Skip to content

Instantly share code, notes, and snippets.

module Switchboard::Aggregator {
use AptosFramework::timestamp;
use Switchboard::Math::{Self, Num};
use Switchboard::VecUtils;
use std::bcs;
use std::hash;
use std::option::{Self, Option};
use std::signer;
use std::vector;
import fetch, { Response } from "node-fetch";
import { Connection, LAMPORTS_PER_SOL, PublicKey } from "@solana/web3.js";
async function loadZeroCopyResult(
con: Connection,
addr: PublicKey
): Promise<any> {
const data = (await con.getAccountInfo(addr))!.data;
let offset = 0;
const dicsriminator = data[0];
<table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
<tbody>
<tr style="padding:0;text-align:left;vertical-align:top">
<td style="Margin:0;color:#0a0a0a;font-family:'Open Sans',Helvetica,Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
<table cellpadding="0" cellspacing="0" style="height:100px;border-collapse:unset;padding:0px">
<tbody>
<tr>
<td height="100" align="left" valign="middle" style="font-size:0px;height:100px;vertical-align:middle;padding:0px">
<p style="margin:0.1pt;line-height:0px;padding:0px">
@mgild
mgild / x.rs
Created September 14, 2022 08:59
use crate::error::Error;
use crate::*;
use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::serde::{Deserialize, Serialize};
#[derive(Default, Clone, BorshSerialize, BorshDeserialize, Serialize, Deserialize)]
pub struct AggregatorRead {
pub address: Uuid,
pub payer: Option<Uuid>,
}
(async function main() {
const con = new sol.Connection("<URL>");
const sigs = await con.getSignaturesForAddress(
new sol.PublicKey("4yc4MtfTaGVh2WyrZ9scxZNusLrzP243E3ra6gTtvcP2"),
{
before: "<START TX>",
until:
"2AVSgDStayxKcvd8tnr2tw3e68ejfUVsjmrAxMkBXNZmryAiiChAWCcNrLisFdJ2UW3JKh9tJUu3yWbsucsnxryG",
}
);
@mgild
mgild / x.ts
Created November 10, 2022 19:03
import Big from "big.js";
import BN from "bn.js";
import * as anchor from "@project-serum/anchor";
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
import { OracleJob, SwitchboardDecimal } from "@switchboard-xyz/common";
import { AggregatorHistoryRow } from "@switchboard-xyz/switchboard-v2";
async function weightedTwap(
history: Array<AggregatorHistoryRow>,
minSamples: number,
async function tsFeedCreate(program, jobData) {
const data = Buffer.from(
OracleJob.encodeDelimited(OracleJob.fromObject(jobData)).finish()
);
const job = await sbv2.JobAccount.create(program, {
data,
authority: sbv2.programWallet(program).publicKey,
});
const queue = new sbv2.OracleQueueAccount({
program,
public async calculateSwapPrice(poolAddress: PublicKey): Promise<Big> {
// calculate swap for normal orca lp pool
try {
const [pool, poolParameters, tokenA, tokenB] = this.getPool(poolAddress);
const quote = await pool.getQuote(
tokenA,
new Decimal(1), // swap amount of tokenA to tokenB
new Decimal(0.5) // allowable slippage
);
#[derive(Serialize, Debug)]
pub struct AggregatorOpenRoundEvent {
pub feed_key: Uuid,
pub oracles: Vec<Uuid>,
pub jobs: Vec<Uuid>,
}
impl NearEvent for AggregatorOpenRoundEvent {}
#[derive(Serialize, Debug)]
jE [FetchError]: request to https://switchbo-switchbo-6225.devnet.rpcpool.com/XXX failed, reason: socket hang up
at ClientRequest.<anonymous> (/home/node_modules/@solana/web3.js/node_modules/node-fetch/lib/index.js:1491:11)
at ClientRequest.emit (node:events:513:28)
at TLSSocket.socketOnEnd (node:_http_client:518:9)
at TLSSocket.emit (node:events:525:35)
at endReadableNT (node:internal/streams/readable:1358:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
type: 'system',
errno: 'ECONNRESET',
code: 'ECONNRESET'