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: add function to withdraw and check delegator rewards #3088

Merged
merged 24 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ func New(
&app.FungibleKeeper,
app.StakingKeeper,
app.BankKeeper,
app.DistrKeeper,
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 @@ -27,6 +27,7 @@
* [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
* [3020](https://github.com/zeta-chain/node/pull/3020) - add support for TON withdrawals
* [3088](https://github.com/zeta-chain/node/pull/3088) - add functions to check and withdraw delegator rewards
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved

### Refactor

Expand Down
12 changes: 11 additions & 1 deletion precompiles/precompiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdktypes "github.com/cosmos/cosmos-sdk/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
Expand All @@ -31,6 +32,7 @@ func StatefulContracts(
fungibleKeeper *fungiblekeeper.Keeper,
stakingKeeper *stakingkeeper.Keeper,
bankKeeper bankkeeper.Keeper,
distributionKeeper distrkeeper.Keeper,
fbac marked this conversation as resolved.
Show resolved Hide resolved
cdc codec.Codec,
gasConfig storetypes.GasConfig,
) (precompiledContracts []evmkeeper.CustomContractFn) {
Expand All @@ -50,7 +52,15 @@ func StatefulContracts(
// Define the staking contract function.
if EnabledStatefulContracts[staking.ContractAddress] {
stakingContract := func(ctx sdktypes.Context, _ ethparams.Rules) vm.PrecompiledContract {
return staking.NewIStakingContract(ctx, stakingKeeper, *fungibleKeeper, bankKeeper, cdc, gasConfig)
return staking.NewIStakingContract(
ctx,
stakingKeeper,
*fungibleKeeper,
bankKeeper,
distributionKeeper,
cdc,
gasConfig,
)
}

// Append the staking contract to the precompiledContracts slice.
Expand Down
9 changes: 8 additions & 1 deletion precompiles/precompiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ func Test_StatefulContracts(t *testing.T) {
}

// StatefulContracts() should return all the enabled contracts.
contracts := StatefulContracts(k, &sdkk.StakingKeeper, sdkk.BankKeeper, appCodec, gasConfig)
contracts := StatefulContracts(
k,
&sdkk.StakingKeeper,
sdkk.BankKeeper,
sdkk.DistributionKeeper,
appCodec,
gasConfig,
)
require.NotNil(t, contracts, "StatefulContracts() should not return a nil slice")
require.Len(t, contracts, expectedContracts, "StatefulContracts() should return all the enabled contracts")

Expand Down
104 changes: 104 additions & 0 deletions precompiles/staking/IStaking.abi
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "claim_address",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "zrc20_token",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "ClaimedRewards",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down Expand Up @@ -105,6 +130,30 @@
"name": "Unstake",
"type": "event"
},
{
"inputs": [
{
"internalType": "address",
"name": "delegator",
"type": "address"
},
{
"internalType": "string",
"name": "validator",
"type": "string"
}
],
"name": "claimRewards",
"outputs": [
{
"internalType": "bool",
"name": "success",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -164,6 +213,61 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "delegator",
"type": "address"
}
],
"name": "getDelegatorValidators",
"outputs": [
{
"internalType": "string[]",
"name": "validators",
"type": "string[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "delegator",
"type": "address"
},
{
"internalType": "string",
"name": "validator",
"type": "string"
}
],
"name": "getRewards",
"outputs": [
{
"components": [
{
"internalType": "string",
"name": "denom",
"type": "string"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"internalType": "struct DecCoin[]",
"name": "rewards",
"type": "tuple[]"
}
],
"stateMutability": "view",
"type": "function"
},
fbac marked this conversation as resolved.
Show resolved Hide resolved
{
"inputs": [
{
Expand Down
Loading
Loading