@hodlmarkets/sdk 0.1.0 → 0.1.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.
Files changed (51) hide show
  1. package/dist/accounts.cjs +22 -0
  2. package/dist/accounts.cjs.map +1 -1
  3. package/dist/accounts.js +22 -0
  4. package/dist/accounts.js.map +1 -1
  5. package/dist/client.cjs +340 -28
  6. package/dist/client.cjs.map +1 -1
  7. package/dist/client.d.cts +6 -2
  8. package/dist/client.d.ts +6 -2
  9. package/dist/client.js +341 -29
  10. package/dist/client.js.map +1 -1
  11. package/dist/constants.cjs +3 -1
  12. package/dist/constants.cjs.map +1 -1
  13. package/dist/constants.d.cts +5 -3
  14. package/dist/constants.d.ts +5 -3
  15. package/dist/constants.js +3 -2
  16. package/dist/constants.js.map +1 -1
  17. package/dist/events.cjs +333 -14
  18. package/dist/events.cjs.map +1 -1
  19. package/dist/events.d.cts +9 -0
  20. package/dist/events.d.ts +9 -0
  21. package/dist/events.js +334 -15
  22. package/dist/events.js.map +1 -1
  23. package/dist/index.cjs +375 -31
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +3 -3
  26. package/dist/index.d.ts +3 -3
  27. package/dist/index.js +375 -32
  28. package/dist/index.js.map +1 -1
  29. package/dist/instructions.cjs +22 -0
  30. package/dist/instructions.cjs.map +1 -1
  31. package/dist/instructions.js +22 -0
  32. package/dist/instructions.js.map +1 -1
  33. package/dist/math.cjs +33 -0
  34. package/dist/math.cjs.map +1 -1
  35. package/dist/math.d.cts +14 -4
  36. package/dist/math.d.ts +14 -4
  37. package/dist/math.js +33 -1
  38. package/dist/math.js.map +1 -1
  39. package/dist/pda.cjs +1 -0
  40. package/dist/pda.cjs.map +1 -1
  41. package/dist/pda.js +1 -0
  42. package/dist/pda.js.map +1 -1
  43. package/dist/transaction.cjs +0 -13
  44. package/dist/transaction.cjs.map +1 -1
  45. package/dist/transaction.d.cts +5 -3
  46. package/dist/transaction.d.ts +5 -3
  47. package/dist/transaction.js +1 -13
  48. package/dist/transaction.js.map +1 -1
  49. package/dist/types.d.cts +3 -0
  50. package/dist/types.d.ts +3 -0
  51. package/package.json +5 -3
package/dist/index.d.cts CHANGED
@@ -1,12 +1,12 @@
1
- export { BPS_DENOMINATOR, DECIMALS, DEVNET_CONFIG, LIMITS, MAINNET_CONFIG, PROGRAM_ID, PROTOCOL_AUTHORITY, PROTOCOL_MINT_FEE, SEEDS, TOTAL_SUPPLY, TRADE_FEE_BPS, VEST_DURATION, VIRTUAL_SOL, VestDuration } from './constants.cjs';
1
+ export { BPS_DENOMINATOR, DECIMALS, DEVNET_CONFIG, LIMITS, MAINNET_CONFIG, MIGRATION_SOL_THRESHOLD, PROGRAM_ID, PROTOCOL_AUTHORITY, PROTOCOL_MINT_FEE, SEEDS, TOTAL_SUPPLY, TRADE_FEE_BPS, VEST_DURATION, VIRTUAL_SOL, VestDuration } from './constants.cjs';
2
2
  export { HODL_ERRORS, HodlError, parseHodlError } from './errors.cjs';
3
3
  export { AccrualClaimedEvent, BuyParams, CreateTokenParams, HodlEvent, PoolMetadata, PoolState, Position, PositionClosedEvent, SdkConfig, SellParams, TokenCreatedEvent, TokenPurchasedEvent, TokenSoldEvent } from './types.cjs';
4
4
  export { getEventAuthorityPDA, getPoolStatePDA, getPositionPDA, getProtocolFeesPDA, getSolVaultPDA, getVaultAuthorityPDA } from './pda.cjs';
