From 287e5be3627739354453e85b69c06b93222577ce Mon Sep 17 00:00:00 2001 From: 0xPatrick Date: Tue, 10 Dec 2024 17:51:28 -0500 Subject: [PATCH] chore: fusdc `getStaticInfo` PF method - ensure contract consumers have access to the contract's orch account addresses which are currently only published to vstorage. since these are not expected to change, a public facet method seems more suitable than a recorderKit --- packages/fast-usdc/src/fast-usdc.contract.js | 15 ++++++++++++++- packages/fast-usdc/src/fast-usdc.start.js | 3 ++- .../fast-usdc/test/fast-usdc.contract.test.ts | 13 +++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/fast-usdc/src/fast-usdc.contract.js b/packages/fast-usdc/src/fast-usdc.contract.js index 0aa443c1aa1..ff9f08c5000 100644 --- a/packages/fast-usdc/src/fast-usdc.contract.js +++ b/packages/fast-usdc/src/fast-usdc.contract.js @@ -12,6 +12,7 @@ import { import { makeZoeTools } from '@agoric/orchestration/src/utils/zoe-tools.js'; import { provideSingleton } from '@agoric/zoe/src/contractSupport/durability.js'; import { prepareRecorderKitMakers } from '@agoric/zoe/src/contractSupport/recorder.js'; +import { Fail } from '@endo/errors'; import { E } from '@endo/far'; import { M } from '@endo/patterns'; import { prepareAdvancer } from './exos/advancer.js'; @@ -27,6 +28,7 @@ const trace = makeTracer('FastUsdc'); const STATUS_NODE = 'status'; const FEE_NODE = 'feeConfig'; +const ADDRESSES_BAGGAGE_KEY = 'addresses'; /** * @import {HostInterface} from '@agoric/async-flow'; @@ -174,6 +176,7 @@ export const contract = async (zcf, privateArgs, zone, tools) => { }); }, async publishAddresses() { + !baggage.has(ADDRESSES_BAGGAGE_KEY) || Fail`Addresses already published`; const [poolAccountAddress, settlementAccountAddress] = await vowTools.when( vowTools.all([ @@ -181,10 +184,13 @@ export const contract = async (zcf, privateArgs, zone, tools) => { E(settlementAccount).getAddress(), ]), ); - await publishAddresses(storageNode, { + const addresses = harden({ poolAccount: poolAccountAddress.value, settlementAccount: settlementAccountAddress.value, }); + baggage.init(ADDRESSES_BAGGAGE_KEY, addresses); + await publishAddresses(storageNode, addresses); + return addresses; }, }); @@ -212,6 +218,13 @@ export const contract = async (zcf, privateArgs, zone, tools) => { getPublicTopics() { return poolKit.public.getPublicTopics(); }, + getStaticInfo() { + baggage.has(ADDRESSES_BAGGAGE_KEY) || + Fail`no addresses. creator must 'publishAddresses' first`; + return harden({ + [ADDRESSES_BAGGAGE_KEY]: baggage.get(ADDRESSES_BAGGAGE_KEY), + }); + }, }); // ^^^ Define all kinds above this line. Keep remote calls below. vvv diff --git a/packages/fast-usdc/src/fast-usdc.start.js b/packages/fast-usdc/src/fast-usdc.start.js index 070025a6c5e..2815569d2ed 100644 --- a/packages/fast-usdc/src/fast-usdc.start.js +++ b/packages/fast-usdc/src/fast-usdc.start.js @@ -227,7 +227,8 @@ export const startFastUSDC = async ( produceInstance.reset(); produceInstance.resolve(instance); - await E(kit.creatorFacet).publishAddresses(); + const addresses = await E(kit.creatorFacet).publishAddresses(); + trace('contract orch account addresses', addresses); if (!net.noNoble) { const addr = await E(kit.creatorFacet).connectToNoble(); trace('noble intermediate recipient', addr); diff --git a/packages/fast-usdc/test/fast-usdc.contract.test.ts b/packages/fast-usdc/test/fast-usdc.contract.test.ts index 665ed382320..872bffc2c0a 100644 --- a/packages/fast-usdc/test/fast-usdc.contract.test.ts +++ b/packages/fast-usdc/test/fast-usdc.contract.test.ts @@ -86,6 +86,7 @@ const startContract = async ( ), ); await E(startKit.creatorFacet).connectToNoble(); + await E(startKit.creatorFacet).publishAddresses(); return { ...startKit, @@ -179,6 +180,18 @@ test('baggage', async t => { t.snapshot(tree, 'contract baggage after start'); }); +test('getStaticInfo', async t => { + const { startKit } = t.context; + const { publicFacet } = startKit; + + t.deepEqual(await E(publicFacet).getStaticInfo(), { + addresses: { + poolAccount: 'agoric1fakeLCAAddress', + settlementAccount: 'agoric1fakeLCAAddress1', + }, + }); +}); + const purseOf = (issuer: Issuer, { pourPayment }) => async (value: bigint) => {