CompliFi
Search…
Pool Data

Key Data Structures

Root element of the protocol is the PoolFactory, which contains a list of Pool contracts ordered by time of creation. Each pool is identified externally by its contract address and internally by index.
Each pool contains a list of derivatives, indexed internally by the creation time.
Each derivative consists of a pair of long ("primary") - short ("complement") pair, indexed as 0 and 1 respectively.
The three indices above are required to query derivative price and user balance.

Set-Up

Basic Pool Factory and Pool ABIs are available here and the Pool Factory address here. Any available script library such as Truffle or Hardhat can be used to request on-chain data and execute transacions.
This guide will use seth - a tool built by Dapphub to interact directly with smart contracts. To install, run the command below (note:Dapp Tools suite installs Nix OS):
1
curl https://dapp.tools/install | sh
Copied!
Follow the remaining steps to select the SETH_CHAIN and address/key: https://github.com/dapphub/dapptools/tree/master/src/seth#example-sethrc-file
Set pool factory proxy address to iterate through the pools:
1
$POOL_FACTORY_PROXY=/set address by the network/
Copied!

Pool Configs

Get pool addresses:
1
seth call $POOL_FACTORY_PROXY "getAllPools()" # returns all pools addresses
Copied!
Get pool configs:
1
seth call $POOL "getConfig()" # returns PoolConfig structure
2
# struct PoolConfig {
3
# uint256 minExitAmount; // minimal LP share tokens exit amount
4
# uint256 protocolFee; // protocol fee percentage ( multiplied 10^26)
5
# address feeWallet; // protocol fee collector
6
# address collateralToken; // pool's collateral token
7
# address collateralOracle; // collateral price feed
8
# address collateralOracleIterator; // collateral price feed iterator
9
# address volatilityEvolution;
10
# address underlyingLiquidityValuer;
11
# address exposure; // pool's market exposure level calculator
12
# address poolShare; // pool's LP token
13
# address traderPortfolio; // trader portfolio NFT token
14
# uint8 collateralDecimals; // colletersl ERC20 decimals param
15
# }
Copied!

Pool Metadata

Trader Portfolio and Pool Share metadata (token's name and symbol) can be requested as standard ERC721 and ERC20 parameters.
Labels below are of the form [Protocol]-[Pool Collateral]-[Derivative Type]. Please note that this form is expected to change in the future, as pools admit more than one type of derivative.
1
Pool 0: 0x4ca5d2088c82089f9700A4f766320844b0252430 COMFI-ETH-CALL
2
Pool 0: Trader Portfolio NFT: 0x812c5eAc129c654EeaF33Af33B42B10C80478712 (COMFI-ETH-CALL)
3
Pool 0: Share Token ERC20: 0x3Bb7f13FE182DB2b3D15cDc825f57088E058C4B0 (COMFI-ETH-CALL-LP)
4
5
Pool 1: 0x3FB905D163C1Ca55EEB649f8c76175781843Bc75 COMFI-BTC-CALL
6
Pool 1: Trader Portfolio NFT: 0x99d0D7C0533A2e1528F619599bC1E0136Ea9c7F4 (COMFI-BTC-CALL)
7
Pool 1: Share Token ERC20: 0x5Eccb0F69B068767d2688D155276e34A39d4097f (COMFI-BTC-CALL-LP)
8
9
Pool 2:0x76a130B4c7175721974c68827f84261e325eA0bD COMFI-MATIC-CALL
10
Pool 2: Trader Portfolio NFT: 0x3ea9b0E181b3C93cd2af834DaB718823F2Cc4705 (COMFI-MATIC-CALL)
11
Pool 2: Share Token ERC20: 0xDa8Abe34F38D5B1B6477fADa43E96F9B63899145 (COMFI-MATIC-CALL-LP)
12
13
Pool 3: 0xDdfd0BdC3444B9B5ABF33e26808fAa7161963Da9 COMFI-USDC-X5
14
Pool 3: Trader Portfolio NFT: 0x43B5146236B4F4B62704d05de44a97674C2FD305 (COMFI-USDC-X5)
15
Pool 3: Share Token ERC20: 0x2EE82c6900868d61E4c52a9d4E88C3F40b151978 (COMFI-USDC-X5-LP)
Copied!

Derivatives Data

1
seth call $POOL "getDerivativePrice(uint256)" $DERIVATIVE_INDEX
2
3
seth call $POOL "getDerivatives()" # returns all derivative information
4
# struct Derivative {
5
# DerivativeConfig config;
6
# address terms; // derivative's Terms Of Trade contract
7
# Sequence sequence; // derivative sequence params (sequence consists of back-to-back vintages of same derivative)
8
# DerivativeParams params; // current derivative vintage params
9
# }
10
11
# struct DerivativeConfig {
12
# address specification;
13
# address[] underlyingOracles; // addresses of oracles for underlying prices
14
# address[] underlyingOracleIterators; // mechanism for extracting historical price from oracle
15
# address collateralToken;
16
# address collateralSplit; // function that determines how collateral is split between long and short positions at settlement
17
# }
18
19
# struct Sequence {
20
# Mode mode; // reinvest = perpetual, temp = fixed maturity
21
# Side side; // "side" of derivative offered for sale - long(primary)/short(complement)/both/none
22
# uint256 settlementDelta; // period between derivative settlements or rollovers
23
# uint256 strikePosition; // determines strike level of a derivative relative to underlying price at the start
24
# }
25
26
# enum Mode {
27
# Temp,
28
# Reinvest
29
# }
30
31
# enum Side {
32
# Primary,
33
# Complement,
34
# Empty,
35
# Both
36
# }
37
38
# struct DerivativeParams {
39
# uint256 priceReference; // reference price of underlying asset, set at start
40
# uint256 settlement; // derivative settlement/rollover date
41
# uint256 denomination; // This nominal (instrinsic) value equation holds at all times: 1 long(primary) + 1 short(complement) = denomination * price of collateral
42
# }
43
44
seth call $POOL "getDerivativeVintages(uint256)" $DERIVATIVE_INDEX # returns all derivative's saved on-chain vintages
45
# struct Vintage {
46
# Pair rollRate; // used for settlements/rollovers; (number of derivatives in vintage n) * rollRate = number of derivatives in vintage n+1
47
# Pair releaseRate; // used for settlements/rollovers; amount of collateral sent to user per unit of derivative
48
# uint256 priceReference;
49
# }
50
51
# struct Pair {
52
# uint256 primary;
53
# uint256 complement;
54
# }
Copied!

Trader Data

All of trader's derivative positions are associated with their Portfolio NFT Token (ERC721)
1
seth call $POOL "checkPortfolioOf(address)" $TRADER_ADDRESS # returns whether trader has portfolio NFT or not
2
seth call $POOL "getPortfolioBy(address)" $TRADER_ADDRESS # returns trader NFT portfolio ID
3
4
seth call $POOL "derivativeBalanceOf(uint256, uint256)" $PORTFOLIO_ID $DERIVATIVE_INDEX
5
seth call $POOL "derivativeVintageIndexOf(uint256, uint256)" $PORTFOLIO_ID $DERIVATIVE_INDEX # returns actula vintage of the derivative in trader's portfolio
Copied!
Get up-to-date trader balances through API:
1
curl --location --request GET 'https://back.compli.fi/api/v2/portfolio/balance?network=137&user=<user address>
Copied!
Public portfolio balance API method will return user's up-to-date derivatives balances in all pools. Format of response is a hash structured by pool address, derivatives index, and derivative side where the user has available balances:
1
{
2
"<pool 0 address>": {
3
"<derivative 0 index>": {
4
"<derivative side primary index (0)>": <amount of derivative ( Number ) >,
5
"<derivative side complement index (1)>": <amount of derivative ( Number ) >
6
},
7
"<derivative 1 index>": {...},
8
...
9
"<derivative N index>": {...},
10
},
11
"<pool 1 address>": {...},
12
...
13
"<pool N address>": {...}
14
}
Copied!

Liquidity Provider Data

Get liquidity provider related information (separate ERC20 pool share token):
1
seth call $POOL_SHARE "balanceOf(address)" # returns LP balance of pool shares
2
seth call $POOL "getPoolSharePrice()" # returns pool share price
3
seth call $POOL "releasedLiquidityOf(address)" $LP_ADDRESS # return collateral liquidity available for withdrawing by user
Copied!

Derivatives and Pool Share (LP token) Prices

Get derivatives and pool share prices:
1
curl --location --request GET 'https://back.compli.fi/api/v2/pool/prices?network=137'
Copied!
Public pool prices API method will return current derivatives and pool share prices. Format of response is hash structured by pool address, derivatives index, and derivative side:
1
{
2
"<pool 0 address>": {
3
share: <pool share price USD (Number)>,
4
derivatives: {
5
"<derivative 0 index>": {
6
"<derivative side primary index (0)>": < primary derivative 1 side price USD (Number) >,
7
"<derivative side complement index (1)>": < complement derivative 1 side price USD (Number)>
8
},
9
"<derivative 1 index>": {...},
10
...
11
"<derivative N index>": {...}
12
}
13
14
},
15
"<pool 1 address>": {...},
16
...
17
"<pool N address>": {...}
18
}
Copied!