Files
proxmox/multi-chain-execution/src/api/route-routes.ts
defiQUG fbda1b4beb
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
docs: Ledger Live integration, contract deploy learnings, NEXT_STEPS updates
- ADD_CHAIN138_TO_LEDGER_LIVE: Ledger form done; public code review repo bis-innovations/LedgerLive; init/push commands
- CONTRACT_DEPLOYMENT_RUNBOOK: Chain 138 gas price 1 gwei, 36-addr check, TransactionMirror workaround
- CONTRACT_*: AddressMapper, MirrorManager deployed 2026-02-12; 36-address on-chain check
- NEXT_STEPS_FOR_YOU: Ledger done; steps completable now (no LAN); run-completable-tasks-from-anywhere
- MASTER_INDEX, OPERATOR_OPTIONAL, SMART_CONTRACTS_INVENTORY_SIMPLE: updates
- LEDGER_BLOCKCHAIN_INTEGRATION_COMPLETE: bis-innovations/LedgerLive reference

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 15:46:57 -08:00

90 lines
3.4 KiB
TypeScript

/**
* Chain138 -> Tezos USDtz route planning API
*/
import { Router, Request, Response } from 'express';
const TEZOS_REGEX = /^(tz[1-4]|KT1)[1-9A-HJ-NP-Za-km-z]{33}$/;
const CHAIN_138 = 138;
const CHAIN_ALL_MAINNET = 651940;
const CUSDC = '0xf22258f57794CC8E06237084b353Ab30fFfa640b';
const AUSDC = '0xa95EeD79f84E6A0151eaEb9d441F9Ffd50e8e881';
/** Active ETH→Tezos bridge (from bridge-capability-matrix) */
const ETH_TO_TEZOS_PROVIDER = 'Wrap Protocol';
interface RoutePlanRequest {
source_chain_id?: number;
source_asset?: string;
source_amount?: string;
destination_tezos_address?: string;
max_slippage_bps?: number;
max_total_fees?: string;
prefer_non_custodial?: boolean;
}
interface RouteHop {
chain: string;
action: string;
protocol: string;
asset_in: string;
amount_in: string;
asset_out: string;
min_amount_out: string;
estimated_fees: string;
}
interface RoutePlan {
route_id: string;
hops: RouteHop[];
totalEstimatedFees: string;
estimatedTimeSeconds: number;
}
const router: Router = Router();
router.post('/v1/routes/chain138-to-usdtz', (req: Request, res: Response) => {
try {
const body = req.body as RoutePlanRequest;
const sourceChainId = body.source_chain_id ?? 138;
const sourceAsset = body.source_asset ?? CUSDC;
const sourceAmount = body.source_amount ?? '0';
const destAddr = body.destination_tezos_address ?? '';
if (sourceChainId !== CHAIN_138 && sourceChainId !== CHAIN_ALL_MAINNET) {
return res.status(400).json({ valid: false, error: 'Only source_chain_id=138 (Chain138) or 651940 (ALL Mainnet) is supported' });
}
if (!destAddr.trim() || !TEZOS_REGEX.test(destAddr.trim())) {
return res.status(400).json({ valid: false, error: 'Invalid destination_tezos_address' });
}
const amount = BigInt(sourceAmount);
if (amount <= 0n) {
return res.status(400).json({ valid: false, error: 'source_amount must be > 0' });
}
const routeId = `route-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
const isChain138 = sourceChainId === CHAIN_138;
const sourceLabel = isChain138 ? 'CHAIN138' : 'ALL_MAINNET';
const stableOut = isChain138 ? CUSDC : AUSDC;
const srcBridge = isChain138 ? 'CCIP' : 'AlltraAdapter';
const hops: RouteHop[] = [
{ chain: sourceLabel, action: 'SWAP', protocol: isChain138 ? 'EnhancedSwapRouter' : 'AlltraDEX', asset_in: sourceAsset, amount_in: sourceAmount, asset_out: stableOut, min_amount_out: sourceAmount, estimated_fees: '0' },
{ chain: sourceLabel, action: 'BRIDGE', protocol: srcBridge, asset_in: stableOut, amount_in: sourceAmount, asset_out: 'USDC', min_amount_out: sourceAmount, estimated_fees: '0' },
{ chain: 'HUB_EVM', action: 'BRIDGE', protocol: ETH_TO_TEZOS_PROVIDER, asset_in: 'USDC', amount_in: sourceAmount, asset_out: 'USDC', min_amount_out: sourceAmount, estimated_fees: '0' },
{ chain: 'TEZOS', action: 'SWAP', protocol: 'Plenty', asset_in: 'USDC', amount_in: sourceAmount, asset_out: 'USDtz', min_amount_out: sourceAmount, estimated_fees: '0' },
];
const plan: RoutePlan = {
route_id: routeId,
hops,
totalEstimatedFees: '0',
estimatedTimeSeconds: 1800,
};
res.status(200).json({ valid: true, routes: [plan] });
} catch (e) {
res.status(500).json({ valid: false, error: e instanceof Error ? e.message : 'Internal error' });
}
});
export default router;