From 8c7e13b3746874c997f47c1efe52512020abcfb0 Mon Sep 17 00:00:00 2001 From: Timofey Trepalin Date: Thu, 9 Mar 2023 15:10:14 +0500 Subject: [PATCH 1/2] Route Assets - changed maxInputAmount param - set approxAmount*slippageTolerance instead balance --- src/modules/ADAR/consts/index.ts | 2 ++ src/store/routeAssets/actions.ts | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/modules/ADAR/consts/index.ts b/src/modules/ADAR/consts/index.ts index 8240edf5e..9dcd8445f 100644 --- a/src/modules/ADAR/consts/index.ts +++ b/src/modules/ADAR/consts/index.ts @@ -39,3 +39,5 @@ function createStage(title: string, componentName: string): Stage { component: componentName, }; } + +export const slippageMultiplier = 1.15; diff --git a/src/store/routeAssets/actions.ts b/src/store/routeAssets/actions.ts index 24c2d9e8b..a4d7014c1 100644 --- a/src/store/routeAssets/actions.ts +++ b/src/store/routeAssets/actions.ts @@ -17,6 +17,7 @@ import { findLast, groupBy, sumBy } from 'lodash'; import { NumberLike } from '@sora-substrate/math'; import { Messages } from '@sora-substrate/util/build/logger'; import { assert } from '@polkadot/util'; +import { slippageMultiplier } from '@/modules/ADAR/consts'; const actions = defineActions({ processingNextStage(context) { @@ -392,10 +393,12 @@ async function executeBatchSwapAndSend(context, data: Array): Promise const findAsset = (assetName: string) => { return assetsTable.find((item: Asset) => item.address === assetName); }; + let inputTokenAmount: FPNumber = FPNumber.ZERO; const swapTransferData = groupedData.map((entry) => { const [outcomeAssetId, receivers] = entry; const approxSum = sumBy(receivers, (receiver) => receiver.usd); const dexIdData = getAmountAndDexId(context, inputAsset, findAsset(outcomeAssetId) as Asset, approxSum); + inputTokenAmount = inputTokenAmount.add(FPNumber.fromCodecValue(dexIdData?.amountFrom as string)); const dexId = dexIdData?.bestDexId; return { outcomeAssetId, @@ -404,8 +407,7 @@ async function executeBatchSwapAndSend(context, data: Array): Promise }; }); - // const formattedToAddress = receiver.slice(0, 2) === 'cn' ? receiver : this.root.formatAddress(receiver); - const maxInputAmount = getAssetBalance(inputAsset); + const maxInputAmount = inputTokenAmount.mul(new FPNumber(slippageMultiplier)).toCodecString(); const params = calcTxParams(inputAsset, maxInputAmount, undefined); await withLoading(async () => { try { From f9563c5dc2f8e9d4da0d9250b37502e5b1a00f33 Mon Sep 17 00:00:00 2001 From: Timofey Trepalin Date: Thu, 9 Mar 2023 17:06:23 +0500 Subject: [PATCH 2/2] route assets - set slippage 5% --- src/modules/ADAR/consts/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/ADAR/consts/index.ts b/src/modules/ADAR/consts/index.ts index 9dcd8445f..eae89d7ef 100644 --- a/src/modules/ADAR/consts/index.ts +++ b/src/modules/ADAR/consts/index.ts @@ -40,4 +40,4 @@ function createStage(title: string, componentName: string): Stage { }; } -export const slippageMultiplier = 1.15; +export const slippageMultiplier = 1.05;