NAV

Introduction

Welcome to the GoldLink documentation! This is the source of truth for accessing the API as well as the GoldLink Python client.

General

Percents

All percents are denominated in WAD where 1e18 = 100%.

Strategy Asset

Each strategy will have a single asset (i.e. USDC) used as both lender capital and as collateral by borrowers. From the API all strategy all strategy assets can be fetched. Additionally, from the client, get strategy asset can be called per strategy.

Core API

The GoldLink JRPC API collates all GoldLink related strategy information and serves requests primarily to power the frontend. See client for information on programmatically engaging the protocol.

Every endpoint begins with https://api-dev.goldlink.io/?method=goldlink/ for testnet.

Get Strategies

JSON Response

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": [
    {
      "name": "Gmx Funding Rate Farming",
      "protocols": ["GMX"],
      "deploy_block": 32169822,
      "controller": "0x62be6F58cD141542d3e0d1CB1814e2464cbf3462",
      "bank": "0xfc8D0b15999b040A2cF1C6fD4ABF18e6f70E84C7",
      "reserve": "0x4b927EC02cFAB1237eA9e13d5568850Dc0FDFBF5",
      "account_deployer": "0x054BF3E7Ce0CFbb069Ab08794BbeD28dBC9d546a",
      "asset": "0x3eBDeaA0DB3FfDe96E7a0DBBAFEC961FC50F725F",
      "insurance_premium": "50000000000000000",
      "tvl_cap": "1000000000000",
      "token_metadata": {
        "name": "USD Coin",
        "address": "0x3eBDeaA0DB3FfDe96E7a0DBBAFEC961FC50F725F",
        "symbols": "USDC",
        "decimals": 6
      },
      "strategy_metadata": {
        "complexity": "5",
        "strategy_risk": "2",
        "longevity": "3",
        "protocol_risk": "1",
        "sharpe_ratio": "2"
      }
      ]
    }
  ]
}

Example Request: https://api-dev.goldlink.io/?method=goldlink/getStrategies

Response

Value Type Description
Strategies Strategy Array All strategies in the protocol.

Strategy

Value Type Description
name String The name of the strategy.
protocols String Array Array of all of the protocols borrowers can actively engage in the strategy.
deploy_block Number The block the strategy was deployed at.
controller Address The address of the strategy controller, maintaining shared state between bank and reserve.
bank Address The address of the strategy bank, where strategy accounts are deployed from.
reserve Address The address of the strategy reserve, where lender funds are deposited.
account_deployer Address The address of the account deployer, responsible for deploying strategy accounts for a specific strategy.
asset Address The address of the asset used for lending, borrowercollateral and lender interest payment in the strategy.
insurance_premium Integer String The percent haircut (see percents) of borrow APR that goes to the insurance fund, not lenders.
tvl_cap Integer String The maximum Asset that can be deposited by lenders into the protocol. Denominated in Asset decimals .
token_metadata TokenMetadata Metadata about the Asset.
strategy_metadata StrategyMetadata Metadata about the Strategy, see risk.

Token Metadata

Value Type Description
name String Name of the token.
address Address The address of the token.
symbol String The symbol for the token.
decimals Number The number of decimals the token has.

Get Strategy Info

JSON Response

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": {
    "supply_apy": "61722007479061281",
    "borrow_apr": "111722007479061281",
    "reserve_balance": "174595347",
    "utilized": "75000000",
    "token_metadata": {
      "name": "USD Coin",
      "address": "0x3eBDeaA0DB3FfDe96E7a0DBBAFEC961FC50F725F",
      "symbol": "USDC",
      "decimals": 6
    }
  }
}

Example Request: https://api-dev.goldlink.io/?method=goldlink/getStrategyInfo&params=["0x62be6F58cD141542d3e0d1CB1814e2464cbf3462"]

Parameters

Parameter Type Description
Strategy Controller Address The address of the strategy controller for the strategy.

Response

Value Type Description
supply_apy String Number The APY paid to lenders.
borrow_apr String Number The rate paid borrowers.
reserve_balance String Number The total balance in the reserve.
utilized String Number The total utilized funds in the strategy.
token_metadata TokenMetadata The metadata for the reserve asset used to lend as well as for collateral.

Get Historic Strategy Info

JSON Response

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": {
    "token_metadata": {
      "name": "USD Coin",
      "address": "0x3ebdeaa0db3ffde96e7a0dbbafec961fc50f725f",
      "symbol": "USDC",
      "decimals": 6
    },
    "values": {
      ...
      {
        "ts": "2024-05-15T17:19:05Z",
        "borrow_apr": "82834714562903052",
        "supply_apy": "78692978834757899",
        "balance": "194048871030",
        "utilized": "5311000000",
        "utilization_percent": "27369393966630798"
      }
    }
  }
}

Example Request: https://api-dev.goldlink.io/?method=goldlink/getHistoricStrategyInfo&params=["0x4b927EC02cFAB1237eA9e13d5568850Dc0FDFBF5", 0, -1]

See percents for explainer on how all percentage response values are represented.

Parameters

Parameter Type Description
Strategy Reserve Address The address of the strategy reserve for the strategy.
Start Integer The UNIX timestamp to look from, 0 if start of all time.
Stop Integer The UNIX timestamp to look up to, -1 if now.

Response

Value Type Description
token_metadata TokenMetadata The metadata for the reserve asset used to lend as well as for collateral.
values HistoricStrategyInfo Array The values for the reserve at each point in time.

HistoricStrategyInfo

Parameter Type Description
ts Timestamp String The timestamp of the info.
borrow_apr Integer The APR borrowers pay on their loans.
supply_apy Integer The APY lenders are paid for their borrowed capital.
balance Integer The total balance of the reserve, includes available and utilized assets.
utilized Integer The total utilized assets in the reserve.
utilization_percent Integer The percent of lender funds being utilized.

Get Strategy Summary

JSON Response

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": {
    "strategy_name": "Gmx Funding Rate Farming",
    "total_value_locked": "165001192",
    "reserve_state": {
      "reserve_address": "0x4b927EC02cFAB1237eA9e13d5568850Dc0FDFBF5",
      "apy_7_day": "63229557520742142",
      "utilization_percent": "454542170822620481"
    },
    "complexity": "5",
    "capacity": "0"
  }
}

Example Request: https://api-dev.goldlink.io/?method=goldlink/getStrategySummary&params=["0x4b927EC02cFAB1237eA9e13d5568850Dc0FDFBF5"]

Parameters

Parameter Type Description
Strategy Reserve Address The address of the strategy reserve for the strategy.

Response

Value Type Description
strategy_name String The name of the strategy.
total_value_locked Integer String Total loan assets locked into the strategy.
reserve_state ReserveState The state of the reserve.
complexity Integer String The overall complexity score of the strategy.
capacity Integer String The maximum total assets that can be loaned to the strategy.

Reserve State

Value Type Description
reserve_address String The address of the strategy Reserve.
apy_7_day Integer String The seven day APY of the strategy for lenders.
utilization_percent Integer String The percent (see percents) of loan assets being borrowed.

Get Interest Rate Model

JSON Response

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": {
    "y_intercept": "80000000000000000",
    "rate_slope1": "105560000000000000",
    "rate_slope2": "15000000000000000000",
    "optimal_utilization": "900000000000000000"
  }
}

Example Request: https://api-dev.goldlink.io/?method=goldlink/getInterestRateModel&params=["0x4b927EC02cFAB1237eA9e13d5568850Dc0FDFBF5"]

See percents for explainer on how all response values are represented.

Parameters

Parameter Type Description
Strategy Reserve Address The address of the strategy reserve for the strategy.

Response

Value Type Description
y_intercept Integer String The base rate paid when borrowing is greater than 0%.
rate_slope1 Integer String The rate paid when borrowing is less than OptimalUtilization.
rate_slope2 Integer String The rate paid in addition to RateSlope1 when borrowing is greater than OptimalUtilization.
optimal_utilization Integer String The percent at which the interest rate rapidly grows to disincentivize borrowing.

Get Historic Reserve Interest Rate

JSON Response

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": [
    ...
    {
      "apy": "111722007479061281",
      "timestamp": "2024-04-28T23:42:05Z"
    },
    {
      "apy": "111719341306470749",
      "timestamp": "2024-04-30T06:58:58Z"
    },
    {
      "apy": "112331045072343622",
      "timestamp": "2024-05-01T07:37:48Z"
    }
  ]
}

