Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pallet assets pop api integration #71

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7c2eac2
feat: pallet assets pop api integration
Daanvdplas Apr 5, 2024
418aa63
style: renaming assets example
Daanvdplas Apr 12, 2024
3d385df
refactor: chain extension tests
Daanvdplas Apr 22, 2024
fd46a27
fix: add error handling other than ModuleError
Daanvdplas Jun 4, 2024
1022926
test: add transfer
Daanvdplas Jun 6, 2024
ecc82e2
chore: remove polkadot launch
Daanvdplas Jun 6, 2024
e81f78a
# This is a combination of 8 commits.
Daanvdplas Jun 6, 2024
f824801
refactor: error handling
Daanvdplas Jun 20, 2024
4670503
refactor: clarify todos
Daanvdplas Jun 20, 2024
2283161
refactor: error handling comments part 1
Daanvdplas Jun 24, 2024
f88dd89
refactor: apply comments part 2
Daanvdplas Jun 25, 2024
61b3a17
refactor: tests local fungibles
Daanvdplas Jun 26, 2024
c1616a3
refactor: naming pallet error
Daanvdplas Jun 26, 2024
13e947e
refactor: optimising pop api and additional logic + test
Daanvdplas Jun 26, 2024
7757319
refactor: runtime
Daanvdplas Jul 3, 2024
924df85
refactor: draft final design
Daanvdplas Jul 2, 2024
972e4c9
feat: add more interfaces
Daanvdplas Jul 5, 2024
47e2ea6
refactor: final bits
Daanvdplas Jul 5, 2024
9dcfccb
fix: compiling
Daanvdplas Jul 6, 2024
b067eda
fix: cannot find macro vec error
Daanvdplas Jul 16, 2024
8730f90
refactor: decoding failed and commenting out unimplemented tests
Daanvdplas Jul 17, 2024
b591222
style: renaming
Daanvdplas Jul 17, 2024
c2acbb5
refactor: bits and pieces
Daanvdplas Jul 18, 2024
3639320
docs: add docs to code
Daanvdplas Jul 18, 2024
81e9844
fix: replace test code to api fungibles
Daanvdplas Jul 18, 2024
023d3dc
fix: own review + fixing CI fail
Daanvdplas Jul 18, 2024
e683e16
refactor: add Error variants index + clippy allowance
Daanvdplas Jul 19, 2024
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
1,684 changes: 864 additions & 820 deletions Cargo.lock

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ subxt-signer = "0.34.0"
tokio = { version = "1.36", features = ["macros", "time", "rt-multi-thread"] }

# Build
substrate-wasm-builder = "18.0.0"
substrate-wasm-builder = "18.0.1"
substrate-build-script-utils = "11.0.0"

# Local
Expand Down Expand Up @@ -76,15 +76,15 @@ sc-transaction-pool-api = "29.0.0"
frame-benchmarking = { version = "29.0.0", default-features = false }
frame-benchmarking-cli = "33.0.0"
frame-executive = { version = "29.0.0", default-features = false }
frame-support = { version = "29.0.0", default-features = false }
frame-support = { version = "29.0.2", default-features = false }
frame-system = { version = "29.0.0", default-features = false }
frame-system-benchmarking = { version = "29.0.0", default-features = false }
frame-system-rpc-runtime-api = { version = "27.0.0", default-features = false }
frame-try-runtime = { version = "0.35.0", default-features = false }
pallet-aura = { version = "28.0.0", default-features = false }
pallet-authorship = { version = "29.0.0", default-features = false }
pallet-assets = { version = "30.0.0", default-features = false }
pallet-balances = { version = "29.0.0", default-features = false }
pallet-balances = { version = "29.0.2", default-features = false }
pallet-contracts = { version = "28.0.0", default-features = false }
pallet-message-queue = { version = "32.0.0", default-features = false }
pallet-multisig = { version = "29.0.0", default-features = false }
Expand All @@ -97,11 +97,11 @@ pallet-scheduler = { version = "30.0.0", default-features = false }
pallet-session = { version = "29.0.0", default-features = false }
pallet-sudo = { version = "29.0.0", default-features = false }
pallet-timestamp = { version = "28.0.0", default-features = false }
pallet-transaction-payment = { version = "29.0.0", default-features = false }
pallet-transaction-payment = { version = "29.0.2", default-features = false }
pallet-transaction-payment-rpc = "31.0.0"
pallet-transaction-payment-rpc-runtime-api = { version = "29.0.0", default-features = false }
pallet-utility = { version = "29.0.0", default-features = false }
sp-api = { version = "27.0.0", default-features = false }
sp-api = { version = "27.0.1", default-features = false }
sp-authority-discovery = { version = "27.0.0", default-features = false }
sp-block-builder = { version = "27.0.0", default-features = false }
sp-blockchain = "29.0.0"
Expand All @@ -125,20 +125,20 @@ sp-transaction-pool = { version = "27.0.0", default-features = false }
sp-version = { version = "30.0.0", default-features = false }

