function transferCollateral(uint dealID) public payable {
    REPODeal storage deal = deals[dealID];
    require(deal.state == 1);
    require(block.number < deal.collateralUntil);
    require(msg.sender == deal.lender);

    uint payment = deal.collateralAmount + deal.lenderFee;
    if (deal.collateral == 0) {
      require(msg.value == payment);
      require(deal.borrower.send(deal.collateralAmount));
      require(owner.send(deal.lenderFee));
    } else {
      require(ERC20(deal.collateral).transferFrom(msg.sender, deal.borrower, deal.collateralAmount));
      require(ERC20(deal.collateral).transferFrom(msg.sender, owner, deal.lenderFee));
    }

    sendGoods(deal.pledge, owner, deal.borrowerFee);

    deal.state = 2;
    CollateralTransfered(dealID);
  }