Skip to content
Open
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
49 changes: 49 additions & 0 deletions .github/workflows/ci-limits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Transfer Limit Tests

on:
workflow_dispatch:
pull_request:
branches: [master]
paths:
- "apps/*/package.json"
- "apps/*/src/runtime.ts"
- "chains.config.json"
- "package.json"
- "packages/fast-bridge-app/src/components/common/utils/transfer-limits.ts"
- "packages/fast-bridge-app/src/components/common/hooks/use-transaction-flow.ts"
- "packages/fast-bridge-app/src/components/common/hooks/use-usd-max-amount.ts"
- "packages/fast-bridge-app/src/types/runtime.ts"
- "pnpm-lock.yaml"
- "tests/**"
- "vitest.config.ts"
push:
branches: [master]
paths:
- "apps/*/package.json"
- "apps/*/src/runtime.ts"
- "chains.config.json"
- "package.json"
- "packages/fast-bridge-app/src/components/common/utils/transfer-limits.ts"
- "packages/fast-bridge-app/src/components/common/hooks/use-transaction-flow.ts"
- "packages/fast-bridge-app/src/components/common/hooks/use-usd-max-amount.ts"
- "packages/fast-bridge-app/src/types/runtime.ts"
- "pnpm-lock.yaml"
- "tests/**"
- "vitest.config.ts"

jobs:
test-limits:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm

- run: pnpm install --frozen-lockfile

- run: pnpm test
2 changes: 1 addition & 1 deletion apps/citrea/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"preview": "vite preview --port 5173"
},
"dependencies": {
"@avail-project/nexus-core": "github:availproject/nexus-sdk#f8851ba2e3307b2cedc71c67f3365a31eb34f039",
"@avail-project/nexus-core": "1.2.0",
"@radix-ui/react-accordion": "^1.2.12",
"@radix-ui/react-checkbox": "^1.3.3",
"@radix-ui/react-dialog": "^1.1.15",
Expand Down
2 changes: 1 addition & 1 deletion apps/megaeth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"preview": "vite preview --port 5173"
},
"dependencies": {
"@avail-project/nexus-core": "github:availproject/nexus-sdk#f8851ba2e3307b2cedc71c67f3365a31eb34f039",
"@avail-project/nexus-core": "1.2.0",
"@radix-ui/react-accordion": "^1.2.12",
"@radix-ui/react-checkbox": "^1.3.3",
"@radix-ui/react-dialog": "^1.1.15",
Expand Down
2 changes: 1 addition & 1 deletion apps/monad/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"preview": "vite preview --port 5173"
},
"dependencies": {
"@avail-project/nexus-core": "github:availproject/nexus-sdk#f8851ba2e3307b2cedc71c67f3365a31eb34f039",
"@avail-project/nexus-core": "1.2.0",
"@radix-ui/react-accordion": "^1.2.12",
"@radix-ui/react-checkbox": "^1.3.3",
"@radix-ui/react-dialog": "^1.1.15",
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@
"check": "ultracite check",
"fix": "ultracite fix",
"precommit:fix-staged": "node scripts/precommit-fix-staged.mjs",
"prepare": "husky"
"prepare": "husky",
"test": "vitest run"
},
"packageManager": "pnpm@9.0.0",
"devDependencies": {
"@biomejs/biome": "2.4.0",
"@types/react": "^19.1.13",
"@types/react-dom": "^19.1.9",
"@types/react-test-renderer": "^19.1.0",
"husky": "^9.1.7",
"react-test-renderer": "19.2.2",
"turbo": "^2.7.5",
"typescript": "~5.8.3",
"ultracite": "7.2.3"
"ultracite": "7.2.3",
"vitest": "^3.2.1"
},
"dependencies": {
"@reown/appkit": "^1.8.19",
Expand Down
2 changes: 1 addition & 1 deletion packages/fast-bridge-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"type": "module",
"dependencies": {
"@avail-project/nexus-core": "github:availproject/nexus-sdk#14928bd575e00439c54a2ac9f4ed4ede3d50af24",
"@avail-project/nexus-core": "1.2.0",
"@radix-ui/react-accordion": "^1.2.12",
"@radix-ui/react-checkbox": "^1.3.3",
"@radix-ui/react-dialog": "^1.1.15",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
getCoverageDecimals,
MAX_AMOUNT_DEBOUNCE_MS,
} from "../utils/transaction-flow";
import { resolveUsdLimitForDestination } from "../utils/transfer-limits";
import { useDebouncedCallback } from "./use-debounced-callback";
import { useNexusError } from "./use-nexus-error";
import { usePolling } from "./use-polling";
Expand Down Expand Up @@ -182,23 +183,15 @@ export function useTransactionFlow(props: UseTransactionFlowProps) {
} = useTransactionSteps<BridgeStepType>();
// Resolve the USD dollar limit for the current destination chain.
// maxAmount and maxAmountByDestinationChainId values are treated as USD.
const usdLimitForDest = useMemo(() => {
if (
maxAmountByDestinationChainId &&
inputs?.chain !== undefined &&
inputs?.chain !== null
) {
const override = maxAmountByDestinationChainId[inputs.chain];
if (override !== undefined) {
return override;
}
}
if (maxAmount === undefined || maxAmount === null) {
return undefined;
}
const parsed = Number(maxAmount);
return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;
}, [maxAmount, maxAmountByDestinationChainId, inputs?.chain]);
const usdLimitForDest = useMemo(
() =>
resolveUsdLimitForDestination({
defaultMaxAmount: maxAmount,
destinationChainId: inputs?.chain,
maxAmountByDestinationChainId,
}),
[maxAmount, maxAmountByDestinationChainId, inputs?.chain]
);

// Convert the USD limit to a token-unit string using live pricing.
// For stablecoins (USDC/USDT/USDM) this is 1:1; for ETH it fetches the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export const resolveUsdLimitForDestination = ({
defaultMaxAmount,
destinationChainId,
maxAmountByDestinationChainId,
}: {
defaultMaxAmount?: string | number;
destinationChainId?: number | null;
maxAmountByDestinationChainId?: Record<number, number>;
}): number | undefined => {
if (
maxAmountByDestinationChainId &&
destinationChainId !== undefined &&
destinationChainId !== null
) {
const override = maxAmountByDestinationChainId[destinationChainId];
if (override !== undefined) {
return override;
}
}

if (defaultMaxAmount === undefined || defaultMaxAmount === null) {
return undefined;
}

const parsedMaxAmount = Number(defaultMaxAmount);
return Number.isFinite(parsedMaxAmount) && parsedMaxAmount > 0
? parsedMaxAmount
: undefined;
};
21 changes: 11 additions & 10 deletions packages/fast-bridge-app/src/components/fast-bridge/fast-bridge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { toast } from "sonner";
import type { Address } from "viem";
import { useWalletClient } from "wagmi";
import { useUsdMaxAmount } from "../common/hooks/use-usd-max-amount";
import { resolveUsdLimitForDestination } from "../common/utils/transfer-limits";
import { useNexus } from "../nexus/nexus-provider";
import { Button } from "../ui/button";
import { Card, CardContent } from "../ui/card";
Expand Down Expand Up @@ -319,16 +320,16 @@ function FastBridge({

// Resolve the USD dollar limit for the currently selected destination chain.
const selectedChain = inputs?.chain;
const usdLimitForDest = useMemo(() => {
const perDestMap = chainFeatures.maxBridgeAmountByDestinationChainId;
if (perDestMap && selectedChain !== undefined && selectedChain !== null) {
const override = perDestMap[selectedChain];
if (override !== undefined) {
return override;
}
}
return chainFeatures.maxBridgeAmount;
}, [selectedChain]);
const usdLimitForDest = useMemo(
() =>
resolveUsdLimitForDestination({
defaultMaxAmount: chainFeatures.maxBridgeAmount,
destinationChainId: selectedChain,
maxAmountByDestinationChainId:
chainFeatures.maxBridgeAmountByDestinationChainId,
}),
[selectedChain]
);

// Convert the USD limit to a token-unit string for UI gating (button
// disabled, AmountInput maxAmount). Undefined while price loads for
Expand Down
Loading
Loading