@sentio/sdk 1.7.14 → 1.7.17
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/{base-processor-template.d.ts → lib/base-processor-template.d.ts} +0 -0
- package/{base-processor-template.js → lib/base-processor-template.js} +0 -0
- package/{base-processor-template.js.map → lib/base-processor-template.js.map} +0 -0
- package/{base-processor.d.ts → lib/base-processor.d.ts} +0 -0
- package/{base-processor.js → lib/base-processor.js} +0 -0
- package/{base-processor.js.map → lib/base-processor.js.map} +0 -0
- package/{bind-options.d.ts → lib/bind-options.d.ts} +0 -0
- package/{bind-options.js → lib/bind-options.js} +0 -0
- package/{bind-options.js.map → lib/bind-options.js.map} +0 -0
- package/{binds.d.ts → lib/binds.d.ts} +0 -0
- package/{binds.js → lib/binds.js} +0 -0
- package/{binds.js.map → lib/binds.js.map} +0 -0
- package/{builtin → lib/builtin}/erc20/index.d.ts +0 -0
- package/{builtin → lib/builtin}/erc20/index.js +0 -0
- package/{builtin → lib/builtin}/erc20/index.js.map +0 -0
- package/{builtin → lib/builtin}/erc20/test-utils.d.ts +0 -0
- package/{builtin → lib/builtin}/erc20/test-utils.js +0 -0
- package/{builtin → lib/builtin}/erc20/test-utils.js.map +0 -0
- package/{builtin → lib/builtin}/internal/Erc20.d.ts +0 -0
- package/{builtin → lib/builtin}/internal/Erc20.js +0 -0
- package/{builtin → lib/builtin}/internal/Erc20.js.map +0 -0
- package/lib/builtin/internal/Weth9.d.ts +221 -0
- package/lib/builtin/internal/Weth9.js +3 -0
- package/lib/builtin/internal/Weth9.js.map +1 -0
- package/{builtin → lib/builtin}/internal/common.d.ts +0 -0
- package/{builtin → lib/builtin}/internal/common.js +0 -0
- package/{builtin → lib/builtin}/internal/common.js.map +0 -0
- package/{builtin → lib/builtin}/internal/erc20_processor.d.ts +0 -0
- package/{builtin → lib/builtin}/internal/erc20_processor.js +0 -0
- package/{builtin → lib/builtin}/internal/erc20_processor.js.map +0 -0
- package/{builtin → lib/builtin}/internal/factories/Erc20__factory.d.ts +0 -0
- package/{builtin → lib/builtin}/internal/factories/Erc20__factory.js +0 -0
- package/{builtin → lib/builtin}/internal/factories/Erc20__factory.js.map +0 -0
- package/lib/builtin/internal/factories/Weth9__factory.d.ts +45 -0
- package/lib/builtin/internal/factories/Weth9__factory.js +297 -0
- package/lib/builtin/internal/factories/Weth9__factory.js.map +1 -0
- package/{builtin → lib/builtin}/internal/factories/index.d.ts +1 -0
- package/{builtin → lib/builtin}/internal/factories/index.js +3 -1
- package/lib/builtin/internal/factories/index.js.map +1 -0
- package/{builtin → lib/builtin}/internal/index.d.ts +2 -0
- package/{builtin → lib/builtin}/internal/index.js +3 -1
- package/lib/builtin/internal/index.js.map +1 -0
- package/lib/builtin/internal/weth9_processor.d.ts +50 -0
- package/lib/builtin/internal/weth9_processor.js +295 -0
- package/lib/builtin/internal/weth9_processor.js.map +1 -0
- package/lib/builtin/weth9/index.d.ts +2 -0
- package/lib/builtin/weth9/index.js +22 -0
- package/lib/builtin/weth9/index.js.map +1 -0
- package/lib/builtin/weth9/test-utils.d.ts +6 -0
- package/lib/builtin/weth9/test-utils.js +57 -0
- package/lib/builtin/weth9/test-utils.js.map +1 -0
- package/{chain-config.d.ts → lib/chain-config.d.ts} +0 -0
- package/{chain-config.js → lib/chain-config.js} +0 -0
- package/{chain-config.js.map → lib/chain-config.js.map} +0 -0
- package/{cli → lib/cli}/build.d.ts +0 -0
- package/{cli → lib/cli}/build.js +14 -0
- package/lib/cli/build.js.map +1 -0
- package/{cli → lib/cli}/cli.d.ts +0 -0
- package/{cli → lib/cli}/cli.js +0 -0
- package/{cli → lib/cli}/cli.js.map +0 -0
- package/{cli → lib/cli}/config.d.ts +0 -0
- package/{cli → lib/cli}/config.js +0 -0
- package/{cli → lib/cli}/config.js.map +0 -0
- package/{cli → lib/cli}/key.d.ts +0 -0
- package/{cli → lib/cli}/key.js +0 -0
- package/{cli → lib/cli}/key.js.map +0 -0
- package/{cli → lib/cli}/solana-code-gen.d.ts +0 -0
- package/{cli → lib/cli}/solana-code-gen.js +0 -0
- package/{cli → lib/cli}/solana-code-gen.js.map +0 -0
- package/{cli → lib/cli}/upload.d.ts +0 -0
- package/{cli → lib/cli}/upload.js +0 -0
- package/{cli → lib/cli}/upload.js.map +0 -0
- package/{cli → lib/cli}/webpack.config.js +0 -0
- package/{context.d.ts → lib/context.d.ts} +0 -0
- package/{context.js → lib/context.js} +0 -0
- package/{context.js.map → lib/context.js.map} +0 -0
- package/{contract-namer.d.ts → lib/contract-namer.d.ts} +0 -0
- package/{contract-namer.js → lib/contract-namer.js} +0 -0
- package/{contract-namer.js.map → lib/contract-namer.js.map} +0 -0
- package/{error.d.ts → lib/error.d.ts} +0 -0
- package/{error.js → lib/error.js} +0 -0
- package/{error.js.map → lib/error.js.map} +0 -0
- package/{gen → lib/gen}/builtin.d.ts +0 -0
- package/{gen → lib/gen}/builtin.js +0 -0
- package/{gen → lib/gen}/builtin.js.map +0 -0
- package/{gen → lib/gen}/google/protobuf/empty.d.ts +0 -0
- package/{gen → lib/gen}/google/protobuf/empty.js +0 -0
- package/{gen → lib/gen}/google/protobuf/empty.js.map +0 -0
- package/{gen → lib/gen}/processor/protos/processor.d.ts +0 -0
- package/{gen → lib/gen}/processor/protos/processor.js +0 -0
- package/{gen → lib/gen}/processor/protos/processor.js.map +0 -0
- package/{generic-processor.d.ts → lib/generic-processor.d.ts} +0 -0
- package/{generic-processor.js → lib/generic-processor.js} +0 -0
- package/{generic-processor.js.map → lib/generic-processor.js.map} +0 -0
- package/{index.d.ts → lib/index.d.ts} +0 -0
- package/{index.js → lib/index.js} +0 -0
- package/{index.js.map → lib/index.js.map} +0 -0
- package/lib/loader.d.ts +5 -0
- package/lib/loader.js +30 -0
- package/lib/loader.js.map +1 -0
- package/{meter.d.ts → lib/meter.d.ts} +0 -0
- package/{meter.js → lib/meter.js} +0 -0
- package/{meter.js.map → lib/meter.js.map} +0 -0
- package/{numberish.d.ts → lib/numberish.d.ts} +0 -0
- package/{numberish.js → lib/numberish.js} +0 -0
- package/{numberish.js.map → lib/numberish.js.map} +0 -0
- package/{numberish.test.d.ts → lib/numberish.test.d.ts} +0 -0
- package/{numberish.test.js → lib/numberish.test.js} +0 -0
- package/{numberish.test.js.map → lib/numberish.test.js.map} +0 -0
- package/{processor-runner.d.ts → lib/processor-runner.d.ts} +0 -0
- package/{processor-runner.js → lib/processor-runner.js} +2 -27
- package/lib/processor-runner.js.map +1 -0
- package/{processor-state.d.ts → lib/processor-state.d.ts} +0 -0
- package/{processor-state.js → lib/processor-state.js} +0 -0
- package/{processor-state.js.map → lib/processor-state.js.map} +0 -0
- package/{promise-or-void.d.ts → lib/promise-or-void.d.ts} +0 -0
- package/{promise-or-void.js → lib/promise-or-void.js} +0 -0
- package/{promise-or-void.js.map → lib/promise-or-void.js.map} +0 -0
- package/{provider.d.ts → lib/provider.d.ts} +0 -0
- package/{provider.js → lib/provider.js} +0 -0
- package/{provider.js.map → lib/provider.js.map} +0 -0
- package/{release.config.js → lib/release.config.js} +0 -0
- package/{service.d.ts → lib/service.d.ts} +2 -1
- package/{service.js → lib/service.js} +6 -3
- package/lib/service.js.map +1 -0
- package/{solana → lib/solana}/builtin/index.d.ts +0 -0
- package/{solana → lib/solana}/builtin/index.js +0 -0
- package/{solana → lib/solana}/builtin/index.js.map +0 -0
- package/{solana → lib/solana}/builtin/spl-token-processor.d.ts +0 -0
- package/{solana → lib/solana}/builtin/spl-token-processor.js +0 -0
- package/{solana → lib/solana}/builtin/spl-token-processor.js.map +0 -0
- package/{solana → lib/solana}/builtin/types.d.ts +0 -0
- package/{solana → lib/solana}/builtin/types.js +0 -0
- package/{solana → lib/solana}/builtin/types.js.map +0 -0
- package/{solana → lib/solana}/builtin/wormhole-processor.d.ts +0 -0
- package/{solana → lib/solana}/builtin/wormhole-processor.js +0 -0
- package/{solana → lib/solana}/builtin/wormhole-processor.js.map +0 -0
- package/{solana-processor.d.ts → lib/solana-processor.d.ts} +0 -0
- package/{solana-processor.js → lib/solana-processor.js} +0 -0
- package/{solana-processor.js.map → lib/solana-processor.js.map} +0 -0
- package/{target-ethers-sentio → lib/target-ethers-sentio}/codegen.d.ts +0 -0
- package/{target-ethers-sentio → lib/target-ethers-sentio}/codegen.js +0 -0
- package/lib/target-ethers-sentio/codegen.js.map +1 -0
- package/{target-ethers-sentio → lib/target-ethers-sentio}/index.d.ts +0 -0
- package/{target-ethers-sentio → lib/target-ethers-sentio}/index.js +0 -0
- package/lib/target-ethers-sentio/index.js.map +1 -0
- package/{test → lib/test}/codegen.test.d.ts +0 -0
- package/{test → lib/test}/codegen.test.js +1 -1
- package/{test → lib/test}/codegen.test.js.map +1 -1
- package/{test → lib/test}/erc20-template.d.ts +0 -0
- package/{test → lib/test}/erc20-template.js +0 -0
- package/{test → lib/test}/erc20-template.js.map +0 -0
- package/{test → lib/test}/erc20-template.test.d.ts +0 -0
- package/{test → lib/test}/erc20-template.test.js +1 -3
- package/lib/test/erc20-template.test.js.map +1 -0
- package/{test → lib/test}/erc20.d.ts +0 -0
- package/{test → lib/test}/erc20.js +0 -0
- package/{test → lib/test}/erc20.js.map +0 -0
- package/{test → lib/test}/erc20.test.d.ts +0 -0
- package/{test → lib/test}/erc20.test.js +1 -3
- package/lib/test/erc20.test.js.map +1 -0
- package/{test → lib/test}/generic-processor.test.d.ts +0 -0
- package/{test → lib/test}/generic-processor.test.js +3 -3
- package/lib/test/generic-processor.test.js.map +1 -0
- package/{test → lib/test}/index.d.ts +0 -0
- package/{test → lib/test}/index.js +0 -0
- package/{test → lib/test}/index.js.map +0 -0
- package/{test → lib/test}/metric-utils.d.ts +0 -0
- package/{test → lib/test}/metric-utils.js +0 -0
- package/{test → lib/test}/metric-utils.js.map +0 -0
- package/{test → lib/test}/mirrorworld.d.ts +0 -0
- package/{test → lib/test}/mirrorworld.js +0 -0
- package/{test → lib/test}/mirrorworld.js.map +0 -0
- package/{test → lib/test}/solana.test.d.ts +0 -0
- package/{test → lib/test}/solana.test.js +3 -3
- package/lib/test/solana.test.js.map +1 -0
- package/{test → lib/test}/test-processor-server.d.ts +1 -1
- package/{test → lib/test}/test-processor-server.js +3 -8
- package/lib/test/test-processor-server.js.map +1 -0
- package/{test → lib/test}/types/game_wallet.d.ts +0 -0
- package/{test → lib/test}/types/game_wallet.js +0 -0
- package/{test → lib/test}/types/game_wallet.js.map +0 -0
- package/{test → lib/test}/types/game_wallet_processor.d.ts +0 -0
- package/{test → lib/test}/types/game_wallet_processor.js +0 -0
- package/{test → lib/test}/types/game_wallet_processor.js.map +0 -0
- package/{test → lib/test}/wormhole-token-bridge.d.ts +0 -0
- package/{test → lib/test}/wormhole-token-bridge.js +0 -0
- package/{test → lib/test}/wormhole-token-bridge.js.map +0 -0
- package/{utils → lib/utils}/chainmap.d.ts +0 -0
- package/{utils → lib/utils}/chainmap.js +0 -0
- package/{utils → lib/utils}/chainmap.js.map +0 -0
- package/{utils → lib/utils}/convert.d.ts +0 -0
- package/{utils → lib/utils}/convert.js +0 -0
- package/{utils → lib/utils}/convert.js.map +0 -0
- package/{utils → lib/utils}/index.d.ts +0 -0
- package/{utils → lib/utils}/index.js +0 -0
- package/{utils → lib/utils}/index.js.map +0 -0
- package/package.json +47 -6
- package/src/abis/erc20.json +198 -0
- package/src/abis/weth9.json +153 -0
- package/src/base-processor-template.ts +92 -0
- package/src/base-processor.ts +128 -0
- package/src/bind-options.ts +41 -0
- package/src/binds.ts +73 -0
- package/src/builtin/erc20/index.ts +6 -0
- package/src/builtin/erc20/test-utils.ts +49 -0
- package/src/builtin/internal/Erc20.ts +356 -0
- package/src/builtin/internal/Weth9.ts +480 -0
- package/src/builtin/internal/common.ts +46 -0
- package/src/builtin/internal/erc20_processor.ts +295 -0
- package/src/builtin/internal/factories/Erc20__factory.ts +216 -0
- package/src/builtin/internal/factories/Weth9__factory.ts +297 -0
- package/src/builtin/internal/factories/index.ts +5 -0
- package/src/builtin/internal/index.ts +8 -0
- package/src/builtin/internal/weth9_processor.ts +403 -0
- package/src/builtin/weth9/index.ts +6 -0
- package/src/builtin/weth9/test-utils.ts +89 -0
- package/src/chain-config.ts +6 -0
- package/src/cli/build.ts +196 -0
- package/src/cli/cli.ts +217 -0
- package/src/cli/config.ts +43 -0
- package/src/cli/key.ts +43 -0
- package/src/cli/solana-code-gen.ts +16 -0
- package/src/cli/upload.ts +86 -0
- package/src/cli/webpack.config.js +42 -0
- package/src/context.ts +93 -0
- package/src/contract-namer.ts +17 -0
- package/src/error.ts +43 -0
- package/src/gen/builtin.ts +22 -0
- package/src/gen/google/protobuf/empty.ts +70 -0
- package/src/gen/processor/protos/processor.ts +3071 -0
- package/src/generic-processor.ts +38 -0
- package/src/index.ts +19 -0
- package/src/loader.ts +24 -0
- package/src/meter.ts +122 -0
- package/src/numberish.test.ts +82 -0
- package/src/numberish.ts +99 -0
- package/src/processor-runner.ts +49 -0
- package/src/processor-state.ts +24 -0
- package/src/promise-or-void.ts +1 -0
- package/src/provider.ts +74 -0
- package/src/service.ts +439 -0
- package/src/solana/builtin/index.ts +2 -0
- package/src/solana/builtin/spl-token-processor.ts +164 -0
- package/src/solana/builtin/types.ts +268 -0
- package/src/solana/builtin/wormhole-processor.ts +178 -0
- package/src/solana-processor.ts +105 -0
- package/src/target-ethers-sentio/codegen.ts +289 -0
- package/src/target-ethers-sentio/index.ts +50 -0
- package/src/target-ethers-sentio/tsconfig.json +9 -0
- package/src/test/abis/evm/anyswapRouter.json +490 -0
- package/src/test/abis/solana/mirrorworld.json +1392 -0
- package/src/test/codegen.test.ts +26 -0
- package/src/test/erc20-template.test.ts +37 -0
- package/src/test/erc20-template.ts +25 -0
- package/src/test/erc20.test.ts +90 -0
- package/src/test/erc20.ts +48 -0
- package/src/test/generic-processor.test.ts +70 -0
- package/src/test/index.ts +1 -0
- package/src/test/metric-utils.ts +49 -0
- package/src/test/mirrorworld.ts +40 -0
- package/src/test/sentio.yaml +4 -0
- package/src/test/solana.test.ts +93 -0
- package/src/test/test-processor-server.ts +205 -0
- package/src/test/types/game_wallet.ts +1392 -0
- package/src/test/types/game_wallet_processor.ts +113 -0
- package/src/test/wormhole-token-bridge.ts +21 -0
- package/src/types/global.d.ts +17 -0
- package/src/utils/chainmap.ts +95 -0
- package/src/utils/convert.ts +6 -0
- package/src/utils/index.ts +2 -0
- package/builtin/internal/factories/index.js.map +0 -1
- package/builtin/internal/index.js.map +0 -1
- package/cli/build.js.map +0 -1
- package/processor-runner.js.map +0 -1
- package/service.js.map +0 -1
- package/target-ethers-sentio/codegen.js.map +0 -1
- package/target-ethers-sentio/index.js.map +0 -1
- package/test/erc20-template.test.js.map +0 -1
- package/test/erc20.test.js.map +0 -1
- package/test/generic-processor.test.js.map +0 -1
- package/test/solana.test.js.map +0 -1
- package/test/test-processor-server.js.map +0 -1
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-redeclare */
|
|
2
|
+
// copy from https://github.com/solana-labs/solana/blob/master/explorer/src/components/instruction/token/types.ts
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
enums,
|
|
6
|
+
type,
|
|
7
|
+
Infer,
|
|
8
|
+
number,
|
|
9
|
+
string,
|
|
10
|
+
optional,
|
|
11
|
+
array,
|
|
12
|
+
nullable,
|
|
13
|
+
union,
|
|
14
|
+
coerce,
|
|
15
|
+
instance,
|
|
16
|
+
} from "superstruct";
|
|
17
|
+
|
|
18
|
+
// Replace with string
|
|
19
|
+
export const PublicKeyFromString = coerce(
|
|
20
|
+
instance(String),
|
|
21
|
+
string(),
|
|
22
|
+
(value) => (value)
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export type TokenAmountUi = Infer<typeof TokenAmountUi>;
|
|
26
|
+
export type MintTo = Infer<typeof MintTo>;
|
|
27
|
+
export type Burn = Infer<typeof Burn>;
|
|
28
|
+
export type InitializeMint = Infer<typeof InitializeMint>;
|
|
29
|
+
export type InitializeAccount = Infer<typeof InitializeAccount>;
|
|
30
|
+
export type InitializeAccount2 = Infer<typeof InitializeAccount2>;
|
|
31
|
+
export type InitializeAccount3 = Infer<typeof InitializeAccount3>;
|
|
32
|
+
export type InitializeMultisig = Infer<typeof InitializeMultisig>;
|
|
33
|
+
|
|
34
|
+
export const TokenAmountUi = type({
|
|
35
|
+
amount: string(),
|
|
36
|
+
decimals: number(),
|
|
37
|
+
uiAmountString: string(),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const InitializeMint = type({
|
|
41
|
+
mint: PublicKeyFromString,
|
|
42
|
+
decimals: number(),
|
|
43
|
+
mintAuthority: PublicKeyFromString,
|
|
44
|
+
rentSysvar: PublicKeyFromString,
|
|
45
|
+
freezeAuthority: optional(PublicKeyFromString),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const InitializeAccount = type({
|
|
49
|
+
account: PublicKeyFromString,
|
|
50
|
+
mint: PublicKeyFromString,
|
|
51
|
+
owner: PublicKeyFromString,
|
|
52
|
+
rentSysvar: PublicKeyFromString,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const InitializeAccount2 = type({
|
|
56
|
+
account: PublicKeyFromString,
|
|
57
|
+
mint: PublicKeyFromString,
|
|
58
|
+
rentSysvar: PublicKeyFromString,
|
|
59
|
+
owner: PublicKeyFromString,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const InitializeAccount3 = type({
|
|
63
|
+
account: PublicKeyFromString,
|
|
64
|
+
mint: PublicKeyFromString,
|
|
65
|
+
owner: PublicKeyFromString,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const InitializeMultisig = type({
|
|
69
|
+
multisig: PublicKeyFromString,
|
|
70
|
+
rentSysvar: PublicKeyFromString,
|
|
71
|
+
signers: array(PublicKeyFromString),
|
|
72
|
+
m: number(),
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
export type Transfer = Infer<typeof Transfer>;
|
|
76
|
+
export const Transfer = type({
|
|
77
|
+
source: PublicKeyFromString,
|
|
78
|
+
destination: PublicKeyFromString,
|
|
79
|
+
amount: union([string(), number()]),
|
|
80
|
+
authority: optional(PublicKeyFromString),
|
|
81
|
+
multisigAuthority: optional(PublicKeyFromString),
|
|
82
|
+
signers: optional(array(PublicKeyFromString)),
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export type Approve = Infer<typeof Approve>;
|
|
86
|
+
const Approve = type({
|
|
87
|
+
source: PublicKeyFromString,
|
|
88
|
+
delegate: PublicKeyFromString,
|
|
89
|
+
amount: union([string(), number()]),
|
|
90
|
+
owner: optional(PublicKeyFromString),
|
|
91
|
+
multisigOwner: optional(PublicKeyFromString),
|
|
92
|
+
signers: optional(array(PublicKeyFromString)),
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
export type Revoke = Infer<typeof Revoke>;
|
|
96
|
+
const Revoke = type({
|
|
97
|
+
source: PublicKeyFromString,
|
|
98
|
+
owner: optional(PublicKeyFromString),
|
|
99
|
+
multisigOwner: optional(PublicKeyFromString),
|
|
100
|
+
signers: optional(array(PublicKeyFromString)),
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const AuthorityType = enums([
|
|
104
|
+
"mintTokens",
|
|
105
|
+
"freezeAccount",
|
|
106
|
+
"accountOwner",
|
|
107
|
+
"closeAccount",
|
|
108
|
+
]);
|
|
109
|
+
|
|
110
|
+
export type SetAuthority = Infer<typeof SetAuthority>;
|
|
111
|
+
const SetAuthority = type({
|
|
112
|
+
mint: optional(PublicKeyFromString),
|
|
113
|
+
account: optional(PublicKeyFromString),
|
|
114
|
+
authorityType: AuthorityType,
|
|
115
|
+
newAuthority: nullable(PublicKeyFromString),
|
|
116
|
+
authority: optional(PublicKeyFromString),
|
|
117
|
+
multisigAuthority: optional(PublicKeyFromString),
|
|
118
|
+
signers: optional(array(PublicKeyFromString)),
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const MintTo = type({
|
|
122
|
+
mint: PublicKeyFromString,
|
|
123
|
+
account: PublicKeyFromString,
|
|
124
|
+
amount: union([string(), number()]),
|
|
125
|
+
mintAuthority: optional(PublicKeyFromString),
|
|
126
|
+
multisigMintAuthority: optional(PublicKeyFromString),
|
|
127
|
+
signers: optional(array(PublicKeyFromString)),
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const Burn = type({
|
|
131
|
+
account: PublicKeyFromString,
|
|
132
|
+
mint: PublicKeyFromString,
|
|
133
|
+
amount: union([string(), number()]),
|
|
134
|
+
authority: optional(PublicKeyFromString),
|
|
135
|
+
multisigAuthority: optional(PublicKeyFromString),
|
|
136
|
+
signers: optional(array(PublicKeyFromString)),
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const CloseAccount = type({
|
|
140
|
+
account: PublicKeyFromString,
|
|
141
|
+
destination: PublicKeyFromString,
|
|
142
|
+
owner: optional(PublicKeyFromString),
|
|
143
|
+
multisigOwner: optional(PublicKeyFromString),
|
|
144
|
+
signers: optional(array(PublicKeyFromString)),
|
|
145
|
+
});
|
|
146
|
+
export type CloseAccount = Infer<typeof CloseAccount>;
|
|
147
|
+
|
|
148
|
+
export type FreezeAccount = Infer<typeof FreezeAccount>;
|
|
149
|
+
const FreezeAccount = type({
|
|
150
|
+
account: PublicKeyFromString,
|
|
151
|
+
mint: PublicKeyFromString,
|
|
152
|
+
freezeAuthority: optional(PublicKeyFromString),
|
|
153
|
+
multisigFreezeAuthority: optional(PublicKeyFromString),
|
|
154
|
+
signers: optional(array(PublicKeyFromString)),
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
export type ThawAccount = Infer<typeof ThawAccount>;
|
|
158
|
+
const ThawAccount = type({
|
|
159
|
+
account: PublicKeyFromString,
|
|
160
|
+
mint: PublicKeyFromString,
|
|
161
|
+
freezeAuthority: optional(PublicKeyFromString),
|
|
162
|
+
multisigFreezeAuthority: optional(PublicKeyFromString),
|
|
163
|
+
signers: optional(array(PublicKeyFromString)),
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
export type TransferChecked = Infer<typeof TransferChecked>;
|
|
167
|
+
export const TransferChecked = type({
|
|
168
|
+
source: PublicKeyFromString,
|
|
169
|
+
mint: PublicKeyFromString,
|
|
170
|
+
destination: PublicKeyFromString,
|
|
171
|
+
authority: optional(PublicKeyFromString),
|
|
172
|
+
multisigAuthority: optional(PublicKeyFromString),
|
|
173
|
+
signers: optional(array(PublicKeyFromString)),
|
|
174
|
+
tokenAmount: TokenAmountUi,
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
export type ApproveChecked = Infer<typeof ApproveChecked>;
|
|
178
|
+
const ApproveChecked = type({
|
|
179
|
+
source: PublicKeyFromString,
|
|
180
|
+
mint: PublicKeyFromString,
|
|
181
|
+
delegate: PublicKeyFromString,
|
|
182
|
+
owner: optional(PublicKeyFromString),
|
|
183
|
+
multisigOwner: optional(PublicKeyFromString),
|
|
184
|
+
signers: optional(array(PublicKeyFromString)),
|
|
185
|
+
tokenAmount: TokenAmountUi,
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
export type MintToChecked = Infer<typeof MintToChecked>;
|
|
189
|
+
const MintToChecked = type({
|
|
190
|
+
account: PublicKeyFromString,
|
|
191
|
+
mint: PublicKeyFromString,
|
|
192
|
+
mintAuthority: optional(PublicKeyFromString),
|
|
193
|
+
multisigMintAuthority: optional(PublicKeyFromString),
|
|
194
|
+
signers: optional(array(PublicKeyFromString)),
|
|
195
|
+
tokenAmount: TokenAmountUi,
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
export type BurnChecked = Infer<typeof BurnChecked>;
|
|
199
|
+
const BurnChecked = type({
|
|
200
|
+
account: PublicKeyFromString,
|
|
201
|
+
mint: PublicKeyFromString,
|
|
202
|
+
authority: optional(PublicKeyFromString),
|
|
203
|
+
multisigAuthority: optional(PublicKeyFromString),
|
|
204
|
+
signers: optional(array(PublicKeyFromString)),
|
|
205
|
+
tokenAmount: TokenAmountUi,
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const SyncNative = type({
|
|
209
|
+
account: PublicKeyFromString,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const GetAccountDataSize = type({
|
|
213
|
+
mint: PublicKeyFromString,
|
|
214
|
+
extensionTypes: optional(array(string())),
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
const InitializeImmutableOwner = type({
|
|
218
|
+
account: PublicKeyFromString,
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
const AmountToUiAmount = type({
|
|
222
|
+
mint: PublicKeyFromString,
|
|
223
|
+
amount: union([string(), number()]),
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
const UiAmountToAmount = type({
|
|
227
|
+
mint: PublicKeyFromString,
|
|
228
|
+
uiAmount: string(),
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
const InitializeMintCloseAuthority = type({
|
|
232
|
+
mint: PublicKeyFromString,
|
|
233
|
+
newAuthority: PublicKeyFromString,
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
const TransferFeeExtension = type({
|
|
237
|
+
mint: PublicKeyFromString,
|
|
238
|
+
transferFeeConfigAuthority: PublicKeyFromString,
|
|
239
|
+
withdrawWitheldAuthority: PublicKeyFromString,
|
|
240
|
+
transferFeeBasisPoints: number(),
|
|
241
|
+
maximumFee: number(),
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
const DefaultAccountStateExtension = type({
|
|
245
|
+
mint: PublicKeyFromString,
|
|
246
|
+
accountState: string(),
|
|
247
|
+
freezeAuthority: optional(PublicKeyFromString),
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
const Reallocate = type({
|
|
251
|
+
account: PublicKeyFromString,
|
|
252
|
+
payer: PublicKeyFromString,
|
|
253
|
+
systemProgram: PublicKeyFromString,
|
|
254
|
+
extensionTypes: array(string()),
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
const MemoTransferExtension = type({
|
|
258
|
+
account: PublicKeyFromString,
|
|
259
|
+
owner: optional(PublicKeyFromString),
|
|
260
|
+
multisigOwner: optional(PublicKeyFromString),
|
|
261
|
+
signers: optional(array(PublicKeyFromString)),
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
const CreateNativeMint = type({
|
|
265
|
+
payer: PublicKeyFromString,
|
|
266
|
+
nativeMint: PublicKeyFromString,
|
|
267
|
+
systemProgram: PublicKeyFromString,
|
|
268
|
+
});
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { SolanaBaseProcessor } from '../../solana-processor'
|
|
2
|
+
import { SolanaContext } from '../../context'
|
|
3
|
+
import { SolanaBindOptions } from '../../bind-options'
|
|
4
|
+
import { Instruction } from '@project-serum/anchor'
|
|
5
|
+
import * as borsh from '@project-serum/borsh'
|
|
6
|
+
import bs58 from 'bs58'
|
|
7
|
+
|
|
8
|
+
// https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/lib.rs#L100
|
|
9
|
+
enum TokenBrigeInstruction {
|
|
10
|
+
Initialize = 0,
|
|
11
|
+
AttestToken,
|
|
12
|
+
CompleteNative, // no args
|
|
13
|
+
CompleteWrapped, // no args
|
|
14
|
+
TransferWrapped,
|
|
15
|
+
TransferNative,
|
|
16
|
+
RegisterChain, // no args
|
|
17
|
+
CreateWrapped, // no args
|
|
18
|
+
UpgradeContract, // no args
|
|
19
|
+
CompleteNativeWithPayload, // no args
|
|
20
|
+
CompleteWrappedWithPayload, // no args
|
|
21
|
+
TransferWrappedWithPayload,
|
|
22
|
+
TransferNativeWithPayload,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class TokenBridgeProcessor extends SolanaBaseProcessor {
|
|
26
|
+
|
|
27
|
+
private readonly transferDataValues = [
|
|
28
|
+
borsh.u32('nonce'),
|
|
29
|
+
borsh.u64('amount'),
|
|
30
|
+
borsh.u64('fee'),
|
|
31
|
+
borsh.array(borsh.u8(undefined), 32, 'target_address'),
|
|
32
|
+
borsh.u16('target_chain')
|
|
33
|
+
]
|
|
34
|
+
// https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/api/transfer_payload.rs#L170
|
|
35
|
+
private readonly transferDataWithPayloadValues = [
|
|
36
|
+
borsh.u32('nonce'),
|
|
37
|
+
borsh.u64('amount'),
|
|
38
|
+
borsh.array(borsh.u8(undefined), 32, 'target_address'),
|
|
39
|
+
borsh.u16('target_chain'),
|
|
40
|
+
borsh.vecU8('payload'),
|
|
41
|
+
borsh.option(borsh.publicKey(undefined), 'cpi_program_id')
|
|
42
|
+
]
|
|
43
|
+
private readonly attestTokenValues = [
|
|
44
|
+
borsh.u32('nonce')
|
|
45
|
+
]
|
|
46
|
+
private readonly initializeDataValues = [
|
|
47
|
+
borsh.publicKey('bridge')
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
static bind(options: SolanaBindOptions): TokenBridgeProcessor {
|
|
51
|
+
return new TokenBridgeProcessor(options)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
decodeInstruction: (rawInstruction: string) => Instruction | null = (ins) => {
|
|
55
|
+
const u8Arr = bs58.decode(ins)
|
|
56
|
+
if (u8Arr.length === 0) {
|
|
57
|
+
return null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let data: any
|
|
61
|
+
// wormhole pass intruction's enum value as its first instrcution data
|
|
62
|
+
switch (u8Arr[0]) {
|
|
63
|
+
case TokenBrigeInstruction.Initialize:
|
|
64
|
+
return {
|
|
65
|
+
data: '',
|
|
66
|
+
name: TokenBrigeInstruction[TokenBrigeInstruction.Initialize]
|
|
67
|
+
}
|
|
68
|
+
case TokenBrigeInstruction.TransferNative:
|
|
69
|
+
// struct is defined at: https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/api/transfer.rs#L295
|
|
70
|
+
data = borsh.struct(this.transferDataValues, 'TransferNativeData').decode(Buffer.from(u8Arr.slice(1)))
|
|
71
|
+
return {
|
|
72
|
+
data,
|
|
73
|
+
name: TokenBrigeInstruction[TokenBrigeInstruction.TransferNative]
|
|
74
|
+
}
|
|
75
|
+
case TokenBrigeInstruction.TransferWrapped:
|
|
76
|
+
// stuct is defined at: https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/api/transfer.rs#L295
|
|
77
|
+
data = borsh.struct(this.transferDataValues, 'TransferWrappedData').decode(Buffer.from(u8Arr.slice(1)))
|
|
78
|
+
return {
|
|
79
|
+
data,
|
|
80
|
+
name: TokenBrigeInstruction[TokenBrigeInstruction.TransferWrapped]
|
|
81
|
+
}
|
|
82
|
+
case TokenBrigeInstruction.TransferNativeWithPayload:
|
|
83
|
+
data = borsh.struct(this.transferDataWithPayloadValues, 'TransferNativeWithPayloadData').decode(Buffer.from(u8Arr.slice(1)))
|
|
84
|
+
return {
|
|
85
|
+
data,
|
|
86
|
+
name: TokenBrigeInstruction[TokenBrigeInstruction.TransferNativeWithPayload]
|
|
87
|
+
}
|
|
88
|
+
case TokenBrigeInstruction.TransferWrappedWithPayload:
|
|
89
|
+
data = borsh.struct(this.transferDataWithPayloadValues, 'TransferWrappedWithPayloadData').decode(Buffer.from(u8Arr.slice(1)))
|
|
90
|
+
return {
|
|
91
|
+
data,
|
|
92
|
+
name: TokenBrigeInstruction[TokenBrigeInstruction.TransferWrappedWithPayload]
|
|
93
|
+
}
|
|
94
|
+
case TokenBrigeInstruction.Initialize:
|
|
95
|
+
data = borsh.struct(this.initializeDataValues, 'InitializeData').decode(Buffer.from(u8Arr.slice(1)))
|
|
96
|
+
return {
|
|
97
|
+
data,
|
|
98
|
+
name: TokenBrigeInstruction[TokenBrigeInstruction.Initialize]
|
|
99
|
+
}
|
|
100
|
+
case TokenBrigeInstruction.AttestToken:
|
|
101
|
+
data = borsh.struct(this.attestTokenValues, 'AttestTokenData').decode(Buffer.from(u8Arr.slice(1)))
|
|
102
|
+
return {
|
|
103
|
+
data,
|
|
104
|
+
name: TokenBrigeInstruction[TokenBrigeInstruction.AttestToken]
|
|
105
|
+
}
|
|
106
|
+
case TokenBrigeInstruction.CompleteNative:
|
|
107
|
+
case TokenBrigeInstruction.CompleteNativeWithPayload:
|
|
108
|
+
case TokenBrigeInstruction.CompleteWrapped:
|
|
109
|
+
case TokenBrigeInstruction.CompleteWrappedWithPayload:
|
|
110
|
+
case TokenBrigeInstruction.CreateWrapped:
|
|
111
|
+
case TokenBrigeInstruction.UpgradeContract:
|
|
112
|
+
case TokenBrigeInstruction.RegisterChain:
|
|
113
|
+
return {
|
|
114
|
+
data: '',
|
|
115
|
+
name: TokenBrigeInstruction[u8Arr[0]]
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
default:
|
|
119
|
+
return null
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
onInitialize(handler: (args: any, ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
124
|
+
this.onInstruction('Initialize', (ins: Instruction, ctx) => {
|
|
125
|
+
if (ins) {
|
|
126
|
+
handler(ins.data, ctx)
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
return this
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
onAttestToken(handler: (args: any, ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
133
|
+
this.onInstruction('AttestToken', (ins: Instruction, ctx) => {
|
|
134
|
+
if (ins) {
|
|
135
|
+
handler(ins.data, ctx)
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
return this
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
onTransferWrapped(handler: (args: any, ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
143
|
+
this.onInstruction('TransferWrapped', (ins: Instruction, ctx) => {
|
|
144
|
+
if (ins) {
|
|
145
|
+
handler(ins.data, ctx)
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
return this
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
onTransferNativeWithPayload(handler: (args: any, ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
152
|
+
this.onInstruction('TransferNativeWithPayload', (ins: Instruction, ctx) => {
|
|
153
|
+
if (ins) {
|
|
154
|
+
handler(ins.data, ctx)
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
return this
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
onTransferWrappedWithPaylod(handler: (args: any, ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
161
|
+
this.onInstruction('TransferWrappedWithPaylod', (ins: Instruction, ctx) => {
|
|
162
|
+
if (ins) {
|
|
163
|
+
handler(ins.data, ctx)
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
return this
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
onTransferNative(handler: (args: any, ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
170
|
+
this.onInstruction('TransferNative', (ins: Instruction, ctx) => {
|
|
171
|
+
if (ins) {
|
|
172
|
+
handler(ins.data, ctx)
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
return this
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { O11yResult } from './gen/processor/protos/processor'
|
|
2
|
+
import { SolanaContext } from './context'
|
|
3
|
+
import Long from 'long'
|
|
4
|
+
import { Instruction } from '@project-serum/anchor'
|
|
5
|
+
import { SolanaBindOptions } from './bind-options'
|
|
6
|
+
|
|
7
|
+
type IndexConfigure = {
|
|
8
|
+
startSlot: Long
|
|
9
|
+
endSlot?: Long
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class SolanaBaseProcessor {
|
|
13
|
+
public instructionHanlderMap: Map<string, (instruction: Instruction, ctx: SolanaContext) => void> = new Map()
|
|
14
|
+
address: string
|
|
15
|
+
endpoint: string
|
|
16
|
+
contractName: string
|
|
17
|
+
processInnerInstruction: boolean
|
|
18
|
+
config: IndexConfigure = { startSlot: new Long(0) }
|
|
19
|
+
decodeInstruction: (rawInstruction: string) => Instruction | null
|
|
20
|
+
fromParsedInstruction: (instruction: { type: string; info: any }) => Instruction | null
|
|
21
|
+
|
|
22
|
+
constructor(options: SolanaBindOptions) {
|
|
23
|
+
if (options) {
|
|
24
|
+
this.bind(options)
|
|
25
|
+
}
|
|
26
|
+
global.PROCESSOR_STATE.solanaProcessors.push(this)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
bind(options: SolanaBindOptions) {
|
|
30
|
+
this.address = options.address
|
|
31
|
+
this.contractName = options.name || ''
|
|
32
|
+
this.processInnerInstruction = options.processInnerInstruction || false
|
|
33
|
+
if (options.startBlock) {
|
|
34
|
+
this.startSlot(options.startBlock)
|
|
35
|
+
}
|
|
36
|
+
if (options.endBlock) {
|
|
37
|
+
this.endBlock(options.endBlock)
|
|
38
|
+
}
|
|
39
|
+
this.endpoint = options.network || 'https://api.mainnet-beta.solana.com'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
innerInstruction(flag: boolean) {
|
|
43
|
+
this.processInnerInstruction = flag
|
|
44
|
+
return this
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public onInstruction(instructionName: string, handler: (instruction: Instruction, ctx: SolanaContext) => void) {
|
|
48
|
+
if (!this.isBind()) {
|
|
49
|
+
throw new Error("Processor doesn't bind to an address")
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.instructionHanlderMap.set(instructionName, handler)
|
|
53
|
+
|
|
54
|
+
return this
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public handleInstruction(ins: string | { type: string; info: any }): O11yResult | null {
|
|
58
|
+
const ctx = new SolanaContext(this.address)
|
|
59
|
+
let parsedInstruction: Instruction | null = null
|
|
60
|
+
|
|
61
|
+
if (ins) {
|
|
62
|
+
if ((ins as { type: string; info: any }).info) {
|
|
63
|
+
if (this.fromParsedInstruction == null) {
|
|
64
|
+
return null
|
|
65
|
+
}
|
|
66
|
+
parsedInstruction = this.fromParsedInstruction(ins as { type: string; info: any })
|
|
67
|
+
} else {
|
|
68
|
+
if (this.decodeInstruction == null) {
|
|
69
|
+
return null
|
|
70
|
+
}
|
|
71
|
+
parsedInstruction = this.decodeInstruction(ins as string)
|
|
72
|
+
}
|
|
73
|
+
if (parsedInstruction) {
|
|
74
|
+
const handler = this.instructionHanlderMap.get(parsedInstruction.name)
|
|
75
|
+
if (handler) {
|
|
76
|
+
handler(parsedInstruction, ctx)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
gauges: ctx.gauges,
|
|
82
|
+
counters: ctx.counters,
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public isBind() {
|
|
87
|
+
return this.address !== null
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public startSlot(startSlot: Long | number) {
|
|
91
|
+
if (typeof startSlot === 'number') {
|
|
92
|
+
startSlot = Long.fromNumber(startSlot)
|
|
93
|
+
}
|
|
94
|
+
this.config.startSlot = startSlot
|
|
95
|
+
return this
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public endBlock(endBlock: Long | number) {
|
|
99
|
+
if (typeof endBlock === 'number') {
|
|
100
|
+
endBlock = Long.fromNumber(endBlock)
|
|
101
|
+
}
|
|
102
|
+
this.config.endSlot = endBlock
|
|
103
|
+
return this
|
|
104
|
+
}
|
|
105
|
+
}
|