Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Developers

Devan Purhar edited this page Oct 14, 2019 · 13 revisions

Getting Started

Please join our Telegram for the Staked community here. Our team looks forward to answering any questions you may have. Feel free to make suggestions for greater clarity or better functionality.

For a prettier interface please visit here

Table of Contents:


Deployed Addresses

Mainnet

Contract Name Description Address
Users Entrypoint
PortfolioManager Main RAY contract 0x06a5Bf70BfF314177488864Fe03576ff608e6aec
Tokens
RAY Token Token that represents users positions in RAY 0xE215e8160a5e0A03f2D6c7900b050F2f04eA5Cbb
Opportunity Token Tokenize positions in Opportunities 0xFDF18FC25B56Deb9753A5D3E95110fFb7fAe083D
Opportunities
CompoundOpportunity Proxy for Compound V2 0xEa5ee32F3A63c3FaBb311c6E8c985D308A53dcC1
DydxOpportunity Proxy for dYdX V2 0xEB6394f817b498c423C44bD72c3D7f8ED5DeeC6e
BzxOpportunity Proxy for bZx (Fulcrum) 0x759A728653C4d0483D897DCCf3a343fe2bBbb54A
Other Base Layer
OpportunityManager Manages Opportunity positions 0xA1FC31d0439522BB70C39CC01329e57CDf97fD90
PositionManager Manages RAY positions 0xAaCc122C8c57af37A30c1d33fDb4416c2956e0c7
NAVCalculator Calculates the Net Asset Value 0xD23fA5F1a001eCDed63b45Da426972fB2AAD2760
Oracle Initiates lends, rebalances and withdraws 0x6eF7CC3891e4881Bf6106F41E4732e4807868633
Admin Permissioned access to the RAY contracts 0xBeb81EB4d6F0A1C20771aA25dacf1cb9689DB7c8
FeeModel Responsible for taking system fees 0xE36A702dcEb228a561fD8704898a0eB9Cec0396f
Storage Eternal storage of the system 0x446711E5ED3013743e40342A0462FBdc437cd43F
StorageWrapper Wrapper around eternal storage 0x9207D2761EFD0308263681F74c50A29CF5bB23e7
StorageWrapperTwo Wrapper around eternal storage 0xAf22c6509830F877C5e2e159eA6CADb03A4C4dFf
TokenWrapper Wrapper around RAY and Opportunity tokens 0x783cfAD070ca1427a6b4AE988eFfE7605879271e
Secondary Layer
GasFunder Enables third-parties paying for gas to interact with RAY Not Deployed
Upgrader Enables auto-adding new Opportunities to a RAY position Not Deployed

Main Smart Contracts

  • PortfolioManager: User entry-point to interact with the product (deposit or withdraw). Deposits are held here before the Oracle lends them.

  • NAVCalculator: Contains functions around calculating the Net Asset Value of RAY portfolios and opportunities, and the value of unique RAY Tokens.

Governance

  • Admin: Contract that has permissioned access to change settings in the system - currently only able to be accessed by a wallet controlled by Staked.

Token Contracts

  • RAY Token: Token that represents user positions in RAY.

  • Opportunity Token: Tokenize positions in Opportunities, currently only used internally.

Opportunity Contracts

  • BzxOpportunity: Proxy to interact with Fulcrum (bZx)

  • CompoundOpportunity: Proxy to interact with Compound V2

  • DydxOpportunity: Proxy to interact with dYdX V2


RAY Integration

Using RAY

The RAY interface smart contract contains all relevant functions.


Mint a RAY token

Location:

Reference this call to the deployed PortfolioManager.sol

Definition:

The mint function allows users to transfer assets to the RAY system and create a new position.

Function Signature:

function mint(bytes32 portfolioId, address beneficiary, uint value) external payable returns(bytes32)

Parameters:

  • msg.sender: The account that will supply the asset
  • portfolioId: The corresponding id for the basket of opportunities to associate with this RAY token
  • beneficiary: The account that will own the RAY token
  • value: The amount in the smallest units of the asset, to deposit

Returns:

The unique identifier of the newly minted RAY token

Note:

For ERC20 tokens, the funder (msg.sender) must first approve PortfolioManager to access their assets for the specified value.

Events:

LogMintRAYT(bytes32 indexed tokenId, bytes32 indexed portfolioId, address indexed beneficiary, uint value);


Deposit to a RAY token

Location:

Reference this call to the deployed PortfolioManager.sol

Definition:

The deposit function allows a user to transfer assets to the RAY system to increase an existing position's value (adding the value to an existing RAY token).

Function Signature:

function deposit(bytes32 tokenId, uint value) external payable

Parameters:

  • msg.sender: The account that will supply the asset
  • tokenId: The unique identifier of the RAY token to deposit value into
  • value: The amount in the smallest units of the asset, to deposit

Note:

For ERC20 tokens, the funder (msg.sender) must first approve PortfolioManager to access their assets for the specified value.

Events:

LogDepositToRAYT(bytes32 indexed tokenId, uint value, uint tokenValue);


Redeem a RAY token

Location:

Reference this call to the deployed PortfolioManager.sol

Definition:

The redeem function allows a user to trade in their RAY token for the underlying value.

Function Signature:

function redeem(bytes32 tokenId, uint valueToWithdraw, address originalCaller) external returns(uint)

