Skip to content

Commit

Permalink
feat: add support for tokenfactory module (#755)
Browse files Browse the repository at this point in the history
## Description

Closes: SDK-47

<!-- Add a description of the changes that this PR introduces and the
files that
are the most critical to review. -->

This PR implements support for the new `x/tokenfactory` module,
introducing compatibility for the following messages:
- `MsgCreateDenom`
- `MsgMint`
- `MsgBurn`
- `MsgSetDenomMetadata`
- `MsgUpdateParams`
---

### Author Checklist

*All items are required. Please add a note to the item if the item is
not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type
prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json)
in the PR title
- [ ] targeted the correct branch (see [PR
Targeting](https://github.com/desmos-labs/desmjs/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable
and please add
your handle next to the items reviewed if you only reviewed selected
items.*

I have...

- [ ] confirmed the correct [type
prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json)
in the PR title
- [ ] confirmed all author checklist items have been addressed
- [ ] confirmed that this PR does not change production code
  • Loading branch information
manu0466 authored Aug 29, 2023
1 parent bc0d264 commit 99520b5
Show file tree
Hide file tree
Showing 20 changed files with 524 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup Protoc 👷
uses: arduino/setup-protoc@v2
with:
version: "3.x"
version: "23.4"
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Node 👷
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ jobs:
with:
node-version: 16

- name: Install Protobuf compiler 👷
if: env.GIT_DIFF
run: |
sudo apt-get update
sudo apt-get -y install protobuf-compiler
- name: Setup Protoc 👷
uses: arduino/setup-protoc@v2
with:
version: "23.4"
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Install 🔨
if: env.GIT_DIFF
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/modules/aminoconverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { AminoConverter as RelationshipsV1AminoConverter } from "./relationships
import { AminoConverter as ReportsV1AminoConverter } from "./reports/v1";
import { AminoConverter as StakingV1Beta1AminoConverter } from "./staking/v1beta1";
import { AminoConverter as SubspacesV3AminoConverter } from "./subspaces/v3";
import { AminoConverter as TokenFactoryV1AminoConverter } from "./tokenfactory/v1";

export const DesmosAminoConverter = {
...createBankAminoConverters(),
Expand All @@ -41,6 +42,7 @@ export const DesmosAminoConverter = {
...ReportsV1AminoConverter,
...StakingV1Beta1AminoConverter,
...SubspacesV3AminoConverter,
...TokenFactoryV1AminoConverter,
};

export default DesmosAminoConverter;
1 change: 1 addition & 0 deletions packages/core/src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export * as Reports from "./reports";
export * as Staking from "./staking";
export * as Subspaces from "./subspaces";
export * as Supply from "./supply";
export * as TokenFactory from "./tokenfactory";
6 changes: 6 additions & 0 deletions packages/core/src/modules/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ import {
SubspacesV3Extension,
} from "./subspaces/v3";
import { setupSupplyV1Extension, SupplyV1Extension } from "./supply/v1";
import {
setupTokenFactoryV1Extension,
TokenFactoryV1Extension,
} from "./tokenfactory/v1";

export type DesmosQueryClient = QueryClient &
AuthzV1Beta1Extension &
Expand All @@ -50,6 +54,7 @@ export type DesmosQueryClient = QueryClient &
ReactionsExtension &
ReportsV1Extension &
SupplyV1Extension &
TokenFactoryV1Extension &
WasmExtension &
IbcExtension;

Expand All @@ -74,6 +79,7 @@ export function buildDesmosQueryClient(
setupSupplyV1Extension,
setupWasmExtension,
setupIbcExtension,
setupTokenFactoryV1Extension,
)
: undefined;
}
2 changes: 2 additions & 0 deletions packages/core/src/modules/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { registry as RelationshipsV1Registry } from "./relationships/v1";
import { registry as ReportsV1Registry } from "./reports/v1";
import { registry as StakingV1Beta1Registry } from "./staking/v1beta1";
import { registry as SubspacesV3Registry } from "./subspaces/v3";
import { registry as TokenFactoryV1Registry } from "./tokenfactory/v1";

export const DesmosRegistry: ReadonlyArray<[string, GeneratedType]> = [
...defaultRegistryTypes,
Expand All @@ -32,6 +33,7 @@ export const DesmosRegistry: ReadonlyArray<[string, GeneratedType]> = [
...ReportsV1Registry,
...StakingV1Beta1Registry,
...SubspacesV3Registry,
...TokenFactoryV1Registry,
];

export default DesmosRegistry;
1 change: 1 addition & 0 deletions packages/core/src/modules/tokenfactory/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as v1 from "./v1";
49 changes: 49 additions & 0 deletions packages/core/src/modules/tokenfactory/v1/aminoconverter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { AminoConverters } from "@cosmjs/stargate";
import {
MsgBurn,
MsgCreateDenom,
MsgMint,
MsgSetDenomMetadata,
MsgUpdateParams,
} from "@desmoslabs/desmjs-types/desmos/tokenfactory/v1/msgs";
import {
MsgBurnAminoType,
MsgBurnTypeUrl,
MsgCreateDenomAminoType,
MsgCreateDenomTypeUrl,
MsgMintAminoType,
MsgMintTypeUrl,
MsgSetDenomMetadataAminoType,
MsgSetDenomMetadataTypeUrl,
MsgUpdateParamsAminoType,
MsgUpdateParamsTypeUrl,
} from "./consts";

// eslint-disable-next-line import/prefer-default-export
export const AminoConverter: AminoConverters = {
[MsgCreateDenomTypeUrl]: {
aminoType: MsgCreateDenomAminoType,
toAmino: MsgCreateDenom.toAmino,
fromAmino: MsgCreateDenom.fromAmino,
},
[MsgMintTypeUrl]: {
aminoType: MsgMintAminoType,
toAmino: MsgMint.toAmino,
fromAmino: MsgMint.fromAmino,
},
[MsgBurnTypeUrl]: {
aminoType: MsgBurnAminoType,
toAmino: MsgBurn.toAmino,
fromAmino: MsgBurn.fromAmino,
},
[MsgSetDenomMetadataTypeUrl]: {
aminoType: MsgSetDenomMetadataAminoType,
toAmino: MsgSetDenomMetadata.toAmino,
fromAmino: MsgSetDenomMetadata.fromAmino,
},
[MsgUpdateParamsTypeUrl]: {
aminoType: MsgUpdateParamsAminoType,
toAmino: MsgUpdateParams.toAmino,
fromAmino: MsgUpdateParams.fromAmino,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import {
MsgBurn,
MsgCreateDenom,
MsgMint,
MsgSetDenomMetadata,
} from "@desmoslabs/desmjs-types/desmos/tokenfactory/v1/msgs";
import { MsgSendEncodeObject } from "@cosmjs/stargate";
import { broadcastTest, createTestSubspace } from "../../../testutils";
import {
MsgBurnEncodeObject,
MsgCreateDenomEncodeObject,
MsgMintEncodeObject,
MsgSetDenomMetadataEncodeObject,
} from "./encodeobjects";
import {
MsgBurnTypeUrl,
MsgCreateDenomTypeUrl,
MsgMintTypeUrl,
MsgSetDenomMetadataTypeUrl,
} from "./consts";
import { MsgSendTypeUrl } from "../../bank/v1beta1";

describe("Broadcast desmos.tokenfactory.v1 messages", () => {
jest.setTimeout(60 * 1000);

describe("Broadcast MsgCreateDenom", () => {
broadcastTest("MsgCreateDenom", async (signer, client, [address]) => {
const subspaceId = await createTestSubspace(client, address);

// Send some coins to the subspace treasury
const { subspace } = await client.querier.subspacesV3.subspace(
subspaceId,
);
await client.signAndBroadcast(
address,
[
{
typeUrl: MsgSendTypeUrl,
value: {
amount: [{ amount: "1", denom: "stake" }],
toAddress: subspace!.treasury,
fromAddress: address,
},
} as MsgSendEncodeObject,
],
"auto",
);

const msgCreateDenom: MsgCreateDenomEncodeObject = {
typeUrl: MsgCreateDenomTypeUrl,
value: MsgCreateDenom.fromPartial({
subspaceId,
sender: address,
subdenom: "cdenom",
}),
};
// Test the denom creation.
await client.signAndBroadcast(address, [msgCreateDenom], "auto");
});
});

describe("Broadcast MsgMint & MsgBurn", () => {
broadcastTest("MsgMint & MsgBur", async (signer, client, [address]) => {
const subspaceId = await createTestSubspace(client, address);

// Send some coins to the subspace treasury
const { subspace } = await client.querier.subspacesV3.subspace(
subspaceId,
);
await client.signAndBroadcast(
address,
[
{
typeUrl: MsgSendTypeUrl,
value: {
amount: [{ amount: "1", denom: "stake" }],
toAddress: subspace!.treasury,
fromAddress: address,
},
} as MsgSendEncodeObject,
],
"auto",
);

// Create a test denom.
const msgCreateDenom: MsgCreateDenomEncodeObject = {
typeUrl: MsgCreateDenomTypeUrl,
value: MsgCreateDenom.fromPartial({
subspaceId,
sender: address,
subdenom: "mintdenom",
}),
};
await client.signAndBroadcast(address, [msgCreateDenom], "auto");

// Test the minting.
const msgMint: MsgMintEncodeObject = {
typeUrl: MsgMintTypeUrl,
value: MsgMint.fromPartial({
subspaceId,
amount: {
amount: "100000",
denom: `factory/${subspace!.treasury}/mintdenom`,
},
sender: address,
}),
};
await client.signAndBroadcast(address, [msgMint], "auto");

// Test the burning.
const msgBurn: MsgBurnEncodeObject = {
typeUrl: MsgBurnTypeUrl,
value: MsgBurn.fromPartial({
subspaceId,
amount: {
amount: "50000",
denom: `factory/${subspace!.treasury}/mintdenom`,
},
sender: address,
}),
};
await client.signAndBroadcast(address, [msgBurn], "auto");
});
});

describe("Broadcast MsgSetDenomMetadata", () => {
broadcastTest("MsgSetDenomMetadata", async (signer, client, [address]) => {
const subspaceId = await createTestSubspace(client, address);

// Send some coins to the subspace treasury
const { subspace } = await client.querier.subspacesV3.subspace(
subspaceId,
);
await client.signAndBroadcast(
address,
[
{
typeUrl: MsgSendTypeUrl,
value: {
amount: [{ amount: "1", denom: "stake" }],
toAddress: subspace!.treasury,
fromAddress: address,
},
} as MsgSendEncodeObject,
],
"auto",
);

// Create a test denom.
const msgCreateDenom: MsgCreateDenomEncodeObject = {
typeUrl: MsgCreateDenomTypeUrl,
value: MsgCreateDenom.fromPartial({
subspaceId,
sender: address,
subdenom: "test",
}),
};
await client.signAndBroadcast(address, [msgCreateDenom], "auto");

// Test set denom metadata.
const msgSetDenomMetadata: MsgSetDenomMetadataEncodeObject = {
typeUrl: MsgSetDenomMetadataTypeUrl,
value: MsgSetDenomMetadata.fromPartial({
subspaceId,
metadata: {
name: "Test denom",
description: "A random denom",
symbol: "test",
base: `factory/${subspace!.treasury}/test`,
display: `factory/${subspace!.treasury}/test`,
denomUnits: [
{
denom: `factory/${subspace!.treasury}/test`,
aliases: ["test"],
exponent: 0,
},
],
},
sender: address,
}),
};
await client.signAndBroadcast(address, [msgSetDenomMetadata], "auto");
});
});
});
11 changes: 11 additions & 0 deletions packages/core/src/modules/tokenfactory/v1/consts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const MsgCreateDenomTypeUrl = "/desmos.tokenfactory.v1.MsgCreateDenom";
export const MsgCreateDenomAminoType = "desmos/MsgCreateDenom";
export const MsgMintTypeUrl = "/desmos.tokenfactory.v1.MsgMint";
export const MsgMintAminoType = "desmos/MsgMint";
export const MsgBurnTypeUrl = "/desmos.tokenfactory.v1.MsgBurn";
export const MsgBurnAminoType = "desmos/MsgBurn";
export const MsgSetDenomMetadataTypeUrl =
"/desmos.tokenfactory.v1.MsgSetDenomMetadata";
export const MsgSetDenomMetadataAminoType = "desmos/MsgSetDenomMetadata";
export const MsgUpdateParamsTypeUrl = "/desmos.tokenfactory.v1.MsgUpdateParams";
export const MsgUpdateParamsAminoType = "desmos/x/tokenfactoy/MsgUpdateParams";
Loading

0 comments on commit 99520b5

Please sign in to comment.