Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.kynesys.xyz/llms.txt

Use this file to discover all available pages before exploring further.

Crosschain SWAP

RubicBridge is a thin SDK client for the node-side Rubic bridge integration. It exposes two methods — getTrade for quoting a swap, and executeTrade for committing it — both of which proxy through the connected DEMOS RPC.

How to SWAP from one chain to another

1. Connect to the network

import { Demos, RubicBridge } from "@kynesyslabs/demosdk/websdk"
import {
    BridgeTradePayload,
    SupportedChains,
} from "@kynesyslabs/demosdk/bridge"

const rpc = "https://node2.demos.sh"
const demos = new Demos()
await demos.connect(rpc)
await demos.connectWallet(mnemonic)

2. Create a RubicBridge instance

RubicBridge is stateless — there are no constructor arguments. The chain and payload are passed per call.
const bridge = new RubicBridge()

3. Build the trade payload

BridgeTradePayload.amount and the chain IDs refer to the source chain’s native units, not Demos OS. For example, an EVM swap of 10 USDT uses amount: 10 because Rubic itself handles the on-chain decimal conversion.
// Swap 10 USDT from Polygon (chain 137) to Ethereum (chain 1).
const payload: BridgeTradePayload = {
    fromToken: "USDT",
    toToken: "USDT",
    amount: 10,
    fromChainId: 137,
    toChainId: 1,
}
Valid fromToken / toToken values are "NATIVE", "USDC", and "USDT". "NATIVE" refers to the source chain’s native token (e.g. ETH on Ethereum, MATIC on Polygon) — not Demos DEM. SupportedChains is exported as a string-valued object with these keys:
export const SupportedChains = {
    ETH: "ETH",
    POLYGON: "POLYGON",
    BSC: "BSC",
    AVALANCHE: "AVALANCHE",
    OPTIMISM: "OPTIMISM",
    ARBITRUM: "ARBITRUM",
    LINEA: "LINEA",
    BASE: "BASE",
    SOLANA: "SOLANA",
}
The first argument to getTrade / executeTrade is the source chain key (SupportedChains.POLYGON in this example).

4. Quote the trade

const trade = await bridge.getTrade(
    demos,
    SupportedChains.POLYGON,
    payload,
)
getTrade returns the standard RPCResponse. Inspect trade.response for the quoted route and pricing before committing.

5. Execute the trade

If the quote looks good, commit the swap with executeTrade. The same payload is passed — there is no separate “trade object” to forward.
const receipt = await bridge.executeTrade(
    demos,
    SupportedChains.POLYGON,
    payload,
)
The result wraps the source-chain transaction hash, e.g.
"0x2342692074a7484f3ac9713d36cd23fdc1c51810d03639e5cf651bfefb62fdc3"
PolygonScan
For local development against an unfunded source chain, RubicBridge.executeMockTrade(demos, chain, wrappedTrade) accepts a WrappedCrossChainTrade (from rubic-sdk) and exercises the same RPC path without broadcasting on the foreign chain.