diff --git a/packages/builders/scripts/fast-usdc/init-fast-usdc.js b/packages/builders/scripts/fast-usdc/init-fast-usdc.js index 08a5d996cdb..5786cb0f0b0 100644 --- a/packages/builders/scripts/fast-usdc/init-fast-usdc.js +++ b/packages/builders/scripts/fast-usdc/init-fast-usdc.js @@ -124,11 +124,17 @@ const options = { default: 'ibc/FE98AAD68F02F03565E9FA39A5E627946699B2B07115889ED812D8BA639576A9', }, + chainInfo: { type: 'string' }, + assetInfo: { type: 'string' }, }; const oraclesUsage = 'use --oracle name:address ...'; const feedPolicyUsage = 'use --feedPolicy ...'; +const chainInfoUsage = 'use --chainInfo chainName:CosmosChainInfo ...'; +const assetInfoUsage = + 'use --assetInfo denom:DenomInfo & {brandKey?: string} ...'; + /** * @typedef {{ * flatFee: string; @@ -139,6 +145,8 @@ const feedPolicyUsage = 'use --feedPolicy ...'; * oracle?: string[]; * usdcDenom: string; * feedPolicy?: string; + * chainInfo: string; + * assetInfo: string; * }} FastUSDCOpts */ @@ -180,7 +188,15 @@ export default async (homeP, endowments) => { /** @type {{ values: FastUSDCOpts }} */ // @ts-expect-error ensured by options const { - values: { oracle: oracleArgs, net, usdcDenom, feedPolicy, ...fees }, + values: { + oracle: oracleArgs, + net, + usdcDenom, + feedPolicy, + chainInfo, + assetInfo, + ...fees + }, } = parseArgs({ args: scriptArgs, options }); const parseFeedPolicy = () => { @@ -226,6 +242,15 @@ export default async (homeP, endowments) => { }; }; + const parseChainInfo = () => { + if (!chainInfo) throw Error(chainInfoUsage); + return JSON.parse(chainInfo); + }; + const parseAssetInfo = () => { + if (!assetInfo) throw Error(assetInfoUsage); + return JSON.parse(assetInfo); + }; + /** @type {FastUSDCConfig} */ const config = harden({ oracles: parseOracleArgs(), @@ -234,6 +259,8 @@ export default async (homeP, endowments) => { }, feeConfig: parseFeeConfigArgs(), feedPolicy: parseFeedPolicy(), + chainInfo: parseChainInfo(), + assetInfo: parseAssetInfo(), }); await writeCoreEval('start-fast-usdc', utils => diff --git a/packages/fast-usdc/src/fast-usdc.contract.js b/packages/fast-usdc/src/fast-usdc.contract.js index 952d26480d1..50dd0de2f18 100644 --- a/packages/fast-usdc/src/fast-usdc.contract.js +++ b/packages/fast-usdc/src/fast-usdc.contract.js @@ -6,7 +6,10 @@ import { } from '@agoric/internal'; import { observeIteration, subscribeEach } from '@agoric/notifier'; import { + CosmosChainInfoShape, + DenomDetailShape, OrchestrationPowersShape, + registerChainsAndAssets, withOrchestration, } from '@agoric/orchestration'; import { provideSingleton } from '@agoric/zoe/src/contractSupport/durability.js'; @@ -27,9 +30,8 @@ import * as flows from './fast-usdc.flows.js'; const trace = makeTracer('FastUsdc'); /** - * @import {Denom} from '@agoric/orchestration'; * @import {HostInterface} from '@agoric/async-flow'; - * @import {OrchestrationAccount} from '@agoric/orchestration'; + * @import {CosmosChainInfo, Denom, DenomDetail, OrchestrationAccount} from '@agoric/orchestration'; * @import {OrchestrationPowers, OrchestrationTools} from '@agoric/orchestration/src/utils/start-helper.js'; * @import {Vow} from '@agoric/vow'; * @import {Zone} from '@agoric/zone'; @@ -53,6 +55,8 @@ export const meta = { ...OrchestrationPowersShape, feeConfig: FeeConfigShape, marshaller: M.remotable(), + chainInfo: M.recordOf(M.string(), CosmosChainInfoShape), + assetInfo: M.recordOf(M.string(), DenomDetailShape), }, }; harden(meta); @@ -62,6 +66,8 @@ harden(meta); * @param {OrchestrationPowers & { * marshaller: Marshaller; * feeConfig: FeeConfig; + * chainInfo: Record; + * assetInfo: Record; * }} privateArgs * @param {Zone} zone * @param {OrchestrationTools} tools @@ -82,7 +88,7 @@ export const contract = async (zcf, privateArgs, zone, tools) => { const { USDC } = terms.brands; const { withdrawToSeat } = tools.zoeTools; - const { chainHub, orchestrateAll, vowTools } = tools; + const { baggage, chainHub, orchestrateAll, vowTools } = tools; const makeSettler = prepareSettler(zone, { statusManager, USDC, @@ -212,6 +218,18 @@ export const contract = async (zcf, privateArgs, zone, tools) => { makeLiquidityPoolKit(shareMint, privateArgs.storageNode), ); + /** Chain, connection, and asset info can only be registered once */ + const firstIncarnationKey = 'firstIncarnationKey'; + if (!baggage.has(firstIncarnationKey)) { + baggage.init(firstIncarnationKey, true); + registerChainsAndAssets( + chainHub, + terms.brands, + privateArgs.chainInfo, + privateArgs.assetInfo, + ); + } + const feedKit = zone.makeOnce('Feed Kit', () => makeFeedKit()); const poolAccountV = zone.makeOnce('PoolAccount', () => makeLocalAccount()); diff --git a/packages/fast-usdc/src/fast-usdc.start.js b/packages/fast-usdc/src/fast-usdc.start.js index 96f14569dad..0dce7f375e2 100644 --- a/packages/fast-usdc/src/fast-usdc.start.js +++ b/packages/fast-usdc/src/fast-usdc.start.js @@ -1,4 +1,5 @@ import { deeplyFulfilledObject, makeTracer, objectMap } from '@agoric/internal'; +import { CosmosChainInfoShape, DenomDetailShape } from '@agoric/orchestration'; import { Fail } from '@endo/errors'; import { E } from '@endo/far'; import { makeMarshal } from '@endo/marshal'; @@ -13,6 +14,7 @@ import { fromExternalConfig } from './utils/config-marshal.js'; /** * @import {DepositFacet} from '@agoric/ertp/src/types.js' * @import {TypedPattern} from '@agoric/internal' + * @import {CosmosChainInfo, Denom, DenomDetail} from '@agoric/orchestration'; * @import {Instance, StartParams} from '@agoric/zoe/src/zoeService/utils' * @import {Board} from '@agoric/vats' * @import {ManifestBundleRef} from '@agoric/deploy-script-support/src/externalTypes.js' @@ -33,6 +35,8 @@ const contractName = 'fastUsdc'; * oracles: Record; * feeConfig: FeeConfig; * feedPolicy: FeedPolicy & Passable; + * chainInfo: Record; + * assetInfo: Record; * }} FastUSDCConfig */ /** @type {TypedPattern} */ @@ -41,6 +45,8 @@ export const FastUSDCConfigShape = M.splitRecord({ oracles: M.recordOf(M.string(), M.string()), feeConfig: FeeConfigShape, feedPolicy: FeedPolicyShape, + chainInfo: M.recordOf(M.string(), CosmosChainInfoShape), + assetInfo: M.recordOf(M.string(), DenomDetailShape), }); /** @@ -149,11 +155,12 @@ export const startFastUSDC = async ( USDC: await E(USDCissuer).getBrand(), }); - const { terms, oracles, feeConfig, feedPolicy } = fromExternalConfig( - config?.options, // just in case config is missing somehow - brands, - FastUSDCConfigShape, - ); + const { terms, oracles, feeConfig, feedPolicy, chainInfo, assetInfo } = + fromExternalConfig( + config?.options, // just in case config is missing somehow + brands, + FastUSDCConfigShape, + ); trace('using terms', terms); trace('using fee config', feeConfig); @@ -187,6 +194,8 @@ export const startFastUSDC = async ( storageNode, timerService, marshaller, + chainInfo, + assetInfo, }), ); diff --git a/packages/fast-usdc/test/snapshots/fast-usdc.contract.test.ts.md b/packages/fast-usdc/test/snapshots/fast-usdc.contract.test.ts.md index e508daf0f99..ec82b58c800 100644 --- a/packages/fast-usdc/test/snapshots/fast-usdc.contract.test.ts.md +++ b/packages/fast-usdc/test/snapshots/fast-usdc.contract.test.ts.md @@ -100,6 +100,7 @@ Generated by [AVA](https://avajs.dev). Recorder_kindHandle: 'Alleged: kind', }, }, + firstIncarnationKey: true, orchestration: { 'Cosmos Orchestration Account Holder_kindHandle': 'Alleged: kind', 'Local Orchestration Account Kit_kindHandle': 'Alleged: kind', diff --git a/packages/fast-usdc/test/snapshots/fast-usdc.contract.test.ts.snap b/packages/fast-usdc/test/snapshots/fast-usdc.contract.test.ts.snap index 5428f409065..5e8c6efc2ee 100644 Binary files a/packages/fast-usdc/test/snapshots/fast-usdc.contract.test.ts.snap and b/packages/fast-usdc/test/snapshots/fast-usdc.contract.test.ts.snap differ diff --git a/packages/fast-usdc/test/supports.ts b/packages/fast-usdc/test/supports.ts index 8ce9d7b12ea..e7977de6963 100644 --- a/packages/fast-usdc/test/supports.ts +++ b/packages/fast-usdc/test/supports.ts @@ -186,6 +186,8 @@ export const commonSetup = async (t: ExecutionContext) => { marshaller, timerService: timer, feeConfig: makeTestFeeConfig(usdc), + chainInfo: {}, + assetInfo: {}, }, facadeServices: { agoricNames,