@paul.lumberwork/bonding-curve-sdk 1.7.0 → 1.7.2

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.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as anchor from '@coral-xyz/anchor';
2
- import { Program } from '@coral-xyz/anchor';
3
- import { PublicKey, Connection, Keypair } from '@solana/web3.js';
2
+ import { BN, Program } from '@coral-xyz/anchor';
3
+ import { PublicKey, Keypair, Connection, TransactionInstruction } from '@solana/web3.js';
4
4
 
5
5
  /**
6
6
  * Program IDL in camelCase format in order to be used in JS/TS.
@@ -3011,6 +3011,95 @@ declare class KickFunSDK {
3011
3011
  /** Calculate K for a given target SOL and curve supply */
3012
3012
  static calculateK(curveSupply: bigint, targetSol: bigint): bigint;
3013
3013
  }
3014
+ interface RegisterStreamerParams {
3015
+ streamerId: string;
3016
+ streamerKeypair: Keypair;
3017
+ }
3018
+ interface RegisterStreamerWithSignatureParams {
3019
+ streamerId: string;
3020
+ streamerPublicKey: PublicKey;
3021
+ signature: Uint8Array;
3022
+ timestamp: number;
3023
+ }
3024
+ interface RegisterStreamerResult {
3025
+ txSignature: string;
3026
+ streamerRegistrationPda: PublicKey;
3027
+ }
3028
+ interface ClaimFundsParams {
3029
+ streamerId: string;
3030
+ streamerKeypair: Keypair;
3031
+ mint: PublicKey;
3032
+ solAmount: BN;
3033
+ tokenAmount: BN;
3034
+ }
3035
+ interface ClaimFundsWithSignatureParams {
3036
+ streamerId: string;
3037
+ streamerPublicKey: PublicKey;
3038
+ mint: PublicKey;
3039
+ solAmount: BN;
3040
+ tokenAmount: BN;
3041
+ signature: Uint8Array;
3042
+ timestamp: number;
3043
+ }
3044
+ interface ClaimFundsResult {
3045
+ txSignature: string;
3046
+ }
3047
+ declare class StreamerSDK {
3048
+ program: Program<any>;
3049
+ connection: Connection;
3050
+ wallet: anchor.Wallet;
3051
+ constructor(program: Program<any>, wallet: anchor.Wallet);
3052
+ derivePlatformConfig(): PublicKey;
3053
+ deriveWhitelistEntry(wallet: PublicKey): PublicKey;
3054
+ deriveStreamerRegistration(streamerId: string): PublicKey;
3055
+ deriveVault(): PublicKey;
3056
+ getSolanaTimestamp(): Promise<number>;
3057
+ /**
3058
+ * Build the message that the streamer must sign for register_streamer.
3059
+ * The streamer signs this with their wallet (e.g. Phantom signMessage).
3060
+ *
3061
+ * Format: "register_streamer:{streamer_id}:{wallet}:{timestamp}"
3062
+ */
3063
+ buildRegisterMessage(streamerId: string, streamerWallet: PublicKey, timestamp: number): Uint8Array;
3064
+ /**
3065
+ * Build the message that the streamer must sign for claim_funds.
3066
+ * The streamer signs this with their wallet (e.g. Phantom signMessage).
3067
+ *
3068
+ * Format: "claim_funds:{streamer_id}:{wallet}:{mint}:{token_amount}:{sol_amount}:{timestamp}"
3069
+ */
3070
+ buildClaimMessage(streamerId: string, streamerWallet: PublicKey, mint: PublicKey, tokenAmount: BN, solAmount: BN, timestamp: number): Uint8Array;
3071
+ /**
3072
+ * Create an Ed25519 instruction from an externally-signed signature.
3073
+ * Use this when the streamer signs via browser wallet (Phantom, Solflare, etc.)
3074
+ * instead of exposing a Keypair.
3075
+ *
3076
+ * @param streamerWallet - Public key of the streamer
3077
+ * @param message - The message bytes (from buildRegisterMessage / buildClaimMessage)
3078
+ * @param signature - The Ed25519 signature from wallet.signMessage(message)
3079
+ */
3080
+ createEd25519Instruction(streamerWallet: PublicKey, message: Uint8Array, signature: Uint8Array): TransactionInstruction;
3081
+ /**
3082
+ * Sign a message using a Keypair directly (server-side / test usage).
3083
+ * Returns the Ed25519 signature bytes.
3084
+ */
3085
+ static signMessage(message: Uint8Array, keypair: Keypair): Uint8Array;
3086
+ registerStreamer(params: RegisterStreamerParams): Promise<RegisterStreamerResult>;
3087
+ claimFunds(params: ClaimFundsParams): Promise<ClaimFundsResult>;
3088
+ registerStreamerWithSignature(params: RegisterStreamerWithSignatureParams): Promise<RegisterStreamerResult>;
3089
+ claimFundsWithSignature(params: ClaimFundsWithSignatureParams): Promise<ClaimFundsResult>;
3090
+ getStreamerRegistration(streamerId: string): Promise<{
3091
+ streamerId: string;
3092
+ wallet: PublicKey;
3093
+ verifiedAt: number;
3094
+ registeredBy: PublicKey;
3095
+ createdAt: number;
3096
+ } | null>;
3097
+ isWhitelisted(wallet: PublicKey): Promise<boolean>;
3098
+ getVaultBalance(mint?: PublicKey): Promise<{
3099
+ sol: bigint;
3100
+ tokens: bigint;
3101
+ }>;
3102
+ }
3014
3103
  /** Format raw token amount to human-readable */
3015
3104
  declare function formatTokens(raw: bigint): string;
3016
3105
  /** Format lamports to SOL */
@@ -3020,4 +3109,4 @@ declare function parseSol(sol: number): bigint;
3020
3109
  /** Parse tokens to raw */
3021
3110
  declare function parseTokens(tokens: number): bigint;
3022
3111
 
3023
- export { ADMIN_WALLET, type AdminWithdrawEvent, type BondingCurveState, CURVE_PERCENT, type CurveCompleteEvent, type EstimateBuyResult, type EstimateSellResult, type EventCallback, FEE_BPS, K_SCALE, type KickFunEvent, type KickFunProgram, KickFunSDK, LAMPORTS, LP_PERCENT, type LaunchAddresses, type LaunchCreatedEvent, METADATA_PROGRAM_ID, PROGRAM_ID, STREAMER_PROGRAM_ID, TOKEN_DECIMALS, TREASURY_PERCENT, type TokenLaunchConfig, type TokenLaunchState, type TokensPurchasedEvent, type TokensSoldEvent, type TradeResult, formatSol, formatTokens, parseSol, parseTokens };
3112
+ export { ADMIN_WALLET, type AdminWithdrawEvent, type BondingCurveState, CURVE_PERCENT, type ClaimFundsParams, type ClaimFundsResult, type ClaimFundsWithSignatureParams, type CurveCompleteEvent, type EstimateBuyResult, type EstimateSellResult, type EventCallback, FEE_BPS, K_SCALE, type KickFunEvent, type KickFunProgram, KickFunSDK, LAMPORTS, LP_PERCENT, type LaunchAddresses, type LaunchCreatedEvent, METADATA_PROGRAM_ID, PROGRAM_ID, type RegisterStreamerParams, type RegisterStreamerResult, type RegisterStreamerWithSignatureParams, STREAMER_PROGRAM_ID, StreamerSDK, TOKEN_DECIMALS, TREASURY_PERCENT, type TokenLaunchConfig, type TokenLaunchState, type TokensPurchasedEvent, type TokensSoldEvent, type TradeResult, formatSol, formatTokens, parseSol, parseTokens };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as anchor from '@coral-xyz/anchor';
2
- import { Program } from '@coral-xyz/anchor';
3
- import { PublicKey, Connection, Keypair } from '@solana/web3.js';
2
+ import { BN, Program } from '@coral-xyz/anchor';
3
+ import { PublicKey, Keypair, Connection, TransactionInstruction } from '@solana/web3.js';
4
4
 
