Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .turbo/cache/6a91baf0e64ff848-meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"hash":"6a91baf0e64ff848","duration":2858}
Binary file added .turbo/cache/6a91baf0e64ff848.tar.zst
Binary file not shown.
1 change: 1 addition & 0 deletions .turbo/cache/819d866a1222082a-meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"hash":"819d866a1222082a","duration":3036}
Binary file added .turbo/cache/819d866a1222082a.tar.zst
Binary file not shown.
1 change: 1 addition & 0 deletions .turbo/cache/f0be77d340149c0e-meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"hash":"f0be77d340149c0e","duration":3880}
Binary file added .turbo/cache/f0be77d340149c0e.tar.zst
Binary file not shown.
1 change: 1 addition & 0 deletions .turbo/cache/f8b2adaa0614c467-meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"hash":"f8b2adaa0614c467","duration":5375}
Binary file added .turbo/cache/f8b2adaa0614c467.tar.zst
Binary file not shown.
Empty file added .turbo/cookies/10.cookie
Empty file.
Empty file added .turbo/cookies/11.cookie
Empty file.
Empty file added .turbo/cookies/12.cookie
Empty file.
Empty file added .turbo/cookies/2.cookie
Empty file.
Empty file added .turbo/cookies/3.cookie
Empty file.
Empty file added .turbo/cookies/4.cookie
Empty file.
Empty file added .turbo/cookies/5.cookie
Empty file.
Empty file added .turbo/cookies/6.cookie
Empty file.
Empty file added .turbo/cookies/7.cookie
Empty file.
Empty file added .turbo/cookies/8.cookie
Empty file.
Empty file added .turbo/cookies/9.cookie
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion apps/docus/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const config: Config = {
// Replace with your project's social card
image: 'img/docusaurus-social-card.jpg',
navbar: {
title: 'TrusSwap Docs',
title: 'TrustSwap Docs',

items: [
{ type: 'doc', docId: 'litepaper/introduction', position: 'left', label: 'Litepaper' },
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NavLink, Outlet, useLocation } from "react-router-dom";
import { useEffect, useRef, useState } from "react";
import styles from "../styles/Layout.module.css";
import { ConnectButton } from "./ConnectButton";
import { NetworkSelect } from "./NetworkSelect";
import logo from "../assets/logo.png";

export default function Layout() {
Expand Down Expand Up @@ -113,6 +114,9 @@ export default function Layout() {
<div className={styles.connectPage}>
<ConnectButton />
</div>
<div className={styles.networkSelectContainer}>
<NetworkSelect />
</div>
</div>
</header>
<main>
Expand Down
39 changes: 39 additions & 0 deletions apps/web/src/components/NetworkSelect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from "react";
import { useChainId, useSwitchChain } from "wagmi";
import { CHAINS } from "../lib/wagmi";
import styles from "../styles/Layout.module.css";

export function NetworkSelect() {
const chainId = useChainId();
const { switchChainAsync } = useSwitchChain();

const handleChange = async (event: React.ChangeEvent<HTMLSelectElement>) => {
const targetId = Number(event.target.value);
const targetChain = CHAINS.find((c) => c.id === targetId);
if (!targetChain) return;

try {
// Wait for chain switch to complete
await switchChainAsync({ chainId: targetChain.id });

// Hard reload to reset all React state / caches
window.location.reload();
} catch (err) {
console.error("Failed to switch chain", err);
}
};

return (
<select
value={chainId}
onChange={handleChange}
className={styles.networkSelect}
>
{CHAINS.map((chain) => (
<option key={chain.id} value={chain.id}>
{chain.name}
</option>
))}
</select>
);
}
64 changes: 41 additions & 23 deletions apps/web/src/config/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// apps/web/src/config/sdk.ts
import type { Address } from "viem";
// Source de vérité: SDK (pas le wallet)
import { INTUITION, addresses as SDK_ADDRESSES } from "@trustswap/sdk";
import {
INTUITION,
INTUITION_MAINNET,
INTUITION_TESTNET,
getAddresses,
} from "@trustswap/sdk";

// --- Types "côté app" (normalisés) ---
export type ProtocolAddresses = {
ROUTER02: Address;
FACTORY: Address;
WNATIVE: Address;
// (optionnel) expose aussi ce dont tu as besoin dans l'app:
TSWP?: Address;
SRF?: Address; // StakingRewardsFactory si tu l'as
SRF?: Address;
};

export type ProtocolSymbols = {
Expand All @@ -19,51 +22,66 @@ export type ProtocolSymbols = {
};

// --- Choix du chainId app ---
// Priorité à l'ENV si tu veux override, sinon SDK
const APP_CHAIN_ID = Number(import.meta.env.VITE_CHAIN_ID || INTUITION.id);
// ENV > sinon on prend le chain du SDK (INTUITION = "courant")
const APP_CHAIN_ID =
Number(import.meta.env.VITE_CHAIN_ID || INTUITION.id);

// --- Adaptateur: mappe les noms du SDK vers tes noms normalisés ---
function normalizeSdkAddresses(a: any): ProtocolAddresses {
// Adapte ces clés selon ce que ton SDK expose exactement
return {
ROUTER02: (a.UniswapV2Router02 ?? a.ROUTER02) as Address,
FACTORY: (a.UniswapV2Factory ?? a.FACTORY) as Address,
WNATIVE: (a.WTTRUST ?? a.WNATIVE ?? a.WETH9) as Address,
TSWP: a.TSWP as Address,
SRF: (a.SRF ?? a.StakingRewardsFactory ?? a.StakingRewardsFactoryV2) as Address,
FACTORY: (a.UniswapV2Factory ?? a.FACTORY) as Address,
// wrapped: WTRUST sur mainnet, WTTRUST sur testnet, WNATIVE/WETH9 en fallback
WNATIVE: (a.WTRUST ?? a.WTTRUST ?? a.WNATIVE ?? a.WETH9) as Address,
TSWP: a.TSWP as Address,
SRF: (a.SRF ?? a.StakingRewardsFactory ?? a.StakingRewardsFactoryV2) as Address,
};
}

// Si ton SDK n'est pas multi-chain, on normalise directement l'objet plat:
const FROM_SDK: ProtocolAddresses = normalizeSdkAddresses(SDK_ADDRESSES);

// Fallbacks (utile si le SDK n'est pas dispo / dev offline)
// Fallbacks explicites si jamais getAddresses ne connaît pas encore la chain
const FALLBACK_ADDRESSES: Record<number, ProtocolAddresses> = {
13579: {
// 🔹 Intuition Testnet
[INTUITION_TESTNET.id]: {
ROUTER02: "0xAc1218b429E2BB26f5FFe635F04F7412ac40979c" as Address,
FACTORY: "0xd103E057242881214793d5A1A7c2A5B84731c75c" as Address,
WNATIVE: "0x51379Cc2C942EE2AE2fF0BD67a7b475F0be39Dcf" as Address,
TSWP: "0x7da120065e104C085fAc6f800d257a6296549cF3" as Address,
// SRF: "0x819030e047cB49E9F68599433FeC5A7C32B41565" as Address, // si besoin
},

// 🔹 Intuition Mainnet
[INTUITION_MAINNET.id]: {
ROUTER02: "0x5123208Aa3C6A37615327a8c479a5e1654c0200E" as Address,
FACTORY: "0x83E9f4E539eb343F7F67d130a484c8a1b6555458" as Address,
WNATIVE: "0x81cFb09cb44f7184Ad934C09F82000701A4bF672" as Address, // WTRUST
// TSWP: "0x...." as Address, // quand tu le lances
},
};

// Symboles (depuis le SDK + override)
// Symboles (depuis le SDK + override par chain)
const FALLBACK_SYMBOLS: Record<number, ProtocolSymbols> = {
13579: {
NATIVE_SYMBOL: INTUITION.nativeCurrency.symbol || "tTRUST",
[INTUITION_TESTNET.id]: {
NATIVE_SYMBOL: INTUITION_TESTNET.nativeCurrency.symbol || "tTRUST",
WRAPPED_SYMBOL: "WTTRUST",
},
[INTUITION_MAINNET.id]: {
NATIVE_SYMBOL: INTUITION_MAINNET.nativeCurrency.symbol || "TRUST",
WRAPPED_SYMBOL: "WTRUST",
},
};

// --- API exportée par le module ---
export function getProtocolConfig() {
let addrs: ProtocolAddresses | undefined = FROM_SDK;
let addrs: ProtocolAddresses | undefined;

if (!addrs?.ROUTER02 || !addrs?.FACTORY || !addrs?.WNATIVE) {
try {
const sdkAddrs = getAddresses(APP_CHAIN_ID);
addrs = normalizeSdkAddresses(sdkAddrs);
} catch {
// si le SDK ne connaît pas encore la chain -> fallback local
addrs = FALLBACK_ADDRESSES[APP_CHAIN_ID];
}
if (!addrs) {

if (!addrs?.ROUTER02 || !addrs?.FACTORY || !addrs?.WNATIVE) {
throw new Error(`Aucune config protocole pour chainId=${APP_CHAIN_ID}`);
}

Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/features/pool/components/PoolRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { Volume1DCell } from "./cells/Volume1DCell";
import { PoolAprCell } from "./cells/PoolAprCell";
import { PoolActionsCell } from "./cells/PoolActionsCell";
import styles from "../tableau.module.css";

import { WNATIVE_ADDRESS } from "../../../lib/tokens";
import { useTokenModule } from "../../../hooks/useTokenModule";

function asUIToken<T extends { address: string; symbol: string; decimals?: number }>(t: T): T {
const { WNATIVE_ADDRESS } = useTokenModule();
const isWNative = t?.address?.toLowerCase() === WNATIVE_ADDRESS.toLowerCase();
if (!isWNative) return t;
return { ...t, symbol: "tTRUST" } as T;
Expand Down Expand Up @@ -49,7 +49,7 @@ export function PoolRow({
>
<IndexCell index={index} loading={loading} />

{/* Display the tokens UI (symbol tTRUST if WTTRUST) */}
{/* Display the tokens UI (symbol tTRUST if WTRUST) */}
<PoolCell token0={uiToken0} token1={uiToken1} pair={pool.pair} loading={loading} />

{/* Pass also the UI tokens if needed (if TvlCell displays the symbols somewhere) */}
Expand Down
14 changes: 12 additions & 2 deletions apps/web/src/features/pool/components/PoolsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ import { PoolsTable } from "./PoolsTable";
import { PoolsFilters } from "./filters/PoolsFilters";
import { PoolsPagination } from "./filters/PoolsPagination";
import { LiquidityModal } from "./liquidity/LiquidityModal";
import { toUIAddress } from "../../../lib/tokens";
import { useTokenModule } from "../../../hooks/useTokenModule";

import styles from "../pools.module.css";



export default function PoolsPage() {

const [page, setPage] = useState(1);
const [query, setQuery] = useState("");

const [hasNextPage, setHasNextPage] = useState(false);

const [isOpen, setIsOpen] = useState(false);
const [tokenA, setTokenA] = useState<Address | undefined>();
const [tokenB, setTokenB] = useState<Address | undefined>();
const { toUIAddress } = useTokenModule();

const pc = usePublicClient({ chainId: 13579 });

Expand Down Expand Up @@ -88,8 +92,14 @@ export default function PoolsPage() {
page={page}
query={query}
onOpenLiquidity={openWithPair}
onPageInfoChange={(info) => setHasNextPage(info.hasNextPage)}
/>

<PoolsPagination
page={page}
hasNextPage={hasNextPage}
onPage={onPageChange}
/>
<PoolsPagination page={page} onPage={onPageChange} />
</>
)}

Expand Down
18 changes: 15 additions & 3 deletions apps/web/src/features/pool/components/PoolsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// apps/web/src/features/pools/components/PoolsTable.tsx
import { useMemo } from "react";
import { useMemo, useEffect } from "react";
import type { Address } from "viem";

import { usePoolsData } from "../hooks/usePoolsData";
Expand All @@ -17,14 +17,24 @@ export function PoolsTable({
page,
query,
onOpenLiquidity,
onPageInfoChange,
}: {
page: number;
query: string;
onOpenLiquidity: (a: Address, b: Address) => void;
onPageInfoChange?: (info: { hasNextPage: boolean }) => void;
}) {
const pageSize = 10;
const pageSize = 8;
const { items, loading, error } = usePoolsData(pageSize, (page - 1) * pageSize);

useEffect(() => {
if (!onPageInfoChange) return;
if (loading || error) return;

// Si on a une page "pleine", il y a potentiellement une page suivante
onPageInfoChange({ hasNextPage: items.length === pageSize });
}, [items.length, loading, error, onPageInfoChange]);

const skeletonPool: PoolItem = {
pair: "0x0000000000000000000000000000000000000000",
token0: { symbol: "", address: "" as `0x${string}`, decimals: 18 },
Expand Down Expand Up @@ -72,7 +82,9 @@ export function PoolsTable({
);
}

if (!items.length) return <div>Aucune pool</div>;
if (!items.length)
return <div className={styles.centerMessage}>No pools available</div>;


return (
<PoolsTableInner
Expand Down
17 changes: 10 additions & 7 deletions apps/web/src/features/pool/components/filters/PoolsPagination.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// PoolsPagination.tsx
import styles from "../../tableau.module.css";

export function PoolsPagination({
page,
totalPages,
hasNextPage,
onPage,
}: {
page: number;
totalPages: number;
hasNextPage: boolean;
onPage: (p: number) => void;
}) {
if (totalPages <= 1) return null;
if (page === 1 && !hasNextPage) return null;

return (
<div className={styles.pagination}>
Expand All @@ -18,10 +19,12 @@ export function PoolsPagination({
Prev
</button>
)}
<span>Page {page}</span>
{page < totalPages && (
<button onClick={() => onPage(page + 1)}>Next</button>
<span>{page}</span>
{hasNextPage && (
<button onClick={() => onPage(page + 1)}>
Next
</button>
)}
</div>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import type { Address } from "viem";
import { parseUnits } from "viem";
import { useAccount, usePublicClient } from "wagmi";
import { useLiquidityActions } from "../../hooks/useLiquidityActions";
import { toWrapped } from "../../../../lib/tokens";
import { getTokenIcon } from "../../../../lib/getTokenIcon";
import styles from "../../modal.module.css";
import TokenField from "../../../swap/components/TokenField";
import { quoteOutFromReserves } from "../../../../utils/quotes";
import { abi, addresses } from "@trustswap/sdk";
import { isZeroAddress } from "../../../../lib/erc20Read";
import { useErc20Read } from "../../../../lib/erc20Read";
import { useTokenModule } from "../../../../hooks/useTokenModule";


type PairData = {
pair: Address;
Expand All @@ -34,6 +35,8 @@ export function AddLiquidityDrawer({
}) {
const { address: to } = useAccount();
const pc = usePublicClient();
const { toWrapped } = useTokenModule();
const { isZeroAddress } = useErc20Read();
const { addLiquidity } = useLiquidityActions();

const [tokenIn, setTokenIn] = useState<Address | undefined>(tokenA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { formatUnits, parseUnits } from "viem";
import styles from "../../modal.module.css";
import { clampDecimalsForInput, tidyOnBlur } from "../../../../utils/number";
import { useLiquidityActions } from "../../hooks/useLiquidityActions";
import { toWrapped } from "../../../../lib/tokens";
import { useTokenModule } from "../../../../hooks/useTokenModule";

import { getTokenIcon } from "../../../../lib/getTokenIcon";
import { useLpPosition } from "../../hooks/useLpPosition";
import { fmtUnits, formatAmountStr } from "../../utils";
Expand All @@ -29,6 +30,8 @@ export function RemoveLiquidityDrawer({

const [lpAmount, setLpAmount] = useState("");
const [lpRawOverride, setLpRawOverride] = useState<bigint | null>(null);
const { toWrapped } = useTokenModule();


// Position LP réelle
const {
Expand Down
Loading
Loading