@subsquid/solana-stream 0.1.4 → 0.2.0-2-0.3887d2

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 (84) hide show
  1. package/lib/index.d.ts +2 -3
  2. package/lib/index.d.ts.map +1 -1
  3. package/lib/index.js +2 -3
  4. package/lib/index.js.map +1 -1
  5. package/lib/instruction.d.ts +2 -3
  6. package/lib/instruction.d.ts.map +1 -1
  7. package/lib/instruction.js +2 -2
  8. package/lib/instruction.js.map +1 -1
  9. package/lib/query.d.ts +46 -0
  10. package/lib/query.d.ts.map +1 -0
  11. package/lib/query.js +161 -0
  12. package/lib/query.js.map +1 -0
  13. package/lib/{archive/schema.d.ts → schema.d.ts} +30 -19
  14. package/lib/schema.d.ts.map +1 -0
  15. package/lib/{archive/schema.js → schema.js} +54 -38
  16. package/lib/schema.js.map +1 -0
  17. package/lib/source.d.ts +24 -101
  18. package/lib/source.d.ts.map +1 -1
  19. package/lib/source.js +67 -270
  20. package/lib/source.js.map +1 -1
  21. package/package.json +11 -16
  22. package/src/index.ts +2 -3
  23. package/src/instruction.ts +4 -9
  24. package/src/query.ts +192 -0
  25. package/src/{archive/schema.ts → schema.ts} +52 -34
  26. package/src/source.ts +94 -365
  27. package/README.md +0 -4
  28. package/lib/archive/schema.d.ts.map +0 -1
  29. package/lib/archive/schema.js.map +0 -1
  30. package/lib/archive/source.d.ts +0 -15
  31. package/lib/archive/source.d.ts.map +0 -1
  32. package/lib/archive/source.js +0 -98
  33. package/lib/archive/source.js.map +0 -1
  34. package/lib/data/fields.d.ts +0 -8
  35. package/lib/data/fields.d.ts.map +0 -1
  36. package/lib/data/fields.js +0 -46
  37. package/lib/data/fields.js.map +0 -1
  38. package/lib/data/model.d.ts +0 -79
  39. package/lib/data/model.d.ts.map +0 -1
  40. package/lib/data/model.js +0 -44
  41. package/lib/data/model.js.map +0 -1
  42. package/lib/data/partial.d.ts +0 -26
  43. package/lib/data/partial.d.ts.map +0 -1
  44. package/lib/data/partial.js +0 -3
  45. package/lib/data/partial.js.map +0 -1
  46. package/lib/data/request.d.ts +0 -106
  47. package/lib/data/request.d.ts.map +0 -1
  48. package/lib/data/request.js +0 -3
  49. package/lib/data/request.js.map +0 -1
  50. package/lib/data/type-util.d.ts +0 -20
  51. package/lib/data/type-util.d.ts.map +0 -1
  52. package/lib/data/type-util.js +0 -3
  53. package/lib/data/type-util.js.map +0 -1
  54. package/lib/rpc/client.d.ts +0 -17
  55. package/lib/rpc/client.d.ts.map +0 -1
  56. package/lib/rpc/client.js +0 -15
  57. package/lib/rpc/client.js.map +0 -1
  58. package/lib/rpc/filter.d.ts +0 -4
  59. package/lib/rpc/filter.d.ts.map +0 -1
  60. package/lib/rpc/filter.js +0 -351
  61. package/lib/rpc/filter.js.map +0 -1
  62. package/lib/rpc/mapping.d.ts +0 -5
  63. package/lib/rpc/mapping.d.ts.map +0 -1
  64. package/lib/rpc/mapping.js +0 -12
  65. package/lib/rpc/mapping.js.map +0 -1
  66. package/lib/rpc/project.d.ts +0 -5
  67. package/lib/rpc/project.d.ts.map +0 -1
  68. package/lib/rpc/project.js +0 -60
  69. package/lib/rpc/project.js.map +0 -1
  70. package/lib/rpc/source.d.ts +0 -15
  71. package/lib/rpc/source.d.ts.map +0 -1
  72. package/lib/rpc/source.js +0 -82
  73. package/lib/rpc/source.js.map +0 -1
  74. package/src/archive/source.ts +0 -105
  75. package/src/data/fields.ts +0 -50
  76. package/src/data/model.ts +0 -154
  77. package/src/data/partial.ts +0 -31
  78. package/src/data/request.ts +0 -140
  79. package/src/data/type-util.ts +0 -42
  80. package/src/rpc/client.ts +0 -26
  81. package/src/rpc/filter.ts +0 -362
  82. package/src/rpc/mapping.ts +0 -13
  83. package/src/rpc/project.ts +0 -61
  84. package/src/rpc/source.ts +0 -90
