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

Frax Convex Strategy with locked Frax Staked Convex LP tokens #1917

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
b92b96e
Fix Natspec of old Convex and ThreePool strategies
naddison36 Nov 7, 2023
31aa809
WIP ConvexFraxLockingStrategy
naddison36 Nov 7, 2023
339d415
Locked Frax Staked Convex deploy script
naddison36 Nov 7, 2023
c7b71dc
Merge remote-tracking branch 'origin/nicka/convex-frxeth-weth-libs' i…
naddison36 Nov 8, 2023
185bd20
Fix findBalancesSlot for FXS
naddison36 Nov 9, 2023
6eb4817
Added FraxConvexStrategy to hot deploy
naddison36 Nov 9, 2023
cd60c74
removed Balancer vault, wstETH and Curve frxETH/WETH from WhaleAddresses
naddison36 Nov 9, 2023
2f29886
Merge remote-tracking branch 'origin/nicka/convex-frxeth-weth-libs' i…
naddison36 Nov 9, 2023
48625da
Refactor of FraxConvexStrategy
naddison36 Nov 10, 2023
e8e0806
Fix lint and slither
naddison36 Nov 10, 2023
02e986a
Generated new contract diagrams
naddison36 Nov 10, 2023
9f3482e
Update comments
naddison36 Nov 13, 2023
e78d5ff
Merge remote-tracking branch 'origin/nicka/convex-frxeth-weth-libs' i…
naddison36 Nov 27, 2023
7b6dc6f
Updated FraxConvexStrategy code comments
naddison36 Nov 28, 2023
8ae4702
Merge remote-tracking branch 'origin/nicka/convex-frxeth-weth-libs' i…
naddison36 Nov 30, 2023
fa86a9f
Merge remote-tracking branch 'origin/nicka/convex-frxeth-weth-libs' i…
naddison36 Nov 30, 2023
86643d4
Updated Frax Convex deploy file
naddison36 Nov 30, 2023
a5ad85e
fix storage variables visibility
naddison36 Nov 30, 2023
c2ba94b
Frax Convex Strategy simplification (#1951)
naddison36 Nov 30, 2023
04db36e
Added check that all assets have the same number of decimals
naddison36 Dec 1, 2023
e77f6e8
Fix slither
naddison36 Dec 1, 2023
f0551f4
Generated latest FraxConvexStrategy diagrams
naddison36 Dec 1, 2023
71a8bf8
Polish Frax Convex Strategy comments
naddison36 Dec 1, 2023
d8d635e
Merge remote-tracking branch 'origin/nicka/convex-frxeth-weth-libs' i…
naddison36 Dec 1, 2023
4b90c23
Added Frax Convex deposit
naddison36 Dec 4, 2023
caa92ce
Skip Convex frxETH/WETH strategy as its no longer being used
naddison36 Dec 5, 2023
6353dd8
Enable FXS harvesting (#1954)
sparrowDom Dec 6, 2023
b397370
Merge remote-tracking branch 'origin/nicka/convex-frxeth-weth-libs' i…
naddison36 Dec 6, 2023
421320c
Merge remote-tracking branch 'origin/nicka/convex-frax-locking' into …
naddison36 Dec 6, 2023
230d15e
Added harvest of FXS to value flow
naddison36 Dec 6, 2023
40f4853
add comment regarding stacking of errors
sparrowDom Dec 6, 2023
5870d1d
Merge remote-tracking branch 'refs/remotes/origin/nicka/convex-frax-l…
sparrowDom Dec 6, 2023
3c5fd03
Removed MIN_LOCK_AMOUNT
naddison36 Dec 7, 2023
ff38071
Merge remote-tracking branch 'origin/nicka/convex-frax-locking' into …
naddison36 Dec 7, 2023
883b06b
Generated new contract diagrams
naddison36 Dec 7, 2023
cc4c40a
Small gas optimization
naddison36 Dec 8, 2023
dcb83d1
Update value flow diagrams (#1953)
naddison36 Jan 15, 2024
34fde41
Merge remote-tracking branch 'origin/master' into nicka/convex-frax-l…
naddison36 Jan 15, 2024
1d6e3de
Fix AMO tests (#1977)
shahthepro Jan 16, 2024
7fb738f
Merge remote-tracking branch 'origin/master' into nicka/convex-frax-l…
naddison36 Jan 16, 2024
717f72d
Changes from yAudit review (#1976)
naddison36 Jan 17, 2024
f0e747b
N-01 Lack of Indexed Event Parameters (#1973)
naddison36 Jan 17, 2024
a1bda8e
N-05 Added CURVE_VIRTUAL_PRICE_SCALE constant (#1974)
naddison36 Jan 17, 2024
826735c
Merge branch 'nicka/convex-frxeth-weth-libs' into nicka/convex-frax-l…
sparrowDom Jan 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
89 changes: 2 additions & 87 deletions README.md
Expand Up @@ -7,8 +7,7 @@ For more details about the product, checkout [our docs](https://docs.oeth.com).
| Branch | CI/CD Status |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `master` | [![Origin DeFi](https://github.com/OriginProtocol/origin-dollar/actions/workflows/defi.yml/badge.svg)](https://github.com/OriginProtocol/origin-dollar/actions/workflows/defi.yml) |
| `staging` | [![Origin DeFi](https://github.com/OriginProtocol/origin-dollar/actions/workflows/defi.yml/badge.svg?branch=staging)](https://github.com/OriginProtocol/origin-dollar/actions/workflows/defi.yml?query=branch%3Astaging) |
| `stable` | [![Origin DeFi](https://github.com/OriginProtocol/origin-dollar/actions/workflows/defi.yml/badge.svg?branch=stable)](https://github.com/OriginProtocol/origin-dollar/actions/workflows/defi.yml?query=branch%3Astable) |


## Requirements

Expand All @@ -32,7 +31,7 @@ cd origin-dollar

## Description

The `origin-dollar` project is a mono repo that hosts both the `smart contracts` and `dapp` code bases. In order to run this project locally, you will need to run both the `Eth node` and the `dapp` in separate processes or terminals.
The `origin-dollar` project is a repo that hosts the smart contracts of some Origin DeFi projects including OUSD and OETH. For Governance related contracts, head over to (origin-dollar-governance)[https://github.com/OriginProtocol/ousd-governance]. In order to run this project locally, you will need to run the `Eth node`.

### Eth Node

Expand All @@ -41,11 +40,6 @@ The `smart contracts` and all of their associated code are located in the `<proj
A variety of Hardhat [tasks](https://hardhat.org/guides/create-task.html) are available to interact with the contracts. Additional information can be found by running `npx hardhat` from the `contracts/` directory.
<br/><br/>

### dapp (Decentralized Application)

The code for `dapp` is located under the `/dapp` directory.
<br/><br/>

---

## Running the node
Expand Down Expand Up @@ -78,85 +72,6 @@ This is an option, but a simpler way is to use the `ACCOUNTS_TO_FUND` setting de
npx hardhat fund --amount 1000 --network localhost
```

##### Requirements

- You will need your web3 wallet configured before you can interact with the dapp. Make sure that you have one - refer to [this section](#configure-web3-wallet) for `Metamask` instructions.
- You will also need the dapp to be running. Refer to [this section](#running-the-dapp-locally) for instructions.

### Configure Web3 Wallet

You will need a web3 wallet to interact with the dapp and sign transactions. Below are the instructions to setup `Metamask` to interact with the dapp running locally.

- Install `Metamask` Chrome extension [HERE](https://metamask.io/)
- Create/Open `Metamask` wallet
- Add a custom RPC endpoint
- Name: `origin` - just an example
- URL: `http://localhost:8545`
- Chain ID: `1337`
<br/><br/>

#### Add Accounts to Metamask

##### Forked mode

Just use the account(s) you normally use on mainnet.

##### Standalone mode

You can get all the accounts for the locally running node and their associated private keys by running the command

```bash
# For Standalone mode
npx hardhat accounts --network localhost
```

Choose a test account past index 3 (accounts 0-3 are reserved).
Copy the private key and import it into Metamask as follows:

- Click the current account icon in the upper right corner of `Metamask`
- Select `Import Account` => paste private key => Click `Import`

Make sure that you select your newly created RPC endpoint in the networks dropdown and use your newly imported account in `Metamask`. You should now be setup to use `Metamask` to interact with the dApp.

Note:
If you want to add all the accounts via a new `Metamask` wallet and import the `mnemonic` it is located in `contracts/hardhat.config.js`. Make sure that you use Account 4 and up for test accounts as 0-3 are reserved.
<br/><br/>

### Running the dapp

Open a separate terminal to run the dapp in.

```bash
# Enter the smart dapp dir (or oeth-dapp)
cd dapp

# Install the dependencies
yarn install

# Start the dapp
yarn run start
```

- Open http://localhost:3000 in your browser and connect your `Metamask` account. See [this section](#configure-web3-wallet) for instructions if you have not done that yet.
- Open http://localhost:3000/swap and verify that you have stablecoins in your account. See [this section](#minting-stablecoins-via-hardhat-task) for instructions if you don't see a balance.

If you see a `Runtime Error: underlying network changed`, then rename `dapp/dev.env` to `.env` and restart `yarn`

If you see an error resembling `digital envelope routines::unsupported`, you are likely using an incompatible Node.js version. At last check, v16.20.2 is good.

### Troubleshooting

When freshly starting a node it is usually necessary to also reset Metamask Account being used:

- `Metamask` => `Settings` => `Advanced` => `Reset Account`
<br/><br/>
This will reset the nonce number that is incorrect if you have submitted any transactions in previous runs of the ethereum node. (Wallet has a too high nonce number comparing to the nonce state on the node)

If you get an `error Command "husky-run" not found.` type of error:
Go to root of the project and run `npx husky install`

---

## Running Smoke Tests

Smoke tests can be run in 2 modes:
Expand Down
107 changes: 107 additions & 0 deletions contracts/contracts/interfaces/IFraxConvexLocking.sol
@@ -0,0 +1,107 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IFraxConvexLocking {
/* ========== EVENTS ========== */
event LockedAdditional(
address indexed user,
bytes32 kek_id,
uint256 amount
);
event LockedLonger(
address indexed user,
bytes32 kek_id,
uint256 new_secs,
uint256 new_start_ts,
uint256 new_end_ts
);
event StakeLocked(
address indexed user,
uint256 amount,
uint256 secs,
bytes32 kek_id,
address source_address
);
event WithdrawLocked(
address indexed user,
uint256 liquidity,
bytes32 kek_id,
address destination_address
);

// Struct for the stake
struct LockedStake {
bytes32 kek_id;
uint256 start_timestamp;
uint256 liquidity;
uint256 ending_timestamp;
uint256 lock_multiplier; // 6 decimals of precision. 1x = 1000000
}

function curvePool() external view returns (address);

function curveToken() external view returns (address);

function earned(address account)
external
view
returns (uint256[] memory new_earned);

function getAllRewardTokens() external view returns (address[] memory);

function getReward(address destination_address)
external
returns (uint256[] memory);

function getReward2(address destination_address, bool claim_extra_too)
external
returns (uint256[] memory);

function getRewardForDuration()
external
view
returns (uint256[] memory rewards_per_duration_arr);

function lastRewardClaimTime(address) external view returns (uint256);

function lastUpdateTime() external view returns (uint256);

function lockAdditional(bytes32 kek_id, uint256 addl_liq) external;

function lockLonger(bytes32 kek_id, uint256 new_ending_ts) external;

function lockMultiplier(uint256 secs) external view returns (uint256);

function lockedLiquidityOf(address account) external view returns (uint256);

function lockedStakes(address, uint256)
external
view
returns (
bytes32 kek_id,
uint256 start_timestamp,
uint256 liquidity,
uint256 ending_timestamp,
uint256 lock_multiplier
);

function lockedStakesOf(address account)
external
view
returns (LockedStake[] memory);

function lockedStakesOfLength(address account)
external
view
returns (uint256);

function stakeLocked(uint256 liquidity, uint256 secs)
external
returns (bytes32);

function withdrawLocked(
bytes32 kek_id,
address destination_address,
bool claim_rewards
) external returns (uint256);
}
69 changes: 69 additions & 0 deletions contracts/contracts/interfaces/IFraxConvexStaking.sol
@@ -0,0 +1,69 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IFraxConvexStaking is IERC20 {
event Deposited(
address indexed _user,
address indexed _account,
uint256 _amount,
bool _wrapped
);
event Withdrawn(address indexed _user, uint256 _amount, bool _unwrapped);
event RewardInvalidated(address _rewardToken);
event RewardRedirected(address indexed _account, address _forward);
event RewardAdded(address _token);
event Shutdown();

struct EarnedData {
address token;
uint256 amount;
}

function collateralVault() external view returns (address);

function convexBooster() external view returns (address);

function convexPool() external view returns (address);

function convexPoolId() external view returns (uint256);

function convexToken() external view returns (address);

function curveToken() external view returns (address);

function deposit(uint256 _amount, address _to) external;

function earned(address _account)
external
returns (EarnedData[] memory claimable);

function getReward(address _account, address _forwardTo) external;

function getReward(address _account) external;

function isShutdown() external view returns (bool);

function rewardLength() external view returns (uint256);

function rewardRedirect(address) external view returns (address);

function rewards(uint256)
external
view
returns (
address reward_token,
address reward_pool,
uint256 reward_integral,
uint256 reward_remaining
);

function stake(uint256 _amount, address _to) external;

function totalBalanceOf(address _account) external view returns (uint256);

function withdraw(uint256 _amount) external;

function withdrawAndUnwrap(uint256 _amount) external;
}
4 changes: 3 additions & 1 deletion contracts/contracts/mocks/MockOracleRouterNoStale.sol
Expand Up @@ -25,7 +25,9 @@ contract MockOracleRouterNoStale is OracleRouter {

// @notice Oracle Router used to bypass staleness
contract MockOETHOracleRouterNoStale is OETHOracleRouter {
constructor(address auraPriceFeed) OETHOracleRouter(auraPriceFeed) {}
constructor(address auraPriceFeed, address fxsPriceFeed)
OETHOracleRouter(auraPriceFeed, fxsPriceFeed)
{}

function feedMetadata(address asset)
internal
Expand Down
14 changes: 13 additions & 1 deletion contracts/contracts/oracle/OETHOracleRouter.sol
Expand Up @@ -10,9 +10,11 @@ contract OETHOracleRouter is OracleRouterBase {
using StableMath for uint256;

address public immutable auraPriceFeed;
address public immutable fxsPriceFeed;

constructor(address _auraPriceFeed) {
constructor(address _auraPriceFeed, address _fxsPriceFeed) {
auraPriceFeed = _auraPriceFeed;
fxsPriceFeed = _fxsPriceFeed;
}

/**
Expand Down Expand Up @@ -105,6 +107,16 @@ contract OETHOracleRouter is OracleRouterBase {
// AURA/ETH
feedAddress = auraPriceFeed;
maxStaleness = 0;
} else if (asset == 0x3432B6A60D23Ca0dFCa7761B7ab56459D9C964D0) {
/* FXS/ETH PriceFeedPar feed contract
*
* Is combining the following to feeds to achieve target feed:
* - https://data.chain.link/ethereum/mainnet/crypto-usd/fxs-usd
* - https://data.chain.link/ethereum/mainnet/crypto-usd/eth-usd (inverted)
*/
feedAddress = fxsPriceFeed;
// eth-usd heartbeat is 1 hour and fxs-usd feed is 1 day
maxStaleness = 1 days + STALENESS_BUFFER;
} else {
revert("Asset not available");
}
Expand Down