Skip to content

Commit

Permalink
Merge branch 'ubiquity:development' into facet-clock
Browse files Browse the repository at this point in the history
  • Loading branch information
molecula451 committed Oct 20, 2023
2 parents 97fc4c5 + 97989f1 commit fad6671
Show file tree
Hide file tree
Showing 29 changed files with 296 additions and 295 deletions.
20 changes: 0 additions & 20 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,3 @@
- We rebranded "Bonding" to "Staking" to disambiguate our bonds (e.g. Chicken Bonds) branding.
- We rebranded "Debts" to "Credits" because it has a positive connotation for the users.
- We rebranded "Ubiquity Algorithmic Dollar" to "Ubiquity Dollar" because the term "algorithmic" is contentious in this context after Luna.
- Filenames should be in kebab-case for example (note as of writing this we still have to fix this):
- credit-nft-manager.sol
- credit-nft-redemption-calculator.sol
- credit-nft.sol
- credit-redemption-calculator.sol
- credit-token.sol
- dollar-manager.sol
- dollar-mint-calculator.sol
- dollar-mint-excess.sol
- dollar-token.sol
- dollar3pool-oracle.sol
- erc1155-ubiquity.sol
- erc20-ubiquity.sol
- formulas.sol
- governance-token.sol
- masterchef-ubiquity.sol
- staking-formulas.sol
- staking-token.sol
- staking.sol
- transfer-hooks/dollar3pool.sol
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Setup Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly-d369d2486f85576eec4ca41d277391dfdae21ba7
version: nightly-5be158ba6dc7c798a6f032026fe60fc01686b33b

- name: Yarn Install
run: yarn install --mode=skip-build && yarn allow-scripts
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coverage-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Setup Foundry
uses: onbjerg/foundry-toolchain@v1
with:
version: nightly-d369d2486f85576eec4ca41d277391dfdae21ba7
version: nightly-5be158ba6dc7c798a6f032026fe60fc01686b33b

- name: Install dependencies
run: sudo apt-get install lcov
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deep-fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly-d369d2486f85576eec4ca41d277391dfdae21ba7
version: nightly-5be158ba6dc7c798a6f032026fe60fc01686b33b

- name: Forge install
working-directory: packages/contracts
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/generate-doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Setup Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly-d369d2486f85576eec4ca41d277391dfdae21ba7
version: nightly-5be158ba6dc7c798a6f032026fe60fc01686b33b

