def deploy(deployer): triple_slope_model = TripleSlopeModel.deploy({'from': deployer}) # min debt 0.2 BNB at 10 gwei gas price (killBps 5% -> at least 0.01BNB bonus) # reserve pool bps 1000 (10%) # kill bps 500 (5%) bank_config = ConfigurableInterestBankConfig.deploy( 2 * 10**17, 1000, 500, triple_slope_model, {'from': deployer}) proxy_admin = ProxyAdminImpl.deploy({'from': deployer}) bank_impl = Bank.deploy({'from': deployer}) bank = TransparentUpgradeableProxyImpl.deploy( bank_impl, proxy_admin, bank_impl.initialize.encode_input(bank_config), {'from': deployer}) bank = interface.IAny(bank) oracle = SimplePriceOracle.deploy({'from': deployer}) # strats add_strat = StrategyAllBNBOnly.deploy(router_address, {'from': deployer}) liq_strat = StrategyLiquidate.deploy(router_address, {'from': deployer}) rem_strat = StrategyWithdrawMinimizeTrading.deploy(router_address, {'from': deployer}) goblin_config = PancakeswapGoblinConfig.deploy(oracle, {'from': deployer}) print('bank', bank.address) print('bank_config', bank_config.address) print('all bnb', add_strat.address) print('liq', liq_strat.address) print('withdraw', rem_strat.address) return bank, add_strat, liq_strat, rem_strat, bank_config, goblin_config, oracle
def setup(): deployer = accounts[0] alice = accounts[1] bob = accounts[2] worker = accounts[9] alpha = interface.IAny('0xa1faa113cbE53436Df28FF0aEe54275c13B40975') proxy_admin = ProxyAdminImpl.deploy({'from': deployer}) staking_impl = AlphaStaking.deploy({'from': deployer}) staking = TransparentUpgradeableProxyImpl.deploy( staking_impl, proxy_admin, staking_impl.initialize.encode_input(alpha, deployer), {'from': deployer}) staking = interface.IAny(staking) # set deployer as worker staking.setWorker(worker, {'from': deployer}) # mint tokens mint_tokens(alpha, alice) mint_tokens(alpha, bob) mint_tokens(alpha, deployer) mint_tokens(alpha, worker) # approve alpha.approve(staking, 2**256 - 1, {'from': alice}) alpha.approve(staking, 2**256 - 1, {'from': bob}) alpha.approve(staking, 2**256 - 1, {'from': deployer}) alpha.approve(staking, 2**256 - 1, {'from': worker}) return deployer, alice, bob, worker, alpha, proxy_admin, staking_impl, staking
def main(): deployer = accounts.at('0xCB8cF8E6f61A3a0E383A3dcd9625d7ACe7436De4', force=True) user = accounts.at('0x435Fd10EA3814583eE5fDDfe830330DD4d6Eb4CF', force=True) # deployer = accounts.load('staking-kovan') # user = accounts.load('kovan-tester') token = MockERC20.deploy('mock', 'MOCK', 18, {'from': deployer}) proxy_admin = ProxyAdminImpl.deploy({'from': deployer}) staking_impl = AlphaStaking.deploy({'from': deployer}) staking = TransparentUpgradeableProxyImpl.deploy( staking_impl, proxy_admin, staking_impl.initialize.encode_input(token, deployer), {'from': deployer}) staking = interface.IAny(staking) staking.setWorker(deployer, {'from': deployer}) # mint tokens to deployer token.mint(deployer, 10**12 * 10**18, {'from': deployer}) token.approve(staking, 2**256-1, {'from': deployer}) staking.stake(1000 * 10**18, {'from': deployer}) token.mint(user, 10**12 * 10**18, {'from': user}) token.approve(staking, 2**256-1, {'from': user}) staking.stake(10 * 10**18, {'from': user})
def main(): deployer = accounts[0] alice = accounts[1] bob = accounts[2] alpha = interface.IAny('0xa1faa113cbE53436Df28FF0aEe54275c13B40975') proxy_admin = ProxyAdminImpl.deploy({'from': deployer}) staking_impl = AlphaStaking.deploy({'from': deployer}) staking = TransparentUpgradeableProxyImpl.deploy( staking_impl, proxy_admin, staking_impl.initialize.encode_input(alpha, deployer), {'from': deployer}) staking = interface.IAny(staking) # mint tokens alpha.mint(alice, 10**30) alpha.mint(bob, 10**30) alpha.mint(deployer, 10**30) # approve alpha.approve(staking, 2**256 - 1, {'from': alice}) alpha.approve(staking, 2**256 - 1, {'from': bob}) alpha.approve(staking, 2**256 - 1, {'from': deployer}) #################################################################################### print('===============================================') print('1. set worker & reward') assert staking.worker( ) == '0x0000000000000000000000000000000000000000', 'worker should initially be 0' staking.setWorker(alice, {'from': deployer}) assert staking.worker() == alice, 'incorrect worker' staking.setWorker(bob, {'from': deployer}) assert staking.worker() == bob, 'incorrect worker' staking.stake(10**18, {'from': alice}) try: staking.reward(0, {'from': alice}) assert False except VirtualMachineError: pass try: staking.reward(10**18, {'from': alice}) assert False except VirtualMachineError: pass staking.reward(0, {'from': deployer}) staking.reward(0, {'from': bob}) staking.reward(10**18, {'from': deployer}) staking.reward(10**18, {'from': bob})
def main(): deployer = accounts.at('0xB593d82d53e2c187dc49673709a6E9f806cdC835', force=True) # deployer = accounts.load('gh') alpha = interface.IAny('0xa1faa113cbE53436Df28FF0aEe54275c13B40975') proxy_admin = ProxyAdminImpl.at('0x090eCE252cEc5998Db765073D07fac77b8e60CB2') staking_impl = AlphaStaking.deploy({'from': deployer, 'gas_price': gas_strategy}) staking = TransparentUpgradeableProxyImpl.deploy( staking_impl, proxy_admin, staking_impl.initialize.encode_input(alpha, deployer), {'from': deployer, 'gas_price': gas_strategy}) staking = interface.IAny(staking) # approve staking contract stake_amt = 10 * 10**18 alpha.approve(staking, stake_amt, {'from': deployer, 'gas_price': gas_strategy}) # stake 10 ALPHA staking.stake(stake_amt, {'from': deployer, 'gas_price': gas_strategy})
def main(): admin = accounts[0] alice = accounts[1] bob = accounts[2] triple_slope_model = TripleSlopeModel.deploy({'from': admin}) # min debt 0.2 BNB at 10 gwei gas price (killBps 5% -> at least 0.01BNB bonus) # reserve pool bps 1000 (10%) # kill bps 500 (5%) bank_config = ConfigurableInterestBankConfig.deploy( 2 * 10**17, 1000, 500, triple_slope_model, {'from': admin}) proxy_admin = ProxyAdminImpl.deploy({'from': admin}) bank_impl = Bank.deploy({'from': admin}) bank = TransparentUpgradeableProxyImpl.deploy( bank_impl, proxy_admin, bank_impl.initialize.encode_input(bank_config), {'from': admin}) bank = interface.IAny(bank) cake = interface.IAny('0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82') wbnb = interface.IAny('0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c') chef = '0x73feaa1ee314f8c655e354234017be2193c9e24e' router = '0x05ff2b0db69458a0750badebc4f9e13add608c7f' # pancake router lp = interface.IAny('0xA527a61703D82139F8a06Bc30097cC9CAA2df5A6') r0, r1, _ = lp.getReserves() cake_price = r1 * 10**18 // r0 # in bnb oracle = SimplePriceOracle.deploy({'from': admin}) oracle.setPrices([cake], [wbnb], [cake_price], {'from': admin}) # strats add_strat = StrategyAllBNBOnly.deploy(router, {'from': admin}) liq_strat = StrategyLiquidate.deploy(router, {'from': admin}) rem_strat = StrategyWithdrawMinimizeTrading.deploy(router, {'from': admin}) # goblin goblin = PancakeswapPool1Goblin.deploy(bank, chef, router, add_strat, liq_strat, 300, {'from': admin}) # new strat add_strat_2 = StrategyAddTwoSidesOptimal.deploy(router, goblin, cake, {'from': admin}) goblin.setStrategyOk([add_strat_2], True, {'from': admin}) # set whitelist cake add_strat.setWhitelistTokens([cake], [True], {'from': admin}) liq_strat.setWhitelistTokens([cake], [True], {'from': admin}) rem_strat.setWhitelistTokens([cake], [True], {'from': admin}) # mint tokens mint_tokens(cake, alice) mint_tokens(wbnb, alice) # approve tokens cake.approve(add_strat_2, 2**256 - 1, {'from': alice}) # set goblin in bank config # work factor 72.5% # kill factor 80% # max price diff 1.1x (11000) goblin_config = PancakeswapGoblinConfig.deploy(oracle, {'from': admin}) goblin_config.setConfigs([goblin], [[True, 7250, 8000, 11000]], {'from': admin}) bank_config.setGoblins([goblin], [goblin_config], {'from': admin}) # add some BNB to bank bank.deposit({'from': bob, 'value': '1000 ether'}) ############################################################################################ print('==============') print('Case 0. set up initial borrow') alice = accounts[1] bob = accounts[2] bank.deposit({'from': bob, 'value': '2 ether'}) prevBNBBal = alice.balance() bank.work( 0, goblin, 10**18, 0, eth_abi.encode_abi(['address', 'bytes'], [ add_strat_2.address, eth_abi.encode_abi(['address', 'uint256', 'uint256'], [cake.address, 0, 0]) ]), { 'from': alice, 'value': '1 ether' }) ########################################################### # work (no borrow) with 0 cake print('==============================================================') print('Case 1. work (no borrow) with 0 CAKE') deposit_amt = 10**18 prevBNBBal = alice.balance() bank.work( 0, goblin, 0, 0, eth_abi.encode_abi(['address', 'bytes'], [ add_strat_2.address, eth_abi.encode_abi(['address', 'uint256', 'uint256'], [cake.address, 0, 0]) ]), { 'from': alice, 'value': deposit_amt }) curBNBBal = alice.balance() print('∆ bnb alice', curBNBBal - prevBNBBal) print('alice pos', bank.positionInfo(2)) pos_health, pos_debt = bank.positionInfo(2) assert almostEqual( pos_health, deposit_amt), 'position health should be ~1 BNB (swap fee 0.2%)' assert pos_debt == 0, 'position debt should be 0' ############################################################ # work (borrow) with 0 cake print('==============================================================') print('Case 2. work 2x (borrow) with 0 CAKE') deposit_amt = 1 * 10**18 borrow_amt = 1 * 10**18 prevBNBBal = alice.balance() bank.work( 0, goblin, borrow_amt, 0, eth_abi.encode_abi(['address', 'bytes'], [ add_strat_2.address, eth_abi.encode_abi(['address', 'uint256', 'uint256'], [cake.address, 0, 0]) ]), { 'from': alice, 'value': deposit_amt }) curBNBBal = alice.balance() print('∆ bnb alice', curBNBBal - prevBNBBal) print('alice pos', bank.positionInfo(3)) pos_health, pos_debt = bank.positionInfo(3) assert almostEqual(curBNBBal - prevBNBBal, -deposit_amt), 'incorrect deposit amt' assert almostEqual(pos_debt, borrow_amt), 'debt != borrow amount' assert almostEqual( pos_health, deposit_amt + borrow_amt), 'position health should be ~ deposited + borrow amt' ########################################################### # work (no borrow) with cake print('==============================================================') print('Case 3. work (no borrow) with CAKE') deposit_amt = 10**18 cake_amt = 2 * 10**18 prevBNBBal = alice.balance() bank.work( 0, goblin, 0, 0, eth_abi.encode_abi(['address', 'bytes'], [ add_strat_2.address, eth_abi.encode_abi(['address', 'uint256', 'uint256'], [cake.address, cake_amt, 0]) ]), { 'from': alice, 'value': deposit_amt }) curBNBBal = alice.balance() print('∆ bnb alice', curBNBBal - prevBNBBal) print('alice pos', bank.positionInfo(4)) pos_health, pos_debt = bank.positionInfo(4) assert almostEqual( pos_health, deposit_amt + cake_amt * cake_price // 10**18), 'position health should be ~1 BNB (swap fee 0.2%)' assert pos_debt == 0, 'position debt should be 0' ############################################################ # work (borrow) with cake print('==============================================================') print('Case 4. work 2x (borrow) with CAKE') deposit_amt = 1 * 10**18 borrow_amt = 1 * 10**18 cake_amt = 2 * 10**18 prevBNBBal = alice.balance() prevCakeBal = cake.balanceOf(alice) bank.work( 0, goblin, borrow_amt, 0, eth_abi.encode_abi(['address', 'bytes'], [ add_strat_2.address, eth_abi.encode_abi(['address', 'uint256', 'uint256'], [cake.address, cake_amt, 0]) ]), { 'from': alice, 'value': deposit_amt }) curBNBBal = alice.balance() curCakeBal = cake.balanceOf(alice) print('∆ bnb alice', curBNBBal - prevBNBBal) print('∆ cake alice', curCakeBal - prevCakeBal) print('alice pos', bank.positionInfo(5)) pos_health, pos_debt = bank.positionInfo(5) assert almostEqual(curBNBBal - prevBNBBal, -deposit_amt), 'incorrect deposit amt' assert almostEqual(pos_debt, borrow_amt), 'debt != input + borrow' assert almostEqual( pos_health, deposit_amt + borrow_amt + cake_amt * cake_price // 10**18), 'position health should be ~ deposited + borrow amt'
def main(): admin = accounts[0] alice = accounts[1] minter = accounts[9] alpha = interface.IAny(alpha_address) pancake_router = interface.IAny(router_address) triple_slope_model = TripleSlopeModel.deploy({'from': admin}) # min debt 0.2 BNB at 10 gwei gas price (killBps 5% -> at least 0.01BNB bonus) # reserve pool bps 1000 (10%) # kill bps 500 (5%) bank_config = ConfigurableInterestBankConfig.deploy( 2 * 10**17, 1000, 500, triple_slope_model, {'from': admin}) proxy_admin = ProxyAdminImpl.deploy({'from': admin}) bank_impl = Bank.deploy({'from': admin}) bank = TransparentUpgradeableProxyImpl.deploy( bank_impl, proxy_admin, bank_impl.initialize.encode_input(bank_config), {'from': admin}) bank = interface.IAny(bank) # create pair factory = interface.IAny(interface.IAny(router_address).factory()) factory.createPair(alpha_address, bank, {'from': minter}) # deploy ibBNBRouter router = IbBNBRouter.deploy(router_address, bank, alpha_address, {'from': admin}) # get ibBNB + ALPHA to minter bank.deposit({'from': minter, 'value': '100000 ether'}) mint_tokens(alpha_address, minter) # mint ibBNB + ALPHA to alice bank.transfer(alice, 1000 * 10**18, {'from': minter}) mint_tokens(alpha_address, alice) # minter approve pancake router alpha.approve(router_address, 2**256-1, {'from': minter}) bank.approve(router_address, 2**256-1, {'from': minter}) # alice approve ibBNB router alpha.approve(router, 2**256-1, {'from': alice}) bank.approve(router, 2**256-1, {'from': alice}) lp = interface.IAny(router.lpToken()) lp.approve(router, 2**256-1, {'from': alice}) # setup liquidity in ibBNB + ALPHA pool price = 1000 # 1 ibBNB = 1000 alpha bnb_supply = 1000 * 10**18 pancake_router.addLiquidity(bank, alpha_address, bnb_supply, bnb_supply * price, 0, 0, minter, 2**256-1, {'from': minter}) ############################################################################################## # Case 1. add & remove liquidity alpha + bnb print('======================================================================') print('Case 1. add liquidity & remove alpha + bnb') prevBNBBal = alice.balance() # add liquidity router.addLiquidityBNB(10**18, 0, 0, alice, 2**256-1, {'from': alice, 'value': 10**18}) curBNBBal = alice.balance() delta1 = curBNBBal - prevBNBBal assert lp.balanceOf(alice) > 0 prevBNBBal = alice.balance() # remove liquidity router.removeLiquidityBNB(lp.balanceOf(alice), 0, 0, alice, 2**256-1, {'from': alice}) curBNBBal = alice.balance() delta2 = curBNBBal - prevBNBBal assert almostEqual(delta1, -10**18 // price), 'incorrect BNB input amount' assert almostEqual(delta2, 10**18 // price), 'incorrect BNB output amount' ############################################################################################## # Case 2. add liquidity two sides optimal print('======================================================================') print('Case 2. add liquidity two sides optimal') prevIbBNBBal = bank.balanceOf(alice) prevAlphaBal = alpha.balanceOf(alice) router.addLiquidityTwoSidesOptimal(10**18, 0, 0, alice, 2**256-1, {'from': alice}) curIbBNBBal = bank.balanceOf(alice) curAlphaBal = alpha.balanceOf(alice) assert almostEqual(curIbBNBBal - prevIbBNBBal, -10**18), 'incorrect ibBNB input amount' prevIbBNBBal = bank.balanceOf(alice) prevAlphaBal = alpha.balanceOf(alice) router.addLiquidityTwoSidesOptimal(0, 10**18, 0, alice, 2**256-1, {'from': alice}) curIbBNBBal = bank.balanceOf(alice) curAlphaBal = alpha.balanceOf(alice) assert almostEqual(curAlphaBal - prevAlphaBal, -10**18), 'incorrect ALPHA input amount' prevIbBNBBal = bank.balanceOf(alice) prevAlphaBal = alpha.balanceOf(alice) router.addLiquidityTwoSidesOptimal(2 * 10**18, 10**18, 0, alice, 2**256-1, {'from': alice}) curIbBNBBal = bank.balanceOf(alice) curAlphaBal = alpha.balanceOf(alice) assert almostEqual(curIbBNBBal - prevIbBNBBal, -2 * 10**18), 'incorrect ibBNB input amount' assert almostEqual(curAlphaBal - prevAlphaBal, -10**18), 'incorrect ALPHA input amount' ############################################################################################## # Case 3. add liquidity two sides optimal bnb print('======================================================================') print('Case 3. add liquidity two sides optimal bnb') prevIbBNBBal = bank.balanceOf(alice) prevAlphaBal = alpha.balanceOf(alice) router.addLiquidityTwoSidesOptimalBNB(10**18, 0, alice, 2**256-1, {'from': alice}) curIbBNBBal = bank.balanceOf(alice) curAlphaBal = alpha.balanceOf(alice) assert almostEqual(curAlphaBal - prevAlphaBal, -10**18), 'incorrect ALPHA input amount' prevIbBNBBal = bank.balanceOf(alice) prevBNBBal = alice.balance() prevAlphaBal = alpha.balanceOf(alice) router.addLiquidityTwoSidesOptimalBNB( 0, 0, alice, 2**256-1, {'from': alice, 'value': '1 ether'}) curIbBNBBal = bank.balanceOf(alice) curBNBBal = alice.balance() curAlphaBal = alpha.balanceOf(alice) assert almostEqual(curBNBBal - prevBNBBal, -10**18), 'incorrect ibBNB input amount' prevIbBNBBal = bank.balanceOf(alice) prevBNBBal = alice.balance() prevAlphaBal = alpha.balanceOf(alice) router.addLiquidityTwoSidesOptimalBNB( 2 * 10**18, 0, alice, 2**256-1, {'from': alice, 'value': '1 ether'}) curIbBNBBal = bank.balanceOf(alice) curBNBBal = alice.balance() curAlphaBal = alpha.balanceOf(alice) assert almostEqual(curBNBBal - prevBNBBal, -10**18), 'incorrect ibBNB input amount' assert almostEqual(curAlphaBal - prevAlphaBal, -2 * 10**18), 'incorrect ALPHA input amount' ############################################################################################## # Case 4. remove liquidity alpha + bnb print('======================================================================') print('Case 4. remove liquidity alpha + bnb') r0, r1, _ = lp.getReserves() supply = lp.totalSupply() prevLPBal = lp.balanceOf(alice) prevIbBNBBal = bank.balanceOf(alice) prevBNBBal = alice.balance() prevAlphaBal = alpha.balanceOf(alice) router.removeLiquidityBNB(lp.balanceOf(alice) // 10, 0, 0, alice, 2**256-1, {'from': alice}) curLPBal = lp.balanceOf(alice) curIbBNBBal = bank.balanceOf(alice) curBNBBal = alice.balance() curAlphaBal = alpha.balanceOf(alice) assert almostEqual(curLPBal - prevLPBal, -prevLPBal // 10), 'incorrect LP withdraw amount' assert almostEqual(curAlphaBal - prevAlphaBal, r0 * prevLPBal // 10 / supply), 'incorrect ALPHA received' assert almostEqual(curBNBBal - prevBNBBal, r1 * prevLPBal // 10 / supply), 'incorrect BNB received' assert prevIbBNBBal == curIbBNBBal, 'ibBNB not equal' ############################################################################################## # Case 5. remove liquidity all alpha print('======================================================================') print('Case 5. remove liquidity all alpha') r0, r1, _ = lp.getReserves() supply = lp.totalSupply() prevLPBal = lp.balanceOf(alice) prevIbBNBBal = bank.balanceOf(alice) prevBNBBal = alice.balance() prevAlphaBal = alpha.balanceOf(alice) router.removeLiquidityAllAlpha(lp.balanceOf(alice) // 10, 0, alice, 2**256-1, {'from': alice}) curLPBal = lp.balanceOf(alice) curIbBNBBal = bank.balanceOf(alice) curBNBBal = alice.balance() curAlphaBal = alpha.balanceOf(alice) assert almostEqual(curLPBal - prevLPBal, -prevLPBal // 10), 'incorrect LP withdraw amount' assert almostEqual(curAlphaBal - prevAlphaBal, 2 * r0 * prevLPBal // 10 / supply), 'incorrect ALPHA received' assert curBNBBal == prevBNBBal, 'BNB not equal' assert prevIbBNBBal == curIbBNBBal, 'ibBNB not equal' ############################################################################################## # Case 6. swap exact bnb for alpha print('======================================================================') print('Case 6. swap exact bnb for alpha') prevIbBNBBal = bank.balanceOf(alice) prevBNBBal = alice.balance() prevAlphaBal = alpha.balanceOf(alice) router.swapExactBNBForAlpha(0, alice, 2**256-1, {'from': alice, 'value': '1 ether'}) curIbBNBBal = bank.balanceOf(alice) curBNBBal = alice.balance() curAlphaBal = alpha.balanceOf(alice) assert almostEqual(curAlphaBal - prevAlphaBal, 10**18 * price), 'incorrect ALPHA received' assert curBNBBal - prevBNBBal == -10**18, 'BNB not equal' assert prevIbBNBBal == curIbBNBBal, 'ibBNB not equal' ############################################################################################## # Case 7. swap alpha for exact bnb print('======================================================================') print('Case 7. swap alpha for exact bnb') prevIbBNBBal = bank.balanceOf(alice) prevBNBBal = alice.balance() prevAlphaBal = alpha.balanceOf(alice) router.swapAlphaForExactBNB(10**16, 2000 * 10**16, alice, 2**256-1, {'from': alice}) curIbBNBBal = bank.balanceOf(alice) curBNBBal = alice.balance() curAlphaBal = alpha.balanceOf(alice) assert almostEqual(curAlphaBal - prevAlphaBal, -10**16 * price), 'incorrect ALPHA received' assert curBNBBal - prevBNBBal == 10**16, 'BNB not equal' assert prevIbBNBBal == curIbBNBBal, 'ibBNB not equal' ############################################################################################## # Case 8. swap exact alpha for bnb print('======================================================================') print('Case 8. swap exact alpha for bnb') prevIbBNBBal = bank.balanceOf(alice) prevBNBBal = alice.balance() prevAlphaBal = alpha.balanceOf(alice) router.swapExactAlphaForBNB(10**18, 0, alice, 2**256-1, {'from': alice}) curIbBNBBal = bank.balanceOf(alice) curBNBBal = alice.balance() curAlphaBal = alpha.balanceOf(alice) assert curAlphaBal - prevAlphaBal == -10**18, 'incorrect ALPHA received' assert almostEqual(curBNBBal - prevBNBBal, 10**18 // price), 'BNB not equal' assert prevIbBNBBal == curIbBNBBal, 'ibBNB not equal' ############################################################################################## # Case 9. swap bnb for exact alpha print('======================================================================') print('Case 9. swap bnb for exact alpha') prevIbBNBBal = bank.balanceOf(alice) prevBNBBal = alice.balance() prevAlphaBal = alpha.balanceOf(alice) router.swapBNBForExactAlpha(10**18, alice, 2**256-1, {'from': alice, 'value': '1 ether'}) curIbBNBBal = bank.balanceOf(alice) curBNBBal = alice.balance() curAlphaBal = alpha.balanceOf(alice) assert curAlphaBal - prevAlphaBal == 10**18, 'incorrect ALPHA received' assert almostEqual(curBNBBal - prevBNBBal, -10**18 // price), 'BNB not equal' assert prevIbBNBBal == curIbBNBBal, 'ibBNB not equal'
def main(): admin = accounts[0] alice = accounts[1] triple_slope_model = TripleSlopeModel.deploy({'from': admin}) # min debt 0.2 BNB at 10 gwei gas price (killBps 5% -> at least 0.01BNB bonus) # reserve pool bps 1000 (10%) # kill bps 500 (5%) bank_config = ConfigurableInterestBankConfig.deploy( 2 * 10**17, 1000, 500, triple_slope_model, {'from': admin}) proxy_admin = ProxyAdminImpl.deploy({'from': admin}) bank_impl = Bank.deploy({'from': admin}) bank = TransparentUpgradeableProxyImpl.deploy( bank_impl, proxy_admin, bank_impl.initialize.encode_input(bank_config), {'from': admin}) bank = interface.IAny(bank) ################################################################### # deposit & withdraw deposit_amt = 10**18 prevBNBBal = alice.balance() prevIbBNBBal = bank.balanceOf(alice) bank.deposit({'from': alice, 'value': deposit_amt}) curBNBBal = alice.balance() curIbBNBBal = bank.balanceOf(alice) print('∆ bnb alice', curBNBBal - prevBNBBal) print('∆ ibBNB alice', curIbBNBBal - prevIbBNBBal) assert curBNBBal - prevBNBBal == -(curIbBNBBal - prevIbBNBBal), 'first depositor should get 1:1' assert curBNBBal - prevBNBBal == -deposit_amt # withdraw 1/3 prevBNBBal = alice.balance() prevIbBNBBal = bank.balanceOf(alice) bank.withdraw(curIbBNBBal // 3, {'from': alice}) curBNBBal = alice.balance() curIbBNBBal = bank.balanceOf(alice) print('∆ bnb alice', curBNBBal - prevBNBBal) print('∆ ibBNB alice', curIbBNBBal - prevIbBNBBal) assert curBNBBal - prevBNBBal == -(curIbBNBBal - prevIbBNBBal), 'first depositor should get 1:1' assert curBNBBal - prevBNBBal == deposit_amt // 3 # withdraw remaining prevBNBBal = alice.balance() prevIbBNBBal = bank.balanceOf(alice) bank.withdraw(curIbBNBBal, {'from': alice}) curBNBBal = alice.balance() curIbBNBBal = bank.balanceOf(alice) print('∆ bnb alice', curBNBBal - prevBNBBal) print('∆ ibBNB alice', curIbBNBBal - prevIbBNBBal) assert curBNBBal - prevBNBBal == -(curIbBNBBal - prevIbBNBBal), 'first depositor should get 1:1' assert curBNBBal - prevBNBBal == deposit_amt - deposit_amt // 3
def main(): # deployer = accounts[0] # deployer = accounts.at('0x1dcEf12e93b0aBF2d36f723e8B59Cc762775d513', force=True) deployer = accounts.add( 'eb555556ca1b0a95142fa46019afa8451eb247dee035992742d60aa44316252f') # ==================================== # 部署相关合约 # bank, add_strat, liq_strat, rem_strat, bank_config, goblin_config, oracle = deploy(deployer) # 或者关联到已部署合约 bank_config = ConfigurableInterestBankConfig.at( '0x50D73FF608c6a66b1c36f4a051363cC8a359621d') bank = TransparentUpgradeableProxyImpl.at( '0xF1FB892E5072cE129Af13a795f211598A8931132') bank = interface.IAny(bank) oracle = SimplePriceOracle.at('0xf3e2206a87014A3acE8def4Bd65BE84CC9B2b388') add_strat = StrategyAllHTOnly.at( '0x7Bc24bB9da86C808cf8cBC9ED935AC61068FCD34') liq_strat = StrategyLiquidate.at( '0x04492d6C6bB5439e5916CC792b570DEd6a3563f6') rem_strat = StrategyWithdrawMinimizeTrading.at( '0x5158e8E7a7C45050Cd039802530473b01570f1f2') goblin_config = PancakeswapGoblinConfig.at( '0x21952994097720Db2356B73617F7d03ee9662Eaa') print('bank', bank.address) print('bank_config', bank_config.address) print('all ht', add_strat.address) print('liq', liq_strat.address) print('withdraw', rem_strat.address) print('goblin_config', goblin_config.address) # ==================================== pools = [ { 'name': 'sashimi', 'token': sashimi_address, 'lp': sashimi_lp_address, 'pid': 1, 'goblinConfig': [True, 6250, 7000, 11000] } # ==================================== # 屏蔽无需测试的token # , # { # 'name': 'busd', # 'token': busd_address, # 'lp': busd_lp_address, # 'pid': 2, # 'goblinConfig': [True, 7000, 8000, 11000] # }, # { # "name": "btcb", # "token": btcb_address, # "lp": btcb_lp_address, # "pid": 15, # "goblinConfig": [True, 7000, 8000, 11000] # }, # { # "name": "eth", # "token": eth_address, # "lp": eth_lp_address, # "pid": 14, # "goblinConfig": [True, 7000, 8000, 11000] # }, # { # "name": "usdt", # "token": usdt_address, # "lp": usdt_lp_address, # "pid": 17, # "goblinConfig": [True, 7000, 8000, 11000] # }, # { # "name": "alpha", # "token": alpha_address, # "lp": alpha_lp_address, # "pid": 16, # "goblinConfig": [True, 6250, 7000, 11000] # } # ==================================== ] # ==================================== # deploy pools # registry = deploy_pools(deployer, bank, add_strat, liq_strat, rem_strat, # bank_config, goblin_config, oracle, pools) # 或者使用已部署的池子 registry = {} goblin = PancakeswapPool1Goblin.at( '0xB67e7267fc3180679AC2C4A0C13442C15321670D') add_strat_2 = StrategyAddTwoSidesOptimal.at( '0xe00ff084fe9d67CA6736052aFeb00F2870315F91') registry['sashimi'] = { 'goblin': goblin, 'two_side': add_strat_2, 'token': '0xc2037C1c13dd589e0c14C699DD2498227d2172cC' } print('registry[ sashimi ]:', registry['sashimi']) # ==================================== wht = interface.IAny(wht_address) fToken = interface.IAny(sashimi_address) # oracle.setPrices([wht], [fToken], [10**18 * 300], {'from': deployer, 'gas_price':1000000000}) # # set whitelist tokens to add_strat (no sashimi) # add_fTokens = list(map(lambda pool: pool['token'], pools[1:])) # print('add_fTokens:', add_fTokens) # print('add_strat.setWhitelistTokens ...') # add_strat.setWhitelistTokens(add_fTokens, [True] * len(add_fTokens), {'from': deployer, 'gas_price':1000000000}) # # set whitelist tokens to liq_strat, rem_strat # fTokens = list(map(lambda pool: pool['token'], pools)) # print('fTokens:', fTokens) # print('liq_strat.setWhitelistTokens ...') # liq_strat.setWhitelistTokens(fTokens, [True] * len(fTokens), {'from': deployer, 'gas_price':1000000000}) # print('rem_strat.setWhitelistTokens ...') # rem_strat.setWhitelistTokens(fTokens, [True] * len(fTokens), {'from': deployer, 'gas_price':1000000000}) ######################################################################### # test work print('开始测试token: sashimi ...') print('bank.nextPositionID=', bank.nextPositionID()) print('goblin.health()=', goblin.health(1)) print('goblin.shares[]=', goblin.shares(1)) print('goblin.shareToBalance(goblin.shares[])=', goblin.shareToBalance(goblin.shares(1)))
def deploy(deployer): triple_slope_model = TripleSlopeModel.deploy({ 'from': deployer, 'gas_price': 1000000000 }) # min debt 1 BNB at 10 gwei gas price (avg gas fee = ~0.006 BNB) (killBps 1% -> at least 0.01BNB bonus) # reserve pool bps 2000 (20%) # kill bps 100 (1%) print('部署 bank_config...') bank_config = ConfigurableInterestBankConfig.deploy( 10 * 17, 2000, 100, triple_slope_model, { 'from': deployer, 'gas_price': 1000000000 }) print('部署 ProxyAdminImpl...') proxy_admin = ProxyAdminImpl.deploy({ 'from': deployer, 'gas_price': 1000000000 }) print('部署 Bank...') bank_impl = Bank.deploy({'from': deployer, 'gas_price': 1000000000}) print('部署 TransparentUpgradeableProxyImpl...') bank = TransparentUpgradeableProxyImpl.deploy( bank_impl, proxy_admin, bank_impl.initialize.encode_input(bank_config), { 'from': deployer, 'gas_price': 1000000000 }) bank = interface.IAny(bank) print('部署 SimplePriceOracle...') # oracle = SimplePriceOracle.deploy({'from': deployer, 'gas_price':1000000000}) oracle = SimplePriceOracle.at('0xf3e2206a87014A3acE8def4Bd65BE84CC9B2b388') # strats print('部署 StrategyAllHTOnly... router_address =', router_address) add_strat = StrategyAllHTOnly.deploy(router_address, { 'from': deployer, 'gas_price': 1000000000 }) print('部署 StrategyLiquidate...') liq_strat = StrategyLiquidate.deploy(router_address, { 'from': deployer, 'gas_price': 1000000000 }) print('部署 StrategyWithdrawMinimizeTrading...') rem_strat = StrategyWithdrawMinimizeTrading.deploy(router_address, { 'from': deployer, 'gas_price': 1000000000 }) print('部署 PancakeswapGoblinConfig...') goblin_config = PancakeswapGoblinConfig.deploy(oracle, { 'from': deployer, 'gas_price': 1000000000 }) print('bank', bank.address) print('bank_config', bank_config.address) print('all ht', add_strat.address) print('liq', liq_strat.address) print('withdraw', rem_strat.address) # bank 0x87b8D8337A8086385326fC23b0c95A39cCA2D45D # bank_config 0x86e2Cd710a6fC950506c718b81A8E791b0F24884 # all ht 0x13e60be414955aF08261b9B2B01C012c9B2E1D0E # liq 0x272fFA2cf090815e5cac7B89aD5e3266800f0fF4 # withdraw 0x1d151C966B875188583E35500B3473eB84E75d71 return bank, add_strat, liq_strat, rem_strat, bank_config, goblin_config, oracle
def main(): # deployer = accounts[0] # deployer = accounts.at('0x1dcEf12e93b0aBF2d36f723e8B59Cc762775d513', force=True) deployer = accounts.add( 'eb555556ca1b0a95142fa46019afa8451eb247dee035992742d60aa44316252f') alice = accounts.add( 'a8060afe2390bd0c00c7ef800f545d466b55cc84d4ad6d01e03220af03e97982') bob = accounts.add( '7b9009958a83807bbe38bf35f451ff0c4bf4d926cee63dd07658762db58ceba4') # =====开始:重新部署合约=============================== # print('1 部署 银行配置合约...') # print(' 部署3段式利率模型 triple_slope_model...') # triple_slope_model = TripleSlopeModel.deploy({'from': deployer}) # print(' 部署可配银行配置合约 ConfigurableInterestBankConfig...') # print(' min debt 0.2 HT at 10 gwei gas price (avg gas fee = ~0.006 HT) (killBps 1% -> at least 0.01BNB bonus)') # print(' reserve pool bps 2000 (20%)') # print(' kill bps 100 (1%)') # bank_config = ConfigurableInterestBankConfig.deploy( # 2 * 10*17, 2000, 100, triple_slope_model, {'from': deployer}) # print('2 部署 银行合约...') # print(' 部署 ProxyAdminImpl...') # proxy_admin = ProxyAdminImpl.deploy({'from': deployer}) # print(' 部署 Bank...') # bank_impl = Bank.deploy({'from': deployer}) # print(' 部署 TransparentUpgradeableProxyImpl...') # bank = TransparentUpgradeableProxyImpl.deploy( # bank_impl, proxy_admin, bank_impl.initialize.encode_input(bank_config), {'from': deployer}) # bank = interface.IAny(bank) # print('3 部署 测试用的预言机合约...') # print(' 部署 SimplePriceOracle...') # # oracle = SimplePriceOracle.deploy({'from': deployer}) # oracle = SimplePriceOracle.at('0xf3e2206a87014A3acE8def4Bd65BE84CC9B2b388') # # strats # print('4 部署 策略合约...') # print(' 部署 StrategyAllHTOnly... router_address =',router_address) # add_strat = StrategyAllHTOnly.deploy(router_address, {'from': deployer}) # print(' 部署流动性策略 StrategyLiquidate...') # liq_strat = StrategyLiquidate.deploy(router_address, {'from': deployer}) # print(' 部署提款策略 StrategyWithdrawMinimizeTrading...') # rem_strat = StrategyWithdrawMinimizeTrading.deploy(router_address, {'from': deployer}) # print(' 部署goblin的配置,传入oracle合约地址 PancakeswapGoblinConfig...') # goblin_config = PancakeswapGoblinConfig.deploy(oracle, {'from': deployer}) # =====结束:重新部署合约=============================== # ==================================== # 或者关联到已部署合约 bank_config = ConfigurableInterestBankConfig.at( '0x50D73FF608c6a66b1c36f4a051363cC8a359621d') bank = TransparentUpgradeableProxyImpl.at( '0xF1FB892E5072cE129Af13a795f211598A8931132') bank = interface.IAny(bank) oracle = SimplePriceOracle.at('0xf3e2206a87014A3acE8def4Bd65BE84CC9B2b388') add_strat = StrategyAllHTOnly.at( '0x7Bc24bB9da86C808cf8cBC9ED935AC61068FCD34') liq_strat = StrategyLiquidate.at( '0x04492d6C6bB5439e5916CC792b570DEd6a3563f6') rem_strat = StrategyWithdrawMinimizeTrading.at( '0x5158e8E7a7C45050Cd039802530473b01570f1f2') goblin_config = PancakeswapGoblinConfig.at( '0x21952994097720Db2356B73617F7d03ee9662Eaa') # ==================================== print(' 部署后合约地址汇总:') print(' bank', bank.address) print(' bank_config', bank_config.address) print(' all ht', add_strat.address) print(' liq', liq_strat.address) print(' withdraw', rem_strat.address) print(' goblin_config', goblin_config.address) pools = [{ 'name': 'sashimi', 'token': sashimi_address, 'lp': sashimi_lp_address, 'pid': 1, 'goblinConfig': [True, 6250, 7000, 11000] }] wht = interface.IAny(wht_address) print(' WHT的地址是:', wht_address) # =====开始:重新配置交易池=============================== # registry = {} # print('5 部署交易池...') # for pool in pools: # print(' ==============================') # print(' 部署交易对:wht -',pool['name'],'地址是:',pool['token']) # fToken = interface.IAny(pool['token']) # if pool['pid'] == 1: # # reinvest 0.3% (avg gas fee ~0.006 BNB) # print(' 部署 pid=1 的交易对的gobilin PancakeswapPool1Goblin ... reinvest 0.3%') # goblin = PancakeswapPool1Goblin.deploy( # ank, # chef_address, # router_address, # add_strat, # liq_strat, # 30, # {'from': deployer}) # else: # # reinvest 0.3% (avg gas fee ~0.006 BNB) # print(' 部署 pid>1 的交易对的gobilin PancakeswapGoblin ... reinvest 0.3%') # goblin = PancakeswapGoblin.deploy( # bank, # chef_address, # router_address, # pool['pid'], # add_strat, # liq_strat, # 30, # {'from': deployer}) # print(' 配置goblin的配置数据到配置合约中 goblin_config.setConfigs ...',pool['goblinConfig']) # goblin_config.setConfigs([goblin], [pool['goblinConfig']], {'from': deployer}) # print(' 部署双边策略合约:add_strat_2 StrategyAddTwoSidesOptimal ...') # add_strat_2 = StrategyAddTwoSidesOptimal.deploy( # router_address, goblin, fToken, {'from': deployer}) # print(' 配置双边策略add_strat_2到 goblin goblin.setStrategyOk ...') # goblin.setStrategyOk([add_strat_2, rem_strat], True, {'from': deployer}) # print(' 配置goblin到银行配置合约 bank_config.setGoblins ...') # bank_config.setGoblins([goblin], [goblin_config], {'from': deployer}) # # re-assign two side strat as add strat for pool 1 goblin # if pool['pid'] == 1: # print(' 对于pid=1的交易池 配置更严格的策略add_strat_2到goblin ...') # goblin.setCriticalStrategies(add_strat_2, liq_strat, {'from': deployer}) # print(' 配置add_strat到goblin goblin.setStrategyOk ...') # goblin.setStrategyOk([add_strat], False, {'from': deployer}) # unset add_strat # registry[pool['name']] = {'goblin': goblin, # 'two_side': add_strat_2, # 'token': fToken.address} # print(' 交易池配置完成!! registry[',pool["name"],']:',registry[pool['name']]) # =====结束:重新配置交易池=============================== # 或者使用已部署的池子 registry = {} goblin = PancakeswapPool1Goblin.at( '0xB67e7267fc3180679AC2C4A0C13442C15321670D') add_strat_2 = StrategyAddTwoSidesOptimal.at( '0xe00ff084fe9d67CA6736052aFeb00F2870315F91') registry['sashimi'] = { 'goblin': goblin, 'two_side': add_strat_2, 'token': '0xc2037C1c13dd589e0c14C699DD2498227d2172cC' } print('registry[ sashimi ]:', registry['sashimi']) # ==================================== wht = interface.IAny(wht_address) sashimi = interface.IAny(sashimi_address) lp = interface.IAny(sashimi_lp_address) r0, r1, _ = lp.getReserves() sashimi_price = r1 * 10**18 // r0 # in bnb oracle.setPrices([sashimi], [wht], [sashimi_price], {'from': deployer}) print('6 配置交易对的价格 sashimi对wht的价格的价格是', sashimi_price / 10**18) print(' lptoken 总供应量是:', lp.totalSupply() / 10**18) print(' 当前bank存款:', bank.totalSupply() / 10**18) # set whitelist tokens to add_strat (no sashimi) add_fTokens = list(map(lambda pool: pool['token'], pools[1:])) print('add_fTokens:', add_fTokens) print('add_strat.setWhitelistTokens ...') add_strat.setWhitelistTokens(add_fTokens, [True] * len(add_fTokens), { 'from': deployer, 'gas_price': 1000000000 }) # set whitelist tokens to liq_strat, rem_strat fTokens = list(map(lambda pool: pool['token'], pools)) print('fTokens:', fTokens) print('liq_strat.setWhitelistTokens ...') liq_strat.setWhitelistTokens(fTokens, [True] * len(fTokens), {'from': deployer}) print('rem_strat.setWhitelistTokens ...') rem_strat.setWhitelistTokens(fTokens, [True] * len(fTokens), {'from': deployer}) # mint tokens # mint_tokens(sashimi, alice) # approve tokens sashimi.approve(add_strat_2, 2**256 - 1, {'from': alice}) wht.approve(bank, 2**256 - 1, {'from': alice}) ######################################################################### # test work print(' 开始测试token: sashimi ...') print(' bank.nextPositionID=', bank.nextPositionID()) print(' 接收债务吗? ', bank_config.acceptDebt(registry['sashimi']['goblin'])) print(' minDebtSize= ', bank_config.minDebtSize()) print( ' minDebtSize.workFactor= ', bank_config.workFactor(registry['sashimi']['goblin'], bank_config.minDebtSize())) print(' workFactor= ', bank_config.workFactor(registry['sashimi']['goblin'], 10**17)) # ======================== prevBNBBal = alice.balance() bank.work( 0, registry['sashimi']['goblin'], 10**17, 0, eth_abi.encode_abi(['address', 'bytes'], [ registry['sashimi']['two_side'].address, eth_abi.encode_abi(['address', 'uint256', 'uint256'], [registry['sashimi']['token'], 0, 0]) ]), { 'from': alice, 'value': '0.05 ether', 'gas_price': 1000000000 }) curBNBBal = alice.balance() print(' bank.nextPositionID=', bank.nextPositionID()) pos_id = bank.nextPositionID() - 1 print(' goblin.health=', goblin.health(pos_id)) print(' goblin.shares=', goblin.shares(pos_id)) print(' goblin.shareToBalance(goblin.shares)=', goblin.shareToBalance(goblin.shares(pos_id))) print(' ∆ ht alice', curBNBBal - prevBNBBal) print(' alice pos', bank.positionInfo(pos_id))