Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/refactor into libraries #51

Merged
merged 91 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
80e7c15
Seperate building from general config
MickdeGraaf Jun 10, 2020
fe9f9d3
updateWeights() implementation
MickdeGraaf Jun 12, 2020
3415bb4
pokeWeigths and updateWeightsGradually implementation
MickdeGraaf Jun 15, 2020
149c201
linting
MickdeGraaf Jun 15, 2020
7fe497b
WIP weight control tests
MickdeGraaf Jun 18, 2020
47f8340
Weight control implementation and tests
MickdeGraaf Jun 23, 2020
f9d4dc0
Remove artifacts
MickdeGraaf Jun 23, 2020
de90dac
Linting fixes
MickdeGraaf Jun 24, 2020
0e0efef
bugfix
MickdeGraaf Jun 24, 2020
b610707
Renamed PWeightControlledSmartPool to PAdjustableSmartPool
MickdeGraaf Jun 24, 2020
7c15613
Implemented remove and add token
MickdeGraaf Jun 25, 2020
cc91ea2
Rename test
MickdeGraaf Jun 25, 2020
3e00e46
Initial refactor structure
MickdeGraaf Jun 25, 2020
518cd87
add remix daemon command
MickdeGraaf Jun 26, 2020
ff4b4f5
Use libraries in AdjustableSmartPool.sol
MickdeGraaf Jun 26, 2020
97c7840
Linting fixes
MickdeGraaf Jun 28, 2020
976c880
Use lib for weight changing functions
MickdeGraaf Jun 28, 2020
1ab87ea
Remove typechain artifacts on `yarn clean`
MickdeGraaf Jun 28, 2020
b59fcb8
reorganized files
MickdeGraaf Jun 28, 2020
eff94e6
WIP linking
MickdeGraaf Jun 28, 2020
d9fce97
Fixed linker
MickdeGraaf Jun 28, 2020
cac1d77
Prettier
MickdeGraaf Jun 28, 2020
ed70066
Less verbose library deployment
MickdeGraaf Jun 28, 2020
e3b332c
Moved all exit and join pool functions to libraries
MickdeGraaf Jun 28, 2020
e938136
Commented out unused code
MickdeGraaf Jun 28, 2020
4d6de2b
Deploy libraries in tests
MickdeGraaf Jul 6, 2020
5e6d0a3
Move getDenormalizedWeights() to basic pool
MickdeGraaf Jul 6, 2020
b9e7916
Remove commented code
MickdeGraaf Jul 6, 2020
e6e063f
Use only seperated storage
MickdeGraaf Jul 6, 2020
9a487e2
Refactored Ownable and ReentryProtection storage
MickdeGraaf Jul 6, 2020
97797b2
Task fixes
MickdeGraaf Jul 8, 2020
172c17d
Add cap enforcement to single asset entry
MickdeGraaf Jul 8, 2020
efc5142
Fix proxy test
MickdeGraaf Jul 8, 2020
24c6e3a
Pool Math libs
MickdeGraaf Jul 8, 2020
d325ebf
Linting
MickdeGraaf Jul 8, 2020
59eda56
Single asset entry and asset calculations
MickdeGraaf Jul 9, 2020
237cc8a
Consolidate entry and exit libraries into one
MickdeGraaf Jul 10, 2020
b7d3aaf
Consolidate token add and removal libs
MickdeGraaf Jul 10, 2020
3e3175e
Make pool math methods internal
MickdeGraaf Jul 10, 2020
20b1df3
Fix library deployments
MickdeGraaf Jul 10, 2020
6cd8dbe
Properly test single asset entry
MickdeGraaf Jul 10, 2020
fd81a76
Big Refactor and annual fees
MickdeGraaf Jul 13, 2020
a7949f9
Handle fees when calculating exit and entry amounts
MickdeGraaf Jul 13, 2020
58a7a97
Removed old pool contracts
MickdeGraaf Jul 14, 2020
f21c5a5
Added circuitbreaker and fixed error messages
MickdeGraaf Jul 14, 2020
79dad45
prettier
MickdeGraaf Jul 14, 2020
94e39a2
Added functions to interface
MickdeGraaf Jul 14, 2020
d842555
Removed unused interfaces
MickdeGraaf Jul 14, 2020
0571abd
Fixed deploy tasks
MickdeGraaf Jul 14, 2020
dbbeea0
fixed artifact import
MickdeGraaf Jul 14, 2020
c6b0a2a
Removed Uniswap related code
MickdeGraaf Jul 14, 2020
a8f2a73
Test fixes
MickdeGraaf Jul 16, 2020
5df272c
Fix most error reasons
MickdeGraaf Jul 16, 2020
bb8273c
Exit & Join swap error messages
MickdeGraaf Jul 16, 2020
0259a9b
Use frontrunning protection on single asset entry and exit. And actua…
MickdeGraaf Jul 18, 2020
9734ddd
Frontrunning protection and fixed max contract size
MickdeGraaf Jul 18, 2020
404512c
Fix library deployment
MickdeGraaf Jul 18, 2020
14cd4b5
Throw error when trying to link a library which is not deployed
MickdeGraaf Jul 18, 2020
b61cb31
Move calculation functions to lib=
MickdeGraaf Jul 18, 2020
d42162b
Upgraded to typechain V2
MickdeGraaf Jul 19, 2020
818b2fa
Formatting
MickdeGraaf Jul 19, 2020
6e647cb
Update PV2SmartPool.sol
MickdeGraaf Jul 19, 2020
5f7c8ec
Use typechain v2 artifacts
MickdeGraaf Jul 19, 2020
d647aff
WIP snapshots
MickdeGraaf Jul 19, 2020
6c6a15e
Upgraded coverage
MickdeGraaf Jul 19, 2020
66adcb6
Improved test deployment task
MickdeGraaf Jul 19, 2020
ca09022
Improved test deployment task
MickdeGraaf Jul 19, 2020
dfbc59c
Update pBasicSmartPool.ts
MickdeGraaf Jul 19, 2020
dcafd5d
export time traveler
MickdeGraaf Jul 20, 2020
b1731e0
Upgraded packages
MickdeGraaf Jul 20, 2020
97ae1d9
Update package.json
MickdeGraaf Jul 20, 2020
7e5feb5
removeToken tests
MickdeGraaf Jul 20, 2020
9ffa8e3
circuit breaker getter
MickdeGraaf Jul 20, 2020
d105e09
circuit breaker setter tests
MickdeGraaf Jul 20, 2020
ec6d5c1
Near complete coverage
MickdeGraaf Jul 22, 2020
c022150
Getters and setters
MickdeGraaf Jul 22, 2020
53ffc96
Update PV2SmartPool.sol
MickdeGraaf Jul 22, 2020
5c97df3
Linting
MickdeGraaf Jul 22, 2020
ee90ac0
Getter fee recipient
MickdeGraaf Jul 22, 2020
baa4a67
Testing most parts of annual fee
MickdeGraaf Jul 22, 2020
7f4d812
fixed param type typo
MickdeGraaf Jul 22, 2020
67d182a
Update IPV2SmartPool.sol
MickdeGraaf Jul 22, 2020
bd4878c
Remove manual total supply adjustment
MickdeGraaf Jul 24, 2020
f11c35a
Charge outstanding fee function
MickdeGraaf Jul 24, 2020
ae2056f
Update TimeTraveler.ts
MickdeGraaf Jul 24, 2020
6acbd37
Tests and bugfixes
MickdeGraaf Jul 24, 2020
9d30b0c
packages upgrade
MickdeGraaf Jul 27, 2020
fd812e1
Interface natspec
MickdeGraaf Jul 27, 2020
3d15439
Formatting and natspec
MickdeGraaf Jul 27, 2020
9b5f758
Prettier
MickdeGraaf Jul 27, 2020
237efb6
Linting fixes
MickdeGraaf Jul 28, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions buidler.compile.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { BuidlerConfig, usePlugin, task } from "@nomiclabs/buidler/config";

usePlugin("buidler-typechain");
import { BuidlerConfig } from "@nomiclabs/buidler/config";

interface ExtendedBuidlerConfig extends BuidlerConfig {
[x:string]: any
Expand All @@ -14,10 +12,6 @@ const config: ExtendedBuidlerConfig = {
enabled: true,
}
},
typechain: {
outDir: "typechain",
target: "ethers"
},
}

export default config;
150 changes: 99 additions & 51 deletions buidler.config.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
// tslint:disable-next-line:no-var-requires
require("dotenv").config();
import { BuidlerConfig, usePlugin, task } from "@nomiclabs/buidler/config";
import { utils, constants, ContractTransaction } from "ethers";
import { BuidlerConfig, usePlugin, task, internalTask } from "@nomiclabs/buidler/config";
import { utils, constants, ContractTransaction, Wallet } from "ethers";
import {deployContract, solidity} from "ethereum-waffle";
import { parseUnits, parseEther, BigNumberish, BigNumber } from "ethers/utils";
import { MockTokenFactory } from "@pie-dao/mock-contracts/dist/typechain/MockTokenFactory";
import { PBasicSmartPoolFactory } from "./typechain/PBasicSmartPoolFactory";
import { PCappedSmartPoolFactory } from "./typechain/PCappedSmartPoolFactory";
import { IBFactoryFactory } from "./typechain/IBFactoryFactory";
import { deployBalancerFactory } from "./utils";
import { IBPoolFactory } from "./typechain/IBPoolFactory";
import { IERC20Factory } from "./typechain/IERC20Factory";

