@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.
@@ -0,0 +1,148 @@
1
+ import { PublicClient, WalletClient, Address, Abi, ContractFunctionName, ContractFunctionArgs, Hex } from 'viem';
2
+ import { IDosGamesClient, BlockchainNetworkDefinition, DepositNFTResponse, DepositTokenResponse, WithdrawalSignatureResponse, NFTWithdrawalResponse, TokenWithdrawalResponse } from '@idosgames/core';
3
+ import { b as BridgeResult } from './chains-DMjdV7VV.js';
4
+
5
+ /**
6
+ * The viem clients + signing account the EVM bridge needs. wagmi supplies all three:
7
+ * `usePublicClient()`, `useWalletClient().data`, and `useAccount().address`. Kept as plain viem
8
+ * types so the framework-agnostic core never imports wagmi/React.
9
+ */
10
+ interface EvmBridgeClients {
11
+ publicClient: PublicClient;
12
+ walletClient: WalletClient;
13
+ /** The connected wallet address that signs and pays for the transactions. */
14
+ account: Address;
15
+ }
16
+ /**
17
+ * Sends a contract write and waits for its receipt, returning the tx hash. Throws if the
18
+ * transaction reverts on-chain (so callers can attribute the failure to the on-chain stage).
19
+ */
20
+ declare function writeAndWait<const TAbi extends Abi, TFunctionName extends ContractFunctionName<TAbi, "nonpayable" | "payable">>(clients: EvmBridgeClients, request: {
21
+ address: Address;
22
+ abi: TAbi;
23
+ functionName: TFunctionName;
24
+ args: ContractFunctionArgs<TAbi, "nonpayable" | "payable", TFunctionName>;
25
+ value?: bigint;
26
+ }): Promise<Hex>;
27
+
28
+ /**
29
+ * Ensures the RewardPool is allowed to pull at least `amount` of an ERC-20 from `account`.
30
+ * Reads the current allowance and only sends an `approve` when it's short. Returns the approve
31
+ * tx hash if one was sent, or null when the existing allowance already covered the amount.
32
+ */
33
+ declare function ensureErc20Allowance(clients: EvmBridgeClients, tokenAddress: Address, spender: Address, amount: bigint): Promise<Hex | null>;
34
+ interface DepositTokenEvmParams {
35
+ client: IDosGamesClient;
36
+ clients: EvmBridgeClients;
37
+ network: BlockchainNetworkDefinition;
38
+ /** ERC-20 contract of the token being deposited (the RewardPool splits/credits it in-game). */
39
+ tokenAddress: Address;
40
+ /** Raw on-chain amount, already scaled by the token's decimals (use viem `parseUnits`). */
41
+ amount: bigint;
42
+ /** The title the client was created for (not exposed on the client — pass it through). */
43
+ titleID: string;
44
+ /** Operation kind; defaults to "game_topup" server-side. Deposits echo it into the tx. */
45
+ category?: string;
46
+ }
47
+ /**
48
+ * Full EVM token-deposit flow: approve (if needed) → `depositERC20(token, amount, userID,
49
+ * titleID, category)` on the RewardPool → report the tx hash to the backend so it verifies the
50
+ * transfer and credits the in-game crypto balance. On success the core cache balance is already
51
+ * updated by `client.blockchain.depositToken`.
52
+ */
53
+ declare function depositTokenEvm(params: DepositTokenEvmParams): Promise<BridgeResult<DepositTokenResponse>>;
54
+ interface DepositNftEvmParams {
55
+ client: IDosGamesClient;
56
+ clients: EvmBridgeClients;
57
+ network: BlockchainNetworkDefinition;
58
+ /** ERC-1155 collection contract holding the NFT. */
59
+ nftContractAddress: Address;
60
+ /** On-chain token id of the NFT being deposited. */
61
+ tokenId: bigint;
62
+ /** Copies to transfer (1 for a unique NFT; ERC-1155 collections can hold fungible editions). */
63
+ amount: bigint;
64
+ titleID: string;
65
+ category?: string;
66
+ }
67
+ /**
68
+ * Full EVM NFT-deposit flow: `safeTransferFrom(account, pool, id, amount, data)` on the ERC-1155
69
+ * collection — where `data = abi.encode(userID, titleID, category)` — then report the tx hash so
70
+ * the backend verifies the transfer and grants the matching in-game item. No operator approval is
71
+ * needed: the player transfers their own token, so msg.sender == from.
72
+ */
73
+ declare function depositNftEvm(params: DepositNftEvmParams): Promise<BridgeResult<DepositNFTResponse>>;
74
+ interface DepositNft721EvmParams {
75
+ client: IDosGamesClient;
76
+ clients: EvmBridgeClients;
77
+ network: BlockchainNetworkDefinition;
78
+ /** ERC-721 collection contract holding the NFT. */
79
+ nftContractAddress: Address;
80
+ /** On-chain token id of the unique NFT being deposited. */
81
+ tokenId: bigint;
82
+ titleID: string;
83
+ category?: string;
84
+ }
85
+ /**
86
+ * Full EVM ERC-721 NFT-deposit flow: `safeTransferFrom(account, pool, tokenId, data)` on the
87
+ * ERC-721 collection — where `data = abi.encode(userID, titleID, category)` — then report the tx
88
+ * hash so the backend verifies the transfer and grants the matching in-game unique item. No
89
+ * operator approval is needed: the player transfers their own token, so msg.sender == from.
90
+ */
91
+ declare function depositNftEvm721(params: DepositNft721EvmParams): Promise<BridgeResult<DepositNFTResponse>>;
92
+
93
+ /**
94
+ * Submits a server-signed ERC-20 withdrawal on-chain by calling `withdrawERC20` on the RewardPool.
95
+ * Every field comes straight from the server's {@link WithdrawalSignatureResponse}; the client
96
+ * only echoes them (Amount and Nonce are decimal strings the server already scaled to raw units,
97
+ * and userID/titleID/category are part of the signed hash — passing anything else reverts). Use
98
+ * this directly to submit a fresh signature from `retryWithdrawal`.
99
+ */
100
+ declare function submitEvmTokenWithdrawal(clients: EvmBridgeClients, sig: WithdrawalSignatureResponse): Promise<Hex>;
101
+ /**
102
+ * Submits a server-signed ERC-1155 game-NFT withdrawal on-chain. The v2 backend signs a MINT voucher
103
+ * (tag "ERC1155_MINT") against the ItemBridge — `sig.ContractAddress` is the bridge and
104
+ * `sig.TokenAddress` is the collection — so this calls `withdrawERC1155Mint`, NOT RewardPool's
105
+ * `withdrawERC1155` (which would fail the selector/hash-tag check).
106
+ */
107
+ declare function submitEvmNftWithdrawal(clients: EvmBridgeClients, sig: WithdrawalSignatureResponse): Promise<Hex>;
108
+ /**
109
+ * Submits a server-signed ERC-721 unique game-NFT withdrawal on-chain via the ItemBridge's
110
+ * `withdrawERC721Mint` (MINT voucher, tag "ERC721_MINT"; `sig.ContractAddress` = bridge,
111
+ * `sig.TokenAddress` = collection) — not RewardPool's custody `withdrawERC721`.
112
+ */
113
+ declare function submitEvmNftWithdrawal721(clients: EvmBridgeClients, sig: WithdrawalSignatureResponse): Promise<Hex>;
114
+ interface WithdrawTokenEvmParams {
115
+ client: IDosGamesClient;
116
+ clients: EvmBridgeClients;
117
+ currencyID: string;
118
+ networkID: string;
119
+ /** Destination wallet — usually the connected `clients.account`. */
120
+ walletAddress: string;
121
+ /** Human decimal amount to withdraw (the server converts and signs raw units). */
122
+ amount: string;
123
+ category?: string;
124
+ }
125
+ /**
126
+ * Full EVM token-withdrawal flow: `requestTokenWithdrawal` (debits in-game immediately and returns
127
+ * a signed payload) → `withdrawERC20` on-chain → `confirmWithdrawal` with the resulting hash.
128
+ *
129
+ * On a failure AFTER the request succeeded, the returned {@link BridgeFailure} carries
130
+ * `titleTransactionID` (the asset is already debited — recover with `retryWithdrawal` while
131
+ * Pending, or `confirmWithdrawal` if the tx actually landed) and, when the on-chain leg landed,
132
+ * `onChainTxHash`. Never restart with a fresh `requestTokenWithdrawal` — that debits twice.
133
+ */
134
+ declare function withdrawTokenEvm(params: WithdrawTokenEvmParams): Promise<BridgeResult<TokenWithdrawalResponse>>;
135
+ interface WithdrawNftEvmParams {
136
+ client: IDosGamesClient;
137
+ clients: EvmBridgeClients;
138
+ itemID: string;
139
+ networkID: string;
140
+ walletAddress: string;
141
+ /** Copies to withdraw, as an integer string (usually "1"). */
142
+ amount: string;
143
+ category?: string;
144
+ }
145
+ /** Full EVM NFT-withdrawal flow: `requestNFTWithdrawal` → `withdrawERC1155` → `confirmWithdrawal`. */
146
+ declare function withdrawNftEvm(params: WithdrawNftEvmParams): Promise<BridgeResult<NFTWithdrawalResponse>>;
147
+
148
+ export { type DepositNft721EvmParams as D, type EvmBridgeClients as E, type WithdrawNftEvmParams as W, type DepositNftEvmParams as a, type DepositTokenEvmParams as b, type WithdrawTokenEvmParams as c, depositNftEvm as d, depositNftEvm721 as e, depositTokenEvm as f, ensureErc20Allowance as g, submitEvmNftWithdrawal721 as h, submitEvmTokenWithdrawal as i, withdrawTokenEvm as j, writeAndWait as k, submitEvmNftWithdrawal as s, withdrawNftEvm as w };
@@ -0,0 +1,148 @@
1
+ import { PublicClient, WalletClient, Address, Abi, ContractFunctionName, ContractFunctionArgs, Hex } from 'viem';
2
+ import { IDosGamesClient, BlockchainNetworkDefinition, DepositNFTResponse, DepositTokenResponse, WithdrawalSignatureResponse, NFTWithdrawalResponse, TokenWithdrawalResponse } from '@idosgames/core';
3
+ import { b as BridgeResult } from './chains-DMjdV7VV.cjs';
4
+
5
+ /**
6
+ * The viem clients + signing account the EVM bridge needs. wagmi supplies all three:
7
+ * `usePublicClient()`, `useWalletClient().data`, and `useAccount().address`. Kept as plain viem
8
+ * types so the framework-agnostic core never imports wagmi/React.
9
+ */
10
+ interface EvmBridgeClients {
11
+ publicClient: PublicClient;
12
+ walletClient: WalletClient;
13
+ /** The connected wallet address that signs and pays for the transactions. */
14
+ account: Address;
15
+ }
16
+ /**
17
+ * Sends a contract write and waits for its receipt, returning the tx hash. Throws if the
18
+ * transaction reverts on-chain (so callers can attribute the failure to the on-chain stage).
19
+ */
20
+ declare function writeAndWait<const TAbi extends Abi, TFunctionName extends ContractFunctionName<TAbi, "nonpayable" | "payable">>(clients: EvmBridgeClients, request: {
21
+ address: Address;
22
+ abi: TAbi;
23
+ functionName: TFunctionName;
24
+ args: ContractFunctionArgs<TAbi, "nonpayable" | "payable", TFunctionName>;
25
+ value?: bigint;
26
+ }): Promise<Hex>;
27
+
28
+ /**
29
+ * Ensures the RewardPool is allowed to pull at least `amount` of an ERC-20 from `account`.
30
+ * Reads the current allowance and only sends an `approve` when it's short. Returns the approve
31
+ * tx hash if one was sent, or null when the existing allowance already covered the amount.
32
+ */
33
+ declare function ensureErc20Allowance(clients: EvmBridgeClients, tokenAddress: Address, spender: Address, amount: bigint): Promise<Hex | null>;
34
+ interface DepositTokenEvmParams {
35
+ client: IDosGamesClient;
36
+ clients: EvmBridgeClients;
37
+ network: BlockchainNetworkDefinition;
38
+ /** ERC-20 contract of the token being deposited (the RewardPool splits/credits it in-game). */
39
+ tokenAddress: Address;
40
+ /** Raw on-chain amount, already scaled by the token's decimals (use viem `parseUnits`). */
41
+ amount: bigint;
42
+ /** The title the client was created for (not exposed on the client — pass it through). */
43
+ titleID: string;
44
+ /** Operation kind; defaults to "game_topup" server-side. Deposits echo it into the tx. */
45
+ category?: string;
46
+ }
47
+ /**
48
+ * Full EVM token-deposit flow: approve (if needed) → `depositERC20(token, amount, userID,
49
+ * titleID, category)` on the RewardPool → report the tx hash to the backend so it verifies the
50
+ * transfer and credits the in-game crypto balance. On success the core cache balance is already
51
+ * updated by `client.blockchain.depositToken`.
52
+ */
53
+ declare function depositTokenEvm(params: DepositTokenEvmParams): Promise<BridgeResult<DepositTokenResponse>>;
54
+ interface DepositNftEvmParams {
55
+ client: IDosGamesClient;
56
+ clients: EvmBridgeClients;
57
+ network: BlockchainNetworkDefinition;
58
+ /** ERC-1155 collection contract holding the NFT. */
59
+ nftContractAddress: Address;
60
+ /** On-chain token id of the NFT being deposited. */
61
+ tokenId: bigint;
62
+ /** Copies to transfer (1 for a unique NFT; ERC-1155 collections can hold fungible editions). */
63
+ amount: bigint;
64
+ titleID: string;
65
+ category?: string;
66
+ }
67
+ /**
68
+ * Full EVM NFT-deposit flow: `safeTransferFrom(account, pool, id, amount, data)` on the ERC-1155
69
+ * collection — where `data = abi.encode(userID, titleID, category)` — then report the tx hash so
70
+ * the backend verifies the transfer and grants the matching in-game item. No operator approval is
71
+ * needed: the player transfers their own token, so msg.sender == from.
72
+ */
73
+ declare function depositNftEvm(params: DepositNftEvmParams): Promise<BridgeResult<DepositNFTResponse>>;
74
+ interface DepositNft721EvmParams {
75
+ client: IDosGamesClient;
76
+ clients: EvmBridgeClients;
77
+ network: BlockchainNetworkDefinition;
78
+ /** ERC-721 collection contract holding the NFT. */
79
+ nftContractAddress: Address;
80
+ /** On-chain token id of the unique NFT being deposited. */
81
+ tokenId: bigint;
82
+ titleID: string;
83
+ category?: string;
84
+ }
85
+ /**
86
+ * Full EVM ERC-721 NFT-deposit flow: `safeTransferFrom(account, pool, tokenId, data)` on the
87
+ * ERC-721 collection — where `data = abi.encode(userID, titleID, category)` — then report the tx
88
+ * hash so the backend verifies the transfer and grants the matching in-game unique item. No
89
+ * operator approval is needed: the player transfers their own token, so msg.sender == from.
90
+ */
91
+ declare function depositNftEvm721(params: DepositNft721EvmParams): Promise<BridgeResult<DepositNFTResponse>>;
92
+
93
+ /**
94
+ * Submits a server-signed ERC-20 withdrawal on-chain by calling `withdrawERC20` on the RewardPool.
95
+ * Every field comes straight from the server's {@link WithdrawalSignatureResponse}; the client
96
+ * only echoes them (Amount and Nonce are decimal strings the server already scaled to raw units,
97
+ * and userID/titleID/category are part of the signed hash — passing anything else reverts). Use
98
+ * this directly to submit a fresh signature from `retryWithdrawal`.
99
+ */
100
+ declare function submitEvmTokenWithdrawal(clients: EvmBridgeClients, sig: WithdrawalSignatureResponse): Promise<Hex>;
101
+ /**
102
+ * Submits a server-signed ERC-1155 game-NFT withdrawal on-chain. The v2 backend signs a MINT voucher
103
+ * (tag "ERC1155_MINT") against the ItemBridge — `sig.ContractAddress` is the bridge and
104
+ * `sig.TokenAddress` is the collection — so this calls `withdrawERC1155Mint`, NOT RewardPool's
105
+ * `withdrawERC1155` (which would fail the selector/hash-tag check).
106
+ */
107
+ declare function submitEvmNftWithdrawal(clients: EvmBridgeClients, sig: WithdrawalSignatureResponse): Promise<Hex>;
108
+ /**
109
+ * Submits a server-signed ERC-721 unique game-NFT withdrawal on-chain via the ItemBridge's
110
+ * `withdrawERC721Mint` (MINT voucher, tag "ERC721_MINT"; `sig.ContractAddress` = bridge,
111
+ * `sig.TokenAddress` = collection) — not RewardPool's custody `withdrawERC721`.
112
+ */
113
+ declare function submitEvmNftWithdrawal721(clients: EvmBridgeClients, sig: WithdrawalSignatureResponse): Promise<Hex>;
114
+ interface WithdrawTokenEvmParams {
115
+ client: IDosGamesClient;
116
+ clients: EvmBridgeClients;
117
+ currencyID: string;
118
+ networkID: string;
119
+ /** Destination wallet — usually the connected `clients.account`. */
120
+ walletAddress: string;
121
+ /** Human decimal amount to withdraw (the server converts and signs raw units). */
122
+ amount: string;
123
+ category?: string;
124
+ }
125
+ /**
126
+ * Full EVM token-withdrawal flow: `requestTokenWithdrawal` (debits in-game immediately and returns
127
+ * a signed payload) → `withdrawERC20` on-chain → `confirmWithdrawal` with the resulting hash.
128
+ *
129
+ * On a failure AFTER the request succeeded, the returned {@link BridgeFailure} carries
130
+ * `titleTransactionID` (the asset is already debited — recover with `retryWithdrawal` while
131
+ * Pending, or `confirmWithdrawal` if the tx actually landed) and, when the on-chain leg landed,
132
+ * `onChainTxHash`. Never restart with a fresh `requestTokenWithdrawal` — that debits twice.
133
+ */
134
+ declare function withdrawTokenEvm(params: WithdrawTokenEvmParams): Promise<BridgeResult<TokenWithdrawalResponse>>;
135
+ interface WithdrawNftEvmParams {
136
+ client: IDosGamesClient;
137
+ clients: EvmBridgeClients;
138
+ itemID: string;
139
+ networkID: string;
140
+ walletAddress: string;
141
+ /** Copies to withdraw, as an integer string (usually "1"). */
142
+ amount: string;
143
+ category?: string;
144
+ }
145
+ /** Full EVM NFT-withdrawal flow: `requestNFTWithdrawal` → `withdrawERC1155` → `confirmWithdrawal`. */
146
+ declare function withdrawNftEvm(params: WithdrawNftEvmParams): Promise<BridgeResult<NFTWithdrawalResponse>>;
147
+
148
+ export { type DepositNft721EvmParams as D, type EvmBridgeClients as E, type WithdrawNftEvmParams as W, type DepositNftEvmParams as a, type DepositTokenEvmParams as b, type WithdrawTokenEvmParams as c, depositNftEvm as d, depositNftEvm721 as e, depositTokenEvm as f, ensureErc20Allowance as g, submitEvmNftWithdrawal721 as h, submitEvmTokenWithdrawal as i, withdrawTokenEvm as j, writeAndWait as k, submitEvmNftWithdrawal as s, withdrawNftEvm as w };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idosgames/wallet",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Wallet-bridge companion to @idosgames/core: connect browser & mobile wallets (EVM via wagmi/viem/WalletConnect, Solana via wallet-adapter) and move tokens/NFTs in and out of the game through client.blockchain.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -42,6 +42,11 @@
42
42
  "types": "./dist/react/index.d.ts",
