From ff00795ecbce4aff2cb2ab2c208be285ddab920b Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 21 May 2024 12:54:58 +0200 Subject: [PATCH] feat: extend from multicall3 in redstoneMulticall3 (#2697) * feat: extend from multicall3 in redstoneMulticall3 * fix: redeclaration of type * fix: use only single aggregate3 function - https://github.com/ethers-io/ethers.js/issues/407 --- .../RedstoneMulticall3.dbg.json | 2 +- .../RedstoneMulticall3.json | 396 +++++++++++++++++- .../contracts/RedstoneMulitcall3.sol | 184 +++++++- 3 files changed, 573 insertions(+), 9 deletions(-) diff --git a/packages/evm-multicall/artifacts/contracts/RedstoneMulitcall3.sol/RedstoneMulticall3.dbg.json b/packages/evm-multicall/artifacts/contracts/RedstoneMulitcall3.sol/RedstoneMulticall3.dbg.json index b11830820..ac8a427fd 100644 --- a/packages/evm-multicall/artifacts/contracts/RedstoneMulitcall3.sol/RedstoneMulticall3.dbg.json +++ b/packages/evm-multicall/artifacts/contracts/RedstoneMulitcall3.sol/RedstoneMulticall3.dbg.json @@ -1,4 +1,4 @@ { "_format": "hh-sol-dbg-1", - "buildInfo": "../../build-info/06fa9f6ea0cbb522e369c719af2cff60.json" + "buildInfo": "../../build-info/23ab2a120ebb5d6a20e22a76315eb6ec.json" } diff --git a/packages/evm-multicall/artifacts/contracts/RedstoneMulitcall3.sol/RedstoneMulticall3.json b/packages/evm-multicall/artifacts/contracts/RedstoneMulitcall3.sol/RedstoneMulticall3.json index 1c48ca523..8c6376639 100644 --- a/packages/evm-multicall/artifacts/contracts/RedstoneMulitcall3.sol/RedstoneMulticall3.json +++ b/packages/evm-multicall/artifacts/contracts/RedstoneMulitcall3.sol/RedstoneMulticall3.json @@ -3,6 +3,42 @@ "contractName": "RedstoneMulticall3", "sourceName": "contracts/RedstoneMulitcall3.sol", "abi": [ + { + "inputs": [ + { + "components": [ + { + "internalType": "address", + "name": "target", + "type": "address" + }, + { + "internalType": "bytes", + "name": "callData", + "type": "bytes" + } + ], + "internalType": "struct Multicall3.Call[]", + "name": "calls", + "type": "tuple[]" + } + ], + "name": "aggregate", + "outputs": [ + { + "internalType": "uint256", + "name": "blockNumber", + "type": "uint256" + }, + { + "internalType": "bytes[]", + "name": "returnData", + "type": "bytes[]" + } + ], + "stateMutability": "payable", + "type": "function" + }, { "inputs": [ { @@ -48,7 +84,361 @@ "type": "bytes" } ], - "internalType": "struct RedstoneMulticall3.Result[]", + "internalType": "struct Multicall3.Result[]", + "name": "returnData", + "type": "tuple[]" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "address", + "name": "target", + "type": "address" + }, + { + "internalType": "bool", + "name": "allowFailure", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "callData", + "type": "bytes" + } + ], + "internalType": "struct Multicall3.Call3Value[]", + "name": "calls", + "type": "tuple[]" + } + ], + "name": "aggregate3Value", + "outputs": [ + { + "components": [ + { + "internalType": "bool", + "name": "success", + "type": "bool" + }, + { + "internalType": "bytes", + "name": "returnData", + "type": "bytes" + } + ], + "internalType": "struct Multicall3.Result[]", + "name": "returnData", + "type": "tuple[]" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "address", + "name": "target", + "type": "address" + }, + { + "internalType": "bytes", + "name": "callData", + "type": "bytes" + } + ], + "internalType": "struct Multicall3.Call[]", + "name": "calls", + "type": "tuple[]" + } + ], + "name": "blockAndAggregate", + "outputs": [ + { + "internalType": "uint256", + "name": "blockNumber", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "blockHash", + "type": "bytes32" + }, + { + "components": [ + { + "internalType": "bool", + "name": "success", + "type": "bool" + }, + { + "internalType": "bytes", + "name": "returnData", + "type": "bytes" + } + ], + "internalType": "struct Multicall3.Result[]", + "name": "returnData", + "type": "tuple[]" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "getBasefee", + "outputs": [ + { + "internalType": "uint256", + "name": "basefee", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "blockNumber", + "type": "uint256" + } + ], + "name": "getBlockHash", + "outputs": [ + { + "internalType": "bytes32", + "name": "blockHash", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getBlockNumber", + "outputs": [ + { + "internalType": "uint256", + "name": "blockNumber", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getChainId", + "outputs": [ + { + "internalType": "uint256", + "name": "chainid", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getCurrentBlockCoinbase", + "outputs": [ + { + "internalType": "address", + "name": "coinbase", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getCurrentBlockDifficulty", + "outputs": [ + { + "internalType": "uint256", + "name": "difficulty", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getCurrentBlockGasLimit", + "outputs": [ + { + "internalType": "uint256", + "name": "gaslimit", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getCurrentBlockTimestamp", + "outputs": [ + { + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "addr", + "type": "address" + } + ], + "name": "getEthBalance", + "outputs": [ + { + "internalType": "uint256", + "name": "balance", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getLastBlockHash", + "outputs": [ + { + "internalType": "bytes32", + "name": "blockHash", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bool", + "name": "requireSuccess", + "type": "bool" + }, + { + "components": [ + { + "internalType": "address", + "name": "target", + "type": "address" + }, + { + "internalType": "bytes", + "name": "callData", + "type": "bytes" + } + ], + "internalType": "struct Multicall3.Call[]", + "name": "calls", + "type": "tuple[]" + } + ], + "name": "tryAggregate", + "outputs": [ + { + "components": [ + { + "internalType": "bool", + "name": "success", + "type": "bool" + }, + { + "internalType": "bytes", + "name": "returnData", + "type": "bytes" + } + ], + "internalType": "struct Multicall3.Result[]", + "name": "returnData", + "type": "tuple[]" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bool", + "name": "requireSuccess", + "type": "bool" + }, + { + "components": [ + { + "internalType": "address", + "name": "target", + "type": "address" + }, + { + "internalType": "bytes", + "name": "callData", + "type": "bytes" + } + ], + "internalType": "struct Multicall3.Call[]", + "name": "calls", + "type": "tuple[]" + } + ], + "name": "tryBlockAndAggregate", + "outputs": [ + { + "internalType": "uint256", + "name": "blockNumber", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "blockHash", + "type": "bytes32" + }, + { + "components": [ + { + "internalType": "bool", + "name": "success", + "type": "bool" + }, + { + "internalType": "bytes", + "name": "returnData", + "type": "bytes" + } + ], + "internalType": "struct Multicall3.Result[]", "name": "returnData", "type": "tuple[]" } @@ -57,8 +447,8 @@ "type": "function" } ], - "bytecode": "0x608060405234801561001057600080fd5b506106d8806100206000396000f3fe60806040526004361061001e5760003560e01c80639867906414610023575b600080fd5b61003d600480360381019061003891906102ae565b610053565b60405161004a91906104a5565b60405180910390f35b606060008383905090508067ffffffffffffffff811115610077576100766104c7565b5b6040519080825280602002602001820160405280156100b057816020015b61009d610223565b8152602001906001900390816100955790505b5091503660005b8281101561021a5760008482815181106100d4576100d36104f6565b5b602002602001015190508686838181106100f1576100f06104f6565b5b90506020028101906101039190610534565b925082600001602081019061011891906105ba565b73ffffffffffffffffffffffffffffffffffffffff16836060013584806040019061014391906105e7565b604051610151929190610689565b60006040518083038160008787f1925050503d806000811461018f576040519150601f19603f3d011682016040523d82523d6000602084013e610194565b606091505b50826000018360200182905282151515158152505050805160208401351761020e577f08c379a000000000000000000000000000000000000000000000000000000000600052602060045260176024527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060445260646000fd5b816001019150506100b7565b50505092915050565b6040518060400160405280600015158152602001606081525090565b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b60008083601f84011261026e5761026d610249565b5b8235905067ffffffffffffffff81111561028b5761028a61024e565b5b6020830191508360208202830111156102a7576102a6610253565b5b9250929050565b600080602083850312156102c5576102c461023f565b5b600083013567ffffffffffffffff8111156102e3576102e2610244565b5b6102ef85828601610258565b92509250509250929050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b60008115159050919050565b61033c81610327565b82525050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561037c578082015181840152602081019050610361565b60008484015250505050565b6000601f19601f8301169050919050565b60006103a482610342565b6103ae818561034d565b93506103be81856020860161035e565b6103c781610388565b840191505092915050565b60006040830160008301516103ea6000860182610333565b50602083015184820360208601526104028282610399565b9150508091505092915050565b600061041b83836103d2565b905092915050565b6000602082019050919050565b600061043b826102fb565b6104458185610306565b93508360208202850161045785610317565b8060005b858110156104935784840389528151610474858261040f565b945061047f83610423565b925060208a0199505060018101905061045b565b50829750879550505050505092915050565b600060208201905081810360008301526104bf8184610430565b905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600080fd5b600080fd5b600080fd5b6000823560016080038336030381126105505761054f610525565b5b80830191505092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006105878261055c565b9050919050565b6105978161057c565b81146105a257600080fd5b50565b6000813590506105b48161058e565b92915050565b6000602082840312156105d0576105cf61023f565b5b60006105de848285016105a5565b91505092915050565b6000808335600160200384360303811261060457610603610525565b5b80840192508235915067ffffffffffffffff8211156106265761062561052a565b5b6020830192506001820236038313156106425761064161052f565b5b509250929050565b600081905092915050565b82818337600083830152505050565b6000610670838561064a565b935061067d838584610655565b82840190509392505050565b6000610696828486610664565b9150819050939250505056fea264697066735822122085729ec4c95061144d57c7b4d3132348b70b4e1a30018b17f896f6efafcf29fb64736f6c63430008120033", - "deployedBytecode": "0x60806040526004361061001e5760003560e01c80639867906414610023575b600080fd5b61003d600480360381019061003891906102ae565b610053565b60405161004a91906104a5565b60405180910390f35b606060008383905090508067ffffffffffffffff811115610077576100766104c7565b5b6040519080825280602002602001820160405280156100b057816020015b61009d610223565b8152602001906001900390816100955790505b5091503660005b8281101561021a5760008482815181106100d4576100d36104f6565b5b602002602001015190508686838181106100f1576100f06104f6565b5b90506020028101906101039190610534565b925082600001602081019061011891906105ba565b73ffffffffffffffffffffffffffffffffffffffff16836060013584806040019061014391906105e7565b604051610151929190610689565b60006040518083038160008787f1925050503d806000811461018f576040519150601f19603f3d011682016040523d82523d6000602084013e610194565b606091505b50826000018360200182905282151515158152505050805160208401351761020e577f08c379a000000000000000000000000000000000000000000000000000000000600052602060045260176024527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060445260646000fd5b816001019150506100b7565b50505092915050565b6040518060400160405280600015158152602001606081525090565b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b60008083601f84011261026e5761026d610249565b5b8235905067ffffffffffffffff81111561028b5761028a61024e565b5b6020830191508360208202830111156102a7576102a6610253565b5b9250929050565b600080602083850312156102c5576102c461023f565b5b600083013567ffffffffffffffff8111156102e3576102e2610244565b5b6102ef85828601610258565b92509250509250929050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b60008115159050919050565b61033c81610327565b82525050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561037c578082015181840152602081019050610361565b60008484015250505050565b6000601f19601f8301169050919050565b60006103a482610342565b6103ae818561034d565b93506103be81856020860161035e565b6103c781610388565b840191505092915050565b60006040830160008301516103ea6000860182610333565b50602083015184820360208601526104028282610399565b9150508091505092915050565b600061041b83836103d2565b905092915050565b6000602082019050919050565b600061043b826102fb565b6104458185610306565b93508360208202850161045785610317565b8060005b858110156104935784840389528151610474858261040f565b945061047f83610423565b925060208a0199505060018101905061045b565b50829750879550505050505092915050565b600060208201905081810360008301526104bf8184610430565b905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600080fd5b600080fd5b600080fd5b6000823560016080038336030381126105505761054f610525565b5b80830191505092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006105878261055c565b9050919050565b6105978161057c565b81146105a257600080fd5b50565b6000813590506105b48161058e565b92915050565b6000602082840312156105d0576105cf61023f565b5b60006105de848285016105a5565b91505092915050565b6000808335600160200384360303811261060457610603610525565b5b80840192508235915067ffffffffffffffff8211156106265761062561052a565b5b6020830192506001820236038313156106425761064161052f565b5b509250929050565b600081905092915050565b82818337600083830152505050565b6000610670838561064a565b935061067d838584610655565b82840190509392505050565b6000610696828486610664565b9150819050939250505056fea264697066735822122085729ec4c95061144d57c7b4d3132348b70b4e1a30018b17f896f6efafcf29fb64736f6c63430008120033", + "bytecode": "0x608060405234801561001057600080fd5b50611886806100206000396000f3fe6080604052600436106100fe5760003560e01c80634d2301cc1161009557806398679064116100645780639867906414610330578063a8b0574e14610360578063bce38bd71461038b578063c3077fa9146103bb578063ee82ac5e146103ed576100fe565b80634d2301cc1461026d57806372425d9d146102aa57806382ad56cb146102d557806386d516e814610305576100fe565b80633408e470116100d15780633408e470146101ba578063399542e9146101e55780633e64a6961461021757806342cbb15c14610242576100fe565b80630f28c97d14610103578063174dea711461012e578063252dba421461015e57806327e86d6e1461018f575b600080fd5b34801561010f57600080fd5b5061011861042a565b6040516101259190610e15565b60405180910390f35b61014860048036038101906101439190610e9f565b610432565b6040516101559190611096565b60405180910390f35b6101786004803603810190610173919061110e565b610650565b60405161018692919061121d565b60405180910390f35b34801561019b57600080fd5b506101a46107e6565b6040516101b19190611266565b60405180910390f35b3480156101c657600080fd5b506101cf6107f2565b6040516101dc9190610e15565b60405180910390f35b6101ff60048036038101906101fa91906112ad565b6107fa565b60405161020e9392919061130d565b60405180910390f35b34801561022357600080fd5b5061022c61081c565b6040516102399190610e15565b60405180910390f35b34801561024e57600080fd5b50610257610824565b6040516102649190610e15565b60405180910390f35b34801561027957600080fd5b50610294600480360381019061028f91906113a9565b61082c565b6040516102a19190610e15565b60405180910390f35b3480156102b657600080fd5b506102bf61084d565b6040516102cc9190610e15565b60405180910390f35b6102ef60048036038101906102ea919061142c565b610855565b6040516102fc9190611096565b60405180910390f35b34801561031157600080fd5b5061031a610a1f565b6040516103279190610e15565b60405180910390f35b61034a600480360381019061034591906114cf565b610a27565b6040516103579190611096565b60405180910390f35b34801561036c57600080fd5b50610375610bf7565b604051610382919061152b565b60405180910390f35b6103a560048036038101906103a091906112ad565b610bff565b6040516103b29190611096565b60405180910390f35b6103d560048036038101906103d0919061110e565b610db1565b6040516103e49392919061130d565b60405180910390f35b3480156103f957600080fd5b50610414600480360381019061040f9190611572565b610dd5565b6040516104219190611266565b60405180910390f35b600042905090565b60606000808484905090508067ffffffffffffffff8111156104575761045661159f565b5b60405190808252806020026020018201604052801561049057816020015b61047d610de0565b8152602001906001900390816104755790505b5092503660005b828110156106045760008582815181106104b4576104b36115ce565b5b602002602001015190508787838181106104d1576104d06115ce565b5b90506020028101906104e3919061160c565b9250600083604001359050808601955083600001602081019061050691906113a9565b73ffffffffffffffffffffffffffffffffffffffff168185806060019061052d9190611634565b60405161053b9291906116d6565b60006040518083038185875af1925050503d8060008114610578576040519150601f19603f3d011682016040523d82523d6000602084013e61057d565b606091505b5083600001846020018290528215151515815250505081516020850135176105f7577f08c379a000000000000000000000000000000000000000000000000000000000600052602060045260176024527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060445260846000fd5b8260010192505050610497565b50823414610647576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161063e9061174c565b60405180910390fd5b50505092915050565b6000606043915060008484905090508067ffffffffffffffff8111156106795761067861159f565b5b6040519080825280602002602001820160405280156106ac57816020015b60608152602001906001900390816106975790505b5091503660005b828110156107dc5760008787838181106106d0576106cf6115ce565b5b90506020028101906106e2919061176c565b92508260000160208101906106f791906113a9565b73ffffffffffffffffffffffffffffffffffffffff1683806020019061071d9190611634565b60405161072b9291906116d6565b6000604051808303816000865af19150503d8060008114610768576040519150601f19603f3d011682016040523d82523d6000602084013e61076d565b606091505b50868481518110610781576107806115ce565b5b602002602001018190528192505050806107d0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107c7906117e0565b60405180910390fd5b816001019150506106b3565b5050509250929050565b60006001430340905090565b600046905090565b600080606043925043409150610811868686610bff565b905093509350939050565b600048905090565b600043905090565b60008173ffffffffffffffffffffffffffffffffffffffff16319050919050565b600044905090565b606060008383905090508067ffffffffffffffff8111156108795761087861159f565b5b6040519080825280602002602001820160405280156108b257816020015b61089f610de0565b8152602001906001900390816108975790505b5091503660005b82811015610a165760008482815181106108d6576108d56115ce565b5b602002602001015190508686838181106108f3576108f26115ce565b5b90506020028101906109059190611800565b925082600001602081019061091a91906113a9565b73ffffffffffffffffffffffffffffffffffffffff168380604001906109409190611634565b60405161094e9291906116d6565b6000604051808303816000865af19150503d806000811461098b576040519150601f19603f3d011682016040523d82523d6000602084013e610990565b606091505b508260000183602001829052821515151581525050508051602084013517610a0a577f08c379a000000000000000000000000000000000000000000000000000000000600052602060045260176024527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060445260646000fd5b816001019150506108b9565b50505092915050565b600045905090565b606060008383905090508067ffffffffffffffff811115610a4b57610a4a61159f565b5b604051908082528060200260200182016040528015610a8457816020015b610a71610de0565b815260200190600190039081610a695790505b5091503660005b82811015610bee576000848281518110610aa857610aa76115ce565b5b60200260200101519050868683818110610ac557610ac46115ce565b5b9050602002810190610ad79190611828565b9250826000016020810190610aec91906113a9565b73ffffffffffffffffffffffffffffffffffffffff168360600135848060400190610b179190611634565b604051610b259291906116d6565b60006040518083038160008787f1925050503d8060008114610b63576040519150601f19603f3d011682016040523d82523d6000602084013e610b68565b606091505b508260000183602001829052821515151581525050508051602084013517610be2577f08c379a000000000000000000000000000000000000000000000000000000000600052602060045260176024527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060445260646000fd5b81600101915050610a8b565b50505092915050565b600041905090565b606060008383905090508067ffffffffffffffff811115610c2357610c2261159f565b5b604051908082528060200260200182016040528015610c5c57816020015b610c49610de0565b815260200190600190039081610c415790505b5091503660005b82811015610da7576000848281518110610c8057610c7f6115ce565b5b60200260200101519050868683818110610c9d57610c9c6115ce565b5b9050602002810190610caf919061176c565b9250826000016020810190610cc491906113a9565b73ffffffffffffffffffffffffffffffffffffffff16838060200190610cea9190611634565b604051610cf89291906116d6565b6000604051808303816000865af19150503d8060008114610d35576040519150601f19603f3d011682016040523d82523d6000602084013e610d3a565b606091505b508260000183602001829052821515151581525050508715610d9b578060000151610d9a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d91906117e0565b60405180910390fd5b5b81600101915050610c63565b5050509392505050565b6000806060610dc2600186866107fa565b8093508194508295505050509250925092565b600081409050919050565b6040518060400160405280600015158152602001606081525090565b6000819050919050565b610e0f81610dfc565b82525050565b6000602082019050610e2a6000830184610e06565b92915050565b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b60008083601f840112610e5f57610e5e610e3a565b5b8235905067ffffffffffffffff811115610e7c57610e7b610e3f565b5b602083019150836020820283011115610e9857610e97610e44565b5b9250929050565b60008060208385031215610eb657610eb5610e30565b5b600083013567ffffffffffffffff811115610ed457610ed3610e35565b5b610ee085828601610e49565b92509250509250929050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b60008115159050919050565b610f2d81610f18565b82525050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610f6d578082015181840152602081019050610f52565b60008484015250505050565b6000601f19601f8301169050919050565b6000610f9582610f33565b610f9f8185610f3e565b9350610faf818560208601610f4f565b610fb881610f79565b840191505092915050565b6000604083016000830151610fdb6000860182610f24565b5060208301518482036020860152610ff38282610f8a565b9150508091505092915050565b600061100c8383610fc3565b905092915050565b6000602082019050919050565b600061102c82610eec565b6110368185610ef7565b93508360208202850161104885610f08565b8060005b8581101561108457848403895281516110658582611000565b945061107083611014565b925060208a0199505060018101905061104c565b50829750879550505050505092915050565b600060208201905081810360008301526110b08184611021565b905092915050565b60008083601f8401126110ce576110cd610e3a565b5b8235905067ffffffffffffffff8111156110eb576110ea610e3f565b5b60208301915083602082028301111561110757611106610e44565b5b9250929050565b6000806020838503121561112557611124610e30565b5b600083013567ffffffffffffffff81111561114357611142610e35565b5b61114f858286016110b8565b92509250509250929050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b60006111938383610f8a565b905092915050565b6000602082019050919050565b60006111b38261115b565b6111bd8185611166565b9350836020820285016111cf85611177565b8060005b8581101561120b57848403895281516111ec8582611187565b94506111f78361119b565b925060208a019950506001810190506111d3565b50829750879550505050505092915050565b60006040820190506112326000830185610e06565b818103602083015261124481846111a8565b90509392505050565b6000819050919050565b6112608161124d565b82525050565b600060208201905061127b6000830184611257565b92915050565b61128a81610f18565b811461129557600080fd5b50565b6000813590506112a781611281565b92915050565b6000806000604084860312156112c6576112c5610e30565b5b60006112d486828701611298565b935050602084013567ffffffffffffffff8111156112f5576112f4610e35565b5b611301868287016110b8565b92509250509250925092565b60006060820190506113226000830186610e06565b61132f6020830185611257565b81810360408301526113418184611021565b9050949350505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006113768261134b565b9050919050565b6113868161136b565b811461139157600080fd5b50565b6000813590506113a38161137d565b92915050565b6000602082840312156113bf576113be610e30565b5b60006113cd84828501611394565b91505092915050565b60008083601f8401126113ec576113eb610e3a565b5b8235905067ffffffffffffffff81111561140957611408610e3f565b5b60208301915083602082028301111561142557611424610e44565b5b9250929050565b6000806020838503121561144357611442610e30565b5b600083013567ffffffffffffffff81111561146157611460610e35565b5b61146d858286016113d6565b92509250509250929050565b60008083601f84011261148f5761148e610e3a565b5b8235905067ffffffffffffffff8111156114ac576114ab610e3f565b5b6020830191508360208202830111156114c8576114c7610e44565b5b9250929050565b600080602083850312156114e6576114e5610e30565b5b600083013567ffffffffffffffff81111561150457611503610e35565b5b61151085828601611479565b92509250509250929050565b6115258161136b565b82525050565b6000602082019050611540600083018461151c565b92915050565b61154f81610dfc565b811461155a57600080fd5b50565b60008135905061156c81611546565b92915050565b60006020828403121561158857611587610e30565b5b60006115968482850161155d565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600080fd5b600080fd5b600080fd5b600082356001608003833603038112611628576116276115fd565b5b80830191505092915050565b60008083356001602003843603038112611651576116506115fd565b5b80840192508235915067ffffffffffffffff82111561167357611672611602565b5b60208301925060018202360383131561168f5761168e611607565b5b509250929050565b600081905092915050565b82818337600083830152505050565b60006116bd8385611697565b93506116ca8385846116a2565b82840190509392505050565b60006116e38284866116b1565b91508190509392505050565b600082825260208201905092915050565b7f4d756c746963616c6c333a2076616c7565206d69736d61746368000000000000600082015250565b6000611736601a836116ef565b915061174182611700565b602082019050919050565b6000602082019050818103600083015261176581611729565b9050919050565b600082356001604003833603038112611788576117876115fd565b5b80830191505092915050565b7f4d756c746963616c6c333a2063616c6c206661696c6564000000000000000000600082015250565b60006117ca6017836116ef565b91506117d582611794565b602082019050919050565b600060208201905081810360008301526117f9816117bd565b9050919050565b60008235600160600383360303811261181c5761181b6115fd565b5b80830191505092915050565b600082356001608003833603038112611844576118436115fd565b5b8083019150509291505056fea2646970667358221220cd2a24bdf708afb33003af898f47cdce0e9d16a1583812625880557da34c22f264736f6c63430008120033", + "deployedBytecode": "0x6080604052600436106100fe5760003560e01c80634d2301cc1161009557806398679064116100645780639867906414610330578063a8b0574e14610360578063bce38bd71461038b578063c3077fa9146103bb578063ee82ac5e146103ed576100fe565b80634d2301cc1461026d57806372425d9d146102aa57806382ad56cb146102d557806386d516e814610305576100fe565b80633408e470116100d15780633408e470146101ba578063399542e9146101e55780633e64a6961461021757806342cbb15c14610242576100fe565b80630f28c97d14610103578063174dea711461012e578063252dba421461015e57806327e86d6e1461018f575b600080fd5b34801561010f57600080fd5b5061011861042a565b6040516101259190610e15565b60405180910390f35b61014860048036038101906101439190610e9f565b610432565b6040516101559190611096565b60405180910390f35b6101786004803603810190610173919061110e565b610650565b60405161018692919061121d565b60405180910390f35b34801561019b57600080fd5b506101a46107e6565b6040516101b19190611266565b60405180910390f35b3480156101c657600080fd5b506101cf6107f2565b6040516101dc9190610e15565b60405180910390f35b6101ff60048036038101906101fa91906112ad565b6107fa565b60405161020e9392919061130d565b60405180910390f35b34801561022357600080fd5b5061022c61081c565b6040516102399190610e15565b60405180910390f35b34801561024e57600080fd5b50610257610824565b6040516102649190610e15565b60405180910390f35b34801561027957600080fd5b50610294600480360381019061028f91906113a9565b61082c565b6040516102a19190610e15565b60405180910390f35b3480156102b657600080fd5b506102bf61084d565b6040516102cc9190610e15565b60405180910390f35b6102ef60048036038101906102ea919061142c565b610855565b6040516102fc9190611096565b60405180910390f35b34801561031157600080fd5b5061031a610a1f565b6040516103279190610e15565b60405180910390f35b61034a600480360381019061034591906114cf565b610a27565b6040516103579190611096565b60405180910390f35b34801561036c57600080fd5b50610375610bf7565b604051610382919061152b565b60405180910390f35b6103a560048036038101906103a091906112ad565b610bff565b6040516103b29190611096565b60405180910390f35b6103d560048036038101906103d0919061110e565b610db1565b6040516103e49392919061130d565b60405180910390f35b3480156103f957600080fd5b50610414600480360381019061040f9190611572565b610dd5565b6040516104219190611266565b60405180910390f35b600042905090565b60606000808484905090508067ffffffffffffffff8111156104575761045661159f565b5b60405190808252806020026020018201604052801561049057816020015b61047d610de0565b8152602001906001900390816104755790505b5092503660005b828110156106045760008582815181106104b4576104b36115ce565b5b602002602001015190508787838181106104d1576104d06115ce565b5b90506020028101906104e3919061160c565b9250600083604001359050808601955083600001602081019061050691906113a9565b73ffffffffffffffffffffffffffffffffffffffff168185806060019061052d9190611634565b60405161053b9291906116d6565b60006040518083038185875af1925050503d8060008114610578576040519150601f19603f3d011682016040523d82523d6000602084013e61057d565b606091505b5083600001846020018290528215151515815250505081516020850135176105f7577f08c379a000000000000000000000000000000000000000000000000000000000600052602060045260176024527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060445260846000fd5b8260010192505050610497565b50823414610647576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161063e9061174c565b60405180910390fd5b50505092915050565b6000606043915060008484905090508067ffffffffffffffff8111156106795761067861159f565b5b6040519080825280602002602001820160405280156106ac57816020015b60608152602001906001900390816106975790505b5091503660005b828110156107dc5760008787838181106106d0576106cf6115ce565b5b90506020028101906106e2919061176c565b92508260000160208101906106f791906113a9565b73ffffffffffffffffffffffffffffffffffffffff1683806020019061071d9190611634565b60405161072b9291906116d6565b6000604051808303816000865af19150503d8060008114610768576040519150601f19603f3d011682016040523d82523d6000602084013e61076d565b606091505b50868481518110610781576107806115ce565b5b602002602001018190528192505050806107d0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107c7906117e0565b60405180910390fd5b816001019150506106b3565b5050509250929050565b60006001430340905090565b600046905090565b600080606043925043409150610811868686610bff565b905093509350939050565b600048905090565b600043905090565b60008173ffffffffffffffffffffffffffffffffffffffff16319050919050565b600044905090565b606060008383905090508067ffffffffffffffff8111156108795761087861159f565b5b6040519080825280602002602001820160405280156108b257816020015b61089f610de0565b8152602001906001900390816108975790505b5091503660005b82811015610a165760008482815181106108d6576108d56115ce565b5b602002602001015190508686838181106108f3576108f26115ce565b5b90506020028101906109059190611800565b925082600001602081019061091a91906113a9565b73ffffffffffffffffffffffffffffffffffffffff168380604001906109409190611634565b60405161094e9291906116d6565b6000604051808303816000865af19150503d806000811461098b576040519150601f19603f3d011682016040523d82523d6000602084013e610990565b606091505b508260000183602001829052821515151581525050508051602084013517610a0a577f08c379a000000000000000000000000000000000000000000000000000000000600052602060045260176024527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060445260646000fd5b816001019150506108b9565b50505092915050565b600045905090565b606060008383905090508067ffffffffffffffff811115610a4b57610a4a61159f565b5b604051908082528060200260200182016040528015610a8457816020015b610a71610de0565b815260200190600190039081610a695790505b5091503660005b82811015610bee576000848281518110610aa857610aa76115ce565b5b60200260200101519050868683818110610ac557610ac46115ce565b5b9050602002810190610ad79190611828565b9250826000016020810190610aec91906113a9565b73ffffffffffffffffffffffffffffffffffffffff168360600135848060400190610b179190611634565b604051610b259291906116d6565b60006040518083038160008787f1925050503d8060008114610b63576040519150601f19603f3d011682016040523d82523d6000602084013e610b68565b606091505b508260000183602001829052821515151581525050508051602084013517610be2577f08c379a000000000000000000000000000000000000000000000000000000000600052602060045260176024527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060445260646000fd5b81600101915050610a8b565b50505092915050565b600041905090565b606060008383905090508067ffffffffffffffff811115610c2357610c2261159f565b5b604051908082528060200260200182016040528015610c5c57816020015b610c49610de0565b815260200190600190039081610c415790505b5091503660005b82811015610da7576000848281518110610c8057610c7f6115ce565b5b60200260200101519050868683818110610c9d57610c9c6115ce565b5b9050602002810190610caf919061176c565b9250826000016020810190610cc491906113a9565b73ffffffffffffffffffffffffffffffffffffffff16838060200190610cea9190611634565b604051610cf89291906116d6565b6000604051808303816000865af19150503d8060008114610d35576040519150601f19603f3d011682016040523d82523d6000602084013e610d3a565b606091505b508260000183602001829052821515151581525050508715610d9b578060000151610d9a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d91906117e0565b60405180910390fd5b5b81600101915050610c63565b5050509392505050565b6000806060610dc2600186866107fa565b8093508194508295505050509250925092565b600081409050919050565b6040518060400160405280600015158152602001606081525090565b6000819050919050565b610e0f81610dfc565b82525050565b6000602082019050610e2a6000830184610e06565b92915050565b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b60008083601f840112610e5f57610e5e610e3a565b5b8235905067ffffffffffffffff811115610e7c57610e7b610e3f565b5b602083019150836020820283011115610e9857610e97610e44565b5b9250929050565b60008060208385031215610eb657610eb5610e30565b5b600083013567ffffffffffffffff811115610ed457610ed3610e35565b5b610ee085828601610e49565b92509250509250929050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b60008115159050919050565b610f2d81610f18565b82525050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610f6d578082015181840152602081019050610f52565b60008484015250505050565b6000601f19601f8301169050919050565b6000610f9582610f33565b610f9f8185610f3e565b9350610faf818560208601610f4f565b610fb881610f79565b840191505092915050565b6000604083016000830151610fdb6000860182610f24565b5060208301518482036020860152610ff38282610f8a565b9150508091505092915050565b600061100c8383610fc3565b905092915050565b6000602082019050919050565b600061102c82610eec565b6110368185610ef7565b93508360208202850161104885610f08565b8060005b8581101561108457848403895281516110658582611000565b945061107083611014565b925060208a0199505060018101905061104c565b50829750879550505050505092915050565b600060208201905081810360008301526110b08184611021565b905092915050565b60008083601f8401126110ce576110cd610e3a565b5b8235905067ffffffffffffffff8111156110eb576110ea610e3f565b5b60208301915083602082028301111561110757611106610e44565b5b9250929050565b6000806020838503121561112557611124610e30565b5b600083013567ffffffffffffffff81111561114357611142610e35565b5b61114f858286016110b8565b92509250509250929050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b60006111938383610f8a565b905092915050565b6000602082019050919050565b60006111b38261115b565b6111bd8185611166565b9350836020820285016111cf85611177565b8060005b8581101561120b57848403895281516111ec8582611187565b94506111f78361119b565b925060208a019950506001810190506111d3565b50829750879550505050505092915050565b60006040820190506112326000830185610e06565b818103602083015261124481846111a8565b90509392505050565b6000819050919050565b6112608161124d565b82525050565b600060208201905061127b6000830184611257565b92915050565b61128a81610f18565b811461129557600080fd5b50565b6000813590506112a781611281565b92915050565b6000806000604084860312156112c6576112c5610e30565b5b60006112d486828701611298565b935050602084013567ffffffffffffffff8111156112f5576112f4610e35565b5b611301868287016110b8565b92509250509250925092565b60006060820190506113226000830186610e06565b61132f6020830185611257565b81810360408301526113418184611021565b9050949350505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006113768261134b565b9050919050565b6113868161136b565b811461139157600080fd5b50565b6000813590506113a38161137d565b92915050565b6000602082840312156113bf576113be610e30565b5b60006113cd84828501611394565b91505092915050565b60008083601f8401126113ec576113eb610e3a565b5b8235905067ffffffffffffffff81111561140957611408610e3f565b5b60208301915083602082028301111561142557611424610e44565b5b9250929050565b6000806020838503121561144357611442610e30565b5b600083013567ffffffffffffffff81111561146157611460610e35565b5b61146d858286016113d6565b92509250509250929050565b60008083601f84011261148f5761148e610e3a565b5b8235905067ffffffffffffffff8111156114ac576114ab610e3f565b5b6020830191508360208202830111156114c8576114c7610e44565b5b9250929050565b600080602083850312156114e6576114e5610e30565b5b600083013567ffffffffffffffff81111561150457611503610e35565b5b61151085828601611479565b92509250509250929050565b6115258161136b565b82525050565b6000602082019050611540600083018461151c565b92915050565b61154f81610dfc565b811461155a57600080fd5b50565b60008135905061156c81611546565b92915050565b60006020828403121561158857611587610e30565b5b60006115968482850161155d565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600080fd5b600080fd5b600080fd5b600082356001608003833603038112611628576116276115fd565b5b80830191505092915050565b60008083356001602003843603038112611651576116506115fd565b5b80840192508235915067ffffffffffffffff82111561167357611672611602565b5b60208301925060018202360383131561168f5761168e611607565b5b509250929050565b600081905092915050565b82818337600083830152505050565b60006116bd8385611697565b93506116ca8385846116a2565b82840190509392505050565b60006116e38284866116b1565b91508190509392505050565b600082825260208201905092915050565b7f4d756c746963616c6c333a2076616c7565206d69736d61746368000000000000600082015250565b6000611736601a836116ef565b915061174182611700565b602082019050919050565b6000602082019050818103600083015261176581611729565b9050919050565b600082356001604003833603038112611788576117876115fd565b5b80830191505092915050565b7f4d756c746963616c6c333a2063616c6c206661696c6564000000000000000000600082015250565b60006117ca6017836116ef565b91506117d582611794565b602082019050919050565b600060208201905081810360008301526117f9816117bd565b9050919050565b60008235600160600383360303811261181c5761181b6115fd565b5b80830191505092915050565b600082356001608003833603038112611844576118436115fd565b5b8083019150509291505056fea2646970667358221220cd2a24bdf708afb33003af898f47cdce0e9d16a1583812625880557da34c22f264736f6c63430008120033", "linkReferences": {}, "deployedLinkReferences": {} } diff --git a/packages/evm-multicall/contracts/RedstoneMulitcall3.sol b/packages/evm-multicall/contracts/RedstoneMulitcall3.sol index 0f6677014..a067e26c7 100644 --- a/packages/evm-multicall/contracts/RedstoneMulitcall3.sol +++ b/packages/evm-multicall/contracts/RedstoneMulitcall3.sol @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; + contract RedstoneMulticall3 { struct RedstoneCall3 { address target; @@ -9,11 +10,6 @@ contract RedstoneMulticall3 { uint256 gasLimit; } - struct Result { - bool success; - bytes returnData; - } - /// @notice Aggregate calls, ensuring each returns success if required /// @param calls An array of Call3 structs /// @return returnData An array of Result structs @@ -43,4 +39,182 @@ contract RedstoneMulticall3 { unchecked { ++i; } } } + + /** + IMPORTANT + Rest of the code is copied from import "./Mulitcall3.sol" (omitted aggregate3) we don't use inheritence to have single aggregate3 function + */ + + struct Call { + address target; + bytes callData; + } + + struct Call3 { + address target; + bool allowFailure; + bytes callData; + } + + struct Call3Value { + address target; + bool allowFailure; + uint256 value; + bytes callData; + } + + struct Result { + bool success; + bytes returnData; + } + + /// @notice Backwards-compatible call aggregation with Multicall + /// @param calls An array of Call structs + /// @return blockNumber The block number where the calls were executed + /// @return returnData An array of bytes containing the responses + function aggregate(Call[] calldata calls) public payable returns (uint256 blockNumber, bytes[] memory returnData) { + blockNumber = block.number; + uint256 length = calls.length; + returnData = new bytes[](length); + Call calldata call; + for (uint256 i = 0; i < length;) { + bool success; + call = calls[i]; + (success, returnData[i]) = call.target.call(call.callData); + require(success, "Multicall3: call failed"); + unchecked { ++i; } + } + } + + /// @notice Backwards-compatible with Multicall2 + /// @notice Aggregate calls without requiring success + /// @param requireSuccess If true, require all calls to succeed + /// @param calls An array of Call structs + /// @return returnData An array of Result structs + function tryAggregate(bool requireSuccess, Call[] calldata calls) public payable returns (Result[] memory returnData) { + uint256 length = calls.length; + returnData = new Result[](length); + Call calldata call; + for (uint256 i = 0; i < length;) { + Result memory result = returnData[i]; + call = calls[i]; + (result.success, result.returnData) = call.target.call(call.callData); + if (requireSuccess) require(result.success, "Multicall3: call failed"); + unchecked { ++i; } + } + } + + /// @notice Backwards-compatible with Multicall2 + /// @notice Aggregate calls and allow failures using tryAggregate + /// @param calls An array of Call structs + /// @return blockNumber The block number where the calls were executed + /// @return blockHash The hash of the block where the calls were executed + /// @return returnData An array of Result structs + function tryBlockAndAggregate(bool requireSuccess, Call[] calldata calls) public payable returns (uint256 blockNumber, bytes32 blockHash, Result[] memory returnData) { + blockNumber = block.number; + blockHash = blockhash(block.number); + returnData = tryAggregate(requireSuccess, calls); + } + + /// @notice Backwards-compatible with Multicall2 + /// @notice Aggregate calls and allow failures using tryAggregate + /// @param calls An array of Call structs + /// @return blockNumber The block number where the calls were executed + /// @return blockHash The hash of the block where the calls were executed + /// @return returnData An array of Result structs + function blockAndAggregate(Call[] calldata calls) public payable returns (uint256 blockNumber, bytes32 blockHash, Result[] memory returnData) { + (blockNumber, blockHash, returnData) = tryBlockAndAggregate(true, calls); + } + + /// @notice Aggregate calls with a msg value + /// @notice Reverts if msg.value is less than the sum of the call values + /// @param calls An array of Call3Value structs + /// @return returnData An array of Result structs + function aggregate3Value(Call3Value[] calldata calls) public payable returns (Result[] memory returnData) { + uint256 valAccumulator; + uint256 length = calls.length; + returnData = new Result[](length); + Call3Value calldata calli; + for (uint256 i = 0; i < length;) { + Result memory result = returnData[i]; + calli = calls[i]; + uint256 val = calli.value; + // Humanity will be a Type V Kardashev Civilization before this overflows - andreas + // ~ 10^25 Wei in existence << ~ 10^76 size uint fits in a uint256 + unchecked { valAccumulator += val; } + (result.success, result.returnData) = calli.target.call{value: val}(calli.callData); + assembly { + // Revert if the call fails and failure is not allowed + // `allowFailure := calldataload(add(calli, 0x20))` and `success := mload(result)` + if iszero(or(calldataload(add(calli, 0x20)), mload(result))) { + // set "Error(string)" signature: bytes32(bytes4(keccak256("Error(string)"))) + mstore(0x00, 0x08c379a000000000000000000000000000000000000000000000000000000000) + // set data offset + mstore(0x04, 0x0000000000000000000000000000000000000000000000000000000000000020) + // set length of revert string + mstore(0x24, 0x0000000000000000000000000000000000000000000000000000000000000017) + // set revert string: bytes32(abi.encodePacked("Multicall3: call failed")) + mstore(0x44, 0x4d756c746963616c6c333a2063616c6c206661696c6564000000000000000000) + revert(0x00, 0x84) + } + } + unchecked { ++i; } + } + // Finally, make sure the msg.value = SUM(call[0...i].value) + require(msg.value == valAccumulator, "Multicall3: value mismatch"); + } + + /// @notice Returns the block hash for the given block number + /// @param blockNumber The block number + function getBlockHash(uint256 blockNumber) public view returns (bytes32 blockHash) { + blockHash = blockhash(blockNumber); + } + + /// @notice Returns the block number + function getBlockNumber() public view returns (uint256 blockNumber) { + blockNumber = block.number; + } + + /// @notice Returns the block coinbase + function getCurrentBlockCoinbase() public view returns (address coinbase) { + coinbase = block.coinbase; + } + + /// @notice Returns the block difficulty + function getCurrentBlockDifficulty() public view returns (uint256 difficulty) { + difficulty = block.difficulty; + } + + /// @notice Returns the block gas limit + function getCurrentBlockGasLimit() public view returns (uint256 gaslimit) { + gaslimit = block.gaslimit; + } + + /// @notice Returns the block timestamp + function getCurrentBlockTimestamp() public view returns (uint256 timestamp) { + timestamp = block.timestamp; + } + + /// @notice Returns the (ETH) balance of a given address + function getEthBalance(address addr) public view returns (uint256 balance) { + balance = addr.balance; + } + + /// @notice Returns the block hash of the last block + function getLastBlockHash() public view returns (bytes32 blockHash) { + unchecked { + blockHash = blockhash(block.number - 1); + } + } + + /// @notice Gets the base fee of the given block + /// @notice Can revert if the BASEFEE opcode is not implemented by the given chain + function getBasefee() public view returns (uint256 basefee) { + basefee = block.basefee; + } + + /// @notice Returns the chain id + function getChainId() public view returns (uint256 chainid) { + chainid = block.chainid; + } }