Contracts

BSC Mainnet Contracts

Source code

Token List

For a list of supported tokens: https://gambit.gitbook.io/gambit/api.

Swapping

To execute a swap:

  • Approve the Router contract for the token and amount you would like to swap

  • Call Router.swap with parameters:

    • _path: [tokenIn, tokenOut]

    • _amountIn: amount of tokenIn to swap

    • _minOut: minimum expected output amount

    • _receiver: address of the receiver of tokenOut

  • The function will revert if the amount of tokenOut sent to the receiver is less than _minOut

To get swap amounts before execution:

  • Call Reader.getMaxAmountIn with parameters:

    • _vault: address of the vault

    • _tokenIn: address of token that will be given

    • _tokenOut: address of token to be received

    • The max amount of tokenIn that can be swapped will be returned

  • Call Reader.getAmountOut with parameters:

    • _vault: address of the vault

    • _tokenIn: address of token that will be given

    • _tokenOut: address of token to be received

    • _amountIn: amount of tokenIn to swap

    • Two values will be returned, the first is the amount out after fees, and the second is the fee amount

    • The fee amount will be in terms of tokenOut

Opening / Increasing a position

To open or increase the size of an existing position:

  • Approve the Router contract for the token and amount you would deposit as collateral for the position

  • Call Router.increasePosition with parameters:

    • _path: [tokenIn, collateralToken] or [tokenIn]

    • _indexToken: the address of the token you want to long or short

    • _amountIn: the amount of tokenIn you want to deposit as collateral

    • _minOut: the min amount of collateralToken to swap for

    • _sizeDelta: the USD value of the change in position size

    • _isLong: whether to long or short

    • _price: the USD value of the min (for longs) or max (for shorts) index price accepted when opening the position

  • _path allows swapping to the collateralToken if needed

  • For longs, the collateralToken must be the same as the indexToken

  • For shorts, the collateralToken can be any stablecoin token

  • _minOut can be zero if no swap is required

  • USD values for _sizeDelta and _price are multiplied by (10 ** 30), so for example to open a long position of size 1000 USD, the value 1000 * (10 ** 30) should be used

Closing / Decreasing a position

To close or decrease an existing position:

  • Call Router.decreasePosition with parameters:

    • _collateralToken: the collateral token used

    • _indexToken: the index token of the position

    • _collateralDelta: the amount of collateral in USD value to withdraw

    • _sizeDelta: the USD value of the change in position size

    • _isLong: whether the position is a long or short

    • _receiver: the address to receive the withdrawn tokens

    • _price: the USD value of the min (for shorts) or max (for longs) index price accepted when decreasing the position

    • If _sizeDelta is the same size as the position, the collateral after adding profits or deducting losses will be sent to the receiver address

Last updated