43
43
  "import": "./dist/react/index.js",
44
44
  "require": "./dist/react/index.cjs"
45
+ },
46
+ "./react/solana": {
47
+ "types": "./dist/react/solanaIndex.d.ts",
48
+ "import": "./dist/react/solanaIndex.js",
49
+ "require": "./dist/react/solanaIndex.cjs"
45
50
  }
46
51
  },
47
52
  "files": [
@@ -57,14 +62,12 @@
57
62
  "dependencies": {
58
63
  "@idosgames/core": "^0.1.1",
59
64
  "@reown/appkit": "^1.8.23",
65
+ "@reown/appkit-adapter-solana": "^1.8.23",
60
66
  "@reown/appkit-adapter-wagmi": "^1.8.23",
61
- "@solana/web3.js": "^1.98.4",
62
- "@walletconnect/ethereum-provider": "^2.21.1",
63
67
  "viem": "^2.55.2"
64
68
  },
65
69
  "peerDependencies": {
66
70
  "@solana/wallet-adapter-base": "^0.9.27",
67
- "@solana/wallet-adapter-react": "^0.15.39",
68
71
  "@tanstack/react-query": "^5.101.2",
69
72
  "react": "^18.3.1 || ^19.0.0",
70
73
  "wagmi": "^3.0.0"
@@ -81,9 +84,6 @@
81
84
  },
82
85
  "@solana/wallet-adapter-base": {
83
86
  "optional": true
84
- },
85
- "@solana/wallet-adapter-react": {
86
- "optional": true
87
87
  }
88
88
  },
89
89
  "devDependencies": {
@@ -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 };