Skip to content

Commit

Permalink
Add tokenfactory module from miniwasm
Browse files Browse the repository at this point in the history
  • Loading branch information
joon9823 committed Mar 27, 2024
1 parent 33db472 commit 564a04d
Show file tree
Hide file tree
Showing 18 changed files with 1,146 additions and 8 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@initia/initia.js",
"version": "0.1.37",
"version": "0.1.38",
"description": "The JavaScript SDK for Initia",
"license": "MIT",
"author": "InitiaLabs",
Expand Down Expand Up @@ -86,7 +86,7 @@
"webpack-cli": "^4.10.0"
},
"dependencies": {
"@initia/initia.proto": "^0.1.27",
"@initia/initia.proto": "^0.1.29",
"@initia/opinit.proto": "^0.0.3",
"@ledgerhq/hw-transport": "^6.27.12",
"@ledgerhq/hw-transport-webhid": "^6.27.12",
Expand Down
3 changes: 3 additions & 0 deletions src/client/lcd/LCDClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
RewardAPI,
SlashingAPI,
TendermintAPI,
TokenfactoryAPI,
TxAPI,
UpgradeAPI,
WasmAPI,
Expand Down Expand Up @@ -104,6 +105,7 @@ export class LCDClient {
public reward: RewardAPI;
public slashing: SlashingAPI;
public tendermint: TendermintAPI;
public tokenfactory: TokenfactoryAPI;
public tx: TxAPI;
public upgrade: UpgradeAPI;
public wasm: WasmAPI;
Expand Down Expand Up @@ -153,6 +155,7 @@ export class LCDClient {
this.reward = new RewardAPI(this.apiRequester);
this.slashing = new SlashingAPI(this.apiRequester);
this.tendermint = new TendermintAPI(this.apiRequester);
this.tokenfactory = new TokenfactoryAPI(this.apiRequester);
this.tx = new TxAPI(this);
this.upgrade = new UpgradeAPI(this.apiRequester);
this.wasm = new WasmAPI(this.apiRequester);
Expand Down
54 changes: 54 additions & 0 deletions src/client/lcd/api/TokenfactoryAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { TokenfactoryParams } from '../../../core';
import { APIParams } from '../APIRequester';
import { BaseAPI } from './BaseAPI';

export interface AuthorityMetadata {
admin: string;
}

export class TokenfactoryAPI extends BaseAPI {
public async authorityMetadata(
denom: string,
params: APIParams = {}
): Promise<AuthorityMetadata> {
return this.c
.get<{ authority_metadata: AuthorityMetadata }>(
`/miniwasm/tokenfactory/v1/denoms/${denom}/authority_metadata`,
params
)
.then(d => d.authority_metadata);
}

public async beforeSendHookAddr(
denom: string,
params: APIParams = {}
): Promise<string> {
return this.c
.get<{ cosmwasm_address: string }>(
`/miniwasm/tokenfactory/v1/denoms/${denom}/before_send_hook`,
params
)
.then(d => d.cosmwasm_address);
}

public async denomsFromCreator(
creator: string,
params: APIParams = {}
): Promise<string[]> {
return this.c
.get<{ denoms: string[] }>(
`/miniwasm/tokenfactory/v1/denoms_from_creator/${creator}`,
params
)
.then(d => d.denoms);
}

public async parameters(params: APIParams = {}): Promise<TokenfactoryParams> {
return this.c
.get<{ params: TokenfactoryParams.Data }>(
`/miniwasm/tokenfactory/v1/params`,
params
)
.then(({ params: d }) => TokenfactoryParams.fromData(d));
}
}
1 change: 1 addition & 0 deletions src/client/lcd/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export * from './OracleAPI';
export * from './RewardAPI';
export * from './SlashingAPI';
export * from './TendermintAPI';
export * from './TokenfactoryAPI';
export * from './TxAPI';
export * from './UpgradeAPI';
export * from './WasmAPI';
69 changes: 69 additions & 0 deletions src/core/Msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@ import {
} from './oracle';
import { RewardMsg, MsgUpdateRewardParams } from './reward';
import { SlashingMsg, MsgUnjail, MsgUpdateSlashingParams } from './slashing';
import {
TokenfactoryMsg,
MsgCreateDenom,
MsgMint,
MsgBurn,
MsgChangeAdmin,
MsgSetDenomMetadataWasm,
MsgSetBeforeSendHook,
MsgForceTransfer,
MsgUpdateTokenfactoryParams,
} from './tokenfactory';
import { UpgradeMsg, MsgSoftwareUpgrade, MsgCancelUpgrade } from './upgrade';
import {
WasmMsg,
Expand Down Expand Up @@ -215,6 +226,7 @@ export type Msg =
| OracleMsg
| RewardMsg
| SlashingMsg
| TokenfactoryMsg
| UpgradeMsg
| WasmMsg;

Expand Down Expand Up @@ -243,6 +255,7 @@ export namespace Msg {
| OracleMsg.Amino
| RewardMsg.Amino
| SlashingMsg.Amino
| TokenfactoryMsg.Amino
| UpgradeMsg.Amino
| WasmMsg.Amino;

Expand Down Expand Up @@ -274,6 +287,7 @@ export namespace Msg {
| OracleMsg.Data
| RewardMsg.Data
| SlashingMsg.Data
| TokenfactoryMsg.Data
| UpgradeMsg.Data
| WasmMsg.Data;

Expand Down Expand Up @@ -305,6 +319,7 @@ export namespace Msg {
| OracleMsg.Proto
| RewardMsg.Proto
| SlashingMsg.Proto
| TokenfactoryMsg.Proto
| UpgradeMsg.Proto
| WasmMsg.Proto;

Expand Down Expand Up @@ -542,6 +557,24 @@ export namespace Msg {
case 'cosmos-sdk/x/slashing/MsgUpdateParams':
return MsgUpdateSlashingParams.fromAmino(data);

// tokenfactory
case 'tokenfactory/MsgCreateDenom':
return MsgCreateDenom.fromAmino(data);
case 'tokenfactory/MsgMint':
return MsgMint.fromAmino(data);
case 'tokenfactory/MsgBurn':
return MsgBurn.fromAmino(data);
case 'tokenfactory/MsgChangeAdmin':
return MsgChangeAdmin.fromAmino(data);
case 'tokenfactory/MsgSetDenomMetadata':
return MsgSetDenomMetadataWasm.fromAmino(data);
case 'tokenfactory/MsgSetBeforeSendHook':
return MsgSetBeforeSendHook.fromAmino(data);
case 'tokenfactory/MsgForceTransfer':
return MsgForceTransfer.fromAmino(data);
case 'tokenfactory/MsgUpdateParams':
return MsgUpdateTokenfactoryParams.fromAmino(data);

// upgrade
case 'cosmos-sdk/MsgSoftwareUpgrade':
return MsgSoftwareUpgrade.fromAmino(data);
Expand Down Expand Up @@ -884,6 +917,24 @@ export namespace Msg {
case '/cosmos.slashing.v1beta1.MsgUpdateParams':
return MsgUpdateSlashingParams.fromData(data);

// tokenfactory
case '/miniwasm.tokenfactory.v1.MsgCreateDenom':
return MsgCreateDenom.fromData(data);
case '/miniwasm.tokenfactory.v1.MsgMint':
return MsgMint.fromData(data);
case '/miniwasm.tokenfactory.v1.MsgBurn':
return MsgBurn.fromData(data);
case '/miniwasm.tokenfactory.v1.MsgChangeAdmin':
return MsgChangeAdmin.fromData(data);
case '/miniwasm.tokenfactory.v1.MsgSetDenomMetadata':
return MsgSetDenomMetadataWasm.fromData(data);
case '/miniwasm.tokenfactory.v1.MsgSetBeforeSendHook':
return MsgSetBeforeSendHook.fromData(data);
case '/miniwasm.tokenfactory.v1.MsgForceTransfer':
return MsgForceTransfer.fromData(data);
case '/miniwasm.tokenfactory.v1.MsgUpdateParams':
return MsgUpdateTokenfactoryParams.fromData(data);

// upgrade
case '/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade':
return MsgSoftwareUpgrade.fromData(data);
Expand Down Expand Up @@ -1229,6 +1280,24 @@ export namespace Msg {
case '/cosmos.slashing.v1beta1.MsgUpdateParams':
return MsgUpdateSlashingParams.unpackAny(proto);

// tokenfactory
case '/miniwasm.tokenfactory.v1.MsgCreateDenom':
return MsgCreateDenom.unpackAny(proto);
case '/miniwasm.tokenfactory.v1.MsgMint':
return MsgMint.unpackAny(proto);
case '/miniwasm.tokenfactory.v1.MsgBurn':
return MsgBurn.unpackAny(proto);
case '/miniwasm.tokenfactory.v1.MsgChangeAdmin':
return MsgChangeAdmin.unpackAny(proto);
case '/miniwasm.tokenfactory.v1.MsgSetDenomMetadata':
return MsgSetDenomMetadataWasm.unpackAny(proto);
case '/miniwasm.tokenfactory.v1.MsgSetBeforeSendHook':
return MsgSetBeforeSendHook.unpackAny(proto);
case '/miniwasm.tokenfactory.v1.MsgForceTransfer':
return MsgForceTransfer.unpackAny(proto);
case '/miniwasm.tokenfactory.v1.MsgUpdateParams':
return MsgUpdateTokenfactoryParams.unpackAny(proto);

// upgrade
case '/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade':
return MsgSoftwareUpgrade.unpackAny(proto);
Expand Down
1 change: 1 addition & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export * from './oracle';
export * from './params';
export * from './reward';
export * from './slashing';
export * from './tokenfactory';
export * from './tx';
export * from './upgrade';
export * from './wasm';
84 changes: 84 additions & 0 deletions src/core/tokenfactory/TokenfactoryParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { JSONSerializable } from '../../util/json';
import { Coins } from '../Coins';
import { Params as Params_pb } from '@initia/initia.proto/miniwasm/tokenfactory/v1/params';
import Long from 'long';

export class TokenfactoryParams extends JSONSerializable<
TokenfactoryParams.Amino,
TokenfactoryParams.Data,
TokenfactoryParams.Proto
> {
public denom_creation_fee: Coins;
/**
* @param denom_creation_fee the fee to be charged on the creation of a new denom
* @param denom_creation_gas_consume the gas cost for creating a new denom
*/
constructor(
denom_creation_fee: Coins.Input,
public denom_creation_gas_consume: number
) {
super();
this.denom_creation_fee = new Coins(denom_creation_fee);
}

public static fromAmino(data: TokenfactoryParams.Amino): TokenfactoryParams {
const { denom_creation_fee, denom_creation_gas_consume } = data;
return new TokenfactoryParams(
Coins.fromAmino(denom_creation_fee),
Number.parseInt(denom_creation_gas_consume)
);
}

public toAmino(): TokenfactoryParams.Amino {
const { denom_creation_fee, denom_creation_gas_consume } = this;
return {
denom_creation_fee: denom_creation_fee.toAmino(),
denom_creation_gas_consume: denom_creation_gas_consume.toString(),
};
}

public static fromData(data: TokenfactoryParams.Data): TokenfactoryParams {
const { denom_creation_fee, denom_creation_gas_consume } = data;
return new TokenfactoryParams(
Coins.fromData(denom_creation_fee),
Number.parseInt(denom_creation_gas_consume)
);
}

public toData(): TokenfactoryParams.Data {
const { denom_creation_fee, denom_creation_gas_consume } = this;
return {
denom_creation_fee: denom_creation_fee.toData(),
denom_creation_gas_consume: denom_creation_gas_consume.toString(),
};
}

public static fromProto(data: TokenfactoryParams.Proto): TokenfactoryParams {
return new TokenfactoryParams(
Coins.fromProto(data.denomCreationFee),
data.denomCreationGasConsume.toNumber()
);
}

public toProto(): TokenfactoryParams.Proto {
const { denom_creation_fee, denom_creation_gas_consume } = this;
return Params_pb.fromPartial({
denomCreationFee: denom_creation_fee.toProto(),
denomCreationGasConsume: Long.fromNumber(denom_creation_gas_consume),
});
}
}

export namespace TokenfactoryParams {
export interface Amino {
denom_creation_fee: Coins.Amino;
denom_creation_gas_consume: string;
}

export interface Data {
denom_creation_fee: Coins.Data;
denom_creation_gas_consume: string;
}

export type Proto = Params_pb;
}
2 changes: 2 additions & 0 deletions src/core/tokenfactory/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './msgs';
export * from './TokenfactoryParams';
Loading

0 comments on commit 564a04d

Please sign in to comment.