solforge 0.2.8 → 0.2.9
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/package.json +1 -1
- package/scripts/decode-b58.ts +5 -1
- package/server/lib/instruction-parser.ts +302 -238
- package/server/lib/parsers/spl-associated-token-account.ts +36 -30
- package/server/lib/parsers/spl-token.ts +285 -142
- package/server/methods/account/request-airdrop.ts +121 -105
- package/server/methods/admin/mint-to.ts +29 -14
- package/server/methods/transaction/get-transaction.ts +390 -326
- package/server/methods/transaction/inner-instructions.test.ts +91 -50
- package/server/methods/transaction/send-transaction.ts +269 -236
- package/server/rpc-server.ts +101 -104
- package/server/types.ts +56 -56
- package/src/db/schema/transactions.ts +29 -29
- package/src/db/schema/tx-account-states.ts +16 -14
- package/src/db/tx-store.ts +97 -99
- package/src/migrations-bundled.ts +4 -4
package/package.json
CHANGED
package/scripts/decode-b58.ts
CHANGED
|
@@ -3,4 +3,8 @@ import { decodeBase58 } from "../server/lib/base58";
|
|
|
3
3
|
const s = process.argv[2] || "84eT";
|
|
4
4
|
const bytes = decodeBase58(s);
|
|
5
5
|
console.log(bytes);
|
|
6
|
-
console.log(
|
|
6
|
+
console.log(
|
|
7
|
+
Array.from(bytes)
|
|
8
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
9
|
+
.join(" "),
|
|
10
|
+
);
|
|
@@ -1,264 +1,328 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
AddressLookupTableInstruction,
|
|
3
|
+
ComputeBudgetInstruction,
|
|
4
|
+
PublicKey,
|
|
5
|
+
StakeInstruction,
|
|
6
|
+
SystemInstruction,
|
|
7
|
+
SystemProgram,
|
|
8
|
+
TransactionInstruction,
|
|
9
|
+
VoteInstruction,
|
|
10
10
|
} from "@solana/web3.js";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
TOKEN_PROGRAM_ID,
|
|
13
|
+
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
14
|
+
TOKEN_2022_PROGRAM_ID,
|
|
15
|
+
} from "@solana/spl-token";
|
|
12
16
|
import { tryParseSplToken } from "./parsers/spl-token";
|
|
13
17
|
import { tryParseAta } from "./parsers/spl-associated-token-account";
|
|
14
18
|
import { decodeBase58 as _decodeBase58 } from "./base58";
|
|
15
19
|
|
|
16
20
|
export type ParsedInstruction =
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
| {
|
|
22
|
+
program: string;
|
|
23
|
+
programId: string;
|
|
24
|
+
parsed: { type: string; info: unknown };
|
|
25
|
+
}
|
|
26
|
+
| { programId: string; accounts: string[]; data: string };
|
|
19
27
|
|
|
20
28
|
function makeIx(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
programId: string,
|
|
30
|
+
accountKeys: string[],
|
|
31
|
+
accounts: number[],
|
|
32
|
+
dataBase58: string,
|
|
25
33
|
): TransactionInstruction {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
const keys = accounts.map((i) => ({
|
|
35
|
+
pubkey: new PublicKey(accountKeys[i] || SystemProgram.programId),
|
|
36
|
+
isSigner: false,
|
|
37
|
+
isWritable: false,
|
|
38
|
+
}));
|
|
39
|
+
const data = Buffer.from(_decodeBase58(dataBase58));
|
|
40
|
+
return new TransactionInstruction({
|
|
41
|
+
programId: new PublicKey(programId),
|
|
42
|
+
keys,
|
|
43
|
+
data,
|
|
44
|
+
});
|
|
33
45
|
}
|
|
34
46
|
|
|
35
|
-
function ok(
|
|
36
|
-
|
|
47
|
+
function ok(
|
|
48
|
+
program: string,
|
|
49
|
+
programId: string,
|
|
50
|
+
type: string,
|
|
51
|
+
info: unknown,
|
|
52
|
+
): ParsedInstruction {
|
|
53
|
+
return { program, programId, parsed: { type, info } };
|
|
37
54
|
}
|
|
38
55
|
|
|
39
56
|
export function parseInstruction(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
57
|
+
programId: string,
|
|
58
|
+
accounts: number[],
|
|
59
|
+
dataBase58: string,
|
|
60
|
+
accountKeys: string[],
|
|
61
|
+
tokenBalanceHints?: Array<{ mint: string; decimals: number }>,
|
|
44
62
|
): ParsedInstruction {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
63
|
+
try {
|
|
64
|
+
const pid = new PublicKey(programId);
|
|
65
|
+
const ix = makeIx(programId, accountKeys, accounts, dataBase58);
|
|
48
66
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
67
|
+
// SPL Token (legacy) and Token-2022
|
|
68
|
+
if (pid.equals(TOKEN_PROGRAM_ID) || pid.equals(TOKEN_2022_PROGRAM_ID)) {
|
|
69
|
+
const parsed = tryParseSplToken(
|
|
70
|
+
ix,
|
|
71
|
+
programId,
|
|
72
|
+
accountKeys,
|
|
73
|
+
dataBase58,
|
|
74
|
+
tokenBalanceHints,
|
|
75
|
+
);
|
|
76
|
+
if (parsed) return parsed;
|
|
77
|
+
}
|
|
54
78
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
79
|
+
// Associated Token Account
|
|
80
|
+
if (pid.equals(ASSOCIATED_TOKEN_PROGRAM_ID)) {
|
|
81
|
+
const parsed = tryParseAta(ix, programId);
|
|
82
|
+
if (parsed) return parsed;
|
|
83
|
+
}
|
|
60
84
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
85
|
+
// System Program
|
|
86
|
+
if (pid.equals(SystemProgram.programId)) {
|
|
87
|
+
try {
|
|
88
|
+
const t = SystemInstruction.decodeInstructionType(ix);
|
|
89
|
+
switch (t) {
|
|
90
|
+
case "Create": {
|
|
91
|
+
try {
|
|
92
|
+
const p = SystemInstruction.decodeCreateAccount(ix);
|
|
93
|
+
const from = p.fromPubkey.toBase58();
|
|
94
|
+
const newAcc = p.newAccountPubkey.toBase58();
|
|
95
|
+
const owner = p.programId.toBase58();
|
|
96
|
+
return ok("system", programId, "createAccount", {
|
|
97
|
+
// Explorer-compatible field names
|
|
98
|
+
source: from,
|
|
99
|
+
newAccount: newAcc,
|
|
100
|
+
owner,
|
|
101
|
+
lamports: Number(p.lamports),
|
|
102
|
+
space: Number(p.space),
|
|
103
|
+
// Keep legacy aliases too
|
|
104
|
+
fromPubkey: from,
|
|
105
|
+
newAccountPubkey: newAcc,
|
|
106
|
+
programId: owner,
|
|
107
|
+
});
|
|
108
|
+
} catch {
|
|
109
|
+
return ok("system", programId, "createAccount", {});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
case "Transfer": {
|
|
113
|
+
try {
|
|
114
|
+
const p = SystemInstruction.decodeTransfer(ix);
|
|
115
|
+
return ok("system", programId, "transfer", {
|
|
116
|
+
source: p.fromPubkey.toBase58(),
|
|
117
|
+
destination: p.toPubkey.toBase58(),
|
|
118
|
+
lamports: Number(p.lamports),
|
|
119
|
+
});
|
|
120
|
+
} catch {
|
|
121
|
+
return ok("system", programId, "transfer", {});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
case "TransferWithSeed": {
|
|
125
|
+
try {
|
|
126
|
+
const p = SystemInstruction.decodeTransferWithSeed(ix);
|
|
127
|
+
return ok("system", programId, "transferWithSeed", {
|
|
128
|
+
fromPubkey: p.fromPubkey.toBase58(),
|
|
129
|
+
basePubkey: p.basePubkey.toBase58(),
|
|
130
|
+
toPubkey: p.toPubkey.toBase58(),
|
|
131
|
+
lamports: Number(p.lamports),
|
|
132
|
+
seed: p.seed,
|
|
133
|
+
programId: p.programId.toBase58(),
|
|
134
|
+
});
|
|
135
|
+
} catch {
|
|
136
|
+
return ok("system", programId, "transferWithSeed", {});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
case "Allocate": {
|
|
140
|
+
try {
|
|
141
|
+
const p = SystemInstruction.decodeAllocate(ix);
|
|
142
|
+
return ok("system", programId, "allocate", {
|
|
143
|
+
accountPubkey: p.accountPubkey.toBase58(),
|
|
144
|
+
space: Number(p.space),
|
|
145
|
+
});
|
|
146
|
+
} catch {
|
|
147
|
+
return ok("system", programId, "allocate", {});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
case "AllocateWithSeed": {
|
|
151
|
+
try {
|
|
152
|
+
const p = SystemInstruction.decodeAllocateWithSeed(ix);
|
|
153
|
+
return ok("system", programId, "allocateWithSeed", {
|
|
154
|
+
accountPubkey: p.accountPubkey.toBase58(),
|
|
155
|
+
basePubkey: p.basePubkey.toBase58(),
|
|
156
|
+
seed: p.seed,
|
|
157
|
+
space: Number(p.space),
|
|
158
|
+
programId: p.programId.toBase58(),
|
|
159
|
+
});
|
|
160
|
+
} catch {
|
|
161
|
+
return ok("system", programId, "allocateWithSeed", {});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
case "Assign": {
|
|
165
|
+
try {
|
|
166
|
+
const p = SystemInstruction.decodeAssign(ix);
|
|
167
|
+
return ok("system", programId, "assign", {
|
|
168
|
+
accountPubkey: p.accountPubkey.toBase58(),
|
|
169
|
+
programId: p.programId.toBase58(),
|
|
170
|
+
});
|
|
171
|
+
} catch {
|
|
172
|
+
return ok("system", programId, "assign", {});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
case "AssignWithSeed": {
|
|
176
|
+
try {
|
|
177
|
+
const p = SystemInstruction.decodeAssignWithSeed(ix);
|
|
178
|
+
return ok("system", programId, "assignWithSeed", {
|
|
179
|
+
accountPubkey: p.accountPubkey.toBase58(),
|
|
180
|
+
basePubkey: p.basePubkey.toBase58(),
|
|
181
|
+
seed: p.seed,
|
|
182
|
+
programId: p.programId.toBase58(),
|
|
183
|
+
});
|
|
184
|
+
} catch {
|
|
185
|
+
return ok("system", programId, "assignWithSeed", {});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
case "InitializeNonceAccount":
|
|
189
|
+
case "AdvanceNonceAccount":
|
|
190
|
+
case "WithdrawNonceAccount":
|
|
191
|
+
case "AuthorizeNonceAccount":
|
|
192
|
+
case "CreateWithSeed":
|
|
193
|
+
case "UpgradeNonceAccount": {
|
|
194
|
+
return ok("system", programId, t, {});
|
|
195
|
+
}
|
|
196
|
+
default:
|
|
197
|
+
return ok("system", programId, t, {});
|
|
198
|
+
}
|
|
199
|
+
} catch {
|
|
200
|
+
// If we cannot even decode the instruction type, fallthrough to raw
|
|
201
|
+
}
|
|
202
|
+
}
|
|
148
203
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
204
|
+
// Compute Budget
|
|
205
|
+
try {
|
|
206
|
+
const t = ComputeBudgetInstruction.decodeInstructionType(ix);
|
|
207
|
+
switch (t) {
|
|
208
|
+
case "SetComputeUnitLimit": {
|
|
209
|
+
const p = ComputeBudgetInstruction.decodeSetComputeUnitLimit(ix);
|
|
210
|
+
return ok("computeBudget", programId, "setComputeUnitLimit", {
|
|
211
|
+
units: Number(p.units),
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
case "SetComputeUnitPrice": {
|
|
215
|
+
const p = ComputeBudgetInstruction.decodeSetComputeUnitPrice(ix);
|
|
216
|
+
return ok("computeBudget", programId, "setComputeUnitPrice", {
|
|
217
|
+
microLamports: Number(p.microLamports),
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
case "RequestHeapFrame": {
|
|
221
|
+
const p = ComputeBudgetInstruction.decodeRequestHeapFrame(ix);
|
|
222
|
+
return ok("computeBudget", programId, "requestHeapFrame", {
|
|
223
|
+
bytes: Number(p.bytes),
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
case "RequestUnits": {
|
|
227
|
+
const p = ComputeBudgetInstruction.decodeRequestUnits(ix);
|
|
228
|
+
return ok("computeBudget", programId, "requestUnits", {
|
|
229
|
+
units: Number(p.units),
|
|
230
|
+
additionalFee: Number(p.additionalFee),
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
} catch {}
|
|
171
235
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
236
|
+
// Stake
|
|
237
|
+
try {
|
|
238
|
+
const t = StakeInstruction.decodeInstructionType(ix);
|
|
239
|
+
switch (t) {
|
|
240
|
+
case "Initialize":
|
|
241
|
+
return ok("stake", programId, "initialize", {});
|
|
242
|
+
case "Delegate": {
|
|
243
|
+
const p = StakeInstruction.decodeDelegate(ix);
|
|
244
|
+
return ok("stake", programId, "delegate", {
|
|
245
|
+
stakePubkey: p.stakePubkey.toBase58(),
|
|
246
|
+
votePubkey: p.votePubkey.toBase58(),
|
|
247
|
+
authorizedPubkey: p.authorizedPubkey.toBase58(),
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
case "Authorize": {
|
|
251
|
+
const p = StakeInstruction.decodeAuthorize(ix);
|
|
252
|
+
return ok("stake", programId, "authorize", {
|
|
253
|
+
stakePubkey: p.stakePubkey.toBase58(),
|
|
254
|
+
authorizedPubkey: p.authorizedPubkey.toBase58(),
|
|
255
|
+
newAuthorizedPubkey: p.newAuthorizedPubkey.toBase58(),
|
|
256
|
+
stakeAuthorizationType: p.stakeAuthorizationType.index,
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
case "AuthorizeWithSeed":
|
|
260
|
+
return ok("stake", programId, "authorizeWithSeed", {});
|
|
261
|
+
case "Split":
|
|
262
|
+
return ok("stake", programId, "split", {});
|
|
263
|
+
case "Withdraw":
|
|
264
|
+
return ok("stake", programId, "withdraw", {});
|
|
265
|
+
case "Deactivate":
|
|
266
|
+
return ok("stake", programId, "deactivate", {});
|
|
267
|
+
case "Merge":
|
|
268
|
+
return ok("stake", programId, "merge", {});
|
|
269
|
+
}
|
|
270
|
+
} catch {}
|
|
207
271
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
272
|
+
// Vote
|
|
273
|
+
try {
|
|
274
|
+
const t = VoteInstruction.decodeInstructionType(ix);
|
|
275
|
+
switch (t) {
|
|
276
|
+
case "InitializeAccount":
|
|
277
|
+
return ok("vote", programId, "initialize", {});
|
|
278
|
+
case "Authorize":
|
|
279
|
+
return ok("vote", programId, "authorize", {});
|
|
280
|
+
case "AuthorizeWithSeed":
|
|
281
|
+
return ok("vote", programId, "authorizeWithSeed", {});
|
|
282
|
+
case "Withdraw":
|
|
283
|
+
return ok("vote", programId, "withdraw", {});
|
|
284
|
+
default:
|
|
285
|
+
return ok("vote", programId, t, {});
|
|
286
|
+
}
|
|
287
|
+
} catch {}
|
|
224
288
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
289
|
+
// Address Lookup Table
|
|
290
|
+
try {
|
|
291
|
+
const t = AddressLookupTableInstruction.decodeInstructionType(ix);
|
|
292
|
+
switch (t) {
|
|
293
|
+
case "CreateLookupTable":
|
|
294
|
+
case "ExtendLookupTable":
|
|
295
|
+
case "CloseLookupTable":
|
|
296
|
+
case "FreezeLookupTable":
|
|
297
|
+
case "DeactivateLookupTable":
|
|
298
|
+
return ok("address-lookup-table", programId, t, {});
|
|
299
|
+
}
|
|
300
|
+
} catch {}
|
|
237
301
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
302
|
+
// Memo program: parse utf8 memo if possible
|
|
303
|
+
if (
|
|
304
|
+
programId === "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr" ||
|
|
305
|
+
programId === "Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo"
|
|
306
|
+
) {
|
|
307
|
+
try {
|
|
308
|
+
const bytes = _decodeBase58(dataBase58);
|
|
309
|
+
const memo = new TextDecoder().decode(bytes);
|
|
310
|
+
return ok("spl-memo", programId, "memo", { memo });
|
|
311
|
+
} catch {}
|
|
312
|
+
return ok("spl-memo", programId, "memo", {});
|
|
313
|
+
}
|
|
250
314
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
315
|
+
// Fallback: unknown program, return raw
|
|
316
|
+
return {
|
|
317
|
+
programId,
|
|
318
|
+
accounts: accounts.map((i) => accountKeys[i] || ""),
|
|
319
|
+
data: dataBase58,
|
|
320
|
+
};
|
|
321
|
+
} catch {
|
|
322
|
+
return {
|
|
323
|
+
programId,
|
|
324
|
+
accounts: accounts.map((i) => accountKeys[i] || ""),
|
|
325
|
+
data: dataBase58,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
264
328
|
}
|