From ffc2c2a5869cf0f7ef8683e0fb74416afb203342 Mon Sep 17 00:00:00 2001 From: SocksNFlops Date: Sat, 16 Mar 2024 01:06:03 +0800 Subject: [PATCH 1/4] style(prettier): adding semicolons to prettier-config --- .prettierrc | 2 +- hardhat.config.ts | 24 +- tasks/accounts.ts | 10 +- tasks/clean.ts | 14 +- tasks/deployers/ButtonTokenWamplRouter.ts | 33 +- tasks/deployers/ButtonTokenWethRouter.ts | 33 +- tasks/deployers/ankrETHOracle.ts | 65 +- tasks/deployers/api3Oracle.ts | 28 +- tasks/deployers/button.ts | 74 +- tasks/deployers/chainlinkOracle.ts | 28 +- tasks/deployers/ethxOracle.ts | 65 +- tasks/deployers/ggAVAXOracle.ts | 65 +- tasks/deployers/inceptionTokenOracle.ts | 71 +- tasks/deployers/index.ts | 39 +- tasks/deployers/mevEthOracle.ts | 65 +- tasks/deployers/mockERC20.ts | 33 +- tasks/deployers/mockOracle.ts | 30 +- tasks/deployers/rsEthRateRecieverOracle.ts | 65 +- tasks/deployers/sDaiOracle.ts | 65 +- tasks/deployers/savaxOracle.ts | 71 +- tasks/deployers/swETHOracle.ts | 65 +- tasks/deployers/unbutton.ts | 90 +-- tasks/deployers/uniETHOracle.ts | 65 +- tasks/deployers/wamplOracle.ts | 64 +- tasks/deployers/wethRouter.ts | 30 +- tasks/deployers/yyAVAXOracle.ts | 65 +- tasks/index.ts | 6 +- test/simulation/precision.ts | 210 ++--- test/unit/API3Oracle.ts | 80 +- test/unit/AnkrETHOracle.ts | 48 +- test/unit/ButtonToken.ts | 520 ++++++------- test/unit/ButtonTokenFactory.ts | 150 ++-- test/unit/ButtonTokenWamplRouter.ts | 250 +++--- test/unit/ButtonTokenWethRouter.ts | 199 ++--- test/unit/ButtonToken_button_wrapper.ts | 624 +++++++-------- test/unit/ButtonToken_erc20_behavior.ts | 518 ++++++------ .../ButtonToken_rebasing_erc20_behavior.ts | 271 ++++--- test/unit/ChainlinkOracle.ts | 80 +- test/unit/ETHxOracle.ts | 48 +- test/unit/GgAVAXOracle.ts | 48 +- test/unit/InceptionTokenOracle.ts | 68 +- test/unit/MevEthOracle.ts | 48 +- test/unit/RSETHRateReceiverOracle.ts | 46 +- test/unit/SDaiOracle.ts | 48 +- test/unit/SavaxOracle.ts | 48 +- test/unit/SwETHOracle.ts | 48 +- test/unit/UnbuttonToken.ts | 734 +++++++++--------- test/unit/UnbuttonTokenFactory.ts | 148 ++-- test/unit/UniETHOracle.ts | 68 +- test/unit/WamplOracle.ts | 184 ++--- test/unit/YyAVAXOracle.ts | 48 +- test/utils/loadDotEnv.ts | 14 +- test/utils/utils.ts | 22 +- 53 files changed, 2958 insertions(+), 2877 deletions(-) diff --git a/.prettierrc b/.prettierrc index f4d79c5..55816bb 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,5 @@ { - "semi": false, + "semi": true, "trailingComma": "all", "singleQuote": true, "bracketSpacing": true, diff --git a/hardhat.config.ts b/hardhat.config.ts index 538a509..2182a0c 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -1,15 +1,15 @@ -import './test/utils/loadDotEnv' -import { HardhatUserConfig } from 'hardhat/config' -import { Wallet } from 'ethers' -import '@nomiclabs/hardhat-ethers' -import '@nomiclabs/hardhat-waffle' -import '@openzeppelin/hardhat-upgrades' -import '@nomiclabs/hardhat-etherscan' -import 'solidity-coverage' -import 'hardhat-gas-reporter' -import './tasks' +import './test/utils/loadDotEnv'; +import { HardhatUserConfig } from 'hardhat/config'; +import { Wallet } from 'ethers'; +import '@nomiclabs/hardhat-ethers'; +import '@nomiclabs/hardhat-waffle'; +import '@openzeppelin/hardhat-upgrades'; +import '@nomiclabs/hardhat-etherscan'; +import 'solidity-coverage'; +import 'hardhat-gas-reporter'; +import './tasks'; -const DEFAULT_MNEMONIC = Wallet.createRandom().mnemonic.phrase +const DEFAULT_MNEMONIC = Wallet.createRandom().mnemonic.phrase; export default { etherscan: { @@ -144,4 +144,4 @@ export default { excludeContracts: ['mocks/'], coinmarketcap: process.env.COINMARKETCAP_API_KEY, }, -} as HardhatUserConfig +} as HardhatUserConfig; diff --git a/tasks/accounts.ts b/tasks/accounts.ts index 008af1d..1994548 100644 --- a/tasks/accounts.ts +++ b/tasks/accounts.ts @@ -1,10 +1,10 @@ -import { Signer } from '@ethersproject/abstract-signer' -import { task } from 'hardhat/config' +import { Signer } from '@ethersproject/abstract-signer'; +import { task } from 'hardhat/config'; task('accounts', 'Prints the list of accounts', async (_taskArgs, hre) => { - const accounts: Signer[] = await hre.ethers.getSigners() + const accounts: Signer[] = await hre.ethers.getSigners(); for (const account of accounts) { - console.log(await account.getAddress()) + console.log(await account.getAddress()); } -}) +}); diff --git a/tasks/clean.ts b/tasks/clean.ts index a8a18ca..538323c 100644 --- a/tasks/clean.ts +++ b/tasks/clean.ts @@ -1,13 +1,13 @@ -import fsExtra from 'fs-extra' -import { TASK_CLEAN } from 'hardhat/builtin-tasks/task-names' -import { task } from 'hardhat/config' +import fsExtra from 'fs-extra'; +import { TASK_CLEAN } from 'hardhat/builtin-tasks/task-names'; +import { task } from 'hardhat/config'; task( TASK_CLEAN, 'Overrides the standard clean task', async function (_taskArgs, _hre, runSuper) { - await fsExtra.remove('./coverage') - await fsExtra.remove('./coverage.json') - await runSuper() + await fsExtra.remove('./coverage'); + await fsExtra.remove('./coverage.json'); + await runSuper(); }, -) +); diff --git a/tasks/deployers/ButtonTokenWamplRouter.ts b/tasks/deployers/ButtonTokenWamplRouter.ts index bd0d9eb..4646e99 100644 --- a/tasks/deployers/ButtonTokenWamplRouter.ts +++ b/tasks/deployers/ButtonTokenWamplRouter.ts @@ -1,39 +1,42 @@ -import { task, types } from 'hardhat/config' -import { TaskArguments } from 'hardhat/types' +import { task, types } from 'hardhat/config'; +import { TaskArguments } from 'hardhat/types'; task('deploy:ButtonTokenWamplRouter') .addParam('wampl', 'the address of wampl', undefined, types.string, false) .setAction(async function (_args: TaskArguments, hre) { - const { wampl } = _args - console.log('Signer', await (await hre.ethers.getSigners())[0].getAddress()) + const { wampl } = _args; + console.log( + 'Signer', + await (await hre.ethers.getSigners())[0].getAddress(), + ); const ButtonTokenWamplRouter = await hre.ethers.getContractFactory( 'ButtonTokenWamplRouter', - ) - const buttonTokenWamplRouter = await ButtonTokenWamplRouter.deploy(wampl) - await buttonTokenWamplRouter.deployed() - const buttonTokenWamplRouterAddress = buttonTokenWamplRouter.address + ); + const buttonTokenWamplRouter = await ButtonTokenWamplRouter.deploy(wampl); + await buttonTokenWamplRouter.deployed(); + const buttonTokenWamplRouterAddress = buttonTokenWamplRouter.address; console.log( `ButtonTokenWamplRouter deployed to ${buttonTokenWamplRouterAddress}`, - ) + ); try { await hre.run('verify:ButtonTokenWamplRouter', { address: buttonTokenWamplRouterAddress, wampl, - }) + }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } - }) + }); task('verify:ButtonTokenWamplRouter', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) .addParam('wampl', 'the address of wampl', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - const { address, wampl } = args + const { address, wampl } = args; await hre.run('verify:verify', { address, constructorArguments: [wampl], - }) - }) + }); + }); diff --git a/tasks/deployers/ButtonTokenWethRouter.ts b/tasks/deployers/ButtonTokenWethRouter.ts index 61e9b02..2738407 100644 --- a/tasks/deployers/ButtonTokenWethRouter.ts +++ b/tasks/deployers/ButtonTokenWethRouter.ts @@ -1,39 +1,42 @@ -import { task, types } from 'hardhat/config' -import { TaskArguments } from 'hardhat/types' +import { task, types } from 'hardhat/config'; +import { TaskArguments } from 'hardhat/types'; task('deploy:ButtonTokenWethRouter') .addParam('weth', 'the address of weth', undefined, types.string, false) .setAction(async function (_args: TaskArguments, hre) { - const { weth } = _args - console.log('Signer', await (await hre.ethers.getSigners())[0].getAddress()) + const { weth } = _args; + console.log( + 'Signer', + await (await hre.ethers.getSigners())[0].getAddress(), + ); const ButtonTokenWethRouter = await hre.ethers.getContractFactory( 'ButtonTokenWethRouter', - ) - const buttonTokenWethRouter = await ButtonTokenWethRouter.deploy(weth) - await buttonTokenWethRouter.deployed() - const buttonTokenWethRouterAddress = buttonTokenWethRouter.address + ); + const buttonTokenWethRouter = await ButtonTokenWethRouter.deploy(weth); + await buttonTokenWethRouter.deployed(); + const buttonTokenWethRouterAddress = buttonTokenWethRouter.address; console.log( `ButtonTokenWethRouter deployed to ${buttonTokenWethRouterAddress}`, - ) + ); try { await hre.run('verify:ButtonTokenWethRouter', { address: buttonTokenWethRouterAddress, weth, - }) + }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } - }) + }); task('verify:ButtonTokenWethRouter', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) .addParam('weth', 'the address of weth', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - const { address, weth } = args + const { address, weth } = args; await hre.run('verify:verify', { address, constructorArguments: [weth], - }) - }) + }); + }); diff --git a/tasks/deployers/ankrETHOracle.ts b/tasks/deployers/ankrETHOracle.ts index da5e093..a22bc58 100644 --- a/tasks/deployers/ankrETHOracle.ts +++ b/tasks/deployers/ankrETHOracle.ts @@ -1,5 +1,5 @@ -import { task, types } from 'hardhat/config' -import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types' +import { task, types } from 'hardhat/config'; +import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types'; // ToDo: Change these const prefilledArgs: Record = { @@ -9,22 +9,22 @@ const prefilledArgs: Record = { goerli: { ankreth: '0x63dC5749fa134fF3B752813388a7215460a8aB01', }, -} +}; task('deploy:AnkrETHOracle:prefilled', 'Verifies on etherscan').setAction( async function (args: TaskArguments, hre) { - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) - const prefilled = prefilledArgs[hre.network.name] + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); + const prefilled = prefilledArgs[hre.network.name]; if (!prefilled) { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { ankreth } = prefilled - console.log('ankrETH Address:', ankreth) - await hre.run('deploy:AnkrETHOracle', { ankreth }) + const { ankreth } = prefilled; + console.log('ankrETH Address:', ankreth); + await hre.run('deploy:AnkrETHOracle', { ankreth }); }, -) +); task('deploy:AnkrETHOracle') .addParam( @@ -35,42 +35,45 @@ task('deploy:AnkrETHOracle') false, ) .setAction(async function (args: TaskArguments, hre) { - const { ankreth } = args - console.log('Signer', await (await hre.ethers.getSigners())[0].getAddress()) - const AnkrETHOracle = await hre.ethers.getContractFactory('AnkrETHOracle') - const ankrETHOracle = await AnkrETHOracle.deploy(ankreth) - await ankrETHOracle.deployed() - console.log(`AnkrETHOracle deployed to ${ankrETHOracle.address}`) + const { ankreth } = args; + console.log( + 'Signer', + await (await hre.ethers.getSigners())[0].getAddress(), + ); + const AnkrETHOracle = await hre.ethers.getContractFactory('AnkrETHOracle'); + const ankrETHOracle = await AnkrETHOracle.deploy(ankreth); + await ankrETHOracle.deployed(); + console.log(`AnkrETHOracle deployed to ${ankrETHOracle.address}`); try { await hre.run('verify:verify', { address: ankrETHOracle.address, constructorArguments: [ankreth], - }) + }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } - }) + }); task('verify:AnkrETHOracle:prefilled', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); - const prefilled = prefilledArgs[hre.network.name] + const prefilled = prefilledArgs[hre.network.name]; if (!prefilled) { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { ankreth } = prefilled + const { ankreth } = prefilled; - const { address } = args + const { address } = args; await hre.run('verify:verify', { address, constructorArguments: [ankreth], - }) - }) + }); + }); task('verify:AnkrETHOracle', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) @@ -82,10 +85,10 @@ task('verify:AnkrETHOracle', 'Verifies on etherscan') false, ) .setAction(async function (args: TaskArguments, hre) { - const { address, ankreth } = args + const { address, ankreth } = args; await hre.run('verify:verify', { address, constructorArguments: [ankreth], - }) - }) + }); + }); diff --git a/tasks/deployers/api3Oracle.ts b/tasks/deployers/api3Oracle.ts index 38bdd1c..42678e8 100644 --- a/tasks/deployers/api3Oracle.ts +++ b/tasks/deployers/api3Oracle.ts @@ -1,37 +1,37 @@ -import { task, types } from 'hardhat/config' -import { TaskArguments } from 'hardhat/types' +import { task, types } from 'hardhat/config'; +import { TaskArguments } from 'hardhat/types'; task('deploy:API3Oracle') .addParam('dapiproxy', 'the address of the underlying DapiProxy contract') .addParam('stalenessthresholdsecs', 'the number of seconds before refresh') .setAction(async function (args: TaskArguments, hre) { - const { dapiproxy, stalenessthresholdsecs } = args - const API3Oracle = await hre.ethers.getContractFactory('API3Oracle') - const oracle = await API3Oracle.deploy(dapiproxy, stalenessthresholdsecs) - await oracle.deployed() - const oracleAddress = oracle.address - console.log(`Oracle deployed to ${oracleAddress}`) + const { dapiproxy, stalenessthresholdsecs } = args; + const API3Oracle = await hre.ethers.getContractFactory('API3Oracle'); + const oracle = await API3Oracle.deploy(dapiproxy, stalenessthresholdsecs); + await oracle.deployed(); + const oracleAddress = oracle.address; + console.log(`Oracle deployed to ${oracleAddress}`); try { await hre.run('verify:API3Oracle', { address: oracleAddress, dapiproxy, stalenessthresholdsecs, - }) + }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } - }) + }); task('verify:API3Oracle') .addParam('address', 'the contract address', undefined, types.string, false) .addParam('dapiproxy', 'the address of the underlying DapiProxy contract') .addParam('stalenessthresholdsecs', 'the number of seconds before refresh') .setAction(async function (args: TaskArguments, hre) { - const { address, dapiproxy, stalenessthresholdsecs } = args + const { address, dapiproxy, stalenessthresholdsecs } = args; await hre.run('verify:verify', { address, constructorArguments: [dapiproxy, stalenessthresholdsecs], - }) - }) + }); + }); diff --git a/tasks/deployers/button.ts b/tasks/deployers/button.ts index 52da924..1122275 100644 --- a/tasks/deployers/button.ts +++ b/tasks/deployers/button.ts @@ -1,62 +1,62 @@ -import { Signer } from '@ethersproject/abstract-signer' -import { task, types } from 'hardhat/config' -import { TaskArguments } from 'hardhat/types' +import { Signer } from '@ethersproject/abstract-signer'; +import { task, types } from 'hardhat/config'; +import { TaskArguments } from 'hardhat/types'; task('deploy:ButtonTokenFactory').setAction(async function ( _args: TaskArguments, hre, ) { - console.log('Signer', await (await hre.ethers.getSigners())[0].getAddress()) - const TokenTemplate = await hre.ethers.getContractFactory('ButtonToken') - const tokenTemplate = await TokenTemplate.deploy() - await tokenTemplate.deployed() - const templateAddress = tokenTemplate.address - console.log(`ButtonToken template deployed to ${templateAddress}`) + console.log('Signer', await (await hre.ethers.getSigners())[0].getAddress()); + const TokenTemplate = await hre.ethers.getContractFactory('ButtonToken'); + const tokenTemplate = await TokenTemplate.deploy(); + await tokenTemplate.deployed(); + const templateAddress = tokenTemplate.address; + console.log(`ButtonToken template deployed to ${templateAddress}`); - const Factory = await hre.ethers.getContractFactory('ButtonTokenFactory') - const factory = await Factory.deploy(templateAddress) - await factory.deployed() - const factoryAddress = factory.address - console.log(`ButtonTokenFactory deployed to ${factoryAddress}`) + const Factory = await hre.ethers.getContractFactory('ButtonTokenFactory'); + const factory = await Factory.deploy(templateAddress); + await factory.deployed(); + const factoryAddress = factory.address; + console.log(`ButtonTokenFactory deployed to ${factoryAddress}`); try { - await hre.run('verify:ButtonToken', { address: templateAddress }) + await hre.run('verify:ButtonToken', { address: templateAddress }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } try { await hre.run('verify:ButtonTokenFactory', { address: factoryAddress, template: templateAddress, - }) + }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } -}) +}); task('verify:ButtonToken', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - const { address } = args + const { address } = args; await hre.run('verify:verify', { address, constructorArguments: [], - }) - }) + }); + }); task('verify:ButtonTokenFactory', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) .addParam('template', 'the template address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - const { address, template } = args + const { address, template } = args; await hre.run('verify:verify', { address, constructorArguments: [template], - }) - }) + }); + }); task('deploy:ButtonToken') .addParam('factory', 'the reference to the button token factory') @@ -65,31 +65,31 @@ task('deploy:ButtonToken') .addParam('symbol', 'the symbol of button token') .addParam('oracle', 'the oracle address. deploy with deploy:ChainlinkOracle') .setAction(async function (args: TaskArguments, hre) { - const { factory, underlying, name, symbol, oracle } = args - const accounts: Signer[] = await hre.ethers.getSigners() - const deployer = accounts[0] + const { factory, underlying, name, symbol, oracle } = args; + const accounts: Signer[] = await hre.ethers.getSigners(); + const deployer = accounts[0]; const bFactory = await hre.ethers.getContractAt( 'ButtonTokenFactory', factory, - ) + ); const deployedAddress = await bFactory.callStatic[ 'create(address,string,string,address)' - ](underlying, name, symbol, oracle) + ](underlying, name, symbol, oracle); const tx = await bFactory['create(address,string,string,address)']( underlying, name, symbol, oracle, - ) - await tx.wait() - console.log('Successfully created tx', tx.hash) - console.log('Token will be deployed to', deployedAddress) + ); + await tx.wait(); + console.log('Successfully created tx', tx.hash); + console.log('Token will be deployed to', deployedAddress); try { - await hre.run('verify:ButtonToken', { address: deployedAddress }) + await hre.run('verify:ButtonToken', { address: deployedAddress }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } - }) + }); diff --git a/tasks/deployers/chainlinkOracle.ts b/tasks/deployers/chainlinkOracle.ts index af45243..a57fb3b 100644 --- a/tasks/deployers/chainlinkOracle.ts +++ b/tasks/deployers/chainlinkOracle.ts @@ -1,42 +1,42 @@ -import { task, types } from 'hardhat/config' -import { TaskArguments } from 'hardhat/types' +import { task, types } from 'hardhat/config'; +import { TaskArguments } from 'hardhat/types'; task('deploy:ChainlinkOracle') .addParam('aggregator', 'the address of the backing chainlink aggregator') .addParam('stalenessthresholdsecs', 'the number of seconds before refresh') .setAction(async function (args: TaskArguments, hre) { - const { aggregator, stalenessthresholdsecs } = args + const { aggregator, stalenessthresholdsecs } = args; const ChainlinkOracle = await hre.ethers.getContractFactory( 'ChainlinkOracle', - ) + ); const oracle = await ChainlinkOracle.deploy( aggregator, stalenessthresholdsecs, - ) - await oracle.deployed() - const oracleAddress = oracle.address - console.log(`Oracle deployed to ${oracleAddress}`) + ); + await oracle.deployed(); + const oracleAddress = oracle.address; + console.log(`Oracle deployed to ${oracleAddress}`); try { await hre.run('verify:ChainlinkOracle', { address: oracleAddress, aggregator, stalenessthresholdsecs, - }) + }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } - }) + }); task('verify:ChainlinkOracle') .addParam('address', 'the contract address', undefined, types.string, false) .addParam('aggregator', 'the address of the backing chainlink aggregator') .addParam('stalenessthresholdsecs', 'the number of seconds before refresh') .setAction(async function (args: TaskArguments, hre) { - const { address, aggregator, stalenessthresholdsecs } = args + const { address, aggregator, stalenessthresholdsecs } = args; await hre.run('verify:verify', { address, constructorArguments: [aggregator, stalenessthresholdsecs], - }) - }) + }); + }); diff --git a/tasks/deployers/ethxOracle.ts b/tasks/deployers/ethxOracle.ts index 99d0d3c..d6f3df3 100644 --- a/tasks/deployers/ethxOracle.ts +++ b/tasks/deployers/ethxOracle.ts @@ -1,5 +1,5 @@ -import { task, types } from 'hardhat/config' -import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types' +import { task, types } from 'hardhat/config'; +import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types'; const prefilledArgs: Record = { mainnet: { @@ -8,22 +8,22 @@ const prefilledArgs: Record = { goerli: { staderoracle: '0x22F8E700ff3912f3Caba5e039F6dfF1a24390E80', }, -} +}; task('deploy:ETHxOracle:prefilled', 'Verifies on etherscan').setAction( async function (args: TaskArguments, hre) { - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) - const prefilled = prefilledArgs[hre.network.name] + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); + const prefilled = prefilledArgs[hre.network.name]; if (!prefilled) { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { staderoracle } = prefilled - console.log('staderOracle Address:', staderoracle) - await hre.run('deploy:ETHxOracle', { staderoracle }) + const { staderoracle } = prefilled; + console.log('staderOracle Address:', staderoracle); + await hre.run('deploy:ETHxOracle', { staderoracle }); }, -) +); task('deploy:ETHxOracle') .addParam( @@ -34,42 +34,45 @@ task('deploy:ETHxOracle') false, ) .setAction(async function (args: TaskArguments, hre) { - const { staderoracle } = args - console.log('Signer', await (await hre.ethers.getSigners())[0].getAddress()) - const ETHxOracle = await hre.ethers.getContractFactory('ETHxOracle') - const eTHxOracle = await ETHxOracle.deploy(staderoracle) - await eTHxOracle.deployed() - console.log(`ETHxOracle deployed to ${eTHxOracle.address}`) + const { staderoracle } = args; + console.log( + 'Signer', + await (await hre.ethers.getSigners())[0].getAddress(), + ); + const ETHxOracle = await hre.ethers.getContractFactory('ETHxOracle'); + const eTHxOracle = await ETHxOracle.deploy(staderoracle); + await eTHxOracle.deployed(); + console.log(`ETHxOracle deployed to ${eTHxOracle.address}`); try { await hre.run('verify:verify', { address: eTHxOracle.address, constructorArguments: [staderoracle], - }) + }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } - }) + }); task('verify:ETHxOracle:prefilled', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); - const prefilled = prefilledArgs[hre.network.name] + const prefilled = prefilledArgs[hre.network.name]; if (!prefilled) { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { staderoracle } = prefilled + const { staderoracle } = prefilled; - const { address } = args + const { address } = args; await hre.run('verify:verify', { address, constructorArguments: [staderoracle], - }) - }) + }); + }); task('verify:ETHxOracle', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) @@ -81,10 +84,10 @@ task('verify:ETHxOracle', 'Verifies on etherscan') false, ) .setAction(async function (args: TaskArguments, hre) { - const { address, staderoracle } = args + const { address, staderoracle } = args; await hre.run('verify:verify', { address, constructorArguments: [staderoracle], - }) - }) + }); + }); diff --git a/tasks/deployers/ggAVAXOracle.ts b/tasks/deployers/ggAVAXOracle.ts index 3d74e5b..a97f9ce 100644 --- a/tasks/deployers/ggAVAXOracle.ts +++ b/tasks/deployers/ggAVAXOracle.ts @@ -1,5 +1,5 @@ -import { task, types } from 'hardhat/config' -import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types' +import { task, types } from 'hardhat/config'; +import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types'; const prefilledArgs: Record = { avalanche: { @@ -8,22 +8,22 @@ const prefilledArgs: Record = { fuji: { ggavax: '0x', }, -} +}; task('deploy:GgAVAXOracle:prefilled', 'Verifies on snowtrace').setAction( async function (args: TaskArguments, hre) { - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) - const prefilled = prefilledArgs[hre.network.name] + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); + const prefilled = prefilledArgs[hre.network.name]; if (!prefilled) { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { ggavax } = prefilled - console.log('ggAVAX Address:', ggavax) - await hre.run('deploy:GgAVAXOracle', { ggavax }) + const { ggavax } = prefilled; + console.log('ggAVAX Address:', ggavax); + await hre.run('deploy:GgAVAXOracle', { ggavax }); }, -) +); task('deploy:GgAVAXOracle') .addParam( @@ -34,42 +34,45 @@ task('deploy:GgAVAXOracle') false, ) .setAction(async function (args: TaskArguments, hre) { - const { ggavax } = args - console.log('Signer', await (await hre.ethers.getSigners())[0].getAddress()) - const GgAVAXOracle = await hre.ethers.getContractFactory('GgAVAXOracle') - const ggAVAXOracle = await GgAVAXOracle.deploy(ggavax) - await ggAVAXOracle.deployed() - console.log(`GgAVAXOracle deployed to ${ggAVAXOracle.address}`) + const { ggavax } = args; + console.log( + 'Signer', + await (await hre.ethers.getSigners())[0].getAddress(), + ); + const GgAVAXOracle = await hre.ethers.getContractFactory('GgAVAXOracle'); + const ggAVAXOracle = await GgAVAXOracle.deploy(ggavax); + await ggAVAXOracle.deployed(); + console.log(`GgAVAXOracle deployed to ${ggAVAXOracle.address}`); try { await hre.run('verify:verify', { address: ggAVAXOracle.address, constructorArguments: [ggavax], - }) + }); } catch (e) { - console.log('Unable to verify on snowtrace', e) + console.log('Unable to verify on snowtrace', e); } - }) + }); task('verify:GgAVAXOracle:prefilled', 'Verifies on snowtrace') .addParam('address', 'the contract address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); - const prefilled = prefilledArgs[hre.network.name] + const prefilled = prefilledArgs[hre.network.name]; if (!prefilled) { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { ggavax } = prefilled + const { ggavax } = prefilled; - const { address } = args + const { address } = args; await hre.run('verify:verify', { address, constructorArguments: [ggavax], - }) - }) + }); + }); task('verify:GgAVAXOracle', 'Verifies on snowtrace') .addParam('address', 'the contract address', undefined, types.string, false) @@ -81,10 +84,10 @@ task('verify:GgAVAXOracle', 'Verifies on snowtrace') false, ) .setAction(async function (args: TaskArguments, hre) { - const { address, ggavax } = args + const { address, ggavax } = args; await hre.run('verify:verify', { address, constructorArguments: [ggavax], - }) - }) + }); + }); diff --git a/tasks/deployers/inceptionTokenOracle.ts b/tasks/deployers/inceptionTokenOracle.ts index 9c60508..0430e36 100644 --- a/tasks/deployers/inceptionTokenOracle.ts +++ b/tasks/deployers/inceptionTokenOracle.ts @@ -1,5 +1,5 @@ -import { task, types } from 'hardhat/config' -import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types' +import { task, types } from 'hardhat/config'; +import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types'; const prefilledArgs: Record = { mainnet: { @@ -18,7 +18,7 @@ const prefilledArgs: Record = { inceptionvault: '0x', }, }, -} +}; task('deploy:InceptionTokenOracle:prefilled', 'Verifies on etherscan') .addParam( @@ -29,19 +29,19 @@ task('deploy:InceptionTokenOracle:prefilled', 'Verifies on etherscan') false, ) .setAction(async function (args: TaskArguments, hre) { - const { underlying } = args - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) - console.log('Underlying:', underlying) - const prefilled = prefilledArgs[hre.network.name][underlying] + const { underlying } = args; + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); + console.log('Underlying:', underlying); + const prefilled = prefilledArgs[hre.network.name][underlying]; if (!prefilled) { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { inceptionvault } = prefilled - console.log('InceptionVault Address:', inceptionvault) - await hre.run('deploy:InceptionTokenOracle', { inceptionvault }) - }) + const { inceptionvault } = prefilled; + console.log('InceptionVault Address:', inceptionvault); + await hre.run('deploy:InceptionTokenOracle', { inceptionvault }); + }); task('deploy:InceptionTokenOracle') .addParam( @@ -52,28 +52,31 @@ task('deploy:InceptionTokenOracle') false, ) .setAction(async function (args: TaskArguments, hre) { - const { inceptionvault } = args - console.log('Signer', await (await hre.ethers.getSigners())[0].getAddress()) + const { inceptionvault } = args; + console.log( + 'Signer', + await (await hre.ethers.getSigners())[0].getAddress(), + ); const InceptionTokenOracle = await hre.ethers.getContractFactory( 'InceptionTokenOracle', - ) + ); const inceptionTokenOracle = await InceptionTokenOracle.deploy( inceptionvault, - ) - await inceptionTokenOracle.deployed() + ); + await inceptionTokenOracle.deployed(); console.log( `inceptionTokenOracle deployed to ${inceptionTokenOracle.address}`, - ) + ); try { await hre.run('verify:verify', { address: inceptionTokenOracle.address, constructorArguments: [inceptionvault], - }) + }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } - }) + }); task('verify:InceptionTokenOracle:prefilled', 'Verifies on etherscan') .addParam( @@ -85,22 +88,22 @@ task('verify:InceptionTokenOracle:prefilled', 'Verifies on etherscan') ) .addParam('address', 'the contract address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - const { underlying, address } = args - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) - console.log('Underlying:', underlying) + const { underlying, address } = args; + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); + console.log('Underlying:', underlying); - const prefilled = prefilledArgs[hre.network.name][underlying] + const prefilled = prefilledArgs[hre.network.name][underlying]; if (!prefilled) { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { inceptionVault } = prefilled + const { inceptionVault } = prefilled; await hre.run('verify:verify', { address, constructorArguments: [inceptionVault], - }) - }) + }); + }); task('verify:InceptionTokenOracle', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) @@ -112,10 +115,10 @@ task('verify:InceptionTokenOracle', 'Verifies on etherscan') false, ) .setAction(async function (args: TaskArguments, hre) { - const { address, inceptionvault } = args + const { address, inceptionvault } = args; await hre.run('verify:verify', { address, constructorArguments: [inceptionvault], - }) - }) + }); + }); diff --git a/tasks/deployers/index.ts b/tasks/deployers/index.ts index ff703a3..8a1cddf 100644 --- a/tasks/deployers/index.ts +++ b/tasks/deployers/index.ts @@ -1,19 +1,20 @@ -import './ankrETHOracle' -import './button' -import './ethxOracle' -import './ggAVAXOracle' -import './inceptionTokenOracle' -import './wethRouter' -import './wamplOracle' -import './mevEthOracle' -import './mockERC20' -import './mockOracle' -import './rsEthRateRecieverOracle' -import './savaxOracle' -import './swETHOracle' -import './sDaiOracle' -import './unbutton' -import './uniETHOracle' -import './ButtonTokenWethRouter' -import './ButtonTokenWamplRouter' -import './yyAVAXOracle' +import './ankrETHOracle'; +import './api3Oracle'; +import './button'; +import './ethxOracle'; +import './ggAVAXOracle'; +import './inceptionTokenOracle'; +import './wethRouter'; +import './wamplOracle'; +import './mevEthOracle'; +import './mockERC20'; +import './mockOracle'; +import './rsEthRateRecieverOracle'; +import './savaxOracle'; +import './swETHOracle'; +import './sDaiOracle'; +import './unbutton'; +import './uniETHOracle'; +import './ButtonTokenWethRouter'; +import './ButtonTokenWamplRouter'; +import './yyAVAXOracle'; diff --git a/tasks/deployers/mevEthOracle.ts b/tasks/deployers/mevEthOracle.ts index b59a3a2..7c73a70 100644 --- a/tasks/deployers/mevEthOracle.ts +++ b/tasks/deployers/mevEthOracle.ts @@ -1,5 +1,5 @@ -import { task, types } from 'hardhat/config' -import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types' +import { task, types } from 'hardhat/config'; +import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types'; const prefilledArgs: Record = { mainnet: { @@ -8,22 +8,22 @@ const prefilledArgs: Record = { goerli: { meveth: '0x', }, -} +}; task('deploy:MevEthOracle:prefilled', 'Verifies on etherscan').setAction( async function (args: TaskArguments, hre) { - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) - const prefilled = prefilledArgs[hre.network.name] + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); + const prefilled = prefilledArgs[hre.network.name]; if (!prefilled) { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { meveth } = prefilled - console.log('MevEth Address:', meveth) - await hre.run('deploy:MevEthOracle', { meveth }) + const { meveth } = prefilled; + console.log('MevEth Address:', meveth); + await hre.run('deploy:MevEthOracle', { meveth }); }, -) +); task('deploy:MevEthOracle') .addParam( @@ -34,42 +34,45 @@ task('deploy:MevEthOracle') false, ) .setAction(async function (args: TaskArguments, hre) { - const { meveth } = args - console.log('Signer', await (await hre.ethers.getSigners())[0].getAddress()) - const MevETHOracle = await hre.ethers.getContractFactory('MevEthOracle') - const mevETHOracle = await MevETHOracle.deploy(meveth) - await mevETHOracle.deployed() - console.log(`MevEthOracle deployed to ${mevETHOracle.address}`) + const { meveth } = args; + console.log( + 'Signer', + await (await hre.ethers.getSigners())[0].getAddress(), + ); + const MevETHOracle = await hre.ethers.getContractFactory('MevEthOracle'); + const mevETHOracle = await MevETHOracle.deploy(meveth); + await mevETHOracle.deployed(); + console.log(`MevEthOracle deployed to ${mevETHOracle.address}`); try { await hre.run('verify:verify', { address: mevETHOracle.address, constructorArguments: [meveth], - }) + }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } - }) + }); task('verify:MevEthOracle:prefilled', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); - const prefilled = prefilledArgs[hre.network.name] + const prefilled = prefilledArgs[hre.network.name]; if (!prefilled) { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { meveth } = prefilled + const { meveth } = prefilled; - const { address } = args + const { address } = args; await hre.run('verify:verify', { address, constructorArguments: [meveth], - }) - }) + }); + }); task('verify:MevEthOracle', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) @@ -81,10 +84,10 @@ task('verify:MevEthOracle', 'Verifies on etherscan') false, ) .setAction(async function (args: TaskArguments, hre) { - const { address, meveth } = args + const { address, meveth } = args; await hre.run('verify:verify', { address, constructorArguments: [meveth], - }) - }) + }); + }); diff --git a/tasks/deployers/mockERC20.ts b/tasks/deployers/mockERC20.ts index a937c35..26b9cdd 100644 --- a/tasks/deployers/mockERC20.ts +++ b/tasks/deployers/mockERC20.ts @@ -1,38 +1,41 @@ -import { task, types } from 'hardhat/config' -import { TaskArguments } from 'hardhat/types' +import { task, types } from 'hardhat/config'; +import { TaskArguments } from 'hardhat/types'; task('deploy:MockERC20') .addParam('name', 'the token name', undefined, types.string, false) .addParam('symbol', 'the token symbol', undefined, types.string, false) .setAction(async function (_args: TaskArguments, hre) { - const { name, symbol } = _args - console.log('Signer', await (await hre.ethers.getSigners())[0].getAddress()) - const MockERC20 = await hre.ethers.getContractFactory('MockERC20') - const mockERC20 = await MockERC20.deploy(name, symbol) - await mockERC20.deployed() - const mockERC20Address = mockERC20.address - console.log(`MockERC20 deployed to ${mockERC20Address}`) + const { name, symbol } = _args; + console.log( + 'Signer', + await (await hre.ethers.getSigners())[0].getAddress(), + ); + const MockERC20 = await hre.ethers.getContractFactory('MockERC20'); + const mockERC20 = await MockERC20.deploy(name, symbol); + await mockERC20.deployed(); + const mockERC20Address = mockERC20.address; + console.log(`MockERC20 deployed to ${mockERC20Address}`); try { await hre.run('verify:MockERC20', { address: mockERC20Address, name, symbol, - }) + }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } - }) + }); task('verify:MockERC20', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) .addParam('name', 'the token name', undefined, types.string, false) .addParam('symbol', 'the token symbol', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - const { address, name, symbol } = args + const { address, name, symbol } = args; await hre.run('verify:verify', { address, constructorArguments: [name, symbol], - }) - }) + }); + }); diff --git a/tasks/deployers/mockOracle.ts b/tasks/deployers/mockOracle.ts index 827b7fe..02a6d5e 100644 --- a/tasks/deployers/mockOracle.ts +++ b/tasks/deployers/mockOracle.ts @@ -1,29 +1,29 @@ -import { task, types } from 'hardhat/config' -import { TaskArguments } from 'hardhat/types' +import { task, types } from 'hardhat/config'; +import { TaskArguments } from 'hardhat/types'; task('deploy:MockOracle').setAction(async function (_args: TaskArguments, hre) { - const { name, symbol } = _args - console.log('Signer', await (await hre.ethers.getSigners())[0].getAddress()) - const MockOracle = await hre.ethers.getContractFactory('MockOracle') - const mockOracle = await MockOracle.deploy() - await mockOracle.deployed() - const mockOracleAddress = mockOracle.address - console.log(`MockOracle deployed to ${mockOracleAddress}`) + const { name, symbol } = _args; + console.log('Signer', await (await hre.ethers.getSigners())[0].getAddress()); + const MockOracle = await hre.ethers.getContractFactory('MockOracle'); + const mockOracle = await MockOracle.deploy(); + await mockOracle.deployed(); + const mockOracleAddress = mockOracle.address; + console.log(`MockOracle deployed to ${mockOracleAddress}`); try { - await hre.run('verify:MockOracle', { address: mockOracleAddress }) + await hre.run('verify:MockOracle', { address: mockOracleAddress }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } -}) +}); task('verify:MockOracle', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - const { address } = args + const { address } = args; await hre.run('verify:verify', { address, constructorArguments: [], - }) - }) + }); + }); diff --git a/tasks/deployers/rsEthRateRecieverOracle.ts b/tasks/deployers/rsEthRateRecieverOracle.ts index 9332b0b..b5887ed 100644 --- a/tasks/deployers/rsEthRateRecieverOracle.ts +++ b/tasks/deployers/rsEthRateRecieverOracle.ts @@ -1,5 +1,5 @@ -import { task, types } from 'hardhat/config' -import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types' +import { task, types } from 'hardhat/config'; +import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types'; const prefilledArgs: Record = { arbitrum: { @@ -8,23 +8,23 @@ const prefilledArgs: Record = { goerli: { rsethratereceiver: '0x', }, -} +}; task( 'deploy:RSETHRateReceiverOracle:prefilled', 'Verifies on etherscan', ).setAction(async function (args: TaskArguments, hre) { - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) - const prefilled = prefilledArgs[hre.network.name] + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); + const prefilled = prefilledArgs[hre.network.name]; if (!prefilled) { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { rsethratereceiver } = prefilled - console.log('RSETHRateReceiver Address:', rsethratereceiver) - await hre.run('deploy:RSETHRateReceiverOracle', { rsethratereceiver }) -}) + const { rsethratereceiver } = prefilled; + console.log('RSETHRateReceiver Address:', rsethratereceiver); + await hre.run('deploy:RSETHRateReceiverOracle', { rsethratereceiver }); +}); task('deploy:RSETHRateReceiverOracle') .addParam( @@ -35,48 +35,51 @@ task('deploy:RSETHRateReceiverOracle') false, ) .setAction(async function (args: TaskArguments, hre) { - const { rsethratereceiver } = args - console.log('Signer', await (await hre.ethers.getSigners())[0].getAddress()) + const { rsethratereceiver } = args; + console.log( + 'Signer', + await (await hre.ethers.getSigners())[0].getAddress(), + ); const RSETHRateReceiverOracle = await hre.ethers.getContractFactory( 'RSETHRateReceiverOracle', - ) + ); const rSETHRateReceiverOracle = await RSETHRateReceiverOracle.deploy( rsethratereceiver, - ) - await rSETHRateReceiverOracle.deployed() + ); + await rSETHRateReceiverOracle.deployed(); console.log( `RSETHRateReceiverOracle deployed to ${rSETHRateReceiverOracle.address}`, - ) + ); try { await hre.run('verify:verify', { address: rSETHRateReceiverOracle.address, constructorArguments: [rsethratereceiver], - }) + }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } - }) + }); task('verify:RSETHRateReceiverOracle:prefilled', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); - const prefilled = prefilledArgs[hre.network.name] + const prefilled = prefilledArgs[hre.network.name]; if (!prefilled) { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { rsethratereceiver } = prefilled + const { rsethratereceiver } = prefilled; - const { address } = args + const { address } = args; await hre.run('verify:verify', { address, constructorArguments: [rsethratereceiver], - }) - }) + }); + }); task('verify:RSETHRateReceiverOracle', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) @@ -88,10 +91,10 @@ task('verify:RSETHRateReceiverOracle', 'Verifies on etherscan') false, ) .setAction(async function (args: TaskArguments, hre) { - const { address, rsethratereceiver } = args + const { address, rsethratereceiver } = args; await hre.run('verify:verify', { address, constructorArguments: [rsethratereceiver], - }) - }) + }); + }); diff --git a/tasks/deployers/sDaiOracle.ts b/tasks/deployers/sDaiOracle.ts index 45debe2..5274616 100644 --- a/tasks/deployers/sDaiOracle.ts +++ b/tasks/deployers/sDaiOracle.ts @@ -1,5 +1,5 @@ -import { task, types } from 'hardhat/config' -import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types' +import { task, types } from 'hardhat/config'; +import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types'; const prefilledArgs: Record = { mainnet: { @@ -8,71 +8,74 @@ const prefilledArgs: Record = { goerli: { sdai: '0xD8134205b0328F5676aaeFb3B2a0DC15f4029d8C', }, -} +}; task('deploy:SDaiOracle:prefilled', 'Verifies on etherscan').setAction( async function (args: TaskArguments, hre) { - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) - const prefilled = prefilledArgs[hre.network.name] + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); + const prefilled = prefilledArgs[hre.network.name]; if (!prefilled) { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { sdai } = prefilled - console.log('sDAI Address:', sdai) - await hre.run('deploy:SDaiOracle', { sdai }) + const { sdai } = prefilled; + console.log('sDAI Address:', sdai); + await hre.run('deploy:SDaiOracle', { sdai }); }, -) +); task('deploy:SDaiOracle') .addParam('sdai', 'the sDAI token address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - const { sdai } = args - console.log('Signer', await (await hre.ethers.getSigners())[0].getAddress()) - const SDaiOracle = await hre.ethers.getContractFactory('SDaiOracle') - const sDaiOracle = await SDaiOracle.deploy(sdai) - await sDaiOracle.deployed() - console.log(`SDaiOracle deployed to ${sDaiOracle.address}`) + const { sdai } = args; + console.log( + 'Signer', + await (await hre.ethers.getSigners())[0].getAddress(), + ); + const SDaiOracle = await hre.ethers.getContractFactory('SDaiOracle'); + const sDaiOracle = await SDaiOracle.deploy(sdai); + await sDaiOracle.deployed(); + console.log(`SDaiOracle deployed to ${sDaiOracle.address}`); try { await hre.run('verify:verify', { address: sDaiOracle.address, constructorArguments: [sdai], - }) + }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } - }) + }); task('verify:SDaiOracle:prefilled', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); - const prefilled = prefilledArgs[hre.network.name] + const prefilled = prefilledArgs[hre.network.name]; if (!prefilled) { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { sdai } = prefilled + const { sdai } = prefilled; - const { address } = args + const { address } = args; await hre.run('verify:verify', { address, constructorArguments: [sdai], - }) - }) + }); + }); task('verify:SDaiOracle', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) .addParam('sdai', 'the sDAI token address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - const { address, sdai } = args + const { address, sdai } = args; await hre.run('verify:verify', { address, constructorArguments: [sdai], - }) - }) + }); + }); diff --git a/tasks/deployers/savaxOracle.ts b/tasks/deployers/savaxOracle.ts index 77f5d41..4e2554b 100644 --- a/tasks/deployers/savaxOracle.ts +++ b/tasks/deployers/savaxOracle.ts @@ -1,80 +1,83 @@ -import { task, types } from 'hardhat/config' -import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types' +import { task, types } from 'hardhat/config'; +import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types'; const argsAvalanche = { savax: '0x2b2C81e08f1Af8835a78Bb2A90AE924ACE0eA4bE', -} +}; const argsFuji = { savax: '0x0', -} +}; task('deploy:SavaxOracle:prefilled', 'Verifies on snowtrace').setAction( async function (args: TaskArguments, hre) { - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); if (hre.network.name === 'fuji') { - args = argsFuji + args = argsFuji; } else if (hre.network.name === 'avalanche') { - args = argsAvalanche + args = argsAvalanche; } else { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { savax } = args - console.log('Savax Address:', savax) - await hre.run('deploy:SavaxOracle', { savax }) + const { savax } = args; + console.log('Savax Address:', savax); + await hre.run('deploy:SavaxOracle', { savax }); }, -) +); task('deploy:SavaxOracle') .addParam('savax', 'the sAVAX token address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - const { savax } = args - console.log('Signer', await (await hre.ethers.getSigners())[0].getAddress()) - const SavaxOracle = await hre.ethers.getContractFactory('SavaxOracle') - const savaxOracle = await SavaxOracle.deploy(savax) - await savaxOracle.deployed() - console.log(`SavaxOracle deployed to ${savaxOracle.address}`) + const { savax } = args; + console.log( + 'Signer', + await (await hre.ethers.getSigners())[0].getAddress(), + ); + const SavaxOracle = await hre.ethers.getContractFactory('SavaxOracle'); + const savaxOracle = await SavaxOracle.deploy(savax); + await savaxOracle.deployed(); + console.log(`SavaxOracle deployed to ${savaxOracle.address}`); try { await hre.run('verify:verify', { address: savaxOracle.address, constructorArguments: [savax], - }) + }); } catch (e) { - console.log('Unable to verify on snowtrace', e) + console.log('Unable to verify on snowtrace', e); } - }) + }); task('verify:SavaxOracle:prefilled', 'Verifies on snowtrace') .addParam('address', 'the contract address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) - let savax + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); + let savax; if (hre.network.name === 'fuji') { - savax = argsFuji.savax + savax = argsFuji.savax; } else if (hre.network.name === 'avalanche') { - savax = argsAvalanche.savax + savax = argsAvalanche.savax; } else { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { address } = args + const { address } = args; await hre.run('verify:verify', { address, constructorArguments: [savax], - }) - }) + }); + }); task('verify:SavaxOracle', 'Verifies on snowtrace') .addParam('address', 'the contract address', undefined, types.string, false) .addParam('savax', 'the sAVAX token address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - const { address, savax } = args + const { address, savax } = args; await hre.run('verify:verify', { address, constructorArguments: [savax], - }) - }) + }); + }); diff --git a/tasks/deployers/swETHOracle.ts b/tasks/deployers/swETHOracle.ts index faadb0a..c124158 100644 --- a/tasks/deployers/swETHOracle.ts +++ b/tasks/deployers/swETHOracle.ts @@ -1,5 +1,5 @@ -import { task, types } from 'hardhat/config' -import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types' +import { task, types } from 'hardhat/config'; +import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types'; const prefilledArgs: Record = { mainnet: { @@ -8,71 +8,74 @@ const prefilledArgs: Record = { goerli: { sweth: '0x8bb383A752Ff3c1d510625C6F536E3332327068F', }, -} +}; task('deploy:SwETHOracle:prefilled', 'Verifies on etherscan').setAction( async function (args: TaskArguments, hre) { - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) - const prefilled = prefilledArgs[hre.network.name] + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); + const prefilled = prefilledArgs[hre.network.name]; if (!prefilled) { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { sweth } = prefilled - console.log('swETH Address:', sweth) - await hre.run('deploy:SwETHOracle', { sweth }) + const { sweth } = prefilled; + console.log('swETH Address:', sweth); + await hre.run('deploy:SwETHOracle', { sweth }); }, -) +); task('deploy:SwETHOracle') .addParam('sweth', 'the swETH token address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - const { sweth } = args - console.log('Signer', await (await hre.ethers.getSigners())[0].getAddress()) - const SwETHOracle = await hre.ethers.getContractFactory('SwETHOracle') - const swETHOracle = await SwETHOracle.deploy(sweth) - await swETHOracle.deployed() - console.log(`SwETHOracle deployed to ${swETHOracle.address}`) + const { sweth } = args; + console.log( + 'Signer', + await (await hre.ethers.getSigners())[0].getAddress(), + ); + const SwETHOracle = await hre.ethers.getContractFactory('SwETHOracle'); + const swETHOracle = await SwETHOracle.deploy(sweth); + await swETHOracle.deployed(); + console.log(`SwETHOracle deployed to ${swETHOracle.address}`); try { await hre.run('verify:verify', { address: swETHOracle.address, constructorArguments: [sweth], - }) + }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } - }) + }); task('verify:SwETHOracle:prefilled', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); - const prefilled = prefilledArgs[hre.network.name] + const prefilled = prefilledArgs[hre.network.name]; if (!prefilled) { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { sweth } = prefilled + const { sweth } = prefilled; - const { address } = args + const { address } = args; await hre.run('verify:verify', { address, constructorArguments: [sweth], - }) - }) + }); + }); task('verify:SwETHOracle', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) .addParam('sweth', 'the swETH token address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - const { address, sweth } = args + const { address, sweth } = args; await hre.run('verify:verify', { address, constructorArguments: [sweth], - }) - }) + }); + }); diff --git a/tasks/deployers/unbutton.ts b/tasks/deployers/unbutton.ts index 53ad60c..5445aa5 100644 --- a/tasks/deployers/unbutton.ts +++ b/tasks/deployers/unbutton.ts @@ -1,61 +1,61 @@ -import { Signer } from '@ethersproject/abstract-signer' -import { task, types } from 'hardhat/config' -import { TaskArguments } from 'hardhat/types' +import { Signer } from '@ethersproject/abstract-signer'; +import { task, types } from 'hardhat/config'; +import { TaskArguments } from 'hardhat/types'; task('deploy:UnbuttonTokenFactory').setAction(async function ( _args: TaskArguments, hre, ) { - const TokenTemplate = await hre.ethers.getContractFactory('UnbuttonToken') - const tokenTemplate = await TokenTemplate.deploy() - await tokenTemplate.deployed() - const templateAddress = tokenTemplate.address - console.log(`UnbuttonToken template deployed to ${templateAddress}`) + const TokenTemplate = await hre.ethers.getContractFactory('UnbuttonToken'); + const tokenTemplate = await TokenTemplate.deploy(); + await tokenTemplate.deployed(); + const templateAddress = tokenTemplate.address; + console.log(`UnbuttonToken template deployed to ${templateAddress}`); - const Factory = await hre.ethers.getContractFactory('UnbuttonTokenFactory') - const factory = await Factory.deploy(templateAddress) - await factory.deployed() - const factoryAddress = factory.address - console.log(`UnbuttonTokenFactory deployed to ${factoryAddress}`) + const Factory = await hre.ethers.getContractFactory('UnbuttonTokenFactory'); + const factory = await Factory.deploy(templateAddress); + await factory.deployed(); + const factoryAddress = factory.address; + console.log(`UnbuttonTokenFactory deployed to ${factoryAddress}`); try { - await hre.run('verify:UnbuttonToken', { address: templateAddress }) + await hre.run('verify:UnbuttonToken', { address: templateAddress }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } try { await hre.run('verify:UnbuttonTokenFactory', { address: factoryAddress, template: templateAddress, - }) + }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } -}) +}); task('verify:UnbuttonToken', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - const { address } = args + const { address } = args; await hre.run('verify:verify', { address, constructorArguments: [], - }) - }) + }); + }); task('verify:UnbuttonTokenFactory', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) .addParam('template', 'the template address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - const { address, template } = args + const { address, template } = args; await hre.run('verify:verify', { address, constructorArguments: [template], - }) - }) + }); + }); task('deploy:UnbuttonToken') .addParam('factory', 'the reference to the unbutton token factory') @@ -64,52 +64,52 @@ task('deploy:UnbuttonToken') .addParam('symbol', 'the symbol of unbutton token') .addParam('initialRate', 'the initial exchange rate') .setAction(async function (args: TaskArguments, hre) { - const { ethers } = hre - const { factory, underlying, name, symbol, initialRate } = args - const accounts: Signer[] = await hre.ethers.getSigners() - const deployer = accounts[0] - const deployerAddress = await deployer.getAddress() + const { ethers } = hre; + const { factory, underlying, name, symbol, initialRate } = args; + const accounts: Signer[] = await hre.ethers.getSigners(); + const deployer = accounts[0]; + const deployerAddress = await deployer.getAddress(); const ubFactory = await hre.ethers.getContractAt( 'UnbuttonTokenFactory', factory, - ) + ); const byteArgs = ethers.utils.defaultAbiCoder.encode( ['address', 'string', 'string', 'uint256'], [underlying, name, symbol, initialRate], - ) + ); const ubTemplate = await hre.ethers.getContractAt( 'UnbuttonToken', await ubFactory.template(), - ) + ); const underlyingToken = await hre.ethers.getContractAt( 'IRebasingERC20', underlying, - ) + ); const initialAllowance = await underlyingToken.allowance( deployerAddress, ubFactory.address, - ) - const expectedAllowance = await ubTemplate.INITIAL_DEPOSIT() + ); + const expectedAllowance = await ubTemplate.INITIAL_DEPOSIT(); if (initialAllowance.lt(expectedAllowance)) { - console.log('Setting allowance for initial deposit') + console.log('Setting allowance for initial deposit'); await ( await underlyingToken.approve(ubFactory.address, expectedAllowance) - ).wait(2) + ).wait(2); } - const deployedAddress = await ubFactory.callStatic.create(byteArgs) - const tx = await ubFactory.create(byteArgs) - console.log('Successfully created tx', tx.hash) - console.log('Token will be deployed to', deployedAddress) - await tx.wait(5) + const deployedAddress = await ubFactory.callStatic.create(byteArgs); + const tx = await ubFactory.create(byteArgs); + console.log('Successfully created tx', tx.hash); + console.log('Token will be deployed to', deployedAddress); + await tx.wait(5); try { - await hre.run('verify:UnbuttonToken', { address: deployedAddress }) + await hre.run('verify:UnbuttonToken', { address: deployedAddress }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } - }) + }); diff --git a/tasks/deployers/uniETHOracle.ts b/tasks/deployers/uniETHOracle.ts index e1bb721..62f3807 100644 --- a/tasks/deployers/uniETHOracle.ts +++ b/tasks/deployers/uniETHOracle.ts @@ -1,5 +1,5 @@ -import { task, types } from 'hardhat/config' -import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types' +import { task, types } from 'hardhat/config'; +import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types'; const prefilledArgs: Record = { mainnet: { @@ -8,22 +8,22 @@ const prefilledArgs: Record = { goerli: { rockxstaking: '0xa6E1a466626Db4927C197468026fa0A54c092492', }, -} +}; task('deploy:UniETHOracle:prefilled', 'Verifies on etherscan').setAction( async function (args: TaskArguments, hre) { - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) - const prefilled = prefilledArgs[hre.network.name] + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); + const prefilled = prefilledArgs[hre.network.name]; if (!prefilled) { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { rockxstaking } = prefilled - console.log('RockXStaking Address:', rockxstaking) - await hre.run('deploy:UniETHOracle', { rockxstaking }) + const { rockxstaking } = prefilled; + console.log('RockXStaking Address:', rockxstaking); + await hre.run('deploy:UniETHOracle', { rockxstaking }); }, -) +); task('deploy:UniETHOracle') .addParam( @@ -34,42 +34,45 @@ task('deploy:UniETHOracle') false, ) .setAction(async function (args: TaskArguments, hre) { - const { rockxstaking } = args - console.log('Signer', await (await hre.ethers.getSigners())[0].getAddress()) - const UniETHOracle = await hre.ethers.getContractFactory('UniETHOracle') - const uniETHOracle = await UniETHOracle.deploy(rockxstaking) - await uniETHOracle.deployed() - console.log(`UniETHOracle deployed to ${uniETHOracle.address}`) + const { rockxstaking } = args; + console.log( + 'Signer', + await (await hre.ethers.getSigners())[0].getAddress(), + ); + const UniETHOracle = await hre.ethers.getContractFactory('UniETHOracle'); + const uniETHOracle = await UniETHOracle.deploy(rockxstaking); + await uniETHOracle.deployed(); + console.log(`UniETHOracle deployed to ${uniETHOracle.address}`); try { await hre.run('verify:verify', { address: uniETHOracle.address, constructorArguments: [rockxstaking], - }) + }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } - }) + }); task('verify:UniETHOracle:prefilled', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); - const prefilled = prefilledArgs[hre.network.name] + const prefilled = prefilledArgs[hre.network.name]; if (!prefilled) { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { rockxstaking } = prefilled + const { rockxstaking } = prefilled; - const { address } = args + const { address } = args; await hre.run('verify:verify', { address, constructorArguments: [rockxstaking], - }) - }) + }); + }); task('verify:UniETHOracle', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) @@ -81,10 +84,10 @@ task('verify:UniETHOracle', 'Verifies on etherscan') false, ) .setAction(async function (args: TaskArguments, hre) { - const { address, rockxstaking } = args + const { address, rockxstaking } = args; await hre.run('verify:verify', { address, constructorArguments: [rockxstaking], - }) - }) + }); + }); diff --git a/tasks/deployers/wamplOracle.ts b/tasks/deployers/wamplOracle.ts index 777f359..3536f8b 100644 --- a/tasks/deployers/wamplOracle.ts +++ b/tasks/deployers/wamplOracle.ts @@ -1,45 +1,45 @@ -import { task, types } from 'hardhat/config' -import { TaskArguments } from 'hardhat/types' +import { task, types } from 'hardhat/config'; +import { TaskArguments } from 'hardhat/types'; const argsMainnet = { amplEthOracle: '0x492575FDD11a0fCf2C6C719867890a7648d526eB', ethUsdOracle: '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419', wampl: '0xEDB171C18cE90B633DB442f2A6F72874093b49Ef', stalenessThresholdSecs: 86400, -} +}; const argsKovan = { amplEthOracle: '0x562C092bEb3a6DF77aDf0BB604F52c018E4f2814', ethUsdOracle: '0x9326BFA02ADD2366b30bacB125260Af641031331', wampl: '0xD012092D13e5a4aa7A9032335B380C62Fc707232', stalenessThresholdSecs: 86400, -} +}; task('deploy:WamplOracle:mainnet', 'Verifies on etherscan').setAction( async function (args: TaskArguments, hre) { const { amplEthOracle, ethUsdOracle, wampl, stalenessThresholdSecs } = - argsMainnet + argsMainnet; await hre.run('deploy:WamplOracle', { amplEthOracle, ethUsdOracle, wampl, stalenessThresholdSecs, - }) + }); }, -) +); task('deploy:WamplOracle:kovan', 'Verifies on etherscan').setAction( async function (args: TaskArguments, hre) { const { amplEthOracle, ethUsdOracle, wampl, stalenessThresholdSecs } = - argsKovan + argsKovan; await hre.run('deploy:WamplOracle', { amplEthOracle, ethUsdOracle, wampl, stalenessThresholdSecs, - }) + }); }, -) +); task('deploy:WamplOracle') .addParam( @@ -65,17 +65,21 @@ task('deploy:WamplOracle') false, ) .setAction(async function (_args: TaskArguments, hre) { - const { amplEthOracle, ethUsdOracle, wampl, stalenessThresholdSecs } = _args - console.log('Signer', await (await hre.ethers.getSigners())[0].getAddress()) - const WamplOracle = await hre.ethers.getContractFactory('WamplOracle') + const { amplEthOracle, ethUsdOracle, wampl, stalenessThresholdSecs } = + _args; + console.log( + 'Signer', + await (await hre.ethers.getSigners())[0].getAddress(), + ); + const WamplOracle = await hre.ethers.getContractFactory('WamplOracle'); const wamplOracle = await WamplOracle.deploy( amplEthOracle, ethUsdOracle, wampl, stalenessThresholdSecs, - ) - await wamplOracle.deployed() - console.log(`WamplOracle deployed to ${wamplOracle.address}`) + ); + await wamplOracle.deployed(); + console.log(`WamplOracle deployed to ${wamplOracle.address}`); try { await hre.run('verify:verify', { @@ -86,18 +90,18 @@ task('deploy:WamplOracle') wampl, stalenessThresholdSecs, ], - }) + }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } - }) + }); task('verify:WamplOracle:mainnet', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - const { address } = args + const { address } = args; const { amplEthOracle, ethUsdOracle, wampl, stalenessThresholdSecs } = - argsMainnet + argsMainnet; await hre.run('verify:verify', { address, @@ -107,15 +111,15 @@ task('verify:WamplOracle:mainnet', 'Verifies on etherscan') wampl, stalenessThresholdSecs, ], - }) - }) + }); + }); task('verify:WamplOracle:kovan', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - const { address } = args + const { address } = args; const { amplEthOracle, ethUsdOracle, wampl, stalenessThresholdSecs } = - argsKovan + argsKovan; await hre.run('verify:verify', { address, @@ -125,8 +129,8 @@ task('verify:WamplOracle:kovan', 'Verifies on etherscan') wampl, stalenessThresholdSecs, ], - }) - }) + }); + }); task('verify:WamplOracle', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) @@ -159,7 +163,7 @@ task('verify:WamplOracle', 'Verifies on etherscan') ethUsdOracle, wampl, stalenessThresholdSecs, - } = args + } = args; await hre.run('verify:verify', { address, @@ -169,5 +173,5 @@ task('verify:WamplOracle', 'Verifies on etherscan') wampl, stalenessThresholdSecs, ], - }) - }) + }); + }); diff --git a/tasks/deployers/wethRouter.ts b/tasks/deployers/wethRouter.ts index 7fd898a..657b0d4 100644 --- a/tasks/deployers/wethRouter.ts +++ b/tasks/deployers/wethRouter.ts @@ -1,34 +1,34 @@ -import { task, types } from 'hardhat/config' -import { TaskArguments } from 'hardhat/types' +import { task, types } from 'hardhat/config'; +import { TaskArguments } from 'hardhat/types'; -const WETH_ADDRESS: string = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' +const WETH_ADDRESS: string = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'; task('deploy:WethRouter').setAction(async function (_args: TaskArguments, hre) { - console.log('Signer', await (await hre.ethers.getSigners())[0].getAddress()) - const factory = await hre.ethers.getContractFactory('ButtonTokenWethRouter') - const router = await factory.deploy(WETH_ADDRESS) - await router.deployed() - const routerAddress = router.address - console.log(`ButtonTokenWethRouter deployed to ${routerAddress}`) + console.log('Signer', await (await hre.ethers.getSigners())[0].getAddress()); + const factory = await hre.ethers.getContractFactory('ButtonTokenWethRouter'); + const router = await factory.deploy(WETH_ADDRESS); + await router.deployed(); + const routerAddress = router.address; + console.log(`ButtonTokenWethRouter deployed to ${routerAddress}`); try { await hre.run('verify:WethRouter', { address: routerAddress, wethAddress: WETH_ADDRESS, - }) + }); } catch (e) { - console.log('Unable to verify on etherscan', e) + console.log('Unable to verify on etherscan', e); } -}) +}); task('verify:WethRouter', 'Verifies on etherscan') .addParam('address', 'the contract address', undefined, types.string, false) .addParam('wethAddress', 'the weth address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - const { address, wethAddress } = args + const { address, wethAddress } = args; await hre.run('verify:verify', { address, constructorArguments: [wethAddress], - }) - }) + }); + }); diff --git a/tasks/deployers/yyAVAXOracle.ts b/tasks/deployers/yyAVAXOracle.ts index cb6e0cc..e587dfd 100644 --- a/tasks/deployers/yyAVAXOracle.ts +++ b/tasks/deployers/yyAVAXOracle.ts @@ -1,5 +1,5 @@ -import { task, types } from 'hardhat/config' -import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types' +import { task, types } from 'hardhat/config'; +import { HardhatRuntimeEnvironment, TaskArguments } from 'hardhat/types'; const prefilledArgs: Record = { avalanche: { @@ -8,22 +8,22 @@ const prefilledArgs: Record = { fuji: { yyavax: '0x', }, -} +}; task('deploy:YyAVAXOracle:prefilled', 'Verifies on snowtrace').setAction( async function (args: TaskArguments, hre) { - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) - const prefilled = prefilledArgs[hre.network.name] + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); + const prefilled = prefilledArgs[hre.network.name]; if (!prefilled) { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { yyavax } = prefilled - console.log('yyAVAX Address:', yyavax) - await hre.run('deploy:YyAVAXOracle', { yyavax }) + const { yyavax } = prefilled; + console.log('yyAVAX Address:', yyavax); + await hre.run('deploy:YyAVAXOracle', { yyavax }); }, -) +); task('deploy:YyAVAXOracle') .addParam( @@ -34,42 +34,45 @@ task('deploy:YyAVAXOracle') false, ) .setAction(async function (args: TaskArguments, hre) { - const { yyavax } = args - console.log('Signer', await (await hre.ethers.getSigners())[0].getAddress()) - const YyAVAXOracle = await hre.ethers.getContractFactory('YyAVAXOracle') - const yyAVAXOracle = await YyAVAXOracle.deploy(yyavax) - await yyAVAXOracle.deployed() - console.log(`YyAVAXOracle deployed to ${yyAVAXOracle.address}`) + const { yyavax } = args; + console.log( + 'Signer', + await (await hre.ethers.getSigners())[0].getAddress(), + ); + const YyAVAXOracle = await hre.ethers.getContractFactory('YyAVAXOracle'); + const yyAVAXOracle = await YyAVAXOracle.deploy(yyavax); + await yyAVAXOracle.deployed(); + console.log(`YyAVAXOracle deployed to ${yyAVAXOracle.address}`); try { await hre.run('verify:verify', { address: yyAVAXOracle.address, constructorArguments: [yyavax], - }) + }); } catch (e) { - console.log('Unable to verify on snowtrace', e) + console.log('Unable to verify on snowtrace', e); } - }) + }); task('verify:YyAVAXOracle:prefilled', 'Verifies on snowtrace') .addParam('address', 'the contract address', undefined, types.string, false) .setAction(async function (args: TaskArguments, hre) { - console.log('chainId:', hre.network.config.chainId) - console.log('Network:', hre.network.name) + console.log('chainId:', hre.network.config.chainId); + console.log('Network:', hre.network.name); - const prefilled = prefilledArgs[hre.network.name] + const prefilled = prefilledArgs[hre.network.name]; if (!prefilled) { - throw new Error('Network not supported') + throw new Error('Network not supported'); } - const { yyavax } = prefilled + const { yyavax } = prefilled; - const { address } = args + const { address } = args; await hre.run('verify:verify', { address, constructorArguments: [yyavax], - }) - }) + }); + }); task('verify:YyAVAXOracle', 'Verifies on snowtrace') .addParam('address', 'the contract address', undefined, types.string, false) @@ -81,10 +84,10 @@ task('verify:YyAVAXOracle', 'Verifies on snowtrace') false, ) .setAction(async function (args: TaskArguments, hre) { - const { address, yyavax } = args + const { address, yyavax } = args; await hre.run('verify:verify', { address, constructorArguments: [yyavax], - }) - }) + }); + }); diff --git a/tasks/index.ts b/tasks/index.ts index 00d4244..56704f0 100644 --- a/tasks/index.ts +++ b/tasks/index.ts @@ -1,3 +1,3 @@ -import './deployers' -import './accounts' -import './clean' +import './deployers'; +import './accounts'; +import './clean'; diff --git a/test/simulation/precision.ts b/test/simulation/precision.ts index 2a3b7dc..e9c59c8 100644 --- a/test/simulation/precision.ts +++ b/test/simulation/precision.ts @@ -15,210 +15,212 @@ A's resulting underlying balance will decrease by "precisely" y. */ -import { ethers, upgrades } from 'hardhat' -import { expect } from 'chai' -import { BigNumber, BigNumberish, Contract, Signer } from 'ethers' -import { imul } from '../utils/utils' -const Stochasm = require('stochasm') - -const PRICE_DECIMALS = 8 -const MAX_UNDERLYING = ethers.BigNumber.from(10).pow(27).sub(1) -const endPrice = ethers.BigNumber.from(2).pow(96).sub(1) +import { ethers, upgrades } from 'hardhat'; +import { expect } from 'chai'; +import { BigNumber, BigNumberish, Contract, Signer } from 'ethers'; +import { imul } from '../utils/utils'; +const Stochasm = require('stochasm'); + +const PRICE_DECIMALS = 8; +const MAX_UNDERLYING = ethers.BigNumber.from(10).pow(27).sub(1); +const endPrice = ethers.BigNumber.from(2).pow(96).sub(1); const priceGrowth = new Stochasm({ min: -0.5, max: 2.5, seed: 'fragments.org', -}) +}); let buttonToken: Contract, mockBTC: Contract, inflation: BigNumber, priceChange = ethers.BigNumber.from(0), deployer: Signer, - user: Signer + user: Signer; async function testMintBurn(cAmount: BigNumberish) { - expect(await mockBTC.balanceOf(deployer.getAddress())).to.eq(MAX_UNDERLYING) - expect(await buttonToken.balanceOf(deployer.getAddress())).to.eq('0') - expect(await buttonToken.scaledBalanceOf(deployer.getAddress())).to.eq('0') - expect(await buttonToken.totalSupply()).to.eq('0') - expect(await buttonToken.scaledTotalSupply()).to.eq('0') + expect(await mockBTC.balanceOf(deployer.getAddress())).to.eq(MAX_UNDERLYING); + expect(await buttonToken.balanceOf(deployer.getAddress())).to.eq('0'); + expect(await buttonToken.scaledBalanceOf(deployer.getAddress())).to.eq('0'); + expect(await buttonToken.totalSupply()).to.eq('0'); + expect(await buttonToken.scaledTotalSupply()).to.eq('0'); - console.log('Price', (await buttonToken.lastPrice()).toString()) - console.log('CAmount', cAmount.toString()) + console.log('Price', (await buttonToken.lastPrice()).toString()); + console.log('CAmount', cAmount.toString()); // deposit underlying - await mockBTC.connect(deployer).approve(buttonToken.address, cAmount) + await mockBTC.connect(deployer).approve(buttonToken.address, cAmount); - const b1 = await mockBTC.balanceOf(deployer.getAddress()) - await buttonToken.connect(deployer).deposit(cAmount) - const b2 = await mockBTC.balanceOf(deployer.getAddress()) - const depositedCAmount = b1.sub(b2) + const b1 = await mockBTC.balanceOf(deployer.getAddress()); + await buttonToken.connect(deployer).deposit(cAmount); + const b2 = await mockBTC.balanceOf(deployer.getAddress()); + const depositedCAmount = b1.sub(b2); // Exactly cAmount gets transferred to the button token contract - expect(depositedCAmount).to.eq(cAmount) + expect(depositedCAmount).to.eq(cAmount); expect(await mockBTC.balanceOf(deployer.getAddress())).to.eq( MAX_UNDERLYING.sub(depositedCAmount), - ) - expect(await mockBTC.balanceOf(buttonToken.address)).to.eq(depositedCAmount) + ); + expect(await mockBTC.balanceOf(buttonToken.address)).to.eq(depositedCAmount); // minter underlying balance increase exactly by depositedCAmount expect(await buttonToken.scaledBalanceOf(deployer.getAddress())).to.eq( depositedCAmount, - ) - expect(await buttonToken.scaledTotalSupply()).to.eq(depositedCAmount) + ); + expect(await buttonToken.scaledTotalSupply()).to.eq(depositedCAmount); // withdraw underlying - await buttonToken.connect(deployer).withdraw(cAmount) - const b3 = await mockBTC.balanceOf(deployer.getAddress()) - const withdrawnCAmount = b3.sub(b2) + await buttonToken.connect(deployer).withdraw(cAmount); + const b3 = await mockBTC.balanceOf(deployer.getAddress()); + const withdrawnCAmount = b3.sub(b2); // Exactly withdrawnCAmount gets transferred out of the button token contract - expect(withdrawnCAmount).to.eq(depositedCAmount) - expect(withdrawnCAmount).to.lte(cAmount) - expect(await mockBTC.balanceOf(deployer.getAddress())).to.eq(MAX_UNDERLYING) - expect(await mockBTC.balanceOf(buttonToken.address)).to.eq('0') + expect(withdrawnCAmount).to.eq(depositedCAmount); + expect(withdrawnCAmount).to.lte(cAmount); + expect(await mockBTC.balanceOf(deployer.getAddress())).to.eq(MAX_UNDERLYING); + expect(await mockBTC.balanceOf(buttonToken.address)).to.eq('0'); // burner underlying balance decreases exactly by withdrawnCAmount - expect(await buttonToken.scaledBalanceOf(deployer.getAddress())).to.eq('0') - expect(await buttonToken.scaledTotalSupply()).to.eq('0') + expect(await buttonToken.scaledBalanceOf(deployer.getAddress())).to.eq('0'); + expect(await buttonToken.scaledTotalSupply()).to.eq('0'); // burner balance decreases exactly by quotedAmt - expect(await buttonToken.balanceOf(deployer.getAddress())).to.eq('0') - expect(await buttonToken.totalSupply()).to.eq('0') + expect(await buttonToken.balanceOf(deployer.getAddress())).to.eq('0'); + expect(await buttonToken.totalSupply()).to.eq('0'); // burn bits if they are left over try { - await buttonToken.connect(deployer).withdrawAll() + await buttonToken.connect(deployer).withdrawAll(); } catch (e) {} } async function testTransfer(from: Signer, to: Signer, tAmt: BigNumberish) { - const _fromT = await buttonToken.balanceOf(from.getAddress()) - const _toT = await buttonToken.balanceOf(to.getAddress()) + const _fromT = await buttonToken.balanceOf(from.getAddress()); + const _toT = await buttonToken.balanceOf(to.getAddress()); - const _ts = await buttonToken.totalSupply() - const _sTs = await buttonToken.scaledTotalSupply() + const _ts = await buttonToken.totalSupply(); + const _sTs = await buttonToken.scaledTotalSupply(); - await buttonToken.connect(from).transfer(to.getAddress(), tAmt) + await buttonToken.connect(from).transfer(to.getAddress(), tAmt); - const fromT_ = await buttonToken.balanceOf(from.getAddress()) - const toT_ = await buttonToken.balanceOf(to.getAddress()) + const fromT_ = await buttonToken.balanceOf(from.getAddress()); + const toT_ = await buttonToken.balanceOf(to.getAddress()); - const ts_ = await buttonToken.totalSupply() - const sTs_ = await buttonToken.scaledTotalSupply() + const ts_ = await buttonToken.totalSupply(); + const sTs_ = await buttonToken.scaledTotalSupply(); // exactly tAmt gets transferred - expect(_fromT.sub(fromT_)).to.eq(tAmt) - expect(toT_.sub(_toT)).to.eq(tAmt) + expect(_fromT.sub(fromT_)).to.eq(tAmt); + expect(toT_.sub(_toT)).to.eq(tAmt); // sum of balances are conserved - expect(_fromT.add(_toT)).to.eq(fromT_.add(toT_)) + expect(_fromT.add(_toT)).to.eq(fromT_.add(toT_)); // supply does not change - expect(_ts).to.eq(ts_) - expect(_sTs).to.eq(sTs_) + expect(_ts).to.eq(ts_); + expect(_sTs).to.eq(sTs_); } async function exec() { - const accounts = await ethers.getSigners() - deployer = accounts[0] - user = accounts[1] + const accounts = await ethers.getSigners(); + deployer = accounts[0]; + user = accounts[1]; - const erc20Factory = await ethers.getContractFactory('MockERC20') + const erc20Factory = await ethers.getContractFactory('MockERC20'); mockBTC = await erc20Factory .connect(deployer) - .deploy('Wood Bitcoin', 'WOOD-BTC') + .deploy('Wood Bitcoin', 'WOOD-BTC'); - const oracleFactory = await ethers.getContractFactory('MockOracle') - const mockOracle = await oracleFactory.connect(deployer).deploy() - await mockOracle.setData('1', true) + const oracleFactory = await ethers.getContractFactory('MockOracle'); + const mockOracle = await oracleFactory.connect(deployer).deploy(); + await mockOracle.setData('1', true); - const buttonTokenFactory = await ethers.getContractFactory('ButtonToken') - buttonToken = await buttonTokenFactory.connect(deployer).deploy() + const buttonTokenFactory = await ethers.getContractFactory('ButtonToken'); + buttonToken = await buttonTokenFactory.connect(deployer).deploy(); - buttonToken.initialize(mockBTC.address, 'TEST', 'TEST', mockOracle.address) + buttonToken.initialize(mockBTC.address, 'TEST', 'TEST', mockOracle.address); await mockBTC .connect(deployer) - .mint(await deployer.getAddress(), MAX_UNDERLYING) + .mint(await deployer.getAddress(), MAX_UNDERLYING); - let i = 0 - let lastPrice = await buttonToken.lastPrice() + let i = 0; + let lastPrice = await buttonToken.lastPrice(); do { await mockOracle.setData( (await buttonToken.lastPrice()).add(priceChange), true, - ) - await buttonToken.connect(deployer).rebase() - lastPrice = await buttonToken.lastPrice() + ); + await buttonToken.connect(deployer).rebase(); + lastPrice = await buttonToken.lastPrice(); if (lastPrice.gte(endPrice)) { - break + break; } - i++ + i++; - console.log('Rebase iteration', i) - console.log('New price', lastPrice.toString(), 'price') + console.log('Rebase iteration', i); + console.log('New price', lastPrice.toString(), 'price'); // recalculate if bounds change const PRICE_BITS = BigNumber.from( '11579208923731619542357098500868790785326998466564000000000', - ) + ); const BITS_PER_UNDERLYING = BigNumber.from( '115792089237316195423570985008687907853269984665640', - ) + ); const minCollateral = PRICE_BITS.div(BITS_PER_UNDERLYING.mul(lastPrice)) .mul(2) - .add(1) + .add(1); console.log( `Testing precision of ${minCollateral.toString()} deposit and withdraw`, - ) - await testMintBurn(minCollateral) + ); + await testMintBurn(minCollateral); console.log( `Testing precision of ${MAX_UNDERLYING.div( 23, ).toString()} deposit and withdraw`, - ) - await testMintBurn(MAX_UNDERLYING.div(23)) + ); + await testMintBurn(MAX_UNDERLYING.div(23)); console.log( `Testing precision of ${MAX_UNDERLYING.toString()} deposit and withdraw`, - ) - await testMintBurn(MAX_UNDERLYING) + ); + await testMintBurn(MAX_UNDERLYING); - await mockBTC.connect(deployer).approve(buttonToken.address, MAX_UNDERLYING) + await mockBTC + .connect(deployer) + .approve(buttonToken.address, MAX_UNDERLYING); const mintAmount = await buttonToken .connect(deployer) - .callStatic.deposit(MAX_UNDERLYING) - await buttonToken.connect(deployer).deposit(MAX_UNDERLYING) + .callStatic.deposit(MAX_UNDERLYING); + await buttonToken.connect(deployer).deposit(MAX_UNDERLYING); - console.log('Testing precision of 1 unit transfer') - await testTransfer(deployer, user, '1') - await testTransfer(user, deployer, '1') + console.log('Testing precision of 1 unit transfer'); + await testTransfer(deployer, user, '1'); + await testTransfer(user, deployer, '1'); console.log( `Testing precision of ${mintAmount.div(23).toString()} transfer`, - ) - await testTransfer(deployer, user, mintAmount.div(23)) - await testTransfer(user, deployer, mintAmount.div(23)) + ); + await testTransfer(deployer, user, mintAmount.div(23)); + await testTransfer(user, deployer, mintAmount.div(23)); - console.log('Testing precision of max transfer') - await testTransfer(deployer, user, mintAmount) - await testTransfer(user, deployer, mintAmount) + console.log('Testing precision of max transfer'); + await testTransfer(deployer, user, mintAmount); + await testTransfer(user, deployer, mintAmount); try { - await buttonToken.connect(user).withdrawAll() + await buttonToken.connect(user).withdrawAll(); } catch (e) {} - await buttonToken.connect(deployer).withdrawAll() + await buttonToken.connect(deployer).withdrawAll(); - inflation = priceGrowth.next().toFixed(5) - priceChange = imul(lastPrice, inflation, 1) - } while (lastPrice.add(priceChange).lt(endPrice)) + inflation = priceGrowth.next().toFixed(5); + priceChange = imul(lastPrice, inflation, 1); + } while (lastPrice.add(priceChange).lt(endPrice)); } describe('Precision tests', function () { it('should successfully run simulation', async function () { - await exec() - }) -}) + await exec(); + }); +}); diff --git a/test/unit/API3Oracle.ts b/test/unit/API3Oracle.ts index 7ef22c7..aae5050 100644 --- a/test/unit/API3Oracle.ts +++ b/test/unit/API3Oracle.ts @@ -1,90 +1,90 @@ -import { ethers, waffle } from 'hardhat' -import { Contract, Signer } from 'ethers' -import { expect } from 'chai' -import { TransactionResponse } from '@ethersproject/providers' +import { ethers, waffle } from 'hardhat'; +import { Contract, Signer } from 'ethers'; +import { expect } from 'chai'; +import { TransactionResponse } from '@ethersproject/providers'; -let oracle: Contract, mockDapiProxy: Contract, oracleFetcher: Contract -let r: Promise -let deployer: Signer, user: Signer +let oracle: Contract, mockDapiProxy: Contract, oracleFetcher: Contract; +let r: Promise; +let deployer: Signer, user: Signer; async function mockedOracle() { - const [deployer, user] = await ethers.getSigners() + const [deployer, user] = await ethers.getSigners(); // deploy mocks const mockDapiProxy = await (await ethers.getContractFactory('MockDapiProxy')) .connect(deployer) - .deploy() + .deploy(); const oracle = await (await ethers.getContractFactory('API3Oracle')) .connect(deployer) - .deploy(mockDapiProxy.address, 60000) + .deploy(mockDapiProxy.address, 60000); const oracleFetcher = await ( await ethers.getContractFactory('MockOracleDataFetcher') ) .connect(deployer) - .deploy(oracle.address) + .deploy(oracle.address); return { deployer, user, oracle, oracleFetcher, mockDapiProxy, - } + }; } describe('API3Oracle', function () { before('setup Orchestrator contract', async () => { - ;({ deployer, user, oracle, oracleFetcher, mockDapiProxy } = - await waffle.loadFixture(mockedOracle)) - }) + ({ deployer, user, oracle, oracleFetcher, mockDapiProxy } = + await waffle.loadFixture(mockedOracle)); + }); describe('when sent ether', async function () { it('should reject', async function () { await expect(user.sendTransaction({ to: oracle.address, value: 1 })).to.be - .reverted - }) - }) + .reverted; + }); + }); describe('Fetching data', async function () { it('should fetch data', async function () { - const data = ethers.BigNumber.from('18923491321') + const data = ethers.BigNumber.from('18923491321'); await expect(mockDapiProxy.connect(user).setLatestAnswer(data)).to.not.be - .reverted + .reverted; await expect( mockDapiProxy .connect(user) .setUpdatedAt(Math.floor(new Date().valueOf() / 1000)), - ).to.not.be.reverted + ).to.not.be.reverted; // we use an oracle fetcher contract because, since the IOracle // interface getData function is writable, we can't fetch the response directly - const tx = await oracleFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [res, success] = await oracleFetcher.getData() + const tx = await oracleFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [res, success] = await oracleFetcher.getData(); - expect(res.toString()).to.eq(data.toString()) - expect(success).to.eq(true) - expect(receipt.gasUsed.toString()).to.equal('76533') - }) + expect(res.toString()).to.eq(data.toString()); + expect(success).to.eq(true); + expect(receipt.gasUsed.toString()).to.equal('76533'); + }); it('should fail with stale data', async function () { - const data = ethers.BigNumber.from('18923491321') + const data = ethers.BigNumber.from('18923491321'); await expect(mockDapiProxy.connect(user).setLatestAnswer(data)).to.not.be - .reverted + .reverted; await expect( mockDapiProxy .connect(user) .setUpdatedAt(Math.floor(new Date().valueOf() / 1000) - 100000), - ).to.not.be.reverted + ).to.not.be.reverted; - const tx = await oracleFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [res, success] = await oracleFetcher.getData() + const tx = await oracleFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [res, success] = await oracleFetcher.getData(); - expect(res.toString()).to.eq(data.toString()) - expect(success).to.eq(false) - expect(receipt.gasUsed.toString()).to.equal('34733') - }) - }) -}) + expect(res.toString()).to.eq(data.toString()); + expect(success).to.eq(false); + expect(receipt.gasUsed.toString()).to.equal('34733'); + }); + }); +}); diff --git a/test/unit/AnkrETHOracle.ts b/test/unit/AnkrETHOracle.ts index f96d8a7..b875717 100644 --- a/test/unit/AnkrETHOracle.ts +++ b/test/unit/AnkrETHOracle.ts @@ -1,23 +1,23 @@ -import { expect } from 'chai' -import { BigNumber } from 'ethers' -import { ethers, waffle } from 'hardhat' +import { expect } from 'chai'; +import { BigNumber } from 'ethers'; +import { ethers, waffle } from 'hardhat'; async function mockedOracle() { - const [deployer, user] = await ethers.getSigners() + const [deployer, user] = await ethers.getSigners(); // deploy mocks const mockAnkrETH = await (await ethers.getContractFactory('MockAnkrETH')) .connect(deployer) - .deploy() + .deploy(); // deploy contract to test const oracle = await (await ethers.getContractFactory('AnkrETHOracle')) .connect(deployer) - .deploy(mockAnkrETH.address) + .deploy(mockAnkrETH.address); // need a contract with a non-view method that calls oracle.getData so we can gas test const mockOracleDataFetcher = await ( await ethers.getContractFactory('MockOracleDataFetcher') ) .connect(deployer) - .deploy(oracle.address) + .deploy(oracle.address); return { deployer, @@ -25,42 +25,42 @@ async function mockedOracle() { mockAnkrETH, oracle, mockOracleDataFetcher, - } + }; } describe('AnkrETHOracle', function () { describe('when sent ether', async function () { it('should reject', async function () { - const { user, oracle } = await waffle.loadFixture(mockedOracle) + const { user, oracle } = await waffle.loadFixture(mockedOracle); await expect(user.sendTransaction({ to: oracle.address, value: 1 })).to.be - .reverted - }) - }) + .reverted; + }); + }); describe('Fetching data', async function () { it('should succeed with fresh data', async function () { const { user, mockAnkrETH, mockOracleDataFetcher } = - await waffle.loadFixture(mockedOracle) + await waffle.loadFixture(mockedOracle); await expect( mockAnkrETH .connect(user) .setTotalShares(BigNumber.from('6413278131285121422182816')), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockAnkrETH .connect(user) .setTotalBonds(BigNumber.from('7091831834635293267033248')), - ).to.not.be.reverted + ).to.not.be.reverted; - const tx = await mockOracleDataFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [value, valid] = await mockOracleDataFetcher.getData() + const tx = await mockOracleDataFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [value, valid] = await mockOracleDataFetcher.getData(); // mockAnkrETH denominated in ETH should be totalShares/totalBonds - expect(value.toString()).to.eq('1105804502698871756') - expect(valid).to.eq(true) - expect(receipt.gasUsed.toString()).to.equal('78601') - }) - }) -}) + expect(value.toString()).to.eq('1105804502698871756'); + expect(valid).to.eq(true); + expect(receipt.gasUsed.toString()).to.equal('78601'); + }); + }); +}); diff --git a/test/unit/ButtonToken.ts b/test/unit/ButtonToken.ts index c705394..a174eff 100644 --- a/test/unit/ButtonToken.ts +++ b/test/unit/ButtonToken.ts @@ -1,20 +1,20 @@ -import { ethers, upgrades } from 'hardhat' -import { Contract, Signer, BigNumber, BigNumberish } from 'ethers' -import { expect } from 'chai' +import { ethers, upgrades } from 'hardhat'; +import { Contract, Signer, BigNumber, BigNumberish } from 'ethers'; +import { expect } from 'chai'; -const PRICE_DECIMALS = 8 -const DECIMALS = 18 -const NAME = 'Button Bitcoin' -const SYMBOL = 'BTN-BTC' +const PRICE_DECIMALS = 8; +const DECIMALS = 18; +const NAME = 'Button Bitcoin'; +const SYMBOL = 'BTN-BTC'; const toOracleValue = (v: string): BigNumber => - ethers.utils.parseUnits(v, PRICE_DECIMALS) + ethers.utils.parseUnits(v, PRICE_DECIMALS); const toFixedPtAmt = (a: string): BigNumber => - ethers.utils.parseUnits(a, DECIMALS) + ethers.utils.parseUnits(a, DECIMALS); -const transferAmount = toFixedPtAmt('10') -const unitTokenAmount = toFixedPtAmt('1') +const transferAmount = toFixedPtAmt('10'); +const unitTokenAmount = toFixedPtAmt('1'); let accounts: Signer[], deployer: Signer, @@ -30,112 +30,112 @@ let accounts: Signer[], buttonToken: Contract, underlyingSupply: BigNumber, cbA: BigNumber, - cbB: BigNumber + cbB: BigNumber; async function setupContracts() { - accounts = await ethers.getSigners() - deployer = accounts[0] - userA = accounts[1] - userB = accounts[2] - userC = accounts[3] - - deployerAddress = await deployer.getAddress() - userAAddress = await userA.getAddress() - userBAddress = await userB.getAddress() - userCAddress = await userC.getAddress() - - const erc20Factory = await ethers.getContractFactory('MockERC20') + accounts = await ethers.getSigners(); + deployer = accounts[0]; + userA = accounts[1]; + userB = accounts[2]; + userC = accounts[3]; + + deployerAddress = await deployer.getAddress(); + userAAddress = await userA.getAddress(); + userBAddress = await userB.getAddress(); + userCAddress = await userC.getAddress(); + + const erc20Factory = await ethers.getContractFactory('MockERC20'); mockBTC = await erc20Factory .connect(deployer) - .deploy('Wood Bitcoin', 'WOOD-BTC') + .deploy('Wood Bitcoin', 'WOOD-BTC'); - const oracleFactory = await ethers.getContractFactory('MockOracle') - mockOracle = await oracleFactory.connect(deployer).deploy() - await mockOracle.setData(toOracleValue('10000'), true) + const oracleFactory = await ethers.getContractFactory('MockOracle'); + mockOracle = await oracleFactory.connect(deployer).deploy(); + await mockOracle.setData(toOracleValue('10000'), true); - const buttonTokenFactory = await ethers.getContractFactory('ButtonToken') - buttonToken = await buttonTokenFactory.connect(deployer).deploy() + const buttonTokenFactory = await ethers.getContractFactory('ButtonToken'); + buttonToken = await buttonTokenFactory.connect(deployer).deploy(); - buttonToken.initialize(mockBTC.address, NAME, SYMBOL, mockOracle.address) + buttonToken.initialize(mockBTC.address, NAME, SYMBOL, mockOracle.address); } function eqAprox(x: BigNumber, y: BigNumberish, diff: BigNumberish = '1') { - expect(x.sub(y).abs()).lte(diff).gte('0') + expect(x.sub(y).abs()).lte(diff).gte('0'); } describe('ButtonToken', () => { - before('setup ButtonToken contract', setupContracts) + before('setup ButtonToken contract', setupContracts); it('should reject any ether sent to it', async function () { - const user = accounts[1] + const user = accounts[1]; await expect(user.sendTransaction({ to: buttonToken.address, value: 1 })).to - .be.reverted - }) -}) + .be.reverted; + }); +}); describe('ButtonToken:Initialization', () => { - beforeEach('setup ButtonToken contract', setupContracts) + beforeEach('setup ButtonToken contract', setupContracts); it('should set the owner', async function () { - expect(await buttonToken.owner()).to.eq(deployerAddress) - }) + expect(await buttonToken.owner()).to.eq(deployerAddress); + }); it('should set the underlying reference', async function () { - expect(await buttonToken.underlying()).to.eq(mockBTC.address) - }) + expect(await buttonToken.underlying()).to.eq(mockBTC.address); + }); it('should set detailed erc20 info parameters', async function () { - expect(await buttonToken.name()).to.eq(NAME) - expect(await buttonToken.symbol()).to.eq(SYMBOL) - expect(await buttonToken.decimals()).to.eq(await mockBTC.decimals()) - }) + expect(await buttonToken.name()).to.eq(NAME); + expect(await buttonToken.symbol()).to.eq(SYMBOL); + expect(await buttonToken.decimals()).to.eq(await mockBTC.decimals()); + }); it('should set the erc20 balance and supply parameters', async function () { - eqAprox(await buttonToken.totalSupply(), '0') - expect(await buttonToken.scaledTotalSupply()).to.eq('0') - eqAprox(await buttonToken.balanceOf(deployerAddress), '0') - expect(await buttonToken.scaledBalanceOf(deployerAddress)).to.eq('0') - }) + eqAprox(await buttonToken.totalSupply(), '0'); + expect(await buttonToken.scaledTotalSupply()).to.eq('0'); + eqAprox(await buttonToken.balanceOf(deployerAddress), '0'); + expect(await buttonToken.scaledBalanceOf(deployerAddress)).to.eq('0'); + }); it('should set the oracle price and reference', async function () { - expect(await buttonToken.oracle()).to.eq(mockOracle.address) - }) -}) + expect(await buttonToken.oracle()).to.eq(mockOracle.address); + }); +}); describe('ButtonToken:updateOracle', async () => { - beforeEach('setup ButtonToken contract', setupContracts) + beforeEach('setup ButtonToken contract', setupContracts); describe('when invoked by non owner', function () { it('should revert', async function () { - const oracleFactory = await ethers.getContractFactory('MockOracle') - mockOracle = await oracleFactory.connect(deployer).deploy() - await mockOracle.setData(toOracleValue('45000'), true) + const oracleFactory = await ethers.getContractFactory('MockOracle'); + mockOracle = await oracleFactory.connect(deployer).deploy(); + await mockOracle.setData(toOracleValue('45000'), true); await expect( buttonToken.connect(userA).updateOracle(mockOracle.address), - ).to.be.revertedWith('Ownable: caller is not the owner') - }) - }) + ).to.be.revertedWith('Ownable: caller is not the owner'); + }); + }); describe('when the new price oracle is NOT valid', function () { it('should revert', async function () { - const oracleFactory = await ethers.getContractFactory('MockOracle') - mockOracle = await oracleFactory.connect(deployer).deploy() - await mockOracle.setData(toOracleValue('45000'), false) + const oracleFactory = await ethers.getContractFactory('MockOracle'); + mockOracle = await oracleFactory.connect(deployer).deploy(); + await mockOracle.setData(toOracleValue('45000'), false); await expect( buttonToken.connect(deployer).updateOracle(mockOracle.address), - ).to.be.revertedWith('ButtonToken: unable to fetch data from oracle') - }) - }) + ).to.be.revertedWith('ButtonToken: unable to fetch data from oracle'); + }); + }); describe('when the new price oracle is valid', function () { it('should update the reference and rebase with new price', async function () { - const oracleFactory = await ethers.getContractFactory('MockOracle') - mockOracle = await oracleFactory.connect(deployer).deploy() - await mockOracle.setData(toOracleValue('45000'), true) + const oracleFactory = await ethers.getContractFactory('MockOracle'); + mockOracle = await oracleFactory.connect(deployer).deploy(); + await mockOracle.setData(toOracleValue('45000'), true); - expect(await buttonToken.oracle()).to.not.eq(mockOracle.address) + expect(await buttonToken.oracle()).to.not.eq(mockOracle.address); await expect( buttonToken.connect(deployer).updateOracle(mockOracle.address), @@ -143,28 +143,28 @@ describe('ButtonToken:updateOracle', async () => { .to.emit(buttonToken, 'Rebase') .withArgs('2', toOracleValue('45000')) .to.emit(buttonToken, 'OracleUpdated') - .withArgs(mockOracle.address) + .withArgs(mockOracle.address); - expect(await buttonToken.oracle()).to.eq(mockOracle.address) - expect(await buttonToken.lastPrice()).to.eq(toOracleValue('45000')) - }) - }) + expect(await buttonToken.oracle()).to.eq(mockOracle.address); + expect(await buttonToken.lastPrice()).to.eq(toOracleValue('45000')); + }); + }); describe('when the new price oracle is ZERO', function () { it('should update price, freeze funds', async function () { - const MINT_AMT = toFixedPtAmt('1') + const MINT_AMT = toFixedPtAmt('1'); // legit user deposits tokens - await mockBTC.connect(deployer).mint(deployerAddress, MINT_AMT) - await mockBTC.connect(deployer).approve(buttonToken.address, MINT_AMT) - await buttonToken.connect(deployer).deposit(MINT_AMT) + await mockBTC.connect(deployer).mint(deployerAddress, MINT_AMT); + await mockBTC.connect(deployer).approve(buttonToken.address, MINT_AMT); + await buttonToken.connect(deployer).deposit(MINT_AMT); // malicious owner updates price to zero - const oracleFactory = await ethers.getContractFactory('MockOracle') - mockOracle = await oracleFactory.connect(deployer).deploy() - await mockOracle.setData(toOracleValue('1'), true) + const oracleFactory = await ethers.getContractFactory('MockOracle'); + mockOracle = await oracleFactory.connect(deployer).deploy(); + await mockOracle.setData(toOracleValue('1'), true); - expect(await buttonToken.oracle()).to.not.eq(mockOracle.address) + expect(await buttonToken.oracle()).to.not.eq(mockOracle.address); await expect( buttonToken.connect(deployer).updateOracle(mockOracle.address), @@ -172,311 +172,311 @@ describe('ButtonToken:updateOracle', async () => { .to.emit(buttonToken, 'Rebase') .withArgs('3', toOracleValue('1')) .to.emit(buttonToken, 'OracleUpdated') - .withArgs(mockOracle.address) + .withArgs(mockOracle.address); - await mockOracle.setData(toOracleValue('0'), true) - await expect(buttonToken.rebase()).to.not.be.reverted + await mockOracle.setData(toOracleValue('0'), true); + await expect(buttonToken.rebase()).to.not.be.reverted; - expect(await buttonToken.oracle()).to.eq(mockOracle.address) - expect(await buttonToken.lastPrice()).to.eq(toOracleValue('1')) + expect(await buttonToken.oracle()).to.eq(mockOracle.address); + expect(await buttonToken.lastPrice()).to.eq(toOracleValue('1')); // checks that you can still withdraw await expect(buttonToken.connect(deployer).withdraw(MINT_AMT)).to.not.be - .reverted - }) - }) -}) + .reverted; + }); + }); +}); describe('ButtonToken:Rebase:Expansion', async () => { // Rebase +10%, with starting balances A:750 and B:250. - let r: any + let r: any; before('setup ButtonToken contract', async function () { - await setupContracts() + await setupContracts(); - await mockBTC.connect(deployer).mint(deployerAddress, toFixedPtAmt('1')) + await mockBTC.connect(deployer).mint(deployerAddress, toFixedPtAmt('1')); await mockBTC .connect(deployer) - .approve(buttonToken.address, toFixedPtAmt('1')) + .approve(buttonToken.address, toFixedPtAmt('1')); - await buttonToken.connect(deployer).deposit(toFixedPtAmt('1')) + await buttonToken.connect(deployer).deposit(toFixedPtAmt('1')); await buttonToken .connect(deployer) - .transfer(userAAddress, toFixedPtAmt('7500')) + .transfer(userAAddress, toFixedPtAmt('7500')); await buttonToken .connect(deployer) - .transfer(userBAddress, toFixedPtAmt('2500')) + .transfer(userBAddress, toFixedPtAmt('2500')); - eqAprox(await buttonToken.totalSupply(), toFixedPtAmt('10000')) - eqAprox(await buttonToken.balanceOf(deployerAddress), toFixedPtAmt('0')) - eqAprox(await buttonToken.balanceOf(userAAddress), toFixedPtAmt('7500')) - eqAprox(await buttonToken.balanceOf(userBAddress), toFixedPtAmt('2500')) + eqAprox(await buttonToken.totalSupply(), toFixedPtAmt('10000')); + eqAprox(await buttonToken.balanceOf(deployerAddress), toFixedPtAmt('0')); + eqAprox(await buttonToken.balanceOf(userAAddress), toFixedPtAmt('7500')); + eqAprox(await buttonToken.balanceOf(userBAddress), toFixedPtAmt('2500')); - underlyingSupply = await buttonToken.scaledTotalSupply() - cbA = await buttonToken.scaledBalanceOf(userAAddress) - cbB = await buttonToken.scaledBalanceOf(userBAddress) + underlyingSupply = await buttonToken.scaledTotalSupply(); + cbA = await buttonToken.scaledBalanceOf(userAAddress); + cbB = await buttonToken.scaledBalanceOf(userBAddress); - await mockOracle.setData(toOracleValue('11000'), true) - r = buttonToken.rebase() - await r - }) + await mockOracle.setData(toOracleValue('11000'), true); + r = buttonToken.rebase(); + await r; + }); it('should emit Rebase', async function () { await expect(r) .to.emit(buttonToken, 'Rebase') - .withArgs('5', toOracleValue('11000')) - }) + .withArgs('5', toOracleValue('11000')); + }); it('should increase the totalSupply', async function () { - eqAprox(await buttonToken.totalSupply(), toFixedPtAmt('11000')) - }) + eqAprox(await buttonToken.totalSupply(), toFixedPtAmt('11000')); + }); it('should NOT CHANGE the scaledTotalSupply', async function () { - expect(await buttonToken.scaledTotalSupply()).to.eq(underlyingSupply) - }) + expect(await buttonToken.scaledTotalSupply()).to.eq(underlyingSupply); + }); it('should increase individual balances', async function () { - eqAprox(await buttonToken.balanceOf(userAAddress), toFixedPtAmt('8250')) - eqAprox(await buttonToken.balanceOf(userBAddress), toFixedPtAmt('2750')) - }) + eqAprox(await buttonToken.balanceOf(userAAddress), toFixedPtAmt('8250')); + eqAprox(await buttonToken.balanceOf(userBAddress), toFixedPtAmt('2750')); + }); it('should NOT CHANGE the individual scaled balances', async function () { - expect(await buttonToken.scaledBalanceOf(userAAddress)).to.eq(cbA) - expect(await buttonToken.scaledBalanceOf(userBAddress)).to.eq(cbB) - }) -}) + expect(await buttonToken.scaledBalanceOf(userAAddress)).to.eq(cbA); + expect(await buttonToken.scaledBalanceOf(userBAddress)).to.eq(cbB); + }); +}); describe('ButtonToken:Rebase:Expansion', async function () { - const MINT_AMT = toFixedPtAmt('1') - const MAX_PRICE = ethers.BigNumber.from(2).pow(96).sub(1) - const MAX_SUPPLY = '792281625142643375935439503363406031780' - let r: any + const MINT_AMT = toFixedPtAmt('1'); + const MAX_PRICE = ethers.BigNumber.from(2).pow(96).sub(1); + const MAX_SUPPLY = '792281625142643375935439503363406031780'; + let r: any; describe('when price is less than MAX_PRICE and expands beyond', function () { beforeEach('setup ButtonToken contract', async function () { - await setupContracts() + await setupContracts(); - await mockBTC.connect(deployer).mint(deployerAddress, MINT_AMT) - await mockBTC.connect(deployer).approve(buttonToken.address, MINT_AMT) - await buttonToken.connect(deployer).deposit(MINT_AMT) + await mockBTC.connect(deployer).mint(deployerAddress, MINT_AMT); + await mockBTC.connect(deployer).approve(buttonToken.address, MINT_AMT); + await buttonToken.connect(deployer).deposit(MINT_AMT); - await mockOracle.setData(MAX_PRICE.sub(1), true) - await buttonToken.rebase() - expect(await buttonToken.lastPrice()).to.eq(MAX_PRICE.sub(1)) + await mockOracle.setData(MAX_PRICE.sub(1), true); + await buttonToken.rebase(); + expect(await buttonToken.lastPrice()).to.eq(MAX_PRICE.sub(1)); - await mockOracle.setData(MAX_PRICE.add(1), true) - r = buttonToken.connect(deployer).rebase() - await r - }) + await mockOracle.setData(MAX_PRICE.add(1), true); + r = buttonToken.connect(deployer).rebase(); + await r; + }); it('should emit Rebase', async function () { - await expect(r).to.emit(buttonToken, 'Rebase').withArgs('4', MAX_PRICE) - }) + await expect(r).to.emit(buttonToken, 'Rebase').withArgs('4', MAX_PRICE); + }); it('should increase the price to MAX_PRICE', async function () { - expect(await buttonToken.lastPrice()).to.eq(MAX_PRICE) - }) + expect(await buttonToken.lastPrice()).to.eq(MAX_PRICE); + }); it('should increase the supply to MAX_SUPPLY', async function () { - eqAprox(await buttonToken.totalSupply(), MAX_SUPPLY) - }) - }) + eqAprox(await buttonToken.totalSupply(), MAX_SUPPLY); + }); + }); describe('when totalSupply is MAX_SUPPLY and expands', function () { beforeEach('setup ButtonToken contract', async function () { - await setupContracts() + await setupContracts(); - await mockBTC.connect(deployer).mint(deployerAddress, MINT_AMT) - await mockBTC.connect(deployer).approve(buttonToken.address, MINT_AMT) - await buttonToken.connect(deployer).deposit(MINT_AMT) + await mockBTC.connect(deployer).mint(deployerAddress, MINT_AMT); + await mockBTC.connect(deployer).approve(buttonToken.address, MINT_AMT); + await buttonToken.connect(deployer).deposit(MINT_AMT); - await mockOracle.setData(MAX_PRICE, true) - await buttonToken.rebase() + await mockOracle.setData(MAX_PRICE, true); + await buttonToken.rebase(); - await mockOracle.setData(MAX_PRICE.add(1), true) - r = buttonToken.connect(deployer).rebase() - await r - }) + await mockOracle.setData(MAX_PRICE.add(1), true); + r = buttonToken.connect(deployer).rebase(); + await r; + }); it('should emit Rebase', async function () { - await expect(r).to.emit(buttonToken, 'Rebase').withArgs('4', MAX_PRICE) - }) + await expect(r).to.emit(buttonToken, 'Rebase').withArgs('4', MAX_PRICE); + }); it('should not change the price', async function () { - expect(await buttonToken.lastPrice()).to.eq(MAX_PRICE) - }) + expect(await buttonToken.lastPrice()).to.eq(MAX_PRICE); + }); it('should not change the totalSupply', async function () { - eqAprox(await buttonToken.totalSupply(), MAX_SUPPLY) - }) - }) -}) + eqAprox(await buttonToken.totalSupply(), MAX_SUPPLY); + }); + }); +}); describe('ButtonToken:Rebase:NoChange', async () => { // Rebase +0%, with starting balances A:750 and B:250. - let r: any + let r: any; before('setup ButtonToken contract', async function () { - await setupContracts() + await setupContracts(); - await mockBTC.connect(deployer).mint(deployerAddress, toFixedPtAmt('1')) + await mockBTC.connect(deployer).mint(deployerAddress, toFixedPtAmt('1')); await mockBTC .connect(deployer) - .approve(buttonToken.address, toFixedPtAmt('1')) + .approve(buttonToken.address, toFixedPtAmt('1')); - await buttonToken.connect(deployer).deposit(toFixedPtAmt('1')) + await buttonToken.connect(deployer).deposit(toFixedPtAmt('1')); await buttonToken .connect(deployer) - .transfer(userAAddress, toFixedPtAmt('7500')) + .transfer(userAAddress, toFixedPtAmt('7500')); await buttonToken .connect(deployer) - .transfer(userBAddress, toFixedPtAmt('2500')) + .transfer(userBAddress, toFixedPtAmt('2500')); - eqAprox(await buttonToken.totalSupply(), toFixedPtAmt('10000')) - eqAprox(await buttonToken.balanceOf(deployerAddress), toFixedPtAmt('0')) - eqAprox(await buttonToken.balanceOf(userAAddress), toFixedPtAmt('7500')) - eqAprox(await buttonToken.balanceOf(userBAddress), toFixedPtAmt('2500')) + eqAprox(await buttonToken.totalSupply(), toFixedPtAmt('10000')); + eqAprox(await buttonToken.balanceOf(deployerAddress), toFixedPtAmt('0')); + eqAprox(await buttonToken.balanceOf(userAAddress), toFixedPtAmt('7500')); + eqAprox(await buttonToken.balanceOf(userBAddress), toFixedPtAmt('2500')); - underlyingSupply = await buttonToken.scaledTotalSupply() - cbA = await buttonToken.scaledBalanceOf(userAAddress) - cbB = await buttonToken.scaledBalanceOf(userBAddress) + underlyingSupply = await buttonToken.scaledTotalSupply(); + cbA = await buttonToken.scaledBalanceOf(userAAddress); + cbB = await buttonToken.scaledBalanceOf(userBAddress); - await mockOracle.setData(toOracleValue('10000'), true) - r = buttonToken.rebase() - await r - }) + await mockOracle.setData(toOracleValue('10000'), true); + r = buttonToken.rebase(); + await r; + }); it('should emit Rebase', async function () { await expect(r) .to.emit(buttonToken, 'Rebase') - .withArgs('5', toOracleValue('10000')) - }) + .withArgs('5', toOracleValue('10000')); + }); it('should not change the totalSupply', async function () { - eqAprox(await buttonToken.totalSupply(), toFixedPtAmt('10000')) - }) + eqAprox(await buttonToken.totalSupply(), toFixedPtAmt('10000')); + }); it('should NOT CHANGE the scaledTotalSupply', async function () { - expect(await buttonToken.scaledTotalSupply()).to.eq(underlyingSupply) - }) + expect(await buttonToken.scaledTotalSupply()).to.eq(underlyingSupply); + }); it('should not change individual balances', async function () { - eqAprox(await buttonToken.balanceOf(userAAddress), toFixedPtAmt('7500')) - eqAprox(await buttonToken.balanceOf(userBAddress), toFixedPtAmt('2500')) - }) + eqAprox(await buttonToken.balanceOf(userAAddress), toFixedPtAmt('7500')); + eqAprox(await buttonToken.balanceOf(userBAddress), toFixedPtAmt('2500')); + }); it('should NOT CHANGE the individual scaled balances', async function () { - expect(await buttonToken.scaledBalanceOf(userAAddress)).to.eq(cbA) - expect(await buttonToken.scaledBalanceOf(userBAddress)).to.eq(cbB) - }) -}) + expect(await buttonToken.scaledBalanceOf(userAAddress)).to.eq(cbA); + expect(await buttonToken.scaledBalanceOf(userBAddress)).to.eq(cbB); + }); +}); describe('ButtonToken:Rebase:Contraction', async () => { // Rebase -10%, with starting balances A:750 and B:250. - let r: any + let r: any; before('setup ButtonToken contract', async function () { - await setupContracts() + await setupContracts(); - await mockBTC.connect(deployer).mint(deployerAddress, toFixedPtAmt('1')) + await mockBTC.connect(deployer).mint(deployerAddress, toFixedPtAmt('1')); await mockBTC .connect(deployer) - .approve(buttonToken.address, toFixedPtAmt('1')) + .approve(buttonToken.address, toFixedPtAmt('1')); - await buttonToken.connect(deployer).deposit(toFixedPtAmt('1')) + await buttonToken.connect(deployer).deposit(toFixedPtAmt('1')); await buttonToken .connect(deployer) - .transfer(userAAddress, toFixedPtAmt('7500')) + .transfer(userAAddress, toFixedPtAmt('7500')); await buttonToken .connect(deployer) - .transfer(userBAddress, toFixedPtAmt('2500')) + .transfer(userBAddress, toFixedPtAmt('2500')); - eqAprox(await buttonToken.totalSupply(), toFixedPtAmt('10000')) - eqAprox(await buttonToken.balanceOf(deployerAddress), toFixedPtAmt('0')) - eqAprox(await buttonToken.balanceOf(userAAddress), toFixedPtAmt('7500')) - eqAprox(await buttonToken.balanceOf(userBAddress), toFixedPtAmt('2500')) + eqAprox(await buttonToken.totalSupply(), toFixedPtAmt('10000')); + eqAprox(await buttonToken.balanceOf(deployerAddress), toFixedPtAmt('0')); + eqAprox(await buttonToken.balanceOf(userAAddress), toFixedPtAmt('7500')); + eqAprox(await buttonToken.balanceOf(userBAddress), toFixedPtAmt('2500')); - underlyingSupply = await buttonToken.scaledTotalSupply() - cbA = await buttonToken.scaledBalanceOf(userAAddress) - cbB = await buttonToken.scaledBalanceOf(userBAddress) + underlyingSupply = await buttonToken.scaledTotalSupply(); + cbA = await buttonToken.scaledBalanceOf(userAAddress); + cbB = await buttonToken.scaledBalanceOf(userBAddress); - await mockOracle.setData(toOracleValue('9000'), true) - r = buttonToken.rebase() - await r - }) + await mockOracle.setData(toOracleValue('9000'), true); + r = buttonToken.rebase(); + await r; + }); it('should emit Rebase', async function () { await expect(r) .to.emit(buttonToken, 'Rebase') - .withArgs('5', toOracleValue('9000')) - }) + .withArgs('5', toOracleValue('9000')); + }); it('should decrease the totalSupply', async function () { - eqAprox(await buttonToken.totalSupply(), toFixedPtAmt('9000')) - }) + eqAprox(await buttonToken.totalSupply(), toFixedPtAmt('9000')); + }); it('should NOT CHANGE the scaledTotalSupply', async function () { - expect(await buttonToken.scaledTotalSupply()).to.eq(underlyingSupply) - }) + expect(await buttonToken.scaledTotalSupply()).to.eq(underlyingSupply); + }); it('should decrease individual balances', async function () { - eqAprox(await buttonToken.balanceOf(userAAddress), toFixedPtAmt('6750')) - eqAprox(await buttonToken.balanceOf(userBAddress), toFixedPtAmt('2250')) - }) + eqAprox(await buttonToken.balanceOf(userAAddress), toFixedPtAmt('6750')); + eqAprox(await buttonToken.balanceOf(userBAddress), toFixedPtAmt('2250')); + }); it('should NOT CHANGE the individual scaled balances', async function () { - expect(await buttonToken.scaledBalanceOf(userAAddress)).to.eq(cbA) - expect(await buttonToken.scaledBalanceOf(userBAddress)).to.eq(cbB) - }) -}) + expect(await buttonToken.scaledBalanceOf(userAAddress)).to.eq(cbA); + expect(await buttonToken.scaledBalanceOf(userBAddress)).to.eq(cbB); + }); +}); describe('ButtonToken:Transfer', function () { before('setup ButtonToken contract', async () => { - await setupContracts() + await setupContracts(); - await mockBTC.connect(deployer).mint(deployerAddress, toFixedPtAmt('1')) + await mockBTC.connect(deployer).mint(deployerAddress, toFixedPtAmt('1')); await mockBTC .connect(deployer) - .approve(buttonToken.address, toFixedPtAmt('1')) - await buttonToken.connect(deployer).deposit(toFixedPtAmt('1')) - }) + .approve(buttonToken.address, toFixedPtAmt('1')); + await buttonToken.connect(deployer).deposit(toFixedPtAmt('1')); + }); describe('deployer transfers 12 to A', function () { it('should have correct balances', async function () { - const deployerBefore = await buttonToken.balanceOf(deployerAddress) + const deployerBefore = await buttonToken.balanceOf(deployerAddress); await buttonToken .connect(deployer) - .transfer(userAAddress, toFixedPtAmt('12')) + .transfer(userAAddress, toFixedPtAmt('12')); eqAprox( await buttonToken.balanceOf(deployerAddress), deployerBefore.sub(toFixedPtAmt('12')), - ) - eqAprox(await buttonToken.balanceOf(userAAddress), toFixedPtAmt('12')) - }) - }) + ); + eqAprox(await buttonToken.balanceOf(userAAddress), toFixedPtAmt('12')); + }); + }); describe('deployer transfers 15 to B', async function () { it('should have balances [973,15]', async function () { - const deployerBefore = await buttonToken.balanceOf(deployerAddress) + const deployerBefore = await buttonToken.balanceOf(deployerAddress); await buttonToken .connect(deployer) - .transfer(userBAddress, toFixedPtAmt('15')) + .transfer(userBAddress, toFixedPtAmt('15')); eqAprox( await buttonToken.balanceOf(deployerAddress), deployerBefore.sub(toFixedPtAmt('15')), - ) - eqAprox(await buttonToken.balanceOf(userBAddress), toFixedPtAmt('15')) - }) - }) + ); + eqAprox(await buttonToken.balanceOf(userBAddress), toFixedPtAmt('15')); + }); + }); describe('deployer transfers the rest to C', async function () { it('should have balances [0,973]', async function () { - const deployerBefore = await buttonToken.balanceOf(deployerAddress) + const deployerBefore = await buttonToken.balanceOf(deployerAddress); await buttonToken .connect(deployer) - .transfer(await userCAddress, deployerBefore) - eqAprox(await buttonToken.balanceOf(deployerAddress), '0') + .transfer(await userCAddress, deployerBefore); + eqAprox(await buttonToken.balanceOf(deployerAddress), '0'); expect(await buttonToken.balanceOf(await userCAddress)).to.eq( deployerBefore, - ) - }) - }) + ); + }); + }); describe('when the recipient address is the contract address', function () { it('reverts on transfer', async function () { @@ -484,17 +484,17 @@ describe('ButtonToken:Transfer', function () { buttonToken .connect(userA) .transfer(buttonToken.address, unitTokenAmount), - ).to.be.reverted - }) + ).to.be.reverted; + }); it('reverts on transferFrom', async function () { await expect( buttonToken .connect(userA) .transferFrom(userAAddress, buttonToken.address, unitTokenAmount), - ).to.be.reverted - }) - }) + ).to.be.reverted; + }); + }); describe('when the recipient is the zero address', function () { it('emits an approval event', async function () { @@ -504,8 +504,8 @@ describe('ButtonToken:Transfer', function () { .approve(ethers.constants.AddressZero, transferAmount), ) .to.emit(buttonToken, 'Approval') - .withArgs(userAAddress, ethers.constants.AddressZero, transferAmount) - }) + .withArgs(userAAddress, ethers.constants.AddressZero, transferAmount); + }); it('transferFrom should fail', async function () { await expect( @@ -516,7 +516,7 @@ describe('ButtonToken:Transfer', function () { ethers.constants.AddressZero, unitTokenAmount, ), - ).to.be.reverted - }) - }) -}) + ).to.be.reverted; + }); + }); +}); diff --git a/test/unit/ButtonTokenFactory.ts b/test/unit/ButtonTokenFactory.ts index d438ccb..860adbd 100644 --- a/test/unit/ButtonTokenFactory.ts +++ b/test/unit/ButtonTokenFactory.ts @@ -1,14 +1,14 @@ -import { ethers } from 'hardhat' -import { Contract, Signer, BigNumber, BigNumberish } from 'ethers' -import { expect } from 'chai' +import { ethers } from 'hardhat'; +import { Contract, Signer, BigNumber, BigNumberish } from 'ethers'; +import { expect } from 'chai'; -const PRICE_DECIMALS = 8 -const DECIMALS = 18 -const NAME = 'Bitcoin' -const SYMBOL = 'BTC' +const PRICE_DECIMALS = 8; +const DECIMALS = 18; +const NAME = 'Bitcoin'; +const SYMBOL = 'BTC'; const toOracleValue = (v: string): BigNumber => - ethers.utils.parseUnits(v, PRICE_DECIMALS) + ethers.utils.parseUnits(v, PRICE_DECIMALS); let accounts: Signer[], deployer: Signer, @@ -22,7 +22,7 @@ let accounts: Signer[], mockBTC: Contract, mockOracle: Contract, template: Contract, - factory: Contract + factory: Contract; async function createInstance( factory: Contract, @@ -34,69 +34,69 @@ async function createInstance( const args = ethers.utils.defaultAbiCoder.encode( ['address', 'string', 'string', 'address'], [underlying, name, symbol, oracle], - ) - const instanceAddress = await factory.callStatic['create(bytes)'](args) - await factory['create(bytes)'](args) + ); + const instanceAddress = await factory.callStatic['create(bytes)'](args); + await factory['create(bytes)'](args); const instance = (await ethers.getContractFactory('ButtonToken')) .connect(deployer) - .attach(instanceAddress) - return instance + .attach(instanceAddress); + return instance; } async function setupContracts() { - accounts = await ethers.getSigners() - deployer = accounts[0] - userA = accounts[1] - userB = accounts[2] - userC = accounts[3] - - deployerAddress = await deployer.getAddress() - userAAddress = await userA.getAddress() - userBAddress = await userB.getAddress() - userCAddress = await userC.getAddress() - - const erc20Factory = await ethers.getContractFactory('MockERC20') + accounts = await ethers.getSigners(); + deployer = accounts[0]; + userA = accounts[1]; + userB = accounts[2]; + userC = accounts[3]; + + deployerAddress = await deployer.getAddress(); + userAAddress = await userA.getAddress(); + userBAddress = await userB.getAddress(); + userCAddress = await userC.getAddress(); + + const erc20Factory = await ethers.getContractFactory('MockERC20'); mockBTC = await erc20Factory .connect(deployer) - .deploy('Wood Bitcoin', 'WOOD-BTC') - await mockBTC.mint(deployerAddress, '10000000000000000000') + .deploy('Wood Bitcoin', 'WOOD-BTC'); + await mockBTC.mint(deployerAddress, '10000000000000000000'); - const oracleFactory = await ethers.getContractFactory('MockOracle') - mockOracle = await oracleFactory.connect(deployer).deploy() - await mockOracle.setData(toOracleValue('10000'), true) + const oracleFactory = await ethers.getContractFactory('MockOracle'); + mockOracle = await oracleFactory.connect(deployer).deploy(); + await mockOracle.setData(toOracleValue('10000'), true); const buttonTokenContractFactory = await ethers.getContractFactory( 'ButtonToken', - ) - template = await buttonTokenContractFactory.connect(deployer).deploy() + ); + template = await buttonTokenContractFactory.connect(deployer).deploy(); factory = await (await ethers.getContractFactory('ButtonTokenFactory')) .connect(deployer) - .deploy(template.address) + .deploy(template.address); } describe('ButtonTokenFactory', () => { - before('setup ButtonTokenFactory contract', setupContracts) + before('setup ButtonTokenFactory contract', setupContracts); it('should reject any ether sent to it', async function () { - const user = accounts[1] + const user = accounts[1]; await expect(user.sendTransaction({ to: factory.address, value: 1 })).to.be - .reverted - }) -}) + .reverted; + }); +}); describe('ButtonToken:Initialization', () => { - beforeEach('setup ButtonTokenFactory contract', setupContracts) + beforeEach('setup ButtonTokenFactory contract', setupContracts); it('should set the correct template reference', async function () { - expect(await factory.template()).to.eq(template.address) - expect(await factory.instanceCount()).to.eq(0) - }) -}) + expect(await factory.template()).to.eq(template.address); + expect(await factory.instanceCount()).to.eq(0); + }); +}); describe('ButtonToken:create', () => { - beforeEach('setup ButtonTokenFactory contract', setupContracts) + beforeEach('setup ButtonTokenFactory contract', setupContracts); it('Clone should set msg.sender as owner', async function () { const bToken = await createInstance( @@ -105,10 +105,10 @@ describe('ButtonToken:create', () => { 'BUTTON-Bitcoin', 'BUTTON-BTC', mockOracle.address, - ) + ); - expect(await bToken.owner()).to.eq(deployerAddress) - }) + expect(await bToken.owner()).to.eq(deployerAddress); + }); it('Clone should have proper parameters set', async function () { const bToken = await createInstance( @@ -117,31 +117,31 @@ describe('ButtonToken:create', () => { 'BUTTON-Bitcoin', 'BUTTON-BTC', mockOracle.address, - ) + ); - expect(await bToken.underlying()).to.eq(mockBTC.address) - expect(await bToken.name()).to.eq('BUTTON-Bitcoin') - expect(await bToken.symbol()).to.eq('BUTTON-BTC') - expect(await bToken.totalSupply()).to.eq('0') - expect(await bToken.totalUnderlying()).to.eq('0') - }) + expect(await bToken.underlying()).to.eq(mockBTC.address); + expect(await bToken.name()).to.eq('BUTTON-Bitcoin'); + expect(await bToken.symbol()).to.eq('BUTTON-BTC'); + expect(await bToken.totalSupply()).to.eq('0'); + expect(await bToken.totalUnderlying()).to.eq('0'); + }); it('Unpacked args should run with correct values', async function () { const instanceAddress = await factory.callStatic[ 'create(address,string,string,address)' - ](mockBTC.address, 'BUTTON-Bitcoin', 'BUTTON-BTC', mockOracle.address) + ](mockBTC.address, 'BUTTON-Bitcoin', 'BUTTON-BTC', mockOracle.address); await factory['create(address,string,string,address)']( mockBTC.address, 'BUTTON-Bitcoin', 'BUTTON-BTC', mockOracle.address, - ) + ); const bToken = (await ethers.getContractFactory('ButtonToken')) .connect(deployer) - .attach(instanceAddress) - expect(await bToken.underlying()).to.eq(mockBTC.address) - }) + .attach(instanceAddress); + expect(await bToken.underlying()).to.eq(mockBTC.address); + }); it('Instance should register into instanceSet', async function () { const bToken = await createInstance( @@ -150,12 +150,12 @@ describe('ButtonToken:create', () => { 'BUTTON-Bitcoin', 'BUTTON-BTC', mockOracle.address, - ) + ); - expect(await factory.instanceCount()).to.eq(1) - expect(await factory.instanceAt(0)).to.eq(bToken.address) - expect(await factory.isInstance(bToken.address)).to.eq(true) - }) + expect(await factory.instanceCount()).to.eq(1); + expect(await factory.instanceAt(0)).to.eq(bToken.address); + expect(await factory.isInstance(bToken.address)).to.eq(true); + }); it('deposits should have the correct conversion', async function () { const bToken = await createInstance( @@ -164,26 +164,26 @@ describe('ButtonToken:create', () => { 'BUTTON-Bitcoin', 'BUTTON-BTC', mockOracle.address, - ) + ); expect(await mockBTC.balanceOf(deployerAddress)).to.eq( '10000000000000000000', - ) + ); - const depositAmt = '5000000000000000000' // 5 mockBTC - await mockBTC.connect(deployer).approve(bToken.address, depositAmt) - await bToken.connect(deployer).deposit(depositAmt) + const depositAmt = '5000000000000000000'; // 5 mockBTC + await mockBTC.connect(deployer).approve(bToken.address, depositAmt); + await bToken.connect(deployer).deposit(depositAmt); // 10000 * depositAmt expect(await bToken.balanceOf(deployerAddress)).to.eq( '50000000000000000000000', - ) + ); - await mockOracle.setData(toOracleValue('50000'), true) + await mockOracle.setData(toOracleValue('50000'), true); // 50000 * depositAmt expect(await bToken.balanceOf(deployerAddress)).to.eq( '250000000000000000000000', - ) - }) -}) + ); + }); +}); diff --git a/test/unit/ButtonTokenWamplRouter.ts b/test/unit/ButtonTokenWamplRouter.ts index b3db673..adb73d6 100644 --- a/test/unit/ButtonTokenWamplRouter.ts +++ b/test/unit/ButtonTokenWamplRouter.ts @@ -1,59 +1,59 @@ -import { ethers, waffle } from 'hardhat' -import { Contract, Signer, BigNumber } from 'ethers' -import { expect } from 'chai' -const { loadFixture } = waffle +import { ethers, waffle } from 'hardhat'; +import { Contract, Signer, BigNumber } from 'ethers'; +import { expect } from 'chai'; +const { loadFixture } = waffle; -const PRICE_DECIMALS = 8 -const NAME = 'Button WAMPL' -const SYMBOL = 'BTN-WAMPL' +const PRICE_DECIMALS = 8; +const NAME = 'Button WAMPL'; +const SYMBOL = 'BTN-WAMPL'; -const startingMultiplier = 10000 -const multiplierGranularity = 10000 -const AMPL_TOTAL_SUPPLY = '50000000000000000' // 50m AMPL +const startingMultiplier = 10000; +const multiplierGranularity = 10000; +const AMPL_TOTAL_SUPPLY = '50000000000000000'; // 50m AMPL interface TestContext { - accounts: Signer[] - buttonToken: Contract - mockOracle: Contract - ampl: Contract - wampl: Contract - router: Contract + accounts: Signer[]; + buttonToken: Contract; + mockOracle: Contract; + ampl: Contract; + wampl: Contract; + router: Contract; } const toOracleValue = (v: string): BigNumber => - ethers.utils.parseUnits(v, PRICE_DECIMALS) + ethers.utils.parseUnits(v, PRICE_DECIMALS); async function fixture(): Promise { - const accounts = await ethers.getSigners() - const deployer = accounts[0] - const deployerAddress = await deployer.getAddress() + const accounts = await ethers.getSigners(); + const deployer = accounts[0]; + const deployerAddress = await deployer.getAddress(); const rebasingErc20ContractFactory = await ethers.getContractFactory( 'MockRebasingERC20', - ) + ); const ampl = await rebasingErc20ContractFactory .connect(deployer) - .deploy('Ampleforth', 'AMPL', startingMultiplier, multiplierGranularity) - await ampl.mint(deployerAddress, AMPL_TOTAL_SUPPLY) + .deploy('Ampleforth', 'AMPL', startingMultiplier, multiplierGranularity); + await ampl.mint(deployerAddress, AMPL_TOTAL_SUPPLY); - const wamplContractFactory = await ethers.getContractFactory('WAMPL') + const wamplContractFactory = await ethers.getContractFactory('WAMPL'); const wampl = await wamplContractFactory .connect(deployer) - .deploy(ampl.address) + .deploy(ampl.address); - const oracleFactory = await ethers.getContractFactory('MockOracle') - const mockOracle = await oracleFactory.deploy() - await mockOracle.setData(toOracleValue('10000'), true) + const oracleFactory = await ethers.getContractFactory('MockOracle'); + const mockOracle = await oracleFactory.deploy(); + await mockOracle.setData(toOracleValue('10000'), true); - const buttonTokenFactory = await ethers.getContractFactory('ButtonToken') - const buttonToken = await buttonTokenFactory.deploy() + const buttonTokenFactory = await ethers.getContractFactory('ButtonToken'); + const buttonToken = await buttonTokenFactory.deploy(); - buttonToken.initialize(wampl.address, NAME, SYMBOL, mockOracle.address) + buttonToken.initialize(wampl.address, NAME, SYMBOL, mockOracle.address); const routerFactory = await ethers.getContractFactory( 'ButtonTokenWamplRouter', - ) - const router = await routerFactory.deploy(wampl.address) + ); + const router = await routerFactory.deploy(wampl.address); return { accounts, @@ -62,26 +62,26 @@ async function fixture(): Promise { ampl, wampl, router, - } + }; } describe('ButtonTokenWamplRouter', () => { it('should instantiate router', async function () { - const { router } = await loadFixture(fixture) + const { router } = await loadFixture(fixture); - expect(router.address).to.exist - }) + expect(router.address).to.exist; + }); it('should deposit AMPL', async function () { const { router, ampl, wampl, accounts, buttonToken } = await loadFixture( fixture, - ) - const [user] = accounts - const userAddress = await user.getAddress() + ); + const [user] = accounts; + const userAddress = await user.getAddress(); - const depositAmount = ethers.utils.parseUnits('5', 9) - const wamplAmount = depositAmount.mul(BigNumber.from(10).pow(9)).div(5) - await ampl.connect(user).approve(router.address, depositAmount) + const depositAmount = ethers.utils.parseUnits('5', 9); + const wamplAmount = depositAmount.mul(BigNumber.from(10).pow(9)).div(5); + await ampl.connect(user).approve(router.address, depositAmount); await expect(router.wamplWrapAndDeposit(buttonToken.address, depositAmount)) // 1. Transfer AMPL to router @@ -108,74 +108,74 @@ describe('ButtonTokenWamplRouter', () => { ethers.constants.AddressZero, userAddress, wamplAmount.mul('10000'), - ) + ); expect(await buttonToken.balanceOf(await user.getAddress())).to.equal( wamplAmount.mul('10000'), - ) + ); - expect(await wampl.balanceOf(router.address)).to.equal('0') - expect(await buttonToken.balanceOf(router.address)).to.equal('0') - expect(await user.provider!.getBalance(router.address)).to.equal('0') - }) + expect(await wampl.balanceOf(router.address)).to.equal('0'); + expect(await buttonToken.balanceOf(router.address)).to.equal('0'); + expect(await user.provider!.getBalance(router.address)).to.equal('0'); + }); it('should fail to deposit if no ampl given', async function () { - const { router, ampl, accounts, buttonToken } = await loadFixture(fixture) - const [user] = accounts + const { router, ampl, accounts, buttonToken } = await loadFixture(fixture); + const [user] = accounts; - const depositAmount = ethers.utils.parseUnits('0', 9) + const depositAmount = ethers.utils.parseUnits('0', 9); await expect( router.wamplWrapAndDeposit(buttonToken.address, depositAmount), - ).to.be.revertedWith('ZeroAmount') + ).to.be.revertedWith('ZeroAmount'); - expect(await ampl.balanceOf(router.address)).to.equal('0') - expect(await buttonToken.balanceOf(router.address)).to.equal('0') - expect(await user.provider!.getBalance(router.address)).to.equal('0') - }) + expect(await ampl.balanceOf(router.address)).to.equal('0'); + expect(await buttonToken.balanceOf(router.address)).to.equal('0'); + expect(await user.provider!.getBalance(router.address)).to.equal('0'); + }); it('should fail to deposit if no buttonToken underlying is not wampl', async function () { - const { router, ampl, accounts, mockOracle } = await loadFixture(fixture) - const [user] = accounts + const { router, ampl, accounts, mockOracle } = await loadFixture(fixture); + const [user] = accounts; - const buttonTokenFactory = await ethers.getContractFactory('ButtonToken') - const invalidButtonToken = await buttonTokenFactory.deploy() + const buttonTokenFactory = await ethers.getContractFactory('ButtonToken'); + const invalidButtonToken = await buttonTokenFactory.deploy(); invalidButtonToken.initialize( ampl.address, 'BAD-BUTTON', 'BTTN-BAD', mockOracle.address, - ) + ); - const depositAmount = ethers.utils.parseUnits('10', 9) + const depositAmount = ethers.utils.parseUnits('10', 9); await expect( router.wamplWrapAndDeposit(invalidButtonToken.address, depositAmount), - ).to.be.revertedWith('InvalidButtonAsset') + ).to.be.revertedWith('InvalidButtonAsset'); - expect(await ampl.balanceOf(router.address)).to.equal('0') - expect(await invalidButtonToken.balanceOf(router.address)).to.equal('0') - expect(await user.provider!.getBalance(router.address)).to.equal('0') - }) + expect(await ampl.balanceOf(router.address)).to.equal('0'); + expect(await invalidButtonToken.balanceOf(router.address)).to.equal('0'); + expect(await user.provider!.getBalance(router.address)).to.equal('0'); + }); it('should burn button tokens', async function () { const { router, accounts, ampl, wampl, buttonToken } = await loadFixture( fixture, - ) - const [user] = accounts - const userAddress = await user.getAddress() + ); + const [user] = accounts; + const userAddress = await user.getAddress(); - const depositAmount = ethers.utils.parseUnits('5', 9) - await ampl.connect(user).approve(router.address, depositAmount) - await router.wamplWrapAndDeposit(buttonToken.address, depositAmount) + const depositAmount = ethers.utils.parseUnits('5', 9); + await ampl.connect(user).approve(router.address, depositAmount); + await router.wamplWrapAndDeposit(buttonToken.address, depositAmount); - const userStartingBalance = await ampl.balanceOf(userAddress) + const userStartingBalance = await ampl.balanceOf(userAddress); await buttonToken.approve( router.address, ethers.utils.parseUnits('5000', 18), - ) + ); - const burnAmount = ethers.utils.parseUnits('5000', 18) - const wamplAmount = burnAmount.div('10000').sub('1') - const amplAmount = wamplAmount.mul(5).div(BigNumber.from(10).pow(9)) + const burnAmount = ethers.utils.parseUnits('5000', 18); + const wamplAmount = burnAmount.div('10000').sub('1'); + const amplAmount = wamplAmount.mul(5).div(BigNumber.from(10).pow(9)); await expect(router.wamplBurnAndUnwrap(buttonToken.address, burnAmount)) // 1. Transfer buttonTokens from user to router .to.emit(buttonToken, 'Transfer') @@ -190,38 +190,38 @@ describe('ButtonTokenWamplRouter', () => { .withArgs(router.address, ethers.constants.AddressZero, wamplAmount) // 4. Burnt wampl sends ampl directly to user .to.emit(ampl, 'Transfer') - .withArgs(wampl.address, userAddress, amplAmount) + .withArgs(wampl.address, userAddress, amplAmount); - const userEndingBalance = await ampl.balanceOf(userAddress) + const userEndingBalance = await ampl.balanceOf(userAddress); // make sure user balance increased by output amount minus some threshold for gas expect( userEndingBalance .sub(userStartingBalance) .gt(ethers.utils.parseUnits('0.24', 9)), - ).to.be.true + ).to.be.true; - expect(await wampl.balanceOf(router.address)).to.equal('0') - expect(await buttonToken.balanceOf(router.address)).to.equal('0') - expect(await ampl.balanceOf(router.address)).to.equal('0') - }) + expect(await wampl.balanceOf(router.address)).to.equal('0'); + expect(await buttonToken.balanceOf(router.address)).to.equal('0'); + expect(await ampl.balanceOf(router.address)).to.equal('0'); + }); it('should burn all button tokens', async function () { const { router, accounts, ampl, wampl, buttonToken } = await loadFixture( fixture, - ) - const [user] = accounts - const userAddress = await user.getAddress() + ); + const [user] = accounts; + const userAddress = await user.getAddress(); - const depositAmount = ethers.utils.parseUnits('5', 9) - await ampl.connect(user).approve(router.address, depositAmount) - await router.wamplWrapAndDeposit(buttonToken.address, depositAmount) + const depositAmount = ethers.utils.parseUnits('5', 9); + await ampl.connect(user).approve(router.address, depositAmount); + await router.wamplWrapAndDeposit(buttonToken.address, depositAmount); - const userStartingBalance = await ampl.balanceOf(userAddress) - await buttonToken.approve(router.address, ethers.constants.MaxUint256) - const userButtonTokenBalance = await buttonToken.balanceOf(userAddress) - const wamplAmount = userButtonTokenBalance.div('10000') - const amplAmount = wamplAmount.mul(5).div(BigNumber.from(10).pow(9)) + const userStartingBalance = await ampl.balanceOf(userAddress); + await buttonToken.approve(router.address, ethers.constants.MaxUint256); + const userButtonTokenBalance = await buttonToken.balanceOf(userAddress); + const wamplAmount = userButtonTokenBalance.div('10000'); + const amplAmount = wamplAmount.mul(5).div(BigNumber.from(10).pow(9)); await expect(router.wamplBurnAndUnwrapAll(buttonToken.address)) // 1. Transfer buttonTokens from user to router @@ -241,54 +241,54 @@ describe('ButtonTokenWamplRouter', () => { .withArgs(router.address, ethers.constants.AddressZero, wamplAmount) // 4. Burnt wampl sends ampl directly to user .to.emit(ampl, 'Transfer') - .withArgs(wampl.address, userAddress, amplAmount) + .withArgs(wampl.address, userAddress, amplAmount); - const userEndingBalance = await ampl.balanceOf(userAddress) + const userEndingBalance = await ampl.balanceOf(userAddress); // make sure user balance increased by output amount minus some threshold for gas expect( userEndingBalance .sub(userStartingBalance) .gt(ethers.utils.parseUnits('4.99', 9)), - ).to.be.true + ).to.be.true; - expect(await wampl.balanceOf(router.address)).to.equal('0') - expect(await buttonToken.balanceOf(router.address)).to.equal('0') - expect(await ampl.balanceOf(router.address)).to.equal('0') - }) + expect(await wampl.balanceOf(router.address)).to.equal('0'); + expect(await buttonToken.balanceOf(router.address)).to.equal('0'); + expect(await ampl.balanceOf(router.address)).to.equal('0'); + }); // it('should fail to burn all if not approved', async function () { const { router, ampl, wampl, accounts, buttonToken } = await loadFixture( fixture, - ) - const [user] = accounts + ); + const [user] = accounts; - const depositAmount = ethers.utils.parseUnits('5', 9) - await ampl.connect(user).approve(router.address, depositAmount) - await router.wamplWrapAndDeposit(buttonToken.address, depositAmount) + const depositAmount = ethers.utils.parseUnits('5', 9); + await ampl.connect(user).approve(router.address, depositAmount); + await router.wamplWrapAndDeposit(buttonToken.address, depositAmount); await expect(router.wamplBurnAndUnwrapAll(buttonToken.address)).to.be - .reverted + .reverted; - expect(await wampl.balanceOf(router.address)).to.equal('0') - expect(await buttonToken.balanceOf(router.address)).to.equal('0') - expect(await ampl.balanceOf(router.address)).to.equal('0') - }) + expect(await wampl.balanceOf(router.address)).to.equal('0'); + expect(await buttonToken.balanceOf(router.address)).to.equal('0'); + expect(await ampl.balanceOf(router.address)).to.equal('0'); + }); it('should fail to burn if not approved', async function () { const { router, ampl, wampl, accounts, buttonToken } = await loadFixture( fixture, - ) - const [user] = accounts + ); + const [user] = accounts; - const depositAmount = ethers.utils.parseUnits('5', 9) - await ampl.connect(user).approve(router.address, depositAmount) - await router.wamplWrapAndDeposit(buttonToken.address, depositAmount) + const depositAmount = ethers.utils.parseUnits('5', 9); + await ampl.connect(user).approve(router.address, depositAmount); + await router.wamplWrapAndDeposit(buttonToken.address, depositAmount); await expect(router.wamplBurnAndUnwrap(buttonToken.address, depositAmount)) - .to.be.reverted + .to.be.reverted; - expect(await wampl.balanceOf(router.address)).to.equal('0') - expect(await buttonToken.balanceOf(router.address)).to.equal('0') - expect(await ampl.balanceOf(router.address)).to.equal('0') - }) -}) + expect(await wampl.balanceOf(router.address)).to.equal('0'); + expect(await buttonToken.balanceOf(router.address)).to.equal('0'); + expect(await ampl.balanceOf(router.address)).to.equal('0'); + }); +}); diff --git a/test/unit/ButtonTokenWethRouter.ts b/test/unit/ButtonTokenWethRouter.ts index 7f86162..088279e 100644 --- a/test/unit/ButtonTokenWethRouter.ts +++ b/test/unit/ButtonTokenWethRouter.ts @@ -1,40 +1,42 @@ -import { ethers, waffle } from 'hardhat' -import { Contract, Signer, BigNumber } from 'ethers' -import { expect } from 'chai' -const { loadFixture } = waffle +import { ethers, waffle } from 'hardhat'; +import { Contract, Signer, BigNumber } from 'ethers'; +import { expect } from 'chai'; +const { loadFixture } = waffle; -const PRICE_DECIMALS = 8 -const NAME = 'Button Bitcoin' -const SYMBOL = 'BTN-BTC' +const PRICE_DECIMALS = 8; +const NAME = 'Button Bitcoin'; +const SYMBOL = 'BTN-BTC'; interface TestContext { - accounts: Signer[] - buttonToken: Contract - mockOracle: Contract - weth: Contract - router: Contract + accounts: Signer[]; + buttonToken: Contract; + mockOracle: Contract; + weth: Contract; + router: Contract; } const toOracleValue = (v: string): BigNumber => - ethers.utils.parseUnits(v, PRICE_DECIMALS) + ethers.utils.parseUnits(v, PRICE_DECIMALS); async function fixture(): Promise { - const accounts = await ethers.getSigners() + const accounts = await ethers.getSigners(); - const wethFactory = await ethers.getContractFactory('WETH9') - const weth = await wethFactory.deploy() + const wethFactory = await ethers.getContractFactory('WETH9'); + const weth = await wethFactory.deploy(); - const oracleFactory = await ethers.getContractFactory('MockOracle') - const mockOracle = await oracleFactory.deploy() - await mockOracle.setData(toOracleValue('10000'), true) + const oracleFactory = await ethers.getContractFactory('MockOracle'); + const mockOracle = await oracleFactory.deploy(); + await mockOracle.setData(toOracleValue('10000'), true); - const buttonTokenFactory = await ethers.getContractFactory('ButtonToken') - const buttonToken = await buttonTokenFactory.deploy() + const buttonTokenFactory = await ethers.getContractFactory('ButtonToken'); + const buttonToken = await buttonTokenFactory.deploy(); - buttonToken.initialize(weth.address, NAME, SYMBOL, mockOracle.address) + buttonToken.initialize(weth.address, NAME, SYMBOL, mockOracle.address); - const routerFactory = await ethers.getContractFactory('ButtonTokenWethRouter') - const router = await routerFactory.deploy(weth.address) + const routerFactory = await ethers.getContractFactory( + 'ButtonTokenWethRouter', + ); + const router = await routerFactory.deploy(weth.address); return { accounts, @@ -42,21 +44,21 @@ async function fixture(): Promise { mockOracle, weth, router, - } + }; } describe('ButtonTokenWethRouter', () => { it('should instantiate router', async function () { - const { router } = await loadFixture(fixture) + const { router } = await loadFixture(fixture); - expect(router.address).to.exist - }) + expect(router.address).to.exist; + }); it('should deposit ETH', async function () { - const { router, weth, accounts, buttonToken } = await loadFixture(fixture) - const [user] = accounts + const { router, weth, accounts, buttonToken } = await loadFixture(fixture); + const [user] = accounts; - const depositAmount = ethers.utils.parseEther('5') + const depositAmount = ethers.utils.parseEther('5'); await expect(router.deposit(buttonToken.address, { value: depositAmount })) .to.emit(weth, 'Deposit') .withArgs(router.address, depositAmount) @@ -65,132 +67,133 @@ describe('ButtonTokenWethRouter', () => { ethers.constants.AddressZero, await user.getAddress(), depositAmount.mul('10000'), - ) + ); expect(await buttonToken.balanceOf(await user.getAddress())).to.equal( depositAmount.mul('10000'), - ) + ); - expect(await weth.balanceOf(router.address)).to.equal('0') - expect(await buttonToken.balanceOf(router.address)).to.equal('0') - expect(await user.provider!.getBalance(router.address)).to.equal('0') - }) + expect(await weth.balanceOf(router.address)).to.equal('0'); + expect(await buttonToken.balanceOf(router.address)).to.equal('0'); + expect(await user.provider!.getBalance(router.address)).to.equal('0'); + }); it('should fail to deposit if no eth given', async function () { - const { router, weth, accounts, buttonToken } = await loadFixture(fixture) - const [user] = accounts + const { router, weth, accounts, buttonToken } = await loadFixture(fixture); + const [user] = accounts; - const depositAmount = ethers.utils.parseEther('0') + const depositAmount = ethers.utils.parseEther('0'); await expect( router.deposit(buttonToken.address, { value: depositAmount }), - ).to.be.revertedWith('ButtonTokenWethRouter: No ETH supplied') + ).to.be.revertedWith('ButtonTokenWethRouter: No ETH supplied'); - expect(await weth.balanceOf(router.address)).to.equal('0') - expect(await buttonToken.balanceOf(router.address)).to.equal('0') - expect(await user.provider!.getBalance(router.address)).to.equal('0') - }) + expect(await weth.balanceOf(router.address)).to.equal('0'); + expect(await buttonToken.balanceOf(router.address)).to.equal('0'); + expect(await user.provider!.getBalance(router.address)).to.equal('0'); + }); it('should burn button tokens', async function () { - const { router, accounts, weth, buttonToken } = await loadFixture(fixture) - const [user] = accounts + const { router, accounts, weth, buttonToken } = await loadFixture(fixture); + const [user] = accounts; - const depositAmount = ethers.utils.parseEther('5') - await router.deposit(buttonToken.address, { value: depositAmount }) + const depositAmount = ethers.utils.parseEther('5'); + await router.deposit(buttonToken.address, { value: depositAmount }); - const userStartingBalance = await user.getBalance() - await buttonToken.approve(router.address, ethers.utils.parseEther('2500')) + const userStartingBalance = await user.getBalance(); + await buttonToken.approve(router.address, ethers.utils.parseEther('2500')); - const burnAmount = ethers.utils.parseEther('2500') + const burnAmount = ethers.utils.parseEther('2500'); await expect(router.burn(buttonToken.address, burnAmount)) .to.emit(buttonToken, 'Transfer') .withArgs(await user.getAddress(), router.address, burnAmount) .to.emit(buttonToken, 'Transfer') - .withArgs(router.address, ethers.constants.AddressZero, burnAmount) + .withArgs(router.address, ethers.constants.AddressZero, burnAmount); - const userEndingBalance = await user.getBalance() + const userEndingBalance = await user.getBalance(); // make sure user balance increased by output amount minus some threshold for gas expect( userEndingBalance .sub(userStartingBalance) .gt(ethers.utils.parseEther('0.24')), - ).to.be.true + ).to.be.true; - expect(await weth.balanceOf(router.address)).to.equal('0') - expect(await buttonToken.balanceOf(router.address)).to.equal('0') - expect(await user.provider!.getBalance(router.address)).to.equal('0') - }) + expect(await weth.balanceOf(router.address)).to.equal('0'); + expect(await buttonToken.balanceOf(router.address)).to.equal('0'); + expect(await user.provider!.getBalance(router.address)).to.equal('0'); + }); it('should burn all button tokens', async function () { - const { router, accounts, weth, buttonToken } = await loadFixture(fixture) - const [user] = accounts + const { router, accounts, weth, buttonToken } = await loadFixture(fixture); + const [user] = accounts; - const depositAmount = ethers.utils.parseEther('5') - await router.deposit(buttonToken.address, { value: depositAmount }) + const depositAmount = ethers.utils.parseEther('5'); + await router.deposit(buttonToken.address, { value: depositAmount }); const userStartingBalance = await ethers.provider.getBalance( await user.getAddress(), - ) - await buttonToken.approve(router.address, ethers.constants.MaxUint256) - const userBalance = await buttonToken.balanceOf(await user.getAddress()) + ); + await buttonToken.approve(router.address, ethers.constants.MaxUint256); + const userBalance = await buttonToken.balanceOf(await user.getAddress()); await expect(router.burnAll(buttonToken.address)) .to.emit(buttonToken, 'Transfer') .withArgs(await user.getAddress(), router.address, userBalance) .to.emit(buttonToken, 'Transfer') - .withArgs(router.address, ethers.constants.AddressZero, userBalance) + .withArgs(router.address, ethers.constants.AddressZero, userBalance); const userEndingBalance = await ethers.provider.getBalance( await user.getAddress(), - ) + ); // make sure user balance increased by output amount minus some threshold for gas expect( userEndingBalance .sub(userStartingBalance) .gt(ethers.utils.parseEther('4.99')), - ).to.be.true + ).to.be.true; - expect(await weth.balanceOf(router.address)).to.equal('0') - expect(await buttonToken.balanceOf(router.address)).to.equal('0') - expect(await user.provider!.getBalance(router.address)).to.equal('0') - }) + expect(await weth.balanceOf(router.address)).to.equal('0'); + expect(await buttonToken.balanceOf(router.address)).to.equal('0'); + expect(await user.provider!.getBalance(router.address)).to.equal('0'); + }); it('should fail to burn all if not approved', async function () { - const { router, weth, accounts, buttonToken } = await loadFixture(fixture) - const [user] = accounts + const { router, weth, accounts, buttonToken } = await loadFixture(fixture); + const [user] = accounts; - const depositAmount = ethers.utils.parseEther('5') - await router.deposit(buttonToken.address, { value: depositAmount }) + const depositAmount = ethers.utils.parseEther('5'); + await router.deposit(buttonToken.address, { value: depositAmount }); - await expect(router.burnAll(buttonToken.address)).to.be.reverted + await expect(router.burnAll(buttonToken.address)).to.be.reverted; - expect(await weth.balanceOf(router.address)).to.equal('0') - expect(await buttonToken.balanceOf(router.address)).to.equal('0') - expect(await user.provider!.getBalance(router.address)).to.equal('0') - }) + expect(await weth.balanceOf(router.address)).to.equal('0'); + expect(await buttonToken.balanceOf(router.address)).to.equal('0'); + expect(await user.provider!.getBalance(router.address)).to.equal('0'); + }); it('should fail to burn if not approved', async function () { - const { router, weth, accounts, buttonToken } = await loadFixture(fixture) - const [user] = accounts + const { router, weth, accounts, buttonToken } = await loadFixture(fixture); + const [user] = accounts; - const depositAmount = ethers.utils.parseEther('5') - await router.deposit(buttonToken.address, { value: depositAmount }) + const depositAmount = ethers.utils.parseEther('5'); + await router.deposit(buttonToken.address, { value: depositAmount }); - await expect(router.burn(buttonToken.address, depositAmount)).to.be.reverted + await expect(router.burn(buttonToken.address, depositAmount)).to.be + .reverted; - expect(await weth.balanceOf(router.address)).to.equal('0') - expect(await buttonToken.balanceOf(router.address)).to.equal('0') - expect(await user.provider!.getBalance(router.address)).to.equal('0') - }) + expect(await weth.balanceOf(router.address)).to.equal('0'); + expect(await buttonToken.balanceOf(router.address)).to.equal('0'); + expect(await user.provider!.getBalance(router.address)).to.equal('0'); + }); it('should send ETH directly to the router', async function () { - const { router, accounts } = await loadFixture(fixture) - const [user] = accounts + const { router, accounts } = await loadFixture(fixture); + const [user] = accounts; - const depositAmount = ethers.utils.parseEther('5') + const depositAmount = ethers.utils.parseEther('5'); await expect( user.sendTransaction({ to: router.address, value: depositAmount }), - ).to.be.revertedWith('ButtonTokenWethRouter: unexpected receive') + ).to.be.revertedWith('ButtonTokenWethRouter: unexpected receive'); - expect(await user.provider!.getBalance(router.address)).to.equal('0') - }) -}) + expect(await user.provider!.getBalance(router.address)).to.equal('0'); + }); +}); diff --git a/test/unit/ButtonToken_button_wrapper.ts b/test/unit/ButtonToken_button_wrapper.ts index ed5461b..969481b 100644 --- a/test/unit/ButtonToken_button_wrapper.ts +++ b/test/unit/ButtonToken_button_wrapper.ts @@ -1,17 +1,17 @@ -import { ethers, upgrades } from 'hardhat' -import { Contract, Signer, BigNumber } from 'ethers' -import { expect } from 'chai' +import { ethers, upgrades } from 'hardhat'; +import { Contract, Signer, BigNumber } from 'ethers'; +import { expect } from 'chai'; -const PRICE_DECIMALS = 8 -const DECIMALS = 18 -const NAME = 'Button Bitcoin' -const SYMBOL = 'BTN-BTC' +const PRICE_DECIMALS = 8; +const DECIMALS = 18; +const NAME = 'Button Bitcoin'; +const SYMBOL = 'BTN-BTC'; const toOracleValue = (v: string): BigNumber => - ethers.utils.parseUnits(v, PRICE_DECIMALS) + ethers.utils.parseUnits(v, PRICE_DECIMALS); const toFixedPtAmt = (a: string): BigNumber => - ethers.utils.parseUnits(a, DECIMALS) + ethers.utils.parseUnits(a, DECIMALS); let accounts: Signer[], deployer: Signer, @@ -22,217 +22,221 @@ let accounts: Signer[], mockOracle: Contract, buttonToken: Contract, cAmount: BigNumber, - withdrawCAmount: BigNumber + withdrawCAmount: BigNumber; async function setupContracts() { - accounts = await ethers.getSigners() - deployer = accounts[0] - userA = accounts[1] + accounts = await ethers.getSigners(); + deployer = accounts[0]; + userA = accounts[1]; - deployerAddress = await deployer.getAddress() - userAAddress = await userA.getAddress() + deployerAddress = await deployer.getAddress(); + userAAddress = await userA.getAddress(); - const erc20Factory = await ethers.getContractFactory('MockERC20') + const erc20Factory = await ethers.getContractFactory('MockERC20'); mockBTC = await erc20Factory .connect(deployer) - .deploy('Wood Bitcoin', 'WOOD-BTC') + .deploy('Wood Bitcoin', 'WOOD-BTC'); - const oracleFactory = await ethers.getContractFactory('MockOracle') - mockOracle = await oracleFactory.connect(deployer).deploy() - await mockOracle.setData(toOracleValue('10000'), true) + const oracleFactory = await ethers.getContractFactory('MockOracle'); + mockOracle = await oracleFactory.connect(deployer).deploy(); + await mockOracle.setData(toOracleValue('10000'), true); - const buttonTokenFactory = await ethers.getContractFactory('ButtonToken') - buttonToken = await buttonTokenFactory.connect(deployer).deploy() + const buttonTokenFactory = await ethers.getContractFactory('ButtonToken'); + buttonToken = await buttonTokenFactory.connect(deployer).deploy(); - buttonToken.initialize(mockBTC.address, NAME, SYMBOL, mockOracle.address) + buttonToken.initialize(mockBTC.address, NAME, SYMBOL, mockOracle.address); } describe('ButtonToken:underlying', async () => { it('should set the correct value', async function () { - await setupContracts() - expect(await buttonToken.underlying()).to.eq(mockBTC.address) - }) -}) + await setupContracts(); + expect(await buttonToken.underlying()).to.eq(mockBTC.address); + }); +}); describe('ButtonToken:deposit', async () => { describe('without sufficient approval', async function () { it('should revert', async function () { - await setupContracts() + await setupContracts(); - await mockBTC.connect(deployer).mint(userAAddress, toFixedPtAmt('1')) + await mockBTC.connect(deployer).mint(userAAddress, toFixedPtAmt('1')); await mockBTC .connect(userA) - .approve(buttonToken.address, toFixedPtAmt('0.99')) + .approve(buttonToken.address, toFixedPtAmt('0.99')); await expect(buttonToken.connect(userA).deposit(toFixedPtAmt('1'))).to.be - .reverted - }) - }) + .reverted; + }); + }); describe('without sufficient balance', async function () { it('should revert', async function () { - await setupContracts() + await setupContracts(); - await mockBTC.connect(deployer).mint(userAAddress, toFixedPtAmt('2')) + await mockBTC.connect(deployer).mint(userAAddress, toFixedPtAmt('2')); await mockBTC .connect(userA) - .approve(buttonToken.address, toFixedPtAmt('1')) + .approve(buttonToken.address, toFixedPtAmt('1')); await expect(buttonToken.connect(userA).deposit(toFixedPtAmt('2'))).to.be - .reverted - }) - }) + .reverted; + }); + }); describe('When deposit amount is > MAX_UNDERLYING', async function () { it('should not be reverted', async function () { - await setupContracts() + await setupContracts(); - cAmount = (await buttonToken.MAX_UNDERLYING()).add(1) + cAmount = (await buttonToken.MAX_UNDERLYING()).add(1); const mintAmt = cAmount .mul(await buttonToken.lastPrice()) - .div(BigNumber.from(10).pow(PRICE_DECIMALS)) + .div(BigNumber.from(10).pow(PRICE_DECIMALS)); - await mockBTC.connect(deployer).mint(userAAddress, cAmount) + await mockBTC.connect(deployer).mint(userAAddress, cAmount); - await mockBTC.connect(userA).approve(buttonToken.address, cAmount) + await mockBTC.connect(userA).approve(buttonToken.address, cAmount); - await expect(buttonToken.connect(userA).deposit(mintAmt)).to.be.reverted - }) - }) + await expect(buttonToken.connect(userA).deposit(mintAmt)).to.be.reverted; + }); + }); describe('When deposit amount < MAX_UNDERLYING', async function () { it('should not be reverted', async function () { - await setupContracts() + await setupContracts(); - const MAX_UNDERLYING = await buttonToken.MAX_UNDERLYING() - const cAmount = MAX_UNDERLYING.sub(1) + const MAX_UNDERLYING = await buttonToken.MAX_UNDERLYING(); + const cAmount = MAX_UNDERLYING.sub(1); - await mockBTC.connect(deployer).mint(userAAddress, cAmount) + await mockBTC.connect(deployer).mint(userAAddress, cAmount); - await mockBTC.connect(userA).approve(buttonToken.address, cAmount) + await mockBTC.connect(userA).approve(buttonToken.address, cAmount); await expect(buttonToken.connect(userA).deposit(cAmount)).not.to.be - .reverted - }) - }) + .reverted; + }); + }); describe('When deposit amount zero', async function () { it('should be reverted', async function () { - await setupContracts() + await setupContracts(); - cAmount = BigNumber.from('1') + cAmount = BigNumber.from('1'); - await mockBTC.connect(deployer).mint(userAAddress, cAmount) - await mockBTC.connect(userA).approve(buttonToken.address, cAmount) + await mockBTC.connect(deployer).mint(userAAddress, cAmount); + await mockBTC.connect(userA).approve(buttonToken.address, cAmount); - await expect(buttonToken.connect(userA).deposit('0')).to.be.reverted - }) - }) + await expect(buttonToken.connect(userA).deposit('0')).to.be.reverted; + }); + }); describe('When deposit < unit amount', async function () { it('should be reverted', async function () { - await setupContracts() + await setupContracts(); - cAmount = BigNumber.from('1') - await mockOracle.setData('123', true) + cAmount = BigNumber.from('1'); + await mockOracle.setData('123', true); - await mockBTC.connect(deployer).mint(userAAddress, cAmount) - await mockBTC.connect(userA).approve(buttonToken.address, cAmount) + await mockBTC.connect(deployer).mint(userAAddress, cAmount); + await mockBTC.connect(userA).approve(buttonToken.address, cAmount); - await expect(buttonToken.connect(userA).deposit(cAmount)).to.be.reverted - }) - }) + await expect(buttonToken.connect(userA).deposit(cAmount)).to.be.reverted; + }); + }); describe('When deposit amount unit amount', async function () { beforeEach('setup ButtonToken contract', async () => { - await setupContracts() + await setupContracts(); - cAmount = BigNumber.from('1') + cAmount = BigNumber.from('1'); - await mockBTC.connect(deployer).mint(userAAddress, cAmount) - await mockBTC.connect(userA).approve(buttonToken.address, cAmount) - }) + await mockBTC.connect(deployer).mint(userAAddress, cAmount); + await mockBTC.connect(userA).approve(buttonToken.address, cAmount); + }); it('should transfer underlying from the user', async function () { - expect(await mockBTC.balanceOf(userAAddress)).to.eq(cAmount) - expect(await mockBTC.balanceOf(buttonToken.address)).to.eq('0') + expect(await mockBTC.balanceOf(userAAddress)).to.eq(cAmount); + expect(await mockBTC.balanceOf(buttonToken.address)).to.eq('0'); - expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq('0') - expect(await buttonToken.totalUnderlying()).to.eq('0') + expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq('0'); + expect(await buttonToken.totalUnderlying()).to.eq('0'); await expect(buttonToken.connect(userA).deposit(cAmount)) .to.emit(mockBTC, 'Transfer') - .withArgs(userAAddress, buttonToken.address, cAmount) + .withArgs(userAAddress, buttonToken.address, cAmount); - expect(await mockBTC.balanceOf(userAAddress)).to.eq('0') - expect(await mockBTC.balanceOf(buttonToken.address)).to.eq(cAmount) + expect(await mockBTC.balanceOf(userAAddress)).to.eq('0'); + expect(await mockBTC.balanceOf(buttonToken.address)).to.eq(cAmount); - expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq(cAmount) - expect(await buttonToken.totalUnderlying()).to.eq(cAmount) - }) + expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq( + cAmount, + ); + expect(await buttonToken.totalUnderlying()).to.eq(cAmount); + }); it('should deposit button tokens', async function () { - expect(await buttonToken.balanceOf(userAAddress)).to.eq('0') + expect(await buttonToken.balanceOf(userAAddress)).to.eq('0'); expect( await buttonToken.connect(userA).callStatic.deposit(cAmount), - ).to.eq('10000') - await buttonToken.connect(userA).deposit(cAmount) + ).to.eq('10000'); + await buttonToken.connect(userA).deposit(cAmount); - expect(await buttonToken.balanceOf(userAAddress)).to.eq('10000') - }) + expect(await buttonToken.balanceOf(userAAddress)).to.eq('10000'); + }); it('should emit transfer log', async function () { await expect(buttonToken.connect(userA).deposit(cAmount)) .to.emit(buttonToken, 'Transfer') - .withArgs(ethers.constants.AddressZero, userAAddress, '10000') - }) - }) + .withArgs(ethers.constants.AddressZero, userAAddress, '10000'); + }); + }); describe('with sufficient approval', async function () { beforeEach('setup ButtonToken contract', async () => { - await setupContracts() + await setupContracts(); - cAmount = toFixedPtAmt('1') - await mockBTC.connect(deployer).mint(userAAddress, cAmount) + cAmount = toFixedPtAmt('1'); + await mockBTC.connect(deployer).mint(userAAddress, cAmount); - await mockBTC.connect(userA).approve(buttonToken.address, cAmount) - }) + await mockBTC.connect(userA).approve(buttonToken.address, cAmount); + }); it('should transfer underlying from the user', async function () { - expect(await mockBTC.balanceOf(userAAddress)).to.eq(cAmount) - expect(await mockBTC.balanceOf(buttonToken.address)).to.eq('0') + expect(await mockBTC.balanceOf(userAAddress)).to.eq(cAmount); + expect(await mockBTC.balanceOf(buttonToken.address)).to.eq('0'); - expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq('0') - expect(await buttonToken.totalUnderlying()).to.eq('0') + expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq('0'); + expect(await buttonToken.totalUnderlying()).to.eq('0'); await expect(buttonToken.connect(userA).deposit(cAmount)) .to.emit(mockBTC, 'Transfer') - .withArgs(userAAddress, buttonToken.address, cAmount) + .withArgs(userAAddress, buttonToken.address, cAmount); - expect(await mockBTC.balanceOf(userAAddress)).to.eq('0') - expect(await mockBTC.balanceOf(buttonToken.address)).to.eq(cAmount) + expect(await mockBTC.balanceOf(userAAddress)).to.eq('0'); + expect(await mockBTC.balanceOf(buttonToken.address)).to.eq(cAmount); - expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq(cAmount) - expect(await buttonToken.totalUnderlying()).to.eq(cAmount) - }) + expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq( + cAmount, + ); + expect(await buttonToken.totalUnderlying()).to.eq(cAmount); + }); it('should deposit button tokens', async function () { - expect(await buttonToken.balanceOf(userAAddress)).to.eq('0') + expect(await buttonToken.balanceOf(userAAddress)).to.eq('0'); expect( await buttonToken.connect(userA).callStatic.deposit(cAmount), - ).to.eq(toFixedPtAmt('10000')) + ).to.eq(toFixedPtAmt('10000')); - await buttonToken.connect(userA).deposit(cAmount) + await buttonToken.connect(userA).deposit(cAmount); expect(await buttonToken.balanceOf(userAAddress)).to.eq( toFixedPtAmt('10000'), - ) - }) + ); + }); it('should emit transfer log', async function () { await expect(buttonToken.connect(userA).deposit(cAmount)) @@ -241,120 +245,122 @@ describe('ButtonToken:deposit', async () => { ethers.constants.AddressZero, userAAddress, toFixedPtAmt('10000'), - ) - }) - }) -}) + ); + }); + }); +}); describe('ButtonToken:withdraw', async () => { describe('When withdraw amount zero', async function () { it('should be reverted', async function () { - await setupContracts() + await setupContracts(); - cAmount = toFixedPtAmt('1') - withdrawCAmount = BigNumber.from('0') + cAmount = toFixedPtAmt('1'); + withdrawCAmount = BigNumber.from('0'); - await mockBTC.connect(deployer).mint(userAAddress, cAmount) - await mockBTC.connect(userA).approve(buttonToken.address, cAmount) - await buttonToken.connect(userA).deposit(cAmount) + await mockBTC.connect(deployer).mint(userAAddress, cAmount); + await mockBTC.connect(userA).approve(buttonToken.address, cAmount); + await buttonToken.connect(userA).deposit(cAmount); await expect(buttonToken.connect(userA).withdraw(withdrawCAmount)).to.be - .reverted - }) - }) + .reverted; + }); + }); describe('When withdraw amount < unit amount', async function () { it('should be reverted', async function () { - await setupContracts() + await setupContracts(); - cAmount = toFixedPtAmt('2') - withdrawCAmount = BigNumber.from('1') + cAmount = toFixedPtAmt('2'); + withdrawCAmount = BigNumber.from('1'); - await mockBTC.connect(deployer).mint(userAAddress, cAmount) - await mockBTC.connect(userA).approve(buttonToken.address, cAmount) - await buttonToken.connect(userA).deposit(cAmount) + await mockBTC.connect(deployer).mint(userAAddress, cAmount); + await mockBTC.connect(userA).approve(buttonToken.address, cAmount); + await buttonToken.connect(userA).deposit(cAmount); - await mockOracle.setData('123', true) + await mockOracle.setData('123', true); await expect(buttonToken.connect(userA).withdraw(withdrawCAmount)).to.be - .reverted - }) - }) + .reverted; + }); + }); describe('When withdraw amount is unit amount', async function () { it('should not be reverted', async function () { - await setupContracts() + await setupContracts(); - cAmount = BigNumber.from('2') - withdrawCAmount = BigNumber.from('1') + cAmount = BigNumber.from('2'); + withdrawCAmount = BigNumber.from('1'); - await mockBTC.connect(deployer).mint(userAAddress, cAmount) - await mockBTC.connect(userA).approve(buttonToken.address, cAmount) - await buttonToken.connect(userA).deposit(cAmount) + await mockBTC.connect(deployer).mint(userAAddress, cAmount); + await mockBTC.connect(userA).approve(buttonToken.address, cAmount); + await buttonToken.connect(userA).deposit(cAmount); await expect(buttonToken.connect(userA).withdraw(withdrawCAmount)).not.to - .be.reverted - }) - }) + .be.reverted; + }); + }); describe('When withdraw amount > balance', async function () { it('should be reverted', async function () { - await setupContracts() + await setupContracts(); - cAmount = toFixedPtAmt('1') + cAmount = toFixedPtAmt('1'); - await mockBTC.connect(deployer).mint(userAAddress, cAmount) - await mockBTC.connect(userA).approve(buttonToken.address, cAmount) - await buttonToken.connect(userA).deposit(cAmount) + await mockBTC.connect(deployer).mint(userAAddress, cAmount); + await mockBTC.connect(userA).approve(buttonToken.address, cAmount); + await buttonToken.connect(userA).deposit(cAmount); await expect(buttonToken.connect(userA).deposit(cAmount.add(1))).to.be - .reverted - }) - }) + .reverted; + }); + }); describe('When withdraw amount equal to the balance', async function () { beforeEach(async function () { - await setupContracts() + await setupContracts(); - cAmount = toFixedPtAmt('1') + cAmount = toFixedPtAmt('1'); - await mockBTC.connect(deployer).mint(userAAddress, cAmount) - await mockBTC.connect(userA).approve(buttonToken.address, cAmount) + await mockBTC.connect(deployer).mint(userAAddress, cAmount); + await mockBTC.connect(userA).approve(buttonToken.address, cAmount); - await buttonToken.connect(userA).callStatic.deposit(cAmount) - await buttonToken.connect(userA).deposit(cAmount) - }) + await buttonToken.connect(userA).callStatic.deposit(cAmount); + await buttonToken.connect(userA).deposit(cAmount); + }); it('should transfer underlying to the user', async function () { - expect(await mockBTC.balanceOf(userAAddress)).to.eq('0') - expect(await mockBTC.balanceOf(buttonToken.address)).to.eq(cAmount) + expect(await mockBTC.balanceOf(userAAddress)).to.eq('0'); + expect(await mockBTC.balanceOf(buttonToken.address)).to.eq(cAmount); - expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq(cAmount) - expect(await buttonToken.totalUnderlying()).to.eq(cAmount) + expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq( + cAmount, + ); + expect(await buttonToken.totalUnderlying()).to.eq(cAmount); await expect(buttonToken.connect(userA).withdraw(cAmount)) .to.emit(mockBTC, 'Transfer') - .withArgs(buttonToken.address, userAAddress, cAmount) + .withArgs(buttonToken.address, userAAddress, cAmount); - expect(await mockBTC.balanceOf(userAAddress)).to.eq(cAmount) - expect(await mockBTC.balanceOf(buttonToken.address)).to.eq('0') + expect(await mockBTC.balanceOf(userAAddress)).to.eq(cAmount); + expect(await mockBTC.balanceOf(buttonToken.address)).to.eq('0'); - expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq('0') - expect(await buttonToken.totalUnderlying()).to.eq('0') - }) + expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq('0'); + expect(await buttonToken.totalUnderlying()).to.eq('0'); + }); it('should deposit button tokens', async function () { expect(await buttonToken.balanceOf(userAAddress)).to.eq( toFixedPtAmt('10000'), - ) + ); expect( await buttonToken.connect(userA).callStatic.withdraw(cAmount), - ).to.eq(toFixedPtAmt('10000')) + ).to.eq(toFixedPtAmt('10000')); - await buttonToken.connect(userA).withdraw(cAmount) + await buttonToken.connect(userA).withdraw(cAmount); - expect(await buttonToken.balanceOf(userAAddress)).to.eq('0') - }) + expect(await buttonToken.balanceOf(userAAddress)).to.eq('0'); + }); it('should emit transfer log', async function () { await expect(buttonToken.connect(userA).withdraw(cAmount)) @@ -363,61 +369,63 @@ describe('ButtonToken:withdraw', async () => { userAAddress, ethers.constants.AddressZero, toFixedPtAmt('10000'), - ) - }) - }) + ); + }); + }); describe('When withdraw amount less than the balance', async function () { beforeEach(async function () { - await setupContracts() + await setupContracts(); - cAmount = toFixedPtAmt('2') - withdrawCAmount = toFixedPtAmt('1') + cAmount = toFixedPtAmt('2'); + withdrawCAmount = toFixedPtAmt('1'); - await mockBTC.connect(deployer).mint(userAAddress, cAmount) - await mockBTC.connect(userA).approve(buttonToken.address, cAmount) + await mockBTC.connect(deployer).mint(userAAddress, cAmount); + await mockBTC.connect(userA).approve(buttonToken.address, cAmount); - await buttonToken.connect(userA).deposit(cAmount) - }) + await buttonToken.connect(userA).deposit(cAmount); + }); it('should transfer underlying to the user', async function () { - expect(await mockBTC.balanceOf(userAAddress)).to.eq('0') - expect(await mockBTC.balanceOf(buttonToken.address)).to.eq(cAmount) + expect(await mockBTC.balanceOf(userAAddress)).to.eq('0'); + expect(await mockBTC.balanceOf(buttonToken.address)).to.eq(cAmount); - expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq(cAmount) - expect(await buttonToken.totalUnderlying()).to.eq(cAmount) + expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq( + cAmount, + ); + expect(await buttonToken.totalUnderlying()).to.eq(cAmount); await expect(buttonToken.connect(userA).withdraw(withdrawCAmount)) .to.emit(mockBTC, 'Transfer') - .withArgs(buttonToken.address, userAAddress, withdrawCAmount) + .withArgs(buttonToken.address, userAAddress, withdrawCAmount); - expect(await mockBTC.balanceOf(userAAddress)).to.eq(toFixedPtAmt('1')) + expect(await mockBTC.balanceOf(userAAddress)).to.eq(toFixedPtAmt('1')); expect(await mockBTC.balanceOf(buttonToken.address)).to.eq( toFixedPtAmt('1'), - ) + ); expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq( cAmount.sub(withdrawCAmount), - ) + ); expect(await buttonToken.totalUnderlying()).to.eq( cAmount.sub(withdrawCAmount), - ) - }) + ); + }); it('should deposit button tokens', async function () { expect(await buttonToken.balanceOf(userAAddress)).to.eq( toFixedPtAmt('20000'), - ) + ); expect( await buttonToken.connect(userA).callStatic.withdraw(withdrawCAmount), - ).to.eq(toFixedPtAmt('10000')) - await buttonToken.connect(userA).withdraw(withdrawCAmount) + ).to.eq(toFixedPtAmt('10000')); + await buttonToken.connect(userA).withdraw(withdrawCAmount); expect(await buttonToken.balanceOf(userAAddress)).to.eq( toFixedPtAmt('10000'), - ) - }) + ); + }); it('should emit transfer log', async function () { await expect(buttonToken.connect(userA).withdraw(withdrawCAmount)) @@ -426,53 +434,53 @@ describe('ButtonToken:withdraw', async () => { userAAddress, ethers.constants.AddressZero, toFixedPtAmt('10000'), - ) - }) - }) -}) + ); + }); + }); +}); describe('ButtonToken:withdrawAll', async () => { beforeEach(async function () { - await setupContracts() + await setupContracts(); - cAmount = toFixedPtAmt('1') + cAmount = toFixedPtAmt('1'); - await mockBTC.connect(deployer).mint(userAAddress, cAmount) - await mockBTC.connect(userA).approve(buttonToken.address, cAmount) + await mockBTC.connect(deployer).mint(userAAddress, cAmount); + await mockBTC.connect(userA).approve(buttonToken.address, cAmount); - await buttonToken.connect(userA).deposit(cAmount) - }) + await buttonToken.connect(userA).deposit(cAmount); + }); it('should transfer underlying to the user', async function () { - expect(await mockBTC.balanceOf(userAAddress)).to.eq('0') - expect(await mockBTC.balanceOf(buttonToken.address)).to.eq(cAmount) + expect(await mockBTC.balanceOf(userAAddress)).to.eq('0'); + expect(await mockBTC.balanceOf(buttonToken.address)).to.eq(cAmount); - expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq(cAmount) - expect(await buttonToken.totalUnderlying()).to.eq(cAmount) + expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq(cAmount); + expect(await buttonToken.totalUnderlying()).to.eq(cAmount); await expect(buttonToken.connect(userA).withdrawAll()) .to.emit(mockBTC, 'Transfer') - .withArgs(buttonToken.address, userAAddress, cAmount) + .withArgs(buttonToken.address, userAAddress, cAmount); - expect(await mockBTC.balanceOf(userAAddress)).to.eq(cAmount) - expect(await mockBTC.balanceOf(buttonToken.address)).to.eq('0') + expect(await mockBTC.balanceOf(userAAddress)).to.eq(cAmount); + expect(await mockBTC.balanceOf(buttonToken.address)).to.eq('0'); - expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq('0') - expect(await buttonToken.totalUnderlying()).to.eq('0') - }) + expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq('0'); + expect(await buttonToken.totalUnderlying()).to.eq('0'); + }); it('should deposit button tokens', async function () { expect(await buttonToken.balanceOf(userAAddress)).to.eq( toFixedPtAmt('10000'), - ) + ); expect(await buttonToken.connect(userA).callStatic.withdrawAll()).to.eq( toFixedPtAmt('10000'), - ) - await buttonToken.connect(userA).withdrawAll() + ); + await buttonToken.connect(userA).withdrawAll(); - expect(await buttonToken.balanceOf(userAAddress)).to.eq('0') - }) + expect(await buttonToken.balanceOf(userAAddress)).to.eq('0'); + }); it('should emit transfer log', async function () { await expect(buttonToken.connect(userA).withdrawAll()) @@ -481,59 +489,59 @@ describe('ButtonToken:withdrawAll', async () => { userAAddress, ethers.constants.AddressZero, toFixedPtAmt('10000'), - ) - }) -}) + ); + }); +}); describe('ButtonToken:depositFor', async function () { beforeEach('setup ButtonToken contract', async () => { - await setupContracts() + await setupContracts(); - cAmount = toFixedPtAmt('1') - await mockBTC.connect(deployer).mint(userAAddress, cAmount) + cAmount = toFixedPtAmt('1'); + await mockBTC.connect(deployer).mint(userAAddress, cAmount); - await mockBTC.connect(userA).approve(buttonToken.address, cAmount) - }) + await mockBTC.connect(userA).approve(buttonToken.address, cAmount); + }); it('should transfer underlying from the user', async function () { - expect(await mockBTC.balanceOf(userAAddress)).to.eq(cAmount) - expect(await mockBTC.balanceOf(buttonToken.address)).to.eq('0') + expect(await mockBTC.balanceOf(userAAddress)).to.eq(cAmount); + expect(await mockBTC.balanceOf(buttonToken.address)).to.eq('0'); - expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq('0') - expect(await buttonToken.totalUnderlying()).to.eq('0') + expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq('0'); + expect(await buttonToken.totalUnderlying()).to.eq('0'); await expect( buttonToken.connect(userA).depositFor(deployerAddress, cAmount), ) .to.emit(mockBTC, 'Transfer') - .withArgs(userAAddress, buttonToken.address, cAmount) + .withArgs(userAAddress, buttonToken.address, cAmount); - expect(await mockBTC.balanceOf(userAAddress)).to.eq('0') - expect(await mockBTC.balanceOf(buttonToken.address)).to.eq(cAmount) + expect(await mockBTC.balanceOf(userAAddress)).to.eq('0'); + expect(await mockBTC.balanceOf(buttonToken.address)).to.eq(cAmount); - expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq('0') + expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq('0'); expect(await buttonToken.balanceOfUnderlying(deployerAddress)).to.eq( cAmount, - ) - expect(await buttonToken.totalUnderlying()).to.eq(cAmount) - }) + ); + expect(await buttonToken.totalUnderlying()).to.eq(cAmount); + }); it('should deposit button tokens', async function () { - expect(await buttonToken.balanceOf(userAAddress)).to.eq('0') + expect(await buttonToken.balanceOf(userAAddress)).to.eq('0'); expect( await buttonToken .connect(userA) .callStatic.depositFor(deployerAddress, cAmount), - ).to.eq(toFixedPtAmt('10000')) + ).to.eq(toFixedPtAmt('10000')); - await buttonToken.connect(userA).depositFor(deployerAddress, cAmount) + await buttonToken.connect(userA).depositFor(deployerAddress, cAmount); - expect(await buttonToken.balanceOf(userAAddress)).to.eq('0') + expect(await buttonToken.balanceOf(userAAddress)).to.eq('0'); expect(await buttonToken.balanceOf(deployerAddress)).to.eq( toFixedPtAmt('10000'), - ) - }) + ); + }); it('should emit transfer log', async function () { await expect( @@ -544,68 +552,68 @@ describe('ButtonToken:depositFor', async function () { ethers.constants.AddressZero, deployerAddress, toFixedPtAmt('10000'), - ) - }) -}) + ); + }); +}); describe('ButtonToken:withdrawTo', async function () { beforeEach(async function () { - await setupContracts() + await setupContracts(); - cAmount = toFixedPtAmt('2') - withdrawCAmount = toFixedPtAmt('1') + cAmount = toFixedPtAmt('2'); + withdrawCAmount = toFixedPtAmt('1'); - await mockBTC.connect(deployer).mint(userAAddress, cAmount) - await mockBTC.connect(userA).approve(buttonToken.address, cAmount) + await mockBTC.connect(deployer).mint(userAAddress, cAmount); + await mockBTC.connect(userA).approve(buttonToken.address, cAmount); - await buttonToken.connect(userA).deposit(cAmount) - }) + await buttonToken.connect(userA).deposit(cAmount); + }); it('should transfer underlying to the user', async function () { - expect(await mockBTC.balanceOf(userAAddress)).to.eq('0') - expect(await mockBTC.balanceOf(buttonToken.address)).to.eq(cAmount) + expect(await mockBTC.balanceOf(userAAddress)).to.eq('0'); + expect(await mockBTC.balanceOf(buttonToken.address)).to.eq(cAmount); - expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq(cAmount) - expect(await buttonToken.totalUnderlying()).to.eq(cAmount) + expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq(cAmount); + expect(await buttonToken.totalUnderlying()).to.eq(cAmount); await expect( buttonToken.connect(userA).withdrawTo(deployerAddress, withdrawCAmount), ) .to.emit(mockBTC, 'Transfer') - .withArgs(buttonToken.address, deployerAddress, withdrawCAmount) + .withArgs(buttonToken.address, deployerAddress, withdrawCAmount); - expect(await mockBTC.balanceOf(userAAddress)).to.eq(toFixedPtAmt('0')) - expect(await mockBTC.balanceOf(deployerAddress)).to.eq(toFixedPtAmt('1')) + expect(await mockBTC.balanceOf(userAAddress)).to.eq(toFixedPtAmt('0')); + expect(await mockBTC.balanceOf(deployerAddress)).to.eq(toFixedPtAmt('1')); expect(await mockBTC.balanceOf(buttonToken.address)).to.eq( toFixedPtAmt('1'), - ) + ); expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq( cAmount.sub(withdrawCAmount), - ) + ); expect(await buttonToken.totalUnderlying()).to.eq( cAmount.sub(withdrawCAmount), - ) - }) + ); + }); it('should deposit button tokens', async function () { expect(await buttonToken.balanceOf(userAAddress)).to.eq( toFixedPtAmt('20000'), - ) + ); expect( await buttonToken .connect(userA) .callStatic.withdrawTo(deployerAddress, withdrawCAmount), - ).to.eq(toFixedPtAmt('10000')) + ).to.eq(toFixedPtAmt('10000')); await buttonToken .connect(userA) - .withdrawTo(deployerAddress, withdrawCAmount) + .withdrawTo(deployerAddress, withdrawCAmount); expect(await buttonToken.balanceOf(userAAddress)).to.eq( toFixedPtAmt('10000'), - ) - }) + ); + }); it('should emit transfer log', async function () { await expect( @@ -616,55 +624,55 @@ describe('ButtonToken:withdrawTo', async function () { userAAddress, ethers.constants.AddressZero, toFixedPtAmt('10000'), - ) - }) -}) + ); + }); +}); describe('ButtonToken:withdrawAllTo', async function () { beforeEach(async function () { - await setupContracts() + await setupContracts(); - cAmount = toFixedPtAmt('2') + cAmount = toFixedPtAmt('2'); - await mockBTC.connect(deployer).mint(userAAddress, cAmount) - await mockBTC.connect(userA).approve(buttonToken.address, cAmount) + await mockBTC.connect(deployer).mint(userAAddress, cAmount); + await mockBTC.connect(userA).approve(buttonToken.address, cAmount); - await buttonToken.connect(userA).deposit(cAmount) - }) + await buttonToken.connect(userA).deposit(cAmount); + }); it('should transfer underlying to the user', async function () { - expect(await mockBTC.balanceOf(userAAddress)).to.eq('0') - expect(await mockBTC.balanceOf(buttonToken.address)).to.eq(cAmount) + expect(await mockBTC.balanceOf(userAAddress)).to.eq('0'); + expect(await mockBTC.balanceOf(buttonToken.address)).to.eq(cAmount); - expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq(cAmount) - expect(await buttonToken.totalUnderlying()).to.eq(cAmount) + expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq(cAmount); + expect(await buttonToken.totalUnderlying()).to.eq(cAmount); await expect(buttonToken.connect(userA).withdrawAllTo(deployerAddress)) .to.emit(mockBTC, 'Transfer') - .withArgs(buttonToken.address, deployerAddress, cAmount) + .withArgs(buttonToken.address, deployerAddress, cAmount); - expect(await mockBTC.balanceOf(userAAddress)).to.eq(toFixedPtAmt('0')) - expect(await mockBTC.balanceOf(deployerAddress)).to.eq(toFixedPtAmt('2')) - expect(await mockBTC.balanceOf(buttonToken.address)).to.eq('0') + expect(await mockBTC.balanceOf(userAAddress)).to.eq(toFixedPtAmt('0')); + expect(await mockBTC.balanceOf(deployerAddress)).to.eq(toFixedPtAmt('2')); + expect(await mockBTC.balanceOf(buttonToken.address)).to.eq('0'); - expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq('0') - expect(await buttonToken.totalUnderlying()).to.eq('0') - }) + expect(await buttonToken.balanceOfUnderlying(userAAddress)).to.eq('0'); + expect(await buttonToken.totalUnderlying()).to.eq('0'); + }); it('should deposit button tokens', async function () { expect(await buttonToken.balanceOf(userAAddress)).to.eq( toFixedPtAmt('20000'), - ) + ); expect( await buttonToken .connect(userA) .callStatic.withdrawAllTo(deployerAddress), - ).to.eq(toFixedPtAmt('20000')) - await buttonToken.connect(userA).withdrawAllTo(deployerAddress) + ).to.eq(toFixedPtAmt('20000')); + await buttonToken.connect(userA).withdrawAllTo(deployerAddress); - expect(await buttonToken.balanceOf(userAAddress)).to.eq('0') - }) + expect(await buttonToken.balanceOf(userAAddress)).to.eq('0'); + }); it('should emit transfer log', async function () { await expect(buttonToken.connect(userA).withdrawAllTo(deployerAddress)) @@ -673,16 +681,16 @@ describe('ButtonToken:withdrawAllTo', async function () { userAAddress, ethers.constants.AddressZero, toFixedPtAmt('20000'), - ) - }) -}) + ); + }); +}); describe('ButtonToken:mint', async () => { it('should not be able to mint tiny amounts with 0 uAmount', async function () { - await setupContracts() + await setupContracts(); await expect( buttonToken.connect(userA).mint(toFixedPtAmt('0.000000000000000001')), - ).to.be.reverted - }) -}) + ).to.be.reverted; + }); +}); diff --git a/test/unit/ButtonToken_erc20_behavior.ts b/test/unit/ButtonToken_erc20_behavior.ts index 1761264..a6e2218 100644 --- a/test/unit/ButtonToken_erc20_behavior.ts +++ b/test/unit/ButtonToken_erc20_behavior.ts @@ -24,97 +24,97 @@ https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/test/token/ERC20/ERC20.test.js */ -import { ethers, upgrades, waffle } from 'hardhat' -import { Contract, Signer, BigNumber } from 'ethers' -import { TransactionResponse } from '@ethersproject/providers' -import { expect } from 'chai' +import { ethers, upgrades, waffle } from 'hardhat'; +import { Contract, Signer, BigNumber } from 'ethers'; +import { TransactionResponse } from '@ethersproject/providers'; +import { expect } from 'chai'; -const ORACLE_DECIMALS = 8 -const DECIMALS = 18 -const NAME = 'Button Bitcoin' -const SYMBOL = 'BTN-BTC' +const ORACLE_DECIMALS = 8; +const DECIMALS = 18; +const NAME = 'Button Bitcoin'; +const SYMBOL = 'BTN-BTC'; const toOracleValue = (v: string): BigNumber => - ethers.utils.parseUnits(v, ORACLE_DECIMALS) + ethers.utils.parseUnits(v, ORACLE_DECIMALS); const toFixedPtAmt = (a: string): BigNumber => - ethers.utils.parseUnits(a, DECIMALS) + ethers.utils.parseUnits(a, DECIMALS); -const INITIAL_SUPPLY = ethers.utils.parseUnits('50', DECIMALS) -const transferAmount = toFixedPtAmt('10') -const unitTokenAmount = toFixedPtAmt('1') +const INITIAL_SUPPLY = ethers.utils.parseUnits('50', DECIMALS); +const transferAmount = toFixedPtAmt('10'); +const unitTokenAmount = toFixedPtAmt('1'); -const overdraftAmount = INITIAL_SUPPLY.add(unitTokenAmount) -const overdraftAmountPlusOne = overdraftAmount.add(unitTokenAmount) -const overdraftAmountMinusOne = overdraftAmount.sub(unitTokenAmount) -const transferAmountPlusOne = transferAmount.add(unitTokenAmount) -const transferAmountMinusOne = transferAmount.sub(unitTokenAmount) +const overdraftAmount = INITIAL_SUPPLY.add(unitTokenAmount); +const overdraftAmountPlusOne = overdraftAmount.add(unitTokenAmount); +const overdraftAmountMinusOne = overdraftAmount.sub(unitTokenAmount); +const transferAmountPlusOne = transferAmount.add(unitTokenAmount); +const transferAmountMinusOne = transferAmount.sub(unitTokenAmount); -let token: Contract, owner: Signer, anotherAccount: Signer, recipient: Signer +let token: Contract, owner: Signer, anotherAccount: Signer, recipient: Signer; async function setupToken() { - const [owner, recipient, anotherAccount] = await ethers.getSigners() + const [owner, recipient, anotherAccount] = await ethers.getSigners(); - const erc20Factory = await ethers.getContractFactory('MockERC20') + const erc20Factory = await ethers.getContractFactory('MockERC20'); const mockBTC = await erc20Factory .connect(owner) - .deploy('Wood Bitcoin', 'WOOD-BTC') + .deploy('Wood Bitcoin', 'WOOD-BTC'); - const oracleFactory = await ethers.getContractFactory('MockOracle') - const mockOracle = await oracleFactory.connect(owner).deploy() - await mockOracle.setData(toOracleValue('1'), true) + const oracleFactory = await ethers.getContractFactory('MockOracle'); + const mockOracle = await oracleFactory.connect(owner).deploy(); + await mockOracle.setData(toOracleValue('1'), true); - const buttonTokenFactory = await ethers.getContractFactory('ButtonToken') - token = await buttonTokenFactory.connect(owner).deploy() + const buttonTokenFactory = await ethers.getContractFactory('ButtonToken'); + token = await buttonTokenFactory.connect(owner).deploy(); - token.initialize(mockBTC.address, NAME, SYMBOL, mockOracle.address) + token.initialize(mockBTC.address, NAME, SYMBOL, mockOracle.address); - await mockBTC.connect(owner).mint(await owner.getAddress(), INITIAL_SUPPLY) + await mockBTC.connect(owner).mint(await owner.getAddress(), INITIAL_SUPPLY); - await mockBTC.connect(owner).approve(token.address, INITIAL_SUPPLY) - await token.connect(owner).deposit(INITIAL_SUPPLY) + await mockBTC.connect(owner).approve(token.address, INITIAL_SUPPLY); + await token.connect(owner).deposit(INITIAL_SUPPLY); - return { token, owner, recipient, anotherAccount } + return { token, owner, recipient, anotherAccount }; } describe('ButtonToken:ERC20', () => { before('setup ButtonToken contract', async function () { - ;({ token, owner, recipient, anotherAccount } = await waffle.loadFixture( + ({ token, owner, recipient, anotherAccount } = await waffle.loadFixture( setupToken, - )) - }) + )); + }); describe('totalSupply', function () { it('returns the total amount of tokens', async function () { - expect(await token.totalSupply()).to.eq(INITIAL_SUPPLY) - }) - }) + expect(await token.totalSupply()).to.eq(INITIAL_SUPPLY); + }); + }); describe('balanceOf', function () { describe('when the requested account has no tokens', function () { it('returns zero', async function () { expect(await token.balanceOf(await anotherAccount.getAddress())).to.eq( 0, - ) - }) - }) + ); + }); + }); describe('when the requested account has some tokens', function () { it('returns the total amount of tokens', async function () { expect(await token.balanceOf(await owner.getAddress())).to.eq( INITIAL_SUPPLY, - ) - }) - }) - }) -}) + ); + }); + }); + }); +}); describe('ButtonToken:ERC20:transfer', () => { before('setup ButtonToken contract', async function () { - ;({ token, owner, recipient, anotherAccount } = await waffle.loadFixture( + ({ token, owner, recipient, anotherAccount } = await waffle.loadFixture( setupToken, - )) - }) + )); + }); describe('when the sender does NOT have enough balance', function () { it('reverts', async function () { @@ -122,9 +122,9 @@ describe('ButtonToken:ERC20:transfer', () => { token .connect(owner) .transfer(await recipient.getAddress(), overdraftAmount), - ).to.be.reverted - }) - }) + ).to.be.reverted; + }); + }); describe('when the sender has enough balance', function () { it('should emit a transfer event', async function () { @@ -138,19 +138,19 @@ describe('ButtonToken:ERC20:transfer', () => { await owner.getAddress(), await recipient.getAddress(), transferAmount, - ) - }) + ); + }); it('should transfer the requested amount', async function () { - const senderBalance = await token.balanceOf(await owner.getAddress()) + const senderBalance = await token.balanceOf(await owner.getAddress()); const recipientBalance = await token.balanceOf( await recipient.getAddress(), - ) - const supply = await token.totalSupply() - expect(supply.sub(transferAmount)).to.eq(senderBalance) - expect(recipientBalance).to.eq(transferAmount) - }) - }) + ); + const supply = await token.totalSupply(); + expect(supply.sub(transferAmount)).to.eq(senderBalance); + expect(recipientBalance).to.eq(transferAmount); + }); + }); describe('when the recipient is the zero address', function () { it('should fail', async function () { @@ -158,24 +158,24 @@ describe('ButtonToken:ERC20:transfer', () => { token .connect(owner) .transfer(ethers.constants.AddressZero, transferAmount), - ).to.be.reverted - }) - }) -}) + ).to.be.reverted; + }); + }); +}); describe('ButtonToken:ERC20:transferFrom', () => { before('setup ButtonToken contract', async function () { - ;({ token, owner, recipient, anotherAccount } = await waffle.loadFixture( + ({ token, owner, recipient, anotherAccount } = await waffle.loadFixture( setupToken, - )) - }) + )); + }); describe('when the spender does NOT have enough approved balance', function () { describe('when the owner does NOT have enough balance', function () { it('reverts', async function () { await token .connect(owner) - .approve(await anotherAccount.getAddress(), overdraftAmountMinusOne) + .approve(await anotherAccount.getAddress(), overdraftAmountMinusOne); await expect( token .connect(anotherAccount) @@ -184,15 +184,15 @@ describe('ButtonToken:ERC20:transferFrom', () => { await recipient.getAddress(), overdraftAmount, ), - ).to.be.reverted - }) - }) + ).to.be.reverted; + }); + }); describe('when the owner has enough balance', function () { it('reverts', async function () { await token .connect(owner) - .approve(await anotherAccount.getAddress(), transferAmountMinusOne) + .approve(await anotherAccount.getAddress(), transferAmountMinusOne); await expect( token .connect(anotherAccount) @@ -201,17 +201,17 @@ describe('ButtonToken:ERC20:transferFrom', () => { await recipient.getAddress(), transferAmount, ), - ).to.be.reverted - }) - }) - }) + ).to.be.reverted; + }); + }); + }); describe('when the spender has enough approved balance', function () { describe('when the owner does NOT have enough balance', function () { it('should fail', async function () { await token .connect(owner) - .approve(await anotherAccount.getAddress(), overdraftAmount) + .approve(await anotherAccount.getAddress(), overdraftAmount); await expect( token .connect(anotherAccount) @@ -220,18 +220,18 @@ describe('ButtonToken:ERC20:transferFrom', () => { await recipient.getAddress(), overdraftAmount, ), - ).to.be.reverted - }) - }) + ).to.be.reverted; + }); + }); describe('when the owner has enough balance', function () { - let prevSenderBalance: BigNumber + let prevSenderBalance: BigNumber; before(async function () { - prevSenderBalance = await token.balanceOf(await owner.getAddress()) + prevSenderBalance = await token.balanceOf(await owner.getAddress()); await token .connect(owner) - .approve(await anotherAccount.getAddress(), transferAmount) - }) + .approve(await anotherAccount.getAddress(), transferAmount); + }); it('emits a transfer and approval event', async function () { await expect( @@ -254,17 +254,17 @@ describe('ButtonToken:ERC20:transferFrom', () => { await owner.getAddress(), await anotherAccount.getAddress(), '0', - ) - }) + ); + }); it('transfers the requested amount', async function () { - const senderBalance = await token.balanceOf(await owner.getAddress()) + const senderBalance = await token.balanceOf(await owner.getAddress()); const recipientBalance = await token.balanceOf( await recipient.getAddress(), - ) - expect(prevSenderBalance.sub(transferAmount)).to.eq(senderBalance) - expect(recipientBalance).to.eq(transferAmount) - }) + ); + expect(prevSenderBalance.sub(transferAmount)).to.eq(senderBalance); + expect(recipientBalance).to.eq(transferAmount); + }); it('decreases the spender allowance', async function () { expect( @@ -272,17 +272,17 @@ describe('ButtonToken:ERC20:transferFrom', () => { await owner.getAddress(), await anotherAccount.getAddress(), ), - ).to.eq(0) - }) - }) - }) + ).to.eq(0); + }); + }); + }); describe('when the spender has made an infinite approval balance', function () { describe('when the owner does NOT have enough balance', function () { it('should fail', async function () { await token .connect(owner) - .approve(await anotherAccount.getAddress(), overdraftAmount) + .approve(await anotherAccount.getAddress(), overdraftAmount); await expect( token .connect(anotherAccount) @@ -291,25 +291,25 @@ describe('ButtonToken:ERC20:transferFrom', () => { await recipient.getAddress(), overdraftAmount, ), - ).to.be.reverted - }) - }) + ).to.be.reverted; + }); + }); describe('when the owner has enough balance', function () { - let prevSenderBalance: BigNumber - let prevRecipientBalance: BigNumber + let prevSenderBalance: BigNumber; + let prevRecipientBalance: BigNumber; before(async function () { - prevSenderBalance = await token.balanceOf(await owner.getAddress()) + prevSenderBalance = await token.balanceOf(await owner.getAddress()); prevRecipientBalance = await token.balanceOf( await recipient.getAddress(), - ) + ); await token .connect(owner) .approve( await anotherAccount.getAddress(), ethers.constants.MaxUint256, - ) - }) + ); + }); it('emits a transfer and but no approval event', async function () { await expect( @@ -327,17 +327,19 @@ describe('ButtonToken:ERC20:transferFrom', () => { await recipient.getAddress(), transferAmount, ) - .to.not.emit(token, 'Approval') - }) + .to.not.emit(token, 'Approval'); + }); it('transfers the requested amount', async function () { - const senderBalance = await token.balanceOf(await owner.getAddress()) + const senderBalance = await token.balanceOf(await owner.getAddress()); const recipientBalance = await token.balanceOf( await recipient.getAddress(), - ) - expect(prevSenderBalance.sub(senderBalance)).to.eq(transferAmount) - expect(recipientBalance.sub(prevRecipientBalance)).to.eq(transferAmount) - }) + ); + expect(prevSenderBalance.sub(senderBalance)).to.eq(transferAmount); + expect(recipientBalance.sub(prevRecipientBalance)).to.eq( + transferAmount, + ); + }); it('does NOT decrease the spender allowance', async function () { expect( @@ -345,41 +347,41 @@ describe('ButtonToken:ERC20:transferFrom', () => { await owner.getAddress(), await anotherAccount.getAddress(), ), - ).to.eq(ethers.constants.MaxUint256) - }) - }) - }) -}) + ).to.eq(ethers.constants.MaxUint256); + }); + }); + }); +}); describe('ButtonToken:ERC20:approve', () => { before('setup ButtonToken contract', async function () { - ;({ token, owner, recipient, anotherAccount } = await waffle.loadFixture( + ({ token, owner, recipient, anotherAccount } = await waffle.loadFixture( setupToken, - )) - }) + )); + }); describe('when the spender is NOT the zero address', function () { describe('when the sender has enough balance', function () { describe('when there was no approved amount before', function () { - let r: Promise + let r: Promise; before(async function () { await token .connect(owner) - .approve(await anotherAccount.getAddress(), 0) + .approve(await anotherAccount.getAddress(), 0); r = token .connect(owner) - .approve(await anotherAccount.getAddress(), transferAmount) - }) + .approve(await anotherAccount.getAddress(), transferAmount); + }); it('approves the requested amount', async function () { - await r + await r; expect( await token.allowance( await owner.getAddress(), await anotherAccount.getAddress(), ), - ).to.eq(transferAmount) - }) + ).to.eq(transferAmount); + }); it('emits an approval event', async function () { await expect(r) @@ -388,30 +390,30 @@ describe('ButtonToken:ERC20:approve', () => { await owner.getAddress(), await anotherAccount.getAddress(), transferAmount, - ) - }) - }) + ); + }); + }); describe('when the spender had an approved amount', function () { - let r: Promise + let r: Promise; before(async function () { await token .connect(owner) - .approve(await anotherAccount.getAddress(), toFixedPtAmt('1')) + .approve(await anotherAccount.getAddress(), toFixedPtAmt('1')); r = token .connect(owner) - .approve(await anotherAccount.getAddress(), transferAmount) - }) + .approve(await anotherAccount.getAddress(), transferAmount); + }); it('approves the requested amount and replaces the previous one', async function () { - await r + await r; expect( await token.allowance( await owner.getAddress(), await anotherAccount.getAddress(), ), - ).to.eq(transferAmount) - }) + ).to.eq(transferAmount); + }); it('emits an approval event', async function () { await expect(r) @@ -420,32 +422,32 @@ describe('ButtonToken:ERC20:approve', () => { await owner.getAddress(), await anotherAccount.getAddress(), transferAmount, - ) - }) - }) - }) + ); + }); + }); + }); describe('when the sender does not have enough balance', function () { describe('when there was no approved amount before', function () { - let r: Promise + let r: Promise; before(async function () { await token .connect(owner) - .approve(await anotherAccount.getAddress(), 0) + .approve(await anotherAccount.getAddress(), 0); r = token .connect(owner) - .approve(await anotherAccount.getAddress(), overdraftAmount) - }) + .approve(await anotherAccount.getAddress(), overdraftAmount); + }); it('approves the requested amount', async function () { - await r + await r; expect( await token.allowance( await owner.getAddress(), await anotherAccount.getAddress(), ), - ).to.eq(overdraftAmount) - }) + ).to.eq(overdraftAmount); + }); it('emits an approval event', async function () { await expect(r) @@ -454,30 +456,30 @@ describe('ButtonToken:ERC20:approve', () => { await owner.getAddress(), await anotherAccount.getAddress(), overdraftAmount, - ) - }) - }) + ); + }); + }); describe('when the spender had an approved amount', function () { - let r: Promise + let r: Promise; before(async function () { await token .connect(owner) - .approve(await anotherAccount.getAddress(), toFixedPtAmt('1')) + .approve(await anotherAccount.getAddress(), toFixedPtAmt('1')); r = token .connect(owner) - .approve(await anotherAccount.getAddress(), overdraftAmount) - }) + .approve(await anotherAccount.getAddress(), overdraftAmount); + }); it('approves the requested amount', async function () { - await r + await r; expect( await token.allowance( await owner.getAddress(), await anotherAccount.getAddress(), ), - ).to.eq(overdraftAmount) - }) + ).to.eq(overdraftAmount); + }); it('emits an approval event', async function () { await expect(r) @@ -486,44 +488,44 @@ describe('ButtonToken:ERC20:approve', () => { await owner.getAddress(), await anotherAccount.getAddress(), overdraftAmount, - ) - }) - }) - }) - }) -}) + ); + }); + }); + }); + }); +}); describe('ButtonToken:ERC20:increaseAllowance', () => { before('setup ButtonToken contract', async function () { - ;({ token, owner, recipient, anotherAccount } = await waffle.loadFixture( + ({ token, owner, recipient, anotherAccount } = await waffle.loadFixture( setupToken, - )) - }) + )); + }); describe('when the spender is NOT the zero address', function () { describe('when the sender has enough balance', function () { describe('when there was no approved amount before', function () { - let r: Promise + let r: Promise; before(async function () { await token .connect(owner) - .approve(await anotherAccount.getAddress(), 0) + .approve(await anotherAccount.getAddress(), 0); r = token .connect(owner) .increaseAllowance( await anotherAccount.getAddress(), transferAmount, - ) - }) + ); + }); it('approves the requested amount', async function () { - await r + await r; expect( await token.allowance( await owner.getAddress(), await anotherAccount.getAddress(), ), - ).to.eq(transferAmount) - }) + ).to.eq(transferAmount); + }); it('emits an approval event', async function () { await expect(r) @@ -532,33 +534,33 @@ describe('ButtonToken:ERC20:increaseAllowance', () => { await owner.getAddress(), await anotherAccount.getAddress(), transferAmount, - ) - }) - }) + ); + }); + }); describe('when the spender had an approved amount', function () { - let r: Promise + let r: Promise; beforeEach(async function () { await token .connect(owner) - .approve(await anotherAccount.getAddress(), unitTokenAmount) + .approve(await anotherAccount.getAddress(), unitTokenAmount); r = token .connect(owner) .increaseAllowance( await anotherAccount.getAddress(), transferAmount, - ) - }) + ); + }); it('increases the spender allowance adding the requested amount', async function () { - await r + await r; expect( await token.allowance( await owner.getAddress(), await anotherAccount.getAddress(), ), - ).to.eq(transferAmountPlusOne) - }) + ).to.eq(transferAmountPlusOne); + }); it('emits an approval event', async function () { await expect(r) @@ -567,35 +569,35 @@ describe('ButtonToken:ERC20:increaseAllowance', () => { await owner.getAddress(), await anotherAccount.getAddress(), transferAmountPlusOne, - ) - }) - }) - }) + ); + }); + }); + }); describe('when the sender does not have enough balance', function () { describe('when there was no approved amount before', function () { - let r: Promise + let r: Promise; before(async function () { await token .connect(owner) - .approve(await anotherAccount.getAddress(), 0) + .approve(await anotherAccount.getAddress(), 0); r = token .connect(owner) .increaseAllowance( await anotherAccount.getAddress(), overdraftAmount, - ) - }) + ); + }); it('approves the requested amount', async function () { - await r + await r; expect( await token.allowance( await owner.getAddress(), await anotherAccount.getAddress(), ), - ).to.eq(overdraftAmount) - }) + ).to.eq(overdraftAmount); + }); it('emits an approval event', async function () { await expect(r) @@ -604,33 +606,33 @@ describe('ButtonToken:ERC20:increaseAllowance', () => { await owner.getAddress(), await anotherAccount.getAddress(), overdraftAmount, - ) - }) - }) + ); + }); + }); describe('when the spender had an approved amount', function () { - let r: Promise + let r: Promise; beforeEach(async function () { await token .connect(owner) - .approve(await anotherAccount.getAddress(), unitTokenAmount) + .approve(await anotherAccount.getAddress(), unitTokenAmount); r = token .connect(owner) .increaseAllowance( await anotherAccount.getAddress(), overdraftAmount, - ) - }) + ); + }); it('increases the spender allowance adding the requested amount', async function () { - await r + await r; expect( await token.allowance( await owner.getAddress(), await anotherAccount.getAddress(), ), - ).to.eq(overdraftAmountPlusOne) - }) + ).to.eq(overdraftAmountPlusOne); + }); it('emits an approval event', async function () { await expect(r) @@ -639,42 +641,42 @@ describe('ButtonToken:ERC20:increaseAllowance', () => { await owner.getAddress(), await anotherAccount.getAddress(), overdraftAmountPlusOne, - ) - }) - }) - }) - }) -}) + ); + }); + }); + }); + }); +}); describe('ButtonToken:ERC20:decreaseAllowance', () => { before('setup ButtonToken contract', async function () { - ;({ token, owner, recipient, anotherAccount } = await waffle.loadFixture( + ({ token, owner, recipient, anotherAccount } = await waffle.loadFixture( setupToken, - )) - }) + )); + }); describe('when the spender is NOT the zero address', function () { describe('when the sender does NOT have enough balance', function () { describe('when there was no approved amount before', function () { - let r: Promise + let r: Promise; before(async function () { r = token .connect(owner) .decreaseAllowance( await anotherAccount.getAddress(), overdraftAmount, - ) - }) + ); + }); it('keeps the allowance to zero', async function () { - await r + await r; expect( await token.allowance( await owner.getAddress(), await anotherAccount.getAddress(), ), - ).to.eq(0) - }) + ).to.eq(0); + }); it('emits an approval event', async function () { await expect(r) @@ -683,33 +685,33 @@ describe('ButtonToken:ERC20:decreaseAllowance', () => { await owner.getAddress(), await anotherAccount.getAddress(), 0, - ) - }) - }) + ); + }); + }); describe('when the spender had an approved amount', function () { - let r: Promise + let r: Promise; before(async function () { await token .connect(owner) - .approve(await anotherAccount.getAddress(), overdraftAmountPlusOne) + .approve(await anotherAccount.getAddress(), overdraftAmountPlusOne); r = token .connect(owner) .decreaseAllowance( await anotherAccount.getAddress(), overdraftAmount, - ) - }) + ); + }); it('decreases the spender allowance subtracting the requested amount', async function () { - await r + await r; expect( await token.allowance( await owner.getAddress(), await anotherAccount.getAddress(), ), - ).to.eq(unitTokenAmount) - }) + ).to.eq(unitTokenAmount); + }); it('emits an approval event', async function () { await expect(r) @@ -718,35 +720,35 @@ describe('ButtonToken:ERC20:decreaseAllowance', () => { await owner.getAddress(), await anotherAccount.getAddress(), unitTokenAmount, - ) - }) - }) - }) + ); + }); + }); + }); describe('when the sender has enough balance', function () { describe('when there was no approved amount before', function () { - let r: Promise + let r: Promise; before(async function () { await token .connect(owner) - .approve(await anotherAccount.getAddress(), 0) + .approve(await anotherAccount.getAddress(), 0); r = token .connect(owner) .decreaseAllowance( await anotherAccount.getAddress(), transferAmount, - ) - }) + ); + }); it('keeps the allowance to zero', async function () { - await r + await r; expect( await token.allowance( await owner.getAddress(), await anotherAccount.getAddress(), ), - ).to.eq(0) - }) + ).to.eq(0); + }); it('emits an approval event', async function () { await expect(r) @@ -755,33 +757,33 @@ describe('ButtonToken:ERC20:decreaseAllowance', () => { await owner.getAddress(), await anotherAccount.getAddress(), 0, - ) - }) - }) + ); + }); + }); describe('when the spender had an approved amount', function () { - let r: Promise + let r: Promise; before(async function () { await token .connect(owner) - .approve(await anotherAccount.getAddress(), transferAmountPlusOne) + .approve(await anotherAccount.getAddress(), transferAmountPlusOne); r = token .connect(owner) .decreaseAllowance( await anotherAccount.getAddress(), transferAmount, - ) - }) + ); + }); it('decreases the spender allowance subtracting the requested amount', async function () { - await r + await r; expect( await token.allowance( await owner.getAddress(), await anotherAccount.getAddress(), ), - ).to.eq(unitTokenAmount) - }) + ).to.eq(unitTokenAmount); + }); it('emits an approval event', async function () { await expect(r) @@ -790,9 +792,9 @@ describe('ButtonToken:ERC20:decreaseAllowance', () => { await owner.getAddress(), await anotherAccount.getAddress(), unitTokenAmount, - ) - }) - }) - }) - }) -}) + ); + }); + }); + }); + }); +}); diff --git a/test/unit/ButtonToken_rebasing_erc20_behavior.ts b/test/unit/ButtonToken_rebasing_erc20_behavior.ts index 0c97d96..e87eb79 100644 --- a/test/unit/ButtonToken_rebasing_erc20_behavior.ts +++ b/test/unit/ButtonToken_rebasing_erc20_behavior.ts @@ -1,118 +1,118 @@ -import { ethers, upgrades, waffle } from 'hardhat' -import { Contract, Signer, BigNumber } from 'ethers' -import { TransactionResponse } from '@ethersproject/providers' -import { expect } from 'chai' +import { ethers, upgrades, waffle } from 'hardhat'; +import { Contract, Signer, BigNumber } from 'ethers'; +import { TransactionResponse } from '@ethersproject/providers'; +import { expect } from 'chai'; -const ORACLE_DECIMALS = 8 -const DECIMALS = 18 -const NAME = 'Button Bitcoin' -const SYMBOL = 'BTN-BTC' +const ORACLE_DECIMALS = 8; +const DECIMALS = 18; +const NAME = 'Button Bitcoin'; +const SYMBOL = 'BTN-BTC'; const toOracleValue = (v: string): BigNumber => - ethers.utils.parseUnits(v, ORACLE_DECIMALS) + ethers.utils.parseUnits(v, ORACLE_DECIMALS); const toFixedPtAmt = (a: string): BigNumber => - ethers.utils.parseUnits(a, DECIMALS) + ethers.utils.parseUnits(a, DECIMALS); -const INITIAL_SUPPLY = ethers.utils.parseUnits('50', DECIMALS) -const unitTokenAmount = toFixedPtAmt('1') +const INITIAL_SUPPLY = ethers.utils.parseUnits('50', DECIMALS); +const unitTokenAmount = toFixedPtAmt('1'); -let token: Contract, owner: Signer, anotherAccount: Signer, recipient: Signer +let token: Contract, owner: Signer, anotherAccount: Signer, recipient: Signer; async function setupToken() { - const [owner, recipient, anotherAccount] = await ethers.getSigners() + const [owner, recipient, anotherAccount] = await ethers.getSigners(); - const erc20Factory = await ethers.getContractFactory('MockERC20') + const erc20Factory = await ethers.getContractFactory('MockERC20'); const mockBTC = await erc20Factory .connect(owner) - .deploy('Wood Bitcoin', 'WOOD-BTC') + .deploy('Wood Bitcoin', 'WOOD-BTC'); - const oracleFactory = await ethers.getContractFactory('MockOracle') - const mockOracle = await oracleFactory.connect(owner).deploy() - await mockOracle.setData(toOracleValue('1'), true) + const oracleFactory = await ethers.getContractFactory('MockOracle'); + const mockOracle = await oracleFactory.connect(owner).deploy(); + await mockOracle.setData(toOracleValue('1'), true); - const buttonTokenFactory = await ethers.getContractFactory('ButtonToken') - token = await buttonTokenFactory.connect(owner).deploy() + const buttonTokenFactory = await ethers.getContractFactory('ButtonToken'); + token = await buttonTokenFactory.connect(owner).deploy(); - await token.initialize(mockBTC.address, NAME, SYMBOL, mockOracle.address) + await token.initialize(mockBTC.address, NAME, SYMBOL, mockOracle.address); - await mockBTC.connect(owner).mint(await owner.getAddress(), INITIAL_SUPPLY) + await mockBTC.connect(owner).mint(await owner.getAddress(), INITIAL_SUPPLY); - await mockBTC.connect(owner).approve(token.address, INITIAL_SUPPLY) - await token.connect(owner).deposit(INITIAL_SUPPLY) + await mockBTC.connect(owner).approve(token.address, INITIAL_SUPPLY); + await token.connect(owner).deposit(INITIAL_SUPPLY); - return { token, owner, recipient, anotherAccount } + return { token, owner, recipient, anotherAccount }; } describe('Button:Elastic', () => { beforeEach('setup Button contract', async function () { - ;({ token, owner, recipient, anotherAccount } = await waffle.loadFixture( + ({ token, owner, recipient, anotherAccount } = await waffle.loadFixture( setupToken, - )) - }) + )); + }); describe('scaledTotalSupply', function () { it('returns the scaled total amount of tokens', async function () { - expect(await token.scaledTotalSupply()).to.eq(INITIAL_SUPPLY) - }) - }) + expect(await token.scaledTotalSupply()).to.eq(INITIAL_SUPPLY); + }); + }); describe('scaledBalanceOf', function () { describe('when the requested for zero account', function () { it('returns zero', async function () { expect(await token.scaledBalanceOf(ethers.constants.AddressZero)).to.eq( 0, - ) - }) - }) + ); + }); + }); describe('when the requested account has no tokens', function () { it('returns zero', async function () { expect( await token.scaledBalanceOf(await anotherAccount.getAddress()), - ).to.eq(0) - }) - }) + ).to.eq(0); + }); + }); describe('when the requested account has some tokens', function () { it('returns the total amount of tokens', async function () { expect(await token.scaledBalanceOf(await owner.getAddress())).to.eq( INITIAL_SUPPLY, - ) - }) - }) - }) -}) + ); + }); + }); + }); +}); describe('Button:Elastic:transferAll', () => { beforeEach('setup Button contract', async function () { - ;({ token, owner, recipient, anotherAccount } = await waffle.loadFixture( + ({ token, owner, recipient, anotherAccount } = await waffle.loadFixture( setupToken, - )) - }) + )); + }); describe('when the recipient is the zero address', function () { it('should revert', async function () { await expect( token.connect(owner).transferAll(ethers.constants.AddressZero), - ).to.be.reverted - }) - }) + ).to.be.reverted; + }); + }); describe('when the recipient is the contract address', function () { it('should revert', async function () { await expect(token.connect(owner).transferAll(token.address)).to.be - .reverted - }) - }) + .reverted; + }); + }); describe('when the sender has zero balance', function () { it('should not revert', async function () { await expect( token.connect(anotherAccount).transferAll(await owner.getAddress()), - ).not.to.be.reverted - }) - }) + ).not.to.be.reverted; + }); + }); describe('when the sender has balance', function () { it('should emit a transfer event', async function () { @@ -124,38 +124,38 @@ describe('Button:Elastic:transferAll', () => { await owner.getAddress(), await recipient.getAddress(), INITIAL_SUPPLY, - ) - }) + ); + }); it("should transfer all of the sender's balance", async function () { - const senderBalance = await token.balanceOf(await owner.getAddress()) + const senderBalance = await token.balanceOf(await owner.getAddress()); const recipientBalance = await token.balanceOf( await recipient.getAddress(), - ) - await token.connect(owner).transferAll(await recipient.getAddress()) - const senderBalance_ = await token.balanceOf(await owner.getAddress()) + ); + await token.connect(owner).transferAll(await recipient.getAddress()); + const senderBalance_ = await token.balanceOf(await owner.getAddress()); const recipientBalance_ = await token.balanceOf( await recipient.getAddress(), - ) - expect(senderBalance_).to.eq('0') - expect(recipientBalance_.sub(recipientBalance)).to.eq(senderBalance) - }) - }) -}) + ); + expect(senderBalance_).to.eq('0'); + expect(recipientBalance_.sub(recipientBalance)).to.eq(senderBalance); + }); + }); +}); describe('Button:Elastic:transferAllFrom', () => { beforeEach('setup Button contract', async function () { - ;({ token, owner, recipient, anotherAccount } = await waffle.loadFixture( + ({ token, owner, recipient, anotherAccount } = await waffle.loadFixture( setupToken, - )) - }) + )); + }); describe('when the recipient is the zero address', function () { it('should revert', async function () { - const senderBalance = await token.balanceOf(await owner.getAddress()) + const senderBalance = await token.balanceOf(await owner.getAddress()); await token .connect(owner) - .approve(await anotherAccount.getAddress(), senderBalance) + .approve(await anotherAccount.getAddress(), senderBalance); await expect( token .connect(anotherAccount) @@ -163,32 +163,32 @@ describe('Button:Elastic:transferAllFrom', () => { await owner.getAddress(), ethers.constants.AddressZero, ), - ).to.be.reverted - }) - }) + ).to.be.reverted; + }); + }); describe('when the recipient is the contract address', function () { it('should revert', async function () { - const senderBalance = await token.balanceOf(await owner.getAddress()) + const senderBalance = await token.balanceOf(await owner.getAddress()); await token .connect(owner) - .approve(await anotherAccount.getAddress(), senderBalance) + .approve(await anotherAccount.getAddress(), senderBalance); await expect( token .connect(anotherAccount) .transferAllFrom(await owner.getAddress(), token.address), - ).to.be.reverted - }) - }) + ).to.be.reverted; + }); + }); describe('when the sender has zero balance', function () { it('should not revert', async function () { const senderBalance = await token.balanceOf( await anotherAccount.getAddress(), - ) + ); await token .connect(anotherAccount) - .approve(await anotherAccount.getAddress(), senderBalance) + .approve(await anotherAccount.getAddress(), senderBalance); await expect( token @@ -197,15 +197,15 @@ describe('Button:Elastic:transferAllFrom', () => { await anotherAccount.getAddress(), await recipient.getAddress(), ), - ).not.to.be.reverted - }) - }) + ).not.to.be.reverted; + }); + }); describe('when the spender does NOT have enough approved balance', function () { it('reverts', async function () { await token .connect(owner) - .approve(await anotherAccount.getAddress(), unitTokenAmount) + .approve(await anotherAccount.getAddress(), unitTokenAmount); await expect( token .connect(anotherAccount) @@ -213,16 +213,16 @@ describe('Button:Elastic:transferAllFrom', () => { await owner.getAddress(), await recipient.getAddress(), ), - ).to.be.reverted - }) - }) + ).to.be.reverted; + }); + }); describe('when the spender has enough approved balance', function () { it('emits a transfer event', async function () { - const senderBalance = await token.balanceOf(await owner.getAddress()) + const senderBalance = await token.balanceOf(await owner.getAddress()); await token .connect(owner) - .approve(await anotherAccount.getAddress(), senderBalance) + .approve(await anotherAccount.getAddress(), senderBalance); await expect( token @@ -237,36 +237,39 @@ describe('Button:Elastic:transferAllFrom', () => { await owner.getAddress(), await recipient.getAddress(), senderBalance, - ) - }) + ); + }); it('transfers the requested amount', async function () { - const senderBalance = await token.balanceOf(await owner.getAddress()) + const senderBalance = await token.balanceOf(await owner.getAddress()); const recipientBalance = await token.balanceOf( await recipient.getAddress(), - ) + ); await token .connect(owner) - .approve(await anotherAccount.getAddress(), senderBalance) + .approve(await anotherAccount.getAddress(), senderBalance); await token .connect(anotherAccount) - .transferAllFrom(await owner.getAddress(), await recipient.getAddress()) + .transferAllFrom( + await owner.getAddress(), + await recipient.getAddress(), + ); - const senderBalance_ = await token.balanceOf(await owner.getAddress()) + const senderBalance_ = await token.balanceOf(await owner.getAddress()); const recipientBalance_ = await token.balanceOf( await recipient.getAddress(), - ) - expect(senderBalance_).to.eq('0') - expect(recipientBalance_.sub(recipientBalance)).to.eq(senderBalance) - }) + ); + expect(senderBalance_).to.eq('0'); + expect(recipientBalance_.sub(recipientBalance)).to.eq(senderBalance); + }); it('decreases the spender allowance', async function () { - const senderBalance = await token.balanceOf(await owner.getAddress()) + const senderBalance = await token.balanceOf(await owner.getAddress()); await token .connect(owner) - .approve(await anotherAccount.getAddress(), senderBalance.add('99')) + .approve(await anotherAccount.getAddress(), senderBalance.add('99')); await expect( token .connect(anotherAccount) @@ -280,22 +283,25 @@ describe('Button:Elastic:transferAllFrom', () => { await owner.getAddress(), await anotherAccount.getAddress(), '99', - ) + ); expect( await token.allowance( await owner.getAddress(), await anotherAccount.getAddress(), ), - ).to.eq('99') - }) - }) + ).to.eq('99'); + }); + }); describe('when the spender has enough approved infinite balance', function () { it('emits a transfer event', async function () { - const senderBalance = await token.balanceOf(await owner.getAddress()) + const senderBalance = await token.balanceOf(await owner.getAddress()); await token .connect(owner) - .approve(await anotherAccount.getAddress(), ethers.constants.MaxUint256) + .approve( + await anotherAccount.getAddress(), + ethers.constants.MaxUint256, + ); await expect( token @@ -310,36 +316,45 @@ describe('Button:Elastic:transferAllFrom', () => { await owner.getAddress(), await recipient.getAddress(), senderBalance, - ) - }) + ); + }); it('transfers the requested amount', async function () { - const senderBalance = await token.balanceOf(await owner.getAddress()) + const senderBalance = await token.balanceOf(await owner.getAddress()); const recipientBalance = await token.balanceOf( await recipient.getAddress(), - ) + ); await token .connect(owner) - .approve(await anotherAccount.getAddress(), ethers.constants.MaxUint256) + .approve( + await anotherAccount.getAddress(), + ethers.constants.MaxUint256, + ); await token .connect(anotherAccount) - .transferAllFrom(await owner.getAddress(), await recipient.getAddress()) + .transferAllFrom( + await owner.getAddress(), + await recipient.getAddress(), + ); - const senderBalance_ = await token.balanceOf(await owner.getAddress()) + const senderBalance_ = await token.balanceOf(await owner.getAddress()); const recipientBalance_ = await token.balanceOf( await recipient.getAddress(), - ) - expect(senderBalance_).to.eq('0') - expect(recipientBalance_.sub(recipientBalance)).to.eq(senderBalance) - }) + ); + expect(senderBalance_).to.eq('0'); + expect(recipientBalance_.sub(recipientBalance)).to.eq(senderBalance); + }); it('does NOT decrease the spender allowance', async function () { - const senderBalance = await token.balanceOf(await owner.getAddress()) + const senderBalance = await token.balanceOf(await owner.getAddress()); await token .connect(owner) - .approve(await anotherAccount.getAddress(), ethers.constants.MaxUint256) + .approve( + await anotherAccount.getAddress(), + ethers.constants.MaxUint256, + ); await expect( token .connect(anotherAccount) @@ -347,13 +362,13 @@ describe('Button:Elastic:transferAllFrom', () => { await owner.getAddress(), await recipient.getAddress(), ), - ).not.to.emit(token, 'Approval') + ).not.to.emit(token, 'Approval'); expect( await token.allowance( await owner.getAddress(), await anotherAccount.getAddress(), ), - ).to.eq(ethers.constants.MaxUint256) - }) - }) -}) + ).to.eq(ethers.constants.MaxUint256); + }); + }); +}); diff --git a/test/unit/ChainlinkOracle.ts b/test/unit/ChainlinkOracle.ts index 6273ae5..7e64cd5 100644 --- a/test/unit/ChainlinkOracle.ts +++ b/test/unit/ChainlinkOracle.ts @@ -1,92 +1,92 @@ -import { ethers, waffle } from 'hardhat' -import { Contract, Signer } from 'ethers' -import { expect } from 'chai' -import { TransactionResponse } from '@ethersproject/providers' +import { ethers, waffle } from 'hardhat'; +import { Contract, Signer } from 'ethers'; +import { expect } from 'chai'; +import { TransactionResponse } from '@ethersproject/providers'; -let oracle: Contract, mockAggregator: Contract, oracleFetcher: Contract -let r: Promise -let deployer: Signer, user: Signer +let oracle: Contract, mockAggregator: Contract, oracleFetcher: Contract; +let r: Promise; +let deployer: Signer, user: Signer; async function mockedOracle() { - const [deployer, user] = await ethers.getSigners() + const [deployer, user] = await ethers.getSigners(); // deploy mocks const mockAggregator = await ( await ethers.getContractFactory('MockChainlinkAggregator') ) .connect(deployer) - .deploy(8) + .deploy(8); const oracle = await (await ethers.getContractFactory('ChainlinkOracle')) .connect(deployer) - .deploy(mockAggregator.address, 60000) + .deploy(mockAggregator.address, 60000); const oracleFetcher = await ( await ethers.getContractFactory('MockOracleDataFetcher') ) .connect(deployer) - .deploy(oracle.address) + .deploy(oracle.address); return { deployer, user, oracle, oracleFetcher, mockAggregator, - } + }; } describe('ChainlinkOracle', function () { before('setup Orchestrator contract', async () => { - ;({ deployer, user, oracle, oracleFetcher, mockAggregator } = - await waffle.loadFixture(mockedOracle)) - }) + ({ deployer, user, oracle, oracleFetcher, mockAggregator } = + await waffle.loadFixture(mockedOracle)); + }); describe('when sent ether', async function () { it('should reject', async function () { await expect(user.sendTransaction({ to: oracle.address, value: 1 })).to.be - .reverted - }) - }) + .reverted; + }); + }); describe('Fetching data', async function () { it('should fetch data', async function () { - const data = ethers.BigNumber.from('18923491321') + const data = ethers.BigNumber.from('18923491321'); await expect(mockAggregator.connect(user).setLatestAnswer(data)).to.not.be - .reverted + .reverted; await expect( mockAggregator .connect(user) .setUpdatedAt(Math.floor(new Date().valueOf() / 1000)), - ).to.not.be.reverted + ).to.not.be.reverted; // we use an oracle fetcher contract because, since the IOracle // interface getData function is writable, we can't fetch the response directly - const tx = await oracleFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [res, success] = await oracleFetcher.getData() + const tx = await oracleFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [res, success] = await oracleFetcher.getData(); - expect(res.toString()).to.eq(data.toString()) - expect(success).to.eq(true) - expect(receipt.gasUsed.toString()).to.equal('78860') - }) + expect(res.toString()).to.eq(data.toString()); + expect(success).to.eq(true); + expect(receipt.gasUsed.toString()).to.equal('78860'); + }); it('should fail with stale data', async function () { - const data = ethers.BigNumber.from('18923491321') + const data = ethers.BigNumber.from('18923491321'); await expect(mockAggregator.connect(user).setLatestAnswer(data)).to.not.be - .reverted + .reverted; await expect( mockAggregator .connect(user) .setUpdatedAt(Math.floor(new Date().valueOf() / 1000) - 100000), - ).to.not.be.reverted + ).to.not.be.reverted; - const tx = await oracleFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [res, success] = await oracleFetcher.getData() + const tx = await oracleFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [res, success] = await oracleFetcher.getData(); - expect(res.toString()).to.eq(data.toString()) - expect(success).to.eq(false) - expect(receipt.gasUsed.toString()).to.equal('37060') - }) - }) -}) + expect(res.toString()).to.eq(data.toString()); + expect(success).to.eq(false); + expect(receipt.gasUsed.toString()).to.equal('37060'); + }); + }); +}); diff --git a/test/unit/ETHxOracle.ts b/test/unit/ETHxOracle.ts index 113b963..111fc3a 100644 --- a/test/unit/ETHxOracle.ts +++ b/test/unit/ETHxOracle.ts @@ -1,25 +1,25 @@ -import { expect } from 'chai' -import { BigNumber } from 'ethers' -import { ethers, waffle } from 'hardhat' +import { expect } from 'chai'; +import { BigNumber } from 'ethers'; +import { ethers, waffle } from 'hardhat'; async function mockedOracle() { - const [deployer, user] = await ethers.getSigners() + const [deployer, user] = await ethers.getSigners(); // deploy mocks const mockStaderOracle = await ( await ethers.getContractFactory('MockStaderOracle') ) .connect(deployer) - .deploy() + .deploy(); // deploy contract to test const oracle = await (await ethers.getContractFactory('ETHxOracle')) .connect(deployer) - .deploy(mockStaderOracle.address) + .deploy(mockStaderOracle.address); // need a contract with a non-view method that calls oracle.getData so we can gas test const mockOracleDataFetcher = await ( await ethers.getContractFactory('MockOracleDataFetcher') ) .connect(deployer) - .deploy(oracle.address) + .deploy(oracle.address); return { deployer, @@ -27,42 +27,42 @@ async function mockedOracle() { mockStaderOracle, oracle, mockOracleDataFetcher, - } + }; } describe('ETHxOracle', function () { describe('when sent ether', async function () { it('should reject', async function () { - const { user, oracle } = await waffle.loadFixture(mockedOracle) + const { user, oracle } = await waffle.loadFixture(mockedOracle); await expect(user.sendTransaction({ to: oracle.address, value: 1 })).to.be - .reverted - }) - }) + .reverted; + }); + }); describe('Fetching data', async function () { it('should succeed with fresh data', async function () { const { user, mockStaderOracle, mockOracleDataFetcher } = - await waffle.loadFixture(mockedOracle) + await waffle.loadFixture(mockedOracle); await expect( mockStaderOracle .connect(user) .setTotalETHXSupply(BigNumber.from('6413278131285121422182816')), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockStaderOracle .connect(user) .setTotalETHBalance(BigNumber.from('7091831834635293267033248')), - ).to.not.be.reverted + ).to.not.be.reverted; - const tx = await mockOracleDataFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [value, valid] = await mockOracleDataFetcher.getData() + const tx = await mockOracleDataFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [value, valid] = await mockOracleDataFetcher.getData(); // ETHx denominated in ETH should be setTotalETHBalance/setTotalETHXSupply - expect(value.toString()).to.eq('1105804502698871756') - expect(valid).to.eq(true) - expect(receipt.gasUsed.toString()).to.equal('78935') - }) - }) -}) + expect(value.toString()).to.eq('1105804502698871756'); + expect(valid).to.eq(true); + expect(receipt.gasUsed.toString()).to.equal('78935'); + }); + }); +}); diff --git a/test/unit/GgAVAXOracle.ts b/test/unit/GgAVAXOracle.ts index 3b0a718..138301a 100644 --- a/test/unit/GgAVAXOracle.ts +++ b/test/unit/GgAVAXOracle.ts @@ -1,23 +1,23 @@ -import { expect } from 'chai' -import { BigNumber } from 'ethers' -import { ethers, waffle } from 'hardhat' +import { expect } from 'chai'; +import { BigNumber } from 'ethers'; +import { ethers, waffle } from 'hardhat'; async function mockedOracle() { - const [deployer, user] = await ethers.getSigners() + const [deployer, user] = await ethers.getSigners(); // deploy mocks const mockGgAVAX = await (await ethers.getContractFactory('MockGgAVAX')) .connect(deployer) - .deploy() + .deploy(); // deploy contract to test const oracle = await (await ethers.getContractFactory('GgAVAXOracle')) .connect(deployer) - .deploy(mockGgAVAX.address) + .deploy(mockGgAVAX.address); // need a contract with a non-view method that calls oracle.getData so we can gas test const mockOracleDataFetcher = await ( await ethers.getContractFactory('MockOracleDataFetcher') ) .connect(deployer) - .deploy(oracle.address) + .deploy(oracle.address); return { deployer, @@ -25,42 +25,42 @@ async function mockedOracle() { mockGgAVAX, oracle, mockOracleDataFetcher, - } + }; } describe('GgAvaxOracle', function () { describe('when sent ether', async function () { it('should reject', async function () { - const { user, oracle } = await waffle.loadFixture(mockedOracle) + const { user, oracle } = await waffle.loadFixture(mockedOracle); await expect(user.sendTransaction({ to: oracle.address, value: 1 })).to.be - .reverted - }) - }) + .reverted; + }); + }); describe('Fetching data', async function () { it('should succeed with fresh data', async function () { const { user, mockGgAVAX, mockOracleDataFetcher } = - await waffle.loadFixture(mockedOracle) + await waffle.loadFixture(mockedOracle); await expect( mockGgAVAX .connect(user) .setTotalShares(BigNumber.from('6413278131285121422182816')), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockGgAVAX .connect(user) .setTotalAssets(BigNumber.from('7091831834635293267033248')), - ).to.not.be.reverted + ).to.not.be.reverted; - const tx = await mockOracleDataFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [value, valid] = await mockOracleDataFetcher.getData() + const tx = await mockOracleDataFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [value, valid] = await mockOracleDataFetcher.getData(); // ggAVAX denominated in AVAX should be totalShares/totalAssets - expect(value.toString()).to.eq('1105804502698871756') - expect(valid).to.eq(true) - expect(receipt.gasUsed.toString()).to.equal('78579') - }) - }) -}) + expect(value.toString()).to.eq('1105804502698871756'); + expect(valid).to.eq(true); + expect(receipt.gasUsed.toString()).to.equal('78579'); + }); + }); +}); diff --git a/test/unit/InceptionTokenOracle.ts b/test/unit/InceptionTokenOracle.ts index 4d49498..e5e02dc 100644 --- a/test/unit/InceptionTokenOracle.ts +++ b/test/unit/InceptionTokenOracle.ts @@ -1,25 +1,25 @@ -import { expect } from 'chai' -import { BigNumber } from 'ethers' -import { ethers, waffle } from 'hardhat' +import { expect } from 'chai'; +import { BigNumber } from 'ethers'; +import { ethers, waffle } from 'hardhat'; async function mockedOracle() { - const [deployer, user] = await ethers.getSigners() + const [deployer, user] = await ethers.getSigners(); // deploy mocks const mockInceptionVault = await ( await ethers.getContractFactory('MockInceptionVault') ) .connect(deployer) - .deploy() + .deploy(); // deploy contract to test const oracle = await (await ethers.getContractFactory('InceptionTokenOracle')) .connect(deployer) - .deploy(mockInceptionVault.address) + .deploy(mockInceptionVault.address); // need a contract with a non-view method that calls oracle.getData so we can gas test const mockOracleDataFetcher = await ( await ethers.getContractFactory('MockOracleDataFetcher') ) .connect(deployer) - .deploy(oracle.address) + .deploy(oracle.address); return { deployer, @@ -27,68 +27,68 @@ async function mockedOracle() { mockInceptionVault, oracle, mockOracleDataFetcher, - } + }; } describe('InceptionTokenOracle', function () { describe('when sent ether', async function () { it('should reject', async function () { - const { user, oracle } = await waffle.loadFixture(mockedOracle) + const { user, oracle } = await waffle.loadFixture(mockedOracle); await expect(user.sendTransaction({ to: oracle.address, value: 1 })).to.be - .reverted - }) - }) + .reverted; + }); + }); describe('Fetching data', async function () { it('should succeed with fresh data', async function () { const { user, mockInceptionVault, mockOracleDataFetcher } = - await waffle.loadFixture(mockedOracle) + await waffle.loadFixture(mockedOracle); await expect( mockInceptionVault .connect(user) .setInceptionTokenSupply(BigNumber.from('6413278131285121422182816')), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockInceptionVault .connect(user) .setTotalDeposited(BigNumber.from('7091831834635293267033248')), - ).to.not.be.reverted + ).to.not.be.reverted; - const tx = await mockOracleDataFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [value, valid] = await mockOracleDataFetcher.getData() + const tx = await mockOracleDataFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [value, valid] = await mockOracleDataFetcher.getData(); // uniETH denominated in ETH should be ETHReserve/XETHAmount expect(value.toString()).to.be.closeTo( BigNumber.from('1105804502698871756'), BigNumber.from('1'), - ) - expect(valid).to.eq(true) - expect(receipt.gasUsed.toString()).to.equal('82168') - }) + ); + expect(valid).to.eq(true); + expect(receipt.gasUsed.toString()).to.equal('82168'); + }); it('should return 1:1 when inceptionToken-eth is empty', async function () { const { user, mockInceptionVault, mockOracleDataFetcher } = - await waffle.loadFixture(mockedOracle) + await waffle.loadFixture(mockedOracle); await expect( mockInceptionVault .connect(user) .setInceptionTokenSupply(BigNumber.from('0')), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockInceptionVault.connect(user).setTotalDeposited(BigNumber.from('0')), - ).to.not.be.reverted + ).to.not.be.reverted; - const tx = await mockOracleDataFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [value, valid] = await mockOracleDataFetcher.getData() + const tx = await mockOracleDataFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [value, valid] = await mockOracleDataFetcher.getData(); // uniETH denominated in ETH should be ETHReserve/XETHAmount - expect(value.toString()).to.eq('1000000000000000000') - expect(valid).to.eq(true) - expect(receipt.gasUsed.toString()).to.equal('79333') - }) - }) -}) + expect(value.toString()).to.eq('1000000000000000000'); + expect(valid).to.eq(true); + expect(receipt.gasUsed.toString()).to.equal('79333'); + }); + }); +}); diff --git a/test/unit/MevEthOracle.ts b/test/unit/MevEthOracle.ts index 2ba819f..fba4712 100644 --- a/test/unit/MevEthOracle.ts +++ b/test/unit/MevEthOracle.ts @@ -1,23 +1,23 @@ -import { expect } from 'chai' -import { BigNumber } from 'ethers' -import { ethers, waffle } from 'hardhat' +import { expect } from 'chai'; +import { BigNumber } from 'ethers'; +import { ethers, waffle } from 'hardhat'; async function mockedOracle() { - const [deployer, user] = await ethers.getSigners() + const [deployer, user] = await ethers.getSigners(); // deploy mocks const mockMevETH = await (await ethers.getContractFactory('MockMevETH')) .connect(deployer) - .deploy() + .deploy(); // deploy contract to test const oracle = await (await ethers.getContractFactory('MevEthOracle')) .connect(deployer) - .deploy(mockMevETH.address) + .deploy(mockMevETH.address); // need a contract with a non-view method that calls oracle.getData so we can gas test const mockOracleDataFetcher = await ( await ethers.getContractFactory('MockOracleDataFetcher') ) .connect(deployer) - .deploy(oracle.address) + .deploy(oracle.address); return { deployer, @@ -25,42 +25,42 @@ async function mockedOracle() { mockMevETH, oracle, mockOracleDataFetcher, - } + }; } describe('MevEthOracle', function () { describe('when sent ether', async function () { it('should reject', async function () { - const { user, oracle } = await waffle.loadFixture(mockedOracle) + const { user, oracle } = await waffle.loadFixture(mockedOracle); await expect(user.sendTransaction({ to: oracle.address, value: 1 })).to.be - .reverted - }) - }) + .reverted; + }); + }); describe('Fetching data', async function () { it('should succeed with fresh data', async function () { const { user, mockMevETH, mockOracleDataFetcher } = - await waffle.loadFixture(mockedOracle) + await waffle.loadFixture(mockedOracle); await expect( mockMevETH .connect(user) .setTotalShares(BigNumber.from('6413278131285121422182816')), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockMevETH .connect(user) .setTotalAssets(BigNumber.from('7091831834635293267033248')), - ).to.not.be.reverted + ).to.not.be.reverted; - const tx = await mockOracleDataFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [value, valid] = await mockOracleDataFetcher.getData() + const tx = await mockOracleDataFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [value, valid] = await mockOracleDataFetcher.getData(); // mevETH denominated in ETH should be totalShares/totalAssets - expect(value.toString()).to.eq('1105804502698871756') - expect(valid).to.eq(true) - expect(receipt.gasUsed.toString()).to.equal('78601') - }) - }) -}) + expect(value.toString()).to.eq('1105804502698871756'); + expect(valid).to.eq(true); + expect(receipt.gasUsed.toString()).to.equal('78601'); + }); + }); +}); diff --git a/test/unit/RSETHRateReceiverOracle.ts b/test/unit/RSETHRateReceiverOracle.ts index b4606be..a45e7a3 100644 --- a/test/unit/RSETHRateReceiverOracle.ts +++ b/test/unit/RSETHRateReceiverOracle.ts @@ -1,27 +1,27 @@ -import { expect } from 'chai' -import { BigNumber } from 'ethers' -import { ethers, waffle } from 'hardhat' +import { expect } from 'chai'; +import { BigNumber } from 'ethers'; +import { ethers, waffle } from 'hardhat'; async function mockedOracle() { - const [deployer, user] = await ethers.getSigners() + const [deployer, user] = await ethers.getSigners(); // deploy mocks const mockRSETHRateReceiver = await ( await ethers.getContractFactory('MockRSETHRateReceiver') ) .connect(deployer) - .deploy() + .deploy(); // deploy contract to test const oracle = await ( await ethers.getContractFactory('RSETHRateReceiverOracle') ) .connect(deployer) - .deploy(mockRSETHRateReceiver.address) + .deploy(mockRSETHRateReceiver.address); // need a contract with a non-view method that calls oracle.getData so we can gas test const mockOracleDataFetcher = await ( await ethers.getContractFactory('MockOracleDataFetcher') ) .connect(deployer) - .deploy(oracle.address) + .deploy(oracle.address); return { deployer, @@ -29,22 +29,22 @@ async function mockedOracle() { mockRSETHRateReceiver, oracle, mockOracleDataFetcher, - } + }; } describe('RSETHRateReceiverOracle', function () { describe('when sent ether', async function () { it('should reject', async function () { - const { user, oracle } = await waffle.loadFixture(mockedOracle) + const { user, oracle } = await waffle.loadFixture(mockedOracle); await expect(user.sendTransaction({ to: oracle.address, value: 1 })).to.be - .reverted - }) - }) + .reverted; + }); + }); describe('Fetching data', async function () { it('should succeed with fresh data', async function () { const { user, mockRSETHRateReceiver, mockOracleDataFetcher } = - await waffle.loadFixture(mockedOracle) + await waffle.loadFixture(mockedOracle); await expect( mockRSETHRateReceiver @@ -54,16 +54,16 @@ describe('RSETHRateReceiverOracle', function () { .mul('1000000000000000000') .div(BigNumber.from('6413278131285121422182816')), ), - ).to.not.be.reverted + ).to.not.be.reverted; - const tx = await mockOracleDataFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [value, valid] = await mockOracleDataFetcher.getData() + const tx = await mockOracleDataFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [value, valid] = await mockOracleDataFetcher.getData(); // rsETH denominated in ETH should be totalShares/totalAssets - expect(value.toString()).to.eq('1105804502698871756') - expect(valid).to.eq(true) - expect(receipt.gasUsed.toString()).to.equal('76245') - }) - }) -}) + expect(value.toString()).to.eq('1105804502698871756'); + expect(valid).to.eq(true); + expect(receipt.gasUsed.toString()).to.equal('76245'); + }); + }); +}); diff --git a/test/unit/SDaiOracle.ts b/test/unit/SDaiOracle.ts index 59cf456..3988ab0 100644 --- a/test/unit/SDaiOracle.ts +++ b/test/unit/SDaiOracle.ts @@ -1,23 +1,23 @@ -import { expect } from 'chai' -import { BigNumber } from 'ethers' -import { ethers, waffle } from 'hardhat' +import { expect } from 'chai'; +import { BigNumber } from 'ethers'; +import { ethers, waffle } from 'hardhat'; async function mockedOracle() { - const [deployer, user] = await ethers.getSigners() + const [deployer, user] = await ethers.getSigners(); // deploy mocks const mockSDAI = await (await ethers.getContractFactory('MockSDAI')) .connect(deployer) - .deploy() + .deploy(); // deploy contract to test const oracle = await (await ethers.getContractFactory('SDaiOracle')) .connect(deployer) - .deploy(mockSDAI.address) + .deploy(mockSDAI.address); // need a contract with a non-view method that calls oracle.getData so we can gas test const mockOracleDataFetcher = await ( await ethers.getContractFactory('MockOracleDataFetcher') ) .connect(deployer) - .deploy(oracle.address) + .deploy(oracle.address); return { deployer, @@ -25,42 +25,42 @@ async function mockedOracle() { mockSDAI, oracle, mockOracleDataFetcher, - } + }; } describe('SDaiOracle', function () { describe('when sent ether', async function () { it('should reject', async function () { - const { user, oracle } = await waffle.loadFixture(mockedOracle) + const { user, oracle } = await waffle.loadFixture(mockedOracle); await expect(user.sendTransaction({ to: oracle.address, value: 1 })).to.be - .reverted - }) - }) + .reverted; + }); + }); describe('Fetching data', async function () { it('should succeed with fresh data', async function () { const { user, mockSDAI, mockOracleDataFetcher } = - await waffle.loadFixture(mockedOracle) + await waffle.loadFixture(mockedOracle); await expect( mockSDAI .connect(user) .setTotalShares(BigNumber.from('6413278131285121422182816')), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockSDAI .connect(user) .setTotalAssets(BigNumber.from('7091831834635293267033248')), - ).to.not.be.reverted + ).to.not.be.reverted; - const tx = await mockOracleDataFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [value, valid] = await mockOracleDataFetcher.getData() + const tx = await mockOracleDataFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [value, valid] = await mockOracleDataFetcher.getData(); // swETH denominated in ETH should be totalETH/totalSwETH - expect(value.toString()).to.eq('1105804502698871756') - expect(valid).to.eq(true) - expect(receipt.gasUsed.toString()).to.equal('78579') - }) - }) -}) + expect(value.toString()).to.eq('1105804502698871756'); + expect(valid).to.eq(true); + expect(receipt.gasUsed.toString()).to.equal('78579'); + }); + }); +}); diff --git a/test/unit/SavaxOracle.ts b/test/unit/SavaxOracle.ts index be9c865..77da838 100644 --- a/test/unit/SavaxOracle.ts +++ b/test/unit/SavaxOracle.ts @@ -1,23 +1,23 @@ -import { expect } from 'chai' -import { BigNumber } from 'ethers' -import { ethers, waffle } from 'hardhat' +import { expect } from 'chai'; +import { BigNumber } from 'ethers'; +import { ethers, waffle } from 'hardhat'; async function mockedOracle() { - const [deployer, user] = await ethers.getSigners() + const [deployer, user] = await ethers.getSigners(); // deploy mocks const mockSavax = await (await ethers.getContractFactory('MockSAVAX')) .connect(deployer) - .deploy() + .deploy(); // deploy contract to test const oracle = await (await ethers.getContractFactory('SavaxOracle')) .connect(deployer) - .deploy(mockSavax.address) + .deploy(mockSavax.address); // need a contract with a non-view method that calls oracle.getData so we can gas test const mockOracleDataFetcher = await ( await ethers.getContractFactory('MockOracleDataFetcher') ) .connect(deployer) - .deploy(oracle.address) + .deploy(oracle.address); return { deployer, @@ -25,42 +25,42 @@ async function mockedOracle() { mockSavax, oracle, mockOracleDataFetcher, - } + }; } describe('SavaxOracle', function () { describe('when sent ether', async function () { it('should reject', async function () { - const { user, oracle } = await waffle.loadFixture(mockedOracle) + const { user, oracle } = await waffle.loadFixture(mockedOracle); await expect(user.sendTransaction({ to: oracle.address, value: 1 })).to.be - .reverted - }) - }) + .reverted; + }); + }); describe('Fetching data', async function () { it('should succeed with fresh data', async function () { const { user, mockSavax, mockOracleDataFetcher } = - await waffle.loadFixture(mockedOracle) + await waffle.loadFixture(mockedOracle); await expect( mockSavax .connect(user) .setTotalShares(BigNumber.from('6413278131285121422182816')), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockSavax .connect(user) .setTotalPooledAvax(BigNumber.from('7091831834635293267033248')), - ).to.not.be.reverted + ).to.not.be.reverted; - const tx = await mockOracleDataFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [value, valid] = await mockOracleDataFetcher.getData() + const tx = await mockOracleDataFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [value, valid] = await mockOracleDataFetcher.getData(); // sAVAX denominated in AVAX should be totalShares/totalPooledAVAX - expect(value.toString()).to.eq('1105804502698871756') - expect(valid).to.eq(true) - expect(receipt.gasUsed.toString()).to.equal('79029') - }) - }) -}) + expect(value.toString()).to.eq('1105804502698871756'); + expect(valid).to.eq(true); + expect(receipt.gasUsed.toString()).to.equal('79029'); + }); + }); +}); diff --git a/test/unit/SwETHOracle.ts b/test/unit/SwETHOracle.ts index acd5532..5b9995e 100644 --- a/test/unit/SwETHOracle.ts +++ b/test/unit/SwETHOracle.ts @@ -1,23 +1,23 @@ -import { expect } from 'chai' -import { BigNumber } from 'ethers' -import { ethers, waffle } from 'hardhat' +import { expect } from 'chai'; +import { BigNumber } from 'ethers'; +import { ethers, waffle } from 'hardhat'; async function mockedOracle() { - const [deployer, user] = await ethers.getSigners() + const [deployer, user] = await ethers.getSigners(); // deploy mocks const mockSwETH = await (await ethers.getContractFactory('MockSwETH')) .connect(deployer) - .deploy() + .deploy(); // deploy contract to test const oracle = await (await ethers.getContractFactory('SwETHOracle')) .connect(deployer) - .deploy(mockSwETH.address) + .deploy(mockSwETH.address); // need a contract with a non-view method that calls oracle.getData so we can gas test const mockOracleDataFetcher = await ( await ethers.getContractFactory('MockOracleDataFetcher') ) .connect(deployer) - .deploy(oracle.address) + .deploy(oracle.address); return { deployer, @@ -25,42 +25,42 @@ async function mockedOracle() { mockSwETH, oracle, mockOracleDataFetcher, - } + }; } describe('SwETHOracle', function () { describe('when sent ether', async function () { it('should reject', async function () { - const { user, oracle } = await waffle.loadFixture(mockedOracle) + const { user, oracle } = await waffle.loadFixture(mockedOracle); await expect(user.sendTransaction({ to: oracle.address, value: 1 })).to.be - .reverted - }) - }) + .reverted; + }); + }); describe('Fetching data', async function () { it('should succeed with fresh data', async function () { const { user, mockSwETH, mockOracleDataFetcher } = - await waffle.loadFixture(mockedOracle) + await waffle.loadFixture(mockedOracle); await expect( mockSwETH .connect(user) .setTotalSwETH(BigNumber.from('6413278131285121422182816')), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockSwETH .connect(user) .setTotalETH(BigNumber.from('7091831834635293267033248')), - ).to.not.be.reverted + ).to.not.be.reverted; - const tx = await mockOracleDataFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [value, valid] = await mockOracleDataFetcher.getData() + const tx = await mockOracleDataFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [value, valid] = await mockOracleDataFetcher.getData(); // swETH denominated in ETH should be totalETH/totalSwETH - expect(value.toString()).to.eq('1105804502698871756') - expect(valid).to.eq(true) - expect(receipt.gasUsed.toString()).to.equal('78589') - }) - }) -}) + expect(value.toString()).to.eq('1105804502698871756'); + expect(valid).to.eq(true); + expect(receipt.gasUsed.toString()).to.equal('78589'); + }); + }); +}); diff --git a/test/unit/UnbuttonToken.ts b/test/unit/UnbuttonToken.ts index eb2b811..92639dd 100644 --- a/test/unit/UnbuttonToken.ts +++ b/test/unit/UnbuttonToken.ts @@ -1,23 +1,23 @@ -import { ethers, upgrades } from 'hardhat' -import { Contract, Signer, BigNumber, BigNumberish } from 'ethers' -import { expect } from 'chai' +import { ethers, upgrades } from 'hardhat'; +import { Contract, Signer, BigNumber, BigNumberish } from 'ethers'; +import { expect } from 'chai'; -const PRICE_DECIMALS = 8 -const DECIMALS = 18 -const NAME = 'Unbutton Ampleforth' -const SYMBOL = 'UBTN-AMPL' +const PRICE_DECIMALS = 8; +const DECIMALS = 18; +const NAME = 'Unbutton Ampleforth'; +const SYMBOL = 'UBTN-AMPL'; const toOracleValue = (v: string): BigNumber => - ethers.utils.parseUnits(v, PRICE_DECIMALS) + ethers.utils.parseUnits(v, PRICE_DECIMALS); const toFixedPtAmt = (a: string): BigNumber => - ethers.utils.parseUnits(a, DECIMALS) + ethers.utils.parseUnits(a, DECIMALS); -const transferAmount = toFixedPtAmt('10') -const unitTokenAmount = toFixedPtAmt('1') +const transferAmount = toFixedPtAmt('10'); +const unitTokenAmount = toFixedPtAmt('1'); -const startingMultiplier = 10000 -const multiplierGranularity = 10000 +const startingMultiplier = 10000; +const multiplierGranularity = 10000; let accounts: Signer[], deployer: Signer, @@ -29,176 +29,176 @@ let accounts: Signer[], userC: Signer, userCAddress: string, mockAmpl: Contract, - unbuttonToken: Contract + unbuttonToken: Contract; async function setupContracts() { - accounts = await ethers.getSigners() - deployer = accounts[0] - userA = accounts[1] - userB = accounts[2] - userC = accounts[3] + accounts = await ethers.getSigners(); + deployer = accounts[0]; + userA = accounts[1]; + userB = accounts[2]; + userC = accounts[3]; - deployerAddress = await deployer.getAddress() - userAAddress = await userA.getAddress() - userBAddress = await userB.getAddress() - userCAddress = await userC.getAddress() + deployerAddress = await deployer.getAddress(); + userAAddress = await userA.getAddress(); + userBAddress = await userB.getAddress(); + userCAddress = await userC.getAddress(); const rebasingErc20Factory = await ethers.getContractFactory( 'MockRebasingERC20', - ) + ); mockAmpl = await rebasingErc20Factory.deploy( 'Ampleforth', 'AMPL', startingMultiplier, multiplierGranularity, - ) + ); - const unbuttonTokenFactory = await ethers.getContractFactory('UnbuttonToken') - unbuttonToken = await unbuttonTokenFactory.deploy() + const unbuttonTokenFactory = await ethers.getContractFactory('UnbuttonToken'); + unbuttonToken = await unbuttonTokenFactory.deploy(); - const initialDeposit = await unbuttonToken.INITIAL_DEPOSIT() - const initialRate = '1000000' - await mockAmpl.mint(deployerAddress, initialDeposit) - await mockAmpl.approve(unbuttonToken.address, initialDeposit) - await unbuttonToken.initialize(mockAmpl.address, NAME, SYMBOL, initialRate) + const initialDeposit = await unbuttonToken.INITIAL_DEPOSIT(); + const initialRate = '1000000'; + await mockAmpl.mint(deployerAddress, initialDeposit); + await mockAmpl.approve(unbuttonToken.address, initialDeposit); + await unbuttonToken.initialize(mockAmpl.address, NAME, SYMBOL, initialRate); } describe('UnbuttonToken', () => { - before('setup UnbuttonToken contract', setupContracts) + before('setup UnbuttonToken contract', setupContracts); it('should reject any ether sent to it', async function () { - const user = accounts[1] + const user = accounts[1]; await expect(user.sendTransaction({ to: unbuttonToken.address, value: 1 })) - .to.be.reverted - }) -}) + .to.be.reverted; + }); +}); describe('UnbuttonToken:Initialization', () => { - beforeEach('setup UnbuttonToken contract', setupContracts) + beforeEach('setup UnbuttonToken contract', setupContracts); it('should set the underlying reference', async function () { - expect(await unbuttonToken.underlying()).to.eq(mockAmpl.address) - }) + expect(await unbuttonToken.underlying()).to.eq(mockAmpl.address); + }); it('should set detailed erc20 info parameters', async function () { - expect(await unbuttonToken.name()).to.eq(NAME) - expect(await unbuttonToken.symbol()).to.eq(SYMBOL) - expect(await unbuttonToken.decimals()).to.eq(18) - }) + expect(await unbuttonToken.name()).to.eq(NAME); + expect(await unbuttonToken.symbol()).to.eq(SYMBOL); + expect(await unbuttonToken.decimals()).to.eq(18); + }); it('should set the erc20 balance and supply', async function () { - expect(await unbuttonToken.totalSupply()).to.eq('1000000000') + expect(await unbuttonToken.totalSupply()).to.eq('1000000000'); expect(await unbuttonToken.balanceOf(unbuttonToken.address)).to.eq( '1000000000', - ) - expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('0') - }) + ); + expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('0'); + }); it('should set the underlying balance and supply', async function () { - expect(await unbuttonToken.totalUnderlying()).to.eq('1000') + expect(await unbuttonToken.totalUnderlying()).to.eq('1000'); expect( await unbuttonToken.balanceOfUnderlying(unbuttonToken.address), - ).to.eq('1000') - expect(await unbuttonToken.balanceOfUnderlying(deployerAddress)).to.eq('0') - }) -}) + ).to.eq('1000'); + expect(await unbuttonToken.balanceOfUnderlying(deployerAddress)).to.eq('0'); + }); +}); describe('UnbuttonToken Invalid Deposit', () => { - beforeEach('setup UnbuttonToken contract', setupContracts) + beforeEach('setup UnbuttonToken contract', setupContracts); it('should fail to deposit negative amount', async function () { - await expect(unbuttonToken.deposit('-1')).to.be.reverted - }) + await expect(unbuttonToken.deposit('-1')).to.be.reverted; + }); it('should fail to deposit more than balance', async function () { - await mockAmpl.mint(deployerAddress, '500') - await mockAmpl.approve(unbuttonToken.address, '1000') - await expect(unbuttonToken.deposit('1000')).to.be.reverted - }) + await mockAmpl.mint(deployerAddress, '500'); + await mockAmpl.approve(unbuttonToken.address, '1000'); + await expect(unbuttonToken.deposit('1000')).to.be.reverted; + }); it('should fail to deposit more than allowed', async function () { - await mockAmpl.mint(deployerAddress, '1000') - await mockAmpl.approve(unbuttonToken.address, '500') - await expect(unbuttonToken.deposit('1000')).to.be.reverted - }) -}) + await mockAmpl.mint(deployerAddress, '1000'); + await mockAmpl.approve(unbuttonToken.address, '500'); + await expect(unbuttonToken.deposit('1000')).to.be.reverted; + }); +}); describe('UnbuttonToken Deposit', () => { - beforeEach('setup UnbuttonToken contract', setupContracts) + beforeEach('setup UnbuttonToken contract', setupContracts); describe('when the user deposits the smallest amount', async function () { - let r: any + let r: any; beforeEach(async function () { - await mockAmpl.mint(deployerAddress, '1') - await mockAmpl.approve(unbuttonToken.address, '1') - r = unbuttonToken.deposit('1') - await r - }) + await mockAmpl.mint(deployerAddress, '1'); + await mockAmpl.approve(unbuttonToken.address, '1'); + r = unbuttonToken.deposit('1'); + await r; + }); it('should mint tokens to the user', async function () { - expect(await unbuttonToken.totalSupply()).to.eq('1001000000') + expect(await unbuttonToken.totalSupply()).to.eq('1001000000'); expect(await unbuttonToken.balanceOf(unbuttonToken.address)).to.eq( '1000000000', - ) - expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('1000000') + ); + expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('1000000'); - expect(await unbuttonToken.totalUnderlying()).to.eq('1001') + expect(await unbuttonToken.totalUnderlying()).to.eq('1001'); expect( await unbuttonToken.balanceOfUnderlying(unbuttonToken.address), - ).to.eq('1000') + ).to.eq('1000'); expect(await unbuttonToken.balanceOfUnderlying(deployerAddress)).to.eq( '1', - ) - }) + ); + }); it('should log transfer', async function () { await expect(r) .to.emit(mockAmpl, 'Transfer') - .withArgs(deployerAddress, unbuttonToken.address, '1') - }) + .withArgs(deployerAddress, unbuttonToken.address, '1'); + }); it('should log mint', async function () { await expect(r) .to.emit(unbuttonToken, 'Transfer') - .withArgs(ethers.constants.AddressZero, deployerAddress, '1000000') - }) - }) + .withArgs(ethers.constants.AddressZero, deployerAddress, '1000000'); + }); + }); describe('when the user deposits a reasonable amount', async function () { - let r: any + let r: any; beforeEach(async function () { - await mockAmpl.mint(deployerAddress, '1000000000000') // 1000 AMPL - await mockAmpl.approve(unbuttonToken.address, '1000000000000') + await mockAmpl.mint(deployerAddress, '1000000000000'); // 1000 AMPL + await mockAmpl.approve(unbuttonToken.address, '1000000000000'); expect(await unbuttonToken.callStatic.deposit('1000000000000')).to.eq( '1000000000000000000', - ) - r = unbuttonToken.deposit('1000000000000') - await r - }) + ); + r = unbuttonToken.deposit('1000000000000'); + await r; + }); it('should mint tokens to the user', async function () { - expect(await unbuttonToken.totalSupply()).to.eq('1000000001000000000') + expect(await unbuttonToken.totalSupply()).to.eq('1000000001000000000'); expect(await unbuttonToken.balanceOf(unbuttonToken.address)).to.eq( '1000000000', - ) + ); expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq( '1000000000000000000', - ) + ); - expect(await unbuttonToken.totalUnderlying()).to.eq('1000000001000') + expect(await unbuttonToken.totalUnderlying()).to.eq('1000000001000'); expect( await unbuttonToken.balanceOfUnderlying(unbuttonToken.address), - ).to.eq('1000') + ).to.eq('1000'); expect(await unbuttonToken.balanceOfUnderlying(deployerAddress)).to.eq( '1000000000000', - ) - }) + ); + }); it('should log transfer', async function () { await expect(r) .to.emit(mockAmpl, 'Transfer') - .withArgs(deployerAddress, unbuttonToken.address, '1000000000000') - }) + .withArgs(deployerAddress, unbuttonToken.address, '1000000000000'); + }); it('should log mint', async function () { await expect(r) @@ -207,41 +207,41 @@ describe('UnbuttonToken Deposit', () => { ethers.constants.AddressZero, deployerAddress, '1000000000000000000', - ) - }) - }) -}) + ); + }); + }); +}); describe('UnbuttonToken DepositFor', () => { - beforeEach('setup UnbuttonToken contract', setupContracts) + beforeEach('setup UnbuttonToken contract', setupContracts); - let r: any + let r: any; beforeEach(async function () { - await mockAmpl.mint(deployerAddress, '1000000000000') // 1000 AMPL - await mockAmpl.approve(unbuttonToken.address, '1000000000000') + await mockAmpl.mint(deployerAddress, '1000000000000'); // 1000 AMPL + await mockAmpl.approve(unbuttonToken.address, '1000000000000'); expect( await unbuttonToken.callStatic.depositFor(userAAddress, '1000000000000'), - ).to.eq('1000000000000000000') - r = unbuttonToken.depositFor(userAAddress, '1000000000000') - await r - }) + ).to.eq('1000000000000000000'); + r = unbuttonToken.depositFor(userAAddress, '1000000000000'); + await r; + }); it('should mint tokens to the user', async function () { - expect(await unbuttonToken.totalSupply()).to.eq('1000000001000000000') + expect(await unbuttonToken.totalSupply()).to.eq('1000000001000000000'); expect(await unbuttonToken.balanceOf(userAAddress)).to.eq( '1000000000000000000', - ) - expect(await unbuttonToken.totalUnderlying()).to.eq('1000000001000') + ); + expect(await unbuttonToken.totalUnderlying()).to.eq('1000000001000'); expect(await unbuttonToken.balanceOfUnderlying(userAAddress)).to.eq( '1000000000000', - ) - }) + ); + }); it('should log transfer', async function () { await expect(r) .to.emit(mockAmpl, 'Transfer') - .withArgs(deployerAddress, unbuttonToken.address, '1000000000000') - }) + .withArgs(deployerAddress, unbuttonToken.address, '1000000000000'); + }); it('should log mint', async function () { await expect(r) @@ -250,196 +250,198 @@ describe('UnbuttonToken DepositFor', () => { ethers.constants.AddressZero, userAAddress, '1000000000000000000', - ) - }) -}) + ); + }); +}); describe('UnbuttonToken Withdrawal', () => { - beforeEach('setup UnbuttonToken contract', setupContracts) + beforeEach('setup UnbuttonToken contract', setupContracts); it('should fail to withdraw 0 tokens', async function () { - await expect(unbuttonToken.connect(userA).withdraw('0')).to.be.reverted - }) + await expect(unbuttonToken.connect(userA).withdraw('0')).to.be.reverted; + }); it('should fail to withdraw more than deposited', async function () { - await mockAmpl.mint(deployerAddress, '3000') - await mockAmpl.approve(unbuttonToken.address, '3000') - await unbuttonToken.deposit('3000') - await expect(unbuttonToken.connect(userA).withdraw('3001')).to.be.reverted - }) + await mockAmpl.mint(deployerAddress, '3000'); + await mockAmpl.approve(unbuttonToken.address, '3000'); + await unbuttonToken.deposit('3000'); + await expect(unbuttonToken.connect(userA).withdraw('3001')).to.be.reverted; + }); describe('correct amount', () => { - let r: any + let r: any; beforeEach(async function () { - await mockAmpl.mint(deployerAddress, '3000') - await mockAmpl.approve(unbuttonToken.address, '3000') - await unbuttonToken.deposit('3000') - expect(await unbuttonToken.callStatic.withdraw('500')).to.eq('500000000') - r = unbuttonToken.withdraw('500') - await r - }) + await mockAmpl.mint(deployerAddress, '3000'); + await mockAmpl.approve(unbuttonToken.address, '3000'); + await unbuttonToken.deposit('3000'); + expect(await unbuttonToken.callStatic.withdraw('500')).to.eq('500000000'); + r = unbuttonToken.withdraw('500'); + await r; + }); it('should withdraw correct amount of corresponding collateral', async function () { - expect(await unbuttonToken.totalSupply()).to.eq('3500000000') - expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('2500000000') - expect(await unbuttonToken.totalUnderlying()).to.eq('3500') + expect(await unbuttonToken.totalSupply()).to.eq('3500000000'); + expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq( + '2500000000', + ); + expect(await unbuttonToken.totalUnderlying()).to.eq('3500'); expect(await unbuttonToken.balanceOfUnderlying(deployerAddress)).to.eq( '2500', - ) - expect(await mockAmpl.balanceOf(deployerAddress)).to.eq('500') - }) + ); + expect(await mockAmpl.balanceOf(deployerAddress)).to.eq('500'); + }); it('should log transfer', async function () { await expect(r) .to.emit(mockAmpl, 'Transfer') - .withArgs(unbuttonToken.address, deployerAddress, '500') - }) + .withArgs(unbuttonToken.address, deployerAddress, '500'); + }); it('should log mint', async function () { await expect(r) .to.emit(unbuttonToken, 'Transfer') - .withArgs(deployerAddress, ethers.constants.AddressZero, '500000000') - }) - }) -}) + .withArgs(deployerAddress, ethers.constants.AddressZero, '500000000'); + }); + }); +}); describe('UnbuttonToken WithdrawTo', () => { - beforeEach('setup UnbuttonToken contract', setupContracts) + beforeEach('setup UnbuttonToken contract', setupContracts); - let r: any + let r: any; beforeEach(async function () { - await mockAmpl.mint(deployerAddress, '3000') - await mockAmpl.approve(unbuttonToken.address, '3000') - await unbuttonToken.deposit('3000') + await mockAmpl.mint(deployerAddress, '3000'); + await mockAmpl.approve(unbuttonToken.address, '3000'); + await unbuttonToken.deposit('3000'); expect( await unbuttonToken.callStatic.withdrawTo(userAAddress, '500'), - ).to.eq('500000000') - r = unbuttonToken.withdrawTo(userAAddress, '500') - await r - }) + ).to.eq('500000000'); + r = unbuttonToken.withdrawTo(userAAddress, '500'); + await r; + }); it('should withdraw correct amount of corresponding collateral', async function () { - expect(await unbuttonToken.totalSupply()).to.eq('3500000000') - expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('2500000000') - expect(await unbuttonToken.totalUnderlying()).to.eq('3500') + expect(await unbuttonToken.totalSupply()).to.eq('3500000000'); + expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('2500000000'); + expect(await unbuttonToken.totalUnderlying()).to.eq('3500'); expect(await unbuttonToken.balanceOfUnderlying(deployerAddress)).to.eq( '2500', - ) - expect(await mockAmpl.balanceOf(deployerAddress)).to.eq('0') - expect(await mockAmpl.balanceOf(userAAddress)).to.eq('500') - }) + ); + expect(await mockAmpl.balanceOf(deployerAddress)).to.eq('0'); + expect(await mockAmpl.balanceOf(userAAddress)).to.eq('500'); + }); it('should log transfer', async function () { await expect(r) .to.emit(mockAmpl, 'Transfer') - .withArgs(unbuttonToken.address, userAAddress, '500') - }) + .withArgs(unbuttonToken.address, userAAddress, '500'); + }); it('should log mint', async function () { await expect(r) .to.emit(unbuttonToken, 'Transfer') - .withArgs(deployerAddress, ethers.constants.AddressZero, '500000000') - }) -}) + .withArgs(deployerAddress, ethers.constants.AddressZero, '500000000'); + }); +}); describe('UnbuttonToken WithdrawalAll', () => { - let r: any + let r: any; beforeEach('setup UnbuttonToken contract', async function () { - await setupContracts() + await setupContracts(); - await mockAmpl.mint(deployerAddress, '3000') - await mockAmpl.approve(unbuttonToken.address, '3000') - await unbuttonToken.deposit('3000') + await mockAmpl.mint(deployerAddress, '3000'); + await mockAmpl.approve(unbuttonToken.address, '3000'); + await unbuttonToken.deposit('3000'); - expect(await unbuttonToken.callStatic.withdrawAll()).to.eq('3000000000') - r = unbuttonToken.withdrawAll() - await r - }) + expect(await unbuttonToken.callStatic.withdrawAll()).to.eq('3000000000'); + r = unbuttonToken.withdrawAll(); + await r; + }); it('should fail to withdraw if balance is 0', async function () { - expect(await unbuttonToken.balanceOf(userBAddress)).to.eq('0') - await expect(unbuttonToken.connect(userB).withdrawAll()).to.be.reverted - }) + expect(await unbuttonToken.balanceOf(userBAddress)).to.eq('0'); + await expect(unbuttonToken.connect(userB).withdrawAll()).to.be.reverted; + }); it('should withdraw correct amount of corresponding collateral', async function () { - expect(await unbuttonToken.totalSupply()).to.eq('1000000000') - expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('0') - expect(await unbuttonToken.totalUnderlying()).to.eq('1000') - expect(await unbuttonToken.balanceOfUnderlying(deployerAddress)).to.eq('0') - expect(await mockAmpl.balanceOf(deployerAddress)).to.eq('3000') - }) + expect(await unbuttonToken.totalSupply()).to.eq('1000000000'); + expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('0'); + expect(await unbuttonToken.totalUnderlying()).to.eq('1000'); + expect(await unbuttonToken.balanceOfUnderlying(deployerAddress)).to.eq('0'); + expect(await mockAmpl.balanceOf(deployerAddress)).to.eq('3000'); + }); it('should log transfer', async function () { await expect(r) .to.emit(mockAmpl, 'Transfer') - .withArgs(unbuttonToken.address, deployerAddress, '3000') - }) + .withArgs(unbuttonToken.address, deployerAddress, '3000'); + }); it('should log mint', async function () { await expect(r) .to.emit(unbuttonToken, 'Transfer') - .withArgs(deployerAddress, ethers.constants.AddressZero, '3000000000') - }) -}) + .withArgs(deployerAddress, ethers.constants.AddressZero, '3000000000'); + }); +}); describe('UnbuttonToken WithdrawalAllTo', () => { - let r: any + let r: any; beforeEach('setup UnbuttonToken contract', async function () { - await setupContracts() + await setupContracts(); - await mockAmpl.mint(deployerAddress, '3000') - await mockAmpl.approve(unbuttonToken.address, '3000') - await unbuttonToken.deposit('3000') + await mockAmpl.mint(deployerAddress, '3000'); + await mockAmpl.approve(unbuttonToken.address, '3000'); + await unbuttonToken.deposit('3000'); expect(await unbuttonToken.callStatic.withdrawAllTo(userAAddress)).to.eq( '3000000000', - ) - r = unbuttonToken.withdrawAllTo(userAAddress) - await r - }) + ); + r = unbuttonToken.withdrawAllTo(userAAddress); + await r; + }); it('should withdraw correct amount of corresponding collateral', async function () { - expect(await unbuttonToken.totalSupply()).to.eq('1000000000') - expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('0') - expect(await unbuttonToken.totalUnderlying()).to.eq('1000') - expect(await unbuttonToken.balanceOfUnderlying(deployerAddress)).to.eq('0') - expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('0') - expect(await mockAmpl.balanceOf(userAAddress)).to.eq('3000') - }) + expect(await unbuttonToken.totalSupply()).to.eq('1000000000'); + expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('0'); + expect(await unbuttonToken.totalUnderlying()).to.eq('1000'); + expect(await unbuttonToken.balanceOfUnderlying(deployerAddress)).to.eq('0'); + expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('0'); + expect(await mockAmpl.balanceOf(userAAddress)).to.eq('3000'); + }); it('should log transfer', async function () { await expect(r) .to.emit(mockAmpl, 'Transfer') - .withArgs(unbuttonToken.address, userAAddress, '3000') - }) + .withArgs(unbuttonToken.address, userAAddress, '3000'); + }); it('should log mint', async function () { await expect(r) .to.emit(unbuttonToken, 'Transfer') - .withArgs(deployerAddress, ethers.constants.AddressZero, '3000000000') - }) -}) + .withArgs(deployerAddress, ethers.constants.AddressZero, '3000000000'); + }); +}); describe('UnbuttonToken Mint', () => { - beforeEach('setup UnbuttonToken contract', setupContracts) + beforeEach('setup UnbuttonToken contract', setupContracts); - let r: any + let r: any; beforeEach(async function () { - await mockAmpl.mint(deployerAddress, '1000000000000') // 1000 AMPL - await mockAmpl.approve(unbuttonToken.address, '1000000000000') + await mockAmpl.mint(deployerAddress, '1000000000000'); // 1000 AMPL + await mockAmpl.approve(unbuttonToken.address, '1000000000000'); expect(await unbuttonToken.callStatic.mint('1000000000000000000')).to.eq( '1000000000000', - ) - r = unbuttonToken.mint('1000000000000000000') - await r - }) + ); + r = unbuttonToken.mint('1000000000000000000'); + await r; + }); it('should mint tokens to the user', async function () { - expect(await unbuttonToken.totalSupply()).to.eq('1000000001000000000') + expect(await unbuttonToken.totalSupply()).to.eq('1000000001000000000'); expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq( '1000000000000000000', - ) - expect(await unbuttonToken.totalUnderlying()).to.eq('1000000001000') + ); + expect(await unbuttonToken.totalUnderlying()).to.eq('1000000001000'); expect(await unbuttonToken.balanceOfUnderlying(deployerAddress)).to.eq( '1000000000000', - ) - }) + ); + }); it('should log transfer', async function () { await expect(r) .to.emit(mockAmpl, 'Transfer') - .withArgs(deployerAddress, unbuttonToken.address, '1000000000000') - }) + .withArgs(deployerAddress, unbuttonToken.address, '1000000000000'); + }); it('should log mint', async function () { await expect(r) @@ -448,44 +450,44 @@ describe('UnbuttonToken Mint', () => { ethers.constants.AddressZero, deployerAddress, '1000000000000000000', - ) - }) -}) + ); + }); +}); describe('UnbuttonToken MintFor', () => { - beforeEach('setup UnbuttonToken contract', setupContracts) + beforeEach('setup UnbuttonToken contract', setupContracts); describe('when the user deposits a reasonable amount', async function () { - let r: any + let r: any; beforeEach(async function () { - await mockAmpl.mint(deployerAddress, '1000000000000') // 1000 AMPL - await mockAmpl.approve(unbuttonToken.address, '1000000000000') + await mockAmpl.mint(deployerAddress, '1000000000000'); // 1000 AMPL + await mockAmpl.approve(unbuttonToken.address, '1000000000000'); expect( await unbuttonToken.callStatic.mintFor( userAAddress, '1000000000000000000', ), - ).to.eq('1000000000000') - r = unbuttonToken.mintFor(userAAddress, '1000000000000000000') - await r - }) + ).to.eq('1000000000000'); + r = unbuttonToken.mintFor(userAAddress, '1000000000000000000'); + await r; + }); it('should mint tokens to the user', async function () { - expect(await unbuttonToken.totalSupply()).to.eq('1000000001000000000') + expect(await unbuttonToken.totalSupply()).to.eq('1000000001000000000'); expect(await unbuttonToken.balanceOf(userAAddress)).to.eq( '1000000000000000000', - ) - expect(await unbuttonToken.totalUnderlying()).to.eq('1000000001000') + ); + expect(await unbuttonToken.totalUnderlying()).to.eq('1000000001000'); expect(await unbuttonToken.balanceOfUnderlying(userAAddress)).to.eq( '1000000000000', - ) - }) + ); + }); it('should log transfer', async function () { await expect(r) .to.emit(mockAmpl, 'Transfer') - .withArgs(deployerAddress, unbuttonToken.address, '1000000000000') - }) + .withArgs(deployerAddress, unbuttonToken.address, '1000000000000'); + }); it('should log mint', async function () { await expect(r) @@ -494,189 +496,191 @@ describe('UnbuttonToken MintFor', () => { ethers.constants.AddressZero, userAAddress, '1000000000000000000', - ) - }) - }) -}) + ); + }); + }); +}); describe('UnbuttonToken Burn', () => { - beforeEach('setup UnbuttonToken contract', setupContracts) + beforeEach('setup UnbuttonToken contract', setupContracts); - let r: any + let r: any; beforeEach(async function () { - await mockAmpl.mint(deployerAddress, '3000') - await mockAmpl.approve(unbuttonToken.address, '3000') - await unbuttonToken.deposit('3000') - expect(await unbuttonToken.callStatic.burn('500000000')).to.eq('500') - r = unbuttonToken.burn('500000000') - await r - }) + await mockAmpl.mint(deployerAddress, '3000'); + await mockAmpl.approve(unbuttonToken.address, '3000'); + await unbuttonToken.deposit('3000'); + expect(await unbuttonToken.callStatic.burn('500000000')).to.eq('500'); + r = unbuttonToken.burn('500000000'); + await r; + }); it('should withdraw correct amount of corresponding collateral', async function () { - expect(await unbuttonToken.totalSupply()).to.eq('3500000000') - expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('2500000000') - expect(await unbuttonToken.totalUnderlying()).to.eq('3500') + expect(await unbuttonToken.totalSupply()).to.eq('3500000000'); + expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('2500000000'); + expect(await unbuttonToken.totalUnderlying()).to.eq('3500'); expect(await unbuttonToken.balanceOfUnderlying(deployerAddress)).to.eq( '2500', - ) - expect(await mockAmpl.balanceOf(deployerAddress)).to.eq('500') - }) + ); + expect(await mockAmpl.balanceOf(deployerAddress)).to.eq('500'); + }); it('should log transfer', async function () { await expect(r) .to.emit(mockAmpl, 'Transfer') - .withArgs(unbuttonToken.address, deployerAddress, '500') - }) + .withArgs(unbuttonToken.address, deployerAddress, '500'); + }); it('should log mint', async function () { await expect(r) .to.emit(unbuttonToken, 'Transfer') - .withArgs(deployerAddress, ethers.constants.AddressZero, '500000000') - }) -}) + .withArgs(deployerAddress, ethers.constants.AddressZero, '500000000'); + }); +}); describe('UnbuttonToken BurnTo', () => { - beforeEach('setup UnbuttonToken contract', setupContracts) + beforeEach('setup UnbuttonToken contract', setupContracts); - let r: any + let r: any; beforeEach(async function () { - await mockAmpl.mint(deployerAddress, '3000') - await mockAmpl.approve(unbuttonToken.address, '3000') - await unbuttonToken.deposit('3000') + await mockAmpl.mint(deployerAddress, '3000'); + await mockAmpl.approve(unbuttonToken.address, '3000'); + await unbuttonToken.deposit('3000'); expect( await unbuttonToken.callStatic.burnTo(userAAddress, '500000000'), - ).to.eq('500') - r = unbuttonToken.burnTo(userAAddress, '500000000') - await r - }) + ).to.eq('500'); + r = unbuttonToken.burnTo(userAAddress, '500000000'); + await r; + }); it('should withdraw correct amount of corresponding collateral', async function () { - expect(await unbuttonToken.totalSupply()).to.eq('3500000000') - expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('2500000000') - expect(await unbuttonToken.totalUnderlying()).to.eq('3500') + expect(await unbuttonToken.totalSupply()).to.eq('3500000000'); + expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('2500000000'); + expect(await unbuttonToken.totalUnderlying()).to.eq('3500'); expect(await unbuttonToken.balanceOfUnderlying(deployerAddress)).to.eq( '2500', - ) - expect(await mockAmpl.balanceOf(deployerAddress)).to.eq('0') - expect(await mockAmpl.balanceOf(userAAddress)).to.eq('500') - }) + ); + expect(await mockAmpl.balanceOf(deployerAddress)).to.eq('0'); + expect(await mockAmpl.balanceOf(userAAddress)).to.eq('500'); + }); it('should log transfer', async function () { await expect(r) .to.emit(mockAmpl, 'Transfer') - .withArgs(unbuttonToken.address, userAAddress, '500') - }) + .withArgs(unbuttonToken.address, userAAddress, '500'); + }); it('should log mint', async function () { await expect(r) .to.emit(unbuttonToken, 'Transfer') - .withArgs(deployerAddress, ethers.constants.AddressZero, '500000000') - }) -}) + .withArgs(deployerAddress, ethers.constants.AddressZero, '500000000'); + }); +}); describe('UnbuttonToken BurnAll', () => { - let r: any + let r: any; beforeEach('setup UnbuttonToken contract', async function () { - await setupContracts() + await setupContracts(); - await mockAmpl.mint(deployerAddress, '3000') - await mockAmpl.approve(unbuttonToken.address, '3000') - await unbuttonToken.deposit('3000') - expect(await unbuttonToken.callStatic.burnAll()).to.eq('3000') - r = unbuttonToken.burnAll() - await r - }) + await mockAmpl.mint(deployerAddress, '3000'); + await mockAmpl.approve(unbuttonToken.address, '3000'); + await unbuttonToken.deposit('3000'); + expect(await unbuttonToken.callStatic.burnAll()).to.eq('3000'); + r = unbuttonToken.burnAll(); + await r; + }); it('should withdraw correct amount of corresponding collateral', async function () { - expect(await unbuttonToken.totalSupply()).to.eq('1000000000') - expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('0') - expect(await unbuttonToken.totalUnderlying()).to.eq('1000') - expect(await unbuttonToken.balanceOfUnderlying(deployerAddress)).to.eq('0') - expect(await mockAmpl.balanceOf(deployerAddress)).to.eq('3000') - }) + expect(await unbuttonToken.totalSupply()).to.eq('1000000000'); + expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('0'); + expect(await unbuttonToken.totalUnderlying()).to.eq('1000'); + expect(await unbuttonToken.balanceOfUnderlying(deployerAddress)).to.eq('0'); + expect(await mockAmpl.balanceOf(deployerAddress)).to.eq('3000'); + }); it('should log transfer', async function () { await expect(r) .to.emit(mockAmpl, 'Transfer') - .withArgs(unbuttonToken.address, deployerAddress, '3000') - }) + .withArgs(unbuttonToken.address, deployerAddress, '3000'); + }); it('should log mint', async function () { await expect(r) .to.emit(unbuttonToken, 'Transfer') - .withArgs(deployerAddress, ethers.constants.AddressZero, '3000000000') - }) -}) + .withArgs(deployerAddress, ethers.constants.AddressZero, '3000000000'); + }); +}); describe('UnbuttonToken BurnAllTo', () => { - let r: any + let r: any; beforeEach('setup UnbuttonToken contract', async function () { - await setupContracts() - - await mockAmpl.mint(deployerAddress, '3000') - await mockAmpl.approve(unbuttonToken.address, '3000') - await unbuttonToken.deposit('3000') - expect(await unbuttonToken.callStatic.burnAllTo(userAAddress)).to.eq('3000') - r = unbuttonToken.burnAllTo(userAAddress) - await r - }) + await setupContracts(); + + await mockAmpl.mint(deployerAddress, '3000'); + await mockAmpl.approve(unbuttonToken.address, '3000'); + await unbuttonToken.deposit('3000'); + expect(await unbuttonToken.callStatic.burnAllTo(userAAddress)).to.eq( + '3000', + ); + r = unbuttonToken.burnAllTo(userAAddress); + await r; + }); it('should withdraw correct amount of corresponding collateral', async function () { - expect(await unbuttonToken.totalSupply()).to.eq('1000000000') - expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('0') - expect(await unbuttonToken.totalUnderlying()).to.eq('1000') - expect(await unbuttonToken.balanceOfUnderlying(deployerAddress)).to.eq('0') - expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('0') - expect(await mockAmpl.balanceOf(userAAddress)).to.eq('3000') - }) + expect(await unbuttonToken.totalSupply()).to.eq('1000000000'); + expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('0'); + expect(await unbuttonToken.totalUnderlying()).to.eq('1000'); + expect(await unbuttonToken.balanceOfUnderlying(deployerAddress)).to.eq('0'); + expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('0'); + expect(await mockAmpl.balanceOf(userAAddress)).to.eq('3000'); + }); it('should log transfer', async function () { await expect(r) .to.emit(mockAmpl, 'Transfer') - .withArgs(unbuttonToken.address, userAAddress, '3000') - }) + .withArgs(unbuttonToken.address, userAAddress, '3000'); + }); it('should log mint', async function () { await expect(r) .to.emit(unbuttonToken, 'Transfer') - .withArgs(deployerAddress, ethers.constants.AddressZero, '3000000000') - }) -}) + .withArgs(deployerAddress, ethers.constants.AddressZero, '3000000000'); + }); +}); describe('UnbuttonToken:Contraction', () => { - beforeEach('setup UnbuttonToken contract', setupContracts) + beforeEach('setup UnbuttonToken contract', setupContracts); it('should see deposited erc20 balance shrink', async function () { - await mockAmpl.mint(deployerAddress, '2000') - await mockAmpl.approve(unbuttonToken.address, '2000') - await unbuttonToken.deposit('2000') - expect(await unbuttonToken.totalSupply()).to.eq('3000000000') - expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('2000000000') - expect(await unbuttonToken.totalUnderlying()).to.eq('3000') + await mockAmpl.mint(deployerAddress, '2000'); + await mockAmpl.approve(unbuttonToken.address, '2000'); + await unbuttonToken.deposit('2000'); + expect(await unbuttonToken.totalSupply()).to.eq('3000000000'); + expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('2000000000'); + expect(await unbuttonToken.totalUnderlying()).to.eq('3000'); expect(await unbuttonToken.balanceOfUnderlying(deployerAddress)).to.eq( '2000', - ) + ); - await mockAmpl.rebase(startingMultiplier / 2) - expect(await unbuttonToken.totalSupply()).to.eq('3000000000') - expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('2000000000') - expect(await unbuttonToken.totalUnderlying()).to.eq('1500') + await mockAmpl.rebase(startingMultiplier / 2); + expect(await unbuttonToken.totalSupply()).to.eq('3000000000'); + expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('2000000000'); + expect(await unbuttonToken.totalUnderlying()).to.eq('1500'); expect(await unbuttonToken.balanceOfUnderlying(deployerAddress)).to.eq( '1000', - ) - }) -}) + ); + }); +}); describe('UnbuttonToken:Expansion', () => { - beforeEach('setup UnbuttonToken contract', setupContracts) + beforeEach('setup UnbuttonToken contract', setupContracts); it('should see deposited erc20 balance grow', async function () { - await mockAmpl.mint(deployerAddress, '2000') - await mockAmpl.approve(unbuttonToken.address, '2000') - await unbuttonToken.deposit('2000') - expect(await unbuttonToken.totalSupply()).to.eq('3000000000') - expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('2000000000') - expect(await unbuttonToken.totalUnderlying()).to.eq('3000') + await mockAmpl.mint(deployerAddress, '2000'); + await mockAmpl.approve(unbuttonToken.address, '2000'); + await unbuttonToken.deposit('2000'); + expect(await unbuttonToken.totalSupply()).to.eq('3000000000'); + expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('2000000000'); + expect(await unbuttonToken.totalUnderlying()).to.eq('3000'); expect(await unbuttonToken.balanceOfUnderlying(deployerAddress)).to.eq( '2000', - ) + ); - await mockAmpl.rebase(startingMultiplier * 3) - expect(await unbuttonToken.totalSupply()).to.eq('3000000000') - expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('2000000000') - expect(await unbuttonToken.totalUnderlying()).to.eq('9000') + await mockAmpl.rebase(startingMultiplier * 3); + expect(await unbuttonToken.totalSupply()).to.eq('3000000000'); + expect(await unbuttonToken.balanceOf(deployerAddress)).to.eq('2000000000'); + expect(await unbuttonToken.totalUnderlying()).to.eq('9000'); expect(await unbuttonToken.balanceOfUnderlying(deployerAddress)).to.eq( '6000', - ) - }) -}) + ); + }); +}); diff --git a/test/unit/UnbuttonTokenFactory.ts b/test/unit/UnbuttonTokenFactory.ts index 0f9f163..124c1ce 100644 --- a/test/unit/UnbuttonTokenFactory.ts +++ b/test/unit/UnbuttonTokenFactory.ts @@ -1,9 +1,9 @@ -import { ethers } from 'hardhat' -import { Contract, Signer, BigNumber, BigNumberish } from 'ethers' -import { expect } from 'chai' +import { ethers } from 'hardhat'; +import { Contract, Signer, BigNumber, BigNumberish } from 'ethers'; +import { expect } from 'chai'; -const startingMultiplier = 10000 -const multiplierGranularity = 10000 +const startingMultiplier = 10000; +const multiplierGranularity = 10000; let accounts: Signer[], deployer: Signer, @@ -18,7 +18,7 @@ let accounts: Signer[], template: Contract, factory: Contract, initialDeposit: BigNumberish, - initialRate: BigNumber + initialRate: BigNumber; async function createInstance( factory: Contract, @@ -30,156 +30,156 @@ async function createInstance( const args = ethers.utils.defaultAbiCoder.encode( ['address', 'string', 'string', 'uint256'], [underlying, name, symbol, initialRate], - ) - const instanceAddress = await factory.callStatic['create(bytes)'](args) - await factory['create(bytes)'](args) + ); + const instanceAddress = await factory.callStatic['create(bytes)'](args); + await factory['create(bytes)'](args); const instance = (await ethers.getContractFactory('UnbuttonToken')) .connect(deployer) - .attach(instanceAddress) - return instance + .attach(instanceAddress); + return instance; } async function setupContracts() { - accounts = await ethers.getSigners() - deployer = accounts[0] - userA = accounts[1] - userB = accounts[2] - userC = accounts[3] + accounts = await ethers.getSigners(); + deployer = accounts[0]; + userA = accounts[1]; + userB = accounts[2]; + userC = accounts[3]; - deployerAddress = await deployer.getAddress() - userAAddress = await userA.getAddress() - userBAddress = await userB.getAddress() - userCAddress = await userC.getAddress() + deployerAddress = await deployer.getAddress(); + userAAddress = await userA.getAddress(); + userBAddress = await userB.getAddress(); + userCAddress = await userC.getAddress(); - const AMPL_TOTAL_SUPPLY = '50000000000000000' // 50m AMPL - const MAX_SUPPLY = '10000000000000000000000000' // 10m unbutton tokens - initialDeposit = '1000' + const AMPL_TOTAL_SUPPLY = '50000000000000000'; // 50m AMPL + const MAX_SUPPLY = '10000000000000000000000000'; // 10m unbutton tokens + initialDeposit = '1000'; const rebasingErc20ContractFactory = await ethers.getContractFactory( 'MockRebasingERC20', - ) + ); mockAmpl = await rebasingErc20ContractFactory .connect(deployer) - .deploy('Ampleforth', 'AMPL', startingMultiplier, multiplierGranularity) - await mockAmpl.mint(deployerAddress, AMPL_TOTAL_SUPPLY) + .deploy('Ampleforth', 'AMPL', startingMultiplier, multiplierGranularity); + await mockAmpl.mint(deployerAddress, AMPL_TOTAL_SUPPLY); const unbuttonTokenContractFactory = await ethers.getContractFactory( 'UnbuttonToken', - ) - template = await unbuttonTokenContractFactory.connect(deployer).deploy() + ); + template = await unbuttonTokenContractFactory.connect(deployer).deploy(); factory = await (await ethers.getContractFactory('UnbuttonTokenFactory')) .connect(deployer) - .deploy(template.address) + .deploy(template.address); - initialRate = BigNumber.from('1').mul(MAX_SUPPLY).div(AMPL_TOTAL_SUPPLY) + initialRate = BigNumber.from('1').mul(MAX_SUPPLY).div(AMPL_TOTAL_SUPPLY); } describe('UnbuttonTokenFactory', () => { - before('setup UnbuttonTokenFactory contract', setupContracts) + before('setup UnbuttonTokenFactory contract', setupContracts); it('should reject any ether sent to it', async function () { - const user = accounts[1] + const user = accounts[1]; await expect(user.sendTransaction({ to: factory.address, value: 1 })).to.be - .reverted - }) -}) + .reverted; + }); +}); describe('UnbuttonToken:Initialization', () => { - beforeEach('setup UnbuttonTokenFactory contract', setupContracts) + beforeEach('setup UnbuttonTokenFactory contract', setupContracts); it('should set the correct template reference', async function () { - expect(await factory.template()).to.eq(template.address) - expect(await factory.instanceCount()).to.eq(0) - }) -}) + expect(await factory.template()).to.eq(template.address); + expect(await factory.instanceCount()).to.eq(0); + }); +}); describe('UnbuttonToken:create', () => { - beforeEach('setup UnbuttonTokenFactory contract', setupContracts) + beforeEach('setup UnbuttonTokenFactory contract', setupContracts); it('Clone should have proper parameters set', async function () { - await mockAmpl.approve(factory.address, await template.INITIAL_DEPOSIT()) + await mockAmpl.approve(factory.address, await template.INITIAL_DEPOSIT()); const ubToken = await createInstance( factory, mockAmpl.address, 'UNBUTTON-Ampleforth', 'UNBUTTON-AMPL', initialRate, - ) + ); - expect(await ubToken.underlying()).to.eq(mockAmpl.address) - expect(await ubToken.name()).to.eq('UNBUTTON-Ampleforth') - expect(await ubToken.symbol()).to.eq('UNBUTTON-AMPL') - expect(await ubToken.totalSupply()).to.eq(initialRate.mul(initialDeposit)) - expect(await ubToken.totalUnderlying()).to.eq('1000') - }) + expect(await ubToken.underlying()).to.eq(mockAmpl.address); + expect(await ubToken.name()).to.eq('UNBUTTON-Ampleforth'); + expect(await ubToken.symbol()).to.eq('UNBUTTON-AMPL'); + expect(await ubToken.totalSupply()).to.eq(initialRate.mul(initialDeposit)); + expect(await ubToken.totalUnderlying()).to.eq('1000'); + }); it('Unpacked args should run with correct values', async function () { - await mockAmpl.approve(factory.address, await template.INITIAL_DEPOSIT()) + await mockAmpl.approve(factory.address, await template.INITIAL_DEPOSIT()); const instanceAddress = await factory.callStatic[ 'create(address,string,string,uint256)' - ](mockAmpl.address, 'UNBUTTON-Ampleforth', 'UNBUTTON-AMPL', initialRate) + ](mockAmpl.address, 'UNBUTTON-Ampleforth', 'UNBUTTON-AMPL', initialRate); await factory['create(address,string,string,uint256)']( mockAmpl.address, 'UNBUTTON-Ampleforth', 'UNBUTTON-AMPL', initialRate, - ) + ); const ubToken = (await ethers.getContractFactory('UnbuttonToken')) .connect(deployer) - .attach(instanceAddress) - expect(await ubToken.underlying()).to.eq(mockAmpl.address) - }) + .attach(instanceAddress); + expect(await ubToken.underlying()).to.eq(mockAmpl.address); + }); it('Instance should register into instanceSet', async function () { - await mockAmpl.approve(factory.address, await template.INITIAL_DEPOSIT()) + await mockAmpl.approve(factory.address, await template.INITIAL_DEPOSIT()); const ubToken = await createInstance( factory, mockAmpl.address, 'UNBUTTON-Ampleforth', 'UNBUTTON-AMPL', initialRate, - ) + ); - expect(await factory.instanceCount()).to.eq(1) - expect(await factory.instanceAt(0)).to.eq(ubToken.address) - expect(await factory.isInstance(ubToken.address)).to.eq(true) - }) + expect(await factory.instanceCount()).to.eq(1); + expect(await factory.instanceAt(0)).to.eq(ubToken.address); + expect(await factory.isInstance(ubToken.address)).to.eq(true); + }); it('deposits should have the correct conversion', async function () { - await mockAmpl.approve(factory.address, await template.INITIAL_DEPOSIT()) + await mockAmpl.approve(factory.address, await template.INITIAL_DEPOSIT()); const ubToken = await createInstance( factory, mockAmpl.address, 'UNBUTTON-Ampleforth', 'UNBUTTON-AMPL', initialRate, - ) + ); { - const depositAmt = '5000000000000000' // 5m or 10% of ampl supply - await mockAmpl.connect(deployer).approve(ubToken.address, depositAmt) - await ubToken.connect(deployer).deposit(depositAmt) + const depositAmt = '5000000000000000'; // 5m or 10% of ampl supply + await mockAmpl.connect(deployer).approve(ubToken.address, depositAmt); + await ubToken.connect(deployer).deposit(depositAmt); // 1m or 10% of ub supply expect(await ubToken.balanceOf(deployerAddress)).to.eq( '1000000000000000000000000', - ) + ); } - await mockAmpl.rebase(2 * startingMultiplier) + await mockAmpl.rebase(2 * startingMultiplier); { - const depositAmt = '10000000000000000' // 10m or 10% of ampl supply - await mockAmpl.connect(deployer).approve(ubToken.address, depositAmt) - await ubToken.connect(deployer).deposit(depositAmt) + const depositAmt = '10000000000000000'; // 10m or 10% of ampl supply + await mockAmpl.connect(deployer).approve(ubToken.address, depositAmt); + await ubToken.connect(deployer).deposit(depositAmt); // 2m or 20% of ub supply expect(await ubToken.balanceOf(deployerAddress)).to.eq( '2000000000000000000000000', - ) + ); } - }) -}) + }); +}); diff --git a/test/unit/UniETHOracle.ts b/test/unit/UniETHOracle.ts index d5e81dd..8314a5d 100644 --- a/test/unit/UniETHOracle.ts +++ b/test/unit/UniETHOracle.ts @@ -1,25 +1,25 @@ -import { expect } from 'chai' -import { BigNumber } from 'ethers' -import { ethers, waffle } from 'hardhat' +import { expect } from 'chai'; +import { BigNumber } from 'ethers'; +import { ethers, waffle } from 'hardhat'; async function mockedOracle() { - const [deployer, user] = await ethers.getSigners() + const [deployer, user] = await ethers.getSigners(); // deploy mocks const mockRockXStaking = await ( await ethers.getContractFactory('MockRockXStaking') ) .connect(deployer) - .deploy() + .deploy(); // deploy contract to test const oracle = await (await ethers.getContractFactory('UniETHOracle')) .connect(deployer) - .deploy(mockRockXStaking.address) + .deploy(mockRockXStaking.address); // need a contract with a non-view method that calls oracle.getData so we can gas test const mockOracleDataFetcher = await ( await ethers.getContractFactory('MockOracleDataFetcher') ) .connect(deployer) - .deploy(oracle.address) + .deploy(oracle.address); return { deployer, @@ -27,63 +27,63 @@ async function mockedOracle() { mockRockXStaking, oracle, mockOracleDataFetcher, - } + }; } describe('UniETHOracle', function () { describe('when sent ether', async function () { it('should reject', async function () { - const { user, oracle } = await waffle.loadFixture(mockedOracle) + const { user, oracle } = await waffle.loadFixture(mockedOracle); await expect(user.sendTransaction({ to: oracle.address, value: 1 })).to.be - .reverted - }) - }) + .reverted; + }); + }); describe('Fetching data', async function () { it('should succeed with fresh data', async function () { const { user, mockRockXStaking, mockOracleDataFetcher } = - await waffle.loadFixture(mockedOracle) + await waffle.loadFixture(mockedOracle); await expect( mockRockXStaking .connect(user) .setXETHAmount(BigNumber.from('6413278131285121422182816')), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockRockXStaking .connect(user) .setETHReserve(BigNumber.from('7091831834635293267033248')), - ).to.not.be.reverted + ).to.not.be.reverted; - const tx = await mockOracleDataFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [value, valid] = await mockOracleDataFetcher.getData() + const tx = await mockOracleDataFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [value, valid] = await mockOracleDataFetcher.getData(); // uniETH denominated in ETH should be ETHReserve/XETHAmount - expect(value.toString()).to.eq('1105804502698871756') - expect(valid).to.eq(true) - expect(receipt.gasUsed.toString()).to.equal('78648') - }) + expect(value.toString()).to.eq('1105804502698871756'); + expect(valid).to.eq(true); + expect(receipt.gasUsed.toString()).to.equal('78648'); + }); it('should return 1:1 when uni-eth is empty', async function () { const { user, mockRockXStaking, mockOracleDataFetcher } = - await waffle.loadFixture(mockedOracle) + await waffle.loadFixture(mockedOracle); await expect( mockRockXStaking.connect(user).setXETHAmount(BigNumber.from('0')), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockRockXStaking.connect(user).setETHReserve(BigNumber.from('0')), - ).to.not.be.reverted + ).to.not.be.reverted; - const tx = await mockOracleDataFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [value, valid] = await mockOracleDataFetcher.getData() + const tx = await mockOracleDataFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [value, valid] = await mockOracleDataFetcher.getData(); // uniETH denominated in ETH should be ETHReserve/XETHAmount - expect(value.toString()).to.eq('1000000000000000000') - expect(valid).to.eq(true) - expect(receipt.gasUsed.toString()).to.equal('76373') - }) - }) -}) + expect(value.toString()).to.eq('1000000000000000000'); + expect(valid).to.eq(true); + expect(receipt.gasUsed.toString()).to.equal('76373'); + }); + }); +}); diff --git a/test/unit/WamplOracle.ts b/test/unit/WamplOracle.ts index 92b495e..b8f908d 100644 --- a/test/unit/WamplOracle.ts +++ b/test/unit/WamplOracle.ts @@ -1,26 +1,26 @@ -import { ethers, waffle } from 'hardhat' -import { BigNumber } from 'ethers' -import { expect } from 'chai' +import { ethers, waffle } from 'hardhat'; +import { BigNumber } from 'ethers'; +import { expect } from 'chai'; async function mockedOracle() { - const [deployer, user] = await ethers.getSigners() + const [deployer, user] = await ethers.getSigners(); // deploy mocks const mockAmplEthAggregator = await ( await ethers.getContractFactory('MockChainlinkAggregator') ) .connect(deployer) - .deploy(18) + .deploy(18); const mockEthUsdAggregator = await ( await ethers.getContractFactory('MockChainlinkAggregator') ) .connect(deployer) - .deploy(8) + .deploy(8); const mockAmpl = await (await ethers.getContractFactory('MockAMPL')) .connect(deployer) - .deploy(9) + .deploy(9); const mockWampl = await (await ethers.getContractFactory('MockWAMPL')) .connect(deployer) - .deploy(18, mockAmpl.address) + .deploy(18, mockAmpl.address); // deploy contract to test const oracle = await (await ethers.getContractFactory('WamplOracle')) .connect(deployer) @@ -29,13 +29,13 @@ async function mockedOracle() { mockEthUsdAggregator.address, mockWampl.address, 60000, - ) + ); // need a contract with a non-view method that calls oracle.getData so we can gas test const mockOracleDataFetcher = await ( await ethers.getContractFactory('MockOracleDataFetcher') ) .connect(deployer) - .deploy(oracle.address) + .deploy(oracle.address); return { deployer, @@ -46,17 +46,17 @@ async function mockedOracle() { mockWampl, oracle, mockOracleDataFetcher, - } + }; } describe('WamplOracle', function () { describe('when sent ether', async function () { it('should reject', async function () { - const { user, oracle } = await waffle.loadFixture(mockedOracle) + const { user, oracle } = await waffle.loadFixture(mockedOracle); await expect(user.sendTransaction({ to: oracle.address, value: 1 })).to.be - .reverted - }) - }) + .reverted; + }); + }); describe('Fetching data', async function () { it('should succeed with fresh data', async function () { @@ -65,42 +65,42 @@ describe('WamplOracle', function () { mockAmplEthAggregator, mockEthUsdAggregator, mockOracleDataFetcher, - } = await waffle.loadFixture(mockedOracle) + } = await waffle.loadFixture(mockedOracle); // Set AMPL to be worth 0.0005 ETH await expect( mockAmplEthAggregator .connect(user) .setLatestAnswer(BigNumber.from('500000000000000')), - ).to.not.be.reverted + ).to.not.be.reverted; // Set ETH to be worth 2000 USD await expect( mockEthUsdAggregator .connect(user) .setLatestAnswer(BigNumber.from('200000000000')), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockAmplEthAggregator .connect(user) .setUpdatedAt(Math.floor(new Date().valueOf() / 1000)), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockEthUsdAggregator .connect(user) .setUpdatedAt(Math.floor(new Date().valueOf() / 1000)), - ).to.not.be.reverted + ).to.not.be.reverted; - const tx = await mockOracleDataFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [res, success] = await mockOracleDataFetcher.getData() + const tx = await mockOracleDataFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [res, success] = await mockOracleDataFetcher.getData(); // The oracles should combine to price AMPL at 1 USD // Thus 1 WAMPL = 1 USD * AMPL:WAMPL ratio, which is defined in MockWAMPL wrapperToUnderlying // 1 WAMPL = ~5.9 AMPL, thus WamplOracle should return ~5.9e8 - expect(res.toString()).to.eq('592916430') - expect(success).to.eq(true) - expect(receipt.gasUsed.toString()).to.equal('95845') - }) + expect(res.toString()).to.eq('592916430'); + expect(success).to.eq(true); + expect(receipt.gasUsed.toString()).to.equal('95845'); + }); it('should fail with stale data', async function () { const { @@ -108,39 +108,39 @@ describe('WamplOracle', function () { mockAmplEthAggregator, mockEthUsdAggregator, mockOracleDataFetcher, - } = await waffle.loadFixture(mockedOracle) + } = await waffle.loadFixture(mockedOracle); // Set AMPL to be worth 0.0005 ETH await expect( mockAmplEthAggregator .connect(user) .setLatestAnswer(BigNumber.from('500000000000000')), - ).to.not.be.reverted + ).to.not.be.reverted; // Set ETH to be worth 2000 USD await expect( mockEthUsdAggregator .connect(user) .setLatestAnswer(BigNumber.from('200000000000')), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockAmplEthAggregator .connect(user) .setUpdatedAt(Math.floor(new Date().valueOf() / 1000) - 100000), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockEthUsdAggregator .connect(user) .setUpdatedAt(Math.floor(new Date().valueOf() / 1000) - 100000), - ).to.not.be.reverted + ).to.not.be.reverted; - const tx = await mockOracleDataFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [res, success] = await mockOracleDataFetcher.getData() + const tx = await mockOracleDataFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [res, success] = await mockOracleDataFetcher.getData(); - expect(res.toString()).to.eq('592916430') - expect(success).to.eq(false) - expect(receipt.gasUsed.toString()).to.equal('75931') - }) + expect(res.toString()).to.eq('592916430'); + expect(success).to.eq(false); + expect(receipt.gasUsed.toString()).to.equal('75931'); + }); it('handles different AMPL<->WAMPL conversion rates', async function () { const { @@ -149,45 +149,45 @@ describe('WamplOracle', function () { mockEthUsdAggregator, mockWampl, mockOracleDataFetcher, - } = await waffle.loadFixture(mockedOracle) + } = await waffle.loadFixture(mockedOracle); // Set AMPL to be worth 0.0005 ETH await expect( mockAmplEthAggregator .connect(user) .setLatestAnswer(BigNumber.from('500000000000000')), - ).to.not.be.reverted + ).to.not.be.reverted; // Set ETH to be worth 2000 USD await expect( mockEthUsdAggregator .connect(user) .setLatestAnswer(BigNumber.from('200000000000')), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockAmplEthAggregator .connect(user) .setUpdatedAt(Math.floor(new Date().valueOf() / 1000)), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockEthUsdAggregator .connect(user) .setUpdatedAt(Math.floor(new Date().valueOf() / 1000)), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockWampl.connect(user).setTotalAMPLSupply('59291643044413257999'), - ).to.not.be.reverted + ).to.not.be.reverted; - const tx = await mockOracleDataFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [res, success] = await mockOracleDataFetcher.getData() + const tx = await mockOracleDataFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [res, success] = await mockOracleDataFetcher.getData(); // The oracles should combine to price AMPL at 1 USD // Thus 1 WAMPL = 1 USD * AMPL:WAMPL ratio, which we set above // 1 WAMPL = ~5929 AMPL, thus WamplOracle should return ~5.9e11 - expect(res.toString()).to.eq('592916430444') - expect(success).to.eq(true) - expect(receipt.gasUsed.toString()).to.equal('95845') - }) + expect(res.toString()).to.eq('592916430444'); + expect(success).to.eq(true); + expect(receipt.gasUsed.toString()).to.equal('95845'); + }); it('handles extreme oracle values', async function () { const { @@ -195,84 +195,84 @@ describe('WamplOracle', function () { mockAmplEthAggregator, mockEthUsdAggregator, mockOracleDataFetcher, - } = await waffle.loadFixture(mockedOracle) + } = await waffle.loadFixture(mockedOracle); // Set AMPL to be worth 5e-18 ETH await expect( mockAmplEthAggregator .connect(user) .setLatestAnswer(BigNumber.from('5')), - ).to.not.be.reverted + ).to.not.be.reverted; // Set ETH to be worth 2000 USD await expect( mockEthUsdAggregator .connect(user) .setLatestAnswer(BigNumber.from('200000000000')), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockAmplEthAggregator .connect(user) .setUpdatedAt(Math.floor(new Date().valueOf() / 1000)), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockEthUsdAggregator .connect(user) .setUpdatedAt(Math.floor(new Date().valueOf() / 1000)), - ).to.not.be.reverted + ).to.not.be.reverted; - const tx = await mockOracleDataFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [res, success] = await mockOracleDataFetcher.getData() + const tx = await mockOracleDataFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [res, success] = await mockOracleDataFetcher.getData(); // The oracles should combine to price AMPL at 0 USD // The amplEth feed is non-zero but too small to remain so after scaled to 8 decimals - expect(res.toString()).to.eq('0') - expect(success).to.eq(true) - expect(receipt.gasUsed.toString()).to.equal('75945') + expect(res.toString()).to.eq('0'); + expect(success).to.eq(true); + expect(receipt.gasUsed.toString()).to.equal('75945'); // Set AMPL to be worth 1 ETH await expect( mockAmplEthAggregator .connect(user) .setLatestAnswer(BigNumber.from('1000000000000000000')), - ).to.not.be.reverted + ).to.not.be.reverted; // Set ETH to be worth 1e-8 USD await expect( mockEthUsdAggregator.connect(user).setLatestAnswer(BigNumber.from('1')), - ).to.not.be.reverted + ).to.not.be.reverted; - const tx2 = await mockOracleDataFetcher.connect(user).fetch() - const receipt2 = await tx2.wait() - const [res2, success2] = await mockOracleDataFetcher.getData() + const tx2 = await mockOracleDataFetcher.connect(user).fetch(); + const receipt2 = await tx2.wait(); + const [res2, success2] = await mockOracleDataFetcher.getData(); // The oracles should combine to price AMPL at 1e-8 USD // There's just enough decimals to capture a non-zero value - expect(res2.toString()).to.eq('5') - expect(success2).to.eq(true) - expect(receipt2.gasUsed.toString()).to.equal('75945') - }) - }) + expect(res2.toString()).to.eq('5'); + expect(success2).to.eq(true); + expect(receipt2.gasUsed.toString()).to.equal('75945'); + }); + }); it('behaves correctly with negative convertPriceByDecimals', async function () { - const { deployer, user } = await waffle.loadFixture(mockedOracle) + const { deployer, user } = await waffle.loadFixture(mockedOracle); // deploy fresh mocks with different configurations const mockAmplEthAggregator = await ( await ethers.getContractFactory('MockChainlinkAggregator') ) .connect(deployer) - .deploy(4) + .deploy(4); const mockEthUsdAggregator = await ( await ethers.getContractFactory('MockChainlinkAggregator') ) .connect(deployer) - .deploy(1) + .deploy(1); const mockAmpl = await (await ethers.getContractFactory('MockAMPL')) .connect(deployer) - .deploy(9) + .deploy(9); const mockWampl = await (await ethers.getContractFactory('MockWAMPL')) .connect(deployer) - .deploy(18, mockAmpl.address) + .deploy(18, mockAmpl.address); // deploy contract to test const oracle = await (await ethers.getContractFactory('WamplOracle')) .connect(deployer) @@ -281,44 +281,44 @@ describe('WamplOracle', function () { mockEthUsdAggregator.address, mockWampl.address, 60000, - ) + ); // need a contract with a non-view method that calls oracle.getData so we can gas test const mockOracleDataFetcher = await ( await ethers.getContractFactory('MockOracleDataFetcher') ) .connect(deployer) - .deploy(oracle.address) + .deploy(oracle.address); // Set AMPL to be worth 0.0005 ETH await expect( mockAmplEthAggregator.connect(user).setLatestAnswer(BigNumber.from('5')), - ).to.not.be.reverted + ).to.not.be.reverted; // Set ETH to be worth 2000 USD await expect( mockEthUsdAggregator .connect(user) .setLatestAnswer(BigNumber.from('20000')), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockAmplEthAggregator .connect(user) .setUpdatedAt(Math.floor(new Date().valueOf() / 1000)), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockEthUsdAggregator .connect(user) .setUpdatedAt(Math.floor(new Date().valueOf() / 1000)), - ).to.not.be.reverted + ).to.not.be.reverted; - const tx = await mockOracleDataFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [res, success] = await mockOracleDataFetcher.getData() + const tx = await mockOracleDataFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [res, success] = await mockOracleDataFetcher.getData(); // The oracles should combine to price AMPL at 1 USD // Thus 1 WAMPL = 1 USD * AMPL:WAMPL ratio, which is defined in MockWAMPL wrapperToUnderlying // 1 WAMPL = ~5.9 AMPL, thus WamplOracle should return ~5.9e8 - expect(res.toString()).to.eq('592916430') - expect(success).to.eq(true) - expect(receipt.gasUsed.toString()).to.equal('95960') - }) -}) + expect(res.toString()).to.eq('592916430'); + expect(success).to.eq(true); + expect(receipt.gasUsed.toString()).to.equal('95960'); + }); +}); diff --git a/test/unit/YyAVAXOracle.ts b/test/unit/YyAVAXOracle.ts index eefe29f..caf7296 100644 --- a/test/unit/YyAVAXOracle.ts +++ b/test/unit/YyAVAXOracle.ts @@ -1,23 +1,23 @@ -import { expect } from 'chai' -import { BigNumber } from 'ethers' -import { ethers, waffle } from 'hardhat' +import { expect } from 'chai'; +import { BigNumber } from 'ethers'; +import { ethers, waffle } from 'hardhat'; async function mockedOracle() { - const [deployer, user] = await ethers.getSigners() + const [deployer, user] = await ethers.getSigners(); // deploy mocks const mockYyAVAX = await (await ethers.getContractFactory('MockYyAVAX')) .connect(deployer) - .deploy() + .deploy(); // deploy contract to test const oracle = await (await ethers.getContractFactory('YyAVAXOracle')) .connect(deployer) - .deploy(mockYyAVAX.address) + .deploy(mockYyAVAX.address); // need a contract with a non-view method that calls oracle.getData so we can gas test const mockOracleDataFetcher = await ( await ethers.getContractFactory('MockOracleDataFetcher') ) .connect(deployer) - .deploy(oracle.address) + .deploy(oracle.address); return { deployer, @@ -25,42 +25,42 @@ async function mockedOracle() { mockYyAVAX, oracle, mockOracleDataFetcher, - } + }; } describe('YyAVAXOracle', function () { describe('when sent ether', async function () { it('should reject', async function () { - const { user, oracle } = await waffle.loadFixture(mockedOracle) + const { user, oracle } = await waffle.loadFixture(mockedOracle); await expect(user.sendTransaction({ to: oracle.address, value: 1 })).to.be - .reverted - }) - }) + .reverted; + }); + }); describe('Fetching data', async function () { it('should succeed with fresh data', async function () { const { user, mockYyAVAX, mockOracleDataFetcher } = - await waffle.loadFixture(mockedOracle) + await waffle.loadFixture(mockedOracle); await expect( mockYyAVAX .connect(user) .setTotalShares(BigNumber.from('6413278131285121422182816')), - ).to.not.be.reverted + ).to.not.be.reverted; await expect( mockYyAVAX .connect(user) .setTotalAssets(BigNumber.from('7091831834635293267033248')), - ).to.not.be.reverted + ).to.not.be.reverted; - const tx = await mockOracleDataFetcher.connect(user).fetch() - const receipt = await tx.wait() - const [value, valid] = await mockOracleDataFetcher.getData() + const tx = await mockOracleDataFetcher.connect(user).fetch(); + const receipt = await tx.wait(); + const [value, valid] = await mockOracleDataFetcher.getData(); // yyAVAX denominated in AVAX should be totalShares/totalAssets - expect(value.toString()).to.eq('1105804502698871756') - expect(valid).to.eq(true) - expect(receipt.gasUsed.toString()).to.equal('78523') - }) - }) -}) + expect(value.toString()).to.eq('1105804502698871756'); + expect(valid).to.eq(true); + expect(receipt.gasUsed.toString()).to.equal('78523'); + }); + }); +}); diff --git a/test/utils/loadDotEnv.ts b/test/utils/loadDotEnv.ts index be1fa81..a3737ff 100644 --- a/test/utils/loadDotEnv.ts +++ b/test/utils/loadDotEnv.ts @@ -1,16 +1,16 @@ -import fs from 'fs' +import fs from 'fs'; function loadDotEnv() { try { - const dotEnvText = fs.readFileSync('.env', 'utf8') - const lines = dotEnvText.match(/(.+?)=(.+)/gm) + const dotEnvText = fs.readFileSync('.env', 'utf8'); + const lines = dotEnvText.match(/(.+?)=(.+)/gm); if (lines) { lines.forEach((line) => { - const [, key, value] = line.match(/(.+?)=(.+)/)! - process.env[key.trim()] = value.trim() - }) + const [, key, value] = line.match(/(.+?)=(.+)/)!; + process.env[key.trim()] = value.trim(); + }); } } catch (err) {} } -loadDotEnv() +loadDotEnv(); diff --git a/test/utils/utils.ts b/test/utils/utils.ts index 9a4dc73..b7e9193 100644 --- a/test/utils/utils.ts +++ b/test/utils/utils.ts @@ -1,25 +1,25 @@ -import { ethers } from 'hardhat' -import { BigNumberish } from 'ethers' -import { BigNumber as BN } from 'bignumber.js' +import { ethers } from 'hardhat'; +import { BigNumberish } from 'ethers'; +import { BigNumber as BN } from 'bignumber.js'; export const imul = (a: BigNumberish, b: BigNumberish, c: BigNumberish) => { return ethers.BigNumber.from( new BN(a.toString()).times(b.toString()).idiv(c.toString()).toString(10), - ) -} + ); +}; export const timeNow = async () => { - return (await ethers.provider.getBlock('latest')).timestamp -} + return (await ethers.provider.getBlock('latest')).timestamp; +}; export const increaseTime = async (seconds: BigNumberish) => { await ethers.provider.send('evm_mine', [ ethers.BigNumber.from(seconds) .add(await timeNow()) .toNumber(), - ]) -} + ]); +}; export const setTime = async (time: BigNumberish) => { - await ethers.provider.send('evm_setNextBlockTimestamp', [time]) -} + await ethers.provider.send('evm_setNextBlockTimestamp', [time]); +}; From 0cdc492a607e621ddd3cc349e6c3fededc74f31e Mon Sep 17 00:00:00 2001 From: SocksNFlops Date: Sat, 16 Mar 2024 01:10:44 +0800 Subject: [PATCH 2/4] ci(prettier): adding prettier-check to test-runner --- .github/workflows/test.yml | 3 +++ package.json | 1 + 2 files changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b8570ea..3456d6e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,6 +37,9 @@ jobs: - name: Lint run: yarn lint + - name: Format-Check + run: yarn format-check + - name: Compile run: yarn compile diff --git a/package.json b/package.json index dece828..5fff90d 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "profile": "REPORT_GAS=true yarn hardhat test test/unit/*.ts", "coverage": "yarn hardhat coverage --testfiles 'test/unit/*.ts'", "format": "yarn prettier --config .prettierrc --write '**/*.ts' 'contracts/**/*.sol'", + "format-check": "yarn prettier --config .prettierrc --check '**/*.ts' 'contracts/**/*.sol'", "lint": "yarn solhint 'contracts/**/*.sol'" }, "pre-commit": [ From 3e98928ce7f8a05dd58e53b9c204e612081f9bc3 Mon Sep 17 00:00:00 2001 From: SocksNFlops Date: Mon, 25 Mar 2024 18:19:41 +0800 Subject: [PATCH 3/4] fixing windows-command complaints for yarn format-check --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5fff90d..e0000ab 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,8 @@ "test": "yarn hardhat test", "profile": "REPORT_GAS=true yarn hardhat test test/unit/*.ts", "coverage": "yarn hardhat coverage --testfiles 'test/unit/*.ts'", - "format": "yarn prettier --config .prettierrc --write '**/*.ts' 'contracts/**/*.sol'", - "format-check": "yarn prettier --config .prettierrc --check '**/*.ts' 'contracts/**/*.sol'", + "format": "yarn prettier --config .prettierrc --write \"**/*.ts\" \"contracts/**/*.sol\"", + "format-check": "yarn prettier --config .prettierrc --check \"**/*.ts\" \"contracts/**/*.sol\"", "lint": "yarn solhint 'contracts/**/*.sol'" }, "pre-commit": [ From 628b6d343d5e493447e68bf148a9112c6030c871 Mon Sep 17 00:00:00 2001 From: SocksNFlops Date: Mon, 25 Mar 2024 18:30:41 +0800 Subject: [PATCH 4/4] removing non-ubuntu test runners --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3456d6e..baf99e8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: strategy: matrix: node-version: [16.20.2] - os: [macOS-latest, windows-latest, ubuntu-latest] + os: [ubuntu-latest] steps: - name: Setup Repo