@toon-protocol/client 0.14.10 → 0.14.11
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/index.d.ts +32 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1264,6 +1264,21 @@ declare class ToonClient {
|
|
|
1264
1264
|
}>;
|
|
1265
1265
|
/** Where a tracked channel sits in the withdraw journey. */
|
|
1266
1266
|
getChannelCloseState(channelId: string): 'open' | 'closing' | 'settleable' | 'settled';
|
|
1267
|
+
getSettleableAt(channelId: string): bigint | undefined;
|
|
1268
|
+
/**
|
|
1269
|
+
* Re-hydrate a RESUMED channel's on-chain deposit. Persisted channel state
|
|
1270
|
+
* omits `depositTotal`, so after a daemon restart the tracked deposit is `0`
|
|
1271
|
+
* and the wallet shows 0 spendable even though real collateral is locked
|
|
1272
|
+
* on-chain. Read the participant's `deposit` from the `participants` mapping
|
|
1273
|
+
* and update the tracked total so `depositTotal - cumulativeAmount` is right.
|
|
1274
|
+
* Best-effort by caller (await + catch); returns the on-chain deposit, or
|
|
1275
|
+
* `undefined` when it can't be read (no channel manager / on-chain client /
|
|
1276
|
+
* EVM address).
|
|
1277
|
+
*/
|
|
1278
|
+
rehydrateChannelDeposit(channelId: string, opts: {
|
|
1279
|
+
chain: string;
|
|
1280
|
+
tokenNetworkAddress: string;
|
|
1281
|
+
}): Promise<bigint | undefined>;
|
|
1267
1282
|
/**
|
|
1268
1283
|
* Read the on-chain settlement-token balance of this client's OWN wallet on
|
|
1269
1284
|
* each configured chain (EVM token, Solana SPL, native MINA). A free read — no
|
|
@@ -2238,6 +2253,23 @@ declare class OnChainChannelClient implements ConnectorChannelClient {
|
|
|
2238
2253
|
}>;
|
|
2239
2254
|
/** Read + destructure the EVM `channels(bytes32)` view. */
|
|
2240
2255
|
private readEvmChannel;
|
|
2256
|
+
/**
|
|
2257
|
+
* Read a participant's on-chain channel state — `deposit` (locked collateral),
|
|
2258
|
+
* `nonce`, and `transferredAmount` — straight from the `participants` mapping.
|
|
2259
|
+
* Takes the chain + token-network explicitly so it works for a channel that
|
|
2260
|
+
* was RESUMED from disk (no in-memory `channelContext` yet), which is exactly
|
|
2261
|
+
* when the daemon needs to re-hydrate the deposit it doesn't persist.
|
|
2262
|
+
*/
|
|
2263
|
+
readEvmParticipantState(opts: {
|
|
2264
|
+
chain: string;
|
|
2265
|
+
tokenNetworkAddress: string;
|
|
2266
|
+
channelId: string;
|
|
2267
|
+
participant: string;
|
|
2268
|
+
}): Promise<{
|
|
2269
|
+
deposit: bigint;
|
|
2270
|
+
nonce: bigint;
|
|
2271
|
+
transferredAmount: bigint;
|
|
2272
|
+
}>;
|
|
2241
2273
|
/**
|
|
2242
2274
|
* Opens a REAL on-chain Solana payment channel.
|
|
2243
2275
|
*
|
package/dist/index.js
CHANGED
|
@@ -2300,6 +2300,17 @@ var TOKEN_NETWORK_ABI = [
|
|
|
2300
2300
|
{ name: "participant2", type: "address" }
|
|
2301
2301
|
]
|
|
2302
2302
|
},
|
|
2303
|
+
{
|
|
2304
|
+
name: "participants",
|
|
2305
|
+
type: "function",
|
|
2306
|
+
stateMutability: "view",
|
|
2307
|
+
inputs: [{ type: "bytes32" }, { type: "address" }],
|
|
2308
|
+
outputs: [
|
|
2309
|
+
{ name: "deposit", type: "uint256" },
|
|
2310
|
+
{ name: "nonce", type: "uint256" },
|
|
2311
|
+
{ name: "transferredAmount", type: "uint256" }
|
|
2312
|
+
]
|
|
2313
|
+
},
|
|
2303
2314
|
{
|
|
2304
2315
|
name: "ChannelOpened",
|
|
2305
2316
|
type: "event",
|
|
@@ -2631,6 +2642,23 @@ var OnChainChannelClient = class {
|
|
|
2631
2642
|
});
|
|
2632
2643
|
return { settlementTimeout: res[0], state: Number(res[1]), closedAt: res[2] };
|
|
2633
2644
|
}
|
|
2645
|
+
/**
|
|
2646
|
+
* Read a participant's on-chain channel state — `deposit` (locked collateral),
|
|
2647
|
+
* `nonce`, and `transferredAmount` — straight from the `participants` mapping.
|
|
2648
|
+
* Takes the chain + token-network explicitly so it works for a channel that
|
|
2649
|
+
* was RESUMED from disk (no in-memory `channelContext` yet), which is exactly
|
|
2650
|
+
* when the daemon needs to re-hydrate the deposit it doesn't persist.
|
|
2651
|
+
*/
|
|
2652
|
+
async readEvmParticipantState(opts) {
|
|
2653
|
+
const { publicClient } = this.createClients(opts.chain);
|
|
2654
|
+
const res = await publicClient.readContract({
|
|
2655
|
+
address: opts.tokenNetworkAddress,
|
|
2656
|
+
abi: TOKEN_NETWORK_ABI,
|
|
2657
|
+
functionName: "participants",
|
|
2658
|
+
args: [opts.channelId, opts.participant]
|
|
2659
|
+
});
|
|
2660
|
+
return { deposit: res[0], nonce: res[1], transferredAmount: res[2] };
|
|
2661
|
+
}
|
|
2634
2662
|
/**
|
|
2635
2663
|
* Opens a REAL on-chain Solana payment channel.
|
|
2636
2664
|
*
|
|
@@ -5010,6 +5038,33 @@ var ToonClient = class {
|
|
|
5010
5038
|
if (!this.channelManager) throw new Error("ChannelManager not initialized");
|
|
5011
5039
|
return this.channelManager.getChannelCloseState(channelId);
|
|
5012
5040
|
}
|
|
5041
|
+
getSettleableAt(channelId) {
|
|
5042
|
+
if (!this.channelManager) throw new Error("ChannelManager not initialized");
|
|
5043
|
+
return this.channelManager.getSettleableAt(channelId);
|
|
5044
|
+
}
|
|
5045
|
+
/**
|
|
5046
|
+
* Re-hydrate a RESUMED channel's on-chain deposit. Persisted channel state
|
|
5047
|
+
* omits `depositTotal`, so after a daemon restart the tracked deposit is `0`
|
|
5048
|
+
* and the wallet shows 0 spendable even though real collateral is locked
|
|
5049
|
+
* on-chain. Read the participant's `deposit` from the `participants` mapping
|
|
5050
|
+
* and update the tracked total so `depositTotal - cumulativeAmount` is right.
|
|
5051
|
+
* Best-effort by caller (await + catch); returns the on-chain deposit, or
|
|
5052
|
+
* `undefined` when it can't be read (no channel manager / on-chain client /
|
|
5053
|
+
* EVM address).
|
|
5054
|
+
*/
|
|
5055
|
+
async rehydrateChannelDeposit(channelId, opts) {
|
|
5056
|
+
if (!this.channelManager || !this.onChainChannelClient) return void 0;
|
|
5057
|
+
const participant = this.getEvmAddress();
|
|
5058
|
+
if (!participant) return void 0;
|
|
5059
|
+
const { deposit } = await this.onChainChannelClient.readEvmParticipantState({
|
|
5060
|
+
chain: opts.chain,
|
|
5061
|
+
tokenNetworkAddress: opts.tokenNetworkAddress,
|
|
5062
|
+
channelId,
|
|
5063
|
+
participant
|
|
5064
|
+
});
|
|
5065
|
+
this.channelManager.setDepositTotal(channelId, deposit);
|
|
5066
|
+
return deposit;
|
|
5067
|
+
}
|
|
5013
5068
|
/**
|
|
5014
5069
|
* Read the on-chain settlement-token balance of this client's OWN wallet on
|
|
5015
5070
|
* each configured chain (EVM token, Solana SPL, native MINA). A free read — no
|