Skip to content

Commit

Permalink
fix: send token adapter fees (#154)
Browse files Browse the repository at this point in the history
Updated send token adapter fees by 1%
  • Loading branch information
palace22 authored Sep 18, 2024
1 parent 5fc007d commit 32b44f5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/violet-insects-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@folks-finance/xchain-sdk": patch
---

increased send token adapter fees by 1%
1 change: 1 addition & 0 deletions src/chains/evm/common/constants/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export const defaultEventParams: EventParams = {

export const GAS_LIMIT_ESTIMATE_INCREASE = 10_000n;
export const SEND_TOKEN_ACTION_RETURN_GAS_LIMIT = 500_000n;
export const RECEIVER_VALUE_SLIPPAGE = 0.01;
12 changes: 8 additions & 4 deletions src/chains/evm/hub/modules/folks-hub-loan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ import {
toFAmount,
toUnderlyingAmount,
} from "../../../../common/utils/formulae.js";
import { bigIntMin, compoundEverySecond } from "../../../../common/utils/math-lib.js";
import { bigIntMin, compoundEverySecond, increaseByPercent } from "../../../../common/utils/math-lib.js";
import { exhaustiveCheck } from "../../../../utils/exhaustive-check.js";
import { defaultEventParams, GAS_LIMIT_ESTIMATE_INCREASE } from "../../common/constants/contract.js";
import {
defaultEventParams,
GAS_LIMIT_ESTIMATE_INCREASE,
RECEIVER_VALUE_SLIPPAGE,
} from "../../common/constants/contract.js";
import { getEvmSignerAccount } from "../../common/utils/chain.js";
import {
buildEvmMessageData,
Expand Down Expand Up @@ -161,8 +165,8 @@ export async function getSendTokenAdapterFees(
extraArgs: buildSendTokenExtraArgsWhenRemoving(spokeTokenData.spokeAddress, hubTokenData.token, amount),
};

// get return adapter fee
return await hubBridgeRouter.read.getSendFee([returnMessage]);
// get return adapter fee increased by 1%
return increaseByPercent(await hubBridgeRouter.read.getSendFee([returnMessage]), RECEIVER_VALUE_SLIPPAGE);
}

export async function getLoanTypeInfo(
Expand Down
4 changes: 4 additions & 0 deletions src/common/utils/math-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ export function compoundEveryHour(rate: Dnum): Dnum {

export const bigIntMax = (...args: Array<bigint>) => args.reduce((m, e) => (e > m ? e : m));
export const bigIntMin = (...args: Array<bigint>) => args.reduce((m, e) => (e < m ? e : m));

export const increaseByPercent = (value: bigint, percent: number) => {
return value + (value * BigInt(10_000 * percent)) / BigInt(10_000);
};

0 comments on commit 32b44f5

Please sign in to comment.