Skip to content

Commit

Permalink
gauntlet: Update to anchor 0.29
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Mar 12, 2024
1 parent ab03ef8 commit 50625c3
Show file tree
Hide file tree
Showing 18 changed files with 193 additions and 147 deletions.
2 changes: 1 addition & 1 deletion gauntlet/packages/gauntlet-serum-multisig/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dependencies": {
"@chainlink/gauntlet-core": "0.1.2",
"@chainlink/gauntlet-solana": "*",
"@project-serum/anchor": "^0.25.0",
"@coral-xyz/anchor": "^0.29.0",
"@solana/web3.js": "^1.50.1"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SolanaCommand, utils } from '@chainlink/gauntlet-solana'
import { logger, BN, prompt } from '@chainlink/gauntlet-core/dist/utils'
import { PublicKey, Keypair, TransactionInstruction, SystemProgram, AccountMeta } from '@solana/web3.js'
import { Idl, Program } from '@project-serum/anchor'
import { Program } from '@coral-xyz/anchor'
import { MAX_BUFFER_SIZE } from '../lib/constants'
import { isDeepEqual } from '../lib/utils'
import { CONTRACT_LIST, getContract } from '../lib/contracts'
Expand Down Expand Up @@ -35,7 +35,7 @@ type ProposalState = {
export const wrapCommand = (command) => {
return class Multisig extends SolanaCommand {
command: SolanaCommand
program: Program<any>
program: any // TODO: typing Program<any> doesn't validate
multisigAddress: PublicKey

static id = `${command.id}:multisig`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getAssociatedTokenAddress, TOKEN_PROGRAM_ID } from '@solana/spl-token'
import { utils } from '@project-serum/anchor'
import { utils } from '@coral-xyz/anchor'
import { PublicKey } from '@solana/web3.js'
import { CONTRACT_LIST, getContract } from '../../../lib/contracts'
import Close from '../../abstract/close'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SolanaCommand, TransactionResponse } from '@chainlink/gauntlet-solana'
import { Keypair, PublicKey, TransactionInstruction, SystemProgram } from '@solana/web3.js'
import { getOrCreateAssociatedTokenAccount } from '@solana/spl-token'
import { CONTRACT_LIST, getContract } from '../../../lib/contracts'
import { utils } from '@project-serum/anchor'
import { utils } from '@coral-xyz/anchor'
import { logger, BN, prompt } from '@chainlink/gauntlet-core/dist/utils'
import RDD from '../../../lib/rdd'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { logger, prompt, BN } from '@chainlink/gauntlet-core/dist/utils'
import { SolanaCommand, TransactionResponse } from '@chainlink/gauntlet-solana'
import { PublicKey } from '@solana/web3.js'
import { getAssociatedTokenAddress, TOKEN_PROGRAM_ID } from '@solana/spl-token'
import { utils } from '@project-serum/anchor'
import { utils } from '@coral-xyz/anchor'
import { CONTRACT_LIST, getContract } from '../../../../lib/contracts'
import ProposeOffchainConfig, { OffchainConfig } from '../proposeOffchainConfig'
import { serializeOffchainConfig, deserializeConfig } from '../../../../lib/encoding'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Result } from '@chainlink/gauntlet-core'
import { SolanaCommand, TransactionResponse } from '@chainlink/gauntlet-solana'
import { PublicKey } from '@solana/web3.js'
import { getAssociatedTokenAddress, TOKEN_PROGRAM_ID } from '@solana/spl-token'
import { utils } from '@project-serum/anchor'
import { utils } from '@coral-xyz/anchor'
import { logger, BN, prompt } from '@chainlink/gauntlet-core/dist/utils'
import { CONTRACT_LIST, getContract } from '../../../lib/contracts'
import RDD from '../../../lib/rdd'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Result } from '@chainlink/gauntlet-core'
import { SolanaCommand, TransactionResponse } from '@chainlink/gauntlet-solana'
import { parseIdlErrors, ProgramError, utils } from '@project-serum/anchor'
import { parseIdlErrors, ProgramError, utils } from '@coral-xyz/anchor'
import { Keypair, PublicKey, Transaction, TransactionInstruction } from '@solana/web3.js'
import { createHash } from 'crypto'
import * as secp256k1 from 'secp256k1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Result } from '@chainlink/gauntlet-core'
import { SolanaCommand, TransactionResponse } from '@chainlink/gauntlet-solana'
import { PublicKey } from '@solana/web3.js'
import { TOKEN_PROGRAM_ID } from '@solana/spl-token'
import { utils } from '@project-serum/anchor'
import { utils } from '@coral-xyz/anchor'
import { logger, BN, prompt } from '@chainlink/gauntlet-core/dist/utils'
import { CONTRACT_LIST, getContract } from '../../../lib/contracts'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Result } from '@chainlink/gauntlet-core'
import { SolanaCommand, TransactionResponse } from '@chainlink/gauntlet-solana'
import { PublicKey } from '@solana/web3.js'
import { TOKEN_PROGRAM_ID } from '@solana/spl-token'
import { utils } from '@project-serum/anchor'
import { utils } from '@coral-xyz/anchor'
import { logger, prompt } from '@chainlink/gauntlet-core/dist/utils'
import { CONTRACT_LIST, getContract } from '../../../lib/contracts'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Result } from '@chainlink/gauntlet-core'
import { logger } from '@chainlink/gauntlet-core/dist/utils'
import { SolanaCommand, TransactionResponse } from '@chainlink/gauntlet-solana'
import { Idl, Program } from '@project-serum/anchor'
import { Idl, Program } from '@coral-xyz/anchor'
import { PublicKey } from '@solana/web3.js'
import { CONTRACT_LIST, getContract } from '../../../lib/contracts'
import { SolanaConstructor } from '../../../lib/types'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Result } from '@chainlink/gauntlet-core'
import { logger } from '@chainlink/gauntlet-core/dist/utils'
import { SolanaCommand, TransactionResponse } from '@chainlink/gauntlet-solana'
import { PublicKey } from '@solana/web3.js'
import { utils } from '@project-serum/anchor'
import { utils } from '@coral-xyz/anchor'
import { CONTRACT_LIST, getContract } from '../../../lib/contracts'
import RDD from '../../../lib/rdd'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Connection, PublicKey } from '@solana/web3.js'
import { Program } from '@project-serum/anchor'
import { Program } from '@coral-xyz/anchor'
import { provider } from '@chainlink/gauntlet-solana'
import { BN } from '@chainlink/gauntlet-core/dist/utils'

Expand Down
4 changes: 2 additions & 2 deletions gauntlet/packages/gauntlet-solana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"@chainlink/gauntlet-core": "0.1.2",
"@ledgerhq/hw-app-solana": "^6.20.0",
"@ledgerhq/hw-transport-node-hid": "^6.20.0",
"@project-serum/anchor": "^0.25.0",
"@project-serum/borsh": "^0.2.2",
"@coral-xyz/anchor": "^0.29.0",
"@coral-xyz/borsh": "^0.29.0",
"@solana/web3.js": "^1.50.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@solana/web3.js'
import { withProvider, withWallet, withNetwork } from '../middlewares'
import { TransactionResponse } from '../types'
import { ProgramError, parseIdlErrors, Idl, Program, AnchorProvider } from '@project-serum/anchor'
import { ProgramError, parseIdlErrors, Idl, Program, AnchorProvider } from '@coral-xyz/anchor'
import { SolanaWallet } from '../wallet'
import { logger } from '@chainlink/gauntlet-core/dist/utils'
import { makeTx } from '../../lib/utils'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Middleware, Next } from '@chainlink/gauntlet-core'
import { boolean } from '@chainlink/gauntlet-core/dist/lib/args'
import { assertions, logger } from '@chainlink/gauntlet-core/dist/utils'
import { AnchorProvider } from '@project-serum/anchor'
import { AnchorProvider } from '@coral-xyz/anchor'
import { Connection, Keypair } from '@solana/web3.js'
import { DEFAULT_DERIVATION_PATH } from '../lib/constants'
import SolanaCommand from './internal/solana'
Expand Down
34 changes: 25 additions & 9 deletions gauntlet/packages/gauntlet-solana/src/commands/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Wallet } from '@project-serum/anchor'
import { Keypair, PublicKey, Transaction } from '@solana/web3.js'
import { Wallet } from '@coral-xyz/anchor'
import { Keypair, PublicKey, Transaction, VersionedTransaction } from '@solana/web3.js'
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'
import Solana from '@ledgerhq/hw-app-solana'
import { logger } from '@chainlink/gauntlet-core/dist/utils'
Expand All @@ -12,8 +12,8 @@ export enum WalletTypes {
export abstract class SolanaWallet {
static create: (...args) => Promise<SolanaWallet>

abstract signTransaction: (tx: Transaction) => Promise<Transaction>
abstract signAllTransactions: (txs: Transaction[]) => Promise<Transaction[]>
abstract signTransaction<T extends Transaction | VersionedTransaction>(tx: T): Promise<T>
abstract signAllTransactions<T extends Transaction | VersionedTransaction>(txs: T[]): Promise<T[]>
abstract publicKey: PublicKey
abstract payer: Keypair

Expand All @@ -33,8 +33,12 @@ export class LocalWallet extends SolanaWallet {
return new LocalWallet(wallet)
}

signTransaction = (tx: Transaction) => this.wallet.signTransaction(tx)
signAllTransactions = (txs: Transaction[]) => this.wallet.signAllTransactions(txs)
async signTransaction<T extends Transaction | VersionedTransaction>(tx: T): Promise<T> {
return this.wallet.signTransaction(tx)
}
async signAllTransactions<T extends Transaction | VersionedTransaction>(txs: T[]): Promise<T[]> {
return this.wallet.signAllTransactions(txs)
}

get publicKey() {
return this.wallet.payer.publicKey
Expand All @@ -47,6 +51,10 @@ export class LocalWallet extends SolanaWallet {
type = () => WalletTypes.LOCAL
}

const isVersionedTransaction = (tx: Transaction | VersionedTransaction): tx is VersionedTransaction => {
return 'version' in tx
}

export class LedgerWallet extends SolanaWallet {
publicKey: PublicKey
wallet: Solana
Expand Down Expand Up @@ -74,15 +82,23 @@ export class LedgerWallet extends SolanaWallet {
}
}

signTransaction = async (tx: Transaction) => {
signTransaction = async <T extends Transaction | VersionedTransaction>(tx: T) => {
logger.info(`Ledger: Request to sign message`)
const msg = tx.serializeMessage()
// serializeMessage on v0, serialize on v1

let msg: Buffer

if (isVersionedTransaction(tx)) {
msg = Buffer.from(tx.serialize())
} else {
msg = tx.serializeMessage()
}
const { signature } = await this.wallet.signTransaction(this.path, msg)
tx.addSignature(this.publicKey, signature)
return tx
}

signAllTransactions = async (txs: Transaction[]) => {
signAllTransactions = async <T extends Transaction | VersionedTransaction>(txs: T[]) => {
logger.warn('Signing multiple transactions with Ledger')
return Promise.all(txs.map(this.signTransaction))
}
Expand Down
2 changes: 1 addition & 1 deletion gauntlet/packages/gauntlet-solana/src/lib/provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Connection, ParsedTransactionWithMeta, PublicKey } from '@solana/web3.js'
import { EventParser, Event, Program } from '@project-serum/anchor'
import { EventParser, Event, Program } from '@coral-xyz/anchor'

/*
Gets the latest transactions to a contract
Expand Down
Loading

0 comments on commit 50625c3

Please sign in to comment.