Skip to content

Instantly share code, notes, and snippets.

@ahermida
ahermida / monadFeedUpdate.ts
Created October 23, 2025 17:48
Monad Update -
#!/usr/bin/env bun
/**
* Monad Mainnet - Switchboard Feed Update Utility
*
* This script fetches oracle data from Switchboard's Crossbar service and submits
* feed updates to the Switchboard contract on Monad Mainnet. It can also query
* the current state of feeds on-chain.
*
* Prerequisites:
* - Bun runtime: https://bun.sh
@ahermida
ahermida / .gitignore
Last active July 1, 2025 14:53
crank
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
# Logs
logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
@ahermida
ahermida / settleRandomness.ts
Created May 14, 2025 19:51
Switchboard Randomness Core Testnet 2 Example
import { ethers, BigNumberish } from 'ethers';
import * as dotenv from 'dotenv';
import { CrossbarClient } from '@switchboard-xyz/common';
// Load environment variables
dotenv.config();
// Contract ABI for the randomness-related functions
const RANDOMNESS_ABI = [
// requestRandomness IS TO BE CALLED WHEN CREATING A NEW RANDOMNESS REQUEST - FROM INSIDE YOUR CONTRACT
@ahermida
ahermida / RandomnessTest.sol
Created October 19, 2024 06:38
Running RNG with Switchboard On-Demand on Arbitrum
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
/// DEPLOYED AT https://sepolia.arbiscan.io/address/0x237485729745b2ba588d1414e40e1faf126fc604
/// My additions:
/// I added the Switchboard Devnet Queue - which hits the cluster of oracles for test networks. This is the only queue enabled on Testnets.
/// Thanks for your patience with this. It will be made clearer in the documentation.
import {Structs} from "";
import {ISwitchboard} from ""
@ahermida
ahermida / batching_example.ts
Created September 11, 2024 20:12
An example of batch requests to switchboard oracles and a simple measurement of the speed altogether.
import { PublicKey, Keypair } from "@solana/web3.js";
import { CrossbarClient } from "@switchboard-xyz/common";
import { PullFeed, asV0Tx, getDefaultQueue } from "@switchboard-xyz/on-demand";
import { config as dotenv } from "dotenv";
import base58 from "bs58";
import perf from "perf_hooks";
// load environment variables
dotenv();
@ahermida
ahermida / batching_example.ts
Created September 11, 2024 20:11
An example of batch requests to switchboard oracles and a simple measurement of the speed altogether.
import { PublicKey, Keypair } from "@solana/web3.js";
import { CrossbarClient } from "@switchboard-xyz/common";
import { PullFeed, asV0Tx, getDefaultQueue } from "@switchboard-xyz/on-demand";
import { config as dotenv } from "dotenv";
import base58 from "bs58";
import perf from "perf_hooks";
// load environment variables
dotenv();
// Import necessary modules
import { GatewayCache } from "./src/chains/evm/GatewayCache";
import { getIPFSClient } from "./src/ipfs";
import type { FeedHashDefinition } from "./src/util";
import { getDevnetQueue } from "./src/util";
import { OracleJob } from "@switchboard-xyz/common";
import { Gateway } from "@switchboard-xyz/on-demand";
import axios from "axios";
import * as fs from "fs";
@ahermida
ahermida / SwitchboardModule.sol
Created May 16, 2024 08:53
Testnet Flows SB
//SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0 <0.9.0;
import {Structs} from "./structs/Structs.sol";
import {FeedLib} from "./feed/FeedLib.sol";
import {FeedStorage} from "./feed/FeedStorage.sol";
import {QueueLib} from "./queue/QueueLib.sol";
import {QueueStorage} from "./queue/QueueStorage.sol";
import {AggregatorLib} from "./aggregator/AggregatorLib.sol";
import {AggregatorStorage} from "./aggregator/AggregatorStorage.sol";
@ahermida
ahermida / gist:bde45365ee3240e93814de5e9b87d4e9
Created May 16, 2024 08:50
Attempt to submit a btc update using Switchboard
import {
getFeedUpdateData,
getDefaultDevnetQueue,
OracleJob,
} from "@switchboard-xyz/on-demand"; // use @switchboard-xyz/[email protected]
import { ethers } from "ethers"; // use ethers@^6.12.1
async function getTimeBTC() {
return getFeedUpdateData(
{
// SPDX-License-Identifier: UNLICENSED
// This is an interface for interacting with the Receiver contract from Switchboard's Pull Model
pragma solidity ^0.8.9;
// Struct representing a result for a feed and interval
struct Result {
int256 value; // The value of the feed result
uint256 timestamp; // The timestamp of the result
uint256 updatedAt; // The timestamp when the result was last updated