From f95c3a6af9feaa866542cfb2973af0f517af3979 Mon Sep 17 00:00:00 2001 From: Jorge-Lopes Date: Thu, 31 Oct 2024 14:26:22 +0000 Subject: [PATCH] fix(a3p): use makeRatio for mintFeeRatio rel: https://github.com/Agoric/BytePitchPartnerEng/issues/22 --- .../proposals/z:acceptance/test-lib/ratio.js | 24 +++++++++++++++++++ .../proposals/z:acceptance/test-lib/vaults.js | 13 ++++++---- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/a3p-integration/proposals/z:acceptance/test-lib/ratio.js b/a3p-integration/proposals/z:acceptance/test-lib/ratio.js index 1197f5383d23..8bf336c3e525 100644 --- a/a3p-integration/proposals/z:acceptance/test-lib/ratio.js +++ b/a3p-integration/proposals/z:acceptance/test-lib/ratio.js @@ -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), + }); +}; \ No newline at end of file diff --git a/a3p-integration/proposals/z:acceptance/test-lib/vaults.js b/a3p-integration/proposals/z:acceptance/test-lib/vaults.js index 8cd173f0cc0a..83766fc7d73b 100644 --- a/a3p-integration/proposals/z:acceptance/test-lib/vaults.js +++ b/a3p-integration/proposals/z:acceptance/test-lib/vaults.js @@ -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'; @@ -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);