Skip to content

Commit

Permalink
refactor: single type-guards.js file
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpatrickdev committed Nov 15, 2024
1 parent 14ec771 commit a1d931d
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 65 deletions.
2 changes: 1 addition & 1 deletion packages/fast-usdc/src/exos/advancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { VowShape } from '@agoric/vow';
import { q } from '@endo/errors';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { CctpTxEvidenceShape, EudParamShape } from '../typeGuards.js';
import { CctpTxEvidenceShape, EudParamShape } from '../type-guards.js';
import { addressTools } from '../utils/address.js';
import { makeFeeTools } from '../utils/fees.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/fast-usdc/src/exos/operator-kit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { makeTracer } from '@agoric/internal';
import { Fail } from '@endo/errors';
import { M } from '@endo/patterns';
import { CctpTxEvidenceShape } from '../typeGuards.js';
import { CctpTxEvidenceShape } from '../type-guards.js';

const trace = makeTracer('TxOperator');

Expand Down
2 changes: 1 addition & 1 deletion packages/fast-usdc/src/exos/status-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { M } from '@endo/patterns';
import { makeError, q } from '@endo/errors';

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

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/fast-usdc/src/exos/transaction-feed.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { makeTracer } from '@agoric/internal';
import { prepareDurablePublishKit } from '@agoric/notifier';
import { M } from '@endo/patterns';
import { CctpTxEvidenceShape } from '../typeGuards.js';
import { CctpTxEvidenceShape } from '../type-guards.js';
import { defineInertInvitation } from '../utils/zoe.js';
import { prepareOperatorKit } from './operator-kit.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/fast-usdc/src/fast-usdc.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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 { FeeConfigShape } from './typeGuards.js';
import { FeeConfigShape } from './type-guards.js';

const trace = makeTracer('FastUsdc');

Expand Down
54 changes: 52 additions & 2 deletions packages/fast-usdc/src/type-guards.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { M } from '@endo/patterns';
import { BrandShape, RatioShape } from '@agoric/ertp';
import { PendingTxStatus } from './constants.js';

/**
* @import {TypedPattern} from '@agoric/internal'
* @import {USDCProposalShapes} from './pool-share-math'
* @import {TypedPattern} from '@agoric/internal';
* @import {USDCProposalShapes} from './pool-share-math';
* @import {CctpTxEvidence, FeeConfig, PendingTx} from './types.js';
*/

/**
Expand All @@ -26,3 +29,50 @@ export const makeProposalShapes = ({ PoolShares, USDC }) => {
});
return harden({ deposit, withdraw });
};

/** @type {TypedPattern<string>} */
export const EvmHashShape = M.string({
stringLengthLimit: 66,
});
harden(EvmHashShape);

/** @type {TypedPattern<CctpTxEvidence>} */
export const CctpTxEvidenceShape = {
aux: {
forwardingChannel: M.string(),
recipientAddress: M.string(),
},
blockHash: EvmHashShape,
blockNumber: M.bigint(),
blockTimestamp: M.bigint(),
chainId: M.number(),
tx: {
amount: M.bigint(),
forwardingAddress: M.string(),
},
txHash: EvmHashShape,
};
harden(CctpTxEvidenceShape);

/** @type {TypedPattern<PendingTx>} */
// @ts-expect-error TypedPattern can't handle spreading?
export const PendingTxShape = {
...CctpTxEvidenceShape,
status: M.or(...Object.values(PendingTxStatus)),
};
harden(PendingTxShape);

export const EudParamShape = {
EUD: M.string(),
};
harden(EudParamShape);

const NatAmountShape = { brand: BrandShape, value: M.nat() };
/** @type {TypedPattern<FeeConfig>} */
export const FeeConfigShape = {
flat: NatAmountShape,
variableRate: RatioShape,
maxVariable: NatAmountShape,
contractRate: RatioShape,
};
harden(FeeConfigShape);
55 changes: 0 additions & 55 deletions packages/fast-usdc/src/typeGuards.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/fast-usdc/src/utils/fees.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AmountMath } from '@agoric/ertp';
import { multiplyBy } from '@agoric/zoe/src/contractSupport/ratio.js';
import { Fail } from '@endo/errors';
import { mustMatch } from '@endo/patterns';
import { FeeConfigShape } from '../typeGuards.js';
import { FeeConfigShape } from '../type-guards.js';

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js';

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

import { MockCctpTxEvidences } from './fixtures.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/fast-usdc/test/utils/address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js';
import { M } from '@endo/patterns';

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

const FIXTURES = {
AGORIC_WITH_DYDX:
Expand Down

0 comments on commit a1d931d

Please sign in to comment.