Skip to content

Commit

Permalink
bit of view function & tests
Browse files Browse the repository at this point in the history
  • Loading branch information
I-M-F committed Jun 24, 2023
1 parent 06867fc commit 313934f
Show file tree
Hide file tree
Showing 13 changed files with 824 additions and 50 deletions.
10 changes: 10 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules
package.json
img
artifacts
cache
coverage
.env
.*
README.md
coverage.json
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tabWidth": 4,
"useTabs": false,
"semi": false,
"singleQuote": false
}
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

Our Stablecoin Features

1. (Relative Stability) Anchored or Pegged -> $1.00
1. Chainlink Price Feed.
2. Set a function to exchnage ETH & BTC -> $$$.
2. Stability Mechanism (Minting): Algorithmic (Decentralized)
1. Can only mint the StbaleCoin with enough collateral.
3. Collateral: Exogenous (Crypto)
1. ETH ERC20 version wETH.
2. BTC ERC20 version wBTC.


-> Calculate Health Factor Function
-> Set Health Factor if dept is 0
-> Added a bunch of view Function

1. What are our invariants/properties?
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
src = "src"
out = "out"
libs = ["lib"]
remappings = ['@chainlink/contracts/=lib/chainlink-brownie-contracts/contracts/', '@openzeppelin/contracts=lib/openzeppelin-contracts/contracts']

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
12 changes: 0 additions & 12 deletions script/Counter.s.sol

This file was deleted.

33 changes: 33 additions & 0 deletions script/DeployDSC.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {Script} from "forge-std/Script.sol";
import {DecentralizedStableCoin} from "../src/DecentralizedStableCoin.sol";
import {DSCEngine} from "../src/DSCEngine.sol";
import {HelperConfig} from "../script/HelperConfig.s.sol";

contract DeployDSC is Script {
// function setUp() public {}

address[] public tokenAddresses;
address[] public priceFeedAddresses;

function run() external returns (DecentralizedStableCoin, DSCEngine, HelperConfig) {
HelperConfig config = new HelperConfig();

(address wethUsdPriceFeed, address wbtcUsdPriceFeed, address weth, address wbtc, uint256 depployerKey) = config.activeNetworkConfig();

tokenAddresses = [weth, wbtc];
priceFeedAddresses = [wethUsdPriceFeed, wbtcUsdPriceFeed];

vm.startBroadcast(depployerKey);
DecentralizedStableCoin dsc = new DecentralizedStableCoin();
DSCEngine engine = new DSCEngine(tokenAddresses, priceFeedAddresses, address(dsc));

dsc.transferOwnership(address(engine));

vm.stopBroadcast();

return (dsc, engine, config);
}
}
66 changes: 66 additions & 0 deletions script/HelperConfig.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {Script} from "forge-std/Script.sol";
import {MockV3Aggregator} from "../test/mocks/MockV3Aggregator.sol";
import {ERC20Mock} from "@openzeppelin/contracts/mocks/ERC20Mock.sol";

contract HelperConfig is Script {
struct NetworkConfig {
address wethUsdPriceFeed;
address wbtcUsdPriceFeed;
address weth;
address wbtc;
uint256 deployerKey;
}

uint8 public constant DECIMALS = 8;
int256 public constant ETH_USD_PRICE = 2000e8;
int256 public constant BTC_USD_PRICE = 1000e8;
uint256 public DEFAULT_ANVIL_KEY = 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80;

NetworkConfig public activeNetworkConfig;

constructor() {
if (block.chainid == 11155111){
activeNetworkConfig = getSepoliaEthConfig();
} else {
activeNetworkConfig = getOrCreateAnvilEthConfig();
}
}

function getSepoliaEthConfig() public view returns (NetworkConfig memory) {
return NetworkConfig({
wethUsdPriceFeed: 0x694AA1769357215DE4FAC081bf1f309aDC325306,
wbtcUsdPriceFeed: 0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43,
weth: 0xdd13E55209Fd76AfE204dBda4007C227904f0a81,
wbtc: 0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063,
deployerKey: vm.envUint("PRIVATE_KEY")
});
}

function getOrCreateAnvilEthConfig() public returns (NetworkConfig memory) {
if (activeNetworkConfig.wethUsdPriceFeed != address(0)) {
return activeNetworkConfig;
}

vm.startBroadcast();
MockV3Aggregator ethUsdPriceFeed = new MockV3Aggregator(DECIMALS, ETH_USD_PRICE);

ERC20Mock wethMock = new ERC20Mock("WETH", "WETH", msg.sender, 1000e8);

MockV3Aggregator btcUsdPriceFeed = new MockV3Aggregator(DECIMALS, BTC_USD_PRICE);

ERC20Mock wbtcMock = new ERC20Mock("WBTC", "WBTC", msg.sender, 1000e8);

vm.stopBroadcast();

return NetworkConfig({
wethUsdPriceFeed: address(ethUsdPriceFeed),
wbtcUsdPriceFeed: address(btcUsdPriceFeed),
weth: address(wethMock),
wbtc: address(wbtcMock),
deployerKey: DEFAULT_ANVIL_KEY
});
}
}
14 changes: 0 additions & 14 deletions src/Counter.sol

This file was deleted.

Loading

0 comments on commit 313934f

Please sign in to comment.