Skip to main content

sbv2-aptos

A Move module to interact with Switchboard V2 on Aptos.

Github

View the Github repo

Install

Add the following to your Move.toml file.

[addresses]
switchboard = "0xc9b4bb0b1f7a343687c4f8bc6eea36dd2a3aa8d654e640050ab5b8635a6b9cbd"

[dependencies]
MoveStdlib = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/move-stdlib/", rev = "devnet" }
AptosFramework = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-framework/", rev = "devnet" }
AptosStdlib = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-stdlib/", rev = "devnet" }
Switchboard = { git = "https://github.com/switchboard-xyz/sbv2-aptos.git", subdir = "switchboard-move/switchboard/", rev = "main" }

Reading Feeds

use switchboard::aggregator;
use switchboard::math;

// store latest value
struct AggregatorInfo has copy, drop, store, key {
aggregator_addr: address,
latest_result: u128,
latest_result_scaling_factor: u8,
latest_result_neg: bool,
}

// get latest value
public fun save_latest_value(aggregator_addr: address) {
// get latest value
let latest_value = aggregator::latest_value(aggregator_addr);
let (value, scaling_factor, neg) = math::unpack(latest_value);
move_to(account, AggregatorInfo {
aggregator_addr: aggregator_addr,
latest_result: value,
latest_result_scaling_factor: scaling_factor,
latest_result_neg: neg,
});
}

Tests

Some testing that uses aggregator test utility functions

#[test(account = @0x1)]
public entry fun test_aggregator(account: &signer) {

// creates test aggregator with data
aggregator::new_test(account, 100, 0, false);

// print out value
std::debug::print(&aggregator::latest_value(signer::address_of(account)));
}