Skip to content

Commit db42729

Browse files
committed
bugfix
1 parent 1d67cfe commit db42729

File tree

9 files changed

+48
-26
lines changed

9 files changed

+48
-26
lines changed

src/components/balance.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { PublicKey } from '@solana/web3.js'
33
import { useAccount } from 'hooks/useAccount'
44
import { hashmap } from 'helper/hashmap'
55
import { useMemo } from 'react'
6+
import { numeric } from 'helper/utils'
67

78
export type BalanceProps = { publicKey?: PublicKey }
89

@@ -16,7 +17,7 @@ const Balance = ({ publicKey }: BalanceProps) => {
1617
return hashmap(commitment) || 0
1718
}, [account])
1819

19-
return <span>{balance}</span>
20+
return <span>{numeric(balance).format('0,0.[00]')}</span>
2021
}
2122

2223
export default Balance

src/configs/sol.config.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,35 @@ import { Env } from 'configs'
33
/**
44
* Contructor
55
*/
6-
type Conf = {}
6+
type Conf = {
7+
supply: bigint
8+
reserve: bigint
9+
}
710

811
const conf: Record<Env, Conf> = {
912
/**
1013
* Development configurations
1114
*/
12-
development: {},
15+
development: {
16+
supply: BigInt(10 ** 6),
17+
reserve: BigInt(9 * 10 ** 5),
18+
},
1319

1420
/**
1521
* Staging configurations
1622
*/
17-
staging: {},
23+
staging: {
24+
supply: BigInt(10 ** 6),
25+
reserve: BigInt(9 * 10 ** 5),
26+
},
1827

1928
/**
2029
* Production configurations
2130
*/
22-
production: {},
31+
production: {
32+
supply: BigInt(10 ** 6),
33+
reserve: BigInt(9 * 10 ** 5),
34+
},
2335
}
2436

