nexus-sdk-swap-flows
9
总安装量
4
周安装量
#32280
全站排名
安装命令
npx skills add https://github.com/availproject/nexus-sdk --skill nexus-sdk-swap-flows
Agent 安装分布
opencode
3
codex
3
claude-code
3
gemini-cli
3
replit
2
amp
2
Skill 文档
Swap Flows
Call swapWithExactIn(input, options?)
- Use when input amount is fixed and sources are known.
- Signature:
sdk.swapWithExactIn(input, { onEvent? })
- Params (
ExactInSwapInput):from: { chainId: number; amount: bigint; tokenAddress: Hex }[]toChainId: numbertoTokenAddress: Hex
- Notes:
- Ensure
fromamounts are in smallest units. - Use chain-specific token addresses (see
TOKEN_CONTRACT_ADDRESSES).
- Ensure
- Result (
SwapResult):{ success: true; result: SuccessfulSwapResult }
Call swapWithExactOut(input, options?)
- Use when desired output amount is fixed.
- Signature:
sdk.swapWithExactOut(input, { onEvent? })
- Params (
ExactOutSwapInput):toChainId: numbertoTokenAddress: HextoAmount: biginttoNativeAmount?: bigint(optional native token output)fromSources?: { chainId: number; tokenAddress: Hex }[](optional)
- Notes:
- If
fromSourcesis omitted, SDK auto-selects sources.
- If
Call swapAndExecute(input, options?)
- Use to perform swap (if needed) and then execute a contract call.
- Signature:
sdk.swapAndExecute(input, { onEvent? })
- Params (
SwapAndExecuteParams):toChainId: numbertoTokenAddress: HextoAmount: bigintfromSources?: { chainId: number; tokenAddress: Hex }[]execute: SwapExecuteParams
SwapExecuteParams:to: Hexdata?: Hexvalue?: bigintgas: bigintgasPrice?: 'low' | 'medium' | 'high'tokenApproval?: { token: Hex; amount: bigint; spender: Hex }
- Result (
SwapAndExecuteResult):swapResult: SuccessfulSwapResult | null(null if swap skipped)
Use token addresses and chains
- Use SDK constants for addresses and chain IDs:
SUPPORTED_CHAINSTOKEN_CONTRACT_ADDRESSES
Attach swap intent hook
- Set
sdk.setOnSwapIntentHook(...)and callallow()to proceed. - If the hook is not set, the SDK auto-approves.
Stream swap events
- Listen for
NEXUS_EVENTS.SWAP_STEP_COMPLETE. - Handle special cases like swap skipped (e.g., already on destination token).
Convert amounts to bigint
- Use
sdk.utils.parseUnits(value, decimals)or sdk.convertTokenReadableAmountToBigInt(value, tokenSymbol, chainId)when decimals vary by chain.