virto-network / virto-node

Virto Network blockchain node.
GNU General Public License v3.0
21 stars 10 forks source link

Generalized payment release strategy #367

Open olanod opened 7 months ago

olanod commented 7 months ago

I propose generalizing the way how payments are released to the beneficiary.

The core feature of payments pallet is being able to hold funds until the sender is satisfied with an event happening off-chain(e.g. when receiving goods). To support more use cases, like when there is more trust between paying parties that conduct businesses regularly, an automated way to release funds progressively becomes very useful.

We can add a parameter to pay that accepts the "release strategy" represented as an enum.

enum Release<T> {
    // Beneficiary must call `release` manually this many times
    // `Release::Manual(1)` matches current behavior
    Manual(NonZeroU8),
    // Whenever beneficiary calls (new)`claim` it can unlock up to the amount that the schedule allows
    // E.g:
    // `Release::Auto{ duration: "30day".into(), start: "-10day".into(), initial: 5 }`
    // A payment of `100 abc` the 10th of the month would on day 0 have 5% of the total amount unlocked
    // the remaining 95% is split evenly along the duration, calling `claim` right after the creation
    // would unlock 10 days worth of pay(on top of the 5%) 
    Auto {
        duration: BlockNumberOf<T>,
        start: i32, // relative to the time of creation to allow tx to be resubmitted without changes
        initial: Percent,
    }
}
olanod commented 7 months ago

NOTE: We use request_refund to cancel from the sender perspective and cancel for beneficiaries to return funds immediately, with the updated release strategy the semantics of "request refund" change, for simplicity I think we can deprecate request_refund and have only cancel for both sender and beneficiary.