diff --git a/03-technical-reference/04-SoroswapRouter.md b/03-technical-reference/04-SoroswapRouter.md index 62b0102..880b216 100644 --- a/03-technical-reference/04-SoroswapRouter.md +++ b/03-technical-reference/04-SoroswapRouter.md @@ -142,3 +142,78 @@ fn router_get_amounts_in(e: Env, amount_out: i128, path: Vec
) -> Vec[!Note] +>You can see all avaliable methods in the [Soroswap/core repo](https://github.com/soroswap/core/blob/main/contracts/router/src/lib.rs). + + +``` rust +use soroban_sdk::token::Client as TokenClient; + +// Import the router contract as .wasm +soroban_sdk::contractimport!( + file = "./soroswap_router.optimized.wasm" +); + +pub type SoroswapRouterClient<'a> = Client<'a>; + +fn my_function( + e: Env, + //{...} any other args required for your function + ) -> Result<(i128, i128, i128), ContractError> { + /* + Define the call parameters here... + */ + + //Create an instance of the router client + let soroswap_router_client = SoroswapRouterClient::new(&e, &soroswap_router_address); + //Calls the swap function + let swap = soroswap_router_client.swap_exact_tokens_for_tokens( + &amount_in, + &amount_out_min, + &path, + &to, + &deadline, + ) + + //Calls the add_liquidity function + let add_liquidty = soroswap_router_client.add_liquidity( + &token_a, + &token_b, + &amount_a, + &amount_b, + &0, + &0, + ¤t_contract, + &deadline, + ); + + //Calls the remove_liquidity function + let remove_liquidty = soroswap_router_client.remove_liquidity( + &token_a, + &token_b, + &liquidity, + &amount_a_min, + &amount_b_min, + &to, + &deadline, + ); +} +``` \ No newline at end of file diff --git a/03-technical-reference/09-using-soroswap-with-TypeScript.md b/03-technical-reference/09-using-soroswap-with-TypeScript.md index 35a7f6f..728e62a 100644 --- a/03-technical-reference/09-using-soroswap-with-TypeScript.md +++ b/03-technical-reference/09-using-soroswap-with-TypeScript.md @@ -4,7 +4,7 @@ The Soroswap protocol allows you to interact with Stellar's smart contract platf ### Prerequisites: -Before starting, it is necessary to clarify that to understand what we are doing here, you need to have a good understanding of TypeScript, smart contracts, and how a blockchain works. In addition, you need to know how to use [stellar-sdk](https://stellar.github.io/js-stellar-sdk/#usage) since we will use its [TransactionBuilder](https://stellar.github.io/js-stellar-sdk/TransactionBuilder.html) class to create operations, simulate, sign, and send transactions. Additionally, some types and functions for transforming values. +Before starting, it is necessary to clarify that to understand what we are doing here, you need to have a good understanding of TypeScript, smart contracts, and how a blockchain works. In addition, you need to know how to use [@stellar/stellar-sdk](https://stellar.github.io/js-stellar-sdk/#usage) since we will use its [TransactionBuilder](https://stellar.github.io/js-stellar-sdk/TransactionBuilder.html) class to create operations, simulate, sign, and send transactions. Additionally, some types and functions for transforming values. >[!Tip] If you need practical examples of how to create a transaction builder or how to use the SDK in general, you can guide yourself from our projects [soroswap/core](https://github.com/soroswap/core/tree/main/scripts) and [paltalabs/mercury-client.](https://github.com/paltalabs/mercury-client) @@ -20,13 +20,13 @@ In this guide, we will be using the ` ^11.2.2 ` version of Stellar SDK, availab To do this, we will install it as follows: ```bash -npm i soroswap-router-sdk@11.2.2 +npm i @stellar/stellar-sdk@11.2.2 ``` or ```bash -yarn add soroswap-router-sdk@11.2.2 +yarn add @stellar/stellar-sdk@11.2.2 ``` ### Building the transaction: