From 653ec1f9e1fb78e4a892f4509cfe68a4a850b597 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Sun, 24 Nov 2024 11:43:45 -0800 Subject: [PATCH 1/6] build: support for .ts in JS bundles --- tsconfig.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tsconfig.json b/tsconfig.json index 628996edaba..bb3cc572b9e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,6 +15,10 @@ "noImplicitThis": true, "noUncheckedSideEffectImports": true, "verbatimModuleSyntax": true, + // .ts and rewriting relative paths allow us to include in bundles + // files that are JS executable (with TS chars blanked) but end in .ts + "allowImportingTsExtensions": true, + "rewriteRelativeImportExtensions": true, "noEmit": true }, "include": [ From f5aa6000ba5c83c730f5602d0ef5ab46dbea6af4 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Sat, 23 Nov 2024 17:38:30 -0800 Subject: [PATCH 2/6] feat(types): generic makeDurablePublishKit --- packages/inter-protocol/src/price/fluxAggregatorKit.js | 1 - packages/notifier/src/publish-kit.js | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/inter-protocol/src/price/fluxAggregatorKit.js b/packages/inter-protocol/src/price/fluxAggregatorKit.js index e538b207dfc..70ca977a817 100644 --- a/packages/inter-protocol/src/price/fluxAggregatorKit.js +++ b/packages/inter-protocol/src/price/fluxAggregatorKit.js @@ -130,7 +130,6 @@ export const prepareFluxAggregatorKit = async ( const makeOracleAdminKit = prepareOracleAdminKit(baggage); const makeRecorderKit = defineRecorderKit({ - // @ts-expect-error XXX makeDurablePublishKit, makeRecorder, }); diff --git a/packages/notifier/src/publish-kit.js b/packages/notifier/src/publish-kit.js index e2403db1455..f0912c2ab8f 100644 --- a/packages/notifier/src/publish-kit.js +++ b/packages/notifier/src/publish-kit.js @@ -402,15 +402,13 @@ const advanceDurablePublishKit = (context, value, targetStatus = 'live') => { /** * @param {import('@agoric/swingset-liveslots').Baggage} baggage * @param {string} kindName + * @returns {(options?: Parameters[0]) => PublishKit} */ export const prepareDurablePublishKit = (baggage, kindName) => { // TODO: Once we unify with makePublishKit, we will use a Zone-compatible weak // map for memoization. const makeMemoizedUpdateRecord = makeUpdateRecordFromPublicationRecord; - /** - * @returns {() => PublishKit<*>} - */ return prepareExoClassKit( baggage, kindName, From f531c7f16d470ece06f6e4caf5ec0ab3fa786a27 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Sat, 23 Nov 2024 17:38:48 -0800 Subject: [PATCH 3/6] feat(types): generic zone.mapStore --- packages/base-zone/src/types.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/base-zone/src/types.js b/packages/base-zone/src/types.js index 26ddc574df4..2adedd5247c 100644 --- a/packages/base-zone/src/types.js +++ b/packages/base-zone/src/types.js @@ -33,7 +33,7 @@ export {}; * @typedef {object} Stores * @property {() => Stores} detached obtain store providers which are detached (the stores are anonymous rather than bound to `label` in the zone) * @property {(specimen: unknown) => boolean} isStorable return true if the specimen can be stored in the zone, whether as exo-object state or in a store - * @property {(label: string, options?: StoreOptions) => MapStore} mapStore provide a Map-like store named `label` in the zone + * @property {(label: string, options?: StoreOptions) => MapStore} mapStore provide a Map-like store named `label` in the zone * @property {(label: string, options?: StoreOptions) => SetStore} setStore provide a Set-like store named `label` in the zone * @property {( * label: string, options?: StoreOptions) => WeakMapStore From 384916e1a1aae0ffefa9c4c03050a91fb77e98ad Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 13 Nov 2024 17:43:56 -0800 Subject: [PATCH 4/6] refactor: fast-usdc.contract to .ts --- .../scripts/fast-usdc/init-fast-usdc.js | 2 +- ...usdc.contract.js => fast-usdc.contract.ts} | 108 ++++++++---------- packages/fast-usdc/src/fast-usdc.start.js | 2 +- packages/fast-usdc/src/type-guards.js | 2 +- .../fast-usdc/test/fast-usdc.contract.test.ts | 6 +- 5 files changed, 55 insertions(+), 65 deletions(-) rename packages/fast-usdc/src/{fast-usdc.contract.js => fast-usdc.contract.ts} (75%) diff --git a/packages/builders/scripts/fast-usdc/init-fast-usdc.js b/packages/builders/scripts/fast-usdc/init-fast-usdc.js index 08a5d996cdb..16bb6d5b142 100644 --- a/packages/builders/scripts/fast-usdc/init-fast-usdc.js +++ b/packages/builders/scripts/fast-usdc/init-fast-usdc.js @@ -164,7 +164,7 @@ export const defaultProposalBuilder = async ( options: toExternalConfig(config, crossVatContext, FastUSDCConfigShape), installKeys: { fastUsdc: publishRef( - install('@agoric/fast-usdc/src/fast-usdc.contract.js'), + install('@agoric/fast-usdc/src/fast-usdc.contract.ts'), ), }, }, diff --git a/packages/fast-usdc/src/fast-usdc.contract.js b/packages/fast-usdc/src/fast-usdc.contract.ts similarity index 75% rename from packages/fast-usdc/src/fast-usdc.contract.js rename to packages/fast-usdc/src/fast-usdc.contract.ts index 0d838534184..39fc1f0a977 100644 --- a/packages/fast-usdc/src/fast-usdc.contract.js +++ b/packages/fast-usdc/src/fast-usdc.contract.ts @@ -8,45 +8,42 @@ import { observeIteration, subscribeEach } from '@agoric/notifier'; import { OrchestrationPowersShape, withOrchestration, + type Denom, + type OrchestrationAccount, + type OrchestrationPowers, + type OrchestrationTools, } from '@agoric/orchestration'; +import { makeZoeTools } from '@agoric/orchestration/src/utils/zoe-tools.js'; import { provideSingleton } from '@agoric/zoe/src/contractSupport/durability.js'; import { prepareRecorderKitMakers } from '@agoric/zoe/src/contractSupport/recorder.js'; -import { makeZoeTools } from '@agoric/orchestration/src/utils/zoe-tools.js'; import { depositToSeat } from '@agoric/zoe/src/contractSupport/zoeHelpers.js'; import { E } from '@endo/far'; import { M, objectMap } from '@endo/patterns'; +import type { Zone } from '@agoric/zone'; +import type { HostInterface } from '@agoric/async-flow'; +import type { Vow } from '@agoric/vow'; import { prepareAdvancer } from './exos/advancer.js'; -import { prepareLiquidityPoolKit } from './exos/liquidity-pool.js'; +import { + prepareLiquidityPoolKit, + type RepayAmountKWR, + type RepayPaymentKWR, +} from './exos/liquidity-pool.js'; import { prepareSettler } from './exos/settler.js'; import { prepareStatusManager } from './exos/status-manager.js'; import { prepareTransactionFeedKit } from './exos/transaction-feed.js'; -import { defineInertInvitation } from './utils/zoe.js'; -import { FastUSDCTermsShape, FeeConfigShape } from './type-guards.js'; import * as flows from './fast-usdc.flows.js'; +import { FastUSDCTermsShape, FeeConfigShape } from './type-guards.js'; +import { defineInertInvitation } from './utils/zoe.js'; +import type { CctpTxEvidence, FeeConfig } from './types.js'; +import type { OperatorKit } from './exos/operator-kit.js'; const trace = makeTracer('FastUsdc'); -/** - * @import {Denom} from '@agoric/orchestration'; - * @import {HostInterface} from '@agoric/async-flow'; - * @import {OrchestrationAccount} from '@agoric/orchestration'; - * @import {OrchestrationPowers, OrchestrationTools} from '@agoric/orchestration/src/utils/start-helper.js'; - * @import {Vow} from '@agoric/vow'; - * @import {Zone} from '@agoric/zone'; - * @import {OperatorKit} from './exos/operator-kit.js'; - * @import {CctpTxEvidence, FeeConfig} from './types.js'; - * @import {RepayAmountKWR, RepayPaymentKWR} from './exos/liquidity-pool.js'; - */ - -/** - * @typedef {{ - * usdcDenom: Denom; - * }} FastUsdcTerms - */ - -/** @type {ContractMeta} */ +export type FastUsdcTerms = { + usdcDenom: Denom; +}; + export const meta = { - // @ts-expect-error TypedPattern not recognized as record customTermsShape: FastUSDCTermsShape, privateArgsShape: { // @ts-expect-error TypedPattern not recognized as record @@ -54,19 +51,19 @@ export const meta = { feeConfig: FeeConfigShape, marshaller: M.remotable(), }, -}; +} as ContractMeta; harden(meta); -/** - * @param {ZCF} zcf - * @param {OrchestrationPowers & { - * marshaller: Marshaller; - * feeConfig: FeeConfig; - * }} privateArgs - * @param {Zone} zone - * @param {OrchestrationTools} tools - */ -export const contract = async (zcf, privateArgs, zone, tools) => { +export const contract = async ( + zcf: ZCF, + privateArgs: OrchestrationPowers & { + feeConfig: FeeConfig; + marshaller: Marshaller; + storageNode: StorageNode; + }, + zone: Zone, + tools: OrchestrationTools, +) => { assert(tools, 'no tools'); const terms = zcf.getTerms(); assert('USDC' in terms.brands, 'no USDC brand'); @@ -109,27 +106,21 @@ export const contract = async (zcf, privateArgs, zone, tools) => { const { makeLocalAccount } = orchestrateAll(flows, {}); const creatorFacet = zone.exo('Fast USDC Creator', undefined, { - /** @type {(operatorId: string) => Promise>} */ - async makeOperatorInvitation(operatorId) { - // eslint-disable-next-line no-use-before-define + async makeOperatorInvitation( + operatorId: string, + ): Promise> { return feedKit.creator.makeOperatorInvitation(operatorId); }, - /** - * @param {{ USDC: Amount<'nat'>}} amounts - */ - testBorrow(amounts) { + testBorrow(amounts: { USDC: Amount<'nat'> }) { console.log('🚧🚧 UNTIL: borrow is integrated (#10388) 🚧🚧', amounts); const { zcfSeat: tmpAssetManagerSeat } = zcf.makeEmptySeatKit(); poolKit.borrower.borrow(tmpAssetManagerSeat, amounts); return tmpAssetManagerSeat.getCurrentAllocation(); }, - /** - * - * @param {RepayAmountKWR} amounts - * @param {RepayPaymentKWR} payments - * @returns {Promise} - */ - async testRepay(amounts, payments) { + async testRepay( + amounts: RepayAmountKWR, + payments: RepayPaymentKWR, + ): Promise { console.log('🚧🚧 UNTIL: repay is integrated (#10388) 🚧🚧', amounts); const { zcfSeat: tmpAssetManagerSeat } = zcf.makeEmptySeatKit(); await depositToSeat( @@ -154,10 +145,9 @@ export const contract = async (zcf, privateArgs, zone, tools) => { * Provide an API call in the form of an invitation maker, so that the * capability is available in the smart-wallet bridge during UI testing. * - * @param {CctpTxEvidence} evidence + * @param evidence */ - makeTestPushInvitation(evidence) { - // eslint-disable-next-line no-use-before-define + makeTestPushInvitation(evidence: CctpTxEvidence) { void advancer.handleTransactionEvent(evidence); return makeTestInvitation(); }, @@ -200,13 +190,12 @@ export const contract = async (zcf, privateArgs, zone, tools) => { const feedKit = zone.makeOnce('Feed Kit', () => makeFeedKit()); - const poolAccountV = + const poolAccountV = zone.makeOnce('Pool Local Orch Account', () => + makeLocalAccount(), + ) as unknown as Vow< // cast to HostInterface - /** @type { Vow>>} */ ( - /** @type {unknown}*/ ( - zone.makeOnce('Pool Local Orch Account', () => makeLocalAccount()) - ) - ); + HostInterface> + >; const poolAccount = await vowTools.when(poolAccountV); const advancer = zone.makeOnce('Advancer', () => @@ -232,4 +221,5 @@ harden(contract); export const start = withOrchestration(contract); harden(start); -/** @typedef {typeof start} FastUsdcSF */ + +export type FastUsdcSF = typeof start; diff --git a/packages/fast-usdc/src/fast-usdc.start.js b/packages/fast-usdc/src/fast-usdc.start.js index 96f14569dad..a2a3377fcea 100644 --- a/packages/fast-usdc/src/fast-usdc.start.js +++ b/packages/fast-usdc/src/fast-usdc.start.js @@ -19,7 +19,7 @@ import { fromExternalConfig } from './utils/config-marshal.js'; * @import {BootstrapManifest} from '@agoric/vats/src/core/lib-boot.js' * @import {Passable} from '@endo/marshal'; * @import {LegibleCapData} from './utils/config-marshal.js' - * @import {FastUsdcSF, FastUsdcTerms} from './fast-usdc.contract.js' + * @import {FastUsdcSF, FastUsdcTerms} from './fast-usdc.contract.ts' * @import {FeeConfig, FeedPolicy} from './types.js' */ diff --git a/packages/fast-usdc/src/type-guards.js b/packages/fast-usdc/src/type-guards.js index 425551bea65..aa334c6d719 100644 --- a/packages/fast-usdc/src/type-guards.js +++ b/packages/fast-usdc/src/type-guards.js @@ -4,7 +4,7 @@ import { PendingTxStatus } from './constants.js'; /** * @import {TypedPattern} from '@agoric/internal'; - * @import {FastUsdcTerms} from './fast-usdc.contract.js'; + * @import {FastUsdcTerms} from './fast-usdc.contract.ts'; * @import {USDCProposalShapes} from './pool-share-math.js'; * @import {CctpTxEvidence, FeeConfig, PendingTx, PoolMetrics, ChainPolicy, FeedPolicy} from './types.js'; */ diff --git a/packages/fast-usdc/test/fast-usdc.contract.test.ts b/packages/fast-usdc/test/fast-usdc.contract.test.ts index e697b9118da..50357d66c43 100644 --- a/packages/fast-usdc/test/fast-usdc.contract.test.ts +++ b/packages/fast-usdc/test/fast-usdc.contract.test.ts @@ -20,15 +20,15 @@ import { deeplyFulfilledObject } from '@agoric/internal'; import type { Subscriber } from '@agoric/notifier'; import { MockCctpTxEvidences } from './fixtures.js'; import { commonSetup } from './supports.js'; -import type { FastUsdcTerms } from '../src/fast-usdc.contract.js'; +import type { FastUsdcTerms } from '../src/fast-usdc.contract.ts'; import { makeFeeTools } from '../src/utils/fees.js'; import type { PoolMetrics } from '../src/types.js'; import { addressTools } from '../src/utils/address.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; +const contractFile = `${dirname}/../src/fast-usdc.contract.ts`; +type StartFn = typeof import('../src/fast-usdc.contract.ts').start; const { add, isGTE, subtract } = AmountMath; From d46b152bb96956e3565cdaf4dfb36e24d746748b Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Sat, 23 Nov 2024 17:29:51 -0800 Subject: [PATCH 5/6] refactor: Convert transaction-feed.js to TypeScript --- ...ransaction-feed.js => transaction-feed.ts} | 78 +++++++++---------- packages/fast-usdc/src/fast-usdc.contract.ts | 2 +- .../test/exos/transaction-feed.test.ts | 2 +- 3 files changed, 38 insertions(+), 44 deletions(-) rename packages/fast-usdc/src/exos/{transaction-feed.js => transaction-feed.ts} (73%) diff --git a/packages/fast-usdc/src/exos/transaction-feed.js b/packages/fast-usdc/src/exos/transaction-feed.ts similarity index 73% rename from packages/fast-usdc/src/exos/transaction-feed.js rename to packages/fast-usdc/src/exos/transaction-feed.ts index 782236d615f..ba83374d908 100644 --- a/packages/fast-usdc/src/exos/transaction-feed.js +++ b/packages/fast-usdc/src/exos/transaction-feed.ts @@ -1,16 +1,13 @@ import { makeTracer } from '@agoric/internal'; import { prepareDurablePublishKit } from '@agoric/notifier'; +import type { Zone } from '@agoric/zone'; import { M } from '@endo/patterns'; import { CctpTxEvidenceShape } from '../type-guards.js'; +import type { CctpTxEvidence } from '../types.js'; import { defineInertInvitation } from '../utils/zoe.js'; +import type { OperatorKit } from './operator-kit.js'; import { prepareOperatorKit } from './operator-kit.js'; -/** - * @import {Zone} from '@agoric/zone'; - * @import {OperatorKit} from './operator-kit.js'; - * @import {CctpTxEvidence} from '../types.js'; - */ - const trace = makeTracer('TxFeed', true); /** Name in the invitation purse (keyed also by this contract instance) */ @@ -21,7 +18,6 @@ const TransactionFeedKitI = harden({ submitEvidence: M.call(CctpTxEvidenceShape, M.any()).returns(), }), creator: M.interface('Transaction Feed Creator', { - // TODO narrow the return shape to OperatorKit initOperator: M.call(M.string()).returns(M.record()), makeOperatorInvitation: M.call(M.string()).returns(M.promise()), removeOperator: M.call(M.string()).returns(), @@ -31,18 +27,18 @@ const TransactionFeedKitI = harden({ }), }); -/** - * @param {Zone} zone - * @param {ZCF} zcf - */ -export const prepareTransactionFeedKit = (zone, zcf) => { - const kinds = zone.mapStore('Kinds'); +interface State { + operators: MapStore; + pending: MapStore>; +} + +export const prepareTransactionFeedKit = (zone: Zone, zcf: ZCF) => { + const kinds = zone.mapStore('Kinds'); const makeDurablePublishKit = prepareDurablePublishKit( kinds, 'Transaction Feed', ); - /** @type {PublishKit} */ - const { publisher, subscriber } = makeDurablePublishKit(); + const { publisher, subscriber } = makeDurablePublishKit(); const makeInertInvitation = defineInertInvitation(zcf, 'submitting evidence'); @@ -53,15 +49,16 @@ export const prepareTransactionFeedKit = (zone, zcf) => { return zone.exoClassKit( 'Fast USDC Feed', TransactionFeedKitI, - () => { - /** @type {MapStore} */ - const operators = zone.mapStore('operators', { - durable: true, - }); - /** @type {MapStore>} */ - const pending = zone.mapStore('pending', { + (): State => { + const operators = zone.mapStore('operators', { durable: true, }); + const pending = zone.mapStore>( + 'pending', + { + durable: true, + }, + ); return { operators, pending }; }, { @@ -71,24 +68,21 @@ export const prepareTransactionFeedKit = (zone, zcf) => { * oracle network, with the able to submit data to submit evidence of * CCTP transactions. * - * @param {string} operatorId unique per contract instance - * @returns {Promise>} + * @param operatorId unique per contract instance */ - makeOperatorInvitation(operatorId) { + makeOperatorInvitation( + operatorId: string, + ): Promise> { const { creator } = this.facets; trace('makeOperatorInvitation', operatorId); - return zcf.makeInvitation( - /** @type {OfferHandler} */ - seat => { - seat.exit(); - return creator.initOperator(operatorId); - }, - INVITATION_MAKERS_DESC, - ); + return zcf.makeInvitation(seat => { + seat.exit(); + return creator.initOperator(operatorId); + }, INVITATION_MAKERS_DESC); }, - /** @param {string} operatorId */ - initOperator(operatorId) { + + initOperator(operatorId: string) { const { operators, pending } = this.state; trace('initOperator', operatorId); @@ -105,8 +99,7 @@ export const prepareTransactionFeedKit = (zone, zcf) => { return operatorKit; }, - /** @param {string} operatorId */ - async removeOperator(operatorId) { + async removeOperator(operatorId: string) { const { operators } = this.state; trace('removeOperator', operatorId); const operatorKit = operators.get(operatorId); @@ -117,11 +110,10 @@ export const prepareTransactionFeedKit = (zone, zcf) => { operatorPowers: { /** * Add evidence from an operator. - * - * @param {CctpTxEvidence} evidence - * @param {OperatorKit} operatorKit + * @param evidence + * @param operatorKit */ - submitEvidence(evidence, operatorKit) { + submitEvidence(evidence: CctpTxEvidence, operatorKit: OperatorKit) { const { pending } = this.state; trace( 'submitEvidence', @@ -177,4 +169,6 @@ export const prepareTransactionFeedKit = (zone, zcf) => { }; harden(prepareTransactionFeedKit); -/** @typedef {ReturnType>} TransactionFeedKit */ +export type TransactionFeedKit = ReturnType< + ReturnType +>; diff --git a/packages/fast-usdc/src/fast-usdc.contract.ts b/packages/fast-usdc/src/fast-usdc.contract.ts index 39fc1f0a977..96ae382aa0f 100644 --- a/packages/fast-usdc/src/fast-usdc.contract.ts +++ b/packages/fast-usdc/src/fast-usdc.contract.ts @@ -30,7 +30,7 @@ import { } from './exos/liquidity-pool.js'; import { prepareSettler } from './exos/settler.js'; import { prepareStatusManager } from './exos/status-manager.js'; -import { prepareTransactionFeedKit } from './exos/transaction-feed.js'; +import { prepareTransactionFeedKit } from './exos/transaction-feed.ts'; import * as flows from './fast-usdc.flows.js'; import { FastUSDCTermsShape, FeeConfigShape } from './type-guards.js'; import { defineInertInvitation } from './utils/zoe.js'; diff --git a/packages/fast-usdc/test/exos/transaction-feed.test.ts b/packages/fast-usdc/test/exos/transaction-feed.test.ts index 5f11c504dc2..28e710d1de7 100644 --- a/packages/fast-usdc/test/exos/transaction-feed.test.ts +++ b/packages/fast-usdc/test/exos/transaction-feed.test.ts @@ -6,7 +6,7 @@ import { makeHeapZone } from '@agoric/zone'; import { prepareTransactionFeedKit, type TransactionFeedKit, -} from '../../src/exos/transaction-feed.js'; +} from '../../src/exos/transaction-feed.ts'; import { MockCctpTxEvidences } from '../fixtures.js'; const nullZcf = null as any; From 2899c22faa0cc1c03493fe3a0d9d6b28b95a0a8d Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Sat, 23 Nov 2024 17:44:36 -0800 Subject: [PATCH 6/6] refactor: convert operator-kit to .ts --- .../exos/{operator-kit.js => operator-kit.ts} | 71 +++++++++---------- .../fast-usdc/src/exos/transaction-feed.ts | 4 +- packages/fast-usdc/src/fast-usdc.contract.ts | 2 +- 3 files changed, 35 insertions(+), 42 deletions(-) rename packages/fast-usdc/src/exos/{operator-kit.js => operator-kit.ts} (62%) diff --git a/packages/fast-usdc/src/exos/operator-kit.js b/packages/fast-usdc/src/exos/operator-kit.ts similarity index 62% rename from packages/fast-usdc/src/exos/operator-kit.js rename to packages/fast-usdc/src/exos/operator-kit.ts index 08b3ac9c368..da80ed333f5 100644 --- a/packages/fast-usdc/src/exos/operator-kit.js +++ b/packages/fast-usdc/src/exos/operator-kit.ts @@ -1,35 +1,36 @@ import { makeTracer } from '@agoric/internal'; import { Fail } from '@endo/errors'; import { M } from '@endo/patterns'; +import type { Zone } from '@agoric/zone'; import { CctpTxEvidenceShape } from '../type-guards.js'; +import type { CctpTxEvidence } from '../types.js'; -const trace = makeTracer('TxOperator'); +const trace: (message: string) => void = makeTracer('TxOperator'); -/** - * @import {Zone} from '@agoric/zone'; - * @import {CctpTxEvidence} from '../types.js'; - */ +interface OperatorPowers { + submitEvidence: (evidence: CctpTxEvidence, operatorKit: OperatorKit) => void; +} -/** - * @typedef {object} OperatorPowers - * @property {(evidence: CctpTxEvidence, operatorKit: OperatorKit) => void} submitEvidence - */ +interface OperatorStatus { + disabled?: boolean; + operatorId: string; +} -/** - * @typedef {object} OperatorStatus - * @property {boolean} [disabled] - * @property {string} operatorId - */ - -/** - * @typedef {Readonly<{ operatorId: string, powers: OperatorPowers }> & {disabled: boolean}} State - */ +interface State { + operatorId: string; + powers: OperatorPowers; + disabled: boolean; +} const OperatorKitI = { admin: M.interface('Admin', { disable: M.call().returns(), }), + /** + * NB: when this kit is an offer result, the smart-wallet will detect the `invitationMakers` + * key and save it for future offers. + */ invitationMakers: M.interface('InvitationMakers', { SubmitEvidence: M.call(CctpTxEvidenceShape).returns(M.promise()), }), @@ -40,20 +41,18 @@ const OperatorKitI = { }), }; -/** - * @param {Zone} zone - * @param {{ makeInertInvitation: Function }} staticPowers - */ -export const prepareOperatorKit = (zone, staticPowers) => +export const prepareOperatorKit = ( + zone: Zone, + staticPowers: { makeInertInvitation: Function }, +) => zone.exoClassKit( 'Operator Kit', OperatorKitI, /** - * @param {string} operatorId - * @param {OperatorPowers} powers facet of the durable transaction feed - * @returns {State} + * @param operatorId + * @param powers facet of the durable transaction feed */ - (operatorId, powers) => { + (operatorId: string, powers: OperatorPowers): State => { return { operatorId, powers, @@ -67,10 +66,6 @@ export const prepareOperatorKit = (zone, staticPowers) => this.state.disabled = true; }, }, - /** - * NB: when this kit is an offer result, the smart-wallet will detect the `invitationMakers` - * key and save it for future offers. - */ invitationMakers: { /** * Provide an API call in the form of an invitation maker, so that the @@ -80,10 +75,9 @@ export const prepareOperatorKit = (zone, staticPowers) => * place, rather than as a means of performing it as in the * fluxAggregator contract used for price oracles. * - * @param {CctpTxEvidence} evidence - * @returns {Promise} + * @param evidence */ - async SubmitEvidence(evidence) { + async SubmitEvidence(evidence: CctpTxEvidence): Promise { const { operator } = this.facets; // TODO(bootstrap integration): cause this call to throw and confirm that it // shows up in the the smart-wallet UpdateRecord `error` property @@ -97,16 +91,15 @@ export const prepareOperatorKit = (zone, staticPowers) => /** * submit evidence from this operator * - * @param {CctpTxEvidence} evidence + * @param evidence */ - async submitEvidence(evidence) { + async submitEvidence(evidence: CctpTxEvidence): Promise { const { state } = this; !state.disabled || Fail`submitEvidence for disabled operator`; const result = state.powers.submitEvidence(evidence, this.facets); return result; }, - /** @returns {OperatorStatus} */ - getStatus() { + getStatus(): OperatorStatus { const { state } = this; return { operatorId: state.operatorId, @@ -117,4 +110,4 @@ export const prepareOperatorKit = (zone, staticPowers) => }, ); -/** @typedef {ReturnType>} OperatorKit */ +export type OperatorKit = ReturnType>; diff --git a/packages/fast-usdc/src/exos/transaction-feed.ts b/packages/fast-usdc/src/exos/transaction-feed.ts index ba83374d908..f05dbee368c 100644 --- a/packages/fast-usdc/src/exos/transaction-feed.ts +++ b/packages/fast-usdc/src/exos/transaction-feed.ts @@ -5,8 +5,8 @@ import { M } from '@endo/patterns'; import { CctpTxEvidenceShape } from '../type-guards.js'; import type { CctpTxEvidence } from '../types.js'; import { defineInertInvitation } from '../utils/zoe.js'; -import type { OperatorKit } from './operator-kit.js'; -import { prepareOperatorKit } from './operator-kit.js'; +import type { OperatorKit } from './operator-kit.ts'; +import { prepareOperatorKit } from './operator-kit.ts'; const trace = makeTracer('TxFeed', true); diff --git a/packages/fast-usdc/src/fast-usdc.contract.ts b/packages/fast-usdc/src/fast-usdc.contract.ts index 96ae382aa0f..502da5d7343 100644 --- a/packages/fast-usdc/src/fast-usdc.contract.ts +++ b/packages/fast-usdc/src/fast-usdc.contract.ts @@ -35,7 +35,7 @@ import * as flows from './fast-usdc.flows.js'; import { FastUSDCTermsShape, FeeConfigShape } from './type-guards.js'; import { defineInertInvitation } from './utils/zoe.js'; import type { CctpTxEvidence, FeeConfig } from './types.js'; -import type { OperatorKit } from './exos/operator-kit.js'; +import type { OperatorKit } from './exos/operator-kit.ts'; const trace = makeTracer('FastUsdc');