Coder Social home page Coder Social logo

core's Introduction

test status solidity v0.8.14

Rage Trade

This repository contains the core smart contracts for the Rage Trade Protocol.

Bug Bounty

This repository is subject to the Rage Trade Bug Bounty program, per the terms defined here.

Scripts:

  • yarn compile: compiles contracts
  • yarn test: runs tests
  • yarn coverage: runs tests and generates coverage report
  • yarn deploy --network arbtest: for testnet deployment
  • yarn deploy --network arbmain: for mainnet deployment

Deployment

The live deployment files are in the deployments directory.

To deploy contracts, you can use yarn deploy --network <network-name>. If you're looking for details, please see DEPLOYMENT_GUIDE.

Licensing

The primary license for Rage Trade Core is the MIT License. However, our dependencies have various licenses and hence the files that import them inherits the maximum restrictive license of it's dependencies, specified by the SPDX identifier in the file.

You can see overview of SPDX License Identifiers used by the source code in our repository here.

core's People

Contributors

0xdosa avatar 134dd3v avatar luce-rage avatar protodev-rage 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

core's Issues

Simple Array based Set Lib

Need seperate libraries implemented using uint32[8] and uint48[5] array. Since this is a set, the library should not expose any index related information. Only following methods need to be exposed

  • ‘include’ method, that includes a given element in the data structure if possible; if inclusion failed (due to space full) then revert.
  • ‘exclude’ method, that excludes a given element from the data structure. If element does not exist still it should not revert.

Add Compressed Money Lib

To use uint32 for calldata money amounts (only for the purpose of input), to lower L1 calldata gas costs on Arbitrum.

struct CompressedMoneyInput {
    uint8 exponent;
    uint24 decimalSignificant;
}

decode(exponent, decimalSignificant) {
  return decimalSignificant * (10 ** decimalSignificant);
}

// does not need an encode function on smart contract

Use SafeCast

In a number of places we have direct casting to lower ranges, e.g. casting uint256 to int256.

Current:

int256(val)

Desirable:

val.toInt256()

Admin methods / Governance vs Team Multisig

Admin functions:

ClearingHouse:

  • enable/disable pools (updateSupportedVTokens), ClearingHouse
  • enable/disable collateral (updateSupportedDeposits), ClearingHouse
  • pause/unpause (setPaused), ClearingHouse
  • setPlatformParameters, ClearingHouse
  • margin ratios, twap durations, oracle address (updateRageTradePoolSettings), ClearingHouse

RageTradeManager (RageTradeFactory)

  • initializePool
  • upgradeClearingHouseToLatestLogic
  • setVPoolWrapperLogicAddress and upgradeVPoolWrapperToLatestLogic

Liquidity Position Library

To be implemented as per spec. Depends on Set library. For milestone 1, pool wrapper will not be implemented, so the logic related that can be kept as TODO comments.

All the tests coverage of logic should be done over isToken0 true and false

Addresses of vBase and vToken contracts influence a lot of logic due to the involvement of isToken0 in various places (example priceX128 is normalised using that). There are various code path depending on the value of isToken0 and hence for better testing we should have everything tested for both cases, i.e. isToken0 as true and false.

Refactor tests

Example

 VBase
    Functions
      ✓ Mint Unsuccessful
      ✓ Burn Unsuccessful
      ✓ Authorize
      ✓ Mint Successful
      ✓ Burn Unsuccessful

change this to

 VBase
    #mint
      ✓ unsuccessful
      ✓ success after authorise
    #burnFrom
      ✓ successful
      ✓ success after authorise

Token Position Library

To be implemented as per spec. Depends on Liquidity Position and Set library. Logic that depends on Pool Wrapper can be kept as TODO.

Move Uniswap's code upgraded to 0.8 to a fork

If licensing is a problem, it may make more sense to import their libraries from their repo. Since we need 0.8 support while Uniswap code base is in 0.7.6, we might have to upgrade the libraries in a fork

Add Pool Wrapper tests

  • Swap
  • Liquidity Change
  • Funding payment tick state
  • Sell Fee tick state
  • Protocol fee collection

vToken Lib

Create vToken lib as per spec. This depends on PoolDeployer / PoolFactory.

Chris Audit Fixes

PRs involved in audix fixes

Issues

