From 54d97c76527b63a9f0e240fcf773a4da3dd5f9da Mon Sep 17 00:00:00 2001 From: Dan Connolly Date: Tue, 5 Nov 2024 12:26:31 -0600 Subject: [PATCH] chore(fast-usdc): proposal shapes for deposit, withdraw --- packages/fast-usdc/src/type-guards.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 packages/fast-usdc/src/type-guards.js diff --git a/packages/fast-usdc/src/type-guards.js b/packages/fast-usdc/src/type-guards.js new file mode 100644 index 00000000000..caba0cf10da --- /dev/null +++ b/packages/fast-usdc/src/type-guards.js @@ -0,0 +1,21 @@ +import { M } from '@endo/patterns'; + +/** + * @param {Brand} brand must be a 'nat' brand, not checked + * @param {NatValue} [min] + */ +export const makeNatAmountShape = (brand, min) => + harden({ brand, value: min ? M.gte(min) : M.nat() }); + +/** @param {Record<'PoolShares' | 'USDC', Brand<'nat'>>} brands */ +export const makeProposalShapes = ({ PoolShares, USDC }) => + harden({ + deposit: M.splitRecord( + { give: { ToPool: makeNatAmountShape(USDC, 1n) } }, + { want: { Shares: makeNatAmountShape(PoolShares) } }, + ), + withdraw: M.splitRecord({ + give: { Shares: makeNatAmountShape(PoolShares, 1n) }, + want: { FromPool: makeNatAmountShape(USDC, 1n) }, + }), + });