Skip to content

Commit cc3086d

Browse files
committed
refactor: change input api for core
1 parent a5a5c8a commit cc3086d

File tree

58 files changed

+1338
-744
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1338
-744
lines changed

packages/core/src/actions/account/public/get-account-base-addresses-from-api.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'
2+
import { WithArgs } from 'src/types/with-args'
23
import { VersionControlTypes } from '../../../codegen/abstract'
34
import { accountIdToParameter } from '../../../utils/account-id'
45
import { getVersionControlQueryClientFromApi } from '../../public/get-version-control-query-client-from-api'
56

6-
export async function getAccountBaseAddressesFromApi(
7-
accountId: VersionControlTypes.AccountId,
8-
cosmWasmClient: CosmWasmClient,
9-
apiUrl: string,
10-
) {
11-
const versionControlQueryClient = await getVersionControlQueryClientFromApi(
12-
cosmWasmClient,
13-
apiUrl,
14-
)
7+
export type GetAccountBaseAddressesFromApiParameters = WithArgs<{
8+
accountId: VersionControlTypes.AccountId
9+
cosmWasmClient: CosmWasmClient
10+
apiUrl: string
11+
}>
12+
13+
export async function getAccountBaseAddressesFromApi({
14+
args: { accountId, cosmWasmClient, apiUrl },
15+
}: GetAccountBaseAddressesFromApiParameters) {
16+
const versionControlQueryClient = await getVersionControlQueryClientFromApi({
17+
args: {
18+
cosmWasmClient,
19+
apiUrl,
20+
},
21+
})
1522
const { account_base: accountBase } =
1623
await versionControlQueryClient.accountBase({
1724
accountId: accountIdToParameter(accountId),

packages/core/src/actions/account/public/get-base-token.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'
2+
import { WithArgs } from 'src/types/with-args'
23
import { CW20Token, NativeToken } from 'src/utils'
34
import { VersionControlTypes } from '../../../codegen/abstract'
45
import { getProxyQueryClientFromApi } from './get-proxy-query-client-from-api'
@@ -11,16 +12,22 @@ function hasCw20Field(base_asset: any): base_asset is { cw20: string } {
1112
return (base_asset as { cw20: string }).cw20 !== undefined
1213
}
1314

14-
export async function getBaseToken(
15-
accountId: VersionControlTypes.AccountId,
16-
cosmWasmClient: CosmWasmClient,
17-
apiUrl: string,
18-
) {
19-
const proxyQueryClient = await getProxyQueryClientFromApi(
20-
accountId,
21-
cosmWasmClient,
22-
apiUrl,
23-
)
15+
export type GetBaseTokenParameters = WithArgs<{
16+
accountId: VersionControlTypes.AccountId
17+
cosmWasmClient: CosmWasmClient
18+
apiUrl: string
19+
}>
20+
21+
export async function getBaseToken({
22+
args: { accountId, cosmWasmClient, apiUrl },
23+
}: GetBaseTokenParameters) {
24+
const proxyQueryClient = await getProxyQueryClientFromApi({
25+
args: {
26+
accountId,
27+
cosmWasmClient,
28+
apiUrl,
29+
},
30+
})
2431
const { base_asset } = await proxyQueryClient.baseAsset()
2532
if (hasNativeField(base_asset))
2633
return {
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'
2+
import { WithArgs } from 'src/types/with-args'
23
import { VersionControlTypes } from '../../../codegen/abstract'
34
import { getManagerQueryClient } from '../../public/get-manager-query-client'
45
import { getAccountBaseAddressesFromApi } from './get-account-base-addresses-from-api'
56

6-
export async function getManagerQueryClientFromApi(
7-
accountId: VersionControlTypes.AccountId,
8-
cosmWasmClient: CosmWasmClient,
9-
apiUrl: string,
10-
) {
11-
const { managerAddress } = await getAccountBaseAddressesFromApi(
12-
accountId,
13-
cosmWasmClient,
14-
apiUrl,
15-
)
7+
export type GetManagerQueryClientFromApiParameters = WithArgs<{
8+
accountId: VersionControlTypes.AccountId
9+
cosmWasmClient: CosmWasmClient
10+
apiUrl: string
11+
}>
12+
export async function getManagerQueryClientFromApi({
13+
args: { accountId, cosmWasmClient, apiUrl },
14+
}: GetManagerQueryClientFromApiParameters) {
15+
const { managerAddress } = await getAccountBaseAddressesFromApi({
16+
args: {
17+
accountId,
18+
cosmWasmClient,
19+
apiUrl,
20+
},
21+
})
1622

17-
return getManagerQueryClient(cosmWasmClient, managerAddress)
23+
return getManagerQueryClient({ args: { cosmWasmClient, managerAddress } })
1824
}

packages/core/src/actions/account/public/get-module-address.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'
2+
import { WithArgs } from 'src/types/with-args'
23
import { VersionControlTypes } from '../../../codegen/abstract'
34
import { getManagerQueryClientFromApi } from './get-manager-query-client-from-api'
45

5-
export async function getModuleAddress(
6-
accountId: VersionControlTypes.AccountId,
7-
cosmWasmClient: CosmWasmClient,
8-
apiUrl: string,
9-
id: string,
10-
) {
11-
const managerQueryClient = await getManagerQueryClientFromApi(
12-
accountId,
13-
cosmWasmClient,
14-
apiUrl,
15-
)
6+
export type GetModuleAddressParameters = WithArgs<{
7+
accountId: VersionControlTypes.AccountId
8+
cosmWasmClient: CosmWasmClient
9+
apiUrl: string
10+
id: string
11+
}>
12+
13+
export async function getModuleAddress({
14+
args: { accountId, cosmWasmClient, apiUrl, id },
15+
}: GetModuleAddressParameters) {
16+
const managerQueryClient = await getManagerQueryClientFromApi({
17+
args: {
18+
accountId,
19+
cosmWasmClient,
20+
apiUrl,
21+
},
22+
})
1623
const { modules } = await managerQueryClient.moduleAddresses({ ids: [id] })
1724

1825
return modules[0]?.[1] ?? null
Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'
2+
import { WithArgs } from 'src/types/with-args'
23
import {
34
ManagerQueryClient,
45
VersionControlTypes,
56
} from '../../../codegen/abstract'
67
import { getManagerQueryClientFromApi } from './get-manager-query-client-from-api'
78

8-
export async function getModules(
9-
accountId: VersionControlTypes.AccountId,
10-
cosmWasmClient: CosmWasmClient,
11-
apiUrl: string,
12-
...params: Parameters<typeof ManagerQueryClient.prototype.moduleInfos>
13-
) {
14-
const managerQueryClient = await getManagerQueryClientFromApi(
15-
accountId,
16-
cosmWasmClient,
17-
apiUrl,
18-
)
19-
const { module_infos: modules } = await managerQueryClient.moduleInfos(
20-
...params,
21-
)
9+
export type GetModulesParameters = WithArgs<
10+
{
11+
accountId: VersionControlTypes.AccountId
12+
cosmWasmClient: CosmWasmClient
13+
apiUrl: string
14+
} & Parameters<typeof ManagerQueryClient.prototype.moduleInfos>[0]
15+
>
16+
17+
export async function getModules({
18+
args: { accountId, cosmWasmClient, apiUrl, ...params },
19+
}: GetModulesParameters) {
20+
const managerQueryClient = await getManagerQueryClientFromApi({
21+
args: {
22+
accountId,
23+
cosmWasmClient,
24+
apiUrl,
25+
},
26+
})
27+
const { module_infos: modules } = await managerQueryClient.moduleInfos(params)
2228

2329
return modules
2430
}

packages/core/src/actions/account/public/get-namespace.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'
2+
import { WithArgs } from 'src/types/with-args'
23
import { VersionControlTypes } from '../../../codegen/abstract'
34
import { accountIdToParameter } from '../../../utils/account-id'
45
import { getVersionControlQueryClientFromApi } from '../../public/get-version-control-query-client-from-api'
56

6-
export async function getNamespace(
7-
accountId: VersionControlTypes.AccountId,
8-
cosmWasmClient: CosmWasmClient,
9-
apiUrl: string,
10-
): Promise<string | null> {
11-
const versionControlQueryClient = await getVersionControlQueryClientFromApi(
12-
cosmWasmClient,
13-
apiUrl,
14-
)
7+
export type GetNamespaceParameters = WithArgs<{
8+
accountId: VersionControlTypes.AccountId
9+
cosmWasmClient: CosmWasmClient
10+
apiUrl: string
11+
}>
12+
13+
export async function getNamespace({
14+
args: { accountId, cosmWasmClient, apiUrl },
15+
}: GetNamespaceParameters): Promise<string | null> {
16+
const versionControlQueryClient = await getVersionControlQueryClientFromApi({
17+
args: {
18+
cosmWasmClient,
19+
apiUrl,
20+
},
21+
})
1522
const namespace = await versionControlQueryClient
1623
.namespaces({ accounts: [accountIdToParameter(accountId)] })
1724
.then((x) => x.namespaces[0]?.[0])

packages/core/src/actions/account/public/get-owner.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'
2+
import { WithArgs } from 'src/types/with-args'
23
import { VersionControlTypes } from '../../../codegen/abstract'
34
import { getManagerQueryClientFromApi } from './get-manager-query-client-from-api'
45

5-
export async function getOwner(
6-
accountId: VersionControlTypes.AccountId,
7-
cosmWasmClient: CosmWasmClient,
8-
apiUrl: string,
9-
) {
10-
const managerQueryClient = await getManagerQueryClientFromApi(
11-
accountId,
12-
cosmWasmClient,
13-
apiUrl,
14-
)
6+
export type GetOwnerParameters = WithArgs<{
7+
accountId: VersionControlTypes.AccountId
8+
cosmWasmClient: CosmWasmClient
9+
apiUrl: string
10+
}>
11+
12+
export async function getOwner({
13+
args: { accountId, cosmWasmClient, apiUrl },
14+
}: GetOwnerParameters) {
15+
const managerQueryClient = await getManagerQueryClientFromApi({
16+
args: {
17+
accountId,
18+
cosmWasmClient,
19+
apiUrl,
20+
},
21+
})
1522
return managerQueryClient
1623
.ownership()
1724
.then((res) => res.owner ?? null)
Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'
2+
import { WithArgs } from 'src/types/with-args'
23
import { VersionControlTypes } from '../../../codegen/abstract'
34
import { getProxyQueryClient } from '../../public/get-proxy-query-client'
45
import { getAccountBaseAddressesFromApi } from './get-account-base-addresses-from-api'
56

6-
export async function getProxyQueryClientFromApi(
7-
accountId: VersionControlTypes.AccountId,
8-
cosmWasmClient: CosmWasmClient,
9-
apiUrl: string,
10-
) {
11-
const { proxyAddress } = await getAccountBaseAddressesFromApi(
12-
accountId,
13-
cosmWasmClient,
14-
apiUrl,
15-
)
7+
export type GetProxyQueryClientFromApiParameters = WithArgs<{
8+
accountId: VersionControlTypes.AccountId
9+
cosmWasmClient: CosmWasmClient
10+
apiUrl: string
11+
}>
1612

17-
return getProxyQueryClient(cosmWasmClient, proxyAddress)
13+
export async function getProxyQueryClientFromApi({
14+
args: { accountId, cosmWasmClient, apiUrl },
15+
}: GetProxyQueryClientFromApiParameters) {
16+
const { proxyAddress } = await getAccountBaseAddressesFromApi({
17+
args: {
18+
accountId,
19+
cosmWasmClient,
20+
apiUrl,
21+
},
22+
})
23+
24+
return getProxyQueryClient({ args: { cosmWasmClient, proxyAddress } })
1825
}

packages/core/src/actions/account/public/get-sub-account-ids.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'
2+
import { WithArgs } from 'src/types/with-args'
23
import {
34
ManagerQueryClient,
45
VersionControlTypes,
@@ -7,20 +8,27 @@ import { sequenceToLocalAccountId } from '../../../utils/account-id/seq-to-local
78
import { chainIdToName } from '../../../utils/chain-registry'
89
import { getSubAccountSequences } from './get-sub-account-sequences'
910

10-
export async function getSubAccountIds(
11-
accountId: VersionControlTypes.AccountId,
12-
cosmWasmClient: CosmWasmClient,
13-
apiUrl: string,
14-
...params: Parameters<typeof ManagerQueryClient.prototype.subAccountIds>
15-
) {
11+
export type GetSubAccountIdsParameters = WithArgs<
12+
{
13+
accountId: VersionControlTypes.AccountId
14+
cosmWasmClient: CosmWasmClient
15+
apiUrl: string
16+
} & Parameters<typeof ManagerQueryClient.prototype.subAccountIds>[0]
17+
>
18+
19+
export async function getSubAccountIds({
20+
args: { accountId, cosmWasmClient, apiUrl, ...params },
21+
}: GetSubAccountIdsParameters) {
1622
const chainId = await cosmWasmClient.getChainId()
1723
const chainName = chainIdToName(chainId)
18-
const sub_accounts = await getSubAccountSequences(
19-
accountId,
20-
cosmWasmClient,
21-
apiUrl,
22-
...params,
23-
)
24+
const sub_accounts = await getSubAccountSequences({
25+
args: {
26+
accountId,
27+
cosmWasmClient,
28+
apiUrl,
29+
...params,
30+
},
31+
})
2432

2533
return sub_accounts.map((sequence) =>
2634
sequenceToLocalAccountId({ chainName, sequence }),
Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'
2+
import { WithArgs } from 'src/types/with-args'
23
import {
34
ManagerQueryClient,
45
VersionControlTypes,
56
} from '../../../codegen/abstract'
67
import { getManagerQueryClientFromApi } from './get-manager-query-client-from-api'
78

8-
export async function getSubAccountSequences(
9-
accountId: VersionControlTypes.AccountId,
10-
cosmWasmClient: CosmWasmClient,
11-
apiUrl: string,
12-
...params: Parameters<typeof ManagerQueryClient.prototype.subAccountIds>
13-
) {
14-
const managerQueryClient = await getManagerQueryClientFromApi(
15-
accountId,
16-
cosmWasmClient,
17-
apiUrl,
18-
)
19-
const { sub_accounts } = await managerQueryClient.subAccountIds(...params)
9+
export type GetSubAccountSequencesParameters = WithArgs<
10+
{
11+
accountId: VersionControlTypes.AccountId
12+
cosmWasmClient: CosmWasmClient
13+
apiUrl: string
14+
} & Parameters<typeof ManagerQueryClient.prototype.subAccountIds>[0]
15+
>
16+
17+
export async function getSubAccountSequences({
18+
args: { accountId, cosmWasmClient, apiUrl, ...params },
19+
}: GetSubAccountSequencesParameters) {
20+
const managerQueryClient = await getManagerQueryClientFromApi({
21+
args: {
22+
accountId,
23+
cosmWasmClient,
24+
apiUrl,
25+
},
26+
})
27+
const { sub_accounts } = await managerQueryClient.subAccountIds(params)
2028

2129
return sub_accounts
2230
}

0 commit comments

Comments
 (0)