starknet 11.9.3 → 11.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +53 -4
- package/dist/index.global.js +73 -27
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +75 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -21877,36 +21877,80 @@ var ContractInterface = class {
|
|
|
21877
21877
|
};
|
|
21878
21878
|
|
|
21879
21879
|
// src/utils/units.ts
|
|
21880
|
+
function amountName(tokenName) {
|
|
21881
|
+
return tokenName ? `${tokenName} amount` : "amount";
|
|
21882
|
+
}
|
|
21883
|
+
function checkTokenName(tokenName) {
|
|
21884
|
+
if (tokenName === void 0) return;
|
|
21885
|
+
assert(isString(tokenName), `the token name must be a string, not ${typeof tokenName}`);
|
|
21886
|
+
assert(tokenName.trim() !== "", "the token name is an empty string");
|
|
21887
|
+
}
|
|
21888
|
+
function toDecimals(decimals) {
|
|
21889
|
+
const shown = isString(decimals) ? `'${decimals}'` : String(decimals);
|
|
21890
|
+
assert(
|
|
21891
|
+
isBigNumberish(decimals) && (!isNumber(decimals) || Number.isInteger(decimals)),
|
|
21892
|
+
`decimals must be an integer, not ${shown}`
|
|
21893
|
+
);
|
|
21894
|
+
assertInRange(decimals, RANGE_U8.min, RANGE_U8.max, "decimals");
|
|
21895
|
+
return Number(decimals);
|
|
21896
|
+
}
|
|
21897
|
+
function decimalToInteger(text, decimals, tokenName) {
|
|
21898
|
+
const match = /^(-?)(\d*)(?:\.(\d*))?$/.exec(text);
|
|
21899
|
+
assert(
|
|
21900
|
+
match !== null && `${match[2]}${match[3] ?? ""}` !== "",
|
|
21901
|
+
`'${text}' is not a valid ${amountName(tokenName)}`
|
|
21902
|
+
);
|
|
21903
|
+
const [, sign, integer, fraction = ""] = match;
|
|
21904
|
+
const name = tokenName ? ` ${tokenName}` : "";
|
|
21905
|
+
const unit = decimals === 1 ? "decimal" : "decimals";
|
|
21906
|
+
assert(
|
|
21907
|
+
!/[1-9]/.test(fraction.slice(decimals)),
|
|
21908
|
+
`'${text}'${name} has more than ${decimals} ${unit}`
|
|
21909
|
+
);
|
|
21910
|
+
const result = BigInt(`0${integer}${fraction.slice(0, decimals).padEnd(decimals, "0")}`);
|
|
21911
|
+
return sign === "-" ? -result : result;
|
|
21912
|
+
}
|
|
21913
|
+
function integerToDecimal(value, decimals, tokenName) {
|
|
21914
|
+
assert(
|
|
21915
|
+
!isString(value) || value.trim() !== "",
|
|
21916
|
+
`the ${amountName(tokenName)} is an empty string`
|
|
21917
|
+
);
|
|
21918
|
+
const integer = toBigInt(value);
|
|
21919
|
+
const sign = integer < 0n ? "-" : "";
|
|
21920
|
+
const digits = (integer < 0n ? -integer : integer).toString();
|
|
21921
|
+
let text;
|
|
21922
|
+
if (digits.length <= decimals) {
|
|
21923
|
+
text = `0.${digits.padStart(decimals, "0")}`;
|
|
21924
|
+
} else {
|
|
21925
|
+
text = `${digits.slice(0, digits.length - decimals)}.${digits.slice(digits.length - decimals)}`;
|
|
21926
|
+
}
|
|
21927
|
+
return sign + text.replace(/(\.[0-9]*[1-9])0+$|\.0*$/, "$1");
|
|
21928
|
+
}
|
|
21880
21929
|
function units(amount, symbol = "fri") {
|
|
21881
21930
|
if (symbol === "strk") {
|
|
21882
|
-
|
|
21883
|
-
|
|
21884
|
-
|
|
21885
|
-
|
|
21886
|
-
const
|
|
21887
|
-
|
|
21888
|
-
throw new Error(`units: '${numStr}' is not a strk amount`);
|
|
21889
|
-
}
|
|
21890
|
-
const [, sign2, integer, decimal = ""] = match;
|
|
21891
|
-
if (/[1-9]/.test(decimal.slice(18))) {
|
|
21892
|
-
throw new Error(`units: '${numStr}' strk has more than 18 decimals`);
|
|
21893
|
-
}
|
|
21894
|
-
const fri2 = BigInt(`${integer}${decimal.slice(0, 18).padEnd(18, "0")}`);
|
|
21895
|
-
return fri2 === 0n ? "0" : `${sign2}${fri2.toString()}`;
|
|
21896
|
-
}
|
|
21897
|
-
if (isString(amount) && amount.trim() === "") {
|
|
21898
|
-
throw new Error("units: the fri amount is an empty string");
|
|
21899
|
-
}
|
|
21900
|
-
const fri = toBigInt(amount);
|
|
21901
|
-
const sign = fri < 0n ? "-" : "";
|
|
21902
|
-
const bis = (fri < 0n ? -fri : fri).toString();
|
|
21903
|
-
let strk;
|
|
21904
|
-
if (bis.length <= 18) {
|
|
21905
|
-
strk = `0.${bis.padStart(18, "0")}`;
|
|
21906
|
-
} else {
|
|
21907
|
-
strk = `${bis.slice(0, bis.length - 18)}.${bis.slice(bis.length - 18)}`;
|
|
21931
|
+
assert(
|
|
21932
|
+
isBigInt(amount) || isString(amount),
|
|
21933
|
+
`the strk amount must be a string or a bigint, not ${typeof amount}`
|
|
21934
|
+
);
|
|
21935
|
+
const text = isBigInt(amount) || isHex(amount) ? toBigInt(amount).toString() : amount;
|
|
21936
|
+
return decimalToInteger(text, 18, "strk").toString();
|
|
21908
21937
|
}
|
|
21909
|
-
return
|
|
21938
|
+
return integerToDecimal(amount, 18, "fri");
|
|
21939
|
+
}
|
|
21940
|
+
function parseUnits(value, decimals, tokenName) {
|
|
21941
|
+
checkTokenName(tokenName);
|
|
21942
|
+
const decimalCount = toDecimals(decimals);
|
|
21943
|
+
assert(isString(value), `the ${amountName(tokenName)} must be a string, not ${typeof value}`);
|
|
21944
|
+
return decimalToInteger(value, decimalCount, tokenName);
|
|
21945
|
+
}
|
|
21946
|
+
function formatUnits(value, decimals, tokenName) {
|
|
21947
|
+
checkTokenName(tokenName);
|
|
21948
|
+
const decimalCount = toDecimals(decimals);
|
|
21949
|
+
assert(
|
|
21950
|
+
isNumber(value) || isBigInt(value) || isString(value),
|
|
21951
|
+
`the ${amountName(tokenName)} must be a number, a bigint or a string, not ${typeof value}`
|
|
21952
|
+
);
|
|
21953
|
+
return integerToDecimal(value, decimalCount, tokenName);
|
|
21910
21954
|
}
|
|
21911
21955
|
var export_TypedDataRevision = api_exports.TypedDataRevision;
|
|
21912
21956
|
export {
|
|
@@ -22055,6 +22099,7 @@ export {
|
|
|
22055
22099
|
fastCairoTypeStrategy,
|
|
22056
22100
|
fastExecute,
|
|
22057
22101
|
fastParsingStrategy,
|
|
22102
|
+
formatUnits,
|
|
22058
22103
|
getAbiVersion,
|
|
22059
22104
|
getChecksumAddress,
|
|
22060
22105
|
getGasPrices,
|
|
@@ -22084,6 +22129,7 @@ export {
|
|
|
22084
22129
|
num_exports as num,
|
|
22085
22130
|
outsideExecution_exports as outsideExecution,
|
|
22086
22131
|
parseCalldataField,
|
|
22132
|
+
parseUnits,
|
|
22087
22133
|
utils_exports as paymaster,
|
|
22088
22134
|
paymasterPlugin,
|
|
22089
22135
|
provider_exports as provider,
|