Skip to content

Commit

Permalink
fixed chains for usdc market
Browse files Browse the repository at this point in the history
  • Loading branch information
vanshwassan committed Sep 5, 2024
1 parent 234b5b3 commit 78411f5
Show file tree
Hide file tree
Showing 19 changed files with 466 additions and 41 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This repository contains the smart contracts source code and market configuratio

This forked version of comet uses API3's dAPIs for data feeds for assets. Check out the API3 documentation [here](https://docs.api3.org/).

## Deploying on Sepolia
## Deploying the protocol

### Deploying the adaptors

Expand All @@ -16,9 +16,10 @@ This forked version of comet uses API3's dAPIs for data feeds for assets. Check
yarn adaptors:build
```

- Open `api3-adaptors/config.json` and add your asset details. You also need proxy contract address for each asset you are going to add. Head over to the [API3 Market](https://market.api3.org/) and get the proxy contract address for the assets you want to add.
- Open `api3-adaptors/config.json` and add your asset and network details. You also need proxy contract address for each asset you are going to add. Head over to the [API3 Market](https://market.api3.org/) and get the proxy contract address for the assets you want to add.

You can also check out [this guide](https://docs.api3.org/guides/dapis/subscribing-to-dapis/) on subscribing to dAPIs and getting a proxy address.
For now, only 3 assets are supported. Do not add any more assets in the config.

*NOTE: It is advisable to use a private RPC for the deployments. If the protocol deployment fails, try using another RPC.*

Expand Down Expand Up @@ -52,10 +53,10 @@ yarn
Run the following command to deploy the protocol:

```bash
yarn protocol:deploy
NETWORK=your-network yarn protocol:deploy
```

This would deploy Compound V3 USDC Market on Sepolia Testnet with all the collateral assets defined in the `api3-adaptors/config.json` file.
This would deploy Compound V3 USDC Market on your desired chain with all the collateral assets defined in the `api3-adaptors/config.json` file.

## Spinning up the frontend

Expand Down
27 changes: 15 additions & 12 deletions api3-adaptors/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,47 @@
"assetName": "Compound",
"assetSymbol": "COMP",
"pairName": "COMP/USD",
"proxyAddress": "0xe3ECd26173d9E08261db4DE2e8690AA303b0339c",
"proxyAddress": "0x6527eb02Ec508C3c8aF39B4258f90705a5e00394",
"description": "COMP/USD Price Feed",
"decimals": 18,
"supplyCap": "500000e18"
"supplyCap": "500000e18",
"deployERC20": false

},
{
"assetName": "Wrapped Bitcoin",
"assetSymbol": "WBTC",
"pairName": "WBTC/USD",
"proxyAddress": "0xF33979e0751687500F4dB02B9669837744d4f478",
"proxyAddress": "0xc64C5fAafd21E04614E14aB3B91034b32164291a",
"description": "WBTC/USD Price Feed",
"decimals": 8,
"supplyCap": "35000e8"
"supplyCap": "35000e8",
"deployERC20": false

},
{
"assetName": "Wrapped Etherereum",
"assetSymbol": "WETH",
"pairName": "WETH/USD",
"proxyAddress": "0x1A4eE81BBbb479f3923f22E315Bc2bD1f6d5d180",
"proxyAddress": "0xB7ce7B052836c69EaB40a1D5C0b2baeE8eFB86C7",
"description": "WETH/USD Price Feed",
"decimals": 18,
"supplyCap": "1000000e18"
"supplyCap": "1000000e18",
"deployERC20": false
}
],
"EthUsdProxyAddress": "0x1A4eE81BBbb479f3923f22E315Bc2bD1f6d5d180",
"UsdcUsdProxyAddress": "0xe8a3E41e620fF07765651a35334c9B6578790ECF",
"EthUsdProxyAddress": "0xB7ce7B052836c69EaB40a1D5C0b2baeE8eFB86C7",
"UsdcUsdProxyAddress": "0x5fb6E1fBCB474E1aAfFb7C2104d731633D8c3D63",
"network": {
"chainId": 11155111,
"name": "Sepolia",
"rpc": "https://ethereum-sepolia.blockpi.network/v1/rpc/public",
"chainId": 84532,
"name": "base-sepolia",
"rpc": "https://sepolia.base.org",
"nativeCurrency" : {
"name": "Ether",
"symbol": "ETH",
"wrapped": "WETH",
"decimals": 18
},
"explorerLink": "https://etherscan.io/"
"explorerLink": "https://basescan.org/"
}
}
23 changes: 23 additions & 0 deletions api3-adaptors/copy-scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const fs = require('fs');
const path = require('path');

const config = JSON.parse(fs.readFileSync('config.json', 'utf8'));

const networkName = config.network.name;

const dirPath = path.join(__dirname, '..', 'deployments', networkName);

if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
}

const sourceDir = path.join(__dirname, 'protocol-deployment-scripts');
const destDir = path.join(dirPath, 'usdc');

if (!fs.existsSync(destDir)) {
fs.mkdirSync(destDir, { recursive: true });
}

fs.readdirSync(sourceDir).forEach(file => {
fs.copyFileSync(path.join(sourceDir, file), path.join(destDir, file));
});
3 changes: 2 additions & 1 deletion api3-adaptors/generateProtocolConfiguration.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs');

const references = JSON.parse(fs.readFileSync('references.json', 'utf8'));
const config = JSON.parse(fs.readFileSync('config.json', 'utf8'));

// base config
let configuration = {
Expand Down Expand Up @@ -44,4 +45,4 @@ for (let asset of references.assets) {
};
}

fs.writeFileSync('../deployments/sepolia/usdc/configuration.json', JSON.stringify(configuration, null, 2));
fs.writeFileSync(`../deployments/${config.network.name}/usdc/configuration.json`, JSON.stringify(configuration, null, 2));
2 changes: 1 addition & 1 deletion api3-adaptors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"scripts": {
"coverage": "solidity-coverage",
"deploy:adaptors": "hardhat deploy --config hardhat.config.js --network custom --tags deployDapiAdapter && node generateProtocolConfiguration.js",
"deploy:adaptors": "hardhat deploy --config hardhat.config.js --network custom --tags deployDapiAdapter && node copy-scripts.js &&node generateProtocolConfiguration.js",
"verify": "hardhat verify"
}
}
82 changes: 82 additions & 0 deletions api3-adaptors/protocol-deployment-scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { Deployed, DeploymentManager } from '../../../plugins/deployment_manager';
import { DeploySpec, cloneGov, deployComet, exp, sameAddress, wait } from '../../../src/deploy';

const clone = {
wbtc: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
weth: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
};

export default async function deploy(deploymentManager: DeploymentManager, deploySpec: DeploySpec): Promise<Deployed> {
const deployed = await deployContracts(deploymentManager, deploySpec);
await mintTokens(deploymentManager);
return deployed;
}

async function deployContracts(deploymentManager: DeploymentManager, deploySpec: DeploySpec): Promise<Deployed> {
const trace = deploymentManager.tracer()
const signer = await deploymentManager.getSigner();

// Deploy governance contracts
const { COMP, fauceteer, timelock } = await cloneGov(deploymentManager);

// Clone collateral assets from mainnet
const WBTC = await deploymentManager.clone('WBTC', clone.wbtc, []);
const WETH = await deploymentManager.clone('WETH', clone.weth, []);

// // ADD CUSTOM TOKENS
// const ARB = await deploymentManager.existing('ARB', '0x117e85D7FA75fFd5Af908E952bAE62b74613eD82', 'sepolia', 'contracts/ERC20.sol:ERC20');

// Deploy all Comet-related contracts
const deployed = await deployComet(deploymentManager, deploySpec);
const { rewards } = deployed;

// Deploy Bulker
const bulker = await deploymentManager.deploy(
'bulker',
'bulkers/BaseBulker.sol',
[timelock.address, WETH.address]
);

await deploymentManager.idempotent(
async () => (await COMP.balanceOf(rewards.address)).eq(0),
async () => {
trace(`Sending some COMP to CometRewards`);
const amount = exp(1_000_000, 18);
trace(await wait(COMP.connect(signer).transfer(rewards.address, amount)));
trace(`COMP.balanceOf(${rewards.address}): ${await COMP.balanceOf(rewards.address)}`);
trace(`COMP.balanceOf(${signer.address}): ${await COMP.balanceOf(signer.address)}`);
}
);

return { ...deployed, fauceteer, bulker };
}

async function mintTokens(deploymentManager: DeploymentManager) {
const trace = deploymentManager.tracer();
const signer = await deploymentManager.getSigner();
const contracts = await deploymentManager.contracts();
const fauceteer = contracts.get('fauceteer');

trace(`Attempting to mint as ${signer.address}...`);

const WETH = contracts.get('WETH');
await deploymentManager.idempotent(
async () => (await WETH.balanceOf(signer.address)).lt(exp(0.01, 18)),
async () => {
trace(`Minting 0.01 WETH for signer (this is a precious resource!)`);
trace(await wait(WETH.connect(signer).deposit({ value: exp(0.01, 18) })));
trace(`WETH.balanceOf(${signer.address}): ${await WETH.balanceOf(signer.address)}`);
}
);

const WBTC = contracts.get('WBTC');
await deploymentManager.idempotent(
async () => (await WBTC.balanceOf(fauceteer.address)).eq(0),
async () => {
trace(`Minting 20 WBTC to fauceteer`);
const amount = exp(20, await WBTC.decimals());
trace(await wait(WBTC.connect(signer).mint(fauceteer.address, amount)));
trace(`WBTC.balanceOf(${fauceteer.address}): ${await WBTC.balanceOf(fauceteer.address)}`);
}
);
}
79 changes: 79 additions & 0 deletions api3-adaptors/protocol-deployment-scripts/relations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import baseRelationConfig from '../../relations';
import fs from 'fs';
import path from 'path';

const configuration = JSON.parse(fs.readFileSync(path.join(__dirname, 'configuration.json'), 'utf8'));

let priceFeeds = {};

for (let assetName in configuration.assets) {
priceFeeds[configuration.assets[assetName].priceFeed] = {
artifact: 'contracts/IPriceFeed.sol:IPriceFeed'
};
}

export default {
...baseRelationConfig,
...priceFeeds,
fxRoot: {
relations: {
stateSender: {
field: async fxRoot => fxRoot.stateSender()
}
}
},
arbitrumInbox: {
delegates: {
field: {
slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'
}
},
relations: {
arbitrumBridge: {
field: async inbox => inbox.bridge()
}
}
},
arbitrumL1GatewayRouter: {
delegates: {
field: {
slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'
}
}
},
baseL1CrossDomainMessenger: {
delegates: {
// Not great, but this address shouldn't change and is very difficult to grab on-chain (private methods)
field: async () => '0xa042e16781484716c1Ef448c919af7BCd9607467'
}
},
baseL1StandardBridge: {
delegates: {
field: {
slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'
}
}
},
lineaMessageService: {
artifact: 'contracts/bridges/linea/IMessageService.sol:IMessageService',
// delegates: {
// field: {
// slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'
// }
// }
},
lineaL1TokenBridge: {
delegates: {
field: {
slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'
}
}
},
lineaL1usdcBridge: {
delegates: {
field: {
slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'
}
}
}
};
1 change: 1 addition & 0 deletions api3-adaptors/protocol-deployment-scripts/roots.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
10 changes: 5 additions & 5 deletions api3-adaptors/references.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
"assetSymbol": "COMP",
"pairName": "COMP/USD",
"decimals": 18,
"EACAggregatorProxy": "0xce07dcB8BF6ACEbC905705f89e7Ad82C1B69766c",
"EACAggregatorProxy": "0xF834eA717d70B7BC1E0e385CB9DcdD7385AA6acA",
"supplyCap": "500000e18"
},
{
"assetSymbol": "WBTC",
"pairName": "WBTC/USD",
"decimals": 8,
"EACAggregatorProxy": "0x1017948567B93E8899604fDc61D6A4090Bc78107",
"EACAggregatorProxy": "0xBcdc2e9381376AC54b5484CA213fbA266A5Da15C",
"supplyCap": "35000e8"
},
{
"assetSymbol": "WETH",
"pairName": "WETH/USD",
"decimals": 18,
"EACAggregatorProxy": "0xeb1DF6D808248260e301C691ff99554Af5169fe1",
"EACAggregatorProxy": "0xFBD69fC0120Ed460E70C637Acd31f68AF8ecaB7b",
"supplyCap": "1000000e18"
}
],
"USDC": "0xB792CBE08421db895E68C513eA7D8f4eaF443a55",
"EACAggregatorProxyUSDC": "0x1e0Cd9F6019eA5D30b9A9983B18FE03B9C1DFC2c"
"USDC": "0x01c3a1E1494ca453aBD19Bbf9f91a25f91264686",
"EACAggregatorProxyUSDC": "0xBc2f0b462D4B43A4ee452f26635EC582844a3C13"
}
54 changes: 54 additions & 0 deletions deployments/base-sepolia/usdc/configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "Compound USDC",
"symbol": "cUSDCv3",
"baseToken": "USDC",
"baseTokenAddress": "0x01c3a1E1494ca453aBD19Bbf9f91a25f91264686",
"baseTokenPriceFeed": "0xBc2f0b462D4B43A4ee452f26635EC582844a3C13",
"pauseGuardian": "0x008a4C5448ac1Df676d6F39A0C6F13b21b189389",
"borrowMin": "1e0",
"storeFrontPriceFactor": 0.5,
"targetReserves": "5000000e6",
"rates": {
"supplyKink": 0.85,
"supplySlopeLow": 0.048,
"supplySlopeHigh": 1.6,
"supplyBase": 0,
"borrowKink": 0.85,
"borrowSlopeLow": 0.053,
"borrowSlopeHigh": 1.7,
"borrowBase": 0.015
},
"tracking": {
"indexScale": "1e15",
"baseSupplySpeed": "0.000011574074074074073e15",
"baseBorrowSpeed": "0.0011458333333333333e15",
"baseMinForRewards": "100e6"
},
"rewardToken": "COMP",
"assets": {
"COMP": {
"priceFeed": "0xF834eA717d70B7BC1E0e385CB9DcdD7385AA6acA",
"decimals": 18,
"borrowCF": 0.75,
"liquidateCF": 0.81,
"liquidationFactor": 0.93,
"supplyCap": "500000e18"
},
"WBTC": {
"priceFeed": "0xBcdc2e9381376AC54b5484CA213fbA266A5Da15C",
"decimals": 8,
"borrowCF": 0.75,
"liquidateCF": 0.81,
"liquidationFactor": 0.93,
"supplyCap": "35000e8"
},
"WETH": {
"priceFeed": "0xFBD69fC0120Ed460E70C637Acd31f68AF8ecaB7b",
"decimals": 18,
"borrowCF": 0.75,
"liquidateCF": 0.81,
"liquidationFactor": 0.93,
"supplyCap": "1000000e18"
}
}
}
Loading

0 comments on commit 78411f5

Please sign in to comment.