Skip to content

Commit

Permalink
feat!: api changes to core and react packages
Browse files Browse the repository at this point in the history
  • Loading branch information
dalechyn committed Mar 13, 2024
1 parent 48cdc3b commit 8ac578d
Show file tree
Hide file tree
Showing 115 changed files with 1,907 additions and 1,429 deletions.
9 changes: 9 additions & 0 deletions .changeset/strange-clocks-return.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions packages/core/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated file. Do not edit directly.
actions/**
clients/**
utils/**
legacy/**
5 changes: 5 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -94,6 +98,7 @@
"./package.json": "./package.json"
},
"files": [
"/actions",
"/clients",
"/utils",
"/legacy",
Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
17 changes: 8 additions & 9 deletions packages/core/src/actions/account/public/get-base-token.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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))
Expand Down
13 changes: 0 additions & 13 deletions packages/core/src/actions/account/public/get-cosm-wasm-client.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 })
}
18 changes: 9 additions & 9 deletions packages/core/src/actions/account/public/get-module-address.ts
Original file line number Diff line number Diff line change
@@ -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] })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 12 additions & 14 deletions packages/core/src/actions/account/public/get-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof ManagerQueryClient.prototype.moduleInfos>[0]
>
export type GetModulesParameters = {
accountId: VersionControlTypes.AccountId
cosmWasmClient: CosmWasmClient
apiUrl: string
} & Parameters<typeof ManagerQueryClient.prototype.moduleInfos>[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)

Expand Down
15 changes: 7 additions & 8 deletions packages/core/src/actions/account/public/get-namespace.ts
Original file line number Diff line number Diff line change
@@ -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<string | null> {
const versionControlQueryClient = await getVersionControlQueryClientFromApi({
args: {
cosmWasmClient,
apiUrl,
},
cosmWasmClient,
apiUrl,
})
const namespace = await versionControlQueryClient
.namespaces({ accounts: [accountIdToParameter(accountId)] })
Expand Down
17 changes: 8 additions & 9 deletions packages/core/src/actions/account/public/get-owner.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
Loading

0 comments on commit 8ac578d

Please sign in to comment.