@idosgames/wallet 0.1.6 → 0.1.7
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/dist/bridge-BEEkIeZj.d.cts +70 -0
- package/dist/bridge-BzZmMMxK.d.ts +70 -0
- package/dist/chains-DMjdV7VV.d.cts +120 -0
- package/dist/chains-DMjdV7VV.d.ts +120 -0
- package/dist/chunk-ACZSIOFR.js +1 -0
- package/dist/chunk-NDNNLWPS.js +1 -0
- package/dist/chunk-XFMDEOHO.js +2 -0
- package/dist/chunk-ZL42KPPC.js +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +1 -1
- package/dist/react/index.cjs +2 -2
- package/dist/react/index.d.cts +8 -53
- package/dist/react/index.d.ts +8 -53
- package/dist/react/index.js +1 -1
- package/dist/react/solanaIndex.cjs +2 -0
- package/dist/react/solanaIndex.d.cts +93 -0
- package/dist/react/solanaIndex.d.ts +93 -0
- package/dist/react/solanaIndex.js +1 -0
- package/dist/withdraw-DTHssYc9.d.ts +148 -0
- package/dist/withdraw-DgTjKpSf.d.cts +148 -0
- package/package.json +7 -7
- package/dist/bridge-DvafuXl9.d.cts +0 -304
- package/dist/bridge-DvafuXl9.d.ts +0 -304
- package/dist/chunk-ZPNBMRUO.js +0 -2
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
import { Chain, PublicClient, WalletClient, Address, Abi, ContractFunctionName, ContractFunctionArgs, Hex } from 'viem';
|
|
2
|
-
import { IDosGamesClient, BlockchainNetworkDefinition, DepositNFTResponse, DepositTokenResponse, WithdrawalSignatureResponse, NFTWithdrawalResponse, TokenWithdrawalResponse, SolanaWithdrawalSignature } from '@idosgames/core';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Where a multi-step bridge flow stopped. Deposits run approve → deposit-onchain → report;
|
|
6
|
-
* withdrawals run request → withdraw-onchain → confirm. Knowing the stage lets a UI recover
|
|
7
|
-
* correctly (e.g. a failed `withdraw-onchain` after a successful `request` means the asset is
|
|
8
|
-
* already debited — offer `retryWithdrawal`, never a fresh request that would debit twice).
|
|
9
|
-
*/
|
|
10
|
-
type BridgeStage = "approve" | "deposit-onchain" | "report" | "request" | "withdraw-onchain" | "confirm";
|
|
11
|
-
interface BridgeSuccess<T> {
|
|
12
|
-
ok: true;
|
|
13
|
-
/** Hash/signature of the on-chain transaction that moved the asset (EVM hex or Solana base58). */
|
|
14
|
-
onChainTxHash: string;
|
|
15
|
-
/** The core SDK response that finalized the operation server-side. */
|
|
16
|
-
data: T;
|
|
17
|
-
}
|
|
18
|
-
interface BridgeFailure {
|
|
19
|
-
ok: false;
|
|
20
|
-
stage: BridgeStage;
|
|
21
|
-
error: string;
|
|
22
|
-
/**
|
|
23
|
-
* Set when the asset-moving on-chain tx already landed but a later step failed — the caller can
|
|
24
|
-
* finish the flow with this hash (e.g. re-call `confirmWithdrawal`) instead of restarting.
|
|
25
|
-
*/
|
|
26
|
-
onChainTxHash?: string;
|
|
27
|
-
/**
|
|
28
|
-
* Set for a withdrawal whose server-side `request` already succeeded (and already debited the
|
|
29
|
-
* player) but whose on-chain/confirm leg failed. Recover with `client.blockchain.retryWithdrawal`
|
|
30
|
-
* (before ExpiresAt) or `confirmWithdrawal` (if the tx actually landed) — NOT a fresh request.
|
|
31
|
-
*/
|
|
32
|
-
titleTransactionID?: string;
|
|
33
|
-
}
|
|
34
|
-
type BridgeResult<T> = BridgeSuccess<T> | BridgeFailure;
|
|
35
|
-
/** Normalizes a thrown value (viem error, plain Error, or unknown) into a short human string. */
|
|
36
|
-
declare function toErrorMessage(e: unknown): string;
|
|
37
|
-
declare function bridgeFail(stage: BridgeStage, error: string, extra?: {
|
|
38
|
-
onChainTxHash?: string;
|
|
39
|
-
titleTransactionID?: string;
|
|
40
|
-
}): BridgeFailure;
|
|
41
|
-
/**
|
|
42
|
-
* Where a wallet-login flow stopped. `challenge` = fetching the message to sign; `sign` = the
|
|
43
|
-
* wallet signing it (user may reject); `login` = exchanging the signature for a session. Unlike
|
|
44
|
-
* a bridge flow there is no on-chain transaction — this is an off-chain proof of ownership.
|
|
45
|
-
*/
|
|
46
|
-
type WalletLoginStage = "challenge" | "sign" | "login";
|
|
47
|
-
interface WalletLoginSuccess<T> {
|
|
48
|
-
ok: true;
|
|
49
|
-
/** The core SDK result of the successful login (the fresh ClientState). */
|
|
50
|
-
data: T;
|
|
51
|
-
}
|
|
52
|
-
interface WalletLoginFailure {
|
|
53
|
-
ok: false;
|
|
54
|
-
stage: WalletLoginStage;
|
|
55
|
-
error: string;
|
|
56
|
-
}
|
|
57
|
-
type WalletLoginResult<T> = WalletLoginSuccess<T> | WalletLoginFailure;
|
|
58
|
-
declare function walletLoginFail(stage: WalletLoginStage, error: string): WalletLoginFailure;
|
|
59
|
-
|
|
60
|
-
declare const mainnet: Chain;
|
|
61
|
-
declare const bsc: Chain;
|
|
62
|
-
declare const polygon: Chain;
|
|
63
|
-
declare const base: Chain;
|
|
64
|
-
declare const arbitrum: Chain;
|
|
65
|
-
declare const optimism: Chain;
|
|
66
|
-
declare const sepolia: Chain;
|
|
67
|
-
declare const polygonAmoy: Chain;
|
|
68
|
-
/** Every chain declared here, keyed by NetworkID-style name — handy for a title-driven picker. */
|
|
69
|
-
declare const idosChains: {
|
|
70
|
-
readonly mainnet: Chain;
|
|
71
|
-
readonly bsc: Chain;
|
|
72
|
-
readonly polygon: Chain;
|
|
73
|
-
readonly base: Chain;
|
|
74
|
-
readonly arbitrum: Chain;
|
|
75
|
-
readonly optimism: Chain;
|
|
76
|
-
readonly sepolia: Chain;
|
|
77
|
-
readonly polygonAmoy: Chain;
|
|
78
|
-
};
|
|
79
|
-
/** Look up a declared chain by its EVM chain id (e.g. from the title's blockchain config). */
|
|
80
|
-
declare function chainById(id: number): Chain | undefined;
|
|
81
|
-
/**
|
|
82
|
-
* A chain in the CAIP shape Reown AppKit expects.
|
|
83
|
-
*
|
|
84
|
-
* AppKit ships its own network list at `@reown/appkit/networks`, but that module is
|
|
85
|
-
* `export * from "viem/chains"` — the very barrel this file exists to avoid. Converting our own
|
|
86
|
-
* chains keeps AppKit working without dragging `tempo`/`ox` (and its BigInt `**`) into the bundle.
|
|
87
|
-
*/
|
|
88
|
-
type AppKitEvmNetwork = Chain & {
|
|
89
|
-
chainNamespace: "eip155";
|
|
90
|
-
caipNetworkId: `eip155:${number}`;
|
|
91
|
-
};
|
|
92
|
-
/** Wraps a chain in the CAIP fields AppKit needs. */
|
|
93
|
-
declare function toAppKitNetwork(chain: Chain): AppKitEvmNetwork;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* The viem clients + signing account the EVM bridge needs. wagmi supplies all three:
|
|
97
|
-
* `usePublicClient()`, `useWalletClient().data`, and `useAccount().address`. Kept as plain viem
|
|
98
|
-
* types so the framework-agnostic core never imports wagmi/React.
|
|
99
|
-
*/
|
|
100
|
-
interface EvmBridgeClients {
|
|
101
|
-
publicClient: PublicClient;
|
|
102
|
-
walletClient: WalletClient;
|
|
103
|
-
/** The connected wallet address that signs and pays for the transactions. */
|
|
104
|
-
account: Address;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Sends a contract write and waits for its receipt, returning the tx hash. Throws if the
|
|
108
|
-
* transaction reverts on-chain (so callers can attribute the failure to the on-chain stage).
|
|
109
|
-
*/
|
|
110
|
-
declare function writeAndWait<const TAbi extends Abi, TFunctionName extends ContractFunctionName<TAbi, "nonpayable" | "payable">>(clients: EvmBridgeClients, request: {
|
|
111
|
-
address: Address;
|
|
112
|
-
abi: TAbi;
|
|
113
|
-
functionName: TFunctionName;
|
|
114
|
-
args: ContractFunctionArgs<TAbi, "nonpayable" | "payable", TFunctionName>;
|
|
115
|
-
value?: bigint;
|
|
116
|
-
}): Promise<Hex>;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Ensures the RewardPool is allowed to pull at least `amount` of an ERC-20 from `account`.
|
|
120
|
-
* Reads the current allowance and only sends an `approve` when it's short. Returns the approve
|
|
121
|
-
* tx hash if one was sent, or null when the existing allowance already covered the amount.
|
|
122
|
-
*/
|
|
123
|
-
declare function ensureErc20Allowance(clients: EvmBridgeClients, tokenAddress: Address, spender: Address, amount: bigint): Promise<Hex | null>;
|
|
124
|
-
interface DepositTokenEvmParams {
|
|
125
|
-
client: IDosGamesClient;
|
|
126
|
-
clients: EvmBridgeClients;
|
|
127
|
-
network: BlockchainNetworkDefinition;
|
|
128
|
-
/** ERC-20 contract of the token being deposited (the RewardPool splits/credits it in-game). */
|
|
129
|
-
tokenAddress: Address;
|
|
130
|
-
/** Raw on-chain amount, already scaled by the token's decimals (use viem `parseUnits`). */
|
|
131
|
-
amount: bigint;
|
|
132
|
-
/** The title the client was created for (not exposed on the client — pass it through). */
|
|
133
|
-
titleID: string;
|
|
134
|
-
/** Operation kind; defaults to "game_topup" server-side. Deposits echo it into the tx. */
|
|
135
|
-
category?: string;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Full EVM token-deposit flow: approve (if needed) → `depositERC20(token, amount, userID,
|
|
139
|
-
* titleID, category)` on the RewardPool → report the tx hash to the backend so it verifies the
|
|
140
|
-
* transfer and credits the in-game crypto balance. On success the core cache balance is already
|
|
141
|
-
* updated by `client.blockchain.depositToken`.
|
|
142
|
-
*/
|
|
143
|
-
declare function depositTokenEvm(params: DepositTokenEvmParams): Promise<BridgeResult<DepositTokenResponse>>;
|
|
144
|
-
interface DepositNftEvmParams {
|
|
145
|
-
client: IDosGamesClient;
|
|
146
|
-
clients: EvmBridgeClients;
|
|
147
|
-
network: BlockchainNetworkDefinition;
|
|
148
|
-
/** ERC-1155 collection contract holding the NFT. */
|
|
149
|
-
nftContractAddress: Address;
|
|
150
|
-
/** On-chain token id of the NFT being deposited. */
|
|
151
|
-
tokenId: bigint;
|
|
152
|
-
/** Copies to transfer (1 for a unique NFT; ERC-1155 collections can hold fungible editions). */
|
|
153
|
-
amount: bigint;
|
|
154
|
-
titleID: string;
|
|
155
|
-
category?: string;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Full EVM NFT-deposit flow: `safeTransferFrom(account, pool, id, amount, data)` on the ERC-1155
|
|
159
|
-
* collection — where `data = abi.encode(userID, titleID, category)` — then report the tx hash so
|
|
160
|
-
* the backend verifies the transfer and grants the matching in-game item. No operator approval is
|
|
161
|
-
* needed: the player transfers their own token, so msg.sender == from.
|
|
162
|
-
*/
|
|
163
|
-
declare function depositNftEvm(params: DepositNftEvmParams): Promise<BridgeResult<DepositNFTResponse>>;
|
|
164
|
-
interface DepositNft721EvmParams {
|
|
165
|
-
client: IDosGamesClient;
|
|
166
|
-
clients: EvmBridgeClients;
|
|
167
|
-
network: BlockchainNetworkDefinition;
|
|
168
|
-
/** ERC-721 collection contract holding the NFT. */
|
|
169
|
-
nftContractAddress: Address;
|
|
170
|
-
/** On-chain token id of the unique NFT being deposited. */
|
|
171
|
-
tokenId: bigint;
|
|
172
|
-
titleID: string;
|
|
173
|
-
category?: string;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Full EVM ERC-721 NFT-deposit flow: `safeTransferFrom(account, pool, tokenId, data)` on the
|
|
177
|
-
* ERC-721 collection — where `data = abi.encode(userID, titleID, category)` — then report the tx
|
|
178
|
-
* hash so the backend verifies the transfer and grants the matching in-game unique item. No
|
|
179
|
-
* operator approval is needed: the player transfers their own token, so msg.sender == from.
|
|
180
|
-
*/
|
|
181
|
-
declare function depositNftEvm721(params: DepositNft721EvmParams): Promise<BridgeResult<DepositNFTResponse>>;
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Submits a server-signed ERC-20 withdrawal on-chain by calling `withdrawERC20` on the RewardPool.
|
|
185
|
-
* Every field comes straight from the server's {@link WithdrawalSignatureResponse}; the client
|
|
186
|
-
* only echoes them (Amount and Nonce are decimal strings the server already scaled to raw units,
|
|
187
|
-
* and userID/titleID/category are part of the signed hash — passing anything else reverts). Use
|
|
188
|
-
* this directly to submit a fresh signature from `retryWithdrawal`.
|
|
189
|
-
*/
|
|
190
|
-
declare function submitEvmTokenWithdrawal(clients: EvmBridgeClients, sig: WithdrawalSignatureResponse): Promise<Hex>;
|
|
191
|
-
/**
|
|
192
|
-
* Submits a server-signed ERC-1155 game-NFT withdrawal on-chain. The v2 backend signs a MINT voucher
|
|
193
|
-
* (tag "ERC1155_MINT") against the ItemBridge — `sig.ContractAddress` is the bridge and
|
|
194
|
-
* `sig.TokenAddress` is the collection — so this calls `withdrawERC1155Mint`, NOT RewardPool's
|
|
195
|
-
* `withdrawERC1155` (which would fail the selector/hash-tag check).
|
|
196
|
-
*/
|
|
197
|
-
declare function submitEvmNftWithdrawal(clients: EvmBridgeClients, sig: WithdrawalSignatureResponse): Promise<Hex>;
|
|
198
|
-
/**
|
|
199
|
-
* Submits a server-signed ERC-721 unique game-NFT withdrawal on-chain via the ItemBridge's
|
|
200
|
-
* `withdrawERC721Mint` (MINT voucher, tag "ERC721_MINT"; `sig.ContractAddress` = bridge,
|
|
201
|
-
* `sig.TokenAddress` = collection) — not RewardPool's custody `withdrawERC721`.
|
|
202
|
-
*/
|
|
203
|
-
declare function submitEvmNftWithdrawal721(clients: EvmBridgeClients, sig: WithdrawalSignatureResponse): Promise<Hex>;
|
|
204
|
-
interface WithdrawTokenEvmParams {
|
|
205
|
-
client: IDosGamesClient;
|
|
206
|
-
clients: EvmBridgeClients;
|
|
207
|
-
currencyID: string;
|
|
208
|
-
networkID: string;
|
|
209
|
-
/** Destination wallet — usually the connected `clients.account`. */
|
|
210
|
-
walletAddress: string;
|
|
211
|
-
/** Human decimal amount to withdraw (the server converts and signs raw units). */
|
|
212
|
-
amount: string;
|
|
213
|
-
category?: string;
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Full EVM token-withdrawal flow: `requestTokenWithdrawal` (debits in-game immediately and returns
|
|
217
|
-
* a signed payload) → `withdrawERC20` on-chain → `confirmWithdrawal` with the resulting hash.
|
|
218
|
-
*
|
|
219
|
-
* On a failure AFTER the request succeeded, the returned {@link BridgeFailure} carries
|
|
220
|
-
* `titleTransactionID` (the asset is already debited — recover with `retryWithdrawal` while
|
|
221
|
-
* Pending, or `confirmWithdrawal` if the tx actually landed) and, when the on-chain leg landed,
|
|
222
|
-
* `onChainTxHash`. Never restart with a fresh `requestTokenWithdrawal` — that debits twice.
|
|
223
|
-
*/
|
|
224
|
-
declare function withdrawTokenEvm(params: WithdrawTokenEvmParams): Promise<BridgeResult<TokenWithdrawalResponse>>;
|
|
225
|
-
interface WithdrawNftEvmParams {
|
|
226
|
-
client: IDosGamesClient;
|
|
227
|
-
clients: EvmBridgeClients;
|
|
228
|
-
itemID: string;
|
|
229
|
-
networkID: string;
|
|
230
|
-
walletAddress: string;
|
|
231
|
-
/** Copies to withdraw, as an integer string (usually "1"). */
|
|
232
|
-
amount: string;
|
|
233
|
-
category?: string;
|
|
234
|
-
}
|
|
235
|
-
/** Full EVM NFT-withdrawal flow: `requestNFTWithdrawal` → `withdrawERC1155` → `confirmWithdrawal`. */
|
|
236
|
-
declare function withdrawNftEvm(params: WithdrawNftEvmParams): Promise<BridgeResult<NFTWithdrawalResponse>>;
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* The on-chain half of the Solana bridge, delegated to the title's own program integration.
|
|
240
|
-
*
|
|
241
|
-
* Unlike EVM — where the RewardPool ABI is fully known and viem builds the calls — the Solana
|
|
242
|
-
* RewardPool is a custom program whose instruction/account layout (DepositSpl, withdraw_spl + the
|
|
243
|
-
* ed25519 sig-verify instruction) lives in that program's IDL, NOT in this client SDK. So the
|
|
244
|
-
* bridge asks you to provide these two calls, built with your program's IDL / `@solana/web3.js`
|
|
245
|
-
* (or Anchor) against the connected wallet from `@solana/wallet-adapter-react`. The SDK-side
|
|
246
|
-
* orchestration (request → submit → confirm, deposit → report) is identical to EVM and handled by
|
|
247
|
-
* {@link depositTokenSolana} / {@link withdrawTokenSolana}.
|
|
248
|
-
*/
|
|
249
|
-
interface SolanaProgramAdapter {
|
|
250
|
-
/**
|
|
251
|
-
* Builds and sends the on-chain `DepositSpl` transfer of `amountRaw` base units of `mint` into
|
|
252
|
-
* the platform program pool, embedding the identifiers the backend reads back
|
|
253
|
-
* (`GetDepositSplCallDetailsBySignature` verifies `userID`). Returns the transaction signature.
|
|
254
|
-
*/
|
|
255
|
-
depositSpl(params: {
|
|
256
|
-
mint: string;
|
|
257
|
-
amountRaw: bigint;
|
|
258
|
-
userID: string;
|
|
259
|
-
titleID: string;
|
|
260
|
-
category: string;
|
|
261
|
-
}): Promise<string>;
|
|
262
|
-
/**
|
|
263
|
-
* Builds and sends the on-chain `withdraw_spl` transaction from a server-issued signature
|
|
264
|
-
* payload — including the ed25519 sig-verify instruction at `SigIxIndex` carrying
|
|
265
|
-
* `Ed25519PublicKey`/`Ed25519Message`/`SignatureHex`. Returns the transaction signature.
|
|
266
|
-
*/
|
|
267
|
-
submitWithdrawal(sig: SolanaWithdrawalSignature): Promise<string>;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
interface DepositTokenSolanaParams {
|
|
271
|
-
client: IDosGamesClient;
|
|
272
|
-
adapter: SolanaProgramAdapter;
|
|
273
|
-
network: BlockchainNetworkDefinition;
|
|
274
|
-
/** SPL mint of the token being deposited. */
|
|
275
|
-
mint: string;
|
|
276
|
-
/** Raw base-unit amount (already scaled by the mint's decimals). */
|
|
277
|
-
amountRaw: bigint;
|
|
278
|
-
titleID: string;
|
|
279
|
-
category?: string;
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Full Solana token-deposit flow: your {@link SolanaProgramAdapter.depositSpl} sends the on-chain
|
|
283
|
-
* transfer, then `client.blockchain.depositToken` reports the signature so the backend verifies
|
|
284
|
-
* and credits the in-game balance. Mirrors {@link depositTokenEvm}.
|
|
285
|
-
*/
|
|
286
|
-
declare function depositTokenSolana(params: DepositTokenSolanaParams): Promise<BridgeResult<DepositTokenResponse>>;
|
|
287
|
-
interface WithdrawTokenSolanaParams {
|
|
288
|
-
client: IDosGamesClient;
|
|
289
|
-
adapter: SolanaProgramAdapter;
|
|
290
|
-
currencyID: string;
|
|
291
|
-
networkID: string;
|
|
292
|
-
walletAddress: string;
|
|
293
|
-
amount: string;
|
|
294
|
-
category?: string;
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Full Solana token-withdrawal flow: `requestTokenWithdrawal` → your
|
|
298
|
-
* {@link SolanaProgramAdapter.submitWithdrawal} sends the `withdraw_spl` tx → `confirmWithdrawal`.
|
|
299
|
-
* Same recovery semantics as EVM: a post-request failure carries `titleTransactionID` (already
|
|
300
|
-
* debited — retry, don't re-request). Mirrors {@link withdrawTokenEvm}.
|
|
301
|
-
*/
|
|
302
|
-
declare function withdrawTokenSolana(params: WithdrawTokenSolanaParams): Promise<BridgeResult<TokenWithdrawalResponse>>;
|
|
303
|
-
|
|
304
|
-
export { type AppKitEvmNetwork as A, type BridgeFailure as B, polygonAmoy as C, type DepositNft721EvmParams as D, type EvmBridgeClients as E, sepolia as F, submitEvmNftWithdrawal as G, submitEvmNftWithdrawal721 as H, submitEvmTokenWithdrawal as I, toAppKitNetwork as J, toErrorMessage as K, walletLoginFail as L, withdrawNftEvm as M, withdrawTokenEvm as N, withdrawTokenSolana as O, writeAndWait as P, type SolanaProgramAdapter as S, type WalletLoginResult as W, type BridgeResult as a, type BridgeStage as b, type BridgeSuccess as c, type DepositNftEvmParams as d, type DepositTokenEvmParams as e, type DepositTokenSolanaParams as f, type WalletLoginFailure as g, type WalletLoginStage as h, type WalletLoginSuccess as i, type WithdrawNftEvmParams as j, type WithdrawTokenEvmParams as k, type WithdrawTokenSolanaParams as l, arbitrum as m, base as n, bridgeFail as o, bsc as p, chainById as q, depositNftEvm as r, depositNftEvm721 as s, depositTokenEvm as t, depositTokenSolana as u, ensureErc20Allowance as v, idosChains as w, mainnet as x, optimism as y, polygon as z };
|
package/dist/chunk-ZPNBMRUO.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import {BaseError,encodeAbiParameters}from'viem';import {normalizeBlockchainCategory}from'@idosgames/core';function g(e){return e instanceof BaseError?e.shortMessage:e instanceof Error?e.message:String(e)}function a(e,t,n){return {ok:false,stage:e,error:t,...n}}function f(e,t){return {ok:false,stage:e,error:t}}var B={id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://eth.llamarpc.com"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io"}}},P={id:56,name:"BNB Smart Chain",nativeCurrency:{name:"BNB",symbol:"BNB",decimals:18},rpcUrls:{default:{http:["https://bsc-dataseed.binance.org"]}},blockExplorers:{default:{name:"BscScan",url:"https://bscscan.com"}}},S={id:137,name:"Polygon",nativeCurrency:{name:"POL",symbol:"POL",decimals:18},rpcUrls:{default:{http:["https://polygon-rpc.com"]}},blockExplorers:{default:{name:"PolygonScan",url:"https://polygonscan.com"}}},R={id:8453,name:"Base",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.base.org"]}},blockExplorers:{default:{name:"BaseScan",url:"https://basescan.org"}}},H={id:42161,name:"Arbitrum One",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://arb1.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://arbiscan.io"}}},M={id:10,name:"OP Mainnet",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.optimism.io"]}},blockExplorers:{default:{name:"Optimistic Etherscan",url:"https://optimistic.etherscan.io"}}},F={id:11155111,name:"Sepolia",testnet:true,nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://rpc.sepolia.org"]}},blockExplorers:{default:{name:"Etherscan",url:"https://sepolia.etherscan.io"}}},L={id:80002,name:"Polygon Amoy",testnet:true,nativeCurrency:{name:"POL",symbol:"POL",decimals:18},rpcUrls:{default:{http:["https://rpc-amoy.polygon.technology"]}},blockExplorers:{default:{name:"PolygonScan",url:"https://amoy.polygonscan.com"}}},G={mainnet:B,bsc:P,polygon:S,base:R,arbitrum:H,optimism:M,sepolia:F,polygonAmoy:L};function nt(e){return Object.values(G).find(t=>t.id===e)}function at(e){return {...e,chainNamespace:"eip155",caipNetworkId:`eip155:${e.id}`}}var w=[{type:"function",name:"depositERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"amount",type:"uint256"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"withdrawERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"amount",type:"uint256"},{name:"burnAmount",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC1155",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC721",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]}],x=[{type:"function",name:"withdrawERC1155Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC721Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]}],k=[{type:"function",name:"approve",stateMutability:"nonpayable",inputs:[{name:"spender",type:"address"},{name:"amount",type:"uint256"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"allowance",stateMutability:"view",inputs:[{name:"owner",type:"address"},{name:"spender",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"decimals",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint8"}]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"}],outputs:[{name:"",type:"uint256"}]}],C=[{type:"function",name:"safeTransferFrom",stateMutability:"nonpayable",inputs:[{name:"from",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"data",type:"bytes"}],outputs:[]},{type:"function",name:"isApprovedForAll",stateMutability:"view",inputs:[{name:"account",type:"address"},{name:"operator",type:"address"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"setApprovalForAll",stateMutability:"nonpayable",inputs:[{name:"operator",type:"address"},{name:"approved",type:"bool"}],outputs:[]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"},{name:"id",type:"uint256"}],outputs:[{name:"",type:"uint256"}]}],D=[{type:"function",name:"safeTransferFrom",stateMutability:"nonpayable",inputs:[{name:"from",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"data",type:"bytes"}],outputs:[]}];function b(e,t,n){return encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[e,t,normalizeBlockchainCategory(n)])}async function h(e,t){let{walletClient:n,publicClient:i,account:d}=e,o=await n.writeContract({address:t.address,abi:t.abi,functionName:t.functionName,args:t.args,account:d,chain:n.chain,value:t.value});if((await i.waitForTransactionReceipt({hash:o})).status==="reverted")throw new Error(`On-chain transaction reverted (${o}).`);return o}function A(e){let t=e.RewardPoolAddress;return t||null}async function E(e,t,n,i){return await e.publicClient.readContract({address:t,abi:k,functionName:"allowance",args:[e.account,n]})>=i?null:h(e,{address:t,abi:k,functionName:"approve",args:[n,i]})}async function O(e){let{client:t,clients:n,network:i,tokenAddress:d,amount:o,titleID:p,category:m}=e,r=t.auth.context?.userID;if(!r)return a("approve","Not logged in.");let c=A(i);if(!c)return a("approve","Network has no RewardPoolAddress.");if(o<=0n)return a("approve","Amount must be positive.");try{await E(n,d,c,o);}catch(u){return a("approve",g(u))}let s;try{s=await h(n,{address:c,abi:w,functionName:"depositERC20",args:[d,o,r,p,m??""]});}catch(u){return a("deposit-onchain",g(u))}let l=await t.blockchain.depositToken(i.NetworkID??"",s);return l.ok?{ok:true,onChainTxHash:s,data:l.data}:a("report",l.error,{onChainTxHash:s})}async function K(e){let{client:t,clients:n,network:i,nftContractAddress:d,tokenId:o,amount:p,titleID:m,category:r}=e,c=t.auth.context?.userID;if(!c)return a("deposit-onchain","Not logged in.");let s=A(i);if(!s)return a("deposit-onchain","Network has no RewardPoolAddress.");if(p<=0n)return a("deposit-onchain","Amount must be positive.");let l=b(c,m,r),u;try{u=await h(n,{address:d,abi:C,functionName:"safeTransferFrom",args:[n.account,s,o,p,l]});}catch(W){return a("deposit-onchain",g(W))}let y=await t.blockchain.depositNFT(i.NetworkID??"",u);return y.ok?{ok:true,onChainTxHash:u,data:y.data}:a("report",y.error,{onChainTxHash:u})}async function $(e){let{client:t,clients:n,network:i,nftContractAddress:d,tokenId:o,titleID:p,category:m}=e,r=t.auth.context?.userID;if(!r)return a("deposit-onchain","Not logged in.");let c=A(i);if(!c)return a("deposit-onchain","Network has no RewardPoolAddress.");let s=b(r,p,m),l;try{l=await h(n,{address:d,abi:D,functionName:"safeTransferFrom",args:[n.account,c,o,s]});}catch(y){return a("deposit-onchain",g(y))}let u=await t.blockchain.depositNFT(i.NetworkID??"",l);return u.ok?{ok:true,onChainTxHash:l,data:u.data}:a("report",u.error,{onChainTxHash:l})}async function T(e,t){return h(e,{address:t.ContractAddress,abi:w,functionName:"withdrawERC20",args:[t.TokenAddress,t.WalletAddress,BigInt(t.Amount??"0"),BigInt(t.BurnAmount??"0"),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function I(e,t){return h(e,{address:t.ContractAddress,abi:x,functionName:"withdrawERC1155Mint",args:[t.TokenAddress,t.WalletAddress,BigInt(t.TokenId??"0"),BigInt(t.Amount??"0"),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function z(e,t){return h(e,{address:t.ContractAddress,abi:x,functionName:"withdrawERC721Mint",args:[t.TokenAddress,t.WalletAddress,BigInt(t.TokenId??"0"),BigInt(t.Nonce??"0"),t.Signature??"0x",t.UserID??"",t.TitleID??"",t.Category??"",BigInt(t.Deadline??"0")]})}async function V(e){let{client:t,clients:n,currencyID:i,networkID:d,walletAddress:o,amount:p,category:m}=e,r=await t.blockchain.requestTokenWithdrawal(i,d,o,p,m);if(!r.ok)return a("request",r.error);let c=r.data.EvmSignature,s=r.data.TitleTransactionID??void 0;if(!c)return a("request","Withdrawal response carried no EVM signature.",{titleTransactionID:s});let l;try{l=await T(n,c);}catch(y){return a("withdraw-onchain",g(y),{titleTransactionID:s})}let u=await v(t,s,l);return u.ok?{ok:true,onChainTxHash:l,data:r.data}:u}async function j(e){let{client:t,clients:n,itemID:i,networkID:d,walletAddress:o,amount:p,category:m}=e,r=await t.blockchain.requestNFTWithdrawal(i,d,o,p,m);if(!r.ok)return a("request",r.error);let c=r.data.EvmSignature,s=r.data.TitleTransactionID??void 0;if(!c)return a("request","Withdrawal response carried no EVM signature.",{titleTransactionID:s});let l;try{l=await I(n,c);}catch(y){return a("withdraw-onchain",g(y),{titleTransactionID:s})}let u=await v(t,s,l);return u.ok?{ok:true,onChainTxHash:l,data:r.data}:u}async function v(e,t,n){if(!t)return a("confirm","Missing TitleTransactionID.",{onChainTxHash:n});let i=await e.blockchain.confirmWithdrawal(t,n);return i.ok?{ok:true,onChainTxHash:n,data:i.data}:a("confirm",i.error,{onChainTxHash:n,titleTransactionID:t})}async function J(e){let{client:t,clients:n,networkID:i}=e,d=e.walletAddress??n.account,o=await t.auth.requestWalletChallenge(d,i);if(!o.ok)return f("challenge",o.error);let p;try{p=await n.walletClient.signMessage({account:n.account,message:o.data.Message});}catch(r){return f("sign",g(r))}let m=await t.auth.loginWithWallet(d,i,p);return m.ok?{ok:true,data:m.data}:f("login",m.error)}async function X(e){let{client:t,adapter:n,network:i,mint:d,amountRaw:o,titleID:p,category:m}=e,r=t.auth.context?.userID;if(!r)return a("deposit-onchain","Not logged in.");if(o<=0n)return a("deposit-onchain","Amount must be positive.");let c;try{c=await n.depositSpl({mint:d,amountRaw:o,userID:r,titleID:p,category:normalizeBlockchainCategory(m)});}catch(l){return a("deposit-onchain",g(l))}let s=await t.blockchain.depositToken(i.NetworkID??"",c);return s.ok?{ok:true,onChainTxHash:c,data:s.data}:a("report",s.error,{onChainTxHash:c})}async function Y(e){let{client:t,adapter:n,currencyID:i,networkID:d,walletAddress:o,amount:p,category:m}=e,r=await t.blockchain.requestTokenWithdrawal(i,d,o,p,m);if(!r.ok)return a("request",r.error);let c=r.data.SolanaSignature,s=r.data.TitleTransactionID??void 0;if(!c)return a("request","Withdrawal response carried no Solana signature.",{titleTransactionID:s});let l;try{l=await n.submitWithdrawal(c);}catch(y){return a("withdraw-onchain",g(y),{titleTransactionID:s})}if(!s)return a("confirm","Missing TitleTransactionID.",{onChainTxHash:l});let u=await t.blockchain.confirmWithdrawal(s,l);return u.ok?{ok:true,onChainTxHash:l,data:r.data}:a("confirm",u.error,{onChainTxHash:l,titleTransactionID:s})}async function Z(e){let{client:t,networkID:n,walletAddress:i,signMessage:d}=e,o=await t.auth.requestWalletChallenge(i,n);if(!o.ok)return f("challenge",o.error);let p;try{let r=await d(new TextEncoder().encode(o.data.Message));p=_(r);}catch(r){return f("sign",g(r))}let m=await t.auth.loginWithWallet(i,n,p);return m.ok?{ok:true,data:m.data}:f("login",m.error)}function _(e){let t="0x";for(let n of e)t+=n.toString(16).padStart(2,"0");return t}
|
|
2
|
-
export{z as A,V as B,j as C,J as D,X as E,Y as F,Z as G,g as a,a as b,f as c,B as d,P as e,S as f,R as g,H as h,M as i,F as j,L as k,G as l,nt as m,at as n,w as o,k as p,C as q,D as r,b as s,h as t,E as u,O as v,K as w,$ as x,T as y,I as z};
|