# Polkadot
pallet-xcm = { version = "=8.0.1", default-features = false }
pallet-xcm = { version = "8.0.5", default-features = false }
polkadot-cli = "8.0.0"
polkadot-parachain-primitives = { version = "7.0.0", default-features = false }
polkadot-runtime-parachains = { version = "8.0.1", default-features = false }
polkadot-runtime-parachains = { version = "8.0.3", default-features = false }
polkadot-primitives = { version = "8.0.1", default-features = false }
polkadot-runtime-common = { version = "8.0.1", default-features = false }
polkadot-runtime-common = { version = "8.0.3", default-features = false }
rococo-runtime-constants = { version = "8.0.0", default-features = false }
rococo-runtime = { version = "8.0.0", default-features = false }
xcm = { package = "staging-xcm", version = "8.0.1", default-features = false }
xcm-builder = { package = "staging-xcm-builder", version = "8.0.1", default-features = false }
xcm-executor = { package = "staging-xcm-executor", version = "8.0.1", default-features = false }
rococo-runtime = { version = "8.0.1", default-features = false }
xcm = { version = "8.0.1", package = "staging-xcm", default-features = false }
xcm-builder = { version = "8.0.3", package = "staging-xcm-builder", default-features = false }
xcm-executor = { version = "8.0.2", package = "staging-xcm-executor", default-features = false }

# Cumulus
asset-hub-rococo-runtime = { version = "0.12.0", default-features = false }
asset-hub-rococo-runtime = { version = "0.12.3", default-features = false }
asset-test-utils = { version = "8.0.1", default-features = false }
cumulus-pallet-aura-ext = { version = "0.8.0", default-features = false }
cumulus-pallet-parachain-system = { version = "0.8.1", default-features = false, features = ["parameterized-consensus-hook"] }
Expand All @@ -149,9 +149,9 @@ cumulus-primitives-aura = { version = "0.8.0", default-features = false }
cumulus-primitives-core = { version = "0.8.0", default-features = false }
cumulus-primitives-utility = { version = "0.8.1", default-features = false }
emulated-integration-tests-common = { version = "4.0.0", default-features = false }
pallet-collator-selection = { version = "10.0.0", default-features = false }
parachains-common = { version = "8.0.0", default-features = false }
parachain-info = { package = "staging-parachain-info", version = "0.8.0", default-features = false }
pallet-collator-selection = { version = "10.0.3", default-features = false }
parachains-common = { version = "8.0.1", default-features = false }
parachain-info = { version = "0.8.0", package = "staging-parachain-info", default-features = false }
cumulus-primitives-parachain-inherent = "0.8.0"
cumulus-relay-chain-interface = "0.8.0"
color-print = "0.3.4"
Expand All @@ -160,4 +160,4 @@ cumulus-client-collator = "0.8.0"
cumulus-client-consensus-aura = "0.8.0"
cumulus-client-consensus-common = "0.8.0"
cumulus-client-consensus-proposer = "0.8.0"
cumulus-client-service = "0.8.0"
cumulus-client-service = "0.8.0"
39 changes: 0 additions & 39 deletions polkadot-launch/config.json

