diff --git a/examples/feeds/01_feed_client/package.json b/examples/feeds/01_feed_client/package.json index d4b86fe56..46653ec6f 100644 --- a/examples/feeds/01_feed_client/package.json +++ b/examples/feeds/01_feed_client/package.json @@ -18,9 +18,9 @@ "@project-serum/borsh": "^0.2.5", "@solana/spl-token": "^0.3.8", "@solana/web3.js": "^1.78.3", - "@switchboard-xyz/common": "^2.3.2", + "@switchboard-xyz/common": "^2.3.4", "@switchboard-xyz/oracle": "latest", - "@switchboard-xyz/solana.js": "^2.5.4", + "@switchboard-xyz/solana.js": "^2.5.6", "chalk": "^4.1.2", "dotenv": "^16.0.1", "yargs": "^17.5.1" diff --git a/examples/feeds/02_spl_native/package.json b/examples/feeds/02_spl_native/package.json index 17a26cba6..ea0372652 100644 --- a/examples/feeds/02_spl_native/package.json +++ b/examples/feeds/02_spl_native/package.json @@ -17,9 +17,9 @@ "dependencies": { "@coral-xyz/anchor": "^0.28.0", "@solana/web3.js": "^1.77.3", - "@switchboard-xyz/common": "^2.3.2", + "@switchboard-xyz/common": "^2.3.4", "@switchboard-xyz/oracle": "latest", - "@switchboard-xyz/solana.js": "^2.5.4" + "@switchboard-xyz/solana.js": "^2.5.6" }, "devDependencies": { "@types/chai": "^4.3.0", diff --git a/examples/functions/01_basic_oracle/Cargo.toml b/examples/functions/01_basic_oracle/Cargo.toml index 6f6e2fb93..2e265090e 100644 --- a/examples/functions/01_basic_oracle/Cargo.toml +++ b/examples/functions/01_basic_oracle/Cargo.toml @@ -19,6 +19,6 @@ cpi = ["no-entrypoint"] default = [] [dependencies] -switchboard-solana = "0.28.4" +switchboard-solana = "=0.28.6" # switchboard-solana = { version = "0.28.4", path = "../../../rust/switchboard-solana" } -bytemuck = "^1" \ No newline at end of file +bytemuck = "^1" diff --git a/examples/functions/01_basic_oracle/package.json b/examples/functions/01_basic_oracle/package.json index 84a1856f6..218846b71 100644 --- a/examples/functions/01_basic_oracle/package.json +++ b/examples/functions/01_basic_oracle/package.json @@ -13,9 +13,9 @@ }, "dependencies": { "@coral-xyz/anchor": "^0.28.0", - "@solana/spl-token": "^0.3.8", - "@solana/web3.js": "^1.78.4", - "@switchboard-xyz/solana.js": "^2.5.4" + "@solana/spl-token": "^0.3.6", + "@solana/web3.js": "^1.78.0", + "@switchboard-xyz/solana.js": "^2.5.6" }, "devDependencies": { "@types/bn.js": "^5.1.0", diff --git a/examples/functions/01_basic_oracle/sgx-function/Cargo.toml b/examples/functions/01_basic_oracle/sgx-function/Cargo.toml index 87b650bdf..b9357f10c 100644 --- a/examples/functions/01_basic_oracle/sgx-function/Cargo.toml +++ b/examples/functions/01_basic_oracle/sgx-function/Cargo.toml @@ -16,6 +16,6 @@ futures = "0.3" serde = "^1" serde_json = "^1" switchboard-utils = "0.8.0" -switchboard-solana = "0.28.4" +switchboard-solana = "=0.28.6" # switchboard-solana = { version = "0.28.4", path = "../../../../rust/switchboard-solana" } -# switchboard-utils = { version = "0.8.0", path = "../../../../../../rust/switchboard-utils" } \ No newline at end of file +# switchboard-utils = { version = "0.8.0", path = "../../../../../../rust/switchboard-utils" } diff --git a/examples/functions/01_basic_oracle/sgx-function/Makefile b/examples/functions/01_basic_oracle/sgx-function/Makefile index e686e949f..84d91be01 100644 --- a/examples/functions/01_basic_oracle/sgx-function/Makefile +++ b/examples/functions/01_basic_oracle/sgx-function/Makefile @@ -9,16 +9,16 @@ DOCKER_BUILD_COMMAND=DOCKER_BUILDKIT=1 docker buildx build --platform linux/amd6 # Default make task all: build -docker_build: +docker_build: ${DOCKER_BUILD_COMMAND} --pull -f Dockerfile -t ${DOCKER_IMAGE_NAME}:latest --load ../ -docker_publish: +docker_publish: ${DOCKER_BUILD_COMMAND} --pull -f Dockerfile -t ${DOCKER_IMAGE_NAME}:latest --push ../ -dev_docker_build: +dev_docker_build: ${DOCKER_BUILD_COMMAND} --pull -f Dockerfile.dev -t ${DOCKER_IMAGE_NAME}:latest --load ../../../../../../ -dev_docker_publish: +dev_docker_publish: ${DOCKER_BUILD_COMMAND} --pull -f Dockerfile.dev -t ${DOCKER_IMAGE_NAME}:latest --push ../../../../../../ build: docker_build measurement @@ -30,15 +30,16 @@ publish: docker_publish measurement dev_publish: dev_docker_publish measurement measurement: - @docker run -d --platform=linux/amd64 --pull always -q --name=my-switchboard-function ${DOCKER_IMAGE_NAME}:latest > /dev/null + @docker run -d --platform=linux/amd64 -q --name=my-switchboard-function ${DOCKER_IMAGE_NAME}:latest > /dev/null @docker cp my-switchboard-function:/measurement.txt measurement.txt + @echo -n 'MrEnclve: ' + @cat measurement.txt @docker stop my-switchboard-function > /dev/null @docker rm my-switchboard-function > /dev/null - @echo MrEnclave: $(shell cat ./measurement.txt) simulate: docker_build docker run -it --platform=linux/amd64 --entrypoint=/bin/bash ${DOCKER_IMAGE_NAME}:latest /boot.sh --test - + # Task to clean up the compiled rust application clean: cargo clean @@ -48,4 +49,4 @@ clean: # @docker cp latest-my-switchboard-function:/measurement.txt latest-measurement.txt # @docker stop latest-my-switchboard-function > /dev/null # @docker rm latest-my-switchboard-function > /dev/null -# @echo latest MrEnclave: $(shell rm ./latest-measurement.txt) \ No newline at end of file +# @echo latest MrEnclave: $(shell rm ./latest-measurement.txt) diff --git a/examples/functions/02_liquidity_oracle/package.json b/examples/functions/02_liquidity_oracle/package.json index 5317cedd8..d324e2551 100644 --- a/examples/functions/02_liquidity_oracle/package.json +++ b/examples/functions/02_liquidity_oracle/package.json @@ -14,8 +14,8 @@ "@coral-xyz/anchor": "^0.28.0", "@solana/spl-token": "^0.3.8", "@solana/web3.js": "^1.78.3", - "@switchboard-xyz/common": "^2.3.2", - "@switchboard-xyz/solana.js": "^2.5.4" + "@switchboard-xyz/common": "^2.3.4", + "@switchboard-xyz/solana.js": "^2.5.6" }, "devDependencies": { "@types/bn.js": "^5.1.0", diff --git a/examples/functions/03_candles_oracle/package.json b/examples/functions/03_candles_oracle/package.json index 969e62b82..0e1bf03b3 100644 --- a/examples/functions/03_candles_oracle/package.json +++ b/examples/functions/03_candles_oracle/package.json @@ -15,8 +15,8 @@ "@coral-xyz/anchor": "^0.28.0", "@solana/spl-token": "^0.3.8", "@solana/web3.js": "^1.78.3", - "@switchboard-xyz/common": "^2.3.2", - "@switchboard-xyz/solana.js": "^2.5.4" + "@switchboard-xyz/common": "^2.3.4", + "@switchboard-xyz/solana.js": "^2.5.6" }, "devDependencies": { "@types/bn.js": "^5.1.0", diff --git a/examples/functions/04_randomness_callback/package.json b/examples/functions/04_randomness_callback/package.json index 9a383e273..e8034a75f 100644 --- a/examples/functions/04_randomness_callback/package.json +++ b/examples/functions/04_randomness_callback/package.json @@ -10,8 +10,8 @@ "@coral-xyz/anchor": "^0.27.0", "@solana/spl-token": "^0.3.8", "@solana/web3.js": "^1.78.3", - "@switchboard-xyz/common": "^2.3.2", - "@switchboard-xyz/solana.js": "^2.5.4", + "@switchboard-xyz/common": "^2.3.4", + "@switchboard-xyz/solana.js": "^2.5.6", "dotenv": "^16.3.1" }, "devDependencies": { diff --git a/examples/functions/05_raffle_program/package.json b/examples/functions/05_raffle_program/package.json index 96a117460..da3a42078 100644 --- a/examples/functions/05_raffle_program/package.json +++ b/examples/functions/05_raffle_program/package.json @@ -7,8 +7,8 @@ }, "dependencies": { "@coral-xyz/anchor": "^0.28.0", - "@switchboard-xyz/common": "^2.3.2", - "@switchboard-xyz/solana.js": "^2.5.4" + "@switchboard-xyz/common": "^2.3.4", + "@switchboard-xyz/solana.js": "^2.5.6" }, "devDependencies": { "@types/bn.js": "^5.1.0", diff --git a/examples/vrf/01_vrf_client/package.json b/examples/vrf/01_vrf_client/package.json index f04b0f929..9fe442a1d 100644 --- a/examples/vrf/01_vrf_client/package.json +++ b/examples/vrf/01_vrf_client/package.json @@ -18,9 +18,9 @@ "@project-serum/borsh": "^0.2.5", "@solana/spl-token": "^0.3.6", "@solana/web3.js": "^1.77.3", - "@switchboard-xyz/common": "^2.3.2", + "@switchboard-xyz/common": "^2.3.4", "@switchboard-xyz/oracle": "latest", - "@switchboard-xyz/solana.js": "^2.5.4", + "@switchboard-xyz/solana.js": "^2.5.6", "chalk": "^4.1.2", "dotenv": "^16.0.1", "yargs": "^17.5.1" diff --git a/javascript/solana.js/idl/attestation-devnet.json b/javascript/solana.js/idl/attestation-devnet.json index c6f01736d..b1c07a614 100644 --- a/javascript/solana.js/idl/attestation-devnet.json +++ b/javascript/solana.js/idl/attestation-devnet.json @@ -2,6 +2,11 @@ "version": "0.1.0", "name": "switchboard_attestation_program", "instructions": [ + { + "name": "viewVersion", + "accounts": [], + "args": [] + }, { "name": "stateInit", "accounts": [ diff --git a/javascript/solana.js/idl/devnet.json b/javascript/solana.js/idl/devnet.json index c627d89ce..1588588c8 100644 --- a/javascript/solana.js/idl/devnet.json +++ b/javascript/solana.js/idl/devnet.json @@ -2,6 +2,11 @@ "version": "0.1.0", "name": "switchboard_v2", "instructions": [ + { + "name": "viewVersion", + "accounts": [], + "args": [] + }, { "name": "aggregatorClose", "accounts": [ diff --git a/javascript/solana.js/package.json b/javascript/solana.js/package.json index b0d57ec60..f8b2748d1 100644 --- a/javascript/solana.js/package.json +++ b/javascript/solana.js/package.json @@ -1,6 +1,6 @@ { "name": "@switchboard-xyz/solana.js", - "version": "2.5.4", + "version": "2.5.6", "author": "", "license": "MIT", "description": "A Typescript client to interact with Switchboard on Solana.", @@ -29,7 +29,7 @@ "@coral-xyz/borsh": "^0.28.0", "@solana/spl-token": "^0.3.8", "@solana/web3.js": "^1.78.3", - "@switchboard-xyz/common": "^2.3.2", + "@switchboard-xyz/common": "^2.3.3", "cron-validator": "^1.3.1", "dotenv": "^16.3.1", "lodash": "^4.17.21" diff --git a/javascript/solana.js/scripts/generate-client.ts b/javascript/solana.js/scripts/generate-client.ts index 3ba8ffd17..336cbf0aa 100644 --- a/javascript/solana.js/scripts/generate-client.ts +++ b/javascript/solana.js/scripts/generate-client.ts @@ -47,11 +47,14 @@ const ignoreFiles = [ `${v2GeneratedPath}/types/Lanes.ts`, // anchor-client-gen struggles with dual exports `${v2GeneratedPath}/types/index.ts`, // TODO: Need a better way to handle this. anchor-client-gen adds multiple, broken exports (for VRF builder) `${v2GeneratedPath}/errors/index.ts`, // need to revert the program ID check, + `${v2GeneratedPath}/instructions/viewVersion.ts`, `${attestationGeneratedPath}/types/VerificationStatus.ts`, `${attestationGeneratedPath}/errors/index.ts`, `${attestationGeneratedPath}/types/SwitchboardAttestationPermission.ts`, `${attestationGeneratedPath}/instructions/functionDeactivateLookup.ts`, `${attestationGeneratedPath}/instructions/accountCloseOverride.ts`, + `${attestationGeneratedPath}/instructions/viewVersion.ts`, + `${attestationGeneratedPath}/instructions/index.ts`, // make sure to disable this if adding more attestation program instructions. used to avoid name conflict on viewVersion ixn // `${v2GeneratedPath}/types/VerificationStatus.ts`, ]; diff --git a/javascript/solana.js/src/SwitchboardProgram.ts b/javascript/solana.js/src/SwitchboardProgram.ts index 04f18dc28..f0d8d1873 100644 --- a/javascript/solana.js/src/SwitchboardProgram.ts +++ b/javascript/solana.js/src/SwitchboardProgram.ts @@ -11,6 +11,7 @@ import { ProgramStateAccount, QueueAccount, } from "./accounts/index.js"; +import { viewVersion as viewAttestationVersion } from "./generated/attestation-program/instructions/viewVersion.js"; import { AggregatorAccountData, BufferRelayerAccountData, @@ -24,6 +25,7 @@ import { SlidingResultAccountData, VrfAccountData, } from "./generated/index.js"; +import { viewVersion as viewSbVersion } from "./generated/oracle-program/instructions/viewVersion.js"; import { DEVNET_GENESIS_HASH, MAINNET_GENESIS_HASH, @@ -46,6 +48,7 @@ import type { LoadedJobDefinition } from "./types.js"; import type { AccountNamespace, Idl, Wallet } from "@coral-xyz/anchor"; import { ACCOUNT_DISCRIMINATOR_SIZE, + AnchorError, AnchorProvider, BorshAccountsCoder, Program, @@ -60,9 +63,13 @@ import type { SendOptions, Transaction, TransactionSignature, +} from "@solana/web3.js"; +import { + Keypair, + PublicKey, + TransactionMessage, VersionedTransaction, } from "@solana/web3.js"; -import { Keypair, PublicKey } from "@solana/web3.js"; import { OracleJob } from "@switchboard-xyz/common"; export type SendTransactionOptions = (ConfirmOptions | SendOptions) & { @@ -429,6 +436,53 @@ export class SwitchboardProgram { return program; }; + public async getGitVersion(): Promise { + const messageV0 = new TransactionMessage({ + payerKey: this.walletPubkey, + instructions: [ + await this._program.methods.viewVersion().accounts({}).instruction(), + ], + recentBlockhash: (await this.connection.getLatestBlockhash()).blockhash, + }).compileToLegacyMessage(); + const simulationResult = await this.connection.simulateTransaction( + new VersionedTransaction(messageV0), + { sigVerify: false } + ); + const logs = (simulationResult.value?.logs ?? []).join("\n"); + const version = extractVersion(logs); + if (version) { + return version; + } + throw new Error( + `Failed to yield the git version in the view_version simulation result` + ); + } + + public async getAttestationGitVersion(): Promise { + const messageV0 = new TransactionMessage({ + payerKey: this.walletPubkey, + instructions: [ + await this._attestationProgram.methods + .viewVersion() + .accounts({}) + .instruction(), + ], + recentBlockhash: (await this.connection.getLatestBlockhash()).blockhash, + }).compileToLegacyMessage(); + const simulationResult = await this.connection.simulateTransaction( + new VersionedTransaction(messageV0), + { sigVerify: false } + ); + const logs = (simulationResult.value?.logs ?? []).join("\n"); + const version = extractVersion(logs); + if (version) { + return version; + } + throw new Error( + `Failed to yield the git version in the view_version simulation result` + ); + } + /** * Retrieves the Switchboard V2 Program ID for the currently connected cluster. * @return The PublicKey of the Switchboard V2 Program ID. @@ -1040,3 +1094,9 @@ interface AccountInfoResponse { pubkey: PublicKey; account: AccountInfo; } + +function extractVersion(input: string): string | null { + const regex = /VERSION: (\S+)/; + const match = input.match(regex); + return match ? match[1] : null; +} diff --git a/javascript/solana.js/src/TransactionObject.ts b/javascript/solana.js/src/TransactionObject.ts index e3b578c59..7849843ff 100644 --- a/javascript/solana.js/src/TransactionObject.ts +++ b/javascript/solana.js/src/TransactionObject.ts @@ -37,7 +37,9 @@ export interface ITransactionObject extends Required { export interface TransactionObjectOptions { enableDurableNonce?: boolean; + /** The number of lamports to affix to the transaction. */ computeUnitPrice?: number; + /** The number of compute units for the transaction. */ computeUnitLimit?: number; } @@ -127,7 +129,8 @@ export class TransactionObject implements ITransactionObject { } const priorityTxn = TransactionObject.getComputeUnitPriceIxn( - options?.computeUnitPrice + options?.computeUnitPrice, + options?.computeUnitLimit ); if ( priorityTxn !== undefined && @@ -178,11 +181,18 @@ export class TransactionObject implements ITransactionObject { } static getComputeUnitPriceIxn( - computeUnitPrice?: number + computeUnitPrice?: number, // lamports + _computeUnitLimit?: number ): TransactionInstruction | undefined { + // calculatePriorityFee = 100 Lamports + // computeUnitLimit = 250,000 CUs + // lamports / CU = 100 / 250,000 = 0.0004 Lamports / CUs + // microLamports = 0.0004 * 10e6 = 4000 microLamports / CU if (computeUnitPrice && computeUnitPrice > 0) { return ComputeBudgetProgram.setComputeUnitPrice({ - microLamports: computeUnitPrice, + microLamports: Math.round( + (computeUnitPrice / (_computeUnitLimit ?? 250000)) * 1000000 + ), }); } diff --git a/javascript/solana.js/src/accounts/aggregatorAccount.ts b/javascript/solana.js/src/accounts/aggregatorAccount.ts index 39d811616..60a0a9bd8 100644 --- a/javascript/solana.js/src/accounts/aggregatorAccount.ts +++ b/javascript/solana.js/src/accounts/aggregatorAccount.ts @@ -33,6 +33,7 @@ import type { TransactionPackOptions, } from "../TransactionObject.js"; import { TransactionObject } from "../TransactionObject.js"; +import { calculatePriorityFee } from "../utils.js"; import type { OnAccountChangeCallback } from "./account.js"; import { Account } from "./account.js"; @@ -2272,32 +2273,28 @@ export class AggregatorAccount extends Account { timestamp = Math.round(Date.now() / 1000), baseFee = 0 // base compute unit price ): number { - // parse defaults + const currentRoundOpenTimestamp = + aggregator.currentRound.roundOpenTimestamp.toNumber(); + const latestConfirmedOpenTimestamp = + aggregator.latestConfirmedRound.roundOpenTimestamp.toNumber(); + const lastUpdateTimestamp = - aggregator.latestConfirmedRound.roundOpenTimestamp.gt(new BN(0)) - ? aggregator.latestConfirmedRound.roundOpenTimestamp.toNumber() - : timestamp; // on first update this would cause max multiplier - const priorityFeeBumpPeriod = Math.max(1, aggregator.priorityFeeBumpPeriod); // cant divide by 0 - const maxPriorityFeeMultiplier = Math.max( - 1, + latestConfirmedOpenTimestamp === 0 + ? timestamp + : // if we use the latest confirmed timestamp then its a race to confirm first + // only the first responder will be fully reimbursed for their priority fee + aggregator.resolutionMode.kind === "ModeSlidingResolution" + ? Math.min(currentRoundOpenTimestamp, latestConfirmedOpenTimestamp) + : latestConfirmedOpenTimestamp; + + return calculatePriorityFee( + timestamp, + lastUpdateTimestamp, + aggregator.basePriorityFee + baseFee, + aggregator.priorityFeeBump, + aggregator.priorityFeeBumpPeriod, aggregator.maxPriorityFeeMultiplier ); - - // calculate staleness multiplier - const multiplier = Math.min( - (timestamp - lastUpdateTimestamp) / priorityFeeBumpPeriod, - maxPriorityFeeMultiplier - ); - - const feeBump = aggregator.priorityFeeBump * multiplier; - const fee = baseFee + aggregator.basePriorityFee + feeBump; - if (Number.isNaN(fee)) { - return 0; - } - - // Should we enforce some upper limit? Like 1 SOL? - // Probably not, gives MEV bots a floor - return Math.round(fee); } /** Fetch the balance of an aggregator's lease */ diff --git a/javascript/solana.js/src/accounts/oracleAccount.ts b/javascript/solana.js/src/accounts/oracleAccount.ts index fc572fc98..7038cb9f8 100644 --- a/javascript/solana.js/src/accounts/oracleAccount.ts +++ b/javascript/solana.js/src/accounts/oracleAccount.ts @@ -609,6 +609,17 @@ export class OracleAccount extends Account { ); if (params.unwrap) { + const withdrawDestination = params.withdrawAccount ?? payer; + const withdrawDestinationAccountInfo = + await this.program.connection.getAccountInfo(withdrawDestination); + if ( + !withdrawDestinationAccountInfo?.owner.equals(SystemProgram.programId) + ) { + throw new Error( + `'withdrawAccount' must be owned by the SystemProgram if 'unwrap' is true` + ); + } + const ephemeralWallet = Keypair.generate(); const ixns = [ @@ -654,7 +665,7 @@ export class OracleAccount extends Account { ), spl.createCloseAccountInstruction( ephemeralWallet.publicKey, - oracle.oracleAuthority, + withdrawDestination, payer ), ]; @@ -675,6 +686,19 @@ export class OracleAccount extends Account { ? params.withdrawAccount : this.program.mint.getAssociatedAddress(payer); + const withdrawAccountInfo = await this.program.mint.getAccount( + withdrawAccount + ); + + if ( + !withdrawAccountInfo || + !withdrawAccountInfo.owner.equals(spl.TOKEN_PROGRAM_ID) + ) { + throw new Error( + `'withdrawAccount' must be initialized and owned by the TokenProgram if 'unwrap' is false` + ); + } + const withdrawIxn = types.oracleWithdraw( this.program, { @@ -852,6 +876,8 @@ export interface OracleWithdrawBaseParams { export interface OracleWithdrawUnwrapParams extends OracleWithdrawBaseParams { unwrap: true; + /** System account where the unwrapped tokens will be sent. Defaults to the payer. */ + withdrawAccount?: PublicKey; } export interface OracleWithdrawWalletParams extends OracleWithdrawBaseParams { diff --git a/javascript/solana.js/src/generated/attestation-program/instructions/viewVersion.ts b/javascript/solana.js/src/generated/attestation-program/instructions/viewVersion.ts new file mode 100644 index 000000000..13083a2ea --- /dev/null +++ b/javascript/solana.js/src/generated/attestation-program/instructions/viewVersion.ts @@ -0,0 +1,15 @@ +import type { SwitchboardProgram } from "../../../SwitchboardProgram.js"; +import * as types from "../types/index.js"; // eslint-disable-line @typescript-eslint/no-unused-vars + +import * as borsh from "@coral-xyz/borsh"; // eslint-disable-line @typescript-eslint/no-unused-vars +import type { AccountMeta, PublicKey } from "@solana/web3.js"; +import { TransactionInstruction } from "@solana/web3.js"; // eslint-disable-line @typescript-eslint/no-unused-vars +import { BN } from "@switchboard-xyz/common"; // eslint-disable-line @typescript-eslint/no-unused-vars + +export function viewVersion(programId: PublicKey) { + const keys: Array = []; + const identifier = Buffer.from([213, 222, 182, 245, 222, 107, 62, 71]); + const data = identifier; + const ix = new TransactionInstruction({ keys, programId, data }); + return ix; +} diff --git a/javascript/solana.js/src/generated/oracle-program/instructions/index.ts b/javascript/solana.js/src/generated/oracle-program/instructions/index.ts index 0e1eee73d..407ca2260 100644 --- a/javascript/solana.js/src/generated/oracle-program/instructions/index.ts +++ b/javascript/solana.js/src/generated/oracle-program/instructions/index.ts @@ -160,6 +160,7 @@ export type { VaultTransferArgs, } from "./vaultTransfer.js"; export { vaultTransfer } from "./vaultTransfer.js"; +export { viewVersion } from "./viewVersion.js"; export type { VrfCloseActionAccounts, VrfCloseActionArgs, diff --git a/javascript/solana.js/src/generated/oracle-program/instructions/viewVersion.ts b/javascript/solana.js/src/generated/oracle-program/instructions/viewVersion.ts new file mode 100644 index 000000000..13083a2ea --- /dev/null +++ b/javascript/solana.js/src/generated/oracle-program/instructions/viewVersion.ts @@ -0,0 +1,15 @@ +import type { SwitchboardProgram } from "../../../SwitchboardProgram.js"; +import * as types from "../types/index.js"; // eslint-disable-line @typescript-eslint/no-unused-vars + +import * as borsh from "@coral-xyz/borsh"; // eslint-disable-line @typescript-eslint/no-unused-vars +import type { AccountMeta, PublicKey } from "@solana/web3.js"; +import { TransactionInstruction } from "@solana/web3.js"; // eslint-disable-line @typescript-eslint/no-unused-vars +import { BN } from "@switchboard-xyz/common"; // eslint-disable-line @typescript-eslint/no-unused-vars + +export function viewVersion(programId: PublicKey) { + const keys: Array = []; + const identifier = Buffer.from([213, 222, 182, 245, 222, 107, 62, 71]); + const data = identifier; + const ix = new TransactionInstruction({ keys, programId, data }); + return ix; +} diff --git a/javascript/solana.js/src/utils.ts b/javascript/solana.js/src/utils.ts index 2969d6e18..320e7a698 100644 --- a/javascript/solana.js/src/utils.ts +++ b/javascript/solana.js/src/utils.ts @@ -278,3 +278,31 @@ export function numToBN(num?: number | BN, defaultVal = 0): BN { return num; } + +export function calculatePriorityFee( + timestamp: number, + roundOpenTimestamp: number, + basePriorityFee: number, + priorityFeeBump: number, + priorityFeeBumpPeriod: number, + maxPriorityFeeMultiplier: number +): number { + if (priorityFeeBumpPeriod <= 0) { + return basePriorityFee; + } + + if (maxPriorityFeeMultiplier <= 0) { + return basePriorityFee; + } + + const staleness = Math.round(timestamp - roundOpenTimestamp); + if (staleness <= 0) { + return basePriorityFee; + } + + const feeMultiplier = Math.floor(staleness / priorityFeeBumpPeriod) - 1; + const multiplier = + feeMultiplier > 0 ? Math.min(feeMultiplier, maxPriorityFeeMultiplier) : 0; + + return Math.floor(priorityFeeBump * multiplier + basePriorityFee); +} diff --git a/javascript/solana.js/test/priority-fees.spec.ts b/javascript/solana.js/test/priority-fees.spec.ts index e4a7e74b4..1ebca9860 100644 --- a/javascript/solana.js/test/priority-fees.spec.ts +++ b/javascript/solana.js/test/priority-fees.spec.ts @@ -1,85 +1,48 @@ /* eslint-disable no-unused-vars */ import "mocha"; -import { AggregatorAccount, types } from "../src/index.js"; +import { calculatePriorityFee } from "../src/index.js"; -import { BN } from "@switchboard-xyz/common"; import assert from "assert"; describe("Priority Fees Tests", () => { - const defaultState = AggregatorAccount.default(); + it("Calculates priority fee with empty values", async () => { + const fee = calculatePriorityFee(10000000, 0, 0, 0, 0, 0); + assert(fee === 0, "PriorityFeeMismatch"); + }); - const startingTimestamp = 100; - const basePriorityFee = 1000; // always bump fee by 1000 lamports - const priorityFeeBump = 500; // bump fee by 500 lamports for every period the feed is stale - const priorityFeeBumpPeriod = 30; // bump fee by priorityFeeBump every 30s - const maxPriorityFeeMultiplier = 10; // the max fee multiplier is 10 * 500 lamports + it("Calculates priority fee with empty max multiplier", async () => { + const fee = calculatePriorityFee(10_500, 10_000, 100, 10, 60, 0); + assert(fee === 100, "PriorityFeeMismatch"); + }); - const aggregatorFields: types.AggregatorAccountDataFields = { - ...defaultState, - basePriorityFee: basePriorityFee, - priorityFeeBump: priorityFeeBump, - priorityFeeBumpPeriod: priorityFeeBumpPeriod, - maxPriorityFeeMultiplier: maxPriorityFeeMultiplier, - latestConfirmedRound: { - ...defaultState.latestConfirmedRound, - roundOpenTimestamp: new BN(startingTimestamp), - }, - }; - const aggregator = new types.AggregatorAccountData(aggregatorFields); + it("Calculates priority fee with empty bump period", async () => { + const fee = calculatePriorityFee(10_500, 10_000, 100, 10, 0, 10); + assert(fee === 100, "PriorityFeeMismatch"); + }); - it("Calculates the priority fee with no staleness", async () => { - // no staleness - const noStalenessFee = AggregatorAccount.calculatePriorityFee( - aggregator, - startingTimestamp - ); - const expectedNoStalenessFee = Math.round(basePriorityFee); - assert( - expectedNoStalenessFee === noStalenessFee, - `priorityFee mismatch with no staleness, expected ${expectedNoStalenessFee}, received ${noStalenessFee}` - ); + it("Calculates priority fee when not stale", async () => { + const fee = calculatePriorityFee(10_500, 10_500, 100, 10, 60, 10); + assert(fee === 100, "PriorityFeeMismatch"); }); - it("Calculates the priority fee with staleness multiplier", async () => { - // with staleness - const multipliers = [0.5, 1, 1.33333, 1.8323232, 2, 5, 10]; - for (const multiplier of multipliers) { - const priorityFee = AggregatorAccount.calculatePriorityFee( - aggregator, - startingTimestamp + multiplier * priorityFeeBumpPeriod - ); - const expectedPriorityFee = Math.round( - basePriorityFee + multiplier * priorityFeeBump - ); - assert( - expectedPriorityFee === priorityFee, - `priorityFee mismatch for multiplier ${multiplier}, expected ${expectedPriorityFee}, received ${priorityFee}` - ); - } + it("Calculates priority fee when barely stale", async () => { + const fee = calculatePriorityFee(10_510, 10_500, 100, 10, 60, 10); + assert(fee === 100, "PriorityFeeMismatch"); }); - it("Calculates the priority fee with max multiplier", async () => { - // with max multiplier - const expectedPriorityFee = Math.round( - basePriorityFee + maxPriorityFeeMultiplier * priorityFeeBump - ); // should never exceed this + it("Calculates priority fee when stale for 1 period", async () => { + const fee = calculatePriorityFee(10_621, 10_500, 100, 10, 60, 10); + assert(fee === 110, "PriorityFeeMismatch"); + }); - const multipliers = [ - maxPriorityFeeMultiplier + 1, - maxPriorityFeeMultiplier * 2, - maxPriorityFeeMultiplier * 10, - ]; + it("Calculates priority fee when stale for 5 periods", async () => { + const fee = calculatePriorityFee(10_861, 10_500, 100, 10, 60, 10); + assert(fee === 150, "PriorityFeeMismatch"); + }); - for (const multiplier of multipliers) { - const priorityFee = AggregatorAccount.calculatePriorityFee( - aggregator, - startingTimestamp + multiplier * priorityFeeBumpPeriod - ); - assert( - expectedPriorityFee === priorityFee, - `priorityFee mismatch for max multiplier, expected ${expectedPriorityFee}, received ${priorityFee}` - ); - } + it("Calculates priority fee when max multiplier exceeded", async () => { + const fee = calculatePriorityFee(10_861, 0, 100, 10, 60, 10); + assert(fee === 200, "PriorityFeeMismatch"); }); }); diff --git a/javascript/solana.js/test/version.spec.ts b/javascript/solana.js/test/version.spec.ts new file mode 100644 index 000000000..b7551eaab --- /dev/null +++ b/javascript/solana.js/test/version.spec.ts @@ -0,0 +1,25 @@ +/* eslint-disable no-unused-vars */ +import "mocha"; + +import type { TestContext } from "./utils.js"; +import { setupTest } from "./utils.js"; + +import assert from "assert"; + +describe("Git Version Tests", () => { + let ctx: TestContext; + + before(async () => { + ctx = await setupTest(); + }); + + it("Gets the oracle program's git version", async () => { + const version = await ctx.program.getGitVersion(); + console.log(`Oracle Version: ${version}`); + }); + + it("Gets the attestation program's git version", async () => { + const version = await ctx.program.getAttestationGitVersion(); + console.log(`Attestation Version: ${version}`); + }); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bc95ab7c7..109784fdb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -63,13 +63,13 @@ importers: specifier: ^1.78.3 version: 1.78.3 '@switchboard-xyz/common': - specifier: ^2.3.2 - version: 2.3.2(@solana/web3.js@1.78.3) + specifier: ^2.3.4 + version: 2.3.4 '@switchboard-xyz/oracle': specifier: latest version: 2.1.13 '@switchboard-xyz/solana.js': - specifier: ^2.5.4 + specifier: ^2.5.6 version: link:../../../javascript/solana.js chalk: specifier: ^4.1.2 @@ -112,13 +112,13 @@ importers: specifier: ^1.77.3 version: 1.77.3 '@switchboard-xyz/common': - specifier: ^2.3.2 - version: 2.3.2(@solana/web3.js@1.77.3) + specifier: ^2.3.4 + version: 2.3.4 '@switchboard-xyz/oracle': specifier: latest version: 2.1.13 '@switchboard-xyz/solana.js': - specifier: ^2.5.4 + specifier: ^2.5.6 version: link:../../../javascript/solana.js devDependencies: '@types/chai': @@ -143,13 +143,13 @@ importers: specifier: ^0.28.0 version: 0.28.0 '@solana/spl-token': - specifier: ^0.3.8 - version: 0.3.8(@solana/web3.js@1.78.4) + specifier: ^0.3.6 + version: 0.3.8(@solana/web3.js@1.78.3) '@solana/web3.js': - specifier: ^1.78.4 - version: 1.78.4 + specifier: ^1.78.0 + version: 1.78.3 '@switchboard-xyz/solana.js': - specifier: ^2.5.4 + specifier: ^2.5.6 version: link:../../../javascript/solana.js devDependencies: '@types/bn.js': @@ -192,10 +192,10 @@ importers: specifier: ^1.78.3 version: 1.78.3 '@switchboard-xyz/common': - specifier: ^2.3.2 - version: 2.3.2(@solana/web3.js@1.78.3) + specifier: ^2.3.4 + version: 2.3.4 '@switchboard-xyz/solana.js': - specifier: ^2.5.4 + specifier: ^2.5.6 version: link:../../../javascript/solana.js devDependencies: '@types/bn.js': @@ -238,10 +238,10 @@ importers: specifier: ^1.78.3 version: 1.78.3 '@switchboard-xyz/common': - specifier: ^2.3.2 - version: 2.3.2(@solana/web3.js@1.78.3) + specifier: ^2.3.4 + version: 2.3.4 '@switchboard-xyz/solana.js': - specifier: ^2.5.4 + specifier: ^2.5.6 version: link:../../../javascript/solana.js devDependencies: '@types/bn.js': @@ -284,10 +284,10 @@ importers: specifier: ^1.78.3 version: 1.78.3 '@switchboard-xyz/common': - specifier: ^2.3.2 - version: 2.3.2(@solana/web3.js@1.78.3) + specifier: ^2.3.4 + version: 2.3.4 '@switchboard-xyz/solana.js': - specifier: ^2.5.4 + specifier: ^2.5.6 version: link:../../../javascript/solana.js dotenv: specifier: ^16.3.1 @@ -326,10 +326,10 @@ importers: specifier: ^0.28.0 version: 0.28.0 '@switchboard-xyz/common': - specifier: ^2.3.2 - version: 2.3.2(@solana/web3.js@1.78.4) + specifier: ^2.3.4 + version: 2.3.4 '@switchboard-xyz/solana.js': - specifier: ^2.5.4 + specifier: ^2.5.6 version: link:../../../javascript/solana.js devDependencies: '@types/bn.js': @@ -378,13 +378,13 @@ importers: specifier: ^1.77.3 version: 1.77.3 '@switchboard-xyz/common': - specifier: ^2.3.2 - version: 2.3.2(@solana/web3.js@1.77.3) + specifier: ^2.3.4 + version: 2.3.4 '@switchboard-xyz/oracle': specifier: latest version: 2.1.13 '@switchboard-xyz/solana.js': - specifier: ^2.5.4 + specifier: ^2.5.6 version: link:../../../javascript/solana.js chalk: specifier: ^4.1.2 @@ -476,8 +476,8 @@ importers: specifier: ^1.78.3 version: 1.78.3 '@switchboard-xyz/common': - specifier: ^2.3.2 - version: 2.3.2(@solana/web3.js@1.78.3) + specifier: ^2.3.3 + version: 2.3.3(@solana/web3.js@1.78.3) cron-validator: specifier: ^1.3.1 version: 1.3.1 @@ -1023,6 +1023,7 @@ packages: '@solana/web3.js': 1.78.4 bn.js: 5.2.1 buffer-layout: 1.2.2 + dev: true /@cspotcode/source-map-support@0.8.1: resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==} @@ -1543,22 +1544,6 @@ packages: - utf-8-validate dev: false - /@solana/spl-token@0.3.8(@solana/web3.js@1.78.4): - resolution: {integrity: sha512-ogwGDcunP9Lkj+9CODOWMiVJEdRtqHAtX2rWF62KxnnSWtMZtV9rDhTrZFshiyJmxDnRL/1nKE1yJHg4jjs3gg==} - engines: {node: '>=16'} - peerDependencies: - '@solana/web3.js': ^1.47.4 - dependencies: - '@solana/buffer-layout': 4.0.0 - '@solana/buffer-layout-utils': 0.2.0 - '@solana/web3.js': 1.78.4 - buffer: 6.0.3 - transitivePeerDependencies: - - bufferutil - - encoding - - utf-8-validate - dev: false - /@solana/web3.js@1.77.3: resolution: {integrity: sha512-PHaO0BdoiQRPpieC1p31wJsBaxwIOWLh8j2ocXNKX8boCQVldt26Jqm2tZE4KlrvnCIV78owPLv1pEUgqhxZ3w==} dependencies: @@ -1630,26 +1615,8 @@ packages: - encoding - utf-8-validate - /@switchboard-xyz/common@2.3.2(@solana/web3.js@1.77.3): - resolution: {integrity: sha512-Vv/Som+QmOOpbvCTWO/FwJ9Bz6yYqBbLqo9T5UuO2JHqL/pBcvTrJGK2ERizTv3UEuHF7Z6zl0k/rdN+11hnyw==} - engines: {node: '>=12'} - dependencies: - '@coral-xyz/borsh': 0.28.0(@solana/web3.js@1.77.3) - '@types/big.js': 6.1.6 - '@types/bn.js': 5.1.1 - big.js: 6.2.1 - bn.js: 5.2.1 - bs58: 5.0.0 - decimal.js: 10.4.3 - lodash: 4.17.21 - protobufjs: 7.2.4 - yaml: 2.2.1 - transitivePeerDependencies: - - '@solana/web3.js' - dev: false - - /@switchboard-xyz/common@2.3.2(@solana/web3.js@1.78.3): - resolution: {integrity: sha512-Vv/Som+QmOOpbvCTWO/FwJ9Bz6yYqBbLqo9T5UuO2JHqL/pBcvTrJGK2ERizTv3UEuHF7Z6zl0k/rdN+11hnyw==} + /@switchboard-xyz/common@2.3.3(@solana/web3.js@1.78.3): + resolution: {integrity: sha512-aZK6Wbu1khMn0qRr0viOwCVcDluS3BzvdoQflmmmCMuEpltDgd7vF/Ax4k+z/9EM54jdqwJRPnAKBDni1RpLyA==} engines: {node: '>=12'} dependencies: '@coral-xyz/borsh': 0.28.0(@solana/web3.js@1.78.3) @@ -1666,13 +1633,10 @@ packages: - '@solana/web3.js' dev: false - /@switchboard-xyz/common@2.3.2(@solana/web3.js@1.78.4): - resolution: {integrity: sha512-Vv/Som+QmOOpbvCTWO/FwJ9Bz6yYqBbLqo9T5UuO2JHqL/pBcvTrJGK2ERizTv3UEuHF7Z6zl0k/rdN+11hnyw==} + /@switchboard-xyz/common@2.3.4: + resolution: {integrity: sha512-9ewK3aQxV8P/OgNjCw2fq5SRm+JLK1sf/+vlTozDK4bb9PwaISHZ08QP7IZ7eCZ+Af69X3eFvxeYh3HDfSzlwg==} engines: {node: '>=12'} dependencies: - '@coral-xyz/borsh': 0.28.0(@solana/web3.js@1.78.4) - '@types/big.js': 6.1.6 - '@types/bn.js': 5.1.1 big.js: 6.2.1 bn.js: 5.2.1 bs58: 5.0.0 @@ -1680,19 +1644,17 @@ packages: lodash: 4.17.21 protobufjs: 7.2.4 yaml: 2.2.1 - transitivePeerDependencies: - - '@solana/web3.js' dev: false /@switchboard-xyz/eslint-config@0.1.9: resolution: {integrity: sha512-ZvCAsXn4NsBCECWvew/GIrkvDGzPhhDzT77jkEKQ7Xd2ftrjFJOeYoREDQIOhD88uN3qBl0cIKHbS4t0amkzGw==} dependencies: - '@typescript-eslint/eslint-plugin': 6.4.0(@typescript-eslint/parser@6.4.0)(eslint@8.47.0)(typescript@5.1.6) - '@typescript-eslint/parser': 6.4.0(eslint@8.47.0)(typescript@5.0.4) - '@typescript-eslint/type-utils': 6.4.0(eslint@8.47.0)(typescript@5.1.6) + '@typescript-eslint/eslint-plugin': 6.4.1(@typescript-eslint/parser@6.4.1)(eslint@8.47.0)(typescript@5.1.6) + '@typescript-eslint/parser': 6.4.1(eslint@8.47.0)(typescript@5.0.4) + '@typescript-eslint/type-utils': 6.4.1(eslint@8.47.0)(typescript@5.1.6) eslint: 8.47.0 eslint-config-prettier: 9.0.0(eslint@8.47.0) - eslint-plugin-import: 2.28.1(@typescript-eslint/parser@6.4.0)(eslint@8.47.0) + eslint-plugin-import: 2.28.1(@typescript-eslint/parser@6.4.1)(eslint@8.47.0) eslint-plugin-node: 11.1.0(eslint@8.47.0) eslint-plugin-prettier: 5.0.0(eslint-config-prettier@9.0.0)(eslint@8.47.0)(prettier@2.8.8) eslint-plugin-simple-import-sort: 10.0.0(eslint@8.47.0) @@ -1899,8 +1861,8 @@ packages: '@types/node': 20.4.2 optional: true - /@typescript-eslint/eslint-plugin@6.4.0(@typescript-eslint/parser@6.4.0)(eslint@8.47.0)(typescript@5.1.6): - resolution: {integrity: sha512-62o2Hmc7Gs3p8SLfbXcipjWAa6qk2wZGChXG2JbBtYpwSRmti/9KHLqfbLs9uDigOexG+3PaQ9G2g3201FWLKg==} + /@typescript-eslint/eslint-plugin@6.4.1(@typescript-eslint/parser@6.4.1)(eslint@8.47.0)(typescript@5.1.6): + resolution: {integrity: sha512-3F5PtBzUW0dYlq77Lcqo13fv+58KDwUib3BddilE8ajPJT+faGgxmI9Sw+I8ZS22BYwoir9ZhNXcLi+S+I2bkw==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: '@typescript-eslint/parser': ^6.0.0 || ^6.0.0-alpha @@ -1911,11 +1873,11 @@ packages: optional: true dependencies: '@eslint-community/regexpp': 4.6.2 - '@typescript-eslint/parser': 6.4.0(eslint@8.47.0)(typescript@5.0.4) - '@typescript-eslint/scope-manager': 6.4.0 - '@typescript-eslint/type-utils': 6.4.0(eslint@8.47.0)(typescript@5.1.6) - '@typescript-eslint/utils': 6.4.0(eslint@8.47.0)(typescript@5.1.6) - '@typescript-eslint/visitor-keys': 6.4.0 + '@typescript-eslint/parser': 6.4.1(eslint@8.47.0)(typescript@5.0.4) + '@typescript-eslint/scope-manager': 6.4.1 + '@typescript-eslint/type-utils': 6.4.1(eslint@8.47.0)(typescript@5.1.6) + '@typescript-eslint/utils': 6.4.1(eslint@8.47.0)(typescript@5.1.6) + '@typescript-eslint/visitor-keys': 6.4.1 debug: 4.3.4(supports-color@8.1.1) eslint: 8.47.0 graphemer: 1.4.0 @@ -1928,8 +1890,8 @@ packages: - supports-color dev: true - /@typescript-eslint/parser@6.4.0(eslint@8.47.0)(typescript@5.0.4): - resolution: {integrity: sha512-I1Ah1irl033uxjxO9Xql7+biL3YD7w9IU8zF+xlzD/YxY6a4b7DYA08PXUUCbm2sEljwJF6ERFy2kTGAGcNilg==} + /@typescript-eslint/parser@6.4.1(eslint@8.47.0)(typescript@5.0.4): + resolution: {integrity: sha512-610G6KHymg9V7EqOaNBMtD1GgpAmGROsmfHJPXNLCU9bfIuLrkdOygltK784F6Crboyd5tBFayPB7Sf0McrQwg==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: eslint: ^7.0.0 || ^8.0.0 @@ -1938,10 +1900,10 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/scope-manager': 6.4.0 - '@typescript-eslint/types': 6.4.0 - '@typescript-eslint/typescript-estree': 6.4.0(typescript@5.0.4) - '@typescript-eslint/visitor-keys': 6.4.0 + '@typescript-eslint/scope-manager': 6.4.1 + '@typescript-eslint/types': 6.4.1 + '@typescript-eslint/typescript-estree': 6.4.1(typescript@5.0.4) + '@typescript-eslint/visitor-keys': 6.4.1 debug: 4.3.4(supports-color@8.1.1) eslint: 8.47.0 typescript: 5.0.4 @@ -1949,16 +1911,16 @@ packages: - supports-color dev: true - /@typescript-eslint/scope-manager@6.4.0: - resolution: {integrity: sha512-TUS7vaKkPWDVvl7GDNHFQMsMruD+zhkd3SdVW0d7b+7Zo+bd/hXJQ8nsiUZMi1jloWo6c9qt3B7Sqo+flC1nig==} + /@typescript-eslint/scope-manager@6.4.1: + resolution: {integrity: sha512-p/OavqOQfm4/Hdrr7kvacOSFjwQ2rrDVJRPxt/o0TOWdFnjJptnjnZ+sYDR7fi4OimvIuKp+2LCkc+rt9fIW+A==} engines: {node: ^16.0.0 || >=18.0.0} dependencies: - '@typescript-eslint/types': 6.4.0 - '@typescript-eslint/visitor-keys': 6.4.0 + '@typescript-eslint/types': 6.4.1 + '@typescript-eslint/visitor-keys': 6.4.1 dev: true - /@typescript-eslint/type-utils@6.4.0(eslint@8.47.0)(typescript@5.1.6): - resolution: {integrity: sha512-TvqrUFFyGY0cX3WgDHcdl2/mMCWCDv/0thTtx/ODMY1QhEiyFtv/OlLaNIiYLwRpAxAtOLOY9SUf1H3Q3dlwAg==} + /@typescript-eslint/type-utils@6.4.1(eslint@8.47.0)(typescript@5.1.6): + resolution: {integrity: sha512-7ON8M8NXh73SGZ5XvIqWHjgX2f+vvaOarNliGhjrJnv1vdjG0LVIz+ToYfPirOoBi56jxAKLfsLm40+RvxVVXA==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: eslint: ^7.0.0 || ^8.0.0 @@ -1967,8 +1929,8 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/typescript-estree': 6.4.0(typescript@5.1.6) - '@typescript-eslint/utils': 6.4.0(eslint@8.47.0)(typescript@5.1.6) + '@typescript-eslint/typescript-estree': 6.4.1(typescript@5.1.6) + '@typescript-eslint/utils': 6.4.1(eslint@8.47.0)(typescript@5.1.6) debug: 4.3.4(supports-color@8.1.1) eslint: 8.47.0 ts-api-utils: 1.0.1(typescript@5.1.6) @@ -1977,13 +1939,13 @@ packages: - supports-color dev: true - /@typescript-eslint/types@6.4.0: - resolution: {integrity: sha512-+FV9kVFrS7w78YtzkIsNSoYsnOtrYVnKWSTVXoL1761CsCRv5wpDOINgsXpxD67YCLZtVQekDDyaxfjVWUJmmg==} + /@typescript-eslint/types@6.4.1: + resolution: {integrity: sha512-zAAopbNuYu++ijY1GV2ylCsQsi3B8QvfPHVqhGdDcbx/NK5lkqMnCGU53amAjccSpk+LfeONxwzUhDzArSfZJg==} engines: {node: ^16.0.0 || >=18.0.0} dev: true - /@typescript-eslint/typescript-estree@6.4.0(typescript@5.0.4): - resolution: {integrity: sha512-iDPJArf/K2sxvjOR6skeUCNgHR/tCQXBsa+ee1/clRKr3olZjZ/dSkXPZjG6YkPtnW6p5D1egeEPMCW6Gn4yLA==} + /@typescript-eslint/typescript-estree@6.4.1(typescript@5.0.4): + resolution: {integrity: sha512-xF6Y7SatVE/OyV93h1xGgfOkHr2iXuo8ip0gbfzaKeGGuKiAnzS+HtVhSPx8Www243bwlW8IF7X0/B62SzFftg==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: typescript: '*' @@ -1991,8 +1953,8 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/types': 6.4.0 - '@typescript-eslint/visitor-keys': 6.4.0 + '@typescript-eslint/types': 6.4.1 + '@typescript-eslint/visitor-keys': 6.4.1 debug: 4.3.4(supports-color@8.1.1) globby: 11.1.0 is-glob: 4.0.3 @@ -2003,8 +1965,8 @@ packages: - supports-color dev: true - /@typescript-eslint/typescript-estree@6.4.0(typescript@5.1.6): - resolution: {integrity: sha512-iDPJArf/K2sxvjOR6skeUCNgHR/tCQXBsa+ee1/clRKr3olZjZ/dSkXPZjG6YkPtnW6p5D1egeEPMCW6Gn4yLA==} + /@typescript-eslint/typescript-estree@6.4.1(typescript@5.1.6): + resolution: {integrity: sha512-xF6Y7SatVE/OyV93h1xGgfOkHr2iXuo8ip0gbfzaKeGGuKiAnzS+HtVhSPx8Www243bwlW8IF7X0/B62SzFftg==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: typescript: '*' @@ -2012,8 +1974,8 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/types': 6.4.0 - '@typescript-eslint/visitor-keys': 6.4.0 + '@typescript-eslint/types': 6.4.1 + '@typescript-eslint/visitor-keys': 6.4.1 debug: 4.3.4(supports-color@8.1.1) globby: 11.1.0 is-glob: 4.0.3 @@ -2024,8 +1986,8 @@ packages: - supports-color dev: true - /@typescript-eslint/utils@6.4.0(eslint@8.47.0)(typescript@5.1.6): - resolution: {integrity: sha512-BvvwryBQpECPGo8PwF/y/q+yacg8Hn/2XS+DqL/oRsOPK+RPt29h5Ui5dqOKHDlbXrAeHUTnyG3wZA0KTDxRZw==} + /@typescript-eslint/utils@6.4.1(eslint@8.47.0)(typescript@5.1.6): + resolution: {integrity: sha512-F/6r2RieNeorU0zhqZNv89s9bDZSovv3bZQpUNOmmQK1L80/cV4KEu95YUJWi75u5PhboFoKUJBnZ4FQcoqhDw==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: eslint: ^7.0.0 || ^8.0.0 @@ -2033,9 +1995,9 @@ packages: '@eslint-community/eslint-utils': 4.4.0(eslint@8.47.0) '@types/json-schema': 7.0.12 '@types/semver': 7.5.0 - '@typescript-eslint/scope-manager': 6.4.0 - '@typescript-eslint/types': 6.4.0 - '@typescript-eslint/typescript-estree': 6.4.0(typescript@5.1.6) + '@typescript-eslint/scope-manager': 6.4.1 + '@typescript-eslint/types': 6.4.1 + '@typescript-eslint/typescript-estree': 6.4.1(typescript@5.1.6) eslint: 8.47.0 semver: 7.5.4 transitivePeerDependencies: @@ -2043,11 +2005,11 @@ packages: - typescript dev: true - /@typescript-eslint/visitor-keys@6.4.0: - resolution: {integrity: sha512-yJSfyT+uJm+JRDWYRYdCm2i+pmvXJSMtPR9Cq5/XQs4QIgNoLcoRtDdzsLbLsFM/c6um6ohQkg/MLxWvoIndJA==} + /@typescript-eslint/visitor-keys@6.4.1: + resolution: {integrity: sha512-y/TyRJsbZPkJIZQXrHfdnxVnxyKegnpEvnRGNam7s3TRR2ykGefEWOhaef00/UUN3IZxizS7BTO3svd3lCOJRQ==} engines: {node: ^16.0.0 || >=18.0.0} dependencies: - '@typescript-eslint/types': 6.4.0 + '@typescript-eslint/types': 6.4.1 eslint-visitor-keys: 3.4.3 dev: true @@ -3169,7 +3131,7 @@ packages: - supports-color dev: true - /eslint-module-utils@2.8.0(@typescript-eslint/parser@6.4.0)(eslint-import-resolver-node@0.3.7)(eslint@8.47.0): + /eslint-module-utils@2.8.0(@typescript-eslint/parser@6.4.1)(eslint-import-resolver-node@0.3.7)(eslint@8.47.0): resolution: {integrity: sha512-aWajIYfsqCKRDgUfjEXNN/JlrzauMuSEy5sbd7WXbtW3EH6A6MpwEh42c7qD+MqQo9QMJ6fWLAeIJynx0g6OAw==} engines: {node: '>=4'} peerDependencies: @@ -3190,7 +3152,7 @@ packages: eslint-import-resolver-webpack: optional: true dependencies: - '@typescript-eslint/parser': 6.4.0(eslint@8.47.0)(typescript@5.0.4) + '@typescript-eslint/parser': 6.4.1(eslint@8.47.0)(typescript@5.0.4) debug: 3.2.7 eslint: 8.47.0 eslint-import-resolver-node: 0.3.7 @@ -3209,7 +3171,7 @@ packages: regexpp: 3.2.0 dev: true - /eslint-plugin-import@2.28.1(@typescript-eslint/parser@6.4.0)(eslint@8.47.0): + /eslint-plugin-import@2.28.1(@typescript-eslint/parser@6.4.1)(eslint@8.47.0): resolution: {integrity: sha512-9I9hFlITvOV55alzoKBI+K9q74kv0iKMeY6av5+umsNwayt59fz692daGyjR+oStBQgx6nwR9rXldDev3Clw+A==} engines: {node: '>=4'} peerDependencies: @@ -3219,7 +3181,7 @@ packages: '@typescript-eslint/parser': optional: true dependencies: - '@typescript-eslint/parser': 6.4.0(eslint@8.47.0)(typescript@5.0.4) + '@typescript-eslint/parser': 6.4.1(eslint@8.47.0)(typescript@5.0.4) array-includes: 3.1.6 array.prototype.findlastindex: 1.2.2 array.prototype.flat: 1.3.1 @@ -3228,7 +3190,7 @@ packages: doctrine: 2.1.0 eslint: 8.47.0 eslint-import-resolver-node: 0.3.7 - eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.4.0)(eslint-import-resolver-node@0.3.7)(eslint@8.47.0) + eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.4.1)(eslint-import-resolver-node@0.3.7)(eslint@8.47.0) has: 1.0.3 is-core-module: 2.13.0 is-glob: 4.0.3 @@ -4837,7 +4799,7 @@ packages: engines: {node: '>=10'} dependencies: hosted-git-info: 4.1.0 - is-core-module: 2.12.1 + is-core-module: 2.13.0 semver: 7.5.4 validate-npm-package-license: 3.0.4 dev: true diff --git a/rust/switchboard-solana/Cargo.lock b/rust/switchboard-solana/Cargo.lock index ab6cc4252..742fb0faf 100644 --- a/rust/switchboard-solana/Cargo.lock +++ b/rust/switchboard-solana/Cargo.lock @@ -4249,7 +4249,7 @@ dependencies = [ [[package]] name = "switchboard-solana" -version = "0.28.5" +version = "0.28.6" dependencies = [ "anchor-client", "anchor-lang", diff --git a/rust/switchboard-solana/Cargo.toml b/rust/switchboard-solana/Cargo.toml index 3350846d4..5f243107a 100644 --- a/rust/switchboard-solana/Cargo.toml +++ b/rust/switchboard-solana/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "switchboard-solana" -version = "0.28.5" +version = "0.28.6" edition = "2021" description = "A Rust library to interact with Switchboard accounts." readme = "README.md" @@ -47,4 +47,4 @@ tokio = "1" url = "2.4" [package.metadata.docs.rs] -rustdoc-args = ["--cfg", "doc_cfg"] \ No newline at end of file +rustdoc-args = ["--cfg", "doc_cfg"] diff --git a/rust/switchboard-solana/src/client/function_runner.rs b/rust/switchboard-solana/src/client/function_runner.rs index 18ba7de1a..1e7504104 100644 --- a/rust/switchboard-solana/src/client/function_runner.rs +++ b/rust/switchboard-solana/src/client/function_runner.rs @@ -57,7 +57,7 @@ impl FunctionRunner { let signer = signer_to_pubkey(signer_keypair.clone())?; let env = SolanaFunctionEnvironment::parse()?; - msg!("ENV: {:?}", env); + msg!("ENV: {:#?}", env); // required to run let function = Pubkey::from_str(&env.function_key).unwrap(); @@ -175,8 +175,7 @@ impl FunctionRunner { } pub fn from_env(commitment: Option) -> Result { - let cluster = Cluster::from_str(&std::env::var("CLUSTER").unwrap_or("devnet".to_string())) - .unwrap_or(Cluster::Devnet); + let cluster = Cluster::from_str(&std::env::var("CLUSTER").unwrap()).unwrap(); Self::new_from_cluster(cluster, commitment) } @@ -550,4 +549,4 @@ impl ToAccountMetas for FunctionRequestVerifyAccounts { AccountMeta::new_readonly(anchor_spl::token::ID, false), ] } -} \ No newline at end of file +}