Skip to content

Commit 27ea6a3

Browse files
authored
docs: update zksync-onramp-sdk docs (#355)
# Description Updating the zksync-easy-onramp SDK docs to reflect the latest changes in the npm package.
1 parent 277fab2 commit 27ea6a3

File tree

5 files changed

+89
-12
lines changed

5 files changed

+89
-12
lines changed

content/00.zksync-era/40.tooling/100.zksync-easy-onramp/00.index.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,17 @@ const quotes = await fetchQuotes({
4747
### Execute a quote
4848

4949
```ts
50-
import { executeRoute } from 'zksync-easy-onramp';
50+
import { executeRoute } from "zksync-easy-onramp";
5151

5252
const quotes = await fetchQuotes({...});
53-
const quote = executeRoute(quotes[0], {
54-
onUpdateHook: (executingRoute) => {
55-
// receive the latest state change
56-
// of the quote that is executing
57-
console.log(executingRoute);
58-
}
59-
})
53+
const selectedQuote = quotes[0];
54+
// A quote needs to be converted to a route before executing.
55+
const routeToExecute = quoteToRoute("buy", selectedQuote.paymentMethods[0], selectedQuote.provider);
56+
const executedRoute = executeRoute(routeToExecute, {
57+
onUpdateHook: (executingRoute) => {
58+
// receive the latest state change
59+
// of the quote that is executing
60+
console.log(executingRoute);
61+
}
62+
});
6063
```
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: SDK Config Settings
3+
description: Get config data to use with your implementation of the SDK
4+
---
5+
6+
The SDK provides an endpoint to get all of the configuration data to use for
7+
building quotes. This includes the list of supported tokens, chains, and
8+
services. This is useful for building a UI that allows users to select
9+
different tokens and chains to use for their on-ramp experience.
10+
11+
## Get SDK config
12+
13+
This is not the same as the SDK configuration that you set when you initialize
14+
the SDK. The `fetchConfig` is a separate endpoint that returns the configuration data for
15+
the SDK.
16+
17+
```ts
18+
import { fetchConfig, } from "zksync-easy-onramp";
19+
20+
const config = await fetchConfig();
21+
```
22+
23+
## Config data
24+
25+
The config data returned from the SDK includes the following:
26+
27+
- `tokens`: A list of all supported tokens for the SDK. This includes the token name,
28+
address, chainId, symbol, decimals, marketCap, usdPrice, and iconUrl.
29+
- `chains`: A list of all supported chains for the SDK. This includes the chain
30+
ID, and name.
31+
- `providers`: A list of all supported services for the SDK. This includes the
32+
service name, logo, type, and supported tokens.
33+
- `fiatCurrencies`: A list of all supported fiat currencies for the SDK.
34+
This is an array of currency codes in string format.

content/00.zksync-era/40.tooling/100.zksync-easy-onramp/30.request-quotes.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ const quotes = await fetchQuotes({
2222
});
2323
```
2424

25-
The `fetchQuotes` method will return an array of quotes containing the necessary information to
26-
execute the quote.
25+
The `fetchQuotes` method will return an array of quotes grouped by provider containing the necessary information to
26+
execute the quote. Within a provider object, the quotes are available under `paymentMethods`.
27+
You can use [helper functions](./util-helpers) to sort and filter the quotes based on your needs.
2728

2829
### Parameters
2930

@@ -66,4 +67,4 @@ quotes based on the amount of tokens the user wants to purchase.
6667
Currently only the `"buy"` option is available. Specify what type of action you want to do with a
6768
quote.
6869

69-
<!-- `country` (string, optional) -->
70+
<!-- `country` (string, optional) -->

content/00.zksync-era/40.tooling/100.zksync-easy-onramp/40.execute-quotes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ tracking order statuses, switching chains, transaction management, execution, an
3535

3636
### Parameters
3737

38-
`route` (Route | ProviderQuoteOption): The route to be executed.
38+
`route` (Route | UnexecutedRoute): The route to be executed.
3939

4040
`executionOptions` (ExecutionOptions, optional): An object containing settings and callbacks for
4141
execution.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: Util Helpers
3+
description: Helper functions to use with the SDK
4+
---
5+
6+
The SDK provides a few helper functions to use with the SDK.
7+
These are useful for formatting and sorting the quotes received from the SDK.
8+
9+
## Helper functions
10+
11+
### `quoteToRoute`
12+
13+
Converts a `ProviderQuoteOption` object to a `Route` object that can be executed.
14+
This is useful for executing a quote that has been selected by the user.
15+
16+
### `sortProviderQuotes`
17+
18+
Sorts an array of provider quotes by arranging the payment methods of each provider
19+
in descending order based on the `amountFiat` value in the `receive` property.
20+
21+
### `sortByHighestReturn`
22+
23+
Sorts a list of provider quotes by the highest return value in fiat currency among
24+
all the providers.
25+
This function takes an array of `ProviderQuoteOption` objects, where each provider
26+
may have multiple payment methods. It flattens the array by creating a new object
27+
for each payment method, retaining the provider's other properties. The resulting
28+
array is then sorted in ascending order based on the `amountFiat` value of the
29+
first payment method in each provider's payment methods array.
30+
31+
### `sortByFees`
32+
33+
Sorts provider quotes by fee amount either within each provider or across all providers.
34+
35+
### `filterByPaymentMethod`
36+
37+
Filters provider quotes based on payment method types.
38+
Can either include only specified payment methods or exclude specified payment methods.
39+
Removes any provider quotes that end up with no payment methods after filtering.

0 commit comments

Comments
 (0)