Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Daanvdplas committed Jul 21, 2024
1 parent c8d8b2a commit c88387d
Show file tree
Hide file tree
Showing 27 changed files with 532 additions and 1,777 deletions.
23 changes: 12 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pallet-api = { path = "pallets/api", default-features = false }
pop-runtime-devnet = { path = "runtime/devnet", default-features = true } # default-features=true required for `-p pop-node` builds
pop-runtime-testnet = { path = "runtime/testnet", default-features = true } # default-features=true required for `-p pop-node` builds
pop-runtime-common = { path = "runtime/common", default-features = false }
pop-primitives = { path = "./primitives", default-features = false }
primitives = { path = "./primitives", default-features = false }

# Substrate
sc-basic-authorship = "0.35.0"
Expand Down
2 changes: 2 additions & 0 deletions pallets/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ frame-benchmarking.workspace = true
frame-support.workspace = true
frame-system.workspace = true
pallet-assets.workspace = true
primitives = { workspace = true, features = ["fungibles"] }
sp-runtime.workspace = true

[dev-dependencies]
Expand All @@ -38,6 +39,7 @@ std = [
"frame-support/std",
"frame-system/std",
"pallet-assets/std",
"primitives/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
Expand Down
49 changes: 35 additions & 14 deletions pallets/api/src/fungibles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ pub mod pallet {
use frame_support::{
dispatch::{DispatchResult, DispatchResultWithPostInfo, WithPostDispatchInfo},
pallet_prelude::*,
traits::fungibles::Inspect,
traits::fungibles::{
approvals::Inspect as ApprovalInspect, metadata::Inspect as MetadataInspect, Inspect,
},
};
use frame_system::pallet_prelude::*;
use pallet_assets::WeightInfo;
use sp_runtime::traits::StaticLookup;

use primitives::constants::fungibles::*;

type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
type AssetIdOf<T> = <pallet_assets::Pallet<T, AssetsInstanceOf<T>> as Inspect<
<T as frame_system::Config>::AccountId,
Expand All @@ -31,19 +35,15 @@ pub mod pallet {

/// The required input for state queries in pallet assets.
#[derive(Encode, Decode, Debug, MaxEncodedLen)]
pub enum AssetsKeys<T: Config> {
#[codec(index = 0)]
TotalSupply(AssetIdOf<T>),
#[codec(index = 1)]
BalanceOf(AssetIdOf<T>, AccountIdOf<T>),
#[codec(index = 2)]
Allowance(AssetIdOf<T>, AccountIdOf<T>, AccountIdOf<T>),
#[codec(index = 3)]
TokenName(AssetIdOf<T>),
#[codec(index = 4)]
TokenSymbol(AssetIdOf<T>),
#[codec(index = 5)]
TokenDecimals(AssetIdOf<T>),
#[repr(u8)]
#[allow(clippy::unnecessary_cast)]
pub enum Keys<T: Config> {
TotalSupply(AssetIdOf<T>) = TOTAL_SUPPLY,
BalanceOf(AssetIdOf<T>, AccountIdOf<T>) = BALANCE_OF,
Allowance(AssetIdOf<T>, AccountIdOf<T>, AccountIdOf<T>) = ALLOWANCE,
TokenName(AssetIdOf<T>) = TOKEN_NAME,
TokenSymbol(AssetIdOf<T>) = TOKEN_SYMBOL,
TokenDecimals(AssetIdOf<T>) = TOKEN_DECIMALS,
}

#[pallet::config]
Expand Down Expand Up @@ -94,8 +94,29 @@ pub mod pallet {
pub fn total_supply(id: AssetIdOf<T>) -> BalanceOf<T> {
Assets::<T>::total_supply(id)
}

pub fn balance_of(id: AssetIdOf<T>, owner: &AccountIdOf<T>) -> BalanceOf<T> {
Assets::<T>::balance(id, owner)
}

pub fn allowance(
id: AssetIdOf<T>,
owner: &AccountIdOf<T>,
spender: &AccountIdOf<T>,
) -> BalanceOf<T> {
Assets::<T>::allowance(id, owner, spender)
}

pub fn token_name(id: AssetIdOf<T>) -> Vec<u8> {
<Assets<T> as MetadataInspect<AccountIdOf<T>>>::name(id)
}

pub fn token_symbol(id: AssetIdOf<T>) -> Vec<u8> {
<Assets<T> as MetadataInspect<AccountIdOf<T>>>::symbol(id)
}

pub fn token_decimals(id: AssetIdOf<T>) -> u8 {
<Assets<T> as MetadataInspect<AccountIdOf<T>>>::decimals(id)
}
}
}
11 changes: 4 additions & 7 deletions pop-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pop-api"
description = "Easily access the power of Polkadot via the Pop Network"
description = "Enabling smart(er) contracts with the power of Polkadot"
license = "GPL-3.0-only"
version = "0.0.0"
edition = "2021"
Expand All @@ -10,7 +10,7 @@ enumflags2 = { version = "0.7.7" }
ink = { version = "5.0.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 }
primitives = { path = "../primitives", default-features = false }

[lib]
name = "pop_api"
Expand All @@ -22,10 +22,7 @@ default = ["std"]
std = [
"enumflags2/std",
"ink/std",
"pop-primitives/std",
"primitives/std",
"sp-io/std",
]
assets = ["pop-primitives/assets"]
balances = []
nfts = ["pop-primitives/nfts"]
cross-chain = ["pop-primitives/cross-chain"]
fungibles = ["primitives/fungibles"]
2 changes: 1 addition & 1 deletion pop-api/examples/fungibles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"

[dependencies]
ink = { version = "5.0.0", default-features = false }
pop-api = { path = "../../../pop-api", default-features = false, features = ["assets"] }
pop-api = { path = "../../../pop-api", default-features = false, features = ["fungibles"] }

[lib]
path = "lib.rs"
Expand Down
4 changes: 2 additions & 2 deletions pop-api/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ frame-system = { version = "29.0.0", default-features = false }
pallet-balances = { version = "29.0.2", default-features = false }
pallet-assets = { version = "30.0.0", default-features = false }
pallet-contracts = { version = "28.0.0", default-features = false }
pop-primitives = { path = "../../primitives", default-features = false, features = ["assets"] }
primitives = { path = "../../primitives", default-features = false }
pop-runtime-devnet = { path = "../../runtime/devnet", default-features = false }
sp-io = { version = "31.0.0", default-features = false }
sp-runtime = { version = "32.0.0", default-features = false }
Expand All @@ -25,7 +25,7 @@ std = [
"pallet-balances/std",
"pallet-assets/std",
"pallet-contracts/std",
"pop-primitives/std",
"primitives/std",
"pop-runtime-devnet/std",
"scale/std",
"sp-io/std",
Expand Down
21 changes: 21 additions & 0 deletions pop-api/integration-tests/contracts/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 = ["fungibles"] }

[lib]
path = "lib.rs"

[features]
default = ["std"]
std = [
"ink/std",
"pop-api/std",
]
ink-as-dependency = []
e2e-tests = []
Loading

0 comments on commit c88387d

Please sign in to comment.