From 1c710351a847d92dd2e46562de6946574e903241 Mon Sep 17 00:00:00 2001 From: Sam Priestley Date: Wed, 9 Dec 2020 15:02:37 +0000 Subject: [PATCH] single tx deposit --- scripts/deposit_dai.py | 66 ++++++++++++++++++++++++++++++++++++++++++ tests/DAI/test_live.py | 10 +++++++ 2 files changed, 76 insertions(+) create mode 100644 scripts/deposit_dai.py diff --git a/scripts/deposit_dai.py b/scripts/deposit_dai.py new file mode 100644 index 0000000..51b772c --- /dev/null +++ b/scripts/deposit_dai.py @@ -0,0 +1,66 @@ + +from brownie import accounts, interface, Wei, Contract +from eth_account import Account +from eth_account._utils.structured_data.hashing import hash_domain +from eth_account.messages import encode_structured_data +from eth_utils import encode_hex +import click + +def build_permit(holder, spender, dai): + data = { + "types": { + "EIP712Domain": [ + {"name": "name", "type": "string"}, + {"name": "version", "type": "string"}, + {"name": "chainId", "type": "uint256"}, + {"name": "verifyingContract", "type": "address"}, + ], + "Permit": [ + {"name": "holder", "type": "address"}, + {"name": "spender", "type": "address"}, + {"name": "nonce", "type": "uint256"}, + {"name": "expiry", "type": "uint256"}, + {"name": "allowed", "type": "bool"}, + ], + }, + "domain": { + "name": dai.name(), + "version": dai.version(), + "chainId": 1, + "verifyingContract": str(dai), + }, + "primaryType": "Permit", + "message": { + "holder": holder, + "spender": spender, + "nonce": dai.nonces(holder), + "expiry": 0, + "allowed": True, + }, + } + assert encode_hex(hash_domain(data)) == dai.DOMAIN_SEPARATOR() + return encode_structured_data(data) + + +def main(): + dai = Contract.from_explorer("0x6B175474E89094C44Da98b954EedeAC495271d0F") + dai_deposit = Contract.from_explorer("0xF6f4526a05a38198dBEddFc226d30dbb5419951F") + dai_vault = Contract.from_explorer("0xBFa4D8AA6d8a379aBFe7793399D3DdaCC5bBECBB") + user = accounts.load(click.prompt("Account", type=click.Choice(accounts.load()))) + #account_name = input(f"What account to use?: ") + #user = accounts.load(account_name) + signer = Account.from_key(user.private_key) + balance = dai.balanceOf(user) + print("DAI balance:", balance.to("ether")) + amount = click.prompt("Deposit amount", type=click.FloatRange(min=0)) + amount = min(Wei(f"{amount} ether"), balance) + permit = build_permit(str(user), str(dai_deposit), dai) + signed = signer.sign_message(permit) + if click.confirm("Send transaction?"): + dai_deposit.deposit( + amount, + [user, dai_deposit, 0, 0, True, signed.v, signed.r, signed.s], + {"from": user}, + ) + vault_balance = dai_vault.balanceOf(user) + print("yvDAI balance", vault_balance.to("ether")) \ No newline at end of file diff --git a/tests/DAI/test_live.py b/tests/DAI/test_live.py index af2de38..db84434 100644 --- a/tests/DAI/test_live.py +++ b/tests/DAI/test_live.py @@ -32,7 +32,17 @@ def test_flash_loan(live_vault_dai2,live_vault_dai3,live_strategy_dai3, Contract #calldata = eth_abi.encode_single('(bool,uint256)', [True, 1000]) #print(calldata) #aave.flashLoan(live_strat, dai, 100, calldata, {'from': whale}) +def test_shutdown(live_strategy_dai2,live_vault_dai2,live_strategy_usdc3, live_strategy_usdc4,live_vault_usdc3, live_strategy_dai4, Contract, usdc, web3,live_gov, accounts, chain, cdai, comp, dai, currency, whale,samdev): + stateOfStrat(live_strategy_dai2, dai, comp) + live_vault_dai2.revokeStrategy(live_strategy_dai2, {'from': samdev}) + stateOfStrat(live_strategy_dai2, dai, comp) + live_strategy_dai2.harvest({'from': samdev}) + live_strategy_dai2.harvest({'from': samdev}) + + stateOfStrat(live_strategy_dai2, dai, comp) + genericStateOfVault(live_vault_dai2, dai) + def test_migration(live_vault_dai3,live_strategy_dai3,live_strategy_usdc3, live_strategy_usdc4,live_vault_usdc3, live_strategy_dai4, Contract, usdc, web3,live_gov, accounts, chain, cdai, comp, dai, live_strategy_dai2,currency, whale,samdev):