import { IbFactoryFactory } from "./typechain/IBFactoryFactory";
import { deployBalancerFactory, deployAndGetLibObject, linkArtifact } from "./utils";
import { IbPoolFactory } from "./typechain/IBPoolFactory";
import { Ierc20Factory } from "./typechain/IERC20Factory";
import { PProxiedFactoryFactory } from "./typechain/PProxiedFactoryFactory";
import { parseUnits, parseEther, BigNumberish, BigNumber } from "ethers/utils";
import { PCappedSmartPool } from "./typechain/PCappedSmartPool";

import { Pv2SmartPool } from "./typechain/Pv2SmartPool";
import { Pv2SmartPoolFactory } from "./typechain/Pv2SmartPoolFactory";
import Pv2SmartPoolArtifact from "./artifacts/PV2SmartPool.json";

import LibPoolEntryExitArtifact from "./artifacts/LibPoolEntryExit.json";
import LibAddRemoveTokenArtifact from "./artifacts/LibAddRemoveToken.json";
import LibWeightsArtifact from "./artifacts/LibWeights.json";
import LibPoolMathArtifact from "./artifacts/LibPoolMath.json";

usePlugin("@nomiclabs/buidler-waffle");
usePlugin("@nomiclabs/buidler-etherscan");
usePlugin("solidity-coverage");
usePlugin("buidler-deploy");

const INFURA_API_KEY = process.env.INFURA_API_KEY || "";
const KOVAN_PRIVATE_KEY = process.env.KOVAN_PRIVATE_KEY || "";
Expand Down Expand Up @@ -53,14 +63,14 @@ const config: ExtendedBuidlerConfig = {
accounts: [
MAINNET_PRIVATE_KEY,
MAINNET_PRIVATE_KEY_SECONDARY
].filter((item) => item != "")
].filter((item) => item !== "")
},
kovan: {
url: `https://kovan.infura.io/v3/${INFURA_API_KEY}`,
accounts: [
KOVAN_PRIVATE_KEY,
KOVAN_PRIVATE_KEY_SECONDARY
].filter((item) => item != "")
].filter((item) => item !== "")
},
rinkeby: {
url: `https://rinkeby.infura.io/v3/${INFURA_API_KEY}`,
Expand All @@ -69,7 +79,7 @@ const config: ExtendedBuidlerConfig = {
accounts: [
RINKEBY_PRIVATE_KEY,
RINKEBY_PRIVATE_KEY_SECONDARY
].filter((item) => item != "")
].filter((item) => item !== "")
},
coverage: {
url: 'http://127.0.0.1:8555', // Coverage launches its own ganache-cli client
Expand All @@ -93,7 +103,7 @@ task("deploy-pie-smart-pool-factory", "deploys a pie smart pool factory")
const factory = await (new PProxiedFactoryFactory(signers[0])).deploy();
console.log(`Factory deployed at: ${factory.address}`);

const implementation = await run("deploy-pie-capped-smart-pool") as PCappedSmartPool;
const implementation = await run("deploy-pie-smart-pool") as Pv2SmartPool;
await implementation.init(PLACE_HOLDER_ADDRESS, "IMPL", "IMPL", "1337");

await factory.init(taskArgs.balancerFactory, implementation.address);
Expand All @@ -107,13 +117,13 @@ task("deploy-pool-from-factory", "deploys a pie smart pool from the factory")
const signers = await ethers.getSigners();
const factory = PProxiedFactoryFactory.connect(taskArgs.factory, signers[0]);

const config = require(taskArgs.allocation);
const allocation = require(taskArgs.allocation);

const name = config.name;
const symbol = config.symbol
const initialSupply = parseEther(config.initialSupply);
const cap = parseEther(config.cap);
const tokens = config.tokens;
const name = allocation.name;
const symbol = allocation.symbol
const initialSupply = parseEther(allocation.initialSupply);
const cap = parseEther(allocation.cap);
const tokens = allocation.tokens;


const tokenAddresses: string[] = [];
Expand All @@ -125,10 +135,10 @@ task("deploy-pool-from-factory", "deploys a pie smart pool from the factory")
tokenWeights.push(parseEther(token.weight).div(2));

// Calc amount
const amount = new BigNumber(Math.floor((config.initialValue / token.value * token.weight / 100 * config.initialSupply * 10 ** token.decimals)).toString());
const amount = new BigNumber(Math.floor((allocation.initialValue / token.value * token.weight / 100 * allocation.initialSupply * 10 ** token.decimals)).toString());

// Approve factory to spend token
const tokenContract = IERC20Factory.connect(token.address, signers[0]);
const tokenContract = Ierc20Factory.connect(token.address, signers[0]);

const allowance = await tokenContract.allowance(await signers[0].getAddress(), factory.address);
if(allowance.lt(amount)) {
Expand All @@ -139,29 +149,27 @@ task("deploy-pool-from-factory", "deploys a pie smart pool from the factory")
}

const tx = await factory.newProxiedSmartPool(name, symbol, initialSupply, tokenAddresses, tokenAmounts, tokenWeights, cap);
const receipt = await tx.wait(2); //wait for 2 confirmations
const receipt = await tx.wait(2); // wait for 2 confirmations
const event = receipt.events.pop();
console.log(`Deployed smart pool at : ${event.address}`);
return event.address;
});

