Custom Algos
PriceRange Market Order
import {
Price,
Dexible,
GasCostPolicy,
SlippagePolicy,
PriceBoundsPolicy,
BaseSwap,
Market,
units
} from 'dexible-sdk';
class MySwapType extends BaseSwap {
constructor(props: BaseSwapConfig) {
super(props, "MySwapType");
}
toAlgo() {
let policies = [
new GasCostPolicy({
gasType: 'relative',
deviation: 0
}),
new SlippagePolicy({
amount: .5
}),
new PriceBoundsPolicy({
basePrice: new Price({
inToken: tokenIn,
outToken: tokenOut,
inUnits: 1,
outUnits: 2500
}),
lowerBoundPercent: 2,
upperBoundPercent: 2
})
];
return new Market({
policies
});
}
}
const main = async () => {
//create Dexible instance since we'll need it later
let sdk = new Dexible(...);
let tokenIn = weth; //assumed full IERC20Token instance
let tokenOut = matic; //same
let swap = new MySwapType({
tokenIn,
tokenOut,
amountIn: units.inBNUnits("18000", 18)
});
...
}
main();Order Matters
Extending Policies
Last updated
Was this helpful?