molecula451 / QuickBorrow

Borrow tokens simply by sending Ether

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

QuickBorrow

Rinkeby Deployment

This is a sample implementation of how to interact with the Compound Money Market from within the EVM. There are two main smart contracts: TokenBorrowerFactory.sol and CDP.sol

The TokenBorrowerFactory is configured by it's constructor, which takes 3 arguments. deployment example

constructor(address weth, address _token, address moneyMarket)

fallback()

  • looks up or creates new cdp for msg.sender
  • forwards ether to cdp and calls "fund" ( This is where the magic happens ).

repay()

  • looks up cdp for msg.sender
  • transfers tokens to cdp ( previously allowed by msg.sender interacting with token contract )
  • calls cdp.repay()

constructor(address _owner, address tokenAddress, address wethAddress, address moneyMarketAddress)

  • owner: who to send any borrowed tokens or withdrawn ether to
  • tokenAddress: address of token to borrow from compound
  • wethAddress: where to wrap and unwrap ether
  • moneyMarketAddress: where to find Compound
  • also approves transfers of weth and configured token

fund()

  • wraps any ether sent
  • deposits it as weth
  • supplies that weth to Compound Money Market
  • borrows configured token
  • sends borrowed tokens back to the user

repay()

  • repays borrowed tokens
  • withdraws any excess collateral
  • sends withdrawn eth back to user

All of these operations will maintain a supply value / borrow value ratio which is equal to the required collateralRatio set in the Compound Money Market + 25%.

Contains function signatures of the Compound Money Market that are needed to implement QuickBorrow. Not a full specification of the Compound Money Market interface.

Test environment Mocks

example test environment deployment

Contains trivial implementations of the Compound Money Market Functions, as well as some cheat mode admin functions to facilitate setting up unit tests.

basic erc 20 token with some admin functions to set up unit tests

wrapped ether implementation with some admin functions to set up unit tests

About

Borrow tokens simply by sending Ether


Languages

Language:JavaScript 100.0%