Skip to content

Commit

Permalink
chore: fusdc getStaticInfo PF method
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
0xpatrickdev committed Dec 11, 2024
1 parent bd2a960 commit 475e720
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
15 changes: 14 additions & 1 deletion packages/fast-usdc/src/fast-usdc.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -174,17 +176,21 @@ 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([
E(poolAccount).getAddress(),
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;
},
});

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion packages/fast-usdc/src/fast-usdc.start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions packages/fast-usdc/test/fast-usdc.contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const startContract = async (
),
);
await E(startKit.creatorFacet).connectToNoble();
await E(startKit.creatorFacet).publishAddresses();

return {
...startKit,
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 475e720

Please sign in to comment.