-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4bee0f
commit 9067972
Showing
6 changed files
with
277 additions
and
433 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import { UFragments } from "ampleforth-contracts/contracts/UFragments.sol"; |
This file was deleted.
Oops, something went wrong.
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,106 @@ | ||
import { ethers } from "hardhat"; | ||
import { promisify } from "util"; | ||
import { expect } from "chai"; | ||
|
||
const AMPL_DECIMALS = 9; | ||
|
||
function $AMPL(x: number) { | ||
return ethers.parseUnits(x.toString(), AMPL_DECIMALS); | ||
} | ||
|
||
// Perc has to be a whole number | ||
async function invokeRebase(ampl, perc) { | ||
await ampl.rebase(1, (await ampl.totalSupply()) * BigInt(perc) / 100n); | ||
} | ||
|
||
function checkAmplAprox(x, y) { | ||
checkAprox(x, $AMPL(y), 10 ** 6); | ||
} | ||
|
||
function checkSharesAprox(x, y) { | ||
checkAprox(x, y, 10 ** 12); | ||
} | ||
|
||
function checkAprox(x, y, delta_) { | ||
const delta = BigInt(parseInt(delta_)); | ||
const upper = y.add(delta); | ||
const lower = y.sub(delta); | ||
expect(x).to.be.bignumber.at.least(lower).and.bignumber.at.most(upper); | ||
} | ||
|
||
export const TimeHelpers = { | ||
secondsFromNow: async (secondsFromNow: number): Promise<number> => { | ||
return (await TimeHelpers.currentTime()) + secondsFromNow; | ||
}, | ||
|
||
increaseTime: async (seconds: number): Promise<void> => { | ||
await hre.network.provider.send("evm_increaseTime", [seconds]); | ||
await hre.network.provider.send("evm_mine"); | ||
}, | ||
|
||
setNextBlockTimestamp: async (timestamp: number): Promise<void> => { | ||
await ethers.provider.send("evm_setNextBlockTimestamp", [timestamp]); | ||
await hre.network.provider.send("evm_mine"); | ||
}, | ||
|
||
currentTime: async (): Promise<number> => { | ||
const res = await hre.network.provider.send("eth_getBlockByNumber", ["latest", false]); | ||
const timestamp = parseInt(res.timestamp, 16); | ||
return timestamp; | ||
}, | ||
|
||
increaseTimeForNextTransaction: async (diff: number): Promise<void> => { | ||
await promisify(ethers.provider.send.bind(ethers.provider))({ | ||
jsonrpc: "2.0", | ||
method: "evm_increaseTime", | ||
params: [diff], | ||
id: new Date().getTime(), | ||
}); | ||
}, | ||
|
||
setTimeForNextTransaction: async (target: number | BigInt): Promise<void> => { | ||
if (!BigInt.isBigNumber(target)) { | ||
target = BigInt(target); | ||
} | ||
|
||
const now = await TimeHelpers.currentTime(); | ||
|
||
if (target.lt(now)) | ||
throw Error( | ||
`Cannot increase current time (${now}) to a moment in the past (${target})`, | ||
); | ||
const diff = target.sub(now); | ||
await TimeHelpers.increaseTime(diff.toNumber()); | ||
}, | ||
}; | ||
|
||
async function printMethodOutput(r) { | ||
console.log(r.logs); | ||
} | ||
|
||
async function printStatus(dist) { | ||
console.log("Total Locked: ", await dist.totalLocked.call().toString()); | ||
console.log("Total UnLocked: ", await dist.totalUnlocked.call().toString()); | ||
const c = (await dist.unlockScheduleCount.call()).toNumber(); | ||
console.log(await dist.unlockScheduleCount.call().toString()); | ||
|
||
for (let i = 0; i < c; i++) { | ||
console.log(await dist.unlockSchedules.call(i).toString()); | ||
} | ||
// TODO: Print the following variables: | ||
// await dist.totalLocked.call() | ||
// await dist.totalUnlocked.call() | ||
// await dist.unlockScheduleCount.call() | ||
// dist.updateAccounting.call() // and all the logs | ||
// dist.unlockSchedules.call(1) | ||
} | ||
|
||
module.exports = { | ||
checkAmplAprox, | ||
checkSharesAprox, | ||
invokeRebase, | ||
$AMPL, | ||
TimeHelpers, | ||
printMethodOutput, | ||
printStatus, | ||
}; |
Oops, something went wrong.