@sentio/sdk 2.35.0 → 2.36.0-rc.1
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/aptos/aptos-plugin.d.ts.map +1 -1
- package/lib/aptos/aptos-plugin.js +30 -20
- package/lib/aptos/aptos-plugin.js.map +1 -1
- package/lib/eth/binds.d.ts +2 -2
- package/lib/eth/binds.d.ts.map +1 -1
- package/lib/eth/binds.js +4 -4
- package/lib/eth/binds.js.map +1 -1
- package/lib/eth/codegen/codegen.js +2 -0
- package/lib/eth/codegen/codegen.js.map +1 -1
- package/lib/eth/codegen/ethers-sentio.d.ts.map +1 -1
- package/lib/eth/codegen/ethers-sentio.js +2 -0
- package/lib/eth/codegen/ethers-sentio.js.map +1 -1
- package/lib/eth/eth-plugin.js +2 -2
- package/lib/eth/eth-plugin.js.map +1 -1
- package/lib/fuel/base-processor.d.ts +13 -0
- package/lib/fuel/base-processor.d.ts.map +1 -0
- package/lib/fuel/base-processor.js +26 -0
- package/lib/fuel/base-processor.js.map +1 -0
- package/lib/fuel/codegen/codegen.d.ts +2 -0
- package/lib/fuel/codegen/codegen.d.ts.map +1 -0
- package/lib/fuel/codegen/codegen.js +132 -0
- package/lib/fuel/codegen/codegen.js.map +1 -0
- package/lib/fuel/codegen/index.d.ts +2 -0
- package/lib/fuel/codegen/index.d.ts.map +1 -0
- package/lib/fuel/codegen/index.js +2 -0
- package/lib/fuel/codegen/index.js.map +1 -0
- package/lib/fuel/codegen/run.d.ts +2 -0
- package/lib/fuel/codegen/run.d.ts.map +1 -0
- package/lib/fuel/codegen/run.js +11 -0
- package/lib/fuel/codegen/run.js.map +1 -0
- package/lib/fuel/codegen/utils.d.ts +2 -0
- package/lib/fuel/codegen/utils.d.ts.map +1 -0
- package/lib/fuel/codegen/utils.js +4 -0
- package/lib/fuel/codegen/utils.js.map +1 -0
- package/lib/fuel/context.d.ts +14 -0
- package/lib/fuel/context.d.ts.map +1 -0
- package/lib/fuel/context.js +27 -0
- package/lib/fuel/context.js.map +1 -0
- package/lib/fuel/fuel-plugin.d.ts +17 -0
- package/lib/fuel/fuel-plugin.d.ts.map +1 -0
- package/lib/fuel/fuel-plugin.js +96 -0
- package/lib/fuel/fuel-plugin.js.map +1 -0
- package/lib/fuel/fuel-processor.d.ts +32 -0
- package/lib/fuel/fuel-processor.d.ts.map +1 -0
- package/lib/fuel/fuel-processor.js +94 -0
- package/lib/fuel/fuel-processor.js.map +1 -0
- package/lib/fuel/index.d.ts +7 -0
- package/lib/fuel/index.d.ts.map +1 -0
- package/lib/fuel/index.js +7 -0
- package/lib/fuel/index.js.map +1 -0
- package/lib/fuel/network.d.ts +8 -0
- package/lib/fuel/network.d.ts.map +1 -0
- package/lib/fuel/network.js +14 -0
- package/lib/fuel/network.js.map +1 -0
- package/lib/fuel/transaction.d.ts +8 -0
- package/lib/fuel/transaction.d.ts.map +1 -0
- package/lib/fuel/transaction.js +23 -0
- package/lib/fuel/transaction.js.map +1 -0
- package/lib/testing/fuel-facet.d.ts +9 -0
- package/lib/testing/fuel-facet.d.ts.map +1 -0
- package/lib/testing/fuel-facet.js +51 -0
- package/lib/testing/fuel-facet.js.map +1 -0
- package/lib/testing/test-processor-server.d.ts +2 -0
- package/lib/testing/test-processor-server.d.ts.map +1 -1
- package/lib/testing/test-processor-server.js +3 -0
- package/lib/testing/test-processor-server.js.map +1 -1
- package/package.json +12 -6
- package/src/aptos/aptos-plugin.ts +38 -32
- package/src/eth/binds.ts +4 -4
- package/src/eth/codegen/codegen.ts +2 -0
- package/src/eth/codegen/ethers-sentio.ts +4 -1
- package/src/eth/eth-plugin.ts +2 -2
- package/src/fuel/base-processor.ts +38 -0
- package/src/fuel/codegen/codegen.ts +149 -0
- package/src/fuel/codegen/index.ts +1 -0
- package/src/fuel/codegen/run.ts +10 -0
- package/src/fuel/codegen/utils.ts +6 -0
- package/src/fuel/context.ts +34 -0
- package/src/fuel/fuel-plugin.ts +128 -0
- package/src/fuel/fuel-processor.ts +125 -0
- package/src/fuel/index.ts +6 -0
- package/src/fuel/network.ts +16 -0
- package/src/fuel/transaction.ts +43 -0
- package/src/testing/fuel-facet.ts +58 -0
- package/src/testing/test-processor-server.ts +4 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sentio/sdk",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.36.0-rc.1",
|
4
4
|
"license": "Apache-2.0",
|
5
5
|
"type": "module",
|
6
6
|
"exports": {
|
@@ -33,7 +33,9 @@
|
|
33
33
|
"./sui/builtin": "./lib/sui/builtin/index.js",
|
34
34
|
"./sui/builtin/0x1": "./lib/sui/builtin/0x1.js",
|
35
35
|
"./sui/builtin/0x2": "./lib/sui/builtin/0x2.js",
|
36
|
-
"./sui/builtin/0x3": "./lib/sui/builtin/0x3.js"
|
36
|
+
"./sui/builtin/0x3": "./lib/sui/builtin/0x3.js",
|
37
|
+
"./fuel": "./lib/fuel/index.js",
|
38
|
+
"./fuel/codegen": "./lib/fuel/codegen/index.js"
|
37
39
|
},
|
38
40
|
"files": [
|
39
41
|
"{lib,src}",
|
@@ -43,10 +45,11 @@
|
|
43
45
|
"dependencies": {
|
44
46
|
"@aptos-labs/ts-sdk": "~1.13.0",
|
45
47
|
"@coral-xyz/borsh": "^0.29.0",
|
48
|
+
"@fuel-ts/abi-typegen": "^0.82.0",
|
46
49
|
"@mysten/sui.js": "~0.51.0",
|
47
50
|
"@project-serum/anchor": "^0.26.0",
|
48
51
|
"@sentio/bigdecimal": "9.1.1-patch.3",
|
49
|
-
"@sentio/chain": "^1.0.
|
52
|
+
"@sentio/chain": "^1.0.21",
|
50
53
|
"@sentio/ethers-v6": "^1.0.29",
|
51
54
|
"@solana/web3.js": "1.89.1",
|
52
55
|
"@typemove/aptos": "~1.5.6",
|
@@ -56,6 +59,7 @@
|
|
56
59
|
"chalk": "^5.3.0",
|
57
60
|
"csv-parse": "^5.5.3",
|
58
61
|
"ethers": "npm:@sentio/ethers@6.7.1-patch.4",
|
62
|
+
"fuels": "^0.81.0",
|
59
63
|
"js-sha3": "^0.9.3",
|
60
64
|
"lru-cache": "^10.2.0",
|
61
65
|
"mkdirp": "^1.0.4",
|
@@ -73,8 +77,8 @@
|
|
73
77
|
"typedoc": "^0.25.7",
|
74
78
|
"utility-types": "^3.11.0",
|
75
79
|
"yaml": "^2.3.4",
|
76
|
-
"@sentio/protos": "2.
|
77
|
-
"@sentio/runtime": "^2.
|
80
|
+
"@sentio/protos": "2.36.0-rc.1",
|
81
|
+
"@sentio/runtime": "^2.36.0-rc.1"
|
78
82
|
},
|
79
83
|
"peerDependencies": {
|
80
84
|
"tsup": "npm:@sentio/tsup@^6.7.2"
|
@@ -93,12 +97,14 @@
|
|
93
97
|
"build": "pnpm gen && pnpm compile",
|
94
98
|
"build:all": "pnpm --filter=$(node -p \"require('./package.json').name\")... build",
|
95
99
|
"compile": "tsc && cp src/utils/*.csv lib/utils && cp src/tsup.config.ts lib",
|
96
|
-
"gen": "pnpm gen:eth && pnpm gen:aptos && pnpm gen:sui && pnpm gen:solana",
|
100
|
+
"gen": "pnpm gen:eth && pnpm gen:aptos && pnpm gen:sui && pnpm gen:solana && pnpm gen:fuel",
|
97
101
|
"gen:aptos": "node --loader ts-node/esm src/aptos/codegen/run.ts src/aptos/abis src/aptos/builtin && pnpm gen:aptos_test",
|
98
102
|
"gen:aptos_test": "node --loader ts-node/esm src/aptos/codegen/run.ts src/aptos/tests/abis src/aptos/tests/types",
|
99
103
|
"gen:docs": "typedoc --options typedoc.json",
|
100
104
|
"gen:eth": "node --loader ts-node/esm src/eth/codegen/run.ts src/eth/abis src/eth/builtin && pnpm gen:eth_test",
|
101
105
|
"gen:eth_test": "node --loader ts-node/esm src/eth/codegen/run.ts src/eth/tests/abis/eth ./src/eth/tests/types",
|
106
|
+
"gen:fuel": "node --loader ts-node/esm src/fuel/codegen/run.ts src/fuel/abis src/sui/builtin && pnpm gen:fuel_test",
|
107
|
+
"gen:fuel_test": "node --loader ts-node/esm src/fuel/codegen/run.ts src/fuel/tests/abis src/fuel/tests/types",
|
102
108
|
"gen:solana": "node --loader ts-node/esm src/solana/codegen/run.ts src/solana/tests/abis src/solana/tests/types",
|
103
109
|
"gen:sui": "node --loader ts-node/esm src/sui/codegen/run.ts src/sui/abis src/sui/builtin && pnpm gen:sui_test",
|
104
110
|
"gen:sui_test": "node --loader ts-node/esm src/sui/codegen/run.ts src/sui/tests/abis src/sui/tests/types",
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'
|
1
|
+
import { errorString, GLOBAL_CONFIG, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'
|
2
2
|
import {
|
3
3
|
AccountConfig,
|
4
4
|
ContractConfig,
|
@@ -12,7 +12,7 @@ import {
|
|
12
12
|
MoveOwnerType,
|
13
13
|
ProcessConfigResponse,
|
14
14
|
ProcessResult,
|
15
|
-
StartRequest
|
15
|
+
StartRequest
|
16
16
|
} from '@sentio/protos'
|
17
17
|
|
18
18
|
import { ServerError, Status } from 'nice-grpc'
|
@@ -24,7 +24,7 @@ import { AptosChainId } from '@sentio/chain'
|
|
24
24
|
import { AptosResourcesContext } from './context.js'
|
25
25
|
import {
|
26
26
|
AptosResourceProcessorTemplate,
|
27
|
-
AptosResourceProcessorTemplateState
|
27
|
+
AptosResourceProcessorTemplateState
|
28
28
|
} from './aptos-resource-processor-template.js'
|
29
29
|
import { AptosNetwork } from './network.js'
|
30
30
|
|
@@ -38,7 +38,7 @@ export class AptosPlugin extends Plugin {
|
|
38
38
|
handlers: Handlers = {
|
39
39
|
aptosEventHandlers: [],
|
40
40
|
aptosCallHandlers: [],
|
41
|
-
aptosResourceHandlers: []
|
41
|
+
aptosResourceHandlers: []
|
42
42
|
}
|
43
43
|
|
44
44
|
async start(request: StartRequest) {
|
@@ -57,7 +57,7 @@ export class AptosPlugin extends Plugin {
|
|
57
57
|
{
|
58
58
|
address: instance.contract?.address || '',
|
59
59
|
network: <AptosNetwork>instance.contract?.chainId || AptosNetwork.MAIN_NET,
|
60
|
-
startVersion: instance.startBlock || 0n
|
60
|
+
startVersion: instance.startBlock || 0n
|
61
61
|
},
|
62
62
|
NoopContext
|
63
63
|
)
|
@@ -68,7 +68,7 @@ export class AptosPlugin extends Plugin {
|
|
68
68
|
const handlers: Handlers = {
|
69
69
|
aptosEventHandlers: [],
|
70
70
|
aptosCallHandlers: [],
|
71
|
-
aptosResourceHandlers: []
|
71
|
+
aptosResourceHandlers: []
|
72
72
|
}
|
73
73
|
for (const aptosProcessor of AptosProcessorState.INSTANCE.getValues()) {
|
74
74
|
const contractConfig = ContractConfig.fromPartial({
|
@@ -77,9 +77,9 @@ export class AptosPlugin extends Plugin {
|
|
77
77
|
name: aptosProcessor.moduleName,
|
78
78
|
chainId: aptosProcessor.getChainId(),
|
79
79
|
address: aptosProcessor.config.address,
|
80
|
-
abi: ''
|
80
|
+
abi: ''
|
81
81
|
},
|
82
|
-
startBlock: aptosProcessor.config.startVersion
|
82
|
+
startBlock: aptosProcessor.config.startVersion
|
83
83
|
})
|
84
84
|
// 1. Prepare event handlers
|
85
85
|
for (const handler of aptosProcessor.eventHandlers) {
|
@@ -88,11 +88,11 @@ export class AptosPlugin extends Plugin {
|
|
88
88
|
filters: handler.filters.map((f) => {
|
89
89
|
return {
|
90
90
|
type: f.type,
|
91
|
-
account: f.account || ''
|
91
|
+
account: f.account || ''
|
92
92
|
}
|
93
93
|
}),
|
94
94
|
fetchConfig: handler.fetchConfig,
|
95
|
-
handlerId
|
95
|
+
handlerId
|
96
96
|
}
|
97
97
|
contractConfig.moveEventConfigs.push(eventHandlerConfig)
|
98
98
|
}
|
@@ -107,11 +107,11 @@ export class AptosPlugin extends Plugin {
|
|
107
107
|
typeArguments: filter.typeArguments || [],
|
108
108
|
withTypeArguments: !!filter.typeArguments,
|
109
109
|
includeFailed: filter.includeFailed || false,
|
110
|
-
publicKeyPrefix: filter.publicKeyPrefix || ''
|
110
|
+
publicKeyPrefix: filter.publicKeyPrefix || ''
|
111
111
|
}
|
112
112
|
}),
|
113
113
|
fetchConfig: handler.fetchConfig,
|
114
|
-
handlerId
|
114
|
+
handlerId
|
115
115
|
}
|
116
116
|
contractConfig.moveCallConfigs.push(functionHandlerConfig)
|
117
117
|
}
|
@@ -122,7 +122,7 @@ export class AptosPlugin extends Plugin {
|
|
122
122
|
const accountConfig = AccountConfig.fromPartial({
|
123
123
|
address: aptosProcessor.config.address,
|
124
124
|
chainId: aptosProcessor.getChainId(),
|
125
|
-
startBlock: aptosProcessor.config.startVersion
|
125
|
+
startBlock: aptosProcessor.config.startVersion
|
126
126
|
})
|
127
127
|
for (const handler of aptosProcessor.resourcesHandlers) {
|
128
128
|
const handlerId = handlers.aptosResourceHandlers.push(handler.handler) - 1
|
@@ -133,11 +133,11 @@ export class AptosPlugin extends Plugin {
|
|
133
133
|
minutesInterval: handler.timeIntervalInMinutes,
|
134
134
|
slot: 0,
|
135
135
|
slotInterval: handler.versionInterval,
|
136
|
-
fetchConfig: undefined
|
136
|
+
fetchConfig: undefined
|
137
137
|
},
|
138
138
|
type: handler.type || '',
|
139
139
|
ownerType: MoveOwnerType.ADDRESS,
|
140
|
-
fetchConfig: undefined
|
140
|
+
fetchConfig: undefined
|
141
141
|
})
|
142
142
|
}
|
143
143
|
config.accountConfigs.push(accountConfig)
|
@@ -168,15 +168,16 @@ export class AptosPlugin extends Plugin {
|
|
168
168
|
const event = binding.data.aptEvent
|
169
169
|
|
170
170
|
for (const handlerId of binding.handlerIds) {
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
171
|
+
const promise = this.handlers.aptosEventHandlers[handlerId](event).catch((e) => {
|
172
|
+
throw new ServerError(
|
173
|
+
Status.INTERNAL,
|
174
|
+
'error processing event: ' + JSON.stringify(event) + '\n' + errorString(e)
|
175
|
+
)
|
176
|
+
})
|
177
|
+
if (GLOBAL_CONFIG.execution.sequential) {
|
178
|
+
await promise
|
179
|
+
}
|
180
|
+
promises.push(promise)
|
180
181
|
}
|
181
182
|
return mergeProcessResults(await Promise.all(promises))
|
182
183
|
}
|
@@ -189,14 +190,16 @@ export class AptosPlugin extends Plugin {
|
|
189
190
|
|
190
191
|
const promises: Promise<ProcessResult>[] = []
|
191
192
|
for (const handlerId of binding.handlerIds) {
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
193
|
+
const promise = this.handlers.aptosResourceHandlers[handlerId](resource).catch((e) => {
|
194
|
+
throw new ServerError(
|
195
|
+
Status.INTERNAL,
|
196
|
+
'error processing resource: ' + JSON.stringify(resource) + '\n' + errorString(e)
|
197
|
+
)
|
198
|
+
})
|
199
|
+
if (GLOBAL_CONFIG.execution.sequential) {
|
200
|
+
await promise
|
201
|
+
}
|
202
|
+
promises.push(promise)
|
200
203
|
}
|
201
204
|
return mergeProcessResults(await Promise.all(promises))
|
202
205
|
}
|
@@ -213,6 +216,9 @@ export class AptosPlugin extends Plugin {
|
|
213
216
|
const promise = this.handlers.aptosCallHandlers[handlerId](call).catch((e) => {
|
214
217
|
throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\n' + errorString(e))
|
215
218
|
})
|
219
|
+
if (GLOBAL_CONFIG.execution.sequential) {
|
220
|
+
await promise
|
221
|
+
}
|
216
222
|
promises.push(promise)
|
217
223
|
}
|
218
224
|
return mergeProcessResults(await Promise.all(promises))
|
package/src/eth/binds.ts
CHANGED
@@ -6,8 +6,8 @@ import { BaseContract } from 'ethers'
|
|
6
6
|
import { MapStateStorage } from '@sentio/runtime'
|
7
7
|
import { EthChainId } from '@sentio/chain'
|
8
8
|
|
9
|
-
export class
|
10
|
-
static INSTANCE = new
|
9
|
+
export class EthProcessorState extends MapStateStorage<BaseProcessor<any, any>> {
|
10
|
+
static INSTANCE = new EthProcessorState()
|
11
11
|
}
|
12
12
|
|
13
13
|
// from abiName_address_chainId => contract wrapper
|
@@ -20,13 +20,13 @@ function getKey(abiName: string, address: string, network: EthChainId) {
|
|
20
20
|
// Dedup processor that bind multiple times
|
21
21
|
export function getProcessor(opts: BindOptions) {
|
22
22
|
const sig = getOptionsSignature(opts)
|
23
|
-
return
|
23
|
+
return EthProcessorState.INSTANCE.getValue(sig)
|
24
24
|
}
|
25
25
|
|
26
26
|
export function addProcessor(opts: BindOptions, processor: BaseProcessor<any, any>) {
|
27
27
|
const sig = getOptionsSignature(opts)
|
28
28
|
|
29
|
-
|
29
|
+
EthProcessorState.INSTANCE.getOrSetValue(sig, processor)
|
30
30
|
}
|
31
31
|
|
32
32
|
export function getContractByABI(abiName: string, address: string, network: EthChainId) {
|
@@ -67,9 +67,11 @@ async function codegenInternal(
|
|
67
67
|
|
68
68
|
const fileDescriptions = loadFileDescriptions(services, config.filesToProcess)
|
69
69
|
|
70
|
+
// @ts-ignore - no types
|
70
71
|
filesGenerated += processOutput(services, config, await target.beforeRun())
|
71
72
|
|
72
73
|
for (const fd of fileDescriptions) {
|
74
|
+
// @ts-ignore - no types
|
73
75
|
filesGenerated += processOutput(services, config, await target.transformFile(fd))
|
74
76
|
}
|
75
77
|
|
@@ -1,3 +1,6 @@
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
2
|
+
// @ts-nocheck
|
3
|
+
|
1
4
|
import Ethers from '@sentio/ethers-v6'
|
2
5
|
import {
|
3
6
|
Config,
|
@@ -65,7 +68,7 @@ export default class EthersSentio extends Ethers.default {
|
|
65
68
|
}
|
66
69
|
}
|
67
70
|
|
68
|
-
override afterRun() {
|
71
|
+
override afterRun(): FileDescription[] {
|
69
72
|
const commonPath = join('internal', 'common.ts')
|
70
73
|
const files = super.afterRun()
|
71
74
|
for (const [idx, file] of files.entries()) {
|
package/src/eth/eth-plugin.ts
CHANGED
@@ -16,7 +16,7 @@ import {
|
|
16
16
|
} from '@sentio/protos'
|
17
17
|
|
18
18
|
import { ServerError, Status } from 'nice-grpc'
|
19
|
-
import {
|
19
|
+
import { EthProcessorState } from './binds.js'
|
20
20
|
import { AccountProcessorState } from './account-processor-state.js'
|
21
21
|
import { ProcessorTemplateProcessorState } from './base-processor-template.js'
|
22
22
|
import { GlobalProcessorState } from './base-processor.js'
|
@@ -49,7 +49,7 @@ export class EthPlugin extends Plugin {
|
|
49
49
|
transactionHandlers: []
|
50
50
|
}
|
51
51
|
|
52
|
-
for (const processor of
|
52
|
+
for (const processor of EthProcessorState.INSTANCE.getValues()) {
|
53
53
|
// If server favor incremental update this need to change
|
54
54
|
// Start basic config for contract
|
55
55
|
const chainId = processor.getChainId()
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import { FuelProcessor, FuelProcessorConfig, FuelProcessorState } from './fuel-processor.js'
|
2
|
+
import { JsonAbi } from 'fuels'
|
3
|
+
import { FuelCall, FuelContext } from './context.js'
|
4
|
+
import { FuelFetchConfig } from './transaction.js'
|
5
|
+
import { FuelChainId } from '@sentio/chain'
|
6
|
+
|
7
|
+
|
8
|
+
export abstract class FuelAbstractProcessor extends FuelProcessor {
|
9
|
+
|
10
|
+
protected constructor(abi: JsonAbi, config?: FuelProcessorConfig) {
|
11
|
+
if (!config) {
|
12
|
+
config = {
|
13
|
+
chainId: FuelChainId.FUEL_MAINNET,
|
14
|
+
address: ''
|
15
|
+
}
|
16
|
+
}
|
17
|
+
config.abi = abi
|
18
|
+
super(config)
|
19
|
+
FuelProcessorState.INSTANCE.addValue(this)
|
20
|
+
}
|
21
|
+
|
22
|
+
protected onCallMethod<T extends Array<any>, R>(method: string, fn: (call: TypedCall<T, R>, ctx: FuelContext) => (void | Promise<void>), config: FuelFetchConfig): this {
|
23
|
+
const nameFilter = method
|
24
|
+
const handler =async (call: FuelCall, ctx: FuelContext) => {
|
25
|
+
await fn({
|
26
|
+
args: call.functionScopes[0].getCallConfig().args as T,
|
27
|
+
returnValue: call.value as R
|
28
|
+
}, ctx)
|
29
|
+
}
|
30
|
+
return super.onCall(nameFilter, handler, config)
|
31
|
+
}
|
32
|
+
|
33
|
+
}
|
34
|
+
|
35
|
+
export type TypedCall<T extends Array<any>, R> = {
|
36
|
+
args: T
|
37
|
+
returnValue: R
|
38
|
+
}
|
@@ -0,0 +1,149 @@
|
|
1
|
+
import fs, { readFileSync, writeFileSync } from 'fs'
|
2
|
+
import chalk from 'chalk'
|
3
|
+
import { AbiTypeGen, IFile, IFunction, ProgramTypeEnum } from '@fuel-ts/abi-typegen'
|
4
|
+
import mkdirp from 'mkdirp'
|
5
|
+
import path from 'path'
|
6
|
+
import { upperFirst } from './utils.js'
|
7
|
+
|
8
|
+
export async function codegen(abisDir: string, outDir: string) {
|
9
|
+
if (!fs.existsSync(abisDir)) {
|
10
|
+
return
|
11
|
+
}
|
12
|
+
|
13
|
+
const numFiles = await codegenInternal(abisDir, outDir)
|
14
|
+
console.log(chalk.green(`Generated ${numFiles} files for Fuel`))
|
15
|
+
}
|
16
|
+
|
17
|
+
function patchImport(contents: string) {
|
18
|
+
return contents.replace(/from\s+['"](\..+)['"]/g, `from '\$1.js'`)
|
19
|
+
}
|
20
|
+
|
21
|
+
function patchEnumType(contents: string) {
|
22
|
+
const matches = contents.matchAll(/export type (.+) = Enum<{ Ok: T, Err: E }>;/g)
|
23
|
+
|
24
|
+
for (const m of matches) {
|
25
|
+
const vname = m[1]
|
26
|
+
contents = contents.replace(m[0], `export type ${vname}<T,E> = Enum<{ Ok: T, Err: E }>;`)
|
27
|
+
|
28
|
+
const reg = new RegExp(`export type (.+) = ${vname}`, 'g')
|
29
|
+
contents = contents.replace(reg, `export type \$1<T,E> = ${vname}<T,E>`)
|
30
|
+
}
|
31
|
+
return contents
|
32
|
+
}
|
33
|
+
|
34
|
+
async function codegenInternal(abisDir: string, outDir: string): Promise<number> {
|
35
|
+
const allFiles = fs.readdirSync(abisDir)
|
36
|
+
if (allFiles.length === 0) {
|
37
|
+
return 0
|
38
|
+
}
|
39
|
+
|
40
|
+
const allABIFiles = []
|
41
|
+
for (const f of allFiles) {
|
42
|
+
if (f.toLowerCase().endsWith('-abi.json')) {
|
43
|
+
allABIFiles.push(path.join(abisDir, f))
|
44
|
+
}
|
45
|
+
}
|
46
|
+
if (allABIFiles.length === 0) {
|
47
|
+
return 0
|
48
|
+
}
|
49
|
+
const abiFiles = allABIFiles.map((filepath) => {
|
50
|
+
const abi: IFile = {
|
51
|
+
path: filepath,
|
52
|
+
contents: readFileSync(filepath, 'utf-8')
|
53
|
+
}
|
54
|
+
return abi
|
55
|
+
})
|
56
|
+
|
57
|
+
// fuels type gen
|
58
|
+
const abiTypeGen = new AbiTypeGen({
|
59
|
+
abiFiles,
|
60
|
+
binFiles: [],
|
61
|
+
storageSlotsFiles: [],
|
62
|
+
outputDir: outDir,
|
63
|
+
programType: ProgramTypeEnum.CONTRACT
|
64
|
+
})
|
65
|
+
|
66
|
+
mkdirp.sync(outDir)
|
67
|
+
mkdirp.sync(path.join(outDir, 'factories'))
|
68
|
+
|
69
|
+
abiTypeGen.files.forEach((file) => {
|
70
|
+
if (!file.path.endsWith('.hex.ts')) {
|
71
|
+
let content = patchImport(file.contents)
|
72
|
+
content = patchEnumType(content)
|
73
|
+
writeFileSync(file.path, content)
|
74
|
+
}
|
75
|
+
})
|
76
|
+
|
77
|
+
for (const abi of abiTypeGen.abis) {
|
78
|
+
const name = abi.name.endsWith('Abi') ? abi.name.slice(0, -3) : abi.name
|
79
|
+
const filePath = path.join(outDir, `${name}Processor.ts`)
|
80
|
+
const importedTypes = collectImportedTypes(abi.types)
|
81
|
+
|
82
|
+
const content = `/* Autogenerated file. Do not edit manually. */
|
83
|
+
|
84
|
+
/* tslint:disable */
|
85
|
+
/* eslint-disable */
|
86
|
+
|
87
|
+
import { FuelAbstractProcessor, FuelContext, FuelProcessorConfig, TypedCall, FuelFetchConfig} from '@sentio/sdk/fuel'
|
88
|
+
import {${abi.name}__factory } from './factories/${abi.name}__factory.js'
|
89
|
+
import {${abi.commonTypesInUse.join(',')}} from './common.js'
|
90
|
+
import {${importedTypes.join(',')}} from './${abi.name}.js'
|
91
|
+
|
92
|
+
import type {
|
93
|
+
BigNumberish,
|
94
|
+
BN,
|
95
|
+
BytesLike,
|
96
|
+
} from 'fuels';
|
97
|
+
|
98
|
+
|
99
|
+
namespace ${name} {
|
100
|
+
${abi.functions.map(genCallType).join('\n')}
|
101
|
+
}
|
102
|
+
|
103
|
+
export class ${name}Processor extends FuelAbstractProcessor {
|
104
|
+
constructor(config?: FuelProcessorConfig) {
|
105
|
+
super(${abi.name}__factory.abi, config)
|
106
|
+
}
|
107
|
+
|
108
|
+
static bind(config?: FuelProcessorConfig) {
|
109
|
+
return new ${name}Processor(config)
|
110
|
+
}
|
111
|
+
|
112
|
+
${abi.functions.map((f) => genOnCallFunction(name, f)).join('\n')}
|
113
|
+
}
|
114
|
+
`
|
115
|
+
writeFileSync(filePath, content)
|
116
|
+
}
|
117
|
+
|
118
|
+
return allABIFiles.length
|
119
|
+
}
|
120
|
+
|
121
|
+
function genCallType(f: IFunction) {
|
122
|
+
const name = upperFirst(f.name)
|
123
|
+
return `
|
124
|
+
export interface ${name}Call extends TypedCall<[${f.attributes.inputs}], ${f.attributes.output}> {
|
125
|
+
args: [${f.attributes.inputs}]
|
126
|
+
returnValue: ${f.attributes.output}
|
127
|
+
}
|
128
|
+
`
|
129
|
+
}
|
130
|
+
|
131
|
+
function genOnCallFunction(contractName: string, f: IFunction) {
|
132
|
+
const name = upperFirst(f.name)
|
133
|
+
return `
|
134
|
+
onCall${name}(handler: (call: ${contractName}.${name}Call, ctx: FuelContext) => void | Promise<void>, config: FuelFetchConfig) {
|
135
|
+
super.onCallMethod('${f.name}', handler, config)
|
136
|
+
}`
|
137
|
+
}
|
138
|
+
|
139
|
+
function collectImportedTypes(types: any[]): string[] {
|
140
|
+
const ret = new Set<string>()
|
141
|
+
for (const type of types) {
|
142
|
+
if ((type && type.name == 'struct') || type.name == 'enum') {
|
143
|
+
ret.add(type.attributes.inputLabel)
|
144
|
+
ret.add(type.attributes.outputLabel)
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
return Array.from(ret)
|
149
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './codegen.js'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { BaseContext, Labels, normalizeLabels } from '../core/index.js'
|
2
|
+
import { ChainId } from '@sentio/chain'
|
3
|
+
import { RecordMetaData } from '@sentio/protos'
|
4
|
+
import { InvocationCallResult } from 'fuels'
|
5
|
+
import { FuelTransaction } from './transaction.js'
|
6
|
+
|
7
|
+
export type FuelCall = InvocationCallResult
|
8
|
+
|
9
|
+
export class FuelContext extends BaseContext {
|
10
|
+
constructor(
|
11
|
+
readonly transaction: FuelTransaction | null,
|
12
|
+
readonly chainId: ChainId
|
13
|
+
) {
|
14
|
+
super({})
|
15
|
+
}
|
16
|
+
|
17
|
+
getChainId(): ChainId {
|
18
|
+
return this.chainId
|
19
|
+
}
|
20
|
+
|
21
|
+
protected getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
|
22
|
+
return {
|
23
|
+
address: this.transaction?.id || '',
|
24
|
+
contractName: this.transaction?.id || '', // TODO
|
25
|
+
blockNumber: 0n,
|
26
|
+
transactionIndex: 0,
|
27
|
+
transactionHash: this.transaction?.id || '', // TODO
|
28
|
+
chainId: this.getChainId(),
|
29
|
+
name: name,
|
30
|
+
logIndex: 0,
|
31
|
+
labels: normalizeLabels(labels)
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|