Skip to content

Commit

Permalink
feat(fast-usdc): publish feeConfig to vstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
samsiegart committed Nov 27, 2024
1 parent 1d5cb99 commit aaf75e7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
9 changes: 9 additions & 0 deletions packages/boot/test/fast-usdc/fast-usdc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ test.serial('writes feed policy to vstorage', async t => {
await documentStorageSchema(t, storage, doc);
});

test.serial('writes fee config to vstorage', async t => {
const { storage } = t.context;
const doc = {
node: 'fastUsdc.feeConfig',
owner: 'the fee configuration for Fast USDC',
};
await documentStorageSchema(t, storage, doc);
});

test.serial('writes status updates to vstorage', async t => {
const { walletFactoryDriver: wd, storage } = t.context;
const wallet = await wd.provideSmartWallet(
Expand Down
14 changes: 14 additions & 0 deletions packages/boot/test/fast-usdc/snapshots/fast-usdc.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ Generated by [AVA](https://avajs.dev).
],
]

## writes fee config to vstorage

> Under "published", the "fastUsdc.feeConfig" node is delegated to the fee configuration for Fast USDC.
> The example below illustrates the schema of the data published there.
>
> See also board marshalling conventions (_to appear_).
[
[
'published.fastUsdc.feeConfig',
'{"blockHeight":"0","values":["{\\"body\\":\\"#{\\\\\\"contractRate\\\\\\":{\\\\\\"denominator\\\\\\":{\\\\\\"brand\\\\\\":\\\\\\"$0.Alleged: USDC brand\\\\\\",\\\\\\"value\\\\\\":\\\\\\"+10\\\\\\"},\\\\\\"numerator\\\\\\":{\\\\\\"brand\\\\\\":\\\\\\"$0\\\\\\",\\\\\\"value\\\\\\":\\\\\\"+2\\\\\\"}},\\\\\\"flat\\\\\\":{\\\\\\"brand\\\\\\":\\\\\\"$0\\\\\\",\\\\\\"value\\\\\\":\\\\\\"+10000\\\\\\"},\\\\\\"maxVariable\\\\\\":{\\\\\\"brand\\\\\\":\\\\\\"$0\\\\\\",\\\\\\"value\\\\\\":\\\\\\"+5000000\\\\\\"},\\\\\\"variableRate\\\\\\":{\\\\\\"denominator\\\\\\":{\\\\\\"brand\\\\\\":\\\\\\"$0\\\\\\",\\\\\\"value\\\\\\":\\\\\\"+100\\\\\\"},\\\\\\"numerator\\\\\\":{\\\\\\"brand\\\\\\":\\\\\\"$0\\\\\\",\\\\\\"value\\\\\\":\\\\\\"+1\\\\\\"}}}\\",\\"slots\\":[\\"board01029\\"]}"]}',
],
]

## writes status updates to vstorage

> Under "published", the "fastUsdc.status" node is delegated to the statuses of fast USDC transfers identified by their tx hashes.
Expand Down
Binary file modified packages/boot/test/fast-usdc/snapshots/fast-usdc.test.ts.snap
Binary file not shown.
22 changes: 18 additions & 4 deletions packages/fast-usdc/src/fast-usdc.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ import * as flows from './fast-usdc.flows.js';
const trace = makeTracer('FastUsdc');

const STATUS_NODE = 'status';
const FEE_NODE = 'feeConfig';

/**
* @import {HostInterface} from '@agoric/async-flow';
* @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 {Remote} from '@agoric/internal';
* @import {Marshaller, StorageNode} from '@agoric/internal/src/lib-chainStorage.js'
* @import {Zone} from '@agoric/zone';
* @import {OperatorKit} from './exos/operator-kit.js';
* @import {CctpTxEvidence, FeeConfig} from './types.js';
Expand Down Expand Up @@ -63,6 +65,17 @@ export const meta = {
};
harden(meta);

/**
* @param {Remote<StorageNode>} node
* @param {ERef<Marshaller>} marshaller
* @param {FeeConfig} feeConfig
*/
const publishFeeConfig = async (node, marshaller, feeConfig) => {
const feeNode = E(node).makeChildNode(FEE_NODE);
const value = await E(marshaller).toCapData(feeConfig);
return E(feeNode).setValue(JSON.stringify(value));
};

/**
* @param {ZCF<FastUsdcTerms>} zcf
* @param {OrchestrationPowers & {
Expand All @@ -80,14 +93,13 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
assert('USDC' in terms.brands, 'no USDC brand');
assert('usdcDenom' in terms, 'no usdcDenom');

const { feeConfig, marshaller } = privateArgs;
const { feeConfig, marshaller, storageNode } = privateArgs;
const { makeRecorderKit } = prepareRecorderKitMakers(
zone.mapStore('vstorage'),
marshaller,
);

const makeStatusNode = () =>
E(privateArgs.storageNode).makeChildNode(STATUS_NODE);
const makeStatusNode = () => E(storageNode).makeChildNode(STATUS_NODE);
const statusManager = prepareStatusManager(zone, makeStatusNode);

const { USDC } = terms.brands;
Expand Down Expand Up @@ -209,6 +221,8 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
// So we use zone.exoClassKit above to define the liquidity pool kind
// and pass the shareMint into the maker / init function.

void publishFeeConfig(storageNode, marshaller, feeConfig);

const shareMint = await provideSingleton(
zone.mapStore('mint'),
'PoolShare',
Expand Down

0 comments on commit aaf75e7

Please sign in to comment.