Parameters:

  • msg.sender: The account that owns the RAY token
  • tokenId: The unique identifier of the RAY token to withdraw value from
  • valueToWithdraw: The amount in the smallest units of the asset, to withdraw
  • originalCaller: The msg.sender. (This parameter can be set to anything, only relevant if the msg.sender is our GasFunder.sol smart contract which enables paying gas on user transactions)

Returns:

The value withdrawn after system fees have been taken

Events:

LogWithdrawFromRAYT(bytes32 indexed tokenId, uint value, uint tokenValue);


Get the value of a RAY token

Location:

Reference this call to the deployed NAVCalculator.sol

Definition:

The getTokenValue function allows a user to get the current value of their RAY token.

Function Signature:

function getTokenValue(bytes32 portfolioId, bytes32 tokenId) public view returns(uint, uint)

Parameters:

  • portfolioId: The corresponding id for the basket of opportunities associated with this RAY token
  • tokenId: The unique identifier of the RAY token to get the value of

Returns:

A two index object.

The first index contains the token's current value in-kind. Ex. If the token's principal type is DAI, the value is represented in DAI.

The second index contains the portfolio's current price per share.


Portfolios Identifiers

These are used for RAY direct contract integration. To dynamically generate these, the template used is as follows:

keccak256({Coin Type Ticker in CamelCase}{Opportunities in Alphabetical Order in CamelCase})

Example: The id of the portfolio that lends ETH to bZx, Compound and dYdX is equal to keccak256(EthBzxCompoundDydx) or 0xbe72e724d4b9326428f7faca782d2dcc9e3e10824e8cf48a6499f23d695fd018

Note: '0x' needs to be pre-pended, some keccak256 generators don't automatically add that.

Valid Values for Opportunities:

  • Bzx
  • Compound
  • Dydx

Valid Values for Coins:

  • Eth
  • Dai
  • Usdc

Below you'll find the actual values for every portfolio (not added yet)

[ bZx, Compound, dYdX ] Portfolios

Coin: ETH

portfolioId: 0xbe72e724d4b9326428f7faca782d2dcc9e3e10824e8cf48a6499f23d695fd018

Coin: DAI

portfolioId: 0x87e3990b15e1e64e3a17b0e4ebfcc4c03cc5ec64a33b442ae01ef15d9dadb575

Coin: USDC

portfolioId: 0x7c80b0e3ce0d2cabe1a3dfc888fca469bab09beccc3496f88cba8613d159a65b

--

[ bZx, Compound ] Portfolios

Coin: ETH

portfolioId: 0x89bdc287eca0056552bd2979865efb44e5f19fdc962accefb49f7eefc0e55ea9

Coin: DAI

portfolioId: 0xe51a4786828f3cbbdd643cd0d415c0f45bdbf7ec739dbdb2e64d6ac97bf103f1

Coin: USDC

portfolioId: 0x1e868d302424cfebaf2b757c06fdd1a32411fd445ebb51ffc433cc15bacfe3e3

--

[ bZx, dYdX ] Portfolios

Coin: ETH

portfolioId: 0xe1d9f3a90e5d350eec05cd47282029fcf71c7c09c29c032f198eeffc936975b6

Coin: DAI

portfolioId: 0xae52c5b4d809b421d746d3a7bde807ea6ec242ae13ae1b2bc6434493acf26d8b

Coin: USDC

portfolioId: 0x978274153eec4f3c072b45a6268ae86c0e61033c7a817328b407954972369b1d

--

[ Compound, dYdX ] Portfolios

Coin: ETH

portfolioId: 0xf26c69dbf25f9fb2bf793e4847f7c619cbc3323cb4ff988fb0ce4c5ea45affa1

Coin: DAI

portfolioId: 0xd33be800bb630e1ae95562a75be01b1b77a96386f99b3faa97a828b28c92dbb9

Coin: USDC

portfolioId: 0xf904b00f34beab1e77301f192a7fe866c4936fb9ea30e65543df5dc2d9176c69

--

[ bZx ] Portfolios

Coin: ETH

portfolioId: 0x21590982edcc6d2c9b986dd8174fda53c28d1a919c8bf9b58ead7d441b306439

Coin: DAI

portfolioId: 0x165de3655459c6088f957bdb2877779c94aa17af570340349630726914a826fa

Coin: USDC

portfolioId: 0xb6cb9e19cd1b048a65dffcccc3a071c8d2d89ad070a0dca6f7efdf4ee7ab9e51

--

[ Compound ] Portfolios

Coin: ETH

portfolioId: 0x5870955881b5219ec3d880e8ad25206c312127210a5695618971c47541982994

Coin: DAI

portfolioId: 0xcd93cf275bcc8c600887dc587ea0a16e8f0a87fa7f99560f72186069c8d3b3df

Coin: USDC

portfolioId: 0x839de554365a548fbb6bf9b32952a781e00390bb8454a2bb8f4f3bbed40bc92c

--

[ dYdX ] Portfolios

Coin: ETH

portfolioId: 0xa49d129cd260862e8226f232c7d2ab0dd7302e2bcb49847810392625b7dbf3f6

Coin: DAI

portfolioId: 0xf21acfdd065ab7839f3b0c66c441c6366b2240db1c3fa7c7da134c9be316fcd0

Coin: USDC

portfolioId: 0x4672ce0a5532a592a953596e6c19fc1cb1bd89cdaf2f6d6b4c71d5f8b6f7f58a