Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.

Commit 4764fc8

Browse files
Added smart swap docs for Unity (#466)
1 parent 369f96e commit 4764fc8

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Currency Swaps
2+
3+
Swapping between different ERC20/native token currencies on a given Chain is made easy by Sequence's Smart Swap API.
4+
5+
## GetSwapPrice
6+
7+
This method can be used to get the current `SwapPrice` for a given buyCurrency and buyAmount using a given sellCurrency.
8+
9+
```
10+
ISwap swapper = new CurrencySwap(_chain);
11+
SwapPrice swapPrice = await swapper.GetSwapPrice(buyCurrencyTokenAddress, usdcAddress, "1000"); // where USDC is an example sell currency
12+
```
13+
You can optionally subscribe to the `OnSwapPriceReturn` and `OnSwapPriceError` events in order to handle the response elsewhere.
14+
15+
You can optionally provide a maximum allowable slippagePercentage.
16+
17+
## GetSwapPrices
18+
19+
This method is similar to `GetSwapPrice`, it can be used to get the current `SwapPrice` for a given buyCurrency and buyAmount. Except, instead of providing a sellCurrency, you instead provide the user's wallet address.
20+
21+
This method will detect the eligible currencies (ERC20s or native tokens) that can be swapped for buyAmount of the buyCurrency and will return a `SwapPrice[]`.
22+
23+
```
24+
ISwap swapper = new CurrencySwap(_chain);
25+
SwapPrice[] swapPrices = await swapper.GetSwapPrices(userWalletAddress, buyCurrencyTokenAddress, "1000");
26+
```
27+
You can optionally subscribe to the `OnSwapPricesReturn` and `OnSwapPricesError` events in order to handle the response elsewhere.
28+
29+
You can optionally provide a maximum allowable slippagePercentage.
30+
31+
## GetSwapQuote
32+
33+
This method is used to get an executable `SwapQuote` for a given userWallet address to buy buyAmount of buyCurrency using sellCurrency.
34+
35+
```
36+
ISwap swapper = new CurrencySwap(_chain);
37+
SwapQuote quote = await swapper.GetSwapQuote(userWalletAddress, buyCurrencyTokenAddess, usdcAddress, "1000", true); // where USDC is an example sell currency
38+
```
39+
40+
Once you've obtained a `SwapQuote`, you can transform it into a `Transaction[]` that can be submitted via your EmbeddedWallet to execute the swap.
41+
42+
```
43+
Transaction[] swapTransactions = quote.AsTransactionArray();
44+
45+
_wallet.SendTransaction(_chain, swapTransactions);
46+
```
47+
48+
If `includeApprove = true` the SwapQuote response will also include the information required to create the required spend approval transaction(s). These will also be added to the `Transaction[]` created above via `SwapQuote.AsTransactionArray()`. As usual, with our embedded smart contract wallets, all of these transactions can be submitted at once in a bundle; significantly improving the UX for your players who would usually need to make separate transactions to approve and swap.

nav.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@ export const sidebar = {
667667
{ text: 'Session Management', link: '/sdk/unity/session-management' },
668668
{ text: 'On-Ramp Funds via Credit Card', link: '/sdk/unity/onboard-user-funds' },
669669
{ text: 'Marketplace', link: '/sdk/unity/marketplace' },
670+
{ text: 'Currency Swaps', link: '/sdk/unity/currency-swaps' },
670671
{
671672
text: 'Connect with External Wallets',
672673
link: '/sdk/unity/connecting-external-wallets',

0 commit comments

Comments
 (0)