-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
10387 simple transaction feed for Fast USDC #10452
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,53 @@ | ||
import { makeTracer } from '@agoric/internal'; | ||
import { prepareDurablePublishKit } from '@agoric/notifier'; | ||
import { M } from '@endo/patterns'; | ||
import { CctpTxEvidenceShape } from '../typeGuards.js'; | ||
|
||
/** | ||
* @import {Zone} from '@agoric/zone'; | ||
* @import {CctpTxEvidence} from '../types.js'; | ||
*/ | ||
|
||
const trace = makeTracer('TxFeed', true); | ||
|
||
export const INVITATION_MAKERS_DESC = 'transaction oracle invitation'; | ||
|
||
const TransactionFeedKitI = harden({ | ||
admin: M.interface('Transaction Feed Admin', { | ||
submitEvidence: M.call(CctpTxEvidenceShape).returns(), | ||
}), | ||
public: M.interface('Transaction Feed Public', { | ||
getEvidenceStream: M.call().returns(M.remotable()), | ||
}), | ||
}); | ||
|
||
/** | ||
* @param {Zone} zone | ||
*/ | ||
export const prepareTransactionFeed = zone => { | ||
return zone.exo('Fast USDC Feed', undefined, {}); | ||
export const prepareTransactionFeedKit = zone => { | ||
const kinds = zone.mapStore('Kinds'); | ||
const makeDurablePublishKit = prepareDurablePublishKit( | ||
kinds, | ||
'Transaction Feed', | ||
); | ||
/** @type {PublishKit<CctpTxEvidence>} */ | ||
const { publisher, subscriber } = makeDurablePublishKit(); | ||
|
||
return zone.exoClassKit('Fast USDC Feed', TransactionFeedKitI, () => ({}), { | ||
admin: { | ||
/** @param {CctpTxEvidence } evidence */ | ||
submitEvidence: evidence => { | ||
trace('TEMPORARY: Add evidence:', evidence); | ||
// TODO decentralize | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider:
|
||
// TODO validate that it's valid to publish | ||
publisher.publish(evidence); | ||
}, | ||
}, | ||
public: { | ||
getEvidenceStream: () => subscriber, | ||
}, | ||
}); | ||
}; | ||
harden(prepareTransactionFeed); | ||
harden(prepareTransactionFeedKit); | ||
|
||
/** @typedef {ReturnType<typeof prepareTransactionFeed>} TransactionFeed */ | ||
/** @typedef {ReturnType<typeof prepareTransactionFeedKit>} TransactionFeedKit */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
import { BrandShape } from '@agoric/ertp/src/typeGuards.js'; | ||
import { assertAllDefined, makeTracer } from '@agoric/internal'; | ||
import { observeIteration, subscribeEach } from '@agoric/notifier'; | ||
import { withOrchestration } from '@agoric/orchestration'; | ||
import { M } from '@endo/patterns'; | ||
import { assertAllDefined, makeTracer } from '@agoric/internal'; | ||
import { prepareTransactionFeed } from './exos/transaction-feed.js'; | ||
import { prepareSettler } from './exos/settler.js'; | ||
import { prepareAdvancer } from './exos/advancer.js'; | ||
import { prepareSettler } from './exos/settler.js'; | ||
import { prepareStatusManager } from './exos/status-manager.js'; | ||
import { prepareTransactionFeedKit } from './exos/transaction-feed.js'; | ||
|
||
const trace = makeTracer('FastUsdc'); | ||
|
||
/** | ||
* @import {OrchestrationPowers, OrchestrationTools} from '@agoric/orchestration/src/utils/start-helper.js'; | ||
* @import {Zone} from '@agoric/zone'; | ||
* @import {CctpTxEvidence} from './types.js'; | ||
*/ | ||
|
||
/** | ||
|
@@ -44,21 +46,58 @@ export const contract = async (zcf, privateArgs, zone, tools) => { | |
assert('PoolShares' in terms.brands, 'no PoolShares brand'); | ||
|
||
const statusManager = prepareStatusManager(zone); | ||
const feed = prepareTransactionFeed(zone); | ||
const makeSettler = prepareSettler(zone, { statusManager }); | ||
const { chainHub, vowTools } = tools; | ||
const makeAdvancer = prepareAdvancer(zone, { | ||
chainHub, | ||
feed, | ||
log: trace, | ||
statusManager, | ||
vowTools, | ||
}); | ||
assertAllDefined({ feed, makeAdvancer, makeSettler, statusManager }); | ||
const makeFeedKit = prepareTransactionFeedKit(zone); | ||
assertAllDefined({ makeFeedKit, makeAdvancer, makeSettler, statusManager }); | ||
const feedKit = makeFeedKit(); | ||
const advancer = makeAdvancer( | ||
// @ts-expect-error FIXME | ||
{}, | ||
); | ||
// Connect evidence stream to advancer | ||
void observeIteration(subscribeEach(feedKit.public.getEvidenceStream()), { | ||
updateState(evidence) { | ||
try { | ||
advancer.handleTransactionEvent(evidence); | ||
} catch (err) { | ||
trace('🚨 Error handling transaction event', err); | ||
} | ||
}, | ||
}); | ||
Comment on lines
+65
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, first time seeing this API. Surprised the second argument doesn't need to be a remotable, but that's convenient here. Are there scenarios where we'd hid the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good questions. It may need to be durable but that's for Milestone 2. If the stream dies, I don't think resubscribing would be safe. It's an unhandled rejection that will need a Core Eval to repair. |
||
|
||
const creatorFacet = zone.exo('Fast USDC Creator', undefined, {}); | ||
|
||
return harden({ creatorFacet }); | ||
const publicFacet = zone.exo('Fast USDC Public', undefined, { | ||
// XXX to be removed before production | ||
/** | ||
* NB: Any caller with access to this invitation maker has the ability to | ||
* add evidence. | ||
* | ||
* Provide an API call in the form of an invitation maker, so that the | ||
* capability is available in the smart-wallet bridge. | ||
* | ||
* @param {CctpTxEvidence} evidence | ||
*/ | ||
makeTestPushInvitation(evidence) { | ||
// TODO(bootstrap integration): force this to throw and confirm that it | ||
// shows up in the the smart-wallet UpdateRecord `error` property | ||
feedKit.admin.submitEvidence(evidence); | ||
return zcf.makeInvitation(async cSeat => { | ||
trace('Offer made on noop invitation'); | ||
cSeat.exit(); | ||
return 'noop; evidence was pushed in the invitation maker call'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That makes sense for offers that get used, but this one is not supposed to be used. So it should be conspicuously different. |
||
}, 'noop invitation'); | ||
}, | ||
}); | ||
|
||
return harden({ creatorFacet, publicFacet }); | ||
}; | ||
harden(contract); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Must be first to set up globals | ||
import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; | ||
|
||
import { makeHeapZone } from '@agoric/zone'; | ||
import { prepareTransactionFeedKit } from '../../src/exos/transaction-feed.js'; | ||
|
||
test('basics', t => { | ||
const zone = makeHeapZone(); | ||
const kit = prepareTransactionFeedKit(zone); | ||
t.deepEqual(Object.values(kit), []); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ 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 fetchedChainInfo from '@agoric/orchestration/src/fetched-chain-info.js'; | ||
import { MockCctpTxEvidences } from './fixtures.js'; | ||
import { commonSetup } from './supports.js'; | ||
|
||
const dirname = path.dirname(new URL(import.meta.url).pathname); | ||
|
@@ -12,17 +14,20 @@ 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 { zoe, bundleAndInstall } = await setUpZoeForTest({ | ||
setJig: jig => { | ||
jig.chainHub.registerChain('osmosis', fetchedChainInfo.osmosis); | ||
}, | ||
Comment on lines
+22
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, great approach for now. We'll need to revisit in a future milestone when we do bootstrap and multichain testing. |
||
}); | ||
|
||
const installation: Installation<StartFn> = | ||
await bundleAndInstall(contractFile); | ||
|
||
const { creatorFacet } = await E(zoe).startInstance( | ||
const { creatorFacet, publicFacet } = await E(zoe).startInstance( | ||
installation, | ||
{ PoolShares: poolShares.issuer, USDC: usdc.issuer }, | ||
{ | ||
|
@@ -32,4 +37,16 @@ test('start', async t => { | |
commonPrivateArgs, | ||
); | ||
t.truthy(creatorFacet); | ||
|
||
const e1 = await E(MockCctpTxEvidences.AGORIC_NO_PARAMS)(); | ||
|
||
const inv = await E(publicFacet).makeTestPushInvitation(e1); | ||
// the invitation maker itself pushes the evidence | ||
|
||
// the offer is still safe to make | ||
const seat = await E(zoe).offer(inv); | ||
t.is( | ||
await E(seat).getOfferResult(), | ||
'noop; evidence was pushed in the invitation maker call', | ||
); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider a more global name (wrt fusdc) since we're exporting