@sentio/sdk 2.0.0-rc.14 → 2.0.0-rc.16
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/api.d.ts +5 -0
- package/lib/aptos/api.js +21 -0
- package/lib/aptos/api.js.map +1 -0
- package/lib/aptos/aptos-plugin.d.ts +14 -0
- package/lib/aptos/aptos-plugin.js +146 -0
- package/lib/aptos/aptos-plugin.js.map +1 -0
- package/lib/aptos/aptos-processor.d.ts +72 -0
- package/lib/aptos/aptos-processor.js +201 -0
- package/lib/aptos/aptos-processor.js.map +1 -0
- package/lib/aptos/builtin/0x1.d.ts +2140 -0
- package/lib/aptos/builtin/0x1.js +2727 -0
- package/lib/aptos/builtin/0x1.js.map +1 -0
- package/lib/aptos/builtin/0x3.d.ts +573 -0
- package/lib/aptos/builtin/0x3.js +496 -0
- package/lib/aptos/builtin/0x3.js.map +1 -0
- package/lib/aptos/builtin/index.d.ts +2 -0
- package/lib/aptos/builtin/index.js +6 -0
- package/lib/aptos/builtin/index.js.map +1 -0
- package/lib/aptos/codegen/codegen.d.ts +23 -0
- package/lib/aptos/codegen/codegen.js +388 -0
- package/lib/aptos/codegen/codegen.js.map +1 -0
- package/lib/aptos/codegen/index.d.ts +1 -0
- package/lib/aptos/codegen/index.js +2 -0
- package/lib/aptos/codegen/index.js.map +1 -0
- package/lib/aptos/codegen/typegen.d.ts +18 -0
- package/lib/aptos/codegen/typegen.js +145 -0
- package/lib/aptos/codegen/typegen.js.map +1 -0
- package/lib/aptos/codegen/typegen.test.d.ts +1 -0
- package/lib/aptos/codegen/typegen.test.js.map +1 -0
- package/lib/aptos/context.d.ts +21 -0
- package/lib/aptos/context.js +59 -0
- package/lib/aptos/context.js.map +1 -0
- package/lib/aptos/index.d.ts +9 -0
- package/lib/aptos/index.js +8 -0
- package/lib/aptos/index.js.map +1 -0
- package/lib/aptos/models.d.ts +37 -0
- package/lib/aptos/models.js +2 -0
- package/lib/aptos/models.js.map +1 -0
- package/lib/aptos/move-coder.d.ts +22 -0
- package/lib/aptos/move-coder.js +164 -0
- package/lib/aptos/move-coder.js.map +1 -0
- package/lib/aptos/move-types.d.ts +10 -0
- package/lib/aptos/move-types.js +2 -0
- package/lib/aptos/move-types.js.map +1 -0
- package/lib/aptos/network.d.ts +11 -0
- package/lib/aptos/network.js +27 -0
- package/lib/aptos/network.js.map +1 -0
- package/lib/aptos/run-codegen.d.ts +1 -0
- package/lib/aptos/run-codegen.js +12 -0
- package/lib/aptos/run-codegen.js.map +1 -0
- package/lib/aptos/tests/aptos.test.d.ts +1 -0
- package/lib/aptos/tests/aptos.test.js.map +1 -0
- package/lib/aptos/tests/souffl3.d.ts +1 -0
- package/lib/aptos/tests/souffl3.js +44 -0
- package/lib/aptos/tests/souffl3.js.map +1 -0
- package/lib/aptos/tests/types/index.d.ts +3 -0
- package/lib/aptos/tests/types/index.js +7 -0
- package/lib/aptos/tests/types/index.js.map +1 -0
- package/lib/aptos/tests/types/reserved.d.ts +445 -0
- package/lib/aptos/tests/types/reserved.js +301 -0
- package/lib/aptos/tests/types/reserved.js.map +1 -0
- package/lib/aptos/tests/types/soffl3.d.ts +1065 -0
- package/lib/aptos/tests/types/soffl3.js +548 -0
- package/lib/aptos/tests/types/soffl3.js.map +1 -0
- package/lib/aptos/tests/types/souffle.d.ts +440 -0
- package/lib/aptos/tests/types/souffle.js +295 -0
- package/lib/aptos/tests/types/souffle.js.map +1 -0
- package/lib/aptos/types.d.ts +9 -0
- package/lib/aptos/types.js +130 -0
- package/lib/aptos/types.js.map +1 -0
- package/lib/aptos/types.test.d.ts +1 -0
- package/lib/aptos/types.test.js.map +1 -0
- package/lib/aptos/utils.d.ts +7 -0
- package/lib/aptos/utils.js +20 -0
- package/lib/aptos/utils.js.map +1 -0
- package/lib/{utils/chain.d.ts → chain.d.ts} +0 -0
- package/lib/{utils/chain.js → chain.js} +0 -0
- package/lib/chain.js.map +1 -0
- package/lib/core/context.js +1 -1
- package/lib/core/context.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 +1 -1
- package/lib/index.js.map +1 -1
- package/lib/solana/builtin/index.d.ts +1 -0
- package/lib/solana/builtin/index.js +2 -0
- package/lib/solana/builtin/index.js.map +1 -0
- package/lib/solana/builtin/spl-token-processor.d.ts +39 -0
- package/lib/solana/builtin/spl-token-processor.js +254 -0
- package/lib/solana/builtin/spl-token-processor.js.map +1 -0
- package/lib/solana/builtin/types.d.ts +427 -0
- package/lib/solana/builtin/types.js +200 -0
- package/lib/solana/builtin/types.js.map +1 -0
- package/lib/solana/codegen/codegen.d.ts +1 -0
- package/lib/solana/codegen/codegen.js +122 -0
- package/lib/solana/codegen/codegen.js.map +1 -0
- package/lib/solana/codegen/index.d.ts +1 -0
- package/lib/solana/codegen/index.js +2 -0
- package/lib/solana/codegen/index.js.map +1 -0
- package/lib/solana/index.d.ts +4 -0
- package/lib/solana/index.js +5 -0
- package/lib/solana/index.js.map +1 -0
- package/lib/solana/run-codegen.d.ts +2 -0
- package/lib/solana/run-codegen.js +12 -0
- package/lib/solana/run-codegen.js.map +1 -0
- package/lib/solana/solana-context.d.ts +9 -0
- package/lib/solana/solana-context.js +28 -0
- package/lib/solana/solana-context.js.map +1 -0
- package/lib/solana/solana-options.d.ts +10 -0
- package/lib/solana/solana-options.js +10 -0
- package/lib/solana/solana-options.js.map +1 -0
- package/lib/solana/solana-plugin.d.ts +9 -0
- package/lib/solana/solana-plugin.js +87 -0
- package/lib/solana/solana-plugin.js.map +1 -0
- package/lib/solana/solana-processor.d.ts +43 -0
- package/lib/solana/solana-processor.js +72 -0
- package/lib/solana/solana-processor.js.map +1 -0
- package/lib/solana/tests/solana.test.d.ts +1 -0
- package/lib/solana/tests/solana.test.js.map +1 -0
- package/lib/solana/tests/types/basic_1.d.ts +26 -0
- package/lib/solana/tests/types/basic_1.js +63 -0
- package/lib/solana/tests/types/basic_1.js.map +1 -0
- package/lib/solana/tests/types/basic_1_processor.d.ts +21 -0
- package/lib/solana/tests/types/basic_1_processor.js +35 -0
- package/lib/solana/tests/types/basic_1_processor.js.map +1 -0
- package/lib/solana/tests/types/token_bridge.d.ts +29 -0
- package/lib/solana/tests/types/token_bridge.js +938 -0
- package/lib/solana/tests/types/token_bridge.js.map +1 -0
- package/lib/solana/tests/types/token_bridge_processor.d.ts +212 -0
- package/lib/solana/tests/types/token_bridge_processor.js +134 -0
- package/lib/solana/tests/types/token_bridge_processor.js.map +1 -0
- package/lib/solana/tests/wormhole-token-bridge.d.ts +15 -0
- package/lib/solana/tests/wormhole-token-bridge.js +79 -0
- package/lib/solana/tests/wormhole-token-bridge.js.map +1 -0
- package/lib/testing/test-processor-server.js +1 -1
- package/lib/testing/test-processor-server.js.map +1 -1
- package/lib/testing/test-provider.js +1 -1
- package/lib/testing/test-provider.js.map +1 -1
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/index.js +0 -1
- package/lib/utils/index.js.map +1 -1
- package/package.json +33 -11
- package/src/aptos/abis/0x1.json +9205 -0
- package/src/aptos/abis/0x3.json +1515 -0
- package/src/aptos/api.ts +23 -0
- package/src/aptos/aptos-plugin.ts +183 -0
- package/src/aptos/aptos-processor.ts +331 -0
- package/src/aptos/builtin/0x1.ts +4911 -0
- package/src/aptos/builtin/0x3.ts +1092 -0
- package/src/aptos/builtin/index.ts +5 -0
- package/src/aptos/codegen/codegen.ts +470 -0
- package/src/aptos/codegen/index.ts +1 -0
- package/src/aptos/codegen/tsconfig.json +8 -0
- package/src/aptos/codegen/typegen.ts +165 -0
- package/src/aptos/context.ts +72 -0
- package/src/aptos/index.ts +10 -0
- package/src/aptos/models.ts +47 -0
- package/src/aptos/move-coder.ts +201 -0
- package/src/aptos/move-types.ts +11 -0
- package/src/aptos/network.ts +29 -0
- package/src/aptos/run-codegen.ts +13 -0
- package/src/aptos/tests/abis/reserved.json +402 -0
- package/src/aptos/tests/abis/soffl3.json +1411 -0
- package/src/aptos/tests/abis/souffle.json +389 -0
- package/src/aptos/tests/souffl3.ts +57 -0
- package/src/aptos/tests/types/index.ts +6 -0
- package/src/aptos/tests/types/reserved.ts +881 -0
- package/src/aptos/tests/types/soffl3.ts +1820 -0
- package/src/aptos/tests/types/souffle.ts +880 -0
- package/src/aptos/types.ts +149 -0
- package/src/aptos/utils.ts +26 -0
- package/src/{utils/chain.ts → chain.ts} +0 -0
- package/src/core/context.ts +1 -1
- package/src/core/sui-plugin.ts +1 -1
- package/src/index.ts +1 -1
- package/src/solana/builtin/index.ts +1 -0
- package/src/solana/builtin/spl-token-processor.ts +298 -0
- package/src/solana/builtin/types.ts +279 -0
- package/src/solana/codegen/codegen.ts +140 -0
- package/src/solana/codegen/index.ts +1 -0
- package/src/solana/codegen/tsconfig.json +8 -0
- package/src/solana/index.ts +4 -0
- package/src/solana/run-codegen.ts +13 -0
- package/src/solana/solana-context.ts +30 -0
- package/src/solana/solana-options.ts +11 -0
- package/src/solana/solana-plugin.ts +103 -0
- package/src/solana/solana-processor.ts +102 -0
- package/src/solana/tests/abis/basic_1.json +62 -0
- package/src/solana/tests/abis/token_bridge.json +937 -0
- package/src/solana/tests/types/basic_1.ts +62 -0
- package/src/solana/tests/types/basic_1_processor.ts +42 -0
- package/src/solana/tests/types/token_bridge.ts +937 -0
- package/src/solana/tests/types/token_bridge_processor.ts +150 -0
- package/src/solana/tests/wormhole-token-bridge.ts +96 -0
- package/src/testing/test-processor-server.ts +1 -1
- package/src/testing/test-provider.ts +1 -1
- package/src/utils/index.ts +0 -1
- package/lib/utils/chain.js.map +0 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { BorshInstructionCoder, Instruction, Idl } from '@project-serum/anchor'
|
|
2
|
+
import { SolanaBaseProcessor, SolanaContext, SolanaBindOptions } from "@sentio/sdk/solana"
|
|
3
|
+
import { token_bridge_idl } from "./token_bridge.js"
|
|
4
|
+
import { PublicKey } from '@solana/web3.js'
|
|
5
|
+
|
|
6
|
+
export class TokenBridgeProcessor extends SolanaBaseProcessor {
|
|
7
|
+
static DEFAULT_OPTIONS = {
|
|
8
|
+
name: 'TokenBridge',
|
|
9
|
+
instructionCoder: new BorshInstructionCoder(token_bridge_idl as Idl)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static bind(options: SolanaBindOptions): TokenBridgeProcessor {
|
|
13
|
+
return new TokenBridgeProcessor( { ...TokenBridgeProcessor.DEFAULT_OPTIONS, ...options })
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
onInitialize(handler: (args: { wormhole: PublicKey }, accounts: { payer: string, config: string, rent: string, systemProgram: string }, ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
18
|
+
this.onInstruction('initialize', (ins: Instruction, ctx, accounts: string[]) => {
|
|
19
|
+
const origin = ins.data as any
|
|
20
|
+
if (origin) {
|
|
21
|
+
const data = { wormhole: origin.wormhole as PublicKey }
|
|
22
|
+
const accountData = { payer: accounts[0], config: accounts[1], rent: accounts[2], systemProgram: accounts[3] }
|
|
23
|
+
handler(data, accountData, ctx)
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
return this
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
onAttestToken(handler: (args: { nonce: number }, accounts: { payer: string, config: string, mint: string, wrappedMeta: string, splMetadata: string, wormholeBridge: string, wormholeMessage: string, wormholeEmitter: string, wormholeSequence: string, wormholeFeeCollector: string, clock: string, rent: string, systemProgram: string, wormholeProgram: string }, ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
30
|
+
this.onInstruction('attestToken', (ins: Instruction, ctx, accounts: string[]) => {
|
|
31
|
+
const origin = ins.data as any
|
|
32
|
+
if (origin) {
|
|
33
|
+
const data = { nonce: origin.nonce as number }
|
|
34
|
+
const accountData = { payer: accounts[0], config: accounts[1], mint: accounts[2], wrappedMeta: accounts[3], splMetadata: accounts[4], wormholeBridge: accounts[5], wormholeMessage: accounts[6], wormholeEmitter: accounts[7], wormholeSequence: accounts[8], wormholeFeeCollector: accounts[9], clock: accounts[10], rent: accounts[11], systemProgram: accounts[12], wormholeProgram: accounts[13] }
|
|
35
|
+
handler(data, accountData, ctx)
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
return this
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
onCompleteNative(handler: (args: { }, accounts: { payer: string, config: string, vaa: string, claim: string, endpoint: string, to: string, toFees: string, custody: string, mint: string, custodySigner: string, rent: string, systemProgram: string, tokenProgram: string, wormholeProgram: string }, ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
42
|
+
this.onInstruction('completeNative', (ins: Instruction, ctx, accounts: string[]) => {
|
|
43
|
+
const origin = ins.data as any
|
|
44
|
+
if (origin) {
|
|
45
|
+
const data = { }
|
|
46
|
+
const accountData = { payer: accounts[0], config: accounts[1], vaa: accounts[2], claim: accounts[3], endpoint: accounts[4], to: accounts[5], toFees: accounts[6], custody: accounts[7], mint: accounts[8], custodySigner: accounts[9], rent: accounts[10], systemProgram: accounts[11], tokenProgram: accounts[12], wormholeProgram: accounts[13] }
|
|
47
|
+
handler(data, accountData, ctx)
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
return this
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
onCompleteWrapped(handler: (args: { }, accounts: { payer: string, config: string, vaa: string, claim: string, endpoint: string, to: string, toFees: string, mint: string, wrappedMeta: string, mintAuthority: string, rent: string, systemProgram: string, tokenProgram: string, wormholeProgram: string }, ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
54
|
+
this.onInstruction('completeWrapped', (ins: Instruction, ctx, accounts: string[]) => {
|
|
55
|
+
const origin = ins.data as any
|
|
56
|
+
if (origin) {
|
|
57
|
+
const data = { }
|
|
58
|
+
const accountData = { payer: accounts[0], config: accounts[1], vaa: accounts[2], claim: accounts[3], endpoint: accounts[4], to: accounts[5], toFees: accounts[6], mint: accounts[7], wrappedMeta: accounts[8], mintAuthority: accounts[9], rent: accounts[10], systemProgram: accounts[11], tokenProgram: accounts[12], wormholeProgram: accounts[13] }
|
|
59
|
+
handler(data, accountData, ctx)
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
return this
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
onTransferWrapped(handler: (args: { nonce: number, amount: bigint, fee: bigint, targetAddress: any, targetChain: number }, accounts: { payer: string, config: string, from: string, fromOwner: string, mint: string, wrappedMeta: string, authoritySigner: string, wormholeBridge: string, wormholeMessage: string, wormholeEmitter: string, wormholeSequence: string, wormholeFeeCollector: string, clock: string, rent: string, systemProgram: string, tokenProgram: string, wormholeProgram: string }, ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
66
|
+
this.onInstruction('transferWrapped', (ins: Instruction, ctx, accounts: string[]) => {
|
|
67
|
+
const origin = ins.data as any
|
|
68
|
+
if (origin) {
|
|
69
|
+
const data = { nonce: origin.nonce as number, amount: BigInt(origin.amount.toString()), fee: BigInt(origin.fee.toString()), targetAddress: origin.targetAddress as any, targetChain: origin.targetChain as number }
|
|
70
|
+
const accountData = { payer: accounts[0], config: accounts[1], from: accounts[2], fromOwner: accounts[3], mint: accounts[4], wrappedMeta: accounts[5], authoritySigner: accounts[6], wormholeBridge: accounts[7], wormholeMessage: accounts[8], wormholeEmitter: accounts[9], wormholeSequence: accounts[10], wormholeFeeCollector: accounts[11], clock: accounts[12], rent: accounts[13], systemProgram: accounts[14], tokenProgram: accounts[15], wormholeProgram: accounts[16] }
|
|
71
|
+
handler(data, accountData, ctx)
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
return this
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
onTransferNative(handler: (args: { nonce: number, amount: bigint, fee: bigint, targetAddress: any, targetChain: number }, accounts: { payer: string, config: string, from: string, mint: string, custody: string, authoritySigner: string, custodySigner: string, wormholeBridge: string, wormholeMessage: string, wormholeEmitter: string, wormholeSequence: string, wormholeFeeCollector: string, clock: string, rent: string, systemProgram: string, tokenProgram: string, wormholeProgram: string }, ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
78
|
+
this.onInstruction('transferNative', (ins: Instruction, ctx, accounts: string[]) => {
|
|
79
|
+
const origin = ins.data as any
|
|
80
|
+
if (origin) {
|
|
81
|
+
const data = { nonce: origin.nonce as number, amount: BigInt(origin.amount.toString()), fee: BigInt(origin.fee.toString()), targetAddress: origin.targetAddress as any, targetChain: origin.targetChain as number }
|
|
82
|
+
const accountData = { payer: accounts[0], config: accounts[1], from: accounts[2], mint: accounts[3], custody: accounts[4], authoritySigner: accounts[5], custodySigner: accounts[6], wormholeBridge: accounts[7], wormholeMessage: accounts[8], wormholeEmitter: accounts[9], wormholeSequence: accounts[10], wormholeFeeCollector: accounts[11], clock: accounts[12], rent: accounts[13], systemProgram: accounts[14], tokenProgram: accounts[15], wormholeProgram: accounts[16] }
|
|
83
|
+
handler(data, accountData, ctx)
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
return this
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
onRegisterChain(handler: (args: { }, accounts: { payer: string, config: string, endpoint: string, vaa: string, claim: string, rent: string, systemProgram: string, wormholeProgram: string }, ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
90
|
+
this.onInstruction('registerChain', (ins: Instruction, ctx, accounts: string[]) => {
|
|
91
|
+
const origin = ins.data as any
|
|
92
|
+
if (origin) {
|
|
93
|
+
const data = { }
|
|
94
|
+
const accountData = { payer: accounts[0], config: accounts[1], endpoint: accounts[2], vaa: accounts[3], claim: accounts[4], rent: accounts[5], systemProgram: accounts[6], wormholeProgram: accounts[7] }
|
|
95
|
+
handler(data, accountData, ctx)
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
return this
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
onCreateWrapped(handler: (args: { }, accounts: { payer: string, config: string, endpoint: string, vaa: string, claim: string, mint: string, wrappedMeta: string, splMetadata: string, mintAuthority: string, rent: string, systemProgram: string, tokenProgram: string, splMetadataProgram: string, wormholeProgram: string }, ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
102
|
+
this.onInstruction('createWrapped', (ins: Instruction, ctx, accounts: string[]) => {
|
|
103
|
+
const origin = ins.data as any
|
|
104
|
+
if (origin) {
|
|
105
|
+
const data = { }
|
|
106
|
+
const accountData = { payer: accounts[0], config: accounts[1], endpoint: accounts[2], vaa: accounts[3], claim: accounts[4], mint: accounts[5], wrappedMeta: accounts[6], splMetadata: accounts[7], mintAuthority: accounts[8], rent: accounts[9], systemProgram: accounts[10], tokenProgram: accounts[11], splMetadataProgram: accounts[12], wormholeProgram: accounts[13] }
|
|
107
|
+
handler(data, accountData, ctx)
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
return this
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
onUpgradeContract(handler: (args: { }, accounts: { payer: string, vaa: string, claim: string, upgradeAuthority: string, spill: string, implementation: string, programData: string, tokenBridgeProgram: string, rent: string, clock: string, bpfLoaderUpgradeable: string, systemProgram: string }, ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
114
|
+
this.onInstruction('upgradeContract', (ins: Instruction, ctx, accounts: string[]) => {
|
|
115
|
+
const origin = ins.data as any
|
|
116
|
+
if (origin) {
|
|
117
|
+
const data = { }
|
|
118
|
+
const accountData = { payer: accounts[0], vaa: accounts[1], claim: accounts[2], upgradeAuthority: accounts[3], spill: accounts[4], implementation: accounts[5], programData: accounts[6], tokenBridgeProgram: accounts[7], rent: accounts[8], clock: accounts[9], bpfLoaderUpgradeable: accounts[10], systemProgram: accounts[11] }
|
|
119
|
+
handler(data, accountData, ctx)
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
return this
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
onTransferWrappedWithPayload(handler: (args: { nonce: number, amount: bigint, targetAddress: any, targetChain: number, payload: any, cpiProgramId: any }, accounts: { payer: string, config: string, from: string, fromOwner: string, mint: string, wrappedMeta: string, authoritySigner: string, wormholeBridge: string, wormholeMessage: string, wormholeEmitter: string, wormholeSequence: string, wormholeFeeCollector: string, clock: string, sender: string, rent: string, systemProgram: string, tokenProgram: string, wormholeProgram: string }, ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
126
|
+
this.onInstruction('transferWrappedWithPayload', (ins: Instruction, ctx, accounts: string[]) => {
|
|
127
|
+
const origin = ins.data as any
|
|
128
|
+
if (origin) {
|
|
129
|
+
const data = { nonce: origin.nonce as number, amount: BigInt(origin.amount.toString()), targetAddress: origin.targetAddress as any, targetChain: origin.targetChain as number, payload: origin.payload as any, cpiProgramId: origin.cpiProgramId as any }
|
|
130
|
+
const accountData = { payer: accounts[0], config: accounts[1], from: accounts[2], fromOwner: accounts[3], mint: accounts[4], wrappedMeta: accounts[5], authoritySigner: accounts[6], wormholeBridge: accounts[7], wormholeMessage: accounts[8], wormholeEmitter: accounts[9], wormholeSequence: accounts[10], wormholeFeeCollector: accounts[11], clock: accounts[12], sender: accounts[13], rent: accounts[14], systemProgram: accounts[15], tokenProgram: accounts[16], wormholeProgram: accounts[17] }
|
|
131
|
+
handler(data, accountData, ctx)
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
return this
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
onTransferNativeWithPayload(handler: (args: { nonce: number, amount: bigint, targetAddress: any, targetChain: number, payload: any, cpiProgramId: any }, accounts: { payer: string, config: string, from: string, mint: string, custody: string, authoritySigner: string, custodySigner: string, wormholeBridge: string, wormholeMessage: string, wormholeEmitter: string, wormholeSequence: string, wormholeFeeCollector: string, clock: string, sender: string, rent: string, systemProgram: string, tokenProgram: string, wormholeProgram: string }, ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
138
|
+
this.onInstruction('transferNativeWithPayload', (ins: Instruction, ctx, accounts: string[]) => {
|
|
139
|
+
const origin = ins.data as any
|
|
140
|
+
if (origin) {
|
|
141
|
+
const data = { nonce: origin.nonce as number, amount: BigInt(origin.amount.toString()), targetAddress: origin.targetAddress as any, targetChain: origin.targetChain as number, payload: origin.payload as any, cpiProgramId: origin.cpiProgramId as any }
|
|
142
|
+
const accountData = { payer: accounts[0], config: accounts[1], from: accounts[2], mint: accounts[3], custody: accounts[4], authoritySigner: accounts[5], custodySigner: accounts[6], wormholeBridge: accounts[7], wormholeMessage: accounts[8], wormholeEmitter: accounts[9], wormholeSequence: accounts[10], wormholeFeeCollector: accounts[11], clock: accounts[12], sender: accounts[13], rent: accounts[14], systemProgram: accounts[15], tokenProgram: accounts[16], wormholeProgram: accounts[17] }
|
|
143
|
+
handler(data, accountData, ctx)
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
return this
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { SPLTokenProcessor } from '@sentio/sdk/solana/builtin'
|
|
2
|
+
import { TokenBridgeProcessor } from './types/token_bridge_processor.js'
|
|
3
|
+
|
|
4
|
+
import { token_bridge_idl } from './types/token_bridge.js'
|
|
5
|
+
import { Idl, Instruction } from '@project-serum/anchor'
|
|
6
|
+
import bs58 from 'bs58'
|
|
7
|
+
import { camelCase, upperFirst } from 'lodash-es'
|
|
8
|
+
// @ts-ignore no type definition
|
|
9
|
+
import { Layout } from 'buffer-layout'
|
|
10
|
+
import { IdlField, IdlStateMethod } from '@project-serum/anchor/dist/cjs/idl.js'
|
|
11
|
+
import * as borsh from '@coral-xyz/borsh'
|
|
12
|
+
import { IdlCoder } from '@project-serum/anchor/dist/cjs/coder/borsh/idl.js'
|
|
13
|
+
|
|
14
|
+
// TODO this could be more general
|
|
15
|
+
class TokenBridgeDecoder {
|
|
16
|
+
private ixLayout: Map<string, Layout>
|
|
17
|
+
|
|
18
|
+
constructor(idl: Idl) {
|
|
19
|
+
this.ixLayout = TokenBridgeDecoder.parseIxLayout(idl)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private static parseIxLayout(idl: Idl): Map<string, Layout> {
|
|
23
|
+
const stateMethods = idl.state ? idl.state.methods : []
|
|
24
|
+
|
|
25
|
+
const ixLayouts = stateMethods
|
|
26
|
+
.map((m: IdlStateMethod): [string, Layout<unknown>] => {
|
|
27
|
+
const fieldLayouts = m.args.map((arg: IdlField) => {
|
|
28
|
+
return IdlCoder.fieldLayout(arg, Array.from([...(idl.accounts ?? []), ...(idl.types ?? [])]))
|
|
29
|
+
})
|
|
30
|
+
const name = camelCase(m.name)
|
|
31
|
+
return [name, borsh.struct(fieldLayouts, name)]
|
|
32
|
+
})
|
|
33
|
+
.concat(
|
|
34
|
+
idl.instructions.map((ix) => {
|
|
35
|
+
const fieldLayouts = ix.args.map((arg: IdlField) =>
|
|
36
|
+
IdlCoder.fieldLayout(arg, Array.from([...(idl.accounts ?? []), ...(idl.types ?? [])]))
|
|
37
|
+
)
|
|
38
|
+
const name = camelCase(ix.name)
|
|
39
|
+
return [name, borsh.struct(fieldLayouts, name)]
|
|
40
|
+
})
|
|
41
|
+
)
|
|
42
|
+
return new Map(ixLayouts)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public decode(ix: Buffer | string, encoding: 'hex' | 'base58' = 'hex'): Instruction | null {
|
|
46
|
+
if (typeof ix === 'string') {
|
|
47
|
+
ix = encoding === 'hex' ? Buffer.from(ix, 'hex') : Buffer.from(bs58.decode(ix))
|
|
48
|
+
}
|
|
49
|
+
const discriminator = ix.subarray(0, 1).readInt8()
|
|
50
|
+
const data = ix.subarray(1)
|
|
51
|
+
|
|
52
|
+
const name = camelCase(TokenBridgeInstruction[discriminator])
|
|
53
|
+
const layout = this.ixLayout.get(name)
|
|
54
|
+
|
|
55
|
+
if (!layout) {
|
|
56
|
+
return null
|
|
57
|
+
}
|
|
58
|
+
return { data: this.ixLayout.get(name)?.decode(data), name }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export enum TokenBridgeInstruction {
|
|
63
|
+
Initialize,
|
|
64
|
+
AttestToken,
|
|
65
|
+
CompleteNative,
|
|
66
|
+
CompleteWrapped,
|
|
67
|
+
TransferWrapped,
|
|
68
|
+
TransferNative,
|
|
69
|
+
RegisterChain,
|
|
70
|
+
CreateWrapped,
|
|
71
|
+
UpgradeContract,
|
|
72
|
+
CompleteNativeWithPayload,
|
|
73
|
+
CompleteWrappedWithPayload,
|
|
74
|
+
TransferWrappedWithPayload,
|
|
75
|
+
TransferNativeWithPayload,
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
TokenBridgeProcessor.bind({
|
|
79
|
+
address: 'wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb',
|
|
80
|
+
instructionCoder: new TokenBridgeDecoder(token_bridge_idl as Idl),
|
|
81
|
+
}).onTransferNative((args, accounts, ctx) => {
|
|
82
|
+
ctx.meter.Counter('total_transfer_amount').add(args.amount)
|
|
83
|
+
ctx.meter.Counter(accounts.payer).add(args.amount)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
SPLTokenProcessor.bind({ address: 'wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb', processInnerInstruction: true })
|
|
87
|
+
.onMintTo((data, ctx) => {
|
|
88
|
+
if (data.mint === '7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs') {
|
|
89
|
+
ctx.meter.Counter('totalWeth_supply').add(BigInt(data.amount))
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
.onBurn((data, ctx) => {
|
|
93
|
+
if (data.mint === '7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs') {
|
|
94
|
+
ctx.meter.Counter('totalWeth_supply').sub(BigInt(data.amount))
|
|
95
|
+
}
|
|
96
|
+
})
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
} from '@sentio/protos'
|
|
15
15
|
import { CallContext } from 'nice-grpc-common'
|
|
16
16
|
import { ProcessorServiceImpl, Endpoints, State } from '@sentio/runtime'
|
|
17
|
-
import { CHAIN_MAP } from '../
|
|
17
|
+
import { CHAIN_MAP } from '../chain.js'
|
|
18
18
|
|
|
19
19
|
import { Trace } from '../eth/trace.js'
|
|
20
20
|
import { LogParams, Networkish, BlockParams, Network } from 'ethers/providers'
|
package/src/utils/index.ts
CHANGED
package/lib/utils/chain.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chain.js","sourceRoot":"","sources":["../../src/utils/chain.ts"],"names":[],"mappings":"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","sourcesContent":["// copy from https://github.com/DefiLlama/chainlist/blob/main/constants/chainIds.js\n// and https://besu.hyperledger.org/en/stable/Concepts/NetworkID-And-ChainID/\n\nexport const CHAIN_IDS = {\n KARDIA: '0',\n ETHEREUM: '1',\n EXPANSE: '2',\n ROPSTEN: '3',\n RINKEBY: '4',\n GOERLI: '5',\n KOTTI: '6',\n UBIQ: '8',\n OPTIMISM: '10',\n SONGBIRD: '19',\n ELASTOS: '20',\n CRONOS: '25',\n RSK: '30',\n TELOS: '40',\n XDC: '50',\n CSC: '52',\n ZYX: '55',\n BINANCE: '56',\n SYSCOIN: '57',\n GOCHAIN: '60',\n ETHCLASSIC: '61',\n MORDOR: '63',\n OKEXCHAIN: '66',\n HOO: '70',\n METER: '82',\n TOMOCHAIN: '88',\n XDAI: '100',\n VELAS: '106',\n THUNDERCORE: '108',\n FUSE: '122',\n HECO: '128',\n POLYGON: '137',\n XDAIARB: '200',\n ASTOR: '212',\n ENERGYWEB: '246',\n FANTOM: '250',\n HPB: '269',\n BOBA: '288',\n KUCOIN: '321',\n SHIDEN: '336',\n THETA: '361',\n SX: '416',\n CANDLE: '534',\n ASTAR: '592',\n CALLISTO: '820',\n WANCHAIN: '888',\n METIS: '1088',\n OMCHAIN: '1246',\n MOONBEAM: '1284',\n MOONRIVER: '1285',\n MOONBASE: '1287',\n DEV: '2018',\n RONIN: '2020',\n KAVA: '2222',\n EZCHAIN: '2612',\n PHI: '4181',\n IOTEX: '4689',\n XLC: '5050',\n NAHMII: '5551',\n NMACTEST: '7777',\n KLAYTN: '8217',\n EVMOS: '9001',\n SMARTBCH: '10000',\n CRYSTALEUM: '103090',\n FUSION: '32659',\n ARBITRUM: '42161',\n CELO: '42220',\n OASIS: '42262',\n AVALANCHE: '43114',\n GODWOKEN: '71402',\n AKROMA: '200625',\n POLIS: '333999',\n ARBITRUM_TEST: '421613',\n SEPOLIA: '11155111',\n AURORA: '1313161554',\n HARMONY: '1666600000',\n PALM: '11297108109',\n CURIO: '836542336838601',\n SOLANA_MAINNET: 'sol_mainnet',\n SOLANA_DEVNET: 'sol_devnet',\n SOLANA_TESTNET: 'sol_testnet',\n SOLANA_PYTH: 'sol_pyth',\n SUI_DEVNET: 'sui_devnet',\n APTOS_MAINNET: 'aptos_mainnet',\n APTOS_TESTNET: 'aptos_testnet',\n}\n\nexport const CHAIN_MAP: Record<string, string> = {}\n\nfor (const [key, value] of Object.entries(CHAIN_IDS)) {\n const parts = key.split('_')\n CHAIN_MAP[value] = parts\n .map((part, index) => {\n return part[0] + part.slice(1).toLowerCase()\n })\n .join(' ')\n}\n\nexport function getChainName(chainId: string | number | null | undefined): string {\n if (typeof chainId === 'number') {\n chainId = chainId.toString()\n }\n if (chainId) {\n const name = CHAIN_MAP[chainId]\n if (name) {\n return name\n }\n }\n return chainId || ''\n}\n\nexport function getChainType(chainId?: string | number): string {\n const id = String(chainId).toLowerCase()\n if (id.startsWith('sol')) {\n return 'solana'\n }\n if (id.startsWith('sui')) {\n return 'sui'\n }\n if (id.startsWith('apt')) {\n return 'aptos'\n }\n return 'EVM'\n}\n"]}
|