Code Monkey home page Code Monkey logo

olympus-contracts's Introduction

Ω Olympus Smart Contracts

image

This is the main Olympus smart contract development repository.

🔧 Setting up local development

Requirements

Local Setup Steps

# Clone the repository
git clone https://github.com/OlympusDAO/olympus-contracts.git

# Install dependencies
yarn install

# Set up environment variables (keys)
cp .env.example .env # (linux)
copy .env.example .env # (windows)

# compile solidity, the below will automatically also run yarn typechain
yarn compile

# if you want to explicitly run typechain, run
yarn compile --no-typechain
yarn typechain

# run a local hardhat node
yarn run start

# test deployment or deploy 
# yarn run deploy:<network>, example:
yarn run deploy:hardhat

Local Setup Steps (with Docker)

A Docker image is available to simplify setup.

# First setup keys, to do this first copy as above
cp .env.example .env # (linux)
copy .env.example .env # (windows)

# Populate ALCHEMY_API_KEY and PRIVATE_KEY into `.env` afterwards
# Then, start the node
make run

📜 Contract Addresses

Notes for localhost

  • The deployments/localhost directory is included in the git repository, so that the contract addresses remain constant. Otherwise, the frontend's constants.ts file would need to be updated.
  • Avoid committing changes to the deployments/localhost files (unless you are sure), as this will alter the state of the hardhat node when deployed in tests.

📖 Guides

Contracts

Testing

olympus-contracts's People

Contributors

0xjem avatar 0xlienid avatar 0xocnus avatar c-n-o-t-e avatar cyotee avatar finaglelord avatar ind-igo avatar jextor avatar kushal256 avatar mirru2532 avatar olyzeus avatar paul4912 avatar tonypiano avatar zayen-x avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

olympus-contracts's Issues

What is the purpose of queue/toggle in treasury?

Hey,

Could you please explain what is the purpose of queue/toggle in the Treasury contract ? Looks like it has been replaced by queueTimelock/execute in new version. I understand how it works, but I don't really understand what it's for?

I'm thinking that maybe it would allow the users of the protocol to anticipate the changes?

In addition, can you confirm that if blocksNeededForQueue=0 then this time locking mechanism becomes useless ?

Thanks!

Guide to Writing Allocator Contracts

The following is a guide for interacting with the treasury as a reserve allocator.

A reserve allocator is a contract that deploys funds into external strategies, such as Aave, Curve, etc.

Treasury Address: 0x31F8Cc382c9898b273eff4e0b7626a6987C846E8

Managing:
The first step is withdraw funds from the treasury via the "manage" function.
"Manage" allows an approved address to withdraw excess reserves from the treasury.
Note that this contract must have the "reserve manager" permission, and that withdrawn reserves decrease the treasury's ability to mint new OHM (since backing has been removed).

function manage( address _token, uint _amount ) external;
Pass in the token address and the amount to manage. The token will be sent to the contract calling the function.

Managing treasury assets should look something like this:
treasury.manage( DAI, amountToManage );

Returning:
The second step is to return funds after the strategy has been closed.
We utilize the "deposit" function to do this. Deposit allows an approved contract to deposit reserve assets into the treasury, and mint OHM against them. In this case however, we will NOT mint any OHM. This will be explained shortly.
Note that the contract must have the "reserve depositor" permission, and that deposited reserves increase the treasury's ability to mint new OHM (since backing has been added).

function deposit( address _from, uint _amount, address _token, uint _profit ) external returns ( uint send_ );
Pass in the address sending the funds (most likely the allocator contract), the amount to deposit, and the address of the token. The final parameter, profit, dictates how much OHM needs to be minted. send_, the amount of OHM to send, equals the value of amount minus profit.
To ensure no OHM is minted, we first get the value of the asset, and pass that in as profit.

function valueOf( address _token, uint _amount ) public view returns ( uint value_ );
Pass in the token address and amount to get the treasury value.

All together, returning funds should look something like this:
treasury.deposit( address(this), amountToReturn, DAI, treasury.valueOf( DAI, amountToReturn ) );

BondDepository.sol for v1.1 does not accept Deposits as per script

Screenshot - 11_24_2021 , 8_19_11 AM

I get a reversion -32015 - which is apparently an "Address not payable" error when i try to deploy and then do the final test of the deposits into the Bonds.

I have tried numerous times now and keep getting the same end result for a week now on 2 different chains.

Any idea what the issue may be?

Thanks!

Treasury: Removing liquidity tokens and reserve tokens right after adding it to the registry

I was taking a look at the Treasury contract and I notice that the function enable has a weird behavior when it comes to LIQUIDITYTOKEN and RESERVETOKEN.

Around the line 318 we have the following steps inside the enable function:

