From bfffef365b45d4bc0eecb7f682c73ff85a014eff Mon Sep 17 00:00:00 2001 From: mncdg Date: Wed, 13 Dec 2023 13:03:20 +0100 Subject: [PATCH] feature: order subsidization --- package-lock.json | 12 ++++++------ package.json | 4 ++-- sample.config.ts | 3 +++ src/chain-common/order-estimator.ts | 2 ++ src/config.ts | 12 ++++++++++++ src/executor.ts | 18 ++++++++++++++++-- src/index.ts | 2 ++ 7 files changed, 43 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index c4b18ddc..113f6f08 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,16 @@ { "name": "@debridge-finance/dln-taker", - "version": "3.0.3", + "version": "3.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@debridge-finance/dln-taker", - "version": "3.0.3", + "version": "3.1.0", "license": "GPL-3.0-only", "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", @@ -595,9 +595,9 @@ } }, "node_modules/@debridge-finance/legacy-dln-profitability": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/@debridge-finance/legacy-dln-profitability/-/legacy-dln-profitability-2.2.2.tgz", - "integrity": "sha512-+tYDvg4QyIaX4aLDCDyVdjL/xtMvcI9x1Gs37KV+TkM/y2WCSIkJugJsvO7qCMjXR5lBguERUXDWQWf9fgJRIQ==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@debridge-finance/legacy-dln-profitability/-/legacy-dln-profitability-3.2.0.tgz", + "integrity": "sha512-yVyx5eQxBoNWj92p0uDurG2eFS/jdyOX5xjkhWPdUruP7XxV1XLewU8MLEEOgR7RRIpBUHx0F9ZVbFYBFMZyrw==", "dependencies": { "@debridge-finance/dln-client": "^8.1.0", "node-cache": "5.1.2", diff --git a/package.json b/package.json index 0eccbcc5..2bc6101c 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/sample.config.ts b/sample.config.ts index 1aad77f3..9bce25c8 100644 --- a/sample.config.ts +++ b/sample.config.ts @@ -50,6 +50,9 @@ const config: ExecutorLaunchConfig = { }, ], + subsidizationRules: [], + allowSubsidy: false, + tokenPriceService: configurator.tokenPriceService({ coingeckoApiKey: process?.env?.COINGECKO_API_KEY, }), diff --git a/src/chain-common/order-estimator.ts b/src/chain-common/order-estimator.ts index 585898b4..8a384572 100644 --- a/src/chain-common/order-estimator.ts +++ b/src/chain-common/order-estimator.ts @@ -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, }; } diff --git a/src/config.ts b/src/config.ts index 1261299f..2e19fea7 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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'; @@ -322,6 +323,17 @@ export interface ExecutorLaunchConfig { */ tokenPriceService?: PriceTokenService; + /** + * Rule to subsidize orders + * Default: [] + */ + subsidizationRules?: SubsidizationRule[]; + + /** + * Default: false + */ + allowSubsidy?: boolean; + /** * Source of orders */ diff --git a/src/executor.ts b/src/executor.ts index 3c3a1592..b4063645 100644 --- a/src/executor.ts +++ b/src/executor.ts @@ -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 { @@ -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'; @@ -119,6 +123,8 @@ export interface IExecutor { readonly client: DlnClient; readonly dlnApi: DataStore; readonly hookEngine: HooksEngine; + readonly subsidizationRules: SubsidizationRule[]; + readonly allowSubsidy: boolean; getSupportedChainIds(): Array; getSupportedChain(chain: ChainId): ExecutorSupportedChain; @@ -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 } = {}; @@ -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, diff --git a/src/index.ts b/src/index.ts index 62b867f9..80124e13 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; @@ -22,6 +23,7 @@ export { configurator, filters, ExecutorLaunchConfig, + SubsidizationRule, // environment environments,