@sentio/sdk 1.7.15 → 1.7.18
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/builtin/internal/Weth9.d.ts +221 -0
- package/lib/builtin/internal/Weth9.js +3 -0
- package/lib/builtin/internal/Weth9.js.map +1 -0
- package/lib/builtin/internal/factories/Weth9__factory.d.ts +45 -0
- package/lib/builtin/internal/factories/Weth9__factory.js +297 -0
- package/lib/builtin/internal/factories/Weth9__factory.js.map +1 -0
- package/lib/builtin/internal/factories/index.d.ts +1 -0
- package/lib/builtin/internal/factories/index.js +3 -1
- package/lib/builtin/internal/factories/index.js.map +1 -1
- package/lib/builtin/internal/index.d.ts +2 -0
- package/lib/builtin/internal/index.js +3 -1
- package/lib/builtin/internal/index.js.map +1 -1
- package/lib/builtin/internal/weth9_processor.d.ts +50 -0
- package/lib/builtin/internal/weth9_processor.js +295 -0
- package/lib/builtin/internal/weth9_processor.js.map +1 -0
- package/lib/builtin/weth9/index.d.ts +2 -0
- package/lib/builtin/weth9/index.js +22 -0
- package/lib/builtin/weth9/index.js.map +1 -0
- package/lib/builtin/weth9/test-utils.d.ts +6 -0
- package/lib/builtin/weth9/test-utils.js +57 -0
- package/lib/builtin/weth9/test-utils.js.map +1 -0
- package/lib/cli/build.js +14 -0
- package/lib/cli/build.js.map +1 -1
- package/lib/cli/upload.js +2 -0
- package/lib/cli/upload.js.map +1 -1
- package/lib/loader.d.ts +5 -0
- package/lib/loader.js +30 -0
- package/lib/loader.js.map +1 -0
- package/lib/processor-runner.js +2 -27
- package/lib/processor-runner.js.map +1 -1
- package/lib/service.d.ts +2 -1
- package/lib/service.js +6 -3
- package/lib/service.js.map +1 -1
- package/lib/test/erc20-template.test.js +1 -3
- package/lib/test/erc20-template.test.js.map +1 -1
- package/lib/test/erc20.test.js +1 -3
- package/lib/test/erc20.test.js.map +1 -1
- package/lib/test/generic-processor.test.js +3 -3
- package/lib/test/generic-processor.test.js.map +1 -1
- package/lib/test/solana.test.js +3 -3
- package/lib/test/solana.test.js.map +1 -1
- package/lib/test/test-processor-server.d.ts +1 -1
- package/lib/test/test-processor-server.js +3 -8
- package/lib/test/test-processor-server.js.map +1 -1
- package/package.json +1 -1
- package/src/abis/weth9.json +153 -0
- package/src/builtin/internal/Weth9.ts +480 -0
- package/src/builtin/internal/factories/Weth9__factory.ts +297 -0
- package/src/builtin/internal/factories/index.ts +1 -0
- package/src/builtin/internal/index.ts +2 -0
- package/src/builtin/internal/weth9_processor.ts +403 -0
- package/src/builtin/weth9/index.ts +6 -0
- package/src/builtin/weth9/test-utils.ts +89 -0
- package/src/cli/build.ts +16 -0
- package/src/cli/upload.ts +2 -0
- package/src/loader.ts +24 -0
- package/src/processor-runner.ts +2 -28
- package/src/service.ts +8 -3
- package/src/test/erc20-template.test.ts +1 -3
- package/src/test/erc20.test.ts +1 -3
- package/src/test/generic-processor.test.ts +3 -5
- package/src/test/solana.test.ts +4 -4
- package/src/test/test-processor-server.ts +4 -9
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/* Autogenerated file. Do not edit manually. */
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
import { Log } from "@ethersproject/providers";
|
|
5
|
+
import {
|
|
6
|
+
getWeth9Contract,
|
|
7
|
+
ApprovalEventObject,
|
|
8
|
+
TransferEventObject,
|
|
9
|
+
DepositEventObject,
|
|
10
|
+
WithdrawalEventObject,
|
|
11
|
+
} from ".";
|
|
12
|
+
const mockField = {
|
|
13
|
+
blockHash:
|
|
14
|
+
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
15
|
+
blockNumber: 0,
|
|
16
|
+
logIndex: 0,
|
|
17
|
+
removed: false,
|
|
18
|
+
transactionHash:
|
|
19
|
+
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
20
|
+
transactionIndex: 0,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function mockApprovalLog(
|
|
24
|
+
contractAddress: string,
|
|
25
|
+
event: ApprovalEventObject
|
|
26
|
+
): Log {
|
|
27
|
+
const contract = getWeth9Contract(contractAddress);
|
|
28
|
+
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
|
29
|
+
contract.rawContract.interface.getEvent("Approval"),
|
|
30
|
+
Object.values(event)
|
|
31
|
+
);
|
|
32
|
+
return {
|
|
33
|
+
...mockField,
|
|
34
|
+
address: contractAddress,
|
|
35
|
+
data: encodedLog.data,
|
|
36
|
+
topics: encodedLog.topics,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function mockTransferLog(
|
|
41
|
+
contractAddress: string,
|
|
42
|
+
event: TransferEventObject
|
|
43
|
+
): Log {
|
|
44
|
+
const contract = getWeth9Contract(contractAddress);
|
|
45
|
+
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
|
46
|
+
contract.rawContract.interface.getEvent("Transfer"),
|
|
47
|
+
Object.values(event)
|
|
48
|
+
);
|
|
49
|
+
return {
|
|
50
|
+
...mockField,
|
|
51
|
+
address: contractAddress,
|
|
52
|
+
data: encodedLog.data,
|
|
53
|
+
topics: encodedLog.topics,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function mockDepositLog(
|
|
58
|
+
contractAddress: string,
|
|
59
|
+
event: DepositEventObject
|
|
60
|
+
): Log {
|
|
61
|
+
const contract = getWeth9Contract(contractAddress);
|
|
62
|
+
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
|
63
|
+
contract.rawContract.interface.getEvent("Deposit"),
|
|
64
|
+
Object.values(event)
|
|
65
|
+
);
|
|
66
|
+
return {
|
|
67
|
+
...mockField,
|
|
68
|
+
address: contractAddress,
|
|
69
|
+
data: encodedLog.data,
|
|
70
|
+
topics: encodedLog.topics,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function mockWithdrawalLog(
|
|
75
|
+
contractAddress: string,
|
|
76
|
+
event: WithdrawalEventObject
|
|
77
|
+
): Log {
|
|
78
|
+
const contract = getWeth9Contract(contractAddress);
|
|
79
|
+
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
|
80
|
+
contract.rawContract.interface.getEvent("Withdrawal"),
|
|
81
|
+
Object.values(event)
|
|
82
|
+
);
|
|
83
|
+
return {
|
|
84
|
+
...mockField,
|
|
85
|
+
address: contractAddress,
|
|
86
|
+
data: encodedLog.data,
|
|
87
|
+
topics: encodedLog.topics,
|
|
88
|
+
};
|
|
89
|
+
}
|
package/src/cli/build.ts
CHANGED
|
@@ -42,6 +42,22 @@ export async function codeGenEthersProcessor(
|
|
|
42
42
|
ETHERS_TARGET = path.join(__dirname, '../target-ethers-sentio'),
|
|
43
43
|
outDir = 'src/types/internal'
|
|
44
44
|
) {
|
|
45
|
+
if (!fs.existsSync(abisDir)) {
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let haveJson = false
|
|
50
|
+
const files = fs.readdirSync(abisDir)
|
|
51
|
+
for (const file of files) {
|
|
52
|
+
if (file.toLowerCase().endsWith('.json')) {
|
|
53
|
+
haveJson = true
|
|
54
|
+
break
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (!haveJson) {
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
|
|
45
61
|
// TODO this will fail during postinstall, need to locate real typechain path
|
|
46
62
|
await execStep(
|
|
47
63
|
'yarn typechain --target ' + ETHERS_TARGET + ` --out-dir ${outDir} ${path.join(abisDir, '*.json')}`,
|
package/src/cli/upload.ts
CHANGED
|
@@ -79,6 +79,8 @@ export async function uploadFile(options: SentioProjectConfig, apiKeyOverride: s
|
|
|
79
79
|
if (commitSha) {
|
|
80
80
|
console.log('\t', chalk.blue('Git commit SHA:'), commitSha)
|
|
81
81
|
}
|
|
82
|
+
const { ProjectSlug } = await res.json()
|
|
83
|
+
console.log('\t', chalk.blue('Check status:'), `${options.host}/${ProjectSlug}/datasource`)
|
|
82
84
|
} else {
|
|
83
85
|
console.error(chalk.red('Upload Failed'))
|
|
84
86
|
console.error(chalk.red(await res.text()))
|
package/src/loader.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function load(name: string): { module: any; name: string; path: string } | undefined {
|
|
2
|
+
const req = eval('require')
|
|
3
|
+
|
|
4
|
+
try {
|
|
5
|
+
let path: string
|
|
6
|
+
try {
|
|
7
|
+
path = req.resolve(name, { paths: [process.cwd()] })
|
|
8
|
+
} catch {
|
|
9
|
+
path = req.resolve(name)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const module = { module: req(path), name, path }
|
|
13
|
+
console.log('Load successfully: ', name)
|
|
14
|
+
return module
|
|
15
|
+
} catch (err) {
|
|
16
|
+
if (err instanceof Error && err.message.startsWith(`Cannot find module '${name}'`)) {
|
|
17
|
+
// this error is expected
|
|
18
|
+
console.log("Couldn't load (expected): ", name)
|
|
19
|
+
return undefined
|
|
20
|
+
} else {
|
|
21
|
+
throw err
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/processor-runner.ts
CHANGED
|
@@ -9,35 +9,11 @@ import { setProvider } from './provider'
|
|
|
9
9
|
import path from 'path'
|
|
10
10
|
import fs from 'fs-extra'
|
|
11
11
|
import { ProcessorState } from './processor-state'
|
|
12
|
+
import { load } from './loader'
|
|
12
13
|
|
|
13
14
|
global.sentio_sdk = require('.')
|
|
14
15
|
global.PROCESSOR_STATE = new ProcessorState()
|
|
15
16
|
|
|
16
|
-
function tryRequire(name: string): { module: any; name: string; path: string } | undefined {
|
|
17
|
-
const req = eval('require')
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
let path: string
|
|
21
|
-
try {
|
|
22
|
-
path = req.resolve(name, { paths: [process.cwd()] })
|
|
23
|
-
} catch {
|
|
24
|
-
path = req.resolve(name)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const module = { module: req(path), name, path }
|
|
28
|
-
console.log('Load successfully: ', name)
|
|
29
|
-
return module
|
|
30
|
-
} catch (err) {
|
|
31
|
-
if (err instanceof Error && err.message.startsWith(`Cannot find module '${name}'`)) {
|
|
32
|
-
// this error is expected
|
|
33
|
-
console.log("Couldn't load (expected): ", name)
|
|
34
|
-
return undefined
|
|
35
|
-
} else {
|
|
36
|
-
throw err
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
17
|
const optionDefinitions = [
|
|
42
18
|
{ name: 'target', type: String, defaultOption: true },
|
|
43
19
|
{ name: 'port', alias: 'p', type: String, defaultValue: '4000' },
|
|
@@ -60,8 +36,6 @@ const chainsConfig = fs.readJsonSync(fullPath)
|
|
|
60
36
|
|
|
61
37
|
setProvider(chainsConfig, options.concurrency, options['use-chainserver'])
|
|
62
38
|
|
|
63
|
-
tryRequire(options.target)
|
|
64
|
-
|
|
65
39
|
console.log('Start Server', options)
|
|
66
40
|
|
|
67
41
|
console.log(global.PROCESSOR_STATE.processors.length, ' processors loaded')
|
|
@@ -69,7 +43,7 @@ console.log(global.PROCESSOR_STATE.solanaProcessors.length, ' solana processors
|
|
|
69
43
|
|
|
70
44
|
const server = createServer()
|
|
71
45
|
|
|
72
|
-
const service = new ProcessorServiceImpl(server.shutdown)
|
|
46
|
+
const service = new ProcessorServiceImpl(() => load(options.target), server.shutdown)
|
|
73
47
|
server.add(ProcessorDefinition, service)
|
|
74
48
|
|
|
75
49
|
server.listen('0.0.0.0:' + options.port)
|
package/src/service.ts
CHANGED
|
@@ -40,10 +40,12 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
40
40
|
private started = false
|
|
41
41
|
private contractConfigs: ContractConfig[]
|
|
42
42
|
private templateInstances: TemplateInstance[]
|
|
43
|
+
private readonly loader: () => void
|
|
43
44
|
|
|
44
45
|
private readonly shutdownHandler?: () => void
|
|
45
46
|
|
|
46
|
-
constructor(shutdownHandler?: () => void) {
|
|
47
|
+
constructor(loader: () => void, shutdownHandler?: () => void) {
|
|
48
|
+
this.loader = loader
|
|
47
49
|
this.shutdownHandler = shutdownHandler
|
|
48
50
|
}
|
|
49
51
|
|
|
@@ -151,8 +153,8 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
151
153
|
endBlock: DEFAULT_MAX_BLOCK,
|
|
152
154
|
instructionConfig: {
|
|
153
155
|
innerInstruction: solanaProcessor.processInnerInstruction,
|
|
154
|
-
parsedInstruction: solanaProcessor.fromParsedInstruction
|
|
155
|
-
rawDataInstruction: solanaProcessor.decodeInstruction
|
|
156
|
+
parsedInstruction: solanaProcessor.fromParsedInstruction !== null,
|
|
157
|
+
rawDataInstruction: solanaProcessor.decodeInstruction !== null,
|
|
156
158
|
},
|
|
157
159
|
}
|
|
158
160
|
this.contractConfigs.push(contractConfig)
|
|
@@ -163,6 +165,9 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
163
165
|
if (this.started) {
|
|
164
166
|
return {}
|
|
165
167
|
}
|
|
168
|
+
|
|
169
|
+
this.loader()
|
|
170
|
+
|
|
166
171
|
for (const instance of request.templateInstances) {
|
|
167
172
|
const template = global.PROCESSOR_STATE.templates[instance.templateId]
|
|
168
173
|
if (!template) {
|
|
@@ -7,11 +7,9 @@ import Long from 'long'
|
|
|
7
7
|
import { TestProcessorServer } from './test-processor-server'
|
|
8
8
|
|
|
9
9
|
describe('Test Template', () => {
|
|
10
|
-
const service = new TestProcessorServer()
|
|
10
|
+
const service = new TestProcessorServer(() => require('./erc20-template'))
|
|
11
11
|
|
|
12
12
|
beforeAll(async () => {
|
|
13
|
-
service.setup()
|
|
14
|
-
require('./erc20-template')
|
|
15
13
|
const request: StartRequest = {
|
|
16
14
|
templateInstances: [
|
|
17
15
|
{
|
package/src/test/erc20.test.ts
CHANGED
|
@@ -10,11 +10,9 @@ import { BigNumber } from 'ethers'
|
|
|
10
10
|
import { mockTransferLog } from '../builtin/erc20/test-utils'
|
|
11
11
|
|
|
12
12
|
describe('Test Basic Examples', () => {
|
|
13
|
-
const service = new TestProcessorServer()
|
|
13
|
+
const service = new TestProcessorServer(() => require('./erc20'))
|
|
14
14
|
|
|
15
15
|
beforeAll(async () => {
|
|
16
|
-
service.setup()
|
|
17
|
-
require('./erc20')
|
|
18
16
|
await service.start()
|
|
19
17
|
})
|
|
20
18
|
|
|
@@ -9,11 +9,7 @@ import { TestProcessorServer } from './test-processor-server'
|
|
|
9
9
|
import { firstCounterValue } from './metric-utils'
|
|
10
10
|
|
|
11
11
|
describe('Test Generic Processor', () => {
|
|
12
|
-
const service = new TestProcessorServer()
|
|
13
|
-
|
|
14
|
-
beforeAll(async () => {
|
|
15
|
-
service.setup()
|
|
16
|
-
|
|
12
|
+
const service = new TestProcessorServer(() => {
|
|
17
13
|
GenericProcessor.bind(
|
|
18
14
|
[
|
|
19
15
|
'event Transfer(address indexed from, address indexed to, uint256 value)',
|
|
@@ -29,7 +25,9 @@ describe('Test Generic Processor', () => {
|
|
|
29
25
|
}).onAllEvents(function (log, ctx) {
|
|
30
26
|
ctx.meter.Counter('wallet').add(1)
|
|
31
27
|
})
|
|
28
|
+
})
|
|
32
29
|
|
|
30
|
+
beforeAll(async () => {
|
|
33
31
|
await service.start()
|
|
34
32
|
})
|
|
35
33
|
|
package/src/test/solana.test.ts
CHANGED
|
@@ -10,12 +10,12 @@ import { TestProcessorServer } from './test-processor-server'
|
|
|
10
10
|
import { firstCounterValue } from './metric-utils'
|
|
11
11
|
|
|
12
12
|
describe('Test Solana Example', () => {
|
|
13
|
-
const service = new TestProcessorServer()
|
|
14
|
-
|
|
15
|
-
beforeAll(async () => {
|
|
16
|
-
await service.setup()
|
|
13
|
+
const service = new TestProcessorServer(() => {
|
|
17
14
|
require('./mirrorworld')
|
|
18
15
|
require('./wormhole-token-bridge')
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
beforeAll(async () => {
|
|
19
19
|
await service.start({ templateInstances: [] })
|
|
20
20
|
})
|
|
21
21
|
|
|
@@ -33,11 +33,13 @@ function cleanTest() {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
36
|
-
service
|
|
36
|
+
service: ProcessorServiceImpl
|
|
37
37
|
contractConfig: ContractConfig[]
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
constructor(loader: () => void, httpEndpoints: Record<string, string> = {}) {
|
|
40
40
|
cleanTest()
|
|
41
|
+
|
|
42
|
+
this.service = new ProcessorServiceImpl(loader)
|
|
41
43
|
const dummyConfig: Record<string, ChainConfig> = {}
|
|
42
44
|
|
|
43
45
|
for (const k in CHAIN_MAP) {
|
|
@@ -49,13 +51,6 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
setProvider(dummyConfig)
|
|
52
|
-
|
|
53
|
-
// if (!Array.isArray(processorPath)) {
|
|
54
|
-
// processorPath = [processorPath]
|
|
55
|
-
// }
|
|
56
|
-
// for (const path of processorPath) {
|
|
57
|
-
// require(path)
|
|
58
|
-
// }
|
|
59
54
|
}
|
|
60
55
|
|
|
61
56
|
async start(request: StartRequest = { templateInstances: [] }, context = TEST_CONTEXT): Promise<Empty> {
|