5
- export { applySlippage, calculateAccruedTokens, calculateBuyAmount, calculatePriceImpact, calculateSellAmount, calculateSolForExactTokens, calculateSpotPrice, calculateTradableVaultedSplit } from './math.cjs';
5
+ export { applySlippage, calculateAccruedTokens, calculateBuyAmount, calculateClaimableTokens, calculatePriceImpact, calculateSellAmount, calculateSolForExactTokens, calculateSpotPrice, calculateTradableVaultedSplit } from './math.cjs';
6
6
  export { fetchPoolState, fetchPoolStateByAddress, fetchPosition } from './accounts.cjs';
7
7
  export { buildBuyInstruction, buildClaimAccruedInstruction, buildClosePositionInstruction, buildCreateTokenInstruction, buildSellInstruction } from './instructions.cjs';
8
8
  export { SubscriptionOptions, fetchAndParseTransaction, parseTransactionEvents, subscribeToAccrualClaimed, subscribeToEvents, subscribeToPositionClosed, subscribeToTokenCreated, subscribeToTokenPurchased, subscribeToTokenSold, unsubscribeFromEvents } from './events.cjs';
9
- export { TxOptions, buildTransaction, sendTransaction } from './transaction.cjs';
9
+ export { TxOptions, buildTransaction } from './transaction.cjs';
10
10
  export { HodlClient } from './client.cjs';
11
11
  import '@solana/web3.js';
12
12
  import 'bn.js';
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- export { BPS_DENOMINATOR, DECIMALS, DEVNET_CONFIG, LIMITS, MAINNET_CONFIG, PROGRAM_ID, PROTOCOL_AUTHORITY, PROTOCOL_MINT_FEE, SEEDS, TOTAL_SUPPLY, TRADE_FEE_BPS, VEST_DURATION, VIRTUAL_SOL, VestDuration } from './constants.js';
1
+ export { BPS_DENOMINATOR, DECIMALS, DEVNET_CONFIG, LIMITS, MAINNET_CONFIG, MIGRATION_SOL_THRESHOLD, PROGRAM_ID, PROTOCOL_AUTHORITY, PROTOCOL_MINT_FEE, SEEDS, TOTAL_SUPPLY, TRADE_FEE_BPS, VEST_DURATION, VIRTUAL_SOL, VestDuration } from './constants.js';
2
2
  export { HODL_ERRORS, HodlError, parseHodlError } from './errors.js';
3
3
  export { AccrualClaimedEvent, BuyParams, CreateTokenParams, HodlEvent, PoolMetadata, PoolState, Position, PositionClosedEvent, SdkConfig, SellParams, TokenCreatedEvent, TokenPurchasedEvent, TokenSoldEvent } from './types.js';
4
4
  export { getEventAuthorityPDA, getPoolStatePDA, getPositionPDA, getProtocolFeesPDA, getSolVaultPDA, getVaultAuthorityPDA } from './pda.js';
5
- export { applySlippage, calculateAccruedTokens, calculateBuyAmount, calculatePriceImpact, calculateSellAmount, calculateSolForExactTokens, calculateSpotPrice, calculateTradableVaultedSplit } from './math.js';
5
+ export { applySlippage, calculateAccruedTokens, calculateBuyAmount, calculateClaimableTokens, calculatePriceImpact, calculateSellAmount, calculateSolForExactTokens, calculateSpotPrice, calculateTradableVaultedSplit } from './math.js';
6
6
  export { fetchPoolState, fetchPoolStateByAddress, fetchPosition } from './accounts.js';
7
7
  export { buildBuyInstruction, buildClaimAccruedInstruction, buildClosePositionInstruction, buildCreateTokenInstruction, buildSellInstruction } from './instructions.js';
8
8
  export { SubscriptionOptions, fetchAndParseTransaction, parseTransactionEvents, subscribeToAccrualClaimed, subscribeToEvents, subscribeToPositionClosed, subscribeToTokenCreated, subscribeToTokenPurchased, subscribeToTokenSold, unsubscribeFromEvents } from './events.js';
