A borrower account has Dai collateral and an open WBTC borrow. It has become under-collateralized. I can seize their cDai by liquidating their WBTC borrow. I have a balance of WBTC. I call approve on cWBTC and pass the amount of WBTC that I want to repay (or greater). I then call liquidateBorrow on cWBTC and pass the borrower address, amount of WBTC to liquidate, and the cDai address. If the liquidation is successful, my WBTC balance goes down and my cDai balance goes up. If I redeem that cDai immediately, the underlying Dai is worth the same amount as the amount of WBTC I gave up plus 8%.
const ethers = require('ethers'); // v5 | |
const providerUrl = process.env.POLYGON_PROVIDER_URL; | |
(async () => { | |
const provider = new ethers.providers.JsonRpcProvider(providerUrl); | |
const cometAddress = '0xF25212E676D1F7F89Cd72fFEe66158f541246445'; | |
const cometAbi = [ | |
'function getAssetInfo(uint8 i) public view returns (uint8 offset, address asset, address priceFeed, uint64 scale, uint64 borrowCollateralFactor, uint64 liquidateCollateralFactor, uint64 liquidationFactor, uint128 supplyCap)', | |
'function baseToken() public view returns (address)', | |
'function baseTokenPriceFeed() public view returns (address)', |
[{"inputs":[],"name":"Absurd","type":"error"},{"inputs":[],"name":"AlreadyInitialized","type":"error"},{"inputs":[],"name":"BadAmount","type":"error"},{"inputs":[],"name":"BadAsset","type":"error"},{"inputs":[],"name":"BadDecimals","type":"error"},{"inputs":[],"name":"BadDiscount","type":"error"},{"inputs":[],"name":"BadMinimum","type":"error"},{"inputs":[],"name":"BadNonce","type":"error"},{"inputs":[],"name":"BadPrice","type":"error"},{"inputs":[],"name":"BadSignatory","type":"error"},{"inputs":[],"name":"BorrowCFTooLarge","type":"error"},{"inputs":[],"name":"BorrowTooSmall","type":"error"},{"inputs":[],"name":"InsufficientReserves","type":"error"},{"inputs":[],"name":"InvalidInt104","type":"error"},{"inputs":[],"name":"InvalidInt256","type":"error"},{"inputs":[],"name":"InvalidUInt104","type":"error"},{"inputs":[],"name":"InvalidUInt128","type":"error"},{"inputs":[],"name":"InvalidUInt64","type":"error"},{"inputs":[],"name":"InvalidValueS","type":"error"},{"inputs":[],"name":"InvalidValueV","type":"error"} |
Hey, I noticed that no one actually added the newest asset, USDP, to the Compound Front-end aka Palisade and I wanted to show the steps so that others can feel comfortable adding in the future for other assets added to the protocol.
The 1st step is updating the contract address and abi config repo containing the newest token added. This step can be tricky to get right as the config repo is how we keep track of all abis and addresses used. This was done and merged here: compound-finance/compound-config#49
Step 2 is to add the the new styles for the asset in the shared components repo. A regular asset icon is needed as well as cToken asset as shown here: https://github.com/compound-finance/compound-components/pull/58/commits/88a3cc2dfe2b2f72c0f15b8fc321ecc601ed1370
The 3rd and final step is to open a PR on Palisade which updates the dependencies for the config repo and the shared components repo as shown here: compound-finance/palisade#12
I'm going to merge a
pragma solidity ^0.5.16; | |
pragma experimental ABIEncoderV2; | |
import "../../contracts/Governance/GovernorBravoDelegate.sol"; | |
// @notice Only use this contract for internal testing | |
contract GovernorBravoDelegateHarness is GovernorBravoDelegate { | |
// @notice Harness initiate the GovenorBravo contract | |
// @dev This function bypasses the need to initiate the GovernorBravo contract from an existing GovernorAlpha for testing. | |
// Actual use will only use the _initiate(address) function |
// First run Ganache locally with `cUsdc` address unlocked | |
const Web3 = require('web3'); | |
const web3 = new Web3('http://127.0.0.1:8545'); | |
const usdcAbi = [{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"authorizer","type":"address"},{"indexed":true,"internalType":"bytes32","name":"nonce","type":"bytes32"}],"name":"AuthorizationCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"authorizer","type":"address"},{"indexed":true,"internalType":"bytes32","name":"nonce","type":"bytes32"}],"name":"AuthorizationUsed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_account","type":"address"}],"name":"Blacklist |
- Convert all supplied and borrowed asset amounts to a single asset (like USD or ETH).
- Calculate the sum of (suppliedAmount * supplyApyAsDecimal - borrowedAmount * borrowApyAsDecimal) for all underlying assets.
- If the calculated sum from the previous step is >0 then Net APY = 100 * (sum / totalSuppliedValue). If the calculation from the previous step is <0 then Net APY = 100 * (sum / totalBorrowedValue). If the calculation from the previous step is 0 then Net APY = 0.
Net APY:
- -7.29%
const Compound = require('@compound-finance/compound-js'); | |
const provider = 'https://mainnet.infura.io/v3/' + process.env.infuraApiKey; | |
// mainnet | |
const CompoundLens = Compound.util.getAddress(Compound.CompoundLens); | |
const LensAbi = Compound.util.getAbi(Compound.CompoundLens); | |
const COMP = Compound.util.getAddress(Compound.COMP); | |
const Comptroller = Compound.util.getAddress(Compound.Comptroller); | |
const me = '0xa0df350d2637096571F7A701CBc1C5fdE30dF76A'; |
// Based on https://github.com/ethereum/EIPs/blob/master/assets/eip-712/Example.js | |
const ethers = require('ethers'); | |
function abiRawEncode(encTypes, encValues) { | |
const hexStr = ethers.utils.defaultAbiCoder.encode(encTypes, encValues); | |
return Buffer.from(hexStr.slice(2, hexStr.length), 'hex'); | |
} | |
function keccak256(arg) { |
const Compound = require('@compound-finance/compound-js');
const provider = 'https://mainnet.infura.io/v3/' + process.env.infuraApiKey;
const cTokenToGetCompApy = Compound.cUSDC; // Pick an asset
const underlying = cTokenToGetCompApy.slice(1, 10);
const underlyingDecimals = Compound.decimals[underlying];