Skip to content

Commit

Permalink
v10.18.4: fix estimateEvm for tuple params
Browse files Browse the repository at this point in the history
  • Loading branch information
10xSebastian committed Sep 15, 2023
1 parent 720d337 commit e72e6d0
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 17 deletions.
22 changes: 20 additions & 2 deletions dist/esm/index.evm.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ const getContractArguments = ({ contract, method, params })=>{
}
};

const tupleParamsToMethodSignature = (components) =>{
return `(${
components.map((component)=>{
if(component.type === 'tuple') {
return tupleParamsToMethodSignature(component.components)
} else {
return component.type
}
}).join(',')
})`
};

var estimateEVM = ({ provider, from, to, value, method, api, params }) => {
if(typeof api == "undefined"){
return provider.estimateGas({ from, to, value })
Expand All @@ -23,10 +35,16 @@ var estimateEVM = ({ provider, from, to, value, method, api, params }) => {
let fragment = contract.interface.fragments.find((fragment) => {
return fragment.name == method
});
let contractArguments = getContractArguments({ contract, method, params });
if(contract[method] === undefined) {
method = `${method}(${fragment.inputs.map((input)=>input.type).join(',')})`;
method = `${method}(${fragment.inputs.map((input)=>{
if(input.type === 'tuple') {
return tupleParamsToMethodSignature(input.components)
} else {
return input.type
}
}).join(',')})`;
}
let contractArguments = getContractArguments({ contract, method, params });
let contractMethod = contract.estimateGas[method];
if(contractArguments) {
return contractMethod(...contractArguments, { from, value })
Expand Down
22 changes: 20 additions & 2 deletions dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,18 @@ const getContractArguments = ({ contract, method, params })=>{
}
};

const tupleParamsToMethodSignature = (components) =>{
return `(${
components.map((component)=>{
if(component.type === 'tuple') {
return tupleParamsToMethodSignature(component.components)
} else {
return component.type
}
}).join(',')
})`
};

var estimateEVM = ({ provider, from, to, value, method, api, params }) => {
if(typeof api == "undefined"){
return provider.estimateGas({ from, to, value })
Expand All @@ -701,10 +713,16 @@ var estimateEVM = ({ provider, from, to, value, method, api, params }) => {
let fragment = contract.interface.fragments.find((fragment) => {
return fragment.name == method
});
let contractArguments = getContractArguments({ contract, method, params });
if(contract[method] === undefined) {
method = `${method}(${fragment.inputs.map((input)=>input.type).join(',')})`;
method = `${method}(${fragment.inputs.map((input)=>{
if(input.type === 'tuple') {
return tupleParamsToMethodSignature(input.components)
} else {
return input.type
}
}).join(',')})`;
}
let contractArguments = getContractArguments({ contract, method, params });
let contractMethod = contract.estimateGas[method];
if(contractArguments) {
return contractMethod(...contractArguments, { from, value })
Expand Down
22 changes: 20 additions & 2 deletions dist/esm/index.solana.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,18 @@ const getContractArguments = ({ contract, method, params })=>{
}
};

const tupleParamsToMethodSignature = (components) =>{
return `(${
components.map((component)=>{
if(component.type === 'tuple') {
return tupleParamsToMethodSignature(component.components)
} else {
return component.type
}
}).join(',')
})`
};

var estimateEVM = ({ provider, from, to, value, method, api, params }) => {
if(typeof api == "undefined"){
return provider.estimateGas({ from, to, value })
Expand All @@ -459,10 +471,16 @@ var estimateEVM = ({ provider, from, to, value, method, api, params }) => {
let fragment = contract.interface.fragments.find((fragment) => {
return fragment.name == method
});
let contractArguments = getContractArguments({ contract, method, params });
if(contract[method] === undefined) {
method = `${method}(${fragment.inputs.map((input)=>input.type).join(',')})`;
method = `${method}(${fragment.inputs.map((input)=>{
if(input.type === 'tuple') {
return tupleParamsToMethodSignature(input.components)
} else {
return input.type
}
}).join(',')})`;
}
let contractArguments = getContractArguments({ contract, method, params });
let contractMethod = contract.estimateGas[method];
if(contractArguments) {
return contractMethod(...contractArguments, { from, value })
Expand Down
22 changes: 20 additions & 2 deletions dist/umd/index.evm.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
}
};

const tupleParamsToMethodSignature = (components) =>{
return `(${
components.map((component)=>{
if(component.type === 'tuple') {
return tupleParamsToMethodSignature(component.components)
} else {
return component.type
}
}).join(',')
})`
};

var estimateEVM = ({ provider, from, to, value, method, api, params }) => {
if(typeof api == "undefined"){
return provider.estimateGas({ from, to, value })
Expand All @@ -30,10 +42,16 @@
let fragment = contract.interface.fragments.find((fragment) => {
return fragment.name == method
});
let contractArguments = getContractArguments({ contract, method, params });
if(contract[method] === undefined) {
method = `${method}(${fragment.inputs.map((input)=>input.type).join(',')})`;
method = `${method}(${fragment.inputs.map((input)=>{
if(input.type === 'tuple') {
return tupleParamsToMethodSignature(input.components)
} else {
return input.type
}
}).join(',')})`;
}
let contractArguments = getContractArguments({ contract, method, params });
let contractMethod = contract.estimateGas[method];
if(contractArguments) {
return contractMethod(...contractArguments, { from, value })
Expand Down
22 changes: 20 additions & 2 deletions dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,18 @@
}
};

const tupleParamsToMethodSignature = (components) =>{
return `(${
components.map((component)=>{
if(component.type === 'tuple') {
return tupleParamsToMethodSignature(component.components)
} else {
return component.type
}
}).join(',')
})`
};

var estimateEVM = ({ provider, from, to, value, method, api, params }) => {
if(typeof api == "undefined"){
return provider.estimateGas({ from, to, value })
Expand All @@ -707,10 +719,16 @@
let fragment = contract.interface.fragments.find((fragment) => {
return fragment.name == method
});
let contractArguments = getContractArguments({ contract, method, params });
if(contract[method] === undefined) {
method = `${method}(${fragment.inputs.map((input)=>input.type).join(',')})`;
method = `${method}(${fragment.inputs.map((input)=>{
if(input.type === 'tuple') {
return tupleParamsToMethodSignature(input.components)
} else {
return input.type
}
}).join(',')})`;
}
let contractArguments = getContractArguments({ contract, method, params });
let contractMethod = contract.estimateGas[method];
if(contractArguments) {
return contractMethod(...contractArguments, { from, value })
Expand Down
22 changes: 20 additions & 2 deletions dist/umd/index.solana.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,18 @@
}
};

const tupleParamsToMethodSignature = (components) =>{
return `(${
components.map((component)=>{
if(component.type === 'tuple') {
return tupleParamsToMethodSignature(component.components)
} else {
return component.type
}
}).join(',')
})`
};

var estimateEVM = ({ provider, from, to, value, method, api, params }) => {
if(typeof api == "undefined"){
return provider.estimateGas({ from, to, value })
Expand All @@ -465,10 +477,16 @@
let fragment = contract.interface.fragments.find((fragment) => {
return fragment.name == method
});
let contractArguments = getContractArguments({ contract, method, params });
if(contract[method] === undefined) {
method = `${method}(${fragment.inputs.map((input)=>input.type).join(',')})`;
method = `${method}(${fragment.inputs.map((input)=>{
if(input.type === 'tuple') {
return tupleParamsToMethodSignature(input.components)
} else {
return input.type
}
}).join(',')})`;
}
let contractArguments = getContractArguments({ contract, method, params });
let contractMethod = contract.estimateGas[method];
if(contractArguments) {
return contractMethod(...contractArguments, { from, value })
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.3",
"version": "10.18.4",
"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.3",
"version": "10.18.4",
"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.3",
"version": "10.18.4",
"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
22 changes: 20 additions & 2 deletions src/platforms/evm/estimate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ const getContractArguments = ({ contract, method, params })=>{
}
}

const tupleParamsToMethodSignature = (components) =>{
return `(${
components.map((component)=>{
if(component.type === 'tuple') {
return tupleParamsToMethodSignature(component.components)
} else {
return component.type
}
}).join(',')
})`
}

export default ({ provider, from, to, value, method, api, params }) => {
if(typeof api == "undefined"){
return provider.estimateGas({ from, to, value })
Expand All @@ -22,10 +34,16 @@ export default ({ provider, from, to, value, method, api, params }) => {
let fragment = contract.interface.fragments.find((fragment) => {
return fragment.name == method
})
let contractArguments = getContractArguments({ contract, method, params })
if(contract[method] === undefined) {
method = `${method}(${fragment.inputs.map((input)=>input.type).join(',')})`
method = `${method}(${fragment.inputs.map((input)=>{
if(input.type === 'tuple') {
return tupleParamsToMethodSignature(input.components)
} else {
return input.type
}
}).join(',')})`
}
let contractArguments = getContractArguments({ contract, method, params })
let contractMethod = contract.estimateGas[method]
if(contractArguments) {
return contractMethod(...contractArguments, { from, value })
Expand Down

0 comments on commit e72e6d0

Please sign in to comment.