Skip to content

Commit

Permalink
chore(fuel): add fuel template files (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacedragon authored May 31, 2024
1 parent 023fd16 commit 40cd115
Show file tree
Hide file tree
Showing 8 changed files with 388 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/cli/src/commands/run-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export async function runCreate(argv: string[]) {
break
case 'solana':
break
case 'fuel':
break
default:
console.error(chalk.red('non supported chain-type for template creation, use --help for more information.'))
console.log(usage)
Expand Down
272 changes: 272 additions & 0 deletions packages/cli/templates/fuel/abis/fuel/counter-contract-abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
{
"encoding": "1",
"types": [
{
"typeId": 0,
"type": "()",
"components": [],
"typeParameters": null
},
{
"typeId": 1,
"type": "b256",
"components": null,
"typeParameters": null
},
{
"typeId": 2,
"type": "bool",
"components": null,
"typeParameters": null
},
{
"typeId": 3,
"type": "enum ColorError",
"components": [
{
"name": "Blue",
"type": 0,
"typeArguments": null
},
{
"name": "Green",
"type": 0,
"typeArguments": null
},
{
"name": "Red",
"type": 0,
"typeArguments": null
},
{
"name": "Other",
"type": 0,
"typeArguments": null
}
],
"typeParameters": null
},
{
"typeId": 4,
"type": "enum Option",
"components": [
{
"name": "None",
"type": 0,
"typeArguments": null
},
{
"name": "Some",
"type": 7,
"typeArguments": null
}
],
"typeParameters": [7]
},
{
"typeId": 5,
"type": "enum Result",
"components": [
{
"name": "Ok",
"type": 7,
"typeArguments": null
},
{
"name": "Err",
"type": 6,
"typeArguments": null
}
],
"typeParameters": [7, 6]
},
{
"typeId": 6,
"type": "generic E",
"components": null,
"typeParameters": null
},
{
"typeId": 7,
"type": "generic T",
"components": null,
"typeParameters": null
},
{
"typeId": 8,
"type": "str[1]",
"components": null,
"typeParameters": null
},
{
"typeId": 9,
"type": "str[25]",
"components": null,
"typeParameters": null
},
{
"typeId": 10,
"type": "struct Foo",
"components": [
{
"name": "bar",
"type": 12,
"typeArguments": null
},
{
"name": "baz",
"type": 2,
"typeArguments": null
}
],
"typeParameters": null
},
{
"typeId": 11,
"type": "u32",
"components": null,
"typeParameters": null
},
{
"typeId": 12,
"type": "u64",
"components": null,
"typeParameters": null
}
],
"functions": [
{
"inputs": [
{
"name": "foo",
"type": 10,
"typeArguments": null
},
{
"name": "option",
"type": 4,
"typeArguments": [
{
"name": "",
"type": 8,
"typeArguments": null
}
]
}
],
"name": "complex",
"output": {
"name": "",
"type": 5,
"typeArguments": [
{
"name": "",
"type": 10,
"typeArguments": null
},
{
"name": "",
"type": 3,
"typeArguments": null
}
]
},
"attributes": [
{
"name": "storage",
"arguments": ["read", "write"]
}
]
},
{
"inputs": [],
"name": "count",
"output": {
"name": "",
"type": 12,
"typeArguments": null
},
"attributes": [
{
"name": "storage",
"arguments": ["read"]
}
]
},
{
"inputs": [
{
"name": "add",
"type": 11,
"typeArguments": null
},
{
"name": "two",
"type": 12,
"typeArguments": null
},
{
"name": "three",
"type": 1,
"typeArguments": null
}
],
"name": "increment",
"output": {
"name": "",
"type": 12,
"typeArguments": null
},
"attributes": [
{
"name": "storage",
"arguments": ["read", "write"]
}
]
}
],
"loggedTypes": [
{
"logId": "1515152261580153489",
"loggedType": {
"name": "",
"type": 12,
"typeArguments": null
}
},
{
"logId": "9006093109815063660",
"loggedType": {
"name": "",
"type": 10,
"typeArguments": []
}
},
{
"logId": "14631882454972838106",
"loggedType": {
"name": "",
"type": 9,
"typeArguments": null
}
},
{
"logId": "15520703124961489725",
"loggedType": {
"name": "",
"type": 11,
"typeArguments": null
}
},
{
"logId": "8961848586872524460",
"loggedType": {
"name": "",
"type": 1,
"typeArguments": null
}
}
],
"messagesTypes": [],
"configurables": []
}
19 changes: 19 additions & 0 deletions packages/cli/templates/fuel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"private": true,
"name": "template-fuel",
"version": "1.0.0",
"type": "module",
"scripts": {
"build": "sentio build",
"gen": "sentio gen",
"test": "sentio test",
"upload": "sentio upload"
},
"dependencies": {
"@sentio/sdk": "workspace:*"
},
"devDependencies": {
"@sentio/cli": "workspace:*",
"typescript": "^5.4.5"
}
}
2 changes: 2 additions & 0 deletions packages/cli/templates/fuel/sentio.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
project: fuel-counter
host: http://localhost:10000
14 changes: 14 additions & 0 deletions packages/cli/templates/fuel/src/processor.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { TestProcessorServer } from '@sentio/sdk/testing'

describe('Test Processor', () => {
const service = new TestProcessorServer(async () => await import('./processor.js'))

beforeAll(async () => {
await service.start()
})

test('has config', async () => {
const config = await service.getConfig({})
expect(config.contractConfigs.length > 0)
})
})
58 changes: 58 additions & 0 deletions packages/cli/templates/fuel/src/processor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { LogLevel } from '@sentio/sdk'
import { FuelProcessor, FuelNetwork } from '@sentio/sdk/fuel'

import abi from '../abis/fuel/counter-contract-abi.json'
import { CounterContractProcessor } from './types/fuel/CounterContractProcessor.js'

FuelProcessor.bind({
address: '0xa14f85860d6ce99154ecbb13570ba5fba1d8dc16b290de13f036b016fd19a29c',
chainId: FuelNetwork.TEST_NET,
abi
})
.onTransaction(
async (tx, ctx) => {
ctx.eventLogger.emit('transaction', {
distinctId: tx.id,
message: 'Transaction processed',
properties: {
fee: tx.fee.toNumber()
},
severity: tx.status === 'success' ? LogLevel.INFO : LogLevel.ERROR
})
},
{ includeFailed: true }
)
.onCall('increment', async (call, ctx) => {
const args = call.functionScopes[0]?.getCallConfig()?.args as any[]
ctx.eventLogger.emit('increment', {
distinctId: ctx.transaction?.id,
message: 'increment',
properties: {
arg0: String(args[0]),
arg1: String(args[1]),
arg2: String(args[2]),
ret: String(call.value)
},
severity: ctx.transaction?.status === 'success' ? LogLevel.INFO : LogLevel.ERROR
})
})

CounterContractProcessor.bind({
address: '0xa14f85860d6ce99154ecbb13570ba5fba1d8dc16b290de13f036b016fd19a29c',
chainId: FuelNetwork.TEST_NET
}).onCallComplex(async (call, ctx) => {
const [arg1, arg2] = call.args
const { Ok, Err } = call.returnValue
ctx.eventLogger.emit('increment', {
distinctId: ctx.transaction?.id,
message: 'complex',
properties: {
baz: arg1.baz,
bar: arg1.bar,
arg2: arg2,
ret: String(Ok),
error: Err
},
severity: ctx.transaction?.status === 'success' ? LogLevel.INFO : LogLevel.ERROR
})
}, {})
8 changes: 8 additions & 0 deletions packages/cli/templates/fuel/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"exclude": ["dist", "jest.config.ts"],
"extends": "../../tsconfig.json"
}
Loading

0 comments on commit 40cd115

Please sign in to comment.