@hawksightco/hawk-sdk 1.3.199 → 1.3.201

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.
Files changed (37) hide show
  1. package/dist/src/addresses.d.ts +0 -3
  2. package/dist/src/addresses.d.ts.map +1 -1
  3. package/dist/src/addresses.js +1 -6
  4. package/dist/src/classes/SimpleIxGenerator.d.ts +0 -7
  5. package/dist/src/classes/SimpleIxGenerator.d.ts.map +1 -1
  6. package/dist/src/classes/SimpleIxGenerator.js +0 -7
  7. package/dist/src/classes/SimplePdaGenerator.d.ts +2 -7
  8. package/dist/src/classes/SimplePdaGenerator.d.ts.map +1 -1
  9. package/dist/src/classes/SimplePdaGenerator.js +2 -7
  10. package/dist/src/classes/Transactions.d.ts +14 -54
  11. package/dist/src/classes/Transactions.d.ts.map +1 -1
  12. package/dist/src/classes/Transactions.js +217 -259
  13. package/dist/src/classes/TxGenerator.d.ts +1 -30
  14. package/dist/src/classes/TxGenerator.d.ts.map +1 -1
  15. package/dist/src/classes/TxGenerator.js +0 -102
  16. package/dist/src/classes/TxGeneratorAutomations.d.ts +15 -29
  17. package/dist/src/classes/TxGeneratorAutomations.d.ts.map +1 -1
  18. package/dist/src/classes/TxGeneratorAutomations.js +52 -84
  19. package/dist/src/functions.js +1 -1
  20. package/dist/src/idl/iyf-extension-idl.d.ts +12 -0
  21. package/dist/src/idl/iyf-extension-idl.d.ts.map +1 -1
  22. package/dist/src/idl/iyf-extension-idl.js +12 -0
  23. package/dist/src/ixGenerator/MeteoraDlmmIxGenerator.d.ts +6 -4
  24. package/dist/src/ixGenerator/MeteoraDlmmIxGenerator.d.ts.map +1 -1
  25. package/dist/src/ixGenerator/MeteoraDlmmIxGenerator.js +4 -10
  26. package/dist/src/pdaGenerator/MeteoraPdaGenerator.d.ts +0 -13
  27. package/dist/src/pdaGenerator/MeteoraPdaGenerator.d.ts.map +1 -1
  28. package/dist/src/pdaGenerator/MeteoraPdaGenerator.js +0 -26
  29. package/dist/src/types.d.ts +23 -127
  30. package/dist/src/types.d.ts.map +1 -1
  31. package/package.json +1 -1
  32. package/dist/src/ixGenerator/HatchIxGenerator.d.ts +0 -186
  33. package/dist/src/ixGenerator/HatchIxGenerator.d.ts.map +0 -1
  34. package/dist/src/ixGenerator/HatchIxGenerator.js +0 -453
  35. package/dist/src/pdaGenerator/HatchPdaGenerator.d.ts +0 -62
  36. package/dist/src/pdaGenerator/HatchPdaGenerator.d.ts.map +0 -1
  37. package/dist/src/pdaGenerator/HatchPdaGenerator.js +0 -118
@@ -1,186 +0,0 @@
1
- import * as web3 from "@solana/web3.js";
2
- import { SimplePdaGenerator } from "../classes/SimplePdaGenerator";
3
- type CreatePoolAndLockedPositionParams = {
4
- connection: web3.Connection;
5
- authority: web3.PublicKey;
6
- /** Position keypair public key - must be a signer (no longer derived from base) */
7
- position: web3.PublicKey;
8
- presetParameter: web3.PublicKey;
9
- tokenMintX: web3.PublicKey;
10
- tokenMintY: web3.PublicKey;
11
- tokenProgramX: web3.PublicKey;
12
- tokenProgramY: web3.PublicKey;
13
- activeId: number;
14
- lowerBinId: number;
15
- upperBinId: number;
16
- /** Strategy type: 0 = Spot, 1 = Curve, 2 = BidAsk (same as MeteoraDlmm) */
17
- strategyType: number;
18
- };
19
- type CreateTokenAndLaunchAccountParams = {
20
- authority: web3.PublicKey;
21
- tokenMint: web3.PublicKey;
22
- tokenProgram: web3.PublicKey;
23
- /** Token name for metadata (e.g., "My Token") */
24
- name: string;
25
- /** Token symbol for metadata (e.g., "MYT") */
26
- symbol: string;
27
- /** Token metadata URI (e.g., "https://example.com/metadata.json") */
28
- uri: string;
29
- };
30
- type ClaimFeeParams = {
31
- connection: web3.Connection;
32
- rebalanceAuthority: web3.PublicKey;
33
- launcherAuthority: web3.PublicKey;
34
- position: web3.PublicKey;
35
- lbPair: web3.PublicKey;
36
- minBinId: number;
37
- maxBinId: number;
38
- tokenMintX: web3.PublicKey;
39
- tokenMintY: web3.PublicKey;
40
- tokenProgramX: web3.PublicKey;
41
- tokenProgramY: web3.PublicKey;
42
- };
43
- type ClaimRewardParams = {
44
- connection: web3.Connection;
45
- rebalanceAuthority: web3.PublicKey;
46
- launcherAuthority: web3.PublicKey;
47
- position: web3.PublicKey;
48
- lbPair: web3.PublicKey;
49
- rewardIndex: number;
50
- minBinId: number;
51
- maxBinId: number;
52
- rewardMint: web3.PublicKey;
53
- rewardVault: web3.PublicKey;
54
- tokenProgram: web3.PublicKey;
55
- };
56
- type InitializeLauncherPdaParams = {
57
- authority: web3.PublicKey;
58
- };
59
- /**
60
- * Instruction generator for the Hatch program.
61
- *
62
- * Hatch provides a secure interface for:
63
- * - Creating locked DLMM positions (LauncherPda is position owner)
64
- * - Claiming trading fees (via rebalance authority)
65
- * - Claiming farming rewards (via rebalance authority)
66
- *
67
- * Note: Positions are "locked" because only the Hatch program can sign
68
- * for LauncherPda via CPI. There is no unlock mechanism.
69
- */
70
- export declare class HatchIxGenerator {
71
- private readonly pda;
72
- constructor(pda: SimplePdaGenerator);
73
- /**
74
- * Create a pool and locked position on Meteora DLMM via Hatch.
75
- *
76
- * The position will be owned by LauncherPda, making it effectively locked
77
- * since only the Hatch program can sign for LauncherPda.
78
- *
79
- * IMPORTANT: Tokens must be in LauncherPda-owned accounts before calling.
80
- * Only the position owner can deposit, and LauncherPda is the owner.
81
- *
82
- * Note: Position is now a keypair (signer), not a derived PDA.
83
- * The caller must generate a new keypair and pass its public key here.
84
- */
85
- createPoolAndLockedPosition({ connection, authority, position, presetParameter, tokenMintX, tokenMintY, tokenProgramX, tokenProgramY, activeId, lowerBinId, upperBinId, strategyType, }: CreatePoolAndLockedPositionParams): Promise<web3.TransactionInstruction>;
86
- /**
87
- * Create a token mint, metadata, and launch token account in a single instruction.
88
- *
89
- * This instruction:
90
- * - Creates the token mint (Token-2022)
91
- * - Creates token metadata via Metaplex Token Metadata program
92
- * - Creates the LaunchTokenAccount PDA to hold tokens for position creation
93
- * - Mints the initial supply to the LaunchTokenAccount
94
- *
95
- * Must be called before createPoolAndLockedPosition.
96
- * LauncherPda must be initialized first (via initializeLauncherPda).
97
- *
98
- * @param authority - The launcher authority wallet
99
- * @param tokenMint - The token mint keypair public key (must be a signer)
100
- * @param tokenProgram - The token program (TOKEN_PROGRAM_ID or TOKEN_2022_PROGRAM_ID)
101
- * @param name - Token name for metadata
102
- * @param symbol - Token symbol for metadata
103
- * @param uri - Token metadata URI
104
- */
105
- createTokenAndLaunchAccount({ authority, tokenMint, tokenProgram, name, symbol, uri, }: CreateTokenAndLaunchAccountParams): web3.TransactionInstruction;
106
- /**
107
- * Claim trading fees from a Hatch position.
108
- *
109
- * Only the rebalance authority can call this.
110
- * Fees go to LauncherPda-owned token accounts, with protocol fee to treasury.
111
- * LauncherPda signs for the claim via CPI.
112
- */
113
- claimFee({ connection, rebalanceAuthority, launcherAuthority, position, lbPair, minBinId, maxBinId, tokenMintX, tokenMintY, tokenProgramX, tokenProgramY, }: ClaimFeeParams): Promise<web3.TransactionInstruction>;
114
- /**
115
- * Claim farming rewards from a Hatch position.
116
- *
117
- * Only the rebalance authority can call this.
118
- * Rewards go to LauncherPda-owned token account, with protocol fee to treasury.
119
- * LauncherPda signs for the claim via CPI.
120
- */
121
- claimReward({ connection, rebalanceAuthority, launcherAuthority, position, lbPair, rewardIndex, minBinId, maxBinId, rewardMint, rewardVault, tokenProgram, }: ClaimRewardParams): Promise<web3.TransactionInstruction>;
122
- /**
123
- * Initialize a LauncherPda for a given authority.
124
- *
125
- * Must be called before createPoolAndLockedPosition if the LauncherPda
126
- * doesn't exist yet. This is a one-time operation per authority wallet.
127
- *
128
- * The LauncherPda becomes the position owner for all positions created
129
- * by this authority.
130
- *
131
- * @param authority - The wallet that will own this LauncherPda
132
- */
133
- initializeLauncherPda({ authority, }: InitializeLauncherPdaParams): web3.TransactionInstruction;
134
- /**
135
- * Check if LauncherPda exists for the given authority.
136
- *
137
- * @param connection - Solana connection
138
- * @param authority - The authority wallet
139
- * @returns true if LauncherPda exists, false otherwise
140
- */
141
- launcherPdaExists(connection: web3.Connection, authority: web3.PublicKey): Promise<boolean>;
142
- /**
143
- * Check if LaunchTokenAccount exists for the given mint and authority.
144
- *
145
- * @param connection - Solana connection
146
- * @param tokenMint - The token mint address
147
- * @param authority - The authority wallet
148
- * @returns true if LaunchTokenAccount exists, false otherwise
149
- */
150
- launchTokenAccountExists(connection: web3.Connection, tokenMint: web3.PublicKey, authority: web3.PublicKey): Promise<boolean>;
151
- /**
152
- * Build all instructions needed to launch a token.
153
- * Automatically checks which accounts exist and only includes necessary init instructions.
154
- *
155
- * This is the recommended method for token launches as it handles:
156
- * - LauncherPda initialization (if not already initialized)
157
- * - Token mint and LaunchTokenAccount creation (if not already created)
158
- * - Pool and locked position creation
159
- *
160
- * @param params - All parameters needed for token launch
161
- * @returns Array of transaction instructions (only includes necessary init instructions)
162
- */
163
- buildTokenLaunchInstructions({ connection, authority, tokenMint, tokenProgram, name, symbol, uri, presetParameter, tokenMintY, tokenProgramX, tokenProgramY, position, activeId, lowerBinId, upperBinId, strategyType, }: {
164
- connection: web3.Connection;
165
- authority: web3.PublicKey;
166
- tokenMint: web3.PublicKey;
167
- tokenProgram: web3.PublicKey;
168
- /** Token name for metadata */
169
- name: string;
170
- /** Token symbol for metadata */
171
- symbol: string;
172
- /** Token metadata URI */
173
- uri: string;
174
- presetParameter: web3.PublicKey;
175
- tokenMintY: web3.PublicKey;
176
- tokenProgramX: web3.PublicKey;
177
- tokenProgramY: web3.PublicKey;
178
- position: web3.PublicKey;
179
- activeId: number;
180
- lowerBinId: number;
181
- upperBinId: number;
182
- strategyType: number;
183
- }): Promise<web3.TransactionInstruction[]>;
184
- }
185
- export {};
186
- //# sourceMappingURL=HatchIxGenerator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"HatchIxGenerator.d.ts","sourceRoot":"","sources":["../../../src/ixGenerator/HatchIxGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,iBAAiB,C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S,CAAC;QAC1B,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC;QAC7B,8BAA8B;QAC9B,IAAI,EAAE,MAAM,CAAC;QACb,gCAAgC;QAChC,MAAM,EAAE,MAAM,CAAC;QACf,yBAAyB;QACzB,GAAG,EAAE,MAAM,CAAC;QACZ,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC;QAChC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC;QAC3B,aAAa,EAAE,IAAI,CAAC,SAAS,CAAC;QAC9B,aAAa,EAAE,IAAI,CAAC,SAAS,CAAC;QAC9B,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC;QACzB,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;QACnB,UAAU,EAAE,MAAM,CAAC;QACnB,YAAY,EAAE,MAAM,CAAC;KACtB,GAAG,OAAO,CAAC,IAAI,CAAC,sBAAsB,EAAE,CAAC;CA4C3C"}
@@ -1,453 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- var __importDefault = (this && this.__importDefault) || function (mod) {
45
- return (mod && mod.__esModule) ? mod : { "default": mod };
46
- };
47
- Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.HatchIxGenerator = void 0;
49
- const web3 = __importStar(require("@solana/web3.js"));
50
- const bn_js_1 = __importDefault(require("bn.js"));
51
- const addresses_1 = require("../addresses");
52
- const functions_1 = require("../functions");
53
- const meteora_1 = require("../meteora");
54
- // Anchor discriminators from the IDL
55
- const DISCRIMINATORS = {
56
- createPoolAndLockedPosition: Buffer.from([140, 164, 125, 74, 166, 59, 206, 48]),
57
- createTokenAndLaunchAccount: Buffer.from([12, 93, 251, 247, 85, 70, 76, 132]),
58
- claimFee: Buffer.from([169, 32, 79, 137, 136, 232, 70, 137]),
59
- claimReward: Buffer.from([149, 95, 181, 242, 94, 90, 158, 162]),
60
- initializeLauncherPda: Buffer.from([149, 59, 86, 45, 74, 12, 137, 15]),
61
- };
62
- /**
63
- * Instruction generator for the Hatch program.
64
- *
65
- * Hatch provides a secure interface for:
66
- * - Creating locked DLMM positions (LauncherPda is position owner)
67
- * - Claiming trading fees (via rebalance authority)
68
- * - Claiming farming rewards (via rebalance authority)
69
- *
70
- * Note: Positions are "locked" because only the Hatch program can sign
71
- * for LauncherPda via CPI. There is no unlock mechanism.
72
- */
73
- class HatchIxGenerator {
74
- constructor(pda) {
75
- this.pda = pda;
76
- }
77
- /**
78
- * Create a pool and locked position on Meteora DLMM via Hatch.
79
- *
80
- * The position will be owned by LauncherPda, making it effectively locked
81
- * since only the Hatch program can sign for LauncherPda.
82
- *
83
- * IMPORTANT: Tokens must be in LauncherPda-owned accounts before calling.
84
- * Only the position owner can deposit, and LauncherPda is the owner.
85
- *
86
- * Note: Position is now a keypair (signer), not a derived PDA.
87
- * The caller must generate a new keypair and pass its public key here.
88
- */
89
- createPoolAndLockedPosition(_a) {
90
- return __awaiter(this, arguments, void 0, function* ({ connection, authority, position, presetParameter, tokenMintX, tokenMintY, tokenProgramX, tokenProgramY, activeId, lowerBinId, upperBinId, strategyType, }) {
91
- // Derive LauncherPda (now the position owner)
92
- const launcherPda = this.pda.hatch.deriveLauncherPda(authority);
93
- // Derive Meteora accounts
94
- const lbPair = this.pda.meteora.deriveLbPairWithPresetParamWithIndexKey(presetParameter, tokenMintX, tokenMintY);
95
- const reserveX = this.pda.meteora.deriveReserve(tokenMintX, lbPair);
96
- const reserveY = this.pda.meteora.deriveReserve(tokenMintY, lbPair);
97
- const oracle = this.pda.meteora.deriveOracle(lbPair);
98
- const binArrayBitmapExtension = this.pda.meteora.deriveBinArrayBitmapExtension(lbPair);
99
- // LaunchTokenAccount PDA holds token X for position creation (replaces userTokenX)
100
- const launchTokenAccount = this.pda.hatch.deriveLaunchTokenAccount(tokenMintX, launcherPda);
101
- // Token Y account still owned by LauncherPda
102
- const userTokenY = (0, functions_1.generateAta)(launcherPda, tokenMintY, tokenProgramY);
103
- // Derive bin arrays for remaining accounts
104
- const binArrays = meteora_1.MeteoraFunctions.findMeteoraTickArrays(lbPair, lowerBinId, upperBinId);
105
- // Serialize instruction data (amounts removed - hardcoded to 70% in contract)
106
- const activeIdBuf = Buffer.alloc(4);
107
- activeIdBuf.writeInt32LE(activeId, 0);
108
- const lowerBinIdBuf = Buffer.alloc(4);
109
- lowerBinIdBuf.writeInt32LE(lowerBinId, 0);
110
- const upperBinIdBuf = Buffer.alloc(4);
111
- upperBinIdBuf.writeInt32LE(upperBinId, 0);
112
- const data = Buffer.concat([
113
- DISCRIMINATORS.createPoolAndLockedPosition,
114
- activeIdBuf,
115
- lowerBinIdBuf,
116
- upperBinIdBuf,
117
- Buffer.from([strategyType]), // Same as MeteoraDlmm
118
- ]);
119
- // Account order: position is now a signer, launchTokenAccount replaces userTokenX
120
- return new web3.TransactionInstruction({
121
- programId: addresses_1.HATCH_PROGRAM,
122
- keys: [
123
- { pubkey: authority, isSigner: true, isWritable: true },
124
- { pubkey: launcherPda, isSigner: false, isWritable: true },
125
- { pubkey: lbPair, isSigner: false, isWritable: true },
126
- { pubkey: reserveX, isSigner: false, isWritable: true },
127
- { pubkey: reserveY, isSigner: false, isWritable: true },
128
- { pubkey: oracle, isSigner: false, isWritable: true },
129
- { pubkey: presetParameter, isSigner: false, isWritable: false },
130
- { pubkey: tokenMintX, isSigner: false, isWritable: false },
131
- { pubkey: tokenMintY, isSigner: false, isWritable: false },
132
- { pubkey: launchTokenAccount, isSigner: false, isWritable: true }, // LaunchTokenAccount PDA
133
- { pubkey: userTokenY, isSigner: false, isWritable: true },
134
- { pubkey: position, isSigner: true, isWritable: true }, // Position is now a signer
135
- { pubkey: binArrayBitmapExtension, isSigner: false, isWritable: true },
136
- { pubkey: tokenProgramX, isSigner: false, isWritable: false },
137
- { pubkey: tokenProgramY, isSigner: false, isWritable: false },
138
- { pubkey: web3.SystemProgram.programId, isSigner: false, isWritable: false },
139
- { pubkey: web3.SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false }, // Rent sysvar added
140
- { pubkey: addresses_1.METEORA_EVENT_AUTHORITY, isSigner: false, isWritable: false },
141
- { pubkey: addresses_1.METEORA_DLMM_PROGRAM, isSigner: false, isWritable: false },
142
- // Remaining accounts: bin arrays
143
- ...binArrays.map(pubkey => ({
144
- pubkey,
145
- isSigner: false,
146
- isWritable: true,
147
- })),
148
- ],
149
- data,
150
- });
151
- });
152
- }
153
- /**
154
- * Create a token mint, metadata, and launch token account in a single instruction.
155
- *
156
- * This instruction:
157
- * - Creates the token mint (Token-2022)
158
- * - Creates token metadata via Metaplex Token Metadata program
159
- * - Creates the LaunchTokenAccount PDA to hold tokens for position creation
160
- * - Mints the initial supply to the LaunchTokenAccount
161
- *
162
- * Must be called before createPoolAndLockedPosition.
163
- * LauncherPda must be initialized first (via initializeLauncherPda).
164
- *
165
- * @param authority - The launcher authority wallet
166
- * @param tokenMint - The token mint keypair public key (must be a signer)
167
- * @param tokenProgram - The token program (TOKEN_PROGRAM_ID or TOKEN_2022_PROGRAM_ID)
168
- * @param name - Token name for metadata
169
- * @param symbol - Token symbol for metadata
170
- * @param uri - Token metadata URI
171
- */
172
- createTokenAndLaunchAccount({ authority, tokenMint, tokenProgram, name, symbol, uri, }) {
173
- // Derive LauncherPda
174
- const launcherPda = this.pda.hatch.deriveLauncherPda(authority);
175
- // Derive Metadata PDA (Metaplex)
176
- const metadata = this.pda.hatch.deriveMetadata(tokenMint);
177
- // Derive LaunchTokenAccount PDA
178
- const launchTokenAccount = this.pda.hatch.deriveLaunchTokenAccount(tokenMint, launcherPda);
179
- // Serialize instruction data with Borsh strings
180
- // Format: discriminator + name (u32 len + bytes) + symbol (u32 len + bytes) + uri (u32 len + bytes)
181
- const nameBytes = Buffer.from(name, 'utf-8');
182
- const symbolBytes = Buffer.from(symbol, 'utf-8');
183
- const uriBytes = Buffer.from(uri, 'utf-8');
184
- const nameLenBuf = Buffer.alloc(4);
185
- nameLenBuf.writeUInt32LE(nameBytes.length, 0);
186
- const symbolLenBuf = Buffer.alloc(4);
187
- symbolLenBuf.writeUInt32LE(symbolBytes.length, 0);
188
- const uriLenBuf = Buffer.alloc(4);
189
- uriLenBuf.writeUInt32LE(uriBytes.length, 0);
190
- const data = Buffer.concat([
191
- DISCRIMINATORS.createTokenAndLaunchAccount,
192
- nameLenBuf,
193
- nameBytes,
194
- symbolLenBuf,
195
- symbolBytes,
196
- uriLenBuf,
197
- uriBytes,
198
- ]);
199
- return new web3.TransactionInstruction({
200
- programId: addresses_1.HATCH_PROGRAM,
201
- keys: [
202
- { pubkey: authority, isSigner: true, isWritable: true },
203
- { pubkey: launcherPda, isSigner: false, isWritable: true },
204
- { pubkey: tokenMint, isSigner: true, isWritable: true },
205
- { pubkey: metadata, isSigner: false, isWritable: true },
206
- { pubkey: launchTokenAccount, isSigner: false, isWritable: true },
207
- { pubkey: addresses_1.TOKEN_METADATA_PROGRAM, isSigner: false, isWritable: false },
208
- { pubkey: tokenProgram, isSigner: false, isWritable: false },
209
- { pubkey: web3.SystemProgram.programId, isSigner: false, isWritable: false },
210
- { pubkey: web3.SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false },
211
- ],
212
- data,
213
- });
214
- }
215
- /**
216
- * Claim trading fees from a Hatch position.
217
- *
218
- * Only the rebalance authority can call this.
219
- * Fees go to LauncherPda-owned token accounts, with protocol fee to treasury.
220
- * LauncherPda signs for the claim via CPI.
221
- */
222
- claimFee(_a) {
223
- return __awaiter(this, arguments, void 0, function* ({ connection, rebalanceAuthority, launcherAuthority, position, lbPair, minBinId, maxBinId, tokenMintX, tokenMintY, tokenProgramX, tokenProgramY, }) {
224
- // Derive LauncherPda (position owner)
225
- const launcherPda = this.pda.hatch.deriveLauncherPda(launcherAuthority);
226
- // Derive Meteora accounts
227
- const reserveX = this.pda.meteora.deriveReserve(tokenMintX, lbPair);
228
- const reserveY = this.pda.meteora.deriveReserve(tokenMintY, lbPair);
229
- // LauncherPda-owned token accounts for fees
230
- const userTokenX = (0, functions_1.generateAta)(launcherPda, tokenMintX, tokenProgramX);
231
- const userTokenY = (0, functions_1.generateAta)(launcherPda, tokenMintY, tokenProgramY);
232
- // Treasury token accounts
233
- const treasuryTokenX = (0, functions_1.generateAta)(addresses_1.HATCH_TREASURY, tokenMintX, tokenProgramX);
234
- const treasuryTokenY = (0, functions_1.generateAta)(addresses_1.HATCH_TREASURY, tokenMintY, tokenProgramY);
235
- // Derive bin arrays for remaining accounts
236
- const binArrays = this.pda.meteora.deriveBinArrays(lbPair, minBinId, maxBinId);
237
- // Serialize remaining accounts info (empty for now - Meteora handles internally)
238
- const remainingAccountsInfo = Buffer.alloc(4); // Empty vec: length = 0
239
- remainingAccountsInfo.writeUInt32LE(0, 0);
240
- // Serialize instruction data
241
- const minBinIdBuf = Buffer.alloc(4);
242
- minBinIdBuf.writeInt32LE(minBinId, 0);
243
- const maxBinIdBuf = Buffer.alloc(4);
244
- maxBinIdBuf.writeInt32LE(maxBinId, 0);
245
- const data = Buffer.concat([
246
- DISCRIMINATORS.claimFee,
247
- minBinIdBuf,
248
- maxBinIdBuf,
249
- remainingAccountsInfo,
250
- ]);
251
- // New account order (no HawkfiPda)
252
- return new web3.TransactionInstruction({
253
- programId: addresses_1.HATCH_PROGRAM,
254
- keys: [
255
- { pubkey: rebalanceAuthority, isSigner: true, isWritable: false },
256
- { pubkey: launcherPda, isSigner: false, isWritable: false },
257
- { pubkey: lbPair, isSigner: false, isWritable: true },
258
- { pubkey: position, isSigner: false, isWritable: true },
259
- { pubkey: reserveX, isSigner: false, isWritable: true },
260
- { pubkey: reserveY, isSigner: false, isWritable: true },
261
- { pubkey: userTokenX, isSigner: false, isWritable: true },
262
- { pubkey: userTokenY, isSigner: false, isWritable: true },
263
- { pubkey: treasuryTokenX, isSigner: false, isWritable: true },
264
- { pubkey: treasuryTokenY, isSigner: false, isWritable: true },
265
- { pubkey: tokenMintX, isSigner: false, isWritable: false },
266
- { pubkey: tokenMintY, isSigner: false, isWritable: false },
267
- { pubkey: tokenProgramX, isSigner: false, isWritable: false },
268
- { pubkey: tokenProgramY, isSigner: false, isWritable: false },
269
- { pubkey: addresses_1.MEMO_PROGRAM, isSigner: false, isWritable: false },
270
- { pubkey: addresses_1.METEORA_EVENT_AUTHORITY, isSigner: false, isWritable: false },
271
- { pubkey: addresses_1.METEORA_DLMM_PROGRAM, isSigner: false, isWritable: false },
272
- // Remaining accounts: bin arrays
273
- ...binArrays.map(pubkey => ({
274
- pubkey,
275
- isSigner: false,
276
- isWritable: true,
277
- })),
278
- ],
279
- data,
280
- });
281
- });
282
- }
283
- /**
284
- * Claim farming rewards from a Hatch position.
285
- *
286
- * Only the rebalance authority can call this.
287
- * Rewards go to LauncherPda-owned token account, with protocol fee to treasury.
288
- * LauncherPda signs for the claim via CPI.
289
- */
290
- claimReward(_a) {
291
- return __awaiter(this, arguments, void 0, function* ({ connection, rebalanceAuthority, launcherAuthority, position, lbPair, rewardIndex, minBinId, maxBinId, rewardMint, rewardVault, tokenProgram, }) {
292
- // Derive LauncherPda (position owner)
293
- const launcherPda = this.pda.hatch.deriveLauncherPda(launcherAuthority);
294
- // LauncherPda-owned token account for rewards
295
- const userTokenAccount = (0, functions_1.generateAta)(launcherPda, rewardMint, tokenProgram);
296
- // Treasury token account
297
- const treasuryTokenAccount = (0, functions_1.generateAta)(addresses_1.HATCH_TREASURY, rewardMint, tokenProgram);
298
- // Derive bin arrays for remaining accounts
299
- const binArrays = this.pda.meteora.deriveBinArrays(lbPair, minBinId, maxBinId);
300
- // Serialize remaining accounts info (empty for now)
301
- const remainingAccountsInfo = Buffer.alloc(4);
302
- remainingAccountsInfo.writeUInt32LE(0, 0);
303
- // Serialize instruction data
304
- const rewardIndexBuf = Buffer.alloc(8);
305
- new bn_js_1.default(rewardIndex).toArrayLike(Buffer, "le", 8).copy(rewardIndexBuf);
306
- const minBinIdBuf = Buffer.alloc(4);
307
- minBinIdBuf.writeInt32LE(minBinId, 0);
308
- const maxBinIdBuf = Buffer.alloc(4);
309
- maxBinIdBuf.writeInt32LE(maxBinId, 0);
310
- const data = Buffer.concat([
311
- DISCRIMINATORS.claimReward,
312
- rewardIndexBuf,
313
- minBinIdBuf,
314
- maxBinIdBuf,
315
- remainingAccountsInfo,
316
- ]);
317
- // New account order (no HawkfiPda)
318
- return new web3.TransactionInstruction({
319
- programId: addresses_1.HATCH_PROGRAM,
320
- keys: [
321
- { pubkey: rebalanceAuthority, isSigner: true, isWritable: false },
322
- { pubkey: launcherPda, isSigner: false, isWritable: false },
323
- { pubkey: lbPair, isSigner: false, isWritable: true },
324
- { pubkey: position, isSigner: false, isWritable: true },
325
- { pubkey: rewardVault, isSigner: false, isWritable: true },
326
- { pubkey: rewardMint, isSigner: false, isWritable: false },
327
- { pubkey: userTokenAccount, isSigner: false, isWritable: true },
328
- { pubkey: treasuryTokenAccount, isSigner: false, isWritable: true },
329
- { pubkey: tokenProgram, isSigner: false, isWritable: false },
330
- { pubkey: addresses_1.MEMO_PROGRAM, isSigner: false, isWritable: false },
331
- { pubkey: addresses_1.METEORA_EVENT_AUTHORITY, isSigner: false, isWritable: false },
332
- { pubkey: addresses_1.METEORA_DLMM_PROGRAM, isSigner: false, isWritable: false },
333
- // Remaining accounts: bin arrays
334
- ...binArrays.map(pubkey => ({
335
- pubkey,
336
- isSigner: false,
337
- isWritable: true,
338
- })),
339
- ],
340
- data,
341
- });
342
- });
343
- }
344
- /**
345
- * Initialize a LauncherPda for a given authority.
346
- *
347
- * Must be called before createPoolAndLockedPosition if the LauncherPda
348
- * doesn't exist yet. This is a one-time operation per authority wallet.
349
- *
350
- * The LauncherPda becomes the position owner for all positions created
351
- * by this authority.
352
- *
353
- * @param authority - The wallet that will own this LauncherPda
354
- */
355
- initializeLauncherPda({ authority, }) {
356
- const launcherPda = this.pda.hatch.deriveLauncherPda(authority);
357
- return new web3.TransactionInstruction({
358
- programId: addresses_1.HATCH_PROGRAM,
359
- keys: [
360
- { pubkey: authority, isSigner: true, isWritable: true },
361
- { pubkey: launcherPda, isSigner: false, isWritable: true },
362
- { pubkey: web3.SystemProgram.programId, isSigner: false, isWritable: false },
363
- ],
364
- data: DISCRIMINATORS.initializeLauncherPda,
365
- });
366
- }
367
- // ============================================================================
368
- // HELPER METHODS FOR ACCOUNT EXISTENCE CHECKS
369
- // ============================================================================
370
- /**
371
- * Check if LauncherPda exists for the given authority.
372
- *
373
- * @param connection - Solana connection
374
- * @param authority - The authority wallet
375
- * @returns true if LauncherPda exists, false otherwise
376
- */
377
- launcherPdaExists(connection, authority) {
378
- return __awaiter(this, void 0, void 0, function* () {
379
- const launcherPda = this.pda.hatch.deriveLauncherPda(authority);
380
- const accountInfo = yield connection.getAccountInfo(launcherPda);
381
- return accountInfo !== null;
382
- });
383
- }
384
- /**
385
- * Check if LaunchTokenAccount exists for the given mint and authority.
386
- *
387
- * @param connection - Solana connection
388
- * @param tokenMint - The token mint address
389
- * @param authority - The authority wallet
390
- * @returns true if LaunchTokenAccount exists, false otherwise
391
- */
392
- launchTokenAccountExists(connection, tokenMint, authority) {
393
- return __awaiter(this, void 0, void 0, function* () {
394
- const launcherPda = this.pda.hatch.deriveLauncherPda(authority);
395
- const launchTokenAccount = this.pda.hatch.deriveLaunchTokenAccount(tokenMint, launcherPda);
396
- const accountInfo = yield connection.getAccountInfo(launchTokenAccount);
397
- return accountInfo !== null;
398
- });
399
- }
400
- /**
401
- * Build all instructions needed to launch a token.
402
- * Automatically checks which accounts exist and only includes necessary init instructions.
403
- *
404
- * This is the recommended method for token launches as it handles:
405
- * - LauncherPda initialization (if not already initialized)
406
- * - Token mint and LaunchTokenAccount creation (if not already created)
407
- * - Pool and locked position creation
408
- *
409
- * @param params - All parameters needed for token launch
410
- * @returns Array of transaction instructions (only includes necessary init instructions)
411
- */
412
- buildTokenLaunchInstructions(_a) {
413
- return __awaiter(this, arguments, void 0, function* ({ connection, authority, tokenMint, tokenProgram, name, symbol, uri, presetParameter, tokenMintY, tokenProgramX, tokenProgramY, position, activeId, lowerBinId, upperBinId, strategyType, }) {
414
- const instructions = [];
415
- // 1. Check if LauncherPda needs to be initialized
416
- const launcherPdaNeeded = !(yield this.launcherPdaExists(connection, authority));
417
- if (launcherPdaNeeded) {
418
- instructions.push(this.initializeLauncherPda({ authority }));
419
- }
420
- // 2. Check if LaunchTokenAccount needs to be created
421
- // Note: For new token launches, this will always be needed since tokenMint is new
422
- const launchTokenAccountNeeded = !(yield this.launchTokenAccountExists(connection, tokenMint, authority));
423
- if (launchTokenAccountNeeded) {
424
- instructions.push(this.createTokenAndLaunchAccount({
425
- authority,
426
- tokenMint,
427
- tokenProgram,
428
- name,
429
- symbol,
430
- uri,
431
- }));
432
- }
433
- // 3. Always add the pool creation instruction
434
- const poolIx = yield this.createPoolAndLockedPosition({
435
- connection,
436
- authority,
437
- position,
438
- presetParameter,
439
- tokenMintX: tokenMint,
440
- tokenMintY,
441
- tokenProgramX,
442
- tokenProgramY,
443
- activeId,
444
- lowerBinId,
445
- upperBinId,
446
- strategyType,
447
- });
448
- instructions.push(poolIx);
449
- return instructions;
450
- });
451
- }
452
- }
453
- exports.HatchIxGenerator = HatchIxGenerator;