Skip to content

Commit

Permalink
chore(fast-usdc): fee account pre-exists contract
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Oct 29, 2024
1 parent 4fe9850 commit 95a612c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
7 changes: 6 additions & 1 deletion packages/fast-usdc/contract/quickSend.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<QuickSendTerms>} zcf
* @param {OrchestrationPowers & {
* marshaller: Marshaller;
Expand Down
14 changes: 7 additions & 7 deletions packages/fast-usdc/contract/quickSend.flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const { add, make, subtract } = AmountMath;
* @typedef {{
* settlement: OrchestrationAccountI;
* fundingPool: OrchestrationAccountI;
* feeAccount: OrchestrationAccountI;
* }} QuickSendAccounts
*/

Expand Down Expand Up @@ -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<void> | undefined' not assignable to 'Promise<any>'
const registration = await settlement.monitorTransfers(tap);
Expand All @@ -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,
});
Expand Down Expand Up @@ -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);
8 changes: 6 additions & 2 deletions packages/fast-usdc/contract/start-quickSend.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const makePublishingStorageKit = async (path, { chainStorage, board }) => {
};

/**
* @typedef {{ watcherAddress: string }} QuickSendConfig
* @typedef {{ watcherAddress: string, feeAccountAddress: string }} QuickSendConfig
*/

/**
Expand Down Expand Up @@ -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 = {
Expand All @@ -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',
Expand Down
23 changes: 11 additions & 12 deletions packages/fast-usdc/test/quickSend-tx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<QuickSendTerms> = harden({
Expand Down Expand Up @@ -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, {
Expand All @@ -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',
Expand All @@ -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,
Expand All @@ -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,
},
};
Expand Down

0 comments on commit 95a612c

Please sign in to comment.