Skip to content

RepaymentRouter Specification

Nadav Hollander edited this page Dec 13, 2017 · 2 revisions

Version 0.0.1

Overview

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:

  1. approves the RepaymentRouter contract with an allowance equal to the amount she wishes to repay.
  2. Sends a transaction to the repay method of the RepaymentRouter, 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.

Procedure

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:

  1. The creditor, termsContract, and termsContractParameters associated with the given entryHash are pulled from the DebtRegistry.
  2. The RepaymentRouter calls token.transferFrom(msg.sender, creditor, amount)
  3. The RepaymentRouter calls registerRepayment on the termsContract in order to record the debtor's repayment with the appropriate amount and token address.
  4. The RepaymentRouter emits an event of the following format:
event LogRepayment(
    bytes32 indexed entryHash,
    address indexed from,
    address indexed creditor,
    uint amount,
    address token,
)

Upgrade Procedures

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.

Contract Specifications

DebtRegistry.sol RepaymentRouter.sol

Clone this wiki locally