Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions guest-examples/swap-info/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod swap_info {
pub decimals: u8,
}

#[program::extension_fn(extension_id = 17401483330909459524u64, fn_index = 0)]
#[program::extension_fn(extension_id = 15900548380266538526u64, fn_index = 0)]
fn quote_price_tokens_for_exact_tokens(
asset1: AssetId,
asset2: AssetId,
Expand All @@ -25,7 +25,7 @@ mod swap_info {
) -> Option<Balance> {
}

#[program::extension_fn(extension_id = 17401483330909459524u64, fn_index = 1)]
#[program::extension_fn(extension_id = 15900548380266538526u64, fn_index = 1)]
fn quote_price_exact_tokens_for_tokens(
asset1: AssetId,
asset2: AssetId,
Expand All @@ -34,15 +34,18 @@ mod swap_info {
) -> Option<Balance> {
}

#[program::extension_fn(extension_id = 17401483330909459524u64, fn_index = 2)]
#[program::extension_fn(extension_id = 15900548380266538526u64, fn_index = 2)]
fn get_liquidity_pool(asset1: AssetId, asset2: AssetId) -> Option<(Balance, Balance)> {}

#[program::extension_fn(extension_id = 17401483330909459524u64, fn_index = 3)]
#[program::extension_fn(extension_id = 15900548380266538526u64, fn_index = 3)]
fn list_pools() -> alloc::vec::Vec<(AssetId, AssetId)> {}

#[program::extension_fn(extension_id = 17401483330909459524u64, fn_index = 4)]
#[program::extension_fn(extension_id = 15900548380266538526u64, fn_index = 4)]
fn asset_info(asset: AssetId) -> Option<AssetInfo> {}

#[program::extension_fn(extension_id = 15900548380266538526u64, fn_index = 5)]
fn assets_info() -> alloc::collections::BTreeMap<AssetId, AssetInfo> {}

#[program::entrypoint]
fn entrypoint_quote_price_exact_tokens_for_tokens(
asset1: AssetId,
Expand Down Expand Up @@ -70,9 +73,10 @@ mod swap_info {
fn entrypoint_list_pools() -> alloc::vec::Vec<(AssetInfo, AssetInfo)> {
let pools = list_pools();
let mut result = alloc::vec::Vec::new();
let assets_info = assets_info();
for pool in pools {
let asset1_info = asset_info(pool.0.clone());
let asset2_info = asset_info(pool.1.clone());
let asset1_info = assets_info.get(&pool.0).cloned();
let asset2_info = assets_info.get(&pool.1).cloned();
if let (Some(a1), Some(a2)) = (asset1_info, asset2_info) {
result.push((a1, a2));
}
Expand Down
3 changes: 3 additions & 0 deletions pvq-extension-swap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use pvq_extension::extension_decl;

#[extension_decl]
pub mod extension {
use alloc::collections::BTreeMap;
use alloc::vec::Vec;

#[extension_decl::extension]
Expand Down Expand Up @@ -32,5 +33,7 @@ pub mod extension {
fn list_pools() -> Vec<(Self::AssetId, Self::AssetId)>;

fn asset_info(asset: Self::AssetId) -> Option<Self::AssetInfo>;

fn assets_info() -> BTreeMap<Self::AssetId, Self::AssetInfo>;
}
}
6 changes: 6 additions & 0 deletions pvq-test-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub enum ExtensionFungiblesFunctions {

#[extensions_impl]
pub mod extensions {
use std::collections::BTreeMap;

use parity_scale_codec::Decode;

#[extensions_impl::impl_struct]
Expand Down Expand Up @@ -78,6 +80,10 @@ pub mod extensions {
fn asset_info(_asset: Self::AssetId) -> Option<Self::AssetInfo> {
None
}

fn assets_info() -> BTreeMap<Self::AssetId, Self::AssetInfo> {
BTreeMap::new()
}
}
}

Expand Down