Skip to content

Commit 6f994c2

Browse files
committed
Shibuya compiles
1 parent df1ccc1 commit 6f994c2

File tree

7 files changed

+95
-77
lines changed

7 files changed

+95
-77
lines changed

pallets/inflation/src/benchmarking.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use super::*;
2020

2121
use frame_benchmarking::v2::*;
22+
use frame_support::traits::tokens::Precision;
2223
use frame_system::{Pallet as System, RawOrigin};
2324
use sp_std::prelude::*;
2425

@@ -65,7 +66,12 @@ fn initial_config<T: Config>() {
6566

6667
// Create some issuance so it's not zero
6768
let dummy_account = whitelisted_caller();
68-
T::Currency::make_free_balance_be(&dummy_account, 1_000_000_000_000_000_000_000);
69+
let _debt = T::Currency::deposit(
70+
&dummy_account,
71+
1_000_000_000_000_000_000_000,
72+
Precision::Exact,
73+
)
74+
.expect("Must succeed for benchmarking");
6975
}
7076

7177
#[benchmarks]

pallets/inflation/src/lib.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,14 @@ use astar_primitives::{
104104
},
105105
Balance,
106106
};
107-
use frame_support::{pallet_prelude::*, traits::Currency, DefaultNoBound};
107+
use frame_support::{
108+
pallet_prelude::*,
109+
traits::{
110+
fungible::{Balanced, Credit, Inspect},
111+
tokens::Precision,
112+
},
113+
DefaultNoBound,
114+
};
108115
use frame_system::{ensure_root, pallet_prelude::*};
109116
use serde::{Deserialize, Serialize};
110117
use sp_runtime::{
@@ -136,19 +143,15 @@ pub mod pallet {
136143
pub struct Pallet<T>(PhantomData<T>);
137144

138145
// Negative imbalance type of this pallet.
139-
pub(crate) type NegativeImbalanceOf<T> = <<T as Config>::Currency as Currency<
140-
<T as frame_system::Config>::AccountId,
141-
>>::NegativeImbalance;
146+
pub(crate) type CreditOf<T> =
147+
Credit<<T as frame_system::Config>::AccountId, <T as Config>::Currency>;
142148

143149
#[pallet::config]
144150
pub trait Config: frame_system::Config {
145-
/// The currency trait.
146-
/// This has been soft-deprecated but it still needs to be used here in order to access `NegativeImbalance`
147-
/// which is defined in the currency trait.
148-
type Currency: Currency<Self::AccountId, Balance = Balance>;
151+
type Currency: Balanced<Self::AccountId, Balance = Balance>;
149152

150153
/// Handler for 'per-block' payouts.
151-
type PayoutPerBlock: PayoutPerBlock<NegativeImbalanceOf<Self>>;
154+
type PayoutPerBlock: PayoutPerBlock<CreditOf<Self>>;
152155

153156
/// Cycle ('year') configuration - covers periods, subperiods, eras & blocks.
154157
type CycleConfiguration: CycleConfiguration;
@@ -451,9 +454,11 @@ pub mod pallet {
451454

452455
// This can fail only if the amount is below existential deposit & the account doesn't exist,
453456
// or if the account has no provider references.
457+
// Another possibility is overflow, but if that happens, we already have a huge problem.
458+
//
454459
// In both cases, the reward is lost but this can be ignored since it's extremely unlikely
455460
// to appear and doesn't bring any real harm.
456-
let _ = T::Currency::deposit_creating(account, reward);
461+
let _ = T::Currency::deposit(account, reward, Precision::Exact);
457462
Ok(())
458463
}
459464
}

pallets/inflation/src/mock.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
// along with Astar. If not, see <http://www.gnu.org/licenses/>.
1818

1919
use crate::{
20-
self as pallet_inflation, ActiveInflationConfig, CycleConfiguration, InflationParameters,
21-
InflationParams, NegativeImbalanceOf, PayoutPerBlock,
20+
self as pallet_inflation, ActiveInflationConfig, CreditOf, CycleConfiguration,
21+
InflationParameters, InflationParams, PayoutPerBlock,
2222
};
2323

2424
use frame_support::{
2525
construct_runtime, parameter_types,
26-
traits::Currency,
27-
traits::{ConstU128, ConstU32, Hooks},
26+
traits::{fungible::Balanced, ConstU128, ConstU32, Hooks},
2827
weights::Weight,
2928
PalletId,
3029
};
@@ -110,13 +109,15 @@ pub(crate) const TREASURY_POT: PalletId = PalletId(*b"moktrsry");
110109
pub(crate) const COLLATOR_POT: PalletId = PalletId(*b"mokcolat");
111110

112111
pub struct DummyPayoutPerBlock;
113-
impl PayoutPerBlock<NegativeImbalanceOf<Test>> for DummyPayoutPerBlock {
114-
fn treasury(reward: NegativeImbalanceOf<Test>) {
115-
Balances::resolve_creating(&TREASURY_POT.into_account_truncating(), reward);
112+
impl PayoutPerBlock<CreditOf<Test>> for DummyPayoutPerBlock {
113+
fn treasury(reward: CreditOf<Test>) {
114+
Balances::resolve(&TREASURY_POT.into_account_truncating(), reward)
115+
.expect("Must succeed for test.");
116116
}
117117

118-
fn collators(reward: NegativeImbalanceOf<Test>) {
119-
Balances::resolve_creating(&COLLATOR_POT.into_account_truncating(), reward);
118+
fn collators(reward: CreditOf<Test>) {
119+
Balances::resolve(&COLLATOR_POT.into_account_truncating(), reward)
120+
.expect("Must succeed for test.");
120121
}
121122
}
122123

runtime/astar/src/lib.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use frame_support::{
3030
genesis_builder_helper::{build_state, get_preset},
3131
parameter_types,
3232
traits::{
33+
fungible::{Balanced, Credit, HoldConsideration},
3334
AsEnsureOriginWithArg, ConstBool, ConstU32, Contains, Currency, FindAuthor, Get, Imbalance,
3435
InstanceFilter, Nothing, OnFinalize, OnUnbalanced, Randomness, WithdrawReasons,
3536
},
@@ -402,12 +403,12 @@ impl pallet_dapp_staking_v3::Config for Runtime {
402403
}
403404

404405
pub struct InflationPayoutPerBlock;
405-
impl pallet_inflation::PayoutPerBlock<NegativeImbalance> for InflationPayoutPerBlock {
406-
fn treasury(reward: NegativeImbalance) {
407-
Balances::resolve_creating(&TreasuryPalletId::get().into_account_truncating(), reward);
406+
impl pallet_inflation::PayoutPerBlock<Credit<AccountId, Balances>> for InflationPayoutPerBlock {
407+
fn treasury(reward: Credit<AccountId, Balances>) {
408+
let _ = Balances::resolve(&TreasuryPalletId::get().into_account_truncating(), reward);
408409
}
409410

410-
fn collators(reward: NegativeImbalance) {
411+
fn collators(reward: Credit<AccountId, Balances>) {
411412
ToStakingPot::on_unbalanced(reward);
412413
}
413414
}
@@ -548,7 +549,7 @@ pub struct ToStakingPot;
548549
impl OnUnbalanced<NegativeImbalance> for ToStakingPot {
549550
fn on_nonzero_unbalanced(amount: NegativeImbalance) {
550551
let staking_pot = PotId::get().into_account_truncating();
551-
Balances::resolve_creating(&staking_pot, amount);
552+
Balances::resolve(&staking_pot, amount);
552553
}
553554
}
554555

runtime/local/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use frame_support::{
2929
genesis_builder_helper::{build_state, get_preset},
3030
parameter_types,
3131
traits::{
32-
fungible::HoldConsideration,
32+
fungible::{Balanced, Credit, HoldConsideration},
3333
tokens::{PayFromAccount, UnityAssetBalanceConversion},
3434
AsEnsureOriginWithArg, ConstU128, ConstU32, ConstU64, Currency, EqualPrivilegeOnly,
3535
FindAuthor, Get, InstanceFilter, LinearStoragePrice, Nothing, OnFinalize, WithdrawReasons,
@@ -500,12 +500,12 @@ impl pallet_dapp_staking_v3::Config for Runtime {
500500
}
501501

502502
pub struct InflationPayoutPerBlock;
503-
impl pallet_inflation::PayoutPerBlock<NegativeImbalance> for InflationPayoutPerBlock {
504-
fn treasury(reward: NegativeImbalance) {
505-
Balances::resolve_creating(&TreasuryPalletId::get().into_account_truncating(), reward);
503+
impl pallet_inflation::PayoutPerBlock<Credit<AccountId, Balances>> for InflationPayoutPerBlock {
504+
fn treasury(reward: Credit<AccountId, Balances>) {
505+
let _ = Balances::resolve(&TreasuryPalletId::get().into_account_truncating(), reward);
506506
}
507507

508-
fn collators(_reward: NegativeImbalance) {
508+
fn collators(_reward: Credit<AccountId, Balances>) {
509509
// no collators for local dev node
510510
}
511511
}

runtime/shibuya/src/lib.rs

+46-42
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ use frame_support::{
3030
genesis_builder_helper::{build_state, get_preset},
3131
parameter_types,
3232
traits::{
33-
fungible::HoldConsideration,
33+
fungible::{Balanced, Credit, HoldConsideration},
3434
tokens::{PayFromAccount, UnityAssetBalanceConversion},
35-
AsEnsureOriginWithArg, ConstU128, ConstU32, ConstU64, Contains, Currency,
36-
EqualPrivilegeOnly, FindAuthor, Get, Imbalance, InstanceFilter, LinearStoragePrice,
37-
Nothing, OnFinalize, OnUnbalanced, WithdrawReasons,
35+
AsEnsureOriginWithArg, ConstU128, ConstU32, ConstU64, Contains, EqualPrivilegeOnly,
36+
FindAuthor, Get, Imbalance, InstanceFilter, LinearStoragePrice, Nothing, OnFinalize,
37+
OnUnbalanced, WithdrawReasons,
3838
},
3939
weights::{
4040
constants::{
4141
BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND,
4242
},
43-
ConstantMultiplier, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients,
44-
WeightToFeePolynomial,
43+
ConstantMultiplier, Weight, WeightToFee as WeightToFeeT, WeightToFeeCoefficient,
44+
WeightToFeeCoefficients, WeightToFeePolynomial,
4545
},
4646
ConsensusEngineId, PalletId,
4747
};
@@ -72,8 +72,8 @@ use sp_runtime::{
7272
};
7373
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
7474
use xcm::{
75-
latest::prelude::*, IntoVersion, VersionedAssetId, VersionedAssets, VersionedLocation,
76-
VersionedXcm,
75+
v4::{AssetId as XcmAssetId, Location as XcmLocation},
76+
IntoVersion, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm,
7777
};
7878
use xcm_fee_payment_runtime_api::Error as XcmPaymentApiError;
7979

@@ -483,12 +483,12 @@ impl pallet_dapp_staking_v3::Config for Runtime {
483483
}
484484

485485
pub struct InflationPayoutPerBlock;
486-
impl pallet_inflation::PayoutPerBlock<NegativeImbalance> for InflationPayoutPerBlock {
487-
fn treasury(reward: NegativeImbalance) {
488-
Balances::resolve_creating(&TreasuryPalletId::get().into_account_truncating(), reward);
486+
impl pallet_inflation::PayoutPerBlock<Credit<AccountId, Balances>> for InflationPayoutPerBlock {
487+
fn treasury(reward: Credit<AccountId, Balances>) {
488+
let _ = Balances::resolve(&TreasuryPalletId::get().into_account_truncating(), reward);
489489
}
490490

491-
fn collators(reward: NegativeImbalance) {
491+
fn collators(reward: Credit<AccountId, Balances>) {
492492
ToStakingPot::on_unbalanced(reward);
493493
}
494494
}
@@ -623,13 +623,11 @@ parameter_types! {
623623
pub TreasuryAccountId: AccountId = TreasuryPalletId::get().into_account_truncating();
624624
}
625625

626-
type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;
627-
628626
pub struct ToStakingPot;
629-
impl OnUnbalanced<NegativeImbalance> for ToStakingPot {
630-
fn on_nonzero_unbalanced(amount: NegativeImbalance) {
627+
impl OnUnbalanced<Credit<AccountId, Balances>> for ToStakingPot {
628+
fn on_nonzero_unbalanced(amount: Credit<AccountId, Balances>) {
631629
let staking_pot = PotId::get().into_account_truncating();
632-
Balances::resolve_creating(&staking_pot, amount);
630+
let _ = Balances::resolve(&staking_pot, amount);
633631
}
634632
}
635633

@@ -795,7 +793,7 @@ impl WeightToFeePolynomial for WeightToFee {
795793
///
796794
/// Similar to standard `WeightToFee` handler, but force uses the minimum multiplier.
797795
pub struct XcmWeightToFee;
798-
impl frame_support::weights::WeightToFee for XcmWeightToFee {
796+
impl WeightToFeeT for XcmWeightToFee {
799797
type Balance = Balance;
800798

801799
fn weight_to_fee(n: &Weight) -> Self::Balance {
@@ -804,8 +802,8 @@ impl frame_support::weights::WeightToFee for XcmWeightToFee {
804802
}
805803

806804
pub struct DealWithFees;
807-
impl OnUnbalanced<NegativeImbalance> for DealWithFees {
808-
fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {
805+
impl OnUnbalanced<Credit<AccountId, Balances>> for DealWithFees {
806+
fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = Credit<AccountId, Balances>>) {
809807
if let Some(fees) = fees_then_tips.next() {
810808
// Burn 80% of fees, rest goes to collator, including 100% of the tips.
811809
let (to_burn, mut collator) = fees.ration(80, 20);
@@ -824,7 +822,7 @@ impl OnUnbalanced<NegativeImbalance> for DealWithFees {
824822

825823
impl pallet_transaction_payment::Config for Runtime {
826824
type RuntimeEvent = RuntimeEvent;
827-
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees>;
825+
type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter<Balances, DealWithFees>;
828826
type WeightToFee = WeightToFee;
829827
type OperationalFeeMultiplier = OperationalFeeMultiplier;
830828
type FeeMultiplierUpdate = TargetedFeeAdjustment<
@@ -930,7 +928,7 @@ impl pallet_evm::Config for Runtime {
930928
// Ethereum-compatible chain_id:
931929
// * Shibuya: 81
932930
type ChainId = EVMChainId;
933-
type OnChargeTransaction = pallet_evm::EVMCurrencyAdapter<Balances, ToStakingPot>;
931+
type OnChargeTransaction = pallet_evm::EVMFungibleAdapter<Balances, ToStakingPot>;
934932
type BlockGasLimit = BlockGasLimit;
935933
type Timestamp = Timestamp;
936934
type OnCreate = ();
@@ -2182,42 +2180,48 @@ impl_runtime_apis! {
21822180
}
21832181

21842182
// Native asset is always supported
2185-
let native_asset_location: Location = Location::try_from(xcm_config::ShibuyaLocation::get())
2183+
let native_asset_location: XcmLocation = XcmLocation::try_from(xcm_config::ShibuyaLocation::get())
21862184
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
21872185

2188-
Ok([VersionedAssetId::V4(native_asset_location).into()]
2189-
.into_iter()
2190-
// Acquire foreign assets which have 'units per second' configured
2191-
.chain(
2192-
pallet_xc_asset_config::AssetLocationUnitsPerSecond::<Runtime>::iter_keys().map(|asset_location| {
2193-
VersionedAssetId::V3(asset_location.into())
2194-
})
2186+
Ok([VersionedAssetId::V4(native_asset_location.into())]
2187+
.into_iter()
2188+
// Acquire foreign assets which have 'units per second' configured
2189+
.chain(
2190+
pallet_xc_asset_config::AssetLocationUnitsPerSecond::<Runtime>::iter_keys().filter_map(|asset_location| {
21952191

2196-
).filter_map(|asset| asset.into_version(xcm_version).ok()))
2192+
match XcmLocation::try_from(asset_location) {
2193+
Ok(asset) => Some(VersionedAssetId::V4(asset.into())),
2194+
Err(_) => None,
2195+
}
2196+
})
2197+
).filter_map(|asset| asset.into_version(xcm_version).ok()).collect())
21972198
}
21982199

2199-
// TODO: improve this function, reduce code duplication, especially on a such functional level
2200+
// TODO: improve this function, reduce code duplication, especially on a such a functional level
22002201
fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
2201-
let native_asset_location: Location = Location::try_from(xcm_config::ShibuyaLocation::get())
2202+
let native_asset_location: XcmLocation = XcmLocation::try_from(xcm_config::ShibuyaLocation::get())
22022203
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
22032204
let native_asset = VersionedAssetId::V4(native_asset_location.into());
22042205

22052206
let asset = asset
22062207
.into_version(4)
22072208
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
22082209

2209-
if native_asset == asset {
2210-
Ok(XcmWeightToFee::weight_to_fee(weight))
2211-
}else {
22122210

2213-
match pallet_xc_asset_config::AssetLocationUnitsPerSecond::<Runtime>::get(asset.into()) {
2214-
Some(units_per_sec) => {
2215-
Ok(units_per_sec.saturating_mul(weight.ref_time() as u128)
2216-
/ (WEIGHT_REF_TIME_PER_SECOND as u128))
2217-
}
2218-
None => Err(XcmPaymentApiError::AssetNotFound),
2211+
if native_asset == asset {
2212+
Ok(XcmWeightToFee::weight_to_fee(&weight))
2213+
} else {
2214+
let asset_id: XcmAssetId = asset.try_into().map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
2215+
let versioned_location = VersionedLocation::V4(asset_id.0);
2216+
2217+
match pallet_xc_asset_config::AssetLocationUnitsPerSecond::<Runtime>::get(versioned_location) {
2218+
Some(units_per_sec) => {
2219+
Ok(units_per_sec.saturating_mul(weight.ref_time() as u128)
2220+
/ (WEIGHT_REF_TIME_PER_SECOND as u128))
22192221
}
2222+
None => Err(XcmPaymentApiError::WeightNotComputable),
22202223
}
2224+
}
22212225
}
22222226

22232227
fn query_xcm_weight(message: VersionedXcm<()>) -> Result<Weight, XcmPaymentApiError> {

runtime/shiden/src/lib.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use frame_support::{
3030
genesis_builder_helper::{build_state, get_preset},
3131
parameter_types,
3232
traits::{
33+
fungible::{Balanced, Credit, HoldConsideration},
3334
AsEnsureOriginWithArg, ConstU32, Contains, Currency, FindAuthor, Get, Imbalance,
3435
InstanceFilter, Nothing, OnFinalize, OnUnbalanced, WithdrawReasons,
3536
},
@@ -442,12 +443,12 @@ impl pallet_dapp_staking_v3::Config for Runtime {
442443
}
443444

444445
pub struct InflationPayoutPerBlock;
445-
impl pallet_inflation::PayoutPerBlock<NegativeImbalance> for InflationPayoutPerBlock {
446-
fn treasury(reward: NegativeImbalance) {
447-
Balances::resolve_creating(&TreasuryPalletId::get().into_account_truncating(), reward);
446+
impl pallet_inflation::PayoutPerBlock<Credit<AccountId, Balances>> for InflationPayoutPerBlock {
447+
fn treasury(reward: Credit<AccountId, Balances>) {
448+
let _ = Balances::resolve(&TreasuryPalletId::get().into_account_truncating(), reward);
448449
}
449450

450-
fn collators(reward: NegativeImbalance) {
451+
fn collators(reward: Credit<AccountId, Balances>) {
451452
ToStakingPot::on_unbalanced(reward);
452453
}
453454
}
@@ -592,7 +593,7 @@ pub struct ToStakingPot;
592593
impl OnUnbalanced<NegativeImbalance> for ToStakingPot {
593594
fn on_nonzero_unbalanced(amount: NegativeImbalance) {
594595
let staking_pot = PotId::get().into_account_truncating();
595-
Balances::resolve_creating(&staking_pot, amount);
596+
Balances::resolve(&staking_pot, amount);
596597
}
597598
}
598599

0 commit comments

Comments
 (0)