Skip to content

Commit

Permalink
Feat/orderbook (#3121)
Browse files Browse the repository at this point in the history
* feat: orderbook

* feat: orderbook beta

* fix: build error

* fix: build error

* feat: portal upgrade trade config

* feat: orderbook optimization

* feat: orderbook optimization 1228

* feat: orderbook optimization 1228

* feat: orderbook optimization 1228

* feat: orderbook

* feat: orderbook beta

* fix: build error

* feat: portal upgrade trade config

* feat: orderbook optimization

* feat: orderbook optimization 1228

* feat: orderbook optimization 1228

* feat: orderbook optimization 1228

* fix

* fix build

---------

Co-authored-by: Jojoo <[email protected]>
  • Loading branch information
wow-sven and jojoo-eth authored Dec 29, 2024
1 parent 02d013f commit 7204c53
Show file tree
Hide file tree
Showing 36 changed files with 746 additions and 1,034 deletions.
4 changes: 0 additions & 4 deletions infra/rooch-portal-v2/src/app/trade/[tick]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,5 @@ export const metadata = {
};

export default function Page({ params }: { params: { tick: string } }) {
// if (!Object.keys(NETWORK_PACKAGE[NETWORK].tickInfo).includes(tick)) {
// return <NotMarketplaceFoundView />;
// }

return <MarketplaceView params={params} />;
}
2 changes: 1 addition & 1 deletion infra/rooch-portal-v2/src/app/trade/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import HomeView from 'src/sections/trade/home-view';
// ----------------------------------------------------------------------

export const metadata = {
title: 'Market | Orderbook',
title: 'Marketplace | List',
};

export default function Page() {
Expand Down
102 changes: 21 additions & 81 deletions infra/rooch-portal-v2/src/components/market/accept-bid-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ import {
} from '@mui/material';

import { fNumber } from 'src/utils/format-number';
import { formatUnitPrice } from 'src/utils/marketplace';
import { fromDust, formatNumber } from 'src/utils/number';

import { secondary } from 'src/theme/core';
import { TESTNET_ORDERBOOK_PACKAGE } from 'src/config/constant';

import { toast } from 'src/components/snackbar';
import { Iconify } from 'src/components/iconify';

import InscriptionShopCard from './inscription-shop-card';
import { useNetworkVariable } from '../../hooks/use-networks';

export type AcceptBidDialogProps = {
open: boolean;
Expand All @@ -42,71 +43,6 @@ export type AcceptBidDialogProps = {
close: () => void;
};

// function makeAcceptBidTxb(
// targetAmount: number,
// userOwnedTickInscription: InscriptionObject[],
// selectedBid: BidItemObject,
// address: string,
// tick: string
// ) {
// const tx = new Transaction();
// const sortedData = userOwnedTickInscription.sort(
// (a, b) => Number(b.data.content.fields.amount) - Number(a.data.content.fields.amount)
// );
// const firstItem = sortedData[0];
// const opSortedData = sortedData.length === 1 ? [sortedData[0]] : sortedData.slice(1);
// let currentTotal = new BigNumber(firstItem.data.content.fields.amount);
// let inputInscription:
// | {
// index: number;
// resultIndex: number;
// kind: 'NestedResult';
// }
// | undefined;
// // eslint-disable-next-line no-restricted-syntax
// for (const inscription of opSortedData) {
// const inscriptionData = inscription.data.content.fields;
// if (new BigNumber(currentTotal).isLessThanOrEqualTo(targetAmount)) {
// tx.callFunction({
// target: `${NETWORK_PACKAGE[NETWORK].MOVESCRIPTIONS_PACKAGE_ID}::movescription::merge`,
// args: [Args.objectId(firstItem.data.objectId), Args.objectId(inscription.data.objectId)],
// });
// currentTotal = currentTotal.plus(inscriptionData.amount);

// if (currentTotal.isEqualTo(targetAmount)) {
// break;
// }
// } else {
// const remainingAmt = new BigNumber(targetAmount).minus(currentTotal);
// if (remainingAmt.isLessThan(0)) {
// const [final] = tx.callFunction({
// target: `${NETWORK_PACKAGE[NETWORK].MOVESCRIPTIONS_PACKAGE_ID}::movescription::do_split`,
// arguments: [Args.objectId(firstItem.data.objectId), Args.u64(BigInt(targetAmount))],
// });
// inputInscription = final;
// break;
// }
// }
// }

// txb.moveCall({
// target: `${NETWORK_PACKAGE[NETWORK].MARKET_PACKAGE_ID}::market::accept_bid`,
// arguments: [
// txb.object(NETWORK_PACKAGE[NETWORK].tickInfo[tick].MARKET_OBJECT_ID),
// txb.object(inputInscription || firstItem.data.objectId),
// txb.pure(selectedBid.bidder),
// txb.pure(selectedBid.bidId),
// txb.object('0x6'),
// ],
// });

// if (inputInscription) {
// txb.transferObjects([firstItem.data.objectId], address);
// }

// return txb;
// }

export default function AcceptBidDialog({
open,
acceptBidItem,
Expand All @@ -117,15 +53,18 @@ export default function AcceptBidDialog({
refreshBidList,
close,
}: AcceptBidDialogProps) {
const market = useNetworkVariable('market')
const account = useCurrentAddress();
const { mutate: signAndExecuteTransaction, isPending } = useSignAndExecuteTransaction();

const price = useMemo(
() => new BigNumber(acceptBidItem.unit_price).times(acceptBidItem.quantity).toString(),
[acceptBidItem.quantity, acceptBidItem.unit_price]
() =>
new BigNumber(formatUnitPrice(acceptBidItem.unit_price, toCoinBalanceInfo.decimals))
.times(fromDust(acceptBidItem.quantity, toCoinBalanceInfo.decimals))
.toString(),
[acceptBidItem.quantity, acceptBidItem.unit_price, toCoinBalanceInfo.decimals]
);

const account = useCurrentAddress();

return (
<Dialog
open={open}
Expand Down Expand Up @@ -157,14 +96,14 @@ export default function AcceptBidDialog({
isVerified
amount={acceptBidItem.quantity}
price={price}
unitPrice={acceptBidItem.unit_price}
unitPrice={formatUnitPrice(acceptBidItem.unit_price, toCoinBalanceInfo.decimals)}
// acc={item.acc}
fromCoinBalanceInfo={fromCoinBalanceInfo}
toCoinBalanceInfo={toCoinBalanceInfo}
seller={acceptBidItem.owner}
selectMode={false}
type="list"
/>
/>
</Card>

<Stack
Expand Down Expand Up @@ -239,18 +178,15 @@ export default function AcceptBidDialog({

const tx = new Transaction();
tx.callFunction({
target: `${TESTNET_ORDERBOOK_PACKAGE}::market_v2::accept_bid`,
target: `${market.orderBookAddress}::market_v2::accept_bid`,
args: [
Args.objectId('0x156d9a5bfa4329f999115b5febde94eed4a37cde10637ad8eed1ba91e89e0bb7'),
Args.objectId(market.tickInfo[tick].obj),
Args.u64(BigInt(acceptBidItem.order_id)),
Args.address(acceptBidItem.owner),
Args.bool(true),
Args.address(account.genRoochAddress().toStr()),
],
typeArgs: [
'0x3::gas_coin::RGas',
'0x1d6f6657fc996008a1e43b8c13805e969a091560d4cea57b1db9f3ce4450d977::fixed_supply_coin::FSC',
],
typeArgs: [fromCoinBalanceInfo.coin_type, toCoinBalanceInfo.coin_type],
});

signAndExecuteTransaction(
Expand All @@ -259,9 +195,13 @@ export default function AcceptBidDialog({
},
{
async onSuccess(data) {
toast.success('Accept bid success');
close();
refreshBidList();
if (data.execution_info.status.type === 'executed') {
toast.success('Accept bid success');
close();
refreshBidList();
} else {
toast.error('Accept bid Failed');
}
},
onError(error) {
toast.error(String(error));
Expand Down
52 changes: 32 additions & 20 deletions infra/rooch-portal-v2/src/components/market/create-bid-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ import {
import { toDust } from 'src/utils/number';

import { secondary } from 'src/theme/core';
import { SUI_DECIMALS } from 'src/config/trade';
import { TESTNET_ORDERBOOK_PACKAGE } from 'src/config/constant';

import { toast } from '../snackbar';
import { toast } from 'src/components/snackbar';

import InscriptionShopCard from './inscription-shop-card';
import { useNetworkVariable } from '../../hooks/use-networks';

export type CreateBidDialogProps = {
open: boolean;
tick: string;
floorPrice: number;
floorPrice?: string;
fromCoinBalanceInfo: BalanceInfoView;
toCoinBalanceInfo: BalanceInfoView;
refreshBidList: () => Promise<void>;
Expand All @@ -47,12 +47,13 @@ export default function CreateBidDialog({
refreshBidList,
close,
}: CreateBidDialogProps) {
const [bidAmount, setBidAmount] = useState('');
const [bidUnitPrice, setBidUnitPrice] = useState('');

const market = useNetworkVariable('market')
const account = useCurrentAddress();
const { mutate: signAndExecuteTransaction, isPending } = useSignAndExecuteTransaction();

const [bidAmount, setBidAmount] = useState('');
const [bidUnitPrice, setBidUnitPrice] = useState('');

return (
<Dialog
open={open}
Expand Down Expand Up @@ -101,6 +102,7 @@ export default function CreateBidDialog({
<TextField
autoFocus
fullWidth
autoComplete="off"
type="number"
InputProps={{
endAdornment: (
Expand All @@ -123,6 +125,7 @@ export default function CreateBidDialog({
<TextField
autoFocus
fullWidth
autoComplete="off"
type="number"
InputProps={{
endAdornment: (
Expand Down Expand Up @@ -244,20 +247,26 @@ export default function CreateBidDialog({
return;
}
const tx = new Transaction();

const unitPriceInMist = toDust(bidUnitPrice, SUI_DECIMALS);
console.log(
'🚀 ~ file: create-bid-dialog.tsx:297 ~ toCoinBalanceInfo:',
fromCoinBalanceInfo,
toCoinBalanceInfo
);
const unitPrice = new BigNumber(
toDust(bidUnitPrice, fromCoinBalanceInfo.decimals).toString()
)
.times(new BigNumber(10).pow(5))
.div(new BigNumber(10).pow(toCoinBalanceInfo.decimals).toNumber())
.toNumber();

tx.callFunction({
target: `${TESTNET_ORDERBOOK_PACKAGE}::market_v2::create_bid`,
target: `${market.orderBookAddress}::market_v2::create_bid`,
args: [
Args.objectId('0x156d9a5bfa4329f999115b5febde94eed4a37cde10637ad8eed1ba91e89e0bb7'),
Args.u64(unitPriceInMist),
Args.objectId(market.tickInfo[tick].obj),
Args.u64(BigInt(unitPrice)),
Args.u256(BigInt(toDust(bidAmount, toCoinBalanceInfo.decimals))),
],
typeArgs: [
'0x3::gas_coin::RGas',
'0x1d6f6657fc996008a1e43b8c13805e969a091560d4cea57b1db9f3ce4450d977::fixed_supply_coin::FSC',
],
typeArgs: [fromCoinBalanceInfo.coin_type, toCoinBalanceInfo.coin_type],
});

signAndExecuteTransaction(
Expand All @@ -266,10 +275,13 @@ export default function CreateBidDialog({
},
{
async onSuccess(data) {
// await refetchAddressOwnedInscription();
toast.success('Create Bid Success');
close();
refreshBidList();
if (data.execution_info.status.type === 'executed') {
toast.success('Create Bid Success');
close();
refreshBidList();
} else {
toast.error('Create Bid Failed');
}
},
onError(error) {
toast.error(String(error));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Link from 'next/link';
import { yellow } from '@mui/material/colors';
import { Chip, Stack, Typography } from '@mui/material';

import { fNumber } from 'src/utils/format-number';

import { Iconify } from 'src/components/iconify';

export interface InscriptionCardProps {
Expand Down Expand Up @@ -62,9 +64,7 @@ export default function InscriptionCard({
{selectMode ? (
<Chip size="small" label={`#${objectId.slice(2, 8)}`} variant="soft" color="info" />
) : (
<Link href={`https://suivision.xyz/object/${objectId}`} target="_blank">
<Chip size="small" label={`#${objectId.slice(2, 8)}`} variant="soft" color="info" />
</Link>
)}
</>
)}
Expand All @@ -84,7 +84,7 @@ export default function InscriptionCard({
fontWeight: 600,
}}
>
{tokenBalance}
{fNumber(tokenBalance)}
</Typography>
</Stack>
);
Expand Down
Loading

0 comments on commit 7204c53

Please sign in to comment.