9
- export { TxOptions, buildTransaction, sendTransaction } from './transaction.js';
9
+ export { TxOptions, buildTransaction } from './transaction.js';
10
10
  export { HodlClient } from './client.js';
11
11
  import '@solana/web3.js';
12
12
  import 'bn.js';
package/dist/index.js CHANGED
@@ -1,9 +1,240 @@
1
1
  import { PublicKey, SystemProgram, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RENT_PUBKEY, ComputeBudgetProgram, TransactionMessage, VersionedTransaction } from '@solana/web3.js';
2
2
  import BN2 from 'bn.js';
3
- import { BorshCoder, EventParser, AnchorProvider, Program } from '@coral-xyz/anchor';
3
+ import { BorshCoder, utils, AnchorProvider, Program } from '@coral-xyz/anchor';
4
4
  import { getAssociatedTokenAddressSync, ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token';
5
5
 
6
- // src/constants.ts
6
+ var __create = Object.create;
7
+ var __defProp = Object.defineProperty;
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __getOwnPropNames = Object.getOwnPropertyNames;
10
+ var __getProtoOf = Object.getPrototypeOf;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
13
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
14
+ }) : x)(function(x) {
15
+ if (typeof require !== "undefined") return require.apply(this, arguments);
16
+ throw Error('Dynamic require of "' + x + '" is not supported');
17
+ });
18
+ var __commonJS = (cb, mod) => function __require2() {
19
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ __defProp(target, "default", { value: mod, enumerable: true }) ,
35
+ mod
36
+ ));
37
+
38
+ // node_modules/safe-buffer/index.js
39
+ var require_safe_buffer = __commonJS({
40
+ "node_modules/safe-buffer/index.js"(exports$1, module) {
41
+ var buffer = __require("buffer");
42
+ var Buffer2 = buffer.Buffer;
43
+ function copyProps(src, dst) {
44
+ for (var key in src) {
45
+ dst[key] = src[key];
46
+ }
47
+ }
48
+ if (Buffer2.from && Buffer2.alloc && Buffer2.allocUnsafe && Buffer2.allocUnsafeSlow) {
49
+ module.exports = buffer;
50
+ } else {
51
+ copyProps(buffer, exports$1);
52
+ exports$1.Buffer = SafeBuffer;
53
+ }
54
+ function SafeBuffer(arg, encodingOrOffset, length) {
55
+ return Buffer2(arg, encodingOrOffset, length);
56
+ }
57
+ SafeBuffer.prototype = Object.create(Buffer2.prototype);
58
+ copyProps(Buffer2, SafeBuffer);
59
+ SafeBuffer.from = function(arg, encodingOrOffset, length) {
60
+ if (typeof arg === "number") {
61
+ throw new TypeError("Argument must not be a number");
62
+ }
63
+ return Buffer2(arg, encodingOrOffset, length);
64
+ };
65
+ SafeBuffer.alloc = function(size, fill, encoding) {
66
+ if (typeof size !== "number") {
67
+ throw new TypeError("Argument must be a number");
68
+ }
69
+ var buf = Buffer2(size);
70
+ if (fill !== void 0) {
71
+ if (typeof encoding === "string") {
72
+ buf.fill(fill, encoding);
73
+ } else {
74
+ buf.fill(fill);
75
+ }
76
+ } else {
77
+ buf.fill(0);
78
+ }
79
+ return buf;
80
+ };
81
+ SafeBuffer.allocUnsafe = function(size) {
82
+ if (typeof size !== "number") {
83
+ throw new TypeError("Argument must be a number");
84
+ }
85
+ return Buffer2(size);
86
+ };
87
+ SafeBuffer.allocUnsafeSlow = function(size) {
88
+ if (typeof size !== "number") {
89
+ throw new TypeError("Argument must be a number");
90
+ }
91
+ return buffer.SlowBuffer(size);
92
+ };
93
+ }
94
+ });
95
+
96
+ // node_modules/base-x/src/index.js
97
+ var require_src = __commonJS({
98
+ "node_modules/base-x/src/index.js"(exports$1, module) {
99
+ var _Buffer = require_safe_buffer().Buffer;
100
+ function base(ALPHABET) {
101
+ if (ALPHABET.length >= 255) {
102
+ throw new TypeError("Alphabet too long");
103
+ }
104
+ var BASE_MAP = new Uint8Array(256);
105
+ for (var j = 0; j < BASE_MAP.length; j++) {
106
+ BASE_MAP[j] = 255;
107
+ }
108
+ for (var i = 0; i < ALPHABET.length; i++) {
109
+ var x = ALPHABET.charAt(i);
110
+ var xc = x.charCodeAt(0);
111
+ if (BASE_MAP[xc] !== 255) {
112
+ throw new TypeError(x + " is ambiguous");
113
+ }
114
+ BASE_MAP[xc] = i;
115
+ }
116
+ var BASE = ALPHABET.length;
117
+ var LEADER = ALPHABET.charAt(0);
118
+ var FACTOR = Math.log(BASE) / Math.log(256);
119
+ var iFACTOR = Math.log(256) / Math.log(BASE);
120
+ function encode(source) {
121
+ if (Array.isArray(source) || source instanceof Uint8Array) {
122
+ source = _Buffer.from(source);
123
+ }
124
+ if (!_Buffer.isBuffer(source)) {
125
+ throw new TypeError("Expected Buffer");
126
+ }
127
+ if (source.length === 0) {
128
+ return "";
129
+ }
130
+ var zeroes = 0;
131
+ var length = 0;
132
+ var pbegin = 0;
133
+ var pend = source.length;
134
+ while (pbegin !== pend && source[pbegin] === 0) {
135
+ pbegin++;
136
+ zeroes++;
137
+ }
138
+ var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
139
+ var b58 = new Uint8Array(size);
140
+ while (pbegin !== pend) {
141
+ var carry = source[pbegin];
142
+ var i2 = 0;
143
+ for (var it1 = size - 1; (carry !== 0 || i2 < length) && it1 !== -1; it1--, i2++) {
144
+ carry += 256 * b58[it1] >>> 0;
145
+ b58[it1] = carry % BASE >>> 0;
146
+ carry = carry / BASE >>> 0;
147
+ }
148
+ if (carry !== 0) {
149
+ throw new Error("Non-zero carry");
150
+ }
151
+ length = i2;
152
+ pbegin++;
153
+ }
154
+ var it2 = size - length;
155
+ while (it2 !== size && b58[it2] === 0) {
156
+ it2++;
157
+ }
158
+ var str = LEADER.repeat(zeroes);
159
+ for (; it2 < size; ++it2) {
160
+ str += ALPHABET.charAt(b58[it2]);
161
+ }
162
+ return str;
163
+ }
164
+ function decodeUnsafe(source) {
165
+ if (typeof source !== "string") {
166
+ throw new TypeError("Expected String");
167
+ }
168
+ if (source.length === 0) {
169
+ return _Buffer.alloc(0);
170
+ }
171
+ var psz = 0;
172
+ var zeroes = 0;
173
+ var length = 0;
174
+ while (source[psz] === LEADER) {
175
+ zeroes++;
176
+ psz++;
177
+ }
178
+ var size = (source.length - psz) * FACTOR + 1 >>> 0;
179
+ var b256 = new Uint8Array(size);
180
+ while (psz < source.length) {
181
+ var charCode = source.charCodeAt(psz);
182
+ if (charCode > 255) {
183
+ return;
184
+ }
185
+ var carry = BASE_MAP[charCode];
186
+ if (carry === 255) {
187
+ return;
188
+ }
189
+ var i2 = 0;
190
+ for (var it3 = size - 1; (carry !== 0 || i2 < length) && it3 !== -1; it3--, i2++) {
191
+ carry += BASE * b256[it3] >>> 0;
192
+ b256[it3] = carry % 256 >>> 0;
193
+ carry = carry / 256 >>> 0;
194
+ }
195
+ if (carry !== 0) {
196
+ throw new Error("Non-zero carry");
197
+ }
198
+ length = i2;
199
+ psz++;
200
+ }
201
+ var it4 = size - length;
202
+ while (it4 !== size && b256[it4] === 0) {
203
+ it4++;
204
+ }
205
+ var vch = _Buffer.allocUnsafe(zeroes + (size - it4));
206
+ vch.fill(0, 0, zeroes);
207
+ var j2 = zeroes;
208
+ while (it4 !== size) {
209
+ vch[j2++] = b256[it4++];
210
+ }
211
+ return vch;
212
+ }
213
+ function decode(string) {
214
+ var buffer = decodeUnsafe(string);
215
+ if (buffer) {
216
+ return buffer;
217
+ }
218
+ throw new Error("Non-base" + BASE + " character");
219
+ }
220
+ return {
221
+ encode,
222
+ decodeUnsafe,
223
+ decode
224
+ };
225
+ }
226
+ module.exports = base;
227
+ }
228
+ });
229
+
230
+ // node_modules/bs58/index.js
231
+ var require_bs58 = __commonJS({
232
+ "node_modules/bs58/index.js"(exports$1, module) {
233
+ var basex = require_src();
234
+ var ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
235
+ module.exports = basex(ALPHABET);
236
+ }
237
+ });
7
238
  var BPS_DENOMINATOR = 1e4;
