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

NameTypeDescription

_admin

address

Address of the admin.

_synthFactory

address

Address of the SynthFactory contract.

_masterSynthChef

address

Address of the MasterSynthChef contract.

_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

NameTypeDescription

sid

uint128

SID to set the pause state for.

enabled

bool

Pause state to set.

setSynthFactory

Sets the SynthFactory contract address.

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

Parameters

NameTypeDescription

_synthFactory

SynthFactory

Address of the SynthFactory contract.

setMasterSynthChef

Sets the MasterSynthChef contract address.

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

Parameters

NameTypeDescription

_masterChef

MasterSynthChef

Address of the MasterSynthChef contract.

getDexSynthTokenBalance

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

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

Parameters

NameTypeDescription

sid

uint128

SID to get the balance for.

Returns

NameTypeDescription

<none>

uint256

Balance of Dex Synth token.

buyForLP

Buys LP tokens for a given SID.

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

Parameters

NameTypeDescription

sid

uint128

SID to buy LP tokens for.

lpAmount

uint256

Amount of LP tokens to buy.

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

NameTypeDescription

sid

uint128

SID to sell LP tokens for.

synthAmount

uint256

Amount of synthetic tokens to sell.

recipient

address

Address to receive LP tokens.

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

NameTypeDescription

sid

uint128

SID to sell LP tokens for.

synthAmount

uint256

Amount of synthetic tokens to sell.

recipient

address

Address to receive LP tokens.

Returns

NameTypeDescription

values

uint256[]

Array of LP token amounts and token addresses.

tokens

address[]

Array of LP token addresses.

convertLpToSynth

Converts LP tokens to synthetic tokens for a given SID.

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

Parameters

NameTypeDescription

sid

uint128

SID to convert LP tokens for.

lpAmount

uint256

Amount of LP tokens to convert.

Returns

NameTypeDescription

synthAmount

uint256

Amount of synthetic tokens obtained.

convertSynthToLp

Converts synthetic tokens to LP tokens for a given SID.

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

Parameters

NameTypeDescription

sid

uint128

SID to convert synthetic tokens for.

synthAmount

uint256

Amount of synthetic tokens to convert.

Returns

NameTypeDescription

lpAmount

uint256

Amount of LP tokens obtained.

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