@sentio/sdk 2.62.0-rc.9 → 2.62.1-rc.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/lib/aptos/context.d.ts.map +1 -1
- package/lib/aptos/context.js +17 -4
- package/lib/aptos/context.js.map +1 -1
- package/lib/core/base-context.test.d.ts +2 -0
- package/lib/core/base-context.test.d.ts.map +1 -0
- package/lib/core/base-context.test.js.map +1 -0
- package/lib/core/normalization.d.ts.map +1 -1
- package/lib/core/normalization.js +5 -2
- package/lib/core/normalization.js.map +1 -1
- package/lib/fuel/asset-processor.d.ts.map +1 -1
- package/lib/fuel/asset-processor.js +10 -7
- package/lib/fuel/asset-processor.js.map +1 -1
- package/lib/store/convert.test.js.map +1 -1
- package/lib/store/decorators.d.ts.map +1 -1
- package/lib/testing/test-processor-server.d.ts +0 -4
- package/lib/testing/test-processor-server.d.ts.map +1 -1
- package/lib/testing/test-processor-server.js +0 -6
- package/lib/testing/test-processor-server.js.map +1 -1
- package/package.json +10 -15
- package/src/aptos/context.ts +28 -4
- package/src/core/normalization.ts +4 -2
- package/src/fuel/asset-processor.ts +10 -7
- package/src/testing/test-processor-server.ts +0 -6
- package/lib/btc/btc-plugin.d.ts +0 -19
- package/lib/btc/btc-plugin.d.ts.map +0 -1
- package/lib/btc/btc-plugin.js +0 -161
- package/lib/btc/btc-plugin.js.map +0 -1
- package/lib/btc/btc-processor.d.ts +0 -34
- package/lib/btc/btc-processor.d.ts.map +0 -1
- package/lib/btc/btc-processor.js +0 -101
- package/lib/btc/btc-processor.js.map +0 -1
- package/lib/btc/filter.d.ts +0 -44
- package/lib/btc/filter.d.ts.map +0 -1
- package/lib/btc/filter.js +0 -127
- package/lib/btc/filter.js.map +0 -1
- package/lib/btc/filter.test.d.ts +0 -2
- package/lib/btc/filter.test.d.ts.map +0 -1
- package/lib/btc/filter.test.js.map +0 -1
- package/lib/btc/index.d.ts +0 -5
- package/lib/btc/index.d.ts.map +0 -1
- package/lib/btc/index.js +0 -5
- package/lib/btc/index.js.map +0 -1
- package/lib/btc/types.d.ts +0 -89
- package/lib/btc/types.d.ts.map +0 -1
- package/lib/btc/types.js +0 -60
- package/lib/btc/types.js.map +0 -1
- package/lib/stark/codegen/codegen.d.ts +0 -2
- package/lib/stark/codegen/codegen.d.ts.map +0 -1
- package/lib/stark/codegen/codegen.js +0 -110
- package/lib/stark/codegen/codegen.js.map +0 -1
- package/lib/stark/codegen/index.d.ts +0 -2
- package/lib/stark/codegen/index.d.ts.map +0 -1
- package/lib/stark/codegen/index.js +0 -2
- package/lib/stark/codegen/index.js.map +0 -1
- package/lib/stark/codegen/run.d.ts +0 -2
- package/lib/stark/codegen/run.d.ts.map +0 -1
- package/lib/stark/codegen/run.js +0 -11
- package/lib/stark/codegen/run.js.map +0 -1
- package/lib/stark/codegen/utils.d.ts +0 -2
- package/lib/stark/codegen/utils.d.ts.map +0 -1
- package/lib/stark/codegen/utils.js +0 -4
- package/lib/stark/codegen/utils.js.map +0 -1
- package/lib/stark/context.d.ts +0 -28
- package/lib/stark/context.d.ts.map +0 -1
- package/lib/stark/context.js +0 -59
- package/lib/stark/context.js.map +0 -1
- package/lib/stark/contract.d.ts +0 -12
- package/lib/stark/contract.d.ts.map +0 -1
- package/lib/stark/contract.js +0 -43
- package/lib/stark/contract.js.map +0 -1
- package/lib/stark/event.d.ts +0 -7
- package/lib/stark/event.d.ts.map +0 -1
- package/lib/stark/event.js +0 -11
- package/lib/stark/event.js.map +0 -1
- package/lib/stark/index.d.ts +0 -7
- package/lib/stark/index.d.ts.map +0 -1
- package/lib/stark/index.js +0 -7
- package/lib/stark/index.js.map +0 -1
- package/lib/stark/starknet-plugin.d.ts +0 -15
- package/lib/stark/starknet-plugin.d.ts.map +0 -1
- package/lib/stark/starknet-plugin.js +0 -87
- package/lib/stark/starknet-plugin.js.map +0 -1
- package/lib/stark/starknet-processor.d.ts +0 -35
- package/lib/stark/starknet-processor.d.ts.map +0 -1
- package/lib/stark/starknet-processor.js +0 -133
- package/lib/stark/starknet-processor.js.map +0 -1
- package/lib/stark/types.d.ts +0 -11
- package/lib/stark/types.d.ts.map +0 -1
- package/lib/stark/types.js +0 -2
- package/lib/stark/types.js.map +0 -1
- package/lib/testing/btc-facet.d.ts +0 -10
- package/lib/testing/btc-facet.d.ts.map +0 -1
- package/lib/testing/btc-facet.js +0 -39
- package/lib/testing/btc-facet.js.map +0 -1
- package/lib/testing/starknet-facet.d.ts +0 -9
- package/lib/testing/starknet-facet.d.ts.map +0 -1
- package/lib/testing/starknet-facet.js +0 -53
- package/lib/testing/starknet-facet.js.map +0 -1
- package/src/btc/btc-plugin.ts +0 -209
- package/src/btc/btc-processor.ts +0 -165
- package/src/btc/filter.ts +0 -206
- package/src/btc/index.ts +0 -4
- package/src/btc/types.ts +0 -134
- package/src/stark/codegen/codegen.ts +0 -125
- package/src/stark/codegen/index.ts +0 -1
- package/src/stark/codegen/run.ts +0 -10
- package/src/stark/codegen/utils.ts +0 -3
- package/src/stark/context.ts +0 -78
- package/src/stark/contract.ts +0 -55
- package/src/stark/event.ts +0 -7
- package/src/stark/index.ts +0 -9
- package/src/stark/starknet-plugin.ts +0 -116
- package/src/stark/starknet-processor.ts +0 -164
- package/src/stark/types.ts +0 -11
- package/src/testing/btc-facet.ts +0 -46
- package/src/testing/starknet-facet.ts +0 -62
package/src/btc/filter.ts
DELETED
@@ -1,206 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
BTCTransactionFilter,
|
3
|
-
BTCTransactionFilter_Condition,
|
4
|
-
BTCTransactionFilter_Filter,
|
5
|
-
BTCTransactionFilter_Filters,
|
6
|
-
BTCTransactionFilter_VinFilter,
|
7
|
-
BTCTransactionFilter_VOutFilter
|
8
|
-
} from '@sentio/protos'
|
9
|
-
import { serializeRichValue } from '../store/util.js'
|
10
|
-
import { BigDecimal } from '@sentio/bigdecimal'
|
11
|
-
import { Transaction, Vin, Vout } from './types.js'
|
12
|
-
|
13
|
-
export type TransactionFields = keyof Omit<Transaction, 'vin' | 'vout'>
|
14
|
-
|
15
|
-
export type VinFields = keyof Omit<Vin, 'pre_vout' | 'pre_transaction' | 'scriptSig'> | 'script_asm' | 'script_hex'
|
16
|
-
|
17
|
-
export type VOutFields =
|
18
|
-
| keyof Omit<Vout, 'scriptPubKey'>
|
19
|
-
| 'script_asm'
|
20
|
-
| 'script_hex'
|
21
|
-
| 'script_type'
|
22
|
-
| 'script_address'
|
23
|
-
|
24
|
-
export type Filter<F extends string> = {
|
25
|
-
[K in F]?: Condition | Comparable
|
26
|
-
}
|
27
|
-
|
28
|
-
export type Condition = {
|
29
|
-
eq?: Comparable
|
30
|
-
gt?: Comparable
|
31
|
-
gte?: Comparable
|
32
|
-
lt?: Comparable
|
33
|
-
lte?: Comparable
|
34
|
-
ne?: Comparable
|
35
|
-
// string has the prefix
|
36
|
-
prefix?: string
|
37
|
-
// string contains
|
38
|
-
contains?: string
|
39
|
-
notContains?: string
|
40
|
-
length?: number
|
41
|
-
lengthGt?: number
|
42
|
-
lengthLt?: number
|
43
|
-
// array contains any of the values
|
44
|
-
hasAny?: Array<Comparable>
|
45
|
-
// array contains all the values
|
46
|
-
hasAll?: Array<Comparable>
|
47
|
-
in?: Array<Comparable>
|
48
|
-
}
|
49
|
-
|
50
|
-
export type Filters<T extends string> = Filter<T> | Filter<T>[]
|
51
|
-
|
52
|
-
export type VinFilter = Filter<VinFields> & {
|
53
|
-
preVOut?: Filter<VOutFields>
|
54
|
-
preTransaction?: {
|
55
|
-
filter?: Array<Filter<TransactionFields>>
|
56
|
-
outputFilter?: Filters<VOutFields>
|
57
|
-
// can't have inputFilter here, we can only support one level of nesting
|
58
|
-
}
|
59
|
-
}
|
60
|
-
|
61
|
-
export type VOutFilter = Filter<VOutFields>
|
62
|
-
|
63
|
-
export type TransactionFilter = {
|
64
|
-
inputFilter?: VinFilter | VinFilter[]
|
65
|
-
outputFilter?: VOutFilter | VOutFilter[]
|
66
|
-
filter?: Array<Filter<TransactionFields>>
|
67
|
-
}
|
68
|
-
|
69
|
-
export type Comparable = number | BigDecimal | bigint | Date | string | boolean
|
70
|
-
|
71
|
-
export type TransactionFilters = TransactionFilter | TransactionFilter[]
|
72
|
-
|
73
|
-
function toVinFilter(inputFilter?: VinFilter | VinFilter[]): BTCTransactionFilter_VinFilter | undefined {
|
74
|
-
if (inputFilter) {
|
75
|
-
const ret = BTCTransactionFilter_VinFilter.create()
|
76
|
-
const filters = []
|
77
|
-
const vouts: Filter<VOutFields>[] = []
|
78
|
-
const txs: TransactionFilters = []
|
79
|
-
|
80
|
-
for (const f of Array.isArray(inputFilter) ? inputFilter : [inputFilter]) {
|
81
|
-
const { preVOut, preTransaction, ...rest } = f
|
82
|
-
filters.push(rest)
|
83
|
-
if (preVOut) {
|
84
|
-
vouts.push(preVOut)
|
85
|
-
}
|
86
|
-
if (preTransaction) {
|
87
|
-
txs.push(preTransaction)
|
88
|
-
}
|
89
|
-
}
|
90
|
-
ret.filters = BTCTransactionFilter_Filters.create({
|
91
|
-
filters: convertFilters(filters)
|
92
|
-
})
|
93
|
-
|
94
|
-
if (vouts.length > 0) {
|
95
|
-
const voutFilters = convertFilters(vouts)
|
96
|
-
if (voutFilters && voutFilters.length > 0) {
|
97
|
-
ret.preVOut = voutFilters[0]
|
98
|
-
}
|
99
|
-
}
|
100
|
-
if (txs.length > 0) {
|
101
|
-
ret.preTransaction = filters2Proto(txs)?.[0]
|
102
|
-
}
|
103
|
-
|
104
|
-
return ret
|
105
|
-
}
|
106
|
-
|
107
|
-
return undefined
|
108
|
-
}
|
109
|
-
|
110
|
-
function toVOutFilter(outputFilter?: VOutFilter | VOutFilter[]): BTCTransactionFilter_VOutFilter | undefined {
|
111
|
-
if (outputFilter) {
|
112
|
-
const ret = BTCTransactionFilter_VOutFilter.create()
|
113
|
-
const filters = Array.isArray(outputFilter) ? outputFilter : ([outputFilter] as Filter<VOutFields>[])
|
114
|
-
ret.filters = BTCTransactionFilter_Filters.create({
|
115
|
-
filters: convertFilters(filters)
|
116
|
-
})
|
117
|
-
|
118
|
-
return ret
|
119
|
-
}
|
120
|
-
return undefined
|
121
|
-
}
|
122
|
-
|
123
|
-
export function filters2Proto(filter: TransactionFilters): BTCTransactionFilter[] {
|
124
|
-
const filters = Array.isArray(filter) ? filter : [filter]
|
125
|
-
return filters.map((f) => {
|
126
|
-
return {
|
127
|
-
filter: convertFilters(f.filter),
|
128
|
-
inputFilter: toVinFilter(f.inputFilter),
|
129
|
-
outputFilter: toVOutFilter(f.outputFilter)
|
130
|
-
} as BTCTransactionFilter
|
131
|
-
})
|
132
|
-
}
|
133
|
-
|
134
|
-
function toCondition(value: Condition | Comparable): BTCTransactionFilter_Condition {
|
135
|
-
const ret: BTCTransactionFilter_Condition = BTCTransactionFilter_Condition.create()
|
136
|
-
if (value instanceof Date) {
|
137
|
-
ret.eq = serializeRichValue(value)
|
138
|
-
}
|
139
|
-
if (typeof value === 'number') {
|
140
|
-
ret.eq = serializeRichValue(value)
|
141
|
-
}
|
142
|
-
if (typeof value === 'string') {
|
143
|
-
ret.eq = serializeRichValue(value)
|
144
|
-
}
|
145
|
-
if (value instanceof BigDecimal) {
|
146
|
-
ret.eq = serializeRichValue(value)
|
147
|
-
}
|
148
|
-
if (typeof value === 'bigint') {
|
149
|
-
ret.eq = serializeRichValue(value)
|
150
|
-
}
|
151
|
-
if (typeof value === 'boolean') {
|
152
|
-
ret.eq = serializeRichValue(value)
|
153
|
-
}
|
154
|
-
if (Array.isArray(value)) {
|
155
|
-
ret.in = { values: value.map((v) => serializeRichValue(v)) }
|
156
|
-
}
|
157
|
-
|
158
|
-
for (const [k, v] of Object.entries(value)) {
|
159
|
-
switch (k) {
|
160
|
-
case 'prefix':
|
161
|
-
case 'contains':
|
162
|
-
case 'notContains':
|
163
|
-
ret[k] = v.toString()
|
164
|
-
break
|
165
|
-
case 'length':
|
166
|
-
ret['lengthEq'] = v
|
167
|
-
break
|
168
|
-
case 'lengthGt':
|
169
|
-
case 'lengthLt':
|
170
|
-
ret[k] = v
|
171
|
-
break
|
172
|
-
case 'hasAny':
|
173
|
-
case 'hasAll':
|
174
|
-
case 'in':
|
175
|
-
ret[k] = { values: v.map((v: any) => serializeRichValue(v)) }
|
176
|
-
break
|
177
|
-
case 'eq':
|
178
|
-
case 'gt':
|
179
|
-
case 'gte':
|
180
|
-
case 'lt':
|
181
|
-
case 'lte':
|
182
|
-
case 'ne':
|
183
|
-
ret[k] = serializeRichValue(v)
|
184
|
-
break
|
185
|
-
default:
|
186
|
-
throw new Error('Unknown condition op: ' + k)
|
187
|
-
}
|
188
|
-
}
|
189
|
-
|
190
|
-
return ret
|
191
|
-
}
|
192
|
-
|
193
|
-
function convertFilters<T extends string>(filters?: Array<Filter<T>>): BTCTransactionFilter_Filter[] | undefined {
|
194
|
-
if (filters && filters.length > 0) {
|
195
|
-
const ret: BTCTransactionFilter_Filter[] = []
|
196
|
-
for (const filter of filters) {
|
197
|
-
const f: BTCTransactionFilter_Filter = BTCTransactionFilter_Filter.create()
|
198
|
-
for (const [key, value] of Object.entries(filter)) {
|
199
|
-
f.conditions[key] = toCondition(value as any)
|
200
|
-
}
|
201
|
-
ret.push(f)
|
202
|
-
}
|
203
|
-
return ret
|
204
|
-
}
|
205
|
-
return []
|
206
|
-
}
|
package/src/btc/index.ts
DELETED
package/src/btc/types.ts
DELETED
@@ -1,134 +0,0 @@
|
|
1
|
-
import { BaseContext, Labels, normalizeLabels } from '../core/index.js'
|
2
|
-
import { Data_BTCBlock, HandleInterval, ProcessResult, RecordMetaData } from '@sentio/protos'
|
3
|
-
import { ChainId } from '@sentio/chain'
|
4
|
-
|
5
|
-
export type Transaction = {
|
6
|
-
txid: string
|
7
|
-
hash: string
|
8
|
-
txindex: number
|
9
|
-
blockhash: string
|
10
|
-
blockheight: number
|
11
|
-
blocktime: number
|
12
|
-
size: number
|
13
|
-
vsize: number
|
14
|
-
version: number
|
15
|
-
locktime: number
|
16
|
-
vin: Vin[]
|
17
|
-
vout: Vout[]
|
18
|
-
}
|
19
|
-
|
20
|
-
export type Vin = {
|
21
|
-
vin_index: number
|
22
|
-
coinbase?: string
|
23
|
-
txid?: string
|
24
|
-
vout?: number
|
25
|
-
sequence: number
|
26
|
-
witness?: string[]
|
27
|
-
scriptSig: {
|
28
|
-
asm: string
|
29
|
-
hex: string
|
30
|
-
}
|
31
|
-
pre_vout?: Vout
|
32
|
-
pre_transaction?: Transaction
|
33
|
-
}
|
34
|
-
|
35
|
-
export type Vout = {
|
36
|
-
value: number
|
37
|
-
n: number
|
38
|
-
scriptPubKey: {
|
39
|
-
asm: string
|
40
|
-
hex: string
|
41
|
-
reqSigs: number
|
42
|
-
type: string
|
43
|
-
address: string
|
44
|
-
}
|
45
|
-
}
|
46
|
-
|
47
|
-
export type BTCBlock = {
|
48
|
-
hash: string
|
49
|
-
confirmations: number
|
50
|
-
strippedsize: number
|
51
|
-
size: number
|
52
|
-
weight: number
|
53
|
-
height: number
|
54
|
-
version: number
|
55
|
-
merkleroot: string
|
56
|
-
tx?: Transaction[]
|
57
|
-
time: number
|
58
|
-
nonce: number
|
59
|
-
bits: string
|
60
|
-
difficulty: number
|
61
|
-
previousblockhash: string
|
62
|
-
nextblockhash: string
|
63
|
-
}
|
64
|
-
|
65
|
-
export class BTCContext extends BaseContext {
|
66
|
-
constructor(
|
67
|
-
readonly chainId: string,
|
68
|
-
readonly name: string,
|
69
|
-
readonly tx: Transaction,
|
70
|
-
readonly address: string
|
71
|
-
) {
|
72
|
-
super({})
|
73
|
-
}
|
74
|
-
|
75
|
-
protected getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
|
76
|
-
return {
|
77
|
-
address: this.address,
|
78
|
-
contractName: this.name,
|
79
|
-
blockNumber: BigInt(this.tx.blockheight ?? 0),
|
80
|
-
transactionIndex: 0,
|
81
|
-
transactionHash: this.tx.txid,
|
82
|
-
chainId: this.getChainId(),
|
83
|
-
name: name,
|
84
|
-
logIndex: 0,
|
85
|
-
labels: normalizeLabels(labels)
|
86
|
-
}
|
87
|
-
}
|
88
|
-
|
89
|
-
getChainId(): ChainId {
|
90
|
-
return this.chainId as ChainId
|
91
|
-
}
|
92
|
-
}
|
93
|
-
|
94
|
-
export class BTCBlockContext extends BaseContext {
|
95
|
-
constructor(
|
96
|
-
readonly chainId: string,
|
97
|
-
readonly name: string,
|
98
|
-
readonly block: BTCBlock,
|
99
|
-
readonly address?: string
|
100
|
-
) {
|
101
|
-
super({})
|
102
|
-
}
|
103
|
-
|
104
|
-
protected getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
|
105
|
-
return {
|
106
|
-
address: this.address ?? '',
|
107
|
-
contractName: this.name,
|
108
|
-
blockNumber: BigInt(this.block.height ?? 0),
|
109
|
-
transactionIndex: 0,
|
110
|
-
transactionHash: '',
|
111
|
-
chainId: this.getChainId(),
|
112
|
-
name: name,
|
113
|
-
logIndex: 0,
|
114
|
-
labels: normalizeLabels(labels)
|
115
|
-
}
|
116
|
-
}
|
117
|
-
|
118
|
-
getChainId(): ChainId {
|
119
|
-
return this.chainId as ChainId
|
120
|
-
}
|
121
|
-
}
|
122
|
-
|
123
|
-
export type BlockHandler = {
|
124
|
-
blockInterval?: HandleInterval
|
125
|
-
timeIntervalInMinutes?: HandleInterval
|
126
|
-
handler: (block: Data_BTCBlock) => Promise<ProcessResult>
|
127
|
-
handlerName: string
|
128
|
-
fetchConfig?: BTCOnIntervalFetchConfig
|
129
|
-
partitionHandler?: (block: Data_BTCBlock) => Promise<string | undefined>
|
130
|
-
}
|
131
|
-
|
132
|
-
export type BTCOnIntervalFetchConfig = {
|
133
|
-
getTransactions?: boolean
|
134
|
-
}
|
@@ -1,125 +0,0 @@
|
|
1
|
-
import fs, { readFileSync, writeFileSync } from 'fs'
|
2
|
-
import chalk from 'chalk'
|
3
|
-
import path from 'path'
|
4
|
-
import { mkdirpSync } from 'mkdirp'
|
5
|
-
import { events } from 'starknet'
|
6
|
-
import { StarknetChainId } from '@sentio/chain'
|
7
|
-
import { Abi } from '@sentio/abi-wan-kanabi'
|
8
|
-
import { recursiveCodegen } from '../../core/codegen.js'
|
9
|
-
|
10
|
-
export async function codegen(abisDir: string, outDir: string) {
|
11
|
-
if (!fs.existsSync(abisDir)) {
|
12
|
-
return
|
13
|
-
}
|
14
|
-
|
15
|
-
const numFiles = await recursiveCodegen(abisDir, outDir, codegenInternal)
|
16
|
-
console.log(chalk.green(`Generated ${numFiles} files for Starknet`))
|
17
|
-
}
|
18
|
-
|
19
|
-
async function codegenInternal(abisDir: string, outDir: string): Promise<number> {
|
20
|
-
const allFiles = fs.readdirSync(abisDir, { recursive: true }) as string[]
|
21
|
-
|
22
|
-
const abis: Record<string, any> = {}
|
23
|
-
let fileCount = 0
|
24
|
-
|
25
|
-
function guessNameFromAbi(abi: any, address: string) {
|
26
|
-
if (Array.isArray(abi)) {
|
27
|
-
const arr = abi as any[]
|
28
|
-
for (const a of arr) {
|
29
|
-
if (a.type == 'impl') {
|
30
|
-
return a.name.replace('Impl', '')
|
31
|
-
}
|
32
|
-
}
|
33
|
-
}
|
34
|
-
return 'Contract' + address.replace('0x', '').slice(0, 6)
|
35
|
-
}
|
36
|
-
|
37
|
-
for (const f of allFiles) {
|
38
|
-
if (f.toLowerCase().endsWith('.json')) {
|
39
|
-
let name = f.replace('.json', '')
|
40
|
-
const content = readFileSync(path.join(abisDir, f))
|
41
|
-
const abi = JSON.parse(content.toString())
|
42
|
-
let chain = StarknetChainId.STARKNET_MAINNET
|
43
|
-
if (name.startsWith('sepolia/')) {
|
44
|
-
chain = StarknetChainId.STARKNET_SEPOLIA
|
45
|
-
name = name.slice('sepolia/'.length)
|
46
|
-
}
|
47
|
-
const parts = name.split('-')
|
48
|
-
const address = parts.pop() as string
|
49
|
-
if (parts.length > 0) {
|
50
|
-
name = parts.join('')
|
51
|
-
} else {
|
52
|
-
name = guessNameFromAbi(abi, address)
|
53
|
-
}
|
54
|
-
abis[name] = {
|
55
|
-
name,
|
56
|
-
address,
|
57
|
-
chain,
|
58
|
-
abi
|
59
|
-
}
|
60
|
-
}
|
61
|
-
}
|
62
|
-
|
63
|
-
const tABIContents: string[] = []
|
64
|
-
|
65
|
-
for (const [name, abi] of Object.entries(abis)) {
|
66
|
-
tABIContents.push(`export const ABI_${name} = ${JSON.stringify(abi.abi, null, 2)} as const;`)
|
67
|
-
}
|
68
|
-
|
69
|
-
mkdirpSync(outDir)
|
70
|
-
writeFileSync(path.join(outDir, 'tabi.ts'), tABIContents.join('\n'))
|
71
|
-
fileCount++
|
72
|
-
for (const { name, address, chain, abi: jsonAbi } of Object.values(abis)) {
|
73
|
-
const content: string[] = []
|
74
|
-
content.push(
|
75
|
-
`import { StarknetProcessorConfig, StarknetEvent, AbstractStarknetProcessor, StarknetContext } from '@sentio/sdk/starknet'`
|
76
|
-
)
|
77
|
-
content.push(`import { EventToPrimitiveType, TypedContractView, Abi } from "@sentio/abi-wan-kanabi"`)
|
78
|
-
content.push(`import { ABI_${name} } from "./tabi.js"\n`)
|
79
|
-
content.push(`export type ${name} = TypedContractView<typeof ABI_${name}>`)
|
80
|
-
const abi = jsonAbi as Abi
|
81
|
-
const abiEventsEnums = abi.filter((obj) => obj.type == 'event' && obj.kind === 'enum')
|
82
|
-
const eventMap: Record<string, string> = {}
|
83
|
-
for (const ev of Object.values(events.getAbiEvents(abi))) {
|
84
|
-
const fullName = ev.name as string
|
85
|
-
let eventName = fullName
|
86
|
-
for (const e of abiEventsEnums) {
|
87
|
-
for (const v of e.variants) {
|
88
|
-
if (v.type === fullName) {
|
89
|
-
eventName = v.name
|
90
|
-
break
|
91
|
-
}
|
92
|
-
}
|
93
|
-
}
|
94
|
-
|
95
|
-
eventMap[eventName] = fullName
|
96
|
-
content.push(`export type ${eventName} = EventToPrimitiveType<typeof ABI_${name}, "${fullName}">`)
|
97
|
-
}
|
98
|
-
|
99
|
-
content.push(`\nexport class ${name}Processor extends AbstractStarknetProcessor {
|
100
|
-
constructor(abi: Abi, config: Partial<StarknetProcessorConfig>) {
|
101
|
-
super(abi, {
|
102
|
-
name: "${name}",
|
103
|
-
address: "${address}",
|
104
|
-
chainId: "${chain}",
|
105
|
-
abi,
|
106
|
-
...config
|
107
|
-
})
|
108
|
-
}`)
|
109
|
-
content.push(`\tstatic bind(config: Partial<StarknetProcessorConfig>) {
|
110
|
-
return new ${name}Processor(ABI_${name}, config)
|
111
|
-
}`)
|
112
|
-
|
113
|
-
for (const [eventName, structName] of Object.entries(eventMap)) {
|
114
|
-
content.push(`\ton${eventName}(handler: (event: StarknetEvent<${eventName}>, ctx: StarknetContext<${name}>) => Promise<void>) {
|
115
|
-
return this.onEvent<${eventName}, ${name}>("${eventName}", "${structName}", handler)
|
116
|
-
}`)
|
117
|
-
}
|
118
|
-
|
119
|
-
content.push(`}`)
|
120
|
-
writeFileSync(path.join(outDir, `${name}-processor.ts`), content.join('\n'))
|
121
|
-
fileCount++
|
122
|
-
}
|
123
|
-
|
124
|
-
return fileCount
|
125
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from './codegen.js'
|
package/src/stark/codegen/run.ts
DELETED
package/src/stark/context.ts
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
import { ChainId } from '@sentio/chain'
|
2
|
-
import { RecordMetaData } from '@sentio/protos'
|
3
|
-
import { BaseContext, Labels, normalizeLabels } from '../core/index.js'
|
4
|
-
import { Provider, RpcProvider } from 'starknet'
|
5
|
-
import { StarknetProcessorConfig } from './types.js'
|
6
|
-
import { Abi } from '@sentio/abi-wan-kanabi'
|
7
|
-
import { StarknetContractView } from './contract.js'
|
8
|
-
|
9
|
-
class AbstractContext extends BaseContext {
|
10
|
-
constructor(
|
11
|
-
readonly provider: Provider,
|
12
|
-
readonly contractAddress: string,
|
13
|
-
readonly chainId: ChainId | string,
|
14
|
-
readonly blockNumber: number,
|
15
|
-
readonly blockHash: string,
|
16
|
-
readonly transactionHash: string,
|
17
|
-
readonly logIndex: number = -1,
|
18
|
-
readonly contractName: string = '',
|
19
|
-
readonly abi?: Abi
|
20
|
-
) {
|
21
|
-
super({})
|
22
|
-
}
|
23
|
-
|
24
|
-
protected getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
|
25
|
-
return {
|
26
|
-
address: this.contractAddress,
|
27
|
-
contractName: '',
|
28
|
-
blockNumber: BigInt(this.blockNumber),
|
29
|
-
transactionIndex: 0,
|
30
|
-
transactionHash: this.transactionHash,
|
31
|
-
chainId: this.getChainId(),
|
32
|
-
name: name,
|
33
|
-
logIndex: this.logIndex,
|
34
|
-
labels: normalizeLabels(labels)
|
35
|
-
}
|
36
|
-
}
|
37
|
-
|
38
|
-
getChainId(): ChainId {
|
39
|
-
return this.chainId as ChainId
|
40
|
-
}
|
41
|
-
}
|
42
|
-
|
43
|
-
export class StarknetContext<CT> extends AbstractContext {
|
44
|
-
private _contract: any
|
45
|
-
|
46
|
-
constructor(
|
47
|
-
config: StarknetProcessorConfig,
|
48
|
-
provider: RpcProvider,
|
49
|
-
blockNumber: number,
|
50
|
-
blockHash: string,
|
51
|
-
transaction_hash: string,
|
52
|
-
logIndex: number,
|
53
|
-
readonly classHash: string
|
54
|
-
) {
|
55
|
-
super(
|
56
|
-
provider,
|
57
|
-
config.address,
|
58
|
-
config.chainId,
|
59
|
-
blockNumber,
|
60
|
-
blockHash,
|
61
|
-
transaction_hash,
|
62
|
-
logIndex,
|
63
|
-
config.name ?? classHash.slice(0, 8),
|
64
|
-
config.abi
|
65
|
-
)
|
66
|
-
}
|
67
|
-
|
68
|
-
getContract(): CT {
|
69
|
-
if (!this.abi) {
|
70
|
-
throw new Error('abi not found')
|
71
|
-
}
|
72
|
-
|
73
|
-
if (!this._contract) {
|
74
|
-
this._contract = new StarknetContractView(this.abi, this.contractAddress, this.provider, this.blockNumber)
|
75
|
-
}
|
76
|
-
return this._contract as CT
|
77
|
-
}
|
78
|
-
}
|
package/src/stark/contract.ts
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
ArgsOrCalldata,
|
3
|
-
ArgsOrCalldataWithOptions,
|
4
|
-
AsyncContractFunction,
|
5
|
-
CallOptions,
|
6
|
-
Contract,
|
7
|
-
Result,
|
8
|
-
RpcProvider,
|
9
|
-
CallData,
|
10
|
-
splitArgsAndOptions
|
11
|
-
} from 'starknet'
|
12
|
-
import { Abi } from '@sentio/abi-wan-kanabi'
|
13
|
-
|
14
|
-
export class StarknetContractView {
|
15
|
-
private _contract: Contract
|
16
|
-
|
17
|
-
constructor(
|
18
|
-
readonly abi: Abi,
|
19
|
-
readonly address: string,
|
20
|
-
readonly provider: RpcProvider,
|
21
|
-
readonly blockNumber: number
|
22
|
-
) {
|
23
|
-
this._contract = new Contract(abi, address, provider)
|
24
|
-
const callData = new CallData(abi)
|
25
|
-
|
26
|
-
for (const fn of callData.abi) {
|
27
|
-
if (fn.type == 'function' && fn.state_mutability == 'view') {
|
28
|
-
const signature = fn.name
|
29
|
-
Object.defineProperty(this, signature, {
|
30
|
-
enumerable: true,
|
31
|
-
writable: false,
|
32
|
-
value: buildCall(this, signature)
|
33
|
-
})
|
34
|
-
}
|
35
|
-
}
|
36
|
-
}
|
37
|
-
|
38
|
-
call(method: string, args?: ArgsOrCalldata, callOptions?: CallOptions): Promise<Result> {
|
39
|
-
return this._contract.call(method, args, {
|
40
|
-
...callOptions,
|
41
|
-
blockIdentifier: this.blockNumber
|
42
|
-
})
|
43
|
-
}
|
44
|
-
}
|
45
|
-
|
46
|
-
function buildCall(contract: StarknetContractView, name: string): AsyncContractFunction {
|
47
|
-
return async function (...args: ArgsOrCalldataWithOptions): Promise<any> {
|
48
|
-
const params = splitArgsAndOptions(args)
|
49
|
-
return contract.call(name, params.args, {
|
50
|
-
parseRequest: true,
|
51
|
-
parseResponse: true,
|
52
|
-
...params.options
|
53
|
-
})
|
54
|
-
}
|
55
|
-
}
|
package/src/stark/event.ts
DELETED
package/src/stark/index.ts
DELETED