@toon-protocol/client 0.14.6 → 0.14.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2165,6 +2165,13 @@ declare class OnChainChannelClient implements ConnectorChannelClient {
2165
2165
  txHash?: string;
2166
2166
  depositTotal: bigint;
2167
2167
  }>;
2168
+ /**
2169
+ * Solana deposit: fire the standalone `deposit` instruction against the channel
2170
+ * vault. Incremental on-chain (the program adds `amount`), so the new total is
2171
+ * the caller-tracked current plus the delta. Requires the funded payer token
2172
+ * account (the funded ATA) from the Solana channel config.
2173
+ */
2174
+ private depositSolana;
2168
2175
  /**
2169
2176
  * EVM deposit: approve the token-network for the delta if the allowance is
2170
2177
  * short, then `setTotalDeposit(channelId, participant, current + delta)` —
package/dist/index.js CHANGED
@@ -2035,29 +2035,44 @@ async function openSolanaChannel(params) {
2035
2035
  ]);
2036
2036
  let depositTxSignature;
2037
2037
  if (params.deposit && params.deposit.amount > 0n) {
2038
- const depositData = new Uint8Array(16);
2039
- depositData.set(IX_DEPOSIT, 0);
2040
- writeU64LE(depositData, 8, params.deposit.amount);
2041
- depositTxSignature = await buildAndSendTransaction(rpcUrl, payer, [
2042
- {
2043
- programId,
2044
- keys: [
2045
- { pubkey: payerPubkey, isSigner: true, isWritable: false },
2046
- {
2047
- pubkey: params.deposit.payerTokenAccount,
2048
- isSigner: false,
2049
- isWritable: true
2050
- },
2051
- { pubkey: vaultPDA, isSigner: false, isWritable: true },
2052
- { pubkey: channelPDA, isSigner: false, isWritable: true },
2053
- { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }
2054
- ],
2055
- data: depositData
2056
- }
2057
- ]);
2038
+ ({ depositTxSignature } = await depositSolanaChannel({
2039
+ rpcUrl,
2040
+ programId,
2041
+ channelPDA,
2042
+ payerSeed,
2043
+ payerPubkey,
2044
+ payerTokenAccount: params.deposit.payerTokenAccount,
2045
+ amount: params.deposit.amount
2046
+ }));
2058
2047
  }
2059
2048
  return { channelPDA, opened: true, initTxSignature, depositTxSignature };
2060
2049
  }
2050
+ async function depositSolanaChannel(params) {
2051
+ const { rpcUrl, programId, channelPDA, payerSeed, payerPubkey, payerTokenAccount, amount } = params;
2052
+ if (amount <= 0n) throw new Error("Solana deposit amount must be positive.");
2053
+ const payer = {
2054
+ publicKey: padTo32(base58Decode(payerPubkey)),
2055
+ privateKey: payerSeed
2056
+ };
2057
+ const { pda: vaultPDA } = deriveVaultPDA(channelPDA, programId);
2058
+ const depositData = new Uint8Array(16);
2059
+ depositData.set(IX_DEPOSIT, 0);
2060
+ writeU64LE(depositData, 8, amount);
2061
+ const depositTxSignature = await buildAndSendTransaction(rpcUrl, payer, [
2062
+ {
2063
+ programId,
2064
+ keys: [
2065
+ { pubkey: payerPubkey, isSigner: true, isWritable: false },
2066
+ { pubkey: payerTokenAccount, isSigner: false, isWritable: true },
2067
+ { pubkey: vaultPDA, isSigner: false, isWritable: true },
2068
+ { pubkey: channelPDA, isSigner: false, isWritable: true },
2069
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }
2070
+ ],
2071
+ data: depositData
2072
+ }
2073
+ ]);
2074
+ return { depositTxSignature };
2075
+ }
2061
2076
 
2062
2077
  // src/channel/mina-channel-open.ts
2063
2078
  import { hexToMinaBase58PrivateKey as hexToMinaBase58PrivateKey2 } from "@toon-protocol/core";
@@ -2429,12 +2444,43 @@ var OnChainChannelClient = class {
2429
2444
  );
2430
2445
  }
2431
2446
  const chainPrefix = ctx.chain.split(":")[0];
2432
- if (chainPrefix === "solana" || chainPrefix === "mina") {
2447
+ if (chainPrefix === "solana") {
2448
+ return this.depositSolana(channelId, amount, opts.currentDeposit);
2449
+ }
2450
+ if (chainPrefix === "mina") {
2451
+ throw new Error("Deposit on mina is not yet supported (EVM + Solana today; Mina follow-up).");
2452
+ }
2453
+ return this.depositEvm(channelId, amount, opts.currentDeposit, ctx);
2454
+ }
2455
+ /**
2456
+ * Solana deposit: fire the standalone `deposit` instruction against the channel
2457
+ * vault. Incremental on-chain (the program adds `amount`), so the new total is
2458
+ * the caller-tracked current plus the delta. Requires the funded payer token
2459
+ * account (the funded ATA) from the Solana channel config.
2460
+ */
2461
+ async depositSolana(channelId, amount, currentDeposit) {
2462
+ if (!this.solanaConfig) {
2463
+ throw new Error("Solana channel config not set \u2014 cannot deposit.");
2464
+ }
2465
+ const cfg = this.solanaConfig;
2466
+ const payerTokenAccount = cfg.deposit?.payerTokenAccount;
2467
+ if (!payerTokenAccount) {
2433
2468
  throw new Error(
2434
- `Deposit on ${chainPrefix} is not yet supported (EVM only; follow-up PR adds it).`
2469
+ "Solana deposit requires solanaConfig.deposit.payerTokenAccount (the funded SPL token account)."
2435
2470
  );
2436
2471
  }
2437
- return this.depositEvm(channelId, amount, opts.currentDeposit, ctx);
2472
+ const payerSeed = cfg.keypair.slice(0, 32);
2473
+ const payerPubkey = base58Encode2(new Uint8Array(ed255192.getPublicKey(payerSeed)));
2474
+ const { depositTxSignature } = await depositSolanaChannel({
2475
+ rpcUrl: cfg.rpcUrl,
2476
+ programId: cfg.programId,
2477
+ channelPDA: channelId,
2478
+ payerSeed,
2479
+ payerPubkey,
2480
+ payerTokenAccount,
2481
+ amount
2482
+ });
2483
+ return { txHash: depositTxSignature, depositTotal: currentDeposit + amount };
2438
2484
  }
2439
2485
  /**
2440
2486
  * EVM deposit: approve the token-network for the delta if the allowance is