@sodax/types 2.0.0-rc.9 → 2.1.0-rc.1
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/dist/backend/backendApiV1.d.ts +28 -0
- package/dist/backend/backendApiV2.d.ts +678 -0
- package/dist/backend/backendApiV2.js +38 -0
- package/dist/backend/index.d.ts +3 -1
- package/dist/backend/index.js +3 -1
- package/dist/backend/sponsoringApi.d.ts +62 -0
- package/dist/backend/sponsoringApi.js +12 -0
- package/dist/bitcoin/bitcoin.d.ts +18 -0
- package/dist/bitcoin/bitcoin.js +13 -0
- package/dist/chains/chain-keys.d.ts +3 -2
- package/dist/chains/chain-keys.js +1 -0
- package/dist/chains/chains.d.ts +435 -16
- package/dist/chains/chains.js +76 -4
- package/dist/chains/tokens.d.ts +592 -12
- package/dist/chains/tokens.js +285 -5
- package/dist/common/common.d.ts +15 -7
- package/dist/common/constants.d.ts +35 -1
- package/dist/common/constants.js +6 -0
- package/dist/dex/dex.d.ts +4 -1
- package/dist/hooks/hooks.d.ts +42 -0
- package/dist/hooks/hooks.js +44 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/injective/injective.d.ts +4 -0
- package/dist/leverageYield/index.d.ts +1 -0
- package/dist/leverageYield/index.js +1 -0
- package/dist/leverageYield/leverageYield.d.ts +152 -0
- package/dist/leverageYield/leverageYield.js +51 -0
- package/dist/moneyMarket/moneyMarket.d.ts +248 -6
- package/dist/moneyMarket/moneyMarket.js +13 -0
- package/dist/near/near-api-js.d.ts +453 -453
- package/dist/near/near.d.ts +5 -1
- package/dist/shared/analytics.d.ts +119 -0
- package/dist/shared/analytics.js +1 -0
- package/dist/shared/features.d.ts +9 -0
- package/dist/shared/features.js +1 -0
- package/dist/shared/index.d.ts +3 -0
- package/dist/shared/index.js +3 -0
- package/dist/shared/logger.d.ts +27 -0
- package/dist/shared/logger.js +1 -0
- package/dist/shared/shared.d.ts +21 -0
- package/dist/sodax-config/sodax-config.d.ts +769 -73
- package/dist/sodax-config/sodax-config.js +3 -4
- package/dist/solana/solana.d.ts +2 -0
- package/dist/stacks/stacks.d.ts +2 -0
- package/dist/stellar/stellar.d.ts +11 -1
- package/dist/sui/sui.d.ts +3 -2
- package/dist/swap/swap.d.ts +478 -90
- package/dist/swap/swap.js +79 -12
- package/dist/utils/utils.js +1 -1
- package/dist/wallet/wallet.d.ts +2 -2
- package/package.json +3 -3
- package/dist/backend/backendApi.d.ts +0 -74
- /package/dist/backend/{backendApi.js → backendApiV1.js} +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Backend Swaps API v2 — request/response contract types.
|
|
2
|
+
//
|
|
3
|
+
// One type per request/response of every endpoint in the backend `swaps-api`
|
|
4
|
+
// controller (`apps/swaps-api/src/api/swaps/swaps.controller.ts`). They favor
|
|
5
|
+
// plain primitives (`string`/`number`/`boolean`/`bigint`/plain objects) over SDK
|
|
6
|
+
// branded types.
|
|
7
|
+
//
|
|
8
|
+
// Inbound (request) and outbound (response) shapes are SEPARATE types because the
|
|
9
|
+
// two directions genuinely differ:
|
|
10
|
+
// - Outbound (response) types are pure JSON: every bigint-derived value (intent
|
|
11
|
+
// ids, amounts, deadlines, fees, relay chain ids) is a decimal `string`, and
|
|
12
|
+
// every `Date` is an ISO 8601 `string` (e.g. `abandonedAt`). A response NEVER
|
|
13
|
+
// contains `bigint` on the wire — JSON cannot represent it (the one typed
|
|
14
|
+
// exception is the unsigned `tx`; see below).
|
|
15
|
+
// - Inbound (request) types mirror the server's parsed request DTOs: the Intent
|
|
16
|
+
// struct (`IntentRequestV2`) carries `bigint` for its numeric fields, matching
|
|
17
|
+
// the backend `IntentDto`. Other request fields (amounts/deadlines on
|
|
18
|
+
// `CreateIntentParamsV2`/`QuoteRequestV2`, fees, relay chain ids, etc.) are
|
|
19
|
+
// decimal `string`, matching their `@IsNumberString` DTO fields.
|
|
20
|
+
// - `Hex` / `Address` / `Hash` / `SpokeChainKey` are plain `string` everywhere.
|
|
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.
|
|
28
|
+
//
|
|
29
|
+
// Shapes used in both directions are split into a `*RequestV2` (client → server)
|
|
30
|
+
// and a `*ResponseV2` (server → client) interface. `IntentRequestV2` (bigint
|
|
31
|
+
// numerics) and `IntentResponseV2` (all-string) genuinely differ;
|
|
32
|
+
// `RelayExtraDataRequestV2` / `RelayExtraDataResponseV2` are identical (no bigint
|
|
33
|
+
// fields). This mirrors the backend's request/response DTO pairs.
|
|
34
|
+
//
|
|
35
|
+
// The Config API v2 section at the bottom of this file takes a DIFFERENT approach
|
|
36
|
+
// (see its header): it REUSES the canonical `@sodax/types` config types and projects
|
|
37
|
+
// only the few bigint fields to `string`, rather than re-declaring a parallel tree.
|
|
38
|
+
export {};
|
package/dist/backend/index.d.ts
CHANGED
package/dist/backend/index.js
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** Build parameters enforced by the Stellar sponsoring service. */
|
|
2
|
+
export interface StellarSponsorConfig {
|
|
3
|
+
/** Rotatable sponsor public key; do not hardcode it in clients. */
|
|
4
|
+
sponsorAccount: string;
|
|
5
|
+
networkPassphrase: string;
|
|
6
|
+
minTotalFeeStroops: string;
|
|
7
|
+
maxTotalFeeStroops: string;
|
|
8
|
+
operationCount: number;
|
|
9
|
+
minPerOperationFeeStroops: string;
|
|
10
|
+
maxPerOperationFeeStroops: string;
|
|
11
|
+
/** Fee per operation to pass to `TransactionBuilder`. */
|
|
12
|
+
recommendedPerOperationFeeStroops: string;
|
|
13
|
+
/** Maximum distance from now to the transaction's `maxTime`, in seconds. */
|
|
14
|
+
maxTimeboundSeconds: number;
|
|
15
|
+
/** Required `createAccount.startingBalance`; do not hardcode it. */
|
|
16
|
+
requiredStartingBalance: string;
|
|
17
|
+
}
|
|
18
|
+
/** Request body for a Stellar sponsored account creation. Extra fields are rejected. */
|
|
19
|
+
export interface StellarSponsoredAccountRequest {
|
|
20
|
+
/**
|
|
21
|
+
* Base64 transaction XDR signed by the account being created.
|
|
22
|
+
* Must not be a fee-bump envelope.
|
|
23
|
+
*/
|
|
24
|
+
data: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Successful sponsored-account result. An already-active account is also a
|
|
28
|
+
* success, but has no submitted transaction hash.
|
|
29
|
+
*/
|
|
30
|
+
export type StellarSponsoredAccountResponse = {
|
|
31
|
+
hash: string;
|
|
32
|
+
alreadyActive: false;
|
|
33
|
+
} | {
|
|
34
|
+
hash: null;
|
|
35
|
+
alreadyActive: true;
|
|
36
|
+
};
|
|
37
|
+
export type SponsoringApiErrorCode = 'INVALID_SPONSOR_XDR' | 'INVALID_RESERVE_DATA' | 'SPONSOR_SEQUENCE_CONFLICT' | 'SPONSOR_TRANSACTION_REJECTED' | 'HORIZON_UNAVAILABLE' | 'SPONSOR_RATE_LIMITED' | 'SPONSOR_BUDGET_EXHAUSTED';
|
|
38
|
+
/** Runtime values used to distinguish domain codes from framework error labels. */
|
|
39
|
+
export declare const SPONSORING_API_ERROR_CODES: readonly ["INVALID_SPONSOR_XDR", "INVALID_RESERVE_DATA", "SPONSOR_SEQUENCE_CONFLICT", "SPONSOR_TRANSACTION_REJECTED", "HORIZON_UNAVAILABLE", "SPONSOR_RATE_LIMITED", "SPONSOR_BUDGET_EXHAUSTED"];
|
|
40
|
+
/**
|
|
41
|
+
* `error` may be a domain code, a framework label, or absent. Check it
|
|
42
|
+
* against {@link SPONSORING_API_ERROR_CODES} before treating it as a code.
|
|
43
|
+
*/
|
|
44
|
+
export interface SponsoringApiErrorResponse {
|
|
45
|
+
statusCode: number;
|
|
46
|
+
/** Human-readable only; do not use for control flow. */
|
|
47
|
+
message: string;
|
|
48
|
+
error?: SponsoringApiErrorCode | string;
|
|
49
|
+
/** Per-key rate-limit backoff in seconds. */
|
|
50
|
+
retryAfterSeconds?: number;
|
|
51
|
+
/**
|
|
52
|
+
* Current sponsor sequence on a sequence conflict. Advisory because another
|
|
53
|
+
* submission can immediately make it stale.
|
|
54
|
+
*/
|
|
55
|
+
sponsorSequence?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface IStellarSponsoringApi<GetConfigArgs extends unknown[] = [], CreateAccountArgs extends unknown[] = []> {
|
|
58
|
+
/** GET /sponsorships/stellar/config */
|
|
59
|
+
getStellarSponsorConfig(...extraArgs: GetConfigArgs): Promise<StellarSponsorConfig>;
|
|
60
|
+
/** POST /sponsorships/stellar/accounts */
|
|
61
|
+
createStellarSponsoredAccount(body: StellarSponsoredAccountRequest, ...extraArgs: CreateAccountArgs): Promise<StellarSponsoredAccountResponse>;
|
|
62
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Runtime values used to distinguish domain codes from framework error labels. */
|
|
2
|
+
export const SPONSORING_API_ERROR_CODES = [
|
|
3
|
+
'INVALID_SPONSOR_XDR',
|
|
4
|
+
'INVALID_RESERVE_DATA',
|
|
5
|
+
'SPONSOR_SEQUENCE_CONFLICT',
|
|
6
|
+
'SPONSOR_TRANSACTION_REJECTED',
|
|
7
|
+
'HORIZON_UNAVAILABLE',
|
|
8
|
+
'SPONSOR_RATE_LIMITED',
|
|
9
|
+
'SPONSOR_BUDGET_EXHAUSTED',
|
|
10
|
+
];
|
|
11
|
+
// Keep the runtime list exhaustive.
|
|
12
|
+
true;
|
|
@@ -6,6 +6,17 @@ export declare function isSupportedBitcoinAddressType(addressType: string): addr
|
|
|
6
6
|
* Shared utility — use this instead of duplicating prefix checks.
|
|
7
7
|
*/
|
|
8
8
|
export declare function detectBitcoinAddressType(address: string): BtcAddressType;
|
|
9
|
+
/**
|
|
10
|
+
* Off-chain message-signing scheme a Bitcoin address type must use: BIP-322 vs ECDSA (BIP-137).
|
|
11
|
+
*
|
|
12
|
+
* - **P2WPKH / P2TR → BIP-322.** Taproot keys are Schnorr/x-only, so ECDSA cannot sign for them
|
|
13
|
+
* (and wallets like Xverse default to Taproot).
|
|
14
|
+
* - **P2SH / P2PKH → ECDSA (BIP-137).** Browser wallets (UniSat/OKX) reject BIP-322 on
|
|
15
|
+
* nested-segwit/legacy addresses — they throw "Not support address type to sign".
|
|
16
|
+
*
|
|
17
|
+
* No single scheme works for every address type, so signers AND verifiers must branch on this.
|
|
18
|
+
*/
|
|
19
|
+
export declare function usesBip322MessageSigning(addressType: BtcAddressType): boolean;
|
|
9
20
|
export declare const BTC_WALLET_ADDRESS_TYPES: readonly ["taproot", "segwit"];
|
|
10
21
|
/** User-friendly Bitcoin address type for wallet connection. */
|
|
11
22
|
export type BtcWalletAddressType = (typeof BTC_WALLET_ADDRESS_TYPES)[number];
|
|
@@ -86,6 +97,13 @@ export interface IBitcoinWalletProvider extends ICoreWallet {
|
|
|
86
97
|
signTransaction(psbt: string, finalize?: boolean): Promise<string>;
|
|
87
98
|
signEcdsaMessage(message: string): Promise<string>;
|
|
88
99
|
signBip322Message(message: string): Promise<string>;
|
|
100
|
+
/**
|
|
101
|
+
* Get the signer's public key as a hex string. Optional capability: required only for the
|
|
102
|
+
* money-market on-demand (borrow/withdraw) flow, where the relay needs the key to verify a
|
|
103
|
+
* BIP-322 (Schnorr/Taproot) signature — which is not public-key-recoverable. Wallets that
|
|
104
|
+
* cannot expose it omit this method; callers guard before use.
|
|
105
|
+
*/
|
|
106
|
+
getPublicKey?(): Promise<string>;
|
|
89
107
|
/**
|
|
90
108
|
* Send Bitcoin to an address
|
|
91
109
|
* @param toAddress - Destination Bitcoin address
|
package/dist/bitcoin/bitcoin.js
CHANGED
|
@@ -17,6 +17,19 @@ export function detectBitcoinAddressType(address) {
|
|
|
17
17
|
return 'P2PKH';
|
|
18
18
|
throw new Error(`Unknown Bitcoin address type: ${address}`);
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Off-chain message-signing scheme a Bitcoin address type must use: BIP-322 vs ECDSA (BIP-137).
|
|
22
|
+
*
|
|
23
|
+
* - **P2WPKH / P2TR → BIP-322.** Taproot keys are Schnorr/x-only, so ECDSA cannot sign for them
|
|
24
|
+
* (and wallets like Xverse default to Taproot).
|
|
25
|
+
* - **P2SH / P2PKH → ECDSA (BIP-137).** Browser wallets (UniSat/OKX) reject BIP-322 on
|
|
26
|
+
* nested-segwit/legacy addresses — they throw "Not support address type to sign".
|
|
27
|
+
*
|
|
28
|
+
* No single scheme works for every address type, so signers AND verifiers must branch on this.
|
|
29
|
+
*/
|
|
30
|
+
export function usesBip322MessageSigning(addressType) {
|
|
31
|
+
return addressType === 'P2WPKH' || addressType === 'P2TR';
|
|
32
|
+
}
|
|
20
33
|
export const BTC_WALLET_ADDRESS_TYPES = ['taproot', 'segwit'];
|
|
21
34
|
/** Address types that Sodax supports for transactions. */
|
|
22
35
|
const BTC_ADDRESS_TYPES = ['P2PKH', 'P2SH', 'P2WPKH', 'P2TR'];
|
|
@@ -23,8 +23,9 @@ export declare const ChainKeys: {
|
|
|
23
23
|
readonly REDBELLY_MAINNET: "redbelly";
|
|
24
24
|
readonly KAIA_MAINNET: "0x2019.kaia";
|
|
25
25
|
readonly STACKS_MAINNET: "stacks";
|
|
26
|
+
readonly HEDERA_MAINNET: "hedera";
|
|
26
27
|
};
|
|
27
28
|
export type ChainKey = (typeof ChainKeys)[keyof typeof ChainKeys];
|
|
28
|
-
export declare const CHAIN_KEYS: ("0xa86a.avax" | "0xa4b1.arbitrum" | "0x2105.base" | "0x38.bsc" | "injective-1" | "sonic" | "0x1.icon" | "sui" | "0xa.optimism" | "0x89.polygon" | "solana" | "stellar" | "hyper" | "lightlink" | "near" | "ethereum" | "bitcoin" | "redbelly" | "0x2019.kaia" | "stacks")[];
|
|
29
|
-
export declare const spokeChainKeysSet: Set<"0xa86a.avax" | "0xa4b1.arbitrum" | "0x2105.base" | "0x38.bsc" | "injective-1" | "sonic" | "0x1.icon" | "sui" | "0xa.optimism" | "0x89.polygon" | "solana" | "stellar" | "hyper" | "lightlink" | "near" | "ethereum" | "bitcoin" | "redbelly" | "0x2019.kaia" | "stacks">;
|
|
29
|
+
export declare const CHAIN_KEYS: ("0xa86a.avax" | "0xa4b1.arbitrum" | "0x2105.base" | "0x38.bsc" | "injective-1" | "sonic" | "0x1.icon" | "sui" | "0xa.optimism" | "0x89.polygon" | "solana" | "stellar" | "hyper" | "lightlink" | "near" | "ethereum" | "bitcoin" | "redbelly" | "0x2019.kaia" | "stacks" | "hedera")[];
|
|
30
|
+
export declare const spokeChainKeysSet: Set<"0xa86a.avax" | "0xa4b1.arbitrum" | "0x2105.base" | "0x38.bsc" | "injective-1" | "sonic" | "0x1.icon" | "sui" | "0xa.optimism" | "0x89.polygon" | "solana" | "stellar" | "hyper" | "lightlink" | "near" | "ethereum" | "bitcoin" | "redbelly" | "0x2019.kaia" | "stacks" | "hedera">;
|
|
30
31
|
export type ChainType = (typeof ChainTypeArr)[number];
|
|
@@ -33,6 +33,7 @@ export const ChainKeys = {
|
|
|
33
33
|
REDBELLY_MAINNET: 'redbelly',
|
|
34
34
|
KAIA_MAINNET: '0x2019.kaia',
|
|
35
35
|
STACKS_MAINNET: 'stacks',
|
|
36
|
+
HEDERA_MAINNET: 'hedera',
|
|
36
37
|
};
|
|
37
38
|
export const CHAIN_KEYS = Object.values(ChainKeys);
|
|
38
39
|
export const spokeChainKeysSet = new Set(CHAIN_KEYS);
|