Skip to content

Commit

Permalink
fixing facade tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmckelvy1 committed Sep 20, 2024
1 parent c38a282 commit d207b3d
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions test/Facade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1330,19 +1330,26 @@ describe('Facade + FacadeMonitor contracts', () => {
const issueAmount = bn('100000e18')

// Decrease redemption allowed amount
const issuanceThrottleParams = { amtRate: issueAmount.div(4), pctRate: fp('0.05') } // 25K
const redeemThrottleParams = { amtRate: issueAmount.div(2), pctRate: fp('0.1') } // 50K
await rToken.connect(owner).setRedemptionThrottleParams(redeemThrottleParams)
await rToken.connect(owner).setThrottleParams(issuanceThrottleParams, redeemThrottleParams)

// Check with no supply
expect(await facadeMonitor.issuanceAvailable(rToken.address)).to.equal(fp('1'))
expect(await rToken.redemptionAvailable()).to.equal(bn(0))
expect(await facadeMonitor.redemptionAvailable(rToken.address)).to.equal(fp('1'))

// Issue some RTokens
await rToken.connect(addr1).issue(issueAmount)
await rToken.connect(addr1).issue(issueAmount.div(4))
advanceTime(3600)

Check failure on line 1344 in test/Facade.test.ts

View workflow job for this annotation

GitHub Actions / Lint Checks

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
await rToken.connect(addr1).issue(issueAmount.div(4))
advanceTime(3600)

Check failure on line 1346 in test/Facade.test.ts

View workflow job for this annotation

GitHub Actions / Lint Checks

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
await rToken.connect(addr1).issue(issueAmount.div(4))
advanceTime(3600)

Check failure on line 1348 in test/Facade.test.ts

View workflow job for this annotation

GitHub Actions / Lint Checks

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
await rToken.connect(addr1).issue(issueAmount.div(4))

// check throttles - redemption still fully available
expect(await facadeMonitor.issuanceAvailable(rToken.address)).to.equal(fp('0.9'))
expect(await facadeMonitor.issuanceAvailable(rToken.address)).to.equal(bn('277777777777777'))
expect(await facadeMonitor.redemptionAvailable(rToken.address)).to.equal(fp('1'))

// Redeem RTokens (50% of throttle)
Expand Down Expand Up @@ -1406,7 +1413,10 @@ describe('Facade + FacadeMonitor contracts', () => {

// Set issuance throttle to percent only
const issuanceThrottleParams = { amtRate: fp('1'), pctRate: fp('0.1') } // 10%
await rToken.connect(owner).setIssuanceThrottleParams(issuanceThrottleParams)
const redemptionThrottleParams = { amtRate: fp('2'), pctRate: fp('0.2') } // 10%
await rToken
.connect(owner)
.setThrottleParams(issuanceThrottleParams, redemptionThrottleParams)

// Advance time significantly
await advanceTime(1000000000)
Expand All @@ -1417,7 +1427,7 @@ describe('Facade + FacadeMonitor contracts', () => {
expect(await facadeMonitor.issuanceAvailable(rToken.address)).to.equal(fp('1'))

// Check redemption throttle unchanged
expect(await rToken.redemptionAvailable()).to.equal(config.redemptionThrottle.amtRate)
expect(await rToken.redemptionAvailable()).to.equal(supplyThrottle.mul(2))
expect(await facadeMonitor.redemptionAvailable(rToken.address)).to.equal(fp('1'))

// Issuance #3 - Should be allowed, does not exceed supply restriction
Expand All @@ -1427,26 +1437,22 @@ describe('Facade + FacadeMonitor contracts', () => {

// Check issuance throttle updated - Previous issuances recharged
expect(await rToken.issuanceAvailable()).to.equal(supplyThrottle.sub(issueAmount3))

// Hourly Limit: 210K (10% of total supply of 2.1 M)
// Available: 100 K / 201K (~ 0.47619)
expect(await facadeMonitor.issuanceAvailable(rToken.address)).to.be.closeTo(
fp('0.476'),
fp('0.001')
)

// Check redemption throttle unchanged
expect(await rToken.redemptionAvailable()).to.equal(config.redemptionThrottle.amtRate)
// expect(await rToken.redemptionAvailable()).to.equal(config.redemptionThrottle.amtRate)
expect(await facadeMonitor.redemptionAvailable(rToken.address)).to.equal(fp('1'))

// Check all issuances are confirmed
expect(await rToken.balanceOf(addr1.address)).to.equal(
issueAmount1.add(issueAmount2).add(issueAmount3)
)

// Advance time, issuance will recharge a bit
await advanceTime(100)

// Now 50% of hourly limit available (~105.8K / 210 K)
expect(await rToken.issuanceAvailable()).to.be.closeTo(fp('105800'), fp('100'))
expect(await facadeMonitor.issuanceAvailable(rToken.address)).to.be.closeTo(
Expand All @@ -1473,20 +1479,16 @@ describe('Facade + FacadeMonitor contracts', () => {
expect(await facadeMonitor.redemptionAvailable(rToken.address)).to.equal(fp('1'))

// Check redemptions
// Set redemption throttle to percent only
const redemptionThrottleParams = { amtRate: fp('1'), pctRate: fp('0.1') } // 10%
await rToken.connect(owner).setRedemptionThrottleParams(redemptionThrottleParams)

const totalSupply = await rToken.totalSupply()
expect(await rToken.redemptionAvailable()).to.equal(totalSupply.div(10)) // 10%
expect(await rToken.redemptionAvailable()).to.equal(totalSupply.div(5)) // 20%
expect(await facadeMonitor.redemptionAvailable(rToken.address)).to.equal(fp('1'))

// Redeem half of the available throttle
await rToken.connect(addr1).redeem(totalSupply.div(10).div(2))

// About 52% now used of redemption throttle
expect(await facadeMonitor.redemptionAvailable(rToken.address)).to.be.closeTo(
fp('0.52'),
fp('0.79'),
fp('0.01')
)

Expand Down

0 comments on commit d207b3d

Please sign in to comment.