@sentio/sdk 2.35.1-rc.1 → 2.36.0-rc.10
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.d.ts.map +1 -1
- package/lib/aptos/aptos-plugin.js +30 -20
- package/lib/aptos/aptos-plugin.js.map +1 -1
- package/lib/fuel/asset-processor.d.ts +36 -0
- package/lib/fuel/asset-processor.d.ts.map +1 -0
- package/lib/fuel/asset-processor.js +87 -0
- package/lib/fuel/asset-processor.js.map +1 -0
- package/lib/fuel/base-processor.d.ts +8 -6
- package/lib/fuel/base-processor.d.ts.map +1 -1
- package/lib/fuel/base-processor.js +14 -11
- package/lib/fuel/base-processor.js.map +1 -1
- package/lib/fuel/codegen/codegen.js +62 -15
- package/lib/fuel/codegen/codegen.js.map +1 -1
- package/lib/fuel/context.d.ts +12 -4
- package/lib/fuel/context.d.ts.map +1 -1
- package/lib/fuel/context.js +21 -7
- package/lib/fuel/context.js.map +1 -1
- package/lib/fuel/fuel-plugin.d.ts.map +1 -1
- package/lib/fuel/fuel-plugin.js +18 -30
- package/lib/fuel/fuel-plugin.js.map +1 -1
- package/lib/fuel/fuel-processor.d.ts +4 -11
- package/lib/fuel/fuel-processor.d.ts.map +1 -1
- package/lib/fuel/fuel-processor.js +12 -12
- package/lib/fuel/fuel-processor.js.map +1 -1
- package/lib/fuel/index.d.ts +2 -0
- package/lib/fuel/index.d.ts.map +1 -1
- package/lib/fuel/index.js +2 -0
- package/lib/fuel/index.js.map +1 -1
- package/lib/fuel/network.js +1 -1
- package/lib/fuel/network.js.map +1 -1
- package/lib/fuel/transaction.d.ts +8 -3
- package/lib/fuel/transaction.d.ts.map +1 -1
- package/lib/fuel/transaction.js +63 -15
- package/lib/fuel/transaction.js.map +1 -1
- package/lib/fuel/types.d.ts +20 -0
- package/lib/fuel/types.d.ts.map +1 -0
- package/lib/fuel/types.js +5 -0
- package/lib/fuel/types.js.map +1 -0
- package/lib/testing/fuel-facet.d.ts.map +1 -1
- package/lib/testing/fuel-facet.js +13 -0
- package/lib/testing/fuel-facet.js.map +1 -1
- package/package.json +9 -5
- package/src/aptos/aptos-plugin.ts +38 -32
- package/src/fuel/asset-processor.ts +122 -0
- package/src/fuel/base-processor.ts +16 -21
- package/src/fuel/codegen/codegen.ts +74 -16
- package/src/fuel/context.ts +22 -8
- package/src/fuel/fuel-plugin.ts +16 -33
- package/src/fuel/fuel-processor.ts +32 -22
- package/src/fuel/index.ts +3 -1
- package/src/fuel/network.ts +1 -1
- package/src/fuel/transaction.ts +76 -26
- package/src/fuel/types.ts +23 -0
- package/src/testing/fuel-facet.ts +14 -0
@@ -1,15 +1,19 @@
|
|
1
|
-
import {
|
2
|
-
import { Data_FuelCall, FuelCallFilter, FuelCallHandlerConfig, ProcessResult } from '@sentio/protos'
|
1
|
+
import { Data_FuelCall, FuelCallFilter } from '@sentio/protos'
|
3
2
|
import { FuelCall, FuelContext } from './context.js'
|
4
|
-
import {
|
3
|
+
import { Provider } from '@fuel-ts/account'
|
4
|
+
import { Contract } from '@fuel-ts/program'
|
5
|
+
import { Interface, JsonAbi } from '@fuel-ts/abi-coder'
|
6
|
+
import { bn } from '@fuel-ts/math'
|
5
7
|
import { FuelNetwork, getRpcEndpoint } from './network.js'
|
6
|
-
import {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
import {
|
9
|
+
decodeFuelTransactionWithAbi,
|
10
|
+
DEFAULT_FUEL_FETCH_CONFIG,
|
11
|
+
FuelFetchConfig,
|
12
|
+
FuelTransaction
|
13
|
+
} from './transaction.js'
|
14
|
+
import { CallHandler, FuelBaseProcessor, FuelProcessorState } from './types.js'
|
15
|
+
|
16
|
+
export class FuelProcessor implements FuelBaseProcessor<FuelProcessorConfig> {
|
13
17
|
callHandlers: CallHandler<Data_FuelCall>[] = []
|
14
18
|
|
15
19
|
private provider: Provider
|
@@ -38,9 +42,14 @@ export class FuelProcessor {
|
|
38
42
|
[this.config.address]: this.config.abi
|
39
43
|
}
|
40
44
|
: {}
|
41
|
-
const tx =
|
42
|
-
|
43
|
-
const ctx = new FuelContext(
|
45
|
+
const tx = decodeFuelTransactionWithAbi(call.transaction, abiMap, this.provider)
|
46
|
+
|
47
|
+
const ctx = new FuelContext(
|
48
|
+
this.config.chainId,
|
49
|
+
this.config.address,
|
50
|
+
this.config.name ?? this.config.address,
|
51
|
+
tx
|
52
|
+
)
|
44
53
|
await handler(tx, ctx)
|
45
54
|
return ctx.stopAndGetResult()
|
46
55
|
},
|
@@ -84,16 +93,22 @@ export class FuelProcessor {
|
|
84
93
|
handler: async (call: Data_FuelCall) => {
|
85
94
|
const contract = new Contract(this.config.address, abi, this.provider)
|
86
95
|
const gqlTransaction = call.transaction
|
87
|
-
const tx =
|
88
|
-
|
89
|
-
const ctx = new FuelContext(
|
96
|
+
const tx = decodeFuelTransactionWithAbi(gqlTransaction, { [this.config.address]: abi }, this.provider)
|
97
|
+
|
98
|
+
const ctx = new FuelContext(
|
99
|
+
this.config.chainId,
|
100
|
+
this.config.address,
|
101
|
+
this.config.name ?? this.config.address,
|
102
|
+
tx
|
103
|
+
)
|
90
104
|
for (const op of tx.operations) {
|
91
105
|
for (const call of op.calls || []) {
|
92
106
|
if (names.has(call.functionName)) {
|
93
107
|
const fn = contract.functions[call.functionName]
|
94
108
|
const args = Object.values(call.argumentsProvided || {})
|
95
109
|
const scope = fn(...args)
|
96
|
-
const invocationResult =
|
110
|
+
const invocationResult = new FuelCall(scope, tx, false, call.argumentsProvided, tx.logs)
|
111
|
+
|
97
112
|
await handler(invocationResult, ctx)
|
98
113
|
}
|
99
114
|
}
|
@@ -110,11 +125,6 @@ export class FuelProcessor {
|
|
110
125
|
}
|
111
126
|
}
|
112
127
|
|
113
|
-
export type CallHandler<T> = {
|
114
|
-
handler: (call: T) => Promise<ProcessResult>
|
115
|
-
fetchConfig: Partial<FuelCallHandlerConfig>
|
116
|
-
}
|
117
|
-
|
118
128
|
export type FuelProcessorConfig = {
|
119
129
|
address: string
|
120
130
|
name?: string
|
package/src/fuel/index.ts
CHANGED
@@ -3,4 +3,6 @@ export * from './context.js'
|
|
3
3
|
export * from './fuel-processor.js'
|
4
4
|
export * from './network.js'
|
5
5
|
export * from './transaction.js'
|
6
|
-
export * from './base-processor.js'
|
6
|
+
export * from './base-processor.js'
|
7
|
+
export * from './asset-processor.js'
|
8
|
+
export * from './types.js'
|
package/src/fuel/network.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { FuelChainId } from '@sentio/chain'
|
2
|
-
import { FUEL_BETA_5_NETWORK_URL, FUEL_NETWORK_URL } from '
|
2
|
+
import { FUEL_BETA_5_NETWORK_URL, FUEL_NETWORK_URL } from '@fuel-ts/account/configs'
|
3
3
|
|
4
4
|
export type FuelNetwork = FuelChainId
|
5
5
|
export const FuelNetwork = <const>{
|
package/src/fuel/transaction.ts
CHANGED
@@ -1,13 +1,9 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Provider,
|
8
|
-
TransactionCoder,
|
9
|
-
TransactionSummary
|
10
|
-
} from 'fuels'
|
1
|
+
import { AbiMap, assembleTransactionSummary, processGqlReceipt, Provider, TransactionSummary } from '@fuel-ts/account'
|
2
|
+
import { ReceiptType, TransactionCoder } from '@fuel-ts/transactions'
|
3
|
+
import { bn } from '@fuel-ts/math'
|
4
|
+
import { arrayify } from '@fuel-ts/utils'
|
5
|
+
import { Interface, BigNumberCoder } from '@fuel-ts/abi-coder'
|
6
|
+
import { FuelLog } from './types.js'
|
11
7
|
|
12
8
|
export type FuelFetchConfig = {
|
13
9
|
includeFailed?: boolean
|
@@ -17,27 +13,81 @@ export const DEFAULT_FUEL_FETCH_CONFIG: FuelFetchConfig = {
|
|
17
13
|
includeFailed: false
|
18
14
|
}
|
19
15
|
|
20
|
-
export type FuelTransaction = TransactionSummary
|
16
|
+
export type FuelTransaction = TransactionSummary & {
|
17
|
+
blockNumber?: string
|
18
|
+
logs?: FuelLog[]
|
19
|
+
}
|
20
|
+
|
21
|
+
export function decodeFuelTransaction(gqlTransaction: any, provider: Provider): FuelTransaction {
|
22
|
+
const rawPayload = arrayify(gqlTransaction.rawPayload)
|
23
|
+
|
24
|
+
const [decodedTransaction] = new TransactionCoder().decode(rawPayload, 0)
|
25
|
+
const { gasCosts, maxInputs, gasPerByte, gasPriceFactor } = provider.getChain().consensusParameters
|
26
|
+
const blockNumber = gqlTransaction.status?.block?.header?.height
|
27
|
+
const gqlTransactionStatus = {
|
28
|
+
type: gqlTransaction.status?.__typename,
|
29
|
+
...gqlTransaction.status
|
30
|
+
}
|
31
|
+
return {
|
32
|
+
...assembleTransactionSummary({
|
33
|
+
id: gqlTransaction.id,
|
34
|
+
receipts: [],
|
35
|
+
transaction: decodedTransaction,
|
36
|
+
transactionBytes: rawPayload,
|
37
|
+
gqlTransactionStatus,
|
38
|
+
gasPerByte: bn(gasPerByte),
|
39
|
+
gasPriceFactor: bn(gasPriceFactor),
|
40
|
+
maxInputs,
|
41
|
+
gasCosts
|
42
|
+
}),
|
43
|
+
blockNumber
|
44
|
+
}
|
45
|
+
}
|
21
46
|
|
22
|
-
export function
|
47
|
+
export function decodeFuelTransactionWithAbi(gqlTransaction: any, abiMap: AbiMap, provider: Provider): FuelTransaction {
|
23
48
|
const rawPayload = arrayify(gqlTransaction.rawPayload)
|
24
49
|
|
25
50
|
const [decodedTransaction] = new TransactionCoder().decode(rawPayload, 0)
|
26
51
|
|
27
52
|
const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || []
|
28
53
|
|
29
|
-
const {
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
54
|
+
const { gasCosts, maxInputs, gasPerByte, gasPriceFactor } = provider.getChain().consensusParameters
|
55
|
+
|
56
|
+
const gqlTransactionStatus = {
|
57
|
+
type: gqlTransaction.status?.__typename,
|
58
|
+
...gqlTransaction.status
|
59
|
+
}
|
60
|
+
const blockNumber = gqlTransactionStatus?.block?.header?.height
|
61
|
+
|
62
|
+
const abi = Object.values(abiMap)[0]
|
63
|
+
|
64
|
+
const logs: FuelLog[] = []
|
65
|
+
for (const receipt of receipts) {
|
66
|
+
if (receipt.type === ReceiptType.LogData || receipt.type === ReceiptType.Log) {
|
67
|
+
const interfaceToUse = new Interface(abi)
|
68
|
+
|
69
|
+
const data = receipt.type === ReceiptType.Log ? new BigNumberCoder('u64').encode(receipt.val0) : receipt.data
|
70
|
+
|
71
|
+
const logId = receipt.val1.toNumber()
|
72
|
+
const [decodedLog] = interfaceToUse.decodeLog(data, logId)
|
73
|
+
logs.push({ logId, decodedLog })
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
return {
|
78
|
+
...assembleTransactionSummary({
|
79
|
+
id: gqlTransaction.id,
|
80
|
+
receipts,
|
81
|
+
transaction: decodedTransaction,
|
82
|
+
transactionBytes: rawPayload,
|
83
|
+
gqlTransactionStatus,
|
84
|
+
gasPerByte: bn(gasPerByte),
|
85
|
+
gasPriceFactor: bn(gasPriceFactor),
|
86
|
+
abiMap,
|
87
|
+
maxInputs,
|
88
|
+
gasCosts
|
89
|
+
}),
|
90
|
+
blockNumber,
|
91
|
+
logs
|
92
|
+
}
|
43
93
|
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { ListStateStorage } from '@sentio/runtime'
|
2
|
+
import { Data_FuelCall, FuelAssetHandlerConfig, FuelCallHandlerConfig, ProcessResult } from '@sentio/protos'
|
3
|
+
|
4
|
+
export interface FuelBaseProcessor<T> {
|
5
|
+
configure(): Promise<void>
|
6
|
+
config: T
|
7
|
+
callHandlers: CallHandler<Data_FuelCall>[]
|
8
|
+
}
|
9
|
+
|
10
|
+
export class FuelProcessorState extends ListStateStorage<FuelBaseProcessor<any>> {
|
11
|
+
static INSTANCE = new FuelProcessorState()
|
12
|
+
}
|
13
|
+
|
14
|
+
export type CallHandler<T> = {
|
15
|
+
handler: (call: T) => Promise<ProcessResult>
|
16
|
+
fetchConfig?: Partial<FuelCallHandlerConfig>
|
17
|
+
assetConfig?: Partial<FuelAssetHandlerConfig>
|
18
|
+
}
|
19
|
+
|
20
|
+
export interface FuelLog {
|
21
|
+
logId: number
|
22
|
+
decodedLog: any
|
23
|
+
}
|
@@ -51,6 +51,20 @@ export class FuelFacet {
|
|
51
51
|
res.push(binding)
|
52
52
|
}
|
53
53
|
}
|
54
|
+
for (const assetConfig of config.assetConfigs) {
|
55
|
+
const binding = {
|
56
|
+
data: {
|
57
|
+
fuelCall: {
|
58
|
+
transaction,
|
59
|
+
timestamp: new Date()
|
60
|
+
}
|
61
|
+
},
|
62
|
+
handlerIds: [assetConfig.handlerId],
|
63
|
+
handlerType: HandlerType.FUEL_CALL
|
64
|
+
}
|
65
|
+
|
66
|
+
res.push(binding)
|
67
|
+
}
|
54
68
|
}
|
55
69
|
|
56
70
|
return res
|