Add Z Bank mainnet payment presets
This commit is contained in:
@@ -26,6 +26,8 @@ export async function fetchRoutePlan(body: {
|
||||
amountIn: string;
|
||||
recipient?: string;
|
||||
maxSlippageBps?: number;
|
||||
allowBridge?: boolean;
|
||||
preferredBridges?: string[];
|
||||
}) {
|
||||
const { data } = await axios.post(
|
||||
`${tokenAggUrl()}/api/v2/routes/plan`,
|
||||
@@ -36,7 +38,11 @@ export async function fetchRoutePlan(body: {
|
||||
tokenOut: body.tokenOut,
|
||||
amountIn: body.amountIn,
|
||||
recipient: body.recipient,
|
||||
constraints: { maxSlippageBps: body.maxSlippageBps ?? 50, allowBridge: false },
|
||||
constraints: {
|
||||
maxSlippageBps: body.maxSlippageBps ?? 50,
|
||||
allowBridge: body.allowBridge ?? false,
|
||||
preferredBridges: body.preferredBridges,
|
||||
},
|
||||
},
|
||||
{ timeout: 120000 },
|
||||
);
|
||||
@@ -51,6 +57,8 @@ export async function fetchExecutionPlan(body: {
|
||||
amountIn: string;
|
||||
recipient: string;
|
||||
maxSlippageBps?: number;
|
||||
allowBridge?: boolean;
|
||||
preferredBridges?: string[];
|
||||
}) {
|
||||
const { data } = await axios.post(
|
||||
`${tokenAggUrl()}/api/v2/routes/internal-execution-plan`,
|
||||
@@ -61,7 +69,11 @@ export async function fetchExecutionPlan(body: {
|
||||
tokenOut: body.tokenOut,
|
||||
amountIn: body.amountIn,
|
||||
recipient: body.recipient,
|
||||
constraints: { maxSlippageBps: body.maxSlippageBps ?? 50, allowBridge: false },
|
||||
constraints: {
|
||||
maxSlippageBps: body.maxSlippageBps ?? 50,
|
||||
allowBridge: body.allowBridge ?? false,
|
||||
preferredBridges: body.preferredBridges,
|
||||
},
|
||||
},
|
||||
{ timeout: 120000 },
|
||||
);
|
||||
|
||||
@@ -106,19 +106,32 @@ export function createExchangeRouter(): Router {
|
||||
router.post('/plan', async (req, res) => {
|
||||
if (!requireTrade(req, res)) return;
|
||||
try {
|
||||
const { tokenIn, tokenOut, amountIn, recipient, maxSlippageBps } = req.body as Record<string, unknown>;
|
||||
const {
|
||||
tokenIn,
|
||||
tokenOut,
|
||||
amountIn,
|
||||
recipient,
|
||||
maxSlippageBps,
|
||||
destinationChainId,
|
||||
allowBridge,
|
||||
preferredBridges,
|
||||
} = req.body as Record<string, unknown>;
|
||||
if (!tokenIn || !tokenOut || !amountIn) {
|
||||
res.status(400).json({ error: 'tokenIn, tokenOut, amountIn required' });
|
||||
return;
|
||||
}
|
||||
const plan = await fetchRoutePlan({
|
||||
sourceChainId: cfg.chainId,
|
||||
destinationChainId: cfg.chainId,
|
||||
destinationChainId: destinationChainId ? Number(destinationChainId) : cfg.chainId,
|
||||
tokenIn: String(tokenIn),
|
||||
tokenOut: String(tokenOut),
|
||||
amountIn: String(amountIn),
|
||||
recipient: recipient ? String(recipient) : undefined,
|
||||
maxSlippageBps: maxSlippageBps ? Number(maxSlippageBps) : cfg.defaultSlippageBps,
|
||||
allowBridge: typeof allowBridge === 'boolean' ? allowBridge : undefined,
|
||||
preferredBridges: Array.isArray(preferredBridges)
|
||||
? preferredBridges.map((value) => String(value))
|
||||
: undefined,
|
||||
});
|
||||
res.json(plan);
|
||||
} catch (e) {
|
||||
@@ -129,19 +142,32 @@ export function createExchangeRouter(): Router {
|
||||
router.post('/execute-plan', async (req, res) => {
|
||||
if (!requireTrade(req, res)) return;
|
||||
try {
|
||||
const { tokenIn, tokenOut, amountIn, recipient, maxSlippageBps } = req.body as Record<string, unknown>;
|
||||
const {
|
||||
tokenIn,
|
||||
tokenOut,
|
||||
amountIn,
|
||||
recipient,
|
||||
maxSlippageBps,
|
||||
destinationChainId,
|
||||
allowBridge,
|
||||
preferredBridges,
|
||||
} = req.body as Record<string, unknown>;
|
||||
if (!tokenIn || !tokenOut || !amountIn || !recipient) {
|
||||
res.status(400).json({ error: 'tokenIn, tokenOut, amountIn, recipient required' });
|
||||
return;
|
||||
}
|
||||
const plan = await fetchExecutionPlan({
|
||||
sourceChainId: cfg.chainId,
|
||||
destinationChainId: cfg.chainId,
|
||||
destinationChainId: destinationChainId ? Number(destinationChainId) : cfg.chainId,
|
||||
tokenIn: String(tokenIn),
|
||||
tokenOut: String(tokenOut),
|
||||
amountIn: String(amountIn),
|
||||
recipient: String(recipient),
|
||||
maxSlippageBps: maxSlippageBps ? Number(maxSlippageBps) : cfg.defaultSlippageBps,
|
||||
allowBridge: typeof allowBridge === 'boolean' ? allowBridge : undefined,
|
||||
preferredBridges: Array.isArray(preferredBridges)
|
||||
? preferredBridges.map((value) => String(value))
|
||||
: undefined,
|
||||
});
|
||||
res.json(plan);
|
||||
} catch (e) {
|
||||
|
||||
@@ -224,6 +224,8 @@ export function createSettlementRouter(): Router {
|
||||
targetChainId: body.convertToCrypto?.targetChainId ?? 138,
|
||||
tokenLineId: body.convertToCrypto?.tokenLineId ?? `${body.currency ?? 'USD'}-M2`,
|
||||
recipientAddress: body.convertToCrypto?.recipientAddress ?? '',
|
||||
symbol: body.convertToCrypto?.symbol,
|
||||
tokenAddress: body.convertToCrypto?.tokenAddress,
|
||||
},
|
||||
moneyLayers: ['M2', 'M3'],
|
||||
});
|
||||
|
||||
@@ -160,6 +160,8 @@ export async function processExternalTransfer(
|
||||
recipient: req.convertToCrypto.recipientAddress,
|
||||
settlementRef: record.settlementId,
|
||||
dryRun: !cfg.production.allowChainMintExecute,
|
||||
symbol: req.convertToCrypto.symbol,
|
||||
tokenAddress: req.convertToCrypto.tokenAddress,
|
||||
});
|
||||
advance('CHAIN_MINT_REQUESTED', { chainTxHash: mint.txHash });
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user