From 8f8eee2df19efbad6a19b747f4a368fe638d7c51 Mon Sep 17 00:00:00 2001 From: Patrick McKelvy Date: Tue, 24 Sep 2024 23:24:48 -0400 Subject: [PATCH] fix extremes? --- test/RTokenExtremes.test.ts | 20 ++++++++++++++++---- test/ZTradingExtremes.test.ts | 18 ++++++++++++------ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/test/RTokenExtremes.test.ts b/test/RTokenExtremes.test.ts index 211678d6c..84025e2fc 100644 --- a/test/RTokenExtremes.test.ts +++ b/test/RTokenExtremes.test.ts @@ -178,14 +178,26 @@ describe(`RTokenP${IMPLEMENTATION} contract`, () => { // ==== Issue the "initial" rtoken supply to owner expect(await rToken.balanceOf(owner.address)).to.equal(bn(0)) if (toIssue0.gt(0)) { - await rToken.connect(owner).issue(toIssue0) + while ((await rToken.balanceOf(owner.address)).lt(toIssue0)) { + const remaining = toIssue0.sub(await rToken.balanceOf(owner.address)) + const amt = + remaining < issuanceThrottleParams.amtRate ? remaining : issuanceThrottleParams.amtRate + await rToken.connect(addr1).issue(amt) + await advanceTime(3600) + } expect(await rToken.balanceOf(owner.address)).to.equal(toIssue0) } // ==== Issue the toIssue supply to addr1 expect(await rToken.balanceOf(addr1.address)).to.equal(0) - await rToken.connect(addr1).issue(toIssue) + while ((await rToken.balanceOf(addr1.address)).lt(toIssue)) { + const remaining = toIssue.sub(await rToken.balanceOf(addr1.address)) + const amt = + remaining < issuanceThrottleParams.amtRate ? remaining : issuanceThrottleParams.amtRate + await rToken.connect(addr1).issue(amt) + await advanceTime(3600) + } expect(await rToken.balanceOf(addr1.address)).to.equal(toIssue) // ==== Send enough rTokens to addr2 that it can redeem the amount `toRedeem` @@ -210,11 +222,11 @@ describe(`RTokenP${IMPLEMENTATION} contract`, () => { const MAX_WEIGHT = fp(1000) const MIN_WEIGHT = fp('1e-6') const MIN_ISSUANCE_PCT = fp('1e-6') - const MIN_REDEMPTION_PCT = MIN_ISSUANCE_PCT.mul(125).div(100) + const MIN_THROTTLE_DELTA = 25 + const MIN_REDEMPTION_PCT = MIN_ISSUANCE_PCT.mul(bn(100).add(MIN_THROTTLE_DELTA)).div(100) const MIN_RTOKENS = fp('1e-6') let paramList - const MIN_THROTTLE_DELTA = 25 if (SLOW) { const bounds: BigNumber[][] = [ diff --git a/test/ZTradingExtremes.test.ts b/test/ZTradingExtremes.test.ts index ffc81e267..0fd752c1d 100644 --- a/test/ZTradingExtremes.test.ts +++ b/test/ZTradingExtremes.test.ts @@ -437,10 +437,12 @@ describeExtreme(`Trading Extreme Values (${SLOW ? 'slow mode' : 'fast mode'})`, const noThrottleIssuance = { amtRate: MAX_THROTTLE_AMT_RATE.mul(80).div(100), pctRate: 0 } const noThrottleRedemption = { amtRate: MAX_THROTTLE_AMT_RATE, pctRate: 0 } await rToken.setThrottleParams(noThrottleIssuance, noThrottleRedemption) - while ((await rToken.balanceOf(addr1.address)) < rTokenSupply) { + while ((await rToken.balanceOf(addr1.address)).lt(rTokenSupply)) { await advanceTime(3600) const remaining = rTokenSupply.sub(await rToken.balanceOf(addr1.address)) - const amt = remaining < noThrottleIssuance.amtRate ? remaining : noThrottleIssuance.amtRate + const amt = remaining.lt(noThrottleIssuance.amtRate) + ? remaining + : noThrottleIssuance.amtRate await rToken.connect(addr1).issue(amt) } await advanceTime(3600) @@ -622,10 +624,12 @@ describeExtreme(`Trading Extreme Values (${SLOW ? 'slow mode' : 'fast mode'})`, const noThrottleIssuance = { amtRate: MAX_THROTTLE_AMT_RATE.mul(80).div(100), pctRate: 0 } const noThrottleRedemption = { amtRate: MAX_THROTTLE_AMT_RATE, pctRate: 0 } await rToken.setThrottleParams(noThrottleIssuance, noThrottleRedemption) - while ((await rToken.balanceOf(addr1.address)) < rTokenSupply) { + while ((await rToken.balanceOf(addr1.address)).lt(rTokenSupply)) { await advanceTime(3600) const remaining = rTokenSupply.sub(await rToken.balanceOf(addr1.address)) - const amt = remaining < noThrottleIssuance.amtRate ? remaining : noThrottleIssuance.amtRate + const amt = remaining.lt(noThrottleIssuance.amtRate) + ? remaining + : noThrottleIssuance.amtRate await rToken.connect(addr1).issue(amt) } await advanceTime(3600) @@ -834,10 +838,12 @@ describeExtreme(`Trading Extreme Values (${SLOW ? 'slow mode' : 'fast mode'})`, const noThrottleIssuance = { amtRate: MAX_THROTTLE_AMT_RATE.mul(80).div(100), pctRate: 0 } const noThrottleRedemption = { amtRate: MAX_THROTTLE_AMT_RATE, pctRate: 0 } await rToken.setThrottleParams(noThrottleIssuance, noThrottleRedemption) - while ((await rToken.balanceOf(addr1.address)) < rTokenSupply) { + while ((await rToken.balanceOf(addr1.address)).lt(rTokenSupply)) { await advanceTime(3600) const remaining = rTokenSupply.sub(await rToken.balanceOf(addr1.address)) - const amt = remaining < noThrottleIssuance.amtRate ? remaining : noThrottleIssuance.amtRate + const amt = remaining.lt(noThrottleIssuance.amtRate) + ? remaining + : noThrottleIssuance.amtRate await rToken.connect(addr1).issue(amt) }