Skip to content

Commit

Permalink
Merge pull request #103 from Threshold-USD/feat/application-adapted-f…
Browse files Browse the repository at this point in the history
…or-mainnet-contracts

feat: application adapted for mainnet contracts
  • Loading branch information
evandrosaturnino authored Nov 22, 2023
2 parents 30eea1b + b94ddf1 commit a381169
Show file tree
Hide file tree
Showing 23 changed files with 1,359 additions and 1,231 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ echo_config() {
echo '{'
[ -n "$TESTNET_ONLY" ] && echo ' "testnetOnly": '$TESTNET_ONLY','
echo ' "frontendTag": "'$FRONTEND_TAG'",'
echo ' "infuraApiKey": "'$INFURA_API_KEY'",'
echo ' "blocksApiUrl": "'$BLOCKS_API_URL'",'
echo ' "thresholdUsdApiUrl": "'$THRESHOLD_USD_API_URL'"'
echo '}'
Expand Down
2 changes: 1 addition & 1 deletion packages/dev-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@web3-onboard/injected-wallets": "2.8.3",
"@web3-onboard/react": "2.7.1",
"@web3-onboard/taho": "2.0.1",
"@web3-onboard/walletconnect": "2.3.4",
"@web3-onboard/walletconnect": "2.4.7",
"@web3-react/core": "6.1.9",
"@web3-react/injected-connector": "6.0.7",
"@web3-react/types": "6.0.7",
Expand Down
25 changes: 21 additions & 4 deletions packages/dev-frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,26 @@ import theme from "./theme";
import { DisposableWalletProvider } from "./testUtils/DisposableWalletProvider";
import { ThresholdFrontend } from "./ThresholdFrontend";

const wcV2InitOptions = {
/**
* Project ID associated with [WalletConnect account](https://cloud.walletconnect.com)
*/
projectId: process.env.REACT_APP_WALLETCONNECT_ID as string,
/**
* Chains required to be supported by all wallets connecting to your DApp
*/
requiredChains: [1],
/**
* Defaults to `appMetadata.explore` that is supplied to the web3-onboard init
* Strongly recommended to provide atleast one URL as it is required by some wallets (i.e. MetaMask)
* To connect with WalletConnect
*/
dappUrl: 'http://app.thresholdusd.org'
}

const injected = injectedModule();
const coinbase = coinbaseModule();
const walletConnect = walletConnectModule();
const walletConnect = walletConnectModule(wcV2InitOptions)
const taho = tahoModule();

const wallets = [
Expand Down Expand Up @@ -77,13 +94,13 @@ if (window.ethereum) {

function getRpcUrl(chainIdHex: '0x1' | '0x5' | '0xaa36a7') {
const publicRpcUrls = {
'0x1': 'https://mainnet.eth.aragon.network/',
'0x1': 'https://cloudflare-eth.com/',
'0x5': 'https://goerli.eth.aragon.network/',
'0xaa36a7': 'https://sepolia.eth.aragon.network/'
};

if (process.env.REACT_APP_INFURA_ID) {
return `https://${chainIdHex === '0x1' ? 'mainnet' : chainIdHex === '0x5' ? 'goerli' : 'sepolia'}.infura.io/v3/${process.env.REACT_APP_INFURA_ID}`;
if (process.env.REACT_APP_ALCHEMY_ID) {
return `https://eth-${chainIdHex === '0x1' ? 'mainnet' : chainIdHex === '0x5' ? 'goerli' : 'sepolia'}.g.alchemy.com/v2/${process.env.REACT_APP_ALCHEMY_ID}`;
} else {
return publicRpcUrls[chainIdHex];
}
Expand Down
4 changes: 2 additions & 2 deletions packages/dev-frontend/src/ThresholdFrontend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const UnsupportedMainnetFallback = (): JSX.Element => (
</Heading>

<Paragraph sx={{ mb: 3 }}>
Please change your network to Sepolia.
Please change your network to Mainnet or Sepolia.
</Paragraph>
</Flex>
);
Expand All @@ -61,7 +61,7 @@ export const ThresholdFrontend = ({ loader }: ThresholdFrontendProps): JSX.Eleme
{chainId === 1 ? "Ethereum Mainnet" : supportedNetworks[chainId] ?? "this network"}
</Flex>.
</Heading>
Please switch to Sepolia.
Please switch to Mainnet or Sepolia.
</Flex>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export type FunctionalPanelProps = {
children?: React.ReactNode;
};

const coingeckoIdsBySymbol = {
eth: "ethereum",
tbtc: "tbtc"
}

const fetchBlockByTimestamp = (timestamp: number, blocksApiUrl: string) => {
const query = `
query {
Expand Down Expand Up @@ -176,7 +181,7 @@ export const ChartProvider = ({ children }: FunctionalPanelProps): JSX.Element

// Destructure values from useThreshold hook
const { threshold, config, provider } = useThreshold();
const { blocksApiUrl, thresholdUsdApiUrl, coingeckoIdsBySymbol } = config;
const { blocksApiUrl, thresholdUsdApiUrl } = config;

// Define the getTVLData function for fetching TVL data
const getTVLData = () => {
Expand All @@ -190,8 +195,8 @@ export const ChartProvider = ({ children }: FunctionalPanelProps): JSX.Element
// Get the network name and corresponding blocks URL
return provider.getNetwork()
.then((network) => {
const networkName = network.name === 'homestead' ? 'ethereum' : network.name;
const blocksUrlByNetwork = `https://${blocksApiUrl}/${networkName}-blocks`;
const networkName = network.name === 'homestead' ? 'mainnet' : network.name;
const blocksUrlByNetwork = `https://${blocksApiUrl}/${networkName === 'mainnet' ? 'ethereum' : network.name}-blocks`;

// Loop through the collaterals in the threshold object and fetch the TVL data for each collateral
for (const thresholdCollateral of threshold) {
Expand Down
8 changes: 4 additions & 4 deletions packages/dev-frontend/src/components/Dashboard/EditPrice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const EditPrice = ({ version, collateral }: EditPriceProps): JSX.Element
return versionedThreshold.version === version && versionedThreshold.collateral === collateral;
})!;

const canSetPrice = collateralThreshold.store.connection._priceFeedIsTestnet
const isUsingRealPriceFeed = collateralThreshold.store.connection._useRealPriceFeed
const [editedPrice, setEditedPrice] = useState(price.toString(2))

return (
Expand All @@ -58,12 +58,12 @@ export const EditPrice = ({ version, collateral }: EditPriceProps): JSX.Element
}}>
{ symbol } Price - {version}
</Flex>
{canSetPrice ? (
{isUsingRealPriceFeed ? (
price.toString(2)
) : (
<Flex sx={{ mb:1, textAlign:"left", height: "1.2em", }}>
{editedPrice}
</Flex>
) : (
price.toString(2)
)}
</Flex>
);
Expand Down
4 changes: 2 additions & 2 deletions packages/dev-frontend/src/components/Dashboard/MintErc20.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ export const MintErc20 = ({ version, collateral }: MintErc20Props): JSX.Element
const collateralThreshold = threshold.find((versionedThreshold) => {
return versionedThreshold.version === version && versionedThreshold.collateral === collateral;
})!;
const canMint = collateralThreshold.store.connection._priceFeedIsTestnet
const isUsingRealPriceFeed = collateralThreshold.store.connection._useRealPriceFeed

return (
<SystemStat>
{canMint && symbol === "TST" ? (
{!isUsingRealPriceFeed && symbol === "TST" ? (
<Flex sx={{ mb: 2, mt: 2, alignItems: "center", height: "1.2em", width: "100%" }}>
<Transaction
id="set-price"
Expand Down
2 changes: 1 addition & 1 deletion packages/dev-frontend/src/components/RiskyVaults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export const RiskyVaults = ({ version, collateral }: RiskyVaultsProps): JSX.Elem
variant="socialIcons"
href={(chainId === 5 && `https://goerli.etherscan.io/address/${vault.ownerAddress}`) ||
(chainId === 11155111 && `https://sepolia.etherscan.io/address/${vault.ownerAddress}`) ||
`https://etherscan.io/address/${vault.ownerAddress})`}
`https://etherscan.io/address/${vault.ownerAddress}`}
target="_blank"
>
<Image src="./icons/external-link.svg" />
Expand Down
10 changes: 2 additions & 8 deletions packages/dev-frontend/src/components/SystemStatsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,17 @@ export const SystemStatsCard = ({ variant = "info", IsPriceEditable }: SystemSta
{ collateralStore.store.total.collateral.shorten() } { collateralStore.store.symbol }
</SystemStat>
))}
{/* <SystemStat
info={`${ COIN } in Stability Pool`}
tooltip={`The total ${ COIN } currently held in the Stability Pool, expressed as an amount and a fraction of the ${ COIN } supply.`}
>
{thusdInSP.shorten()}
</SystemStat> */}
<SystemStat
info={`${ COIN } in B.AMM`}
tooltip={`The total ${ COIN } currently held in the Backstop AMM, expressed as an amount and a fraction of the ${ COIN } supply.`}
tooltip={`The total ${ COIN } currently held in the Backstop AMM, expressed as an amount.`}
>
{thusdInBammm.shorten()}
</SystemStat>
<SystemStat
info={`${ COIN } in PCV`}
tooltip={`The total ${ COIN } currently held in the PCV, expressed as an amount and a fraction of the ${ COIN } supply.`}
>
{pcvBal.prettify()}
{pcvBal.shorten()}
</SystemStat>
<SystemStat
info={`${ COIN } Supply`}
Expand Down
19 changes: 0 additions & 19 deletions packages/dev-frontend/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export type ThresholdConfig = {
coingeckoIdsBySymbol?: object
infuraApiKey?: string;
testnetOnly?: boolean;
blocksApiUrl?: string;
thresholdUsdApiUrl?: string;
Expand All @@ -17,23 +15,6 @@ const parseConfig = (json: unknown): ThresholdConfig => {
const config = { ...defaultConfig };

if (typeof json === "object" && json !== null) {
if (hasKey(json, "coingeckoIdsBySymbol") && typeof json.coingeckoIdsBySymbol === "object" && json.coingeckoIdsBySymbol !== null) {
const { coingeckoIdsBySymbol } = json;
config.coingeckoIdsBySymbol = coingeckoIdsBySymbol;
} else {
console.error("Malformed infuraApiKey:");
}

if (hasKey(json, "infuraApiKey") && json.infuraApiKey !== "") {
const { infuraApiKey } = json;
if (typeof infuraApiKey === "string") {
config.infuraApiKey = infuraApiKey;
} else {
console.error("Malformed infuraApiKey:");
console.log(infuraApiKey);
}
}

if (hasKey(json, "testnetOnly")) {
const { testnetOnly } = json;

Expand Down
11 changes: 5 additions & 6 deletions packages/dev-frontend/src/hooks/ThresholdContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ type ThresholdProviderProps = {
unsupportedMainnetFallback?: React.ReactNode;
};

const wsParams = (network: string, infuraApiKey: string): [string, string] => [
`wss://${network === "homestead" ? "mainnet" : network}.infura.io/ws/v3/${infuraApiKey}`,
const wsParams = (network: string, alchemyApiKey: string): [string, string] => [
`wss://eth-${network === "homestead" ? "mainnet" : network}.g.alchemy.com/v2/${alchemyApiKey}`,
network
];

export const supportedNetworks: SupportedNetworks = { 1: "homestead", 5: "goerli", 11155111: "sepolia"};

const getCollateralVersions = async (chainId: number): Promise<CollateralsVersionedDeployments> => {
const network = supportedNetworks[chainId];
return await getCollateralsDeployments(network);
return await getCollateralsDeployments(network === "homestead" ? "mainnet" : network);
}

async function getConnections(
Expand Down Expand Up @@ -132,7 +132,6 @@ export const ThresholdProvider = ({
.catch((err) => console.error('get collateral error: ', err))
}, [chainId, provider, address, config])


useEffect(() => {
getConfig().then(setConfig);
}, []);
Expand Down Expand Up @@ -165,8 +164,8 @@ export const ThresholdProvider = ({
}
if (isWebSocketAugmentedProvider(provider)) {
const network = getNetwork(chainId);
if (network.name && Object.keys(supportedNetworks).includes(network.name) && config.infuraApiKey) {
provider.openWebSocket(...wsParams(network.name, config.infuraApiKey));
if (network.name && Object.keys(supportedNetworks).includes(network.name) && process.env.REACT_APP_ALCHEMY_ID) {
provider.openWebSocket(...wsParams(network.name, process.env.REACT_APP_ALCHEMY_ID));
} else if (connections[0]._isDev) {
provider.openWebSocket(`ws://${window.location.hostname}:8546`, chainId);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/dev-frontend/src/pages/VaultPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const VaultPage = (): JSX.Element => {
<Container variant="singlePage">
<PageHeading
heading="Open a Vault"
description={`To borrow you must open a Vault and deposit a certain amount of collateral to it. Then you can draw ${ COIN } up to a collateral ratio of 120%. A minimum debt of 2,000 ${ COIN } is required.`}
description={`To borrow you must open a Vault and deposit a certain amount of collateral to it. Then you can draw ${ COIN } up to a collateral ratio of 110%. A minimum debt of 2,000 ${ COIN } is required.`}
link="https://github.com/Threshold-USD/dev"
/>
<PageRow Component={Vault} />
Expand Down
28 changes: 28 additions & 0 deletions packages/lib-ethers/deployments/default/eth/v1/mainnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"chainId": 1,
"version": "v1",
"collateralSymbol": "eth",
"deploymentDate": 1698207110328,
"_useRealPriceFeed": true,
"_isDev": false,
"startBlock": 18424608,
"addresses": {
"activePool": "0xE922B5591Da479a559b25261BD6Dc8f89cA1A29d",
"borrowerOperations": "0x874a8ee5b4Cc0B9973c7c002FA891fc28666cAA9",
"troveManager": "0x27D7D02AED6C4F95Ada2faf02DcCB9666D3abB8C",
"collSurplusPool": "0x67dbd2ad541c61d37F17B0515d2e452e04597A36",
"defaultPool": "0xa8BdAb0F0D3f5Cd04d29df5f4ba6B43d7cdb7Ba9",
"hintHelpers": "0xF3dA35dd10Ed653Fd66Eb03D349EDfD139521Df5",
"pcv": "0x1a4739509F50E683927472b03e251e36d07DD872",
"sortedTroves": "0xE5Ada07ACE9412A623B0A282Cd67d16a3a094E17",
"stabilityPool": "0xA18Ab4Fa9a44A72c58e64bfB33D425Ec48475a9f",
"bLens": "0xf21AcB3C2E8418fc5466bc794f9970df7255aE28",
"gasPool": "0x34Fbfd06Cb537aBd1a75E91A9Cf7F5B61B47eCa6",
"erc20": "0x0000000000000000000000000000000000000000",
"priceFeed": "0x684645ccAB4d55863A149C52eC3176051Cdb732d",
"chainlink": "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419",
"multiTroveGetter": "0x8836b66727bbde25974110442Bb46B7a4805B36c",
"thusdToken": "0xCFC5bD99915aAa815401C5a41A927aB7a38d29cf",
"bamm": "0x1f490764473eb1013461D6079F827DB95d8B4DC5"
}
}
34 changes: 17 additions & 17 deletions packages/lib-ethers/deployments/default/eth/v1/sepolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
"chainId": 11155111,
"version": "v1",
"collateralSymbol": "eth",
"deploymentDate": 1695957487249,
"deploymentDate": 1697598770309,
"_useRealPriceFeed": true,
"_isDev": false,
"startBlock": 4385881,
"startBlock": 4510979,
"addresses": {
"activePool": "0x42B2BA1099D5cddb9893D8BDf7aBBd228C0F4A9E",
"borrowerOperations": "0x52Ec55D25E6d2c08c4668C80CaE778Ab81f2E61D",
"troveManager": "0x92304f49d10FefF861E692CD7A1461596fA21E96",
"collSurplusPool": "0x09397b5DaD73b06e27F8f386d7E1fF0Bf402e026",
"defaultPool": "0xdBb5B98639Fa4cC43D60d7f593728272545c3853",
"hintHelpers": "0x026Eed10Eed6b19FE5301361A37A857FA15c1698",
"pcv": "0x55749fD8aA6aa324dB0dBa58D8Ba8C68Cca79B88",
"sortedTroves": "0x15560C4766A099FeD76857ab1459026b51ee2372",
"stabilityPool": "0xFCDc7888d5744CC56cE08289CB23Fb22d5DC6214",
"bLens": "0x2DF50a886ba3C911250C540C6129cFd471A289eA",
"gasPool": "0x656Abc25822aA8955651370EF1A694C6a497625E",
"activePool": "0x7Ad9aC09aABeA7549061FCa5B46D14295a073330",
"borrowerOperations": "0xe2eA5880effFdd234A065dBBC174D6cb8a867167",
"troveManager": "0x4D74b0eFfa314a79dFd324C129D5b29c11ADbb04",
"collSurplusPool": "0xf5fff7676A98A73D6eCFb6F85dFd1c2b825f5940",
"defaultPool": "0xf97C6561228cEa0fA34201e710a9740E41953aC9",
"hintHelpers": "0x700138435639Ac2de1b6Ea29c117BD299775DB98",
"pcv": "0x74B81477E64fbeF008A2956bA5074F283d68Dc46",
"sortedTroves": "0xd2e4d6c9096a37e9FE7B1Ef7778266a4c6Aa1Acd",
"stabilityPool": "0x7153332F610f513b9CeC128385926E23a2AC8182",
"bLens": "0xc86d498B77542245959625436e679D18f0F4076E",
"gasPool": "0x206a6B4a318949655c221BE5Ac54B8740dDe1FA7",
"erc20": "0x0000000000000000000000000000000000000000",
"priceFeed": "0x8d1B32f2F81915D409FAf54169c855f4495bA8A2",
"priceFeed": "0xA34e20fF8d6569Aa008F15ec58589bE9ad746AB8",
"chainlink": "0x694AA1769357215DE4FAC081bf1f309aDC325306",
"multiTroveGetter": "0xA712ac7079F129364B0bcA6FC84f632f65F0DB5D",
"thusdToken": "0xb0d375882d19be3b4688Dee71860307e95f86AED",
"bamm": "0xA3F9688bEC1480b3C543aa7744A77Fbfb9d7Bf95"
"multiTroveGetter": "0x8C93c45A12a50d29FF9Bee6019FD72Fd48Fb5398",
"thusdToken": "0xF3e72cc2e04BB24999718e9b2Ca55fA764c5f9ea",
"bamm": "0xB774F31e2f64897fa7Eb9435884E08149eD3F1e5"
}
}
28 changes: 28 additions & 0 deletions packages/lib-ethers/deployments/default/tbtc/v1/mainnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"chainId": 1,
"version": "v1",
"collateralSymbol": "tbtc",
"deploymentDate": 1698207110491,
"_useRealPriceFeed": true,
"_isDev": false,
"startBlock": 18424621,
"addresses": {
"activePool": "0x4dbcb0cFf525B91E8b9D18b224c1B45feF008549",
"borrowerOperations": "0xf5e4fFeB7d2183B61753AA4074d72E51873C1D0a",
"troveManager": "0xfC7d41A684b7dB7c817A9dDd028f9A31c2F6f893",
"collSurplusPool": "0x3BEC529c86317C64305dc161998Fb7f40078F200",
"defaultPool": "0xbe037954B419676904117F0D7d7e15f78FF1Bf4B",
"hintHelpers": "0x2249e86a4b99EcCC081600C11B2B30FF64202f55",
"pcv": "0x097f1ee62E63aCFC3Bf64c1a61d96B3771dd06cB",
"sortedTroves": "0xA5626CBA9A4448019e73CE59784bD22736986711",
"stabilityPool": "0xF6374AEfb1e69a21ee516ea4B803b2eA96d06f29",
"bLens": "0x65222d72f13860913fEF03f088c385Cbfc11A50c",
"gasPool": "0x8a7C0b18FB80Bd0a1d3530262B15264278e5f64D",
"erc20": "0x18084fbA666a33d37592fA2633fD49a74DD93a88",
"priceFeed": "0x83aE3931C5D03773755311372c0737F856657a43",
"chainlink": "0xF4030086522a5bEEa4988F8cA5B36dbC97BeE88c",
"multiTroveGetter": "0xd74DFFDC614b84610329AF4707D8Dcc484c735d0",
"thusdToken": "0xCFC5bD99915aAa815401C5a41A927aB7a38d29cf",
"bamm": "0x920623AcBa785ED9a70d33ACab53631e1e834675"
}
}
Loading

0 comments on commit a381169

Please sign in to comment.