From 2d6325e7184f33bf99d728edc243e43c86fcc642 Mon Sep 17 00:00:00 2001 From: hanchon Date: Sun, 29 May 2022 18:07:15 +0200 Subject: [PATCH 1/2] feat: (wip)withdrawValidatorCommission message --- packages/eip712/src/messages/staking.ts | 20 ++++++ packages/proto/src/messages/staking.ts | 17 +++++ packages/transactions/src/messages/staking.ts | 62 +++++++++++++++++++ 3 files changed, 99 insertions(+) diff --git a/packages/eip712/src/messages/staking.ts b/packages/eip712/src/messages/staking.ts index 308064e6..b52d90f0 100644 --- a/packages/eip712/src/messages/staking.ts +++ b/packages/eip712/src/messages/staking.ts @@ -118,3 +118,23 @@ export function createMsgWithdrawDelegatorReward( }, } } + +export const MSG_WITHDRAW_VALIDATOR_COMMISSION_TYPES = { + MsgValue: [{ name: 'validator_address', type: 'string' }], +} + +export interface MsgWithdrawValidatorCommissionInterface { + type: string + value: { + validator_address: string + } +} + +export function createMsgWithdrawValidatorCommission(validatorAddress: string) { + return { + type: 'cosmos-sdk/MsgWithdrawValidatorCommission', + value: { + validator_address: validatorAddress, + }, + } +} diff --git a/packages/proto/src/messages/staking.ts b/packages/proto/src/messages/staking.ts index 8db8b409..12363a57 100644 --- a/packages/proto/src/messages/staking.ts +++ b/packages/proto/src/messages/staking.ts @@ -93,3 +93,20 @@ export function createMsgWithdrawDelegatorReward( path: 'cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward', } } + +export interface MsgWithdrawValidatorCommissionProtoInterface { + path: string + message: dist.cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission +} + +export function createMsgWithdrawValidatorCommission(validatorAddress: string) { + const message = + new dist.cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission({ + validator_address: validatorAddress, + }) + + return { + message, + path: 'cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission', + } +} diff --git a/packages/transactions/src/messages/staking.ts b/packages/transactions/src/messages/staking.ts index eefac9e9..de62c6f3 100644 --- a/packages/transactions/src/messages/staking.ts +++ b/packages/transactions/src/messages/staking.ts @@ -3,6 +3,7 @@ import { createMsgDelegate as protoMsgDelegate, createMsgUndelegate as protoMsgUndelegate, createMsgWithdrawDelegatorReward as protoeMsgWithdrawDelegatorReward, + createMsgWithdrawValidatorCommission as protoMsgWithdrawValidatorCommission, MsgWithdrawDelegatorRewardProtoInterface, createTransaction, createTransactionWithMultipleMessages, @@ -23,6 +24,9 @@ import { MSG_WITHDRAW_DELEGATOR_REWARD_TYPES, createMsgWithdrawDelegatorReward, MsgWithdrawDelegatorRewardInterface, + MSG_WITHDRAW_VALIDATOR_COMMISSION_TYPES, + createMsgWithdrawValidatorCommission, + MsgWithdrawValidatorCommissionInterface, } from '@tharsis/eip712' import { Chain, Fee, Sender } from './common' @@ -344,3 +348,61 @@ export function createTxMsgMultipleWithdrawDelegatorReward( eipToSign, } } + +export interface MsgWithdrawValidatorCommissionParams { + validatorAddress: string +} + +export function createTxMsgWithdrawValidatorCommission( + chain: Chain, + sender: Sender, + fee: Fee, + memo: string, + params: MsgWithdrawValidatorCommissionParams, +) { + // EIP712 + const feeObject = generateFee( + fee.amount, + fee.denom, + fee.gas, + sender.accountAddress, + ) + const types = generateTypes(MSG_WITHDRAW_VALIDATOR_COMMISSION_TYPES) + const msg = createMsgWithdrawValidatorCommission( + sender.accountAddress, + params.validatorAddress, + ) + const messages = generateMessage( + sender.accountNumber.toString(), + sender.sequence.toString(), + chain.cosmosChainId, + memo, + feeObject, + msg, + ) + const eipToSign = createEIP712(types, chain.chainId, messages) + + // Cosmos + const protoMessage = protoMsgWithdrawValidatorCommission( + sender.accountAddress, + params.validatorAddress, + ) + const tx = createTransaction( + protoMessage, + memo, + fee.amount, + fee.denom, + parseInt(fee.gas, 10), + 'ethsecp256', + sender.pubkey, + sender.sequence, + sender.accountNumber, + chain.cosmosChainId, + ) + + return { + signDirect: tx.signDirect, + legacyAmino: tx.legacyAmino, + eipToSign, + } +} From dc13e85be6edd56cd5c47d5e32c6d547bef308c2 Mon Sep 17 00:00:00 2001 From: hanchon Date: Sun, 29 May 2022 23:02:05 +0200 Subject: [PATCH 2/2] fix: send the correct params --- packages/transactions/src/messages/staking.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/transactions/src/messages/staking.ts b/packages/transactions/src/messages/staking.ts index de62c6f3..616dafdf 100644 --- a/packages/transactions/src/messages/staking.ts +++ b/packages/transactions/src/messages/staking.ts @@ -26,7 +26,6 @@ import { MsgWithdrawDelegatorRewardInterface, MSG_WITHDRAW_VALIDATOR_COMMISSION_TYPES, createMsgWithdrawValidatorCommission, - MsgWithdrawValidatorCommissionInterface, } from '@tharsis/eip712' import { Chain, Fee, Sender } from './common' @@ -368,10 +367,7 @@ export function createTxMsgWithdrawValidatorCommission( sender.accountAddress, ) const types = generateTypes(MSG_WITHDRAW_VALIDATOR_COMMISSION_TYPES) - const msg = createMsgWithdrawValidatorCommission( - sender.accountAddress, - params.validatorAddress, - ) + const msg = createMsgWithdrawValidatorCommission(params.validatorAddress) const messages = generateMessage( sender.accountNumber.toString(), sender.sequence.toString(), @@ -384,7 +380,6 @@ export function createTxMsgWithdrawValidatorCommission( // Cosmos const protoMessage = protoMsgWithdrawValidatorCommission( - sender.accountAddress, params.validatorAddress, ) const tx = createTransaction(