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."
This subgraph aims to track the status of the Multi-Collateral DAI (MCD) through multiple contracts.
-
_ Must be placed in the same level directory as dss deploy scripts
-
_ Dss deploy scripts must have contracts. json present
-
_ If you need to update mainnet information, there must be dss deploy scripts/out/{the network you entered}}/addresses. json present
-
_ Modify the IP in package.json
yarn
1. Initialize subgraph. yaml and contract abi
./InitConfig.sh initNetworkData mainnet
./InitConfig.sh initNetworkData testchain
./InitConfig.sh initABI mainnet
Fill the contract address and block height into subgraph. yaml
yarn fix-network:testchain / mainnet
2. Start the graph node in the docker first
cd docker && ./ run_ graph_ node.sh init
3. Compilation contract
yarn codegen
yarn build
4. Deploy subgraph on graph node
yarn create-local
yarn deploy-local
.clean
Yarn remove local Delete subgraph in graph node
Yarn clean cleans up all generated files
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.
fill me with the description of the contract
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.
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.
function cage()
Creates a LiveChangeLog entry for the contract address
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.
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.
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.
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.
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.
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
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
function suck(address u, address v, uint rad)
Mint unbacked stablecoin
Update the following entities:
- User
- SystemDebt
- SystemState
function fold(bytes32 i, address u, int rate)
Modify the debt multiplier, creating/destroying corresponding debt
Update the following entities:
- User
- CollateralType
- SystemState
The Spot liaison between the oracles and the core contracts. It functions as an interface contract and only stores the current ilk list.
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
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.
Create the LiveChangeLog entity.
The handleCage function changes the Liveness of the spot contract. It creates the LiveChangeLog Entity to track the changes.
The DAI token contract and all of the adapters DaiJoin adapters.
fill me with the description of the contract
The Maker Protocol's Collateral Auction House (Liquidation System 2.0)
The Clipper contract is part of the Liquidation 2.0 Module. It is responsible for creating and managing auctions.
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
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
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.
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.
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.
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
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.
Create the LiveChangeLog entity.
The handleCage function changes the Liveness of the spot contract. It creates the LiveChangeLog Entity to track the changes.
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.
Updates:
- SystemState
The handleFileVow functions receives a File1 Event. It updates the address in the parameter dogVowContract when what = "vow".
Updates:
- SystemState
The handleFileHole functions receives a File Event. It updates the parameter maxDaiToCoverAuction with the rad value from the submitted data.
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.
Updates:
- CollateralType
The handleFileClip functions receives a File3 Event. It updates the liquidatorAddress when what = "clip".
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
fill me with the description of the module
fill me with the description of the contract
fill me with the description of the module
fill me with the description of the contract
fill me with the description of the module
The primary function of the Jug smart contract is to accumulate stability fees for a particular collateral type whenever its drip() method is called.
Updates:
- CollateralType
Fetches the CollateralType according to arg1, sets stabilityFee to '1' and stabilityFeeUpdateAt to the timestamp of the block.
Updates:
- CollateralType
Updates the stabilityFeeUpdatedAt of the CollateralType.
Updates:
- SystemState
- ColllateralType
Updates variables according to the what variable.
what="duty": Updates CollateralType.stabilityFee to the Ray value from data.
what="base": Updates SystemState.baseStabilityFee to the Ray value from data.
what="vow": Updates SystemState.jugVowContract to the Address from data.
The Pot is the core of theDai Savings Rate. It allows users to deposit dai and activate the Dai Savings Rate and earning savings on their dai.
Updates:
- SystemState
Updates the SystemState according to the what variable.
what="dsr": Updates SystemState.savingsRate with the Ray value from data.
what="vow": Updates SystemState.potVowContract with the value from data.
Creates:
- LiveChangeLog
Updates:
- SystemState
Updates the SystemState.savingsRate to 1 and creates a new LiveChangeLog.
Updates:
- User
- SystemState
Adds the WDA value arg1 to User.savings and SystemState.totalSavingsInPot. The Subgraph will update these values according to the result.
Updates:
- User
- SystemState
Substracts the WDA value arg1 from User.savings and SystemState.totalSavingsInPot. The Subgraph will update these values according to the result.
Updates:
- SystemState
Binds the Pot contract to get the chi value from the contract. Afterwards, the subgraph will update SystemState.rateAccumulator with the resultvalue and sets SystemState.lastPotDripAt to the timestamp of the block.
fill me with the description of the module
Flapper is a Surplus Auction. These auctions are used to auction off a fixed amount of the surplus Dai in the system for MKR. This surplus Dai will come from the Stability Fees that are accumulated from Vaults. In this auction type, bidders compete with increasing amounts of MKR. Once the auction has ended, the Dai auctioned off is sent to the winning bidder. The system then burns the MKR received from the winning bid.
Updates:
- SystemState
Updates SystemState according to the what value.
what="beg": Updates surplusAuctionMinimumBidIncrease to the WAD value from data.
what="ttl": Updates surplusAuctionBidDuration to the value from data.
what="tau": Updates surplusAuctionDuration to the value from data.
Creates:
- LiveChangeLog
Creates the LiveChangeLog event with the required values.
Updates:
- SystemState
- SurplusAuction
Updates bidAmount, quantity, highestBidder from the SurplusAuction entities to the values from the event and sets active to true. If SystemState.surplusAuctionBidDuration is set, it will add the block timestamp to this value.
Updates:
- SurplusAuction
Sets SurplusAuction.endTimeAt to the timestamp of the block and adds SystemState.surplusAuctionBidDuration to it
Updates:
- SurplusAuction
Sets the highestBidder to the transaction creator.
Updates:
- SurplusAuction
Sets the highestBidder to the transaction creator and updates the bidAmount to Int value of arg2.
Updates:
- SurplusAuction
Deactivates (active=false) the SurplusAuction and sets the deletedAt variable.
Debt Auctions are used to recapitalize the system by auctioning off MKR for a fixed amount of DAI. In this process, bidders compete by offering to accept decreasing amounts of MKR for the DAI they will end up paying.
Updates:
- SystemSate
Updates the SystemSate according to the what value.
what="beg": Updates debtAuctionMinimumBidIncrease to the WAD value from data.
what="pad": Updates debtAuctionLotSizeIncrease to the WAD value from data.
what="ttl": Updates debtAuctionBidDuration to the value from data.
what="tau": Updates debtAuctionDuration to the value from data.
Creates:
- LiveChangeLog
Creates the entity LiveChangeLog
Updates:
- DebtAuction
Receives a Kick event as input. Sets bidAmount to the bid value, quantity to the lot value and hgihestBidder to the gal value from the event. Sets the endTimeAt to the timestamp of the block plus SystemState.debtAuctionBidDuration.
Updates:
- DebtAuction
Calculates SystemState.debtAuctionLotSizeIncrease * auction.quantity (lot in the contract), converts the result to WAD and sets it to DebtAuction.quantity. Updates endTimeAt to the block timestamp + SystemState.debtAuctionBidDuration.
Updates:
- DebtAuction
Deactivates the DebtAuction(active = false) and sets the deletedAt variable to the timestamp of the block.
Updates:
- DebtAuction
Sets the highestBidder to the transaction creator and the quantity to the Int value from arg2. Updates endTimeAt to the block timestamp + SystemState.debtAuctionBidDuration.
Updates:
- DebtAuction
Deactivates the DebtAuction(active = false) and sets the deletedAt variable to the timestamp of the block.
The Vow contract represents the Maker Protocol's balance sheet. In particular, the Vow acts as the recipient of both the system surplus and system debt. Its main functions are to cover deficits via debt (Flop) auctions and discharge surpluses via surplus (Flap) auctions.
Updates:
- SystemState
Sets variables according to the what value from the LogNote event.
what="wait": Updates debtAuctionDelay to the value from data.
what="bump": Updates surplusAuctionLotSize to the RAD value from data.
what="sump": Updates debtAuctionBidSize to the RAD value from data.
what="dump": Updates debtAuctionInitialLotSize to the WAD value from data.
what="hump": Updates surplusAuctionBuffer to the RAD value from data.
what="flapper": Updates vowFlapperContract to the Address from arg2.
what="flopper": Updates vowFlopperContract to the Address from arg2.
Creates:
- LiveChangeLog
Creates a LiveChangeLog entity
Creates:
- PopDebtQueueLog
Updates:
- SystemState
Binds to the Vow contract to receive the sin value from the era (=arg1). It afterwards substracts the RAD value from the result from the SystemState.systemDebtInQueue value. It updates SystemState.systemDebtInQueue with the result from this calculation. The subgraph will then create the PopDebtQueueLog entity.
Creates:
- PushDebtQueueLog
Updates:
- SystemState
Adds SystemState.systemDebtInQueue with the RAD value from _tab(=_arg1) and updates SystemState.systemDebtInQueue with the result.
Creates:
- VowFlapLog
Creates a VowFlapLog entity and sets the VowFlapLog.surplusAuctionLotSize to the value from SystemState.surplusAuctionLotSize.
Creates:
- VowFlopLog
Updates:
- SystemState
Adds SystemState.debtOnAuctionTotalAmount (=ash; if the value is not set it will default to 0) with SystemState.debtAuctionBidSize(=sump) and sets the result to SystemState.debtOnAuctionTotalAmount. The subgraph will create the entity VowFlopLog afterwards.
Updates:
- SystemState
Sets the SystemState.debtOnAuctionTotalAmount to the RAD value from arg1 + the current value from debtOnAuctionTotalAmount.