Example Request: https://api-dev.goldlink.io/?method=goldlink/getHistoricReserveInterestRate&params=["0x4b927EC02cFAB1237eA9e13d5568850Dc0FDFBF5", 0, -1]

Parameters

Parameter Type Description
Strategy Reserve Address The address of the strategy reserve for the strategy.
Start Integer The UNIX timestamp to look from, 0 if start of all time.
Stop Integer The UNIX timestamp to look up to, -1 if now.

Response

Parameter Type Description
APY Array APY Array Array of APYs

APY

Parameter Type Description
apy Integer String The APY value at the timestamp.
timestamp Timestamp String The ISO timestamp string for the APY.

Get Risk Score

JSON Response

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": {
    "protocol_risk": "1",
    "tvl_risk": "1",
    "utilization_risk": "1",
    "complexity": "2",
    "longevity": "5"
  }
}

Example Request: https://api-dev.goldlink.io/?method=goldlink/getRiskScore&params=["0x4b927EC02cFAB1237eA9e13d5568850Dc0FDFBF5"]

Parameters

Parameter Type Description
Strategy Reserve Address The address of the strategy reserve for the strategy.

Response

Value Type Description
protocol_risk Integer String The risk associated with the strategy protocols.
tvl_risk Integer String The risk associated with the strategy tvl.
utilization_risk Integer String The risk associated with the strategy utilization.
complexity Integer String The rated complexity of the strategy.
longevity Integer String How long the strategy protocols have been deployed for.

Risk scoring guide

Get Lending Stats

JSON Response

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": {
    "total_value_locked_usd": "174595347",
    "total_borrowed_usd": "75000000",
    "protocol_net_earnings": 92651
  }
}

Example Request: https://api-dev.goldlink.io/goldlink/getLendingStats

Response

Value Type Description
total_value_locked_usd Integer String The lender TVL denominated in USD.
total_borrowed_usd Integer String The total borrowed assets denominated in USD.
protocol_net_earnings Number The total proft (includes interest and insurance) paid to lenders and the insurance pool.

Get Lenders

JSON Response

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": ["0xd369853d3e81e7b07f8642fb884634617cb8be07"]
}

Example Request: https://api-dev.goldlink.io/?method=goldlink/getLenders&params=["0x4b927EC02cFAB1237eA9e13d5568850Dc0FDFBF5"]

Parameters

Parameter Type Description
Strategy Reserve Address The address of the strategy reserve for the strategy.

Response

Value Type Description
Lenders Address Array The addresses of all lenders for the strategy.

Get Lender Position

JSON Response

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": {
    "strategy_name": "Gmx Funding Rate Farming",
    "protocols": ["GMX"],
    "deposits_usd": "1662337",
    "reserve_state": {
      "reserve_address": "0x4b927EC02cFAB1237eA9e13d5568850Dc0FDFBF5",
      "apy_7_day": "63229557520742142",
      "utilization_percent": "454542170822620481"
    },
    "realized_profit_usdc": "80000000",
    "unrealized_profit_usdc": "108338457"
  }
}

Example Request: https://api-dev.goldlink.io/?method=goldlink/getLenderPosition&params=["0x4b927EC02cFAB1237eA9e13d5568850Dc0FDFBF5", "0xd369853d3e81e7b07f8642fb884634617cb8be07", 0]

Parameters

Parameter Type Description
Strategy Reserve Address The address of the strategy reserve for the strategy.
Lender Address Address The address of the lender in the strategy.
Block Integer The first block to look from.

Response

Value Type Description
strategy_name String The name of the strategy.
protocols String Array List of protocols loan funds can be deployed to from the strategy.
deposits_usd Integer String The total USD value of loans deposited into the strategy by the lender.
reserve_state ReserveState The state of the reserve.
realized_profit_usdc Integer String The total claimed lender profit in USDC since Block for lender.
unrealized_profit_usdc Integer String The total unclaimed lender profit in USDC since Block for lender.

Get Strategy Accounts

JSON Response

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": [
    "0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
    "0x518f1c560789df8120f1c7bc2613f5eb97408173",
    "0x12094df59ac5f58b1527c6757b068982663ac3e3",
    "0x29d56d61ced1b48ca2a5471e43f4ed94e691b22d",
    "0x32a81630e55f69cc5f3eafe1b5d4dc7f0a1ae79f",
    "0x24c55be7a954d1a4169a006ee123dd517333be9f",
    "0xd6fa45c469acbfa081c7bea36d1c95e98f38629d",
    "0x511a6334bf1d7b189b1e5797a7a6e8f85ec01a02",
    "0xa30f4ba11c7b3f1786078b74b06e8b6ac7c4d6f0",
    "0x1a646afcdfd4827dbb6a94dddc7a9ea5854c6f41"
  ]
}

Example Request: https://api-dev.goldlink.io/?method=goldlink/getStrategyAccounts&params=["0x9d42836db1cfad7898b486b9c8265ce8d9c99d71"]

Parameters

Parameter Type Description
Strategy Bank Address The address of the strategy reserve for the strategy.

Response

Value Type Description
Strategy Accounts Address Array The array of all strategy addresses deployed by the strategy bank.

Get Strategy Account

JSON Response

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": "0x34effbade0f3a31c349ba4fd1be4869fa1392c8c"
}

Example Request: https://api-dev.goldlink.io/?method=goldlink/getStrategyAccount&params=["0x9d42836db1cfad7898b486b9c8265ce8d9c99d71", "0xd369853D3E81e7b07f8642fB884634617CB8Be07"]

Parameters

Parameter Type Description
Strategy Bank Address The address of the strategy reserve for the strategy.
Owner Address The address of the strategy account owner.

Response

Value Type Description
Strategy Account Address The strategy account owned by Owner in the strategy bank.

GMX FRF Strategy API

The GMX Funding-Rate Farming API provides relevant information for the GMX Funding-Rate Farming strategy. The information is derived both from GoldLink events and directly from GMX V2 events. See API for general API.

Execution Fee

For certain methods that require GMX Keeper's to execute, such as executeCreateIncreaseOrder and executeCreateDecreaseOrder, an executionFee must be provided. This execution fee can be calculated using the logic provided by GMX here: https://github.com/gmx-io/gmx-synthetics/blob/main/contracts/gas/GasUtils.sol

The msg.value for any method containing the executionFee should be equivalent to the executionFee. If the msg.value is greater than executionFee, funds will be lost. However, any excess executionFee provided (which will likely be the case) will be refunded to the original msg.sender upon keeper execution.

For multicalls, the msg.value must be equivalent to the sum of all executionFee parameters passed to nested multicall methods.

GMX Price Formatting

Any parameter, field, or return value that contains the suffix USD can be formatted by dividing by 10^30, i.e. 15100000000000000000000000000000 -> $15.1

To calculate the GMX USD price of a given asset, compute the USD price in GMX terms, i.e. formatted price * 1e30, and divide the result by 10^decimals, where decimals represents the ERC20 decimals of the specified asset. For example, if the current price of ETH is 3742.8, to compute the GMX USD price you would do the following: 3742.8 * 1e30 / 1e18 = 3742800000000000.

To convert a token amount to a GMX USD value, given the GMX USD price, simply multiply the two together. For example, to get the value of 1.5 ETH given a GMX USD price of 3742800000000000: 3742800000000000 * 1500000000000000000 = 5.6142×10^33.

Get GMX Markets

JSON Response

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": [
    {
      "Pair": "WAVAX-USDC",
      "Market": "0xD996ff47A1F763E1e55415BC4437c59292D1F415",
      "long_token": {
        "name": "Wrapped Avax",
        "address": "0x1D308089a2D1Ced3f1Ce36B1FcaF815b07217be3",
        "symbol": "WAVAX",
        "decimals": 18
      },
      "short_token": {
        "name": "USD Coin",
        "address": "0x3eBDeaA0DB3FfDe96E7a0DBBAFEC961FC50F725F",
        "symbol": "USDC",
        "decimals": 6
      }
    }
  ]
}

Example Request: https://api-dev.goldlink.io/?method=goldlink/getGmxMarkets

Response

