@sodax/types 2.0.0-rc.18 → 2.0.0-rc.19

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.
@@ -0,0 +1,28 @@
1
+ import type { SpokeChainKey, IntentRelayChainIdMap } from '../chains/chains.js';
2
+ import type { XToken } from '../chains/tokens.js';
3
+ import type { Result, SpokeChainConfigMap } from '../common/common.js';
4
+ import type { Address } from '../shared/shared.js';
5
+ export type GetChainsApiResponse = readonly SpokeChainKey[];
6
+ export type GetSwapTokensApiResponse = Record<SpokeChainKey, readonly XToken[]>;
7
+ export type GetSwapTokensByChainIdApiResponse = readonly XToken[];
8
+ export type GetMoneyMarketTokensApiResponse = Record<SpokeChainKey, readonly XToken[]>;
9
+ export type GetMoneyMarketTokensByChainIdApiResponse = readonly XToken[];
10
+ export type GetRelayChainIdMapApiResponse = IntentRelayChainIdMap;
11
+ export type GetSpokeChainConfigApiResponse = SpokeChainConfigMap;
12
+ export type GetMoneyMarketReserveAssetsApiResponse = readonly Address[];
13
+ export type GetAllConfigApiResponse = {
14
+ version?: number;
15
+ supportedChains: GetChainsApiResponse;
16
+ supportedSwapTokens: GetSwapTokensApiResponse;
17
+ supportedMoneyMarketTokens: GetMoneyMarketTokensApiResponse;
18
+ supportedMoneyMarketReserveAssets: GetMoneyMarketReserveAssetsApiResponse;
19
+ relayChainIdMap: GetRelayChainIdMapApiResponse;
20
+ spokeChainConfig: GetSpokeChainConfigApiResponse;
21
+ };
22
+ export interface IConfigApiV1 {
23
+ getChains(): Promise<Result<GetChainsApiResponse>>;
24
+ getSwapTokens(): Promise<Result<GetSwapTokensApiResponse>>;
25
+ getSwapTokensByChainId(chainId: SpokeChainKey): Promise<Result<GetSwapTokensByChainIdApiResponse>>;
26
+ getMoneyMarketTokens(): Promise<Result<GetMoneyMarketTokensApiResponse>>;
27
+ getMoneyMarketTokensByChainId(chainId: SpokeChainKey): Promise<Result<GetMoneyMarketTokensByChainIdApiResponse>>;
28
+ }
@@ -3,6 +3,7 @@ import type { XToken } from '../chains/tokens.js';
3
3
  import type { RelayConfig } from '../common/constants.js';
4
4
  import type { ConcentratedLiquidityConfig, DexDefaultConfig } from '../dex/dex.js';
5
5
  import type { SodaxDefaultConfig } from '../sodax-config/sodax-config.js';
6
+ import type { RawTxReturnType } from '../common/index.js';
6
7
  /** Quote direction. Only exact-input quoting is supported. */
7
8
  export type QuoteTypeV2 = 'exact_input';
8
9
  /**
@@ -254,13 +255,13 @@ export interface AllowanceCheckResponseV2 {
254
255
  }
255
256
  /** POST /swaps/approve — response body. */
256
257
  export interface ApproveResponseV2 {
257
- /** Unsigned approval transaction (chain-specific shape). For EVM: `{ from, to, value, data }`. */
258
- tx: unknown;
258
+ /** Unsigned approval transaction the `RawTxReturnType` variant for the request's `srcChainKey`. */
259
+ tx: RawTxReturnType;
259
260
  }
260
261
  /** POST /swaps/intents — response body. */
