Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: bank precompile #2860

Merged
merged 43 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d06485f
feat: bank precompile
fbac Sep 10, 2024
969d2d2
feat: add deposit
fbac Sep 11, 2024
71aa8d5
feat: extend deposit
fbac Sep 11, 2024
322618b
PoC: spend amount on behalf of EOA
fbac Sep 11, 2024
7e85925
feat: expand deposit with transferFrom
fbac Sep 11, 2024
5fe30cf
use CallEVM instead on ZRC20 bindings
fbac Sep 11, 2024
f69c695
divide the contract into different files
fbac Sep 11, 2024
5863536
initialize e2e testing
fbac Sep 11, 2024
12a5138
remove duplicated funding
fbac Sep 11, 2024
a4be05e
add codecov
fbac Sep 11, 2024
75efde6
expand e2e
fbac Sep 11, 2024
6340abb
fix: wait for deposit tx to be mined
fbac Sep 11, 2024
0f347f2
apply first round of reviews
fbac Sep 12, 2024
e0fa24a
cover al error types test
fbac Sep 12, 2024
cf17671
fixes using time.Since
fbac Sep 12, 2024
02ddce3
Include CallContract interface
fbac Sep 12, 2024
c1836a3
fix eth events in deposit precompile method
skosito Sep 16, 2024
8503dc8
emit Deposit event
fbac Sep 16, 2024
6a19fb0
add withdraw function
fbac Sep 17, 2024
e7ddcb0
finalize withdraw
fbac Sep 17, 2024
f1e5b3a
pack event arguments generically
fbac Sep 17, 2024
05d0bfb
add high level event function
fbac Sep 17, 2024
0fa8d50
first round of review fixes
fbac Sep 17, 2024
b6b78a9
second round of reviews
fbac Sep 18, 2024
6271e7a
create bank account when instantiating bank
fbac Sep 18, 2024
1a4f553
e2e: add good and bad scenarios
fbac Sep 19, 2024
6caabef
Merge branch 'develop' into feat/bank-precompile
Sep 19, 2024
9ed6bfb
modify fmt
fbac Sep 19, 2024
b8094e2
chore: group input into eventData struct
fbac Sep 19, 2024
a7533eb
docs: document bank's methods
fbac Sep 19, 2024
67ad4fa
chore: generate files with suffix .gen.go
fbac Sep 20, 2024
82f5204
chore: assert errors with errorIs
fbac Sep 20, 2024
4d0a57b
chore: reset e2e test by resetting allowance
fbac Sep 20, 2024
c9bf427
test: add first batch of unit test
fbac Sep 21, 2024
84e7b9e
test: cover all cases
fbac Sep 23, 2024
dbec3ca
test: complete unit test cases
fbac Sep 23, 2024
af858ab
include review suggestions
fbac Sep 23, 2024
b18c50d
include e2e through contract
fbac Sep 24, 2024
35013e3
test: add e2e through contract complete
fbac Sep 25, 2024
de990fa
test: revert balance between tests
fbac Sep 25, 2024
f74194a
Merge branch 'develop' into feat/bank-precompile
Sep 25, 2024
b532de2
Update precompiles/bank/const.go
Sep 25, 2024
eeff21c
fix: changed coin denom
fbac Sep 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile-localnet
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ EXPOSE 22
FROM base-runtime AS latest-runtime

COPY --from=cosmovisor-build /go/bin/cosmovisor /usr/local/bin
COPY --from=latest-build /go/bin/zetacored /go/bin/zetaclientd /go/bin/zetaclientd-supervisor /go/bin/zetae2e /usr/local/bin
COPY --from=latest-build /go/bin/zetacored /go/bin/zetaclientd /go/bin/zetaclientd-supervisor /go/bin/zetae2e /usr/local/bin/
fbac marked this conversation as resolved.
Show resolved Hide resolved