Value Type Description
Markets Market Array All markets whitelisted in the strategy.

Market

Value Type Description
pair String The market pair.
market Address The address of the market on GMX.
long_token TokenMetadata The metadata for the long token.
short_token TokenMetadata The metadata for the short token.

Get All Market One Hour Funding

JSON Response

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": [
    {
      "market": "0xc25cef6061cf5de5eb761b50e4743c1f5d7e5407",
      "funding_rate": 5.004020197548746e25
    },
    {
      "market": "0x7f1fa204bb700853d36994da19f830b6ad18455c",
      "funding_rate": 4.8646388389539954e25
    },
    ...
  ]
}

Example Request: https://api-dev.goldlink.io/?method=goldlink/getAllMarketOneHourFunding

Request

Value Type Description
limit (Optional) Integer Will default to look within the most recent 1000 events. Modify to expand or compress the search.

Response

Value Type Description
Markets MarketFunding Array The one hour funding for all markets whitelisted in the strategy.

MarketFunding

Value Type Description
market Address The address of the market on GMX.
funding_rate Integer The one hour funding for the market with 1e30 being 100%.

Get Gmx Historic Funding Rate

JSON Response

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": [
    {
      "ts": "2024-01-08T16:31:33Z",
      "funding_rate": 409968000000000000000000000000
    },
    {
      "ts": "2024-01-08T16:35:46Z",
      "funding_rate": 409968000000000000000000000000
    },
    ...
  ]
}

Example Request: http://api-dev.goldlink.io/?method=goldlink/getGmxHistoricFundingRate&params=["0x70d95587d40A2caf56bd97485aB3Eec10Bee6336"]

Request

Value Type Description
market Address The address of the market on GMX.
sample (Optional) Integer Will default to sample every 200 events. Modify to expand or compress the search.

Response

Value Type Description
Markets FundingRateTime Array The funding rate at each time for the market in the strategy.

FundingRateTime

Value Type Description
ts Timestamp The ISO Timestamp the funding rate event was emitted at.
funding_rate Integer The yearly funding for the market with 1e30 being 100%.

Get Gmx Historic Open Interest

JSON Response

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": {
    "long_oi": [
      {
        "ts": "2024-01-08T16:06:14Z",
        "value": "30376974277341196258139521845544274788"
      },
      {
        "ts": "2024-01-08T16:06:14Z",
        "value": "30376223177341196258139521845544274788"
      },
      ...
    ]
  }
}

Example Request: http://api-dev.goldlink.io/?method=goldlink/getGmxHistoricOpenInterest&params=[%220x70d95587d40A2caf56bd97485aB3Eec10Bee6336%22]

Request

Value Type Description
market Address The address of the market on GMX.
sample (Optional) Integer Will default to sample every 200 events. Modify to expand or compress the search.

Response

Value Type Description
Markets OpenInterestTime Array The open interest at each time for the market in the strategy.

OpenInterestTime

Value Type Description
ts Timestamp The ISO Timestamp the funding rate event was emitted at.
value Integer The open interest for the market with 1e30 being 1.

Get Account Orders

JSON Response

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": [
    {
      "order_type": "increase",
      "block": 32219453,
      "log_index": 8,
      "txn": "0x3d52969047107afc74ab37c6cccca5de2ba0874e018010205201a07919018653",
      "ts": "2024-04-25T00:55:09Z",
      "order_status": 2,
      "order_key": "0xa18b0cc36fe8b1f387bcbe1d53b8f122632eec96b85965cf3a33c963d3d67bfc",
      "market": "0xd996ff47a1f763e1e55415bc4437c59292d1f415",
      "initial_collateral_token": "0x3ebdeaa0db3ffde96e7a0dbbafec961fc50f725f",
      "size_delta_usd": "59944635162673741498589046929242",
      "initial_collateral_delta_amount": "60000000",
      "acceptable_price": "32919559686000",
      "execution_fee": "2500000000000000000",
      "min_output_amount": "1476429285919945338"
    },
    {
      "order_type": "decrease",
      "block": 32219473,
      "log_index": 9,
      "txn": "0x51d543de4577d90c73707e2cd4c31c4e8581613b7b0a1a6d1d77dc07cabbf778",
      "ts": "2024-04-25T00:55:52Z",
      "order_status": 2,
      "order_key": "0xecacf425683e8e1d061c836fed90104e696af80d8f5c3fe47b5c37a5a1908b8b",
      "market": "0xd996ff47a1f763e1e55415bc4437c59292d1f415",
      "initial_collateral_token": "0x1d308089a2d1ced3f1ce36b1fcaf815b07217be3",
      "size_delta_usd": "60000000",
      "initial_collateral_delta_amount": "0",
      "acceptable_price": "40235017394000",
      "execution_fee": "2500000000000000000",
      "min_output_amount": "0"
    },
    ...
  ]
}

Example Request: https://api-dev.goldlink.io/?method=goldlink/getGmxAccountOrders&params=["0x12094df59AC5F58B1527c6757B068982663Ac3e3"]

Parameters

Value Type Description
Strategy Account Address The Strategy Account orders are being queried for.

Response

Value Type Description
Orders Order Array Array of orders placed by the Strategy Account.

Order

Value Type Description
order_type String The type of the order (increase, decrease, etc.).
block Integer The block the order was placed at.
log_index Integer The index of the event log the order was created at.
txn Bytes The transaction the order was placed in.
ts Timestamp The timestamp the order was placed at.
order_key String The Hex string representing the order's unique key in GMX.
market Address The GMX Market address the order was placed for.
initial_collateral_token Address The address of the token that acted as the initial collateral.
size_delta_usd Integer String The size of the order in USD.
initial_collateral_delta_amount Integer String The initial delta from collateral.
acceptable_price Integer String The price the order can execute at.
execution_fee Integer String The fee charged for executing the order.
min_output_amount Integer String The minimum assets received for collateral.

Get Account Positions

JSON Response

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": [
    {
      "account": "0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
      "market": "0xd996ff47a1f763e1e55415bc4437c59292d1f415",
      "block": 32620554,
      "ts": "2024-05-05T20:38:34Z",
      "collateral_token": "0x1d308089a2d1ced3f1ce36b1fcaf815b07217be3",
      "size_in_usd": "299685675137860788334582336584084",
      "size_in_tokens": "8530371863020640471",
      "collateral_amount": "8506718133078685384",
      "borrowing_factor": "7788416999744280335881332446",
      "funding_fee_amount_per_size": "482996967050024352214002030609",
      "long_token_claimable_funding_amount_per_size": "410133071027199098221216356660640",
      "short_token_claimable_funding_amount_per_size": "420464391921245350625",
      "index_token_price_max": "37220000000000",
      "collateral_token_price_max": "37220000000000",
      "position_key": "0xe42db38a62b7a50b13472106b711bb29cff4b15016025fa95732b4760f39eb15"
    }
  ]
}

Example Request: https://api-dev.goldlink.io/?method=goldlink/getAccountPositions&params=["0x5E6084dB5CE5206EfFd84350Fe101Fe70517eF92"]

Parameters

Value Type Description
Strategy Account Address The address of the strategy account being queried.

Response

Value Type Description
Positions Position Array Array of positions for the strategy account.

Position

Value Type Description
account Adress The address of the strategy account.
market Address The address of the market the position is for.
block Integer The block the position was created at.
ts Timestamp The ISO Timestamp the position was created at.
collateral_token Address The address of the collateral token.
size_in_usd Integer String The value in USD of the position.
size_in_tokens Integer String The vlaue of the position in collateral tokens.
collateral_amount Integer String The amount of collateral backing the position.
borrowing_factor Integer String The cost factor for borrowing.
funding_fee_amount_per_size Integer String The funding fee per size of the position.
long_token_claimable_funding_amount_per_size Integer String The claimable funding amount for long asset per size.
short_token_claimable_funding_amount_per_size Integer String The claimable funding amount for short asset per size.
index_token_price_max Integer String The maximum price of the index token.
collateral_token_price_max Integer String The maximum price of the collateral token.
position_key Bytes The key for the position in GMX storage.

Get Account Active Positions

