@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/client.cjs CHANGED
@@ -9,7 +9,238 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
9
 
10
10
  var BN__default = /*#__PURE__*/_interopDefault(BN);
11
11
 
12
- // src/constants.ts
12
+ var __create = Object.create;
13
+ var __defProp = Object.defineProperty;
14
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
15
+ var __getOwnPropNames = Object.getOwnPropertyNames;
16
+ var __getProtoOf = Object.getPrototypeOf;
17
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
18
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
19
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
20
+ }) : x)(function(x) {
21
+ if (typeof require !== "undefined") return require.apply(this, arguments);
22
+ throw Error('Dynamic require of "' + x + '" is not supported');
23
+ });
24
+ var __commonJS = (cb, mod) => function __require2() {
25
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
26
+ };
27
+ var __copyProps = (to, from, except, desc) => {
28
+ if (from && typeof from === "object" || typeof from === "function") {
29
+ for (let key of __getOwnPropNames(from))
30
+ if (!__hasOwnProp.call(to, key) && key !== except)
31
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
32
+ }
33
+ return to;
34
+ };
35
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
36
+ // If the importer is in node compatibility mode or this is not an ESM
37
+ // file that has been converted to a CommonJS file using a Babel-
38
+ // compatible transform (i.e. "__esModule" has not been set), then set
39
+ // "default" to the CommonJS "module.exports" for node compatibility.
40
+ __defProp(target, "default", { value: mod, enumerable: true }) ,
41
+ mod
42
+ ));
43
+
44
+ // node_modules/safe-buffer/index.js
45
+ var require_safe_buffer = __commonJS({
46
+ "node_modules/safe-buffer/index.js"(exports$1, module) {
47
+ var buffer = __require("buffer");
48
+ var Buffer2 = buffer.Buffer;
49
+ function copyProps(src, dst) {
50
+ for (var key in src) {
51
+ dst[key] = src[key];
52
+ }
53
+ }
54
+ if (Buffer2.from && Buffer2.alloc && Buffer2.allocUnsafe && Buffer2.allocUnsafeSlow) {
55
+ module.exports = buffer;
56
+ } else {
57
+ copyProps(buffer, exports$1);
58
+ exports$1.Buffer = SafeBuffer;
59
+ }
60
+ function SafeBuffer(arg, encodingOrOffset, length) {
61
+ return Buffer2(arg, encodingOrOffset, length);
62
+ }
63
+ SafeBuffer.prototype = Object.create(Buffer2.prototype);
64
+ copyProps(Buffer2, SafeBuffer);
65
+ SafeBuffer.from = function(arg, encodingOrOffset, length) {
66
+ if (typeof arg === "number") {
67
+ throw new TypeError("Argument must not be a number");
68
+ }
69
+ return Buffer2(arg, encodingOrOffset, length);
70
+ };
71
+ SafeBuffer.alloc = function(size, fill, encoding) {
72
+ if (typeof size !== "number") {
73
+ throw new TypeError("Argument must be a number");
74
+ }
75
+ var buf = Buffer2(size);
76
+ if (fill !== void 0) {
77
+ if (typeof encoding === "string") {
78
+ buf.fill(fill, encoding);
79
+ } else {
80
+ buf.fill(fill);
81
+ }
82
+ } else {
83
+ buf.fill(0);
84
+ }
85
+ return buf;
86
+ };
87
+ SafeBuffer.allocUnsafe = function(size) {
88
+ if (typeof size !== "number") {
89
+ throw new TypeError("Argument must be a number");
90
+ }
91
+ return Buffer2(size);
92
+ };
93
+ SafeBuffer.allocUnsafeSlow = function(size) {
94
+ if (typeof size !== "number") {
95
+ throw new TypeError("Argument must be a number");
96
+ }
97
+ return buffer.SlowBuffer(size);
98
+ };
99
+ }
100
+ });
101
+
102
+ // node_modules/base-x/src/index.js
103
+ var require_src = __commonJS({
104
+ "node_modules/base-x/src/index.js"(exports$1, module) {
105
+ var _Buffer = require_safe_buffer().Buffer;
106
+ function base(ALPHABET) {
107
+ if (ALPHABET.length >= 255) {
108
+ throw new TypeError("Alphabet too long");
109
+ }
110
+ var BASE_MAP = new Uint8Array(256);
111
+ for (var j = 0; j < BASE_MAP.length; j++) {
112
+ BASE_MAP[j] = 255;
113
+ }
114
+ for (var i = 0; i < ALPHABET.length; i++) {
115
+ var x = ALPHABET.charAt(i);
116
+ var xc = x.charCodeAt(0);
117
+ if (BASE_MAP[xc] !== 255) {
118
+ throw new TypeError(x + " is ambiguous");
119
+ }
120
+ BASE_MAP[xc] = i;
121
+ }
122
+ var BASE = ALPHABET.length;
123
+ var LEADER = ALPHABET.charAt(0);
124
+ var FACTOR = Math.log(BASE) / Math.log(256);
125
+ var iFACTOR = Math.log(256) / Math.log(BASE);
126
+ function encode(source) {
127
+ if (Array.isArray(source) || source instanceof Uint8Array) {
128
+ source = _Buffer.from(source);
129
+ }
130
+ if (!_Buffer.isBuffer(source)) {
131
+ throw new TypeError("Expected Buffer");
132
+ }
133
+ if (source.length === 0) {
134
+ return "";
135
+ }
136
+ var zeroes = 0;
137
+ var length = 0;
138
+ var pbegin = 0;
139
+ var pend = source.length;
140
+ while (pbegin !== pend && source[pbegin] === 0) {
141
+ pbegin++;
142
+ zeroes++;
143
+ }
144
+ var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
145
+ var b58 = new Uint8Array(size);
146
+ while (pbegin !== pend) {
147
+ var carry = source[pbegin];
148
+ var i2 = 0;
149
+ for (var it1 = size - 1; (carry !== 0 || i2 < length) && it1 !== -1; it1--, i2++) {
150
+ carry += 256 * b58[it1] >>> 0;
151
+ b58[it1] = carry % BASE >>> 0;
152
+ carry = carry / BASE >>> 0;
153
+ }
154
+ if (carry !== 0) {
155
+ throw new Error("Non-zero carry");
156
+ }
157
+ length = i2;
158
+ pbegin++;
159
+ }
160
+ var it2 = size - length;
161
+ while (it2 !== size && b58[it2] === 0) {
162
+ it2++;
163
+ }
164
+ var str = LEADER.repeat(zeroes);
165
+ for (; it2 < size; ++it2) {
166
+ str += ALPHABET.charAt(b58[it2]);
167
+ }
168
+ return str;
169
+ }
170
+ function decodeUnsafe(source) {
171
+ if (typeof source !== "string") {
172
+ throw new TypeError("Expected String");
173
+ }
174
+ if (source.length === 0) {
175
+ return _Buffer.alloc(0);
176
+ }
177
+ var psz = 0;
178
+ var zeroes = 0;
179
+ var length = 0;
180
+ while (source[psz] === LEADER) {
181
+ zeroes++;
182
+ psz++;
183
+ }
184
+ var size = (source.length - psz) * FACTOR + 1 >>> 0;
185
+ var b256 = new Uint8Array(size);
186
+ while (psz < source.length) {
187
+ var charCode = source.charCodeAt(psz);
188
+ if (charCode > 255) {
189
+ return;
190
+ }
191
+ var carry = BASE_MAP[charCode];
192
+ if (carry === 255) {
193
+ return;
194
+ }
195
+ var i2 = 0;
196
+ for (var it3 = size - 1; (carry !== 0 || i2 < length) && it3 !== -1; it3--, i2++) {
197
+ carry += BASE * b256[it3] >>> 0;
198
+ b256[it3] = carry % 256 >>> 0;
199
+ carry = carry / 256 >>> 0;
200
+ }
201
+ if (carry !== 0) {
202
+ throw new Error("Non-zero carry");
203
+ }
204
+ length = i2;
205
+ psz++;
206
+ }
207
+ var it4 = size - length;
208
+ while (it4 !== size && b256[it4] === 0) {
209
+ it4++;
210
+ }
211
+ var vch = _Buffer.allocUnsafe(zeroes + (size - it4));
212
+ vch.fill(0, 0, zeroes);
213
+ var j2 = zeroes;
214
+ while (it4 !== size) {
215
+ vch[j2++] = b256[it4++];
216
+ }
217
+ return vch;
218
+ }
219
+ function decode(string) {
220
+ var buffer = decodeUnsafe(string);
221
+ if (buffer) {
222
+ return buffer;
223
+ }
224
+ throw new Error("Non-base" + BASE + " character");
225
+ }
226
+ return {
227
+ encode,
228
+ decodeUnsafe,
229
+ decode
230
+ };
231
+ }
232
+ module.exports = base;
233
+ }
234
+ });
235
+
236
+ // node_modules/bs58/index.js
237
+ var require_bs58 = __commonJS({
238
+ "node_modules/bs58/index.js"(exports$1, module) {
239
+ var basex = require_src();
240
+ var ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
241
+ module.exports = basex(ALPHABET);
242
+ }
243
+ });
13
244
  var PROGRAM_ID = new web3_js.PublicKey("hodLrUfwyK3Z7Td5hdZhyojyznG1rqbHVex11y5s4yG");