task("deploy-pie-smart-pool", "deploys a pie smart pool")
.setAction(async(taskArgs, { ethers }) => {
.setAction(async(taskArgs, { ethers, run }) => {
const signers = await ethers.getSigners();
const factory = new PBasicSmartPoolFactory(signers[0]);
const smartpool = await factory.deploy();

console.log(`PBasicSmartPool deployed at: ${smartpool.address}`);
});
console.log("deploying libraries");
const libraries = await run("deploy-libraries");
console.log("libraries deployed");
console.table(libraries);
const linkedArtifact = linkArtifact(Pv2SmartPoolArtifact, libraries);

task("deploy-pie-capped-smart-pool", "deploys a capped pie smart pool")
.setAction(async(taskArgs, { ethers }) => {
const signers = await ethers.getSigners();
const factory = new PCappedSmartPoolFactory(signers[0]);
const smartpool = await factory.deploy();
const smartpool = (await deployContract(signers[0] as Wallet, linkedArtifact, [], {
gasLimit: 100000000,
})) as Pv2SmartPool;

console.log(`PCappedSmartPool deployed at: ${smartpool.address}`);
return smartpool;
console.log(`Pv2SmartPool deployed at: ${smartpool.address}`);
});

task("init-smart-pool", "initialises a smart pool")
Expand All @@ -172,7 +180,7 @@ task("init-smart-pool", "initialises a smart pool")
.addParam("initialSupply", "Initial supply of the token")
.setAction(async(taskArgs, { ethers }) => {
const signers = await ethers.getSigners();
const smartpool = PBasicSmartPoolFactory.connect(taskArgs.smartPool, signers[0]);
const smartpool = Pv2SmartPoolFactory.connect(taskArgs.smartPool, signers[0]);
const tx = await smartpool.init(taskArgs.pool, taskArgs.name, taskArgs.symbol, utils.parseEther(taskArgs.initialSupply));
const receipt = await tx.wait(1);

Expand All @@ -183,10 +191,9 @@ task("deploy-smart-pool-implementation-complete")
.addParam("implName")
.setAction(async(taskArgs, { ethers, run }) => {
const signers = await ethers.getSigners();
const factory = new PCappedSmartPoolFactory(signers[0]);

// Deploy capped pool
const implementation = await run("deploy-pie-capped-smart-pool");
const implementation = await run("deploy-pie-smart-pool");
// Init capped smart pool
await run("init-smart-pool", {
smartPool: implementation.address,
Expand All @@ -212,7 +219,7 @@ task("set-cap", "Sets the cap on a capped pool")
.addParam("cap")
.setAction(async(taskArgs, { ethers }) => {
const signers = await ethers.getSigners();
const smartpool = PCappedSmartPoolFactory.connect(taskArgs.pool, signers[0]);
const smartpool = Pv2SmartPoolFactory.connect(taskArgs.pool, signers[0]);
const tx = await smartpool.setCap(parseEther(taskArgs.cap), {gasLimit: 2000000});

console.log(`Cap set tx: ${tx.hash}`);
Expand All @@ -224,13 +231,13 @@ task("join-smart-pool")
.addParam("amount")
.setAction(async(taskArgs, { ethers }) => {
const signers = await ethers.getSigners();
const smartpool = PBasicSmartPoolFactory.connect(taskArgs.pool, signers[0]);
const smartpool = Pv2SmartPoolFactory.connect(taskArgs.pool, signers[0]);

// TODO fix this confusing line
const tokens = await IBPoolFactory.connect(await smartpool.getBPool(), signers[0]).getCurrentTokens();
const tokens = await IbPoolFactory.connect(await smartpool.getBPool(), signers[0]).getCurrentTokens();

for(const tokenAddress of tokens) {
const token = IERC20Factory.connect(tokenAddress, signers[0]);
const token = Ierc20Factory.connect(tokenAddress, signers[0]);
// TODO make below more readable
console.log("approving tokens");
await (await token.approve(smartpool.address, constants.MaxUint256)).wait(1);
Expand All @@ -245,13 +252,13 @@ task("approve-smart-pool")
.addParam("pool")
.setAction(async(taskArgs, { ethers }) => {
const signers = await ethers.getSigners();
const smartpool = PBasicSmartPoolFactory.connect(taskArgs.pool, signers[0]);
const smartpool = Pv2SmartPoolFactory.connect(taskArgs.pool, signers[0]);

// TODO fix this confusing line
const tokens = await IBPoolFactory.connect(await smartpool.bPool(), signers[0]).getCurrentTokens();
const tokens = await IbPoolFactory.connect(await smartpool.bPool(), signers[0]).getCurrentTokens();

for(const tokenAddress of tokens) {
const token = IERC20Factory.connect(tokenAddress, signers[0]);
const token = Ierc20Factory.connect(tokenAddress, signers[0]);
// TODO make below more readable
const receipt = await (await token.approve(smartpool.address, constants.MaxUint256)).wait(1);
console.log(`${tokenAddress} approved tx: ${receipt.transactionHash}`);
Expand Down Expand Up @@ -281,9 +288,9 @@ task("deploy-balancer-pool", "deploys a balancer pool from a factory")
.addParam("factory", "Address of the balancer pool address")
.setAction(async(taskArgs, { ethers }) => {
const signers = await ethers.getSigners();
const factory = await IBFactoryFactory.connect(taskArgs.factory, signers[0]);
const factory = await IbFactoryFactory.connect(taskArgs.factory, signers[0]);
const tx = await factory.newBPool();
const receipt = await tx.wait(2); //wait for 2 confirmations
const receipt = await tx.wait(2); // wait for 2 confirmations
const event = receipt.events.pop();
console.log(`Deployed balancer pool at : ${event.address}`);
});
Expand All @@ -298,11 +305,12 @@ task("balancer-bind-token", "binds a token to a balancer pool")
// Approve token
const signers = await ethers.getSigners();
const account = await signers[0].getAddress();
const pool = IBPoolFactory.connect(taskArgs.pool, signers[0]);
const pool = IbPoolFactory.connect(taskArgs.pool, signers[0]);

const weight = parseUnits(taskArgs.weight, 18);
// tslint:disable-next-line:radix
const balance = utils.parseUnits(taskArgs.balance, parseInt(taskArgs.decimals));
const token = await IERC20Factory.connect(taskArgs.token, signers[0]);
const token = await Ierc20Factory.connect(taskArgs.token, signers[0]);

const allowance = await token.allowance(account, pool.address);

Expand All @@ -322,7 +330,7 @@ task("balancer-unbind-token", "removed a balancer token from a pool")
.setAction(async(taskArgs, { ethers }) => {
const signers = await ethers.getSigners();
const account = await signers[0].getAddress();
const pool = IBPoolFactory.connect(taskArgs.pool, signers[0]);
const pool = IbPoolFactory.connect(taskArgs.pool, signers[0]);

const tx = await pool.unbind(taskArgs.token);
const receipt = await tx.wait(1);
Expand All @@ -335,7 +343,7 @@ task("balancer-set-controller")
.addParam("controller")
.setAction(async(taskArgs, { ethers }) => {
const signers = await ethers.getSigners();
const pool = IBPoolFactory.connect(taskArgs.pool, signers[0]);
const pool = IbPoolFactory.connect(taskArgs.pool, signers[0]);

const tx = await pool.setController(taskArgs.controller);
const receipt = await tx.wait(1);
Expand All @@ -344,4 +352,44 @@ task("balancer-set-controller")
});


task("deploy-libraries", "deploys all external libraries")
.setAction(async(taskArgs, { ethers, deployments }) => {
const signers = await ethers.getSigners();
const {deploy} = deployments;
const libraries: any[] = [];

libraries.push(await deployAndGetLibObject(LibAddRemoveTokenArtifact, signers[0]));
libraries.push(await deployAndGetLibObject(LibPoolEntryExitArtifact, signers[0]));
libraries.push(await deployAndGetLibObject(LibWeightsArtifact, signers[0]));
libraries.push(await deployAndGetLibObject(LibPoolMathArtifact, signers[0]));

return libraries;
});

task("deploy-libraries-and-get-object")
.setAction(async(taskArgs, { ethers, run }) => {
const libraries = await run("deploy-libraries");

const libObject: any = {};

for (const lib of libraries) {
libObject[lib.name] = lib.address;
}

return libObject;

});

// Use only in testing!
internalTask("deploy-libraries-and-smartpool")
.setAction(async(taskArgs, { ethers, run, deployments}) => {
const {deploy} = deployments;
const signers = await ethers.getSigners();
const libraries = await run("deploy-libraries-and-get-object");

const contract = (await deploy("PV2SmartPool", {contractName: "PV2SmartPool", from: await signers[0].getAddress(), libraries}));
return Pv2SmartPoolFactory.connect(contract.address, signers[0]);
});


export default config;
47 changes: 0 additions & 47 deletions contracts/Math.sol

This file was deleted.

Loading