JSON Response

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": [
    {
      "position_key": "0xe42db38a62b7a50b13472106b711bb29cff4b15016025fa95732b4760f39eb15",
      "market": "0xd996ff47a1f763e1e55415bc4437c59292d1f415",
      "short_token": "0x3ebdeaa0db3ffde96e7a0dbbafec961fc50f725f",
      "long_token": "0x1d308089a2d1ced3f1ce36b1fcaf815b07217be3",
      "short_token_price_min": "1000194480000000000000000",
      "short_token_price_max": "1000194480000000000000000",
      "long_token_price_min": "37220000000000",
      "long_token_price_max": "37220000000000"
    }
  ]
}

Example Request: https://api-dev.goldlink.io/?method=goldlink/getGmxAccountActivePositions&params=["0x5E6084dB5CE5206EfFd84350Fe101Fe70517eF92"]

Parameters

Value Type Description
Strategy Account Address The address of the strategy account being queried.

Response

Value Type Description
Active Positions ActivePosition Array Array of active positions for the strategy account.

ActivePosition

Value Type Description
position_key Bytes The key for the position in GMX storage.
market Address The address of the market the position is for.
short_token Address The address of the short token.
long_token Address The address of the long token.
short_token_price_min Integer String The minimum acceptable price for the short token.
short_token_price_max Integer String The maximum acceptable price for the short token.
long_token_price_min Integer String The minimum acceptable price for the long token.
long_token_price_max Integer String The maximum acceptable price for the long token.

Get All Claim Funding Fee Events for Account

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": [
    {
      "ts": "2024-05-31T13:27:48Z",
      "markets": [
        "0x70d95587d40a2caf56bd97485ab3eec10bee6336",
        "0x70d95587d40a2caf56bd97485ab3eec10bee6336"
      ],
      "assets": [
        "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
        "0xaf88d065e77c8cc2239327c5edb3a432268e5831"
      ],
      "amounts": ["1204825788707", "19192"]
    },
    {
      "ts": "2024-06-04T14:12:19Z",
      "markets": [
        "0x70d95587d40a2caf56bd97485ab3eec10bee6336",
        "0x70d95587d40a2caf56bd97485ab3eec10bee6336"
      ],
      "assets": [
        "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
        "0xaf88d065e77c8cc2239327c5edb3a432268e5831"
      ],
      "amounts": ["667918596249206", "9845721"]
    },
    ...
  ]
}

Example Request: https://api-dev.goldlink.io/?method=goldlink/getGmxAccountActivePositions&params=["0x2E6084cB5CF5200AfFd24350Aa161Fe70513eF90"]

Parameters

Value Type Description
Strategy Account Address The address of the strategy account being queried.

Response

Value Type Description
Claim Events ClaimEvent Array Array of claim events for the strategy account.

ClaimEvent

Value Type Description
ts Timestamp The ISO timestamp of the claim event.
markets Address Array The array of markets that claim events were for. Note, markets match 1:1 with assets so a single market will appear twice in a claim event.
assets Address Array The array of assets the claims were in.
amounts Integer Array The array of claim amounts, denominated in asset decimals.

Get Oracle Price

JSON Response

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": {
    "min_price": "20840000000000",
    "max_price": "20840000000000"
  }
}

Example Request: https://api-dev.goldlink.io/?method=goldlink/getOraclePrice&params=["0x1D308089a2D1Ced3f1Ce36B1FcaF815b07217be3"]

Parameters

Value Type Description
Asset Address The address of the asset being queried.

Response

Value Type Description
min_price Integer String The minimum price of asset in interval.
max_price Integer String The maximum price of asset in interval.

Core Client

The client provides the functionality to read from and write directly to the blockchain. This allows acting as a lendor, borrower or liquidator on the GoldLink Protocol. The client can be accessed on github or downloaded from Pypi. See examples for walkthroughs of different client flows.

Getting Started

The goal of the Client is to allow flexible use depending on what features are neeed. The client can support varying levels of authentication. See the examples directory for complete examples.

Reader Endpoints

Python

from web3 import Web3

from goldlink import Client
from goldlink import constants

read_client = Client(
    network_id=constants.NETWORK_ID_FUJI,
)
read_client.reader.get_strategy_asset(
    strategy_reserve="0x4b927EC02cFAB1237eA9e13d5568850Dc0FDFBF5",
)

No authentication is required to access any reader module.

However, one of the following is required to query contracts. This will also be needed for sending transactions with the writer:

Writer Endpoints

Python

from web3 import Web3

from goldlink import Client
from goldlink import constants

write_client = Client(
    host=constants.NETWORK_ID_FUJI,
    web3_provider=Web3.HTTPProvider(...),
)
write_client.writer.deposit(
    amount=10000000,
    strategy_reserve="0x4b927EC02cFAB1237eA9e13d5568850Dc0FDFBF5",
)

To initialize a writer client, one of the following is required to sign transactions:

Initialize Client

Python

# Initialize client.
client = Client(
    network_id=constants.NETWORK_ID_FUJI,
    web3=Web3(Web3.HTTPProvider(constants.WEB_PROVIDER_URL_FUJI)),
    private_key=PRIVATE_KEY,
    strategy_reserve="0x4b927EC02cFAB1237eA9e13d5568850Dc0FDFBF5",
)

Full set of options when initializing a client.

Parameters

Parameter Type Description
send_options (Optional) SendOptions Default send options to transact with, see sendTransaction.
api_timeout (Optional) Integer The timeout window for requests, in milliseconds.
web3 (Optional) Web3 Web3 object used to sign and/or send transactions/queries.
network_id (Optional) Integer The network ID for the chain. Defaults to web3.net.version if available or constants.NETWORK_ID_MAINNET.
private_key (Optional) Bytes The private key to transact with.
web3_account (Optional) Web3Account The Web3 account holding the private key to transact with.
web3_provider (Optional) Web3Provider The Web3 provider, same utility as web3 object.
host (Optional) String The host URL to send transactions through.
strategy_reserve (Optional)Address Address of the Strategy Reserve that will be queried/have transactions sent to it.
strategy_bank (Optional)Address Address of the Strategy Bank that will be queried/have transactions sent to it.
strategy_account (Optional)Address Address of the Strategy Account that will be queried/have transactions sent to it.

Send Transaction

Python

borrow_native_transaction = client.writer.withdraw_native_asset(
    strategy_account=STRATEGY_ACCOUNT,
    amount=0,
    send_options=options
)
receipt = client.writer.wait_for_transaction(borrow_native_transaction)
print("Withdraw native, event: ", client.event_handler.handle_withdraw_native_asset_event(STRATEGY_ACCOUNT, receipt))

When sending a transaction, the response will just be the transaction hash. To actually get information about the transaction:

  1. Wait for the transaction to complete with wait_for_transaction.
  2. Get the specific event information for the transaction.

Approve

Python

client.writer.approve(
    address="0x4b927EC02cFAB1237eA9e13d5568850Dc0FDFBF5",
    amount=2000,
    erc20="0x3eBDeaA0DB3FfDe96E7a0DBBAFEC961FC50F725F",
)

Approve address to pull allowed asset funds from wallet.

Parameters

Parameter Type Description
address Address The address being approved.
amount Integer The amount of asset, denominated in asset decimals.
erc20 Address The address of the ERC20 being approved for transfer.
send_options (Optional) SendOptions Specific send options for the transaction.

Transfer

Python

client.writer.transfer(
    to="0x4b927EC02cFAB1237eA9e13d5568850Dc0FDFBF5",
    amount=2000,
    erc20="0x3eBDeaA0DB3FfDe96E7a0DBBAFEC961FC50F725F",
)

Transfer erc20 to another address.

Parameters

Parameter Type Description
to Address The address assets are being sent to.
amount Integer The amount of asset, denominated in asset decimals.
erc20 Address The address of the ERC20 being transferred.
send_options (Optional) SendOptions Specific send options for the transaction.

Deposit

Python

client.writer.deposit(
    amount=10000000,
    on_behalf_of="0xd369853D3E81e7b07f8642fB884634617CB8Be07",
)

Deposit capital into the strategy reserve as a lender. See strategy asset for address of lender asset.

Parameters

Parameter Type Description
amount Integer The amount of asset, denominated in asset decimals.
on_behalf_of Address The address shares are being sent to.
send_options (Optional) SendOptions Specific send options for the transaction.

Mint

Python

