Skip to content

Commit

Permalink
test: add wrapper token tests
Browse files Browse the repository at this point in the history
  • Loading branch information
red-0ne committed Jun 9, 2021
1 parent d44a8b5 commit f13eb4a
Show file tree
Hide file tree
Showing 37 changed files with 1,162 additions and 5,098 deletions.
322 changes: 261 additions & 61 deletions .openzeppelin/unknown-31337.json

Large diffs are not rendered by default.

9 changes: 3 additions & 6 deletions @types/augmentations.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { Greeter } from "../typechain/Greeter";

export interface TypechainConfig {
outDir?: string;
target?: "ethers-v4" | "ethers-v5" | "truffle-v4" | "truffle-v5" | "web3-v1";
}
import { EtherscanConfig } from "@nomiclabs/hardhat-etherscan/dist/src/types";
import { TypechainConfig } from "hardhat-typechain/dist/src/types";

declare module "hardhat/types" {
interface HardhatUserConfig {
typechain?: TypechainConfig;
etherscan?: EtherscanConfig
}

interface ProjectPaths {
Expand Down
6 changes: 3 additions & 3 deletions @types/buidler-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/// <reference types="hardhat/types" />
/// <reference types="@nomiclabs/hardhat-ethers/src/type-extensions" />
/// <reference types="@nomiclabs/hardhat-waffle/src/type-extensions" />
// <reference types="hardhat/types" />
// <reference types="node_modules/@nomiclabs/hardhat-ethers/src/type-extensions" />
// <reference types="node_modules/@nomiclabs/hardhat-waffle/src/type-extensions" />
4 changes: 2 additions & 2 deletions contracts/Wrapper.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// contracts/Wrapper.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
pragma solidity 0.6.10;

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import { StakedToken } from "./StakedToken.sol";
Expand All @@ -13,7 +13,7 @@ contract Wrapper is ERC20Upgradeable {
function initialize(address _token, string memory name, string memory symbol) public initializer {
__ERC20_init(name, symbol);

token = StakedToken(token);
token = StakedToken(_token);
_setupDecimals(token.decimals());
}

Expand Down
53 changes: 53 additions & 0 deletions contracts/WrapperMockUpgraded.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// contracts/Wrapper.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.6.10;

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import { StakedToken } from "./StakedToken.sol";

contract WrapperMockUpgraded is ERC20Upgradeable {
using SafeMathUpgradeable for uint256;

StakedToken token;

function initialize(address _token, string memory name, string memory symbol) public initializer {
__ERC20_init(name, symbol);

token = StakedToken(_token);
_setupDecimals(token.decimals());
}

function balance() public view returns (uint256) {
return token.balanceOf(address(this));
}

function deposit(uint256 _amount) public {
uint256 _before = balance();

require(token.transferFrom(msg.sender, address(this), _amount));

uint256 _after = balance();
// Recompute amount in case of deflationary token
_amount = _after.sub(_before);

uint256 shares = 0;
if ( totalSupply() == 0) {
shares = _amount;
} else {
shares = _amount.mul(totalSupply()).div(_before);
}

_mint(msg.sender, shares);
}

function withdraw(uint256 _shares) public {
uint256 _amountToRedeem = _shares.mul(balance()).div(totalSupply());
_burn(msg.sender, _shares);

token.transfer(msg.sender, _amountToRedeem);
}

function sayHi() public view returns (string memory) {
return "hi";
}
}
1 change: 0 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ const config: HardhatUserConfig = {
outDir: "typechain",
target: "ethers-v5",
},
// @ts-ignore
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY,
},
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"devDependencies": {
"@commitlint/cli": "^9.0.1",
"@commitlint/config-conventional": "^9.0.1",
"@commitlint/config-conventional": "^13.0.0",
"@ethersproject/abstract-signer": "^5.0.1",
"@ethersproject/bignumber": "^5.0.3",
"@nomiclabs/hardhat-ethers": "^2.0.0",
Expand All @@ -34,7 +34,7 @@
"eslint": "^7.4.0",
"eslint-config-prettier": "^6.11.0",
"ethereum-waffle": "^3.0.1",
"ethers": "^5.0.4",
"ethers": "^5.3.0",
"fs-extra": "^9.0.1",
"hardhat": "^2.0.3",
"hardhat-contract-sizer": "^2.0.2",
Expand Down Expand Up @@ -89,8 +89,9 @@
"accounts": "hardhat accounts"
},
"dependencies": {
"@gnosis.pm/safe-contracts": "^1.2.0",
"@gnosis.pm/safe-contracts": "^1.3.0",
"@openzeppelin/contracts-upgradeable": "^3.4.0",
"@types/cli-progress": "^3.9.1",
"abi-decoder": "^2.4.0",
"axios": "^0.21.1",
"browser-env": "^3.3.0",
Expand Down
10 changes: 5 additions & 5 deletions scripts/add-downstream.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { ethers } from "hardhat";
import { Contract, ContractFactory } from "ethers";
import { ContractFactory } from "ethers";
import { StakedToken } from "../typechain/StakedToken";

async function main(): Promise<void> {
Expand All @@ -11,13 +11,13 @@ async function main(): Promise<void> {

const stakedTokenAddress = process.env.STAKED_TOKEN_ADDRESS || '';

const StakedToken: ContractFactory = await ethers.getContractFactory("StakedToken");
const stakedToken = StakedToken.attach(stakedTokenAddress) as StakedToken;
const StakedTokenFactory: ContractFactory = await ethers.getContractFactory("StakedToken");
const stakedToken = StakedTokenFactory.attach(stakedTokenAddress) as StakedToken;

const downstreamAddress = "0x70974f06338974d691fa38327ef25d1cf3e87ce6";

let ABI = ["function sync()"];
let iface = new ethers.utils.Interface(ABI);
const ABI = ["function sync()"];
const iface = new ethers.utils.Interface(ABI);
const data = iface.encodeFunctionData("sync", []);

console.log(`Adding function call to downstream`);
Expand Down
3 changes: 1 addition & 2 deletions scripts/address-info.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import { ethers, upgrades } from "hardhat";
import { Contract, ContractFactory } from "ethers";
import { ethers } from "hardhat";

async function main(): Promise<void> {
// Hardhat always runs the compile task when running scripts through it.
Expand Down
6 changes: 3 additions & 3 deletions scripts/burn.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { ethers } from "hardhat";
import { Contract, ContractFactory } from "ethers";
import { ContractFactory } from "ethers";
import { StakedToken } from "../typechain/StakedToken";

async function main(): Promise<void> {
Expand All @@ -12,8 +12,8 @@ async function main(): Promise<void> {
const stakedTokenAddress = process.env.STAKED_TOKEN_ADDRESS || '';
const amount = ethers.BigNumber.from(1000000000);

const StakedToken: ContractFactory = await ethers.getContractFactory("StakedToken");
const stakedToken = StakedToken.attach(stakedTokenAddress) as StakedToken;
const StakedTokenFactory: ContractFactory = await ethers.getContractFactory("StakedToken");
const stakedToken = StakedTokenFactory.attach(stakedTokenAddress) as StakedToken;

console.log(`Burning ${amount.toString()}`);
await stakedToken.burn(amount);
Expand Down
6 changes: 3 additions & 3 deletions scripts/change-owner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { ethers } from "hardhat";
import { Contract, ContractFactory } from "ethers";
import { ContractFactory } from "ethers";
import { StakedToken } from "../typechain/StakedToken";

async function main(): Promise<void> {
Expand All @@ -15,8 +15,8 @@ async function main(): Promise<void> {
const newOwner = '0x619bB406Eb26E27d056AB3DcEC64EBb66BEdC425';


const StakedToken: ContractFactory = await ethers.getContractFactory("StakedToken");
const stakedToken = StakedToken.attach(stakedTokenAddress) as StakedToken;
const StakedTokenFactory: ContractFactory = await ethers.getContractFactory("StakedToken");
const stakedToken = StakedTokenFactory.attach(stakedTokenAddress) as StakedToken;

console.log("Transferring ownership of stakedToken...");
await stakedToken.transferOwnership(newOwner);
Expand Down
6 changes: 1 addition & 5 deletions scripts/change-proxy-admin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

import { ethers, upgrades } from "hardhat";
import { Contract, ContractFactory } from "ethers";
import { StakedToken } from "../typechain/StakedToken";
import { upgrades } from "hardhat";

async function main(): Promise<void> {
// Hardhat always runs the compile task when running scripts through it.
Expand All @@ -18,7 +15,6 @@ async function main(): Promise<void> {
// Proxy admin is loaded from .openzeppelin/network.json

console.log("Changing proxy admin of stakedToken...");
// @ts-ignore
await upgrades.admin.transferProxyAdminOwnership(newOwner);
console.log("Changed proxy admin of stakedToken to:", newOwner);
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/change-supply-controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { ethers } from "hardhat";
import { Contract, ContractFactory } from "ethers";
import { ContractFactory } from "ethers";
import { StakedToken } from "../typechain/StakedToken";

async function main(): Promise<void> {
Expand All @@ -20,8 +20,8 @@ async function main(): Promise<void> {
const newSupplyController = '0xE14ce18903B0d3678a098F3BdEDA0AAC3790Ac3B';


const StakedToken: ContractFactory = await ethers.getContractFactory("StakedToken");
const stakedToken = StakedToken.attach(stakedTokenAddress) as StakedToken;
const StakedTokenFactory: ContractFactory = await ethers.getContractFactory("StakedToken");
const stakedToken = StakedTokenFactory.attach(stakedTokenAddress) as StakedToken;

console.log("Changing supply controller of stakedToken...");
await stakedToken.setSupplyController(newSupplyController);
Expand Down
10 changes: 5 additions & 5 deletions scripts/downstream-transactions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { ethers } from "hardhat";
import { Contract, ContractFactory } from "ethers";
import { ContractFactory } from "ethers";
import { StakedToken } from "../typechain/StakedToken";
import { DownstreamCaller } from "../typechain/DownstreamCaller";

Expand All @@ -11,15 +11,15 @@ async function main(): Promise<void> {
// await run("compile");

const stakedTokenAddress = process.env.STAKED_TOKEN_ADDRESS || '';
const StakedToken: ContractFactory = await ethers.getContractFactory("StakedToken");
const stakedToken = StakedToken.attach(stakedTokenAddress) as StakedToken;
const StakedTokenFactory: ContractFactory = await ethers.getContractFactory("StakedToken");
const stakedToken = StakedTokenFactory.attach(stakedTokenAddress) as StakedToken;

const txs = await stakedToken.transactionsSize();
console.log(`Total downstream transactions: ${txs}`);

const downstreamCallerAddress = await stakedToken.downstreamCallerAddress();
const DownstreamCaller: ContractFactory = await ethers.getContractFactory("DownstreamCaller");
const downstreamCaller = DownstreamCaller.attach(downstreamCallerAddress) as DownstreamCaller;
const DownstreamCallerFactory: ContractFactory = await ethers.getContractFactory("DownstreamCaller");
const downstreamCaller = DownstreamCallerFactory.attach(downstreamCallerAddress) as DownstreamCaller;

for (let i=0; i<txs.toNumber(); i++) {
console.log(`Downstream transaction ${i}: ${await downstreamCaller.transactions(i)}`);
Expand Down
6 changes: 3 additions & 3 deletions scripts/get-airdrop-sources.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { ethers } from "hardhat";
import { BigNumber, Contract } from "ethers";
import Axios from "axios";
import fs from "fs";
import path from "path";

import stakedTokenABI from '../stakedTokenABI.json'; // This import style requires "esModuleInterop", see "side notes"
import poolTokenABI from '../poolTokenABI.json'; // This import style requires "esModuleInterop", see "side notes"


const cliProgress = require('cli-progress');
const _colors = require('colors');
import * as cliProgress from 'cli-progress';
import * as _colors from 'colors';

const alchemyUrl = `https://eth-mainnet.alchemyapi.io/v2/${process.env.ALCHEMY_API_KEY}`;
const etherscanUrl = 'https://api.etherscan.io/api';
Expand Down
6 changes: 2 additions & 4 deletions scripts/gnosis/mint.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

import { ethers, upgrades } from "hardhat";
import { Contract, ContractFactory } from "ethers";
import GnosisSafeSol from '@gnosis.pm/safe-contracts/build/contracts/GnosisSafe.json';
import { StakedToken } from "../../typechain/StakedToken";
import { ethers } from "hardhat";
import { ContractFactory } from "ethers";

async function main(): Promise<void> {
// Hardhat always runs the compile task when running scripts through it.
Expand Down
4 changes: 1 addition & 3 deletions scripts/gnosis/pause.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@

import { ethers } from "hardhat";
import { Contract, ContractFactory } from "ethers";
import { ContractFactory } from "ethers";

async function main(): Promise<void> {
// Hardhat always runs the compile task when running scripts through it.
// If this runs in a standalone fashion you may want to call compile manually
// to make sure everything is compiled
// await run("compile");

const stakedTokenAddress = process.env.STAKED_TOKEN_ADDRESS || '';

const StakedToken: ContractFactory = await ethers.getContractFactory("StakedToken");
const callData = StakedToken.interface.encodeFunctionData('pause');

Expand Down
2 changes: 1 addition & 1 deletion scripts/gnosis/prepare-upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { ethers, upgrades } from "hardhat";
import { Contract, ContractFactory } from "ethers";
import { ContractFactory } from "ethers";

async function main(): Promise<void> {
// Hardhat always runs the compile task when running scripts through it.
Expand Down
6 changes: 2 additions & 4 deletions scripts/gnosis/rebase.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

import { ethers, upgrades } from "hardhat";
import { Contract, ContractFactory } from "ethers";
import GnosisSafeSol from '@gnosis.pm/safe-contracts/build/contracts/GnosisSafe.json';
import { StakedToken } from "../../typechain/StakedToken";
import { ethers } from "hardhat";
import { ContractFactory } from "ethers";

async function main(): Promise<void> {
// Hardhat always runs the compile task when running scripts through it.
Expand Down
6 changes: 2 additions & 4 deletions scripts/gnosis/rebrand.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

import { ethers, upgrades } from "hardhat";
import { Contract, ContractFactory } from "ethers";
import GnosisSafeSol from '@gnosis.pm/safe-contracts/build/contracts/GnosisSafe.json';
import { StakedToken } from "../../typechain/StakedToken";
import { ethers } from "hardhat";
import { ContractFactory } from "ethers";

async function main(): Promise<void> {
// Hardhat always runs the compile task when running scripts through it.
Expand Down
8 changes: 4 additions & 4 deletions scripts/list-rebases.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { ethers } from "hardhat";
import { Contract, ContractFactory } from "ethers";
import { ContractFactory } from "ethers";
import { StakedToken } from "../typechain/StakedToken";

async function main(): Promise<void> {
Expand All @@ -11,15 +11,15 @@ async function main(): Promise<void> {

const stakedTokenAddress = process.env.STAKED_TOKEN_ADDRESS || '';

const StakedToken: ContractFactory = await ethers.getContractFactory("StakedToken");
const stakedToken = StakedToken.attach(stakedTokenAddress) as StakedToken;
const StakedTokenFactory: ContractFactory = await ethers.getContractFactory("StakedToken");
const stakedToken = StakedTokenFactory.attach(stakedTokenAddress) as StakedToken;

const filter = stakedToken.filters.LogTokenDistribution(null, null, null, null);
const rebases = await stakedToken.queryFilter(filter, 0);

console.log('block,timestamp,oldTotalSupply,newTotalSupply');

for(let r of rebases) {
for(const r of rebases) {
const date = new Date((await r.getBlock()).timestamp*1000);
console.log(`${r.blockNumber},"${date.toUTCString()}",${r.args?.oldTotalSupply},${r.args?.newTotalSupply}`)
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/mint.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { ethers } from "hardhat";
import { Contract, ContractFactory } from "ethers";
import { ContractFactory } from "ethers";
import { StakedToken } from "../typechain/StakedToken";

async function main(): Promise<void> {
Expand Down Expand Up @@ -32,8 +32,8 @@ async function main(): Promise<void> {

const recipient = '0xFE3FEec104E6B5c3dE77693652Bfc32AD7b5A76f';

const StakedToken: ContractFactory = await ethers.getContractFactory("StakedToken");
const stakedToken = StakedToken.attach(stakedTokenAddress) as StakedToken;
const StakedTokenFactory: ContractFactory = await ethers.getContractFactory("StakedToken");
const stakedToken = StakedTokenFactory.attach(stakedTokenAddress) as StakedToken;

console.log(`Minting ${amount.toString()} to ${recipient}`);
await stakedToken.mint(recipient, amount);
Expand Down
3 changes: 0 additions & 3 deletions scripts/rebase-legacy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

import { ethers } from "hardhat";
import { Contract, ContractFactory } from "ethers";
import { StakedToken } from "../typechain/StakedToken";

async function main(): Promise<void> {
// Hardhat always runs the compile task when running scripts through it.
Expand Down
Loading

0 comments on commit f13eb4a

Please sign in to comment.