-
Notifications
You must be signed in to change notification settings - Fork 0
/
flashBalancer.vy
57 lines (49 loc) · 1.23 KB
/
flashBalancer.vy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# @title flashBalancer.vy
# @notice a simple example using vyper for a flash loan from Balancers vault
# @author Maka
# --
VAULT: constant(address) = 0xBA12222222228d8Ba445958a75a0704d566BF2C8
B: constant(uint256) = 2048
admin: address
weth: public(address)
# --
interface IERC20:
def balanceOf(account: address) -> uint256: view
def transfer(recipient: address, amount: uint256) -> bool: nonpayable
interface Balancer:
def flashLoan(
receiver: address,
tokens: DynArray[address, 4],
amounts: DynArray[uint256, 4],
data: Bytes[B]
): nonpayable
@external
def __init__(_weth: address):
self.admin = msg.sender
self.weth = _weth
@external
@payable
def __default__():
raw_call(
self.weth, method_id('deposit()'), value=msg.value, max_outsize=0)
# --
@external
def makeFlashLoan(
tokens: DynArray[address, 4],
amounts: DynArray[uint256, 4],
userData: Bytes[B]
):
Balancer(VAULT).flashLoan(self, tokens, amounts, userData)
@external
def receiveFlashLoan(
tokens: DynArray[address, 4],
amounts: DynArray[uint256, 4],
feeAmounts: DynArray[uint256, 4],
userData: Bytes[B]
):
assert(msg.sender == VAULT)
#...
i: uint256 = 0
for token in tokens:
IERC20(token).transfer(VAULT, amounts[i])
i += 1