From 95a612ce425ac62fdc195c740a87297a15fdd8bd Mon Sep 17 00:00:00 2001 From: Dan Connolly Date: Tue, 29 Oct 2024 16:27:34 -0500 Subject: [PATCH] chore(fast-usdc): fee account pre-exists contract --- .../fast-usdc/contract/quickSend.contract.js | 7 +++++- .../fast-usdc/contract/quickSend.flows.js | 14 +++++------ .../fast-usdc/contract/start-quickSend.js | 8 +++++-- packages/fast-usdc/test/quickSend-tx.test.ts | 23 +++++++++---------- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/packages/fast-usdc/contract/quickSend.contract.js b/packages/fast-usdc/contract/quickSend.contract.js index cadd2d1903c..27d917000ae 100644 --- a/packages/fast-usdc/contract/quickSend.contract.js +++ b/packages/fast-usdc/contract/quickSend.contract.js @@ -18,12 +18,17 @@ export const meta = { customTermsShape: { contractFee: NatAmountShape, makerFee: NatAmountShape, + feeAccountAddress: M.string(), }, }; harden(meta); /** - * @typedef {{ makerFee: Amount<'nat'>; contractFee: Amount<'nat'> }} QuickSendTerms + * @typedef {{ + * makerFee: Amount<'nat'>; + * contractFee: Amount<'nat'>; + * feeAccountAddress: string; + * }} QuickSendTerms * @param {ZCF} zcf * @param {OrchestrationPowers & { * marshaller: Marshaller; diff --git a/packages/fast-usdc/contract/quickSend.flows.js b/packages/fast-usdc/contract/quickSend.flows.js index ddeb20be539..83d9eaeb028 100644 --- a/packages/fast-usdc/contract/quickSend.flows.js +++ b/packages/fast-usdc/contract/quickSend.flows.js @@ -27,7 +27,6 @@ const { add, make, subtract } = AmountMath; * @typedef {{ * settlement: OrchestrationAccountI; * fundingPool: OrchestrationAccountI; - * feeAccount: OrchestrationAccountI; * }} QuickSendAccounts */ @@ -70,8 +69,7 @@ export const initAccounts = async (orch, ctx, seat, _offerArgs) => { const fundingPool = await agoric.makeAccount(); const settlement = await agoric.makeAccount(); - const feeAccount = await agoric.makeAccount(); - const accts = harden({ fundingPool, settlement, feeAccount }); + const accts = harden({ fundingPool, settlement }); const tap = ctx.makeSettleTap(accts); // @ts-expect-error tap.receiveUpcall: 'Vow | undefined' not assignable to 'Promise' const registration = await settlement.monitorTransfers(tap); @@ -84,7 +82,6 @@ export const initAccounts = async (orch, ctx, seat, _offerArgs) => { publicSubscribers: { fundingPool: (await fundingPool.getPublicTopics()).account, settlement: (await settlement.getPublicTopics()).account, - feeAccount: (await feeAccount.getPublicTopics()).account, }, ...cont, }); @@ -175,14 +172,17 @@ export const settle = async (orch, ctx, acct, event) => { // } const { contractFee } = ctx.terms; const { USDC } = ctx.terms.brands; - const { settlement, fundingPool, feeAccount } = acct; + const { settlement, fundingPool } = acct; const { nextLabel: next = () => '#?' } = ctx.t?.context || {}; const amount = make(USDC, BigInt(tx.amount)); log(next(), 'tap onReceive', { amount }); + + const poolAddr = fundingPool.getAddress(); + const feeAddr = harden({ ...poolAddr, value: ctx.terms.feeAccountAddress }); // XXX partial failure? await Promise.all([ - settlement.send(fundingPool.getAddress(), subtract(amount, contractFee)), - settlement.send(feeAccount.getAddress(), contractFee), + settlement.send(poolAddr, subtract(amount, contractFee)), + settlement.send(feeAddr, contractFee), ]); }; harden(settle); diff --git a/packages/fast-usdc/contract/start-quickSend.js b/packages/fast-usdc/contract/start-quickSend.js index b59f112ae06..03dd1325afc 100644 --- a/packages/fast-usdc/contract/start-quickSend.js +++ b/packages/fast-usdc/contract/start-quickSend.js @@ -30,7 +30,7 @@ const makePublishingStorageKit = async (path, { chainStorage, board }) => { }; /** - * @typedef {{ watcherAddress: string }} QuickSendConfig + * @typedef {{ watcherAddress: string, feeAccountAddress: string }} QuickSendConfig */ /** @@ -68,7 +68,10 @@ export const startQuickSend = async ( config = {}, ) => { trace('startQuickSend'); - const { watcherAddress = 'agoric1watcher' } = config.options?.quickSend || {}; + const { + watcherAddress = 'agoric1watcher', + feeAccountAddress = 'agoric1fee', + } = config.options?.quickSend || {}; await null; const USDC = { @@ -78,6 +81,7 @@ export const startQuickSend = async ( const terms = { makerFee: AmountMath.make(USDC.brand, 100n), // TODO: parameterize contractFee: AmountMath.make(USDC.brand, 30n), + feeAccountAddress, }; const { storageNode, marshaller } = await makePublishingStorageKit( 'quickSend', diff --git a/packages/fast-usdc/test/quickSend-tx.test.ts b/packages/fast-usdc/test/quickSend-tx.test.ts index 2380250ea6c..c8d8eea288d 100644 --- a/packages/fast-usdc/test/quickSend-tx.test.ts +++ b/packages/fast-usdc/test/quickSend-tx.test.ts @@ -256,11 +256,13 @@ const setup = async (t, io) => { 'published.quickSend.settlementBase', ); + const feeAccountAddress = await chains.agoric.makeAccount(); const terms = { issuers: { USDC: USDCe.issuer }, brands: { USDC: USDCe.brand }, makerFee: AmountMath.make(USDCe.brand, termValues.makerFee), contractFee: AmountMath.make(USDCe.brand, termValues.contractFee), + feeAccountAddress, }; const handlers = new Map(); const zcf: ZCF = harden({ @@ -372,12 +374,13 @@ const setup = async (t, io) => { const ursula = makeUser({ nobleApp, ethereum, myAddr: '0xUrsula', cctpAddr }); - return { chains, ursula, quiesce, contract, addrs, usdc }; + return { chains, ursula, quiesce, contract, addrs, terms, usdc }; }; test('tx lifecycle', async t => { const io = { setTimeout }; - const { chains, ursula, quiesce, contract, addrs, usdc } = await setup(t, io); + const info = await setup(t, io); + const { chains, ursula, quiesce, addrs, terms, usdc } = info; const destAddr = await chains.dydx.makeAccount(); // is this a prereq? await ursula.doTransfer(100n, { @@ -388,11 +391,7 @@ test('tx lifecycle', async t => { await quiesce(); - const { - fundingPool: poolAddr, - feeAccount: feeAddr, - settlement: settlementAddr, - } = addrs; + const { fundingPool: poolAddr, settlement: settlementAddr } = addrs; const actual = { user: { addr: '0xUrsula', @@ -409,8 +408,8 @@ test('tx lifecycle', async t => { balance: await chains.agoric.getBalance(poolAddr), }, fee: { - addr: feeAddr, - balance: await chains.agoric.getBalance(feeAddr), + addr: terms.feeAccountAddress, + balance: await chains.agoric.getBalance(terms.feeAccountAddress), }, settlement: { addr: settlementAddr, @@ -428,13 +427,13 @@ test('tx lifecycle', async t => { balance: 100n - termValues.makerFee - termValues.contractFee, }, pool: { - addr: 'agoric112', + addr: 'agoric113', start: startFunds.pool, balance: startFunds.pool + termValues.makerFee, }, - fee: { addr: 'agoric114', balance: termValues.contractFee }, + fee: { addr: 'agoric112', balance: termValues.contractFee }, settlement: { - addr: 'agoric113', + addr: 'agoric114', balance: 0n, }, };