@idosgames/wallet 0.1.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/LICENSE +21 -0
- package/README.md +254 -0
- package/dist/bridge-BCxf6AHE.d.cts +269 -0
- package/dist/bridge-BCxf6AHE.d.ts +269 -0
- package/dist/chunk-Q6C5EFPV.js +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +335 -0
- package/dist/index.d.ts +335 -0
- package/dist/index.js +1 -0
- package/dist/react/index.cjs +1 -0
- package/dist/react/index.d.cts +150 -0
- package/dist/react/index.d.ts +150 -0
- package/dist/react/index.js +1 -0
- package/package.json +94 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { 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
|
+
/**
|
|
61
|
+
* The viem clients + signing account the EVM bridge needs. wagmi supplies all three:
|
|
62
|
+
* `usePublicClient()`, `useWalletClient().data`, and `useAccount().address`. Kept as plain viem
|
|
63
|
+
* types so the framework-agnostic core never imports wagmi/React.
|
|
64
|
+
*/
|
|
65
|
+
interface EvmBridgeClients {
|
|
66
|
+
publicClient: PublicClient;
|
|
67
|
+
walletClient: WalletClient;
|
|
68
|
+
/** The connected wallet address that signs and pays for the transactions. */
|
|
69
|
+
account: Address;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Sends a contract write and waits for its receipt, returning the tx hash. Throws if the
|
|
73
|
+
* transaction reverts on-chain (so callers can attribute the failure to the on-chain stage).
|
|
74
|
+
*/
|
|
75
|
+
declare function writeAndWait<const TAbi extends Abi, TFunctionName extends ContractFunctionName<TAbi, "nonpayable" | "payable">>(clients: EvmBridgeClients, request: {
|
|
76
|
+
address: Address;
|
|
77
|
+
abi: TAbi;
|
|
78
|
+
functionName: TFunctionName;
|
|
79
|
+
args: ContractFunctionArgs<TAbi, "nonpayable" | "payable", TFunctionName>;
|
|
80
|
+
value?: bigint;
|
|
81
|
+
}): Promise<Hex>;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Ensures the RewardPool is allowed to pull at least `amount` of an ERC-20 from `account`.
|
|
85
|
+
* Reads the current allowance and only sends an `approve` when it's short. Returns the approve
|
|
86
|
+
* tx hash if one was sent, or null when the existing allowance already covered the amount.
|
|
87
|
+
*/
|
|
88
|
+
declare function ensureErc20Allowance(clients: EvmBridgeClients, tokenAddress: Address, spender: Address, amount: bigint): Promise<Hex | null>;
|
|
89
|
+
interface DepositTokenEvmParams {
|
|
90
|
+
client: IDosGamesClient;
|
|
91
|
+
clients: EvmBridgeClients;
|
|
92
|
+
network: BlockchainNetworkDefinition;
|
|
93
|
+
/** ERC-20 contract of the token being deposited (the RewardPool splits/credits it in-game). */
|
|
94
|
+
tokenAddress: Address;
|
|
95
|
+
/** Raw on-chain amount, already scaled by the token's decimals (use viem `parseUnits`). */
|
|
96
|
+
amount: bigint;
|
|
97
|
+
/** The title the client was created for (not exposed on the client — pass it through). */
|
|
98
|
+
titleID: string;
|
|
99
|
+
/** Operation kind; defaults to "game_topup" server-side. Deposits echo it into the tx. */
|
|
100
|
+
category?: string;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Full EVM token-deposit flow: approve (if needed) → `depositERC20(token, amount, userID,
|
|
104
|
+
* titleID, category)` on the RewardPool → report the tx hash to the backend so it verifies the
|
|
105
|
+
* transfer and credits the in-game crypto balance. On success the core cache balance is already
|
|
106
|
+
* updated by `client.blockchain.depositToken`.
|
|
107
|
+
*/
|
|
108
|
+
declare function depositTokenEvm(params: DepositTokenEvmParams): Promise<BridgeResult<DepositTokenResponse>>;
|
|
109
|
+
interface DepositNftEvmParams {
|
|
110
|
+
client: IDosGamesClient;
|
|
111
|
+
clients: EvmBridgeClients;
|
|
112
|
+
network: BlockchainNetworkDefinition;
|
|
113
|
+
/** ERC-1155 collection contract holding the NFT. */
|
|
114
|
+
nftContractAddress: Address;
|
|
115
|
+
/** On-chain token id of the NFT being deposited. */
|
|
116
|
+
tokenId: bigint;
|
|
117
|
+
/** Copies to transfer (1 for a unique NFT; ERC-1155 collections can hold fungible editions). */
|
|
118
|
+
amount: bigint;
|
|
119
|
+
titleID: string;
|
|
120
|
+
category?: string;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Full EVM NFT-deposit flow: `safeTransferFrom(account, pool, id, amount, data)` on the ERC-1155
|
|
124
|
+
* collection — where `data = abi.encode(userID, titleID, category)` — then report the tx hash so
|
|
125
|
+
* the backend verifies the transfer and grants the matching in-game item. No operator approval is
|
|
126
|
+
* needed: the player transfers their own token, so msg.sender == from.
|
|
127
|
+
*/
|
|
128
|
+
declare function depositNftEvm(params: DepositNftEvmParams): Promise<BridgeResult<DepositNFTResponse>>;
|
|
129
|
+
interface DepositNft721EvmParams {
|
|
130
|
+
client: IDosGamesClient;
|
|
131
|
+
clients: EvmBridgeClients;
|
|
132
|
+
network: BlockchainNetworkDefinition;
|
|
133
|
+
/** ERC-721 collection contract holding the NFT. */
|
|
134
|
+
nftContractAddress: Address;
|
|
135
|
+
/** On-chain token id of the unique NFT being deposited. */
|
|
136
|
+
tokenId: bigint;
|
|
137
|
+
titleID: string;
|
|
138
|
+
category?: string;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Full EVM ERC-721 NFT-deposit flow: `safeTransferFrom(account, pool, tokenId, data)` on the
|
|
142
|
+
* ERC-721 collection — where `data = abi.encode(userID, titleID, category)` — then report the tx
|
|
143
|
+
* hash so the backend verifies the transfer and grants the matching in-game unique item. No
|
|
144
|
+
* operator approval is needed: the player transfers their own token, so msg.sender == from.
|
|
145
|
+
*/
|
|
146
|
+
declare function depositNftEvm721(params: DepositNft721EvmParams): Promise<BridgeResult<DepositNFTResponse>>;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Submits a server-signed ERC-20 withdrawal on-chain by calling `withdrawERC20` on the RewardPool.
|
|
150
|
+
* Every field comes straight from the server's {@link WithdrawalSignatureResponse}; the client
|
|
151
|
+
* only echoes them (Amount and Nonce are decimal strings the server already scaled to raw units,
|
|
152
|
+
* and userID/titleID/category are part of the signed hash — passing anything else reverts). Use
|
|
153
|
+
* this directly to submit a fresh signature from `retryWithdrawal`.
|
|
154
|
+
*/
|
|
155
|
+
declare function submitEvmTokenWithdrawal(clients: EvmBridgeClients, sig: WithdrawalSignatureResponse): Promise<Hex>;
|
|
156
|
+
/**
|
|
157
|
+
* Submits a server-signed ERC-1155 game-NFT withdrawal on-chain. The v2 backend signs a MINT voucher
|
|
158
|
+
* (tag "ERC1155_MINT") against the ItemBridge — `sig.ContractAddress` is the bridge and
|
|
159
|
+
* `sig.TokenAddress` is the collection — so this calls `withdrawERC1155Mint`, NOT RewardPool's
|
|
160
|
+
* `withdrawERC1155` (which would fail the selector/hash-tag check).
|
|
161
|
+
*/
|
|
162
|
+
declare function submitEvmNftWithdrawal(clients: EvmBridgeClients, sig: WithdrawalSignatureResponse): Promise<Hex>;
|
|
163
|
+
/**
|
|
164
|
+
* Submits a server-signed ERC-721 unique game-NFT withdrawal on-chain via the ItemBridge's
|
|
165
|
+
* `withdrawERC721Mint` (MINT voucher, tag "ERC721_MINT"; `sig.ContractAddress` = bridge,
|
|
166
|
+
* `sig.TokenAddress` = collection) — not RewardPool's custody `withdrawERC721`.
|
|
167
|
+
*/
|
|
168
|
+
declare function submitEvmNftWithdrawal721(clients: EvmBridgeClients, sig: WithdrawalSignatureResponse): Promise<Hex>;
|
|
169
|
+
interface WithdrawTokenEvmParams {
|
|
170
|
+
client: IDosGamesClient;
|
|
171
|
+
clients: EvmBridgeClients;
|
|
172
|
+
currencyID: string;
|
|
173
|
+
networkID: string;
|
|
174
|
+
/** Destination wallet — usually the connected `clients.account`. */
|
|
175
|
+
walletAddress: string;
|
|
176
|
+
/** Human decimal amount to withdraw (the server converts and signs raw units). */
|
|
177
|
+
amount: string;
|
|
178
|
+
category?: string;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Full EVM token-withdrawal flow: `requestTokenWithdrawal` (debits in-game immediately and returns
|
|
182
|
+
* a signed payload) → `withdrawERC20` on-chain → `confirmWithdrawal` with the resulting hash.
|
|
183
|
+
*
|
|
184
|
+
* On a failure AFTER the request succeeded, the returned {@link BridgeFailure} carries
|
|
185
|
+
* `titleTransactionID` (the asset is already debited — recover with `retryWithdrawal` while
|
|
186
|
+
* Pending, or `confirmWithdrawal` if the tx actually landed) and, when the on-chain leg landed,
|
|
187
|
+
* `onChainTxHash`. Never restart with a fresh `requestTokenWithdrawal` — that debits twice.
|
|
188
|
+
*/
|
|
189
|
+
declare function withdrawTokenEvm(params: WithdrawTokenEvmParams): Promise<BridgeResult<TokenWithdrawalResponse>>;
|
|
190
|
+
interface WithdrawNftEvmParams {
|
|
191
|
+
client: IDosGamesClient;
|
|
192
|
+
clients: EvmBridgeClients;
|
|
193
|
+
itemID: string;
|
|
194
|
+
networkID: string;
|
|
195
|
+
walletAddress: string;
|
|
196
|
+
/** Copies to withdraw, as an integer string (usually "1"). */
|
|
197
|
+
amount: string;
|
|
198
|
+
category?: string;
|
|
199
|
+
}
|
|
200
|
+
/** Full EVM NFT-withdrawal flow: `requestNFTWithdrawal` → `withdrawERC1155` → `confirmWithdrawal`. */
|
|
201
|
+
declare function withdrawNftEvm(params: WithdrawNftEvmParams): Promise<BridgeResult<NFTWithdrawalResponse>>;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* The on-chain half of the Solana bridge, delegated to the title's own program integration.
|
|
205
|
+
*
|
|
206
|
+
* Unlike EVM — where the RewardPool ABI is fully known and viem builds the calls — the Solana
|
|
207
|
+
* RewardPool is a custom program whose instruction/account layout (DepositSpl, withdraw_spl + the
|
|
208
|
+
* ed25519 sig-verify instruction) lives in that program's IDL, NOT in this client SDK. So the
|
|
209
|
+
* bridge asks you to provide these two calls, built with your program's IDL / `@solana/web3.js`
|
|
210
|
+
* (or Anchor) against the connected wallet from `@solana/wallet-adapter-react`. The SDK-side
|
|
211
|
+
* orchestration (request → submit → confirm, deposit → report) is identical to EVM and handled by
|
|
212
|
+
* {@link depositTokenSolana} / {@link withdrawTokenSolana}.
|
|
213
|
+
*/
|
|
214
|
+
interface SolanaProgramAdapter {
|
|
215
|
+
/**
|
|
216
|
+
* Builds and sends the on-chain `DepositSpl` transfer of `amountRaw` base units of `mint` into
|
|
217
|
+
* the platform program pool, embedding the identifiers the backend reads back
|
|
218
|
+
* (`GetDepositSplCallDetailsBySignature` verifies `userID`). Returns the transaction signature.
|
|
219
|
+
*/
|
|
220
|
+
depositSpl(params: {
|
|
221
|
+
mint: string;
|
|
222
|
+
amountRaw: bigint;
|
|
223
|
+
userID: string;
|
|
224
|
+
titleID: string;
|
|
225
|
+
category: string;
|
|
226
|
+
}): Promise<string>;
|
|
227
|
+
/**
|
|
228
|
+
* Builds and sends the on-chain `withdraw_spl` transaction from a server-issued signature
|
|
229
|
+
* payload — including the ed25519 sig-verify instruction at `SigIxIndex` carrying
|
|
230
|
+
* `Ed25519PublicKey`/`Ed25519Message`/`SignatureHex`. Returns the transaction signature.
|
|
231
|
+
*/
|
|
232
|
+
submitWithdrawal(sig: SolanaWithdrawalSignature): Promise<string>;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
interface DepositTokenSolanaParams {
|
|
236
|
+
client: IDosGamesClient;
|
|
237
|
+
adapter: SolanaProgramAdapter;
|
|
238
|
+
network: BlockchainNetworkDefinition;
|
|
239
|
+
/** SPL mint of the token being deposited. */
|
|
240
|
+
mint: string;
|
|
241
|
+
/** Raw base-unit amount (already scaled by the mint's decimals). */
|
|
242
|
+
amountRaw: bigint;
|
|
243
|
+
titleID: string;
|
|
244
|
+
category?: string;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Full Solana token-deposit flow: your {@link SolanaProgramAdapter.depositSpl} sends the on-chain
|
|
248
|
+
* transfer, then `client.blockchain.depositToken` reports the signature so the backend verifies
|
|
249
|
+
* and credits the in-game balance. Mirrors {@link depositTokenEvm}.
|
|
250
|
+
*/
|
|
251
|
+
declare function depositTokenSolana(params: DepositTokenSolanaParams): Promise<BridgeResult<DepositTokenResponse>>;
|
|
252
|
+
interface WithdrawTokenSolanaParams {
|
|
253
|
+
client: IDosGamesClient;
|
|
254
|
+
adapter: SolanaProgramAdapter;
|
|
255
|
+
currencyID: string;
|
|
256
|
+
networkID: string;
|
|
257
|
+
walletAddress: string;
|
|
258
|
+
amount: string;
|
|
259
|
+
category?: string;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Full Solana token-withdrawal flow: `requestTokenWithdrawal` → your
|
|
263
|
+
* {@link SolanaProgramAdapter.submitWithdrawal} sends the `withdraw_spl` tx → `confirmWithdrawal`.
|
|
264
|
+
* Same recovery semantics as EVM: a post-request failure carries `titleTransactionID` (already
|
|
265
|
+
* debited — retry, don't re-request). Mirrors {@link withdrawTokenEvm}.
|
|
266
|
+
*/
|
|
267
|
+
declare function withdrawTokenSolana(params: WithdrawTokenSolanaParams): Promise<BridgeResult<TokenWithdrawalResponse>>;
|
|
268
|
+
|
|
269
|
+
export { writeAndWait as A, type BridgeFailure as B, type DepositNft721EvmParams as D, type EvmBridgeClients as E, 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, bridgeFail as m, depositNftEvm as n, depositNftEvm721 as o, depositTokenEvm as p, depositTokenSolana as q, ensureErc20Allowance as r, submitEvmNftWithdrawal as s, submitEvmNftWithdrawal721 as t, submitEvmTokenWithdrawal as u, toErrorMessage as v, walletLoginFail as w, withdrawNftEvm as x, withdrawTokenEvm as y, withdrawTokenSolana as z };
|
|
@@ -0,0 +1 @@
|
|
|
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 w(e,t){return {ok:false,stage:e,error:t}}var h=[{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:[]}],D=[{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"}]}],A=[{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"}]}],x=[{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 f(e,t){let{walletClient:n,publicClient:i,account:c}=e,o=await n.writeContract({address:t.address,abi:t.abi,functionName:t.functionName,args:t.args,account:c,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 I(e){let t=e.PlatformPoolAddress;return t||null}async function T(e,t,n,i){return await e.publicClient.readContract({address:t,abi:k,functionName:"allowance",args:[e.account,n]})>=i?null:f(e,{address:t,abi:k,functionName:"approve",args:[n,i]})}async function S(e){let{client:t,clients:n,network:i,tokenAddress:c,amount:o,titleID:p,category:u}=e,r=t.auth.context?.userID;if(!r)return a("approve","Not logged in.");let d=I(i);if(!d)return a("approve","Network has no PlatformPoolAddress.");if(o<=0n)return a("approve","Amount must be positive.");try{await T(n,c,d,o);}catch(m){return a("approve",g(m))}let s;try{s=await f(n,{address:d,abi:h,functionName:"depositERC20",args:[c,o,r,p,u??""]});}catch(m){return a("deposit-onchain",g(m))}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 R(e){let{client:t,clients:n,network:i,nftContractAddress:c,tokenId:o,amount:p,titleID:u,category:r}=e,d=t.auth.context?.userID;if(!d)return a("deposit-onchain","Not logged in.");let s=I(i);if(!s)return a("deposit-onchain","Network has no PlatformPoolAddress.");if(p<=0n)return a("deposit-onchain","Amount must be positive.");let l=b(d,u,r),m;try{m=await f(n,{address:c,abi:A,functionName:"safeTransferFrom",args:[n.account,s,o,p,l]});}catch(E){return a("deposit-onchain",g(E))}let y=await t.blockchain.depositNFT(i.NetworkID??"",m);return y.ok?{ok:true,onChainTxHash:m,data:y.data}:a("report",y.error,{onChainTxHash:m})}async function H(e){let{client:t,clients:n,network:i,nftContractAddress:c,tokenId:o,titleID:p,category:u}=e,r=t.auth.context?.userID;if(!r)return a("deposit-onchain","Not logged in.");let d=I(i);if(!d)return a("deposit-onchain","Network has no PlatformPoolAddress.");let s=b(r,p,u),l;try{l=await f(n,{address:c,abi:x,functionName:"safeTransferFrom",args:[n.account,d,o,s]});}catch(y){return a("deposit-onchain",g(y))}let m=await t.blockchain.depositNFT(i.NetworkID??"",l);return m.ok?{ok:true,onChainTxHash:l,data:m.data}:a("report",m.error,{onChainTxHash:l})}async function C(e,t){return f(e,{address:t.ContractAddress,abi:h,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 W(e,t){return f(e,{address:t.ContractAddress,abi:D,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 M(e,t){return f(e,{address:t.ContractAddress,abi:D,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 F(e){let{client:t,clients:n,currencyID:i,networkID:c,walletAddress:o,amount:p,category:u}=e,r=await t.blockchain.requestTokenWithdrawal(i,c,o,p,u);if(!r.ok)return a("request",r.error);let d=r.data.EvmSignature,s=r.data.TitleTransactionID??void 0;if(!d)return a("request","Withdrawal response carried no EVM signature.",{titleTransactionID:s});let l;try{l=await C(n,d);}catch(y){return a("withdraw-onchain",g(y),{titleTransactionID:s})}let m=await v(t,s,l);return m.ok?{ok:true,onChainTxHash:l,data:r.data}:m}async function L(e){let{client:t,clients:n,itemID:i,networkID:c,walletAddress:o,amount:p,category:u}=e,r=await t.blockchain.requestNFTWithdrawal(i,c,o,p,u);if(!r.ok)return a("request",r.error);let d=r.data.EvmSignature,s=r.data.TitleTransactionID??void 0;if(!d)return a("request","Withdrawal response carried no EVM signature.",{titleTransactionID:s});let l;try{l=await W(n,d);}catch(y){return a("withdraw-onchain",g(y),{titleTransactionID:s})}let m=await v(t,s,l);return m.ok?{ok:true,onChainTxHash:l,data:r.data}:m}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 G(e){let{client:t,clients:n,networkID:i}=e,c=e.walletAddress??n.account,o=await t.auth.requestWalletChallenge(c,i);if(!o.ok)return w("challenge",o.error);let p;try{p=await n.walletClient.signMessage({account:n.account,message:o.data.Message});}catch(r){return w("sign",g(r))}let u=await t.auth.loginWithWallet(c,i,p);return u.ok?{ok:true,data:u.data}:w("login",u.error)}async function U(e){let{client:t,adapter:n,network:i,mint:c,amountRaw:o,titleID:p,category:u}=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 d;try{d=await n.depositSpl({mint:c,amountRaw:o,userID:r,titleID:p,category:normalizeBlockchainCategory(u)});}catch(l){return a("deposit-onchain",g(l))}let s=await t.blockchain.depositToken(i.NetworkID??"",d);return s.ok?{ok:true,onChainTxHash:d,data:s.data}:a("report",s.error,{onChainTxHash:d})}async function O(e){let{client:t,adapter:n,currencyID:i,networkID:c,walletAddress:o,amount:p,category:u}=e,r=await t.blockchain.requestTokenWithdrawal(i,c,o,p,u);if(!r.ok)return a("request",r.error);let d=r.data.SolanaSignature,s=r.data.TitleTransactionID??void 0;if(!d)return a("request","Withdrawal response carried no Solana signature.",{titleTransactionID:s});let l;try{l=await n.submitWithdrawal(d);}catch(y){return a("withdraw-onchain",g(y),{titleTransactionID:s})}if(!s)return a("confirm","Missing TitleTransactionID.",{onChainTxHash:l});let m=await t.blockchain.confirmWithdrawal(s,l);return m.ok?{ok:true,onChainTxHash:l,data:r.data}:a("confirm",m.error,{onChainTxHash:l,titleTransactionID:s})}async function z(e){let{client:t,networkID:n,walletAddress:i,signMessage:c}=e,o=await t.auth.requestWalletChallenge(i,n);if(!o.ok)return w("challenge",o.error);let p;try{let r=await c(new TextEncoder().encode(o.data.Message));p=V(r);}catch(r){return w("sign",g(r))}let u=await t.auth.loginWithWallet(i,n,p);return u.ok?{ok:true,data:u.data}:w("login",u.error)}function V(e){let t="0x";for(let n of e)t+=n.toString(16).padStart(2,"0");return t}export{g as a,a as b,w as c,h as d,k as e,A as f,x as g,b as h,f as i,T as j,S as k,R as l,H as m,C as n,W as o,M as p,F as q,L as r,G as s,U as t,O as u,z as v};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var viem=require('viem'),core=require('@idosgames/core');function g(e){return e instanceof viem.BaseError?e.shortMessage:e instanceof Error?e.message:String(e)}function a(e,t,n){return {ok:false,stage:e,error:t,...n}}function w(e,t){return {ok:false,stage:e,error:t}}var h=[{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:[]}],D=[{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"}]}],x=[{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"}]}],A=[{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 viem.encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[e,t,core.normalizeBlockchainCategory(n)])}async function f(e,t){let{walletClient:n,publicClient:i,account:c}=e,o=await n.writeContract({address:t.address,abi:t.abi,functionName:t.functionName,args:t.args,account:c,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 I(e){let t=e.PlatformPoolAddress;return t||null}async function T(e,t,n,i){return await e.publicClient.readContract({address:t,abi:k,functionName:"allowance",args:[e.account,n]})>=i?null:f(e,{address:t,abi:k,functionName:"approve",args:[n,i]})}async function S(e){let{client:t,clients:n,network:i,tokenAddress:c,amount:o,titleID:p,category:u}=e,r=t.auth.context?.userID;if(!r)return a("approve","Not logged in.");let d=I(i);if(!d)return a("approve","Network has no PlatformPoolAddress.");if(o<=0n)return a("approve","Amount must be positive.");try{await T(n,c,d,o);}catch(m){return a("approve",g(m))}let s;try{s=await f(n,{address:d,abi:h,functionName:"depositERC20",args:[c,o,r,p,u??""]});}catch(m){return a("deposit-onchain",g(m))}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 R(e){let{client:t,clients:n,network:i,nftContractAddress:c,tokenId:o,amount:p,titleID:u,category:r}=e,d=t.auth.context?.userID;if(!d)return a("deposit-onchain","Not logged in.");let s=I(i);if(!s)return a("deposit-onchain","Network has no PlatformPoolAddress.");if(p<=0n)return a("deposit-onchain","Amount must be positive.");let l=b(d,u,r),m;try{m=await f(n,{address:c,abi:x,functionName:"safeTransferFrom",args:[n.account,s,o,p,l]});}catch(E){return a("deposit-onchain",g(E))}let y=await t.blockchain.depositNFT(i.NetworkID??"",m);return y.ok?{ok:true,onChainTxHash:m,data:y.data}:a("report",y.error,{onChainTxHash:m})}async function F(e){let{client:t,clients:n,network:i,nftContractAddress:c,tokenId:o,titleID:p,category:u}=e,r=t.auth.context?.userID;if(!r)return a("deposit-onchain","Not logged in.");let d=I(i);if(!d)return a("deposit-onchain","Network has no PlatformPoolAddress.");let s=b(r,p,u),l;try{l=await f(n,{address:c,abi:A,functionName:"safeTransferFrom",args:[n.account,d,o,s]});}catch(y){return a("deposit-onchain",g(y))}let m=await t.blockchain.depositNFT(i.NetworkID??"",l);return m.ok?{ok:true,onChainTxHash:l,data:m.data}:a("report",m.error,{onChainTxHash:l})}async function C(e,t){return f(e,{address:t.ContractAddress,abi:h,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 W(e,t){return f(e,{address:t.ContractAddress,abi:D,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 M(e,t){return f(e,{address:t.ContractAddress,abi:D,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 H(e){let{client:t,clients:n,currencyID:i,networkID:c,walletAddress:o,amount:p,category:u}=e,r=await t.blockchain.requestTokenWithdrawal(i,c,o,p,u);if(!r.ok)return a("request",r.error);let d=r.data.EvmSignature,s=r.data.TitleTransactionID??void 0;if(!d)return a("request","Withdrawal response carried no EVM signature.",{titleTransactionID:s});let l;try{l=await C(n,d);}catch(y){return a("withdraw-onchain",g(y),{titleTransactionID:s})}let m=await v(t,s,l);return m.ok?{ok:true,onChainTxHash:l,data:r.data}:m}async function L(e){let{client:t,clients:n,itemID:i,networkID:c,walletAddress:o,amount:p,category:u}=e,r=await t.blockchain.requestNFTWithdrawal(i,c,o,p,u);if(!r.ok)return a("request",r.error);let d=r.data.EvmSignature,s=r.data.TitleTransactionID??void 0;if(!d)return a("request","Withdrawal response carried no EVM signature.",{titleTransactionID:s});let l;try{l=await W(n,d);}catch(y){return a("withdraw-onchain",g(y),{titleTransactionID:s})}let m=await v(t,s,l);return m.ok?{ok:true,onChainTxHash:l,data:r.data}:m}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 G(e){let{client:t,clients:n,networkID:i}=e,c=e.walletAddress??n.account,o=await t.auth.requestWalletChallenge(c,i);if(!o.ok)return w("challenge",o.error);let p;try{p=await n.walletClient.signMessage({account:n.account,message:o.data.Message});}catch(r){return w("sign",g(r))}let u=await t.auth.loginWithWallet(c,i,p);return u.ok?{ok:true,data:u.data}:w("login",u.error)}async function U(e){let{client:t,adapter:n,network:i,mint:c,amountRaw:o,titleID:p,category:u}=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 d;try{d=await n.depositSpl({mint:c,amountRaw:o,userID:r,titleID:p,category:core.normalizeBlockchainCategory(u)});}catch(l){return a("deposit-onchain",g(l))}let s=await t.blockchain.depositToken(i.NetworkID??"",d);return s.ok?{ok:true,onChainTxHash:d,data:s.data}:a("report",s.error,{onChainTxHash:d})}async function O(e){let{client:t,adapter:n,currencyID:i,networkID:c,walletAddress:o,amount:p,category:u}=e,r=await t.blockchain.requestTokenWithdrawal(i,c,o,p,u);if(!r.ok)return a("request",r.error);let d=r.data.SolanaSignature,s=r.data.TitleTransactionID??void 0;if(!d)return a("request","Withdrawal response carried no Solana signature.",{titleTransactionID:s});let l;try{l=await n.submitWithdrawal(d);}catch(y){return a("withdraw-onchain",g(y),{titleTransactionID:s})}if(!s)return a("confirm","Missing TitleTransactionID.",{onChainTxHash:l});let m=await t.blockchain.confirmWithdrawal(s,l);return m.ok?{ok:true,onChainTxHash:l,data:r.data}:a("confirm",m.error,{onChainTxHash:l,titleTransactionID:s})}async function z(e){let{client:t,networkID:n,walletAddress:i,signMessage:c}=e,o=await t.auth.requestWalletChallenge(i,n);if(!o.ok)return w("challenge",o.error);let p;try{let r=await c(new TextEncoder().encode(o.data.Message));p=V(r);}catch(r){return w("sign",g(r))}let u=await t.auth.loginWithWallet(i,n,p);return u.ok?{ok:true,data:u.data}:w("login",u.error)}function V(e){let t="0x";for(let n of e)t+=n.toString(16).padStart(2,"0");return t}exports.bridgeFail=a;exports.depositNftEvm=R;exports.depositNftEvm721=F;exports.depositTokenEvm=S;exports.depositTokenSolana=U;exports.encodeNftDepositData=b;exports.ensureErc20Allowance=T;exports.erc1155Abi=x;exports.erc20Abi=k;exports.erc721Abi=A;exports.loginWithWalletEvm=G;exports.loginWithWalletSolana=z;exports.rewardPoolAbi=h;exports.submitEvmNftWithdrawal=W;exports.submitEvmNftWithdrawal721=M;exports.submitEvmTokenWithdrawal=C;exports.toErrorMessage=g;exports.walletLoginFail=w;exports.withdrawNftEvm=L;exports.withdrawTokenEvm=H;exports.withdrawTokenSolana=O;exports.writeAndWait=f;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { E as EvmBridgeClients, W as WalletLoginResult } from './bridge-BCxf6AHE.cjs';
|
|
2
|
+
export { B as BridgeFailure, a as BridgeResult, b as BridgeStage, c as BridgeSuccess, D as DepositNft721EvmParams, d as DepositNftEvmParams, e as DepositTokenEvmParams, f as DepositTokenSolanaParams, S as SolanaProgramAdapter, g as WalletLoginFailure, h as WalletLoginStage, i as WalletLoginSuccess, j as WithdrawNftEvmParams, k as WithdrawTokenEvmParams, l as WithdrawTokenSolanaParams, m as bridgeFail, n as depositNftEvm, o as depositNftEvm721, p as depositTokenEvm, q as depositTokenSolana, r as ensureErc20Allowance, s as submitEvmNftWithdrawal, t as submitEvmNftWithdrawal721, u as submitEvmTokenWithdrawal, v as toErrorMessage, w as walletLoginFail, x as withdrawNftEvm, y as withdrawTokenEvm, z as withdrawTokenSolana, A as writeAndWait } from './bridge-BCxf6AHE.cjs';
|
|
3
|
+
import { Hex } from 'viem';
|
|
4
|
+
import { IDosGamesClient, ClientState } from '@idosgames/core';
|
|
5
|
+
|
|
6
|
+
declare const rewardPoolAbi: readonly [{
|
|
7
|
+
readonly type: "function";
|
|
8
|
+
readonly name: "depositERC20";
|
|
9
|
+
readonly stateMutability: "nonpayable";
|
|
10
|
+
readonly inputs: readonly [{
|
|
11
|
+
readonly name: "token";
|
|
12
|
+
readonly type: "address";
|
|
13
|
+
}, {
|
|
14
|
+
readonly name: "amount";
|
|
15
|
+
readonly type: "uint256";
|
|
16
|
+
}, {
|
|
17
|
+
readonly name: "userID";
|
|
18
|
+
readonly type: "string";
|
|
19
|
+
}, {
|
|
20
|
+
readonly name: "titleID";
|
|
21
|
+
readonly type: "string";
|
|
22
|
+
}, {
|
|
23
|
+
readonly name: "category";
|
|
24
|
+
readonly type: "string";
|
|
25
|
+
}];
|
|
26
|
+
readonly outputs: readonly [{
|
|
27
|
+
readonly name: "";
|
|
28
|
+
readonly type: "bool";
|
|
29
|
+
}];
|
|
30
|
+
}, {
|
|
31
|
+
readonly type: "function";
|
|
32
|
+
readonly name: "withdrawERC20";
|
|
33
|
+
readonly stateMutability: "nonpayable";
|
|
34
|
+
readonly inputs: readonly [{
|
|
35
|
+
readonly name: "token";
|
|
36
|
+
readonly type: "address";
|
|
37
|
+
}, {
|
|
38
|
+
readonly name: "to";
|
|
39
|
+
readonly type: "address";
|
|
40
|
+
}, {
|
|
41
|
+
readonly name: "amount";
|
|
42
|
+
readonly type: "uint256";
|
|
43
|
+
}, {
|
|
44
|
+
readonly name: "burnAmount";
|
|
45
|
+
readonly type: "uint256";
|
|
46
|
+
}, {
|
|
47
|
+
readonly name: "nonce";
|
|
48
|
+
readonly type: "uint256";
|
|
49
|
+
}, {
|
|
50
|
+
readonly name: "signature";
|
|
51
|
+
readonly type: "bytes";
|
|
52
|
+
}, {
|
|
53
|
+
readonly name: "userID";
|
|
54
|
+
readonly type: "string";
|
|
55
|
+
}, {
|
|
56
|
+
readonly name: "titleID";
|
|
57
|
+
readonly type: "string";
|
|
58
|
+
}, {
|
|
59
|
+
readonly name: "category";
|
|
60
|
+
readonly type: "string";
|
|
61
|
+
}, {
|
|
62
|
+
readonly name: "deadline";
|
|
63
|
+
readonly type: "uint256";
|
|
64
|
+
}];
|
|
65
|
+
readonly outputs: readonly [];
|
|
66
|
+
}, {
|
|
67
|
+
readonly type: "function";
|
|
68
|
+
readonly name: "withdrawERC1155";
|
|
69
|
+
readonly stateMutability: "nonpayable";
|
|
70
|
+
readonly inputs: readonly [{
|
|
71
|
+
readonly name: "token";
|
|
72
|
+
readonly type: "address";
|
|
73
|
+
}, {
|
|
74
|
+
readonly name: "to";
|
|
75
|
+
readonly type: "address";
|
|
76
|
+
}, {
|
|
77
|
+
readonly name: "id";
|
|
78
|
+
readonly type: "uint256";
|
|
79
|
+
}, {
|
|
80
|
+
readonly name: "amount";
|
|
81
|
+
readonly type: "uint256";
|
|
82
|
+
}, {
|
|
83
|
+
readonly name: "nonce";
|
|
84
|
+
readonly type: "uint256";
|
|
85
|
+
}, {
|
|
86
|
+
readonly name: "signature";
|
|
87
|
+
readonly type: "bytes";
|
|
88
|
+
}, {
|
|
89
|
+
readonly name: "userID";
|
|
90
|
+
readonly type: "string";
|
|
91
|
+
}, {
|
|
92
|
+
readonly name: "titleID";
|
|
93
|
+
readonly type: "string";
|
|
94
|
+
}, {
|
|
95
|
+
readonly name: "category";
|
|
96
|
+
readonly type: "string";
|
|
97
|
+
}, {
|
|
98
|
+
readonly name: "deadline";
|
|
99
|
+
readonly type: "uint256";
|
|
100
|
+
}];
|
|
101
|
+
readonly outputs: readonly [];
|
|
102
|
+
}, {
|
|
103
|
+
readonly type: "function";
|
|
104
|
+
readonly name: "withdrawERC721";
|
|
105
|
+
readonly stateMutability: "nonpayable";
|
|
106
|
+
readonly inputs: readonly [{
|
|
107
|
+
readonly name: "token";
|
|
108
|
+
readonly type: "address";
|
|
109
|
+
}, {
|
|
110
|
+
readonly name: "to";
|
|
111
|
+
readonly type: "address";
|
|
112
|
+
}, {
|
|
113
|
+
readonly name: "tokenId";
|
|
114
|
+
readonly type: "uint256";
|
|
115
|
+
}, {
|
|
116
|
+
readonly name: "nonce";
|
|
117
|
+
readonly type: "uint256";
|
|
118
|
+
}, {
|
|
119
|
+
readonly name: "signature";
|
|
120
|
+
readonly type: "bytes";
|
|
121
|
+
}, {
|
|
122
|
+
readonly name: "userID";
|
|
123
|
+
readonly type: "string";
|
|
124
|
+
}, {
|
|
125
|
+
readonly name: "titleID";
|
|
126
|
+
readonly type: "string";
|
|
127
|
+
}, {
|
|
128
|
+
readonly name: "category";
|
|
129
|
+
readonly type: "string";
|
|
130
|
+
}, {
|
|
131
|
+
readonly name: "deadline";
|
|
132
|
+
readonly type: "uint256";
|
|
133
|
+
}];
|
|
134
|
+
readonly outputs: readonly [];
|
|
135
|
+
}];
|
|
136
|
+
/** Minimal ERC-20 surface the bridge needs (approve/allowance for deposits, decimals/balance for UX). */
|
|
137
|
+
declare const erc20Abi: readonly [{
|
|
138
|
+
readonly type: "function";
|
|
139
|
+
readonly name: "approve";
|
|
140
|
+
readonly stateMutability: "nonpayable";
|
|
141
|
+
readonly inputs: readonly [{
|
|
142
|
+
readonly name: "spender";
|
|
143
|
+
readonly type: "address";
|
|
144
|
+
}, {
|
|
145
|
+
readonly name: "amount";
|
|
146
|
+
readonly type: "uint256";
|
|
147
|
+
}];
|
|
148
|
+
readonly outputs: readonly [{
|
|
149
|
+
readonly name: "";
|
|
150
|
+
readonly type: "bool";
|
|
151
|
+
}];
|
|
152
|
+
}, {
|
|
153
|
+
readonly type: "function";
|
|
154
|
+
readonly name: "allowance";
|
|
155
|
+
readonly stateMutability: "view";
|
|
156
|
+
readonly inputs: readonly [{
|
|
157
|
+
readonly name: "owner";
|
|
158
|
+
readonly type: "address";
|
|
159
|
+
}, {
|
|
160
|
+
readonly name: "spender";
|
|
161
|
+
readonly type: "address";
|
|
162
|
+
}];
|
|
163
|
+
readonly outputs: readonly [{
|
|
164
|
+
readonly name: "";
|
|
165
|
+
readonly type: "uint256";
|
|
166
|
+
}];
|
|
167
|
+
}, {
|
|
168
|
+
readonly type: "function";
|
|
169
|
+
readonly name: "decimals";
|
|
170
|
+
readonly stateMutability: "view";
|
|
171
|
+
readonly inputs: readonly [];
|
|
172
|
+
readonly outputs: readonly [{
|
|
173
|
+
readonly name: "";
|
|
174
|
+
readonly type: "uint8";
|
|
175
|
+
}];
|
|
176
|
+
}, {
|
|
177
|
+
readonly type: "function";
|
|
178
|
+
readonly name: "balanceOf";
|
|
179
|
+
readonly stateMutability: "view";
|
|
180
|
+
readonly inputs: readonly [{
|
|
181
|
+
readonly name: "account";
|
|
182
|
+
readonly type: "address";
|
|
183
|
+
}];
|
|
184
|
+
readonly outputs: readonly [{
|
|
185
|
+
readonly name: "";
|
|
186
|
+
readonly type: "uint256";
|
|
187
|
+
}];
|
|
188
|
+
}];
|
|
189
|
+
/**
|
|
190
|
+
* Minimal ERC-1155 surface. NFT deposits go through the collection contract's own
|
|
191
|
+
* `safeTransferFrom(from, to=pool, id, amount, data)`, where `data` carries the ABI-encoded
|
|
192
|
+
* (userID, titleID, category) the receiving RewardPool decodes — see {@link encodeNftDepositData}.
|
|
193
|
+
*/
|
|
194
|
+
declare const erc1155Abi: readonly [{
|
|
195
|
+
readonly type: "function";
|
|
196
|
+
readonly name: "safeTransferFrom";
|
|
197
|
+
readonly stateMutability: "nonpayable";
|
|
198
|
+
readonly inputs: readonly [{
|
|
199
|
+
readonly name: "from";
|
|
200
|
+
readonly type: "address";
|
|
201
|
+
}, {
|
|
202
|
+
readonly name: "to";
|
|
203
|
+
readonly type: "address";
|
|
204
|
+
}, {
|
|
205
|
+
readonly name: "id";
|
|
206
|
+
readonly type: "uint256";
|
|
207
|
+
}, {
|
|
208
|
+
readonly name: "amount";
|
|
209
|
+
readonly type: "uint256";
|
|
210
|
+
}, {
|
|
211
|
+
readonly name: "data";
|
|
212
|
+
readonly type: "bytes";
|
|
213
|
+
}];
|
|
214
|
+
readonly outputs: readonly [];
|
|
215
|
+
}, {
|
|
216
|
+
readonly type: "function";
|
|
217
|
+
readonly name: "isApprovedForAll";
|
|
218
|
+
readonly stateMutability: "view";
|
|
219
|
+
readonly inputs: readonly [{
|
|
220
|
+
readonly name: "account";
|
|
221
|
+
readonly type: "address";
|
|
222
|
+
}, {
|
|
223
|
+
readonly name: "operator";
|
|
224
|
+
readonly type: "address";
|
|
225
|
+
}];
|
|
226
|
+
readonly outputs: readonly [{
|
|
227
|
+
readonly name: "";
|
|
228
|
+
readonly type: "bool";
|
|
229
|
+
}];
|
|
230
|
+
}, {
|
|
231
|
+
readonly type: "function";
|
|
232
|
+
readonly name: "setApprovalForAll";
|
|
233
|
+
readonly stateMutability: "nonpayable";
|
|
234
|
+
readonly inputs: readonly [{
|
|
235
|
+
readonly name: "operator";
|
|
236
|
+
readonly type: "address";
|
|
237
|
+
}, {
|
|
238
|
+
readonly name: "approved";
|
|
239
|
+
readonly type: "bool";
|
|
240
|
+
}];
|
|
241
|
+
readonly outputs: readonly [];
|
|
242
|
+
}, {
|
|
243
|
+
readonly type: "function";
|
|
244
|
+
readonly name: "balanceOf";
|
|
245
|
+
readonly stateMutability: "view";
|
|
246
|
+
readonly inputs: readonly [{
|
|
247
|
+
readonly name: "account";
|
|
248
|
+
readonly type: "address";
|
|
249
|
+
}, {
|
|
250
|
+
readonly name: "id";
|
|
251
|
+
readonly type: "uint256";
|
|
252
|
+
}];
|
|
253
|
+
readonly outputs: readonly [{
|
|
254
|
+
readonly name: "";
|
|
255
|
+
readonly type: "uint256";
|
|
256
|
+
}];
|
|
257
|
+
}];
|
|
258
|
+
/**
|
|
259
|
+
* Minimal ERC-721 surface. NFT deposits go through the collection contract's own 4-arg
|
|
260
|
+
* `safeTransferFrom(from, to=pool, tokenId, data)`, where `data` carries the ABI-encoded
|
|
261
|
+
* (userID, titleID, category) the receiving RewardPool decodes — see {@link encodeNftDepositData}.
|
|
262
|
+
*/
|
|
263
|
+
declare const erc721Abi: readonly [{
|
|
264
|
+
readonly type: "function";
|
|
265
|
+
readonly name: "safeTransferFrom";
|
|
266
|
+
readonly stateMutability: "nonpayable";
|
|
267
|
+
readonly inputs: readonly [{
|
|
268
|
+
readonly name: "from";
|
|
269
|
+
readonly type: "address";
|
|
270
|
+
}, {
|
|
271
|
+
readonly name: "to";
|
|
272
|
+
readonly type: "address";
|
|
273
|
+
}, {
|
|
274
|
+
readonly name: "tokenId";
|
|
275
|
+
readonly type: "uint256";
|
|
276
|
+
}, {
|
|
277
|
+
readonly name: "data";
|
|
278
|
+
readonly type: "bytes";
|
|
279
|
+
}];
|
|
280
|
+
readonly outputs: readonly [];
|
|
281
|
+
}];
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Builds the `data` blob for an ERC-1155 NFT deposit's `safeTransferFrom`.
|
|
285
|
+
*
|
|
286
|
+
* The updated RewardPool decodes this as `abi.encode(string userID, string titleID, string
|
|
287
|
+
* category)` — see RewardPoolEvmV2.GetDepositIdsFromNftTransferData / DepositIdsOutput on the
|
|
288
|
+
* backend. The three fields must be a non-packed ABI encode of exactly (string, string, string)
|
|
289
|
+
* in that order, or the receiver can't attribute the deposit and the backend rejects it with
|
|
290
|
+
* "Cannot extract userID from transaction."
|
|
291
|
+
*/
|
|
292
|
+
declare function encodeNftDepositData(userID: string, titleID: string, category?: string): Hex;
|
|
293
|
+
|
|
294
|
+
interface LoginWithWalletEvmParams {
|
|
295
|
+
client: IDosGamesClient;
|
|
296
|
+
clients: EvmBridgeClients;
|
|
297
|
+
/** NetworkID (key of cfg.Blockchain.Networks) the wallet proves ownership on. Must be an EVM network. */
|
|
298
|
+
networkID: string;
|
|
299
|
+
/** Address to authenticate; defaults to the connected `clients.account`. */
|
|
300
|
+
walletAddress?: string;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Full EVM wallet-login flow: `requestWalletChallenge` → `personal_sign` the returned message with
|
|
304
|
+
* the connected wallet → `loginWithWallet`. On success the core client is logged in (auth context
|
|
305
|
+
* applied, client state fetched) and the fresh {@link ClientState} is returned.
|
|
306
|
+
*
|
|
307
|
+
* No on-chain transaction and no gas — this is an off-chain signature proving wallet ownership.
|
|
308
|
+
* A user-rejected signature surfaces as a `{ ok: false, stage: "sign" }` failure, not a throw.
|
|
309
|
+
*/
|
|
310
|
+
declare function loginWithWalletEvm(params: LoginWithWalletEvmParams): Promise<WalletLoginResult<ClientState>>;
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* A wallet-adapter message signer: signs raw bytes and returns the 64-byte ed25519 signature.
|
|
314
|
+
* This is exactly the shape of `@solana/wallet-adapter-react`'s `useWallet().signMessage`.
|
|
315
|
+
*/
|
|
316
|
+
type SolanaMessageSigner = (message: Uint8Array) => Promise<Uint8Array>;
|
|
317
|
+
interface LoginWithWalletSolanaParams {
|
|
318
|
+
client: IDosGamesClient;
|
|
319
|
+
/** NetworkID (key of cfg.Blockchain.Networks) the wallet proves ownership on. Must be a Solana network. */
|
|
320
|
+
networkID: string;
|
|
321
|
+
/** The connected wallet's base58 address (owner pubkey). */
|
|
322
|
+
walletAddress: string;
|
|
323
|
+
/** The connected wallet's message signer (e.g. `useWallet().signMessage`). */
|
|
324
|
+
signMessage: SolanaMessageSigner;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Full Solana wallet-login flow: `requestWalletChallenge` → sign the returned message bytes with
|
|
328
|
+
* the connected wallet (`signMessage`) → `loginWithWallet`. The signature is sent as 0x-hex, which
|
|
329
|
+
* the backend decodes unambiguously (base58/base64 ed25519 signatures can collide with each other's
|
|
330
|
+
* alphabets, so hex avoids the guesswork). On success the core client is logged in and the fresh
|
|
331
|
+
* {@link ClientState} is returned. No on-chain transaction — off-chain proof of ownership only.
|
|
332
|
+
*/
|
|
333
|
+
declare function loginWithWalletSolana(params: LoginWithWalletSolanaParams): Promise<WalletLoginResult<ClientState>>;
|
|
334
|
+
|
|
335
|
+
export { EvmBridgeClients, type LoginWithWalletEvmParams, type LoginWithWalletSolanaParams, type SolanaMessageSigner, WalletLoginResult, encodeNftDepositData, erc1155Abi, erc20Abi, erc721Abi, loginWithWalletEvm, loginWithWalletSolana, rewardPoolAbi };
|