This file was deleted.

12 changes: 5 additions & 7 deletions pop-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ edition = "2021"
[dependencies]
enumflags2 = { version = "0.7.7" }
ink = { version = "5.0.0", default-features = false }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.6", default-features = false, features = ["derive"] }
sp-io = { version = "23.0.0", default-features = false, features = ["disable_panic_handler", "disable_oom", "disable_allocator"] }
sp-runtime = { version = "24.0", default-features = false }
sp-io = { version = "31.0.0", default-features = false, features = ["disable_panic_handler", "disable_oom", "disable_allocator"] }

pop-primitives = { path = "../primitives", default-features = false }

Expand All @@ -26,8 +23,9 @@ std = [
"enumflags2/std",
"ink/std",
"pop-primitives/std",
"scale/std",
"scale-info/std",
"sp-io/std",
"sp-runtime/std",
]
assets = ["pop-primitives/assets"]
Daanvdplas marked this conversation as resolved.
Show resolved Hide resolved
balances = []
nfts = ["pop-primitives/nfts"]
cross-chain = ["pop-primitives/cross-chain"]
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Ignore build artifacts from the local tests sub-crate.
/target/
**/target/

# Ignore backup files creates by cargo fmt.
**/*.rs.bk

# Remove Cargo.lock when creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Cargo.lock
**/Cargo.lock
9 changes: 0 additions & 9 deletions pop-api/examples/balance-transfer/.gitignore

This file was deleted.

21 changes: 21 additions & 0 deletions pop-api/examples/fungibles/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "fungibles"
version = "0.1.0"
authors = ["[your_name] <[your_email]>"]
edition = "2021"

[dependencies]
ink = { version = "5.0.0", default-features = false }
pop-api = { path = "../../../pop-api", default-features = false, features = ["assets"] }
Daanvdplas marked this conversation as resolved.
Show resolved Hide resolved

[lib]
path = "lib.rs"

[features]
default = ["std"]
std = [
"ink/std",
"pop-api/std",
]
ink-as-dependency = []
e2e-tests = []
185 changes: 185 additions & 0 deletions pop-api/examples/fungibles/lib.rs
Daanvdplas marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
#![cfg_attr(not(feature = "std"), no_std, no_main)]

/// Local Fungibles:
/// 1. PSP-22 Interface
/// 2. PSP-22 Metadata Interface
/// 3. Asset Management
///
use ink::prelude::vec::Vec;
use pop_api::{
assets::fungibles::{self as api},
primitives::AssetId,
StatusCode,
};

pub type Result<T> = core::result::Result<T, StatusCode>;

