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

Commit

Permalink
create pool fee (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
rudy5348 authored Jan 1, 2024
1 parent 3f63343 commit 285b134
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions src/pages/liquidity/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { useRouter } from 'next/router'
import { ReactNode, useMemo, useState } from 'react'
import { twMerge } from 'tailwind-merge'

import useAppAdvancedSettings from '@/application/common/useAppAdvancedSettings'
import useAppSettings from '@/application/common/useAppSettings'
import useConnection from '@/application/connection/useConnection'
import txCreateAndInitNewPool from '@/application/createPool/txCreateAndInitNewPool'
import { updateCreatePoolInfo } from '@/application/createPool/updateCreatePoolInfo'
import useCreatePool from '@/application/createPool/useCreatePool'
Expand All @@ -23,14 +25,16 @@ import Link from '@/components/Link'
import PageLayout from '@/components/PageLayout'
import Row from '@/components/Row'
import SetpIndicator from '@/components/SetpIndicator'
import Tooltip from '@/components/Tooltip'
import copyToClipboard from '@/functions/dom/copyToClipboard'
import { toTokenAmount } from '@/functions/format/toTokenAmount'
import { isMeaningfulNumber, lte } from '@/functions/numberish/compare'
import { div } from '@/functions/numberish/operations'
import { toString } from '@/functions/numberish/toString'
import useAsyncMemo from '@/hooks/useAsyncMemo'
import useToggle from '@/hooks/useToggle'
import { Liquidity, struct, u64 } from '@raydium-io/raydium-sdk'
import { getMaxBalanceBNIfNotATA } from '../../application/token/getMaxBalanceIfNotATA'
import Tooltip from '@/components/Tooltip'

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

const [priceReverse, { toggle }] = useToggle()
const solCost = useCreatePoolSOLCost()

const step2Content = (
<>
Expand Down Expand Up @@ -180,8 +185,8 @@ function PanelContent({ close }: { close(): void }) {
onDateChange={(selectedDate) => useCreatePool.setState({ startTime: selectedDate })}
showTime={{ format: 'HH:mm:ss' }}
/>
{/* <Row className="text-xs font-medium text-[#D6CC56] bg-[#D6CC5620] py-3 px-4 rounded-xl mb-5">
A creation fee of X.XX SOL is required for new pools
<Row className="text-xs font-medium text-[#D6CC56] bg-[#D6CC5620] py-3 px-4 rounded-xl mb-5">
A creation fee of {solCost ?? '--'} SOL is required for new pools
<Tooltip>
<Icon iconClassName="ml-1" size="sm" heroIconName="information-circle" />
<Tooltip.Panel>
Expand All @@ -191,7 +196,7 @@ function PanelContent({ close }: { close(): void }) {
</div>
</Tooltip.Panel>
</Tooltip>
</Row> */}
</Row>

<Button
className="frosted-glass-teal w-full"
Expand Down Expand Up @@ -440,3 +445,27 @@ function UserCreatedPoolsExhibitionPanel() {
</div>
)
}

/**
* async hook
* used in sol cost alert
* @author Rudy
*/
function useCreatePoolSOLCost(): number | undefined {
const programIds = useAppAdvancedSettings((s) => s.programIds)
const connection = useConnection((s) => s.connection)
const cost = useAsyncMemo(async () => {
const data = (
await connection?.getAccountInfo(Liquidity.getAssociatedConfigId({ programId: programIds.AmmV4 }), {
dataSlice: { offset: 536, length: 8 }
})
)?.data
return data
? struct([u64('fee')])
.decode(data)
.fee.toNumber() /
10 ** 9
: undefined
}, [connection, programIds.AmmV4])
return cost
}

1 comment on commit 285b134

@vercel
Copy link

@vercel vercel bot commented on 285b134 Jan 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.