5
5
  /**
6
6
  * Program IDL in camelCase format in order to be used in JS/TS.
@@ -3011,6 +3011,95 @@ declare class KickFunSDK {
3011
3011
  /** Calculate K for a given target SOL and curve supply */
3012
3012
  static calculateK(curveSupply: bigint, targetSol: bigint): bigint;
3013
3013
  }
3014
+ interface RegisterStreamerParams {
3015
+ streamerId: string;
3016
+ streamerKeypair: Keypair;
3017
+ }
3018
+ interface RegisterStreamerWithSignatureParams {
3019
+ streamerId: string;
3020
+ streamerPublicKey: PublicKey;
3021
+ signature: Uint8Array;
3022
+ timestamp: number;
3023
+ }
3024
+ interface RegisterStreamerResult {
3025
+ txSignature: string;
3026
+ streamerRegistrationPda: PublicKey;
3027
+ }
3028
+ interface ClaimFundsParams {
3029
+ streamerId: string;
3030
+ streamerKeypair: Keypair;
3031
+ mint: PublicKey;
3032
+ solAmount: BN;
3033
+ tokenAmount: BN;
3034
+ }
3035
+ interface ClaimFundsWithSignatureParams {
3036
+ streamerId: string;
3037
+ streamerPublicKey: PublicKey;
3038
+ mint: PublicKey;
3039
+ solAmount: BN;
3040
+ tokenAmount: BN;
3041
+ signature: Uint8Array;
3042
+ timestamp: number;
3043
+ }
3044
+ interface ClaimFundsResult {
3045
+ txSignature: string;
3046
+ }
3047
+ declare class StreamerSDK {
3048
+ program: Program<any>;
3049
+ connection: Connection;
3050
+ wallet: anchor.Wallet;
3051
+ constructor(program: Program<any>, wallet: anchor.Wallet);
3052
+ derivePlatformConfig(): PublicKey;
3053
+ deriveWhitelistEntry(wallet: PublicKey): PublicKey;
3054
+ deriveStreamerRegistration(streamerId: string): PublicKey;
3055
+ deriveVault(): PublicKey;
3056
+ getSolanaTimestamp(): Promise<number>;
3057
+ /**
3058
+ * Build the message that the streamer must sign for register_streamer.
3059
+ * The streamer signs this with their wallet (e.g. Phantom signMessage).
3060
+ *
3061
+ * Format: "register_streamer:{streamer_id}:{wallet}:{timestamp}"
3062
+ */
3063
+ buildRegisterMessage(streamerId: string, streamerWallet: PublicKey, timestamp: number): Uint8Array;
3064
+ /**
3065
+ * Build the message that the streamer must sign for claim_funds.
3066
+ * The streamer signs this with their wallet (e.g. Phantom signMessage).
3067
+ *
3068
+ * Format: "claim_funds:{streamer_id}:{wallet}:{mint}:{token_amount}:{sol_amount}:{timestamp}"
3069
+ */
3070
+ buildClaimMessage(streamerId: string, streamerWallet: PublicKey, mint: PublicKey, tokenAmount: BN, solAmount: BN, timestamp: number): Uint8Array;
3071
+ /**
3072
+ * Create an Ed25519 instruction from an externally-signed signature.
3073
+ * Use this when the streamer signs via browser wallet (Phantom, Solflare, etc.)
3074
+ * instead of exposing a Keypair.
3075
+ *
3076
+ * @param streamerWallet - Public key of the streamer
3077
+ * @param message - The message bytes (from buildRegisterMessage / buildClaimMessage)
3078
+ * @param signature - The Ed25519 signature from wallet.signMessage(message)
3079
+ */
3080
+ createEd25519Instruction(streamerWallet: PublicKey, message: Uint8Array, signature: Uint8Array): TransactionInstruction;
3081
+ /**
3082
+ * Sign a message using a Keypair directly (server-side / test usage).
3083
+ * Returns the Ed25519 signature bytes.
3084
+ */
3085
+ static signMessage(message: Uint8Array, keypair: Keypair): Uint8Array;
3086
+ registerStreamer(params: RegisterStreamerParams): Promise<RegisterStreamerResult>;
3087
+ claimFunds(params: ClaimFundsParams): Promise<ClaimFundsResult>;
3088
+ registerStreamerWithSignature(params: RegisterStreamerWithSignatureParams): Promise<RegisterStreamerResult>;
3089
+ claimFundsWithSignature(params: ClaimFundsWithSignatureParams): Promise<ClaimFundsResult>;
3090
+ getStreamerRegistration(streamerId: string): Promise<{
3091
+ streamerId: string;
3092
+ wallet: PublicKey;
3093
+ verifiedAt: number;
3094
+ registeredBy: PublicKey;
3095
+ createdAt: number;
3096
+ } | null>;
3097
+ isWhitelisted(wallet: PublicKey): Promise<boolean>;
3098
+ getVaultBalance(mint?: PublicKey): Promise<{
3099
+ sol: bigint;
3100
+ tokens: bigint;
3101
+ }>;
3102
+ }
3014
3103
  /** Format raw token amount to human-readable */