(bool registered, ) = indexInRegistry(_address, _status);
if (!registered) {
    registry[_status].push(_address);

    if (_status == STATUS.LIQUIDITYTOKEN || _status == STATUS.RESERVETOKEN) {
        (bool reg, uint256 index) = indexInRegistry(_address, _status);
        if (reg) {
            delete registry[_status][index];
        }
    }
}

The function checks if the checks if the address that we're trying to add to the registry is already registered, if it isn't it puts the address in the array of that particular STATUS.

The problem begins when the we're trying to enable a LIQUIDITYTOKEN or a RESERVETOKEN. Right after pushing the address to the registry, if it's any of the two STATUS mentioned above it removes soon after. So the first question here: why not simply checking if it's a LIQUIDITYTOKEN or a RESERVETOKEN before pushing the addresses to the registry?

The problem continues when we check other functions in the body of the Treasury contract.
For example, the function auditReserves uses both liquidity tokens and reserve tokens registered to update the totalReserves, but as both gets delete on the time of creation we end up with an array filled with zero addresses, therefore when we check the balances of each token, we'll always get zero which results in the totalReserves never being updated, since it uses those values to add to that variable.

With that in mind, the next question would be how the totalReserves is being updated after we call the deposit function on the BondDepository contract? Since the function mentioned doesn't call the deposit function on the Treasury contract, it simply uses a regular transfer from an ERC-20 token

Testing gOHM on rinkeby

HI

I writing automated solution for Olympus Staking/Unstaking and trading. How do I get test OHM on Rinkeby network?
Do you have a link to a faucet?

Thanks and best regards.

Old Token in Lists

Hi, I believe your token is not updated in Kleros List: https://t2cr-docs.readthedocs.io/en/latest/

See https://tokenlists.org/token-list?url=t2crtokens.eth

There you will see the V1 token only.

This is an issue because if people want to buy it they will be buying the wrong token at the wrong price: https://tokenlists.org/token-list?url=t2crtokens.eth

Just to do a quick test and see the issue, try buying the token in Uniswap or CowSwap https://cowswap.exchange

image

image

You are offered the wrong token, and the USD estimation is misleading, because of the big price difference between v1 and v2

Changing The Blockchain Type.

Hello there!
I would like to ask how to change the blockchain type on the contract from Ethereum to Binance.
Thanks in advance.

About how contracts automatically deal with buy back and burn.

GM, I have some questions with 👇:

When OHM trades below 1 DAI, 
how the contract buy back and burn OHM? 
And could I know the exact code lines that written in the contract. 
Could I know exactly how this mechanism works(how to buy back, how to know when should buy back, etc.)?

Because I don't see how the contract handles this automatically.
Looking forward to your reply. :)
Thank you. Have a good coding day.

`yarn run start` fails with "Error: ENOENT: no such file or directory"

Hi,

When trying the commands shown in the README, I got the following error:

➜  olympus-contracts git:(deployment) ✗ yarn run start         
yarn run v1.22.15
$ yarn run typechain
$ TS_NODE_TRANSPILE_ONLY=true hardhat typechain
Generating typings for: 0 artifacts in dir: types for target: ethers-v5
Successfully generated 242 typings!
$ hardhat node --network hardhat
Nothing to compile
No need to generate any newer typings.
deploying "OlympusAuthority" (tx: 0xa202cf1880954a127e917909d8d7fb860ad5e70c95b00ff9c3c00df0c51e17fe)...Error HH604: Error running JSON-RPC server: ERROR processing /olympus-contracts/scripts/deploy/000_deploy_authority.ts:
Error: ENOENT: no such file or directory, open '/olympus-contracts/artifacts/build-info/957f20a5ad9a91e108198aa294b9cab6.json'

For more info go to https://hardhat.org/HH604 or run Hardhat with --show-stack-traces
error Command failed with exit code 1.

Effectively, as specified by the error message, 957f20a5ad9a91e108198aa294b9cab6.json doesn't exists, a weird detail if that deployments/localhost directory gets deleted by the script.

Any insights?

Thanks.

[Non-Core - Tyche] Yield Streamer for Olympus Give

Motivation:
It's been requested in the discord for a contract to allow users to deposit their ohm and allow the yield to be converted to DAI in whatever time interval they want. The goal of the contract is to automate that and socialise the gas costs.

User Flow:
Users deposit their gOHM into the contract. They set parameters like userMinimumDaiThreshold(Lowest amount of dai they willing to accumulate before its send to them) and paymentInterval(minimum time elapse before their ohm yields are swapped into dai).

The DAO runs a gelato job so every once in a while(week maybe) it upkeeps the contract. During an upkeep users whos payment Interval has passed will have their yield in OHM swapped to DAI. If the amount of DAI they have to claim passes a user set threshold they will have it sent to their address they put. The DAO will get a fee in gOHM every time the swap to DAI happens. This will essentially pay for the gas costs of up-keeping the contract.

Users also have the option to withdraw at any time or claim their yield at any time in gOhm or DAI.

LUSDAllocator could revert for wrong ethToLUSDRatio

The contract can revert if the set ethToLUSDRatio is set to above 1e6, which the contract currently allows.
The reversion would happen inside the uniswap v3 SwapRouter once not enough tokens are transferred, link.

Lines 92-95, 155 in LUSDAllocator.sol:

// line 92 - 95
    function setEthToLUSDRatio(uint256 _ethToLUSDRatio) external onlyGuardian {
        require(_ethToLUSDRatio <= 100 * FEE_PRECISION, "Value must be between 0 and 100 * 1e6");
        ethToLUSDRatio = _ethToLUSDRatio;
    }
// line 155           
    if (ethToLUSDRatio > 0 && ethToLUSDRatio <= (100 * FEE_PRECISION)) {

Line 93 should be changed to FEE_PRECISION, and if the fee can't be set through other functions then the check at line 155 is redundant and should be removed.

Incorrect distribute amount when stake triggers rebase

Hello, ohmies!

I seem to have found a bug in staking.sol

When stake transaction triggers rebase the following is happening:

  1. First the staking contract transfers OHM from a user to itself
    OHM.safeTransferFrom(msg.sender, address(this), _amount);
  2. Then on the next line rebase is triggered
    _amount = _amount.add(rebase()); // add bounty if rebase occurred
  3. The Distributor contract mints new OHMs to staking contract
    distributor.distribute();
  4. And lastly the distribute amount is set for the next epoch.
    epoch.distribute = balance.sub(staked).sub(bounty);

The bug is in the last step. Because the staking contract transferred the user's OHMs before triggering rebase (see step 1) it impacts the distribution amount. So instead of equal to minted OHM amount of sOHM to be distributed in the next rebase it also includes the user's stake therefore OHM balance of the staking contract and sOHM circulation start slowly diverge.

npx hardhat test

Hi, just trying to run your test suite to see how your contract works. I usually start with trying to run npx hardhat test Some mocks appear missing that are easy to get, like the TestTokens 1&2 and the uniswap v2-core stuff, but I'm not sure where to find this one. I see a StandardBondingCalculator but no DebtCalculator in the repo.

MockDebtCalculatorContract = await ethers.getContractFactory('MockDebtCalculator');

Am I missing some docs around local deployments? I'm seeing some people ask around for it, and even a dockerized e-2-e in the PRs, but other than that I'm not sure. I've also hopped around the Development Discord Server, but I'm not looking to commit time to the project, just to do a technical due dilligence

Thanks!

How to distribute in rebase mechanism

Hello, everyone.
I have researched OHM contract and have learnt much more.
But I have some questions about rebase mechanism.
I have understood like this.
When user stake and/or unstake, rebase is performed.
And then function distributor in Distributor.sol is called.
But in that function, I have noticed there is an array variable called "info".
I understood this variable stores stakers' addresses. But I can't find when the user's address is added to this variable.
I have tried to find functions "addRecipient", "removeRecipient" and "setAdjustment" in contract and frontend, but have nothing.
Is there any other platform to call policy functions?
When is the user added to the info array variable?
Looking forward to your kind answers.
Thanks.

V2 Treasury: `enable` method never allows for adding `LIQUIDITY_TOKEN` and `RESERVE_TOKEN` to the registry

@olyzeus The following lines effectively prohibit the permissioned Governor from adding any liquidity or reserve assets to the treasury whitelist:

(bool registered, ) = indexInRegistry(_address, _status);
if (!registered) {
registry[_status].push(_address);
if (_status == STATUS.LIQUIDITYTOKEN || _status == STATUS.RESERVETOKEN) {
(bool reg, uint256 index) = indexInRegistry(_address, _status);
if (reg) {
delete registry[_status][index];
}
}
}

(bool registered, ) = indexInRegistry(info.toPermit, info.managing);
if (!registered) {
registry[info.managing].push(info.toPermit);
if (info.managing == STATUS.LIQUIDITYTOKEN) {
(bool reg, uint256 index) = indexInRegistry(info.toPermit, STATUS.RESERVETOKEN);
if (reg) {
delete registry[STATUS.RESERVETOKEN][index];
}
} else if (info.managing == STATUS.RESERVETOKEN) {
(bool reg, uint256 index) = indexInRegistry(info.toPermit, STATUS.LIQUIDITYTOKEN);
if (reg) {
delete registry[STATUS.LIQUIDITYTOKEN][index];
}
}

What does 'gon' stand for?

Currently read through the contracts, but get stuck at sOlympusERC20.sol.
What does 'gon' stand for? Is it an abbreviation of something?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.