Skip to content

Commit

Permalink
Merge pull request #156 from AbstractSDK/adair/adapterQueries
Browse files Browse the repository at this point in the history
Update adapter message builders
  • Loading branch information
adairrr authored Nov 25, 2024
2 parents da2207a + 4be7428 commit 746e375
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'

import { AdapterQueryMsgBuilder } from '@abstract-money/core'
import { RegistryTypes } from '../../../codegen/abstract'
import { getAccountAddressFromApi } from './get-account-address-from-api'

export type GetAdapterAuthorizedAddresses = {
cosmWasmClient: CosmWasmClient
apiUrl: string
accountId: RegistryTypes.AccountId
adapterAddress: string
}

export async function getAdapterAuthorizedAddresses({
cosmWasmClient,
accountId,
adapterAddress,
apiUrl,
}: GetAdapterAuthorizedAddresses) {
const account = await getAccountAddressFromApi({
accountId,
cosmWasmClient,
apiUrl,
})

return await cosmWasmClient.queryContractSmart(
adapterAddress,
AdapterQueryMsgBuilder.authorizedAddresses(account),
)
}
25 changes: 17 additions & 8 deletions packages/core/src/utils/modules/msg-factory/Adapter.msg-factory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContractMsg } from '@abstract-money/core'
import { type AppQueryMsg, ContractMsg } from '@abstract-money/core'
import { CamelCasedProperties } from 'type-fest'
import {
AdapterBaseExecuteMsg,
Expand Down Expand Up @@ -33,17 +33,17 @@ import {
export abstract class AdapterExecuteMsgFactory {
/**
* Make a request to an adapter module.
* @param proxyAddress
* @param accountAddress
* @param request
*/
static executeAdapter = <TAppMsg>({
proxyAddress,
accountAddress,
request,
}: CamelCasedProperties<
AdapterRequestMsg<TAppMsg>
>): AdapterExecuteMsg<TAppMsg> => {
return ModuleExecuteMsgFactory.module({
proxy_address: proxyAddress,
account_address: accountAddress,
request,
})
}
Expand Down Expand Up @@ -82,14 +82,14 @@ export abstract class AdapterQueryMsgBuilder {

/**
* Base adapter authorized addresses query.
* @param proxyAddress
* @param accountAddress
*/
static authorizedAddresses = (
proxyAddress?: string,
accountAddress?: string,
): AdapterQueryMsg<never> => {
return ModuleQueryMsgFactory.base({
authorized_addresses: {
proxy_address: proxyAddress,
account_address: accountAddress,
},
})
}
Expand All @@ -99,7 +99,16 @@ export abstract class AdapterQueryMsgBuilder {
*/
static config = (): AdapterQueryMsg<never> => {
return ModuleQueryMsgFactory.base({
config: {},
base_config: {},
})
}

/**
* App module data query.
*/
static moduleData = (): AppQueryMsg<never> => {
return ModuleQueryMsgFactory.base({
module_data: {},
})
}
}
13 changes: 8 additions & 5 deletions packages/core/src/utils/modules/msg-factory/Adapter.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type AdapterBaseExecuteMsg = {
}
}
export type AdapterRequestMsg<TAppMsg> = {
proxy_address?: string | null
account_address?: string | null
request: TAppMsg
}

Expand All @@ -18,11 +18,14 @@ export type AdapterExecuteMsg<TAppMsg> = ModuleExecuteMsg<
export type AdapterBaseQueryMsg =
| {
authorized_addresses: {
proxy_address?: string | null
account_address?: string | null
}
}
| {
config: Record<string, never>
base_config: Record<string, never>
}
| {
module_data: Record<string, never>
}

export type AdapterQueryMsg<TAppMsg> = ModuleQueryMsg<
Expand All @@ -32,15 +35,15 @@ export type AdapterQueryMsg<TAppMsg> = ModuleQueryMsg<

export type AdapterBaseInitMsg = {
ans_host_address: string
version_control_address: string
registry_address: string
}

export interface AdapterAuthorizedAddressesResponse {
addresses: string[]
}

export interface AdapterConfigResponse {
version_control_address: string
registry_address: string
ans_host_address: string
dependencies: string[]
}
22 changes: 20 additions & 2 deletions packages/core/src/utils/modules/msg-factory/App.msg-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export abstract class AppQueryMsgFactory {
*/
static config = (): AppQueryMsg<never> => {
return ModuleQueryMsgFactory.base({
config: {},
base_config: {},
})
}

Expand All @@ -65,7 +65,25 @@ export abstract class AppQueryMsgFactory {
*/
static admin = (): AppQueryMsg<never> => {
return ModuleQueryMsgFactory.base({
admin: {},
base_admin: {},
})
}

/**
* App module data query.
*/
static moduleData = (): AppQueryMsg<never> => {
return ModuleQueryMsgFactory.base({
module_data: {},
})
}

/**
* App top level owner query.
*/
static topLevelOwner = (): AppQueryMsg<never> => {
return ModuleQueryMsgFactory.base({
top_level_owner: {},
})
}
}
18 changes: 15 additions & 3 deletions packages/core/src/utils/modules/msg-factory/App.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,30 @@ export type AppExecuteMsg<TAppMsg> = ModuleExecuteMsg<
>
export type AppBaseQueryMsg =
| {
admin: Record<string, never>
base_admin: Record<string, never>
}
| {
config: Record<string, never>
base_config: Record<string, never>
}
| {
module_data: Record<string, never>
}
| {
top_level_owner: Record<string, never>
}

export type AppQueryMsg<TAppMsg> = ModuleQueryMsg<AppBaseQueryMsg, TAppMsg>

export type AppBaseInitMsg = {
ans_host_address: string
version_control_address: string
registry_address: string
}

// Empty migrate msg
export type AppBaseMigrateMsg = Record<string, never>

export interface AppConfigResponse {
account: string
ans_host_address: string
registry_address: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export abstract class ModuleInitMsgFactory {
return {
base: {
ans_host_address: ansHostAddress,
version_control_address: registryAddress,
registry_address: registryAddress,
},
module: appModuleInitMsg,
}
Expand All @@ -99,7 +99,7 @@ export abstract class ModuleInitMsgFactory {
return {
base: {
ans_host_address: ansHostAddress,
version_control_address: registryAddress,
registry_address: registryAddress,
},
module: adapterInitMsg,
}
Expand Down

0 comments on commit 746e375

Please sign in to comment.