@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 CHANGED
@@ -11,12 +11,42 @@ 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
+ Withdraw migration notes for existing integrators: `./MIGRATION.md`
48
+
49
+
20
50
  ## Quick start
21
51
  ```tsx
22
52
  import {
@@ -26,13 +56,15 @@ import {
26
56
  createWalletConnectController,
27
57
  createWalletExecutionController,
28
58
  } from "@ab-org/sdk-core";
59
+ import {
60
+ type CustodyAdapter,
61
+ } from "@ab-org/predicate-market-sdk";
29
62
  import {
30
63
  createDepositController,
31
64
  createWithdrawController,
32
65
  createMarketDataProvider,
33
66
  createPredicateMarketPolicyAdapter,
34
- type CustodyAdapter,
35
- } from "@ab-org/predicate-market-sdk";
67
+ } from "@ab-org/predicate-market-sdk/merchant";
36
68
 
37
69
  declare const custodyAdapter: CustodyAdapter;
38
70
 
@@ -67,10 +99,11 @@ const policy = createPredicateMarketPolicyAdapter({
67
99
 
68
100
  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
101
 
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 the session provider.
102
+ **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
103
 
72
104
  ```tsx
73
- import { initSDK, SignInModal } from "@ab-org/predicate-market-sdk";
105
+ import { initSDK } from "@ab-org/predicate-market-sdk";
106
+ import { SignInModal } from "@ab-org/predicate-market-sdk/react";
74
107
 
75
108
  initSDK({
76
109
  // Optional: only used by other Twitter flows; SignInModal X login uses /relay/x on RELAY_ORIGIN
@@ -89,6 +122,8 @@ initSDK({
89
122
  },
90
123
  });
91
124
 
125
+ - 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.
126
+
92
127
  <SignInModal />;
93
128
  ```
94
129
 
@@ -101,7 +136,7 @@ Rules:
101
136
  - **`getFundingTokenAddress(chainId?)`** — same optional **`chainId`** as **`getChainInfo`**. If **`NEXT_PUBLIC_FUNDING_TOKEN_ADDRESS`** / **`FUNDING_TOKEN_ADDRESS`** or legacy defaultFundingTokenAddress`**.
102
137
  - **`DEFAULT_FUNDING_TOKEN_ADDRESS`** — shorthand for **`getChainInfo().defaultFundingTokenAddress`** (default funding chain **`3131`**).
103
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).
104
- - **`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.
105
140
 
106
141
  **Type note:** **`EvmChainInfo`** includes **`defaultFundingTokenAddress`**. If you construct chain objects manually in TypeScript, add that field or use **`getChainInfo`** instead of literals.
107
142
  - `socialProviders: undefined` uses built-in defaults (`google`, `x`)
@@ -112,7 +147,7 @@ Rules:
112
147
  - known wallet ids automatically reuse built-in metadata like `installUrl` and detected `installed` state unless you override them
113
148
  - component props still override `initSDK({ signIn })` on a per-modal basis
114
149
 
115
- The package still **exports** `signInWithGoogle` (Google Identity Services, optional FedCM) for **custom** integrations; the built-in **`SignInModal`** does **not** use it for Google.
150
+ Note: Use the built-in OIDC relay flow via `SignInModal` for Google/X.
116
151
 
117
152
  ## Address & balance
118
153
  ```tsx
@@ -162,7 +197,7 @@ const quote = await withdraw.fetchQuote("USDT", "ETH", "200");
162
197
  Replace `createMarketDataProvider()` with your own implementation:
163
198
 