client.writer.mint(
    shares=10000000,
    on_behalf_of="0xd369853D3E81e7b07f8642fB884634617CB8Be07",
)

Mint shares in the strategy reserve.

Parameters

Parameter Type Description
shares Integer The number of shares to mint.
on_behalf_of Address The address shares are being sent to.
send_options (Optional) SendOptions Specific send options for the transaction.

Withdraw

Python

client.writer.withdraw(
    amount=10000000,
    on_behalf_of="0xd369853D3E81e7b07f8642fB884634617CB8Be07",
)

Withdraw assets from the strategy reserve and burn tokenized vault shares.

Parameters

Parameter Type Description
amount Integer The amount of asset, denominated in asset decimals, to withdraw.
on_behalf_of Address The address receiving the assets.
send_options (Optional) SendOptions Specific send options for the transaction.

Redeem

Python

client.writer.redeem(
    shares=10000000,
    on_behalf_of="0xd369853D3E81e7b07f8642fB884634617CB8Be07",
)

Redeem shares from the strategy reserve.

Parameters

Parameter Type Description
shares Integer The number of shares to redeem.
on_behalf_of Address The address receiving the value of the redeemed shares.
send_options (Optional) SendOptions Specific send options for the transaction.

Open Account

Python

client.writer.open_account(
    on_behalf_of="0xd369853D3E81e7b07f8642fB884634617CB8Be07",
)

Open a new strategy account.

Parameters

Parameter Type Description
on_behalf_of Address The address that will own the new strategy account.
send_options (Optional) SendOptions Specific send options for the transaction.

Add Collateral

Python

client.writer.add_collateral(
    amount=1000000
)

Add collateral to a strategy account.

Parameters

Parameter Type Description
amount Integer The amount of collateral, being deposited.
send_options (Optional) SendOptions Specific send options for the transaction.

Borrow

Python

client.writer.borrow(
    amount=2000000
)

Borrow funds into a strategy account.

Parameters

Parameter Type Description
amount Integer The amount of assets being borrowed.
send_options (Optional) SendOptions Specific send options for the transaction.

Repay

Python

client.writer.repay(
    amount=2000000,
)

Repay funds from a strategy account.

Parameters

Parameter Type Description
amount Integer The amount of assets being repaid.
send_options (Optional) SendOptions Specific send options for the transaction.

Withdraw Collateral

Python

client.writer.withdrawal_collateral(
    amount=1000000,
    on_behalf_of="0xd369853D3E81e7b07f8642fB884634617CB8Be07",
    use_soft_withdrawal=True,
)

Withdraw collateral that was put up for a strategy account.

Parameters

Parameter Type Description
amount Integer The amount of assets being withdrawn.
on_behalf_of Address The address that will receive the funds.
use_soft_withdrawal Boolean If the request should send less than amount if full amount cannot be withdrawn.
send_options (Optional) SendOptions Specific send options for the transaction.

Withdraw Native Asset

Python

client.writer.withdraw_native_asset(
    amount=1000000,
    on_behalf_of="0xd369853D3E81e7b07f8642fB884634617CB8Be07",
)

Withdraw native asset from a strategy account.

Parameters

Parameter Type Description
amount Integer The amount of native assets being withdrawn.
on_behalf_of Address The address that will receive the funds.
send_options (Optional) SendOptions Specific send options for the transaction.

Withdraw ERC20 Assets

Python

client.writer.withdraw_erc20_assets(
    tokens=["0x1D308089a2D1Ced3f1Ce36B1FcaF815b07217be3"],
    amounts=[1000000],
    on_behalf_of="0xd369853D3E81e7b07f8642fB884634617CB8Be07",
)

Withdraw erc20 assets from a strategy account.

Parameters

Parameter Type Description
tokens []Address The array of token addresses to withdraw.
amounts []Integer The amounts of tokens being withdrawn.
on_behalf_of Address The address that will receive the funds.
send_options (Optional) SendOptions Specific send options for the transaction.

Initiate Liquidation

Python

client.writer.initiate_liquidation(
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
)

Initiate a liquidation for a strategy account.

Parameters

Parameter Type Description
strategy_account Address The address of the strategy the liquidation is being initiated for.
send_options (Optional) SendOptions Specific send options for the transaction.

Process Liquidation

Python

client.writer.process_liquidation(
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
)

Process a liquidation for a strategy account.

Parameters

Parameter Type Description
strategy_account Address The address of the strategy the liquidation is being processed for.
send_options (Optional) SendOptions Specific send options for the transaction.

Get Strategy Asset

Python

strategy_asset = client.reader.get_strategy_asset()

Get the asset being used as collateral.

Return

Value Type Description
strategy_asset_address Address Address of the strategy asset.

Get Strategy Bank for Reserve

Python

strategy_bank = client.reader.get_strategy_bank_for_reserve()

Get address of the Strategy Bank for a reserve.

Return

Value Type Description
strategy_bank Address Address of the Strategy Bank associated with the reserve.

Get Strategy Reserve for Bank

Python

strategy_reserve = client.reader.get_strategy_reserve_for_bank()

Return

Value Type Description
strategy_reserve Address Address of the Strategy Reserve associated with the bank.

Get Strategy Accounts for Bank

Python

strategy_accounts = client.reader.get_strategy_accounts_for_bank()

Get address of strategy accounts for a bank or just owned by owner.

Parameters

Parameter Type Description
owner (Optional) Address Owner address to filter strategy accounts on.
stop (Optional) Integer Number of accounts to fetch, will not filter by owner.

Return

Value Type Description
strategy_accounts []Address Array of all strategy accounts deployed by the strategy_bank.

Get Balance Of

Python

balance = client.reader.get_balance_of(
    erc20="0x3eBDeaA0DB3FfDe96E7a0DBBAFEC961FC50F725F",
    address="0xd369853D3E81e7b07f8642fB884634617CB8Be07",
)

Get address balance of erc20.

Parameters

Parameter Type Description
erc20 Address Address of the ERC20.
address Address Address whose balance is being checked.

Return

Value Type Description
balance Integer The address balance of the erc20.

Get Strategy Account Holdings

Python

holdings = client.reader.get_strategy_account_holdings(
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
)

Get holdings for a Strategy Account.

Parameters

Parameter Type Description
strategy_account Address Address of the Strategy Account, must have been deployed via the strategy_bank.

Return

Value Type Description
holdings BorrowerHoldings The Strategy Account holdings in the bank.

BorrowerHoldings

Value Type Description
collateral Integer Current collateral supporting the Strategy Account.
loan Integer Current outstanding loan held by the Strategy Account.
interestIndexLast Integer The last updated interest index for the Strategy Account.

Get Strategy Account Holdings After Paying Interest

Python

holdings = client.reader.get_strategy_account_holdings_after_paying_interest(
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
)

Get holdings for a strategy account after factoring in interest.

Parameters

Parameter Type Description
strategy_account Address Address of the Strategy Account, must have been deployed via the strategy_bank.

Return

Value Type Description
holdings BorrowerHoldings The Strategy Account holdings in the bank.

Get Withdrawable Collateral

Python

withdrawable_collateral = client.reader.get_withdrawable_collateral(
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
)

Get withdrawable collateral for a strategy account.

Parameters

Parameter Type Description
strategy_account Address Address of the Strategy Account, must have been deployed via the strategy_bank.

Return

Value Type Description
withdrawable_collateral Integer The withdrawable collateral available to the strategy_account.

Get Account Liquidation Status

Python

liquidation_status = client.reader.get_account_liquidation_status(
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
)

Get account liquidation status. Will be 0 if the account is not currently being liquidated and 1 if it is.

Parameters

Parameter Type Description
strategy_account Address Address of the Strategy Account.

Return

Value Type Description
liquidation_status Integer The liquidation status for the strategy_account.

Get Account Value

Python

value = client.reader.get_account_value(
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
)

Get account value.

Parameters

Parameter Type Description
strategy_account Address Address of the Strategy Account, must have been deployed via the strategy_bank.

Return

Value Type Description
value Integer The total value for the strategy_account.

GMX FRF Strategy Client

See client for initializing a client. The GMX FRF client is just a collection of methods for engaging with the GMX FRF strategy. These calls are still made from the "core" client. See examples for walkthroughs of different strategy flows.

