Skip to content

Commit

Permalink
feat: distribute ZRC20 rewards function (#3019)
Browse files Browse the repository at this point in the history
* feat: distribute ZRC20 rewards function

* add unit testing first batch

* fix should return empty array if validators not set unit test

* migrate to new test suite

* remove function depending on staking precompile

* commit last unit test changes

* add e2e base

* add distribution query client to e2e

* e2e: finish disitribute tests

* fix event name typo

* Update precompiles/types/coin.go

Co-authored-by: Tanmay <[email protected]>

* first batch of reviews

* apply reviews

* add nonZRC20 token e2e test

* add fee collector balance check

* check for err while DepositZRC20

* fix CI

* fix gosec

* modify CreateCoinSet to accept a common.Address

* fix lint

---------

Co-authored-by: Tanmay <[email protected]>
Co-authored-by: Tanmay <[email protected]>
  • Loading branch information
3 people authored Oct 30, 2024
1 parent df8b0e8 commit 60f0f1a
Show file tree
Hide file tree
Showing 51 changed files with 4,070 additions and 1,803 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* [3012](https://github.com/zeta-chain/node/pull/3012) - integrate authenticated calls erc20 smart contract functionality into protocol
* [3025](https://github.com/zeta-chain/node/pull/3025) - standard memo for Bitcoin inbound
* [3028](https://github.com/zeta-chain/node/pull/3028) - whitelist connection gater
* [3019](https://github.com/zeta-chain/node/pull/3019) - add ditribute functions to staking precompile

### Refactor

Expand Down
3 changes: 3 additions & 0 deletions cmd/zetacored/config/prefixes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const (
// Bech32Prefix defines the Bech32 prefix used for Cronos Accounts
Bech32Prefix = "zeta"

// ZRC20DenomPrefix defines the prefix for ZRC20 tokens when converted to sdk.Coin.
ZRC20DenomPrefix = "zrc20/"

// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address
Bech32PrefixAccAddr = Bech32Prefix
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key
Expand Down
19 changes: 11 additions & 8 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,17 @@ func localE2ETest(cmd *cobra.Command, _ []string) {

if !skipPrecompiles {
precompiledContractTests = []string{
e2etests.TestPrecompilesPrototypeName,
e2etests.TestPrecompilesPrototypeThroughContractName,
e2etests.TestPrecompilesStakingName,
// Disabled until further notice, check https://github.com/zeta-chain/node/issues/3005.
// e2etests.TestPrecompilesStakingThroughContractName,
e2etests.TestPrecompilesBankName,
e2etests.TestPrecompilesBankFailName,
e2etests.TestPrecompilesBankThroughContractName,
// e2etests.TestPrecompilesPrototypeName,
// e2etests.TestPrecompilesPrototypeThroughContractName,
// e2etests.TestPrecompilesStakingName,
// // Disabled until further notice, check https://github.com/zeta-chain/node/issues/3005.
// // e2etests.TestPrecompilesStakingThroughContractName,
// e2etests.TestPrecompilesBankName,
// e2etests.TestPrecompilesBankFailName,
// e2etests.TestPrecompilesBankThroughContractName,
e2etests.TestPrecompilesDistributeName,
e2etests.TestPrecompilesDistributeNonZRC20Name,
e2etests.TestPrecompilesDistributeThroughContractName,
}
}

Expand Down
64 changes: 64 additions & 0 deletions e2e/contracts/testdistribute/TestDistribute.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "zrc20_distributor",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "zrc20_token",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "Distributed",
"type": "event"
},
{
"stateMutability": "payable",
"type": "fallback"
},
{
"inputs": [
{
"internalType": "address",
"name": "zrc20",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "distributeThroughContract",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"stateMutability": "payable",
"type": "receive"
}
]
1 change: 1 addition & 0 deletions e2e/contracts/testdistribute/TestDistribute.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
60a060405260666000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555034801561005157600080fd5b503373ffffffffffffffffffffffffffffffffffffffff1660808173ffffffffffffffffffffffffffffffffffffffff168152505060805161034d6100a06000396000606c015261034d6000f3fe6080604052600436106100225760003560e01c806350b54e841461002b57610029565b3661002957005b005b34801561003757600080fd5b50610052600480360381019061004d9190610201565b610068565b60405161005f919061025c565b60405180910390f35b60007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146100c257600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663fb93210884846040518363ffffffff1660e01b815260040161011d929190610295565b6020604051808303816000875af115801561013c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061016091906102ea565b905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006101988261016d565b9050919050565b6101a88161018d565b81146101b357600080fd5b50565b6000813590506101c58161019f565b92915050565b6000819050919050565b6101de816101cb565b81146101e957600080fd5b50565b6000813590506101fb816101d5565b92915050565b6000806040838503121561021857610217610168565b5b6000610226858286016101b6565b9250506020610237858286016101ec565b9150509250929050565b60008115159050919050565b61025681610241565b82525050565b6000602082019050610271600083018461024d565b92915050565b6102808161018d565b82525050565b61028f816101cb565b82525050565b60006040820190506102aa6000830185610277565b6102b76020830184610286565b9392505050565b6102c781610241565b81146102d257600080fd5b50565b6000815190506102e4816102be565b92915050565b600060208284031215610300576102ff610168565b5b600061030e848285016102d5565b9150509291505056fea26469706673582212205443ec313ecb8c2e08ca8a30687daed4c3b666f9318ae72ccbe9033479c8b8be64736f6c634300080a0033
Loading

0 comments on commit 60f0f1a

Please sign in to comment.