SynthFactory

SynthFactory creates synthetic tokens and also stores information about them (e.g. their current price).

Git Source

Inherits: Initializable, AccessControlUpgradeable, UUPSUpgradeable, OwnableUpgradeable

SynthFactory manages CDT creation, price fetching, comission handling

State Variables

ADMIN

Admin role

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

MINTER

Minter role

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

masterSynthChef

Address of Entangle MasterSynthChef

MasterSynthChef public masterSynthChef;

synths

Mapping that link sid with SynthInfo(address of synth token, and info if it is active)

mapping(uint128 => SynthInfo) public synths;

synthDecimals

Default Synth token decimals

uint8 public constant synthDecimals = 18;

feeCollector

Address of Entangle fee collector. The Address where we are accumalating all fees

address public feeCollector;

feeRate

Global commission rate

uint256 public feeRate;

customFeeRates

Mapping from Entangle sid to custom fee rates

mapping(uint128 => CustomFeeRate) public customFeeRates;

FEE_BASE

Fee divider for calculations of fees

uint256 public constant FEE_BASE = 10000;

Functions

constructor

constructor();

initialize

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

function initialize(
    address msc,
    address admin,
    address entangleDex,
    address _feeCollector,
    uint256 _globalFeeRate,
    SidName[] calldata sids
) public initializer;

Parameters

NameTypeDescription

msc

address

Address of the MasterChef contract.

admin

address

Address of the admin.

entangleDex

address

Address of the EntangleDex contract.

_feeCollector

address

Address of the Fee collecter, where we collect all fees.

_globalFeeRate

uint256

Initial fee rate for sids across all chain

sids

SidName[]

Array with initial Synths

_authorizeUpgrade

function _authorizeUpgrade(address) internal override onlyOwner;

validSynth

Modifier that checks if Synth is active

modifier validSynth(uint128 sid);

Parameters

NameTypeDescription

sid

uint128

Sid of the Synth token that should be checked

deploySynth

Function that managing the process of Synth token creation

function deploySynth(uint128 sid, string calldata name) public onlyRole(ADMIN) returns (address);

Parameters

NameTypeDescription

sid

uint128

Sid of Synth token that will be created

name

string

The name that will be assigned to new Synth token

Returns

NameTypeDescription

<none>

address

Address of created Synth token

mint

first depositor encounters a slight decrease of liquidity

Mint function for the Synth token

function mint(uint128 sid, uint256 amount, address to) public validSynth(sid) onlyRole(MINTER);

Parameters

NameTypeDescription

sid

uint128

Sid of the Synth token that should be minted

amount

uint256

Amount of Synth token to mint

to

address

Recipient of frsh tokens

burn

Mint function for the Synth token

Due to Entangle grabs comission only when user withdraw his token, also, commission is calculated here. The commission is in Synth token and we send it to feeCollector address.

function burn(uint128 sid, uint256 amount, address from)
    public
    validSynth(sid)
    onlyRole(MINTER)
    returns (uint256 feeGained);

Parameters

NameTypeDescription

sid

uint128

Sid of the Synth token that should be burned

amount

uint256

Amount of Synth token to burn

from

address

Address that will be burned

Returns

NameTypeDescription

feeGained

uint256

the amount of Synth token that should be gained

getSynth

Function that returns address of Synth token associated with a given sid.

function getSynth(uint128 sid) public view validSynth(sid) returns (EntangleSynth);

Parameters

NameTypeDescription

sid

uint128

Sid of Synth token

Returns

NameTypeDescription

<none>

EntangleSynth

Address of the Synth token

getPrice

Retrieves the current price of a synthetic asset.

The price is calculated as the ratio of the total locked LP token balance to the total supply of the synthetic asset.

function getPrice(uint128 sid) public view validSynth(sid) returns (uint256);

Parameters

NameTypeDescription

sid

uint128

Compressed information required to identify the synthetic asset.

Returns

NameTypeDescription

<none>

uint256

The current price of the synthetic asset, expressed with 18 decimals.

setFeeRate

Sets the fee rate percentage.

function setFeeRate(uint256 _feeRate) public onlyRole(ADMIN);

Parameters

NameTypeDescription

_feeRate

uint256

New fee rate percentage.

setCustomFeeRate

Sets custom fee rate for a specific SID.

function setCustomFeeRate(uint128 _sid, uint64 _feeRate, bool _useCustomFeeRate)
    public
    onlyRole(ADMIN);

Parameters

NameTypeDescription

_sid

uint128

Entangle's sid of the pool

_feeRate

uint64

New fee rate percentage.

_useCustomFeeRate

bool

Flag to indicate whether to use the custom fee rate.

setFeeCollector

Sets the fee collector address.

function setFeeCollector(address _feeCollector) public onlyRole(ADMIN);

Parameters

NameTypeDescription

_feeCollector

address

New fee collector address.

Events

Mint

event Mint(uint128 sid, uint256 amount, address to);

Burn

event Burn(uint128 sid, uint256 amount, address from);

SetPrice

event SetPrice(uint128 sid, uint256 price);

NewFeeRate

event NewFeeRate(uint256);

NewCustomFeeRate

event NewCustomFeeRate(uint128 sid, uint256 amount, bool);

NewFeeCollector

event NewFeeCollector(address indexed newAddress);

Errors

SynthFactory__E1

Synth already delpoyed : SynthFactory

error SynthFactory__E1();

SynthFactory__E2

SID is not active : SynthFactory

error SynthFactory__E2();

SynthFactory__E3

New fee rate should less than or equal to FEE_BASE : SynthFactory

error SynthFactory__E3();

SynthFactory__E4

Address of the new feeCollector equals to 0x0 : SynthFactory

error SynthFactory__E4();

Structs

SidName

struct that have sid and it's name

struct SidName {
    uint128 sid;
    string name;
}

CustomFeeRate

Struct that reflects Custom Fee Rates

struct CustomFeeRate {
    uint64 feeRate;
    bool useCustomFeeRate;
}

SynthInfo

Struct that have information about active state of synth and also address of synth

struct SynthInfo {
    bool isActive;
    EntangleSynth synth;
}

Last updated