import { EnsoClient } from "@ensofinance/sdk";
import { parseUnits } from "viem";
// Chain IDs
const HYPERLIQUID_ID = 999;
const PLASMA_ID = 9745;
// Common addresses
const WALLET_ADDRESS = "0x826e0BB2276271eFdF2a500597f37b94f6c153bA";
// Token addresses on Hyperliquid
const chUSD_HYPE = "0x2222227d90046F1483B3Fb37990DEA31FCaBea02";
// Token addresses on Plasma
const chUSD_PLASMA = "0x22222215d4EdC5510d23D0886133E7ece7F5fdC1";
const schUSD_PLASMA = "0x888888bAb58A7bd3068110749BC7B63B62CE874d";
// Pool addresses (from LayerZero API)
const chUSD_POOL_HYPE_TO_PLASMA = "0x2222227d90046F1483B3Fb37990DEA31FCaBea02";
const schUSD_POOL_PLASMA_TO_HYPE = "0x8888883ACA65976e98E16931b46308E4C588D533";
const client = new EnsoClient({
apiKey: process.env.ENSO_API_KEY!,
});
// Or fetch pools dynamically:
// const chUsdPools = await client.getLayerZeroPool({
// chainId: HYPERLIQUID_ID,
// token: chUSD_HYPE,
// destinationChainId: PLASMA_ID + "",
// });
const bundle = await client.getBundleData(
{
chainId: HYPERLIQUID_ID,
fromAddress: WALLET_ADDRESS,
routingStrategy: "router",
},
[
{
protocol: "stargate",
action: "bridge",
args: {
primaryAddress: chUSD_POOL_HYPE_TO_PLASMA,
destinationChainId: PLASMA_ID,
tokenIn: chUSD_HYPE,
amountIn: parseUnits("1", 18).toString(), // 1 chUSD
receiver: WALLET_ADDRESS,
callback: [
// Step 1: Check chUSD balance on Plasma
{
protocol: "enso",
action: "balance",
args: {
token: chUSD_PLASMA,
},
},
// Step 2: Swap chUSD to schUSD on Plasma
{
protocol: "enso",
action: "route",
args: {
slippage: "50", // 0.5%
tokenIn: chUSD_PLASMA,
tokenOut: schUSD_PLASMA,
amountIn: { useOutputOfCallAt: 0 },
},
},
// Step 3: Bridge schUSD back to Hyperliquid
{
protocol: "stargate",
action: "bridge",
args: {
primaryAddress: schUSD_POOL_PLASMA_TO_HYPE,
destinationChainId: HYPERLIQUID_ID,
tokenIn: schUSD_PLASMA,
amountIn: { useOutputOfCallAt: 1 },
receiver: WALLET_ADDRESS,
// Final destination - no callback needed
},
},
],
},
},
]
);
return bundle;