Skip to content

Commit

Permalink
all tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
NourAlharithi committed Dec 10, 2024
1 parent a776e48 commit 0d41146
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 67 deletions.
6 changes: 5 additions & 1 deletion Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ token_faucet = "V4v1mQiAdLz4qwckEb45WqHYceYizoib39cDBHSWfaB"

[[test.validator.account]]
address = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
filename = "./deps/configs/usdc.json"
filename = "./deps/configs/usdc.json"

[[test.validator.account]]
address = "3rdJbqfnagQ4yx9HXJViD4zc4xpiSqmFsKpPuSCQVyQL"
filename = "./deps/configs/pyth_lazer_storage.json"
13 changes: 13 additions & 0 deletions deps/configs/pyth_lazer_storage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"pubkey": "3rdJbqfnagQ4yx9HXJViD4zc4xpiSqmFsKpPuSCQVyQL",
"account": {
"lamports": 1461600,
"data": [
"0XX/ucSvRAkL/td28gTUmmjn6CkzKyvYXJOMcup4pEKu3cXcP7cvDAH2UhC+5Pz1sc7h5Tf6vP2VAQKXZTuUrwTUVPxHPpSDT+g2BnoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
"base64"
],
"owner": "pytd2yyk641x7ak7mkaasSJVXh6YYZnC7wTmtgAyxPt",
"executable": false,
"rentEpoch": 367
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@pythnetwork/client": "^2.5.1",
"@solana/spl-token": "0.3.7",
"@solana/web3.js": "1.73.2",
"@types/bn.js": "5.1.6",
"@types/chai": "^5.0.0",
"@types/mocha": "^8.2.2",
"@typescript-eslint/eslint-plugin": "^4.28.0",
Expand Down
4 changes: 1 addition & 3 deletions sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@
"@solana/web3.js": "1.92.3",
"@switchboard-xyz/on-demand": "1.2.42",
"@triton-one/yellowstone-grpc": "1.3.0",
"anchor-bankrun": "^0.3.0",
"node-cache": "^5.1.2",
"rpc-websockets": "7.5.1",
"solana-bankrun": "^0.3.0",
"strict-event-emitter-types": "^2.0.0",
"tweetnacl": "1.0.3",
"uuid": "^8.3.2",
Expand All @@ -61,7 +59,7 @@
},
"devDependencies": {
"@types/big.js": "^6.2.0",
"@types/bn.js": "^5.1.3",
"@types/bn.js": "5.1.6",
"@types/bs58": "^4.0.4",
"@types/chai": "^4.3.1",
"@types/jest": "^28.1.3",
Expand Down
6 changes: 4 additions & 2 deletions sdk/src/driftClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8576,7 +8576,9 @@ export class DriftClient {
): Promise<string> {
const postIxs = this.getPostPythLazerOracleUpdateIxs(
feedId,
pythMessageHex
pythMessageHex,
undefined,
2
);
const tx = await this.buildTransaction(postIxs);
const { txSig } = await this.sendTransaction(tx, [], this.opts);
Expand All @@ -8597,7 +8599,7 @@ export class DriftClient {
updateData.set(pythMessageBytes, 1);

const verifyIx = createMinimalEd25519VerifyIx(
overrideIxCount ?? precedingIxs.length + 2,
overrideIxCount || precedingIxs.length + 1,
messageOffset,
updateData
);
Expand Down
46 changes: 1 addition & 45 deletions sdk/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@
resolved "https://registry.yarnpkg.com/@types/big.js/-/big.js-6.2.2.tgz#69422ec9ef59df1330ccfde2106d9e1159a083c3"
integrity sha512-e2cOW9YlVzFY2iScnGBBkplKsrn2CsObHQ2Hiw4V1sSyiGbgWL8IyqE3zFi1Pt5o1pdAtYkDAIsF3KKUPjdzaA==

"@types/bn.js@^5.1.0", "@types/bn.js@^5.1.3":
"@types/[email protected].6", "@types/bn.js@^5.1.0":
version "5.1.6"
resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-5.1.6.tgz#9ba818eec0c85e4d3c679518428afdf611d03203"
integrity sha512-Xh8vSwUeMKeYYrj3cX4lGQgFSF/N03r+tv4AiLl1SucqV+uTQpxRcnM8AkXKHwYP9ZPXOYXRr2KPXpVlIvqh9w==
Expand Down Expand Up @@ -1111,11 +1111,6 @@ ajv@^8.0.1:
json-schema-traverse "^1.0.0"
require-from-string "^2.0.2"

anchor-bankrun@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/anchor-bankrun/-/anchor-bankrun-0.3.0.tgz#3789fcecbc201a2334cff228b99cc0da8ef0167e"
integrity sha512-PYBW5fWX+iGicIS5MIM/omhk1tQPUc0ELAnI/IkLKQJ6d75De/CQRh8MF2bU/TgGyFi6zEel80wUe3uRol9RrQ==

ansi-colors@^4.1.1, ansi-colors@^4.1.3:
version "4.1.3"
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.3.tgz#37611340eb2243e70cc604cad35d63270d48781b"
Expand Down Expand Up @@ -3017,45 +3012,6 @@ snake-case@^3.0.4:
dot-case "^3.0.4"
tslib "^2.0.3"

[email protected]:
version "0.3.1"
resolved "https://registry.yarnpkg.com/solana-bankrun-darwin-arm64/-/solana-bankrun-darwin-arm64-0.3.1.tgz#65ab6cd2e74eef260c38251f4c53721cf5b9030f"
integrity sha512-9LWtH/3/WR9fs8Ve/srdo41mpSqVHmRqDoo69Dv1Cupi+o1zMU6HiEPUHEvH2Tn/6TDbPEDf18MYNfReLUqE6A==

[email protected]:
version "0.3.1"
resolved "https://registry.yarnpkg.com/solana-bankrun-darwin-universal/-/solana-bankrun-darwin-universal-0.3.1.tgz#bf691457cf046e8739c021ca11e48de5b4fefd45"
integrity sha512-muGHpVYWT7xCd8ZxEjs/bmsbMp8XBqroYGbE4lQPMDUuLvsJEIrjGqs3MbxEFr71sa58VpyvgywWd5ifI7sGIg==

[email protected]:
version "0.3.1"
resolved "https://registry.yarnpkg.com/solana-bankrun-darwin-x64/-/solana-bankrun-darwin-x64-0.3.1.tgz#c6f30c0a6bc3e1621ed90ce7562f26e93bf5303f"
integrity sha512-oCaxfHyt7RC3ZMldrh5AbKfy4EH3YRMl8h6fSlMZpxvjQx7nK7PxlRwMeflMnVdkKKp7U8WIDak1lilIPd3/lg==

[email protected]:
version "0.3.1"
resolved "https://registry.yarnpkg.com/solana-bankrun-linux-x64-gnu/-/solana-bankrun-linux-x64-gnu-0.3.1.tgz#78b522f1a581955a48f43a8fb560709c11301cfd"
integrity sha512-PfRFhr7igGFNt2Ecfdzh3li9eFPB3Xhmk0Eib17EFIB62YgNUg3ItRnQQFaf0spazFjjJLnglY1TRKTuYlgSVA==

[email protected]:
version "0.3.1"
resolved "https://registry.yarnpkg.com/solana-bankrun-linux-x64-musl/-/solana-bankrun-linux-x64-musl-0.3.1.tgz#1a044a132138a0084e82406ec7bf4939f06bed68"
integrity sha512-6r8i0NuXg3CGURql8ISMIUqhE7Hx/O7MlIworK4oN08jYrP0CXdLeB/hywNn7Z8d1NXrox/NpYUgvRm2yIzAsQ==

solana-bankrun@^0.3.0:
version "0.3.1"
resolved "https://registry.yarnpkg.com/solana-bankrun/-/solana-bankrun-0.3.1.tgz#13665ab7c1c15ec2b3354aae56980d0ded514998"
integrity sha512-inRwON7fBU5lPC36HdEqPeDg15FXJYcf77+o0iz9amvkUMJepcwnRwEfTNyMVpVYdgjTOBW5vg+596/3fi1kGA==
dependencies:
"@solana/web3.js" "^1.68.0"
bs58 "^4.0.1"
optionalDependencies:
solana-bankrun-darwin-arm64 "0.3.1"
solana-bankrun-darwin-universal "0.3.1"
solana-bankrun-darwin-x64 "0.3.1"
solana-bankrun-linux-x64-gnu "0.3.1"
solana-bankrun-linux-x64-musl "0.3.1"

spok@^1.4.3:
version "1.5.5"
resolved "https://registry.yarnpkg.com/spok/-/spok-1.5.5.tgz#a51f7f290a53131d7b7a922dfedc461dda0aed72"
Expand Down
1 change: 0 additions & 1 deletion tests/placeAndMakeSwiftPerpBankrun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
Transaction,
TransactionInstruction,
TransactionMessage,
VersionedMessage,
VersionedTransaction,
} from '@solana/web3.js';

Expand Down
40 changes: 25 additions & 15 deletions tests/pythLazer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,21 @@ import { Program } from '@coral-xyz/anchor';
import {
BulkAccountLoader,
OracleSource,
PTYH_LAZER_PROGRAM_ID,
TestClient,
assert,
getPythLazerOraclePublicKey,
} from '../sdk/src';
import { AccountInfo, LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js';
import {
PublicKey,
TransactionMessage,
VersionedTransaction,
} from '@solana/web3.js';
import {
initializeQuoteSpotMarket,
mockUSDCMint,
} from './testHelpersLocalValidator';
import { Wallet, loadKeypair } from '../sdk/src';
import { PYTH_LAZER_HEX_STRING_BTC, PYTH_STORAGE_DATA } from './pythLazerData';

// set up account infos to load into banks client
const PYTH_STORAGE_ACCOUNT_INFO: AccountInfo<Buffer> = {
executable: false,
lamports: LAMPORTS_PER_SOL,
owner: new PublicKey(PTYH_LAZER_PROGRAM_ID),
rentEpoch: 0,
data: Buffer.from(PYTH_STORAGE_DATA, 'base64'),
};
import { Wallet, loadKeypair, EventSubscriber } from '../sdk/src';
import { PYTH_LAZER_HEX_STRING_BTC } from './pythLazerData';

describe('pyth lazer oracles', () => {
const provider = anchor.AnchorProvider.local(undefined, {
Expand All @@ -41,6 +36,12 @@ describe('pyth lazer oracles', () => {
const feedId = 3;
let solUsd: PublicKey;

//@ts-ignore
const eventSubscriber = new EventSubscriber(connection, chProgram, {
commitment: 'recent',
});
eventSubscriber.subscribe();

before(async () => {
// use bankrun builtin function to start solana program test

Expand Down Expand Up @@ -88,10 +89,19 @@ describe('pyth lazer oracles', () => {
});

it('crank', async () => {
const tx = await driftClient.postPythLazerOracleUpdate(
const ixs = await driftClient.getPostPythLazerOracleUpdateIxs(
1,
PYTH_LAZER_HEX_STRING_BTC
);
console.log(tx);

const message = new TransactionMessage({
instructions: ixs,
payerKey: driftClient.wallet.payer.publicKey,
recentBlockhash: (await connection.getLatestBlockhash()).blockhash,
}).compileToV0Message();
const tx = new VersionedTransaction(message);
const simResult = await provider.connection.simulateTransaction(tx);
console.log(simResult.value.logs);
assert(simResult.value.err === null);
});
});
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,13 @@
node-cache "^5.1.2"
protobufjs "^7.2.6"

"@types/[email protected]":
version "5.1.6"
resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-5.1.6.tgz#9ba818eec0c85e4d3c679518428afdf611d03203"
integrity sha512-Xh8vSwUeMKeYYrj3cX4lGQgFSF/N03r+tv4AiLl1SucqV+uTQpxRcnM8AkXKHwYP9ZPXOYXRr2KPXpVlIvqh9w==
dependencies:
"@types/node" "*"

"@types/bn.js@^5.1.0":
version "5.1.5"
resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-5.1.5.tgz#2e0dacdcce2c0f16b905d20ff87aedbc6f7b4bf0"
Expand Down

0 comments on commit 0d41146

Please sign in to comment.