Arbera
  • 🐻Arbera Overview
    • 🐝Volatility Farming
    • 💫Arbera Flywheel
    • 💯Beras can't read
    • 💵Arbitrage
  • 🍯Dens
    • 🥞Growing Dens
    • ⚖️Optimizing Trading with brTOKENS
    • 💸Fees
    • 🐾User Guides
      • 🔍Identify Den APRs
      • 📩Wrap into the Den
      • 📥Add Den LP (and stake)
      • 📤Remove LP (and unstake)
      • 📨Unwrap from the Den
      • 💌Claim Rewards
  • 💰Tokenomics
    • 🚶User Journey
  • ✅Deployed Addresses
  • 🌊Deep Dive
    • 🧠Smart Contracts
    • 🖇️Integration 101
    • 🎯User/Fee Flow
Powered by GitBook
On this page
  • View functions
  • Get list of all the Dens
  • Get Den Info (CBR, fees)
  • Calculate CBR (Manual)
  • Get amount of brTOKEN received by wrapping TOKEN
  • Get amount of TOKEN received by unwrapping brTOKEN
  • Interactions
  • Wrap TOKEN into brTOKEN
  • Unwrap brTOKEN into TOKEN
  • Add liquidity without fees
  • Remove liquidity without fees
  • Flash loan underlying tokens
  1. Deep Dive

Integration 101

Common contract integration points.

You can find deployed contracts addresses and interfaces in Deployed Addresses.

View functions

Get list of all the Dens

// IndexManager.sol
struct IIndexAndStatus {
    address index;
    bool verified;
}

function allIndexes() external view returns (IIndexAndStatus[] memory);

If the Den is not verified it's better not to interact with it, as it may have been unverified for security reasons.

Get Den Info (CBR, fees)

// IndexLens.sol
struct Fees {
    uint16 burn;
    uint16 bond;
    uint16 debond;
    uint16 buy;
    uint16 sell;
}

struct DenInfoMutable {
    uint cbr;
    Fees fees;
    address[] tokens;
    address pairedToken;
    [...]
}
function getIndexImmutableInfo(address _indexAddress) external view returns (DenInfoImmutable memory info_);

Returns DenInfoImmutable struct with Den info which cannot change:

  • cbr as a number with 18 decimals.

  • fees struct with all the fees except partner fee (taken on top of other fees, transparent to the user)

  • tokens array of underlying assets (currently Arbera supports only 1 asset Dens).

  • pairedToken address of the Paired LP Token (currently HONEY or WBERA).

And many more — check out IndexLens.sol verified contract code.

Calculate CBR (Manual)

IDecentralizedIndex index = IDecentralizedIndex(_indexAddress);
uint totalSupply = index.totalSupply();
// Get underlying asset in th Den contract.
// Assuming there is only one underlying asset.
IDecentralizedIndex.IndexAssetInfo[] memory tokens = index.getAllAssets();
uint underlying = IERC20(tokens[0].token).balanceOf(_indexAddress);
uint decimals = IERC20Metadata(tokens[0].token).decimals();
// Normalize decimals
if (decimals < 18) {
	info_.underlying *= 10 ** (18 - decimals);
}
uint cbr = underlying == 0 || totalSupply == 0 ? 1e18 : (underlying * 1e18) / totalSupply;

To get CBR just divide underlying.balanceOf(index) by index.totalSupply() .

If totalSupply is 0 or there is no underlying token deposited it should default to 1e18.

Get amount of brTOKEN received by wrapping TOKEN

// IndexLens.sol
function getBondAmountsOut(address _index, address _token, uint _amount) external view returns (uint) {
  • _index — address of the Den token.

  • _token — underlying asset of the Den.

  • _amount — amount of underlying _token to wrap.

Returns amounts of brTOKEN received (after fees and accounting for CBR).

Get amount of TOKEN received by unwrapping brTOKEN

// IndexLens.sol
function getDebondAmountsOut(
    address _index,
    uint _amount
) external view returns (address[] memory tokens_, uint[] memory amounts_)
  • _index — address of the Den token.

  • _amount — amount of underlying _index to unwrap.

Returns array of token addresses and array of amounts.

Currently all Dens have single asset, so it's safe to assume you only receive 1 token, ie. length of the arrays equals 1.

Interactions

Wrap TOKEN into brTOKEN

// WeightedIndex.sol
function bond(address token, uint amount, uint amountMintMin) external;
  • token — underlying token address

  • amount — amount to wrap.

  • amountMintMin — minimum amount to receive (considdering fees and CBR).

Calling this function needs approval of the amount of token to the Den token contract.

Unwrap brTOKEN into TOKEN

// WeightedIndex.sol
function debond(uint amount, address[] memory token, uint8[] memory percentage) external;
  • amount — amount to wrap.

  • amountMintMin — minimum amount to receive (considering fees and CBR).

This function doesn't need approvals.

Add liquidity without fees

// WeightedIndex.sol
function addLiquidityV2(uint idxTokens, uint daiTokens, uint slippage, uint deadline) external returns (uint);
  • idxTokens — amount of Den tokens (brTOKEN).

  • daiTokens — amount of paired LP Token (currently DAI or WBERA).

  • slippage — slippage as number with 4 decimals, ie. 100 = 1%

  • deadline — deadline timestamp for providing liquidity.

Calling this function needs approval of the daiTokens of pairedLPToken (DAI or WEBERA) to the Den token contract.

Remove liquidity without fees

// WeightedIndex.sol
function removeLiquidityV2(uint lpTokens, uint minTokens, uint minDAI, uint deadline) external;
  • idxTokens — amount of Den tokens (brTOKEN).

  • daiTokens — amount of paired LP Token (currently DAI or WBERA).

  • slippage — slippage as number with 4 decimals, ie. 100 = 1%

  • deadline — deadline timestamp for providing liquidity.

Calling this function needs approval of the lpTokens of LP receipt token to the Den token contract.

Flash loan underlying tokens

/**
 * @notice Take flash loan of underlying tokens.
 * @dev Other index functions are locked during flash loan.
 * @param _recipient Recipient of the flash loan.
 * @param _token Address of the token to flash loan.
 * @param _amount Amount of the token to flash loan.
 * @param _data Data passed to recipient in the callback.
 */
function flash(address _recipient, address _token, uint _amount, bytes calldata _data) external

You need to implement IFlashLoanRecipient interface.

PreviousSmart ContractsNextUser/Fee Flow

Last updated 1 month ago

🌊
🖇️