Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,100 changes: 343 additions & 757 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
},
"dependencies": {
"@bull-board/koa": "^5.8.4",
"@burnt-labs/xion-types": "^21.0.0-alpha.3",
"@burnt-labs/xion-types": "28.1.0-rc6",
"@cosmjs/amino": "^0.32.3",
"@cosmjs/cosmwasm-stargate": "^0.32.3",
"@cosmjs/crypto": "^0.32.3",
Expand Down
14 changes: 12 additions & 2 deletions src/formulas/formulas/contract/xion/account.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import type { Params } from '@burnt-labs/xion-types'

import { ContractFormula } from '@/types'

import { Authenticator } from './types/Account.types'
import { Params } from './types/Treasury.types'
// Stored authenticator shape (on-chain representation, snake_case keys).
// Not produced by ts-codegen since the contract query responses return Binary;
// derived from the account contract's state serialization.
type Authenticator =
| { secp256_k1: { pubkey: string } }
| { ed25519: { pubkey: string } }
| { eth_wallet: { address: string } }
| { jwt: { aud: string; sub: string } }
| { secp256_r1: { pubkey: string } }
| { passkey: { passkey: string; url: string } }

const AccountStorageKeys = {
AUTHENTICATORS: 'authenticators',
Expand Down
79 changes: 76 additions & 3 deletions src/formulas/formulas/contract/xion/treasury.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,60 @@
import {
Addr,
import type {
TreasuryAddr as Addr,
FeeConfig,
GrantConfig,
Params,
} from '@/formulas/formulas/contract/xion/types/Treasury.types'
} from '@burnt-labs/xion-types'
import type { OpenAPIV3_1 } from 'openapi-types'

import { ContractFormula } from '@/types'

import { makeSimpleContractFormula } from '../../utils'

// Load the CosmWasm-generated JSON Schema for the treasury contract.
// The schema files are included in @burnt-labs/xion-types dist via the
// package's copy script and kept in sync with the Rust contract via `cargo schema`.
// eslint-disable-next-line @typescript-eslint/no-require-imports
const treasurySchema =
require('@burnt-labs/xion-types/contracts/treasury/schema/raw/instantiate.json') as {
definitions: Record<string, OpenAPIV3_1.SchemaObject>
}

// Resolve JSON Schema $ref references inline for OpenAPI v3.1 compatibility.
function resolveRefs(
schema: OpenAPIV3_1.SchemaObject,
defs: Record<string, OpenAPIV3_1.SchemaObject>
): OpenAPIV3_1.SchemaObject {
if ('$ref' in schema) {
const name = (schema as { $ref: string }).$ref.replace('#/definitions/', '')
return resolveRefs(defs[name], defs)
}
const resolved = { ...schema }
if (resolved.properties) {
resolved.properties = Object.fromEntries(
Object.entries(resolved.properties).map(([k, v]) => [
k,
resolveRefs(v as OpenAPIV3_1.SchemaObject, defs),
])
)
}
if (resolved.anyOf) {
resolved.anyOf = resolved.anyOf.map((s) =>
resolveRefs(s as OpenAPIV3_1.SchemaObject, defs)
)
}
return resolved
}

const { definitions: defs } = treasurySchema
const AddrSchema = resolveRefs(defs['Addr'], defs)
const FeeConfigSchema = resolveRefs(defs['FeeConfig'], defs)
const GrantConfigSchema = resolveRefs(defs['GrantConfig'], defs)
const ParamsSchema = resolveRefs(defs['Params'], defs)
const GrantConfigMapSchema: OpenAPIV3_1.SchemaObject = {
type: 'object',
additionalProperties: GrantConfigSchema,
}

const TreasuryStorageKeys = {
GRANT_CONFIGS: 'grant_configs',
FEE_CONFIG: 'fee_config',
Expand All @@ -19,6 +66,7 @@ const TreasuryStorageKeys = {
export const grantConfigs: ContractFormula<Record<string, GrantConfig>> = {
docs: {
description: "Get the treasury's grant configs by msg type url",
response: GrantConfigMapSchema,
},
compute: async (env) => {
const { contractAddress, getMap } = env
Expand All @@ -35,6 +83,9 @@ export const grantConfigs: ContractFormula<Record<string, GrantConfig>> = {
export const feeConfig: ContractFormula<FeeConfig | null> = {
docs: {
description: 'Get the fee sponsorship configuration for the treasury',
response: {
oneOf: [FeeConfigSchema, { type: 'null' }],
},
},
compute: async (env) => {
const { contractAddress, get } = env
Expand All @@ -49,6 +100,7 @@ export const feeConfig: ContractFormula<FeeConfig | null> = {
export const admin: ContractFormula<Addr | null> = {
docs: {
description: 'Get the curent admin for the treasury',
response: { oneOf: [AddrSchema, { type: 'null' }] },
},
compute: async (env) => {
const { contractAddress, get } = env
Expand All @@ -63,6 +115,7 @@ export const admin: ContractFormula<Addr | null> = {
export const pendingAdmin = makeSimpleContractFormula<Addr | null>({
docs: {
description: 'Get the pending admin for the treasury',
response: { oneOf: [AddrSchema, { type: 'null' }] },
},
transformation: TreasuryStorageKeys.PENDING_ADMIN,
fallback: null,
Expand All @@ -71,6 +124,7 @@ export const pendingAdmin = makeSimpleContractFormula<Addr | null>({
export const params: ContractFormula<Record<string, Params>> = {
docs: {
description: 'Get the params for the treasury',
response: ParamsSchema,
},
compute: async (env) => {
const { contractAddress, get } = env
Expand All @@ -85,6 +139,10 @@ export const params: ContractFormula<Record<string, Params>> = {
export const balances: ContractFormula<Record<string, string>> = {
docs: {
description: 'Get the balance of the treasury',
response: {
type: 'object',
additionalProperties: { type: 'string' },
},
},
compute: async (env) => {
const { contractAddress, getBalances } = env
Expand All @@ -103,6 +161,21 @@ export const all: ContractFormula<{
}> = {
docs: {
description: 'Get all treasury data in a single endpoint',
response: {
type: 'object',
required: ['grantConfigs', 'params'],
properties: {
grantConfigs: GrantConfigMapSchema,
feeConfig: { oneOf: [FeeConfigSchema, { type: 'null' }] },
admin: { oneOf: [AddrSchema, { type: 'null' }] },
pendingAdmin: { oneOf: [AddrSchema, { type: 'null' }] },
params: ParamsSchema,
balances: {
type: 'object',
additionalProperties: { type: 'string' },
},
},
},
},
compute: async (env) => {
// Call all the individual endpoints
Expand Down
114 changes: 0 additions & 114 deletions src/formulas/formulas/contract/xion/types/Account.types.ts

This file was deleted.

116 changes: 0 additions & 116 deletions src/formulas/formulas/contract/xion/types/Treasury.types.ts

This file was deleted.

Loading
Loading