Swap fee on amountOut #24
-
Could anyone please provide an example of how to swap custom ERC20 tokens for ETH, or vice versa, while applying a 1% swap fee on the |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Hello @rahulthakkar796 |
Beta Was this translation helpful? Give feedback.
-
Ah ok, I see: you're talking of the Unfortunately, these functions are not yet supported by this SDK ... |
Beta Was this translation helpful? Give feedback.
-
Hello @rahulthakkar796 v1.0.0 has been released and it adds support for the Universal Router functions 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_sender=False)
.pay_portion(FunctionRecipient.CUSTOM, uni_address, fees, account_2.address)
.sweep(FunctionRecipient.SENDER, uni_address, 0)
.build(codec.get_default_deadline())
) Please, let me know if it answers your question. |
Beta Was this translation helpful? Give feedback.
Hello @rahulthakkar796
v1.0.0 has been released and it adds support for the Universal Router functions
PAY_PORTION
andSWEEP
.So here is an example of how to swap ETH for an erc20 token (here UNI) with a 1% fee sent to another address: