Skip to content

Commit

Permalink
fix(a3p): use makeRatio for mintFeeRatio
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge-Lopes committed Oct 31, 2024
1 parent b243730 commit f95c3a6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
24 changes: 24 additions & 0 deletions a3p-integration/proposals/z:acceptance/test-lib/ratio.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,27 @@ const multiplyHelper = (amount, ratio, divideOp) => {
export const ceilMultiplyBy = (amount, ratio) => {
return multiplyHelper(amount, ratio, natSafeMath.ceilDivide);
};

const PERCENT = 100n;

/**
* @param {bigint} numerator
* @param {import('@agoric/ertp').Brand} numeratorBrand
* @param {bigint} [denominator] The default denominator is 100
* @param {import('@agoric/ertp').Brand} [denominatorBrand] The default is to reuse the numeratorBrand
* @returns {import('@agoric/zoe/src/contractSupport/types-ambient.js').Ratio}
*/
export const makeRatio = (
numerator,
numeratorBrand,
denominator = PERCENT,
denominatorBrand = numeratorBrand,
) => {
denominator > 0n ||
Fail`No infinite ratios! Denominator was 0 ${q(denominatorBrand)}`;

return harden({
numerator: AmountMath.make(numeratorBrand, numerator),
denominator: AmountMath.make(denominatorBrand, denominator),
});
};
13 changes: 8 additions & 5 deletions a3p-integration/proposals/z:acceptance/test-lib/vaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
GOV2ADDR,
} from '@agoric/synthetic-chain';
import { AmountMath } from '@agoric/ertp';
import { ceilMultiplyBy } from './ratio.js';
import { ceilMultiplyBy, makeRatio } from './ratio.js';
import { getAgoricNamesBrands, getAgoricNamesInstances } from './utils.js';
import { boardSlottingMarshaller, makeFromBoard } from './rpc.js';
import { retryUntilCondition } from './sync-tools.js';
Expand Down Expand Up @@ -100,10 +100,13 @@ export const calculateMintFee = async (toMintValue, vaultManager) => {

const mintFee = governance.current.MintFee;
const { numerator, denominator } = mintFee.value;
const mintFeeRatio = harden({
numerator: AmountMath.make(brands.IST, numerator.value),
denominator: AmountMath.make(brands.IST, denominator.value),
});

const mintFeeRatio = makeRatio(
numerator.value,
brands.IST,
denominator.value,
brands.IST,
);

const toMintAmount = AmountMath.make(brands.IST, toMintValue * 1_000_000n);
const expectedMintFee = ceilMultiplyBy(toMintAmount, mintFeeRatio);
Expand Down

0 comments on commit f95c3a6

Please sign in to comment.