Skip to content
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
4525073
Fork pallet-balances
ghzlatarev Aug 11, 2023
0fea396
Add barrier code to pallet-balances and update all runtimes
ghzlatarev Aug 11, 2023
6eea3da
Add xcmbarrierlist
ghzlatarev Aug 14, 2023
d096638
Checkpoint
ghzlatarev Aug 14, 2023
685004f
Split to native-barrier pallet. Integrate into pallet-balances. Per d…
ghzlatarev Aug 14, 2023
2eb8660
Support accumulation fo skipped days
ghzlatarev Aug 14, 2023
95f10ed
add to mantapya
ghzlatarev Aug 14, 2023
64a603e
move to orml_traits, add to xtokens and only for native assets
ghzlatarev Aug 14, 2023
351ef1d
Add Here check for native assets
ghzlatarev Aug 15, 2023
2a57473
Uncomment pallet0balances tests and benchs
ghzlatarev Aug 15, 2023
f21f2e6
Re-enable tests and benches for pallet-balances. Add new config to al…
ghzlatarev Aug 15, 2023
4d93c84
Make start_unix_time a configurable storage item
ghzlatarev Aug 15, 2023
ff00649
add setter extrinsics for storage items
ghzlatarev Aug 15, 2023
457ea32
Clean up native-barrier pallet toml, delete unnecessary fiels and upd…
ghzlatarev Aug 15, 2023
117c7d7
add events
ghzlatarev Aug 15, 2023
aaec2ba
add gensis config, clean up
ghzlatarev Aug 15, 2023
4b59705
Debugging
ghzlatarev Aug 16, 2023
3b23239
Remove xcmnativetransfers storage item, only remainingxcmlimit is nee…
ghzlatarev Aug 16, 2023
4764e74
Merge branch 'manta' into ghzlatarev/whale-blocker
ghzlatarev Aug 16, 2023
d554ccf
fmt and remove unnecessary imports
ghzlatarev Aug 16, 2023
cde01c1
Change headers
ghzlatarev Aug 16, 2023
744b134
storage docs
ghzlatarev Aug 16, 2023
785982a
remove unnecessary error
ghzlatarev Aug 16, 2023
53f808c
fix errors docs
ghzlatarev Aug 16, 2023
e9997fe
Clean up
ghzlatarev Aug 16, 2023
527e202
Extrinsics docs
ghzlatarev Aug 16, 2023
9681f15
Events docs , add remove from barrier event and use iter() instead of…
ghzlatarev Aug 16, 2023
297177d
Clean up todos
ghzlatarev Aug 16, 2023
eb186c3
Clean up todos in native-barrier pallet
ghzlatarev Aug 16, 2023
c0444e8
fmt
ghzlatarev Aug 16, 2023
ff92613
Add native-barrier benchmak code
ghzlatarev Aug 17, 2023
ba1fc94
Add benchamrk unit tests and add to runtimes
ghzlatarev Aug 17, 2023
9745b79
Add on_initialize benchmark and generate weight file in pallet
ghzlatarev Aug 17, 2023
2e0760b
Add weights file to runtiems
ghzlatarev Aug 17, 2023
24a19b4
First tests
ghzlatarev Aug 17, 2023
548d679
tests work
ghzlatarev Aug 18, 2023
6f8d87b
Clean up tests
ghzlatarev Aug 18, 2023
b576761
clean up warnins
ghzlatarev Aug 18, 2023
c3cf148
remove palle-tteimestamp
ghzlatarev Aug 18, 2023
c5c23bc
Simlify reset_remaining_xcm_limit
ghzlatarev Aug 18, 2023
673d526
storage version should be 0
ghzlatarev Aug 18, 2023
e84bda8
fmt'
ghzlatarev Aug 18, 2023
b25ca88
Disab le clippy for balances and fix for rest
ghzlatarev Aug 18, 2023
c35ac80
add comments and improve asserts in benchmark code
ghzlatarev Aug 18, 2023
22e647a
Use 0937 orml branch
ghzlatarev Aug 18, 2023
08507a9
add limits growth test
ghzlatarev Aug 20, 2023
bc4c9f9
Clean up tests
ghzlatarev Aug 20, 2023
7696701
Revert ignore
ghzlatarev Aug 21, 2023
4080b84
add docs
ghzlatarev Aug 21, 2023
522f071
check all pallet-balances extriniscs in tests
ghzlatarev Aug 21, 2023
a85095c
Remove extra daily limit
ghzlatarev Aug 22, 2023
0bbe97f
Delete geneiss config unused code
ghzlatarev Aug 22, 2023
def99a5
Update storage
ghzlatarev Aug 22, 2023
bc4abe6
Update index'
ghzlatarev Aug 22, 2023
f320489
remove xcm mentions 1/2
ghzlatarev Aug 22, 2023
7f57ad6
remove xmc mentions 2/2
ghzlatarev Aug 22, 2023
ce5937a
Merge branch 'manta' into ghzlatarev/whale-blocker
ghzlatarev Aug 22, 2023
4643f3f
Clean up
ghzlatarev Aug 22, 2023
a95fdda
Clippy
ghzlatarev Aug 22, 2023
e9c3f20
Update tx-fees diff files
ghzlatarev Aug 23, 2023
80d4e79
Merge branch 'manta' into ghzlatarev/whale-blocker
ghzlatarev Aug 23, 2023
69da06f
Merge branch 'manta' into ghzlatarev/whale-blocker
ghzlatarev Aug 24, 2023
de34377
Udpate lastdayprocessed on init
ghzlatarev Aug 29, 2023
b9a420c
add accounts to initialize barrier extrinsic
ghzlatarev Aug 30, 2023
b8e22e1
Revert last commit and addd default daily_limit on initialization again
ghzlatarev Aug 30, 2023
290c2af
Update the in the future tests as well
ghzlatarev Aug 30, 2023
5f645cb
Merfe conflicts and update weights
ghzlatarev Aug 30, 2023
74f8f46
Fix benchmarking compile
ghzlatarev Aug 30, 2023
51f9320
Ignore diff_tx-Fees tests temporarily
ghzlatarev Aug 30, 2023
c92c446
Unignore test and update fees csv
ghzlatarev Aug 30, 2023
9a38533
Bump manta integrations test timeout
ghzlatarev Aug 31, 2023
a335a24
Use orml branch for now
ghzlatarev Aug 31, 2023
da094d8
update cargo lock
ghzlatarev Aug 31, 2023
d3b705d
Update orml dep
ghzlatarev Aug 31, 2023
4426549
Merge branch 'manta' into ghzlatarev/whale-blocker
ghzlatarev Sep 30, 2023
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
154 changes: 115 additions & 39 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pallets/asset-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ sp-std = { git = "https://github.com/paritytech/substrate.git", branch = "polkad
xcm = { git = "https://github.com/paritytech/polkadot.git", default-features = false, branch = "release-v0.9.37" }

# 3rd party dependencies
orml-traits = { git = "https://github.com/manta-network/open-runtime-module-library.git", default-features = false, branch = "polkadot-v0.9.37" }
orml-traits = { git = "https://github.com/manta-network/open-runtime-module-library.git", default-features = false, branch = "ghzlatarev/polkadot-v0.9.37" }

[dev-dependencies]
pallet-assets = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
pallet-balances = { path = "../balances" }
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }

Expand Down
18 changes: 18 additions & 0 deletions pallets/asset-manager/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ impl pallet_assets::Config for Runtime {
type BenchmarkHelper = ();
}

pub struct MockNativeBarrier;
impl orml_traits::xcm_transfer::NativeBarrier<AccountId, Balance> for MockNativeBarrier {
fn update_xcm_native_transfers(_account_id: &AccountId, _amount: Balance) {}
fn ensure_xcm_transfer_limit_not_exceeded(
_account_id: &AccountId,
_amount: Balance,
) -> frame_support::dispatch::DispatchResult {
Ok(())
}
}

impl orml_traits::xcm_transfer::NativeChecker<u64> for MockNativeBarrier {
fn is_native(_currency_id: &u64) -> bool {
true
}
}

parameter_types! {
pub ExistentialDeposit: Balance = 1;
pub const MaxLocks: u32 = 50;
Expand All @@ -125,6 +142,7 @@ impl pallet_balances::Config for Runtime {
type WeightInfo = ();
type MaxReserves = MaxReserves;
type ReserveIdentifier = [u8; 8];
type NativeBarrierType = MockNativeBarrier;
}

pub struct MantaAssetRegistry;
Expand Down
48 changes: 48 additions & 0 deletions pallets/balances/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[package]
name = "pallet-balances"
version = "4.0.0-dev"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"
license = "Apache-2.0"
homepage = "https://substrate.io"
repository = "https://github.com/paritytech/substrate/"
description = "FRAME pallet to manage balances"
readme = "README.md"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "max-encoded-len"] }
log = { version = "0.4.17", default-features = false }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
frame-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37", default-features = false, optional = true }
frame-support = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.37" }
frame-system = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.37" }
sp-runtime = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.37" }
sp-std = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.37" }

pallet-native-barrier = { path = '../native-barrier', default-features = false }
orml-traits = { git = 'https://github.com/manta-network/open-runtime-module-library.git', default-features = false, branch = "ghzlatarev/polkadot-v0.9.37" }

[dev-dependencies]
pallet-transaction-payment = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.37" }
sp-core = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.37" }
sp-io = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.37" }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"log/std",
"scale-info/std",
"sp-runtime/std",
"sp-std/std",
"pallet-native-barrier/std",
"orml-traits/std"
]
runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"]
try-runtime = ["frame-support/try-runtime", "pallet-native-barrier/try-runtime"]
122 changes: 122 additions & 0 deletions pallets/balances/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Balances Module

The Balances module provides functionality for handling accounts and balances.

- [`Config`](https://docs.rs/pallet-balances/latest/pallet_balances/pallet/trait.Config.html)
- [`Call`](https://docs.rs/pallet-balances/latest/pallet_balances/pallet/enum.Call.html)
- [`Pallet`](https://docs.rs/pallet-balances/latest/pallet_balances/pallet/struct.Pallet.html)

## Overview

The Balances module provides functions for:

- Getting and setting free balances.
- Retrieving total, reserved and unreserved balances.
- Repatriating a reserved balance to a beneficiary account that exists.
- Transferring a balance between accounts (when not reserved).
- Slashing an account balance.
- Account creation and removal.
- Managing total issuance.
- Setting and managing locks.

### Terminology

- **Existential Deposit:** The minimum balance required to create or keep an account open. This prevents
"dust accounts" from filling storage. When the free plus the reserved balance (i.e. the total balance)
fall below this, then the account is said to be dead; and it loses its functionality as well as any
prior history and all information on it is removed from the chain's state.
No account should ever have a total balance that is strictly between 0 and the existential
deposit (exclusive). If this ever happens, it indicates either a bug in this module or an
erroneous raw mutation of storage.

- **Total Issuance:** The total number of units in existence in a system.

- **Reaping an account:** The act of removing an account by resetting its nonce. Happens after its
total balance has become zero (or, strictly speaking, less than the Existential Deposit).

- **Free Balance:** The portion of a balance that is not reserved. The free balance is the only
balance that matters for most operations.

- **Reserved Balance:** Reserved balance still belongs to the account holder, but is suspended.
Reserved balance can still be slashed, but only after all the free balance has been slashed.

- **Imbalance:** A condition when some funds were credited or debited without equal and opposite accounting
(i.e. a difference between total issuance and account balances). Functions that result in an imbalance will
return an object of the `Imbalance` trait that can be managed within your runtime logic. (If an imbalance is
simply dropped, it should automatically maintain any book-keeping such as total issuance.)

- **Lock:** A freeze on a specified amount of an account's free balance until a specified block number. Multiple
locks always operate over the same funds, so they "overlay" rather than "stack".

### Implementations

The Balances module provides implementations for the following traits. If these traits provide the functionality
that you need, then you can avoid coupling with the Balances module.

- [`Currency`](https://docs.rs/frame-support/latest/frame_support/traits/trait.Currency.html): Functions for dealing with a
fungible assets system.
- [`ReservableCurrency`](https://docs.rs/frame-support/latest/frame_support/traits/trait.ReservableCurrency.html):
Functions for dealing with assets that can be reserved from an account.
- [`LockableCurrency`](https://docs.rs/frame-support/latest/frame_support/traits/trait.LockableCurrency.html): Functions for
dealing with accounts that allow liquidity restrictions.
- [`Imbalance`](https://docs.rs/frame-support/latest/frame_support/traits/trait.Imbalance.html): Functions for handling
imbalances between total issuance in the system and account balances. Must be used when a function
creates new funds (e.g. a reward) or destroys some funds (e.g. a system fee).
- [`IsDeadAccount`](https://docs.rs/frame-support/latest/frame_support/traits/trait.IsDeadAccount.html): Determiner to say whether a
given account is unused.

## Interface

### Dispatchable Functions

- `transfer` - Transfer some liquid free balance to another account.
- `set_balance` - Set the balances of a given account. The origin of this call must be root.

## Usage

The following examples show how to use the Balances module in your custom module.

### Examples from the FRAME

The Contract module uses the `Currency` trait to handle gas payment, and its types inherit from `Currency`:

```rust
use frame_support::traits::Currency;

pub type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
pub type NegativeImbalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;

```

The Staking module uses the `LockableCurrency` trait to lock a stash account's funds:

```rust
use frame_support::traits::{WithdrawReasons, LockableCurrency};
use sp_runtime::traits::Bounded;
pub trait Config: frame_system::Config {
type Currency: LockableCurrency<Self::AccountId, Moment=Self::BlockNumber>;
}

fn update_ledger<T: Config>(
controller: &T::AccountId,
ledger: &StakingLedger<T>
) {
T::Currency::set_lock(
STAKING_ID,
&ledger.stash,
ledger.total,
WithdrawReasons::all()
);
// <Ledger<T>>::insert(controller, ledger); // Commented out as we don't have access to Staking's storage here.
}
```

## Genesis config

The Balances module depends on the [`GenesisConfig`](https://docs.rs/pallet-balances/latest/pallet_balances/pallet/struct.GenesisConfig.html).

## Assumptions

* Total issued balanced of all accounts should be less than `Config::Balance::max_value()`.

License: Apache-2.0
Loading