Skip to content

Commit a1d931d

Browse files
committed
refactor: single type-guards.js file
1 parent 14ec771 commit a1d931d

10 files changed

+60
-65
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { VowShape } from '@agoric/vow';
66
import { q } from '@endo/errors';
77
import { E } from '@endo/far';
88
import { M } from '@endo/patterns';
9-
import { CctpTxEvidenceShape, EudParamShape } from '../typeGuards.js';
9+
import { CctpTxEvidenceShape, EudParamShape } from '../type-guards.js';
1010
import { addressTools } from '../utils/address.js';
1111
import { makeFeeTools } from '../utils/fees.js';
1212

packages/fast-usdc/src/exos/operator-kit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { makeTracer } from '@agoric/internal';
22
import { Fail } from '@endo/errors';
33
import { M } from '@endo/patterns';
4-
import { CctpTxEvidenceShape } from '../typeGuards.js';
4+
import { CctpTxEvidenceShape } from '../type-guards.js';
55

66
const trace = makeTracer('TxOperator');
77

packages/fast-usdc/src/exos/status-manager.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { M } from '@endo/patterns';
22
import { makeError, q } from '@endo/errors';
33

44
import { appendToStoredArray } from '@agoric/store/src/stores/store-utils.js';
5-
import { CctpTxEvidenceShape, PendingTxShape } from '../typeGuards.js';
5+
import { CctpTxEvidenceShape, PendingTxShape } from '../type-guards.js';
66
import { PendingTxStatus } from '../constants.js';
77

88
/**

packages/fast-usdc/src/exos/transaction-feed.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { makeTracer } from '@agoric/internal';
22
import { prepareDurablePublishKit } from '@agoric/notifier';
33
import { M } from '@endo/patterns';
4-
import { CctpTxEvidenceShape } from '../typeGuards.js';
4+
import { CctpTxEvidenceShape } from '../type-guards.js';
55
import { defineInertInvitation } from '../utils/zoe.js';
66
import { prepareOperatorKit } from './operator-kit.js';
77

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { prepareSettler } from './exos/settler.js';
1414
import { prepareStatusManager } from './exos/status-manager.js';
1515
import { prepareTransactionFeedKit } from './exos/transaction-feed.js';
1616
import { defineInertInvitation } from './utils/zoe.js';
17-
import { FeeConfigShape } from './typeGuards.js';
17+
import { FeeConfigShape } from './type-guards.js';
1818

1919
const trace = makeTracer('FastUsdc');
2020

packages/fast-usdc/src/type-guards.js

+52-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { M } from '@endo/patterns';
2+
import { BrandShape, RatioShape } from '@agoric/ertp';
3+
import { PendingTxStatus } from './constants.js';
24

35
/**
4-
* @import {TypedPattern} from '@agoric/internal'
5-
* @import {USDCProposalShapes} from './pool-share-math'
6+
* @import {TypedPattern} from '@agoric/internal';
7+
* @import {USDCProposalShapes} from './pool-share-math';
8+
* @import {CctpTxEvidence, FeeConfig, PendingTx} from './types.js';
69
*/
710

811
/**
@@ -26,3 +29,50 @@ export const makeProposalShapes = ({ PoolShares, USDC }) => {
2629
});
2730
return harden({ deposit, withdraw });
2831
};
32+
33+
/** @type {TypedPattern<string>} */
34+
export const EvmHashShape = M.string({
35+
stringLengthLimit: 66,
36+
});
37+
harden(EvmHashShape);
38+
39+
/** @type {TypedPattern<CctpTxEvidence>} */
40+
export const CctpTxEvidenceShape = {
41+
aux: {
42+
forwardingChannel: M.string(),
43+
recipientAddress: M.string(),
44+
},
45+
blockHash: EvmHashShape,
46+
blockNumber: M.bigint(),
47+
blockTimestamp: M.bigint(),
48+
chainId: M.number(),
49+
tx: {
50+
amount: M.bigint(),
51+
forwardingAddress: M.string(),
52+
},
53+
txHash: EvmHashShape,
54+
};
55+
harden(CctpTxEvidenceShape);
56+
57+
/** @type {TypedPattern<PendingTx>} */
58+
// @ts-expect-error TypedPattern can't handle spreading?
59+
export const PendingTxShape = {
60+
...CctpTxEvidenceShape,
61+
status: M.or(...Object.values(PendingTxStatus)),
62+
};
63+
harden(PendingTxShape);
64+
65+
export const EudParamShape = {
66+
EUD: M.string(),
67+
};
68+
harden(EudParamShape);
69+
70+
const NatAmountShape = { brand: BrandShape, value: M.nat() };
71+
/** @type {TypedPattern<FeeConfig>} */
72+
export const FeeConfigShape = {
73+
flat: NatAmountShape,
74+
variableRate: RatioShape,
75+
maxVariable: NatAmountShape,
76+
contractRate: RatioShape,
77+
};
78+
harden(FeeConfigShape);

packages/fast-usdc/src/typeGuards.js

-55
This file was deleted.

packages/fast-usdc/src/utils/fees.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { AmountMath } from '@agoric/ertp';
22
import { multiplyBy } from '@agoric/zoe/src/contractSupport/ratio.js';
33
import { Fail } from '@endo/errors';
44
import { mustMatch } from '@endo/patterns';
5-
import { FeeConfigShape } from '../typeGuards.js';
5+
import { FeeConfigShape } from '../type-guards.js';
66

77
const { add, isGTE, min, subtract } = AmountMath;
88

packages/fast-usdc/test/typeGuards.test.ts packages/fast-usdc/test/type-guards.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js';
22

33
import { mustMatch } from '@endo/patterns';
44
import { TxStatus, PendingTxStatus } from '../src/constants.js';
5-
import { CctpTxEvidenceShape, PendingTxShape } from '../src/typeGuards.js';
5+
import { CctpTxEvidenceShape, PendingTxShape } from '../src/type-guards.js';
66
import type { CctpTxEvidence } from '../src/types.js';
77

88
import { MockCctpTxEvidences } from './fixtures.js';

packages/fast-usdc/test/utils/address.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js';
22
import { M } from '@endo/patterns';
33

44
import { addressTools } from '../../src/utils/address.js';
5-
import { EudParamShape } from '../../src/typeGuards.js';
5+
import { EudParamShape } from '../../src/type-guards.js';
66

77
const FIXTURES = {
88
AGORIC_WITH_DYDX:

0 commit comments

Comments
 (0)