import { Hono } from 'hono' import * as z from 'zod/mini' import type * as App from '../../../App.js' import * as Auth from '../../../internal/Auth.js' import * as Cache from '../../../internal/Cache.js' import * as FundingCatalog from '../../../internal/funding/Catalog.js' import * as FundingProvider from '../../../internal/funding/Provider.js' import * as OpenApi from '../../../internal/OpenApi.js' import * as Response from '../../../internal/Response.js' import * as Schema from '../../../internal/Schema.js' import * as Inventory from '../Inventory.js' /** Zod schemas owned by funding chain resources. */ export namespace schema { /** Source chain reference. */ export const Chain = FundingProvider.schema.ChainRef /** Source token reference. */ export const Token = FundingProvider.schema.TokenRef /** Chain inventory entry returned by the funding chains endpoint. */ export const ChainInventory = OpenApi.component( Schema.describe( z.extend(Chain, { tokens: z.array(Token).check(z.describe('Stablecoins known on this source chain.')), }), 'One source chain and its known stablecoin inventory.', ), 'FundingChainInventory', ) /** Schemas for the getFundingChains operation. */ export namespace getFundingChains { /** Non-paginated source-chain inventory. */ export const Response = OpenApi.component( Schema.describe( z.object({ data: z .array(ChainInventory) .check(z.describe('Source chains and stablecoins supported by funding quotes.')), }), 'A non-paginated list of source chains and stablecoin inventory.', ), 'FundingChainList', ) } } const baseChainExample = { addressFormat: 'hex', id: 'eip155:8453', kind: 'evm', name: 'Base', } as const const baseUsdcExample = { address: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', currency: 'USD', decimals: 6, name: 'USD Coin', standard: 'ERC-20', symbol: 'USDC', tokenKey: 'eip155:8453/erc20:0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', verified: true, } as const const fundingChainsResponseExample = { data: [{ ...baseChainExample, tokens: [baseUsdcExample] }], } satisfies z.output /** Mounts funding chain inventory routes. */ export function chains() { return new Hono().get( '/v1/funding/chains', Auth.policy({ apiKey: { scopes: ['data:read'] }, mpp: true, public: true }), OpenApi.describeRoute({ description: 'Lists supported source chains and tokens.', operationId: 'getFundingChains', responses: OpenApi.responses({ errors: { 400: { codes: [] } }, success: { description: 'Supported source chains and stablecoins.', example: fundingChainsResponseExample, schema: schema.getFundingChains.Response, }, }), summary: 'Get chains', tags: ['Chains'], }), Cache.response({ cacheControl: Cache.policies.stable, key: Inventory.key, name: 'tempo-api:funding-chains:v5', }), async (c) => { if (Auth.narrowAccess) return Auth.paidAccessError(c) const catalog = await FundingCatalog.snapshot(c) const providers = c.get('providers').filter(FundingProvider.is) return c.json( Response.validated(schema.getFundingChains.Response, { data: FundingProvider.getChains({ catalog, providers }), }), 200, ) }, ) }