Additionally, it is important to understand what the GMX executionFee is as well as how GMX price formatting works.

Create Increase Order

Python

client.gmx_frf_writer.create_increase_order(
    market="0xD996ff47A1F763E1e55415BC4437c59292D1F415",
    amount=60000000,
    execution_fee=2500000000000000000,
)

Create an increase order for a position.

Parameters

Parameter Type Description
market Address The address of the GMX market the order is for.
amount Integer The collateral amount being provided for the order.
execution_fee Integer The allowed execution fee for processing the order.
send_options (Optional) SendOptions Specific send options for the transaction.

Create Decrease Order

Python

client.gmx_frf_writer.create_decrease_order(
    market="0xD996ff47A1F763E1e55415BC4437c59292D1F415",
    size_delta_usd=60000000,
    execution_fee=2500000000000000000,
)

Create a decrease order for a position.

Parameters

Parameter Type Description
market Address The address of the GMX market the order is for.
size_delta_usd Integer The size of the order.
execution_fee Integer The allowed execution fee for processing the order.
send_options (Optional) SendOptions Specific send options for the transaction.

Claim Collateral

Python

client.gmx_frf_writer.claim_collateral(
    market="0xD996ff47A1F763E1e55415BC4437c59292D1F415"
    asset="0x1D308089a2D1Ced3f1Ce36B1FcaF815b07217be3",
    time_key=60000000,
)

Claim collateral for a market.

Parameters

Parameter Type Description
market Address The address of the GMX market the claim is for.
asset Address The address of the asset being claimed.
time_key Integer The time key for the collateral claim.
send_options (Optional) SendOptions Specific send options for the transaction.

Claim Funding Fees

Python

client.gmx_frf_writer.claim_funding_fees(
    markets=["0xD996ff47A1F763E1e55415BC4437c59292D1F415"],
    assets=["0x1D308089a2D1Ced3f1Ce36B1FcaF815b07217be3"],
)

Claim funding fees across markets.

Parameters

Parameter Type Description
markets []Address The address of the GMX markets the claims are for.
assets []Address The address of the assets being claimed.
send_options (Optional) SendOptions Specific send options for the transaction.

Cancel Order

Python

client.gmx_frf_writer.cancel_order(
    order_key="0xa18b0cc36fe8b1f387bcbe1d53b8f122632eec96b85965cf3a33c963d3d67bfc"
)

Cancel an order.

Parameters

Parameter Type Description
order_key Bytes The GMX ID of the order being cancelled.
send_options (Optional) SendOptions Specific send options for the transaction.

Swap Assets

Python

client.gmx_frf_writer.swap_assets(
    market="0xD996ff47A1F763E1e55415BC4437c59292D1F415",
    long_token_amount_out=100000000000,
    callback="0x01F20550e4E60B698bd00B4E22D029FE74181F7a",
    receiver="0x01F20550e4E60B698bd00B4E22D029FE74181F7a",
)

Swap assets for the strategy account.

Parameters

Parameter Type Description
market Address The address of the GMX market being swapped.
long_token_amount_out Integer The amount of asset to swap.
callback Address The address of the callback contract.
receiver Address Address to send asset to before the callback is executed.
send_options (Optional) SendOptions Specific send options for the transaction.

Withdraw Profit

Python


client.gmx_frf_writer.withdraw_profit(
    params={
        'market': "0xD996ff47A1F763E1e55415BC4437c59292D1F415",
        'amount': 1000,
        'recipient': "0xd369853D3E81e7b07f8642fB884634617CB8Be07",
    }
)

Withdraw profit from a strategy account.

Parameters

Parameter Type Description
params WithdrawParams The withdraw parameters.
send_options (Optional) SendOptions Specific send options for the transaction.

WithdrawParams

Parameter Type Description
market Address The address of the GMX market profit is being withdrawn from.
amount Integer The amount of profit being withdrawn.
recipient Address The address receiving the profit.

Liquidate Assets

Python


client.gmx_frf_writer.liquidate_assets(
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
    asset="0x1D308089a2D1Ced3f1Ce36B1FcaF815b07217be3",
    amount=10000,
    callback="0x01F20550e4E60B698bd00B4E22D029FE74181F7a",
    receiver="0x01F20550e4E60B698bd00B4E22D029FE74181F7a",
)

Liquidate an amount of an asset for an underwater strategy account.

Parameters

Parameter Type Description
strategy_account Address The strategy account whose assets are being liquidated.
asset Address The address of the asset being liquidated.
amount Integer The amount of asset to liquidate.
callback Address The address of the callback contract.
receiver Address Address to send asset to before the callback is executed.
send_options (Optional) SendOptions Specific send options for the transaction.

Liquidate Position

Python


client.gmx_frf_writer.liquidate_position(
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
    market="0xD996ff47A1F763E1e55415BC4437c59292D1F415",
    size_delta_usd=10000,
    execution_fee=10000000000,
)

Liquidate an amount of a position for an underwater strategy account.

Parameters

Parameter Type Description
strategy_account Address The strategy account whose position is being liquidated.
market Address The address of the GMX market the position is in.
size_delta_usd Integer The amount of the position to liquidate.
execution_fee Integer The allowed execution fee for processing the order to reduce the position.
send_options (Optional) SendOptions Specific send options for the transaction.

Rebalance Position

Python


client.gmx_frf_writer.rebalance_position(
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
    market="0xD996ff47A1F763E1e55415BC4437c59292D1F415",
    execution_fee=10000000000,
)

Rebalance a position for a strategy account.

Parameters

Parameter Type Description
strategy_account Address The strategy account whose position is being rebalanced.
market Address The address of the GMX market the position is in.
execution_fee Integer The allowed execution fee for processing the order to rebalance the position.
send_options (Optional) SendOptions Specific send options for the transaction.

Releverage Position

Python


client.gmx_frf_writer.releverage_position(
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
    market="0xD996ff47A1F763E1e55415BC4437c59292D1F415",
    size_delta_usd=10000,
    execution_fee=10000000000,
)

Releverage a position for a strategy account.

Parameters

Parameter Type Description
strategy_account Address The strategy account whose position is being releveraged.
market Address The address of the GMX market the position is in.
size_delta_usd Integer The amount of the position to unwind with the releverage.
execution_fee Integer The allowed execution fee for processing the order to releverage the position.
send_options (Optional) SendOptions Specific send options for the transaction.

Swap Rebalance

Python


client.gmx_frf_writer.swap_rebalance(
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
    market="0xD996ff47A1F763E1e55415BC4437c59292D1F415",
    callback_config={
        callback="0x01F20550e4E60B698bd00B4E22D029FE74181F7a",
        receiver="0x01F20550e4E60B698bd00B4E22D029FE74181F7a",
        tokenAmountMax=10000,
    },
)

Swap rebalance, allowing a liquidator to sell long tokens for USDC.

Parameters

Parameter Type Description
strategy_account Address The strategy account whose assets are being swapped.
market Address The address of the long token being swapped.
callback_config CallbackConfig The callback configuration for the swap.
send_options (Optional) SendOptions Specific send options for the transaction.

CallbackConfig

Parameter Type Description
callback Address The address of the callback contract.
receiver Address Address to send asset to before the callback is executed.
tokenAmountMax Integer Maximum amount of token to swap.

Multicall

Python


client.gmx_frf_writer.multi_call(
    data=[0x60fe47b10000000000000000000000000000000000000000000000000000000000000c8]
)

Make a multi-call for the strategy account.

Parameters

Parameter Type Description
data []Bytes The encoded bytes array of all calls to make.
send_options (Optional) SendOptions Specific send options for the transaction.

Get Asset Liquidation Fee Percent

Python


fee_percent = client.gmx_frf_reader.get_asset_liquidation_fee_percent(
    asset="0x1D308089a2D1Ced3f1Ce36B1FcaF815b07217be3"
)

Get the asset liquidation fee percent for the strategy.

Parameters

Parameter Type Description
asset Address The address of the asset whose liquidation fee percent is being queried.

Response

Parameter Type Description
fee_percent Integer The liquidation fee percent for the asset.

Get Callback Gas Limit

Python


callback_gas_limit = client.gmx_frf_reader.get_callback_gas_limit()

Get the callback gas limit for the strategy.

Response

Parameter Type Description
callback_gas_limit Integer The limit on gas that can be spent in a GMX callback.