@@ -1,105 +0,0 @@
1
- import {BlockHeader} from '@subsquid/solana-normalization'
2
- import {Base58Bytes} from '@subsquid/solana-rpc-data'
3
- import {assertNotNull} from '@subsquid/util-internal'
4
- import {ArchiveClient} from '@subsquid/util-internal-archive-client'
5
- import {archiveIngest} from '@subsquid/util-internal-ingest-tools'
6
- import {getRequestAt, mapRangeRequestList, RangeRequestList} from '@subsquid/util-internal-range'
7
- import {array, cast} from '@subsquid/util-internal-validation'
8
- import assert from 'assert'
9
- import {PartialBlock} from '../data/partial'
10
- import {DataRequest} from '../data/request'
11
- import {getDataSchema} from './schema'
12
-
13
-
14
- export class SolanaArchive {
15
- constructor(private client: ArchiveClient) {}
16
-
17
- getFinalizedHeight(): Promise<number> {
18
- return this.client.getHeight()
19
- }
20
-
21
- async getBlockHash(height: number): Promise<Base58Bytes | undefined> {
22
- let blocks = await this.client.query({
23
- type: 'solana',
24
- fromBlock: height,
25
- toBlock: height,
26
- includeAllBlocks: true
27
- })
28
- assert(blocks.length == 1)
29
- return blocks[0].header.hash
30
- }
31
-
32
- async getBlockHeader(height: number): Promise<BlockHeader> {
33
- let blocks = await this.client.query({
34
- type: 'solana',
35
- fromBlock: height,
36
- toBlock: height,
37
- includeAllBlocks: true,
38
- fields: {
39
- block: {
40
- slot: true,
41
- parentSlot: true,
42
- parentHash: true,
43
- timestamp: true
44
- }
45
- }
46
- })
47
- assert(blocks.length == 1)
48
- let {number, ...rest} = blocks[0].header
49
- return {
50
- height: number,
51
- ...rest
52
- } as BlockHeader
53
- }
54
-
55
- async *getBlockStream(requests: RangeRequestList<DataRequest>, stopOnHead?: boolean | undefined): AsyncIterable<PartialBlock[]> {
56
- let archiveRequests = mapRangeRequestList(requests, req => {
57
- let {fields, includeAllBlocks, ...items} = req
58
- let archiveItems: any = {}
59
- let key: keyof typeof items
60
- for (key in items) {
61
- archiveItems[key] = items[key]?.map(it => ({...it.where, ...it.include}))
62
- }
63
- return {
64
- type: 'solana',
65
- fields: {
66
- block: {parentHash: true, ...fields?.block},
67
- transaction: fields?.transaction,
68
- instruction: fields?.instruction,
69
- log: {instructionAddress: true, ...fields?.log},
70
- balance: fields?.balance,
71
- tokenBalance: fields?.tokenBalance,
72
- reward: fields?.reward
73
- },
74
- includeAllBlocks,
75
- ...archiveItems
76
- }
77
- })
78
-
79
- for await (let batch of archiveIngest({
80
- client: this.client,
81
- requests: archiveRequests,
82
- stopOnHead
83
- })) {
84
- let req = getRequestAt(requests, batch.blocks[0].header.number)
85
-
86
- let blocks = cast(
87
- array(getDataSchema(assertNotNull(req?.fields))),
88
- batch.blocks
89
- ).map(b => {
90
- let {header: {number, ...hdr}, ...items} = b
91
- return {
92
- header: {height: number, ...hdr},
93
- transactions: items.transactions || [],
94
- instructions: items.instructions || [],
95
- logs: items.logs || [],
96
- balances: items.balances || [],
97
- tokenBalances: items.tokenBalances || [],
98
- rewards: items.rewards || []
99
- }
100
- })
101
-
102
- yield blocks
103
- }
104
- }
105
- }
@@ -1,50 +0,0 @@
1
- import {DEFAULT_FIELDS, FieldSelection} from './model'
2
- import {Selector} from './type-util'
3
-
4
-
5
- /**
6
- * Get effective set of selected fields.
7
- */
8
- export function getFields(fields: FieldSelection | undefined): FieldSelection {
9
- return {
10
- block: merge(DEFAULT_FIELDS.block, fields?.block),
11
- transaction: merge(DEFAULT_FIELDS.transaction, fields?.transaction),
12
- instruction: merge(DEFAULT_FIELDS.instruction, fields?.instruction),
13
- log: merge(DEFAULT_FIELDS.log, fields?.log),
14
- balance: merge(DEFAULT_FIELDS.balance, fields?.balance),
15
- tokenBalance: merge(DEFAULT_FIELDS.tokenBalance, fields?.tokenBalance),
16
- reward: merge(DEFAULT_FIELDS.reward, fields?.reward)
17
- }
18
- }
19
-
20
-
21
- function merge<Keys extends string>(def: Selector<Keys>, requested: Selector<Keys> = {}): Selector<Keys> {
22
- let fields: Selector<Keys> = {}
23
-
24
- for (let key in def) {
25
- if (requested[key] !== false) {
26
- fields[key] = def[key]
27
- }
28
- }
29
-
30
- for (let key in requested) {
31
- if (requested[key]) {
32
- fields[key] = true
33
- }
34
- }
35
-
36
- return fields
37
- }
38
-
39
-
40
- export function project<T>(fields: Selector<keyof T> | undefined, obj: T): Partial<T> {
41
- if (fields == null) return {}
42
- let result: Partial<T> = {}
43
- let key: keyof T
44
- for (key in obj) {
45
- if (fields[key]) {
46
- result[key] = obj[key]
47
- }
48
- }
49
- return result
50
- }
package/src/data/model.ts DELETED
@@ -1,154 +0,0 @@
1
- import type * as data from '@subsquid/solana-normalization'
2
- import type {
3
- BalanceRequiredFields,
4
- BlockRequiredFields,
5
- InstructionRequiredFields,
6
- LogRequiredFields,
7
- RewardRequiredFields,
8
- TokenBalanceRequiredFields,
9
- TransactionRequiredFields
10
- } from './partial'
11
- import type {GetFields, Select, Selector, Simplify} from './type-util'
12
-
13
-
14
- /**
15
- * Hex encoded binary string
16
- */
17
- export type Bytes = string
18
-
19
-
20
- /**
21
- * Base58 encoded binary string
22
- */
23
- export type Base58Bytes = string
24
-
25
-
26
- export interface FieldSelection {
27
- block?: Selector<Exclude<keyof data.BlockHeader, BlockRequiredFields>>
28
- transaction?: Selector<Exclude<keyof data.Transaction, TransactionRequiredFields>>
29
- instruction?: Selector<Exclude<keyof data.Instruction, InstructionRequiredFields>>
30
- log?: Selector<Exclude<keyof data.LogMessage, LogRequiredFields>>
31
- balance?: Selector<Exclude<keyof data.Balance, BalanceRequiredFields>>
32
- tokenBalance?: Selector<Exclude<keyof data.TokenBalance, TokenBalanceRequiredFields>>
33
- reward?: Selector<Exclude<keyof data.Reward, RewardRequiredFields>>
34
- }
35
-
36
-
37
- export const DEFAULT_FIELDS = {
38
- block: {
39
- slot: true,
40
- parentSlot: true,
41
- timestamp: true
42
- },
43
- transaction: {
44
- signatures: true,
45
- err: true
46
- },
47
- instruction: {
48
- programId: true,
49
- accounts: true,
50
- data: true,
51
- isCommitted: true
52
- },
53
- log: {
54
- programId: true,
55
- kind: true,
56
- message: true
57
- },
58
- balance: {
59
- pre: true,
60
- post: true
61
- },
62
- tokenBalance: {
63
- preMint: true,
64
- preDecimals: true,
65
- preOwner: true,
66
- preAmount: true,
67
- postMint: true,
68
- postDecimals: true,
69
- postOwner: true,
70
- postAmount: true
71
- },
72
- reward: {
73
- lamports: true,
74
- rewardType: true
75
- }
76
- } as const
77
-
78
-
79
- type Item<
80
- Data,
81
- RequiredFields extends keyof Data,
82
- F extends FieldSelection,
83
- K extends keyof FieldSelection
84
- > = Simplify<
85
- Pick<Data, RequiredFields> &
86
- Select<Data, GetFields<FieldSelection, typeof DEFAULT_FIELDS, F, K>>
87
- >
88
-
89
-
90
- export type BlockHeader<F extends FieldSelection = {}> = Item<
91
- data.BlockHeader,
92
- BlockRequiredFields,
93
- F,
94
- 'block'
95
- >
96
-
97
-
98
- export type Transaction<F extends FieldSelection = {}> = Item<
99
- data.Transaction,
100
- TransactionRequiredFields,
101
- F,
102
- 'transaction'
103
- >
104
-
105
-
106
- export type Instruction<F extends FieldSelection = {}> = Item<
107
- data.Instruction,
108
- InstructionRequiredFields,
109
- F,
110
- 'instruction'
111
- >
112
-
113
-
114
- export type LogMessage<F extends FieldSelection = {}> = Item<
115
- data.LogMessage,
116
- LogRequiredFields,
117
- F,
118
- 'log'
119
- >
120
-
121
-
122
- export type Balance<F extends FieldSelection = {}> = Item<
123
- data.Balance,
124
- BalanceRequiredFields,
125
- F,
126
- 'balance'
127
- >
128
-
129
-
130
- export type TokenBalance<F extends FieldSelection = {}> = Item<
131
- data.TokenBalance,
132
- TokenBalanceRequiredFields,
133
- F,
134
- 'tokenBalance'
135
- >
136
-
137
-
138
- export type Reward<F extends FieldSelection = {}> = Item<
139
- data.Reward,
140
- RewardRequiredFields,
141
- F,
142
- 'reward'
143
- >
144
-
145
-
146
- export interface Block<F extends FieldSelection = {}> {
147
- header: BlockHeader<F>
148
- transactions: Transaction<F>[]
149
- instructions: Instruction<F>[]
150
- logs: LogMessage<F>[]
151
- balances: Balance<F>[]
152
- tokenBalances: TokenBalance<F>[]
153
- rewards: Reward<F>[]
154
- }
@@ -1,31 +0,0 @@
1
- import type * as data from '@subsquid/solana-normalization'
2
- import type {MakePartial} from './type-util'
3
-
4
-
5
- export type BlockRequiredFields = 'height' | 'hash' | 'parentHash'
6
- export type TransactionRequiredFields = 'transactionIndex'
7
- export type InstructionRequiredFields = 'transactionIndex' | 'instructionAddress'
8
- export type LogRequiredFields = 'transactionIndex' | 'logIndex' | 'instructionAddress'
9
- export type BalanceRequiredFields = 'transactionIndex' | 'account'
10
- export type TokenBalanceRequiredFields = 'transactionIndex' | 'account'
11
- export type RewardRequiredFields = 'pubkey'
12
-
13
-
14
- export type PartialBlockHeader = MakePartial<data.BlockHeader, BlockRequiredFields>
15
- export type PartialTransaction = MakePartial<data.Transaction, TransactionRequiredFields>
16
- export type PartialInstruction = MakePartial<data.Instruction, InstructionRequiredFields>
17
- export type PartialLogMessage = MakePartial<data.LogMessage, LogRequiredFields>
18
- export type PartialBalance = MakePartial<data.Balance, BalanceRequiredFields>
19
- export type PartialTokenBalance = MakePartial<data.PrePostTokenBalance, TokenBalanceRequiredFields>
20
- export type PartialReward = MakePartial<data.Reward, RewardRequiredFields>
21
-
22
-
23
- export interface PartialBlock {
24
- header: PartialBlockHeader
25
- transactions: PartialTransaction[]
26
- instructions: PartialInstruction[]
27
- logs: PartialLogMessage[]
28
- balances: PartialBalance[]
29
- tokenBalances: PartialTokenBalance[]
30
- rewards: PartialReward[]
31
- }
@@ -1,140 +0,0 @@
1
- import {Base58Bytes} from '@subsquid/solana-rpc'
2
- import {LogMessage} from '@subsquid/solana-normalization'
3
- import {FieldSelection} from './model'
4
-
5
-
6
- export interface DataRequest {
7
- fields?: FieldSelection
8
- includeAllBlocks?: boolean
9
- transactions?: TransactionRequest[]
10
- instructions?: InstructionRequest[]
11
- logs?: LogRequest[]
12
- balances?: BalanceRequest[]
13
- tokenBalances?: TokenBalanceRequest[]
14
- rewards?: RewardRequest[]
15
- }
16
-
17
-
18
- export interface TransactionRequest {
19
- where?: TransactionRequestWhere
20
- include?: TransactionRequestRelations
21
- }
22
-
23
-
24
- export interface TransactionRequestWhere {
25
- feePayer?: Base58Bytes[]
26
- }
27
-
28
-
29
- export interface TransactionRequestRelations {
30
- instructions?: boolean
31
- logs?: boolean
32
- }
33
-
34
- /**
35
- * Hex encoded prefix of instruction data
36
- */
37
- export type Discriminator = string
38
-
39
-
40
- export interface InstructionRequest {
41
- where?: InstructionRequestWhere
42
- include?: InstructionRequestRelations
43
- }
44
-
45
-
46
- export interface InstructionRequestWhere {
47
- programId?: Base58Bytes[]
48
- d1?: Discriminator[]
49
- d2?: Discriminator[]
50
- d3?: Discriminator[]
51
- d4?: Discriminator[]
52
- d8?: Discriminator[]
53
- a0?: Base58Bytes[]
54
- a1?: Base58Bytes[]
55
- a2?: Base58Bytes[]
56
- a3?: Base58Bytes[]
57
- a4?: Base58Bytes[]
58
- a5?: Base58Bytes[]
59
- a6?: Base58Bytes[]
60
- a7?: Base58Bytes[]
61
- a8?: Base58Bytes[]
62
- a9?: Base58Bytes[]
63
- isCommitted?: boolean
64
- }
65
-
66
-
67
- export interface InstructionRequestRelations {
68
- transaction?: boolean
69
- transactionBalances?: boolean
70
- transactionTokenBalances?: boolean
71
- transactionInstructions?: boolean
72
- logs?: boolean
73
- innerInstructions?: boolean
74
- }
75
-
76
-
77
- export interface LogRequest {
78
- where?: LogRequestWhere
79
- include?: LogRequestRelations
80
- }
81
-
82
-
83
- export interface LogRequestWhere {
84
- programId?: Base58Bytes[]
85
- kind?: LogMessage['kind'][]
86
- }
87
-
88
-
89
- export interface LogRequestRelations {
90
- transaction?: boolean
91
- instruction?: boolean
92
- }
93
-
94
-
95
- export interface BalanceRequest {
96
- where?: BalanceRequestWhere
97
- include?: BalanceRequestRelations
98
- }
99
-
100
-
101
- export interface BalanceRequestWhere {
102
- account?: Base58Bytes[]
103
- }
104
-
105
-
106
- export interface BalanceRequestRelations {
107
- transaction?: boolean
108
- transactionInstructions?: boolean
109
- }
110
-
111
-
112
- export interface TokenBalanceRequest {
113
- where?: TokenBalanceRequestWhere
114
- include?: TokenBalanceRequestRelations
115
- }
116
-
117
-
118
- export interface TokenBalanceRequestWhere {
119
- account?: Base58Bytes[]
120
- preProgramId?: Base58Bytes[]
121
- postProgramId?: Base58Bytes[]
122
- preMint?: Base58Bytes[]
123
- postMint?: Base58Bytes[]
124
- preOwner?: Base58Bytes[]
125
- postOwner?: Base58Bytes[]
126
- }
127
-
128
-
129
- export interface TokenBalanceRequestRelations {
130
- transaction?: boolean
131
- transactionInstructions?: boolean
132
- }
133
-
134
-
135
- export interface RewardRequest {
136
- where?: {
137
- pubkey?: Base58Bytes[]
138
- }
139
- include?: undefined
140
- }
@@ -1,42 +0,0 @@
1
- export type Simplify<T> = {
2
- [K in keyof T]: T[K]
3
- } & {}
4
-
5
-
6
- export type ExcludeUndefined<T> = {
7
- [K in keyof T as undefined extends T[K] ? never : K]: T[K]
8
- } & {}
9
-
10
-
11
- export type GetFields<
12
- FieldSelectionType,
13
- Defaults extends FieldSelectionType,
14
- Selection extends FieldSelectionType,
15
- K extends keyof FieldSelectionType
16
- > = TrueFields<MergeDefault<Selection[K], Defaults[K]>>
17
-
18
-
19
- type MergeDefault<T, D> = Simplify<
20
- undefined extends T ? D : Omit<D, keyof ExcludeUndefined<T>> & ExcludeUndefined<T>
21
- >
22
-
23
-
24
- type TrueFields<F> = keyof {
25
- [K in keyof F as true extends F[K] ? K : never]: true
26
- }
27
-
28
-
29
- export type Select<T, Fields> = T extends any ? Simplify<Pick<T, Extract<keyof T, Fields>>> : never
30
-
31
-
32
- export type Selector<Fields extends string | number | symbol> = {
33
- [P in Fields]?: boolean
34
- }
35
-
36
-
37
- export type MakePartial<T, Required extends keyof T> = Simplify<
38
- Pick<T, Required> &
39
- {
40
- [K in keyof T as K extends Required ? never : K]+?: T[K]
41
- }
42
- >
package/src/rpc/client.ts DELETED
@@ -1,26 +0,0 @@
1
- import {RpcClient, RpcClientOptions} from '@subsquid/rpc-client'
2
-
3
-
4
- export interface SolanaRpcClientOptions extends RpcClientOptions {
5
- /**
6
- * Retry on connection error.
7
- *
8
- * By default, retries indefinitely.
9
- */
10
- retryAttempts?: number
11
- /**
12
- * Unsafe integer check must be always enabled
13
- */
14
- fixUnsafeIntegers?: true
15
- }
16
-
17
-
18
- export class SolanaRpcClient extends RpcClient {
19
- constructor(options: SolanaRpcClientOptions) {
20
- super({
21
- retryAttempts: Number.MAX_SAFE_INTEGER,
22
- ...options,
23
- fixUnsafeIntegers: true
24
- })
25
- }
26
- }