From 8f09fc246cd34ca691f8eb03b1537ff66b313970 Mon Sep 17 00:00:00 2001 From: Nicholas Rodrigues Lordello Date: Fri, 22 Nov 2024 18:04:05 +0100 Subject: [PATCH 1/2] Simulated Token Balances for Verified Quotes This PR is a follow up to #3125 and uses the component introduced in the aforementioned PR for setting up a simulated token balance using state overrides in order for quote verification to work even when the trader does not have sufficient balance. The way it works is by configuring known mapping slots for the `mapping(address => uint256) balances` in ERC20 token contract implementations and using this to compute the slot for overriding a separate account's token balance (the `Spardose`), which can prefund the trader during quote simualtions. We intentionally do not override the trader's or solver's balance in order to not interfere with the settlement process: > Technically a solver could have private inventory they would like to > use for the solution instead of transfering it to the trader. _Posted by @MartinquaXD_ Note that the type of the state override changed slightly. This is because it was wrong to begin with. Node implementations I tested with (Geth and Anvil) expect both the slot and the value for state overrides to be exactly 32-bytes long (so `H256`). I guess this feature of the state override in the `ethrpc` crate was not used in the past and therefore no one noticed :shrug:. ### Test Plan Added an E2E test that uses the new token balance override feature in order to produce a verified quote for a trader with no balances. Note that commenting out the API arguments causes the test to fail as expected. --- crates/contracts/artifacts/Solver.json | 2 +- crates/contracts/artifacts/Spardose.json | 1 + crates/contracts/artifacts/Swapper.json | 2 +- crates/contracts/artifacts/Trader.json | 2 +- crates/contracts/build.rs | 3 +- crates/contracts/solidity/Makefile | 1 + crates/contracts/solidity/Solver.sol | 32 ++++-- crates/contracts/solidity/Spardose.sol | 34 ++++++ crates/contracts/solidity/Trader.sol | 3 - .../solidity/libraries/SafeERC20.sol | 17 ++- crates/contracts/src/lib.rs | 1 + crates/e2e/tests/e2e/quote_verification.rs | 102 +++++++++++++++++- crates/ethrpc/src/extensions.rs | 4 +- crates/shared/src/code_simulation.rs | 17 +-- crates/shared/src/price_estimation/factory.rs | 24 +++-- crates/shared/src/price_estimation/mod.rs | 11 ++ .../src/price_estimation/trade_verifier.rs | 69 ++++++++++-- .../trade_verifier/balance_overrides.rs | 79 ++++++++++++-- 18 files changed, 342 insertions(+), 62 deletions(-) create mode 100644 crates/contracts/artifacts/Spardose.json create mode 100644 crates/contracts/solidity/Spardose.sol diff --git a/crates/contracts/artifacts/Solver.json b/crates/contracts/artifacts/Solver.json index f4de20dccc..82e749c93b 100644 --- a/crates/contracts/artifacts/Solver.json +++ b/crates/contracts/artifacts/Solver.json @@ -1 +1 @@ -{"abi":[{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"bool","name":"countGas","type":"bool"}],"name":"storeBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ISettlement","name":"settlementContract","type":"address"},{"internalType":"address payable","name":"trader","type":"address"},{"internalType":"address","name":"sellToken","type":"address"},{"internalType":"uint256","name":"sellAmount","type":"uint256"},{"internalType":"address","name":"nativeToken","type":"address"},{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"address payable","name":"receiver","type":"address"},{"internalType":"bytes","name":"settlementCall","type":"bytes"},{"internalType":"bool","name":"mockPreconditions","type":"bool"}],"name":"swap","outputs":[{"internalType":"uint256","name":"gasUsed","type":"uint256"},{"internalType":"uint256[]","name":"queriedBalances","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"}],"bytecode":"0x608060405234801561001057600080fd5b50610941806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80633bbb2e1d1461003b578063cc6b67a914610050575b600080fd5b61004e610049366004610600565b61007a565b005b61006361005e3660046106d5565b6101af565b6040516100719291906107bf565b60405180910390f35b60005a9050600173eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee73ffffffffffffffffffffffffffffffffffffffff861614610147576040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff85811660048301528616906370a0823190602401602060405180830381865afa15801561011e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610142919061080d565b610160565b8373ffffffffffffffffffffffffffffffffffffffff16315b8154600181018355600092835260209092209091015581156101a9575a6101879082610855565b6101939061116c61086e565b6000808282546101a3919061086e565b90915550505b50505050565b60006060333014610246576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603860248201527f6f6e6c792073696d756c6174696f6e206c6f67696320697320616c6c6f77656460448201527f20746f2063616c6c202773776170272066756e6374696f6e0000000000000000606482015260840160405180910390fd5b82156102e5576040517f57d5a1d300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8e811660048301528c81166024830152604482018c90528a811660648301528d16906357d5a1d390608401600060405180830381600087803b1580156102cc57600080fd5b505af11580156102e0573d6000803e3d6000fd5b505050505b60405173ffffffffffffffffffffffffffffffffffffffff8716906000908181818181875af1925050503d806000811461033b576040519150601f19603f3d011682016040523d82523d6000602084013e610340565b606091505b50505061034e88888f6103c9565b6103598d86866104a1565b915061036688888f6103c9565b60018054806020026020016040519081016040528092919081815260200182805480156103b257602002820191906000526020600020905b81548152602001906001019080831161039e575b505050505090509b509b9950505050505050505050565b60005b828110156101a95730633bbb2e1d8585848181106103ec576103ec610881565b905060200201602081019061040191906108b0565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815273ffffffffffffffffffffffffffffffffffffffff9182166004820152908516602482015260006044820152606401600060405180830381600087803b15801561047657600080fd5b505af115801561048a573d6000803e3d6000fd5b505050508080610499906108cd565b9150506103cc565b6000805a90506104fe84848080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505073ffffffffffffffffffffffffffffffffffffffff891692915050610520565b506000545a61050d9083610855565b6105179190610855565b95945050505050565b606061052e83600084610535565b9392505050565b606060008473ffffffffffffffffffffffffffffffffffffffff16848460405161055f9190610905565b60006040518083038185875af1925050503d806000811461059c576040519150601f19603f3d011682016040523d82523d6000602084013e6105a1565b606091505b5092509050806105b357815160208301fd5b509392505050565b73ffffffffffffffffffffffffffffffffffffffff811681146105dd57600080fd5b50565b80356105eb816105bb565b919050565b803580151581146105eb57600080fd5b60008060006060848603121561061557600080fd5b8335610620816105bb565b92506020840135610630816105bb565b915061063e604085016105f0565b90509250925092565b60008083601f84011261065957600080fd5b50813567ffffffffffffffff81111561067157600080fd5b6020830191508360208260051b850101111561068c57600080fd5b9250929050565b60008083601f8401126106a557600080fd5b50813567ffffffffffffffff8111156106bd57600080fd5b60208301915083602082850101111561068c57600080fd5b60008060008060008060008060008060006101208c8e0312156106f757600080fd5b6107018c356105bb565b8b359a5061071260208d01356105bb565b60208c0135995061072560408d016105e0565b985060608c0135975061073a60808d016105e0565b965067ffffffffffffffff8060a08e0135111561075657600080fd5b6107668e60a08f01358f01610647565b909750955061077760c08e016105e0565b94508060e08e0135111561078a57600080fd5b5061079b8d60e08e01358e01610693565b90935091506107ad6101008d016105f0565b90509295989b509295989b9093969950565b6000604082018483526020604081850152818551808452606086019150828701935060005b81811015610800578451835293830193918301916001016107e4565b5090979650505050505050565b60006020828403121561081f57600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b8181038181111561086857610868610826565b92915050565b8082018082111561086857610868610826565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000602082840312156108c257600080fd5b813561052e816105bb565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036108fe576108fe610826565b5060010190565b6000825160005b81811015610926576020818601810151858301520161090c565b50600092019182525091905056fea164736f6c6343000811000a","deployedBytecode":"0x608060405234801561001057600080fd5b50600436106100365760003560e01c80633bbb2e1d1461003b578063cc6b67a914610050575b600080fd5b61004e610049366004610600565b61007a565b005b61006361005e3660046106d5565b6101af565b6040516100719291906107bf565b60405180910390f35b60005a9050600173eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee73ffffffffffffffffffffffffffffffffffffffff861614610147576040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff85811660048301528616906370a0823190602401602060405180830381865afa15801561011e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610142919061080d565b610160565b8373ffffffffffffffffffffffffffffffffffffffff16315b8154600181018355600092835260209092209091015581156101a9575a6101879082610855565b6101939061116c61086e565b6000808282546101a3919061086e565b90915550505b50505050565b60006060333014610246576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603860248201527f6f6e6c792073696d756c6174696f6e206c6f67696320697320616c6c6f77656460448201527f20746f2063616c6c202773776170272066756e6374696f6e0000000000000000606482015260840160405180910390fd5b82156102e5576040517f57d5a1d300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8e811660048301528c81166024830152604482018c90528a811660648301528d16906357d5a1d390608401600060405180830381600087803b1580156102cc57600080fd5b505af11580156102e0573d6000803e3d6000fd5b505050505b60405173ffffffffffffffffffffffffffffffffffffffff8716906000908181818181875af1925050503d806000811461033b576040519150601f19603f3d011682016040523d82523d6000602084013e610340565b606091505b50505061034e88888f6103c9565b6103598d86866104a1565b915061036688888f6103c9565b60018054806020026020016040519081016040528092919081815260200182805480156103b257602002820191906000526020600020905b81548152602001906001019080831161039e575b505050505090509b509b9950505050505050505050565b60005b828110156101a95730633bbb2e1d8585848181106103ec576103ec610881565b905060200201602081019061040191906108b0565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815273ffffffffffffffffffffffffffffffffffffffff9182166004820152908516602482015260006044820152606401600060405180830381600087803b15801561047657600080fd5b505af115801561048a573d6000803e3d6000fd5b505050508080610499906108cd565b9150506103cc565b6000805a90506104fe84848080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505073ffffffffffffffffffffffffffffffffffffffff891692915050610520565b506000545a61050d9083610855565b6105179190610855565b95945050505050565b606061052e83600084610535565b9392505050565b606060008473ffffffffffffffffffffffffffffffffffffffff16848460405161055f9190610905565b60006040518083038185875af1925050503d806000811461059c576040519150601f19603f3d011682016040523d82523d6000602084013e6105a1565b606091505b5092509050806105b357815160208301fd5b509392505050565b73ffffffffffffffffffffffffffffffffffffffff811681146105dd57600080fd5b50565b80356105eb816105bb565b919050565b803580151581146105eb57600080fd5b60008060006060848603121561061557600080fd5b8335610620816105bb565b92506020840135610630816105bb565b915061063e604085016105f0565b90509250925092565b60008083601f84011261065957600080fd5b50813567ffffffffffffffff81111561067157600080fd5b6020830191508360208260051b850101111561068c57600080fd5b9250929050565b60008083601f8401126106a557600080fd5b50813567ffffffffffffffff8111156106bd57600080fd5b60208301915083602082850101111561068c57600080fd5b60008060008060008060008060008060006101208c8e0312156106f757600080fd5b6107018c356105bb565b8b359a5061071260208d01356105bb565b60208c0135995061072560408d016105e0565b985060608c0135975061073a60808d016105e0565b965067ffffffffffffffff8060a08e0135111561075657600080fd5b6107668e60a08f01358f01610647565b909750955061077760c08e016105e0565b94508060e08e0135111561078a57600080fd5b5061079b8d60e08e01358e01610693565b90935091506107ad6101008d016105f0565b90509295989b509295989b9093969950565b6000604082018483526020604081850152818551808452606086019150828701935060005b81811015610800578451835293830193918301916001016107e4565b5090979650505050505050565b60006020828403121561081f57600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b8181038181111561086857610868610826565b92915050565b8082018082111561086857610868610826565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000602082840312156108c257600080fd5b813561052e816105bb565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036108fe576108fe610826565b5060010190565b6000825160005b81811015610926576020818601810151858301520161090c565b50600092019182525091905056fea164736f6c6343000811000a","devdoc":{"methods":{}},"userdoc":{"methods":{}}} +{"abi":[{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"bool","name":"countGas","type":"bool"}],"name":"storeBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ISettlement","name":"settlementContract","type":"address"},{"internalType":"address payable","name":"trader","type":"address"},{"internalType":"address","name":"sellToken","type":"address"},{"internalType":"uint256","name":"sellAmount","type":"uint256"},{"internalType":"address","name":"nativeToken","type":"address"},{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"address payable","name":"receiver","type":"address"},{"internalType":"bytes","name":"settlementCall","type":"bytes"},{"components":[{"internalType":"bool","name":"enabled","type":"bool"},{"internalType":"address","name":"spardose","type":"address"}],"internalType":"struct Solver.Mock","name":"mock","type":"tuple"}],"name":"swap","outputs":[{"internalType":"uint256","name":"gasUsed","type":"uint256"},{"internalType":"uint256[]","name":"queriedBalances","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"}],"bytecode":"0x608060405234801561001057600080fd5b50610a68806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806317b86b161461003b5780633bbb2e1d14610065575b600080fd5b61004e6100493660046107b4565b61007a565b60405161005c92919061089f565b60405180910390f35b6100786100733660046108ed565b610332565b005b60006060333014610111576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603860248201527f6f6e6c792073696d756c6174696f6e206c6f67696320697320616c6c6f77656460448201527f20746f2063616c6c202773776170272066756e6374696f6e0000000000000000606482015260840160405180910390fd5b825115610247576040517f57d5a1d300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8e811660048301528c81166024830152604482018c90528a811660648301528d16906357d5a1d390608401600060405180830381600087803b15801561019857600080fd5b505af11580156101ac573d6000803e3d6000fd5b50505060208401516040517fc56cca8300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8f811660048301528e81166024830152604482018e9052909116915063c56cca8390606401600060405180830381600087803b15801561022e57600080fd5b505af1158015610242573d6000803e3d6000fd5b505050505b60008673ffffffffffffffffffffffffffffffffffffffff16600060405160006040518083038185875af1925050503d80600081146102a2576040519150601f19603f3d011682016040523d82523d6000602084013e6102a7565b606091505b50509050506102b788888f610467565b6102c28d868661053f565b91506102cf88888f610467565b600180548060200260200160405190810160405280929190818152602001828054801561031b57602002820191906000526020600020905b815481526020019060010190808311610307575b505050505090509b509b9950505050505050505050565b60005a9050600173eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee73ffffffffffffffffffffffffffffffffffffffff8616146103ff576040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff85811660048301528616906370a0823190602401602060405180830381865afa1580156103d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103fa9190610934565b610418565b8373ffffffffffffffffffffffffffffffffffffffff16315b815460018101835560009283526020909220909101558115610461575a61043f908261097c565b61044b9061116c610995565b60008082825461045b9190610995565b90915550505b50505050565b60005b828110156104615730633bbb2e1d85858481811061048a5761048a6109a8565b905060200201602081019061049f91906109d7565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815273ffffffffffffffffffffffffffffffffffffffff9182166004820152908516602482015260006044820152606401600060405180830381600087803b15801561051457600080fd5b505af1158015610528573d6000803e3d6000fd5b505050508080610537906109f4565b91505061046a565b6000805a905061059c84848080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505073ffffffffffffffffffffffffffffffffffffffff8916929150506105be565b506000545a6105ab908361097c565b6105b5919061097c565b95945050505050565b60606105cc836000846105d3565b9392505050565b606060008473ffffffffffffffffffffffffffffffffffffffff1684846040516105fd9190610a2c565b60006040518083038185875af1925050503d806000811461063a576040519150601f19603f3d011682016040523d82523d6000602084013e61063f565b606091505b50925090508061065157815160208301fd5b509392505050565b73ffffffffffffffffffffffffffffffffffffffff8116811461067b57600080fd5b50565b803561068981610659565b919050565b60008083601f8401126106a057600080fd5b50813567ffffffffffffffff8111156106b857600080fd5b6020830191508360208260051b85010111156106d357600080fd5b9250929050565b60008083601f8401126106ec57600080fd5b50813567ffffffffffffffff81111561070457600080fd5b6020830191508360208285010111156106d357600080fd5b8035801515811461068957600080fd5b60006040828403121561073e57600080fd5b6040516040810181811067ffffffffffffffff82111715610788577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040529050806107978361071c565b815260208301356107a781610659565b6020919091015292915050565b60008060008060008060008060008060006101408c8e0312156107d657600080fd5b6107e08c35610659565b8b359a506107f160208d0135610659565b60208c0135995061080460408d0161067e565b985060608c0135975061081960808d0161067e565b965067ffffffffffffffff8060a08e0135111561083557600080fd5b6108458e60a08f01358f0161068e565b909750955061085660c08e0161067e565b94508060e08e0135111561086957600080fd5b5061087a8d60e08e01358e016106da565b909350915061088d8d6101008e0161072c565b90509295989b509295989b9093969950565b6000604082018483526020604081850152818551808452606086019150828701935060005b818110156108e0578451835293830193918301916001016108c4565b5090979650505050505050565b60008060006060848603121561090257600080fd5b833561090d81610659565b9250602084013561091d81610659565b915061092b6040850161071c565b90509250925092565b60006020828403121561094657600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b8181038181111561098f5761098f61094d565b92915050565b8082018082111561098f5761098f61094d565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000602082840312156109e957600080fd5b81356105cc81610659565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610a2557610a2561094d565b5060010190565b6000825160005b81811015610a4d5760208186018101518583015201610a33565b50600092019182525091905056fea164736f6c6343000811000a","deployedBytecode":"0x608060405234801561001057600080fd5b50600436106100365760003560e01c806317b86b161461003b5780633bbb2e1d14610065575b600080fd5b61004e6100493660046107b4565b61007a565b60405161005c92919061089f565b60405180910390f35b6100786100733660046108ed565b610332565b005b60006060333014610111576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603860248201527f6f6e6c792073696d756c6174696f6e206c6f67696320697320616c6c6f77656460448201527f20746f2063616c6c202773776170272066756e6374696f6e0000000000000000606482015260840160405180910390fd5b825115610247576040517f57d5a1d300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8e811660048301528c81166024830152604482018c90528a811660648301528d16906357d5a1d390608401600060405180830381600087803b15801561019857600080fd5b505af11580156101ac573d6000803e3d6000fd5b50505060208401516040517fc56cca8300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8f811660048301528e81166024830152604482018e9052909116915063c56cca8390606401600060405180830381600087803b15801561022e57600080fd5b505af1158015610242573d6000803e3d6000fd5b505050505b60008673ffffffffffffffffffffffffffffffffffffffff16600060405160006040518083038185875af1925050503d80600081146102a2576040519150601f19603f3d011682016040523d82523d6000602084013e6102a7565b606091505b50509050506102b788888f610467565b6102c28d868661053f565b91506102cf88888f610467565b600180548060200260200160405190810160405280929190818152602001828054801561031b57602002820191906000526020600020905b815481526020019060010190808311610307575b505050505090509b509b9950505050505050505050565b60005a9050600173eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee73ffffffffffffffffffffffffffffffffffffffff8616146103ff576040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff85811660048301528616906370a0823190602401602060405180830381865afa1580156103d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103fa9190610934565b610418565b8373ffffffffffffffffffffffffffffffffffffffff16315b815460018101835560009283526020909220909101558115610461575a61043f908261097c565b61044b9061116c610995565b60008082825461045b9190610995565b90915550505b50505050565b60005b828110156104615730633bbb2e1d85858481811061048a5761048a6109a8565b905060200201602081019061049f91906109d7565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815273ffffffffffffffffffffffffffffffffffffffff9182166004820152908516602482015260006044820152606401600060405180830381600087803b15801561051457600080fd5b505af1158015610528573d6000803e3d6000fd5b505050508080610537906109f4565b91505061046a565b6000805a905061059c84848080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505073ffffffffffffffffffffffffffffffffffffffff8916929150506105be565b506000545a6105ab908361097c565b6105b5919061097c565b95945050505050565b60606105cc836000846105d3565b9392505050565b606060008473ffffffffffffffffffffffffffffffffffffffff1684846040516105fd9190610a2c565b60006040518083038185875af1925050503d806000811461063a576040519150601f19603f3d011682016040523d82523d6000602084013e61063f565b606091505b50925090508061065157815160208301fd5b509392505050565b73ffffffffffffffffffffffffffffffffffffffff8116811461067b57600080fd5b50565b803561068981610659565b919050565b60008083601f8401126106a057600080fd5b50813567ffffffffffffffff8111156106b857600080fd5b6020830191508360208260051b85010111156106d357600080fd5b9250929050565b60008083601f8401126106ec57600080fd5b50813567ffffffffffffffff81111561070457600080fd5b6020830191508360208285010111156106d357600080fd5b8035801515811461068957600080fd5b60006040828403121561073e57600080fd5b6040516040810181811067ffffffffffffffff82111715610788577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040529050806107978361071c565b815260208301356107a781610659565b6020919091015292915050565b60008060008060008060008060008060006101408c8e0312156107d657600080fd5b6107e08c35610659565b8b359a506107f160208d0135610659565b60208c0135995061080460408d0161067e565b985060608c0135975061081960808d0161067e565b965067ffffffffffffffff8060a08e0135111561083557600080fd5b6108458e60a08f01358f0161068e565b909750955061085660c08e0161067e565b94508060e08e0135111561086957600080fd5b5061087a8d60e08e01358e016106da565b909350915061088d8d6101008e0161072c565b90509295989b509295989b9093969950565b6000604082018483526020604081850152818551808452606086019150828701935060005b818110156108e0578451835293830193918301916001016108c4565b5090979650505050505050565b60008060006060848603121561090257600080fd5b833561090d81610659565b9250602084013561091d81610659565b915061092b6040850161071c565b90509250925092565b60006020828403121561094657600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b8181038181111561098f5761098f61094d565b92915050565b8082018082111561098f5761098f61094d565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000602082840312156109e957600080fd5b81356105cc81610659565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610a2557610a2561094d565b5060010190565b6000825160005b81811015610a4d5760208186018101518583015201610a33565b50600092019182525091905056fea164736f6c6343000811000a","devdoc":{"methods":{}},"userdoc":{"methods":{}}} diff --git a/crates/contracts/artifacts/Spardose.json b/crates/contracts/artifacts/Spardose.json new file mode 100644 index 0000000000..ce19b8db54 --- /dev/null +++ b/crates/contracts/artifacts/Spardose.json @@ -0,0 +1 @@ +{"abi":[{"inputs":[{"internalType":"address","name":"trader","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ensureBalance","outputs":[],"stateMutability":"nonpayable","type":"function"}],"bytecode":"0x608060405234801561001057600080fd5b506103ee806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063c56cca8314610030575b600080fd5b61004361003e3660046102fa565b610045565b005b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8481166004830152600091908416906370a0823190602401602060405180830381865afa1580156100b5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100d99190610336565b90508181106100e85750505050565b60006100f4828461034f565b905061011773ffffffffffffffffffffffffffffffffffffffff851686836101ae565b6101a7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f74726164657220646f6573206e6f74206861766520656e6f7567682073656c6c60448201527f5f746f6b656e0000000000000000000000000000000000000000000000000000606482015260840160405180910390fd5b5050505050565b6040805173ffffffffffffffffffffffffffffffffffffffff8481166024830152604480830185905283518084039091018152606490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052915160009260609190871690610247908490610389565b6000604051808303816000865af19150503d8060008114610284576040519150601f19603f3d011682016040523d82523d6000602084013e610289565b606091505b5090935090508280156102a057506102a0816102aa565b9695505050505050565b60008151600014806102cb5750818060200190518101906102cb91906103b8565b92915050565b803573ffffffffffffffffffffffffffffffffffffffff811681146102f557600080fd5b919050565b60008060006060848603121561030f57600080fd5b610318846102d1565b9250610326602085016102d1565b9150604084013590509250925092565b60006020828403121561034857600080fd5b5051919050565b818103818111156102cb577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000825160005b818110156103aa5760208186018101518583015201610390565b506000920191825250919050565b6000602082840312156103ca57600080fd5b815180151581146103da57600080fd5b939250505056fea164736f6c6343000811000a","deployedBytecode":"0x608060405234801561001057600080fd5b506004361061002b5760003560e01c8063c56cca8314610030575b600080fd5b61004361003e3660046102fa565b610045565b005b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8481166004830152600091908416906370a0823190602401602060405180830381865afa1580156100b5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100d99190610336565b90508181106100e85750505050565b60006100f4828461034f565b905061011773ffffffffffffffffffffffffffffffffffffffff851686836101ae565b6101a7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f74726164657220646f6573206e6f74206861766520656e6f7567682073656c6c60448201527f5f746f6b656e0000000000000000000000000000000000000000000000000000606482015260840160405180910390fd5b5050505050565b6040805173ffffffffffffffffffffffffffffffffffffffff8481166024830152604480830185905283518084039091018152606490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052915160009260609190871690610247908490610389565b6000604051808303816000865af19150503d8060008114610284576040519150601f19603f3d011682016040523d82523d6000602084013e610289565b606091505b5090935090508280156102a057506102a0816102aa565b9695505050505050565b60008151600014806102cb5750818060200190518101906102cb91906103b8565b92915050565b803573ffffffffffffffffffffffffffffffffffffffff811681146102f557600080fd5b919050565b60008060006060848603121561030f57600080fd5b610318846102d1565b9250610326602085016102d1565b9150604084013590509250925092565b60006020828403121561034857600080fd5b5051919050565b818103818111156102cb577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000825160005b818110156103aa5760208186018101518583015201610390565b506000920191825250919050565b6000602082840312156103ca57600080fd5b815180151581146103da57600080fd5b939250505056fea164736f6c6343000811000a","devdoc":{"methods":{}},"userdoc":{"methods":{}}} diff --git a/crates/contracts/artifacts/Swapper.json b/crates/contracts/artifacts/Swapper.json index 3b4420dd93..7f6566ee0d 100644 --- a/crates/contracts/artifacts/Swapper.json +++ b/crates/contracts/artifacts/Swapper.json @@ -1 +1 @@ -{"abi":[{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"isValidSignature","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"contract ISettlement","name":"settlement","type":"address"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct Asset","name":"sell","type":"tuple"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct Asset","name":"buy","type":"tuple"},{"components":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct Allowance","name":"allowance","type":"tuple"},{"components":[{"internalType":"address","name":"target","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct Interaction","name":"call","type":"tuple"}],"name":"swap","outputs":[{"internalType":"uint256","name":"gasUsed","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}],"bytecode":"0x608060405234801561001057600080fd5b506111c8806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80631626ba7e1461003b5780639ed280dd146100a7575b600080fd5b610071610049366004610b03565b7f1626ba7e000000000000000000000000000000000000000000000000000000009392505050565b6040517fffffffff0000000000000000000000000000000000000000000000000000000090911681526020015b60405180910390f35b6100ba6100b5366004610bbc565b6100c8565b60405190815260200161009e565b6000602085018035906100db9087610c49565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff91909116906370a0823190602401602060405180830381865afa158015610147573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061016b9190610c66565b1015610179575060006108b8565b6102178673ffffffffffffffffffffffffffffffffffffffff16639b552cc26040518163ffffffff1660e01b8152600401602060405180830381865afa1580156101c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101eb9190610c7f565b60006101fa6020890189610c49565b73ffffffffffffffffffffffffffffffffffffffff1691906108c1565b61029a8673ffffffffffffffffffffffffffffffffffffffff16639b552cc26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610265573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102899190610c7f565b602087018035906101fa9089610c49565b6040805160028082526060820183526000926020830190803683370190505090506102c86020870187610c49565b816000815181106102db576102db610ccb565b73ffffffffffffffffffffffffffffffffffffffff90921660209283029190910182015261030b90860186610c49565b8160018151811061031e5761031e610ccb565b73ffffffffffffffffffffffffffffffffffffffff92909216602092830291909101820152604080516002808252606082018352600093919290918301908036833701905050905085602001358160008151811061037e5761037e610ccb565b6020026020010181815250508660200135816001815181106103a2576103a2610ccb565b6020908102919091010152604080516001808252818301909252600091816020015b6104406040518061016001604052806000815260200160008152602001600073ffffffffffffffffffffffffffffffffffffffff1681526020016000815260200160008152602001600063ffffffff16815260200160008019168152602001600081526020016000815260200160008152602001606081525090565b8152602001906001900390816103c45790505090506040518061016001604052806000815260200160018152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001896020013581526020018860200135815260200163ffffffff801681526020016000801b815260200160008152602001604081526020016000815260200130604051602001610506919060609190911b7fffffffffffffffffffffffffffffffffffffffff00000000000000000000000016815260140190565b6040516020818303038152906040528152508160008151811061052b5761052b610ccb565b602002602001018190525061053e610adc565b60208088013590610551908b018b610c49565b73ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e8c61057a60208c018c610c49565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff928316600482015291166024820152604401602060405180830381865afa1580156105ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061060e9190610c66565b101561078c5760408051600180825281830190925290816020015b60408051606080820183526000808352602083015291810191909152815260200190600190039081610629575050815261066660208a018a610c49565b8151805160009061067957610679610ccb565b60209081029190910181015173ffffffffffffffffffffffffffffffffffffffff9092169091526106ac908a018a610c49565b73ffffffffffffffffffffffffffffffffffffffff1663095ea7b36106d460208a018a610c49565b60405173ffffffffffffffffffffffffffffffffffffffff909116602482015260208a01356044820152606401604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1660e09390931b929092179091529050816000602002015160008151811061077c5761077c610ccb565b6020026020010151604001819052505b60408051600180825281830190925290816020015b604080516060808201835260008083526020830152918101919091528152602001906001900390816107a157505060208201526107dd86610d72565b602082015180516000906107f3576107f3610ccb565b60200260200101819052506108b18a73ffffffffffffffffffffffffffffffffffffffff166313d79a0b868686866040516024016108349493929190611071565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1660e09390931b9290921790915273ffffffffffffffffffffffffffffffffffffffff8d16915061099c565b9450505050505b95945050505050565b6040805173ffffffffffffffffffffffffffffffffffffffff848116602483015260448083018590528351808403909101815260649092019092526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b30000000000000000000000000000000000000000000000000000000017905290600090610954908616836109b1565b9050610995816040518060400160405280601a81526020017f5361666545524332303a20617070726f76616c206661696c65640000000000008152506109bf565b5050505050565b60006109aa83600084610a23565b9392505050565b60606109aa83600084610a56565b815115806109dc5750818060200190518101906109dc919061112a565b8190610a1e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a15919061114c565b60405180910390fd5b505050565b60005a905060008083516020850186885af1610a43573d6000803e3d6000fd5b5a610a4e908261115f565b949350505050565b606060008473ffffffffffffffffffffffffffffffffffffffff168484604051610a80919061119f565b60006040518083038185875af1925050503d8060008114610abd576040519150601f19603f3d011682016040523d82523d6000602084013e610ac2565b606091505b509250905080610ad457815160208301fd5b509392505050565b60405180606001604052806003905b6060815260200190600190039081610aeb5790505090565b600080600060408486031215610b1857600080fd5b83359250602084013567ffffffffffffffff80821115610b3757600080fd5b818601915086601f830112610b4b57600080fd5b813581811115610b5a57600080fd5b876020828501011115610b6c57600080fd5b6020830194508093505050509250925092565b73ffffffffffffffffffffffffffffffffffffffff81168114610ba157600080fd5b50565b600060408284031215610bb657600080fd5b50919050565b60008060008060006101008688031215610bd557600080fd5b8535610be081610b7f565b9450610bef8760208801610ba4565b9350610bfe8760608801610ba4565b9250610c0d8760a08801610ba4565b915060e086013567ffffffffffffffff811115610c2957600080fd5b860160608189031215610c3b57600080fd5b809150509295509295909350565b600060208284031215610c5b57600080fd5b81356109aa81610b7f565b600060208284031215610c7857600080fd5b5051919050565b600060208284031215610c9157600080fd5b81516109aa81610b7f565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6040516060810167ffffffffffffffff81118282101715610d1d57610d1d610c9c565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715610d6a57610d6a610c9c565b604052919050565b600060608236031215610d8457600080fd5b610d8c610cfa565b8235610d9781610b7f565b815260208381013581830152604084013567ffffffffffffffff80821115610dbe57600080fd5b9085019036601f830112610dd157600080fd5b813581811115610de357610de3610c9c565b610e13847fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f84011601610d23565b91508082523684828501011115610e2957600080fd5b808484018584013760009082019093019290925250604082015292915050565b60005b83811015610e64578181015183820152602001610e4c565b50506000910152565b60008151808452610e85816020860160208601610e49565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b600081518084526020808501808196508360051b8101915082860160005b85811015610f975782840389528151610160815186528682015187870152604080830151610f1a8289018273ffffffffffffffffffffffffffffffffffffffff169052565b5050606082810151908701526080808301519087015260a08083015163ffffffff169087015260c0808301519087015260e080830151908701526101008083015190870152610120808301519087015261014091820151918601819052610f8381870183610e6d565b9a87019a9550505090840190600101610ed5565b5091979650505050505050565b6000826060808201846000805b6003811015610f97578584038952825180518086526020918201918087019190600582901b88018101865b8381101561105a578982037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe00185528551805173ffffffffffffffffffffffffffffffffffffffff16835283810151848401526040908101519083018c90526110478c840182610e6d565b9684019695840195925050600101610fdc565b509c81019c97509590950194505050600101610fb1565b6080808252855190820181905260009060209060a0840190828901845b828110156110c057815173ffffffffffffffffffffffffffffffffffffffff168452928401929084019060010161108e565b5050508381038285015286518082528783019183019060005b818110156110f5578351835292840192918401916001016110d9565b505084810360408601526111098188610eb7565b92505050828103606084015261111f8185610fa4565b979650505050505050565b60006020828403121561113c57600080fd5b815180151581146109aa57600080fd5b6020815260006109aa6020830184610e6d565b81810381811115611199577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b92915050565b600082516111b1818460208701610e49565b919091019291505056fea164736f6c6343000811000a","deployedBytecode":"0x608060405234801561001057600080fd5b50600436106100365760003560e01c80631626ba7e1461003b5780639ed280dd146100a7575b600080fd5b610071610049366004610b03565b7f1626ba7e000000000000000000000000000000000000000000000000000000009392505050565b6040517fffffffff0000000000000000000000000000000000000000000000000000000090911681526020015b60405180910390f35b6100ba6100b5366004610bbc565b6100c8565b60405190815260200161009e565b6000602085018035906100db9087610c49565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff91909116906370a0823190602401602060405180830381865afa158015610147573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061016b9190610c66565b1015610179575060006108b8565b6102178673ffffffffffffffffffffffffffffffffffffffff16639b552cc26040518163ffffffff1660e01b8152600401602060405180830381865afa1580156101c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101eb9190610c7f565b60006101fa6020890189610c49565b73ffffffffffffffffffffffffffffffffffffffff1691906108c1565b61029a8673ffffffffffffffffffffffffffffffffffffffff16639b552cc26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610265573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102899190610c7f565b602087018035906101fa9089610c49565b6040805160028082526060820183526000926020830190803683370190505090506102c86020870187610c49565b816000815181106102db576102db610ccb565b73ffffffffffffffffffffffffffffffffffffffff90921660209283029190910182015261030b90860186610c49565b8160018151811061031e5761031e610ccb565b73ffffffffffffffffffffffffffffffffffffffff92909216602092830291909101820152604080516002808252606082018352600093919290918301908036833701905050905085602001358160008151811061037e5761037e610ccb565b6020026020010181815250508660200135816001815181106103a2576103a2610ccb565b6020908102919091010152604080516001808252818301909252600091816020015b6104406040518061016001604052806000815260200160008152602001600073ffffffffffffffffffffffffffffffffffffffff1681526020016000815260200160008152602001600063ffffffff16815260200160008019168152602001600081526020016000815260200160008152602001606081525090565b8152602001906001900390816103c45790505090506040518061016001604052806000815260200160018152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001896020013581526020018860200135815260200163ffffffff801681526020016000801b815260200160008152602001604081526020016000815260200130604051602001610506919060609190911b7fffffffffffffffffffffffffffffffffffffffff00000000000000000000000016815260140190565b6040516020818303038152906040528152508160008151811061052b5761052b610ccb565b602002602001018190525061053e610adc565b60208088013590610551908b018b610c49565b73ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e8c61057a60208c018c610c49565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff928316600482015291166024820152604401602060405180830381865afa1580156105ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061060e9190610c66565b101561078c5760408051600180825281830190925290816020015b60408051606080820183526000808352602083015291810191909152815260200190600190039081610629575050815261066660208a018a610c49565b8151805160009061067957610679610ccb565b60209081029190910181015173ffffffffffffffffffffffffffffffffffffffff9092169091526106ac908a018a610c49565b73ffffffffffffffffffffffffffffffffffffffff1663095ea7b36106d460208a018a610c49565b60405173ffffffffffffffffffffffffffffffffffffffff909116602482015260208a01356044820152606401604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1660e09390931b929092179091529050816000602002015160008151811061077c5761077c610ccb565b6020026020010151604001819052505b60408051600180825281830190925290816020015b604080516060808201835260008083526020830152918101919091528152602001906001900390816107a157505060208201526107dd86610d72565b602082015180516000906107f3576107f3610ccb565b60200260200101819052506108b18a73ffffffffffffffffffffffffffffffffffffffff166313d79a0b868686866040516024016108349493929190611071565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1660e09390931b9290921790915273ffffffffffffffffffffffffffffffffffffffff8d16915061099c565b9450505050505b95945050505050565b6040805173ffffffffffffffffffffffffffffffffffffffff848116602483015260448083018590528351808403909101815260649092019092526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b30000000000000000000000000000000000000000000000000000000017905290600090610954908616836109b1565b9050610995816040518060400160405280601a81526020017f5361666545524332303a20617070726f76616c206661696c65640000000000008152506109bf565b5050505050565b60006109aa83600084610a23565b9392505050565b60606109aa83600084610a56565b815115806109dc5750818060200190518101906109dc919061112a565b8190610a1e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a15919061114c565b60405180910390fd5b505050565b60005a905060008083516020850186885af1610a43573d6000803e3d6000fd5b5a610a4e908261115f565b949350505050565b606060008473ffffffffffffffffffffffffffffffffffffffff168484604051610a80919061119f565b60006040518083038185875af1925050503d8060008114610abd576040519150601f19603f3d011682016040523d82523d6000602084013e610ac2565b606091505b509250905080610ad457815160208301fd5b509392505050565b60405180606001604052806003905b6060815260200190600190039081610aeb5790505090565b600080600060408486031215610b1857600080fd5b83359250602084013567ffffffffffffffff80821115610b3757600080fd5b818601915086601f830112610b4b57600080fd5b813581811115610b5a57600080fd5b876020828501011115610b6c57600080fd5b6020830194508093505050509250925092565b73ffffffffffffffffffffffffffffffffffffffff81168114610ba157600080fd5b50565b600060408284031215610bb657600080fd5b50919050565b60008060008060006101008688031215610bd557600080fd5b8535610be081610b7f565b9450610bef8760208801610ba4565b9350610bfe8760608801610ba4565b9250610c0d8760a08801610ba4565b915060e086013567ffffffffffffffff811115610c2957600080fd5b860160608189031215610c3b57600080fd5b809150509295509295909350565b600060208284031215610c5b57600080fd5b81356109aa81610b7f565b600060208284031215610c7857600080fd5b5051919050565b600060208284031215610c9157600080fd5b81516109aa81610b7f565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6040516060810167ffffffffffffffff81118282101715610d1d57610d1d610c9c565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715610d6a57610d6a610c9c565b604052919050565b600060608236031215610d8457600080fd5b610d8c610cfa565b8235610d9781610b7f565b815260208381013581830152604084013567ffffffffffffffff80821115610dbe57600080fd5b9085019036601f830112610dd157600080fd5b813581811115610de357610de3610c9c565b610e13847fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f84011601610d23565b91508082523684828501011115610e2957600080fd5b808484018584013760009082019093019290925250604082015292915050565b60005b83811015610e64578181015183820152602001610e4c565b50506000910152565b60008151808452610e85816020860160208601610e49565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b600081518084526020808501808196508360051b8101915082860160005b85811015610f975782840389528151610160815186528682015187870152604080830151610f1a8289018273ffffffffffffffffffffffffffffffffffffffff169052565b5050606082810151908701526080808301519087015260a08083015163ffffffff169087015260c0808301519087015260e080830151908701526101008083015190870152610120808301519087015261014091820151918601819052610f8381870183610e6d565b9a87019a9550505090840190600101610ed5565b5091979650505050505050565b6000826060808201846000805b6003811015610f97578584038952825180518086526020918201918087019190600582901b88018101865b8381101561105a578982037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe00185528551805173ffffffffffffffffffffffffffffffffffffffff16835283810151848401526040908101519083018c90526110478c840182610e6d565b9684019695840195925050600101610fdc565b509c81019c97509590950194505050600101610fb1565b6080808252855190820181905260009060209060a0840190828901845b828110156110c057815173ffffffffffffffffffffffffffffffffffffffff168452928401929084019060010161108e565b5050508381038285015286518082528783019183019060005b818110156110f5578351835292840192918401916001016110d9565b505084810360408601526111098188610eb7565b92505050828103606084015261111f8185610fa4565b979650505050505050565b60006020828403121561113c57600080fd5b815180151581146109aa57600080fd5b6020815260006109aa6020830184610e6d565b81810381811115611199577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b92915050565b600082516111b1818460208701610e49565b919091019291505056fea164736f6c6343000811000a","devdoc":{"methods":{}},"userdoc":{"methods":{}}} +{"abi":[{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"isValidSignature","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"contract ISettlement","name":"settlement","type":"address"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct Asset","name":"sell","type":"tuple"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct Asset","name":"buy","type":"tuple"},{"components":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct Allowance","name":"allowance","type":"tuple"},{"components":[{"internalType":"address","name":"target","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct Interaction","name":"call","type":"tuple"}],"name":"swap","outputs":[{"internalType":"uint256","name":"gasUsed","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}],"bytecode":"0x608060405234801561001057600080fd5b506111d5806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80631626ba7e1461003b5780639ed280dd146100a7575b600080fd5b610071610049366004610b16565b7f1626ba7e000000000000000000000000000000000000000000000000000000009392505050565b6040517fffffffff0000000000000000000000000000000000000000000000000000000090911681526020015b60405180910390f35b6100ba6100b5366004610bcf565b6100c8565b60405190815260200161009e565b6000602085018035906100db9087610c5c565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff91909116906370a0823190602401602060405180830381865afa158015610147573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061016b9190610c79565b1015610179575060006108b8565b6102178673ffffffffffffffffffffffffffffffffffffffff16639b552cc26040518163ffffffff1660e01b8152600401602060405180830381865afa1580156101c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101eb9190610c92565b60006101fa6020890189610c5c565b73ffffffffffffffffffffffffffffffffffffffff1691906108c1565b61029a8673ffffffffffffffffffffffffffffffffffffffff16639b552cc26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610265573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102899190610c92565b602087018035906101fa9089610c5c565b6040805160028082526060820183526000926020830190803683370190505090506102c86020870187610c5c565b816000815181106102db576102db610cde565b73ffffffffffffffffffffffffffffffffffffffff90921660209283029190910182015261030b90860186610c5c565b8160018151811061031e5761031e610cde565b73ffffffffffffffffffffffffffffffffffffffff92909216602092830291909101820152604080516002808252606082018352600093919290918301908036833701905050905085602001358160008151811061037e5761037e610cde565b6020026020010181815250508660200135816001815181106103a2576103a2610cde565b6020908102919091010152604080516001808252818301909252600091816020015b6104406040518061016001604052806000815260200160008152602001600073ffffffffffffffffffffffffffffffffffffffff1681526020016000815260200160008152602001600063ffffffff16815260200160008019168152602001600081526020016000815260200160008152602001606081525090565b8152602001906001900390816103c45790505090506040518061016001604052806000815260200160018152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001896020013581526020018860200135815260200163ffffffff801681526020016000801b815260200160008152602001604081526020016000815260200130604051602001610506919060609190911b7fffffffffffffffffffffffffffffffffffffffff00000000000000000000000016815260140190565b6040516020818303038152906040528152508160008151811061052b5761052b610cde565b602002602001018190525061053e610aef565b60208088013590610551908b018b610c5c565b73ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e8c61057a60208c018c610c5c565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff928316600482015291166024820152604401602060405180830381865afa1580156105ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061060e9190610c79565b101561078c5760408051600180825281830190925290816020015b60408051606080820183526000808352602083015291810191909152815260200190600190039081610629575050815261066660208a018a610c5c565b8151805160009061067957610679610cde565b60209081029190910181015173ffffffffffffffffffffffffffffffffffffffff9092169091526106ac908a018a610c5c565b73ffffffffffffffffffffffffffffffffffffffff1663095ea7b36106d460208a018a610c5c565b60405173ffffffffffffffffffffffffffffffffffffffff909116602482015260208a01356044820152606401604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1660e09390931b929092179091529050816000602002015160008151811061077c5761077c610cde565b6020026020010151604001819052505b60408051600180825281830190925290816020015b604080516060808201835260008083526020830152918101919091528152602001906001900390816107a157505060208201526107dd86610d85565b602082015180516000906107f3576107f3610cde565b60200260200101819052506108b18a73ffffffffffffffffffffffffffffffffffffffff166313d79a0b868686866040516024016108349493929190611084565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1660e09390931b9290921790915273ffffffffffffffffffffffffffffffffffffffff8d16915061099c565b9450505050505b95945050505050565b6040805173ffffffffffffffffffffffffffffffffffffffff848116602483015260448083018590528351808403909101815260649092019092526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b30000000000000000000000000000000000000000000000000000000017905290600090610954908616836109b1565b9050610995816040518060400160405280601a81526020017f5361666545524332303a20617070726f76616c206661696c65640000000000008152506109bf565b5050505050565b60006109aa83600084610a0f565b9392505050565b60606109aa83600084610a42565b6109c882610ac8565b8190610a0a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a01919061113d565b60405180910390fd5b505050565b60005a905060008083516020850186885af1610a2f573d6000803e3d6000fd5b5a610a3a9082611150565b949350505050565b606060008473ffffffffffffffffffffffffffffffffffffffff168484604051610a6c919061118a565b60006040518083038185875af1925050503d8060008114610aa9576040519150601f19603f3d011682016040523d82523d6000602084013e610aae565b606091505b509250905080610ac057815160208301fd5b509392505050565b6000815160001480610ae9575081806020019051810190610ae991906111a6565b92915050565b60405180606001604052806003905b6060815260200190600190039081610afe5790505090565b600080600060408486031215610b2b57600080fd5b83359250602084013567ffffffffffffffff80821115610b4a57600080fd5b818601915086601f830112610b5e57600080fd5b813581811115610b6d57600080fd5b876020828501011115610b7f57600080fd5b6020830194508093505050509250925092565b73ffffffffffffffffffffffffffffffffffffffff81168114610bb457600080fd5b50565b600060408284031215610bc957600080fd5b50919050565b60008060008060006101008688031215610be857600080fd5b8535610bf381610b92565b9450610c028760208801610bb7565b9350610c118760608801610bb7565b9250610c208760a08801610bb7565b915060e086013567ffffffffffffffff811115610c3c57600080fd5b860160608189031215610c4e57600080fd5b809150509295509295909350565b600060208284031215610c6e57600080fd5b81356109aa81610b92565b600060208284031215610c8b57600080fd5b5051919050565b600060208284031215610ca457600080fd5b81516109aa81610b92565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6040516060810167ffffffffffffffff81118282101715610d3057610d30610caf565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715610d7d57610d7d610caf565b604052919050565b600060608236031215610d9757600080fd5b610d9f610d0d565b8235610daa81610b92565b815260208381013581830152604084013567ffffffffffffffff80821115610dd157600080fd5b9085019036601f830112610de457600080fd5b813581811115610df657610df6610caf565b610e26847fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f84011601610d36565b91508082523684828501011115610e3c57600080fd5b808484018584013760009082019093019290925250604082015292915050565b60005b83811015610e77578181015183820152602001610e5f565b50506000910152565b60008151808452610e98816020860160208601610e5c565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b600081518084526020808501808196508360051b8101915082860160005b85811015610faa5782840389528151610160815186528682015187870152604080830151610f2d8289018273ffffffffffffffffffffffffffffffffffffffff169052565b5050606082810151908701526080808301519087015260a08083015163ffffffff169087015260c0808301519087015260e080830151908701526101008083015190870152610120808301519087015261014091820151918601819052610f9681870183610e80565b9a87019a9550505090840190600101610ee8565b5091979650505050505050565b6000826060808201846000805b6003811015610faa578584038952825180518086526020918201918087019190600582901b88018101865b8381101561106d578982037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe00185528551805173ffffffffffffffffffffffffffffffffffffffff16835283810151848401526040908101519083018c905261105a8c840182610e80565b9684019695840195925050600101610fef565b509c81019c97509590950194505050600101610fc4565b6080808252855190820181905260009060209060a0840190828901845b828110156110d357815173ffffffffffffffffffffffffffffffffffffffff16845292840192908401906001016110a1565b5050508381038285015286518082528783019183019060005b81811015611108578351835292840192918401916001016110ec565b5050848103604086015261111c8188610eca565b9250505082810360608401526111328185610fb7565b979650505050505050565b6020815260006109aa6020830184610e80565b81810381811115610ae9577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000825161119c818460208701610e5c565b9190910192915050565b6000602082840312156111b857600080fd5b815180151581146109aa57600080fdfea164736f6c6343000811000a","deployedBytecode":"0x608060405234801561001057600080fd5b50600436106100365760003560e01c80631626ba7e1461003b5780639ed280dd146100a7575b600080fd5b610071610049366004610b16565b7f1626ba7e000000000000000000000000000000000000000000000000000000009392505050565b6040517fffffffff0000000000000000000000000000000000000000000000000000000090911681526020015b60405180910390f35b6100ba6100b5366004610bcf565b6100c8565b60405190815260200161009e565b6000602085018035906100db9087610c5c565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff91909116906370a0823190602401602060405180830381865afa158015610147573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061016b9190610c79565b1015610179575060006108b8565b6102178673ffffffffffffffffffffffffffffffffffffffff16639b552cc26040518163ffffffff1660e01b8152600401602060405180830381865afa1580156101c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101eb9190610c92565b60006101fa6020890189610c5c565b73ffffffffffffffffffffffffffffffffffffffff1691906108c1565b61029a8673ffffffffffffffffffffffffffffffffffffffff16639b552cc26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610265573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102899190610c92565b602087018035906101fa9089610c5c565b6040805160028082526060820183526000926020830190803683370190505090506102c86020870187610c5c565b816000815181106102db576102db610cde565b73ffffffffffffffffffffffffffffffffffffffff90921660209283029190910182015261030b90860186610c5c565b8160018151811061031e5761031e610cde565b73ffffffffffffffffffffffffffffffffffffffff92909216602092830291909101820152604080516002808252606082018352600093919290918301908036833701905050905085602001358160008151811061037e5761037e610cde565b6020026020010181815250508660200135816001815181106103a2576103a2610cde565b6020908102919091010152604080516001808252818301909252600091816020015b6104406040518061016001604052806000815260200160008152602001600073ffffffffffffffffffffffffffffffffffffffff1681526020016000815260200160008152602001600063ffffffff16815260200160008019168152602001600081526020016000815260200160008152602001606081525090565b8152602001906001900390816103c45790505090506040518061016001604052806000815260200160018152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001896020013581526020018860200135815260200163ffffffff801681526020016000801b815260200160008152602001604081526020016000815260200130604051602001610506919060609190911b7fffffffffffffffffffffffffffffffffffffffff00000000000000000000000016815260140190565b6040516020818303038152906040528152508160008151811061052b5761052b610cde565b602002602001018190525061053e610aef565b60208088013590610551908b018b610c5c565b73ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e8c61057a60208c018c610c5c565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff928316600482015291166024820152604401602060405180830381865afa1580156105ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061060e9190610c79565b101561078c5760408051600180825281830190925290816020015b60408051606080820183526000808352602083015291810191909152815260200190600190039081610629575050815261066660208a018a610c5c565b8151805160009061067957610679610cde565b60209081029190910181015173ffffffffffffffffffffffffffffffffffffffff9092169091526106ac908a018a610c5c565b73ffffffffffffffffffffffffffffffffffffffff1663095ea7b36106d460208a018a610c5c565b60405173ffffffffffffffffffffffffffffffffffffffff909116602482015260208a01356044820152606401604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1660e09390931b929092179091529050816000602002015160008151811061077c5761077c610cde565b6020026020010151604001819052505b60408051600180825281830190925290816020015b604080516060808201835260008083526020830152918101919091528152602001906001900390816107a157505060208201526107dd86610d85565b602082015180516000906107f3576107f3610cde565b60200260200101819052506108b18a73ffffffffffffffffffffffffffffffffffffffff166313d79a0b868686866040516024016108349493929190611084565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1660e09390931b9290921790915273ffffffffffffffffffffffffffffffffffffffff8d16915061099c565b9450505050505b95945050505050565b6040805173ffffffffffffffffffffffffffffffffffffffff848116602483015260448083018590528351808403909101815260649092019092526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b30000000000000000000000000000000000000000000000000000000017905290600090610954908616836109b1565b9050610995816040518060400160405280601a81526020017f5361666545524332303a20617070726f76616c206661696c65640000000000008152506109bf565b5050505050565b60006109aa83600084610a0f565b9392505050565b60606109aa83600084610a42565b6109c882610ac8565b8190610a0a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a01919061113d565b60405180910390fd5b505050565b60005a905060008083516020850186885af1610a2f573d6000803e3d6000fd5b5a610a3a9082611150565b949350505050565b606060008473ffffffffffffffffffffffffffffffffffffffff168484604051610a6c919061118a565b60006040518083038185875af1925050503d8060008114610aa9576040519150601f19603f3d011682016040523d82523d6000602084013e610aae565b606091505b509250905080610ac057815160208301fd5b509392505050565b6000815160001480610ae9575081806020019051810190610ae991906111a6565b92915050565b60405180606001604052806003905b6060815260200190600190039081610afe5790505090565b600080600060408486031215610b2b57600080fd5b83359250602084013567ffffffffffffffff80821115610b4a57600080fd5b818601915086601f830112610b5e57600080fd5b813581811115610b6d57600080fd5b876020828501011115610b7f57600080fd5b6020830194508093505050509250925092565b73ffffffffffffffffffffffffffffffffffffffff81168114610bb457600080fd5b50565b600060408284031215610bc957600080fd5b50919050565b60008060008060006101008688031215610be857600080fd5b8535610bf381610b92565b9450610c028760208801610bb7565b9350610c118760608801610bb7565b9250610c208760a08801610bb7565b915060e086013567ffffffffffffffff811115610c3c57600080fd5b860160608189031215610c4e57600080fd5b809150509295509295909350565b600060208284031215610c6e57600080fd5b81356109aa81610b92565b600060208284031215610c8b57600080fd5b5051919050565b600060208284031215610ca457600080fd5b81516109aa81610b92565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6040516060810167ffffffffffffffff81118282101715610d3057610d30610caf565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715610d7d57610d7d610caf565b604052919050565b600060608236031215610d9757600080fd5b610d9f610d0d565b8235610daa81610b92565b815260208381013581830152604084013567ffffffffffffffff80821115610dd157600080fd5b9085019036601f830112610de457600080fd5b813581811115610df657610df6610caf565b610e26847fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f84011601610d36565b91508082523684828501011115610e3c57600080fd5b808484018584013760009082019093019290925250604082015292915050565b60005b83811015610e77578181015183820152602001610e5f565b50506000910152565b60008151808452610e98816020860160208601610e5c565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b600081518084526020808501808196508360051b8101915082860160005b85811015610faa5782840389528151610160815186528682015187870152604080830151610f2d8289018273ffffffffffffffffffffffffffffffffffffffff169052565b5050606082810151908701526080808301519087015260a08083015163ffffffff169087015260c0808301519087015260e080830151908701526101008083015190870152610120808301519087015261014091820151918601819052610f9681870183610e80565b9a87019a9550505090840190600101610ee8565b5091979650505050505050565b6000826060808201846000805b6003811015610faa578584038952825180518086526020918201918087019190600582901b88018101865b8381101561106d578982037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe00185528551805173ffffffffffffffffffffffffffffffffffffffff16835283810151848401526040908101519083018c905261105a8c840182610e80565b9684019695840195925050600101610fef565b509c81019c97509590950194505050600101610fc4565b6080808252855190820181905260009060209060a0840190828901845b828110156110d357815173ffffffffffffffffffffffffffffffffffffffff16845292840192908401906001016110a1565b5050508381038285015286518082528783019183019060005b81811015611108578351835292840192918401916001016110ec565b5050848103604086015261111c8188610eca565b9250505082810360608401526111328185610fb7565b979650505050505050565b6020815260006109aa6020830184610e80565b81810381811115610ae9577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000825161119c818460208701610e5c565b9190910192915050565b6000602082840312156111b857600080fd5b815180151581146109aa57600080fdfea164736f6c6343000811000a","devdoc":{"methods":{}},"userdoc":{"methods":{}}} diff --git a/crates/contracts/artifacts/Trader.json b/crates/contracts/artifacts/Trader.json index f2a600e845..2614e657ac 100644 --- a/crates/contracts/artifacts/Trader.json +++ b/crates/contracts/artifacts/Trader.json @@ -1 +1 @@ -{"abi":[{"stateMutability":"payable","type":"fallback"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"isValidSignature","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"contract ISettlement","name":"settlementContract","type":"address"},{"internalType":"address","name":"sellToken","type":"address"},{"internalType":"uint256","name":"sellAmount","type":"uint256"},{"internalType":"address","name":"nativeToken","type":"address"}],"name":"prepareSwap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}],"bytecode":"0x608060405234801561001057600080fd5b50610bb5806100206000396000f3fe60806040526004361061002d5760003560e01c80631626ba7e1461008657806357d5a1d3146100fe57610034565b3661003457005b600061007c6000368080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525062010000939250506101209050565b9050805160208201f35b34801561009257600080fd5b506100c96100a136600461098b565b7f1626ba7e000000000000000000000000000000000000000000000000000000009392505050565b6040517fffffffff00000000000000000000000000000000000000000000000000000000909116815260200160405180910390f35b34801561010a57600080fd5b5061011e610119366004610a2c565b6101a2565b005b606060008373ffffffffffffffffffffffffffffffffffffffff16836040516101499190610aa3565b600060405180830381855af49150503d8060008114610184576040519150601f19603f3d011682016040523d82523d6000602084013e610189565b606091505b50925090508061019b57815160208301fd5b5092915050565b6101aa61077f565b1561023c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602360248201527f70726570617265537761702063616e206f6e6c792062652063616c6c6564206f60448201527f6e6365000000000000000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16036103e7576040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009073ffffffffffffffffffffffffffffffffffffffff8516906370a0823190602401602060405180830381865afa1580156102dc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103009190610abf565b9050828110156103e55760006103168285610ad8565b905080471015610382576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f6e6f7420656e6f7567682045544820746f2077726170000000000000000000006044820152606401610233565b8273ffffffffffffffffffffffffffffffffffffffff1663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b1580156103ca57600080fd5b505af11580156103de573d6000803e3d6000fd5b5050505050505b505b60008373ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e308773ffffffffffffffffffffffffffffffffffffffff16639b552cc26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610451573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104759190610b18565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff928316600482015291166024820152604401602060405180830381865afa1580156104e5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105099190610abf565b905082811015610654576105a48573ffffffffffffffffffffffffffffffffffffffff16639b552cc26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610561573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105859190610b18565b73ffffffffffffffffffffffffffffffffffffffff86169060006107ba565b6106548573ffffffffffffffffffffffffffffffffffffffff16639b552cc26040518163ffffffff1660e01b8152600401602060405180830381865afa1580156105f2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106169190610b18565b73ffffffffffffffffffffffffffffffffffffffff8616907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6107ba565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009073ffffffffffffffffffffffffffffffffffffffff8616906370a0823190602401602060405180830381865afa1580156106c1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106e59190610abf565b905083811015610777576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f74726164657220646f6573206e6f74206861766520656e6f7567682073656c6c60448201527f5f746f6b656e00000000000000000000000000000000000000000000000000006064820152608401610233565b505050505050565b6000806107ad60017f7f36ecad6e52bbe2ff70badce94360882c890b7877b16131c08eabfc635c9735610ad8565b8054600190915592915050565b6040805173ffffffffffffffffffffffffffffffffffffffff848116602483015260448083018590528351808403909101815260649092019092526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b3000000000000000000000000000000000000000000000000000000001790529060009061084d90861683610895565b905061088e816040518060400160405280601a81526020017f5361666545524332303a20617070726f76616c206661696c65640000000000008152506108aa565b5050505050565b60606108a383600084610905565b9392505050565b815115806108c75750818060200190518101906108c79190610b35565b8190610900576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102339190610b57565b505050565b606060008473ffffffffffffffffffffffffffffffffffffffff16848460405161092f9190610aa3565b60006040518083038185875af1925050503d806000811461096c576040519150601f19603f3d011682016040523d82523d6000602084013e610971565b606091505b50925090508061098357815160208301fd5b509392505050565b6000806000604084860312156109a057600080fd5b83359250602084013567ffffffffffffffff808211156109bf57600080fd5b818601915086601f8301126109d357600080fd5b8135818111156109e257600080fd5b8760208285010111156109f457600080fd5b6020830194508093505050509250925092565b73ffffffffffffffffffffffffffffffffffffffff81168114610a2957600080fd5b50565b60008060008060808587031215610a4257600080fd5b8435610a4d81610a07565b93506020850135610a5d81610a07565b9250604085013591506060850135610a7481610a07565b939692955090935050565b60005b83811015610a9a578181015183820152602001610a82565b50506000910152565b60008251610ab5818460208701610a7f565b9190910192915050565b600060208284031215610ad157600080fd5b5051919050565b81810381811115610b12577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b92915050565b600060208284031215610b2a57600080fd5b81516108a381610a07565b600060208284031215610b4757600080fd5b815180151581146108a357600080fd5b6020815260008251806020840152610b76816040850160208701610a7f565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016919091016040019291505056fea164736f6c6343000811000a","deployedBytecode":"0x60806040526004361061002d5760003560e01c80631626ba7e1461008657806357d5a1d3146100fe57610034565b3661003457005b600061007c6000368080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525062010000939250506101209050565b9050805160208201f35b34801561009257600080fd5b506100c96100a136600461098b565b7f1626ba7e000000000000000000000000000000000000000000000000000000009392505050565b6040517fffffffff00000000000000000000000000000000000000000000000000000000909116815260200160405180910390f35b34801561010a57600080fd5b5061011e610119366004610a2c565b6101a2565b005b606060008373ffffffffffffffffffffffffffffffffffffffff16836040516101499190610aa3565b600060405180830381855af49150503d8060008114610184576040519150601f19603f3d011682016040523d82523d6000602084013e610189565b606091505b50925090508061019b57815160208301fd5b5092915050565b6101aa61077f565b1561023c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602360248201527f70726570617265537761702063616e206f6e6c792062652063616c6c6564206f60448201527f6e6365000000000000000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16036103e7576040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009073ffffffffffffffffffffffffffffffffffffffff8516906370a0823190602401602060405180830381865afa1580156102dc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103009190610abf565b9050828110156103e55760006103168285610ad8565b905080471015610382576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f6e6f7420656e6f7567682045544820746f2077726170000000000000000000006044820152606401610233565b8273ffffffffffffffffffffffffffffffffffffffff1663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b1580156103ca57600080fd5b505af11580156103de573d6000803e3d6000fd5b5050505050505b505b60008373ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e308773ffffffffffffffffffffffffffffffffffffffff16639b552cc26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610451573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104759190610b18565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff928316600482015291166024820152604401602060405180830381865afa1580156104e5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105099190610abf565b905082811015610654576105a48573ffffffffffffffffffffffffffffffffffffffff16639b552cc26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610561573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105859190610b18565b73ffffffffffffffffffffffffffffffffffffffff86169060006107ba565b6106548573ffffffffffffffffffffffffffffffffffffffff16639b552cc26040518163ffffffff1660e01b8152600401602060405180830381865afa1580156105f2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106169190610b18565b73ffffffffffffffffffffffffffffffffffffffff8616907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6107ba565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009073ffffffffffffffffffffffffffffffffffffffff8616906370a0823190602401602060405180830381865afa1580156106c1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106e59190610abf565b905083811015610777576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f74726164657220646f6573206e6f74206861766520656e6f7567682073656c6c60448201527f5f746f6b656e00000000000000000000000000000000000000000000000000006064820152608401610233565b505050505050565b6000806107ad60017f7f36ecad6e52bbe2ff70badce94360882c890b7877b16131c08eabfc635c9735610ad8565b8054600190915592915050565b6040805173ffffffffffffffffffffffffffffffffffffffff848116602483015260448083018590528351808403909101815260649092019092526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b3000000000000000000000000000000000000000000000000000000001790529060009061084d90861683610895565b905061088e816040518060400160405280601a81526020017f5361666545524332303a20617070726f76616c206661696c65640000000000008152506108aa565b5050505050565b60606108a383600084610905565b9392505050565b815115806108c75750818060200190518101906108c79190610b35565b8190610900576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102339190610b57565b505050565b606060008473ffffffffffffffffffffffffffffffffffffffff16848460405161092f9190610aa3565b60006040518083038185875af1925050503d806000811461096c576040519150601f19603f3d011682016040523d82523d6000602084013e610971565b606091505b50925090508061098357815160208301fd5b509392505050565b6000806000604084860312156109a057600080fd5b83359250602084013567ffffffffffffffff808211156109bf57600080fd5b818601915086601f8301126109d357600080fd5b8135818111156109e257600080fd5b8760208285010111156109f457600080fd5b6020830194508093505050509250925092565b73ffffffffffffffffffffffffffffffffffffffff81168114610a2957600080fd5b50565b60008060008060808587031215610a4257600080fd5b8435610a4d81610a07565b93506020850135610a5d81610a07565b9250604085013591506060850135610a7481610a07565b939692955090935050565b60005b83811015610a9a578181015183820152602001610a82565b50506000910152565b60008251610ab5818460208701610a7f565b9190910192915050565b600060208284031215610ad157600080fd5b5051919050565b81810381811115610b12577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b92915050565b600060208284031215610b2a57600080fd5b81516108a381610a07565b600060208284031215610b4757600080fd5b815180151581146108a357600080fd5b6020815260008251806020840152610b76816040850160208701610a7f565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016919091016040019291505056fea164736f6c6343000811000a","devdoc":{"methods":{}},"userdoc":{"methods":{}}} +{"abi":[{"stateMutability":"payable","type":"fallback"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"isValidSignature","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"contract ISettlement","name":"settlementContract","type":"address"},{"internalType":"address","name":"sellToken","type":"address"},{"internalType":"uint256","name":"sellAmount","type":"uint256"},{"internalType":"address","name":"nativeToken","type":"address"}],"name":"prepareSwap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}],"bytecode":"0x608060405234801561001057600080fd5b50610a97806100206000396000f3fe60806040526004361061002d5760003560e01c80631626ba7e1461008657806357d5a1d3146100fe57610034565b3661003457005b600061007c6000368080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525062010000939250506101209050565b9050805160208201f35b34801561009257600080fd5b506100c96100a1366004610873565b7f1626ba7e000000000000000000000000000000000000000000000000000000009392505050565b6040517fffffffff00000000000000000000000000000000000000000000000000000000909116815260200160405180910390f35b34801561010a57600080fd5b5061011e610119366004610914565b6101a2565b005b606060008373ffffffffffffffffffffffffffffffffffffffff1683604051610149919061098b565b600060405180830381855af49150503d8060008114610184576040519150601f19603f3d011682016040523d82523d6000602084013e610189565b606091505b50925090508061019b57815160208301fd5b5092915050565b6101aa61065b565b1561023c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602360248201527f70726570617265537761702063616e206f6e6c792062652063616c6c6564206f60448201527f6e6365000000000000000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16036103e7576040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009073ffffffffffffffffffffffffffffffffffffffff8516906370a0823190602401602060405180830381865afa1580156102dc573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061030091906109a7565b9050828110156103e557600061031682856109c0565b905080471015610382576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f6e6f7420656e6f7567682045544820746f2077726170000000000000000000006044820152606401610233565b8273ffffffffffffffffffffffffffffffffffffffff1663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b1580156103ca57600080fd5b505af11580156103de573d6000803e3d6000fd5b5050505050505b505b60008373ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e308773ffffffffffffffffffffffffffffffffffffffff16639b552cc26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610451573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061047591906109fa565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff928316600482015291166024820152604401602060405180830381865afa1580156104e5573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061050991906109a7565b905082811015610654576105a48573ffffffffffffffffffffffffffffffffffffffff16639b552cc26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610561573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061058591906109fa565b73ffffffffffffffffffffffffffffffffffffffff8616906000610696565b6106548573ffffffffffffffffffffffffffffffffffffffff16639b552cc26040518163ffffffff1660e01b8152600401602060405180830381865afa1580156105f2573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061061691906109fa565b73ffffffffffffffffffffffffffffffffffffffff8616907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff610696565b5050505050565b60008061068960017f7f36ecad6e52bbe2ff70badce94360882c890b7877b16131c08eabfc635c97356109c0565b8054600190915592915050565b6040805173ffffffffffffffffffffffffffffffffffffffff848116602483015260448083018590528351808403909101815260649092019092526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b300000000000000000000000000000000000000000000000000000000179052906000906107299086168361076a565b9050610654816040518060400160405280601a81526020017f5361666545524332303a20617070726f76616c206661696c656400000000000081525061077f565b6060610778836000846107c6565b9392505050565b6107888261084c565b81906107c1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102339190610a17565b505050565b606060008473ffffffffffffffffffffffffffffffffffffffff1684846040516107f0919061098b565b60006040518083038185875af1925050503d806000811461082d576040519150601f19603f3d011682016040523d82523d6000602084013e610832565b606091505b50925090508061084457815160208301fd5b509392505050565b600081516000148061086d57508180602001905181019061086d9190610a68565b92915050565b60008060006040848603121561088857600080fd5b83359250602084013567ffffffffffffffff808211156108a757600080fd5b818601915086601f8301126108bb57600080fd5b8135818111156108ca57600080fd5b8760208285010111156108dc57600080fd5b6020830194508093505050509250925092565b73ffffffffffffffffffffffffffffffffffffffff8116811461091157600080fd5b50565b6000806000806080858703121561092a57600080fd5b8435610935816108ef565b93506020850135610945816108ef565b925060408501359150606085013561095c816108ef565b939692955090935050565b60005b8381101561098257818101518382015260200161096a565b50506000910152565b6000825161099d818460208701610967565b9190910192915050565b6000602082840312156109b957600080fd5b5051919050565b8181038181111561086d577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600060208284031215610a0c57600080fd5b8151610778816108ef565b6020815260008251806020840152610a36816040850160208701610967565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169190910160400192915050565b600060208284031215610a7a57600080fd5b8151801515811461077857600080fdfea164736f6c6343000811000a","deployedBytecode":"0x60806040526004361061002d5760003560e01c80631626ba7e1461008657806357d5a1d3146100fe57610034565b3661003457005b600061007c6000368080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525062010000939250506101209050565b9050805160208201f35b34801561009257600080fd5b506100c96100a1366004610873565b7f1626ba7e000000000000000000000000000000000000000000000000000000009392505050565b6040517fffffffff00000000000000000000000000000000000000000000000000000000909116815260200160405180910390f35b34801561010a57600080fd5b5061011e610119366004610914565b6101a2565b005b606060008373ffffffffffffffffffffffffffffffffffffffff1683604051610149919061098b565b600060405180830381855af49150503d8060008114610184576040519150601f19603f3d011682016040523d82523d6000602084013e610189565b606091505b50925090508061019b57815160208301fd5b5092915050565b6101aa61065b565b1561023c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602360248201527f70726570617265537761702063616e206f6e6c792062652063616c6c6564206f60448201527f6e6365000000000000000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16036103e7576040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009073ffffffffffffffffffffffffffffffffffffffff8516906370a0823190602401602060405180830381865afa1580156102dc573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061030091906109a7565b9050828110156103e557600061031682856109c0565b905080471015610382576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f6e6f7420656e6f7567682045544820746f2077726170000000000000000000006044820152606401610233565b8273ffffffffffffffffffffffffffffffffffffffff1663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b1580156103ca57600080fd5b505af11580156103de573d6000803e3d6000fd5b5050505050505b505b60008373ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e308773ffffffffffffffffffffffffffffffffffffffff16639b552cc26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610451573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061047591906109fa565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff928316600482015291166024820152604401602060405180830381865afa1580156104e5573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061050991906109a7565b905082811015610654576105a48573ffffffffffffffffffffffffffffffffffffffff16639b552cc26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610561573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061058591906109fa565b73ffffffffffffffffffffffffffffffffffffffff8616906000610696565b6106548573ffffffffffffffffffffffffffffffffffffffff16639b552cc26040518163ffffffff1660e01b8152600401602060405180830381865afa1580156105f2573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061061691906109fa565b73ffffffffffffffffffffffffffffffffffffffff8616907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff610696565b5050505050565b60008061068960017f7f36ecad6e52bbe2ff70badce94360882c890b7877b16131c08eabfc635c97356109c0565b8054600190915592915050565b6040805173ffffffffffffffffffffffffffffffffffffffff848116602483015260448083018590528351808403909101815260649092019092526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b300000000000000000000000000000000000000000000000000000000179052906000906107299086168361076a565b9050610654816040518060400160405280601a81526020017f5361666545524332303a20617070726f76616c206661696c656400000000000081525061077f565b6060610778836000846107c6565b9392505050565b6107888261084c565b81906107c1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102339190610a17565b505050565b606060008473ffffffffffffffffffffffffffffffffffffffff1684846040516107f0919061098b565b60006040518083038185875af1925050503d806000811461082d576040519150601f19603f3d011682016040523d82523d6000602084013e610832565b606091505b50925090508061084457815160208301fd5b509392505050565b600081516000148061086d57508180602001905181019061086d9190610a68565b92915050565b60008060006040848603121561088857600080fd5b83359250602084013567ffffffffffffffff808211156108a757600080fd5b818601915086601f8301126108bb57600080fd5b8135818111156108ca57600080fd5b8760208285010111156108dc57600080fd5b6020830194508093505050509250925092565b73ffffffffffffffffffffffffffffffffffffffff8116811461091157600080fd5b50565b6000806000806080858703121561092a57600080fd5b8435610935816108ef565b93506020850135610945816108ef565b925060408501359150606085013561095c816108ef565b939692955090935050565b60005b8381101561098257818101518382015260200161096a565b50506000910152565b6000825161099d818460208701610967565b9190910192915050565b6000602082840312156109b957600080fd5b5051919050565b8181038181111561086d577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600060208284031215610a0c57600080fd5b8151610778816108ef565b6020815260008251806020840152610a36816040850160208701610967565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169190910160400192915050565b600060208284031215610a7a57600080fd5b8151801515811461077857600080fdfea164736f6c6343000811000a","devdoc":{"methods":{}},"userdoc":{"methods":{}}} diff --git a/crates/contracts/build.rs b/crates/contracts/build.rs index 7a6e4369bb..dda30d09e8 100644 --- a/crates/contracts/build.rs +++ b/crates/contracts/build.rs @@ -990,8 +990,9 @@ fn main() { generate_contract("CowAmmUniswapV2PriceOracle"); // Support contracts used for trade and token simulations. - generate_contract("Trader"); generate_contract("Solver"); + generate_contract("Spardose"); + generate_contract("Trader"); // Support contracts used for various order simulations. generate_contract("Balances"); diff --git a/crates/contracts/solidity/Makefile b/crates/contracts/solidity/Makefile index 5816391d8d..9402416722 100644 --- a/crates/contracts/solidity/Makefile +++ b/crates/contracts/solidity/Makefile @@ -14,6 +14,7 @@ CONTRACTS := \ Signatures.sol \ SimulateCode.sol \ Solver.sol \ + Spardose.sol \ Swapper.sol \ Trader.sol ARTIFACTS := $(patsubst %.sol,$(ARTIFACTDIR)/%.json,$(CONTRACTS)) diff --git a/crates/contracts/solidity/Solver.sol b/crates/contracts/solidity/Solver.sol index 9833c1e5c1..a7a27a9fff 100644 --- a/crates/contracts/solidity/Solver.sol +++ b/crates/contracts/solidity/Solver.sol @@ -6,6 +6,7 @@ import { Interaction, Trade, ISettlement } from "./interfaces/ISettlement.sol"; import { Caller } from "./libraries/Caller.sol"; import { Math } from "./libraries/Math.sol"; import { SafeERC20 } from "./libraries/SafeERC20.sol"; +import { Spardose } from "./Spardose.sol"; import { Trader } from "./Trader.sol"; /// @title A contract for impersonating a solver. This contract @@ -16,7 +17,11 @@ import { Trader } from "./Trader.sol"; contract Solver { using Caller for *; using Math for *; - using SafeERC20 for *; + + struct Mock { + bool enabled; + address spardose; + } uint256 private _simulationOverhead; uint256[] private _queriedBalances; @@ -35,10 +40,10 @@ contract Solver { /// @param tokens - list of tokens used in the trade /// @param receiver - address receiving the bought tokens /// @param settlementCall - the calldata of the `settle()` call - /// @param mockPreconditions - controls whether things like ETH wrapping - /// or setting allowance should be done on behalf of the - /// user to support quote verification even if the user didn't - /// wrap their ETH or set the necessary allowances yet. + /// @param mock - mocking configuration for the simulation; this controls + /// whether things like ETH wrapping, setting allowance and + /// pre-funding should be done on behalf of the user to support + /// quote verification for users who aren't ready to swap. /// /// @return gasUsed - gas used for the `settle()` call /// @return queriedBalances - list of balances stored during the simulation @@ -51,16 +56,16 @@ contract Solver { address[] calldata tokens, address payable receiver, bytes calldata settlementCall, - bool mockPreconditions + Mock memory mock ) external returns ( uint256 gasUsed, uint256[] memory queriedBalances ) { require(msg.sender == address(this), "only simulation logic is allowed to call 'swap' function"); - // Prepare the trade in the context of the trader so we are allowed - // to set approvals and things like that. - if (mockPreconditions) { + if (mock.enabled) { + // Prepare the trade in the context of the trader so we are allowed + // to set approvals and things like that. Trader(trader) .prepareSwap( settlementContract, @@ -68,13 +73,20 @@ contract Solver { sellAmount, nativeToken ); + + // Ensure that the user has sufficient sell token balance for the + // swap using balance overrides. + Spardose(mock.spardose).ensureBalance(trader, sellToken, sellAmount); } // Warm the storage for sending ETH to smart contract addresses. // We allow this call to revert becaues it was either unnecessary in the first place // or failing to send `ETH` to the `receiver` will cause a revert in the settlement // contract. - receiver.call{value: 0}(""); + { + (bool success,) = receiver.call{value: 0}(""); + success; + } // Store pre-settlement balances _storeSettlementBalances(tokens, settlementContract); diff --git a/crates/contracts/solidity/Spardose.sol b/crates/contracts/solidity/Spardose.sol new file mode 100644 index 0000000000..502261ac02 --- /dev/null +++ b/crates/contracts/solidity/Spardose.sol @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.17; + +import { IERC20 } from "./interfaces/IERC20.sol"; +import { SafeERC20 } from "./libraries/SafeERC20.sol"; + +/// @title A piggy bank contract (Spardose is piggy bank in German) +/// @notice This contract account is used for pre-funding traders with tokens +/// for quote simulations. A separate contract is used (instead of overriding +/// the balance of the solver or trader directly) in order to interfere as +/// little as possible with the settlement. +contract Spardose { + using SafeERC20 for *; + + /// @dev Ensures that the trader has at least `amount` tokens. If not, it + /// will transfer the difference to the trader. + /// + /// @param trader - the address of the trader + /// @param token - the token to ensure a balance for + /// @param amount - the amount of `token` that the `trader` must hold. + function ensureBalance(address trader, address token, uint256 amount) external { + uint256 traderBalance = IERC20(token).balanceOf(trader); + if (traderBalance >= amount) { + // Nothing to do. + return; + } + + uint256 difference = amount - traderBalance; + require( + IERC20(token).trySafeTransfer(trader, difference), + "trader does not have enough sell_token" + ); + } +} diff --git a/crates/contracts/solidity/Trader.sol b/crates/contracts/solidity/Trader.sol index d1354cb982..c9fa5e0fdf 100644 --- a/crates/contracts/solidity/Trader.sol +++ b/crates/contracts/solidity/Trader.sol @@ -99,9 +99,6 @@ contract Trader { IERC20(sellToken).safeApprove(address(settlementContract.vaultRelayer()), 0); IERC20(sellToken).safeApprove(address(settlementContract.vaultRelayer()), type(uint256).max); } - - uint256 availableSellToken = IERC20(sellToken).balanceOf(address(this)); - require(availableSellToken >= sellAmount, "trader does not have enough sell_token"); } /// @dev Validate all signature requests. This makes "signing" CoW protocol diff --git a/crates/contracts/solidity/libraries/SafeERC20.sol b/crates/contracts/solidity/libraries/SafeERC20.sol index 785ff3324d..9cc30ef35f 100644 --- a/crates/contracts/solidity/libraries/SafeERC20.sol +++ b/crates/contracts/solidity/libraries/SafeERC20.sol @@ -7,13 +7,24 @@ import { Caller } from "./Caller.sol"; library SafeERC20 { using Caller for *; + function trySafeTransfer(IERC20 self, address target, uint256 amount) internal returns (bool success) { + bytes memory cdata = abi.encodeCall(self.transfer, (target, amount)); + bytes memory rdata; + (success, rdata) = address(self).call(cdata); + return success && check(rdata); + } + function safeApprove(IERC20 self, address target, uint256 amount) internal { bytes memory cdata = abi.encodeCall(self.approve, (target, amount)); bytes memory rdata = address(self).doCall(cdata); - check(rdata, "SafeERC20: approval failed"); + ensure(rdata, "SafeERC20: approval failed"); + } + + function check(bytes memory rdata) internal pure returns (bool ok) { + return rdata.length == 0 || abi.decode(rdata, (bool)); } - function check(bytes memory self, string memory message) internal pure { - require(self.length == 0 || abi.decode(self, (bool)), message); + function ensure(bytes memory rdata, string memory message) internal pure { + require(check(rdata), message); } } diff --git a/crates/contracts/src/lib.rs b/crates/contracts/src/lib.rs index b033656adb..f9aefaca3e 100644 --- a/crates/contracts/src/lib.rs +++ b/crates/contracts/src/lib.rs @@ -114,6 +114,7 @@ pub mod support { Signatures; SimulateCode; Solver; + Spardose; Swapper; Trader; } diff --git a/crates/e2e/tests/e2e/quote_verification.rs b/crates/e2e/tests/e2e/quote_verification.rs index 5e442d2e35..2aafb0e98b 100644 --- a/crates/e2e/tests/e2e/quote_verification.rs +++ b/crates/e2e/tests/e2e/quote_verification.rs @@ -1,7 +1,7 @@ use { bigdecimal::{BigDecimal, Zero}, - e2e::setup::*, - ethcontract::H160, + e2e::{setup::*, tx}, + ethcontract::{H160, U256}, ethrpc::Web3, model::{ order::{BuyTokenDestination, OrderKind, SellTokenSource}, @@ -19,6 +19,12 @@ use { std::{str::FromStr, sync::Arc}, }; +#[tokio::test] +#[ignore] +async fn local_node_standard_verified_quote() { + run_test(standard_verified_quote).await; +} + #[tokio::test] #[ignore] async fn forked_node_bypass_verification_for_rfq_quotes() { @@ -37,6 +43,51 @@ async fn local_node_verified_quote_for_settlement_contract() { run_test(verified_quote_for_settlement_contract).await; } +#[tokio::test] +#[ignore] +async fn local_node_verified_quote_with_simulated_balance() { + run_test(verified_quote_with_simulated_balance).await; +} + +/// Verified quotes work as expected. +async fn standard_verified_quote(web3: Web3) { + tracing::info!("Setting up chain state."); + let mut onchain = OnchainComponents::deploy(web3).await; + + let [solver] = onchain.make_solvers(to_wei(10)).await; + let [trader] = onchain.make_accounts(to_wei(1)).await; + let [token] = onchain + .deploy_tokens_with_weth_uni_v2_pools(to_wei(1_000), to_wei(1_000)) + .await; + + token.mint(trader.address(), to_wei(1)).await; + tx!( + trader.account(), + token.approve(onchain.contracts().allowance, to_wei(1)) + ); + + tracing::info!("Starting services."); + let services = Services::new(&onchain).await; + services.start_protocol(solver).await; + + // quote where the trader has no balances or approval set. + let response = services + .submit_quote(&OrderQuoteRequest { + from: trader.address(), + sell_token: token.address(), + buy_token: onchain.contracts().weth.address(), + side: OrderQuoteSide::Sell { + sell_amount: SellAmount::BeforeFee { + value: to_wei(1).try_into().unwrap(), + }, + }, + ..Default::default() + }) + .await + .unwrap(); + assert!(response.verified); +} + /// The block number from which we will fetch state for the forked tests. const FORK_BLOCK_MAINNET: u64 = 19796077; @@ -208,3 +259,50 @@ async fn verified_quote_for_settlement_contract(web3: Web3) { .unwrap(); assert!(response.verified); } + +/// Test that asserts that we can verify quotes for traders with simulated +/// balances. +async fn verified_quote_with_simulated_balance(web3: Web3) { + tracing::info!("Setting up chain state."); + let mut onchain = OnchainComponents::deploy(web3).await; + + let [solver] = onchain.make_solvers(to_wei(10)).await; + let [trader] = onchain.make_accounts(to_wei(0)).await; + let [token] = onchain + .deploy_tokens_with_weth_uni_v2_pools(to_wei(1_000), to_wei(1_000)) + .await; + + tracing::info!("Starting services."); + let services = Services::new(&onchain).await; + services + .start_protocol_with_args( + ExtraServiceArgs { + api: vec![format!( + // The OpenZeppelin `ERC20Mintable` token uses a mapping in + // the first (0'th) storage slot for balances. + "--quote-token-balance-overrides={:?}@0", + token.address() + )], + ..Default::default() + }, + solver, + ) + .await; + + // quote where the trader has no balances or approval set. + let response = services + .submit_quote(&OrderQuoteRequest { + from: trader.address(), + sell_token: token.address(), + buy_token: onchain.contracts().weth.address(), + side: OrderQuoteSide::Sell { + sell_amount: SellAmount::BeforeFee { + value: to_wei(1).try_into().unwrap(), + }, + }, + ..Default::default() + }) + .await + .unwrap(); + assert!(response.verified); +} diff --git a/crates/ethrpc/src/extensions.rs b/crates/ethrpc/src/extensions.rs index 78f2d77eea..d57ff77993 100644 --- a/crates/ethrpc/src/extensions.rs +++ b/crates/ethrpc/src/extensions.rs @@ -68,12 +68,12 @@ pub struct StateOverride { /// Fake key-value mapping to override **all** slots in the account storage /// before executing the call. #[serde(skip_serializing_if = "Option::is_none")] - pub state: Option>, + pub state: Option>, /// Fake key-value mapping to override **individual** slots in the account /// storage before executing the call. #[serde(skip_serializing_if = "Option::is_none")] - pub state_diff: Option>, + pub state_diff: Option>, } #[cfg(test)] diff --git a/crates/shared/src/code_simulation.rs b/crates/shared/src/code_simulation.rs index 7035c2dfb6..40a3fb4d82 100644 --- a/crates/shared/src/code_simulation.rs +++ b/crates/shared/src/code_simulation.rs @@ -4,7 +4,7 @@ use { crate::tenderly_api::{SimulationKind, SimulationRequest, StateObject, TenderlyApi}, anyhow::{ensure, Context as _, Result}, contracts::errors::EthcontractErrorType, - ethcontract::{errors::ExecutionError, H256}, + ethcontract::errors::ExecutionError, ethrpc::{ extensions::{EthExt as _, StateOverride, StateOverrides}, Web3, @@ -206,16 +206,7 @@ impl TryFrom for StateObject { Ok(StateObject { balance: value.balance, code: value.code, - storage: value.state_diff.map(|state_diff| { - state_diff - .into_iter() - .map(|(key, uint)| { - let mut value = H256::default(); - uint.to_big_endian(&mut value.0); - (key, value) - }) - .collect() - }), + storage: value.state_diff, }) } } @@ -262,6 +253,7 @@ mod tests { use { super::*, crate::{ethrpc::create_env_test_transport, tenderly_api::TenderlyHttpApi}, + ethcontract::H256, hex_literal::hex, maplit::hashmap, std::time::Duration, @@ -393,7 +385,8 @@ mod tests { hashmap! { addr!("D533a949740bb3306d119CC777fa900bA034cd52") => StateOverride { state_diff: Some(hashmap! { - H256(balance_slot) => 1.into() + H256(balance_slot) => + H256(hex!("0000000000000000000000000000000000000000000000000000000000000001")), }), ..Default::default() }, diff --git a/crates/shared/src/price_estimation/factory.rs b/crates/shared/src/price_estimation/factory.rs index 03b2083264..cd5e38e2b2 100644 --- a/crates/shared/src/price_estimation/factory.rs +++ b/crates/shared/src/price_estimation/factory.rs @@ -113,17 +113,21 @@ impl<'a> PriceEstimatorFactory<'a> { None => Arc::new(web3.clone()), }; + let balance_overrides = Arc::new(args.quote_token_balance_overrides.clone()); + + let verifier = TradeVerifier::new( + web3, + simulator, + components.code_fetcher.clone(), + network.block_stream.clone(), + network.settlement, + network.native_token, + args.quote_inaccuracy_limit.clone(), + ) + .await?; + Ok(Some(Arc::new( - TradeVerifier::new( - web3, - simulator, - components.code_fetcher.clone(), - network.block_stream.clone(), - network.settlement, - network.native_token, - args.quote_inaccuracy_limit.clone(), - ) - .await?, + verifier.with_balance_overrides(balance_overrides), ))) } diff --git a/crates/shared/src/price_estimation/mod.rs b/crates/shared/src/price_estimation/mod.rs index 9ba6405f9a..50d1b32d7f 100644 --- a/crates/shared/src/price_estimation/mod.rs +++ b/crates/shared/src/price_estimation/mod.rs @@ -1,4 +1,5 @@ use { + self::trade_verifier::balance_overrides::ConfigurationBalanceOverrides, crate::{ arguments::{display_option, display_secret_option, ExternalSolver}, trade_finding::Interaction, @@ -211,6 +212,10 @@ pub struct Arguments { value_parser = humantime::parse_duration, )] pub quote_timeout: Duration, + + /// Token configuration for simulated balances on verified quotes. + #[clap(long, env, default_value_t)] + pub quote_token_balance_overrides: ConfigurationBalanceOverrides, } #[derive(clap::Parser)] @@ -290,6 +295,7 @@ impl Display for Arguments { quote_inaccuracy_limit, quote_verification, quote_timeout, + quote_token_balance_overrides, } = self; display_option( @@ -367,6 +373,11 @@ impl Display for Arguments { writeln!(f, "quote_inaccuracy_limit: {}", quote_inaccuracy_limit)?; writeln!(f, "quote_verification: {:?}", quote_verification)?; writeln!(f, "quote_timeout: {:?}", quote_timeout)?; + writeln!( + f, + "quote_token_balance_overrides: {:?}", + quote_token_balance_overrides + )?; Ok(()) } diff --git a/crates/shared/src/price_estimation/trade_verifier.rs b/crates/shared/src/price_estimation/trade_verifier.rs index 7107ac5ff0..e13e4ca70e 100644 --- a/crates/shared/src/price_estimation/trade_verifier.rs +++ b/crates/shared/src/price_estimation/trade_verifier.rs @@ -1,6 +1,11 @@ pub mod balance_overrides; use { + self::balance_overrides::{ + BalanceOverrideRequest, + BalanceOverriding, + ConfigurationBalanceOverrides, + }, super::{Estimate, Verification}, crate::{ code_fetching::CodeFetching, @@ -18,7 +23,7 @@ use { contracts::{ deployed_bytecode, dummy_contract, - support::{AnyoneAuthenticator, Solver, Trader}, + support::{AnyoneAuthenticator, Solver, Spardose, Trader}, GPv2Settlement, WETH9, }, @@ -58,6 +63,7 @@ pub struct TradeVerifier { web3: Web3, simulator: Arc, code_fetcher: Arc, + balance_overrides: Arc, block_stream: CurrentBlockWatcher, settlement: GPv2Settlement, native_token: H160, @@ -67,6 +73,7 @@ pub struct TradeVerifier { impl TradeVerifier { const DEFAULT_GAS: u64 = 8_000_000; + const SPARDOSE: H160 = addr!("0000000000000000000000000000000000020000"); const TRADER_IMPL: H160 = addr!("0000000000000000000000000000000000010000"); pub async fn new( @@ -84,6 +91,7 @@ impl TradeVerifier { Ok(Self { simulator, code_fetcher, + balance_overrides: Arc::new(ConfigurationBalanceOverrides::default()), block_stream, settlement: settlement_contract, native_token, @@ -93,6 +101,11 @@ impl TradeVerifier { }) } + pub fn with_balance_overrides(mut self, balance_overrides: Arc) -> Self { + self.balance_overrides = balance_overrides; + self + } + async fn verify_inner( &self, query: &PriceQuery, @@ -153,6 +166,11 @@ impl TradeVerifier { OrderKind::Buy => *out_amount, }; + // Only enable additional mocking (approvals, native token wrapping, + // balance overrides) if the user did not provide pre-interactions. If + // the user did provide pre-interactions, it's reasonable to assume that + // they will set up all the necessary details of the trade. + let mock_enabled = verification.pre_interactions.is_empty(); let simulation = solver .methods() .swap( @@ -164,11 +182,7 @@ impl TradeVerifier { tokens.clone(), verification.receiver, Bytes(settlement.data.unwrap().0), - // only if the user did not provide pre-interactions is it safe - // to set up the trade's pre-conditions on behalf of the user. - // if the user provided pre-interactions it's reasonable to assume - // that they will set up all the necessary details for the trade. - verification.pre_interactions.is_empty(), + (mock_enabled, Self::SPARDOSE), ) .tx; @@ -185,7 +199,7 @@ impl TradeVerifier { }; let overrides = self - .prepare_state_overrides(verification, trade) + .prepare_state_overrides(verification, query, trade) .await .map_err(Error::SimulationFailed)?; @@ -281,6 +295,7 @@ impl TradeVerifier { async fn prepare_state_overrides( &self, verification: &Verification, + query: &PriceQuery, trade: &TradeKind, ) -> Result> { // Set up mocked trader. @@ -308,6 +323,46 @@ impl TradeVerifier { ); } + // Setup the funding contract override. Regardless of whether or not the + // contract has funds, it needs to exist in order to not revert + // simulations (Solidity reverts on attempts to call addresses without + // any code). + overrides.insert( + Self::SPARDOSE, + StateOverride { + code: Some(deployed_bytecode!(Spardose)), + ..Default::default() + }, + ); + + // Provide mocked balances if possible to the solver to allow it to + // give some balances to the trader in order to verify trades even for + // owners without balances. Note that we explicitly override the + // **solver's** balance and not the trader's directly. This allows the + // simulation to conditionally transfer the balance only when it is + // safe to mock the trade pre-conditions on behalf of the user. We use + // a similar strategy for determining whether or not to set approvals on + // behalf of the trader. + if let Some(solver_balance_override) = + self.balance_overrides + .state_override(&BalanceOverrideRequest { + token: query.sell_token, + holder: Self::SPARDOSE, + amount: match query.kind { + OrderKind::Sell => query.in_amount.get(), + OrderKind::Buy => trade.out_amount( + &query.buy_token, + &query.sell_token, + &query.in_amount.get(), + &query.kind, + )?, + }, + }) + { + tracing::debug!(?solver_balance_override, "solver balance override enabled"); + overrides.insert(query.sell_token, solver_balance_override); + } + // Set up mocked solver. let mut solver_override = StateOverride { code: Some(deployed_bytecode!(Solver)), diff --git a/crates/shared/src/price_estimation/trade_verifier/balance_overrides.rs b/crates/shared/src/price_estimation/trade_verifier/balance_overrides.rs index e8992efb6c..65e04f0665 100644 --- a/crates/shared/src/price_estimation/trade_verifier/balance_overrides.rs +++ b/crates/shared/src/price_estimation/trade_verifier/balance_overrides.rs @@ -1,8 +1,13 @@ use { + anyhow::Context as _, ethcontract::{Address, H256, U256}, ethrpc::extensions::StateOverride, maplit::hashmap, - std::collections::HashMap, + std::{ + collections::HashMap, + fmt::{self, Display, Formatter}, + str::FromStr, + }, web3::signing, }; @@ -10,7 +15,7 @@ use { /// /// This allows a wider range of verified quotes to work, even when balances /// are not available for the quoter. -pub trait BalanceOverriding { +pub trait BalanceOverriding: Send + Sync + 'static { fn state_override(&self, request: &BalanceOverrideRequest) -> Option; } @@ -43,13 +48,68 @@ impl BalanceOverriding for ConfigurationBalanceOverrides { fn state_override(&self, request: &BalanceOverrideRequest) -> Option { let strategy = self.0.get(&request.token)?; match strategy { - Strategy::Mapping { slot } => Some(StateOverride { - state_diff: Some(hashmap! { - address_mapping_storage_slot(slot, &request.holder) => request.amount, - }), - ..Default::default() - }), + Strategy::Mapping { slot } => { + let slot = address_mapping_storage_slot(slot, &request.holder); + let value = { + let mut value = H256::default(); + request.amount.to_big_endian(&mut value.0); + value + }; + Some(StateOverride { + state_diff: Some(hashmap! { slot => value }), + ..Default::default() + }) + } + } + } +} + +impl Display for ConfigurationBalanceOverrides { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + let format_entry = + |f: &mut Formatter, (addr, strategy): (&Address, &Strategy)| match strategy { + Strategy::Mapping { slot } => write!(f, "{addr:?}@{slot}"), + }; + + let mut entries = self.0.iter(); + + let Some(first) = entries.next() else { + return Ok(()); + }; + format_entry(f, first)?; + + for entry in entries { + f.write_str(",")?; + format_entry(f, entry)?; } + + Ok(()) + } +} + +impl FromStr for ConfigurationBalanceOverrides { + type Err = anyhow::Error; + + fn from_str(s: &str) -> Result { + if s.is_empty() { + return Ok(Self::default()); + } + + let entries = s + .split(',') + .map(|part| -> Result<_, Self::Err> { + let (addr, slot) = part + .split_once('@') + .context("expected {addr}@{slot} format")?; + Ok(( + addr.parse()?, + Strategy::Mapping { + slot: slot.parse()?, + }, + )) + }) + .collect::>()?; + Ok(Self(entries)) } } @@ -84,7 +144,8 @@ mod tests { }), Some(StateOverride { state_diff: Some(hashmap! { - H256(hex!("fca351f4d96129454cfc8ef7930b638ac71fea35eb69ee3b8d959496beb04a33")) => 0x42_u64.into() + H256(hex!("fca351f4d96129454cfc8ef7930b638ac71fea35eb69ee3b8d959496beb04a33")) => + H256(hex!("0000000000000000000000000000000000000000000000000000000000000042")), }), ..Default::default() }), From 604beb493745b2639faa0f751b25343edd7b6234 Mon Sep 17 00:00:00 2001 From: Nicholas Rodrigues Lordello Date: Thu, 5 Dec 2024 15:40:56 +0100 Subject: [PATCH 2/2] review comments --- crates/contracts/artifacts/Solver.json | 2 +- crates/contracts/artifacts/Spardose.json | 2 +- crates/contracts/solidity/Solver.sol | 10 +++++++--- crates/contracts/solidity/Spardose.sol | 16 +++++++--------- crates/shared/src/price_estimation/factory.rs | 7 +++---- crates/shared/src/price_estimation/mod.rs | 9 ++++++++- .../src/price_estimation/trade_verifier.rs | 9 +++++---- 7 files changed, 32 insertions(+), 23 deletions(-) diff --git a/crates/contracts/artifacts/Solver.json b/crates/contracts/artifacts/Solver.json index 82e749c93b..0b3ffa8e18 100644 --- a/crates/contracts/artifacts/Solver.json +++ b/crates/contracts/artifacts/Solver.json @@ -1 +1 @@ -{"abi":[{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"bool","name":"countGas","type":"bool"}],"name":"storeBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ISettlement","name":"settlementContract","type":"address"},{"internalType":"address payable","name":"trader","type":"address"},{"internalType":"address","name":"sellToken","type":"address"},{"internalType":"uint256","name":"sellAmount","type":"uint256"},{"internalType":"address","name":"nativeToken","type":"address"},{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"address payable","name":"receiver","type":"address"},{"internalType":"bytes","name":"settlementCall","type":"bytes"},{"components":[{"internalType":"bool","name":"enabled","type":"bool"},{"internalType":"address","name":"spardose","type":"address"}],"internalType":"struct Solver.Mock","name":"mock","type":"tuple"}],"name":"swap","outputs":[{"internalType":"uint256","name":"gasUsed","type":"uint256"},{"internalType":"uint256[]","name":"queriedBalances","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"}],"bytecode":"0x608060405234801561001057600080fd5b50610a68806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806317b86b161461003b5780633bbb2e1d14610065575b600080fd5b61004e6100493660046107b4565b61007a565b60405161005c92919061089f565b60405180910390f35b6100786100733660046108ed565b610332565b005b60006060333014610111576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603860248201527f6f6e6c792073696d756c6174696f6e206c6f67696320697320616c6c6f77656460448201527f20746f2063616c6c202773776170272066756e6374696f6e0000000000000000606482015260840160405180910390fd5b825115610247576040517f57d5a1d300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8e811660048301528c81166024830152604482018c90528a811660648301528d16906357d5a1d390608401600060405180830381600087803b15801561019857600080fd5b505af11580156101ac573d6000803e3d6000fd5b50505060208401516040517fc56cca8300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8f811660048301528e81166024830152604482018e9052909116915063c56cca8390606401600060405180830381600087803b15801561022e57600080fd5b505af1158015610242573d6000803e3d6000fd5b505050505b60008673ffffffffffffffffffffffffffffffffffffffff16600060405160006040518083038185875af1925050503d80600081146102a2576040519150601f19603f3d011682016040523d82523d6000602084013e6102a7565b606091505b50509050506102b788888f610467565b6102c28d868661053f565b91506102cf88888f610467565b600180548060200260200160405190810160405280929190818152602001828054801561031b57602002820191906000526020600020905b815481526020019060010190808311610307575b505050505090509b509b9950505050505050505050565b60005a9050600173eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee73ffffffffffffffffffffffffffffffffffffffff8616146103ff576040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff85811660048301528616906370a0823190602401602060405180830381865afa1580156103d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103fa9190610934565b610418565b8373ffffffffffffffffffffffffffffffffffffffff16315b815460018101835560009283526020909220909101558115610461575a61043f908261097c565b61044b9061116c610995565b60008082825461045b9190610995565b90915550505b50505050565b60005b828110156104615730633bbb2e1d85858481811061048a5761048a6109a8565b905060200201602081019061049f91906109d7565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815273ffffffffffffffffffffffffffffffffffffffff9182166004820152908516602482015260006044820152606401600060405180830381600087803b15801561051457600080fd5b505af1158015610528573d6000803e3d6000fd5b505050508080610537906109f4565b91505061046a565b6000805a905061059c84848080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505073ffffffffffffffffffffffffffffffffffffffff8916929150506105be565b506000545a6105ab908361097c565b6105b5919061097c565b95945050505050565b60606105cc836000846105d3565b9392505050565b606060008473ffffffffffffffffffffffffffffffffffffffff1684846040516105fd9190610a2c565b60006040518083038185875af1925050503d806000811461063a576040519150601f19603f3d011682016040523d82523d6000602084013e61063f565b606091505b50925090508061065157815160208301fd5b509392505050565b73ffffffffffffffffffffffffffffffffffffffff8116811461067b57600080fd5b50565b803561068981610659565b919050565b60008083601f8401126106a057600080fd5b50813567ffffffffffffffff8111156106b857600080fd5b6020830191508360208260051b85010111156106d357600080fd5b9250929050565b60008083601f8401126106ec57600080fd5b50813567ffffffffffffffff81111561070457600080fd5b6020830191508360208285010111156106d357600080fd5b8035801515811461068957600080fd5b60006040828403121561073e57600080fd5b6040516040810181811067ffffffffffffffff82111715610788577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040529050806107978361071c565b815260208301356107a781610659565b6020919091015292915050565b60008060008060008060008060008060006101408c8e0312156107d657600080fd5b6107e08c35610659565b8b359a506107f160208d0135610659565b60208c0135995061080460408d0161067e565b985060608c0135975061081960808d0161067e565b965067ffffffffffffffff8060a08e0135111561083557600080fd5b6108458e60a08f01358f0161068e565b909750955061085660c08e0161067e565b94508060e08e0135111561086957600080fd5b5061087a8d60e08e01358e016106da565b909350915061088d8d6101008e0161072c565b90509295989b509295989b9093969950565b6000604082018483526020604081850152818551808452606086019150828701935060005b818110156108e0578451835293830193918301916001016108c4565b5090979650505050505050565b60008060006060848603121561090257600080fd5b833561090d81610659565b9250602084013561091d81610659565b915061092b6040850161071c565b90509250925092565b60006020828403121561094657600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b8181038181111561098f5761098f61094d565b92915050565b8082018082111561098f5761098f61094d565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000602082840312156109e957600080fd5b81356105cc81610659565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610a2557610a2561094d565b5060010190565b6000825160005b81811015610a4d5760208186018101518583015201610a33565b50600092019182525091905056fea164736f6c6343000811000a","deployedBytecode":"0x608060405234801561001057600080fd5b50600436106100365760003560e01c806317b86b161461003b5780633bbb2e1d14610065575b600080fd5b61004e6100493660046107b4565b61007a565b60405161005c92919061089f565b60405180910390f35b6100786100733660046108ed565b610332565b005b60006060333014610111576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603860248201527f6f6e6c792073696d756c6174696f6e206c6f67696320697320616c6c6f77656460448201527f20746f2063616c6c202773776170272066756e6374696f6e0000000000000000606482015260840160405180910390fd5b825115610247576040517f57d5a1d300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8e811660048301528c81166024830152604482018c90528a811660648301528d16906357d5a1d390608401600060405180830381600087803b15801561019857600080fd5b505af11580156101ac573d6000803e3d6000fd5b50505060208401516040517fc56cca8300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8f811660048301528e81166024830152604482018e9052909116915063c56cca8390606401600060405180830381600087803b15801561022e57600080fd5b505af1158015610242573d6000803e3d6000fd5b505050505b60008673ffffffffffffffffffffffffffffffffffffffff16600060405160006040518083038185875af1925050503d80600081146102a2576040519150601f19603f3d011682016040523d82523d6000602084013e6102a7565b606091505b50509050506102b788888f610467565b6102c28d868661053f565b91506102cf88888f610467565b600180548060200260200160405190810160405280929190818152602001828054801561031b57602002820191906000526020600020905b815481526020019060010190808311610307575b505050505090509b509b9950505050505050505050565b60005a9050600173eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee73ffffffffffffffffffffffffffffffffffffffff8616146103ff576040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff85811660048301528616906370a0823190602401602060405180830381865afa1580156103d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103fa9190610934565b610418565b8373ffffffffffffffffffffffffffffffffffffffff16315b815460018101835560009283526020909220909101558115610461575a61043f908261097c565b61044b9061116c610995565b60008082825461045b9190610995565b90915550505b50505050565b60005b828110156104615730633bbb2e1d85858481811061048a5761048a6109a8565b905060200201602081019061049f91906109d7565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815273ffffffffffffffffffffffffffffffffffffffff9182166004820152908516602482015260006044820152606401600060405180830381600087803b15801561051457600080fd5b505af1158015610528573d6000803e3d6000fd5b505050508080610537906109f4565b91505061046a565b6000805a905061059c84848080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505073ffffffffffffffffffffffffffffffffffffffff8916929150506105be565b506000545a6105ab908361097c565b6105b5919061097c565b95945050505050565b60606105cc836000846105d3565b9392505050565b606060008473ffffffffffffffffffffffffffffffffffffffff1684846040516105fd9190610a2c565b60006040518083038185875af1925050503d806000811461063a576040519150601f19603f3d011682016040523d82523d6000602084013e61063f565b606091505b50925090508061065157815160208301fd5b509392505050565b73ffffffffffffffffffffffffffffffffffffffff8116811461067b57600080fd5b50565b803561068981610659565b919050565b60008083601f8401126106a057600080fd5b50813567ffffffffffffffff8111156106b857600080fd5b6020830191508360208260051b85010111156106d357600080fd5b9250929050565b60008083601f8401126106ec57600080fd5b50813567ffffffffffffffff81111561070457600080fd5b6020830191508360208285010111156106d357600080fd5b8035801515811461068957600080fd5b60006040828403121561073e57600080fd5b6040516040810181811067ffffffffffffffff82111715610788577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040529050806107978361071c565b815260208301356107a781610659565b6020919091015292915050565b60008060008060008060008060008060006101408c8e0312156107d657600080fd5b6107e08c35610659565b8b359a506107f160208d0135610659565b60208c0135995061080460408d0161067e565b985060608c0135975061081960808d0161067e565b965067ffffffffffffffff8060a08e0135111561083557600080fd5b6108458e60a08f01358f0161068e565b909750955061085660c08e0161067e565b94508060e08e0135111561086957600080fd5b5061087a8d60e08e01358e016106da565b909350915061088d8d6101008e0161072c565b90509295989b509295989b9093969950565b6000604082018483526020604081850152818551808452606086019150828701935060005b818110156108e0578451835293830193918301916001016108c4565b5090979650505050505050565b60008060006060848603121561090257600080fd5b833561090d81610659565b9250602084013561091d81610659565b915061092b6040850161071c565b90509250925092565b60006020828403121561094657600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b8181038181111561098f5761098f61094d565b92915050565b8082018082111561098f5761098f61094d565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000602082840312156109e957600080fd5b81356105cc81610659565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610a2557610a2561094d565b5060010190565b6000825160005b81811015610a4d5760208186018101518583015201610a33565b50600092019182525091905056fea164736f6c6343000811000a","devdoc":{"methods":{}},"userdoc":{"methods":{}}} +{"abi":[{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"bool","name":"countGas","type":"bool"}],"name":"storeBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ISettlement","name":"settlementContract","type":"address"},{"internalType":"address payable","name":"trader","type":"address"},{"internalType":"address","name":"sellToken","type":"address"},{"internalType":"uint256","name":"sellAmount","type":"uint256"},{"internalType":"address","name":"nativeToken","type":"address"},{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"address payable","name":"receiver","type":"address"},{"internalType":"bytes","name":"settlementCall","type":"bytes"},{"components":[{"internalType":"bool","name":"enabled","type":"bool"},{"internalType":"address","name":"spardose","type":"address"}],"internalType":"struct Solver.Mock","name":"mock","type":"tuple"}],"name":"swap","outputs":[{"internalType":"uint256","name":"gasUsed","type":"uint256"},{"internalType":"uint256[]","name":"queriedBalances","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"}],"bytecode":"0x608060405234801561001057600080fd5b50610b26806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806317b86b161461003b5780633bbb2e1d14610065575b600080fd5b61004e610049366004610851565b61007a565b60405161005c92919061093c565b60405180910390f35b61007861007336600461098a565b6103cf565b005b60006060333014610112576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603860248201527f6f6e6c792073696d756c6174696f6e206c6f67696320697320616c6c6f77656460448201527f20746f2063616c6c202773776170272066756e6374696f6e000000000000000060648201526084015b60405180910390fd5b8251156102e4576040517f57d5a1d300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8e811660048301528c81166024830152604482018c90528a811660648301528d16906357d5a1d390608401600060405180830381600087803b15801561019957600080fd5b505af11580156101ad573d6000803e3d6000fd5b50505060208401516040517fc56cca8300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8f811660048301528e81166024830152604482018e9052909116915063c56cca83906064016020604051808303816000875af1158015610234573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061025891906109d5565b6102e4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f74726164657220646f6573206e6f74206861766520656e6f7567682073656c6c60448201527f20746f6b656e00000000000000000000000000000000000000000000000000006064820152608401610109565b60008673ffffffffffffffffffffffffffffffffffffffff16600060405160006040518083038185875af1925050503d806000811461033f576040519150601f19603f3d011682016040523d82523d6000602084013e610344565b606091505b505090505061035488888f610504565b61035f8d86866105dc565b915061036c88888f610504565b60018054806020026020016040519081016040528092919081815260200182805480156103b857602002820191906000526020600020905b8154815260200190600101908083116103a4575b505050505090509b509b9950505050505050505050565b60005a9050600173eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee73ffffffffffffffffffffffffffffffffffffffff86161461049c576040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff85811660048301528616906370a0823190602401602060405180830381865afa158015610473573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061049791906109f2565b6104b5565b8373ffffffffffffffffffffffffffffffffffffffff16315b8154600181018355600092835260209092209091015581156104fe575a6104dc9082610a3a565b6104e89061116c610a53565b6000808282546104f89190610a53565b90915550505b50505050565b60005b828110156104fe5730633bbb2e1d85858481811061052757610527610a66565b905060200201602081019061053c9190610a95565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815273ffffffffffffffffffffffffffffffffffffffff9182166004820152908516602482015260006044820152606401600060405180830381600087803b1580156105b157600080fd5b505af11580156105c5573d6000803e3d6000fd5b5050505080806105d490610ab2565b915050610507565b6000805a905061063984848080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505073ffffffffffffffffffffffffffffffffffffffff89169291505061065b565b506000545a6106489083610a3a565b6106529190610a3a565b95945050505050565b606061066983600084610670565b9392505050565b606060008473ffffffffffffffffffffffffffffffffffffffff16848460405161069a9190610aea565b60006040518083038185875af1925050503d80600081146106d7576040519150601f19603f3d011682016040523d82523d6000602084013e6106dc565b606091505b5092509050806106ee57815160208301fd5b509392505050565b73ffffffffffffffffffffffffffffffffffffffff8116811461071857600080fd5b50565b8035610726816106f6565b919050565b60008083601f84011261073d57600080fd5b50813567ffffffffffffffff81111561075557600080fd5b6020830191508360208260051b850101111561077057600080fd5b9250929050565b60008083601f84011261078957600080fd5b50813567ffffffffffffffff8111156107a157600080fd5b60208301915083602082850101111561077057600080fd5b801515811461071857600080fd5b6000604082840312156107d957600080fd5b6040516040810181811067ffffffffffffffff82111715610823577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040529050808235610834816107b9565b81526020830135610844816106f6565b6020919091015292915050565b60008060008060008060008060008060006101408c8e03121561087357600080fd5b61087d8c356106f6565b8b359a5061088e60208d01356106f6565b60208c013599506108a160408d0161071b565b985060608c013597506108b660808d0161071b565b965067ffffffffffffffff8060a08e013511156108d257600080fd5b6108e28e60a08f01358f0161072b565b90975095506108f360c08e0161071b565b94508060e08e0135111561090657600080fd5b506109178d60e08e01358e01610777565b909350915061092a8d6101008e016107c7565b90509295989b509295989b9093969950565b6000604082018483526020604081850152818551808452606086019150828701935060005b8181101561097d57845183529383019391830191600101610961565b5090979650505050505050565b60008060006060848603121561099f57600080fd5b83356109aa816106f6565b925060208401356109ba816106f6565b915060408401356109ca816107b9565b809150509250925092565b6000602082840312156109e757600080fd5b8151610669816107b9565b600060208284031215610a0457600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b81810381811115610a4d57610a4d610a0b565b92915050565b80820180821115610a4d57610a4d610a0b565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600060208284031215610aa757600080fd5b8135610669816106f6565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610ae357610ae3610a0b565b5060010190565b6000825160005b81811015610b0b5760208186018101518583015201610af1565b50600092019182525091905056fea164736f6c6343000811000a","deployedBytecode":"0x608060405234801561001057600080fd5b50600436106100365760003560e01c806317b86b161461003b5780633bbb2e1d14610065575b600080fd5b61004e610049366004610851565b61007a565b60405161005c92919061093c565b60405180910390f35b61007861007336600461098a565b6103cf565b005b60006060333014610112576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603860248201527f6f6e6c792073696d756c6174696f6e206c6f67696320697320616c6c6f77656460448201527f20746f2063616c6c202773776170272066756e6374696f6e000000000000000060648201526084015b60405180910390fd5b8251156102e4576040517f57d5a1d300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8e811660048301528c81166024830152604482018c90528a811660648301528d16906357d5a1d390608401600060405180830381600087803b15801561019957600080fd5b505af11580156101ad573d6000803e3d6000fd5b50505060208401516040517fc56cca8300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8f811660048301528e81166024830152604482018e9052909116915063c56cca83906064016020604051808303816000875af1158015610234573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061025891906109d5565b6102e4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f74726164657220646f6573206e6f74206861766520656e6f7567682073656c6c60448201527f20746f6b656e00000000000000000000000000000000000000000000000000006064820152608401610109565b60008673ffffffffffffffffffffffffffffffffffffffff16600060405160006040518083038185875af1925050503d806000811461033f576040519150601f19603f3d011682016040523d82523d6000602084013e610344565b606091505b505090505061035488888f610504565b61035f8d86866105dc565b915061036c88888f610504565b60018054806020026020016040519081016040528092919081815260200182805480156103b857602002820191906000526020600020905b8154815260200190600101908083116103a4575b505050505090509b509b9950505050505050505050565b60005a9050600173eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee73ffffffffffffffffffffffffffffffffffffffff86161461049c576040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff85811660048301528616906370a0823190602401602060405180830381865afa158015610473573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061049791906109f2565b6104b5565b8373ffffffffffffffffffffffffffffffffffffffff16315b8154600181018355600092835260209092209091015581156104fe575a6104dc9082610a3a565b6104e89061116c610a53565b6000808282546104f89190610a53565b90915550505b50505050565b60005b828110156104fe5730633bbb2e1d85858481811061052757610527610a66565b905060200201602081019061053c9190610a95565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815273ffffffffffffffffffffffffffffffffffffffff9182166004820152908516602482015260006044820152606401600060405180830381600087803b1580156105b157600080fd5b505af11580156105c5573d6000803e3d6000fd5b5050505080806105d490610ab2565b915050610507565b6000805a905061063984848080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505073ffffffffffffffffffffffffffffffffffffffff89169291505061065b565b506000545a6106489083610a3a565b6106529190610a3a565b95945050505050565b606061066983600084610670565b9392505050565b606060008473ffffffffffffffffffffffffffffffffffffffff16848460405161069a9190610aea565b60006040518083038185875af1925050503d80600081146106d7576040519150601f19603f3d011682016040523d82523d6000602084013e6106dc565b606091505b5092509050806106ee57815160208301fd5b509392505050565b73ffffffffffffffffffffffffffffffffffffffff8116811461071857600080fd5b50565b8035610726816106f6565b919050565b60008083601f84011261073d57600080fd5b50813567ffffffffffffffff81111561075557600080fd5b6020830191508360208260051b850101111561077057600080fd5b9250929050565b60008083601f84011261078957600080fd5b50813567ffffffffffffffff8111156107a157600080fd5b60208301915083602082850101111561077057600080fd5b801515811461071857600080fd5b6000604082840312156107d957600080fd5b6040516040810181811067ffffffffffffffff82111715610823577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040529050808235610834816107b9565b81526020830135610844816106f6565b6020919091015292915050565b60008060008060008060008060008060006101408c8e03121561087357600080fd5b61087d8c356106f6565b8b359a5061088e60208d01356106f6565b60208c013599506108a160408d0161071b565b985060608c013597506108b660808d0161071b565b965067ffffffffffffffff8060a08e013511156108d257600080fd5b6108e28e60a08f01358f0161072b565b90975095506108f360c08e0161071b565b94508060e08e0135111561090657600080fd5b506109178d60e08e01358e01610777565b909350915061092a8d6101008e016107c7565b90509295989b509295989b9093969950565b6000604082018483526020604081850152818551808452606086019150828701935060005b8181101561097d57845183529383019391830191600101610961565b5090979650505050505050565b60008060006060848603121561099f57600080fd5b83356109aa816106f6565b925060208401356109ba816106f6565b915060408401356109ca816107b9565b809150509250925092565b6000602082840312156109e757600080fd5b8151610669816107b9565b600060208284031215610a0457600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b81810381811115610a4d57610a4d610a0b565b92915050565b80820180821115610a4d57610a4d610a0b565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600060208284031215610aa757600080fd5b8135610669816106f6565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610ae357610ae3610a0b565b5060010190565b6000825160005b81811015610b0b5760208186018101518583015201610af1565b50600092019182525091905056fea164736f6c6343000811000a","devdoc":{"methods":{}},"userdoc":{"methods":{}}} diff --git a/crates/contracts/artifacts/Spardose.json b/crates/contracts/artifacts/Spardose.json index ce19b8db54..08787fb5a7 100644 --- a/crates/contracts/artifacts/Spardose.json +++ b/crates/contracts/artifacts/Spardose.json @@ -1 +1 @@ -{"abi":[{"inputs":[{"internalType":"address","name":"trader","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ensureBalance","outputs":[],"stateMutability":"nonpayable","type":"function"}],"bytecode":"0x608060405234801561001057600080fd5b506103ee806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063c56cca8314610030575b600080fd5b61004361003e3660046102fa565b610045565b005b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8481166004830152600091908416906370a0823190602401602060405180830381865afa1580156100b5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100d99190610336565b90508181106100e85750505050565b60006100f4828461034f565b905061011773ffffffffffffffffffffffffffffffffffffffff851686836101ae565b6101a7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f74726164657220646f6573206e6f74206861766520656e6f7567682073656c6c60448201527f5f746f6b656e0000000000000000000000000000000000000000000000000000606482015260840160405180910390fd5b5050505050565b6040805173ffffffffffffffffffffffffffffffffffffffff8481166024830152604480830185905283518084039091018152606490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052915160009260609190871690610247908490610389565b6000604051808303816000865af19150503d8060008114610284576040519150601f19603f3d011682016040523d82523d6000602084013e610289565b606091505b5090935090508280156102a057506102a0816102aa565b9695505050505050565b60008151600014806102cb5750818060200190518101906102cb91906103b8565b92915050565b803573ffffffffffffffffffffffffffffffffffffffff811681146102f557600080fd5b919050565b60008060006060848603121561030f57600080fd5b610318846102d1565b9250610326602085016102d1565b9150604084013590509250925092565b60006020828403121561034857600080fd5b5051919050565b818103818111156102cb577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000825160005b818110156103aa5760208186018101518583015201610390565b506000920191825250919050565b6000602082840312156103ca57600080fd5b815180151581146103da57600080fd5b939250505056fea164736f6c6343000811000a","deployedBytecode":"0x608060405234801561001057600080fd5b506004361061002b5760003560e01c8063c56cca8314610030575b600080fd5b61004361003e3660046102fa565b610045565b005b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8481166004830152600091908416906370a0823190602401602060405180830381865afa1580156100b5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100d99190610336565b90508181106100e85750505050565b60006100f4828461034f565b905061011773ffffffffffffffffffffffffffffffffffffffff851686836101ae565b6101a7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f74726164657220646f6573206e6f74206861766520656e6f7567682073656c6c60448201527f5f746f6b656e0000000000000000000000000000000000000000000000000000606482015260840160405180910390fd5b5050505050565b6040805173ffffffffffffffffffffffffffffffffffffffff8481166024830152604480830185905283518084039091018152606490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052915160009260609190871690610247908490610389565b6000604051808303816000865af19150503d8060008114610284576040519150601f19603f3d011682016040523d82523d6000602084013e610289565b606091505b5090935090508280156102a057506102a0816102aa565b9695505050505050565b60008151600014806102cb5750818060200190518101906102cb91906103b8565b92915050565b803573ffffffffffffffffffffffffffffffffffffffff811681146102f557600080fd5b919050565b60008060006060848603121561030f57600080fd5b610318846102d1565b9250610326602085016102d1565b9150604084013590509250925092565b60006020828403121561034857600080fd5b5051919050565b818103818111156102cb577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000825160005b818110156103aa5760208186018101518583015201610390565b506000920191825250919050565b6000602082840312156103ca57600080fd5b815180151581146103da57600080fd5b939250505056fea164736f6c6343000811000a","devdoc":{"methods":{}},"userdoc":{"methods":{}}} +{"abi":[{"inputs":[{"internalType":"address","name":"trader","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ensureBalance","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"}],"bytecode":"0x608060405234801561001057600080fd5b50610364806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063c56cca8314610030575b600080fd5b61004361003e366004610277565b610057565b604051901515815260200160405180910390f35b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff848116600483015260009182918516906370a0823190602401602060405180830381865afa1580156100c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100ec91906102b3565b90508281106100ff576001915050610133565b600061010b82856102cc565b905061012e73ffffffffffffffffffffffffffffffffffffffff8616878361013a565b925050505b9392505050565b6040805173ffffffffffffffffffffffffffffffffffffffff8481166024830152604480830185905283518084039091018152606490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001790529151600092606091908716906101d3908490610306565b6000604051808303816000865af19150503d8060008114610210576040519150601f19603f3d011682016040523d82523d6000602084013e610215565b606091505b50909350905082801561012e575061012e8160008151600014806102485750818060200190518101906102489190610335565b92915050565b803573ffffffffffffffffffffffffffffffffffffffff8116811461027257600080fd5b919050565b60008060006060848603121561028c57600080fd5b6102958461024e565b92506102a36020850161024e565b9150604084013590509250925092565b6000602082840312156102c557600080fd5b5051919050565b81810381811115610248577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000825160005b81811015610327576020818601810151858301520161030d565b506000920191825250919050565b60006020828403121561034757600080fd5b8151801515811461013357600080fdfea164736f6c6343000811000a","deployedBytecode":"0x608060405234801561001057600080fd5b506004361061002b5760003560e01c8063c56cca8314610030575b600080fd5b61004361003e366004610277565b610057565b604051901515815260200160405180910390f35b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff848116600483015260009182918516906370a0823190602401602060405180830381865afa1580156100c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100ec91906102b3565b90508281106100ff576001915050610133565b600061010b82856102cc565b905061012e73ffffffffffffffffffffffffffffffffffffffff8616878361013a565b925050505b9392505050565b6040805173ffffffffffffffffffffffffffffffffffffffff8481166024830152604480830185905283518084039091018152606490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001790529151600092606091908716906101d3908490610306565b6000604051808303816000865af19150503d8060008114610210576040519150601f19603f3d011682016040523d82523d6000602084013e610215565b606091505b50909350905082801561012e575061012e8160008151600014806102485750818060200190518101906102489190610335565b92915050565b803573ffffffffffffffffffffffffffffffffffffffff8116811461027257600080fd5b919050565b60008060006060848603121561028c57600080fd5b6102958461024e565b92506102a36020850161024e565b9150604084013590509250925092565b6000602082840312156102c557600080fd5b5051919050565b81810381811115610248577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000825160005b81811015610327576020818601810151858301520161030d565b506000920191825250919050565b60006020828403121561034757600080fd5b8151801515811461013357600080fdfea164736f6c6343000811000a","devdoc":{"methods":{}},"userdoc":{"methods":{}}} diff --git a/crates/contracts/solidity/Solver.sol b/crates/contracts/solidity/Solver.sol index a7a27a9fff..eece404458 100644 --- a/crates/contracts/solidity/Solver.sol +++ b/crates/contracts/solidity/Solver.sol @@ -74,9 +74,13 @@ contract Solver { nativeToken ); - // Ensure that the user has sufficient sell token balance for the - // swap using balance overrides. - Spardose(mock.spardose).ensureBalance(trader, sellToken, sellAmount); + // Ensure that the user has sufficient sell token balance. In case + // balance overrides are enabled, the Spardose will fund the trader + // with simulated balances. + require( + Spardose(mock.spardose).ensureBalance(trader, sellToken, sellAmount), + "trader does not have enough sell token" + ); } // Warm the storage for sending ETH to smart contract addresses. diff --git a/crates/contracts/solidity/Spardose.sol b/crates/contracts/solidity/Spardose.sol index 502261ac02..c1fa6167be 100644 --- a/crates/contracts/solidity/Spardose.sol +++ b/crates/contracts/solidity/Spardose.sol @@ -13,22 +13,20 @@ contract Spardose { using SafeERC20 for *; /// @dev Ensures that the trader has at least `amount` tokens. If not, it - /// will transfer the difference to the trader. + /// will try and transfer the difference to the trader. /// /// @param trader - the address of the trader /// @param token - the token to ensure a balance for - /// @param amount - the amount of `token` that the `trader` must hold. - function ensureBalance(address trader, address token, uint256 amount) external { + /// @param amount - the amount of `token` that the `trader` must hold + /// + /// @return success - the `trader`'s `token` balance is more than `amount` + function ensureBalance(address trader, address token, uint256 amount) external returns (bool success) { uint256 traderBalance = IERC20(token).balanceOf(trader); if (traderBalance >= amount) { - // Nothing to do. - return; + return true; } uint256 difference = amount - traderBalance; - require( - IERC20(token).trySafeTransfer(trader, difference), - "trader does not have enough sell_token" - ); + return IERC20(token).trySafeTransfer(trader, difference); } } diff --git a/crates/shared/src/price_estimation/factory.rs b/crates/shared/src/price_estimation/factory.rs index cd5e38e2b2..2d660adf03 100644 --- a/crates/shared/src/price_estimation/factory.rs +++ b/crates/shared/src/price_estimation/factory.rs @@ -124,11 +124,10 @@ impl<'a> PriceEstimatorFactory<'a> { network.native_token, args.quote_inaccuracy_limit.clone(), ) - .await?; + .await? + .with_balance_overrides(balance_overrides); - Ok(Some(Arc::new( - verifier.with_balance_overrides(balance_overrides), - ))) + Ok(Some(Arc::new(verifier))) } fn native_token_price_estimation_amount(&self) -> Result { diff --git a/crates/shared/src/price_estimation/mod.rs b/crates/shared/src/price_estimation/mod.rs index 50d1b32d7f..607925bc83 100644 --- a/crates/shared/src/price_estimation/mod.rs +++ b/crates/shared/src/price_estimation/mod.rs @@ -213,7 +213,14 @@ pub struct Arguments { )] pub quote_timeout: Duration, - /// Token configuration for simulated balances on verified quotes. + /// Token configuration for simulated balances on verified quotes. This + /// allows the quote verification system to produce verified quotes for + /// traders without sufficient balance for the configured token pairs. + /// + /// The expected format is a comma separated list of `${ADDR}@${SLOT}`, + /// where `ADDR` is the token address and `SLOT` is the Solidity storage + /// slot for the balances mapping. For example for WETH: + /// `0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2@3`. #[clap(long, env, default_value_t)] pub quote_token_balance_overrides: ConfigurationBalanceOverrides, } diff --git a/crates/shared/src/price_estimation/trade_verifier.rs b/crates/shared/src/price_estimation/trade_verifier.rs index e13e4ca70e..fed26bb928 100644 --- a/crates/shared/src/price_estimation/trade_verifier.rs +++ b/crates/shared/src/price_estimation/trade_verifier.rs @@ -335,12 +335,13 @@ impl TradeVerifier { }, ); - // Provide mocked balances if possible to the solver to allow it to + // Provide mocked balances if possible to the spardose to allow it to // give some balances to the trader in order to verify trades even for - // owners without balances. Note that we explicitly override the - // **solver's** balance and not the trader's directly. This allows the + // owners without balances. Note that we use a separate account for + // funding to not interfere with the settlement process. This allows the // simulation to conditionally transfer the balance only when it is - // safe to mock the trade pre-conditions on behalf of the user. We use + // safe to mock the trade pre-conditions on behalf of the user and to + // not alter solver balances which may be used during settlement. We use // a similar strategy for determining whether or not to set approvals on // behalf of the trader. if let Some(solver_balance_override) =