Get Execution Fee Buffer Percent

Python


execution_fee_buffer_percent = client.gmx_frf_reader.get_execution_fee_buffer_percent()

Get the execution fee buffer percent for the strategy.

Response

Parameter Type Description
execution_fee_buffer_percent Integer The buffer that will be padded onto the execution fee.

Get Liquidation Order Timeout Deadline

Python


liquidation_order_timeout_deadline = client.gmx_frf_reader.get_liquidation_order_timeout_deadline()

Get the liquidation order timeout deadline for the strategy.

Response

Parameter Type Description
liquidation_order_timeout_deadline Integer The timeout after which point liquidation orders can be cancelled.

Get Profit Withdrawal Buffer Percent

Python


profit_withdrawal_buffer_percent = client.gmx_frf_reader.get_profit_withdrawal_buffer_percent()

Get the profit withdrawal buffer percent for the strategy.

Response

Parameter Type Description
profit_withdrawal_buffer_percent Integer The buffer on the loan that must exist after profit is withdrawn.

Get Referral Code

Python


referral_code = client.gmx_frf_reader.get_referral_code()

Get the referral code for the strategy.

Response

Parameter Type Description
get_referral_code Bytes The referral code used by Strategy Accounts to trade on GMX at a discount.

Get Token Addresses For Markets

Python

token_addresses = client.gmx_frf_reader.get_token_addresses_for_market(
    market="0xD996ff47A1F763E1e55415BC4437c59292D1F415",
)

Get addresses for market.

Parameters

Parameter Type Description
market Address The address of the market being checked.

Response

Parameter Type Description
token_addresses MarketAddresses The relevant addresses for a GMX V2 market.

MarketAddresses

Parameter Type Description
market_token Address Address of the market token.
index_token Address Address of the index token.
long_token Address Address of the long token.
short_token Address Address of the short token.

Get Market Info

Python


market_info = client.gmx_frf_reader.get_market_info(
    market="0xD996ff47A1F763E1e55415BC4437c59292D1F415",
)

Get market information.

Parameters

Parameter Type Description
market Address The address of the market being checked.

Response

Parameter Type Description
market_info MarketInfo Information for the market.

MarketInfo

Parameter Type Description
market MarketAddresses Addresses for the market.
borrowing_factor_per_second_for_longs Integer The borrowing factor per second for longs.
borrowing_factor_per_second_for_shorts Integer The borrowing factor per second for shorts.
base_funding BaseFunding The base funding information for the market.
next_funding NextFunding The next funding information for the market.
virtual_inventory VirtualInventory The virtual inventory information for the market.
is_disabled Boolean If the market is currently disabled on GMX.

BaseFunding

Parameter Type Description
funding_fee_amount_per_size LongShortInformation Funding fee amount per size information
claimable_funding_amount_per_size LongShortInformation Claimable funding amount per size information

NextFunding

Parameter Type Description
longs_pay_shorts Boolean If longs pay funding fee to shorts.
funding_factor_per_second Integer The funding factor per second being paid.
next_saved_funding_factor_per_second Integer The saved next funding factor per second.
funding_fee_amount_per_size_delta LongShortInformation The funding fee amount per size information.
claimable_funding_amount_per_size_delta LongShortInformation The claimable funding fee amount per size information.

VirtualInventory

Parameter Type Description
virtual_pool_amount_for_long_token Integer The virtual pool amount for long tokens.
virtual_pool_amount_for_short_token Integer The virtual pool amount for short tokens.
virtual_inventory_for_positions Integer The virtual inventory for positions.

LongShortInformation

Parameter Type Description
long PairInformation Information if the position is long.
short PairInformation Information if the position is short.

Pair Information

Parameter Type Description
long_token Integer The funding rate for the long token.
short_token Integer The funding rate for the short token.

Get Available Markets

Python


available_markets = client.gmx_frf_reader.get_available_markets()

Get the available markets for the strategy.

Response

Parameter Type Description
available_markets []Address The markets available in the strategy to establish positions on GMX.

Get Market Configuration

Python


market_config = client.gmx_frf_reader.get_market_configuration
    market="0xD996ff47A1F763E1e55415BC4437c59292D1F415",
)

Get market configuration for the strategy.

Parameters

Parameter Type Description
market Address The address of the market being checked.

Response

Parameter Type Description
market_config MarketConfig The configuration for the market.

MarketConfig

Parameter Type Description
orderPricingParameters OrderPricingParameters The order pricing parameters for the market.
sharedOrderParameters SharedOrderParameters The shared order parameters for the market.
positionParameters PositionParameters The position parameters for the market.
unwindParameters UnwindParameters The unwind parameters for the market.

OrderPricingParameters

Parameter Type Description
maxSwapSlippagePercent Integer The maximum swap slippage percentage for this market. The value is computed using the oracle price as a reference.
maxPositionSlippagePercent Integer The maximum slippage percentage for this market. The value is computed using the oracle price as a reference.
minOrderSizeUsd Integer The minimum order size in USD for this market.
maxOrderSizeUsd Integer The maximum order size in USD for this market.
increaseEnabled Boolean Whether or not increase orders are enabled.

SharedOrderParameters

Parameter Type Description
callbackGasLimit Integer The callback gas limit for all orders.
executionFeeBufferPercent Integer The execution fee buffer percentage required for placing an order.
referralCode Bytes The referral code to use for all orders.
uiFeeReceiver Address The ui fee receiver used for all orders.
withdrawalBufferPercentage Integer The withdrawalBufferPercentage for all accounts

PositionParameters

Parameter Type Description
minPositionSizeUsd Integer The minimum position size in USD for this market, in order to prevent dust orders from needing to be liquidated.
maxPositionSizeUsd Integer The maximum position size in USD for this market.

UnwindParameters

Parameter Type Description
maxDeltaProportion Integer The minimum amount of delta the position is allowed to have before it can be rebalanced.
minSwapRebalanceSize Integer The minimum size of a token sale rebalance required. This is used to prevent dust orders from preventing rebalancing of a position via unwinding a position from occuring.
maxPositionLeverage Integer The maximum amount of leverage a position is allowed to have.
unwindFee Integer The fee rate that pays rebalancers for purchasing additional assets to match the short position.

Get Market Unwind Configuration

Python


market_unwind_config = client.gmx_frf_reader.get_market_unwind_configuration
    market="0xD996ff47A1F763E1e55415BC4437c59292D1F415",
)

Get market unwind configuration for the strategy.

Parameters

Parameter Type Description
market Address The address of the market being checked.

Response

Parameter Type Description
market_unwind_config MarketUnwindConfig The unwind configuration for the market, see unwind parameters.

Get Is Approved Market

Python


is_approved = client.gmx_frf_reader.get_is_approved_market(
    market="0xD996ff47A1F763E1e55415BC4437c59292D1F415",
)

Get if a market is approved for the strategy.

Parameters

Parameter Type Description
market Address The address of the market being checked.

Response

Parameter Type Description
is_approved Boolean Get if a market is approved for the strategy.

Get Market Net Funding Rate

Python

net_funding_rate = client.gmx_frf_reader.get_market_net_funding_rate(
    market="0xD996ff47A1F763E1e55415BC4437c59292D1F415",
)

Get the net funding rate for a market.

Parameters

Parameter Type Description
market Address The address of the market being checked.

Response

Parameter Type Description
net_funding_rate Integer The net funding rate for short positions for a market with 1e30 being 100%.

Get Asset Oracle

Python


asset_oracle = client.gmx_frf_reader.get_is_approved_market
    asset="0x1D308089a2D1Ced3f1Ce36B1FcaF815b07217be3",
)

Get the asset oracle for the strategy.

Parameters

Parameter Type Description
asset Address The address of the asset whose oracle is being checked.

Response

Parameter Type Description
asset_oracle Address The address of the oracle for the asset.

Get Asset Oracle Configuration

Python


asset_oracle_configuration = client.gmx_frf_reader.get_asset_oracle_configuration
    asset="0x1D308089a2D1Ced3f1Ce36B1FcaF815b07217be3",
)

Get the asset oracle configuration for the strategy.

Parameters

Parameter Type Description
asset Address The address of the asset whose oracle configuration is being checked.

Response

