2.3.17 • Published 2 months ago

@switchboard-xyz/sui.js v2.3.17

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

Switchboard Logo

@switchboard-xyz/sui.js

A Typescript client to interact with Switchboard V2 on Sui.

NPM Badge

Install

npm i --save @switchboard-xyz/sui.js

Usage

Directory

Reading Feeds

import { AggregatorAccount } from "@switchboard-xyz/sui.js";

const aggregatorAccount: AggregatorAccount = new AggregatorAccount(
  client,
  aggregator_address,
  SWITCHBOARD_ADDRESS
);

console.log(await aggregatorAccount.loadData());

Creating Feeds

import { Buffer } from "buffer";
import { OracleJob, createFeed } from "@switchboard-xyz/sui.js";
import Big from "big.js";
import {
Ed25519Keypair,
JsonRpcProvider,
devnetConnection,
} from "@mysten/sui.js";

// devnet address
const SWITCHBOARD_ADDRESS = "0x23ecb0df7bed0b4048f939298c9a179973e13d4e";
const QUEUE_ADDRESS = "0xacbb5327b76a6980495f4f3b7482c7f6cc5a4791";

// keypair
const keypair = Ed25519Keypair.fromSecretKey(Buffer.from(/** YOUR KEYPAIR IMPORT GOES HERE **/, "hex"));

// Make Job data for btc price
const serializedJob = Buffer.from(
OracleJob.encodeDelimited(
  OracleJob.create({
    tasks: [
      {
        httpTask: {
          url: "https://www.binance.us/api/v3/ticker/price?symbol=BTCUSD",
        },
      },
      {
        jsonParseTask: {
          path: "$.price",
        },
      },
    ],
  })
).finish()
);

const coins = await provider.selectCoinsWithBalanceGreaterThanOrEqual(
userAddress,
BigInt(10000000)
);

const coin: any = coins.pop();

const [aggregator, createFeedTx] = await createFeed(
provider,
keypair, // you will need to import a Sui Payer Keypair
{
  name: "BTC/USD",
  authority: userAddress,
  queueAddress: queue.address,
  batchSize: 1,
  minJobResults: 1,
  minOracleResults: 1,
  minUpdateDelaySeconds: 5,
  varianceThreshold: new Big(0),
  forceReportPeriod: 0,
  coinType: "0x2::sui::SUI",
  initialLoadAmount: 1,
  loadCoin: coin.details.reference.objectId,
  jobs: [
    {
      name: "BTC/USD",
      data: Array.from(serializedJob1),
      weight: 1,
    },
  ],
},
SWITCHBOARD_ADDRESS
);

console.log(`Created Aggregator address ${aggregator.address}.`);
2.3.18-beta.0

2 months ago

2.3.17-beta.0

3 months ago

2.3.17-beta.1

3 months ago

2.3.17

3 months ago

2.3.15-beta.0

3 months ago

2.3.15-beta.1

3 months ago

2.3.16

3 months ago

2.3.15

3 months ago

2.3.14

5 months ago

2.3.14-beta.0

5 months ago

2.3.13

1 year ago

2.3.12

1 year ago

2.3.11

1 year ago

2.3.8

1 year ago

2.3.7

1 year ago

2.3.9

1 year ago

2.3.5

1 year ago

2.3.10

1 year ago

2.3.2

1 year ago

2.3.4

1 year ago

2.3.3

1 year ago

2.3.0

1 year ago

2.3.1

1 year ago

2.2.1

1 year ago

2.2.0

1 year ago

2.1.0

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago