@subsquid/solana-ingest 0.0.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.
- package/bin/run.js +3 -0
- package/lib/ingest.d.ts +12 -0
- package/lib/ingest.d.ts.map +1 -0
- package/lib/ingest.js +44 -0
- package/lib/ingest.js.map +1 -0
- package/lib/main.d.ts +2 -0
- package/lib/main.d.ts.map +1 -0
- package/lib/main.js +5 -0
- package/lib/main.js.map +1 -0
- package/lib/mapping.d.ts +199 -0
- package/lib/mapping.d.ts.map +1 -0
- package/lib/mapping.js +47 -0
- package/lib/mapping.js.map +1 -0
- package/package.json +33 -0
- package/src/ingest.ts +48 -0
- package/src/main.ts +3 -0
- package/src/mapping.ts +56 -0
package/bin/run.js
ADDED
package/lib/ingest.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Command, Ingest, IngestOptions, Range } from '@subsquid/util-internal-ingest-cli';
|
|
2
|
+
interface Options extends IngestOptions {
|
|
3
|
+
votes: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare class SolanaIngest extends Ingest<Options> {
|
|
6
|
+
protected getLoggingNamespace(): string;
|
|
7
|
+
protected hasRpc(): 'required' | boolean;
|
|
8
|
+
protected setUpProgram(program: Command): void;
|
|
9
|
+
protected getBlocks(range: Range): AsyncIterable<object[]>;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=ingest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingest.d.ts","sourceRoot":"","sources":["../src/ingest.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAC,MAAM,oCAAoC,CAAA;AAKxF,UAAU,OAAQ,SAAQ,aAAa;IACnC,KAAK,EAAE,OAAO,CAAA;CACjB;AAGD,qBAAa,YAAa,SAAQ,MAAM,CAAC,OAAO,CAAC;IAC7C,SAAS,CAAC,mBAAmB,IAAI,MAAM;IAIvC,SAAS,CAAC,MAAM,IAAI,UAAU,GAAG,OAAO;IAIxC,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO;cAUtB,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC;CAiBpE"}
|
package/lib/ingest.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SolanaIngest = void 0;
|
|
4
|
+
const util_internal_1 = require("@subsquid/util-internal");
|
|
5
|
+
const util_internal_ingest_cli_1 = require("@subsquid/util-internal-ingest-cli");
|
|
6
|
+
const util_internal_json_1 = require("@subsquid/util-internal-json");
|
|
7
|
+
const mapping_1 = require("./mapping");
|
|
8
|
+
class SolanaIngest extends util_internal_ingest_cli_1.Ingest {
|
|
9
|
+
getLoggingNamespace() {
|
|
10
|
+
return 'sqd:solana-ingest';
|
|
11
|
+
}
|
|
12
|
+
hasRpc() {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
setUpProgram(program) {
|
|
16
|
+
program.description('Data ingestion tool for Solana');
|
|
17
|
+
program.options.forEach(option => {
|
|
18
|
+
if (option.attributeName() == 'rawArchive') {
|
|
19
|
+
option.required = true;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
program.option('--no-votes', 'Exclude vote transactions');
|
|
23
|
+
}
|
|
24
|
+
async *getBlocks(range) {
|
|
25
|
+
let votes = this.options().votes;
|
|
26
|
+
for await (let blocks of this.archive().getRawBlocks(range)) {
|
|
27
|
+
yield blocks.map(raw => {
|
|
28
|
+
try {
|
|
29
|
+
let block = (0, mapping_1.mapRawBlock)(raw, !votes);
|
|
30
|
+
return (0, util_internal_json_1.toJSON)(block);
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
throw (0, util_internal_1.addErrorContext)(err, {
|
|
34
|
+
blockHash: raw.hash,
|
|
35
|
+
blockHeight: raw.height,
|
|
36
|
+
blockSlot: raw.slot
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.SolanaIngest = SolanaIngest;
|
|
44
|
+
//# sourceMappingURL=ingest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingest.js","sourceRoot":"","sources":["../src/ingest.ts"],"names":[],"mappings":";;;AAAA,2DAAuD;AACvD,iFAAwF;AACxF,qEAAmD;AACnD,uCAA+C;AAQ/C,MAAa,YAAa,SAAQ,iCAAe;IACnC,mBAAmB;QACzB,OAAO,mBAAmB,CAAA;IAC9B,CAAC;IAES,MAAM;QACZ,OAAO,KAAK,CAAA;IAChB,CAAC;IAES,YAAY,CAAC,OAAgB;QACnC,OAAO,CAAC,WAAW,CAAC,gCAAgC,CAAC,CAAA;QACrD,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YAC7B,IAAI,MAAM,CAAC,aAAa,EAAE,IAAI,YAAY,EAAE,CAAC;gBACzC,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAA;YAC1B,CAAC;QACL,CAAC,CAAC,CAAA;QACF,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,2BAA2B,CAAC,CAAA;IAC7D,CAAC;IAES,KAAK,CAAC,CAAC,SAAS,CAAC,KAAY;QACnC,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAA;QAChC,IAAI,KAAK,EAAE,IAAI,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC,YAAY,CAAW,KAAK,CAAC,EAAE,CAAC;YACpE,MAAM,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;gBACnB,IAAI,CAAC;oBACD,IAAI,KAAK,GAAG,IAAA,qBAAW,EAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAA;oBACpC,OAAO,IAAA,2BAAM,EAAC,KAAK,CAAC,CAAA;gBACxB,CAAC;gBAAC,OAAM,GAAQ,EAAE,CAAC;oBACf,MAAM,IAAA,+BAAe,EAAC,GAAG,EAAE;wBACvB,SAAS,EAAE,GAAG,CAAC,IAAI;wBACnB,WAAW,EAAE,GAAG,CAAC,MAAM;wBACvB,SAAS,EAAE,GAAG,CAAC,IAAI;qBACtB,CAAC,CAAA;gBACN,CAAC;YACL,CAAC,CAAC,CAAA;QACN,CAAC;IACL,CAAC;CACJ;AApCD,oCAoCC"}
|
package/lib/main.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":""}
|
package/lib/main.js
ADDED
package/lib/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;AAAA,qCAAqC;AAErC,IAAI,qBAAY,EAAE,CAAC,GAAG,EAAE,CAAA"}
|
package/lib/mapping.d.ts
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { Block } from '@subsquid/solana-normalization';
|
|
2
|
+
import { GetSrcType } from '@subsquid/util-internal-validation';
|
|
3
|
+
declare const RawBlock: import("@subsquid/util-internal-validation").Validator<{
|
|
4
|
+
hash: string;
|
|
5
|
+
height: number;
|
|
6
|
+
slot: number;
|
|
7
|
+
block: {
|
|
8
|
+
blockHeight: number;
|
|
9
|
+
blockTime: number;
|
|
10
|
+
blockhash: string;
|
|
11
|
+
parentSlot: number;
|
|
12
|
+
previousBlockhash: string;
|
|
13
|
+
transactions: {
|
|
14
|
+
meta: {
|
|
15
|
+
fee: bigint;
|
|
16
|
+
preBalances: bigint[];
|
|
17
|
+
postBalances: bigint[];
|
|
18
|
+
logMessages: string[] | null;
|
|
19
|
+
computeUnitsConsumed?: bigint | undefined;
|
|
20
|
+
err?: any;
|
|
21
|
+
preTokenBalances?: {
|
|
22
|
+
accountIndex: number;
|
|
23
|
+
mint: string;
|
|
24
|
+
uiTokenAmount: {
|
|
25
|
+
amount: bigint;
|
|
26
|
+
decimals: number;
|
|
27
|
+
};
|
|
28
|
+
owner?: string | undefined;
|
|
29
|
+
programId?: string | undefined;
|
|
30
|
+
}[] | undefined;
|
|
31
|
+
postTokenBalances?: {
|
|
32
|
+
accountIndex: number;
|
|
33
|
+
mint: string;
|
|
34
|
+
uiTokenAmount: {
|
|
35
|
+
amount: bigint;
|
|
36
|
+
decimals: number;
|
|
37
|
+
};
|
|
38
|
+
owner?: string | undefined;
|
|
39
|
+
programId?: string | undefined;
|
|
40
|
+
}[] | undefined;
|
|
41
|
+
innerInstructions?: {
|
|
42
|
+
index: number;
|
|
43
|
+
instructions: {
|
|
44
|
+
accounts: number[];
|
|
45
|
+
data: string;
|
|
46
|
+
programIdIndex: number;
|
|
47
|
+
stackHeight: number | null;
|
|
48
|
+
}[];
|
|
49
|
+
}[] | undefined;
|
|
50
|
+
loadedAddresses?: {
|
|
51
|
+
readonly: string[];
|
|
52
|
+
writable: string[];
|
|
53
|
+
} | undefined;
|
|
54
|
+
rewards?: {
|
|
55
|
+
pubkey: string;
|
|
56
|
+
lamports: number;
|
|
57
|
+
postBalance: bigint;
|
|
58
|
+
rewardType?: string | undefined;
|
|
59
|
+
commission?: number | undefined;
|
|
60
|
+
}[] | undefined;
|
|
61
|
+
returnData?: {
|
|
62
|
+
programId: string;
|
|
63
|
+
data: [string, "base64"];
|
|
64
|
+
} | undefined;
|
|
65
|
+
};
|
|
66
|
+
transaction: {
|
|
67
|
+
message: {
|
|
68
|
+
accountKeys: string[];
|
|
69
|
+
header: {
|
|
70
|
+
numReadonlySignedAccounts: number;
|
|
71
|
+
numReadonlyUnsignedAccounts: number;
|
|
72
|
+
numRequiredSignatures: number;
|
|
73
|
+
};
|
|
74
|
+
instructions: {
|
|
75
|
+
accounts: number[];
|
|
76
|
+
data: string;
|
|
77
|
+
programIdIndex: number;
|
|
78
|
+
stackHeight: number | null;
|
|
79
|
+
}[];
|
|
80
|
+
recentBlockhash: string;
|
|
81
|
+
addressTableLookups?: {
|
|
82
|
+
accountKey: string;
|
|
83
|
+
readonlyIndexes: number[];
|
|
84
|
+
writableIndexes: number[];
|
|
85
|
+
}[] | undefined;
|
|
86
|
+
};
|
|
87
|
+
signatures: string[];
|
|
88
|
+
};
|
|
89
|
+
version: number | "legacy";
|
|
90
|
+
}[];
|
|
91
|
+
rewards: {
|
|
92
|
+
pubkey: string;
|
|
93
|
+
lamports: number;
|
|
94
|
+
postBalance: bigint;
|
|
95
|
+
rewardType?: string | undefined;
|
|
96
|
+
commission?: number | undefined;
|
|
97
|
+
}[];
|
|
98
|
+
};
|
|
99
|
+
}, {
|
|
100
|
+
hash: string;
|
|
101
|
+
height: number;
|
|
102
|
+
slot: number;
|
|
103
|
+
block: {
|
|
104
|
+
blockHeight: number;
|
|
105
|
+
blockTime: number;
|
|
106
|
+
blockhash: string;
|
|
107
|
+
parentSlot: number;
|
|
108
|
+
previousBlockhash: string;
|
|
109
|
+
transactions: {
|
|
110
|
+
meta: {
|
|
111
|
+
fee: string | number;
|
|
112
|
+
preBalances: (string | number)[];
|
|
113
|
+
postBalances: (string | number)[];
|
|
114
|
+
logMessages: string[] | null;
|
|
115
|
+
computeUnitsConsumed?: string | number | null | undefined;
|
|
116
|
+
err?: any;
|
|
117
|
+
preTokenBalances?: {
|
|
118
|
+
accountIndex: number;
|
|
119
|
+
mint: string;
|
|
120
|
+
uiTokenAmount: {
|
|
121
|
+
amount: string;
|
|
122
|
+
decimals: number;
|
|
123
|
+
};
|
|
124
|
+
owner?: string | null | undefined;
|
|
125
|
+
programId?: string | null | undefined;
|
|
126
|
+
}[] | null | undefined;
|
|
127
|
+
postTokenBalances?: {
|
|
128
|
+
accountIndex: number;
|
|
129
|
+
mint: string;
|
|
130
|
+
uiTokenAmount: {
|
|
131
|
+
amount: string;
|
|
132
|
+
decimals: number;
|
|
133
|
+
};
|
|
134
|
+
owner?: string | null | undefined;
|
|
135
|
+
programId?: string | null | undefined;
|
|
136
|
+
}[] | null | undefined;
|
|
137
|
+
innerInstructions?: {
|
|
138
|
+
index: number;
|
|
139
|
+
instructions: {
|
|
140
|
+
accounts: number[];
|
|
141
|
+
data: string;
|
|
142
|
+
programIdIndex: number;
|
|
143
|
+
stackHeight: number | null;
|
|
144
|
+
}[];
|
|
145
|
+
}[] | null | undefined;
|
|
146
|
+
loadedAddresses?: {
|
|
147
|
+
readonly: string[];
|
|
148
|
+
writable: string[];
|
|
149
|
+
} | null | undefined;
|
|
150
|
+
rewards?: {
|
|
151
|
+
pubkey: string;
|
|
152
|
+
lamports: number;
|
|
153
|
+
postBalance: string | number;
|
|
154
|
+
rewardType?: string | null | undefined;
|
|
155
|
+
commission?: number | null | undefined;
|
|
156
|
+
}[] | null | undefined;
|
|
157
|
+
returnData?: {
|
|
158
|
+
programId: string;
|
|
159
|
+
data: [string, "base64"];
|
|
160
|
+
} | null | undefined;
|
|
161
|
+
};
|
|
162
|
+
transaction: {
|
|
163
|
+
message: {
|
|
164
|
+
accountKeys: string[];
|
|
165
|
+
header: {
|
|
166
|
+
numReadonlySignedAccounts: number;
|
|
167
|
+
numReadonlyUnsignedAccounts: number;
|
|
168
|
+
numRequiredSignatures: number;
|
|
169
|
+
};
|
|
170
|
+
instructions: {
|
|
171
|
+
accounts: number[];
|
|
172
|
+
data: string;
|
|
173
|
+
programIdIndex: number;
|
|
174
|
+
stackHeight: number | null;
|
|
175
|
+
}[];
|
|
176
|
+
recentBlockhash: string;
|
|
177
|
+
addressTableLookups?: {
|
|
178
|
+
accountKey: string;
|
|
179
|
+
readonlyIndexes: number[];
|
|
180
|
+
writableIndexes: number[];
|
|
181
|
+
}[] | null | undefined;
|
|
182
|
+
};
|
|
183
|
+
signatures: string[];
|
|
184
|
+
};
|
|
185
|
+
version: number | "legacy";
|
|
186
|
+
}[];
|
|
187
|
+
rewards: {
|
|
188
|
+
pubkey: string;
|
|
189
|
+
lamports: number;
|
|
190
|
+
postBalance: string | number;
|
|
191
|
+
rewardType?: string | null | undefined;
|
|
192
|
+
commission?: number | null | undefined;
|
|
193
|
+
}[];
|
|
194
|
+
};
|
|
195
|
+
}>;
|
|
196
|
+
export type RawBlock = GetSrcType<typeof RawBlock>;
|
|
197
|
+
export declare function mapRawBlock(raw: unknown, noVotes: boolean): Block;
|
|
198
|
+
export {};
|
|
199
|
+
//# sourceMappingURL=mapping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../src/mapping.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAc,MAAM,gCAAgC,CAAA;AAEjE,OAAO,EAA6B,UAAU,EAAc,MAAM,oCAAoC,CAAA;AActG,QAAA,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKZ,CAAA;AAGF,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAA;AAGlD,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,KAAK,CAOjE"}
|
package/lib/mapping.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapRawBlock = void 0;
|
|
4
|
+
const solana_normalization_1 = require("@subsquid/solana-normalization");
|
|
5
|
+
const solana_rpc_data_1 = require("@subsquid/solana-rpc-data");
|
|
6
|
+
const util_internal_validation_1 = require("@subsquid/util-internal-validation");
|
|
7
|
+
const GetBlock = (0, util_internal_validation_1.object)({
|
|
8
|
+
blockHeight: util_internal_validation_1.NAT,
|
|
9
|
+
blockTime: util_internal_validation_1.NAT,
|
|
10
|
+
blockhash: util_internal_validation_1.B58,
|
|
11
|
+
parentSlot: util_internal_validation_1.NAT,
|
|
12
|
+
previousBlockhash: util_internal_validation_1.B58,
|
|
13
|
+
transactions: (0, util_internal_validation_1.array)(solana_rpc_data_1.Transaction),
|
|
14
|
+
rewards: (0, util_internal_validation_1.array)(solana_rpc_data_1.Reward)
|
|
15
|
+
});
|
|
16
|
+
const RawBlock = (0, util_internal_validation_1.object)({
|
|
17
|
+
hash: util_internal_validation_1.B58,
|
|
18
|
+
height: util_internal_validation_1.NAT,
|
|
19
|
+
slot: util_internal_validation_1.NAT,
|
|
20
|
+
block: GetBlock
|
|
21
|
+
});
|
|
22
|
+
function mapRawBlock(raw, noVotes) {
|
|
23
|
+
(0, util_internal_validation_1.assertValidity)(RawBlock, raw);
|
|
24
|
+
let block = (0, solana_normalization_1.mapRpcBlock)(raw);
|
|
25
|
+
if (noVotes) {
|
|
26
|
+
removeVotes(block);
|
|
27
|
+
}
|
|
28
|
+
return block;
|
|
29
|
+
}
|
|
30
|
+
exports.mapRawBlock = mapRawBlock;
|
|
31
|
+
function removeVotes(block) {
|
|
32
|
+
let removed = new Set();
|
|
33
|
+
for (let i of block.instructions) {
|
|
34
|
+
if (i.programId == 'Vote111111111111111111111111111111111111111') {
|
|
35
|
+
removed.add(i.transactionIndex);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function kept(item) {
|
|
39
|
+
return !removed.has(item.transactionIndex);
|
|
40
|
+
}
|
|
41
|
+
block.transactions = block.transactions.filter(kept);
|
|
42
|
+
block.instructions = block.instructions.filter(kept);
|
|
43
|
+
block.logs = block.logs.filter(kept);
|
|
44
|
+
block.balances = block.balances.filter(kept);
|
|
45
|
+
block.tokenBalances = block.tokenBalances.filter(kept);
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=mapping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapping.js","sourceRoot":"","sources":["../src/mapping.ts"],"names":[],"mappings":";;;AAAA,yEAAiE;AACjE,+DAA6D;AAC7D,iFAAsG;AAGtG,MAAM,QAAQ,GAAG,IAAA,iCAAM,EAAC;IACpB,WAAW,EAAE,8BAAG;IAChB,SAAS,EAAE,8BAAG;IACd,SAAS,EAAE,8BAAG;IACd,UAAU,EAAE,8BAAG;IACf,iBAAiB,EAAE,8BAAG;IACtB,YAAY,EAAE,IAAA,gCAAK,EAAC,6BAAW,CAAC;IAChC,OAAO,EAAE,IAAA,gCAAK,EAAC,wBAAM,CAAC;CACzB,CAAC,CAAA;AAGF,MAAM,QAAQ,GAAG,IAAA,iCAAM,EAAC;IACpB,IAAI,EAAE,8BAAG;IACT,MAAM,EAAE,8BAAG;IACX,IAAI,EAAE,8BAAG;IACT,KAAK,EAAE,QAAQ;CAClB,CAAC,CAAA;AAMF,SAAgB,WAAW,CAAC,GAAY,EAAE,OAAgB;IACtD,IAAA,yCAAc,EAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;IAC7B,IAAI,KAAK,GAAG,IAAA,kCAAW,EAAC,GAAG,CAAC,CAAA;IAC5B,IAAI,OAAO,EAAE,CAAC;QACV,WAAW,CAAC,KAAK,CAAC,CAAA;IACtB,CAAC;IACD,OAAO,KAAK,CAAA;AAChB,CAAC;AAPD,kCAOC;AAGD,SAAS,WAAW,CAAC,KAAY;IAC7B,IAAI,OAAO,GAAG,IAAI,GAAG,EAAU,CAAA;IAE/B,KAAK,IAAI,CAAC,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;QAC/B,IAAI,CAAC,CAAC,SAAS,IAAI,6CAA6C,EAAE,CAAC;YAC/D,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAA;QACnC,CAAC;IACL,CAAC;IAED,SAAS,IAAI,CAAC,IAAgC;QAC1C,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;IAC9C,CAAC;IAED,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACpD,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACpD,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACpC,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC5C,KAAK,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AAC1D,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@subsquid/solana-ingest",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Data fetcher and normalizer for Solana",
|
|
5
|
+
"license": "GPL-3.0-or-later",
|
|
6
|
+
"repository": "git@github.com:subsquid/squid.git",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"solana-ingest": "./bin/run.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"bin",
|
|
15
|
+
"lib",
|
|
16
|
+
"src"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@subsquid/solana-normalization": "^0.0.0",
|
|
20
|
+
"@subsquid/solana-rpc-data": "^0.0.0",
|
|
21
|
+
"@subsquid/util-internal": "^3.2.0",
|
|
22
|
+
"@subsquid/util-internal-ingest-cli": "^0.0.2",
|
|
23
|
+
"@subsquid/util-internal-json": "^1.2.3",
|
|
24
|
+
"@subsquid/util-internal-validation": "^0.4.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^18.18.14",
|
|
28
|
+
"typescript": "~5.3.2"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "rm -rf lib && tsc"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/ingest.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {addErrorContext} from '@subsquid/util-internal'
|
|
2
|
+
import {Command, Ingest, IngestOptions, Range} from '@subsquid/util-internal-ingest-cli'
|
|
3
|
+
import {toJSON} from '@subsquid/util-internal-json'
|
|
4
|
+
import {mapRawBlock, RawBlock} from './mapping'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
interface Options extends IngestOptions {
|
|
8
|
+
votes: boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export class SolanaIngest extends Ingest<Options> {
|
|
13
|
+
protected getLoggingNamespace(): string {
|
|
14
|
+
return 'sqd:solana-ingest'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
protected hasRpc(): 'required' | boolean {
|
|
18
|
+
return false
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
protected setUpProgram(program: Command) {
|
|
22
|
+
program.description('Data ingestion tool for Solana')
|
|
23
|
+
program.options.forEach(option => {
|
|
24
|
+
if (option.attributeName() == 'rawArchive') {
|
|
25
|
+
option.required = true
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
program.option('--no-votes', 'Exclude vote transactions')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected async *getBlocks(range: Range): AsyncIterable<object[]> {
|
|
32
|
+
let votes = this.options().votes
|
|
33
|
+
for await (let blocks of this.archive().getRawBlocks<RawBlock>(range)) {
|
|
34
|
+
yield blocks.map(raw => {
|
|
35
|
+
try {
|
|
36
|
+
let block = mapRawBlock(raw, !votes)
|
|
37
|
+
return toJSON(block)
|
|
38
|
+
} catch(err: any) {
|
|
39
|
+
throw addErrorContext(err, {
|
|
40
|
+
blockHash: raw.hash,
|
|
41
|
+
blockHeight: raw.height,
|
|
42
|
+
blockSlot: raw.slot
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
package/src/main.ts
ADDED
package/src/mapping.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {Block, mapRpcBlock} from '@subsquid/solana-normalization'
|
|
2
|
+
import {Reward, Transaction} from '@subsquid/solana-rpc-data'
|
|
3
|
+
import {array, assertValidity, B58, GetSrcType, NAT, object} from '@subsquid/util-internal-validation'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const GetBlock = object({
|
|
7
|
+
blockHeight: NAT,
|
|
8
|
+
blockTime: NAT,
|
|
9
|
+
blockhash: B58,
|
|
10
|
+
parentSlot: NAT,
|
|
11
|
+
previousBlockhash: B58,
|
|
12
|
+
transactions: array(Transaction),
|
|
13
|
+
rewards: array(Reward)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
const RawBlock = object({
|
|
18
|
+
hash: B58,
|
|
19
|
+
height: NAT,
|
|
20
|
+
slot: NAT,
|
|
21
|
+
block: GetBlock
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
export type RawBlock = GetSrcType<typeof RawBlock>
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
export function mapRawBlock(raw: unknown, noVotes: boolean): Block {
|
|
29
|
+
assertValidity(RawBlock, raw)
|
|
30
|
+
let block = mapRpcBlock(raw)
|
|
31
|
+
if (noVotes) {
|
|
32
|
+
removeVotes(block)
|
|
33
|
+
}
|
|
34
|
+
return block
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
function removeVotes(block: Block): void {
|
|
39
|
+
let removed = new Set<number>()
|
|
40
|
+
|
|
41
|
+
for (let i of block.instructions) {
|
|
42
|
+
if (i.programId == 'Vote111111111111111111111111111111111111111') {
|
|
43
|
+
removed.add(i.transactionIndex)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function kept(item: {transactionIndex: number}): boolean {
|
|
48
|
+
return !removed.has(item.transactionIndex)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
block.transactions = block.transactions.filter(kept)
|
|
52
|
+
block.instructions = block.instructions.filter(kept)
|
|
53
|
+
block.logs = block.logs.filter(kept)
|
|
54
|
+
block.balances = block.balances.filter(kept)
|
|
55
|
+
block.tokenBalances = block.tokenBalances.filter(kept)
|
|
56
|
+
}
|