@sentio/sdk 2.0.0-rc.2 → 2.0.0-rc.20
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 +1914 -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 +491 -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 +21 -0
- package/lib/aptos/codegen/codegen.js +380 -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/{core/generic-processor.test.d.ts → aptos/codegen/typegen.test.d.ts} +0 -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 +27 -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 +162 -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 +345 -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 +812 -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 +340 -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/core/base-context.d.ts +4 -4
- package/lib/core/base-context.js +7 -11
- package/lib/core/base-context.js.map +1 -1
- package/lib/core/big-decimal.d.ts +2 -0
- package/lib/core/big-decimal.js +11 -7
- package/lib/core/big-decimal.js.map +1 -1
- package/lib/{utils → core}/chain.d.ts +0 -0
- package/lib/{utils → core}/chain.js +7 -12
- package/lib/core/chain.js.map +1 -0
- package/lib/core/core-plugin.js +9 -13
- package/lib/core/core-plugin.js.map +1 -1
- package/lib/core/event-tracker.d.ts +2 -2
- package/lib/core/event-tracker.js +6 -13
- package/lib/core/event-tracker.js.map +1 -1
- package/lib/core/exporter.d.ts +2 -2
- package/lib/core/exporter.js +4 -9
- package/lib/core/exporter.js.map +1 -1
- package/lib/core/index.d.ts +10 -9
- package/lib/core/index.js +10 -32
- package/lib/core/index.js.map +1 -1
- package/lib/core/logger.d.ts +2 -2
- package/lib/core/logger.js +7 -11
- package/lib/core/logger.js.map +1 -1
- package/lib/core/metadata.d.ts +4 -0
- package/lib/core/metadata.js +21 -7
- package/lib/core/metadata.js.map +1 -1
- package/lib/core/meter.d.ts +3 -7
- package/lib/core/meter.js +22 -57
- package/lib/core/meter.js.map +1 -1
- package/lib/core/meter.test.js.map +1 -1
- package/lib/core/numberish.d.ts +1 -3
- package/lib/core/numberish.js +11 -26
- package/lib/core/numberish.js.map +1 -1
- package/lib/core/numberish.test.js.map +1 -1
- package/lib/core/sui-plugin.js +12 -16
- package/lib/core/sui-plugin.js.map +1 -1
- package/lib/core/sui-processor.d.ts +1 -1
- package/lib/core/sui-processor.js +6 -12
- package/lib/core/sui-processor.js.map +1 -1
- package/lib/eth/account-processor-state.d.ts +1 -1
- package/lib/eth/account-processor-state.js +2 -6
- package/lib/eth/account-processor-state.js.map +1 -1
- package/lib/eth/account-processor.d.ts +7 -7
- package/lib/eth/account-processor.js +23 -27
- package/lib/eth/account-processor.js.map +1 -1
- package/lib/eth/base-processor-template.d.ts +9 -8
- package/lib/eth/base-processor-template.js +8 -14
- package/lib/eth/base-processor-template.js.map +1 -1
- package/lib/eth/base-processor.d.ts +8 -7
- package/lib/eth/base-processor.js +21 -27
- package/lib/eth/base-processor.js.map +1 -1
- package/lib/{core → eth}/bind-options.d.ts +0 -0
- package/lib/eth/bind-options.js +40 -0
- package/lib/eth/bind-options.js.map +1 -0
- package/lib/eth/binds.d.ts +3 -3
- package/lib/eth/binds.js +11 -19
- package/lib/eth/binds.js.map +1 -1
- package/lib/eth/builtin/eacaggregatorproxy/index.d.ts +3 -0
- package/lib/eth/builtin/eacaggregatorproxy/index.js +7 -0
- package/lib/eth/builtin/eacaggregatorproxy/index.js.map +1 -0
- package/lib/{builtin → eth/builtin}/eacaggregatorproxy/test-utils.d.ts +1 -1
- package/lib/{builtin → eth/builtin}/eacaggregatorproxy/test-utils.js +9 -16
- package/lib/eth/builtin/eacaggregatorproxy/test-utils.js.map +1 -0
- package/lib/eth/builtin/erc1155/index.d.ts +3 -0
- package/lib/eth/builtin/erc1155/index.js +7 -0
- package/lib/eth/builtin/erc1155/index.js.map +1 -0
- package/lib/{builtin → eth/builtin}/erc1155/test-utils.d.ts +1 -1
- package/lib/{builtin → eth/builtin}/erc1155/test-utils.js +9 -16
- package/lib/eth/builtin/erc1155/test-utils.js.map +1 -0
- package/lib/eth/builtin/erc20/index.d.ts +3 -0
- package/lib/eth/builtin/erc20/index.js +7 -0
- package/lib/eth/builtin/erc20/index.js.map +1 -0
- package/lib/{builtin → eth/builtin}/erc20/test-utils.d.ts +1 -1
- package/lib/{builtin → eth/builtin}/erc20/test-utils.js +7 -13
- package/lib/eth/builtin/erc20/test-utils.js.map +1 -0
- package/lib/eth/builtin/erc20bytes/index.d.ts +3 -0
- package/lib/eth/builtin/erc20bytes/index.js +7 -0
- package/lib/eth/builtin/erc20bytes/index.js.map +1 -0
- package/lib/{builtin → eth/builtin}/erc20bytes/test-utils.d.ts +1 -1
- package/lib/{builtin → eth/builtin}/erc20bytes/test-utils.js +5 -10
- package/lib/eth/builtin/erc20bytes/test-utils.js.map +1 -0
- package/lib/eth/builtin/erc721/index.d.ts +3 -0
- package/lib/eth/builtin/erc721/index.js +7 -0
- package/lib/eth/builtin/erc721/index.js.map +1 -0
- package/lib/{builtin → eth/builtin}/erc721/test-utils.d.ts +1 -1
- package/lib/{builtin → eth/builtin}/erc721/test-utils.js +7 -13
- package/lib/eth/builtin/erc721/test-utils.js.map +1 -0
- package/lib/eth/builtin/index.d.ts +8 -0
- package/lib/eth/builtin/index.js +9 -0
- package/lib/eth/builtin/index.js.map +1 -0
- package/lib/{builtin → eth/builtin}/internal/EACAggregatorProxy.d.ts +6 -6
- package/lib/eth/builtin/internal/EACAggregatorProxy.js +2 -0
- package/lib/eth/builtin/internal/EACAggregatorProxy.js.map +1 -0
- package/lib/{builtin → eth/builtin}/internal/ERC1155.d.ts +6 -6
- package/lib/eth/builtin/internal/ERC1155.js +2 -0
- package/lib/eth/builtin/internal/ERC1155.js.map +1 -0
- package/lib/{builtin → eth/builtin}/internal/ERC20.d.ts +5 -5
- package/lib/eth/builtin/internal/ERC20.js +2 -0
- package/lib/eth/builtin/internal/ERC20.js.map +1 -0
- package/lib/{builtin → eth/builtin}/internal/ERC20Bytes.d.ts +4 -4
- package/lib/eth/builtin/internal/ERC20Bytes.js +2 -0
- package/lib/eth/builtin/internal/ERC20Bytes.js.map +1 -0
- package/lib/{builtin → eth/builtin}/internal/ERC721.d.ts +5 -5
- package/lib/eth/builtin/internal/ERC721.js +2 -0
- package/lib/eth/builtin/internal/ERC721.js.map +1 -0
- package/lib/{builtin → eth/builtin}/internal/WETH9.d.ts +6 -6
- package/lib/eth/builtin/internal/WETH9.js +2 -0
- package/lib/eth/builtin/internal/WETH9.js.map +1 -0
- package/lib/{builtin → eth/builtin}/internal/common.d.ts +4 -2
- package/lib/{builtin → eth/builtin}/internal/common.js +1 -2
- package/lib/eth/builtin/internal/common.js.map +1 -0
- package/lib/{builtin → eth/builtin}/internal/eacaggregatorproxy_processor.d.ts +3 -3
- package/lib/{builtin → eth/builtin}/internal/eacaggregatorproxy_processor.js +123 -221
- package/lib/eth/builtin/internal/eacaggregatorproxy_processor.js.map +1 -0
- package/lib/{builtin → eth/builtin}/internal/erc1155_processor.d.ts +3 -3
- package/lib/{builtin → eth/builtin}/internal/erc1155_processor.js +45 -78
- package/lib/eth/builtin/internal/erc1155_processor.js.map +1 -0
- package/lib/{builtin → eth/builtin}/internal/erc20_processor.d.ts +3 -3
- package/lib/{builtin → eth/builtin}/internal/erc20_processor.js +63 -111
- package/lib/eth/builtin/internal/erc20_processor.js.map +1 -0
- package/lib/{builtin → eth/builtin}/internal/erc20bytes_processor.d.ts +3 -3
- package/lib/{builtin → eth/builtin}/internal/erc20bytes_processor.js +51 -89
- package/lib/eth/builtin/internal/erc20bytes_processor.js.map +1 -0
- package/lib/{builtin → eth/builtin}/internal/erc721_processor.d.ts +3 -3
- package/lib/{builtin → eth/builtin}/internal/erc721_processor.js +69 -122
- package/lib/eth/builtin/internal/erc721_processor.js.map +1 -0
- package/lib/{builtin → eth/builtin}/internal/factories/EACAggregatorProxy__factory.d.ts +1 -1
- package/lib/{builtin → eth/builtin}/internal/factories/EACAggregatorProxy__factory.js +4 -8
- package/lib/eth/builtin/internal/factories/EACAggregatorProxy__factory.js.map +1 -0
- package/lib/{builtin → eth/builtin}/internal/factories/ERC1155__factory.d.ts +1 -1
- package/lib/{builtin → eth/builtin}/internal/factories/ERC1155__factory.js +4 -8
- package/lib/eth/builtin/internal/factories/ERC1155__factory.js.map +1 -0
- package/lib/{builtin → eth/builtin}/internal/factories/ERC20Bytes__factory.d.ts +1 -1
- package/lib/{builtin → eth/builtin}/internal/factories/ERC20Bytes__factory.js +4 -8
- package/lib/eth/builtin/internal/factories/ERC20Bytes__factory.js.map +1 -0
- package/lib/{builtin → eth/builtin}/internal/factories/ERC20__factory.d.ts +1 -1
- package/lib/{builtin → eth/builtin}/internal/factories/ERC20__factory.js +4 -8
- package/lib/eth/builtin/internal/factories/ERC20__factory.js.map +1 -0
- package/lib/{builtin → eth/builtin}/internal/factories/ERC721__factory.d.ts +1 -1
- package/lib/{builtin → eth/builtin}/internal/factories/ERC721__factory.js +4 -8
- package/lib/eth/builtin/internal/factories/ERC721__factory.js.map +1 -0
- package/lib/{builtin → eth/builtin}/internal/factories/WETH9__factory.d.ts +1 -1
- package/lib/{builtin → eth/builtin}/internal/factories/WETH9__factory.js +4 -8
- package/lib/eth/builtin/internal/factories/WETH9__factory.js.map +1 -0
- package/lib/eth/builtin/internal/factories/index.d.ts +6 -0
- package/lib/eth/builtin/internal/factories/index.js +10 -0
- package/lib/eth/builtin/internal/factories/index.js.map +1 -0
- package/lib/eth/builtin/internal/index.d.ts +13 -0
- package/lib/eth/builtin/internal/index.js +8 -0
- package/lib/eth/builtin/internal/index.js.map +1 -0
- package/lib/{builtin → eth/builtin}/internal/weth9_processor.d.ts +3 -3
- package/lib/{builtin → eth/builtin}/internal/weth9_processor.js +51 -89
- package/lib/eth/builtin/internal/weth9_processor.js.map +1 -0
- package/lib/eth/builtin/weth9/index.d.ts +3 -0
- package/lib/eth/builtin/weth9/index.js +7 -0
- package/lib/eth/builtin/weth9/index.js.map +1 -0
- package/lib/{builtin → eth/builtin}/weth9/test-utils.d.ts +1 -1
- package/lib/{builtin → eth/builtin}/weth9/test-utils.js +9 -16
- package/lib/eth/builtin/weth9/test-utils.js.map +1 -0
- package/lib/eth/codegen/codegen.d.ts +1 -0
- package/lib/eth/codegen/codegen.js +53 -0
- package/lib/eth/codegen/codegen.js.map +1 -0
- package/lib/{target-ethers-sentio/index.d.ts → eth/codegen/ethers-sentio.d.ts} +1 -1
- package/lib/eth/codegen/ethers-sentio.js +57 -0
- package/lib/eth/codegen/ethers-sentio.js.map +1 -0
- package/lib/{target-ethers-sentio → eth/codegen}/event-handler.d.ts +0 -0
- package/lib/eth/codegen/event-handler.js +46 -0
- package/lib/eth/codegen/event-handler.js.map +1 -0
- package/lib/{target-ethers-sentio → eth/codegen}/file.d.ts +0 -0
- package/lib/{target-ethers-sentio → eth/codegen}/file.js +33 -39
- package/lib/eth/codegen/file.js.map +1 -0
- package/lib/{target-ethers-sentio → eth/codegen}/functions-handler.d.ts +0 -0
- package/lib/{target-ethers-sentio → eth/codegen}/functions-handler.js +12 -18
- package/lib/eth/codegen/functions-handler.js.map +1 -0
- package/lib/eth/codegen/index.d.ts +1 -0
- package/lib/eth/codegen/index.js +2 -0
- package/lib/eth/codegen/index.js.map +1 -0
- package/lib/{target-ethers-sentio → eth/codegen}/types.d.ts +0 -0
- package/lib/{target-ethers-sentio → eth/codegen}/types.js +3 -9
- package/lib/eth/codegen/types.js.map +1 -0
- package/lib/{target-ethers-sentio → eth/codegen}/view-function.d.ts +0 -0
- package/lib/eth/codegen/view-function.js +62 -0
- package/lib/eth/codegen/view-function.js.map +1 -0
- package/lib/{core → eth}/context.d.ts +5 -5
- package/lib/{core → eth}/context.js +14 -23
- package/lib/eth/context.js.map +1 -0
- package/lib/eth/error.d.ts +1 -0
- package/lib/eth/error.js +3 -0
- package/lib/eth/error.js.map +1 -0
- package/lib/eth/eth-plugin.js +30 -34
- package/lib/eth/eth-plugin.js.map +1 -1
- package/lib/eth/eth.d.ts +13 -0
- package/lib/eth/eth.js +44 -0
- package/lib/eth/eth.js.map +1 -0
- package/lib/eth/generic-processor.d.ts +3 -3
- package/lib/eth/generic-processor.js +9 -13
- package/lib/eth/generic-processor.js.map +1 -1
- package/lib/eth/generic-processor.test.d.ts +1 -0
- package/lib/eth/generic-processor.test.js.map +1 -0
- package/lib/eth/index.d.ts +11 -6
- package/lib/eth/index.js +10 -14
- package/lib/eth/index.js.map +1 -1
- package/lib/eth/provider.js +13 -17
- package/lib/eth/provider.js.map +1 -1
- package/lib/eth/run-codegen.d.ts +2 -0
- package/lib/eth/run-codegen.js +12 -0
- package/lib/eth/run-codegen.js.map +1 -0
- package/lib/eth/trace.js +1 -2
- package/lib/eth/trace.js.map +1 -1
- package/lib/index.d.ts +2 -5
- package/lib/index.js +3 -18
- package/lib/index.js.map +1 -1
- package/lib/jest.config.d.ts +9 -0
- package/lib/jest.config.js +9 -0
- package/lib/jest.config.js.map +1 -0
- package/lib/promise-or-void.js +1 -2
- 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/index.d.ts +3 -2
- package/lib/testing/index.js +3 -10
- package/lib/testing/index.js.map +1 -1
- package/lib/testing/metric-utils.d.ts +1 -1
- package/lib/testing/metric-utils.js +7 -13
- package/lib/testing/metric-utils.js.map +1 -1
- package/lib/testing/test-processor-server.d.ts +3 -4
- package/lib/testing/test-processor-server.js +24 -29
- package/lib/testing/test-processor-server.js.map +1 -1
- package/lib/testing/test-provider.js +5 -9
- package/lib/testing/test-provider.js.map +1 -1
- package/lib/tsup.config.ts +31 -0
- package/lib/utils/conversion.d.ts +0 -5
- package/lib/utils/conversion.js +22 -27
- package/lib/utils/conversion.js.map +1 -1
- package/lib/utils/dex-price.js +14 -19
- package/lib/utils/dex-price.js.map +1 -1
- package/lib/utils/dex-price.test.js.map +1 -1
- package/lib/utils/erc20.test.js.map +1 -1
- package/lib/utils/index.d.ts +3 -4
- package/lib/utils/index.js +3 -8
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/price.d.ts +11 -11
- package/lib/utils/price.js +10 -16
- package/lib/utils/price.js.map +1 -1
- package/lib/utils/token.d.ts +1 -2
- package/lib/utils/token.js +23 -40
- package/lib/utils/token.js.map +1 -1
- package/package.json +51 -23
- 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 +4685 -0
- package/src/aptos/builtin/0x3.ts +1010 -0
- package/src/{builtin/weth9 → aptos/builtin}/index.ts +2 -3
- package/src/aptos/codegen/codegen.ts +457 -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 +35 -0
- package/src/aptos/move-coder.ts +199 -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 +781 -0
- package/src/aptos/tests/types/soffl3.ts +1567 -0
- package/src/aptos/tests/types/souffle.ts +780 -0
- package/src/aptos/types.ts +149 -0
- package/src/aptos/utils.ts +26 -0
- package/src/core/base-context.ts +4 -4
- package/src/core/big-decimal.ts +11 -0
- package/src/{utils → core}/chain.ts +0 -0
- package/src/core/core-plugin.ts +3 -3
- package/src/core/event-tracker.ts +2 -2
- package/src/core/exporter.ts +3 -3
- package/src/core/index.ts +10 -10
- package/src/core/logger.ts +2 -2
- package/src/core/metadata.ts +23 -2
- package/src/core/meter.ts +3 -26
- package/src/core/numberish.ts +1 -12
- package/src/core/sui-plugin.ts +2 -2
- package/src/core/sui-processor.ts +1 -1
- package/src/{abis → eth/abis}/EACAggregatorProxy.json +0 -0
- package/src/{abis → eth/abis}/ERC1155.json +0 -0
- package/src/{abis → eth/abis}/ERC20.json +0 -0
- package/src/{abis → eth/abis}/ERC20Bytes.json +0 -0
- package/src/{abis → eth/abis}/ERC721.json +0 -0
- package/src/{abis → eth/abis}/WETH9.json +0 -0
- package/src/eth/account-processor-state.ts +1 -1
- package/src/eth/account-processor.ts +11 -11
- package/src/eth/base-processor-template.ts +8 -7
- package/src/eth/base-processor.ts +12 -22
- package/src/{core → eth}/bind-options.ts +0 -0
- package/src/eth/binds.ts +3 -3
- package/src/eth/builtin/eacaggregatorproxy/index.ts +7 -0
- package/src/{builtin → eth/builtin}/eacaggregatorproxy/test-utils.ts +1 -1
- package/src/eth/builtin/erc1155/index.ts +7 -0
- package/src/{builtin → eth/builtin}/erc1155/test-utils.ts +1 -1
- package/src/eth/builtin/erc20/index.ts +7 -0
- package/src/{builtin → eth/builtin}/erc20/test-utils.ts +1 -1
- package/src/eth/builtin/erc20bytes/index.ts +7 -0
- package/src/{builtin → eth/builtin}/erc20bytes/test-utils.ts +1 -1
- package/src/eth/builtin/erc721/index.ts +7 -0
- package/src/{builtin → eth/builtin}/erc721/test-utils.ts +1 -1
- package/src/eth/builtin/index.ts +8 -0
- package/src/{builtin → eth/builtin}/internal/EACAggregatorProxy.ts +6 -10
- package/src/{builtin → eth/builtin}/internal/ERC1155.ts +6 -10
- package/src/{builtin → eth/builtin}/internal/ERC20.ts +5 -8
- package/src/{builtin → eth/builtin}/internal/ERC20Bytes.ts +4 -6
- package/src/{builtin → eth/builtin}/internal/ERC721.ts +5 -8
- package/src/{builtin → eth/builtin}/internal/WETH9.ts +6 -10
- package/src/eth/builtin/internal/common.ts +22 -0
- package/src/{builtin → eth/builtin}/internal/eacaggregatorproxy_processor.ts +93 -165
- package/src/{builtin → eth/builtin}/internal/erc1155_processor.ts +28 -52
- package/src/{builtin → eth/builtin}/internal/erc20_processor.ts +43 -75
- package/src/{builtin → eth/builtin}/internal/erc20bytes_processor.ts +33 -57
- package/src/{builtin → eth/builtin}/internal/erc721_processor.ts +48 -84
- package/src/{builtin → eth/builtin}/internal/factories/EACAggregatorProxy__factory.ts +1 -1
- package/src/{builtin → eth/builtin}/internal/factories/ERC1155__factory.ts +1 -1
- package/src/{builtin → eth/builtin}/internal/factories/ERC20Bytes__factory.ts +1 -1
- package/src/{builtin → eth/builtin}/internal/factories/ERC20__factory.ts +1 -1
- package/src/{builtin → eth/builtin}/internal/factories/ERC721__factory.ts +1 -1
- package/src/{builtin → eth/builtin}/internal/factories/WETH9__factory.ts +1 -1
- package/src/eth/builtin/internal/factories/index.ts +9 -0
- package/src/eth/builtin/internal/index.ts +16 -0
- package/src/{builtin → eth/builtin}/internal/weth9_processor.ts +33 -57
- package/src/eth/builtin/weth9/index.ts +7 -0
- package/src/{builtin → eth/builtin}/weth9/test-utils.ts +1 -1
- package/src/eth/codegen/codegen.ts +62 -0
- package/src/{target-ethers-sentio/index.ts → eth/codegen/ethers-sentio.ts} +5 -2
- package/src/{target-ethers-sentio → eth/codegen}/event-handler.ts +2 -2
- package/src/{target-ethers-sentio → eth/codegen}/file.ts +13 -12
- package/src/{target-ethers-sentio → eth/codegen}/functions-handler.ts +4 -5
- package/src/eth/codegen/index.ts +1 -0
- package/src/eth/codegen/tsconfig.json +8 -0
- package/src/{target-ethers-sentio → eth/codegen}/types.ts +1 -1
- package/src/{target-ethers-sentio → eth/codegen}/view-function.ts +7 -12
- package/src/{core → eth}/context.ts +5 -6
- package/src/eth/error.ts +4 -0
- package/src/eth/eth-plugin.ts +3 -3
- package/src/eth/eth.ts +56 -0
- package/src/eth/generic-processor.ts +5 -5
- package/src/eth/index.ts +12 -6
- package/src/eth/provider.ts +4 -3
- package/src/eth/run-codegen.ts +12 -0
- package/src/index.ts +2 -9
- package/src/jest.config.ts +8 -0
- 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/index.ts +3 -3
- package/src/testing/metric-utils.ts +2 -2
- package/src/testing/test-processor-server.ts +5 -5
- package/src/testing/test-provider.ts +1 -1
- package/src/tsup.config.ts +31 -0
- package/src/utils/conversion.ts +21 -25
- package/src/utils/dex-price.ts +4 -5
- package/src/utils/index.ts +3 -4
- package/src/utils/price.ts +1 -1
- package/src/utils/token.ts +20 -31
- package/lib/builtin/eacaggregatorproxy/index.d.ts +0 -2
- package/lib/builtin/eacaggregatorproxy/index.js +0 -9
- package/lib/builtin/eacaggregatorproxy/index.js.map +0 -1
- package/lib/builtin/eacaggregatorproxy/test-utils.js.map +0 -1
- package/lib/builtin/erc1155/index.d.ts +0 -2
- package/lib/builtin/erc1155/index.js +0 -9
- package/lib/builtin/erc1155/index.js.map +0 -1
- package/lib/builtin/erc1155/test-utils.js.map +0 -1
- package/lib/builtin/erc20/index.d.ts +0 -2
- package/lib/builtin/erc20/index.js +0 -9
- package/lib/builtin/erc20/index.js.map +0 -1
- package/lib/builtin/erc20/test-utils.js.map +0 -1
- package/lib/builtin/erc20bytes/index.d.ts +0 -2
- package/lib/builtin/erc20bytes/index.js +0 -9
- package/lib/builtin/erc20bytes/index.js.map +0 -1
- package/lib/builtin/erc20bytes/test-utils.js.map +0 -1
- package/lib/builtin/erc721/index.d.ts +0 -2
- package/lib/builtin/erc721/index.js +0 -9
- package/lib/builtin/erc721/index.js.map +0 -1
- package/lib/builtin/erc721/test-utils.js.map +0 -1
- package/lib/builtin/index.d.ts +0 -4
- package/lib/builtin/index.js +0 -9
- package/lib/builtin/index.js.map +0 -1
- package/lib/builtin/internal/EACAggregatorProxy.js +0 -3
- package/lib/builtin/internal/EACAggregatorProxy.js.map +0 -1
- package/lib/builtin/internal/ERC1155.js +0 -3
- package/lib/builtin/internal/ERC1155.js.map +0 -1
- package/lib/builtin/internal/ERC20.js +0 -3
- package/lib/builtin/internal/ERC20.js.map +0 -1
- package/lib/builtin/internal/ERC20Bytes.js +0 -3
- package/lib/builtin/internal/ERC20Bytes.js.map +0 -1
- package/lib/builtin/internal/ERC721.js +0 -3
- package/lib/builtin/internal/ERC721.js.map +0 -1
- package/lib/builtin/internal/WETH9.js +0 -3
- package/lib/builtin/internal/WETH9.js.map +0 -1
- package/lib/builtin/internal/common.js.map +0 -1
- package/lib/builtin/internal/eacaggregatorproxy_processor.js.map +0 -1
- package/lib/builtin/internal/erc1155_processor.js.map +0 -1
- package/lib/builtin/internal/erc20_processor.js.map +0 -1
- package/lib/builtin/internal/erc20bytes_processor.js.map +0 -1
- package/lib/builtin/internal/erc721_processor.js.map +0 -1
- package/lib/builtin/internal/factories/EACAggregatorProxy__factory.js.map +0 -1
- package/lib/builtin/internal/factories/ERC1155__factory.js.map +0 -1
- package/lib/builtin/internal/factories/ERC20Bytes__factory.js.map +0 -1
- package/lib/builtin/internal/factories/ERC20__factory.js.map +0 -1
- package/lib/builtin/internal/factories/ERC721__factory.js.map +0 -1
- package/lib/builtin/internal/factories/WETH9__factory.js.map +0 -1
- package/lib/builtin/internal/factories/index.d.ts +0 -6
- package/lib/builtin/internal/factories/index.js +0 -19
- package/lib/builtin/internal/factories/index.js.map +0 -1
- package/lib/builtin/internal/index.d.ts +0 -13
- package/lib/builtin/internal/index.js +0 -18
- package/lib/builtin/internal/index.js.map +0 -1
- package/lib/builtin/internal/weth9_processor.js.map +0 -1
- package/lib/builtin/weth9/index.d.ts +0 -2
- package/lib/builtin/weth9/index.js +0 -9
- package/lib/builtin/weth9/index.js.map +0 -1
- package/lib/builtin/weth9/test-utils.js.map +0 -1
- package/lib/core/bind-options.js +0 -47
- package/lib/core/bind-options.js.map +0 -1
- package/lib/core/context.js.map +0 -1
- package/lib/core/generic-processor.test.js.map +0 -1
- package/lib/error.d.ts +0 -7
- package/lib/error.js +0 -43
- package/lib/error.js.map +0 -1
- package/lib/target-ethers-sentio/event-handler.js +0 -52
- package/lib/target-ethers-sentio/event-handler.js.map +0 -1
- package/lib/target-ethers-sentio/file.js.map +0 -1
- package/lib/target-ethers-sentio/functions-handler.js.map +0 -1
- package/lib/target-ethers-sentio/index.js +0 -58
- package/lib/target-ethers-sentio/index.js.map +0 -1
- package/lib/target-ethers-sentio/types.js.map +0 -1
- package/lib/target-ethers-sentio/view-function.js +0 -74
- package/lib/target-ethers-sentio/view-function.js.map +0 -1
- package/lib/utils/chain.js.map +0 -1
- package/lib/webpack.config.js +0 -50
- package/src/builtin/eacaggregatorproxy/index.ts +0 -6
- package/src/builtin/erc1155/index.ts +0 -6
- package/src/builtin/erc20/index.ts +0 -6
- package/src/builtin/erc20bytes/index.ts +0 -6
- package/src/builtin/erc721/index.ts +0 -6
- package/src/builtin/index.ts +0 -4
- package/src/builtin/internal/common.ts +0 -46
- package/src/builtin/internal/factories/index.ts +0 -9
- package/src/builtin/internal/index.ts +0 -16
- package/src/error.ts +0 -45
- package/src/target-ethers-sentio/.eslintrc.json +0 -14
- package/src/target-ethers-sentio/tsconfig.json +0 -9
- package/src/webpack.config.js +0 -50
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../../src/aptos/codegen/codegen.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,OAAO,EAAE,wBAAwB,EAAE,eAAe,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AACzG,OAAO,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,WAAW,EAAE,QAAQ,EAAE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C,MAAM,EAAE;YACjC,MAAM,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YACnC,IAAI,CAAC,CAAC,KAAK,KAAK,yBAAyB,EAAE;gBACzC,MAAM,KAAK,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;gBACjC,MAAM,WAAW,GAAG,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;gBACxC,IAAI,WAAW,EAAE;oBACf,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,CAAA;iBACjC;aACF;SACF;KACF;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,SAAS,gBAAgB,CAAC,MAAkB,EAAE,MAAkB;IAC9D,mCAAmC;IACnC,kCAAkC;IAClC,cAAc;IACd,IAAI;IAEJ,6DAA6D;IAE7D,MAAM,UAAU,GAAG,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACjD,MAAM,MAAM,GAAG;WACN,MAAM,CAAC,IAAI,kBAAkB,UAAU,IAAI,iBAAiB,CACnE,MAAM,CAAC,IAAI,CACZ,0EAA0E,UAAU;;eAExE,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI;;;;;GAKvC,CAAA;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAa;IACxC,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,KAAK,CAAA;KACb;IACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;AAC9E,CAAC","sourcesContent":["import * as fs from 'fs'\nimport * as path from 'path'\nimport { format } from 'prettier'\nimport { MoveFunction, MoveModule, MoveModuleBytecode, MoveStruct } from '../move-types.js'\nimport { AccountModulesImportInfo, AccountRegister, generateType, normalizeToJSName } from './typegen.js'\nimport { getMeaningfulFunctionParams, isFrameworkAccount, moduleQname, SPLITTER } from '../utils.js'\nimport chalk from 'chalk'\nimport { AptosNetwork, getAptosChainName } from '../network.js'\nimport { parseMoveType } from '../types.js'\nimport { AptosClient } from 'aptos-sdk'\nimport { camelCase } from 'lodash-es'\n\nexport async function codegen(abisDir: string, outDir = 'src/types/aptos') {\n if (!fs.existsSync(abisDir)) {\n return\n }\n console.log(chalk.green('Generated Types for Aptos'))\n await generate(abisDir, outDir)\n}\n\nfunction getRpcEndpoint(network: AptosNetwork): string {\n switch (network) {\n case AptosNetwork.TEST_NET:\n return 'https://testnet.aptoslabs.com/'\n }\n return 'https://mainnet.aptoslabs.com/'\n}\n\nfunction getRpcClient(network: AptosNetwork): AptosClient {\n return new AptosClient(getRpcEndpoint(network))\n}\n\nasync function generate(srcDir: string, outputDir: string) {\n await generateForNetwork(srcDir, outputDir, AptosNetwork.MAIN_NET)\n await generateForNetwork(path.join(srcDir, 'testnet'), path.join(outputDir, 'testnet'), AptosNetwork.TEST_NET)\n}\n\nasync function generateForNetwork(srcDir: string, outputDir: string, network: AptosNetwork) {\n if (!fs.existsSync(srcDir)) {\n return\n }\n if (network === AptosNetwork.TEST_NET) {\n console.log('Found testnet directory, generate code for testnet modules')\n }\n const files = fs.readdirSync(srcDir)\n outputDir = path.resolve(outputDir)\n const outputs: OutputFile[] = []\n\n fs.mkdirSync(outputDir, { recursive: true })\n\n const loader = new AccountRegister()\n\n // when generating user code, don't need to generate framework account\n loader.accountImports.set('0x1', new AccountModulesImportInfo('0x1', '0x1'))\n loader.accountImports.set('0x2', new AccountModulesImportInfo('0x2', '0x2'))\n loader.accountImports.set('0x3', new AccountModulesImportInfo('0x3', '0x3'))\n const client = getRpcClient(network)\n\n for (const file of files) {\n if (!file.endsWith('.json')) {\n continue\n }\n const fullPath = path.resolve(srcDir, file)\n const modules = JSON.parse(fs.readFileSync(fullPath, 'utf-8'))\n\n for (const module of modules) {\n if (module.abi) {\n loader.register(module.abi, path.basename(file, '.json'))\n }\n }\n const codeGen = new AccountCodegen(loader, modules, {\n fileName: path.basename(file, '.json'),\n outputDir: outputDir,\n network,\n })\n\n outputs.push(...codeGen.generate())\n }\n\n while (loader.pendingAccounts.size > 0) {\n for (const account of loader.pendingAccounts) {\n console.log(`download dependent module for account ${account} at ${getAptosChainName(network)}`)\n\n try {\n const modules = await client.getAccountModules(account)\n fs.writeFileSync(path.resolve(srcDir, account + '.json'), JSON.stringify(modules, null, '\\t'))\n\n for (const module of modules) {\n if (module.abi) {\n loader.register(module.abi, account)\n }\n }\n const codeGen = new AccountCodegen(loader, modules, {\n fileName: account,\n outputDir: outputDir,\n network,\n })\n\n outputs.push(...codeGen.generate())\n } catch (e) {\n console.error(\n chalk.red(\n 'Error downloading account module, check if you choose the right network,or download account modules manually into your director'\n )\n )\n console.error(e)\n process.exit(1)\n }\n }\n }\n\n for (const output of outputs) {\n const content = format(output.fileContent, { parser: 'typescript' })\n fs.writeFileSync(path.join(outputDir, output.fileName), content)\n }\n\n const rootFile = path.join(outputDir, 'index.ts')\n fs.writeFileSync(\n rootFile,\n `/* Autogenerated file. Do not edit manually. */\n/* tslint:disable */\n/* eslint-disable */\n`\n )\n for (const output of outputs) {\n const parsed = path.parse(output.fileName)\n const content = `export * as _${parsed.name} from './${parsed.name}.js'\\n`\n fs.appendFileSync(rootFile, content)\n }\n}\n\ninterface OutputFile {\n fileName: string\n fileContent: string\n}\n\ninterface Config {\n fileName: string\n outputDir: string\n network: AptosNetwork\n}\n\nexport class AccountCodegen {\n modules: MoveModuleBytecode[]\n config: Config\n loader: AccountRegister\n\n constructor(loader: AccountRegister, modules: MoveModuleBytecode[], config: Config) {\n // const json = fs.readFileSync(config.srcFile, 'utf-8')\n this.modules = modules\n this.config = config\n this.loader = loader\n }\n\n generate(): OutputFile[] {\n if (!this.modules) {\n return []\n }\n // const baseName = path.basename(this.config.fileName, '.json')\n\n let address: string | undefined\n for (const module of this.modules) {\n if (module.abi && module.abi.address) {\n address = module.abi.address\n }\n }\n if (!address) {\n return []\n }\n\n const imports = `\n import { \n MoveCoder, AptosBindOptions, AptosBaseProcessor, \n TypedEventInstance, AptosNetwork, TypedEntryFunctionPayload,\n AptosContext, CallFilter\n } from \"@sentio/sdk/aptos\"\n import { AptosFetchConfig } from \"@sentio/protos\"\n import { Address, MoveModule } from \"@sentio/sdk/aptos\"\n `\n\n const dependedAccounts: string[] = []\n\n const moduleImports: string[] = []\n\n const info = this.loader.accountImports.get(address)\n\n if (info) {\n for (const [account] of info.imports.entries()) {\n // Remap to user's filename if possible, TODO codepath not well tested\n const tsAccountModule = './' + (this.loader.accountImports.get(account)?.moduleName || account)\n if (isFrameworkAccount(account) && !isFrameworkAccount(address)) {\n // Decide where to find runtime library\n moduleImports.push(`import { _${account} } from \"@sentio/sdk/aptos/builtin\"`)\n } else {\n moduleImports.push(`import * as _${account} from \"${tsAccountModule}.js\"`)\n }\n\n dependedAccounts.push(account)\n }\n }\n\n const source = `\n /* Autogenerated file. Do not edit manually. */\n /* tslint:disable */\n /* eslint-disable */\n \n /* Generated modules for account ${address} */\n \n ${imports}\n \n ${moduleImports.join('\\n')}\n \n ${this.modules.map((m) => generateModule(m, this.config.network)).join('\\n')}\n \n export function loadAllTypes(_r: MoveCoder) {\n ${dependedAccounts.map((a) => `_${a}.loadAllTypes(_r)`).join('\\n')}\n\n ${this.modules\n .map((m) => {\n return `_r.load(${normalizeToJSName(m.abi!.name)}.ABI)`\n })\n .join('\\n')}\n }\n ` // source\n\n return [\n {\n fileName: this.config.fileName + '.ts',\n fileContent: source,\n },\n ]\n }\n}\n\nfunction generateNetworkOption(network: AptosNetwork) {\n switch (network) {\n case AptosNetwork.TEST_NET:\n return 'TEST_NET'\n }\n return 'MAIN_NET'\n}\n\nfunction generateModule(moduleByteCode: MoveModuleBytecode, network: AptosNetwork) {\n if (!moduleByteCode.abi) {\n return ''\n }\n const module = moduleByteCode.abi\n\n const functions = module.exposed_functions.map((f) => generateOnEntryFunctions(module, f)).filter((s) => s !== '')\n\n const eventStructs = getEventStructs(module)\n const eventTypes = new Set(eventStructs.keys())\n const events = Array.from(eventStructs.values())\n .map((e) => generateOnEvents(module, e))\n .filter((s) => s !== '')\n const structs = module.structs.map((s) => generateStructs(module, s, eventTypes))\n const callArgs = module.exposed_functions.map((f) => generateCallArgsStructs(module, f))\n\n const moduleName = normalizeToJSName(module.name)\n let processor = ''\n if (functions.length > 0 || events.length > 0) {\n processor = `export class ${moduleName} extends AptosBaseProcessor {\n\n constructor(options: AptosBindOptions) {\n super(\"${module.name}\", options)\n }\n static DEFAULT_OPTIONS: AptosBindOptions = {\n address: \"${module.address}\",\n network: AptosNetwork.${generateNetworkOption(network)} \n }\n\n static bind(options: Partial<AptosBindOptions> = {}): ${moduleName} {\n return new ${moduleName}({ ...${moduleName}.DEFAULT_OPTIONS, ...options })\n }\n \n ${functions.join('\\n')}\n \n ${events.join('\\n')}\n \n loadTypesInternal(registry: MoveCoder) {\n loadAllTypes(registry)\n }\n }\n `\n }\n\n return `\n ${processor}\n\n export namespace ${moduleName} {\n ${structs.join('\\n')}\n \n ${callArgs.join('\\n')}\n \n export function loadTypes(_r: MoveCoder) {\n loadAllTypes(_r)\n }\n export const ABI: MoveModule = JSON.parse('${JSON.stringify(module)}')\n }\n `\n}\n\nfunction generateStructs(module: MoveModule, struct: MoveStruct, events: Set<string>) {\n const genericString = generateStructTypeParameters(struct)\n const genericStringAny = generateStructTypeParameters(struct, true)\n\n const structName = normalizeToJSName(struct.name)\n\n const fields = struct.fields.map((field) => {\n return `${field.name}: ${generateType(field.type, module.address)}`\n })\n\n let eventPayload = ''\n if (events.has(moduleQname(module) + SPLITTER + struct.name)) {\n eventPayload = `\n export interface ${structName}Instance extends \n TypedEventInstance<${structName}${genericStringAny}> {\n data_decoded: ${structName}${genericStringAny}\n type_arguments: [${struct.generic_type_params.map((_) => 'string').join(', ')}]\n }\n `\n }\n\n return `\n export class ${structName}${genericString} {\n static TYPE_QNAME = '${module.address}::${module.name}::${struct.name}'\n ${fields.join('\\n')} \n }\n \n ${eventPayload}\n `\n}\n\nfunction generateFunctionTypeParameters(func: MoveFunction) {\n let genericString = ''\n if (func.generic_type_params && func.generic_type_params.length > 0) {\n const params = func.generic_type_params\n .map((v, idx) => {\n return `T${idx}=any`\n })\n .join(',')\n genericString = `<${params}>`\n }\n return genericString\n}\n\nfunction generateStructTypeParameters(struct: MoveStruct, useAny = false) {\n let genericString = ''\n\n if (struct.generic_type_params && struct.generic_type_params.length > 0) {\n const params = struct.generic_type_params\n .map((v, idx) => {\n return useAny ? 'any' : 'T' + idx\n })\n .join(',')\n genericString = `<${params}>`\n }\n return genericString\n}\n\nfunction generateCallArgsStructs(module: MoveModule, func: MoveFunction) {\n if (!func.is_entry) {\n return\n }\n\n const fields = getMeaningfulFunctionParams(func).map((param) => {\n return `${generateType(param, module.address)}`\n })\n\n const camelFuncName = capitalizeFirstChar(camelCase(func.name))\n\n const genericString = generateFunctionTypeParameters(func)\n return `\n export interface ${camelFuncName}Payload${genericString}\n extends TypedEntryFunctionPayload<[${fields.join(',')}]> {\n arguments_decoded: [${fields.join(',')}],\n type_arguments: [${func.generic_type_params.map((_) => 'string').join(', ')}]\n }\n `\n}\n\nfunction generateOnEntryFunctions(module: MoveModule, func: MoveFunction) {\n if (!func.is_entry) {\n return ''\n }\n\n // const genericString = generateFunctionTypeParameters(func)\n const moduleName = normalizeToJSName(module.name)\n\n const camelFuncName = capitalizeFirstChar(camelCase(func.name))\n const source = `\n onEntry${camelFuncName}(func: (call: ${moduleName}.${camelFuncName}Payload, ctx: AptosContext) => void, filter?: CallFilter, fetchConfig?: AptosFetchConfig): ${moduleName} {\n this.onEntryFunctionCall(func, {\n ...filter,\n function: '${module.name}::${func.name}'\n },\n fetchConfig)\n return this\n }`\n\n return source\n}\n\nfunction getEventStructs(module: MoveModule) {\n const qname = moduleQname(module)\n const structMap = new Map<string, MoveStruct>()\n const eventMap = new Map<string, MoveStruct>()\n\n for (const struct of module.structs) {\n structMap.set(qname + SPLITTER + struct.name, struct)\n }\n\n for (const struct of module.structs) {\n for (const field of struct.fields) {\n const t = parseMoveType(field.type)\n if (t.qname === '0x1::event::EventHandle') {\n const event = t.typeArgs[0].qname\n const eventStruct = structMap.get(event)\n if (eventStruct) {\n eventMap.set(event, eventStruct)\n }\n }\n }\n }\n\n return eventMap\n}\n\nfunction generateOnEvents(module: MoveModule, struct: MoveStruct): string {\n // for struct that has drop + store\n // if (!isEvent(struct, module)) {\n // return ''\n // }\n\n // const genericString = generateStructTypeParameters(struct)\n\n const moduleName = normalizeToJSName(module.name)\n const source = `\n onEvent${struct.name}(func: (event: ${moduleName}.${normalizeToJSName(\n struct.name\n )}Instance, ctx: AptosContext) => void, fetchConfig?: AptosFetchConfig): ${moduleName} {\n this.onEvent(func, {\n type: '${module.name}::${struct.name}'\n },\n fetchConfig)\n return this\n }\n `\n return source\n}\n\nfunction capitalizeFirstChar(input: string): string {\n if (!input) {\n return input\n }\n return input[0].toUpperCase() + (input.length > 1 ? input.substring(1) : '')\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './codegen.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/aptos/codegen/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA","sourcesContent":["export * from './codegen.js'\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MoveModule } from '../move-types.js';
|
|
2
|
+
import { TypeDescriptor } from '../types.js';
|
|
3
|
+
export declare function generateType(type: string, currentAddress: string): string;
|
|
4
|
+
export declare class AccountModulesImportInfo {
|
|
5
|
+
imports: Map<string, Set<string>>;
|
|
6
|
+
account: string;
|
|
7
|
+
moduleName: string;
|
|
8
|
+
constructor(account: string, tsModuleName: string);
|
|
9
|
+
addImport(account: string, module: string): void;
|
|
10
|
+
}
|
|
11
|
+
export declare class AccountRegister {
|
|
12
|
+
accountImports: Map<string, AccountModulesImportInfo>;
|
|
13
|
+
pendingAccounts: Set<string>;
|
|
14
|
+
typeDescriptors: Map<string, TypeDescriptor>;
|
|
15
|
+
private loadTypeDescriptor;
|
|
16
|
+
register(module: MoveModule, tsModuleName: string): AccountModulesImportInfo;
|
|
17
|
+
}
|
|
18
|
+
export declare function normalizeToJSName(name: string): string;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { parseMoveType } from '../types.js';
|
|
2
|
+
import { moduleQname, moduleQnameForType, SPLITTER, VECTOR_STR } from '../utils.js';
|
|
3
|
+
function generateTypeForDescriptor(type, currentAddress) {
|
|
4
|
+
// TODO &signer is defintely an address, but what if &OTHER_TYPE?
|
|
5
|
+
if (type.qname.startsWith('&')) {
|
|
6
|
+
return 'Address';
|
|
7
|
+
}
|
|
8
|
+
switch (type.qname) {
|
|
9
|
+
case 'signer': // TODO check this
|
|
10
|
+
case 'address':
|
|
11
|
+
return 'Address';
|
|
12
|
+
case '0x1::string::String':
|
|
13
|
+
return 'string';
|
|
14
|
+
case 'bool':
|
|
15
|
+
return 'Boolean';
|
|
16
|
+
case 'u8':
|
|
17
|
+
case 'u16':
|
|
18
|
+
case 'u32':
|
|
19
|
+
return 'number';
|
|
20
|
+
case 'u64':
|
|
21
|
+
case 'u128':
|
|
22
|
+
return 'bigint';
|
|
23
|
+
}
|
|
24
|
+
if (type.qname === VECTOR_STR) {
|
|
25
|
+
// vector<u8> as hex string
|
|
26
|
+
const elementTypeQname = type.typeArgs[0].qname;
|
|
27
|
+
if (elementTypeQname === 'u8') {
|
|
28
|
+
return 'string';
|
|
29
|
+
}
|
|
30
|
+
if (elementTypeQname.startsWith('T') && !elementTypeQname.includes(SPLITTER)) {
|
|
31
|
+
return `${elementTypeQname}[] | string`;
|
|
32
|
+
}
|
|
33
|
+
return generateTypeForDescriptor(type.typeArgs[0], currentAddress) + '[]';
|
|
34
|
+
}
|
|
35
|
+
const simpleName = generateSimpleType(type.qname, currentAddress);
|
|
36
|
+
if (simpleName.length === 0) {
|
|
37
|
+
console.error('unexpected error');
|
|
38
|
+
}
|
|
39
|
+
if (simpleName.includes('vector')) {
|
|
40
|
+
console.error('unexpected error');
|
|
41
|
+
}
|
|
42
|
+
if (type.typeArgs.length > 0) {
|
|
43
|
+
// return simpleName
|
|
44
|
+
return simpleName + '<' + type.typeArgs.map((t) => generateTypeForDescriptor(t, currentAddress)).join(',') + '>';
|
|
45
|
+
}
|
|
46
|
+
return simpleName;
|
|
47
|
+
}
|
|
48
|
+
function generateSimpleType(type, currentAddress) {
|
|
49
|
+
const parts = type.split(SPLITTER);
|
|
50
|
+
for (let i = 0; i < parts.length; i++) {
|
|
51
|
+
parts[i] = normalizeToJSName(parts[i]);
|
|
52
|
+
}
|
|
53
|
+
if (parts.length < 2) {
|
|
54
|
+
return parts[0];
|
|
55
|
+
}
|
|
56
|
+
if (parts[0] === currentAddress) {
|
|
57
|
+
return parts.slice(1).join('.');
|
|
58
|
+
}
|
|
59
|
+
return '_' + parts.join('.');
|
|
60
|
+
}
|
|
61
|
+
// TODO ctx need to have type parameters
|
|
62
|
+
export function generateType(type, currentAddress) {
|
|
63
|
+
return generateTypeForDescriptor(parseMoveType(type), currentAddress);
|
|
64
|
+
}
|
|
65
|
+
export class AccountModulesImportInfo {
|
|
66
|
+
// account to module
|
|
67
|
+
imports;
|
|
68
|
+
account;
|
|
69
|
+
moduleName;
|
|
70
|
+
constructor(account, tsModuleName) {
|
|
71
|
+
this.account = account;
|
|
72
|
+
this.moduleName = tsModuleName;
|
|
73
|
+
this.imports = new Map();
|
|
74
|
+
}
|
|
75
|
+
addImport(account, module) {
|
|
76
|
+
if (account === this.account) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
let accountModules = this.imports.get(account);
|
|
80
|
+
if (!accountModules) {
|
|
81
|
+
accountModules = new Set();
|
|
82
|
+
this.imports.set(account, accountModules);
|
|
83
|
+
}
|
|
84
|
+
accountModules.add(module);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export class AccountRegister {
|
|
88
|
+
accountImports = new Map();
|
|
89
|
+
pendingAccounts = new Set();
|
|
90
|
+
// loadedAccount = new Set<string>()
|
|
91
|
+
typeDescriptors = new Map();
|
|
92
|
+
loadTypeDescriptor(type) {
|
|
93
|
+
let descriptor = this.typeDescriptors.get(type);
|
|
94
|
+
// const descriptparseMoveType(type)
|
|
95
|
+
if (!descriptor) {
|
|
96
|
+
descriptor = parseMoveType(type);
|
|
97
|
+
this.typeDescriptors.set(type, descriptor);
|
|
98
|
+
}
|
|
99
|
+
return descriptor;
|
|
100
|
+
}
|
|
101
|
+
register(module, tsModuleName) {
|
|
102
|
+
const currentModuleFqn = moduleQname(module);
|
|
103
|
+
let accountModuleImports = this.accountImports.get(module.address);
|
|
104
|
+
if (!accountModuleImports) {
|
|
105
|
+
accountModuleImports = new AccountModulesImportInfo(module.address, tsModuleName);
|
|
106
|
+
this.accountImports.set(module.address, accountModuleImports);
|
|
107
|
+
// the account has already be processed, delete pending task
|
|
108
|
+
this.pendingAccounts.delete(module.address);
|
|
109
|
+
}
|
|
110
|
+
for (const struct of module.structs) {
|
|
111
|
+
for (const field of struct.fields) {
|
|
112
|
+
for (const type of this.loadTypeDescriptor(field.type).dependedTypes()) {
|
|
113
|
+
const [account, module] = moduleQnameForType(type);
|
|
114
|
+
accountModuleImports.addImport(account, module);
|
|
115
|
+
if (!this.accountImports.has(account)) {
|
|
116
|
+
this.pendingAccounts.add(account);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
for (const func of module.exposed_functions) {
|
|
122
|
+
if (!func.is_entry) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
for (const param of func.params) {
|
|
126
|
+
for (const type of this.loadTypeDescriptor(param).dependedTypes()) {
|
|
127
|
+
const [account, module] = moduleQnameForType(type);
|
|
128
|
+
accountModuleImports.addImport(account, module);
|
|
129
|
+
if (!this.accountImports.has(account)) {
|
|
130
|
+
this.pendingAccounts.add(account);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
this.accountImports.set(currentModuleFqn, accountModuleImports);
|
|
136
|
+
return accountModuleImports;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
export function normalizeToJSName(name) {
|
|
140
|
+
if (name === 'package' || name === 'volatile') {
|
|
141
|
+
return name + '_';
|
|
142
|
+
}
|
|
143
|
+
return name;
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=typegen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typegen.js","sourceRoot":"","sources":["../../../src/aptos/codegen/typegen.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAkB,MAAM,aAAa,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAEnF,SAAS,yBAAyB,CAAC,IAAoB,EAAE,cAAsB;IAC7E,iEAAiE;IACjE,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QAC9B,OAAO,SAAS,CAAA;KACjB;IAED,QAAQ,IAAI,CAAC,KAAK,EAAE;QAClB,KAAK,QAAQ,CAAC,CAAC,kBAAkB;QACjC,KAAK,SAAS;YACZ,OAAO,SAAS,CAAA;QAClB,KAAK,qBAAqB;YACxB,OAAO,QAAQ,CAAA;QACjB,KAAK,MAAM;YACT,OAAO,SAAS,CAAA;QAClB,KAAK,IAAI,CAAC;QACV,KAAK,KAAK,CAAC;QACX,KAAK,KAAK;YACR,OAAO,QAAQ,CAAA;QACjB,KAAK,KAAK,CAAC;QACX,KAAK,MAAM;YACT,OAAO,QAAQ,CAAA;KAClB;IAED,IAAI,IAAI,CAAC,KAAK,KAAK,UAAU,EAAE;QAC7B,2BAA2B;QAC3B,MAAM,gBA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B,CAAC,IAAI,CAAC,CAAA;oBAClD,oBAAoB,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;oBAC/C,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;wBACrC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;qBAClC;iBACF;aACF;SACF;QAED,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,iBAAiB,EAAE;YAC3C,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;gBAClB,SAAQ;aACT;YACD,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;gBAC/B,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,aAAa,EAAE,EAAE;oBACjE,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAA;oBAClD,oBAAoB,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;oBAC/C,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;wBACrC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;qBAClC;iBACF;aACF;SACF;QACD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,gBAAgB,EAAE,oBAAoB,CAAC,CAAA;QAC/D,OAAO,oBAAoB,CAAA;IAC7B,CAAC;CACF;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,UAAU,EAAE;QAC7C,OAAO,IAAI,GAAG,GAAG,CAAA;KAClB;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import { MoveModule } from '../move-types.js'\nimport { parseMoveType, TypeDescriptor } from '../types.js'\nimport { moduleQname, moduleQnameForType, SPLITTER, VECTOR_STR } from '../utils.js'\n\nfunction generateTypeForDescriptor(type: TypeDescriptor, currentAddress: string): string {\n // TODO &signer is defintely an address, but what if &OTHER_TYPE?\n if (type.qname.startsWith('&')) {\n return 'Address'\n }\n\n switch (type.qname) {\n case 'signer': // TODO check this\n case 'address':\n return 'Address'\n case '0x1::string::String':\n return 'string'\n case 'bool':\n return 'Boolean'\n case 'u8':\n case 'u16':\n case 'u32':\n return 'number'\n case 'u64':\n case 'u128':\n return 'bigint'\n }\n\n if (type.qname === VECTOR_STR) {\n // vector<u8> as hex string\n const elementTypeQname = type.typeArgs[0].qname\n if (elementTypeQname === 'u8') {\n return 'string'\n }\n if (elementTypeQname.startsWith('T') && !elementTypeQname.includes(SPLITTER)) {\n return `${elementTypeQname}[] | string`\n }\n return generateTypeForDescriptor(type.typeArgs[0], currentAddress) + '[]'\n }\n\n const simpleName = generateSimpleType(type.qname, currentAddress)\n if (simpleName.length === 0) {\n console.error('unexpected error')\n }\n if (simpleName.includes('vector')) {\n console.error('unexpected error')\n }\n if (type.typeArgs.length > 0) {\n // return simpleName\n return simpleName + '<' + type.typeArgs.map((t) => generateTypeForDescriptor(t, currentAddress)).join(',') + '>'\n }\n return simpleName\n}\n\nfunction generateSimpleType(type: string, currentAddress: string): string {\n const parts = type.split(SPLITTER)\n\n for (let i = 0; i < parts.length; i++) {\n parts[i] = normalizeToJSName(parts[i])\n }\n\n if (parts.length < 2) {\n return parts[0]\n }\n if (parts[0] === currentAddress) {\n return parts.slice(1).join('.')\n }\n return '_' + parts.join('.')\n}\n\n// TODO ctx need to have type parameters\nexport function generateType(type: string, currentAddress: string): string {\n return generateTypeForDescriptor(parseMoveType(type), currentAddress)\n}\n\nexport class AccountModulesImportInfo {\n // account to module\n imports: Map<string, Set<string>>\n account: string\n moduleName: string\n\n constructor(account: string, tsModuleName: string) {\n this.account = account\n this.moduleName = tsModuleName\n this.imports = new Map<string, Set<string>>()\n }\n\n addImport(account: string, module: string) {\n if (account === this.account) {\n return\n }\n let accountModules = this.imports.get(account)\n if (!accountModules) {\n accountModules = new Set<string>()\n this.imports.set(account, accountModules)\n }\n accountModules.add(module)\n }\n}\n\nexport class AccountRegister {\n accountImports = new Map<string, AccountModulesImportInfo>()\n pendingAccounts = new Set<string>()\n\n // loadedAccount = new Set<string>()\n typeDescriptors = new Map<string, TypeDescriptor>()\n\n private loadTypeDescriptor(type: string) {\n let descriptor = this.typeDescriptors.get(type)\n\n // const descriptparseMoveType(type)\n if (!descriptor) {\n descriptor = parseMoveType(type)\n this.typeDescriptors.set(type, descriptor)\n }\n return descriptor\n }\n\n register(module: MoveModule, tsModuleName: string): AccountModulesImportInfo {\n const currentModuleFqn = moduleQname(module)\n\n let accountModuleImports = this.accountImports.get(module.address)\n if (!accountModuleImports) {\n accountModuleImports = new AccountModulesImportInfo(module.address, tsModuleName)\n this.accountImports.set(module.address, accountModuleImports)\n // the account has already be processed, delete pending task\n this.pendingAccounts.delete(module.address)\n }\n\n for (const struct of module.structs) {\n for (const field of struct.fields) {\n for (const type of this.loadTypeDescriptor(field.type).dependedTypes()) {\n const [account, module] = moduleQnameForType(type)\n accountModuleImports.addImport(account, module)\n if (!this.accountImports.has(account)) {\n this.pendingAccounts.add(account)\n }\n }\n }\n }\n\n for (const func of module.exposed_functions) {\n if (!func.is_entry) {\n continue\n }\n for (const param of func.params) {\n for (const type of this.loadTypeDescriptor(param).dependedTypes()) {\n const [account, module] = moduleQnameForType(type)\n accountModuleImports.addImport(account, module)\n if (!this.accountImports.has(account)) {\n this.pendingAccounts.add(account)\n }\n }\n }\n }\n this.accountImports.set(currentModuleFqn, accountModuleImports)\n return accountModuleImports\n }\n}\n\nexport function normalizeToJSName(name: string) {\n if (name === 'package' || name === 'volatile') {\n return name + '_'\n }\n return name\n}\n"]}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typegen.test.js","sourceRoot":"","sources":["../../../src/aptos/codegen/typegen.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,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AyC,CAAC,CAAA;QAE7D,MAAM,kBAAkB,GAAG,GAAG,CAAC,YAAY,EAAE,CAAA;QAC7C,MAAM,CAAC,kBAAkB,KAAK,UAAU,CAAC,CAAA;IAC3C,CAAC,CAAC,CAAA;IACF,sCAAsC;IACtC,EAAE;IACF,iEAAiE;IACjE,qBAAqB;IACrB,EAAE;IACF,+BAA+B;IAC/B,4DAA4D;IAC5D,yEAAyE;IACzE,KAAK;AACP,CAAC,CAAC,CAAA","sourcesContent":["import { assert } from 'chai'\nimport { parseMoveType } from '../types.js'\n\ndescribe('type gen', () => {\n test('type gen for generic', async () => {\n const res = parseMoveType('x<g1<a,g2<c,d>>,b,g3<a,b>,e>')\n\n assert(res.qname === 'x')\n assert(res.typeArgs[0].typeArgs[1].qname === 'g2')\n assert(res.typeArgs[0].typeArgs[1].typeArgs[1].qname === 'd')\n })\n\n test('type gen for non generic', async () => {\n const res = parseMoveType('xyz')\n\n assert(res.qname === 'xyz')\n assert(res.typeArgs.length === 0)\n })\n\n test('test depended types', async () => {\n const typeString =\n '0x1::table_with_length::TableWithLength<T0, 0xd5f9f2b1c24faee8f07b790e570c75dfa1b7d8c1e9a60162fbd92ade03ea29e4::iterable_table::IterableValue<T0, T1>>'\n const res = parseMoveType(typeString)\n\n const deps = res.dependedTypes()\n assert(deps.length === 2)\n assert(\n deps[0] === '0xd5f9f2b1c24faee8f07b790e570c75dfa1b7d8c1e9a60162fbd92ade03ea29e4::iterable_table::IterableValue'\n )\n assert(deps[1] === '0x1::table_with_length::TableWithLength')\n\n const computedTypeString = res.getSignature()\n assert(computedTypeString === typeString)\n })\n // test('type type gen', async () => {\n //\n // const res = parseGenericType('x<g1<a,g2<c,d>>,b,g3<a,b>,e>')\n // console.log(res)\n //\n // assert(res.symbol === 'x')\n // assert(res.typeParams[0].typeParams[1].symbol === \"g2\")\n // assert(res.typeParams[0].typeParams[1].typeParams[1].symbol === \"d\")\n // })\n})\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { RecordMetaData } from '@sentio/protos';
|
|
2
|
+
import { type Labels, BaseContext } from '@sentio/sdk';
|
|
3
|
+
import { Transaction_UserTransaction } from './move-types.js';
|
|
4
|
+
import { AptosNetwork } from './network.js';
|
|
5
|
+
export declare class AptosContext extends BaseContext {
|
|
6
|
+
address: string;
|
|
7
|
+
network: AptosNetwork;
|
|
8
|
+
moduleName: string;
|
|
9
|
+
version: bigint;
|
|
10
|
+
transaction: Transaction_UserTransaction;
|
|
11
|
+
constructor(moduleName: string, network: AptosNetwork, address: string, version: bigint, transaction?: Transaction_UserTransaction);
|
|
12
|
+
getMetaData(name: string, labels: Labels): RecordMetaData;
|
|
13
|
+
}
|
|
14
|
+
export declare class AptosResourceContext extends BaseContext {
|
|
15
|
+
address: string;
|
|
16
|
+
network: AptosNetwork;
|
|
17
|
+
version: bigint;
|
|
18
|
+
timestampInMicros: number;
|
|
19
|
+
constructor(network: AptosNetwork, address: string, version: bigint, timestampInMicros: number);
|
|
20
|
+
getMetaData(name: string, labels: Labels): RecordMetaData;
|
|
21
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { BaseContext, normalizeLabels } from '@sentio/sdk';
|
|
2
|
+
import { getChainId } from './network.js';
|
|
3
|
+
export class AptosContext extends BaseContext {
|
|
4
|
+
address;
|
|
5
|
+
network;
|
|
6
|
+
moduleName;
|
|
7
|
+
version;
|
|
8
|
+
transaction;
|
|
9
|
+
constructor(moduleName, network, address, version, transaction) {
|
|
10
|
+
super();
|
|
11
|
+
this.address = address;
|
|
12
|
+
this.network = network;
|
|
13
|
+
this.moduleName = moduleName;
|
|
14
|
+
this.version = version;
|
|
15
|
+
if (transaction) {
|
|
16
|
+
this.transaction = transaction;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
getMetaData(name, labels) {
|
|
20
|
+
return {
|
|
21
|
+
address: this.address,
|
|
22
|
+
contractName: this.moduleName,
|
|
23
|
+
blockNumber: this.version,
|
|
24
|
+
transactionIndex: 0,
|
|
25
|
+
transactionHash: this.transaction?.hash || '',
|
|
26
|
+
logIndex: 0,
|
|
27
|
+
chainId: getChainId(this.network),
|
|
28
|
+
name: name,
|
|
29
|
+
labels: normalizeLabels(labels),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export class AptosResourceContext extends BaseContext {
|
|
34
|
+
address;
|
|
35
|
+
network;
|
|
36
|
+
version;
|
|
37
|
+
timestampInMicros;
|
|
38
|
+
constructor(network, address, version, timestampInMicros) {
|
|
39
|
+
super();
|
|
40
|
+
this.address = address;
|
|
41
|
+
this.network = network;
|
|
42
|
+
this.version = version;
|
|
43
|
+
this.timestampInMicros = timestampInMicros;
|
|
44
|
+
}
|
|
45
|
+
getMetaData(name, labels) {
|
|
46
|
+
return {
|
|
47
|
+
address: this.address,
|
|
48
|
+
contractName: 'resources',
|
|
49
|
+
blockNumber: this.version,
|
|
50
|
+
transactionIndex: 0,
|
|
51
|
+
transactionHash: '',
|
|
52
|
+
logIndex: 0,
|
|
53
|
+
chainId: getChainId(this.network),
|
|
54
|
+
name: name,
|
|
55
|
+
labels: normalizeLabels(labels),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/aptos/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAEvE,OAAO,EAAgB,UAAU,EAAE,MAAM,cAAc,CAAA;AAEvD,MAAM,OAAO,YAAa,SAAQ,WAAW;IAC3C,OAAO,CAAQ;IACf,OAAO,CAAc;IACrB,UAAU,CAAQ;IAClB,OAAO,CAAQ;IACf,WAAW,CAA6B;IAExC,YACE,UAAkB,EAClB,OAAqB,EACrB,OAAe,EACf,OAAe,EACf,WAAyC;QAEzC,KAAK,EAAE,CAAA;QACP,IAAI,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ACnB,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC;YACjC,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF","sourcesContent":["import { RecordMetaData } from '@sentio/protos'\nimport { type Labels, BaseContext, normalizeLabels } from '@sentio/sdk'\nimport { Transaction_UserTransaction } from './move-types.js'\nimport { AptosNetwork, getChainId } from './network.js'\n\nexport class AptosContext extends BaseContext {\n address: string\n network: AptosNetwork\n moduleName: string\n version: bigint\n transaction: Transaction_UserTransaction\n\n constructor(\n moduleName: string,\n network: AptosNetwork,\n address: string,\n version: bigint,\n transaction?: Transaction_UserTransaction\n ) {\n super()\n this.address = address\n this.network = network\n this.moduleName = moduleName\n this.version = version\n if (transaction) {\n this.transaction = transaction\n }\n }\n\n getMetaData(name: string, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.moduleName,\n blockNumber: this.version,\n transactionIndex: 0,\n transactionHash: this.transaction?.hash || '', // TODO\n logIndex: 0,\n chainId: getChainId(this.network),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n}\n\nexport class AptosResourceContext extends BaseContext {\n address: string\n network: AptosNetwork\n version: bigint\n timestampInMicros: number\n\n constructor(network: AptosNetwork, address: string, version: bigint, timestampInMicros: number) {\n super()\n this.address = address\n this.network = network\n this.version = version\n this.timestampInMicros = timestampInMicros\n }\n\n getMetaData(name: string, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: 'resources',\n blockNumber: this.version,\n transactionIndex: 0,\n transactionHash: '',\n logIndex: 0,\n chainId: getChainId(this.network),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './move-types.js';
|
|
2
|
+
export type { EventInstance, TypedEventInstance, TypedEntryFunctionPayload, TypedMoveResource } from './models.js';
|
|
3
|
+
export { defaultMoveCoder, MoveCoder } from './move-coder.js';
|
|
4
|
+
export type { FunctionNameAndCallFilter, EventFilter, CallFilter, ArgumentsFilter } from './aptos-processor.js';
|
|
5
|
+
export { AptosBaseProcessor, AptosAccountProcessor } from './aptos-processor.js';
|
|
6
|
+
export { AptosContext, AptosResourceContext } from './context.js';
|
|
7
|
+
export { AptosBindOptions, AptosNetwork } from './network.js';
|
|
8
|
+
export * from './api.js';
|
|
9
|
+
export { AptosPlugin } from './aptos-plugin.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './move-types.js';
|
|
2
|
+
export { defaultMoveCoder, MoveCoder } from './move-coder.js';
|
|
3
|
+
export { AptosBaseProcessor, AptosAccountProcessor } from './aptos-processor.js';
|
|
4
|
+
export { AptosContext, AptosResourceContext } from './context.js';
|
|
5
|
+
export { AptosBindOptions, AptosNetwork } from './network.js';
|
|
6
|
+
export * from './api.js';
|
|
7
|
+
export { AptosPlugin } from './aptos-plugin.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/aptos/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAE/B,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE7D,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAChF,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACjE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC7D,cAAc,UAAU,CAAA;AAExB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA","sourcesContent":["export * from './move-types.js'\nexport type { EventInstance, TypedEventInstance, TypedEntryFunctionPayload, TypedMoveResource } from './models.js'\nexport { defaultMoveCoder, MoveCoder } from './move-coder.js'\nexport type { FunctionNameAndCallFilter, EventFilter, CallFilter, ArgumentsFilter } from './aptos-processor.js'\nexport { AptosBaseProcessor, AptosAccountProcessor } from './aptos-processor.js'\nexport { AptosContext, AptosResourceContext } from './context.js'\nexport { AptosBindOptions, AptosNetwork } from './network.js'\nexport * from './api.js'\n\nexport { AptosPlugin } from './aptos-plugin.js'\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Event, MoveResource, TransactionPayload_EntryFunctionPayload } from './move-types.js';
|
|
2
|
+
export type EventInstance = Event & {
|
|
3
|
+
version: string;
|
|
4
|
+
};
|
|
5
|
+
export type TypedEventInstance<T> = EventInstance & {
|
|
6
|
+
/**
|
|
7
|
+
* decoded data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
|
|
8
|
+
*/
|
|
9
|
+
data_decoded: T;
|
|
10
|
+
type_arguments: string[];
|
|
11
|
+
};
|
|
12
|
+
export type TypedEntryFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {
|
|
13
|
+
/**
|
|
14
|
+
* decoded argument data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
|
|
15
|
+
*/
|
|
16
|
+
arguments_decoded: T;
|
|
17
|
+
};
|
|
18
|
+
export type TypedMoveResource<T> = MoveResource & {
|
|
19
|
+
type_arguments: string[];
|
|
20
|
+
};
|
|
21
|
+
export interface StructWithTag {
|
|
22
|
+
type: string;
|
|
23
|
+
data: any;
|
|
24
|
+
}
|
|
25
|
+
export interface StructWithType<T> extends StructWithTag {
|
|
26
|
+
type_arguments: string[];
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/aptos/models.ts"],"names":[],"mappings":"","sourcesContent":["import { Event, MoveResource, TransactionPayload_EntryFunctionPayload } from './move-types.js'\n\nexport type EventInstance = Event & {\n version: string\n}\n\nexport type TypedEventInstance<T> = EventInstance & {\n /**\n * decoded data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch\n */\n data_decoded: T\n\n type_arguments: string[]\n}\n\n// Don't use intermediate type to make IDE happier\nexport type TypedEntryFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {\n /**\n * decoded argument data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch\n */\n arguments_decoded: T\n}\n\nexport type TypedMoveResource<T> = MoveResource & {\n type_arguments: string[]\n}\n\nexport interface StructWithTag {\n type: string\n data: any\n}\n\nexport interface StructWithType<T> extends StructWithTag {\n type_arguments: string[]\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Event, MoveFunction, MoveModule, MoveResource, MoveStruct, TransactionPayload_EntryFunctionPayload } from './move-types.js';
|
|
2
|
+
import { TypeDescriptor } from './types.js';
|
|
3
|
+
import { TypedEventInstance, TypedMoveResource } from './models.js';
|
|
4
|
+
export declare class MoveCoder {
|
|
5
|
+
private moduleMapping;
|
|
6
|
+
private typeMapping;
|
|
7
|
+
private funcMapping;
|
|
8
|
+
contains(account: string, name: string): boolean;
|
|
9
|
+
load(module: MoveModule): void;
|
|
10
|
+
getMoveStruct(type: string): MoveStruct;
|
|
11
|
+
getMoveFunction(type: string): MoveFunction;
|
|
12
|
+
decode(data: any, type: TypeDescriptor): any;
|
|
13
|
+
decodeEvent<T>(event: Event): TypedEventInstance<T> | undefined;
|
|
14
|
+
filterAndDecodeEvents<T>(typeQname: string, resources: Event[]): TypedEventInstance<T>[];
|
|
15
|
+
decodeResource<T>(res: MoveResource): TypedMoveResource<T> | undefined;
|
|
16
|
+
filterAndDecodeResources<T>(typeQname: string, resources: MoveResource[]): TypedMoveResource<T>[];
|
|
17
|
+
private filterAndDecodeInternal;
|
|
18
|
+
private decodedInternal;
|
|
19
|
+
decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): TransactionPayload_EntryFunctionPayload;
|
|
20
|
+
}
|
|
21
|
+
export declare const MOVE_CODER: MoveCoder;
|
|
22
|
+
export declare function defaultMoveCoder(): MoveCoder;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { getMeaningfulFunctionParams, moduleQname, SPLITTER, VECTOR_STR } from './utils.js';
|
|
2
|
+
import { parseMoveType } from './types.js';
|
|
3
|
+
export class MoveCoder {
|
|
4
|
+
moduleMapping = new Map();
|
|
5
|
+
typeMapping = new Map();
|
|
6
|
+
funcMapping = new Map();
|
|
7
|
+
contains(account, name) {
|
|
8
|
+
return this.moduleMapping.has(account + '::' + name);
|
|
9
|
+
}
|
|
10
|
+
load(module) {
|
|
11
|
+
if (this.contains(module.address, module.name)) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
this.moduleMapping.set(moduleQname(module), module);
|
|
15
|
+
for (const struct of module.structs) {
|
|
16
|
+
// TODO move to util
|
|
17
|
+
const key = [module.address, module.name, struct.name].join(SPLITTER);
|
|
18
|
+
this.typeMapping.set(key, struct);
|
|
19
|
+
}
|
|
20
|
+
for (const func of module.exposed_functions) {
|
|
21
|
+
if (!func.is_entry) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const key = [module.address, module.name, func.name].join(SPLITTER);
|
|
25
|
+
this.funcMapping.set(key, func);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
getMoveStruct(type) {
|
|
29
|
+
const struct = this.typeMapping.get(type);
|
|
30
|
+
if (!struct) {
|
|
31
|
+
throw new Error('Failed to load type' + type);
|
|
32
|
+
}
|
|
33
|
+
return struct;
|
|
34
|
+
}
|
|
35
|
+
getMoveFunction(type) {
|
|
36
|
+
const func = this.funcMapping.get(type);
|
|
37
|
+
if (!func) {
|
|
38
|
+
throw new Error('Failed to load function' + type);
|
|
39
|
+
}
|
|
40
|
+
return func;
|
|
41
|
+
}
|
|
42
|
+
decode(data, type) {
|
|
43
|
+
// process simple type
|
|
44
|
+
if (type.qname.startsWith('&')) {
|
|
45
|
+
return data;
|
|
46
|
+
}
|
|
47
|
+
switch (type.qname) {
|
|
48
|
+
case 'signer': // TODO check this
|
|
49
|
+
case 'address':
|
|
50
|
+
case '0x1::string::String':
|
|
51
|
+
case 'bool':
|
|
52
|
+
case 'u8':
|
|
53
|
+
case 'u16':
|
|
54
|
+
case 'u32':
|
|
55
|
+
return data;
|
|
56
|
+
case 'u64':
|
|
57
|
+
case 'u128':
|
|
58
|
+
return BigInt(data);
|
|
59
|
+
}
|
|
60
|
+
// process vector
|
|
61
|
+
if (type.qname === VECTOR_STR) {
|
|
62
|
+
// vector<u8> as hex string
|
|
63
|
+
if (type.typeArgs[0].qname === 'u8') {
|
|
64
|
+
return data;
|
|
65
|
+
}
|
|
66
|
+
const res = [];
|
|
67
|
+
for (const entry of data) {
|
|
68
|
+
res.push(this.decode(entry, type.typeArgs[0]));
|
|
69
|
+
}
|
|
70
|
+
return res;
|
|
71
|
+
}
|
|
72
|
+
// Process complex type
|
|
73
|
+
const struct = this.getMoveStruct(type.qname);
|
|
74
|
+
const typeCtx = new Map();
|
|
75
|
+
for (const [idx, typeArg] of type.typeArgs.entries()) {
|
|
76
|
+
typeCtx.set('T' + idx, typeArg);
|
|
77
|
+
}
|
|
78
|
+
const typedData = {};
|
|
79
|
+
for (const field of struct.fields) {
|
|
80
|
+
let filedType = parseMoveType(field.type);
|
|
81
|
+
filedType = filedType.applyTypeArgs(typeCtx);
|
|
82
|
+
const value = this.decode(data[field.name], filedType);
|
|
83
|
+
typedData[field.name] = value;
|
|
84
|
+
}
|
|
85
|
+
return typedData;
|
|
86
|
+
}
|
|
87
|
+
decodeEvent(event) {
|
|
88
|
+
return this.decodedInternal(event);
|
|
89
|
+
}
|
|
90
|
+
filterAndDecodeEvents(typeQname, resources) {
|
|
91
|
+
return this.filterAndDecodeInternal(typeQname, resources);
|
|
92
|
+
}
|
|
93
|
+
decodeResource(res) {
|
|
94
|
+
return this.decodedInternal(res);
|
|
95
|
+
}
|
|
96
|
+
filterAndDecodeResources(typeQname, resources) {
|
|
97
|
+
return this.filterAndDecodeInternal(typeQname, resources);
|
|
98
|
+
}
|
|
99
|
+
filterAndDecodeInternal(typeQname, structs) {
|
|
100
|
+
if (!structs) {
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
const results = [];
|
|
104
|
+
for (const resource of structs) {
|
|
105
|
+
if (resource.type.split('<')[0] !== typeQname) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const result = this.decodedInternal(resource);
|
|
109
|
+
if (result) {
|
|
110
|
+
results.push(result);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return results;
|
|
114
|
+
}
|
|
115
|
+
decodedInternal(typeStruct) {
|
|
116
|
+
const registry = MOVE_CODER;
|
|
117
|
+
// this.loadTypes(registry)
|
|
118
|
+
// TODO check if module is not loaded
|
|
119
|
+
const typeDescriptor = parseMoveType(typeStruct.type);
|
|
120
|
+
const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature());
|
|
121
|
+
let dataTyped = undefined;
|
|
122
|
+
try {
|
|
123
|
+
dataTyped = registry.decode(typeStruct.data, typeDescriptor);
|
|
124
|
+
}
|
|
125
|
+
catch (e) {
|
|
126
|
+
console.error('Decoding error for ', JSON.stringify(typeStruct), e);
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
...typeStruct,
|
|
131
|
+
data_decoded: dataTyped,
|
|
132
|
+
type_arguments: typeArguments,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
decodeFunctionPayload(payload) {
|
|
136
|
+
const registry = MOVE_CODER;
|
|
137
|
+
// this.loadTypes(registry)
|
|
138
|
+
const argumentsTyped = [];
|
|
139
|
+
try {
|
|
140
|
+
const func = registry.getMoveFunction(payload.function);
|
|
141
|
+
const params = getMeaningfulFunctionParams(func);
|
|
142
|
+
for (const [idx, arg] of payload.arguments.entries()) {
|
|
143
|
+
// TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them
|
|
144
|
+
const argType = parseMoveType(params[idx]);
|
|
145
|
+
argumentsTyped.push(registry.decode(arg, argType));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
catch (e) {
|
|
149
|
+
console.error('Decoding error for ', JSON.stringify(payload), e);
|
|
150
|
+
return payload;
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
...payload,
|
|
154
|
+
arguments_decoded: argumentsTyped,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
export const MOVE_CODER = new MoveCoder();
|
|
159
|
+
export function defaultMoveCoder() {
|
|
160
|
+
return MOVE_CODER;
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=move-coder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"move-coder.js","sourceRoot":"","sources":["../../src/aptos/move-coder.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,2BAA2B,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC3F,OAAO,EAAE,aAAa,EAAkB,MAAM,YAAY,CAAA;AAS1D,MAAM,OAAO,SAAS;IACZ,aAAa,GAAG,IAAI,GAAG,EAAsB,CAAA;IAC7C,WAAW,GAAG,IAAI,GAAG,EAAsB,CAAA;IAC3C,WAAW,GAAG,IAAI,GAAG,EAAwB,CAAA;IAErD,QAAQ,CAAC,OAAe,EAAE,IAAY;QACpC,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC,CAAA;IACtD,CAAC;IAED,IAAI,CAAC,MAAkB;QACrB,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE;YAC9C,OAAM;SACP;QACD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAA;QAEnD,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE;YACnC,oBAAoB;YACpB,MAAM,GAAG,GAAG,CAAC,MAA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AO,OAAO,CAAA;SACf;QAED,OAAO;YACL,GAAG,OAAO;YACV,iBAAiB,EAAE,cAAc;SACA,CAAA;IACrC,CAAC;CACF;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,SAAS,EAAE,CAAA;AAEzC,MAAM,UAAU,gBAAgB;IAC9B,OAAO,UAAU,CAAA;AACnB,CAAC","sourcesContent":["import {\n Event,\n MoveFunction,\n MoveModule,\n MoveResource,\n MoveStruct,\n TransactionPayload_EntryFunctionPayload,\n} from './move-types.js'\n\nimport { getMeaningfulFunctionParams, moduleQname, SPLITTER, VECTOR_STR } from './utils.js'\nimport { parseMoveType, TypeDescriptor } from './types.js'\nimport {\n TypedEventInstance,\n TypedMoveResource,\n StructWithTag,\n StructWithType,\n TypedEntryFunctionPayload,\n} from './models.js'\n\nexport class MoveCoder {\n private moduleMapping = new Map<string, MoveModule>()\n private typeMapping = new Map<string, MoveStruct>()\n private funcMapping = new Map<string, MoveFunction>()\n\n contains(account: string, name: string) {\n return this.moduleMapping.has(account + '::' + name)\n }\n\n load(module: MoveModule) {\n if (this.contains(module.address, module.name)) {\n return\n }\n this.moduleMapping.set(moduleQname(module), module)\n\n for (const struct of module.structs) {\n // TODO move to util\n const key = [module.address, module.name, struct.name].join(SPLITTER)\n this.typeMapping.set(key, struct)\n }\n\n for (const func of module.exposed_functions) {\n if (!func.is_entry) {\n continue\n }\n const key = [module.address, module.name, func.name].join(SPLITTER)\n this.funcMapping.set(key, func)\n }\n }\n\n getMoveStruct(type: string): MoveStruct {\n const struct = this.typeMapping.get(type)\n if (!struct) {\n throw new Error('Failed to load type' + type)\n }\n return struct\n }\n\n getMoveFunction(type: string): MoveFunction {\n const func = this.funcMapping.get(type)\n if (!func) {\n throw new Error('Failed to load function' + type)\n }\n return func\n }\n\n decode(data: any, type: TypeDescriptor): any {\n // process simple type\n if (type.qname.startsWith('&')) {\n return data\n }\n switch (type.qname) {\n case 'signer': // TODO check this\n case 'address':\n case '0x1::string::String':\n case 'bool':\n case 'u8':\n case 'u16':\n case 'u32':\n return data\n case 'u64':\n case 'u128':\n return BigInt(data)\n }\n\n // process vector\n if (type.qname === VECTOR_STR) {\n // vector<u8> as hex string\n if (type.typeArgs[0].qname === 'u8') {\n return data\n }\n\n const res = []\n for (const entry of data) {\n res.push(this.decode(entry, type.typeArgs[0]))\n }\n return res\n }\n\n // Process complex type\n const struct = this.getMoveStruct(type.qname)\n\n const typeCtx = new Map<string, TypeDescriptor>()\n for (const [idx, typeArg] of type.typeArgs.entries()) {\n typeCtx.set('T' + idx, typeArg)\n }\n\n const typedData: any = {}\n\n for (const field of struct.fields) {\n let filedType = parseMoveType(field.type)\n filedType = filedType.applyTypeArgs(typeCtx)\n const value = this.decode(data[field.name], filedType)\n typedData[field.name] = value\n }\n return typedData\n }\n\n decodeEvent<T>(event: Event): TypedEventInstance<T> | undefined {\n return this.decodedInternal<T>(event) as TypedEventInstance<T>\n }\n filterAndDecodeEvents<T>(typeQname: string, resources: Event[]): TypedEventInstance<T>[] {\n return this.filterAndDecodeInternal(typeQname, resources) as TypedEventInstance<T>[]\n }\n decodeResource<T>(res: MoveResource): TypedMoveResource<T> | undefined {\n return this.decodedInternal<T>(res)\n }\n filterAndDecodeResources<T>(typeQname: string, resources: MoveResource[]): TypedMoveResource<T>[] {\n return this.filterAndDecodeInternal(typeQname, resources)\n }\n\n private filterAndDecodeInternal<T>(typeQname: string, structs: StructWithTag[]): StructWithType<T>[] {\n if (!structs) {\n return []\n }\n const results: StructWithType<T>[] = []\n for (const resource of structs) {\n if (resource.type.split('<')[0] !== typeQname) {\n continue\n }\n const result = this.decodedInternal(resource)\n if (result) {\n results.push(result as StructWithType<T>)\n }\n }\n return results\n }\n\n private decodedInternal<T>(typeStruct: StructWithTag): StructWithType<T> | undefined {\n const registry = MOVE_CODER\n // this.loadTypes(registry)\n // TODO check if module is not loaded\n\n const typeDescriptor = parseMoveType(typeStruct.type)\n const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature())\n\n let dataTyped = undefined\n try {\n dataTyped = registry.decode(typeStruct.data, typeDescriptor)\n } catch (e) {\n console.error('Decoding error for ', JSON.stringify(typeStruct), e)\n return undefined\n }\n return {\n ...typeStruct,\n data_decoded: dataTyped,\n type_arguments: typeArguments,\n } as StructWithType<T>\n }\n\n decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): TransactionPayload_EntryFunctionPayload {\n const registry = MOVE_CODER\n // this.loadTypes(registry)\n const argumentsTyped: any[] = []\n\n try {\n const func = registry.getMoveFunction(payload.function)\n const params = getMeaningfulFunctionParams(func)\n for (const [idx, arg] of payload.arguments.entries()) {\n // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them\n const argType = parseMoveType(params[idx])\n argumentsTyped.push(registry.decode(arg, argType))\n }\n } catch (e) {\n console.error('Decoding error for ', JSON.stringify(payload), e)\n return payload\n }\n\n return {\n ...payload,\n arguments_decoded: argumentsTyped,\n } as TypedEntryFunctionPayload<any>\n }\n}\n\nexport const MOVE_CODER = new MoveCoder()\n\nexport function defaultMoveCoder(): MoveCoder {\n return MOVE_CODER\n}\n"]}
|