VelocoreSynthChef

Git Source

Inherits: IProtocolSynthChef, Initializable, UUPSUpgradeable, AccessControlUpgradeable, OwnableUpgradeable

A contract for managing interactions with Velocore Finance for yield farming purposes.

This contract provides functionalities to interact with Velocore pools, deposit and withdraw LP tokens, harvest rewards, and more.

State Variables

vault

Interface of Velocore Vault (Router)

IVault public vault;

entMasterChef

Entangle MasterChef address

address public entMasterChef;

ADMIN

Role identifier for the admin.

bytes32 public constant ADMIN = keccak256("ADMIN");

MASTER

Role identifier for the master.

bytes32 public constant MASTER = keccak256("MASTER");

SWAP

Velocore 'execute' codes

uint8 constant SWAP = 0;

GAUGE

uint8 constant GAUGE = 1;

EXACTLY

uint8 constant EXACTLY = 0;

AT_MOST

uint8 constant AT_MOST = 1;

ALL

uint8 constant ALL = 2;

vc

address public vc;

lens

address public lens;

NATIVE

Token immutable NATIVE =
    Token.wrap(0xEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE);

WETH

Token immutable WETH = addressToToken(0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f);

pools

Mapping from entangle internal pool Id to Velocore pool Id

mapping(uint32 poolId => Pool) public pools;

isPoolInitialized

Mapping to track if a pool is initialized.

mapping(uint32 poolId => bool) public isPoolInitialized;

Functions

onlyCompounder

Modifier to restrict function access to the Compounder.

modifier onlyCompounder();

initialize

Initializes the CurveConvexSynthChef contract with initial parameters.

This function is called during deployment to set up initial configuration.

function initialize(
    address _vault,
    address _admin,
    address _masterSynthChef,
    address _vc,
    address _lens,
    uint32[] calldata entanglePoolIds,
    Pool[] calldata poolData
) public initializer;

Parameters

NameTypeDescription

_vault

address

The address of the Vault Velocore contract.

_admin

address

_masterSynthChef

address

The address of the Entangle MasterChef contract.

_vc

address

The address of the admin role for managing contract administration.

_lens

address

The address of the Lens Velocore contract.

entanglePoolIds

uint32[]

Array of Entangle internal pool IDs.

poolData

Pool[]

Array of Pool struct data containing Curve pool information.

_authorizeUpgrade

function _authorizeUpgrade(address) internal override onlyOwner;

addPool

Adds a new Curve pool to the contract.

This function can only be called by the admin.

function addPool(uint32 poolId, bytes calldata poolInfo) external onlyRole(ADMIN);

Parameters

NameTypeDescription

poolId

uint32

Entangle internal poolId.

poolInfo

bytes

Information required to communicate with Velocore.

reinvest

Reinvests LP tokens into the farm.

This function can only be called by the Compounder and requires a valid pool ID.

function reinvest(uint32 poolId) external onlyCompounder returns (uint256);

Parameters

NameTypeDescription

poolId

uint32

Entangle internal poolId.

Returns

NameTypeDescription

<none>

uint256

amountLPs The amount of LP tokens reinvested.

_optimalDeposit

Calculates the optimal amount of LP tokens to deposit into the farm.

This function computes the deposit amounts for each token in the pool based on the current balances.

function _optimalDeposit(Pool memory pool) internal returns (uint256);

Parameters

NameTypeDescription

pool

Pool

Pool entity for dedicated Velocore pool.

Returns

NameTypeDescription

<none>

uint256

amountLPs The optimal amount of LP tokens to deposit.

_getOptimalDeposit

function _getOptimalDeposit(Pool memory pool)
    internal
    view
    returns (uint256 amount0, uint256 amount1);

_ensureAllowance

function _ensureAllowance(address token, address spender, uint256 amount) internal;

withdraw

Withdraws LP tokens from the farm and removes liquidity.

This function transfers the withdrawn tokens to the recipient address.

function withdraw(uint32 poolId, uint256 lpAmountToWithdraw, address recipient)
    external
    onlyRole(MASTER)
    returns (uint256[] memory amounts);

Parameters

NameTypeDescription

poolId

uint32

Entangle internal poolId.

lpAmountToWithdraw

uint256

Amount of LP tokens to withdraw.

recipient

address

Address to receive the withdrawn tokens.

