From 502e980b4ff1c73fe2b93b107ee1352f08cec27d Mon Sep 17 00:00:00 2001 From: willclarktech Date: Tue, 26 Jan 2021 15:56:11 +0000 Subject: [PATCH 1/4] launchpad: Export distribution msgs --- packages/launchpad/src/index.ts | 8 ++++++++ packages/launchpad/types/index.d.ts | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/packages/launchpad/src/index.ts b/packages/launchpad/src/index.ts index 52990a9d..5d2647c7 100644 --- a/packages/launchpad/src/index.ts +++ b/packages/launchpad/src/index.ts @@ -104,17 +104,25 @@ export { isMsgCreateValidator, isMsgDelegate, isMsgEditValidator, + isMsgFundCommunityPool, isMsgMultiSend, isMsgSend, + isMsgSetWithdrawAddress, isMsgUndelegate, + isMsgWithdrawDelegatorReward, + isMsgWithdrawValidatorCommission, Msg, MsgBeginRedelegate, MsgCreateValidator, MsgDelegate, MsgEditValidator, + MsgFundCommunityPool, MsgMultiSend, MsgSend, + MsgSetWithdrawAddress, MsgUndelegate, + MsgWithdrawDelegatorReward, + MsgWithdrawValidatorCommission, } from "./msgs"; export { decodeAminoPubkey, diff --git a/packages/launchpad/types/index.d.ts b/packages/launchpad/types/index.d.ts index e0a1863f..44e906e2 100644 --- a/packages/launchpad/types/index.d.ts +++ b/packages/launchpad/types/index.d.ts @@ -102,17 +102,25 @@ export { isMsgCreateValidator, isMsgDelegate, isMsgEditValidator, + isMsgFundCommunityPool, isMsgMultiSend, isMsgSend, + isMsgSetWithdrawAddress, isMsgUndelegate, + isMsgWithdrawDelegatorReward, + isMsgWithdrawValidatorCommission, Msg, MsgBeginRedelegate, MsgCreateValidator, MsgDelegate, MsgEditValidator, + MsgFundCommunityPool, MsgMultiSend, MsgSend, + MsgSetWithdrawAddress, MsgUndelegate, + MsgWithdrawDelegatorReward, + MsgWithdrawValidatorCommission, } from "./msgs"; export { decodeAminoPubkey, From 5b4afec3fc90336d039d97e45534a81f100e822f Mon Sep 17 00:00:00 2001 From: willclarktech Date: Tue, 26 Jan 2021 15:59:08 +0000 Subject: [PATCH 2/4] root: Update CHANGELOG for Launchpad exports --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e994f667..dceef247 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,9 @@ ### Added +- @cosmjs/launchpad: Export distribution module msg types + `MsgFundCommunityPool`, `MsgSetWithdrawAddress`, `MsgWithdrawDelegatorReward`, + `MsgWithdrawValidatorCommission` and type checker helper functions. - @cosmjs/utils: Added `assertDefinedAndNotNull`. ### Changed From 0b423e443818bd9ed4601e25d795559c5506d66f Mon Sep 17 00:00:00 2001 From: willclarktech Date: Tue, 26 Jan 2021 15:32:35 +0000 Subject: [PATCH 3/4] stargate: Add Amino type conversions for distribution msgs --- packages/stargate/src/aminotypes.ts | 81 +++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/packages/stargate/src/aminotypes.ts b/packages/stargate/src/aminotypes.ts index 8d424d72..11b217ef 100644 --- a/packages/stargate/src/aminotypes.ts +++ b/packages/stargate/src/aminotypes.ts @@ -8,9 +8,13 @@ import { MsgCreateValidator, MsgDelegate, MsgEditValidator, + MsgFundCommunityPool, MsgMultiSend, MsgSend, + MsgSetWithdrawAddress, MsgUndelegate, + MsgWithdrawDelegatorReward, + MsgWithdrawValidatorCommission, } from "@cosmjs/launchpad"; import { EncodeObject } from "@cosmjs/proto-signing"; import { assertDefinedAndNotNull } from "@cosmjs/utils"; @@ -20,6 +24,10 @@ import { coinFromProto } from "./stargateclient"; type IMsgSend = cosmos.bank.v1beta1.IMsgSend; type IMsgMultiSend = cosmos.bank.v1beta1.IMsgMultiSend; +type IMsgFundCommunityPool = cosmos.distribution.v1beta1.IMsgFundCommunityPool; +type IMsgSetWithdrawAddress = cosmos.distribution.v1beta1.IMsgSetWithdrawAddress; +type IMsgWithdrawDelegatorReward = cosmos.distribution.v1beta1.IMsgWithdrawDelegatorReward; +type IMsgWithdrawValidatorCommission = cosmos.distribution.v1beta1.IMsgWithdrawValidatorCommission; type IMsgBeginRedelegate = cosmos.staking.v1beta1.IMsgBeginRedelegate; type IMsgCreateValidator = cosmos.staking.v1beta1.IMsgCreateValidator; type IMsgDelegate = cosmos.staking.v1beta1.IMsgDelegate; @@ -87,6 +95,79 @@ function createDefaultTypes(prefix: string): Record { })), }), }, + "/cosmos.distribution.v1beta1.MsgFundCommunityPool": { + aminoType: "cosmos-sdk/MsgFundCommunityPool", + toAmino: ({ amount, depositor }: IMsgFundCommunityPool): MsgFundCommunityPool["value"] => { + assertDefinedAndNotNull(amount); + assertDefinedAndNotNull(depositor); + return { + amount: amount.map(coinFromProto), + depositor: depositor, + }; + }, + fromAmino: ({ amount, depositor }: MsgFundCommunityPool["value"]): IMsgFundCommunityPool => ({ + amount: [...amount], + depositor: depositor, + }), + }, + "/cosmos.distribution.v1beta1.MsgSetWithdrawAddress": { + aminoType: "cosmos-sdk/MsgSetWithdrawAddress", + toAmino: ({ + delegatorAddress, + withdrawAddress, + }: IMsgSetWithdrawAddress): MsgSetWithdrawAddress["value"] => { + assertDefinedAndNotNull(delegatorAddress); + assertDefinedAndNotNull(withdrawAddress); + return { + delegator_address: delegatorAddress, + withdraw_address: withdrawAddress, + }; + }, + fromAmino: ({ + delegator_address, + withdraw_address, + }: MsgSetWithdrawAddress["value"]): IMsgSetWithdrawAddress => ({ + delegatorAddress: delegator_address, + withdrawAddress: withdraw_address, + }), + }, + "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward": { + aminoType: "cosmos-sdk/MsgWithdrawDelegatorReward", + toAmino: ({ + delegatorAddress, + validatorAddress, + }: IMsgWithdrawDelegatorReward): MsgWithdrawDelegatorReward["value"] => { + assertDefinedAndNotNull(delegatorAddress); + assertDefinedAndNotNull(validatorAddress); + return { + delegator_address: delegatorAddress, + validator_address: validatorAddress, + }; + }, + fromAmino: ({ + delegator_address, + validator_address, + }: MsgWithdrawDelegatorReward["value"]): IMsgWithdrawDelegatorReward => ({ + delegatorAddress: delegator_address, + validatorAddress: validator_address, + }), + }, + "/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission": { + aminoType: "cosmos-sdk/MsgWithdrawValidatorCommission", + toAmino: ({ + validatorAddress, + }: IMsgWithdrawValidatorCommission): MsgWithdrawValidatorCommission["value"] => { + assertDefinedAndNotNull(validatorAddress); + return { + validator_address: validatorAddress, + }; + }, + fromAmino: ({ + validator_address, + }: MsgWithdrawValidatorCommission["value"]): IMsgWithdrawValidatorCommission => ({ + validatorAddress: validator_address, + }), + }, "/cosmos.staking.v1beta1.MsgBeginRedelegate": { aminoType: "cosmos-sdk/MsgBeginRedelegate", toAmino: ({ From ade4350696e8af96801bc9182028a27cef2d4d3a Mon Sep 17 00:00:00 2001 From: willclarktech Date: Tue, 26 Jan 2021 15:40:52 +0000 Subject: [PATCH 4/4] stargate: Add tests for distribution msgs Amino types --- packages/stargate/src/aminotypes.spec.ts | 84 ++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/packages/stargate/src/aminotypes.spec.ts b/packages/stargate/src/aminotypes.spec.ts index 8aef1d19..85ccd821 100644 --- a/packages/stargate/src/aminotypes.spec.ts +++ b/packages/stargate/src/aminotypes.spec.ts @@ -12,12 +12,22 @@ import { MsgSend, MsgUndelegate, } from "@cosmjs/launchpad"; +import { + MsgFundCommunityPool, + MsgSetWithdrawAddress, + MsgWithdrawDelegatorReward, + MsgWithdrawValidatorCommission, +} from "@cosmjs/launchpad/types/msgs"; import { AminoTypes } from "./aminotypes"; import { cosmos } from "./codec"; type IMsgSend = cosmos.bank.v1beta1.IMsgSend; type IMsgMultiSend = cosmos.bank.v1beta1.IMsgMultiSend; +type IMsgFundCommunityPool = cosmos.distribution.v1beta1.IMsgFundCommunityPool; +type IMsgSetWithdrawAddress = cosmos.distribution.v1beta1.IMsgSetWithdrawAddress; +type IMsgWithdrawDelegatorReward = cosmos.distribution.v1beta1.IMsgWithdrawDelegatorReward; +type IMsgWithdrawValidatorCommission = cosmos.distribution.v1beta1.IMsgWithdrawValidatorCommission; type IMsgBeginRedelegate = cosmos.staking.v1beta1.IMsgBeginRedelegate; type IMsgCreateValidator = cosmos.staking.v1beta1.IMsgCreateValidator; type IMsgDelegate = cosmos.staking.v1beta1.IMsgDelegate; @@ -78,6 +88,80 @@ describe("AminoTypes", () => { expect(aminoMsg).toEqual(expected); }); + it("works for MsgFundCommunityPool", async () => { + const msg: IMsgFundCommunityPool = { + amount: coins(1234, "ucosm"), + depositor: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", + }; + const aminoMsg = new AminoTypes().toAmino({ + typeUrl: "/cosmos.distribution.v1beta1.MsgFundCommunityPool", + value: msg, + }); + const expected: MsgFundCommunityPool = { + type: "cosmos-sdk/MsgFundCommunityPool", + value: { + amount: coins(1234, "ucosm"), + depositor: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", + }, + }; + expect(aminoMsg).toEqual(expected); + }); + + it("works for MsgSetWithdrawAddress", async () => { + const msg: IMsgSetWithdrawAddress = { + delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", + withdrawAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", + }; + const aminoMsg = new AminoTypes().toAmino({ + typeUrl: "/cosmos.distribution.v1beta1.MsgSetWithdrawAddress", + value: msg, + }); + const expected: MsgSetWithdrawAddress = { + type: "cosmos-sdk/MsgSetWithdrawAddress", + value: { + delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", + withdraw_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", + }, + }; + expect(aminoMsg).toEqual(expected); + }); + + it("works for MsgWithdrawDelegatorReward", async () => { + const msg: IMsgWithdrawDelegatorReward = { + delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", + validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", + }; + const aminoMsg = new AminoTypes().toAmino({ + typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward", + value: msg, + }); + const expected: MsgWithdrawDelegatorReward = { + type: "cosmos-sdk/MsgWithdrawDelegatorReward", + value: { + delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", + validator_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", + }, + }; + expect(aminoMsg).toEqual(expected); + }); + + it("works for MsgWithdrawValidatorCommission", async () => { + const msg: IMsgWithdrawValidatorCommission = { + validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", + }; + const aminoMsg = new AminoTypes().toAmino({ + typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission", + value: msg, + }); + const expected: MsgWithdrawValidatorCommission = { + type: "cosmos-sdk/MsgWithdrawValidatorCommission", + value: { + validator_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", + }, + }; + expect(aminoMsg).toEqual(expected); + }); + it("works for MsgBeginRedelegate", () => { const msg: IMsgBeginRedelegate = { delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",