Algos

With an SDK instance and in/out tokens, and a quote, the next thing to address is how you want Dexible to carry out the trade. You do that through "algos" or trade algorithm types. Dexible supports specific named algos; but in reality algos are made up of execution policies. The SDK offers two paths to construct algos: using a simple factory or customizing an algo with policy configurations. We'll start with the algo factory and then cover policies and customizations in a follow-on section.

Algo Factory

The simplest way to get started is to use the Algo factory that is embedded in the SDK instance we created earlier. Each algo type for the factory determines the parameters the factory expects, and we'll cover those here.

Common Parameters

Every algo created through the factory expects three basic parameters: type, gasPolicy, and slippagePercent. Let's start with the simplest algo type as an example: the Market algo.

let algo = sdk.algo.create({
    type: sdk.algo.types.Market,
    gasPolicy: {
        type: sdk.gasPolicyTypes.RELATIVE,
        deviation: 0
    },
    slippagePercent: .5
});

This code snippet needs some explanation. Every algo starts with a type, and there are currently 4 types supported: Limit, Market, StopLoss, and TWAP. Here, we are specifying Market as the algo type.

Every order must have a gas policy, which tells Dexible how you want the system to evaluate gas costs for each round. RELATIVE means use the current fast gas price (i.e. make the cost relative to the current gas market) plus some amount of deviation (expressed as a percentage).

Another option for the gas policy type is FIXED, which means Dexible will wait until the fast gas price is less than or equal to a specific amount. A FIXED gas policy would look like this:

let algo = sdk.algo.create({
    type: sdk.algo.types.Market,
    gasPolicy: {
        type: sdk.gasPolicyTypes.FIXED,
        //do not execute unless gas is 25gwei or better
        amount: ethers.utils.parseUnits("25", 9).toString()
    },
    slippagePercent: .5
});

The slippagePercent tells Dexible how much slippage tolerance you want to allow when submitting orders on-chain. Note that this number cannot be less than .5%. This is because Dexible is covering the cost of failed transactions and .5% is the minimum risk the platform can tolerate w/out incurring excessive failures.

Last updated