14
245
  var PROTOCOL_AUTHORITY = new web3_js.PublicKey("EFAquDGAHjkoPB6TGKVibD3BYhbFXNDjuXKpiBHdYzji");
15
246
  var VIRTUAL_SOL = new BN__default.default("30000000000");
@@ -32,6 +263,7 @@ var MAINNET_CONFIG = {
32
263
  decimals: DECIMALS,
33
264
  totalSupply: TOTAL_SUPPLY
34
265
  };
266
+ new BN__default.default("85000000000");
35
267
  function getPoolStatePDA(mint, programId) {
36
268
  return web3_js.PublicKey.findProgramAddressSync([SEEDS.POOL, mint.toBuffer()], programId);
37
269
  }
@@ -1515,6 +1747,27 @@ var hodl_default = {
1515
1747
  ],
1516
1748
  type: "u64"
1517
1749
  },
1750
+ {
1751
+ name: "migration_complete",
1752
+ docs: [
1753
+ "One-way flag: set to true once vamm_real_sol >= MIGRATION_SOL_THRESHOLD, never reverts"
1754
+ ],
1755
+ type: "bool"
1756
+ },
1757
+ {
1758
+ name: "total_fees_sol",
1759
+ docs: [
1760
+ "Cumulative SOL fees collected from buys (lamports)"
1761
+ ],
1762
+ type: "u64"
1763
+ },
1764
+ {
1765
+ name: "total_fees_tokens",
1766
+ docs: [
1767
+ "Cumulative token fees collected from sells"
1768
+ ],
1769
+ type: "u64"
1770
+ },
1518
1771
  {
1519
1772
  name: "bump_vault_auth",
1520
1773
  docs: [
@@ -2044,30 +2297,80 @@ async function buildTransaction(connection, instructions, payer, opts = {}) {
2044
2297
  }).compileToV0Message();
2045
2298
  return new web3_js.VersionedTransaction(message);
2046
2299
  }
