From d335f2de0b28c01382833927d4cab8319c9b2f9d Mon Sep 17 00:00:00 2001 From: skosito Date: Tue, 10 Sep 2024 11:21:39 +0100 Subject: [PATCH] fix: calling precompile through sc with sc state update (#2853) * fix calling precompile through sc with sc state update * changelog * extend comment a bit --- changelog.md | 1 + e2e/contracts/teststaking/TestStaking.abi | 71 +++++++++++++++++ e2e/contracts/teststaking/TestStaking.bin | 2 +- e2e/contracts/teststaking/TestStaking.go | 77 ++++++++++++++++++- e2e/contracts/teststaking/TestStaking.json | 73 +++++++++++++++++- e2e/contracts/teststaking/TestStaking.sol | 17 ++++ ...st_precompiles_staking_through_contract.go | 71 ++++++++++++++++- precompiles/staking/staking.go | 11 ++- precompiles/staking/staking_test.go | 38 ++++----- 9 files changed, 334 insertions(+), 27 deletions(-) diff --git a/changelog.md b/changelog.md index a7dcab0bc3..7673903099 100644 --- a/changelog.md +++ b/changelog.md @@ -40,6 +40,7 @@ * [2672](https://github.com/zeta-chain/node/pull/2672) - check observer set for duplicates when adding a new observer or updating an existing one * [2787](https://github.com/zeta-chain/node/pull/2787) - ask for 3 accounts (signer, pda, system_program) on solana gateway deposit * [2842](https://github.com/zeta-chain/node/pull/2842) - fix: move interval assignment out of cctx loop in EVM outbound tx scheduler +* [2853](https://github.com/zeta-chain/node/pull/2853) - calling precompile through sc with sc state update ## v19.0.0 diff --git a/e2e/contracts/teststaking/TestStaking.abi b/e2e/contracts/teststaking/TestStaking.abi index 1dc4f1592e..69003af87f 100644 --- a/e2e/contracts/teststaking/TestStaking.abi +++ b/e2e/contracts/teststaking/TestStaking.abi @@ -14,6 +14,19 @@ "stateMutability": "payable", "type": "fallback" }, + { + "inputs": [], + "name": "counter", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "depositWZETA", @@ -143,6 +156,64 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "staker", + "type": "address" + }, + { + "internalType": "string", + "name": "validator", + "type": "string" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "stakeAndRevert", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "staker", + "type": "address" + }, + { + "internalType": "string", + "name": "validator", + "type": "string" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "stakeWithStateUpdate", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { diff --git a/e2e/contracts/teststaking/TestStaking.bin b/e2e/contracts/teststaking/TestStaking.bin index f2b883adb0..35c4198862 100644 --- a/e2e/contracts/teststaking/TestStaking.bin +++ b/e2e/contracts/teststaking/TestStaking.bin @@ -1 +1 @@ -608060405260666000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055503480156200005257600080fd5b50604051620014d3380380620014d383398181016040528101906200007891906200016b565b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555033600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550506200019d565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000620001338262000106565b9050919050565b620001458162000126565b81146200015157600080fd5b50565b60008151905062000165816200013a565b92915050565b60006020828403121562000184576200018362000101565b5b6000620001948482850162000154565b91505092915050565b61132680620001ad6000396000f3fe6080604052600436106100745760003560e01c806390b8436f1161004e57806390b8436f146101015780639a0fb6731461013e578063d11a93d014610167578063f3513a37146101a45761007b565b80630d1b3daf1461007d5780632c5d24ae146100ba57806357c6ea3e146100c45761007b565b3661007b57005b005b34801561008957600080fd5b506100a4600480360381019061009f91906109a4565b6101cf565b6040516100b19190610a19565b60405180910390f35b6100c2610276565b005b3480156100d057600080fd5b506100eb60048036038101906100e69190610a60565b610355565b6040516100f89190610aeb565b60405180910390f35b34801561010d57600080fd5b5061012860048036038101906101239190610a60565b61045a565b6040516101359190610b21565b60405180910390f35b34801561014a57600080fd5b5061016560048036038101906101609190610b3c565b61055f565b005b34801561017357600080fd5b5061018e60048036038101906101899190610b69565b610649565b60405161019b9190610aeb565b60405180910390f35b3480156101b057600080fd5b506101b9610751565b6040516101c69190610e42565b60405180910390f35b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16630d1b3daf84846040518363ffffffff1660e01b815260040161022d929190610ebd565b602060405180830381865afa15801561024a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061026e9190610f02565b905092915050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146102d057600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561033a57600080fd5b505af115801561034e573d6000803e3d6000fd5b5050505050565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146103b157600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166357c6ea3e8585856040518463ffffffff1660e01b815260040161040e93929190610f2f565b6020604051808303816000875af115801561042d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104519190610f99565b90509392505050565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146104b657600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166390b8436f8585856040518463ffffffff1660e01b815260040161051393929190610f2f565b6020604051808303816000875af1158015610532573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105569190610ff2565b90509392505050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146105b957600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16632e1a7d4d826040518263ffffffff1660e01b81526004016106149190610a19565b600060405180830381600087803b15801561062e57600080fd5b505af1158015610642573d6000803e3d6000fd5b5050505050565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146106a557600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d11a93d0868686866040518563ffffffff1660e01b8152600401610704949392919061101f565b6020604051808303816000875af1158015610723573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107479190610f99565b9050949350505050565b606060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f3513a376040518163ffffffff1660e01b8152600401600060405180830381865afa1580156107be573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f820116820180604052508101906107e791906112a7565b905090565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061082b82610800565b9050919050565b61083b81610820565b811461084657600080fd5b50565b60008135905061085881610832565b92915050565b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6108b182610868565b810181811067ffffffffffffffff821117156108d0576108cf610879565b5b80604052505050565b60006108e36107ec565b90506108ef82826108a8565b919050565b600067ffffffffffffffff82111561090f5761090e610879565b5b61091882610868565b9050602081019050919050565b82818337600083830152505050565b6000610947610942846108f4565b6108d9565b90508281526020810184848401111561096357610962610863565b5b61096e848285610925565b509392505050565b600082601f83011261098b5761098a61085e565b5b813561099b848260208601610934565b91505092915050565b600080604083850312156109bb576109ba6107f6565b5b60006109c985828601610849565b925050602083013567ffffffffffffffff8111156109ea576109e96107fb565b5b6109f685828601610976565b9150509250929050565b6000819050919050565b610a1381610a00565b82525050565b6000602082019050610a2e6000830184610a0a565b92915050565b610a3d81610a00565b8114610a4857600080fd5b50565b600081359050610a5a81610a34565b92915050565b600080600060608486031215610a7957610a786107f6565b5b6000610a8786828701610849565b935050602084013567ffffffffffffffff811115610aa857610aa76107fb565b5b610ab486828701610976565b9250506040610ac586828701610a4b565b9150509250925092565b60008160070b9050919050565b610ae581610acf565b82525050565b6000602082019050610b006000830184610adc565b92915050565b60008115159050919050565b610b1b81610b06565b82525050565b6000602082019050610b366000830184610b12565b92915050565b600060208284031215610b5257610b516107f6565b5b6000610b6084828501610a4b565b91505092915050565b60008060008060808587031215610b8357610b826107f6565b5b6000610b9187828801610849565b945050602085013567ffffffffffffffff811115610bb257610bb16107fb565b5b610bbe87828801610976565b935050604085013567ffffffffffffffff811115610bdf57610bde6107fb565b5b610beb87828801610976565b9250506060610bfc87828801610a4b565b91505092959194509250565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610c6e578082015181840152602081019050610c53565b83811115610c7d576000848401525b50505050565b6000610c8e82610c34565b610c988185610c3f565b9350610ca8818560208601610c50565b610cb181610868565b840191505092915050565b610cc581610b06565b82525050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b60048110610d0b57610d0a610ccb565b5b50565b6000819050610d1c82610cfa565b919050565b6000610d2c82610d0e565b9050919050565b610d3c81610d21565b82525050565b60006080830160008301518482036000860152610d5f8282610c83565b91505060208301518482036020860152610d798282610c83565b9150506040830151610d8e6040860182610cbc565b506060830151610da16060860182610d33565b508091505092915050565b6000610db88383610d42565b905092915050565b6000602082019050919050565b6000610dd882610c08565b610de28185610c13565b935083602082028501610df485610c24565b8060005b85811015610e305784840389528151610e118582610dac565b9450610e1c83610dc0565b925060208a01995050600181019050610df8565b50829750879550505050505092915050565b60006020820190508181036000830152610e5c8184610dcd565b905092915050565b610e6d81610820565b82525050565b600082825260208201905092915050565b6000610e8f82610c34565b610e998185610e73565b9350610ea9818560208601610c50565b610eb281610868565b840191505092915050565b6000604082019050610ed26000830185610e64565b8181036020830152610ee48184610e84565b90509392505050565b600081519050610efc81610a34565b92915050565b600060208284031215610f1857610f176107f6565b5b6000610f2684828501610eed565b91505092915050565b6000606082019050610f446000830186610e64565b8181036020830152610f568185610e84565b9050610f656040830184610a0a565b949350505050565b610f7681610acf565b8114610f8157600080fd5b50565b600081519050610f9381610f6d565b92915050565b600060208284031215610faf57610fae6107f6565b5b6000610fbd84828501610f84565b91505092915050565b610fcf81610b06565b8114610fda57600080fd5b50565b600081519050610fec81610fc6565b92915050565b600060208284031215611008576110076107f6565b5b600061101684828501610fdd565b91505092915050565b60006080820190506110346000830187610e64565b81810360208301526110468186610e84565b9050818103604083015261105a8185610e84565b90506110696060830184610a0a565b95945050505050565b600067ffffffffffffffff82111561108d5761108c610879565b5b602082029050602081019050919050565b600080fd5b600080fd5b600080fd5b60006110c06110bb846108f4565b6108d9565b9050828152602081018484840111156110dc576110db610863565b5b6110e7848285610c50565b509392505050565b600082601f8301126111045761110361085e565b5b81516111148482602086016110ad565b91505092915050565b6004811061112a57600080fd5b50565b60008151905061113c8161111d565b92915050565b600060808284031215611158576111576110a3565b5b61116260806108d9565b9050600082015167ffffffffffffffff811115611182576111816110a8565b5b61118e848285016110ef565b600083015250602082015167ffffffffffffffff8111156111b2576111b16110a8565b5b6111be848285016110ef565b60208301525060406111d284828501610fdd565b60408301525060606111e68482850161112d565b60608301525092915050565b600061120561120084611072565b6108d9565b905080838252602082019050602084028301858111156112285761122761109e565b5b835b8181101561126f57805167ffffffffffffffff81111561124d5761124c61085e565b5b80860161125a8982611142565b8552602085019450505060208101905061122a565b5050509392505050565b600082601f83011261128e5761128d61085e565b5b815161129e8482602086016111f2565b91505092915050565b6000602082840312156112bd576112bc6107f6565b5b600082015167ffffffffffffffff8111156112db576112da6107fb565b5b6112e784828501611279565b9150509291505056fea26469706673582212209d34227b9c73d9c6eb2b67ca8fabedb28adcac235655b12df2a572847549ea2a64736f6c634300080a0033 +608060405260666000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060006003553480156200005757600080fd5b506040516200192d3803806200192d83398181016040528101906200007d919062000170565b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555033600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050620001a2565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600062000138826200010b565b9050919050565b6200014a816200012b565b81146200015657600080fd5b50565b6000815190506200016a816200013f565b92915050565b60006020828403121562000189576200018862000106565b5b6000620001998482850162000159565b91505092915050565b61177b80620001b26000396000f3fe6080604052600436106100955760003560e01c806390b8436f1161005957806390b8436f1461018a5780639a0fb673146101c7578063bca8f527146101f0578063d11a93d01461022d578063f3513a371461026a5761009c565b80630d1b3daf1461009e5780632c5d24ae146100db57806357c6ea3e146100e557806361bc221a146101225780636be8916c1461014d5761009c565b3661009c57005b005b3480156100aa57600080fd5b506100c560048036038101906100c09190610d08565b610295565b6040516100d29190610d7d565b60405180910390f35b6100e361033c565b005b3480156100f157600080fd5b5061010c60048036038101906101079190610dc4565b61041b565b6040516101199190610e4f565b60405180910390f35b34801561012e57600080fd5b50610137610520565b6040516101449190610d7d565b60405180910390f35b34801561015957600080fd5b50610174600480360381019061016f9190610dc4565b610526565b6040516101819190610e85565b60405180910390f35b34801561019657600080fd5b506101b160048036038101906101ac9190610dc4565b61065c565b6040516101be9190610e85565b60405180910390f35b3480156101d357600080fd5b506101ee60048036038101906101e99190610ea0565b610761565b005b3480156101fc57600080fd5b5061021760048036038101906102129190610dc4565b61084b565b6040516102249190610e85565b60405180910390f35b34801561023957600080fd5b50610254600480360381019061024f9190610ecd565b6109ad565b6040516102619190610e4f565b60405180910390f35b34801561027657600080fd5b5061027f610ab5565b60405161028c91906111a6565b60405180910390f35b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16630d1b3daf84846040518363ffffffff1660e01b81526004016102f3929190611221565b602060405180830381865afa158015610310573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103349190611266565b905092915050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461039657600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561040057600080fd5b505af1158015610414573d6000803e3d6000fd5b5050505050565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461047757600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166357c6ea3e8585856040518463ffffffff1660e01b81526004016104d493929190611293565b6020604051808303816000875af11580156104f3573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061051791906112fd565b90509392505050565b60035481565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461058257600080fd5b60016003546105919190611359565b60038190555060008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166390b8436f8686866040518463ffffffff1660e01b81526004016105f793929190611293565b6020604051808303816000875af1158015610616573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061063a91906113db565b9050600160035461064b9190611359565b600381905550809150509392505050565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146106b857600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166390b8436f8585856040518463ffffffff1660e01b815260040161071593929190611293565b6020604051808303816000875af1158015610734573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061075891906113db565b90509392505050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146107bb57600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16632e1a7d4d826040518263ffffffff1660e01b81526004016108169190610d7d565b600060405180830381600087803b15801561083057600080fd5b505af1158015610844573d6000803e3d6000fd5b5050505050565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146108a757600080fd5b60016003546108b69190611359565b60038190555060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166390b8436f8585856040518463ffffffff1660e01b815260040161091993929190611293565b6020604051808303816000875af1158015610938573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061095c91906113db565b50600160035461096c9190611359565b6003819055506040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109a490611454565b60405180910390fd5b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610a0957600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d11a93d0868686866040518563ffffffff1660e01b8152600401610a689493929190611474565b6020604051808303816000875af1158015610a87573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aab91906112fd565b9050949350505050565b606060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f3513a376040518163ffffffff1660e01b8152600401600060405180830381865afa158015610b22573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f82011682018060405250810190610b4b91906116fc565b905090565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610b8f82610b64565b9050919050565b610b9f81610b84565b8114610baa57600080fd5b50565b600081359050610bbc81610b96565b92915050565b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610c1582610bcc565b810181811067ffffffffffffffff82111715610c3457610c33610bdd565b5b80604052505050565b6000610c47610b50565b9050610c538282610c0c565b919050565b600067ffffffffffffffff821115610c7357610c72610bdd565b5b610c7c82610bcc565b9050602081019050919050565b82818337600083830152505050565b6000610cab610ca684610c58565b610c3d565b905082815260208101848484011115610cc757610cc6610bc7565b5b610cd2848285610c89565b509392505050565b600082601f830112610cef57610cee610bc2565b5b8135610cff848260208601610c98565b91505092915050565b60008060408385031215610d1f57610d1e610b5a565b5b6000610d2d85828601610bad565b925050602083013567ffffffffffffffff811115610d4e57610d4d610b5f565b5b610d5a85828601610cda565b9150509250929050565b6000819050919050565b610d7781610d64565b82525050565b6000602082019050610d926000830184610d6e565b92915050565b610da181610d64565b8114610dac57600080fd5b50565b600081359050610dbe81610d98565b92915050565b600080600060608486031215610ddd57610ddc610b5a565b5b6000610deb86828701610bad565b935050602084013567ffffffffffffffff811115610e0c57610e0b610b5f565b5b610e1886828701610cda565b9250506040610e2986828701610daf565b9150509250925092565b60008160070b9050919050565b610e4981610e33565b82525050565b6000602082019050610e646000830184610e40565b92915050565b60008115159050919050565b610e7f81610e6a565b82525050565b6000602082019050610e9a6000830184610e76565b92915050565b600060208284031215610eb657610eb5610b5a565b5b6000610ec484828501610daf565b91505092915050565b60008060008060808587031215610ee757610ee6610b5a565b5b6000610ef587828801610bad565b945050602085013567ffffffffffffffff811115610f1657610f15610b5f565b5b610f2287828801610cda565b935050604085013567ffffffffffffffff811115610f4357610f42610b5f565b5b610f4f87828801610cda565b9250506060610f6087828801610daf565b91505092959194509250565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610fd2578082015181840152602081019050610fb7565b83811115610fe1576000848401525b50505050565b6000610ff282610f98565b610ffc8185610fa3565b935061100c818560208601610fb4565b61101581610bcc565b840191505092915050565b61102981610e6a565b82525050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b6004811061106f5761106e61102f565b5b50565b60008190506110808261105e565b919050565b600061109082611072565b9050919050565b6110a081611085565b82525050565b600060808301600083015184820360008601526110c38282610fe7565b915050602083015184820360208601526110dd8282610fe7565b91505060408301516110f26040860182611020565b5060608301516111056060860182611097565b508091505092915050565b600061111c83836110a6565b905092915050565b6000602082019050919050565b600061113c82610f6c565b6111468185610f77565b93508360208202850161115885610f88565b8060005b8581101561119457848403895281516111758582611110565b945061118083611124565b925060208a0199505060018101905061115c565b50829750879550505050505092915050565b600060208201905081810360008301526111c08184611131565b905092915050565b6111d181610b84565b82525050565b600082825260208201905092915050565b60006111f382610f98565b6111fd81856111d7565b935061120d818560208601610fb4565b61121681610bcc565b840191505092915050565b600060408201905061123660008301856111c8565b818103602083015261124881846111e8565b90509392505050565b60008151905061126081610d98565b92915050565b60006020828403121561127c5761127b610b5a565b5b600061128a84828501611251565b91505092915050565b60006060820190506112a860008301866111c8565b81810360208301526112ba81856111e8565b90506112c96040830184610d6e565b949350505050565b6112da81610e33565b81146112e557600080fd5b50565b6000815190506112f7816112d1565b92915050565b60006020828403121561131357611312610b5a565b5b6000611321848285016112e8565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061136482610d64565b915061136f83610d64565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156113a4576113a361132a565b5b828201905092915050565b6113b881610e6a565b81146113c357600080fd5b50565b6000815190506113d5816113af565b92915050565b6000602082840312156113f1576113f0610b5a565b5b60006113ff848285016113c6565b91505092915050565b7f7465737472657665727400000000000000000000000000000000000000000000600082015250565b600061143e600a836111d7565b915061144982611408565b602082019050919050565b6000602082019050818103600083015261146d81611431565b9050919050565b600060808201905061148960008301876111c8565b818103602083015261149b81866111e8565b905081810360408301526114af81856111e8565b90506114be6060830184610d6e565b95945050505050565b600067ffffffffffffffff8211156114e2576114e1610bdd565b5b602082029050602081019050919050565b600080fd5b600080fd5b600080fd5b600061151561151084610c58565b610c3d565b90508281526020810184848401111561153157611530610bc7565b5b61153c848285610fb4565b509392505050565b600082601f83011261155957611558610bc2565b5b8151611569848260208601611502565b91505092915050565b6004811061157f57600080fd5b50565b60008151905061159181611572565b92915050565b6000608082840312156115ad576115ac6114f8565b5b6115b76080610c3d565b9050600082015167ffffffffffffffff8111156115d7576115d66114fd565b5b6115e384828501611544565b600083015250602082015167ffffffffffffffff811115611607576116066114fd565b5b61161384828501611544565b6020830152506040611627848285016113c6565b604083015250606061163b84828501611582565b60608301525092915050565b600061165a611655846114c7565b610c3d565b9050808382526020820190506020840283018581111561167d5761167c6114f3565b5b835b818110156116c457805167ffffffffffffffff8111156116a2576116a1610bc2565b5b8086016116af8982611597565b8552602085019450505060208101905061167f565b5050509392505050565b600082601f8301126116e3576116e2610bc2565b5b81516116f3848260208601611647565b91505092915050565b60006020828403121561171257611711610b5a565b5b600082015167ffffffffffffffff8111156117305761172f610b5f565b5b61173c848285016116ce565b9150509291505056fea2646970667358221220fbbd8da0d7360633653761cbde3d46828949fcca1b71279d79140864c678daeb64736f6c634300080a0033 diff --git a/e2e/contracts/teststaking/TestStaking.go b/e2e/contracts/teststaking/TestStaking.go index b124d177dc..2251253862 100644 --- a/e2e/contracts/teststaking/TestStaking.go +++ b/e2e/contracts/teststaking/TestStaking.go @@ -39,8 +39,8 @@ type Validator struct { // TestStakingMetaData contains all meta data concerning the TestStaking contract. var TestStakingMetaData = &bind.MetaData{ - ABI: "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_wzeta\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"stateMutability\":\"payable\",\"type\":\"fallback\"},{\"inputs\":[],\"name\":\"depositWZETA\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getAllValidators\",\"outputs\":[{\"components\":[{\"internalType\":\"string\",\"name\":\"operatorAddress\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"consensusPubKey\",\"type\":\"string\"},{\"internalType\":\"bool\",\"name\":\"jailed\",\"type\":\"bool\"},{\"internalType\":\"enumBondStatus\",\"name\":\"bondStatus\",\"type\":\"uint8\"}],\"internalType\":\"structValidator[]\",\"name\":\"validators\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"staker\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"validator\",\"type\":\"string\"}],\"name\":\"getShares\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"shares\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"staker\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"validatorSrc\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"validatorDst\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"moveStake\",\"outputs\":[{\"internalType\":\"int64\",\"name\":\"completionTime\",\"type\":\"int64\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"staker\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"validator\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"stake\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"staker\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"validator\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"unstake\",\"outputs\":[{\"internalType\":\"int64\",\"name\":\"completionTime\",\"type\":\"int64\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"wad\",\"type\":\"uint256\"}],\"name\":\"withdrawWZETA\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"stateMutability\":\"payable\",\"type\":\"receive\"}]", - Bin: "0x608060405260666000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055503480156200005257600080fd5b50604051620014d3380380620014d383398181016040528101906200007891906200016b565b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555033600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550506200019d565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000620001338262000106565b9050919050565b620001458162000126565b81146200015157600080fd5b50565b60008151905062000165816200013a565b92915050565b60006020828403121562000184576200018362000101565b5b6000620001948482850162000154565b91505092915050565b61132680620001ad6000396000f3fe6080604052600436106100745760003560e01c806390b8436f1161004e57806390b8436f146101015780639a0fb6731461013e578063d11a93d014610167578063f3513a37146101a45761007b565b80630d1b3daf1461007d5780632c5d24ae146100ba57806357c6ea3e146100c45761007b565b3661007b57005b005b34801561008957600080fd5b506100a4600480360381019061009f91906109a4565b6101cf565b6040516100b19190610a19565b60405180910390f35b6100c2610276565b005b3480156100d057600080fd5b506100eb60048036038101906100e69190610a60565b610355565b6040516100f89190610aeb565b60405180910390f35b34801561010d57600080fd5b5061012860048036038101906101239190610a60565b61045a565b6040516101359190610b21565b60405180910390f35b34801561014a57600080fd5b5061016560048036038101906101609190610b3c565b61055f565b005b34801561017357600080fd5b5061018e60048036038101906101899190610b69565b610649565b60405161019b9190610aeb565b60405180910390f35b3480156101b057600080fd5b506101b9610751565b6040516101c69190610e42565b60405180910390f35b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16630d1b3daf84846040518363ffffffff1660e01b815260040161022d929190610ebd565b602060405180830381865afa15801561024a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061026e9190610f02565b905092915050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146102d057600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561033a57600080fd5b505af115801561034e573d6000803e3d6000fd5b5050505050565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146103b157600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166357c6ea3e8585856040518463ffffffff1660e01b815260040161040e93929190610f2f565b6020604051808303816000875af115801561042d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104519190610f99565b90509392505050565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146104b657600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166390b8436f8585856040518463ffffffff1660e01b815260040161051393929190610f2f565b6020604051808303816000875af1158015610532573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105569190610ff2565b90509392505050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146105b957600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16632e1a7d4d826040518263ffffffff1660e01b81526004016106149190610a19565b600060405180830381600087803b15801561062e57600080fd5b505af1158015610642573d6000803e3d6000fd5b5050505050565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146106a557600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d11a93d0868686866040518563ffffffff1660e01b8152600401610704949392919061101f565b6020604051808303816000875af1158015610723573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107479190610f99565b9050949350505050565b606060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f3513a376040518163ffffffff1660e01b8152600401600060405180830381865afa1580156107be573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f820116820180604052508101906107e791906112a7565b905090565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061082b82610800565b9050919050565b61083b81610820565b811461084657600080fd5b50565b60008135905061085881610832565b92915050565b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6108b182610868565b810181811067ffffffffffffffff821117156108d0576108cf610879565b5b80604052505050565b60006108e36107ec565b90506108ef82826108a8565b919050565b600067ffffffffffffffff82111561090f5761090e610879565b5b61091882610868565b9050602081019050919050565b82818337600083830152505050565b6000610947610942846108f4565b6108d9565b90508281526020810184848401111561096357610962610863565b5b61096e848285610925565b509392505050565b600082601f83011261098b5761098a61085e565b5b813561099b848260208601610934565b91505092915050565b600080604083850312156109bb576109ba6107f6565b5b60006109c985828601610849565b925050602083013567ffffffffffffffff8111156109ea576109e96107fb565b5b6109f685828601610976565b9150509250929050565b6000819050919050565b610a1381610a00565b82525050565b6000602082019050610a2e6000830184610a0a565b92915050565b610a3d81610a00565b8114610a4857600080fd5b50565b600081359050610a5a81610a34565b92915050565b600080600060608486031215610a7957610a786107f6565b5b6000610a8786828701610849565b935050602084013567ffffffffffffffff811115610aa857610aa76107fb565b5b610ab486828701610976565b9250506040610ac586828701610a4b565b9150509250925092565b60008160070b9050919050565b610ae581610acf565b82525050565b6000602082019050610b006000830184610adc565b92915050565b60008115159050919050565b610b1b81610b06565b82525050565b6000602082019050610b366000830184610b12565b92915050565b600060208284031215610b5257610b516107f6565b5b6000610b6084828501610a4b565b91505092915050565b60008060008060808587031215610b8357610b826107f6565b5b6000610b9187828801610849565b945050602085013567ffffffffffffffff811115610bb257610bb16107fb565b5b610bbe87828801610976565b935050604085013567ffffffffffffffff811115610bdf57610bde6107fb565b5b610beb87828801610976565b9250506060610bfc87828801610a4b565b91505092959194509250565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610c6e578082015181840152602081019050610c53565b83811115610c7d576000848401525b50505050565b6000610c8e82610c34565b610c988185610c3f565b9350610ca8818560208601610c50565b610cb181610868565b840191505092915050565b610cc581610b06565b82525050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b60048110610d0b57610d0a610ccb565b5b50565b6000819050610d1c82610cfa565b919050565b6000610d2c82610d0e565b9050919050565b610d3c81610d21565b82525050565b60006080830160008301518482036000860152610d5f8282610c83565b91505060208301518482036020860152610d798282610c83565b9150506040830151610d8e6040860182610cbc565b506060830151610da16060860182610d33565b508091505092915050565b6000610db88383610d42565b905092915050565b6000602082019050919050565b6000610dd882610c08565b610de28185610c13565b935083602082028501610df485610c24565b8060005b85811015610e305784840389528151610e118582610dac565b9450610e1c83610dc0565b925060208a01995050600181019050610df8565b50829750879550505050505092915050565b60006020820190508181036000830152610e5c8184610dcd565b905092915050565b610e6d81610820565b82525050565b600082825260208201905092915050565b6000610e8f82610c34565b610e998185610e73565b9350610ea9818560208601610c50565b610eb281610868565b840191505092915050565b6000604082019050610ed26000830185610e64565b8181036020830152610ee48184610e84565b90509392505050565b600081519050610efc81610a34565b92915050565b600060208284031215610f1857610f176107f6565b5b6000610f2684828501610eed565b91505092915050565b6000606082019050610f446000830186610e64565b8181036020830152610f568185610e84565b9050610f656040830184610a0a565b949350505050565b610f7681610acf565b8114610f8157600080fd5b50565b600081519050610f9381610f6d565b92915050565b600060208284031215610faf57610fae6107f6565b5b6000610fbd84828501610f84565b91505092915050565b610fcf81610b06565b8114610fda57600080fd5b50565b600081519050610fec81610fc6565b92915050565b600060208284031215611008576110076107f6565b5b600061101684828501610fdd565b91505092915050565b60006080820190506110346000830187610e64565b81810360208301526110468186610e84565b9050818103604083015261105a8185610e84565b90506110696060830184610a0a565b95945050505050565b600067ffffffffffffffff82111561108d5761108c610879565b5b602082029050602081019050919050565b600080fd5b600080fd5b600080fd5b60006110c06110bb846108f4565b6108d9565b9050828152602081018484840111156110dc576110db610863565b5b6110e7848285610c50565b509392505050565b600082601f8301126111045761110361085e565b5b81516111148482602086016110ad565b91505092915050565b6004811061112a57600080fd5b50565b60008151905061113c8161111d565b92915050565b600060808284031215611158576111576110a3565b5b61116260806108d9565b9050600082015167ffffffffffffffff811115611182576111816110a8565b5b61118e848285016110ef565b600083015250602082015167ffffffffffffffff8111156111b2576111b16110a8565b5b6111be848285016110ef565b60208301525060406111d284828501610fdd565b60408301525060606111e68482850161112d565b60608301525092915050565b600061120561120084611072565b6108d9565b905080838252602082019050602084028301858111156112285761122761109e565b5b835b8181101561126f57805167ffffffffffffffff81111561124d5761124c61085e565b5b80860161125a8982611142565b8552602085019450505060208101905061122a565b5050509392505050565b600082601f83011261128e5761128d61085e565b5b815161129e8482602086016111f2565b91505092915050565b6000602082840312156112bd576112bc6107f6565b5b600082015167ffffffffffffffff8111156112db576112da6107fb565b5b6112e784828501611279565b9150509291505056fea26469706673582212209d34227b9c73d9c6eb2b67ca8fabedb28adcac235655b12df2a572847549ea2a64736f6c634300080a0033", + ABI: "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_wzeta\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"stateMutability\":\"payable\",\"type\":\"fallback\"},{\"inputs\":[],\"name\":\"counter\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"depositWZETA\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getAllValidators\",\"outputs\":[{\"components\":[{\"internalType\":\"string\",\"name\":\"operatorAddress\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"consensusPubKey\",\"type\":\"string\"},{\"internalType\":\"bool\",\"name\":\"jailed\",\"type\":\"bool\"},{\"internalType\":\"enumBondStatus\",\"name\":\"bondStatus\",\"type\":\"uint8\"}],\"internalType\":\"structValidator[]\",\"name\":\"validators\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"staker\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"validator\",\"type\":\"string\"}],\"name\":\"getShares\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"shares\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"staker\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"validatorSrc\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"validatorDst\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"moveStake\",\"outputs\":[{\"internalType\":\"int64\",\"name\":\"completionTime\",\"type\":\"int64\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"staker\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"validator\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"stake\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"staker\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"validator\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"stakeAndRevert\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"staker\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"validator\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"stakeWithStateUpdate\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"staker\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"validator\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"unstake\",\"outputs\":[{\"internalType\":\"int64\",\"name\":\"completionTime\",\"type\":\"int64\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"wad\",\"type\":\"uint256\"}],\"name\":\"withdrawWZETA\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"stateMutability\":\"payable\",\"type\":\"receive\"}]", + Bin: "0x608060405260666000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060006003553480156200005757600080fd5b506040516200192d3803806200192d83398181016040528101906200007d919062000170565b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555033600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050620001a2565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600062000138826200010b565b9050919050565b6200014a816200012b565b81146200015657600080fd5b50565b6000815190506200016a816200013f565b92915050565b60006020828403121562000189576200018862000106565b5b6000620001998482850162000159565b91505092915050565b61177b80620001b26000396000f3fe6080604052600436106100955760003560e01c806390b8436f1161005957806390b8436f1461018a5780639a0fb673146101c7578063bca8f527146101f0578063d11a93d01461022d578063f3513a371461026a5761009c565b80630d1b3daf1461009e5780632c5d24ae146100db57806357c6ea3e146100e557806361bc221a146101225780636be8916c1461014d5761009c565b3661009c57005b005b3480156100aa57600080fd5b506100c560048036038101906100c09190610d08565b610295565b6040516100d29190610d7d565b60405180910390f35b6100e361033c565b005b3480156100f157600080fd5b5061010c60048036038101906101079190610dc4565b61041b565b6040516101199190610e4f565b60405180910390f35b34801561012e57600080fd5b50610137610520565b6040516101449190610d7d565b60405180910390f35b34801561015957600080fd5b50610174600480360381019061016f9190610dc4565b610526565b6040516101819190610e85565b60405180910390f35b34801561019657600080fd5b506101b160048036038101906101ac9190610dc4565b61065c565b6040516101be9190610e85565b60405180910390f35b3480156101d357600080fd5b506101ee60048036038101906101e99190610ea0565b610761565b005b3480156101fc57600080fd5b5061021760048036038101906102129190610dc4565b61084b565b6040516102249190610e85565b60405180910390f35b34801561023957600080fd5b50610254600480360381019061024f9190610ecd565b6109ad565b6040516102619190610e4f565b60405180910390f35b34801561027657600080fd5b5061027f610ab5565b60405161028c91906111a6565b60405180910390f35b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16630d1b3daf84846040518363ffffffff1660e01b81526004016102f3929190611221565b602060405180830381865afa158015610310573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103349190611266565b905092915050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461039657600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561040057600080fd5b505af1158015610414573d6000803e3d6000fd5b5050505050565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461047757600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166357c6ea3e8585856040518463ffffffff1660e01b81526004016104d493929190611293565b6020604051808303816000875af11580156104f3573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061051791906112fd565b90509392505050565b60035481565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461058257600080fd5b60016003546105919190611359565b60038190555060008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166390b8436f8686866040518463ffffffff1660e01b81526004016105f793929190611293565b6020604051808303816000875af1158015610616573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061063a91906113db565b9050600160035461064b9190611359565b600381905550809150509392505050565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146106b857600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166390b8436f8585856040518463ffffffff1660e01b815260040161071593929190611293565b6020604051808303816000875af1158015610734573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061075891906113db565b90509392505050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146107bb57600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16632e1a7d4d826040518263ffffffff1660e01b81526004016108169190610d7d565b600060405180830381600087803b15801561083057600080fd5b505af1158015610844573d6000803e3d6000fd5b5050505050565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146108a757600080fd5b60016003546108b69190611359565b60038190555060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166390b8436f8585856040518463ffffffff1660e01b815260040161091993929190611293565b6020604051808303816000875af1158015610938573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061095c91906113db565b50600160035461096c9190611359565b6003819055506040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109a490611454565b60405180910390fd5b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610a0957600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d11a93d0868686866040518563ffffffff1660e01b8152600401610a689493929190611474565b6020604051808303816000875af1158015610a87573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aab91906112fd565b9050949350505050565b606060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f3513a376040518163ffffffff1660e01b8152600401600060405180830381865afa158015610b22573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f82011682018060405250810190610b4b91906116fc565b905090565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610b8f82610b64565b9050919050565b610b9f81610b84565b8114610baa57600080fd5b50565b600081359050610bbc81610b96565b92915050565b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610c1582610bcc565b810181811067ffffffffffffffff82111715610c3457610c33610bdd565b5b80604052505050565b6000610c47610b50565b9050610c538282610c0c565b919050565b600067ffffffffffffffff821115610c7357610c72610bdd565b5b610c7c82610bcc565b9050602081019050919050565b82818337600083830152505050565b6000610cab610ca684610c58565b610c3d565b905082815260208101848484011115610cc757610cc6610bc7565b5b610cd2848285610c89565b509392505050565b600082601f830112610cef57610cee610bc2565b5b8135610cff848260208601610c98565b91505092915050565b60008060408385031215610d1f57610d1e610b5a565b5b6000610d2d85828601610bad565b925050602083013567ffffffffffffffff811115610d4e57610d4d610b5f565b5b610d5a85828601610cda565b9150509250929050565b6000819050919050565b610d7781610d64565b82525050565b6000602082019050610d926000830184610d6e565b92915050565b610da181610d64565b8114610dac57600080fd5b50565b600081359050610dbe81610d98565b92915050565b600080600060608486031215610ddd57610ddc610b5a565b5b6000610deb86828701610bad565b935050602084013567ffffffffffffffff811115610e0c57610e0b610b5f565b5b610e1886828701610cda565b9250506040610e2986828701610daf565b9150509250925092565b60008160070b9050919050565b610e4981610e33565b82525050565b6000602082019050610e646000830184610e40565b92915050565b60008115159050919050565b610e7f81610e6a565b82525050565b6000602082019050610e9a6000830184610e76565b92915050565b600060208284031215610eb657610eb5610b5a565b5b6000610ec484828501610daf565b91505092915050565b60008060008060808587031215610ee757610ee6610b5a565b5b6000610ef587828801610bad565b945050602085013567ffffffffffffffff811115610f1657610f15610b5f565b5b610f2287828801610cda565b935050604085013567ffffffffffffffff811115610f4357610f42610b5f565b5b610f4f87828801610cda565b9250506060610f6087828801610daf565b91505092959194509250565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610fd2578082015181840152602081019050610fb7565b83811115610fe1576000848401525b50505050565b6000610ff282610f98565b610ffc8185610fa3565b935061100c818560208601610fb4565b61101581610bcc565b840191505092915050565b61102981610e6a565b82525050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b6004811061106f5761106e61102f565b5b50565b60008190506110808261105e565b919050565b600061109082611072565b9050919050565b6110a081611085565b82525050565b600060808301600083015184820360008601526110c38282610fe7565b915050602083015184820360208601526110dd8282610fe7565b91505060408301516110f26040860182611020565b5060608301516111056060860182611097565b508091505092915050565b600061111c83836110a6565b905092915050565b6000602082019050919050565b600061113c82610f6c565b6111468185610f77565b93508360208202850161115885610f88565b8060005b8581101561119457848403895281516111758582611110565b945061118083611124565b925060208a0199505060018101905061115c565b50829750879550505050505092915050565b600060208201905081810360008301526111c08184611131565b905092915050565b6111d181610b84565b82525050565b600082825260208201905092915050565b60006111f382610f98565b6111fd81856111d7565b935061120d818560208601610fb4565b61121681610bcc565b840191505092915050565b600060408201905061123660008301856111c8565b818103602083015261124881846111e8565b90509392505050565b60008151905061126081610d98565b92915050565b60006020828403121561127c5761127b610b5a565b5b600061128a84828501611251565b91505092915050565b60006060820190506112a860008301866111c8565b81810360208301526112ba81856111e8565b90506112c96040830184610d6e565b949350505050565b6112da81610e33565b81146112e557600080fd5b50565b6000815190506112f7816112d1565b92915050565b60006020828403121561131357611312610b5a565b5b6000611321848285016112e8565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061136482610d64565b915061136f83610d64565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156113a4576113a361132a565b5b828201905092915050565b6113b881610e6a565b81146113c357600080fd5b50565b6000815190506113d5816113af565b92915050565b6000602082840312156113f1576113f0610b5a565b5b60006113ff848285016113c6565b91505092915050565b7f7465737472657665727400000000000000000000000000000000000000000000600082015250565b600061143e600a836111d7565b915061144982611408565b602082019050919050565b6000602082019050818103600083015261146d81611431565b9050919050565b600060808201905061148960008301876111c8565b818103602083015261149b81866111e8565b905081810360408301526114af81856111e8565b90506114be6060830184610d6e565b95945050505050565b600067ffffffffffffffff8211156114e2576114e1610bdd565b5b602082029050602081019050919050565b600080fd5b600080fd5b600080fd5b600061151561151084610c58565b610c3d565b90508281526020810184848401111561153157611530610bc7565b5b61153c848285610fb4565b509392505050565b600082601f83011261155957611558610bc2565b5b8151611569848260208601611502565b91505092915050565b6004811061157f57600080fd5b50565b60008151905061159181611572565b92915050565b6000608082840312156115ad576115ac6114f8565b5b6115b76080610c3d565b9050600082015167ffffffffffffffff8111156115d7576115d66114fd565b5b6115e384828501611544565b600083015250602082015167ffffffffffffffff811115611607576116066114fd565b5b61161384828501611544565b6020830152506040611627848285016113c6565b604083015250606061163b84828501611582565b60608301525092915050565b600061165a611655846114c7565b610c3d565b9050808382526020820190506020840283018581111561167d5761167c6114f3565b5b835b818110156116c457805167ffffffffffffffff8111156116a2576116a1610bc2565b5b8086016116af8982611597565b8552602085019450505060208101905061167f565b5050509392505050565b600082601f8301126116e3576116e2610bc2565b5b81516116f3848260208601611647565b91505092915050565b60006020828403121561171257611711610b5a565b5b600082015167ffffffffffffffff8111156117305761172f610b5f565b5b61173c848285016116ce565b9150509291505056fea2646970667358221220fbbd8da0d7360633653761cbde3d46828949fcca1b71279d79140864c678daeb64736f6c634300080a0033", } // TestStakingABI is the input ABI used to generate the binding from. @@ -210,6 +210,37 @@ func (_TestStaking *TestStakingTransactorRaw) Transact(opts *bind.TransactOpts, return _TestStaking.Contract.contract.Transact(opts, method, params...) } +// Counter is a free data retrieval call binding the contract method 0x61bc221a. +// +// Solidity: function counter() view returns(uint256) +func (_TestStaking *TestStakingCaller) Counter(opts *bind.CallOpts) (*big.Int, error) { + var out []interface{} + err := _TestStaking.contract.Call(opts, &out, "counter") + + if err != nil { + return *new(*big.Int), err + } + + out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int) + + return out0, err + +} + +// Counter is a free data retrieval call binding the contract method 0x61bc221a. +// +// Solidity: function counter() view returns(uint256) +func (_TestStaking *TestStakingSession) Counter() (*big.Int, error) { + return _TestStaking.Contract.Counter(&_TestStaking.CallOpts) +} + +// Counter is a free data retrieval call binding the contract method 0x61bc221a. +// +// Solidity: function counter() view returns(uint256) +func (_TestStaking *TestStakingCallerSession) Counter() (*big.Int, error) { + return _TestStaking.Contract.Counter(&_TestStaking.CallOpts) +} + // GetAllValidators is a free data retrieval call binding the contract method 0xf3513a37. // // Solidity: function getAllValidators() view returns((string,string,bool,uint8)[] validators) @@ -335,6 +366,48 @@ func (_TestStaking *TestStakingTransactorSession) Stake(staker common.Address, v return _TestStaking.Contract.Stake(&_TestStaking.TransactOpts, staker, validator, amount) } +// StakeAndRevert is a paid mutator transaction binding the contract method 0xbca8f527. +// +// Solidity: function stakeAndRevert(address staker, string validator, uint256 amount) returns(bool) +func (_TestStaking *TestStakingTransactor) StakeAndRevert(opts *bind.TransactOpts, staker common.Address, validator string, amount *big.Int) (*types.Transaction, error) { + return _TestStaking.contract.Transact(opts, "stakeAndRevert", staker, validator, amount) +} + +// StakeAndRevert is a paid mutator transaction binding the contract method 0xbca8f527. +// +// Solidity: function stakeAndRevert(address staker, string validator, uint256 amount) returns(bool) +func (_TestStaking *TestStakingSession) StakeAndRevert(staker common.Address, validator string, amount *big.Int) (*types.Transaction, error) { + return _TestStaking.Contract.StakeAndRevert(&_TestStaking.TransactOpts, staker, validator, amount) +} + +// StakeAndRevert is a paid mutator transaction binding the contract method 0xbca8f527. +// +// Solidity: function stakeAndRevert(address staker, string validator, uint256 amount) returns(bool) +func (_TestStaking *TestStakingTransactorSession) StakeAndRevert(staker common.Address, validator string, amount *big.Int) (*types.Transaction, error) { + return _TestStaking.Contract.StakeAndRevert(&_TestStaking.TransactOpts, staker, validator, amount) +} + +// StakeWithStateUpdate is a paid mutator transaction binding the contract method 0x6be8916c. +// +// Solidity: function stakeWithStateUpdate(address staker, string validator, uint256 amount) returns(bool) +func (_TestStaking *TestStakingTransactor) StakeWithStateUpdate(opts *bind.TransactOpts, staker common.Address, validator string, amount *big.Int) (*types.Transaction, error) { + return _TestStaking.contract.Transact(opts, "stakeWithStateUpdate", staker, validator, amount) +} + +// StakeWithStateUpdate is a paid mutator transaction binding the contract method 0x6be8916c. +// +// Solidity: function stakeWithStateUpdate(address staker, string validator, uint256 amount) returns(bool) +func (_TestStaking *TestStakingSession) StakeWithStateUpdate(staker common.Address, validator string, amount *big.Int) (*types.Transaction, error) { + return _TestStaking.Contract.StakeWithStateUpdate(&_TestStaking.TransactOpts, staker, validator, amount) +} + +// StakeWithStateUpdate is a paid mutator transaction binding the contract method 0x6be8916c. +// +// Solidity: function stakeWithStateUpdate(address staker, string validator, uint256 amount) returns(bool) +func (_TestStaking *TestStakingTransactorSession) StakeWithStateUpdate(staker common.Address, validator string, amount *big.Int) (*types.Transaction, error) { + return _TestStaking.Contract.StakeWithStateUpdate(&_TestStaking.TransactOpts, staker, validator, amount) +} + // Unstake is a paid mutator transaction binding the contract method 0x57c6ea3e. // // Solidity: function unstake(address staker, string validator, uint256 amount) returns(int64 completionTime) diff --git a/e2e/contracts/teststaking/TestStaking.json b/e2e/contracts/teststaking/TestStaking.json index ebc45c196a..fbfc23ab37 100644 --- a/e2e/contracts/teststaking/TestStaking.json +++ b/e2e/contracts/teststaking/TestStaking.json @@ -15,6 +15,19 @@ "stateMutability": "payable", "type": "fallback" }, + { + "inputs": [], + "name": "counter", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "depositWZETA", @@ -144,6 +157,64 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "staker", + "type": "address" + }, + { + "internalType": "string", + "name": "validator", + "type": "string" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "stakeAndRevert", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "staker", + "type": "address" + }, + { + "internalType": "string", + "name": "validator", + "type": "string" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "stakeWithStateUpdate", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -191,5 +262,5 @@ "type": "receive" } ], - "bin": "608060405260666000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055503480156200005257600080fd5b50604051620014d3380380620014d383398181016040528101906200007891906200016b565b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555033600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550506200019d565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000620001338262000106565b9050919050565b620001458162000126565b81146200015157600080fd5b50565b60008151905062000165816200013a565b92915050565b60006020828403121562000184576200018362000101565b5b6000620001948482850162000154565b91505092915050565b61132680620001ad6000396000f3fe6080604052600436106100745760003560e01c806390b8436f1161004e57806390b8436f146101015780639a0fb6731461013e578063d11a93d014610167578063f3513a37146101a45761007b565b80630d1b3daf1461007d5780632c5d24ae146100ba57806357c6ea3e146100c45761007b565b3661007b57005b005b34801561008957600080fd5b506100a4600480360381019061009f91906109a4565b6101cf565b6040516100b19190610a19565b60405180910390f35b6100c2610276565b005b3480156100d057600080fd5b506100eb60048036038101906100e69190610a60565b610355565b6040516100f89190610aeb565b60405180910390f35b34801561010d57600080fd5b5061012860048036038101906101239190610a60565b61045a565b6040516101359190610b21565b60405180910390f35b34801561014a57600080fd5b5061016560048036038101906101609190610b3c565b61055f565b005b34801561017357600080fd5b5061018e60048036038101906101899190610b69565b610649565b60405161019b9190610aeb565b60405180910390f35b3480156101b057600080fd5b506101b9610751565b6040516101c69190610e42565b60405180910390f35b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16630d1b3daf84846040518363ffffffff1660e01b815260040161022d929190610ebd565b602060405180830381865afa15801561024a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061026e9190610f02565b905092915050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146102d057600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561033a57600080fd5b505af115801561034e573d6000803e3d6000fd5b5050505050565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146103b157600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166357c6ea3e8585856040518463ffffffff1660e01b815260040161040e93929190610f2f565b6020604051808303816000875af115801561042d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104519190610f99565b90509392505050565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146104b657600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166390b8436f8585856040518463ffffffff1660e01b815260040161051393929190610f2f565b6020604051808303816000875af1158015610532573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105569190610ff2565b90509392505050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146105b957600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16632e1a7d4d826040518263ffffffff1660e01b81526004016106149190610a19565b600060405180830381600087803b15801561062e57600080fd5b505af1158015610642573d6000803e3d6000fd5b5050505050565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146106a557600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d11a93d0868686866040518563ffffffff1660e01b8152600401610704949392919061101f565b6020604051808303816000875af1158015610723573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107479190610f99565b9050949350505050565b606060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f3513a376040518163ffffffff1660e01b8152600401600060405180830381865afa1580156107be573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f820116820180604052508101906107e791906112a7565b905090565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061082b82610800565b9050919050565b61083b81610820565b811461084657600080fd5b50565b60008135905061085881610832565b92915050565b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6108b182610868565b810181811067ffffffffffffffff821117156108d0576108cf610879565b5b80604052505050565b60006108e36107ec565b90506108ef82826108a8565b919050565b600067ffffffffffffffff82111561090f5761090e610879565b5b61091882610868565b9050602081019050919050565b82818337600083830152505050565b6000610947610942846108f4565b6108d9565b90508281526020810184848401111561096357610962610863565b5b61096e848285610925565b509392505050565b600082601f83011261098b5761098a61085e565b5b813561099b848260208601610934565b91505092915050565b600080604083850312156109bb576109ba6107f6565b5b60006109c985828601610849565b925050602083013567ffffffffffffffff8111156109ea576109e96107fb565b5b6109f685828601610976565b9150509250929050565b6000819050919050565b610a1381610a00565b82525050565b6000602082019050610a2e6000830184610a0a565b92915050565b610a3d81610a00565b8114610a4857600080fd5b50565b600081359050610a5a81610a34565b92915050565b600080600060608486031215610a7957610a786107f6565b5b6000610a8786828701610849565b935050602084013567ffffffffffffffff811115610aa857610aa76107fb565b5b610ab486828701610976565b9250506040610ac586828701610a4b565b9150509250925092565b60008160070b9050919050565b610ae581610acf565b82525050565b6000602082019050610b006000830184610adc565b92915050565b60008115159050919050565b610b1b81610b06565b82525050565b6000602082019050610b366000830184610b12565b92915050565b600060208284031215610b5257610b516107f6565b5b6000610b6084828501610a4b565b91505092915050565b60008060008060808587031215610b8357610b826107f6565b5b6000610b9187828801610849565b945050602085013567ffffffffffffffff811115610bb257610bb16107fb565b5b610bbe87828801610976565b935050604085013567ffffffffffffffff811115610bdf57610bde6107fb565b5b610beb87828801610976565b9250506060610bfc87828801610a4b565b91505092959194509250565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610c6e578082015181840152602081019050610c53565b83811115610c7d576000848401525b50505050565b6000610c8e82610c34565b610c988185610c3f565b9350610ca8818560208601610c50565b610cb181610868565b840191505092915050565b610cc581610b06565b82525050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b60048110610d0b57610d0a610ccb565b5b50565b6000819050610d1c82610cfa565b919050565b6000610d2c82610d0e565b9050919050565b610d3c81610d21565b82525050565b60006080830160008301518482036000860152610d5f8282610c83565b91505060208301518482036020860152610d798282610c83565b9150506040830151610d8e6040860182610cbc565b506060830151610da16060860182610d33565b508091505092915050565b6000610db88383610d42565b905092915050565b6000602082019050919050565b6000610dd882610c08565b610de28185610c13565b935083602082028501610df485610c24565b8060005b85811015610e305784840389528151610e118582610dac565b9450610e1c83610dc0565b925060208a01995050600181019050610df8565b50829750879550505050505092915050565b60006020820190508181036000830152610e5c8184610dcd565b905092915050565b610e6d81610820565b82525050565b600082825260208201905092915050565b6000610e8f82610c34565b610e998185610e73565b9350610ea9818560208601610c50565b610eb281610868565b840191505092915050565b6000604082019050610ed26000830185610e64565b8181036020830152610ee48184610e84565b90509392505050565b600081519050610efc81610a34565b92915050565b600060208284031215610f1857610f176107f6565b5b6000610f2684828501610eed565b91505092915050565b6000606082019050610f446000830186610e64565b8181036020830152610f568185610e84565b9050610f656040830184610a0a565b949350505050565b610f7681610acf565b8114610f8157600080fd5b50565b600081519050610f9381610f6d565b92915050565b600060208284031215610faf57610fae6107f6565b5b6000610fbd84828501610f84565b91505092915050565b610fcf81610b06565b8114610fda57600080fd5b50565b600081519050610fec81610fc6565b92915050565b600060208284031215611008576110076107f6565b5b600061101684828501610fdd565b91505092915050565b60006080820190506110346000830187610e64565b81810360208301526110468186610e84565b9050818103604083015261105a8185610e84565b90506110696060830184610a0a565b95945050505050565b600067ffffffffffffffff82111561108d5761108c610879565b5b602082029050602081019050919050565b600080fd5b600080fd5b600080fd5b60006110c06110bb846108f4565b6108d9565b9050828152602081018484840111156110dc576110db610863565b5b6110e7848285610c50565b509392505050565b600082601f8301126111045761110361085e565b5b81516111148482602086016110ad565b91505092915050565b6004811061112a57600080fd5b50565b60008151905061113c8161111d565b92915050565b600060808284031215611158576111576110a3565b5b61116260806108d9565b9050600082015167ffffffffffffffff811115611182576111816110a8565b5b61118e848285016110ef565b600083015250602082015167ffffffffffffffff8111156111b2576111b16110a8565b5b6111be848285016110ef565b60208301525060406111d284828501610fdd565b60408301525060606111e68482850161112d565b60608301525092915050565b600061120561120084611072565b6108d9565b905080838252602082019050602084028301858111156112285761122761109e565b5b835b8181101561126f57805167ffffffffffffffff81111561124d5761124c61085e565b5b80860161125a8982611142565b8552602085019450505060208101905061122a565b5050509392505050565b600082601f83011261128e5761128d61085e565b5b815161129e8482602086016111f2565b91505092915050565b6000602082840312156112bd576112bc6107f6565b5b600082015167ffffffffffffffff8111156112db576112da6107fb565b5b6112e784828501611279565b9150509291505056fea26469706673582212209d34227b9c73d9c6eb2b67ca8fabedb28adcac235655b12df2a572847549ea2a64736f6c634300080a0033" + "bin": "608060405260666000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060006003553480156200005757600080fd5b506040516200192d3803806200192d83398181016040528101906200007d919062000170565b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555033600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050620001a2565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600062000138826200010b565b9050919050565b6200014a816200012b565b81146200015657600080fd5b50565b6000815190506200016a816200013f565b92915050565b60006020828403121562000189576200018862000106565b5b6000620001998482850162000159565b91505092915050565b61177b80620001b26000396000f3fe6080604052600436106100955760003560e01c806390b8436f1161005957806390b8436f1461018a5780639a0fb673146101c7578063bca8f527146101f0578063d11a93d01461022d578063f3513a371461026a5761009c565b80630d1b3daf1461009e5780632c5d24ae146100db57806357c6ea3e146100e557806361bc221a146101225780636be8916c1461014d5761009c565b3661009c57005b005b3480156100aa57600080fd5b506100c560048036038101906100c09190610d08565b610295565b6040516100d29190610d7d565b60405180910390f35b6100e361033c565b005b3480156100f157600080fd5b5061010c60048036038101906101079190610dc4565b61041b565b6040516101199190610e4f565b60405180910390f35b34801561012e57600080fd5b50610137610520565b6040516101449190610d7d565b60405180910390f35b34801561015957600080fd5b50610174600480360381019061016f9190610dc4565b610526565b6040516101819190610e85565b60405180910390f35b34801561019657600080fd5b506101b160048036038101906101ac9190610dc4565b61065c565b6040516101be9190610e85565b60405180910390f35b3480156101d357600080fd5b506101ee60048036038101906101e99190610ea0565b610761565b005b3480156101fc57600080fd5b5061021760048036038101906102129190610dc4565b61084b565b6040516102249190610e85565b60405180910390f35b34801561023957600080fd5b50610254600480360381019061024f9190610ecd565b6109ad565b6040516102619190610e4f565b60405180910390f35b34801561027657600080fd5b5061027f610ab5565b60405161028c91906111a6565b60405180910390f35b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16630d1b3daf84846040518363ffffffff1660e01b81526004016102f3929190611221565b602060405180830381865afa158015610310573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103349190611266565b905092915050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461039657600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561040057600080fd5b505af1158015610414573d6000803e3d6000fd5b5050505050565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461047757600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166357c6ea3e8585856040518463ffffffff1660e01b81526004016104d493929190611293565b6020604051808303816000875af11580156104f3573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061051791906112fd565b90509392505050565b60035481565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461058257600080fd5b60016003546105919190611359565b60038190555060008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166390b8436f8686866040518463ffffffff1660e01b81526004016105f793929190611293565b6020604051808303816000875af1158015610616573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061063a91906113db565b9050600160035461064b9190611359565b600381905550809150509392505050565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146106b857600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166390b8436f8585856040518463ffffffff1660e01b815260040161071593929190611293565b6020604051808303816000875af1158015610734573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061075891906113db565b90509392505050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146107bb57600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16632e1a7d4d826040518263ffffffff1660e01b81526004016108169190610d7d565b600060405180830381600087803b15801561083057600080fd5b505af1158015610844573d6000803e3d6000fd5b5050505050565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146108a757600080fd5b60016003546108b69190611359565b60038190555060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166390b8436f8585856040518463ffffffff1660e01b815260040161091993929190611293565b6020604051808303816000875af1158015610938573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061095c91906113db565b50600160035461096c9190611359565b6003819055506040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109a490611454565b60405180910390fd5b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610a0957600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d11a93d0868686866040518563ffffffff1660e01b8152600401610a689493929190611474565b6020604051808303816000875af1158015610a87573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aab91906112fd565b9050949350505050565b606060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f3513a376040518163ffffffff1660e01b8152600401600060405180830381865afa158015610b22573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f82011682018060405250810190610b4b91906116fc565b905090565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610b8f82610b64565b9050919050565b610b9f81610b84565b8114610baa57600080fd5b50565b600081359050610bbc81610b96565b92915050565b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610c1582610bcc565b810181811067ffffffffffffffff82111715610c3457610c33610bdd565b5b80604052505050565b6000610c47610b50565b9050610c538282610c0c565b919050565b600067ffffffffffffffff821115610c7357610c72610bdd565b5b610c7c82610bcc565b9050602081019050919050565b82818337600083830152505050565b6000610cab610ca684610c58565b610c3d565b905082815260208101848484011115610cc757610cc6610bc7565b5b610cd2848285610c89565b509392505050565b600082601f830112610cef57610cee610bc2565b5b8135610cff848260208601610c98565b91505092915050565b60008060408385031215610d1f57610d1e610b5a565b5b6000610d2d85828601610bad565b925050602083013567ffffffffffffffff811115610d4e57610d4d610b5f565b5b610d5a85828601610cda565b9150509250929050565b6000819050919050565b610d7781610d64565b82525050565b6000602082019050610d926000830184610d6e565b92915050565b610da181610d64565b8114610dac57600080fd5b50565b600081359050610dbe81610d98565b92915050565b600080600060608486031215610ddd57610ddc610b5a565b5b6000610deb86828701610bad565b935050602084013567ffffffffffffffff811115610e0c57610e0b610b5f565b5b610e1886828701610cda565b9250506040610e2986828701610daf565b9150509250925092565b60008160070b9050919050565b610e4981610e33565b82525050565b6000602082019050610e646000830184610e40565b92915050565b60008115159050919050565b610e7f81610e6a565b82525050565b6000602082019050610e9a6000830184610e76565b92915050565b600060208284031215610eb657610eb5610b5a565b5b6000610ec484828501610daf565b91505092915050565b60008060008060808587031215610ee757610ee6610b5a565b5b6000610ef587828801610bad565b945050602085013567ffffffffffffffff811115610f1657610f15610b5f565b5b610f2287828801610cda565b935050604085013567ffffffffffffffff811115610f4357610f42610b5f565b5b610f4f87828801610cda565b9250506060610f6087828801610daf565b91505092959194509250565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610fd2578082015181840152602081019050610fb7565b83811115610fe1576000848401525b50505050565b6000610ff282610f98565b610ffc8185610fa3565b935061100c818560208601610fb4565b61101581610bcc565b840191505092915050565b61102981610e6a565b82525050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b6004811061106f5761106e61102f565b5b50565b60008190506110808261105e565b919050565b600061109082611072565b9050919050565b6110a081611085565b82525050565b600060808301600083015184820360008601526110c38282610fe7565b915050602083015184820360208601526110dd8282610fe7565b91505060408301516110f26040860182611020565b5060608301516111056060860182611097565b508091505092915050565b600061111c83836110a6565b905092915050565b6000602082019050919050565b600061113c82610f6c565b6111468185610f77565b93508360208202850161115885610f88565b8060005b8581101561119457848403895281516111758582611110565b945061118083611124565b925060208a0199505060018101905061115c565b50829750879550505050505092915050565b600060208201905081810360008301526111c08184611131565b905092915050565b6111d181610b84565b82525050565b600082825260208201905092915050565b60006111f382610f98565b6111fd81856111d7565b935061120d818560208601610fb4565b61121681610bcc565b840191505092915050565b600060408201905061123660008301856111c8565b818103602083015261124881846111e8565b90509392505050565b60008151905061126081610d98565b92915050565b60006020828403121561127c5761127b610b5a565b5b600061128a84828501611251565b91505092915050565b60006060820190506112a860008301866111c8565b81810360208301526112ba81856111e8565b90506112c96040830184610d6e565b949350505050565b6112da81610e33565b81146112e557600080fd5b50565b6000815190506112f7816112d1565b92915050565b60006020828403121561131357611312610b5a565b5b6000611321848285016112e8565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061136482610d64565b915061136f83610d64565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156113a4576113a361132a565b5b828201905092915050565b6113b881610e6a565b81146113c357600080fd5b50565b6000815190506113d5816113af565b92915050565b6000602082840312156113f1576113f0610b5a565b5b60006113ff848285016113c6565b91505092915050565b7f7465737472657665727400000000000000000000000000000000000000000000600082015250565b600061143e600a836111d7565b915061144982611408565b602082019050919050565b6000602082019050818103600083015261146d81611431565b9050919050565b600060808201905061148960008301876111c8565b818103602083015261149b81866111e8565b905081810360408301526114af81856111e8565b90506114be6060830184610d6e565b95945050505050565b600067ffffffffffffffff8211156114e2576114e1610bdd565b5b602082029050602081019050919050565b600080fd5b600080fd5b600080fd5b600061151561151084610c58565b610c3d565b90508281526020810184848401111561153157611530610bc7565b5b61153c848285610fb4565b509392505050565b600082601f83011261155957611558610bc2565b5b8151611569848260208601611502565b91505092915050565b6004811061157f57600080fd5b50565b60008151905061159181611572565b92915050565b6000608082840312156115ad576115ac6114f8565b5b6115b76080610c3d565b9050600082015167ffffffffffffffff8111156115d7576115d66114fd565b5b6115e384828501611544565b600083015250602082015167ffffffffffffffff811115611607576116066114fd565b5b61161384828501611544565b6020830152506040611627848285016113c6565b604083015250606061163b84828501611582565b60608301525092915050565b600061165a611655846114c7565b610c3d565b9050808382526020820190506020840283018581111561167d5761167c6114f3565b5b835b818110156116c457805167ffffffffffffffff8111156116a2576116a1610bc2565b5b8086016116af8982611597565b8552602085019450505060208101905061167f565b5050509392505050565b600082601f8301126116e3576116e2610bc2565b5b81516116f3848260208601611647565b91505092915050565b60006020828403121561171257611711610b5a565b5b600082015167ffffffffffffffff8111156117305761172f610b5f565b5b61173c848285016116ce565b9150509291505056fea2646970667358221220fbbd8da0d7360633653761cbde3d46828949fcca1b71279d79140864c678daeb64736f6c634300080a0033" } diff --git a/e2e/contracts/teststaking/TestStaking.sol b/e2e/contracts/teststaking/TestStaking.sol index f4d633ca38..a92786519b 100644 --- a/e2e/contracts/teststaking/TestStaking.sol +++ b/e2e/contracts/teststaking/TestStaking.sol @@ -52,6 +52,9 @@ contract TestStaking { WZETA wzeta; address owner; + // @dev used to test state change in smart contract + uint256 public counter = 0; + constructor(address _wzeta) { wzeta = WZETA(_wzeta); owner = msg.sender; @@ -76,6 +79,20 @@ contract TestStaking { return staking.stake(staker, validator, amount); } + function stakeWithStateUpdate(address staker, string memory validator, uint256 amount) external onlyOwner returns (bool) { + counter = counter + 1; + bool success = staking.stake(staker, validator, amount); + counter = counter + 1; + return success; + } + + function stakeAndRevert(address staker, string memory validator, uint256 amount) external onlyOwner returns (bool) { + counter = counter + 1; + staking.stake(staker, validator, amount); + counter = counter + 1; + revert("testrevert"); + } + function unstake( address staker, string memory validator, diff --git a/e2e/e2etests/test_precompiles_staking_through_contract.go b/e2e/e2etests/test_precompiles_staking_through_contract.go index ade60de7bf..a9112f5b6e 100644 --- a/e2e/e2etests/test_precompiles_staking_through_contract.go +++ b/e2e/e2etests/test_precompiles_staking_through_contract.go @@ -4,10 +4,12 @@ import ( "math/big" sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/stretchr/testify/require" + "github.com/zeta-chain/node/cmd/zetacored/config" "github.com/zeta-chain/node/e2e/contracts/teststaking" "github.com/zeta-chain/node/e2e/runner" "github.com/zeta-chain/node/e2e/utils" @@ -58,15 +60,78 @@ func TestPrecompilesStakingThroughContract(r *runner.E2ERunner, args []string) { utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) r.ZEVMAuth.Value = big.NewInt(0) - tx, err = testStaking.WithdrawWZETA(r.ZEVMAuth, big.NewInt(100000000000)) + stakeAmount := 100000000000 + tx, err = testStaking.WithdrawWZETA(r.ZEVMAuth, big.NewInt(int64(stakeAmount))) require.NoError(r, err) utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) - // stake 3 to validator1 using testStaking smart contract - tx, err = testStaking.Stake(r.ZEVMAuth, testStakingAddr, validators[0].OperatorAddress, big.NewInt(3)) + // bank balance at the start + balanceBefore, err := r.BankClient.Balance(r.Ctx, &banktypes.QueryBalanceRequest{ + Address: sdk.AccAddress(testStakingAddr.Bytes()).String(), + Denom: config.BaseDenom, + }) + require.NoError(r, err) + require.Equal(r, int64(stakeAmount), balanceBefore.Balance.Amount.Int64()) + + // stake 3 to validator1 and revert in same function + tx, err = testStaking.StakeAndRevert(r.ZEVMAuth, testStakingAddr, validators[0].OperatorAddress, big.NewInt(3)) + require.NoError(r, err) + utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) + + // check that bank balance was not changed because of revert in testStaking contract + balanceAfterRevert, err := r.BankClient.Balance(r.Ctx, &banktypes.QueryBalanceRequest{ + Address: sdk.AccAddress(testStakingAddr.Bytes()).String(), + Denom: config.BaseDenom, + }) + require.NoError(r, err) + require.Equal(r, balanceBefore.Balance.Amount.Int64(), balanceAfterRevert.Balance.Amount.Int64()) + + // check that counter was not updated + counter, err := testStaking.Counter(&bind.CallOpts{}) + require.NoError(r, err) + require.Equal(r, int64(0), counter.Int64()) + + // check that shares are still 0 + sharesAfterRevert, err := testStaking.GetShares(&bind.CallOpts{}, testStakingAddr, validators[0].OperatorAddress) + require.NoError(r, err) + require.Equal(r, int64(0), sharesAfterRevert.Int64()) + + // stake 1 to validator1 using testStaking smart contract without smart contract state update + tx, err = testStaking.Stake(r.ZEVMAuth, testStakingAddr, validators[0].OperatorAddress, big.NewInt(1)) + require.NoError(r, err) + utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) + + // check that bank balance is reduced by 1 + balanceAfterStake, err := r.BankClient.Balance(r.Ctx, &banktypes.QueryBalanceRequest{ + Address: sdk.AccAddress(testStakingAddr.Bytes()).String(), + Denom: config.BaseDenom, + }) + require.NoError(r, err) + require.Equal(r, balanceBefore.Balance.Amount.Int64()-1, balanceAfterStake.Balance.Amount.Int64()) + + // stake 2 more to validator1 using testStaking smart contract with smart contract state update + tx, err = testStaking.StakeWithStateUpdate( + r.ZEVMAuth, + testStakingAddr, + validators[0].OperatorAddress, + big.NewInt(2), + ) require.NoError(r, err) utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) + // check that bank balance is reduced by 2 more, 3 in total + balanceAfterStake, err = r.BankClient.Balance(r.Ctx, &banktypes.QueryBalanceRequest{ + Address: sdk.AccAddress(testStakingAddr.Bytes()).String(), + Denom: config.BaseDenom, + }) + require.NoError(r, err) + require.Equal(r, balanceBefore.Balance.Amount.Int64()-3, balanceAfterStake.Balance.Amount.Int64()) + + // check that counter is updated + counter, err = testStaking.Counter(&bind.CallOpts{}) + require.NoError(r, err) + require.Equal(r, int64(2), counter.Int64()) + // check shares are set to 3 sharesAfterVal1, err := testStaking.GetShares(&bind.CallOpts{}, testStakingAddr, validators[0].OperatorAddress) require.NoError(r, err) diff --git a/precompiles/staking/staking.go b/precompiles/staking/staking.go index 6ce344a344..e800bf7d88 100644 --- a/precompiles/staking/staking.go +++ b/precompiles/staking/staking.go @@ -182,6 +182,7 @@ func (c *Contract) GetShares( func (c *Contract) Stake( ctx sdk.Context, + evm *vm.EVM, contract *vm.Contract, method *abi.Method, args []interface{}, @@ -231,6 +232,14 @@ func (c *Contract) Stake( return nil, err } + // if caller is not the same as origin it means call is coming through smart contract, + // and because state of smart contract calling precompile might be updated as well + // manually reduce amount in stateDB, so it is properly reflected in bank module + stateDB := evm.StateDB.(ptypes.ExtStateDB) + if contract.CallerAddress != evm.Origin { + stateDB.SubBalance(stakerAddress, amount) + } + return method.Outputs.Pack(true) } @@ -389,7 +398,7 @@ func (c *Contract) Run(evm *vm.EVM, contract *vm.Contract, _ bool) ([]byte, erro case StakeMethodName: var res []byte execErr := stateDB.ExecuteNativeAction(contract.Address(), nil, func(ctx sdk.Context) error { - res, err = c.Stake(ctx, contract, method, args) + res, err = c.Stake(ctx, evm, contract, method, args) return err }) if execErr != nil { diff --git a/precompiles/staking/staking_test.go b/precompiles/staking/staking_test.go index d7dfe933ac..b71316887f 100644 --- a/precompiles/staking/staking_test.go +++ b/precompiles/staking/staking_test.go @@ -376,7 +376,7 @@ func Test_Stake(t *testing.T) { t.Run("should fail if wrong args amount", func(t *testing.T) { // ARRANGE - ctx, contract, abi, sdkKeepers, _, _ := setup(t) + ctx, contract, abi, sdkKeepers, mockEVM, _ := setup(t) methodID := abi.Methods[StakeMethodName] r := rand.New(rand.NewSource(42)) validator := sample.Validator(t, r) @@ -395,7 +395,7 @@ func Test_Stake(t *testing.T) { args := []interface{}{stakerEthAddr, validator.OperatorAddress} // ACT - _, err = contract.Stake(ctx, &vm.Contract{CallerAddress: stakerAddr}, &methodID, args) + _, err = contract.Stake(ctx, mockEVM, &vm.Contract{CallerAddress: stakerAddr}, &methodID, args) // ASSERT require.Error(t, err) @@ -403,7 +403,7 @@ func Test_Stake(t *testing.T) { t.Run("should fail if staker is not eth addr", func(t *testing.T) { // ARRANGE - ctx, contract, abi, sdkKeepers, _, _ := setup(t) + ctx, contract, abi, sdkKeepers, mockEVM, _ := setup(t) methodID := abi.Methods[StakeMethodName] r := rand.New(rand.NewSource(42)) validator := sample.Validator(t, r) @@ -421,7 +421,7 @@ func Test_Stake(t *testing.T) { args := []interface{}{staker, validator.OperatorAddress, coins.AmountOf(config.BaseDenom).BigInt()} // ACT - _, err = contract.Stake(ctx, &vm.Contract{CallerAddress: stakerAddr}, &methodID, args) + _, err = contract.Stake(ctx, mockEVM, &vm.Contract{CallerAddress: stakerAddr}, &methodID, args) // ASSERT require.Error(t, err) @@ -429,7 +429,7 @@ func Test_Stake(t *testing.T) { t.Run("should fail if validator is not valid string", func(t *testing.T) { // ARRANGE - ctx, contract, abi, sdkKeepers, _, _ := setup(t) + ctx, contract, abi, sdkKeepers, mockEVM, _ := setup(t) methodID := abi.Methods[StakeMethodName] r := rand.New(rand.NewSource(42)) validator := sample.Validator(t, r) @@ -448,7 +448,7 @@ func Test_Stake(t *testing.T) { args := []interface{}{stakerEthAddr, 42, coins.AmountOf(config.BaseDenom).BigInt()} // ACT - _, err = contract.Stake(ctx, &vm.Contract{CallerAddress: stakerAddr}, &methodID, args) + _, err = contract.Stake(ctx, mockEVM, &vm.Contract{CallerAddress: stakerAddr}, &methodID, args) // ASSERT require.Error(t, err) @@ -456,7 +456,7 @@ func Test_Stake(t *testing.T) { t.Run("should fail if amount is not int64", func(t *testing.T) { // ARRANGE - ctx, contract, abi, sdkKeepers, _, _ := setup(t) + ctx, contract, abi, sdkKeepers, mockEVM, _ := setup(t) methodID := abi.Methods[StakeMethodName] r := rand.New(rand.NewSource(42)) validator := sample.Validator(t, r) @@ -475,7 +475,7 @@ func Test_Stake(t *testing.T) { args := []interface{}{stakerEthAddr, validator.OperatorAddress, coins.AmountOf(config.BaseDenom).Uint64()} // ACT - _, err = contract.Stake(ctx, &vm.Contract{CallerAddress: stakerAddr}, &methodID, args) + _, err = contract.Stake(ctx, mockEVM, &vm.Contract{CallerAddress: stakerAddr}, &methodID, args) // ASSERT require.Error(t, err) @@ -818,7 +818,7 @@ func Test_MoveStake(t *testing.T) { t.Run("should fail if staker is invalid arg", func(t *testing.T) { // ARRANGE - ctx, contract, abi, sdkKeepers, _, _ := setup(t) + ctx, contract, abi, sdkKeepers, mockEVM, _ := setup(t) methodID := abi.Methods[MoveStakeMethodName] r := rand.New(rand.NewSource(42)) validatorSrc := sample.Validator(t, r) @@ -844,7 +844,7 @@ func Test_MoveStake(t *testing.T) { // stake to validator src stakeMethodID := abi.Methods[StakeMethodName] - _, err = contract.Stake(ctx, &vm.Contract{CallerAddress: stakerAddr}, &stakeMethodID, argsStake) + _, err = contract.Stake(ctx, mockEVM, &vm.Contract{CallerAddress: stakerAddr}, &stakeMethodID, argsStake) require.NoError(t, err) argsMoveStake := []interface{}{ @@ -863,7 +863,7 @@ func Test_MoveStake(t *testing.T) { t.Run("should fail if validator src is invalid arg", func(t *testing.T) { // ARRANGE - ctx, contract, abi, sdkKeepers, _, _ := setup(t) + ctx, contract, abi, sdkKeepers, mockEVM, _ := setup(t) methodID := abi.Methods[MoveStakeMethodName] r := rand.New(rand.NewSource(42)) validatorSrc := sample.Validator(t, r) @@ -889,7 +889,7 @@ func Test_MoveStake(t *testing.T) { // stake to validator src stakeMethodID := abi.Methods[StakeMethodName] - _, err = contract.Stake(ctx, &vm.Contract{CallerAddress: stakerAddr}, &stakeMethodID, argsStake) + _, err = contract.Stake(ctx, mockEVM, &vm.Contract{CallerAddress: stakerAddr}, &stakeMethodID, argsStake) require.NoError(t, err) argsMoveStake := []interface{}{ @@ -908,7 +908,7 @@ func Test_MoveStake(t *testing.T) { t.Run("should fail if validator dest is invalid arg", func(t *testing.T) { // ARRANGE - ctx, contract, abi, sdkKeepers, _, _ := setup(t) + ctx, contract, abi, sdkKeepers, mockEVM, _ := setup(t) methodID := abi.Methods[MoveStakeMethodName] r := rand.New(rand.NewSource(42)) validatorSrc := sample.Validator(t, r) @@ -934,7 +934,7 @@ func Test_MoveStake(t *testing.T) { // stake to validator src stakeMethodID := abi.Methods[StakeMethodName] - _, err = contract.Stake(ctx, &vm.Contract{CallerAddress: stakerAddr}, &stakeMethodID, argsStake) + _, err = contract.Stake(ctx, mockEVM, &vm.Contract{CallerAddress: stakerAddr}, &stakeMethodID, argsStake) require.NoError(t, err) argsMoveStake := []interface{}{ @@ -953,7 +953,7 @@ func Test_MoveStake(t *testing.T) { t.Run("should fail if amount is invalid arg", func(t *testing.T) { // ARRANGE - ctx, contract, abi, sdkKeepers, _, _ := setup(t) + ctx, contract, abi, sdkKeepers, mockEVM, _ := setup(t) methodID := abi.Methods[MoveStakeMethodName] r := rand.New(rand.NewSource(42)) validatorSrc := sample.Validator(t, r) @@ -979,7 +979,7 @@ func Test_MoveStake(t *testing.T) { // stake to validator src stakeMethodID := abi.Methods[StakeMethodName] - _, err = contract.Stake(ctx, &vm.Contract{CallerAddress: stakerAddr}, &stakeMethodID, argsStake) + _, err = contract.Stake(ctx, mockEVM, &vm.Contract{CallerAddress: stakerAddr}, &stakeMethodID, argsStake) require.NoError(t, err) argsMoveStake := []interface{}{ @@ -998,7 +998,7 @@ func Test_MoveStake(t *testing.T) { t.Run("should fail if wrong args amount", func(t *testing.T) { // ARRANGE - ctx, contract, abi, sdkKeepers, _, _ := setup(t) + ctx, contract, abi, sdkKeepers, mockEVM, _ := setup(t) methodID := abi.Methods[MoveStakeMethodName] r := rand.New(rand.NewSource(42)) validatorSrc := sample.Validator(t, r) @@ -1024,7 +1024,7 @@ func Test_MoveStake(t *testing.T) { // stake to validator src stakeMethodID := abi.Methods[StakeMethodName] - _, err = contract.Stake(ctx, &vm.Contract{CallerAddress: stakerAddr}, &stakeMethodID, argsStake) + _, err = contract.Stake(ctx, mockEVM, &vm.Contract{CallerAddress: stakerAddr}, &stakeMethodID, argsStake) require.NoError(t, err) argsMoveStake := []interface{}{stakerEthAddr, validatorSrc.OperatorAddress, validatorDest.OperatorAddress} @@ -1152,7 +1152,7 @@ func Test_GetShares(t *testing.T) { stakeMethodID := abi.Methods[StakeMethodName] // ACT - _, err = contract.Stake(ctx, &vm.Contract{CallerAddress: stakerAddr}, &stakeMethodID, stakeArgs) + _, err = contract.Stake(ctx, mockEVM, &vm.Contract{CallerAddress: stakerAddr}, &stakeMethodID, stakeArgs) require.NoError(t, err) // ASSERT