@ab-org/predicate-market-sdk 2.0.1-beta.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 +3 -1
- package/dist/{chunk-26RFAFJG.js → autoReconnect-IFPVI2XU.js} +3 -1
- package/dist/{chunk-66CHMJG7.js → chunk-IUBVUCWJ.js} +51 -159
- package/dist/{chunk-F3HQRJID.js → chunk-JFRRJXOJ.js} +1 -1
- package/dist/{chunk-C5BV2OG7.js → chunk-LOJTP47I.js} +1 -1
- package/dist/core.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -4
- package/dist/merchant.d.ts +25 -6
- package/dist/merchant.js +1 -4
- package/package.json +3 -3
- package/dist/autoReconnect-6YV7YSSL.js +0 -4
package/README.md
CHANGED
|
@@ -44,6 +44,8 @@ Why the split:
|
|
|
44
44
|
|
|
45
45
|
Upgrade notes are summarized in `docs/pages/index.mdx` under “Upgrading from legacy root exports”.
|
|
46
46
|
|
|
47
|
+
Withdraw migration notes for existing integrators: `./MIGRATION.md`
|
|
48
|
+
|
|
47
49
|
|
|
48
50
|
## Quick start
|
|
49
51
|
```tsx
|
|
@@ -134,7 +136,7 @@ Rules:
|
|
|
134
136
|
- **`getFundingTokenAddress(chainId?)`** — same optional **`chainId`** as **`getChainInfo`**. If **`NEXT_PUBLIC_FUNDING_TOKEN_ADDRESS`** / **`FUNDING_TOKEN_ADDRESS`** or legacy defaultFundingTokenAddress`**.
|
|
135
137
|
- **`DEFAULT_FUNDING_TOKEN_ADDRESS`** — shorthand for **`getChainInfo().defaultFundingTokenAddress`** (default funding chain **`3131`**).
|
|
136
138
|
- **`fetchFundingTokenBalance(address, { chainId, rpcUrl?, tokenAddress?, decimals?, displaySymbol? })`** — uses **`getChainInfo(chainId)`** for RPC when **`rpcUrl`** is omitted, **`getFundingTokenAddress(chainId)`** when **`tokenAddress`** is omitted, and **`decimals`** default **`chain.nativeCurrencyDecimals`** when omitted (override if your funding token uses different decimals).
|
|
137
|
-
- **`createFundingWithdrawExecutor({ chainId?, rpcUrl?, tokenAddress?, … })`** — uses the same **`chainId`** for **`getChainInfo`**, default token address (**`getFundingTokenAddress(chainId)`**), and order payload (default **`3131`** when **`chainId`** omitted).
|
|
139
|
+
- **`createFundingWithdrawExecutor({ chainId?, rpcUrl?, tokenAddress?, … })`** — uses the same **`chainId`** for **`getChainInfo`**, default token address (**`getFundingTokenAddress(chainId)`**), and order payload (default **`3131`** when **`chainId`** omitted). It now returns withdraw metadata plus a **`txRequest`**; your app must implement the actual **`sendWithdrawTx(txRequest)`** wallet broadcast.
|
|
138
140
|
|
|
139
141
|
**Type note:** **`EvmChainInfo`** includes **`defaultFundingTokenAddress`**. If you construct chain objects manually in TypeScript, add that field or use **`getChainInfo`** instead of literals.
|
|
140
142
|
- `socialProviders: undefined` uses built-in defaults (`google`, `x`)
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { getSDKConfig } from './chunk-
|
|
1
|
+
import { getSDKConfig } from './chunk-JFRRJXOJ.js';
|
|
2
|
+
import './chunk-SHLNBZBY.js';
|
|
3
|
+
import './chunk-WHTI52FI.js';
|
|
2
4
|
import { sessionStore, createDefaultInjectedWalletRegistry, WalletConnector } from '@ab-org/sdk-core';
|
|
3
5
|
import { CubistSocialProvider } from '@ab-org/sdk-core/social/provider';
|
|
4
6
|
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { getChainInfo, getFundingTokenAddress, DEFAULT_FUNDING_CHAIN_ID } from './chunk-F2UPP3YC.js';
|
|
2
2
|
import { getChains, createOrder } from './chunk-TPMI3XWV.js';
|
|
3
|
-
import { tryAutoReconnect } from './chunk-26RFAFJG.js';
|
|
4
3
|
import { getEnv } from './chunk-SHLNBZBY.js';
|
|
5
4
|
import { sessionStore, createSessionCapabilityPolicy } from '@ab-org/sdk-core';
|
|
6
|
-
import {
|
|
5
|
+
import { formatUnits } from 'viem';
|
|
7
6
|
|
|
8
7
|
function requireSession() {
|
|
9
8
|
const session = sessionStore.getState().session;
|
|
@@ -253,119 +252,69 @@ async function fetchFundingTokenBalance(walletAddress, options) {
|
|
|
253
252
|
symbol: displaySymbol
|
|
254
253
|
};
|
|
255
254
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
function
|
|
259
|
-
|
|
255
|
+
|
|
256
|
+
// src/modules/withdrawDirect.ts
|
|
257
|
+
function isUsdtWithdrawDirect(chainId, tokenAddress, chains) {
|
|
258
|
+
if (chainId !== String(DEFAULT_FUNDING_CHAIN_ID)) return false;
|
|
259
|
+
const addr = tokenAddress.trim();
|
|
260
|
+
if (!addr) return false;
|
|
261
|
+
const chain = chains.find((c) => c.chain_id === chainId);
|
|
262
|
+
const token = chain?.tokens.find((t) => t.address.toLowerCase() === addr.toLowerCase());
|
|
263
|
+
return token?.is_usd_stable === true;
|
|
260
264
|
}
|
|
261
|
-
function
|
|
262
|
-
|
|
265
|
+
function findTokenDataFromChains(chains, chainId, opts) {
|
|
266
|
+
const chain = chains.find((c) => c.chain_id === chainId);
|
|
267
|
+
if (!chain?.tokens.length) return void 0;
|
|
268
|
+
const sym = opts.symbol.trim();
|
|
269
|
+
const addr = opts.tokenAddress?.trim().toLowerCase();
|
|
270
|
+
return chain.tokens.find((t) => {
|
|
271
|
+
if (addr && t.address.toLowerCase() === addr) return true;
|
|
272
|
+
if (sym.length > 0 && t.symbol === sym) return true;
|
|
273
|
+
return false;
|
|
274
|
+
});
|
|
263
275
|
}
|
|
276
|
+
|
|
277
|
+
// src/modules/withdrawExecutor.ts
|
|
264
278
|
function parseUnits(value, decimals) {
|
|
265
279
|
if (!value || value === "0") return 0n;
|
|
266
280
|
const [intPart = "0", fracPart = ""] = value.split(".");
|
|
267
281
|
const padded = fracPart.padEnd(decimals, "0").slice(0, decimals);
|
|
268
282
|
return BigInt(intPart) * 10n ** BigInt(decimals) + BigInt(padded);
|
|
269
283
|
}
|
|
270
|
-
function encodeTransferData(to, amountWei) {
|
|
271
|
-
return `${ERC20_TRANSFER_SELECTOR}${padAddress2(to)}${padHex256(amountWei)}`;
|
|
272
|
-
}
|
|
273
|
-
function isUnsupportedMethodError(error) {
|
|
274
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
275
|
-
return /unsupported rpc method|unsupported method|method not found|does not support/i.test(
|
|
276
|
-
message
|
|
277
|
-
);
|
|
278
|
-
}
|
|
279
|
-
function toHexQuantity(value) {
|
|
280
|
-
if (typeof value === "string") {
|
|
281
|
-
if (/^0x[0-9a-fA-F]+$/.test(value)) {
|
|
282
|
-
return value;
|
|
283
|
-
}
|
|
284
|
-
if (/^\d+$/.test(value)) {
|
|
285
|
-
return toHex(BigInt(value));
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
if (typeof value === "number") {
|
|
289
|
-
return toHex(BigInt(value));
|
|
290
|
-
}
|
|
291
|
-
if (typeof value === "bigint") {
|
|
292
|
-
return toHex(value);
|
|
293
|
-
}
|
|
294
|
-
throw new Error(`Invalid EVM quantity: ${String(value)}`);
|
|
295
|
-
}
|
|
296
|
-
async function callRpc(rpcUrl, method, params) {
|
|
297
|
-
const response = await fetch(rpcUrl, {
|
|
298
|
-
method: "POST",
|
|
299
|
-
headers: { "Content-Type": "application/json" },
|
|
300
|
-
body: JSON.stringify({
|
|
301
|
-
jsonrpc: "2.0",
|
|
302
|
-
id: Date.now(),
|
|
303
|
-
method,
|
|
304
|
-
params
|
|
305
|
-
})
|
|
306
|
-
});
|
|
307
|
-
const json = await response.json();
|
|
308
|
-
if (!response.ok || json.error) {
|
|
309
|
-
throw new Error(json.error?.message ?? `${method} failed`);
|
|
310
|
-
}
|
|
311
|
-
return json.result;
|
|
312
|
-
}
|
|
313
|
-
async function requestHexQuantity(provider, rpcUrl, method, params) {
|
|
314
|
-
try {
|
|
315
|
-
const result = await provider.request({ method, params });
|
|
316
|
-
return toHexQuantity(result);
|
|
317
|
-
} catch (error) {
|
|
318
|
-
if (!isUnsupportedMethodError(error)) {
|
|
319
|
-
throw error;
|
|
320
|
-
}
|
|
321
|
-
return toHexQuantity(await callRpc(rpcUrl, method, params));
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
async function ensureFundingEvmChain(provider, chainId) {
|
|
325
|
-
const hex = `0x${chainId.toString(16)}`;
|
|
326
|
-
try {
|
|
327
|
-
await provider.request({ method: "wallet_switchEthereumChain", params: [{ chainId: hex }] });
|
|
328
|
-
} catch {
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
284
|
function getDstTokenAddress(chains, chainId, tokenSymbol) {
|
|
332
285
|
const chain = chains.find((c) => c.chain_id === chainId);
|
|
333
286
|
return chain?.tokens.find((t) => t.symbol === tokenSymbol)?.address;
|
|
334
287
|
}
|
|
335
288
|
function createFundingWithdrawExecutor(options) {
|
|
336
289
|
const fundingChain = getChainInfo(options?.chainId);
|
|
337
|
-
const chainIdNum = Number(fundingChain.chainId);
|
|
338
|
-
const rpcUrl = options?.rpcUrl ?? fundingChain.rpcUrls[0];
|
|
339
290
|
const tokenAddress = options?.tokenAddress ?? getFundingTokenAddress(options?.chainId);
|
|
340
291
|
const decimals = options?.decimals ?? fundingChain.nativeCurrencyDecimals;
|
|
341
292
|
const maxAmountWei = options?.maxAmountWei;
|
|
342
293
|
const fundingLegTokenSymbol = options?.fundingLegTokenSymbol || getEnv("FUNDING_TOKEN_SYMBOL") || "USDT";
|
|
343
294
|
return async (request) => {
|
|
295
|
+
const chainsRes = await getChains();
|
|
296
|
+
const chains = chainsRes?.chains ?? [];
|
|
297
|
+
if (isUsdtWithdrawDirect(request.chain, request.tokenAddress, chains)) {
|
|
298
|
+
return {
|
|
299
|
+
txRequest: {
|
|
300
|
+
toAddress: request.toAddress,
|
|
301
|
+
amount: request.amount,
|
|
302
|
+
token: request.token,
|
|
303
|
+
tokenAddress: request.tokenAddress,
|
|
304
|
+
tokenDecimals: chains.find((c) => c.chain_id === request.chain)?.tokens.find((t) => t.address.toLowerCase() === request.tokenAddress.toLowerCase())?.decimals ?? decimals,
|
|
305
|
+
chain: request.chain
|
|
306
|
+
},
|
|
307
|
+
fundingChainId: request.chain,
|
|
308
|
+
withdrawMode: "direct"
|
|
309
|
+
};
|
|
310
|
+
}
|
|
344
311
|
const amountWei = parseUnits(request.amount, decimals);
|
|
345
312
|
const amountWeiStr = amountWei.toString();
|
|
346
313
|
if (maxAmountWei != null && amountWei > BigInt(maxAmountWei)) {
|
|
347
314
|
throw new Error("Withdraw amount exceeds the single-transaction limit");
|
|
348
315
|
}
|
|
349
|
-
|
|
316
|
+
const session = sessionStore.getState().session;
|
|
350
317
|
if (!session) throw new Error("Login required");
|
|
351
|
-
let { provider } = session;
|
|
352
|
-
try {
|
|
353
|
-
await provider.request({ method: "eth_chainId", params: [] });
|
|
354
|
-
} catch (err) {
|
|
355
|
-
const msg = err.message ?? "";
|
|
356
|
-
if (msg.includes("restored from cache") || msg.includes("Reconnect your wallet")) {
|
|
357
|
-
const reconnected = await tryAutoReconnect();
|
|
358
|
-
if (reconnected) {
|
|
359
|
-
session = reconnected;
|
|
360
|
-
provider = reconnected.provider;
|
|
361
|
-
} else {
|
|
362
|
-
sessionStore.clearSession();
|
|
363
|
-
throw new Error("Session expired. Please sign in again.");
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
const chainsRes = await getChains();
|
|
368
|
-
const chains = chainsRes?.chains ?? [];
|
|
369
318
|
const dstTokenAddress = getDstTokenAddress(chains, request.chain, request.token);
|
|
370
319
|
if (!dstTokenAddress) {
|
|
371
320
|
throw new Error(`Unsupported token ${request.token} on chain ${request.chain}`);
|
|
@@ -396,78 +345,21 @@ function createFundingWithdrawExecutor(options) {
|
|
|
396
345
|
if (!oneTimeAddress) {
|
|
397
346
|
throw new Error("Order created but no one-time wallet address returned");
|
|
398
347
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
nonce,
|
|
412
|
-
data,
|
|
413
|
-
chainId: toHex(chainIdNum)
|
|
414
|
-
};
|
|
415
|
-
const estimatedGasHex = await requestHexQuantity(
|
|
416
|
-
provider,
|
|
417
|
-
rpcUrl,
|
|
418
|
-
"eth_estimateGas",
|
|
419
|
-
[tx]
|
|
420
|
-
);
|
|
421
|
-
const estimatedGas = fromHex(estimatedGasHex, "bigint");
|
|
422
|
-
const gas = toHex(
|
|
423
|
-
estimatedGas > MAX_WITHDRAW_GAS_LIMIT ? MAX_WITHDRAW_GAS_LIMIT : estimatedGas
|
|
424
|
-
);
|
|
425
|
-
const transaction = {
|
|
426
|
-
...tx,
|
|
427
|
-
gas,
|
|
428
|
-
maxFeePerGas: toHex(parseGwei("5")),
|
|
429
|
-
maxPriorityFeePerGas: toHex(parseGwei("1"))
|
|
348
|
+
return {
|
|
349
|
+
txRequest: {
|
|
350
|
+
toAddress: oneTimeAddress,
|
|
351
|
+
amount: request.amount,
|
|
352
|
+
token: fundingLegTokenSymbol,
|
|
353
|
+
tokenAddress,
|
|
354
|
+
tokenDecimals: decimals,
|
|
355
|
+
chain: fundingChain.chainId
|
|
356
|
+
},
|
|
357
|
+
orderId: orderRes.order_id,
|
|
358
|
+
fundingChainId: fundingChain.chainId,
|
|
359
|
+
withdrawMode: "cross_chain"
|
|
430
360
|
};
|
|
431
|
-
let txHash;
|
|
432
|
-
try {
|
|
433
|
-
txHash = await provider.request({
|
|
434
|
-
method: "eth_sendTransaction",
|
|
435
|
-
params: [transaction]
|
|
436
|
-
});
|
|
437
|
-
} catch (error) {
|
|
438
|
-
if (!isUnsupportedMethodError(error)) {
|
|
439
|
-
throw error;
|
|
440
|
-
}
|
|
441
|
-
const signedTx = await provider.request({
|
|
442
|
-
method: "eth_signTransaction",
|
|
443
|
-
params: [transaction]
|
|
444
|
-
});
|
|
445
|
-
txHash = await callRpc(rpcUrl, "eth_sendRawTransaction", [signedTx]);
|
|
446
|
-
}
|
|
447
|
-
return { txHash, orderId: orderRes.order_id, fundingChainId: fundingChain.chainId };
|
|
448
361
|
};
|
|
449
362
|
}
|
|
450
|
-
|
|
451
|
-
// src/modules/withdrawDirect.ts
|
|
452
|
-
function isUsdtWithdrawDirect(chainId, tokenAddress, chains) {
|
|
453
|
-
if (chainId !== String(DEFAULT_FUNDING_CHAIN_ID)) return false;
|
|
454
|
-
const addr = tokenAddress.trim();
|
|
455
|
-
if (!addr) return false;
|
|
456
|
-
const chain = chains.find((c) => c.chain_id === chainId);
|
|
457
|
-
const token = chain?.tokens.find((t) => t.address.toLowerCase() === addr.toLowerCase());
|
|
458
|
-
return token?.is_usd_stable === true;
|
|
459
|
-
}
|
|
460
|
-
function findTokenDataFromChains(chains, chainId, opts) {
|
|
461
|
-
const chain = chains.find((c) => c.chain_id === chainId);
|
|
462
|
-
if (!chain?.tokens.length) return void 0;
|
|
463
|
-
const sym = opts.symbol.trim();
|
|
464
|
-
const addr = opts.tokenAddress?.trim().toLowerCase();
|
|
465
|
-
return chain.tokens.find((t) => {
|
|
466
|
-
if (addr && t.address.toLowerCase() === addr) return true;
|
|
467
|
-
if (sym.length > 0 && t.symbol === sym) return true;
|
|
468
|
-
return false;
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
363
|
var createPolicy = (overrides, options) => createSessionCapabilityPolicy({
|
|
472
364
|
appId: options?.appId,
|
|
473
365
|
origin: options?.origin,
|
|
@@ -101,7 +101,7 @@ function getFixedAuthConfig() {
|
|
|
101
101
|
}
|
|
102
102
|
function scheduleAutoReconnect() {
|
|
103
103
|
if (typeof window === "undefined") return;
|
|
104
|
-
void import('./autoReconnect-
|
|
104
|
+
void import('./autoReconnect-IFPVI2XU.js').then(({ tryAutoReconnect }) => tryAutoReconnect()).catch(() => {
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
function initSDK2(config = {}) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/core.ts
|
|
2
2
|
function tryAutoReconnect() {
|
|
3
|
-
return import('./autoReconnect-
|
|
3
|
+
return import('./autoReconnect-IFPVI2XU.js').then(({ tryAutoReconnect: reconnect }) => reconnect());
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
export { tryAutoReconnect };
|
package/dist/core.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { tryAutoReconnect } from './chunk-
|
|
1
|
+
export { tryAutoReconnect } from './chunk-LOJTP47I.js';
|
|
2
2
|
export { ClientIds, DEFAULT_FUNDING_CHAIN_ID, DEFAULT_FUNDING_TOKEN_ADDRESS, getChainInfo, getFundingTokenAddress } from './chunk-F2UPP3YC.js';
|
|
3
3
|
export { getExplorerUrl } from './chunk-XB2DFS2W.js';
|
|
4
|
-
export { getFixedAuthConfig, getSDKConfig, initSDK } from './chunk-
|
|
4
|
+
export { getFixedAuthConfig, getSDKConfig, initSDK } from './chunk-JFRRJXOJ.js';
|
|
5
5
|
export { getEnv } from './chunk-SHLNBZBY.js';
|
|
6
6
|
import './chunk-WHTI52FI.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { ClientIds, DEFAULT_FUNDING_CHAIN_ID, DEFAULT_FUNDING_TOKEN_ADDRESS, Evm
|
|
|
2
2
|
export { notifyTwitterCallback } from './auth.js';
|
|
3
3
|
export { G as GoogleCredential, S as SignInUiConfig, a as SocialProvider, T as TwitterAuthResult, W as WalletItem } from './signInTypes-DESvmgWG.js';
|
|
4
4
|
export { DepositDetailsPanel, DepositDetailsPanelProps, DepositModal, DepositModalProps, DropdownField, DropdownFieldProps, SelectOption, SignInModal, SignInModalProps, Toast, WalletAccount, WalletOption, WalletSelectionModal, WalletSelectionModalProps, WithdrawModal, WithdrawModalProps, WithdrawUiStatus, clearSocialAccountInstance } from './react.js';
|
|
5
|
-
export { DepositController, DepositModalConfig, DepositStatus, Erc20BalanceResult, FundingTokenBalanceOptions, FundingWithdrawExecutorOptions, PredicateMarketPolicyAdapterOptions, WithdrawController, WithdrawExecutor, WithdrawModalConfig, WithdrawRequest, WithdrawResult, WithdrawStatus, createDepositController, createFundingWithdrawExecutor, createMarketDataProvider, createPredicateMarketPolicyAdapter, createWithdrawController, fetchErc20Balance, fetchFundingTokenBalance, findTokenDataFromChains, isUsdtWithdrawDirect, parseUnits } from './merchant.js';
|
|
5
|
+
export { DepositController, DepositModalConfig, DepositStatus, Erc20BalanceResult, FundingTokenBalanceOptions, FundingWithdrawExecutorOptions, PredicateMarketPolicyAdapterOptions, WithdrawController, WithdrawExecutor, WithdrawModalConfig, WithdrawRequest, WithdrawResult, WithdrawStatus, WithdrawTxRequest, createDepositController, createFundingWithdrawExecutor, createMarketDataProvider, createPredicateMarketPolicyAdapter, createWithdrawController, fetchErc20Balance, fetchFundingTokenBalance, findTokenDataFromChains, isUsdtWithdrawDirect, parseUnits } from './merchant.js';
|
|
6
6
|
export { A as ApiResponse, C as ChainData, 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, T as TokenData, 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';
|
|
7
7
|
export { C as ChainInfo, a as CustodyAdapter, D as DepositAddressResult, M as MarketDataProvider, b as ModalController, Q as QuoteRequest, c as QuoteResult, T as TokenInfo } from './types-BFidNjd9.js';
|
|
8
8
|
import '@ab-org/sdk-core/social/auth';
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
export { notifyTwitterCallback } from './chunk-UAXKA6QC.js';
|
|
2
|
-
export { tryAutoReconnect } from './chunk-
|
|
3
|
-
export { createDepositController, createFundingWithdrawExecutor, createMarketDataProvider, createPredicateMarketPolicyAdapter, createWithdrawController, fetchErc20Balance, fetchFundingTokenBalance, findTokenDataFromChains, isUsdtWithdrawDirect, parseUnits } from './chunk-
|
|
2
|
+
export { tryAutoReconnect } from './chunk-LOJTP47I.js';
|
|
3
|
+
export { createDepositController, createFundingWithdrawExecutor, createMarketDataProvider, createPredicateMarketPolicyAdapter, createWithdrawController, fetchErc20Balance, fetchFundingTokenBalance, findTokenDataFromChains, isUsdtWithdrawDirect, parseUnits } from './chunk-IUBVUCWJ.js';
|
|
4
4
|
export { ClientIds, DEFAULT_FUNDING_CHAIN_ID, DEFAULT_FUNDING_TOKEN_ADDRESS, getChainInfo, getFundingTokenAddress } from './chunk-F2UPP3YC.js';
|
|
5
5
|
export { DepositDetailsPanel, DepositModal, DropdownField, SignInModal, Toast, WalletAccount, WalletSelectionModal, WithdrawModal, clearSocialAccountInstance } from './chunk-SZYGIQT3.js';
|
|
6
6
|
export { getExplorerUrl } from './chunk-XB2DFS2W.js';
|
|
7
7
|
export { configureMerchantApi, createOrder, getChains, getDepositOrder, getMerchantApiClient, getWithdrawOrder, quote, registerPlatform } from './chunk-TPMI3XWV.js';
|
|
8
|
-
|
|
9
|
-
export { getFixedAuthConfig, getSDKConfig, initSDK } from './chunk-F3HQRJID.js';
|
|
8
|
+
export { getFixedAuthConfig, getSDKConfig, initSDK } from './chunk-JFRRJXOJ.js';
|
|
10
9
|
export { getEnv } from './chunk-SHLNBZBY.js';
|
|
11
10
|
import './chunk-6YQEHB6P.js';
|
|
12
11
|
import './chunk-WHTI52FI.js';
|
package/dist/merchant.d.ts
CHANGED
|
@@ -102,6 +102,20 @@ interface FundingTokenBalanceOptions {
|
|
|
102
102
|
*/
|
|
103
103
|
declare function fetchFundingTokenBalance(walletAddress: string, options?: FundingTokenBalanceOptions): Promise<Erc20BalanceResult>;
|
|
104
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
|
+
}
|
|
105
119
|
interface WithdrawRequest {
|
|
106
120
|
/** 用户收款地址(目标链) */
|
|
107
121
|
toAddress: string;
|
|
@@ -109,16 +123,20 @@ interface WithdrawRequest {
|
|
|
109
123
|
amount: string;
|
|
110
124
|
/** 目标链代币 symbol,如 "USDT" */
|
|
111
125
|
token: string;
|
|
126
|
+
/** 目标链代币地址 */
|
|
127
|
+
tokenAddress: string;
|
|
112
128
|
/** 目标链 chain_id */
|
|
113
129
|
chain: string;
|
|
114
130
|
}
|
|
115
131
|
interface WithdrawResult {
|
|
116
|
-
/**
|
|
117
|
-
|
|
132
|
+
/** 调用方需要执行的链上转账参数 */
|
|
133
|
+
txRequest: WithdrawTxRequest;
|
|
118
134
|
/** 提现订单 ID,用于轮询 getWithdrawOrder(orderId) */
|
|
119
|
-
orderId
|
|
135
|
+
orderId?: string;
|
|
120
136
|
/** 广播 funding tx 的链 id,用于构建 explorer 链接 */
|
|
121
137
|
fundingChainId?: string;
|
|
138
|
+
/** direct: 直接提币;cross_chain: 创建订单后向 one-time address 打款 */
|
|
139
|
+
withdrawMode: "direct" | "cross_chain";
|
|
122
140
|
}
|
|
123
141
|
/**
|
|
124
142
|
* A function that executes a withdraw operation.
|
|
@@ -154,8 +172,9 @@ interface FundingWithdrawExecutorOptions {
|
|
|
154
172
|
/**
|
|
155
173
|
* Factory that returns a `WithdrawExecutor` implementing the flow in withdraw.md:
|
|
156
174
|
* 1) Create NATIVE_SWAP order → get one-time wallet address (OTW);
|
|
157
|
-
* 2)
|
|
158
|
-
* 3)
|
|
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).
|
|
159
178
|
*/
|
|
160
179
|
declare function createFundingWithdrawExecutor(options?: FundingWithdrawExecutorOptions): WithdrawExecutor;
|
|
161
180
|
|
|
@@ -184,4 +203,4 @@ declare const createPredicateMarketPolicyAdapter: (options?: PredicateMarketPoli
|
|
|
184
203
|
trade(chain: SupportedChain, capabilities?: WalletCapability[]): SessionCapabilityPolicy;
|
|
185
204
|
};
|
|
186
205
|
|
|
187
|
-
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, createDepositController, createFundingWithdrawExecutor, createMarketDataProvider, createPredicateMarketPolicyAdapter, createWithdrawController, fetchErc20Balance, fetchFundingTokenBalance, findTokenDataFromChains, isUsdtWithdrawDirect, parseUnits };
|
|
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
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export { createDepositController, createFundingWithdrawExecutor, createMarketDataProvider, createPredicateMarketPolicyAdapter, createWithdrawController, fetchErc20Balance, fetchFundingTokenBalance, findTokenDataFromChains, isUsdtWithdrawDirect, parseUnits } from './chunk-
|
|
1
|
+
export { createDepositController, createFundingWithdrawExecutor, createMarketDataProvider, createPredicateMarketPolicyAdapter, createWithdrawController, fetchErc20Balance, fetchFundingTokenBalance, findTokenDataFromChains, isUsdtWithdrawDirect, parseUnits } from './chunk-IUBVUCWJ.js';
|
|
2
2
|
import './chunk-F2UPP3YC.js';
|
|
3
3
|
export { configureMerchantApi, createOrder, getChains, getDepositOrder, getMerchantApiClient, getWithdrawOrder, quote, registerPlatform } from './chunk-TPMI3XWV.js';
|
|
4
|
-
import './chunk-26RFAFJG.js';
|
|
5
|
-
import './chunk-F3HQRJID.js';
|
|
6
4
|
import './chunk-SHLNBZBY.js';
|
|
7
|
-
import './chunk-WHTI52FI.js';
|
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/**/*",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"axios": "^1.13.6",
|
|
40
40
|
"qrcode-generator": "^2.0.4",
|
|
41
41
|
"viem": "2.21.54",
|
|
42
|
-
"@ab-org/sdk-core": "0.
|
|
42
|
+
"@ab-org/sdk-core": "0.2.2-beta.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"react": ">=18"
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"@types/react": "^18.2.66",
|
|
49
49
|
"typescript": "^5.5.4",
|
|
50
50
|
"tsup": "^8.5.1",
|
|
51
|
-
"@ab-org/chains-service": "0.0.8",
|
|
52
51
|
"@ab-org/oidc-auth": "0.0.16",
|
|
52
|
+
"@ab-org/chains-service": "0.0.8",
|
|
53
53
|
"@ab-org/sign-in-sdk": "0.1.0",
|
|
54
54
|
"@ab-org/wallet-utils": "0.0.7"
|
|
55
55
|
},
|