2047
- async function sendTransaction(connection, tx, opts = {}) {
2048
- const sig = await connection.sendTransaction(tx, {
2049
- skipPreflight: opts.skipPreflight ?? false,
2050
- maxRetries: 3
2051
- });
2052
- const latestBlockhash = await connection.getLatestBlockhash("confirmed");
2053
- await connection.confirmTransaction({
2054
- signature: sig,
2055
- ...latestBlockhash
2056
- }, "confirmed");
2057
- return sig;
2300
+
2301
+ // src/events.ts
2302
+ var import_bs58 = __toESM(require_bs58());
2303
+ var PROGRAM_DATA_PREFIX = "Program data: ";
2304
+ function toCamelCase(name) {
2305
+ return name.charAt(0).toLowerCase() + name.slice(1);
2306
+ }
2307
+ function snakeToCamelKeys(obj) {
2308
+ const result = {};
2309
+ for (const [key, value] of Object.entries(obj)) {
2310
+ const camelKey = key.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
2311
+ result[camelKey] = value;
2312
+ }
2313
+ return result;
2314
+ }
2315
+ function tryDecodeEvent(coder, data) {
2316
+ try {
2317
+ const event = coder.events.decode(data);
2318
+ if (event) {
2319
+ return {
2320
+ name: toCamelCase(event.name),
2321
+ data: snakeToCamelKeys(event.data)
2322
+ };
2323
+ }
2324
+ } catch {
2325
+ }
2326
+ return null;
2058
2327
  }
2059
2328
  function parseTransactionEvents(input, config) {
2060
2329
  if (!input) return [];
2061
- const logs = Array.isArray(input) ? input : input.meta?.logMessages ?? [];
2062
- if (logs.length === 0) return [];
2063
2330
  const coder = new anchor.BorshCoder(hodl_default);
2064
- const parser = new anchor.EventParser(config.programId, coder);
2065
2331
  const events = [];
2066
- try {
2067
- for (const event of parser.parseLogs(logs)) {
2068
- events.push({ name: event.name, data: event.data });
2332
+ if (Array.isArray(input)) {
2333
+ for (const log of input) {
2334
+ if (!log.startsWith(PROGRAM_DATA_PREFIX)) continue;
2335
+ const b64 = log.slice(PROGRAM_DATA_PREFIX.length);
2336
+ const event = tryDecodeEvent(coder, b64);
2337
+ if (event) events.push(event);
2338
+ }
2339
+ return events;
2340
+ }
2341
+ const tx = input;
2342
+ const logs = tx.meta?.logMessages ?? [];
2343
+ for (const log of logs) {
2344
+ if (!log.startsWith(PROGRAM_DATA_PREFIX)) continue;
2345
+ const b64 = log.slice(PROGRAM_DATA_PREFIX.length);
2346
+ const event = tryDecodeEvent(coder, b64);
2347
+ if (event) events.push(event);
2348
+ }
2349
+ const programId = config.programId.toBase58();
2350
+ const staticKeys = tx.transaction.message.staticAccountKeys;
2351
+ const loadedWritable = tx.meta?.loadedAddresses?.writable ?? [];
2352
+ const loadedReadonly = tx.meta?.loadedAddresses?.readonly ?? [];
2353
+ const allKeys = [...staticKeys, ...loadedWritable, ...loadedReadonly];
2354
+ for (const inner of tx.meta?.innerInstructions ?? []) {
2355
+ for (const ix of inner.instructions) {
2356
+ const ixProgramKey = allKeys[ix.programIdIndex];
2357
+ if (!ixProgramKey || ixProgramKey.toBase58() !== programId) continue;
2358
+ try {
2359
+ const bytes = import_bs58.default.decode(ix.data);
2360
+ const b64Full = anchor.utils.bytes.base64.encode(Buffer.from(bytes));
2361
+ const eventFull = tryDecodeEvent(coder, b64Full);
2362
+ if (eventFull) {
2363
+ events.push(eventFull);
2364
+ continue;
2365
+ }
2366
+ if (bytes.length > 8) {
2367
+ const b64Skip = anchor.utils.bytes.base64.encode(Buffer.from(bytes.slice(8)));
2368
+ const eventSkip = tryDecodeEvent(coder, b64Skip);
2369
+ if (eventSkip) events.push(eventSkip);
2370
+ }
2371
+ } catch {
2372
+ }
2069
2373
  }
2070
- } catch {
2071
2374
  }
2072
2375
  return events;
2073
2376
  }
@@ -2081,7 +2384,6 @@ async function fetchAndParseTransaction(connection, signature, config) {
2081
2384
  function subscribeToEvents(connection, config, onEvent, opts = {}) {
2082
2385
  const commitment = opts.commitment ?? "confirmed";
2083
2386
  const coder = new anchor.BorshCoder(hodl_default);
2084
- const parser = new anchor.EventParser(config.programId, coder);
2085
2387
  return connection.onLogs(
2086
2388
  config.programId,
2087
2389
  ({ logs, err, signature }, context) => {
@@ -2090,12 +2392,13 @@ function subscribeToEvents(connection, config, onEvent, opts = {}) {
2090
2392
  return;
2091
2393
  }
2092
2394
  try {
2093
- for (const event of parser.parseLogs(logs)) {
2094
- onEvent(
2095
- { name: event.name, data: event.data },
2096
- context.slot,
2097
- signature
2098
- );
2395
+ for (const log of logs) {
2396
+ if (!log.startsWith(PROGRAM_DATA_PREFIX)) continue;
2397
+ const b64 = log.slice(PROGRAM_DATA_PREFIX.length);
2398
+ const event = tryDecodeEvent(coder, b64);
2399
+ if (event) {
2400
+ onEvent(event, context.slot, signature);
2401
+ }
2099
2402
  }
2100
2403
  } catch (e) {
2101
2404
  opts.onError?.(e instanceof Error ? e : new Error(String(e)));
@@ -2142,8 +2445,12 @@ var HodlClient = class {
2142
2445
  const ix = await buildClosePositionInstruction({ ...params, connection: this.connection, config: this.config });
2143
2446
  return buildTransaction(this.connection, [ix], params.owner, opts);
2144
2447
  }
2145
- send(tx, opts) {
2146
- return sendTransaction(this.connection, tx, opts);
2448
+ /**
2449
+ * Build a transaction from raw instructions. Fetches a fresh blockhash.
2450
+ * Sign the returned transaction, then send via connection.sendRawTransaction.
2451
+ */
2452
+ buildTransaction(instructions, payer, opts) {
2453
+ return buildTransaction(this.connection, instructions, payer, opts);
2147
2454
  }
2148
2455
  subscribeToEvents(onEvent, opts) {
2149
2456
  return subscribeToEvents(this.connection, this.config, onEvent, opts);
@@ -2155,6 +2462,11 @@ var HodlClient = class {
2155
2462
  return fetchAndParseTransaction(this.connection, signature, this.config);
2156
2463
  }
2157
2464
  };
2465
+ /*! Bundled license information:
2466
+
2467
+ safe-buffer/index.js:
2468
+ (*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> *)
2469
+ */
2158
2470
 
2159
2471
  exports.HodlClient = HodlClient;
2160
2472
  //# sourceMappingURL=client.cjs.map