Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Refactor Transactions Revenue #120

Merged
merged 7 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ Ref: https://keepachangelog.com/en/1.0.0/
- (transactions)[#117](https://github.com/evmos/evmosjs/pull/117) Refactor Transactions `ERC-20` module using base infrastructure and add unit tests
- (transactions)[#118](https://github.com/evmos/evmosjs/pull/118) Refactor Transactions `Gov` module using base infrastructure and add unit tests
- (transactions)[#119](https://github.com/evmos/evmosjs/pull/119) Refactor Transactions `IBC` module using base infrastructure and add unit tests
- (transactions)[#120](https://github.com/evmos/evmosjs/pull/120) Refactor Transactions `Revenue` module using base infrastructure and add unit tests
86 changes: 86 additions & 0 deletions docs/transactions/revenue/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Revenue

This package creates transaction payloads with messages from the [Revenue Module](https://docs.evmos.org/modules/revenue/).

Find the `TxContext` and `TxPayload` types in the Transaction Docs.

### MsgCancelRevenue

```ts
export interface MsgCancelRevenueParams {
contractAddress: string
deployerAddress: string
}

/**
* Creates a transaction for a `MsgCancelRevenue` object.
*
* @remarks
* This method creates a transaction wrapping the Evmos
* {@link https://docs.evmos.org/modules/revenue/04_transactions.html#msgcancelrevenue | MsgCancelRevenue}
*
* @param context - Transaction Context
* @param params - MsgCancelRevenue Params
* @returns Transaction with the MsgCancelRevenue payload
*
*/
export const createTxMsgCancelRevenue: (
context: TxContext,
params: MsgCancelRevenueParams,
): TxPayload
```

### MsgRegisterRevenue

```ts
export interface MsgRegisterRevenueParams {
contractAddress: string
deployerAddress: string
withdrawerAddress: string
nonces: number[]
}

/**
* Creates a transaction for a `MsgRegisterRevenue` object.
*
* @remarks
* This method creates a transaction wrapping the Evmos
* {@link https://docs.evmos.org/modules/revenue/04_transactions.html#msgregisterrevenue | MsgRegisterRevenue}
*
* @param context - Transaction Context
* @param params - MsgRegisterRevenue Params
* @returns Transaction with the MsgRegisterRevenue payload
*
*/
export const createTxMsgRegisterRevenue: (
context: TxContext,
params: MsgRegisterRevenueParams,
): TxPayload
```

### MsgUpdateRevenue

```ts
export interface MsgUpdateRevenueParams {
contractAddress: string
deployerAddress: string
withdrawerAddress: string
}

/**
* Creates a transaction for a `MsgUpdateRevenue` object.
*
* @remarks
* This method creates a transaction wrapping the Evmos
* {@link https://docs.evmos.org/modules/revenue/04_transactions.html#msgupdaterevenue | MsgUpdateRevenue}
*
* @param context - Transaction Context
* @param params - MsgUpdateRevenue Params
* @returns Transaction with the MsgUpdateRevenue payload
*
*/
export const createTxMsgUpdateRevenue: (
context: TxContext,
params: MsgUpdateRevenueParams,
): TxPayload
```
6 changes: 2 additions & 4 deletions packages/transactions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
export * from './messages/authz'
export * from './messages/bank'
export * from './messages/common'
export * from './messages/erc20'
export * from './messages/gov'
export * from './messages/ibc'
export * from './messages/revenue/msgCancelRevenue'
export * from './messages/revenue/msgUpdateRevenue'
export * from './messages/revenue/msgRegisterRevenue'
export * from './messages/revenue'
export * from './messages/vesting/msgCreateClawbackVestingAccount'
export * from './messages/vesting/msgClawback'
export * from './messages/common'
export * from './messages/staking'
export * from './messages/txRaw'
export * from './messages/validator'
Expand Down
6 changes: 3 additions & 3 deletions packages/transactions/src/messages/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ const createCosmosPayload = (
* Creates a signable transaction with SignDirect,
* LegacyAmino, and EIP-712 components.
*
* @param context Transaction Context
* @param typedData EIP-712 Typed Data
* @param cosmosMessage Cosmos SDK Message to sign
* @param context - Transaction Context
* @param typedData - EIP-712 Typed Data
* @param cosmosMessage - Cosmos SDK Message to sign
* @returns Signable Payload
*
*/
Expand Down
48 changes: 48 additions & 0 deletions packages/transactions/src/messages/revenue/cancelRevenue.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { createMsgCancelRevenue as protoMsgCancelRevenue } from '@evmos/proto'
import {
generateTypes,
createMsgCancelRevenue,
MSG_CANCEL_REVENUE_TYPES,
} from '@evmos/eip712'
import {
MsgCancelRevenueParams,
createTxMsgCancelRevenue,
} from './cancelRevenue'
import { createTransactionPayload } from '../base'
import TestUtils from '../../tests/utils'

const { context } = TestUtils
const contractAddress = TestUtils.addrHex1
const deployerAddress = context.sender.accountAddress

const params: MsgCancelRevenueParams = {
contractAddress,
deployerAddress,
}

describe('test tx payload', () => {
it('produces tx payloads as expected', () => {
const types = generateTypes(MSG_CANCEL_REVENUE_TYPES)
const message = createMsgCancelRevenue(
params.contractAddress,
params.deployerAddress,
)
const typedData = {
types,
message,
}

const messageCosmos = protoMsgCancelRevenue(
params.contractAddress,
params.deployerAddress,
)

const payload = createTxMsgCancelRevenue(context, params)
const expectedPayload = createTransactionPayload(
context,
typedData,
messageCosmos,
)
expect(payload).toStrictEqual(expectedPayload)
})
})
53 changes: 53 additions & 0 deletions packages/transactions/src/messages/revenue/cancelRevenue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { createMsgCancelRevenue as protoMsgCancelRevenue } from '@evmos/proto'

import {
generateTypes,
createMsgCancelRevenue,
MSG_CANCEL_REVENUE_TYPES,
} from '@evmos/eip712'
import { createTransactionPayload, TxContext } from '../base'

export interface MsgCancelRevenueParams {
contractAddress: string
deployerAddress: string
}

const createEIP712MsgCancelRevenue = (params: MsgCancelRevenueParams) => {
const types = generateTypes(MSG_CANCEL_REVENUE_TYPES)

const message = createMsgCancelRevenue(
params.contractAddress,
params.deployerAddress,
)

return {
types,
message,
}
}

const createCosmosMsgCancelRevenue = (params: MsgCancelRevenueParams) => {
return protoMsgCancelRevenue(params.contractAddress, params.deployerAddress)
}

/**
* Creates a transaction for a `MsgCancelRevenue` object.
*
* @remarks
* This method creates a transaction wrapping the Evmos
* {@link https://docs.evmos.org/modules/revenue/04_transactions.html#msgcancelrevenue | MsgCancelRevenue}
*
* @param context - Transaction Context
* @param params - MsgCancelRevenue Params
* @returns Transaction with the MsgCancelRevenue payload
*
*/
export const createTxMsgCancelRevenue = (
context: TxContext,
params: MsgCancelRevenueParams,
) => {
const typedData = createEIP712MsgCancelRevenue(params)
const cosmosMsg = createCosmosMsgCancelRevenue(params)

return createTransactionPayload(context, typedData, cosmosMsg)
}
3 changes: 3 additions & 0 deletions packages/transactions/src/messages/revenue/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './cancelRevenue'
export * from './registerRevenue'
export * from './updateRevenue'
75 changes: 0 additions & 75 deletions packages/transactions/src/messages/revenue/msgCancelRevenue.ts

This file was deleted.

81 changes: 0 additions & 81 deletions packages/transactions/src/messages/revenue/msgRegisterRevenue.ts

This file was deleted.

Loading