diff --git a/.size-limit.json b/.size-limit.json index 983e6c88..d42fe3fe 100644 --- a/.size-limit.json +++ b/.size-limit.json @@ -3,7 +3,7 @@ "path": "packages/anchor-contrib/dist/esm/index.js", "limit": "12 KB", "ignore": [ - "@project-serum/anchor", + "@coral-xyz/anchor", "@solana/web3.js", "@saberhq/solana-contrib" ], diff --git a/package.json b/package.json index 84ce7ecf..f27acfcc 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,8 @@ "@babel/core": "^7.23.5", "@babel/preset-env": "^7.23.5", "@babel/preset-typescript": "^7.23.3", + "@coral-xyz/anchor": "^0.29.0", "@jest/types": "^29.6.3", - "@project-serum/anchor": "^0.25.0", "@rushstack/eslint-patch": "^1.6.0", "@saberhq/eslint-config": "^3.1.1", "@saberhq/eslint-config-react": "^3.1.1", diff --git a/packages/anchor-contrib/package.json b/packages/anchor-contrib/package.json index 22d4467e..c92d5542 100644 --- a/packages/anchor-contrib/package.json +++ b/packages/anchor-contrib/package.json @@ -22,12 +22,12 @@ "prepublishOnly": "npm run build" }, "peerDependencies": { - "@project-serum/anchor": "^0.22 || ^0.23 || ^0.24", + "@coral-xyz/anchor": "^0.22 || ^0.23 || ^0.24 || ^0.28 || ^0.29", "@solana/web3.js": "^1.42", "bn.js": "^4 || ^5" }, "devDependencies": { - "@project-serum/anchor": "^0.25.0", + "@coral-xyz/anchor": "^0.29.0", "@saberhq/tsconfig": "^3.1.1", "@solana/web3.js": "^1.87.6", "@types/lodash.camelcase": "^4.3.9", diff --git a/packages/anchor-contrib/src/errors.ts b/packages/anchor-contrib/src/errors.ts index 089b910e..20f97537 100644 --- a/packages/anchor-contrib/src/errors.ts +++ b/packages/anchor-contrib/src/errors.ts @@ -1,5 +1,5 @@ -import type { Idl } from "@project-serum/anchor"; -import type { IdlErrorCode } from "@project-serum/anchor/dist/esm/idl.js"; +import type { Idl } from "@coral-xyz/anchor"; +import type { IdlErrorCode } from "@coral-xyz/anchor/dist/esm/idl.js"; import type { AnchorError } from "./index.js"; diff --git a/packages/anchor-contrib/src/generateAccountParsers.ts b/packages/anchor-contrib/src/generateAccountParsers.ts index 6081ccef..97be78f7 100644 --- a/packages/anchor-contrib/src/generateAccountParsers.ts +++ b/packages/anchor-contrib/src/generateAccountParsers.ts @@ -1,5 +1,5 @@ -import type { AccountsCoder, Idl } from "@project-serum/anchor"; -import { BorshAccountsCoder } from "@project-serum/anchor"; +import type { AccountsCoder, Idl } from "@coral-xyz/anchor"; +import { BorshAccountsCoder } from "@coral-xyz/anchor"; import camelCase from "lodash.camelcase"; /** diff --git a/packages/anchor-contrib/src/types.ts b/packages/anchor-contrib/src/types.ts index 656c223e..90806cfd 100644 --- a/packages/anchor-contrib/src/types.ts +++ b/packages/anchor-contrib/src/types.ts @@ -3,10 +3,10 @@ import type { Address, BN, Context as AnchorContext, + MethodsNamespace, Program as AProgram, ProgramAccount, - StateClient, -} from "@project-serum/anchor"; +} from "@coral-xyz/anchor"; import type { Idl, IdlAccountItem, @@ -18,7 +18,7 @@ import type { IdlType, IdlTypeDef, IdlTypeDefTyStruct, -} from "@project-serum/anchor/dist/esm/idl.js"; +} from "@coral-xyz/anchor/dist/esm/idl.js"; import type { AccountMeta, PublicKey, @@ -27,6 +27,13 @@ import type { TransactionSignature, } from "@solana/web3.js"; +export type IdlWithState = Idl & { + state?: { + methods: IdlInstruction[]; + struct: IdlTypeDef; + }; +}; + type InstructionsParsed = Record< string, { @@ -159,7 +166,7 @@ type MakeInstructions = { }; export type AnchorProgram< - IDL extends Idl, + IDL extends IdlWithState, A, Defined = AnchorDefined, RPCInstructions extends MakeInstructions< @@ -175,7 +182,7 @@ export type AnchorProgram< "rpc" | "state" | "account" | "transaction" | "instruction" > & { rpc: RpcNamespace; - state: StateClient; + state: MethodsNamespace; account: AccountsNamespace; transaction: TransactionNamespace; instruction: InstructionNamespace; @@ -210,13 +217,13 @@ export type AnchorAccounts = AnchorTypeDefs< Defined >; -export type AnchorState = AnchorTypeDef< +export type AnchorState = AnchorTypeDef< NonNullable["struct"], Defined >; export type AnchorTypes< - T extends Idl, + T extends IdlWithState, AccountMap = Record, D = Record, DEF = AnchorDefined, diff --git a/packages/anchor-contrib/src/utils/accounts.ts b/packages/anchor-contrib/src/utils/accounts.ts index a1959a7e..c498c2e5 100644 --- a/packages/anchor-contrib/src/utils/accounts.ts +++ b/packages/anchor-contrib/src/utils/accounts.ts @@ -1,6 +1,6 @@ -import type { AccountsCoder } from "@project-serum/anchor"; -import { BorshAccountsCoder } from "@project-serum/anchor"; -import type { IdlTypeDef } from "@project-serum/anchor/dist/esm/idl.js"; +import type { AccountsCoder } from "@coral-xyz/anchor"; +import { BorshAccountsCoder } from "@coral-xyz/anchor"; +import type { IdlTypeDef } from "@coral-xyz/anchor/dist/esm/idl.js"; import type { ProgramAccountParser, PublicKey } from "@saberhq/solana-contrib"; import camelCase from "lodash.camelcase"; diff --git a/packages/anchor-contrib/src/utils/coder.ts b/packages/anchor-contrib/src/utils/coder.ts index 18de3c85..72a8342e 100644 --- a/packages/anchor-contrib/src/utils/coder.ts +++ b/packages/anchor-contrib/src/utils/coder.ts @@ -1,11 +1,11 @@ -import type { Accounts, Idl } from "@project-serum/anchor"; -import { BorshCoder, EventParser, utils } from "@project-serum/anchor"; -import { default as InstructionNamespaceFactory } from "@project-serum/anchor/dist/cjs/program/namespace/instruction.js"; -import type { InstructionDisplay } from "@project-serum/anchor/dist/esm/coder/borsh/instruction.js"; +import type { Accounts, Idl } from "@coral-xyz/anchor"; +import { BorshCoder, EventParser, utils } from "@coral-xyz/anchor"; +import { default as InstructionNamespaceFactory } from "@coral-xyz/anchor/dist/cjs/program/namespace/instruction.js"; +import type { InstructionDisplay } from "@coral-xyz/anchor/dist/esm/coder/borsh/instruction.js"; import type { IdlAccountItem, IdlTypeDef, -} from "@project-serum/anchor/dist/esm/idl.js"; +} from "@coral-xyz/anchor/dist/esm/idl.js"; import type { Provider as SaberProvider } from "@saberhq/solana-contrib"; import type { GetProgramAccountsFilter, PublicKey } from "@solana/web3.js"; import { TransactionInstruction } from "@solana/web3.js"; @@ -207,6 +207,7 @@ export class SuperCoder { const keys = InstructionNamespaceFactory.accountsArray( accounts, idlIx.accounts, + this.address, name, ); return new TransactionInstruction({ diff --git a/packages/anchor-contrib/src/utils/idl.ts b/packages/anchor-contrib/src/utils/idl.ts index bcb2d1e4..53760438 100644 --- a/packages/anchor-contrib/src/utils/idl.ts +++ b/packages/anchor-contrib/src/utils/idl.ts @@ -1,4 +1,4 @@ -import type { IdlType } from "@project-serum/anchor/dist/esm/idl.js"; +import type { IdlType } from "@coral-xyz/anchor/dist/esm/idl.js"; /** * Formats an IDL type as a string. This comes straight from the Anchor source. diff --git a/packages/anchor-contrib/src/utils/programs.ts b/packages/anchor-contrib/src/utils/programs.ts index ca0d3355..2a3a4c9f 100644 --- a/packages/anchor-contrib/src/utils/programs.ts +++ b/packages/anchor-contrib/src/utils/programs.ts @@ -1,5 +1,5 @@ -import type { Idl } from "@project-serum/anchor"; -import { Program } from "@project-serum/anchor"; +import type { Idl } from "@coral-xyz/anchor"; +import { Program } from "@coral-xyz/anchor"; import type { Provider as SaberProvider, ReadonlyProvider as ReadonlySaberProvider, diff --git a/packages/anchor-contrib/src/utils/provider.ts b/packages/anchor-contrib/src/utils/provider.ts index d60bc89e..e4d3c7c4 100644 --- a/packages/anchor-contrib/src/utils/provider.ts +++ b/packages/anchor-contrib/src/utils/provider.ts @@ -1,8 +1,8 @@ import type { AnchorProvider as AnchorProviderImpl, Provider as IAnchorProvider, -} from "@project-serum/anchor"; -import * as anchor from "@project-serum/anchor"; +} from "@coral-xyz/anchor"; +import * as anchor from "@coral-xyz/anchor"; import type { Provider as SaberProvider, ReadonlyProvider as ReadonlySaberProvider, diff --git a/packages/chai-solana/package.json b/packages/chai-solana/package.json index 78c93571..fc41758f 100644 --- a/packages/chai-solana/package.json +++ b/packages/chai-solana/package.json @@ -42,13 +42,13 @@ "access": "public" }, "peerDependencies": { - "@project-serum/anchor": ">=0.17", + "@coral-xyz/anchor": ">=0.17", "@solana/web3.js": "^1.42", "bn.js": "^5.2.0", "jsbi": "*" }, "devDependencies": { - "@project-serum/anchor": "^0.25.0", + "@coral-xyz/anchor": "^0.29.0", "@saberhq/tsconfig": "^3.1.1", "@solana/web3.js": "^1.87.6", "bn.js": "^5.2.1", diff --git a/packages/chai-solana/src/expectTXTable.ts b/packages/chai-solana/src/expectTXTable.ts index 1d2a3d08..d4cb2337 100644 --- a/packages/chai-solana/src/expectTXTable.ts +++ b/packages/chai-solana/src/expectTXTable.ts @@ -1,4 +1,4 @@ -import type { IdlErrorCode } from "@project-serum/anchor/dist/esm/idl.js"; +import type { IdlErrorCode } from "@coral-xyz/anchor/dist/esm/idl.js"; import { matchError, matchErrorCode } from "@saberhq/anchor-contrib"; import type { TransactionEnvelope } from "@saberhq/solana-contrib"; import { parseTransactionLogs, printTXTable } from "@saberhq/solana-contrib"; diff --git a/packages/chai-solana/src/index.ts b/packages/chai-solana/src/index.ts index 776f512d..df02d8a1 100644 --- a/packages/chai-solana/src/index.ts +++ b/packages/chai-solana/src/index.ts @@ -5,8 +5,8 @@ import "./types.js"; -import type { Address } from "@project-serum/anchor"; -import { BN } from "@project-serum/anchor"; +import type { Address } from "@coral-xyz/anchor"; +import { BN } from "@coral-xyz/anchor"; import { TokenAmount } from "@saberhq/token-utils"; import { PublicKey } from "@solana/web3.js"; import chaiAsPromised from "chai-as-promised"; diff --git a/packages/chai-solana/src/types.ts b/packages/chai-solana/src/types.ts index 6317ab6c..db9c2ece 100644 --- a/packages/chai-solana/src/types.ts +++ b/packages/chai-solana/src/types.ts @@ -3,7 +3,7 @@ import "chai-bn"; import "chai-as-promised"; -import type { Address } from "@project-serum/anchor"; +import type { Address } from "@coral-xyz/anchor"; import type { BigintIsh, TokenAmount } from "@saberhq/token-utils"; declare global { diff --git a/packages/chai-solana/src/utils.ts b/packages/chai-solana/src/utils.ts index e3a95f8d..18969ea1 100644 --- a/packages/chai-solana/src/utils.ts +++ b/packages/chai-solana/src/utils.ts @@ -1,6 +1,6 @@ import "chai-as-promised"; -import type { Idl } from "@project-serum/anchor"; +import type { Idl } from "@coral-xyz/anchor"; import type { PromiseOrValue, TransactionLike, diff --git a/packages/solana-contrib/src/interfaces.ts b/packages/solana-contrib/src/interfaces.ts index d3496b44..189bf870 100644 --- a/packages/solana-contrib/src/interfaces.ts +++ b/packages/solana-contrib/src/interfaces.ts @@ -10,36 +10,33 @@ import type { Signer, SimulatedTransactionResponse, Transaction, - TransactionVersion, } from "@solana/web3.js"; import { VersionedTransaction } from "@solana/web3.js"; import type { BroadcastOptions, PendingTransaction } from "./index.js"; -export type SupportedTransactionVersions = Set | null; - export const isVersionedTransaction = ( tx: Transaction | VersionedTransaction, ): tx is VersionedTransaction => { return "version" in tx || tx instanceof VersionedTransaction; }; -export const ALL_TRANSACTION_VERSIONS: Set = - new Set(["legacy", 0]); - -export type TransactionOrVersionedTransaction< - S extends SupportedTransactionVersions, -> = S extends null ? Transaction : Transaction | VersionedTransaction; +/** + * Wallet interface for objects that can be used to sign provider transactions. + * + * This interface comes from Anchor. + */ +export interface Wallet { + /** + * The PublicKey of the wallet. + */ + publicKey: PublicKey; -export interface MultiVersionWalletAdapter< - V extends SupportedTransactionVersions, -> { - readonly supportedTransactionVersions: V; /** * Signs a transaction with the wallet. * @param tx */ - signTransaction>( + signTransaction( tx: T, ): Promise; @@ -47,25 +44,11 @@ export interface MultiVersionWalletAdapter< * Signs all transactions with the wallet. * @param txs */ - signAllTransactions>( + signAllTransactions( txs: T[], ): Promise; } -/** - * Wallet interface for objects that can be used to sign provider transactions. - * - * This interface comes from Anchor. - */ -export interface Wallet< - V extends SupportedTransactionVersions = SupportedTransactionVersions, -> extends MultiVersionWalletAdapter { - /** - * The PublicKey of the wallet. - */ - publicKey: PublicKey; -} - /** * Request to send a transaction. */ diff --git a/packages/solana-contrib/src/provider.ts b/packages/solana-contrib/src/provider.ts index 386d854b..3f1c45bf 100644 --- a/packages/solana-contrib/src/provider.ts +++ b/packages/solana-contrib/src/provider.ts @@ -16,7 +16,6 @@ import { default as invariant } from "tiny-invariant"; import { SingleConnectionBroadcaster } from "./broadcaster/index.js"; import type { Broadcaster, ReadonlyProvider } from "./index.js"; import { - ALL_TRANSACTION_VERSIONS, PendingTransaction, SignerWallet, TieredBroadcaster, @@ -58,7 +57,6 @@ export class SolanaReadonlyProvider implements ReadonlyProvider { } wallet: Wallet = { - supportedTransactionVersions: ALL_TRANSACTION_VERSIONS, signTransaction: Promise.resolve.bind(Promise), signAllTransactions: Promise.resolve.bind(Promise), publicKey: DEFAULT_READONLY_PUBLIC_KEY, diff --git a/packages/solana-contrib/src/utils/printAccountOwners.ts b/packages/solana-contrib/src/utils/printAccountOwners.ts index 658c7d64..6c601d1a 100644 --- a/packages/solana-contrib/src/utils/printAccountOwners.ts +++ b/packages/solana-contrib/src/utils/printAccountOwners.ts @@ -1,4 +1,4 @@ -// import { Provider as AnchorProvider } from "@project-serum/anchor"; +// import { Provider as AnchorProvider } from "@coral-xyz/anchor"; import type { AccountInfo, Connection } from "@solana/web3.js"; import { PublicKey } from "@solana/web3.js"; @@ -213,12 +213,12 @@ const _transformAccountOwners = async ( if (Object.keys(base58ToResultKey).length > 0) { const accountInfos = await gracefulGetMultipleAccountsInfo( connection, - base58ToLookup + base58ToLookup, ); for (const [base58, resultKey] of Object.entries(base58ToResultKey)) { const lookupIndex = base58ToLookup.findIndex( - (p) => p.toBase58() === base58 + (p) => p.toBase58() === base58, ); if (lookupIndex >= 0) { const accountInfo = accountInfos[lookupIndex]; diff --git a/packages/solana-contrib/src/wallet.ts b/packages/solana-contrib/src/wallet.ts index f1f13ae0..9fbe21b8 100644 --- a/packages/solana-contrib/src/wallet.ts +++ b/packages/solana-contrib/src/wallet.ts @@ -3,14 +3,13 @@ import type { Connection, PublicKey, Signer, + Transaction, + VersionedTransaction, } from "@solana/web3.js"; import { - ALL_TRANSACTION_VERSIONS, isVersionedTransaction, type Provider, - type SupportedTransactionVersions, - type TransactionOrVersionedTransaction, type Wallet, } from "./interfaces.js"; import { SolanaProvider } from "./provider.js"; @@ -18,18 +17,16 @@ import { SolanaProvider } from "./provider.js"; /** * Wallet based on a Signer. */ -export class SignerWallet implements Wallet { +export class SignerWallet implements Wallet { constructor(readonly signer: Signer) {} get publicKey(): PublicKey { return this.signer.publicKey; } - readonly supportedTransactionVersions = ALL_TRANSACTION_VERSIONS; - - signAllTransactions< - T extends TransactionOrVersionedTransaction, - >(txs: T[]): Promise { + signAllTransactions( + txs: T[], + ): Promise { return Promise.resolve( txs.map((tx) => { if (isVersionedTransaction(tx)) { @@ -42,9 +39,9 @@ export class SignerWallet implements Wallet { ); } - signTransaction< - T extends TransactionOrVersionedTransaction, - >(transaction: T): Promise { + signTransaction( + transaction: T, + ): Promise { if (isVersionedTransaction(transaction)) { transaction.sign([this.signer]); } else { diff --git a/packages/use-solana/src/adapters/ledger/core.ts b/packages/use-solana/src/adapters/ledger/core.ts index cfa8f671..4a483346 100644 --- a/packages/use-solana/src/adapters/ledger/core.ts +++ b/packages/use-solana/src/adapters/ledger/core.ts @@ -1,5 +1,6 @@ import type Transport from "@ledgerhq/hw-transport"; -import type { Transaction } from "@solana/web3.js"; +import { isVersionedTransaction } from "@saberhq/solana-contrib"; +import type { Transaction, VersionedTransaction } from "@solana/web3.js"; import { PublicKey } from "@solana/web3.js"; const INS_GET_PUBKEY = 0x05; @@ -90,18 +91,22 @@ export function getSolanaDerivationPath( return derivationPath; } -export async function signTransaction( +export async function signTransaction< + T extends Transaction | VersionedTransaction, +>( transport: Transport, - transaction: Transaction, + transaction: T, derivationPath: Buffer = getSolanaDerivationPath(), ): Promise { - const messageBytes = transaction.serializeMessage(); - return signBytes(transport, messageBytes, derivationPath); + const message = isVersionedTransaction(transaction) + ? transaction.message.serialize() + : transaction.serializeMessage(); + return signBytes(transport, message, derivationPath); } export async function signBytes( transport: Transport, - bytes: Buffer, + bytes: Uint8Array, derivationPath: Buffer = getSolanaDerivationPath(), ): Promise { const numPaths = Buffer.alloc(1); diff --git a/packages/use-solana/src/adapters/ledger/index.ts b/packages/use-solana/src/adapters/ledger/index.ts index 895cf554..57a4f370 100644 --- a/packages/use-solana/src/adapters/ledger/index.ts +++ b/packages/use-solana/src/adapters/ledger/index.ts @@ -6,7 +6,12 @@ import type { SignAndBroadcastOptions, } from "@saberhq/solana-contrib"; import { doSignAndBroadcastTransaction } from "@saberhq/solana-contrib"; -import type { Connection, PublicKey, Transaction } from "@solana/web3.js"; +import type { + Connection, + PublicKey, + Transaction, + VersionedTransaction, +} from "@solana/web3.js"; import EventEmitter from "eventemitter3"; import type { ConnectedWallet, WalletAdapter } from "../types"; @@ -62,10 +67,10 @@ export class LedgerWalletAdapter extends EventEmitter implements WalletAdapter { ); } - async signAllTransactions( - transactions: Transaction[], - ): Promise { - const result: Transaction[] = []; + async signAllTransactions( + transactions: T[], + ): Promise { + const result: T[] = []; for (let i = 0; i < transactions.length; i++) { const transaction = transactions[i]; if (transaction) { @@ -77,7 +82,9 @@ export class LedgerWalletAdapter extends EventEmitter implements WalletAdapter { return result; } - async signTransaction(transaction: Transaction): Promise { + async signTransaction( + transaction: T, + ): Promise { if (!this._transport || !this._publicKey) { throw new Error("Not connected to Ledger"); } diff --git a/packages/use-solana/src/adapters/readonly/index.ts b/packages/use-solana/src/adapters/readonly/index.ts index 810da6d2..af62c904 100644 --- a/packages/use-solana/src/adapters/readonly/index.ts +++ b/packages/use-solana/src/adapters/readonly/index.ts @@ -3,7 +3,11 @@ import type { BroadcastOptions, PendingTransaction, } from "@saberhq/solana-contrib"; -import type { Connection, Transaction } from "@solana/web3.js"; +import type { + Connection, + Transaction, + VersionedTransaction, +} from "@solana/web3.js"; import { PublicKey } from "@solana/web3.js"; import { EventEmitter } from "eventemitter3"; @@ -66,11 +70,15 @@ export class ReadonlyAdapter extends EventEmitter implements WalletAdapter { throw new Error("readonly adapter cannot sign transactions"); } - signAllTransactions(_transactions: Transaction[]): Promise { + signAllTransactions( + _transactions: T[], + ): Promise { throw new Error("readonly adapter cannot sign transactions"); } - signTransaction(_transaction: Transaction): Promise { + signTransaction( + _transaction: T, + ): Promise { throw new Error("readonly adapter cannot sign transactions"); } diff --git a/packages/use-solana/src/adapters/secret-key/index.ts b/packages/use-solana/src/adapters/secret-key/index.ts index 26a57caf..4cad8f4e 100644 --- a/packages/use-solana/src/adapters/secret-key/index.ts +++ b/packages/use-solana/src/adapters/secret-key/index.ts @@ -7,7 +7,12 @@ import { doSignAndBroadcastTransaction, SignerWallet, } from "@saberhq/solana-contrib"; -import type { Connection, PublicKey, Transaction } from "@solana/web3.js"; +import type { + Connection, + PublicKey, + Transaction, + VersionedTransaction, +} from "@solana/web3.js"; import { Keypair } from "@solana/web3.js"; import EventEmitter from "eventemitter3"; @@ -49,7 +54,9 @@ export class SecretKeyAdapter extends EventEmitter implements WalletAdapter { ); } - signAllTransactions(transactions: Transaction[]): Promise { + signAllTransactions( + transactions: T[], + ): Promise { const wallet = this._wallet; if (!wallet) { return Promise.resolve(transactions); @@ -61,7 +68,9 @@ export class SecretKeyAdapter extends EventEmitter implements WalletAdapter { return this._publicKey ?? null; } - async signTransaction(transaction: Transaction): Promise { + async signTransaction( + transaction: T, + ): Promise { const wallet = this._wallet; if (!wallet) { return Promise.resolve(transaction); diff --git a/packages/use-solana/src/adapters/solana.ts b/packages/use-solana/src/adapters/solana.ts index 08638c78..7d227493 100644 --- a/packages/use-solana/src/adapters/solana.ts +++ b/packages/use-solana/src/adapters/solana.ts @@ -1,6 +1,5 @@ import type { Broadcaster, - MultiVersionWalletAdapter, SignAndBroadcastOptions, } from "@saberhq/solana-contrib"; import { @@ -10,35 +9,33 @@ import { import type { EventEmitter, SignerWalletAdapter, - SupportedTransactionVersions, - TransactionOrVersionedTransaction, WalletAdapterEvents, } from "@solana/wallet-adapter-base"; import { BaseSignerWalletAdapter } from "@solana/wallet-adapter-base"; import { GlowWalletName } from "@solana/wallet-adapter-glow"; import { PhantomWalletName } from "@solana/wallet-adapter-phantom"; -import type { Connection, PublicKey, Transaction } from "@solana/web3.js"; +import type { + Connection, + PublicKey, + Transaction, + VersionedTransaction, +} from "@solana/web3.js"; import type { ConnectedWallet, WalletAdapter } from "./types"; -export class SolanaWalletAdapter - implements WalletAdapter -{ - readonly supportedTransactionVersions: V; - +export class SolanaWalletAdapter implements WalletAdapter { constructor( readonly adapter: Omit< SignerWalletAdapter, - | "sendTransaction" - | keyof EventEmitter - | "signTransaction" - | "signAllTransactions" + "sendTransaction" | keyof EventEmitter > & - EventEmitter & - MultiVersionWalletAdapter, - ) { - this.supportedTransactionVersions = adapter.supportedTransactionVersions; - } + EventEmitter & { + signTransaction: (transaction: T) => Promise; + signAllTransactions: ( + transactions: T[], + ) => Promise; + }, + ) {} async signAndBroadcastTransaction( transaction: Transaction, @@ -121,7 +118,7 @@ export class SolanaWalletAdapter return false; } - async signAllTransactions>( + async signAllTransactions( transactions: T[], ): Promise { return this.adapter.signAllTransactions(transactions); @@ -131,7 +128,7 @@ export class SolanaWalletAdapter return this.adapter.publicKey; } - async signTransaction>( + async signTransaction( transaction: T, ): Promise { if (!this.adapter) { diff --git a/packages/use-solana/src/adapters/types.ts b/packages/use-solana/src/adapters/types.ts index b19aa53b..2740297e 100644 --- a/packages/use-solana/src/adapters/types.ts +++ b/packages/use-solana/src/adapters/types.ts @@ -5,21 +5,16 @@ import type { Wallet, } from "@saberhq/solana-contrib"; import { PublicKey } from "@saberhq/solana-contrib"; -import type { - SupportedTransactionVersions, - TransactionOrVersionedTransaction, -} from "@solana/wallet-adapter-base"; import type { WalletConnectWalletAdapterConfig } from "@solana/wallet-adapter-walletconnect"; import type { Connection, PublicKey as SolanaPublicKey, Transaction, + VersionedTransaction, } from "@solana/web3.js"; -export interface WalletAdapter< - Connected extends boolean = boolean, - V extends SupportedTransactionVersions = SupportedTransactionVersions, -> extends Omit, "publicKey"> { +export interface WalletAdapter + extends Omit { publicKey: Connected extends true ? SolanaPublicKey : null; autoApprove: boolean; connected: Connected; @@ -56,16 +51,10 @@ export type WalletAdapterBuilder = ( /** * Wallet adapter wrapper with caching of the PublicKey built-in. */ -export class WrappedWalletAdapter< - Connected extends boolean = boolean, - V extends SupportedTransactionVersions = SupportedTransactionVersions, -> implements Omit, "publicKey"> +export class WrappedWalletAdapter + implements Omit, "publicKey"> { - readonly supportedTransactionVersions: V; - - constructor(readonly adapter: WalletAdapter) { - this.supportedTransactionVersions = adapter.supportedTransactionVersions; - } + constructor(readonly adapter: WalletAdapter) {} private _prevPubkey: SolanaPublicKey | null = null; private _publicKeyCached: PublicKey | null = null; @@ -115,13 +104,13 @@ export class WrappedWalletAdapter< ); } - signTransaction>( + signTransaction( tx: T, ): Promise { return this.adapter.signTransaction(tx); } - signAllTransactions>( + signAllTransactions( transaction: T[], ): Promise { return this.adapter.signAllTransactions(transaction); diff --git a/yarn.lock b/yarn.lock index 57f39257..a87dfd75 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1743,6 +1743,15 @@ __metadata: languageName: node linkType: hard +"@babel/runtime@npm:^7.23.4": + version: 7.24.1 + resolution: "@babel/runtime@npm:7.24.1" + dependencies: + regenerator-runtime: "npm:^0.14.0" + checksum: 10/3a8d61400c636d1ce3a42895a106cd4dfb4e9b88832a8a754a724c68652f821d7a46dce394305d7623f9f0d3597bf0a98aeb5f9c150ef60e14bbbf66caab4654 + languageName: node + linkType: hard + "@babel/template@npm:^7.18.10, @babel/template@npm:^7.3.3": version: 7.18.10 resolution: "@babel/template@npm:7.18.10" @@ -1830,6 +1839,40 @@ __metadata: languageName: node linkType: hard +"@coral-xyz/anchor@npm:^0.29.0": + version: 0.29.0 + resolution: "@coral-xyz/anchor@npm:0.29.0" + dependencies: + "@coral-xyz/borsh": "npm:^0.29.0" + "@noble/hashes": "npm:^1.3.1" + "@solana/web3.js": "npm:^1.68.0" + bn.js: "npm:^5.1.2" + bs58: "npm:^4.0.1" + buffer-layout: "npm:^1.2.2" + camelcase: "npm:^6.3.0" + cross-fetch: "npm:^3.1.5" + crypto-hash: "npm:^1.3.0" + eventemitter3: "npm:^4.0.7" + pako: "npm:^2.0.3" + snake-case: "npm:^3.0.4" + superstruct: "npm:^0.15.4" + toml: "npm:^3.0.0" + checksum: 10/7487e64a033ebd066c86303f6d6d256547bf96fcf6d86d71ab33dfd1110df678569db1bf03df3f05ef622a0c960d793e790d4449ea7507b994bb8144653764c9 + languageName: node + linkType: hard + +"@coral-xyz/borsh@npm:^0.29.0": + version: 0.29.0 + resolution: "@coral-xyz/borsh@npm:0.29.0" + dependencies: + bn.js: "npm:^5.1.2" + buffer-layout: "npm:^1.2.0" + peerDependencies: + "@solana/web3.js": ^1.68.0 + checksum: 10/0c9e3834d26aa9c60f6818a28552729efcf9316ac0a66d790e5cf017c45c7e729498d43681da8c5a1a584f07a479222b2b802468232bcde14ed2248e5e75ea9f + languageName: node + linkType: hard + "@cspotcode/source-map-support@npm:^0.8.0": version: 0.8.1 resolution: "@cspotcode/source-map-support@npm:0.8.1" @@ -2428,6 +2471,13 @@ __metadata: languageName: node linkType: hard +"@noble/hashes@npm:^1.3.3": + version: 1.4.0 + resolution: "@noble/hashes@npm:1.4.0" + checksum: 10/e156e65794c473794c52fa9d06baf1eb20903d0d96719530f523cc4450f6c721a957c544796e6efd0197b2296e7cd70efeb312f861465e17940a3e3c7e0febc6 + languageName: node + linkType: hard + "@noble/secp256k1@npm:^1.6.3": version: 1.7.0 resolution: "@noble/secp256k1@npm:1.7.0" @@ -2496,41 +2546,6 @@ __metadata: languageName: node linkType: hard -"@project-serum/anchor@npm:^0.25.0": - version: 0.25.0 - resolution: "@project-serum/anchor@npm:0.25.0" - dependencies: - "@project-serum/borsh": "npm:^0.2.5" - "@solana/web3.js": "npm:^1.36.0" - base64-js: "npm:^1.5.1" - bn.js: "npm:^5.1.2" - bs58: "npm:^4.0.1" - buffer-layout: "npm:^1.2.2" - camelcase: "npm:^5.3.1" - cross-fetch: "npm:^3.1.5" - crypto-hash: "npm:^1.3.0" - eventemitter3: "npm:^4.0.7" - js-sha256: "npm:^0.9.0" - pako: "npm:^2.0.3" - snake-case: "npm:^3.0.4" - superstruct: "npm:^0.15.4" - toml: "npm:^3.0.0" - checksum: 10/618ab87167cd435223b6606498feba7cd35381bf0b4b2332fe0d2bf64d04c7cb734d98ecedd2020cbb13d74a842a6d69a6eb801f2bf71a709c589b940e1d61e3 - languageName: node - linkType: hard - -"@project-serum/borsh@npm:^0.2.5": - version: 0.2.5 - resolution: "@project-serum/borsh@npm:0.2.5" - dependencies: - bn.js: "npm:^5.1.2" - buffer-layout: "npm:^1.2.0" - peerDependencies: - "@solana/web3.js": ^1.2.0 - checksum: 10/809089b07e7294b3dcb90484292b2426377fbb8b22cf3a99eb6d08015e274d269a6fbeccf100a25f3ea54bf2c0d3e8fc6e5358caf9689affa6051e5367b70958 - languageName: node - linkType: hard - "@project-serum/sol-wallet-adapter@npm:0.2.0": version: 0.2.0 resolution: "@project-serum/sol-wallet-adapter@npm:0.2.0" @@ -2566,7 +2581,7 @@ __metadata: version: 0.0.0-use.local resolution: "@saberhq/anchor-contrib@workspace:packages/anchor-contrib" dependencies: - "@project-serum/anchor": "npm:^0.25.0" + "@coral-xyz/anchor": "npm:^0.29.0" "@saberhq/solana-contrib": "workspace:^" "@saberhq/tsconfig": "npm:^3.1.1" "@solana/web3.js": "npm:^1.87.6" @@ -2579,7 +2594,7 @@ __metadata: tslib: "npm:^2.6.2" typescript: "npm:^5.3.2" peerDependencies: - "@project-serum/anchor": ^0.22 || ^0.23 || ^0.24 + "@coral-xyz/anchor": ^0.22 || ^0.23 || ^0.24 || ^0.28 || ^0.29 "@solana/web3.js": ^1.42 bn.js: ^4 || ^5 languageName: unknown @@ -2589,7 +2604,7 @@ __metadata: version: 0.0.0-use.local resolution: "@saberhq/chai-solana@workspace:packages/chai-solana" dependencies: - "@project-serum/anchor": "npm:^0.25.0" + "@coral-xyz/anchor": "npm:^0.29.0" "@saberhq/anchor-contrib": "workspace:^" "@saberhq/solana-contrib": "workspace:^" "@saberhq/token-utils": "workspace:^" @@ -2607,7 +2622,7 @@ __metadata: tslib: "npm:^2.6.2" typescript: "npm:^5.3.2" peerDependencies: - "@project-serum/anchor": ">=0.17" + "@coral-xyz/anchor": ">=0.17" "@solana/web3.js": ^1.42 bn.js: ^5.2.0 jsbi: "*" @@ -2664,8 +2679,8 @@ __metadata: "@babel/core": "npm:^7.23.5" "@babel/preset-env": "npm:^7.23.5" "@babel/preset-typescript": "npm:^7.23.3" + "@coral-xyz/anchor": "npm:^0.29.0" "@jest/types": "npm:^29.6.3" - "@project-serum/anchor": "npm:^0.25.0" "@rushstack/eslint-patch": "npm:^1.6.0" "@saberhq/eslint-config": "npm:^3.1.1" "@saberhq/eslint-config-react": "npm:^3.1.1" @@ -2942,6 +2957,15 @@ __metadata: languageName: node linkType: hard +"@solana/buffer-layout@npm:^4.0.1": + version: 4.0.1 + resolution: "@solana/buffer-layout@npm:4.0.1" + dependencies: + buffer: "npm:~6.0.3" + checksum: 10/c64b996b832b2b7966a09e97f501fdd1409fece8975f7fb47698d7b8addb97504360cfb2f3d1368949c643d23ed9a4c9f79e19bbd721ebe5bf229353252f649e + languageName: node + linkType: hard + "@solana/spl-token@npm:^0.1.8": version: 0.1.8 resolution: "@solana/spl-token@npm:0.1.8" @@ -3137,7 +3161,7 @@ __metadata: languageName: node linkType: hard -"@solana/web3.js@npm:^1.21.0, @solana/web3.js@npm:^1.36.0": +"@solana/web3.js@npm:^1.21.0": version: 1.63.1 resolution: "@solana/web3.js@npm:1.63.1" dependencies: @@ -3160,6 +3184,29 @@ __metadata: languageName: node linkType: hard +"@solana/web3.js@npm:^1.68.0": + version: 1.91.1 + resolution: "@solana/web3.js@npm:1.91.1" + dependencies: + "@babel/runtime": "npm:^7.23.4" + "@noble/curves": "npm:^1.2.0" + "@noble/hashes": "npm:^1.3.3" + "@solana/buffer-layout": "npm:^4.0.1" + agentkeepalive: "npm:^4.5.0" + bigint-buffer: "npm:^1.1.5" + bn.js: "npm:^5.2.1" + borsh: "npm:^0.7.0" + bs58: "npm:^4.0.1" + buffer: "npm:6.0.3" + fast-stable-stringify: "npm:^1.0.0" + jayson: "npm:^4.1.0" + node-fetch: "npm:^2.7.0" + rpc-websockets: "npm:^7.5.1" + superstruct: "npm:^0.14.2" + checksum: 10/43474b924a73493937eb0979f9ddfe74fb1f3fd7c0c8caa47315e5e4f67c9a70b2d768fe66a3f789180e7e87398c2a086d49d0f25e09a2e1d5bce692d2880b3b + languageName: node + linkType: hard + "@solana/web3.js@npm:^1.87.6": version: 1.87.6 resolution: "@solana/web3.js@npm:1.87.6" @@ -5291,7 +5338,7 @@ __metadata: languageName: node linkType: hard -"agentkeepalive@npm:^4.3.0": +"agentkeepalive@npm:^4.3.0, agentkeepalive@npm:^4.5.0": version: 4.5.0 resolution: "agentkeepalive@npm:4.5.0" dependencies: @@ -5833,7 +5880,7 @@ __metadata: languageName: node linkType: hard -"base64-js@npm:^1.3.1, base64-js@npm:^1.5.1": +"base64-js@npm:^1.3.1": version: 1.5.1 resolution: "base64-js@npm:1.5.1" checksum: 10/669632eb3745404c2f822a18fc3a0122d2f9a7a13f7fb8b5823ee19d1d2ff9ee5b52c53367176ea4ad093c332fd5ab4bd0ebae5a8e27917a4105a4cfc86b1005 @@ -6194,7 +6241,7 @@ __metadata: languageName: node linkType: hard -"camelcase@npm:^6.2.0": +"camelcase@npm:^6.2.0, camelcase@npm:^6.3.0": version: 6.3.0 resolution: "camelcase@npm:6.3.0" checksum: 10/8c96818a9076434998511251dcb2761a94817ea17dbdc37f47ac080bd088fc62c7369429a19e2178b993497132c8cbcf5cc1f44ba963e76782ba469c0474938d @@ -9667,13 +9714,6 @@ __metadata: languageName: node linkType: hard -"js-sha256@npm:^0.9.0": - version: 0.9.0 - resolution: "js-sha256@npm:0.9.0" - checksum: 10/4dc16be74bf4e60d8ee2a482cc822c4d4f5cd060d9f92a060fe3ab1f143cd0946edda552cd274459251c279073df15872a5df47fc4bff054bbc3812e396e990b - languageName: node - linkType: hard - "js-tokens@npm:^3.0.0 || ^4.0.0, js-tokens@npm:^4.0.0": version: 4.0.0 resolution: "js-tokens@npm:4.0.0" @@ -10444,7 +10484,7 @@ __metadata: languageName: node linkType: hard -"node-fetch@npm:^2.6.12": +"node-fetch@npm:^2.6.12, node-fetch@npm:^2.7.0": version: 2.7.0 resolution: "node-fetch@npm:2.7.0" dependencies: