Skip to content

Commit

Permalink
chore: pull monorepo changes (#119)
Browse files Browse the repository at this point in the history
* Project import generated by Copybara.

GitOrigin-RevId: 8e1fcb690780885a2aa28fb132c00ed984c24f14

* chore: manual cleanup

---------

Co-authored-by: Copybara <copybara@example.com>
  • Loading branch information
gallynaut and Copybara authored Aug 23, 2023
1 parent 5e4cde7 commit 9dc3df8
Show file tree
Hide file tree
Showing 29 changed files with 368 additions and 253 deletions.
4 changes: 2 additions & 2 deletions examples/feeds/01_feed_client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions examples/feeds/02_spl_native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions examples/functions/01_basic_oracle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
bytemuck = "^1"
6 changes: 3 additions & 3 deletions examples/functions/01_basic_oracle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions examples/functions/01_basic_oracle/sgx-function/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
# switchboard-utils = { version = "0.8.0", path = "../../../../../../rust/switchboard-utils" }
17 changes: 9 additions & 8 deletions examples/functions/01_basic_oracle/sgx-function/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
# @echo latest MrEnclave: $(shell rm ./latest-measurement.txt)
4 changes: 2 additions & 2 deletions examples/functions/02_liquidity_oracle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions examples/functions/03_candles_oracle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions examples/functions/04_randomness_callback/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions examples/functions/05_raffle_program/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions examples/vrf/01_vrf_client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions javascript/solana.js/idl/attestation-devnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
"version": "0.1.0",
"name": "switchboard_attestation_program",
"instructions": [
{
"name": "viewVersion",
"accounts": [],
"args": []
},
{
"name": "stateInit",
"accounts": [
Expand Down
5 changes: 5 additions & 0 deletions javascript/solana.js/idl/devnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
"version": "0.1.0",
"name": "switchboard_v2",
"instructions": [
{
"name": "viewVersion",
"accounts": [],
"args": []
},
{
"name": "aggregatorClose",
"accounts": [
Expand Down
4 changes: 2 additions & 2 deletions javascript/solana.js/package.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions javascript/solana.js/scripts/generate-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
];

Expand Down
62 changes: 61 additions & 1 deletion javascript/solana.js/src/SwitchboardProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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) & {
Expand Down Expand Up @@ -429,6 +436,53 @@ export class SwitchboardProgram {
return program;
};

public async getGitVersion(): Promise<string> {
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<string> {
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.
Expand Down Expand Up @@ -1040,3 +1094,9 @@ interface AccountInfoResponse {
pubkey: PublicKey;
account: AccountInfo<Buffer>;
}

function extractVersion(input: string): string | null {
const regex = /VERSION: (\S+)/;
const match = input.match(regex);
return match ? match[1] : null;
}
16 changes: 13 additions & 3 deletions javascript/solana.js/src/TransactionObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export interface ITransactionObject extends Required<TransactionObjectOptions> {

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;
}

Expand Down Expand Up @@ -127,7 +129,8 @@ export class TransactionObject implements ITransactionObject {
}

const priorityTxn = TransactionObject.getComputeUnitPriceIxn(
options?.computeUnitPrice
options?.computeUnitPrice,
options?.computeUnitLimit
);
if (
priorityTxn !== undefined &&
Expand Down Expand Up @@ -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
),
});
}

Expand Down
Loading

0 comments on commit 9dc3df8

Please sign in to comment.