Contracts
Docs for the ELFi Protocol contracts.
ELFi Protocol utilizes EIP-2535 Diamonds, see below a list of ELFi's diamond address:
Chain | Diamond address |
---|---|
Arbitrum | 0x153c613D572c050104086c7113d00B76Fbaa5d55 |
# Python demo: Get contract object
AccountFacet = w3.eth.contract(address= diamond_addr, abi=json.loads('AccountFacet.json'))
AccountFacet.getAccountInfo('0x000000000')
ABIs
All abis is here: ABIs (opens in a new tab)
Precision
USD value are multiplied by (10 ** 18)
Prices are multiplied by (10 ** 8)
Token amounts are multiplied by (10 ** token.decimals)
Rates are multiplied by (10 ** 5)
MarketFacet
All Symbol
To get all symbol information
function getAllSymbols() external view returns (SymbolInfo[] memory)
Response
struct SymbolInfo {
bytes32 code;
Symbol.Status status;
address stakeToken; // pool address
address indexToken; // index token
address baseToken; // base token for long position
SymbolConfig config;
}
Get a single symbol
To get a single symbol information
function getSymbol(bytes32 code) external view returns (SymbolInfo memory params)
Response
struct SymbolInfo {
bytes32 code;
Symbol.Status status;
address stakeToken;
address indexToken;
address baseToken;
SymbolConfig config;
}
AccountFacet
Only for CROSSED
Deposit
Deposit tokens to your portfolio account. First request rest api '/tokens' to get supported tokens
function deposit(address token, int256 amount) external payable
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
token | string | yes | Address of token that will be deposited |
amount | long | yes | The amount of token |
Demos
# python demo (Deposit 10 USDC):
USDC = '0xaf88d065e77c8cC2239327C5EDb3A432268e5831'
amount = 10 * 10 ** 6
USDCContract.functions.approve(diamond_addr, amount).build_transaction({
'from': account.address
})
AccountFacet.deposit(USDC, amount)
Creating a Withdrawal
Deposit tokens to your portfolio account.
function createWithdrawRequest(
address token,
int256 amount,
int256 executionFee,
bool isWithdrawMax
) external payable
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
token | string | yes | Address of token that will be withdrawn |
amount | long | yes | Multiplied by (10 ** token.decimals), set to 0 if isWithdrawMax is true |
executionFee | long | yes | The amount of native token that is included for the execution fee, currently not charged, set to 0 |
isWithdrawMax | bool | yes | Whether to withdraw all amount of the token |
Demos
#python demo (Withdraw 10 USDC):
USDC = '0xaf88d065e77c8cC2239327C5EDb3A432268e5831'
amount = 10 * 10 ** 6
AccountFacet.createWithdrawRequest(USDC, amount, 0, false)
#python demo (Withdraw all WBTC):
WBTC = '0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f'
amount = 0
AccountFacet.createWithdrawRequest(WBTC, amount, 0, true)
Account info
To get account information
function getAccountInfo(address account) external view returns (AccountInfo memory)
Response
struct AccountInfo {
address owner;
TokenBalance[] tokenBalances;
address[] tokens;
address[] trialFundsTokens;
uint256[] trialFundsAmounts;
bytes32[] positions;
uint256 portfolioNetValue;
uint256 totalUsedValue;
int256 availableValue;
uint256 orderHoldInUsd;
int256 crossMMR;
int256 crossNetValue;
uint256 totalMM;
}
OrderFacet
New Order
Send in a new increase/decrease position order. To create a increase isolate position order, you needs to first approval orderMargin to Diamond
function createOrderRequest(PlaceOrderParams calldata params) external payable;
Parameters PlaceOrderParams
Name | Type | Mandatory | Description |
---|---|---|---|
symbol | string | yes | BTCUSD |
isCrossMargin | bool | yes | True for CROSSED else ISOLATED |
isNativeToken | bool | yes | True for native token(Arbitrum is ETH), others false |
orderSide | int | yes | 1: LONG, 2: SHORT |
posSide | int | yes | 1: INCREASE, 2: DECREASE |
orderType | int | yes | 1: MARKET, 2: LIMIT, 3: STOP |
stopType | int | yes | 0: NOT_STOP_ORDER, 1: STOP_LOSS, 2: TAKE_PROFIT, 3: POSITION_STOP_LOSS, 4:POSITION_TAKE_PROFIT |
marginToken | string | yes | Address of margin token. baseToken for long, USDC for short |
qty | long | yes | The position size to decrease, multiplied by 10 ** 18 |
orderMargin | long | yes | The amount of margin to increase position. token amount for ISOLATED, multiplied by 10 ** token.decimals. usd amount for CROSSED, multiplied by 10 ** 18 |
leverage | long | yes | From 1 * 10 ** 5 to 20 * 10 ** 5 |
triggerPrice | long | yes | The trigger price for limit / stop-loss / take-profit orders, the order will be attempted to be executed if price reaches the trigger price |
acceptablePrice | long | yes | The acceptable price at which the order can be executed. For market orders, the order will be cancelled if it cannot be executed at the acceptable price. For limit / stop-loss / take-profit orders, the order will not be executed if the trigger price is reached but the acceptable price cannot be fulfilled |
executionFee | long | yes | The amount of native token that is included for the execution fee, currently not charged, set to 0 |
placeTime | long | yes |
Demos
#python demo (Create a increase long order, CROSSED)
WBTC = '0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f'
orderMargin = 100 * 10 ** 18 // 100 USD, usd value for CROSSED
leverage = 5 * 10 ** 5 // 5x
OrderFacet.createOrderRequest({
symbol: 'BTCUSD',
isCrossMargin: true,
isNativeToken: false,
orderSide: 1,
posSide: 1,
orderType: 1,
stopType: 0,
marginToken: WBTC,
qty: 0,
orderMargin: orderMargin,
leverage: leverage,
triggerPrice: 0,
acceptablePrice: 0,
executionFee: 0,
placeTime: 0,
})
#python demo (Create a increase short order, CROSSED)
USDC = '0xaf88d065e77c8cC2239327C5EDb3A432268e5831'
orderMargin = 100 * 10 ** 18 // 100 USD, usd value for CROSSED
leverage = 5 * 10 ** 5 // 5x
OrderFacet.createOrderRequest({
symbol: 'BTCUSD',
isCrossMargin: true,
isNativeToken: false,
orderSide: 2,
posSide: 1,
orderType: 1,
stopType: 0,
marginToken: USDC, // short need to use USDC
qty: 0,
orderMargin: orderMargin,
leverage: leverage,
triggerPrice: 0,
acceptablePrice: 0,
executionFee: 0,
placeTime: 0,
})
#python demo (Create a increase long order, ISOLATED)
WBTC = '0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f'
orderMargin = 1 * 10 ** 8 // 1 WBTC, token amount for ISOLATED
leverage = 5 * 10 ** 5 // 5x
// ISOLATED: first to execute approve
WBTCContract.functions.approve(diamond_addr, orderMargin).build_transaction({
'from': account.address
})
OrderFacet.createOrderRequest({
symbol: 'BTCUSD',
isCrossMargin: false,
isNativeToken: false,
orderSide: 1,
posSide: 1,
orderType: 1,
stopType: 0,
marginToken: WBTC,
qty: 0,
orderMargin: orderMargin,
leverage: leverage,
triggerPrice: 0,
acceptablePrice: 0,
executionFee: 0,
placeTime: 0,
})
#python demo (Create a increase short order, ISOLATED)
USDC = '0xaf88d065e77c8cC2239327C5EDb3A432268e5831'
orderMargin = 1000 * 10 ** 6 // 1000 USDC, token amount for ISOLATED
leverage = 5 * 10 ** 5 // 5x
// ISOLATED: first to execute approve
USDCContract.functions.approve(diamond_addr, orderMargin).build_transaction({
'from': account.address
})
OrderFacet.createOrderRequest({
symbol: 'BTCUSD',
isCrossMargin: false,
isNativeToken: false,
orderSide: 2,
posSide: 1,
orderType: 1,
stopType: 0,
marginToken: USDC, // short need to use USDC
qty: 0,
orderMargin: orderMargin,
leverage: leverage,
triggerPrice: 0,
acceptablePrice: 0,
executionFee: 0,
placeTime: 0,
})
#python demo (Create a decrease long position order, CROSSED)
WBTC = '0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f'
qty = 1000 * 10 ** 18 // 1000 USD
leverage = 5 * 10 ** 5 // 5x
OrderFacet.createOrderRequest({
symbol: 'BTCUSD',
isCrossMargin: true,
isNativeToken: false,
orderSide: 2, // short order to decrease long position
posSide: 2,
orderType: 1,
stopType: 0,
marginToken: WBTC,
qty: qty,
orderMargin: 0,
leverage: leverage,
triggerPrice: 0,
acceptablePrice: 0,
executionFee: 0,
placeTime: 0,
})
#python demo (Create a decrease short position order, CROSSED)
USDC = '0xaf88d065e77c8cC2239327C5EDb3A432268e5831'
qty = 1000 * 10 ** 18 // 1000 USD
leverage = 5 * 10 ** 5 // 5x
OrderFacet.createOrderRequest({
symbol: 'BTCUSD',
isCrossMargin: true,
isNativeToken: false,
orderSide: 1, // long order to decrease short position
posSide: 2,
orderType: 1,
stopType: 0,
marginToken: USDC,
qty: qty,
orderMargin: 0,
leverage: leverage,
triggerPrice: 0,
acceptablePrice: 0,
executionFee: 0,
placeTime: 0,
})
#python demo (Create a decrease long position order, ISOLATED)
WBTC = '0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f'
qty = 1000 * 10 ** 18 // 1000 USD
leverage = 5 * 10 ** 5 // 5x
OrderFacet.createOrderRequest({
symbol: 'BTCUSD',
isCrossMargin: false,
isNativeToken: false,
orderSide: 2, // short order to decrease long position
posSide: 2,
orderType: 1,
stopType: 0,
marginToken: WBTC,
qty: qty,
orderMargin: 0,
leverage: leverage,
triggerPrice: 0,
acceptablePrice: 0,
executionFee: 0,
placeTime: 0,
})
#python demo (Create a decrease short position order, ISOLATED)
USDC = '0xaf88d065e77c8cC2239327C5EDb3A432268e5831'
qty = 1000 * 10 ** 18 // 1000 USD
leverage = 5 * 10 ** 5 // 5x
OrderFacet.createOrderRequest({
symbol: 'BTCUSD',
isCrossMargin: false,
isNativeToken: false,
orderSide: 1, // long order to decrease short position
posSide: 2,
orderType: 1,
stopType: 0,
marginToken: USDC,
qty: qty,
orderMargin: 0,
leverage: leverage,
triggerPrice: 0,
acceptablePrice: 0,
executionFee: 0,
placeTime: 0,
})
Cancel an order
Cancel an existing order.
function cancelOrder(int256 orderId) external;
Parameters
PlaceOrderParams
Name | Type | Mandatory | Description |
---|---|---|---|
orderId | string | yes |
All orders
To get all orders of account
function getAccountOrders(address account) external view returns (AccountOrder[] memory);
Response
struct AccountOrder {
uint256 orderId;
Order.OrderInfo orderInfo;
}
struct OrderInfo {
address account;
bytes32 symbol;
Side orderSide;
PositionSide posSide;
Type orderType;
StopType stopType;
bool isCrossMargin;
bool isExecutionFeeFromTradeVault;
address marginToken;
uint256 qty;
uint256 leverage;
uint256 orderMargin;
uint256 triggerPrice;
uint256 acceptablePrice;
uint256 placeTime;
uint256 executionFee;
uint256 lastBlock;
}
PositionFacet
Get a single position
To get a single position of account
function getSinglePosition(
address account,
bytes32 symbol,
address marginToken,
bool isCrossMargin
) external pure returns (Position.Props memory)
Response
struct Position.Props {
bytes32 key;
bytes32 symbol;
bool isLong;
bool isCrossMargin;
address account;
address marginToken;
address indexToken;
uint256 qty;
uint256 entryPrice;
uint256 entryMarginTokenPrice;
uint256 leverage;
uint256 initialMargin;
uint256 initialMarginInUsd;
uint256 initialMarginInUsdFromBalance;
uint256 holdPoolAmount;
PositionFee positionFee;
int256 realizedPnl;
uint256 lastUpdateTime;
}
All positions
To get all positions of account
function getAllPositions(address account) external view returns (PositionInfo[] memory)
Response
struct PositionInfo {
Position.Props position;
uint256 liquidationPrice;
uint256 currentTimestamp;
}