Skip to content

Commit

Permalink
veSDL contracts (saddle-finance#620)
Browse files Browse the repository at this point in the history
* Add veToken contracts

* Add vyper compiler settings and update dependency paths

* Add deployment scripts for the system contracts

* Update any token names to SDL

* Add deploy script for FeeDistributor

* Update package.json for correct typechain output

* Apply workaround for vyper imports

* Add a typical user case for veSDL

* Deploy gauges for each valid LP

* Add test cases for boosting your LP deposits

* Refactor burn to donate on FeeDistributor

* Add withdraw case for liquidity gauge more helper functions

* Add fee distributor test cases

* Add a setup script that can be modified for frontend testings

* Add HelperContract for easier gauge -> pool data access

* Added script to test gauge weights. (saddle-finance#573)

* Added script to test gauge weights.

Added to the exampleSetup script to mock a lock of sdl
and a change of the weight of the usdcv2 gauge.

* Added logging for all gauges.

* Removed gaslimit from config, estimated gas within script.

Removed the unneeded gas limit from hardhat config, estimated
gas for all vyper calls individually.

* Add gas estimation for change gauge weight.

* Update helper contract to get gauge rewards (saddle-finance#579)

* Renamed helper contract, added getting gauge rewards *broken

Currently not compiling. Renamed helper contract and all
occurences. Added getGaugeRewards() to find all rewards
for a gauge.

* Updated types for rewardTokenAddresses().

* Helper contract correctly calls reward_data().

Renamed helper contract deploy script, helper contract
includes getGaugeRewards() to retrieve all rewards for a
given gauge address.

* New function getClaimableRewards gets a users claimable tokens

Added getClaimableRewards(gauge address, user address) to find
all reward token balances a user has on a certain gauge.

* Updated script to test helper contract checking rewards.

* Updated LiquidityGauge contract add_reward()

Added token address to Reward struct within add_reward() in
the Liquidity gauge contract. Cleaned up and commented
checkGaugeRewards script.

* Fixed case of constant variable.

* Added assert to check for zero address of token.

* Add sdl rewards to mike's local script (saddle-finance#587)

* Use D4 pool LP token as the token to distribute to veSDL holders (saddle-finance#592)

* Use D4 pool LP token as the token to distribute to veSDL holders

* Add a setup script for checking fee distributor claimables

* Add multisig as a namedAccount

* Create a deploy script that mirrors multisig actions after deployments of VotingEscrow (saddle-finance#600)

* Add checkAll script to use with forked mainnet environment

* Call transfer ownership on GaugeController

* Modify intial Minter rate. Move set up script to deploy script

* Remove checkAll set up script.

* Use SushiSwapPair address for Fee token

* Adds a utils time file for time related helper functions

* Deploy a dummy token for SLP that is used for FeeDistributor contract (saddle-finance#608)

* Rename folder path for gauges (saddle-finance#609)

* Add bridge calls to multisig script  (saddle-finance#604)

* Updated multisig actions to transfer sdl to L2's.

Still todo:
arbitrum outBoundTransfer() not working
evmos, not working because of recipient field

* Typo addition.

* Fix incorrect parameters

* Arbitrum bridge requires encoding max submission cost as data
* Approve the SDL gateway before initiating call through arbitrum
  gateway router.
* Evmos reciepient need to be padded to 32 bytes

Co-authored-by: Michael Daly <[email protected]>

* Skip 599 deploy script if we are on hardhat (saddle-finance#610)

* Change paramters for `add_gauge` call (saddle-finance#614)

- Second parameter is supposed to be gauge_type and third is intial
  weight. This commit updates add_gauge calls to fix this.

* Merge master and copy over any vesdl deploy scripts to hardhat folder (saddle-finance#615)

* Add LP token Script (saddle-finance#612)

* Add LP token

* Change package-lock.json back

Co-authored-by: Jongseung Lim <[email protected]>

* Create a hardhat specific deploy folder. (saddle-finance#613)

- This is to make managing deploy scripts easier per network

* Copy some of the vesdl related deploy scripts to hardhat

Co-authored-by: Duy Nguyen <[email protected]>

* Add RootGaugeLocal contract (saddle-finance#605)

* Add RootGaugeLocal contract

* Add forked cross chain gauge contracts

* Fix child_chain_streamer bug, add vyper compilers

* Add 'localhost' deploy folder as copy of 'mainnet'

* Add cross chain contracts test deployment scripts

* Delete duplicate file

* Linting fix

* Fix some of the incorrect parameters

* Ensure the localhost gauge type weight is 1e18
* Ensure the localhost gauge type index is at 1
* Ensure the ERC20 symbol and name are in the right order

* Use strict equality

Co-authored-by: Hannes P <[email protected]>

* Cleanup example setup script and update it to recognize RootGauge (saddle-finance#617)

* Changes the initial Minter rate to 1.25M SDL/WEEK or 5M SDL/Month (saddle-finance#625)

* Add RootGauge contracts (saddle-finance#619)

* Add 'RootGaugeArbitrum' contract

* Fix constructor argument docs (add _lp_symbol)

* Add 'RootGaugeEvmos.vy' contract

* Add Optimism RootGauge, fix Arbitrum and Evmos RootGauges

* Fix checkpoint function docstrings

* Add `name()` function to RootGauges

* Add dummy initial weights for testing and more console output (saddle-finance#621)

* prints a table of intial weights in 599

* Register contracts related to VotingEscrow  (saddle-finance#623)

* Register contracts related to VotingEscrow

* Add comments and cleanup imports

* Register the contracts on mainnet deployments

* Add couple test cases for RootGaugeLocal contract (saddle-finance#618)

* Add couple test cases for RootGaugeLocal contract

* Add names() function to RootGaugeLocal

* Add MAX_REWARDS constant matching the contract's

* Change helper contract logic to return empty data on reverts (saddle-finance#628)

* Refactored old gauge scripts into first/second week setup. (saddle-finance#622)

* Refactored old gauge scripts into firstweek setup and ff.

Removed checkGaugeRewards and exampleSetup for new first
and sendond week scripts. First week sets gauge weights
and rewards. Second week fast forwards one week and checks
claimable rewards.

* Removed adding root gauges to gauge controller for testing

* Updated relative gauge weight calls to use _write

* removed unneeded const/import added comments

* updated assert, updated readability

* Cleaned up comments, removed un-needed logs.

* Removed un-needed scipts

* Change flow to account for time between deploying the contracts and the
first epoch

* Enable transferability on hardhat

Co-authored-by: Jongseung Lim <[email protected]>

* Add a gauge with a non Saddle token as the staking token (saddle-finance#629)

* This is to mainly test the case when we add Sushiswap LP token to a
  gauge. Combined with saddle-finance#628 the frontend can detect if the staking token
is a saddle LP token.

* Update distributed token to SDL/WETH pair token (saddle-finance#631)

* Allow resuming the script when out of gas (saddle-finance#633)

* Added initial gauge weights for current pools and sushi swap pair

* adding deployment data

* removing unneeded script

* Linting and add skip field to 599 (saddle-finance#634)

* Add 'working_balance' logging to setup script (saddle-finance#635)

* Add logging for 'working_balances' (not tested)

* Add logging 'working_supply' of gauge

* Add 'gas_limit' to 'user_checkpoint' call

* Fix 'user_checkpoint'call

* Print boost value per signers

* Adding fraxBP and alUSD/SUSD/USDT metapools (saddle-finance#636)

* adding fraxBP and alUSD/SUSD/USDT metapools

* updated scripts to add new deploys to registry

* Added USDs metapool to arbitrum, cleaned up scripts

* Refactor deploys to utilize deployUtils

* Abstracted check tokens to deployUtils

* Ran lint:fix

* Updated alUSD decimals

* Dont change package-lock.json

* Added decimal check to deploy utils

* Linter fixes

* removed unneeded susd deployment

* added correct USDT deployment for fantom

* changed file name typo

* removed deploy scripts for SUSD

* fixed typo in arbitrum register script

* fixed typo in file names

Co-authored-by: Jongseung (John) Lim <[email protected]>

* Deploy frax liq v5 gauges (saddle-finance#637)

* Add deploy script for FRAX mainnet LiqV5 gauges

* Fix eslint changes

* Change deploy script name to '580..'

* Add Frax pool deployment data (saddle-finance#640)

* Add Arbitrum deployment data

* Optimism deployment data

* Fantom deployment data

* Improve continuing the deploy script

* Add mainnet deployment data

* added hard codded api keys for L2's

Co-authored-by: Michael Daly <[email protected]>

* Draft for smart wallet checker (saddle-finance#641)

* Deploy SmartWalletChecker and add Frax's multisig as approved wallet (saddle-finance#642)

* Re-deploy SmartWalletChecker (saddle-finance#643)

* Deploy SmartWalletChecker and add Frax's multisig as approved wallet

* Redeploy SmartWalletChecker

* aleth frax pool updated deployments (saddle-finance#646)

* updated deployments of alUSD pools on mainnet and fantom

* adding partial deployment

* Deployed updated alUSD metapools and associated contracts

* registered new alUSD pool on mainnnet and fantom

* removing one-off scripts

* Fix broken tests caused by parameter changes (saddle-finance#649)

* Update package-lock.json

* Dont run fee distributor test on coverage

Co-authored-by: mjdatadog <[email protected]>
Co-authored-by: David Hamme <[email protected]>
Co-authored-by: Michael Daly <[email protected]>
Co-authored-by: Duy Nguyen <[email protected]>
Co-authored-by: Hannes P <[email protected]>
  • Loading branch information
6 people authored Jul 8, 2022
1 parent e6b10e0 commit be4fe59
Show file tree
Hide file tree
Showing 185 changed files with 67,091 additions and 3,147 deletions.
6 changes: 0 additions & 6 deletions .solcover.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
const shell = require('shelljs'); // This module is already a solidity-coverage dep

module.exports = {
onCompileComplete: async function(config){
shell.exec("typechain --target ethers-v5 --outDir ./build/typechain './build/artifacts/*.json'");
},
onIstanbulComplete: async function(config){
shell.rm('-rf', './build/typechain'); // Clean up at the end
},
// TODO: remove VirtualSwap from skipFiles once coverage is added
// TODO: add coverage for older contracts
skipFiles: [
Expand Down
122 changes: 122 additions & 0 deletions contracts/helper/GaugeHelperContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "../interfaces/IMasterRegistry.sol";
import "../interfaces/IPoolRegistry.sol";

interface ILiquidityGaugeV5 {
struct Reward {
address token;
address distributor;
uint256 period_finish;
uint256 rate;
uint256 last_update;
uint256 integral;
}

function lp_token() external view returns (address);

// reward_count
function reward_count() external view returns (uint256);

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

function reward_data(address) external view returns (Reward memory);

function claimable_reward(address, address) external view returns (uint256);
}

interface ILPToken {
function owner() external view returns (address);
}

contract GaugeHelperContract {
IMasterRegistry public immutable MASTER_REGISTRY;
bytes32 public constant POOL_REGISTRY_NAME =
0x506f6f6c52656769737472790000000000000000000000000000000000000000;

constructor(address _masterRegistry) public {
MASTER_REGISTRY = IMasterRegistry(_masterRegistry);
}

function gaugeToPoolAddress(address gauge) public view returns (address) {
try ILiquidityGaugeV5(gauge).lp_token() returns (
address saddleLpToken
) {
try ILPToken(saddleLpToken).owner() returns (
address saddlePoolAddress
) {
return saddlePoolAddress;
} catch {
return address(0);
}
} catch {
// Returns zero address if the gauge is not directly using saddle LP token
return address(0);
}
}

function gaugeToPoolData(address gauge)
public
view
returns (IPoolRegistry.PoolData memory)
{
// Get PoolRegistry from MasterRegistry
IPoolRegistry poolRegistry = IPoolRegistry(
MASTER_REGISTRY.resolveNameToLatestAddress(POOL_REGISTRY_NAME)
);

// Try getting pool data
try poolRegistry.getPoolData(gaugeToPoolAddress(gauge)) returns (
IPoolRegistry.PoolData memory poolData
) {
return poolData;
} catch {
// Returns zero address if the gauge is not directly using saddle LP token
IPoolRegistry.PoolData memory poolData;
return poolData;
}
}

function getGaugeRewards(address gauge)
public
view
returns (ILiquidityGaugeV5.Reward[] memory)
{
uint256 rewardCount = ILiquidityGaugeV5(gauge).reward_count();
address[] memory rewardTokens = new address[](rewardCount);
for (uint256 i = 0; i < rewardCount; i++) {
rewardTokens[i] = ILiquidityGaugeV5(gauge).reward_tokens(i);
}
// call reward_data() will all reward token addresses
ILiquidityGaugeV5.Reward[]
memory rewardData = new ILiquidityGaugeV5.Reward[](rewardCount);
for (uint256 i = 0; i < rewardCount; i++) {
rewardData[i] = ILiquidityGaugeV5(gauge).reward_data(
rewardTokens[i]
);
}
return rewardData;
}

function getClaimableRewards(address gauge, address user)
public
view
returns (uint256[] memory)
{
uint256 rewardCount = ILiquidityGaugeV5(gauge).reward_count();
address[] memory rewardTokens = new address[](rewardCount);
for (uint256 i = 0; i < rewardCount; i++) {
rewardTokens[i] = ILiquidityGaugeV5(gauge).reward_tokens(i);
}
// call reward_data() will all reward token addresses
uint256[] memory claimableRewards = new uint256[](rewardCount);
for (uint256 i = 0; i < rewardCount; i++) {
claimableRewards[i] = ILiquidityGaugeV5(gauge).claimable_reward(
user,
rewardTokens[i]
);
}
return claimableRewards;
}
}
41 changes: 41 additions & 0 deletions contracts/helper/GenericERC20NoOwnerFunction.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.6.12;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

/**
* @title Generic ERC20 token
* @notice This contract simulates a generic ERC20 token that is mintable and burnable.
*/
contract GenericERC20NoOwnerFunction is ERC20 {
address private immutable _owner;

/**
* @notice Deploy this contract with given name, symbol, and decimals
* @dev the caller of this constructor will become the owner of this contract
* @param name_ name of this token
* @param symbol_ symbol of this token
* @param decimals_ number of decimals this token will be based on
*/
constructor(
string memory name_,
string memory symbol_,
uint8 decimals_
) public ERC20(name_, symbol_) {
_setupDecimals(decimals_);
_owner = msg.sender;
}

/**
* @notice Mints given amount of tokens to recipient
* @dev only owner can call this mint function
* @param recipient address of account to receive the tokens
* @param amount amount of tokens to mint
*/
function mint(address recipient, uint256 amount) external {
require(amount != 0, "amount == 0");
require(msg.sender == _owner, "only owner can mint");
_mint(recipient, amount);
}
}
2 changes: 1 addition & 1 deletion contracts/interfaces/IMasterRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;
pragma solidity >=0.6.0;
pragma experimental ABIEncoderV2;

interface IMasterRegistry {
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IPoolRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;
pragma solidity >=0.6.0;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
Expand Down
22 changes: 22 additions & 0 deletions contracts/interfaces/IVotingEscrow.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-4.4.0/token/ERC20/IERC20.sol";

interface IVotingEscrow is IERC20 {
struct LockedBalance {
int128 amount;
uint256 end;
}

function balanceOf(address) external view override returns (uint256);

function totalSupply() external view override returns (uint256);

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

function locked(address) external view returns (LockedBalance memory);

function deposit_for(address, uint256) external;

function is_unlocked() external view returns (bool);
}
Loading

0 comments on commit be4fe59

Please sign in to comment.