starknet 11.9.3 → 11.10.1
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 +12 -0
- package/dist/index.d.ts +50 -1
- package/dist/index.global.js +84 -29
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +86 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +84 -29
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -13841,8 +13841,17 @@ var BatchClient = class {
|
|
|
13841
13841
|
this.batchPromises[key] = promise;
|
|
13842
13842
|
});
|
|
13843
13843
|
}
|
|
13844
|
-
|
|
13845
|
-
|
|
13844
|
+
let results;
|
|
13845
|
+
try {
|
|
13846
|
+
results = await this.batchPromises[requestId];
|
|
13847
|
+
} finally {
|
|
13848
|
+
delete this.batchPromises[requestId];
|
|
13849
|
+
}
|
|
13850
|
+
if (!Array.isArray(results)) {
|
|
13851
|
+
const reply = results;
|
|
13852
|
+
if (reply?.error) return reply;
|
|
13853
|
+
throw new Error(`Unexpected reply to a batch request. Method: ${String(method)}`);
|
|
13854
|
+
}
|
|
13846
13855
|
const result = results.find((res) => res.id === requestId);
|
|
13847
13856
|
if (!result)
|
|
13848
13857
|
throw new Error(`Couldn't find the result for the request. Method: ${String(method)}`);
|
|
@@ -21877,36 +21886,80 @@ var ContractInterface = class {
|
|
|
21877
21886
|
};
|
|
21878
21887
|
|
|
21879
21888
|
// src/utils/units.ts
|
|
21889
|
+
function amountName(tokenName) {
|
|
21890
|
+
return tokenName ? `${tokenName} amount` : "amount";
|
|
21891
|
+
}
|
|
21892
|
+
function checkTokenName(tokenName) {
|
|
21893
|
+
if (tokenName === void 0) return;
|
|
21894
|
+
assert(isString(tokenName), `the token name must be a string, not ${typeof tokenName}`);
|
|
21895
|
+
assert(tokenName.trim() !== "", "the token name is an empty string");
|
|
21896
|
+
}
|
|
21897
|
+
function toDecimals(decimals) {
|
|
21898
|
+
const shown = isString(decimals) ? `'${decimals}'` : String(decimals);
|
|
21899
|
+
assert(
|
|
21900
|
+
isBigNumberish(decimals) && (!isNumber(decimals) || Number.isInteger(decimals)),
|
|
21901
|
+
`decimals must be an integer, not ${shown}`
|
|
21902
|
+
);
|
|
21903
|
+
assertInRange(decimals, RANGE_U8.min, RANGE_U8.max, "decimals");
|
|
21904
|
+
return Number(decimals);
|
|
21905
|
+
}
|
|
21906
|
+
function decimalToInteger(text, decimals, tokenName) {
|
|
21907
|
+
const match = /^(-?)(\d*)(?:\.(\d*))?$/.exec(text);
|
|
21908
|
+
assert(
|
|
21909
|
+
match !== null && `${match[2]}${match[3] ?? ""}` !== "",
|
|
21910
|
+
`'${text}' is not a valid ${amountName(tokenName)}`
|
|
21911
|
+
);
|
|
21912
|
+
const [, sign, integer, fraction = ""] = match;
|
|
21913
|
+
const name = tokenName ? ` ${tokenName}` : "";
|
|
21914
|
+
const unit = decimals === 1 ? "decimal" : "decimals";
|
|
21915
|
+
assert(
|
|
21916
|
+
!/[1-9]/.test(fraction.slice(decimals)),
|
|
21917
|
+
`'${text}'${name} has more than ${decimals} ${unit}`
|
|
21918
|
+
);
|
|
21919
|
+
const result = BigInt(`0${integer}${fraction.slice(0, decimals).padEnd(decimals, "0")}`);
|
|
21920
|
+
return sign === "-" ? -result : result;
|
|
21921
|
+
}
|
|
21922
|
+
function integerToDecimal(value, decimals, tokenName) {
|
|
21923
|
+
assert(
|
|
21924
|
+
!isString(value) || value.trim() !== "",
|
|
21925
|
+
`the ${amountName(tokenName)} is an empty string`
|
|
21926
|
+
);
|
|
21927
|
+
const integer = toBigInt(value);
|
|
21928
|
+
const sign = integer < 0n ? "-" : "";
|
|
21929
|
+
const digits = (integer < 0n ? -integer : integer).toString();
|
|
21930
|
+
let text;
|
|
21931
|
+
if (digits.length <= decimals) {
|
|
21932
|
+
text = `0.${digits.padStart(decimals, "0")}`;
|
|
21933
|
+
} else {
|
|
21934
|
+
text = `${digits.slice(0, digits.length - decimals)}.${digits.slice(digits.length - decimals)}`;
|
|
21935
|
+
}
|
|
21936
|
+
return sign + text.replace(/(\.[0-9]*[1-9])0+$|\.0*$/, "$1");
|
|
21937
|
+
}
|
|
21880
21938
|
function units(amount, symbol = "fri") {
|
|
21881
21939
|
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)}`;
|
|
21940
|
+
assert(
|
|
21941
|
+
isBigInt(amount) || isString(amount),
|
|
21942
|
+
`the strk amount must be a string or a bigint, not ${typeof amount}`
|
|
21943
|
+
);
|
|
21944
|
+
const text = isBigInt(amount) || isHex(amount) ? toBigInt(amount).toString() : amount;
|
|
21945
|
+
return decimalToInteger(text, 18, "strk").toString();
|
|
21908
21946
|
}
|
|
21909
|
-
return
|
|
21947
|
+
return integerToDecimal(amount, 18, "fri");
|
|
21948
|
+
}
|
|
21949
|
+
function parseUnits(value, decimals, tokenName) {
|
|
21950
|
+
checkTokenName(tokenName);
|
|
21951
|
+
const decimalCount = toDecimals(decimals);
|
|
21952
|
+
assert(isString(value), `the ${amountName(tokenName)} must be a string, not ${typeof value}`);
|
|
21953
|
+
return decimalToInteger(value, decimalCount, tokenName);
|
|
21954
|
+
}
|
|
21955
|
+
function formatUnits(value, decimals, tokenName) {
|
|
21956
|
+
checkTokenName(tokenName);
|
|
21957
|
+
const decimalCount = toDecimals(decimals);
|
|
21958
|
+
assert(
|
|
21959
|
+
isNumber(value) || isBigInt(value) || isString(value),
|
|
21960
|
+
`the ${amountName(tokenName)} must be a number, a bigint or a string, not ${typeof value}`
|
|
21961
|
+
);
|
|
21962
|
+
return integerToDecimal(value, decimalCount, tokenName);
|
|
21910
21963
|
}
|
|
21911
21964
|
var export_TypedDataRevision = api_exports.TypedDataRevision;
|
|
21912
21965
|
export {
|
|
@@ -22055,6 +22108,7 @@ export {
|
|
|
22055
22108
|
fastCairoTypeStrategy,
|
|
22056
22109
|
fastExecute,
|
|
22057
22110
|
fastParsingStrategy,
|
|
22111
|
+
formatUnits,
|
|
22058
22112
|
getAbiVersion,
|
|
22059
22113
|
getChecksumAddress,
|
|
22060
22114
|
getGasPrices,
|
|
@@ -22084,6 +22138,7 @@ export {
|
|
|
22084
22138
|
num_exports as num,
|
|
22085
22139
|
outsideExecution_exports as outsideExecution,
|
|
22086
22140
|
parseCalldataField,
|
|
22141
|
+
parseUnits,
|
|
22087
22142
|
utils_exports as paymaster,
|
|
22088
22143
|
paymasterPlugin,
|
|
22089
22144
|
provider_exports as provider,
|