Skip to content

Instantly share code, notes, and snippets.

@mgild
Created September 29, 2025 03:29
Show Gist options
  • Select an option

  • Save mgild/bea4427f504096ea61f229011a30772e to your computer and use it in GitHub Desktop.

Select an option

Save mgild/bea4427f504096ea61f229011a30772e to your computer and use it in GitHub Desktop.
import { OracleJob, CrossbarClient } from "@switchboard-xyz/common";
import * as sb from "@switchboard-xyz/on-demand";
import { Keypair } from "@solana/web3.js";
function getRangeRiskScoreJob(payer: Keypair): OracleJob {
const job = OracleJob.fromObject({
tasks: [
{
httpTask: {
url: "https://api.range.org/v1/risk/address?address=${ADDRESS}&network=solana",
headers: [
{ key: "accept", value: "application/json" },
// placeholder resolved on-oracle by Secrets
{ key: "X-API-KEY", value: "${RANGE_API_KEY}" },
],
},
},
// Only accept numeric riskScore >= 0; null => no match => failure so no Risk
{ jsonParseTask: { path: "$.riskScore" } },
{ multiplyTask: { scalar: 10 } }, // 0–10 => 0–100
{
boundTask: {
lowerBoundValue: "0",
onExceedsLowerBoundValue: "0",
upperBoundValue: "100",
onExceedsUpperBoundValue: "100",
},
},
],
});
return job;
}
(async function main() {
const { crossbar, queue, gateway } = await sb.AnchorUtils.loadEnv();
// You'll need to provide the payer keypair and ADDRESS
const payer = Keypair.generate(); // Replace with your actual payer keypair
const res = await queue.fetchSignaturesConsensus({
gateway,
useEd25519: true,
feedConfigs: [
{
feed: {
jobs: [getRangeRiskScoreJob(payer)],
},
},
],
variableOverrides: {
RANGE_API_KEY: process.env.RANGE_API_KEY!,
ADDRESS: '5PAhQiYdLBd6SVdjzBQDxUAEFyDdF5ExNPQfcscnPRj5',
},
});
console.log(res.median_responses);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment