From 392c9f4cb5201e1de95e170d03e0f6c34d984922 Mon Sep 17 00:00:00 2001 From: elshenak Date: Wed, 20 Nov 2024 00:34:56 -0500 Subject: [PATCH 1/4] refactor: adding eth & tokenfactory types --- src/sdk/msg/eth.ts | 16 +++++++++++ src/sdk/msg/tokenfactory.ts | 40 ++++++++++++++++++++++++++++ src/sdk/tx/txClient.ts | 10 ++++++- test.ts | 53 +++++++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 test.ts diff --git a/src/sdk/msg/eth.ts b/src/sdk/msg/eth.ts index 8f9af639..d93db7bf 100644 --- a/src/sdk/msg/eth.ts +++ b/src/sdk/msg/eth.ts @@ -1,5 +1,6 @@ import { createProtobufRpcClient, QueryClient } from "@cosmjs/stargate" import { + MsgServiceName, MsgClientImpl, MsgConvertCoinToEvm, MsgConvertCoinToEvmResponse, @@ -10,6 +11,21 @@ import { MsgUpdateParams, MsgUpdateParamsResponse, } from "../../protojs/eth/evm/v1/tx" +import { GeneratedType } from "@cosmjs/proto-signing" + +export const ETH_MSG_TYPE_URLS = { + MsgEthereumTx: `/${MsgServiceName}EthereumTx`, + MsgUpdateParams: `/${MsgServiceName}UpdateParams`, + MsgCreateFunToken: `/${MsgServiceName}CreateFunToken`, + MsgConvertCoinToEvm: `/${MsgServiceName}ConvertCoinToEvm`, +} + +export const ethTypes: ReadonlyArray<[string, GeneratedType]> = [ + [ETH_MSG_TYPE_URLS.MsgEthereumTx, MsgEthereumTx], + [ETH_MSG_TYPE_URLS.MsgUpdateParams, MsgUpdateParams], + [ETH_MSG_TYPE_URLS.MsgCreateFunToken, MsgCreateFunToken], + [ETH_MSG_TYPE_URLS.MsgConvertCoinToEvm, MsgConvertCoinToEvm], +] export interface EthMsgExtension { ethereumTx: (body: MsgEthereumTx) => Promise diff --git a/src/sdk/msg/tokenfactory.ts b/src/sdk/msg/tokenfactory.ts index 2b6c1d85..0accda3f 100644 --- a/src/sdk/msg/tokenfactory.ts +++ b/src/sdk/msg/tokenfactory.ts @@ -1,5 +1,6 @@ import { createProtobufRpcClient, QueryClient } from "@cosmjs/stargate" import { + MsgServiceName, MsgCreateDenom, MsgClientImpl, MsgCreateDenomResponse, @@ -16,6 +17,27 @@ import { MsgBurnNative, MsgBurnNativeResponse, } from "../../protojs/nibiru/tokenfactory/v1/tx" +import { GeneratedType } from "@cosmjs/proto-signing" + +export const TOKENFACTORY_MSG_TYPE_URLS = { + MsgCreateDenom: `/${MsgServiceName}CreateDenom`, + MsgChangeAdmin: `/${MsgServiceName}ChangeAdmin`, + MsgUpdateModuleParams: `/${MsgServiceName}UpdateModuleParams`, + MsgMint: `/${MsgServiceName}Mint`, + MsgBurns: `/${MsgServiceName}Burns`, + MsgSetDenomMetadata: `/${MsgServiceName}SetDenomMetadata`, + MsgBurnNative: `/${MsgServiceName}BurnNative`, +} + +export const tokenfactoryTypes: ReadonlyArray<[string, GeneratedType]> = [ + [TOKENFACTORY_MSG_TYPE_URLS.MsgCreateDenom, MsgCreateDenom], + [TOKENFACTORY_MSG_TYPE_URLS.MsgChangeAdmin, MsgChangeAdmin], + [TOKENFACTORY_MSG_TYPE_URLS.MsgUpdateModuleParams, MsgUpdateModuleParams], + [TOKENFACTORY_MSG_TYPE_URLS.MsgMint, MsgMint], + [TOKENFACTORY_MSG_TYPE_URLS.MsgBurns, MsgBurn], + [TOKENFACTORY_MSG_TYPE_URLS.MsgSetDenomMetadata, MsgSetDenomMetadata], + [TOKENFACTORY_MSG_TYPE_URLS.MsgBurnNative, MsgBurnNative], +] export interface TokenFactoryMsgExtension { createDenom: (body: MsgCreateDenom) => Promise @@ -57,3 +79,21 @@ export const setupTokenFactoryMsgExtension = ( queryService.BurnNative(MsgBurnNative.fromPartial(body)), } } + +export { + MsgCreateDenom, + MsgClientImpl, + MsgCreateDenomResponse, + MsgChangeAdmin, + MsgChangeAdminResponse, + MsgUpdateModuleParams, + MsgUpdateModuleParamsResponse, + MsgBurn, + MsgBurnResponse, + MsgMint, + MsgMintResponse, + MsgSetDenomMetadata, + MsgSetDenomMetadataResponse, + MsgBurnNative, + MsgBurnNativeResponse, +} diff --git a/src/sdk/tx/txClient.ts b/src/sdk/tx/txClient.ts index 1f1c10fd..1c7f99d0 100644 --- a/src/sdk/tx/txClient.ts +++ b/src/sdk/tx/txClient.ts @@ -13,7 +13,12 @@ import { } from "@cosmjs/stargate" import { Tendermint37Client } from "@cosmjs/tendermint-rpc" import { setupWasmExtension } from "@cosmjs/cosmwasm-stargate" -import { NibiruExtensions, setupNibiruExtension } from ".." +import { + ethTypes, + NibiruExtensions, + setupNibiruExtension, + tokenfactoryTypes, +} from ".." import { accountFromNibiru } from "./account" import { NibiSigningCosmWasmClient, @@ -22,6 +27,8 @@ import { export const nibiruRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [ ...defaultRegistryTypes, + ...tokenfactoryTypes, + ...ethTypes, ] export class NibiruTxClient extends SigningStargateClient { @@ -60,6 +67,7 @@ export class NibiruTxClient extends SigningStargateClient { signer, { gasPrice: GasPrice.fromString("0.025unibi"), + registry: new Registry(nibiruRegistryTypes), accountParser: accountFromNibiru, ...wasmOptions, } diff --git a/test.ts b/test.ts new file mode 100644 index 00000000..987ab73c --- /dev/null +++ b/test.ts @@ -0,0 +1,53 @@ +import { EncodeObject } from "@cosmjs/proto-signing" +import { + NibiruTxClient, + NibiruQuerier, + Chain, + Testnet, + newRandomWallet, + newSignerFromMnemonic, + MsgCreateDenom, + MsgCreateDenomResponse, +} from "./src" + +const main = async () => { + const chain: Chain = Testnet() // Permanent testnet + + // ---------------- NibiruTxClient ---------------- + // let signer = await newRandomWallet() // Signer: randomly generated + const signer = await newSignerFromMnemonic( + "business wrong poverty again define paper recipe trade tissue left lawn result whale fiber farm version split network cereal swallow path finger payment risk" + ) // Signer: in-practice + const txClient = await NibiruTxClient.connectWithSigner(chain.endptTm, signer) + + const account = await signer.getAccounts() // from cosmos + const signerAddress = account[0].address + console.log(signerAddress) + + const tx = await txClient.nibiruExtensions.msg.tokenFactoryMsg.createDenom({ + sender: signerAddress, + subdenom: "urex", // replace with your subdenom + }) + console.log(tx) + + // const fee = "auto" // You can specify the fee if needed + + // const msgs: EncodeObject[] = [ + // { + // typeUrl: "/nibiru.tokenfactory.v1.MsgCreateDenom", + // value: MsgCreateDenom.fromPartial({ + // sender: signerAddress, + // subdenom: "urexx", // replace with your subdenom + // }), + // }, + // ] + + // const tx = await txClient.signAndBroadcast(signerAddress, msgs, fee) + + // console.log(tx) + + // const rtx = MsgCreateDenomResponse.decode(tx.msgResponses[0].value) + // console.log(rtx) +} + +main() From d132d231634d333ce04aaf42dd764e901ac41581 Mon Sep 17 00:00:00 2001 From: elshenak Date: Wed, 20 Nov 2024 00:35:26 -0500 Subject: [PATCH 2/4] chore: remove test file --- test.ts | 53 ----------------------------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 test.ts diff --git a/test.ts b/test.ts deleted file mode 100644 index 987ab73c..00000000 --- a/test.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { EncodeObject } from "@cosmjs/proto-signing" -import { - NibiruTxClient, - NibiruQuerier, - Chain, - Testnet, - newRandomWallet, - newSignerFromMnemonic, - MsgCreateDenom, - MsgCreateDenomResponse, -} from "./src" - -const main = async () => { - const chain: Chain = Testnet() // Permanent testnet - - // ---------------- NibiruTxClient ---------------- - // let signer = await newRandomWallet() // Signer: randomly generated - const signer = await newSignerFromMnemonic( - "business wrong poverty again define paper recipe trade tissue left lawn result whale fiber farm version split network cereal swallow path finger payment risk" - ) // Signer: in-practice - const txClient = await NibiruTxClient.connectWithSigner(chain.endptTm, signer) - - const account = await signer.getAccounts() // from cosmos - const signerAddress = account[0].address - console.log(signerAddress) - - const tx = await txClient.nibiruExtensions.msg.tokenFactoryMsg.createDenom({ - sender: signerAddress, - subdenom: "urex", // replace with your subdenom - }) - console.log(tx) - - // const fee = "auto" // You can specify the fee if needed - - // const msgs: EncodeObject[] = [ - // { - // typeUrl: "/nibiru.tokenfactory.v1.MsgCreateDenom", - // value: MsgCreateDenom.fromPartial({ - // sender: signerAddress, - // subdenom: "urexx", // replace with your subdenom - // }), - // }, - // ] - - // const tx = await txClient.signAndBroadcast(signerAddress, msgs, fee) - - // console.log(tx) - - // const rtx = MsgCreateDenomResponse.decode(tx.msgResponses[0].value) - // console.log(rtx) -} - -main() From 6998804cdaf6f228b233188c4a75140d931b6ae3 Mon Sep 17 00:00:00 2001 From: elshenak Date: Wed, 20 Nov 2024 00:45:04 -0500 Subject: [PATCH 3/4] fix: typo --- src/sdk/msg/tokenfactory.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sdk/msg/tokenfactory.ts b/src/sdk/msg/tokenfactory.ts index 0accda3f..0028c274 100644 --- a/src/sdk/msg/tokenfactory.ts +++ b/src/sdk/msg/tokenfactory.ts @@ -24,7 +24,7 @@ export const TOKENFACTORY_MSG_TYPE_URLS = { MsgChangeAdmin: `/${MsgServiceName}ChangeAdmin`, MsgUpdateModuleParams: `/${MsgServiceName}UpdateModuleParams`, MsgMint: `/${MsgServiceName}Mint`, - MsgBurns: `/${MsgServiceName}Burns`, + MsgBurn: `/${MsgServiceName}Burn`, MsgSetDenomMetadata: `/${MsgServiceName}SetDenomMetadata`, MsgBurnNative: `/${MsgServiceName}BurnNative`, } @@ -34,7 +34,7 @@ export const tokenfactoryTypes: ReadonlyArray<[string, GeneratedType]> = [ [TOKENFACTORY_MSG_TYPE_URLS.MsgChangeAdmin, MsgChangeAdmin], [TOKENFACTORY_MSG_TYPE_URLS.MsgUpdateModuleParams, MsgUpdateModuleParams], [TOKENFACTORY_MSG_TYPE_URLS.MsgMint, MsgMint], - [TOKENFACTORY_MSG_TYPE_URLS.MsgBurns, MsgBurn], + [TOKENFACTORY_MSG_TYPE_URLS.MsgBurn, MsgBurn], [TOKENFACTORY_MSG_TYPE_URLS.MsgSetDenomMetadata, MsgSetDenomMetadata], [TOKENFACTORY_MSG_TYPE_URLS.MsgBurnNative, MsgBurnNative], ] From 05a700d10571702b1eaaf91d3801602a4ff07760 Mon Sep 17 00:00:00 2001 From: elshenak Date: Wed, 20 Nov 2024 01:01:51 -0500 Subject: [PATCH 4/4] refactor: wasmclient doesn't need nibi registry --- src/sdk/tx/txClient.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sdk/tx/txClient.ts b/src/sdk/tx/txClient.ts index 1c7f99d0..4c1ddec8 100644 --- a/src/sdk/tx/txClient.ts +++ b/src/sdk/tx/txClient.ts @@ -67,7 +67,6 @@ export class NibiruTxClient extends SigningStargateClient { signer, { gasPrice: GasPrice.fromString("0.025unibi"), - registry: new Registry(nibiruRegistryTypes), accountParser: accountFromNibiru, ...wasmOptions, }