Approving the tokens to sell
The first step is approving the tokens you want to sell to the GPv2VaultRelayer.
The safe that I am using had yvUSDC, yvYFI and yvLINK, so my first tx takes care of withdrawing and approving each token. Code is the following:
1
import click
2
from ape_safe import ApeSafe
3
from brownie *
4
5
def withdraw_and_approve_tokens_sep_21():
6
# Get the safe
7
safe = ApeSafe("0xMySafeAddress")
8
9
# Contract we need to approve so our tokens can be transferFrom
10
gnosis_vault_relayer = safe.contract("0xC92E8bdf79f0507f65a392b0ab4667716BFE0110")
11
12
# yearn vault tokens
13
yvUSDC = safe.contract("0x5f18C75AbDAe578b483E5F43f12a39cF75b973a9")
14
yvYFI = safe.contract("0xE14d13d8B3b85aF791b2AADD661cDBd5E6097Db1")
15
yvLINK = safe.contract("0x671a912C10bba0CFA74Cfc2d6Fba9BA1ed9530B2")
16
17
for vault in [yvUSDC, yvYFI, yvLINK]:
18
print(f"Processing {vault.name()}")
19
20
# Withdraw everything from the vault
21
vault.withdraw()
22
token = safe.contract(vault.token())
23
token_balance = token.balanceOf(safe.address)
24
print(f"Balance of {token.name()}: {(token_balance / 10 ** token.decimals()):_}")
25
assert token.balanceOf(safe.address) > 0
26
27
# Approve so we can create a cowswap order
28
token.approve(gnosis_vault_relayer, 2**256-1)
29
30
31
safe_tx = safe.multisend_from_receipts()
32
account = click.prompt("signer", type=click.Choice(accounts.load()))
33
safe_tx.sign(accounts.load(account).private_key)
34
safe.preview(safe_tx, events=False, call_trace=False)
35
safe.post_transaction(safe_tx)
Copied!
After testing in a fork, ape-safe will ask for your account password and submit the tx to the multisign.
After the tx is executed, we would have our vanilla erc-20 tokens plus all approvals needed to submit an order.
Copy link