This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use crate::protos::oracle_job::*; | |
use crate::TaskOutput; | |
use crate::TaskResult; | |
use crate::TaskRunnerContext; | |
use anyhow_ext::anyhow; | |
use anyhow_ext::Result; | |
use async_recursion::async_recursion; | |
use jupiter_amm_interface::Amm; | |
use jupiter_amm_interface::SwapMode; | |
use lazy_static::lazy_static; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async fn get_accounts(client: &RpcClient, keys: Vec<Pubkey>) -> Result<HashMap<Pubkey, Account>> { | |
let account_datas: Vec<Option<Account>> = client | |
.get_multiple_accounts(&keys.clone()) | |
.await | |
.map_err(|_| anyhow!("Failed to get inf SPool accounts"))?; | |
let mut data_map = HashMap::new(); | |
for i in 0..keys.len() { | |
let key = &keys[i]; | |
let account = &account_datas[i]; | |
if let Some(account) = account { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as anchor from "@coral-xyz/anchor"; | |
import type { Commitment } from "@solana/web3.js"; | |
import { Connection, Keypair } from "@solana/web3.js"; | |
import * as fs from "fs"; | |
import yaml from 'js-yaml'; | |
import path from 'path'; | |
import os from 'os'; | |
type SolanaConfig = { | |
rpcUrl: string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
which base58 > /dev/null || (brew install pipx && pipx install base58) | |
# Function to detect if the input is hex | |
is_hex() { | |
[[ $1 =~ ^[0-9a-fA-F]+$ ]] && return 0 || return 1 | |
} | |
# Function to detect if the input is base64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const coder = new BorshAccountsCoder(program.idl); | |
const oracles = await queue.fetchOracleKeys(); | |
const oracleAccounts = await utils.rpc.getMultipleAccounts( | |
program.provider.connection, | |
oracles | |
); | |
const oracleDatas = oracleAccounts | |
.map((x: any) => coder.decode("OracleAccountData", x.account.data)); | |
// TODO: now filter out all oracles that keys are not currently verified and keys expire in more than an hour |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
TransactionInstruction, | |
Connection, | |
PublicKey, | |
Keypair, | |
Transaction, | |
SystemProgram, | |
LAMPORTS_PER_SOL, | |
} from "@solana/web3.js"; | |
import { Program } from "@coral-xyz/anchor"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use switchboard_solana::AggregatorHistoryBuffer; | |
use std::convert::TryInto; | |
let history_buffer = AggregatorHistoryBuffer::new(history_account_info)?; | |
let current_timestamp = Clock::get()?.unix_timestamp; | |
let one_hour_ago: f64 = history_buffer.lower_bound(current_timestamp - 3600).unwrap().try_into()?; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async sendRestTransaction( | |
serializedTx: Uint8Array | Buffer | Array<number>, | |
retries, | |
rpcEndpoint = this.defaultConnection.rpcEndpoint, | |
skipPreFlight = true | |
): Promise<TransactionSignature> { | |
const res = await fetch(rpcEndpoint, { | |
method: "POST", | |
headers: { | |
"Content-Type": "application/json", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const NONCE_RENT: u64 = 1_447_680; | |
pub struct NonceManager { | |
pub rpc_client: Arc<RpcClient>, | |
pub authority: Pubkey, | |
pub capacity: u64, | |
pub idx: u64, | |
} | |
impl NonceManager { | |
pub fn new(rpc_client: Arc<RpcClient>, authority: Pubkey, capacity: u64) -> Self { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static async asV0TxWithComputeIxs( | |
program: anchor.Program, | |
ixs: Array<TransactionInstruction>, | |
computeUnitLimitMultiple: number, | |
computeUnitPrice: number, | |
lookupTables?: Array<AddressLookupTableAccount> | |
): Promise<VersionedTransaction> { | |
lookupTables = lookupTables ?? []; | |
const priorityFeeIx = ComputeBudgetProgram.setComputeUnitPrice({ | |
microLamports: computeUnitPrice, |
NewerOlder