MasterSynthChef

MasterSynthChef

Git Source

Inherits: Initializable, UUPSUpgradeable, AccessControlUpgradeable, OwnableUpgradeable

This contract manages the staking of LP tokens for synthetic assets in various protocols. Users can deposit LP tokens and earn rewards, and the contract can compound rewards automatically.

State Variables

chefs

Map with addresses of Entangle ProtoSynthChefs protocols

mapping(uint32 protocolId => address ProtoSynthChef) public chefs;

compounder

Entangle Compounder address

ICompounder public compounder;

ADMIN

Admin role

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

DEPOSITOR

Depositor Role

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

COMPOUNDER_EOA

Compounder External owned account role

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

synthFactory

Entangle SynthFactory address

SynthFactory public immutable synthFactory;

Functions

sidCheck

Modifier that checks sid that it satisfies current requirements

modifier sidCheck(uint128 sid);

constructor

constructor(address _synthFactory);

initialize

Initializes the contract with initial parameters and sets up protocol-specific synthetic chefs.

function initialize(
    address _admin,
    address _compounderEOA,
    address _compounder,
    address _entangleDex,
    ProtocolSynthChefData[] calldata protocolSynthChefs
) public initializer;

Parameters

NameTypeDescription

_admin

address

Address of the admin.

_compounderEOA

address

Address of the EOA (externally owned account) for the compounder.

_compounder

address

Address of the compounder contract.

_entangleDex

address

Address of the EntangleDex contract.

protocolSynthChefs

ProtocolSynthChefData[]

Array of protocol synthetic chef data.

_authorizeUpgrade

function _authorizeUpgrade(address) internal override onlyOwner;

setCompounder

Sets the address of the compounder contract.

function setCompounder(address _compounder) public onlyRole(ADMIN);

Parameters

NameTypeDescription

_compounder

address

New address of the compounder contract.

addProtocolSynthChef

Adds a new synthetic chef for a specific protocol.

function addProtocolSynthChef(uint32 protocolId, address chefAddress) public onlyRole(ADMIN);

Parameters

NameTypeDescription

protocolId

uint32

Inner ID of the new protocol.

chefAddress

address

Address of the synthetic chef.

getLpTokenTotalBalance

Retrieves the total LP token balance for a specific SID.

function getLpTokenTotalBalance(uint128 sid)
    public
    view
    sidCheck(sid)
    returns (uint256 lpTokenBalance);

Parameters

NameTypeDescription

sid

uint128

Entangle's sid of the pool

Returns

NameTypeDescription

lpTokenBalance

uint256

Total LP token balance.

getLpToken

Retrieves the address of the LP token for a specific SID.

function getLpToken(uint128 sid) public view sidCheck(sid) returns (address token);

Parameters

NameTypeDescription

sid

uint128

Entangle's sid of the pool

Returns

NameTypeDescription

token

address

Address of the LP token.

depositLP

LOGIC FUNCTIONS **

Transfer lp tokens to ProtocolSynthChef to stake them into farm

function depositLP(uint128 sid, uint256 lpTokenAmount) external onlyRole(DEPOSITOR) sidCheck(sid);

Parameters

NameTypeDescription

sid

uint128

Entangle's sid of the pool

lpTokenAmount

uint256

amount of lp tokens to deposit

withdrawLP

unstake lp tokens and transfer them to recipient address

function withdrawLP(uint128 sid, uint256 lpTokenAmount, address recipient)
    external
    onlyRole(DEPOSITOR)
    sidCheck(sid);

Parameters

NameTypeDescription

sid

uint128

Entangle's sid of the pool

lpTokenAmount

uint256

amount of lp tokens to withdraw

recipient

address

lp tokens recipient

withdrawLPAndExtract

unstake lp tokens, unwraps them to underlying assets and transfer underlying assets to recipient address. Only for liquidator's usage.

function withdrawLPAndExtract(uint128 sid, uint256 lpTokenAmount, address recipient)
    external
    onlyRole(DEPOSITOR)
    returns (uint256[] memory values, address[] memory tokens);

Parameters

NameTypeDescription

sid

uint128

Entangle's sid of the pool

lpTokenAmount

uint256

amount of lp tokens to withdraw

recipient

address

lp tokens recipient

compound

this function should be called from a special backend script that preconfigures all the data including compound fee transferring and approvals needed

function compound(
    uint128 sid,
    ICompounder.PreconfiguredCallConfig[] calldata callConfigs,
    uint256 minLP,
    bool reinvest
) external onlyRole(COMPOUNDER_EOA) sidCheck(sid) returns (uint256 lpCompounded);

_emitCompound

Function that emits special event required for handle metrics on Entangle's front

function _emitCompound(address chef, uint128 sid, uint32 poolId) internal;

Events

DepositLP

event DepositLP(uint128 sid, uint256 lpAmount, uint256 lpOnFarm);

WithdrawLP

event WithdrawLP(uint128 sid, uint256 lpAmount, uint256 lpOnFarm);

NewCompounder

event NewCompounder(address newAddress);

NewProtoSynthChef

event NewProtoSynthChef(uint32 indexed protocolId, address chefAddress);

Compound

event Compound(uint128 sid, uint256 lpOnFarm, uint256 newPrice);

WithdrawLPAndExtract

event WithdrawLPAndExtract(uint128 sid, uint256 lpAmount, address recipient, uint256 opId);

Errors

MasterSynthChef__E1

not lp staking sid : MasterSynthChef

error MasterSynthChef__E1();

MasterSynthChef__E3

wrong protocol id : MasterSynthChef

error MasterSynthChef__E3(uint32);

MasterSynthChef__E4

wrong pool Id : MasterSynthChef

error MasterSynthChef__E4(uint32);

MasterSynthChef__E5

compounder address eq 0 : MasterSynthChef

error MasterSynthChef__E5();

MasterSynthChef__E8

Protocol id already exists : MasterSynthChef

error MasterSynthChef__E8();

MasterSynthChef__E9

chefAddress eq 0 : MasterSynthChef

error MasterSynthChef__E9();

MasterSynthChef__E10

Amount eq 0 : MasterSynthChef

error MasterSynthChef__E10();

MasterSynthChef__E11

recipient address eq 0 : MasterSynthChef

error MasterSynthChef__E11();

MasterSynthChef__E12

Compound slippage error : MasterSynthChef

error MasterSynthChef__E12();

Structs

ProtocolSynthChefData

Struct that reflects Data about ProtocolSynthChef

struct ProtocolSynthChefData {
    uint32 protocolId;
    address synthChef;
}

CompoundTempData

Struct for internal usage in compound process

struct CompoundTempData {
    uint32 protocolId;
    uint32 poolId;
    address chef;
}

Last updated