-
Notifications
You must be signed in to change notification settings - Fork 47
RepaymentRouter Specification
Version 0.0.1
The RepaymentRouter contract is responsible for facilitating repayments between debtors and creditors and recording those repayments in a debt's associated terms contract. If a debtor wishes to make a repayment, she does two things:
-
approves theRepaymentRoutercontract with an allowance equal to the amount she wishes to repay. - Sends a transaction to the
repaymethod of theRepaymentRouter, which transfers her repayment amount to the creditor and registers the repayment with the debt's associated terms contract.
The reason we leverage this construction (in lieu of, say, having debtors repay creditors directly) is so that repayments can be trustlessly tracked in the terms contract associated with any given debt. By having every repayment be routed by a single smart contract, terms contracts can keep track of any debt's repayment status on a highly granular basis. Without a central routing mechanism, it would be highly impractical for a smart contract to verify that repayments have / have not occurred in the context of any given debt agreement.
A RepaymentRouter implementation needs to expose the following method signature:
function repay(bytes32 entryHash, uint amount, address token) public;When repay is called, the following must happen:
- The
creditor,termsContract, andtermsContractParametersassociated with the givenentryHashare pulled from theDebtRegistry. - The
RepaymentRoutercallstoken.transferFrom(msg.sender, creditor, amount) - The
RepaymentRoutercallsregisterRepaymenton thetermsContractin order to record the debtor's repayment with the appropriateamountandtokenaddress. - The
RepaymentRouteremits an event of the following format:
event LogRepayment(
bytes32 indexed entryHash,
address indexed from,
address indexed creditor,
uint amount,
address token,
)If the RepaymentRouter needs to be upgraded (either because the terms contract interface has been updated, or for any other reasons), we simply deploy a new RepaymentRouter contract and add its address to the DebtKernel's registry of trusted repayment routing contracts. Since a borrower determines the repayment router's address by retrieving the version field from the DebtRegistry, we simply need to add the new contract's address to the list of version field values the DebtKernel permits. No logic needs to be implemented in the RepaymentRouter itself in order to facilitate this.
Dharma is a generic protocol for tokenized debt issuance. We are committed to building permissionless, non-rent seeking infrastructure for the credit markets of tomorrow. Backed by YCombinator, Polychain Capital, Green Visor Capital, and others.