Skip to content

Instantly share code, notes, and snippets.

@mgild
mgild / x.rs
Created February 22, 2024 16:19
use base64::{engine::general_purpose::STANDARD as base64, Engine as _};
use wormhole_vaas::GuardianSetSig;
use wormhole_vaas::Vaa;
use libsecp256k1;
use hex;
use sha2::{Sha256, Digest};
use wormhole_vaas::Readable;
pub const DUMMY_VAA: &str = "UE5BVQEAAAADuAEAAAADDQH2RWm2Z8mKR0pI+MW+n7QQz/rfif2tRO/L6b+eVhIR9GHc2MwpL+NYVcsBhkhAg0hx18C5eVD+dCYLwey5EHYlAAJfsE584lX5cPZ2Of9IE2xaMMD88L70IOlTB2XkFbbrcR4PTS7+OeSJvHubUrzggYK3lhyEwJ00wtfZcdUmHMwoAAOjCCNZSw/UDoT7Xvcb9dfQy9BnnvFlnfih0qlQuSErc3kKrGkGLpYaaErVPNHZ3R4BY605Bsvp2kBKammsPwKrAQQJEzvF0E1gpLPn97YnZdyL+yDao4osiMlGS2YDYQFg5XLBuhbFcscSY9nj2PN54KR7OzkDafNBNHMN0Xl7aydcAAZlE4aG6Zf1Pf4lPx2gbQgPCc9wyICVXFhvbYdOvIafDnlN+MmKBuQUCt3YWZybtA4CTKlbKGjG3BkXVPvxTQu8AQdGn1M5uWJwNMoqg842mEWy7XeU6ZAfZVPo3Q0gGhHtahWMfOHZ0TnXmhrJjGw6oO7pDGKqSUEr3Gm+rIO0e/fZAQiVdsBtWxfKhhZKZKCAtrZZHonKTHu91bYm9RvoJRY93gEUFgSzKbyUJpYEb7DO6aBHwclVtYYlr5M2L7l/ufshAAqasa+PaMyZLLSbCkbgSaATkxVe1y2Ze8TdtMpRaCwcQyTCEFUDmo6LUc5088ykvCrB50l7VDsslautlgrr+TUfAQvDQiBFP6NKV/g38NivyNAXzIcoCAVLUn6H1IlgCyVQBhIIjehwad5
import { Connection, PublicKey } from "@solana/web3.js";
import {
BorshCoder,
BorshEventCoder,
EventParser,
Program,
web3,
} from "@coral-xyz/anchor";
import { IDL } from "./idl";
import { Connection, PublicKey } from "@solana/web3.js";
// Assuming you have initialized a connection to a Solana node
const connection = new Connection(
"https://switchboard.rpcpool.com/XXX"
);
// Public key of the program you want to get instructions for
const programId = new PublicKey("FFxRNZyzkQacQnkBD96ksKid4HScE5Bd33gKdyJ4aJyW");
import type { AccountInfo } from "@solana/web3.js";
import { Connection, PublicKey } from "@solana/web3.js";
import { Big, BigUtils, bs58 } from "@switchboard-xyz/common";
import { OracleJob } from "@switchboard-xyz/common";
async function fetchLatestSlotHash(
connection: Connection
): Promise<[bigint, string]> {
const slotHashesSysvarKey = new PublicKey(
"SysvarS1otHashes111111111111111111111111111"
import type { AccountInfo } from "@solana/web3.js";
import { Connection, PublicKey } from "@solana/web3.js";
import { Big, BigUtils, bs58 } from "@switchboard-xyz/common";
import { OracleJob } from "@switchboard-xyz/common";
async function fetchLatestSlotHash(
connection: Connection
): Promise<[bigint, string]> {
const slotHashesSysvarKey = new PublicKey(
"SysvarS1otHashes111111111111111111111111111"
@mgild
mgild / x.ts
Created December 28, 2023 21:35
import {
AptosAccount,
AptosClient,
BCS,
HexString,
TxnBuilderTypes,
} from "aptos";
import type { EntryFunctionId, MoveStructTag } from "aptos/src/generated";
import * as YAML from "yaml";
import * as fs from "fs";
async pop(account: AptosAccount, pop_idx?: number): Promise<string> {
return await sendAptosTx(
this.client,
account,
`${this.switchboardAddress}::crank_pop_action::run`,
[HexString.ensure(this.address).hex(), pop_idx ?? 0],
[this.coinType]
);
}
{% set arch_libdir = "/lib/x86_64-linux-gnu" %}
{% set log_level = "error" %}
sys.stack.size = "2048K"
sys.brk.max_size = "1024K"
loader.entrypoint = "file:{{ gramine.libos }}"
libos.entrypoint = "/sgx/app"
loader.log_level = "{{ log_level }}"
@mgild
mgild / x.rs
Created November 29, 2023 21:07
let v: Vec<Pin<Box<dyn Future<Output = Result<Decimal, SbError>>>>> = vec![
Box::pin(switchboard_utils::exchanges::BitfinexApi::fetch_ticker("tETHUSD", None).map_ok(|x| x.last_price)),
Box::pin(switchboard_utils::exchanges::CoinbaseApi::fetch_ticker("ETH-USD", None).map_ok(|x| x.price)),
Box::pin(switchboard_utils::exchanges::HuobiApi::fetch_ticker("ethusdt", None).map_ok(|x| Decimal::from_f64(x.close).unwrap())),
Box::pin(switchboard_utils::exchanges::KrakenApi::fetch_ticker("ETHUSD", None).map_ok(|x| x.close[0]))
];
let eth_prices: Vec<Decimal> = join_all(v).await.into_iter().filter_map(|x| x.ok()).collect();
use tokio;
use balancer_sdk;
use balancer_sdk::Web3;
use web3;
use ethcontract;
use balancer_sdk::helpers::build_web3;
use balancer_sdk::helpers::*;
use balancer_sdk::*;
use balancer_sdk::{Address, U256};
use balancer_sdk::helpers::*;