Skip to content

Commit

Permalink
Enhance fixed fee resolver with additional parameter for increasing risk
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrwitek committed Nov 20, 2024
1 parent beb432e commit d59d975
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/dma-library/src/utils/swap/fee-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export const feeResolver = async <T extends string = string>(
},
): Promise<ResolvedFee> => {
if (isCorrelatedPosition(fromToken, toToken) || options?.isEarnPosition) {
return fixedFeeResolver(options?.positionData, options?.isOpeningPosition)
return fixedFeeResolver(
options?.positionData,
options?.isOpeningPosition,
options?.isIncreasingRisk,
)
} else {
return percentageFeeResolver(fromToken, toToken, options)
}
Expand Down
20 changes: 18 additions & 2 deletions packages/dma-library/src/utils/swap/fixed-fee-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,28 @@ import {
} from '../fee-service/getFixedFeeForPosition'
import type { ResolvedFee } from './fee-resolver'

const debugEnabled = process.env.DEBUG === 'true'
const log = (...args: any[]) => {
if (debugEnabled) {
console.log(...args)
}
}

export const fixedFeeResolver = async (
positionData: FixedFeePositionData | undefined,
isOpeningPosition?: boolean,
isIncreasingRisk?: boolean,
): Promise<ResolvedFee> => {
if (isOpeningPosition) {
console.log('Fixed fee is zero when opening a new earn position')
log('Fixed fee is zero when opening a new earn position')
return {
feeType: SwapFeeType.Fixed,
feeToCharge: new BigNumber(0),
}
}

if (isIncreasingRisk) {
log('Fixed fee is zero when increasing risk')
return {
feeType: SwapFeeType.Fixed,
feeToCharge: new BigNumber(0),
Expand All @@ -36,7 +52,7 @@ export const fixedFeeResolver = async (
feeType: SwapFeeType.Fixed,
feeToCharge: new BigNumber(fixedFee),
}
console.log('Fixed fee:', {
log('Fixed fee:', {
feeToCharge: resolvedFee.feeToCharge.toString(),
positionData,
isOpeningPosition,
Expand Down

0 comments on commit d59d975

Please sign in to comment.