To cover all possible scenarios,๏ฟฝ ๏ฟฝcalle r should have already given the router an allowance of at least amountADesired/amountBDesired on tokenA/tokenB.
Always adds assets at the ideal ratio, according to the price when the transaction is executed.
Swaps an exact amount of input tokens for as many output tokens as possible, along the route determined by the path. The first element of path is the input token, the last is the output token, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).
caller should have already given the router an allowance of at least amountIn on the input token.
Receive an exact amount of output tokens for as few input tokens as possible, along the route determined by the path. The first element of path is the input token, the last is the output token, and any intermediate elements represent intermediate tokens to trade through (if, for example, a direct pair does not exist).
caller should have already given the router an allowance of at least amountInMax on the input token.
Interface
%lang starknet
from starkware.cairo.common.uint256 import Uint256
@contract_interface
namespace IRouter:
func factory() -> (address: felt):
end
func sort_tokens(tokenA: felt, tokenB: felt) -> (token0: felt, token1: felt):
end
func quote(amountA: Uint256, reserveA: Uint256, reserveB: Uint256) -> (amountB: Uint256):
end
โfunc get_amount_out(amountIn: Uint256, reserveIn: Uint256, reserveOut: Uint256) -> (amountOut: Uint256):
end
โfunc get_amount_in(amountOut: Uint256, reserveIn: Uint256, reserveOut: Uint256) -> (amountIn: Uint256):
end
func get_amounts_out(amountIn: Uint256, path_len: felt, path: felt*) -> (amounts_len: felt, amounts: Uint256*):
end
func get_amounts_in(amountOut: Uint256, path_len: felt, path: felt*) -> (amounts_len: felt, amounts: Uint256*):
end
func add_liquidity(tokenA: felt, tokenB: felt, amountADesired: Uint256, amountBDesired: Uint256, amountAMin: Uint256, amountBMin: Uint256, to: felt, deadline: felt) -> (amountA: Uint256, amountB: Uint256, liquidity: Uint256):
end
โfunc remove_liquidity(tokenA: felt, tokenB: felt, liquidity: Uint256, amountAMin: Uint256, amountBMin: Uint256, to: felt, deadline: felt) -> (amountA: Uint256, amountB: Uint256):
end
โfunc swap_exact_tokens_for_tokens(amountIn: Uint256, amountOutMin: Uint256, path_len: felt, path: felt*, to: felt, deadline: felt) -> (amounts_len: felt, amounts: Uint256*):
end
โfunc swap_tokens_for_exact_tokens(amountOut: Uint256, amountInMax: Uint256, path_len: felt, path: felt*, to: felt, deadline: felt) -> (amounts_len: felt, amounts: Uint256*):
end
end
Useful for calculating optimal token amounts before calling .
Given an input asset amount and an array of token addresses, calculates all subsequent maximum output token amounts by calling for each pair of token addresses in the path in turn, and using these to call .
Useful for calculating optimal token amounts before calling .
Given an output asset amount and an array of token addresses, calculates all preceding minimum input token amounts by calling for each pair of token addresses in the path in turn, and using these to call .
Useful for calculating optimal token amounts before calling .