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

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 } 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,50 @@ 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 RegisterStreamerResult {
3019
+ txSignature: string;
3020
+ streamerRegistrationPda: PublicKey;
3021
+ }
3022
+ interface ClaimFundsParams {
3023
+ streamerId: string;
3024
+ streamerKeypair: Keypair;
3025
+ mint: PublicKey;
3026
+ solAmount: BN;
3027
+ tokenAmount: BN;
3028
+ }
3029
+ interface ClaimFundsResult {
3030
+ txSignature: string;
3031
+ }
3032
+ declare class StreamerSDK {
3033
+ program: Program<any>;
3034
+ connection: Connection;
3035
+ wallet: anchor.Wallet;
3036
+ constructor(program: Program<any>, wallet: anchor.Wallet);
3037
+ derivePlatformConfig(): PublicKey;
3038
+ deriveWhitelistEntry(wallet: PublicKey): PublicKey;
3039
+ deriveStreamerRegistration(streamerId: string): PublicKey;
3040
+ deriveVault(): PublicKey;
3041
+ private getSolanaTimestamp;
3042
+ private createEd25519Instruction;
3043
+ registerStreamer(params: RegisterStreamerParams): Promise<RegisterStreamerResult>;
3044
+ claimFunds(params: ClaimFundsParams): Promise<ClaimFundsResult>;
3045
+ getStreamerRegistration(streamerId: string): Promise<{
3046
+ streamerId: string;
3047
+ wallet: PublicKey;
3048
+ verifiedAt: number;
3049
+ registeredBy: PublicKey;
3050
+ createdAt: number;
3051
+ } | null>;
3052
+ isWhitelisted(wallet: PublicKey): Promise<boolean>;
3053
+ getVaultBalance(mint?: PublicKey): Promise<{
3054
+ sol: bigint;
3055
+ tokens: bigint;
3056
+ }>;
3057
+ }
3014
3058
  /** Format raw token amount to human-readable */
3015
3059
  declare function formatTokens(raw: bigint): string;
3016
3060
  /** Format lamports to SOL */
@@ -3020,4 +3064,4 @@ declare function parseSol(sol: number): bigint;
3020
3064
  /** Parse tokens to raw */
3021
3065
  declare function parseTokens(tokens: number): bigint;
3022
3066
 
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 };
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 };
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 } 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,50 @@ 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 RegisterStreamerResult {
3019
+ txSignature: string;
3020
+ streamerRegistrationPda: PublicKey;
3021
+ }
3022
+ interface ClaimFundsParams {
3023
+ streamerId: string;
3024
+ streamerKeypair: Keypair;
3025
+ mint: PublicKey;
3026
+ solAmount: BN;
3027
+ tokenAmount: BN;
3028
+ }
3029
+ interface ClaimFundsResult {
3030
+ txSignature: string;
3031
+ }
3032
+ declare class StreamerSDK {
3033
+ program: Program<any>;
3034
+ connection: Connection;
3035
+ wallet: anchor.Wallet;
3036
+ constructor(program: Program<any>, wallet: anchor.Wallet);
3037
+ derivePlatformConfig(): PublicKey;
3038
+ deriveWhitelistEntry(wallet: PublicKey): PublicKey;
3039
+ deriveStreamerRegistration(streamerId: string): PublicKey;
3040
+ deriveVault(): PublicKey;
3041
+ private getSolanaTimestamp;
3042
+ private createEd25519Instruction;
3043
+ registerStreamer(params: RegisterStreamerParams): Promise<RegisterStreamerResult>;
3044
+ claimFunds(params: ClaimFundsParams): Promise<ClaimFundsResult>;
3045
+ getStreamerRegistration(streamerId: string): Promise<{
3046
+ streamerId: string;
3047
+ wallet: PublicKey;
3048
+ verifiedAt: number;
3049
+ registeredBy: PublicKey;
3050
+ createdAt: number;
3051
+ } | null>;
3052
+ isWhitelisted(wallet: PublicKey): Promise<boolean>;
3053
+ getVaultBalance(mint?: PublicKey): Promise<{
3054
+ sol: bigint;
3055
+ tokens: bigint;
3056
+ }>;
3057
+ }
3014
3058
  /** Format raw token amount to human-readable */
3015
3059
  declare function formatTokens(raw: bigint): string;
3016
3060
  /** Format lamports to SOL */
@@ -3020,4 +3064,4 @@ declare function parseSol(sol: number): bigint;
3020
3064
  /** Parse tokens to raw */
3021
3065
  declare function parseTokens(tokens: number): bigint;
3022
3066
 
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 };
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 };
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,170 @@ var KickFunSDK = class {
618
639
  return numerator / denominator;
619
640
  }
620
641
  };
