Skip to content

Commit

Permalink
single tx deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Priestley committed Dec 9, 2020
1 parent bfa62a8 commit 1c71035
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
66 changes: 66 additions & 0 deletions scripts/deposit_dai.py
Original file line number Diff line number Diff line change
@@ -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"))
10 changes: 10 additions & 0 deletions tests/DAI/test_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down

0 comments on commit 1c71035

Please sign in to comment.