164
199
  ```ts
165
- import type { MarketDataProvider } from "@ab-org/predicate-market-sdk";
200
+ import type { MarketDataProvider } from "@ab-org/predicate-market-sdk/merchant";
166
201
 
167
202
  const realMarketData: MarketDataProvider = {
168
203
  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,33 @@
1
+ import { getSDKConfig } from './chunk-JFRRJXOJ.js';
2
+ import './chunk-SHLNBZBY.js';
3
+ import './chunk-WHTI52FI.js';
4
+ import { sessionStore, createDefaultInjectedWalletRegistry, WalletConnector } from '@ab-org/sdk-core';
5
+ import { CubistSocialProvider } from '@ab-org/sdk-core/social/provider';
6
+
7
+ var pending = null;
8
+ function tryAutoReconnect() {
9
+ const session = sessionStore.getState().session;
10
+ if (!session) return Promise.resolve(null);
11
+ if (pending) return pending;
12
+ pending = doAutoReconnect().finally(() => {
13
+ pending = null;
14
+ });
15
+ return pending;
16
+ }
17
+ async function doAutoReconnect() {
18
+ const config = getSDKConfig();
19
+ const registry = createDefaultInjectedWalletRegistry();
20
+ const adapters = [...registry.map((r) => r.provider)];
21
+ if (config.cubeSigner) {
22
+ adapters.push(
23
+ new CubistSocialProvider({
24
+ ...config.cubeSigner,
25
+ defaultSessionPolicy: config.signIn?.sessionPolicy ?? config.cubeSigner.defaultSessionPolicy
26
+ })
27
+ );
28
+ }
29
+ const connector = new WalletConnector(adapters);
30
+ return connector.tryAutoReconnect();
31
+ }
32
+
33
+ export { tryAutoReconnect };
@@ -0,0 +1,14 @@
1
+ import { getEnv, getChainInfo } from './chunk-YX56ZGDB.js';
2
+
3
+ // ../sign_in_sdk/src/config.ts
4
+ var stage = getEnv("STAGE") || "dev";
5
+ var clientIds = {
6
+ google: getEnv("GOOGLE_CLIENT_ID"),
7
+ x: getEnv("X_CLIENT_ID")
8
+ };
9
+ var chainConfig = {
10
+ chainType: "evm",
11
+ chainId: getChainInfo().chainId
12
+ };
13
+
14
+ export { chainConfig, clientIds, stage };
@@ -0,0 +1,88 @@
1
+ import { getEnv } from './chunk-SHLNBZBY.js';
2
+
3
+ // src/constants/chains.ts
4
+ var TENDERLY_BSC_3131 = {
5
+ chainId: "3131",
6
+ name: "BSC_TENDERLY",
7
+ chainName: "BSC_TENDERLY",
8
+ nativeCurrencyName: "BSC",
9
+ nativeCurrencySymbol: "BSC",
10
+ nativeCurrencyDecimals: 18,
11
+ rpcUrls: [
12
+ "https://virtual.binance.eu.rpc.tenderly.co/e643ea28-32eb-4fb9-8116-90be24f7defa"
13
+ ],
14
+ blockExplorerUrl: "https://dashboard.tenderly.co/explorer/vnet/6593bc72-f548-497d-bff9-5be061436a48",
15
+ platformType: "EVM",
16
+ icon: "https://static.tomo.inc/token/bsc_new.svg",
17
+ defaultFundingTokenAddress: "0x55d398326f99059fF775485246999027B3197955"
18
+ };
19
+ var BSC_MAINNET_56 = {
20
+ chainId: "56",
21
+ name: "BSC",
22
+ chainName: "BNB Smart Chain",
23
+ nativeCurrencyName: "BNB",
24
+ nativeCurrencySymbol: "BNB",
25
+ nativeCurrencyDecimals: 18,
26
+ rpcUrls: ["https://bsc-dataseed.binance.org", "https://bsc-dataseed1.defibit.io"],
27
+ blockExplorerUrl: "https://bscscan.com",
28
+ platformType: "EVM",
29
+ icon: "https://static.tomo.inc/token/bsc_new.svg",
30
+ defaultFundingTokenAddress: "0x55d398326f99059fF775485246999027B3197955"
31
+ };
32
+ var CHAIN_REGISTRY = {
33
+ [TENDERLY_BSC_3131.chainId]: TENDERLY_BSC_3131,
34
+ [BSC_MAINNET_56.chainId]: BSC_MAINNET_56
35
+ };
36
+ var DEFAULT_FUNDING_CHAIN_ID = getEnv("FUNDING_CHAIN_ID") || "3131";
37
+ function normalizeFundingChainId(chainId) {
38
+ if (chainId === void 0 || chainId === null) return DEFAULT_FUNDING_CHAIN_ID;
39
+ const normalized = String(chainId).trim();
40
+ return normalized === "" ? DEFAULT_FUNDING_CHAIN_ID : normalized;
41
+ }
42
+ function getChainInfo(chainId) {
43
+ const id = normalizeFundingChainId(chainId);
44
+ const info = CHAIN_REGISTRY[id];
45
+ if (!info) {
46
+ throw new Error(
47
+ `Unsupported funding chainId "${id}". Supported: ${Object.keys(CHAIN_REGISTRY).sort().join(", ")}`
48
+ );
49
+ }
50
+ return info;
51
+ }
52
+ function pickEnvFundingTokenAddress() {
53
+ const candidates = [["NEXT_PUBLIC_FUNDING_TOKEN_ADDRESS", "FUNDING_TOKEN_ADDRESS"]];
54
+ const processEnv = globalThis.process?.env;
55
+ if (processEnv) {
56
+ for (const [pub, priv] of candidates) {
57
+ const publicValue = processEnv[pub];
58
+ const privateValue = processEnv[priv];
59
+ if (publicValue != null && publicValue !== "") return publicValue;
60
+ if (privateValue != null && privateValue !== "") return privateValue;
61
+ }
62
+ }
63
+ try {
64
+ const metaEnv = import.meta.env;
65
+ if (metaEnv) {
66
+ for (const [pub, priv] of candidates) {
67
+ const publicValue = metaEnv[pub];
68
+ const privateValue = metaEnv[priv];
69
+ if (publicValue != null && publicValue !== "") return publicValue;
70
+ if (privateValue != null && privateValue !== "") return privateValue;
71
+ }
72
+ }
73
+ } catch {
74
+ }
75
+ return void 0;
76
+ }
77
+ function getFundingTokenAddress(chainId) {
78
+ const fromEnv = pickEnvFundingTokenAddress();
79
+ if (fromEnv && /^0x[0-9a-fA-F]{40}$/.test(fromEnv)) return fromEnv;
80
+ return getChainInfo(chainId).defaultFundingTokenAddress;
81
+ }
82
+ var DEFAULT_FUNDING_TOKEN_ADDRESS = getFundingTokenAddress(DEFAULT_FUNDING_CHAIN_ID);
83
+ var ClientIds = {
84
+ google: getEnv("GOOGLE_CLIENT_ID"),
85
+ x: getEnv("X_CLIENT_ID")
86
+ };
87
+
88
+ export { ClientIds, DEFAULT_FUNDING_CHAIN_ID, DEFAULT_FUNDING_TOKEN_ADDRESS, getChainInfo, getFundingTokenAddress };