Skip to content
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

convert fast-usdc contract to .ts #10480

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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) */
Expand All @@ -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(),
Expand All @@ -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<string, OperatorKit>;
pending: MapStore<string, MapStore<string, CctpTxEvidence>>;
}

export const prepareTransactionFeedKit = (zone: Zone, zcf: ZCF) => {
const kinds = zone.mapStore<string, unknown>('Kinds');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this unknown?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just didn't know what to type it and this worked

const makeDurablePublishKit = prepareDurablePublishKit(
kinds,
'Transaction Feed',
);
/** @type {PublishKit<CctpTxEvidence>} */
const { publisher, subscriber } = makeDurablePublishKit();
const { publisher, subscriber } = makeDurablePublishKit<CctpTxEvidence>();

const makeInertInvitation = defineInertInvitation(zcf, 'submitting evidence');

Expand All @@ -53,15 +49,16 @@ export const prepareTransactionFeedKit = (zone, zcf) => {
return zone.exoClassKit(
'Fast USDC Feed',
TransactionFeedKitI,
() => {
/** @type {MapStore<string, OperatorKit>} */
const operators = zone.mapStore('operators', {
durable: true,
});
/** @type {MapStore<string, MapStore<string, CctpTxEvidence>>} */
const pending = zone.mapStore('pending', {
(): State => {
const operators = zone.mapStore<string, OperatorKit>('operators', {
durable: true,
});
const pending = zone.mapStore<string, MapStore<string, CctpTxEvidence>>(
'pending',
{
durable: true,
},
);
return { operators, pending };
},
{
Expand All @@ -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<Invitation<OperatorKit>>}
* @param operatorId unique per contract instance
*/
makeOperatorInvitation(operatorId) {
makeOperatorInvitation(
operatorId: string,
): Promise<Invitation<OperatorKit>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why type the return? It seems the same value is inferred

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just moved from what was there. I'll leave since it doesn't hurt to be explicit

const { creator } = this.facets;
trace('makeOperatorInvitation', operatorId);

return zcf.makeInvitation(
/** @type {OfferHandler<OperatorKit>} */
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);

Expand All @@ -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);
Expand All @@ -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',
Expand Down Expand Up @@ -177,4 +169,6 @@ export const prepareTransactionFeedKit = (zone, zcf) => {
};
harden(prepareTransactionFeedKit);

/** @typedef {ReturnType<ReturnType<typeof prepareTransactionFeedKit>>} TransactionFeedKit */
export type TransactionFeedKit = ReturnType<
ReturnType<typeof prepareTransactionFeedKit>
>;
2 changes: 1 addition & 1 deletion packages/fast-usdc/src/fast-usdc.contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/fast-usdc/test/exos/transaction-feed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down