@hodlmarkets/sdk 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/accounts.cjs +22 -0
- package/dist/accounts.cjs.map +1 -1
- package/dist/accounts.js +22 -0
- package/dist/accounts.js.map +1 -1
- package/dist/client.cjs +340 -28
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +6 -2
- package/dist/client.d.ts +6 -2
- package/dist/client.js +341 -29
- package/dist/client.js.map +1 -1
- package/dist/constants.cjs +3 -1
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +5 -3
- package/dist/constants.d.ts +5 -3
- package/dist/constants.js +3 -2
- package/dist/constants.js.map +1 -1
- package/dist/events.cjs +333 -14
- package/dist/events.cjs.map +1 -1
- package/dist/events.d.cts +9 -0
- package/dist/events.d.ts +9 -0
- package/dist/events.js +334 -15
- package/dist/events.js.map +1 -1
- package/dist/index.cjs +375 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +375 -32
- package/dist/index.js.map +1 -1
- package/dist/instructions.cjs +22 -0
- package/dist/instructions.cjs.map +1 -1
- package/dist/instructions.js +22 -0
- package/dist/instructions.js.map +1 -1
- package/dist/math.cjs +33 -0
- package/dist/math.cjs.map +1 -1
- package/dist/math.d.cts +14 -4
- package/dist/math.d.ts +14 -4
- package/dist/math.js +33 -1
- package/dist/math.js.map +1 -1
- package/dist/pda.cjs +1 -0
- package/dist/pda.cjs.map +1 -1
- package/dist/pda.js +1 -0
- package/dist/pda.js.map +1 -1
- package/dist/transaction.cjs +0 -13
- package/dist/transaction.cjs.map +1 -1
- package/dist/transaction.d.cts +5 -3
- package/dist/transaction.d.ts +5 -3
- package/dist/transaction.js +1 -13
- package/dist/transaction.js.map +1 -1
- package/dist/types.d.cts +3 -0
- package/dist/types.d.ts +3 -0
- package/package.json +5 -3
package/dist/client.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Connection, PublicKey, VersionedTransaction } from '@solana/web3.js';
|
|
2
2
|
import { SdkConfig, PoolState, Position, BuyParams, SellParams, CreateTokenParams, HodlEvent } from './types.cjs';
|
|
3
|
-
import { TxOptions } from './transaction.cjs';
|
|
3
|
+
import { TxOptions, buildTransaction } from './transaction.cjs';
|
|
4
4
|
import { SubscriptionOptions } from './events.cjs';
|
|
5
5
|
import 'bn.js';
|
|
6
6
|
|
|
@@ -35,7 +35,11 @@ declare class HodlClient {
|
|
|
35
35
|
mint: PublicKey;
|
|
36
36
|
userTokenAccount: PublicKey;
|
|
37
37
|
}, opts?: TxOptions): Promise<VersionedTransaction>;
|
|
38
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Build a transaction from raw instructions. Fetches a fresh blockhash.
|
|
40
|
+
* Sign the returned transaction, then send via connection.sendRawTransaction.
|
|
41
|
+
*/
|
|
42
|
+
buildTransaction(instructions: Parameters<typeof buildTransaction>[1], payer: PublicKey, opts?: TxOptions): Promise<VersionedTransaction>;
|
|
39
43
|
subscribeToEvents(onEvent: (event: HodlEvent, slot: number, signature: string) => void, opts?: SubscriptionOptions): number;
|
|
40
44
|
unsubscribe(subscriptionId: number): Promise<void>;
|
|
41
45
|
fetchAndParseTransaction(signature: string): Promise<HodlEvent[]>;
|
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Connection, PublicKey, VersionedTransaction } from '@solana/web3.js';
|
|
2
2
|
import { SdkConfig, PoolState, Position, BuyParams, SellParams, CreateTokenParams, HodlEvent } from './types.js';
|
|
3
|
-
import { TxOptions } from './transaction.js';
|
|
3
|
+
import { TxOptions, buildTransaction } from './transaction.js';
|
|
4
4
|
import { SubscriptionOptions } from './events.js';
|
|
5
5
|
import 'bn.js';
|
|
6
6
|
|
|
@@ -35,7 +35,11 @@ declare class HodlClient {
|
|
|
35
35
|
mint: PublicKey;
|
|
36
36
|
userTokenAccount: PublicKey;
|
|
37
37
|
}, opts?: TxOptions): Promise<VersionedTransaction>;
|
|
38
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Build a transaction from raw instructions. Fetches a fresh blockhash.
|
|
40
|
+
* Sign the returned transaction, then send via connection.sendRawTransaction.
|
|
41
|
+
*/
|
|
42
|
+
buildTransaction(instructions: Parameters<typeof buildTransaction>[1], payer: PublicKey, opts?: TxOptions): Promise<VersionedTransaction>;
|
|
39
43
|
subscribeToEvents(onEvent: (event: HodlEvent, slot: number, signature: string) => void, opts?: SubscriptionOptions): number;
|
|
40
44
|
unsubscribe(subscriptionId: number): Promise<void>;
|
|
41
45
|
fetchAndParseTransaction(signature: string): Promise<HodlEvent[]>;
|
package/dist/client.js
CHANGED
|
@@ -1,9 +1,240 @@
|
|
|
1
1
|
import { PublicKey, SystemProgram, ComputeBudgetProgram, TransactionMessage, VersionedTransaction, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RENT_PUBKEY } from '@solana/web3.js';
|
|
2
2
|
import BN from 'bn.js';
|
|
3
|
-
import { BorshCoder,
|
|
3
|
+
import { BorshCoder, AnchorProvider, Program, utils } from '@coral-xyz/anchor';
|
|
4
4
|
import { getAssociatedTokenAddressSync, ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
5
5
|
|
|
6
|
-
|
|
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 PROGRAM_ID = new PublicKey("hodLrUfwyK3Z7Td5hdZhyojyznG1rqbHVex11y5s4yG");
|
|
8
239
|
var PROTOCOL_AUTHORITY = new PublicKey("EFAquDGAHjkoPB6TGKVibD3BYhbFXNDjuXKpiBHdYzji");
|
|
9
240
|
var VIRTUAL_SOL = new BN("30000000000");
|
|
@@ -26,6 +257,7 @@ var MAINNET_CONFIG = {
|
|
|
26
257
|
decimals: DECIMALS,
|
|
27
258
|
totalSupply: TOTAL_SUPPLY
|
|
28
259
|
};
|
|
260
|
+
new BN("85000000000");
|
|
29
261
|
function getPoolStatePDA(mint, programId) {
|
|
30
262
|
return PublicKey.findProgramAddressSync([SEEDS.POOL, mint.toBuffer()], programId);
|
|
31
263
|
}
|
|
@@ -1509,6 +1741,27 @@ var hodl_default = {
|
|
|
1509
1741
|
],
|
|
1510
1742
|
type: "u64"
|
|
1511
1743
|
},
|
|
1744
|
+
{
|
|
1745
|
+
name: "migration_complete",
|
|
1746
|
+
docs: [
|
|
1747
|
+
"One-way flag: set to true once vamm_real_sol >= MIGRATION_SOL_THRESHOLD, never reverts"
|
|
1748
|
+
],
|
|
1749
|
+
type: "bool"
|
|
1750
|
+
},
|
|
1751
|
+
{
|
|
1752
|
+
name: "total_fees_sol",
|
|
1753
|
+
docs: [
|
|
1754
|
+
"Cumulative SOL fees collected from buys (lamports)"
|
|
1755
|
+
],
|
|
1756
|
+
type: "u64"
|
|
1757
|
+
},
|
|
1758
|
+
{
|
|
1759
|
+
name: "total_fees_tokens",
|
|
1760
|
+
docs: [
|
|
1761
|
+
"Cumulative token fees collected from sells"
|
|
1762
|
+
],
|
|
1763
|
+
type: "u64"
|
|
1764
|
+
},
|
|
1512
1765
|
{
|
|
1513
1766
|
name: "bump_vault_auth",
|
|
1514
1767
|
docs: [
|
|
@@ -2038,30 +2291,80 @@ async function buildTransaction(connection, instructions, payer, opts = {}) {
|
|
|
2038
2291
|
}).compileToV0Message();
|
|
2039
2292
|
return new VersionedTransaction(message);
|
|
2040
2293
|
}
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2294
|
+
|
|
2295
|
+
// src/events.ts
|
|
2296
|
+
var import_bs58 = __toESM(require_bs58());
|
|
2297
|
+
var PROGRAM_DATA_PREFIX = "Program data: ";
|
|
2298
|
+
function toCamelCase(name) {
|
|
2299
|
+
return name.charAt(0).toLowerCase() + name.slice(1);
|
|
2300
|
+
}
|
|
2301
|
+
function snakeToCamelKeys(obj) {
|
|
2302
|
+
const result = {};
|
|
2303
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
2304
|
+
const camelKey = key.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
2305
|
+
result[camelKey] = value;
|
|
2306
|
+
}
|
|
2307
|
+
return result;
|
|
2308
|
+
}
|
|
2309
|
+
function tryDecodeEvent(coder, data) {
|
|
2310
|
+
try {
|
|
2311
|
+
const event = coder.events.decode(data);
|
|
2312
|
+
if (event) {
|
|
2313
|
+
return {
|
|
2314
|
+
name: toCamelCase(event.name),
|
|
2315
|
+
data: snakeToCamelKeys(event.data)
|
|
2316
|
+
};
|
|
2317
|
+
}
|
|
2318
|
+
} catch {
|
|
2319
|
+
}
|
|
2320
|
+
return null;
|
|
2052
2321
|
}
|
|
2053
2322
|
function parseTransactionEvents(input, config) {
|
|
2054
2323
|
if (!input) return [];
|
|
2055
|
-
const logs = Array.isArray(input) ? input : input.meta?.logMessages ?? [];
|
|
2056
|
-
if (logs.length === 0) return [];
|
|
2057
2324
|
const coder = new BorshCoder(hodl_default);
|
|
2058
|
-
const parser = new EventParser(config.programId, coder);
|
|
2059
2325
|
const events = [];
|
|
2060
|
-
|
|
2061
|
-
for (const
|
|
2062
|
-
|
|
2326
|
+
if (Array.isArray(input)) {
|
|
2327
|
+
for (const log of input) {
|
|
2328
|
+
if (!log.startsWith(PROGRAM_DATA_PREFIX)) continue;
|
|
2329
|
+
const b64 = log.slice(PROGRAM_DATA_PREFIX.length);
|
|
2330
|
+
const event = tryDecodeEvent(coder, b64);
|
|
2331
|
+
if (event) events.push(event);
|
|
2332
|
+
}
|
|
2333
|
+
return events;
|
|
2334
|
+
}
|
|
2335
|
+
const tx = input;
|
|
2336
|
+
const logs = tx.meta?.logMessages ?? [];
|
|
2337
|
+
for (const log of logs) {
|
|
2338
|
+
if (!log.startsWith(PROGRAM_DATA_PREFIX)) continue;
|
|
2339
|
+
const b64 = log.slice(PROGRAM_DATA_PREFIX.length);
|
|
2340
|
+
const event = tryDecodeEvent(coder, b64);
|
|
2341
|
+
if (event) events.push(event);
|
|
2342
|
+
}
|
|
2343
|
+
const programId = config.programId.toBase58();
|
|
2344
|
+
const staticKeys = tx.transaction.message.staticAccountKeys;
|
|
2345
|
+
const loadedWritable = tx.meta?.loadedAddresses?.writable ?? [];
|
|
2346
|
+
const loadedReadonly = tx.meta?.loadedAddresses?.readonly ?? [];
|
|
2347
|
+
const allKeys = [...staticKeys, ...loadedWritable, ...loadedReadonly];
|
|
2348
|
+
for (const inner of tx.meta?.innerInstructions ?? []) {
|
|
2349
|
+
for (const ix of inner.instructions) {
|
|
2350
|
+
const ixProgramKey = allKeys[ix.programIdIndex];
|
|
2351
|
+
if (!ixProgramKey || ixProgramKey.toBase58() !== programId) continue;
|
|
2352
|
+
try {
|
|
2353
|
+
const bytes = import_bs58.default.decode(ix.data);
|
|
2354
|
+
const b64Full = utils.bytes.base64.encode(Buffer.from(bytes));
|
|
2355
|
+
const eventFull = tryDecodeEvent(coder, b64Full);
|
|
2356
|
+
if (eventFull) {
|
|
2357
|
+
events.push(eventFull);
|
|
2358
|
+
continue;
|
|
2359
|
+
}
|
|
2360
|
+
if (bytes.length > 8) {
|
|
2361
|
+
const b64Skip = utils.bytes.base64.encode(Buffer.from(bytes.slice(8)));
|
|
2362
|
+
const eventSkip = tryDecodeEvent(coder, b64Skip);
|
|
2363
|
+
if (eventSkip) events.push(eventSkip);
|
|
2364
|
+
}
|
|
2365
|
+
} catch {
|
|
2366
|
+
}
|
|
2063
2367
|
}
|
|
2064
|
-
} catch {
|
|
2065
2368
|
}
|
|
2066
2369
|
return events;
|
|
2067
2370
|
}
|
|
@@ -2075,7 +2378,6 @@ async function fetchAndParseTransaction(connection, signature, config) {
|
|
|
2075
2378
|
function subscribeToEvents(connection, config, onEvent, opts = {}) {
|
|
2076
2379
|
const commitment = opts.commitment ?? "confirmed";
|
|
2077
2380
|
const coder = new BorshCoder(hodl_default);
|
|
2078
|
-
const parser = new EventParser(config.programId, coder);
|
|
2079
2381
|
return connection.onLogs(
|
|
2080
2382
|
config.programId,
|
|
2081
2383
|
({ logs, err, signature }, context) => {
|
|
@@ -2084,12 +2386,13 @@ function subscribeToEvents(connection, config, onEvent, opts = {}) {
|
|
|
2084
2386
|
return;
|
|
2085
2387
|
}
|
|
2086
2388
|
try {
|
|
2087
|
-
for (const
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2389
|
+
for (const log of logs) {
|
|
2390
|
+
if (!log.startsWith(PROGRAM_DATA_PREFIX)) continue;
|
|
2391
|
+
const b64 = log.slice(PROGRAM_DATA_PREFIX.length);
|
|
2392
|
+
const event = tryDecodeEvent(coder, b64);
|
|
2393
|
+
if (event) {
|
|
2394
|
+
onEvent(event, context.slot, signature);
|
|
2395
|
+
}
|
|
2093
2396
|
}
|
|
2094
2397
|
} catch (e) {
|
|
2095
2398
|
opts.onError?.(e instanceof Error ? e : new Error(String(e)));
|
|
@@ -2136,8 +2439,12 @@ var HodlClient = class {
|
|
|
2136
2439
|
const ix = await buildClosePositionInstruction({ ...params, connection: this.connection, config: this.config });
|
|
2137
2440
|
return buildTransaction(this.connection, [ix], params.owner, opts);
|
|
2138
2441
|
}
|
|
2139
|
-
|
|
2140
|
-
|
|
2442
|
+
/**
|
|
2443
|
+
* Build a transaction from raw instructions. Fetches a fresh blockhash.
|
|
2444
|
+
* Sign the returned transaction, then send via connection.sendRawTransaction.
|
|
2445
|
+
*/
|
|
2446
|
+
buildTransaction(instructions, payer, opts) {
|
|
2447
|
+
return buildTransaction(this.connection, instructions, payer, opts);
|
|
2141
2448
|
}
|
|
2142
2449
|
subscribeToEvents(onEvent, opts) {
|
|
2143
2450
|
return subscribeToEvents(this.connection, this.config, onEvent, opts);
|
|
@@ -2149,6 +2456,11 @@ var HodlClient = class {
|
|
|
2149
2456
|
return fetchAndParseTransaction(this.connection, signature, this.config);
|
|
2150
2457
|
}
|
|
2151
2458
|
};
|
|
2459
|
+
/*! Bundled license information:
|
|
2460
|
+
|
|
2461
|
+
safe-buffer/index.js:
|
|
2462
|
+
(*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> *)
|
|
2463
|
+
*/
|
|
2152
2464
|
|
|
2153
2465
|
export { HodlClient };
|
|
2154
2466
|
//# sourceMappingURL=client.js.map
|