Overview
This document describes an architecture design of lending plapps (plasma apps). I outlined the specification referring to Dharma project functionalities. Special thanks to @ben-chain for review and thanks to @yuriko.
- Collateralizer(Alice) and Lender(Bob) swap their tokens
- Alice makes her collateral state with token A and swap the collateral for Bob’s token B.
- It means that Bob lent token B to Alice
- Collateral(tokenA) is returned to Alice if the total repayment has been repaid within the grace period.
Architecture
We defined 2 predicates, swap predicate and collateral predicate based on Plasma Group’s specification. You first use swap predicate to set up a collateral. Then, lender will execute collateral predicate.
Swap predicate
This is a setup phase of lending. The debtor makes the collateral state described in the next section and swap it for loaned token.
It’s basically the same design as swap predicate, but collateralizer wants to cancel collateral when a swap fails. Hence, requirements are
- When a swap succeeds, the new state is a collateral state
- When a swap fails, the new state is a simple ownership of collateralizer(Alice)
verifyTransaction
- ensure
witness
is a signature bypreState.data.owner
- If predicate can ensure inclusion of a counter state(loan)
- ensure inclusion of a counter state(loan)
- ensure
postState
is a collateral state
- If predicate can’t ensure inclusion of a counter state
- ensure
postState
has the ownership of collateralizer
- ensure
Collateral predicate
State object specification
struct lendingStateData:
collateralizer: address
lender: address
amount: uint256
grace_period: uint256
Methods
There are 2 methods.
refundCollateral
method
Refund collateral. Lender gets a refund on the collateral after debt enters default.
returnCollateral
method
Collateral is returned to the original collateralizer of the debt agreement.
The collateralizer can get collateral in exchange for the “repayment”.
verifyTransaction
Refund collateral.
- ensure
block.number
is bigger thanpreState.data.grace_period
- ensure
witness
is a signature bypreState.data.lender
- ensure
block.number
is bigger thanpreState.data.grace_period
- ensure
postState.range
has the same amount astransaction.range
- ensure
postState
is a ownership state ofprestate.data.lender
- ensure
- ensure
block.number
is smaller thanpreState.data.grace_period
- ensure
witness
is a signature bypreState.data.collateralizer
(Alice) - ensure “repayment” has valid history
- finalize exit of “repayment” on behalf of lender(Bob)
- or show deprecation of “repayment” by Bob
- ensure “repayment” has the same amount as
preState.data.amount
- ensure
postState.range
has the same amount astransaction.range
- ensure
postState
has the ownership state of collateralizer
- ensure
Questions
- Can Alice use tokenA after the repayment?
I think she can, as far as she proves that her “repayment” is valid. It means recievers of tokenA should verify tokenB’s history. It requires addtional amount of history.
When operator withholds a block, Alice should be able to exit her collateral state. The grace period should be added for its upcoming challenge period.
- Can Bob use tokenA after debt enters default?
Bob can keep using tokenA after its grace period. When Bob attempts to use tokenA maliciously, for example when he (and colluded operator) transfers tokenA to someone before the grace period ends, Alice should be able to exit tokenA as soon as possible.