From 564a04db8bb7961475bdde47b005dbb8d0a656ae Mon Sep 17 00:00:00 2001 From: joon9823 Date: Wed, 27 Mar 2024 18:05:27 +0900 Subject: [PATCH 1/2] Add tokenfactory module from miniwasm --- package-lock.json | 12 +- package.json | 4 +- src/client/lcd/LCDClient.ts | 3 + src/client/lcd/api/TokenfactoryAPI.ts | 54 ++++++++ src/client/lcd/api/index.ts | 1 + src/core/Msg.ts | 69 ++++++++++ src/core/index.ts | 1 + src/core/tokenfactory/TokenfactoryParams.ts | 84 ++++++++++++ src/core/tokenfactory/index.ts | 2 + src/core/tokenfactory/msgs/MsgBurn.ts | 107 +++++++++++++++ src/core/tokenfactory/msgs/MsgChangeAdmin.ts | 102 ++++++++++++++ src/core/tokenfactory/msgs/MsgCreateDenom.ts | 92 +++++++++++++ .../tokenfactory/msgs/MsgForceTransfer.ts | 125 ++++++++++++++++++ src/core/tokenfactory/msgs/MsgMint.ts | 107 +++++++++++++++ .../tokenfactory/msgs/MsgSetBeforeSendHook.ts | 114 ++++++++++++++++ .../msgs/MsgSetDenomMetadataWasm.ts | 109 +++++++++++++++ .../msgs/MsgUpdateTokenfactoryParams.ts | 109 +++++++++++++++ src/core/tokenfactory/msgs/index.ts | 59 +++++++++ 18 files changed, 1146 insertions(+), 8 deletions(-) create mode 100644 src/client/lcd/api/TokenfactoryAPI.ts create mode 100644 src/core/tokenfactory/TokenfactoryParams.ts create mode 100644 src/core/tokenfactory/index.ts create mode 100644 src/core/tokenfactory/msgs/MsgBurn.ts create mode 100644 src/core/tokenfactory/msgs/MsgChangeAdmin.ts create mode 100644 src/core/tokenfactory/msgs/MsgCreateDenom.ts create mode 100644 src/core/tokenfactory/msgs/MsgForceTransfer.ts create mode 100644 src/core/tokenfactory/msgs/MsgMint.ts create mode 100644 src/core/tokenfactory/msgs/MsgSetBeforeSendHook.ts create mode 100644 src/core/tokenfactory/msgs/MsgSetDenomMetadataWasm.ts create mode 100644 src/core/tokenfactory/msgs/MsgUpdateTokenfactoryParams.ts create mode 100644 src/core/tokenfactory/msgs/index.ts diff --git a/package-lock.json b/package-lock.json index b6efb6d..1526e7f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "@initia/initia.js", - "version": "0.1.37", + "version": "0.1.38", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@initia/initia.js", - "version": "0.1.37", + "version": "0.1.38", "license": "MIT", "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", @@ -883,9 +883,9 @@ } }, "node_modules/@initia/initia.proto": { - "version": "0.1.27", - "resolved": "https://registry.npmjs.org/@initia/initia.proto/-/initia.proto-0.1.27.tgz", - "integrity": "sha512-GIjISGNnKQumGV6M0cswlIyJUEFLJwR+OW/YfcMr/AOgtnSh0f+obret895lKVfvZFhXoJtydBtV+gDr9n/73g==", + "version": "0.1.29", + "resolved": "https://registry.npmjs.org/@initia/initia.proto/-/initia.proto-0.1.29.tgz", + "integrity": "sha512-W42LtqHXbfvpfkUGhN/YmObEAVkq+uz8H26himFTsazUVYV/qikiEDwoVNLXwjb0W4Gxc2Edpg6UdsHayyfymQ==", "dependencies": { "@improbable-eng/grpc-web": "^0.15.0", "google-protobuf": "^3.21.0", diff --git a/package.json b/package.json index 0bd8f28..e5f08d9 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/src/client/lcd/LCDClient.ts b/src/client/lcd/LCDClient.ts index 193e561..89fc47a 100644 --- a/src/client/lcd/LCDClient.ts +++ b/src/client/lcd/LCDClient.ts @@ -24,6 +24,7 @@ import { RewardAPI, SlashingAPI, TendermintAPI, + TokenfactoryAPI, TxAPI, UpgradeAPI, WasmAPI, @@ -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; @@ -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); diff --git a/src/client/lcd/api/TokenfactoryAPI.ts b/src/client/lcd/api/TokenfactoryAPI.ts new file mode 100644 index 0000000..d947b49 --- /dev/null +++ b/src/client/lcd/api/TokenfactoryAPI.ts @@ -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 { + 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 { + 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 { + return this.c + .get<{ denoms: string[] }>( + `/miniwasm/tokenfactory/v1/denoms_from_creator/${creator}`, + params + ) + .then(d => d.denoms); + } + + public async parameters(params: APIParams = {}): Promise { + return this.c + .get<{ params: TokenfactoryParams.Data }>( + `/miniwasm/tokenfactory/v1/params`, + params + ) + .then(({ params: d }) => TokenfactoryParams.fromData(d)); + } +} diff --git a/src/client/lcd/api/index.ts b/src/client/lcd/api/index.ts index a83712b..248e793 100644 --- a/src/client/lcd/api/index.ts +++ b/src/client/lcd/api/index.ts @@ -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'; diff --git a/src/core/Msg.ts b/src/core/Msg.ts index eb664c7..e4ef4ba 100644 --- a/src/core/Msg.ts +++ b/src/core/Msg.ts @@ -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, @@ -215,6 +226,7 @@ export type Msg = | OracleMsg | RewardMsg | SlashingMsg + | TokenfactoryMsg | UpgradeMsg | WasmMsg; @@ -243,6 +255,7 @@ export namespace Msg { | OracleMsg.Amino | RewardMsg.Amino | SlashingMsg.Amino + | TokenfactoryMsg.Amino | UpgradeMsg.Amino | WasmMsg.Amino; @@ -274,6 +287,7 @@ export namespace Msg { | OracleMsg.Data | RewardMsg.Data | SlashingMsg.Data + | TokenfactoryMsg.Data | UpgradeMsg.Data | WasmMsg.Data; @@ -305,6 +319,7 @@ export namespace Msg { | OracleMsg.Proto | RewardMsg.Proto | SlashingMsg.Proto + | TokenfactoryMsg.Proto | UpgradeMsg.Proto | WasmMsg.Proto; @@ -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); @@ -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); @@ -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); diff --git a/src/core/index.ts b/src/core/index.ts index 7e514d4..0d90d1a 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -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'; diff --git a/src/core/tokenfactory/TokenfactoryParams.ts b/src/core/tokenfactory/TokenfactoryParams.ts new file mode 100644 index 0000000..b1e4fbf --- /dev/null +++ b/src/core/tokenfactory/TokenfactoryParams.ts @@ -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; +} diff --git a/src/core/tokenfactory/index.ts b/src/core/tokenfactory/index.ts new file mode 100644 index 0000000..9ee51cf --- /dev/null +++ b/src/core/tokenfactory/index.ts @@ -0,0 +1,2 @@ +export * from './msgs'; +export * from './TokenfactoryParams'; diff --git a/src/core/tokenfactory/msgs/MsgBurn.ts b/src/core/tokenfactory/msgs/MsgBurn.ts new file mode 100644 index 0000000..e259cdb --- /dev/null +++ b/src/core/tokenfactory/msgs/MsgBurn.ts @@ -0,0 +1,107 @@ +import { JSONSerializable } from '../../../util/json'; +import { Coin } from '../../Coin'; +import { AccAddress } from '../../bech32'; +import { Any } from '@initia/initia.proto/google/protobuf/any'; +import { MsgBurn as MsgBurn_pb } from '@initia/initia.proto/miniwasm/tokenfactory/v1/tx'; + +export class MsgBurn extends JSONSerializable< + MsgBurn.Amino, + MsgBurn.Data, + MsgBurn.Proto +> { + /** + * @param sender + * @param amount + * @param burn_from_address + */ + constructor( + public sender: AccAddress, + public amount: Coin, + public burn_from_address: AccAddress + ) { + super(); + } + + public static fromAmino(data: MsgBurn.Amino): MsgBurn { + const { + value: { sender, amount, burn_from_address }, + } = data; + + return new MsgBurn(sender, Coin.fromAmino(amount), burn_from_address); + } + + public toAmino(): MsgBurn.Amino { + const { sender, amount, burn_from_address } = this; + return { + type: 'tokenfactory/MsgBurn', + value: { + sender, + amount: amount.toAmino(), + burn_from_address, + }, + }; + } + + public static fromData(data: MsgBurn.Data): MsgBurn { + const { sender, amount, burn_from_address } = data; + return new MsgBurn(sender, Coin.fromData(amount), burn_from_address); + } + + public toData(): MsgBurn.Data { + const { sender, amount, burn_from_address } = this; + return { + '@type': '/miniwasm.tokenfactory.v1.MsgBurn', + sender, + amount: amount.toData(), + burn_from_address, + }; + } + + public static fromProto(data: MsgBurn.Proto): MsgBurn { + return new MsgBurn( + data.sender, + Coin.fromProto(data.amount as Coin.Proto), + data.burnFromAddress + ); + } + + public toProto(): MsgBurn.Proto { + const { sender, amount, burn_from_address } = this; + return MsgBurn_pb.fromPartial({ + sender, + amount: amount.toProto(), + burnFromAddress: burn_from_address, + }); + } + + public packAny(): Any { + return Any.fromPartial({ + typeUrl: '/miniwasm.tokenfactory.v1.MsgBurn', + value: MsgBurn_pb.encode(this.toProto()).finish(), + }); + } + + public static unpackAny(msgAny: Any): MsgBurn { + return MsgBurn.fromProto(MsgBurn_pb.decode(msgAny.value)); + } +} + +export namespace MsgBurn { + export interface Amino { + type: 'tokenfactory/MsgBurn'; + value: { + sender: AccAddress; + amount: Coin.Amino; + burn_from_address: AccAddress; + }; + } + + export interface Data { + '@type': '/miniwasm.tokenfactory.v1.MsgBurn'; + sender: AccAddress; + amount: Coin.Data; + burn_from_address: AccAddress; + } + + export type Proto = MsgBurn_pb; +} diff --git a/src/core/tokenfactory/msgs/MsgChangeAdmin.ts b/src/core/tokenfactory/msgs/MsgChangeAdmin.ts new file mode 100644 index 0000000..95f7cc5 --- /dev/null +++ b/src/core/tokenfactory/msgs/MsgChangeAdmin.ts @@ -0,0 +1,102 @@ +import { JSONSerializable } from '../../../util/json'; +import { AccAddress } from '../../bech32'; +import { Any } from '@initia/initia.proto/google/protobuf/any'; +import { MsgChangeAdmin as MsgChangeAdmin_pb } from '@initia/initia.proto/miniwasm/tokenfactory/v1/tx'; + +export class MsgChangeAdmin extends JSONSerializable< + MsgChangeAdmin.Amino, + MsgChangeAdmin.Data, + MsgChangeAdmin.Proto +> { + /** + * @param sender + * @param denom + * @param new_admin + */ + constructor( + public sender: AccAddress, + public denom: string, + public new_admin: AccAddress + ) { + super(); + } + + public static fromAmino(data: MsgChangeAdmin.Amino): MsgChangeAdmin { + const { + value: { sender, denom, new_admin }, + } = data; + + return new MsgChangeAdmin(sender, denom, new_admin); + } + + public toAmino(): MsgChangeAdmin.Amino { + const { sender, denom, new_admin } = this; + return { + type: 'tokenfactory/MsgChangeAdmin', + value: { + sender, + denom, + new_admin, + }, + }; + } + + public static fromData(data: MsgChangeAdmin.Data): MsgChangeAdmin { + const { sender, denom, new_admin } = data; + return new MsgChangeAdmin(sender, denom, new_admin); + } + + public toData(): MsgChangeAdmin.Data { + const { sender, denom, new_admin } = this; + return { + '@type': '/miniwasm.tokenfactory.v1.MsgChangeAdmin', + sender, + denom, + new_admin, + }; + } + + public static fromProto(data: MsgChangeAdmin.Proto): MsgChangeAdmin { + return new MsgChangeAdmin(data.sender, data.denom, data.newAdmin); + } + + public toProto(): MsgChangeAdmin.Proto { + const { sender, denom, new_admin } = this; + return MsgChangeAdmin_pb.fromPartial({ + sender, + denom, + newAdmin: new_admin, + }); + } + + public packAny(): Any { + return Any.fromPartial({ + typeUrl: '/miniwasm.tokenfactory.v1.MsgChangeAdmin', + value: MsgChangeAdmin_pb.encode(this.toProto()).finish(), + }); + } + + public static unpackAny(msgAny: Any): MsgChangeAdmin { + return MsgChangeAdmin.fromProto(MsgChangeAdmin_pb.decode(msgAny.value)); + } +} + +export namespace MsgChangeAdmin { + export interface Amino { + type: 'tokenfactory/MsgChangeAdmin'; + value: { + sender: AccAddress; + denom: string; + new_admin: AccAddress; + }; + } + + export interface Data { + '@type': '/miniwasm.tokenfactory.v1.MsgChangeAdmin'; + sender: AccAddress; + denom: string; + new_admin: AccAddress; + } + + export type Proto = MsgChangeAdmin_pb; +} diff --git a/src/core/tokenfactory/msgs/MsgCreateDenom.ts b/src/core/tokenfactory/msgs/MsgCreateDenom.ts new file mode 100644 index 0000000..e5a8590 --- /dev/null +++ b/src/core/tokenfactory/msgs/MsgCreateDenom.ts @@ -0,0 +1,92 @@ +import { JSONSerializable } from '../../../util/json'; +import { AccAddress } from '../../bech32'; +import { Any } from '@initia/initia.proto/google/protobuf/any'; +import { MsgCreateDenom as MsgCreateDenom_pb } from '@initia/initia.proto/miniwasm/tokenfactory/v1/tx'; + +export class MsgCreateDenom extends JSONSerializable< + MsgCreateDenom.Amino, + MsgCreateDenom.Data, + MsgCreateDenom.Proto +> { + /** + * @param sender the actor that signed the messages + * @param subdenom can be up to 44 "alphanumeric" characters long + */ + constructor(public sender: AccAddress, public subdenom: string) { + super(); + } + + public static fromAmino(data: MsgCreateDenom.Amino): MsgCreateDenom { + const { + value: { sender, subdenom }, + } = data; + + return new MsgCreateDenom(sender, subdenom); + } + + public toAmino(): MsgCreateDenom.Amino { + const { sender, subdenom } = this; + return { + type: 'tokenfactory/MsgCreateDenom', + value: { + sender, + subdenom, + }, + }; + } + + public static fromData(data: MsgCreateDenom.Data): MsgCreateDenom { + const { sender, subdenom } = data; + return new MsgCreateDenom(sender, subdenom); + } + + public toData(): MsgCreateDenom.Data { + const { sender, subdenom } = this; + return { + '@type': '/miniwasm.tokenfactory.v1.MsgCreateDenom', + sender, + subdenom, + }; + } + + public static fromProto(data: MsgCreateDenom.Proto): MsgCreateDenom { + return new MsgCreateDenom(data.sender, data.subdenom); + } + + public toProto(): MsgCreateDenom.Proto { + const { sender, subdenom } = this; + return MsgCreateDenom_pb.fromPartial({ + sender, + subdenom, + }); + } + + public packAny(): Any { + return Any.fromPartial({ + typeUrl: '/miniwasm.tokenfactory.v1.MsgCreateDenom', + value: MsgCreateDenom_pb.encode(this.toProto()).finish(), + }); + } + + public static unpackAny(msgAny: Any): MsgCreateDenom { + return MsgCreateDenom.fromProto(MsgCreateDenom_pb.decode(msgAny.value)); + } +} + +export namespace MsgCreateDenom { + export interface Amino { + type: 'tokenfactory/MsgCreateDenom'; + value: { + sender: AccAddress; + subdenom: string; + }; + } + + export interface Data { + '@type': '/miniwasm.tokenfactory.v1.MsgCreateDenom'; + sender: AccAddress; + subdenom: string; + } + + export type Proto = MsgCreateDenom_pb; +} diff --git a/src/core/tokenfactory/msgs/MsgForceTransfer.ts b/src/core/tokenfactory/msgs/MsgForceTransfer.ts new file mode 100644 index 0000000..cfb56e6 --- /dev/null +++ b/src/core/tokenfactory/msgs/MsgForceTransfer.ts @@ -0,0 +1,125 @@ +import { JSONSerializable } from '../../../util/json'; +import { Coin } from '../../Coin'; +import { AccAddress } from '../../bech32'; +import { Any } from '@initia/initia.proto/google/protobuf/any'; +import { MsgForceTransfer as MsgForceTransfer_pb } from '@initia/initia.proto/miniwasm/tokenfactory/v1/tx'; + +export class MsgForceTransfer extends JSONSerializable< + MsgForceTransfer.Amino, + MsgForceTransfer.Data, + MsgForceTransfer.Proto +> { + /** + * @param sender + * @param amount + * @param transfer_from_address + * @param transfer_to_address + */ + constructor( + public sender: AccAddress, + public amount: Coin, + public transfer_from_address: AccAddress, + public transfer_to_address: AccAddress + ) { + super(); + } + + public static fromAmino(data: MsgForceTransfer.Amino): MsgForceTransfer { + const { + value: { sender, amount, transfer_from_address, transfer_to_address }, + } = data; + + return new MsgForceTransfer( + sender, + Coin.fromAmino(amount), + transfer_from_address, + transfer_to_address + ); + } + + public toAmino(): MsgForceTransfer.Amino { + const { sender, amount, transfer_from_address, transfer_to_address } = this; + return { + type: 'tokenfactory/MsgForceTransfer', + value: { + sender, + amount: amount.toAmino(), + transfer_from_address, + transfer_to_address, + }, + }; + } + + public static fromData(data: MsgForceTransfer.Data): MsgForceTransfer { + const { sender, amount, transfer_from_address, transfer_to_address } = data; + return new MsgForceTransfer( + sender, + Coin.fromData(amount), + transfer_from_address, + transfer_to_address + ); + } + + public toData(): MsgForceTransfer.Data { + const { sender, amount, transfer_from_address, transfer_to_address } = this; + return { + '@type': '/miniwasm.tokenfactory.v1.MsgForceTransfer', + sender, + amount: amount.toData(), + transfer_from_address, + transfer_to_address, + }; + } + + public static fromProto(data: MsgForceTransfer.Proto): MsgForceTransfer { + return new MsgForceTransfer( + data.sender, + Coin.fromProto(data.amount as Coin.Proto), + data.transferFromAddress, + data.transferToAddress + ); + } + + public toProto(): MsgForceTransfer.Proto { + const { sender, amount, transfer_from_address, transfer_to_address } = this; + return MsgForceTransfer_pb.fromPartial({ + sender, + amount: amount.toProto(), + transferFromAddress: transfer_from_address, + transferToAddress: transfer_to_address, + }); + } + + public packAny(): Any { + return Any.fromPartial({ + typeUrl: '/miniwasm.tokenfactory.v1.MsgForceTransfer', + value: MsgForceTransfer_pb.encode(this.toProto()).finish(), + }); + } + + public static unpackAny(msgAny: Any): MsgForceTransfer { + return MsgForceTransfer.fromProto(MsgForceTransfer_pb.decode(msgAny.value)); + } +} + +export namespace MsgForceTransfer { + export interface Amino { + type: 'tokenfactory/MsgForceTransfer'; + value: { + sender: AccAddress; + amount: Coin.Amino; + transfer_from_address: AccAddress; + transfer_to_address: AccAddress; + }; + } + + export interface Data { + '@type': '/miniwasm.tokenfactory.v1.MsgForceTransfer'; + sender: AccAddress; + amount: Coin.Data; + transfer_from_address: AccAddress; + transfer_to_address: AccAddress; + } + + export type Proto = MsgForceTransfer_pb; +} diff --git a/src/core/tokenfactory/msgs/MsgMint.ts b/src/core/tokenfactory/msgs/MsgMint.ts new file mode 100644 index 0000000..43973fd --- /dev/null +++ b/src/core/tokenfactory/msgs/MsgMint.ts @@ -0,0 +1,107 @@ +import { JSONSerializable } from '../../../util/json'; +import { Coin } from '../../Coin'; +import { AccAddress } from '../../bech32'; +import { Any } from '@initia/initia.proto/google/protobuf/any'; +import { MsgMint as MsgMint_pb } from '@initia/initia.proto/miniwasm/tokenfactory/v1/tx'; + +export class MsgMint extends JSONSerializable< + MsgMint.Amino, + MsgMint.Data, + MsgMint.Proto +> { + /** + * @param sender + * @param amount + * @param mint_to_address + */ + constructor( + public sender: AccAddress, + public amount: Coin, + public mint_to_address: AccAddress + ) { + super(); + } + + public static fromAmino(data: MsgMint.Amino): MsgMint { + const { + value: { sender, amount, mint_to_address }, + } = data; + + return new MsgMint(sender, Coin.fromAmino(amount), mint_to_address); + } + + public toAmino(): MsgMint.Amino { + const { sender, amount, mint_to_address } = this; + return { + type: 'tokenfactory/MsgMint', + value: { + sender, + amount: amount.toAmino(), + mint_to_address, + }, + }; + } + + public static fromData(data: MsgMint.Data): MsgMint { + const { sender, amount, mint_to_address } = data; + return new MsgMint(sender, Coin.fromData(amount), mint_to_address); + } + + public toData(): MsgMint.Data { + const { sender, amount, mint_to_address } = this; + return { + '@type': '/miniwasm.tokenfactory.v1.MsgMint', + sender, + amount: amount.toData(), + mint_to_address, + }; + } + + public static fromProto(data: MsgMint.Proto): MsgMint { + return new MsgMint( + data.sender, + Coin.fromProto(data.amount as Coin.Proto), + data.mintToAddress + ); + } + + public toProto(): MsgMint.Proto { + const { sender, amount, mint_to_address } = this; + return MsgMint_pb.fromPartial({ + sender, + amount: amount.toProto(), + mintToAddress: mint_to_address, + }); + } + + public packAny(): Any { + return Any.fromPartial({ + typeUrl: '/miniwasm.tokenfactory.v1.MsgMint', + value: MsgMint_pb.encode(this.toProto()).finish(), + }); + } + + public static unpackAny(msgAny: Any): MsgMint { + return MsgMint.fromProto(MsgMint_pb.decode(msgAny.value)); + } +} + +export namespace MsgMint { + export interface Amino { + type: 'tokenfactory/MsgMint'; + value: { + sender: AccAddress; + amount: Coin.Amino; + mint_to_address: AccAddress; + }; + } + + export interface Data { + '@type': '/miniwasm.tokenfactory.v1.MsgMint'; + sender: AccAddress; + amount: Coin.Data; + mint_to_address: AccAddress; + } + + export type Proto = MsgMint_pb; +} diff --git a/src/core/tokenfactory/msgs/MsgSetBeforeSendHook.ts b/src/core/tokenfactory/msgs/MsgSetBeforeSendHook.ts new file mode 100644 index 0000000..bcd5fbb --- /dev/null +++ b/src/core/tokenfactory/msgs/MsgSetBeforeSendHook.ts @@ -0,0 +1,114 @@ +import { JSONSerializable } from '../../../util/json'; +import { AccAddress } from '../../bech32'; +import { Any } from '@initia/initia.proto/google/protobuf/any'; +import { MsgSetBeforeSendHook as MsgSetBeforeSendHook_pb } from '@initia/initia.proto/miniwasm/tokenfactory/v1/tx'; + +export class MsgSetBeforeSendHook extends JSONSerializable< + MsgSetBeforeSendHook.Amino, + MsgSetBeforeSendHook.Data, + MsgSetBeforeSendHook.Proto +> { + /** + * @param sender + * @param denom + * @param cosmwasm_address + */ + constructor( + public sender: AccAddress, + public denom: string, + public cosmwasm_address: AccAddress + ) { + super(); + } + + public static fromAmino( + data: MsgSetBeforeSendHook.Amino + ): MsgSetBeforeSendHook { + const { + value: { sender, denom, cosmwasm_address }, + } = data; + + return new MsgSetBeforeSendHook(sender, denom, cosmwasm_address); + } + + public toAmino(): MsgSetBeforeSendHook.Amino { + const { sender, denom, cosmwasm_address } = this; + return { + type: 'tokenfactory/MsgSetBeforeSendHook', + value: { + sender, + denom, + cosmwasm_address, + }, + }; + } + + public static fromData( + data: MsgSetBeforeSendHook.Data + ): MsgSetBeforeSendHook { + const { sender, denom, cosmwasm_address } = data; + return new MsgSetBeforeSendHook(sender, denom, cosmwasm_address); + } + + public toData(): MsgSetBeforeSendHook.Data { + const { sender, denom, cosmwasm_address } = this; + return { + '@type': '/miniwasm.tokenfactory.v1.MsgSetBeforeSendHook', + sender, + denom, + cosmwasm_address, + }; + } + + public static fromProto( + data: MsgSetBeforeSendHook.Proto + ): MsgSetBeforeSendHook { + return new MsgSetBeforeSendHook( + data.sender, + data.denom, + data.cosmwasmAddress + ); + } + + public toProto(): MsgSetBeforeSendHook.Proto { + const { sender, denom, cosmwasm_address } = this; + return MsgSetBeforeSendHook_pb.fromPartial({ + sender, + denom, + cosmwasmAddress: cosmwasm_address, + }); + } + + public packAny(): Any { + return Any.fromPartial({ + typeUrl: '/miniwasm.tokenfactory.v1.MsgSetBeforeSendHook', + value: MsgSetBeforeSendHook_pb.encode(this.toProto()).finish(), + }); + } + + public static unpackAny(msgAny: Any): MsgSetBeforeSendHook { + return MsgSetBeforeSendHook.fromProto( + MsgSetBeforeSendHook_pb.decode(msgAny.value) + ); + } +} + +export namespace MsgSetBeforeSendHook { + export interface Amino { + type: 'tokenfactory/MsgSetBeforeSendHook'; + value: { + sender: AccAddress; + denom: string; + cosmwasm_address: AccAddress; + }; + } + + export interface Data { + '@type': '/miniwasm.tokenfactory.v1.MsgSetBeforeSendHook'; + sender: AccAddress; + denom: string; + cosmwasm_address: AccAddress; + } + + export type Proto = MsgSetBeforeSendHook_pb; +} diff --git a/src/core/tokenfactory/msgs/MsgSetDenomMetadataWasm.ts b/src/core/tokenfactory/msgs/MsgSetDenomMetadataWasm.ts new file mode 100644 index 0000000..2515ee2 --- /dev/null +++ b/src/core/tokenfactory/msgs/MsgSetDenomMetadataWasm.ts @@ -0,0 +1,109 @@ +import { JSONSerializable } from '../../../util/json'; +import { AccAddress } from '../../bech32'; +import { DenomMetadata } from '../../bank/DenomMetadata'; +import { Any } from '@initia/initia.proto/google/protobuf/any'; +import { MsgSetDenomMetadata as MsgSetDenomMetadata_pb } from '@initia/initia.proto/miniwasm/tokenfactory/v1/tx'; + +export class MsgSetDenomMetadataWasm extends JSONSerializable< + MsgSetDenomMetadataWasm.Amino, + MsgSetDenomMetadataWasm.Data, + MsgSetDenomMetadataWasm.Proto +> { + /** + * @param sender + * @param metadata + */ + constructor(public sender: AccAddress, public metadata: DenomMetadata) { + super(); + } + + public static fromAmino( + data: MsgSetDenomMetadataWasm.Amino + ): MsgSetDenomMetadataWasm { + const { + value: { sender, metadata }, + } = data; + return new MsgSetDenomMetadataWasm( + sender, + DenomMetadata.fromAmino(metadata) + ); + } + + public toAmino(): MsgSetDenomMetadataWasm.Amino { + const { sender, metadata } = this; + return { + type: 'tokenfactory/MsgSetDenomMetadata', + value: { + sender, + metadata: metadata.toAmino(), + }, + }; + } + + public static fromData( + data: MsgSetDenomMetadataWasm.Data + ): MsgSetDenomMetadataWasm { + const { sender, metadata } = data; + return new MsgSetDenomMetadataWasm( + sender, + DenomMetadata.fromData(metadata) + ); + } + + public toData(): MsgSetDenomMetadataWasm.Data { + const { sender, metadata } = this; + return { + '@type': '/miniwasm.tokenfactory.v1.MsgSetDenomMetadata', + sender, + metadata: metadata.toData(), + }; + } + + public static fromProto( + data: MsgSetDenomMetadataWasm.Proto + ): MsgSetDenomMetadataWasm { + return new MsgSetDenomMetadataWasm( + data.sender, + DenomMetadata.fromProto(data.metadata as DenomMetadata.Proto) + ); + } + + public toProto(): MsgSetDenomMetadataWasm.Proto { + const { sender, metadata } = this; + return MsgSetDenomMetadata_pb.fromPartial({ + sender, + metadata: metadata.toProto(), + }); + } + + public packAny(): Any { + return Any.fromPartial({ + typeUrl: '/miniwasm.tokenfactory.v1.MsgSetDenomMetadata', + value: MsgSetDenomMetadata_pb.encode(this.toProto()).finish(), + }); + } + + public static unpackAny(msgAny: Any): MsgSetDenomMetadataWasm { + return MsgSetDenomMetadataWasm.fromProto( + MsgSetDenomMetadata_pb.decode(msgAny.value) + ); + } +} + +export namespace MsgSetDenomMetadataWasm { + export interface Amino { + type: 'tokenfactory/MsgSetDenomMetadata'; + value: { + sender: AccAddress; + metadata: DenomMetadata.Amino; + }; + } + + export interface Data { + '@type': '/miniwasm.tokenfactory.v1.MsgSetDenomMetadata'; + sender: AccAddress; + metadata: DenomMetadata.Data; + } + + export type Proto = MsgSetDenomMetadata_pb; +} diff --git a/src/core/tokenfactory/msgs/MsgUpdateTokenfactoryParams.ts b/src/core/tokenfactory/msgs/MsgUpdateTokenfactoryParams.ts new file mode 100644 index 0000000..3c8f94b --- /dev/null +++ b/src/core/tokenfactory/msgs/MsgUpdateTokenfactoryParams.ts @@ -0,0 +1,109 @@ +import { JSONSerializable } from '../../../util/json'; +import { AccAddress } from '../../bech32'; +import { TokenfactoryParams } from '../TokenfactoryParams'; +import { Any } from '@initia/initia.proto/google/protobuf/any'; +import { MsgUpdateParams as MsgUpdateParams_pb } from '@initia/initia.proto/miniwasm/tokenfactory/v1/tx'; + +export class MsgUpdateTokenfactoryParams extends JSONSerializable< + MsgUpdateTokenfactoryParams.Amino, + MsgUpdateTokenfactoryParams.Data, + MsgUpdateTokenfactoryParams.Proto +> { + /** + * @param authority the address that controls the module + * @param params params defines the x/tokenfactory parameters to update + */ + constructor(public authority: AccAddress, public params: TokenfactoryParams) { + super(); + } + + public static fromAmino( + data: MsgUpdateTokenfactoryParams.Amino + ): MsgUpdateTokenfactoryParams { + const { + value: { authority, params }, + } = data; + return new MsgUpdateTokenfactoryParams( + authority, + TokenfactoryParams.fromAmino(params) + ); + } + + public toAmino(): MsgUpdateTokenfactoryParams.Amino { + const { authority, params } = this; + return { + type: 'tokenfactory/MsgUpdateParams', + value: { + authority, + params: params.toAmino(), + }, + }; + } + + public static fromData( + data: MsgUpdateTokenfactoryParams.Data + ): MsgUpdateTokenfactoryParams { + const { authority, params } = data; + return new MsgUpdateTokenfactoryParams( + authority, + TokenfactoryParams.fromData(params) + ); + } + + public toData(): MsgUpdateTokenfactoryParams.Data { + const { authority, params } = this; + return { + '@type': '/miniwasm.tokenfactory.v1.MsgUpdateParams', + authority, + params: params.toData(), + }; + } + + public static fromProto( + data: MsgUpdateTokenfactoryParams.Proto + ): MsgUpdateTokenfactoryParams { + return new MsgUpdateTokenfactoryParams( + data.authority, + TokenfactoryParams.fromProto(data.params as TokenfactoryParams.Proto) + ); + } + + public toProto(): MsgUpdateTokenfactoryParams.Proto { + const { authority, params } = this; + return MsgUpdateParams_pb.fromPartial({ + authority, + params: params.toProto(), + }); + } + + public packAny(): Any { + return Any.fromPartial({ + typeUrl: '/miniwasm.tokenfactory.v1.MsgUpdateParams', + value: MsgUpdateParams_pb.encode(this.toProto()).finish(), + }); + } + + public static unpackAny(msgAny: Any): MsgUpdateTokenfactoryParams { + return MsgUpdateTokenfactoryParams.fromProto( + MsgUpdateParams_pb.decode(msgAny.value) + ); + } +} + +export namespace MsgUpdateTokenfactoryParams { + export interface Amino { + type: 'tokenfactory/MsgUpdateParams'; + value: { + authority: AccAddress; + params: TokenfactoryParams.Amino; + }; + } + + export interface Data { + '@type': '/miniwasm.tokenfactory.v1.MsgUpdateParams'; + authority: AccAddress; + params: TokenfactoryParams.Data; + } + + export type Proto = MsgUpdateParams_pb; +} diff --git a/src/core/tokenfactory/msgs/index.ts b/src/core/tokenfactory/msgs/index.ts new file mode 100644 index 0000000..cc7d57d --- /dev/null +++ b/src/core/tokenfactory/msgs/index.ts @@ -0,0 +1,59 @@ +import { MsgCreateDenom } from './MsgCreateDenom'; +import { MsgMint } from './MsgMint'; +import { MsgBurn } from './MsgBurn'; +import { MsgChangeAdmin } from './MsgChangeAdmin'; +import { MsgSetDenomMetadataWasm } from './MsgSetDenomMetadataWasm'; +import { MsgSetBeforeSendHook } from './MsgSetBeforeSendHook'; +import { MsgForceTransfer } from './MsgForceTransfer'; +import { MsgUpdateTokenfactoryParams } from './MsgUpdateTokenfactoryParams'; + +export * from './MsgCreateDenom'; +export * from './MsgMint'; +export * from './MsgBurn'; +export * from './MsgChangeAdmin'; +export * from './MsgSetDenomMetadataWasm'; +export * from './MsgSetBeforeSendHook'; +export * from './MsgForceTransfer'; +export * from './MsgUpdateTokenfactoryParams'; + +export type TokenfactoryMsg = + | MsgCreateDenom + | MsgMint + | MsgBurn + | MsgChangeAdmin + | MsgSetDenomMetadataWasm + | MsgSetBeforeSendHook + | MsgForceTransfer + | MsgUpdateTokenfactoryParams; + +export namespace TokenfactoryMsg { + export type Amino = + | MsgCreateDenom.Amino + | MsgMint.Amino + | MsgBurn.Amino + | MsgChangeAdmin.Amino + | MsgSetDenomMetadataWasm.Amino + | MsgSetBeforeSendHook.Amino + | MsgForceTransfer.Amino + | MsgUpdateTokenfactoryParams.Amino; + + export type Data = + | MsgCreateDenom.Data + | MsgMint.Data + | MsgBurn.Data + | MsgChangeAdmin.Data + | MsgSetDenomMetadataWasm.Data + | MsgSetBeforeSendHook.Data + | MsgForceTransfer.Data + | MsgUpdateTokenfactoryParams.Data; + + export type Proto = + | MsgCreateDenom.Proto + | MsgMint.Proto + | MsgBurn.Proto + | MsgChangeAdmin.Proto + | MsgSetDenomMetadataWasm.Proto + | MsgSetBeforeSendHook.Proto + | MsgForceTransfer.Proto + | MsgUpdateTokenfactoryParams.Proto; +} From c0f7df6ea524c9bf6721c68c1cc3447268665d38 Mon Sep 17 00:00:00 2001 From: joon9823 Date: Wed, 27 Mar 2024 19:06:25 +0900 Subject: [PATCH 2/2] Add evm module from minievm --- src/client/lcd/LCDClient.ts | 3 + src/client/lcd/api/EvmAPI.ts | 79 ++++++++++++++++++ src/client/lcd/api/index.ts | 1 + src/core/Msg.ts | 29 +++++++ src/core/evm/EvmParams.ts | 74 +++++++++++++++++ src/core/evm/index.ts | 2 + src/core/evm/msgs/MsgCall.ts | 102 ++++++++++++++++++++++++ src/core/evm/msgs/MsgCreate.ts | 92 +++++++++++++++++++++ src/core/evm/msgs/MsgUpdateEvmParams.ts | 97 ++++++++++++++++++++++ src/core/evm/msgs/index.ts | 23 ++++++ src/core/index.ts | 1 + 11 files changed, 503 insertions(+) create mode 100644 src/client/lcd/api/EvmAPI.ts create mode 100644 src/core/evm/EvmParams.ts create mode 100644 src/core/evm/index.ts create mode 100644 src/core/evm/msgs/MsgCall.ts create mode 100644 src/core/evm/msgs/MsgCreate.ts create mode 100644 src/core/evm/msgs/MsgUpdateEvmParams.ts create mode 100644 src/core/evm/msgs/index.ts diff --git a/src/client/lcd/LCDClient.ts b/src/client/lcd/LCDClient.ts index 89fc47a..e055ce4 100644 --- a/src/client/lcd/LCDClient.ts +++ b/src/client/lcd/LCDClient.ts @@ -6,6 +6,7 @@ import { BankAPI, DistributionAPI, EvidenceAPI, + EvmAPI, FeeGrantAPI, GovAPI, GroupAPI, @@ -87,6 +88,7 @@ export class LCDClient { public bank: BankAPI; public distribution: DistributionAPI; public evidence: EvidenceAPI; + public evm: EvmAPI; public feeGrant: FeeGrantAPI; public gov: GovAPI; public group: GroupAPI; @@ -137,6 +139,7 @@ export class LCDClient { this.bank = new BankAPI(this.apiRequester); this.distribution = new DistributionAPI(this.apiRequester); this.evidence = new EvidenceAPI(this.apiRequester); + this.evm = new EvmAPI(this.apiRequester); this.feeGrant = new FeeGrantAPI(this.apiRequester); this.gov = new GovAPI(this.apiRequester); this.group = new GroupAPI(this.apiRequester); diff --git a/src/client/lcd/api/EvmAPI.ts b/src/client/lcd/api/EvmAPI.ts new file mode 100644 index 0000000..b895c56 --- /dev/null +++ b/src/client/lcd/api/EvmAPI.ts @@ -0,0 +1,79 @@ +import { AccAddress, EvmParams } from '../../../core'; +import { APIParams } from '../APIRequester'; +import { BaseAPI } from './BaseAPI'; + +export interface CallResponse { + response: string; + used_gas: string; + logs: { + address: AccAddress; + topics: string[]; + data: string; + }[]; + trace_output: string; +} + +export class EvmAPI extends BaseAPI { + public async code( + contractAddr: AccAddress, + params: APIParams = {} + ): Promise { + return this.c + .get<{ code: string }>(`/minievm/evm/v1/codes/${contractAddr}`, params) + .then(d => d.code); + } + + public async state( + contractAddr: AccAddress, + key: string, + params: APIParams = {} + ): Promise { + return this.c + .get<{ value: string }>( + `/minievm/evm/v1/states/${contractAddr}/${key}`, + params + ) + .then(d => d.value); + } + + public async contractAddrByDenom( + denom: string, + params: APIParams = {} + ): Promise { + return this.c + .get<{ address: AccAddress }>(`/minievm/evm/v1/contracts/by_denom`, { + ...params, + denom, + }) + .then(d => d.address); + } + + public async denom( + contractAddr: AccAddress, + params: APIParams = {} + ): Promise { + return this.c + .get<{ denom: string }>(`/minievm/evm/v1/denoms/${contractAddr}`, params) + .then(d => d.denom); + } + + public async call( + sender: AccAddress, + contractAddr: AccAddress, + input: string, + withTrace: boolean + ): Promise { + return this.c.post(`/minievm/evm/v1/call`, { + sender, + contract_addr: contractAddr, + input, + with_trace: withTrace, + }); + } + + public async parameters(params: APIParams = {}): Promise { + return this.c + .get<{ params: EvmParams.Data }>(`/minievm/evm/v1/params`, params) + .then(({ params: d }) => EvmParams.fromData(d)); + } +} diff --git a/src/client/lcd/api/index.ts b/src/client/lcd/api/index.ts index 248e793..7cc5812 100644 --- a/src/client/lcd/api/index.ts +++ b/src/client/lcd/api/index.ts @@ -4,6 +4,7 @@ export * from './AuthzAPI'; export * from './BankAPI'; export * from './DistributionAPI'; export * from './EvidenceAPI'; +export * from './EvmAPI'; export * from './FeeGrantAPI'; export * from './GovAPI'; export * from './GroupAPI'; diff --git a/src/core/Msg.ts b/src/core/Msg.ts index e4ef4ba..8cc9d3f 100644 --- a/src/core/Msg.ts +++ b/src/core/Msg.ts @@ -26,6 +26,7 @@ import { MsgDepositValidatorRewardsPool, } from './distribution'; import { EvidenceMsg, MsgSubmitEvidence } from './evidence'; +import { EvmMsg, MsgCreate, MsgCall, MsgUpdateEvmParams } from './evm'; import { FeeGrantMsg, MsgGrantAllowance, MsgRevokeAllowance } from './feegrant'; import { GovMsg, @@ -206,6 +207,7 @@ export type Msg = | CrisisMsg | DistributionMsg | EvidenceMsg + | EvmMsg | FeeGrantMsg | GovMsg | GroupMsg @@ -239,6 +241,7 @@ export namespace Msg { | CrisisMsg.Amino | DistributionMsg.Amino | EvidenceMsg.Amino + | EvmMsg.Amino | FeeGrantMsg.Amino | GovMsg.Amino | GroupMsg.Amino @@ -267,6 +270,7 @@ export namespace Msg { | CrisisMsg.Data | DistributionMsg.Data | EvidenceMsg.Data + | EvmMsg.Data | FeeGrantMsg.Data | GovMsg.Data | GroupMsg.Data @@ -299,6 +303,7 @@ export namespace Msg { | CrisisMsg.Proto | DistributionMsg.Proto | EvidenceMsg.Proto + | EvmMsg.Proto | FeeGrantMsg.Proto | GovMsg.Proto | GroupMsg.Proto @@ -381,6 +386,14 @@ export namespace Msg { case 'cosmos-sdk/MsgSubmitEvidence': return MsgSubmitEvidence.fromAmino(data); + // evm + case 'evm/MsgCreate': + return MsgCreate.fromAmino(data); + case 'evm/MsgCall': + return MsgCall.fromAmino(data); + case 'evm/MsgUpdateParams': + return MsgUpdateEvmParams.fromAmino(data); + // feegrant case 'cosmos-sdk/MsgGrantAllowance': return MsgGrantAllowance.fromAmino(data); @@ -677,6 +690,14 @@ export namespace Msg { case '/cosmos.evidence.v1beta1.MsgSubmitEvidence': return MsgSubmitEvidence.fromData(data); + // evm + case '/minievm.evm.v1.MsgCreate': + return MsgCreate.fromData(data); + case '/minievm.evm.v1.MsgCall': + return MsgCall.fromData(data); + case '/minievm.evm.v1.MsgUpdateParams': + return MsgUpdateEvmParams.fromData(data); + // feegrant case '/cosmos.feegrant.v1beta1.MsgGrantAllowance': return MsgGrantAllowance.fromData(data); @@ -1040,6 +1061,14 @@ export namespace Msg { case '/cosmos.evidence.v1beta1.MsgSubmitEvidence': return MsgSubmitEvidence.unpackAny(proto); + // evm + case '/minievm.evm.v1.MsgCreate': + return MsgCreate.unpackAny(proto); + case '/minievm.evm.v1.MsgCall': + return MsgCall.unpackAny(proto); + case '/minievm.evm.v1.MsgUpdateParams': + return MsgUpdateEvmParams.unpackAny(proto); + // feegrant case '/cosmos.feegrant.v1beta1.MsgGrantAllowance': return MsgGrantAllowance.unpackAny(proto); diff --git a/src/core/evm/EvmParams.ts b/src/core/evm/EvmParams.ts new file mode 100644 index 0000000..c9e8edf --- /dev/null +++ b/src/core/evm/EvmParams.ts @@ -0,0 +1,74 @@ +import { JSONSerializable } from '../../util/json'; +import { Params as Params_pb } from '@initia/initia.proto/minievm/evm/v1/types'; + +export class EvmParams extends JSONSerializable< + EvmParams.Amino, + EvmParams.Data, + EvmParams.Proto +> { + /** + * @param extra_eips the additional EIPs for the vm.Config + * @param allowed_publishers list of addresses with permission to distribute contracts + */ + constructor( + public extra_eips: number[], + public allowed_publishers: string[] + ) { + super(); + } + + public static fromAmino(data: EvmParams.Amino): EvmParams { + const { extra_eips, allowed_publishers } = data; + return new EvmParams(extra_eips.map(Number.parseInt), allowed_publishers); + } + + public toAmino(): EvmParams.Amino { + const { extra_eips, allowed_publishers } = this; + return { + extra_eips: extra_eips.map(eip => eip.toString()), + allowed_publishers, + }; + } + + public static fromData(data: EvmParams.Data): EvmParams { + const { extra_eips, allowed_publishers } = data; + return new EvmParams(extra_eips.map(Number.parseInt), allowed_publishers); + } + + public toData(): EvmParams.Data { + const { extra_eips, allowed_publishers } = this; + return { + extra_eips: extra_eips.map(eip => eip.toString()), + allowed_publishers, + }; + } + + public static fromProto(proto: EvmParams.Proto): EvmParams { + return new EvmParams( + proto.extraEips.map(eip => eip.toNumber()), + proto.allowedPublishers + ); + } + + public toProto(): EvmParams.Proto { + const { extra_eips, allowed_publishers } = this; + return Params_pb.fromPartial({ + extraEips: extra_eips, + allowedPublishers: allowed_publishers, + }); + } +} + +export namespace EvmParams { + export interface Amino { + extra_eips: string[]; + allowed_publishers: string[]; + } + + export interface Data { + extra_eips: string[]; + allowed_publishers: string[]; + } + + export type Proto = Params_pb; +} diff --git a/src/core/evm/index.ts b/src/core/evm/index.ts new file mode 100644 index 0000000..dca890e --- /dev/null +++ b/src/core/evm/index.ts @@ -0,0 +1,2 @@ +export * from './msgs'; +export * from './EvmParams'; diff --git a/src/core/evm/msgs/MsgCall.ts b/src/core/evm/msgs/MsgCall.ts new file mode 100644 index 0000000..fb412d5 --- /dev/null +++ b/src/core/evm/msgs/MsgCall.ts @@ -0,0 +1,102 @@ +import { JSONSerializable } from '../../../util/json'; +import { AccAddress } from '../../bech32'; +import { Any } from '@initia/initia.proto/google/protobuf/any'; +import { MsgCall as MsgCall_pb } from '@initia/initia.proto/minievm/evm/v1/tx'; + +export class MsgCall extends JSONSerializable< + MsgCall.Amino, + MsgCall.Data, + MsgCall.Proto +> { + /** + * @param sender the actor that signed the messages + * @param contract_addr the contract address to be executed, can be cosmos address or hex encoded address + * @param input hex encoded execution input bytes + */ + constructor( + public sender: AccAddress, + public contract_addr: AccAddress, + public input: string + ) { + super(); + } + + public static fromAmino(data: MsgCall.Amino): MsgCall { + const { + value: { sender, contract_addr, input }, + } = data; + + return new MsgCall(sender, contract_addr, input); + } + + public toAmino(): MsgCall.Amino { + const { sender, contract_addr, input } = this; + return { + type: 'evm/MsgCall', + value: { + sender, + contract_addr, + input, + }, + }; + } + + public static fromData(data: MsgCall.Data): MsgCall { + const { sender, contract_addr, input } = data; + return new MsgCall(sender, contract_addr, input); + } + + public toData(): MsgCall.Data { + const { sender, contract_addr, input } = this; + return { + '@type': '/minievm.evm.v1.MsgCall', + sender, + contract_addr, + input, + }; + } + + public static fromProto(data: MsgCall.Proto): MsgCall { + return new MsgCall(data.sender, data.contractAddr, data.input); + } + + public toProto(): MsgCall.Proto { + const { sender, contract_addr, input } = this; + return MsgCall_pb.fromPartial({ + sender, + contractAddr: contract_addr, + input, + }); + } + + public packAny(): Any { + return Any.fromPartial({ + typeUrl: '/minievm.evm.v1.MsgCall', + value: MsgCall_pb.encode(this.toProto()).finish(), + }); + } + + public static unpackAny(msgAny: Any): MsgCall { + return MsgCall.fromProto(MsgCall_pb.decode(msgAny.value)); + } +} + +export namespace MsgCall { + export interface Amino { + type: 'evm/MsgCall'; + value: { + sender: AccAddress; + contract_addr: AccAddress; + input: string; + }; + } + + export interface Data { + '@type': '/minievm.evm.v1.MsgCall'; + sender: AccAddress; + contract_addr: AccAddress; + input: string; + } + + export type Proto = MsgCall_pb; +} diff --git a/src/core/evm/msgs/MsgCreate.ts b/src/core/evm/msgs/MsgCreate.ts new file mode 100644 index 0000000..464360b --- /dev/null +++ b/src/core/evm/msgs/MsgCreate.ts @@ -0,0 +1,92 @@ +import { JSONSerializable } from '../../../util/json'; +import { AccAddress } from '../../bech32'; +import { Any } from '@initia/initia.proto/google/protobuf/any'; +import { MsgCreate as MsgCreate_pb } from '@initia/initia.proto/minievm/evm/v1/tx'; + +export class MsgCreate extends JSONSerializable< + MsgCreate.Amino, + MsgCreate.Data, + MsgCreate.Proto +> { + /** + * @param sender the actor that signed the messages + * @param code hex encoded raw contract bytes code + */ + constructor(public sender: AccAddress, public code: string) { + super(); + } + + public static fromAmino(data: MsgCreate.Amino): MsgCreate { + const { + value: { sender, code }, + } = data; + + return new MsgCreate(sender, code); + } + + public toAmino(): MsgCreate.Amino { + const { sender, code } = this; + return { + type: 'evm/MsgCreate', + value: { + sender, + code, + }, + }; + } + + public static fromData(data: MsgCreate.Data): MsgCreate { + const { sender, code } = data; + return new MsgCreate(sender, code); + } + + public toData(): MsgCreate.Data { + const { sender, code } = this; + return { + '@type': '/minievm.evm.v1.MsgCreate', + sender, + code, + }; + } + + public static fromProto(data: MsgCreate.Proto): MsgCreate { + return new MsgCreate(data.sender, data.code); + } + + public toProto(): MsgCreate.Proto { + const { sender, code } = this; + return MsgCreate_pb.fromPartial({ + sender, + code, + }); + } + + public packAny(): Any { + return Any.fromPartial({ + typeUrl: '/minievm.evm.v1.MsgCreate', + value: MsgCreate_pb.encode(this.toProto()).finish(), + }); + } + + public static unpackAny(msgAny: Any): MsgCreate { + return MsgCreate.fromProto(MsgCreate_pb.decode(msgAny.value)); + } +} + +export namespace MsgCreate { + export interface Amino { + type: 'evm/MsgCreate'; + value: { + sender: AccAddress; + code: string; + }; + } + + export interface Data { + '@type': '/minievm.evm.v1.MsgCreate'; + sender: AccAddress; + code: string; + } + + export type Proto = MsgCreate_pb; +} diff --git a/src/core/evm/msgs/MsgUpdateEvmParams.ts b/src/core/evm/msgs/MsgUpdateEvmParams.ts new file mode 100644 index 0000000..c29b91b --- /dev/null +++ b/src/core/evm/msgs/MsgUpdateEvmParams.ts @@ -0,0 +1,97 @@ +import { JSONSerializable } from '../../../util/json'; +import { AccAddress } from '../../bech32'; +import { EvmParams } from '../EvmParams'; +import { Any } from '@initia/initia.proto/google/protobuf/any'; +import { MsgUpdateParams as MsgUpdateParams_pb } from '@initia/initia.proto/minievm/evm/v1/tx'; + +export class MsgUpdateEvmParams extends JSONSerializable< + MsgUpdateEvmParams.Amino, + MsgUpdateEvmParams.Data, + MsgUpdateEvmParams.Proto +> { + /** + * @param authority the address that controls the module + * @param params params defines the x/evm parameters to update + */ + constructor(public authority: AccAddress, public params: EvmParams) { + super(); + } + + public static fromAmino(data: MsgUpdateEvmParams.Amino): MsgUpdateEvmParams { + const { + value: { authority, params }, + } = data; + return new MsgUpdateEvmParams(authority, EvmParams.fromAmino(params)); + } + + public toAmino(): MsgUpdateEvmParams.Amino { + const { authority, params } = this; + return { + type: 'evm/MsgUpdateParams', + value: { + authority, + params: params.toAmino(), + }, + }; + } + + public static fromData(data: MsgUpdateEvmParams.Data): MsgUpdateEvmParams { + const { authority, params } = data; + return new MsgUpdateEvmParams(authority, EvmParams.fromData(params)); + } + + public toData(): MsgUpdateEvmParams.Data { + const { authority, params } = this; + return { + '@type': '/minievm.evm.v1.MsgUpdateParams', + authority, + params: params.toData(), + }; + } + + public static fromProto(data: MsgUpdateEvmParams.Proto): MsgUpdateEvmParams { + return new MsgUpdateEvmParams( + data.authority, + EvmParams.fromProto(data.params as EvmParams.Proto) + ); + } + + public toProto(): MsgUpdateEvmParams.Proto { + const { authority, params } = this; + return MsgUpdateParams_pb.fromPartial({ + authority, + params: params.toProto(), + }); + } + + public packAny(): Any { + return Any.fromPartial({ + typeUrl: '/minievm.evm.v1.MsgUpdateParams', + value: MsgUpdateParams_pb.encode(this.toProto()).finish(), + }); + } + + public static unpackAny(msgAny: Any): MsgUpdateEvmParams { + return MsgUpdateEvmParams.fromProto( + MsgUpdateParams_pb.decode(msgAny.value) + ); + } +} + +export namespace MsgUpdateEvmParams { + export interface Amino { + type: 'evm/MsgUpdateParams'; + value: { + authority: AccAddress; + params: EvmParams.Amino; + }; + } + + export interface Data { + '@type': '/minievm.evm.v1.MsgUpdateParams'; + authority: AccAddress; + params: EvmParams.Data; + } + + export type Proto = MsgUpdateParams_pb; +} diff --git a/src/core/evm/msgs/index.ts b/src/core/evm/msgs/index.ts new file mode 100644 index 0000000..c66b364 --- /dev/null +++ b/src/core/evm/msgs/index.ts @@ -0,0 +1,23 @@ +import { MsgCreate } from './MsgCreate'; +import { MsgCall } from './MsgCall'; +import { MsgUpdateEvmParams } from './MsgUpdateEvmParams'; + +export * from './MsgCreate'; +export * from './MsgCall'; +export * from './MsgUpdateEvmParams'; + +export type EvmMsg = MsgCreate | MsgCall | MsgUpdateEvmParams; + +export namespace EvmMsg { + export type Amino = + | MsgCreate.Amino + | MsgCall.Amino + | MsgUpdateEvmParams.Amino; + + export type Data = MsgCreate.Data | MsgCall.Data | MsgUpdateEvmParams.Data; + + export type Proto = + | MsgCreate.Proto + | MsgCall.Proto + | MsgUpdateEvmParams.Proto; +} diff --git a/src/core/index.ts b/src/core/index.ts index 0d90d1a..8e60b60 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -16,6 +16,7 @@ export * from './consensus'; export * from './crisis'; export * from './distribution'; export * from './evidence'; +export * from './evm'; export * from './feegrant'; export * from './gov'; export * from './group';