Skip to content

protofire/maker-protocol-subgraph

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maker Protocol Subgraph

Made by Protofire.io under GPL-3.0-only License


"The Maker Protocol, also known as the Multi-Collateral Dai (MCD) system, allows users to generate Dai by leveraging collateral assets approved by “Maker Governance."

Took from white paper


Description

This subgraph aims to track the status of the Multi-Collateral DAI (MCD) through multiple contracts.


Data sources

Core Module:

The Core Module is crucial to the system as it contains the entire state of the Maker Protocol and controls the central mechanisms of the system while it is in the expected normal state of operation.

Vault Engine (Vat)

fill me with the description of the contract

handleInit
function init(bytes32 ilk)

Creates new CollateralType

Update the following entities:

  • CollateralType
  • SystemState

The handleInit mapper function receives 1 parameter.

We pick the collateralTypeId from the arg1 then we create the CollateralType record with some default values. Also, we track the collateralType quantity by increasing the field collateralCount on SystemState.

handleFile
function file(bytes32 what, uint data)

function file(bytes32 ilk, bytes32 what, uint data)

Updates CollateralType and SystemState

  • SystemState.totalDebtCeiling
  • CollateralType.debtCeiling
  • CollateralType.vaultDebtFloor

The handleFile mapper function receives a LogNote event as parameter. This handler processes 2 contract functions with the same name file but different arity. We use the signature parameter to split the logic for those contract functions.

handleCage
function cage()

Creates a LiveChangeLog entry for the contract address

handleSlip
function slip(bytes32 ilk, address usr, int256 wad)

Updates Collateral, CollateralType and CollateralChangeLog

  • Collateral.amount
  • CollateralType.totalCollateral
  • CollateralChangeLog.collateralAfter
  • CollateralChangeLog.collateralBefore

The handleSlip mapper function receives a LogNote event as parameter. We pick the collateralTypeId from arg1, user from arg2 and the amount from arg3. Then we update the amount of CollateralType for the user and track the change in time adding an entry on CollateralChangeLog.

handleFlux

Transfers collateral between users

function flux(bytes32 ilk, address src, address dst, uint256 wad)

Updates Collateral and CollateralTransferLog

  • Collateral.amount
  • CollateralTransferLog.amount
  • CollateralTransferLog.src
  • CollateralTransferLog.dst
  • CollateralTransferLog.collateral
  • CollateralTransferLog.direction

The handleFlux mapper function receives a LogNote event as parameter. Here we receive 4 parameters; ilk (the CollateralType id), src (the source User), dst (the destination User) and wad (amount of Collateral) to transfer.

We track the collateral balance of the user by updating a record in the Collateral entity. Then we track the movement by adding a record in the CollateralTransferLog entity.

handleMove

Transfers stablecoin between users

function move(address src, address dst, uint256 rad)

Updates User and DaiMoveLog

  • User.totalVaultDai
  • DaiMoveLog.amount
  • DaiMoveLog.src
  • DaiMoveLog.dst

The handleMove mapper function receives a LogNote event as parameter. We receive 3 parameters; src (source User), dst (destination User) and the rad (the amount of stablecoin) to transfer.

We track the in vault dai of an user by updating field totalVaultDai in User entity. Then we track the movement by adding a record to DaiMoveLog.

handleFrob
function frob(bytes32 i, address u, address v, address w, int dink, int dart)

Creates or updates a Vault

  • CollateralType.unmanagedVaultCount
  • CollateralType.totalCollateral
  • CollateralType.debtNormalized
  • CollateralType.totalDebt
  • SystemState.unmanagedVaultCount
  • Vault.collateral
  • Vault.collateralType
  • Vault.debt
  • Vault.handler
  • Vault.owner
  • VaultCollateralChangeLog
  • VaultDebtChangeLog
  • VaultCreationLog

The handleFrob receives 4 parameters; ilk (collateralTypeId), urn (vaultId), dink (collateral), dart (debt)

if the Vault exist, we update the Vault summing up the collateral and debt otherwise we create the Vault with default values then we track the unmanaged vault by increasing the unmanagedVaultCount field.

