Skip to content

Swap fee on amountOut #24

Answered by Elnaril
rahulthakkar796 asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @rahulthakkar796

v1.0.0 has been released and it adds support for the Universal Router functions PAY_PORTION and SWEEP.

So here is an example of how to swap ETH for an erc20 token (here UNI) with a 1% fee sent to another address:

# Buying for 1 eth of uni from v2 and send 1% of out_amount to account_2
v2_path = [weth_address, uni_address]
v2_in_amount = 1 * 10 ** 18  # 1 eth
out_amount = 381140129360952845496
v2_out_amount = int(out_amount * 0.995)  # 0.5% slippage
fees = 100  # 1%
encoded_input = (
    codec
    .encode
    .chain()
    .wrap_eth(FunctionRecipient.ROUTER, v2_in_amount)
    .v2_swap_exact_in(FunctionRecipient.ROUTER, v2_in_amount, v2_out_amount, v2_path, payer_is_se…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@rahulthakkar796
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Elnaril
Comment options

Answer selected by Elnaril
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants