SoroswapLibrary
The SoroswapLibrary is a rust crate that anyone can implement in their smart contracts. Check all the documentation here: https://docs.rs/soroswap-library/latest/soroswap_library/
Code
You can find the Soroswap library code on the Soroswap GitHub repository. in https://github.com/soroswap/core/tree/main/contracts/library
Usage as a crate
1.- Add this to your Cargo.toml:
[dependencies] soroswap-library = ""
2.- Import it:
3.- Use it:
Internal Functions
sort_tokens
Sorts token addresses.
pair_for
Calculates the address for a pair without making any external calls.
get_reserves
Fetches and sorts the reserves for a pair.
quote
Given some asset amount and reserves, returns an amount of the other asset representing an equivalent value.
Useful for calculating optimal token amounts before calling
deposit
.
get_amount_out
Given an input asset amount, returns the maximum output amount of the other asset (accounting for fees) given reserves.
Used in
get_amounts_out
.
get_amount_in
Returns the minimum input asset amount required to buy the given output asset amount (accounting for fees) given reserves.
Used in
get_amounts_in
.
get_amounts_out
Given an input asset amount and an array of token addresses, calculates all subsequent maximum output token amounts by calling get_reserves
for each pair of token addresses in the path in turn and using these to call get_amount_out
.
Useful for calculating optimal token amounts before calling
swap
.
get_amounts_in
Given an output asset amount and an array of token addresses, calculates all preceding minimum input token amounts by calling get_reserves
for each pair of token addresses in the path in turn and using these to call get_amount_in
.
Useful for calculating optimal token amounts before calling
swap
.
This Soroswap library is designed to facilitate efficient and precise token swapping and handling in the Soroswap.Finance ecosystem. It includes a range of functions to support various aspects of token management, from sorting token addresses to calculating reserves and performing chained calculations for different pairs. These functions are crucial for the optimal functioning of Soroswap in the Stellar network.
Last updated