|
| 1 | +const { BN } = require("@openzeppelin/test-helpers/src/setup"); |
| 2 | +const { MAX_UINT256 } = require("@openzeppelin/test-helpers/src/constants"); |
| 3 | + |
| 4 | +const CoreOrchestrator = artifacts.require("CoreOrchestrator"); |
| 5 | +const Core = artifacts.require("Core"); |
| 6 | +const Fei = artifacts.require("Fei"); |
| 7 | +const IUniswapV2Pair = artifacts.require("IUniswapV2Pair"); |
| 8 | +const EthBondingCurve = artifacts.require("EthBondingCurve"); |
| 9 | +const UniswapIncentive = artifacts.require("UniswapIncentive"); |
| 10 | +const FeiRouter = artifacts.require("FeiRouter"); |
| 11 | + |
| 12 | +module.exports = async function(callback) { |
| 13 | + let accounts = await web3.eth.getAccounts(); |
| 14 | + let co = await CoreOrchestrator.deployed(); |
| 15 | + let core = await Core.at(await co.core()); |
| 16 | + let fei = await Fei.at(await core.fei()); |
| 17 | + |
| 18 | + let ethPair = await IUniswapV2Pair.at(await co.ethFeiPair()); |
| 19 | + let ui = await UniswapIncentive.at(await co.uniswapIncentive()); |
| 20 | + |
| 21 | + let ethAmount = new BN('100000000000000000000000'); |
| 22 | + let feiTotal = ethAmount.mul(new BN('1000000')); |
| 23 | + let router = await FeiRouter.deployed(); |
| 24 | + await core.grantMinter(accounts[0], {from: accounts[0]}); |
| 25 | + await core.grantBurner(accounts[0], {from: accounts[0]}); |
| 26 | + |
| 27 | + await fei.mint(accounts[0], feiTotal); |
| 28 | + await fei.approve(router.address, feiTotal, {from: accounts[0]}); |
| 29 | + await ui.updateOracle(); |
| 30 | + |
| 31 | + console.log('Current'); |
| 32 | + |
| 33 | + let reserves = await ui.getReserves(); |
| 34 | + let price = reserves[0].div(reserves[1]); |
| 35 | + let peg = await ui.peg(); |
| 36 | + let pegBN = new BN(peg.value).div(new BN('1000000000000000000')); |
| 37 | + console.log(price); |
| 38 | + console.log(pegBN); |
| 39 | + |
| 40 | + console.log('Sync'); |
| 41 | + let targetFei = reserves[1].mul(pegBN); |
| 42 | + let currentFei = await fei.balanceOf(ethPair.address); |
| 43 | + |
| 44 | + await fei.burnFrom(ethPair.address, currentFei, {from: accounts[0]}); |
| 45 | + await fei.mint(ethPair.address, targetFei, {from: accounts[0]}); |
| 46 | + await ethPair.sync(); |
| 47 | + |
| 48 | + await ui.setExemptAddress(accounts[0], true, {from: accounts[0]}); |
| 49 | + |
| 50 | + console.log('Selling At'); |
| 51 | + reserves = await ui.getReserves() |
| 52 | + let twoPercent = reserves[0].div(new BN('50')); |
| 53 | + let maxBurn = twoPercent; |
| 54 | + let sell = await router.sellFei(maxBurn, twoPercent, 0, accounts[0], MAX_UINT256, {from: accounts[0]}); |
| 55 | + console.log(sell); |
| 56 | + |
| 57 | + console.log('Buying Below'); |
| 58 | + reserves = await ui.getReserves(); |
| 59 | + let buy = await router.buyFei(0, 0, accounts[0], MAX_UINT256, {value: twoPercent.mul(new BN('2')), from: accounts[0]}); |
| 60 | + console.log(buy); |
| 61 | + |
| 62 | + console.log('Buying Above'); |
| 63 | + reserves = await ui.getReserves(); |
| 64 | + buy = await router.buyFei(0, 0, accounts[0], MAX_UINT256, {value: twoPercent, from: accounts[0]}); |
| 65 | + console.log(buy); |
| 66 | + |
| 67 | + console.log('Selling Above'); |
| 68 | + reserves = await ui.getReserves(); |
| 69 | + sell = await router.sellFei(maxBurn, twoPercent, 0, accounts[0], MAX_UINT256, {from: accounts[0]}); |
| 70 | + console.log(sell); |
| 71 | + |
| 72 | + callback(); |
| 73 | +} |
| 74 | + |
| 75 | +function sleep(ms) { |
| 76 | + return new Promise(resolve => setTimeout(resolve, ms)); |
| 77 | +} |
| 78 | + |
| 79 | +function stringify(bn) { |
| 80 | + let decimals = new BN('1000000000000000000'); |
| 81 | + return bn.div(decimals).toString(); |
| 82 | +} |
0 commit comments