3015
3104
  declare function formatTokens(raw: bigint): string;
3016
3105
  /** Format lamports to SOL */
@@ -3020,4 +3109,4 @@ declare function parseSol(sol: number): bigint;
3020
3109
  /** Parse tokens to raw */
3021
3110
  declare function parseTokens(tokens: number): bigint;
3022
3111
 
3023
- export { ADMIN_WALLET, type AdminWithdrawEvent, type BondingCurveState, CURVE_PERCENT, type CurveCompleteEvent, type EstimateBuyResult, type EstimateSellResult, type EventCallback, FEE_BPS, K_SCALE, type KickFunEvent, type KickFunProgram, KickFunSDK, LAMPORTS, LP_PERCENT, type LaunchAddresses, type LaunchCreatedEvent, METADATA_PROGRAM_ID, PROGRAM_ID, STREAMER_PROGRAM_ID, TOKEN_DECIMALS, TREASURY_PERCENT, type TokenLaunchConfig, type TokenLaunchState, type TokensPurchasedEvent, type TokensSoldEvent, type TradeResult, formatSol, formatTokens, parseSol, parseTokens };
3112
+ export { ADMIN_WALLET, type AdminWithdrawEvent, type BondingCurveState, CURVE_PERCENT, type ClaimFundsParams, type ClaimFundsResult, type ClaimFundsWithSignatureParams, type CurveCompleteEvent, type EstimateBuyResult, type EstimateSellResult, type EventCallback, FEE_BPS, K_SCALE, type KickFunEvent, type KickFunProgram, KickFunSDK, LAMPORTS, LP_PERCENT, type LaunchAddresses, type LaunchCreatedEvent, METADATA_PROGRAM_ID, PROGRAM_ID, type RegisterStreamerParams, type RegisterStreamerResult, type RegisterStreamerWithSignatureParams, STREAMER_PROGRAM_ID, StreamerSDK, TOKEN_DECIMALS, TREASURY_PERCENT, type TokenLaunchConfig, type TokenLaunchState, type TokensPurchasedEvent, type TokensSoldEvent, type TradeResult, formatSol, formatTokens, parseSol, parseTokens };
package/dist/index.js CHANGED
@@ -3,6 +3,11 @@
3
3
  var anchor = require('@coral-xyz/anchor');
4
4
  var web3_js = require('@solana/web3.js');
5
5
  var splToken = require('@solana/spl-token');
