Skip to content

Commit

Permalink
update create pool page
Browse files Browse the repository at this point in the history
  • Loading branch information
Ridel1e committed Feb 26, 2024
1 parent 9c6acc7 commit 5f955b6
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 42 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@sentry/react": "^6.16.1",
"@sentry/tracing": "^6.16.1",
"@spectrumlabs/analytics": "^1.1.9",
"@spectrumlabs/cardano-dex-sdk": "^0.1.305",
"@spectrumlabs/cardano-dex-sdk": "^0.1.306",
"@types/file-saver": "^2.0.5",
"@types/lodash": "^4.14.172",
"@types/numeral": "^2.0.2",
Expand Down Expand Up @@ -113,6 +113,6 @@
]
},
"engines": {
"node": "^19"
"node": "^20"
}
}
14 changes: 14 additions & 0 deletions src/applicationConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RustModule } from '@spectrumlabs/cardano-dex-sdk/build/main/utils/rustLoader';
import { DateTime } from 'luxon';

import { Dictionary } from './common/utils/Dictionary';
Expand Down Expand Up @@ -313,3 +314,16 @@ export const applicationConfig: ApplicationConfig = {
],
cardanoAmmSwapsOpenTime: DateTime.utc(2023, 6, 21, 19, 59, 0),
};

RustModule.load().then((m) =>
console.log(
m.EnterpriseAddress.new(
0,
m.StakeCredential.from_scripthash(
m.ScriptHash.from_hex(
'e55e73b818db7b6de30b51faa932490acee50063e90a8c41d6f0236a',
),
),
),
),
);
15 changes: 5 additions & 10 deletions src/common/models/AmmPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,17 @@ export abstract class AmmPool {
): Currency;

get poolFee(): number {
return evaluate(
`(1 - ${this.feeNum} / ${this.feeDenom}) * ${
this.feeDenom / 10n ** this.feeDecimalsCount
}`,
).toFixed(1, Number(this.feeDecimalsCount));
return evaluate(`(1 - ${this.feeNum} / ${this.feeDenom}) * 100`).toFixed(
1,
Number(this.feeDecimalsCount),
);
}

get treasuryFee(): number | undefined {
if (!this.treasuryFeeNum) {
return undefined;
}
return evaluate(
`${this.treasuryFeeNum} / (${
this.feeDenom / 10n ** this.feeDecimalsCount
})`,
);
return evaluate(`${this.treasuryFeeNum} / 100`);
}

