@coinmasters/helpers
Advanced tools
Comparing version 11.0.24 to 11.0.25
@@ -671,3 +671,3 @@ var be = Object.defineProperty; | ||
} | ||
}, I = (r) => Math.log10(parseFloat(r.toString())); | ||
}, I = (r) => Math.log10(Number(r)); | ||
function H({ | ||
@@ -728,14 +728,2 @@ value: r, | ||
} | ||
// constructor(params: SKBigIntParams) { | ||
// const value = getStringValue(params); | ||
// const isComplex = typeof params === 'object'; | ||
// this.decimal = isComplex ? params.decimal : undefined; | ||
// | ||
// // use the multiplier to keep track of decimal point - defaults to 8 if lower than 8 | ||
// this.decimalMultiplier = | ||
// isComplex && 'decimalMultiplier' in params | ||
// ? params.decimalMultiplier | ||
// : toMultiplier(Math.max(getFloatDecimals(toSafeValue(value)), this.decimal || 0)); | ||
// this.#setValue(value); | ||
// } | ||
set(e) { | ||
@@ -771,3 +759,2 @@ return new this.constructor({ decimal: this.decimal, value: e, identifier: this.toString() }); | ||
} | ||
// @ts-expect-error False positive | ||
getValue(e) { | ||
@@ -787,3 +774,2 @@ const t = this.formatBigIntToSafeValue( | ||
} | ||
// @ts-expect-error | ||
getBaseValue(e) { | ||
@@ -881,3 +867,2 @@ const t = this.decimalMultiplier / v(this.decimal || d.THOR), s = this.bigIntValue / t; | ||
}, | ||
//normalize is to precision multiplier base | ||
this.bigIntValue * i / this.decimalMultiplier | ||
@@ -884,0 +869,0 @@ ), c = H({ |
@@ -11,5 +11,5 @@ { | ||
"vitest": "0.34.6", | ||
"@internal/config": "2.7.24", | ||
"@coinmasters/tokens": "3.7.24", | ||
"@coinmasters/types": "4.7.24" | ||
"@internal/config": "2.7.25", | ||
"@coinmasters/types": "4.7.25", | ||
"@coinmasters/tokens": "3.7.25" | ||
}, | ||
@@ -20,4 +20,4 @@ "eslintConfig": { | ||
"peerDependencies": { | ||
"@coinmasters/tokens": "3.7.24", | ||
"@coinmasters/types": "4.7.24" | ||
"@coinmasters/tokens": "3.7.25", | ||
"@coinmasters/types": "4.7.25" | ||
}, | ||
@@ -47,3 +47,3 @@ "exports": { | ||
"types": "./dist/index.d.ts", | ||
"version": "11.0.24", | ||
"version": "11.0.25", | ||
"scripts": { | ||
@@ -50,0 +50,0 @@ "build": "vite build", |
import { BaseDecimal } from '@coinmasters/types'; | ||
import type { SwapKitNumber } from './swapKitNumber.ts'; | ||
@@ -28,11 +27,10 @@ | ||
}; | ||
// const toMultiplier = (decimal: number) => 10n ** BigInt(decimal); | ||
const decimalFromMultiplier = (multiplier: bigint) => Math.log10(parseFloat(multiplier.toString())); | ||
const decimalFromMultiplier = (multiplier: bigint): number => Math.log10(Number(multiplier)); | ||
export function formatBigIntToSafeValue({ | ||
value, | ||
bigIntDecimal = DEFAULT_DECIMAL, | ||
decimal = DEFAULT_DECIMAL, | ||
}: { | ||
value, | ||
bigIntDecimal = DEFAULT_DECIMAL, | ||
decimal = DEFAULT_DECIMAL, | ||
}: { | ||
value: bigint; | ||
@@ -54,5 +52,3 @@ bigIntDecimal?: number; | ||
// Check if we need to round up | ||
if (parseInt(decimalString[bigIntDecimal]) >= 5) { | ||
// Increment the last decimal place and slice off the rest | ||
decimalString = `${decimalString.substring(0, bigIntDecimal - 1)}${( | ||
@@ -62,3 +58,2 @@ parseInt(decimalString[bigIntDecimal - 1]) + 1 | ||
} else { | ||
// Just slice off the extra digits | ||
decimalString = decimalString.substring(0, bigIntDecimal); | ||
@@ -86,6 +81,6 @@ } | ||
static shiftDecimals({ | ||
value, | ||
from, | ||
to, | ||
}: { | ||
value, | ||
from, | ||
to, | ||
}: { | ||
value: InstanceType<typeof SwapKitNumber>; | ||
@@ -121,43 +116,38 @@ from: number; | ||
// constructor(params: SKBigIntParams) { | ||
// const value = getStringValue(params); | ||
// const isComplex = typeof params === 'object'; | ||
// this.decimal = isComplex ? params.decimal : undefined; | ||
// | ||
// // use the multiplier to keep track of decimal point - defaults to 8 if lower than 8 | ||
// this.decimalMultiplier = | ||
// isComplex && 'decimalMultiplier' in params | ||
// ? params.decimalMultiplier | ||
// : toMultiplier(Math.max(getFloatDecimals(toSafeValue(value)), this.decimal || 0)); | ||
// this.#setValue(value); | ||
// } | ||
set(value: SKBigIntParams): this { | ||
// @ts-expect-error False positive | ||
return new this.constructor({ decimal: this.decimal, value, identifier: this.toString() }); | ||
} | ||
add(...args: InitialisationValueType[]) { | ||
return this.#arithmetics('add', ...args); | ||
} | ||
sub(...args: InitialisationValueType[]) { | ||
return this.#arithmetics('sub', ...args); | ||
} | ||
mul(...args: InitialisationValueType[]) { | ||
return this.#arithmetics('mul', ...args); | ||
} | ||
div(...args: InitialisationValueType[]) { | ||
return this.#arithmetics('div', ...args); | ||
} | ||
gt(value: InitialisationValueType) { | ||
return this.#comparison('gt', value); | ||
} | ||
gte(value: InitialisationValueType) { | ||
return this.#comparison('gte', value); | ||
} | ||
lt(value: InitialisationValueType) { | ||
return this.#comparison('lt', value); | ||
} | ||
lte(value: InitialisationValueType) { | ||
return this.#comparison('lte', value); | ||
} | ||
eqValue(value: InitialisationValueType) { | ||
@@ -167,3 +157,2 @@ return this.#comparison('eqValue', value); | ||
// @ts-expect-error False positive | ||
getValue<T extends AllowedNumberTypes>(type: T): NumberPrimitivesType[T] { | ||
@@ -186,3 +175,2 @@ const value = this.formatBigIntToSafeValue( | ||
// @ts-expect-error | ||
getBaseValue<T extends AllowedNumberTypes>(type: T): NumberPrimitivesType[T] { | ||
@@ -315,5 +303,3 @@ const divisor = this.decimalMultiplier / toMultiplier(this.decimal || BaseDecimal.THOR); | ||
// Check if we need to round up | ||
if (parseInt(decimalString[bigIntDecimal]) >= 5) { | ||
// Increment the last decimal place and slice off the rest | ||
decimalString = `${decimalString.substring(0, bigIntDecimal - 1)}${( | ||
@@ -323,3 +309,2 @@ parseInt(decimalString[bigIntDecimal - 1]) + 1 | ||
} else { | ||
// Just slice off the extra digits | ||
decimalString = decimalString.substring(0, bigIntDecimal); | ||
@@ -348,10 +333,2 @@ } | ||
return acc - value; | ||
/** | ||
* Multiplication & division would end up with wrong result if we don't adjust the value | ||
* 200000000n * 200000000n => 40000000000000000n | ||
* 200000000n / 200000000n => 1n | ||
* So we do the following: | ||
* 200000000n * 200000000n = 40000000000000000n / 100000000n (decimals) => 400000000n | ||
* (200000000n * 100000000n (decimals)) / 200000000n => 100000000n | ||
*/ | ||
case 'mul': | ||
@@ -367,3 +344,2 @@ return (acc * value) / precisionDecimalMultiplier; | ||
}, | ||
//normalize is to precision multiplier base | ||
(this.bigIntValue * precisionDecimalMultiplier) / this.decimalMultiplier, | ||
@@ -378,3 +354,2 @@ ); | ||
// @ts-expect-error False positive | ||
return new this.constructor({ | ||
@@ -460,7 +435,2 @@ decimalMultiplier: toMultiplier(decimal), | ||
// function getFloatDecimals(value: string) { | ||
// const decimals = value.split('.')[1]?.length || 0; | ||
// return Math.max(decimals, DEFAULT_DECIMAL); | ||
// } | ||
function getStringValue(param: SKBigIntParams) { | ||
@@ -467,0 +437,0 @@ return typeof param === 'object' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
238298
4011