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

Commit

Permalink
Fix: respect subsidization on rough profitability pre-estimation (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeychr authored Dec 22, 2023
1 parent 96535e6 commit 6256581
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@debridge-finance/dln-taker",
"version": "3.2.1",
"version": "3.2.2",
"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
33 changes: 29 additions & 4 deletions src/chain-common/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ import {
ChainEngine,
ChainId,
} from '@debridge-finance/dln-client';
import { findExpectedBucket } from '@debridge-finance/legacy-dln-profitability';
import {
calculateSubsidization,
findExpectedBucket,
} from '@debridge-finance/legacy-dln-profitability';
import { helpers } from '@debridge-finance/solana-utils';
import { Logger } from 'pino';
import { EVMOrderValidator } from '../chain-evm/order-validator';
import { createClientLogger } from '../dln-ts-client.utils';
import {
IExecutor,
ExecutorSupportedChain,
Expand Down Expand Up @@ -88,9 +92,30 @@ export class CreatedOrder {

async getMaxProfitableReserveAmountWithoutOperatingExpenses(): Promise<bigint> {
// getting the rough amount we are willing to spend after reserving our intended margin
const reserveDstAmount = await this.getGiveAmountInReserveToken();
const amount = (reserveDstAmount * (10_000n - BigInt(this.requiredMargin))) / 10_000n;
return amount;
let reserveDstAmount = await this.getGiveAmountInReserveToken();

// subtracting margin
reserveDstAmount = (reserveDstAmount * (10_000n - BigInt(this.requiredMargin))) / 10_000n;

// adding subsidy
if (this.executor.allowSubsidy && this.executor.subsidizationRules) {
const subsidyAmount = await calculateSubsidization(
{
order: this.orderData,
reserveDstTokenAddress: this.route.reserveDstToken,
},
{
client: this.executor.client,
priceTokenService: this.executor.tokenPriceService,
subsidizationRules: this.executor.subsidizationRules,
logger: createClientLogger(this.#logger),
},
);

reserveDstAmount += subsidyAmount;
}

return reserveDstAmount;
}

get blockConfirmations(): number {
Expand Down

0 comments on commit 6256581

Please sign in to comment.