import { Sly } from '@sly_ai/sdk';
const sly = new Sly({ apiKey: process.env.SLY_API_KEY });
async function sendWithRetries(opts, maxAttempts = 3) {
const idempotencyKey = opts.idempotencyKey ?? `tx-${opts.orderId}`;
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
try {
return await sly.transfers.create({ ...opts, idempotencyKey });
} catch (e) {
if (attempt === maxAttempts) throw e;
if (!['UPSTREAM_TIMEOUT', 'RATE_LIMIT_EXCEEDED', 'INTERNAL_ERROR'].includes(e.code)) throw e;
await new Promise(r => setTimeout(r, 500 * 2 ** attempt));
}
}
}
const result = await sendWithRetries({
type: 'internal',
from_wallet_id: 'wal_src',
to_wallet_id: 'wal_dst',
amount: '100.00',
currency: 'USDC',
orderId: 'ord_abc',
});