diff --git a/examples/deserialize-transaction/package.json b/examples/deserialize-transaction/package.json index 8fafc144a..68b915e21 100644 --- a/examples/deserialize-transaction/package.json +++ b/examples/deserialize-transaction/package.json @@ -12,10 +12,10 @@ "test:typecheck": "tsc" }, "dependencies": { - "@solana-program/memo": "^0.6.1", - "@solana-program/system": "^0.6.2", + "@solana-program/memo": "^0.7.0", + "@solana-program/system": "^0.7.0", "@solana/example-utils": "workspace:*", - "@solana/web3.js": "workspace:*" + "@solana/kit": "workspace:*" }, "devDependencies": { "start-server-and-test": "^2.0.10", diff --git a/examples/deserialize-transaction/src/example.ts b/examples/deserialize-transaction/src/example.ts index bb397653d..0c31b82a2 100644 --- a/examples/deserialize-transaction/src/example.ts +++ b/examples/deserialize-transaction/src/example.ts @@ -1,6 +1,6 @@ /** * EXAMPLE - * Deserialize and inspect a transaction with @solana/web3.js. + * Deserialize and inspect a transaction with @solana/kit * * Before running any of the examples in this monorepo, make sure to set up a test validator by * running `pnpm test:live-with-test-validator:setup` in the root directory. @@ -32,7 +32,7 @@ import { setTransactionMessageFeePayer, setTransactionMessageLifetimeUsingBlockhash, verifySignature, -} from '@solana/web3.js'; +} from '@solana/kit'; import { getAddMemoInstruction, MEMO_PROGRAM_ADDRESS, parseAddMemoInstruction } from '@solana-program/memo'; import { getTransferSolInstruction, @@ -113,7 +113,7 @@ const transactionMessage = pipe( source: SOURCE_ACCOUNT_SIGNER, }), getAddMemoInstruction({ - memo: 'hello from @solana/web3.js', + memo: 'hello from @solana/kit', }), ], tx, @@ -179,7 +179,7 @@ log.info(`[setup] Encoded the transaction as base64: ${base64EncodedTransaction. /** * STEP 1: DECODE TO TRANSACTION - * @solana/web3.js has encoders/decoders for many Solana data structures and common data formats, + * @solana/kit has encoders/decoders for many Solana data structures and common data formats, * including both base64 strings and our `Transaction` data structure * To convert between these, we first encode to a byte array, and then decode to the * desired data structure. @@ -366,7 +366,7 @@ log.info(decompiledTransactionMessage.instructions[0].data, '[step 3] The data b * STEP 4: PARSING THE INSTRUCTIONS * To understand what is actually happening in each instruction, we need to decode the data field * We will do this by using the generated `@solana-program/system` client, which can decode data - * from the @solana/web3.js instruction data structure for the System program + * from the @solana/kit instruction data structure for the System program * We know from the program address (11111111111111111111111111111111) that the first instruction * is to the system program * You can generate such a client for any Solana program using Codama @@ -385,7 +385,7 @@ if (identifiedInstruction === SystemInstruction.TransferSol) { assertIsInstructionWithAccounts(firstInstruction); // TODO: This can just be `parseTransferSolInstruction(firstInstruction)` when the client is updated - // with the `@solana/web3.js` version that changes the instruction data type to `ReadonlyUint8Array` + // with the `@solana/kit` version that changes the instruction data type to `ReadonlyUint8Array` const parsedFirstInstruction = parseTransferSolInstruction({ ...firstInstruction, data: firstInstruction.data as unknown as Uint8Array, @@ -416,7 +416,7 @@ if (secondInstruction.programAddress === MEMO_PROGRAM_ADDRESS) { assertIsInstructionWithData(secondInstruction); // TODO: This can just be `parseAddMemoInstruction(secondInstruction)` when the client is updated -// with the `@solana/web3.js` version that changes the instruction data type to `ReadonlyUint8Array` +// with the `@solana/kit` version that changes the instruction data type to `ReadonlyUint8Array` const parsedSecondInstruction = parseAddMemoInstruction({ ...secondInstruction, data: secondInstruction.data as unknown as Uint8Array, diff --git a/examples/react-app/package.json b/examples/react-app/package.json index 51f1bd229..65f90dd5c 100644 --- a/examples/react-app/package.json +++ b/examples/react-app/package.json @@ -16,9 +16,9 @@ "@radix-ui/react-dropdown-menu": "2.1.6", "@radix-ui/react-icons": "1.3.2", "@radix-ui/themes": "3.2.0", - "@solana-program/system": "^0.6.2", + "@solana-program/system": "^0.7.0", + "@solana/kit": "workspace:*", "@solana/react": "workspace:*", - "@solana/web3.js": "workspace:*", "@wallet-standard/core": "^1.1.0", "@wallet-standard/react": "^1.0.0", "react": "^19", diff --git a/examples/react-app/src/components/Balance.tsx b/examples/react-app/src/components/Balance.tsx index 3e138e95e..c7071d796 100644 --- a/examples/react-app/src/components/Balance.tsx +++ b/examples/react-app/src/components/Balance.tsx @@ -1,6 +1,6 @@ import { ExclamationTriangleIcon } from '@radix-ui/react-icons'; import { Text, Tooltip } from '@radix-ui/themes'; -import { address } from '@solana/web3.js'; +import { address } from '@solana/kit'; import type { UiWalletAccount } from '@wallet-standard/react'; import { useContext, useMemo } from 'react'; import useSWRSubscription from 'swr/subscription'; diff --git a/examples/react-app/src/components/BaseSignMessageFeaturePanel.tsx b/examples/react-app/src/components/BaseSignMessageFeaturePanel.tsx index ca6936755..23ffc1d66 100644 --- a/examples/react-app/src/components/BaseSignMessageFeaturePanel.tsx +++ b/examples/react-app/src/components/BaseSignMessageFeaturePanel.tsx @@ -1,6 +1,6 @@ import { Pencil1Icon } from '@radix-ui/react-icons'; import { Blockquote, Box, Button, Code, DataList, Dialog, Flex, TextField } from '@radix-ui/themes'; -import { getBase64Decoder } from '@solana/web3.js'; +import { getBase64Decoder } from '@solana/kit'; import type { ReadonlyUint8Array } from '@wallet-standard/core'; import type { SyntheticEvent } from 'react'; import { useRef, useState } from 'react'; diff --git a/examples/react-app/src/components/SolanaSignAndSendTransactionFeaturePanel.tsx b/examples/react-app/src/components/SolanaSignAndSendTransactionFeaturePanel.tsx index e43178cfc..96a5a646a 100644 --- a/examples/react-app/src/components/SolanaSignAndSendTransactionFeaturePanel.tsx +++ b/examples/react-app/src/components/SolanaSignAndSendTransactionFeaturePanel.tsx @@ -1,5 +1,4 @@ import { Blockquote, Box, Button, Dialog, Flex, Link, Select, Text, TextField } from '@radix-ui/themes'; -import { useWalletAccountTransactionSendingSigner } from '@solana/react'; import { address, appendTransactionMessageInstruction, @@ -11,7 +10,8 @@ import { setTransactionMessageFeePayerSigner, setTransactionMessageLifetimeUsingBlockhash, signAndSendTransactionMessageWithSigners, -} from '@solana/web3.js'; +} from '@solana/kit'; +import { useWalletAccountTransactionSendingSigner } from '@solana/react'; import { getTransferSolInstruction } from '@solana-program/system'; import { getUiWalletAccountStorageKey, type UiWalletAccount, useWallets } from '@wallet-standard/react'; import type { SyntheticEvent } from 'react'; diff --git a/examples/react-app/src/components/SolanaSignMessageFeaturePanel.tsx b/examples/react-app/src/components/SolanaSignMessageFeaturePanel.tsx index f074f92ae..0ad6c2c19 100644 --- a/examples/react-app/src/components/SolanaSignMessageFeaturePanel.tsx +++ b/examples/react-app/src/components/SolanaSignMessageFeaturePanel.tsx @@ -1,5 +1,5 @@ +import type { Address } from '@solana/kit'; import { useWalletAccountMessageSigner } from '@solana/react'; -import type { Address } from '@solana/web3.js'; import type { ReadonlyUint8Array } from '@wallet-standard/core'; import type { UiWalletAccount } from '@wallet-standard/react'; import { useCallback } from 'react'; diff --git a/examples/react-app/src/context/ChainContext.tsx b/examples/react-app/src/context/ChainContext.tsx index 96161dab0..fddb01f37 100644 --- a/examples/react-app/src/context/ChainContext.tsx +++ b/examples/react-app/src/context/ChainContext.tsx @@ -1,5 +1,5 @@ -import type { ClusterUrl } from '@solana/web3.js'; -import { devnet } from '@solana/web3.js'; +import type { ClusterUrl } from '@solana/kit'; +import { devnet } from '@solana/kit'; import { createContext } from 'react'; export type ChainContext = Readonly<{ diff --git a/examples/react-app/src/context/ChainContextProvider.tsx b/examples/react-app/src/context/ChainContextProvider.tsx index 87269a020..d4ad7400c 100644 --- a/examples/react-app/src/context/ChainContextProvider.tsx +++ b/examples/react-app/src/context/ChainContextProvider.tsx @@ -1,4 +1,4 @@ -import { mainnet, testnet } from '@solana/web3.js'; +import { mainnet, testnet } from '@solana/kit'; import { useMemo, useState } from 'react'; import { ChainContext, DEFAULT_CHAIN_CONFIG } from './ChainContext'; diff --git a/examples/react-app/src/context/RpcContext.tsx b/examples/react-app/src/context/RpcContext.tsx index 4a4c847af..396eb0d2d 100644 --- a/examples/react-app/src/context/RpcContext.tsx +++ b/examples/react-app/src/context/RpcContext.tsx @@ -1,5 +1,5 @@ -import type { Rpc, RpcSubscriptions, SolanaRpcApiMainnet, SolanaRpcSubscriptionsApi } from '@solana/web3.js'; -import { createSolanaRpc, createSolanaRpcSubscriptions, devnet } from '@solana/web3.js'; +import type { Rpc, RpcSubscriptions, SolanaRpcApiMainnet, SolanaRpcSubscriptionsApi } from '@solana/kit'; +import { createSolanaRpc, createSolanaRpcSubscriptions, devnet } from '@solana/kit'; import { createContext } from 'react'; export const RpcContext = createContext<{ diff --git a/examples/react-app/src/context/RpcContextProvider.tsx b/examples/react-app/src/context/RpcContextProvider.tsx index 75d9d449a..a93eb17e5 100644 --- a/examples/react-app/src/context/RpcContextProvider.tsx +++ b/examples/react-app/src/context/RpcContextProvider.tsx @@ -1,4 +1,4 @@ -import { createSolanaRpc, createSolanaRpcSubscriptions } from '@solana/web3.js'; +import { createSolanaRpc, createSolanaRpcSubscriptions } from '@solana/kit'; import { ReactNode, useContext, useMemo } from 'react'; import { ChainContext } from './ChainContext'; diff --git a/examples/react-app/src/functions/balance.ts b/examples/react-app/src/functions/balance.ts index 33e213f27..bf62bc7a2 100644 --- a/examples/react-app/src/functions/balance.ts +++ b/examples/react-app/src/functions/balance.ts @@ -1,4 +1,4 @@ -import { AccountNotificationsApi, Address, GetBalanceApi, Lamports, Rpc, RpcSubscriptions } from '@solana/web3.js'; +import { AccountNotificationsApi, Address, GetBalanceApi, Lamports, Rpc, RpcSubscriptions } from '@solana/kit'; import { SWRSubscription } from 'swr/subscription'; const EXPLICIT_ABORT_TOKEN = Symbol(); diff --git a/examples/rpc-custom-api/package.json b/examples/rpc-custom-api/package.json index 388226252..16ebd4ab2 100644 --- a/examples/rpc-custom-api/package.json +++ b/examples/rpc-custom-api/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@solana/example-utils": "workspace:*", - "@solana/web3.js": "workspace:*" + "@solana/kit": "workspace:*" }, "devDependencies": { "tsx": "^4.19.3" diff --git a/examples/rpc-custom-api/src/example.ts b/examples/rpc-custom-api/src/example.ts index ee1a55de3..1e9113c3d 100644 --- a/examples/rpc-custom-api/src/example.ts +++ b/examples/rpc-custom-api/src/example.ts @@ -1,6 +1,6 @@ /** * EXAMPLE - * Add a custom JSON RPC method to the base Solana JSON RPC API using @solana/web3.js. + * Add a custom JSON RPC method to the base Solana JSON RPC API using @solana/kit. * * To run this example, execute `pnpm start` in this directory. */ @@ -17,7 +17,7 @@ import { RpcApi, RpcPlan, SolanaRpcApiMainnet, -} from '@solana/web3.js'; +} from '@solana/kit'; const log = createLogger('Custom JSON RPC API'); diff --git a/examples/rpc-transport-throttled/package.json b/examples/rpc-transport-throttled/package.json index 34b05f873..9d47e49c4 100644 --- a/examples/rpc-transport-throttled/package.json +++ b/examples/rpc-transport-throttled/package.json @@ -13,7 +13,7 @@ }, "dependencies": { "@solana/example-utils": "workspace:*", - "@solana/web3.js": "workspace:*" + "@solana/kit": "workspace:*" }, "devDependencies": { "start-server-and-test": "^2.0.10", diff --git a/examples/rpc-transport-throttled/src/example.ts b/examples/rpc-transport-throttled/src/example.ts index 3ea436160..44d6be08b 100644 --- a/examples/rpc-transport-throttled/src/example.ts +++ b/examples/rpc-transport-throttled/src/example.ts @@ -14,7 +14,7 @@ import { createSolanaRpcFromTransport, mainnet, RpcTransportFromClusterUrl, -} from '@solana/web3.js'; +} from '@solana/kit'; const log = createLoggerWithTimestamp('Throttling transport'); diff --git a/examples/signers/package.json b/examples/signers/package.json index c4f74d374..6b68208a0 100644 --- a/examples/signers/package.json +++ b/examples/signers/package.json @@ -12,9 +12,9 @@ "test:typecheck": "tsc" }, "dependencies": { - "@solana-program/system": "^0.6.2", + "@solana-program/system": "^0.7.0", "@solana/example-utils": "workspace:*", - "@solana/web3.js": "workspace:*" + "@solana/kit": "workspace:*" }, "devDependencies": { "start-server-and-test": "^2.0.10", diff --git a/examples/signers/src/example.ts b/examples/signers/src/example.ts index 24cd58da0..85d407451 100644 --- a/examples/signers/src/example.ts +++ b/examples/signers/src/example.ts @@ -1,6 +1,6 @@ /** * EXAMPLE - * Create and use signers with @solana/web3.js. + * Create and use signers with @solana/kit. * * Before running any of the examples in this monorepo, make sure to set up a test validator by * running `pnpm test:live-with-test-validator:setup` in the root directory. @@ -28,7 +28,7 @@ import { setTransactionMessageLifetimeUsingBlockhash, TransactionPartialSigner, TransactionSigner, -} from '@solana/web3.js'; +} from '@solana/kit'; import { getTransferSolInstruction } from '@solana-program/system'; import { readFile } from 'fs/promises'; import path from 'path'; diff --git a/examples/transfer-lamports/package.json b/examples/transfer-lamports/package.json index 242a97048..ea83cb1ba 100644 --- a/examples/transfer-lamports/package.json +++ b/examples/transfer-lamports/package.json @@ -12,9 +12,9 @@ "test:typecheck": "tsc" }, "dependencies": { - "@solana-program/system": "^0.6.2", + "@solana-program/system": "^0.7.0", "@solana/example-utils": "workspace:*", - "@solana/web3.js": "workspace:*" + "@solana/kit": "workspace:*" }, "devDependencies": { "start-server-and-test": "^2.0.10", diff --git a/examples/transfer-lamports/src/example.ts b/examples/transfer-lamports/src/example.ts index 312aaaf2e..cdf2ec0aa 100644 --- a/examples/transfer-lamports/src/example.ts +++ b/examples/transfer-lamports/src/example.ts @@ -1,6 +1,6 @@ /** * EXAMPLE - * Transfer Lamports from one account to another with @solana/web3.js. + * Transfer Lamports from one account to another with @solana/kit. * * Before running any of the examples in this monorepo, make sure to set up a test validator by * running `pnpm test:live-with-test-validator:setup` in the root directory. @@ -25,7 +25,7 @@ import { setTransactionMessageLifetimeUsingBlockhash, signTransactionMessageWithSigners, SOLANA_ERROR__JSON_RPC__SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE, -} from '@solana/web3.js'; +} from '@solana/kit'; import { getSystemErrorMessage, getTransferSolInstruction, isSystemError } from '@solana-program/system'; const log = createLogger('Transfer'); diff --git a/packages/library/.gitignore b/packages/library/.gitignore deleted file mode 100644 index 77738287f..000000000 --- a/packages/library/.gitignore +++ /dev/null @@ -1 +0,0 @@ -dist/ \ No newline at end of file diff --git a/packages/library/.npmrc b/packages/library/.npmrc deleted file mode 100644 index b6f27f135..000000000 --- a/packages/library/.npmrc +++ /dev/null @@ -1 +0,0 @@ -engine-strict=true diff --git a/packages/library/.prettierignore b/packages/library/.prettierignore deleted file mode 100644 index 2bd5f0063..000000000 --- a/packages/library/.prettierignore +++ /dev/null @@ -1,4 +0,0 @@ -# Changelogs are autogenerated, so leave them alone -CHANGELOG.md - -dist/ diff --git a/packages/library/CHANGELOG.md b/packages/library/CHANGELOG.md deleted file mode 100644 index 0e0d16c4f..000000000 --- a/packages/library/CHANGELOG.md +++ /dev/null @@ -1,435 +0,0 @@ -# @solana/web3.js - -## 2.0.0 - -### Major Changes - -- [`4e7ec14`](https://github.com/solana-labs/solana-web3.js/commit/4e7ec14d9c1a74122d8b9b6cd177928bd1087c4b) Thanks [@steveluscher](https://github.com/steveluscher)! - This version of the `@solana/web3.js` Technology Preview fixes a bug with the default RPC transport, adds a utility that you can use to get an estimate of a transaction message's compute unit cost, and introduces `@solana/react` hooks for interacting with Wallet Standard wallets. - - To install the fourth Technology Preview: - - ```shell - npm install --save @solana/web3.js@tp4 - ``` - - For an example of how to use the new `@solana/react` package to interact with wallets in a React application, see the example application in [`examples/react-app`](https://github.com/solana-labs/solana-web3.js/tree/master/examples/react-app#readme). We hope to see similar wallet-connection packages patterned off `@solana/react` for other application frameworks soon. - - Try a demo of Technology Preview 4 in your browser at [CodeSandbox](https://codesandbox.io/p/sandbox/solana-javascript-sdk-technology-preview-4-h8cz4v?file=%2Fsrc%2Findex.ts%3A21%2C8). - - - [#2858](https://github.com/solana-labs/solana-web3.js/pull/2858) [`22a34aa`](https://github.com/solana-labs/solana-web3.js/commit/22a34aa08d1be7e9b43ccfea94a99eaa2694e491) Thanks [@steveluscher](https://github.com/steveluscher)! - Transaction signers' methods now take `minContextSlot` as an option. This is important for signers that simulate transactions, like wallets. They might be interested in knowing the slot at which the transaction was prepared, lest they run simulation at too early a slot. - - [#2852](https://github.com/solana-labs/solana-web3.js/pull/2852) [`cec9048`](https://github.com/solana-labs/solana-web3.js/commit/cec9048b2f83535df7e499db5488c336981dfb5a) Thanks [@lorisleiva](https://github.com/lorisleiva)! - The `signAndSendTransactionMessageWithSigners` function now automatically asserts that the provided transaction message contains a single sending signer and fails otherwise. - - [#2707](https://github.com/solana-labs/solana-web3.js/pull/2707) [`cb49bfa`](https://github.com/solana-labs/solana-web3.js/commit/cb49bfa28f412376a41e758eeda59e7e90983147) Thanks [@mcintyre94](https://github.com/mcintyre94)! - Allow creating keypairs and keys from ReadonlyUint8Array - - [#2715](https://github.com/solana-labs/solana-web3.js/pull/2715) [`26dae19`](https://github.com/solana-labs/solana-web3.js/commit/26dae190c2ec835fbdaa7b7d66ca33d6ba0727b8) Thanks [@lorisleiva](https://github.com/lorisleiva)! - Consolidated `getNullableCodec` and `getOptionCodec` with their `Zeroable` counterparts and added more configurations - - Namely, the `prefix` option can now be set to `null` and the `fixed` option was replaced with the `noneValue` option which can be set to `"zeroes"` for `Zeroable` codecs or a custom byte array for custom representations of none values. This means the `getZeroableNullableCodec` and `getZeroableOptionCodec` functions were removed in favor of the new options. - - ```ts - // Before. - getZeroableNullableCodec(getU16Codec()); - - // After. - getNullableCodec(getU16Codec(), { noneValue: 'zeroes', prefix: null }); - ``` - - Additionally, it is now possible to create nullable codecs that have no `prefix` nor `noneValue`. In this case, the existence of the nullable item is indicated by the presence of any remaining bytes left to decode. - - ```ts - const codec = getNullableCodec(getU16Codec(), { prefix: null }); - codec.encode(42); // 0x2a00 - codec.encode(null); // Encodes nothing. - codec.decode(new Uint8Array([42, 0])); // 42 - codec.decode(new Uint8Array([])); // null - ``` - - Also note that it is now possible for custom `noneValue` byte arrays to be of any length — previously, it had to match the fixed-size of the nullable item. - - Here is a recap of all supported scenarios, using a `u16` codec as an example: - - | `encode(42)` / `encode(null)` | No `noneValue` (default) | `noneValue: "zeroes"` | Custom `noneValue` (`0xff`) | - | ----------------------------- | ------------------------ | --------------------------- | --------------------------- | - | `u8` prefix (default) | `0x012a00` / `0x00` | `0x012a00` / `0x000000` | `0x012a00` / `0x00ff` | - | Custom `prefix` (`u16`) | `0x01002a00` / `0x0000` | `0x01002a00` / `0x00000000` | `0x01002a00` / `0x0000ff` | - | No `prefix` | `0x2a00` / `0x` | `0x2a00` / `0x0000` | `0x2a00` / `0xff` | - - Reciprocal changes were made with `getOptionCodec`. - - - [#2785](https://github.com/solana-labs/solana-web3.js/pull/2785) [`4f19842`](https://github.com/solana-labs/solana-web3.js/commit/4f198423997d28d927f982333d268e19940656df) Thanks [@steveluscher](https://github.com/steveluscher)! - The development mode error message printer no longer fatals on Safari < 16.4. - - [#2867](https://github.com/solana-labs/solana-web3.js/pull/2867) [`be36bab`](https://github.com/solana-labs/solana-web3.js/commit/be36babd752b1c987a2f53b4ff83ac8c045a3418) Thanks [@steveluscher](https://github.com/steveluscher)! - The `innerInstructions` property of JSON-RPC errors used snake case rather than camelCase for `stackHeight` and `programId`. This has been corrected. - - [#2728](https://github.com/solana-labs/solana-web3.js/pull/2728) [`f1e9ac2`](https://github.com/solana-labs/solana-web3.js/commit/f1e9ac2af579e4fbfb5550cbdbd971a87a4e4432) Thanks [@joncinque](https://github.com/joncinque)! - Simulate with the maximum quantity of compute units (1.4M) instead of `u32::MAX` - - [#2703](https://github.com/solana-labs/solana-web3.js/pull/2703) [`0908628`](https://github.com/solana-labs/solana-web3.js/commit/09086289a230aa1b780c1035408b48243ab960f2) Thanks [@steveluscher](https://github.com/steveluscher)! - Created a utility function to estimate the compute unit consumption of a transaction message - - [#2795](https://github.com/solana-labs/solana-web3.js/pull/2795) [`ce876d9`](https://github.com/solana-labs/solana-web3.js/commit/ce876d99f04d539292abd810acd77a319c52f50d) Thanks [@steveluscher](https://github.com/steveluscher)! - Added React hooks to which you can pass a Wallet Standard `UiWalletAccount` and obtain a `MessageModifyingSigner`, `TransactionModifyingSigner`, or `TransactionSendingSigner` for use in constructing, signing, and sending Solana transactions and messages - - [#2772](https://github.com/solana-labs/solana-web3.js/pull/2772) [`8fe4551`](https://github.com/solana-labs/solana-web3.js/commit/8fe4551217a3ad8bfdcd1609ac7b23e8fd044c72) Thanks [@steveluscher](https://github.com/steveluscher)! - Added a series of React hooks to which you can pass a Wallet Standard `UiWalletAccount` to extract its `signMessage`, `signTransaction`, and `signAndSendTransaction` features - - [#2819](https://github.com/solana-labs/solana-web3.js/pull/2819) [`7ee47ae`](https://github.com/solana-labs/solana-web3.js/commit/7ee47ae24ad73b429ee863342f300a6f6c49e3d2) Thanks [@steveluscher](https://github.com/steveluscher)! - Fixed a bug where coalesced RPC calls could end up aborted even though there were still interested consumers. This would happen if the consumer count fell to zero, then rose above zero again, in the same runloop. - - [#2868](https://github.com/solana-labs/solana-web3.js/pull/2868) [`91fb1f3`](https://github.com/solana-labs/solana-web3.js/commit/91fb1f39bb174cf1e899a21365153a7b3bbf3571) Thanks [@steveluscher](https://github.com/steveluscher)! - The `simulateTransaction` RPC method now accepts an `innerInstructions` param. When `true`, the simulation result will include an array of inner instructions, if any. - - [#2866](https://github.com/solana-labs/solana-web3.js/pull/2866) [`73bd5a9`](https://github.com/solana-labs/solana-web3.js/commit/73bd5a9e0b32846cd5d76f2d2d1b21661eab0677) Thanks [@steveluscher](https://github.com/steveluscher)! - The `TransactionInstruction` RPC type now has `stackHeight` - - [#2751](https://github.com/solana-labs/solana-web3.js/pull/2751) [`6340744`](https://github.com/solana-labs/solana-web3.js/commit/6340744e5cf0ea91ae677f381d5a187638a19597) Thanks [@mcintyre94](https://github.com/mcintyre94)! - Allow Rpc Request params to be any type, instead of requiring an array - -### Patch Changes - -- [#2728](https://github.com/solana-labs/solana-web3.js/pull/2728) [`f1e9ac2`](https://github.com/solana-labs/solana-web3.js/commit/f1e9ac2af579e4fbfb5550cbdbd971a87a4e4432) Thanks [@joncinque](https://github.com/joncinque)! - Simulate with the maximum quantity of compute units (1.4M) instead of `u32::MAX` - -- [#3407](https://github.com/solana-labs/solana-web3.js/pull/3407) [`10b08ac`](https://github.com/solana-labs/solana-web3.js/commit/10b08ac8cdb61aa1412475426cfcaf0eefe32722) Thanks [@lorisleiva](https://github.com/lorisleiva)! - Use `RpcRequest`, `RpcResponse` and their transformers in RPC Subscriptions packages - - This change makes the RPC and RPC Subscriptions architecture more consistent by using the same `RpcRequest` and `RpcResponse` types and transformers as the basis for handling user requests (RPC calls or subscriptions) and returning responses to them. - - See the following PRs for more details: - - - [PR #3393](https://github.com/solana-labs/solana-web3.js/pull/3393) - - [PR #3394](https://github.com/solana-labs/solana-web3.js/pull/3394) - - [PR #3403](https://github.com/solana-labs/solana-web3.js/pull/3403) - - [PR #3404](https://github.com/solana-labs/solana-web3.js/pull/3404) - - [PR #3405](https://github.com/solana-labs/solana-web3.js/pull/3405) - -- [#3541](https://github.com/solana-labs/solana-web3.js/pull/3541) [`135dc5a`](https://github.com/solana-labs/solana-web3.js/commit/135dc5ad43f286380a4c3a689668016f0d7945f4) Thanks [@steveluscher](https://github.com/steveluscher)! - Drop the Release Candidate label and publish `@solana/web3.js` at version 2.0.0 - -- [#2905](https://github.com/solana-labs/solana-web3.js/pull/2905) [`56fde06`](https://github.com/solana-labs/solana-web3.js/commit/56fde06003841228d4e7de162059dda648f1043d) Thanks [@steveluscher](https://github.com/steveluscher)! - Fixed the type of `config` on `getComputeUnitEstimateForTransactionMessage`. It is now optional and does not include `transactionMessage`. - -- [#3453](https://github.com/solana-labs/solana-web3.js/pull/3453) [`bafefed`](https://github.com/solana-labs/solana-web3.js/commit/bafefed88574009ba5a983023e439d91b65fada2) Thanks [@mcintyre94](https://github.com/mcintyre94)! - Rename decodeTransactionMessage to decompileTransactionMessageFetchingLookupTables - -- [#2504](https://github.com/solana-labs/solana-web3.js/pull/2504) [`18d6b56`](https://github.com/solana-labs/solana-web3.js/commit/18d6b56a69509e4c98de8f3de51abe2623b46763) Thanks [@steveluscher](https://github.com/steveluscher)! - Replaced `fast-stable-stringify` with our fork - -- [#3290](https://github.com/solana-labs/solana-web3.js/pull/3290) [`2368163`](https://github.com/solana-labs/solana-web3.js/commit/23681637fa3ee0e2242b3b6bf087a066393bcbd8) Thanks [@mcintyre94](https://github.com/mcintyre94)! - Throw an error if a transaction fails when being simulated to estimate CUs - -- [#2606](https://github.com/solana-labs/solana-web3.js/pull/2606) [`367b8ad`](https://github.com/solana-labs/solana-web3.js/commit/367b8ad0cce55a916abfb0125f36b6e844333b2b) Thanks [@lorisleiva](https://github.com/lorisleiva)! - Use commonjs package type - -- [#2703](https://github.com/solana-labs/solana-web3.js/pull/2703) [`0908628`](https://github.com/solana-labs/solana-web3.js/commit/09086289a230aa1b780c1035408b48243ab960f2) Thanks [@steveluscher](https://github.com/steveluscher)! - Created a utility function to estimate the compute unit consumption of a transaction message - -- [#3137](https://github.com/solana-labs/solana-web3.js/pull/3137) [`fd72c2e`](https://github.com/solana-labs/solana-web3.js/commit/fd72c2ed1edad488318fa5d3e285f04852f4210a) Thanks [@mcintyre94](https://github.com/mcintyre94)! - The build is now compatible with the Vercel Edge runtime and Cloudflare Workers through the addition of `edge-light` and `workerd` to the package exports. - -- Updated dependencies [[`9370133`](https://github.com/solana-labs/solana-web3.js/commit/9370133e414bfa863517248d97905449e9a867eb), [`31916ae`](https://github.com/solana-labs/solana-web3.js/commit/31916ae5d4fb29f239c63252a59745e33a6979ea), [`42a70f4`](https://github.com/solana-labs/solana-web3.js/commit/42a70f4c3004e55fe6ce5a8e500f5610765ec66f), [`292487d`](https://github.com/solana-labs/solana-web3.js/commit/292487da00ee57350e8faf49ccf961203aed6403), [`10b08ac`](https://github.com/solana-labs/solana-web3.js/commit/10b08ac8cdb61aa1412475426cfcaf0eefe32722), [`7d310f6`](https://github.com/solana-labs/solana-web3.js/commit/7d310f6f9cd7d02fca4d6f8e311b857c9dd84e61), [`1ad523d`](https://github.com/solana-labs/solana-web3.js/commit/1ad523dc5792d9152a66e9dc2b83294e3eba4db0), [`7ee47ae`](https://github.com/solana-labs/solana-web3.js/commit/7ee47ae24ad73b429ee863342f300a6f6c49e3d2), [`3834d82`](https://github.com/solana-labs/solana-web3.js/commit/3834d82eb1dd150f261612d742c3105194689c13), [`696c72c`](https://github.com/solana-labs/solana-web3.js/commit/696c72ce25c96f06442785bddffbc890ceb802f3), [`419c12e`](https://github.com/solana-labs/solana-web3.js/commit/419c12e617435570d0cded6ca6d35370d0060da7), [`45df702`](https://github.com/solana-labs/solana-web3.js/commit/45df7028d872e65759dad86b97cd9d4a9a3a545e), [`9dfca45`](https://github.com/solana-labs/solana-web3.js/commit/9dfca454355819444bad29e48602886428ba4cac), [`3c02c35`](https://github.com/solana-labs/solana-web3.js/commit/3c02c3582f5b87151b7ac1d9cd24b9d20f6945ea), [`1c25dd4`](https://github.com/solana-labs/solana-web3.js/commit/1c25dd4069a3a8f5599285c9b0eaeb71a2f897d1), [`89f399d`](https://github.com/solana-labs/solana-web3.js/commit/89f399d474abac463b1daaa864c88305d7b8c21f), [`3fc388f`](https://github.com/solana-labs/solana-web3.js/commit/3fc388f0b40243436a3ecbcd2af27ea8efa683e4), [`ebb03cd`](https://github.com/solana-labs/solana-web3.js/commit/ebb03cd8270027db957d4cecc7d2374d468d4ccb), [`002cc38`](https://github.com/solana-labs/solana-web3.js/commit/002cc38a99cd4c91c7ce9023e1b4fb28f7e10832), [`26dae19`](https://github.com/solana-labs/solana-web3.js/commit/26dae190c2ec835fbdaa7b7d66ca33d6ba0727b8), [`2040f96`](https://github.com/solana-labs/solana-web3.js/commit/2040f96cc22e4195749577d265cd6a76d8a08b87), [`0245265`](https://github.com/solana-labs/solana-web3.js/commit/024526554fa0145e31e62a0d47f1eea556a30e71), [`ce1be3f`](https://github.com/solana-labs/solana-web3.js/commit/ce1be3fe37ea9b744fd836f3d6c2c8e5e31efd77), [`1672346`](https://github.com/solana-labs/solana-web3.js/commit/1672346246fe9444b018d726ab7bfcd4bb092ec2), [`82cf07f`](https://github.com/solana-labs/solana-web3.js/commit/82cf07f4e905f6b056e70a0463a94222c3e7cadd), [`2d54650`](https://github.com/solana-labs/solana-web3.js/commit/2d5465018d8060eceb00efbf4f718df26d145199), [`135dc5a`](https://github.com/solana-labs/solana-web3.js/commit/135dc5ad43f286380a4c3a689668016f0d7945f4), [`bef9604`](https://github.com/solana-labs/solana-web3.js/commit/bef960435eb2303395bfa76e44f84d3348c5722d), [`af9fa3b`](https://github.com/solana-labs/solana-web3.js/commit/af9fa3b7e83220d69eab67b37d3a36beac0e848c), [`7e86583`](https://github.com/solana-labs/solana-web3.js/commit/7e86583da68695076ec62033f3fe078b3890f026), [`500a991`](https://github.com/solana-labs/solana-web3.js/commit/500a991d292638eaee1fa48a7b94acfe2ff83cb7), [`c122c75`](https://github.com/solana-labs/solana-web3.js/commit/c122c75936e8fa5364edf114a5182cf119b26922), [`0b02de1`](https://github.com/solana-labs/solana-web3.js/commit/0b02de140887654f19f8eda374f40c6f5a8f5e92), [`4f19842`](https://github.com/solana-labs/solana-web3.js/commit/4f198423997d28d927f982333d268e19940656df), [`231a030`](https://github.com/solana-labs/solana-web3.js/commit/231a0303ae5960e783719a8ff1d17a50ff26ad78), [`677a9c4`](https://github.com/solana-labs/solana-web3.js/commit/677a9c4eb88a8ac6a9ede8d82f367c5ac8d69ff4), [`8f94a9e`](https://github.com/solana-labs/solana-web3.js/commit/8f94a9ede71b32662bff991e6def68bc9e8bc921), [`38faba0`](https://github.com/solana-labs/solana-web3.js/commit/38faba05fab479ddbd95d0e211744d203f8aa823), [`73bd5a9`](https://github.com/solana-labs/solana-web3.js/commit/73bd5a9e0b32846cd5d76f2d2d1b21661eab0677), [`2e5af9f`](https://github.com/solana-labs/solana-web3.js/commit/2e5af9f1a9410f15108863342b48225fdf9a0c83), [`cec9048`](https://github.com/solana-labs/solana-web3.js/commit/cec9048b2f83535df7e499db5488c336981dfb5a), [`e3e82d9`](https://github.com/solana-labs/solana-web3.js/commit/e3e82d909825e958ae234ed18500335a621773bd), [`4c7224d`](https://github.com/solana-labs/solana-web3.js/commit/4c7224d0a884b0dc91ea536ce5fbdcd0a0d7e011), [`2798061`](https://github.com/solana-labs/solana-web3.js/commit/27980617e4f8d34dbc7b6da4507e4bca68a68090), [`44c8772`](https://github.com/solana-labs/solana-web3.js/commit/44c8772c8711b99e68dce3348e17bfc5b1d2a833), [`54d68c4`](https://github.com/solana-labs/solana-web3.js/commit/54d68c482feebf4e62a9896b3badd77dab615941), [`be36bab`](https://github.com/solana-labs/solana-web3.js/commit/be36babd752b1c987a2f53b4ff83ac8c045a3418), [`cb49bfa`](https://github.com/solana-labs/solana-web3.js/commit/cb49bfa28f412376a41e758eeda59e7e90983147), [`18d6b56`](https://github.com/solana-labs/solana-web3.js/commit/18d6b56a69509e4c98de8f3de51abe2623b46763), [`e1cb697`](https://github.com/solana-labs/solana-web3.js/commit/e1cb697d66dc906aa2433965452417e03cf86e13), [`288029a`](https://github.com/solana-labs/solana-web3.js/commit/288029a55a5eeb863b6df960027a59214ffc37f1), [`4ae78f5`](https://github.com/solana-labs/solana-web3.js/commit/4ae78f5cdddd6772b25351beb813483d4e52cea6), [`3d90241`](https://github.com/solana-labs/solana-web3.js/commit/3d902419c1b232fa7145757b9c95976de69790c7), [`478443f`](https://github.com/solana-labs/solana-web3.js/commit/478443fedac06678f12e8ac285aa7c7fcf503ee8), [`367b8ad`](https://github.com/solana-labs/solana-web3.js/commit/367b8ad0cce55a916abfb0125f36b6e844333b2b), [`fd72c2e`](https://github.com/solana-labs/solana-web3.js/commit/fd72c2ed1edad488318fa5d3e285f04852f4210a), [`4decebb`](https://github.com/solana-labs/solana-web3.js/commit/4decebb9b619972f49c740323b59cf470696e105), [`d4965ec`](https://github.com/solana-labs/solana-web3.js/commit/d4965ece9abaf81e3006442db15f3f77d89a622c), [`9239e6e`](https://github.com/solana-labs/solana-web3.js/commit/9239e6ec972b4de9f0d15b197fbef1d2871759d9), [`0158b31`](https://github.com/solana-labs/solana-web3.js/commit/0158b3181ed96996f269f3bff689f76411e460b3), [`db144da`](https://github.com/solana-labs/solana-web3.js/commit/db144da362e3389837b56f97abfb766cc8c847c2), [`22a34aa`](https://github.com/solana-labs/solana-web3.js/commit/22a34aa08d1be7e9b43ccfea94a99eaa2694e491), [`f9a8446`](https://github.com/solana-labs/solana-web3.js/commit/f9a84460670a97d4ab6514b28fe0d29c6fac3302), [`c8e6e71`](https://github.com/solana-labs/solana-web3.js/commit/c8e6e71529f219caf83ed444e53f5a1e757129dc), [`125fc15`](https://github.com/solana-labs/solana-web3.js/commit/125fc1540cfbc0a4afdba5aabac0884c750e58c1)]: - - @solana/errors@2.0.0 - - @solana/transactions@2.0.0 - - @solana/addresses@2.0.0 - - @solana/rpc-types@2.0.0 - - @solana/rpc@2.0.0 - - @solana/rpc-subscriptions@2.0.0 - - @solana/rpc-spec-types@2.0.0 - - @solana/keys@2.0.0 - - @solana/signers@2.0.0 - - @solana/transaction-confirmation@2.0.0 - - @solana/transaction-messages@2.0.0 - - @solana/accounts@2.0.0 - - @solana/codecs@2.0.0 - - @solana/programs@2.0.0 - - @solana/rpc-parsed-types@2.0.0 - - @solana/instructions@2.0.0 - - @solana/functional@2.0.0 - - @solana/sysvars@2.0.0 - -## 2.0.0-rc.4 - -### Patch Changes - -- Updated dependencies [[`2798061`](https://github.com/solana-labs/solana-web3.js/commit/27980617e4f8d34dbc7b6da4507e4bca68a68090)]: - - @solana/errors@2.0.0-rc.4 - - @solana/accounts@2.0.0-rc.4 - - @solana/addresses@2.0.0-rc.4 - - @solana/instructions@2.0.0-rc.4 - - @solana/keys@2.0.0-rc.4 - - @solana/programs@2.0.0-rc.4 - - @solana/rpc@2.0.0-rc.4 - - @solana/rpc-subscriptions@2.0.0-rc.4 - - @solana/rpc-types@2.0.0-rc.4 - - @solana/signers@2.0.0-rc.4 - - @solana/sysvars@2.0.0-rc.4 - - @solana/transaction-confirmation@2.0.0-rc.4 - - @solana/transaction-messages@2.0.0-rc.4 - - @solana/transactions@2.0.0-rc.4 - - @solana/rpc-parsed-types@2.0.0-rc.4 - - @solana/codecs@2.0.0-rc.4 - - @solana/functional@2.0.0-rc.4 - - @solana/rpc-spec-types@2.0.0-rc.4 - -## 2.0.0-rc.3 - -### Patch Changes - -- Updated dependencies [[`45df702`](https://github.com/solana-labs/solana-web3.js/commit/45df7028d872e65759dad86b97cd9d4a9a3a545e)]: - - @solana/rpc-subscriptions@2.0.0-rc.3 - - @solana/rpc-spec-types@2.0.0-rc.3 - - @solana/transaction-confirmation@2.0.0-rc.3 - - @solana/rpc@2.0.0-rc.3 - - @solana/accounts@2.0.0-rc.3 - - @solana/sysvars@2.0.0-rc.3 - - @solana/addresses@2.0.0-rc.3 - - @solana/codecs@2.0.0-rc.3 - - @solana/errors@2.0.0-rc.3 - - @solana/functional@2.0.0-rc.3 - - @solana/instructions@2.0.0-rc.3 - - @solana/keys@2.0.0-rc.3 - - @solana/programs@2.0.0-rc.3 - - @solana/rpc-parsed-types@2.0.0-rc.3 - - @solana/rpc-types@2.0.0-rc.3 - - @solana/signers@2.0.0-rc.3 - - @solana/transaction-messages@2.0.0-rc.3 - - @solana/transactions@2.0.0-rc.3 - -## 2.0.0-rc.2 - -### Patch Changes - -- [#3407](https://github.com/solana-labs/solana-web3.js/pull/3407) [`10b08ac`](https://github.com/solana-labs/solana-web3.js/commit/10b08ac8cdb61aa1412475426cfcaf0eefe32722) Thanks [@lorisleiva](https://github.com/lorisleiva)! - Use `RpcRequest`, `RpcResponse` and their transformers in RPC Subscriptions packages - - This change makes the RPC and RPC Subscriptions architecture more consistent by using the same `RpcRequest` and `RpcResponse` types and transformers as the basis for handling user requests (RPC calls or subscriptions) and returning responses to them. - - See the following PRs for more details: - - - [PR #3393](https://github.com/solana-labs/solana-web3.js/pull/3393) - - [PR #3394](https://github.com/solana-labs/solana-web3.js/pull/3394) - - [PR #3403](https://github.com/solana-labs/solana-web3.js/pull/3403) - - [PR #3404](https://github.com/solana-labs/solana-web3.js/pull/3404) - - [PR #3405](https://github.com/solana-labs/solana-web3.js/pull/3405) - -- [#3453](https://github.com/solana-labs/solana-web3.js/pull/3453) [`bafefed`](https://github.com/solana-labs/solana-web3.js/commit/bafefed88574009ba5a983023e439d91b65fada2) Thanks [@mcintyre94](https://github.com/mcintyre94)! - Rename decodeTransactionMessage to decompileTransactionMessageFetchingLookupTables - -- [#3290](https://github.com/solana-labs/solana-web3.js/pull/3290) [`2368163`](https://github.com/solana-labs/solana-web3.js/commit/23681637fa3ee0e2242b3b6bf087a066393bcbd8) Thanks [@mcintyre94](https://github.com/mcintyre94)! - Throw an error if a transaction fails when being simulated to estimate CUs - -- [#3137](https://github.com/solana-labs/solana-web3.js/pull/3137) [`fd72c2e`](https://github.com/solana-labs/solana-web3.js/commit/fd72c2ed1edad488318fa5d3e285f04852f4210a) Thanks [@mcintyre94](https://github.com/mcintyre94)! - The build is now compatible with the Vercel Edge runtime and Cloudflare Workers through the addition of `edge-light` and `workerd` to the package exports. - -- Updated dependencies [[`292487d`](https://github.com/solana-labs/solana-web3.js/commit/292487da00ee57350e8faf49ccf961203aed6403), [`10b08ac`](https://github.com/solana-labs/solana-web3.js/commit/10b08ac8cdb61aa1412475426cfcaf0eefe32722), [`3834d82`](https://github.com/solana-labs/solana-web3.js/commit/3834d82eb1dd150f261612d742c3105194689c13), [`696c72c`](https://github.com/solana-labs/solana-web3.js/commit/696c72ce25c96f06442785bddffbc890ceb802f3), [`9dfca45`](https://github.com/solana-labs/solana-web3.js/commit/9dfca454355819444bad29e48602886428ba4cac), [`3c02c35`](https://github.com/solana-labs/solana-web3.js/commit/3c02c3582f5b87151b7ac1d9cd24b9d20f6945ea), [`1c25dd4`](https://github.com/solana-labs/solana-web3.js/commit/1c25dd4069a3a8f5599285c9b0eaeb71a2f897d1), [`3fc388f`](https://github.com/solana-labs/solana-web3.js/commit/3fc388f0b40243436a3ecbcd2af27ea8efa683e4), [`0245265`](https://github.com/solana-labs/solana-web3.js/commit/024526554fa0145e31e62a0d47f1eea556a30e71), [`500a991`](https://github.com/solana-labs/solana-web3.js/commit/500a991d292638eaee1fa48a7b94acfe2ff83cb7), [`231a030`](https://github.com/solana-labs/solana-web3.js/commit/231a0303ae5960e783719a8ff1d17a50ff26ad78), [`8f94a9e`](https://github.com/solana-labs/solana-web3.js/commit/8f94a9ede71b32662bff991e6def68bc9e8bc921), [`38faba0`](https://github.com/solana-labs/solana-web3.js/commit/38faba05fab479ddbd95d0e211744d203f8aa823), [`4c7224d`](https://github.com/solana-labs/solana-web3.js/commit/4c7224d0a884b0dc91ea536ce5fbdcd0a0d7e011), [`44c8772`](https://github.com/solana-labs/solana-web3.js/commit/44c8772c8711b99e68dce3348e17bfc5b1d2a833), [`e1cb697`](https://github.com/solana-labs/solana-web3.js/commit/e1cb697d66dc906aa2433965452417e03cf86e13), [`fd72c2e`](https://github.com/solana-labs/solana-web3.js/commit/fd72c2ed1edad488318fa5d3e285f04852f4210a), [`4decebb`](https://github.com/solana-labs/solana-web3.js/commit/4decebb9b619972f49c740323b59cf470696e105), [`d4965ec`](https://github.com/solana-labs/solana-web3.js/commit/d4965ece9abaf81e3006442db15f3f77d89a622c), [`0158b31`](https://github.com/solana-labs/solana-web3.js/commit/0158b3181ed96996f269f3bff689f76411e460b3), [`db144da`](https://github.com/solana-labs/solana-web3.js/commit/db144da362e3389837b56f97abfb766cc8c847c2), [`c8e6e71`](https://github.com/solana-labs/solana-web3.js/commit/c8e6e71529f219caf83ed444e53f5a1e757129dc)]: - - @solana/addresses@2.0.0-rc.2 - - @solana/rpc-subscriptions@2.0.0-rc.2 - - @solana/rpc-spec-types@2.0.0-rc.2 - - @solana/rpc@2.0.0-rc.2 - - @solana/rpc-types@2.0.0-rc.2 - - @solana/transaction-confirmation@2.0.0-rc.2 - - @solana/accounts@2.0.0-rc.2 - - @solana/transaction-messages@2.0.0-rc.2 - - @solana/rpc-parsed-types@2.0.0-rc.2 - - @solana/sysvars@2.0.0-rc.2 - - @solana/errors@2.0.0-rc.2 - - @solana/instructions@2.0.0-rc.2 - - @solana/transactions@2.0.0-rc.2 - - @solana/functional@2.0.0-rc.2 - - @solana/programs@2.0.0-rc.2 - - @solana/signers@2.0.0-rc.2 - - @solana/codecs@2.0.0-rc.2 - - @solana/keys@2.0.0-rc.2 - -## 2.0.0-rc.1 - -### Patch Changes - -- Updated dependencies [[`7d310f6`](https://github.com/solana-labs/solana-web3.js/commit/7d310f6f9cd7d02fca4d6f8e311b857c9dd84e61), [`1ad523d`](https://github.com/solana-labs/solana-web3.js/commit/1ad523dc5792d9152a66e9dc2b83294e3eba4db0), [`c122c75`](https://github.com/solana-labs/solana-web3.js/commit/c122c75936e8fa5364edf114a5182cf119b26922), [`f9a8446`](https://github.com/solana-labs/solana-web3.js/commit/f9a84460670a97d4ab6514b28fe0d29c6fac3302)]: - - @solana/keys@2.0.0-rc.1 - - @solana/signers@2.0.0-rc.1 - - @solana/transaction-confirmation@2.0.0-rc.1 - - @solana/rpc-subscriptions@2.0.0-rc.1 - - @solana/transactions@2.0.0-rc.1 - - @solana/rpc@2.0.0-rc.1 - - @solana/sysvars@2.0.0-rc.1 - - @solana/accounts@2.0.0-rc.1 - - @solana/addresses@2.0.0-rc.1 - - @solana/codecs@2.0.0-rc.1 - - @solana/errors@2.0.0-rc.1 - - @solana/functional@2.0.0-rc.1 - - @solana/instructions@2.0.0-rc.1 - - @solana/programs@2.0.0-rc.1 - - @solana/rpc-parsed-types@2.0.0-rc.1 - - @solana/rpc-types@2.0.0-rc.1 - - @solana/transaction-messages@2.0.0-rc.1 - -## 2.0.0-rc.0 - -### Patch Changes - -- [#2905](https://github.com/solana-labs/solana-web3.js/pull/2905) [`56fde06`](https://github.com/solana-labs/solana-web3.js/commit/56fde06003841228d4e7de162059dda648f1043d) Thanks [@steveluscher](https://github.com/steveluscher)! - Fixed the type of `config` on `getComputeUnitEstimateForTransactionMessage`. It is now optional and does not include `transactionMessage`. - -- Updated dependencies [[`42a70f4`](https://github.com/solana-labs/solana-web3.js/commit/42a70f4c3004e55fe6ce5a8e500f5610765ec66f), [`419c12e`](https://github.com/solana-labs/solana-web3.js/commit/419c12e617435570d0cded6ca6d35370d0060da7), [`677a9c4`](https://github.com/solana-labs/solana-web3.js/commit/677a9c4eb88a8ac6a9ede8d82f367c5ac8d69ff4), [`9239e6e`](https://github.com/solana-labs/solana-web3.js/commit/9239e6ec972b4de9f0d15b197fbef1d2871759d9)]: - - @solana/rpc@2.0.0-rc.0 - - @solana/transaction-messages@2.0.0-rc.0 - - @solana/errors@2.0.0-rc.0 - - @solana/rpc-subscriptions@2.0.0-rc.0 - - @solana/programs@2.0.0-rc.0 - - @solana/transaction-confirmation@2.0.0-rc.0 - - @solana/signers@2.0.0-rc.0 - - @solana/transactions@2.0.0-rc.0 - - @solana/accounts@2.0.0-rc.0 - - @solana/sysvars@2.0.0-rc.0 - - @solana/addresses@2.0.0-rc.0 - - @solana/instructions@2.0.0-rc.0 - - @solana/keys@2.0.0-rc.0 - - @solana/rpc-types@2.0.0-rc.0 - - @solana/rpc-parsed-types@2.0.0-rc.0 - - @solana/codecs@2.0.0-rc.0 - - @solana/functional@2.0.0-rc.0 - -## 2.0.0-preview.4 - -### Major Changes - -- This version of the `@solana/web3.js` Technology Preview fixes a bug with the default RPC transport, adds a utility that you can use to get an estimate of a transaction message's compute unit cost, and introduces `@solana/react` hooks for interacting with Wallet Standard wallets. - - To install the fourth Technology Preview: - - ```shell - npm install --save @solana/web3.js@tp4 - ``` - - For an example of how to use the new `@solana/react` package to interact with wallets in a React application, see the example application in [`examples/react-app`](https://github.com/solana-labs/solana-web3.js/tree/master/examples/react-app#readme). We hope to see similar wallet-connection packages patterned off `@solana/react` for other application frameworks soon. - - Try a demo of Technology Preview 4 in your browser at [CodeSandbox](https://codesandbox.io/p/sandbox/solana-javascript-sdk-technology-preview-4-h8cz4v?file=%2Fsrc%2Findex.ts%3A21%2C8). - - - [#2858](https://github.com/solana-labs/solana-web3.js/pull/2858) [`22a34aa`](https://github.com/solana-labs/solana-web3.js/commit/22a34aa08d1be7e9b43ccfea94a99eaa2694e491) Thanks [@steveluscher](https://github.com/steveluscher)! - Transaction signers' methods now take `minContextSlot` as an option. This is important for signers that simulate transactions, like wallets. They might be interested in knowing the slot at which the transaction was prepared, lest they run simulation at too early a slot. - - [#2852](https://github.com/solana-labs/solana-web3.js/pull/2852) [`cec9048`](https://github.com/solana-labs/solana-web3.js/commit/cec9048b2f83535df7e499db5488c336981dfb5a) Thanks [@lorisleiva](https://github.com/lorisleiva)! - The `signAndSendTransactionMessageWithSigners` function now automatically asserts that the provided transaction message contains a single sending signer and fails otherwise. - - [#2707](https://github.com/solana-labs/solana-web3.js/pull/2707) [`cb49bfa`](https://github.com/solana-labs/solana-web3.js/commit/cb49bfa28f412376a41e758eeda59e7e90983147) Thanks [@mcintyre94](https://github.com/mcintyre94)! - Allow creating keypairs and keys from ReadonlyUint8Array - - [#2715](https://github.com/solana-labs/solana-web3.js/pull/2715) [`26dae19`](https://github.com/solana-labs/solana-web3.js/commit/26dae190c2ec835fbdaa7b7d66ca33d6ba0727b8) Thanks [@lorisleiva](https://github.com/lorisleiva)! - Consolidated `getNullableCodec` and `getOptionCodec` with their `Zeroable` counterparts and added more configurations - - Namely, the `prefix` option can now be set to `null` and the `fixed` option was replaced with the `noneValue` option which can be set to `"zeroes"` for `Zeroable` codecs or a custom byte array for custom representations of none values. This means the `getZeroableNullableCodec` and `getZeroableOptionCodec` functions were removed in favor of the new options. - - ```ts - // Before. - getZeroableNullableCodec(getU16Codec()); - - // After. - getNullableCodec(getU16Codec(), { noneValue: 'zeroes', prefix: null }); - ``` - - Additionally, it is now possible to create nullable codecs that have no `prefix` nor `noneValue`. In this case, the existence of the nullable item is indicated by the presence of any remaining bytes left to decode. - - ```ts - const codec = getNullableCodec(getU16Codec(), { prefix: null }); - codec.encode(42); // 0x2a00 - codec.encode(null); // Encodes nothing. - codec.decode(new Uint8Array([42, 0])); // 42 - codec.decode(new Uint8Array([])); // null - ``` - - Also note that it is now possible for custom `noneValue` byte arrays to be of any length — previously, it had to match the fixed-size of the nullable item. - - Here is a recap of all supported scenarios, using a `u16` codec as an example: - - | `encode(42)` / `encode(null)` | No `noneValue` (default) | `noneValue: "zeroes"` | Custom `noneValue` (`0xff`) | - | ----------------------------- | ------------------------ | --------------------------- | --------------------------- | - | `u8` prefix (default) | `0x012a00` / `0x00` | `0x012a00` / `0x000000` | `0x012a00` / `0x00ff` | - | Custom `prefix` (`u16`) | `0x01002a00` / `0x0000` | `0x01002a00` / `0x00000000` | `0x01002a00` / `0x0000ff` | - | No `prefix` | `0x2a00` / `0x` | `0x2a00` / `0x0000` | `0x2a00` / `0xff` | - - Reciprocal changes were made with `getOptionCodec`. - - - [#2785](https://github.com/solana-labs/solana-web3.js/pull/2785) [`4f19842`](https://github.com/solana-labs/solana-web3.js/commit/4f198423997d28d927f982333d268e19940656df) Thanks [@steveluscher](https://github.com/steveluscher)! - The development mode error message printer no longer fatals on Safari < 16.4. - - [#2867](https://github.com/solana-labs/solana-web3.js/pull/2867) [`be36bab`](https://github.com/solana-labs/solana-web3.js/commit/be36babd752b1c987a2f53b4ff83ac8c045a3418) Thanks [@steveluscher](https://github.com/steveluscher)! - The `innerInstructions` property of JSON-RPC errors used snake case rather than camelCase for `stackHeight` and `programId`. This has been corrected. - - [#2728](https://github.com/solana-labs/solana-web3.js/pull/2728) [`f1e9ac2`](https://github.com/solana-labs/solana-web3.js/commit/f1e9ac2af579e4fbfb5550cbdbd971a87a4e4432) Thanks [@joncinque](https://github.com/joncinque)! - Simulate with the maximum quantity of compute units (1.4M) instead of `u32::MAX` - - [#2703](https://github.com/solana-labs/solana-web3.js/pull/2703) [`0908628`](https://github.com/solana-labs/solana-web3.js/commit/09086289a230aa1b780c1035408b48243ab960f2) Thanks [@steveluscher](https://github.com/steveluscher)! - Created a utility function to estimate the compute unit consumption of a transaction message - - [#2795](https://github.com/solana-labs/solana-web3.js/pull/2795) [`ce876d9`](https://github.com/solana-labs/solana-web3.js/commit/ce876d99f04d539292abd810acd77a319c52f50d) Thanks [@steveluscher](https://github.com/steveluscher)! - Added React hooks to which you can pass a Wallet Standard `UiWalletAccount` and obtain a `MessageModifyingSigner`, `TransactionModifyingSigner`, or `TransactionSendingSigner` for use in constructing, signing, and sending Solana transactions and messages - - [#2772](https://github.com/solana-labs/solana-web3.js/pull/2772) [`8fe4551`](https://github.com/solana-labs/solana-web3.js/commit/8fe4551217a3ad8bfdcd1609ac7b23e8fd044c72) Thanks [@steveluscher](https://github.com/steveluscher)! - Added a series of React hooks to which you can pass a Wallet Standard `UiWalletAccount` to extract its `signMessage`, `signTransaction`, and `signAndSendTransaction` features - - [#2819](https://github.com/solana-labs/solana-web3.js/pull/2819) [`7ee47ae`](https://github.com/solana-labs/solana-web3.js/commit/7ee47ae24ad73b429ee863342f300a6f6c49e3d2) Thanks [@steveluscher](https://github.com/steveluscher)! - Fixed a bug where coalesced RPC calls could end up aborted even though there were still interested consumers. This would happen if the consumer count fell to zero, then rose above zero again, in the same runloop. - - [#2868](https://github.com/solana-labs/solana-web3.js/pull/2868) [`91fb1f3`](https://github.com/solana-labs/solana-web3.js/commit/91fb1f39bb174cf1e899a21365153a7b3bbf3571) Thanks [@steveluscher](https://github.com/steveluscher)! - The `simulateTransaction` RPC method now accepts an `innerInstructions` param. When `true`, the simulation result will include an array of inner instructions, if any. - - [#2866](https://github.com/solana-labs/solana-web3.js/pull/2866) [`73bd5a9`](https://github.com/solana-labs/solana-web3.js/commit/73bd5a9e0b32846cd5d76f2d2d1b21661eab0677) Thanks [@steveluscher](https://github.com/steveluscher)! - The `TransactionInstruction` RPC type now has `stackHeight` - - [#2751](https://github.com/solana-labs/solana-web3.js/pull/2751) [`6340744`](https://github.com/solana-labs/solana-web3.js/commit/6340744e5cf0ea91ae677f381d5a187638a19597) Thanks [@mcintyre94](https://github.com/mcintyre94)! - Allow Rpc Request params to be any type, instead of requiring an array - -### Patch Changes - -- [#2728](https://github.com/solana-labs/solana-web3.js/pull/2728) [`f1e9ac2`](https://github.com/solana-labs/solana-web3.js/commit/f1e9ac2af579e4fbfb5550cbdbd971a87a4e4432) Thanks [@joncinque](https://github.com/joncinque)! - Simulate with the maximum quantity of compute units (1.4M) instead of `u32::MAX` - -- [#2606](https://github.com/solana-labs/solana-web3.js/pull/2606) [`367b8ad`](https://github.com/solana-labs/solana-web3.js/commit/367b8ad0cce55a916abfb0125f36b6e844333b2b) Thanks [@lorisleiva](https://github.com/lorisleiva)! - Use commonjs package type - -- [#2703](https://github.com/solana-labs/solana-web3.js/pull/2703) [`0908628`](https://github.com/solana-labs/solana-web3.js/commit/09086289a230aa1b780c1035408b48243ab960f2) Thanks [@steveluscher](https://github.com/steveluscher)! - Created a utility function to estimate the compute unit consumption of a transaction message - -- Updated dependencies [[`7ee47ae`](https://github.com/solana-labs/solana-web3.js/commit/7ee47ae24ad73b429ee863342f300a6f6c49e3d2), [`26dae19`](https://github.com/solana-labs/solana-web3.js/commit/26dae190c2ec835fbdaa7b7d66ca33d6ba0727b8), [`4f19842`](https://github.com/solana-labs/solana-web3.js/commit/4f198423997d28d927f982333d268e19940656df), [`73bd5a9`](https://github.com/solana-labs/solana-web3.js/commit/73bd5a9e0b32846cd5d76f2d2d1b21661eab0677), [`cec9048`](https://github.com/solana-labs/solana-web3.js/commit/cec9048b2f83535df7e499db5488c336981dfb5a), [`be36bab`](https://github.com/solana-labs/solana-web3.js/commit/be36babd752b1c987a2f53b4ff83ac8c045a3418), [`cb49bfa`](https://github.com/solana-labs/solana-web3.js/commit/cb49bfa28f412376a41e758eeda59e7e90983147), [`3d90241`](https://github.com/solana-labs/solana-web3.js/commit/3d902419c1b232fa7145757b9c95976de69790c7), [`367b8ad`](https://github.com/solana-labs/solana-web3.js/commit/367b8ad0cce55a916abfb0125f36b6e844333b2b), [`22a34aa`](https://github.com/solana-labs/solana-web3.js/commit/22a34aa08d1be7e9b43ccfea94a99eaa2694e491)]: - - @solana/rpc@2.0.0-preview.4 - - @solana/codecs@2.0.0-preview.4 - - @solana/errors@2.0.0-preview.4 - - @solana/rpc-types@2.0.0-preview.4 - - @solana/signers@2.0.0-preview.4 - - @solana/keys@2.0.0-preview.4 - - @solana/transaction-messages@2.0.0-preview.4 - - @solana/transaction-confirmation@2.0.0-preview.4 - - @solana/rpc-subscriptions@2.0.0-preview.4 - - @solana/rpc-parsed-types@2.0.0-preview.4 - - @solana/instructions@2.0.0-preview.4 - - @solana/transactions@2.0.0-preview.4 - - @solana/functional@2.0.0-preview.4 - - @solana/addresses@2.0.0-preview.4 - - @solana/accounts@2.0.0-preview.4 - - @solana/programs@2.0.0-preview.4 - - @solana/sysvars@2.0.0-preview.4 - -## 2.0.0-preview.3 - -### Patch Changes - -- [#2504](https://github.com/solana-labs/solana-web3.js/pull/2504) [`18d6b56`](https://github.com/solana-labs/solana-web3.js/commit/18d6b56a69509e4c98de8f3de51abe2623b46763) Thanks [@steveluscher](https://github.com/steveluscher)! - Replaced `fast-stable-stringify` with our fork - -- Updated dependencies [[`9370133`](https://github.com/solana-labs/solana-web3.js/commit/9370133e414bfa863517248d97905449e9a867eb), [`31916ae`](https://github.com/solana-labs/solana-web3.js/commit/31916ae5d4fb29f239c63252a59745e33a6979ea), [`89f399d`](https://github.com/solana-labs/solana-web3.js/commit/89f399d474abac463b1daaa864c88305d7b8c21f), [`ebb03cd`](https://github.com/solana-labs/solana-web3.js/commit/ebb03cd8270027db957d4cecc7d2374d468d4ccb), [`002cc38`](https://github.com/solana-labs/solana-web3.js/commit/002cc38a99cd4c91c7ce9023e1b4fb28f7e10832), [`2040f96`](https://github.com/solana-labs/solana-web3.js/commit/2040f96cc22e4195749577d265cd6a76d8a08b87), [`ce1be3f`](https://github.com/solana-labs/solana-web3.js/commit/ce1be3fe37ea9b744fd836f3d6c2c8e5e31efd77), [`1672346`](https://github.com/solana-labs/solana-web3.js/commit/1672346246fe9444b018d726ab7bfcd4bb092ec2), [`82cf07f`](https://github.com/solana-labs/solana-web3.js/commit/82cf07f4e905f6b056e70a0463a94222c3e7cadd), [`2d54650`](https://github.com/solana-labs/solana-web3.js/commit/2d5465018d8060eceb00efbf4f718df26d145199), [`bef9604`](https://github.com/solana-labs/solana-web3.js/commit/bef960435eb2303395bfa76e44f84d3348c5722d), [`af9fa3b`](https://github.com/solana-labs/solana-web3.js/commit/af9fa3b7e83220d69eab67b37d3a36beac0e848c), [`7e86583`](https://github.com/solana-labs/solana-web3.js/commit/7e86583da68695076ec62033f3fe078b3890f026), [`0b02de1`](https://github.com/solana-labs/solana-web3.js/commit/0b02de140887654f19f8eda374f40c6f5a8f5e92), [`2e5af9f`](https://github.com/solana-labs/solana-web3.js/commit/2e5af9f1a9410f15108863342b48225fdf9a0c83), [`e3e82d9`](https://github.com/solana-labs/solana-web3.js/commit/e3e82d909825e958ae234ed18500335a621773bd), [`54d68c4`](https://github.com/solana-labs/solana-web3.js/commit/54d68c482feebf4e62a9896b3badd77dab615941), [`18d6b56`](https://github.com/solana-labs/solana-web3.js/commit/18d6b56a69509e4c98de8f3de51abe2623b46763), [`288029a`](https://github.com/solana-labs/solana-web3.js/commit/288029a55a5eeb863b6df960027a59214ffc37f1), [`4ae78f5`](https://github.com/solana-labs/solana-web3.js/commit/4ae78f5cdddd6772b25351beb813483d4e52cea6), [`478443f`](https://github.com/solana-labs/solana-web3.js/commit/478443fedac06678f12e8ac285aa7c7fcf503ee8), [`125fc15`](https://github.com/solana-labs/solana-web3.js/commit/125fc1540cfbc0a4afdba5aabac0884c750e58c1)]: - - @solana/errors@2.0.0-preview.3 - - @solana/transactions@2.0.0-preview.3 - - @solana/addresses@2.0.0-preview.3 - - @solana/rpc-types@2.0.0-preview.3 - - @solana/programs@2.0.0-preview.3 - - @solana/codecs@2.0.0-preview.3 - - @solana/transaction-confirmation@2.0.0-preview.3 - - @solana/transaction-messages@2.0.0-preview.3 - - @solana/rpc-subscriptions@2.0.0-preview.3 - - @solana/rpc@2.0.0-preview.3 - - @solana/keys@2.0.0-preview.3 - - @solana/accounts@2.0.0-preview.3 - - @solana/instructions@2.0.0-preview.3 - - @solana/signers@2.0.0-preview.3 - - @solana/rpc-parsed-types@2.0.0-preview.3 - - @solana/functional@2.0.0-preview.3 - -## 2.0.0-preview.2 - -### Patch Changes - -- The first Technology Preview of `@solana/web3.js` 2.0 was [released at the Breakpoint conference](https://www.youtube.com/watch?v=JUJtAPhES5g) in November 2023. Based on your feedback, we want to get a second version of it into your hands now with some changes, bug fixes, and new features. - - To install the second Technology Preview: - - ```shell - npm install --save @solana/web3.js@tp2 - ``` - - Most notably, this release integrates with the new JavaScript client generator for on-chain programs. Instruction creators and account decoders can now be autogenerated for any program, including your own! Read more [here](https://github.com/solana-program/create-solana-program), and check out the growing list of autogenerated core programs [here](https://www.npmjs.com/search?q=%40solana-program). - - Try a demo of Technology Preview 2 in your browser at https://sola.na/web3tp2demo. - - - Renamed `Base58EncodedAddress` to `Address` (#1814) [63683a4bc](https://github.com/solana-labs/solana-web3.js/commit/63683a4bc) - - Renamed `Ed25519Signature` and `TransactionSignature` to `SignatureBytes` and `Signature` (#1815) [205c09268](https://github.com/solana-labs/solana-web3.js/commit/205c09268) - - Fixed return type of `getSignaturesForAddress` (#1821) [36c7263bd](https://github.com/solana-labs/solana-web3.js/commit/36c7263bd) - - `signTransaction` now asserts that the transaction is fully signed; added `partiallySignTransaction` that does not (#1820) [7d54c2dad](https://github.com/solana-labs/solana-web3.js/commit/7d54c2dad) - - The `@solana/webcrypto-ed25519-polyfill` now sets the `crypto` global in Node [17a54d24a](https://github.com/solana-labs/solana-web3.js/commit/17a54d24a) - - Added `assertIsBlockhashLifetimeTransaction` that asserts transaction has a blockhash lifetime (#1908) [ae94ca38d](https://github.com/solana-labs/solana-web3.js/commit/ae94ca38d) - - Added a `createPrivateKeyFromBytes` helper (#1913) [85b7dfe13](https://github.com/solana-labs/solana-web3.js/commit/85b7dfe13) - - Added `@solana/accounts`; types and helper methods for representing, fetching and decoding Solana accounts (#1855) [e1ca3966e](https://github.com/solana-labs/solana-web3.js/commit/e1ca3966e) - - Export the TransactionError type (#1964) [4c009bf5b](https://github.com/solana-labs/solana-web3.js/commit/4c009bf5b) - - Export all RPC method XApi types from `@solana/rpc-core` (#1965) [ed98b3d9c](https://github.com/solana-labs/solana-web3.js/commit/ed98b3d9c) - - Added a generic `createJsonRpcApi` function for custom APIs [1e2106f21](https://github.com/solana-labs/solana-web3.js/commit/1e2106f21) - - Added a generic `createJsonRpcSubscriptionsApi` function for custom APIs [ae3f1f087](https://github.com/solana-labs/solana-web3.js/commit/ae3f1f087) - - RPC commitment now defaults to `confirmed` when not explicitly specified [cb7702ca5](https://github.com/solana-labs/solana-web3.js/commit/cb7702ca5) - - Added `ClusterUrl` types and handlers (#2084) [61f7ba0](https://github.com/solana-labs/solana-web3.js/commit/61f7ba0) - - RPC transports can now be cluster-specific, ie. `RpcDevnet` & `RpcSubscriptionsDevnet` (#2053) [e58bb22](https://github.com/solana-labs/solana-web3.js/commit/e58bb22), (#2056) [cbf8f38](https://github.com/solana-labs/solana-web3.js/commit/cbf8f38) - - RPC APIs can now be cluster-specific, ie. `SolanaRpcMethodsDevnet` (#2054) [5175d8a](https://github.com/solana-labs/solana-web3.js/commit/5175d8a) - - Added cluster-level RPC support for `@solana/web3.js` (#2055) [5a6335d](https://github.com/solana-labs/solana-web3.js/commit/5a6335d), (#2058) [0e03ca9](https://github.com/solana-labs/solana-web3.js/commit/0e03ca9) - - Added `@solana/signers`; an abstraction layer over signing messages and transactions in Solana (#1710) [7c29a1e](https://github.com/solana-labs/solana-web3.js/commit/7c29a1e) - - Updated codec such that only one instance of `Uint8Array` is created when encoding data. This allows `Encoders` to set data at different offsets and therefore enables non-linear serialization (#1865) [7800e3b](https://github.com/solana-labs/solana-web3.js/commit/7800e3b) - - Added `FixedSize*` and `VariableSize*` type variants for `Codecs`, `Encoders` and `Decoders` (#1883) [5e58d5c](https://github.com/solana-labs/solana-web3.js/commit/5e58d5c) - - Repaired some inaccurate RPC method signatures (#2137) [bb65ba9](https://github.com/solana-labs/solana-web3.js/commit/bb65ba9) - - Renamed transaction/airdrop sender factories with the ‘Factory’ suffix (#2130) [2d1d49c](https://github.com/solana-labs/solana-web3.js/commit/2d1d49c5467e5cb13871067c3dc0f9c87f007b9f) - - All code now throws coded exceptions defined in `@solana/errors` which can be refined using `isSolanaError()` and decoded in production using `npx @solana/errors decode` (#2160) [3524f2c](https://github.com/solana-labs/solana-web3.js/commit/3524f2c583dbc663cf6dcb73a01b0beed6cfd136), (#2161) [94944b](https://github.com/solana-labs/solana-web3.js/commit/94944b65b9d957ca95653d66dc1f4805f1a36740), (#2213) [8541c2e](https://github.com/solana-labs/solana-web3.js/commit/8541c2ef860535514fa39c4b9a6a75276417ffaa), (#2220) [c9b2705](https://github.com/solana-labs/solana-web3.js/commit/c9b2705318724bbccb05efdb1ddc088dd82921b2), (#2207) [75a18e3](https://github.com/solana-labs/solana-web3.js/commit/75a18e30524078ea1e8c07133fd6c75fad357db3), (#2224) [613053d](https://github.com/solana-labs/solana-web3.js/commit/613053deab85e5a8703e241ab138ec51cc54885a), (#2226) [94fee67](https://github.com/solana-labs/solana-web3.js/commit/94fee67560faae1f41aeddb2e7c3d0d9078ab851), (#2228) [483c674](https://github.com/solana-labs/solana-web3.js/commit/483c674a8b19f146c7dba5f1eb64182f01fdcdc4), (#2235) [803b2d8](https://github.com/solana-labs/solana-web3.js/commit/803b2d88e9e39cecf18f03b2130507dea7230423), (#2236) [cf9c20c](https://github.com/solana-labs/solana-web3.js/commit/cf9c20ceed7186f5af704ee646344c42d4ec0084), (#2242) [9084fdd](https://github.com/solana-labs/solana-web3.js/commit/9084fddec79eebb9c00c70738e43b4bfb01bf352), (#2245) [e374ac6](https://github.com/solana-labs/solana-web3.js/commit/e374ac67ad48a121470d125a1d08485b8b529b2b), (#2186) [546263e](https://github.com/solana-labs/solana-web3.js/commit/546263e251c8a7b08949b01d0d51fa2398dc7fff), (#2187) [bea19d2](https://github.com/solana-labs/solana-web3.js/commit/bea19d209ea6b02351c21a878200f87da1e9b4be), (#2188) [2e0ae95](https://github.com/solana-labs/solana-web3.js/commit/2e0ae95ffc2738ae047249c7f64c46a95e9573d1), (#2189) [7712fc3](https://github.com/solana-labs/solana-web3.js/commit/7712fc32ef33bfe7f235d85d3ba2308ba6884143), (#2190) [7d67615](https://github.com/solana-labs/solana-web3.js/commit/7d67615ac1ae771810dfc544ecc17d664a0fc11d), (#2191) [0ba8f21](https://github.com/solana-labs/solana-web3.js/commit/0ba8f216d962d61e0f653404c4a9289e59712cc2), (#2192) [91a360d](https://github.com/solana-labs/solana-web3.js/commit/91a360daf5c66ac0f1bae7347298f25ae89329b2), (#2202) [a71a2db](https://github.com/solana-labs/solana-web3.js/commit/a71a2db4c35136c8650b56985bbd33c5413e1bbd), (#2286) [52a5d3d](https://github.com/solana-labs/solana-web3.js/commit/52a5d3db60e702ccf77b4d17b8a3fd388e6e8584), and more - - You can now supply a custom Undici dispatcher for use with the `fetch` API when creating an RPC transport in Node (#2178) [a2fc5a3](https://github.com/solana-labs/solana-web3.js/commit/a2fc5a3fda252cccc6ee62f2f7163d1578a20113) - - Added functions to assert a value is an `IInstructionWithAccounts` and IInstructionWithData` (#2212) [07c30c1](https://github.com/solana-labs/solana-web3.js/commit/07c30c14c7d5efd6121290db62fa40371f108778) - - Added a function to assert an instruction is for a given program (#2234) [fb655dd](https://github.com/solana-labs/solana-web3.js/commit/fb655ddd217e4c4f55c5c8a81a08177e20ef5431) - - You can now create an RPC using only a URL (#2238) [cd0b6c6](https://github.com/solana-labs/solana-web3.js/commit/cd0b6c616ded7d1fdee33e33d3e44ce9bce48cef), (#2239) [fc11993](https://github.com/solana-labs/solana-web3.js/commit/fc119937ade7e46f487c99f254ff5a874e524c2c) - - You can now resize codec with the `resizeCodec` helper (#2293) [606de63](https://github.com/solana-labs/solana-web3.js/commit/606de638e21eebd0535806dee445e6d046cfb074) - - You can now skip bytes while writing byte buffers using the `offsetCodec` helper (#2294) [09d8cc8](https://github.com/solana-labs/solana-web3.js/commit/09d8cc815d133d70da0db93c9a0c0092e0d9a929) - - You can now now pad the beginning or end of byte buffers using the `padLeftCodec` and `padRightCodec` helpers (#2314) [f9509c7](https://github.com/solana-labs/solana-web3.js/commit/f9509c77dd6ec92357edbbe18acbb76c5a33e4b2) - - Added a new `@solana/sysvars` package for fetching, decoding, and building transactions with sysvar accounts (#2041) - -- Updated dependencies [[`0546a8c`](https://github.com/solana-labs/solana-web3.js/commit/0546a8ce95b6852324d58bb32ac31480506193a7)]: - - @solana/accounts@2.0.0-preview.2 - - @solana/addresses@2.0.0-preview.2 - - @solana/codecs@2.0.0-preview.2 - - @solana/errors@2.0.0-preview.2 - - @solana/functional@2.0.0-preview.2 - - @solana/instructions@2.0.0-preview.2 - - @solana/keys@2.0.0-preview.2 - - @solana/programs@2.0.0-preview.2 - - @solana/rpc@2.0.0-preview.2 - - @solana/rpc-parsed-types@2.0.0-preview.2 - - @solana/rpc-subscriptions@2.0.0-preview.2 - - @solana/rpc-types@2.0.0-preview.2 - - @solana/signers@2.0.0-preview.2 - - @solana/transaction-confirmation@2.0.0-preview.2 - - @solana/transactions@2.0.0-preview.2 diff --git a/packages/library/LICENSE b/packages/library/LICENSE deleted file mode 100644 index ec09953d3..000000000 --- a/packages/library/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2023 Solana Labs, Inc - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/library/README.md b/packages/library/README.md deleted file mode 100644 index 26e7527b9..000000000 --- a/packages/library/README.md +++ /dev/null @@ -1,167 +0,0 @@ -[![npm][npm-image]][npm-url] -[![npm-downloads][npm-downloads-image]][npm-url] -
-[![code-style-prettier][code-style-prettier-image]][code-style-prettier-url] - -[code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square -[code-style-prettier-url]: https://github.com/prettier/prettier -[npm-downloads-image]: https://img.shields.io/npm/dm/@solana/web3.js/next.svg?style=flat -[npm-image]: https://img.shields.io/npm/v/@solana/web3.js/next.svg?style=flat -[npm-url]: https://www.npmjs.com/package/@solana/web3.js/v/next - -# @solana/web3.js - -This is the JavaScript SDK for building Solana apps for Node, web, and React Native. - -## Functions - -In addition to reexporting functions from packages in the `@solana/*` namespace, this package offers additional helpers for building Solana applications, with sensible defaults. - -### `airdropFactory({rpc, rpcSubscriptions})` - -Returns a function that you can call to airdrop a certain amount of `Lamports` to a Solana address. - -```ts -import { - address, - airdropFactory, - createSolanaRpc, - createSolanaRpcSubscriptions, - devnet, - lamports, -} from '@solana/web3.js'; - -const rpc = createSolanaRpc(devnet('http://127.0.0.1:8899')); -const rpcSubscriptions = createSolanaRpcSubscriptions(devnet('ws://127.0.0.1:8900')); - -const airdrop = airdropFactory({ rpc, rpcSubscriptions }); - -await airdrop({ - commitment: 'confirmed', - recipientAddress: address('FnHyam9w4NZoWR6mKN1CuGBritdsEWZQa4Z4oawLZGxa'), - lamports: lamports(10_000_000n), -}); -``` - -> [!NOTE] This only works on test clusters. - -### `decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc, config)` - -Returns a `TransactionMessage` from a `CompiledTransactionMessage`. If any of the accounts in the compiled message require an address lookup table to find their address, this function will use the supplied RPC instance to fetch the contents of the address lookup table from the network. - -### `fetchLookupTables(lookupTableAddresses, rpc, config)` - -Given a list of addresses belonging to address lookup tables, returns a map of lookup table addresses to an ordered array of the addresses they contain. - -### `getComputeUnitEstimateForTransactionMessageFactory({rpc})` - -Correctly budgeting a compute unit limit for your transaction message can increase the probability that your transaction will be accepted for processing. If you don't declare a compute unit limit on your transaction, validators will assume an upper limit of 200K compute units (CU) per instruction. - -Since validators have an incentive to pack as many transactions into each block as possible, they may choose to include transactions that they know will fit into the remaining compute budget for the current block over transactions that might not. For this reason, you should set a compute unit limit on each of your transaction messages, whenever possible. - -Use this utility to estimate the actual compute unit cost of a given transaction message. - -```ts -import { getSetComputeUnitLimitInstruction } from '@solana-program/compute-budget'; -import { createSolanaRpc, getComputeUnitEstimateForTransactionMessageFactory, pipe } from '@solana/web3.js'; - -// Create an estimator function. -const rpc = createSolanaRpc('http://127.0.0.1:8899'); -const getComputeUnitEstimateForTransactionMessage = getComputeUnitEstimateForTransactionMessageFactory({ - rpc, -}); - -// Create your transaction message. -const transactionMessage = pipe( - createTransactionMessage({ version: 'legacy' }), - /* ... */ -); - -// Request an estimate of the actual compute units this message will consume. -const computeUnitsEstimate = await getComputeUnitEstimateForTransactionMessage(transactionMessage); - -// Set the transaction message's compute unit budget. -const transactionMessageWithComputeUnitLimit = prependTransactionMessageInstruction( - getSetComputeUnitLimitInstruction({ units: computeUnitsEstimate }), - transactionMessage, -); -``` - -> [!WARNING] -> The compute unit estimate is just that – an estimate. The compute unit consumption of the actual transaction might be higher or lower than what was observed in simulation. Unless you are confident that your particular transaction message will consume the same or fewer compute units as was estimated, you might like to augment the estimate by either a fixed number of CUs or a multiplier. - -> [!NOTE] -> If you are preparing an _unsigned_ transaction, destined to be signed and submitted to the network by a wallet, you might like to leave it up to the wallet to determine the compute unit limit. Consider that the wallet might have a more global view of how many compute units certain types of transactions consume, and might be able to make better estimates of an appropriate compute unit budget. - -### `sendAndConfirmDurableNonceTransactionFactory({rpc, rpcSubscriptions})` - -Returns a function that you can call to send a nonce-based transaction to the network and to wait until it has been confirmed. - -```ts -import { - isSolanaError, - sendAndConfirmDurableNonceTransactionFactory, - SOLANA_ERROR__INVALID_NONCE, - SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND, -} from '@solana/web3.js'; - -const sendAndConfirmNonceTransaction = sendAndConfirmDurableNonceTransactionFactory({ rpc, rpcSubscriptions }); - -try { - await sendAndConfirmNonceTransaction(transaction, { commitment: 'confirmed' }); -} catch (e) { - if (isSolanaError(e, SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND)) { - console.error( - 'The lifetime specified by this transaction refers to a nonce account ' + - `\`${e.context.nonceAccountAddress}\` that does not exist`, - ); - } else if (isSolanaError(e, SOLANA_ERROR__INVALID_NONCE)) { - console.error('This transaction depends on a nonce that is no longer valid'); - } else { - throw e; - } -} -``` - -### `sendAndConfirmTransactionFactory({rpc, rpcSubscriptions})` - -Returns a function that you can call to send a blockhash-based transaction to the network and to wait until it has been confirmed. - -```ts -import { isSolanaError, sendAndConfirmTransactionFactory, SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED } from '@solana/web3.js'; - -const sendAndConfirmTransaction = sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions }); - -try { - await sendAndConfirmTransaction(transaction, { commitment: 'confirmed' }); -} catch (e) { - if (isSolanaError(e, SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED)) { - console.error('This transaction depends on a blockhash that has expired'); - } else { - throw e; - } -} -``` - -### `sendTransactionWithoutConfirmingFactory({rpc, rpcSubscriptions})` - -Returns a function that you can call to send a transaction with any kind of lifetime to the network without waiting for it to be confirmed. - -```ts -import { - sendTransactionWithoutConfirmingFactory, - SOLANA_ERROR__JSON_RPC__SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE, -} from '@solana/web3.js'; - -const sendTransaction = sendTransactionWithoutConfirmingFactory({ rpc }); - -try { - await sendTransaction(transaction, { commitment: 'confirmed' }); -} catch (e) { - if (isSolanaError(e, SOLANA_ERROR__JSON_RPC__SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE)) { - console.error('The transaction failed in simulation', e.cause); - } else { - throw e; - } -} -``` diff --git a/packages/library/package.json b/packages/library/package.json deleted file mode 100644 index 439159404..000000000 --- a/packages/library/package.json +++ /dev/null @@ -1,100 +0,0 @@ -{ - "name": "@solana/web3.js", - "version": "2.0.0", - "private": true, - "description": "Solana Javascript API", - "exports": { - "edge-light": { - "import": "./dist/index.node.mjs", - "require": "./dist/index.node.cjs" - }, - "workerd": { - "import": "./dist/index.node.mjs", - "require": "./dist/index.node.cjs" - }, - "browser": { - "import": "./dist/index.browser.mjs", - "require": "./dist/index.browser.cjs" - }, - "node": { - "import": "./dist/index.node.mjs", - "require": "./dist/index.node.cjs" - }, - "react-native": "./dist/index.native.mjs", - "types": "./dist/types/index.d.ts" - }, - "browser": { - "./dist/index.node.cjs": "./dist/index.browser.cjs", - "./dist/index.node.mjs": "./dist/index.browser.mjs" - }, - "jsdelivr": "./dist/index.production.min.js", - "umd": "./dist/index.production.min.js", - "unpkg": "./dist/index.production.min.js", - "main": "./dist/index.node.cjs", - "module": "./dist/index.node.mjs", - "react-native": "./dist/index.native.mjs", - "types": "./dist/types/index.d.ts", - "type": "commonjs", - "files": [ - "./dist/" - ], - "sideEffects": false, - "keywords": [ - "blockchain", - "solana", - "web3" - ], - "scripts": { - "compile:js": "tsup --config build-scripts/tsup.config.library.ts", - "compile:typedefs": "tsc -p ./tsconfig.declarations.json", - "dev": "jest -c ../../node_modules/@solana/test-config/jest-dev.config.ts --rootDir . --watch", - "style:fix": "pnpm eslint --fix src && pnpm prettier --log-level warn --ignore-unknown --write ./*", - "test:lint": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-lint.config.ts --rootDir . --silent", - "test:prettier": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-prettier.config.ts --rootDir . --silent", - "test:treeshakability:browser": "agadoo dist/index.browser.mjs", - "test:treeshakability:native": "agadoo dist/index.native.mjs", - "test:treeshakability:node": "agadoo dist/index.node.mjs", - "test:typecheck": "tsc --noEmit", - "test:unit:browser": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-unit.config.browser.ts --rootDir . --silent", - "test:unit:node": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-unit.config.node.ts --rootDir . --silent" - }, - "author": "Solana Labs Maintainers ", - "license": "MIT", - "repository": { - "type": "git", - "url": "https://github.com/anza-xyz/solana-web3.js" - }, - "bugs": { - "url": "http://github.com/anza-xyz/solana-web3.js/issues" - }, - "browserslist": [ - "supports bigint and not dead", - "maintained node versions" - ], - "dependencies": { - "@solana/accounts": "workspace:*", - "@solana/addresses": "workspace:*", - "@solana/codecs": "workspace:*", - "@solana/errors": "workspace:*", - "@solana/functional": "workspace:*", - "@solana/instructions": "workspace:*", - "@solana/keys": "workspace:*", - "@solana/programs": "workspace:*", - "@solana/rpc": "workspace:*", - "@solana/rpc-parsed-types": "workspace:*", - "@solana/rpc-subscriptions": "workspace:*", - "@solana/rpc-types": "workspace:*", - "@solana/rpc-spec-types": "workspace:*", - "@solana/signers": "workspace:*", - "@solana/sysvars": "workspace:*", - "@solana/transaction-confirmation": "workspace:*", - "@solana/transaction-messages": "workspace:*", - "@solana/transactions": "workspace:*" - }, - "peerDependencies": { - "typescript": ">=5" - }, - "engines": { - "node": ">=20.18.0" - } -} diff --git a/packages/library/src/__tests__/airdrop-internal-test.ts b/packages/library/src/__tests__/airdrop-internal-test.ts deleted file mode 100644 index 6afc3bdc8..000000000 --- a/packages/library/src/__tests__/airdrop-internal-test.ts +++ /dev/null @@ -1,114 +0,0 @@ -import type { Address } from '@solana/addresses'; -import type { Signature } from '@solana/keys'; -import type { GetSignatureStatusesApi, RequestAirdropApi, Rpc } from '@solana/rpc'; -import { lamports } from '@solana/rpc-types'; - -import { requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT } from '../airdrop-internal'; - -const FOREVER_PROMISE = new Promise(() => { - /* never resolve */ -}); - -describe('requestAndConfirmAirdrop', () => { - let confirmSignatureOnlyTransaction: jest.Mock; - let rpc: Rpc; - let requestAirdrop: jest.Mock; - let sendAirdropRequest: jest.Mock; - beforeEach(() => { - jest.useFakeTimers(); - confirmSignatureOnlyTransaction = jest.fn().mockReturnValue(FOREVER_PROMISE); - sendAirdropRequest = jest.fn().mockReturnValue(FOREVER_PROMISE); - requestAirdrop = jest.fn().mockReturnValue({ send: sendAirdropRequest }); - rpc = { - getSignatureStatuses: jest.fn().mockReturnValue({ send: jest.fn() }), - requestAirdrop, - }; - }); - it('aborts the `requestAirdrop` request when aborted', () => { - const abortController = new AbortController(); - requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({ - abortSignal: abortController.signal, - commitment: 'finalized', - confirmSignatureOnlyTransaction, - lamports: lamports(1n), - recipientAddress: '123' as Address, - rpc, - }).catch(() => {}); - expect(sendAirdropRequest).toHaveBeenCalledWith({ - abortSignal: expect.objectContaining({ aborted: false }), - }); - abortController.abort(); - expect(sendAirdropRequest).toHaveBeenCalledWith({ - abortSignal: expect.objectContaining({ aborted: true }), - }); - }); - it('aborts the `confirmSignatureOnlyTransaction` call when aborted', async () => { - expect.assertions(2); - const abortController = new AbortController(); - sendAirdropRequest.mockResolvedValue('abc' as Signature); - requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({ - abortSignal: abortController.signal, - commitment: 'finalized', - confirmSignatureOnlyTransaction, - lamports: lamports(1n), - recipientAddress: '123' as Address, - rpc, - }).catch(() => {}); - await jest.runAllTimersAsync(); - expect(confirmSignatureOnlyTransaction).toHaveBeenCalledWith( - expect.objectContaining({ - abortSignal: expect.objectContaining({ aborted: false }), - }), - ); - abortController.abort(); - expect(confirmSignatureOnlyTransaction).toHaveBeenCalledWith( - expect.objectContaining({ - abortSignal: expect.objectContaining({ aborted: true }), - }), - ); - }); - it('passes the expected input to the airdrop request', () => { - sendAirdropRequest.mockResolvedValue('abc' as Signature); - requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({ - abortSignal: new AbortController().signal, - commitment: 'finalized', - confirmSignatureOnlyTransaction, - lamports: lamports(1n), - recipientAddress: '123' as Address, - rpc, - }).catch(() => {}); - expect(requestAirdrop).toHaveBeenCalledWith('123', 1n, { commitment: 'finalized' }); - }); - it('passes the expected input to the transaction confirmer', async () => { - expect.assertions(1); - sendAirdropRequest.mockResolvedValue('abc' as Signature); - requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({ - abortSignal: new AbortController().signal, - commitment: 'finalized', - confirmSignatureOnlyTransaction, - lamports: lamports(1n), - recipientAddress: '123' as Address, - rpc, - }).catch(() => {}); - await jest.runAllTimersAsync(); - expect(confirmSignatureOnlyTransaction).toHaveBeenCalledWith({ - abortSignal: expect.any(AbortSignal), - commitment: 'finalized', - signature: 'abc' as Signature, - }); - }); - it('returns the airdrop transaction signature on success', async () => { - expect.assertions(1); - sendAirdropRequest.mockResolvedValue('abc' as Signature); - confirmSignatureOnlyTransaction.mockResolvedValue(undefined); - const airdropPromise = requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({ - abortSignal: new AbortController().signal, - commitment: 'finalized', - confirmSignatureOnlyTransaction, - lamports: lamports(1n), - recipientAddress: '123' as Address, - rpc, - }); - await expect(airdropPromise).resolves.toBe('abc'); - }); -}); diff --git a/packages/library/src/__tests__/compute-limit-internal-test.ts b/packages/library/src/__tests__/compute-limit-internal-test.ts deleted file mode 100644 index 73d4000f5..000000000 --- a/packages/library/src/__tests__/compute-limit-internal-test.ts +++ /dev/null @@ -1,279 +0,0 @@ -import { Address } from '@solana/addresses'; -import { - SOLANA_ERROR__INSTRUCTION_ERROR__INSUFFICIENT_FUNDS, - SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT, - SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT, - SolanaError, -} from '@solana/errors'; -import { AccountRole } from '@solana/instructions'; -import { Rpc, SimulateTransactionApi } from '@solana/rpc'; -import { Blockhash, TransactionError } from '@solana/rpc-types'; -import { ITransactionMessageWithFeePayer, Nonce, TransactionMessage } from '@solana/transaction-messages'; - -import { getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPORT } from '../compute-limit-internal'; - -const FOREVER_PROMISE = new Promise(() => { - /* never resolve */ -}); - -const MOCK_BLOCKHASH_LIFETIME_CONSTRAINT = { - blockhash: 'GNtuHnNyW68wviopST3ki37Afv7LPphxfSwiHAkX5Q9H' as Blockhash, - lastValidBlockHeight: 0n, -} as const; - -describe('getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPORT', () => { - let sendSimulateTransactionRequest: jest.Mock; - let mockTransactionMessage: ITransactionMessageWithFeePayer & TransactionMessage; - let rpc: Rpc; - let simulateTransaction: jest.Mock; - beforeEach(() => { - mockTransactionMessage = { - feePayer: { address: '7U8VWgTUucttJPt5Bbkt48WknWqRGBfstBt8qqLHnfPT' as Address }, - instructions: [], - version: 0, - }; - sendSimulateTransactionRequest = jest.fn().mockReturnValue(FOREVER_PROMISE); - simulateTransaction = jest.fn().mockReturnValue({ send: sendSimulateTransactionRequest }); - rpc = { - simulateTransaction, - }; - }); - it('aborts the `simulateTransaction` request when aborted', () => { - const abortController = new AbortController(); - getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPORT({ - abortSignal: abortController.signal, - rpc, - transactionMessage: { - ...mockTransactionMessage, - lifetimeConstraint: MOCK_BLOCKHASH_LIFETIME_CONSTRAINT, - }, - }).catch(() => {}); - expect(sendSimulateTransactionRequest).toHaveBeenCalledWith({ - abortSignal: expect.objectContaining({ aborted: false }), - }); - abortController.abort(); - expect(sendSimulateTransactionRequest).toHaveBeenCalledWith({ - abortSignal: expect.objectContaining({ aborted: true }), - }); - }); - it('passes the expected basic input to the simulation request', () => { - const transactionMessage = { - ...mockTransactionMessage, - lifetimeConstraint: MOCK_BLOCKHASH_LIFETIME_CONSTRAINT, - }; - getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPORT({ - commitment: 'finalized', - minContextSlot: 42n, - rpc, - transactionMessage, - }).catch(() => {}); - expect(simulateTransaction).toHaveBeenCalledWith( - expect.any(String), - expect.objectContaining({ - commitment: 'finalized', - encoding: 'base64', - minContextSlot: 42n, - sigVerify: false, - }), - ); - }); - it('appends a set compute unit limit instruction when one does not exist', async () => { - expect.assertions(1); - await jest.isolateModulesAsync(async () => { - jest.mock('@solana/transactions'); - const [ - { compileTransaction }, - { getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPORT }, - ] = await Promise.all([ - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - import('@solana/transactions'), - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - import('../compute-limit-internal'), - ]); - const transactionMessage = { - ...mockTransactionMessage, // No `SetComputeUnitLimit` instruction - lifetimeConstraint: MOCK_BLOCKHASH_LIFETIME_CONSTRAINT, - }; - getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPORT({ - rpc, - transactionMessage, - }).catch(() => {}); - expect(compileTransaction).toHaveBeenCalledWith({ - ...transactionMessage, - instructions: [ - ...transactionMessage.instructions, - { - data: - // prettier-ignore - new Uint8Array([ - 0x02, // SetComputeUnitLimit instruction inde - 0xc0, 0x5c, 0x15, 0x00, // 1,400,000, MAX_COMPUTE_UNITS - ]), - programAddress: 'ComputeBudget111111111111111111111111111111', - }, - ], - }); - }); - }); - it('replaces the existing set compute unit limit instruction when one exists', async () => { - expect.assertions(1); - await jest.isolateModulesAsync(async () => { - jest.mock('@solana/transactions'); - const [ - { compileTransaction }, - { getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPORT }, - ] = await Promise.all([ - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - import('@solana/transactions'), - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - import('../compute-limit-internal'), - ]); - const transactionMessage = { - ...mockTransactionMessage, - instructions: [ - { programAddress: '4Kk4nA3F2nWHCcuyT8nR6oF7HQUQHmmzAVD5k8FQPKB2' as Address }, - { - data: - // prettier-ignore - new Uint8Array([ - 0x02, // SetComputeUnitLimit instruction inde - 0x01, 0x02, 0x03, 0x04, // ComputeUnits(u32) - ]), - programAddress: 'ComputeBudget111111111111111111111111111111' as Address, - }, - { programAddress: '4Kk4nA3F2nWHCcuyT8nR6oF7HQUQHmmzAVD5k8FQPKB2' as Address }, - ], - lifetimeConstraint: MOCK_BLOCKHASH_LIFETIME_CONSTRAINT, - }; - getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPORT({ - rpc, - transactionMessage, - }).catch(() => {}); - expect(compileTransaction).toHaveBeenCalledWith( - expect.objectContaining({ - instructions: [ - transactionMessage.instructions[0], - { - ...transactionMessage.instructions[1], - data: new Uint8Array([0x02, 0xc0, 0x5c, 0x15, 0x00]), // Replaced with MAX_COMPUTE_UNITS - }, - transactionMessage.instructions[2], - ], - }), - ); - }); - }); - it('does not ask for a replacement blockhash when the transaction message is a durable nonce transaction', () => { - getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPORT({ - rpc, - transactionMessage: { - ...mockTransactionMessage, - instructions: [ - { - accounts: [ - { - address: '7wJFRFuAE9x5Ptnz2VoBWsfecTCfuuM2sQCpECGypnTU' as Address, - role: AccountRole.WRITABLE, - }, - { - address: 'SysvarRecentB1ockHashes11111111111111111111' as Address, - role: AccountRole.READONLY, - }, - { - address: 'HzMoc78z1VNNf9nwD4Czt6CDYEb9LVD8KsVGP46FEmyJ' as Address, - role: AccountRole.READONLY_SIGNER, - }, - ], - data: new Uint8Array([4, 0, 0, 0]), - programAddress: '11111111111111111111111111111111' as Address, - }, - ], - lifetimeConstraint: { - nonce: 'BzAqD6382v5r1pcELoi8HWrBDV4dSL9NGemMn2JYAhxc' as Nonce, - }, - }, - }).catch(() => {}); - expect(simulateTransaction).toHaveBeenCalledWith( - expect.anything(), - expect.objectContaining({ replaceRecentBlockhash: false }), - ); - }); - it('asks for a replacement blockhash even when the transaction message has a blockhash lifetime', () => { - getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPORT({ - rpc, - transactionMessage: { - ...mockTransactionMessage, - lifetimeConstraint: MOCK_BLOCKHASH_LIFETIME_CONSTRAINT, - }, - }).catch(() => {}); - expect(simulateTransaction).toHaveBeenCalledWith( - expect.anything(), - expect.objectContaining({ replaceRecentBlockhash: true }), - ); - }); - it('asks for a replacement blockhash when the transaction message has no lifetime', () => { - getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPORT({ - rpc, - transactionMessage: mockTransactionMessage, - }).catch(() => {}); - expect(simulateTransaction).toHaveBeenCalledWith( - expect.anything(), - expect.objectContaining({ replaceRecentBlockhash: true }), - ); - }); - it('returns the estimated compute units on success', async () => { - expect.assertions(1); - sendSimulateTransactionRequest.mockResolvedValue({ value: { unitsConsumed: 42n } }); - const estimatePromise = getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPORT({ - rpc, - transactionMessage: mockTransactionMessage, - }); - await expect(estimatePromise).resolves.toBe(42); - }); - it('caps the estimated compute units to MAX_COMPUTE_UNITS of 1.4M', async () => { - expect.assertions(1); - sendSimulateTransactionRequest.mockResolvedValue({ - value: { unitsConsumed: 1400000n /* MAX_COMPUTE_UNITS */ }, - }); - const estimatePromise = getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPORT({ - rpc, - transactionMessage: mockTransactionMessage, - }); - await expect(estimatePromise).resolves.toBe(1400000); - }); - it('throws with the transaction error as cause when the transaction fails in simulation', async () => { - expect.assertions(1); - const transactionError: TransactionError = 'AccountNotFound'; - sendSimulateTransactionRequest.mockResolvedValue({ value: { err: transactionError, unitsConsumed: 42n } }); - const estimatePromise = getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPORT({ - rpc, - transactionMessage: mockTransactionMessage, - }); - await expect(estimatePromise).rejects.toThrow( - new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT, { - cause: transactionError, - unitsConsumed: 42, - }), - ); - }); - it('throws with the cause when simulation fails', async () => { - expect.assertions(1); - const simulationError = new SolanaError(SOLANA_ERROR__INSTRUCTION_ERROR__INSUFFICIENT_FUNDS, { - index: 42, - }); - sendSimulateTransactionRequest.mockRejectedValue(simulationError); - const estimatePromise = getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPORT({ - rpc, - transactionMessage: mockTransactionMessage, - }); - await expect(estimatePromise).rejects.toThrow( - new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT, { - cause: simulationError, - }), - ); - }); -}); diff --git a/packages/library/src/__tests__/decompile-transaction-message-fetching-lookup-tables-test.ts b/packages/library/src/__tests__/decompile-transaction-message-fetching-lookup-tables-test.ts deleted file mode 100644 index b889bcefd..000000000 --- a/packages/library/src/__tests__/decompile-transaction-message-fetching-lookup-tables-test.ts +++ /dev/null @@ -1,362 +0,0 @@ -import { FetchAccountsConfig, fetchJsonParsedAccounts } from '@solana/accounts'; -import type { Address } from '@solana/addresses'; -import type { GetMultipleAccountsApi, Rpc } from '@solana/rpc'; -import type { Blockhash, Lamports } from '@solana/rpc-types'; -import { - CompiledTransactionMessage, - decompileTransactionMessage, - TransactionMessage, -} from '@solana/transaction-messages'; - -import { decompileTransactionMessageFetchingLookupTables } from '../decompile-transaction-message-fetching-lookup-tables'; - -jest.mock('@solana/accounts'); -jest.mock('@solana/transaction-messages'); - -describe('decompileTransactionMessageFetchingLookupTables', () => { - const blockhash = 'abc' as Blockhash; - const rpc: Rpc = { - getMultipleAccounts: jest.fn(), - }; - - describe('for a legacy transaction', () => { - const compiledTransactionMessage: CompiledTransactionMessage = { - // no `addressTableLookups` field - header: { - numReadonlyNonSignerAccounts: 0, - numReadonlySignerAccounts: 0, - numSignerAccounts: 0, - }, - instructions: [], - lifetimeToken: blockhash, - staticAccounts: [], - version: 'legacy', - }; - - const transactionMessage = { version: 'legacy' } as unknown as TransactionMessage; - - beforeEach(() => { - (decompileTransactionMessage as jest.Mock).mockReturnValue(transactionMessage); - // reset mock calls - jest.clearAllMocks(); - }); - - it('should return the result of `decompileTransactionMessage`', async () => { - expect.assertions(1); - await expect( - decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc), - ).resolves.toStrictEqual(transactionMessage); - }); - - it('should not call the `fetchJsonParsedAccounts` function', async () => { - expect.assertions(1); - await decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc); - expect(fetchJsonParsedAccounts).not.toHaveBeenCalled(); - }); - - it('should call `decompileTransactionMessage` with the input transaction', async () => { - expect.assertions(1); - await decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc); - expect(decompileTransactionMessage).toHaveBeenCalledWith( - compiledTransactionMessage, - expect.any(Object), // config - ); - }); - - it('should call the `decompileTransactionMessage` with no lookup tables', async () => { - expect.assertions(1); - await decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc); - expect(decompileTransactionMessage).toHaveBeenCalledWith( - expect.any(Object), // transaction - expect.objectContaining({ - addressesByLookupTableAddress: {}, - }), - ); - }); - - it('should pass `lastValidBlockHeight` to `decompileTransactionMessage`', async () => { - expect.assertions(1); - await decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc, { - lastValidBlockHeight: 100n, - }); - expect(decompileTransactionMessage).toHaveBeenCalledWith( - expect.any(Object), // transaction - expect.objectContaining({ - lastValidBlockHeight: 100n, - }), - ); - }); - }); - - describe('for a versioned transaction with no `addressTableLookups` field', () => { - const compiledTransactionMessage: CompiledTransactionMessage = { - // no `addressTableLookups` field - header: { - numReadonlyNonSignerAccounts: 0, - numReadonlySignerAccounts: 0, - numSignerAccounts: 0, - }, - instructions: [], - lifetimeToken: blockhash, - staticAccounts: [], - version: 0, - }; - - const transactionMessage = { version: 0 } as unknown as TransactionMessage; - - beforeEach(() => { - (decompileTransactionMessage as jest.Mock).mockReturnValue(transactionMessage); - // reset mock calls - jest.clearAllMocks(); - }); - - it('should return the result of `decompileTransactionMessage`', async () => { - expect.assertions(1); - await expect( - decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc), - ).resolves.toStrictEqual(transactionMessage); - }); - - it('should not call the `fetchJsonParsedAccounts` function', async () => { - expect.assertions(1); - await decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc); - expect(fetchJsonParsedAccounts).not.toHaveBeenCalled(); - }); - - it('should call `decompileTransactionMessage` with the input transaction', async () => { - expect.assertions(1); - await decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc); - expect(decompileTransactionMessage).toHaveBeenCalledWith( - compiledTransactionMessage, - expect.any(Object), // config - ); - }); - - it('should call `decompileTransactionMessage` with no lookup tables', async () => { - expect.assertions(1); - await decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc); - expect(decompileTransactionMessage).toHaveBeenCalledWith( - expect.any(Object), // transaction - expect.objectContaining({ - addressesByLookupTableAddress: {}, - }), - ); - }); - - it('should pass `lastValidBlockHeight` to `decompileTransactionMessage`', async () => { - expect.assertions(1); - await decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc, { - lastValidBlockHeight: 100n, - }); - expect(decompileTransactionMessage).toHaveBeenCalledWith( - expect.any(Object), // transaction - expect.objectContaining({ - lastValidBlockHeight: 100n, - }), - ); - }); - }); - - describe('for a versioned transaction with empty `addressTableLookups`', () => { - const compiledTransactionMessage: CompiledTransactionMessage = { - addressTableLookups: [], - header: { - numReadonlyNonSignerAccounts: 0, - numReadonlySignerAccounts: 0, - numSignerAccounts: 0, - }, - instructions: [], - lifetimeToken: blockhash, - staticAccounts: [], - version: 0, - }; - - const transactionMessage = { version: 0 } as unknown as TransactionMessage; - - beforeEach(() => { - (decompileTransactionMessage as jest.Mock).mockReturnValue(transactionMessage); - // reset mock calls - jest.clearAllMocks(); - }); - - it('should return the result of `decompileTransactionMessage`', async () => { - expect.assertions(1); - await expect( - decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc), - ).resolves.toStrictEqual(transactionMessage); - }); - - it('should not call the `fetchJsonParsedAccounts` function', async () => { - expect.assertions(1); - await decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc); - expect(fetchJsonParsedAccounts).not.toHaveBeenCalled(); - }); - - it('should call `decompileTransactionMessage` with the input transaction', async () => { - expect.assertions(1); - await decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc); - expect(decompileTransactionMessage).toHaveBeenCalledWith( - compiledTransactionMessage, - expect.any(Object), // config - ); - }); - - it('should call `decompileTransactionMessage` with no lookup tables', async () => { - expect.assertions(1); - await decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc); - expect(decompileTransactionMessage).toHaveBeenCalledWith( - expect.any(Object), // transaction - expect.objectContaining({ - addressesByLookupTableAddress: {}, - }), - ); - }); - - it('should pass `lastValidBlockHeight` to `decompileTransactionMessage`', async () => { - expect.assertions(1); - await decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc, { - lastValidBlockHeight: 100n, - }); - expect(decompileTransactionMessage).toHaveBeenCalledWith( - expect.any(Object), // transaction - expect.objectContaining({ - lastValidBlockHeight: 100n, - }), - ); - }); - }); - - describe('for a versioned transaction with non-empty `addressTableLookups`', () => { - const lookupTableAddress1 = '1111' as Address; - const lookupTableAddress2 = '2222' as Address; - - const compiledTransactionMessage: CompiledTransactionMessage = { - addressTableLookups: [ - { - lookupTableAddress: lookupTableAddress1, - readableIndices: [0], - writableIndices: [], - }, - { - lookupTableAddress: lookupTableAddress2, - readableIndices: [0], - writableIndices: [], - }, - ], - header: { - numReadonlyNonSignerAccounts: 0, - numReadonlySignerAccounts: 0, - numSignerAccounts: 0, - }, - instructions: [], - lifetimeToken: blockhash, - staticAccounts: [], - version: 0, - }; - - const transactionMessage = { version: 0 } as unknown as TransactionMessage; - - const addressInLookup1 = '3333' as Address; - const addressInLookup2 = '4444' as Address; - - const fetchedLookupTables: Awaited> = [ - { - address: lookupTableAddress1, - data: { - addresses: [addressInLookup1], - }, - executable: false, - exists: true, - lamports: 0n as Lamports, - programAddress: 'program' as Address, - space: 0n, - }, - { - address: lookupTableAddress2, - data: { - addresses: [addressInLookup2], - }, - executable: false, - exists: true, - lamports: 0n as Lamports, - programAddress: 'program' as Address, - space: 0n, - }, - ]; - - beforeEach(() => { - (decompileTransactionMessage as jest.Mock).mockReturnValue(transactionMessage); - (fetchJsonParsedAccounts as jest.Mock).mockResolvedValue(fetchedLookupTables); - - // reset mock calls - jest.clearAllMocks(); - }); - - it('should return the result of `decompileTransactionMessage`', async () => { - expect.assertions(1); - await expect( - decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc), - ).resolves.toStrictEqual(transactionMessage); - }); - - it('should call `fetchJsonParsedAccounts` with the lookup table addresses', async () => { - expect.assertions(1); - await decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc); - expect(fetchJsonParsedAccounts).toHaveBeenCalledWith(rpc, [lookupTableAddress1, lookupTableAddress2], {}); - }); - - it('should pass config to `fetchJsonParsedAccounts`', async () => { - expect.assertions(1); - const fetchAccountsConfig: FetchAccountsConfig = { - abortSignal: new AbortController().signal, - commitment: 'confirmed', - minContextSlot: 100n, - }; - await decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc, { - ...fetchAccountsConfig, - lastValidBlockHeight: 100n, - }); - expect(fetchJsonParsedAccounts).toHaveBeenCalledWith( - rpc, - [lookupTableAddress1, lookupTableAddress2], - fetchAccountsConfig, - ); - }); - - it('should call `decompileTransactionMessage` with the input transaction', async () => { - expect.assertions(1); - await decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc); - expect(decompileTransactionMessage).toHaveBeenCalledWith( - compiledTransactionMessage, - expect.any(Object), // config - ); - }); - - it('should call `decompileTransactionMessage` with the addresses from the lookup tables', async () => { - expect.assertions(1); - await decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc); - expect(decompileTransactionMessage).toHaveBeenCalledWith( - expect.any(Object), // transaction - expect.objectContaining({ - addressesByLookupTableAddress: { - [lookupTableAddress1]: [addressInLookup1], - [lookupTableAddress2]: [addressInLookup2], - }, - }), - ); - }); - - it('should pass `lastValidBlockHeight` to `decompileTransactionMessage`', async () => { - expect.assertions(1); - await decompileTransactionMessageFetchingLookupTables(compiledTransactionMessage, rpc, { - lastValidBlockHeight: 100n, - }); - expect(decompileTransactionMessage).toHaveBeenCalledWith( - expect.any(Object), // transaction - expect.objectContaining({ - lastValidBlockHeight: 100n, - }), - ); - }); - }); -}); diff --git a/packages/library/src/__tests__/fetch-lookup-tables-test.ts b/packages/library/src/__tests__/fetch-lookup-tables-test.ts deleted file mode 100644 index 605f0c657..000000000 --- a/packages/library/src/__tests__/fetch-lookup-tables-test.ts +++ /dev/null @@ -1,137 +0,0 @@ -import { Address } from '@solana/addresses'; -import { - SOLANA_ERROR__ACCOUNTS__EXPECTED_ALL_ACCOUNTS_TO_BE_DECODED, - SOLANA_ERROR__ACCOUNTS__ONE_OR_MORE_ACCOUNTS_NOT_FOUND, - SolanaError, -} from '@solana/errors'; -import { GetMultipleAccountsApi, Rpc } from '@solana/rpc'; - -import { fetchAddressesForLookupTables } from '../fetch-lookup-tables'; - -describe('fetchAddressesForLookupTables', () => { - describe('when no lookup table addresses are provided', () => { - it('returns an empty object', async () => { - expect.assertions(1); - const rpc = { - getMultipleAccounts: jest.fn(), - }; - - const lookupTableAddresses: Address[] = []; - const lookupTables = await fetchAddressesForLookupTables(lookupTableAddresses, rpc); - expect(lookupTables).toEqual({}); - }); - - it('does not call the RPC', async () => { - expect.assertions(1); - const rpc = { - getMultipleAccounts: jest.fn(), - }; - - const lookupTableAddresses: Address[] = []; - await fetchAddressesForLookupTables(lookupTableAddresses, rpc); - expect(rpc.getMultipleAccounts).not.toHaveBeenCalled(); - }); - }); - - describe('when lookup table addresses are provided', () => { - it('returns an object with the lookup table addresses as keys and the addresses as values', async () => { - expect.assertions(1); - - const rpc: Rpc = { - getMultipleAccounts: jest.fn().mockReturnValue({ - send: jest.fn().mockResolvedValue({ - value: [ - { - data: { - parsed: { - info: { - addresses: ['1111', '2222'], - }, - }, - }, - }, - { - data: { - parsed: { - info: { - addresses: ['3333'], - }, - }, - }, - }, - ], - }), - }), - }; - - const lookupTableAddresses: Address[] = ['abc' as Address, 'def' as Address]; - const lookupTables = await fetchAddressesForLookupTables(lookupTableAddresses, rpc); - - expect(lookupTables).toEqual({ - abc: ['1111', '2222'], - def: ['3333'], - }); - }); - - it('throws when the RPC returns invalid data', async () => { - expect.assertions(1); - - const rpc: Rpc = { - getMultipleAccounts: jest.fn().mockReturnValue({ - send: jest.fn().mockResolvedValue({ - value: [ - { - data: { - parsed: { - info: { - addresses: ['1111', '2222'], - }, - }, - }, - }, - { - data: ['', 'base64'], - }, - ], - }), - }), - }; - - const lookupTableAddresses: Address[] = ['abc' as Address, 'def' as Address]; - await expect(fetchAddressesForLookupTables(lookupTableAddresses, rpc)).rejects.toThrow( - new SolanaError(SOLANA_ERROR__ACCOUNTS__EXPECTED_ALL_ACCOUNTS_TO_BE_DECODED, { - addresses: ['def'], - }), - ); - }); - - it('throws when the RPC returns missing data', async () => { - expect.assertions(1); - - const rpc: Rpc = { - getMultipleAccounts: jest.fn().mockReturnValue({ - send: jest.fn().mockResolvedValue({ - value: [ - // returns abc, not def - { - data: { - parsed: { - info: { - addresses: ['1111', '2222'], - }, - }, - }, - }, - null, - ], - }), - }), - }; - - const lookupTableAddresses: Address[] = ['abc' as Address, 'def' as Address]; - await expect(fetchAddressesForLookupTables(lookupTableAddresses, rpc)).rejects.toThrow( - new SolanaError(SOLANA_ERROR__ACCOUNTS__ONE_OR_MORE_ACCOUNTS_NOT_FOUND, { addresses: ['def'] }), - ); - }); - }); -}); diff --git a/packages/library/src/__tests__/send-transaction-internal-test.ts b/packages/library/src/__tests__/send-transaction-internal-test.ts deleted file mode 100644 index 15de7ac81..000000000 --- a/packages/library/src/__tests__/send-transaction-internal-test.ts +++ /dev/null @@ -1,330 +0,0 @@ -import { Signature } from '@solana/keys'; -import type { Rpc, SendTransactionApi } from '@solana/rpc'; -import type { Commitment } from '@solana/rpc-types'; -import { - Base64EncodedWireTransaction, - FullySignedTransaction, - getBase64EncodedWireTransaction, - TransactionWithBlockhashLifetime, - TransactionWithDurableNonceLifetime, -} from '@solana/transactions'; - -import { - sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT, - sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT, -} from '../send-transaction-internal'; - -jest.mock('@solana/transactions'); - -const FOREVER_PROMISE = new Promise(() => { - /* never resolve */ -}); - -describe('sendAndConfirmTransaction', () => { - const MOCK_TRANSACTION = {} as FullySignedTransaction & TransactionWithBlockhashLifetime; - let confirmRecentTransaction: jest.Mock; - let createPendingRequest: jest.Mock; - let rpc: Rpc; - let sendTransaction: jest.Mock; - beforeEach(() => { - jest.useFakeTimers(); - confirmRecentTransaction = jest.fn().mockReturnValue(FOREVER_PROMISE); - sendTransaction = jest.fn().mockReturnValue(FOREVER_PROMISE); - createPendingRequest = jest.fn().mockReturnValue({ send: sendTransaction }); - rpc = { - sendTransaction: createPendingRequest, - }; - jest.mocked(getBase64EncodedWireTransaction).mockReturnValue( - 'MOCK_WIRE_TRANSACTION' as Base64EncodedWireTransaction, - ); - }); - it('encodes the transaction into wire format before sending', () => { - sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({ - abortSignal: new AbortController().signal, - commitment: 'finalized', - confirmRecentTransaction, - rpc, - transaction: MOCK_TRANSACTION, - }).catch(() => {}); - expect(getBase64EncodedWireTransaction).toHaveBeenCalledWith(MOCK_TRANSACTION); - expect(createPendingRequest).toHaveBeenCalledWith('MOCK_WIRE_TRANSACTION', expect.anything()); - }); - it('calls `sendTransaction` with the expected inputs', () => { - const sendTransactionConfig = { - maxRetries: 42n, - minContextSlot: 123n, - preflightCommitment: 'confirmed' as Commitment, - skipPreflight: false, - } as Parameters[1]; - sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({ - ...sendTransactionConfig, - abortSignal: new AbortController().signal, - commitment: 'finalized' as Commitment, - confirmRecentTransaction, - rpc, - transaction: MOCK_TRANSACTION, - }).catch(() => {}); - expect(getBase64EncodedWireTransaction).toHaveBeenCalledWith(MOCK_TRANSACTION); - expect(createPendingRequest).toHaveBeenCalledWith('MOCK_WIRE_TRANSACTION', { - ...sendTransactionConfig, - encoding: 'base64', - }); - }); - it('calls `confirmRecentTransaction` with the expected inputs', async () => { - expect.assertions(1); - const sendTransactionConfig = { - maxRetries: 42n, - minContextSlot: 123n, - preflightCommitment: 'confirmed' as Commitment, - skipPreflight: false, - } as Parameters[1]; - sendTransaction.mockResolvedValue('abc' as Signature); - const abortSignal = new AbortController().signal; - sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({ - ...sendTransactionConfig, - abortSignal, - commitment: 'finalized' as Commitment, - confirmRecentTransaction, - rpc, - transaction: MOCK_TRANSACTION, - }).catch(() => {}); - await jest.runAllTimersAsync(); - expect(confirmRecentTransaction).toHaveBeenCalledWith({ - abortSignal, - commitment: 'finalized', - transaction: MOCK_TRANSACTION, - }); - }); - it.each` - commitment | expectedPreflightCommitment - ${'processed'} | ${'processed'} - ${'confirmed'} | ${'confirmed'} - `( - 'when missing a `preflightCommitment` and the commitment is $commitment, applies a downgraded `preflightCommitment`', - ({ commitment, expectedPreflightCommitment }) => { - sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({ - abortSignal: new AbortController().signal, - commitment, - confirmRecentTransaction, - rpc, - transaction: MOCK_TRANSACTION, - }).catch(() => {}); - expect(createPendingRequest).toHaveBeenCalledWith( - expect.anything(), - expect.objectContaining({ - preflightCommitment: expectedPreflightCommitment, - }), - ); - }, - ); - it.each` - commitment | preflightCommitment | expectedPreflightCommitment - ${'processed'} | ${'processed'} | ${'processed'} - ${'processed'} | ${'confirmed'} | ${'confirmed'} - ${'processed'} | ${'finalized'} | ${'finalized'} - ${'confirmed'} | ${'processed'} | ${'processed'} - ${'confirmed'} | ${'confirmed'} | ${'confirmed'} - ${'confirmed'} | ${'finalized'} | ${'finalized'} - ${'finalized'} | ${'processed'} | ${'processed'} - ${'finalized'} | ${'confirmed'} | ${'confirmed'} - ${'finalized'} | ${'finalized'} | ${'finalized'} - `( - 'honours the explicit `preflightCommitment` no matter that the commitment is $commitment', - ({ commitment, preflightCommitment, expectedPreflightCommitment }) => { - sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({ - abortSignal: new AbortController().signal, - commitment, - confirmRecentTransaction, - preflightCommitment, - rpc, - transaction: MOCK_TRANSACTION, - }).catch(() => {}); - expect(createPendingRequest).toHaveBeenCalledWith( - expect.anything(), - expect.objectContaining({ - preflightCommitment: expectedPreflightCommitment, - }), - ); - }, - ); - it('when missing a `preflightCommitment` and the commitment is the same as the server default for `preflightCommitment`, does not apply a `preflightCommitment`', () => { - expect.assertions(1); - sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({ - abortSignal: new AbortController().signal, - commitment: 'finalized', - confirmRecentTransaction, - rpc, - transaction: MOCK_TRANSACTION, - }).catch(() => {}); - expect(createPendingRequest.mock.lastCall![1]).not.toHaveProperty('preflightCommitment'); - }); - it('returns the signature of the transaction', async () => { - expect.assertions(1); - sendTransaction.mockResolvedValue('abc'); - confirmRecentTransaction.mockResolvedValue(undefined); - await expect( - sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({ - abortSignal: new AbortController().signal, - commitment: 'finalized', - confirmRecentTransaction, - rpc, - transaction: MOCK_TRANSACTION, - }), - ).resolves.toBe('abc'); - }); -}); - -describe('sendAndConfirmDurableNonceTransaction', () => { - const MOCK_DURABLE_NONCE_TRANSACTION = {} as unknown as FullySignedTransaction & - TransactionWithDurableNonceLifetime; - let confirmDurableNonceTransaction: jest.Mock; - let createPendingRequest: jest.Mock; - let rpc: Rpc; - let sendTransaction: jest.Mock; - beforeEach(() => { - jest.useFakeTimers(); - confirmDurableNonceTransaction = jest.fn().mockReturnValue(FOREVER_PROMISE); - sendTransaction = jest.fn().mockReturnValue(FOREVER_PROMISE); - createPendingRequest = jest.fn().mockReturnValue({ send: sendTransaction }); - rpc = { - sendTransaction: createPendingRequest, - }; - jest.mocked(getBase64EncodedWireTransaction).mockReturnValue( - 'MOCK_WIRE_TRANSACTION' as Base64EncodedWireTransaction, - ); - }); - it('encodes the transaction into wire format before sending', () => { - sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({ - abortSignal: new AbortController().signal, - commitment: 'finalized', - confirmDurableNonceTransaction, - rpc, - transaction: MOCK_DURABLE_NONCE_TRANSACTION, - }).catch(() => {}); - expect(getBase64EncodedWireTransaction).toHaveBeenCalledWith(MOCK_DURABLE_NONCE_TRANSACTION); - expect(createPendingRequest).toHaveBeenCalledWith('MOCK_WIRE_TRANSACTION', expect.anything()); - }); - it('calls `sendTransaction` with the expected inputs', () => { - const sendTransactionConfig = { - maxRetries: 42n, - minContextSlot: 123n, - preflightCommitment: 'confirmed' as Commitment, - skipPreflight: false, - } as Parameters[1]; - sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({ - ...sendTransactionConfig, - abortSignal: new AbortController().signal, - commitment: 'finalized' as Commitment, - confirmDurableNonceTransaction, - rpc, - transaction: MOCK_DURABLE_NONCE_TRANSACTION, - }).catch(() => {}); - expect(getBase64EncodedWireTransaction).toHaveBeenCalledWith(MOCK_DURABLE_NONCE_TRANSACTION); - expect(createPendingRequest).toHaveBeenCalledWith('MOCK_WIRE_TRANSACTION', { - ...sendTransactionConfig, - encoding: 'base64', - }); - }); - it('calls `confirmDurableNonceTransaction` with the expected inputs', async () => { - expect.assertions(1); - const sendTransactionConfig = { - maxRetries: 42n, - minContextSlot: 123n, - preflightCommitment: 'confirmed' as Commitment, - skipPreflight: false, - } as Parameters[1]; - sendTransaction.mockResolvedValue('abc' as Signature); - const abortSignal = new AbortController().signal; - sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({ - ...sendTransactionConfig, - abortSignal, - commitment: 'finalized' as Commitment, - confirmDurableNonceTransaction, - rpc, - transaction: MOCK_DURABLE_NONCE_TRANSACTION, - }).catch(() => {}); - await jest.runAllTimersAsync(); - expect(confirmDurableNonceTransaction).toHaveBeenCalledWith({ - abortSignal, - commitment: 'finalized', - transaction: MOCK_DURABLE_NONCE_TRANSACTION, - }); - }); - it.each` - commitment | expectedPreflightCommitment - ${'processed'} | ${'processed'} - ${'confirmed'} | ${'confirmed'} - `( - 'when missing a `preflightCommitment` and the commitment is $commitment, applies a downgraded `preflightCommitment`', - ({ commitment, expectedPreflightCommitment }) => { - sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({ - abortSignal: new AbortController().signal, - commitment, - confirmDurableNonceTransaction, - rpc, - transaction: MOCK_DURABLE_NONCE_TRANSACTION, - }).catch(() => {}); - expect(createPendingRequest).toHaveBeenCalledWith( - expect.anything(), - expect.objectContaining({ - preflightCommitment: expectedPreflightCommitment, - }), - ); - }, - ); - it.each` - commitment | preflightCommitment | expectedPreflightCommitment - ${'processed'} | ${'processed'} | ${'processed'} - ${'processed'} | ${'confirmed'} | ${'confirmed'} - ${'processed'} | ${'finalized'} | ${'finalized'} - ${'confirmed'} | ${'processed'} | ${'processed'} - ${'confirmed'} | ${'confirmed'} | ${'confirmed'} - ${'confirmed'} | ${'finalized'} | ${'finalized'} - ${'finalized'} | ${'processed'} | ${'processed'} - ${'finalized'} | ${'confirmed'} | ${'confirmed'} - ${'finalized'} | ${'finalized'} | ${'finalized'} - `( - 'honours the explicit `preflightCommitment` no matter that the commitment is $commitment', - ({ commitment, preflightCommitment, expectedPreflightCommitment }) => { - sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({ - abortSignal: new AbortController().signal, - commitment, - confirmDurableNonceTransaction, - preflightCommitment, - rpc, - transaction: MOCK_DURABLE_NONCE_TRANSACTION, - }).catch(() => {}); - expect(createPendingRequest).toHaveBeenCalledWith( - expect.anything(), - expect.objectContaining({ - preflightCommitment: expectedPreflightCommitment, - }), - ); - }, - ); - it('when missing a `preflightCommitment` and the commitment is the same as the server default for `preflightCommitment`, does not apply a `preflightCommitment`', () => { - expect.assertions(1); - sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({ - abortSignal: new AbortController().signal, - commitment: 'finalized', - confirmDurableNonceTransaction, - rpc, - transaction: MOCK_DURABLE_NONCE_TRANSACTION, - }).catch(() => {}); - expect(createPendingRequest.mock.lastCall![1]).not.toHaveProperty('preflightCommitment'); - }); - it('returns the signature of the transaction', async () => { - expect.assertions(1); - sendTransaction.mockResolvedValue('abc'); - confirmDurableNonceTransaction.mockResolvedValue(undefined); - await expect( - sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({ - abortSignal: new AbortController().signal, - commitment: 'finalized', - confirmDurableNonceTransaction, - rpc, - transaction: MOCK_DURABLE_NONCE_TRANSACTION, - }), - ).resolves.toBe('abc'); - }); -}); diff --git a/packages/library/src/__typetests__/airdrop-typetests.ts b/packages/library/src/__typetests__/airdrop-typetests.ts deleted file mode 100644 index 895b908d1..000000000 --- a/packages/library/src/__typetests__/airdrop-typetests.ts +++ /dev/null @@ -1,62 +0,0 @@ -/* eslint-disable @typescript-eslint/ban-ts-comment */ -import { GetSignatureStatusesApi, RequestAirdropApi, Rpc, RpcDevnet, RpcMainnet, RpcTestnet } from '@solana/rpc'; -import { - RpcSubscriptions, - RpcSubscriptionsDevnet, - RpcSubscriptionsMainnet, - RpcSubscriptionsTestnet, - SignatureNotificationsApi, -} from '@solana/rpc-subscriptions'; - -import { airdropFactory } from '../airdrop'; - -const rpc = null as unknown as Rpc; -const rpcDevnet = null as unknown as RpcDevnet; -const rpcTestnet = null as unknown as RpcTestnet; -const rpcMainnet = null as unknown as RpcMainnet; -// No sense discriminating against RPCs who decide to offer mainnet airdrops! -const rpcMainnetWithAirdrop = null as unknown as RpcMainnet; - -const rpcSubscriptions = null as unknown as RpcSubscriptions; -const rpcSubscriptionsDevnet = null as unknown as RpcSubscriptionsDevnet; -const rpcSubscriptionsMainnet = null as unknown as RpcSubscriptionsMainnet; -const rpcSubscriptionsTestnet = null as unknown as RpcSubscriptionsTestnet; - -// [DESCRIBE] airdropFactory -{ - { - // It typechecks when the RPC clusters match and have the `RequestAirdropApi` - airdropFactory({ rpc, rpcSubscriptions }); - airdropFactory({ rpc: rpcDevnet, rpcSubscriptions: rpcSubscriptionsDevnet }); - airdropFactory({ rpc: rpcTestnet, rpcSubscriptions: rpcSubscriptionsTestnet }); - airdropFactory({ rpc: rpcMainnetWithAirdrop, rpcSubscriptions: rpcSubscriptionsMainnet }); - } - { - // It typechecks when either RPC is generic - airdropFactory({ rpc, rpcSubscriptions }); - airdropFactory({ rpc: rpcDevnet, rpcSubscriptions }); - airdropFactory({ rpc: rpcTestnet, rpcSubscriptions }); - airdropFactory({ rpc, rpcSubscriptions: rpcSubscriptionsDevnet }); - airdropFactory({ rpc, rpcSubscriptions: rpcSubscriptionsTestnet }); - } - { - // It fails to typecheck when used with an RPC that doesn't have `RequestAirdropApi` - // @ts-expect-error - airdropFactory({ rpc: rpcMainnet, rpcSubscriptions: rpcSubscriptionsMainnet }); - } - { - // It fails to typecheck when explicit RPC clusters mismatch - // @ts-expect-error - airdropFactory({ rpc: rpcDevnet, rpcSubscriptions: rpcSubscriptionsTestnet }); - // @ts-expect-error - airdropFactory({ rpc: rpcDevnet, rpcSubscriptions: rpcSubscriptionsMainnet }); - // @ts-expect-error - airdropFactory({ rpc: rpcTestnet, rpcSubscriptions: rpcSubscriptionsMainnet }); - // @ts-expect-error - airdropFactory({ rpc: rpcTestnet, rpcSubscriptions: rpcSubscriptionsDevnet }); - // @ts-expect-error - airdropFactory({ rpc: rpcMainnetWithAirdrop, rpcSubscriptions: rpcSubscriptionsDevnet }); - // @ts-expect-error - airdropFactory({ rpc: rpcMainnetWithAirdrop, rpcSubscriptions: rpcSubscriptionsTestnet }); - } -} diff --git a/packages/library/src/__typetests__/send-and-confirm-durable-nonce-transaction-typetests.ts b/packages/library/src/__typetests__/send-and-confirm-durable-nonce-transaction-typetests.ts deleted file mode 100644 index 6850fca23..000000000 --- a/packages/library/src/__typetests__/send-and-confirm-durable-nonce-transaction-typetests.ts +++ /dev/null @@ -1,69 +0,0 @@ -/* eslint-disable @typescript-eslint/ban-ts-comment */ -import { - GetAccountInfoApi, - GetSignatureStatusesApi, - Rpc, - RpcDevnet, - RpcMainnet, - RpcTestnet, - SendTransactionApi, -} from '@solana/rpc'; -import { - AccountNotificationsApi, - RpcSubscriptions, - RpcSubscriptionsDevnet, - RpcSubscriptionsMainnet, - RpcSubscriptionsTestnet, - SignatureNotificationsApi, -} from '@solana/rpc-subscriptions'; - -import { sendAndConfirmDurableNonceTransactionFactory } from '../send-and-confirm-durable-nonce-transaction'; - -const rpc = null as unknown as Rpc; -const rpcDevnet = null as unknown as RpcDevnet; -const rpcTestnet = null as unknown as RpcTestnet; -const rpcMainnet = null as unknown as RpcMainnet; - -const rpcSubscriptions = null as unknown as RpcSubscriptions; -const rpcSubscriptionsDevnet = null as unknown as RpcSubscriptionsDevnet< - AccountNotificationsApi & SignatureNotificationsApi ->; -const rpcSubscriptionsMainnet = null as unknown as RpcSubscriptionsMainnet< - AccountNotificationsApi & SignatureNotificationsApi ->; -const rpcSubscriptionsTestnet = null as unknown as RpcSubscriptionsTestnet< - AccountNotificationsApi & SignatureNotificationsApi ->; - -// [DESCRIBE] sendAndConfirmDurableNonceTransactionFactory -{ - { - // It typechecks when the RPC clusters match. - sendAndConfirmDurableNonceTransactionFactory({ rpc, rpcSubscriptions }); - sendAndConfirmDurableNonceTransactionFactory({ rpc: rpcDevnet, rpcSubscriptions: rpcSubscriptionsDevnet }); - sendAndConfirmDurableNonceTransactionFactory({ rpc: rpcTestnet, rpcSubscriptions: rpcSubscriptionsTestnet }); - sendAndConfirmDurableNonceTransactionFactory({ rpc: rpcMainnet, rpcSubscriptions: rpcSubscriptionsMainnet }); - } - { - // It typechecks when either RPC is generic. - sendAndConfirmDurableNonceTransactionFactory({ rpc, rpcSubscriptions }); - sendAndConfirmDurableNonceTransactionFactory({ rpc: rpcDevnet, rpcSubscriptions }); - sendAndConfirmDurableNonceTransactionFactory({ rpc: rpcTestnet, rpcSubscriptions }); - sendAndConfirmDurableNonceTransactionFactory({ rpc: rpcMainnet, rpcSubscriptions }); - } - { - // It fails to typecheck when explicit RPC clusters mismatch. - // @ts-expect-error - sendAndConfirmDurableNonceTransactionFactory({ rpc: rpcDevnet, rpcSubscriptions: rpcSubscriptionsTestnet }); - // @ts-expect-error - sendAndConfirmDurableNonceTransactionFactory({ rpc: rpcDevnet, rpcSubscriptions: rpcSubscriptionsMainnet }); - // @ts-expect-error - sendAndConfirmDurableNonceTransactionFactory({ rpc: rpcTestnet, rpcSubscriptions: rpcSubscriptionsMainnet }); - // @ts-expect-error - sendAndConfirmDurableNonceTransactionFactory({ rpc: rpcTestnet, rpcSubscriptions: rpcSubscriptionsDevnet }); - // @ts-expect-error - sendAndConfirmDurableNonceTransactionFactory({ rpc: rpcMainnet, rpcSubscriptions: rpcSubscriptionsDevnet }); - // @ts-expect-error - sendAndConfirmDurableNonceTransactionFactory({ rpc: rpcMainnet, rpcSubscriptions: rpcSubscriptionsTestnet }); - } -} diff --git a/packages/library/src/__typetests__/send-and-confirm-transaction-typetests.ts b/packages/library/src/__typetests__/send-and-confirm-transaction-typetests.ts deleted file mode 100644 index 3ad5cc14e..000000000 --- a/packages/library/src/__typetests__/send-and-confirm-transaction-typetests.ts +++ /dev/null @@ -1,69 +0,0 @@ -/* eslint-disable @typescript-eslint/ban-ts-comment */ -import { - GetEpochInfoApi, - GetSignatureStatusesApi, - Rpc, - RpcDevnet, - RpcMainnet, - RpcTestnet, - SendTransactionApi, -} from '@solana/rpc'; -import { - RpcSubscriptions, - RpcSubscriptionsDevnet, - RpcSubscriptionsMainnet, - RpcSubscriptionsTestnet, - SignatureNotificationsApi, - SlotNotificationsApi, -} from '@solana/rpc-subscriptions'; - -import { sendAndConfirmTransactionFactory } from '../send-and-confirm-transaction'; - -const rpc = null as unknown as Rpc; -const rpcDevnet = null as unknown as RpcDevnet; -const rpcTestnet = null as unknown as RpcTestnet; -const rpcMainnet = null as unknown as RpcMainnet; - -const rpcSubscriptions = null as unknown as RpcSubscriptions; -const rpcSubscriptionsDevnet = null as unknown as RpcSubscriptionsDevnet< - SignatureNotificationsApi & SlotNotificationsApi ->; -const rpcSubscriptionsMainnet = null as unknown as RpcSubscriptionsMainnet< - SignatureNotificationsApi & SlotNotificationsApi ->; -const rpcSubscriptionsTestnet = null as unknown as RpcSubscriptionsTestnet< - SignatureNotificationsApi & SlotNotificationsApi ->; - -// [DESCRIBE] sendAndConfirmTransactionFactory -{ - { - // It typechecks when the RPC clusters match. - sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions }); - sendAndConfirmTransactionFactory({ rpc: rpcDevnet, rpcSubscriptions: rpcSubscriptionsDevnet }); - sendAndConfirmTransactionFactory({ rpc: rpcTestnet, rpcSubscriptions: rpcSubscriptionsTestnet }); - sendAndConfirmTransactionFactory({ rpc: rpcMainnet, rpcSubscriptions: rpcSubscriptionsMainnet }); - } - { - // It typechecks when either RPC is generic. - sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions }); - sendAndConfirmTransactionFactory({ rpc: rpcDevnet, rpcSubscriptions }); - sendAndConfirmTransactionFactory({ rpc: rpcTestnet, rpcSubscriptions }); - sendAndConfirmTransactionFactory({ rpc: rpcMainnet, rpcSubscriptions }); - } - { - // It fails to typecheck when explicit RPC clusters mismatch. - // @ts-expect-error - sendAndConfirmTransactionFactory({ rpc: rpcDevnet, rpcSubscriptions: rpcSubscriptionsTestnet }); - // @ts-expect-error - sendAndConfirmTransactionFactory({ rpc: rpcDevnet, rpcSubscriptions: rpcSubscriptionsMainnet }); - // @ts-expect-error - sendAndConfirmTransactionFactory({ rpc: rpcTestnet, rpcSubscriptions: rpcSubscriptionsMainnet }); - // @ts-expect-error - sendAndConfirmTransactionFactory({ rpc: rpcTestnet, rpcSubscriptions: rpcSubscriptionsDevnet }); - // @ts-expect-error - sendAndConfirmTransactionFactory({ rpc: rpcMainnet, rpcSubscriptions: rpcSubscriptionsDevnet }); - // @ts-expect-error - sendAndConfirmTransactionFactory({ rpc: rpcMainnet, rpcSubscriptions: rpcSubscriptionsTestnet }); - } -} diff --git a/packages/library/src/airdrop-internal.ts b/packages/library/src/airdrop-internal.ts deleted file mode 100644 index a958efaf3..000000000 --- a/packages/library/src/airdrop-internal.ts +++ /dev/null @@ -1,38 +0,0 @@ -import type { Address } from '@solana/addresses'; -import type { Signature } from '@solana/keys'; -import type { RequestAirdropApi, Rpc } from '@solana/rpc'; -import type { Commitment, Lamports } from '@solana/rpc-types'; -import { waitForRecentTransactionConfirmationUntilTimeout } from '@solana/transaction-confirmation'; - -type RequestAndConfirmAirdropConfig = Readonly<{ - abortSignal?: AbortSignal; - commitment: Commitment; - confirmSignatureOnlyTransaction: ( - config: Omit< - Parameters[0], - 'getRecentSignatureConfirmationPromise' | 'getTimeoutPromise' - >, - ) => Promise; - lamports: Lamports; - recipientAddress: Address; - rpc: Rpc; -}>; - -export async function requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({ - abortSignal, - commitment, - confirmSignatureOnlyTransaction, - lamports, - recipientAddress, - rpc, -}: RequestAndConfirmAirdropConfig): Promise { - const airdropTransactionSignature = await rpc - .requestAirdrop(recipientAddress, lamports, { commitment }) - .send({ abortSignal }); - await confirmSignatureOnlyTransaction({ - abortSignal, - commitment, - signature: airdropTransactionSignature, - }); - return airdropTransactionSignature; -} diff --git a/packages/library/src/airdrop.ts b/packages/library/src/airdrop.ts deleted file mode 100644 index 5a77594b8..000000000 --- a/packages/library/src/airdrop.ts +++ /dev/null @@ -1,54 +0,0 @@ -import type { Signature } from '@solana/keys'; -import type { GetSignatureStatusesApi, RequestAirdropApi, Rpc } from '@solana/rpc'; -import type { RpcSubscriptions, SignatureNotificationsApi } from '@solana/rpc-subscriptions'; -import { - createRecentSignatureConfirmationPromiseFactory, - getTimeoutPromise, - waitForRecentTransactionConfirmationUntilTimeout, -} from '@solana/transaction-confirmation'; - -import { requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT } from './airdrop-internal'; - -type AirdropFunction = ( - config: Omit< - Parameters[0], - 'confirmSignatureOnlyTransaction' | 'rpc' - >, -) => Promise; - -type AirdropFactoryConfig = { - rpc: Rpc & { '~cluster'?: TCluster }; - rpcSubscriptions: RpcSubscriptions & { '~cluster'?: TCluster }; -}; - -export function airdropFactory({ rpc, rpcSubscriptions }: AirdropFactoryConfig<'devnet'>): AirdropFunction; -export function airdropFactory({ rpc, rpcSubscriptions }: AirdropFactoryConfig<'mainnet'>): AirdropFunction; -export function airdropFactory({ rpc, rpcSubscriptions }: AirdropFactoryConfig<'testnet'>): AirdropFunction; -export function airdropFactory({ - rpc, - rpcSubscriptions, -}: AirdropFactoryConfig): AirdropFunction { - const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory({ - rpc, - rpcSubscriptions, - } as Parameters[0]); - async function confirmSignatureOnlyTransaction( - config: Omit< - Parameters[0], - 'getRecentSignatureConfirmationPromise' | 'getTimeoutPromise' - >, - ) { - await waitForRecentTransactionConfirmationUntilTimeout({ - ...config, - getRecentSignatureConfirmationPromise, - getTimeoutPromise, - }); - } - return async function airdrop(config) { - return await requestAndConfirmAirdrop_INTERNAL_ONLY_DO_NOT_EXPORT({ - ...config, - confirmSignatureOnlyTransaction, - rpc, - }); - }; -} diff --git a/packages/library/src/compute-limit-internal.ts b/packages/library/src/compute-limit-internal.ts deleted file mode 100644 index 251406286..000000000 --- a/packages/library/src/compute-limit-internal.ts +++ /dev/null @@ -1,200 +0,0 @@ -import { Address } from '@solana/addresses'; -import { getU32Encoder } from '@solana/codecs'; -import { - isSolanaError, - SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT, - SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT, - SolanaError, -} from '@solana/errors'; -import { - IInstruction, - IInstructionWithData, - isInstructionForProgram, - isInstructionWithData, -} from '@solana/instructions'; -import { Rpc, SimulateTransactionApi } from '@solana/rpc'; -import { Blockhash, Commitment, Slot } from '@solana/rpc-types'; -import { - appendTransactionMessageInstruction, - CompilableTransactionMessage, - isDurableNonceTransaction, - isTransactionMessageWithBlockhashLifetime, - ITransactionMessageWithFeePayer, - setTransactionMessageLifetimeUsingBlockhash, - TransactionMessage, -} from '@solana/transaction-messages'; -import { compileTransaction, getBase64EncodedWireTransaction } from '@solana/transactions'; - -type ComputeUnitEstimateForTransactionMessageConfig = Readonly<{ - abortSignal?: AbortSignal; - commitment?: Commitment; - minContextSlot?: Slot; - rpc: Rpc; - transactionMessage: CompilableTransactionMessage | (ITransactionMessageWithFeePayer & TransactionMessage); -}>; - -const COMPUTE_BUDGET_PROGRAM_ADDRESS = - 'ComputeBudget111111111111111111111111111111' as Address<'ComputeBudget111111111111111111111111111111'>; -// HACK: Since the `compileTransaction()` method will not compile a transaction with no lifetime we -// supply a dummy lifetime. -const INVALID_BUT_SUFFICIENT_FOR_COMPILATION_BLOCKHASH = { - blockhash: '11111111111111111111111111111111' as Blockhash, - lastValidBlockHeight: 0n, // This is not included in compiled transactions; it can be anything. -} as const; -const SET_COMPUTE_UNIT_LIMIT_INSTRUCTION_INDEX = 0x02; - -function createComputeUnitLimitInstruction(units: number): IInstruction { - const data = new Uint8Array(5); - data[0] = SET_COMPUTE_UNIT_LIMIT_INSTRUCTION_INDEX; - getU32Encoder().write(units, data, 1 /* offset */); - return Object.freeze({ - data, - programAddress: COMPUTE_BUDGET_PROGRAM_ADDRESS, - }); -} - -function isSetComputeLimitInstruction( - instruction: IInstruction, -): instruction is IInstruction & IInstructionWithData { - return ( - isInstructionForProgram(instruction, COMPUTE_BUDGET_PROGRAM_ADDRESS) && - isInstructionWithData(instruction) && - instruction.data[0] === SET_COMPUTE_UNIT_LIMIT_INSTRUCTION_INDEX - ); -} - -/** - * Simulates a transaction message on the network and returns the number of compute units it - * consumed during simulation. - * - * The estimate this function returns can be used to set a compute unit limit on the transaction. - * Correctly budgeting a compute unit limit for your transaction message can increase the probability - * that your transaction will be accepted for processing. - * - * If you don't declare a compute unit limit on your transaction, validators will assume an upper - * limit of 200K compute units (CU) per instruction. Since validators have an incentive to pack as - * many transactions into each block as possible, they may choose to include transactions that they - * know will fit into the remaining compute budget for the current block over transactions that - * might not. For this reason, you should set a compute unit limit on each of your transaction - * messages, whenever possible. - * - * ## Example - * - * ```ts - * import { getSetComputeLimitInstruction } from '@solana-program/compute-budget'; - * import { createSolanaRpc, getComputeUnitEstimateForTransactionMessageFactory, pipe } from '@solana/web3.js'; - * - * // Create an estimator function. - * const rpc = createSolanaRpc('http://127.0.0.1:8899'); - * const getComputeUnitEstimateForTransactionMessage = - * getComputeUnitEstimateForTransactionMessageFactory({ rpc }); - * - * // Create your transaction message. - * const transactionMessage = pipe( - * createTransactionMessage({ version: 'legacy' }), - * /* ... *\/ - * ); - * - * // Request an estimate of the actual compute units this message will consume. - * const computeUnitsEstimate = - * await getComputeUnitEstimateForTransactionMessage(transactionMessage); - * - * // Set the transaction message's compute unit budget. - * const transactionMessageWithComputeUnitLimit = prependTransactionMessageInstruction( - * getSetComputeLimitInstruction({ units: computeUnitsEstimate }), - * transactionMessage, - * ); - * ``` - * - * > [!WARNING] - * > The compute unit estimate is just that – an estimate. The compute unit consumption of the - * > actual transaction might be higher or lower than what was observed in simulation. Unless you - * > are confident that your particular transaction message will consume the same or fewer compute - * > units as was estimated, you might like to augment the estimate by either a fixed number of CUs - * > or a multiplier. - * - * > [!NOTE] - * > If you are preparing an _unsigned_ transaction, destined to be signed and submitted to the - * > network by a wallet, you might like to leave it up to the wallet to determine the compute unit - * > limit. Consider that the wallet might have a more global view of how many compute units certain - * > types of transactions consume, and might be able to make better estimates of an appropriate - * > compute unit budget. - */ -export async function getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPORT({ - abortSignal, - rpc, - transactionMessage, - ...simulateConfig -}: ComputeUnitEstimateForTransactionMessageConfig): Promise { - /** - * STEP 1: Make sure the transaction message will not fail in simulation for lack of a lifetime - * - either a recent blockhash lifetime or a nonce. - */ - const isDurableNonceTransactionMessage = isDurableNonceTransaction(transactionMessage); - let compilableTransactionMessage; - if (isDurableNonceTransactionMessage || isTransactionMessageWithBlockhashLifetime(transactionMessage)) { - compilableTransactionMessage = transactionMessage; - } else { - compilableTransactionMessage = setTransactionMessageLifetimeUsingBlockhash( - INVALID_BUT_SUFFICIENT_FOR_COMPILATION_BLOCKHASH, - transactionMessage, - ); - } - /** - * STEP 2: Ensure that the message has a `SetComputeLimit` instruction. The set compute limit - * instruction itself consumes compute units, so it must be included in the simulation. - */ - const existingSetComputeUnitLimitInstructionIndex = - transactionMessage.instructions.findIndex(isSetComputeLimitInstruction); - const maxComputeUnitLimitInstruction = createComputeUnitLimitInstruction(1_400_000 /* MAX_COMPUTE_UNIT_LIMIT */); - if (existingSetComputeUnitLimitInstructionIndex === -1) { - compilableTransactionMessage = appendTransactionMessageInstruction( - maxComputeUnitLimitInstruction, - compilableTransactionMessage, - ); - } else { - const nextInstructions = [...compilableTransactionMessage.instructions]; - nextInstructions.splice(existingSetComputeUnitLimitInstructionIndex, 1, maxComputeUnitLimitInstruction); - compilableTransactionMessage = Object.freeze({ - ...compilableTransactionMessage, - instructions: nextInstructions, - } as typeof compilableTransactionMessage); - } - /** - * STEP 3: Simulate the transaction to measure its compute unit consumption. - */ - const compiledTransaction = compileTransaction(compilableTransactionMessage); - const wireTransactionBytes = getBase64EncodedWireTransaction(compiledTransaction); - try { - const { - value: { err: transactionError, unitsConsumed }, - } = await rpc - .simulateTransaction(wireTransactionBytes, { - ...simulateConfig, - encoding: 'base64', - replaceRecentBlockhash: !isDurableNonceTransactionMessage, - sigVerify: false, - }) - .send({ abortSignal }); - if (unitsConsumed == null) { - // This should never be hit, because all RPCs should support `unitsConsumed` by now. - throw new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT); - } - // FIXME(https://github.com/anza-xyz/agave/issues/1295): The simulation response returns - // compute units as a u64, but the `SetComputeLimit` instruction only accepts a u32. Until - // this changes, downcast it. - const downcastUnitsConsumed = unitsConsumed > 4_294_967_295n ? 4_294_967_295 : Number(unitsConsumed); - if (transactionError) { - throw new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT, { - cause: transactionError, - unitsConsumed: downcastUnitsConsumed, - }); - } - return downcastUnitsConsumed; - } catch (e) { - if (isSolanaError(e, SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT)) throw e; - throw new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT, { - cause: e, - }); - } -} diff --git a/packages/library/src/compute-limit.ts b/packages/library/src/compute-limit.ts deleted file mode 100644 index 82865bce7..000000000 --- a/packages/library/src/compute-limit.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { Rpc, SimulateTransactionApi } from '@solana/rpc'; -import { - CompilableTransactionMessage, - ITransactionMessageWithFeePayer, - TransactionMessage, -} from '@solana/transaction-messages'; - -import { getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPORT } from './compute-limit-internal'; - -type ComputeUnitEstimateForTransactionMessageFactoryConfig = Readonly<{ - rpc: Rpc; -}>; -type ComputeUnitEstimateForTransactionMessageFunction = ( - transactionMessage: CompilableTransactionMessage | (ITransactionMessageWithFeePayer & TransactionMessage), - config?: Omit< - Parameters[0], - 'rpc' | 'transactionMessage' - >, -) => Promise; - -export function getComputeUnitEstimateForTransactionMessageFactory({ - rpc, -}: ComputeUnitEstimateForTransactionMessageFactoryConfig): ComputeUnitEstimateForTransactionMessageFunction { - return async function getComputeUnitEstimateForTransactionMessage(transactionMessage, config) { - return await getComputeUnitEstimateForTransactionMessage_INTERNAL_ONLY_DO_NOT_EXPORT({ - ...config, - rpc, - transactionMessage, - }); - }; -} diff --git a/packages/library/src/decompile-transaction-message-fetching-lookup-tables.ts b/packages/library/src/decompile-transaction-message-fetching-lookup-tables.ts deleted file mode 100644 index e44bda662..000000000 --- a/packages/library/src/decompile-transaction-message-fetching-lookup-tables.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { type FetchAccountsConfig } from '@solana/accounts'; -import type { GetMultipleAccountsApi, Rpc } from '@solana/rpc'; -import { - CompilableTransactionMessage, - CompiledTransactionMessage, - decompileTransactionMessage, -} from '@solana/transaction-messages'; - -import { fetchAddressesForLookupTables } from './fetch-lookup-tables'; - -type DecompileTransactionMessageFetchingLookupTablesConfig = FetchAccountsConfig & { - lastValidBlockHeight?: bigint; -}; - -export async function decompileTransactionMessageFetchingLookupTables( - compiledTransactionMessage: CompiledTransactionMessage, - rpc: Rpc, - config?: DecompileTransactionMessageFetchingLookupTablesConfig, -): Promise { - const lookupTables = - 'addressTableLookups' in compiledTransactionMessage && - compiledTransactionMessage.addressTableLookups !== undefined && - compiledTransactionMessage.addressTableLookups.length > 0 - ? compiledTransactionMessage.addressTableLookups - : []; - const lookupTableAddresses = lookupTables.map(l => l.lookupTableAddress); - - const { lastValidBlockHeight, ...fetchAccountsConfig } = config ?? {}; - const addressesByLookupTableAddress = - lookupTableAddresses.length > 0 - ? await fetchAddressesForLookupTables(lookupTableAddresses, rpc, fetchAccountsConfig) - : {}; - - return decompileTransactionMessage(compiledTransactionMessage, { - addressesByLookupTableAddress, - lastValidBlockHeight, - }); -} diff --git a/packages/library/src/fetch-lookup-tables.ts b/packages/library/src/fetch-lookup-tables.ts deleted file mode 100644 index a82dfdbfd..000000000 --- a/packages/library/src/fetch-lookup-tables.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { - assertAccountsDecoded, - assertAccountsExist, - type FetchAccountsConfig, - fetchJsonParsedAccounts, -} from '@solana/accounts'; -import type { Address } from '@solana/addresses'; -import type { GetMultipleAccountsApi, Rpc } from '@solana/rpc'; -import { type AddressesByLookupTableAddress } from '@solana/transaction-messages'; - -type FetchedAddressLookup = { - addresses: Address[]; -}; - -export async function fetchAddressesForLookupTables( - lookupTableAddresses: Address[], - rpc: Rpc, - config?: FetchAccountsConfig, -): Promise { - if (lookupTableAddresses.length === 0) { - return {}; - } - - const fetchedLookupTables = await fetchJsonParsedAccounts( - rpc, - lookupTableAddresses, - config, - ); - - assertAccountsDecoded(fetchedLookupTables); - assertAccountsExist(fetchedLookupTables); - - return fetchedLookupTables.reduce((acc, lookup) => { - return { - ...acc, - [lookup.address]: lookup.data.addresses, - }; - }, {}); -} diff --git a/packages/library/src/index.ts b/packages/library/src/index.ts deleted file mode 100644 index 99dea2b4b..000000000 --- a/packages/library/src/index.ts +++ /dev/null @@ -1,31 +0,0 @@ -export * from '@solana/accounts'; -export * from '@solana/addresses'; -export * from '@solana/codecs'; -export * from '@solana/errors'; -export * from '@solana/functional'; -export * from '@solana/instructions'; -export * from '@solana/keys'; -export * from '@solana/programs'; -export * from '@solana/rpc'; -export * from '@solana/rpc-parsed-types'; -export * from '@solana/rpc-subscriptions'; -export * from '@solana/rpc-types'; -export * from '@solana/signers'; -export * from '@solana/transaction-messages'; -export * from '@solana/transactions'; -export * from './airdrop'; -export * from './compute-limit'; -export * from './decompile-transaction-message-fetching-lookup-tables'; -export * from './fetch-lookup-tables'; -export * from './send-and-confirm-durable-nonce-transaction'; -export * from './send-and-confirm-transaction'; -export * from './send-transaction-without-confirming'; - -export type { - RpcRequest, - RpcRequestTransformer, - RpcResponse, - RpcResponseData, - RpcResponseTransformer, -} from '@solana/rpc-spec-types'; -export { createRpcMessage } from '@solana/rpc-spec-types'; diff --git a/packages/library/src/send-and-confirm-durable-nonce-transaction.ts b/packages/library/src/send-and-confirm-durable-nonce-transaction.ts deleted file mode 100644 index e454ae2dd..000000000 --- a/packages/library/src/send-and-confirm-durable-nonce-transaction.ts +++ /dev/null @@ -1,70 +0,0 @@ -import type { GetAccountInfoApi, GetSignatureStatusesApi, Rpc, SendTransactionApi } from '@solana/rpc'; -import type { AccountNotificationsApi, RpcSubscriptions, SignatureNotificationsApi } from '@solana/rpc-subscriptions'; -import { - createNonceInvalidationPromiseFactory, - createRecentSignatureConfirmationPromiseFactory, - waitForDurableNonceTransactionConfirmation, -} from '@solana/transaction-confirmation'; -import { FullySignedTransaction, TransactionWithDurableNonceLifetime } from '@solana/transactions'; - -import { sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT } from './send-transaction-internal'; - -type SendAndConfirmDurableNonceTransactionFunction = ( - transaction: FullySignedTransaction & TransactionWithDurableNonceLifetime, - config: Omit< - Parameters[0], - 'confirmDurableNonceTransaction' | 'rpc' | 'transaction' - >, -) => Promise; - -type SendAndConfirmDurableNonceTransactionFactoryConfig = { - rpc: Rpc & { '~cluster'?: TCluster }; - rpcSubscriptions: RpcSubscriptions & { '~cluster'?: TCluster }; -}; - -export function sendAndConfirmDurableNonceTransactionFactory({ - rpc, - rpcSubscriptions, -}: SendAndConfirmDurableNonceTransactionFactoryConfig<'devnet'>): SendAndConfirmDurableNonceTransactionFunction; -export function sendAndConfirmDurableNonceTransactionFactory({ - rpc, - rpcSubscriptions, -}: SendAndConfirmDurableNonceTransactionFactoryConfig<'testnet'>): SendAndConfirmDurableNonceTransactionFunction; -export function sendAndConfirmDurableNonceTransactionFactory({ - rpc, - rpcSubscriptions, -}: SendAndConfirmDurableNonceTransactionFactoryConfig<'mainnet'>): SendAndConfirmDurableNonceTransactionFunction; -export function sendAndConfirmDurableNonceTransactionFactory< - TCluster extends 'devnet' | 'mainnet' | 'testnet' | void = void, ->({ - rpc, - rpcSubscriptions, -}: SendAndConfirmDurableNonceTransactionFactoryConfig): SendAndConfirmDurableNonceTransactionFunction { - const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory({ rpc, rpcSubscriptions } as Parameters< - typeof createNonceInvalidationPromiseFactory - >[0]); - const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory({ - rpc, - rpcSubscriptions, - } as Parameters[0]); - async function confirmDurableNonceTransaction( - config: Omit< - Parameters[0], - 'getNonceInvalidationPromise' | 'getRecentSignatureConfirmationPromise' - >, - ) { - await waitForDurableNonceTransactionConfirmation({ - ...config, - getNonceInvalidationPromise, - getRecentSignatureConfirmationPromise, - }); - } - return async function sendAndConfirmDurableNonceTransaction(transaction, config) { - await sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({ - ...config, - confirmDurableNonceTransaction, - rpc, - transaction, - }); - }; -} diff --git a/packages/library/src/send-and-confirm-transaction.ts b/packages/library/src/send-and-confirm-transaction.ts deleted file mode 100644 index 58b53713f..000000000 --- a/packages/library/src/send-and-confirm-transaction.ts +++ /dev/null @@ -1,69 +0,0 @@ -import type { GetEpochInfoApi, GetSignatureStatusesApi, Rpc, SendTransactionApi } from '@solana/rpc'; -import type { RpcSubscriptions, SignatureNotificationsApi, SlotNotificationsApi } from '@solana/rpc-subscriptions'; -import { - createBlockHeightExceedencePromiseFactory, - createRecentSignatureConfirmationPromiseFactory, - waitForRecentTransactionConfirmation, -} from '@solana/transaction-confirmation'; -import { FullySignedTransaction, TransactionWithBlockhashLifetime } from '@solana/transactions'; - -import { sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT } from './send-transaction-internal'; - -type SendAndConfirmTransactionWithBlockhashLifetimeFunction = ( - transaction: FullySignedTransaction & TransactionWithBlockhashLifetime, - config: Omit< - Parameters[0], - 'confirmRecentTransaction' | 'rpc' | 'transaction' - >, -) => Promise; - -type SendAndConfirmTransactionWithBlockhashLifetimeFactoryConfig = { - rpc: Rpc & { '~cluster'?: TCluster }; - rpcSubscriptions: RpcSubscriptions & { '~cluster'?: TCluster }; -}; - -export function sendAndConfirmTransactionFactory({ - rpc, - rpcSubscriptions, -}: SendAndConfirmTransactionWithBlockhashLifetimeFactoryConfig<'devnet'>): SendAndConfirmTransactionWithBlockhashLifetimeFunction; -export function sendAndConfirmTransactionFactory({ - rpc, - rpcSubscriptions, -}: SendAndConfirmTransactionWithBlockhashLifetimeFactoryConfig<'testnet'>): SendAndConfirmTransactionWithBlockhashLifetimeFunction; -export function sendAndConfirmTransactionFactory({ - rpc, - rpcSubscriptions, -}: SendAndConfirmTransactionWithBlockhashLifetimeFactoryConfig<'mainnet'>): SendAndConfirmTransactionWithBlockhashLifetimeFunction; -export function sendAndConfirmTransactionFactory({ - rpc, - rpcSubscriptions, -}: SendAndConfirmTransactionWithBlockhashLifetimeFactoryConfig): SendAndConfirmTransactionWithBlockhashLifetimeFunction { - const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory({ - rpc, - rpcSubscriptions, - } as Parameters[0]); - const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory({ - rpc, - rpcSubscriptions, - } as Parameters[0]); - async function confirmRecentTransaction( - config: Omit< - Parameters[0], - 'getBlockHeightExceedencePromise' | 'getRecentSignatureConfirmationPromise' - >, - ) { - await waitForRecentTransactionConfirmation({ - ...config, - getBlockHeightExceedencePromise, - getRecentSignatureConfirmationPromise, - }); - } - return async function sendAndConfirmTransaction(transaction, config) { - await sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({ - ...config, - confirmRecentTransaction, - rpc, - transaction, - }); - }; -} diff --git a/packages/library/src/send-transaction-internal.ts b/packages/library/src/send-transaction-internal.ts deleted file mode 100644 index 73b052319..000000000 --- a/packages/library/src/send-transaction-internal.ts +++ /dev/null @@ -1,135 +0,0 @@ -import type { Signature } from '@solana/keys'; -import type { Rpc, SendTransactionApi } from '@solana/rpc'; -import { Commitment, commitmentComparator } from '@solana/rpc-types'; -import { - waitForDurableNonceTransactionConfirmation, - waitForRecentTransactionConfirmation, -} from '@solana/transaction-confirmation'; -import { - FullySignedTransaction, - getBase64EncodedWireTransaction, - TransactionWithBlockhashLifetime, - TransactionWithDurableNonceLifetime, -} from '@solana/transactions'; - -interface SendAndConfirmDurableNonceTransactionConfig - extends SendTransactionBaseConfig, - SendTransactionConfigWithoutEncoding { - confirmDurableNonceTransaction: ( - config: Omit< - Parameters[0], - 'getNonceInvalidationPromise' | 'getRecentSignatureConfirmationPromise' - >, - ) => Promise; - transaction: FullySignedTransaction & TransactionWithDurableNonceLifetime; -} - -interface SendAndConfirmTransactionWithBlockhashLifetimeConfig - extends SendTransactionBaseConfig, - SendTransactionConfigWithoutEncoding { - confirmRecentTransaction: ( - config: Omit< - Parameters[0], - 'getBlockHeightExceedencePromise' | 'getRecentSignatureConfirmationPromise' - >, - ) => Promise; - transaction: FullySignedTransaction & TransactionWithBlockhashLifetime; -} - -interface SendTransactionBaseConfig extends SendTransactionConfigWithoutEncoding { - abortSignal?: AbortSignal; - commitment: Commitment; - rpc: Rpc; - transaction: FullySignedTransaction; -} - -type SendTransactionConfigWithoutEncoding = Omit< - NonNullable[1]>, - 'encoding' ->; - -function getSendTransactionConfigWithAdjustedPreflightCommitment( - commitment: Commitment, - config?: SendTransactionConfigWithoutEncoding, -): SendTransactionConfigWithoutEncoding | void { - if ( - // The developer has supplied no value for `preflightCommitment`. - !config?.preflightCommitment && - // The value of `commitment` is lower than the server default of `preflightCommitment`. - commitmentComparator(commitment, 'finalized' /* default value of `preflightCommitment` */) < 0 - ) { - return { - ...config, - // In the common case, it is unlikely that you want to simulate a transaction at - // `finalized` commitment when your standard of commitment for confirming the - // transaction is lower. Cap the simulation commitment level to the level of the - // confirmation commitment. - preflightCommitment: commitment, - }; - } - // The commitment at which the developer wishes to confirm the transaction is at least as - // high as the commitment at which they want to simulate it. Honour the config as-is. - return config; -} - -export async function sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({ - abortSignal, - commitment, - rpc, - transaction, - ...sendTransactionConfig -}: SendTransactionBaseConfig): Promise { - const base64EncodedWireTransaction = getBase64EncodedWireTransaction(transaction); - return await rpc - .sendTransaction(base64EncodedWireTransaction, { - ...getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, sendTransactionConfig), - encoding: 'base64', - }) - .send({ abortSignal }); -} - -export async function sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({ - abortSignal, - commitment, - confirmDurableNonceTransaction, - rpc, - transaction, - ...sendTransactionConfig -}: SendAndConfirmDurableNonceTransactionConfig): Promise { - const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({ - ...sendTransactionConfig, - abortSignal, - commitment, - rpc, - transaction, - }); - await confirmDurableNonceTransaction({ - abortSignal, - commitment, - transaction, - }); - return transactionSignature; -} - -export async function sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({ - abortSignal, - commitment, - confirmRecentTransaction, - rpc, - transaction, - ...sendTransactionConfig -}: SendAndConfirmTransactionWithBlockhashLifetimeConfig): Promise { - const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({ - ...sendTransactionConfig, - abortSignal, - commitment, - rpc, - transaction, - }); - await confirmRecentTransaction({ - abortSignal, - commitment, - transaction, - }); - return transactionSignature; -} diff --git a/packages/library/src/send-transaction-without-confirming.ts b/packages/library/src/send-transaction-without-confirming.ts deleted file mode 100644 index 6fab269d0..000000000 --- a/packages/library/src/send-transaction-without-confirming.ts +++ /dev/null @@ -1,25 +0,0 @@ -import type { Rpc, SendTransactionApi } from '@solana/rpc'; -import { FullySignedTransaction } from '@solana/transactions'; - -import { sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT } from './send-transaction-internal'; - -type SendTransactionWithoutConfirmingFunction = ( - transaction: FullySignedTransaction, - config: Omit[0], 'rpc' | 'transaction'>, -) => Promise; - -interface SendTransactionWithoutConfirmingFactoryConfig { - rpc: Rpc; -} - -export function sendTransactionWithoutConfirmingFactory({ - rpc, -}: SendTransactionWithoutConfirmingFactoryConfig): SendTransactionWithoutConfirmingFunction { - return async function sendTransactionWithoutConfirming(transaction, config) { - await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({ - ...config, - rpc, - transaction, - }); - }; -} diff --git a/packages/library/src/types/global.d.ts b/packages/library/src/types/global.d.ts deleted file mode 100644 index d3c8f0762..000000000 --- a/packages/library/src/types/global.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -declare const __BROWSER__: boolean; -declare const __DEV__: boolean; -declare const __NODEJS__: boolean; -declare const __REACTNATIVE__: boolean; -declare const __VERSION__: string; diff --git a/packages/library/tsconfig.declarations.json b/packages/library/tsconfig.declarations.json deleted file mode 100644 index dc2d27bb0..000000000 --- a/packages/library/tsconfig.declarations.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "compilerOptions": { - "declaration": true, - "declarationMap": true, - "emitDeclarationOnly": true, - "outDir": "./dist/types" - }, - "extends": "./tsconfig.json", - "include": ["src/index.ts", "src/types"] -} diff --git a/packages/library/tsconfig.json b/packages/library/tsconfig.json deleted file mode 100644 index 323b6d30e..000000000 --- a/packages/library/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/tsconfig", - "compilerOptions": { - "lib": ["DOM", "ES2020", "ES2022.Error"] - }, - "display": "@solana/web3.js", - "extends": "../tsconfig/base.json", - "include": ["src"] -} diff --git a/packages/library/typedoc.json b/packages/library/typedoc.json deleted file mode 100644 index d99f37ef3..000000000 --- a/packages/library/typedoc.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "$schema": "https://typedoc.org/schema.json", - "extends": ["../typedoc.base.json"], - "entryPoints": ["src/index.ts"] -} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index efce8986f..ffb57d7a8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -130,17 +130,17 @@ importers: examples/deserialize-transaction: dependencies: '@solana-program/memo': - specifier: ^0.6.1 - version: 0.6.1(@solana/web3.js@packages+library) + specifier: ^0.7.0 + version: 0.7.0(@solana/kit@packages+kit) '@solana-program/system': - specifier: ^0.6.2 - version: 0.6.2(@solana/web3.js@packages+library) + specifier: ^0.7.0 + version: 0.7.0(@solana/kit@packages+kit) '@solana/example-utils': specifier: workspace:* version: link:../utils - '@solana/web3.js': + '@solana/kit': specifier: workspace:* - version: link:../../packages/library + version: link:../../packages/kit devDependencies: start-server-and-test: specifier: ^2.0.10 @@ -161,14 +161,14 @@ importers: specifier: 3.2.0 version: 3.2.0(@types/react-dom@19.0.4(@types/react@19.0.10))(@types/react@19.0.10)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) '@solana-program/system': - specifier: ^0.6.2 - version: 0.6.2(@solana/web3.js@packages+library) + specifier: ^0.7.0 + version: 0.7.0(@solana/kit@packages+kit) + '@solana/kit': + specifier: workspace:* + version: link:../../packages/kit '@solana/react': specifier: workspace:* version: link:../../packages/react - '@solana/web3.js': - specifier: workspace:* - version: link:../../packages/library '@wallet-standard/core': specifier: ^1.1.0 version: 1.1.0 @@ -215,9 +215,9 @@ importers: '@solana/example-utils': specifier: workspace:* version: link:../utils - '@solana/web3.js': + '@solana/kit': specifier: workspace:* - version: link:../../packages/library + version: link:../../packages/kit devDependencies: tsx: specifier: ^4.19.3 @@ -228,9 +228,9 @@ importers: '@solana/example-utils': specifier: workspace:* version: link:../utils - '@solana/web3.js': + '@solana/kit': specifier: workspace:* - version: link:../../packages/library + version: link:../../packages/kit devDependencies: start-server-and-test: specifier: ^2.0.10 @@ -242,14 +242,14 @@ importers: examples/signers: dependencies: '@solana-program/system': - specifier: ^0.6.2 - version: 0.6.2(@solana/web3.js@packages+library) + specifier: ^0.7.0 + version: 0.7.0(@solana/kit@packages+kit) '@solana/example-utils': specifier: workspace:* version: link:../utils - '@solana/web3.js': + '@solana/kit': specifier: workspace:* - version: link:../../packages/library + version: link:../../packages/kit devDependencies: start-server-and-test: specifier: ^2.0.10 @@ -261,14 +261,14 @@ importers: examples/transfer-lamports: dependencies: '@solana-program/system': - specifier: ^0.6.2 - version: 0.6.2(@solana/web3.js@packages+library) + specifier: ^0.7.0 + version: 0.7.0(@solana/kit@packages+kit) '@solana/example-utils': specifier: workspace:* version: link:../utils - '@solana/web3.js': + '@solana/kit': specifier: workspace:* - version: link:../../packages/library + version: link:../../packages/kit devDependencies: start-server-and-test: specifier: ^2.0.10 @@ -616,66 +616,6 @@ importers: specifier: '>=5' version: 5.7.3 - packages/library: - dependencies: - '@solana/accounts': - specifier: workspace:* - version: link:../accounts - '@solana/addresses': - specifier: workspace:* - version: link:../addresses - '@solana/codecs': - specifier: workspace:* - version: link:../codecs - '@solana/errors': - specifier: workspace:* - version: link:../errors - '@solana/functional': - specifier: workspace:* - version: link:../functional - '@solana/instructions': - specifier: workspace:* - version: link:../instructions - '@solana/keys': - specifier: workspace:* - version: link:../keys - '@solana/programs': - specifier: workspace:* - version: link:../programs - '@solana/rpc': - specifier: workspace:* - version: link:../rpc - '@solana/rpc-parsed-types': - specifier: workspace:* - version: link:../rpc-parsed-types - '@solana/rpc-spec-types': - specifier: workspace:* - version: link:../rpc-spec-types - '@solana/rpc-subscriptions': - specifier: workspace:* - version: link:../rpc-subscriptions - '@solana/rpc-types': - specifier: workspace:* - version: link:../rpc-types - '@solana/signers': - specifier: workspace:* - version: link:../signers - '@solana/sysvars': - specifier: workspace:* - version: link:../sysvars - '@solana/transaction-confirmation': - specifier: workspace:* - version: link:../transaction-confirmation - '@solana/transaction-messages': - specifier: workspace:* - version: link:../transaction-messages - '@solana/transactions': - specifier: workspace:* - version: link:../transactions - typescript: - specifier: '>=5' - version: 5.7.3 - packages/options: dependencies: '@solana/codecs-core': @@ -3515,15 +3455,15 @@ packages: '@sinonjs/fake-timers@8.1.0': resolution: {integrity: sha512-OAPJUAtgeINhh/TAlUID4QTs53Njm7xzddaVlEs/SXwgtiD1tW22zAB/W1wdqfrpmikgaWQ9Fw6Ws+hsiRm5Vg==} - '@solana-program/memo@0.6.1': - resolution: {integrity: sha512-m1Mt/10uADf5WeqTQequI5GqeNsEw3xWzFz1KR018U+olUWXCKoVE4TsjF0+C0lxW9kQ+smLXvCDyqTHW/Lf6A==} + '@solana-program/memo@0.7.0': + resolution: {integrity: sha512-3T9iUjWSYtN/5S5jzJuasD2yQfVfFAQ9yTwIE25+P9peWqz4oarn6ZQvRj/FLcBqaMLtSqLhU1hN2cyVBS6hyg==} peerDependencies: - '@solana/web3.js': ^2.0.0 + '@solana/kit': ^2.1.0 - '@solana-program/system@0.6.2': - resolution: {integrity: sha512-q0ZnylK+LISjuP2jH5GWV9IJPtpzQctj5KQwij9XCDRSGkcFr2fpqptNnVupTLQiNL6Q4c1OZuG8WBmyFXVXZw==} + '@solana-program/system@0.7.0': + resolution: {integrity: sha512-FKTBsKHpvHHNc1ATRm7SlC5nF/VdJtOSjldhcyfMN9R7xo712Mo2jHIzvBgn8zQO5Kg0DcWuKB7268Kv1ocicw==} peerDependencies: - '@solana/web3.js': ^2.0.0 + '@solana/kit': ^2.1.0 '@solana/buffer-layout@4.0.1': resolution: {integrity: sha512-E1ImOIAD1tBZFRdjeM4/pzTiTApC0AOBGwyAMS4fwIodCWArzJ3DWdoh8cKxeFM2fElkxBh2Aqts1BPC373rHA==} @@ -9601,13 +9541,13 @@ snapshots: dependencies: '@sinonjs/commons': 1.8.6 - '@solana-program/memo@0.6.1(@solana/web3.js@packages+library)': + '@solana-program/memo@0.7.0(@solana/kit@packages+kit)': dependencies: - '@solana/web3.js': link:packages/library + '@solana/kit': link:packages/kit - '@solana-program/system@0.6.2(@solana/web3.js@packages+library)': + '@solana-program/system@0.7.0(@solana/kit@packages+kit)': dependencies: - '@solana/web3.js': link:packages/library + '@solana/kit': link:packages/kit '@solana/buffer-layout@4.0.1': dependencies: