Skip to content

Commit 67f4a79

Browse files
Payments pallet (#691)
* Create payments pallet crate * sync current version * sync latest version * remove virto deps * trigger ci * cleanup cargo.toml * sync latest version * cargo fmt * Reduce clones & Handle state change inconsistencies * udpate to 0.9.18 * make orml-tokens dep * remove remove_task benchmark * review fixes - docs and formatting * Create payments pallet crate * sync current version * sync latest version * remove virto deps * trigger ci * cleanup cargo.toml * sync latest version * cargo fmt * Reduce clones & Handle state change inconsistencies * udpate to 0.9.18 * review fixes - docs and formatting * update to 0.9.19 * limit tasks to sort * Update to polkadot-v0.9.19 * fix take() limit on read Co-authored-by: Stanly Johnson <[email protected]>
1 parent 23f7092 commit 67f4a79

File tree

8 files changed

+2675
-0
lines changed

8 files changed

+2675
-0
lines changed

Cargo.dev.toml

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ members = [
2222
"build-script-utils",
2323
"weight-gen",
2424
"weight-meter",
25+
"payments"
2526
]
2627

2728
resolver = "2"

payments/Cargo.toml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[package]
2+
authors = ["Virto Network <[email protected]>"]
3+
edition = '2021'
4+
name = "orml-payments"
5+
version = "0.4.1-dev"
6+
license = "Apache-2.0"
7+
homepage = "https://github.com/virto-network/virto-node"
8+
repository = "https://github.com/virto-network/virto-node"
9+
description = "Allows users to post escrow payment on-chain"
10+
readme = "README.md"
11+
12+
[dependencies]
13+
parity-scale-codec = { version = "3.1.2", default-features = false, features = ["max-encoded-len"] }
14+
log = { version = "0.4.14", default-features = false }
15+
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.19", default-features = false }
16+
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.19", default-features = false }
17+
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.19", default-features = false }
18+
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.19", default-features = false }
19+
orml-traits = {path = "../traits", version = "0.4.1-dev", default-features = false }
20+
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
21+
22+
[dev-dependencies]
23+
serde = { version = "1.0.136" }
24+
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.19", default-features = false }
25+
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.19", default-features = false }
26+
orml-tokens = { path = "../tokens", version = "0.4.1-dev", default-features = false }
27+
28+
[features]
29+
default = ['std']
30+
std = [
31+
'parity-scale-codec/std',
32+
'frame-support/std',
33+
'frame-system/std',
34+
'log/std',
35+
'sp-runtime/std',
36+
'sp-std/std',
37+
'scale-info/std',
38+
'orml-traits/std',
39+
'orml-tokens/std'
40+
]

payments/README.md

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Payments Pallet
2+
3+
This pallet allows users to create secure reversible payments that keep funds locked in a merchant's account until the off-chain goods are confirmed to be received. Each payment gets assigned its own *judge* that can help resolve any disputes between the two parties.
4+
5+
## Terminology
6+
7+
- Created: A payment has been created and the amount arrived to its destination but it's locked.
8+
- NeedsReview: The payment has bee disputed and is awaiting settlement by a judge.
9+
- IncentivePercentage: A small share of the payment amount is held in escrow until a payment is completed/cancelled. The Incentive Percentage represents this value.
10+
- Resolver Account: A resolver account is assigned to every payment created, this account has the privilege to cancel/release a payment that has been disputed.
11+
- Remark: The pallet allows to create payments by optionally providing some extra(limited) amount of bytes, this is reffered to as Remark. This can be used by a marketplace to seperate/tag payments.
12+
- CancelBufferBlockLength: This is the time window where the recipient can dispute a cancellation request from the payment creator.
13+
14+
## Interface
15+
16+
#### Events
17+
18+
- `PaymentCreated { from: T::AccountId, asset: AssetIdOf<T>, amount: BalanceOf<T> },`,
19+
- `PaymentReleased { from: T::AccountId, to: T::AccountId }`,
20+
- `PaymentCancelled { from: T::AccountId, to: T::AccountId }`,
21+
- `PaymentCreatorRequestedRefund { from: T::AccountId, to: T::AccountId, expiry: T::BlockNumber}`
22+
- `PaymentRefundDisputed { from: T::AccountId, to: T::AccountId }`
23+
- `PaymentRequestCreated { from: T::AccountId, to: T::AccountId }`
24+
- `PaymentRequestCompleted { from: T::AccountId, to: T::AccountId }`
25+
26+
#### Extrinsics
27+
28+
- `pay` - Create an payment for the given currencyid/amount
29+
- `pay_with_remark` - Create a payment with a remark, can be used to tag payments
30+
- `release` - Release the payment amount to recipent
31+
- `cancel` - Allows the recipient to cancel the payment and release the payment amount to creator
32+
- `resolve_release_payment` - Allows assigned judge to release a payment
33+
- `resolve_cancel_payment` - Allows assigned judge to cancel a payment
34+
- `request_refund` - Allows the creator of the payment to trigger cancel with a buffer time.
35+
- `claim_refund` - Allows the creator to claim payment refund after buffer time
36+
- `dispute_refund` - Allows the recipient to dispute the payment request of sender
37+
- `request_payment` - Create a payment that can be completed by the sender using the `accept_and_pay` extrinsic.
38+
- `accept_and_pay` - Allows the sender to fulfill a payment request created by a recipient
39+
40+
## Implementations
41+
42+
The RatesProvider module provides implementations for the following traits.
43+
- [`PaymentHandler`](./src/types.rs)
44+
45+
## Types
46+
47+
The `PaymentDetail` struct stores information about the payment/escrow. A "payment" in virto network is similar to an escrow, it is used to guarantee proof of funds and can be released once an agreed upon condition has reached between the payment creator and recipient. The payment lifecycle is tracked using the state field.
48+
49+
```rust
50+
pub struct PaymentDetail<T: pallet::Config> {
51+
/// type of asset used for payment
52+
pub asset: AssetIdOf<T>,
53+
/// amount of asset used for payment
54+
pub amount: BalanceOf<T>,
55+
/// incentive amount that is credited to creator for resolving
56+
pub incentive_amount: BalanceOf<T>,
57+
/// enum to track payment lifecycle [Created, NeedsReview]
58+
pub state: PaymentState<T::BlockNumber>,
59+
/// account that can settle any disputes created in the payment
60+
pub resolver_account: T::AccountId,
61+
/// fee charged and recipient account details
62+
pub fee_detail: Option<(T::AccountId, BalanceOf<T>)>,
63+
/// remarks to give context to payment
64+
pub remark: Option<BoundedDataOf<T>>,
65+
}
66+
```
67+
68+
The `PaymentState` enum tracks the possible states that a payment can be in. When a payment is 'completed' or 'cancelled' it is removed from storage and hence not tracked by a state.
69+
70+
```rust
71+
pub enum PaymentState<BlockNumber> {
72+
/// Amounts have been reserved and waiting for release/cancel
73+
Created,
74+
/// A judge needs to review and release manually
75+
NeedsReview,
76+
/// The user has requested refund and will be processed by `BlockNumber`
77+
RefundRequested(BlockNumber),
78+
}
79+
```
80+
81+
## GenesisConfig
82+
83+
The rates_provider pallet does not depend on the `GenesisConfig`
84+
85+
License: Apache-2.0

0 commit comments

Comments
 (0)