Skip to content

Commit

Permalink
distribution and staking precompile changes (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
dssei committed Aug 12, 2024
1 parent 11883c7 commit 35c62d0
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 59 deletions.
5 changes: 5 additions & 0 deletions .changeset/fair-emus-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sei-js/evm": minor
---

Adding new functions to distribution and staking precompiles
22 changes: 12 additions & 10 deletions packages/evm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,12 @@ The Distribution precompile contract facilitates operations related to rewards w

#### Functions

| Function Name | Input Parameters | Return Value | Description |
|--------------------------------------------------------------------------------------------------|------------------------------|------------------------|-----------------------------------------------------|
| [`setWithdrawAddress`](/sei-js/docs/interfaces/evm.DistributionPrecompileFunctions.html#setWithdrawAddress) | `withdrawAddress: ` `string` | `{ success: boolean }` | Sets the withdrawal address for rewards. |
| [`withdrawDelegationRewards`](/sei-js/docs/interfaces/evm.DistributionPrecompileFunctions.html#withdrawDelegationRewards) | `validator: ` `string` | `{ success: boolean }` | Withdraws delegation rewards for a given validator. |
| [`withdrawMultipleDelegationRewards`](/sei-js/docs/interfaces/evm.DistributionPrecompileFunctions.html#withdrawMultipleDelegationRewards) | `validators: ` `string[]` | `{ success: boolean }` | Withdraws delegation rewards for given validators. |
| Function Name | Input Parameters | Return Value | Description |
|-------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------|-----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`setWithdrawAddress`](/sei-js/docs/interfaces/evm.DistributionPrecompileFunctions.html#setWithdrawAddress) | `withdrawAddress: ` `string` | `{ success: boolean }` | Sets the withdrawal address for rewards. |
| [`withdrawDelegationRewards`](/sei-js/docs/interfaces/evm.DistributionPrecompileFunctions.html#withdrawDelegationRewards) | `validator: ` `string` | `{ success: boolean }` | Withdraws delegation rewards for a given validator. |
| [`withdrawMultipleDelegationRewards`](/sei-js/docs/interfaces/evm.DistributionPrecompileFunctions.html#withdrawMultipleDelegationRewards) | `validators: ` `string[]` | `{ success: boolean }` | Withdraws delegation rewards for given validators. |
| [`rewards`](/sei-js/docs/interfaces/evm.DistributionPrecompileFunctions.html#rewards) | `delegatorAddress: ` `address` | `{ rewards: Rewards }` | Queries rewards available for a given delegator address. Rewards are usually returned as decimals. To calculate the actual amount, divide the amount by decimals. |

#### Precompile Addresses
0x0000000000000000000000000000000000001007
Expand Down Expand Up @@ -196,11 +197,12 @@ The Staking precompile contract provides functions for delegation, re-delegation

#### Functions

| Function Name | Input Parameters | Return Value | Description |
|----------------------------------------------------------------------------------------|-----------------------------------------------------------------------|------------------------|----------------------------------------------------------------------------|
| [`delegate`](/sei-js/docs/interfaces/evm.StakingPrecompileFunctions.html#delegate) | `valAddress: ` `string` | `{ success: boolean }` | Delegates tokens to the specified validator. |
| [`redelegate`](/sei-js/docs/interfaces/evm.StakingPrecompileFunctions.html#redelegate) | `srcAddress: ` `string`, `dstAddress: ` `string`, `amount: ` `string` | `{ success: boolean }` | Redelegates tokens from the source validator to the destination validator. |
| [`undelegate`](/sei-js/docs/interfaces/evm.StakingPrecompileFunctions.html#undelegate) | `valAddress: ` `string`, `amount: ` `string` | `{ success: boolean }` | Undelegates tokens from the specified validator. |
| Function Name | Input Parameters | Return Value | Description |
|----------------------------------------------------------------------------------------|-----------------------------------------------------------------------|------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`delegate`](/sei-js/docs/interfaces/evm.StakingPrecompileFunctions.html#delegate) | `valAddress: ` `string` | `{ success: boolean }` | Delegates tokens to the specified validator. |
| [`redelegate`](/sei-js/docs/interfaces/evm.StakingPrecompileFunctions.html#redelegate) | `srcAddress: ` `string`, `dstAddress: ` `string`, `amount: ` `string` | `{ success: boolean }` | Redelegates tokens from the source validator to the destination validator. |
| [`undelegate`](/sei-js/docs/interfaces/evm.StakingPrecompileFunctions.html#undelegate) | `valAddress: ` `string`, `amount: ` `string` | `{ success: boolean }` | Undelegates tokens from the specified validator. |
| [`delegation`](/sei-js/docs/interfaces/evm.StakingPrecompileFunctions.html#delegation) | `delegator`: `address`, `valAddress: ` `string` | `{ delegation: Delegation }` | Queries delegation by delegator and validator address. Shares in DelegationDetails are usually returned as decimals. To calculate the actual amount, divide the shares by decimals. |

#### Precompile Addresses
0x0000000000000000000000000000000000001005
Expand Down
77 changes: 56 additions & 21 deletions packages/evm/src/precompiles/distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,60 @@ export const DISTRIBUTION_PRECOMPILE_ADDRESS: `0x${string}` = '0x000000000000000
* @category Cosmos Interoperability
*/
export const DISTRIBUTION_PRECOMPILE_ABI = [
{
inputs: [{ internalType: 'address', name: 'withdrawAddr', type: 'address' }],
name: 'setWithdrawAddress',
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
stateMutability: 'nonpayable',
type: 'function'
},
{
inputs: [{ internalType: 'string', name: 'validator', type: 'string' }],
name: 'withdrawDelegationRewards',
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
stateMutability: 'nonpayable',
type: 'function'
},
{
inputs: [{ internalType: 'string[]', name: 'validators', type: 'string[]' }],
name: 'withdrawMultipleDelegationRewards',
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
stateMutability: 'nonpayable',
type: 'function'
}
{
inputs: [{ internalType: 'address', name: 'withdrawAddr', type: 'address' }],
name: 'setWithdrawAddress',
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
stateMutability: 'nonpayable',
type: 'function'
},
{
inputs: [{ internalType: 'string', name: 'validator', type: 'string' }],
name: 'withdrawDelegationRewards',
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
stateMutability: 'nonpayable',
type: 'function'
},
{
inputs: [{ internalType: 'string[]', name: 'validators', type: 'string[]' }],
name: 'withdrawMultipleDelegationRewards',
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
stateMutability: 'nonpayable',
type: 'function'
},
{
inputs: [{ internalType: 'address', name: 'delegatorAddress', type: 'address' }],
name: 'rewards',
outputs: [
{
components: [
{
components: [
{
components: [
{ internalType: 'uint256', name: 'amount', type: 'uint256' },
{ internalType: 'uint256', name: 'decimals', type: 'uint256' },
{ internalType: 'string', name: 'denom', type: 'string' }
],
internalType: 'struct Coin[]', name: 'coins', type: 'tuple[]'
},
{ internalType: 'string', name: 'validator_address', type: 'string' }
],
internalType: 'struct Reward[]', name: 'rewards', type: 'tuple[]'
},
{
components: [
{ internalType: 'uint256', name: 'amount', type: 'uint256' },
{ internalType: 'uint256', name: 'decimals', type: 'uint256' },
{ internalType: 'string', name: 'denom', type: 'string' }
],
internalType: 'struct Coin[]', name: 'total', type: 'tuple[]'
}
],
internalType: 'struct Rewards', name: 'rewards', type: 'tuple'
}
],
stateMutability: 'view',
type: 'function'
}
] as const;
88 changes: 60 additions & 28 deletions packages/evm/src/precompiles/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,64 @@ export const STAKING_PRECOMPILE_ADDRESS: `0x${string}` = '0x00000000000000000000
* @category Cosmos Interoperability
*/
export const STAKING_PRECOMPILE_ABI = [
{
inputs: [{ internalType: 'string', name: 'valAddress', type: 'string' }],
name: 'delegate',
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
stateMutability: 'payable',
type: 'function'
},
{
inputs: [
{ internalType: 'string', name: 'srcAddress', type: 'string' },
{ internalType: 'string', name: 'dstAddress', type: 'string' },
{ internalType: 'uint256', name: 'amount', type: 'uint256' }
],
name: 'redelegate',
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
stateMutability: 'nonpayable',
type: 'function'
},
{
inputs: [
{ internalType: 'string', name: 'valAddress', type: 'string' },
{ internalType: 'uint256', name: 'amount', type: 'uint256' }
],
name: 'undelegate',
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
stateMutability: 'nonpayable',
type: 'function'
}
{
inputs: [{ internalType: 'string', name: 'valAddress', type: 'string' }],
name: 'delegate',
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
stateMutability: 'payable',
type: 'function'
},
{
inputs: [
{ internalType: 'string', name: 'srcAddress', type: 'string' },
{ internalType: 'string', name: 'dstAddress', type: 'string' },
{ internalType: 'uint256', name: 'amount', type: 'uint256' }
],
name: 'redelegate',
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
stateMutability: 'nonpayable',
type: 'function'
},
{
inputs: [
{ internalType: 'string', name: 'valAddress', type: 'string' },
{ internalType: 'uint256', name: 'amount', type: 'uint256' }
],
name: 'undelegate',
outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
stateMutability: 'nonpayable',
type: 'function'
},
{
inputs: [
{ internalType: 'address', name: 'delegator', type: 'address' },
{ internalType: 'string', name: 'valAddress', type: 'string' }
],
name: 'delegation',
outputs: [
{
components: [
{
components: [
{ internalType: 'uint256', name: 'amount', type: 'uint256' },
{ internalType: 'string', name: 'denom', type: 'string' }
],
internalType: 'struct Balance', name: 'balance', type: 'tuple'
},
{
components: [
{ internalType: 'string', name: 'delegator_address', type: 'string' },
{ internalType: 'uint256', name: 'shares', type: 'uint256' },
{ internalType: 'uint256', name: 'decimals', type: 'uint256' },
{ internalType: 'string', name: 'validator_address', type: 'string' }
],
internalType: 'struct DelegationDetails', name: 'delegation', type: 'tuple'
}
],
internalType: 'struct Delegation', name: 'delegation', type: 'tuple'
}
],
stateMutability: 'view',
type: 'function'
}
] as const;

0 comments on commit 35c62d0

Please sign in to comment.