# Optional old version build (from source). This old build is used as the genesis version in the upgrade tests.
# Use --target latest-runtime to skip.
Expand All @@ -75,7 +75,7 @@ RUN cd node && make install
FROM base-runtime AS old-runtime-source

COPY --from=cosmovisor-build /go/bin/cosmovisor /usr/local/bin
COPY --from=old-build-source /go/bin/zetacored /go/bin/zetaclientd /usr/local/bin
COPY --from=old-build-source /go/bin/zetacored /go/bin/zetaclientd /usr/local/bin/
COPY --from=latest-build /go/bin/zetaclientd-supervisor /usr/local/bin

# Optional old version build (from binary).
Expand Down
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ func New(
precompiles.StatefulContracts(
&app.FungibleKeeper,
app.StakingKeeper,
app.BankKeeper,
appCodec,
storetypes.TransientGasConfig(),
),
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* [2784](https://github.com/zeta-chain/node/pull/2784) - staking precompiled contract
* [2795](https://github.com/zeta-chain/node/pull/2795) - support restricted address in Solana
* [2861](https://github.com/zeta-chain/node/pull/2861) - emit events from staking precompile
* [2860](https://github.com/zeta-chain/node/pull/2860) - bank precompiled contract
* [2870](https://github.com/zeta-chain/node/pull/2870) - support for multiple Bitcoin chains in the zetaclient
* [2883](https://github.com/zeta-chain/node/pull/2883) - add chain static information for btc signet testnet
* [2907](https://github.com/zeta-chain/node/pull/2907) - derive Bitcoin tss address by chain id and added more Signet static info
Expand Down
3 changes: 3 additions & 0 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
e2etests.TestPrecompilesPrototypeThroughContractName,
e2etests.TestPrecompilesStakingName,
e2etests.TestPrecompilesStakingThroughContractName,
e2etests.TestPrecompilesBankName,
e2etests.TestPrecompilesBankFailName,
lumtis marked this conversation as resolved.
Show resolved Hide resolved
e2etests.TestPrecompilesBankThroughContractName,
}
}

Expand Down
4 changes: 4 additions & 0 deletions cmd/zetae2e/local/precompiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func statefulPrecompilesTestRoutine(
precompileRunner.Logger.Print("🏃 starting stateful precompiled contracts tests")
startTime := time.Now()

// Send ERC20 that will be depositted into ERC20ZRC20 tokens.
txERC20Send := deployerRunner.SendERC20OnEvm(account.EVMAddress(), 10000)
precompileRunner.WaitForTxReceiptOnEvm(txERC20Send)

testsToRun, err := precompileRunner.GetE2ETestsToRunByName(
e2etests.AllE2ETests,
testNames...,
Expand Down
3 changes: 1 addition & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,4 @@ ignore:
- "precompiles/**/*.abi"
- "precompiles/**/*.json"
- "precompiles/**/*.sol"
- "precompiles/prototype/IPrototype.go"
- "precompiles/staking/IStaking.go"
- "precompiles/**/*.gen.go"
12 changes: 1 addition & 11 deletions contrib/localnet/orchestrator/start-zetae2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fund_eth_from_config '.additional_accounts.user_admin.evm_address' 10000 "admin
fund_eth_from_config '.additional_accounts.user_migration.evm_address' 10000 "migration tester"

# unlock precompile tests accounts
fund_eth_from_config '.additional_accounts.user_precompile.evm_address' 10000 "precompile tester"
fund_eth_from_config '.additional_accounts.user_precompile.evm_address' 10000 "precompiles tester"
fbac marked this conversation as resolved.
Show resolved Hide resolved

# unlock v2 ethers tests accounts
fund_eth_from_config '.additional_accounts.user_v2_ether.evm_address' 10000 "V2 ethers tester"
Expand All @@ -131,16 +131,6 @@ fund_eth_from_config '.additional_accounts.user_v2_ether_revert.evm_address' 100
# unlock v2 erc20 revert tests accounts
fund_eth_from_config '.additional_accounts.user_v2_erc20_revert.evm_address' 10000 "V2 ERC20 revert tester"

# unlock precompile tests accounts
address=$(yq -r '.additional_accounts.user_precompile.evm_address' config.yml)
echo "funding precompile tester address ${address} with 10000 Ether"
geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 > /dev/null

# unlock precompile tests accounts
address=$(yq -r '.additional_accounts.user_precompile.evm_address' config.yml)
echo "funding precompile tester address ${address} with 10000 Ether"
geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 > /dev/null

# unlock local solana relayer accounts
if host solana > /dev/null; then
solana_url=$(config_str '.rpcs.solana')
Expand Down
87 changes: 87 additions & 0 deletions e2e/contracts/testbank/TestBank.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
[
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"stateMutability": "payable",
"type": "fallback"
},
{
"inputs": [
{
"internalType": "address",
"name": "zrc20",
"type": "address"
},
{
"internalType": "address",
"name": "user",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "zrc20",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "deposit",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "zrc20",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "withdraw",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"stateMutability": "payable",
"type": "receive"
}
]
1 change: 1 addition & 0 deletions e2e/contracts/testbank/TestBank.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
60a060405260676000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555034801561005157600080fd5b503373ffffffffffffffffffffffffffffffffffffffff1660808173ffffffffffffffffffffffffffffffffffffffff16815250506080516106a16100ae6000396000818160fc015281816101fc01526102fc01526106a16000f3fe6080604052600436106100385760003560e01c806347e7ef2414610041578063f3fef3a31461007e578063f7888aec146100bb5761003f565b3661003f57005b005b34801561004d57600080fd5b506100686004803603810190610063919061048f565b6100f8565b60405161007591906104ea565b60405180910390f35b34801561008a57600080fd5b506100a560048036038101906100a0919061048f565b6101f8565b6040516100b291906104ea565b60405180910390f35b3480156100c757600080fd5b506100e260048036038101906100dd9190610505565b6102f8565b6040516100ef9190610554565b60405180910390f35b60007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461015257600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166347e7ef2484846040518363ffffffff1660e01b81526004016101ad92919061057e565b6020604051808303816000875af11580156101cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101f091906105d3565b905092915050565b60007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461025257600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f3fef3a384846040518363ffffffff1660e01b81526004016102ad92919061057e565b6020604051808303816000875af11580156102cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102f091906105d3565b905092915050565b60007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461035257600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f7888aec84846040518363ffffffff1660e01b81526004016103ad929190610600565b602060405180830381865afa1580156103ca573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103ee919061063e565b905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610426826103fb565b9050919050565b6104368161041b565b811461044157600080fd5b50565b6000813590506104538161042d565b92915050565b6000819050919050565b61046c81610459565b811461047757600080fd5b50565b60008135905061048981610463565b92915050565b600080604083850312156104a6576104a56103f6565b5b60006104b485828601610444565b92505060206104c58582860161047a565b9150509250929050565b60008115159050919050565b6104e4816104cf565b82525050565b60006020820190506104ff60008301846104db565b92915050565b6000806040838503121561051c5761051b6103f6565b5b600061052a85828601610444565b925050602061053b85828601610444565b9150509250929050565b61054e81610459565b82525050565b60006020820190506105696000830184610545565b92915050565b6105788161041b565b82525050565b6000604082019050610593600083018561056f565b6105a06020830184610545565b9392505050565b6105b0816104cf565b81146105bb57600080fd5b50565b6000815190506105cd816105a7565b92915050565b6000602082840312156105e9576105e86103f6565b5b60006105f7848285016105be565b91505092915050565b6000604082019050610615600083018561056f565b610622602083018461056f565b9392505050565b60008151905061063881610463565b92915050565b600060208284031215610654576106536103f6565b5b600061066284828501610629565b9150509291505056fea2646970667358221220c0c585590967d576c91dec72feb553b8a6186d045ddc558ecc1de043c068bcb764736f6c634300080a0033
Loading
Loading