@sentio/sdk 1.20.2 → 1.21.1
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/aptos/aptos-processor.d.ts +16 -15
- package/lib/aptos/aptos-processor.js +65 -13
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/bind-options.d.ts +0 -6
- package/lib/aptos/bind-options.js +1 -8
- package/lib/aptos/bind-options.js.map +1 -1
- package/lib/aptos/context.d.ts +5 -4
- package/lib/aptos/context.js +9 -6
- package/lib/aptos/context.js.map +1 -1
- package/lib/aptos/index.d.ts +3 -2
- package/lib/aptos/index.js +1 -2
- package/lib/aptos/index.js.map +1 -1
- package/lib/aptos/runtime.d.ts +2 -0
- package/lib/aptos/runtime.js +16 -0
- package/lib/aptos/runtime.js.map +1 -0
- package/lib/aptos/types.d.ts +28 -0
- package/lib/aptos/types.js +159 -0
- package/lib/aptos/types.js.map +1 -0
- package/lib/aptos/utils.d.ts +6 -0
- package/lib/aptos/utils.js +19 -0
- package/lib/aptos/utils.js.map +1 -0
- package/lib/aptos-codegen/codegen.d.ts +5 -2
- package/lib/aptos-codegen/codegen.js +195 -17
- package/lib/aptos-codegen/codegen.js.map +1 -1
- package/lib/aptos-codegen/typegen.d.ts +18 -0
- package/lib/aptos-codegen/typegen.js +196 -0
- package/lib/aptos-codegen/typegen.js.map +1 -0
- package/lib/binds.d.ts +2 -3
- package/lib/binds.js +6 -33
- package/lib/binds.js.map +1 -1
- package/lib/builtin/aptos/0x1.d.ts +1624 -0
- package/lib/builtin/aptos/0x1.js +2570 -0
- package/lib/builtin/aptos/0x1.js.map +1 -0
- package/lib/builtin/aptos/0x3.d.ts +414 -0
- package/lib/builtin/aptos/0x3.js +474 -0
- package/lib/builtin/aptos/0x3.js.map +1 -0
- package/lib/builtin/internal/eacaggregatorproxy_processor.d.ts +2 -2
- package/lib/builtin/internal/eacaggregatorproxy_processor.js +12 -11
- package/lib/builtin/internal/eacaggregatorproxy_processor.js.map +1 -1
- package/lib/builtin/internal/erc20_processor.d.ts +2 -2
- package/lib/builtin/internal/erc20_processor.js +12 -11
- package/lib/builtin/internal/erc20_processor.js.map +1 -1
- package/lib/builtin/internal/erc20bytes_processor.d.ts +2 -2
- package/lib/builtin/internal/erc20bytes_processor.js +12 -11
- package/lib/builtin/internal/erc20bytes_processor.js.map +1 -1
- package/lib/builtin/internal/weth9_processor.d.ts +2 -2
- package/lib/builtin/internal/weth9_processor.js +12 -11
- package/lib/builtin/internal/weth9_processor.js.map +1 -1
- package/lib/builtin/solana/types.d.ts +5 -5
- package/lib/builtin/solana/wormhole-processor.d.ts +6 -6
- package/lib/builtin/solana/wormhole-processor.js +15 -12
- package/lib/builtin/solana/wormhole-processor.js.map +1 -1
- package/lib/cli/build.js +17 -16
- package/lib/cli/build.js.map +1 -1
- package/lib/core/base-processor-template.d.ts +7 -7
- package/lib/core/base-processor-template.js.map +1 -1
- package/lib/core/base-processor.d.ts +5 -6
- package/lib/core/base-processor.js +6 -4
- package/lib/core/base-processor.js.map +1 -1
- package/lib/core/big-decimal.d.ts +1 -0
- package/lib/core/big-decimal.js +6 -0
- package/lib/core/big-decimal.js.map +1 -0
- package/lib/core/bind-options.d.ts +0 -2
- package/lib/core/bind-options.js +4 -4
- package/lib/core/bind-options.js.map +1 -1
- package/lib/core/context.d.ts +14 -11
- package/lib/core/context.js +28 -19
- package/lib/core/context.js.map +1 -1
- package/lib/core/generic-processor.js +5 -5
- package/lib/core/generic-processor.js.map +1 -1
- package/lib/core/index.d.ts +5 -5
- package/lib/core/index.js +6 -6
- package/lib/core/index.js.map +1 -1
- package/lib/core/logger.d.ts +2 -3
- package/lib/core/logger.js +6 -6
- package/lib/core/logger.js.map +1 -1
- package/lib/core/metadata.d.ts +7 -4
- package/lib/core/metadata.js +13 -10
- package/lib/core/metadata.js.map +1 -1
- package/lib/core/meter.d.ts +4 -7
- package/lib/core/meter.js +12 -13
- package/lib/core/meter.js.map +1 -1
- package/lib/core/solana-processor.d.ts +7 -4
- package/lib/core/solana-processor.js +14 -20
- package/lib/core/solana-processor.js.map +1 -1
- package/lib/core/sui-processor.d.ts +5 -4
- package/lib/core/sui-processor.js +10 -17
- package/lib/core/sui-processor.js.map +1 -1
- package/lib/error.d.ts +2 -2
- package/lib/error.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +24 -12
- package/lib/gen/processor/protos/processor.js +147 -58
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/index.d.ts +1 -2
- package/lib/index.js +1 -4
- package/lib/index.js.map +1 -1
- package/lib/processor-state.d.ts +1 -1
- package/lib/processor-state.js.map +1 -1
- package/lib/service.js +15 -13
- package/lib/service.js.map +1 -1
- package/lib/target-ethers-sentio/codegen.js +14 -15
- package/lib/target-ethers-sentio/codegen.js.map +1 -1
- package/lib/test-abi-code-gen.js.map +1 -1
- package/lib/testing/metric-utils.js +2 -2
- package/lib/testing/metric-utils.js.map +1 -1
- package/lib/tests/aptos.test.js +95 -2
- package/lib/tests/aptos.test.js.map +1 -1
- package/lib/tests/erc20.js +1 -1
- package/lib/tests/erc20.js.map +1 -1
- package/lib/tests/erc20.test.js +3 -4
- package/lib/tests/erc20.test.js.map +1 -1
- package/lib/tests/solana.test.js +5 -1
- package/lib/tests/solana.test.js.map +1 -1
- package/lib/tests/souffl3.js +17 -4
- package/lib/tests/souffl3.js.map +1 -1
- package/lib/tests/sui.test.js +1 -4
- package/lib/tests/sui.test.js.map +1 -1
- package/lib/tests/types/aptos/souffle.d.ts +311 -22
- package/lib/tests/types/aptos/souffle.js +172 -20
- package/lib/tests/types/aptos/souffle.js.map +1 -1
- package/lib/tests/types/solana/basic_1_processor.d.ts +2 -2
- package/lib/tests/types/solana/basic_1_processor.js +4 -4
- package/lib/tests/types/solana/basic_1_processor.js.map +1 -1
- package/lib/tests/wormhole-token-bridge.js +2 -1
- package/lib/tests/wormhole-token-bridge.js.map +1 -1
- package/lib/utils/chain.d.ts +1 -0
- package/lib/utils/chain.js +15 -1
- package/lib/utils/chain.js.map +1 -1
- package/lib/utils/conversion.d.ts +1 -1
- package/lib/utils/conversion.js.map +1 -1
- package/package.json +3 -2
- package/src/abis/aptos/0x1.json +9205 -0
- package/src/abis/aptos/0x3.json +1515 -0
- package/src/aptos/aptos-processor.ts +89 -25
- package/src/aptos/bind-options.ts +0 -7
- package/src/aptos/context.ts +11 -8
- package/src/aptos/index.ts +3 -2
- package/src/aptos/runtime.ts +13 -0
- package/src/aptos/types.ts +203 -0
- package/src/aptos/utils.ts +18 -0
- package/src/aptos-codegen/codegen.ts +222 -18
- package/src/aptos-codegen/typegen.test.ts +29 -0
- package/src/aptos-codegen/typegen.ts +216 -0
- package/src/binds.ts +5 -39
- package/src/builtin/aptos/0x1.ts +3917 -0
- package/src/builtin/aptos/0x3.ts +824 -0
- package/src/builtin/internal/eacaggregatorproxy_processor.ts +14 -31
- package/src/builtin/internal/erc20_processor.ts +14 -25
- package/src/builtin/internal/erc20bytes_processor.ts +14 -25
- package/src/builtin/internal/weth9_processor.ts +14 -25
- package/src/builtin/solana/wormhole-processor.ts +21 -18
- package/src/cli/build.ts +19 -17
- package/src/core/base-processor-template.ts +7 -7
- package/src/core/base-processor.ts +30 -9
- package/src/core/big-decimal.ts +1 -0
- package/src/core/bind-options.ts +3 -2
- package/src/core/context.ts +40 -24
- package/src/core/generic-processor.ts +6 -7
- package/src/core/index.ts +5 -5
- package/src/core/logger.ts +7 -7
- package/src/core/metadata.ts +14 -12
- package/src/core/meter.ts +12 -14
- package/src/core/solana-processor.ts +24 -21
- package/src/core/sui-processor.ts +10 -21
- package/src/error.ts +2 -2
- package/src/gen/processor/protos/processor.ts +177 -69
- package/src/index.ts +1 -2
- package/src/processor-state.ts +1 -1
- package/src/service.ts +23 -16
- package/src/target-ethers-sentio/codegen.ts +14 -15
- package/src/test-abi-code-gen.ts +1 -0
- package/src/testing/metric-utils.ts +2 -2
- package/src/tests/aptos.test.ts +102 -3
- package/src/tests/erc20.test.ts +3 -4
- package/src/tests/erc20.ts +1 -1
- package/src/tests/solana.test.ts +5 -1
- package/src/tests/souffl3.ts +21 -6
- package/src/tests/sui.test.ts +1 -4
- package/src/tests/types/aptos/souffle.ts +470 -56
- package/src/tests/types/solana/basic_1_processor.ts +6 -6
- package/src/tests/wormhole-token-bridge.ts +2 -1
- package/src/types/global.d.ts +1 -1
- package/src/utils/chain.ts +14 -0
- package/src/utils/conversion.ts +1 -1
- package/lib/contract-namer.d.ts +0 -6
- package/lib/contract-namer.js +0 -20
- package/lib/contract-namer.js.map +0 -1
- package/src/aptos-codegen/codgen.test.ts +0 -11
- package/src/contract-namer.ts +0 -17
|
@@ -71,6 +71,9 @@ class TokenBridgeProcessor extends sdk_1.SolanaBaseProcessor {
|
|
|
71
71
|
borsh.publicKey('bridge')
|
|
72
72
|
];
|
|
73
73
|
static bind(options) {
|
|
74
|
+
if (options && !options.name) {
|
|
75
|
+
options.name = 'WormholeTokenBridge';
|
|
76
|
+
}
|
|
74
77
|
return new TokenBridgeProcessor(options);
|
|
75
78
|
}
|
|
76
79
|
decodeInstruction = (ins) => {
|
|
@@ -140,49 +143,49 @@ class TokenBridgeProcessor extends sdk_1.SolanaBaseProcessor {
|
|
|
140
143
|
}
|
|
141
144
|
};
|
|
142
145
|
onInitialize(handler) {
|
|
143
|
-
this.onInstruction('Initialize', (ins, ctx) => {
|
|
146
|
+
this.onInstruction('Initialize', (ins, ctx, accounts) => {
|
|
144
147
|
if (ins) {
|
|
145
|
-
handler(ins.data, ctx);
|
|
148
|
+
handler(ins.data, accounts, ctx);
|
|
146
149
|
}
|
|
147
150
|
});
|
|
148
151
|
return this;
|
|
149
152
|
}
|
|
150
153
|
onAttestToken(handler) {
|
|
151
|
-
this.onInstruction('AttestToken', (ins, ctx) => {
|
|
154
|
+
this.onInstruction('AttestToken', (ins, ctx, accounts) => {
|
|
152
155
|
if (ins) {
|
|
153
|
-
handler(ins.data, ctx);
|
|
156
|
+
handler(ins.data, accounts, ctx);
|
|
154
157
|
}
|
|
155
158
|
});
|
|
156
159
|
return this;
|
|
157
160
|
}
|
|
158
161
|
onTransferWrapped(handler) {
|
|
159
|
-
this.onInstruction('TransferWrapped', (ins, ctx) => {
|
|
162
|
+
this.onInstruction('TransferWrapped', (ins, ctx, accounts) => {
|
|
160
163
|
if (ins) {
|
|
161
|
-
handler(ins.data, ctx);
|
|
164
|
+
handler(ins.data, accounts, ctx);
|
|
162
165
|
}
|
|
163
166
|
});
|
|
164
167
|
return this;
|
|
165
168
|
}
|
|
166
169
|
onTransferNativeWithPayload(handler) {
|
|
167
|
-
this.onInstruction('TransferNativeWithPayload', (ins, ctx) => {
|
|
170
|
+
this.onInstruction('TransferNativeWithPayload', (ins, ctx, accounts) => {
|
|
168
171
|
if (ins) {
|
|
169
|
-
handler(ins.data, ctx);
|
|
172
|
+
handler(ins.data, accounts, ctx);
|
|
170
173
|
}
|
|
171
174
|
});
|
|
172
175
|
return this;
|
|
173
176
|
}
|
|
174
177
|
onTransferWrappedWithPaylod(handler) {
|
|
175
|
-
this.onInstruction('TransferWrappedWithPaylod', (ins, ctx) => {
|
|
178
|
+
this.onInstruction('TransferWrappedWithPaylod', (ins, ctx, accounts) => {
|
|
176
179
|
if (ins) {
|
|
177
|
-
handler(ins.data, ctx);
|
|
180
|
+
handler(ins.data, accounts, ctx);
|
|
178
181
|
}
|
|
179
182
|
});
|
|
180
183
|
return this;
|
|
181
184
|
}
|
|
182
185
|
onTransferNative(handler) {
|
|
183
|
-
this.onInstruction('TransferNative', (ins, ctx) => {
|
|
186
|
+
this.onInstruction('TransferNative', (ins, ctx, accounts) => {
|
|
184
187
|
if (ins) {
|
|
185
|
-
handler(ins.data, ctx);
|
|
188
|
+
handler(ins.data, accounts, ctx);
|
|
186
189
|
}
|
|
187
190
|
});
|
|
188
191
|
return this;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wormhole-processor.js","sourceRoot":"","sources":["../../../src/builtin/solana/wormhole-processor.ts"],"names":[],"m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,IAAI,CAAA;IACb,CAAC;IAED,2BAA2B,CAAC,OAAgD;QAC1E,IAAI,CAAC,aAAa,CAAC,2BAA2B,EAAE,CAAC,GAAgB,EAAE,GAAG,EAAE,EAAE;YACxE,IAAI,GAAG,EAAE;gBACP,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;aACvB;QACH,CAAC,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAED,2BAA2B,CAAC,OAAgD;QAC1E,IAAI,CAAC,aAAa,CAAC,2BAA2B,EAAE,CAAC,GAAgB,EAAE,GAAG,EAAE,EAAE;YACxE,IAAI,GAAG,EAAE;gBACP,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;aACvB;QACH,CAAC,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAED,gBAAgB,CAAC,OAAgD;QAC/D,IAAI,CAAC,aAAa,CAAC,gBAAgB,EAAE,CAAC,GAAgB,EAAE,GAAG,EAAE,EAAE;YAC7D,IAAI,GAAG,EAAE;gBACP,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;aACvB;QACH,CAAC,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAxJD,oDAwJC","sourcesContent":["import { SolanaBaseProcessor, SolanaContext, SolanaBindOptions } from '@sentio/sdk'\nimport { Instruction } from '@project-serum/anchor'\nimport * as borsh from '@project-serum/borsh'\nimport bs58 from 'bs58'\n\n// https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/lib.rs#L100\nenum TokenBrigeInstruction {\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\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 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 TokenBrigeInstruction.Initialize:\n return {\n data: '',\n name: TokenBrigeInstruction[TokenBrigeInstruction.Initialize]\n }\n case TokenBrigeInstruction.TransferNative:\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: TokenBrigeInstruction[TokenBrigeInstruction.TransferNative]\n }\n case TokenBrigeInstruction.TransferWrapped:\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: TokenBrigeInstruction[TokenBrigeInstruction.TransferWrapped]\n }\n case TokenBrigeInstruction.TransferNativeWithPayload:\n data = borsh.struct(this.transferDataWithPayloadValues, 'TransferNativeWithPayloadData').decode(Buffer.from(u8Arr.slice(1)))\n return {\n data,\n name: TokenBrigeInstruction[TokenBrigeInstruction.TransferNativeWithPayload]\n }\n case TokenBrigeInstruction.TransferWrappedWithPayload:\n data = borsh.struct(this.transferDataWithPayloadValues, 'TransferWrappedWithPayloadData').decode(Buffer.from(u8Arr.slice(1)))\n return {\n data,\n name: TokenBrigeInstruction[TokenBrigeInstruction.TransferWrappedWithPayload]\n }\n case TokenBrigeInstruction.Initialize:\n data = borsh.struct(this.initializeDataValues, 'InitializeData').decode(Buffer.from(u8Arr.slice(1)))\n return {\n data,\n name: TokenBrigeInstruction[TokenBrigeInstruction.Initialize]\n }\n case TokenBrigeInstruction.AttestToken:\n data = borsh.struct(this.attestTokenValues, 'AttestTokenData').decode(Buffer.from(u8Arr.slice(1)))\n return {\n data,\n name: TokenBrigeInstruction[TokenBrigeInstruction.AttestToken]\n }\n case TokenBrigeInstruction.CompleteNative:\n case TokenBrigeInstruction.CompleteNativeWithPayload:\n case TokenBrigeInstruction.CompleteWrapped:\n case TokenBrigeInstruction.CompleteWrappedWithPayload:\n case TokenBrigeInstruction.CreateWrapped:\n case TokenBrigeInstruction.UpgradeContract:\n case TokenBrigeInstruction.RegisterChain:\n return {\n data: '',\n name: TokenBrigeInstruction[u8Arr[0]]\n }\n\n default:\n return null\n }\n }\n\n onInitialize(handler: (args: any, ctx: SolanaContext) => void): TokenBridgeProcessor {\n this.onInstruction('Initialize', (ins: Instruction, ctx) => {\n if (ins) {\n handler(ins.data, ctx)\n }\n })\n return this\n }\n\n onAttestToken(handler: (args: any, ctx: SolanaContext) => void): TokenBridgeProcessor {\n this.onInstruction('AttestToken', (ins: Instruction, ctx) => {\n if (ins) {\n handler(ins.data, ctx)\n }\n })\n return this\n }\n\n\n onTransferWrapped(handler: (args: any, ctx: SolanaContext) => void): TokenBridgeProcessor {\n this.onInstruction('TransferWrapped', (ins: Instruction, ctx) => {\n if (ins) {\n handler(ins.data, ctx)\n }\n })\n return this\n }\n\n onTransferNativeWithPayload(handler: (args: any, ctx: SolanaContext) => void): TokenBridgeProcessor {\n this.onInstruction('TransferNativeWithPayload', (ins: Instruction, ctx) => {\n if (ins) {\n handler(ins.data, ctx)\n }\n })\n return this\n }\n\n onTransferWrappedWithPaylod(handler: (args: any, ctx: SolanaContext) => void): TokenBridgeProcessor {\n this.onInstruction('TransferWrappedWithPaylod', (ins: Instruction, ctx) => {\n if (ins) {\n handler(ins.data, ctx)\n }\n })\n return this\n }\n\n onTransferNative(handler: (args: any, ctx: SolanaContext) => void): TokenBridgeProcessor {\n this.onInstruction('TransferNative', (ins: Instruction, ctx) => {\n if (ins) {\n handler(ins.data, ctx)\n }\n })\n return this\n }\n}\n "]}
|
|
1
|
+
{"version":3,"file":"wormhole-processor.js","sourceRoot":"","sources":["../../../src/builtin/solana/wormhole-processor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAmF;AAEnF,4DAA6C;AAC7C,gDAAuB;AAEvB,0IAA0I;AAC1I,IAAK,qBAcJ;AAdD,WAAK,qBAAqB;IACxB,6EAAc,CAAA;IACd,+EAAW,CAAA;IACX,qFAAc,CAAA;IACd,uFAAe,CAAA;IACf,uFAAe,CAAA;IACf,qFAAc,CAAA;IACd,mFAAa,CAAA;IACb,mFAAa,CAAA;IACb,uFAAe,CAAA;IACf,2GAAyB,CAAA;IACzB,8GAA0B,CAAA;IAC1B,8GAA0B,CAAA;IAC1B,4GAAyB,CAAA;AAC3B,CAAC,EAdI,qBAAqB,KAArB,qBAAqB,QAczB;AAED,MAAa,oBAAqB,SAAQ,yBAAmB;IAE1C,kBAAkB,GAAG;QACpC,KAAK,CAAC,GAAG,CAAC,OAAO,CAA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AC,aAAa,CAAC,2BAA2B,EAAE,CAAC,GAAgB,EAAE,GAAG,EAAE,QAAkB,EAAE,EAAE;YAC5F,IAAI,GAAG,EAAE;gBACP,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAA;aACjC;QACH,CAAC,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAED,gBAAgB,CAAC,OAAoE;QACnF,IAAI,CAAC,aAAa,CAAC,gBAAgB,EAAE,CAAC,GAAgB,EAAE,GAAG,EAAE,QAAkB,EAAE,EAAE;YACjF,IAAI,GAAG,EAAE;gBACP,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAA;aACjC;QACH,CAAC,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA3JD,oDA2JC","sourcesContent":["import { SolanaBaseProcessor, SolanaContext, SolanaBindOptions } from '@sentio/sdk'\nimport { Instruction } from '@project-serum/anchor'\nimport * as borsh from '@project-serum/borsh'\nimport bs58 from 'bs58'\n\n// https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/lib.rs#L100\nenum TokenBrigeInstruction {\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\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 TokenBrigeInstruction.Initialize:\n return {\n data: '',\n name: TokenBrigeInstruction[TokenBrigeInstruction.Initialize]\n }\n case TokenBrigeInstruction.TransferNative:\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: TokenBrigeInstruction[TokenBrigeInstruction.TransferNative]\n }\n case TokenBrigeInstruction.TransferWrapped:\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: TokenBrigeInstruction[TokenBrigeInstruction.TransferWrapped]\n }\n case TokenBrigeInstruction.TransferNativeWithPayload:\n data = borsh.struct(this.transferDataWithPayloadValues, 'TransferNativeWithPayloadData').decode(Buffer.from(u8Arr.slice(1)))\n return {\n data,\n name: TokenBrigeInstruction[TokenBrigeInstruction.TransferNativeWithPayload]\n }\n case TokenBrigeInstruction.TransferWrappedWithPayload:\n data = borsh.struct(this.transferDataWithPayloadValues, 'TransferWrappedWithPayloadData').decode(Buffer.from(u8Arr.slice(1)))\n return {\n data,\n name: TokenBrigeInstruction[TokenBrigeInstruction.TransferWrappedWithPayload]\n }\n case TokenBrigeInstruction.Initialize:\n data = borsh.struct(this.initializeDataValues, 'InitializeData').decode(Buffer.from(u8Arr.slice(1)))\n return {\n data,\n name: TokenBrigeInstruction[TokenBrigeInstruction.Initialize]\n }\n case TokenBrigeInstruction.AttestToken:\n data = borsh.struct(this.attestTokenValues, 'AttestTokenData').decode(Buffer.from(u8Arr.slice(1)))\n return {\n data,\n name: TokenBrigeInstruction[TokenBrigeInstruction.AttestToken]\n }\n case TokenBrigeInstruction.CompleteNative:\n case TokenBrigeInstruction.CompleteNativeWithPayload:\n case TokenBrigeInstruction.CompleteWrapped:\n case TokenBrigeInstruction.CompleteWrappedWithPayload:\n case TokenBrigeInstruction.CreateWrapped:\n case TokenBrigeInstruction.UpgradeContract:\n case TokenBrigeInstruction.RegisterChain:\n return {\n data: '',\n name: TokenBrigeInstruction[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 "]}
|
package/lib/cli/build.js
CHANGED
|
@@ -40,20 +40,21 @@ function codeGenAptosProcessor(abisDir, outDir = 'src/types/aptos') {
|
|
|
40
40
|
if (!fs_1.default.existsSync(abisDir)) {
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
|
-
const files =
|
|
43
|
+
// const files = fs.readdirSync(abisDir)
|
|
44
44
|
console.log(chalk_1.default.green('Generated Types for Aptos'));
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
45
|
+
(0, codegen_1.generate)(abisDir, outDir);
|
|
46
|
+
// for (const file of files) {
|
|
47
|
+
// if (path.extname(file) === '.json') {
|
|
48
|
+
// if (!fs.existsSync(outDir)) {
|
|
49
|
+
// fs.mkdirSync(outDir, { recursive: true })
|
|
50
|
+
// }
|
|
51
|
+
// }
|
|
52
|
+
// const codegen = new AptosAccountCodegen({
|
|
53
|
+
// srcFile: path.join(abisDir, file),
|
|
54
|
+
// outputDir: outDir,
|
|
55
|
+
// })
|
|
56
|
+
// codegen.generate()
|
|
57
|
+
// }
|
|
57
58
|
}
|
|
58
59
|
exports.codeGenAptosProcessor = codeGenAptosProcessor;
|
|
59
60
|
async function codeGenEthersProcessor(abisDir, ETHERS_TARGET = path_1.default.join(__dirname, '../target-ethers-sentio'), outDir = 'src/types/internal') {
|
|
@@ -131,10 +132,10 @@ function codeGenSolanaInstruction(idlName, ins) {
|
|
|
131
132
|
const instructionName = ins.name;
|
|
132
133
|
const argsTypeString = codeGenInstructionArgs(ins.args);
|
|
133
134
|
return `
|
|
134
|
-
on${instructionName.charAt(0).toUpperCase() + instructionName.slice(1)}(handler: (args: ${argsTypeString}, ctx: SolanaContext) => void): ${idlName}Processor {
|
|
135
|
-
this.onInstruction('${instructionName}', (ins: Instruction, ctx) => {
|
|
135
|
+
on${instructionName.charAt(0).toUpperCase() + instructionName.slice(1)}(handler: (args: ${argsTypeString}, accounts: string[], ctx: SolanaContext) => void): ${idlName}Processor {
|
|
136
|
+
this.onInstruction('${instructionName}', (ins: Instruction, ctx, accounts: string[]) => {
|
|
136
137
|
if (ins) {
|
|
137
|
-
handler(ins.data as ${argsTypeString}, ctx)
|
|
138
|
+
handler(ins.data as ${argsTypeString}, accounts, ctx)
|
|
138
139
|
}
|
|
139
140
|
})
|
|
140
141
|
return this
|
package/lib/cli/build.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyB;AACzB,gDAAuB;AACvB,4CAAmB;AACnB,iDAAoC;AACpC,sDAAuD;AACvD,iDAAiD;AAE1C,KAAK,UAAU,cAAc,CAAC,OAAgB;IACnD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,WAAW,EAAE,CAAA;KACpB;IAED,oFAAoF;IACpF,uBAAuB;IACvB,MAAM,uBAAuB,CAAC,OAAO,CAAC,CAAA;IACtC,IAAI;IAEJ,IAAI,CAAC,OAAO,EAAE;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C,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAEjC,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC5B,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAC5B,CAAC,CAAC,CAAA;IAEF,IAAI,KAAK,CAAC,QAAQ,EAAE;QAClB,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAA;QAC9C,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;KAC7B;IACD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAA;IAC9C,OAAO,CAAC,GAAG,EAAE,CAAA;AACf,CAAC","sourcesContent":["import chalk from 'chalk'\nimport path from 'path'\nimport fs from 'fs'\nimport { exec } from 'child_process'\nimport { AptosCodegen } from '../aptos-codegen/codegen'\n// import { EVM, SOLANA, Target } from './config'\n\nexport async function buildProcessor(onlyGen: boolean) {\n if (!onlyGen) {\n await installDeps()\n }\n\n // targets.forEach(async (target) => await buildProcessorForTarget(onlyGen, target))\n // for (const target) {\n await buildProcessorForTarget(onlyGen)\n // }\n\n if (!onlyGen) {\n const WEBPACK_CONFIG = path.join(__dirname, 'webpack.config.js')\n await execStep('yarn tsc -p .', 'Compile')\n await execStep('yarn webpack --config=' + WEBPACK_CONFIG, 'Packaging')\n }\n}\n\nasync function buildProcessorForTarget(onlyGen: boolean) {\n await codeGenEthersProcessor(path.join('abis', 'evm'))\n codeGenSolanaProcessor(path.join('abis', 'solana'))\n codeGenAptosProcessor(path.join('abis', 'aptos'))\n\n if (onlyGen) {\n return\n }\n}\n\nasync function installDeps() {\n await execStep('yarn install --ignore-scripts', 'Yarn Install')\n}\n\nexport function codeGenAptosProcessor(abisDir: string, outDir = 'src/types/aptos') {\n if (!fs.existsSync(abisDir)) {\n return\n }\n\n const files = fs.readdirSync(abisDir)\n\n console.log(chalk.green('Generated Types for Aptos'))\n for (const file of files) {\n if (path.extname(file) === '.json') {\n if (!fs.existsSync(outDir)) {\n fs.mkdirSync(outDir, { recursive: true })\n }\n }\n const codegen = new AptosCodegen({\n srcFile: path.join(abisDir, file),\n outputDir: outDir,\n })\n codegen.generate()\n }\n}\n\nexport async function codeGenEthersProcessor(\n abisDir: string,\n ETHERS_TARGET = path.join(__dirname, '../target-ethers-sentio'),\n outDir = 'src/types/internal'\n) {\n if (!fs.existsSync(abisDir)) {\n return\n }\n\n let haveJson = false\n const files = fs.readdirSync(abisDir)\n for (const file of files) {\n if (file.toLowerCase().endsWith('.json')) {\n haveJson = true\n break\n }\n }\n if (!haveJson) {\n return\n }\n\n console.log(chalk.green('Generated Types for EVM'))\n\n // TODO this will fail during postinstall, need to locate real typechain path\n await execStep(\n 'yarn typechain --target ' + ETHERS_TARGET + ` --out-dir ${outDir} ${path.join(abisDir, '*.json')}`,\n 'Type definitions gen'\n )\n}\n\nexport function codeGenSolanaProcessor(abisDir: string, targetPath = path.join('src', 'types', 'solana')) {\n if (!fs.existsSync(abisDir)) {\n return\n }\n\n const abisFiles = fs.readdirSync(abisDir)\n\n if (abisFiles.length > 0) {\n console.log(chalk.green('Generated Types for Solana'))\n }\n\n for (const file of abisFiles) {\n if (path.extname(file) === '.json') {\n if (!fs.existsSync(targetPath)) {\n fs.mkdirSync(targetPath, { recursive: true })\n }\n const idlContent = fs.readFileSync(path.join(abisDir, file), 'utf-8')\n const idlObj = JSON.parse(idlContent)\n const idlName = idlObj.name\n const idlFile = path.join(targetPath, idlName + '.ts')\n fs.writeFileSync(idlFile, `export const ${idlName}_idl = ${idlContent}`)\n fs.writeFileSync(path.join(targetPath, `${idlName}_processor.ts`), codeGenSolanaIdlProcessor(idlObj))\n }\n }\n}\n\nfunction codeGenSolanaIdlProcessor(idlObj: any): string {\n const idlName = idlObj.name\n const idlNamePascalCase = toPascalCase(idlName)\n const instructions: any[] = idlObj.instructions\n return `import { BorshInstructionCoder, Instruction, Idl, BN } from '@project-serum/anchor'\nimport { SolanaBaseProcessor, SolanaContext, SolanaBindOptions } from \"@sentio/sdk\"\nimport { ${idlName}_idl } from \"./${idlName}\"\nimport bs58 from 'bs58'\nimport { PublicKey } from '@solana/web3.js'\n\nexport class ${idlNamePascalCase}Processor extends SolanaBaseProcessor {\n static bind(options: SolanaBindOptions): ${idlNamePascalCase}Processor {\n if (options && !options.name) {\n options.name = '${idlNamePascalCase}'\n }\n return new ${idlNamePascalCase}Processor(options)\n }\n\n decodeInstruction: (rawInstruction: string) => Instruction | null = (rawInstruction) => {\n const instructionCoder = new BorshInstructionCoder(${idlName}_idl as Idl)\n const decodedIns = instructionCoder.decode(Buffer.from(bs58.decode(rawInstruction)))\n return decodedIns\n }\n\n ${instructions.map((ins) => codeGenSolanaInstruction(idlNamePascalCase, ins)).join('')}\n}\n `\n}\n\nfunction codeGenSolanaInstruction(idlName: string, ins: any): string {\n const instructionName = ins.name\n const argsTypeString = codeGenInstructionArgs(ins.args)\n return `\n on${\n instructionName.charAt(0).toUpperCase() + instructionName.slice(1)\n }(handler: (args: ${argsTypeString}, ctx: SolanaContext) => void): ${idlName}Processor {\n this.onInstruction('${instructionName}', (ins: Instruction, ctx) => {\n if (ins) {\n handler(ins.data as ${argsTypeString}, ctx)\n }\n })\n return this\n }\n `\n}\n\nfunction codeGenInstructionArgs(args: { name: string; type: string }[]): string {\n return `{ ${args.map((arg) => arg.name + ': ' + mapType(arg.type)).join(', ')} }`\n}\n\n// Reference: https://github.com/coral-xyz/anchor/blob/93332766f13e86efbe77c9986722731742317ede/ts/src/program/namespace/types.ts#L104\nfunction mapType(tpe: string): string {\n switch (tpe) {\n case 'publicKey':\n return 'PublicKey'\n case 'bool':\n return 'boolean'\n case 'string':\n return 'string'\n case 'u8':\n case 'i8':\n case 'u16':\n case 'i16':\n case 'u32':\n case 'i32':\n case 'f32':\n case 'f64':\n return 'number'\n case 'u64':\n case 'i64':\n case 'u128':\n case 'i128':\n return 'BN'\n default:\n return 'any'\n }\n}\n\nfunction toPascalCase(str: string) {\n return `${str}`\n .toLowerCase()\n .replace(new RegExp(/[-_]+/, 'g'), ' ')\n .replace(new RegExp(/[^\\w\\s]/, 'g'), '')\n .replace(new RegExp(/\\s+(.)(\\w*)/, 'g'), ($1, $2, $3) => `${$2.toUpperCase() + $3}`)\n .replace(new RegExp(/\\w/), (s) => s.toUpperCase())\n}\n\nasync function execStep(cmd: string, stepName: string) {\n const child = exec(cmd)\n console.log(chalk.blue(stepName + ' begin'))\n\n if (!child.stdout || !child.stderr) {\n console.error(chalk.red(stepName + ' failed'))\n process.exit(1)\n }\n\n child.stdout.pipe(process.stdout)\n child.stderr.pipe(process.stderr)\n\n await new Promise((resolve) => {\n child.on('close', resolve)\n })\n\n if (child.exitCode) {\n console.error(chalk.red(stepName + ' failed'))\n process.exit(child.exitCode)\n }\n console.log(chalk.blue(stepName + ' success'))\n console.log()\n}\n"]}
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyB;AACzB,gDAAuB;AACvB,4CAAmB;AACnB,iDAAoC;AACpC,sDAAmD;AACnD,iDAAiD;AAE1C,KAAK,UAAU,cAAc,CAAC,OAAgB;IACnD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,WAAW,EAAE,CAAA;KACpB;IAED,oFAAoF;IACpF,uBAAuB;IACvB,MAAM,uBAAuB,CAAC,OAAO,CAAC,CAAA;IACtC,IAAI;IAEJ,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,cAAc,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAA;QAChE,MAAM,QAAQ,CAAC,eAAe,EAAE,SAAS,CAAC,CAAA;QAC1C,MAAM,QAAQ,CAAC,wBAAwB,GAAG,cAAc,EAAE,WAAW,CAAC,CAAA;KACvE;AACH,C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AG,EAAE,CAAA;AACf,CAAC","sourcesContent":["import chalk from 'chalk'\nimport path from 'path'\nimport fs from 'fs'\nimport { exec } from 'child_process'\nimport { generate } from '../aptos-codegen/codegen'\n// import { EVM, SOLANA, Target } from './config'\n\nexport async function buildProcessor(onlyGen: boolean) {\n if (!onlyGen) {\n await installDeps()\n }\n\n // targets.forEach(async (target) => await buildProcessorForTarget(onlyGen, target))\n // for (const target) {\n await buildProcessorForTarget(onlyGen)\n // }\n\n if (!onlyGen) {\n const WEBPACK_CONFIG = path.join(__dirname, 'webpack.config.js')\n await execStep('yarn tsc -p .', 'Compile')\n await execStep('yarn webpack --config=' + WEBPACK_CONFIG, 'Packaging')\n }\n}\n\nasync function buildProcessorForTarget(onlyGen: boolean) {\n await codeGenEthersProcessor(path.join('abis', 'evm'))\n codeGenSolanaProcessor(path.join('abis', 'solana'))\n codeGenAptosProcessor(path.join('abis', 'aptos'))\n\n if (onlyGen) {\n return\n }\n}\n\nasync function installDeps() {\n await execStep('yarn install --ignore-scripts', 'Yarn Install')\n}\n\nexport function codeGenAptosProcessor(abisDir: string, outDir = 'src/types/aptos') {\n if (!fs.existsSync(abisDir)) {\n return\n }\n\n // const files = fs.readdirSync(abisDir)\n\n console.log(chalk.green('Generated Types for Aptos'))\n\n generate(abisDir, outDir)\n // for (const file of files) {\n // if (path.extname(file) === '.json') {\n // if (!fs.existsSync(outDir)) {\n // fs.mkdirSync(outDir, { recursive: true })\n // }\n // }\n // const codegen = new AptosAccountCodegen({\n // srcFile: path.join(abisDir, file),\n // outputDir: outDir,\n // })\n // codegen.generate()\n // }\n}\n\nexport async function codeGenEthersProcessor(\n abisDir: string,\n ETHERS_TARGET = path.join(__dirname, '../target-ethers-sentio'),\n outDir = 'src/types/internal'\n) {\n if (!fs.existsSync(abisDir)) {\n return\n }\n\n let haveJson = false\n const files = fs.readdirSync(abisDir)\n for (const file of files) {\n if (file.toLowerCase().endsWith('.json')) {\n haveJson = true\n break\n }\n }\n if (!haveJson) {\n return\n }\n\n console.log(chalk.green('Generated Types for EVM'))\n\n // TODO this will fail during postinstall, need to locate real typechain path\n await execStep(\n 'yarn typechain --target ' + ETHERS_TARGET + ` --out-dir ${outDir} ${path.join(abisDir, '*.json')}`,\n 'Type definitions gen'\n )\n}\n\nexport function codeGenSolanaProcessor(abisDir: string, targetPath = path.join('src', 'types', 'solana')) {\n if (!fs.existsSync(abisDir)) {\n return\n }\n\n const abisFiles = fs.readdirSync(abisDir)\n\n if (abisFiles.length > 0) {\n console.log(chalk.green('Generated Types for Solana'))\n }\n\n for (const file of abisFiles) {\n if (path.extname(file) === '.json') {\n if (!fs.existsSync(targetPath)) {\n fs.mkdirSync(targetPath, { recursive: true })\n }\n const idlContent = fs.readFileSync(path.join(abisDir, file), 'utf-8')\n const idlObj = JSON.parse(idlContent)\n const idlName = idlObj.name\n const idlFile = path.join(targetPath, idlName + '.ts')\n fs.writeFileSync(idlFile, `export const ${idlName}_idl = ${idlContent}`)\n fs.writeFileSync(path.join(targetPath, `${idlName}_processor.ts`), codeGenSolanaIdlProcessor(idlObj))\n }\n }\n}\n\nfunction codeGenSolanaIdlProcessor(idlObj: any): string {\n const idlName = idlObj.name\n const idlNamePascalCase = toPascalCase(idlName)\n const instructions: any[] = idlObj.instructions\n return `import { BorshInstructionCoder, Instruction, Idl, BN } from '@project-serum/anchor'\nimport { SolanaBaseProcessor, SolanaContext, SolanaBindOptions } from \"@sentio/sdk\"\nimport { ${idlName}_idl } from \"./${idlName}\"\nimport bs58 from 'bs58'\nimport { PublicKey } from '@solana/web3.js'\n\nexport class ${idlNamePascalCase}Processor extends SolanaBaseProcessor {\n static bind(options: SolanaBindOptions): ${idlNamePascalCase}Processor {\n if (options && !options.name) {\n options.name = '${idlNamePascalCase}'\n }\n return new ${idlNamePascalCase}Processor(options)\n }\n\n decodeInstruction: (rawInstruction: string) => Instruction | null = (rawInstruction) => {\n const instructionCoder = new BorshInstructionCoder(${idlName}_idl as Idl)\n const decodedIns = instructionCoder.decode(Buffer.from(bs58.decode(rawInstruction)))\n return decodedIns\n }\n\n ${instructions.map((ins) => codeGenSolanaInstruction(idlNamePascalCase, ins)).join('')}\n}\n `\n}\n\nfunction codeGenSolanaInstruction(idlName: string, ins: any): string {\n const instructionName = ins.name\n const argsTypeString = codeGenInstructionArgs(ins.args)\n return `\n on${\n instructionName.charAt(0).toUpperCase() + instructionName.slice(1)\n }(handler: (args: ${argsTypeString}, accounts: string[], ctx: SolanaContext) => void): ${idlName}Processor {\n this.onInstruction('${instructionName}', (ins: Instruction, ctx, accounts: string[]) => {\n if (ins) {\n handler(ins.data as ${argsTypeString}, accounts, ctx)\n }\n })\n return this\n }\n `\n}\n\nfunction codeGenInstructionArgs(args: { name: string; type: string }[]): string {\n return `{ ${args.map((arg) => arg.name + ': ' + mapType(arg.type)).join(', ')} }`\n}\n\n// Reference: https://github.com/coral-xyz/anchor/blob/93332766f13e86efbe77c9986722731742317ede/ts/src/program/namespace/types.ts#L104\nfunction mapType(tpe: string): string {\n switch (tpe) {\n case 'publicKey':\n return 'PublicKey'\n case 'bool':\n return 'boolean'\n case 'string':\n return 'string'\n case 'u8':\n case 'i8':\n case 'u16':\n case 'i16':\n case 'u32':\n case 'i32':\n case 'f32':\n case 'f64':\n return 'number'\n case 'u64':\n case 'i64':\n case 'u128':\n case 'i128':\n return 'BN'\n default:\n return 'any'\n }\n}\n\nfunction toPascalCase(str: string) {\n return `${str}`\n .toLowerCase()\n .replace(new RegExp(/[-_]+/, 'g'), ' ')\n .replace(new RegExp(/[^\\w\\s]/, 'g'), '')\n .replace(new RegExp(/\\s+(.)(\\w*)/, 'g'), ($1, $2, $3) => `${$2.toUpperCase() + $3}`)\n .replace(new RegExp(/\\w/), (s) => s.toUpperCase())\n}\n\nasync function execStep(cmd: string, stepName: string) {\n const child = exec(cmd)\n console.log(chalk.blue(stepName + ' begin'))\n\n if (!child.stdout || !child.stderr) {\n console.error(chalk.red(stepName + ' failed'))\n process.exit(1)\n }\n\n child.stdout.pipe(process.stdout)\n child.stderr.pipe(process.stderr)\n\n await new Promise((resolve) => {\n child.on('close', resolve)\n })\n\n if (child.exitCode) {\n console.error(chalk.red(stepName + ' failed'))\n process.exit(child.exitCode)\n }\n console.log(chalk.blue(stepName + ' success'))\n console.log()\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BoundContractView,
|
|
1
|
+
import { BoundContractView, ContractContext, ContractView } from './context';
|
|
2
2
|
import { Block } from '@ethersproject/abstract-provider';
|
|
3
3
|
import { BaseContract, EventFilter } from 'ethers';
|
|
4
4
|
import { Event } from '@ethersproject/contracts';
|
|
@@ -9,19 +9,19 @@ import { Trace } from './trace';
|
|
|
9
9
|
export declare abstract class BaseProcessorTemplate<TContract extends BaseContract, TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>> {
|
|
10
10
|
id: number;
|
|
11
11
|
binds: Set<string>;
|
|
12
|
-
blockHandlers: ((block: Block, ctx:
|
|
12
|
+
blockHandlers: ((block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid)[];
|
|
13
13
|
traceHandlers: {
|
|
14
14
|
signature: string;
|
|
15
|
-
handler: (trace: Trace, ctx:
|
|
15
|
+
handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid;
|
|
16
16
|
}[];
|
|
17
17
|
eventHandlers: {
|
|
18
|
-
handler: (event: Event, ctx:
|
|
18
|
+
handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid;
|
|
19
19
|
filter: EventFilter | EventFilter[];
|
|
20
20
|
}[];
|
|
21
21
|
constructor();
|
|
22
22
|
bind(options: BindOptions): BaseProcessor<TContract, TBoundContractView> | undefined;
|
|
23
|
-
onEvent(handler: (event: Event, ctx:
|
|
24
|
-
onBlock(handler: (block: Block, ctx:
|
|
25
|
-
onTrace(signature: string, handler: (trace: Trace, ctx:
|
|
23
|
+
onEvent(handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, filter: EventFilter | EventFilter[]): this;
|
|
24
|
+
onBlock(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid): this;
|
|
25
|
+
onTrace(signature: string, handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid): this;
|
|
26
26
|
protected abstract bindInternal(options: BindOptions): BaseProcessor<TContract, TBoundContractView>;
|
|
27
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-processor-template.js","sourceRoot":"","sources":["../../src/core/base-processor-template.ts"],"names":[],"mappings":";;;;;;AAKA,iDAAiE;AAEjE,gDAAuB;AACvB,wDAAqD;AAIrD,MAAsB,qBAAqB;IAIzC,EAAE,CAAQ;IACV,KAAK,GAAG,IAAI,GAAG,EAAU,CAAA;IACzB,aAAa,
|
|
1
|
+
{"version":3,"file":"base-processor-template.js","sourceRoot":"","sources":["../../src/core/base-processor-template.ts"],"names":[],"mappings":";;;;;;AAKA,iDAAiE;AAEjE,gDAAuB;AACvB,wDAAqD;AAIrD,MAAsB,qBAAqB;IAIzC,EAAE,CAAQ;IACV,KAAK,GAAG,IAAI,GAAG,EAAU,CAAA;IACzB,aAAa,GAA6F,EAAE,CAAA;IAC5G,aAAa,GAGP,EAAE,CAAA;IACR,aAAa,GAGP,EAAE,CAAA;IAER;QACE,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,MAAM,CAAA;QACjD,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC7C,CAAC;IAEM,IAAI,CAAC,OAAoB;QAC9B,MAAM,GAAG,GAAG,IAAA,kCAAmB,EAAC,OAAO,CAAC,CAAA;QACxC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACvB,OAAM;SACP;QACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAEnB,M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,OAAO,CAAC,QAAQ,CAAA;aACrC;SACF;QACD,MAAM,CAAC,eAAe,CAAC,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAExD,OAAO,SAAS,CAAA;IAClB,CAAC;IAEM,OAAO,CACZ,OAA6F,EAC7F,MAAmC;QAEnC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YACtB,OAAO,EAAE,OAAO;YAChB,MAAM,EAAE,MAAM;SACf,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,OAAO,CAAC,OAA6F;QAC1G,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAChC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,OAAO,CACZ,SAAiB,EACjB,OAA6F;QAE7F,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAA;QAC/C,OAAO,IAAI,CAAA;IACb,CAAC;CAGF;AA5FD,sDA4FC","sourcesContent":["import { BoundContractView, ContractContext, ContractView } from './context'\nimport { Block } from '@ethersproject/abstract-provider'\nimport { BaseContract, EventFilter } from 'ethers'\nimport { Event } from '@ethersproject/contracts'\nimport { BaseProcessor } from './base-processor'\nimport { BindOptions, getOptionsSignature } from './bind-options'\nimport { TemplateInstance } from '../gen'\nimport Long from 'long'\nimport { getNetwork } from '@ethersproject/providers'\nimport { PromiseOrVoid } from '../promise-or-void'\nimport { Trace } from './trace'\n\nexport abstract class BaseProcessorTemplate<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n id: number\n binds = new Set<string>()\n blockHandlers: ((block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid)[] = []\n traceHandlers: {\n signature: string\n handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n }[] = []\n eventHandlers: {\n handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n filter: EventFilter | EventFilter[]\n }[] = []\n\n constructor() {\n this.id = global.PROCESSOR_STATE.templates.length\n global.PROCESSOR_STATE.templates.push(this)\n }\n\n public bind(options: BindOptions) {\n const sig = getOptionsSignature(options)\n if (this.binds.has(sig)) {\n return\n }\n this.binds.add(sig)\n\n const processor = this.bindInternal(options)\n\n for (const eh of this.eventHandlers) {\n processor.onEvent(eh.handler, eh.filter)\n }\n for (const bh of this.blockHandlers) {\n processor.onBlock(bh)\n }\n\n const instance: TemplateInstance = {\n templateId: this.id,\n contract: {\n address: options.address,\n name: options.name || '',\n chainId: options.network ? getNetwork(options.network).chainId.toString() : '1',\n abi: '',\n },\n startBlock: Long.ZERO,\n endBlock: Long.ZERO,\n }\n if (options.startBlock) {\n if (typeof options.startBlock === 'number') {\n instance.startBlock = Long.fromNumber(options.startBlock)\n } else {\n instance.startBlock = options.startBlock\n }\n }\n if (options.endBlock) {\n if (typeof options.endBlock === 'number') {\n instance.endBlock = Long.fromNumber(options.endBlock)\n } else {\n instance.endBlock = options.endBlock\n }\n }\n global.PROCESSOR_STATE.templatesInstances.push(instance)\n\n return processor\n }\n\n public onEvent(\n handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: EventFilter | EventFilter[]\n ) {\n this.eventHandlers.push({\n handler: handler,\n filter: filter,\n })\n return this\n }\n\n public onBlock(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {\n this.blockHandlers.push(handler)\n return this\n }\n\n public onTrace(\n signature: string,\n handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n ) {\n this.traceHandlers.push({ signature, handler })\n return this\n }\n\n protected abstract bindInternal(options: BindOptions): BaseProcessor<TContract, TBoundContractView>\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Event } from '@ethersproject/contracts';
|
|
2
2
|
import { Block, Log } from '@ethersproject/providers';
|
|
3
3
|
import { BaseContract, EventFilter } from '@ethersproject/contracts';
|
|
4
|
-
import { BoundContractView,
|
|
4
|
+
import { BoundContractView, ContractContext, ContractView } from './context';
|
|
5
5
|
import { ProcessResult } from '../gen';
|
|
6
6
|
import { BindInternalOptions, BindOptions } from './bind-options';
|
|
7
7
|
import { PromiseOrVoid } from '../promise-or-void';
|
|
@@ -18,13 +18,12 @@ export declare abstract class BaseProcessor<TContract extends BaseContract, TBou
|
|
|
18
18
|
blockHandlers: ((block: Block) => Promise<ProcessResult>)[];
|
|
19
19
|
eventHandlers: EventsHandler[];
|
|
20
20
|
traceHandlers: TraceHandler[];
|
|
21
|
-
name: string;
|
|
22
21
|
config: BindInternalOptions;
|
|
23
22
|
constructor(config: BindOptions);
|
|
24
23
|
protected abstract CreateBoundContractView(): TBoundContractView;
|
|
25
24
|
getChainId(): number;
|
|
26
|
-
onEvent(handler: (event: Event, ctx:
|
|
27
|
-
onBlock(handler: (block: Block, ctx:
|
|
28
|
-
onAllEvents(handler: (event: Log, ctx:
|
|
29
|
-
protected onTrace(signature: string, handler: (trace: Trace, ctx:
|
|
25
|
+
onEvent(handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, filter: EventFilter | EventFilter[]): this;
|
|
26
|
+
onBlock(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid): this;
|
|
27
|
+
onAllEvents(handler: (event: Log, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid): this;
|
|
28
|
+
protected onTrace(signature: string, handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid): this;
|
|
30
29
|
}
|
|
@@ -21,7 +21,6 @@ class BaseProcessor {
|
|
|
21
21
|
blockHandlers = [];
|
|
22
22
|
eventHandlers = [];
|
|
23
23
|
traceHandlers = [];
|
|
24
|
-
name;
|
|
25
24
|
config;
|
|
26
25
|
constructor(config) {
|
|
27
26
|
this.config = {
|
|
@@ -60,10 +59,11 @@ class BaseProcessor {
|
|
|
60
59
|
_filters.push(filter);
|
|
61
60
|
}
|
|
62
61
|
const contractView = this.CreateBoundContractView();
|
|
62
|
+
const contractName = this.config.name;
|
|
63
63
|
this.eventHandlers.push({
|
|
64
64
|
filters: _filters,
|
|
65
65
|
handler: async function (log) {
|
|
66
|
-
const ctx = new context_1.
|
|
66
|
+
const ctx = new context_1.ContractContext(contractName, contractView, chainId, undefined, log);
|
|
67
67
|
// let event: Event = <Event>deepCopy(log);
|
|
68
68
|
const event = log;
|
|
69
69
|
const parsed = contractView.rawContract.interface.parseLog(log);
|
|
@@ -94,8 +94,9 @@ class BaseProcessor {
|
|
|
94
94
|
onBlock(handler) {
|
|
95
95
|
const chainId = this.getChainId();
|
|
96
96
|
const contractView = this.CreateBoundContractView();
|
|
97
|
+
const contractName = this.config.name;
|
|
97
98
|
this.blockHandlers.push(async function (block) {
|
|
98
|
-
const ctx = new context_1.
|
|
99
|
+
const ctx = new context_1.ContractContext(contractName, contractView, chainId, block, undefined);
|
|
99
100
|
await handler(block, ctx);
|
|
100
101
|
return {
|
|
101
102
|
gauges: ctx.gauges,
|
|
@@ -118,6 +119,7 @@ class BaseProcessor {
|
|
|
118
119
|
onTrace(signature, handler) {
|
|
119
120
|
const chainId = this.getChainId();
|
|
120
121
|
const contractView = this.CreateBoundContractView();
|
|
122
|
+
const contractName = this.config.name;
|
|
121
123
|
this.traceHandlers.push({
|
|
122
124
|
signature,
|
|
123
125
|
handler: async function (trace) {
|
|
@@ -132,7 +134,7 @@ class BaseProcessor {
|
|
|
132
134
|
}
|
|
133
135
|
const traceData = '0x' + trace.action.input.slice(10);
|
|
134
136
|
trace.args = contractInterface._abiCoder.decode(fragment.inputs, traceData);
|
|
135
|
-
const ctx = new context_1.
|
|
137
|
+
const ctx = new context_1.ContractContext(contractName, contractView, chainId, undefined, undefined, trace);
|
|
136
138
|
await handler(trace, ctx);
|
|
137
139
|
return {
|
|
138
140
|
gauges: ctx.gauges,
|
|
@@ -1 +1 @@
|
|
|
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AAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AArJD,sCAqJC","sourcesContent":["import { Event } from '@ethersproject/contracts'\nimport { BytesLike } from '@ethersproject/bytes'\nimport { Block, Log, getNetwork } from '@ethersproject/providers'\nimport { BaseContract, EventFilter } from '@ethersproject/contracts'\nimport Long from 'long'\n\nimport { BoundContractView, Context, ContractView } from './context'\nimport { ProcessResult } from '../gen'\nimport { BindInternalOptions, BindOptions } from './bind-options'\nimport { PromiseOrVoid } from '../promise-or-void'\nimport { Trace } from './trace'\n\nexport class EventsHandler {\n filters: EventFilter[]\n handler: (event: Log) => Promise<ProcessResult>\n}\n\nexport class TraceHandler {\n signature: string\n handler: (trace: Trace) => Promise<ProcessResult>\n}\n\nexport abstract class BaseProcessor<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n blockHandlers: ((block: Block) => Promise<ProcessResult>)[] = []\n eventHandlers: EventsHandler[] = []\n traceHandlers: TraceHandler[] = []\n\n name: string\n config: BindInternalOptions\n\n constructor(config: BindOptions) {\n this.config = {\n address: config.address,\n name: config.name || '',\n network: config.network ? config.network : 1,\n startBlock: new Long(0),\n }\n if (config.startBlock) {\n if (typeof config.startBlock === 'number') {\n this.config.startBlock = Long.fromNumber(config.startBlock)\n } else {\n this.config.startBlock = config.startBlock\n }\n }\n if (config.endBlock) {\n if (typeof config.endBlock === 'number') {\n this.config.endBlock = Long.fromNumber(config.endBlock)\n } else {\n this.config.endBlock = config.endBlock\n }\n }\n }\n\n protected abstract CreateBoundContractView(): TBoundContractView\n\n public getChainId(): number {\n return getNetwork(this.config.network).chainId\n }\n\n public onEvent(\n handler: (event: Event, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: EventFilter | EventFilter[]\n ) {\n const chainId = this.getChainId()\n\n let _filters: EventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n const contractView = this.CreateBoundContractView()\n this.eventHandlers.push({\n filters: _filters,\n handler: async function (log) {\n const ctx = new Context<TContract, TBoundContractView>(contractView, chainId, undefined, log)\n // let event: Event = <Event>deepCopy(log);\n const event: Event = <Event>log\n const parsed = contractView.rawContract.interface.parseLog(log)\n if (parsed) {\n event.args = parsed.args\n event.decode = (data: BytesLike, topics?: Array<any>) => {\n return contractView.rawContract.interface.decodeEventLog(parsed.eventFragment, data, topics)\n }\n event.event = parsed.name\n event.eventSignature = parsed.signature\n\n // TODO fix this bug\n await handler(event, ctx)\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n }\n return {\n gauges: [],\n counters: [],\n logs: [],\n }\n },\n })\n return this\n }\n\n public onBlock(handler: (block: Block, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid) {\n const chainId = this.getChainId()\n const contractView = this.CreateBoundContractView()\n\n this.blockHandlers.push(async function (block: Block) {\n const ctx = new Context<TContract, TBoundContractView>(contractView, chainId, block, undefined)\n await handler(block, ctx)\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n })\n return this\n }\n\n public onAllEvents(handler: (event: Log, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid) {\n const _filters: EventFilter[] = []\n const tmpContract = this.CreateBoundContractView()\n\n for (const key in tmpContract.filters) {\n _filters.push(tmpContract.filters[key]())\n }\n return this.onEvent(function (log, ctx) {\n return handler(log, ctx)\n }, _filters)\n }\n\n protected onTrace(\n signature: string,\n handler: (trace: Trace, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid\n ) {\n const chainId = this.getChainId()\n const contractView = this.CreateBoundContractView()\n\n this.traceHandlers.push({\n signature,\n handler: async function (trace: Trace) {\n const contractInterface = contractView.rawContract.interface\n const fragment = contractInterface.getFunction(signature)\n if (!trace.action.input) {\n return {\n gauges: [],\n counters: [],\n logs: [],\n }\n }\n const traceData = '0x' + trace.action.input.slice(10)\n trace.args = contractInterface._abiCoder.decode(fragment.inputs, traceData)\n\n const ctx = new Context<TContract, TBoundContractView>(contractView, chainId, undefined, undefined, trace)\n await handler(trace, ctx)\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n })\n return this\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base-processor.js","sourceRoot":"","sources":["../../src/core/base-processor.ts"],"names":[],"mappings":";;;;;;AAEA,wDAAiE;AAEjE,gDAAuB;AAEvB,uCAA4E;AAM5E,MAAa,aAAa;IACxB,OAAO,CAAe;IACtB,OAAO,CAAwC;CAChD;AAHD,sCAGC;AAED,MAAa,YAAY;IACvB,SAAS,CAAQ;IACjB,OAAO,CAA0C;CAClD;AAHD,oCAGC;AAED,MAAsB,aAAa;IAIjC,aAAa,GAAiD,EAAE,CAAA;IAChE,aAAa,GAAoB,EAAE,CAAA;IACnC,aAAa,GAAmB,EAAE,CAAA;IAElC,MAAM,CAAqB;IAE3B,YAAY,MAAmB;QAC7B,IAAI,CAAC,MAAM,GAAG;YACZ,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,EAAE;YACvB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC5C,UAAU,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC;SACxB,CAAA;QACD,IAAI,MAAM,CAAC,UAAU,EAAE;YACrB,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ,EAAE;gBACzC,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,cAAI,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;aAC5D;iBAAM;gBACL,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;aAC3C;SACF;QACD,IAAI,MAAM,CAAC,QAAQ,EAAE;YACnB,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE;gBAC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BAE3E,MAAM,GAAG,GAAG,IAAI,yBAAe,CAC7B,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,SAAS,EACT,SAAS,EACT,KAAK,CACN,CAAA;gBACD,MAAM,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;gBACzB,OAAO;oBACL,MAAM,EAAE,GAAG,CAAC,MAAM;oBAClB,QAAQ,EAAE,GAAG,CAAC,QAAQ;oBACtB,IAAI,EAAE,GAAG,CAAC,IAAI;iBACf,CAAA;YACH,CAAC;SACF,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA1KD,sCA0KC","sourcesContent":["import { Event } from '@ethersproject/contracts'\nimport { BytesLike } from '@ethersproject/bytes'\nimport { Block, Log, getNetwork } from '@ethersproject/providers'\nimport { BaseContract, EventFilter } from '@ethersproject/contracts'\nimport Long from 'long'\n\nimport { BoundContractView, ContractContext, ContractView } from './context'\nimport { ProcessResult } from '../gen'\nimport { BindInternalOptions, BindOptions } from './bind-options'\nimport { PromiseOrVoid } from '../promise-or-void'\nimport { Trace } from './trace'\n\nexport class EventsHandler {\n filters: EventFilter[]\n handler: (event: Log) => Promise<ProcessResult>\n}\n\nexport class TraceHandler {\n signature: string\n handler: (trace: Trace) => Promise<ProcessResult>\n}\n\nexport abstract class BaseProcessor<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n blockHandlers: ((block: Block) => Promise<ProcessResult>)[] = []\n eventHandlers: EventsHandler[] = []\n traceHandlers: TraceHandler[] = []\n\n config: BindInternalOptions\n\n constructor(config: BindOptions) {\n this.config = {\n address: config.address,\n name: config.name || '',\n network: config.network ? config.network : 1,\n startBlock: new Long(0),\n }\n if (config.startBlock) {\n if (typeof config.startBlock === 'number') {\n this.config.startBlock = Long.fromNumber(config.startBlock)\n } else {\n this.config.startBlock = config.startBlock\n }\n }\n if (config.endBlock) {\n if (typeof config.endBlock === 'number') {\n this.config.endBlock = Long.fromNumber(config.endBlock)\n } else {\n this.config.endBlock = config.endBlock\n }\n }\n }\n\n protected abstract CreateBoundContractView(): TBoundContractView\n\n public getChainId(): number {\n return getNetwork(this.config.network).chainId\n }\n\n public onEvent(\n handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: EventFilter | EventFilter[]\n ) {\n const chainId = this.getChainId()\n\n let _filters: EventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n this.eventHandlers.push({\n filters: _filters,\n handler: async function (log) {\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n undefined,\n log\n )\n // let event: Event = <Event>deepCopy(log);\n const event: Event = <Event>log\n const parsed = contractView.rawContract.interface.parseLog(log)\n if (parsed) {\n event.args = parsed.args\n event.decode = (data: BytesLike, topics?: Array<any>) => {\n return contractView.rawContract.interface.decodeEventLog(parsed.eventFragment, data, topics)\n }\n event.event = parsed.name\n event.eventSignature = parsed.signature\n\n // TODO fix this bug\n await handler(event, ctx)\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n }\n return {\n gauges: [],\n counters: [],\n logs: [],\n }\n },\n })\n return this\n }\n\n public onBlock(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {\n const chainId = this.getChainId()\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n\n this.blockHandlers.push(async function (block: Block) {\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n block,\n undefined\n )\n await handler(block, ctx)\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n })\n return this\n }\n\n public onAllEvents(handler: (event: Log, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {\n const _filters: EventFilter[] = []\n const tmpContract = this.CreateBoundContractView()\n\n for (const key in tmpContract.filters) {\n _filters.push(tmpContract.filters[key]())\n }\n return this.onEvent(function (log, ctx) {\n return handler(log, ctx)\n }, _filters)\n }\n\n protected onTrace(\n signature: string,\n handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n ) {\n const chainId = this.getChainId()\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n\n this.traceHandlers.push({\n signature,\n handler: async function (trace: Trace) {\n const contractInterface = contractView.rawContract.interface\n const fragment = contractInterface.getFunction(signature)\n if (!trace.action.input) {\n return {\n gauges: [],\n counters: [],\n logs: [],\n }\n }\n const traceData = '0x' + trace.action.input.slice(10)\n trace.args = contractInterface._abiCoder.decode(fragment.inputs, traceData)\n\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n undefined,\n undefined,\n trace\n )\n await handler(trace, ctx)\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n })\n return this\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BigNumber as BigDecimal } from 'bignumber.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BigDecimal = void 0;
|
|
4
|
+
var bignumber_js_1 = require("bignumber.js");
|
|
5
|
+
Object.defineProperty(exports, "BigDecimal", { enumerable: true, get: function () { return bignumber_js_1.BigNumber; } });
|
|
6
|
+
//# sourceMappingURL=big-decimal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"big-decimal.js","sourceRoot":"","sources":["../../src/core/big-decimal.ts"],"names":[],"mappings":";;;AAAA,6CAAsD;AAA7C,0GAAA,SAAS,OAAc","sourcesContent":["export { BigNumber as BigDecimal } from 'bignumber.js'\n"]}
|
package/lib/core/bind-options.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SolanaBindOptions = exports.BindInternalOptions = exports.getOptionsSignature = exports.BindOptions = void 0;
|
|
4
4
|
const providers_1 = require("@ethersproject/providers");
|
|
5
5
|
class BindOptions {
|
|
6
|
+
// Contract address
|
|
6
7
|
address;
|
|
8
|
+
// Optional, if not set, then use eth mainnet
|
|
7
9
|
network = 1;
|
|
10
|
+
// Optional, override default contract name
|
|
8
11
|
name;
|
|
9
12
|
startBlock;
|
|
10
13
|
endBlock;
|
|
@@ -39,7 +42,4 @@ class SolanaBindOptions extends BindOptions {
|
|
|
39
42
|
processInnerInstruction;
|
|
40
43
|
}
|
|
41
44
|
exports.SolanaBindOptions = SolanaBindOptions;
|
|
42
|
-
class SuiBindOptions extends BindOptions {
|
|
43
|
-
}
|
|
44
|
-
exports.SuiBindOptions = SuiBindOptions;
|
|
45
45
|
//# sourceMappingURL=bind-options.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind-options.js","sourceRoot":"","sources":["../../src/core/bind-options.ts"],"names":[],"mappings":";;;AAEA,wDAAqD;AAErD,MAAa,WAAW;IACtB,OAAO,CAAQ;IACf,OAAO,GAAgB,CAAC,CAAA;IACxB,IAAI,CAAS;IACb,UAAU,CAAgB;IAC1B,QAAQ,CAAgB;CACzB;
|
|
1
|
+
{"version":3,"file":"bind-options.js","sourceRoot":"","sources":["../../src/core/bind-options.ts"],"names":[],"mappings":";;;AAEA,wDAAqD;AAErD,MAAa,WAAW;IACtB,mBAAmB;IACnB,OAAO,CAAQ;IACf,6CAA6C;IAC7C,OAAO,GAAgB,CAAC,CAAA;IACxB,2CAA2C;IAC3C,IAAI,CAAS;IACb,UAAU,CAAgB;IAC1B,QAAQ,CAAgB;CACzB;AATD,kCASC;AAED,SAAgB,mBAAmB,CAAC,IAAiB;IACnD,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC1B,IAAI,IAAI,CAAC,OAAO,EAAE;QAChB,GAAG,CAAC,IAAI,CAAC,IAAA,sBAAU,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA;KACtD;IACD,IAAI,IAAI,CAAC,IAAI,EAAE;QACb,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;KACpB;IACD,IAAI,IAAI,CAAC,UAAU,EAAE;QACnB,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAA;KACrC;IACD,IAAI,IAAI,CAAC,QAAQ,EAAE;QACjB,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAA;KACnC;IACD,OAAO,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACtB,CAAC;AAfD,kDAeC;AAED,MAAa,mBAAmB;IAC9B,OAAO,CAAQ;IACf,OAAO,CAAY;IACnB,IAAI,CAAQ;IACZ,UAAU,CAAM;IAChB,QAAQ,CAAO;CAChB;AAND,kDAMC;AAED,MAAa,iBAAkB,SAAQ,WAAW;IAEhD,uBAAuB,CAAU;CAClC;AAHD,8CAGC","sourcesContent":["import { Networkish } from '@ethersproject/networks'\nimport Long from 'long'\nimport { getNetwork } from '@ethersproject/providers'\n\nexport class BindOptions {\n // Contract address\n address: string\n // Optional, if not set, then use eth mainnet\n network?: Networkish = 1\n // Optional, override default contract name\n name?: string\n startBlock?: Long | number\n endBlock?: Long | number\n}\n\nexport function getOptionsSignature(opts: BindOptions): string {\n const sig = [opts.address]\n if (opts.network) {\n sig.push(getNetwork(opts.network).chainId.toString())\n }\n if (opts.name) {\n sig.push(opts.name)\n }\n if (opts.startBlock) {\n sig.push(opts.startBlock.toString())\n }\n if (opts.endBlock) {\n sig.push(opts.endBlock.toString())\n }\n return sig.join('_')\n}\n\nexport class BindInternalOptions {\n address: string\n network: Networkish\n name: string\n startBlock: Long\n endBlock?: Long\n}\n\nexport class SolanaBindOptions extends BindOptions {\n declare network?: string\n processInnerInstruction?: boolean\n}\n"]}
|
package/lib/core/context.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CounterResult, GaugeResult, LogResult,
|
|
1
|
+
import { CounterResult, GaugeResult, LogResult, DataDescriptor, RecordMetaData } from '../gen';
|
|
2
2
|
import { BaseContract, EventFilter } from 'ethers';
|
|
3
3
|
import { Block, Log } from '@ethersproject/abstract-provider';
|
|
4
4
|
import { Meter } from './meter';
|
|
@@ -13,22 +13,23 @@ export declare abstract class BaseContext {
|
|
|
13
13
|
meter: Meter;
|
|
14
14
|
logger: Logger;
|
|
15
15
|
protected constructor();
|
|
16
|
-
abstract getMetaData(descriptor:
|
|
16
|
+
abstract getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData;
|
|
17
17
|
}
|
|
18
18
|
export declare abstract class EthContext extends BaseContext {
|
|
19
19
|
chainId: number;
|
|
20
|
+
address: string;
|
|
20
21
|
log?: Log;
|
|
21
22
|
block?: Block;
|
|
22
23
|
trace?: Trace;
|
|
23
24
|
blockNumber: Long;
|
|
24
25
|
transactionHash?: string;
|
|
25
|
-
protected constructor(chainId: number, block?: Block, log?: Log, trace?: Trace);
|
|
26
|
+
protected constructor(chainId: number, address: string, block?: Block, log?: Log, trace?: Trace);
|
|
26
27
|
}
|
|
27
|
-
export declare class
|
|
28
|
+
export declare class ContractContext<TContract extends BaseContract, TContractBoundView extends BoundContractView<TContract, ContractView<TContract>>> extends EthContext {
|
|
28
29
|
contract: TContractBoundView;
|
|
29
|
-
|
|
30
|
-
constructor(view: TContractBoundView, chainId: number, block?: Block, log?: Log, trace?: Trace);
|
|
31
|
-
getMetaData(descriptor:
|
|
30
|
+
contractName: string;
|
|
31
|
+
constructor(contractName: string, view: TContractBoundView, chainId: number, block?: Block, log?: Log, trace?: Trace);
|
|
32
|
+
getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData;
|
|
32
33
|
}
|
|
33
34
|
export declare class ContractView<TContract extends BaseContract> {
|
|
34
35
|
filters: {
|
|
@@ -41,7 +42,7 @@ export declare class ContractView<TContract extends BaseContract> {
|
|
|
41
42
|
}
|
|
42
43
|
export declare class BoundContractView<TContract extends BaseContract, TContractView extends ContractView<TContract>> {
|
|
43
44
|
protected view: TContractView;
|
|
44
|
-
context:
|
|
45
|
+
context: ContractContext<TContract, BoundContractView<TContract, TContractView>>;
|
|
45
46
|
constructor(view: TContractView);
|
|
46
47
|
get rawContract(): TContract;
|
|
47
48
|
get provider(): import("@ethersproject/abstract-provider").Provider;
|
|
@@ -51,13 +52,15 @@ export declare class BoundContractView<TContract extends BaseContract, TContract
|
|
|
51
52
|
}
|
|
52
53
|
export declare class SolanaContext extends BaseContext {
|
|
53
54
|
address: string;
|
|
55
|
+
programName: string;
|
|
54
56
|
blockNumber: Long;
|
|
55
|
-
constructor(address: string, slot: Long);
|
|
56
|
-
getMetaData(descriptor:
|
|
57
|
+
constructor(programName: string, address: string, slot: Long);
|
|
58
|
+
getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData;
|
|
57
59
|
}
|
|
58
60
|
export declare class SuiContext extends BaseContext {
|
|
59
61
|
address: string;
|
|
62
|
+
moduleName: string;
|
|
60
63
|
blockNumber: Long;
|
|
61
64
|
constructor(address: string, slot: Long);
|
|
62
|
-
getMetaData(descriptor:
|
|
65
|
+
getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData;
|
|
63
66
|
}
|