Skip to content

Commit

Permalink
v10.18.12: fix estimate (overloaded method names)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNe0x1 committed Aug 26, 2024
1 parent d76006e commit 0e08b48
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 66 deletions.
20 changes: 11 additions & 9 deletions dist/esm/index.evm.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)=>{
Expand Down
20 changes: 11 additions & 9 deletions dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)=>{
Expand Down
20 changes: 11 additions & 9 deletions dist/esm/index.solana.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)=>{
Expand Down
20 changes: 11 additions & 9 deletions dist/umd/index.evm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)=>{
Expand Down
20 changes: 11 additions & 9 deletions dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)=>{
Expand Down
20 changes: 11 additions & 9 deletions dist/umd/index.solana.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)=>{
Expand Down
2 changes: 1 addition & 1 deletion package.evm.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.solana.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
20 changes: 11 additions & 9 deletions src/platforms/evm/estimate.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)=>{
Expand Down

0 comments on commit 0e08b48

Please sign in to comment.