Skip to content

Commit

Permalink
feat: parameterize fusdc with chainInfo and assetInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpatrickdev committed Nov 26, 2024
1 parent f5d2aa0 commit 7dd647e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
29 changes: 28 additions & 1 deletion packages/builders/scripts/fast-usdc/init-fast-usdc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <policy> ...';

const chainInfoUsage = 'use --chainInfo chainName:CosmosChainInfo ...';
const assetInfoUsage =
'use --assetInfo denom:DenomInfo & {brandKey?: string} ...';

/**
* @typedef {{
* flatFee: string;
Expand All @@ -139,6 +145,8 @@ const feedPolicyUsage = 'use --feedPolicy <policy> ...';
* oracle?: string[];
* usdcDenom: string;
* feedPolicy?: string;
* chainInfo: string;
* assetInfo: string;
* }} FastUSDCOpts
*/

Expand Down Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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(),
Expand All @@ -234,6 +259,8 @@ export default async (homeP, endowments) => {
},
feeConfig: parseFeeConfigArgs(),
feedPolicy: parseFeedPolicy(),
chainInfo: parseChainInfo(),
assetInfo: parseAssetInfo(),
});

await writeCoreEval('start-fast-usdc', utils =>
Expand Down
18 changes: 18 additions & 0 deletions packages/fast-usdc/src/fast-usdc.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {
} from '@agoric/internal';
import { observeIteration, subscribeEach } from '@agoric/notifier';
import {
CosmosChainInfoShape,
DenomInfoShape,
OrchestrationPowersShape,
registerChainsAndAssets,
withOrchestration,
} from '@agoric/orchestration';
import { provideSingleton } from '@agoric/zoe/src/contractSupport/durability.js';
Expand Down Expand Up @@ -53,6 +56,12 @@ export const meta = {
...OrchestrationPowersShape,
feeConfig: FeeConfigShape,
marshaller: M.remotable(),
chainInfo: M.recordOf(M.string(), CosmosChainInfoShape),
assetInfo: M.recordOf(M.string(), {
// @ts-expect-error TypedPattern not recognized as record
...DenomInfoShape,
brandKey: M.opt(M.string()),
}),
},
};
harden(meta);
Expand All @@ -62,6 +71,8 @@ harden(meta);
* @param {OrchestrationPowers & {
* marshaller: Marshaller;
* feeConfig: FeeConfig;
* chainInfo: Record<string, import('@agoric/orchestration').ChainInfo>;
* assetInfo: Record<Denom, import('@agoric/orchestration').DenomDetail & { brandKey?: string}>;
* }} privateArgs
* @param {Zone} zone
* @param {OrchestrationTools} tools
Expand Down Expand Up @@ -251,6 +262,13 @@ export const contract = async (zcf, privateArgs, zone, tools) => {

await settlerKit.creator.monitorMintingDeposits();

registerChainsAndAssets(
chainHub,
terms.brands,
privateArgs.chainInfo,
privateArgs.assetInfo,
);

return harden({ creatorFacet, publicFacet });
};
harden(contract);
Expand Down
16 changes: 11 additions & 5 deletions packages/fast-usdc/src/fast-usdc.start.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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'
Expand All @@ -33,6 +34,8 @@ const contractName = 'fastUsdc';
* oracles: Record<string, string>;
* feeConfig: FeeConfig;
* feedPolicy: FeedPolicy & Passable;
* chainInfo: Record<string, CosmosChainInfo & Passable>;
* assetInfo: Record<Denom, DenomDetail & {brandKey?: string}>;
* }} FastUSDCConfig
*/
/** @type {TypedPattern<FastUSDCConfig>} */
Expand Down Expand Up @@ -149,11 +152,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);

Expand Down Expand Up @@ -187,6 +191,8 @@ export const startFastUSDC = async (
storageNode,
timerService,
marshaller,
chainInfo,
assetInfo,
}),
);

Expand Down
2 changes: 2 additions & 0 deletions packages/fast-usdc/test/supports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ export const commonSetup = async (t: ExecutionContext<any>) => {
marshaller,
timerService: timer,
feeConfig: makeTestFeeConfig(usdc),
chainInfo: {},
assetInfo: {},
},
facadeServices: {
agoricNames,
Expand Down

0 comments on commit 7dd647e

Please sign in to comment.