Skip to content

Commit

Permalink
scaffold Fast USDC contract (#10383)
Browse files Browse the repository at this point in the history
in preparation for other tickets

## Description

Sets up the basic structure of the fast-usdc contract.

### Security Considerations
none

### Scaling Considerations
none

### Documentation Considerations
none

### Testing Considerations
none

### Upgrade Considerations
none
  • Loading branch information
mergify[bot] authored Nov 1, 2024
2 parents 5429b84 + 17df411 commit 604ac38
Show file tree
Hide file tree
Showing 9 changed files with 391 additions and 3 deletions.
17 changes: 17 additions & 0 deletions packages/fast-usdc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,28 @@
"lint:eslint": "eslint ."
},
"devDependencies": {
"@agoric/swingset-liveslots": "^0.10.2",
"@agoric/vats": "^0.15.1",
"@agoric/zoe": "^0.26.2",
"@agoric/zone": "^0.2.2",
"ava": "^5.3.0",
"c8": "^9.1.0",
"ts-blank-space": "^0.4.1"
},
"dependencies": {
"@agoric/ertp": "^0.16.2",
"@agoric/internal": "^0.3.2",
"@agoric/orchestration": "^0.1.0",
"@agoric/store": "^0.9.2",
"@agoric/vow": "^0.1.0",
"@endo/common": "^1.2.7",
"@endo/errors": "^1.2.7",
"@endo/eventual-send": "^1.2.7",
"@endo/far": "^1.1.8",
"@endo/marshal": "^1.6.1",
"@endo/pass-style": "^1.4.6",
"@endo/patterns": "^1.4.6",
"@endo/promise-kit": "^1.1.7",
"commander": "^12.1.0"
},
"ava": {
Expand Down
19 changes: 19 additions & 0 deletions packages/fast-usdc/src/exos/advancer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @import {Zone} from '@agoric/zone';
* @import {TransactionFeed} from './transaction-feed.js';
* @import {StatusManager} from './status-manager.js';
*/

import { assertAllDefined } from '@agoric/internal';

/**
* @param {Zone} zone
* @param {object} caps
* @param {TransactionFeed} caps.feed
* @param {StatusManager} caps.statusManager
*/
export const prepareAdvancer = (zone, { feed, statusManager }) => {
assertAllDefined({ feed, statusManager });
return zone.exo('Fast USDC Advancer', undefined, {});
};
harden(prepareAdvancer);
17 changes: 17 additions & 0 deletions packages/fast-usdc/src/exos/settler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @import {Zone} from '@agoric/zone';
* @import {StatusManager} from './status-manager.js';
*/

import { assertAllDefined } from '@agoric/internal';

/**
* @param {Zone} zone
* @param {object} caps
* @param {StatusManager} caps.statusManager
*/
export const prepareSettler = (zone, { statusManager }) => {
assertAllDefined({ statusManager });
return zone.exo('Fast USDC Settler', undefined, {});
};
harden(prepareSettler);
13 changes: 13 additions & 0 deletions packages/fast-usdc/src/exos/status-manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @import {Zone} from '@agoric/zone';
*/

/**
* @param {Zone} zone
*/
export const prepareStatusManager = zone => {
return zone.exo('Fast USDC Status Manager', undefined, {});
};
harden(prepareStatusManager);

/** @typedef {ReturnType<typeof prepareStatusManager>} StatusManager */
13 changes: 13 additions & 0 deletions packages/fast-usdc/src/exos/transaction-feed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @import {Zone} from '@agoric/zone';
*/

/**
* @param {Zone} zone
*/
export const prepareTransactionFeed = zone => {
return zone.exo('Fast USDC Feed', undefined, {});
};
harden(prepareTransactionFeed);

/** @typedef {ReturnType<typeof prepareTransactionFeed>} TransactionFeed */
58 changes: 58 additions & 0 deletions packages/fast-usdc/src/fast-usdc.contract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { BrandShape } from '@agoric/ertp/src/typeGuards.js';
import { withOrchestration } from '@agoric/orchestration';
import { M } from '@endo/patterns';
import { assertAllDefined } from '@agoric/internal';
import { prepareTransactionFeed } from './exos/transaction-feed.js';
import { prepareSettler } from './exos/settler.js';
import { prepareAdvancer } from './exos/advancer.js';
import { prepareStatusManager } from './exos/status-manager.js';

/**
* @import {OrchestrationPowers, OrchestrationTools} from '@agoric/orchestration/src/utils/start-helper.js';
* @import {Zone} from '@agoric/zone';
*/

/**
* @typedef {{
* poolFee: Amount<'nat'>;
* contractFee: Amount<'nat'>;
* }} FastUsdcTerms
*/
const NatAmountShape = { brand: BrandShape, value: M.nat() };
export const meta = {
customTermsShape: {
contractFee: NatAmountShape,
poolFee: NatAmountShape,
},
};
harden(meta);

/**
* @param {ZCF<FastUsdcTerms>} zcf
* @param {OrchestrationPowers & {
* marshaller: Marshaller;
* }} privateArgs
* @param {Zone} zone
* @param {OrchestrationTools} tools
*/
export const contract = async (zcf, privateArgs, zone, tools) => {
assert(tools, 'no tools');
const terms = zcf.getTerms();
assert('USDC' in terms.brands, 'no USDC brand');
assert('PoolShares' in terms.brands, 'no PoolShares brand');

const statusManager = prepareStatusManager(zone);
const feed = prepareTransactionFeed(zone);
const settler = prepareSettler(zone, { statusManager });
const advancer = prepareAdvancer(zone, { feed, statusManager });
assertAllDefined({ feed, settler, advancer, statusManager });

const creatorFacet = zone.exo('Fast USDC Creator', undefined, {});

return harden({ creatorFacet });
};
harden(contract);

export const start = withOrchestration(contract);
harden(start);
/** @typedef {typeof start} FastUsdcSF */
35 changes: 35 additions & 0 deletions packages/fast-usdc/test/fast-usdc.contract.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js';

import { setUpZoeForTest } from '@agoric/zoe/tools/setup-zoe.js';
import { E } from '@endo/far';
import path from 'path';
import { commonSetup } from './supports.js';

const dirname = path.dirname(new URL(import.meta.url).pathname);

const contractFile = `${dirname}/../src/fast-usdc.contract.js`;
type StartFn = typeof import('../src/fast-usdc.contract.js').start;

test('start', async t => {
const {
bootstrap,
brands: { poolShares, usdc },
commonPrivateArgs,
utils,
} = await commonSetup(t);

const { zoe, bundleAndInstall } = await setUpZoeForTest();
const installation: Installation<StartFn> =
await bundleAndInstall(contractFile);

const { creatorFacet } = await E(zoe).startInstance(
installation,
{ PoolShares: poolShares.issuer, USDC: usdc.issuer },
{
poolFee: usdc.make(1n),
contractFee: usdc.make(1n),
},
commonPrivateArgs,
);
t.truthy(creatorFacet);
});
Loading

0 comments on commit 604ac38

Please sign in to comment.