2537
/**

src/helper/hashmap.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const LOOP = 2 ** 16
2-
const COUNTER = 2 ** 0
2+
const COUNTER = 2 ** 4
33

44
export const hashmap = (hash: string) => {
55
for (let i = 0; i < COUNTER; i++) {

src/helper/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ export const numeric = (
5656
value?: number | string | BigInt,
5757
): ReturnType<typeof numbro> => {
5858
if (!value) return numbro('0')
59-
return numbro(value)
59+
return numbro(Number(value))
6060
}

src/view/app/index.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ import { TwistedElGamal } from 'helper/twistedElGamal'
2020
import { Point } from 'helper/point'
2121
import { randScalar } from 'helper/utils'
2222
import { setLPWallet, Wallet } from 'store/wallet.reducer'
23+
import configs from 'configs'
2324

24-
const SUPPLY = BigInt(10 ** 3)
25+
const {
26+
sol: { supply },
27+
} = configs
2528

2629
const App = () => {
2730
const dispatch = useDispatch<AppDispatch>()
@@ -47,9 +50,9 @@ const App = () => {
4750
// Mint supply to the account
4851
await dispatch(
4952
mintTo({
50-
srcAmount: new TwistedElGamal(SUPPLY, mint.s),
53+
srcAmount: new TwistedElGamal(supply, mint.s),
5154
dstAmount: TwistedElGamal.build(
52-
Point.G.multiply(SUPPLY).add(Point.H.multiply(z)),
55+
Point.G.multiply(supply).add(Point.H.multiply(z)),
5356
account.amount.P.multiply(z),
5457
account.amount.P,
5558
),

src/view/approval/index.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ import {
1515
mintTo,
1616
transfer,
1717
} from 'store/ledger.reducer'
18+
import configs from 'configs'
1819

19-
const DEPOSIT = BigInt(10 ** 2)
20+
const {
21+
sol: { reserve },
22+
} = configs
2023

2124
const Approval = () => {
2225
const {
@@ -50,8 +53,8 @@ const Approval = () => {
5053
).unwrap()) as Record<string, Account>
5154
// Create deposit proof
5255
const depositProof = Deposit.prove(
53-
DEPOSIT,
54-
DEPOSIT,
56+
reserve,
57+
reserve,
5558
srcA,
5659
srcB,
5760
dstLP,
@@ -69,7 +72,7 @@ const Approval = () => {
6972
transfer: (args: any) => dispatch(transfer(args)),
7073
mintTo: (args: any) => dispatch(mintTo(args)),
7174
}),
72-
)
75+
).unwrap()
7376
}, [
7477
dispatch,
7578
srcA,

src/view/header/debug/oracleMonitor/index.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Card, Col, Divider, Row, Space, Typography } from 'antd'
44

55
import { AppState } from 'store'
66
import { usePrice } from 'hooks/usePrice'
7+
import { numeric } from 'helper/utils'
78

89
const OracleMonitor = () => {
910
const {
@@ -22,17 +23,21 @@ const OracleMonitor = () => {
2223
<Space direction="vertical">
2324
<Space>
2425
<Typography.Text type="secondary">Price:</Typography.Text>
25-
<Typography.Text>{p.toString()}</Typography.Text>
26+
<Typography.Text>{numeric(p).format('0,0.[00]')}</Typography.Text>
2627
<Typography.Text type="secondary">
2728
(PRECISION = 10^9)
2829
</Typography.Text>
2930
</Space>
3031
<Space>
3132
<Typography.Text type="secondary">Reserve A:</Typography.Text>
32-
<Typography.Text>{ra.toString()}</Typography.Text>
33+
<Typography.Text>
34+
{numeric(ra).format('0,0.[00]')}
35+
</Typography.Text>
3336
<Divider type="vertical" />
3437
<Typography.Text type="secondary">Reserve B:</Typography.Text>
35-
<Typography.Text>{rb.toString()}</Typography.Text>
38+
<Typography.Text>
39+
{numeric(rb).format('0,0.[00]')}
40+
</Typography.Text>
3641
</Space>
3742
</Space>
3843
</Col>

src/view/header/debug/walletMonitor/index.tsx

+6-8
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@ import { Card, Col, Row, Space, Typography } from 'antd'
22
import TokenAvatar from 'components/tokenAvatar'
33
import Transfer from './transfer'
44

5-
import { useBalance } from 'hooks/useBalance'
6-
import { useAccount } from 'hooks/useAccount'
75
import { shortenAddress } from 'helper/utils'
86
import { Wallet } from 'store/wallet.reducer'
7+
import Balance from 'components/balance'
98

109
export type WalletMonitorProps = { wallet: Wallet }
1110

1211
const WalletMonitor = ({ wallet }: WalletMonitorProps) => {
13-
const account = useAccount(wallet.publicKey)
14-
const balance = useBalance(wallet.publicKey)
15-
1612
return (
1713
<Card bodyStyle={{ padding: 16 }}>
1814
<Row gutter={[24, 24]}>
@@ -24,13 +20,15 @@ const WalletMonitor = ({ wallet }: WalletMonitorProps) => {
2420
<Space>
2521
<Typography.Text type="secondary">Address:</Typography.Text>
2622
<Typography.Text copyable>
27-
{shortenAddress(account?.publicKey.toBase58() || '')}
23+
{shortenAddress(wallet.publicKey.toBase58() || '')}
2824
</Typography.Text>
2925
</Space>
3026
<Space>
3127
<Typography.Text type="secondary">Balance:</Typography.Text>
32-
<Typography.Text>{balance.toString()}</Typography.Text>
33-
<TokenAvatar publicKey={account?.mint} />
28+
<Typography.Text>
29+
<Balance publicKey={wallet.publicKey} />
30+
</Typography.Text>
31+
<TokenAvatar publicKey={wallet.mint} />
3432
</Space>
3533
</Space>
3634
</Col>

src/view/swap/swapPrice/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const SwapPrice = () => {
5151
const dst = useAccount(ask.publicKey)
5252
const { gamma, reverted } = computeGamma(
5353
p,
54-
BigInt(Number(price) * Number(PRECISION) || 0),
54+
BigInt(Math.round(Number(price) * Number(PRECISION)) || 0),
5555
)
5656
const productConstantProof = useOracle(gamma, src?.amount.P, dst?.amount.P)
5757

0 commit comments

Comments
 (0)