(Please only look at the ticked ones for now, the rest ones will be confirmed ASAP)

  • 3.1 poolwrapper external function checks (fixed, PR#92, 1f9d870)
  • 3.2 Trader Position Increase issue (fixed, PR#93, 5c1d419, 0e188a5)
  • 3.3 Fix exclude (fixed, PR#99, 4587ac2)
  • 3.4 Calldata.limit (fixed, PR#92, 188be91)
  • 3.5 Unsafe casting @alex (fixed, PR#99, e793cbe)
  • 3.6 Reduce issue (file removed, PR#93, 1a08c63)
  • 3.7 Exclude issue (file removed, PR#93, 1a08c63)
  • 3.8 Extsload - fix memory corruption? (fixed, PR#92, c5d7e41)
  • 3.9 VTokenPosition deactivation logic (fixed, PR#93, bd8999f)
  • 3.10 Increase oracle cardinality in rage trade factory. (fixed, PR#93, b5a4906)
  • 3.11 Unsupported RToken withdrawal - c36a2fb
  • 3.12 - No Fix Needed
  • 3.13 - Permissionless removal of limit orders. Issue fixed - Limit order removal should use currentTick rather than twapTick to check if order is filled. Removal of limit order away from TWAP price (if current price is far away due to flash attack) would not be an issue since token value on removal would be higher ( https://docs.google.com/spreadsheets/d/16Q3FP7NjmRmNUwwuQNt3D3aiW91dDBDj/edit?usp=sharing&ouid=101320775168527941295&rtpof=true&sd=true ). (PR#93, d3d8299, df442dd, 667f30e). The commit : df442dd introduced an issue which has been fixed with the commit: 7ed75a4.
  • 3.14 - SignedFullMath issue (fixed, PR#92, 8e11dff)
  • 3.15 - Real Token Never init - real token initialized not needed anymore - have removed it (fixed, PR#93, 5d40761)
  • 3.16 - getLiquidityPosition optimization (fixed, PR#93, b2c51e0)
  • 3.17 - Include efficiency issue 1a08c63 (File Removed)
  • 3.18 - Misc
    • Account.LiquidationParams: The fixFee and minRequiredMargin variables do not exist on the
      struct anymore but are still listed in the docs. 308e9ab
    • Account.liquidateLiquidityPositions: The protocol.liquidationParams.liquidationFeeFraction
      is divided by 1e5 whereas all other Account.LiquidationParams are in basis points (1e4).
      Document the dierent base for all of these parameters and consider changing all percentages
      to a common base. 308e9ab
    • Account.getLiquidationPriceX128AndFee: The parameter descriptions in the docs do not match
      the parameters 308e9ab
    • Account.updateLiquidationAccounts: Function uses anamedreturn variable liquidatorBalanceAdjustments
      but never sets it. The last balanceAdjustments assignment should be to liquidatorBalanceAdjustments
      instead (and the return statement should be skipped). 308e9ab
    • Uint32L8Set._existsReducer: Function not used. (file removed, PR#93, 1a08c63)
    • Uint48Lib.concat: No need to mask the 24 lower bits on the 24-bit val2 value with and(val2, 0
      x000000ffffff). One can directly use the 24-bits of val2. (NO ACTION)
    • ClearingHouseStorage.realTokenInitilized / ClearingHouseView.isRealTokenAlreadyInitilized
      : TYPO: Initilized -> Initialized 5d40761 (Functions removed)
    • ClearingHouse: The *WithGasClaim functions are not part of the IClearingHouse interface. 800623f
    • ClearingHouseEthereum: The TODO put a upper limit to tx.gasprice seems to already be resolved by use of the checkTxGasPrice(tx.gasprice) modifier. (NO ACTION)
    • ClearingHouseEthereum: EVM gas costs can change over time with new forks. (NO ACTION)
    • VBaseDeployer._isVBaseAddressGood: comment should say “most significant hex char of address
      is "f"” instead of “d”. (fixed, PR#93, e2710a1)
    • VPoolWrapper.swap: Regarding the TODO questioning if the assert(vTokenIn_simulated ==
      vTokenIn && vBaseIn_simulated == vBaseIn) should be removed: This invariant should always
      be true, so we recommend keeping it to be able to easier detect any issues. (NO ACTION)
    • Tick.getUniswapFeeGrowthInside: This function is not used and should be removed. (fixed, PR#93, 801deed)

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.