0.1.5 • Published 2 months ago

@renec-foundation/oracle-sdk v0.1.5

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
2 months ago

oracle-sdk

How to use

import {
  PublicKey,
  Connection,
  Keypair,
  Commitment,
} from "@solana/web3.js";
import { AnchorProvider, Wallet, BN, Address } from "@project-serum/anchor";
import { Context, ProductClient, 
  ORACLE_PROGRAM_ID, REUSD, REVND, VERSION 
} from "@renec-foundation/oracle-sdk";


...
// yourKey = Keypair.fromSecretKey(Uint8Array.from([124, 149, 222, 31, 236, 142, 29, 95...]));

const commitment: Commitment = "confirmed";
const connection = new Connection(consts.RPC_ENDPOINT_URL, { commitment });
const wallet = new Wallet(yourKey);
const provider = new AnchorProvider(connection, wallet, { commitment });

const ctx = Context.withProvider(provider, ORACLE_PROGRAM_ID);


const base = REUSD;
const quote = REVND;
const newPrice = 24500.35;

const productClient = await ProductClient.getProduct(ctx, quote, base, VERSION);
const tx = await productClient.postPrice(
    newPrice,
    productClient.ctx.wallet.publicKey
);

await tx.buildAndExecute();
await productClient.refresh();

const price = await productClient.getPrice();
console.log("price", price);
  • Output
price {
  "price": 25000,
  "symbol": "VND/USD",
  "timestamp": 1686731721,
  "numberPublishers": 1
}