@sentio/sdk 1.37.0-rc.2 → 1.37.0-rc.3
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/index.d.ts +0 -2
- package/lib/builtin/index.js +1 -3
- package/lib/builtin/index.js.map +1 -1
- package/lib/core/eth-plugin.js +12 -15
- package/lib/core/eth-plugin.js.map +1 -1
- package/lib/core/index.d.ts +0 -4
- package/lib/core/index.js +1 -9
- package/lib/core/index.js.map +1 -1
- package/lib/core/sui-plugin.js +1 -1
- package/lib/core/sui-plugin.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -14
- package/lib/index.js.map +1 -1
- package/lib/service.d.ts +0 -4
- package/lib/service.js +40 -71
- package/lib/service.js.map +1 -1
- package/package.json +5 -16
- package/src/builtin/index.ts +1 -4
- package/src/core/eth-plugin.ts +5 -8
- package/src/core/index.ts +0 -5
- package/src/core/sui-plugin.ts +2 -2
- package/src/index.ts +3 -1
- package/src/service.ts +13 -71
- package/lib/aptos/api.d.ts +0 -2
- package/lib/aptos/api.js +0 -14
- package/lib/aptos/api.js.map +0 -1
- package/lib/aptos/aptos-plugin.d.ts +0 -14
- package/lib/aptos/aptos-plugin.js +0 -185
- package/lib/aptos/aptos-plugin.js.map +0 -1
- package/lib/aptos/aptos-processor.d.ts +0 -75
- package/lib/aptos/aptos-processor.js +0 -193
- package/lib/aptos/aptos-processor.js.map +0 -1
- package/lib/aptos/context.d.ts +0 -22
- package/lib/aptos/context.js +0 -65
- package/lib/aptos/context.js.map +0 -1
- package/lib/aptos/index.d.ts +0 -9
- package/lib/aptos/index.js +0 -34
- package/lib/aptos/index.js.map +0 -1
- package/lib/aptos/models.d.ts +0 -23
- package/lib/aptos/models.js +0 -3
- package/lib/aptos/models.js.map +0 -1
- package/lib/aptos/network.d.ts +0 -14
- package/lib/aptos/network.js +0 -46
- package/lib/aptos/network.js.map +0 -1
- package/lib/aptos/runtime.d.ts +0 -2
- package/lib/aptos/runtime.js +0 -16
- package/lib/aptos/runtime.js.map +0 -1
- package/lib/aptos/type-registry.d.ts +0 -21
- package/lib/aptos/type-registry.js +0 -156
- package/lib/aptos/type-registry.js.map +0 -1
- package/lib/aptos/types.d.ts +0 -9
- package/lib/aptos/types.js +0 -135
- package/lib/aptos/types.js.map +0 -1
- package/lib/aptos/types.test.d.ts +0 -1
- package/lib/aptos/types.test.js.map +0 -1
- package/lib/aptos/utils.d.ts +0 -7
- package/lib/aptos/utils.js +0 -27
- package/lib/aptos/utils.js.map +0 -1
- package/lib/aptos-codegen/codegen.d.ts +0 -23
- package/lib/aptos-codegen/codegen.js +0 -364
- package/lib/aptos-codegen/codegen.js.map +0 -1
- package/lib/aptos-codegen/typegen.d.ts +0 -17
- package/lib/aptos-codegen/typegen.js +0 -142
- package/lib/aptos-codegen/typegen.js.map +0 -1
- package/lib/builtin/aptos/0x1.d.ts +0 -1913
- package/lib/builtin/aptos/0x1.js +0 -2748
- package/lib/builtin/aptos/0x1.js.map +0 -1
- package/lib/builtin/aptos/0x3.d.ts +0 -482
- package/lib/builtin/aptos/0x3.js +0 -526
- package/lib/builtin/aptos/0x3.js.map +0 -1
- package/lib/builtin/aptos/index.d.ts +0 -2
- package/lib/builtin/aptos/index.js +0 -29
- package/lib/builtin/aptos/index.js.map +0 -1
- package/lib/builtin/solana/index.d.ts +0 -2
- package/lib/builtin/solana/index.js +0 -19
- package/lib/builtin/solana/index.js.map +0 -1
- package/lib/builtin/solana/spl-token-processor.d.ts +0 -39
- package/lib/builtin/solana/spl-token-processor.js +0 -258
- package/lib/builtin/solana/spl-token-processor.js.map +0 -1
- package/lib/builtin/solana/types.d.ts +0 -427
- package/lib/builtin/solana/types.js +0 -203
- package/lib/builtin/solana/types.js.map +0 -1
- package/lib/builtin/solana/wormhole-processor.d.ts +0 -12
- package/lib/builtin/solana/wormhole-processor.js +0 -268
- package/lib/builtin/solana/wormhole-processor.js.map +0 -1
- package/lib/core/solana-context.d.ts +0 -11
- package/lib/core/solana-context.js +0 -34
- package/lib/core/solana-context.js.map +0 -1
- package/lib/core/solana-options.d.ts +0 -8
- package/lib/core/solana-options.js +0 -13
- package/lib/core/solana-options.js.map +0 -1
- package/lib/core/solana-plugin.d.ts +0 -9
- package/lib/core/solana-plugin.js +0 -79
- package/lib/core/solana-plugin.js.map +0 -1
- package/lib/core/solana-processor.d.ts +0 -40
- package/lib/core/solana-processor.js +0 -80
- package/lib/core/solana-processor.js.map +0 -1
- package/lib/solana-codegen/codegen.d.ts +0 -1
- package/lib/solana-codegen/codegen.js +0 -124
- package/lib/solana-codegen/codegen.js.map +0 -1
- package/lib/test-abi-code-gen.d.ts +0 -2
- package/lib/test-abi-code-gen.js +0 -20
- package/lib/test-abi-code-gen.js.map +0 -1
- package/src/abis/aptos/0x1.json +0 -9205
- package/src/abis/aptos/0x3.json +0 -1515
- package/src/aptos/api.ts +0 -11
- package/src/aptos/aptos-plugin.ts +0 -216
- package/src/aptos/aptos-processor.ts +0 -305
- package/src/aptos/context.ts +0 -74
- package/src/aptos/index.ts +0 -10
- package/src/aptos/models.ts +0 -34
- package/src/aptos/network.ts +0 -42
- package/src/aptos/runtime.ts +0 -13
- package/src/aptos/type-registry.ts +0 -187
- package/src/aptos/types.ts +0 -149
- package/src/aptos/utils.ts +0 -26
- package/src/aptos-codegen/codegen.ts +0 -428
- package/src/aptos-codegen/tsconfig.json +0 -9
- package/src/aptos-codegen/typegen.ts +0 -153
- package/src/builtin/aptos/0x1.ts +0 -4210
- package/src/builtin/aptos/0x3.ts +0 -888
- package/src/builtin/aptos/index.ts +0 -2
- package/src/builtin/solana/index.ts +0 -2
- package/src/builtin/solana/spl-token-processor.ts +0 -298
- package/src/builtin/solana/types.ts +0 -279
- package/src/builtin/solana/wormhole-processor.ts +0 -269
- package/src/core/solana-context.ts +0 -34
- package/src/core/solana-options.ts +0 -8
- package/src/core/solana-plugin.ts +0 -97
- package/src/core/solana-processor.ts +0 -102
- package/src/solana-codegen/codegen.ts +0 -129
- package/src/test-abi-code-gen.ts +0 -16
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { SolanaBaseProcessor, SolanaContext, SolanaBindOptions } from '@sentio/sdk';
|
|
2
|
-
import { Instruction } from '@project-serum/anchor';
|
|
3
|
-
export declare class TokenBridgeProcessor extends SolanaBaseProcessor {
|
|
4
|
-
static bind(options: SolanaBindOptions): TokenBridgeProcessor;
|
|
5
|
-
decodeInstruction: (rawInstruction: string) => Instruction | null;
|
|
6
|
-
onInitialize(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor;
|
|
7
|
-
onAttestToken(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor;
|
|
8
|
-
onTransferWrapped(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor;
|
|
9
|
-
onTransferNativeWithPayload(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor;
|
|
10
|
-
onTransferWrappedWithPaylod(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor;
|
|
11
|
-
onTransferNative(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor;
|
|
12
|
-
}
|
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.TokenBridgeProcessor = void 0;
|
|
13
|
-
const sdk_1 = require("@sentio/sdk");
|
|
14
|
-
const bs58_1 = __importDefault(require("bs58"));
|
|
15
|
-
const borsh_1 = require("@dao-xyz/borsh");
|
|
16
|
-
// https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/lib.rs#L100
|
|
17
|
-
var TokenBridgeInstruction;
|
|
18
|
-
(function (TokenBridgeInstruction) {
|
|
19
|
-
TokenBridgeInstruction[TokenBridgeInstruction["Initialize"] = 0] = "Initialize";
|
|
20
|
-
TokenBridgeInstruction[TokenBridgeInstruction["AttestToken"] = 1] = "AttestToken";
|
|
21
|
-
TokenBridgeInstruction[TokenBridgeInstruction["CompleteNative"] = 2] = "CompleteNative";
|
|
22
|
-
TokenBridgeInstruction[TokenBridgeInstruction["CompleteWrapped"] = 3] = "CompleteWrapped";
|
|
23
|
-
TokenBridgeInstruction[TokenBridgeInstruction["TransferWrapped"] = 4] = "TransferWrapped";
|
|
24
|
-
TokenBridgeInstruction[TokenBridgeInstruction["TransferNative"] = 5] = "TransferNative";
|
|
25
|
-
TokenBridgeInstruction[TokenBridgeInstruction["RegisterChain"] = 6] = "RegisterChain";
|
|
26
|
-
TokenBridgeInstruction[TokenBridgeInstruction["CreateWrapped"] = 7] = "CreateWrapped";
|
|
27
|
-
TokenBridgeInstruction[TokenBridgeInstruction["UpgradeContract"] = 8] = "UpgradeContract";
|
|
28
|
-
TokenBridgeInstruction[TokenBridgeInstruction["CompleteNativeWithPayload"] = 9] = "CompleteNativeWithPayload";
|
|
29
|
-
TokenBridgeInstruction[TokenBridgeInstruction["CompleteWrappedWithPayload"] = 10] = "CompleteWrappedWithPayload";
|
|
30
|
-
TokenBridgeInstruction[TokenBridgeInstruction["TransferWrappedWithPayload"] = 11] = "TransferWrappedWithPayload";
|
|
31
|
-
TokenBridgeInstruction[TokenBridgeInstruction["TransferNativeWithPayload"] = 12] = "TransferNativeWithPayload";
|
|
32
|
-
})(TokenBridgeInstruction || (TokenBridgeInstruction = {}));
|
|
33
|
-
class TransferDataValues {
|
|
34
|
-
nonce;
|
|
35
|
-
amount;
|
|
36
|
-
fee;
|
|
37
|
-
target_address;
|
|
38
|
-
target_chain;
|
|
39
|
-
constructor(data) {
|
|
40
|
-
if (data) {
|
|
41
|
-
Object.assign(this, data);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
__decorate([
|
|
46
|
-
(0, borsh_1.field)({ type: 'u32' })
|
|
47
|
-
], TransferDataValues.prototype, "nonce", void 0);
|
|
48
|
-
__decorate([
|
|
49
|
-
(0, borsh_1.field)({ type: 'u64' })
|
|
50
|
-
], TransferDataValues.prototype, "amount", void 0);
|
|
51
|
-
__decorate([
|
|
52
|
-
(0, borsh_1.field)({ type: 'u64' })
|
|
53
|
-
], TransferDataValues.prototype, "fee", void 0);
|
|
54
|
-
__decorate([
|
|
55
|
-
(0, borsh_1.field)({ type: (0, borsh_1.fixedArray)('u8', 32) })
|
|
56
|
-
], TransferDataValues.prototype, "target_address", void 0);
|
|
57
|
-
__decorate([
|
|
58
|
-
(0, borsh_1.field)({ type: 'u16' })
|
|
59
|
-
], TransferDataValues.prototype, "target_chain", void 0);
|
|
60
|
-
class TransferNativeWithPayloadData {
|
|
61
|
-
nonce;
|
|
62
|
-
amount;
|
|
63
|
-
fee;
|
|
64
|
-
target_address;
|
|
65
|
-
target_chain;
|
|
66
|
-
payload;
|
|
67
|
-
cpi_program_id;
|
|
68
|
-
constructor(data) {
|
|
69
|
-
if (data) {
|
|
70
|
-
Object.assign(this, data);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
__decorate([
|
|
75
|
-
(0, borsh_1.field)({ type: 'u32' })
|
|
76
|
-
], TransferNativeWithPayloadData.prototype, "nonce", void 0);
|
|
77
|
-
__decorate([
|
|
78
|
-
(0, borsh_1.field)({ type: 'u64' })
|
|
79
|
-
], TransferNativeWithPayloadData.prototype, "amount", void 0);
|
|
80
|
-
__decorate([
|
|
81
|
-
(0, borsh_1.field)({ type: 'u64' })
|
|
82
|
-
], TransferNativeWithPayloadData.prototype, "fee", void 0);
|
|
83
|
-
__decorate([
|
|
84
|
-
(0, borsh_1.field)({ type: (0, borsh_1.fixedArray)('u8', 32) })
|
|
85
|
-
], TransferNativeWithPayloadData.prototype, "target_address", void 0);
|
|
86
|
-
__decorate([
|
|
87
|
-
(0, borsh_1.field)({ type: 'u16' })
|
|
88
|
-
], TransferNativeWithPayloadData.prototype, "target_chain", void 0);
|
|
89
|
-
__decorate([
|
|
90
|
-
(0, borsh_1.field)({ type: (0, borsh_1.vec)('u8') })
|
|
91
|
-
], TransferNativeWithPayloadData.prototype, "payload", void 0);
|
|
92
|
-
__decorate([
|
|
93
|
-
(0, borsh_1.field)({ type: (0, borsh_1.option)((0, borsh_1.fixedArray)('u8', 32)) })
|
|
94
|
-
], TransferNativeWithPayloadData.prototype, "cpi_program_id", void 0);
|
|
95
|
-
class AttestTokenValues {
|
|
96
|
-
nonce;
|
|
97
|
-
constructor(data) {
|
|
98
|
-
if (data) {
|
|
99
|
-
Object.assign(this, data);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
__decorate([
|
|
104
|
-
(0, borsh_1.field)({ type: 'u32' })
|
|
105
|
-
], AttestTokenValues.prototype, "nonce", void 0);
|
|
106
|
-
class InitializeDataValues {
|
|
107
|
-
bridge;
|
|
108
|
-
constructor(data) {
|
|
109
|
-
if (data) {
|
|
110
|
-
Object.assign(this, data);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
__decorate([
|
|
115
|
-
(0, borsh_1.field)({ type: (0, borsh_1.fixedArray)('u8', 32) })
|
|
116
|
-
], InitializeDataValues.prototype, "bridge", void 0);
|
|
117
|
-
class TokenBridgeProcessor extends sdk_1.SolanaBaseProcessor {
|
|
118
|
-
// private readonly transferDataValues = [
|
|
119
|
-
// borsh.u32('nonce'),
|
|
120
|
-
// borsh.u64('amount'),
|
|
121
|
-
// borsh.u64('fee'),
|
|
122
|
-
// borsh.array(borsh.u8(undefined), 32, 'target_address'),
|
|
123
|
-
// borsh.u16('target_chain')
|
|
124
|
-
// ]
|
|
125
|
-
// https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/api/transfer_payload.rs#L170
|
|
126
|
-
// private readonly transferDataWithPayloadValues = [
|
|
127
|
-
// borsh.u32('nonce'),
|
|
128
|
-
// borsh.u64('amount'),
|
|
129
|
-
// borsh.array(borsh.u8(undefined), 32, 'target_address'),
|
|
130
|
-
// borsh.u16('target_chain'),
|
|
131
|
-
// borsh.vecU8('payload'),
|
|
132
|
-
// borsh.option(borsh.publicKey(undefined), 'cpi_program_id')
|
|
133
|
-
// ]
|
|
134
|
-
// private readonly attestTokenValues = [
|
|
135
|
-
// borsh.u32('nonce')
|
|
136
|
-
// ]
|
|
137
|
-
// private readonly initializeDataValues = [
|
|
138
|
-
// borsh.publicKey('bridge')
|
|
139
|
-
// ]
|
|
140
|
-
static bind(options) {
|
|
141
|
-
if (options && !options.name) {
|
|
142
|
-
options.name = 'WormholeTokenBridge';
|
|
143
|
-
}
|
|
144
|
-
return new TokenBridgeProcessor(options);
|
|
145
|
-
}
|
|
146
|
-
decodeInstruction = (ins) => {
|
|
147
|
-
const u8Arr = bs58_1.default.decode(ins);
|
|
148
|
-
if (u8Arr.length === 0) {
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
let data;
|
|
152
|
-
// wormhole pass intruction's enum value as its first instrcution data
|
|
153
|
-
switch (u8Arr[0]) {
|
|
154
|
-
case TokenBridgeInstruction.Initialize:
|
|
155
|
-
return {
|
|
156
|
-
data: '',
|
|
157
|
-
name: TokenBridgeInstruction[TokenBridgeInstruction.Initialize]
|
|
158
|
-
};
|
|
159
|
-
case TokenBridgeInstruction.TransferNative:
|
|
160
|
-
data = (0, borsh_1.deserialize)(Buffer.from(u8Arr.slice(1)), TransferDataValues);
|
|
161
|
-
// struct is defined at: https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/api/transfer.rs#L295
|
|
162
|
-
// data = borsh.struct(this.transferDataValues, 'TransferNativeData').decode(Buffer.from(u8Arr.slice(1)))
|
|
163
|
-
return {
|
|
164
|
-
data,
|
|
165
|
-
name: TokenBridgeInstruction[TokenBridgeInstruction.TransferNative]
|
|
166
|
-
};
|
|
167
|
-
case TokenBridgeInstruction.TransferWrapped:
|
|
168
|
-
data = (0, borsh_1.deserialize)(Buffer.from(u8Arr.slice(1)), TransferDataValues);
|
|
169
|
-
// stuct is defined at: https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/api/transfer.rs#L295
|
|
170
|
-
// data = borsh.struct(this.transferDataValues, 'TransferWrappedData').decode(Buffer.from(u8Arr.slice(1)))
|
|
171
|
-
return {
|
|
172
|
-
data,
|
|
173
|
-
name: TokenBridgeInstruction[TokenBridgeInstruction.TransferWrapped]
|
|
174
|
-
};
|
|
175
|
-
case TokenBridgeInstruction.TransferNativeWithPayload:
|
|
176
|
-
data = (0, borsh_1.deserialize)(Buffer.from(u8Arr.slice(1)), TransferNativeWithPayloadData);
|
|
177
|
-
// data = borsh.struct(this.transferDataWithPayloadValues, 'TransferNativeWithPayloadData').decode(Buffer.from(u8Arr.slice(1)))
|
|
178
|
-
return {
|
|
179
|
-
data,
|
|
180
|
-
name: TokenBridgeInstruction[TokenBridgeInstruction.TransferNativeWithPayload]
|
|
181
|
-
};
|
|
182
|
-
case TokenBridgeInstruction.TransferWrappedWithPayload:
|
|
183
|
-
data = (0, borsh_1.deserialize)(Buffer.from(u8Arr.slice(1)), TransferNativeWithPayloadData);
|
|
184
|
-
// data = borsh.struct(this.transferDataWithPayloadValues, 'TransferWrappedWithPayloadData').decode(Buffer.from(u8Arr.slice(1)))
|
|
185
|
-
return {
|
|
186
|
-
data,
|
|
187
|
-
name: TokenBridgeInstruction[TokenBridgeInstruction.TransferWrappedWithPayload]
|
|
188
|
-
};
|
|
189
|
-
case TokenBridgeInstruction.Initialize:
|
|
190
|
-
data = (0, borsh_1.deserialize)(Buffer.from(u8Arr.slice(1)), InitializeDataValues);
|
|
191
|
-
// data = borsh.struct(this.initializeDataValues, 'InitializeData').decode(Buffer.from(u8Arr.slice(1)))
|
|
192
|
-
return {
|
|
193
|
-
data,
|
|
194
|
-
name: TokenBridgeInstruction[TokenBridgeInstruction.Initialize]
|
|
195
|
-
};
|
|
196
|
-
case TokenBridgeInstruction.AttestToken:
|
|
197
|
-
data = (0, borsh_1.deserialize)(Buffer.from(u8Arr.slice(1)), AttestTokenValues);
|
|
198
|
-
// data = borsh.struct(this.attestTokenValues, 'AttestTokenData').decode(Buffer.from(u8Arr.slice(1)))
|
|
199
|
-
return {
|
|
200
|
-
data,
|
|
201
|
-
name: TokenBridgeInstruction[TokenBridgeInstruction.AttestToken]
|
|
202
|
-
};
|
|
203
|
-
case TokenBridgeInstruction.CompleteNative:
|
|
204
|
-
case TokenBridgeInstruction.CompleteNativeWithPayload:
|
|
205
|
-
case TokenBridgeInstruction.CompleteWrapped:
|
|
206
|
-
case TokenBridgeInstruction.CompleteWrappedWithPayload:
|
|
207
|
-
case TokenBridgeInstruction.CreateWrapped:
|
|
208
|
-
case TokenBridgeInstruction.UpgradeContract:
|
|
209
|
-
case TokenBridgeInstruction.RegisterChain:
|
|
210
|
-
return {
|
|
211
|
-
data: '',
|
|
212
|
-
name: TokenBridgeInstruction[u8Arr[0]]
|
|
213
|
-
};
|
|
214
|
-
default:
|
|
215
|
-
return null;
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
onInitialize(handler) {
|
|
219
|
-
this.onInstruction('Initialize', (ins, ctx, accounts) => {
|
|
220
|
-
if (ins) {
|
|
221
|
-
handler(ins.data, accounts, ctx);
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
return this;
|
|
225
|
-
}
|
|
226
|
-
onAttestToken(handler) {
|
|
227
|
-
this.onInstruction('AttestToken', (ins, ctx, accounts) => {
|
|
228
|
-
if (ins) {
|
|
229
|
-
handler(ins.data, accounts, ctx);
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
return this;
|
|
233
|
-
}
|
|
234
|
-
onTransferWrapped(handler) {
|
|
235
|
-
this.onInstruction('TransferWrapped', (ins, ctx, accounts) => {
|
|
236
|
-
if (ins) {
|
|
237
|
-
handler(ins.data, accounts, ctx);
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
return this;
|
|
241
|
-
}
|
|
242
|
-
onTransferNativeWithPayload(handler) {
|
|
243
|
-
this.onInstruction('TransferNativeWithPayload', (ins, ctx, accounts) => {
|
|
244
|
-
if (ins) {
|
|
245
|
-
handler(ins.data, accounts, ctx);
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
return this;
|
|
249
|
-
}
|
|
250
|
-
onTransferWrappedWithPaylod(handler) {
|
|
251
|
-
this.onInstruction('TransferWrappedWithPaylod', (ins, ctx, accounts) => {
|
|
252
|
-
if (ins) {
|
|
253
|
-
handler(ins.data, accounts, ctx);
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
return this;
|
|
257
|
-
}
|
|
258
|
-
onTransferNative(handler) {
|
|
259
|
-
this.onInstruction('TransferNative', (ins, ctx, accounts) => {
|
|
260
|
-
if (ins) {
|
|
261
|
-
handler(ins.data, accounts, ctx);
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
return this;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
exports.TokenBridgeProcessor = TokenBridgeProcessor;
|
|
268
|
-
//# sourceMappingURL=wormhole-processor.js.map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AAC;CACF;AAvKD,oDAuKC","sourcesContent":["import { SolanaBaseProcessor, SolanaContext, SolanaBindOptions } from '@sentio/sdk'\nimport { Instruction } from '@project-serum/anchor'\nimport bs58 from 'bs58'\n\nimport {\n deserialize,\n field,\n vec, fixedArray, option,\n} from \"@dao-xyz/borsh\";\n\n// https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/lib.rs#L100\nenum TokenBridgeInstruction {\n Initialize = 0,\n AttestToken,\n CompleteNative, // no args\n CompleteWrapped, // no args\n TransferWrapped,\n TransferNative,\n RegisterChain, // no args\n CreateWrapped, // no args\n UpgradeContract, // no args\n CompleteNativeWithPayload, // no args\n CompleteWrappedWithPayload, // no args\n TransferWrappedWithPayload,\n TransferNativeWithPayload,\n}\n\nclass TransferDataValues {\n @field({ type: 'u32' })\n nonce: number\n\n @field({type: 'u64'})\n amount: bigint\n\n @field({type: 'u64'})\n fee: bigint\n\n @field({ type: fixedArray('u8', 32) })\n target_address: number[];\n\n @field({ type: 'u16' })\n target_chain: number\n\n constructor(data?: TransferDataValues) {\n if(data){\n Object.assign(this,data)\n }\n }\n}\n\nclass TransferNativeWithPayloadData {\n @field({ type: 'u32' })\n nonce: number\n\n @field({type: 'u64'})\n amount: bigint\n\n @field({type: 'u64'})\n fee: bigint\n\n @field({ type: fixedArray('u8', 32) })\n target_address: number[];\n\n @field({ type: 'u16' })\n target_chain: number\n\n @field({ type: vec('u8') })\n payload: number[];\n\n @field({type: option(fixedArray('u8', 32) )})\n cpi_program_id?: number[]\n\n constructor(data?: TransferNativeWithPayloadData) {\n if(data){\n Object.assign(this,data)\n }\n }\n}\n\nclass AttestTokenValues {\n @field({ type: 'u32' })\n nonce: number\n\n constructor(data?: AttestTokenValues) {\n if(data){\n Object.assign(this,data)\n }\n }\n}\n\nclass InitializeDataValues {\n @field({type: fixedArray('u8', 32) })\n bridge: number[]\n\n constructor(data?: InitializeDataValues) {\n if(data){\n Object.assign(this,data)\n }\n }\n}\n\nexport class TokenBridgeProcessor extends SolanaBaseProcessor {\n\n // private readonly transferDataValues = [\n // borsh.u32('nonce'),\n // borsh.u64('amount'),\n // borsh.u64('fee'),\n // borsh.array(borsh.u8(undefined), 32, 'target_address'),\n // borsh.u16('target_chain')\n // ]\n // https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/api/transfer_payload.rs#L170\n // private readonly transferDataWithPayloadValues = [\n // borsh.u32('nonce'),\n // borsh.u64('amount'),\n // borsh.array(borsh.u8(undefined), 32, 'target_address'),\n // borsh.u16('target_chain'),\n // borsh.vecU8('payload'),\n // borsh.option(borsh.publicKey(undefined), 'cpi_program_id')\n // ]\n // private readonly attestTokenValues = [\n // borsh.u32('nonce')\n // ]\n // private readonly initializeDataValues = [\n // borsh.publicKey('bridge')\n // ]\n\n static bind(options: SolanaBindOptions): TokenBridgeProcessor {\n if (options && !options.name) {\n options.name = 'WormholeTokenBridge'\n }\n return new TokenBridgeProcessor(options)\n }\n\n decodeInstruction: (rawInstruction: string) => Instruction | null = (ins) => {\n const u8Arr = bs58.decode(ins)\n if (u8Arr.length === 0) {\n return null\n }\n\n let data: any\n // wormhole pass intruction's enum value as its first instrcution data\n switch (u8Arr[0]) {\n case TokenBridgeInstruction.Initialize:\n return {\n data: '',\n name: TokenBridgeInstruction[TokenBridgeInstruction.Initialize]\n }\n case TokenBridgeInstruction.TransferNative:\n data = deserialize(Buffer.from(u8Arr.slice(1)), TransferDataValues)\n\n // struct is defined at: https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/api/transfer.rs#L295\n // data = borsh.struct(this.transferDataValues, 'TransferNativeData').decode(Buffer.from(u8Arr.slice(1)))\n return {\n data,\n name: TokenBridgeInstruction[TokenBridgeInstruction.TransferNative]\n }\n case TokenBridgeInstruction.TransferWrapped:\n data = deserialize(Buffer.from(u8Arr.slice(1)), TransferDataValues)\n\n // stuct is defined at: https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/api/transfer.rs#L295\n // data = borsh.struct(this.transferDataValues, 'TransferWrappedData').decode(Buffer.from(u8Arr.slice(1)))\n return {\n data,\n name: TokenBridgeInstruction[TokenBridgeInstruction.TransferWrapped]\n }\n case TokenBridgeInstruction.TransferNativeWithPayload:\n data = deserialize(Buffer.from(u8Arr.slice(1)), TransferNativeWithPayloadData)\n\n // data = borsh.struct(this.transferDataWithPayloadValues, 'TransferNativeWithPayloadData').decode(Buffer.from(u8Arr.slice(1)))\n return {\n data,\n name: TokenBridgeInstruction[TokenBridgeInstruction.TransferNativeWithPayload]\n }\n case TokenBridgeInstruction.TransferWrappedWithPayload:\n data = deserialize(Buffer.from(u8Arr.slice(1)), TransferNativeWithPayloadData)\n\n // data = borsh.struct(this.transferDataWithPayloadValues, 'TransferWrappedWithPayloadData').decode(Buffer.from(u8Arr.slice(1)))\n return {\n data,\n name: TokenBridgeInstruction[TokenBridgeInstruction.TransferWrappedWithPayload]\n }\n case TokenBridgeInstruction.Initialize:\n data = deserialize(Buffer.from(u8Arr.slice(1)), InitializeDataValues)\n\n // data = borsh.struct(this.initializeDataValues, 'InitializeData').decode(Buffer.from(u8Arr.slice(1)))\n return {\n data,\n name: TokenBridgeInstruction[TokenBridgeInstruction.Initialize]\n }\n case TokenBridgeInstruction.AttestToken:\n data = deserialize(Buffer.from(u8Arr.slice(1)), AttestTokenValues)\n\n // data = borsh.struct(this.attestTokenValues, 'AttestTokenData').decode(Buffer.from(u8Arr.slice(1)))\n return {\n data,\n name: TokenBridgeInstruction[TokenBridgeInstruction.AttestToken]\n }\n case TokenBridgeInstruction.CompleteNative:\n case TokenBridgeInstruction.CompleteNativeWithPayload:\n case TokenBridgeInstruction.CompleteWrapped:\n case TokenBridgeInstruction.CompleteWrappedWithPayload:\n case TokenBridgeInstruction.CreateWrapped:\n case TokenBridgeInstruction.UpgradeContract:\n case TokenBridgeInstruction.RegisterChain:\n return {\n data: '',\n name: TokenBridgeInstruction[u8Arr[0]]\n }\n\n default:\n return null\n }\n }\n\n onInitialize(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor {\n this.onInstruction('Initialize', (ins: Instruction, ctx, accounts: string[]) => {\n if (ins) {\n handler(ins.data, accounts, ctx)\n }\n })\n return this\n }\n\n onAttestToken(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor {\n this.onInstruction('AttestToken', (ins: Instruction, ctx, accounts: string[]) => {\n if (ins) {\n handler(ins.data, accounts, ctx)\n }\n })\n return this\n }\n\n\n onTransferWrapped(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor {\n this.onInstruction('TransferWrapped', (ins: Instruction, ctx, accounts: string[]) => {\n if (ins) {\n handler(ins.data, accounts, ctx)\n }\n })\n return this\n }\n\n onTransferNativeWithPayload(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor {\n this.onInstruction('TransferNativeWithPayload', (ins: Instruction, ctx, accounts: string[]) => {\n if (ins) {\n handler(ins.data, accounts, ctx)\n }\n })\n return this\n }\n\n onTransferWrappedWithPaylod(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor {\n this.onInstruction('TransferWrappedWithPaylod', (ins: Instruction, ctx, accounts: string[]) => {\n if (ins) {\n handler(ins.data, accounts, ctx)\n }\n })\n return this\n }\n\n onTransferNative(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor {\n this.onInstruction('TransferNative', (ins: Instruction, ctx, accounts: string[]) => {\n if (ins) {\n handler(ins.data, accounts, ctx)\n }\n })\n return this\n }\n}\n"]}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { BaseContext } from './base-context';
|
|
2
|
-
import { Labels } from './metadata';
|
|
3
|
-
import { RecordMetaData } from '@sentio/sdk';
|
|
4
|
-
export declare class SolanaContext extends BaseContext {
|
|
5
|
-
network: string;
|
|
6
|
-
address: string;
|
|
7
|
-
programName: string;
|
|
8
|
-
blockNumber: bigint;
|
|
9
|
-
constructor(programName: string, network: string, address: string, slot: bigint);
|
|
10
|
-
getMetaData(name: string, labels: Labels): RecordMetaData;
|
|
11
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SolanaContext = void 0;
|
|
4
|
-
const base_context_1 = require("./base-context");
|
|
5
|
-
const chain_1 = require("../utils/chain");
|
|
6
|
-
const meter_1 = require("./meter");
|
|
7
|
-
class SolanaContext extends base_context_1.BaseContext {
|
|
8
|
-
network;
|
|
9
|
-
address;
|
|
10
|
-
programName;
|
|
11
|
-
blockNumber;
|
|
12
|
-
constructor(programName, network, address, slot) {
|
|
13
|
-
super();
|
|
14
|
-
this.network = network || chain_1.CHAIN_IDS.SOLANA_MAINNET;
|
|
15
|
-
this.programName = programName;
|
|
16
|
-
this.address = address;
|
|
17
|
-
this.blockNumber = slot;
|
|
18
|
-
}
|
|
19
|
-
getMetaData(name, labels) {
|
|
20
|
-
return {
|
|
21
|
-
address: this.address,
|
|
22
|
-
contractName: this.programName,
|
|
23
|
-
blockNumber: this.blockNumber,
|
|
24
|
-
transactionIndex: 0,
|
|
25
|
-
transactionHash: '',
|
|
26
|
-
logIndex: 0,
|
|
27
|
-
chainId: this.network,
|
|
28
|
-
name: name,
|
|
29
|
-
labels: (0, meter_1.normalizeLabels)(labels),
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.SolanaContext = SolanaContext;
|
|
34
|
-
//# sourceMappingURL=solana-context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"solana-context.js","sourceRoot":"","sources":["../../src/core/solana-context.ts"],"names":[],"mappings":";;;AAAA,iDAA4C;AAG5C,0CAA0C;AAC1C,mCAAyC;AAEzC,MAAa,aAAc,SAAQ,0BAAW;IAC5C,OAAO,CAAQ;IACf,OAAO,CAAQ;IACf,WAAW,CAAQ;IACnB,WAAW,CAAQ;IAEnB,YAAY,WAAmB,EAAE,OAAe,EAAE,OAAe,EAAE,IAAY;QAC7E,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,iBAAS,CAAC,cAAc,CAAA;QAClD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA;IACzB,CAAC;IAED,WAAW,CAAC,IAAY,EAAE,MAAc;QACtC,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,IAAI,CAAC,WAAW;YAC9B,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,gBAAgB,EAAE,CAAC;YACnB,eAAe,EAAE,EAAE;YACnB,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,IAAA,uBAAe,EAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF;AA3BD,sCA2BC","sourcesContent":["import { BaseContext } from './base-context'\nimport { Labels } from './metadata'\nimport { RecordMetaData } from '@sentio/sdk'\nimport { CHAIN_IDS } from '../utils/chain'\nimport { normalizeLabels } from './meter'\n\nexport class SolanaContext extends BaseContext {\n network: string\n address: string\n programName: string\n blockNumber: bigint\n\n constructor(programName: string, network: string, address: string, slot: bigint) {\n super()\n this.network = network || CHAIN_IDS.SOLANA_MAINNET\n this.programName = programName\n this.address = address\n this.blockNumber = slot\n }\n\n getMetaData(name: string, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.programName,\n blockNumber: this.blockNumber,\n transactionIndex: 0,\n transactionHash: '', // TODO add\n logIndex: 0,\n chainId: this.network,\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SolanaBindOptions = void 0;
|
|
4
|
-
class SolanaBindOptions {
|
|
5
|
-
address;
|
|
6
|
-
network;
|
|
7
|
-
name;
|
|
8
|
-
startBlock;
|
|
9
|
-
endBlock;
|
|
10
|
-
processInnerInstruction;
|
|
11
|
-
}
|
|
12
|
-
exports.SolanaBindOptions = SolanaBindOptions;
|
|
13
|
-
//# sourceMappingURL=solana-options.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"solana-options.js","sourceRoot":"","sources":["../../src/core/solana-options.ts"],"names":[],"mappings":";;;AAAA,MAAa,iBAAiB;IAC5B,OAAO,CAAQ;IACf,OAAO,CAAS;IAChB,IAAI,CAAS;IACb,UAAU,CAAkB;IAC5B,QAAQ,CAAkB;IAC1B,uBAAuB,CAAU;CAClC;AAPD,8CAOC","sourcesContent":["export class SolanaBindOptions {\n address: string\n network?: string\n name?: string\n startBlock?: bigint | number\n endBlock?: bigint | number\n processInnerInstruction?: boolean\n}\n"]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Plugin } from '@sentio/base';
|
|
2
|
-
import { DataBinding, HandlerType, ProcessConfigResponse, ProcessResult } from '@sentio/protos';
|
|
3
|
-
export declare class SolanaPlugin implements Plugin {
|
|
4
|
-
name: string;
|
|
5
|
-
configure(config: ProcessConfigResponse): void;
|
|
6
|
-
supportedHandlers: HandlerType[];
|
|
7
|
-
processBinding(request: DataBinding): Promise<ProcessResult>;
|
|
8
|
-
processSolInstruction(request: DataBinding): Promise<ProcessResult>;
|
|
9
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SolanaPlugin = void 0;
|
|
4
|
-
const base_1 = require("@sentio/base");
|
|
5
|
-
const protos_1 = require("@sentio/protos");
|
|
6
|
-
const service_1 = require("../service");
|
|
7
|
-
const nice_grpc_1 = require("nice-grpc");
|
|
8
|
-
const solana_processor_1 = require("./solana-processor");
|
|
9
|
-
class SolanaPlugin {
|
|
10
|
-
name = 'SolanaPlugin';
|
|
11
|
-
configure(config) {
|
|
12
|
-
// Part 2, prepare solana constractors
|
|
13
|
-
for (const solanaProcessor of solana_processor_1.SolanaProcessorState.INSTANCE.getValues()) {
|
|
14
|
-
const contractConfig = {
|
|
15
|
-
processorType: service_1.USER_PROCESSOR,
|
|
16
|
-
contract: {
|
|
17
|
-
name: solanaProcessor.contractName,
|
|
18
|
-
chainId: solanaProcessor.network,
|
|
19
|
-
address: solanaProcessor.address,
|
|
20
|
-
abi: '',
|
|
21
|
-
},
|
|
22
|
-
logConfigs: [],
|
|
23
|
-
traceConfigs: [],
|
|
24
|
-
intervalConfigs: [],
|
|
25
|
-
startBlock: solanaProcessor.config.startSlot,
|
|
26
|
-
endBlock: service_1.DEFAULT_MAX_BLOCK,
|
|
27
|
-
instructionConfig: {
|
|
28
|
-
innerInstruction: solanaProcessor.processInnerInstruction,
|
|
29
|
-
parsedInstruction: solanaProcessor.fromParsedInstruction !== null,
|
|
30
|
-
rawDataInstruction: solanaProcessor.decodeInstruction !== null,
|
|
31
|
-
},
|
|
32
|
-
aptosEventConfigs: [],
|
|
33
|
-
aptosCallConfigs: [],
|
|
34
|
-
};
|
|
35
|
-
config.contractConfigs.push(contractConfig);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
supportedHandlers = [protos_1.HandlerType.SOL_INSTRUCTION];
|
|
39
|
-
processBinding(request) {
|
|
40
|
-
switch (request.handlerType) {
|
|
41
|
-
case protos_1.HandlerType.SOL_INSTRUCTION:
|
|
42
|
-
return this.processSolInstruction(request);
|
|
43
|
-
default:
|
|
44
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
async processSolInstruction(request) {
|
|
48
|
-
if (!request.data) {
|
|
49
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'instruction data cannot be empty');
|
|
50
|
-
}
|
|
51
|
-
const instruction = request.data.solInstruction || protos_1.Data_SolInstruction.decode(request.data.raw); // JSON.parse(jsonString)
|
|
52
|
-
const promises = [];
|
|
53
|
-
// Only have instruction handlers for solana processors
|
|
54
|
-
for (const processor of solana_processor_1.SolanaProcessorState.INSTANCE.getValues()) {
|
|
55
|
-
if (processor.address === instruction.programAccountId) {
|
|
56
|
-
let parsedInstruction = null;
|
|
57
|
-
if (instruction.parsed) {
|
|
58
|
-
parsedInstruction = processor.getParsedInstruction(instruction.parsed);
|
|
59
|
-
}
|
|
60
|
-
else if (instruction.instructionData) {
|
|
61
|
-
parsedInstruction = processor.getParsedInstruction(instruction.instructionData);
|
|
62
|
-
}
|
|
63
|
-
if (parsedInstruction == null) {
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
const insHandler = processor.getInstructionHandler(parsedInstruction);
|
|
67
|
-
if (insHandler == null) {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
const res = await processor.handleInstruction(parsedInstruction, instruction.accounts, insHandler, instruction.slot);
|
|
71
|
-
promises.push(Promise.resolve(res));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return (0, service_1.mergeProcessResults)(await Promise.all(promises));
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.SolanaPlugin = SolanaPlugin;
|
|
78
|
-
base_1.PluginManager.INSTANCE.register(new SolanaPlugin());
|
|
79
|
-
//# sourceMappingURL=solana-plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"solana-plugin.js","sourceRoot":"","sources":["../../src/core/solana-plugin.ts"],"names":[],"mappings":";;;AAAA,uCAAo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ACF;QACD,OAAO,IAAA,6BAAmB,EAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IACzD,CAAC;CACF;AA9ED,oCA8EC;AAED,oBAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,YAAY,EAAE,CAAC,CAAA","sourcesContent":["import { Plugin, PluginManager } from '@sentio/base'\nimport {\n ContractConfig,\n Data_SolInstruction,\n DataBinding,\n HandlerType,\n ProcessConfigResponse,\n ProcessResult,\n} from '@sentio/protos'\nimport { DEFAULT_MAX_BLOCK, mergeProcessResults, USER_PROCESSOR } from '../service'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { SolanaProcessorState } from './solana-processor'\nimport { Instruction as SolInstruction } from '@project-serum/anchor/dist/cjs/coder/borsh/instruction'\n\nexport class SolanaPlugin implements Plugin {\n name: string = 'SolanaPlugin'\n\n configure(config: ProcessConfigResponse): void {\n // Part 2, prepare solana constractors\n for (const solanaProcessor of SolanaProcessorState.INSTANCE.getValues()) {\n const contractConfig: ContractConfig = {\n processorType: USER_PROCESSOR,\n contract: {\n name: solanaProcessor.contractName,\n chainId: solanaProcessor.network,\n address: solanaProcessor.address,\n abi: '',\n },\n logConfigs: [],\n traceConfigs: [],\n intervalConfigs: [],\n startBlock: solanaProcessor.config.startSlot,\n endBlock: DEFAULT_MAX_BLOCK,\n instructionConfig: {\n innerInstruction: solanaProcessor.processInnerInstruction,\n parsedInstruction: solanaProcessor.fromParsedInstruction !== null,\n rawDataInstruction: solanaProcessor.decodeInstruction !== null,\n },\n aptosEventConfigs: [],\n aptosCallConfigs: [],\n }\n config.contractConfigs.push(contractConfig)\n }\n }\n\n supportedHandlers = [HandlerType.SOL_INSTRUCTION]\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n switch (request.handlerType) {\n case HandlerType.SOL_INSTRUCTION:\n return this.processSolInstruction(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n\n async processSolInstruction(request: DataBinding): Promise<ProcessResult> {\n if (!request.data) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'instruction data cannot be empty')\n }\n\n const instruction = request.data.solInstruction || Data_SolInstruction.decode(request.data.raw) // JSON.parse(jsonString)\n const promises: Promise<ProcessResult>[] = []\n\n // Only have instruction handlers for solana processors\n for (const processor of SolanaProcessorState.INSTANCE.getValues()) {\n if (processor.address === instruction.programAccountId) {\n let parsedInstruction: SolInstruction | null = null\n if (instruction.parsed) {\n parsedInstruction = processor.getParsedInstruction(instruction.parsed as { type: string; info: any })\n } else if (instruction.instructionData) {\n parsedInstruction = processor.getParsedInstruction(instruction.instructionData)\n }\n if (parsedInstruction == null) {\n continue\n }\n const insHandler = processor.getInstructionHandler(parsedInstruction)\n if (insHandler == null) {\n continue\n }\n const res = await processor.handleInstruction(\n parsedInstruction,\n instruction.accounts,\n insHandler,\n instruction.slot\n )\n\n promises.push(Promise.resolve(res))\n }\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n}\n\nPluginManager.INSTANCE.register(new SolanaPlugin())\n"]}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { ProcessResult } from '@sentio/protos';
|
|
2
|
-
import { SolanaContext } from './solana-context';
|
|
3
|
-
import { Instruction } from '@project-serum/anchor';
|
|
4
|
-
import { SolanaBindOptions } from './solana-options';
|
|
5
|
-
import { ListStateStorage } from '@sentio/base';
|
|
6
|
-
declare type IndexConfigure = {
|
|
7
|
-
startSlot: bigint;
|
|
8
|
-
endSlot?: bigint;
|
|
9
|
-
};
|
|
10
|
-
export declare type SolanaInstructionHandler = (instruction: Instruction, ctx: SolanaContext, accounts?: string[]) => void;
|
|
11
|
-
export declare class SolanaProcessorState extends ListStateStorage<SolanaBaseProcessor> {
|
|
12
|
-
static INSTANCE: SolanaProcessorState;
|
|
13
|
-
}
|
|
14
|
-
export declare class SolanaBaseProcessor {
|
|
15
|
-
instructionHandlerMap: Map<string, SolanaInstructionHandler>;
|
|
16
|
-
address: string;
|
|
17
|
-
endpoint: string;
|
|
18
|
-
contractName: string;
|
|
19
|
-
network: string;
|
|
20
|
-
processInnerInstruction: boolean;
|
|
21
|
-
config: IndexConfigure;
|
|
22
|
-
decodeInstruction: (rawInstruction: string) => Instruction | null;
|
|
23
|
-
fromParsedInstruction: (instruction: {
|
|
24
|
-
type: string;
|
|
25
|
-
info: any;
|
|
26
|
-
}) => Instruction | null;
|
|
27
|
-
constructor(options: SolanaBindOptions);
|
|
28
|
-
bind(options: SolanaBindOptions): void;
|
|
29
|
-
onInstruction(instructionName: string, handler: SolanaInstructionHandler): this;
|
|
30
|
-
getParsedInstruction(ins: string | {
|
|
31
|
-
type: string;
|
|
32
|
-
info: any;
|
|
33
|
-
}): Instruction | null;
|
|
34
|
-
getInstructionHandler(parsedInstruction: Instruction): SolanaInstructionHandler | undefined;
|
|
35
|
-
handleInstruction(parsedInstruction: Instruction, accounts: string[], handler: SolanaInstructionHandler, slot: bigint): ProcessResult;
|
|
36
|
-
isBind(): boolean;
|
|
37
|
-
startSlot(startSlot: bigint | number): this;
|
|
38
|
-
endBlock(endBlock: bigint | number): this;
|
|
39
|
-
}
|
|
40
|
-
export {};
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SolanaBaseProcessor = exports.SolanaProcessorState = void 0;
|
|
4
|
-
const solana_context_1 = require("./solana-context");
|
|
5
|
-
const base_1 = require("@sentio/base");
|
|
6
|
-
const chain_1 = require("../utils/chain");
|
|
7
|
-
class SolanaProcessorState extends base_1.ListStateStorage {
|
|
8
|
-
static INSTANCE = new SolanaProcessorState();
|
|
9
|
-
}
|
|
10
|
-
exports.SolanaProcessorState = SolanaProcessorState;
|
|
11
|
-
class SolanaBaseProcessor {
|
|
12
|
-
instructionHandlerMap = new Map();
|
|
13
|
-
address;
|
|
14
|
-
endpoint;
|
|
15
|
-
contractName;
|
|
16
|
-
network;
|
|
17
|
-
processInnerInstruction;
|
|
18
|
-
config = { startSlot: 0n };
|
|
19
|
-
decodeInstruction;
|
|
20
|
-
fromParsedInstruction;
|
|
21
|
-
constructor(options) {
|
|
22
|
-
if (options) {
|
|
23
|
-
this.bind(options);
|
|
24
|
-
}
|
|
25
|
-
SolanaProcessorState.INSTANCE.addValue(this);
|
|
26
|
-
}
|
|
27
|
-
bind(options) {
|
|
28
|
-
this.address = options.address;
|
|
29
|
-
this.contractName = options.name || '';
|
|
30
|
-
this.processInnerInstruction = options.processInnerInstruction || false;
|
|
31
|
-
this.network = options.network || chain_1.CHAIN_IDS.SOLANA_MAINNET;
|
|
32
|
-
if (options.startBlock) {
|
|
33
|
-
this.startSlot(options.startBlock);
|
|
34
|
-
}
|
|
35
|
-
if (options.endBlock) {
|
|
36
|
-
this.endBlock(options.endBlock);
|
|
37
|
-
}
|
|
38
|
-
this.endpoint = options.network || 'https://api.mainnet-beta.solana.com';
|
|
39
|
-
}
|
|
40
|
-
onInstruction(instructionName, handler) {
|
|
41
|
-
if (!this.isBind()) {
|
|
42
|
-
throw new Error("Processor doesn't bind to an address");
|
|
43
|
-
}
|
|
44
|
-
this.instructionHandlerMap.set(instructionName, handler);
|
|
45
|
-
return this;
|
|
46
|
-
}
|
|
47
|
-
getParsedInstruction(ins) {
|
|
48
|
-
if (ins) {
|
|
49
|
-
if (ins.info) {
|
|
50
|
-
return this.fromParsedInstruction ? this.fromParsedInstruction(ins) : null;
|
|
51
|
-
}
|
|
52
|
-
if (this.decodeInstruction != null) {
|
|
53
|
-
return this.decodeInstruction(ins);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
getInstructionHandler(parsedInstruction) {
|
|
59
|
-
return this.instructionHandlerMap.get(parsedInstruction.name);
|
|
60
|
-
}
|
|
61
|
-
// TODO this should be a async function
|
|
62
|
-
handleInstruction(parsedInstruction, accounts, handler, slot) {
|
|
63
|
-
const ctx = new solana_context_1.SolanaContext(this.contractName, this.network, this.address, slot);
|
|
64
|
-
handler(parsedInstruction, ctx, accounts);
|
|
65
|
-
return ctx.getProcessResult();
|
|
66
|
-
}
|
|
67
|
-
isBind() {
|
|
68
|
-
return this.address !== null;
|
|
69
|
-
}
|
|
70
|
-
startSlot(startSlot) {
|
|
71
|
-
this.config.startSlot = BigInt(startSlot);
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
endBlock(endBlock) {
|
|
75
|
-
this.config.endSlot = BigInt(endBlock);
|
|
76
|
-
return this;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
exports.SolanaBaseProcessor = SolanaBaseProcessor;
|
|
80
|
-
//# sourceMappingURL=solana-processor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"solana-processor.js","sourceRoot":"","sources":["../../src/core/solana-processor.ts"],"names":[],"mappings":";;;AACA,qDAAgD;AAGhD,uCAA+C;AAC/C,0CAA0C;AAS1C,MAAa,oBAAqB,SAAQ,uBAAqC;IAC7E,MAAM,CAAC,QAAQ,GAAyB,IAAI,oBAAoB,EAAE,CAAA;;AADpE,oDAEC;AAED,MAAa,mBAAmB;IACvB,qBAAqB,GAA0C,IAAI,GAAG,EAAE,CAAA;IAC/E,OAAO,CAAQ;IACf,QAAQ,CAAQ;IAChB,YAAY,CAAQ;IACpB,OAAO,CAAQ;IACf,uBAAuB,CAAS;IAChC,MAAM,GAAmB,EAAE,SAAS,EAAE,EAAE,EAAE,CAAA;IAC1C,iBAAiB,CAAgD;IACjE,qBAAqB,CAAkE;IAEvF,YAAY,OAA0B;QACpC,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SACnB;QACD,oBAAoB,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IAC9C,CAAC;IAED,IAAI,CAAC,OAA0B;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CA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I,CAAC,CAAA;IAC/D,CAAC;IAED,uCAAuC;IAChC,iBAAiB,CACtB,iBAA8B,EAC9B,QAAkB,EAClB,OAAiC,EACjC,IAAY;QAEZ,MAAM,GAAG,GAAG,IAAI,8BAAa,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QAClF,OAAO,CAAC,iBAAiB,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAA;QACzC,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;IAC/B,CAAC;IAEM,MAAM;QACX,OAAO,IAAI,CAAC,OAAO,KAAK,IAAI,CAAA;IAC9B,CAAC;IAEM,SAAS,CAAC,SAA0B;QACzC,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;QACzC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,QAAQ,CAAC,QAAyB;QACvC,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;QACtC,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAnFD,kDAmFC","sourcesContent":["import { ProcessResult } from '@sentio/protos'\nimport { SolanaContext } from './solana-context'\nimport { Instruction } from '@project-serum/anchor'\nimport { SolanaBindOptions } from './solana-options'\nimport { ListStateStorage } from '@sentio/base'\nimport { CHAIN_IDS } from '../utils/chain'\n\ntype IndexConfigure = {\n startSlot: bigint\n endSlot?: bigint\n}\n\nexport type SolanaInstructionHandler = (instruction: Instruction, ctx: SolanaContext, accounts?: string[]) => void\n\nexport class SolanaProcessorState extends ListStateStorage<SolanaBaseProcessor> {\n static INSTANCE: SolanaProcessorState = new SolanaProcessorState()\n}\n\nexport class SolanaBaseProcessor {\n public instructionHandlerMap: Map<string, SolanaInstructionHandler> = new Map()\n address: string\n endpoint: string\n contractName: string\n network: string\n processInnerInstruction: boolean\n config: IndexConfigure = { startSlot: 0n }\n decodeInstruction: (rawInstruction: string) => Instruction | null\n fromParsedInstruction: (instruction: { type: string; info: any }) => Instruction | null\n\n constructor(options: SolanaBindOptions) {\n if (options) {\n this.bind(options)\n }\n SolanaProcessorState.INSTANCE.addValue(this)\n }\n\n bind(options: SolanaBindOptions) {\n this.address = options.address\n this.contractName = options.name || ''\n this.processInnerInstruction = options.processInnerInstruction || false\n this.network = options.network || CHAIN_IDS.SOLANA_MAINNET\n if (options.startBlock) {\n this.startSlot(options.startBlock)\n }\n if (options.endBlock) {\n this.endBlock(options.endBlock)\n }\n this.endpoint = options.network || 'https://api.mainnet-beta.solana.com'\n }\n\n public onInstruction(instructionName: string, handler: SolanaInstructionHandler) {\n if (!this.isBind()) {\n throw new Error(\"Processor doesn't bind to an address\")\n }\n\n this.instructionHandlerMap.set(instructionName, handler)\n\n return this\n }\n\n public getParsedInstruction(ins: string | { type: string; info: any }): Instruction | null {\n if (ins) {\n if ((ins as { type: string; info: any }).info) {\n return this.fromParsedInstruction ? this.fromParsedInstruction(ins as { type: string; info: any }) : null\n }\n if (this.decodeInstruction != null) {\n return this.decodeInstruction(ins as string)\n }\n }\n return null\n }\n\n public getInstructionHandler(parsedInstruction: Instruction): SolanaInstructionHandler | undefined {\n return this.instructionHandlerMap.get(parsedInstruction.name)\n }\n\n // TODO this should be a async function\n public handleInstruction(\n parsedInstruction: Instruction,\n accounts: string[],\n handler: SolanaInstructionHandler,\n slot: bigint\n ): ProcessResult {\n const ctx = new SolanaContext(this.contractName, this.network, this.address, slot)\n handler(parsedInstruction, ctx, accounts)\n return ctx.getProcessResult()\n }\n\n public isBind() {\n return this.address !== null\n }\n\n public startSlot(startSlot: bigint | number) {\n this.config.startSlot = BigInt(startSlot)\n return this\n }\n\n public endBlock(endBlock: bigint | number) {\n this.config.endSlot = BigInt(endBlock)\n return this\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function codeGenSolanaProcessor(abisDir: string, targetPath?: string): void;
|