- name: Yarn Install
run: yarn install --mode=skip-build && yarn allow-scripts
Expand Down
11 changes: 0 additions & 11 deletions global.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"lint-staged": {
"*.{js,jsx,ts,tsx,json}": [
"prettier --write",
"eslint --fix",
"eslint --fix --max-warnings=0",
"cspell --no-must-find-files"
],
"*.sol": [
Expand Down
11 changes: 6 additions & 5 deletions packages/dapp/components/layout/anvil/anvil-rpcs.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React from "react";
import Button from "../../ui/button";
import { methodConfigs } from "./method-configs";
import useWeb3 from "@/components/lib/hooks/use-web-3";
import { LOCAL_NODE_ADDRESS } from "@/components/lib/hooks/use-web-3";
import { useState } from "react";

export default function AnvilRpcs() {
const [isHidden, setIsHidden] = React.useState<boolean>(true);
const [isVisible, setIsVisible] = React.useState<number>(0);
const [methodArgs, setMethodArgs] = React.useState<Record<string, string>>({});
const [isHidden, setIsHidden] = useState<boolean>(true);
const [isVisible, setIsVisible] = useState<number>(0);
const [methodArgs, setMethodArgs] = useState<Record<string, string>>({});
const { signer } = useWeb3();

const handleFetch = async (method: string, params: unknown[]) => {
const result = await fetch("http://localhost:8545", {
const result = await fetch(LOCAL_NODE_ADDRESS, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
3 changes: 2 additions & 1 deletion packages/dapp/components/layout/inventory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import icons from "@/ui/icons";

import useManagerManaged from "../lib/hooks/contracts/use-manager-managed";
import useNamedContracts from "../lib/hooks/contracts/use-named-contracts";
import useBalances, { Balances } from "../lib/hooks/use-balances";
import useBalances from "../lib/hooks/use-balances";
import { ManagedContracts } from "../lib/hooks/contracts/use-manager-managed";
import { Balances } from "../lib/types";

const Inventory = () => {
const { walletAddress } = useWeb3();
Expand Down
1 change: 0 additions & 1 deletion packages/dapp/components/lib/app-context-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ManagedContractsContextProvider } from "./hooks/contracts/use-manager-managed";
import { BalancesContextProvider } from "./hooks/use-balances";
import { TransactionsContextProvider } from "./hooks/use-transaction-logger";
import { UseWeb3Provider } from "./hooks/use-web-3";
Expand Down
7 changes: 3 additions & 4 deletions packages/dapp/components/lib/contracts-shortcuts.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { BigNumber, ethers } from "ethers";
import { ERC1155Ubiquity, ERC20 } from "types";
import { BigNumber, ethers, Contract } from "ethers";

import { performTransaction } from "./utils";

export async function ensureERC20Allowance(
logName: string,
contract: ERC20,
contract: Contract,
amount: BigNumber,
signer: ethers.providers.JsonRpcSigner,
spender: string,
Expand All @@ -25,7 +24,7 @@ export async function ensureERC20Allowance(
return true;
}

export async function ensureERC1155Allowance(logName: string, contract: ERC1155Ubiquity, signer: ethers.providers.JsonRpcSigner, spender: string): Promise<boolean> {
export async function ensureERC1155Allowance(logName: string, contract: Contract, signer: ethers.providers.JsonRpcSigner, spender: string): Promise<boolean> {
const signerAddress = await signer.getAddress();
const isAllowed = await contract.isApprovedForAll(signerAddress, spender);
console.log(`${logName} isAllowed: `, isAllowed);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import useWeb3, { PossibleProviders } from "../use-web-3";

import Deployed_Contracts from "@ubiquity/contracts/deployments.json";
import NAMED_ACCOUNTS from "../../../config/named-accounts.json";
import { getCurveFactoryContract, getDebtCouponManagerContract, getERC20Contract, getIJarContract, getYieldProxyContract } from "@/components/utils/contracts";

const getDebtCouponManagerAddress = () => {
const contractDeployments: Record<string, any> = Deployed_Contracts;
const record = contractDeployments["1"] ?? {};
const contract = record?.contracts ? record?.contracts["DebtCouponManager"] : undefined;
return contract ? contract.address : undefined;
};
export const DEBT_COUPON_MANAGER_ADDRESS = getDebtCouponManagerAddress();
import { getCurveFactoryContract, getERC20Contract, getIJarContract, getYieldProxyContract } from "@/components/utils/contracts";

export type NamedContracts = ReturnType<typeof connectedContracts> | null;
export function connectedContracts(provider: NonNullable<PossibleProviders>) {
Expand All @@ -20,7 +11,6 @@ export function connectedContracts(provider: NonNullable<PossibleProviders>) {
usdc: getERC20Contract(NAMED_ACCOUNTS.USDC, provider),
dai: getERC20Contract(NAMED_ACCOUNTS.DAI, provider),
usdt: getERC20Contract(NAMED_ACCOUNTS.USDT, provider),
debtCouponManager: getDebtCouponManagerContract(DEBT_COUPON_MANAGER_ADDRESS, provider),
jarUsdc: getIJarContract(NAMED_ACCOUNTS.jarUSDCAddr, provider),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Contract, ethers } from "ethers";

import latestDeployment from "@ubiquity/contracts/broadcast/05_StakingShare.s.sol/31337/run-latest.json";
import useWeb3 from "../use-web-3";
import { sushiSwapPoolAddress, dollar3poolMarketAddress } from "@/lib/utils";

// contract build artifacts
// separately deployed contracts
Expand All @@ -27,59 +28,66 @@ import StakingFacetArtifact from "@ubiquity/contracts/out/StakingFacet.sol/Staki
import StakingFormulasFacetArtifact from "@ubiquity/contracts/out/StakingFormulasFacet.sol/StakingFormulasFacet.json";
import TWAPOracleDollar3poolFacetArtifact from "@ubiquity/contracts/out/TWAPOracleDollar3poolFacet.sol/TWAPOracleDollar3poolFacet.json";
import UbiquityPoolFacetArtifact from "@ubiquity/contracts/out/UbiquityPoolFacet.sol/UbiquityPoolFacet.json";
// other related contracts
// import SushiSwapPoolArtifact from "@ubiquity/contracts/out/SushiSwapPool.sol/SushiSwapPool.json";
import IMetaPoolArtifact from "@ubiquity/contracts/out/IMetaPool.sol/IMetaPool.json";
import UniswapV2PairABI from "@/components/config/abis/uniswap-v-2-pair.json";

/**
* Returns all of the available protocol contracts.
*
* Returns all of the available protocol contracts
*
* Right now the Ubiquity org uses:
* - separately deployed contracts (https://github.com/ubiquity/ubiquity-dollar/tree/development/packages/contracts/src/dollar/core)
* - contracts deployed as diamond proxy facets (https://github.com/ubiquity/ubiquity-dollar/tree/development/packages/contracts/src/dollar/facets)
*
*
* The following contracts are not exported for various reasons (but feel free
* to export new contracts when you need them):
*
*
* Contracts not used in the UI (as far as I understand):
* - https://github.com/ubiquity/ubiquity-dollar/blob/development/packages/contracts/src/dollar/core/ERC1155Ubiquity.sol
* - https://github.com/ubiquity/ubiquity-dollar/blob/development/packages/contracts/src/dollar/core/ERC20Ubiquity.sol
* - https://github.com/ubiquity/ubiquity-dollar/blob/development/packages/contracts/src/dollar/facets/DiamondCutFacet.sol
* - https://github.com/ubiquity/ubiquity-dollar/blob/development/packages/contracts/src/dollar/facets/DiamondLoupeFacet.sol
* - https://github.com/ubiquity/ubiquity-dollar/blob/development/packages/contracts/src/dollar/Diamond.sol
* - https://github.com/ubiquity/ubiquity-dollar/blob/development/packages/contracts/src/dollar/DirectGovernanceFarmer.sol
*
*
* Contracts not yet integrated (i.e. not used in other solidity contracts):
* - https://github.com/ubiquity/ubiquity-dollar/blob/development/packages/contracts/src/dollar/core/CreditClock.sol
*
*
* Contracts on hold (i.e. obsolete) until we find a better utility for them:
* - https://github.com/ubiquity/ubiquity-dollar/tree/development/packages/contracts/src/ubiquistick
*/
const useProtocolContracts = () => {
export type ProtocolContracts = ReturnType<typeof useProtocolContracts> | null;
const useProtocolContracts = async () => {
// get current web3 provider
const { provider } = useWeb3();

// all protocol contracts
const protocolContracts: {
// separately deployed contracts (i.e. not part of the diamond)
creditNft: Contract | null,
creditToken: Contract | null,
dollarToken: Contract | null,
governanceToken: Contract | null,
stakingShare: Contract | null,
creditNft: Contract | null;
creditToken: Contract | null;
dollarToken: Contract | null;
governanceToken: Contract | null;
stakingShare: Contract | null;
// diamond facets
accessControlFacet: Contract | null,
chefFacet: Contract | null,
collectableDustFacet: Contract | null,
creditNftManagerFacet: Contract | null,
creditNftRedemptionCalculatorFacet: Contract | null,
creditRedemptionCalculatorFacet: Contract | null,
curveDollarIncentiveFacet: Contract | null,
dollarMintCalculatorFacet: Contract | null,
dollarMintExcessFacet: Contract | null,
managerFacet: Contract | null,
ownershipFacet: Contract | null,
stakingFacet: Contract | null,
stakingFormulasFacet: Contract | null,
twapOracleDollar3poolFacet: Contract | null,
ubiquityPoolFacet: Contract | null,
accessControlFacet: Contract | null;
chefFacet: Contract | null;
collectableDustFacet: Contract | null;
creditNftManagerFacet: Contract | null;
creditNftRedemptionCalculatorFacet: Contract | null;
creditRedemptionCalculatorFacet: Contract | null;
curveDollarIncentiveFacet: Contract | null;
dollarMintCalculatorFacet: Contract | null;
dollarMintExcessFacet: Contract | null;
managerFacet: Contract | null;
ownershipFacet: Contract | null;
stakingFacet: Contract | null;
stakingFormulasFacet: Contract | null;
twapOracleDollar3poolFacet: Contract | null;
ubiquityPoolFacet: Contract | null;
sushiPoolGovernanceDollarLp: Contract | null;
curveMetaPoolDollarTriPoolLp: Contract | null;
} = {
// separately deployed contracts (i.e. not part of the diamond)
creditNft: null,
Expand All @@ -103,31 +111,33 @@ const useProtocolContracts = () => {
stakingFormulasFacet: null,
twapOracleDollar3poolFacet: null,
ubiquityPoolFacet: null,
// related contracts
sushiPoolGovernanceDollarLp: null,
curveMetaPoolDollarTriPoolLp: null,
};

let diamondAddress = '';
let diamondAddress = "";

// for all of the deployment transactions
latestDeployment.transactions.map(tx => {
if (tx.transactionType === 'CREATE') {
latestDeployment.transactions.map((tx) => {
if (tx.transactionType === "CREATE") {
// find contracts that deployed separately (i.e. not part of the diamond)
if (tx.contractName === 'CreditNft') {
if (tx.contractName === "CreditNft") {
protocolContracts.creditNft = new ethers.Contract(tx.contractAddress, CreditNftArtifact.abi, <Provider>provider);
}
if (tx.contractName === 'UbiquityCreditToken') {
if (tx.contractName === "UbiquityCreditToken") {
protocolContracts.creditToken = new ethers.Contract(tx.contractAddress, UbiquityCreditTokenArtifact.abi, <Provider>provider);
}
if (tx.contractName === 'UbiquityDollarToken') {
if (tx.contractName === "UbiquityDollarToken") {
protocolContracts.dollarToken = new ethers.Contract(tx.contractAddress, UbiquityDollarTokenArtifact.abi, <Provider>provider);
}
if (tx.contractName === 'UbiquityGovernanceToken') {
if (tx.contractName === "UbiquityGovernanceToken") {
protocolContracts.governanceToken = new ethers.Contract(tx.contractAddress, UbiquityGovernanceTokenArtifact.abi, <Provider>provider);
}
if (tx.contractName === 'StakingShare') {
if (tx.contractName === "StakingShare") {
protocolContracts.stakingShare = new ethers.Contract(tx.contractAddress, StakingShareArtifact.abi, <Provider>provider);
}
// find the diamond address
if (tx.contractName === 'Diamond') diamondAddress = tx.contractAddress;
if (tx.contractName === "Diamond") diamondAddress = tx.contractAddress;
}
});

Expand All @@ -148,6 +158,18 @@ const useProtocolContracts = () => {
protocolContracts.twapOracleDollar3poolFacet = new ethers.Contract(diamondAddress, TWAPOracleDollar3poolFacetArtifact.abi, <Provider>provider);
protocolContracts.ubiquityPoolFacet = new ethers.Contract(diamondAddress, UbiquityPoolFacetArtifact.abi, <Provider>provider);

// other related contracts
// const sushiSwapPool = await protocolContracts.managerFacet.sushiSwapPoolAddress();
// const sushiSwapPoolContract = new ethers.Contract(sushiSwapPool, SushiSwapPoolArtifact.abi, <Provider>provider);
// const UniswapV2PairContract = new ethers.Contract(await sushiSwapPoolContract.pair(), UniswapV2PairABI, <Provider>provider);
const UniswapV2PairContract = new ethers.Contract(sushiSwapPoolAddress, UniswapV2PairABI, <Provider>provider);
protocolContracts.sushiPoolGovernanceDollarLp = UniswapV2PairContract;

// const dollar3poolMarket = await protocolContracts.managerFacet.stableSwapMetaPoolAddress();
// const metaPoolContract = new ethers.Contract(dollar3poolMarket, IMetaPoolArtifact.abi, <Provider>provider);
const metaPoolContract = new ethers.Contract(dollar3poolMarketAddress, IMetaPoolArtifact.abi, <Provider>provider);
protocolContracts.curveMetaPoolDollarTriPoolLp = metaPoolContract;

return protocolContracts;
};

Expand Down
Loading

0 comments on commit fad6671

Please sign in to comment.