Skip to content

Commit

Permalink
useAvailable when setting throttles.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmckelvy1 committed Aug 1, 2023
1 parent 3c20f04 commit 87012ba
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions contracts/p1/RToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ contract RTokenP1 is ComponentP1, ERC20PermitUpgradeable, IRToken {
require(params.amtRate >= MIN_THROTTLE_RATE_AMT, "issuance amtRate too small");
require(params.amtRate <= MAX_THROTTLE_RATE_AMT, "issuance amtRate too big");
require(params.pctRate <= MAX_THROTTLE_PCT_AMT, "issuance pctRate too big");
issuanceThrottle.useAvailable(totalSupply(), 0);
emit IssuanceThrottleSet(issuanceThrottle.params, params);
issuanceThrottle.params = params;
}
Expand All @@ -451,6 +452,7 @@ contract RTokenP1 is ComponentP1, ERC20PermitUpgradeable, IRToken {
require(params.amtRate >= MIN_THROTTLE_RATE_AMT, "redemption amtRate too small");
require(params.amtRate <= MAX_THROTTLE_RATE_AMT, "redemption amtRate too big");
require(params.pctRate <= MAX_THROTTLE_PCT_AMT, "redemption pctRate too big");
redemptionThrottle.useAvailable(totalSupply(), 0);
emit RedemptionThrottleSet(redemptionThrottle.params, params);
redemptionThrottle.params = params;
}
Expand Down
44 changes: 44 additions & 0 deletions test/RToken.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,26 @@ describe(`RTokenP${IMPLEMENTATION} contract`, () => {
).to.be.revertedWith('issuance pctRate too big')
})

it.only('Should account for accrued value when updating issuance throttle parameters', async () => {
await advanceTime(12*5*60) // 60 minutes, charge fully

Check failure on line 228 in test/RToken.test.ts

View workflow job for this annotation

GitHub Actions / Lint Checks

Replace `*5*` with `·*·5·*·`
const issuanceThrottleParams = { amtRate: fp('60'), pctRate: fp('0.1') }

await rToken.connect(owner).setIssuanceThrottleParams(issuanceThrottleParams)
let params = await rToken.issuanceThrottleParams()

Check failure on line 232 in test/RToken.test.ts

View workflow job for this annotation

GitHub Actions / Lint Checks

'params' is never reassigned. Use 'const' instead
expect(params[0]).to.equal(issuanceThrottleParams.amtRate)
expect(params[1]).to.equal(issuanceThrottleParams.pctRate)

await Promise.all(tokens.map((t) => t.connect(addr1).approve(rToken.address, initialBal)))
await rToken.connect(addr1).issue(fp('20'))
expect(await rToken.issuanceAvailable()).to.equal(fp('40'))

await setNextBlockTimestamp(await getLatestBlockTimestamp() + 12*5*10) // 10 minutes

Check failure on line 240 in test/RToken.test.ts

View workflow job for this annotation

GitHub Actions / Lint Checks

Replace `await·getLatestBlockTimestamp()·+·12*5*` with `(await·getLatestBlockTimestamp())·+·12·*·5·*·`

issuanceThrottleParams.amtRate = fp('100')
await rToken.connect(owner).setIssuanceThrottleParams(issuanceThrottleParams)
expect(await rToken.issuanceAvailable()).to.equal(fp('50'))
})

it('Should allow to update redemption throttle if Owner and perform validations', async () => {
const redemptionThrottleParams = { amtRate: fp('1'), pctRate: fp('0.1') }
await expect(
Expand Down Expand Up @@ -262,6 +282,30 @@ describe(`RTokenP${IMPLEMENTATION} contract`, () => {
).to.be.revertedWith('redemption pctRate too big')
})

it.only('Should account for accrued value when updating redemption throttle parameters', async () => {
await advanceTime(12*5*60) // 60 minutes, charge fully

Check failure on line 286 in test/RToken.test.ts

View workflow job for this annotation

GitHub Actions / Lint Checks

Replace `*5*` with `·*·5·*·`
const issuanceThrottleParams = { amtRate: fp('100'), pctRate: fp('0.1') }
const redemptionThrottleParams = { amtRate: fp('60'), pctRate: fp('0.1') }

await rToken.connect(owner).setIssuanceThrottleParams(issuanceThrottleParams)
await rToken.connect(owner).setRedemptionThrottleParams(redemptionThrottleParams)
let params = await rToken.redemptionThrottleParams()

Check failure on line 292 in test/RToken.test.ts

View workflow job for this annotation

GitHub Actions / Lint Checks

'params' is never reassigned. Use 'const' instead
expect(params[0]).to.equal(redemptionThrottleParams.amtRate)
expect(params[1]).to.equal(redemptionThrottleParams.pctRate)

await Promise.all(tokens.map((t) => t.connect(addr1).approve(rToken.address, initialBal)))
await rToken.connect(addr1).issue(fp('100'))
expect(await rToken.redemptionAvailable()).to.equal(fp('60'))
await rToken.connect(addr1).redeem(fp('30'))
expect(await rToken.redemptionAvailable()).to.equal(fp('30'))

await setNextBlockTimestamp(await getLatestBlockTimestamp() + 12*5*10) // 10 minutes

Check failure on line 302 in test/RToken.test.ts

View workflow job for this annotation

GitHub Actions / Lint Checks

Replace `await·getLatestBlockTimestamp()·+·12*5*` with `(await·getLatestBlockTimestamp())·+·12·*·5·*·`

redemptionThrottleParams.amtRate = fp('100')
await rToken.connect(owner).setRedemptionThrottleParams(redemptionThrottleParams)
expect(await rToken.redemptionAvailable()).to.equal(fp('40'))
})

it('Should return a price of 0 if the assets become unregistered', async () => {
const startPrice = await basketHandler.price()

Expand Down

0 comments on commit 87012ba

Please sign in to comment.