Integration
Swapping and Aggregation
Javascript SDK
Get Status

Get Status

getStatus

Fetches the status of an ongoing swap based on the provided swapStatusRequest argument.

getStatus(
  swapStatusRequest: SwapStatusRequest,
  options?: RequestOptions
): Promise<SwapStatusResponse>

The SwapStatusRequest object includes the following arguments:

ParamDescriptionData type
id(required)

One of the following:

string

The response will include the following:

interface SwapFee {
  type: 'LIQUIDITY' | 'NETWORK' | 'INGRESS' | 'EGRESS' | 'BROKER';
  chain: Chain;
  asset: Asset;
  amount: string;
}
 
interface CommonStatusFields {
  srcChain: Chain;
  destChain: Chain;
  srcAsset: Asset;
  destAsset: Asset;
  destAddress: string | undefined;
  depositAddress: string | undefined;
  depositChannelBrokerCommissionBps: number | undefined;
  estimatedDepositChannelExpiryTime: number | undefined;
  expectedDepositAmount: string | undefined;
  isDepositChannelExpired: boolean;
  ccmDepositReceivedBlockIndex: string | undefined;
  ccmMetadata: {
      gasBudget: string;
      message: `0x${string}`;
  } | undefined;
  feesPaid: SwapFee[];
}
 
export type SwapStatusResponse = CommonStatusFields &
  (
    | {
      // we are waiting for the user to send funds
      state: 'AWAITING_DEPOSIT';
      depositAmount: string | undefined;
      depositTransactionHash: string | undefined;
      depositTransactionConfirmations: number | undefined;
    }
  | {
      // funds have been received and the swap is being performed
      state: 'DEPOSIT_RECEIVED';
      swapId: string;
      depositAmount: string;
      depositReceivedAt: number;
      depositReceivedBlockIndex: string;
    }
  | {
      // funds have been swapped through the AMM and awaiting scheduling
      state: 'SWAP_EXECUTED';
      swapId: string;
      depositAmount: string;
      depositReceivedAt: number;
      depositReceivedBlockIndex: string;
      intermediateAmount: string | undefined;
      swapExecutedAt: number;
      swapExecutedBlockIndex: string;
    }
  | {
      // funds have been scheduled to be sent to the destination address
      state: 'EGRESS_SCHEDULED';
      swapId: string;
      depositAmount: string;
      depositReceivedAt: number;
      depositReceivedBlockIndex: string;
      intermediateAmount: string | undefined;
      swapExecutedAt: number;
      swapExecutedBlockIndex: string;
      egressAmount: string;
      egressScheduledAt: number;
      egressScheduledBlockIndex: string;
    }
  | {
      state:
        // a validator has been requested to send the funds
        | "BROADCAST_REQUESTED"
        // the transaction has been included in a block on the destination chain
        | "BROADCASTED";
      swapId: string;
      depositAmount: string;
      depositReceivedAt: number;
      depositReceivedBlockIndex: string;
      intermediateAmount: string | undefined;
      swapExecutedAt: number;
      swapExecutedBlockIndex: string;
      egressAmount: string;
      egressScheduledAt: number;
      egressScheduledBlockIndex: string;
      broadcastRequestedAt: number;
      broadcastRequestedBlockIndex: string;
      broadcastTransactionRef: string;
    }
  | {
      // the transaction could not be successfully completed
      state: 'BROADCAST_ABORTED';
      swapId: string;
      depositAmount: string;
      depositReceivedAt: number;
      depositReceivedBlockIndex: string;
      intermediateAmount: string | undefined;
      swapExecutedAt: number;
      swapExecutedBlockIndex: string;
      egressAmount: string;
      egressScheduledAt: number;
      egressScheduledBlockIndex: string;
      broadcastRequestedAt: number;
      broadcastRequestedBlockIndex: string;
      broadcastAbortedAt: number;
      broadcastAbortedBlockIndex: string;
    }
  | {
      // the transaction has been confirmed beyond our safety margin
      state: 'COMPLETE';
      swapId: string;
      depositAmount: string;
      depositReceivedAt: number;
      depositReceivedBlockIndex: string;
      intermediateAmount: string | undefined;
      swapExecutedAt: number;
      swapExecutedBlockIndex: string;
      egressAmount: string;
      egressScheduledAt: number;
      egressScheduledBlockIndex: string;
      broadcastRequestedAt: number;
      broadcastRequestedBlockIndex: string;
      broadcastSucceededAt: number;
      broadcastSucceededBlockIndex: string;
      broadcastTransactionRef: string;
    }
  | {
      // the swap failed due to an error on the source chain
      state: 'FAILED';
      failure: 'INGRESS_IGNORED';
      error: { name: string; message: string };
      depositAmount: string;
      depositTransactionHash: string | undefined;
      failedAt: number;
      failedBlockIndex: string;
    }
  | {
      // the swap failed due to an error on the destination chain
      state: 'FAILED';
      failure: 'EGRESS_IGNORED';
      error: { name: string; message: string };
      swapId: string;
      depositAmount: string;
      depositReceivedAt: number;
      depositReceivedBlockIndex: string;
      intermediateAmount: string | undefined;
      swapExecutedAt: number;
      swapExecutedBlockIndex: string;
      ignoredEgressAmount: string;
      egressIgnoredAt: number;
      egressIgnoredBlockIndex: string;
    };
  );

broadcastTransactionRef

After a transaction is successfully broadcast by the Chainflip protocol, its transaction reference is returned in the response under the key broadcastTransactionRef. This field will have a different format depending on the chain the transaction was broadcast on:

  • For Polkadot, the transaction reference is in the format ${blockNumber}-${extrinsicIndex}. For example, 200-3 refers to the fourth extrinsic in block 200.
  • For EVM-based chains, the transaction reference is the transaction hash.
  • For Bitcoin, the transaction reference is the transaction ID.

Example

Here is an example using Request Deposit Address:

const swapStatusRequest = {
  id: "1234567890", // depositChannelId or transactionHash
};
 
console.log(await swapSDK.getStatus(swapStatusRequest));

Sample Response

{
  "broadcastAbortedBlockIndex": null,
  "broadcastRequestedAt": 1669907147201,
  "broadcastRequestedBlockIndex": "202-4",
  "broadcastSucceededAt": 1669907153201,
  "broadcastSucceededBlockIndex": "204-4",
  "broadcastTransactionRef": "20054255-2", // block number - extrinsic index (polkadot)
  "depositAddress": "0x6Aa69332B63bB5b1d7Ca5355387EDd5624e181F2",
  "depositAmount": "1000000000000",
  "ccmMetadata": {
    "gasBudget": "100000000000",
    "message": "0x436861696e666c697020526f636b73"
  },
  "depositReceivedAt": 1669907135201,
  "depositReceivedBlockIndex": "100-3",
  "destAddress": "5F3sa2TJAWMqDhXG6jhV4N8ko9SxwGy8TpaNS1repo5EYjQX",
  "destAsset": "DOT",
  "destChain": "Polkadot",
  "egressAmount": "1000000000000000000",
  "egressScheduledAt": 1669907147201,
  "egressScheduledBlockIndex": "202-3",
  "expectedDepositAmount": "10000000000",
  "intermediateAmount": "20000000",
  "srcAsset": "ETH",
  "srcChain": "Ethereum",
  "state": "COMPLETE",
  "swapExecutedAt": 1669907141201,
  "swapExecutedBlockIndex": "200-3"
}

Lifecycle of a Swap


;