8
239
  var PROGRAM_ID = new PublicKey("hodLrUfwyK3Z7Td5hdZhyojyznG1rqbHVex11y5s4yG");
9
240
  var PROTOCOL_AUTHORITY = new PublicKey("EFAquDGAHjkoPB6TGKVibD3BYhbFXNDjuXKpiBHdYzji");
@@ -36,9 +267,10 @@ var DEVNET_CONFIG = {
36
267
  totalSupply: TOTAL_SUPPLY
37
268
  };
38
269
  var TRADE_FEE_BPS = 25;
270
+ var MIGRATION_SOL_THRESHOLD = new BN2("85000000000");
39
271
  var VEST_DURATION = {
40
272
  ONE_MINUTE: 60,
41
- TEN_MINUTES: 600
273
+ THIRTY_MINUTES: 1800
42
274
  };
43
275
  var LIMITS = {
44
276
  NAME: { min: 1, max: 32 },
@@ -138,6 +370,37 @@ function calculateTradableVaultedSplit(tokensOut, tokensSold, bandSize = BAND_SI
138
370
  const vaulted = tokensOut.sub(tradable);
139
371
  return { tradable, vaulted, tradablePct };
140
372
  }
373
+ function calculateClaimableTokens(tradableTokens, vaultedTokens, initialVaulted, tokensTransferred, entryTimestamp, poolCreationTimestamp, vestDuration, currentTimestamp) {
374
+ const totalTokens = tradableTokens.add(vaultedTokens);
375
+ if (totalTokens.isZero()) return ZERO;
376
+ const globalUnlockTime = poolCreationTimestamp.add(vestDuration);
377
+ if (currentTimestamp.gte(globalUnlockTime)) {
378
+ const claimable2 = totalTokens.sub(tokensTransferred);
379
+ return claimable2.isNeg() ? ZERO : claimable2;
380
+ }
381
+ if (initialVaulted.isZero() || vestDuration.isZero()) {
382
+ const claimable2 = totalTokens.sub(tokensTransferred);
383
+ return claimable2.isNeg() ? ZERO : claimable2;
384
+ }
385
+ const elapsed = currentTimestamp.sub(entryTimestamp);
386
+ if (elapsed.isNeg()) {
387
+ const claimable2 = tradableTokens.sub(tokensTransferred);
388
+ return claimable2.isNeg() ? ZERO : claimable2;
389
+ }
390
+ let currentVaulted;
391
+ if (elapsed.gte(vestDuration)) {
392
+ currentVaulted = ZERO;
393
+ } else {
394
+ const remainingBps = BPS.sub(elapsed.mul(BPS).div(vestDuration));
395
+ currentVaulted = initialVaulted.mul(remainingBps).div(BPS);
396
+ }
397
+ if (currentVaulted.gt(totalTokens)) {
398
+ currentVaulted = totalTokens;
399
+ }
400
+ const newTradable = totalTokens.sub(currentVaulted);
401
+ const claimable = newTradable.sub(tokensTransferred);
402
+ return claimable.isNeg() ? ZERO : claimable;
403
+ }
141
404
  function calculateAccruedTokens(initialVaulted, tokensTransferred, entryTimestamp, vestDuration, currentTimestamp) {
142
405
  if (initialVaulted.isZero()) return ZERO;
143
406
  const remaining = initialVaulted.sub(tokensTransferred);
@@ -1627,6 +1890,27 @@ var hodl_default = {
1627
1890
  ],
1628
1891
  type: "u64"
1629
1892
  },
1893
+ {
1894
+ name: "migration_complete",
1895
+ docs: [
1896
+ "One-way flag: set to true once vamm_real_sol >= MIGRATION_SOL_THRESHOLD, never reverts"
1897
+ ],
1898
+ type: "bool"
1899
+ },
1900
+ {
1901
+ name: "total_fees_sol",
1902
+ docs: [
1903
+ "Cumulative SOL fees collected from buys (lamports)"
1904
+ ],
1905
+ type: "u64"
1906
+ },
1907
+ {
1908
+ name: "total_fees_tokens",
1909
+ docs: [
1910
+ "Cumulative token fees collected from sells"
1911
+ ],
1912
+ type: "u64"
1913
+ },
1630
1914
  {
1631
1915
  name: "bump_vault_auth",
1632
1916
  docs: [
@@ -2145,18 +2429,80 @@ async function buildClosePositionInstruction(params) {
2145
2429
  program: config.programId
2146
2430
  }).instruction();
2147
2431
  }
2432
+
2433
+ // src/events.ts
2434
+ var import_bs58 = __toESM(require_bs58());
2435
+ var PROGRAM_DATA_PREFIX = "Program data: ";
2436
+ function toCamelCase(name) {
2437
+ return name.charAt(0).toLowerCase() + name.slice(1);
2438
+ }
2439
+ function snakeToCamelKeys(obj) {
2440
+ const result = {};
2441
+ for (const [key, value] of Object.entries(obj)) {
2442
+ const camelKey = key.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
2443
+ result[camelKey] = value;
2444
+ }
2445
+ return result;
2446
+ }
2447
+ function tryDecodeEvent(coder, data) {
2448
+ try {
2449
+ const event = coder.events.decode(data);
2450
+ if (event) {
2451
+ return {
2452
+ name: toCamelCase(event.name),
2453
+ data: snakeToCamelKeys(event.data)
2454
+ };
2455
+ }
2456
+ } catch {
2457
+ }
2458
+ return null;
2459
+ }
2148
2460
  function parseTransactionEvents(input, config) {
2149
2461
  if (!input) return [];
2150
- const logs = Array.isArray(input) ? input : input.meta?.logMessages ?? [];
2151
- if (logs.length === 0) return [];
2152
2462
  const coder = new BorshCoder(hodl_default);
2153
- const parser = new EventParser(config.programId, coder);
2154
2463
  const events = [];
2155
- try {
2156
- for (const event of parser.parseLogs(logs)) {
2157
- events.push({ name: event.name, data: event.data });
2464
+ if (Array.isArray(input)) {
2465
+ for (const log of input) {
2466
+ if (!log.startsWith(PROGRAM_DATA_PREFIX)) continue;
2467
+ const b64 = log.slice(PROGRAM_DATA_PREFIX.length);
2468
+ const event = tryDecodeEvent(coder, b64);
2469
+ if (event) events.push(event);
2470
+ }
2471
+ return events;
2472
+ }
2473
+ const tx = input;
2474
+ const logs = tx.meta?.logMessages ?? [];
2475
+ for (const log of logs) {
2476
+ if (!log.startsWith(PROGRAM_DATA_PREFIX)) continue;
2477
+ const b64 = log.slice(PROGRAM_DATA_PREFIX.length);
2478
+ const event = tryDecodeEvent(coder, b64);
2479
+ if (event) events.push(event);
2480
+ }
2481
+ const programId = config.programId.toBase58();
2482
+ const staticKeys = tx.transaction.message.staticAccountKeys;
2483
+ const loadedWritable = tx.meta?.loadedAddresses?.writable ?? [];
2484
+ const loadedReadonly = tx.meta?.loadedAddresses?.readonly ?? [];
2485
+ const allKeys = [...staticKeys, ...loadedWritable, ...loadedReadonly];
2486
+ for (const inner of tx.meta?.innerInstructions ?? []) {
2487
+ for (const ix of inner.instructions) {
2488
+ const ixProgramKey = allKeys[ix.programIdIndex];
2489
+ if (!ixProgramKey || ixProgramKey.toBase58() !== programId) continue;
2490
+ try {
2491
+ const bytes = import_bs58.default.decode(ix.data);
2492
+ const b64Full = utils.bytes.base64.encode(Buffer.from(bytes));
2493
+ const eventFull = tryDecodeEvent(coder, b64Full);
2494
+ if (eventFull) {
2495
+ events.push(eventFull);
2496
+ continue;
2497
+ }
2498
+ if (bytes.length > 8) {
2499
+ const b64Skip = utils.bytes.base64.encode(Buffer.from(bytes.slice(8)));
2500
+ const eventSkip = tryDecodeEvent(coder, b64Skip);
2501
+ if (eventSkip) events.push(eventSkip);
2502
+ }
2503
+ } catch {
2504
+ }
2158
2505
  }
2159
- } catch {
2160
2506
  }
2161
2507
  return events;
2162
2508
  }
@@ -2170,7 +2516,6 @@ async function fetchAndParseTransaction(connection, signature, config) {
2170
2516
  function subscribeToEvents(connection, config, onEvent, opts = {}) {
2171
2517
  const commitment = opts.commitment ?? "confirmed";
2172
2518
  const coder = new BorshCoder(hodl_default);
2173
- const parser = new EventParser(config.programId, coder);
2174
2519
  return connection.onLogs(
2175
2520
  config.programId,
2176
2521
  ({ logs, err, signature }, context) => {
@@ -2179,12 +2524,13 @@ function subscribeToEvents(connection, config, onEvent, opts = {}) {
2179
2524
  return;
2180
2525
  }
2181
2526
  try {
2182
- for (const event of parser.parseLogs(logs)) {
2183
- onEvent(
2184
- { name: event.name, data: event.data },
2185
- context.slot,
2186
- signature
2187
- );
2527
+ for (const log of logs) {
2528
+ if (!log.startsWith(PROGRAM_DATA_PREFIX)) continue;
2529
+ const b64 = log.slice(PROGRAM_DATA_PREFIX.length);
2530
+ const event = tryDecodeEvent(coder, b64);
2531
+ if (event) {
2532
+ onEvent(event, context.slot, signature);
2533
+ }
2188
2534
  }
2189
2535
  } catch (e) {
2190
2536
  opts.onError?.(e instanceof Error ? e : new Error(String(e)));
@@ -2236,18 +2582,6 @@ async function buildTransaction(connection, instructions, payer, opts = {}) {
2236
2582
  }).compileToV0Message();
2237
2583
  return new VersionedTransaction(message);
2238
2584
  }
2239
- async function sendTransaction(connection, tx, opts = {}) {
2240
- const sig = await connection.sendTransaction(tx, {
2241
- skipPreflight: opts.skipPreflight ?? false,
2242
- maxRetries: 3
2243
- });
2244
- const latestBlockhash = await connection.getLatestBlockhash("confirmed");
2245
- await connection.confirmTransaction({
2246
- signature: sig,
2247
- ...latestBlockhash
2248
- }, "confirmed");
2249
- return sig;
2250
- }
2251
2585
 
2252
2586
  // src/client.ts
2253
2587
  var HodlClient = class {
@@ -2283,8 +2617,12 @@ var HodlClient = class {
2283
2617
  const ix = await buildClosePositionInstruction({ ...params, connection: this.connection, config: this.config });
2284
2618
  return buildTransaction(this.connection, [ix], params.owner, opts);
2285
2619
  }
2286
- send(tx, opts) {
2287
- return sendTransaction(this.connection, tx, opts);
2620
+ /**
2621
+ * Build a transaction from raw instructions. Fetches a fresh blockhash.
2622
+ * Sign the returned transaction, then send via connection.sendRawTransaction.
2623
+ */
2624
+ buildTransaction(instructions, payer, opts) {
2625
+ return buildTransaction(this.connection, instructions, payer, opts);
2288
2626
  }
2289
2627
  subscribeToEvents(onEvent, opts) {
2290
2628
  return subscribeToEvents(this.connection, this.config, onEvent, opts);
@@ -2296,7 +2634,12 @@ var HodlClient = class {
2296
2634
  return fetchAndParseTransaction(this.connection, signature, this.config);
2297
2635
  }
2298
2636
  };
2637
+ /*! Bundled license information:
2638
+
2639
+ safe-buffer/index.js:
2640
+ (*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> *)
2641
+ */
2299
2642
 
2300
- export { BPS_DENOMINATOR, DECIMALS, DEVNET_CONFIG, HODL_ERRORS, HodlClient, HodlError, LIMITS, MAINNET_CONFIG, PROGRAM_ID, PROTOCOL_AUTHORITY, PROTOCOL_MINT_FEE, SEEDS, TOTAL_SUPPLY, TRADE_FEE_BPS, VEST_DURATION, VIRTUAL_SOL, applySlippage, buildBuyInstruction, buildClaimAccruedInstruction, buildClosePositionInstruction, buildCreateTokenInstruction, buildSellInstruction, buildTransaction, calculateAccruedTokens, calculateBuyAmount, calculatePriceImpact, calculateSellAmount, calculateSolForExactTokens, calculateSpotPrice, calculateTradableVaultedSplit, fetchAndParseTransaction, fetchPoolState, fetchPoolStateByAddress, fetchPosition, getEventAuthorityPDA, getPoolStatePDA, getPositionPDA, getProtocolFeesPDA, getSolVaultPDA, getVaultAuthorityPDA, parseHodlError, parseTransactionEvents, sendTransaction, subscribeToAccrualClaimed, subscribeToEvents, subscribeToPositionClosed, subscribeToTokenCreated, subscribeToTokenPurchased, subscribeToTokenSold, unsubscribeFromEvents };
2643
+ export { BPS_DENOMINATOR, DECIMALS, DEVNET_CONFIG, HODL_ERRORS, HodlClient, HodlError, LIMITS, MAINNET_CONFIG, MIGRATION_SOL_THRESHOLD, PROGRAM_ID, PROTOCOL_AUTHORITY, PROTOCOL_MINT_FEE, SEEDS, TOTAL_SUPPLY, TRADE_FEE_BPS, VEST_DURATION, VIRTUAL_SOL, applySlippage, buildBuyInstruction, buildClaimAccruedInstruction, buildClosePositionInstruction, buildCreateTokenInstruction, buildSellInstruction, buildTransaction, calculateAccruedTokens, calculateBuyAmount, calculateClaimableTokens, calculatePriceImpact, calculateSellAmount, calculateSolForExactTokens, calculateSpotPrice, calculateTradableVaultedSplit, fetchAndParseTransaction, fetchPoolState, fetchPoolStateByAddress, fetchPosition, getEventAuthorityPDA, getPoolStatePDA, getPositionPDA, getProtocolFeesPDA, getSolVaultPDA, getVaultAuthorityPDA, parseHodlError, parseTransactionEvents, subscribeToAccrualClaimed, subscribeToEvents, subscribeToPositionClosed, subscribeToTokenCreated, subscribeToTokenPurchased, subscribeToTokenSold, unsubscribeFromEvents };
2301
2644
  //# sourceMappingURL=index.js.map
2302
2645
  //# sourceMappingURL=index.js.map