Skip to content

Commit

Permalink
Merge pull request #132 from dhedge/feat/add-withdrawal-fee
Browse files Browse the repository at this point in the history
feat: add withdrawal fee
  • Loading branch information
dimlbc authored Nov 29, 2024
2 parents fa7d0a3 + 1d6fa21 commit e67b78e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/trading-widget/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhedge/trading-widget",
"version": "3.1.4",
"version": "3.1.5",
"license": "MIT",
"type": "module",
"main": "index.js",
Expand Down
10 changes: 10 additions & 0 deletions packages/trading-widget/src/core-kit/const/synthetix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,13 @@ export const SYNTHETIX_V3_POSITION_DEBT_ARGUMENTS: Record<string, string[]> = {
'0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
],
}

export const WITHDRAWAL_FEE_MAP = new Map<Address, number>([
['0x7d3c9c6566375d7ad6e89169ca5c01b5edc15364', 0.2], // SOLBULL2X_OPTIMISM
['0x32ad28356ef70adc3ec051d8aacdeeaa10135296', 0.2], // BTCBULL2X_OPTIMISM
['0xb03818de4992388260b62259361778cf98485dfe', 0.3], // BTCBULL3X_OPTIMISM
['0x11b55966527ff030ca9c7b1c548b4be5e7eaee6d', 0.4], // BTCBULL4X_OPTIMISM
['0xcc7d6ed524760539311ed0cdb41d0852b4eb77eb', 0.6], // SOLBULL3X_OPTIMISM
['0x49bdb78f48db6e0ced4d4475b6d2047539df1412', 0.4], // DOGEBULL2X_OPTIMISM
['0x1bae4efc60269fe66ecec7252825d6a0250a02ee', 0.6], // SUIBULL2X_OPTIMISM
])
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo } from 'react'

import { MANAGER_FEE_DENOMINATOR } from 'core-kit/const'
import { MANAGER_FEE_DENOMINATOR, WITHDRAWAL_FEE_MAP } from 'core-kit/const'
import { usePoolDynamicContractData } from 'core-kit/hooks/pool'
import { useTradingPanelPoolFallbackData } from 'core-kit/hooks/state'
import type { Address, ChainId } from 'core-kit/types/web3.types'
Expand Down Expand Up @@ -47,6 +47,7 @@ export const usePoolFees = ({ address, chainId }: PoolFeesParams) => {
2,
),
exitFee: formatNumeratorToPercentage(exitFee, MANAGER_FEE_DENOMINATOR, 2),
withdrawalFeeNumber: WITHDRAWAL_FEE_MAP.get(address) ?? 0,
exitFeeNumber: getPercent(+exitFee, MANAGER_FEE_DENOMINATOR),
}),
[
Expand All @@ -56,6 +57,7 @@ export const usePoolFees = ({ address, chainId }: PoolFeesParams) => {
streamingFee,
entryFee,
exitFee,
address,
],
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { isNumeric } from 'core-kit/utils'

export const useInitWithdrawQuote = () => {
const { chainId, address } = useTradingPanelPoolConfig()
const { exitFeeNumber } = usePoolFees({ address, chainId })
const { exitFeeNumber, withdrawalFeeNumber } = usePoolFees({
address,
chainId,
})
const [sendToken] = useSendTokenInput()
const [receiveToken, updateReceiveToken] = useReceiveTokenInput()
const sendTokenPrice = usePoolTokenPrice({ address, chainId })
Expand All @@ -28,7 +31,7 @@ export const useInitWithdrawQuote = () => {
}
const sendValue = new BigNumber(sendToken.value)
.times(sendTokenPrice)
.times(1 - exitFeeNumber / 100)
.times(1 - (exitFeeNumber + withdrawalFeeNumber) / 100)
const receiveTokenAmount = sendValue
.dividedBy(receiveTokenPrice)
.toFixed(receiveToken.decimals)
Expand All @@ -38,6 +41,7 @@ export const useInitWithdrawQuote = () => {
})
}, [
exitFeeNumber,
withdrawalFeeNumber,
receiveToken.decimals,
receiveTokenPrice,
sendToken.value,
Expand Down

0 comments on commit e67b78e

Please sign in to comment.