From 0d411461a15aa8efe6e0eba3865a152484c61de7 Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Tue, 10 Dec 2024 09:06:00 -0800 Subject: [PATCH] all tests pass --- Anchor.toml | 6 +++- deps/configs/pyth_lazer_storage.json | 13 ++++++++ package.json | 1 + sdk/package.json | 4 +-- sdk/src/driftClient.ts | 6 ++-- sdk/yarn.lock | 46 +-------------------------- tests/placeAndMakeSwiftPerpBankrun.ts | 1 - tests/pythLazer.ts | 40 ++++++++++++++--------- yarn.lock | 7 ++++ 9 files changed, 57 insertions(+), 67 deletions(-) create mode 100644 deps/configs/pyth_lazer_storage.json diff --git a/Anchor.toml b/Anchor.toml index 958bfca26..dbaa02376 100644 --- a/Anchor.toml +++ b/Anchor.toml @@ -21,4 +21,8 @@ token_faucet = "V4v1mQiAdLz4qwckEb45WqHYceYizoib39cDBHSWfaB" [[test.validator.account]] address = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" -filename = "./deps/configs/usdc.json" \ No newline at end of file +filename = "./deps/configs/usdc.json" + +[[test.validator.account]] +address = "3rdJbqfnagQ4yx9HXJViD4zc4xpiSqmFsKpPuSCQVyQL" +filename = "./deps/configs/pyth_lazer_storage.json" \ No newline at end of file diff --git a/deps/configs/pyth_lazer_storage.json b/deps/configs/pyth_lazer_storage.json new file mode 100644 index 000000000..3c4a1368f --- /dev/null +++ b/deps/configs/pyth_lazer_storage.json @@ -0,0 +1,13 @@ +{ + "pubkey": "3rdJbqfnagQ4yx9HXJViD4zc4xpiSqmFsKpPuSCQVyQL", + "account": { + "lamports": 1461600, + "data": [ + "0XX/ucSvRAkL/td28gTUmmjn6CkzKyvYXJOMcup4pEKu3cXcP7cvDAH2UhC+5Pz1sc7h5Tf6vP2VAQKXZTuUrwTUVPxHPpSDT+g2BnoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==", + "base64" + ], + "owner": "pytd2yyk641x7ak7mkaasSJVXh6YYZnC7wTmtgAyxPt", + "executable": false, + "rentEpoch": 367 + } +} diff --git a/package.json b/package.json index 994b98339..cf37dab7c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/sdk/package.json b/sdk/package.json index 2afec6fb8..81c7504b3 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -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", @@ -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", diff --git a/sdk/src/driftClient.ts b/sdk/src/driftClient.ts index 7319c8d60..623b25368 100644 --- a/sdk/src/driftClient.ts +++ b/sdk/src/driftClient.ts @@ -8576,7 +8576,9 @@ export class DriftClient { ): Promise { const postIxs = this.getPostPythLazerOracleUpdateIxs( feedId, - pythMessageHex + pythMessageHex, + undefined, + 2 ); const tx = await this.buildTransaction(postIxs); const { txSig } = await this.sendTransaction(tx, [], this.opts); @@ -8597,7 +8599,7 @@ export class DriftClient { updateData.set(pythMessageBytes, 1); const verifyIx = createMinimalEd25519VerifyIx( - overrideIxCount ?? precedingIxs.length + 2, + overrideIxCount || precedingIxs.length + 1, messageOffset, updateData ); diff --git a/sdk/yarn.lock b/sdk/yarn.lock index a70670532..5698ba9ff 100644 --- a/sdk/yarn.lock +++ b/sdk/yarn.lock @@ -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/bn.js@5.1.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== @@ -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" @@ -3017,45 +3012,6 @@ snake-case@^3.0.4: dot-case "^3.0.4" tslib "^2.0.3" -solana-bankrun-darwin-arm64@0.3.1: - 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== - -solana-bankrun-darwin-universal@0.3.1: - 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== - -solana-bankrun-darwin-x64@0.3.1: - 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== - -solana-bankrun-linux-x64-gnu@0.3.1: - 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== - -solana-bankrun-linux-x64-musl@0.3.1: - 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" diff --git a/tests/placeAndMakeSwiftPerpBankrun.ts b/tests/placeAndMakeSwiftPerpBankrun.ts index ee26cc901..fea69af07 100644 --- a/tests/placeAndMakeSwiftPerpBankrun.ts +++ b/tests/placeAndMakeSwiftPerpBankrun.ts @@ -15,7 +15,6 @@ import { Transaction, TransactionInstruction, TransactionMessage, - VersionedMessage, VersionedTransaction, } from '@solana/web3.js'; diff --git a/tests/pythLazer.ts b/tests/pythLazer.ts index f12e940c5..c5b832d0f 100644 --- a/tests/pythLazer.ts +++ b/tests/pythLazer.ts @@ -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 = { - 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, { @@ -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 @@ -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); }); }); diff --git a/yarn.lock b/yarn.lock index ddd493a00..a61e8bc15 100644 --- a/yarn.lock +++ b/yarn.lock @@ -698,6 +698,13 @@ node-cache "^5.1.2" protobufjs "^7.2.6" +"@types/bn.js@5.1.6": + 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"