@surec/oracle
Version:
Typescript SDK for the Sure Oracle to be used to bring off-chain data on-chain
56 lines • 1.77 kB
JavaScript
import * as anchor from '@project-serum/anchor';
import * as solanaContrib from '@saberhq/solana-contrib';
import { IDL } from './idls/oracle.js';
import { Proposal } from './proposal.js';
import { Vote } from './vote.js';
import { PDA } from './pda.js';
import { SURE_ADDRESSES } from './constants.js';
import { Config } from './config.js';
// checkpoint : generate oracle idl and use it in sdk
export class Provider {
constructor(connection, wallet, opts) {
this.connection = connection;
this.wallet = wallet;
this.opts = opts;
}
static init({ connection, wallet, opts }) {
return new Provider(connection, wallet, opts);
}
}
export class SureOracleSDK {
constructor(provider, program, pda) {
this.provider = provider;
this.program = program;
this.pda = pda;
}
static init({ connection, wallet, opts, }) {
const oracleProvider = solanaContrib.SolanaProvider.init({
connection,
wallet: wallet,
opts,
});
const anchorProvider = new anchor.AnchorProvider(connection, wallet, {
skipPreflight: true,
});
// get anchorprogram properly
const program = new anchor.Program(IDL, SURE_ADDRESSES.Oracle, anchorProvider);
const pda = new PDA();
return new SureOracleSDK(new solanaContrib.SolanaAugmentedProvider(oracleProvider), program, pda);
}
static pda() {
return new PDA();
}
config() {
return new Config(this);
}
proposal() {
return new Proposal(this);
}
vote() {
return new Vote(this);
}
executeTransactionInstructions(tx) {
return this.provider.newTX(tx);
}
}
//# sourceMappingURL=sdk.js.map