def test_estimated_total_assets(strategy, gov, hegic, hegicStaking): hegic.approve(gov, 2 ** 256 - 1, {"from": gov}) hegicStaking.approve(gov, 2 ** 256 - 1, {"from": gov}) # For test simplicity, transfer to the strategy without going through the vault hegic.transferFrom(gov, strategy, Wei("100 ether"), {"from": gov}) hegicStaking.transferFrom(gov, strategy, 1, {"from": gov}) assert strategy.estimatedTotalAssets() == Wei("888100 ether")
def test_operation_lpstrat( currencyLP, strategylp, chain, vaultlp, whaleLP, gov, bob, alice, strategist, guardian, interface, ): # Amount configs test_budget = Wei("88 ether") approve_amount = Wei("100 ether") deposit_limit = Wei("88 ether") bob_deposit = Wei("10 ether") alice_deposit = Wei("78 ether") currencyLP.approve(whaleLP, approve_amount, {"from": whaleLP}) currencyLP.transferFrom(whaleLP, gov, test_budget, {"from": whaleLP}) vaultlp.setDepositLimit(deposit_limit) # 100% of the vault's depositLimit vaultlp.addStrategy(strategylp, 10_000, 0, 2**256 - 1, 0, {"from": gov}) currencyLP.approve(gov, approve_amount, {"from": gov}) currencyLP.transferFrom(gov, bob, bob_deposit, {"from": gov}) currencyLP.transferFrom(gov, alice, alice_deposit, {"from": gov}) currencyLP.approve(vaultlp, approve_amount, {"from": bob}) currencyLP.approve(vaultlp, approve_amount, {"from": alice}) vaultlp.deposit(bob_deposit, {"from": bob}) vaultlp.deposit(alice_deposit, {"from": alice}) # Sleep and harvest 5 times sleepAndHarvest(5, strategylp, gov) # Log estimated APR growthInShares = vaultlp.pricePerShare() - 1e18 growthInPercent = (growthInShares / 1e18) * 100 growthInPercent = growthInPercent * 24 growthYearly = growthInPercent * 365 print(f"Yearly APR :{growthYearly}%") print(vaultlp.pricePerShare() / 1e18) # We should have made profit or stayed stagnant (This happens when there is no rewards in 1INCH rewards) assert vaultlp.pricePerShare() / 1e18 >= 1 # Withdraws should not fail vaultlp.withdraw(alice_deposit, {"from": alice}) vaultlp.withdraw(bob_deposit, {"from": bob}) # Depositors after withdraw should have a profit or gotten the original amount assert currencyLP.balanceOf(alice) >= alice_deposit assert currencyLP.balanceOf(bob) >= bob_deposit # Make sure it isnt less than 1 after depositors withdrew assert vaultlp.pricePerShare() / 1e18 >= 1
def test_add_keeper(live_vault_dai2, Contract, web3, accounts, chain, cdai, comp, dai, live_strategy_dai2,currency, whale,samdev): strategist = samdev strategy = live_strategy_dai2 vault = live_vault_dai2 #stateOfStrat(strategy, dai, comp) #genericStateOfVault(vault, dai) keeper = Contract.from_explorer("0x13dAda6157Fee283723c0254F43FF1FdADe4EEd6") kp3r = Contract.from_explorer("0x1cEB5cB57C4D4E2b2433641b95Dd330A33185A44") #strategy.setKeeper(keeper, {'from': strategist}) #carlos = accounts.at("0x73f2f3A4fF97B6A6d7afc03C449f0e9a0c0d90aB", force=True) #keeper.addStrategy(strategy, 1700000, 10, {'from': carlos}) bot = accounts.at("0xfe56a0dbdad44Dd14E4d560632Cc842c8A13642b", force=True) assert keeper.harvestable(strategy) == False depositAmount = Wei('3500 ether') deposit(depositAmount, whale, currency, vault) assert keeper.harvestable(strategy) == False depositAmount = Wei('1000 ether') deposit(depositAmount, whale, currency, vault) assert keeper.harvestable(strategy) == True keeper.harvest(strategy, {'from': bot}) balanceBefore = kp3r.balanceOf(bot) #print(tx.events) chain.mine(4) #assert kp3r.balanceOf(bot) > balanceBefore #strategy.harvest({'from': strategist}) assert keeper.harvestable(strategy) == False stateOfStrat(strategy, dai, comp) genericStateOfVault(vault, dai) #stateOfStrat(strategy, dai, comp) #stateOfVault(vault, strategy) #depositAmount = Wei('1000 ether') #deposit(depositAmount, whale, currency, vault) #stateOfStrat(strategy, dai, comp) #genericStateOfVault(vault, dai) #strategy.harvest({'from': strategist}) #stateOfStrat(strategy, dai, comp) #genericStateOfVault(vault, dai)
def test_harvest_trigger_with_profit(gov, vault, hegic, hegicStaking, strategy): hegic.approve(vault, 2**256 - 1, {"from": gov}) vault.addStrategy(strategy, 10_000, 0, 0, {"from": gov}) vault.deposit(Wei("888000 ether"), {"from": gov}) strategy.harvest() assert hegicStaking.balanceOf(strategy) == 1 hegicStaking.sendProfit({"value": Wei("1 ether")}) assert strategy.harvestTrigger(1) == True
def test_toomany_boxes_at_once(nftbox, voucher, minter, accounts, chain): voucher.setCaller(nftbox, True, {'from':minter}) nftbox.setBoxVoucher(voucher, {'from':minter}) nftbox.createBoxMould(50, 5, 0, Wei('0.1 ether'), [], [], "This is a test box", "", "", "", "", {'from':minter}) nftbox.setLockOnBox(1, False, {'from':minter}) nftbox.distributeReservedBoxes(1, 20, {'from':minter}) chain.sleep(901) with brownie.reverts("!buy"): nftbox.buyManyBoxes(1, 6, {'from':accounts[0], "value": Wei("0.1 ether") * 6}) nftbox.buyManyBoxes(1, 5, {'from':accounts[0], "value": Wei("0.1 ether") * 5})
def test_not_buyable_edition_over(nftbox, voucher, minter, accounts, chain): voucher.setCaller(nftbox, True, {'from':minter}) nftbox.setBoxVoucher(voucher, {'from':minter}) nftbox.createBoxMould(5, 5, 0, Wei('0.01 ether'), [], [], "This is a test box", "", "", "", "", {'from':minter}) nftbox.setLockOnBox(1, False, {'from':minter}) nftbox.distributeReservedBoxes(1, 20, {'from':minter}) chain.sleep(901) nftbox.buyManyBoxes(1, 5, {'from':accounts[0], "value": Wei("0.01 ether") * 5}) with brownie.reverts("!live"): nftbox.buyManyBoxes(1, 1, {'from':accounts[0], "value": Wei("0.01 ether")})
def test_buy_stake(gov, vault, hegic, hegicStaking, strategy): hegic.approve(vault, 2**256 - 1, {"from": gov}) vault.addStrategy(strategy, 10_000, 0, 0, {"from": gov}) # deposit 1MM in total to test vault.deposit(Wei("1000000 ether"), {"from": gov}) strategy.harvest() assert hegicStaking.balanceOf(strategy) == 1 assert hegic.balanceOf(strategy) == Wei("112000 ether")
def test_claim_token(accounts, launcpadWL, distributor, dai, niftsy20, weth, ERC721Distr): #token is claimed. try to claim again with reverts("ERC721: operator query for nonexistent token"): launcpadWL.claimNFT(1, zero_address, {"value": '0.01 ether'}) #not allowed token to pay with reverts("Cant pay with this ERC20"): launcpadWL.claimNFT(2, weth) #not enough tokens dai.transfer(accounts[1], dai.balanceOf(accounts[0]) - 1, {"from": accounts[0]}) payAmount = launcpadWL.getWNFTPrice(2, dai) dai.approve(launcpadWL, payAmount, {"from": accounts[0]}) with reverts("ERC20: transfer amount exceeds balance"): launcpadWL.claimNFT(2, dai) #enough tokens and send ether dai.transfer(accounts[0], payAmount, {"from": accounts[1]}) bbDAI0 = dai.balanceOf(accounts[0]) bbeL = launcpadWL.balance() with reverts("No need ether"): launcpadWL.claimNFT(2, dai, {"value": '1 ether'}) launcpadWL.claimNFT(2, dai, {"from": accounts[0]}) assert dai.balanceOf( accounts[0]) == bbDAI0 - launcpadWL.getWNFTPrice(2, dai) assert dai.balanceOf(launcpadWL) == launcpadWL.getWNFTPrice(2, dai) #assert launcpadWL.balance() == bbeL + Wei('1 ether') assert launcpadWL.balance() == bbeL assert distributor.balanceOf(launcpadWL) == COUNT - 2 assert distributor.balanceOf(accounts[0]) == 1 #unwrap claimed token bbe0 = accounts[0].balance() bbn0 = niftsy20.balanceOf(accounts[0]) bbw0 = weth.balanceOf(accounts[0]) bbeD = distributor.balance() bbnD = niftsy20.balanceOf(distributor) bbwD = weth.balanceOf(distributor) distributor.unWrap721(2) assert bbe0 + Wei(ETH_AMOUNT) / COUNT == accounts[0].balance() assert bbn0 + ERC20_COLLATERAL_AMOUNT == niftsy20.balanceOf(accounts[0]) assert bbw0 + ERC20_COLLATERAL_AMOUNT_WETH == weth.balanceOf(accounts[0]) assert bbeD - Wei(ETH_AMOUNT) / COUNT == distributor.balance() assert bbnD - ERC20_COLLATERAL_AMOUNT == niftsy20.balanceOf(distributor) assert bbwD - ERC20_COLLATERAL_AMOUNT_WETH == weth.balanceOf(distributor) assert distributor.balanceOf(accounts[0]) == 0 assert ERC721Distr.balanceOf(accounts[0]) == 2
def test_dai(Vault, StrategyDAI3pool, dai_vault, dai_whale, gov, dai): # deploy dai strategy dai_strategy = gov.deploy(StrategyDAI3pool, dai_vault) print(f'type of strategy: {type(dai_strategy)} @ {dai_strategy}') # activate the strategy from vault view dai_vault.addStrategy(dai_strategy, 2**64, 2**64, 1000, {'from': gov}) print(f'credit of strategy: {dai_vault.creditAvailable(dai_strategy)}') # rm yvdai's guestlist dai_vault.setGuestList('0x0000000000000000000000000000000000000000', {'from': gov}) print(f'yvdai guest list: {dai_vault.guestList()}') # approve dai vault to use dai dai.approve(dai_vault, 2**256 - 1, {'from': dai_whale}) # start deposit print('\n=== deposit 100 dai ===') print( f'whale\'s dai balance before deposit: {dai.balanceOf(dai_whale)/1e18}' ) deposit_amount = Wei('100 ether') dai_vault.deposit(deposit_amount, {'from': dai_whale}) print( f'whale\'s dai balance after deposit: {dai.balanceOf(dai_whale)/1e18}' ) # start strategy print('\n=== harvest dai ===') dai_strategy.harvest({'from': gov}) print('harvest done') print('\n=== dai status ===') genericStateOfStrat(dai_strategy, dai, dai_vault) genericStateOfVault(dai_vault, dai) # withdraw print('\n=== withdraw dai ===') print(f'whale\'s dai vault share: {dai_vault.balanceOf(dai_whale)/1e18}') dai_vault.withdraw(Wei('1 ether'), {'from': dai_whale}) print(f'withdraw 1 share of dai done') print(f'whale\'s dai vault share: {dai_vault.balanceOf(dai_whale)/1e18}') # withdraw all print('\n=== withdraw all dai ===') print(f'whale\'s dai vault share: {dai_vault.balanceOf(dai_whale)/1e18}') dai_vault.withdraw({'from': dai_whale}) print(f'withdraw all dai') print(f'whale\'s dai vault share: {dai_vault.balanceOf(dai_whale)/1e18}') # call tend print('\ncall tend') dai_strategy.tend() print('tend done')
def test_zap(accounts, ZapYvecrvSwapSeth, vault_ecrv_live): whale = accounts.at("0xbe0eb53f46cd790cd13851d5eff43d12404d33e8", force=True) zap = whale.deploy(ZapYvecrvSwapSeth) vault_ecrv_live.approve(zap.address, 2**256 - 1, {"from": whale}) print("Zap In 100 ETH eCRV estimates") print("----------------------------") lpTokenEstimate, _ = zap.estimateZapIn(Wei("100 ether"), 0) lpTokenEstimatePretty = lpTokenEstimate / Wei("1 ether") print(f" 0% swap: {lpTokenEstimatePretty} eCRV") lpTokenEstimate, _ = zap.estimateZapIn(Wei("100 ether"), 50) lpTokenEstimatePretty = lpTokenEstimate / Wei("1 ether") print(f" 50% swap: {lpTokenEstimatePretty} eCRV") lpTokenEstimate, _ = zap.estimateZapIn(Wei("100 ether"), 100) lpTokenEstimatePretty = lpTokenEstimate / Wei("1 ether") print(f"100% swap: {lpTokenEstimatePretty} eCRV") print("") print("Zap In 100 ETH actuals") print("----------------------------") zap.zapIn(0, {"from": whale, "value": Wei("100 ether")}) yvTokens = vault_ecrv_live.balanceOf(whale) yvTokensPretty = yvTokens / Wei("1 ether") print(f"Zap in: {yvTokensPretty} yveCRV") startingEthBalance = whale.balance() zap.zapOut(yvTokens, 0, {"from": whale}) zappedOutEth = whale.balance() - startingEthBalance zappedOutEthPretty = zappedOutEth / Wei("1 ether") print(f"Zap out: {zappedOutEthPretty} ETH")
def test_many_at_once(nftbox, voucher, minter, accounts, chain): voucher.setCaller(nftbox, True, {'from': minter}) nftbox.setBoxVoucher(voucher, {'from': minter}) nftbox.createBoxMould(30, 30, 0, Wei('0.01 ether'), [], [], "This is a test box", "", "", "", "", {'from': minter}) nftbox.createBoxMould(20, 20, 0, Wei('0.1 ether'), [], [], "This is a test box", "", "", "", "", {'from': minter}) nftbox.setLockOnBox(1, False, {'from': minter}) nftbox.setLockOnBox(2, False, {'from': minter}) nftbox.distributeReservedBoxes(1, 20, {'from': minter}) nftbox.distributeReservedBoxes(2, 20, {'from': minter}) chain.sleep(901) nftbox.buyManyBoxes(2, 5, { 'from': accounts[0], "value": Wei("0.1 ether") * 5 }) supply = nftbox.totalSupply() for i in range(10): nftbox.buyManyBoxes(1, 1, { 'from': accounts[0], "value": Wei("0.01 ether") }) assert nftbox.ownerOf(2 * i + supply + 1) == accounts[0] assert nftbox.boxes(2 * i + supply + 1) == (1, i * 2 + 1) nftbox.buyManyBoxes(1, 1, { 'from': accounts[1], "value": Wei("0.01 ether") }) assert nftbox.ownerOf(2 * i + supply + 2) == accounts[1] assert nftbox.boxes(2 * i + 2 + supply) == (1, i * 2 + 1 + 1) nftbox.buyManyBoxes(1, 5, { 'from': accounts[0], "value": Wei("0.01 ether") * 5 }) with brownie.reverts("NFTBoxes: !price"): nftbox.buyManyBoxes(1, 5, { 'from': accounts[0], "value": Wei("0.01 ether") }) nftbox.buyManyBoxes(1, 5, { 'from': accounts[0], "value": Wei("0.01 ether") * 5 }) with brownie.reverts("NFTBoxes: Too many boxes"): nftbox.buyManyBoxes(1, 5, { 'from': accounts[0], "value": Wei("0.01 ether") * 5 }) with brownie.reverts("NFTBoxes: Too many boxes"): nftbox.buyManyBoxes(1, 1, { 'from': accounts[0], "value": Wei("0.01 ether") })
def test_vault_shares_generic( strategy, web3, chain, vault, currency, whale, strategist, gov ): deposit_limit = Wei("1000 ether") # set limit to the vault vault.setDepositLimit(deposit_limit, {"from": gov}) vault.addStrategy(strategy, 10_000, 0, 2 ** 256 - 1, 0, {"from": gov}) print(currency) assert vault.totalSupply() == 0 amount1 = Wei("50 ether") deposit(amount1, whale, currency, vault) whale_share = vault.balanceOf(whale) deposit(amount1, gov, currency, vault) gov_share = vault.balanceOf(gov) assert gov_share == whale_share assert vault.pricePerShare() == 1e18 assert vault.pricePerShare() * whale_share / 1e18 == amount1 assert vault.pricePerShare() * whale_share / 1e18 == vault.totalAssets() / 2 assert gov_share == whale_share strategy.harvest({"from": gov}) chain.mine(2) chain.sleep(2) strategy.harvest({"from": gov}) # no profit yet whale_share = vault.balanceOf(whale) gov_share = vault.balanceOf(gov) assert gov_share > whale_share sleep(chain, 100) whale_share = vault.balanceOf(whale) gov_share = vault.balanceOf(gov) # no profit just aum fee. meaning total balance should be the same assert (gov_share + whale_share) * vault.pricePerShare() / 1e18 == 100 * 1e18 strategy.harvest({"from": gov}) whale_share = vault.balanceOf(whale) gov_share = vault.balanceOf(gov) # add strategy return assert vault.totalSupply() == whale_share + gov_share value = (gov_share + whale_share) * vault.pricePerShare() / 1e18 assert ( value * 0.99999 < vault.totalAssets() and value * 1.00001 > vault.totalAssets() ) # check we are within 0.1% of expected returns assert ( value < strategy.estimatedTotalAssets() * 1.001 and value > strategy.estimatedTotalAssets() * 0.999 ) assert gov_share > whale_share
def test_wrapped_props(accounts, distributor, launcpadWLNative, dai, niftsy20): for i in range(distributor.balanceOf(launcpadWLNative)): logging.info('tokenId={}, etherBalance={}'.format( distributor.tokenOfOwnerByIndex(launcpadWLNative, i), Wei( distributor.getTokenValue( distributor.tokenOfOwnerByIndex(launcpadWLNative, i))[0]).to('ether'))) assert distributor.getTokenValue( distributor.tokenOfOwnerByIndex(launcpadWLNative, i))[0] == Wei(ETH_AMOUNT) / COUNT
def test_vault_shares_generic(strategy_changeable, web3, chain, Vault, currency, whale, strategist): gov = strategist vault = strategist.deploy(Vault, currency, strategist, strategist, "TestVault", "Amount") deposit_limit = Wei('1000 ether') #set limit to the vault vault.setDepositLimit(deposit_limit, {"from": strategist}) #deploy strategy strategy = strategist.deploy(strategy_changeable, vault) vault.addStrategy(strategy, deposit_limit, deposit_limit, 50, {"from": strategist}) amount1 = Wei('50 ether') deposit(amount1, whale, currency, vault) whale_share = vault.balanceOf(whale) deposit(amount1, gov, currency, vault) gov_share = vault.balanceOf(gov) assert gov_share == whale_share assert vault.pricePerShare() == 1e18 assert vault.pricePerShare() * whale_share / 1e18 == amount1 assert vault.pricePerShare() * whale_share / 1e18 == vault.totalAssets( ) / 2 assert gov_share == whale_share strategy.harvest({'from': gov}) #no profit yet whale_share = vault.balanceOf(whale) gov_share = vault.balanceOf(gov) assert gov_share > whale_share wait(100, chain) whale_share = vault.balanceOf(whale) gov_share = vault.balanceOf(gov) # no profit just aum fee. meaning total balance should be the same assert (gov_share + whale_share) * vault.pricePerShare() / 1e18 == 100 * 1e18 strategy.harvest({'from': gov}) whale_share = vault.balanceOf(whale) gov_share = vault.balanceOf(gov) #add strategy return assert vault.totalSupply() == whale_share + gov_share value = (gov_share + whale_share) * vault.pricePerShare() / 1e18 assert value == 100 * 1e18 + vault.strategies(strategy)[6] #check we are within 0.1% of expected returns assert value < strategy.estimatedTotalAssets( ) * 1.001 and value > strategy.estimatedTotalAssets() * 0.999 assert gov_share > whale_share
def test_wrong_price(nftbox, voucher, minter, accounts, chain): voucher.setCaller(nftbox, True, {'from':minter}) nftbox.setBoxVoucher(voucher, {'from':minter}) nftbox.createBoxMould(50, 50, 0, Wei('0.01 ether'), [], [], "This is a test box", "", "", "", "", {'from':minter}) nftbox.setLockOnBox(1, False, {'from':minter}) nftbox.distributeReservedBoxes(1, 20, {'from':minter}) chain.sleep(901) for j in range(5): nftbox.buyManyBoxes(1, 1, {'from':accounts[0], "value": Wei("0.01 ether")}) with brownie.reverts("!price"): nftbox.buyManyBoxes(1, 1, {'from':accounts[0], "value": Wei("1 ether")})
def test_usdt(Vault, StrategyUSDT3pool, usdt_whale, gov, usdt): # deploy usdt vault usdt_vault = gov.deploy(Vault, usdt, gov, gov, '', '') print(f'type of vault: {type(usdt_vault)} @ {usdt_vault}') # deploy usdt strategy usdt_strategy = gov.deploy(StrategyUSDT3pool, usdt_vault) print(f'type of strategy: {type(usdt_strategy)} @ {usdt_strategy}') # activate the strategy from vault view usdt_vault.addStrategy(usdt_strategy, 2**64, 2**64, 1000, {'from': gov}) print(f'credit of strategy: {usdt_vault.creditAvailable(usdt_strategy)}') # rm yvusdt's guestlist usdt_vault.setGuestList('0x0000000000000000000000000000000000000000', {'from': gov}) print(f'yvusdt guest list: {usdt_vault.guestList()}') # approve usdt vault to use usdt usdt.approve(usdt_vault, 2**256-1, {'from': usdt_whale}) # start deposit print('\n=== deposit 100 usdt ===') print(f'whale\'s usdt balance before deposit: {usdt.balanceOf(usdt_whale)/1e6}') deposit_amount = Wei('100 ether')/1e12 usdt_vault.deposit(deposit_amount, {'from': usdt_whale}) print(f'whale\'s usdt balance after deposit: {usdt.balanceOf(usdt_whale)/1e6}') # start strategy print('\n=== harvest usdt ===') usdt_strategy.harvest({'from': gov}) print('harvest done') print('\n=== usdt status ===') genericStateOfStrat(usdt_strategy, usdt, usdt_vault) genericStateOfVault(usdt_vault, usdt) # withdraw print('\n=== withdraw usdt ===') print(f'whale\'s usdt vault share: {usdt_vault.balanceOf(usdt_whale)/1e6}') usdt_vault.withdraw(Wei('1 ether')/1e12, {'from': usdt_whale}) print(f'withdraw 1 share of usdt done') print(f'whale\'s usdt vault share: {usdt_vault.balanceOf(usdt_whale)/1e6}') # withdraw all print('\n=== withdraw all usdt ===') print(f'whale\'s usdt vault share: {usdt_vault.balanceOf(usdt_whale)/1e6}') usdt_vault.withdraw({'from': usdt_whale}) print(f'withdraw all usdt') print(f'whale\'s usdt vault share: {usdt_vault.balanceOf(usdt_whale)/1e6}') # call tend print('\ncall tend') usdt_strategy.tend() print('tend done')
def main(): badger = connect_badger("deploy-final.json") admin = badger.devProxyAdmin multisig = badger.devMultisig contracts = badger.contracts_upgradeable deployer = badger.deployer expectedMultisig = "0xB65cef03b9B89f99517643226d76e286ee999e77" assert multisig == expectedMultisig """ Total $BADGER 603,750 Setts renbtcCRV — 83,437.5 $BADGER sbtcCRV — 83,437.5 $BADGER tbtcCRV — 83,437.5 $BADGER Badger — 70,000 $BADGER (NEW) wBTC/ETH Sushiswap LP — 40,000 $BADGER Badger <>wBTC Uniswap LP — 110,000 $BADGER (NEW) Badger <>wBTC Sushiswap LP— 50,000 $BADGER wbtc/eth = 34,285 $BADGER (which should be distributed evenly over 3 days ie today 1pm to tomorrow, tomorrow to wednesday, wed- thursday then new emissions) Badger <>wBTC Sushiswap LP— 30,000 $BADGER (10k/day) Super Sett Harvest renbtc CRV —83,437.5 $BADGER """ rest = RewardsSchedule(badger) rest.setStart(to_timestamp(datetime.datetime(2020, 12, 31, 12, 00))) rest.setDuration(days(7)) rest.setAmounts({ "native.renCrv": Wei("83437.5 ether"), "native.sbtcCrv": Wei("83437.5 ether"), "native.tbtcCrv": Wei("83437.5 ether"), "native.badger": Wei("60000 ether"), "native.sushiWbtcEth": Wei("80000 ether"), "native.uniBadgerWbtc": Wei("80000 ether"), "native.sushiBadgerWbtc": Wei("80000 ether"), "harvest.renCrv": Wei("83437.5 ether"), }) rest.testTransactions() rest.printState("Week 5 - Sushi Continues") total = rest.total expected = Wei("633750 ether") print("overall total ", total) print("expected total ", expected) assert total == expected console.print("\n[green] ✅ Total matches expected {} [/green]".format( val(expected)))
def test_getLoanParams(bzx, accounts, SUSD, WETH, loanParamsId, loanParams): loanParamsAfter = bzx.getLoanParams([loanParamsId])[0] loanParamsAfter = dict(zip(list(loanParams.keys()), loanParamsAfter)) print("loanParamsAfter", loanParamsAfter) assert (loanParamsAfter["id"] != "0x0") assert (loanParamsAfter["active"]) assert (loanParamsAfter["owner"] == accounts[0]) assert (loanParamsAfter["loanToken"] == SUSD.address) assert (loanParamsAfter["collateralToken"] == WETH.address) assert (loanParamsAfter["initialMargin"] == Wei("50 ether")) assert (loanParamsAfter["maintenanceMargin"] == Wei("15 ether")) assert (loanParamsAfter["fixedLoanTerm"] == "2419200")
def test_add_collateral(accounts, wrapper): native_collateral_before = wrapper.getWrappedToken( wrapper.lastWrappedNFTId())[2] tx = wrapper.addNativeCollateral(wrapper.lastWrappedNFTId(), { 'from': accounts[0], 'value': ADD_NATIVE_COLLATERAL }) logging.info('getWrappedToken {}'.format( wrapper.getWrappedToken(wrapper.lastWrappedNFTId()))) assert Wei( wrapper.getWrappedToken(wrapper.lastWrappedNFTId())[2] - native_collateral_before) == Wei(ADD_NATIVE_COLLATERAL)
def test_min_deposit(vault, gov, hegic, hegicStaking, strategy): # Minimal constructor test assert strategy.name() == "StrategyHegicETH" # Send 1 hegic which shouldn't be enough to buy a lot hegic.approve(vault, 2**256 - 1, {"from": gov}) vault.addStrategy(strategy, 10_000, 0, 0, {"from": gov}) vault.deposit(Wei("1 ether"), {"from": gov}) strategy.harvest() assert hegic.balanceOf(strategy) == Wei("1 ether") assert hegicStaking.balanceOf(strategy) == 0
def test_many_of_one(nftbox, minter, accounts): nftbox.createBoxMould(50, Wei('0.01 ether'), [1, 2, 3, 4], [], [], "This is a test box", {'from':minter}) nftbox.createBoxMould(20, Wei('0.1 ether'), [1, 2, 3, 4], [], [], "This is a test box", {'from':minter}) nftbox.buyManyBoxes(2, 5, {'from':accounts[0], "value": Wei("0.1 ether") * 5}) supply = nftbox.totalSupply() for i in range(10): nftbox.buyManyBoxes(1, 1, {'from':accounts[0], "value": Wei("0.01 ether")}) assert nftbox.ownerOf(2 * i + supply) == accounts[0] assert nftbox.boxes(2 * i + supply) == (1, i * 2) nftbox.buyManyBoxes(1, 1, {'from':accounts[1], "value": Wei("0.01 ether")}) assert nftbox.ownerOf(2 * i + supply + 1) == accounts[1] assert nftbox.boxes(2 * i + 1 + supply) == (1, i * 2 + 1)
def test_transfer(testyield, yieldtoken, accounts, chain): testyield.mintNFTs(10, {'from': accounts[0]}) testyield.getReward({'from': accounts[0]}) chain.sleep(86400) for i in range(5): testyield.safeTransferFrom(accounts[0], accounts[1], i) chain.sleep(86401) pre = yieldtoken.balanceOf(accounts[0]) testyield.getReward({'from': accounts[0]}) testyield.getReward({'from': accounts[1]}) assert yieldtoken.balanceOf(accounts[0]) - pre >= 15 * Wei("10 ether") assert yieldtoken.balanceOf(accounts[1]) >= 5 * Wei("10 ether")
def main(): dai = interface.ERC20('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2') strategy = YearnWethCreamStratV2.at( '0x97785a81B3505Ea9026b2aFFa709dfd0C9Ef24f6') vault = Vault.at('0xf20731f26e98516dd83bb645dd757d33826a37b5') print(f'strategy YearnWethCreamStratV2: {strategy.address}') print(f'Vault: {vault.address}') print(f'Vault name: {vault.name()} and symbol: {vault.symbol()}') strategist_confirmed = strategy.strategist() print(f'Strategy strategist: {strategist_confirmed}') account_name = input(f"What account to use?: ") dev = accounts.load(account_name) print(f"You are using: 'dev' [{dev.address}]") devDai = dai.balanceOf(dev).to('ether') print(f"You're DAI balance is: [{devDai}]") are_you_strategist = strategist_confirmed == dev.address print(f"Are you strategist? {are_you_strategist}") if input("Continue? y/[N]: ").lower() != "y": return deposit_limit = Wei('500 ether') deposit_limit_eth = deposit_limit.to('ether') if input(f"Set deposit limit to: {deposit_limit_eth}?").lower() != "y": return # vault.setDepositLimit(deposit_limit, {"from": dev, 'gas_price':Wei("17 gwei")}) if input(f"Add strategy: {strategy} ?").lower() != "y": return #vault.addStrategy(strategy, deposit_limit, deposit_limit, 500, {"from": dev, 'gas_price':Wei("17 gwei")}) amount = Wei('0.1 ether') amountE = amount.to('ether') if input(f"approve: {amountE} WETH?").lower() != "y": return #dai.approve(vault, amount*100, {"from": dev, 'gas_price':Wei("17 gwei")}) print('deposit amount:', amount.to('ether')) if input("Continue? y/[N]: ").lower() != "y": return #vault.deposit(amount, {"from": dev, 'gas_price':Wei("17 gwei")}) print('harvest time') if input("Continue? y/[N]: ").lower() != "y": return strategy.harvest({"from": dev, 'gas_price': Wei("25 gwei")})
def loanParams(accounts, sovryn, WRBTC, SUSD, Constants): loanParams = { "id": "0x0", "active": False, "owner": Constants["ZERO_ADDRESS"], "loanToken": SUSD.address, "collateralToken": WRBTC.address, "initialMargin": Wei("50 ether"), "maintenanceMargin": Wei("15 ether"), "fixedLoanTerm": "2419200" } return loanParams
def test_apr_generic(strategy_changeable, web3, chain, Vault, currency, whale, strategist): vault = strategist.deploy(Vault, currency, strategist, strategist, "TestVault", "Amount") deposit_limit = Wei('1000000 ether') #set limit to the vault vault.setDepositLimit(deposit_limit, {"from": strategist}) #deploy strategy strategy = strategist.deploy(strategy_changeable, vault) vault.addStrategy(strategy, deposit_limit, deposit_limit, 50, {"from": strategist}) deposit_amount = Wei('1000 ether') deposit(deposit_amount, whale, currency, vault) harvest(strategy, strategist, vault) startingBalance = vault.totalAssets() genericStateOfStrat(strategy, currency, vault) genericStateOfVault(vault, currency) for i in range(10): waitBlock = 25 print(f'\n----wait {waitBlock} blocks----') chain.mine(waitBlock) print(f'\n----harvest----') strategy.harvest({'from': strategist}) genericStateOfStrat(strategy, currency, vault) genericStateOfVault(vault, currency) profit = (vault.totalAssets() - startingBalance).to('ether') strState = vault.strategies(strategy) totalReturns = strState[6] totaleth = totalReturns.to('ether') print(f'Real Profit: {profit:.5f}') difff = profit - totaleth print(f'Diff: {difff}') blocks_per_year = 2_300_000 assert startingBalance != 0 time = (i + 1) * waitBlock assert time != 0 apr = (totalReturns / startingBalance) * (blocks_per_year / time) print(apr) print(f'implied apr: {apr:.8%}') vault.withdraw(vault.balanceOf(whale), {'from': whale})
def test_operation(web3, chain, vault, strategy, token, amount, dai, dai_vault, whale, gov, guardian, strategist): # whale approve weth vault to use weth token.approve(vault, 2**256 - 1, {"from": whale}) print('cdp id: {}'.format(strategy.cdpId())) print(f'type of strategy: {type(strategy)} @ {strategy}') print(f'type of weth vault: {type(vault)} @ {vault}') print() # start deposit vault.deposit(amount, {"from": whale}) print(f'whale deposit done with {amount/1e18} weth\n') print("\n****** Initial Status ******") print("\n****** yfi ******") genericStateOfStrat(strategy, token, vault) genericStateOfVault(vault, token) print("\n****** Dai ******") genericStateOfVault(dai_vault, dai) print("\n****** Harvest yfi ******") strategy.harvest({'from': strategist}) print("\n****** yfi ******") genericStateOfStrat(strategy, token, vault) genericStateOfVault(vault, token) print("\n****** Dai ******") genericStateOfVault(dai_vault, dai) # withdraw yfi print('\n****** withdraw yfi ******') print(f'whale\'s yfi vault share: {vault.balanceOf(whale)/1e18}') vault.withdraw(Wei('1 ether'), {"from": whale}) print(f'withdraw 1 ether done') print(f'whale\'s yfi vault share: {vault.balanceOf(whale)/1e18}') # transfer dai to strategy due to rounding issue dai.transfer(strategy, Wei('1 wei'), {"from": gov}) # withdraw all yfi print('\n****** withdraw all yfi ******') print(f'whale\'s yfi vault share: {vault.balanceOf(whale)/1e18}') vault.withdraw({"from": whale}) print(f'withdraw all yfi') print(f'whale\'s yfi vault share: {vault.balanceOf(whale)/1e18}') # try call tend print('\ncall tend') strategy.tend() print('tend done')
def test_set_price(accounts, launcpadWLNative, distributor, dai, niftsy20): launcpadWLNative.setPrice(dai, 3, 100) launcpadWLNative.setPrice(zero_address, 2, 1000) for i in range(distributor.balanceOf(launcpadWLNative)): tid=distributor.tokenOfOwnerByIndex(launcpadWLNative, i) p1 = launcpadWLNative.getWNFTPrice(tid, dai) p2 = launcpadWLNative.getWNFTPrice(tid, zero_address) #????????????? logging.info('tokenId={},\n etherBalance={},\n priceErc20={},\n priceETH={}'.format( distributor.tokenOfOwnerByIndex(launcpadWLNative, i), Wei(distributor.getTokenValue(distributor.tokenOfOwnerByIndex(launcpadWLNative, i))[0]).to('ether'), Wei(p1).to('ether'), Wei(p2).to('ether') )) assert launcpadWLNative.getWNFTPrice(1, dai) == distributor.getTokenValue(distributor.tokenOfOwnerByIndex(launcpadWLNative, i))[0]* launcpadWLNative.priceForOneCollateralUnit(dai)[0]/launcpadWLNative.priceForOneCollateralUnit(dai)[1]
def stateOf(strategy): deposits, borrows = strategy.getCurrentPosition() print('deposits:', Wei(deposits).to('ether')) print('borrows:', Wei(borrows).to('ether')) if deposits == 0: collat = 0 else: collat = borrows / deposits leverage = 1 / (1 - collat) print(f'collat: {collat:.5%}') print(f'leverage: {leverage:.5f}x') assert (collat < strategy.collateralTarget(), "Over collateral target!")
def main(): lido = interface.Lido(steth_token_address) lido.submit(ZERO_ADDRESS, {"from": accounts[2], "value": "10 ether"}) lido.submit(ZERO_ADDRESS, {"from": accounts[3], "value": "10 ether"}) steth_token = interface.ERC20(steth_token_address) steth_token.transfer(accounts[0], Wei("10 ether"), {"from": accounts[2]}) steth_token.transfer(accounts[0], Wei("10 ether"), {"from": accounts[3]}) ldo_token = interface.ERC20(ldo_token_address) ldo_whale = accounts.at("0x454f11d58e27858926d7a4ece8bfea2c33e97b13", force=True) ldo_token.transfer(accounts[0], Wei("50000 ether"), {"from": ldo_whale})
def test_operation(web3, chain, vault, strategy, token, amount, usdp, usdp_vault, whale, gov, guardian, strategist): # whale approve weth vault to use weth token.approve(vault, 2**256 - 1, {"from": whale}) # start deposit vault.deposit(amount, {"from": whale}) print(f'whale deposit done with {amount/1e18} weth\n') print(f"\n****** Initial Status ******") print(f"\n****** {token.symbol()} ******") state_of_strategy(strategy, token, vault) state_of_vault(vault, token) print(f"\n****** usdp ******") state_of_vault(usdp_vault, usdp) print(f"\n****** Harvest {token.symbol()} ******") strategy.harvest({'from': strategist}) print(f"\n****** {token.symbol()} ******") state_of_strategy(strategy, token, vault) state_of_vault(vault, token) print(f"\n****** usdp ******") state_of_vault(usdp_vault, usdp) # withdraw {token.symbol()} print(f"\n****** withdraw {token.symbol()} ******") print( f"whale's {token.symbol()} vault share: {vault.balanceOf(whale)/1e18}") vault.withdraw(Wei('1 ether'), {"from": whale}) print(f"withdraw 1 {token.symbol()} done") print( f"whale's {token.symbol()} vault share: {vault.balanceOf(whale)/1e18}") # transfer usdp to strategy due to rounding issue usdp.transfer(strategy, Wei('1 wei'), {"from": gov}) # withdraw all {token.symbol()} print(f"\n****** withdraw all {token.symbol()} ******") print( f"whale's {token.symbol()} vault share: {vault.balanceOf(whale)/1e18}") vault.withdraw({"from": whale}) print(f"withdraw all {token.symbol()}") print( f"whale's {token.symbol()} vault share: {vault.balanceOf(whale)/1e18}") # try call tend print(f"\ncall tend") strategy.tend() print(f"tend done")