Skip to content

Commit 0ea3ad5

Browse files
authored
convert fast-usdc contract to .ts (#10480)
refs: #5760 ## Description Convert some `.js` files of the fast-usdc packages to `.ts`. I'd like to migrate to `.ts` incrementally because this package is in active development and if I were to migrate the whole thing now there would be lots of merge conflicts. ### Security Considerations As usual, readers must keep in mind that the types are advisory and be sure that adequate runtime validation is also in place. ### Scaling Considerations none ### Documentation Considerations Once this is working, we should convert the demo dapps to it to make them more accessible. ### Testing Considerations CI should cover it. ### Upgrade Considerations Should have no runtime impacts.
2 parents 962e6c4 + 60256aa commit 0ea3ad5

18 files changed

+307
-316
lines changed

packages/fast-usdc-contract/src/exos/advancer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { makeFeeTools } from '@agoric/fast-usdc/src/utils/fees.js';
2727
* @import {VowTools} from '@agoric/vow';
2828
* @import {Zone} from '@agoric/zone';
2929
* @import {AddressHook, EvmHash, FeeConfig, LogFn, NobleAddress, EvidenceWithRisk} from '@agoric/fast-usdc/src/types.js';
30-
* @import {StatusManager} from './status-manager.js';
30+
* @import {StatusManager} from './status-manager.ts';
3131
* @import {LiquidityPoolKit} from './liquidity-pool.js';
3232
*/
3333

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,45 @@
1+
import { OperatorKitI } from '@agoric/fast-usdc/src/operator-kit-interface.js';
12
import { makeTracer } from '@agoric/internal';
3+
import type { Zone } from '@agoric/zone';
24
import { Fail } from '@endo/errors';
3-
import { OperatorKitI } from '@agoric/fast-usdc/src/operator-kit-interface.js';
4-
5-
const trace = makeTracer('TxOperator');
5+
import type {
6+
CctpTxEvidence,
7+
RiskAssessment,
8+
} from '@agoric/fast-usdc/src/types.js';
69

7-
/**
8-
* @import {Zone} from '@agoric/zone';
9-
* @import {CctpTxEvidence, RiskAssessment} from '@agoric/fast-usdc/src/types.js';
10-
*/
10+
const trace: (...args: unknown[]) => void = makeTracer('TxOperator');
1111

12-
/**
13-
* @typedef {object} OperatorPowers
14-
* @property {(evidence: CctpTxEvidence, riskAssessment: RiskAssessment, operatorId: string) => void} attest
15-
*/
12+
interface OperatorPowers {
13+
attest: (
14+
evidence: CctpTxEvidence,
15+
riskAssessment: RiskAssessment,
16+
operatorId: string,
17+
) => void;
18+
}
1619

17-
/**
18-
* @typedef {object} OperatorStatus
19-
* @property {boolean} [disabled]
20-
* @property {string} operatorId
21-
*/
20+
interface OperatorStatus {
21+
disabled?: boolean;
22+
operatorId: string;
23+
}
2224

23-
/**
24-
* @typedef {Readonly<{ operatorId: string, powers: OperatorPowers }> & {disabled: boolean}} State
25-
*/
25+
interface State {
26+
operatorId: string;
27+
powers: OperatorPowers;
28+
disabled: boolean;
29+
}
2630

27-
/**
28-
* @param {Zone} zone
29-
* @param {{ makeInertInvitation: Function }} staticPowers
30-
*/
31-
export const prepareOperatorKit = (zone, staticPowers) =>
31+
export const prepareOperatorKit = (
32+
zone: Zone,
33+
staticPowers: { makeInertInvitation: () => Promise<Invitation> },
34+
) =>
3235
zone.exoClassKit(
3336
'Operator Kit',
3437
OperatorKitI,
3538
/**
36-
* @param {string} operatorId
37-
* @param {OperatorPowers} powers facet of the durable transaction feed
38-
* @returns {State}
39+
* @param operatorId
40+
* @param powers facet of the durable transaction feed
3941
*/
40-
(operatorId, powers) => {
42+
(operatorId: string, powers: OperatorPowers): State => {
4143
return {
4244
operatorId,
4345
powers,
@@ -64,33 +66,34 @@ export const prepareOperatorKit = (zone, staticPowers) =>
6466
* place, rather than as a means of performing it as in the
6567
* fluxAggregator contract used for price oracles.
6668
*
67-
* @param {CctpTxEvidence} evidence
68-
* @param {RiskAssessment} [riskAssessment]
69-
* @returns {Promise<Invitation>}
69+
* @param evidence
70+
* @param riskAssessment
7071
*/
71-
async SubmitEvidence(evidence, riskAssessment) {
72+
async SubmitEvidence(
73+
evidence: CctpTxEvidence,
74+
riskAssessment: RiskAssessment,
75+
): Promise<Invitation> {
7276
const { operator } = this.facets;
7377
operator.submitEvidence(evidence, riskAssessment);
74-
return staticPowers.makeInertInvitation(
75-
'evidence was pushed in the invitation maker call',
76-
);
78+
return staticPowers.makeInertInvitation();
7779
},
7880
},
7981
operator: {
8082
/**
8183
* submit evidence from this operator
8284
*
83-
* @param {CctpTxEvidence} evidence
84-
* @param {RiskAssessment} [riskAssessment]
85-
* @returns {void}
85+
* @param evidence
86+
* @param riskAssessment
8687
*/
87-
submitEvidence(evidence, riskAssessment = {}) {
88+
submitEvidence(
89+
evidence: CctpTxEvidence,
90+
riskAssessment: RiskAssessment = {},
91+
): void {
8892
const { state } = this;
8993
!state.disabled || Fail`submitEvidence for disabled operator`;
9094
state.powers.attest(evidence, riskAssessment, state.operatorId);
9195
},
92-
/** @returns {OperatorStatus} */
93-
getStatus() {
96+
getStatus(): OperatorStatus {
9497
const { state } = this;
9598
return {
9699
operatorId: state.operatorId,
@@ -101,4 +104,4 @@ export const prepareOperatorKit = (zone, staticPowers) =>
101104
},
102105
);
103106

104-
/** @typedef {ReturnType<ReturnType<typeof prepareOperatorKit>>} OperatorKit */
107+
export type OperatorKit = ReturnType<ReturnType<typeof prepareOperatorKit>>;

packages/fast-usdc-contract/src/exos/settler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { asMultiset } from '../utils/store.js';
2626
* @import {HostOf, HostInterface} from '@agoric/async-flow';
2727
* @import {TargetRegistration} from '@agoric/vats/src/bridge-target.js';
2828
* @import {NobleAddress, FeeConfig, EvmHash, LogFn, CctpTxEvidence} from '@agoric/fast-usdc/src/types.js';
29-
* @import {StatusManager} from './status-manager.js';
29+
* @import {StatusManager} from './status-manager.ts';
3030
* @import {LiquidityPoolKit} from './liquidity-pool.js';
3131
*/
3232

0 commit comments

Comments
 (0)