@sentio/sdk 0.1.2 → 0.1.5
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/dist/cli/build.js +2 -2
- package/dist/cli/build.js.map +1 -1
- package/dist/cli/cli.js +1 -1
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/upload.js +8 -0
- package/dist/cli/upload.js.map +1 -1
- package/dist/cli/webpack.config.js +2 -1
- package/dist/context.d.ts +7 -0
- package/dist/context.js +12 -1
- package/dist/context.js.map +1 -1
- package/dist/gen/processor/protos/processor.d.ts +68 -0
- package/dist/gen/processor/protos/processor.js +281 -2
- package/dist/gen/processor/protos/processor.js.map +1 -1
- package/dist/meter.d.ts +4 -4
- package/dist/meter.js +30 -16
- package/dist/meter.js.map +1 -1
- package/dist/processor_server.js +2 -0
- package/dist/processor_server.js.map +1 -1
- package/dist/service.d.ts +2 -1
- package/dist/service.js +74 -1
- package/dist/service.js.map +1 -1
- package/dist/solana_processor.d.ts +25 -0
- package/dist/solana_processor.js +84 -0
- package/dist/solana_processor.js.map +1 -0
- package/dist/test_case/mirrorworld.d.ts +4 -0
- package/dist/test_case/mirrorworld.js +89 -0
- package/dist/test_case/mirrorworld.js.map +1 -0
- package/package.json +9 -3
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SolanaBaseProcessor = void 0;
|
|
7
|
+
const context_1 = require("./context");
|
|
8
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
9
|
+
const long_1 = __importDefault(require("long"));
|
|
10
|
+
class SolanaBaseProcessor {
|
|
11
|
+
transactionHandlers = [];
|
|
12
|
+
instructionHandlers = [];
|
|
13
|
+
address;
|
|
14
|
+
endpoint;
|
|
15
|
+
connection;
|
|
16
|
+
contractName;
|
|
17
|
+
config = { startSlot: new long_1.default(0) };
|
|
18
|
+
constructor(contractName, address, endpoint) {
|
|
19
|
+
this.endpoint = endpoint;
|
|
20
|
+
this.address = address;
|
|
21
|
+
if (!globalThis.SolanaProcessors) {
|
|
22
|
+
globalThis.SolanaProcessors = [];
|
|
23
|
+
}
|
|
24
|
+
globalThis.SolanaProcessors.push(this);
|
|
25
|
+
this.connection = new web3_js_1.Connection(endpoint, 'confirmed');
|
|
26
|
+
this.contractName = contractName;
|
|
27
|
+
}
|
|
28
|
+
bind(address) {
|
|
29
|
+
this.address = address;
|
|
30
|
+
}
|
|
31
|
+
onTransaction(handler) {
|
|
32
|
+
if (!this.isBind()) {
|
|
33
|
+
throw new Error("Processor doesn't bind to an address");
|
|
34
|
+
}
|
|
35
|
+
this.transactionHandlers.push(async (transaction) => {
|
|
36
|
+
const ctx = new context_1.SolanaContext(this.address);
|
|
37
|
+
const parsedTransaction = await this.connection.getParsedTransaction(transaction.txHash);
|
|
38
|
+
if (parsedTransaction != null) {
|
|
39
|
+
await handler(parsedTransaction, ctx);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
histograms: ctx.histograms,
|
|
43
|
+
counters: ctx.counters,
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
onInstruction(handler) {
|
|
49
|
+
if (!this.isBind()) {
|
|
50
|
+
throw new Error("Processor doesn't bind to an address");
|
|
51
|
+
}
|
|
52
|
+
this.instructionHandlers.push(async (ins) => {
|
|
53
|
+
const ctx = new context_1.SolanaContext(this.address);
|
|
54
|
+
// const parsedTransaction = await this.connection.getParsedTransaction(ins)
|
|
55
|
+
if (ins != null) {
|
|
56
|
+
await handler(ins, ctx);
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
histograms: ctx.histograms,
|
|
60
|
+
counters: ctx.counters,
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
isBind() {
|
|
66
|
+
return this.address != null;
|
|
67
|
+
}
|
|
68
|
+
startSlot(startSlot) {
|
|
69
|
+
if (typeof startSlot === 'number') {
|
|
70
|
+
startSlot = long_1.default.fromNumber(startSlot);
|
|
71
|
+
}
|
|
72
|
+
this.config.startSlot = startSlot;
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
endBlock(endBlock) {
|
|
76
|
+
if (typeof endBlock === 'number') {
|
|
77
|
+
endBlock = long_1.default.fromNumber(endBlock);
|
|
78
|
+
}
|
|
79
|
+
this.config.endSlot = endBlock;
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.SolanaBaseProcessor = SolanaBaseProcessor;
|
|
84
|
+
//# sourceMappingURL=solana_processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solana_processor.js","sourceRoot":"","sources":["../src/solana_processor.ts"],"names":[],"mappings":";;;;;;AACA,uCAAkD;AAClD,6CAAuE;AACvE,gDAAuB;AAOvB,MAAa,mBAAmB;IAC9B,mBAAmB,GAAkD,EAAE,CAAA;IACvE,mBAAmB,GAAqD,EAAE,CAAA;IAC1E,OAAO,CAAQ;IACf,QAAQ,CAAQ;IAChB,UAAU,CAAY;IACtB,YAAY,CAAQ;IACpB,MAAM,GAAmB,EAAE,SAAS,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC,EAAE,CAAA;IAEnD,YAAY,YAAoB,EAAE,OAAe,EAAE,QAAgB;QACjE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,CAAC,gBAAgB,EAAE;YAChC,UAAU,CAAC,gBAAgB,GAAG,EAAE,CAAA;SACjC;QACD,UAAU,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACtC,IAAI,CAAC,UAAU,GAAG,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AAU,EAAE,GAAG,CAAC,UAAU;gBAC1B,QAAQ,EAAE,GAAG,CAAC,QAAQ;aACvB,CAAA;QACH,CAAC,CAAC,CAAA;QAEF,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,MAAM;QACX,OAAO,IAAI,CAAC,OAAO,IAAI,IAAI,CAAA;IAC7B,CAAC;IAEM,SAAS,CAAC,SAAwB;QACvC,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;YACjC,SAAS,GAAG,cAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;SACvC;QACD,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,SAAS,CAAA;QACjC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,QAAQ,CAAC,QAAuB;QACrC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;YAChC,QAAQ,GAAG,cAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;SACrC;QACD,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAA;QAC9B,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AApFD,kDAoFC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.MirrorWorldProcessor = void 0;
|
|
30
|
+
const solana_processor_1 = require("solana_processor");
|
|
31
|
+
const fs = __importStar(require("fs"));
|
|
32
|
+
const path = __importStar(require("path"));
|
|
33
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
34
|
+
const anchor_1 = require("@project-serum/anchor");
|
|
35
|
+
class MirrorWorldProcessor extends solana_processor_1.SolanaBaseProcessor {
|
|
36
|
+
static bind(address, endpoint, name = 'MirrorWorld') {
|
|
37
|
+
return new MirrorWorldProcessor(name, address, endpoint);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.MirrorWorldProcessor = MirrorWorldProcessor;
|
|
41
|
+
MirrorWorldProcessor.bind('F78NhTC9XmP1DKsCBRz5LGdQc4n4yFbj2dURiv7T9gGZ', 'https://api.mainnet-beta.solana.com')
|
|
42
|
+
.onTransaction((txn, ctx) => {
|
|
43
|
+
const idlStr = fs.readFileSync(path.join(__dirname, 'solana-abis/mirrorworld.json'));
|
|
44
|
+
const idl = JSON.parse(idlStr.toString());
|
|
45
|
+
const instructionCoder = new anchor_1.BorshInstructionCoder(idl);
|
|
46
|
+
for (const instruction of txn.transaction.message.instructions) {
|
|
47
|
+
const decodedData = instructionCoder.decode(Buffer.from(bs58_1.default.decode(instruction.data)));
|
|
48
|
+
console.log('instruction name: ' + decodedData?.name);
|
|
49
|
+
if (decodedData != null) {
|
|
50
|
+
handleDecodedInstruction(decodedData, ctx);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
.onInstruction((ins, ctx) => {
|
|
55
|
+
const idlStr = fs.readFileSync(path.join(__dirname, 'solana-abis/mirrorworld.json'));
|
|
56
|
+
const idl = JSON.parse(idlStr.toString());
|
|
57
|
+
const instructionCoder = new anchor_1.BorshInstructionCoder(idl);
|
|
58
|
+
const decodedData = instructionCoder.decode(Buffer.from(bs58_1.default.decode(ins)));
|
|
59
|
+
if (decodedData != null) {
|
|
60
|
+
handleDecodedInstruction(decodedData, ctx);
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
.startSlot(111111);
|
|
64
|
+
function handleDecodedInstruction(instruction, ctx) {
|
|
65
|
+
const instructionName = instruction.name;
|
|
66
|
+
switch (instructionName) {
|
|
67
|
+
case 'distributeWithoutUser':
|
|
68
|
+
const amount = instruction.data.amount;
|
|
69
|
+
ctx.meter.Counter('distributeAmount').add(amount.toNumber());
|
|
70
|
+
break;
|
|
71
|
+
case 'deposit':
|
|
72
|
+
break;
|
|
73
|
+
case 'withdraw':
|
|
74
|
+
break;
|
|
75
|
+
case 'spend':
|
|
76
|
+
break;
|
|
77
|
+
case 'distribute':
|
|
78
|
+
break;
|
|
79
|
+
case 'spendWithoutUser':
|
|
80
|
+
break;
|
|
81
|
+
case 'addDistributeSupply':
|
|
82
|
+
break;
|
|
83
|
+
case 'updateTokenConfig':
|
|
84
|
+
break;
|
|
85
|
+
default:
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=mirrorworld.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mirrorworld.js","sourceRoot":"","sources":["../../src/test_case/mirrorworld.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;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AE,8BAA8B,CAAC,CAAC,CAAA;IACpF,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAA;IACzC,MAAM,gBAAgB,GAAG,IAAI,8BAAqB,CAAC,GAAG,CAAC,CAAA;IACvD,MAAM,WAAW,GAAG,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,cAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IAC1E,IAAI,WAAW,IAAI,IAAI,EAAE;QACvB,wBAAwB,CAAC,WAAW,EAAE,GAAG,CAAC,CAAA;KAC3C;AACH,CAAC,CAAC;KACD,SAAS,CAAC,MAAM,CAAC,CAAA;AAEpB,SAAS,wBAAwB,CAAC,WAAwB,EAAE,GAAkB;IAC5E,MAAM,eAAe,GAAG,WAAW,CAAC,IAAI,CAAA;IACxC,QAAQ,eAAe,EAAE;QACvB,KAAK,uBAAuB;YAC1B,MAAM,MAAM,GAAQ,WAAW,CAAC,IAAY,CAAC,MAAM,CAAA;YACnD,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAA;YAC5D,MAAK;QACP,KAAK,SAAS;YACZ,MAAK;QACP,KAAK,UAAU;YACb,MAAK;QACP,KAAK,OAAO;YACV,MAAK;QACP,KAAK,YAAY;YACf,MAAK;QACP,KAAK,kBAAkB;YACrB,MAAK;QACP,KAAK,qBAAqB;YACxB,MAAK;QACP,KAAK,mBAAmB;YACtB,MAAK;QAEP;YACE,MAAK;KACR;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -17,10 +17,14 @@
|
|
|
17
17
|
"processor_server": "./dist/processor_server.js",
|
|
18
18
|
"sentio": "./dist/cli/cli.js"
|
|
19
19
|
},
|
|
20
|
-
"version": "0.1.
|
|
20
|
+
"version": "0.1.5",
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@ethersproject/providers": "^5.6.7",
|
|
23
|
+
"@project-serum/anchor": "^0.25.0",
|
|
24
|
+
"@solana/web3.js": "^1.47.3",
|
|
23
25
|
"@typechain/ethers-v5": "^10.0.0",
|
|
26
|
+
"bn.js": "^5.2.1",
|
|
27
|
+
"bs58": "^5.0.0",
|
|
24
28
|
"command-line-args": "^5.2.1",
|
|
25
29
|
"command-line-usage": "^6.1.3",
|
|
26
30
|
"ethers": "^5.6.7",
|
|
@@ -31,13 +35,14 @@
|
|
|
31
35
|
"log-timestamp": "^0.3.0",
|
|
32
36
|
"nice-grpc": "^1.2.0",
|
|
33
37
|
"node-fetch": "2",
|
|
38
|
+
"ts-loader": "^9.3.0",
|
|
34
39
|
"typechain": "^8.0.0",
|
|
35
|
-
"webpack-cli": "^4.9.2",
|
|
36
40
|
"webpack": "^5.72.1",
|
|
37
|
-
"
|
|
41
|
+
"webpack-cli": "^4.9.2"
|
|
38
42
|
},
|
|
39
43
|
"devDependencies": {
|
|
40
44
|
"@bazel/typescript": "^5.4.2",
|
|
45
|
+
"@types/bn.js": "^5.1.0",
|
|
41
46
|
"@types/chai": "^4.3.1",
|
|
42
47
|
"@types/command-line-args": "^5.2.0",
|
|
43
48
|
"@types/command-line-usage": "^5.0.2",
|
|
@@ -48,6 +53,7 @@
|
|
|
48
53
|
"@types/mkdirp": "^1.0.2",
|
|
49
54
|
"@types/mocha": "^9.1.1",
|
|
50
55
|
"@types/node": "^18.0.4",
|
|
56
|
+
"@types/node-fetch": "^2.6.2",
|
|
51
57
|
"chai": "^4.3.6",
|
|
52
58
|
"mocha": "^10.0.0",
|
|
53
59
|
"ts-mocha": "^10.0.0",
|