depositLP

Deposits LP tokens into the farm.

This function can only be called by the MASTER and requires a valid pool ID.

function depositLP(uint32 poolId, uint256 lpAmount) external onlyRole(MASTER);

Parameters

NameTypeDescription

poolId

uint32

Entangle internal poolId.

lpAmount

uint256

Amount of LP tokens to deposit.

withdrawLP

Withdraws LP tokens from the farm and transfers them to the Entangle MasterChef.

This function can only be called by the MASTER and requires a valid pool ID.

function withdrawLP(uint32 poolId, uint256 lpAmount) external onlyRole(MASTER);

Parameters

NameTypeDescription

poolId

uint32

Entangle internal poolId.

lpAmount

uint256

Amount of LP tokens to withdraw.

harvest

Accrues rewards and transfers them to the Compounder.

This function can only be called by the Compounder and requires a valid pool ID.

function harvest(uint32 poolId)
    external
    onlyCompounder
    returns (address[] memory rewardTokens, uint256[] memory amounts);

Parameters

NameTypeDescription

poolId

uint32

Entangle internal poolId.

Returns

NameTypeDescription

rewardTokens

address[]

Array of reward tokens transferred.

amounts

uint256[]

Array of reward amounts transferred.

getTotalLpBalance

Retrieves the total balance of LP tokens on the farm.

This function returns the LP token balance of this contract for a given pool ID.

function getTotalLpBalance(uint32 poolId) public view returns (uint256 amount);

Parameters

NameTypeDescription

poolId

uint32

Entangle internal poolId.

Returns

NameTypeDescription

amount

uint256

Balance of LP tokens of this contract.

getPoolTokens

Retrieves the addresses of tokens in a pool.

This function returns an array of pool token addresses for a given pool ID.

function getPoolTokens(uint32 poolId) external view returns (address[] memory tokens);

Parameters

NameTypeDescription

poolId

uint32

Entangle internal poolId.

Returns

NameTypeDescription

tokens

address[]

Array of pool token addresses.

lpTokenAddress

Retrieves the LP token address for a given pool ID.

This function returns the address of the LP token for a specified pool ID.

function lpTokenAddress(uint32 poolId) external view returns (address lpToken);

Parameters

NameTypeDescription

poolId

uint32

Entangle internal poolId.

Returns

NameTypeDescription

lpToken

address

Address of the LP token.

getLPDecimals

function getLPDecimals(uint32 poolId) external view returns (uint8);

run3

function run3(
    Action action,
    address pool,
    uint8 method,
    Token t1,
    uint8 m1,
    int128 a1,
    Token t2,
    uint8 m2,
    int128 a2,
    Token t3,
    uint8 m3,
    int128 a3
) internal;

run2

function run2(
    address pool,
    uint8 method,
    Token t1,
    uint8 m1,
    int128 a1,
    Token t2,
    uint8 m2,
    int128 a2
) internal;

run1

function run1(address pool, uint8 method, Token t1, uint8 m1, int128 a1) internal;

addressToToken

function addressToToken(address _address) public pure returns (Token);

getPoolInfo

Retrieves the details of a pool for a given pool ID.

This function returns the details of the pool including LP token, convex ID, Curve pool, and Convex reward contract.

function getPoolInfo(uint32 index) external view returns (Pool memory);

Parameters

NameTypeDescription

index

uint32

Entangle internal poolId.

Returns

NameTypeDescription

<none>

Pool

Pool struct containing the details of the pool.

addressToBytes32

function addressToBytes32(address token) internal pure returns (bytes32);

receive

receive() external payable;

Errors

VelocoreSynthChef__E1

PoolId already exists : VelocoreSynthChef

error VelocoreSynthChef__E1();

VelocoreSynthChef__E2

Amount eq 0 : VelocoreSynthChef

error VelocoreSynthChef__E2();

VelocoreSynthChef__NotACompounder

Caller is not Entangle's Compounder

error VelocoreSynthChef__NotACompounder();

VelocoreSynthChef__WrongUnderlyingCount

Amount of tokens unexpected

error VelocoreSynthChef__WrongUnderlyingCount();

Structs

Pool

struct Pool {
    address poolAddr;
    address[] uTokens;
}

Enums

Action

enum Action {
    DEPOSIT,
    WITHDRAW
}

Last updated