diff --git a/package-lock.json b/package-lock.json index 348c09d..941fdac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@influenceth/sdk", - "version": "2.1.3", + "version": "2.1.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@influenceth/sdk", - "version": "2.1.3", + "version": "2.1.4", "license": "SEE LICENSE IN LICENSE", "dependencies": { "@influenceth/astro": "^0.2.6", diff --git a/package.json b/package.json index 90c0372..9bc62d8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@influenceth/sdk", - "version": "2.1.3", + "version": "2.1.4", "description": "Influence SDK", "type": "module", "module": "./build/index.js", diff --git a/src/lib/system.js b/src/lib/system.js index 9036bb2..11a5a29 100644 --- a/src/lib/system.js +++ b/src/lib/system.js @@ -41,6 +41,8 @@ const Systems = Object.keys(SystemData).reduce((acc, name) => { return acc; }, {}); +const toBigInt = (value) => BigInt(Math.round(Number(value || 0))); + const formatCalldataValue = (type, value) => { if (type === 'ContractAddress') { return value; @@ -53,22 +55,22 @@ const formatCalldataValue = (type, value) => { } else if (type === 'Boolean') { return value; } else if (type === 'BigNumber') { - return BigInt(value); + return toBigInt(value); } else if (type === 'Ether') { return uint256.bnToUint256(value); } else if (type === 'InventoryItem') { return [value.product, value.amount]; } else if (type === 'Withdrawal') { - return { recipient: value.recipient, amount: uint256.bnToUint256(BigInt(value.amount)) }; + return { recipient: value.recipient, amount: uint256.bnToUint256(toBigInt(value.amount)) }; } else if (type === 'Boolean') { return !!value; } else if (type === 'Fixed64') { const neg = value < 0; - const val = BigInt(Math.floor(Math.abs(value) * 2 ** 32)); + const val = toBigInt(Math.floor(Math.abs(value) * 2 ** 32)); return [val, neg ? 1 : 0]; } else if (type === 'Fixed128') { const neg = value < 0; - const val = BigInt(Math.floor(Math.abs(value) * 2 ** 64)); // TODO: this will cause precision loss, use bignumber + const val = toBigInt(Math.floor(Math.abs(value) * 2 ** 64)); // TODO: this will cause precision loss, use bignumber return [val, neg ? 1 : 0]; } else if (type === 'EscrowHook') { if (!value) return { contract: 0, entry_point_selector: '0', calldata: [] }; @@ -168,7 +170,7 @@ const getTransferWithConfirmationCall = (recipient, amount, memo, consumerAddres [ { value: recipient, type: 'ContractAddress' }, { value: amount, type: 'BigNumber' }, - { value: Array.isArray(memo) ? ec.starkCurve.poseidonHashMany(memo.map((v) => BigInt(v))) : memo }, + { value: Array.isArray(memo) ? ec.starkCurve.poseidonHashMany(memo.map((v) => toBigInt(v))) : memo }, { value: consumerAddress, type: 'ContractAddress' } ] );