Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
feature: order subsidization
Browse files Browse the repository at this point in the history
  • Loading branch information
mncdg committed Dec 13, 2023
1 parent 578b25a commit bfffef3
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 10 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@debridge-finance/dln-taker",
"version": "3.0.3",
"version": "3.1.0",
"description": "DLN executor is the rule-based daemon service developed to automatically execute orders placed on the deSwap Liquidity Network (DLN) across supported blockchains",
"license": "GPL-3.0-only",
"author": "deBridge",
Expand Down Expand Up @@ -33,7 +33,7 @@
"types": "./dist/index.d.ts",
"dependencies": {
"@debridge-finance/dln-client": "8.3.3",
"@debridge-finance/legacy-dln-profitability": "2.2.2",
"@debridge-finance/legacy-dln-profitability": "3.2.0",
"@debridge-finance/solana-utils": "4.2.1",
"@protobuf-ts/plugin": "2.8.1",
"@solana/web3.js": "1.66.2",
Expand Down
3 changes: 3 additions & 0 deletions sample.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const config: ExecutorLaunchConfig = {
},
],

subsidizationRules: [],
allowSubsidy: false,

tokenPriceService: configurator.tokenPriceService({
coingeckoApiKey: process?.env?.COINGECKO_API_KEY,
}),
Expand Down
2 changes: 2 additions & 0 deletions src/chain-common/order-estimator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export class OrderEstimator extends OrderEvaluationContextual {
batchSize: this.order.giveChain.srcConstraints.batchUnlockSize,
swapEstimationPreference: this.getRouteHint(),
isFeatureEnableOpHorizon: process.env.DISABLE_OP_HORIZON_CAMPAIGN !== 'true',
allowSubsidy: this.order.executor.allowSubsidy,
subsidizationRules: this.order.executor.subsidizationRules,
};
}

Expand Down
12 changes: 12 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ChainId, PriceTokenService } from '@debridge-finance/dln-client';

import { SubsidizationRule } from '@debridge-finance/legacy-dln-profitability';
import { OrderFilterInitializer } from './filters/order.filter';
import { GetNextOrder } from './interfaces';
import { Hooks } from './hooks/HookEnums';
Expand Down Expand Up @@ -322,6 +323,17 @@ export interface ExecutorLaunchConfig {
*/
tokenPriceService?: PriceTokenService;

/**
* Rule to subsidize orders
* Default: []
*/
subsidizationRules?: SubsidizationRule[];

/**
* Default: false
*/
allowSubsidy?: boolean;

/**
* Source of orders
*/
Expand Down
18 changes: 16 additions & 2 deletions src/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import { Connection, Keypair, PublicKey } from '@solana/web3.js';
import bs58 from 'bs58';
import { Logger } from 'pino';

import { TokensBucket, setSlippageOverloader } from '@debridge-finance/legacy-dln-profitability';
import {
TokensBucket,
setSlippageOverloader,
SubsidizationRule,
} from '@debridge-finance/legacy-dln-profitability';
import BigNumber from 'bignumber.js';
import Web3 from 'web3';
import {
Expand All @@ -34,7 +38,7 @@ import {
avgBlockSpeed,
} from './config';
import * as filters from './filters/index';
import { OrderFilter } from './filters/index';
import { OrderFilter } from './filters';
import { Authority, GetNextOrder, IncomingOrder, OrderInfoStatus } from './interfaces';
import { WsNextOrder } from './orderFeeds/ws.order.feed';
import { EvmTxSigner } from './chain-evm/signer';
Expand Down Expand Up @@ -119,6 +123,8 @@ export interface IExecutor {
readonly client: DlnClient;
readonly dlnApi: DataStore;
readonly hookEngine: HooksEngine;
readonly subsidizationRules: SubsidizationRule[];
readonly allowSubsidy: boolean;

getSupportedChainIds(): Array<ChainId>;
getSupportedChain(chain: ChainId): ExecutorSupportedChain;
Expand Down Expand Up @@ -151,6 +157,12 @@ export class Executor implements IExecutor {
// @ts-ignore Initialized deferredly within the init() method. Should be rewritten during the next major refactoring
hookEngine: HooksEngine;

// @ts-ignore Initialized deferredly within the init() method. Should be rewritten during the next major refactoring
allowSubsidy: boolean;

// @ts-ignore Initialized deferredly within the init() method. Should be rewritten during the next major refactoring
subsidizationRules: SubsidizationRule[];

chains: { [key in ChainId]?: ExecutorSupportedChain } = {};

processors: { [key in ChainId]?: OrderProcessor } = {};
Expand Down Expand Up @@ -239,6 +251,8 @@ export class Executor implements IExecutor {
if (this.#isInitialized) return;

this.tokenPriceService = config.tokenPriceService || new CoingeckoPriceFeed();
this.allowSubsidy = config.allowSubsidy || false;
this.subsidizationRules = config.subsidizationRules || [];

this.swapConnector = new SwapConnectorImplementationService({
oneInchApi: this.#url1Inch,
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ChainId } from '@debridge-finance/dln-client';
import { SubsidizationRule } from '@debridge-finance/legacy-dln-profitability';
import configurator from './configurator/index';
import * as filters from './filters';
import { ExecutorLaunchConfig } from './config';
Expand All @@ -22,6 +23,7 @@ export {
configurator,
filters,
ExecutorLaunchConfig,
SubsidizationRule,

// environment
environments,
Expand Down

0 comments on commit bfffef3

Please sign in to comment.