EntangleDexV2

Git Source

Inherits: Initializable, UUPSUpgradeable, AccessControlUpgradeable, ReentrancyGuardUpgradeable

This contract facilitates the exchange of LP tokens for synthetic assets and vice versa. It integrates with the MasterSynthChef and SynthFactory contracts to manage LP token staking and synthetic asset creation.

State Variables

ADMIN_ROLE

Constant that defines Admin role

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

sidInfo

Mapping to store SID information

mapping(uint128 => SidInfo) public sidInfo;

masterSynthChef

Entangle MasterChef address

MasterSynthChef public masterSynthChef;

synthFactory

Entangle SynthFactory address

SynthFactory public synthFactory;

Functions

isPausedSID

Modifier to check if a SID is paused.

modifier isPausedSID(uint128 _sid);

onlyLpStakingSid

Modifier to check if a SID is an LP staking synth.

modifier onlyLpStakingSid(uint128 sid);

onlyHomeChain

Modifier to check if a SID belongs to the home chain.

modifier onlyHomeChain(uint128 sid);

constructor

constructor();

initialize

Initializes the contract.

function initialize(address _admin, address _synthFactory, address _masterSynthChef)
    public
    initializer;

Parameters

_authorizeUpgrade

function _authorizeUpgrade(address) internal override onlyRole(ADMIN_ROLE);

setPausedSid

Sets the pause state of a SID.

function setPausedSid(uint128 sid, bool enabled) public onlyRole(ADMIN_ROLE);

Parameters

setSynthFactory

Sets the SynthFactory contract address.

function setSynthFactory(SynthFactory _synthFactory) public onlyRole(ADMIN_ROLE);

Parameters

setMasterSynthChef

Sets the MasterSynthChef contract address.

function setMasterSynthChef(MasterSynthChef _masterChef) public onlyRole(ADMIN_ROLE);

Parameters

getDexSynthTokenBalance

Gets the balance of Dex Synth token for a given SID.

function getDexSynthTokenBalance(uint128 sid) public view returns (uint256);

Parameters

Returns

buyForLP

Buys LP tokens for a given SID.

function buyForLP(uint128 sid, uint256 lpAmount)
    public
    onlyLpStakingSid(sid)
    onlyHomeChain(sid)
    isPausedSID(sid)
    nonReentrant;

Parameters

sellForLP

Sells LP tokens for a given SID.

function sellForLP(uint128 sid, uint256 synthAmount, address recipient)
    public
    isPausedSID(sid)
    onlyHomeChain(sid)
    onlyLpStakingSid(sid)
    nonReentrant;

Parameters

sellForLPAndWithdraw

Sells LP tokens for a given SID and withdraws them.

function sellForLPAndWithdraw(uint128 sid, uint256 synthAmount, address recipient)
    public
    onlyLpStakingSid(sid)
    onlyHomeChain(sid)
    isPausedSID(sid)
    nonReentrant
    returns (uint256[] memory values, address[] memory tokens);

Parameters

Returns

convertLpToSynth

Converts LP tokens to synthetic tokens for a given SID.

function convertLpToSynth(uint128 sid, uint256 lpAmount)
    external
    view
    returns (uint256 synthAmount);

Parameters

Returns

convertSynthToLp

Converts synthetic tokens to LP tokens for a given SID.

function convertSynthToLp(uint128 sid, uint256 synthAmount)
    external
    view
    returns (uint256 lpAmount);

Parameters

Returns

Events

LPStackingSynthSell

event LPStackingSynthSell(uint128 sid, uint256 lpAmount, uint256 synthAmount, address recipient);

SynthFactorySetted

event SynthFactorySetted(address indexed newAddress);

SynthStateChanged

event SynthStateChanged(uint128 indexed sid, bool state);

MasterChefSetted

event MasterChefSetted(address indexed newAddress);

DepositLP

event DepositLP(uint128 indexed sid, address indexed buyer, uint256 indexed amount);

Errors

EntangleDex__E1

paused sid : EntangleDexV2

error EntangleDex__E1(uint128);

EntangleDex__E2

Non liquidable sid : EntangleDexV2

error EntangleDex__E2(uint128);

EntangleDex__E3

Not an lp staking synth : EntangleDexV2

error EntangleDex__E3(uint128);

EntangleDex__E4

Not the home network for synth : EntangleDexV2

error EntangleDex__E4(uint128);

EntangleDex__E5

zero amount : EntangleDexV2

error EntangleDex__E5();

EntangleDex__E6

crossChain operations are not allowed for this sid

error EntangleDex__E6();

Structs

SidInfo

Struct to store SID information

struct SidInfo {
    bool isPausedSid;
}

Last updated