@ab-org/predicate-market-sdk 2.0.0 → 2.1.1-beta.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 +42 -7
- package/dist/account-F5Z2SMJE.js +213 -0
- package/dist/api-DyQAYQ0i.d.ts +156 -0
- package/dist/auth.d.ts +8 -0
- package/dist/auth.js +1 -0
- package/dist/autoReconnect-IFPVI2XU.js +33 -0
- package/dist/chunk-6YQEHB6P.js +14 -0
- package/dist/chunk-F2UPP3YC.js +88 -0
- package/dist/chunk-IUBVUCWJ.js +419 -0
- package/dist/chunk-JFRRJXOJ.js +149 -0
- package/dist/chunk-LOJTP47I.js +6 -0
- package/dist/chunk-SHLNBZBY.js +72 -0
- package/dist/chunk-SZYGIQT3.js +3192 -0
- package/dist/chunk-TPMI3XWV.js +114 -0
- package/dist/chunk-UAXKA6QC.js +17 -0
- package/dist/chunk-WHTI52FI.js +10 -0
- package/dist/chunk-XB2DFS2W.js +50 -0
- package/dist/chunk-YX56ZGDB.js +274 -0
- package/dist/core.d.ts +63 -0
- package/dist/core.js +6 -0
- package/dist/dist-Q2PDXT2F.js +81 -0
- package/dist/index.d.ts +12 -706
- package/dist/index.js +12 -43009
- package/dist/merchant.d.ts +206 -0
- package/dist/merchant.js +4 -0
- package/dist/react.d.ts +197 -0
- package/dist/react.js +7 -0
- package/dist/signInTypes-DESvmgWG.d.ts +41 -0
- package/dist/types-BFidNjd9.d.ts +64 -0
- package/package.json +23 -11
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { b as ModalController, T as TokenInfo, C as ChainInfo, c as QuoteResult, D as DepositAddressResult, a as CustodyAdapter, M as MarketDataProvider } from './types-BFidNjd9.js';
|
|
2
|
+
import { C as ChainData, T as TokenData } from './api-DyQAYQ0i.js';
|
|
3
|
+
export { A as ApiResponse, a as ChainsResponseData, b as CreateOrderRequest, c as CreateOrderResponseData, D as DepositOrderResponseData, d as DepositOrderStatus, M as MerchantApiConfig, N as NativeSwapPayload, P as PaymentPairData, e as PaymentSessionResponseData, f as PaymentSessionStatus, g as PlatformRegisterRequest, h as PlatformRegisterResponseData, Q as QuoteDirection, i as QuoteResponseData, W as WithdrawOrderResponseData, j as WithdrawOrderStatus, k as configureMerchantApi, l as createOrder, m as getChains, n as getDepositOrder, o as getMerchantApiClient, p as getWithdrawOrder, q as quote, r as registerPlatform } from './api-DyQAYQ0i.js';
|
|
4
|
+
import { SupportedToken, SupportedChain, SessionCapabilityPolicy, WalletCapability } from '@ab-org/sdk-core';
|
|
5
|
+
import 'axios';
|
|
6
|
+
|
|
7
|
+
interface DepositModalConfig {
|
|
8
|
+
preferredToken?: string;
|
|
9
|
+
preferredChain?: string;
|
|
10
|
+
onStatusChange?: (status: DepositStatus) => void;
|
|
11
|
+
}
|
|
12
|
+
type DepositStatus = {
|
|
13
|
+
phase: "idle";
|
|
14
|
+
} | {
|
|
15
|
+
phase: "address-issued";
|
|
16
|
+
depositId: string;
|
|
17
|
+
address: string;
|
|
18
|
+
} | {
|
|
19
|
+
phase: "confirming";
|
|
20
|
+
depositId: string;
|
|
21
|
+
} | {
|
|
22
|
+
phase: "settled";
|
|
23
|
+
depositId: string;
|
|
24
|
+
txHash?: string;
|
|
25
|
+
} | {
|
|
26
|
+
phase: "failed";
|
|
27
|
+
reason: string;
|
|
28
|
+
};
|
|
29
|
+
interface DepositController extends ModalController<DepositModalConfig> {
|
|
30
|
+
readonly status: DepositStatus;
|
|
31
|
+
fetchTokens(): Promise<TokenInfo[]>;
|
|
32
|
+
fetchChains(token: string): Promise<ChainInfo[]>;
|
|
33
|
+
fetchQuote(token: string, chain: string, amount: string): Promise<QuoteResult>;
|
|
34
|
+
fetchDepositAddress(token: string, chain: string): Promise<DepositAddressResult>;
|
|
35
|
+
}
|
|
36
|
+
declare const createDepositController: (custody: CustodyAdapter, marketData: MarketDataProvider) => DepositController;
|
|
37
|
+
|
|
38
|
+
interface WithdrawModalConfig {
|
|
39
|
+
defaultAmount?: string;
|
|
40
|
+
defaultToken?: string;
|
|
41
|
+
defaultChain?: string;
|
|
42
|
+
targetAddress?: string;
|
|
43
|
+
onStatusChange?: (status: WithdrawStatus) => void;
|
|
44
|
+
}
|
|
45
|
+
type WithdrawStatus = {
|
|
46
|
+
phase: "idle";
|
|
47
|
+
} | {
|
|
48
|
+
phase: "requested";
|
|
49
|
+
requestId: string;
|
|
50
|
+
} | {
|
|
51
|
+
phase: "processing";
|
|
52
|
+
requestId: string;
|
|
53
|
+
} | {
|
|
54
|
+
phase: "settled";
|
|
55
|
+
requestId: string;
|
|
56
|
+
txHash?: string;
|
|
57
|
+
} | {
|
|
58
|
+
phase: "failed";
|
|
59
|
+
reason: string;
|
|
60
|
+
};
|
|
61
|
+
interface WithdrawController extends ModalController<WithdrawModalConfig> {
|
|
62
|
+
readonly status: WithdrawStatus;
|
|
63
|
+
fetchTokens(): Promise<TokenInfo[]>;
|
|
64
|
+
fetchChains(token: string): Promise<ChainInfo[]>;
|
|
65
|
+
fetchQuote(token: string, chain: string, amount: string): Promise<QuoteResult>;
|
|
66
|
+
}
|
|
67
|
+
declare const createWithdrawController: (custody: CustodyAdapter, marketData: MarketDataProvider) => WithdrawController;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Default `MarketDataProvider` backed by the merchant chains API.
|
|
71
|
+
* - getSupportedTokens / getSupportedChains: from GET `{merchantBase}/chains`
|
|
72
|
+
* - getQuote: local estimate until a dedicated quote API exists
|
|
73
|
+
* - getDepositAddress: 当前 session 钱包地址 + 与 `token`/`chain` 匹配的 `GET /chains` 中 `minimum_deposit`(按 decimals 格式化)
|
|
74
|
+
*/
|
|
75
|
+
declare function createMarketDataProvider(): MarketDataProvider;
|
|
76
|
+
|
|
77
|
+
interface Erc20BalanceResult {
|
|
78
|
+
raw: bigint;
|
|
79
|
+
formatted: string;
|
|
80
|
+
symbol: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Query any ERC-20 token balance via a raw JSON-RPC `eth_call`.
|
|
84
|
+
* No external library dependency – uses the global `fetch`.
|
|
85
|
+
*/
|
|
86
|
+
declare function fetchErc20Balance(rpcUrl: string, tokenAddress: string, walletAddress: string): Promise<bigint>;
|
|
87
|
+
interface FundingTokenBalanceOptions {
|
|
88
|
+
rpcUrl?: string;
|
|
89
|
+
tokenAddress?: string;
|
|
90
|
+
decimals?: number;
|
|
91
|
+
/**
|
|
92
|
+
* Funding chain id (e.g. `"3131"` Tenderly BSC, `"56"` mainnet).
|
|
93
|
+
* When omitted, defaults to `3131` via {@link getChainInfo}.
|
|
94
|
+
*/
|
|
95
|
+
chainId?: string | number | null;
|
|
96
|
+
/** Label for {@link Erc20BalanceResult.symbol} (default `"Funding"`). */
|
|
97
|
+
displaySymbol?: string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Fetches the configured funding ERC-20 balance on the selected funding chain.
|
|
101
|
+
* Defaults: chain `3131`, RPC from {@link getChainInfo}, token from {@link getFundingTokenAddress} / env.
|
|
102
|
+
*/
|
|
103
|
+
declare function fetchFundingTokenBalance(walletAddress: string, options?: FundingTokenBalanceOptions): Promise<Erc20BalanceResult>;
|
|
104
|
+
|
|
105
|
+
interface WithdrawTxRequest {
|
|
106
|
+
/** 链上交易实际发送到的地址 */
|
|
107
|
+
toAddress: string;
|
|
108
|
+
/** Human-readable amount, e.g. "100.5" */
|
|
109
|
+
amount: string;
|
|
110
|
+
/** 实际发送的代币 symbol */
|
|
111
|
+
token: string;
|
|
112
|
+
/** 实际发送的代币合约地址 */
|
|
113
|
+
tokenAddress: string;
|
|
114
|
+
/** 实际发送代币的 decimals */
|
|
115
|
+
tokenDecimals: number;
|
|
116
|
+
/** 实际发起交易的链 id */
|
|
117
|
+
chain: string;
|
|
118
|
+
}
|
|
119
|
+
interface WithdrawRequest {
|
|
120
|
+
/** 用户收款地址(目标链) */
|
|
121
|
+
toAddress: string;
|
|
122
|
+
/** Human-readable amount, e.g. "100.5" */
|
|
123
|
+
amount: string;
|
|
124
|
+
/** 目标链代币 symbol,如 "USDT" */
|
|
125
|
+
token: string;
|
|
126
|
+
/** 目标链代币地址 */
|
|
127
|
+
tokenAddress: string;
|
|
128
|
+
/** 目标链 chain_id */
|
|
129
|
+
chain: string;
|
|
130
|
+
}
|
|
131
|
+
interface WithdrawResult {
|
|
132
|
+
/** 调用方需要执行的链上转账参数 */
|
|
133
|
+
txRequest: WithdrawTxRequest;
|
|
134
|
+
/** 提现订单 ID,用于轮询 getWithdrawOrder(orderId) */
|
|
135
|
+
orderId?: string;
|
|
136
|
+
/** 广播 funding tx 的链 id,用于构建 explorer 链接 */
|
|
137
|
+
fundingChainId?: string;
|
|
138
|
+
/** direct: 直接提币;cross_chain: 创建订单后向 one-time address 打款 */
|
|
139
|
+
withdrawMode: "direct" | "cross_chain";
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* A function that executes a withdraw operation.
|
|
143
|
+
* Callers can supply their own implementation to override the default behaviour.
|
|
144
|
+
*/
|
|
145
|
+
type WithdrawExecutor = (request: WithdrawRequest) => Promise<WithdrawResult>;
|
|
146
|
+
/**
|
|
147
|
+
* Convert a human-readable decimal string to the smallest unit (wei-equivalent).
|
|
148
|
+
*
|
|
149
|
+
* Examples with decimals=18:
|
|
150
|
+
* "1" → 1000000000000000000n
|
|
151
|
+
* "0.5" → 500000000000000000n
|
|
152
|
+
* "100.1" → 100100000000000000000n
|
|
153
|
+
*/
|
|
154
|
+
declare function parseUnits(value: string, decimals: number): bigint;
|
|
155
|
+
interface FundingWithdrawExecutorOptions {
|
|
156
|
+
/** 源链 funding ERC-20 合约地址;默认 {@link getFundingTokenAddress} / env */
|
|
157
|
+
tokenAddress?: string;
|
|
158
|
+
decimals?: number;
|
|
159
|
+
/**
|
|
160
|
+
* Funding EVM chain id(如 `3131` Tenderly、`56` 主网)。未传时默认 `3131`。
|
|
161
|
+
*/
|
|
162
|
+
chainId?: number | string;
|
|
163
|
+
/** 覆盖 {@link getChainInfo} 提供的 JSON-RPC URL */
|
|
164
|
+
rpcUrl?: string;
|
|
165
|
+
/** 系统配置的单笔限额(wei 字符串),若提供则校验 request.amount 不得超过此值 */
|
|
166
|
+
maxAmountWei?: string;
|
|
167
|
+
/**
|
|
168
|
+
* 与商户订单接口约定的 funding 侧 token symbol(默认 `USDT`,按后端协议)。
|
|
169
|
+
*/
|
|
170
|
+
fundingLegTokenSymbol?: string;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Factory that returns a `WithdrawExecutor` implementing the flow in withdraw.md:
|
|
174
|
+
* 1) Create NATIVE_SWAP order → get one-time wallet address (OTW);
|
|
175
|
+
* 2) For cross-chain withdraw, return a `txRequest` that sends the funding token to the OTW;
|
|
176
|
+
* 3) For direct withdraw, return a `txRequest` that sends the token directly to the user-entered address;
|
|
177
|
+
* 4) The caller must implement wallet signing / broadcasting and, when `orderId` exists, poll getWithdrawOrder(orderId).
|
|
178
|
+
*/
|
|
179
|
+
declare function createFundingWithdrawExecutor(options?: FundingWithdrawExecutorOptions): WithdrawExecutor;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* funding 链(与 {@link DEFAULT_FUNDING_CHAIN_ID} 一致)上,且 `tokenAddress` 在 Merchant `GET /chains`
|
|
183
|
+
* 中对应条目的 `is_usd_stable === true` 时,由业务层自行完成提现并构造 `withdrawDirectResult`;
|
|
184
|
+
* 其余情况走默认 funding 提现执行器与订单轮询。
|
|
185
|
+
*/
|
|
186
|
+
declare function isUsdtWithdrawDirect(chainId: string, tokenAddress: string, chains: ChainData[]): boolean;
|
|
187
|
+
/**
|
|
188
|
+
* 从 `getChains()` 返回的 `chains` 中,按当前选择的链 id + token symbol 或合约地址解析 `TokenData`。
|
|
189
|
+
*/
|
|
190
|
+
declare function findTokenDataFromChains(chains: ChainData[], chainId: string, opts: {
|
|
191
|
+
symbol: string;
|
|
192
|
+
tokenAddress?: string;
|
|
193
|
+
}): TokenData | undefined;
|
|
194
|
+
|
|
195
|
+
interface PredicateMarketPolicyAdapterOptions {
|
|
196
|
+
appId?: string;
|
|
197
|
+
origin?: string;
|
|
198
|
+
expiresAt?: number;
|
|
199
|
+
}
|
|
200
|
+
declare const createPredicateMarketPolicyAdapter: (options?: PredicateMarketPolicyAdapterOptions) => {
|
|
201
|
+
deposit(token: SupportedToken, chain: SupportedChain, maxAmount?: string): SessionCapabilityPolicy;
|
|
202
|
+
withdraw(token: SupportedToken, chain: SupportedChain, maxAmount?: string): SessionCapabilityPolicy;
|
|
203
|
+
trade(chain: SupportedChain, capabilities?: WalletCapability[]): SessionCapabilityPolicy;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export { ChainData, type DepositController, type DepositModalConfig, type DepositStatus, type Erc20BalanceResult, type FundingTokenBalanceOptions, type FundingWithdrawExecutorOptions, type PredicateMarketPolicyAdapterOptions, TokenData, type WithdrawController, type WithdrawExecutor, type WithdrawModalConfig, type WithdrawRequest, type WithdrawResult, type WithdrawStatus, type WithdrawTxRequest, createDepositController, createFundingWithdrawExecutor, createMarketDataProvider, createPredicateMarketPolicyAdapter, createWithdrawController, fetchErc20Balance, fetchFundingTokenBalance, findTokenDataFromChains, isUsdtWithdrawDirect, parseUnits };
|
package/dist/merchant.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createDepositController, createFundingWithdrawExecutor, createMarketDataProvider, createPredicateMarketPolicyAdapter, createWithdrawController, fetchErc20Balance, fetchFundingTokenBalance, findTokenDataFromChains, isUsdtWithdrawDirect, parseUnits } from './chunk-IUBVUCWJ.js';
|
|
2
|
+
import './chunk-F2UPP3YC.js';
|
|
3
|
+
export { configureMerchantApi, createOrder, getChains, getDepositOrder, getMerchantApiClient, getWithdrawOrder, quote, registerPlatform } from './chunk-TPMI3XWV.js';
|
|
4
|
+
import './chunk-SHLNBZBY.js';
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { a as SocialProvider, W as WalletItem, G as GoogleCredential, T as TwitterAuthResult } from './signInTypes-DESvmgWG.js';
|
|
3
|
+
import { WalletSession, WalletProviderRequest } from '@ab-org/sdk-core';
|
|
4
|
+
import { CubeSignerSession } from '@ab-org/sdk-core/social/auth';
|
|
5
|
+
import { ReactNode, ChangeEventHandler } from 'react';
|
|
6
|
+
import { W as WithdrawOrderResponseData } from './api-DyQAYQ0i.js';
|
|
7
|
+
import 'axios';
|
|
8
|
+
|
|
9
|
+
interface SignInModalProps {
|
|
10
|
+
title?: string;
|
|
11
|
+
socialProviders?: SocialProvider[];
|
|
12
|
+
wallets?: WalletItem[];
|
|
13
|
+
initialVisibleCount?: number;
|
|
14
|
+
privacyPolicyUrl?: string;
|
|
15
|
+
termsOfUseUrl?: string;
|
|
16
|
+
onGoogleLogin?: (credential: GoogleCredential) => void;
|
|
17
|
+
onTwitterLogin?: (result: TwitterAuthResult) => void;
|
|
18
|
+
onCubeSignerSession?: (session: CubeSignerSession) => void;
|
|
19
|
+
onWalletConnected?: (session: WalletSession, walletId: string) => void;
|
|
20
|
+
onSocialLogin?: (providerId: string) => void;
|
|
21
|
+
onWalletSelect?: (walletId: string) => void | Promise<void>;
|
|
22
|
+
/** 仅关闭弹窗(点 X 或遮罩时调用),不传 session */
|
|
23
|
+
onDismiss?: () => void;
|
|
24
|
+
/** 登录成功后调用,传入 session;调用方在此回调里更新 session 并自行关闭弹窗 */
|
|
25
|
+
onSuccess?: (session: WalletSession) => void;
|
|
26
|
+
}
|
|
27
|
+
declare const SignInModal: ({ title, socialProviders, wallets, initialVisibleCount, privacyPolicyUrl, termsOfUseUrl, onGoogleLogin, onTwitterLogin, onCubeSignerSession, onWalletConnected, onSocialLogin, onWalletSelect, onDismiss, onSuccess, }: SignInModalProps) => react_jsx_runtime.JSX.Element;
|
|
28
|
+
|
|
29
|
+
type ToastVariant = "success" | "error" | "info";
|
|
30
|
+
interface ToastProps {
|
|
31
|
+
message: string;
|
|
32
|
+
variant?: ToastVariant;
|
|
33
|
+
/** Auto-dismiss after ms. Omit for no auto-dismiss. */
|
|
34
|
+
duration?: number;
|
|
35
|
+
onClose?: () => void;
|
|
36
|
+
}
|
|
37
|
+
declare const Toast: ({ message, variant, duration, onClose }: ToastProps) => react_jsx_runtime.JSX.Element;
|
|
38
|
+
|
|
39
|
+
type HexString = `0x${string}`;
|
|
40
|
+
type BlockTag = "latest" | "pending";
|
|
41
|
+
type SwitchEthereumChainRequest = {
|
|
42
|
+
chainId: string | number | bigint;
|
|
43
|
+
};
|
|
44
|
+
interface SocialAccountInstance {
|
|
45
|
+
readonly address: HexString;
|
|
46
|
+
request<T = unknown>(payload: WalletProviderRequest): Promise<T>;
|
|
47
|
+
eth_accounts(): Promise<string[]>;
|
|
48
|
+
eth_requestAccounts(): Promise<string[]>;
|
|
49
|
+
eth_chainId(): Promise<HexString>;
|
|
50
|
+
wallet_switchEthereumChain(networks: SwitchEthereumChainRequest[]): Promise<boolean>;
|
|
51
|
+
eth_getBalance(params: [HexString, "latest"]): Promise<string>;
|
|
52
|
+
eth_getTransactionCount(params: [HexString, BlockTag]): Promise<number>;
|
|
53
|
+
personal_sign(params: [string, HexString]): Promise<HexString>;
|
|
54
|
+
eth_signTypedData_v4(params: [HexString, unknown]): Promise<HexString>;
|
|
55
|
+
eth_signTransaction(params: [Record<string, unknown>]): Promise<string>;
|
|
56
|
+
disconnect(): Promise<void>;
|
|
57
|
+
getCubeSignerSession(): CubeSignerSession;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface WalletOption {
|
|
61
|
+
id: string;
|
|
62
|
+
label: string;
|
|
63
|
+
description: string;
|
|
64
|
+
category: "social" | "plugin";
|
|
65
|
+
icon?: ReactNode;
|
|
66
|
+
}
|
|
67
|
+
interface WalletSelectionModalProps {
|
|
68
|
+
title?: string;
|
|
69
|
+
options: WalletOption[];
|
|
70
|
+
onSelect?: (id: string) => void;
|
|
71
|
+
}
|
|
72
|
+
declare const WalletSelectionModal: ({ title, options, onSelect, }: WalletSelectionModalProps) => react_jsx_runtime.JSX.Element;
|
|
73
|
+
|
|
74
|
+
interface SelectOption {
|
|
75
|
+
id: string;
|
|
76
|
+
label: string;
|
|
77
|
+
subtitle?: string;
|
|
78
|
+
icon?: ReactNode;
|
|
79
|
+
}
|
|
80
|
+
interface DropdownFieldProps {
|
|
81
|
+
label: string;
|
|
82
|
+
placeholder?: string;
|
|
83
|
+
value?: string;
|
|
84
|
+
icon?: ReactNode;
|
|
85
|
+
focused?: boolean;
|
|
86
|
+
options?: SelectOption[];
|
|
87
|
+
onSelect?: (id: string) => void;
|
|
88
|
+
/** @deprecated Use `options` + `onSelect` instead. */
|
|
89
|
+
onClick?: () => void;
|
|
90
|
+
}
|
|
91
|
+
declare const DropdownField: ({ label, placeholder, value, icon, focused, options, onSelect, onClick, }: DropdownFieldProps) => react_jsx_runtime.JSX.Element;
|
|
92
|
+
|
|
93
|
+
interface DepositModalProps {
|
|
94
|
+
/** Pre-selected token id. */
|
|
95
|
+
token?: string;
|
|
96
|
+
/** Pre-selected chain id. */
|
|
97
|
+
chain?: string;
|
|
98
|
+
/** Available tokens (when not provided, fetched from getChains). */
|
|
99
|
+
tokenOptions?: SelectOption[];
|
|
100
|
+
/** Available chains (when not provided, derived from getChains by token). */
|
|
101
|
+
chainOptions?: SelectOption[];
|
|
102
|
+
/** Deposit address,必须由调用方传入;在已选 token+chain 时若未传入合法值将抛错。 */
|
|
103
|
+
depositAddress?: string;
|
|
104
|
+
/** e.g. "0.01 USDT" */
|
|
105
|
+
minimumDeposit?: string;
|
|
106
|
+
/** Icon rendered at the center of the QR code. */
|
|
107
|
+
qrCenterIcon?: ReactNode;
|
|
108
|
+
/** Extra icons shown on the Transfer Crypto row. */
|
|
109
|
+
cryptoIcons?: ReactNode;
|
|
110
|
+
/** Deposit amount for quote (optional; when set, quote is fetched and shown). */
|
|
111
|
+
depositAmount?: string;
|
|
112
|
+
/** Called for toast messages (copy, quote expired, wait for balance, transfer confirmed). */
|
|
113
|
+
onShowToast?: (message: string) => void;
|
|
114
|
+
/** When set, show "Transfer confirmed" toast and explorer link. */
|
|
115
|
+
txHash?: string;
|
|
116
|
+
/** Build explorer URL for tx; e.g. (chainId, txHash) => `https://bscscan.com/tx/${txHash}` */
|
|
117
|
+
explorerTxUrl?: (chainId: string, txHash: string) => string;
|
|
118
|
+
onTokenSelect?: (id: string) => void;
|
|
119
|
+
onChainSelect?: (id: string) => void;
|
|
120
|
+
onCopyAddress?: (address: string) => void;
|
|
121
|
+
onBuyCrypto?: () => void;
|
|
122
|
+
onSignIn?: () => void;
|
|
123
|
+
onBack?: () => void;
|
|
124
|
+
onClose?: () => void;
|
|
125
|
+
}
|
|
126
|
+
declare const DepositModal: ({ token, chain, tokenOptions: tokenOptionsProp, chainOptions: chainOptionsProp, depositAddress, minimumDeposit, qrCenterIcon, cryptoIcons, depositAmount, onShowToast, txHash, explorerTxUrl, onTokenSelect, onChainSelect, onCopyAddress, onBuyCrypto, onSignIn, onBack, onClose, }: DepositModalProps) => react_jsx_runtime.JSX.Element;
|
|
127
|
+
|
|
128
|
+
type WithdrawUiStatus = "idle" | "pending" | "success" | "manual_review";
|
|
129
|
+
interface WithdrawModalProps {
|
|
130
|
+
address?: string;
|
|
131
|
+
token?: string;
|
|
132
|
+
tokenSymbol?: string;
|
|
133
|
+
chain?: string;
|
|
134
|
+
amount?: string;
|
|
135
|
+
balance?: string;
|
|
136
|
+
status?: WithdrawUiStatus;
|
|
137
|
+
receiveAmount?: string;
|
|
138
|
+
txHash?: string;
|
|
139
|
+
eta?: string;
|
|
140
|
+
tokenOptions?: SelectOption[];
|
|
141
|
+
chainOptions?: SelectOption[];
|
|
142
|
+
/** 使用 Merchant API:getChains 拉取 token/chain,quote(withdraw) 询价 */
|
|
143
|
+
useMerchantApi?: boolean;
|
|
144
|
+
/** 创建订单后传入,用于轮询提现订单状态 */
|
|
145
|
+
orderId?: string;
|
|
146
|
+
/** 提现模式:direct 直接提现,cross_chain 跨链提现 */
|
|
147
|
+
withdrawMode?: "direct" | "cross_chain";
|
|
148
|
+
/**
|
|
149
|
+
* 直接提现模式(无 orderId)下的结果数据;
|
|
150
|
+
* 将用来构造一个与 getWithdrawOrder 返回值兼容的对象,从而复用“有 orderId”时的全部交互与展示。
|
|
151
|
+
* 最少建议提供:status、dst_token_amount、target_chain_id、target_address(必要时包含 dst_tx_hash / out_tx_hash、fee)。
|
|
152
|
+
*/
|
|
153
|
+
withdrawDirectResult?: Partial<WithdrawOrderResponseData>;
|
|
154
|
+
/** 成功页 Fee 展示:优先用订单接口返回的 fee,若后端未返回则用此值(如询价时的 fee),均无则显示 "—" */
|
|
155
|
+
feeDisplay?: string;
|
|
156
|
+
/** 广播后的 funding tx 所在链 id,与 txHash 一起用于展示「查看交易」链接 */
|
|
157
|
+
fundingChainId?: string;
|
|
158
|
+
/** 构建链上交易浏览器链接(已弃用,使用 getExplorerUrl) */
|
|
159
|
+
explorerTxUrl?: (chainId: string, txHash: string) => string;
|
|
160
|
+
onShowToast?: (message: string) => void;
|
|
161
|
+
onAddressChange?: ChangeEventHandler<HTMLInputElement>;
|
|
162
|
+
onTokenSelect?: (id: string) => void;
|
|
163
|
+
onChainSelect?: (id: string) => void;
|
|
164
|
+
onAmountChange?: ChangeEventHandler<HTMLInputElement>;
|
|
165
|
+
onMaxClick?: () => void;
|
|
166
|
+
/** 提交时传入当前表单值(收款地址、金额、所选 token、链上合约地址、所选 chain),由调用方执行提现 */
|
|
167
|
+
onSubmit?: (payload: {
|
|
168
|
+
toAddress: string;
|
|
169
|
+
amount: string;
|
|
170
|
+
token: string;
|
|
171
|
+
tokenAddress: string;
|
|
172
|
+
chain: string;
|
|
173
|
+
}) => void;
|
|
174
|
+
/** 提现订单状态变为 completed 时调用,用于调用方刷新余额等 */
|
|
175
|
+
onWithdrawCompleted?: () => void;
|
|
176
|
+
/** 点击「Start another withdrawal」时调用;应由调用方清空 orderId、重置 amount,恢复到待提交状态(不关弹层)。未传则退化为 onClose。 */
|
|
177
|
+
onStartAnotherWithdrawal?: () => void;
|
|
178
|
+
onSignIn?: () => void;
|
|
179
|
+
onClose?: () => void;
|
|
180
|
+
}
|
|
181
|
+
declare const WithdrawModal: ({ address, token, tokenSymbol, chain, amount, balance, status, receiveAmount: receiveAmountProp, txHash, tokenOptions: tokenOptionsProp, chainOptions: chainOptionsProp, useMerchantApi, orderId, withdrawMode, withdrawDirectResult, feeDisplay, fundingChainId, onShowToast, onAddressChange, onTokenSelect, onChainSelect, onAmountChange, onMaxClick, onSubmit, onWithdrawCompleted, onStartAnotherWithdrawal, onSignIn, onClose, }: WithdrawModalProps) => react_jsx_runtime.JSX.Element;
|
|
182
|
+
|
|
183
|
+
interface DepositDetailsPanelProps {
|
|
184
|
+
address: string;
|
|
185
|
+
tokenIcon?: ReactNode;
|
|
186
|
+
minimumDeposit?: string;
|
|
187
|
+
onCopyAddress?: (address: string) => void;
|
|
188
|
+
}
|
|
189
|
+
declare const DepositDetailsPanel: ({ address, tokenIcon, minimumDeposit, onCopyAddress, }: DepositDetailsPanelProps) => react_jsx_runtime.JSX.Element;
|
|
190
|
+
|
|
191
|
+
declare const WalletAccount: {
|
|
192
|
+
getInstance(oidcToken: string): Promise<SocialAccountInstance>;
|
|
193
|
+
clearInstance(): void;
|
|
194
|
+
};
|
|
195
|
+
declare function clearSocialAccountInstance(): void;
|
|
196
|
+
|
|
197
|
+
export { DepositDetailsPanel, type DepositDetailsPanelProps, DepositModal, type DepositModalProps, DropdownField, type DropdownFieldProps, type SelectOption, SignInModal, type SignInModalProps, SocialProvider, Toast, WalletAccount, WalletItem, type WalletOption, WalletSelectionModal, type WalletSelectionModalProps, WithdrawModal, type WithdrawModalProps, type WithdrawUiStatus, clearSocialAccountInstance };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { DepositDetailsPanel, DepositModal, DropdownField, SignInModal, Toast, WalletAccount, WalletSelectionModal, WithdrawModal, clearSocialAccountInstance } from './chunk-SZYGIQT3.js';
|
|
2
|
+
import './chunk-XB2DFS2W.js';
|
|
3
|
+
import './chunk-TPMI3XWV.js';
|
|
4
|
+
import './chunk-SHLNBZBY.js';
|
|
5
|
+
import './chunk-6YQEHB6P.js';
|
|
6
|
+
import './chunk-WHTI52FI.js';
|
|
7
|
+
import './chunk-YX56ZGDB.js';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { SessionCapabilityPolicy } from '@ab-org/sdk-core';
|
|
3
|
+
|
|
4
|
+
interface WalletItem {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
icon?: ReactNode;
|
|
8
|
+
installed?: boolean;
|
|
9
|
+
installUrl?: string;
|
|
10
|
+
}
|
|
11
|
+
interface SocialProvider {
|
|
12
|
+
id: string;
|
|
13
|
+
label: string;
|
|
14
|
+
icon?: ReactNode;
|
|
15
|
+
}
|
|
16
|
+
interface SignInUiConfig {
|
|
17
|
+
socialProviders?: SocialProvider[];
|
|
18
|
+
wallets?: WalletItem[];
|
|
19
|
+
initialVisibleCount?: number;
|
|
20
|
+
sessionConfirmation?: {
|
|
21
|
+
enabled?: boolean;
|
|
22
|
+
title?: string;
|
|
23
|
+
message?: string;
|
|
24
|
+
};
|
|
25
|
+
sessionPolicy?: Partial<SessionCapabilityPolicy>;
|
|
26
|
+
}
|
|
27
|
+
/** Shape for optional `onGoogleLogin` callbacks (modal uses OIDC `handleSocialClick` instead). */
|
|
28
|
+
interface GoogleCredential {
|
|
29
|
+
idToken: string;
|
|
30
|
+
email?: string;
|
|
31
|
+
name?: string;
|
|
32
|
+
picture?: string;
|
|
33
|
+
}
|
|
34
|
+
/** Shape for optional `onTwitterLogin` callbacks (modal uses OIDC `handleSocialClick` instead). */
|
|
35
|
+
interface TwitterAuthResult {
|
|
36
|
+
code: string;
|
|
37
|
+
codeVerifier: string;
|
|
38
|
+
state: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type { GoogleCredential as G, SignInUiConfig as S, TwitterAuthResult as T, WalletItem as W, SocialProvider as a };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
interface CustodyAdapter {
|
|
2
|
+
getDepositStatus(depositId: string): Promise<{
|
|
3
|
+
status: string;
|
|
4
|
+
txHash?: string;
|
|
5
|
+
}>;
|
|
6
|
+
requestWithdraw(params: {
|
|
7
|
+
amount: string;
|
|
8
|
+
token: string;
|
|
9
|
+
chain: string;
|
|
10
|
+
targetAddress: string;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
requestId: string;
|
|
13
|
+
}>;
|
|
14
|
+
getWithdrawStatus(requestId: string): Promise<{
|
|
15
|
+
status: string;
|
|
16
|
+
txHash?: string;
|
|
17
|
+
etaSeconds?: number;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
interface ModalController<TConfig> {
|
|
21
|
+
open(config?: TConfig): void;
|
|
22
|
+
}
|
|
23
|
+
interface TokenInfo {
|
|
24
|
+
symbol: string;
|
|
25
|
+
name: string;
|
|
26
|
+
decimals: number;
|
|
27
|
+
iconUrl?: string;
|
|
28
|
+
minAmount?: string;
|
|
29
|
+
maxAmount?: string;
|
|
30
|
+
}
|
|
31
|
+
interface ChainInfo {
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
iconUrl?: string;
|
|
35
|
+
confirmations?: number;
|
|
36
|
+
estimatedTime?: string;
|
|
37
|
+
}
|
|
38
|
+
interface QuoteRequest {
|
|
39
|
+
token: string;
|
|
40
|
+
chain: string;
|
|
41
|
+
amount: string;
|
|
42
|
+
direction: "deposit" | "withdraw";
|
|
43
|
+
}
|
|
44
|
+
interface QuoteResult {
|
|
45
|
+
quoteId: string;
|
|
46
|
+
estimatedAmount: string;
|
|
47
|
+
slippage: string;
|
|
48
|
+
fee: string;
|
|
49
|
+
feeToken: string;
|
|
50
|
+
exchangeRate: string;
|
|
51
|
+
expiresAt: number;
|
|
52
|
+
}
|
|
53
|
+
interface DepositAddressResult {
|
|
54
|
+
address: string;
|
|
55
|
+
minimumDeposit?: string;
|
|
56
|
+
}
|
|
57
|
+
interface MarketDataProvider {
|
|
58
|
+
getSupportedTokens(direction: "deposit" | "withdraw"): Promise<TokenInfo[]>;
|
|
59
|
+
getSupportedChains(token: string, direction: "deposit" | "withdraw"): Promise<ChainInfo[]>;
|
|
60
|
+
getQuote(request: QuoteRequest): Promise<QuoteResult>;
|
|
61
|
+
getDepositAddress(token: string, chain: string): Promise<DepositAddressResult>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type { ChainInfo as C, DepositAddressResult as D, MarketDataProvider as M, QuoteRequest as Q, TokenInfo as T, CustodyAdapter as a, ModalController as b, QuoteResult as c };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ab-org/predicate-market-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1-beta.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/**/*",
|
|
@@ -13,6 +13,22 @@
|
|
|
13
13
|
".": {
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
15
|
"import": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./core": {
|
|
18
|
+
"types": "./dist/core.d.ts",
|
|
19
|
+
"import": "./dist/core.js"
|
|
20
|
+
},
|
|
21
|
+
"./auth": {
|
|
22
|
+
"types": "./dist/auth.d.ts",
|
|
23
|
+
"import": "./dist/auth.js"
|
|
24
|
+
},
|
|
25
|
+
"./react": {
|
|
26
|
+
"types": "./dist/react.d.ts",
|
|
27
|
+
"import": "./dist/react.js"
|
|
28
|
+
},
|
|
29
|
+
"./merchant": {
|
|
30
|
+
"types": "./dist/merchant.d.ts",
|
|
31
|
+
"import": "./dist/merchant.js"
|
|
16
32
|
}
|
|
17
33
|
},
|
|
18
34
|
"publishConfig": {
|
|
@@ -20,29 +36,25 @@
|
|
|
20
36
|
"registry": "https://registry.npmjs.org/"
|
|
21
37
|
},
|
|
22
38
|
"dependencies": {
|
|
23
|
-
"@cubist-labs/cubesigner-sdk": "^0.4.219",
|
|
24
39
|
"axios": "^1.13.6",
|
|
25
40
|
"qrcode-generator": "^2.0.4",
|
|
26
|
-
"
|
|
41
|
+
"viem": "2.21.54",
|
|
42
|
+
"@ab-org/sdk-core": "0.2.2-beta.0"
|
|
27
43
|
},
|
|
28
44
|
"peerDependencies": {
|
|
29
|
-
"react": ">=18"
|
|
30
|
-
"viem": ">=2"
|
|
45
|
+
"react": ">=18"
|
|
31
46
|
},
|
|
32
47
|
"devDependencies": {
|
|
33
48
|
"@types/react": "^18.2.66",
|
|
34
49
|
"typescript": "^5.5.4",
|
|
35
|
-
"viem": "2.21.54",
|
|
36
50
|
"tsup": "^8.5.1",
|
|
51
|
+
"@ab-org/oidc-auth": "0.0.16",
|
|
37
52
|
"@ab-org/chains-service": "0.0.8",
|
|
38
|
-
"@ab-org/cubist-wallet-sdk": "0.0.9",
|
|
39
53
|
"@ab-org/sign-in-sdk": "0.1.0",
|
|
40
|
-
"@ab-org/
|
|
41
|
-
"@ab-org/wallet-utils": "0.0.7",
|
|
42
|
-
"@ab-org/oidc-auth": "0.0.16"
|
|
54
|
+
"@ab-org/wallet-utils": "0.0.7"
|
|
43
55
|
},
|
|
44
56
|
"scripts": {
|
|
45
|
-
"build": "tsup",
|
|
57
|
+
"build": "pnpm exec tsup",
|
|
46
58
|
"lint": "eslint 'src/**/*.{ts,tsx}'",
|
|
47
59
|
"test": "vitest run --passWithNoTests"
|
|
48
60
|
}
|