Skip to content
This repository was archived by the owner on Nov 15, 2024. It is now read-only.

Commit 285b134

Browse files
authored
create pool fee (#13)
1 parent 3f63343 commit 285b134

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

src/pages/liquidity/create.tsx

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { useRouter } from 'next/router'
22
import { ReactNode, useMemo, useState } from 'react'
33
import { twMerge } from 'tailwind-merge'
44

5+
import useAppAdvancedSettings from '@/application/common/useAppAdvancedSettings'
56
import useAppSettings from '@/application/common/useAppSettings'
7+
import useConnection from '@/application/connection/useConnection'
68
import txCreateAndInitNewPool from '@/application/createPool/txCreateAndInitNewPool'
79
import { updateCreatePoolInfo } from '@/application/createPool/updateCreatePoolInfo'
810
import useCreatePool from '@/application/createPool/useCreatePool'
@@ -23,14 +25,16 @@ import Link from '@/components/Link'
2325
import PageLayout from '@/components/PageLayout'
2426
import Row from '@/components/Row'
2527
import SetpIndicator from '@/components/SetpIndicator'
28+
import Tooltip from '@/components/Tooltip'
2629
import copyToClipboard from '@/functions/dom/copyToClipboard'
2730
import { toTokenAmount } from '@/functions/format/toTokenAmount'
2831
import { isMeaningfulNumber, lte } from '@/functions/numberish/compare'
2932
import { div } from '@/functions/numberish/operations'
3033
import { toString } from '@/functions/numberish/toString'
34+
import useAsyncMemo from '@/hooks/useAsyncMemo'
3135
import useToggle from '@/hooks/useToggle'
36+
import { Liquidity, struct, u64 } from '@raydium-io/raydium-sdk'
3237
import { getMaxBalanceBNIfNotATA } from '../../application/token/getMaxBalanceIfNotATA'
33-
import Tooltip from '@/components/Tooltip'
3438

3539
/**
3640
* @see https://uiwjs.github.io/#/components/date-input
@@ -125,6 +129,7 @@ function PanelContent({ close }: { close(): void }) {
125129
const haveEnoughCoinQuote = quoteAmount && quoteTokenBalance && lte(quoteAmount, quoteTokenBalance)
126130

127131
const [priceReverse, { toggle }] = useToggle()
132+
const solCost = useCreatePoolSOLCost()
128133

129134
const step2Content = (
130135
<>
@@ -180,8 +185,8 @@ function PanelContent({ close }: { close(): void }) {
180185
onDateChange={(selectedDate) => useCreatePool.setState({ startTime: selectedDate })}
181186
showTime={{ format: 'HH:mm:ss' }}
182187
/>
183-
{/* <Row className="text-xs font-medium text-[#D6CC56] bg-[#D6CC5620] py-3 px-4 rounded-xl mb-5">
184-
A creation fee of X.XX SOL is required for new pools
188+
<Row className="text-xs font-medium text-[#D6CC56] bg-[#D6CC5620] py-3 px-4 rounded-xl mb-5">
189+
A creation fee of {solCost ?? '--'} SOL is required for new pools
185190
<Tooltip>
186191
<Icon iconClassName="ml-1" size="sm" heroIconName="information-circle" />
187192
<Tooltip.Panel>
@@ -191,7 +196,7 @@ function PanelContent({ close }: { close(): void }) {
191196
</div>
192197
</Tooltip.Panel>
193198
</Tooltip>
194-
</Row> */}
199+
</Row>
195200

196201
<Button
197202
className="frosted-glass-teal w-full"
@@ -440,3 +445,27 @@ function UserCreatedPoolsExhibitionPanel() {
440445
</div>
441446
)
442447
}
448+
449+
/**
450+
* async hook
451+
* used in sol cost alert
452+
* @author Rudy
453+
*/
454+
function useCreatePoolSOLCost(): number | undefined {
455+
const programIds = useAppAdvancedSettings((s) => s.programIds)
456+
const connection = useConnection((s) => s.connection)
457+
const cost = useAsyncMemo(async () => {
458+
const data = (
459+
await connection?.getAccountInfo(Liquidity.getAssociatedConfigId({ programId: programIds.AmmV4 }), {
460+
dataSlice: { offset: 536, length: 8 }
461+
})
462+
)?.data
463+
return data
464+
? struct([u64('fee')])
465+
.decode(data)
466+
.fee.toNumber() /
467+
10 ** 9
468+
: undefined
469+
}, [connection, programIds.AmmV4])
470+
return cost
471+
}

0 commit comments

Comments
 (0)