crypto-aio 0.0.3 → 0.1.0
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/CHANGELOG.md +17 -0
- package/README.md +144 -14
- package/dist/adapters/avalanche/address.d.ts +15 -0
- package/dist/adapters/avalanche/address.js +74 -0
- package/dist/adapters/avalanche/address.js.map +1 -0
- package/dist/adapters/avalanche/api.d.ts +100 -0
- package/dist/adapters/avalanche/api.js +381 -0
- package/dist/adapters/avalanche/api.js.map +1 -0
- package/dist/adapters/avalanche/builder.d.ts +13 -0
- package/dist/adapters/avalanche/builder.js +336 -0
- package/dist/adapters/avalanche/builder.js.map +1 -0
- package/dist/adapters/avalanche/cb58.d.ts +7 -0
- package/dist/adapters/avalanche/cb58.js +49 -0
- package/dist/adapters/avalanche/cb58.js.map +1 -0
- package/dist/adapters/avalanche/chains.d.ts +21 -0
- package/dist/adapters/avalanche/chains.js +79 -0
- package/dist/adapters/avalanche/chains.js.map +1 -0
- package/dist/adapters/avalanche/codec.d.ts +94 -0
- package/dist/adapters/avalanche/codec.js +371 -0
- package/dist/adapters/avalanche/codec.js.map +1 -0
- package/dist/adapters/avalanche/context.d.ts +59 -0
- package/dist/adapters/avalanche/context.js +114 -0
- package/dist/adapters/avalanche/context.js.map +1 -0
- package/dist/adapters/avalanche/decode.d.ts +16 -0
- package/dist/adapters/avalanche/decode.js +101 -0
- package/dist/adapters/avalanche/decode.js.map +1 -0
- package/dist/adapters/avalanche/driver.d.ts +22 -0
- package/dist/adapters/avalanche/driver.js +81 -0
- package/dist/adapters/avalanche/driver.js.map +1 -0
- package/dist/adapters/avalanche/errors.d.ts +18 -0
- package/dist/adapters/avalanche/errors.js +61 -0
- package/dist/adapters/avalanche/errors.js.map +1 -0
- package/dist/adapters/avalanche/fees.d.ts +23 -0
- package/dist/adapters/avalanche/fees.js +105 -0
- package/dist/adapters/avalanche/fees.js.map +1 -0
- package/dist/adapters/avalanche/index.d.ts +19 -0
- package/dist/adapters/avalanche/index.js +8 -0
- package/dist/adapters/avalanche/index.js.map +1 -0
- package/dist/adapters/avalanche/network.d.ts +37 -0
- package/dist/adapters/avalanche/network.js +135 -0
- package/dist/adapters/avalanche/network.js.map +1 -0
- package/dist/adapters/avalanche/plugin.d.ts +21 -0
- package/dist/adapters/avalanche/plugin.js +46 -0
- package/dist/adapters/avalanche/plugin.js.map +1 -0
- package/dist/adapters/avalanche/presets.d.ts +6 -0
- package/dist/adapters/avalanche/presets.js +86 -0
- package/dist/adapters/avalanche/presets.js.map +1 -0
- package/dist/adapters/avalanche/proofs.d.ts +41 -0
- package/dist/adapters/avalanche/proofs.js +270 -0
- package/dist/adapters/avalanche/proofs.js.map +1 -0
- package/dist/adapters/avalanche/reader.d.ts +40 -0
- package/dist/adapters/avalanche/reader.js +231 -0
- package/dist/adapters/avalanche/reader.js.map +1 -0
- package/dist/adapters/avalanche/sdk.d.ts +182 -0
- package/dist/adapters/avalanche/sdk.js +21 -0
- package/dist/adapters/avalanche/sdk.js.map +1 -0
- package/dist/adapters/avalanche/types.d.ts +86 -0
- package/dist/{type/common.js → adapters/avalanche/types.js} +1 -1
- package/dist/adapters/avalanche/types.js.map +1 -0
- package/dist/adapters/evm/builder.d.ts +11 -0
- package/dist/adapters/evm/builder.js +326 -0
- package/dist/adapters/evm/builder.js.map +1 -0
- package/dist/adapters/evm/chains.d.ts +6 -0
- package/dist/adapters/evm/chains.js +203 -0
- package/dist/adapters/evm/chains.js.map +1 -0
- package/dist/adapters/evm/client.d.ts +84 -0
- package/dist/adapters/evm/client.js +335 -0
- package/dist/adapters/evm/client.js.map +1 -0
- package/dist/adapters/evm/decode.d.ts +35 -0
- package/dist/adapters/evm/decode.js +170 -0
- package/dist/adapters/evm/decode.js.map +1 -0
- package/dist/adapters/evm/driver.d.ts +8 -0
- package/dist/adapters/evm/driver.js +61 -0
- package/dist/adapters/evm/driver.js.map +1 -0
- package/dist/adapters/evm/errors.d.ts +20 -0
- package/dist/adapters/evm/errors.js +110 -0
- package/dist/adapters/evm/errors.js.map +1 -0
- package/dist/adapters/evm/ethers-client.d.ts +43 -0
- package/dist/adapters/evm/ethers-client.js +135 -0
- package/dist/adapters/evm/ethers-client.js.map +1 -0
- package/dist/adapters/evm/fees.d.ts +79 -0
- package/dist/adapters/evm/fees.js +234 -0
- package/dist/adapters/evm/fees.js.map +1 -0
- package/dist/adapters/evm/index.d.ts +20 -0
- package/dist/adapters/evm/index.js +11 -0
- package/dist/adapters/evm/index.js.map +1 -0
- package/dist/adapters/evm/network.d.ts +60 -0
- package/dist/adapters/evm/network.js +131 -0
- package/dist/adapters/evm/network.js.map +1 -0
- package/dist/adapters/evm/plugin.d.ts +36 -0
- package/dist/adapters/evm/plugin.js +102 -0
- package/dist/adapters/evm/plugin.js.map +1 -0
- package/dist/adapters/evm/presets.d.ts +2 -0
- package/dist/adapters/evm/presets.js +105 -0
- package/dist/adapters/evm/presets.js.map +1 -0
- package/dist/adapters/evm/proofs.d.ts +19 -0
- package/dist/adapters/evm/proofs.js +358 -0
- package/dist/adapters/evm/proofs.js.map +1 -0
- package/dist/adapters/evm/rawtx.d.ts +25 -0
- package/dist/adapters/evm/rawtx.js +176 -0
- package/dist/adapters/evm/rawtx.js.map +1 -0
- package/dist/adapters/evm/reader.d.ts +65 -0
- package/dist/adapters/evm/reader.js +292 -0
- package/dist/adapters/evm/reader.js.map +1 -0
- package/dist/adapters/evm/rpc.d.ts +39 -0
- package/dist/adapters/evm/rpc.js +152 -0
- package/dist/adapters/evm/rpc.js.map +1 -0
- package/dist/adapters/evm/tokens.d.ts +7 -0
- package/dist/adapters/evm/tokens.js +23 -0
- package/dist/adapters/evm/tokens.js.map +1 -0
- package/dist/adapters/evm/types.d.ts +255 -0
- package/dist/{type/account.js → adapters/evm/types.js} +1 -1
- package/dist/adapters/evm/types.js.map +1 -0
- package/dist/adapters/evm/web3-client.d.ts +23 -0
- package/dist/adapters/evm/web3-client.js +159 -0
- package/dist/adapters/evm/web3-client.js.map +1 -0
- package/dist/adapters/solana/builder.d.ts +18 -0
- package/dist/adapters/solana/builder.js +545 -0
- package/dist/adapters/solana/builder.js.map +1 -0
- package/dist/adapters/solana/chains.d.ts +13 -0
- package/dist/adapters/solana/chains.js +37 -0
- package/dist/adapters/solana/chains.js.map +1 -0
- package/dist/adapters/solana/decode.d.ts +111 -0
- package/dist/adapters/solana/decode.js +595 -0
- package/dist/adapters/solana/decode.js.map +1 -0
- package/dist/adapters/solana/driver.d.ts +15 -0
- package/dist/adapters/solana/driver.js +72 -0
- package/dist/adapters/solana/driver.js.map +1 -0
- package/dist/adapters/solana/errors.d.ts +36 -0
- package/dist/adapters/solana/errors.js +154 -0
- package/dist/adapters/solana/errors.js.map +1 -0
- package/dist/adapters/solana/fees.d.ts +68 -0
- package/dist/adapters/solana/fees.js +205 -0
- package/dist/adapters/solana/fees.js.map +1 -0
- package/dist/adapters/solana/heights.d.ts +47 -0
- package/dist/adapters/solana/heights.js +185 -0
- package/dist/adapters/solana/heights.js.map +1 -0
- package/dist/adapters/solana/history.d.ts +10 -0
- package/dist/adapters/solana/history.js +71 -0
- package/dist/adapters/solana/history.js.map +1 -0
- package/dist/adapters/solana/index.d.ts +16 -0
- package/dist/adapters/solana/index.js +9 -0
- package/dist/adapters/solana/index.js.map +1 -0
- package/dist/adapters/solana/keys.d.ts +13 -0
- package/dist/adapters/solana/keys.js +69 -0
- package/dist/adapters/solana/keys.js.map +1 -0
- package/dist/adapters/solana/network.d.ts +24 -0
- package/dist/adapters/solana/network.js +95 -0
- package/dist/adapters/solana/network.js.map +1 -0
- package/dist/adapters/solana/plugin.d.ts +18 -0
- package/dist/adapters/solana/plugin.js +41 -0
- package/dist/adapters/solana/plugin.js.map +1 -0
- package/dist/adapters/solana/presets.d.ts +2 -0
- package/dist/adapters/solana/presets.js +77 -0
- package/dist/adapters/solana/presets.js.map +1 -0
- package/dist/adapters/solana/programs.d.ts +44 -0
- package/dist/adapters/solana/programs.js +159 -0
- package/dist/adapters/solana/programs.js.map +1 -0
- package/dist/adapters/solana/proofs.d.ts +56 -0
- package/dist/adapters/solana/proofs.js +540 -0
- package/dist/adapters/solana/proofs.js.map +1 -0
- package/dist/adapters/solana/reader.d.ts +82 -0
- package/dist/adapters/solana/reader.js +326 -0
- package/dist/adapters/solana/reader.js.map +1 -0
- package/dist/adapters/solana/rpc.d.ts +102 -0
- package/dist/adapters/solana/rpc.js +301 -0
- package/dist/adapters/solana/rpc.js.map +1 -0
- package/dist/adapters/solana/tokens.d.ts +7 -0
- package/dist/adapters/solana/tokens.js +19 -0
- package/dist/adapters/solana/tokens.js.map +1 -0
- package/dist/adapters/solana/types.d.ts +121 -0
- package/dist/{type/contract.js → adapters/solana/types.js} +1 -1
- package/dist/adapters/solana/types.js.map +1 -0
- package/dist/adapters/solana/web3.d.ts +5 -0
- package/dist/adapters/solana/web3.js +83 -0
- package/dist/adapters/solana/web3.js.map +1 -0
- package/dist/adapters/solana/wire.d.ts +62 -0
- package/dist/adapters/solana/wire.js +168 -0
- package/dist/adapters/solana/wire.js.map +1 -0
- package/dist/adapters/ton/address.d.ts +43 -0
- package/dist/adapters/ton/address.js +168 -0
- package/dist/adapters/ton/address.js.map +1 -0
- package/dist/adapters/ton/api.d.ts +344 -0
- package/dist/adapters/ton/api.js +942 -0
- package/dist/adapters/ton/api.js.map +1 -0
- package/dist/adapters/ton/builder.d.ts +18 -0
- package/dist/adapters/ton/builder.js +701 -0
- package/dist/adapters/ton/builder.js.map +1 -0
- package/dist/adapters/ton/chains.d.ts +16 -0
- package/dist/adapters/ton/chains.js +39 -0
- package/dist/adapters/ton/chains.js.map +1 -0
- package/dist/adapters/ton/decode.d.ts +43 -0
- package/dist/adapters/ton/decode.js +219 -0
- package/dist/adapters/ton/decode.js.map +1 -0
- package/dist/adapters/ton/driver.d.ts +10 -0
- package/dist/adapters/ton/driver.js +117 -0
- package/dist/adapters/ton/driver.js.map +1 -0
- package/dist/adapters/ton/errors.d.ts +36 -0
- package/dist/adapters/ton/errors.js +89 -0
- package/dist/adapters/ton/errors.js.map +1 -0
- package/dist/adapters/ton/fees.d.ts +28 -0
- package/dist/adapters/ton/fees.js +121 -0
- package/dist/adapters/ton/fees.js.map +1 -0
- package/dist/adapters/ton/index.d.ts +16 -0
- package/dist/adapters/ton/index.js +9 -0
- package/dist/adapters/ton/index.js.map +1 -0
- package/dist/adapters/ton/messages.d.ts +157 -0
- package/dist/adapters/ton/messages.js +397 -0
- package/dist/adapters/ton/messages.js.map +1 -0
- package/dist/adapters/ton/native-client.d.ts +10 -0
- package/dist/adapters/ton/native-client.js +47 -0
- package/dist/adapters/ton/native-client.js.map +1 -0
- package/dist/adapters/ton/network.d.ts +58 -0
- package/dist/adapters/ton/network.js +207 -0
- package/dist/adapters/ton/network.js.map +1 -0
- package/dist/adapters/ton/plugin.d.ts +24 -0
- package/dist/adapters/ton/plugin.js +57 -0
- package/dist/adapters/ton/plugin.js.map +1 -0
- package/dist/adapters/ton/presets.d.ts +6 -0
- package/dist/adapters/ton/presets.js +94 -0
- package/dist/adapters/ton/presets.js.map +1 -0
- package/dist/adapters/ton/proofs.d.ts +66 -0
- package/dist/adapters/ton/proofs.js +813 -0
- package/dist/adapters/ton/proofs.js.map +1 -0
- package/dist/adapters/ton/reader.d.ts +194 -0
- package/dist/adapters/ton/reader.js +781 -0
- package/dist/adapters/ton/reader.js.map +1 -0
- package/dist/adapters/ton/tokens.d.ts +10 -0
- package/dist/adapters/ton/tokens.js +27 -0
- package/dist/adapters/ton/tokens.js.map +1 -0
- package/dist/adapters/ton/trace.d.ts +48 -0
- package/dist/adapters/ton/trace.js +277 -0
- package/dist/adapters/ton/trace.js.map +1 -0
- package/dist/adapters/ton/types.d.ts +105 -0
- package/dist/{type/transact.js → adapters/ton/types.js} +1 -1
- package/dist/adapters/ton/types.js.map +1 -0
- package/dist/adapters/ton/wallets.d.ts +86 -0
- package/dist/adapters/ton/wallets.js +373 -0
- package/dist/adapters/ton/wallets.js.map +1 -0
- package/dist/adapters/tron/abi.d.ts +39 -0
- package/dist/adapters/tron/abi.js +110 -0
- package/dist/adapters/tron/abi.js.map +1 -0
- package/dist/adapters/tron/address.d.ts +20 -0
- package/dist/adapters/tron/address.js +110 -0
- package/dist/adapters/tron/address.js.map +1 -0
- package/dist/adapters/tron/builder.d.ts +12 -0
- package/dist/adapters/tron/builder.js +553 -0
- package/dist/adapters/tron/builder.js.map +1 -0
- package/dist/adapters/tron/chains.d.ts +12 -0
- package/dist/adapters/tron/chains.js +35 -0
- package/dist/adapters/tron/chains.js.map +1 -0
- package/dist/adapters/tron/codec.d.ts +10 -0
- package/dist/adapters/tron/codec.js +322 -0
- package/dist/adapters/tron/codec.js.map +1 -0
- package/dist/adapters/tron/decode.d.ts +50 -0
- package/dist/adapters/tron/decode.js +280 -0
- package/dist/adapters/tron/decode.js.map +1 -0
- package/dist/adapters/tron/driver.d.ts +12 -0
- package/dist/adapters/tron/driver.js +106 -0
- package/dist/adapters/tron/driver.js.map +1 -0
- package/dist/adapters/tron/errors.d.ts +74 -0
- package/dist/adapters/tron/errors.js +261 -0
- package/dist/adapters/tron/errors.js.map +1 -0
- package/dist/adapters/tron/fees.d.ts +49 -0
- package/dist/adapters/tron/fees.js +166 -0
- package/dist/adapters/tron/fees.js.map +1 -0
- package/dist/adapters/tron/http.d.ts +173 -0
- package/dist/adapters/tron/http.js +729 -0
- package/dist/adapters/tron/http.js.map +1 -0
- package/dist/adapters/tron/index.d.ts +16 -0
- package/dist/adapters/tron/index.js +15 -0
- package/dist/adapters/tron/index.js.map +1 -0
- package/dist/adapters/tron/network.d.ts +44 -0
- package/dist/adapters/tron/network.js +163 -0
- package/dist/adapters/tron/network.js.map +1 -0
- package/dist/adapters/tron/plugin.d.ts +17 -0
- package/dist/adapters/tron/plugin.js +39 -0
- package/dist/adapters/tron/plugin.js.map +1 -0
- package/dist/adapters/tron/presets.d.ts +5 -0
- package/dist/adapters/tron/presets.js +68 -0
- package/dist/adapters/tron/presets.js.map +1 -0
- package/dist/adapters/tron/proofs.d.ts +80 -0
- package/dist/adapters/tron/proofs.js +370 -0
- package/dist/adapters/tron/proofs.js.map +1 -0
- package/dist/adapters/tron/protobuf.d.ts +36 -0
- package/dist/adapters/tron/protobuf.js +90 -0
- package/dist/adapters/tron/protobuf.js.map +1 -0
- package/dist/adapters/tron/reader.d.ts +47 -0
- package/dist/adapters/tron/reader.js +203 -0
- package/dist/adapters/tron/reader.js.map +1 -0
- package/dist/adapters/tron/tokens.d.ts +7 -0
- package/dist/adapters/tron/tokens.js +14 -0
- package/dist/adapters/tron/tokens.js.map +1 -0
- package/dist/adapters/tron/types.d.ts +166 -0
- package/dist/adapters/tron/types.js +3 -0
- package/dist/adapters/tron/types.js.map +1 -0
- package/dist/adapters/utxo/address.d.ts +51 -0
- package/dist/adapters/utxo/address.js +341 -0
- package/dist/adapters/utxo/address.js.map +1 -0
- package/dist/adapters/utxo/builder.d.ts +35 -0
- package/dist/adapters/utxo/builder.js +380 -0
- package/dist/adapters/utxo/builder.js.map +1 -0
- package/dist/adapters/utxo/chains.d.ts +17 -0
- package/dist/adapters/utxo/chains.js +99 -0
- package/dist/adapters/utxo/chains.js.map +1 -0
- package/dist/adapters/utxo/codec.d.ts +120 -0
- package/dist/adapters/utxo/codec.js +408 -0
- package/dist/adapters/utxo/codec.js.map +1 -0
- package/dist/adapters/utxo/coinselect.d.ts +48 -0
- package/dist/adapters/utxo/coinselect.js +131 -0
- package/dist/adapters/utxo/coinselect.js.map +1 -0
- package/dist/adapters/utxo/context.d.ts +57 -0
- package/dist/adapters/utxo/context.js +118 -0
- package/dist/adapters/utxo/context.js.map +1 -0
- package/dist/adapters/utxo/decode.d.ts +14 -0
- package/dist/adapters/utxo/decode.js +85 -0
- package/dist/adapters/utxo/decode.js.map +1 -0
- package/dist/adapters/utxo/driver.d.ts +16 -0
- package/dist/adapters/utxo/driver.js +74 -0
- package/dist/adapters/utxo/driver.js.map +1 -0
- package/dist/adapters/utxo/ecc.d.ts +9 -0
- package/dist/adapters/utxo/ecc.js +26 -0
- package/dist/adapters/utxo/ecc.js.map +1 -0
- package/dist/adapters/utxo/errors.d.ts +52 -0
- package/dist/adapters/utxo/errors.js +191 -0
- package/dist/adapters/utxo/errors.js.map +1 -0
- package/dist/adapters/utxo/esplora.d.ts +79 -0
- package/dist/adapters/utxo/esplora.js +451 -0
- package/dist/adapters/utxo/esplora.js.map +1 -0
- package/dist/adapters/utxo/fees.d.ts +41 -0
- package/dist/adapters/utxo/fees.js +125 -0
- package/dist/adapters/utxo/fees.js.map +1 -0
- package/dist/adapters/utxo/index.d.ts +17 -0
- package/dist/adapters/utxo/index.js +8 -0
- package/dist/adapters/utxo/index.js.map +1 -0
- package/dist/adapters/utxo/network.d.ts +50 -0
- package/dist/adapters/utxo/network.js +165 -0
- package/dist/adapters/utxo/network.js.map +1 -0
- package/dist/adapters/utxo/plugin.d.ts +17 -0
- package/dist/adapters/utxo/plugin.js +41 -0
- package/dist/adapters/utxo/plugin.js.map +1 -0
- package/dist/adapters/utxo/presets.d.ts +12 -0
- package/dist/adapters/utxo/presets.js +47 -0
- package/dist/adapters/utxo/presets.js.map +1 -0
- package/dist/adapters/utxo/preview.d.ts +3 -0
- package/dist/adapters/utxo/preview.js +65 -0
- package/dist/adapters/utxo/preview.js.map +1 -0
- package/dist/adapters/utxo/proofs.d.ts +57 -0
- package/dist/adapters/utxo/proofs.js +331 -0
- package/dist/adapters/utxo/proofs.js.map +1 -0
- package/dist/adapters/utxo/rawtx.d.ts +59 -0
- package/dist/adapters/utxo/rawtx.js +234 -0
- package/dist/adapters/utxo/rawtx.js.map +1 -0
- package/dist/adapters/utxo/reader.d.ts +36 -0
- package/dist/adapters/utxo/reader.js +265 -0
- package/dist/adapters/utxo/reader.js.map +1 -0
- package/dist/adapters/utxo/sdk.d.ts +18 -0
- package/dist/adapters/utxo/sdk.js +17 -0
- package/dist/adapters/utxo/sdk.js.map +1 -0
- package/dist/adapters/utxo/signed-psbt.d.ts +36 -0
- package/dist/adapters/utxo/signed-psbt.js +428 -0
- package/dist/adapters/utxo/signed-psbt.js.map +1 -0
- package/dist/adapters/utxo/spend.d.ts +59 -0
- package/dist/adapters/utxo/spend.js +230 -0
- package/dist/adapters/utxo/spend.js.map +1 -0
- package/dist/adapters/utxo/types.d.ts +167 -0
- package/dist/adapters/utxo/types.js +3 -0
- package/dist/adapters/utxo/types.js.map +1 -0
- package/dist/core/assets/service.d.ts +18 -0
- package/dist/core/assets/service.js +69 -0
- package/dist/core/assets/service.js.map +1 -0
- package/dist/core/blockchain/default-ref.d.ts +4 -0
- package/dist/core/blockchain/default-ref.js +16 -0
- package/dist/core/blockchain/default-ref.js.map +1 -0
- package/dist/core/blockchain/handle.d.ts +200 -0
- package/dist/core/blockchain/handle.js +579 -0
- package/dist/core/blockchain/handle.js.map +1 -0
- package/dist/core/blockchain/internal.d.ts +19 -0
- package/dist/core/blockchain/internal.js +16 -0
- package/dist/core/blockchain/internal.js.map +1 -0
- package/dist/core/blockchain/mapping.d.ts +22 -0
- package/dist/core/blockchain/mapping.js +136 -0
- package/dist/core/blockchain/mapping.js.map +1 -0
- package/dist/core/config/env.d.ts +8 -0
- package/dist/core/config/env.js +60 -0
- package/dist/core/config/env.js.map +1 -0
- package/dist/core/config/merge.d.ts +26 -0
- package/dist/core/config/merge.js +144 -0
- package/dist/core/config/merge.js.map +1 -0
- package/dist/core/config/resolve.d.ts +12 -0
- package/dist/core/config/resolve.js +251 -0
- package/dist/core/config/resolve.js.map +1 -0
- package/dist/core/config/types.d.ts +165 -0
- package/dist/core/config/types.js +3 -0
- package/dist/core/config/types.js.map +1 -0
- package/dist/core/container/builtins.d.ts +4 -0
- package/dist/core/container/builtins.js +13 -0
- package/dist/core/container/builtins.js.map +1 -0
- package/dist/core/container/container.d.ts +69 -0
- package/dist/core/container/container.js +466 -0
- package/dist/core/container/container.js.map +1 -0
- package/dist/core/container/default.d.ts +15 -0
- package/dist/core/container/default.js +70 -0
- package/dist/core/container/default.js.map +1 -0
- package/dist/core/container/internals.d.ts +54 -0
- package/dist/core/container/internals.js +21 -0
- package/dist/core/container/internals.js.map +1 -0
- package/dist/core/container/pool.d.ts +27 -0
- package/dist/core/container/pool.js +77 -0
- package/dist/core/container/pool.js.map +1 -0
- package/dist/core/driver/types.d.ts +346 -0
- package/dist/core/driver/types.js +3 -0
- package/dist/core/driver/types.js.map +1 -0
- package/dist/core/errors/codes.d.ts +153 -0
- package/dist/core/errors/codes.js +49 -0
- package/dist/core/errors/codes.js.map +1 -0
- package/dist/core/errors/error.d.ts +66 -0
- package/dist/core/errors/error.js +129 -0
- package/dist/core/errors/error.js.map +1 -0
- package/dist/core/events/bus.d.ts +12 -0
- package/dist/core/events/bus.js +46 -0
- package/dist/core/events/bus.js.map +1 -0
- package/dist/core/events/logger.d.ts +13 -0
- package/dist/core/events/logger.js +42 -0
- package/dist/core/events/logger.js.map +1 -0
- package/dist/core/events/types.d.ts +131 -0
- package/dist/core/events/types.js +3 -0
- package/dist/core/events/types.js.map +1 -0
- package/dist/core/lifecycle/engine-rules.d.ts +107 -0
- package/dist/core/lifecycle/engine-rules.js +257 -0
- package/dist/core/lifecycle/engine-rules.js.map +1 -0
- package/dist/core/lifecycle/engine.d.ts +500 -0
- package/dist/core/lifecycle/engine.js +1732 -0
- package/dist/core/lifecycle/engine.js.map +1 -0
- package/dist/core/lifecycle/evaluate.d.ts +19 -0
- package/dist/core/lifecycle/evaluate.js +72 -0
- package/dist/core/lifecycle/evaluate.js.map +1 -0
- package/dist/core/lifecycle/intent.d.ts +11 -0
- package/dist/core/lifecycle/intent.js +88 -0
- package/dist/core/lifecycle/intent.js.map +1 -0
- package/dist/core/lifecycle/monitor.d.ts +138 -0
- package/dist/core/lifecycle/monitor.js +606 -0
- package/dist/core/lifecycle/monitor.js.map +1 -0
- package/dist/core/lifecycle/observations.d.ts +17 -0
- package/dist/core/lifecycle/observations.js +59 -0
- package/dist/core/lifecycle/observations.js.map +1 -0
- package/dist/core/lifecycle/reconcile.d.ts +58 -0
- package/dist/core/lifecycle/reconcile.js +112 -0
- package/dist/core/lifecycle/reconcile.js.map +1 -0
- package/dist/core/lifecycle/views.d.ts +49 -0
- package/dist/core/lifecycle/views.js +57 -0
- package/dist/core/lifecycle/views.js.map +1 -0
- package/dist/core/lifecycle/workers.d.ts +82 -0
- package/dist/core/lifecycle/workers.js +329 -0
- package/dist/core/lifecycle/workers.js.map +1 -0
- package/dist/core/model/address.d.ts +32 -0
- package/dist/core/model/address.js +43 -0
- package/dist/core/model/address.js.map +1 -0
- package/dist/core/model/amount.d.ts +25 -0
- package/dist/core/model/amount.js +102 -0
- package/dist/core/model/amount.js.map +1 -0
- package/dist/core/model/asset.d.ts +28 -0
- package/dist/core/model/asset.js +47 -0
- package/dist/core/model/asset.js.map +1 -0
- package/dist/core/model/capability.d.ts +3 -0
- package/dist/core/model/capability.js +18 -0
- package/dist/core/model/capability.js.map +1 -0
- package/dist/core/model/chain.d.ts +63 -0
- package/dist/core/model/chain.js +8 -0
- package/dist/core/model/chain.js.map +1 -0
- package/dist/core/model/fee.d.ts +36 -0
- package/dist/core/model/fee.js +17 -0
- package/dist/core/model/fee.js.map +1 -0
- package/dist/core/model/ids.d.ts +37 -0
- package/dist/core/model/ids.js +13 -0
- package/dist/core/model/ids.js.map +1 -0
- package/dist/core/model/intent.d.ts +63 -0
- package/dist/core/model/intent.js +81 -0
- package/dist/core/model/intent.js.map +1 -0
- package/dist/core/model/ordering.d.ts +20 -0
- package/dist/core/model/ordering.js +29 -0
- package/dist/core/model/ordering.js.map +1 -0
- package/dist/core/model/transaction.d.ts +116 -0
- package/dist/{type/lib-types.js → core/model/transaction.js} +1 -1
- package/dist/core/model/transaction.js.map +1 -0
- package/dist/core/observe/scanner.d.ts +135 -0
- package/dist/core/observe/scanner.js +355 -0
- package/dist/core/observe/scanner.js.map +1 -0
- package/dist/core/ordering/reservations.d.ts +16 -0
- package/dist/core/ordering/reservations.js +53 -0
- package/dist/core/ordering/reservations.js.map +1 -0
- package/dist/core/ordering/sequence.d.ts +61 -0
- package/dist/core/ordering/sequence.js +155 -0
- package/dist/core/ordering/sequence.js.map +1 -0
- package/dist/core/registry/adapters.d.ts +10 -0
- package/dist/core/registry/adapters.js +56 -0
- package/dist/core/registry/adapters.js.map +1 -0
- package/dist/core/registry/assets.d.ts +18 -0
- package/dist/core/registry/assets.js +90 -0
- package/dist/core/registry/assets.js.map +1 -0
- package/dist/core/registry/chains.d.ts +10 -0
- package/dist/core/registry/chains.js +80 -0
- package/dist/core/registry/chains.js.map +1 -0
- package/dist/core/registry/plugin.d.ts +41 -0
- package/dist/core/registry/plugin.js +109 -0
- package/dist/core/registry/plugin.js.map +1 -0
- package/dist/core/registry/providers.d.ts +31 -0
- package/dist/core/registry/providers.js +43 -0
- package/dist/core/registry/providers.js.map +1 -0
- package/dist/core/registry/schemes.d.ts +30 -0
- package/dist/core/registry/schemes.js +84 -0
- package/dist/core/registry/schemes.js.map +1 -0
- package/dist/core/secret/fragments.d.ts +33 -0
- package/dist/core/secret/fragments.js +110 -0
- package/dist/core/secret/fragments.js.map +1 -0
- package/dist/core/secret/redact.d.ts +10 -0
- package/dist/core/secret/redact.js +110 -0
- package/dist/core/secret/redact.js.map +1 -0
- package/dist/core/secret/secret.d.ts +14 -0
- package/dist/core/secret/secret.js +42 -0
- package/dist/core/secret/secret.js.map +1 -0
- package/dist/core/signing/callback.d.ts +10 -0
- package/dist/core/signing/callback.js +22 -0
- package/dist/core/signing/callback.js.map +1 -0
- package/dist/core/signing/guard.d.ts +18 -0
- package/dist/core/signing/guard.js +72 -0
- package/dist/core/signing/guard.js.map +1 -0
- package/dist/core/signing/hd.d.ts +36 -0
- package/dist/core/signing/hd.js +167 -0
- package/dist/core/signing/hd.js.map +1 -0
- package/dist/core/signing/local.d.ts +48 -0
- package/dist/core/signing/local.js +190 -0
- package/dist/core/signing/local.js.map +1 -0
- package/dist/core/signing/orchestrator.d.ts +40 -0
- package/dist/core/signing/orchestrator.js +300 -0
- package/dist/core/signing/orchestrator.js.map +1 -0
- package/dist/core/signing/types.d.ts +64 -0
- package/dist/core/signing/types.js +3 -0
- package/dist/core/signing/types.js.map +1 -0
- package/dist/core/signing/wallet.d.ts +48 -0
- package/dist/core/signing/wallet.js +153 -0
- package/dist/core/signing/wallet.js.map +1 -0
- package/dist/core/store/clone.d.ts +25 -0
- package/dist/core/store/clone.js +71 -0
- package/dist/core/store/clone.js.map +1 -0
- package/dist/core/store/memory.d.ts +38 -0
- package/dist/core/store/memory.js +325 -0
- package/dist/core/store/memory.js.map +1 -0
- package/dist/core/store/types.d.ts +246 -0
- package/dist/core/store/types.js +117 -0
- package/dist/core/store/types.js.map +1 -0
- package/dist/core/transport/backoff.d.ts +8 -0
- package/dist/core/transport/backoff.js +27 -0
- package/dist/core/transport/backoff.js.map +1 -0
- package/dist/core/transport/circuit.d.ts +25 -0
- package/dist/core/transport/circuit.js +61 -0
- package/dist/core/transport/circuit.js.map +1 -0
- package/dist/core/transport/http-transport.d.ts +30 -0
- package/dist/core/transport/http-transport.js +1695 -0
- package/dist/core/transport/http-transport.js.map +1 -0
- package/dist/core/transport/rate-limit.d.ts +27 -0
- package/dist/core/transport/rate-limit.js +78 -0
- package/dist/core/transport/rate-limit.js.map +1 -0
- package/dist/core/transport/stale-view.d.ts +11 -0
- package/dist/core/transport/stale-view.js +17 -0
- package/dist/core/transport/stale-view.js.map +1 -0
- package/dist/core/transport/types.d.ts +144 -0
- package/dist/core/transport/types.js +6 -0
- package/dist/core/transport/types.js.map +1 -0
- package/dist/core/util/bytes.d.ts +9 -0
- package/dist/core/util/bytes.js +40 -0
- package/dist/core/util/bytes.js.map +1 -0
- package/dist/core/util/clock.d.ts +6 -0
- package/dist/core/util/clock.js +26 -0
- package/dist/core/util/clock.js.map +1 -0
- package/dist/core/util/freeze.d.ts +8 -0
- package/dist/core/util/freeze.js +31 -0
- package/dist/core/util/freeze.js.map +1 -0
- package/dist/core/util/json.d.ts +29 -0
- package/dist/core/util/json.js +165 -0
- package/dist/core/util/json.js.map +1 -0
- package/dist/core/util/names.d.ts +21 -0
- package/dist/core/util/names.js +46 -0
- package/dist/core/util/names.js.map +1 -0
- package/dist/index.d.ts +64 -14
- package/dist/index.js +105 -49
- package/dist/index.js.map +1 -1
- package/dist/native.d.ts +21 -0
- package/dist/native.js +44 -0
- package/dist/native.js.map +1 -0
- package/dist/testing/contracts/api.d.ts +12 -0
- package/dist/testing/contracts/api.js +58 -0
- package/dist/testing/contracts/api.js.map +1 -0
- package/dist/testing/contracts/cursors.d.ts +6 -0
- package/dist/testing/contracts/cursors.js +43 -0
- package/dist/testing/contracts/cursors.js.map +1 -0
- package/dist/testing/contracts/locks.d.ts +10 -0
- package/dist/testing/contracts/locks.js +63 -0
- package/dist/testing/contracts/locks.js.map +1 -0
- package/dist/testing/contracts/operations.d.ts +21 -0
- package/dist/testing/contracts/operations.js +718 -0
- package/dist/testing/contracts/operations.js.map +1 -0
- package/dist/testing/contracts/sequences.d.ts +6 -0
- package/dist/testing/contracts/sequences.js +68 -0
- package/dist/testing/contracts/sequences.js.map +1 -0
- package/dist/testing/env.d.ts +63 -0
- package/dist/testing/env.js +105 -0
- package/dist/testing/env.js.map +1 -0
- package/dist/testing/fake-chain.d.ts +118 -0
- package/dist/testing/fake-chain.js +536 -0
- package/dist/testing/fake-chain.js.map +1 -0
- package/dist/testing/fake-clock.d.ts +15 -0
- package/dist/testing/fake-clock.js +86 -0
- package/dist/testing/fake-clock.js.map +1 -0
- package/dist/testing/fake-driver.d.ts +15 -0
- package/dist/testing/fake-driver.js +458 -0
- package/dist/testing/fake-driver.js.map +1 -0
- package/dist/testing/fake-fetch.d.ts +32 -0
- package/dist/testing/fake-fetch.js +81 -0
- package/dist/testing/fake-fetch.js.map +1 -0
- package/dist/testing/fake-plugin.d.ts +30 -0
- package/dist/testing/fake-plugin.js +66 -0
- package/dist/testing/fake-plugin.js.map +1 -0
- package/dist/testing/faulty-store.d.ts +36 -0
- package/dist/testing/faulty-store.js +66 -0
- package/dist/testing/faulty-store.js.map +1 -0
- package/dist/testing/generation.d.ts +60 -0
- package/dist/testing/generation.js +252 -0
- package/dist/testing/generation.js.map +1 -0
- package/dist/testing/index.d.ts +28 -0
- package/dist/testing/index.js +51 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +188 -45
- package/dist/libs/eth/account.d.ts +0 -9
- package/dist/libs/eth/account.js +0 -58
- package/dist/libs/eth/account.js.map +0 -1
- package/dist/libs/eth/contract.d.ts +0 -7
- package/dist/libs/eth/contract.js +0 -42
- package/dist/libs/eth/contract.js.map +0 -1
- package/dist/libs/eth/index.d.ts +0 -24
- package/dist/libs/eth/index.js +0 -72
- package/dist/libs/eth/index.js.map +0 -1
- package/dist/libs/eth/transact.d.ts +0 -7
- package/dist/libs/eth/transact.js +0 -26
- package/dist/libs/eth/transact.js.map +0 -1
- package/dist/libs/index.d.ts +0 -2
- package/dist/libs/index.js +0 -19
- package/dist/libs/index.js.map +0 -1
- package/dist/libs/trx/account.d.ts +0 -9
- package/dist/libs/trx/account.js +0 -55
- package/dist/libs/trx/account.js.map +0 -1
- package/dist/libs/trx/contract.d.ts +0 -7
- package/dist/libs/trx/contract.js +0 -27
- package/dist/libs/trx/contract.js.map +0 -1
- package/dist/libs/trx/index.d.ts +0 -22
- package/dist/libs/trx/index.js +0 -64
- package/dist/libs/trx/index.js.map +0 -1
- package/dist/libs/trx/transact.d.ts +0 -7
- package/dist/libs/trx/transact.js +0 -26
- package/dist/libs/trx/transact.js.map +0 -1
- package/dist/tool/common.d.ts +0 -28
- package/dist/tool/common.js +0 -33
- package/dist/tool/common.js.map +0 -1
- package/dist/tool/eth-tools.d.ts +0 -3
- package/dist/tool/eth-tools.js +0 -33
- package/dist/tool/eth-tools.js.map +0 -1
- package/dist/tool/index.d.ts +0 -5
- package/dist/tool/index.js +0 -22
- package/dist/tool/index.js.map +0 -1
- package/dist/tool/logging.d.ts +0 -3
- package/dist/tool/logging.js +0 -11
- package/dist/tool/logging.js.map +0 -1
- package/dist/tool/options.d.ts +0 -6
- package/dist/tool/options.js +0 -41
- package/dist/tool/options.js.map +0 -1
- package/dist/tool/trx-tools.d.ts +0 -3
- package/dist/tool/trx-tools.js +0 -20
- package/dist/tool/trx-tools.js.map +0 -1
- package/dist/type/account.d.ts +0 -9
- package/dist/type/account.js.map +0 -1
- package/dist/type/common.d.ts +0 -18
- package/dist/type/common.js.map +0 -1
- package/dist/type/contract.d.ts +0 -10
- package/dist/type/contract.js.map +0 -1
- package/dist/type/index.d.ts +0 -5
- package/dist/type/index.js +0 -22
- package/dist/type/index.js.map +0 -1
- package/dist/type/lib-types.d.ts +0 -9
- package/dist/type/lib-types.js.map +0 -1
- package/dist/type/transact.d.ts +0 -7
- package/dist/type/transact.js.map +0 -1
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lamportsCharged = exports.MAX_PRICE_VARIANT = exports.VARIANTS = exports.SPEED_PERCENTILE = void 0;
|
|
4
|
+
exports.computeUnitLimitFor = computeUnitLimitFor;
|
|
5
|
+
exports.fallbackComputeUnitLimit = fallbackComputeUnitLimit;
|
|
6
|
+
exports.variantOffsets = variantOffsets;
|
|
7
|
+
exports.speedPrice = speedPrice;
|
|
8
|
+
exports.aboveMaxPrice = aboveMaxPrice;
|
|
9
|
+
exports.variantCounter = variantCounter;
|
|
10
|
+
exports.priorityFee = priorityFee;
|
|
11
|
+
exports.priceForSpeed = priceForSpeed;
|
|
12
|
+
exports.parseOverride = parseOverride;
|
|
13
|
+
exports.feeDraft = feeDraft;
|
|
14
|
+
exports.detailsOf = detailsOf;
|
|
15
|
+
exports.signedFee = signedFee;
|
|
16
|
+
/**
|
|
17
|
+
* The Solana fee policy (base fee plus priority), pure and bigint-only. The
|
|
18
|
+
* priority fee is `ceil(computeUnitPrice × computeUnitLimit / 1_000_000)` lamports, charged
|
|
19
|
+
* on the requested limit (Solana's fee documentation).
|
|
20
|
+
*/
|
|
21
|
+
const error_1 = require("../../core/errors/error");
|
|
22
|
+
const programs_1 = require("./programs");
|
|
23
|
+
const rpc_1 = require("./rpc");
|
|
24
|
+
/** Library policy: the percentile of recent prioritization fees each speed pays. */
|
|
25
|
+
exports.SPEED_PERCENTILE = Object.freeze({
|
|
26
|
+
slow: 25,
|
|
27
|
+
normal: 50,
|
|
28
|
+
fast: 75,
|
|
29
|
+
});
|
|
30
|
+
/** Library policy: the compute-unit limit is the simulated usage plus 20% and 1,000 units. */
|
|
31
|
+
function computeUnitLimitFor(unitsConsumed) {
|
|
32
|
+
const limit = unitsConsumed + unitsConsumed / 5n + 1000n;
|
|
33
|
+
return limit > programs_1.MAX_COMPUTE_UNIT_LIMIT ? programs_1.MAX_COMPUTE_UNIT_LIMIT : limit;
|
|
34
|
+
}
|
|
35
|
+
/** The runtime's own default when a simulation cannot measure the transaction. */
|
|
36
|
+
function fallbackComputeUnitLimit(instructions) {
|
|
37
|
+
const limit = programs_1.DEFAULT_INSTRUCTION_COMPUTE_UNITS * BigInt(instructions);
|
|
38
|
+
return limit > programs_1.MAX_COMPUTE_UNIT_LIMIT ? programs_1.MAX_COMPUTE_UNIT_LIMIT : limit;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Build variants: identical intents built on the same blockhash would
|
|
42
|
+
* sign byte-identical messages, so a second Operation would silently share the first one's
|
|
43
|
+
* signature and one payment would be lost. Each estimate therefore adds a variant to the
|
|
44
|
+
* compute-unit limit (0 to 1,023 units) and, for a speed, to the price (0 to 999
|
|
45
|
+
* micro-lamports): at most about one lamport of priority fee per 1,000 compute units.
|
|
46
|
+
*/
|
|
47
|
+
exports.VARIANTS = 1_024 * 1_000;
|
|
48
|
+
function variantOffsets(variant) {
|
|
49
|
+
return {
|
|
50
|
+
limit: BigInt(variant % 1_024),
|
|
51
|
+
price: BigInt(Math.floor(variant / 1_024) % 1_000),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** The largest price variant a speed adds, in micro-lamports per compute unit. */
|
|
55
|
+
exports.MAX_PRICE_VARIANT = 999n;
|
|
56
|
+
/**
|
|
57
|
+
* A speed's signed price within the handle's `maxComputeUnitPrice`: the node's
|
|
58
|
+
* percentile, at most the bound less the largest variant, plus this build's variant. The
|
|
59
|
+
* signed price never exceeds the bound, and identical transfers still differ at it.
|
|
60
|
+
* The bound is at least `MAX_PRICE_VARIANT` (`solanaNetworkConfig`).
|
|
61
|
+
*/
|
|
62
|
+
function speedPrice(percentile, variant, maxComputeUnitPrice) {
|
|
63
|
+
const ceiling = maxComputeUnitPrice - exports.MAX_PRICE_VARIANT;
|
|
64
|
+
return (percentile < ceiling ? percentile : ceiling) + variant;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* An explicit price above the handle's bound, refused before anything is signed. The details
|
|
68
|
+
* carry the price and the bound (decimal strings), so the caller sees what to allow.
|
|
69
|
+
*/
|
|
70
|
+
function aboveMaxPrice(price, maxComputeUnitPrice) {
|
|
71
|
+
return new error_1.ValidationError('INVALID_INTENT', 'computeUnitPrice is above maxComputeUnitPrice, the Solana handle option that bounds it (micro-lamports per compute unit)', {
|
|
72
|
+
details: {
|
|
73
|
+
required: price.toString(),
|
|
74
|
+
maxComputeUnitPrice: maxComputeUnitPrice.toString(),
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The highest recent price a speed pays: the u64 range less the largest price variant
|
|
80
|
+
* (999), so the varied price still fits its u64 field.
|
|
81
|
+
*/
|
|
82
|
+
const MAX_RECENT_PRICE = 2n ** 64n - 1n - 999n;
|
|
83
|
+
/** A per-driver counter from a random start: distinct in-process, rare across processes. */
|
|
84
|
+
function variantCounter(start) {
|
|
85
|
+
let next = start % exports.VARIANTS;
|
|
86
|
+
return () => {
|
|
87
|
+
const variant = next;
|
|
88
|
+
next = (next + 1) % exports.VARIANTS;
|
|
89
|
+
return variant;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function priorityFee(computeUnitPrice, computeUnitLimit) {
|
|
93
|
+
return (computeUnitPrice * computeUnitLimit + 999999n) / 1000000n;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The nearest-rank percentile of `getRecentPrioritizationFees` answers (micro-lamports per
|
|
97
|
+
* compute unit); `0n` when the node reports none. A malformed entry, including one outside
|
|
98
|
+
* the u64 range or without room for the price variant, is a retryable
|
|
99
|
+
* `PROVIDER_UNAVAILABLE`.
|
|
100
|
+
*/
|
|
101
|
+
function priceForSpeed(recent, speed) {
|
|
102
|
+
if (!Array.isArray(recent))
|
|
103
|
+
throw (0, rpc_1.malformed)('getRecentPrioritizationFees');
|
|
104
|
+
const fees = recent.map((entry) => {
|
|
105
|
+
const fee = (0, rpc_1.u64)(entry?.prioritizationFee, 'getRecentPrioritizationFees');
|
|
106
|
+
if (fee > MAX_RECENT_PRICE)
|
|
107
|
+
throw (0, rpc_1.malformed)('getRecentPrioritizationFees');
|
|
108
|
+
return fee;
|
|
109
|
+
});
|
|
110
|
+
if (fees.length === 0)
|
|
111
|
+
return 0n;
|
|
112
|
+
fees.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
113
|
+
const rank = Math.ceil((exports.SPEED_PERCENTILE[speed] / 100) * fees.length);
|
|
114
|
+
return fees[Math.max(0, rank - 1)];
|
|
115
|
+
}
|
|
116
|
+
/** A validated `SolanaFeeOverride`; anything else is `INVALID_INTENT`. */
|
|
117
|
+
function parseOverride(fee) {
|
|
118
|
+
const invalid = (reason) => new error_1.ValidationError('INVALID_INTENT', `Solana fee override: ${reason}`);
|
|
119
|
+
const keys = Object.keys(fee);
|
|
120
|
+
if (keys.some((key) => key !== 'computeUnitPrice' && key !== 'computeUnitLimit')) {
|
|
121
|
+
throw invalid('only computeUnitPrice and computeUnitLimit are allowed');
|
|
122
|
+
}
|
|
123
|
+
const { computeUnitPrice, computeUnitLimit } = fee;
|
|
124
|
+
if (typeof computeUnitPrice !== 'bigint' ||
|
|
125
|
+
computeUnitPrice < 0n ||
|
|
126
|
+
computeUnitPrice >= 2n ** 64n) {
|
|
127
|
+
throw invalid('computeUnitPrice must be a bigint of micro-lamports in the u64 range');
|
|
128
|
+
}
|
|
129
|
+
if (computeUnitLimit !== undefined &&
|
|
130
|
+
(typeof computeUnitLimit !== 'bigint' ||
|
|
131
|
+
computeUnitLimit < 1n ||
|
|
132
|
+
computeUnitLimit > programs_1.MAX_COMPUTE_UNIT_LIMIT)) {
|
|
133
|
+
throw invalid('computeUnitLimit must be a bigint from 1 to 1,400,000');
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
computeUnitPrice,
|
|
137
|
+
...(computeUnitLimit !== undefined ? { computeUnitLimit } : {}),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The fee draft: `network` (the signature fee), `priority` and, when the recipient's token
|
|
142
|
+
* account is created, `rent`. The bound is `exact` unless rent is charged: that deposit is
|
|
143
|
+
* skipped when someone else creates the account first, so it is an upper bound.
|
|
144
|
+
*/
|
|
145
|
+
function feeDraft(speed, details) {
|
|
146
|
+
const charges = [
|
|
147
|
+
{ asset: 'native', amount: details.baseFee, label: 'network' },
|
|
148
|
+
{ asset: 'native', amount: details.priorityFee, label: 'priority' },
|
|
149
|
+
];
|
|
150
|
+
if (details.createsRecipientAccount) {
|
|
151
|
+
charges.push({ asset: 'native', amount: details.rent, label: 'rent' });
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
kind: 'solana',
|
|
155
|
+
speed,
|
|
156
|
+
charges,
|
|
157
|
+
bound: details.createsRecipientAccount ? 'upper' : 'exact',
|
|
158
|
+
details: { ...details },
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/** The `SolanaFeeDetails` of a draft this driver made; anything else is `INVALID_INTENT`. */
|
|
162
|
+
function detailsOf(fee) {
|
|
163
|
+
const d = fee.details;
|
|
164
|
+
if (fee.kind !== 'solana' ||
|
|
165
|
+
typeof d.computeUnitLimit !== 'bigint' ||
|
|
166
|
+
typeof d.computeUnitPrice !== 'bigint' ||
|
|
167
|
+
typeof d.baseFee !== 'bigint' ||
|
|
168
|
+
typeof d.priorityFee !== 'bigint' ||
|
|
169
|
+
typeof d.rent !== 'bigint' ||
|
|
170
|
+
typeof d.signatures !== 'number' ||
|
|
171
|
+
typeof d.createsRecipientAccount !== 'boolean') {
|
|
172
|
+
throw new error_1.ValidationError('INVALID_INTENT', 'not a Solana fee estimate');
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
signatures: d.signatures,
|
|
176
|
+
baseFee: d.baseFee,
|
|
177
|
+
computeUnitLimit: d.computeUnitLimit,
|
|
178
|
+
computeUnitPrice: d.computeUnitPrice,
|
|
179
|
+
priorityFee: d.priorityFee,
|
|
180
|
+
rent: d.rent,
|
|
181
|
+
createsRecipientAccount: d.createsRecipientAccount,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* The compute budget `build` signs, checked wherever the estimate
|
|
186
|
+
* came from (the store, `prepareTransfer`, a caller): the price within the handle's bound,
|
|
187
|
+
* the limit within the protocol's, and the priority fee exactly the one that budget costs.
|
|
188
|
+
*/
|
|
189
|
+
function signedFee(fee, maxComputeUnitPrice) {
|
|
190
|
+
const details = detailsOf(fee);
|
|
191
|
+
const { computeUnitPrice: price, computeUnitLimit: limit } = details;
|
|
192
|
+
if (price > maxComputeUnitPrice)
|
|
193
|
+
throw aboveMaxPrice(price, maxComputeUnitPrice);
|
|
194
|
+
if (price < 0n ||
|
|
195
|
+
limit < 1n ||
|
|
196
|
+
limit > programs_1.MAX_COMPUTE_UNIT_LIMIT ||
|
|
197
|
+
details.priorityFee !== priorityFee(price, limit)) {
|
|
198
|
+
throw new error_1.ValidationError('INVALID_INTENT', 'the fee estimate is not consistent with its own compute budget');
|
|
199
|
+
}
|
|
200
|
+
return details;
|
|
201
|
+
}
|
|
202
|
+
/** The lamports every fee charge of `fee` adds up to. */
|
|
203
|
+
const lamportsCharged = (fee) => fee.charges.reduce((sum, charge) => sum + charge.amount, 0n);
|
|
204
|
+
exports.lamportsCharged = lamportsCharged;
|
|
205
|
+
//# sourceMappingURL=fees.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fees.js","sourceRoot":"","sources":["../../../src/adapters/solana/fees.ts"],"names":[],"mappings":";;;AAwBA,kDAGC;AAGD,4DAGC;AAWD,wCAQC;AAWD,gCAOC;AAMD,sCAcC;AASD,wCAOC;AAED,kCAEC;AAQD,sCAcC;AAGD,sCA2BC;AAOD,4BAkBC;AAGD,8BAuBC;AAOD,8BAmBC;AA/OD;;;;GAIG;AACH,mDAA0D;AAO1D,yCAAuF;AACvF,+BAAuC;AAGvC,oFAAoF;AACvE,QAAA,gBAAgB,GAAuC,MAAM,CAAC,MAAM,CAAC;IAChF,IAAI,EAAE,EAAE;IACR,MAAM,EAAE,EAAE;IACV,IAAI,EAAE,EAAE;CACT,CAAC,CAAC;AAEH,8FAA8F;AAC9F,SAAgB,mBAAmB,CAAC,aAAqB;IACvD,MAAM,KAAK,GAAG,aAAa,GAAG,aAAa,GAAG,EAAE,GAAG,KAAM,CAAC;IAC1D,OAAO,KAAK,GAAG,iCAAsB,CAAC,CAAC,CAAC,iCAAsB,CAAC,CAAC,CAAC,KAAK,CAAC;AACzE,CAAC;AAED,kFAAkF;AAClF,SAAgB,wBAAwB,CAAC,YAAoB;IAC3D,MAAM,KAAK,GAAG,4CAAiC,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;IACvE,OAAO,KAAK,GAAG,iCAAsB,CAAC,CAAC,CAAC,iCAAsB,CAAC,CAAC,CAAC,KAAK,CAAC;AACzE,CAAC;AAED;;;;;;GAMG;AACU,QAAA,QAAQ,GAAG,KAAK,GAAG,KAAK,CAAC;AAEtC,SAAgB,cAAc,CAAC,OAAe;IAI5C,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC;QAC9B,KAAK,EAAE,MAAM,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IACrE,IAAI,KAAK,GAAG,mBAAmB;QAAE,MAAM,aAAa,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;IACjF,IACE,KAAK,GAAG,EAAE;QACV,KAAK,GAAG,EAAE;QACV,KAAK,GAAG,iCAAsB;QAC9B,OAAO,CAAC,WAAW,KAAK,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,EACjD,CAAC;QACD,MAAM,IAAI,uBAAe,CACvB,gBAAgB,EAChB,gEAAgE,CACjE,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,yDAAyD;AAClD,MAAM,eAAe,GAAG,CAAC,GAAqB,EAAU,EAAE,CAC/D,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AADlD,QAAA,eAAe,mBACmC","sourcesContent":["/**\n * The Solana fee policy (base fee plus priority), pure and bigint-only. The\n * priority fee is `ceil(computeUnitPrice × computeUnitLimit / 1_000_000)` lamports, charged\n * on the requested limit (Solana's fee documentation).\n */\nimport { ValidationError } from '../../core/errors/error';\nimport type {\n FeeChargeDraft,\n FeeEstimateDraft,\n FeeOverride,\n FeeSpeed,\n} from '../../core/model/fee';\nimport { DEFAULT_INSTRUCTION_COMPUTE_UNITS, MAX_COMPUTE_UNIT_LIMIT } from './programs';\nimport { malformed, u64 } from './rpc';\nimport type { SolanaFeeDetails, SolanaFeeOverride } from './types';\n\n/** Library policy: the percentile of recent prioritization fees each speed pays. */\nexport const SPEED_PERCENTILE: Readonly<Record<FeeSpeed, number>> = Object.freeze({\n slow: 25,\n normal: 50,\n fast: 75,\n});\n\n/** Library policy: the compute-unit limit is the simulated usage plus 20% and 1,000 units. */\nexport function computeUnitLimitFor(unitsConsumed: bigint): bigint {\n const limit = unitsConsumed + unitsConsumed / 5n + 1_000n;\n return limit > MAX_COMPUTE_UNIT_LIMIT ? MAX_COMPUTE_UNIT_LIMIT : limit;\n}\n\n/** The runtime's own default when a simulation cannot measure the transaction. */\nexport function fallbackComputeUnitLimit(instructions: number): bigint {\n const limit = DEFAULT_INSTRUCTION_COMPUTE_UNITS * BigInt(instructions);\n return limit > MAX_COMPUTE_UNIT_LIMIT ? MAX_COMPUTE_UNIT_LIMIT : limit;\n}\n\n/**\n * Build variants: identical intents built on the same blockhash would\n * sign byte-identical messages, so a second Operation would silently share the first one's\n * signature and one payment would be lost. Each estimate therefore adds a variant to the\n * compute-unit limit (0 to 1,023 units) and, for a speed, to the price (0 to 999\n * micro-lamports): at most about one lamport of priority fee per 1,000 compute units.\n */\nexport const VARIANTS = 1_024 * 1_000;\n\nexport function variantOffsets(variant: number): {\n readonly limit: bigint;\n readonly price: bigint;\n} {\n return {\n limit: BigInt(variant % 1_024),\n price: BigInt(Math.floor(variant / 1_024) % 1_000),\n };\n}\n\n/** The largest price variant a speed adds, in micro-lamports per compute unit. */\nexport const MAX_PRICE_VARIANT = 999n;\n\n/**\n * A speed's signed price within the handle's `maxComputeUnitPrice`: the node's\n * percentile, at most the bound less the largest variant, plus this build's variant. The\n * signed price never exceeds the bound, and identical transfers still differ at it.\n * The bound is at least `MAX_PRICE_VARIANT` (`solanaNetworkConfig`).\n */\nexport function speedPrice(\n percentile: bigint,\n variant: bigint,\n maxComputeUnitPrice: bigint,\n): bigint {\n const ceiling = maxComputeUnitPrice - MAX_PRICE_VARIANT;\n return (percentile < ceiling ? percentile : ceiling) + variant;\n}\n\n/**\n * An explicit price above the handle's bound, refused before anything is signed. The details\n * carry the price and the bound (decimal strings), so the caller sees what to allow.\n */\nexport function aboveMaxPrice(\n price: bigint,\n maxComputeUnitPrice: bigint,\n): ValidationError {\n return new ValidationError(\n 'INVALID_INTENT',\n 'computeUnitPrice is above maxComputeUnitPrice, the Solana handle option that bounds it (micro-lamports per compute unit)',\n {\n details: {\n required: price.toString(),\n maxComputeUnitPrice: maxComputeUnitPrice.toString(),\n },\n },\n );\n}\n\n/**\n * The highest recent price a speed pays: the u64 range less the largest price variant\n * (999), so the varied price still fits its u64 field.\n */\nconst MAX_RECENT_PRICE = 2n ** 64n - 1n - 999n;\n\n/** A per-driver counter from a random start: distinct in-process, rare across processes. */\nexport function variantCounter(start: number): () => number {\n let next = start % VARIANTS;\n return () => {\n const variant = next;\n next = (next + 1) % VARIANTS;\n return variant;\n };\n}\n\nexport function priorityFee(computeUnitPrice: bigint, computeUnitLimit: bigint): bigint {\n return (computeUnitPrice * computeUnitLimit + 999_999n) / 1_000_000n;\n}\n\n/**\n * The nearest-rank percentile of `getRecentPrioritizationFees` answers (micro-lamports per\n * compute unit); `0n` when the node reports none. A malformed entry, including one outside\n * the u64 range or without room for the price variant, is a retryable\n * `PROVIDER_UNAVAILABLE`.\n */\nexport function priceForSpeed(recent: unknown, speed: FeeSpeed): bigint {\n if (!Array.isArray(recent)) throw malformed('getRecentPrioritizationFees');\n const fees = recent.map((entry: unknown) => {\n const fee = u64(\n (entry as { prioritizationFee?: unknown } | null)?.prioritizationFee,\n 'getRecentPrioritizationFees',\n );\n if (fee > MAX_RECENT_PRICE) throw malformed('getRecentPrioritizationFees');\n return fee;\n });\n if (fees.length === 0) return 0n;\n fees.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));\n const rank = Math.ceil((SPEED_PERCENTILE[speed] / 100) * fees.length);\n return fees[Math.max(0, rank - 1)] as bigint;\n}\n\n/** A validated `SolanaFeeOverride`; anything else is `INVALID_INTENT`. */\nexport function parseOverride(fee: FeeOverride): SolanaFeeOverride {\n const invalid = (reason: string) =>\n new ValidationError('INVALID_INTENT', `Solana fee override: ${reason}`);\n const keys = Object.keys(fee);\n if (keys.some((key) => key !== 'computeUnitPrice' && key !== 'computeUnitLimit')) {\n throw invalid('only computeUnitPrice and computeUnitLimit are allowed');\n }\n const { computeUnitPrice, computeUnitLimit } = fee;\n if (\n typeof computeUnitPrice !== 'bigint' ||\n computeUnitPrice < 0n ||\n computeUnitPrice >= 2n ** 64n\n ) {\n throw invalid('computeUnitPrice must be a bigint of micro-lamports in the u64 range');\n }\n if (\n computeUnitLimit !== undefined &&\n (typeof computeUnitLimit !== 'bigint' ||\n computeUnitLimit < 1n ||\n computeUnitLimit > MAX_COMPUTE_UNIT_LIMIT)\n ) {\n throw invalid('computeUnitLimit must be a bigint from 1 to 1,400,000');\n }\n return {\n computeUnitPrice,\n ...(computeUnitLimit !== undefined ? { computeUnitLimit } : {}),\n };\n}\n\n/**\n * The fee draft: `network` (the signature fee), `priority` and, when the recipient's token\n * account is created, `rent`. The bound is `exact` unless rent is charged: that deposit is\n * skipped when someone else creates the account first, so it is an upper bound.\n */\nexport function feeDraft(\n speed: FeeSpeed | 'custom',\n details: SolanaFeeDetails,\n): FeeEstimateDraft {\n const charges: FeeChargeDraft[] = [\n { asset: 'native', amount: details.baseFee, label: 'network' },\n { asset: 'native', amount: details.priorityFee, label: 'priority' },\n ];\n if (details.createsRecipientAccount) {\n charges.push({ asset: 'native', amount: details.rent, label: 'rent' });\n }\n return {\n kind: 'solana',\n speed,\n charges,\n bound: details.createsRecipientAccount ? 'upper' : 'exact',\n details: { ...details },\n };\n}\n\n/** The `SolanaFeeDetails` of a draft this driver made; anything else is `INVALID_INTENT`. */\nexport function detailsOf(fee: FeeEstimateDraft): SolanaFeeDetails {\n const d = fee.details as Partial<SolanaFeeDetails>;\n if (\n fee.kind !== 'solana' ||\n typeof d.computeUnitLimit !== 'bigint' ||\n typeof d.computeUnitPrice !== 'bigint' ||\n typeof d.baseFee !== 'bigint' ||\n typeof d.priorityFee !== 'bigint' ||\n typeof d.rent !== 'bigint' ||\n typeof d.signatures !== 'number' ||\n typeof d.createsRecipientAccount !== 'boolean'\n ) {\n throw new ValidationError('INVALID_INTENT', 'not a Solana fee estimate');\n }\n return {\n signatures: d.signatures,\n baseFee: d.baseFee,\n computeUnitLimit: d.computeUnitLimit,\n computeUnitPrice: d.computeUnitPrice,\n priorityFee: d.priorityFee,\n rent: d.rent,\n createsRecipientAccount: d.createsRecipientAccount,\n };\n}\n\n/**\n * The compute budget `build` signs, checked wherever the estimate\n * came from (the store, `prepareTransfer`, a caller): the price within the handle's bound,\n * the limit within the protocol's, and the priority fee exactly the one that budget costs.\n */\nexport function signedFee(\n fee: FeeEstimateDraft,\n maxComputeUnitPrice: bigint,\n): SolanaFeeDetails {\n const details = detailsOf(fee);\n const { computeUnitPrice: price, computeUnitLimit: limit } = details;\n if (price > maxComputeUnitPrice) throw aboveMaxPrice(price, maxComputeUnitPrice);\n if (\n price < 0n ||\n limit < 1n ||\n limit > MAX_COMPUTE_UNIT_LIMIT ||\n details.priorityFee !== priorityFee(price, limit)\n ) {\n throw new ValidationError(\n 'INVALID_INTENT',\n 'the fee estimate is not consistent with its own compute budget',\n );\n }\n return details;\n}\n\n/** The lamports every fee charge of `fee` adds up to. */\nexport const lamportsCharged = (fee: FeeEstimateDraft): bigint =>\n fee.charges.reduce((sum, charge) => sum + charge.amount, 0n);\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dense block heights over Solana's slots: the core's heights must be dense, so they are
|
|
3
|
+
* block heights, never slots. Slots can be skipped; block heights count only produced
|
|
4
|
+
* blocks, so every height up to the head has exactly one block. The index maps a height
|
|
5
|
+
* to its slot with `getBlocks`, which lists the produced slots of a range: anchored on a
|
|
6
|
+
* known block at the head, the block `k` places before it in that list is `k` heights
|
|
7
|
+
* lower.
|
|
8
|
+
*
|
|
9
|
+
* A list can have gaps (a ledger jump to a snapshot, a long-term-storage gap, pruning), so
|
|
10
|
+
* no pair is believed until a read of the list's first block confirms its height. Only
|
|
11
|
+
* finalized, verified pairs are cached (immutable chain data, the only state a shared
|
|
12
|
+
* driver may keep), which makes a forward scan cost one `getBlock` per height. A height
|
|
13
|
+
* the endpoint no longer holds is a retryable error that decides nothing, never `null`
|
|
14
|
+
* (`null` means "not visible yet"). Every read is a single endpoint's view: verdicts
|
|
15
|
+
* quorum-read the block at the resolved slot. Any other RPC error decides nothing either:
|
|
16
|
+
* proofs reach this index, and agave answers `getBlocks` below its local ledger with
|
|
17
|
+
* `-32602 "BigTable query failed"` when long-term storage fails. Such a page starts again
|
|
18
|
+
* at the endpoint's first available block (liveness), so a height inside its ledger still
|
|
19
|
+
* resolves.
|
|
20
|
+
*/
|
|
21
|
+
import type { Transport } from '../../core/transport/types';
|
|
22
|
+
import { type BlockHeader } from './rpc';
|
|
23
|
+
import type { Commitment, SolanaCallTags } from './types';
|
|
24
|
+
export interface HeadBlock {
|
|
25
|
+
readonly slot: bigint;
|
|
26
|
+
readonly header: BlockHeader;
|
|
27
|
+
}
|
|
28
|
+
export declare class HeightIndex {
|
|
29
|
+
#private;
|
|
30
|
+
constructor(transport: Transport);
|
|
31
|
+
/** The block at the endpoint's `commitment` head (one `getSlot`, one `getBlock`). */
|
|
32
|
+
head(commitment: Commitment, tags: SolanaCallTags): Promise<HeadBlock>;
|
|
33
|
+
/**
|
|
34
|
+
* The block at `slot`, or `null` while the endpoint has not reached it at `commitment`.
|
|
35
|
+
* A pruned or missing block is a retryable error (decides nothing); a slot the endpoint
|
|
36
|
+
* calls skipped means a list named a slot with no block, so the cache is dropped.
|
|
37
|
+
*/
|
|
38
|
+
header(slot: bigint, commitment: Commitment, tags: SolanaCallTags): Promise<BlockHeader | null>;
|
|
39
|
+
/**
|
|
40
|
+
* The slot of the block at `height` on the endpoint's chain at `commitment`, or `null`
|
|
41
|
+
* while that chain has no block at `height` yet. A `confirmed` lookup at or below the
|
|
42
|
+
* endpoint's finalized height resolves on the finalized chain, which fills the cache.
|
|
43
|
+
*/
|
|
44
|
+
slotAt(height: bigint, commitment: Commitment, tags: SolanaCallTags): Promise<bigint | null>;
|
|
45
|
+
/** Drops every cached pair: a later read contradicted one (cheap to rebuild). */
|
|
46
|
+
forget(): void;
|
|
47
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HeightIndex = void 0;
|
|
4
|
+
const rpc_1 = require("./rpc");
|
|
5
|
+
/** `getBlocks` accepts at most this many slots per call (agave). */
|
|
6
|
+
const MAX_RANGE = 500000n;
|
|
7
|
+
/** At most this many `getBlocks` pages below the head (about 8 M slots). */
|
|
8
|
+
const MAX_PAGES = 16;
|
|
9
|
+
/** Verified finalized height → slot pairs kept per driver. */
|
|
10
|
+
const CACHE_SIZE = 8_192;
|
|
11
|
+
class HeightIndex {
|
|
12
|
+
#transport;
|
|
13
|
+
#final = new Map();
|
|
14
|
+
constructor(transport) {
|
|
15
|
+
this.#transport = transport;
|
|
16
|
+
}
|
|
17
|
+
/** The block at the endpoint's `commitment` head (one `getSlot`, one `getBlock`). */
|
|
18
|
+
async head(commitment, tags) {
|
|
19
|
+
const slot = (0, rpc_1.u64)(await (0, rpc_1.call)(this.#transport, 'getSlot', [{ commitment }], tags), 'getSlot');
|
|
20
|
+
const header = await this.header(slot, commitment, tags);
|
|
21
|
+
if (!header)
|
|
22
|
+
throw (0, rpc_1.notYet)(`the ${commitment} head block`);
|
|
23
|
+
return { slot, header };
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The block at `slot`, or `null` while the endpoint has not reached it at `commitment`.
|
|
27
|
+
* A pruned or missing block is a retryable error (decides nothing); a slot the endpoint
|
|
28
|
+
* calls skipped means a list named a slot with no block, so the cache is dropped.
|
|
29
|
+
*/
|
|
30
|
+
async header(slot, commitment, tags) {
|
|
31
|
+
let result;
|
|
32
|
+
try {
|
|
33
|
+
result = await (0, rpc_1.call)(this.#transport, 'getBlock', [Number(slot), (0, rpc_1.headerOptions)(commitment)], tags);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if ((0, rpc_1.isNotYet)(error))
|
|
37
|
+
return null;
|
|
38
|
+
if ((0, rpc_1.isGone)(error))
|
|
39
|
+
throw (0, rpc_1.gone)(`the block at slot ${slot}`);
|
|
40
|
+
if ((0, rpc_1.isSkipped)(error)) {
|
|
41
|
+
this.forget();
|
|
42
|
+
throw (0, rpc_1.inconsistent)(`slot ${slot} holds no block`);
|
|
43
|
+
}
|
|
44
|
+
throw (0, rpc_1.undecided)(error, `the block at slot ${slot}`);
|
|
45
|
+
}
|
|
46
|
+
return result === null ? null : (0, rpc_1.blockHeader)(result);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The slot of the block at `height` on the endpoint's chain at `commitment`, or `null`
|
|
50
|
+
* while that chain has no block at `height` yet. A `confirmed` lookup at or below the
|
|
51
|
+
* endpoint's finalized height resolves on the finalized chain, which fills the cache.
|
|
52
|
+
*/
|
|
53
|
+
async slotAt(height, commitment, tags) {
|
|
54
|
+
if (height < 0n)
|
|
55
|
+
return null;
|
|
56
|
+
const cached = this.#final.get(height);
|
|
57
|
+
if (cached !== undefined)
|
|
58
|
+
return cached;
|
|
59
|
+
const final = await this.head('finalized', tags);
|
|
60
|
+
if (height <= final.header.blockHeight) {
|
|
61
|
+
return this.#resolve(height, final, 'finalized', tags);
|
|
62
|
+
}
|
|
63
|
+
if (commitment === 'finalized')
|
|
64
|
+
return null;
|
|
65
|
+
const top = await this.head('confirmed', tags);
|
|
66
|
+
if (height > top.header.blockHeight)
|
|
67
|
+
return null;
|
|
68
|
+
return this.#resolve(height, top, 'confirmed', tags);
|
|
69
|
+
}
|
|
70
|
+
/** Counts back from `top` through verified `getBlocks` pages to the block at `height`. */
|
|
71
|
+
async #resolve(height, top, commitment, tags) {
|
|
72
|
+
let anchorSlot = top.slot;
|
|
73
|
+
let anchorHeight = top.header.blockHeight;
|
|
74
|
+
if (height === anchorHeight)
|
|
75
|
+
return anchorSlot;
|
|
76
|
+
let span = anchorHeight - height + (anchorHeight - height) / 4n + 64n;
|
|
77
|
+
for (let page = 0; page < MAX_PAGES; page++) {
|
|
78
|
+
if (span > MAX_RANGE)
|
|
79
|
+
span = MAX_RANGE;
|
|
80
|
+
const want = anchorSlot > span ? anchorSlot - span : 0n;
|
|
81
|
+
const { from, slots } = await this.#page(want, anchorSlot, commitment, tags);
|
|
82
|
+
const last = slots.length - 1;
|
|
83
|
+
// agave lists nothing when the range ends above what the endpoint holds at
|
|
84
|
+
// `commitment` (a backend whose root trails the anchor): that list ends nowhere.
|
|
85
|
+
if (last < 0 || slots[last] !== anchorSlot) {
|
|
86
|
+
throw (0, rpc_1.inconsistent)(`getBlocks does not end at slot ${anchorSlot}`);
|
|
87
|
+
}
|
|
88
|
+
// A list that adds nothing below its anchor: the endpoint holds nothing older.
|
|
89
|
+
if (last === 0)
|
|
90
|
+
throw (0, rpc_1.gone)(`the block at height ${height}`);
|
|
91
|
+
// The list's first block must sit exactly `last` heights below the anchor, or
|
|
92
|
+
// the list has a gap; nothing from it is believed or cached.
|
|
93
|
+
const firstHeight = anchorHeight - BigInt(last);
|
|
94
|
+
const first = await this.header(slots[0], commitment, tags);
|
|
95
|
+
if (!first)
|
|
96
|
+
throw (0, rpc_1.notYet)(`the block at slot ${slots[0]}`);
|
|
97
|
+
if (first.blockHeight !== firstHeight) {
|
|
98
|
+
throw (0, rpc_1.inconsistent)(`the blocks listed below slot ${anchorSlot} have a gap`);
|
|
99
|
+
}
|
|
100
|
+
slots.forEach((slot, i) => {
|
|
101
|
+
const at = firstHeight + BigInt(i);
|
|
102
|
+
// Keep the pairs a forward scan from `height` needs next.
|
|
103
|
+
if (at >= height && at < height + BigInt(CACHE_SIZE)) {
|
|
104
|
+
this.#remember(commitment, at, slot);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
if (height >= firstHeight)
|
|
108
|
+
return slots[Number(height - firstHeight)];
|
|
109
|
+
// The list started at slot 0, or at the endpoint's first available block.
|
|
110
|
+
if (from === 0n || from > want)
|
|
111
|
+
throw (0, rpc_1.gone)(`the block at height ${height}`);
|
|
112
|
+
anchorHeight = firstHeight;
|
|
113
|
+
anchorSlot = slots[0];
|
|
114
|
+
span *= 2n;
|
|
115
|
+
}
|
|
116
|
+
throw (0, rpc_1.gone)(`the block at height ${height} (too far below the head)`);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* One verified-shape page of produced slots from `from` to `to`, and where it starts.
|
|
120
|
+
* When the endpoint cannot list from `from` (a definitive RPC error with a JSON-RPC
|
|
121
|
+
* code: agave answers `-32602 "BigTable query failed"` below its local ledger when
|
|
122
|
+
* long-term storage fails), the page starts once more at the endpoint's first available
|
|
123
|
+
* block, when that lies inside the range (liveness only). Every other error, and a
|
|
124
|
+
* second failure, decides nothing.
|
|
125
|
+
*/
|
|
126
|
+
async #page(from, to, commitment, tags) {
|
|
127
|
+
try {
|
|
128
|
+
return { from, slots: await this.#blocks(from, to, commitment, tags) };
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
// Only an endpoint's own definitive answer: an ambiguous error, or one without a
|
|
132
|
+
// JSON-RPC code, says nothing about what this endpoint can list.
|
|
133
|
+
const first = (0, rpc_1.rpcCode)(error) === undefined ? null : await this.#firstAvailable(tags);
|
|
134
|
+
if (first === null || first <= from || first > to) {
|
|
135
|
+
throw (0, rpc_1.undecided)(error, `the blocks from slot ${from}`);
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
return { from: first, slots: await this.#blocks(first, to, commitment, tags) };
|
|
139
|
+
}
|
|
140
|
+
catch (retry) {
|
|
141
|
+
throw (0, rpc_1.undecided)(retry, `the blocks from slot ${first}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/** The endpoint's first available block: a hint only, `null` when it cannot say. */
|
|
146
|
+
async #firstAvailable(tags) {
|
|
147
|
+
try {
|
|
148
|
+
return (0, rpc_1.u64)(await (0, rpc_1.call)(this.#transport, 'getFirstAvailableBlock', [], tags), 'getFirstAvailableBlock');
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
if (tags.signal?.aborted)
|
|
152
|
+
throw error;
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/** `getBlocks` from `from` to `to`: strictly increasing slots inside the range. */
|
|
157
|
+
async #blocks(from, to, commitment, tags) {
|
|
158
|
+
const result = await (0, rpc_1.call)(this.#transport, 'getBlocks', [Number(from), Number(to), { commitment }], tags);
|
|
159
|
+
if (!Array.isArray(result))
|
|
160
|
+
throw (0, rpc_1.malformed)('getBlocks');
|
|
161
|
+
const slots = result.map((slot) => (0, rpc_1.u64)(slot, 'getBlocks slot'));
|
|
162
|
+
for (let i = 0; i < slots.length; i++) {
|
|
163
|
+
const slot = slots[i];
|
|
164
|
+
if (slot < from || slot > to || (i > 0 && slot <= slots[i - 1])) {
|
|
165
|
+
throw (0, rpc_1.malformed)('getBlocks');
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return slots;
|
|
169
|
+
}
|
|
170
|
+
/** Drops every cached pair: a later read contradicted one (cheap to rebuild). */
|
|
171
|
+
forget() {
|
|
172
|
+
this.#final.clear();
|
|
173
|
+
}
|
|
174
|
+
#remember(commitment, height, slot) {
|
|
175
|
+
if (commitment !== 'finalized' || this.#final.has(height))
|
|
176
|
+
return;
|
|
177
|
+
this.#final.set(height, slot);
|
|
178
|
+
if (this.#final.size > CACHE_SIZE) {
|
|
179
|
+
const oldest = this.#final.keys().next().value;
|
|
180
|
+
this.#final.delete(oldest);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.HeightIndex = HeightIndex;
|
|
185
|
+
//# sourceMappingURL=heights.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heights.js","sourceRoot":"","sources":["../../../src/adapters/solana/heights.ts"],"names":[],"mappings":";;;AAqBA,+BAee;AAGf,oEAAoE;AACpE,MAAM,SAAS,GAAG,OAAQ,CAAC;AAC3B,4EAA4E;AAC5E,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,8DAA8D;AAC9D,MAAM,UAAU,GAAG,KAAK,CAAC;AAOzB,MAAa,WAAW;IACb,UAAU,CAAY;IAC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Ae,CAAC;YACzD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;CACF;AA1MD,kCA0MC","sourcesContent":["/**\n * Dense block heights over Solana's slots: the core's heights must be dense, so they are\n * block heights, never slots. Slots can be skipped; block heights count only produced\n * blocks, so every height up to the head has exactly one block. The index maps a height\n * to its slot with `getBlocks`, which lists the produced slots of a range: anchored on a\n * known block at the head, the block `k` places before it in that list is `k` heights\n * lower.\n *\n * A list can have gaps (a ledger jump to a snapshot, a long-term-storage gap, pruning), so\n * no pair is believed until a read of the list's first block confirms its height. Only\n * finalized, verified pairs are cached (immutable chain data, the only state a shared\n * driver may keep), which makes a forward scan cost one `getBlock` per height. A height\n * the endpoint no longer holds is a retryable error that decides nothing, never `null`\n * (`null` means \"not visible yet\"). Every read is a single endpoint's view: verdicts\n * quorum-read the block at the resolved slot. Any other RPC error decides nothing either:\n * proofs reach this index, and agave answers `getBlocks` below its local ledger with\n * `-32602 \"BigTable query failed\"` when long-term storage fails. Such a page starts again\n * at the endpoint's first available block (liveness), so a height inside its ledger still\n * resolves.\n */\nimport type { Transport } from '../../core/transport/types';\nimport {\n blockHeader,\n call,\n gone,\n headerOptions,\n inconsistent,\n isGone,\n isNotYet,\n isSkipped,\n malformed,\n notYet,\n rpcCode,\n u64,\n undecided,\n type BlockHeader,\n} from './rpc';\nimport type { Commitment, SolanaCallTags } from './types';\n\n/** `getBlocks` accepts at most this many slots per call (agave). */\nconst MAX_RANGE = 500_000n;\n/** At most this many `getBlocks` pages below the head (about 8 M slots). */\nconst MAX_PAGES = 16;\n/** Verified finalized height → slot pairs kept per driver. */\nconst CACHE_SIZE = 8_192;\n\nexport interface HeadBlock {\n readonly slot: bigint;\n readonly header: BlockHeader;\n}\n\nexport class HeightIndex {\n readonly #transport: Transport;\n readonly #final = new Map<bigint, bigint>();\n\n constructor(transport: Transport) {\n this.#transport = transport;\n }\n\n /** The block at the endpoint's `commitment` head (one `getSlot`, one `getBlock`). */\n async head(commitment: Commitment, tags: SolanaCallTags): Promise<HeadBlock> {\n const slot = u64(\n await call(this.#transport, 'getSlot', [{ commitment }], tags),\n 'getSlot',\n );\n const header = await this.header(slot, commitment, tags);\n if (!header) throw notYet(`the ${commitment} head block`);\n return { slot, header };\n }\n\n /**\n * The block at `slot`, or `null` while the endpoint has not reached it at `commitment`.\n * A pruned or missing block is a retryable error (decides nothing); a slot the endpoint\n * calls skipped means a list named a slot with no block, so the cache is dropped.\n */\n async header(\n slot: bigint,\n commitment: Commitment,\n tags: SolanaCallTags,\n ): Promise<BlockHeader | null> {\n let result: unknown;\n try {\n result = await call(\n this.#transport,\n 'getBlock',\n [Number(slot), headerOptions(commitment)],\n tags,\n );\n } catch (error) {\n if (isNotYet(error)) return null;\n if (isGone(error)) throw gone(`the block at slot ${slot}`);\n if (isSkipped(error)) {\n this.forget();\n throw inconsistent(`slot ${slot} holds no block`);\n }\n throw undecided(error, `the block at slot ${slot}`);\n }\n return result === null ? null : blockHeader(result);\n }\n\n /**\n * The slot of the block at `height` on the endpoint's chain at `commitment`, or `null`\n * while that chain has no block at `height` yet. A `confirmed` lookup at or below the\n * endpoint's finalized height resolves on the finalized chain, which fills the cache.\n */\n async slotAt(\n height: bigint,\n commitment: Commitment,\n tags: SolanaCallTags,\n ): Promise<bigint | null> {\n if (height < 0n) return null;\n const cached = this.#final.get(height);\n if (cached !== undefined) return cached;\n const final = await this.head('finalized', tags);\n if (height <= final.header.blockHeight) {\n return this.#resolve(height, final, 'finalized', tags);\n }\n if (commitment === 'finalized') return null;\n const top = await this.head('confirmed', tags);\n if (height > top.header.blockHeight) return null;\n return this.#resolve(height, top, 'confirmed', tags);\n }\n\n /** Counts back from `top` through verified `getBlocks` pages to the block at `height`. */\n async #resolve(\n height: bigint,\n top: HeadBlock,\n commitment: Commitment,\n tags: SolanaCallTags,\n ): Promise<bigint> {\n let anchorSlot = top.slot;\n let anchorHeight = top.header.blockHeight;\n if (height === anchorHeight) return anchorSlot;\n let span = anchorHeight - height + (anchorHeight - height) / 4n + 64n;\n for (let page = 0; page < MAX_PAGES; page++) {\n if (span > MAX_RANGE) span = MAX_RANGE;\n const want = anchorSlot > span ? anchorSlot - span : 0n;\n const { from, slots } = await this.#page(want, anchorSlot, commitment, tags);\n const last = slots.length - 1;\n // agave lists nothing when the range ends above what the endpoint holds at\n // `commitment` (a backend whose root trails the anchor): that list ends nowhere.\n if (last < 0 || slots[last] !== anchorSlot) {\n throw inconsistent(`getBlocks does not end at slot ${anchorSlot}`);\n }\n // A list that adds nothing below its anchor: the endpoint holds nothing older.\n if (last === 0) throw gone(`the block at height ${height}`);\n // The list's first block must sit exactly `last` heights below the anchor, or\n // the list has a gap; nothing from it is believed or cached.\n const firstHeight = anchorHeight - BigInt(last);\n const first = await this.header(slots[0] as bigint, commitment, tags);\n if (!first) throw notYet(`the block at slot ${slots[0]}`);\n if (first.blockHeight !== firstHeight) {\n throw inconsistent(`the blocks listed below slot ${anchorSlot} have a gap`);\n }\n slots.forEach((slot, i) => {\n const at = firstHeight + BigInt(i);\n // Keep the pairs a forward scan from `height` needs next.\n if (at >= height && at < height + BigInt(CACHE_SIZE)) {\n this.#remember(commitment, at, slot);\n }\n });\n if (height >= firstHeight) return slots[Number(height - firstHeight)] as bigint;\n // The list started at slot 0, or at the endpoint's first available block.\n if (from === 0n || from > want) throw gone(`the block at height ${height}`);\n anchorHeight = firstHeight;\n anchorSlot = slots[0] as bigint;\n span *= 2n;\n }\n throw gone(`the block at height ${height} (too far below the head)`);\n }\n\n /**\n * One verified-shape page of produced slots from `from` to `to`, and where it starts.\n * When the endpoint cannot list from `from` (a definitive RPC error with a JSON-RPC\n * code: agave answers `-32602 \"BigTable query failed\"` below its local ledger when\n * long-term storage fails), the page starts once more at the endpoint's first available\n * block, when that lies inside the range (liveness only). Every other error, and a\n * second failure, decides nothing.\n */\n async #page(\n from: bigint,\n to: bigint,\n commitment: Commitment,\n tags: SolanaCallTags,\n ): Promise<{ readonly from: bigint; readonly slots: bigint[] }> {\n try {\n return { from, slots: await this.#blocks(from, to, commitment, tags) };\n } catch (error) {\n // Only an endpoint's own definitive answer: an ambiguous error, or one without a\n // JSON-RPC code, says nothing about what this endpoint can list.\n const first =\n rpcCode(error) === undefined ? null : await this.#firstAvailable(tags);\n if (first === null || first <= from || first > to) {\n throw undecided(error, `the blocks from slot ${from}`);\n }\n try {\n return { from: first, slots: await this.#blocks(first, to, commitment, tags) };\n } catch (retry) {\n throw undecided(retry, `the blocks from slot ${first}`);\n }\n }\n }\n\n /** The endpoint's first available block: a hint only, `null` when it cannot say. */\n async #firstAvailable(tags: SolanaCallTags): Promise<bigint | null> {\n try {\n return u64(\n await call(this.#transport, 'getFirstAvailableBlock', [], tags),\n 'getFirstAvailableBlock',\n );\n } catch (error) {\n if (tags.signal?.aborted) throw error;\n return null;\n }\n }\n\n /** `getBlocks` from `from` to `to`: strictly increasing slots inside the range. */\n async #blocks(\n from: bigint,\n to: bigint,\n commitment: Commitment,\n tags: SolanaCallTags,\n ): Promise<bigint[]> {\n const result = await call(\n this.#transport,\n 'getBlocks',\n [Number(from), Number(to), { commitment }],\n tags,\n );\n if (!Array.isArray(result)) throw malformed('getBlocks');\n const slots = result.map((slot) => u64(slot, 'getBlocks slot'));\n for (let i = 0; i < slots.length; i++) {\n const slot = slots[i] as bigint;\n if (slot < from || slot > to || (i > 0 && slot <= (slots[i - 1] as bigint))) {\n throw malformed('getBlocks');\n }\n }\n return slots;\n }\n\n /** Drops every cached pair: a later read contradicted one (cheap to rebuild). */\n forget(): void {\n this.#final.clear();\n }\n\n #remember(commitment: Commitment, height: bigint, slot: bigint): void {\n if (commitment !== 'finalized' || this.#final.has(height)) return;\n this.#final.set(height, slot);\n if (this.#final.size > CACHE_SIZE) {\n const oldest = this.#final.keys().next().value as bigint;\n this.#final.delete(oldest);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Address history from `getSignaturesForAddress`, newest first. The cursor is the
|
|
3
|
+
* last signature of a page. A token account's history holds the SPL transfers into it; an
|
|
4
|
+
* owner's history holds only the transactions that name the owner itself.
|
|
5
|
+
*/
|
|
6
|
+
import type { AddressHistorySource } from '../../core/driver/types';
|
|
7
|
+
import { type SolanaContext } from './reader';
|
|
8
|
+
/** `getSignaturesForAddress` returns at most this many signatures per call (agave). */
|
|
9
|
+
export declare const MAX_HISTORY_PAGE = 1000;
|
|
10
|
+
export declare function createSolanaHistory(ctx: SolanaContext): AddressHistorySource;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_HISTORY_PAGE = void 0;
|
|
4
|
+
exports.createSolanaHistory = createSolanaHistory;
|
|
5
|
+
const error_1 = require("../../core/errors/error");
|
|
6
|
+
const decode_1 = require("./decode");
|
|
7
|
+
const keys_1 = require("./keys");
|
|
8
|
+
const reader_1 = require("./reader");
|
|
9
|
+
const rpc_1 = require("./rpc");
|
|
10
|
+
/** `getSignaturesForAddress` returns at most this many signatures per call (agave). */
|
|
11
|
+
exports.MAX_HISTORY_PAGE = 1_000;
|
|
12
|
+
function createSolanaHistory(ctx) {
|
|
13
|
+
return {
|
|
14
|
+
async list(address, { cursor, limit }) {
|
|
15
|
+
if (cursor !== undefined && !(0, keys_1.isSignature)(cursor)) {
|
|
16
|
+
throw new error_1.ValidationError('INVALID_INTENT', 'not a Solana history cursor');
|
|
17
|
+
}
|
|
18
|
+
const size = Math.min(limit, exports.MAX_HISTORY_PAGE);
|
|
19
|
+
let result;
|
|
20
|
+
try {
|
|
21
|
+
result = await (0, rpc_1.call)(ctx.transport, 'getSignaturesForAddress', [
|
|
22
|
+
address,
|
|
23
|
+
{
|
|
24
|
+
limit: size,
|
|
25
|
+
commitment: 'confirmed',
|
|
26
|
+
...(cursor !== undefined ? { before: cursor } : {}),
|
|
27
|
+
},
|
|
28
|
+
], rpc_1.READ);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
// A backend that does not hold the cursor's transaction (another backend behind a
|
|
32
|
+
// load balancer, or a pruned one) answers -32020. That decides nothing: another
|
|
33
|
+
// backend may hold it.
|
|
34
|
+
if ((0, rpc_1.rpcCode)(error) === rpc_1.RPC_CODES.FILTER_TRANSACTION_NOT_FOUND) {
|
|
35
|
+
// The node's error stays reachable: its cause and where it happened.
|
|
36
|
+
throw new error_1.ProviderError('PROVIDER_UNAVAILABLE', 'the endpoint does not know the history cursor', { cause: error, context: error.context });
|
|
37
|
+
}
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
if (!Array.isArray(result))
|
|
41
|
+
throw (0, rpc_1.malformed)('getSignaturesForAddress');
|
|
42
|
+
const signatures = result.map((entry) => {
|
|
43
|
+
const signature = entry?.signature;
|
|
44
|
+
if (!(0, keys_1.isSignature)(signature))
|
|
45
|
+
throw (0, rpc_1.malformed)('getSignaturesForAddress');
|
|
46
|
+
return signature;
|
|
47
|
+
});
|
|
48
|
+
const items = [];
|
|
49
|
+
for (const signature of signatures) {
|
|
50
|
+
const found = await (0, reader_1.readTransaction)(ctx, signature, rpc_1.READ);
|
|
51
|
+
if (!found)
|
|
52
|
+
throw (0, rpc_1.inconsistent)('a listed transaction is missing');
|
|
53
|
+
items.push((0, decode_1.decodeTransaction)(found.parsed, {
|
|
54
|
+
height: found.header.blockHeight,
|
|
55
|
+
hash: found.header.blockhash,
|
|
56
|
+
...(found.parsed.blockTime !== undefined
|
|
57
|
+
? { blockTime: found.parsed.blockTime }
|
|
58
|
+
: {}),
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
// Paged on the raw page: only a page shorter than asked ends the history, and one
|
|
62
|
+
// longer than asked never does.
|
|
63
|
+
const last = signatures[signatures.length - 1];
|
|
64
|
+
return {
|
|
65
|
+
items,
|
|
66
|
+
...(signatures.length >= size && last !== undefined ? { next: last } : {}),
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../../src/adapters/solana/history.ts"],"names":[],"mappings":";;;AAmBA,kDAiEC;AA9ED,mDAIiC;AACjC,qCAA6C;AAC7C,iCAAqC;AACrC,qCAA+D;AAC/D,+BAAgF;AAEhF,uFAAuF;AAC1E,QAAA,gBAAgB,GAAG,KAAK,CAAC;AAEtC,SAAgB,mBAAmB,CAAC,GAAkB;IACpD,OAAO;QACL,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE;YACnC,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,IAAA,kBAAW,EAAC,MAAM,CAAC,EAAE,CAAC;gBACjD,MAAM,IAAI,uBAAe,CAAC,gBAAgB,EAAE,6BAA6B,CAAC,CAAC;YAC7E,CAAC;YACD,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,wBAAgB,CAAC,CAAC;YAC/C,IAAI,MAAe,CAAC;YACpB,IAAI,CAAC;gBACH,MAAM,GAAG,MAAM,IAAA,UAAI,EACjB,GAAG,CAAC,SAAS,EACb,yBAAyB,EACzB;oBACE,OAAO;oBACP;wBACE,KAAK,EAAE,IAAI;wBACX,UAAU,EAAE,WAAW;wBACvB,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;qBACpD;iBACF,EACD,UAAI,CACL,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,kFAAkF;gBAClF,gFAAgF;gBAChF,uBAAuB;gBACvB,IAAI,IAAA,aAAO,EAAC,KAAK,CAAC,KAAK,eAAS,CAAC,4BAA4B,EAAE,CAAC;oBAC9D,qEAAqE;oBACrE,MAAM,IAAI,qBAAa,C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U,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAC/C,OAAO;gBACL,KAAK;gBACL,GAAG,CAAC,UAAU,CAAC,MAAM,IAAI,IAAI,IAAI,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC3E,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Address history from `getSignaturesForAddress`, newest first. The cursor is the\n * last signature of a page. A token account's history holds the SPL transfers into it; an\n * owner's history holds only the transactions that name the owner itself.\n */\nimport type { AddressHistorySource, DriverTransaction } from '../../core/driver/types';\nimport {\n ProviderError,\n ValidationError,\n type CryptoAioError,\n} from '../../core/errors/error';\nimport { decodeTransaction } from './decode';\nimport { isSignature } from './keys';\nimport { readTransaction, type SolanaContext } from './reader';\nimport { READ, RPC_CODES, call, inconsistent, malformed, rpcCode } from './rpc';\n\n/** `getSignaturesForAddress` returns at most this many signatures per call (agave). */\nexport const MAX_HISTORY_PAGE = 1_000;\n\nexport function createSolanaHistory(ctx: SolanaContext): AddressHistorySource {\n return {\n async list(address, { cursor, limit }) {\n if (cursor !== undefined && !isSignature(cursor)) {\n throw new ValidationError('INVALID_INTENT', 'not a Solana history cursor');\n }\n const size = Math.min(limit, MAX_HISTORY_PAGE);\n let result: unknown;\n try {\n result = await call(\n ctx.transport,\n 'getSignaturesForAddress',\n [\n address,\n {\n limit: size,\n commitment: 'confirmed',\n ...(cursor !== undefined ? { before: cursor } : {}),\n },\n ],\n READ,\n );\n } catch (error) {\n // A backend that does not hold the cursor's transaction (another backend behind a\n // load balancer, or a pruned one) answers -32020. That decides nothing: another\n // backend may hold it.\n if (rpcCode(error) === RPC_CODES.FILTER_TRANSACTION_NOT_FOUND) {\n // The node's error stays reachable: its cause and where it happened.\n throw new ProviderError(\n 'PROVIDER_UNAVAILABLE',\n 'the endpoint does not know the history cursor',\n { cause: error, context: (error as CryptoAioError).context },\n );\n }\n throw error;\n }\n if (!Array.isArray(result)) throw malformed('getSignaturesForAddress');\n const signatures = result.map((entry: unknown) => {\n const signature = (entry as { signature?: unknown } | null)?.signature;\n if (!isSignature(signature)) throw malformed('getSignaturesForAddress');\n return signature;\n });\n const items: DriverTransaction[] = [];\n for (const signature of signatures) {\n const found = await readTransaction(ctx, signature, READ);\n if (!found) throw inconsistent('a listed transaction is missing');\n items.push(\n decodeTransaction(found.parsed, {\n height: found.header.blockHeight,\n hash: found.header.blockhash,\n ...(found.parsed.blockTime !== undefined\n ? { blockTime: found.parsed.blockTime }\n : {}),\n }),\n );\n }\n // Paged on the raw page: only a page shorter than asked ends the history, and one\n // longer than asked never does.\n const last = signatures[signatures.length - 1];\n return {\n items,\n ...(signatures.length >= size && last !== undefined ? { next: last } : {}),\n };\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `crypto-aio/solana`: the SDK-free Solana types, and the `crypto-aio/native` client type:
|
|
3
|
+
* importing this entry types `native(bc, '@solana/web3.js')` as a `Connection` wired to the
|
|
4
|
+
* handle's transport (HTTP JSON-RPC only; subscriptions have no transport bridge).
|
|
5
|
+
*
|
|
6
|
+
* @module crypto-aio/solana
|
|
7
|
+
*/
|
|
8
|
+
import type { Connection } from '@solana/web3.js';
|
|
9
|
+
declare module '../../index' {
|
|
10
|
+
interface NativeClientMap {
|
|
11
|
+
'@solana/web3.js': Connection;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export { SOLANA_PEER_DEPENDENCIES } from './plugin';
|
|
15
|
+
export { DEFAULT_MAX_COMPUTE_UNIT_PRICE, SOLANA_CAPABILITIES } from './network';
|
|
16
|
+
export type { SolanaExpiryOrdering, SolanaExt, SolanaFeeDetails, SolanaFeeOverride, SolanaTokenAccount, } from './types';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SOLANA_CAPABILITIES = exports.DEFAULT_MAX_COMPUTE_UNIT_PRICE = exports.SOLANA_PEER_DEPENDENCIES = void 0;
|
|
4
|
+
var plugin_1 = require("./plugin");
|
|
5
|
+
Object.defineProperty(exports, "SOLANA_PEER_DEPENDENCIES", { enumerable: true, get: function () { return plugin_1.SOLANA_PEER_DEPENDENCIES; } });
|
|
6
|
+
var network_1 = require("./network");
|
|
7
|
+
Object.defineProperty(exports, "DEFAULT_MAX_COMPUTE_UNIT_PRICE", { enumerable: true, get: function () { return network_1.DEFAULT_MAX_COMPUTE_UNIT_PRICE; } });
|
|
8
|
+
Object.defineProperty(exports, "SOLANA_CAPABILITIES", { enumerable: true, get: function () { return network_1.SOLANA_CAPABILITIES; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/adapters/solana/index.ts"],"names":[],"mappings":";;;AAiBA,mCAAoD;AAA3C,kHAAA,wBAAwB,OAAA;AACjC,qCAAgF;AAAvE,yHAAA,8BAA8B,OAAA;AAAE,8GAAA,mBAAmB,OAAA","sourcesContent":["/**\n * `crypto-aio/solana`: the SDK-free Solana types, and the `crypto-aio/native` client type:\n * importing this entry types `native(bc, '@solana/web3.js')` as a `Connection` wired to the\n * handle's transport (HTTP JSON-RPC only; subscriptions have no transport bridge).\n *\n * @module crypto-aio/solana\n */\nimport type { Connection } from '@solana/web3.js';\n\n// Augments the package entry's map. SDK types appear only here, so the main entry's\n// typings name no SDK.\ndeclare module '../../index' {\n interface NativeClientMap {\n '@solana/web3.js': Connection;\n }\n}\n\nexport { SOLANA_PEER_DEPENDENCIES } from './plugin';\nexport { DEFAULT_MAX_COMPUTE_UNIT_PRICE, SOLANA_CAPABILITIES } from './network';\nexport type {\n SolanaExpiryOrdering,\n SolanaExt,\n SolanaFeeDetails,\n SolanaFeeOverride,\n SolanaTokenAccount,\n} from './types';\n"]}
|