-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: init timelock whitelist Signed-off-by: GopherJ <alex_cj96@foxmail.com> * fix: stack too deep Signed-off-by: GopherJ <alex_cj96@foxmail.com> * feat: add basic admin tests Signed-off-by: GopherJ <alex_cj96@foxmail.com> * fix: typo Signed-off-by: GopherJ <alex_cj96@foxmail.com> * fix: add missing tests Signed-off-by: GopherJ <alex_cj96@foxmail.com> * feat: simplify implementation Signed-off-by: GopherJ <alex_cj96@foxmail.com> * fix: tests Signed-off-by: GopherJ <alex_cj96@foxmail.com> * chore: tiny improvement Signed-off-by: GopherJ <alex_cj96@foxmail.com> --------- Signed-off-by: GopherJ <alex_cj96@foxmail.com>
- Loading branch information
Showing
7 changed files
with
279 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
nightly-2022-09-19 | ||
nightly-2023-05-22 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import {expect} from "chai"; | ||
import {BigNumber} from "ethers"; | ||
import {timeLatest, waitForTx} from "../helpers/misc-utils"; | ||
import {loadFixture} from "@nomicfoundation/hardhat-network-helpers"; | ||
import {deployReserveTimeLockStrategy} from "../helpers/contracts-deployments"; | ||
import {testEnvFixture} from "./helpers/setup-env"; | ||
import {TestEnv} from "./helpers/make-suite"; | ||
import {DefaultTimeLockStrategy} from "../types"; | ||
import {eContractid} from "../helpers/types"; | ||
import {supplyAndValidate} from "./helpers/validated-steps"; | ||
import {almostEqual} from "./helpers/uniswapv3-helper"; | ||
import {convertToCurrencyDecimals} from "../helpers/contracts-helpers"; | ||
import {getInitializableAdminUpgradeabilityProxy} from "../helpers/contracts-getters"; | ||
import {ONE_ADDRESS} from "../helpers/constants"; | ||
|
||
describe("timeLock whiteList tests", function () { | ||
let defaultTimeLockStrategy: DefaultTimeLockStrategy; | ||
let testEnv: TestEnv; | ||
|
||
const minThreshold = BigNumber.from(10); | ||
const midThreshold = BigNumber.from(20); | ||
const minWaitTime = 100; | ||
const midWaitTime = 2000; | ||
const maxWaitTime = 36000; | ||
const maxPoolPeriodRate = BigNumber.from(400); | ||
const maxPoolPeriodWaitTime = 40; | ||
const period = 86400; | ||
|
||
const fixture = async () => { | ||
testEnv = await loadFixture(testEnvFixture); | ||
const { | ||
configurator, | ||
pool, | ||
usdc, | ||
users: [user1, user2], | ||
} = testEnv; | ||
|
||
defaultTimeLockStrategy = await deployReserveTimeLockStrategy( | ||
eContractid.DefaultTimeLockStrategy, | ||
pool.address, | ||
minThreshold.toString(), | ||
midThreshold.toString(), | ||
minWaitTime.toString(), | ||
midWaitTime.toString(), | ||
maxWaitTime.toString(), | ||
maxPoolPeriodRate.toString(), | ||
maxPoolPeriodWaitTime.toString(), | ||
period.toString() | ||
); | ||
|
||
await supplyAndValidate(usdc, "10000", user1, true); | ||
await supplyAndValidate(usdc, "10000", user2, true); | ||
|
||
await waitForTx( | ||
await configurator.setReserveTimeLockStrategyAddress( | ||
usdc.address, | ||
defaultTimeLockStrategy.address | ||
) | ||
); | ||
|
||
return testEnv; | ||
}; | ||
|
||
it("normal non-whitelisted user should still have long wait time", async function () { | ||
const { | ||
pool, | ||
users: [user1], | ||
usdc, | ||
timeLock, | ||
} = await loadFixture(fixture); | ||
const currentTime = (await timeLatest()).toNumber(); | ||
await waitForTx( | ||
await pool | ||
.connect(user1.signer) | ||
.borrow( | ||
usdc.address, | ||
await convertToCurrencyDecimals(usdc.address, "1000"), | ||
0, | ||
user1.address | ||
) | ||
); | ||
await expect( | ||
(await timeLock.getAgreement(0)).releaseTime - currentTime | ||
).to.gte(minWaitTime); | ||
}); | ||
|
||
it("whitelisted user should only have 12s of wait time", async function () { | ||
const { | ||
pool, | ||
users: [user1], | ||
usdc, | ||
timeLock, | ||
poolAdmin, | ||
} = await loadFixture(fixture); | ||
await waitForTx( | ||
await (await getInitializableAdminUpgradeabilityProxy(timeLock.address)) | ||
.connect(poolAdmin.signer) | ||
.changeAdmin(ONE_ADDRESS) | ||
); | ||
await waitForTx( | ||
await timeLock | ||
.connect(poolAdmin.signer) | ||
.updateTimeLockWhiteList([user1.address], []) | ||
); | ||
await waitForTx( | ||
await pool | ||
.connect(user1.signer) | ||
.withdraw( | ||
usdc.address, | ||
await convertToCurrencyDecimals(usdc.address, "1000"), | ||
user1.address | ||
) | ||
); | ||
const currentTime = (await timeLatest()).toNumber(); | ||
await almostEqual( | ||
(await timeLock.getAgreement(0)).releaseTime - currentTime, | ||
12 | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters