Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: UbiquityPool UI Update #860

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,497 changes: 0 additions & 2,497 deletions packages/contracts/broadcast/05_StakingShare.s.sol/31337/run-latest.json

This file was deleted.

16 changes: 11 additions & 5 deletions packages/contracts/src/dollar/mocks/MockMetaPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract MockMetaPool is IMetaPool, MockERC20 {
address token1;
address[2] public coins;
uint256[2] public balances = [10e18, 10e18];
uint256[2] public dy_values = [100e18, 100e18];
uint256[2] public dy_values = [1e18, 1e18];
uint256[2] price_cumulative_last = [10e18, 10e18];
uint256 last_block_timestamp = 10000;

Expand Down Expand Up @@ -101,11 +101,17 @@ contract MockMetaPool is IMetaPool, MockERC20 {
}

function get_dy(
int128 /* i */,
int128 /* j */,
int128 i,
int128 j,
uint256 /* dx */
) external pure returns (uint256) {
return 0;
) external view returns (uint256) {
if (i == 0 && j == 1) {
return dy_values[1];
} else if (i == 1 && j == 0) {
return dy_values[0];
} else {
return 0;
}
}

function get_dy_underlying(
Expand Down
3 changes: 1 addition & 2 deletions packages/dapp/components/layout/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ const Sidebar = () => {
<li>
<hr />
</li>
<Item text="Staking" href="/staking" icon="⛏"></Item>
<Item text="Credits" href="/credits" icon="💸"></Item>
<Item text="Pool" href="/pool" icon="💸"></Item>
<Item text="Markets" href="/markets" icon="🔁"></Item>
</ul>

Expand Down
31 changes: 31 additions & 0 deletions packages/dapp/components/lib/contracts-shortcuts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Provider } from "@ethersproject/providers";
import IERC20Artifact from "@ubiquity/contracts/out/IERC20.sol/IERC20.json";
import { BigNumber, ethers, Contract } from "ethers";

import { PossibleProviders } from "./hooks/use-web-3";
import { performTransaction } from "./utils";

export async function ensureERC20Allowance(
Expand Down Expand Up @@ -39,6 +42,34 @@ export async function ensureERC1155Allowance(logName: string, contract: Contract
return true;
}

/**
* Returns ERC20 token allowance
* @param provider Provider
* @param contractAddress ERC20 token address
* @param ownerAddress Owner address
* @param spenderAddress Spender address
* @returns Allowance amount
*/
export async function getERC20Allowance(
provider: PossibleProviders,
contractAddress: string,
ownerAddress: string,
spenderAddress: string
): Promise<BigNumber> {
const contract = new ethers.Contract(contractAddress, IERC20Artifact.abi, <Provider>provider);
return await contract.allowance(ownerAddress, spenderAddress);
}

/**
* Returns ERC20 contract instance
* @param contractAddress ERC20 contract address
* @param provider Provider
* @returns Contract instance
*/
export async function getERC20Contract(contractAddress: string, provider: PossibleProviders) {
return new ethers.Contract(contractAddress, IERC20Artifact.abi, <Provider>provider);
}

// const toEtherNum = (n: BigNumber) => +n.toString() / 1e18;
// const toNum = (n: BigNumber) => +n.toString();

Expand Down
236 changes: 113 additions & 123 deletions packages/dapp/components/lib/hooks/contracts/use-protocol-contracts.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/dapp/components/lib/hooks/use-balances.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const BalancesContextProvider: React.FC<ChildrenShim> = ({ children }) =>
usdt,
});
}

}

useEffect(() => {
Expand Down
5 changes: 4 additions & 1 deletion packages/dapp/components/lib/hooks/use-web-3.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JsonRpcProvider, JsonRpcSigner, Web3Provider } from "@ethersproject/providers";
import { useAccount, useProvider, useSigner } from "wagmi";
import { useAccount, useChainId, useProvider, useSigner } from "wagmi";
import { WagmiConfig, createClient } from "wagmi";
import { mainnet, localhost, foundry } from "wagmi/chains";
import { WalletConnectConnector } from "wagmi/connectors/walletConnect";
Expand All @@ -23,6 +23,7 @@ export type Web3State = {
connecting: boolean;
walletAddress: null | string;
signer?: JsonRpcSigner;
chainId: number;
};

const metamaskInstalled = (typeof window !== "undefined" ? window.ethereum : undefined);
Expand Down Expand Up @@ -101,6 +102,7 @@ const useWeb3 = (): Web3State => {
const provider = useProvider();
const { isConnecting, address } = useAccount();
const { data: signer } = useSigner();
const chainId = useChainId();

return {
metamaskInstalled,
Expand All @@ -110,6 +112,7 @@ const useWeb3 = (): Web3State => {
connecting: isConnecting,
walletAddress: address as string,
signer: signer as JsonRpcSigner,
chainId,
};
};

Expand Down
9 changes: 5 additions & 4 deletions packages/dapp/components/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ export const formatTimeDiff = (diff: number) => {

export const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";

// Governance token address in mainnet
export const GOVERNANCE_TOKEN_ADDRESS = "0x4e38D89362f7e5db0096CE44ebD021c3962aA9a0";
// Curve's Dollar-3CRVLP metapool in mainnet (TODO: update when we redeploy metapool with the new Dollar token)
export const CURVE_DOLLAR_3CRVLP_METAPOOL_ADDRESS = "0x20955CB69Ae1515962177D164dfC9522feef567E";

// Stable Coin Addresses
export const USDC_ADDRESS = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48";
export const DAI_ADDRESS = "0x6b175474e89094c44da98b954eedeac495271d0f";
Expand All @@ -122,10 +127,6 @@ export const CREDIT_USDT_ADDRESS = "0x9d498aB38Aa889AE0f4A865d30da2116ee9716bC";
// Uniswap Router address
export const V3_ROUTER_ADDRESS = "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45";

export const sushiSwapPoolAddress = "0x41e087485f47538752A1195D984109cB8Dc0E429";
export const dollar3poolMarketAddress = "0x20955CB69Ae1515962177D164dfC9522feef567E";
export const _3crvTokenAddress = "0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490";

export const safeParseEther = (val: string) => {
try {
return ethers.utils.parseEther(val);
Expand Down
9 changes: 3 additions & 6 deletions packages/dapp/components/redeem/lib/use-prices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ const usePrices = (): [BigNumber | null, BigNumber | null, () => Promise<void>]
return;
}

const contracts = await protocolContracts;

if (contracts.curveMetaPoolDollarTriPoolLp) {
const dollarTokenAddress = await contracts.managerFacet?.dollarTokenAddress();
const newTwapPrice = await contracts.twapOracleDollar3poolFacet?.consult(dollarTokenAddress);
const newSpotPrice = await contracts.curveMetaPoolDollarTriPoolLp["get_dy(int128,int128,uint256)"](0, 1, utils.parseEther("1"));
if (protocolContracts.curveDollar3CrvLpMetapool) {
const newTwapPrice = await protocolContracts.twapOracleDollar3poolFacet?.consult(protocolContracts.dollarToken?.address);
const newSpotPrice = await protocolContracts.curveDollar3CrvLpMetapool["get_dy(int128,int128,uint256)"](0, 1, utils.parseEther("1"));
setTwapPrice(newTwapPrice);
setSpotPrice(newSpotPrice);
}
Expand Down
130 changes: 0 additions & 130 deletions packages/dapp/components/utils/local-data.ts

This file was deleted.

27 changes: 1 addition & 26 deletions packages/dapp/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,12 @@
import { ethers } from "ethers";
import { FC, useState } from "react";
import { FC } from "react";
import "@uniswap/widgets/fonts.css";

import useProtocolContracts from "@/components/lib/hooks/contracts/use-protocol-contracts";
import useEffectAsync from "@/components/lib/hooks/use-effect-async";
import DollarPrice from "@/components/redeem/dollar-price";
import { fetchData } from "@/components/utils/local-data";

import dynamic from "next/dynamic";
const WalletConnectionWall = dynamic(() => import("@/components/ui/wallet-connection-wall"), { ssr: false }); //@note Fix: (Hydration Error)

const index: FC = (): JSX.Element => {
const [twapPrice, setTwapPrice] = useState<ethers.BigNumber | null>(null);
const protocolContracts = useProtocolContracts();

useEffectAsync(async () => {
if (protocolContracts != null) {
try {
console.log(twapPrice, "priced in ");
} catch (error) {
console.log("Error occurred while executing contract call", error);
setTwapPrice(null);
}
} else {
console.log("protocolContracts is null");
setTwapPrice(null);
}
}, []);

if (process.env.DEBUG === "true") {
fetchData();
}

return (
<WalletConnectionWall>
<DollarPrice />
Expand Down
Loading
Loading