642
+ var StreamerSDK = class {
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
+ createEd25519Instruction(keypair, message) {
689
+ const signature = nacl__default.default.sign.detached(message, keypair.secretKey);
690
+ return web3_js.Ed25519Program.createInstructionWithPublicKey({
691
+ publicKey: keypair.publicKey.toBytes(),
692
+ message,
693
+ signature
694
+ });
695
+ }
696
+ // ═══════════════════════════════════════════════════════════════════════════
697
+ // Register Streamer
698
+ // ═══════════════════════════════════════════════════════════════════════════
699
+ async registerStreamer(params) {
700
+ const { streamerId, streamerKeypair } = params;
701
+ 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
+ );
707
+ const whitelistPda = this.deriveWhitelistEntry(this.wallet.publicKey);
708
+ const streamerRegPda = this.deriveStreamerRegistration(streamerId);
709
+ const registerIx = await this.program.methods.registerStreamer(
710
+ streamerId,
711
+ streamerKeypair.publicKey,
712
+ new anchor.BN(timestamp)
713
+ ).accounts({
714
+ caller: this.wallet.publicKey,
715
+ whitelistEntry: whitelistPda,
716
+ streamerRegistration: streamerRegPda,
717
+ instructionsSysvar: web3_js.SYSVAR_INSTRUCTIONS_PUBKEY
718
+ }).instruction();
719
+ const tx = new web3_js.Transaction().add(ed25519Ix).add(registerIx);
720
+ const provider = this.program.provider;
721
+ const txSignature = await provider.sendAndConfirm(tx);
722
+ return { txSignature, streamerRegistrationPda: streamerRegPda };
723
+ }
724
+ // ═══════════════════════════════════════════════════════════════════════════
725
+ // Claim Funds
726
+ // ═══════════════════════════════════════════════════════════════════════════
727
+ async claimFunds(params) {
728
+ const { streamerId, streamerKeypair, mint, solAmount, tokenAmount } = params;
729
+ 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
+ );
735
+ const whitelistPda = this.deriveWhitelistEntry(this.wallet.publicKey);
736
+ const streamerRegPda = this.deriveStreamerRegistration(streamerId);
737
+ const vaultPda = this.deriveVault();
738
+ const programTokenAccount = splToken.getAssociatedTokenAddressSync(
739
+ mint,
740
+ vaultPda,
741
+ true
742
+ );
743
+ const streamerTokenAccount = splToken.getAssociatedTokenAddressSync(
744
+ mint,
745
+ streamerKeypair.publicKey,
746
+ false
747
+ );
748
+ const claimIx = await this.program.methods.claimFunds(streamerId, solAmount, tokenAmount, new anchor.BN(timestamp)).accounts({
749
+ caller: this.wallet.publicKey,
750
+ whitelistEntry: whitelistPda,
751
+ streamerRegistration: streamerRegPda,
752
+ streamerWallet: streamerKeypair.publicKey,
753
+ vault: vaultPda,
754
+ mint,
755
+ programTokenAccount,
756
+ streamerTokenAccount,
757
+ instructionsSysvar: web3_js.SYSVAR_INSTRUCTIONS_PUBKEY
758
+ }).instruction();
759
+ const tx = new web3_js.Transaction().add(ed25519Ix).add(claimIx);
760
+ const provider = this.program.provider;
761
+ const txSignature = await provider.sendAndConfirm(tx);
762
+ return { txSignature };
763
+ }
764
+ // ═══════════════════════════════════════════════════════════════════════════
765
+ // Read State
766
+ // ═══════════════════════════════════════════════════════════════════════════
767
+ async getStreamerRegistration(streamerId) {
768
+ const pda = this.deriveStreamerRegistration(streamerId);
769
+ try {
770
+ const account = await this.program.account.streamerRegistration.fetch(pda);
771
+ return {
772
+ streamerId: account.streamerId,
773
+ wallet: account.wallet,
774
+ verifiedAt: account.verifiedAt.toNumber(),
775
+ registeredBy: account.registeredBy,
776
+ createdAt: account.createdAt.toNumber()
777
+ };
778
+ } catch {
779
+ return null;
780
+ }
781
+ }
782
+ async isWhitelisted(wallet) {
783
+ const pda = this.deriveWhitelistEntry(wallet);
784
+ try {
785
+ const account = await this.program.account.whitelistEntry.fetch(pda);
786
+ return account.active;
787
+ } catch {
788
+ return false;
789
+ }
790
+ }
791
+ async getVaultBalance(mint) {
792
+ const vaultPda = this.deriveVault();
793
+ const sol = BigInt(await this.connection.getBalance(vaultPda));
794
+ let tokens = 0n;
795
+ if (mint) {
796
+ const ata = splToken.getAssociatedTokenAddressSync(mint, vaultPda, true);
797
+ try {
798
+ const account = await splToken.getAccount(this.connection, ata);
799
+ tokens = account.amount;
800
+ } catch {
801
+ }
802
+ }
803
+ return { sol, tokens };
804
+ }
805
+ };
621
806
  function formatTokens(raw) {
622
807
  const tokens = Number(raw) / 10 ** TOKEN_DECIMALS;
623
808
  return tokens.toLocaleString(void 0, { maximumFractionDigits: 2 });
@@ -643,6 +828,7 @@ exports.LP_PERCENT = LP_PERCENT;
643
828
  exports.METADATA_PROGRAM_ID = METADATA_PROGRAM_ID;
644
829
  exports.PROGRAM_ID = PROGRAM_ID;
645
830
  exports.STREAMER_PROGRAM_ID = STREAMER_PROGRAM_ID;
831
+ exports.StreamerSDK = StreamerSDK;
646
832
  exports.TOKEN_DECIMALS = TOKEN_DECIMALS;
647
833
  exports.TREASURY_PERCENT = TREASURY_PERCENT;
648
834
  exports.formatSol = formatSol;