get xRatio(): Ratio {
Expand Down
2 changes: 1 addition & 1 deletion src/network/cardano/api/ammPools/CardanoAmmPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class CardanoAmmPool extends AmmPool {
}

get feeDecimalsCount(): bigint {
return this.pool.type === AmmPoolType.DEFAULT ? 1n : 2n;
return this.pool.type === AmmPoolType.DEFAULT ? 1n : 3n;
}

get poolFeeNum(): number {
Expand Down
10 changes: 9 additions & 1 deletion src/network/cardano/api/operations/createPool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,20 @@ export const toCreatePoolTxCandidate = ({
]) => {
return transactionBuilder$.pipe(
switchMap((transactionBuilder) => {
console.log(
BigInt((1 - Number((feePct / 100).toFixed(4))) * 100000),
);
return transactionBuilder.poolCreation({
x: new AssetAmount(x.asset.data, x.amount),
y: new AssetAmount(y.asset.data, y.amount),
nft: nftData[0],
lq: lqData[0],
feeNum: BigInt((1 - Number((feePct / 100).toFixed(4))) * 10000),
feeNum: BigInt(
Math.round((1 - Number((feePct / 100).toFixed(5))) * 100000),
),
daoFeeNum: BigInt(
Math.round(Number((feePct / 100 / 10).toFixed(5)) * 100000),
),
mintingCreationTxHash: utxo.txOut.txHash,
mintingCreationTxOutIdx: utxo.txOut.index,
lqMintingScript: lqData[1].script,
Expand Down
62 changes: 39 additions & 23 deletions src/pages/CreatePool/FeeSelector/FeeSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Control, Flex, Input, Typography } from '@ergolabs/ui-kit';
import { t } from '@lingui/macro';
import { t, Trans } from '@lingui/macro';
import { FC, ReactNode, useState } from 'react';

import { escapeRegExp } from '../../../components/common/TokenControl/AssetAmountInput/format';
import { InfoTooltip } from '../../../components/InfoTooltip/InfoTooltip.tsx';
import { formatToFeePercent } from '../../../services/number.ts';
import { FeeBox } from './FeeBox/FeeBox';

interface FeeDescriptor {
Expand Down Expand Up @@ -57,32 +59,46 @@ export const FeeSelector: FC<FeeSelectorProps> = ({ value, onChange }) => {
setUserInput(userInput ?? '');
};

const daoFee = value ? formatToFeePercent(value / 10) : undefined;

return (
<Flex>
{FEES.map((fee) => (
<Flex.Item key={fee.percent} flex={1} marginRight={2}>
<Flex col width="100%">
<Flex.Item display="flex" align="center" width="100%" marginBottom={4}>
{FEES.map((fee) => (
<Flex.Item key={fee.percent} flex={1} marginRight={2}>
<FeeBox
onClick={() => handleItemClick(fee.percent)}
active={fee.percent === value}
description={fee.description}
content={fee.content}
/>
</Flex.Item>
))}
<Flex.Item flex={1}>
<FeeBox
onClick={() => handleItemClick(fee.percent)}
active={fee.percent === value}
description={fee.description}
content={fee.content}
active={!!value && FEES.every((fee) => value !== fee.percent)}
description={t`Custom fee tier`}
content={
<Input
size="large"
textAlign="right"
value={userInput}
onChange={(e) => handleInputChange(e.target.value)}
suffix={<Typography.Body>%</Typography.Body>}
/>
}
/>
</Flex.Item>
))}
<Flex.Item flex={1}>
<FeeBox
active={!!value && FEES.every((fee) => value !== fee.percent)}
description={t`Custom fee tier`}
content={
<Input
size="large"
textAlign="right"
value={userInput}
onChange={(e) => handleInputChange(e.target.value)}
suffix={<Typography.Body>%</Typography.Body>}
/>
}
/>
</Flex.Item>
<Flex.Item display="flex" align="center" justify="space-between">
<InfoTooltip content="" isQuestionIcon>
<Typography.Body size="small">
<Trans>DAO Fee</Trans>
</Typography.Body>
</InfoTooltip>
<Typography.Body size="small">
{daoFee ? `${daoFee}%` : '–'}
</Typography.Body>
</Flex.Item>
</Flex>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import { Box, Typography } from '@ergolabs/ui-kit';
import { FC } from 'react';

import { AmmPool } from '../../../../common/models/AmmPool';
import { formatToFeePercent } from '../../../../services/number.ts';

interface PoolFeeTagProps {
readonly ammPool: AmmPool;
}

export const PoolFeeTag: FC<PoolFeeTagProps> = ({ ammPool }) => (
<Box padding={[0.5, 1]} secondary borderRadius="m">
<Typography.Body size="small">{ammPool.poolFee}%</Typography.Body>
<Typography.Body size="small">
{formatToFeePercent(ammPool.poolFee)}%
</Typography.Body>
</Box>
);
9 changes: 9 additions & 0 deletions src/services/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,12 @@ export const formatToPercent = (amount: number | string): string => {

export const formatToInt = (amount: number | string): string =>
numeral(amount).format(INT_FORMAT);

const feePctFormatter = new Intl.NumberFormat('en-US', {
maximumFractionDigits: 3,
minimumFractionDigits: 1,
});

export const formatToFeePercent = (amount: number): string => {
return feePctFormatter.format(amount);
};
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3337,10 +3337,10 @@
dependencies:
"@amplitude/analytics-browser" "^1.9.0"

"@spectrumlabs/cardano-dex-sdk@^0.1.305":
version "0.1.305"
resolved "https://registry.yarnpkg.com/@spectrumlabs/cardano-dex-sdk/-/cardano-dex-sdk-0.1.305.tgz#da1d17eaea074b7ca103fa4eb6f14923da088bb0"
integrity sha512-GDqvLq6KAHj+rMCeFQdJRQkdb0tACMbS7xeJypZ+EzaickODmXODw8u5nHwxcn/+nYqZw1swnCv3AtJ5A0ypOw==
"@spectrumlabs/cardano-dex-sdk@^0.1.306":
version "0.1.306"
resolved "https://registry.yarnpkg.com/@spectrumlabs/cardano-dex-sdk/-/cardano-dex-sdk-0.1.306.tgz#53220e262694d24d6ed4a5c15d1eaad611976057"
integrity sha512-QtaBAii2oFwtYBGL82hTSfT8ZI/ATRQxCJ373VgsNm+7UHXFXTf9aKTHTFd82AvvaOaBzPWy1u8mV/eehmHH8Q==
dependencies:
"@emurgo/cardano-serialization-lib-browser" "^11.5.0"
axios "^0.21.1"
Expand Down

0 comments on commit 5f955b6

Please sign in to comment.