Skip to content

Commit

Permalink
chore: remove maxVariable from FeeConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpatrickdev committed Jan 17, 2025
1 parent 371f6f3 commit 003861a
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 69 deletions.
4 changes: 0 additions & 4 deletions packages/boot/test/fast-usdc/snapshots/fast-usdc.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ Generated by [AVA](https://avajs.dev).
brand: Object @Alleged: USDC brand {},
value: 10000n,
},
maxVariable: {
brand: Object @Alleged: USDC brand {},
value: 5000000n,
},
variableRate: {
denominator: {
brand: Object @Alleged: USDC brand {},
Expand Down
Binary file modified packages/boot/test/fast-usdc/snapshots/fast-usdc.test.ts.snap
Binary file not shown.
5 changes: 1 addition & 4 deletions packages/builders/scripts/fast-usdc/start-fast-usdc.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const { keys } = Object;
const options = {
flatFee: { type: 'string', default: '0.01' },
variableRate: { type: 'string', default: '0.01' },
maxVariableFee: { type: 'string', default: '5' },
contractRate: { type: 'string', default: '0.2' },
net: { type: 'string' },
oracle: { type: 'string', multiple: true },
Expand All @@ -50,7 +49,6 @@ const assetInfoUsage =
* @typedef {{
* flatFee: string;
* variableRate: string;
* maxVariableFee: string;
* contractRate: string;
* net?: string;
* oracle?: string[];
Expand Down Expand Up @@ -161,11 +159,10 @@ export default async (homeP, endowments) => {
/** @param {string} numeral */
const toRatio = numeral => parseRatio(numeral, USDC);
const parseFeeConfigArgs = () => {
const { flatFee, variableRate, maxVariableFee, contractRate } = fees;
const { flatFee, variableRate, contractRate } = fees;
return {
flat: toAmount(flatFee),
variableRate: toRatio(variableRate),
maxVariable: toAmount(maxVariableFee),
contractRate: toRatio(contractRate),
};
};
Expand Down
1 change: 0 additions & 1 deletion packages/fast-usdc/src/type-guards.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ const NatAmountShape = { brand: BrandShape, value: M.nat() };
export const FeeConfigShape = {
flat: NatAmountShape,
variableRate: RatioShape,
maxVariable: NatAmountShape,
contractRate: RatioShape,
};
harden(FeeConfigShape);
Expand Down
4 changes: 3 additions & 1 deletion packages/fast-usdc/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ export interface PendingTx extends CctpTxEvidence {
}

export type FeeConfig = {
/** flat fee charged for every advance */
flat: Amount<'nat'>;
/** proportion of advance kept as a fee */
variableRate: Ratio;
maxVariable: Amount<'nat'>;
/** proportion of fees that goes to the contract (remaining goes to LPs) */
contractRate: Ratio;
};

Expand Down
7 changes: 3 additions & 4 deletions packages/fast-usdc/src/utils/fees.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Fail } from '@endo/errors';
import { mustMatch } from '@endo/patterns';
import { FeeConfigShape } from '../type-guards.js';

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

/**
* @import {Amount} from '@agoric/ertp';
Expand All @@ -15,7 +15,7 @@ const { add, isGTE, min, subtract } = AmountMath;
/** @param {FeeConfig} feeConfig */
export const makeFeeTools = feeConfig => {
mustMatch(feeConfig, FeeConfigShape, 'Must provide feeConfig');
const { flat, variableRate, maxVariable } = feeConfig;
const { flat, variableRate } = feeConfig;
const feeTools = harden({
/**
* Calculate the net amount to advance after withholding fees.
Expand All @@ -34,8 +34,7 @@ export const makeFeeTools = feeConfig => {
* @throws {Error} if requested does not exceed fees
*/
calculateAdvanceFee(requested) {
const variable = min(multiplyBy(requested, variableRate), maxVariable);
const fee = add(variable, flat);
const fee = add(multiplyBy(requested, variableRate), flat);
!isGTE(fee, requested) || Fail`Request must exceed fees.`;
return fee;
},
Expand Down
2 changes: 0 additions & 2 deletions packages/fast-usdc/test/config-marshal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ test('cross-vat configuration of Fast USDC FeeConfig', t => {
const config = harden({
flat: make(USDC, 100n),
variableRate: makeRatio(1n, USDC),
maxVariable: make(USDC, 100_000n),
contractRate: makeRatio(20n, USDC),
});
testMatches(t, config, FeeConfigShape);
Expand All @@ -51,7 +50,6 @@ test('cross-vat configuration of Fast USDC FeeConfig', t => {
},
},
flat: { brand: '$0', value: '+100' },
maxVariable: { brand: '$0', value: '+100000' },
variableRate: {
denominator: {
brand: '$0',
Expand Down
2 changes: 1 addition & 1 deletion packages/fast-usdc/test/exos/advancer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ test('updates status to OBSERVED on insufficient pool funds', async t => {
[
'Advancer error:',
Error(
`Cannot borrow. Requested ${q(usdc.make(294999999n))} must be less than pool balance ${q(usdc.make(1n))}.`,
`Cannot borrow. Requested ${q(usdc.make(293999999n))} must be less than pool balance ${q(usdc.make(1n))}.`,
),
],
]);
Expand Down
1 change: 0 additions & 1 deletion packages/fast-usdc/test/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,5 @@ export const makeTestFeeConfig = (usdc: Omit<AmountUtils, 'mint'>): FeeConfig =>
harden({
flat: usdc.make(1n),
variableRate: makeRatio(2n, usdc.brand),
maxVariable: usdc.units(5),
contractRate: makeRatio(20n, usdc.brand),
});
56 changes: 5 additions & 51 deletions packages/fast-usdc/test/utils/fees.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const USDCRatio = (numerator: bigint, denominator: bigint = 100n) =>
const aFeeConfig: FeeConfig = {
flat: USDC(10n),
variableRate: USDCRatio(2n),
maxVariable: USDC(100n),
contractRate: USDCRatio(20n),
};
harden(aFeeConfig);
Expand Down Expand Up @@ -69,32 +68,6 @@ const feeToolsScenario = test.macro({
},
});

test(feeToolsScenario, {
name: 'below max variable fee',
requested: USDC(1000n),
expected: {
totalFee: USDC(30n), // 10 flat + 20 variable
advance: USDC(970n),
split: {
ContractFee: USDC(6n),
PoolFee: USDC(24n),
},
},
});

test(feeToolsScenario, {
name: 'above max variable fee',
requested: USDC(10000n),
expected: {
totalFee: USDC(110n), // 10 flat + 100 max
advance: USDC(9890n),
split: {
ContractFee: USDC(22n),
PoolFee: USDC(88n),
},
},
});

test(feeToolsScenario, {
name: 'zero variable fee',
requested: USDC(1000n),
Expand Down Expand Up @@ -147,33 +120,14 @@ test(feeToolsScenario, {
},
});

test(feeToolsScenario, {
// TODO consider behavior where 0 or undefined means "no fee cap"
name: 'only flat is charged if `maxVariable: 0`',
requested: USDC(10000n),
config: {
...aFeeConfig,
variableRate: USDCRatio(20n),
maxVariable: USDC(0n),
},
expected: {
totalFee: USDC(10n), // only flat
advance: USDC(9990n),
split: {
ContractFee: USDC(2n),
PoolFee: USDC(8n),
},
},
});

test(feeToolsScenario, {
name: 'AGORIC_PLUS_OSMO with commonPrivateArgs.feeConfig',
// 150_000_000n
requested: USDC(MockCctpTxEvidences.AGORIC_PLUS_OSMO().tx.amount),
// same as commonPrivateArgs.feeConfig from `CommonSetup`
config: makeTestFeeConfig(withAmountUtils(issuerKits.USDC)),
expected: {
totalFee: USDC(3000001n), // 1n + min(2% of 150USDC, 5USDC)
totalFee: USDC(3000001n), // 1n + 2% of 150USDC
advance: USDC(146999999n),
split: {
ContractFee: USDC(600000n), // 20% of fee
Expand All @@ -189,11 +143,11 @@ test(feeToolsScenario, {
// same as commonPrivateArgs.feeConfig from `CommonSetup`
config: makeTestFeeConfig(withAmountUtils(issuerKits.USDC)),
expected: {
totalFee: USDC(5000001n), // 1n + min(2% of 300USDC, 5USDC)
advance: USDC(294999999n),
totalFee: USDC(6000001n), // 1n + 2% of 300USDC
advance: USDC(293999999n),
split: {
ContractFee: USDC(1000000n), // 20% of fee
PoolFee: USDC(4000001n),
ContractFee: USDC(1200000n), // 20% of fee
PoolFee: USDC(4800001n),
},
},
});
Expand Down

0 comments on commit 003861a

Please sign in to comment.