-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scaffold Fast USDC contract (#10383)
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
Showing
9 changed files
with
391 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
Oops, something went wrong.