From 0e08b48cbbd7c8b2d540d852c7759d3a54b25dd9 Mon Sep 17 00:00:00 2001 From: Sebastian Pape <0xneo11@gmail.com> Date: Mon, 26 Aug 2024 16:56:06 +0200 Subject: [PATCH] v10.18.12: fix estimate (overloaded method names) --- dist/esm/index.evm.js | 20 +++++++++++--------- dist/esm/index.js | 20 +++++++++++--------- dist/esm/index.solana.js | 20 +++++++++++--------- dist/umd/index.evm.js | 20 +++++++++++--------- dist/umd/index.js | 20 +++++++++++--------- dist/umd/index.solana.js | 20 +++++++++++--------- package.evm.json | 2 +- package.json | 2 +- package.solana.json | 2 +- src/platforms/evm/estimate.js | 20 +++++++++++--------- 10 files changed, 80 insertions(+), 66 deletions(-) diff --git a/dist/esm/index.evm.js b/dist/esm/index.evm.js index 5768981..7371f6b 100644 --- a/dist/esm/index.evm.js +++ b/dist/esm/index.evm.js @@ -1,10 +1,17 @@ import { ethers } from 'ethers'; import Blockchains from '@depay/web3-blockchains'; +const findFragment = ({ fragments, method, params })=>{ + return contract.interface.fragments.find((fragment) => { + return( + fragment.name == method && + (fragment.inputs && params && typeof(params) === 'object' ? fragment.inputs.length == Object.keys(params).length : true) + ) + }) +}; + const getContractArguments = ({ contract, method, params })=>{ - let fragment = contract.interface.fragments.find((fragment) => { - return fragment.name == method - }); + let fragment = findFragment({ fragments: contract.interface.fragments, method, params }); if(params instanceof Array) { return params @@ -32,12 +39,7 @@ var estimateEVM = ({ provider, from, to, value, method, api, params }) => { return provider.estimateGas({ from, to, value }) } else { let contract = new ethers.Contract(to, api, provider); - let fragment = contract.interface.fragments.find((fragment) => { - return( - fragment.name == method && - (fragment.inputs && params && typeof(params) === 'object' ? fragment.inputs.length == Object.keys(params).length : true) - ) - }); + let fragment = findFragment({ fragments: contract.interface.fragments, method, params }); let contractArguments = getContractArguments({ contract, method, params }); if(contract[method] === undefined) { method = `${method}(${fragment.inputs.map((input)=>{ diff --git a/dist/esm/index.js b/dist/esm/index.js index 09ef37f..15bc1fc 100644 --- a/dist/esm/index.js +++ b/dist/esm/index.js @@ -724,10 +724,17 @@ let simulate = async function ({ blockchain, from, to, keys, api, params }) { }) }; +const findFragment = ({ fragments, method, params })=>{ + return contract.interface.fragments.find((fragment) => { + return( + fragment.name == method && + (fragment.inputs && params && typeof(params) === 'object' ? fragment.inputs.length == Object.keys(params).length : true) + ) + }) +}; + const getContractArguments = ({ contract, method, params })=>{ - let fragment = contract.interface.fragments.find((fragment) => { - return fragment.name == method - }); + let fragment = findFragment({ fragments: contract.interface.fragments, method, params }); if(params instanceof Array) { return params @@ -755,12 +762,7 @@ var estimateEVM = ({ provider, from, to, value, method, api, params }) => { return provider.estimateGas({ from, to, value }) } else { let contract = new ethers.Contract(to, api, provider); - let fragment = contract.interface.fragments.find((fragment) => { - return( - fragment.name == method && - (fragment.inputs && params && typeof(params) === 'object' ? fragment.inputs.length == Object.keys(params).length : true) - ) - }); + let fragment = findFragment({ fragments: contract.interface.fragments, method, params }); let contractArguments = getContractArguments({ contract, method, params }); if(contract[method] === undefined) { method = `${method}(${fragment.inputs.map((input)=>{ diff --git a/dist/esm/index.solana.js b/dist/esm/index.solana.js index 76495c8..2f15d64 100644 --- a/dist/esm/index.solana.js +++ b/dist/esm/index.solana.js @@ -475,10 +475,17 @@ let simulate = async function ({ blockchain, from, to, keys, api, params }) { }) }; +const findFragment = ({ fragments, method, params })=>{ + return contract.interface.fragments.find((fragment) => { + return( + fragment.name == method && + (fragment.inputs && params && typeof(params) === 'object' ? fragment.inputs.length == Object.keys(params).length : true) + ) + }) +}; + const getContractArguments = ({ contract, method, params })=>{ - let fragment = contract.interface.fragments.find((fragment) => { - return fragment.name == method - }); + let fragment = findFragment({ fragments: contract.interface.fragments, method, params }); if(params instanceof Array) { return params @@ -506,12 +513,7 @@ var estimateEVM = ({ provider, from, to, value, method, api, params }) => { return provider.estimateGas({ from, to, value }) } else { let contract = new ethers.Contract(to, api, provider); - let fragment = contract.interface.fragments.find((fragment) => { - return( - fragment.name == method && - (fragment.inputs && params && typeof(params) === 'object' ? fragment.inputs.length == Object.keys(params).length : true) - ) - }); + let fragment = findFragment({ fragments: contract.interface.fragments, method, params }); let contractArguments = getContractArguments({ contract, method, params }); if(contract[method] === undefined) { method = `${method}(${fragment.inputs.map((input)=>{ diff --git a/dist/umd/index.evm.js b/dist/umd/index.evm.js index 1506586..6ca7a30 100644 --- a/dist/umd/index.evm.js +++ b/dist/umd/index.evm.js @@ -8,10 +8,17 @@ var Blockchains__default = /*#__PURE__*/_interopDefaultLegacy(Blockchains); + const findFragment = ({ fragments, method, params })=>{ + return contract.interface.fragments.find((fragment) => { + return( + fragment.name == method && + (fragment.inputs && params && typeof(params) === 'object' ? fragment.inputs.length == Object.keys(params).length : true) + ) + }) + }; + const getContractArguments = ({ contract, method, params })=>{ - let fragment = contract.interface.fragments.find((fragment) => { - return fragment.name == method - }); + let fragment = findFragment({ fragments: contract.interface.fragments, method, params }); if(params instanceof Array) { return params @@ -39,12 +46,7 @@ return provider.estimateGas({ from, to, value }) } else { let contract = new ethers.ethers.Contract(to, api, provider); - let fragment = contract.interface.fragments.find((fragment) => { - return( - fragment.name == method && - (fragment.inputs && params && typeof(params) === 'object' ? fragment.inputs.length == Object.keys(params).length : true) - ) - }); + let fragment = findFragment({ fragments: contract.interface.fragments, method, params }); let contractArguments = getContractArguments({ contract, method, params }); if(contract[method] === undefined) { method = `${method}(${fragment.inputs.map((input)=>{ diff --git a/dist/umd/index.js b/dist/umd/index.js index 30171b3..38a4cb1 100644 --- a/dist/umd/index.js +++ b/dist/umd/index.js @@ -730,10 +730,17 @@ }) }; + const findFragment = ({ fragments, method, params })=>{ + return contract.interface.fragments.find((fragment) => { + return( + fragment.name == method && + (fragment.inputs && params && typeof(params) === 'object' ? fragment.inputs.length == Object.keys(params).length : true) + ) + }) + }; + const getContractArguments = ({ contract, method, params })=>{ - let fragment = contract.interface.fragments.find((fragment) => { - return fragment.name == method - }); + let fragment = findFragment({ fragments: contract.interface.fragments, method, params }); if(params instanceof Array) { return params @@ -761,12 +768,7 @@ return provider.estimateGas({ from, to, value }) } else { let contract = new ethers.ethers.Contract(to, api, provider); - let fragment = contract.interface.fragments.find((fragment) => { - return( - fragment.name == method && - (fragment.inputs && params && typeof(params) === 'object' ? fragment.inputs.length == Object.keys(params).length : true) - ) - }); + let fragment = findFragment({ fragments: contract.interface.fragments, method, params }); let contractArguments = getContractArguments({ contract, method, params }); if(contract[method] === undefined) { method = `${method}(${fragment.inputs.map((input)=>{ diff --git a/dist/umd/index.solana.js b/dist/umd/index.solana.js index 3adc8e5..3aaa1dc 100644 --- a/dist/umd/index.solana.js +++ b/dist/umd/index.solana.js @@ -481,10 +481,17 @@ }) }; + const findFragment = ({ fragments, method, params })=>{ + return contract.interface.fragments.find((fragment) => { + return( + fragment.name == method && + (fragment.inputs && params && typeof(params) === 'object' ? fragment.inputs.length == Object.keys(params).length : true) + ) + }) + }; + const getContractArguments = ({ contract, method, params })=>{ - let fragment = contract.interface.fragments.find((fragment) => { - return fragment.name == method - }); + let fragment = findFragment({ fragments: contract.interface.fragments, method, params }); if(params instanceof Array) { return params @@ -512,12 +519,7 @@ return provider.estimateGas({ from, to, value }) } else { let contract = new ethers.ethers.Contract(to, api, provider); - let fragment = contract.interface.fragments.find((fragment) => { - return( - fragment.name == method && - (fragment.inputs && params && typeof(params) === 'object' ? fragment.inputs.length == Object.keys(params).length : true) - ) - }); + let fragment = findFragment({ fragments: contract.interface.fragments, method, params }); let contractArguments = getContractArguments({ contract, method, params }); if(contract[method] === undefined) { method = `${method}(${fragment.inputs.map((input)=>{ diff --git a/package.evm.json b/package.evm.json index 16c5c9a..6922429 100644 --- a/package.evm.json +++ b/package.evm.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-client-evm", "moduleName": "Web3Client", - "version": "10.18.11", + "version": "10.18.12", "description": "A web3 client to fetch blockchain data just like you are used to with HTTP clients.", "main": "dist/umd/index.evm.js", "module": "dist/esm/index.evm.js", diff --git a/package.json b/package.json index 7b0358d..5258d92 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-client", "moduleName": "Web3Client", - "version": "10.18.11", + "version": "10.18.12", "description": "A web3 client to fetch blockchain data just like you are used to with HTTP clients.", "main": "dist/umd/index.js", "module": "dist/esm/index.js", diff --git a/package.solana.json b/package.solana.json index 0bcb893..5f5acfc 100644 --- a/package.solana.json +++ b/package.solana.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-client-solana", "moduleName": "Web3Client", - "version": "10.18.11", + "version": "10.18.12", "description": "A web3 client to fetch blockchain data just like you are used to with HTTP clients.", "main": "dist/umd/index.solana.js", "module": "dist/esm/index.solana.js", diff --git a/src/platforms/evm/estimate.js b/src/platforms/evm/estimate.js index aa37ec0..149a4e7 100644 --- a/src/platforms/evm/estimate.js +++ b/src/platforms/evm/estimate.js @@ -1,9 +1,16 @@ import { ethers } from 'ethers' -const getContractArguments = ({ contract, method, params })=>{ - let fragment = contract.interface.fragments.find((fragment) => { - return fragment.name == method +const findFragment = ({ fragments, method, params })=>{ + return contract.interface.fragments.find((fragment) => { + return( + fragment.name == method && + (fragment.inputs && params && typeof(params) === 'object' ? fragment.inputs.length == Object.keys(params).length : true) + ) }) +} + +const getContractArguments = ({ contract, method, params })=>{ + let fragment = findFragment({ fragments: contract.interface.fragments, method, params }) if(params instanceof Array) { return params @@ -31,12 +38,7 @@ export default ({ provider, from, to, value, method, api, params }) => { return provider.estimateGas({ from, to, value }) } else { let contract = new ethers.Contract(to, api, provider) - let fragment = contract.interface.fragments.find((fragment) => { - return( - fragment.name == method && - (fragment.inputs && params && typeof(params) === 'object' ? fragment.inputs.length == Object.keys(params).length : true) - ) - }) + let fragment = findFragment({ fragments: contract.interface.fragments, method, params }) let contractArguments = getContractArguments({ contract, method, params }) if(contract[method] === undefined) { method = `${method}(${fragment.inputs.map((input)=>{