@heliofi/withdraw-core 0.0.1 → 0.0.3-alpha.1780563517
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/WithdrawApiError.d.ts +9 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/sdk/ApiClient.d.ts +17 -0
- package/dist/sdk/WithdrawSDK.d.ts +25 -0
- package/dist/sdk/index.d.ts +3 -0
- package/dist/types/enums.d.ts +35 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/prepared.d.ts +30 -0
- package/dist/types/requests.d.ts +31 -0
- package/dist/types/responses.d.ts +12 -0
- package/dist/withdraw-core.cjs +1 -0
- package/dist/withdraw-core.js +135 -0
- package/package.json +16 -16
- package/dist/withdraw-core.es.js +0 -4
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WithdrawErrorCode } from '../types/enums';
|
|
2
|
+
export declare class WithdrawApiError extends Error {
|
|
3
|
+
readonly status: number;
|
|
4
|
+
readonly code: WithdrawErrorCode;
|
|
5
|
+
readonly detail?: string | undefined;
|
|
6
|
+
readonly name = "WithdrawApiError";
|
|
7
|
+
constructor(status: number, code: WithdrawErrorCode, detail?: string | undefined);
|
|
8
|
+
}
|
|
9
|
+
export declare function toWithdrawErrorCode(raw: string | undefined): WithdrawErrorCode;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { toWithdrawErrorCode, WithdrawApiError } from './WithdrawApiError';
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { toWithdrawErrorCode, WithdrawApiError } from './errors';
|
|
2
|
+
export type { ApiClientConfig, WithdrawJwtPayload } from './sdk';
|
|
3
|
+
export { WithdrawSDK } from './sdk';
|
|
4
|
+
export type { BalanceResponse, CreateQuoteParams, PolymarketWalletPreparedTransaction, PreparedTransaction, QuoteResponse, QuoteSummary, RawPreparedTransaction, RoutesResponse, SourceWallet, StatusResponse, SubmitResponse, SubmitWithdrawParams, UpdateQuoteParams, UserOpPreparedTransaction, WithdrawConfig, WithdrawDetails, } from './types';
|
|
5
|
+
export { SignedTransactionKind, SourceWalletKind, TERMINAL_STATES, WithdrawErrorCode, WithdrawState, } from './types';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface ApiClientConfig {
|
|
2
|
+
baseUrl: string;
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
headers?: Record<string, string>;
|
|
5
|
+
fetch?: typeof globalThis.fetch;
|
|
6
|
+
}
|
|
7
|
+
export declare class ApiClient {
|
|
8
|
+
private readonly baseUrl;
|
|
9
|
+
private readonly defaultHeaders;
|
|
10
|
+
private readonly fetch;
|
|
11
|
+
constructor(config: ApiClientConfig);
|
|
12
|
+
get<T>(path: string, signal?: AbortSignal): Promise<T>;
|
|
13
|
+
post<T>(path: string, body: unknown, signal?: AbortSignal): Promise<T>;
|
|
14
|
+
patch<T>(path: string, body: unknown, signal?: AbortSignal): Promise<T>;
|
|
15
|
+
private request;
|
|
16
|
+
private buildError;
|
|
17
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { QuoteResponse } from '../types/prepared';
|
|
2
|
+
import type { CreateQuoteParams, SubmitWithdrawParams, UpdateQuoteParams } from '../types/requests';
|
|
3
|
+
import type { BalanceResponse, RoutesResponse, StatusResponse, SubmitResponse, WithdrawConfig, WithdrawDetails } from '../types/responses';
|
|
4
|
+
import { type ApiClientConfig } from './ApiClient';
|
|
5
|
+
export interface WithdrawJwtPayload {
|
|
6
|
+
exp?: number;
|
|
7
|
+
iat?: number;
|
|
8
|
+
withdrawDetailsId?: string;
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
}
|
|
11
|
+
export declare class WithdrawSDK {
|
|
12
|
+
private readonly api;
|
|
13
|
+
constructor(config: ApiClientConfig);
|
|
14
|
+
getWithdraw(withdrawId: string, signal?: AbortSignal): Promise<WithdrawConfig>;
|
|
15
|
+
getRoutes(withdrawId: string, signal?: AbortSignal): Promise<RoutesResponse>;
|
|
16
|
+
getBalance(withdrawId: string, fromWallet: string, signal?: AbortSignal): Promise<BalanceResponse>;
|
|
17
|
+
createQuote(params: CreateQuoteParams, signal?: AbortSignal): Promise<QuoteResponse>;
|
|
18
|
+
updateQuote(withdrawDetailsId: string, params: UpdateQuoteParams, signal?: AbortSignal): Promise<QuoteResponse>;
|
|
19
|
+
submitWithdraw(params: SubmitWithdrawParams, signal?: AbortSignal): Promise<SubmitResponse>;
|
|
20
|
+
getStatus(withdrawDetailsId: string, signal?: AbortSignal): Promise<StatusResponse>;
|
|
21
|
+
getWithdrawal(withdrawDetailsId: string, signal?: AbortSignal): Promise<WithdrawDetails>;
|
|
22
|
+
static decodeJwt(jwt: string): WithdrawJwtPayload;
|
|
23
|
+
static isQuoteExpired(jwt: string, bufferMs?: number): boolean;
|
|
24
|
+
private buildSubmitBody;
|
|
25
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare enum WithdrawState {
|
|
2
|
+
QUOTED = "QUOTED",
|
|
3
|
+
SUBMITTED = "SUBMITTED",
|
|
4
|
+
BRIDGING = "BRIDGING",
|
|
5
|
+
COMPLETED = "COMPLETED",
|
|
6
|
+
FAILED = "FAILED",
|
|
7
|
+
FAILED_EXPIRED = "FAILED_EXPIRED",
|
|
8
|
+
EXPIRED = "EXPIRED",
|
|
9
|
+
REFUNDED_BY_PROVIDER = "REFUNDED_BY_PROVIDER"
|
|
10
|
+
}
|
|
11
|
+
export declare const TERMINAL_STATES: ReadonlySet<WithdrawState>;
|
|
12
|
+
export declare enum WithdrawErrorCode {
|
|
13
|
+
WITHDRAW_TX_INVALID_SIGNATURE = "WITHDRAW_TX_INVALID_SIGNATURE",
|
|
14
|
+
WITHDRAW_TX_BLOCKHASH_EXPIRED = "WITHDRAW_TX_BLOCKHASH_EXPIRED",
|
|
15
|
+
WITHDRAW_TX_NONCE_TOO_LOW = "WITHDRAW_TX_NONCE_TOO_LOW",
|
|
16
|
+
WITHDRAW_TX_USEROP_EXPIRED = "WITHDRAW_TX_USEROP_EXPIRED",
|
|
17
|
+
WITHDRAW_TX_UNDERPRICED = "WITHDRAW_TX_UNDERPRICED",
|
|
18
|
+
WITHDRAW_BUNDLER_REJECTED = "WITHDRAW_BUNDLER_REJECTED",
|
|
19
|
+
WITHDRAW_TX_BROADCAST_TIMEOUT = "WITHDRAW_TX_BROADCAST_TIMEOUT",
|
|
20
|
+
WITHDRAW_TX_ALREADY_KNOWN = "WITHDRAW_TX_ALREADY_KNOWN",
|
|
21
|
+
WITHDRAW_QUOTE_EXPIRED = "WITHDRAW_QUOTE_EXPIRED",
|
|
22
|
+
WITHDRAW_SANCTIONS_BLOCKED = "WITHDRAW_SANCTIONS_BLOCKED",
|
|
23
|
+
WITHDRAW_NO_ROUTE = "WITHDRAW_NO_ROUTE",
|
|
24
|
+
WITHDRAW_NOT_FOUND = "WITHDRAW_NOT_FOUND",
|
|
25
|
+
WITHDRAW_INSUFFICIENT_BALANCE = "WITHDRAW_INSUFFICIENT_BALANCE",
|
|
26
|
+
WITHDRAW_DETAILS_NOT_UPDATABLE = "WITHDRAW_DETAILS_NOT_UPDATABLE",
|
|
27
|
+
INVALID_WALLET_ADDRESS = "INVALID_WALLET_ADDRESS",
|
|
28
|
+
BALANCE_FETCH_FAILED = "BALANCE_FETCH_FAILED",
|
|
29
|
+
UNKNOWN = "UNKNOWN"
|
|
30
|
+
}
|
|
31
|
+
export declare enum SignedTransactionKind {
|
|
32
|
+
RAW = "raw",
|
|
33
|
+
USER_OP = "userop",
|
|
34
|
+
POLYMARKET_WALLET = "polymarket_wallet"
|
|
35
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { SignedTransactionKind, TERMINAL_STATES, WithdrawErrorCode, WithdrawState, } from './enums';
|
|
2
|
+
export type { PolymarketWalletPreparedTransaction, PreparedTransaction, QuoteResponse, QuoteSummary, RawPreparedTransaction, UserOpPreparedTransaction, } from './prepared';
|
|
3
|
+
export type { CreateQuoteParams, SourceWallet, SubmitWithdrawParams, UpdateQuoteParams, } from './requests';
|
|
4
|
+
export { SourceWalletKind } from './requests';
|
|
5
|
+
export type { BalanceResponse, RoutesResponse, StatusResponse, SubmitResponse, WithdrawConfig, WithdrawDetails, } from './responses';
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
token: string;
|
|
28
|
+
prepared: PreparedTransaction;
|
|
29
|
+
summary: QuoteSummary;
|
|
30
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { SignedTransactionKind } from './enums';
|
|
2
|
+
export interface CreateQuoteParams {
|
|
3
|
+
withdrawId: string;
|
|
4
|
+
sourceChain: string;
|
|
5
|
+
sourceToken: string;
|
|
6
|
+
sourceAmount: string;
|
|
7
|
+
destinationChain: string;
|
|
8
|
+
destinationToken: string;
|
|
9
|
+
destinationAddress: string;
|
|
10
|
+
sourceWallet: SourceWallet;
|
|
11
|
+
}
|
|
12
|
+
export interface SourceWallet {
|
|
13
|
+
kind: SourceWalletKind;
|
|
14
|
+
address: string;
|
|
15
|
+
signerAddress?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare enum SourceWalletKind {
|
|
18
|
+
EOA = "eoa",
|
|
19
|
+
SMART_WALLET = "smart_wallet",
|
|
20
|
+
POLYMARKET_WALLET = "polymarket_wallet"
|
|
21
|
+
}
|
|
22
|
+
export interface UpdateQuoteParams {
|
|
23
|
+
sourceAmount: string;
|
|
24
|
+
destinationAddress?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface SubmitWithdrawParams {
|
|
27
|
+
withdrawId: string;
|
|
28
|
+
jwt: string;
|
|
29
|
+
kind: SignedTransactionKind;
|
|
30
|
+
signedResult: string;
|
|
31
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { WithdrawState } from './enums';
|
|
2
|
+
export type WithdrawConfig = unknown;
|
|
3
|
+
export type RoutesResponse = unknown;
|
|
4
|
+
export type BalanceResponse = unknown;
|
|
5
|
+
export type SubmitResponse = unknown;
|
|
6
|
+
export interface StatusResponse {
|
|
7
|
+
state: WithdrawState;
|
|
8
|
+
txHash?: string;
|
|
9
|
+
errorReason?: string;
|
|
10
|
+
updatedAt: string;
|
|
11
|
+
}
|
|
12
|
+
export type WithdrawDetails = unknown;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var W=Object.defineProperty;var N=(e,t,s)=>t in e?W(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var _=(e,t,s)=>N(e,typeof t!="symbol"?t+"":t,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var R=(e=>(e.QUOTED="QUOTED",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))(R||{});const O=new Set(["COMPLETED","FAILED","FAILED_EXPIRED","EXPIRED","REFUNDED_BY_PROVIDER"]);var D=(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))(D||{}),I=(e=>(e.RAW="raw",e.USER_OP="userop",e.POLYMARKET_WALLET="polymarket_wallet",e))(I||{});const c=new Set(Object.values(D));class i extends Error{constructor(s,T,E){super(E??T);_(this,"name","WithdrawApiError");this.status=s,this.code=T,this.detail=E}}function r(e){return e&&c.has(e)?e:D.UNKNOWN}class L{constructor(t){_(this,"baseUrl");_(this,"defaultHeaders");_(this,"fetch");this.baseUrl=t.baseUrl.replace(/\/+$/,""),this.defaultHeaders={"Content-Type":"application/json",...t.headers},t.apiKey&&(this.defaultHeaders["x-api-key"]=t.apiKey),this.fetch=t.fetch??globalThis.fetch.bind(globalThis)}async get(t,s){return this.request("GET",t,void 0,s)}async post(t,s,T){return this.request("POST",t,s,T)}async patch(t,s,T){return this.request("PATCH",t,s,T)}async request(t,s,T,E){const u=`${this.baseUrl}${s}`,A=await this.fetch(u,{method:t,headers:this.defaultHeaders,body:T!==void 0?JSON.stringify(T):void 0,signal:E});if(!A.ok)throw await this.buildError(A);return await A.json()}async buildError(t){let s,T;try{const E=await t.json();s=E.message??void 0,T=E.errorCode??E.errorType??void 0}catch{s=t.statusText||void 0}return new i(t.status,r(T),s)}}class a{constructor(t){_(this,"api");this.api=new L(t)}async getWithdraw(t,s){return this.api.get(`/withdraw/${t}`,s)}async getRoutes(t,s){return this.api.get(`/withdraw/${t}/routes`,s)}async getBalance(t,s,T){return this.api.get(`/withdraw/${t}/balance/${s}`,T)}async createQuote(t,s){return this.api.post("/withdraw/quote",t,s)}async updateQuote(t,s,T){return this.api.patch(`/withdraw/quote/${t}`,s,T)}async submitWithdraw(t,s){const T=this.buildSubmitBody(t);return this.api.post("/withdraw/submit",T,s)}async getStatus(t,s){return this.api.get(`/withdraw/${t}/status`,s)}async getWithdrawal(t,s){return this.api.get(`/withdraw/${t}`,s)}static decodeJwt(t){const s=t.split(".");if(s.length!==3)throw new Error("Invalid JWT: expected 3 parts");const T=atob(s[1].replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(T)}static isQuoteExpired(t,s=5e3){const{exp:T}=a.decodeJwt(t);return T===void 0?!1:Date.now()>=T*1e3-s}buildSubmitBody(t){const s={withdrawId:t.withdrawId,jwt:t.jwt};return t.kind===I.POLYMARKET_WALLET?{...s,signature:t.signedResult}:{...s,signedTx:t.signedResult}}}var n=(e=>(e.EOA="eoa",e.SMART_WALLET="smart_wallet",e.POLYMARKET_WALLET="polymarket_wallet",e))(n||{});exports.SignedTransactionKind=I;exports.SourceWalletKind=n;exports.TERMINAL_STATES=O;exports.WithdrawApiError=i;exports.WithdrawErrorCode=D;exports.WithdrawSDK=a;exports.WithdrawState=R;exports.toWithdrawErrorCode=r;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
var i = Object.defineProperty;
|
|
2
|
+
var n = (e, t, s) => t in e ? i(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
|
|
3
|
+
var _ = (e, t, s) => n(e, typeof t != "symbol" ? t + "" : t, s);
|
|
4
|
+
var u = /* @__PURE__ */ ((e) => (e.QUOTED = "QUOTED", 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))(u || {});
|
|
5
|
+
const l = /* @__PURE__ */ new Set([
|
|
6
|
+
"COMPLETED",
|
|
7
|
+
"FAILED",
|
|
8
|
+
"FAILED_EXPIRED",
|
|
9
|
+
"EXPIRED",
|
|
10
|
+
"REFUNDED_BY_PROVIDER"
|
|
11
|
+
/* REFUNDED_BY_PROVIDER */
|
|
12
|
+
]);
|
|
13
|
+
var A = /* @__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))(A || {}), I = /* @__PURE__ */ ((e) => (e.RAW = "raw", e.USER_OP = "userop", e.POLYMARKET_WALLET = "polymarket_wallet", e))(I || {});
|
|
14
|
+
const N = new Set(Object.values(A));
|
|
15
|
+
class r extends Error {
|
|
16
|
+
constructor(s, T, E) {
|
|
17
|
+
super(E ?? T);
|
|
18
|
+
_(this, "name", "WithdrawApiError");
|
|
19
|
+
this.status = s, this.code = T, this.detail = E;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function O(e) {
|
|
23
|
+
return e && N.has(e) ? e : A.UNKNOWN;
|
|
24
|
+
}
|
|
25
|
+
class W {
|
|
26
|
+
constructor(t) {
|
|
27
|
+
_(this, "baseUrl");
|
|
28
|
+
_(this, "defaultHeaders");
|
|
29
|
+
_(this, "fetch");
|
|
30
|
+
this.baseUrl = t.baseUrl.replace(/\/+$/, ""), this.defaultHeaders = {
|
|
31
|
+
"Content-Type": "application/json",
|
|
32
|
+
...t.headers
|
|
33
|
+
}, t.apiKey && (this.defaultHeaders["x-api-key"] = t.apiKey), this.fetch = t.fetch ?? globalThis.fetch.bind(globalThis);
|
|
34
|
+
}
|
|
35
|
+
async get(t, s) {
|
|
36
|
+
return this.request("GET", t, void 0, s);
|
|
37
|
+
}
|
|
38
|
+
async post(t, s, T) {
|
|
39
|
+
return this.request("POST", t, s, T);
|
|
40
|
+
}
|
|
41
|
+
async patch(t, s, T) {
|
|
42
|
+
return this.request("PATCH", t, s, T);
|
|
43
|
+
}
|
|
44
|
+
async request(t, s, T, E) {
|
|
45
|
+
const a = `${this.baseUrl}${s}`, D = await this.fetch(a, {
|
|
46
|
+
method: t,
|
|
47
|
+
headers: this.defaultHeaders,
|
|
48
|
+
body: T !== void 0 ? JSON.stringify(T) : void 0,
|
|
49
|
+
signal: E
|
|
50
|
+
});
|
|
51
|
+
if (!D.ok)
|
|
52
|
+
throw await this.buildError(D);
|
|
53
|
+
return await D.json();
|
|
54
|
+
}
|
|
55
|
+
async buildError(t) {
|
|
56
|
+
let s, T;
|
|
57
|
+
try {
|
|
58
|
+
const E = await t.json();
|
|
59
|
+
s = E.message ?? void 0, T = E.errorCode ?? E.errorType ?? void 0;
|
|
60
|
+
} catch {
|
|
61
|
+
s = t.statusText || void 0;
|
|
62
|
+
}
|
|
63
|
+
return new r(
|
|
64
|
+
t.status,
|
|
65
|
+
O(T),
|
|
66
|
+
s
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
class R {
|
|
71
|
+
constructor(t) {
|
|
72
|
+
_(this, "api");
|
|
73
|
+
this.api = new W(t);
|
|
74
|
+
}
|
|
75
|
+
async getWithdraw(t, s) {
|
|
76
|
+
return this.api.get(`/withdraw/${t}`, s);
|
|
77
|
+
}
|
|
78
|
+
async getRoutes(t, s) {
|
|
79
|
+
return this.api.get(`/withdraw/${t}/routes`, s);
|
|
80
|
+
}
|
|
81
|
+
async getBalance(t, s, T) {
|
|
82
|
+
return this.api.get(
|
|
83
|
+
`/withdraw/${t}/balance/${s}`,
|
|
84
|
+
T
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
async createQuote(t, s) {
|
|
88
|
+
return this.api.post("/withdraw/quote", t, s);
|
|
89
|
+
}
|
|
90
|
+
async updateQuote(t, s, T) {
|
|
91
|
+
return this.api.patch(
|
|
92
|
+
`/withdraw/quote/${t}`,
|
|
93
|
+
s,
|
|
94
|
+
T
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
// TODO: submit body shape TBD — confirm field names with BE once submit controller lands
|
|
98
|
+
async submitWithdraw(t, s) {
|
|
99
|
+
const T = this.buildSubmitBody(t);
|
|
100
|
+
return this.api.post("/withdraw/submit", T, s);
|
|
101
|
+
}
|
|
102
|
+
async getStatus(t, s) {
|
|
103
|
+
return this.api.get(`/withdraw/${t}/status`, s);
|
|
104
|
+
}
|
|
105
|
+
async getWithdrawal(t, s) {
|
|
106
|
+
return this.api.get(`/withdraw/${t}`, s);
|
|
107
|
+
}
|
|
108
|
+
static decodeJwt(t) {
|
|
109
|
+
const s = t.split(".");
|
|
110
|
+
if (s.length !== 3)
|
|
111
|
+
throw new Error("Invalid JWT: expected 3 parts");
|
|
112
|
+
const T = atob(s[1].replace(/-/g, "+").replace(/_/g, "/"));
|
|
113
|
+
return JSON.parse(T);
|
|
114
|
+
}
|
|
115
|
+
static isQuoteExpired(t, s = 5e3) {
|
|
116
|
+
const { exp: T } = R.decodeJwt(t);
|
|
117
|
+
return T === void 0 ? !1 : Date.now() >= T * 1e3 - s;
|
|
118
|
+
}
|
|
119
|
+
// TODO: submit body shape TBD — kind discriminator and field naming may change
|
|
120
|
+
buildSubmitBody(t) {
|
|
121
|
+
const s = { withdrawId: t.withdrawId, jwt: t.jwt };
|
|
122
|
+
return t.kind === I.POLYMARKET_WALLET ? { ...s, signature: t.signedResult } : { ...s, signedTx: t.signedResult };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
var L = /* @__PURE__ */ ((e) => (e.EOA = "eoa", e.SMART_WALLET = "smart_wallet", e.POLYMARKET_WALLET = "polymarket_wallet", e))(L || {});
|
|
126
|
+
export {
|
|
127
|
+
I as SignedTransactionKind,
|
|
128
|
+
L as SourceWalletKind,
|
|
129
|
+
l as TERMINAL_STATES,
|
|
130
|
+
r as WithdrawApiError,
|
|
131
|
+
A as WithdrawErrorCode,
|
|
132
|
+
R as WithdrawSDK,
|
|
133
|
+
u as WithdrawState,
|
|
134
|
+
O as toWithdrawErrorCode
|
|
135
|
+
};
|
package/package.json
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heliofi/withdraw-core",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3-alpha.1780563517",
|
|
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 && npm 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
|
+
},
|
|
29
32
|
"files": [
|
|
30
33
|
"dist"
|
|
31
34
|
],
|
|
32
35
|
"devDependencies": {
|
|
33
|
-
"@
|
|
34
|
-
"@typescript-eslint/parser": "6.7.4",
|
|
35
|
-
"eslint": "8.45.0",
|
|
36
|
-
"rimraf": "3.0.2",
|
|
36
|
+
"@biomejs/biome": "^2.4.16",
|
|
37
37
|
"typescript": "5.1.6",
|
|
38
38
|
"vite": "6.4.2",
|
|
39
39
|
"vite-plugin-dts": "3.7.1",
|
package/dist/withdraw-core.es.js
DELETED