Skip to content

Payments pallet #691

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

Merged
merged 33 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d044689
Create payments pallet crate
olanod Feb 8, 2022
4f49fa2
sync current version
stanly-johnson Feb 20, 2022
0f98297
sync latest version
stanly-johnson Mar 12, 2022
3d1dfa7
Merge branch 'master' of https://github.com/open-web3-stack/open-runt…
stanly-johnson Mar 12, 2022
0e970e4
remove virto deps
stanly-johnson Mar 12, 2022
36489ac
trigger ci
stanly-johnson Mar 18, 2022
c59bad3
cleanup cargo.toml
stanly-johnson Mar 18, 2022
94756b1
sync latest version
stanly-johnson Mar 19, 2022
86dbb60
cargo fmt
stanly-johnson Mar 20, 2022
36974ca
Reduce clones & Handle state change inconsistencies
olanod Mar 21, 2022
c4ee61e
Merge branch 'master' of https://github.com/open-web3-stack/open-runt…
stanly-johnson Apr 6, 2022
beea72e
udpate to 0.9.18
stanly-johnson Apr 6, 2022
fb40c4e
make orml-tokens dep
stanly-johnson Apr 6, 2022
69428a3
remove remove_task benchmark
stanly-johnson Apr 6, 2022
0377671
review fixes - docs and formatting
stanly-johnson Apr 11, 2022
de2580f
Create payments pallet crate
olanod Feb 8, 2022
fb01b95
sync current version
stanly-johnson Feb 20, 2022
a5b5daf
sync latest version
stanly-johnson Mar 12, 2022
e7a5bd0
remove virto deps
stanly-johnson Mar 12, 2022
7dfbd51
trigger ci
stanly-johnson Mar 18, 2022
669d8c3
cleanup cargo.toml
stanly-johnson Mar 18, 2022
c85d1ec
sync latest version
stanly-johnson Mar 19, 2022
44b802f
cargo fmt
stanly-johnson Mar 20, 2022
dcf30fe
Reduce clones & Handle state change inconsistencies
olanod Mar 21, 2022
19742bc
udpate to 0.9.18
stanly-johnson Apr 6, 2022
29d10b1
review fixes - docs and formatting
stanly-johnson Apr 11, 2022
5977e2b
Merge branch 'master' of https://github.com/open-web3-stack/open-runt…
stanly-johnson Apr 28, 2022
6150284
update to 0.9.19
stanly-johnson Apr 28, 2022
16be330
limit tasks to sort
stanly-johnson Apr 28, 2022
5e76d0c
Merge branch 'multiple-fee-recipients' into payments-pallet
stanly-johnson Apr 28, 2022
dce1f46
Update to polkadot-v0.9.19
olanod Apr 28, 2022
ab44472
Merge branch 'payments-pallet' of github.com:virto-network/open-runti…
stanly-johnson Apr 29, 2022
d6502bc
fix take() limit on read
stanly-johnson Apr 29, 2022
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 change: 1 addition & 0 deletions Cargo.dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ members = [
"build-script-utils",
"weight-gen",
"weight-meter",
"payments"
]

resolver = "2"
Expand Down
40 changes: 40 additions & 0 deletions payments/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[package]
authors = ["Virto Network <[email protected]>"]
edition = '2021'
name = "orml-payments"
version = "0.4.1-dev"
license = "Apache-2.0"
homepage = "https://github.com/virto-network/virto-node"
repository = "https://github.com/virto-network/virto-node"
description = "Allows users to post escrow payment on-chain"
readme = "README.md"

[dependencies]
parity-scale-codec = { version = "3.0.0", default-features = false, features = ["max-encoded-len"] }
log = { version = "0.4.14", default-features = false }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.18", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.18", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.18", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.18", default-features = false }
orml-traits = {path = "../traits", version = "0.4.1-dev", default-features = false }
scale-info = { version = "2.0.1", default-features = false, features = ["derive"] }

[dev-dependencies]
serde = { version = "1.0.136" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.18", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.18", default-features = false }
orml-tokens = { path = "../tokens", version = "0.4.1-dev", default-features = false }

[features]
default = ['std']
std = [
'parity-scale-codec/std',
'frame-support/std',
'frame-system/std',
'log/std',
'sp-runtime/std',
'sp-std/std',
'scale-info/std',
'orml-traits/std',
'orml-tokens/std'
]
85 changes: 85 additions & 0 deletions payments/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Payments Pallet

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.

## Terminology

- Created: A payment has been created and the amount arrived to its destination but it's locked.
- NeedsReview: The payment has bee disputed and is awaiting settlement by a judge.
- IncentivePercentage: A small share of the payment amount is held in escrow until a payment is completed/cancelled. The Incentive Percentage represents this value.
- 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.
- 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.
- CancelBufferBlockLength: This is the time window where the recipient can dispute a cancellation request from the payment creator.

## Interface

#### Events

- `PaymentCreated { from: T::AccountId, asset: AssetIdOf<T>, amount: BalanceOf<T> },`,
- `PaymentReleased { from: T::AccountId, to: T::AccountId }`,
- `PaymentCancelled { from: T::AccountId, to: T::AccountId }`,
- `PaymentCreatorRequestedRefund { from: T::AccountId, to: T::AccountId, expiry: T::BlockNumber}`
- `PaymentRefundDisputed { from: T::AccountId, to: T::AccountId }`
- `PaymentRequestCreated { from: T::AccountId, to: T::AccountId }`
- `PaymentRequestCompleted { from: T::AccountId, to: T::AccountId }`

#### Extrinsics

- `pay` - Create an payment for the given currencyid/amount
- `pay_with_remark` - Create a payment with a remark, can be used to tag payments
- `release` - Release the payment amount to recipent
- `cancel` - Allows the recipient to cancel the payment and release the payment amount to creator
- `resolve_release_payment` - Allows assigned judge to release a payment
- `resolve_cancel_payment` - Allows assigned judge to cancel a payment
- `request_refund` - Allows the creator of the payment to trigger cancel with a buffer time.
- `claim_refund` - Allows the creator to claim payment refund after buffer time
- `dispute_refund` - Allows the recipient to dispute the payment request of sender
- `request_payment` - Create a payment that can be completed by the sender using the `accept_and_pay` extrinsic.
- `accept_and_pay` - Allows the sender to fulfill a payment request created by a recipient

## Implementations

The RatesProvider module provides implementations for the following traits.
- [`PaymentHandler`](./src/types.rs)

## Types

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.

```rust
pub struct PaymentDetail<T: pallet::Config> {
/// type of asset used for payment
pub asset: AssetIdOf<T>,
/// amount of asset used for payment
pub amount: BalanceOf<T>,
/// incentive amount that is credited to creator for resolving
pub incentive_amount: BalanceOf<T>,
/// enum to track payment lifecycle [Created, NeedsReview]
pub state: PaymentState<T::BlockNumber>,
/// account that can settle any disputes created in the payment
pub resolver_account: T::AccountId,
/// fee charged and recipient account details
pub fee_detail: Option<(T::AccountId, BalanceOf<T>)>,
/// remarks to give context to payment
pub remark: Option<BoundedDataOf<T>>,
}
```

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.

```rust
pub enum PaymentState<BlockNumber> {
/// Amounts have been reserved and waiting for release/cancel
Created,
/// A judge needs to review and release manually
NeedsReview,
/// The user has requested refund and will be processed by `BlockNumber`
RefundRequested(BlockNumber),
}
```

## GenesisConfig

The rates_provider pallet does not depend on the `GenesisConfig`

License: Apache-2.0
Loading