diff --git a/package.json b/package.json index 77f435aa..70483036 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,6 @@ "@babel/plugin-proposal-decorators": "^7.6.0", "@babel/plugin-transform-react-jsx": "^7.3.0", "@babel/types": "^7.7.4", - "@ledgerhq/hw-app-eth": "^4.72.1", - "@ledgerhq/hw-transport-u2f": "^4.72.1", "@material-ui/core": "^4.5.0", "@material-ui/icons": "^4.4.3", "@material-ui/lab": "^4.0.0-alpha.28", @@ -23,21 +21,18 @@ "@web3-react/core": "^6.0.0-beta.19", "@web3-react/injected-connector": "^6.0.0-beta.25", "@web3-react/network-connector": "^6.0.0-beta.25", - "abi-decoder": "^2.2.2", "babel-eslint": "10.0.3", "babel-jest": "^24.9.0", "babel-loader": "8.0.6", "babel-plugin-named-asset-import": "^0.3.4", "babel-preset-react-app": "^9.0.2", "@balancer-labs/sor": "^0.2.2", - "big.js": "^5.2.2", "bignumber.js": "^9.0.0", "camelcase": "^5.2.0", "case-sensitive-paths-webpack-plugin": "2.2.0", "chart.js": "^2.9.3", "copy-to-clipboard": "^3.2.0", "css-loader": "2.1.1", - "decimal.js": "^10.2.0", "dotenv": "^8.1.0", "dotenv-expand": "5.1.0", "eslint": "^6.1.0", @@ -48,8 +43,6 @@ "eslint-plugin-jsx-a11y": "6.2.3", "eslint-plugin-react": "7.14.3", "eslint-plugin-react-hooks": "^1.6.1", - "ethereumjs-tx": "^2.1.1", - "ethereumjs-util": "^6.1.0", "ethers": "^4.0.40", "file-loader": "3.0.1", "fs-extra": "7.0.1", @@ -66,7 +59,6 @@ "mini-css-extract-plugin": "0.8.0", "mobx": "^5.14.0", "mobx-react": "^6.1.3", - "mobx-state-tree": "^3.15.0", "node-sass": "^4.12.0", "optimize-css-assets-webpack-plugin": "5.0.3", "pnp-webpack-plugin": "1.5.0", @@ -97,7 +89,6 @@ "sass-extract-loader": "^1.1.0", "sass-loader": "7.2.0", "semver": "6.3.0", - "strip-hex-prefix": "^1.0.0", "style-loader": "1.0.0", "styled-components": "^4.4.1", "terser-webpack-plugin": "1.4.1", @@ -107,7 +98,6 @@ "tslint-react": "^4.1.0", "typescript": "<3.7.0", "url-loader": "2.1.0", - "web3-provider-engine": "^15.0.3", "webpack": "4.41.0", "webpack-dev-server": "3.2.1", "webpack-manifest-plugin": "2.1.1", diff --git a/scripts/constants.js b/scripts/constants.js deleted file mode 100644 index cecb0317..00000000 --- a/scripts/constants.js +++ /dev/null @@ -1,25 +0,0 @@ -const Web3 = require('web3'); - -const MAX_GAS = 0xffffffff; -const MAX_UINT = Web3.utils.toTwosComplement('-1'); -const { BN } = Web3.utils; - -const TEN18 = new BN('1000000000000000000'); -const TEN15 = new BN('1000000000000000'); -const TEN9 = new BN('1000000000'); - -const schema = { - BPool: require('../src/abi/BPool'), - BFactory: require('../src/abi/BFactory'), - TestToken: require('../src/abi/TestToken'), - ExchangeProxy: require('../src/abi/ExchangeProxy'), -}; - -module.exports = { - MAX_GAS, - MAX_UINT, - schema, - TEN18, - TEN15, - TEN9, -}; diff --git a/scripts/deployPreConfigured.js b/scripts/deployPreConfigured.js deleted file mode 100644 index a6fd8345..00000000 --- a/scripts/deployPreConfigured.js +++ /dev/null @@ -1,262 +0,0 @@ -const Web3 = require('web3'); -const fs = require('fs'); -const schema = require('./constants').schema; - -const web3 = new Web3('http://localhost:8545'); -const toHex = web3.utils.toHex; -const toBN = web3.utils.toBN; -const toWei = web3.utils.toWei; -const fromWei = web3.utils.fromWei; - -const MAX_GAS = require('./constants').MAX_GAS; -const MAX_UINT = require('./constants').MAX_UINT; - -const params = { - tokenParams: [ - { - name: 'WETH', - symbol: 'WETH', - balance: toWei('20'), - weight: toWei('5'), - userBalance: toWei('100'), - initialSupply: toWei('1000'), - }, - { - name: 'MKR', - symbol: 'MKR', - balance: toWei('20'), - weight: toWei('5'), - userBalance: toWei('50'), - initialSupply: toWei('350'), - }, - { - name: 'DAI', - symbol: 'DAI', - balance: toWei('8000'), - weight: toWei('5'), - userBalance: toWei('20000'), - initialSupply: toWei('100000'), - }, - ], - extraTokenParams: [ - { - name: 'TokenD', - symbol: 'TokenD', - userBalance: toWei('50'), - initialSupply: toWei('200'), - }, - { - name: 'TokenE', - symbol: 'TokenE', - userBalance: toWei('24'), - initialSupply: toWei('100'), - }, - { - name: 'TokenF', - symbol: 'TokenF', - userBalance: toWei('4000'), - initialSupply: toWei('17000'), - }, - ], -}; - -function writeConfigFile(deployed) { - const filePath = process.cwd() + `/src/deployed.json`; - - // let config = { - // factoryAddress: factoryAddress, - // }; - - let data = JSON.stringify(deployed); - fs.writeFileSync(filePath, data); -} - -function printResults(deployed) { - // That's it! - console.log('-----------------'); - console.log('Deployed Factory :', deployed.bFactory); - console.log('Deployed ExchangeProxy:', deployed.proxy); - console.log('Deployed pools : '); - for (let i = 0; i < deployed.pools.length; i++) { - console.log(`\t\t ${deployed.pools[i]}`); - } - console.log('Tokens (pre-added) : '); - for (let i = 0; i < deployed.tokens.length; i++) { - console.log(`\t\t ${deployed.tokens[i]}`); - } - console.log('Tokens (not added) : '); - for (let i = 0; i < deployed.extraTokens.length; i++) { - console.log(`\t\t ${deployed.extraTokens[i]}`); - } - console.log('-----------------'); - console.log(''); -} - -function toChecksum(address) { - return web3.utils.toChecksumAddress(address); -} - -async function deployPreConfigured() { - const accounts = await web3.eth.getAccounts(); - const defaultAccount = accounts[0]; - const newManager = accounts[1]; - const investor = accounts[2]; - const user = accounts[3]; - - const { tokenParams, extraTokenParams } = params; - - const TestToken = new web3.eth.Contract(schema.TestToken.abi, { - data: schema.TestToken.bytecode, - gas: MAX_GAS, - from: defaultAccount, - }); - const BFactory = new web3.eth.Contract(schema.BFactory.abi, { - data: schema.BFactory.abi, - gas: MAX_GAS, - from: defaultAccount, - }); - const ExchangeProxy = new web3.eth.Contract(schema.ExchangeProxy.abi, { - data: schema.ExchangeProxy.abi, - gas: MAX_GAS, - from: defaultAccount, - }); - - let tx; - // Deploy Tokens - let tokens = []; - - for (let i = 0; i < tokenParams.length; i++) { - console.log(`Deploying Token ${i}...`); - const initialSupply = tokenParams[i].initialSupply; - const token = await TestToken.deploy({ - data: schema.TestToken.bytecode, - arguments: [ - tokenParams[i].name, - tokenParams[i].symbol, - 18, - initialSupply, - ], - }).send({ gas: MAX_GAS }); - // const token = new web3.eth.Contract(abi.TestToken, tokenAddress) - tokens.push(token); - } - - for (let i = 0; i < tokens.length; i++) { - console.log(`Distributing token ${i} to test accounts...`); - const amount = tokenParams[i].userBalance; - await tokens[i].methods.transfer(newManager, amount).send(); - await tokens[i].methods.transfer(investor, amount).send(); - await tokens[i].methods.transfer(user, amount).send(); - } - - let extraTokens = []; - - for (let i = 0; i < extraTokenParams.length; i++) { - console.log(`Deploying Extra token ${i}...`); - const initialSupply = extraTokenParams[i].initialSupply; - const token = await TestToken.deploy({ - data: schema.TestToken.bytecode, - arguments: [ - extraTokenParams[i].name, - extraTokenParams[i].symbol, - 18, - initialSupply, - ], - }).send({ gas: MAX_GAS }); - // const token = new web3.eth.Contract(abi.TestToken, tokenAddress) - extraTokens.push(token); - } - - for (let i = 0; i < extraTokens.length; i++) { - console.log(`Distributing extra token ${i} to test accounts...`); - const amount = extraTokenParams[i].userBalance; - await extraTokens[i].methods.transfer(newManager, amount).send(); - await extraTokens[i].methods.transfer(investor, amount).send(); - await extraTokens[i].methods.transfer(user, amount).send(); - } - - // Deploy Factory - const factory = await BFactory.deploy({ - data: schema.BFactory.bytecode, - }).send({ gas: MAX_GAS }); - - console.log(`Deploying ExchangeProxy...`); - const proxy = await ExchangeProxy.deploy({ - data: schema.ExchangeProxy.bytecode, - }).send({ gas: MAX_GAS }); - - // // Deploy Pools - let numPools = 3; - let pools = []; - for (let i = 0; i <= numPools; i++) { - console.log(`Deploying BPool...`); - tx = await factory.methods.newBPool().send(); - - const poolAddress = tx.events['LOG_NEW_POOL'].returnValues.pool; - const bpool = new web3.eth.Contract(schema.BPool.abi, poolAddress, { - from: defaultAccount, - }); - pools.push(bpool); - - // Set Token Approvals + Bind Tokens - for (let i = 0; i < tokens.length; i++) { - console.log(`Approving Token ${i} to Bind...`); - await tokens[i].methods - .approve(bpool.options.address, MAX_UINT) - .send(); - await tokens[i].methods - .approve(proxy.options.address, MAX_UINT) - .send(); - console.log(`Binding Token ${i} to BPool...`); - await bpool.methods - .bind( - tokens[i].options.address, - tokenParams[i].balance, - tokenParams[i].weight - ) - .send({ gas: MAX_GAS }); - } - - console.log('Set Public Swap'); - - await bpool.methods.setPublicSwap(true).send(); - } - - let deployed = { - bFactory: toChecksum(factory.options.address), - proxy: toChecksum(proxy.options.address), - pools: [], - tokens: [], - extraTokens: [], - allTokens: [], - }; - - for (let i = 0; i < pools.length; i++) { - const checksumAddress = toChecksum(pools[i].options.address); - deployed.pools.push(checksumAddress); - } - - for (let i = 0; i < tokens.length; i++) { - const symbol = await tokens[i].methods.symbol().call(); - const checksumAddress = toChecksum(tokens[i].options.address); - deployed.tokens.push({ symbol: symbol, address: checksumAddress }); - deployed.allTokens.push({ symbol: symbol, address: checksumAddress }); - } - - for (let i = 0; i < extraTokens.length; i++) { - const symbol = await extraTokens[i].methods.symbol().call(); - const checksumAddress = toChecksum(extraTokens[i].options.address); - deployed.extraTokens.push({ symbol: symbol, address: checksumAddress }); - deployed.allTokens.push({ symbol: symbol, address: checksumAddress }); - } - - printResults(deployed); - writeConfigFile(deployed); - console.log('Deployed factory address written to config file'); -} - -function main() { - deployPreConfigured(); -} - -main(); diff --git a/scripts/interact.js b/scripts/interact.js deleted file mode 100644 index 6ce1a475..00000000 --- a/scripts/interact.js +++ /dev/null @@ -1,131 +0,0 @@ -const Web3 = require('web3'); -const { schema, MAX_GAS, TEN18, TEN15, TEN9 } = require('./constants'); - -const web3 = new Web3('http://localhost:8545'); -const { BN } = web3.utils; - -const addresses = { - BPool: '0x2a8AbEDeaAEE2fb1502ED9Ec0C47ed8670B2e948', - Ti: '0x0DB84570A89A95d91eB331f8248fEeba8491cd04', - To: '0xfa0186102A9c16f4515E984AEc687ddF1767FF84', -}; - -async function test() { - const accounts = await web3.eth.getAccounts(); - const defaultAccount = accounts[1]; - - const Ti = new web3.eth.Contract(schema.TestToken.abi, addresses.Ti, { - from: defaultAccount, - }); - const To = new web3.eth.Contract(schema.TestToken.abi, addresses.To, { - from: defaultAccount, - }); - const bPool = new web3.eth.Contract(schema.BPool.abi, addresses.BPool, { - from: defaultAccount, - }); - - // Set Initial Pool Params - - const Ai = new BN(10).mul(TEN18); - const Lo = new BN(0).mul(TEN18); - // const LP = new BN(TEN9).mul(TEN18) - const LP = new BN( - '115792089237316195423570985008687907853269984665640564039457584007913129639935000000000000000000' - ); - - let result; - - // MATH - const UserBalanceI = new BN( - await Ti.methods.balanceOf(defaultAccount).call() - ); - const UserBalanceO = new BN( - await To.methods.balanceOf(defaultAccount).call() - ); - - const Bi = new BN(await Ti.methods.balanceOf(bPool.options.address).call()); - const Bo = new BN(await To.methods.balanceOf(bPool.options.address).call()); - const Wi = new BN( - await bPool.methods.getNormalizedWeight(Ti.options.address).call() - ); - const Wo = new BN( - await bPool.methods.getNormalizedWeight(To.options.address).call() - ); - - console.log('_swap_ExactAmountIn_'); - - console.log('Initial State :'); - console.log('------------------'); - console.log('User Balance (Ti): ', UserBalanceI.toString()); - console.log('User Balance (To): ', UserBalanceO.toString()); - console.log(''); - console.log('Pool Balance (Ti): ', Bi.toString()); - console.log('Pool Balance (To): ', Bo.toString()); - console.log(''); - console.log('Wi : ', Wi.toString()); - console.log('Wo: : ', Wo.toString()); - console.log(''); - - console.log('Swap Parameters :'); - console.log('------------------'); - console.log('Ai : ', Ai.toString()); - console.log('Lo : ', Lo.toString()); - console.log('LP : ', LP.toString()); - console.log(''); - - try { - const result = await bPool.methods - .swap_ExactAmountIn( - addresses.To, - Ai.toString(), - addresses.To, - Lo.toString(), - LP.toString() - ) - .send({ from: defaultAccount, gas: MAX_GAS }); - - console.log('Transaction Result :'); - console.log('------------------'); - console.log( - 'Amount In : ', - result.events['LOG_SWAP'].returnValues.amountIn - ); - console.log( - 'Amount Out : ', - result.events['LOG_SWAP'].returnValues.amountOut - ); - console.log(''); - } catch (e) { - console.log(result); - console.log(e); - } - - const UserBalanceI2 = new BN( - await Ti.methods.balanceOf(defaultAccount).call() - ); - const UserBalanceO2 = new BN( - await To.methods.balanceOf(defaultAccount).call() - ); - - const Bi2 = new BN( - await Ti.methods.balanceOf(bPool.options.address).call() - ); - const Bo2 = new BN( - await To.methods.balanceOf(bPool.options.address).call() - ); - - console.log('After State :'); - console.log('------------------'); - console.log('User Balance (Ti): ', UserBalanceI2.toString()); - console.log('User Balance (To): ', UserBalanceO2.toString()); - console.log(''); - console.log('Pool Balance (Ti): ', Bi2.toString()); - console.log('Pool Balance (To): ', Bo2.toString()); - console.log(''); -} - -function main() { - test(); -} - -main();