#[ink::contract]
mod fungibles {
Daanvdplas marked this conversation as resolved.
Show resolved Hide resolved
use super::*;

#[ink(storage)]
#[derive(Default)]
pub struct Fungibles;

impl Fungibles {
#[ink(constructor, payable)]
Daanvdplas marked this conversation as resolved.
Show resolved Hide resolved
pub fn new() -> Self {
Daanvdplas marked this conversation as resolved.
Show resolved Hide resolved
ink::env::debug_println!("PopApiFungiblesExample::new");
Default::default()
}

/// 1. PSP-22 Interface:
/// - total_supply
/// - balance_of
/// - allowance
/// - transfer
/// - transfer_from
/// - approve
/// - increase_allowance
/// - decrease_allowance

#[ink(message)]
pub fn total_supply(&self, id: AssetId) -> Result<Balance> {
Daanvdplas marked this conversation as resolved.
Show resolved Hide resolved
api::total_supply(id)
}

#[ink(message)]
pub fn balance_of(&self, id: AssetId, owner: AccountId) -> Result<Balance> {
api::balance_of(id, owner)
}

#[ink(message)]
pub fn allowance(
&self,
id: AssetId,
owner: AccountId,
spender: AccountId,
) -> Result<Balance> {
api::allowance(id, owner, spender)
}

#[ink(message)]
pub fn transfer(&self, id: AssetId, to: AccountId, value: Balance) -> Result<()> {
Daanvdplas marked this conversation as resolved.
Show resolved Hide resolved
api::transfer(id, to, value)
}

#[ink(message)]
pub fn transfer_from(
&self,
id: AssetId,
from: AccountId,
to: AccountId,
value: Balance,
// In the PSP-22 standard a `[u8]`, but the size needs to be known at compile time.
_data: Vec<u8>,
) -> Result<()> {
api::transfer_from(id, from, to, value)
}

#[ink(message)]
pub fn approve(&self, id: AssetId, spender: AccountId, value: Balance) -> Result<()> {
api::approve(id, spender, value)
}

#[ink(message)]
pub fn increase_allowance(
&self,
id: AssetId,
spender: AccountId,
value: Balance,
) -> Result<()> {
api::increase_allowance(id, spender, value)
}

#[ink(message)]
pub fn decrease_allowance(
&self,
id: AssetId,
spender: AccountId,
value: Balance,
) -> Result<()> {
api::decrease_allowance(id, spender, value)
}

/// 2. PSP-22 Metadata Interface:
/// - token_name
/// - token_symbol
/// - token_decimals

#[ink(message)]
pub fn token_name(&self, id: AssetId) -> Result<Vec<u8>> {
api::token_name(id)
}

#[ink(message)]
pub fn token_symbol(&self, id: AssetId) -> Result<Vec<u8>> {
api::token_symbol(id)
}

#[ink(message)]
pub fn token_decimals(&self, id: AssetId) -> Result<u8> {
api::token_decimals(id)
}

// 3. Asset Management:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#92

// - create
// - start_destroy
// - destroy_accounts
// - destroy_approvals
// - finish_destroy
// - set_metadata
// - clear_metadata

// #[ink(message)]
// pub fn create(&self, id: AssetId, admin: AccountId, min_balance: Balance) -> Result<()> {
Daanvdplas marked this conversation as resolved.
Show resolved Hide resolved
// ink::env::debug_println!(
// "PopApiFungiblesExample::create: id: {:?} admin: {:?} min_balance: {:?}",
// id,
// admin,
// min_balance,
// );
// let result = api::create(id, admin, min_balance);
// ink::env::debug_println!("Result: {:?}", result);
// result.map_err(|e| e.into())
// result
// }

// #[ink(message)]
// pub fn set_metadata(
// &self,
// id: AssetId,
// name: Vec<u8>,
// symbol: Vec<u8>,
// decimals: u8,
// ) -> Result<()> {
// ink::env::debug_println!(
// "PopApiFungiblesExample::set_metadata: id: {:?} name: {:?} symbol: {:?}, decimals: {:?}",
// id,
// name,
// symbol,
// decimals,
// );
// let result = api::set_metadata(id, name, symbol, decimals);
// ink::env::debug_println!("Result: {:?}", result);
// // result.map_err(|e| e.into())
// result
// }
//
// #[ink(message)]
// pub fn asset_exists(&self, id: AssetId) -> Result<bool> {
// // api::asset_exists(id).map_err(|e| e.into())
// api::asset_exists(id)
// }
}

#[cfg(test)]
mod tests {
use super::*;

#[ink::test]
fn default_works() {
Daanvdplas marked this conversation as resolved.
Show resolved Hide resolved
PopApiFungiblesExample::new();
}
}
}
9 changes: 0 additions & 9 deletions pop-api/examples/nfts/.gitignore

This file was deleted.

Loading
Loading