@paul.lumberwork/bonding-curve-sdk 1.7.1 → 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
2
  import { BN, Program } from '@coral-xyz/anchor';
3
- import { PublicKey, Keypair, Connection } from '@solana/web3.js';
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.
@@ -3015,6 +3015,12 @@ interface RegisterStreamerParams {
3015
3015
  streamerId: string;
3016
3016
  streamerKeypair: Keypair;
3017
3017
  }
3018
+ interface RegisterStreamerWithSignatureParams {
3019
+ streamerId: string;
3020
+ streamerPublicKey: PublicKey;
3021
+ signature: Uint8Array;
3022
+ timestamp: number;
3023
+ }
3018
3024
  interface RegisterStreamerResult {
3019
3025
  txSignature: string;
3020
3026
  streamerRegistrationPda: PublicKey;
@@ -3026,6 +3032,15 @@ interface ClaimFundsParams {
3026
3032
  solAmount: BN;
3027
3033
  tokenAmount: BN;
3028
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
+ }
3029
3044
  interface ClaimFundsResult {
3030
3045
  txSignature: string;
3031
3046
  }
@@ -3038,10 +3053,40 @@ declare class StreamerSDK {
3038
3053
  deriveWhitelistEntry(wallet: PublicKey): PublicKey;
3039
3054
  deriveStreamerRegistration(streamerId: string): PublicKey;
3040
3055
  deriveVault(): PublicKey;
3041
- private getSolanaTimestamp;
3042
- private createEd25519Instruction;
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;
3043
3086
  registerStreamer(params: RegisterStreamerParams): Promise<RegisterStreamerResult>;
3044
3087
  claimFunds(params: ClaimFundsParams): Promise<ClaimFundsResult>;
3088
+ registerStreamerWithSignature(params: RegisterStreamerWithSignatureParams): Promise<RegisterStreamerResult>;
3089
+ claimFundsWithSignature(params: ClaimFundsWithSignatureParams): Promise<ClaimFundsResult>;
3045
3090
  getStreamerRegistration(streamerId: string): Promise<{
3046
3091
  streamerId: string;
3047
3092
  wallet: PublicKey;
@@ -3064,4 +3109,4 @@ declare function parseSol(sol: number): bigint;
3064
3109
  /** Parse tokens to raw */
3065
3110
  declare function parseTokens(tokens: number): bigint;
3066
3111
 
3067
- export { ADMIN_WALLET, type AdminWithdrawEvent, type BondingCurveState, CURVE_PERCENT, type ClaimFundsParams, type ClaimFundsResult, 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, STREAMER_PROGRAM_ID, StreamerSDK, 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
2
  import { BN, Program } from '@coral-xyz/anchor';
3
- import { PublicKey, Keypair, Connection } from '@solana/web3.js';
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.
@@ -3015,6 +3015,12 @@ interface RegisterStreamerParams {
3015
3015
  streamerId: string;
3016
3016
  streamerKeypair: Keypair;
3017
3017
  }
3018
+ interface RegisterStreamerWithSignatureParams {
3019
+ streamerId: string;
3020
+ streamerPublicKey: PublicKey;
3021
+ signature: Uint8Array;
3022
+ timestamp: number;
3023
+ }
3018
3024
  interface RegisterStreamerResult {
3019
3025
  txSignature: string;
3020
3026
  streamerRegistrationPda: PublicKey;
@@ -3026,6 +3032,15 @@ interface ClaimFundsParams {
3026
3032
  solAmount: BN;
3027
3033
  tokenAmount: BN;
3028
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
+ }
3029
3044
  interface ClaimFundsResult {
3030
3045
  txSignature: string;
3031
3046
  }
@@ -3038,10 +3053,40 @@ declare class StreamerSDK {
3038
3053
  deriveWhitelistEntry(wallet: PublicKey): PublicKey;
3039
3054
  deriveStreamerRegistration(streamerId: string): PublicKey;
3040
3055
  deriveVault(): PublicKey;
3041
- private getSolanaTimestamp;
3042
- private createEd25519Instruction;
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;
3043
3086
  registerStreamer(params: RegisterStreamerParams): Promise<RegisterStreamerResult>;
3044
3087
  claimFunds(params: ClaimFundsParams): Promise<ClaimFundsResult>;
3088
+ registerStreamerWithSignature(params: RegisterStreamerWithSignatureParams): Promise<RegisterStreamerResult>;
3089
+ claimFundsWithSignature(params: ClaimFundsWithSignatureParams): Promise<ClaimFundsResult>;
3045
3090
  getStreamerRegistration(streamerId: string): Promise<{
3046
3091
  streamerId: string;
3047
3092
  wallet: PublicKey;
@@ -3064,4 +3109,4 @@ declare function parseSol(sol: number): bigint;
3064
3109
  /** Parse tokens to raw */
3065
3110
  declare function parseTokens(tokens: number): bigint;
3066
3111
 
3067
- export { ADMIN_WALLET, type AdminWithdrawEvent, type BondingCurveState, CURVE_PERCENT, type ClaimFundsParams, type ClaimFundsResult, 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, STREAMER_PROGRAM_ID, StreamerSDK, 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
@@ -639,7 +639,7 @@ var KickFunSDK = class {
639
639
  return numerator / denominator;
640
640
  }
641
641
  };
642
- var StreamerSDK = class {
642
+ var StreamerSDK = class _StreamerSDK {
643
643
  constructor(program, wallet) {
644
644
  this.program = program;
645
645
  this.connection = program.provider.connection;
@@ -685,25 +685,61 @@ var StreamerSDK = class {
685
685
  if (!blockTime) throw new Error("Failed to get block time");
686
686
  return blockTime;
687
687
  }
688
- createEd25519Instruction(keypair, message) {
689
- const signature = nacl__default.default.sign.detached(message, keypair.secretKey);
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) {
690
721
  return web3_js.Ed25519Program.createInstructionWithPublicKey({
691
- publicKey: keypair.publicKey.toBytes(),
722
+ publicKey: streamerWallet.toBytes(),
692
723
  message,
693
724
  signature
694
725
  });
695
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
+ }
696
734
  // ═══════════════════════════════════════════════════════════════════════════
697
735
  // Register Streamer
698
736
  // ═══════════════════════════════════════════════════════════════════════════
699
737
  async registerStreamer(params) {
700
738
  const { streamerId, streamerKeypair } = params;
701
739
  const timestamp = await this.getSolanaTimestamp();
702
- const message = `register_streamer:${streamerId}:${streamerKeypair.publicKey.toBase58()}:${timestamp}`;
703
- const ed25519Ix = this.createEd25519Instruction(
704
- streamerKeypair,
705
- Buffer.from(message, "utf-8")
706
- );
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);
707
743
  const whitelistPda = this.deriveWhitelistEntry(this.wallet.publicKey);
708
744
  const streamerRegPda = this.deriveStreamerRegistration(streamerId);
709
745
  const registerIx = await this.program.methods.registerStreamer(
@@ -727,11 +763,9 @@ var StreamerSDK = class {
727
763
  async claimFunds(params) {
728
764
  const { streamerId, streamerKeypair, mint, solAmount, tokenAmount } = params;
729
765
  const timestamp = await this.getSolanaTimestamp();
730
- const message = `claim_funds:${streamerId}:${streamerKeypair.publicKey.toBase58()}:${mint.toBase58()}:${tokenAmount.toString()}:${solAmount.toString()}:${timestamp}`;
731
- const ed25519Ix = this.createEd25519Instruction(
732
- streamerKeypair,
733
- Buffer.from(message, "utf-8")
734
- );
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);
735
769
  const whitelistPda = this.deriveWhitelistEntry(this.wallet.publicKey);
736
770
  const streamerRegPda = this.deriveStreamerRegistration(streamerId);
737
771
  const vaultPda = this.deriveVault();
@@ -762,6 +796,54 @@ var StreamerSDK = class {
762
796
  return { txSignature };
763
797
  }
764
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
+ // ═══════════════════════════════════════════════════════════════════════════
765
847
  // Read State
766
848
  // ═══════════════════════════════════════════════════════════════════════════
767
849
  async getStreamerRegistration(streamerId) {