-
Notifications
You must be signed in to change notification settings - Fork 173
feat: implement MsgMigrateERC20CustodyFunds to migrate the funds from the ERC20Custody to a new contracts
#2630
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
2a026cd
refactor cmd cctx creation
lumtis 45f5a1d
initialize migrate funds message
lumtis fb389f8
implement migrate message
lumtis c4462a1
zetaclient implementation
lumtis d00a1db
fix event
lumtis 497ff84
fix params
lumtis e30a31c
add e2e test
lumtis fc28be0
generate
lumtis 3db77d2
changelog
lumtis a7253be
zetaclient test
lumtis 3d6e11e
fix message test
lumtis 9128af7
initialize cctx test
lumtis 7c2a29e
cmd cctx type tests
lumtis eba8c00
message test
lumtis e93d861
conflicts
lumtis 719d44e
Update zetaclient/chains/evm/signer/admin_cmd.go
lumtis 8d08528
tanmay comments
lumtis 4a1d9ed
stefan comments
lumtis c6898fd
admin commands
lumtis bad8fb6
changelogs
lumtis 5f2bb5f
make generate
lumtis 0aaba69
conflicts
lumtis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package e2etests | ||
|
|
||
| import ( | ||
| sdkmath "cosmossdk.io/math" | ||
| "github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/zeta-chain/zetacore/e2e/runner" | ||
| "github.com/zeta-chain/zetacore/e2e/txserver" | ||
| "github.com/zeta-chain/zetacore/e2e/utils" | ||
| "github.com/zeta-chain/zetacore/testutil/sample" | ||
| crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" | ||
| ) | ||
|
|
||
| // TestMigrateERC20CustodyFunds tests the migration of ERC20 custody funds | ||
| func TestMigrateERC20CustodyFunds(r *runner.E2ERunner, _ []string) { | ||
| // get erc20 balance on ERC20 custody contract | ||
| balance, err := r.ERC20.BalanceOf(&bind.CallOpts{}, r.ERC20CustodyAddr) | ||
| require.NoError(r, err) | ||
|
|
||
| // get EVM chain ID | ||
| chainID, err := r.EVMClient.ChainID(r.Ctx) | ||
| require.NoError(r, err) | ||
|
|
||
| newAddr := sample.EthAddress() | ||
|
|
||
| // send MigrateERC20CustodyFunds command | ||
| // NOTE: we currently use a random address for the destination as a sufficient way to check migration | ||
| // TODO: makes the test more complete and perform a withdraw to new custody once the contract V2 architecture is integrated | ||
| // https://github.com/zeta-chain/node/issues/2474 | ||
| msg := crosschaintypes.NewMsgMigrateERC20CustodyFunds( | ||
| r.ZetaTxServer.MustGetAccountAddressFromName(utils.AdminPolicyName), | ||
| chainID.Int64(), | ||
| newAddr.Hex(), | ||
| r.ERC20Addr.Hex(), | ||
| sdkmath.NewUintFromBigInt(balance), | ||
| ) | ||
| res, err := r.ZetaTxServer.BroadcastTx(utils.AdminPolicyName, msg) | ||
| require.NoError(r, err) | ||
|
|
||
| // fetch cctx index from tx response | ||
| cctxIndex, err := txserver.FetchAttributeFromTxResponse(res, "cctx_index") | ||
| require.NoError(r, err) | ||
|
|
||
| cctxRes, err := r.CctxClient.Cctx(r.Ctx, &crosschaintypes.QueryGetCctxRequest{Index: cctxIndex}) | ||
| require.NoError(r, err) | ||
|
|
||
| cctx := cctxRes.CrossChainTx | ||
| r.Logger.CCTX(*cctx, "migration") | ||
|
|
||
| // wait for the cctx to be mined | ||
| r.WaitForMinedCCTXFromIndex(cctxIndex) | ||
|
|
||
| // check ERC20 balance on new address | ||
| newAddrBalance, err := r.ERC20.BalanceOf(&bind.CallOpts{}, newAddr) | ||
| require.NoError(r, err) | ||
| require.Equal(r, balance, newAddrBalance) | ||
|
|
||
| // artificially set the ERC20 Custody address to the new address to prevent accounting check from failing | ||
lumtis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| r.ERC20CustodyAddr = newAddr | ||
| } | ||
lumtis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.