handleFork
function fork(bytes32 ilk, address src, address dst, int dink, int dart)

Split a Vault

  • Vault
  • VaultSplitChangeLog

The handleFork function receives 5 parameters; ilk, src, dst, dink, dart

We find the Vaults by using the ilk (collateralTypeId), src (source User) and dst (destination User). Then we move collateral and debt from source Vault to destination Vault.

handleGrab
function grab(bytes32 i, address u, address v, address w, int dink, int dart)

Liquidates a Vault, create/update the following entities:

  • User
  • Vault
  • Collateral
  • CollateralType
  • SystemDebt
  • SystemState

The handleGrab functions receives 6 parameters; i (collateralTypeId), u (urn user), v (liquidator user), w (vow address), dink (collateral), dart (debt)

  • Find or create vault and liquidator users
  • Updates the CollateralType.debtNormalized by summing up the dart (debt)
  • Updates the CollateralType.totalDebt by multipling the dart by the CollateralType.rate
  • Updates Vault.collateral and Vault.debt
  • Updates Collateral.amount for liquidator user
  • Updates SystemDebt.amount
  • Updates SystemState.totalSystemDebt
handleHeal
function heal(uint rad)

Create/destroy equal quantities of stablecoin and system debt

The handleHeal function receives 1 parameter; rad (debt amount)

Update the following entities:

  • User
  • SystemDebt
  • SystemState
handleSuck
function suck(address u, address v, uint rad)

Mint unbacked stablecoin

Update the following entities:

  • User
  • SystemDebt
  • SystemState
handleFold
function fold(bytes32 i, address u, int rate)

Modify the debt multiplier, creating/destroying corresponding debt

Update the following entities:

  • User
  • CollateralType
  • SystemState

Liaison between the Oracles and Core Contracts (Spot)

The Spot liaison between the oracles and the core contracts. It functions as an interface contract and only stores the current ilk list.

handleFile

Creates/Updates the following entities:

  • CollateralPrice
  • SpotParLog
  • CollateralType
  • SystemState

The handleFile mapper function receives a LogNote event as parameter. The handler processes 3 contract functions with the same name file but different arity. We pick arg2 as what parameter to separate the logic.

what = "mat": Updates the liquidationRatio of a CollateralType

what = "pip": Creates a new CollateralPrice and maps it to the corresponding CollateralType

what = "par": Creates the Entity SpotParLog

handlePoke

Creates/Updates the following entities:

  • CollateralPrice
  • CollateralPriceUpdateLog
  • CollateralType

The handlePoke mapper function receives a Poke event as parameter. This event consists of two parameters: the id of the CollateralType (ilk) and the price (val). It creates the entity CollateralPrice. It also updates the price parameter of the CollateralType entity to the newly created CollateralPrice entity.

handleCage

Create the LiveChangeLog entity.

The handleCage function changes the Liveness of the spot contract. It creates the LiveChangeLog Entity to track the changes.

Dai Module:

The DAI token contract and all of the adapters DaiJoin adapters.

Token

fill me with the description of the contract

handleTransfer
handleApproval

Liquidation Module:

The Maker Protocol's Collateral Auction House (Liquidation System 2.0)

DAI Auction Module 2.0 (Clipper)

The Clipper contract is part of the Liquidation 2.0 Module. It is responsible for creating and managing auctions.

handleFile1

Updates:

  • SystemState

The handleFile1 mapper function receives a FileBigIntEvent event as parameter. It updates the SystemState depending on the submitted what parameter in the event. This function updates required parameters by the Clipper contract.

what = "buf": updates saleAuctionStartingPriceFactor

what = "tail": updates saleAuctionResetTime

what = "cusp": updates saleAuctionDropPercentage

what = "chip": updates saleAuctionDaiToRaisePercentage

what = "tip": updates saleAuctionFlatFee

handleFile2

Updates:

  • SystemState

The handleFile2 mapper function receives a FileAddressEvent event as parameter. It updates the SystemState depending on the submitted what parameter in the event. The clipper contract requires other contracts for various functionalities. This function updates the address for required contracts.

what = "spotter": updates saleAuctionSpotterContract

what = "dog": updates saleAuctionDogContract

what = "vow": updates saleAuctionVowContract

what = "calc": updates saleAuctionCalcContract

handleKick

Creates:

  • SaleAuction

The handleKick mapper function receives a KickEvent event as parameter. The contract intiiates an auction by calling the Kick function. Therefore, this function creates the entity SaleAuction with the parameters of the event and sets isActive to true.

handleTake

Updates:

  • SaleAuction

The handleTake mapper function receives a TakeEvent event as parameter. With this function you can buy collateral from the auction indexed by id. If the auction is sold out, it will set isActive to false.

handleRedo

Updates:

  • SaleAuction

The handleRedo mapperfunction receives a RedoEvent event as parameter. The starting price of an auction will be set to the corresponding parameter in the event.

handleYank

Updates:

  • SaleAuction

The handleYank mapperfunction receives a YankEvent event as parameter. This function will mark an auction as deleted by setting isActive to false and the timestamp to deletedAt

Liquidation Contract (Dog)

In the liquidation contract (the Dog), an auction is started promptly to sell the transferred collateral for DAI in an attempt to cancel out the debt now assigned to the protocol.

handleCage

Create the LiveChangeLog entity.

The handleCage function changes the Liveness of the spot contract. It creates the LiveChangeLog Entity to track the changes.

handleDigs

Updates:

  • SystemState
  • CollateralType

The handleDigs function loads the SystemState Entity and substracts the rad (contract parameter) from the totalDaiAmountToCoverDebtAndFees. Afterwards, it updates the Collateraltype and subtracts the rad from the daiAmountToCoverDebtAndFees.

handleFileVow

Updates:

  • SystemState

The handleFileVow functions receives a File1 Event. It updates the address in the parameter dogVowContract when what = "vow".

handleFileHole

Updates:

  • SystemState

The handleFileHole functions receives a File Event. It updates the parameter maxDaiToCoverAuction with the rad value from the submitted data.

handleFileChop

Updates:

  • CollateralType

The handleFileChop functions receives a File2 Event. It updates the parameters of the entity CollateralType according to the provided what parameter.

what = "chop": Updates the parameter liquidationPenalty with the wad value from the submitted data.

what = "hole": Updates the parameter maxDaiToCoverAuction with the rad value from the submitted data.

handleFileClip

Updates:

  • CollateralType

The handleFileClip functions receives a File3 Event. It updates the liquidatorAddress when what = "clip".

handleBark

Updates:

  • SaleAuction
  • CollateralType
  • SystemState

The handleBark functions receives a Bark Event. It liquidates a Vault and start a Dutch auction to sell its collateral for DAI.

SaleAuction: Updates the connection to the Vault and CollateralType entity.

CollateralType: Adds liquidationPenalty * due to the daiAmountToCoverDebtAndFees

SystemState: Adds liquidationPenalty * due to the totalDaiAmountToCoverDebtAndFees

MKR Module:

fill me with the description of the module

fill me (DsToken)

fill me with the description of the contract

handleTransfer
handleApproval
handleMint
handleBurn

Proxy Module:

fill me with the description of the module

Proxy registration (ProxyFactory)

fill me with the description of the contract

handleCreated

Rates Module:

fill me with the description of the module

Accumulation of Stability Fees for Collateral Types (Jug)

fill me with the description of the contract

handleInit
handleDrip
handleFile

The Dai Savings Rate (Pot)

fill me with the description of the contract

handleFile
handleCage
handleJoin
handleExit
handleDrip

System Stabilizer Module:

fill me with the description of the module

Surplus Auction House (Flapper)

fill me with the description of the contract

handleFile
handleCage
handleKick
handleTick
handleDeal
handleTend
handleYank

Debt Auction House (Flopper)

fill me with the description of the contract

handleFile
handleCage
handleKick
handleTick
handleDeal
handleDent
handleYank

Balance Sheet (Vow)

fill me with the description of the contract

handleFile
handleCage
handleFrog
handleFess
handleFlap
handleFlop
handleKiss

Contributors 2

  •  
  •