@cosmwasm/ts-codegen 1.13.1 → 1.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-Apache +1 -1
- package/LICENSE-MIT +1 -1
- package/README.md +2 -1
- package/esm/helpers/baseClient.js +13 -2
- package/helpers/baseClient.d.ts +1 -1
- package/helpers/baseClient.js +13 -2
- package/package.json +4 -4
    
        package/LICENSE-Apache
    CHANGED
    
    | @@ -186,7 +186,7 @@ APPENDIX: How to apply the Apache License to your work. | |
| 186 186 | 
             
               same "printed page" as the copyright notice for easier
         | 
| 187 187 | 
             
               identification within third-party archives.
         | 
| 188 188 |  | 
| 189 | 
            -
            Copyright (c) 2024 Interweb, Inc. <developers@ | 
| 189 | 
            +
            Copyright (c) 2024 Interweb, Inc. <developers@interweb.co>
         | 
| 190 190 |  | 
| 191 191 | 
             
            Licensed under the Apache License, Version 2.0 (the "License");
         | 
| 192 192 | 
             
            you may not use this file except in compliance with the License.
         | 
    
        package/LICENSE-MIT
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            MIT License
         | 
| 2 2 |  | 
| 3 | 
            -
            Copyright (c) 2024 Interweb, Inc. <developers@ | 
| 3 | 
            +
            Copyright (c) 2024 Interweb, Inc. <developers@interweb.co>
         | 
| 4 4 |  | 
| 5 5 | 
             
            Permission is hereby granted, free of charge, to any person obtaining a copy
         | 
| 6 6 | 
             
            of this software and associated documentation files (the "Software"), to deal
         | 
    
        package/README.md
    CHANGED
    
    | @@ -657,7 +657,8 @@ A unified toolkit for building applications and smart contracts in the Interchai | |
| 657 657 |  | 
| 658 658 | 
             
            ## Credits
         | 
| 659 659 |  | 
| 660 | 
            -
            🛠 Built by  | 
