-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b8031a
commit 268986e
Showing
64 changed files
with
1,324 additions
and
681 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * as Genesis from './genesis_pb.js' | ||
export * as Genesis from './v1/genesis_pb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
export * from './messages/base.js' | ||
export * from './messages/common.js' | ||
export * from './messages/authz/index.js' | ||
export * from './messages/bank/index.js' | ||
export * from './messages/distribution/index.js' | ||
export * from './messages/erc20/index.js' | ||
export * from './messages/gov/index.js' | ||
export * from './messages/ibc/index.js' | ||
export * from './messages/staking/index.js' | ||
export * from './messages/vesting/index.js' | ||
export * from './messages/common.js' | ||
export * from './messages/txRaw.js' | ||
export * from './messages/web3Extension.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './genericGrant.js' | ||
export * from './genericRevoke.js' | ||
export * from './stakingGrant.js' | ||
export * from './stakingRevoke.js' |
66 changes: 66 additions & 0 deletions
66
packages/transactions/src/messages/authz/stakingGrant.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { createMsgGrant, createStakeAuthorization, Proto } from '@evmos/proto' | ||
import { createTransactionPayload } from '../base' | ||
|
||
import { | ||
MsgStakeAuthorizationParams, | ||
createTxMsgStakeAuthorization, | ||
} from './stakingGrant' | ||
import TestUtils from '../../tests/utils' | ||
|
||
const { context, denom } = TestUtils | ||
const granteeAddress = TestUtils.addr1 | ||
const maxTokens = TestUtils.amount1 | ||
const expiration = 10000 | ||
|
||
const createParams = (validatorAddress: string | string[]) => ({ | ||
granteeAddress, | ||
validatorAddress, | ||
denom, | ||
maxTokens, | ||
expiration, | ||
}) | ||
|
||
const validatePayload = (params: MsgStakeAuthorizationParams) => { | ||
const typedData = { | ||
types: {}, | ||
message: {}, | ||
} | ||
|
||
const stakeAuthType = Proto.Cosmos.Staking.Authz.AuthorizationType.DELEGATE | ||
const auth = createStakeAuthorization( | ||
params.validatorAddress, | ||
params.denom, | ||
params.maxTokens, | ||
stakeAuthType, | ||
) | ||
|
||
const messageCosmos = createMsgGrant( | ||
context.sender.accountAddress, | ||
params.granteeAddress, | ||
auth, | ||
params.expiration, | ||
) | ||
|
||
const payload = createTxMsgStakeAuthorization(context, params) | ||
const expectedPayload = createTransactionPayload( | ||
context, | ||
typedData, | ||
messageCosmos, | ||
) | ||
|
||
expect(payload).toStrictEqual(expectedPayload) | ||
} | ||
|
||
describe('test tx payload', () => { | ||
it('correctly produces tx payloads with single validator', () => { | ||
const validator = TestUtils.addrVal1 | ||
const params = createParams(validator) | ||
validatePayload(params) | ||
}) | ||
|
||
it('correctly produces tx payloads with multiple validators', () => { | ||
const validators = [TestUtils.addrVal1, TestUtils.addrVal2] | ||
const params = createParams(validators) | ||
validatePayload(params) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { createMsgGrant, createStakeAuthorization, Proto } from '@evmos/proto' | ||
import { createTransactionPayload, TxContext } from '../base.js' | ||
|
||
export interface MsgStakeAuthorizationParams { | ||
granteeAddress: string | ||
validatorAddress: string | string[] | ||
denom: string | ||
maxTokens: string | undefined | ||
expiration: number | ||
} | ||
|
||
const createEIP712MsgStakeAuthorization = () => { | ||
// TODO: EIP-712 Stake Authorization is blocked until StakeAuthorization | ||
// is added to @evmos/eip712 | ||
return { | ||
types: {}, | ||
message: {}, | ||
} | ||
} | ||
|
||
const createCosmosMsgStakeAuthorization = ( | ||
context: TxContext, | ||
params: MsgStakeAuthorizationParams, | ||
) => { | ||
const stakeAuthType = Proto.Cosmos.Staking.Authz.AuthorizationType.DELEGATE | ||
|
||
const auth = createStakeAuthorization( | ||
params.validatorAddress, | ||
params.denom, | ||
params.maxTokens, | ||
stakeAuthType, | ||
) | ||
|
||
return createMsgGrant( | ||
context.sender.accountAddress, | ||
params.granteeAddress, | ||
auth, | ||
params.expiration, | ||
) | ||
} | ||
|
||
/** | ||
* Creates a transaction for a staking MsgGrant. | ||
* | ||
* @remarks | ||
* This method creates a transaction wrapping the Cosmos SDK's | ||
* {@link https://docs.cosmos.network/main/modules/authz#msggrant | MsgGrant} | ||
* | ||
* @param context - Transaction Context | ||
* @param params - MsgGrant Staking Auth Params | ||
* @returns Transaction with the MsgGrant payload | ||
* | ||
*/ | ||
export function createTxMsgStakeAuthorization( | ||
context: TxContext, | ||
params: MsgStakeAuthorizationParams, | ||
) { | ||
const typedData = createEIP712MsgStakeAuthorization() | ||
const cosmosMsg = createCosmosMsgStakeAuthorization(context, params) | ||
|
||
return createTransactionPayload(context, typedData, cosmosMsg) | ||
} |
40 changes: 40 additions & 0 deletions
40
packages/transactions/src/messages/authz/stakingRevoke.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { createMsgRevoke, RevokeMessages } from '@evmos/proto' | ||
|
||
import { createTransactionPayload } from '../base' | ||
|
||
import { | ||
MsgStakeRevokeAuthorizationParams, | ||
createTxMsgStakeRevokeAuthorization, | ||
} from './stakingRevoke' | ||
import TestUtils from '../../tests/utils' | ||
|
||
const { context } = TestUtils | ||
const granteeAddress = TestUtils.addr1 | ||
|
||
const params: MsgStakeRevokeAuthorizationParams = { | ||
granteeAddress, | ||
} | ||
|
||
describe('test tx payload', () => { | ||
it('produces tx payloads as expected', () => { | ||
const typedData = { | ||
types: {}, | ||
message: {}, | ||
} | ||
|
||
const messageCosmos = createMsgRevoke( | ||
context.sender.accountAddress, | ||
params.granteeAddress, | ||
RevokeMessages.REVOKE_MSG_DELEGATE, | ||
) | ||
|
||
const payload = createTxMsgStakeRevokeAuthorization(context, params) | ||
const expectedPayload = createTransactionPayload( | ||
context, | ||
typedData, | ||
messageCosmos, | ||
) | ||
|
||
expect(payload).toStrictEqual(expectedPayload) | ||
}) | ||
}) |
Oops, something went wrong.