@sentio/sdk 2.36.0-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/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/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
| @@ -15,7 +15,22 @@ export async function codegen(abisDir: string, outDir: string) { | |
| 15 15 | 
             
            }
         | 
| 16 16 |  | 
| 17 17 | 
             
            function patchImport(contents: string) {
         | 
| 18 | 
            -
              return contents | 
| 18 | 
            +
              return contents
         | 
| 19 | 
            +
                .replace(
         | 
| 20 | 
            +
                  `import { Interface, Contract, ContractFactory } from "fuels";`,
         | 
| 21 | 
            +
                  `import { Contract, } from "@fuel-ts/program";
         | 
| 22 | 
            +
            import { ContractFactory } from "@fuel-ts/contract";
         | 
| 23 | 
            +
            import { Interface } from "@fuel-ts/abi-coder";`
         | 
| 24 | 
            +
                )
         | 
| 25 | 
            +
                .replace(
         | 
| 26 | 
            +
                  `import type { Provider, Account, AbstractAddress, BytesLike, DeployContractOptions, StorageSlot } from "fuels";
         | 
| 27 | 
            +
            `,
         | 
| 28 | 
            +
                  `import type { Provider, Account } from "@fuel-ts/account";
         | 
| 29 | 
            +
            import type { AbstractAddress, BytesLike } from "@fuel-ts/interfaces";
         | 
| 30 | 
            +
            import type { DeployContractOptions } from "@fuel-ts/contract";
         | 
| 31 | 
            +
            import type { StorageSlot } from "@fuel-ts/transactions";`
         | 
| 32 | 
            +
                )
         | 
| 33 | 
            +
                .replace(/from\s+['"](\..+)['"]/g, `from '\$1.js'`)
         | 
| 19 34 | 
             
            }
         | 
| 20 35 |  | 
| 21 36 | 
             
            function patchEnumType(contents: string) {
         | 
| @@ -65,38 +80,63 @@ async function codegenInternal(abisDir: string, outDir: string): Promise<number> | |
| 65 80 |  | 
| 66 81 | 
             
              mkdirp.sync(outDir)
         | 
| 67 82 | 
             
              mkdirp.sync(path.join(outDir, 'factories'))
         | 
| 68 | 
            -
             | 
| 83 | 
            +
              let count = 0
         | 
| 69 84 | 
             
              abiTypeGen.files.forEach((file) => {
         | 
| 70 85 | 
             
                if (!file.path.endsWith('.hex.ts')) {
         | 
| 71 86 | 
             
                  let content = patchImport(file.contents)
         | 
| 72 87 | 
             
                  content = patchEnumType(content)
         | 
| 73 88 | 
             
                  writeFileSync(file.path, content)
         | 
| 89 | 
            +
                  count++
         | 
| 74 90 | 
             
                }
         | 
| 75 91 | 
             
              })
         | 
| 76 92 |  | 
| 93 | 
            +
              // for (const file of abiTypeGen.files) {
         | 
| 94 | 
            +
              //   const jsonAbi: JsonAbi = JSON.parse(file.contents)
         | 
| 95 | 
            +
              //   for (const logType of jsonAbi.loggedTypes) {
         | 
| 96 | 
            +
              //     logType.loggedType.name
         | 
| 97 | 
            +
              //
         | 
| 98 | 
            +
              //   }
         | 
| 99 | 
            +
              // }
         | 
| 100 | 
            +
             | 
| 77 101 | 
             
              for (const abi of abiTypeGen.abis) {
         | 
| 78 102 | 
             
                const name = abi.name.endsWith('Abi') ? abi.name.slice(0, -3) : abi.name
         | 
| 79 103 | 
             
                const filePath = path.join(outDir, `${name}Processor.ts`)
         | 
| 80 104 | 
             
                const importedTypes = collectImportedTypes(abi.types)
         | 
| 81 105 |  | 
| 106 | 
            +
                const logTypes: Record<string, string> = {}
         | 
| 107 | 
            +
                for (const logType of abi.rawContents.loggedTypes) {
         | 
| 108 | 
            +
                  // @ts-ignore - we know that the type is in the abi
         | 
| 109 | 
            +
                  const t = abi.types.find((t) => t.rawAbiType.typeId == logType.loggedType?.type)
         | 
| 110 | 
            +
                  // @ts-ignore - we know that the type is in the abi
         | 
| 111 | 
            +
                  logTypes[logType.logId] = t?.attributes?.outputLabel
         | 
| 112 | 
            +
                }
         | 
| 113 | 
            +
             | 
| 82 114 | 
             
                const content = `/* Autogenerated file. Do not edit manually. */
         | 
| 83 115 |  | 
| 84 116 | 
             
            /* tslint:disable */
         | 
| 85 117 | 
             
            /* eslint-disable */
         | 
| 86 118 |  | 
| 87 | 
            -
            import { FuelAbstractProcessor, FuelContext, FuelProcessorConfig, TypedCall, FuelFetchConfig} from '@sentio/sdk/fuel'
         | 
| 119 | 
            +
            import { FuelAbstractProcessor, FuelContext, FuelProcessorConfig, TypedCall, FuelFetchConfig, FuelCall} from '@sentio/sdk/fuel'
         | 
| 88 120 | 
             
            import {${abi.name}__factory } from './factories/${abi.name}__factory.js'
         | 
| 89 121 | 
             
            import {${abi.commonTypesInUse.join(',')}} from './common.js'
         | 
| 90 122 | 
             
            import {${importedTypes.join(',')}} from './${abi.name}.js'
         | 
| 91 123 |  | 
| 92 | 
            -
            import type {
         | 
| 93 | 
            -
             | 
| 94 | 
            -
              BN,
         | 
| 95 | 
            -
              BytesLike,
         | 
| 96 | 
            -
            } from 'fuels';
         | 
| 124 | 
            +
            import type { BigNumberish, BN } from '@fuel-ts/math';
         | 
| 125 | 
            +
            import type { BytesLike } from '@fuel-ts/interfaces';
         | 
| 97 126 |  | 
| 98 127 |  | 
| 99 128 | 
             
            namespace ${name} {
         | 
| 129 | 
            +
              export abstract class CallWithLogs<T extends Array<any>, R> extends TypedCall<T, R> {
         | 
| 130 | 
            +
            ${Object.entries(logTypes)
         | 
| 131 | 
            +
              .map(
         | 
| 132 | 
            +
                ([k, v]) =>
         | 
| 133 | 
            +
                  `   getLog${k}(): Array<${v}>  {
         | 
| 134 | 
            +
                  return this.logs?.filter(l => l.logId == ${k})?.map(l => l.decodedLog) as Array<${v}>
         | 
| 135 | 
            +
                }`
         | 
| 136 | 
            +
              )
         | 
| 137 | 
            +
              .join('\n')}
         | 
| 138 | 
            +
              }
         | 
| 139 | 
            +
             | 
| 100 140 | 
             
            ${abi.functions.map(genCallType).join('\n')}
         | 
| 101 141 | 
             
            }
         | 
| 102 142 |  | 
| @@ -105,25 +145,43 @@ export class ${name}Processor extends FuelAbstractProcessor { | |
| 105 145 | 
             
                super(${abi.name}__factory.abi, config)
         | 
| 106 146 | 
             
              }
         | 
| 107 147 |  | 
| 108 | 
            -
              static bind(config | 
| 109 | 
            -
                return new ${name}Processor( | 
| 148 | 
            +
              static bind(config: FuelProcessorConfig) {
         | 
| 149 | 
            +
                return new ${name}Processor({
         | 
| 150 | 
            +
                  name: '${name}',
         | 
| 151 | 
            +
                  ...config,
         | 
| 152 | 
            +
                })
         | 
| 110 153 | 
             
              }
         | 
| 111 154 |  | 
| 112 155 | 
             
            ${abi.functions.map((f) => genOnCallFunction(name, f)).join('\n')}   
         | 
| 113 156 | 
             
            }
         | 
| 114 157 | 
             
            `
         | 
| 115 158 | 
             
                writeFileSync(filePath, content)
         | 
| 159 | 
            +
                count++
         | 
| 116 160 | 
             
              }
         | 
| 117 161 |  | 
| 118 | 
            -
              return  | 
| 162 | 
            +
              return count
         | 
| 119 163 | 
             
            }
         | 
| 120 164 |  | 
| 121 165 | 
             
            function genCallType(f: IFunction) {
         | 
| 122 166 | 
             
              const name = upperFirst(f.name)
         | 
| 167 | 
            +
              const argMap: Record<string, string> = {}
         | 
| 168 | 
            +
              const argTypes = f.attributes.inputs.split(',').map((t) => t.trim())
         | 
| 169 | 
            +
              f.rawAbiFunction.inputs.forEach((input, idx) => {
         | 
| 170 | 
            +
                argMap[input.name] = argTypes[idx]
         | 
| 171 | 
            +
              })
         | 
| 172 | 
            +
             | 
| 123 173 | 
             
              return `
         | 
| 124 | 
            -
              export  | 
| 125 | 
            -
                  args: [${ | 
| 126 | 
            -
                  returnValue: ${f.attributes.output}
         | 
| 174 | 
            +
              export class ${name}Call extends CallWithLogs<[${argTypes.join(', ')}], ${f.attributes.output}> {
         | 
| 175 | 
            +
                  declare args: [${argTypes.join(', ')}]
         | 
| 176 | 
            +
                  declare returnValue: ${f.attributes.output}
         | 
| 177 | 
            +
                  declare argsObject: {
         | 
| 178 | 
            +
                      ${Object.entries(argMap)
         | 
| 179 | 
            +
                        .map(([k, v]) => `${k}: ${v}`)
         | 
| 180 | 
            +
                        .join(', ')}
         | 
| 181 | 
            +
                  } 
         | 
| 182 | 
            +
                  constructor(call: FuelCall) {
         | 
| 183 | 
            +
                    super(call)
         | 
| 184 | 
            +
                  }
         | 
| 127 185 | 
             
              }
         | 
| 128 186 | 
             
            `
         | 
| 129 187 | 
             
            }
         | 
| @@ -131,8 +189,8 @@ function genCallType(f: IFunction) { | |
| 131 189 | 
             
            function genOnCallFunction(contractName: string, f: IFunction) {
         | 
| 132 190 | 
             
              const name = upperFirst(f.name)
         | 
| 133 191 | 
             
              return `
         | 
| 134 | 
            -
              onCall${name}(handler: (call: ${contractName}.${name}Call, ctx: FuelContext) => void | Promise<void>, config | 
| 135 | 
            -
                  super. | 
| 192 | 
            +
              onCall${name}(handler: (call: ${contractName}.${name}Call, ctx: FuelContext) => void | Promise<void>, config?: FuelFetchConfig) {
         | 
| 193 | 
            +
                  super.onCall('${f.name}', (call, ctx) => handler(new ${contractName}.${name}Call(call), ctx), config)
         | 
| 136 194 | 
             
              }`
         | 
| 137 195 | 
             
            }
         | 
| 138 196 |  | 
    
        package/src/fuel/context.ts
    CHANGED
    
    | @@ -1,15 +1,29 @@ | |
| 1 1 | 
             
            import { BaseContext, Labels, normalizeLabels } from '../core/index.js'
         | 
| 2 2 | 
             
            import { ChainId } from '@sentio/chain'
         | 
| 3 3 | 
             
            import { RecordMetaData } from '@sentio/protos'
         | 
| 4 | 
            -
            import { InvocationCallResult } from ' | 
| 4 | 
            +
            import { InvocationCallResult, InvocationScopeLike } from '@fuel-ts/program'
         | 
| 5 5 | 
             
            import { FuelTransaction } from './transaction.js'
         | 
| 6 | 
            +
            import type { CallResult } from '@fuel-ts/account'
         | 
| 7 | 
            +
            import { FuelLog } from './types.js'
         | 
| 6 8 |  | 
| 7 | 
            -
            export  | 
| 9 | 
            +
            export class FuelCall extends InvocationCallResult {
         | 
| 10 | 
            +
              constructor(
         | 
| 11 | 
            +
                funcScopes: InvocationScopeLike | Array<InvocationScopeLike>,
         | 
| 12 | 
            +
                callResult: CallResult,
         | 
| 13 | 
            +
                isMultiCall: boolean,
         | 
| 14 | 
            +
                readonly args?: Record<string, any>,
         | 
| 15 | 
            +
                readonly logs?: FuelLog[]
         | 
| 16 | 
            +
              ) {
         | 
| 17 | 
            +
                super(funcScopes, callResult, isMultiCall)
         | 
| 18 | 
            +
              }
         | 
| 19 | 
            +
            }
         | 
| 8 20 |  | 
| 9 21 | 
             
            export class FuelContext extends BaseContext {
         | 
| 10 22 | 
             
              constructor(
         | 
| 11 | 
            -
                readonly  | 
| 12 | 
            -
                readonly  | 
| 23 | 
            +
                readonly chainId: ChainId,
         | 
| 24 | 
            +
                readonly contractAddress: string,
         | 
| 25 | 
            +
                readonly contractName: string,
         | 
| 26 | 
            +
                readonly transaction: FuelTransaction | null
         | 
| 13 27 | 
             
              ) {
         | 
| 14 28 | 
             
                super({})
         | 
| 15 29 | 
             
              }
         | 
| @@ -20,14 +34,14 @@ export class FuelContext extends BaseContext { | |
| 20 34 |  | 
| 21 35 | 
             
              protected getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
         | 
| 22 36 | 
             
                return {
         | 
| 23 | 
            -
                  address: this. | 
| 24 | 
            -
                  contractName: this. | 
| 25 | 
            -
                  blockNumber:  | 
| 37 | 
            +
                  address: this.contractAddress,
         | 
| 38 | 
            +
                  contractName: this.contractName,
         | 
| 39 | 
            +
                  blockNumber: BigInt(this.transaction?.blockNumber || 0),
         | 
| 26 40 | 
             
                  transactionIndex: 0,
         | 
| 27 41 | 
             
                  transactionHash: this.transaction?.id || '', // TODO
         | 
| 28 42 | 
             
                  chainId: this.getChainId(),
         | 
| 29 43 | 
             
                  name: name,
         | 
| 30 | 
            -
                  logIndex:  | 
| 44 | 
            +
                  logIndex: -1,
         | 
| 31 45 | 
             
                  labels: normalizeLabels(labels)
         | 
| 32 46 | 
             
                }
         | 
| 33 47 | 
             
              }
         | 
    
        package/src/fuel/fuel-plugin.ts
    CHANGED
    
    | @@ -10,9 +10,10 @@ import { | |
| 10 10 | 
             
            } from '@sentio/protos'
         | 
| 11 11 |  | 
| 12 12 | 
             
            import { ServerError, Status } from 'nice-grpc'
         | 
| 13 | 
            -
            import { GlobalProcessorState } from '../eth/base-processor.js'
         | 
| 14 13 | 
             
            import { TemplateInstanceState } from '../core/template.js'
         | 
| 15 | 
            -
            import {  | 
| 14 | 
            +
            import { FuelAssetProcessor } from './asset-processor.js'
         | 
| 15 | 
            +
            import { FuelProcessorState } from './types.js'
         | 
| 16 | 
            +
            import { FuelProcessor } from './fuel-processor.js'
         | 
| 16 17 |  | 
| 17 18 | 
             
            interface Handlers {
         | 
| 18 19 | 
             
              callHandlers: ((trace: Data_FuelCall) => Promise<ProcessResult>)[]
         | 
| @@ -36,58 +37,40 @@ export class FuelPlugin extends Plugin { | |
| 36 37 | 
             
                    contract: {
         | 
| 37 38 | 
             
                      name: processor.config.name,
         | 
| 38 39 | 
             
                      chainId: processor.config.chainId.toString(),
         | 
| 39 | 
            -
                      address: processor.config.address,
         | 
| 40 | 
            +
                      address: processor.config.address || '*',
         | 
| 40 41 | 
             
                      abi: ''
         | 
| 41 42 | 
             
                    },
         | 
| 42 43 | 
             
                    startBlock: processor.config.startBlock,
         | 
| 43 44 | 
             
                    endBlock: processor.config.endBlock
         | 
| 44 45 | 
             
                  })
         | 
| 45 | 
            -
             | 
| 46 46 | 
             
                  for (const callHandler of processor.callHandlers) {
         | 
| 47 47 | 
             
                    const handlerId = handlers.callHandlers.push(callHandler.handler) - 1
         | 
| 48 | 
            -
                     | 
| 49 | 
            -
                       | 
| 50 | 
            -
             | 
| 48 | 
            +
                    if (processor instanceof FuelProcessor) {
         | 
| 49 | 
            +
                      const fetchConfig = {
         | 
| 50 | 
            +
                        handlerId,
         | 
| 51 | 
            +
                        filters: callHandler.fetchConfig?.filters || []
         | 
| 52 | 
            +
                      }
         | 
| 53 | 
            +
                      contractConfig.fuelCallConfigs.push(fetchConfig)
         | 
| 54 | 
            +
                    } else if (processor instanceof FuelAssetProcessor) {
         | 
| 55 | 
            +
                      const assetConfig = callHandler.assetConfig
         | 
| 56 | 
            +
                      contractConfig.assetConfigs.push({
         | 
| 57 | 
            +
                        filters: assetConfig?.filters || [],
         | 
| 58 | 
            +
                        handlerId
         | 
| 59 | 
            +
                      })
         | 
| 51 60 | 
             
                    }
         | 
| 52 | 
            -
                    contractConfig.fuelCallConfigs.push(fetchConfig)
         | 
| 53 61 | 
             
                  }
         | 
| 54 62 |  | 
| 55 63 | 
             
                  // Finish up a contract
         | 
| 56 64 | 
             
                  config.contractConfigs.push(contractConfig)
         | 
| 57 65 | 
             
                }
         | 
| 58 66 |  | 
| 59 | 
            -
                for (const processor of GlobalProcessorState.INSTANCE.getValues()) {
         | 
| 60 | 
            -
                  const chainId = processor.getChainId()
         | 
| 61 | 
            -
             | 
| 62 | 
            -
                  const contractConfig = ContractConfig.fromPartial({
         | 
| 63 | 
            -
                    processorType: USER_PROCESSOR,
         | 
| 64 | 
            -
                    contract: {
         | 
| 65 | 
            -
                      name: processor.config.name,
         | 
| 66 | 
            -
                      chainId: chainId.toString(),
         | 
| 67 | 
            -
                      address: processor.config.address, // can only be *
         | 
| 68 | 
            -
                      abi: ''
         | 
| 69 | 
            -
                    },
         | 
| 70 | 
            -
                    startBlock: processor.config.startBlock,
         | 
| 71 | 
            -
                    endBlock: processor.config.endBlock
         | 
| 72 | 
            -
                  })
         | 
| 73 | 
            -
             | 
| 74 | 
            -
                  config.contractConfigs.push(contractConfig)
         | 
| 75 | 
            -
                }
         | 
| 76 | 
            -
             | 
| 77 67 | 
             
                this.handlers = handlers
         | 
| 78 68 | 
             
              }
         | 
| 79 69 |  | 
| 80 70 | 
             
              supportedHandlers = [HandlerType.FUEL_CALL]
         | 
| 81 71 |  | 
| 82 72 | 
             
              processBinding(request: DataBinding): Promise<ProcessResult> {
         | 
| 83 | 
            -
                // return Promise.resolve(undefined);
         | 
| 84 73 | 
             
                switch (request.handlerType) {
         | 
| 85 | 
            -
                  // case HandlerType.FUEL_LOG:
         | 
| 86 | 
            -
                  //   return this.processLog(request)
         | 
| 87 | 
            -
                  // case HandlerType.FUEL_TRACE:
         | 
| 88 | 
            -
                  //   return this.processTrace(request)
         | 
| 89 | 
            -
                  // case HandlerType.FUEL_BLOCK:
         | 
| 90 | 
            -
                  //   return this.processBlock(request)
         | 
| 91 74 | 
             
                  case HandlerType.FUEL_CALL:
         | 
| 92 75 | 
             
                    return this.processTransaction(request)
         | 
| 93 76 | 
             
                  default:
         | 
| @@ -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
         |