| 660 | 
            +
            🛠 Built by [Interweb](https://interweb.co) — if you like our tools, please checkout and contribute [https://interweb.co](https://interweb.co)
         | 
| 661 | 
            +
             | 
| 661 662 |  | 
| 662 663 | 
             
            ## Disclaimer
         | 
| 663 664 |  | 
| @@ -97,7 +97,7 @@ export interface ICosmWasmClient { | |
| 97 97 | 
             
              queryContractSmart(contractAddr: string, query: any): Promise<any>;
         | 
| 98 98 | 
             
            }
         | 
| 99 99 |  | 
| 100 | 
            -
            export interface ISigningCosmWasmClient {
         | 
| 100 | 
            +
            export interface ISigningCosmWasmClient extends ICosmWasmClient {
         | 
| 101 101 | 
             
              execute(
         | 
| 102 102 | 
             
                sender: string, 
         | 
| 103 103 | 
             
                contractAddress: string, 
         | 
| @@ -137,8 +137,19 @@ export function getCosmWasmClient(rpcEndpoint: string): ICosmWasmClient { | |
| 137 137 | 
             
              };
         | 
| 138 138 | 
             
            }
         | 
| 139 139 |  | 
| 140 | 
            -
            export function getSigningCosmWasmClient(signingClient: DirectSigner): ISigningCosmWasmClient {
         | 
| 140 | 
            +
            export function getSigningCosmWasmClient(signingClient: DirectSigner, rpcEndpoint?: string): ISigningCosmWasmClient {
         | 
| 141 141 | 
             
              return {
         | 
| 142 | 
            +
                queryContractSmart: async (contractAddr: string, query: any) => {
         | 
| 143 | 
            +
                  if (!rpcEndpoint) {
         | 
| 144 | 
            +
                    throw new Error('rpcEndpoint is required for queryContractSmart in signing client');
         | 
| 145 | 
            +
                  }
         | 
| 146 | 
            +
                  const request: QuerySmartContractStateRequest = {
         | 
| 147 | 
            +
                    address: contractAddr,
         | 
| 148 | 
            +
                    queryData: toUint8Array(query)
         | 
| 149 | 
            +
                  };
         | 
| 150 | 
            +
                  const response: QuerySmartContractStateResponse = await getSmartContractState(rpcEndpoint, request);
         | 
| 151 | 
            +
                  return fromUint8Array(response.data);
         | 
| 152 | 
            +
                },
         | 
| 142 153 | 
             
                execute: async (
         | 
| 143 154 | 
             
                  sender: string, 
         | 
| 144 155 | 
             
                  contractAddress: string, 
         | 
    
        package/helpers/baseClient.d.ts
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            export declare const baseClient = "\nimport { StdFee, Coin } from '@interchainjs/types';\nimport { DirectSigner } from '@interchainjs/cosmos';\nimport { getSmartContractState } from 'interchainjs/cosmwasm/wasm/v1/query.rpc.func';\nimport { executeContract } from 'interchainjs/cosmwasm/wasm/v1/tx.rpc.func';\nimport { QuerySmartContractStateRequest, QuerySmartContractStateResponse } from 'interchainjs/cosmwasm/wasm/v1/query';\nimport { MsgExecuteContract } from 'interchainjs/cosmwasm/wasm/v1/tx';\nimport { Chain } from '@chain-registry/v2-types';\n\n// Encoding utility functions\nconst fromUint8Array = <T>(uint8Array: Uint8Array): T => {\n  const text = new TextDecoder().decode(uint8Array);\n  return JSON.parse(text);\n};\n\nconst toUint8Array = (obj: any): Uint8Array => {\n  const text = JSON.stringify(obj);\n  return new TextEncoder().encode(text);\n};\n\n// Chain registry configuration\n// The amount under gasPrice represents gas price per unit\nexport interface ChainConfig {\n  chain?: Chain;\n  gasPrice?: {\n    denom: string;\n    amount: string;\n  };\n}\n\n// Gas fee calculation utilities\nexport const calculateGasFromChain = (chain: Chain, gasAmount: string): StdFee => {\n  try {\n    const feeTokens = chain.fees?.feeTokens;\n    \n    if (feeTokens && feeTokens.length > 0) {\n      const primaryToken = feeTokens[0];\n      // v2 chain-registry uses camelCase: averageGasPrice, lowGasPrice, fixedMinGasPrice\n      const gasPrice = primaryToken.averageGasPrice || primaryToken.lowGasPrice || primaryToken.fixedMinGasPrice || 0.025;\n      const gasAmountNum = parseInt(gasAmount);\n      const feeAmount = Math.ceil(gasAmountNum * gasPrice).toString();\n      \n      return {\n        amount: [{\n          denom: primaryToken.denom,\n          amount: feeAmount\n        }],\n        gas: gasAmount\n      };\n    }\n  } catch (error) {\n    console.warn('Failed to calculate gas from chain registry:', error);\n  }\n  \n  // Fallback to default\n  return { amount: [], gas: gasAmount };\n};\n\n// Default gas amount - users can easily change this\nexport let DEFAULT_GAS_AMOUNT = '200000';\n\n// Allow users to set their preferred default gas amount\nexport const setDefaultGasAmount = (gasAmount: string): void => {\n  DEFAULT_GAS_AMOUNT = gasAmount;\n};\n\n// Get current default gas amount\nexport const getDefaultGasAmount = (): string => DEFAULT_GAS_AMOUNT;\n\nexport const getAutoGasFee = (chainConfig?: ChainConfig): StdFee => {\n  const gasAmount = DEFAULT_GAS_AMOUNT;\n  \n  if (chainConfig?.chain) {\n    return calculateGasFromChain(chainConfig.chain, gasAmount);\n  }\n  \n  if (chainConfig?.gasPrice) {\n    const gasAmountNum = parseInt(gasAmount);\n    const gasPriceNum = parseFloat(chainConfig.gasPrice.amount);\n    const feeAmount = Math.ceil(gasAmountNum * gasPriceNum).toString();\n    \n    return {\n      amount: [{\n        denom: chainConfig.gasPrice.denom,\n        amount: feeAmount\n      }],\n      gas: gasAmount\n    };\n  }\n  \n  // Fallback: no fee tokens, just gas amount\n  return { amount: [], gas: gasAmount };\n};\n\n// InterchainJS interfaces for CosmWasm clients\nexport interface ICosmWasmClient {\n  queryContractSmart(contractAddr: string, query: any): Promise<any>;\n}\n\nexport interface ISigningCosmWasmClient {\n  execute(\n    sender: string, \n    contractAddress: string, \n    msg: any, \n    fee?: number | StdFee | \"auto\", \n    memo?: string, \n    funds?: Coin[], \n    chainConfig?: ChainConfig\n  ): Promise<any>;\n}\n\nexport interface ISigningClient {\n  signAndBroadcast(\n    signerAddress: string,\n    messages: any[],\n    fee: number | StdFee | \"auto\",\n    memo?: string\n  ): Promise<any>;\n}\n\n// Helper functions to create InterchainJS clients\nexport function getCosmWasmClient(rpcEndpoint: string): ICosmWasmClient {\n  return {\n    queryContractSmart: async (contractAddr: string, query: any) => {\n      // Create the request object\n      const request: QuerySmartContractStateRequest = {\n        address: contractAddr,\n        queryData: toUint8Array(query)\n      };\n      \n      // Execute the query using InterchainJS\n      const response: QuerySmartContractStateResponse = await getSmartContractState(rpcEndpoint, request);\n      \n      // Parse and return the result\n      return fromUint8Array(response.data);\n    },\n  };\n}\n\nexport function getSigningCosmWasmClient(signingClient: DirectSigner): ISigningCosmWasmClient {\n  return {\n    execute: async (\n      sender: string, \n      contractAddress: string, \n      msg: any, \n      fee?: number | StdFee | \"auto\", \n      memo?: string, \n      funds?: Coin[], \n      chainConfig?: ChainConfig\n    ) => {\n      // Handle fee conversion\n      let finalFee: StdFee;\n      if (typeof fee === 'number') {\n        finalFee = { amount: [], gas: fee.toString() };\n      } else if (fee === 'auto') {\n        finalFee = getAutoGasFee(chainConfig);\n      } else if (fee) {\n        finalFee = fee;\n      } else {\n        finalFee = getAutoGasFee(chainConfig);\n      }\n\n      // Create the message object\n      const message: MsgExecuteContract = {\n        sender,\n        contract: contractAddress,\n        msg: toUint8Array(msg),\n        funds: funds || []\n      };\n      \n      // Execute the transaction using InterchainJS\n      const result = await executeContract(\n        signingClient as any,\n        sender,\n        message,\n        finalFee,\n        memo || ''\n      );\n      \n      return result;\n    },\n  };\n}\n";
         | 
| 1 | 
            +
            export declare const baseClient = "\nimport { StdFee, Coin } from '@interchainjs/types';\nimport { DirectSigner } from '@interchainjs/cosmos';\nimport { getSmartContractState } from 'interchainjs/cosmwasm/wasm/v1/query.rpc.func';\nimport { executeContract } from 'interchainjs/cosmwasm/wasm/v1/tx.rpc.func';\nimport { QuerySmartContractStateRequest, QuerySmartContractStateResponse } from 'interchainjs/cosmwasm/wasm/v1/query';\nimport { MsgExecuteContract } from 'interchainjs/cosmwasm/wasm/v1/tx';\nimport { Chain } from '@chain-registry/v2-types';\n\n// Encoding utility functions\nconst fromUint8Array = <T>(uint8Array: Uint8Array): T => {\n  const text = new TextDecoder().decode(uint8Array);\n  return JSON.parse(text);\n};\n\nconst toUint8Array = (obj: any): Uint8Array => {\n  const text = JSON.stringify(obj);\n  return new TextEncoder().encode(text);\n};\n\n// Chain registry configuration\n// The amount under gasPrice represents gas price per unit\nexport interface ChainConfig {\n  chain?: Chain;\n  gasPrice?: {\n    denom: string;\n    amount: string;\n  };\n}\n\n// Gas fee calculation utilities\nexport const calculateGasFromChain = (chain: Chain, gasAmount: string): StdFee => {\n  try {\n    const feeTokens = chain.fees?.feeTokens;\n    \n    if (feeTokens && feeTokens.length > 0) {\n      const primaryToken = feeTokens[0];\n      // v2 chain-registry uses camelCase: averageGasPrice, lowGasPrice, fixedMinGasPrice\n      const gasPrice = primaryToken.averageGasPrice || primaryToken.lowGasPrice || primaryToken.fixedMinGasPrice || 0.025;\n      const gasAmountNum = parseInt(gasAmount);\n      const feeAmount = Math.ceil(gasAmountNum * gasPrice).toString();\n      \n      return {\n        amount: [{\n          denom: primaryToken.denom,\n          amount: feeAmount\n        }],\n        gas: gasAmount\n      };\n    }\n  } catch (error) {\n    console.warn('Failed to calculate gas from chain registry:', error);\n  }\n  \n  // Fallback to default\n  return { amount: [], gas: gasAmount };\n};\n\n// Default gas amount - users can easily change this\nexport let DEFAULT_GAS_AMOUNT = '200000';\n\n// Allow users to set their preferred default gas amount\nexport const setDefaultGasAmount = (gasAmount: string): void => {\n  DEFAULT_GAS_AMOUNT = gasAmount;\n};\n\n// Get current default gas amount\nexport const getDefaultGasAmount = (): string => DEFAULT_GAS_AMOUNT;\n\nexport const getAutoGasFee = (chainConfig?: ChainConfig): StdFee => {\n  const gasAmount = DEFAULT_GAS_AMOUNT;\n  \n  if (chainConfig?.chain) {\n    return calculateGasFromChain(chainConfig.chain, gasAmount);\n  }\n  \n  if (chainConfig?.gasPrice) {\n    const gasAmountNum = parseInt(gasAmount);\n    const gasPriceNum = parseFloat(chainConfig.gasPrice.amount);\n    const feeAmount = Math.ceil(gasAmountNum * gasPriceNum).toString();\n    \n    return {\n      amount: [{\n        denom: chainConfig.gasPrice.denom,\n        amount: feeAmount\n      }],\n      gas: gasAmount\n    };\n  }\n  \n  // Fallback: no fee tokens, just gas amount\n  return { amount: [], gas: gasAmount };\n};\n\n// InterchainJS interfaces for CosmWasm clients\nexport interface ICosmWasmClient {\n  queryContractSmart(contractAddr: string, query: any): Promise<any>;\n}\n\nexport interface ISigningCosmWasmClient extends ICosmWasmClient {\n  execute(\n    sender: string, \n    contractAddress: string, \n    msg: any, \n    fee?: number | StdFee | \"auto\", \n    memo?: string, \n    funds?: Coin[], \n    chainConfig?: ChainConfig\n  ): Promise<any>;\n}\n\nexport interface ISigningClient {\n  signAndBroadcast(\n    signerAddress: string,\n    messages: any[],\n    fee: number | StdFee | \"auto\",\n    memo?: string\n  ): Promise<any>;\n}\n\n// Helper functions to create InterchainJS clients\nexport function getCosmWasmClient(rpcEndpoint: string): ICosmWasmClient {\n  return {\n    queryContractSmart: async (contractAddr: string, query: any) => {\n      // Create the request object\n      const request: QuerySmartContractStateRequest = {\n        address: contractAddr,\n        queryData: toUint8Array(query)\n      };\n      \n      // Execute the query using InterchainJS\n      const response: QuerySmartContractStateResponse = await getSmartContractState(rpcEndpoint, request);\n      \n      // Parse and return the result\n      return fromUint8Array(response.data);\n    },\n  };\n}\n\nexport function getSigningCosmWasmClient(signingClient: DirectSigner, rpcEndpoint?: string): ISigningCosmWasmClient {\n  return {\n    queryContractSmart: async (contractAddr: string, query: any) => {\n      if (!rpcEndpoint) {\n        throw new Error('rpcEndpoint is required for queryContractSmart in signing client');\n      }\n      const request: QuerySmartContractStateRequest = {\n        address: contractAddr,\n        queryData: toUint8Array(query)\n      };\n      const response: QuerySmartContractStateResponse = await getSmartContractState(rpcEndpoint, request);\n      return fromUint8Array(response.data);\n    },\n    execute: async (\n      sender: string, \n      contractAddress: string, \n      msg: any, \n      fee?: number | StdFee | \"auto\", \n      memo?: string, \n      funds?: Coin[], \n      chainConfig?: ChainConfig\n    ) => {\n      // Handle fee conversion\n      let finalFee: StdFee;\n      if (typeof fee === 'number') {\n        finalFee = { amount: [], gas: fee.toString() };\n      } else if (fee === 'auto') {\n        finalFee = getAutoGasFee(chainConfig);\n      } else if (fee) {\n        finalFee = fee;\n      } else {\n        finalFee = getAutoGasFee(chainConfig);\n      }\n\n      // Create the message object\n      const message: MsgExecuteContract = {\n        sender,\n        contract: contractAddress,\n        msg: toUint8Array(msg),\n        funds: funds || []\n      };\n      \n      // Execute the transaction using InterchainJS\n      const result = await executeContract(\n        signingClient as any,\n        sender,\n        message,\n        finalFee,\n        memo || ''\n      );\n      \n      return result;\n    },\n  };\n}\n";
         | 
    
        package/helpers/baseClient.js
    CHANGED
    
    | @@ -100,7 +100,7 @@ export interface ICosmWasmClient { | |
| 100 100 | 
             
              queryContractSmart(contractAddr: string, query: any): Promise<any>;
         | 
| 101 101 | 
             
            }
         | 
| 102 102 |  | 
| 103 | 
            -
            export interface ISigningCosmWasmClient {
         | 
| 103 | 
            +
            export interface ISigningCosmWasmClient extends ICosmWasmClient {
         | 
| 104 104 | 
             
              execute(
         | 
| 105 105 | 
             
                sender: string, 
         | 
| 106 106 | 
             
                contractAddress: string, 
         | 
| @@ -140,8 +140,19 @@ export function getCosmWasmClient(rpcEndpoint: string): ICosmWasmClient { | |
| 140 140 | 
             
              };
         | 
| 141 141 | 
             
            }
         | 
| 142 142 |  | 
| 143 | 
            -
            export function getSigningCosmWasmClient(signingClient: DirectSigner): ISigningCosmWasmClient {
         | 
| 143 | 
            +
            export function getSigningCosmWasmClient(signingClient: DirectSigner, rpcEndpoint?: string): ISigningCosmWasmClient {
         | 
| 144 144 | 
             
              return {
         | 
| 145 | 
            +
                queryContractSmart: async (contractAddr: string, query: any) => {
         | 
| 146 | 
            +
                  if (!rpcEndpoint) {
         | 
| 147 | 
            +
                    throw new Error('rpcEndpoint is required for queryContractSmart in signing client');
         | 
| 148 | 
            +
                  }
         | 
| 149 | 
            +
                  const request: QuerySmartContractStateRequest = {
         | 
| 150 | 
            +
                    address: contractAddr,
         | 
| 151 | 
            +
                    queryData: toUint8Array(query)
         | 
| 152 | 
            +
                  };
         | 
| 153 | 
            +
                  const response: QuerySmartContractStateResponse = await getSmartContractState(rpcEndpoint, request);
         | 
| 154 | 
            +
                  return fromUint8Array(response.data);
         | 
| 155 | 
            +
                },
         | 
| 145 156 | 
             
                execute: async (
         | 
| 146 157 | 
             
                  sender: string, 
         | 
| 147 158 | 
             
                  contractAddress: string, 
         | 
    
        package/package.json
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            {
         | 
| 2 2 | 
             
              "name": "@cosmwasm/ts-codegen",
         | 
| 3 | 
            -
              "version": "1.13. | 
| 3 | 
            +
              "version": "1.13.3",
         | 
| 4 4 | 
             
              "description": "@cosmwasm/ts-codegen converts your CosmWasm smart contracts into dev-friendly TypeScript classes so you can focus on shipping code.",
         | 
| 5 5 | 
             
              "author": "Dan Lynch <pyramation@gmail.com>",
         | 
| 6 6 | 
             
              "homepage": "https://github.com/hyperweb-io/ts-codegen",
         | 
| @@ -43,8 +43,8 @@ | |
| 43 43 | 
             
                "@chain-registry/types": "^0.17.1",
         | 
| 44 44 | 
             
                "@chain-registry/utils": "^1.51.71",
         | 
| 45 45 | 
             
                "@chain-registry/v2": "^1.71.229",
         | 
| 46 | 
            -
                "@cosmwasm/ts-codegen-ast": "^1.9. | 
| 47 | 
            -
                "@cosmwasm/ts-codegen-types": "^1.4. | 
| 46 | 
            +
                "@cosmwasm/ts-codegen-ast": "^1.9.3",
         | 
| 47 | 
            +
                "@cosmwasm/ts-codegen-types": "^1.4.3",
         | 
| 48 48 | 
             
                "@interchainjs/amino": "1.17.1",
         | 
| 49 49 | 
             
                "@interchainjs/cosmos": "1.17.1",
         | 
| 50 50 | 
             
                "@interchainjs/types": "1.17.1",
         | 
| @@ -72,5 +72,5 @@ | |
| 72 72 | 
             
                "smart contracts",
         | 
| 73 73 | 
             
                "codegen"
         | 
| 74 74 | 
             
              ],
         | 
| 75 | 
            -
              "gitHead": " | 
| 75 | 
            +
              "gitHead": "9f7a1f7bc4ce7c86b145c9c2c32ff544fc1b252a"
         | 
| 76 76 | 
             
            }
         |