6
+ var nacl = require('tweetnacl');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var nacl__default = /*#__PURE__*/_interopDefault(nacl);
6
11
 
7
12
  // src/sdk/index.ts
8
13
  var PROGRAM_ID = new web3_js.PublicKey("6o7oTqg2CfvcMCJTLNEJsef7c875zGpTvcnFctNAjudL");
@@ -135,6 +140,22 @@ var KickFunSDK = class {
135
140
  preInstructions.push(
136
141
  web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: computeUnits })
137
142
  );
143
+ preInstructions.push(
144
+ splToken.createAssociatedTokenAccountIdempotentInstruction(
145
+ this.wallet.publicKey,
146
+ streamerTokenAccount,
147
+ streamerVaultPda,
148
+ mint
149
+ )
150
+ );
151
+ preInstructions.push(
152
+ splToken.createAssociatedTokenAccountIdempotentInstruction(
153
+ this.wallet.publicKey,
154
+ adminTokenAccount,
155
+ ADMIN_WALLET,
156
+ mint
157
+ )
158
+ );
138
159
  const tx = await this.program.methods.buyTokens(solLamports).accountsPartial({
139
160
  contributor: this.wallet.publicKey,
140
161
  launchpad: this.launchpadPda,
@@ -618,6 +639,252 @@ var KickFunSDK = class {
618
639
  return numerator / denominator;
619
640
  }
620
641
  };
642
+ var StreamerSDK = class _StreamerSDK {
643
+ constructor(program, wallet) {
644
+ this.program = program;
645
+ this.connection = program.provider.connection;
646
+ this.wallet = wallet;
647
+ }
648
+ // ═══════════════════════════════════════════════════════════════════════════
649
+ // PDA Derivation Helpers
650
+ // ═══════════════════════════════════════════════════════════════════════════
651
+ derivePlatformConfig() {
652
+ const [pda] = web3_js.PublicKey.findProgramAddressSync(
653
+ [Buffer.from("platform_config")],
654
+ this.program.programId
655
+ );
656
+ return pda;
657
+ }
658
+ deriveWhitelistEntry(wallet) {
659
+ const [pda] = web3_js.PublicKey.findProgramAddressSync(
660
+ [Buffer.from("whitelist"), wallet.toBuffer()],
661
+ this.program.programId
662
+ );
663
+ return pda;
664
+ }
665
+ deriveStreamerRegistration(streamerId) {
666
+ const [pda] = web3_js.PublicKey.findProgramAddressSync(
667
+ [Buffer.from("streamer"), Buffer.from(streamerId)],
668
+ this.program.programId
669
+ );
670
+ return pda;
671
+ }
672
+ deriveVault() {
673
+ const [pda] = web3_js.PublicKey.findProgramAddressSync(
674
+ [Buffer.from("vault")],
675
+ this.program.programId
676
+ );
677
+ return pda;
678
+ }
679
+ // ═══════════════════════════════════════════════════════════════════════════
680
+ // Helpers
681
+ // ═══════════════════════════════════════════════════════════════════════════
682
+ async getSolanaTimestamp() {
683
+ const slot = await this.connection.getSlot();
684
+ const blockTime = await this.connection.getBlockTime(slot);
685
+ if (!blockTime) throw new Error("Failed to get block time");
686
+ return blockTime;
687
+ }
688
+ // ═══════════════════════════════════════════════════════════════════════════
689
+ // Ed25519 Signing Utilities (for browser wallets / external signers)
690
+ // ═══════════════════════════════════════════════════════════════════════════
691
+ /**
692
+ * Build the message that the streamer must sign for register_streamer.
693
+ * The streamer signs this with their wallet (e.g. Phantom signMessage).
694
+ *
695
+ * Format: "register_streamer:{streamer_id}:{wallet}:{timestamp}"
696
+ */
697
+ buildRegisterMessage(streamerId, streamerWallet, timestamp) {
698
+ const msg = `register_streamer:${streamerId}:${streamerWallet.toBase58()}:${timestamp}`;
699
+ return Buffer.from(msg, "utf-8");
700
+ }
701
+ /**
702
+ * Build the message that the streamer must sign for claim_funds.
703
+ * The streamer signs this with their wallet (e.g. Phantom signMessage).
704
+ *
705
+ * Format: "claim_funds:{streamer_id}:{wallet}:{mint}:{token_amount}:{sol_amount}:{timestamp}"
706
+ */
707
+ buildClaimMessage(streamerId, streamerWallet, mint, tokenAmount, solAmount, timestamp) {
708
+ const msg = `claim_funds:${streamerId}:${streamerWallet.toBase58()}:${mint.toBase58()}:${tokenAmount.toString()}:${solAmount.toString()}:${timestamp}`;
709
+ return Buffer.from(msg, "utf-8");
710
+ }
711
+ /**
712
+ * Create an Ed25519 instruction from an externally-signed signature.
713
+ * Use this when the streamer signs via browser wallet (Phantom, Solflare, etc.)
714
+ * instead of exposing a Keypair.
715
+ *
716
+ * @param streamerWallet - Public key of the streamer
717
+ * @param message - The message bytes (from buildRegisterMessage / buildClaimMessage)
718
+ * @param signature - The Ed25519 signature from wallet.signMessage(message)
719
+ */
720
+ createEd25519Instruction(streamerWallet, message, signature) {
721
+ return web3_js.Ed25519Program.createInstructionWithPublicKey({
722
+ publicKey: streamerWallet.toBytes(),
723
+ message,
724
+ signature
725
+ });
726
+ }
727
+ /**
728
+ * Sign a message using a Keypair directly (server-side / test usage).
729
+ * Returns the Ed25519 signature bytes.
730
+ */
731
+ static signMessage(message, keypair) {
732
+ return nacl__default.default.sign.detached(message, keypair.secretKey);
733
+ }
734
+ // ═══════════════════════════════════════════════════════════════════════════
735
+ // Register Streamer
736
+ // ═══════════════════════════════════════════════════════════════════════════
737
+ async registerStreamer(params) {
738
+ const { streamerId, streamerKeypair } = params;
739
+ const timestamp = await this.getSolanaTimestamp();
740
+ const msgBytes = this.buildRegisterMessage(streamerId, streamerKeypair.publicKey, timestamp);
741
+ const sig = _StreamerSDK.signMessage(msgBytes, streamerKeypair);
742
+ const ed25519Ix = this.createEd25519Instruction(streamerKeypair.publicKey, msgBytes, sig);
743
+ const whitelistPda = this.deriveWhitelistEntry(this.wallet.publicKey);
744
+ const streamerRegPda = this.deriveStreamerRegistration(streamerId);
745
+ const registerIx = await this.program.methods.registerStreamer(
746
+ streamerId,
747
+ streamerKeypair.publicKey,
748
+ new anchor.BN(timestamp)
749
+ ).accounts({
750
+ caller: this.wallet.publicKey,
751
+ whitelistEntry: whitelistPda,
752
+ streamerRegistration: streamerRegPda,
753
+ instructionsSysvar: web3_js.SYSVAR_INSTRUCTIONS_PUBKEY
754
+ }).instruction();
755
+ const tx = new web3_js.Transaction().add(ed25519Ix).add(registerIx);
756
+ const provider = this.program.provider;
757
+ const txSignature = await provider.sendAndConfirm(tx);
758
+ return { txSignature, streamerRegistrationPda: streamerRegPda };
759
+ }
760
+ // ═══════════════════════════════════════════════════════════════════════════
761
+ // Claim Funds
762
+ // ═══════════════════════════════════════════════════════════════════════════
763
+ async claimFunds(params) {
764
+ const { streamerId, streamerKeypair, mint, solAmount, tokenAmount } = params;
765
+ const timestamp = await this.getSolanaTimestamp();
766
+ const msgBytes = this.buildClaimMessage(streamerId, streamerKeypair.publicKey, mint, tokenAmount, solAmount, timestamp);
767
+ const sig = _StreamerSDK.signMessage(msgBytes, streamerKeypair);
768
+ const ed25519Ix = this.createEd25519Instruction(streamerKeypair.publicKey, msgBytes, sig);
769
+ const whitelistPda = this.deriveWhitelistEntry(this.wallet.publicKey);
770
+ const streamerRegPda = this.deriveStreamerRegistration(streamerId);
771
+ const vaultPda = this.deriveVault();
772
+ const programTokenAccount = splToken.getAssociatedTokenAddressSync(
773
+ mint,
774
+ vaultPda,
775
+ true
776
+ );
777
+ const streamerTokenAccount = splToken.getAssociatedTokenAddressSync(
778
+ mint,
779
+ streamerKeypair.publicKey,
780
+ false
781
+ );
782
+ const claimIx = await this.program.methods.claimFunds(streamerId, solAmount, tokenAmount, new anchor.BN(timestamp)).accounts({
783
+ caller: this.wallet.publicKey,
784
+ whitelistEntry: whitelistPda,
785
+ streamerRegistration: streamerRegPda,
786
+ streamerWallet: streamerKeypair.publicKey,
787
+ vault: vaultPda,
788
+ mint,
789
+ programTokenAccount,
790
+ streamerTokenAccount,
791
+ instructionsSysvar: web3_js.SYSVAR_INSTRUCTIONS_PUBKEY
792
+ }).instruction();
793
+ const tx = new web3_js.Transaction().add(ed25519Ix).add(claimIx);
794
+ const provider = this.program.provider;
795
+ const txSignature = await provider.sendAndConfirm(tx);
796
+ return { txSignature };
797
+ }
798
+ // ═══════════════════════════════════════════════════════════════════════════
799
+ // Register Streamer (browser wallet — signature from Phantom/Solflare)
800
+ // ═══════════════════════════════════════════════════════════════════════════
801
+ async registerStreamerWithSignature(params) {
802
+ const { streamerId, streamerPublicKey, signature, timestamp } = params;
803
+ const msgBytes = this.buildRegisterMessage(streamerId, streamerPublicKey, timestamp);
804
+ const ed25519Ix = this.createEd25519Instruction(streamerPublicKey, msgBytes, signature);
805
+ const whitelistPda = this.deriveWhitelistEntry(this.wallet.publicKey);
806
+ const streamerRegPda = this.deriveStreamerRegistration(streamerId);
807
+ const registerIx = await this.program.methods.registerStreamer(streamerId, streamerPublicKey, new anchor.BN(timestamp)).accounts({
808
+ caller: this.wallet.publicKey,
809
+ whitelistEntry: whitelistPda,
810
+ streamerRegistration: streamerRegPda,
811
+ instructionsSysvar: web3_js.SYSVAR_INSTRUCTIONS_PUBKEY
812
+ }).instruction();
813
+ const tx = new web3_js.Transaction().add(ed25519Ix).add(registerIx);
814
+ const provider = this.program.provider;
815
+ const txSignature = await provider.sendAndConfirm(tx);
816
+ return { txSignature, streamerRegistrationPda: streamerRegPda };
817
+ }
818
+ // ═══════════════════════════════════════════════════════════════════════════
819
+ // Claim Funds (browser wallet — signature from Phantom/Solflare)
820
+ // ═══════════════════════════════════════════════════════════════════════════
821
+ async claimFundsWithSignature(params) {
822
+ const { streamerId, streamerPublicKey, mint, solAmount, tokenAmount, signature, timestamp } = params;
823
+ const msgBytes = this.buildClaimMessage(streamerId, streamerPublicKey, mint, tokenAmount, solAmount, timestamp);
824
+ const ed25519Ix = this.createEd25519Instruction(streamerPublicKey, msgBytes, signature);
825
+ const whitelistPda = this.deriveWhitelistEntry(this.wallet.publicKey);
826
+ const streamerRegPda = this.deriveStreamerRegistration(streamerId);
827
+ const vaultPda = this.deriveVault();
828
+ const programTokenAccount = splToken.getAssociatedTokenAddressSync(mint, vaultPda, true);
829
+ const streamerTokenAccount = splToken.getAssociatedTokenAddressSync(mint, streamerPublicKey, false);
830
+ const claimIx = await this.program.methods.claimFunds(streamerId, solAmount, tokenAmount, new anchor.BN(timestamp)).accounts({
831
+ caller: this.wallet.publicKey,
832
+ whitelistEntry: whitelistPda,
833
+ streamerRegistration: streamerRegPda,
834
+ streamerWallet: streamerPublicKey,
835
+ vault: vaultPda,
836
+ mint,
837
+ programTokenAccount,
838
+ streamerTokenAccount,
839
+ instructionsSysvar: web3_js.SYSVAR_INSTRUCTIONS_PUBKEY
840
+ }).instruction();
841
+ const tx = new web3_js.Transaction().add(ed25519Ix).add(claimIx);
842
+ const provider = this.program.provider;
843
+ const txSignature = await provider.sendAndConfirm(tx);
844
+ return { txSignature };
845
+ }
846
+ // ═══════════════════════════════════════════════════════════════════════════
847
+ // Read State
848
+ // ═══════════════════════════════════════════════════════════════════════════
849
+ async getStreamerRegistration(streamerId) {
850
+ const pda = this.deriveStreamerRegistration(streamerId);
851
+ try {
852
+ const account = await this.program.account.streamerRegistration.fetch(pda);
853
+ return {
854
+ streamerId: account.streamerId,
855
+ wallet: account.wallet,
856
+ verifiedAt: account.verifiedAt.toNumber(),
857
+ registeredBy: account.registeredBy,
858
+ createdAt: account.createdAt.toNumber()
859
+ };
860
+ } catch {
861
+ return null;
862
+ }
863
+ }
864
+ async isWhitelisted(wallet) {
865
+ const pda = this.deriveWhitelistEntry(wallet);
866
+ try {
867
+ const account = await this.program.account.whitelistEntry.fetch(pda);
868
+ return account.active;
869
+ } catch {
870
+ return false;
871
+ }
872
+ }
873
+ async getVaultBalance(mint) {
874
+ const vaultPda = this.deriveVault();
875
+ const sol = BigInt(await this.connection.getBalance(vaultPda));
876
+ let tokens = 0n;
877
+ if (mint) {
878
+ const ata = splToken.getAssociatedTokenAddressSync(mint, vaultPda, true);
879
+ try {
880
+ const account = await splToken.getAccount(this.connection, ata);
881
+ tokens = account.amount;
882
+ } catch {
883
+ }
884
+ }
885
+ return { sol, tokens };
886
+ }
887
+ };
621
888
  function formatTokens(raw) {
622
889
  const tokens = Number(raw) / 10 ** TOKEN_DECIMALS;
623
890
  return tokens.toLocaleString(void 0, { maximumFractionDigits: 2 });
@@ -643,6 +910,7 @@ exports.LP_PERCENT = LP_PERCENT;
643
910
  exports.METADATA_PROGRAM_ID = METADATA_PROGRAM_ID;
644
911
  exports.PROGRAM_ID = PROGRAM_ID;
645
912
  exports.STREAMER_PROGRAM_ID = STREAMER_PROGRAM_ID;
913
+ exports.StreamerSDK = StreamerSDK;
646
914
  exports.TOKEN_DECIMALS = TOKEN_DECIMALS;
647
915
  exports.TREASURY_PERCENT = TREASURY_PERCENT;
648
916
  exports.formatSol = formatSol;