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.js
CHANGED
|
@@ -176,6 +176,7 @@ __export(index_exports, {
|
|
|
176
176
|
fastCairoTypeStrategy: () => fastCairoTypeStrategy,
|
|
177
177
|
fastExecute: () => fastExecute,
|
|
178
178
|
fastParsingStrategy: () => fastParsingStrategy,
|
|
179
|
+
formatUnits: () => formatUnits,
|
|
179
180
|
getAbiVersion: () => getAbiVersion,
|
|
180
181
|
getChecksumAddress: () => getChecksumAddress,
|
|
181
182
|
getGasPrices: () => getGasPrices,
|
|
@@ -205,6 +206,7 @@ __export(index_exports, {
|
|
|
205
206
|
num: () => num_exports,
|
|
206
207
|
outsideExecution: () => outsideExecution_exports,
|
|
207
208
|
parseCalldataField: () => parseCalldataField,
|
|
209
|
+
parseUnits: () => parseUnits,
|
|
208
210
|
paymaster: () => utils_exports,
|
|
209
211
|
paymasterPlugin: () => paymasterPlugin,
|
|
210
212
|
provider: () => provider_exports,
|
|
@@ -14050,8 +14052,17 @@ var BatchClient = class {
|
|
|
14050
14052
|
this.batchPromises[key] = promise;
|
|
14051
14053
|
});
|
|
14052
14054
|
}
|
|
14053
|
-
|
|
14054
|
-
|
|
14055
|
+
let results;
|
|
14056
|
+
try {
|
|
14057
|
+
results = await this.batchPromises[requestId];
|
|
14058
|
+
} finally {
|
|
14059
|
+
delete this.batchPromises[requestId];
|
|
14060
|
+
}
|
|
14061
|
+
if (!Array.isArray(results)) {
|
|
14062
|
+
const reply = results;
|
|
14063
|
+
if (reply?.error) return reply;
|
|
14064
|
+
throw new Error(`Unexpected reply to a batch request. Method: ${String(method)}`);
|
|
14065
|
+
}
|
|
14055
14066
|
const result = results.find((res) => res.id === requestId);
|
|
14056
14067
|
if (!result)
|
|
14057
14068
|
throw new Error(`Couldn't find the result for the request. Method: ${String(method)}`);
|
|
@@ -22086,36 +22097,80 @@ var ContractInterface = class {
|
|
|
22086
22097
|
};
|
|
22087
22098
|
|
|
22088
22099
|
// src/utils/units.ts
|
|
22100
|
+
function amountName(tokenName) {
|
|
22101
|
+
return tokenName ? `${tokenName} amount` : "amount";
|
|
22102
|
+
}
|
|
22103
|
+
function checkTokenName(tokenName) {
|
|
22104
|
+
if (tokenName === void 0) return;
|
|
22105
|
+
assert(isString(tokenName), `the token name must be a string, not ${typeof tokenName}`);
|
|
22106
|
+
assert(tokenName.trim() !== "", "the token name is an empty string");
|
|
22107
|
+
}
|
|
22108
|
+
function toDecimals(decimals) {
|
|
22109
|
+
const shown = isString(decimals) ? `'${decimals}'` : String(decimals);
|
|
22110
|
+
assert(
|
|
22111
|
+
isBigNumberish(decimals) && (!isNumber(decimals) || Number.isInteger(decimals)),
|
|
22112
|
+
`decimals must be an integer, not ${shown}`
|
|
22113
|
+
);
|
|
22114
|
+
assertInRange(decimals, RANGE_U8.min, RANGE_U8.max, "decimals");
|
|
22115
|
+
return Number(decimals);
|
|
22116
|
+
}
|
|
22117
|
+
function decimalToInteger(text, decimals, tokenName) {
|
|
22118
|
+
const match = /^(-?)(\d*)(?:\.(\d*))?$/.exec(text);
|
|
22119
|
+
assert(
|
|
22120
|
+
match !== null && `${match[2]}${match[3] ?? ""}` !== "",
|
|
22121
|
+
`'${text}' is not a valid ${amountName(tokenName)}`
|
|
22122
|
+
);
|
|
22123
|
+
const [, sign, integer, fraction = ""] = match;
|
|
22124
|
+
const name = tokenName ? ` ${tokenName}` : "";
|
|
22125
|
+
const unit = decimals === 1 ? "decimal" : "decimals";
|
|
22126
|
+
assert(
|
|
22127
|
+
!/[1-9]/.test(fraction.slice(decimals)),
|
|
22128
|
+
`'${text}'${name} has more than ${decimals} ${unit}`
|
|
22129
|
+
);
|
|
22130
|
+
const result = BigInt(`0${integer}${fraction.slice(0, decimals).padEnd(decimals, "0")}`);
|
|
22131
|
+
return sign === "-" ? -result : result;
|
|
22132
|
+
}
|
|
22133
|
+
function integerToDecimal(value, decimals, tokenName) {
|
|
22134
|
+
assert(
|
|
22135
|
+
!isString(value) || value.trim() !== "",
|
|
22136
|
+
`the ${amountName(tokenName)} is an empty string`
|
|
22137
|
+
);
|
|
22138
|
+
const integer = toBigInt(value);
|
|
22139
|
+
const sign = integer < 0n ? "-" : "";
|
|
22140
|
+
const digits = (integer < 0n ? -integer : integer).toString();
|
|
22141
|
+
let text;
|
|
22142
|
+
if (digits.length <= decimals) {
|
|
22143
|
+
text = `0.${digits.padStart(decimals, "0")}`;
|
|
22144
|
+
} else {
|
|
22145
|
+
text = `${digits.slice(0, digits.length - decimals)}.${digits.slice(digits.length - decimals)}`;
|
|
22146
|
+
}
|
|
22147
|
+
return sign + text.replace(/(\.[0-9]*[1-9])0+$|\.0*$/, "$1");
|
|
22148
|
+
}
|
|
22089
22149
|
function units(amount, symbol = "fri") {
|
|
22090
22150
|
if (symbol === "strk") {
|
|
22091
|
-
|
|
22092
|
-
|
|
22093
|
-
|
|
22094
|
-
|
|
22095
|
-
const
|
|
22096
|
-
|
|
22097
|
-
throw new Error(`units: '${numStr}' is not a strk amount`);
|
|
22098
|
-
}
|
|
22099
|
-
const [, sign2, integer, decimal = ""] = match;
|
|
22100
|
-
if (/[1-9]/.test(decimal.slice(18))) {
|
|
22101
|
-
throw new Error(`units: '${numStr}' strk has more than 18 decimals`);
|
|
22102
|
-
}
|
|
22103
|
-
const fri2 = BigInt(`${integer}${decimal.slice(0, 18).padEnd(18, "0")}`);
|
|
22104
|
-
return fri2 === 0n ? "0" : `${sign2}${fri2.toString()}`;
|
|
22105
|
-
}
|
|
22106
|
-
if (isString(amount) && amount.trim() === "") {
|
|
22107
|
-
throw new Error("units: the fri amount is an empty string");
|
|
22108
|
-
}
|
|
22109
|
-
const fri = toBigInt(amount);
|
|
22110
|
-
const sign = fri < 0n ? "-" : "";
|
|
22111
|
-
const bis = (fri < 0n ? -fri : fri).toString();
|
|
22112
|
-
let strk;
|
|
22113
|
-
if (bis.length <= 18) {
|
|
22114
|
-
strk = `0.${bis.padStart(18, "0")}`;
|
|
22115
|
-
} else {
|
|
22116
|
-
strk = `${bis.slice(0, bis.length - 18)}.${bis.slice(bis.length - 18)}`;
|
|
22151
|
+
assert(
|
|
22152
|
+
isBigInt(amount) || isString(amount),
|
|
22153
|
+
`the strk amount must be a string or a bigint, not ${typeof amount}`
|
|
22154
|
+
);
|
|
22155
|
+
const text = isBigInt(amount) || isHex(amount) ? toBigInt(amount).toString() : amount;
|
|
22156
|
+
return decimalToInteger(text, 18, "strk").toString();
|
|
22117
22157
|
}
|
|
22118
|
-
return
|
|
22158
|
+
return integerToDecimal(amount, 18, "fri");
|
|
22159
|
+
}
|
|
22160
|
+
function parseUnits(value, decimals, tokenName) {
|
|
22161
|
+
checkTokenName(tokenName);
|
|
22162
|
+
const decimalCount = toDecimals(decimals);
|
|
22163
|
+
assert(isString(value), `the ${amountName(tokenName)} must be a string, not ${typeof value}`);
|
|
22164
|
+
return decimalToInteger(value, decimalCount, tokenName);
|
|
22165
|
+
}
|
|
22166
|
+
function formatUnits(value, decimals, tokenName) {
|
|
22167
|
+
checkTokenName(tokenName);
|
|
22168
|
+
const decimalCount = toDecimals(decimals);
|
|
22169
|
+
assert(
|
|
22170
|
+
isNumber(value) || isBigInt(value) || isString(value),
|
|
22171
|
+
`the ${amountName(tokenName)} must be a number, a bigint or a string, not ${typeof value}`
|
|
22172
|
+
);
|
|
22173
|
+
return integerToDecimal(value, decimalCount, tokenName);
|
|
22119
22174
|
}
|
|
22120
22175
|
// Annotate the CommonJS export names for ESM import in node:
|
|
22121
22176
|
0 && (module.exports = {
|
|
@@ -22264,6 +22319,7 @@ function units(amount, symbol = "fri") {
|
|
|
22264
22319
|
fastCairoTypeStrategy,
|
|
22265
22320
|
fastExecute,
|
|
22266
22321
|
fastParsingStrategy,
|
|
22322
|
+
formatUnits,
|
|
22267
22323
|
getAbiVersion,
|
|
22268
22324
|
getChecksumAddress,
|
|
22269
22325
|
getGasPrices,
|
|
@@ -22293,6 +22349,7 @@ function units(amount, symbol = "fri") {
|
|
|
22293
22349
|
num,
|
|
22294
22350
|
outsideExecution,
|
|
22295
22351
|
parseCalldataField,
|
|
22352
|
+
parseUnits,
|
|
22296
22353
|
paymaster,
|
|
22297
22354
|
paymasterPlugin,
|
|
22298
22355
|
provider,
|