Parameter Type Description
asset_oracle_configuration AssetOracleConfiguration The oracle configuration for the asset.

AssetOracleConfiguration

Parameter Type Description
oracle Address The address of the oracle for the asset.
validPriceDuration Integer Duration of time that a price is valid before it becomes stale.

Get Asset Price

Python


asset_price = client.gmx_frf_reader.get_is_approved_market
    asset="0x1D308089a2D1Ced3f1Ce36B1FcaF815b07217be3",
)

Parameters

Parameter Type Description
asset Address The address of the asset whose price is being fetched.

Response

Parameter Type Description
asset_price AssetPrice The price of the asset.

AssetPrice

Parameter Type Description
price Integer The price of the asset.
decimals Integer The number of decimals the asset has.

Get Registered Assets

Python


registered_assets = client.gmx_frf_reader.get_registered_assets()

Get the registered assets for the strategy.

Response

Parameter Type Description
registered_assets []Address The registered assets for the strategy.

Get GMX V2 Exchange Router

Python


gmx_v2_exchange_router = client.gmx_frf_reader.get_gmx_v2_exchange_router()

Get the GMX V2 exchange router for the strategy.

Response

Parameter Type Description
gmx_v2_exchange_router Address The address of the GMX V2 exchange router for the strategy.

Get GMX V2 Order Vault

Python


gmx_v2_order_vault = client.gmx_frf_reader.get_gmx_v2_order_vault()

Get the GMX V2 order vault for the strategy.

Response

Parameter Type Description
gmx_v2_order_vault Address The address of the GMX V2 order vault for the strategy.

Get Referral Storage

Python


referral_storage = client.gmx_frf_reader.get_referral_storage()

Get the referral storage address.

Response

Parameter Type Description
referral_storage Address The address of the GMX V2 referral storage for the strategy.

Get UI Fee Receiver

Python


ui_fee_receiver = client.gmx_frf_reader.get_ui_fee_receiver()

Get UI fee receiver address.

Response

Parameter Type Description
ui_fee_receiver Address The address of the UI fee receiver for the strategy.

Get Account Orders Value USD

Python


orders_value_usd = client.gmx_frf_reader.get_account_orders_value_usd
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
)

Get an account's order value in USD.

Parameters

Parameter Type Description
strategy_account Address The address of the strategy account being checked.

Response

Parameter Type Description
orders_value_usd Integer The total value of all orders for the strategy_account in USD.

Get Account Positions Value USD

Python


positions_value_usd = client.gmx_frf_reader.get_account_positions_value_usd
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
)

Get an account's positions' value in USD.

Parameters

Parameter Type Description
strategy_account Address The address of the strategy account being checked.

Response

Parameter Type Description
positions_value_usd Integer The total value of all positions for the strategy_account in USD.

Get Account Value USDC

Python


account_value_usdc = client.gmx_frf_reader.get_account_value_usdc
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
)

Get an account's value in USDC.

Parameters

Parameter Type Description
strategy_account Address The address of the strategy account being checked.

Response

Parameter Type Description
account_value_usdc Integer The total value of the strategy_account in USDC.

Get Settled Funding Fees

Python


settled_funding_fees = client.gmx_frf_reader.get_settled_funding_fees
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
    market="0xD996ff47A1F763E1e55415BC4437c59292D1F415",
    short_token="0x3eBDeaA0DB3FfDe96E7a0DBBAFEC961FC50F725F",
    long_token="0x1D308089a2D1Ced3f1Ce36B1FcaF815b07217be3",
)

Get an account's settled funding fees for a market.

Parameters

Parameter Type Description
strategy_account Address The address of the strategy account being checked.
market Address The GMX market the funding fees have accrued in.
short_token Address The address of the short token in the position.
long_token Address The address of the long token in the position.

Response

Parameter Type Description
settled_funding_fees Integer The settled funding fees for the account in the specific market.

Get Settled Funding Fees for Token

Python


settled_funding_fees = client.gmx_frf_reader.get_settled_funding_fees_for_token
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
    market="0xD996ff47A1F763E1e55415BC4437c59292D1F415",
    token="0x3eBDeaA0DB3FfDe96E7a0DBBAFEC961FC50F725F",
)

Get an account's settled funding fees for a token.

Parameters

Parameter Type Description
strategy_account Address The address of the strategy account being checked.
market Address The GMX market the funding fees have accrued in.
token Address The address of the token in the position being checked.

Response

Parameter Type Description
settled_funding_fees Integer The settled funding fees for the token for the account in the specific market.

Get Settled Funding Fees Value USD

Python


settled_funding_fees_value_usd = client.gmx_frf_reader.get_settled_funding_fees_value_usd
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
)

Get an account's settled funding fees total USD value.

Parameters

Parameter Type Description
strategy_account Address The address of the strategy account being checked.

Response

Parameter Type Description
settled_funding_fees_value_usd Integer The USD value of settled funding fees for the strategy_account.

Get Is Liquidation Finished

Python


is_finished = client.gmx_frf_reader.get_is_liquidation_finished
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
)

Get if an account is not in a liquidation state.

Parameters

Parameter Type Description
strategy_account Address The address of the strategy account being checked.

Response

Parameter Type Description
is_finished Boolean If the liquidation for the account is finished/there is no ongoing liquidation.

Get Order Value USD

Python


order_value_usd = client.gmx_frf_reader.get_order_value_usd
    order_id="0xa18b0cc36fe8b1f387bcbe1d53b8f122632eec96b85965cf3a33c963d3d67bfc",
)

Get an order's value in USD.

Parameters

Parameter Type Description
order_id Bytes The GMX ID of the order being queried.

Response

Parameter Type Description
order_value_usd Integer The USD value of the order.

Get Position Value USD

Python


position_value_usd = client.gmx_frf_reader.get_position_value_usd
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
    market="0xD996ff47A1F763E1e55415BC4437c59292D1F415",
)

Get a position's value in USD.

Parameters

Parameter Type Description
strategy_account Address The address of the strategy account being checked.
market Address The GMX market the position is in.

Response

Parameter Type Description
position_value_usd Integer The USD value of the position.

Get Position


position = client.gmx_frf_reader.get_position_info
    market="0xD996ff47A1F763E1e55415BC4437c59292D1F415",
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
)

Get a position.

Parameters

Parameter Type Description
market Address The GMX market the position is in.
strategy_account Address The address of the strategy account being checked.

Response

Parameter Type Description
position Position Gmx position information.

Position

Parameter Type Description
addresses PositionAddresses Relevant addresses for the position.
number PositionNumbers Important numbers for the position.
flags PositionFlags Flags for the position.

PositionAddresses

Parameter Type Description
account Address Address of the strategy account that deployed the position.
market Address The market the position is in.
collateral_token Address The address of the collateral token for the position.

PositionNumbers

Parameter Type Description
size_in_usd Integer The size of the position is USD.
size_in_tokens Integer The size of the position denominated in position tokens.
collateral_amount Integer The amount of collateral that is backing the position.
borrowing_factor Integer The borrowing factor for the position.
funding_fee_amount_per_size Integer The funding fee per size of the position.
long_token_claimable_funding_amount_per_size Integer The claimable funding amount for long asset per size.
short_token_claimable_funding_amount_per_size Integer The claimable funding amount for short asset per size.
increased_at_block Integer The block the position was last increased at.
decreased_at_block Integer The block the position was last decreased at.

PositionFlags

Parameter Type Description
isLong Boolean If the position is long.

Get Position Info


position_info = client.gmx_frf_reader.get_position_info
    market="0xD996ff47A1F763E1e55415BC4437c59292D1F415",
    strategy_account="0x34effbade0f3a31c349ba4fd1be4869fa1392c8c",
)

Get a position's info.

Parameters

Parameter Type Description
market Address The GMX market the position is in.
strategy_account Address The address of the strategy account being checked.

Response

Parameter Type Description
position_info PositionInfo Gmx position information as well as metadata information.

PositionInfo

Parameter Type Description
position Position The position placed on GMX.
fees Fees The fees associated with the position.

Fees

Parameter Type Description
referral Referral Referral information for the position.

Referral

Parameter Type Description
refferal_code bytes The unique referral code tying all orders to the GoldLink referral.
afffiliate Address The address of referral affiliates.
trader Address The account of the position trader, the strategy account.