@heliofi/withdraw-core 0.0.1 → 0.0.2
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 +12 -0
- package/dist/errors/WithdrawalApiError.d.ts +9 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/index.d.ts +7 -1
- package/dist/jwt.d.ts +8 -0
- package/dist/sdk/ApiClient.d.ts +16 -0
- package/dist/sdk/WithdrawalSDK.d.ts +31 -0
- package/dist/sdk/index.d.ts +2 -0
- package/dist/types/enums.d.ts +66 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/prepared.d.ts +31 -0
- package/dist/types/requests.d.ts +47 -0
- package/dist/types/responses.d.ts +77 -0
- package/dist/withdraw-core.cjs +1 -0
- package/dist/withdraw-core.js +154 -0
- package/package.json +17 -16
- package/dist/withdraw-core.es.js +0 -4
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @heliofi/withdraw-core
|
|
2
|
+
|
|
3
|
+
Core JS/TS SDK for MoonPay Commerce withdrawals — routes, quotes, balance checks, and transaction submission.
|
|
4
|
+
|
|
5
|
+
## Install guide
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @heliofi/withdraw-core
|
|
9
|
+
yarn add @heliofi/withdraw-core
|
|
10
|
+
pnpm add @heliofi/withdraw-core
|
|
11
|
+
```
|
|
12
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WithdrawalErrorCode } from '../types/enums';
|
|
2
|
+
export declare class WithdrawalApiError extends Error {
|
|
3
|
+
readonly status: number;
|
|
4
|
+
readonly code: WithdrawalErrorCode;
|
|
5
|
+
readonly detail?: string | undefined;
|
|
6
|
+
readonly name = "WithdrawalApiError";
|
|
7
|
+
constructor(status: number, code: WithdrawalErrorCode, detail?: string | undefined);
|
|
8
|
+
}
|
|
9
|
+
export declare const toWithdrawalErrorCode: (raw: string | undefined) => WithdrawalErrorCode;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { toWithdrawalErrorCode, WithdrawalApiError, } from './WithdrawalApiError';
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { toWithdrawalErrorCode, WithdrawalApiError, } from './errors';
|
|
2
|
+
export type { WithdrawalJwtPayload } from './jwt';
|
|
3
|
+
export { decodeJwt, isQuoteExpired } from './jwt';
|
|
4
|
+
export type { ApiClientConfig } from './sdk';
|
|
5
|
+
export { WithdrawalSDK } from './sdk';
|
|
6
|
+
export type { BalanceResponse, BaseBlockchain, PolymarketWalletPreparedTransaction, PreparedTransaction, PrepareWithdrawalParams, QuoteResponse, QuoteSummary, RawPreparedTransaction, RoutesResponse, SlimCurrencyWithBlockchain, StatusResponse, SubmitResponse, SubmitWithdrawalParams, UpdateQuoteParams, UserOpPreparedTransaction, WalletCurrencyBalance, WithdrawalConfig, WithdrawalCurrenciesExchangeRate, WithdrawalCustomerSwapRoute, } from './types';
|
|
7
|
+
export { BroadcastAck, SignedTransactionKind, TERMINAL_STATES, WithdrawalErrorCode, WithdrawalState, WithdrawBlockchainSymbol, WithdrawFeature, WithdrawPlatform, } from './types';
|
package/dist/jwt.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface WithdrawalJwtPayload {
|
|
2
|
+
exp?: number;
|
|
3
|
+
iat?: number;
|
|
4
|
+
withdrawalDetailId?: string;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
export declare const decodeJwt: (jwt: string) => WithdrawalJwtPayload;
|
|
8
|
+
export declare const isQuoteExpired: (jwt: string, bufferMs?: number) => boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface ApiClientConfig {
|
|
2
|
+
baseUrl: string;
|
|
3
|
+
headers?: Record<string, string>;
|
|
4
|
+
fetch?: typeof globalThis.fetch;
|
|
5
|
+
}
|
|
6
|
+
export declare class ApiClient {
|
|
7
|
+
private readonly baseUrl;
|
|
8
|
+
private readonly headers;
|
|
9
|
+
private readonly fetch;
|
|
10
|
+
constructor(config: ApiClientConfig);
|
|
11
|
+
get<T>(path: string, signal?: AbortSignal): Promise<T>;
|
|
12
|
+
post<T>(path: string, body: unknown, signal?: AbortSignal): Promise<T>;
|
|
13
|
+
patch<T>(path: string, body: unknown, signal?: AbortSignal): Promise<T>;
|
|
14
|
+
private request;
|
|
15
|
+
private buildError;
|
|
16
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { QuoteResponse } from '../types/prepared';
|
|
2
|
+
import type { PrepareWithdrawalParams, SubmitWithdrawalParams, UpdateQuoteParams } from '../types/requests';
|
|
3
|
+
import type { BalanceResponse, RoutesResponse, StatusResponse, SubmitResponse, WithdrawalConfig } from '../types/responses';
|
|
4
|
+
import { type ApiClientConfig } from './ApiClient';
|
|
5
|
+
export declare class WithdrawalSDK {
|
|
6
|
+
private readonly api;
|
|
7
|
+
constructor(config: ApiClientConfig);
|
|
8
|
+
getWithdrawalConfig(withdrawalConfigId: string, signal?: AbortSignal): Promise<WithdrawalConfig>;
|
|
9
|
+
getRoutes(withdrawalConfigId: string, signal?: AbortSignal): Promise<RoutesResponse>;
|
|
10
|
+
getBalance(withdrawalConfigId: string, walletAddress: string, signal?: AbortSignal): Promise<BalanceResponse>;
|
|
11
|
+
/**
|
|
12
|
+
* Calls `POST /withdraw/:withdrawalConfigId/prepare`.
|
|
13
|
+
* `withdrawalConfigId` goes in the path; the remaining fields are the
|
|
14
|
+
* request body matching the backend `PreparedWithdrawalDto`.
|
|
15
|
+
*/
|
|
16
|
+
prepare(params: PrepareWithdrawalParams, signal?: AbortSignal): Promise<QuoteResponse>;
|
|
17
|
+
/**
|
|
18
|
+
* Update an existing quote.
|
|
19
|
+
*
|
|
20
|
+
* NOTE: The backend does not yet expose a PATCH endpoint for prepare.
|
|
21
|
+
* This stub is kept for forward compatibility. It will throw until
|
|
22
|
+
* the backend ships the handler.
|
|
23
|
+
*/
|
|
24
|
+
updateQuote(_withdrawalDetailId: string, _params: UpdateQuoteParams, _signal?: AbortSignal): Promise<QuoteResponse>;
|
|
25
|
+
/**
|
|
26
|
+
* Body matches the backend `SubmitWithdrawalDto`:
|
|
27
|
+
* `{ token, signedTx }`, where `signedTx` is the bare signed payload string.
|
|
28
|
+
*/
|
|
29
|
+
submitWithdrawal(params: SubmitWithdrawalParams, signal?: AbortSignal): Promise<SubmitResponse>;
|
|
30
|
+
getWithdrawalDetail(withdrawalDetailId: string, signal?: AbortSignal): Promise<StatusResponse>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export declare enum WithdrawalState {
|
|
2
|
+
QUOTED = "QUOTED",
|
|
3
|
+
SUBMITTING = "SUBMITTING",
|
|
4
|
+
SUBMITTED = "SUBMITTED",
|
|
5
|
+
BRIDGING = "BRIDGING",
|
|
6
|
+
COMPLETED = "COMPLETED",
|
|
7
|
+
FAILED = "FAILED",
|
|
8
|
+
FAILED_EXPIRED = "FAILED_EXPIRED",
|
|
9
|
+
EXPIRED = "EXPIRED",
|
|
10
|
+
REFUNDED_BY_PROVIDER = "REFUNDED_BY_PROVIDER"
|
|
11
|
+
}
|
|
12
|
+
export declare const TERMINAL_STATES: ReadonlySet<WithdrawalState>;
|
|
13
|
+
export declare enum WithdrawalErrorCode {
|
|
14
|
+
WITHDRAW_TX_INVALID_SIGNATURE = "WITHDRAW_TX_INVALID_SIGNATURE",
|
|
15
|
+
WITHDRAW_TX_BLOCKHASH_EXPIRED = "WITHDRAW_TX_BLOCKHASH_EXPIRED",
|
|
16
|
+
WITHDRAW_TX_NONCE_TOO_LOW = "WITHDRAW_TX_NONCE_TOO_LOW",
|
|
17
|
+
WITHDRAW_TX_USEROP_EXPIRED = "WITHDRAW_TX_USEROP_EXPIRED",
|
|
18
|
+
WITHDRAW_TX_UNDERPRICED = "WITHDRAW_TX_UNDERPRICED",
|
|
19
|
+
WITHDRAW_BUNDLER_REJECTED = "WITHDRAW_BUNDLER_REJECTED",
|
|
20
|
+
WITHDRAW_TX_BROADCAST_TIMEOUT = "WITHDRAW_TX_BROADCAST_TIMEOUT",
|
|
21
|
+
WITHDRAW_TX_ALREADY_KNOWN = "WITHDRAW_TX_ALREADY_KNOWN",
|
|
22
|
+
WITHDRAW_QUOTE_EXPIRED = "WITHDRAW_QUOTE_EXPIRED",
|
|
23
|
+
WITHDRAW_SANCTIONS_BLOCKED = "WITHDRAW_SANCTIONS_BLOCKED",
|
|
24
|
+
WITHDRAW_NO_ROUTE = "WITHDRAW_NO_ROUTE",
|
|
25
|
+
WITHDRAW_NOT_FOUND = "WITHDRAW_NOT_FOUND",
|
|
26
|
+
WITHDRAW_INSUFFICIENT_BALANCE = "WITHDRAW_INSUFFICIENT_BALANCE",
|
|
27
|
+
WITHDRAW_DETAILS_NOT_UPDATABLE = "WITHDRAW_DETAILS_NOT_UPDATABLE",
|
|
28
|
+
INVALID_WALLET_ADDRESS = "INVALID_WALLET_ADDRESS",
|
|
29
|
+
BALANCE_FETCH_FAILED = "BALANCE_FETCH_FAILED",
|
|
30
|
+
UNKNOWN = "UNKNOWN"
|
|
31
|
+
}
|
|
32
|
+
export declare enum BroadcastAck {
|
|
33
|
+
ACKNOWLEDGED = "acknowledged",
|
|
34
|
+
UNACKNOWLEDGED = "unacknowledged",
|
|
35
|
+
REJECTED = "rejected"
|
|
36
|
+
}
|
|
37
|
+
export declare enum SignedTransactionKind {
|
|
38
|
+
RAW = "raw",
|
|
39
|
+
USER_OP = "userop",
|
|
40
|
+
POLYMARKET_WALLET = "polymarket_wallet"
|
|
41
|
+
}
|
|
42
|
+
/** Mirror of backend `Platform` (packages/common/.../constants/platform.ts). */
|
|
43
|
+
export declare enum WithdrawPlatform {
|
|
44
|
+
HELIO = "HELIO",
|
|
45
|
+
MAGIC_EDEN = "MAGIC_EDEN"
|
|
46
|
+
}
|
|
47
|
+
/** Mirror of backend `WithdrawalFeature` (.../withdraw/constants/WithdrawalFeature.ts). */
|
|
48
|
+
export declare enum WithdrawFeature {
|
|
49
|
+
IRON = "iron",
|
|
50
|
+
MP_SELL = "mp_sell"
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Mirror of backend `BlockchainSymbol`
|
|
54
|
+
* (.../blockchain/constants/BlockchainSymbol.ts) — withdraw-supported chains.
|
|
55
|
+
*/
|
|
56
|
+
export declare enum WithdrawBlockchainSymbol {
|
|
57
|
+
SOL = "SOL",
|
|
58
|
+
ETH = "ETH",
|
|
59
|
+
POLYGON = "POLYGON",
|
|
60
|
+
BASE = "BASE",
|
|
61
|
+
BITCOIN = "BITCOIN",
|
|
62
|
+
ARBITRUM = "ARBITRUM",
|
|
63
|
+
BSC = "BSC",
|
|
64
|
+
TRON = "TRON",
|
|
65
|
+
DOGE = "DOGE"
|
|
66
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { BroadcastAck, SignedTransactionKind, TERMINAL_STATES, WithdrawalErrorCode, WithdrawalState, WithdrawBlockchainSymbol, WithdrawFeature, WithdrawPlatform, } from './enums';
|
|
2
|
+
export type { PolymarketWalletPreparedTransaction, PreparedTransaction, QuoteResponse, QuoteSummary, RawPreparedTransaction, UserOpPreparedTransaction, } from './prepared';
|
|
3
|
+
export type { PrepareWithdrawalParams, SubmitWithdrawalParams, UpdateQuoteParams, } from './requests';
|
|
4
|
+
export type { BalanceResponse, BaseBlockchain, RoutesResponse, SlimCurrencyWithBlockchain, StatusResponse, SubmitResponse, WalletCurrencyBalance, WithdrawalConfig, WithdrawalCurrenciesExchangeRate, WithdrawalCustomerSwapRoute, } from './responses';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { SignedTransactionKind } from './enums';
|
|
2
|
+
export interface PolymarketWalletPreparedTransaction {
|
|
3
|
+
kind: SignedTransactionKind.POLYMARKET_WALLET;
|
|
4
|
+
typedData: Record<string, unknown>;
|
|
5
|
+
}
|
|
6
|
+
export interface RawPreparedTransaction {
|
|
7
|
+
kind: SignedTransactionKind.RAW;
|
|
8
|
+
chain: string;
|
|
9
|
+
unsignedTx: string;
|
|
10
|
+
}
|
|
11
|
+
export interface UserOpPreparedTransaction {
|
|
12
|
+
kind: SignedTransactionKind.USER_OP;
|
|
13
|
+
chain: string;
|
|
14
|
+
userOp: Record<string, unknown>;
|
|
15
|
+
entryPoint: string;
|
|
16
|
+
}
|
|
17
|
+
export type PreparedTransaction = PolymarketWalletPreparedTransaction | RawPreparedTransaction | UserOpPreparedTransaction;
|
|
18
|
+
export interface QuoteSummary {
|
|
19
|
+
sourceToken: string;
|
|
20
|
+
sourceAmount: string;
|
|
21
|
+
destinationToken: string;
|
|
22
|
+
destinationAmount: string;
|
|
23
|
+
destinationAmountMin: string;
|
|
24
|
+
expiresAt: string;
|
|
25
|
+
}
|
|
26
|
+
export interface QuoteResponse {
|
|
27
|
+
withdrawalDetailId: string;
|
|
28
|
+
token: string;
|
|
29
|
+
prepared: PreparedTransaction;
|
|
30
|
+
summary: QuoteSummary;
|
|
31
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parameters for `POST /withdraw/:withdrawalConfigId/prepare`.
|
|
3
|
+
*
|
|
4
|
+
* Field names mirror the backend `PreparedWithdrawalDto` exactly.
|
|
5
|
+
* `withdrawalConfigId` is sent as a URL path segment (not in the body).
|
|
6
|
+
*/
|
|
7
|
+
export interface PrepareWithdrawalParams {
|
|
8
|
+
/** Merchant withdrawal config ID — used in the URL path. */
|
|
9
|
+
withdrawalConfigId: string;
|
|
10
|
+
/** Owner address of the source wallet (lane-specific format). */
|
|
11
|
+
ownerAddress: string;
|
|
12
|
+
/** Destination address to receive the withdrawn funds. */
|
|
13
|
+
recipient: string;
|
|
14
|
+
/** Amount in atomic units (no decimals), serialised as a string. */
|
|
15
|
+
amount: string;
|
|
16
|
+
/** Destination currency ID (MongoDB ObjectId). */
|
|
17
|
+
toCurrencyId: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parameters for `PATCH /withdraw/:withdrawalDetailId/prepare`.
|
|
21
|
+
*
|
|
22
|
+
* NOTE: The backend does not yet expose this endpoint. The SDK method
|
|
23
|
+
* is kept as a forward-compatible stub and will throw at runtime until
|
|
24
|
+
* the backend ships the PATCH handler.
|
|
25
|
+
*/
|
|
26
|
+
export interface UpdateQuoteParams {
|
|
27
|
+
amount: string;
|
|
28
|
+
recipient?: string;
|
|
29
|
+
toCurrencyId?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parameters for `POST /withdraw/:withdrawalDetailId/submit`.
|
|
33
|
+
*
|
|
34
|
+
* Field names mirror the backend `SubmitWithdrawalDto`.
|
|
35
|
+
*/
|
|
36
|
+
export interface SubmitWithdrawalParams {
|
|
37
|
+
/** Per-request WithdrawalDetail ID (returned by prepare in JWT claims). */
|
|
38
|
+
withdrawalDetailId: string;
|
|
39
|
+
/** JWT token from the prepare response. */
|
|
40
|
+
token: string;
|
|
41
|
+
/**
|
|
42
|
+
* The client's signed payload, interpreted server-side by the strategy the
|
|
43
|
+
* WithdrawalConfig resolves: an EIP-712 signature for polymarket, a base64
|
|
44
|
+
* signed tx for raw. Mirrors the backend `SubmitWithdrawalDto.signedTx: string`.
|
|
45
|
+
*/
|
|
46
|
+
signedTx: string;
|
|
47
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { BroadcastAck, WithdrawalState, WithdrawBlockchainSymbol, WithdrawFeature, WithdrawPlatform } from './enums';
|
|
2
|
+
export interface WithdrawalCurrenciesExchangeRate {
|
|
3
|
+
minimalUnitRate: string;
|
|
4
|
+
decimalRate: string;
|
|
5
|
+
fromCurrencyId: string;
|
|
6
|
+
fromCurrencySymbol: string;
|
|
7
|
+
fromBlockchainSymbol: WithdrawBlockchainSymbol;
|
|
8
|
+
toCurrencyId: string;
|
|
9
|
+
toCurrencySymbol: string;
|
|
10
|
+
}
|
|
11
|
+
export interface WithdrawalConfig {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
platform: WithdrawPlatform;
|
|
15
|
+
disabled: boolean;
|
|
16
|
+
disabledBlockchainSymbols: WithdrawBlockchainSymbol[];
|
|
17
|
+
enabledFeatures: WithdrawFeature[];
|
|
18
|
+
/** ISO 8601 timestamp. */
|
|
19
|
+
createdAt: string;
|
|
20
|
+
/** ISO 8601 timestamp. */
|
|
21
|
+
updatedAt: string;
|
|
22
|
+
fromCurrencies: SlimCurrencyWithBlockchain[];
|
|
23
|
+
exchangeRates: WithdrawalCurrenciesExchangeRate[];
|
|
24
|
+
}
|
|
25
|
+
export interface BaseBlockchain {
|
|
26
|
+
id: string;
|
|
27
|
+
symbol: string;
|
|
28
|
+
displayName: string;
|
|
29
|
+
}
|
|
30
|
+
export interface SlimCurrencyWithBlockchain {
|
|
31
|
+
id: string;
|
|
32
|
+
symbol: string;
|
|
33
|
+
name: string;
|
|
34
|
+
mintAddress: string;
|
|
35
|
+
decimals: number;
|
|
36
|
+
blockchain: BaseBlockchain;
|
|
37
|
+
}
|
|
38
|
+
export interface WithdrawalCustomerSwapRoute {
|
|
39
|
+
id: string;
|
|
40
|
+
fromCurrencyId: string;
|
|
41
|
+
toCurrency: SlimCurrencyWithBlockchain;
|
|
42
|
+
available: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface RoutesResponse {
|
|
45
|
+
/** Source currencies available under the merchant's config. */
|
|
46
|
+
fromCurrencies: SlimCurrencyWithBlockchain[];
|
|
47
|
+
routes: WithdrawalCustomerSwapRoute[];
|
|
48
|
+
}
|
|
49
|
+
export interface WalletCurrencyBalance {
|
|
50
|
+
currencyId: string;
|
|
51
|
+
symbol: string;
|
|
52
|
+
mintAddress: string;
|
|
53
|
+
/** Minimal units. */
|
|
54
|
+
balance: string | null;
|
|
55
|
+
uiBalance: string | null;
|
|
56
|
+
}
|
|
57
|
+
export interface BalanceResponse {
|
|
58
|
+
balances: WalletCurrencyBalance[];
|
|
59
|
+
}
|
|
60
|
+
export interface SubmitResponse {
|
|
61
|
+
withdrawalDetailId: string;
|
|
62
|
+
/**
|
|
63
|
+
* Relayer/transaction hash; `null` only when the broadcast was rejected
|
|
64
|
+
* before producing a hash.
|
|
65
|
+
*/
|
|
66
|
+
txHash: string | null;
|
|
67
|
+
state: WithdrawalState;
|
|
68
|
+
/** `null` when no broadcast was attempted (defensive idempotent return). */
|
|
69
|
+
broadcastAck: BroadcastAck | null;
|
|
70
|
+
}
|
|
71
|
+
export interface StatusResponse {
|
|
72
|
+
withdrawalDetailId: string;
|
|
73
|
+
state: WithdrawalState;
|
|
74
|
+
txHash: string | null;
|
|
75
|
+
broadcastAck: BroadcastAck | null;
|
|
76
|
+
errorReason: string | null;
|
|
77
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var L=Object.defineProperty;var p=(e,t,E)=>t in e?L(e,t,{enumerable:!0,configurable:!0,writable:!0,value:E}):e[t]=E;var D=(e,t,E)=>p(e,typeof t!="symbol"?t+"":t,E);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var A=(e=>(e.QUOTED="QUOTED",e.SUBMITTING="SUBMITTING",e.SUBMITTED="SUBMITTED",e.BRIDGING="BRIDGING",e.COMPLETED="COMPLETED",e.FAILED="FAILED",e.FAILED_EXPIRED="FAILED_EXPIRED",e.EXPIRED="EXPIRED",e.REFUNDED_BY_PROVIDER="REFUNDED_BY_PROVIDER",e))(A||{});const U=new Set(["COMPLETED","FAILED","FAILED_EXPIRED","EXPIRED","REFUNDED_BY_PROVIDER"]);var I=(e=>(e.WITHDRAW_TX_INVALID_SIGNATURE="WITHDRAW_TX_INVALID_SIGNATURE",e.WITHDRAW_TX_BLOCKHASH_EXPIRED="WITHDRAW_TX_BLOCKHASH_EXPIRED",e.WITHDRAW_TX_NONCE_TOO_LOW="WITHDRAW_TX_NONCE_TOO_LOW",e.WITHDRAW_TX_USEROP_EXPIRED="WITHDRAW_TX_USEROP_EXPIRED",e.WITHDRAW_TX_UNDERPRICED="WITHDRAW_TX_UNDERPRICED",e.WITHDRAW_BUNDLER_REJECTED="WITHDRAW_BUNDLER_REJECTED",e.WITHDRAW_TX_BROADCAST_TIMEOUT="WITHDRAW_TX_BROADCAST_TIMEOUT",e.WITHDRAW_TX_ALREADY_KNOWN="WITHDRAW_TX_ALREADY_KNOWN",e.WITHDRAW_QUOTE_EXPIRED="WITHDRAW_QUOTE_EXPIRED",e.WITHDRAW_SANCTIONS_BLOCKED="WITHDRAW_SANCTIONS_BLOCKED",e.WITHDRAW_NO_ROUTE="WITHDRAW_NO_ROUTE",e.WITHDRAW_NOT_FOUND="WITHDRAW_NOT_FOUND",e.WITHDRAW_INSUFFICIENT_BALANCE="WITHDRAW_INSUFFICIENT_BALANCE",e.WITHDRAW_DETAILS_NOT_UPDATABLE="WITHDRAW_DETAILS_NOT_UPDATABLE",e.INVALID_WALLET_ADDRESS="INVALID_WALLET_ADDRESS",e.BALANCE_FETCH_FAILED="BALANCE_FETCH_FAILED",e.UNKNOWN="UNKNOWN",e))(I||{}),R=(e=>(e.ACKNOWLEDGED="acknowledged",e.UNACKNOWLEDGED="unacknowledged",e.REJECTED="rejected",e))(R||{}),r=(e=>(e.RAW="raw",e.USER_OP="userop",e.POLYMARKET_WALLET="polymarket_wallet",e))(r||{}),n=(e=>(e.HELIO="HELIO",e.MAGIC_EDEN="MAGIC_EDEN",e))(n||{}),N=(e=>(e.IRON="iron",e.MP_SELL="mp_sell",e))(N||{}),O=(e=>(e.SOL="SOL",e.ETH="ETH",e.POLYGON="POLYGON",e.BASE="BASE",e.BITCOIN="BITCOIN",e.ARBITRUM="ARBITRUM",e.BSC="BSC",e.TRON="TRON",e.DOGE="DOGE",e))(O||{});const c=new Set(Object.values(I));class a extends Error{constructor(E,s,T){super(T??s);D(this,"name","WithdrawalApiError");this.status=E,this.code=s,this.detail=T}}const i=e=>e&&c.has(e)?e:I.UNKNOWN,u=e=>{const t=e.split(".");if(t.length!==3)throw new Error("Invalid JWT: expected 3 parts");const E=atob(t[1].replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(E)},o=(e,t=5e3)=>{const{exp:E}=u(e);return E===void 0?!1:Date.now()>=E*1e3-t};class H{constructor(t){D(this,"baseUrl");D(this,"headers");D(this,"fetch");this.baseUrl=t.baseUrl.endsWith("/")?t.baseUrl.slice(0,-1):t.baseUrl,this.headers={"Content-Type":"application/json",...t.headers},this.fetch=t.fetch??globalThis.fetch.bind(globalThis)}async get(t,E){return this.request("GET",t,void 0,E)}async post(t,E,s){return this.request("POST",t,E,s)}async patch(t,E,s){return this.request("PATCH",t,E,s)}async request(t,E,s,T){const W=`${this.baseUrl}${E}`,_=await this.fetch(W,{method:t,headers:this.headers,body:s!==void 0?JSON.stringify(s):void 0,signal:T});if(!_.ok)throw await this.buildError(_);return await _.json()}async buildError(t){let E,s;try{const T=await t.json();E=T.message??void 0,s=T.errorCode??T.errorType??void 0}catch{E=t.statusText||void 0}return new a(t.status,i(s),E)}}class P{constructor(t){D(this,"api");this.api=new H(t)}async getWithdrawalConfig(t,E){return this.api.get(`/withdrawal-configs/${t}/public`,E)}async getRoutes(t,E){return this.api.get(`/withdraw/${t}/routes`,E)}async getBalance(t,E,s){return this.api.get(`/withdraw/${t}/balances?walletAddress=${encodeURIComponent(E)}`,s)}async prepare(t,E){const{withdrawalConfigId:s,...T}=t;return this.api.post(`/withdraw/${s}/prepare`,T,E)}async updateQuote(t,E,s){throw new Error("updateQuote is not yet supported by the backend. Create a new quote via prepare() instead.")}async submitWithdrawal(t,E){const{withdrawalDetailId:s,...T}=t;return this.api.post(`/withdraw/${s}/submit`,T,E)}async getWithdrawalDetail(t,E){return this.api.get(`/withdraw-details/${t}`,E)}}exports.BroadcastAck=R;exports.SignedTransactionKind=r;exports.TERMINAL_STATES=U;exports.WithdrawBlockchainSymbol=O;exports.WithdrawFeature=N;exports.WithdrawPlatform=n;exports.WithdrawalApiError=a;exports.WithdrawalErrorCode=I;exports.WithdrawalSDK=P;exports.WithdrawalState=A;exports.decodeJwt=u;exports.isQuoteExpired=o;exports.toWithdrawalErrorCode=i;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
var R = Object.defineProperty;
|
|
2
|
+
var N = (e, E, D) => E in e ? R(e, E, { enumerable: !0, configurable: !0, writable: !0, value: D }) : e[E] = D;
|
|
3
|
+
var T = (e, E, D) => N(e, typeof E != "symbol" ? E + "" : E, D);
|
|
4
|
+
var O = /* @__PURE__ */ ((e) => (e.QUOTED = "QUOTED", e.SUBMITTING = "SUBMITTING", e.SUBMITTED = "SUBMITTED", e.BRIDGING = "BRIDGING", e.COMPLETED = "COMPLETED", e.FAILED = "FAILED", e.FAILED_EXPIRED = "FAILED_EXPIRED", e.EXPIRED = "EXPIRED", e.REFUNDED_BY_PROVIDER = "REFUNDED_BY_PROVIDER", e))(O || {});
|
|
5
|
+
const P = /* @__PURE__ */ new Set([
|
|
6
|
+
"COMPLETED",
|
|
7
|
+
"FAILED",
|
|
8
|
+
"FAILED_EXPIRED",
|
|
9
|
+
"EXPIRED",
|
|
10
|
+
"REFUNDED_BY_PROVIDER"
|
|
11
|
+
/* REFUNDED_BY_PROVIDER */
|
|
12
|
+
]);
|
|
13
|
+
var _ = /* @__PURE__ */ ((e) => (e.WITHDRAW_TX_INVALID_SIGNATURE = "WITHDRAW_TX_INVALID_SIGNATURE", e.WITHDRAW_TX_BLOCKHASH_EXPIRED = "WITHDRAW_TX_BLOCKHASH_EXPIRED", e.WITHDRAW_TX_NONCE_TOO_LOW = "WITHDRAW_TX_NONCE_TOO_LOW", e.WITHDRAW_TX_USEROP_EXPIRED = "WITHDRAW_TX_USEROP_EXPIRED", e.WITHDRAW_TX_UNDERPRICED = "WITHDRAW_TX_UNDERPRICED", e.WITHDRAW_BUNDLER_REJECTED = "WITHDRAW_BUNDLER_REJECTED", e.WITHDRAW_TX_BROADCAST_TIMEOUT = "WITHDRAW_TX_BROADCAST_TIMEOUT", e.WITHDRAW_TX_ALREADY_KNOWN = "WITHDRAW_TX_ALREADY_KNOWN", e.WITHDRAW_QUOTE_EXPIRED = "WITHDRAW_QUOTE_EXPIRED", e.WITHDRAW_SANCTIONS_BLOCKED = "WITHDRAW_SANCTIONS_BLOCKED", e.WITHDRAW_NO_ROUTE = "WITHDRAW_NO_ROUTE", e.WITHDRAW_NOT_FOUND = "WITHDRAW_NOT_FOUND", e.WITHDRAW_INSUFFICIENT_BALANCE = "WITHDRAW_INSUFFICIENT_BALANCE", e.WITHDRAW_DETAILS_NOT_UPDATABLE = "WITHDRAW_DETAILS_NOT_UPDATABLE", e.INVALID_WALLET_ADDRESS = "INVALID_WALLET_ADDRESS", e.BALANCE_FETCH_FAILED = "BALANCE_FETCH_FAILED", e.UNKNOWN = "UNKNOWN", e))(_ || {}), n = /* @__PURE__ */ ((e) => (e.ACKNOWLEDGED = "acknowledged", e.UNACKNOWLEDGED = "unacknowledged", e.REJECTED = "rejected", e))(n || {}), r = /* @__PURE__ */ ((e) => (e.RAW = "raw", e.USER_OP = "userop", e.POLYMARKET_WALLET = "polymarket_wallet", e))(r || {}), u = /* @__PURE__ */ ((e) => (e.HELIO = "HELIO", e.MAGIC_EDEN = "MAGIC_EDEN", e))(u || {}), L = /* @__PURE__ */ ((e) => (e.IRON = "iron", e.MP_SELL = "mp_sell", e))(L || {}), p = /* @__PURE__ */ ((e) => (e.SOL = "SOL", e.ETH = "ETH", e.POLYGON = "POLYGON", e.BASE = "BASE", e.BITCOIN = "BITCOIN", e.ARBITRUM = "ARBITRUM", e.BSC = "BSC", e.TRON = "TRON", e.DOGE = "DOGE", e))(p || {});
|
|
14
|
+
const W = new Set(Object.values(_));
|
|
15
|
+
class U extends Error {
|
|
16
|
+
constructor(D, s, t) {
|
|
17
|
+
super(t ?? s);
|
|
18
|
+
T(this, "name", "WithdrawalApiError");
|
|
19
|
+
this.status = D, this.code = s, this.detail = t;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const i = (e) => e && W.has(e) ? e : _.UNKNOWN, a = (e) => {
|
|
23
|
+
const E = e.split(".");
|
|
24
|
+
if (E.length !== 3)
|
|
25
|
+
throw new Error("Invalid JWT: expected 3 parts");
|
|
26
|
+
const D = atob(E[1].replace(/-/g, "+").replace(/_/g, "/"));
|
|
27
|
+
return JSON.parse(D);
|
|
28
|
+
}, C = (e, E = 5e3) => {
|
|
29
|
+
const { exp: D } = a(e);
|
|
30
|
+
return D === void 0 ? !1 : Date.now() >= D * 1e3 - E;
|
|
31
|
+
};
|
|
32
|
+
class H {
|
|
33
|
+
constructor(E) {
|
|
34
|
+
T(this, "baseUrl");
|
|
35
|
+
T(this, "headers");
|
|
36
|
+
T(this, "fetch");
|
|
37
|
+
this.baseUrl = E.baseUrl.endsWith("/") ? E.baseUrl.slice(0, -1) : E.baseUrl, this.headers = {
|
|
38
|
+
"Content-Type": "application/json",
|
|
39
|
+
...E.headers
|
|
40
|
+
}, this.fetch = E.fetch ?? globalThis.fetch.bind(globalThis);
|
|
41
|
+
}
|
|
42
|
+
async get(E, D) {
|
|
43
|
+
return this.request("GET", E, void 0, D);
|
|
44
|
+
}
|
|
45
|
+
async post(E, D, s) {
|
|
46
|
+
return this.request("POST", E, D, s);
|
|
47
|
+
}
|
|
48
|
+
async patch(E, D, s) {
|
|
49
|
+
return this.request("PATCH", E, D, s);
|
|
50
|
+
}
|
|
51
|
+
async request(E, D, s, t) {
|
|
52
|
+
const A = `${this.baseUrl}${D}`, I = await this.fetch(A, {
|
|
53
|
+
method: E,
|
|
54
|
+
headers: this.headers,
|
|
55
|
+
body: s !== void 0 ? JSON.stringify(s) : void 0,
|
|
56
|
+
signal: t
|
|
57
|
+
});
|
|
58
|
+
if (!I.ok)
|
|
59
|
+
throw await this.buildError(I);
|
|
60
|
+
return await I.json();
|
|
61
|
+
}
|
|
62
|
+
async buildError(E) {
|
|
63
|
+
let D, s;
|
|
64
|
+
try {
|
|
65
|
+
const t = await E.json();
|
|
66
|
+
D = t.message ?? void 0, s = t.errorCode ?? t.errorType ?? void 0;
|
|
67
|
+
} catch {
|
|
68
|
+
D = E.statusText || void 0;
|
|
69
|
+
}
|
|
70
|
+
return new U(
|
|
71
|
+
E.status,
|
|
72
|
+
i(s),
|
|
73
|
+
D
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
class X {
|
|
78
|
+
constructor(E) {
|
|
79
|
+
T(this, "api");
|
|
80
|
+
this.api = new H(E);
|
|
81
|
+
}
|
|
82
|
+
async getWithdrawalConfig(E, D) {
|
|
83
|
+
return this.api.get(
|
|
84
|
+
`/withdrawal-configs/${E}/public`,
|
|
85
|
+
D
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
async getRoutes(E, D) {
|
|
89
|
+
return this.api.get(`/withdraw/${E}/routes`, D);
|
|
90
|
+
}
|
|
91
|
+
async getBalance(E, D, s) {
|
|
92
|
+
return this.api.get(
|
|
93
|
+
`/withdraw/${E}/balances?walletAddress=${encodeURIComponent(
|
|
94
|
+
D
|
|
95
|
+
)}`,
|
|
96
|
+
s
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Calls `POST /withdraw/:withdrawalConfigId/prepare`.
|
|
101
|
+
* `withdrawalConfigId` goes in the path; the remaining fields are the
|
|
102
|
+
* request body matching the backend `PreparedWithdrawalDto`.
|
|
103
|
+
*/
|
|
104
|
+
async prepare(E, D) {
|
|
105
|
+
const { withdrawalConfigId: s, ...t } = E;
|
|
106
|
+
return this.api.post(
|
|
107
|
+
`/withdraw/${s}/prepare`,
|
|
108
|
+
t,
|
|
109
|
+
D
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Update an existing quote.
|
|
114
|
+
*
|
|
115
|
+
* NOTE: The backend does not yet expose a PATCH endpoint for prepare.
|
|
116
|
+
* This stub is kept for forward compatibility. It will throw until
|
|
117
|
+
* the backend ships the handler.
|
|
118
|
+
*/
|
|
119
|
+
async updateQuote(E, D, s) {
|
|
120
|
+
throw new Error(
|
|
121
|
+
"updateQuote is not yet supported by the backend. Create a new quote via prepare() instead."
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Body matches the backend `SubmitWithdrawalDto`:
|
|
126
|
+
* `{ token, signedTx }`, where `signedTx` is the bare signed payload string.
|
|
127
|
+
*/
|
|
128
|
+
async submitWithdrawal(E, D) {
|
|
129
|
+
const { withdrawalDetailId: s, ...t } = E;
|
|
130
|
+
return this.api.post(
|
|
131
|
+
`/withdraw/${s}/submit`,
|
|
132
|
+
t,
|
|
133
|
+
D
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
async getWithdrawalDetail(E, D) {
|
|
137
|
+
return this.api.get(`/withdraw-details/${E}`, D);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export {
|
|
141
|
+
n as BroadcastAck,
|
|
142
|
+
r as SignedTransactionKind,
|
|
143
|
+
P as TERMINAL_STATES,
|
|
144
|
+
p as WithdrawBlockchainSymbol,
|
|
145
|
+
L as WithdrawFeature,
|
|
146
|
+
u as WithdrawPlatform,
|
|
147
|
+
U as WithdrawalApiError,
|
|
148
|
+
_ as WithdrawalErrorCode,
|
|
149
|
+
X as WithdrawalSDK,
|
|
150
|
+
O as WithdrawalState,
|
|
151
|
+
a as decodeJwt,
|
|
152
|
+
C as isQuoteExpired,
|
|
153
|
+
i as toWithdrawalErrorCode
|
|
154
|
+
};
|
package/package.json
CHANGED
|
@@ -1,39 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heliofi/withdraw-core",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite",
|
|
8
8
|
"build": "tsc && vite build",
|
|
9
|
-
"lint": "
|
|
10
|
-
"lint:
|
|
11
|
-
"
|
|
12
|
-
"format": "
|
|
13
|
-
"
|
|
14
|
-
"prepublishOnly": "rimraf dist && yarn build",
|
|
9
|
+
"lint": "biome check src/",
|
|
10
|
+
"lint:fix": "biome check --fix src/",
|
|
11
|
+
"format": "biome format --fix src/",
|
|
12
|
+
"format:check": "biome format src/",
|
|
13
|
+
"prepublishOnly": "rm -rf dist && pnpm run build",
|
|
15
14
|
"test": "vitest run",
|
|
16
15
|
"test:watch": "vitest",
|
|
17
|
-
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
18
|
-
"typecheck:fast": "tsc --noEmit --incremental"
|
|
16
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
19
17
|
},
|
|
20
|
-
"main": "./dist/withdraw-core.
|
|
21
|
-
"module": "./dist/withdraw-core.
|
|
18
|
+
"main": "./dist/withdraw-core.cjs",
|
|
19
|
+
"module": "./dist/withdraw-core.js",
|
|
22
20
|
"types": "./dist/index.d.ts",
|
|
21
|
+
"sideEffects": false,
|
|
23
22
|
"exports": {
|
|
24
23
|
".": {
|
|
25
24
|
"types": "./dist/index.d.ts",
|
|
26
|
-
"import": "./dist/withdraw-core.
|
|
25
|
+
"import": "./dist/withdraw-core.js",
|
|
26
|
+
"require": "./dist/withdraw-core.cjs"
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=18"
|
|
31
|
+
},
|
|
32
|
+
"packageManager": "pnpm@10",
|
|
29
33
|
"files": [
|
|
30
34
|
"dist"
|
|
31
35
|
],
|
|
32
36
|
"devDependencies": {
|
|
33
|
-
"@
|
|
34
|
-
"@typescript-eslint/parser": "6.7.4",
|
|
35
|
-
"eslint": "8.45.0",
|
|
36
|
-
"rimraf": "3.0.2",
|
|
37
|
+
"@biomejs/biome": "^2.4.16",
|
|
37
38
|
"typescript": "5.1.6",
|
|
38
39
|
"vite": "6.4.2",
|
|
39
40
|
"vite-plugin-dts": "3.7.1",
|
package/dist/withdraw-core.es.js
DELETED