From 8ac578dd0703391257e06fcce219ab32afe01fd9 Mon Sep 17 00:00:00 2001 From: hotwater Date: Wed, 13 Mar 2024 18:12:48 +0200 Subject: [PATCH 1/2] feat!: api changes to `core` and `react` packages --- .changeset/strange-clocks-return.md | 9 + packages/core/.gitignore | 1 + packages/core/package.json | 5 + .../get-account-base-addresses-from-api.ts | 15 +- .../actions/account/public/get-base-token.ts | 17 +- .../account/public/get-cosm-wasm-client.ts | 13 -- ...et-ibc-client-query-client-from-manager.ts | 16 +- .../get-manager-query-client-from-api.ts | 19 +- .../account/public/get-module-address.ts | 18 +- ...et-module-instantiate2-address-from-api.ts | 28 +-- .../src/actions/account/public/get-modules.ts | 26 ++- .../actions/account/public/get-namespace.ts | 15 +- .../src/actions/account/public/get-owner.ts | 17 +- .../public/get-proxy-query-client-from-api.ts | 19 +- .../account/public/get-remote-account-ids.ts | 15 +- .../public/get-remote-account-proxies.ts | 29 +-- .../account/public/get-sub-account-ids.ts | 28 ++- .../public/get-sub-account-sequences.ts | 26 ++- .../actions/account/public/get-total-value.ts | 17 +- .../actions/account/wallet/claim-namespace.ts | 14 +- .../account/wallet/create-sub-account.ts | 28 ++- .../src/actions/account/wallet/deposit.ts | 18 +- .../src/actions/account/wallet/execute.ts | 18 +- .../wallet/get-manager-client-from-api.ts | 22 +- .../wallet/get-proxy-client-from-api.ts | 22 +- .../account/wallet/remove-namespace.ts | 21 +- .../src/actions/account/wallet/withdraw.ts | 32 +-- .../actions/get-account-balance-from-api.ts | 12 +- .../get-account-factory-address-from-api.ts | 8 +- .../actions/get-accounts-by-owner-from-api.ts | 11 +- .../actions/get-ans-host-address-from-api.ts | 8 +- .../src/actions/get-ans-token-from-api.ts | 13 +- .../src/actions/get-ans-tokens-from-api.ts | 9 +- .../get-version-control-address-from-api.ts | 8 +- packages/core/src/actions/index.ts | 70 +++++++ ...act-module-address-from-version-control.ts | 22 +- .../public/get-abstract-module-version.ts | 22 +- ...nt-factory-address-from-version-control.ts | 25 +-- ...t-account-factory-query-client-from-api.ts | 14 +- ...ctory-query-client-from-version-control.ts | 27 ++- .../get-account-factory-query-client.ts | 8 +- .../public/get-account-factory-version.ts | 25 +-- ...t-ans-host-address-from-version-control.ts | 25 +-- .../get-ans-host-query-client-from-api.ts | 13 +- ...-host-query-client-from-version-control.ts | 19 +- .../public/get-ans-host-query-client.ts | 8 +- .../actions/public/get-ans-host-version.ts | 25 +-- ...app-module-code-id-from-version-control.ts | 16 +- .../actions/public/get-cosm-wasm-client.ts | 8 +- .../public/get-manager-query-client.ts | 8 +- ...le-factory-address-from-version-control.ts | 25 +-- .../public/get-module-factory-version.ts | 25 +-- .../actions/public/get-proxy-query-client.ts | 8 +- .../public/get-version-control-module-data.ts | 6 +- ...t-version-control-query-client-from-api.ts | 17 +- .../get-version-control-query-client.ts | 8 +- packages/core/src/actions/public/types.ts | 5 + .../actions/wallet/create-account-monarchy.ts | 56 +++-- .../core/src/actions/wallet/create-account.ts | 36 ++-- .../get-account-factory-client-from-api.ts | 16 +- ...unt-factory-client-from-version-control.ts | 22 +- .../wallet/get-account-factory-client.ts | 9 +- .../wallet/get-ans-host-client-from-api.ts | 16 +- ...et-ans-host-client-from-version-control.ts | 22 +- .../src/actions/wallet/get-ans-host-client.ts | 9 +- .../src/actions/wallet/get-manager-client.ts | 9 +- .../src/actions/wallet/get-proxy-client.ts | 9 +- .../src/actions/wallet/get-sender-address.ts | 10 +- .../wallet/get-signing-cosm-wasm-client.ts | 8 +- .../get-version-control-client-from-api.ts | 19 +- .../wallet/get-version-control-client.ts | 9 +- .../clients/create-account-public-client.ts | 4 +- .../clients/create-account-wallet-client.ts | 4 +- .../core/src/clients/create-api-client.ts | 4 +- packages/core/src/clients/create-client.ts | 7 +- .../core/src/clients/create-public-client.ts | 4 +- .../core/src/clients/create-wallet-client.ts | 4 +- .../src/clients/decorators/account-public.ts | 196 ++++++++++-------- .../src/clients/decorators/account-wallet.ts | 115 ++++++---- packages/core/src/clients/decorators/api.ts | 81 ++++---- .../core/src/clients/decorators/public.ts | 178 ++++++++-------- .../core/src/clients/decorators/wallet.ts | 146 ++++++------- .../core/src/legacy/clients/AbstractClient.ts | 3 +- packages/core/src/types/parameters.ts | 17 ++ packages/core/src/types/utils.ts | 103 ++++++++- packages/core/src/types/with-args.ts | 32 --- packages/core/src/utils/assets/ans/types.ts | 4 +- packages/core/tsup.config.ts | 1 + packages/react/src/create-config.ts | 2 +- .../use-account-base-addresses-from-api.ts | 39 ++-- ...se-module-instantiate2-address-from-api.ts | 59 +++--- .../public/use-sub-accounts-ids-from-api.ts | 53 +++-- .../account/wallet/use-create-sub-account.ts | 32 +-- .../src/hooks/account/wallet/use-deposit.ts | 35 ++-- .../src/hooks/account/wallet/use-execute.ts | 34 +-- .../src/hooks/account/wallet/use-withdraw.ts | 35 ++-- .../public/use-abstract-module-version.ts | 41 ++-- .../use-account-factory-config-from-api.ts | 43 ++-- ...e-account-factory-query-client-from-api.ts | 45 ++-- .../src/hooks/public/use-cosm-wasm-client.ts | 60 +++--- .../src/hooks/use-account-balance-from-api.ts | 38 ++-- packages/react/src/hooks/use-accounts.ts | 50 +++-- .../react/src/hooks/use-ans-token-from-api.ts | 38 ++-- .../wallet/use-create-account-monarchy.ts | 29 +-- .../src/hooks/wallet/use-create-account.ts | 26 +-- .../src/hooks/wallet/use-sender-address.ts | 43 ++-- .../wallet/use-signing-cosm-wasm-client.ts | 40 ++-- .../wallet/utils/use-sign-and-broadcast.ts | 10 +- packages/react/src/types/args.ts | 7 + packages/react/src/types/queries.ts | 128 ++++++++++++ packages/react/src/types/utils.ts | 97 ++++++++- .../react/src/utils/use-abstract-client.ts | 59 +++--- .../src/utils/use-abstract-module-client.ts | 47 +++-- .../utils/use-abstract-module-query-client.ts | 48 +++-- .../src/utils/use-abstract-query-client.ts | 39 ++-- 115 files changed, 1907 insertions(+), 1429 deletions(-) create mode 100644 .changeset/strange-clocks-return.md delete mode 100644 packages/core/src/actions/account/public/get-cosm-wasm-client.ts create mode 100644 packages/core/src/actions/index.ts create mode 100644 packages/core/src/actions/public/types.ts create mode 100644 packages/core/src/types/parameters.ts delete mode 100644 packages/core/src/types/with-args.ts create mode 100644 packages/react/src/types/args.ts create mode 100644 packages/react/src/types/queries.ts diff --git a/.changeset/strange-clocks-return.md b/.changeset/strange-clocks-return.md new file mode 100644 index 00000000..506633a5 --- /dev/null +++ b/.changeset/strange-clocks-return.md @@ -0,0 +1,9 @@ +--- +"@abstract-money/core": major +"@abstract-money/react": major +"wagemos-cosmoskit-nextjs": patch +"wagemos-graz-nextjs": patch +"@abstract-money/cli": patch +--- + +Changed the API for `react` and `core` packages. Previously `core` package had unnecessary `args:{}` wrapping, now it doesn't. Also, `query` and `mutation` fields were added to the `react` package to have a clear separation of concerns, as well as fixed inconsistent API around `chainName` and types. diff --git a/packages/core/.gitignore b/packages/core/.gitignore index 2b875bee..81c4e83c 100644 --- a/packages/core/.gitignore +++ b/packages/core/.gitignore @@ -1,4 +1,5 @@ # Generated file. Do not edit directly. +actions/** clients/** utils/** legacy/** \ No newline at end of file diff --git a/packages/core/package.json b/packages/core/package.json index f0a32522..650ba5c2 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -79,6 +79,10 @@ "types": "./dist/index.d.ts", "default": "./dist/index.js" }, + "./actions": { + "types": "./dist/actions/index.d.ts", + "default": "./dist/actions/index.js" + }, "./clients": { "types": "./dist/clients/index.d.ts", "default": "./dist/clients/index.js" @@ -94,6 +98,7 @@ "./package.json": "./package.json" }, "files": [ + "/actions", "/clients", "/utils", "/legacy", diff --git a/packages/core/src/actions/account/public/get-account-base-addresses-from-api.ts b/packages/core/src/actions/account/public/get-account-base-addresses-from-api.ts index ee0cfc83..8aeb7876 100644 --- a/packages/core/src/actions/account/public/get-account-base-addresses-from-api.ts +++ b/packages/core/src/actions/account/public/get-account-base-addresses-from-api.ts @@ -1,23 +1,22 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { VersionControlTypes } from '../../../codegen/abstract' -import { WithArgs } from '../../../types/with-args' import { accountIdToParameter } from '../../../utils/account-id' import { getVersionControlQueryClientFromApi } from '../../public/get-version-control-query-client-from-api' -export type GetAccountBaseAddressesFromApiParameters = WithArgs<{ +export type GetAccountBaseAddressesFromApiParameters = { accountId: VersionControlTypes.AccountId cosmWasmClient: CosmWasmClient apiUrl: string -}> +} export async function getAccountBaseAddressesFromApi({ - args: { accountId, cosmWasmClient, apiUrl }, + accountId, + cosmWasmClient, + apiUrl, }: GetAccountBaseAddressesFromApiParameters) { const versionControlQueryClient = await getVersionControlQueryClientFromApi({ - args: { - cosmWasmClient, - apiUrl, - }, + cosmWasmClient, + apiUrl, }) const { account_base: accountBase } = await versionControlQueryClient.accountBase({ diff --git a/packages/core/src/actions/account/public/get-base-token.ts b/packages/core/src/actions/account/public/get-base-token.ts index 57fbad2c..2d59baef 100644 --- a/packages/core/src/actions/account/public/get-base-token.ts +++ b/packages/core/src/actions/account/public/get-base-token.ts @@ -1,6 +1,5 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { VersionControlTypes } from '../../../codegen/abstract' -import { WithArgs } from '../../../types/with-args' import { CW20Token, NativeToken } from '../../../utils' import { getProxyQueryClientFromApi } from './get-proxy-query-client-from-api' @@ -12,21 +11,21 @@ function hasCw20Field(base_asset: any): base_asset is { cw20: string } { return (base_asset as { cw20: string }).cw20 !== undefined } -export type GetBaseTokenParameters = WithArgs<{ +export type GetBaseTokenParameters = { accountId: VersionControlTypes.AccountId cosmWasmClient: CosmWasmClient apiUrl: string -}> +} export async function getBaseToken({ - args: { accountId, cosmWasmClient, apiUrl }, + accountId, + cosmWasmClient, + apiUrl, }: GetBaseTokenParameters) { const proxyQueryClient = await getProxyQueryClientFromApi({ - args: { - accountId, - cosmWasmClient, - apiUrl, - }, + accountId, + cosmWasmClient, + apiUrl, }) const { base_asset } = await proxyQueryClient.baseAsset() if (hasNativeField(base_asset)) diff --git a/packages/core/src/actions/account/public/get-cosm-wasm-client.ts b/packages/core/src/actions/account/public/get-cosm-wasm-client.ts deleted file mode 100644 index d40c852e..00000000 --- a/packages/core/src/actions/account/public/get-cosm-wasm-client.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' - -import { WithArgs } from '../../../types/with-args' - -export type GetCosmWasmClientParameters = WithArgs<{ - cosmWasmClient: CosmWasmClient -}> - -export async function getCosmWasmClient({ - args: { cosmWasmClient }, -}: GetCosmWasmClientParameters) { - return cosmWasmClient -} diff --git a/packages/core/src/actions/account/public/get-ibc-client-query-client-from-manager.ts b/packages/core/src/actions/account/public/get-ibc-client-query-client-from-manager.ts index 9cc560fb..40d57e51 100644 --- a/packages/core/src/actions/account/public/get-ibc-client-query-client-from-manager.ts +++ b/packages/core/src/actions/account/public/get-ibc-client-query-client-from-manager.ts @@ -3,14 +3,13 @@ import { IbcClientQueryClient, VersionControlTypes, } from '../../../codegen/abstract' -import { WithArgs } from '../../../types/with-args' import { getModuleAddress } from './get-module-address' -export type GetModuleAddressParameters = WithArgs<{ +export type GetIbcClientQueryClientFromManagerParameters = { accountId: VersionControlTypes.AccountId cosmWasmClient: CosmWasmClient apiUrl: string -}> +} const IBC_CLIENT_MODULE_ID = 'abstract:ibc-client' @@ -22,10 +21,15 @@ const IBC_CLIENT_MODULE_ID = 'abstract:ibc-client' * @param apiUrl */ export async function getIbcClientQueryClientFromManager({ - args: { accountId, cosmWasmClient, apiUrl }, -}: GetModuleAddressParameters) { + accountId, + cosmWasmClient, + apiUrl, +}: GetIbcClientQueryClientFromManagerParameters) { const ibcClientAddress = await getModuleAddress({ - args: { accountId, cosmWasmClient, apiUrl, id: IBC_CLIENT_MODULE_ID }, + accountId, + cosmWasmClient, + apiUrl, + id: IBC_CLIENT_MODULE_ID, }) if (!ibcClientAddress) { diff --git a/packages/core/src/actions/account/public/get-manager-query-client-from-api.ts b/packages/core/src/actions/account/public/get-manager-query-client-from-api.ts index a38b9c31..2a228f0e 100644 --- a/packages/core/src/actions/account/public/get-manager-query-client-from-api.ts +++ b/packages/core/src/actions/account/public/get-manager-query-client-from-api.ts @@ -1,24 +1,23 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { VersionControlTypes } from '../../../codegen/abstract' -import { WithArgs } from '../../../types/with-args' import { getManagerQueryClient } from '../../public/get-manager-query-client' import { getAccountBaseAddressesFromApi } from './get-account-base-addresses-from-api' -export type GetManagerQueryClientFromApiParameters = WithArgs<{ +export type GetManagerQueryClientFromApiParameters = { accountId: VersionControlTypes.AccountId cosmWasmClient: CosmWasmClient apiUrl: string -}> +} export async function getManagerQueryClientFromApi({ - args: { accountId, cosmWasmClient, apiUrl }, + accountId, + cosmWasmClient, + apiUrl, }: GetManagerQueryClientFromApiParameters) { const { managerAddress } = await getAccountBaseAddressesFromApi({ - args: { - accountId, - cosmWasmClient, - apiUrl, - }, + accountId, + cosmWasmClient, + apiUrl, }) - return getManagerQueryClient({ args: { cosmWasmClient, managerAddress } }) + return getManagerQueryClient({ cosmWasmClient, managerAddress }) } diff --git a/packages/core/src/actions/account/public/get-module-address.ts b/packages/core/src/actions/account/public/get-module-address.ts index 7dca2fea..979382bd 100644 --- a/packages/core/src/actions/account/public/get-module-address.ts +++ b/packages/core/src/actions/account/public/get-module-address.ts @@ -1,24 +1,24 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { VersionControlTypes } from '../../../codegen/abstract' -import { WithArgs } from '../../../types/with-args' import { getManagerQueryClientFromApi } from './get-manager-query-client-from-api' -export type GetModuleAddressParameters = WithArgs<{ +export type GetModuleAddressParameters = { accountId: VersionControlTypes.AccountId cosmWasmClient: CosmWasmClient apiUrl: string id: string -}> +} export async function getModuleAddress({ - args: { accountId, cosmWasmClient, apiUrl, id }, + accountId, + cosmWasmClient, + apiUrl, + id, }: GetModuleAddressParameters) { const managerQueryClient = await getManagerQueryClientFromApi({ - args: { - accountId, - cosmWasmClient, - apiUrl, - }, + accountId, + cosmWasmClient, + apiUrl, }) const { modules } = await managerQueryClient.moduleAddresses({ ids: [id] }) diff --git a/packages/core/src/actions/account/public/get-module-instantiate2-address-from-api.ts b/packages/core/src/actions/account/public/get-module-instantiate2-address-from-api.ts index f0b6289b..30e4a602 100644 --- a/packages/core/src/actions/account/public/get-module-instantiate2-address-from-api.ts +++ b/packages/core/src/actions/account/public/get-module-instantiate2-address-from-api.ts @@ -5,41 +5,43 @@ import { } from '@abstract-money/core' import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { VersionControlTypes } from '../../../codegen/abstract' -import { WithArgs } from '../../../types/with-args' import { getVersionControlAddressFromApi } from '../../get-version-control-address-from-api' import { getAppModuleCodeIdFromVersionControl } from '../../public/get-app-module-code-id-from-version-control' import { getModuleFactoryAddressFromVersionControl } from '../../public/get-module-factory-address-from-version-control' -export type GetModuleInstantiate2AddressFromApi = WithArgs<{ +export type GetModuleInstantiate2AddressFromApi = { accountId: VersionControlTypes.AccountId moduleId: ModuleId version?: VersionControlTypes.ModuleVersion cosmWasmClient: CosmWasmClient apiUrl: string -}> +} export async function getModuleInstantiate2AddressFromApi({ - args: { accountId, cosmWasmClient, apiUrl, moduleId, version }, + accountId, + cosmWasmClient, + apiUrl, + moduleId, + version, }: GetModuleInstantiate2AddressFromApi) { const chainId = await cosmWasmClient.getChainId() const chainName = chainIdToName(chainId) const versionControlAddress = await getVersionControlAddressFromApi({ - args: { - apiUrl, - chainName, - }, + apiUrl, + chainName, }) const moduleFactoryAddress = await getModuleFactoryAddressFromVersionControl({ - args: { - cosmWasmClient, - versionControlAddress, - }, + cosmWasmClient, + versionControlAddress, }) const moduleCodeId = await getAppModuleCodeIdFromVersionControl({ - args: { moduleId, version, cosmWasmClient, versionControlAddress }, + moduleId, + version, + cosmWasmClient, + versionControlAddress, }) const moduleCodeDetails = await cosmWasmClient.getCodeDetails(moduleCodeId) diff --git a/packages/core/src/actions/account/public/get-modules.ts b/packages/core/src/actions/account/public/get-modules.ts index 225d2eab..fa3b6199 100644 --- a/packages/core/src/actions/account/public/get-modules.ts +++ b/packages/core/src/actions/account/public/get-modules.ts @@ -3,26 +3,24 @@ import { ManagerQueryClient, VersionControlTypes, } from '../../../codegen/abstract' -import { WithArgs } from '../../../types/with-args' import { getManagerQueryClientFromApi } from './get-manager-query-client-from-api' -export type GetModulesParameters = WithArgs< - { - accountId: VersionControlTypes.AccountId - cosmWasmClient: CosmWasmClient - apiUrl: string - } & Parameters[0] -> +export type GetModulesParameters = { + accountId: VersionControlTypes.AccountId + cosmWasmClient: CosmWasmClient + apiUrl: string +} & Parameters[0] export async function getModules({ - args: { accountId, cosmWasmClient, apiUrl, ...params }, + accountId, + cosmWasmClient, + apiUrl, + ...params }: GetModulesParameters) { const managerQueryClient = await getManagerQueryClientFromApi({ - args: { - accountId, - cosmWasmClient, - apiUrl, - }, + accountId, + cosmWasmClient, + apiUrl, }) const { module_infos: modules } = await managerQueryClient.moduleInfos(params) diff --git a/packages/core/src/actions/account/public/get-namespace.ts b/packages/core/src/actions/account/public/get-namespace.ts index 871ea619..cd95b1f0 100644 --- a/packages/core/src/actions/account/public/get-namespace.ts +++ b/packages/core/src/actions/account/public/get-namespace.ts @@ -1,23 +1,22 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { VersionControlTypes } from '../../../codegen/abstract' -import { WithArgs } from '../../../types/with-args' import { accountIdToParameter } from '../../../utils/account-id' import { getVersionControlQueryClientFromApi } from '../../public/get-version-control-query-client-from-api' -export type GetNamespaceParameters = WithArgs<{ +export type GetNamespaceParameters = { accountId: VersionControlTypes.AccountId cosmWasmClient: CosmWasmClient apiUrl: string -}> +} export async function getNamespace({ - args: { accountId, cosmWasmClient, apiUrl }, + accountId, + cosmWasmClient, + apiUrl, }: GetNamespaceParameters): Promise { const versionControlQueryClient = await getVersionControlQueryClientFromApi({ - args: { - cosmWasmClient, - apiUrl, - }, + cosmWasmClient, + apiUrl, }) const namespace = await versionControlQueryClient .namespaces({ accounts: [accountIdToParameter(accountId)] }) diff --git a/packages/core/src/actions/account/public/get-owner.ts b/packages/core/src/actions/account/public/get-owner.ts index e700a181..103f3d61 100644 --- a/packages/core/src/actions/account/public/get-owner.ts +++ b/packages/core/src/actions/account/public/get-owner.ts @@ -1,23 +1,22 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { VersionControlTypes } from '../../../codegen/abstract' -import { WithArgs } from '../../../types/with-args' import { getManagerQueryClientFromApi } from './get-manager-query-client-from-api' -export type GetOwnerParameters = WithArgs<{ +export type GetOwnerParameters = { accountId: VersionControlTypes.AccountId cosmWasmClient: CosmWasmClient apiUrl: string -}> +} export async function getOwner({ - args: { accountId, cosmWasmClient, apiUrl }, + accountId, + cosmWasmClient, + apiUrl, }: GetOwnerParameters) { const managerQueryClient = await getManagerQueryClientFromApi({ - args: { - accountId, - cosmWasmClient, - apiUrl, - }, + accountId, + cosmWasmClient, + apiUrl, }) return managerQueryClient .ownership() diff --git a/packages/core/src/actions/account/public/get-proxy-query-client-from-api.ts b/packages/core/src/actions/account/public/get-proxy-query-client-from-api.ts index f5c86c4c..8467915c 100644 --- a/packages/core/src/actions/account/public/get-proxy-query-client-from-api.ts +++ b/packages/core/src/actions/account/public/get-proxy-query-client-from-api.ts @@ -1,25 +1,24 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { VersionControlTypes } from '../../../codegen/abstract' -import { WithArgs } from '../../../types/with-args' import { getProxyQueryClient } from '../../public/get-proxy-query-client' import { getAccountBaseAddressesFromApi } from './get-account-base-addresses-from-api' -export type GetProxyQueryClientFromApiParameters = WithArgs<{ +export type GetProxyQueryClientFromApiParameters = { accountId: VersionControlTypes.AccountId cosmWasmClient: CosmWasmClient apiUrl: string -}> +} export async function getProxyQueryClientFromApi({ - args: { accountId, cosmWasmClient, apiUrl }, + accountId, + cosmWasmClient, + apiUrl, }: GetProxyQueryClientFromApiParameters) { const { proxyAddress } = await getAccountBaseAddressesFromApi({ - args: { - accountId, - cosmWasmClient, - apiUrl, - }, + accountId, + cosmWasmClient, + apiUrl, }) - return getProxyQueryClient({ args: { cosmWasmClient, proxyAddress } }) + return getProxyQueryClient({ cosmWasmClient, proxyAddress }) } diff --git a/packages/core/src/actions/account/public/get-remote-account-ids.ts b/packages/core/src/actions/account/public/get-remote-account-ids.ts index 3a497862..0ed1b52b 100644 --- a/packages/core/src/actions/account/public/get-remote-account-ids.ts +++ b/packages/core/src/actions/account/public/get-remote-account-ids.ts @@ -1,11 +1,4 @@ import { AccountId, chainIdToName } from '@abstract-money/core' -import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { - IbcClientQueryClient, - VersionControlTypes, -} from '../../../codegen/abstract' -import { WithArgs } from '../../../types/with-args' -import { getIbcClientQueryClientFromManager } from './get-ibc-client-query-client-from-manager' import { GetRemoteProxiesParameters, getRemoteAccountProxies, @@ -20,10 +13,14 @@ export type GetRemoteAccountIdsParameters = GetRemoteProxiesParameters * @param apiUrl */ export async function getRemoteAccountIds({ - args: { accountId, cosmWasmClient, apiUrl }, + accountId, + cosmWasmClient, + apiUrl, }: GetRemoteAccountIdsParameters): Promise { const remoteProxies = await getRemoteAccountProxies({ - args: { accountId, cosmWasmClient, apiUrl }, + accountId, + cosmWasmClient, + apiUrl, }) const chainId = await cosmWasmClient.getChainId() diff --git a/packages/core/src/actions/account/public/get-remote-account-proxies.ts b/packages/core/src/actions/account/public/get-remote-account-proxies.ts index a30924bb..5b9d67e8 100644 --- a/packages/core/src/actions/account/public/get-remote-account-proxies.ts +++ b/packages/core/src/actions/account/public/get-remote-account-proxies.ts @@ -3,20 +3,17 @@ import { IbcClientQueryClient, VersionControlTypes, } from '../../../codegen/abstract' -import { WithArgs } from '../../../types/with-args' import { getIbcClientQueryClientFromManager } from './get-ibc-client-query-client-from-manager' -export type GetRemoteProxiesParameters = WithArgs< - { - accountId: VersionControlTypes.AccountId - cosmWasmClient: CosmWasmClient - apiUrl: string - } & Omit< - Parameters< - typeof IbcClientQueryClient.prototype.listRemoteProxiesByAccountId - >[0], - 'accountId' - > +export type GetRemoteProxiesParameters = { + accountId: VersionControlTypes.AccountId + cosmWasmClient: CosmWasmClient + apiUrl: string +} & Omit< + Parameters< + typeof IbcClientQueryClient.prototype.listRemoteProxiesByAccountId + >[0], + 'accountId' > type ChainName = string @@ -29,12 +26,16 @@ type MaybeProxyAddress = string | null * @param apiUrl */ export async function getRemoteAccountProxies({ - args: { accountId, cosmWasmClient, apiUrl }, + accountId, + cosmWasmClient, + apiUrl, }: GetRemoteProxiesParameters): Promise> { let ibcClient: IbcClientQueryClient try { ibcClient = await getIbcClientQueryClientFromManager({ - args: { accountId, cosmWasmClient, apiUrl }, + accountId, + cosmWasmClient, + apiUrl, }) } catch (e) { // IBC client not installed diff --git a/packages/core/src/actions/account/public/get-sub-account-ids.ts b/packages/core/src/actions/account/public/get-sub-account-ids.ts index 0debc0f7..fe0fdd5a 100644 --- a/packages/core/src/actions/account/public/get-sub-account-ids.ts +++ b/packages/core/src/actions/account/public/get-sub-account-ids.ts @@ -4,31 +4,29 @@ import { ManagerQueryClient, VersionControlTypes, } from '../../../codegen/abstract' -import { WithArgs } from '../../../types/with-args' import { sequenceToLocalAccountId } from '../../../utils/account-id/seq-to-local-account-id' import { chainIdToName } from '../../../utils/chain-registry' import { getSubAccountSequences } from './get-sub-account-sequences' -export type GetSubAccountIdsParameters = WithArgs< - { - accountId: VersionControlTypes.AccountId - cosmWasmClient: CosmWasmClient - apiUrl: string - } & Parameters[0] -> +export type GetSubAccountIdsParameters = { + accountId: VersionControlTypes.AccountId + cosmWasmClient: CosmWasmClient + apiUrl: string +} & Parameters[0] export async function getSubAccountIds({ - args: { accountId, cosmWasmClient, apiUrl, ...params }, + accountId, + cosmWasmClient, + apiUrl, + ...params }: GetSubAccountIdsParameters): Promise { const chainId = await cosmWasmClient.getChainId() const chainName = chainIdToName(chainId) const sub_accounts = await getSubAccountSequences({ - args: { - accountId, - cosmWasmClient, - apiUrl, - ...params, - }, + accountId, + cosmWasmClient, + apiUrl, + ...params, }) return sub_accounts.map((sequence) => diff --git a/packages/core/src/actions/account/public/get-sub-account-sequences.ts b/packages/core/src/actions/account/public/get-sub-account-sequences.ts index 4f647eab..602d6e57 100644 --- a/packages/core/src/actions/account/public/get-sub-account-sequences.ts +++ b/packages/core/src/actions/account/public/get-sub-account-sequences.ts @@ -3,26 +3,24 @@ import { ManagerQueryClient, VersionControlTypes, } from '../../../codegen/abstract' -import { WithArgs } from '../../../types/with-args' import { getManagerQueryClientFromApi } from './get-manager-query-client-from-api' -export type GetSubAccountSequencesParameters = WithArgs< - { - accountId: VersionControlTypes.AccountId - cosmWasmClient: CosmWasmClient - apiUrl: string - } & Parameters[0] -> +export type GetSubAccountSequencesParameters = { + accountId: VersionControlTypes.AccountId + cosmWasmClient: CosmWasmClient + apiUrl: string +} & Parameters[0] export async function getSubAccountSequences({ - args: { accountId, cosmWasmClient, apiUrl, ...params }, + accountId, + cosmWasmClient, + apiUrl, + ...params }: GetSubAccountSequencesParameters) { const managerQueryClient = await getManagerQueryClientFromApi({ - args: { - accountId, - cosmWasmClient, - apiUrl, - }, + accountId, + cosmWasmClient, + apiUrl, }) const { sub_accounts } = await managerQueryClient.subAccountIds(params) diff --git a/packages/core/src/actions/account/public/get-total-value.ts b/packages/core/src/actions/account/public/get-total-value.ts index 2c0fd19a..39efde8b 100644 --- a/packages/core/src/actions/account/public/get-total-value.ts +++ b/packages/core/src/actions/account/public/get-total-value.ts @@ -1,23 +1,22 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { VersionControlTypes } from '../../../codegen/abstract' -import { WithArgs } from '../../../types/with-args' import { getProxyQueryClientFromApi } from './get-proxy-query-client-from-api' -export type GetTotalValueParameters = WithArgs<{ +export type GetTotalValueParameters = { accountId: VersionControlTypes.AccountId cosmWasmClient: CosmWasmClient apiUrl: string -}> +} export async function getTotalValue({ - args: { accountId, cosmWasmClient, apiUrl }, + accountId, + cosmWasmClient, + apiUrl, }: GetTotalValueParameters): Promise { const proxyQueryClient = await getProxyQueryClientFromApi({ - args: { - accountId, - cosmWasmClient, - apiUrl, - }, + accountId, + cosmWasmClient, + apiUrl, }) const res = await proxyQueryClient.totalValue() // @TODO: might overflow a number diff --git a/packages/core/src/actions/account/wallet/claim-namespace.ts b/packages/core/src/actions/account/wallet/claim-namespace.ts index 31a0b646..31427c4a 100644 --- a/packages/core/src/actions/account/wallet/claim-namespace.ts +++ b/packages/core/src/actions/account/wallet/claim-namespace.ts @@ -1,10 +1,10 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { VersionControlClient } from '../../../codegen/abstract' -import { WithArgsAndCosmWasmSignOptions } from '../../../types/with-args' +import { WithCosmWasmSignOptions } from '../../../types/parameters' import { accountIdToParameter } from '../../../utils/account-id' import { getVersionControlClientFromApi } from '../../wallet/get-version-control-client-from-api' -export type ClaimNamespaceParameters = WithArgsAndCosmWasmSignOptions< +export type ClaimNamespaceParameters = WithCosmWasmSignOptions< { signingCosmWasmClient: SigningCosmWasmClient apiUrl: string @@ -14,13 +14,19 @@ export type ClaimNamespaceParameters = WithArgsAndCosmWasmSignOptions< > export async function claimNamespace({ - args: { signingCosmWasmClient, apiUrl, namespace, sender, accountId }, + signingCosmWasmClient, + apiUrl, + namespace, + sender, + accountId, fee, funds, memo, }: ClaimNamespaceParameters) { const versionControlClient = await getVersionControlClientFromApi({ - args: { signingCosmWasmClient, apiUrl, sender }, + signingCosmWasmClient, + apiUrl, + sender, }) return versionControlClient.claimNamespace( { accountId: accountIdToParameter(accountId), namespace }, diff --git a/packages/core/src/actions/account/wallet/create-sub-account.ts b/packages/core/src/actions/account/wallet/create-sub-account.ts index 6eeeccda..984ad4a7 100644 --- a/packages/core/src/actions/account/wallet/create-sub-account.ts +++ b/packages/core/src/actions/account/wallet/create-sub-account.ts @@ -1,9 +1,9 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { ManagerClient, VersionControlTypes } from '../../../codegen/abstract' -import { WithArgsAndCosmWasmSignOptions } from '../../../types/with-args' +import { WithCosmWasmSignOptions } from '../../../types/parameters' import { getManagerClientFromApi } from './get-manager-client-from-api' -export type CreateSubAccountParameters = WithArgsAndCosmWasmSignOptions< +export type CreateSubAccountParameters = WithCosmWasmSignOptions< { accountId: VersionControlTypes.AccountId signingCosmWasmClient: SigningCosmWasmClient @@ -16,25 +16,21 @@ export type CreateSubAccountParameters = WithArgsAndCosmWasmSignOptions< > export async function createSubAccount({ - args: { - accountId, - subAccountId, - signingCosmWasmClient, - apiUrl, - sender, - ...rest - }, + accountId, + subAccountId, + signingCosmWasmClient, + apiUrl, + sender, fee, memo, funds, + ...rest }: CreateSubAccountParameters) { const managerClient = await getManagerClientFromApi({ - args: { - accountId, - signingCosmWasmClient, - sender, - apiUrl, - }, + accountId, + signingCosmWasmClient, + sender, + apiUrl, }) return managerClient.createSubAccount( { ...rest, accountId: subAccountId }, diff --git a/packages/core/src/actions/account/wallet/deposit.ts b/packages/core/src/actions/account/wallet/deposit.ts index 9c488356..4b00f193 100644 --- a/packages/core/src/actions/account/wallet/deposit.ts +++ b/packages/core/src/actions/account/wallet/deposit.ts @@ -1,11 +1,11 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { VersionControlTypes } from '../../../codegen/abstract' -import { WithArgsAndCosmWasmSignOptions } from '../../../types/with-args' +import { WithCosmWasmSignOptions } from '../../../types/parameters' import { Asset, encodeAssetsTransfersMsgs } from '../../../utils/assets' import { getAccountBaseAddressesFromApi } from '../public/get-account-base-addresses-from-api' export type DepositParameters = Omit< - WithArgsAndCosmWasmSignOptions<{ + WithCosmWasmSignOptions<{ accountId: VersionControlTypes.AccountId signingCosmWasmClient: SigningCosmWasmClient apiUrl: string @@ -16,16 +16,18 @@ export type DepositParameters = Omit< > export async function deposit({ - args: { accountId, signingCosmWasmClient, apiUrl, sender, assets }, + accountId, + signingCosmWasmClient, + apiUrl, + sender, + assets, fee, memo, }: DepositParameters) { const { proxyAddress } = await getAccountBaseAddressesFromApi({ - args: { - accountId, - cosmWasmClient: signingCosmWasmClient, - apiUrl, - }, + accountId, + cosmWasmClient: signingCosmWasmClient, + apiUrl, }) return signingCosmWasmClient.signAndBroadcast( sender, diff --git a/packages/core/src/actions/account/wallet/execute.ts b/packages/core/src/actions/account/wallet/execute.ts index 33188633..09696e81 100644 --- a/packages/core/src/actions/account/wallet/execute.ts +++ b/packages/core/src/actions/account/wallet/execute.ts @@ -5,13 +5,13 @@ import { ProxyTypes, VersionControlTypes, } from '../../../codegen/abstract' +import { WithCosmWasmSignOptions } from '../../../types/parameters' import { MaybeArray } from '../../../types/utils' -import { WithArgsAndCosmWasmSignOptions } from '../../../types/with-args' import { jsonToBinary } from '../../../utils/encoding' import { getAccountBaseAddressesFromApi } from '../public/get-account-base-addresses-from-api' export type ExecuteParameters = Omit< - WithArgsAndCosmWasmSignOptions<{ + WithCosmWasmSignOptions<{ accountId: VersionControlTypes.AccountId signingCosmWasmClient: SigningCosmWasmClient apiUrl: string @@ -22,16 +22,18 @@ export type ExecuteParameters = Omit< > export async function execute({ - args: { accountId, signingCosmWasmClient, apiUrl, sender, msgs }, + accountId, + signingCosmWasmClient, + apiUrl, + sender, + msgs, fee, memo, }: ExecuteParameters) { const { managerAddress } = await getAccountBaseAddressesFromApi({ - args: { - accountId, - cosmWasmClient: signingCosmWasmClient, - apiUrl, - }, + accountId, + cosmWasmClient: signingCosmWasmClient, + apiUrl, }) return signingCosmWasmClient.signAndBroadcast( sender, diff --git a/packages/core/src/actions/account/wallet/get-manager-client-from-api.ts b/packages/core/src/actions/account/wallet/get-manager-client-from-api.ts index 514f5d7c..cc7d30ea 100644 --- a/packages/core/src/actions/account/wallet/get-manager-client-from-api.ts +++ b/packages/core/src/actions/account/wallet/get-manager-client-from-api.ts @@ -1,28 +1,30 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { VersionControlTypes } from '../../../codegen/abstract' -import { WithArgs } from '../../../types/with-args' import { getManagerClient } from '../../wallet/get-manager-client' import { getAccountBaseAddressesFromApi } from '../public/get-account-base-addresses-from-api' -export type GetManagerClientFromApiParameters = WithArgs<{ +export type GetManagerClientFromApiParameters = { accountId: VersionControlTypes.AccountId signingCosmWasmClient: SigningCosmWasmClient apiUrl: string sender: string -}> +} export async function getManagerClientFromApi({ - args: { accountId, signingCosmWasmClient, apiUrl, sender }, + accountId, + signingCosmWasmClient, + apiUrl, + sender, }: GetManagerClientFromApiParameters) { const { managerAddress } = await getAccountBaseAddressesFromApi({ - args: { - accountId, - cosmWasmClient: signingCosmWasmClient, - apiUrl, - }, + accountId, + cosmWasmClient: signingCosmWasmClient, + apiUrl, }) return getManagerClient({ - args: { signingCosmWasmClient, sender, managerAddress }, + signingCosmWasmClient, + sender, + managerAddress, }) } diff --git a/packages/core/src/actions/account/wallet/get-proxy-client-from-api.ts b/packages/core/src/actions/account/wallet/get-proxy-client-from-api.ts index e70087ee..1e70c70b 100644 --- a/packages/core/src/actions/account/wallet/get-proxy-client-from-api.ts +++ b/packages/core/src/actions/account/wallet/get-proxy-client-from-api.ts @@ -1,28 +1,30 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { VersionControlTypes } from '../../../codegen/abstract' -import { WithArgs } from '../../../types/with-args' import { getProxyClient } from '../../wallet/get-proxy-client' import { getAccountBaseAddressesFromApi } from '../public/get-account-base-addresses-from-api' -export type GetProxyClientFromApiParameters = WithArgs<{ +export type GetProxyClientFromApiParameters = { accountId: VersionControlTypes.AccountId signingCosmWasmClient: SigningCosmWasmClient sender: string apiUrl: string -}> +} export async function getProxyClientFromApi({ - args: { accountId, signingCosmWasmClient, sender, apiUrl }, + accountId, + signingCosmWasmClient, + sender, + apiUrl, }: GetProxyClientFromApiParameters) { const { proxyAddress } = await getAccountBaseAddressesFromApi({ - args: { - accountId, - cosmWasmClient: signingCosmWasmClient, - apiUrl, - }, + accountId, + cosmWasmClient: signingCosmWasmClient, + apiUrl, }) return getProxyClient({ - args: { signingCosmWasmClient, sender, proxyAddress }, + signingCosmWasmClient, + sender, + proxyAddress, }) } diff --git a/packages/core/src/actions/account/wallet/remove-namespace.ts b/packages/core/src/actions/account/wallet/remove-namespace.ts index c080afb4..3dbbf1b1 100644 --- a/packages/core/src/actions/account/wallet/remove-namespace.ts +++ b/packages/core/src/actions/account/wallet/remove-namespace.ts @@ -1,10 +1,10 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { VersionControlTypes } from '../../../codegen/abstract' -import { WithArgsAndCosmWasmSignOptions } from '../../../types/with-args' +import { WithCosmWasmSignOptions } from '../../../types/parameters' import { getVersionControlClientFromApi } from '../../wallet/get-version-control-client-from-api' import { getNamespace } from '../public/get-namespace' -export type RevokeNamespaceParameters = WithArgsAndCosmWasmSignOptions<{ +export type RevokeNamespaceParameters = WithCosmWasmSignOptions<{ accountId: VersionControlTypes.AccountId signingCosmWasmClient: SigningCosmWasmClient apiUrl: string @@ -12,20 +12,23 @@ export type RevokeNamespaceParameters = WithArgsAndCosmWasmSignOptions<{ }> export async function revokeNamespace({ - args: { accountId, signingCosmWasmClient, apiUrl, sender }, + accountId, + signingCosmWasmClient, + apiUrl, + sender, fee, memo, funds, }: RevokeNamespaceParameters) { const versionControlClient = await getVersionControlClientFromApi({ - args: { - signingCosmWasmClient, - apiUrl, - sender, - }, + signingCosmWasmClient, + apiUrl, + sender, }) const namespace = await getNamespace({ - args: { accountId, cosmWasmClient: signingCosmWasmClient, apiUrl }, + accountId, + cosmWasmClient: signingCosmWasmClient, + apiUrl, }) if (!namespace) throw new Error('Namespace not found') diff --git a/packages/core/src/actions/account/wallet/withdraw.ts b/packages/core/src/actions/account/wallet/withdraw.ts index 950a6aa6..5fb0b2e0 100644 --- a/packages/core/src/actions/account/wallet/withdraw.ts +++ b/packages/core/src/actions/account/wallet/withdraw.ts @@ -1,12 +1,11 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { VersionControlTypes } from '../../../codegen/abstract' -import { SliceFirstTwo } from '../../../types/utils' -import { WithArgsAndCosmWasmSignOptions } from '../../../types/with-args' +import { WithCosmWasmSignOptions } from '../../../types/parameters' import { Asset, encodeAssetsProxyTransferMsgs } from '../../../utils/assets' import { getAccountBaseAddressesFromApi } from '../public/get-account-base-addresses-from-api' import { execute } from './execute' -export type WithdrawParameters = WithArgsAndCosmWasmSignOptions<{ +export type WithdrawParameters = WithCosmWasmSignOptions<{ accountId: VersionControlTypes.AccountId signingCosmWasmClient: SigningCosmWasmClient apiUrl: string @@ -18,14 +17,17 @@ export type WithdrawParameters = WithArgsAndCosmWasmSignOptions<{ export async function withdraw({ fee, memo, - args: { accountId, signingCosmWasmClient, apiUrl, sender, assets, recipient }, + accountId, + signingCosmWasmClient, + apiUrl, + sender, + assets, + recipient, }: WithdrawParameters) { const { proxyAddress } = await getAccountBaseAddressesFromApi({ - args: { - accountId, - cosmWasmClient: signingCosmWasmClient, - apiUrl, - }, + accountId, + cosmWasmClient: signingCosmWasmClient, + apiUrl, }) const transferMsgs = encodeAssetsProxyTransferMsgs( @@ -35,13 +37,11 @@ export async function withdraw({ ) return execute({ - args: { - accountId, - signingCosmWasmClient, - apiUrl, - sender, - msgs: transferMsgs, - }, + accountId, + signingCosmWasmClient, + apiUrl, + sender, + msgs: transferMsgs, fee, memo, }) diff --git a/packages/core/src/actions/get-account-balance-from-api.ts b/packages/core/src/actions/get-account-balance-from-api.ts index c3941da6..4ede2637 100644 --- a/packages/core/src/actions/get-account-balance-from-api.ts +++ b/packages/core/src/actions/get-account-balance-from-api.ts @@ -1,18 +1,18 @@ import request from 'graphql-request' -import { tokenFromApi } from 'src/utils/tokens/token-from-api' import { tokenToAsset } from '..' import { gql } from '../codegen/gql' -import { WithArgs } from '../types/with-args' import { AccountId, accountIdToApiFormat } from '../utils/account-id' +import { tokenFromApi } from '../utils/tokens/token-from-api' -export type GetAccountBalancesFromApi = WithArgs<{ +export type GetAccountBalancesFromApiParameters = { apiUrl: string accountId: AccountId -}> +} export async function getAccountBalancesFromApi({ - args: { apiUrl, accountId }, -}: GetAccountBalancesFromApi) { + apiUrl, + accountId, +}: GetAccountBalancesFromApiParameters) { const result = await request( apiUrl, gql(/* GraphQL */ ` diff --git a/packages/core/src/actions/get-account-factory-address-from-api.ts b/packages/core/src/actions/get-account-factory-address-from-api.ts index f5652381..0c6aed26 100644 --- a/packages/core/src/actions/get-account-factory-address-from-api.ts +++ b/packages/core/src/actions/get-account-factory-address-from-api.ts @@ -1,14 +1,14 @@ import { request } from 'graphql-request' import { gql } from '../codegen/gql' -import { WithArgs } from '../types/with-args' -export type GetAccountFactoryAddressFromApiParameters = WithArgs<{ +export type GetAccountFactoryAddressFromApiParameters = { apiUrl: string chainName: string -}> +} export async function getAccountFactoryAddressFromApi({ - args: { apiUrl, chainName }, + apiUrl, + chainName, }: GetAccountFactoryAddressFromApiParameters) { const deploymentData = await request( apiUrl, diff --git a/packages/core/src/actions/get-accounts-by-owner-from-api.ts b/packages/core/src/actions/get-accounts-by-owner-from-api.ts index b0aefdc5..a67c3bd6 100644 --- a/packages/core/src/actions/get-accounts-by-owner-from-api.ts +++ b/packages/core/src/actions/get-accounts-by-owner-from-api.ts @@ -1,17 +1,18 @@ import request from 'graphql-request' import { gql } from '../codegen/gql' -import { WithArgs } from '../types/with-args' import { accountIdApiFormatToAccountId } from '../utils/account-id/account-id-api-format-to-account-id' -export type GetAccountsByOwnerFromApi = WithArgs<{ +export type GetAccountsByOwnerFromApiParameters = { apiUrl: string owner: string chains: string[] -}> +} export async function getAccountsByOwnerFromApi({ - args: { apiUrl, owner, chains }, -}: GetAccountsByOwnerFromApi) { + apiUrl, + owner, + chains, +}: GetAccountsByOwnerFromApiParameters) { const result = await request( apiUrl, gql(/* GraphQL */ ` diff --git a/packages/core/src/actions/get-ans-host-address-from-api.ts b/packages/core/src/actions/get-ans-host-address-from-api.ts index fbe21a5d..61341305 100644 --- a/packages/core/src/actions/get-ans-host-address-from-api.ts +++ b/packages/core/src/actions/get-ans-host-address-from-api.ts @@ -1,14 +1,14 @@ import { request } from 'graphql-request' import { gql } from '../codegen/gql' -import { WithArgs } from '../types/with-args' -export type GetAnsHostAddressFromApiParameters = WithArgs<{ +export type GetAnsHostAddressFromApiParameters = { apiUrl: string chainName: string -}> +} export async function getAnsHostAddressFromApi({ - args: { apiUrl, chainName }, + apiUrl, + chainName, }: GetAnsHostAddressFromApiParameters) { const deploymentData = await request( apiUrl, diff --git a/packages/core/src/actions/get-ans-token-from-api.ts b/packages/core/src/actions/get-ans-token-from-api.ts index 1da41df3..42a9eaba 100644 --- a/packages/core/src/actions/get-ans-token-from-api.ts +++ b/packages/core/src/actions/get-ans-token-from-api.ts @@ -1,18 +1,21 @@ -import { WithArgs } from '../types/with-args' import { AnsId } from '../utils/tokens/ans/types' import { getAnsTokensFromApi } from './get-ans-tokens-from-api' -export type GetAnsTokenFromApiParameters = WithArgs<{ +export type GetAnsTokenFromApiParameters = { apiUrl: string chainName: string id: AnsId -}> +} export async function getAnsTokenFromApi({ - args: { apiUrl, chainName, id }, + apiUrl, + chainName, + id, }: GetAnsTokenFromApiParameters) { const result = await getAnsTokensFromApi({ - args: { apiUrl, chainName, ids: [id] }, + apiUrl, + chainName, + ids: [id], }).then((tokens) => tokens[0]) if (!result) throw new Error(`Cannot find token with id ${id}`) return result diff --git a/packages/core/src/actions/get-ans-tokens-from-api.ts b/packages/core/src/actions/get-ans-tokens-from-api.ts index 1e925862..47b2db86 100644 --- a/packages/core/src/actions/get-ans-tokens-from-api.ts +++ b/packages/core/src/actions/get-ans-tokens-from-api.ts @@ -1,17 +1,18 @@ import { request } from 'graphql-request' import { gql } from '../codegen/gql' -import { WithArgs } from '../types/with-args' import { ansTokenFromApi } from '../utils/tokens/ans/ans-token-from-api' import { AnsId } from '../utils/tokens/ans/types' -export type GetAnsTokensFromApiParameters = WithArgs<{ +export type GetAnsTokensFromApiParameters = { apiUrl: string chainName: string ids: AnsId[] -}> +} export async function getAnsTokensFromApi({ - args: { apiUrl, chainName, ids }, + apiUrl, + chainName, + ids, }: GetAnsTokensFromApiParameters) { const result = await request( apiUrl, diff --git a/packages/core/src/actions/get-version-control-address-from-api.ts b/packages/core/src/actions/get-version-control-address-from-api.ts index ab978147..7ed95d1b 100644 --- a/packages/core/src/actions/get-version-control-address-from-api.ts +++ b/packages/core/src/actions/get-version-control-address-from-api.ts @@ -1,14 +1,14 @@ import { request } from 'graphql-request' import { gql } from '../codegen/gql' -import { WithArgs } from '../types/with-args' -export type GetVersionControlAddressFromApiParameters = WithArgs<{ +export type GetVersionControlAddressFromApiParameters = { apiUrl: string chainName: string -}> +} export async function getVersionControlAddressFromApi({ - args: { apiUrl, chainName }, + apiUrl, + chainName, }: GetVersionControlAddressFromApiParameters) { const deploymentData = await request( apiUrl, diff --git a/packages/core/src/actions/index.ts b/packages/core/src/actions/index.ts new file mode 100644 index 00000000..0defba84 --- /dev/null +++ b/packages/core/src/actions/index.ts @@ -0,0 +1,70 @@ +export * from './get-account-balance-from-api' +export * from './get-account-factory-address-from-api' +export * from './get-accounts-by-owner-from-api' +export * from './get-ans-host-address-from-api' +export * from './get-ans-token-from-api' +export * from './get-ans-tokens-from-api' +export * from './get-version-control-address-from-api' + +export * from './account/public/get-account-base-addresses-from-api' +export * from './account/public/get-base-token' +export * from './account/public/get-ibc-client-query-client-from-manager' +export * from './account/public/get-manager-query-client-from-api' +export * from './account/public/get-module-address' +export * from './account/public/get-module-instantiate2-address-from-api' +export * from './account/public/get-modules' +export * from './account/public/get-namespace' +export * from './account/public/get-owner' +export * from './account/public/get-proxy-query-client-from-api' +export * from './account/public/get-remote-account-ids' +export * from './account/public/get-remote-account-proxies' +export * from './account/public/get-sub-account-ids' +export * from './account/public/get-sub-account-sequences' +export * from './account/public/get-total-value' + +export * from './account/wallet/claim-namespace' +export * from './account/wallet/create-sub-account' +export * from './account/wallet/deposit' +export * from './account/wallet/execute' +export * from './account/wallet/get-manager-client-from-api' +export * from './account/wallet/get-proxy-client-from-api' +export * from './account/wallet/remove-namespace' +export * from './account/wallet/withdraw' + +export * from './public/get-abstract-module-address-from-version-control' +export * from './public/get-abstract-module-version' +export * from './public/get-account-factory-address-from-version-control' +export * from './public/get-account-factory-query-client-from-api' +export * from './public/get-account-factory-query-client-from-version-control' +export * from './public/get-account-factory-query-client' +export * from './public/get-account-factory-version' +export * from './public/get-ans-host-address-from-version-control' +export * from './public/get-ans-host-query-client-from-api' +export * from './public/get-ans-host-query-client-from-version-control' +export * from './public/get-ans-host-query-client' +export * from './public/get-ans-host-version' +export * from './public/get-app-module-code-id-from-version-control' +export * from './public/get-cosm-wasm-client' +export * from './public/get-manager-query-client' +export * from './public/get-module-factory-address-from-version-control' +export * from './public/get-module-factory-version' +export * from './public/get-proxy-query-client' +export * from './public/get-version-control-module-data' +export * from './public/get-version-control-query-client-from-api' +export * from './public/get-version-control-query-client' +export * from './public/types' + +export * from './wallet/create-account-monarchy' +export * from './wallet/create-account' +export * from './wallet/get-account-factory-client-from-api' +export * from './wallet/get-account-factory-client-from-version-control' +export * from './wallet/get-account-factory-client' +export * from './wallet/get-ans-host-client-from-api' +export * from './wallet/get-ans-host-client-from-version-control' +export * from './wallet/get-ans-host-client' +export * from './wallet/get-manager-client' +export * from './wallet/get-proxy-client' +export * from './wallet/get-sender-address' +export * from './wallet/get-signing-cosm-wasm-client' +export * from './wallet/get-version-control-client-from-api' +export * from './wallet/get-version-control-client' diff --git a/packages/core/src/actions/public/get-abstract-module-address-from-version-control.ts b/packages/core/src/actions/public/get-abstract-module-address-from-version-control.ts index c6cc9e52..3b997a4b 100644 --- a/packages/core/src/actions/public/get-abstract-module-address-from-version-control.ts +++ b/packages/core/src/actions/public/get-abstract-module-address-from-version-control.ts @@ -1,31 +1,25 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { VersionControlTypes } from '../../codegen/abstract' -import { WithArgs } from '../../types/with-args' import { versionControlModuleToAddress } from '../../utils/version-control/version-control-module-to-address' import { getVersionControlQueryClient } from './get-version-control-query-client' -export enum CommonModuleNames { - ACCOUNT_FACTORY = 'account-factory', - MODULE_FACTORY = 'module-factory', - ANS_HOST = 'ans-host', -} - -export type GetAbstractModuleAddressFromVersionControl = WithArgs<{ +export type GetAbstractModuleAddressFromVersionControl = { moduleName: string cosmWasmClient: CosmWasmClient versionControlAddress: string version?: string -}> +} export async function getAbstractModuleAddressFromVersionControl({ - args: { moduleName, cosmWasmClient, versionControlAddress, version }, + moduleName, + cosmWasmClient, + versionControlAddress, + version, }: GetAbstractModuleAddressFromVersionControl) { const versionControlQueryClient = getVersionControlQueryClient({ - args: { - cosmWasmClient, - versionControlAddress, - }, + cosmWasmClient, + versionControlAddress, }) const [moduleAddress] = await versionControlQueryClient diff --git a/packages/core/src/actions/public/get-abstract-module-version.ts b/packages/core/src/actions/public/get-abstract-module-version.ts index f5beac25..6fab9ed7 100644 --- a/packages/core/src/actions/public/get-abstract-module-version.ts +++ b/packages/core/src/actions/public/get-abstract-module-version.ts @@ -1,31 +1,25 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { VersionControlTypes } from '../../codegen/abstract' -import { WithArgs } from '../../types/with-args' import { versionControlModuleToVersion } from '../../utils/version-control/version-control-module-to-version' import { getVersionControlQueryClientFromApi } from './get-version-control-query-client-from-api' -export enum CommonModuleNames { - ACCOUNT_FACTORY = 'account-factory', - MODULE_FACTORY = 'module-factory', - ANS_HOST = 'ans-host', -} - -export type GetAbstractModuleVersion = WithArgs<{ +export type GetAbstractModuleVersion = { moduleName: string cosmWasmClient: CosmWasmClient version?: string apiUrl: string -}> +} export async function getAbstractModuleVersion({ - args: { moduleName, cosmWasmClient, version, apiUrl }, + moduleName, + cosmWasmClient, + version, + apiUrl, }: GetAbstractModuleVersion) { const versionControlQueryClient = await getVersionControlQueryClientFromApi({ - args: { - cosmWasmClient, - apiUrl, - }, + cosmWasmClient, + apiUrl, }) const [moduleVersion] = await versionControlQueryClient diff --git a/packages/core/src/actions/public/get-account-factory-address-from-version-control.ts b/packages/core/src/actions/public/get-account-factory-address-from-version-control.ts index 36507cda..9b3bc62f 100644 --- a/packages/core/src/actions/public/get-account-factory-address-from-version-control.ts +++ b/packages/core/src/actions/public/get-account-factory-address-from-version-control.ts @@ -1,25 +1,22 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { WithArgs } from '../../types/with-args' -import { - CommonModuleNames, - getAbstractModuleAddressFromVersionControl, -} from './get-abstract-module-address-from-version-control' +import { getAbstractModuleAddressFromVersionControl } from './get-abstract-module-address-from-version-control' +import { CommonModuleNames } from './types' -export type GetAccountFactoryAddressFromVersionControlParameters = WithArgs<{ +export type GetAccountFactoryAddressFromVersionControlParameters = { cosmWasmClient: CosmWasmClient versionControlAddress: string version?: string -}> +} export async function getAccountFactoryAddressFromVersionControl({ - args: { cosmWasmClient, versionControlAddress, version }, + cosmWasmClient, + versionControlAddress, + version, }: GetAccountFactoryAddressFromVersionControlParameters) { return getAbstractModuleAddressFromVersionControl({ - args: { - moduleName: CommonModuleNames.ACCOUNT_FACTORY, - cosmWasmClient, - versionControlAddress, - version, - }, + moduleName: CommonModuleNames.ACCOUNT_FACTORY, + cosmWasmClient, + versionControlAddress, + version, }) } diff --git a/packages/core/src/actions/public/get-account-factory-query-client-from-api.ts b/packages/core/src/actions/public/get-account-factory-query-client-from-api.ts index db07cfd1..2db339ca 100644 --- a/packages/core/src/actions/public/get-account-factory-query-client-from-api.ts +++ b/packages/core/src/actions/public/get-account-factory-query-client-from-api.ts @@ -1,25 +1,27 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { WithArgs } from '../../types/with-args' import { chainIdToName } from '../../utils/chain-registry' import { getAccountFactoryAddressFromApi } from '../get-account-factory-address-from-api' import { getAccountFactoryQueryClient } from './get-account-factory-query-client' -export type GetAccountFactoryQueryClientFromApiParameters = WithArgs<{ +export type GetAccountFactoryQueryClientFromApiParameters = { cosmWasmClient: CosmWasmClient apiUrl: string -}> +} export async function getAccountFactoryQueryClientFromApi({ - args: { cosmWasmClient, apiUrl }, + cosmWasmClient, + apiUrl, }: GetAccountFactoryQueryClientFromApiParameters) { const chainId = await cosmWasmClient.getChainId() const chainName = chainIdToName(chainId) const accountFactoryAddress = await getAccountFactoryAddressFromApi({ - args: { apiUrl, chainName }, + apiUrl, + chainName, }) return getAccountFactoryQueryClient({ - args: { cosmWasmClient, accountFactoryAddress }, + cosmWasmClient, + accountFactoryAddress, }) } diff --git a/packages/core/src/actions/public/get-account-factory-query-client-from-version-control.ts b/packages/core/src/actions/public/get-account-factory-query-client-from-version-control.ts index cc193901..bbd8b0a1 100644 --- a/packages/core/src/actions/public/get-account-factory-query-client-from-version-control.ts +++ b/packages/core/src/actions/public/get-account-factory-query-client-from-version-control.ts @@ -1,29 +1,28 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { WithArgs } from '../../types/with-args' import { getAccountFactoryAddressFromVersionControl } from './get-account-factory-address-from-version-control' import { getAccountFactoryQueryClient } from './get-account-factory-query-client' -export type GetAccountFactoryQueryClientFromVersionControlParameters = - WithArgs<{ - cosmWasmClient: CosmWasmClient - versionControlAddress: string - version?: string - }> +export type GetAccountFactoryQueryClientFromVersionControlParameters = { + cosmWasmClient: CosmWasmClient + versionControlAddress: string + version?: string +} export async function getAccountFactoryQueryClientFromVersionControl({ - args: { cosmWasmClient, versionControlAddress, version }, + cosmWasmClient, + versionControlAddress, + version, }: GetAccountFactoryQueryClientFromVersionControlParameters) { const accountFactoryAddress = await getAccountFactoryAddressFromVersionControl({ - args: { - cosmWasmClient, - versionControlAddress, - version, - }, + cosmWasmClient, + versionControlAddress, + version, }) return getAccountFactoryQueryClient({ - args: { cosmWasmClient, accountFactoryAddress }, + cosmWasmClient, + accountFactoryAddress, }) } diff --git a/packages/core/src/actions/public/get-account-factory-query-client.ts b/packages/core/src/actions/public/get-account-factory-query-client.ts index 882e61f3..10ea08e4 100644 --- a/packages/core/src/actions/public/get-account-factory-query-client.ts +++ b/packages/core/src/actions/public/get-account-factory-query-client.ts @@ -1,15 +1,15 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { AccountFactoryQueryClient } from '../../codegen/abstract' -import { WithArgs } from '../../types/with-args' -export type GetAccountFactoryQueryClientParameters = WithArgs<{ +export type GetAccountFactoryQueryClientParameters = { cosmWasmClient: CosmWasmClient accountFactoryAddress: string -}> +} export async function getAccountFactoryQueryClient({ - args: { cosmWasmClient, accountFactoryAddress }, + cosmWasmClient, + accountFactoryAddress, }: GetAccountFactoryQueryClientParameters) { return new AccountFactoryQueryClient(cosmWasmClient, accountFactoryAddress) } diff --git a/packages/core/src/actions/public/get-account-factory-version.ts b/packages/core/src/actions/public/get-account-factory-version.ts index fc45e73d..9c701139 100644 --- a/packages/core/src/actions/public/get-account-factory-version.ts +++ b/packages/core/src/actions/public/get-account-factory-version.ts @@ -1,25 +1,22 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { WithArgs } from '../../types/with-args' -import { - CommonModuleNames, - getAbstractModuleVersion, -} from './get-abstract-module-version' +import { getAbstractModuleVersion } from './get-abstract-module-version' +import { CommonModuleNames } from './types' -export type GetAccountFactoryVersionParameters = WithArgs<{ +export type GetAccountFactoryVersionParameters = { cosmWasmClient: CosmWasmClient apiUrl: string version?: string -}> +} export async function getAccountFactoryVersion({ - args: { cosmWasmClient, apiUrl, version }, + cosmWasmClient, + apiUrl, + version, }: GetAccountFactoryVersionParameters) { return getAbstractModuleVersion({ - args: { - apiUrl, - moduleName: CommonModuleNames.ACCOUNT_FACTORY, - cosmWasmClient, - version, - }, + apiUrl, + moduleName: CommonModuleNames.ACCOUNT_FACTORY, + cosmWasmClient, + version, }) } diff --git a/packages/core/src/actions/public/get-ans-host-address-from-version-control.ts b/packages/core/src/actions/public/get-ans-host-address-from-version-control.ts index 69a7ea04..01b04fc3 100644 --- a/packages/core/src/actions/public/get-ans-host-address-from-version-control.ts +++ b/packages/core/src/actions/public/get-ans-host-address-from-version-control.ts @@ -1,25 +1,22 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { WithArgs } from '../../types/with-args' -import { - CommonModuleNames, - getAbstractModuleAddressFromVersionControl, -} from './get-abstract-module-address-from-version-control' +import { getAbstractModuleAddressFromVersionControl } from './get-abstract-module-address-from-version-control' +import { CommonModuleNames } from './types' -export type GetAnsHostAddressFromVersionControlParameters = WithArgs<{ +export type GetAnsHostAddressFromVersionControlParameters = { cosmWasmClient: CosmWasmClient versionControlAddress: string version?: string -}> +} export async function getAnsHostAddressFromVersionControl({ - args: { cosmWasmClient, versionControlAddress, version }, + cosmWasmClient, + versionControlAddress, + version, }: GetAnsHostAddressFromVersionControlParameters) { return getAbstractModuleAddressFromVersionControl({ - args: { - moduleName: CommonModuleNames.ANS_HOST, - cosmWasmClient, - versionControlAddress, - version, - }, + moduleName: CommonModuleNames.ANS_HOST, + cosmWasmClient, + versionControlAddress, + version, }) } diff --git a/packages/core/src/actions/public/get-ans-host-query-client-from-api.ts b/packages/core/src/actions/public/get-ans-host-query-client-from-api.ts index 5a77d6b3..f1ab7c08 100644 --- a/packages/core/src/actions/public/get-ans-host-query-client-from-api.ts +++ b/packages/core/src/actions/public/get-ans-host-query-client-from-api.ts @@ -1,24 +1,25 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { WithArgs } from '../../types/with-args' import { chainIdToName } from '../../utils/chain-registry' import { getAnsHostAddressFromApi } from '../get-ans-host-address-from-api' import { getAnsHostQueryClient } from './get-ans-host-query-client' -export type GetAnsHostQueryClientFromApiParameters = WithArgs<{ +export type GetAnsHostQueryClientFromApiParameters = { cosmWasmClient: CosmWasmClient apiUrl: string -}> +} export async function getAnsHostQueryClientFromApi({ - args: { cosmWasmClient, apiUrl }, + cosmWasmClient, + apiUrl, }: GetAnsHostQueryClientFromApiParameters) { const chainId = await cosmWasmClient.getChainId() const chainName = chainIdToName(chainId) const ansHostAddress = await getAnsHostAddressFromApi({ - args: { apiUrl, chainName }, + apiUrl, + chainName, }) - return getAnsHostQueryClient({ args: { cosmWasmClient, ansHostAddress } }) + return getAnsHostQueryClient({ cosmWasmClient, ansHostAddress }) } diff --git a/packages/core/src/actions/public/get-ans-host-query-client-from-version-control.ts b/packages/core/src/actions/public/get-ans-host-query-client-from-version-control.ts index a6c08a6b..16fcbfda 100644 --- a/packages/core/src/actions/public/get-ans-host-query-client-from-version-control.ts +++ b/packages/core/src/actions/public/get-ans-host-query-client-from-version-control.ts @@ -1,24 +1,23 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { WithArgs } from '../../types/with-args' import { getAnsHostAddressFromVersionControl } from './get-ans-host-address-from-version-control' import { getAnsHostQueryClient } from './get-ans-host-query-client' -export type GetAnsHostQueryClientFromVersionControlParameters = WithArgs<{ +export type GetAnsHostQueryClientFromVersionControlParameters = { cosmWasmClient: CosmWasmClient versionControlAddress: string version?: string -}> +} export async function getAnsHostQueryClientFromVersionControl({ - args: { cosmWasmClient, versionControlAddress, version }, + cosmWasmClient, + versionControlAddress, + version, }: GetAnsHostQueryClientFromVersionControlParameters) { const ansHostAddress = await getAnsHostAddressFromVersionControl({ - args: { - cosmWasmClient, - versionControlAddress, - version, - }, + cosmWasmClient, + versionControlAddress, + version, }) - return getAnsHostQueryClient({ args: { cosmWasmClient, ansHostAddress } }) + return getAnsHostQueryClient({ cosmWasmClient, ansHostAddress }) } diff --git a/packages/core/src/actions/public/get-ans-host-query-client.ts b/packages/core/src/actions/public/get-ans-host-query-client.ts index 83c8e7f0..53e24764 100644 --- a/packages/core/src/actions/public/get-ans-host-query-client.ts +++ b/packages/core/src/actions/public/get-ans-host-query-client.ts @@ -1,15 +1,15 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { AnsHostQueryClient } from '../../codegen/abstract' -import { WithArgs } from '../../types/with-args' -export type GetAnsHostQueryClientParameters = WithArgs<{ +export type GetAnsHostQueryClientParameters = { cosmWasmClient: CosmWasmClient ansHostAddress: string -}> +} export async function getAnsHostQueryClient({ - args: { cosmWasmClient, ansHostAddress }, + cosmWasmClient, + ansHostAddress, }: GetAnsHostQueryClientParameters) { return new AnsHostQueryClient(cosmWasmClient, ansHostAddress) } diff --git a/packages/core/src/actions/public/get-ans-host-version.ts b/packages/core/src/actions/public/get-ans-host-version.ts index 0b9588a1..822e895b 100644 --- a/packages/core/src/actions/public/get-ans-host-version.ts +++ b/packages/core/src/actions/public/get-ans-host-version.ts @@ -1,25 +1,22 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { WithArgs } from '../../types/with-args' -import { - CommonModuleNames, - getAbstractModuleVersion, -} from './get-abstract-module-version' +import { getAbstractModuleVersion } from './get-abstract-module-version' +import { CommonModuleNames } from './types' -export type GetAnsHostVersionParameters = WithArgs<{ +export type GetAnsHostVersionParameters = { cosmWasmClient: CosmWasmClient apiUrl: string version?: string -}> +} export async function getAnsHostVersion({ - args: { cosmWasmClient, apiUrl, version }, + cosmWasmClient, + apiUrl, + version, }: GetAnsHostVersionParameters) { return getAbstractModuleVersion({ - args: { - moduleName: CommonModuleNames.ANS_HOST, - cosmWasmClient, - apiUrl, - version, - }, + moduleName: CommonModuleNames.ANS_HOST, + cosmWasmClient, + apiUrl, + version, }) } diff --git a/packages/core/src/actions/public/get-app-module-code-id-from-version-control.ts b/packages/core/src/actions/public/get-app-module-code-id-from-version-control.ts index d33ab689..54ae48dd 100644 --- a/packages/core/src/actions/public/get-app-module-code-id-from-version-control.ts +++ b/packages/core/src/actions/public/get-app-module-code-id-from-version-control.ts @@ -6,25 +6,25 @@ import { moduleIdToNamespace, } from '@abstract-money/core' import { VersionControlTypes } from '../../codegen/abstract' -import { WithArgs } from '../../types/with-args' import { versionControlModuleToCodeId } from '../../utils/version-control/version-control-module-to-code-id' import { getVersionControlQueryClient } from './get-version-control-query-client' -export type GetAppModuleCodeIdFromVersionControl = WithArgs<{ +export type GetAppModuleCodeIdFromVersionControl = { moduleId: `${ModuleId}` cosmWasmClient: CosmWasmClient versionControlAddress: string version?: VersionControlTypes.ModuleVersion -}> +} export async function getAppModuleCodeIdFromVersionControl({ - args: { moduleId, cosmWasmClient, versionControlAddress, version }, + moduleId, + cosmWasmClient, + versionControlAddress, + version, }: GetAppModuleCodeIdFromVersionControl) { const versionControlQueryClient = getVersionControlQueryClient({ - args: { - cosmWasmClient, - versionControlAddress, - }, + cosmWasmClient, + versionControlAddress, }) const [moduleAddress] = await versionControlQueryClient diff --git a/packages/core/src/actions/public/get-cosm-wasm-client.ts b/packages/core/src/actions/public/get-cosm-wasm-client.ts index de8b97c4..532ea9b7 100644 --- a/packages/core/src/actions/public/get-cosm-wasm-client.ts +++ b/packages/core/src/actions/public/get-cosm-wasm-client.ts @@ -1,13 +1,11 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { WithArgs } from '../../types/with-args' - -export type GetCosmWasmClientParameters = WithArgs<{ +export type GetCosmWasmClientParameters = { cosmWasmClient: CosmWasmClient -}> +} export async function getCosmWasmClient({ - args: { cosmWasmClient }, + cosmWasmClient, }: GetCosmWasmClientParameters) { return cosmWasmClient } diff --git a/packages/core/src/actions/public/get-manager-query-client.ts b/packages/core/src/actions/public/get-manager-query-client.ts index 31f5b76f..b512cf32 100644 --- a/packages/core/src/actions/public/get-manager-query-client.ts +++ b/packages/core/src/actions/public/get-manager-query-client.ts @@ -1,14 +1,14 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { ManagerQueryClient } from '../../codegen/abstract' -import { WithArgs } from '../../types/with-args' -export type GetManagerQueryClientParameters = WithArgs<{ +export type GetManagerQueryClientParameters = { cosmWasmClient: CosmWasmClient managerAddress: string -}> +} export async function getManagerQueryClient({ - args: { cosmWasmClient, managerAddress }, + cosmWasmClient, + managerAddress, }: GetManagerQueryClientParameters) { return new ManagerQueryClient(cosmWasmClient, managerAddress) } diff --git a/packages/core/src/actions/public/get-module-factory-address-from-version-control.ts b/packages/core/src/actions/public/get-module-factory-address-from-version-control.ts index 29e31aea..21b9ad69 100644 --- a/packages/core/src/actions/public/get-module-factory-address-from-version-control.ts +++ b/packages/core/src/actions/public/get-module-factory-address-from-version-control.ts @@ -1,25 +1,22 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { WithArgs } from '../../types/with-args' -import { - CommonModuleNames, - getAbstractModuleAddressFromVersionControl, -} from './get-abstract-module-address-from-version-control' +import { getAbstractModuleAddressFromVersionControl } from './get-abstract-module-address-from-version-control' +import { CommonModuleNames } from './types' -export type GetModuleFactoryAddressFromVersionControlParameters = WithArgs<{ +export type GetModuleFactoryAddressFromVersionControlParameters = { cosmWasmClient: CosmWasmClient versionControlAddress: string version?: string -}> +} export async function getModuleFactoryAddressFromVersionControl({ - args: { cosmWasmClient, versionControlAddress, version }, + cosmWasmClient, + versionControlAddress, + version, }: GetModuleFactoryAddressFromVersionControlParameters) { return getAbstractModuleAddressFromVersionControl({ - args: { - moduleName: CommonModuleNames.MODULE_FACTORY, - cosmWasmClient, - versionControlAddress, - version, - }, + moduleName: CommonModuleNames.MODULE_FACTORY, + cosmWasmClient, + versionControlAddress, + version, }) } diff --git a/packages/core/src/actions/public/get-module-factory-version.ts b/packages/core/src/actions/public/get-module-factory-version.ts index 8f168bf3..9d3aece1 100644 --- a/packages/core/src/actions/public/get-module-factory-version.ts +++ b/packages/core/src/actions/public/get-module-factory-version.ts @@ -1,25 +1,22 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { WithArgs } from '../../types/with-args' -import { - CommonModuleNames, - getAbstractModuleVersion, -} from './get-abstract-module-version' +import { getAbstractModuleVersion } from './get-abstract-module-version' +import { CommonModuleNames } from './types' -export type GetModuleFactoryVersionParameters = WithArgs<{ +export type GetModuleFactoryVersionParameters = { cosmWasmClient: CosmWasmClient apiUrl: string version?: string -}> +} export async function getModuleFactoryVersion({ - args: { cosmWasmClient, apiUrl, version }, + cosmWasmClient, + apiUrl, + version, }: GetModuleFactoryVersionParameters) { return getAbstractModuleVersion({ - args: { - moduleName: CommonModuleNames.MODULE_FACTORY, - cosmWasmClient, - apiUrl, - version, - }, + moduleName: CommonModuleNames.MODULE_FACTORY, + cosmWasmClient, + apiUrl, + version, }) } diff --git a/packages/core/src/actions/public/get-proxy-query-client.ts b/packages/core/src/actions/public/get-proxy-query-client.ts index 4b7ad731..954d9a60 100644 --- a/packages/core/src/actions/public/get-proxy-query-client.ts +++ b/packages/core/src/actions/public/get-proxy-query-client.ts @@ -1,14 +1,14 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { ProxyQueryClient } from '../../codegen/abstract' -import { WithArgs } from '../../types/with-args' -export type GetProxyQueryClientParameters = WithArgs<{ +export type GetProxyQueryClientParameters = { cosmWasmClient: CosmWasmClient proxyAddress: string -}> +} export async function getProxyQueryClient({ - args: { cosmWasmClient, proxyAddress }, + cosmWasmClient, + proxyAddress, }: GetProxyQueryClientParameters) { return new ProxyQueryClient(cosmWasmClient, proxyAddress) } diff --git a/packages/core/src/actions/public/get-version-control-module-data.ts b/packages/core/src/actions/public/get-version-control-module-data.ts index 7672acde..766b84f8 100644 --- a/packages/core/src/actions/public/get-version-control-module-data.ts +++ b/packages/core/src/actions/public/get-version-control-module-data.ts @@ -3,7 +3,6 @@ import { type CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { match } from 'ts-pattern' import { VersionControlTypes } from '../../codegen/abstract' import { type ModuleData } from '../../legacy/generics/Module.types' -import { WithArgs } from '../../types/with-args' import { formatModuleIdWithVersion } from '../../utils/version-control/module-id/format-module-id-with-version' import { versionControlModuleToAddress } from '../../utils/version-control/version-control-module-to-address' import { versionControlModuleToCodeId } from '../../utils/version-control/version-control-module-to-code-id' @@ -11,12 +10,13 @@ import { versionControlModuleToType } from '../../utils/version-control/version- export type GetVersionControlModuleDataParameters< TVcModule extends VersionControlTypes.Module = VersionControlTypes.Module, -> = WithArgs<{ cosmWasmClient: CosmWasmClient; module: TVcModule }> +> = { cosmWasmClient: CosmWasmClient; module: TVcModule } export async function getVersionControlModuleData< const TVcModule extends VersionControlTypes.Module = VersionControlTypes.Module, >({ - args: { cosmWasmClient, module }, + cosmWasmClient, + module, }: GetVersionControlModuleDataParameters): Promise { // Retrieve the first instantiation of the module const moduleType = versionControlModuleToType(module) diff --git a/packages/core/src/actions/public/get-version-control-query-client-from-api.ts b/packages/core/src/actions/public/get-version-control-query-client-from-api.ts index 82559bd7..0b68f4e4 100644 --- a/packages/core/src/actions/public/get-version-control-query-client-from-api.ts +++ b/packages/core/src/actions/public/get-version-control-query-client-from-api.ts @@ -1,28 +1,27 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { WithArgs } from '../../types/with-args' import { chainIdToName } from '../../utils/chain-registry' import { getVersionControlAddressFromApi } from '../get-version-control-address-from-api' import { getVersionControlQueryClient } from './get-version-control-query-client' -export type GetVersionControlQueryClientFromApiParameters = WithArgs<{ +export type GetVersionControlQueryClientFromApiParameters = { cosmWasmClient: CosmWasmClient apiUrl: string -}> +} export async function getVersionControlQueryClientFromApi({ - args: { cosmWasmClient, apiUrl }, + cosmWasmClient, + apiUrl, }: GetVersionControlQueryClientFromApiParameters) { const chainId = await cosmWasmClient.getChainId() const chainName = chainIdToName(chainId) const versionControlAddress = await getVersionControlAddressFromApi({ - args: { - apiUrl, - chainName, - }, + apiUrl, + chainName, }) return getVersionControlQueryClient({ - args: { cosmWasmClient, versionControlAddress }, + cosmWasmClient, + versionControlAddress, }) } diff --git a/packages/core/src/actions/public/get-version-control-query-client.ts b/packages/core/src/actions/public/get-version-control-query-client.ts index 4eed130b..e6779332 100644 --- a/packages/core/src/actions/public/get-version-control-query-client.ts +++ b/packages/core/src/actions/public/get-version-control-query-client.ts @@ -1,15 +1,15 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { VersionControlQueryClient } from '../../codegen/abstract' -import { WithArgs } from '../../types/with-args' -export type GetVersionControlQueryClientParameters = WithArgs<{ +export type GetVersionControlQueryClientParameters = { cosmWasmClient: CosmWasmClient versionControlAddress: string -}> +} export function getVersionControlQueryClient({ - args: { cosmWasmClient, versionControlAddress }, + cosmWasmClient, + versionControlAddress, }: GetVersionControlQueryClientParameters) { return new VersionControlQueryClient(cosmWasmClient, versionControlAddress) } diff --git a/packages/core/src/actions/public/types.ts b/packages/core/src/actions/public/types.ts new file mode 100644 index 00000000..95c7929f --- /dev/null +++ b/packages/core/src/actions/public/types.ts @@ -0,0 +1,5 @@ +export enum CommonModuleNames { + ACCOUNT_FACTORY = 'account-factory', + MODULE_FACTORY = 'module-factory', + ANS_HOST = 'ans-host', +} diff --git a/packages/core/src/actions/wallet/create-account-monarchy.ts b/packages/core/src/actions/wallet/create-account-monarchy.ts index b4571017..33e27995 100644 --- a/packages/core/src/actions/wallet/create-account-monarchy.ts +++ b/packages/core/src/actions/wallet/create-account-monarchy.ts @@ -1,11 +1,11 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { AccountFactoryClient } from '../../codegen/abstract' +import { WithCosmWasmSignOptions } from '../../types/parameters' import { WithOptional } from '../../types/utils' -import { WithArgsAndCosmWasmSignOptions } from '../../types/with-args' import { accountIdToParameter } from '../../utils' import { createAccount } from './create-account' -export type CreateAccountMonarchyParameters = WithArgsAndCosmWasmSignOptions< +export type CreateAccountMonarchyParameters = WithCosmWasmSignOptions< { signingCosmWasmClient: SigningCosmWasmClient apiUrl: string @@ -21,41 +21,37 @@ export type CreateAccountMonarchyParameters = WithArgsAndCosmWasmSignOptions< > export async function createAccountMonarchy({ - args: { - signingCosmWasmClient, - apiUrl, - sender, - installModules = [], - baseAsset, - description, - name, - namespace, - link, - owner, - accountId, - }, + signingCosmWasmClient, + apiUrl, + sender, + installModules = [], + baseAsset, + description, + name, + namespace, + link, + owner, + accountId, fee, memo, funds, }: CreateAccountMonarchyParameters) { return createAccount({ - args: { - signingCosmWasmClient, - apiUrl, - sender, - governance: { - Monarchy: { - monarch: owner, - }, + signingCosmWasmClient, + apiUrl, + sender, + governance: { + Monarchy: { + monarch: owner, }, - name, - description, - link, - installModules, - baseAsset, - namespace, - accountId: accountId ? accountIdToParameter(accountId) : undefined, }, + name, + description, + link, + installModules, + baseAsset, + namespace, + accountId: accountId ? accountIdToParameter(accountId) : undefined, fee, memo, funds, diff --git a/packages/core/src/actions/wallet/create-account.ts b/packages/core/src/actions/wallet/create-account.ts index 60ce512e..c9b6db57 100644 --- a/packages/core/src/actions/wallet/create-account.ts +++ b/packages/core/src/actions/wallet/create-account.ts @@ -1,13 +1,13 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { AccountFactoryClient } from '../../codegen/abstract' +import { WithCosmWasmSignOptions } from '../../types/parameters' import { WithOptional } from '../../types/utils' -import { WithArgsAndCosmWasmSignOptions } from '../../types/with-args' import { accountIdToParameter } from '../../utils' import { parseCreateAccountExecuteResult } from '../../utils/account-factory/parse-create-account-execute-result' import { chainIdToName } from '../../utils/chain-registry' import { getAccountFactoryClientFromApi } from './get-account-factory-client-from-api' -export type CreateAccountParameters = WithArgsAndCosmWasmSignOptions< +export type CreateAccountParameters = WithCosmWasmSignOptions< { signingCosmWasmClient: SigningCosmWasmClient apiUrl: string @@ -18,19 +18,17 @@ export type CreateAccountParameters = WithArgsAndCosmWasmSignOptions< > > export async function createAccount({ - args: { - signingCosmWasmClient, - apiUrl, - sender, - installModules = [], - baseAsset, - description, - name, - namespace, - governance, - link, - accountId, - }, + signingCosmWasmClient, + apiUrl, + sender, + installModules = [], + baseAsset, + description, + name, + namespace, + governance, + link, + accountId, fee, memo, funds, @@ -38,11 +36,9 @@ export async function createAccount({ const chainId = await signingCosmWasmClient.getChainId() const chainName = chainIdToName(chainId) const accountFactoryClient = await getAccountFactoryClientFromApi({ - args: { - signingCosmWasmClient, - apiUrl, - sender, - }, + signingCosmWasmClient, + apiUrl, + sender, }) // @TODO: parameter validation diff --git a/packages/core/src/actions/wallet/get-account-factory-client-from-api.ts b/packages/core/src/actions/wallet/get-account-factory-client-from-api.ts index f3bd84fd..c73edce3 100644 --- a/packages/core/src/actions/wallet/get-account-factory-client-from-api.ts +++ b/packages/core/src/actions/wallet/get-account-factory-client-from-api.ts @@ -1,26 +1,30 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { WithArgs } from '../../types/with-args' import { chainIdToName } from '../../utils/chain-registry' import { getAccountFactoryAddressFromApi } from '../get-account-factory-address-from-api' import { getAccountFactoryClient } from './get-account-factory-client' -export type GetAccountFactoryClientFromApiParameters = WithArgs<{ +export type GetAccountFactoryClientFromApiParameters = { signingCosmWasmClient: SigningCosmWasmClient apiUrl: string sender: string -}> +} export async function getAccountFactoryClientFromApi({ - args: { signingCosmWasmClient, apiUrl, sender }, + signingCosmWasmClient, + apiUrl, + sender, }: GetAccountFactoryClientFromApiParameters) { const chainId = await signingCosmWasmClient.getChainId() const chainName = chainIdToName(chainId) const factoryAddress = await getAccountFactoryAddressFromApi({ - args: { apiUrl, chainName }, + apiUrl, + chainName, }) return getAccountFactoryClient({ - args: { signingCosmWasmClient, sender, factoryAddress }, + signingCosmWasmClient, + sender, + factoryAddress, }) } diff --git a/packages/core/src/actions/wallet/get-account-factory-client-from-version-control.ts b/packages/core/src/actions/wallet/get-account-factory-client-from-version-control.ts index ee2d2cd9..e2b696c4 100644 --- a/packages/core/src/actions/wallet/get-account-factory-client-from-version-control.ts +++ b/packages/core/src/actions/wallet/get-account-factory-client-from-version-control.ts @@ -1,28 +1,30 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { WithArgs } from '../../types/with-args' import { getAccountFactoryAddressFromVersionControl } from '../public/get-account-factory-address-from-version-control' import { getAccountFactoryClient } from './get-account-factory-client' -export type GetAccountFactoryClientFromVersionControlParameters = WithArgs<{ +export type GetAccountFactoryClientFromVersionControlParameters = { signingCosmWasmClient: SigningCosmWasmClient sender: string versionControlAddress: string version?: string -}> +} export async function getAccountFactoryClientFromVersionControl({ - args: { signingCosmWasmClient, sender, versionControlAddress, version }, + signingCosmWasmClient, + sender, + versionControlAddress, + version, }: GetAccountFactoryClientFromVersionControlParameters) { const factoryAddress = await getAccountFactoryAddressFromVersionControl({ - args: { - cosmWasmClient: signingCosmWasmClient, - versionControlAddress, - version, - }, + cosmWasmClient: signingCosmWasmClient, + versionControlAddress, + version, }) return getAccountFactoryClient({ - args: { signingCosmWasmClient, sender, factoryAddress }, + signingCosmWasmClient, + sender, + factoryAddress, }) } diff --git a/packages/core/src/actions/wallet/get-account-factory-client.ts b/packages/core/src/actions/wallet/get-account-factory-client.ts index 3f669a43..6cbd6a40 100644 --- a/packages/core/src/actions/wallet/get-account-factory-client.ts +++ b/packages/core/src/actions/wallet/get-account-factory-client.ts @@ -1,16 +1,17 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { AccountFactoryClient } from '../../codegen/abstract' -import { WithArgs } from '../../types/with-args' -export type GetAccountFactoryClientParameters = WithArgs<{ +export type GetAccountFactoryClientParameters = { signingCosmWasmClient: SigningCosmWasmClient sender: string factoryAddress: string -}> +} export async function getAccountFactoryClient({ - args: { signingCosmWasmClient, sender, factoryAddress }, + signingCosmWasmClient, + sender, + factoryAddress, }: GetAccountFactoryClientParameters) { return new AccountFactoryClient(signingCosmWasmClient, sender, factoryAddress) } diff --git a/packages/core/src/actions/wallet/get-ans-host-client-from-api.ts b/packages/core/src/actions/wallet/get-ans-host-client-from-api.ts index 7eb77231..968bd95d 100644 --- a/packages/core/src/actions/wallet/get-ans-host-client-from-api.ts +++ b/packages/core/src/actions/wallet/get-ans-host-client-from-api.ts @@ -1,26 +1,30 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { WithArgs } from '../../types/with-args' import { chainIdToName } from '../../utils/chain-registry' import { getAnsHostAddressFromApi } from '../get-ans-host-address-from-api' import { getAnsHostClient } from './get-ans-host-client' -export type GetAnsHostClientFromApiParameters = WithArgs<{ +export type GetAnsHostClientFromApiParameters = { signingCosmWasmClient: SigningCosmWasmClient apiUrl: string sender: string -}> +} export async function getAnsHostClientFromApi({ - args: { signingCosmWasmClient, apiUrl, sender }, + signingCosmWasmClient, + apiUrl, + sender, }: GetAnsHostClientFromApiParameters) { const chainId = await signingCosmWasmClient.getChainId() const chainName = chainIdToName(chainId) const ansHostAddress = await getAnsHostAddressFromApi({ - args: { apiUrl, chainName }, + apiUrl, + chainName, }) return getAnsHostClient({ - args: { signingCosmWasmClient, sender, ansHostAddress }, + signingCosmWasmClient, + sender, + ansHostAddress, }) } diff --git a/packages/core/src/actions/wallet/get-ans-host-client-from-version-control.ts b/packages/core/src/actions/wallet/get-ans-host-client-from-version-control.ts index 91bb5570..8836a99c 100644 --- a/packages/core/src/actions/wallet/get-ans-host-client-from-version-control.ts +++ b/packages/core/src/actions/wallet/get-ans-host-client-from-version-control.ts @@ -1,28 +1,30 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { WithArgs } from '../../types/with-args' import { getAnsHostAddressFromVersionControl } from '../public/get-ans-host-address-from-version-control' import { getAnsHostClient } from './get-ans-host-client' -export type GetAnsHostClientFromVersionControlParameters = WithArgs<{ +export type GetAnsHostClientFromVersionControlParameters = { signingCosmWasmClient: SigningCosmWasmClient sender: string versionControlAddress: string version?: string -}> +} export async function getAnsHostClientFromVersionControl({ - args: { signingCosmWasmClient, sender, versionControlAddress, version }, + signingCosmWasmClient, + sender, + versionControlAddress, + version, }: GetAnsHostClientFromVersionControlParameters) { const ansHostAddress = await getAnsHostAddressFromVersionControl({ - args: { - cosmWasmClient: signingCosmWasmClient, - versionControlAddress, - version, - }, + cosmWasmClient: signingCosmWasmClient, + versionControlAddress, + version, }) return getAnsHostClient({ - args: { signingCosmWasmClient, sender, ansHostAddress }, + signingCosmWasmClient, + sender, + ansHostAddress, }) } diff --git a/packages/core/src/actions/wallet/get-ans-host-client.ts b/packages/core/src/actions/wallet/get-ans-host-client.ts index 8098bebe..dd4fbec5 100644 --- a/packages/core/src/actions/wallet/get-ans-host-client.ts +++ b/packages/core/src/actions/wallet/get-ans-host-client.ts @@ -1,16 +1,17 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { AnsHostClient } from '../../codegen/abstract' -import { WithArgs } from '../../types/with-args' -export type GetAnsHostClientParameters = WithArgs<{ +export type GetAnsHostClientParameters = { signingCosmWasmClient: SigningCosmWasmClient sender: string ansHostAddress: string -}> +} export async function getAnsHostClient({ - args: { signingCosmWasmClient, sender, ansHostAddress }, + signingCosmWasmClient, + sender, + ansHostAddress, }: GetAnsHostClientParameters) { return new AnsHostClient(signingCosmWasmClient, sender, ansHostAddress) } diff --git a/packages/core/src/actions/wallet/get-manager-client.ts b/packages/core/src/actions/wallet/get-manager-client.ts index faa51adb..1376a931 100644 --- a/packages/core/src/actions/wallet/get-manager-client.ts +++ b/packages/core/src/actions/wallet/get-manager-client.ts @@ -1,16 +1,17 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { ManagerClient } from '../../codegen/abstract' -import { WithArgs } from '../../types/with-args' -export type GetManagerClientParameters = WithArgs<{ +export type GetManagerClientParameters = { signingCosmWasmClient: SigningCosmWasmClient sender: string managerAddress: string -}> +} export async function getManagerClient({ - args: { signingCosmWasmClient, sender, managerAddress }, + signingCosmWasmClient, + sender, + managerAddress, }: GetManagerClientParameters) { return new ManagerClient(signingCosmWasmClient, sender, managerAddress) } diff --git a/packages/core/src/actions/wallet/get-proxy-client.ts b/packages/core/src/actions/wallet/get-proxy-client.ts index 9dafd028..e4873f8d 100644 --- a/packages/core/src/actions/wallet/get-proxy-client.ts +++ b/packages/core/src/actions/wallet/get-proxy-client.ts @@ -1,16 +1,17 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { ProxyClient } from '../../codegen/abstract' -import { WithArgs } from '../../types/with-args' -export type GetProxyClientParameters = WithArgs<{ +export type GetProxyClientParameters = { signingCosmWasmClient: SigningCosmWasmClient sender: string proxyAddress: string -}> +} export async function getProxyClient({ - args: { signingCosmWasmClient, sender, proxyAddress }, + signingCosmWasmClient, + sender, + proxyAddress, }: GetProxyClientParameters) { return new ProxyClient(signingCosmWasmClient, sender, proxyAddress) } diff --git a/packages/core/src/actions/wallet/get-sender-address.ts b/packages/core/src/actions/wallet/get-sender-address.ts index ca2ceb1f..21c8a861 100644 --- a/packages/core/src/actions/wallet/get-sender-address.ts +++ b/packages/core/src/actions/wallet/get-sender-address.ts @@ -1,11 +1,7 @@ -import { WithArgs } from '../../types/with-args' - -export type GetSenderAddressParameters = WithArgs<{ +export type GetSenderAddressParameters = { sender: string -}> +} -export async function getSenderAddress({ - args: { sender }, -}: GetSenderAddressParameters) { +export async function getSenderAddress({ sender }: GetSenderAddressParameters) { return sender } diff --git a/packages/core/src/actions/wallet/get-signing-cosm-wasm-client.ts b/packages/core/src/actions/wallet/get-signing-cosm-wasm-client.ts index 7caa8c98..3125332c 100644 --- a/packages/core/src/actions/wallet/get-signing-cosm-wasm-client.ts +++ b/packages/core/src/actions/wallet/get-signing-cosm-wasm-client.ts @@ -1,13 +1,11 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { WithArgs } from '../../types/with-args' - -export type GetSigningCosmWasmClientParameters = WithArgs<{ +export type GetSigningCosmWasmClientParameters = { signingCosmWasmClient: SigningCosmWasmClient -}> +} export async function getSigningCosmWasmClient({ - args: { signingCosmWasmClient }, + signingCosmWasmClient, }: GetSigningCosmWasmClientParameters) { return signingCosmWasmClient } diff --git a/packages/core/src/actions/wallet/get-version-control-client-from-api.ts b/packages/core/src/actions/wallet/get-version-control-client-from-api.ts index 32988425..6ea0a641 100644 --- a/packages/core/src/actions/wallet/get-version-control-client-from-api.ts +++ b/packages/core/src/actions/wallet/get-version-control-client-from-api.ts @@ -1,29 +1,30 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { WithArgs } from '../../types/with-args' import { chainIdToName } from '../../utils/chain-registry' import { getVersionControlAddressFromApi } from '../get-version-control-address-from-api' import { getVersionControlClient } from './get-version-control-client' -export type GetVersionControlClientFromApiParameters = WithArgs<{ +export type GetVersionControlClientFromApiParameters = { signingCosmWasmClient: SigningCosmWasmClient apiUrl: string sender: string -}> +} export async function getVersionControlClientFromApi({ - args: { signingCosmWasmClient, apiUrl, sender }, + signingCosmWasmClient, + apiUrl, + sender, }: GetVersionControlClientFromApiParameters) { const chainId = await signingCosmWasmClient.getChainId() const chainName = chainIdToName(chainId) const versionControlAddress = await getVersionControlAddressFromApi({ - args: { - apiUrl, - chainName, - }, + apiUrl, + chainName, }) return getVersionControlClient({ - args: { signingCosmWasmClient, sender, versionControlAddress }, + signingCosmWasmClient, + sender, + versionControlAddress, }) } diff --git a/packages/core/src/actions/wallet/get-version-control-client.ts b/packages/core/src/actions/wallet/get-version-control-client.ts index e76fb7d1..a28eb2e3 100644 --- a/packages/core/src/actions/wallet/get-version-control-client.ts +++ b/packages/core/src/actions/wallet/get-version-control-client.ts @@ -1,16 +1,17 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { VersionControlClient } from '../../codegen/abstract' -import { WithArgs } from '../../types/with-args' -export type GetVersionControlClientParameters = WithArgs<{ +export type GetVersionControlClientParameters = { signingCosmWasmClient: SigningCosmWasmClient sender: string versionControlAddress: string -}> +} export async function getVersionControlClient({ - args: { signingCosmWasmClient, sender, versionControlAddress }, + signingCosmWasmClient, + sender, + versionControlAddress, }: GetVersionControlClientParameters) { return new VersionControlClient( signingCosmWasmClient, diff --git a/packages/core/src/clients/create-account-public-client.ts b/packages/core/src/clients/create-account-public-client.ts index ca1ad85d..3ad256c0 100644 --- a/packages/core/src/clients/create-account-public-client.ts +++ b/packages/core/src/clients/create-account-public-client.ts @@ -1,5 +1,5 @@ import { VersionControlTypes } from '../codegen/abstract/index' -import type { Prettify } from '../types/utils' +import type { Evaluate } from '../types/utils' import { ABSTRACT_API_URL } from '../utils' import { type Client } from './create-client' import { PublicClientConfig, createPublicClient } from './create-public-client' @@ -12,7 +12,7 @@ export type AccountPublicClientConfig = PublicClientConfig & { accountId: VersionControlTypes.AccountId } -export type AccountPublicClient = Prettify> +export type AccountPublicClient = Evaluate> export function createAccountPublicClient( parameters: AccountPublicClientConfig, diff --git a/packages/core/src/clients/create-account-wallet-client.ts b/packages/core/src/clients/create-account-wallet-client.ts index b9c0b9a8..df9419a6 100644 --- a/packages/core/src/clients/create-account-wallet-client.ts +++ b/packages/core/src/clients/create-account-wallet-client.ts @@ -1,5 +1,5 @@ import { VersionControlTypes } from '../codegen/abstract/index' -import type { Prettify } from '../types/utils' +import type { Evaluate } from '../types/utils' import { ABSTRACT_API_URL } from '../utils' import { type Client } from './create-client' import { WalletClientConfig, createWalletClient } from './create-wallet-client' @@ -12,7 +12,7 @@ export type AccountWalletClientConfig = WalletClientConfig & { accountId: VersionControlTypes.AccountId } -export type AccountWalletClient = Prettify> +export type AccountWalletClient = Evaluate> export function createAccountWalletClient( parameters: AccountWalletClientConfig, diff --git a/packages/core/src/clients/create-api-client.ts b/packages/core/src/clients/create-api-client.ts index ebadcfdd..55a6686a 100644 --- a/packages/core/src/clients/create-api-client.ts +++ b/packages/core/src/clients/create-api-client.ts @@ -1,4 +1,4 @@ -import type { Prettify } from '../types/utils' +import type { Evaluate } from '../types/utils' import { ABSTRACT_API_URL } from '../utils/constants' import { type Client, type ClientConfig, createClient } from './create-client' import { type ApiActions, apiActions } from './decorators/api' @@ -7,7 +7,7 @@ export type ApiClientConfig = ClientConfig & { apiUrl?: string } -export type ApiClient = Prettify> +export type ApiClient = Evaluate> export function createApiClient(parameters: ApiClientConfig): ApiClient { const { diff --git a/packages/core/src/clients/create-client.ts b/packages/core/src/clients/create-client.ts index a2bd2dd6..11749ee2 100644 --- a/packages/core/src/clients/create-client.ts +++ b/packages/core/src/clients/create-client.ts @@ -1,5 +1,4 @@ -import { Prettify } from '../types/utils' -import { ABSTRACT_API_URL } from '../utils/constants' +import { Evaluate } from '../types/utils' export type ClientConfig = { /** A key for the client. */ @@ -22,11 +21,11 @@ export type Client< extend: ( fn: (client: Client) => client, ) => Client< - Prettify & (extended extends Extended ? extended : unknown) + Evaluate & (extended extends Extended ? extended : unknown) > } -export type Extended = Prettify< +export type Extended = Evaluate< // disallow redefining base properties { [_ in keyof TClient]?: undefined } & { [key: string]: unknown diff --git a/packages/core/src/clients/create-public-client.ts b/packages/core/src/clients/create-public-client.ts index 1969433e..9e372302 100644 --- a/packages/core/src/clients/create-public-client.ts +++ b/packages/core/src/clients/create-public-client.ts @@ -1,5 +1,5 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import type { Prettify } from '../types/utils' +import type { Evaluate } from '../types/utils' import { ABSTRACT_API_URL } from '../utils' import { ApiClientConfig, createApiClient } from './create-api-client' import { type Client } from './create-client' @@ -9,7 +9,7 @@ export type PublicClientConfig = ApiClientConfig & { cosmWasmClient: CosmWasmClient } -export type PublicClient = Prettify> +export type PublicClient = Evaluate> export function createPublicClient( parameters: PublicClientConfig, diff --git a/packages/core/src/clients/create-wallet-client.ts b/packages/core/src/clients/create-wallet-client.ts index 5fece9a5..bef71ad6 100644 --- a/packages/core/src/clients/create-wallet-client.ts +++ b/packages/core/src/clients/create-wallet-client.ts @@ -1,5 +1,5 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import type { Prettify } from '../types/utils' +import type { Evaluate } from '../types/utils' import { ABSTRACT_API_URL } from '../utils' import { type Client } from './create-client' import { PublicClientConfig, createPublicClient } from './create-public-client' @@ -10,7 +10,7 @@ export type WalletClientConfig = Omit & { sender: string } -export type WalletClient = Prettify> +export type WalletClient = Evaluate> export function createWalletClient( parameters: WalletClientConfig, diff --git a/packages/core/src/clients/decorators/account-public.ts b/packages/core/src/clients/decorators/account-public.ts index 1ad1adcc..1f5e7c59 100644 --- a/packages/core/src/clients/decorators/account-public.ts +++ b/packages/core/src/clients/decorators/account-public.ts @@ -1,5 +1,4 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { getCosmWasmClient } from 'src/actions/account/public/get-cosm-wasm-client' import { getAccountBaseAddressesFromApi } from '../../actions/account/public/get-account-base-addresses-from-api' import { getBaseToken } from '../../actions/account/public/get-base-token' import { getManagerQueryClientFromApi } from '../../actions/account/public/get-manager-query-client-from-api' @@ -15,72 +14,83 @@ import { getSubAccountIds } from '../../actions/account/public/get-sub-account-i import { getSubAccountSequences } from '../../actions/account/public/get-sub-account-sequences' import { getTotalValue } from '../../actions/account/public/get-total-value' import { VersionControlTypes } from '../../codegen/abstract/index' -import { CutArgs } from '../../types/with-args' +import { ExtractAndOmitParameters } from '../../types/parameters' -type CutCosmWasmClientFromParameter any> = CutArgs< - { - readonly cosmWasmClient: CosmWasmClient - }, - T -> - -type CutSpecificArgsFromParameter any> = CutArgs< - { - readonly accountId: VersionControlTypes.AccountId - readonly cosmWasmClient: CosmWasmClient - readonly apiUrl: string - }, - T -> +type ExtractAndOmitDecoratedParametersFromParameters< + fn extends (parameters: any) => any, +> = ExtractAndOmitParameters export type AccountPublicActions = { getAccountBaseAddresses( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getAccountBaseAddressesFromApi + >, ): ReturnType getBaseToken( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getBaseToken + >, ): ReturnType getManagerQueryClientFromApi( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getManagerQueryClientFromApi + >, ): ReturnType getModuleAddress( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getModuleAddress + >, ): ReturnType getModules( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getModules + >, ): ReturnType getModuleInstantiate2AddressFromApi( - args: CutSpecificArgsFromParameter< + parameters: ExtractAndOmitDecoratedParametersFromParameters< typeof getModuleInstantiate2AddressFromApi >, ): ReturnType getNamespace( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getNamespace + >, ): ReturnType getOwner( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getOwner + >, ): ReturnType getProxyQueryClientFromApi( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getProxyQueryClientFromApi + >, ): ReturnType getSubAccountIds( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getSubAccountIds + >, ): ReturnType getSubAccountSequences( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getSubAccountSequences + >, ): ReturnType getRemoteAccountProxies( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getRemoteAccountProxies + >, ): ReturnType getRemoteAccountIds( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getRemoteAccountIds + >, ): ReturnType getTotalValue( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getTotalValue + >, ): ReturnType - getCosmWasmClient( - args: CutCosmWasmClientFromParameter, - ): ReturnType } export function accountPublicActions( @@ -89,81 +99,103 @@ export function accountPublicActions( apiUrl: string, ): AccountPublicActions { return { - getAccountBaseAddresses: ({ args, ...rest }) => + getAccountBaseAddresses: (parameters) => getAccountBaseAddressesFromApi({ - args: { ...args, accountId, cosmWasmClient, apiUrl }, - ...rest, + accountId, + cosmWasmClient, + apiUrl, + ...parameters, }), - getBaseToken: ({ args, ...rest }) => + getBaseToken: (parameters) => getBaseToken({ - args: { ...args, accountId, cosmWasmClient, apiUrl }, - ...rest, + ...parameters, + accountId, + cosmWasmClient, + apiUrl, }), - getManagerQueryClientFromApi: ({ args, ...rest }) => + getManagerQueryClientFromApi: (parameters) => getManagerQueryClientFromApi({ - args: { ...args, accountId, cosmWasmClient, apiUrl }, - ...rest, + ...parameters, + accountId, + cosmWasmClient, + apiUrl, }), - getModuleAddress: ({ args, ...rest }) => + getModuleAddress: (parameters) => getModuleAddress({ - args: { ...args, accountId, cosmWasmClient, apiUrl }, - ...rest, + ...parameters, + accountId, + cosmWasmClient, + apiUrl, }), - getModules: ({ args, ...rest }) => + getModules: (parameters) => getModules({ - args: { ...args, accountId, cosmWasmClient, apiUrl }, - ...rest, + ...parameters, + accountId, + cosmWasmClient, + apiUrl, }), - getModuleInstantiate2AddressFromApi: ({ args, ...rest }) => + getModuleInstantiate2AddressFromApi: (parameters) => getModuleInstantiate2AddressFromApi({ - args: { ...args, accountId, cosmWasmClient, apiUrl }, - ...rest, + ...parameters, + accountId, + cosmWasmClient, + apiUrl, }), - getNamespace: ({ args, ...rest }) => + getNamespace: (parameters) => getNamespace({ - args: { ...args, accountId, cosmWasmClient, apiUrl }, - ...rest, + ...parameters, + accountId, + cosmWasmClient, + apiUrl, }), - getOwner: ({ args, ...rest }) => + getOwner: (parameters) => getOwner({ - args: { ...args, accountId, cosmWasmClient, apiUrl }, - ...rest, + ...parameters, + accountId, + cosmWasmClient, + apiUrl, }), - getProxyQueryClientFromApi: ({ args, ...rest }) => + getProxyQueryClientFromApi: (parameters) => getProxyQueryClientFromApi({ - args: { ...args, accountId, cosmWasmClient, apiUrl }, - ...rest, + ...parameters, + accountId, + cosmWasmClient, + apiUrl, }), - getSubAccountIds: ({ args, ...rest }) => + getSubAccountIds: (parameters) => getSubAccountIds({ - args: { ...args, accountId, cosmWasmClient, apiUrl }, - ...rest, + ...parameters, + accountId, + cosmWasmClient, + apiUrl, }), - getSubAccountSequences: ({ args, ...rest }) => + getSubAccountSequences: (parameters) => getSubAccountSequences({ - args: { ...args, accountId, cosmWasmClient, apiUrl }, - ...rest, + ...parameters, + accountId, + cosmWasmClient, + apiUrl, }), - getRemoteAccountProxies: ({ args, ...rest }) => + getRemoteAccountProxies: (parameters) => getRemoteAccountProxies({ - args: { ...args, accountId, cosmWasmClient, apiUrl }, - ...rest, + ...parameters, + accountId, + cosmWasmClient, + apiUrl, }), - getRemoteAccountIds: ({ args, ...rest }) => + getRemoteAccountIds: (parameters) => getRemoteAccountIds({ - args: { ...args, accountId, cosmWasmClient, apiUrl }, - ...rest, + ...parameters, + accountId, + cosmWasmClient, + apiUrl, }), - getTotalValue: ({ args, ...rest }) => + getTotalValue: (parameters) => getTotalValue({ - args: { ...args, accountId, cosmWasmClient, apiUrl }, - ...rest, - }), - - getCosmWasmClient: ({ args, ...rest }) => - getCosmWasmClient({ - args: { ...args, cosmWasmClient }, - ...rest, + ...parameters, + accountId, + cosmWasmClient, + apiUrl, }), } } diff --git a/packages/core/src/clients/decorators/account-wallet.ts b/packages/core/src/clients/decorators/account-wallet.ts index 502b8ad5..aed8669e 100644 --- a/packages/core/src/clients/decorators/account-wallet.ts +++ b/packages/core/src/clients/decorators/account-wallet.ts @@ -8,42 +8,51 @@ import { getProxyClientFromApi } from '../../actions/account/wallet/get-proxy-cl import { revokeNamespace } from '../../actions/account/wallet/remove-namespace' import { withdraw } from '../../actions/account/wallet/withdraw' import { VersionControlTypes } from '../../codegen/abstract/index' -import { CutArgs } from '../../types/with-args' +import { ExtractAndOmitParameters } from '../../types/parameters' -type CutSpecificArgsFromParameter any> = CutArgs< - { - readonly accountId: VersionControlTypes.AccountId - readonly signingCosmWasmClient: SigningCosmWasmClient - readonly apiUrl: string - readonly sender: string - }, - T +type ExtractAndOmitDecoratedParametersFromParameters< + fn extends (payload: any) => any, +> = ExtractAndOmitParameters< + fn, + 'accountId' | 'signingCosmWasmClient' | 'apiUrl' | 'sender' > export type AccountWalletActions = { claimNamespace( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof claimNamespace + >, ): ReturnType createSubAccount( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof createSubAccount + >, ): ReturnType deposit( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters, ): ReturnType execute( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters, ): ReturnType getManagerClientFromApi( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getManagerClientFromApi + >, ): ReturnType getProxyClientFromApi( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getProxyClientFromApi + >, ): ReturnType revokeNamespace( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof revokeNamespace + >, ): ReturnType withdraw( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof withdraw + >, ): ReturnType } @@ -54,45 +63,69 @@ export function accountWalletActions( apiUrl: string, ): AccountWalletActions { return { - claimNamespace: ({ args, ...rest }) => + claimNamespace: (parameters) => claimNamespace({ - args: { ...args, accountId, signingCosmWasmClient, apiUrl, sender }, - ...rest, + ...parameters, + accountId, + signingCosmWasmClient, + apiUrl, + sender, }), - createSubAccount: ({ args, ...rest }) => + createSubAccount: (parameters) => createSubAccount({ - args: { ...args, accountId, signingCosmWasmClient, apiUrl, sender }, - ...rest, + ...parameters, + accountId, + signingCosmWasmClient, + apiUrl, + sender, }), - deposit: ({ args, ...rest }) => + deposit: (parameters) => deposit({ - args: { ...args, accountId, signingCosmWasmClient, apiUrl, sender }, - ...rest, + ...parameters, + accountId, + signingCosmWasmClient, + apiUrl, + sender, }), - execute: ({ args, ...rest }) => + execute: (parameters) => execute({ - args: { ...args, accountId, signingCosmWasmClient, apiUrl, sender }, - ...rest, + ...parameters, + accountId, + signingCosmWasmClient, + apiUrl, + sender, }), - withdraw: ({ args, ...rest }) => + withdraw: (parameters) => withdraw({ - args: { ...args, accountId, signingCosmWasmClient, apiUrl, sender }, - ...rest, + ...parameters, + accountId, + signingCosmWasmClient, + apiUrl, + sender, }), - getManagerClientFromApi: ({ args, ...rest }) => + getManagerClientFromApi: (parameters) => getManagerClientFromApi({ - args: { ...args, accountId, signingCosmWasmClient, apiUrl, sender }, - ...rest, + ...parameters, + accountId, + signingCosmWasmClient, + apiUrl, + sender, }), - getProxyClientFromApi: ({ args, ...rest }) => + getProxyClientFromApi: (parameters) => getProxyClientFromApi({ - args: { ...args, accountId, signingCosmWasmClient, apiUrl, sender }, - ...rest, + ...parameters, + accountId, + signingCosmWasmClient, + apiUrl, + sender, }), - revokeNamespace: ({ args, ...rest }) => + revokeNamespace: (parameters) => revokeNamespace({ - args: { ...args, accountId, signingCosmWasmClient, apiUrl, sender }, - ...rest, + ...parameters, + accountId, + signingCosmWasmClient, + apiUrl, + sender, }), } } diff --git a/packages/core/src/clients/decorators/api.ts b/packages/core/src/clients/decorators/api.ts index 02baefc3..fa955d1f 100644 --- a/packages/core/src/clients/decorators/api.ts +++ b/packages/core/src/clients/decorators/api.ts @@ -5,75 +5,86 @@ import { getAnsHostAddressFromApi } from '../../actions/get-ans-host-address-fro import { getAnsTokenFromApi } from '../../actions/get-ans-token-from-api' import { getAnsTokensFromApi } from '../../actions/get-ans-tokens-from-api' import { getVersionControlAddressFromApi } from '../../actions/get-version-control-address-from-api' -import { CutArgs } from '../../types/with-args' +import { ExtractAndOmitParameters } from '../../types/parameters' -type CutSpecificArgsFromParameter any> = CutArgs< - { - readonly apiUrl: string - }, - T -> +type ExtractAndOmitDecoratedParametersFromParameters< + fn extends (payload: any) => any, +> = ExtractAndOmitParameters export type ApiActions = { getAccountFactoryAddressFromApi( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getAccountFactoryAddressFromApi + >, ): ReturnType getAnsHostAddressFromApi( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getAnsHostAddressFromApi + >, ): ReturnType getAccountsByOwnerFromApi( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getAccountsByOwnerFromApi + >, ): ReturnType getAnsTokenFromApi( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getAnsTokenFromApi + >, ): ReturnType getAnsTokensFromApi( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getAnsTokensFromApi + >, ): ReturnType getVersionControlAddressFromApi( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getVersionControlAddressFromApi + >, ): ReturnType getAccountBalancesFromApi( - args: CutSpecificArgsFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getAccountBalancesFromApi + >, ): ReturnType } export function apiActions(apiUrl: string): ApiActions { return { - getAccountBalancesFromApi: ({ args, ...rest }) => + getAccountBalancesFromApi: (parameters) => getAccountBalancesFromApi({ - args: { ...args, apiUrl }, - ...rest, + ...parameters, + apiUrl, }), - getAccountFactoryAddressFromApi: ({ args, ...rest }) => + getAccountFactoryAddressFromApi: (parameters) => getAccountFactoryAddressFromApi({ - args: { ...args, apiUrl }, - ...rest, + ...parameters, + apiUrl, }), - getAnsHostAddressFromApi: ({ args, ...rest }) => + getAnsHostAddressFromApi: (parameters) => getAnsHostAddressFromApi({ - args: { ...args, apiUrl }, - ...rest, + ...parameters, + apiUrl, }), - getAccountsByOwnerFromApi: ({ args, ...rest }) => + getAccountsByOwnerFromApi: (parameters) => getAccountsByOwnerFromApi({ - args: { ...args, apiUrl }, - ...rest, + ...parameters, + apiUrl, }), - getAnsTokenFromApi: ({ args, ...rest }) => + getAnsTokenFromApi: (parameters) => getAnsTokenFromApi({ - args: { ...args, apiUrl }, - ...rest, + ...parameters, + apiUrl, }), - getAnsTokensFromApi: ({ args, ...rest }) => + getAnsTokensFromApi: (parameters) => getAnsTokensFromApi({ - args: { ...args, apiUrl }, - ...rest, + ...parameters, + apiUrl, }), - getVersionControlAddressFromApi: ({ args, ...rest }) => + getVersionControlAddressFromApi: (parameters) => getVersionControlAddressFromApi({ - args: { ...args, apiUrl }, - ...rest, + ...parameters, + apiUrl, }), } } diff --git a/packages/core/src/clients/decorators/public.ts b/packages/core/src/clients/decorators/public.ts index 9671f830..b7246a9b 100644 --- a/packages/core/src/clients/decorators/public.ts +++ b/packages/core/src/clients/decorators/public.ts @@ -17,95 +17,97 @@ import { getProxyQueryClient } from '../../actions/public/get-proxy-query-client import { getVersionControlModuleData } from '../../actions/public/get-version-control-module-data' import { getVersionControlQueryClient } from '../../actions/public/get-version-control-query-client' import { getVersionControlQueryClientFromApi } from '../../actions/public/get-version-control-query-client-from-api' -import { CutArgs } from '../../types/with-args' +import { ExtractAndOmitParameters } from '../../types/parameters' -type CutCosmWasmClientFromParameter any> = CutArgs< - { - readonly cosmWasmClient: CosmWasmClient - }, - T -> - -type CutCosmWasmClientAndApiUrlFromParameter any> = - CutArgs< - { - readonly cosmWasmClient: CosmWasmClient - readonly apiUrl: string - }, - T - > +type ExtractAndOmitDecoratedParametersFromParameters< + fn extends (payload: any) => any, +> = ExtractAndOmitParameters export type PublicActions = { getAbstractModuleVersion( - args: CutCosmWasmClientAndApiUrlFromParameter< + parameters: ExtractAndOmitDecoratedParametersFromParameters< typeof getAbstractModuleVersion >, ): ReturnType getAbstractModuleAddressFromVersionControl( - args: CutCosmWasmClientFromParameter< + parameters: ExtractAndOmitDecoratedParametersFromParameters< typeof getAbstractModuleAddressFromVersionControl >, ): ReturnType getAccountFactoryAddressFromVersionControl( - args: CutCosmWasmClientFromParameter< + parameters: ExtractAndOmitDecoratedParametersFromParameters< typeof getAccountFactoryAddressFromVersionControl >, ): ReturnType getAccountFactoryVersion( - args: CutCosmWasmClientAndApiUrlFromParameter< + parameters: ExtractAndOmitDecoratedParametersFromParameters< typeof getAccountFactoryVersion >, ): ReturnType getAccountFactoryQueryClientFromVersionControl( - args: CutCosmWasmClientFromParameter< + parameters: ExtractAndOmitDecoratedParametersFromParameters< typeof getAccountFactoryQueryClientFromVersionControl >, ): ReturnType getAccountFactoryQueryClientFromApi( - args: CutCosmWasmClientAndApiUrlFromParameter< + parameters: ExtractAndOmitDecoratedParametersFromParameters< typeof getAccountFactoryQueryClientFromApi >, ): ReturnType getAccountFactoryQueryClient( - args: CutCosmWasmClientFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getAccountFactoryQueryClient + >, ): ReturnType getAnsHostVersion( - args: CutCosmWasmClientAndApiUrlFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getAnsHostVersion + >, ): ReturnType getAnsHostAddressFromVersionControl( - args: CutCosmWasmClientFromParameter< + parameters: ExtractAndOmitDecoratedParametersFromParameters< typeof getAnsHostAddressFromVersionControl >, ): ReturnType getAnsHostQueryClientFromVersionControl( - args: CutCosmWasmClientFromParameter< + parameters: ExtractAndOmitDecoratedParametersFromParameters< typeof getAnsHostQueryClientFromVersionControl >, ): ReturnType getAnsHostQueryClientFromApi( - args: CutCosmWasmClientAndApiUrlFromParameter< + parameters: ExtractAndOmitDecoratedParametersFromParameters< typeof getAnsHostQueryClientFromApi >, ): ReturnType getAnsHostQueryClient( - args: CutCosmWasmClientFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getAnsHostQueryClient + >, ): ReturnType getManagerQueryClient( - args: CutCosmWasmClientFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getManagerQueryClient + >, ): ReturnType getProxyQueryClient( - args: CutCosmWasmClientFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getProxyQueryClient + >, ): ReturnType getVersionControlModuleData( - args: CutCosmWasmClientFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getVersionControlModuleData + >, ): ReturnType getVersionControlQueryClientFromApi( - args: CutCosmWasmClientAndApiUrlFromParameter< + parameters: ExtractAndOmitDecoratedParametersFromParameters< typeof getVersionControlQueryClientFromApi >, ): ReturnType getVersionControlQueryClient( - args: CutCosmWasmClientFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getVersionControlQueryClient + >, ): ReturnType getCosmWasmClient(): ReturnType } @@ -115,97 +117,103 @@ export function publicActions( apiUrl: string, ): PublicActions { return { - getAbstractModuleAddressFromVersionControl: ({ args, ...rest }) => + getAbstractModuleAddressFromVersionControl: (parameters) => getAbstractModuleAddressFromVersionControl({ - args: { ...args, cosmWasmClient }, - ...rest, + ...parameters, + cosmWasmClient, }), - getAbstractModuleVersion: ({ args, ...rest }) => + getAbstractModuleVersion: (parameters) => getAbstractModuleVersion({ - args: { ...args, cosmWasmClient, apiUrl }, - ...rest, + ...parameters, + cosmWasmClient, + apiUrl, }), - getAccountFactoryVersion: ({ args, ...rest }) => + getAccountFactoryVersion: (parameters) => getAccountFactoryVersion({ - args: { ...args, cosmWasmClient, apiUrl }, - ...rest, + ...parameters, + cosmWasmClient, + apiUrl, }), - getAccountFactoryAddressFromVersionControl: ({ args, ...rest }) => + getAccountFactoryAddressFromVersionControl: (parameters) => getAccountFactoryAddressFromVersionControl({ - args: { ...args, cosmWasmClient }, - ...rest, + ...parameters, + cosmWasmClient, }), - getAccountFactoryQueryClientFromVersionControl: ({ args, ...rest }) => + getAccountFactoryQueryClientFromVersionControl: (parameters) => getAccountFactoryQueryClientFromVersionControl({ - args: { ...args, cosmWasmClient }, - ...rest, + ...parameters, + cosmWasmClient, }), - getAccountFactoryQueryClientFromApi: ({ args, ...rest }) => + getAccountFactoryQueryClientFromApi: (parameters) => getAccountFactoryQueryClientFromApi({ - args: { ...args, cosmWasmClient, apiUrl }, - ...rest, + ...parameters, + cosmWasmClient, + apiUrl, }), - getAccountFactoryQueryClient: ({ args, ...rest }) => + getAccountFactoryQueryClient: (parameters) => getAccountFactoryQueryClient({ - args: { ...args, cosmWasmClient }, - ...rest, + ...parameters, + cosmWasmClient, }), - getAnsHostVersion: ({ args, ...rest }) => + getAnsHostVersion: (parameters) => getAnsHostVersion({ - args: { ...args, apiUrl, cosmWasmClient }, - ...rest, + ...parameters, + apiUrl, + cosmWasmClient, }), - getAnsHostAddressFromVersionControl: ({ args, ...rest }) => + getAnsHostAddressFromVersionControl: (parameters) => getAnsHostAddressFromVersionControl({ - args: { ...args, cosmWasmClient }, - ...rest, + ...parameters, + cosmWasmClient, }), - getAnsHostQueryClientFromVersionControl: ({ args, ...rest }) => + getAnsHostQueryClientFromVersionControl: (parameters) => getAnsHostQueryClientFromVersionControl({ - args: { ...args, cosmWasmClient }, - ...rest, + ...parameters, + cosmWasmClient, }), - getAnsHostQueryClientFromApi: ({ args, ...rest }) => + getAnsHostQueryClientFromApi: (parameters) => getAnsHostQueryClientFromApi({ - args: { ...args, cosmWasmClient, apiUrl }, - ...rest, + ...parameters, + cosmWasmClient, + apiUrl, }), - getAnsHostQueryClient: ({ args, ...rest }) => + getAnsHostQueryClient: (parameters) => getAnsHostQueryClient({ - args: { ...args, cosmWasmClient }, - ...rest, + ...parameters, + cosmWasmClient, }), - getVersionControlModuleData: ({ args, ...rest }) => + getVersionControlModuleData: (parameters) => getVersionControlModuleData({ - args: { ...args, cosmWasmClient }, - ...rest, + ...parameters, + cosmWasmClient, }), - getVersionControlQueryClientFromApi: ({ args, ...rest }) => + getVersionControlQueryClientFromApi: (parameters) => getVersionControlQueryClientFromApi({ - args: { ...args, cosmWasmClient, apiUrl }, - ...rest, + ...parameters, + cosmWasmClient, + apiUrl, }), - getVersionControlQueryClient: ({ args, ...rest }) => + getVersionControlQueryClient: (parameters) => getVersionControlQueryClient({ - args: { ...args, cosmWasmClient }, - ...rest, + ...parameters, + cosmWasmClient, }), - getManagerQueryClient: ({ args, ...rest }) => + getManagerQueryClient: (parameters) => getManagerQueryClient({ - args: { ...args, cosmWasmClient }, - ...rest, + ...parameters, + cosmWasmClient, }), - getProxyQueryClient: ({ args, ...rest }) => + getProxyQueryClient: (parameters) => getProxyQueryClient({ - args: { ...args, cosmWasmClient }, - ...rest, + ...parameters, + cosmWasmClient, }), getCosmWasmClient: () => getCosmWasmClient({ - args: { cosmWasmClient }, + cosmWasmClient, }), } } diff --git a/packages/core/src/clients/decorators/wallet.ts b/packages/core/src/clients/decorators/wallet.ts index d04493bf..68e3afb6 100644 --- a/packages/core/src/clients/decorators/wallet.ts +++ b/packages/core/src/clients/decorators/wallet.ts @@ -14,85 +14,72 @@ import { getProxyClient } from '../../actions/wallet/get-proxy-client' import { getSenderAddress } from '../../actions/wallet/get-sender-address' import { getSigningCosmWasmClient } from '../../actions/wallet/get-signing-cosm-wasm-client' import { getVersionControlClient } from '../../actions/wallet/get-version-control-client' -import { CutArgs } from '../../types/with-args' +import { ExtractAndOmitParameters } from '../../types/parameters' -type CutSigningCosmWasmClientAndSenderFromParameter< - T extends (payload: any) => any, -> = CutArgs< - { - readonly signingCosmWasmClient: SigningCosmWasmClient - readonly sender: string - }, - T -> - -type CutSigningCosmWasmClientAndApiUrlFromParameter< - T extends (payload: any) => any, -> = CutArgs< - { - readonly signingCosmWasmClient: SigningCosmWasmClient - readonly sender: string - readonly apiUrl: string - }, - T -> +type ExtractAndOmitDecoratedParametersFromParameters< + fn extends (payload: any) => any, +> = ExtractAndOmitParameters export type WalletActions = { createAccount( - args: CutSigningCosmWasmClientAndApiUrlFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof createAccount + >, ): ReturnType createAccountMonarchy( - args: CutSigningCosmWasmClientAndApiUrlFromParameter< + parameters: ExtractAndOmitDecoratedParametersFromParameters< typeof createAccountMonarchy >, ): ReturnType getAccountFactoryClient( - args: CutSigningCosmWasmClientAndSenderFromParameter< + parameters: ExtractAndOmitDecoratedParametersFromParameters< typeof getAccountFactoryClient >, ): ReturnType getAccountFactoryClientFromVersionControl( - args: CutSigningCosmWasmClientAndSenderFromParameter< + parameters: ExtractAndOmitDecoratedParametersFromParameters< typeof getAccountFactoryClientFromVersionControl >, ): ReturnType getAccountFactoryClientFromApi( - args: CutSigningCosmWasmClientAndApiUrlFromParameter< + parameters: ExtractAndOmitDecoratedParametersFromParameters< typeof getAccountFactoryClientFromApi >, ): ReturnType getAnsHostClient( - args: CutSigningCosmWasmClientAndSenderFromParameter< + parameters: ExtractAndOmitDecoratedParametersFromParameters< typeof getAnsHostClient >, ): ReturnType getAnsHostClientFromApi( - args: CutSigningCosmWasmClientAndApiUrlFromParameter< + parameters: ExtractAndOmitDecoratedParametersFromParameters< typeof getAnsHostClientFromApi >, ): ReturnType getAnsHostClientFromVersionControl( - args: CutSigningCosmWasmClientAndSenderFromParameter< + parameters: ExtractAndOmitDecoratedParametersFromParameters< typeof getAnsHostClientFromVersionControl >, ): ReturnType getVersionControlClient( - args: CutSigningCosmWasmClientAndSenderFromParameter< + parameters: ExtractAndOmitDecoratedParametersFromParameters< typeof getVersionControlClient >, ): ReturnType getVersionControlClientFromApi( - args: CutSigningCosmWasmClientAndApiUrlFromParameter< + parameters: ExtractAndOmitDecoratedParametersFromParameters< typeof getVersionControlClientFromApi >, ): ReturnType getManagerClient( - args: CutSigningCosmWasmClientAndSenderFromParameter< + parameters: ExtractAndOmitDecoratedParametersFromParameters< typeof getManagerClient >, ): ReturnType getProxyClient( - args: CutSigningCosmWasmClientAndSenderFromParameter, + parameters: ExtractAndOmitDecoratedParametersFromParameters< + typeof getProxyClient + >, ): ReturnType getSigningCosmWasmClient(): ReturnType getSenderAddress(): ReturnType @@ -104,77 +91,94 @@ export function walletActions( apiUrl: string, ): WalletActions { return { - createAccount: ({ args, ...rest }) => + createAccount: (parameters) => createAccount({ - args: { ...args, signingCosmWasmClient, sender, apiUrl }, - ...rest, + ...parameters, + signingCosmWasmClient, + sender, + apiUrl, }), - createAccountMonarchy: ({ args, ...rest }) => + createAccountMonarchy: (parameters) => createAccountMonarchy({ - args: { ...args, signingCosmWasmClient, sender, apiUrl }, - ...rest, + ...parameters, + signingCosmWasmClient, + sender, + apiUrl, }), - getAccountFactoryClient: ({ args, ...rest }) => + getAccountFactoryClient: (parameters) => getAccountFactoryClient({ - args: { ...args, signingCosmWasmClient, sender }, - ...rest, + ...parameters, + signingCosmWasmClient, + sender, }), - getAccountFactoryClientFromVersionControl: ({ args, ...rest }) => + getAccountFactoryClientFromVersionControl: (parameters) => getAccountFactoryClientFromVersionControl({ - args: { ...args, signingCosmWasmClient, sender }, - ...rest, + ...parameters, + signingCosmWasmClient, + sender, }), - getAccountFactoryClientFromApi: ({ args, ...rest }) => + getAccountFactoryClientFromApi: (parameters) => getAccountFactoryClientFromApi({ - args: { ...args, signingCosmWasmClient, sender, apiUrl }, - ...rest, + ...parameters, + signingCosmWasmClient, + sender, + apiUrl, }), - getAnsHostClient: ({ args, ...rest }) => + getAnsHostClient: (parameters) => getAnsHostClient({ - args: { ...args, signingCosmWasmClient, sender }, - ...rest, + ...parameters, + signingCosmWasmClient, + sender, }), - getAnsHostClientFromApi: ({ args, ...rest }) => + getAnsHostClientFromApi: (parameters) => getAnsHostClientFromApi({ - args: { ...args, signingCosmWasmClient, sender, apiUrl }, - ...rest, + ...parameters, + signingCosmWasmClient, + sender, + apiUrl, }), - getAnsHostClientFromVersionControl: ({ args, ...rest }) => + getAnsHostClientFromVersionControl: (parameters) => getAnsHostClientFromVersionControl({ - args: { ...args, signingCosmWasmClient, sender }, - ...rest, + ...parameters, + signingCosmWasmClient, + sender, }), - getVersionControlClientFromApi: ({ args, ...rest }) => + getVersionControlClientFromApi: (parameters) => getVersionControlClientFromApi({ - args: { ...args, signingCosmWasmClient, sender, apiUrl }, - ...rest, + ...parameters, + signingCosmWasmClient, + sender, + apiUrl, }), - getVersionControlClient: ({ args, ...rest }) => + getVersionControlClient: (parameters) => getVersionControlClient({ - args: { ...args, signingCosmWasmClient, sender }, - ...rest, + ...parameters, + signingCosmWasmClient, + sender, }), - getManagerClient: ({ args, ...rest }) => + getManagerClient: (parameters) => getManagerClient({ - args: { ...args, signingCosmWasmClient, sender }, - ...rest, + ...parameters, + signingCosmWasmClient, + sender, }), - getProxyClient: ({ args, ...rest }) => + getProxyClient: (parameters) => getProxyClient({ - args: { ...args, signingCosmWasmClient, sender }, - ...rest, + ...parameters, + signingCosmWasmClient, + sender, }), getSigningCosmWasmClient: () => getSigningCosmWasmClient({ - args: { signingCosmWasmClient }, + signingCosmWasmClient, }), getSenderAddress: () => getSenderAddress({ - args: { sender }, + sender, }), } } diff --git a/packages/core/src/legacy/clients/AbstractClient.ts b/packages/core/src/legacy/clients/AbstractClient.ts index de4ba433..5db7ad19 100644 --- a/packages/core/src/legacy/clients/AbstractClient.ts +++ b/packages/core/src/legacy/clients/AbstractClient.ts @@ -150,7 +150,8 @@ export class AbstractQueryClient implements IAbstractQueryClient { chains: string[], ): Promise { const result = await this._apiClient.getAccountsByOwnerFromApi({ - args: { owner, chains }, + owner, + chains, }) return result.map((r) => new AbstractAccountId(r.chainName, r.seq, r.trace)) } diff --git a/packages/core/src/types/parameters.ts b/packages/core/src/types/parameters.ts new file mode 100644 index 00000000..5166b511 --- /dev/null +++ b/packages/core/src/types/parameters.ts @@ -0,0 +1,17 @@ +import { Coin, StdFee } from '@cosmjs/stargate' +import { Evaluate, Omit } from './utils' + +export type WithCosmWasmSignOptions< + parameters extends {} | readonly unknown[], +> = Evaluate< + parameters & { + readonly fee: number | StdFee | 'auto' + readonly memo?: string + readonly funds?: (Coin & { [key: string]: string })[] + } +> + +export type ExtractAndOmitParameters< + fn extends (parameters: any) => any, + keys extends keyof Parameters[0], +> = Evaluate[0], keys>> diff --git a/packages/core/src/types/utils.ts b/packages/core/src/types/utils.ts index e8800860..5cc0ceb2 100644 --- a/packages/core/src/types/utils.ts +++ b/packages/core/src/types/utils.ts @@ -1,14 +1,99 @@ +// Copied from https://github.com/wevm/wagmi/blob/main/packages/core/src/types/utils.ts#L10 +/** Combines members of an intersection into a readable type. */ +// https://twitter.com/mattpocockuk/status/1622730173446557697?s=20&t=NdpAcmEFXY01xkqU3KO0Mg +export type Evaluate = { [key in keyof type]: type[key] } & unknown + /** - * @description Combines members of an intersection into a readable type. + * Makes all properties of an object optional. * - * @see {@link https://twitter.com/mattpocockuk/status/1622730173446557697?s=20&t=NdpAcmEFXY01xkqU3KO0Mg} - * @example - * Prettify<{ a: string } & { b: string } & { c: number, d: bigint }> - * => { a: string, b: string, c: number, d: bigint } + * Compatible with [`exactOptionalPropertyTypes`](https://www.typescriptlang.org/tsconfig#exactOptionalPropertyTypes). + */ +export type ExactPartial = { + [key in keyof type]?: type[key] | undefined +} + +/** Checks if {@link type} can be narrowed further than {@link type2} */ +export type IsNarrowable = IsUnknown extends true + ? false + : undefined extends type + ? false + : IsNever< + (type extends type2 ? true : false) & (type2 extends type ? false : true) + > extends true + ? false + : true + +/** + * @internal + * Checks if {@link type} is `never` + */ +export type IsNever = [type] extends [never] ? true : false + +/** + * @internal + * Checks if {@link type} is `unknown` */ -export type Prettify = { - [K in keyof T]: T[K] -} & {} +export type IsUnknown = unknown extends type ? true : false + +/** Merges two object types into new type */ +export type Merge = Evaluate< + LooseOmit & + obj2 +> + +/** Removes `readonly` from all properties of an object. */ +export type Mutable = { + -readonly [key in keyof type]: type[key] +} + +/** Strict version of built-in Omit type */ +export type Omit = Pick< + type, + Exclude +> + +/** Makes objects destructurable. */ +export type OneOf< + union extends object, + /// + keys extends KeyofUnion = KeyofUnion, +> = union extends infer Item + ? Evaluate]?: undefined }> + : never +type KeyofUnion = type extends type ? keyof type : never + +/** Makes {@link key} optional in {@link type} while preserving type inference. */ +// s/o trpc (https://github.com/trpc/trpc/blob/main/packages/server/src/types.ts#L6) +export type PartialBy = ExactPartial< + Pick +> & + Omit + +/////////////////////////////////////////////////////////////////////////// +// Loose types + +/** Loose version of {@link Omit} */ +export type LooseOmit = Pick< + type, + Exclude +> + +/////////////////////////////////////////////////////////////////////////// +// Union types + +export type UnionEvaluate = type extends object ? Evaluate : type + +export type UnionLooseOmit = type extends any + ? LooseOmit + : never + +export type UnionOmit = type extends any + ? Omit + : never + +export type UnionPartial = type extends object ? ExactPartial : type + +export type MaybeArray = T | T[] export type SliceFirst = T extends readonly [ infer _, @@ -46,5 +131,3 @@ export type SliceFirstFour = T extends readonly [ export type WithOptional = Omit & Partial> - -export type MaybeArray = T | T[] diff --git a/packages/core/src/types/with-args.ts b/packages/core/src/types/with-args.ts deleted file mode 100644 index 9c379f6b..00000000 --- a/packages/core/src/types/with-args.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { Coin, StdFee } from '@cosmjs/stargate' -import { Prettify } from './utils' - -export type WithArgs = { - args: Prettify> -} - -export type WithArgsAndCosmWasmSignOptions< - TArgs extends {} | readonly unknown[], -> = Prettify< - WithArgs & { - readonly fee: number | StdFee | 'auto' - readonly memo?: string - readonly funds?: (Coin & { [key: string]: string })[] - } -> - -export type CutArgs< - TArgs extends {}, - T extends (payload: any) => any, - K extends keyof TArgs = keyof TArgs, -> = Prettify< - T extends (payload: infer P) => any - ? P extends WithArgs - ? Prettify< - Omit & { - args: Prettify> - } - > - : never - : never -> diff --git a/packages/core/src/utils/assets/ans/types.ts b/packages/core/src/utils/assets/ans/types.ts index 2db61556..c6891428 100644 --- a/packages/core/src/utils/assets/ans/types.ts +++ b/packages/core/src/utils/assets/ans/types.ts @@ -1,5 +1,5 @@ -import { Prettify } from '../../../types/utils' +import { Evaluate } from '../../../types/utils' import { AnsToken } from '../../../utils/tokens/ans/types' import { Asset } from '../asset' -export type AnsAsset = Prettify & Asset> +export type AnsAsset = Evaluate & Asset> diff --git a/packages/core/tsup.config.ts b/packages/core/tsup.config.ts index 058c2918..47a666f2 100644 --- a/packages/core/tsup.config.ts +++ b/packages/core/tsup.config.ts @@ -10,6 +10,7 @@ export default defineConfig( //dev: process.env.DEV === 'true', entry: [ 'src/index.ts', + 'src/actions/index.ts', 'src/clients/index.ts', 'src/utils/index.ts', 'src/legacy/index.ts', diff --git a/packages/react/src/create-config.ts b/packages/react/src/create-config.ts index 1c38b9b0..93de5892 100644 --- a/packages/react/src/create-config.ts +++ b/packages/react/src/create-config.ts @@ -17,7 +17,7 @@ import { SigningCosmWasmClient, } from '@cosmjs/cosmwasm-stargate' import { useMemo } from 'react' -import { Prettify } from './types/utils' +import { Prettify } from './types/args' type CommonProviderArgs = { chainName: string | undefined diff --git a/packages/react/src/hooks/account/public/use-account-base-addresses-from-api.ts b/packages/react/src/hooks/account/public/use-account-base-addresses-from-api.ts index 4cfae6a8..651e152b 100644 --- a/packages/react/src/hooks/account/public/use-account-base-addresses-from-api.ts +++ b/packages/react/src/hooks/account/public/use-account-base-addresses-from-api.ts @@ -1,11 +1,12 @@ -import { AccountId, AccountPublicClient } from '@abstract-money/core' -import { - UseQueryOptions, - UseQueryResult, - useQuery, -} from '@tanstack/react-query' +import { AccountPublicClient } from '@abstract-money/core/clients' +import { AccountId } from '@abstract-money/core/utils' import React from 'react' import { useConfig } from '../../../contexts' +import { + UseQueryParameters, + UseQueryReturnType, + useQuery, +} from '../../../types/queries' type QueryFnData = Awaited< ReturnType @@ -20,15 +21,20 @@ type QueryKey = readonly [ ] type QueryOptions = Omit< - UseQueryOptions, + UseQueryParameters, 'queryFn' > -type QueryResult = UseQueryResult +type QueryResult = UseQueryReturnType -export function useAccountBaseAddressesFromApi( - { accountId }: { accountId: AccountId | undefined }, - options: QueryOptions = { enabled: true }, -): QueryResult { +export type UseAccountBaseAddressesFromApiParameters = { + accountId: AccountId | undefined + query?: QueryOptions +} + +export function useAccountBaseAddressesFromApi({ + accountId, + query = {}, +}: UseAccountBaseAddressesFromApiParameters): QueryResult { const config = useConfig() const accountPublicClient = config.useAccountPublicClient({ accountId, @@ -39,16 +45,13 @@ export function useAccountBaseAddressesFromApi( [accountPublicClient, accountId], ) - const enabled = React.useMemo( - () => Boolean(accountPublicClient && options.enabled), - [options.enabled, accountPublicClient], - ) + const enabled = Boolean(accountPublicClient && (query.enabled ?? true)) const queryFn = React.useCallback(() => { if (!accountPublicClient) throw new Error('No client') - return accountPublicClient.getAccountBaseAddresses({ args: {} }) + return accountPublicClient.getAccountBaseAddresses({}) }, [accountPublicClient]) - return useQuery(queryKey, queryFn, { ...options, enabled }) + return useQuery({ queryKey, queryFn, ...query, enabled }) } diff --git a/packages/react/src/hooks/account/public/use-module-instantiate2-address-from-api.ts b/packages/react/src/hooks/account/public/use-module-instantiate2-address-from-api.ts index 35e7dd5f..318cd8ff 100644 --- a/packages/react/src/hooks/account/public/use-module-instantiate2-address-from-api.ts +++ b/packages/react/src/hooks/account/public/use-module-instantiate2-address-from-api.ts @@ -1,11 +1,13 @@ -import { AccountId, AccountPublicClient } from '@abstract-money/core' -import { - UseQueryOptions, - UseQueryResult, - useQuery, -} from '@tanstack/react-query' +import { AccountPublicClient } from '@abstract-money/core/clients' +import { AccountId } from '@abstract-money/core/utils' import React from 'react' import { useConfig } from '../../../contexts' +import { WithArgs } from '../../../types/args' +import { + UseQueryParameters, + UseQueryReturnType, + useQuery, +} from '../../../types/queries' type QueryFnData = Awaited< ReturnType @@ -17,26 +19,28 @@ type QueryKey = readonly [ 'moduleInstantiate2AddressFromApi', AccountPublicClient | undefined, AccountId | undefined, - UseModuleInstantiate2AddressFromApiArgs['args'], + UseModuleInstantiate2AddressFromApiParameters['args'], ] -type QueryOptions = Omit< - UseQueryOptions, - 'queryFn' +type QueryOptions = UseQueryParameters< + QueryFnData, + QueryError, + QueryData, + QueryKey > -type QueryResult = UseQueryResult - -type UseModuleInstantiate2AddressFromApiArgs = Parameters< - AccountPublicClient['getModuleInstantiate2AddressFromApi'] ->[0] -export function useModuleInstantiate2AddressFromApi( - parameters: UseModuleInstantiate2AddressFromApiArgs & { - accountId: AccountId | undefined - }, - options: QueryOptions = { enabled: true }, -): QueryResult { - const { args, accountId } = parameters +type QueryResult = UseQueryReturnType +export type UseModuleInstantiate2AddressFromApiParameters = WithArgs< + Parameters[0] +> & { + query?: QueryOptions + accountId: AccountId | undefined +} +export function useModuleInstantiate2AddressFromApi({ + args, + accountId, + query = {}, +}: UseModuleInstantiate2AddressFromApiParameters): QueryResult { const config = useConfig() const accountPublicClient = config.useAccountPublicClient({ accountId, @@ -53,19 +57,16 @@ export function useModuleInstantiate2AddressFromApi( [accountPublicClient, accountId, args], ) - const enabled = React.useMemo( - () => Boolean(accountPublicClient && args && options.enabled), - [options.enabled, accountPublicClient], + const enabled = Boolean( + accountPublicClient && args && (query.enabled ?? true), ) const queryFn = React.useCallback(() => { if (!accountPublicClient) throw new Error('No client') if (!args) throw new Error('No args') - return accountPublicClient.getModuleInstantiate2AddressFromApi({ - args, - }) + return accountPublicClient.getModuleInstantiate2AddressFromApi(args) }, [accountPublicClient]) - return useQuery(queryKey, queryFn, { ...options, enabled }) + return useQuery({ queryKey, queryFn, ...query, enabled }) } diff --git a/packages/react/src/hooks/account/public/use-sub-accounts-ids-from-api.ts b/packages/react/src/hooks/account/public/use-sub-accounts-ids-from-api.ts index f133b265..b646e1de 100644 --- a/packages/react/src/hooks/account/public/use-sub-accounts-ids-from-api.ts +++ b/packages/react/src/hooks/account/public/use-sub-accounts-ids-from-api.ts @@ -1,40 +1,42 @@ -import { AccountId, AccountPublicClient } from '@abstract-money/core' -import { - UseQueryOptions, - UseQueryResult, - useQuery, -} from '@tanstack/react-query' +import { AccountPublicClient } from '@abstract-money/core/clients' +import { AccountId } from '@abstract-money/core/utils' import React from 'react' import { useConfig } from '../../../contexts' +import { WithArgs } from '../../../types/args' +import { + UseQueryParameters, + UseQueryReturnType, + useQuery, +} from '../../../types/queries' type QueryFnData = Awaited> type QueryError = unknown type QueryData = QueryFnData -type UseSubAccountIdsFromApiArgs = Parameters< - AccountPublicClient['getSubAccountIds'] ->[0] +export type UseSubAccountIdsFromApiParameters = WithArgs< + Parameters[0] +> & { + query?: QueryOptions + accountId: AccountId | undefined +} type QueryKey = readonly [ 'getSubAccountIdsFromApi', AccountPublicClient | undefined, AccountId | undefined, - UseSubAccountIdsFromApiArgs['args'], + UseSubAccountIdsFromApiParameters['args'], ] type QueryOptions = Omit< - UseQueryOptions, + UseQueryParameters, 'queryFn' > -type QueryResult = UseQueryResult - -export function useSubAccountIdsFromApi( - parameters: UseSubAccountIdsFromApiArgs & { - accountId: AccountId | undefined - }, - options: QueryOptions = { enabled: true }, -): QueryResult { - const { args, accountId } = parameters +type QueryResult = UseQueryReturnType +export function useSubAccountIdsFromApi({ + args, + accountId, + query = {}, +}: UseSubAccountIdsFromApiParameters): QueryResult { const config = useConfig() const accountPublicClient = config.useAccountPublicClient({ accountId, @@ -51,19 +53,16 @@ export function useSubAccountIdsFromApi( [accountPublicClient, accountId, args], ) - const enabled = React.useMemo( - () => Boolean(accountPublicClient && args && options.enabled), - [options.enabled, accountPublicClient], + const enabled = Boolean( + (accountPublicClient && args && query.enabled) ?? true, ) const queryFn = React.useCallback(() => { if (!accountPublicClient) throw new Error('No client') if (!args) throw new Error('No args') - return accountPublicClient.getSubAccountIds({ - args, - }) + return accountPublicClient.getSubAccountIds(args) }, [accountPublicClient]) - return useQuery(queryKey, queryFn, { ...options, enabled }) + return useQuery({ queryKey, queryFn, ...query, enabled }) } diff --git a/packages/react/src/hooks/account/wallet/use-create-sub-account.ts b/packages/react/src/hooks/account/wallet/use-create-sub-account.ts index 4b481e8a..6ab6b98d 100644 --- a/packages/react/src/hooks/account/wallet/use-create-sub-account.ts +++ b/packages/react/src/hooks/account/wallet/use-create-sub-account.ts @@ -1,22 +1,26 @@ -import { AccountId, AccountWalletClient } from '@abstract-money/core' -import { UseMutationOptions, useMutation } from '@tanstack/react-query' +import { AccountWalletClient } from '@abstract-money/core/clients' +import { AccountId } from '@abstract-money/core/utils' +import { useMutation } from '@tanstack/react-query' import { useConfig } from '../../../contexts' +import { UseMutationParameters } from '../../../types/queries' type CreateSubAccountMutation = Parameters< AccountWalletClient['createSubAccount'] >[0] -export function useCreateSubAccount( - { accountId }: { accountId: AccountId | undefined }, - options?: Omit< - UseMutationOptions< - Awaited>, - unknown, - CreateSubAccountMutation - >, - 'mutationFn' - >, -) { +export type UseCreateSubAccountParameters = { + accountId: AccountId | undefined + mutation?: UseMutationParameters< + Awaited>, + unknown, + CreateSubAccountMutation + > +} + +export function useCreateSubAccount({ + accountId, + mutation, +}: UseCreateSubAccountParameters) { const config = useConfig() const walletClient = config.useAccountWalletClient({ chainName: accountId?.chainName, @@ -26,5 +30,5 @@ export function useCreateSubAccount( return useMutation((parameters) => { if (!walletClient) throw new Error('walletClient is not defined') return walletClient.createSubAccount(parameters) - }, options) + }, mutation) } diff --git a/packages/react/src/hooks/account/wallet/use-deposit.ts b/packages/react/src/hooks/account/wallet/use-deposit.ts index aff68249..0c2cf940 100644 --- a/packages/react/src/hooks/account/wallet/use-deposit.ts +++ b/packages/react/src/hooks/account/wallet/use-deposit.ts @@ -1,25 +1,32 @@ -import { AccountId, AccountWalletClient } from '@abstract-money/core' +import { AccountWalletClient } from '@abstract-money/core/clients' +import { AccountId } from '@abstract-money/core/utils' import { DeliverTxResponse } from '@cosmjs/stargate' -import { - UseMutationOptions, - UseMutationResult, - useMutation, -} from '@tanstack/react-query' +import { useMutation } from '@tanstack/react-query' import { useConfig } from '../../../contexts' +import { + UseMutationParameters, + UseMutationReturnType, +} from '../../../types/queries' type DepositMutation = Parameters[0] +export type UseDepositParameters = { + accountId: AccountId | undefined + mutation?: UseMutationParameters +} + /** * Hook to deposit assets to an Account. * @param options deposit options. */ -export function useDeposit( - { accountId }: { accountId: AccountId | undefined }, - options?: Omit< - UseMutationOptions, - 'mutationFn' - >, -): UseMutationResult { +export function useDeposit({ + accountId, + mutation, +}: UseDepositParameters): UseMutationReturnType< + DeliverTxResponse, + unknown, + DepositMutation +> { const config = useConfig() const accountWalletClient = config.useAccountWalletClient({ accountId, @@ -28,5 +35,5 @@ export function useDeposit( return useMutation(({ ...rest }) => { if (!accountWalletClient) throw new Error('client is not defined') return accountWalletClient.deposit(rest) - }, options) + }, mutation) } diff --git a/packages/react/src/hooks/account/wallet/use-execute.ts b/packages/react/src/hooks/account/wallet/use-execute.ts index a348d27c..15bb7429 100644 --- a/packages/react/src/hooks/account/wallet/use-execute.ts +++ b/packages/react/src/hooks/account/wallet/use-execute.ts @@ -1,21 +1,27 @@ -import { AccountId, AccountWalletClient } from '@abstract-money/core' +import { AccountWalletClient } from '@abstract-money/core/clients' +import { AccountId } from '@abstract-money/core/utils' import { DeliverTxResponse } from '@cosmjs/stargate' -import { - UseMutationOptions, - UseMutationResult, - useMutation, -} from '@tanstack/react-query' +import { useMutation } from '@tanstack/react-query' import { useConfig } from '../../../contexts' +import { + UseMutationParameters, + UseMutationReturnType, +} from '../../../types/queries' type ExecuteMutation = Parameters[0] -export function useExecute( - { accountId }: { accountId: AccountId | undefined }, - options?: Omit< - UseMutationOptions, - 'mutationFn' - >, -): UseMutationResult { +export type UseExecuteParameters = { + accountId: AccountId | undefined + mutation?: UseMutationParameters +} +export function useExecute({ + accountId, + mutation, +}: UseExecuteParameters): UseMutationReturnType< + DeliverTxResponse, + unknown, + ExecuteMutation +> { const config = useConfig() const accountWalletClient = config.useAccountWalletClient({ chainName: accountId?.chainName, @@ -24,5 +30,5 @@ export function useExecute( return useMutation(({ ...rest }) => { if (!accountWalletClient) throw new Error('client is not defined') return accountWalletClient.execute(rest) - }, options) + }, mutation) } diff --git a/packages/react/src/hooks/account/wallet/use-withdraw.ts b/packages/react/src/hooks/account/wallet/use-withdraw.ts index 8e7ca274..3eeff35b 100644 --- a/packages/react/src/hooks/account/wallet/use-withdraw.ts +++ b/packages/react/src/hooks/account/wallet/use-withdraw.ts @@ -1,25 +1,32 @@ -import { AccountId, AccountWalletClient } from '@abstract-money/core' +import { AccountWalletClient } from '@abstract-money/core/clients' +import { AccountId } from '@abstract-money/core/utils' import { DeliverTxResponse } from '@cosmjs/stargate' -import { - UseMutationOptions, - UseMutationResult, - useMutation, -} from '@tanstack/react-query' +import { useMutation } from '@tanstack/react-query' import { useConfig } from '../../../contexts' +import { + UseMutationParameters, + UseMutationReturnType, +} from '../../../types/queries' type WithdrawMutation = Parameters[0] +export type UseWithdrawParameters = { + accountId: AccountId | undefined + mutation?: UseMutationParameters +} + /** * Hook to withdraw to an Account. * @param options withdraw options. */ -export function useWithdraw( - { accountId }: { accountId: AccountId | undefined }, - options?: Omit< - UseMutationOptions, - 'mutationFn' - >, -): UseMutationResult { +export function useWithdraw({ + accountId, + mutation, +}: UseWithdrawParameters): UseMutationReturnType< + DeliverTxResponse, + unknown, + WithdrawMutation +> { const config = useConfig() const accountWalletClient = config.useAccountWalletClient({ chainName: accountId?.chainName, @@ -28,5 +35,5 @@ export function useWithdraw( return useMutation(({ ...rest }) => { if (!accountWalletClient) throw new Error('client is not defined') return accountWalletClient.withdraw(rest) - }, options) + }, mutation) } diff --git a/packages/react/src/hooks/public/use-abstract-module-version.ts b/packages/react/src/hooks/public/use-abstract-module-version.ts index 0a726a06..43732a90 100644 --- a/packages/react/src/hooks/public/use-abstract-module-version.ts +++ b/packages/react/src/hooks/public/use-abstract-module-version.ts @@ -1,7 +1,8 @@ -import { PublicClient } from '@abstract-money/core' -import { UseQueryOptions, useQuery } from '@tanstack/react-query' +import { PublicClient } from '@abstract-money/core/clients' import React from 'react' import { useConfig } from '../../contexts' +import { WithArgs } from '../../types/args' +import { UseQueryParameters, useQuery } from '../../types/queries' type QueryFnData = Awaited> @@ -11,21 +12,24 @@ type QueryKey = readonly [ 'abstractModuleVersion', PublicClient | undefined, string | undefined, - UseAbstractModuleVersionArgs['args'], + UseAbstractModuleVersionParameters['args'], ] -type QueryOptions = Omit< - UseQueryOptions, - 'queryFn' +type QueryOptions = UseQueryParameters< + QueryFnData, + QueryError, + QueryData, + QueryKey > -type UseAbstractModuleVersionArgs = Parameters< - PublicClient['getAbstractModuleVersion'] ->[0] & { chainName: string | undefined } -export function useAbstractModuleVersion( - { args, chainName }: UseAbstractModuleVersionArgs, - options: QueryOptions = { enabled: true }, -) { +export type UseAbstractModuleVersionParameters = WithArgs< + Parameters[0] +> & { chainName?: string | undefined; query?: QueryOptions } +export function useAbstractModuleVersion({ + args, + chainName, + query = {}, +}: UseAbstractModuleVersionParameters) { const config = useConfig() const publicClient = config.usePublicClient({ chainName, @@ -35,19 +39,14 @@ export function useAbstractModuleVersion( [publicClient, args], ) - const enabled = React.useMemo( - () => Boolean(publicClient && args && options?.enabled), - [options?.enabled, publicClient], - ) + const enabled = Boolean(publicClient && args && (query.enabled ?? true)) const queryFn = React.useCallback(() => { if (!publicClient) throw new Error('No client') if (!args) throw new Error('No args') - return publicClient.getAbstractModuleVersion({ - args, - }) + return publicClient.getAbstractModuleVersion(args) }, [publicClient]) - return useQuery(queryKey, queryFn, { ...options, enabled }) + return useQuery({ queryKey, queryFn, ...query, enabled }) } diff --git a/packages/react/src/hooks/public/use-account-factory-config-from-api.ts b/packages/react/src/hooks/public/use-account-factory-config-from-api.ts index ed4448b6..8319bb1c 100644 --- a/packages/react/src/hooks/public/use-account-factory-config-from-api.ts +++ b/packages/react/src/hooks/public/use-account-factory-config-from-api.ts @@ -1,11 +1,12 @@ -import { PublicClient } from '@abstract-money/core' -import { - UseQueryOptions, - UseQueryResult, - useQuery, -} from '@tanstack/react-query' +import { PublicClient } from '@abstract-money/core/clients' import React from 'react' import { useConfig } from '../../contexts' +import { WithArgs } from '../../types/args' +import { + UseQueryParameters, + UseQueryReturnType, + useQuery, +} from '../../types/queries' type QueryFnData = Awaited< ReturnType< @@ -21,16 +22,23 @@ type QueryKey = readonly [ 'accountFactoryConfigFromApi', PublicClient | undefined, ] -type QueryResult = UseQueryResult +type QueryResult = UseQueryReturnType -type QueryOptions = Omit< - UseQueryOptions, - 'queryFn' +type QueryOptions = UseQueryParameters< + QueryFnData, + QueryError, + QueryData, + QueryKey > -export function useAccountFactoryConfigFromApi( - chainName?: string, - options: QueryOptions = { enabled: true }, -): QueryResult { + +export type UseAccountFactoryConfigFromApi = WithArgs< + Parameters[0] +> & { chainName?: string | undefined; query?: QueryOptions } + +export function useAccountFactoryConfigFromApi({ + chainName, + query = {}, +}: UseAccountFactoryConfigFromApi): QueryResult { const config = useConfig() const publicClient = config.usePublicClient({ chainName, @@ -40,10 +48,7 @@ export function useAccountFactoryConfigFromApi( [publicClient], ) - const enabled = React.useMemo( - () => Boolean(publicClient && options?.enabled), - [options?.enabled, publicClient], - ) + const enabled = Boolean(publicClient && (query.enabled ?? true)) const queryFn = React.useCallback(async () => { if (!publicClient) throw new Error('No client') @@ -54,5 +59,5 @@ export function useAccountFactoryConfigFromApi( return config }, [publicClient]) - return useQuery(queryKey, queryFn, { ...options, enabled }) + return useQuery({ queryKey, queryFn, ...query, enabled }) } diff --git a/packages/react/src/hooks/public/use-account-factory-query-client-from-api.ts b/packages/react/src/hooks/public/use-account-factory-query-client-from-api.ts index b1c7b109..d49c3a9f 100644 --- a/packages/react/src/hooks/public/use-account-factory-query-client-from-api.ts +++ b/packages/react/src/hooks/public/use-account-factory-query-client-from-api.ts @@ -1,11 +1,12 @@ -import { PublicClient } from '@abstract-money/core' -import { - UseQueryOptions, - UseQueryResult, - useQuery, -} from '@tanstack/react-query' +import { PublicClient } from '@abstract-money/core/clients' import React from 'react' import { useConfig } from '../../contexts' +import { WithArgs } from '../../types/args' +import { + UseQueryParameters, + UseQueryReturnType, + useQuery, +} from '../../types/queries' type QueryFnData = Awaited< ReturnType @@ -17,16 +18,23 @@ type QueryKey = readonly [ 'accountFactoryQueryClientFromApi', PublicClient | undefined, ] -type QueryResult = UseQueryResult +type QueryResult = UseQueryReturnType -type QueryOptions = Omit< - UseQueryOptions, - 'queryFn' +type QueryOptions = UseQueryParameters< + QueryFnData, + QueryError, + QueryData, + QueryKey > -export function useAccountFactoryQueryClientFromApi( - chainName?: string, - options: QueryOptions = { enabled: true }, -): QueryResult { + +export type UseAccountFactoryQueryClientFromApi = WithArgs< + Parameters[0] +> & { chainName?: string | undefined; query?: QueryOptions } + +export function useAccountFactoryQueryClientFromApi({ + chainName, + query = {}, +}: UseAccountFactoryQueryClientFromApi): QueryResult { const config = useConfig() const publicClient = config.usePublicClient({ chainName, @@ -36,16 +44,13 @@ export function useAccountFactoryQueryClientFromApi( [publicClient], ) - const enabled = React.useMemo( - () => Boolean(publicClient && options?.enabled), - [options?.enabled, publicClient], - ) + const enabled = Boolean(publicClient && (query.enabled ?? true)) const queryFn = React.useCallback(() => { if (!publicClient) throw new Error('No client') - return publicClient.getAccountFactoryQueryClientFromApi({ args: {} }) + return publicClient.getAccountFactoryQueryClientFromApi({}) }, [publicClient]) - return useQuery(queryKey, queryFn, { ...options, enabled }) + return useQuery({ queryKey, queryFn, ...query, enabled }) } diff --git a/packages/react/src/hooks/public/use-cosm-wasm-client.ts b/packages/react/src/hooks/public/use-cosm-wasm-client.ts index a4e0b68a..d72b0e68 100644 --- a/packages/react/src/hooks/public/use-cosm-wasm-client.ts +++ b/packages/react/src/hooks/public/use-cosm-wasm-client.ts @@ -1,29 +1,40 @@ import { PublicClient } from '@abstract-money/core' -import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { UseQueryOptions, useQuery } from '@tanstack/react-query' import React from 'react' -import { useConfig } from 'src/contexts' - -export function useCosmWasmClient( - args: { - /** Pass only if you are using cosmos-kit provider, graz doesn't need one. */ - chainName: string | undefined - }, - { - enabled: enabled_ = true, - ...rest - }: UseQueryOptions< - CosmWasmClient | undefined, - unknown, - CosmWasmClient | undefined, - readonly ['cosm-wasm-client', PublicClient | undefined] - > = {}, -) { +import { useConfig } from '../../contexts' +import { + UseQueryParameters, + UseQueryReturnType, + useQuery, +} from '../../types/queries' + +type QueryFnData = Awaited> + +type QueryError = unknown +type QueryData = QueryFnData +type QueryKey = readonly ['cosmWasmClient', PublicClient | undefined] +type QueryResult = UseQueryReturnType + +type QueryOptions = UseQueryParameters< + QueryFnData, + QueryError, + QueryData, + QueryKey +> + +export type UseCosmWasmClientParameters = { + chainName?: string | undefined + query?: QueryOptions +} + +export function useCosmWasmClient({ + chainName, + query = {}, +}: UseCosmWasmClientParameters): QueryResult { const config = useConfig() - const publicClient = config.usePublicClient({ chainName: args?.chainName }) + const publicClient = config.usePublicClient({ chainName }) const queryKey = React.useMemo( - () => ['cosm-wasm-client', publicClient] as const, + () => ['cosmWasmClient', publicClient] as const, [publicClient], ) @@ -33,10 +44,7 @@ export function useCosmWasmClient( return publicClient.getCosmWasmClient() }, [publicClient]) - const enabled = React.useMemo( - () => Boolean(publicClient && enabled_), - [enabled_, publicClient], - ) + const enabled = Boolean(publicClient && (query.enabled ?? true)) - return useQuery(queryKey, queryFn, { enabled, ...rest }) + return useQuery({ queryKey, queryFn, ...query, enabled }) } diff --git a/packages/react/src/hooks/use-account-balance-from-api.ts b/packages/react/src/hooks/use-account-balance-from-api.ts index fc5fd99c..e23b25fc 100644 --- a/packages/react/src/hooks/use-account-balance-from-api.ts +++ b/packages/react/src/hooks/use-account-balance-from-api.ts @@ -1,27 +1,28 @@ -import { ApiClient } from '@abstract-money/core' -import { UseQueryOptions, useQuery } from '@tanstack/react-query' +import { ApiClient } from '@abstract-money/core/clients' import React from 'react' import { useConfig } from '../contexts' -import { WithArgs } from '../types/utils' +import { WithArgs } from '../types/args' +import { UseQueryParameters, useQuery } from '../types/queries' -export function useAccountBalancesFromApi( - { - args, - }: WithArgs[0]['args']>, - { - enabled: enabled_ = true, - ...rest - }: UseQueryOptions< +export type UseAccountBalancesFromApiParameters = WithArgs< + Parameters[0] +> & { + query?: UseQueryParameters< Awaited>, unknown, Awaited>, readonly [ 'accountBalancesFromApi', - WithArgs[0]['args']>, + WithArgs[0]>, ApiClient | undefined, ] - > = {}, -) { + > +} + +export function useAccountBalancesFromApi({ + args, + query = {}, +}: UseAccountBalancesFromApiParameters) { const config = useConfig() const client = config.useApiClient() const queryKey = React.useMemo( @@ -29,18 +30,15 @@ export function useAccountBalancesFromApi( [args, client], ) - const enabled = React.useMemo( - () => Boolean(client && args?.accountId && enabled_), - [enabled_, client, args], - ) + const enabled = Boolean(client && args?.accountId && (query.enabled ?? true)) const queryFn = React.useCallback(() => { if (!client || !args?.accountId) throw new Error('No client or accountid') return client.getAccountBalancesFromApi({ - args: { accountId: args.accountId }, + accountId: args.accountId, }) }, [client, args]) - return useQuery(queryKey, queryFn, { enabled, ...rest }) + return useQuery({ queryKey, queryFn, ...query, enabled }) } diff --git a/packages/react/src/hooks/use-accounts.ts b/packages/react/src/hooks/use-accounts.ts index 31381254..e77d4903 100644 --- a/packages/react/src/hooks/use-accounts.ts +++ b/packages/react/src/hooks/use-accounts.ts @@ -1,25 +1,16 @@ -import { AccountId, ApiClient } from '@abstract-money/core' -import { UseQueryOptions, useQuery } from '@tanstack/react-query' +import { ApiClient } from '@abstract-money/core/clients' +import { AccountId } from '@abstract-money/core/utils' import React from 'react' import { useConfig } from '../contexts' -import { MaybeArray, WithArgs } from '../types/utils' +import { WithArgs } from '../types/args' +import { UseQueryParameters, useQuery } from '../types/queries' +import { MaybeArray } from '../types/utils' -/** - * Loads all accounts for a given owner and chain. - * @param owner address of the owner. Will automatically translate to other chains' addresses. - * @param chainName chain to load accounts for. - */ -export function useAccounts( - { - args, - }: WithArgs<{ - owner: string - chainName: MaybeArray - }>, - { - enabled: enabled_ = true, - ...rest - }: UseQueryOptions< +export type UseAccountsParameters = WithArgs<{ + owner: string + chainName: MaybeArray +}> & { + query?: UseQueryParameters< AccountId[], unknown, AccountId[], @@ -29,8 +20,15 @@ export function useAccounts( string[] | undefined, ApiClient | undefined, ] - > = {}, -) { + > +} + +/** + * Loads all accounts for a given owner and chain. + * @param owner address of the owner. Will automatically translate to other chains' addresses. + * @param chainName chain to load accounts for. + */ +export function useAccounts({ args, query = {} }: UseAccountsParameters) { const chains = React.useMemo( () => args?.chainName @@ -47,9 +45,8 @@ export function useAccounts( [args?.owner, chains, client], ) - const enabled = React.useMemo( - () => Boolean(client && chains && args?.owner && enabled_), - [enabled_, client, args?.owner, chains], + const enabled = Boolean( + client && chains && args?.owner && (query.enabled ?? true), ) const queryFn = React.useCallback(() => { @@ -57,9 +54,10 @@ export function useAccounts( throw new Error('No client or owner or chain') return client.getAccountsByOwnerFromApi({ - args: { owner: args.owner, chains }, + owner: args.owner, + chains, }) }, [client, args?.owner, chains]) - return useQuery(queryKey, queryFn, { enabled, ...rest }) + return useQuery({ queryKey, queryFn, ...query, enabled }) } diff --git a/packages/react/src/hooks/use-ans-token-from-api.ts b/packages/react/src/hooks/use-ans-token-from-api.ts index 86a500c3..e28c7c39 100644 --- a/packages/react/src/hooks/use-ans-token-from-api.ts +++ b/packages/react/src/hooks/use-ans-token-from-api.ts @@ -1,25 +1,29 @@ -import { AnsToken, ApiClient } from '@abstract-money/core' -import { UseQueryOptions, useQuery } from '@tanstack/react-query' +import { ApiClient } from '@abstract-money/core/clients' +import { AnsToken } from '@abstract-money/core/utils' import React from 'react' import { useConfig } from '../contexts' -import { WithArgs } from '../types/utils' +import { WithArgs } from '../types/args' +import { UseQueryParameters, useQuery } from '../types/queries' -export function useAnsTokenFromAPI( - { args }: WithArgs[0]['args']>, - { - enabled: enabled_ = true, - ...rest - }: UseQueryOptions< +export type UseAnsTokenFromAPIParameters = WithArgs< + Parameters[0] +> & { + query?: UseQueryParameters< AnsToken, unknown, AnsToken, readonly [ 'ansTokenFromApi', - WithArgs[0]['args']>, + WithArgs[0]>, ApiClient | undefined, ] - > = {}, -) { + > +} + +export function useAnsTokenFromAPI({ + args, + query = {}, +}: UseAnsTokenFromAPIParameters) { const config = useConfig() const client = config.useApiClient() const queryKey = React.useMemo( @@ -27,9 +31,8 @@ export function useAnsTokenFromAPI( [args, client], ) - const enabled = React.useMemo( - () => Boolean(client && args?.id && args?.chainName && enabled_), - [enabled_, client, args], + const enabled = Boolean( + client && args?.id && args?.chainName && (query.enabled ?? true), ) const queryFn = React.useCallback(() => { @@ -37,9 +40,10 @@ export function useAnsTokenFromAPI( throw new Error('No client or owner or chain') return client.getAnsTokenFromApi({ - args: { chainName: args.chainName, id: args.id }, + chainName: args.chainName, + id: args.id, }) }, [client, args]) - return useQuery(queryKey, queryFn, { enabled, ...rest }) + return useQuery({ queryKey, queryFn, ...query, enabled }) } diff --git a/packages/react/src/hooks/wallet/use-create-account-monarchy.ts b/packages/react/src/hooks/wallet/use-create-account-monarchy.ts index 99d99814..f6a328e0 100644 --- a/packages/react/src/hooks/wallet/use-create-account-monarchy.ts +++ b/packages/react/src/hooks/wallet/use-create-account-monarchy.ts @@ -1,27 +1,30 @@ import { WalletClient } from '@abstract-money/core' -import { UseMutationOptions, useMutation } from '@tanstack/react-query' +import { useMutation } from '@tanstack/react-query' import { useConfig } from '../../contexts' +import { UseMutationParameters } from '../../types/queries' type CreateAccountMonarchyMutation = Parameters< WalletClient['createAccountMonarchy'] >[0] -export function useCreateAccountMonarchy( - { args: { chainName } }: { args: { chainName: string } }, - options?: Omit< - UseMutationOptions< - Awaited>, - unknown, - CreateAccountMonarchyMutation - >, - 'mutationFn' - >, -) { +export type UseCreateAccountMonarchyParameters = { + chainName: string | undefined + mutation?: UseMutationParameters< + Awaited>, + unknown, + CreateAccountMonarchyMutation + > +} + +export function useCreateAccountMonarchy({ + chainName, + mutation, +}: UseCreateAccountMonarchyParameters) { const config = useConfig() const walletClient = config.useWalletClient({ chainName: chainName }) return useMutation((parameters) => { if (!walletClient) throw new Error('walletClient is not defined') return walletClient.createAccountMonarchy(parameters) - }, options) + }, mutation) } diff --git a/packages/react/src/hooks/wallet/use-create-account.ts b/packages/react/src/hooks/wallet/use-create-account.ts index 0a97460e..96038ede 100644 --- a/packages/react/src/hooks/wallet/use-create-account.ts +++ b/packages/react/src/hooks/wallet/use-create-account.ts @@ -1,25 +1,25 @@ import { WalletClient } from '@abstract-money/core' -import { UseMutationOptions, useMutation } from '@tanstack/react-query' +import { useMutation } from '@tanstack/react-query' import { useConfig } from '../../contexts' +import { UseMutationParameters } from '../../types/queries' type CreateAccountMutation = Parameters[0] -export function useCreateAccount( - { args: { chainName } }: { args: { chainName: string } }, - options?: Omit< - UseMutationOptions< - Awaited>, - unknown, - CreateAccountMutation - >, - 'mutationFn' - >, -) { +export type UseCreateAccount = { + chainName: string | undefined + mutation?: UseMutationParameters< + Awaited>, + unknown, + CreateAccountMutation + > +} + +export function useCreateAccount({ chainName, mutation }: UseCreateAccount) { const config = useConfig() const walletClient = config.useWalletClient({ chainName: chainName }) return useMutation((parameters) => { if (!walletClient) throw new Error('walletClient is not defined') return walletClient.createAccount(parameters) - }, options) + }, mutation) } diff --git a/packages/react/src/hooks/wallet/use-sender-address.ts b/packages/react/src/hooks/wallet/use-sender-address.ts index ca1bab0b..e40b275f 100644 --- a/packages/react/src/hooks/wallet/use-sender-address.ts +++ b/packages/react/src/hooks/wallet/use-sender-address.ts @@ -1,26 +1,24 @@ import { WalletClient } from '@abstract-money/core' -import { UseQueryOptions, useQuery } from '@tanstack/react-query' import React from 'react' -import { useConfig } from 'src/contexts' +import { useConfig } from '../../contexts' +import { UseQueryParameters, useQuery } from '../../types/queries' -export function useSenderAddress( - /** Pass only if you are using cosmos-kit provider, graz doesn't need one */ - args?: { - /** Pass only if you are using cosmos-kit provider, graz doesn't need one. */ - chainName: string | undefined - }, - { - enabled: enabled_ = true, - ...rest - }: UseQueryOptions< - string | undefined, - unknown, - string | undefined, - readonly ['sender-address', WalletClient | undefined] - > = {}, -) { +export type UseSenderAddressParameters = + | { + chainName?: string | undefined + query?: UseQueryParameters< + string | undefined, + unknown, + string | undefined, + readonly ['sender-address', WalletClient | undefined] + > + } + | never + +export function useSenderAddress(parameters: UseSenderAddressParameters) { + const { query = {}, chainName } = parameters ?? {} const config = useConfig() - const walletClient = config.useWalletClient({ chainName: args?.chainName }) + const walletClient = config.useWalletClient({ chainName }) const queryKey = React.useMemo( () => ['sender-address', walletClient] as const, @@ -33,10 +31,7 @@ export function useSenderAddress( return walletClient.getSenderAddress() }, [walletClient]) - const enabled = React.useMemo( - () => Boolean(walletClient && enabled_), - [enabled_, walletClient], - ) + const enabled = Boolean(walletClient && (query.enabled ?? true)) - return useQuery(queryKey, queryFn, { enabled, ...rest }) + return useQuery({ queryKey, queryFn, ...query, enabled }) } diff --git a/packages/react/src/hooks/wallet/use-signing-cosm-wasm-client.ts b/packages/react/src/hooks/wallet/use-signing-cosm-wasm-client.ts index 22ec4a5f..a676ce04 100644 --- a/packages/react/src/hooks/wallet/use-signing-cosm-wasm-client.ts +++ b/packages/react/src/hooks/wallet/use-signing-cosm-wasm-client.ts @@ -1,27 +1,28 @@ import { WalletClient } from '@abstract-money/core' import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { UseQueryOptions, useQuery } from '@tanstack/react-query' import React from 'react' -import { useConfig } from 'src/contexts' +import { useConfig } from '../../contexts' +import { UseQueryParameters, useQuery } from '../../types/queries' + +export type UseSigningCosmWasmClientParameters = + | { + chainName?: string | undefined + query?: UseQueryParameters< + SigningCosmWasmClient | undefined, + unknown, + SigningCosmWasmClient | undefined, + readonly ['signing-cosm-wasm-client', WalletClient | undefined] + > + } + | never export function useSigningCosmWasmClient( /** Pass only if you are using cosmos-kit provider, graz doesn't need one */ - args?: { - /** Pass only if you are using cosmos-kit provider, graz doesn't need one. */ - chainName: string | undefined - }, - { - enabled: enabled_ = true, - ...rest - }: UseQueryOptions< - SigningCosmWasmClient | undefined, - unknown, - SigningCosmWasmClient | undefined, - readonly ['signing-cosm-wasm-client', WalletClient | undefined] - > = {}, + parameters: UseSigningCosmWasmClientParameters, ) { + const { chainName, query = {} } = parameters ?? {} const config = useConfig() - const walletClient = config.useWalletClient({ chainName: args?.chainName }) + const walletClient = config.useWalletClient({ chainName }) const queryKey = React.useMemo( () => ['signing-cosm-wasm-client', walletClient] as const, @@ -34,10 +35,7 @@ export function useSigningCosmWasmClient( return walletClient.getSigningCosmWasmClient() }, [walletClient]) - const enabled = React.useMemo( - () => Boolean(walletClient && enabled_), - [enabled_, walletClient], - ) + const enabled = Boolean(walletClient && (query.enabled ?? true)) - return useQuery(queryKey, queryFn, { enabled, ...rest }) + return useQuery({ queryKey, queryFn, ...query, enabled }) } diff --git a/packages/react/src/hooks/wallet/utils/use-sign-and-broadcast.ts b/packages/react/src/hooks/wallet/utils/use-sign-and-broadcast.ts index 01842c99..949510db 100644 --- a/packages/react/src/hooks/wallet/utils/use-sign-and-broadcast.ts +++ b/packages/react/src/hooks/wallet/utils/use-sign-and-broadcast.ts @@ -1,6 +1,7 @@ import { EncodeObject } from '@cosmjs/proto-signing' import { DeliverTxResponse, StdFee } from '@cosmjs/stargate' -import { UseMutationOptions, useMutation } from '@tanstack/react-query' +import { useMutation } from '@tanstack/react-query' +import { UseMutationParameters } from '../../../types/queries' import { useSenderAddress } from '../use-sender-address' import { useSigningCosmWasmClient } from '../use-signing-cosm-wasm-client' @@ -14,9 +15,10 @@ type SignAndBroadcastMutation = { export function useSignAndBroadcast( { args: { chainName } }: { args: { chainName: string } }, - options?: Omit< - UseMutationOptions, - 'mutationFn' + options?: UseMutationParameters< + DeliverTxResponse, + unknown, + SignAndBroadcastMutation >, ) { const { data: signingCosmWasmClient } = useSigningCosmWasmClient({ diff --git a/packages/react/src/types/args.ts b/packages/react/src/types/args.ts new file mode 100644 index 00000000..bdebc2c3 --- /dev/null +++ b/packages/react/src/types/args.ts @@ -0,0 +1,7 @@ +import { type Evaluate } from './utils' + +export type WithArgs = { + args: Evaluate> | undefined +} + +export type ExtractArgs = TParameters['args'] diff --git a/packages/react/src/types/queries.ts b/packages/react/src/types/queries.ts new file mode 100644 index 00000000..0a7708b5 --- /dev/null +++ b/packages/react/src/types/queries.ts @@ -0,0 +1,128 @@ +// Modified from https://github.com/wevm/wagmi/blob/d767265eb52f830164388f05921fa270acf5dce6/packages/react/src/utils/query.ts +import { + type QueryKey, + type UseInfiniteQueryOptions, + type UseInfiniteQueryResult, + type UseMutationOptions, + type UseMutationResult, + type UseQueryOptions, + type UseQueryResult, + useInfiniteQuery as tanstack_useInfiniteQuery, + useQuery as tanstack_useQuery, +} from '@tanstack/react-query' +import { type Evaluate, type ExactPartial, type Omit } from './utils' + +export type UseMutationParameters< + data = unknown, + error = Error, + variables = void, + context = unknown, +> = Evaluate< + Omit< + UseMutationOptions, context>, + 'mutationFn' | 'mutationKey' + > +> + +export type UseMutationReturnType< + data = unknown, + error = Error, + variables = void, + context = unknown, +> = Evaluate< + Omit< + UseMutationResult, + 'mutate' | 'mutateAsync' + > +> + +//////////////////////////////////////////////////////////////////////////////// + +export type UseQueryParameters< + queryFnData = unknown, + error = Error, + data = queryFnData, + queryKey extends QueryKey = QueryKey, +> = Evaluate< + ExactPartial< + Omit, 'initialData'> + > & { + // Fix `initialData` type + initialData?: + | UseQueryOptions['initialData'] + | undefined + } +> + +export type UseQueryReturnType = Evaluate< + UseQueryResult & { + queryKey: QueryKey + } +> + +// Adding some basic customization. +// Ideally we don't have this function, but `import('@tanstack/react-query').useQuery` currently has some quirks where it is super hard to +// pass down the inferred `initialData` type because of it's discriminated overload in the on `useQuery`. +export function useQuery( + parameters: UseQueryParameters & { + queryKey: QueryKey + }, +): UseQueryReturnType { + const result = tanstack_useQuery({ + ...(parameters as any), + // queryKeyHashFn: hashFn, // for bigint support + }) as UseQueryReturnType + result.queryKey = parameters.queryKey + return result +} + +//////////////////////////////////////////////////////////////////////////////// + +export type UseInfiniteQueryParameters< + queryFnData = unknown, + error = Error, + data = queryFnData, + queryData = queryFnData, + queryKey extends QueryKey = QueryKey, +> = Evaluate< + Omit< + UseInfiniteQueryOptions, + 'initialData' + > & { + // Fix `initialData` type + initialData?: + | UseInfiniteQueryOptions< + queryFnData, + error, + data, + queryKey + >['initialData'] + | undefined + } +> + +export type UseInfiniteQueryReturnType< + data = unknown, + error = Error, +> = UseInfiniteQueryResult & { + queryKey: QueryKey +} + +// Adding some basic customization. +export function useInfiniteQuery< + queryFnData, + error, + data, + queryKey extends QueryKey, +>( + parameters: UseInfiniteQueryParameters & { + queryKey: QueryKey + }, +): UseInfiniteQueryReturnType { + const result = tanstack_useInfiniteQuery({ + ...(parameters as any), + // queryKeyHashFn: hashFn, // for bigint support + }) as UseInfiniteQueryReturnType + result.queryKey = parameters.queryKey + return result +} diff --git a/packages/react/src/types/utils.ts b/packages/react/src/types/utils.ts index 00dabc9b..a07d2df7 100644 --- a/packages/react/src/types/utils.ts +++ b/packages/react/src/types/utils.ts @@ -1,7 +1,96 @@ -export type MaybeArray = T | T[] +// Copied from https://github.com/wevm/wagmi/blob/main/packages/core/src/types/utils.ts#L10 +/** Combines members of an intersection into a readable type. */ +// https://twitter.com/mattpocockuk/status/1622730173446557697?s=20&t=NdpAcmEFXY01xkqU3KO0Mg +export type Evaluate = { [key in keyof type]: type[key] } & unknown + +/** + * Makes all properties of an object optional. + * + * Compatible with [`exactOptionalPropertyTypes`](https://www.typescriptlang.org/tsconfig#exactOptionalPropertyTypes). + */ +export type ExactPartial = { + [key in keyof type]?: type[key] | undefined +} + +/** Checks if {@link type} can be narrowed further than {@link type2} */ +export type IsNarrowable = IsUnknown extends true + ? false + : undefined extends type + ? false + : IsNever< + (type extends type2 ? true : false) & (type2 extends type ? false : true) + > extends true + ? false + : true + +/** + * @internal + * Checks if {@link type} is `never` + */ +export type IsNever = [type] extends [never] ? true : false -export type Prettify = { [key in keyof type]: type[key] } & {} +/** + * @internal + * Checks if {@link type} is `unknown` + */ +export type IsUnknown = unknown extends type ? true : false -export type WithArgs = { - args: Prettify> | undefined +/** Merges two object types into new type */ +export type Merge = Evaluate< + LooseOmit & + obj2 +> + +/** Removes `readonly` from all properties of an object. */ +export type Mutable = { + -readonly [key in keyof type]: type[key] } + +/** Strict version of built-in Omit type */ +export type Omit = Pick< + type, + Exclude +> + +/** Makes objects destructurable. */ +export type OneOf< + union extends object, + /// + keys extends KeyofUnion = KeyofUnion, +> = union extends infer Item + ? Evaluate]?: undefined }> + : never +type KeyofUnion = type extends type ? keyof type : never + +/** Makes {@link key} optional in {@link type} while preserving type inference. */ +// s/o trpc (https://github.com/trpc/trpc/blob/main/packages/server/src/types.ts#L6) +export type PartialBy = ExactPartial< + Pick +> & + Omit + +/////////////////////////////////////////////////////////////////////////// +// Loose types + +/** Loose version of {@link Omit} */ +export type LooseOmit = Pick< + type, + Exclude +> + +/////////////////////////////////////////////////////////////////////////// +// Union types + +export type UnionEvaluate = type extends object ? Evaluate : type + +export type UnionLooseOmit = type extends any + ? LooseOmit + : never + +export type UnionOmit = type extends any + ? Omit + : never + +export type UnionPartial = type extends object ? ExactPartial : type + +export type MaybeArray = T | T[] diff --git a/packages/react/src/utils/use-abstract-client.ts b/packages/react/src/utils/use-abstract-client.ts index 52b2d528..f0157f5a 100644 --- a/packages/react/src/utils/use-abstract-client.ts +++ b/packages/react/src/utils/use-abstract-client.ts @@ -5,10 +5,10 @@ import { graphqlRequest, } from '@abstract-money/core/legacy' import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { UseQueryOptions, useQuery } from '@tanstack/react-query' import React from 'react' -import { useConfig } from 'src/contexts' -import { useSenderAddress, useSigningCosmWasmClient } from 'src/hooks' +import { useConfig } from '../contexts' +import { useSenderAddress, useSigningCosmWasmClient } from '../hooks' +import { UseQueryParameters, useQuery } from '../types/queries' export async function getAbstractClient({ sender, @@ -43,28 +43,26 @@ export async function getAbstractClient({ ) } -export function useAbstractClient( - { - chainName, - }: { - chainName: string | undefined - }, - { - enabled: enabled_ = true, - ...rest - }: UseQueryOptions< - AbstractClient | undefined, - unknown, - AbstractClient | undefined, - readonly [ - 'abstract-client', - string | undefined, - string | undefined, - string, - SigningCosmWasmClient | undefined, - ] - > = {}, -) { +export type UseAbstractClientParameters = + | { + chainName?: string | undefined + query?: UseQueryParameters< + AbstractClient | undefined, + unknown, + AbstractClient | undefined, + readonly [ + 'abstract-client', + string | undefined, + string | undefined, + string, + SigningCosmWasmClient | undefined, + ] + > + } + | never + +export function useAbstractClient(parameters: UseAbstractClientParameters) { + const { chainName, query = {} } = parameters ?? {} const { apiUrl } = useConfig() const { @@ -98,14 +96,13 @@ export function useAbstractClient( }) }, [client, chainName, apiUrl]) - const enabled = React.useMemo( - () => Boolean(client && chainName && enabled_), - [enabled_, client, chainName], - ) + const enabled = Boolean(client && chainName && (query.enabled ?? true)) - const { data, isLoading, isError, error } = useQuery(queryKey, queryFn, { + const { data, isLoading, isError, error } = useQuery({ + queryKey, + queryFn, + ...query, enabled, - ...rest, }) if (isSigningCosmWasmClientError) diff --git a/packages/react/src/utils/use-abstract-module-client.ts b/packages/react/src/utils/use-abstract-module-client.ts index 9c661bbe..0b524ce6 100644 --- a/packages/react/src/utils/use-abstract-module-client.ts +++ b/packages/react/src/utils/use-abstract-module-client.ts @@ -6,7 +6,7 @@ import { AbstractClient, accountIdToLegacyAccountId, } from '@abstract-money/core/legacy' -import { UseQueryOptions, useQuery } from '@tanstack/react-query' +import { UseQueryParameters, useQuery } from '../types/queries' import { useAbstractClient } from './use-abstract-client' interface AbstractModuleClientConstructor { @@ -46,18 +46,13 @@ async function getAbstractModuleClient< }) as InstanceType } -export function useAbstractModuleClient< +export type UseAbstractModuleClientParameters< TModule extends AbstractModuleClientConstructor, ->( - parameters: { - accountId: AccountId | undefined - moduleId: string - Module: TModule - }, - { - enabled: enabled_ = true, - ...rest - }: UseQueryOptions< +> = { + accountId: AccountId | undefined + moduleId: string + Module: TModule + query?: UseQueryParameters< InstanceType | undefined, unknown, InstanceType | undefined, @@ -68,19 +63,26 @@ export function useAbstractModuleClient< TModule, AbstractClient | undefined, ] - > = {}, -) { - const { moduleId, accountId, Module } = parameters + > +} +export function useAbstractModuleClient< + TModule extends AbstractModuleClientConstructor, +>({ + moduleId, + accountId, + Module, + query = {}, +}: UseAbstractModuleClientParameters) { const { data: abstractClient, isLoading: isAbstractClientLoading, isError: isAbstractClientError, error: abstractClientError, - } = useAbstractClient( - { chainName: accountId?.chainName }, - { enabled: enabled_ }, - ) + } = useAbstractClient({ + chainName: accountId?.chainName, + query: { enabled: query.enabled ?? true }, + }) const queryKey = React.useMemo( () => @@ -106,9 +108,8 @@ export function useAbstractModuleClient< }) }, [abstractClient, accountId, moduleId, Module]) - const enabled = React.useMemo( - () => Boolean(abstractClient && accountId && enabled_), - [enabled_, abstractClient, accountId], + const enabled = Boolean( + abstractClient && accountId && (query.enabled ?? true), ) const { @@ -116,7 +117,7 @@ export function useAbstractModuleClient< isLoading: isAbstractModuleClientLoading, isError: isAbstractModuleClientError, error: abstractModuleClientError, - } = useQuery(queryKey, queryFn, { enabled, ...rest }) + } = useQuery({ queryKey, queryFn, ...query, enabled }) if (isAbstractClientError) return { diff --git a/packages/react/src/utils/use-abstract-module-query-client.ts b/packages/react/src/utils/use-abstract-module-query-client.ts index 510551ef..912261f8 100644 --- a/packages/react/src/utils/use-abstract-module-query-client.ts +++ b/packages/react/src/utils/use-abstract-module-query-client.ts @@ -6,8 +6,8 @@ import { AbstractQueryClient, accountIdToLegacyAccountId, } from '@abstract-money/core/legacy' -import { UseQueryOptions, useQuery } from '@tanstack/react-query' import { useConfig } from '../contexts' +import { UseQueryParameters, useQuery } from '../types/queries' import { useAbstractQueryClient } from './use-abstract-query-client' interface AbstractModuleQueryClientConstructor { @@ -62,25 +62,28 @@ type TQueryKey = AbstractQueryClient | undefined, ] -export function useAbstractModuleQueryClient< +export type UseAbstractModuleQueryClientParameters< TModule extends AbstractModuleQueryClientConstructor, ->( - parameters: { - accountId: AccountId | undefined - moduleId: string - Module: TModule - }, - { - enabled: enabled_ = true, - ...rest - }: UseQueryOptions< +> = { + accountId: AccountId | undefined + moduleId: string + Module: TModule + query?: UseQueryParameters< TQueryFnData, unknown, TQueryData, TQueryKey - > = {}, -) { - const { moduleId, accountId, Module } = parameters + > +} + +export function useAbstractModuleQueryClient< + TModule extends AbstractModuleQueryClientConstructor, +>({ + accountId, + moduleId, + Module, + query = {}, +}: UseAbstractModuleQueryClientParameters) { const { apiUrl } = useConfig() const { @@ -88,10 +91,10 @@ export function useAbstractModuleQueryClient< isLoading: isAbstractClientLoading, isError: isAbstractClientError, error: abstractClientError, - } = useAbstractQueryClient( - { chainName: accountId?.chainName }, - { enabled: enabled_ }, - ) + } = useAbstractQueryClient({ + chainName: accountId?.chainName, + query: { enabled: query.enabled ?? true }, + }) const queryKey = React.useMemo( () => @@ -118,9 +121,8 @@ export function useAbstractModuleQueryClient< }) }, [abstractQueryClient, apiUrl, accountId, moduleId, Module]) - const enabled = React.useMemo( - () => Boolean(abstractQueryClient && accountId && enabled_), - [enabled_, abstractQueryClient, accountId], + const enabled = Boolean( + abstractQueryClient && accountId && (query.enabled ?? true), ) const { @@ -128,7 +130,7 @@ export function useAbstractModuleQueryClient< isLoading: isAbstractModuleQueryClientLoading, isError: isAbstractModuleQueryClientError, error: abstractModuleQueryClientError, - } = useQuery(queryKey, queryFn, { enabled, ...rest }) + } = useQuery({ queryKey, queryFn, ...query, enabled }) if (isAbstractClientError) return { diff --git a/packages/react/src/utils/use-abstract-query-client.ts b/packages/react/src/utils/use-abstract-query-client.ts index 909fc051..ff663c2f 100644 --- a/packages/react/src/utils/use-abstract-query-client.ts +++ b/packages/react/src/utils/use-abstract-query-client.ts @@ -5,10 +5,10 @@ import { graphqlRequest, } from '@abstract-money/core/legacy' import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { UseQueryOptions, useQuery } from '@tanstack/react-query' import React from 'react' -import { useConfig } from 'src/contexts' -import { useCosmWasmClient } from 'src/hooks' +import { useConfig } from '../contexts' +import { useCosmWasmClient } from '../hooks' +import { UseQueryParameters, useQuery } from '../types/queries' async function getAbstractQueryClient({ client, @@ -40,16 +40,9 @@ async function getAbstractQueryClient({ ) } -export function useAbstractQueryClient( - { - chainName, - }: { - chainName: string | undefined - }, - { - enabled: enabled_ = true, - ...rest - }: UseQueryOptions< +export type UseAbstractQueryClientParameters = { + chainName?: string | undefined + query?: UseQueryParameters< AbstractQueryClient | undefined, unknown, AbstractQueryClient | undefined, @@ -59,8 +52,13 @@ export function useAbstractQueryClient( string, CosmWasmClient | undefined, ] - > = {}, -) { + > +} + +export function useAbstractQueryClient({ + chainName, + query = {}, +}: UseAbstractQueryClientParameters) { const { apiUrl } = useConfig() const { @@ -86,14 +84,13 @@ export function useAbstractQueryClient( }) }, [client, chainName, apiUrl]) - const enabled = React.useMemo( - () => Boolean(client && chainName && enabled_), - [enabled_, client, chainName], - ) + const enabled = Boolean(client && chainName && (query.enabled ?? true)) - const { data, isLoading, isError, error } = useQuery(queryKey, queryFn, { + const { data, isLoading, isError, error } = useQuery({ + queryKey, + queryFn, + ...query, enabled, - ...rest, }) if (isCosmWasmClientError) From 427df38fca98c540c54ce77f17f0b6751c5f3112 Mon Sep 17 00:00:00 2001 From: hotwater Date: Thu, 14 Mar 2024 18:27:11 +0200 Subject: [PATCH 2/2] fix: `args` to be present in mutations --- .../src/_generated/index.ts | 84 ++++++++----------- .../src/_generated/index.ts | 84 ++++++++----------- .../src/app/authz-osmosis/page.tsx | 20 ++--- packages/cli/src/plugins/react.ts | 6 +- packages/react/src/create-config.ts | 16 ++-- .../account/wallet/use-create-sub-account.ts | 11 +-- .../src/hooks/account/wallet/use-deposit.ts | 9 +- .../src/hooks/account/wallet/use-execute.ts | 9 +- .../src/hooks/account/wallet/use-withdraw.ts | 9 +- .../wallet/use-create-account-monarchy.ts | 14 ++-- .../src/hooks/wallet/use-create-account.ts | 9 +- .../wallet/utils/use-sign-and-broadcast.ts | 2 +- packages/react/src/types/args.ts | 21 ++++- 13 files changed, 150 insertions(+), 144 deletions(-) diff --git a/examples/wagemos-cosmoskit-nextjs/src/_generated/index.ts b/examples/wagemos-cosmoskit-nextjs/src/_generated/index.ts index 38c19b24..a5220b37 100644 --- a/examples/wagemos-cosmoskit-nextjs/src/_generated/index.ts +++ b/examples/wagemos-cosmoskit-nextjs/src/_generated/index.ts @@ -66,14 +66,12 @@ export const betting = { isLoading: isBettingAppQueryClientLoading, isError: isBettingAppQueryClientError, error: bettingAppQueryClientError, - } = useAbstractModuleQueryClient( - { - moduleId: BETTING_MODULE_ID, - ...rest, - Module: BettingAppQueryClient, - }, - { enabled: options?.enabled }, - ) + } = useAbstractModuleQueryClient({ + moduleId: BETTING_MODULE_ID, + ...rest, + Module: BettingAppQueryClient, + query: { enabled: options?.enabled }, + }) const { data, @@ -128,14 +126,12 @@ export const betting = { isLoading: isBettingAppQueryClientLoading, isError: isBettingAppQueryClientError, error: bettingAppQueryClientError, - } = useAbstractModuleQueryClient( - { - moduleId: BETTING_MODULE_ID, - ...rest, - Module: BettingAppQueryClient, - }, - { enabled: options?.enabled }, - ) + } = useAbstractModuleQueryClient({ + moduleId: BETTING_MODULE_ID, + ...rest, + Module: BettingAppQueryClient, + query: { enabled: options?.enabled }, + }) const { data, @@ -192,14 +188,12 @@ export const betting = { isLoading: isBettingAppQueryClientLoading, isError: isBettingAppQueryClientError, error: bettingAppQueryClientError, - } = useAbstractModuleQueryClient( - { - moduleId: BETTING_MODULE_ID, - ...rest, - Module: BettingAppQueryClient, - }, - { enabled: options?.enabled }, - ) + } = useAbstractModuleQueryClient({ + moduleId: BETTING_MODULE_ID, + ...rest, + Module: BettingAppQueryClient, + query: { enabled: options?.enabled }, + }) const { data, @@ -255,14 +249,12 @@ export const betting = { isLoading: isBettingAppQueryClientLoading, isError: isBettingAppQueryClientError, error: bettingAppQueryClientError, - } = useAbstractModuleQueryClient( - { - moduleId: BETTING_MODULE_ID, - ...rest, - Module: BettingAppQueryClient, - }, - { enabled: options?.enabled }, - ) + } = useAbstractModuleQueryClient({ + moduleId: BETTING_MODULE_ID, + ...rest, + Module: BettingAppQueryClient, + query: { enabled: options?.enabled }, + }) const { data, @@ -320,14 +312,12 @@ export const betting = { isLoading: isBettingAppQueryClientLoading, isError: isBettingAppQueryClientError, error: bettingAppQueryClientError, - } = useAbstractModuleQueryClient( - { - moduleId: BETTING_MODULE_ID, - ...rest, - Module: BettingAppQueryClient, - }, - { enabled: options?.enabled }, - ) + } = useAbstractModuleQueryClient({ + moduleId: BETTING_MODULE_ID, + ...rest, + Module: BettingAppQueryClient, + query: { enabled: options?.enabled }, + }) const { data, @@ -383,14 +373,12 @@ export const betting = { isLoading: isBettingAppQueryClientLoading, isError: isBettingAppQueryClientError, error: bettingAppQueryClientError, - } = useAbstractModuleQueryClient( - { - moduleId: BETTING_MODULE_ID, - ...rest, - Module: BettingAppQueryClient, - }, - { enabled: options?.enabled }, - ) + } = useAbstractModuleQueryClient({ + moduleId: BETTING_MODULE_ID, + ...rest, + Module: BettingAppQueryClient, + query: { enabled: options?.enabled }, + }) const { data, diff --git a/examples/wagemos-graz-nextjs/src/_generated/index.ts b/examples/wagemos-graz-nextjs/src/_generated/index.ts index 38c19b24..a5220b37 100644 --- a/examples/wagemos-graz-nextjs/src/_generated/index.ts +++ b/examples/wagemos-graz-nextjs/src/_generated/index.ts @@ -66,14 +66,12 @@ export const betting = { isLoading: isBettingAppQueryClientLoading, isError: isBettingAppQueryClientError, error: bettingAppQueryClientError, - } = useAbstractModuleQueryClient( - { - moduleId: BETTING_MODULE_ID, - ...rest, - Module: BettingAppQueryClient, - }, - { enabled: options?.enabled }, - ) + } = useAbstractModuleQueryClient({ + moduleId: BETTING_MODULE_ID, + ...rest, + Module: BettingAppQueryClient, + query: { enabled: options?.enabled }, + }) const { data, @@ -128,14 +126,12 @@ export const betting = { isLoading: isBettingAppQueryClientLoading, isError: isBettingAppQueryClientError, error: bettingAppQueryClientError, - } = useAbstractModuleQueryClient( - { - moduleId: BETTING_MODULE_ID, - ...rest, - Module: BettingAppQueryClient, - }, - { enabled: options?.enabled }, - ) + } = useAbstractModuleQueryClient({ + moduleId: BETTING_MODULE_ID, + ...rest, + Module: BettingAppQueryClient, + query: { enabled: options?.enabled }, + }) const { data, @@ -192,14 +188,12 @@ export const betting = { isLoading: isBettingAppQueryClientLoading, isError: isBettingAppQueryClientError, error: bettingAppQueryClientError, - } = useAbstractModuleQueryClient( - { - moduleId: BETTING_MODULE_ID, - ...rest, - Module: BettingAppQueryClient, - }, - { enabled: options?.enabled }, - ) + } = useAbstractModuleQueryClient({ + moduleId: BETTING_MODULE_ID, + ...rest, + Module: BettingAppQueryClient, + query: { enabled: options?.enabled }, + }) const { data, @@ -255,14 +249,12 @@ export const betting = { isLoading: isBettingAppQueryClientLoading, isError: isBettingAppQueryClientError, error: bettingAppQueryClientError, - } = useAbstractModuleQueryClient( - { - moduleId: BETTING_MODULE_ID, - ...rest, - Module: BettingAppQueryClient, - }, - { enabled: options?.enabled }, - ) + } = useAbstractModuleQueryClient({ + moduleId: BETTING_MODULE_ID, + ...rest, + Module: BettingAppQueryClient, + query: { enabled: options?.enabled }, + }) const { data, @@ -320,14 +312,12 @@ export const betting = { isLoading: isBettingAppQueryClientLoading, isError: isBettingAppQueryClientError, error: bettingAppQueryClientError, - } = useAbstractModuleQueryClient( - { - moduleId: BETTING_MODULE_ID, - ...rest, - Module: BettingAppQueryClient, - }, - { enabled: options?.enabled }, - ) + } = useAbstractModuleQueryClient({ + moduleId: BETTING_MODULE_ID, + ...rest, + Module: BettingAppQueryClient, + query: { enabled: options?.enabled }, + }) const { data, @@ -383,14 +373,12 @@ export const betting = { isLoading: isBettingAppQueryClientLoading, isError: isBettingAppQueryClientError, error: bettingAppQueryClientError, - } = useAbstractModuleQueryClient( - { - moduleId: BETTING_MODULE_ID, - ...rest, - Module: BettingAppQueryClient, - }, - { enabled: options?.enabled }, - ) + } = useAbstractModuleQueryClient({ + moduleId: BETTING_MODULE_ID, + ...rest, + Module: BettingAppQueryClient, + query: { enabled: options?.enabled }, + }) const { data, diff --git a/examples/wagemos-graz-nextjs/src/app/authz-osmosis/page.tsx b/examples/wagemos-graz-nextjs/src/app/authz-osmosis/page.tsx index f9217a95..b4500767 100644 --- a/examples/wagemos-graz-nextjs/src/app/authz-osmosis/page.tsx +++ b/examples/wagemos-graz-nextjs/src/app/authz-osmosis/page.tsx @@ -36,10 +36,10 @@ export default function AuthzPage() { const { data: account } = useAccount({ chainId: 'osmosis-1' }) const { data: accountFactory, isLoading } = - useAccountFactoryQueryClientFromApi(CHAIN_NAME) + useAccountFactoryQueryClientFromApi({ chainName: CHAIN_NAME, args: {} }) const { mutate: createAccount } = useCreateAccountMonarchy({ - args: { chainName: CHAIN_NAME }, + chainName: CHAIN_NAME, }) const onCreateAccount = useCallback(async () => { @@ -59,17 +59,13 @@ export default function AuthzPage() { }) }, [accountFactory]) - const { data: savingsAppAddress } = useModuleInstantiate2AddressFromApi( - { - accountId: stringToAccountId(TEST_SAVINGS_ACCOUNT_ID, CHAIN_NAME), - args: { - moduleId: SAVINGS_APP_MODULE_ID, - }, + const { data: savingsAppAddress } = useModuleInstantiate2AddressFromApi({ + accountId: stringToAccountId(TEST_SAVINGS_ACCOUNT_ID, CHAIN_NAME), + args: { + moduleId: SAVINGS_APP_MODULE_ID, }, - { - enabled: true, - }, - ) + query: { enabled: true }, + }) console.log('calculated savings app address', savingsAppAddress) diff --git a/packages/cli/src/plugins/react.ts b/packages/cli/src/plugins/react.ts index 84756380..6ecb974b 100644 --- a/packages/cli/src/plugins/react.ts +++ b/packages/cli/src/plugins/react.ts @@ -311,8 +311,12 @@ export function react(options: ReactOptions = {}): ReactResult { } ...rest, Module: ${queryClientPascalCase}, + ${ + hasAbstractApp + ? 'query: { enabled: options?.enabled }' + : '' + } }, - ${hasAbstractApp ? '{ enabled: options?.enabled }' : ''} ) const { diff --git a/packages/react/src/create-config.ts b/packages/react/src/create-config.ts index 93de5892..d6106c67 100644 --- a/packages/react/src/create-config.ts +++ b/packages/react/src/create-config.ts @@ -17,7 +17,7 @@ import { SigningCosmWasmClient, } from '@cosmjs/cosmwasm-stargate' import { useMemo } from 'react' -import { Prettify } from './types/args' +import { Evaluate } from './types/utils' type CommonProviderArgs = { chainName: string | undefined @@ -54,7 +54,7 @@ export function createConfig(parameters: CreateConfigParameters) { } function usePublicClient( - ...args: Prettify> + ...args: Evaluate> ): PublicClient | undefined { const cosmWasmClient = provider.useCosmWasmClient(...args) return useMemo(() => { @@ -67,7 +67,7 @@ export function createConfig(parameters: CreateConfigParameters) { } function useWalletClient( - ...args: Prettify> + ...args: Evaluate> ): WalletClient | undefined { const signingCosmWasmClient = provider.useSigningCosmWasmClient(...args) const sender = provider.useSenderAddress(...args) @@ -84,7 +84,7 @@ export function createConfig(parameters: CreateConfigParameters) { function useAccountPublicClient({ accountId, ...rest - }: Prettify< + }: Evaluate< { accountId: AccountId | undefined } & Parameters< Provider['useCosmWasmClient'] >[0] @@ -103,7 +103,7 @@ export function createConfig(parameters: CreateConfigParameters) { function useAccountWalletClient({ accountId, ...rest - }: Prettify< + }: Evaluate< { accountId: AccountId | undefined } & Parameters< Provider['useSigningCosmWasmClient'] >[0] @@ -140,17 +140,17 @@ export type Config = { ...args: Parameters ): PublicClient | undefined useWalletClient( - ...args: Prettify> + ...args: Evaluate> ): WalletClient | undefined useAccountPublicClient( - args: Prettify< + args: Evaluate< { accountId: AccountId | undefined } & Parameters< Provider['useCosmWasmClient'] >[0] >, ): AccountPublicClient | undefined useAccountWalletClient( - args: Prettify< + args: Evaluate< { accountId: AccountId | undefined } & Parameters< Provider['useCosmWasmClient'] >[0] diff --git a/packages/react/src/hooks/account/wallet/use-create-sub-account.ts b/packages/react/src/hooks/account/wallet/use-create-sub-account.ts index 6ab6b98d..12c8ab0a 100644 --- a/packages/react/src/hooks/account/wallet/use-create-sub-account.ts +++ b/packages/react/src/hooks/account/wallet/use-create-sub-account.ts @@ -2,11 +2,12 @@ import { AccountWalletClient } from '@abstract-money/core/clients' import { AccountId } from '@abstract-money/core/utils' import { useMutation } from '@tanstack/react-query' import { useConfig } from '../../../contexts' +import { ExtractArgsFromParameters } from '../../../types/args' import { UseMutationParameters } from '../../../types/queries' -type CreateSubAccountMutation = Parameters< - AccountWalletClient['createSubAccount'] ->[0] +type CreateSubAccountMutation = ExtractArgsFromParameters< + Parameters[0] +> export type UseCreateSubAccountParameters = { accountId: AccountId | undefined @@ -27,8 +28,8 @@ export function useCreateSubAccount({ accountId, }) - return useMutation((parameters) => { + return useMutation(({ args, ...cosmWasmSignOptions }) => { if (!walletClient) throw new Error('walletClient is not defined') - return walletClient.createSubAccount(parameters) + return walletClient.createSubAccount({ ...cosmWasmSignOptions, ...args }) }, mutation) } diff --git a/packages/react/src/hooks/account/wallet/use-deposit.ts b/packages/react/src/hooks/account/wallet/use-deposit.ts index 0c2cf940..5c97fc61 100644 --- a/packages/react/src/hooks/account/wallet/use-deposit.ts +++ b/packages/react/src/hooks/account/wallet/use-deposit.ts @@ -3,12 +3,15 @@ import { AccountId } from '@abstract-money/core/utils' import { DeliverTxResponse } from '@cosmjs/stargate' import { useMutation } from '@tanstack/react-query' import { useConfig } from '../../../contexts' +import { ExtractArgsFromParameters } from '../../../types/args' import { UseMutationParameters, UseMutationReturnType, } from '../../../types/queries' -type DepositMutation = Parameters[0] +type DepositMutation = ExtractArgsFromParameters< + Parameters[0] +> export type UseDepositParameters = { accountId: AccountId | undefined @@ -32,8 +35,8 @@ export function useDeposit({ accountId, chainName: accountId?.chainName, }) - return useMutation(({ ...rest }) => { + return useMutation(({ args, ...cosmWasmSignOptions }) => { if (!accountWalletClient) throw new Error('client is not defined') - return accountWalletClient.deposit(rest) + return accountWalletClient.deposit({ ...args, ...cosmWasmSignOptions }) }, mutation) } diff --git a/packages/react/src/hooks/account/wallet/use-execute.ts b/packages/react/src/hooks/account/wallet/use-execute.ts index 15bb7429..59bc476f 100644 --- a/packages/react/src/hooks/account/wallet/use-execute.ts +++ b/packages/react/src/hooks/account/wallet/use-execute.ts @@ -3,12 +3,15 @@ import { AccountId } from '@abstract-money/core/utils' import { DeliverTxResponse } from '@cosmjs/stargate' import { useMutation } from '@tanstack/react-query' import { useConfig } from '../../../contexts' +import { ExtractArgsFromParameters } from '../../../types/args' import { UseMutationParameters, UseMutationReturnType, } from '../../../types/queries' -type ExecuteMutation = Parameters[0] +type ExecuteMutation = ExtractArgsFromParameters< + Parameters[0] +> export type UseExecuteParameters = { accountId: AccountId | undefined @@ -27,8 +30,8 @@ export function useExecute({ chainName: accountId?.chainName, accountId, }) - return useMutation(({ ...rest }) => { + return useMutation(({ args, ...cosmWasmSignOptions }) => { if (!accountWalletClient) throw new Error('client is not defined') - return accountWalletClient.execute(rest) + return accountWalletClient.execute({ ...cosmWasmSignOptions, ...args }) }, mutation) } diff --git a/packages/react/src/hooks/account/wallet/use-withdraw.ts b/packages/react/src/hooks/account/wallet/use-withdraw.ts index 3eeff35b..4cd4bb11 100644 --- a/packages/react/src/hooks/account/wallet/use-withdraw.ts +++ b/packages/react/src/hooks/account/wallet/use-withdraw.ts @@ -3,12 +3,15 @@ import { AccountId } from '@abstract-money/core/utils' import { DeliverTxResponse } from '@cosmjs/stargate' import { useMutation } from '@tanstack/react-query' import { useConfig } from '../../../contexts' +import { ExtractArgsFromParameters } from '../../../types/args' import { UseMutationParameters, UseMutationReturnType, } from '../../../types/queries' -type WithdrawMutation = Parameters[0] +type WithdrawMutation = ExtractArgsFromParameters< + Parameters[0] +> export type UseWithdrawParameters = { accountId: AccountId | undefined @@ -32,8 +35,8 @@ export function useWithdraw({ chainName: accountId?.chainName, accountId, }) - return useMutation(({ ...rest }) => { + return useMutation(({ args, ...cosmWasmSignOptions }) => { if (!accountWalletClient) throw new Error('client is not defined') - return accountWalletClient.withdraw(rest) + return accountWalletClient.withdraw({ ...args, ...cosmWasmSignOptions }) }, mutation) } diff --git a/packages/react/src/hooks/wallet/use-create-account-monarchy.ts b/packages/react/src/hooks/wallet/use-create-account-monarchy.ts index f6a328e0..66210aa4 100644 --- a/packages/react/src/hooks/wallet/use-create-account-monarchy.ts +++ b/packages/react/src/hooks/wallet/use-create-account-monarchy.ts @@ -1,11 +1,12 @@ import { WalletClient } from '@abstract-money/core' import { useMutation } from '@tanstack/react-query' import { useConfig } from '../../contexts' +import { ExtractArgsFromParameters } from '../../types/args' import { UseMutationParameters } from '../../types/queries' -type CreateAccountMonarchyMutation = Parameters< - WalletClient['createAccountMonarchy'] ->[0] +type CreateAccountMonarchyMutation = ExtractArgsFromParameters< + Parameters[0] +> export type UseCreateAccountMonarchyParameters = { chainName: string | undefined @@ -23,8 +24,11 @@ export function useCreateAccountMonarchy({ const config = useConfig() const walletClient = config.useWalletClient({ chainName: chainName }) - return useMutation((parameters) => { + return useMutation(({ args, ...cosmWasmSignOptions }) => { if (!walletClient) throw new Error('walletClient is not defined') - return walletClient.createAccountMonarchy(parameters) + return walletClient.createAccountMonarchy({ + ...args, + ...cosmWasmSignOptions, + }) }, mutation) } diff --git a/packages/react/src/hooks/wallet/use-create-account.ts b/packages/react/src/hooks/wallet/use-create-account.ts index 96038ede..59bc045c 100644 --- a/packages/react/src/hooks/wallet/use-create-account.ts +++ b/packages/react/src/hooks/wallet/use-create-account.ts @@ -1,9 +1,12 @@ import { WalletClient } from '@abstract-money/core' import { useMutation } from '@tanstack/react-query' import { useConfig } from '../../contexts' +import { ExtractArgsFromParameters } from '../../types/args' import { UseMutationParameters } from '../../types/queries' -type CreateAccountMutation = Parameters[0] +type CreateAccountMutation = ExtractArgsFromParameters< + Parameters[0] +> export type UseCreateAccount = { chainName: string | undefined @@ -18,8 +21,8 @@ export function useCreateAccount({ chainName, mutation }: UseCreateAccount) { const config = useConfig() const walletClient = config.useWalletClient({ chainName: chainName }) - return useMutation((parameters) => { + return useMutation(({ args, ...cosmWasmSignOptions }) => { if (!walletClient) throw new Error('walletClient is not defined') - return walletClient.createAccount(parameters) + return walletClient.createAccount({ ...args, ...cosmWasmSignOptions }) }, mutation) } diff --git a/packages/react/src/hooks/wallet/utils/use-sign-and-broadcast.ts b/packages/react/src/hooks/wallet/utils/use-sign-and-broadcast.ts index 949510db..282613ba 100644 --- a/packages/react/src/hooks/wallet/utils/use-sign-and-broadcast.ts +++ b/packages/react/src/hooks/wallet/utils/use-sign-and-broadcast.ts @@ -8,7 +8,7 @@ import { useSigningCosmWasmClient } from '../use-signing-cosm-wasm-client' type SignAndBroadcastMutation = { readonly fee: number | StdFee | 'auto' readonly memo?: string | undefined - args: { + readonly args: { messages: readonly EncodeObject[] } } diff --git a/packages/react/src/types/args.ts b/packages/react/src/types/args.ts index bdebc2c3..033b9efa 100644 --- a/packages/react/src/types/args.ts +++ b/packages/react/src/types/args.ts @@ -1,7 +1,20 @@ -import { type Evaluate } from './utils' +import { Coin, StdFee } from '@cosmjs/stargate' +import { type Evaluate, Omit } from './utils' -export type WithArgs = { - args: Evaluate> | undefined +export type WithArgs = { + args: Evaluate> | undefined } -export type ExtractArgs = TParameters['args'] +export type ExtractArgsFromParameters< + parameters extends { + readonly fee: number | StdFee | 'auto' + readonly memo?: string + readonly funds?: (Coin & { [key: string]: string })[] + }, +> = Evaluate< + Pick & { + args: Evaluate> + } +> + +export type ExtractArgs = parameters['args']