Skip to content

Commit

Permalink
new fee controls
Browse files Browse the repository at this point in the history
  • Loading branch information
0xodia committed Jan 7, 2025
1 parent 723d82a commit 9ec8c7b
Show file tree
Hide file tree
Showing 3 changed files with 325 additions and 173 deletions.
94 changes: 48 additions & 46 deletions solend-sdk/__tests__/oracle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,58 +17,58 @@ import { bs58 } from "@coral-xyz/anchor/dist/cjs/utils/bytes";

jest.setTimeout(50_000);

const connection = new Connection("https://api.mainnet-beta.solana.com");
const testKey = [];
const connection = new Connection('https://solendf-solendf-67c7.rpcpool.com/6096fc4b-78fc-4130-a42a-e6d4b9c37813');
const testKey = [99,83,244,164,214,230,128,126,248,174,145,117,216,181,19,254,1,131,156,63,88,149,91,49,158,109,27,0,133,146,203,224,169,50,229,208,53,199,40,226,125,95,165,25,40,81,148,114,53,21,246,241,28,114,166,120,171,70,98,82,7,91,1,37];

describe("pulls sb oracles", function () {
it("pulls switchboard oracle", async function () {
if (testKey.length === 0) {
throw Error('Best tested with a throwaway mainnet test account.')
}
// it("pulls switchboard oracle", async function () {
// if (testKey.length === 0) {
// throw Error('Best tested with a throwaway mainnet test account.')
// }

const provider = new AnchorProvider(connection, new NodeWallet(Keypair.fromSecretKey(new Uint8Array(
testKey
))), {});
const idl = (await Program.fetchIdl(ON_DEMAND_MAINNET_PID, provider))!;
const sbod = new Program(idl, provider);
// const provider = new AnchorProvider(connection, new NodeWallet(Keypair.fromSecretKey(new Uint8Array(
// testKey
// ))), {});
// const idl = (await Program.fetchIdl(ON_DEMAND_MAINNET_PID, provider))!;
// const sbod = new Program(idl, provider);

const sbPulledOracles = [
'2F9M59yYc28WMrAymNWceaBEk8ZmDAjUAKULp8seAJF3',
'AZcoqpWhMJUaKEDUfKsfzCr3Y96gSQwv43KSQ6KpeyQ1',
'Ai2GsLRioGKwVgWX8dtbLF5rJJEZX17SteGEDqrpzBv3',
'4sPZ75ipUH9W2CC7gfpipLpPLN5m7RD2FES9SfegfZbP',
'AJkAFiXdbMonys8rTXZBrRnuUiLcDFdkyoPuvrVKXhex',
// '65J9bVEMhNbtbsNgArNV1K4krzcsomjho4bgR51sZXoj'
];
// const sbPulledOracles = [
// '2F9M59yYc28WMrAymNWceaBEk8ZmDAjUAKULp8seAJF3',
// // 'AZcoqpWhMJUaKEDUfKsfzCr3Y96gSQwv43KSQ6KpeyQ1',
// // 'Ai2GsLRioGKwVgWX8dtbLF5rJJEZX17SteGEDqrpzBv3',
// // '4sPZ75ipUH9W2CC7gfpipLpPLN5m7RD2FES9SfegfZbP',
// // 'AJkAFiXdbMonys8rTXZBrRnuUiLcDFdkyoPuvrVKXhex',
// // '65J9bVEMhNbtbsNgArNV1K4krzcsomjho4bgR51sZXoj'
// ];

// Example usage
const feedAccounts = sbPulledOracles.map((oracleKey) => new PullFeed(sbod as any, oracleKey));
const crossbar = new CrossbarClient("https://crossbar-fvumormova-uc.a.run.app");
// // Example usage
// const feedAccounts = sbPulledOracles.map((oracleKey) => new PullFeed(sbod as any, oracleKey));
// const crossbar = new CrossbarClient("https://crossbar-fvumormova-uc.a.run.app");

// Responses is Array<[pullIx, responses, success]>
const responses = await Promise.all(feedAccounts.map((feedAccount) => feedAccount.fetchUpdateIx({ numSignatures: 1, crossbarClient: crossbar,
gateway: 'https://xoracle-1-mn.switchboard.xyz' })));
const oracles = responses.flatMap((x) => x[1].map(y => y.oracle));
const lookupTables = await loadLookupTables([...oracles, ...feedAccounts]);
// // Responses is Array<[pullIx, responses, success]>
// const responses = await Promise.all(feedAccounts.map((feedAccount) => feedAccount.fetchUpdateIx({ numSignatures: 1, crossbarClient: crossbar,
// gateway: 'https://xoracle-1-mn.switchboard.xyz' })));
// const oracles = responses.flatMap((x) => x[1].map(y => y.oracle));
// const lookupTables = await loadLookupTables([...oracles, ...feedAccounts]);

// Get the latest context
const {
value: { blockhash },
} = await connection.getLatestBlockhashAndContext();
// // Get the latest context
// const {
// value: { blockhash },
// } = await connection.getLatestBlockhashAndContext();

// Get Transaction Message
const message = new TransactionMessage({
payerKey: provider.publicKey,
recentBlockhash: blockhash,
instructions: [...responses.map(r => r[0]!)],
}).compileToV0Message(lookupTables);
// // Get Transaction Message
// const message = new TransactionMessage({
// payerKey: provider.publicKey,
// recentBlockhash: blockhash,
// instructions: [...responses.map(r => r[0]!)],
// }).compileToV0Message(lookupTables);

// Get Versioned Transaction
const vtx = new VersionedTransaction(message);
provider.wallet.signAllTransactions([vtx]);
const sig = await connection.sendRawTransaction(vtx.serialize(), {skipPreflight: true});
await connection.confirmTransaction(sig, 'confirmed');
});
// // Get Versioned Transaction
// const vtx = new VersionedTransaction(message);
// provider.wallet.signAllTransactions([vtx]);
// const sig = await connection.sendRawTransaction(vtx.serialize(), {skipPreflight: true});
// await connection.confirmTransaction(sig, 'confirmed');
// });

it("pulls pyth oracles", async function () {
if (testKey.length === 0) {
Expand All @@ -81,14 +81,17 @@ import { bs58 } from "@coral-xyz/anchor/dist/cjs/utils/bytes";
testKey
)))
});

console.log(pythSolanaReceiver.wallet.publicKey.toBase58())
return;
const transactionBuilder = pythSolanaReceiver.newTransactionBuilder({
closeUpdateAccounts: true,
});

let priceFeedUpdateData;
priceFeedUpdateData = await priceServiceConnection.getLatestVaas(
[
'eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a', // USDC
'bed3097008b9b5e3c93bec20be79cb43986b85a996475589351a21e67bae9b61', // USDC
]
);

Expand All @@ -99,8 +102,7 @@ import { bs58 } from "@coral-xyz/anchor/dist/cjs/utils/bytes";

const transactionsWithSigners = await transactionBuilder.buildVersionedTransactions({
tightComputeBudget: true,
jitoTipLamports: 10

jitoTipLamports: 100000
});

const pullPriceTxns = [] as Array<VersionedTransaction>;
Expand Down
2 changes: 1 addition & 1 deletion solend-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@solendprotocol/solend-sdk",
"version": "0.13.35",
"version": "0.13.36",
"private": true,
"main": "src/index.ts",
"module": "src/index.ts",
Expand Down
Loading

0 comments on commit 9ec8c7b

Please sign in to comment.