Program Client
Banksea Oracle aims to provide value of NFTs support on Solana. In this guide, we will teach you how to get the value (floor price, AI floor price, avg price in 24h) of collection on Solana Devnet.
Environment Setup
Development requires rust and solana environment:
Clone the example
Clone the example about Banksea Oracle:
$ git clone https://github.com/Banksea-Finance/banksea-oracle-example.git
Run the example
This section will guide you how to run the Banksea Oracle example.
Install the dependencies
$ npm install
Build the program
$ cargo build-bpf
Set Solana cluster to Devnet
$ solana config set --url devnet
Deploy the program
$ solana program deploy target/deploy/banksea_oracle_example.so
Run the test client
Run the following command to test the example program:
$ ts-node client/main.ts
Then, the result will be print, like following:
Answer Information:
degods
floor price is 269 SOL
AI floor price is 269 SOL
avg price is 360 SOL
updated on 'Fri, 22 Jul 2022 08:00:14 GMT'
Review the example
In this section, we will review the example code with you.
Cargo settings
First of all, please view the cargo.toml on root directory of the example project.
[package]
name = "banksea-oracle-example"
version = "0.3.0"
edition = "2018"
[dependencies]
borsh = "0.9.3"
borsh-derive = "0.9.3"
solana-program = "=1.10.29"
banksea-oracle-client = "0.4.0"
[lib]
crate-type = ["cdylib", "lib"]
There is banksea-oracle which is a rust library for Banksea Oracle. If you want to use Banksea Oracle on your program, you should copy this line to the cargo.toml on your project.
Program
the lib.rs is a simple program example:
fn process_instruction(
_program_id: &Pubkey,
accounts: &[AccountInfo],
_instruction_data: &[u8],
) -> ProgramResult {
let accounts_iter = &mut accounts.iter();
let feed_account = next_account_info(accounts_iter)?;
let answer_account = next_account_info(accounts_iter)?;
let feed_info = banksea_oracle::get_feed_info(feed_account)?;
let mut answer_info: Answer = try_from_slice_unchecked(&answer_account.data.borrow())?;
answer_info.unit = feed_info.unit;
answer_info.code = feed_info.code;
answer_info.decimals = feed_info.decimals;
answer_info.floor_price = feed_info.floor_price;
answer_info.avg_price = feed_info.avg_price;
answer_info.ai_floor_price = feed_info.ai_floor_price;
answer_info.aggregate_time = feed_info.aggregate_time;
answer_info.serialize(&mut &mut answer_account.data.borrow_mut()[..])?;
Ok(())
}
Client will call the process_instruction with feed_account and answer_account.
The process_instruction call the banksea_oracle::get_feed_info (to parse the feed_account) and copy the result to answer_account.
Then, the Client will print the detail of answer_account.
The table below provides an overview of the fields on FeedInfo:
Field Name
Description
oracle
The oracle handle which save configure of the oracle.
subscriber
The subcriber of this feeding.
code
The collection code which identify a collection.
unit
The unit of price.
decimals
The decimals of price.
aggregate_time
The latest aggregation time.
aggregate_node_count
The number of nodes at the latest aggregation.
floor_price
Minimum listing price of this collection on marketplace
ai_floor_price
The minimum AI valuation of this collection
avg_price
The 24 hour average price of the collection
Client
The typescript client is inclue:
main.ts: the program entry of client.
oracle.ts: the oracle call.
utils.ts: the utils of solana access.
Please View getOracleInfo on oracle.ts:
export async function getOracleInfo(): Promise<void> {
const feedAccountId = new PublicKey("DGaMbFh9BPZbNVWLygK4m3VhxBaNZkCumbnhpijFroaD") // It is `degods`
let feedAccount = {
pubkey: feedAccountId,
isSigner: false,
isWritable: false,
};
let answer = {
pubkey: answerPubkey,
isSigner: false,
isWritable: true
};
const instruction = new TransactionInstruction({
keys: [feedAccount, answer],
programId,
data: Buffer.alloc(0),
});
await sendAndConfirmTransaction(
connection,
new Transaction().add(instruction),
[payer],
);
// print the detail of answer account
const accountInfo = await connection.getAccountInfo(answerPubkey);
if (accountInfo === null) {
throw 'Error: cannot find the account';
}
const answerInfo = borsh.deserializeUnchecked(
AnswerSchema,
AnswerAccount,
Buffer.from(accountInfo.data),
);
answerInfo.print();
}
This function is an example for getting feed information about DeGods. If you want to get other collection, you can find the Feed Account on our site and replace the value of feedAccountId with it.
Last updated