lcx-liberty-sdk 1.9.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/errors.js +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/resources/rwa.d.ts +29 -0
- package/dist/resources/rwa.js +52 -0
- package/dist/types.d.ts +116 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -151,6 +151,13 @@ client is not the place to publish a surface by implication.
|
|
|
151
151
|
| `quote()` | a stablecoin conversion, measured against par or a reference rate |
|
|
152
152
|
| `swap()` | the quote and the transaction, its minimum set from your tolerance |
|
|
153
153
|
|
|
154
|
+
### `lcx.rwa`
|
|
155
|
+
| method | what it is for |
|
|
156
|
+
|---|---|
|
|
157
|
+
| `assets()` | every tokenized stock, ETF, gold and treasury token the API quotes, by chain, with its reference price |
|
|
158
|
+
| `quote()` | a swap measured against the token's reference price (Chainlink, or the issuing vault's rate) |
|
|
159
|
+
| `swap()` | the quote and the transaction, its minimum set from your tolerance |
|
|
160
|
+
|
|
154
161
|
### `lcx.crossChain`
|
|
155
162
|
| method | what it is for |
|
|
156
163
|
|---|---|
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Version, hosts and chain constants. Imported by every resource. */
|
|
2
|
-
export declare const VERSION = "1.
|
|
2
|
+
export declare const VERSION = "1.10.0";
|
|
3
3
|
/**
|
|
4
4
|
* The API, where every call needs a key. Get a free one (150k calls/month, no
|
|
5
5
|
* card) at https://dex.lcx.com/dashboard.
|
package/dist/constants.js
CHANGED
package/dist/errors.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { AccountResource, ChainsResource } from "./resources/account.js";
|
|
|
2
2
|
import { CrossChainResource } from "./resources/crosschain.js";
|
|
3
3
|
import { MultiResource } from "./resources/multi.js";
|
|
4
4
|
import { PricesResource } from "./resources/prices.js";
|
|
5
|
+
import { RwaResource } from "./resources/rwa.js";
|
|
5
6
|
import { StablecoinsResource } from "./resources/stablecoins.js";
|
|
6
7
|
import { SwapResource } from "./resources/swap.js";
|
|
7
8
|
import { TokensResource } from "./resources/tokens.js";
|
|
@@ -14,6 +15,11 @@ export declare class LibertyDex {
|
|
|
14
15
|
* with your tolerance enforced on chain. `/v1/stablecoins/*`.
|
|
15
16
|
*/
|
|
16
17
|
readonly stablecoins: StablecoinsResource;
|
|
18
|
+
/**
|
|
19
|
+
* The RWA API: tokenized stocks, ETFs, gold and treasury tokens, each quote measured against what the
|
|
20
|
+
* token stands for, with your tolerance enforced on chain. `/v1/rwa/*`.
|
|
21
|
+
*/
|
|
22
|
+
readonly rwa: RwaResource;
|
|
17
23
|
/** Quote across chains, and follow a transfer to the far side. */
|
|
18
24
|
readonly crossChain: CrossChainResource;
|
|
19
25
|
/** Several tokens in and several out, as one transaction: `/v1/multi/*`. */
|
|
@@ -34,6 +40,7 @@ export { Transport } from "./transport.js";
|
|
|
34
40
|
export * from "./types.js";
|
|
35
41
|
export { SwapResource, type SubmitResult } from "./resources/swap.js";
|
|
36
42
|
export { StablecoinsResource } from "./resources/stablecoins.js";
|
|
43
|
+
export { RwaResource } from "./resources/rwa.js";
|
|
37
44
|
export { CrossChainResource } from "./resources/crosschain.js";
|
|
38
45
|
export { MultiResource } from "./resources/multi.js";
|
|
39
46
|
export { TokensResource } from "./resources/tokens.js";
|
package/dist/index.js
CHANGED
|
@@ -47,6 +47,7 @@ import { AccountResource, ChainsResource } from "./resources/account.js";
|
|
|
47
47
|
import { CrossChainResource } from "./resources/crosschain.js";
|
|
48
48
|
import { MultiResource } from "./resources/multi.js";
|
|
49
49
|
import { PricesResource } from "./resources/prices.js";
|
|
50
|
+
import { RwaResource } from "./resources/rwa.js";
|
|
50
51
|
import { StablecoinsResource } from "./resources/stablecoins.js";
|
|
51
52
|
import { SwapResource } from "./resources/swap.js";
|
|
52
53
|
import { TokensResource } from "./resources/tokens.js";
|
|
@@ -58,6 +59,11 @@ export class LibertyDex {
|
|
|
58
59
|
* with your tolerance enforced on chain. `/v1/stablecoins/*`.
|
|
59
60
|
*/
|
|
60
61
|
stablecoins;
|
|
62
|
+
/**
|
|
63
|
+
* The RWA API: tokenized stocks, ETFs, gold and treasury tokens, each quote measured against what the
|
|
64
|
+
* token stands for, with your tolerance enforced on chain. `/v1/rwa/*`.
|
|
65
|
+
*/
|
|
66
|
+
rwa;
|
|
61
67
|
/** Quote across chains, and follow a transfer to the far side. */
|
|
62
68
|
crossChain;
|
|
63
69
|
/** Several tokens in and several out, as one transaction: `/v1/multi/*`. */
|
|
@@ -74,6 +80,7 @@ export class LibertyDex {
|
|
|
74
80
|
const t = new Transport(options);
|
|
75
81
|
this.swap = new SwapResource(t);
|
|
76
82
|
this.stablecoins = new StablecoinsResource(t);
|
|
83
|
+
this.rwa = new RwaResource(t);
|
|
77
84
|
this.crossChain = new CrossChainResource(t);
|
|
78
85
|
this.multi = new MultiResource(t);
|
|
79
86
|
this.tokens = new TokensResource(t);
|
|
@@ -88,6 +95,7 @@ export { Transport } from "./transport.js";
|
|
|
88
95
|
export * from "./types.js";
|
|
89
96
|
export { SwapResource } from "./resources/swap.js";
|
|
90
97
|
export { StablecoinsResource } from "./resources/stablecoins.js";
|
|
98
|
+
export { RwaResource } from "./resources/rwa.js";
|
|
91
99
|
export { CrossChainResource } from "./resources/crosschain.js";
|
|
92
100
|
export { MultiResource } from "./resources/multi.js";
|
|
93
101
|
export { TokensResource } from "./resources/tokens.js";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Transport } from "../transport.js";
|
|
2
|
+
import type { RwaAssetsResponse, RwaCategory, RwaQuote, RwaQuoteParams, RwaSwap, RwaSwapParams } from "../types.js";
|
|
3
|
+
export declare class RwaResource {
|
|
4
|
+
private readonly t;
|
|
5
|
+
constructor(t: Transport);
|
|
6
|
+
/**
|
|
7
|
+
* Every RWA token the API quotes, by chain: issuer, class, what it stands for, its live reference price and
|
|
8
|
+
* our measured depth. Narrow with `chainId` and `category`. The registry changes when the API deploys; the
|
|
9
|
+
* reference is live.
|
|
10
|
+
*/
|
|
11
|
+
assets(params?: {
|
|
12
|
+
chainId?: number;
|
|
13
|
+
category?: RwaCategory;
|
|
14
|
+
}): Promise<RwaAssetsResponse>;
|
|
15
|
+
/**
|
|
16
|
+
* A swap, priced and measured against the token's reference price. Read-only.
|
|
17
|
+
*
|
|
18
|
+
* `rwa.refDeviationBps` is the distance from the reference (positive pays more), and `rwa.minOut` the least
|
|
19
|
+
* a swap would deliver. Throws `LibertyError` with `below_tolerance`, `no_reference_price`, `off_reference`,
|
|
20
|
+
* `insufficient_liquidity` (`details.fillsUpTo`), `not_an_rwa` and the other codes of `RwaRefusalCode`.
|
|
21
|
+
*/
|
|
22
|
+
quote(params: RwaQuoteParams): Promise<RwaQuote>;
|
|
23
|
+
/**
|
|
24
|
+
* The quote and a transaction to sign, in one call. The transaction's minimum output is `rwa.minOut`: if the
|
|
25
|
+
* market moves past it, the swap reverts on chain rather than paying less. `idempotencyKey` goes out as the
|
|
26
|
+
* `Idempotency-Key` header, so a retry returns the first answer instead of building a second transaction.
|
|
27
|
+
*/
|
|
28
|
+
swap(params: RwaSwapParams): Promise<RwaSwap>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The RWA API: swaps into and out of tokenized stocks, ETFs, gold and treasury tokens, under rules.
|
|
3
|
+
*
|
|
4
|
+
* The same engine and router as `lcx.swap`, with a rule set around it: one side must be a registered RWA
|
|
5
|
+
* token, every quote is measured against what the token stands for (a Chainlink feed or the issuing vault's
|
|
6
|
+
* rate, read on chain), a quote past your tolerance is refused instead of filled, a token with no live
|
|
7
|
+
* reference needs `allowUnreferenced`, and buying one far under its reference needs `allowOffReference`.
|
|
8
|
+
* Refusals are `LibertyError`s whose `details` carry the fields of `RwaRefusal`.
|
|
9
|
+
*/
|
|
10
|
+
import { LibertyError } from "../errors.js";
|
|
11
|
+
/** What the API accepts as an `Idempotency-Key`: 1 to 128 visible ASCII characters. */
|
|
12
|
+
const IDEMPOTENCY_KEY = /^[\x21-\x7e]{1,128}$/;
|
|
13
|
+
export class RwaResource {
|
|
14
|
+
t;
|
|
15
|
+
constructor(t) {
|
|
16
|
+
this.t = t;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Every RWA token the API quotes, by chain: issuer, class, what it stands for, its live reference price and
|
|
20
|
+
* our measured depth. Narrow with `chainId` and `category`. The registry changes when the API deploys; the
|
|
21
|
+
* reference is live.
|
|
22
|
+
*/
|
|
23
|
+
assets(params = {}) {
|
|
24
|
+
return this.t.request("GET", "/v1/rwa/assets", undefined, {
|
|
25
|
+
chainId: params.chainId,
|
|
26
|
+
category: params.category,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A swap, priced and measured against the token's reference price. Read-only.
|
|
31
|
+
*
|
|
32
|
+
* `rwa.refDeviationBps` is the distance from the reference (positive pays more), and `rwa.minOut` the least
|
|
33
|
+
* a swap would deliver. Throws `LibertyError` with `below_tolerance`, `no_reference_price`, `off_reference`,
|
|
34
|
+
* `insufficient_liquidity` (`details.fillsUpTo`), `not_an_rwa` and the other codes of `RwaRefusalCode`.
|
|
35
|
+
*/
|
|
36
|
+
quote(params) {
|
|
37
|
+
return this.t.request("POST", "/v1/rwa/quote", params);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The quote and a transaction to sign, in one call. The transaction's minimum output is `rwa.minOut`: if the
|
|
41
|
+
* market moves past it, the swap reverts on chain rather than paying less. `idempotencyKey` goes out as the
|
|
42
|
+
* `Idempotency-Key` header, so a retry returns the first answer instead of building a second transaction.
|
|
43
|
+
*/
|
|
44
|
+
// `async` so a bad key rejects rather than throws, like `stablecoins.swap`.
|
|
45
|
+
async swap(params) {
|
|
46
|
+
const { idempotencyKey, ...body } = params;
|
|
47
|
+
if (idempotencyKey !== undefined && !IDEMPOTENCY_KEY.test(idempotencyKey)) {
|
|
48
|
+
throw new LibertyError("bad_request", "idempotencyKey must be 1 to 128 visible ASCII characters", 400);
|
|
49
|
+
}
|
|
50
|
+
return this.t.request("POST", "/v1/rwa/swap", body, undefined, idempotencyKey === undefined ? undefined : { "idempotency-key": idempotencyKey });
|
|
51
|
+
}
|
|
52
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -718,6 +718,122 @@ export interface StablecoinTransaction {
|
|
|
718
718
|
export interface StablecoinSwap extends StablecoinQuote {
|
|
719
719
|
transaction: StablecoinTransaction;
|
|
720
720
|
}
|
|
721
|
+
/** The RWA registry's classes. */
|
|
722
|
+
export type RwaCategory = "stocks" | "etfs" | "metals" | "treasury" | "credit" | "commodities";
|
|
723
|
+
/** A token's reference price: USD per whole token, where it came from, and when it was last set. */
|
|
724
|
+
export interface RwaReference {
|
|
725
|
+
usd: number;
|
|
726
|
+
/** e.g. "Chainlink Coinbase NVDA on Base", "SYRUPUSDC vault rate (convertToAssets) on Ethereum". */
|
|
727
|
+
source: string;
|
|
728
|
+
/** Unix seconds of the source's last update. Equity feeds update in US sessions only. */
|
|
729
|
+
updatedAt: number;
|
|
730
|
+
}
|
|
731
|
+
/** One RWA token: `GET /v1/rwa/assets` -> `data.chains[].assets[]`. */
|
|
732
|
+
export interface RwaAsset {
|
|
733
|
+
/** Checksummed. Send it as `tokenIn` / `tokenOut`. */
|
|
734
|
+
address: string;
|
|
735
|
+
symbol: string;
|
|
736
|
+
name: string | null;
|
|
737
|
+
decimals: number | null;
|
|
738
|
+
issuer: string | null;
|
|
739
|
+
category: RwaCategory | (string & {}) | null;
|
|
740
|
+
/** What one token stands for: a ticker ("TSLA"), "XAU" for gold, or null. */
|
|
741
|
+
underlying: string | null;
|
|
742
|
+
/** The live reference, or null when its source has no live answer. */
|
|
743
|
+
reference: RwaReference | null;
|
|
744
|
+
/** The token has a reference source at all. */
|
|
745
|
+
referenced: boolean;
|
|
746
|
+
/** "us_equities" when its reference follows US sessions, else "always". */
|
|
747
|
+
marketHours: "us_equities" | "always";
|
|
748
|
+
/** Our measured depth in the token's deepest pool, USD. */
|
|
749
|
+
depthUsd: number | null;
|
|
750
|
+
}
|
|
751
|
+
export interface RwaChain {
|
|
752
|
+
chainId: number;
|
|
753
|
+
chain: string;
|
|
754
|
+
/** The chain has passed LCX's benchmark gate. Informational. */
|
|
755
|
+
named: boolean;
|
|
756
|
+
assets: RwaAsset[];
|
|
757
|
+
}
|
|
758
|
+
export interface RwaAssetsResponse {
|
|
759
|
+
/** Whether the US equity session is open now. */
|
|
760
|
+
usEquitiesOpen: boolean;
|
|
761
|
+
chains: RwaChain[];
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* A swap with at least one registered RWA token on `chainId`. Exactly one of `amountIn` (base units) /
|
|
765
|
+
* `amount` (human units).
|
|
766
|
+
*/
|
|
767
|
+
export type RwaQuoteParams = SellAmount & {
|
|
768
|
+
chainId: number;
|
|
769
|
+
tokenIn: string;
|
|
770
|
+
tokenOut: string;
|
|
771
|
+
decimals?: number;
|
|
772
|
+
/** How far below the reference price you accept, in bps. Default 100; above 0 and at most 500. */
|
|
773
|
+
maxRefDeviationBps?: number;
|
|
774
|
+
/** The bound against the quote itself. Default 50. */
|
|
775
|
+
slippageBps?: number;
|
|
776
|
+
/** Buy a token whose market pays more than 3% above its reference anyway. Default false (`off_reference`). */
|
|
777
|
+
allowOffReference?: boolean;
|
|
778
|
+
/** Quote a token with no live reference, under the engine's guards only. Default false (`no_reference_price`). */
|
|
779
|
+
allowUnreferenced?: boolean;
|
|
780
|
+
/** Your integration (an address or a registered slug), as on `/v1/quote`. */
|
|
781
|
+
integrator?: string;
|
|
782
|
+
};
|
|
783
|
+
export type RwaSwapParams = RwaQuoteParams & {
|
|
784
|
+
/** Address that sends the transaction and receives the output. Required. */
|
|
785
|
+
taker: string;
|
|
786
|
+
/** Seconds until the on-chain deadline. Default 300, at most 3600. */
|
|
787
|
+
deadlineSecs?: number;
|
|
788
|
+
/** Sent as the `Idempotency-Key` header. 1 to 128 visible ASCII characters. */
|
|
789
|
+
idempotencyKey?: string;
|
|
790
|
+
};
|
|
791
|
+
/** The rule set's verdict on a quote: `data.rwa`. */
|
|
792
|
+
export interface RwaVerdict {
|
|
793
|
+
asset: {
|
|
794
|
+
symbol: string;
|
|
795
|
+
name: string | null;
|
|
796
|
+
issuer: string | null;
|
|
797
|
+
category: string | null;
|
|
798
|
+
underlying: string | null;
|
|
799
|
+
};
|
|
800
|
+
/** The reference used for each RWA side; null for a side that is not an RWA token. */
|
|
801
|
+
referenceIn: RwaReference | null;
|
|
802
|
+
referenceOut: RwaReference | null;
|
|
803
|
+
/** Whether the reference's US session is open; null for gold and vault rates. */
|
|
804
|
+
marketOpen: boolean | null;
|
|
805
|
+
/** Distance from the reference in bps, positive pays MORE; null with `allowUnreferenced`. */
|
|
806
|
+
refDeviationBps: number | null;
|
|
807
|
+
maxRefDeviationBps: number | null;
|
|
808
|
+
/** The least the swap may deliver, in base units of tokenOut. Read this, not `quote.output.minimumAmount`. */
|
|
809
|
+
minOut: string;
|
|
810
|
+
/** The output exactly at your tolerance. Absent with `allowUnreferenced`. */
|
|
811
|
+
floorOut?: string;
|
|
812
|
+
/** `minOut` as a slippage figure; send it to `swap.build()` to keep that floor. */
|
|
813
|
+
slippageBps: number;
|
|
814
|
+
named: boolean;
|
|
815
|
+
}
|
|
816
|
+
export interface RwaQuote {
|
|
817
|
+
/** The `/v1/quote` answer, field for field. */
|
|
818
|
+
quote: Quote;
|
|
819
|
+
rwa: RwaVerdict;
|
|
820
|
+
}
|
|
821
|
+
export interface RwaSwap extends RwaQuote {
|
|
822
|
+
transaction: StablecoinTransaction;
|
|
823
|
+
}
|
|
824
|
+
/** Every code an RWA API call is refused with, beyond the swap API's own. */
|
|
825
|
+
export type RwaRefusalCode = "not_an_rwa" | "no_reference_price" | "below_tolerance" | "off_reference" | "insufficient_liquidity" | "excluded_coin" | "bad_tolerance" | "idempotency_key_reused";
|
|
826
|
+
/** The body of an RWA refusal, on `LibertyError.details`. */
|
|
827
|
+
export interface RwaRefusal {
|
|
828
|
+
success: false;
|
|
829
|
+
code: RwaRefusalCode | (string & {});
|
|
830
|
+
message: string;
|
|
831
|
+
refusalReason?: string;
|
|
832
|
+
refDeviationBps?: number;
|
|
833
|
+
maxRefDeviationBps?: number;
|
|
834
|
+
marketOpen?: boolean | null;
|
|
835
|
+
fillsUpTo?: string;
|
|
836
|
+
}
|
|
721
837
|
/** Every code a Stablecoin API call is refused with, beyond the swap API's own. */
|
|
722
838
|
export type StablecoinRefusalCode = "below_tolerance" | "off_peg" | "insufficient_liquidity" | "excluded_coin" | "no_reference_rate" | "not_a_stablecoin" | "bad_tolerance" | "no_route" | "idempotency_key_reused";
|
|
723
839
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lcx-liberty-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "TypeScript SDK for the LCX Liberty DEX aggregator. Best-execution routing across Ethereum, Base, Arbitrum, OP Mainnet, BNB Chain, Polygon, Avalanche, Robinhood Chain, Unichain, Monad, HyperEVM and Arc.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/index.js",
|