@ab-org/predicate-market-sdk 2.0.0 → 2.0.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 +39 -6
- 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-6YV7YSSL.js +4 -0
- package/dist/chunk-26RFAFJG.js +31 -0
- package/dist/chunk-66CHMJG7.js +527 -0
- package/dist/chunk-6YQEHB6P.js +14 -0
- package/dist/chunk-C5BV2OG7.js +6 -0
- package/dist/chunk-F2UPP3YC.js +88 -0
- package/dist/chunk-F3HQRJID.js +149 -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 +13 -43009
- package/dist/merchant.d.ts +187 -0
- package/dist/merchant.js +7 -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
package/README.md
CHANGED
|
@@ -11,12 +11,40 @@ Prediction-market specific helpers built on top of `@ab-org/sdk-core`.
|
|
|
11
11
|
- **Dynamic token & chain lists** via `MarketDataProvider` (backend-driven, mock included)
|
|
12
12
|
- **Quote / slippage API** — fetch real-time pricing before confirming deposit or withdraw
|
|
13
13
|
- Predicate-market policy adapter for deposit / withdraw / trade flows
|
|
14
|
+
- Social login bridge now uses `@ab-org/sdk-core` + CubeSigner EVM session helpers, so the main React entry no longer statically pulls in the legacy multi-chain `cubist-sig-sdk` bundle
|
|
14
15
|
|
|
15
16
|
## Installation
|
|
16
17
|
```bash
|
|
17
18
|
npm install @ab-org/sdk-core @ab-org/predicate-market-sdk
|
|
18
19
|
```
|
|
19
20
|
|
|
21
|
+
## Migration guide
|
|
22
|
+
|
|
23
|
+
`@ab-org/predicate-market-sdk@2` adds narrower entrypoints while keeping the legacy root import compatible:
|
|
24
|
+
|
|
25
|
+
- `@ab-org/predicate-market-sdk` remains the compatibility root entry.
|
|
26
|
+
- `@ab-org/predicate-market-sdk/react` for `SignInModal`, `DepositModal`, and `WithdrawModal`.
|
|
27
|
+
- `@ab-org/predicate-market-sdk/auth` for auth helpers such as `notifyTwitterCallback`.
|
|
28
|
+
- `@ab-org/predicate-market-sdk/merchant` for merchant APIs, market-data helpers, and controller factories.
|
|
29
|
+
|
|
30
|
+
If you want leaner bundle graphs in new code, migrate imports like this:
|
|
31
|
+
|
|
32
|
+
| Before | After |
|
|
33
|
+
|-------|-------|
|
|
34
|
+
| `SignInModal`, `DepositModal`, `WithdrawModal` from `@ab-org/predicate-market-sdk` | `@ab-org/predicate-market-sdk/react` |
|
|
35
|
+
| `notifyTwitterCallback` from `@ab-org/predicate-market-sdk` | `@ab-org/predicate-market-sdk/auth` |
|
|
36
|
+
| `createMarketDataProvider`, `registerPlatform`, `createFundingWithdrawExecutor`, `createDepositController`, `createWithdrawController` from `@ab-org/predicate-market-sdk` | `@ab-org/predicate-market-sdk/merchant` |
|
|
37
|
+
|
|
38
|
+
Why the split:
|
|
39
|
+
|
|
40
|
+
- Root import stays compatible for old consumers.
|
|
41
|
+
- Merchant runtime config is lazy, so importing the SDK no longer fails just because `MERCHANT_BASE_URL` is missing.
|
|
42
|
+
- Pages that only need auth helpers or core helpers no longer pull in the React and merchant bundles by accident.
|
|
43
|
+
- Current packages are meant to work with default Next.js and Vite setups, without custom `next.config.js` or `vite.config.ts` just to import the SDK.
|
|
44
|
+
|
|
45
|
+
Upgrade notes are summarized in `docs/pages/index.mdx` under “Upgrading from legacy root exports”.
|
|
46
|
+
|
|
47
|
+
|
|
20
48
|
## Quick start
|
|
21
49
|
```tsx
|
|
22
50
|
import {
|
|
@@ -26,13 +54,15 @@ import {
|
|
|
26
54
|
createWalletConnectController,
|
|
27
55
|
createWalletExecutionController,
|
|
28
56
|
} from "@ab-org/sdk-core";
|
|
57
|
+
import {
|
|
58
|
+
type CustodyAdapter,
|
|
59
|
+
} from "@ab-org/predicate-market-sdk";
|
|
29
60
|
import {
|
|
30
61
|
createDepositController,
|
|
31
62
|
createWithdrawController,
|
|
32
63
|
createMarketDataProvider,
|
|
33
64
|
createPredicateMarketPolicyAdapter,
|
|
34
|
-
|
|
35
|
-
} from "@ab-org/predicate-market-sdk";
|
|
65
|
+
} from "@ab-org/predicate-market-sdk/merchant";
|
|
36
66
|
|
|
37
67
|
declare const custodyAdapter: CustodyAdapter;
|
|
38
68
|
|
|
@@ -67,10 +97,11 @@ const policy = createPredicateMarketPolicyAdapter({
|
|
|
67
97
|
|
|
68
98
|
The SDK ships with **bundled auth config** (Google client id, Twitter client id, CubeSigner env/org) so you can call `initSDK` with only `signIn`. Override via env (`NEXT_PUBLIC_*`) or by passing options to `initSDK`.
|
|
69
99
|
|
|
70
|
-
**Google / X in `SignInModal`** use the SDK's **bundled OIDC relay auth**: a **popup** opens your **`NEXT_PUBLIC_RELAY_ORIGIN`** routes **`/relay/google`** and **`/relay/x`**, then the SDK's built-in **WalletAccount** bridge turns the returned OIDC token into
|
|
100
|
+
**Google / X in `SignInModal`** use the SDK's **bundled OIDC relay auth**: a **popup** opens your **`NEXT_PUBLIC_RELAY_ORIGIN`** routes **`/relay/google`** and **`/relay/x`**, then the SDK's built-in **WalletAccount** bridge turns the returned OIDC token into a CubeSigner-backed EVM session provider.
|
|
71
101
|
|
|
72
102
|
```tsx
|
|
73
|
-
import { initSDK
|
|
103
|
+
import { initSDK } from "@ab-org/predicate-market-sdk";
|
|
104
|
+
import { SignInModal } from "@ab-org/predicate-market-sdk/react";
|
|
74
105
|
|
|
75
106
|
initSDK({
|
|
76
107
|
// Optional: only used by other Twitter flows; SignInModal X login uses /relay/x on RELAY_ORIGIN
|
|
@@ -89,6 +120,8 @@ initSDK({
|
|
|
89
120
|
},
|
|
90
121
|
});
|
|
91
122
|
|
|
123
|
+
- Auto registration: when `NEXT_PUBLIC_CUBE_REG` (or `CUBE_REG`) is set and you do not pass a custom `registerUser`, the SDK automatically registers a new OIDC user on first login (prove → signed payload → POST `CUBE_REG`) before creating the CubeSigner session.
|
|
124
|
+
|
|
92
125
|
<SignInModal />;
|
|
93
126
|
```
|
|
94
127
|
|
|
@@ -112,7 +145,7 @@ Rules:
|
|
|
112
145
|
- known wallet ids automatically reuse built-in metadata like `installUrl` and detected `installed` state unless you override them
|
|
113
146
|
- component props still override `initSDK({ signIn })` on a per-modal basis
|
|
114
147
|
|
|
115
|
-
|
|
148
|
+
Note: Use the built-in OIDC relay flow via `SignInModal` for Google/X.
|
|
116
149
|
|
|
117
150
|
## Address & balance
|
|
118
151
|
```tsx
|
|
@@ -162,7 +195,7 @@ const quote = await withdraw.fetchQuote("USDT", "ETH", "200");
|
|
|
162
195
|
Replace `createMarketDataProvider()` with your own implementation:
|
|
163
196
|
|
|
164
197
|
```ts
|
|
165
|
-
import type { MarketDataProvider } from "@ab-org/predicate-market-sdk";
|
|
198
|
+
import type { MarketDataProvider } from "@ab-org/predicate-market-sdk/merchant";
|
|
166
199
|
|
|
167
200
|
const realMarketData: MarketDataProvider = {
|
|
168
201
|
async getSupportedTokens(direction) {
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { chainConfig } from './chunk-6YQEHB6P.js';
|
|
2
|
+
import { getSDKConfig } from './chunk-WHTI52FI.js';
|
|
3
|
+
import { getChainInfo } from './chunk-YX56ZGDB.js';
|
|
4
|
+
import { sessionStore, getSupportedChainFromEvmChainId } from '@ab-org/sdk-core';
|
|
5
|
+
import { CubeSignerAuth, createCubistEvmWalletProvider } from '@ab-org/sdk-core/social/auth';
|
|
6
|
+
|
|
7
|
+
function resolveCubeSignerConfig() {
|
|
8
|
+
const cubeSigner = getSDKConfig().cubeSigner;
|
|
9
|
+
if (!cubeSigner) {
|
|
10
|
+
throw new Error("cubeSigner config is required. Call initSDK({ cubeSigner: { env, orgId } }) first.");
|
|
11
|
+
}
|
|
12
|
+
return cubeSigner;
|
|
13
|
+
}
|
|
14
|
+
function resolveDefaultChain() {
|
|
15
|
+
try {
|
|
16
|
+
return getSupportedChainFromEvmChainId(chainConfig.chainId);
|
|
17
|
+
} catch {
|
|
18
|
+
return "BSC";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function resolveRpcChainId(chain) {
|
|
22
|
+
switch (chain) {
|
|
23
|
+
case "BSC":
|
|
24
|
+
return "56";
|
|
25
|
+
case "BSC_TENDERLY":
|
|
26
|
+
return "3131";
|
|
27
|
+
default:
|
|
28
|
+
throw new Error(`Read-only RPC methods are not configured for chain ${chain}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function resolveRpcUrl(chain) {
|
|
32
|
+
return getChainInfo(resolveRpcChainId(chain)).rpcUrls[0];
|
|
33
|
+
}
|
|
34
|
+
async function resolveEvmAddress(session) {
|
|
35
|
+
const keys = await session.client.sessionKeys();
|
|
36
|
+
const evmKey = keys.find((key) => key.cached.key_type === "SecpEthAddr");
|
|
37
|
+
if (!evmKey) {
|
|
38
|
+
throw new Error("No EVM key found in CubeSigner session");
|
|
39
|
+
}
|
|
40
|
+
return evmKey.materialId;
|
|
41
|
+
}
|
|
42
|
+
var CubistWalletAccount = class {
|
|
43
|
+
constructor(auth, cubeSignerSession, address, chain) {
|
|
44
|
+
this.auth = auth;
|
|
45
|
+
this.cubeSignerSession = cubeSignerSession;
|
|
46
|
+
this.address = address;
|
|
47
|
+
this.chain = chain;
|
|
48
|
+
this.provider = this.createProvider(chain);
|
|
49
|
+
}
|
|
50
|
+
createProvider(chain) {
|
|
51
|
+
return createCubistEvmWalletProvider({
|
|
52
|
+
session: this.cubeSignerSession,
|
|
53
|
+
address: this.address,
|
|
54
|
+
chain
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
assertCurrentAddress(address) {
|
|
58
|
+
if (address.toLowerCase() !== this.address.toLowerCase()) {
|
|
59
|
+
throw new Error("address is not the current account");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async rpcRequest(method, params) {
|
|
63
|
+
const response = await fetch(resolveRpcUrl(this.chain), {
|
|
64
|
+
method: "POST",
|
|
65
|
+
headers: { "Content-Type": "application/json" },
|
|
66
|
+
body: JSON.stringify({
|
|
67
|
+
id: Date.now(),
|
|
68
|
+
jsonrpc: "2.0",
|
|
69
|
+
method,
|
|
70
|
+
params
|
|
71
|
+
})
|
|
72
|
+
});
|
|
73
|
+
if (!response.ok) {
|
|
74
|
+
throw new Error(`RPC request failed (${response.status})`);
|
|
75
|
+
}
|
|
76
|
+
const payload = await response.json();
|
|
77
|
+
if (payload.error) {
|
|
78
|
+
throw new Error(payload.error.message ?? `RPC request failed for ${method}`);
|
|
79
|
+
}
|
|
80
|
+
return payload.result;
|
|
81
|
+
}
|
|
82
|
+
getCubeSignerSession() {
|
|
83
|
+
return this.cubeSignerSession;
|
|
84
|
+
}
|
|
85
|
+
async request(payload) {
|
|
86
|
+
const params = payload.params ?? [];
|
|
87
|
+
switch (payload.method) {
|
|
88
|
+
case "wallet_switchEthereumChain":
|
|
89
|
+
return await this.wallet_switchEthereumChain(
|
|
90
|
+
params
|
|
91
|
+
);
|
|
92
|
+
case "eth_getBalance":
|
|
93
|
+
return await this.eth_getBalance(params);
|
|
94
|
+
case "eth_getTransactionCount":
|
|
95
|
+
return await this.eth_getTransactionCount(
|
|
96
|
+
params
|
|
97
|
+
);
|
|
98
|
+
default:
|
|
99
|
+
return this.provider.request(payload);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async eth_accounts() {
|
|
103
|
+
return this.provider.request({ method: "eth_accounts" });
|
|
104
|
+
}
|
|
105
|
+
async eth_requestAccounts() {
|
|
106
|
+
return this.provider.request({ method: "eth_requestAccounts" });
|
|
107
|
+
}
|
|
108
|
+
async eth_chainId() {
|
|
109
|
+
return this.provider.request({ method: "eth_chainId" });
|
|
110
|
+
}
|
|
111
|
+
async wallet_switchEthereumChain(networks) {
|
|
112
|
+
const nextChainId = networks[0]?.chainId;
|
|
113
|
+
if (nextChainId === void 0) {
|
|
114
|
+
throw new Error("chainId is required");
|
|
115
|
+
}
|
|
116
|
+
this.chain = getSupportedChainFromEvmChainId(nextChainId);
|
|
117
|
+
this.provider = this.createProvider(this.chain);
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
async eth_getBalance([address, blockTag]) {
|
|
121
|
+
this.assertCurrentAddress(address);
|
|
122
|
+
if (blockTag !== "latest") {
|
|
123
|
+
throw new Error("type is not supported");
|
|
124
|
+
}
|
|
125
|
+
const balanceHex = await this.rpcRequest("eth_getBalance", [
|
|
126
|
+
address,
|
|
127
|
+
blockTag
|
|
128
|
+
]);
|
|
129
|
+
return BigInt(balanceHex).toString();
|
|
130
|
+
}
|
|
131
|
+
async eth_getTransactionCount([address, blockTag]) {
|
|
132
|
+
this.assertCurrentAddress(address);
|
|
133
|
+
if (blockTag !== "latest" && blockTag !== "pending") {
|
|
134
|
+
throw new Error("type is not supported");
|
|
135
|
+
}
|
|
136
|
+
const nonceHex = await this.rpcRequest(
|
|
137
|
+
"eth_getTransactionCount",
|
|
138
|
+
[address, blockTag]
|
|
139
|
+
);
|
|
140
|
+
return Number(BigInt(nonceHex));
|
|
141
|
+
}
|
|
142
|
+
async personal_sign(params) {
|
|
143
|
+
return this.provider.request({
|
|
144
|
+
method: "personal_sign",
|
|
145
|
+
params
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
async eth_signTypedData_v4(params) {
|
|
149
|
+
return this.provider.request({
|
|
150
|
+
method: "eth_signTypedData_v4",
|
|
151
|
+
params
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
async eth_signTransaction(params) {
|
|
155
|
+
return this.provider.request({
|
|
156
|
+
method: "eth_signTransaction",
|
|
157
|
+
params
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
async disconnect() {
|
|
161
|
+
await this.provider.disconnect();
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
var _WalletAccount = class _WalletAccount {
|
|
165
|
+
/** Clear cached instance so next login creates a fresh CubeSigner session. */
|
|
166
|
+
static clearInstance() {
|
|
167
|
+
const current = _WalletAccount.instance;
|
|
168
|
+
_WalletAccount.instance = null;
|
|
169
|
+
_WalletAccount.instanceToken = null;
|
|
170
|
+
void current?.disconnect().catch(() => {
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
static async getInstance(oidcToken) {
|
|
174
|
+
if (_WalletAccount.instance && _WalletAccount.instanceToken === oidcToken) {
|
|
175
|
+
return _WalletAccount.instance;
|
|
176
|
+
}
|
|
177
|
+
if (_WalletAccount.instance) {
|
|
178
|
+
_WalletAccount.clearInstance();
|
|
179
|
+
}
|
|
180
|
+
const auth = new CubeSignerAuth(resolveCubeSignerConfig());
|
|
181
|
+
const cubeSignerSession = await auth.loginWithOidcToken(oidcToken);
|
|
182
|
+
const address = await resolveEvmAddress(cubeSignerSession);
|
|
183
|
+
const walletAccount = new CubistWalletAccount(
|
|
184
|
+
auth,
|
|
185
|
+
cubeSignerSession,
|
|
186
|
+
address,
|
|
187
|
+
resolveDefaultChain()
|
|
188
|
+
);
|
|
189
|
+
_WalletAccount.instance = walletAccount;
|
|
190
|
+
_WalletAccount.instanceToken = oidcToken;
|
|
191
|
+
return walletAccount;
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
_WalletAccount.instance = null;
|
|
195
|
+
_WalletAccount.instanceToken = null;
|
|
196
|
+
var WalletAccount = _WalletAccount;
|
|
197
|
+
function clearSocialAccountInstance() {
|
|
198
|
+
WalletAccount.clearInstance();
|
|
199
|
+
try {
|
|
200
|
+
const storage = typeof localStorage !== "undefined" ? localStorage : null;
|
|
201
|
+
const adapterId = storage?.getItem("ab:wallet:adapterId");
|
|
202
|
+
const session = sessionStore.getState().session;
|
|
203
|
+
const isSocialSession = session?.walletType === "social" || session?.authSource === "google" || session?.authSource === "twitter" || adapterId === "cubist";
|
|
204
|
+
if (!isSocialSession) return;
|
|
205
|
+
sessionStore.clearSession();
|
|
206
|
+
storage?.removeItem("ab:wallet:session");
|
|
207
|
+
storage?.removeItem("ab:wallet:adapterId");
|
|
208
|
+
} catch {
|
|
209
|
+
sessionStore.clearSession();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export { clearSocialAccountInstance, WalletAccount as default };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Merchant API client
|
|
5
|
+
* 基于 axios 封装,类型与文档一致。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** 通用 API 响应:所有接口统一格式 */
|
|
9
|
+
interface ApiResponse<T> {
|
|
10
|
+
data: T | null;
|
|
11
|
+
code: number;
|
|
12
|
+
msg: string;
|
|
13
|
+
timestamp: number;
|
|
14
|
+
}
|
|
15
|
+
interface TokenData {
|
|
16
|
+
symbol: string;
|
|
17
|
+
address: string;
|
|
18
|
+
decimals: number;
|
|
19
|
+
/** 最小充值量(最小单位字符串,如 `"15000000"`) */
|
|
20
|
+
minimum_deposit?: string;
|
|
21
|
+
/** 是否为 USD 类稳定币 */
|
|
22
|
+
is_usd_stable?: boolean;
|
|
23
|
+
}
|
|
24
|
+
interface ChainData {
|
|
25
|
+
chain_id: string;
|
|
26
|
+
network: string;
|
|
27
|
+
tokens: TokenData[];
|
|
28
|
+
}
|
|
29
|
+
interface ChainsResponseData {
|
|
30
|
+
chains: ChainData[];
|
|
31
|
+
is_testnet: boolean;
|
|
32
|
+
}
|
|
33
|
+
interface PlatformRegisterRequest {
|
|
34
|
+
platform_contract_address: string;
|
|
35
|
+
chain_id: string;
|
|
36
|
+
}
|
|
37
|
+
interface PlatformRegisterResponseData {
|
|
38
|
+
deposit_address: string;
|
|
39
|
+
chain_id: string;
|
|
40
|
+
}
|
|
41
|
+
type QuoteDirection = "deposit" | "withdraw";
|
|
42
|
+
interface QuoteRequest {
|
|
43
|
+
direction: QuoteDirection;
|
|
44
|
+
chain_id: string;
|
|
45
|
+
token_address: string;
|
|
46
|
+
token_amount?: string;
|
|
47
|
+
dst_token_amount?: string;
|
|
48
|
+
}
|
|
49
|
+
interface QuoteResponseData {
|
|
50
|
+
token_address: string;
|
|
51
|
+
token_symbol: string;
|
|
52
|
+
token_decimals: number;
|
|
53
|
+
rate: string;
|
|
54
|
+
chain_id: number;
|
|
55
|
+
deposit_address?: string;
|
|
56
|
+
dst_token_amount?: string;
|
|
57
|
+
token_amount?: string;
|
|
58
|
+
expires_at?: string;
|
|
59
|
+
}
|
|
60
|
+
type DepositOrderStatus = "received" | "processing" | "completed" | "failed" | "funded";
|
|
61
|
+
interface DepositOrderResponseData {
|
|
62
|
+
order_id: string;
|
|
63
|
+
status: DepositOrderStatus;
|
|
64
|
+
source_chain_id: string;
|
|
65
|
+
token_address: string;
|
|
66
|
+
token_amount?: string;
|
|
67
|
+
dst_token_amount?: string;
|
|
68
|
+
deposit_address?: string;
|
|
69
|
+
source_tx_hash?: string;
|
|
70
|
+
created_at?: string;
|
|
71
|
+
updated_at?: string;
|
|
72
|
+
}
|
|
73
|
+
type WithdrawOrderStatus = "pending" | "funded" | "processing" | "completed" | "failed" | "expired";
|
|
74
|
+
interface WithdrawOrderResponseData {
|
|
75
|
+
order_id: string;
|
|
76
|
+
status: WithdrawOrderStatus;
|
|
77
|
+
one_time_address?: string;
|
|
78
|
+
chain_id: string;
|
|
79
|
+
dst_token_amount: string;
|
|
80
|
+
/** Fee (e.g. "0.01 USDT"); only present if backend includes it in GET /api/v1/orders/withdraw/:id. UI falls back to feeDisplay prop or "—". */
|
|
81
|
+
fee?: string;
|
|
82
|
+
target_chain_id: string;
|
|
83
|
+
target_address: string;
|
|
84
|
+
funding_tx_hash?: string;
|
|
85
|
+
dst_tx_hash?: string;
|
|
86
|
+
out_tx_hash?: string;
|
|
87
|
+
created_at?: string;
|
|
88
|
+
updated_at?: string;
|
|
89
|
+
}
|
|
90
|
+
interface NativeSwapPayload {
|
|
91
|
+
chain_id: string;
|
|
92
|
+
token_address: string;
|
|
93
|
+
token_amount: string;
|
|
94
|
+
dst_chain_id: string;
|
|
95
|
+
dst_token_address: string;
|
|
96
|
+
recipient: string;
|
|
97
|
+
}
|
|
98
|
+
interface PaymentPairData {
|
|
99
|
+
token_symbol: string;
|
|
100
|
+
token_amount: string;
|
|
101
|
+
token_address: string;
|
|
102
|
+
user_address: string;
|
|
103
|
+
chain_id: string;
|
|
104
|
+
}
|
|
105
|
+
interface CreateOrderRequest {
|
|
106
|
+
intent_id: string;
|
|
107
|
+
order_type: "NATIVE_SWAP";
|
|
108
|
+
order_payload: NativeSwapPayload;
|
|
109
|
+
payment_pairs: PaymentPairData[];
|
|
110
|
+
}
|
|
111
|
+
type PaymentSessionStatus = "CREATED" | "PENDING" | "FUNDED" | "CANCELED" | "CAPTURING" | "SUCCEED";
|
|
112
|
+
interface PaymentSessionResponseData {
|
|
113
|
+
payment_session_id: string;
|
|
114
|
+
created_at?: string;
|
|
115
|
+
status: PaymentSessionStatus;
|
|
116
|
+
one_time_wallet_address: string;
|
|
117
|
+
amount: string;
|
|
118
|
+
currency: string;
|
|
119
|
+
user_address?: string;
|
|
120
|
+
network?: string;
|
|
121
|
+
token_symbol?: string;
|
|
122
|
+
chain_id?: string;
|
|
123
|
+
funding_transaction_hash?: string | null;
|
|
124
|
+
capturable_amount?: string;
|
|
125
|
+
captured_amount?: string;
|
|
126
|
+
}
|
|
127
|
+
interface CreateOrderResponseData {
|
|
128
|
+
order_id: string;
|
|
129
|
+
payment_sessions: PaymentSessionResponseData[];
|
|
130
|
+
}
|
|
131
|
+
interface MerchantApiConfig {
|
|
132
|
+
baseUrl?: string;
|
|
133
|
+
client?: AxiosInstance;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* 配置 Merchant API 的 baseURL
|
|
137
|
+
*/
|
|
138
|
+
declare function configureMerchantApi(config?: MerchantApiConfig): AxiosInstance;
|
|
139
|
+
/**
|
|
140
|
+
* 获取当前 axios 实例(用于自定义请求)
|
|
141
|
+
*/
|
|
142
|
+
declare function getMerchantApiClient(): AxiosInstance;
|
|
143
|
+
/** GET /chains - 查询支持的链和代币列表 */
|
|
144
|
+
declare function getChains(): Promise<ChainsResponseData>;
|
|
145
|
+
/** POST /api/v1/platform - 注册平台合约并获取充值地址 */
|
|
146
|
+
declare function registerPlatform(body: PlatformRegisterRequest): Promise<PlatformRegisterResponseData>;
|
|
147
|
+
/** POST /api/v1/quote - 统一报价(充值/提现) */
|
|
148
|
+
declare function quote(body: QuoteRequest): Promise<QuoteResponseData>;
|
|
149
|
+
/** GET /api/v1/orders/deposit/{order_id} - 查询充值订单状态 */
|
|
150
|
+
declare function getDepositOrder(orderId: string): Promise<DepositOrderResponseData>;
|
|
151
|
+
/** GET /api/v1/orders/withdraw/{order_id} - 查询提现订单状态 */
|
|
152
|
+
declare function getWithdrawOrder(orderId: string): Promise<WithdrawOrderResponseData>;
|
|
153
|
+
/** POST /order - 创建 NATIVE_SWAP 提现订单 */
|
|
154
|
+
declare function createOrder(body: CreateOrderRequest): Promise<CreateOrderResponseData>;
|
|
155
|
+
|
|
156
|
+
export { type ApiResponse as A, type ChainData as C, type DepositOrderResponseData as D, type MerchantApiConfig as M, type NativeSwapPayload as N, type PaymentPairData as P, type QuoteDirection as Q, type TokenData as T, type WithdrawOrderResponseData as W, type ChainsResponseData as a, type CreateOrderRequest as b, type CreateOrderResponseData as c, type DepositOrderStatus as d, type PaymentSessionResponseData as e, type PaymentSessionStatus as f, type PlatformRegisterRequest as g, type PlatformRegisterResponseData as h, type QuoteResponseData as i, type WithdrawOrderStatus as j, configureMerchantApi as k, createOrder as l, getChains as m, getDepositOrder as n, getMerchantApiClient as o, getWithdrawOrder as p, quote as q, registerPlatform as r };
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { G as GoogleCredential, T as TwitterAuthResult } from './signInTypes-DESvmgWG.js';
|
|
2
|
+
import 'react';
|
|
3
|
+
import '@ab-org/sdk-core';
|
|
4
|
+
|
|
5
|
+
/** Legacy X OAuth popup callback: posts `code` / `state` to `window.opener` and closes. OIDC relay flows do not use this. */
|
|
6
|
+
declare function notifyTwitterCallback(): void;
|
|
7
|
+
|
|
8
|
+
export { notifyTwitterCallback };
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { notifyTwitterCallback } from './chunk-UAXKA6QC.js';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getSDKConfig } from './chunk-F3HQRJID.js';
|
|
2
|
+
import { sessionStore, createDefaultInjectedWalletRegistry, WalletConnector } from '@ab-org/sdk-core';
|
|
3
|
+
import { CubistSocialProvider } from '@ab-org/sdk-core/social/provider';
|
|
4
|
+
|
|
5
|
+
var pending = null;
|
|
6
|
+
function tryAutoReconnect() {
|
|
7
|
+
const session = sessionStore.getState().session;
|
|
8
|
+
if (!session) return Promise.resolve(null);
|
|
9
|
+
if (pending) return pending;
|
|
10
|
+
pending = doAutoReconnect().finally(() => {
|
|
11
|
+
pending = null;
|
|
12
|
+
});
|
|
13
|
+
return pending;
|
|
14
|
+
}
|
|
15
|
+
async function doAutoReconnect() {
|
|
16
|
+
const config = getSDKConfig();
|
|
17
|
+
const registry = createDefaultInjectedWalletRegistry();
|
|
18
|
+
const adapters = [...registry.map((r) => r.provider)];
|
|
19
|
+
if (config.cubeSigner) {
|
|
20
|
+
adapters.push(
|
|
21
|
+
new CubistSocialProvider({
|
|
22
|
+
...config.cubeSigner,
|
|
23
|
+
defaultSessionPolicy: config.signIn?.sessionPolicy ?? config.cubeSigner.defaultSessionPolicy
|
|
24
|
+
})
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
const connector = new WalletConnector(adapters);
|
|
28
|
+
return connector.tryAutoReconnect();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { tryAutoReconnect };
|