From 1f7d452c33e44377af5c74c24fa5d45a3279ec11 Mon Sep 17 00:00:00 2001 From: indirection42 Date: Wed, 6 Aug 2025 09:26:17 +0800 Subject: [PATCH 1/3] add more functions to fungibles extension --- .../sum-balance-percent/src/main.rs | 4 +-- guest-examples/sum-balance/src/main.rs | 2 +- poc/runtime/src/pvq.rs | 27 ++++++++++++++----- pvq-extension-fungibles/src/lib.rs | 6 +++++ pvq-test-runner/src/lib.rs | 18 +++++++++++++ 5 files changed, 48 insertions(+), 9 deletions(-) diff --git a/guest-examples/sum-balance-percent/src/main.rs b/guest-examples/sum-balance-percent/src/main.rs index 3468a24..1468c9c 100644 --- a/guest-examples/sum-balance-percent/src/main.rs +++ b/guest-examples/sum-balance-percent/src/main.rs @@ -6,9 +6,9 @@ mod sum_balance_percent { type AssetId = u32; type AccountId = [u8; 32]; type Balance = u64; - #[program::extension_fn(extension_id = 4071833530116166512u64, fn_index = 1)] + #[program::extension_fn(extension_id = 1248491991627109725u64, fn_index = 6)] fn balance(asset: AssetId, who: AccountId) -> Balance {} - #[program::extension_fn(extension_id = 4071833530116166512u64, fn_index = 0)] + #[program::extension_fn(extension_id = 1248491991627109725u64, fn_index = 5)] fn total_supply(asset: AssetId) -> Balance {} #[program::entrypoint] diff --git a/guest-examples/sum-balance/src/main.rs b/guest-examples/sum-balance/src/main.rs index 764cf32..2780a58 100644 --- a/guest-examples/sum-balance/src/main.rs +++ b/guest-examples/sum-balance/src/main.rs @@ -20,7 +20,7 @@ mod sum_balance { } } - #[program::extension_fn(extension_id = 4071833530116166512u64, fn_index = 1)] + #[program::extension_fn(extension_id = 1248491991627109725u64, fn_index = 6)] fn balance(asset: AssetId, who: AccountId) -> Balance {} #[program::entrypoint] diff --git a/poc/runtime/src/pvq.rs b/poc/runtime/src/pvq.rs index ccde806..e4d2797 100644 --- a/poc/runtime/src/pvq.rs +++ b/poc/runtime/src/pvq.rs @@ -1,11 +1,11 @@ -#[allow(unused_imports)] -use frame::deps::scale_info::prelude::{format, string::String}; - use pvq_extension::metadata::Metadata; use pvq_extension::{extensions_impl, ExtensionsExecutor, InvokeSource}; #[extensions_impl] pub mod extensions { + use frame::deps::scale_info::prelude::vec::Vec; + use frame::token::fungibles; + #[extensions_impl::impl_struct] pub struct ExtensionImpl; @@ -20,14 +20,29 @@ pub mod extensions { #[extensions_impl::extension] impl pvq_extension_fungibles::extension::ExtensionFungibles for ExtensionImpl { - type AccountId = [u8; 32]; + type AccountId = crate::interface::AccountId; type Balance = crate::interface::Balance; type AssetId = crate::interface::AssetId; + fn name(asset: Self::AssetId) -> Vec { + >::name(asset) + } + fn symbol(asset: Self::AssetId) -> Vec { + >::symbol(asset) + } + fn decimals(asset: Self::AssetId) -> u8 { + >::decimals(asset) + } fn balance(asset: Self::AssetId, who: Self::AccountId) -> Self::Balance { - crate::Assets::balance(asset, crate::interface::AccountId::from(who)) + >::balance(asset, &who) } fn total_supply(asset: Self::AssetId) -> Self::Balance { - crate::Assets::total_supply(asset) + >::total_issuance(asset) + } + fn minimum_balance(asset: Self::AssetId) -> Self::Balance { + >::minimum_balance(asset) + } + fn asset_exists(asset: Self::AssetId) -> bool { + >::asset_exists(asset) } } } diff --git a/pvq-extension-fungibles/src/lib.rs b/pvq-extension-fungibles/src/lib.rs index 2936bd9..7e104ca 100644 --- a/pvq-extension-fungibles/src/lib.rs +++ b/pvq-extension-fungibles/src/lib.rs @@ -3,11 +3,17 @@ use pvq_extension::extension_decl; #[extension_decl] pub mod extension { + use scale_info::prelude::vec::Vec; #[extension_decl::extension] pub trait ExtensionFungibles { type AssetId; type Balance; type AccountId; + fn asset_exists(asset: Self::AssetId) -> bool; + fn name(asset: Self::AssetId) -> Vec; + fn symbol(asset: Self::AssetId) -> Vec; + fn decimals(asset: Self::AssetId) -> u8; + fn minimum_balance(asset: Self::AssetId) -> Self::Balance; fn total_supply(asset: Self::AssetId) -> Self::Balance; fn balance(asset: Self::AssetId, who: Self::AccountId) -> Self::Balance; } diff --git a/pvq-test-runner/src/lib.rs b/pvq-test-runner/src/lib.rs index d9500ff..1bfd083 100644 --- a/pvq-test-runner/src/lib.rs +++ b/pvq-test-runner/src/lib.rs @@ -37,9 +37,24 @@ pub mod extensions { type AssetId = u32; type AccountId = [u8; 32]; type Balance = u64; + fn name(_asset: Self::AssetId) -> Vec { + b"Test".to_vec() + } + fn symbol(_asset: Self::AssetId) -> Vec { + b"TEST".to_vec() + } + fn decimals(_asset: Self::AssetId) -> u8 { + 18 + } fn total_supply(_asset: Self::AssetId) -> Self::Balance { 100 } + fn minimum_balance(_asset: Self::AssetId) -> Self::Balance { + 100 + } + fn asset_exists(_asset: Self::AssetId) -> bool { + true + } fn balance(_asset: Self::AssetId, _who: Self::AccountId) -> Self::Balance { 100 } @@ -133,6 +148,9 @@ impl TestRunner { pub fn expected_result(program_path: &str, chain: &str, entrypoint_idx: u8) -> Vec { // TODO: add more entrypoints + if program_path.contains("sum-balance") && chain == "poc" && entrypoint_idx == 0 { + return 1000_000_000u64.encode(); + } if program_path.contains("swap-info") && chain == "ah" && entrypoint_idx == 2 { return (10_235_709_412_325u128, 12_117_819_770_919u128).encode(); } From 0e50211afdf37962975d8cf87da455d2d3b365e1 Mon Sep 17 00:00:00 2001 From: indirection42 Date: Wed, 6 Aug 2025 09:30:28 +0800 Subject: [PATCH 2/3] fix clippy --- pvq-test-runner/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvq-test-runner/src/lib.rs b/pvq-test-runner/src/lib.rs index 1bfd083..106de3a 100644 --- a/pvq-test-runner/src/lib.rs +++ b/pvq-test-runner/src/lib.rs @@ -149,7 +149,7 @@ impl TestRunner { pub fn expected_result(program_path: &str, chain: &str, entrypoint_idx: u8) -> Vec { // TODO: add more entrypoints if program_path.contains("sum-balance") && chain == "poc" && entrypoint_idx == 0 { - return 1000_000_000u64.encode(); + return 1_000_000_000u64.encode(); } if program_path.contains("swap-info") && chain == "ah" && entrypoint_idx == 2 { return (10_235_709_412_325u128, 12_117_819_770_919u128).encode(); From 9b6d1429b9e55f517664e54cd1c3b4fa787c9bc0 Mon Sep 17 00:00:00 2001 From: indirection42 Date: Wed, 6 Aug 2025 10:43:53 +0800 Subject: [PATCH 3/3] build(ci): make build-guests run on pr to master --- .github/workflows/build.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 35bc0cf..86069b9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -123,11 +123,12 @@ jobs: # Generate guest program list dynamically generate-guest-matrix: runs-on: ubuntu-latest - # Run on main branches, release branches, or when explicitly requested + # Run on main branches, release branches, PRs to master, or when explicitly requested if: | github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release/') || startsWith(github.ref, 'refs/tags/v') || + github.base_ref == 'master' || contains(github.event.pull_request.labels.*.name, 'full-build') outputs: guest-matrix: ${{ steps.generate-matrix.outputs.guest-matrix }} @@ -189,7 +190,7 @@ jobs: collect-guests: runs-on: ubuntu-latest needs: [generate-guest-matrix, build-guest] - if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'full-build') + if: github.event_name == 'push' || github.base_ref == 'master' || contains(github.event.pull_request.labels.*.name, 'full-build') steps: - name: Download all guest artifacts uses: actions/download-artifact@v4