@sentio/sdk 2.13.0-rc.8 → 2.13.0
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/aptos-plugin.js +5 -2
- package/lib/aptos/aptos-plugin.js.map +1 -1
- package/lib/aptos/ext/aptos-dex.d.ts +2 -1
- package/lib/aptos/ext/aptos-dex.js +1 -1
- package/lib/aptos/ext/aptos-dex.js.map +1 -1
- package/lib/aptos/index.d.ts +1 -0
- package/lib/aptos/index.js +1 -0
- package/lib/aptos/index.js.map +1 -1
- package/lib/aptos/utils.d.ts +2 -0
- package/lib/aptos/utils.js +13 -0
- package/lib/aptos/utils.js.map +1 -0
- package/lib/eth/base-processor-template.d.ts +4 -3
- package/lib/eth/base-processor-template.js +7 -7
- package/lib/eth/base-processor-template.js.map +1 -1
- package/lib/eth/base-processor.d.ts +7 -6
- package/lib/eth/base-processor.js +13 -10
- package/lib/eth/base-processor.js.map +1 -1
- package/lib/eth/eth-plugin.js +8 -5
- package/lib/eth/eth-plugin.js.map +1 -1
- package/lib/eth/eth.d.ts +2 -0
- package/lib/eth/eth.js +15 -0
- package/lib/eth/eth.js.map +1 -1
- package/lib/move/types.d.ts +3 -0
- package/lib/move/types.js +11 -1
- package/lib/move/types.js.map +1 -1
- package/lib/move/utils.js +6 -1
- package/lib/move/utils.js.map +1 -1
- package/lib/sui/sui-plugin.js +4 -2
- package/lib/sui/sui-plugin.js.map +1 -1
- package/lib/sui/utils.d.ts +3 -1
- package/lib/sui/utils.js +22 -1
- package/lib/sui/utils.js.map +1 -1
- package/package.json +4 -4
- package/src/aptos/aptos-plugin.ts +5 -2
- package/src/aptos/ext/aptos-dex.ts +3 -5
- package/src/aptos/index.ts +2 -0
- package/src/aptos/utils.ts +14 -0
- package/src/eth/base-processor-template.ts +20 -10
- package/src/eth/base-processor.ts +37 -16
- package/src/eth/eth-plugin.ts +9 -6
- package/src/eth/eth.ts +16 -0
- package/src/move/types.ts +15 -1
- package/src/move/utils.ts +6 -1
- package/src/sui/sui-plugin.ts +4 -2
- package/src/sui/utils.ts +28 -0
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sentio/sdk",
|
3
3
|
"license": "Apache-2.0",
|
4
|
-
"version": "2.13.0
|
4
|
+
"version": "2.13.0",
|
5
5
|
"type": "module",
|
6
6
|
"scripts": {
|
7
7
|
"compile": "tsc && cp src/utils/*.csv lib/utils && cp src/tsup.config.ts lib",
|
@@ -23,8 +23,8 @@
|
|
23
23
|
"@project-serum/anchor": "^0.26.0",
|
24
24
|
"@sentio/bigdecimal": "^9.1.1-patch.3",
|
25
25
|
"@sentio/ethers-v6": "^1.0.28",
|
26
|
-
"@sentio/protos": "^2.13.0
|
27
|
-
"@sentio/runtime": "^2.13.0
|
26
|
+
"@sentio/protos": "^2.13.0",
|
27
|
+
"@sentio/runtime": "^2.13.0",
|
28
28
|
"@solana/web3.js": "^1.74.0",
|
29
29
|
"@types/prettier": "^2.7.2",
|
30
30
|
"aptos-sdk": "npm:aptos@^1.8.3",
|
@@ -88,5 +88,5 @@
|
|
88
88
|
"engines": {
|
89
89
|
"node": ">=16"
|
90
90
|
},
|
91
|
-
"gitHead": "
|
91
|
+
"gitHead": "73d75748a375e4c2bea7badc9db1c973db91d175"
|
92
92
|
}
|
@@ -20,6 +20,7 @@ import { ServerError, Status } from 'nice-grpc'
|
|
20
20
|
import { AptosAccountProcessorState, AptosProcessorState } from './aptos-processor.js'
|
21
21
|
|
22
22
|
import { initCoinList } from './ext/coin.js'
|
23
|
+
import { validateAndNormalizeAddress } from './utils.js'
|
23
24
|
|
24
25
|
export class AptosPlugin extends Plugin {
|
25
26
|
name: string = 'AptosPlugin'
|
@@ -39,7 +40,7 @@ export class AptosPlugin extends Plugin {
|
|
39
40
|
contract: {
|
40
41
|
name: aptosProcessor.moduleName,
|
41
42
|
chainId: aptosProcessor.getChainId(),
|
42
|
-
address: aptosProcessor.config.address,
|
43
|
+
address: validateAndNormalizeAddress(aptosProcessor.config.address),
|
43
44
|
abi: '',
|
44
45
|
},
|
45
46
|
startBlock: aptosProcessor.config.startVersion,
|
@@ -82,7 +83,7 @@ export class AptosPlugin extends Plugin {
|
|
82
83
|
|
83
84
|
for (const aptosProcessor of AptosAccountProcessorState.INSTANCE.getValues()) {
|
84
85
|
const accountConfig = AccountConfig.fromPartial({
|
85
|
-
address: aptosProcessor.config.address,
|
86
|
+
address: validateAndNormalizeAddress(aptosProcessor.config.address),
|
86
87
|
chainId: aptosProcessor.getChainId(),
|
87
88
|
startBlock: aptosProcessor.config.startVersion,
|
88
89
|
})
|
@@ -96,6 +97,7 @@ export class AptosPlugin extends Plugin {
|
|
96
97
|
minutesInterval: handler.timeIntervalInMinutes,
|
97
98
|
slot: 0,
|
98
99
|
slotInterval: handler.versionInterval,
|
100
|
+
fetchConfig: undefined,
|
99
101
|
},
|
100
102
|
type: handler.type || '',
|
101
103
|
})
|
@@ -107,6 +109,7 @@ export class AptosPlugin extends Plugin {
|
|
107
109
|
minutesInterval: handler.timeIntervalInMinutes,
|
108
110
|
slot: 0,
|
109
111
|
slotInterval: handler.versionInterval,
|
112
|
+
fetchConfig: undefined,
|
110
113
|
},
|
111
114
|
type: handler.type || '',
|
112
115
|
ownerType: MoveOnIntervalConfig_OwnerType.ADDRESS,
|
@@ -2,12 +2,13 @@ import { Gauge } from '@sentio/sdk'
|
|
2
2
|
import { BigDecimal } from '@sentio/bigdecimal'
|
3
3
|
import { calculateValueInUsd, getCoinInfo, whitelistCoins, whiteListed } from './coin.js'
|
4
4
|
import { AptosResourcesContext, TypedMoveResource, MoveResource, AptosContext } from '@sentio/sdk/aptos'
|
5
|
+
import { TypeDescriptor } from '../../move/index.js'
|
5
6
|
|
6
7
|
export interface PoolAdaptor<T> {
|
7
8
|
getXReserve(pool: T): bigint
|
8
9
|
getYReserve(pool: T): bigint
|
9
10
|
getExtraPoolTags(pool: TypedMoveResource<T>): any
|
10
|
-
|
11
|
+
poolType: TypeDescriptor<T>
|
11
12
|
}
|
12
13
|
|
13
14
|
export class AptosDex<T> {
|
@@ -98,10 +99,7 @@ export class AptosDex<T> {
|
|
98
99
|
ctx: AptosResourcesContext,
|
99
100
|
poolsHandler?: (pools: TypedMoveResource<T>[]) => Promise<void> | void
|
100
101
|
) {
|
101
|
-
const pools
|
102
|
-
this.poolAdaptor.poolTypeName,
|
103
|
-
resources
|
104
|
-
)
|
102
|
+
const pools = await ctx.coder.filterAndDecodeResources(this.poolAdaptor.poolType, resources)
|
105
103
|
|
106
104
|
const volumeByCoin = new Map<string, BigDecimal>()
|
107
105
|
const timestamp = ctx.timestampInMicros
|
package/src/aptos/index.ts
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
import { HexString, TxnBuilderTypes } from 'aptos-sdk'
|
2
|
+
import { isFrameworkAccount } from '../move/index.js'
|
3
|
+
|
4
|
+
export function isValidAptosAddress(value: string): boolean {
|
5
|
+
return TxnBuilderTypes.AccountAddress.isValid(value)
|
6
|
+
}
|
7
|
+
|
8
|
+
export function validateAndNormalizeAddress(address: string): string {
|
9
|
+
const hex = TxnBuilderTypes.AccountAddress.fromHex(address).toHexString()
|
10
|
+
if (isFrameworkAccount(address)) {
|
11
|
+
return HexString.ensure(hex).toShortString()
|
12
|
+
}
|
13
|
+
return hex.toString()
|
14
|
+
}
|
@@ -30,6 +30,7 @@ export abstract class BaseProcessorTemplate<
|
|
30
30
|
handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid
|
31
31
|
blockInterval?: HandleInterval
|
32
32
|
timeIntervalInMinutes?: HandleInterval
|
33
|
+
fetchConfig?: EthFetchConfig
|
33
34
|
}[] = []
|
34
35
|
traceHandlers: {
|
35
36
|
signature: string
|
@@ -64,7 +65,7 @@ export abstract class BaseProcessorTemplate<
|
|
64
65
|
processor.onTrace(th.signature, th.handler, th.fetchConfig)
|
65
66
|
}
|
66
67
|
for (const bh of this.blockHandlers) {
|
67
|
-
processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval)
|
68
|
+
processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval, bh.fetchConfig)
|
68
69
|
}
|
69
70
|
|
70
71
|
const instance: TemplateInstance = {
|
@@ -103,32 +104,41 @@ export abstract class BaseProcessorTemplate<
|
|
103
104
|
public onBlockInterval(
|
104
105
|
handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
|
105
106
|
blockInterval = 1000,
|
106
|
-
backfillBlockInterval = 4000
|
107
|
+
backfillBlockInterval = 4000,
|
108
|
+
fetchConfig?: EthFetchConfig
|
107
109
|
) {
|
108
|
-
return this.onInterval(
|
109
|
-
|
110
|
-
|
111
|
-
|
110
|
+
return this.onInterval(
|
111
|
+
handler,
|
112
|
+
undefined,
|
113
|
+
{
|
114
|
+
recentInterval: blockInterval,
|
115
|
+
backfillInterval: backfillBlockInterval,
|
116
|
+
},
|
117
|
+
fetchConfig
|
118
|
+
)
|
112
119
|
}
|
113
120
|
|
114
121
|
public onTimeInterval(
|
115
122
|
handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
|
116
123
|
timeIntervalInMinutes = 60,
|
117
|
-
backfillBlockInterval = 240
|
124
|
+
backfillBlockInterval = 240,
|
125
|
+
fetchConfig?: EthFetchConfig
|
118
126
|
) {
|
119
127
|
return this.onInterval(
|
120
128
|
handler,
|
121
129
|
{ recentInterval: timeIntervalInMinutes, backfillInterval: backfillBlockInterval },
|
122
|
-
undefined
|
130
|
+
undefined,
|
131
|
+
fetchConfig
|
123
132
|
)
|
124
133
|
}
|
125
134
|
|
126
135
|
public onInterval(
|
127
136
|
handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
|
128
137
|
timeInterval: HandleInterval | undefined,
|
129
|
-
blockInterval: HandleInterval | undefined
|
138
|
+
blockInterval: HandleInterval | undefined,
|
139
|
+
fetchConfig: EthFetchConfig | undefined
|
130
140
|
) {
|
131
|
-
this.blockHandlers.push({ handler, timeIntervalInMinutes: timeInterval, blockInterval
|
141
|
+
this.blockHandlers.push({ handler, timeIntervalInMinutes: timeInterval, blockInterval, fetchConfig })
|
132
142
|
return this
|
133
143
|
}
|
134
144
|
|
@@ -41,6 +41,7 @@ export class BlockHandler {
|
|
41
41
|
blockInterval?: HandleInterval
|
42
42
|
timeIntervalInMinutes?: HandleInterval
|
43
43
|
handler: (block: Data_EthBlock) => Promise<ProcessResult>
|
44
|
+
fetchConfig: EthFetchConfig
|
44
45
|
}
|
45
46
|
|
46
47
|
export class TransactionHandler {
|
@@ -89,23 +90,31 @@ export class GlobalProcessor {
|
|
89
90
|
public onBlockInterval(
|
90
91
|
handler: (block: RichBlock, ctx: GlobalContext) => PromiseOrVoid,
|
91
92
|
blockInterval = 250,
|
92
|
-
backfillBlockInterval = 1000
|
93
|
+
backfillBlockInterval = 1000,
|
94
|
+
fetchConfig?: Partial<EthFetchConfig>
|
93
95
|
): this {
|
94
|
-
return this.onInterval(
|
95
|
-
|
96
|
-
|
97
|
-
|
96
|
+
return this.onInterval(
|
97
|
+
handler,
|
98
|
+
undefined,
|
99
|
+
{
|
100
|
+
recentInterval: blockInterval,
|
101
|
+
backfillInterval: backfillBlockInterval,
|
102
|
+
},
|
103
|
+
fetchConfig
|
104
|
+
)
|
98
105
|
}
|
99
106
|
|
100
107
|
public onTimeInterval(
|
101
108
|
handler: (block: RichBlock, ctx: GlobalContext) => PromiseOrVoid,
|
102
109
|
timeIntervalInMinutes = 60,
|
103
|
-
backfillTimeIntervalInMinutes = 240
|
110
|
+
backfillTimeIntervalInMinutes = 240,
|
111
|
+
fetchConfig?: Partial<EthFetchConfig>
|
104
112
|
): this {
|
105
113
|
return this.onInterval(
|
106
114
|
handler,
|
107
115
|
{ recentInterval: timeIntervalInMinutes, backfillInterval: backfillTimeIntervalInMinutes },
|
108
|
-
undefined
|
116
|
+
undefined,
|
117
|
+
fetchConfig
|
109
118
|
)
|
110
119
|
}
|
111
120
|
|
@@ -116,7 +125,8 @@ export class GlobalProcessor {
|
|
116
125
|
public onInterval(
|
117
126
|
handler: (block: RichBlock, ctx: GlobalContext) => PromiseOrVoid,
|
118
127
|
timeInterval: HandleInterval | undefined,
|
119
|
-
blockInterval: HandleInterval | undefined
|
128
|
+
blockInterval: HandleInterval | undefined,
|
129
|
+
fetchConfig: Partial<EthFetchConfig> | undefined
|
120
130
|
): this {
|
121
131
|
const chainId = this.getChainId()
|
122
132
|
|
@@ -134,6 +144,7 @@ export class GlobalProcessor {
|
|
134
144
|
},
|
135
145
|
timeIntervalInMinutes: timeInterval,
|
136
146
|
blockInterval: blockInterval,
|
147
|
+
fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),
|
137
148
|
})
|
138
149
|
return this
|
139
150
|
}
|
@@ -246,30 +257,39 @@ export abstract class BaseProcessor<
|
|
246
257
|
public onBlockInterval(
|
247
258
|
handler: (block: RichBlock, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
|
248
259
|
blockInterval = 250,
|
249
|
-
backfillBlockInterval = 1000
|
260
|
+
backfillBlockInterval = 1000,
|
261
|
+
fetchConfig?: Partial<EthFetchConfig>
|
250
262
|
): this {
|
251
|
-
return this.onInterval(
|
252
|
-
|
253
|
-
|
254
|
-
|
263
|
+
return this.onInterval(
|
264
|
+
handler,
|
265
|
+
undefined,
|
266
|
+
{
|
267
|
+
recentInterval: blockInterval,
|
268
|
+
backfillInterval: backfillBlockInterval,
|
269
|
+
},
|
270
|
+
fetchConfig
|
271
|
+
)
|
255
272
|
}
|
256
273
|
|
257
274
|
public onTimeInterval(
|
258
275
|
handler: (block: RichBlock, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
|
259
276
|
timeIntervalInMinutes = 60,
|
260
|
-
backfillTimeIntervalInMinutes = 240
|
277
|
+
backfillTimeIntervalInMinutes = 240,
|
278
|
+
fetchConfig?: Partial<EthFetchConfig>
|
261
279
|
): this {
|
262
280
|
return this.onInterval(
|
263
281
|
handler,
|
264
282
|
{ recentInterval: timeIntervalInMinutes, backfillInterval: backfillTimeIntervalInMinutes },
|
265
|
-
undefined
|
283
|
+
undefined,
|
284
|
+
fetchConfig
|
266
285
|
)
|
267
286
|
}
|
268
287
|
|
269
288
|
public onInterval(
|
270
289
|
handler: (block: RichBlock, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
|
271
290
|
timeInterval: HandleInterval | undefined,
|
272
|
-
blockInterval: HandleInterval | undefined
|
291
|
+
blockInterval: HandleInterval | undefined,
|
292
|
+
fetchConfig: Partial<EthFetchConfig> | undefined
|
273
293
|
): this {
|
274
294
|
const chainId = this.getChainId()
|
275
295
|
const processor = this
|
@@ -299,6 +319,7 @@ export abstract class BaseProcessor<
|
|
299
319
|
},
|
300
320
|
timeIntervalInMinutes: timeInterval,
|
301
321
|
blockInterval: blockInterval,
|
322
|
+
fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),
|
302
323
|
})
|
303
324
|
return this
|
304
325
|
}
|
package/src/eth/eth-plugin.ts
CHANGED
@@ -20,6 +20,7 @@ import { ProcessorState } from './binds.js'
|
|
20
20
|
import { AccountProcessorState } from './account-processor-state.js'
|
21
21
|
import { ProcessorTemplateProcessorState, TemplateInstanceState } from './base-processor-template.js'
|
22
22
|
import { GlobalProcessorState } from './base-processor.js'
|
23
|
+
import { validateAndNormalizeAddress } from './eth.js'
|
23
24
|
|
24
25
|
export class EthPlugin extends Plugin {
|
25
26
|
name: string = 'EthPlugin'
|
@@ -44,7 +45,7 @@ export class EthPlugin extends Plugin {
|
|
44
45
|
contract: {
|
45
46
|
name: processor.config.name,
|
46
47
|
chainId: chainId.toString(),
|
47
|
-
address: processor.config.address,
|
48
|
+
address: validateAndNormalizeAddress(processor.config.address),
|
48
49
|
abi: '',
|
49
50
|
},
|
50
51
|
startBlock: processor.config.startBlock,
|
@@ -62,6 +63,7 @@ export class EthPlugin extends Plugin {
|
|
62
63
|
minutes: 0,
|
63
64
|
minutesInterval: blockHandler.timeIntervalInMinutes,
|
64
65
|
handlerId: handlerId,
|
66
|
+
fetchConfig: blockHandler.fetchConfig,
|
65
67
|
})
|
66
68
|
}
|
67
69
|
|
@@ -95,7 +97,7 @@ export class EthPlugin extends Plugin {
|
|
95
97
|
// }
|
96
98
|
const logFilter: LogFilter = {
|
97
99
|
addressType: undefined,
|
98
|
-
address: contractConfig.contract?.address,
|
100
|
+
address: contractConfig.contract?.address && validateAndNormalizeAddress(contractConfig.contract.address),
|
99
101
|
topics: [],
|
100
102
|
}
|
101
103
|
|
@@ -125,7 +127,7 @@ export class EthPlugin extends Plugin {
|
|
125
127
|
contract: {
|
126
128
|
name: processor.config.name,
|
127
129
|
chainId: chainId.toString(),
|
128
|
-
address: processor.config.address,
|
130
|
+
address: processor.config.address, // can only be *
|
129
131
|
abi: '',
|
130
132
|
},
|
131
133
|
startBlock: processor.config.startBlock,
|
@@ -140,6 +142,7 @@ export class EthPlugin extends Plugin {
|
|
140
142
|
minutes: 0,
|
141
143
|
minutesInterval: blockHandler.timeIntervalInMinutes,
|
142
144
|
handlerId: handlerId,
|
145
|
+
fetchConfig: blockHandler.fetchConfig,
|
143
146
|
})
|
144
147
|
}
|
145
148
|
|
@@ -156,7 +159,7 @@ export class EthPlugin extends Plugin {
|
|
156
159
|
// part 1.b prepare EVM account processors
|
157
160
|
for (const processor of AccountProcessorState.INSTANCE.getValues()) {
|
158
161
|
const accountConfig = AccountConfig.fromPartial({
|
159
|
-
address: processor.config.address,
|
162
|
+
address: validateAndNormalizeAddress(processor.config.address),
|
160
163
|
chainId: processor.getChainId().toString(),
|
161
164
|
startBlock: processor.config.startBlock ? BigInt(processor.config.startBlock) : 0n,
|
162
165
|
})
|
@@ -181,7 +184,7 @@ export class EthPlugin extends Plugin {
|
|
181
184
|
}
|
182
185
|
const logFilter: LogFilter = {
|
183
186
|
addressType: filter.addressType,
|
184
|
-
address,
|
187
|
+
address: address && validateAndNormalizeAddress(address),
|
185
188
|
topics: [],
|
186
189
|
}
|
187
190
|
|
@@ -232,7 +235,7 @@ export class EthPlugin extends Plugin {
|
|
232
235
|
}
|
233
236
|
template.bind({
|
234
237
|
name: instance.contract.name,
|
235
|
-
address: instance.contract.address,
|
238
|
+
address: validateAndNormalizeAddress(instance.contract.address),
|
236
239
|
network: Number(instance.contract.chainId),
|
237
240
|
startBlock: instance.startBlock,
|
238
241
|
endBlock: instance.endBlock,
|
package/src/eth/eth.ts
CHANGED
@@ -241,3 +241,19 @@ export interface TraceResult {
|
|
241
241
|
// "transactionPosition": 22,
|
242
242
|
// "type": "create"
|
243
243
|
// }
|
244
|
+
|
245
|
+
export function isNullAddress(address: string) {
|
246
|
+
try {
|
247
|
+
// Normalize the input address
|
248
|
+
const normalizedAddress = getAddress(address)
|
249
|
+
// Check if the normalized address is equal to the null address (all zeros)
|
250
|
+
return normalizedAddress === '0x0000000000000000000000000000000000000000'
|
251
|
+
} catch (error) {
|
252
|
+
return false
|
253
|
+
}
|
254
|
+
}
|
255
|
+
|
256
|
+
export function validateAndNormalizeAddress(address: string): string {
|
257
|
+
const normalizedAddress = getAddress(address)
|
258
|
+
return normalizedAddress.toLowerCase()
|
259
|
+
}
|
package/src/move/types.ts
CHANGED
@@ -178,10 +178,17 @@ function adjustType(type: TypeDescriptor) {
|
|
178
178
|
|
179
179
|
export const ANY_TYPE = new TypeDescriptor<any>('any')
|
180
180
|
|
181
|
+
export function vectorType<T>(t: TypeDescriptor<T> = ANY_TYPE): TypeDescriptor<T[]> {
|
182
|
+
return BUILTIN_TYPES.VECTOR_TYPE_ANY.apply(t)
|
183
|
+
}
|
184
|
+
|
181
185
|
export const BUILTIN_TYPES = {
|
182
186
|
ADDRESS_TYPE: new TypeDescriptor<string>('address'),
|
183
187
|
// export const Address = new TypeDescriptor<string>("Address")
|
184
188
|
|
189
|
+
VECTOR_TYPE_ANY: new TypeDescriptor<any[]>('vector'),
|
190
|
+
VECTOR_TYPE: vectorType,
|
191
|
+
|
185
192
|
BOOL_TYPE: new TypeDescriptor<number>('bool'),
|
186
193
|
|
187
194
|
U8_TYPE: new TypeDescriptor<number>('u8'),
|
@@ -198,7 +205,14 @@ export const BUILTIN_TYPES = {
|
|
198
205
|
// export const U256 = new TypeDescriptor<number>("U256")
|
199
206
|
}
|
200
207
|
|
201
|
-
const BUILTIN_TYPES_SET = new Set(
|
208
|
+
const BUILTIN_TYPES_SET = new Set(
|
209
|
+
Object.values(BUILTIN_TYPES).flatMap((t) => {
|
210
|
+
if (typeof t === 'object') {
|
211
|
+
return [t.qname.toLowerCase()]
|
212
|
+
}
|
213
|
+
return []
|
214
|
+
})
|
215
|
+
)
|
202
216
|
|
203
217
|
/**
|
204
218
|
*
|
package/src/move/utils.ts
CHANGED
@@ -1,11 +1,16 @@
|
|
1
1
|
import { InternalMoveModule, InternalMoveStruct } from './internal-models.js'
|
2
|
+
import { parseInt } from 'lodash-es'
|
2
3
|
|
3
4
|
export const SPLITTER = '::'
|
4
5
|
|
5
6
|
export const VECTOR_STR = 'vector'
|
6
7
|
|
7
8
|
export function isFrameworkAccount(account: string) {
|
8
|
-
|
9
|
+
const n = parseInt(account, 16)
|
10
|
+
if (Number.isNaN(n)) {
|
11
|
+
return false
|
12
|
+
}
|
13
|
+
return n >= 0 && n < 16
|
9
14
|
}
|
10
15
|
|
11
16
|
const KEYWORDS = new Set(['package', 'namespace', 'volatile', 'object', 'string', 'number', 'bigint', 'any'])
|
package/src/sui/sui-plugin.ts
CHANGED
@@ -17,6 +17,7 @@ import { ServerError, Status } from 'nice-grpc'
|
|
17
17
|
|
18
18
|
import { SuiAccountProcessorState, SuiProcessorState } from './sui-processor.js'
|
19
19
|
import { getChainId } from './network.js'
|
20
|
+
import { validateAndNormalizeAddress } from './utils.js'
|
20
21
|
|
21
22
|
export class SuiPlugin extends Plugin {
|
22
23
|
name: string = 'SuiPlugin'
|
@@ -33,7 +34,7 @@ export class SuiPlugin extends Plugin {
|
|
33
34
|
contract: {
|
34
35
|
name: suiProcessor.moduleName,
|
35
36
|
chainId: getChainId(suiProcessor.config.network),
|
36
|
-
address: suiProcessor.config.address,
|
37
|
+
address: validateAndNormalizeAddress(suiProcessor.config.address),
|
37
38
|
abi: '',
|
38
39
|
},
|
39
40
|
startBlock: BigInt(suiProcessor.config.startTimestamp),
|
@@ -73,7 +74,7 @@ export class SuiPlugin extends Plugin {
|
|
73
74
|
|
74
75
|
for (const processor of SuiAccountProcessorState.INSTANCE.getValues()) {
|
75
76
|
const accountConfig = AccountConfig.fromPartial({
|
76
|
-
address: processor.config.address,
|
77
|
+
address: validateAndNormalizeAddress(processor.config.address),
|
77
78
|
chainId: processor.getChainId(),
|
78
79
|
startBlock: BigInt(processor.config.startTimestamp), // TODO maybe use another field
|
79
80
|
})
|
@@ -86,6 +87,7 @@ export class SuiPlugin extends Plugin {
|
|
86
87
|
minutesInterval: handler.timeIntervalInMinutes,
|
87
88
|
slot: 0,
|
88
89
|
slotInterval: handler.versionInterval,
|
90
|
+
fetchConfig: undefined,
|
89
91
|
},
|
90
92
|
type: handler.type || '',
|
91
93
|
ownerType: processor.ownerType,
|
package/src/sui/utils.ts
CHANGED
@@ -5,7 +5,12 @@ import {
|
|
5
5
|
getProgrammableTransaction,
|
6
6
|
ProgrammableTransaction,
|
7
7
|
SuiTransaction,
|
8
|
+
normalizeSuiAddress,
|
9
|
+
SUI_ADDRESS_LENGTH,
|
10
|
+
SuiAddress,
|
8
11
|
} from '@mysten/sui.js'
|
12
|
+
import { isFrameworkAccount } from '../move/index.js'
|
13
|
+
import { parseInt } from 'lodash-es'
|
9
14
|
|
10
15
|
export function getMoveCalls(txBlock: SuiTransactionBlockResponse) {
|
11
16
|
const txKind = getTransactionKind(txBlock)
|
@@ -32,3 +37,26 @@ export function getMoveCalls(txBlock: SuiTransactionBlockResponse) {
|
|
32
37
|
return []
|
33
38
|
})
|
34
39
|
}
|
40
|
+
|
41
|
+
function isHex(value: string): boolean {
|
42
|
+
return /^(0x|0X)?[a-fA-F0-9]+$/.test(value)
|
43
|
+
}
|
44
|
+
|
45
|
+
function getHexByteLength(value: string): number {
|
46
|
+
return /^(0x|0X)/.test(value) ? (value.length - 2) / 2 : value.length / 2
|
47
|
+
}
|
48
|
+
|
49
|
+
export function isValidSuiAddress(value: string): value is SuiAddress {
|
50
|
+
return isHex(value) && getHexByteLength(value) <= SUI_ADDRESS_LENGTH
|
51
|
+
}
|
52
|
+
|
53
|
+
export function validateAndNormalizeAddress(address: string): string {
|
54
|
+
if (isFrameworkAccount(address)) {
|
55
|
+
const n = parseInt(address, 16)
|
56
|
+
return `0x${n.toString(16)}`
|
57
|
+
}
|
58
|
+
if (!isValidSuiAddress(address)) {
|
59
|
+
throw Error('Not valid Address')
|
60
|
+
}
|
61
|
+
return normalizeSuiAddress(address, true)
|
62
|
+
}
|