261
262
  export interface CreateIntentResponseV2 {
262
- /** Unsigned create-intent transaction (chain-specific shape). For EVM: `{ from, to, value, data }`. */
263
- tx: unknown;
263
+ /** Unsigned create-intent transaction the `RawTxReturnType` variant for the request's `srcChainKey`. */
264
+ tx: RawTxReturnType;
264
265
  /** Built intent struct (hub representation). */
265
266
  intent: IntentResponseV2;
266
267
  /** Extra data required when calling `POST /swaps/intents/submit`. */
@@ -301,8 +302,8 @@ export interface CancelIntentRequestV2 {
301
302
  }
302
303
  /** POST /swaps/intents/cancel — response body. */
303
304
  export interface CancelIntentResponseV2 {
304
- /** Unsigned cancel transaction (chain-specific shape). For EVM: `{ from, to, value, data }`. */
305
- tx: unknown;
305
+ /** Unsigned cancel-intent transaction the `RawTxReturnType` variant for the request's `srcChainKey`. */
306
+ tx: RawTxReturnType;
306
307
  }
307
308
  /** POST /swaps/intents/hash — request body. */
308
309
  export interface IntentHashRequestV2 {
@@ -10,15 +10,21 @@
10
10
  // - Outbound (response) types are pure JSON: every bigint-derived value (intent
11
11
  // ids, amounts, deadlines, fees, relay chain ids) is a decimal `string`, and
12
12
  // every `Date` is an ISO 8601 `string` (e.g. `abandonedAt`). A response NEVER
13
- // contains `bigint` — JSON cannot represent it.
13
+ // contains `bigint` on the wire — JSON cannot represent it (the one typed
14
+ // exception is the unsigned `tx`; see below).
14
15
  // - Inbound (request) types mirror the server's parsed request DTOs: the Intent
15
16
  // struct (`IntentRequestV2`) carries `bigint` for its numeric fields, matching
16
17
  // the backend `IntentDto`. Other request fields (amounts/deadlines on
17
18
  // `CreateIntentParamsV2`/`QuoteRequestV2`, fees, relay chain ids, etc.) are
18
19
  // decimal `string`, matching their `@IsNumberString` DTO fields.
19
20
  // - `Hex` / `Address` / `Hash` / `SpokeChainKey` are plain `string` everywhere.
20
- // - Chain-specific opaque payloads (unsigned `tx`, gas estimate, raw relay
21
- // `result`) are `unknown` because their shape varies by chain family.
21
+ // - The unsigned `tx` is typed as the SDK domain union `RawTxReturnType`. It
22
+ // travels as pure JSON (bigints stringified; Injective byte arrays as
23
+ // `{ "0": N, … }` index objects), and the SDK client's response schema
24
+ // (`@sodax/sdk` `rawTxSchemas`) rebuilds the domain shape (`bigint`,
25
+ // `Uint8Array`) on parse — the inverse of the backend's `stringifyBigInts`.
26
+ // - The remaining chain-specific opaque payloads (gas estimate, raw relay
27
+ // `result`) stay `unknown` because their shape varies by chain family.
22
28
  //
23
29
  // Shapes used in both directions are split into a `*RequestV2` (client → server)
24
30
  // and a `*ResponseV2` (server → client) interface. `IntentRequestV2` (bigint
@@ -1,2 +1,2 @@
1
- export * from './backendApi.js';
1
+ export * from './backendApiV1.js';
2
2
  export * from './backendApiV2.js';
@@ -1,2 +1,2 @@
1
- export * from './backendApi.js';
1
+ export * from './backendApiV1.js';
2
2
  export * from './backendApiV2.js';
@@ -29,7 +29,7 @@ export const RelayChainIdMap = {
29
29
  [ChainKeys.STACKS_MAINNET]: 60n,
30
30
  };
31
31
  export const INTENT_CHAIN_IDS = Object.values(RelayChainIdMap);
32
- export const IntentRelayChainIdToChainKey = Object.fromEntries(Object.entries(RelayChainIdMap).map(([chainKey, chainId]) => [chainId, chainKey]));
32
+ export const IntentRelayChainIdToChainKey = new Map(Object.entries(RelayChainIdMap).map(([chainKey, chainId]) => [chainId, chainKey]));
33
33
  /**
34
34
  * Base URL for default chain logos hosted in the `@sodax/assets` package.
35
35
  * Each logo is served from `main` via raw.githubusercontent and named by its
@@ -15,11 +15,28 @@ export declare const DEFAULT_BACKEND_API_HEADERS: {
15
15
  };
16
16
  export declare const DEFAULT_RELAYER_API_ENDPOINT = "https://xcall-relay.nw.iconblockchain.xyz";
17
17
  export declare const VAULT_TOKEN_DECIMALS = 18;
18
- export type ApiConfig = {
18
+ export type BaseApiConfig = {
19
19
  baseURL: HttpUrl;
20
20
  timeout: number;
21
21
  headers: Record<string, string>;
22
22
  };
23
+ /** Per-endpoint config for the swaps API. Structurally identical to {@link BaseApiConfig}. */
24
+ export type SwapsApiConfig = BaseApiConfig;
25
+ /**
26
+ * Nested config that points the base (backend) API and the swaps API at independent endpoints.
27
+ * At least one slice must be provided — an empty custom config is meaningless (pass a flat
28
+ * {@link BaseApiConfig} instead). Requiring a slice keeps the two members disjoint from
29
+ * `BaseApiConfig` (which carries `baseURL`), so {@link ApiConfig} can be discriminated by the
30
+ * presence of a `baseApiConfig` / `swapsApiConfig` slice.
31
+ */
32
+ export type CustomApiConfig = {
33
+ baseApiConfig: BaseApiConfig;
34
+ swapsApiConfig?: SwapsApiConfig;
35
+ } | {
36
+ baseApiConfig?: BaseApiConfig;
37
+ swapsApiConfig: SwapsApiConfig;
38
+ };
39
+ export type ApiConfig = BaseApiConfig | CustomApiConfig;
23
40
  export declare const apiConfig: {
24
41
  baseURL: "https://api.sodax.com/v1/be";
25
42
  timeout: number;
package/dist/index.d.ts CHANGED
@@ -19,4 +19,4 @@ export * from './sui/index.js';
19
19
  export * from './swap/index.js';
20
20
  export * from './utils/index.js';
21
21
  export * from './wallet/index.js';
22
- export declare const CONFIG_VERSION = 216;
22
+ export declare const CONFIG_VERSION = 217;
package/dist/index.js CHANGED
@@ -19,4 +19,4 @@ export * from './sui/index.js';
19
19
  export * from './swap/index.js';
20
20
  export * from './utils/index.js';
21
21
  export * from './wallet/index.js';
22
- export const CONFIG_VERSION = 216; // this value should be incremented (inside release/sdk branch) each time @sodax/types package is updated
22
+ export const CONFIG_VERSION = 217; // this value should be incremented (inside release/sdk branch) each time @sodax/types package is updated
@@ -6,4 +6,4 @@
6
6
  * per-feature analytics toggles). It lives in `@sodax/types`, the lowest layer, so every package
7
7
  * shares one source of truth instead of redefining the list; `@sodax/sdk` re-exports it.
8
8
  */
9
- export type SodaxFeature = 'swap' | 'moneyMarket' | 'bridge' | 'staking' | 'migration' | 'dex' | 'partner' | 'recovery' | 'leverageYield';
9
+ export type SodaxFeature = 'swap' | 'moneyMarket' | 'bridge' | 'staking' | 'migration' | 'dex' | 'partner' | 'recovery' | 'backend' | 'leverageYield';
@@ -42,6 +42,7 @@ export type SodaxOptionalConfig = {
42
42
  moneyMarket?: MoneyMarketOptions;
43
43
  bridge?: BridgeOptions;
44
44
  leverageYield?: LeverageYieldOptions;
45
+ swapsOptions?: SwapsClientOptions;
45
46
  };
46
47
  /**
47
48
  * Options (always optional) accepted by `new Sodax(...)`. A deep-partial override of the {@link SodaxDefaultConfig} data
@@ -70,8 +71,17 @@ export type SodaxDefaultConfig = {
70
71
  relay: RelayConfig;
71
72
  };
72
73
  /**
73
- * Sodax default static data object which can always be overriden through Sodax instance (i.e. new Sodax(...config))
74
+ * Client-side swap behavior options. Like {@link SodaxOptionalConfig.logger}, these are runtime toggles
75
+ * resolved once at construction — NOT part of the backend-fetched {@link SodaxDefaultConfig} data.
74
76
  */
77
+ export type SwapsClientOptions = {
78
+ /**
79
+ * Opt-in: route `swap()` through the backend submit-tx 2-step flow (the backend relays +
80
+ * post-executes server-side). On ANY non-success the SDK falls back to the client-side relay so
81
+ * the swap still completes. Default `false` (the current fully client-side flow).
82
+ */
83
+ useBackendSubmitTx?: boolean;
84
+ };
75
85
  export declare const sodaxConfig: {
76
86
  chains: {
77
87
  readonly sonic: {
@@ -5,9 +5,7 @@ import { swapsConfig } from '../swap/swap.js';
5
5
  import { leverageYieldConfig, } from '../leverageYield/leverageYield.js';
6
6
  import { spokeChainConfig, hubConfig, } from '../chains/chains.js';
7
7
  export const bridgeConfig = {};
8
- /**
9
- * Sodax default static data object which can always be overriden through Sodax instance (i.e. new Sodax(...config))
10
- */
8
+ // default sodax config object which can always be overriden through Sodax instance (i.e. new Sodax(...config))
11
9
  export const sodaxConfig = {
12
10
  chains: spokeChainConfig,
13
11
  swaps: swapsConfig,
@@ -100,6 +100,8 @@ export interface ISolanaWalletProvider extends ICoreWallet {
100
100
  readonly chainType: 'SOLANA';
101
101
  getWalletAddress: () => Promise<string>;
102
102
  sendTransaction: (rawTransaction: Uint8Array | Array<number>) => Promise<TransactionSignature>;
103
+ /** Deserialize, sign, and broadcast an unsigned `SolanaRawTransaction` (e.g. from the Swaps API). */
104
+ signAndSendTransaction?: (params: SolanaRawTransaction) => Promise<TransactionSignature>;
103
105
  waitForConfirmation: (signature: TransactionSignature, commitment: Commitment) => Promise<SolanaRpcResponseAndContext<SolanaSignatureResult>>;
104
106
  buildV0Txn: (instructions: SolanaRawTransactionInstruction[]) => Promise<SolanaSerializedTransaction>;
105
107
  getWalletBase58PublicKey: () => SolanaBase58PublicKey;
@@ -207,4 +207,6 @@ export interface IStacksWalletProvider extends ICoreWallet {
207
207
  getPublicKey: () => Promise<string>;
208
208
  getBalance: (address: string) => Promise<bigint>;
209
209
  sendTransaction: (txParams: StacksTransactionParams) => Promise<string>;
210
+ /** Sign and broadcast an unsigned `StacksRawTransaction` (e.g. from the Swaps API). Returns the tx id. */
211
+ signAndSendTransaction?: (params: StacksRawTransaction) => Promise<string>;
210
212
  }
@@ -92,5 +92,9 @@ export interface IStellarWalletProvider extends ICoreWallet {
92
92
  readonly chainType: 'STELLAR';
93
93
  signTransaction: (tx: XDR) => Promise<XDR>;
94
94
  waitForTransactionReceipt: (txHash: string) => Promise<StellarRawTransactionReceipt>;
95
+ /** Broadcast an already-signed XDR transaction via the Soroban RPC server. Returns the tx hash. */
96
+ sendTransaction?: (signedTx: XDR) => Promise<string>;
97
+ /** Sign and broadcast an unsigned `StellarRawTransaction` (e.g. from the Swaps API). Returns the tx hash. */
98
+ signAndSendTransaction?: (params: StellarRawTransaction) => Promise<string>;
95
99
  }
96
100
  export {};
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "2.0.0-rc.18",
7
+ "version": "2.0.0-rc.19",
8
8
  "description": "Sodax Common Types",
9
9
  "main": "dist/index.js",
10
10
  "homepage": "https://github.com/icon-project/sodax-sdks/tree/main/packages/types",
@@ -1,74 +0,0 @@
1
- import type { SpokeChainKey, IntentRelayChainIdMap } from '../chains/chains.js';
2
- import type { XToken } from '../chains/tokens.js';
3
- import type { Result, SpokeChainConfigMap } from '../common/common.js';
4
- import type { Address } from '../shared/shared.js';
5
- import type { SodaxConfig } from '../sodax-config/sodax-config.js';
6
- export type GetChainsApiResponse = readonly SpokeChainKey[];
7
- export type GetSwapTokensApiResponse = Record<SpokeChainKey, readonly XToken[]>;
8
- export type GetSwapTokensByChainIdApiResponse = readonly XToken[];
9
- export type GetMoneyMarketTokensApiResponse = Record<SpokeChainKey, readonly XToken[]>;
10
- export type GetMoneyMarketTokensByChainIdApiResponse = readonly XToken[];
11
- export type GetRelayChainIdMapApiResponse = IntentRelayChainIdMap;
12
- export type GetSpokeChainConfigApiResponse = SpokeChainConfigMap;
13
- export type GetMoneyMarketReserveAssetsApiResponse = readonly Address[];
14
- export type GetAllConfigApiResponse = {
15
- version?: number;
16
- config: SodaxConfig;
17
- };
18
- export interface IConfigApi {
19
- getChains(): Promise<Result<GetChainsApiResponse>>;
20
- getSwapTokens(): Promise<Result<GetSwapTokensApiResponse>>;
21
- getSwapTokensByChainId(chainId: SpokeChainKey): Promise<Result<GetSwapTokensByChainIdApiResponse>>;
22
- getMoneyMarketTokens(): Promise<Result<GetMoneyMarketTokensApiResponse>>;
23
- getMoneyMarketTokensByChainId(chainId: SpokeChainKey): Promise<Result<GetMoneyMarketTokensByChainIdApiResponse>>;
24
- }
25
- export interface SwapIntentData {
26
- intentId: string;
27
- creator: string;
28
- inputToken: string;
29
- outputToken: string;
30
- inputAmount: string;
31
- minOutputAmount: string;
32
- deadline: string;
33
- allowPartialFill: boolean;
34
- srcChain: number;
35
- dstChain: number;
36
- srcAddress: string;
37
- dstAddress: string;
38
- solver: string;
39
- data: string;
40
- }
41
- export interface SubmitSwapTxRequest {
42
- txHash: string;
43
- srcChainKey: string;
44
- walletAddress: string;
45
- intent: SwapIntentData;
46
- relayData: string;
47
- }
48
- export interface SubmitSwapTxResponse {
49
- success: boolean;
50
- message: string;
51
- }
52
- export interface GetSubmitSwapTxStatusParams {
53
- txHash: string;
54
- srcChainKey?: string;
55
- }
56
- export interface SubmitSwapTxStatusResult {
57
- dstIntentTxHash: string;
58
- packetData?: Record<string, unknown>;
59
- intent_hash?: string;
60
- }
61
- export type SubmitSwapTxStatus = 'pending' | 'verifying' | 'verified' | 'relaying' | 'relayed' | 'posting_execution' | 'executed' | 'failed';
62
- export interface SubmitSwapTxStatusData {
63
- txHash: string;
64
- srcChainKey: string;
65
- status: SubmitSwapTxStatus;
66
- failedAtStep?: string;
67
- failureReason?: string;
68
- failedAttempts: number;
69
- result?: SubmitSwapTxStatusResult;
70
- }
71
- export interface SubmitSwapTxStatusResponse {
72
- success: boolean;
73
- data: SubmitSwapTxStatusData;
74
- }
File without changes