Skip to content

v0.3.0

Choose a tag to compare

@atharen atharen released this 11 Nov 09:55
· 7 commits to main since this release
285c7ea

Overview

New SDK surface:

  • userIp on quotes.get() and swaps.create()
  • destinationMemo on quotes.get() and swaps.create()
  • QuoteRoute.destinationMemoLabel
  • DESTINATION_MEMO_UNSUPPORTED
  • providerStatus on TransactionWebhookData.input

SDK 0.3.0 requires Pegaroute v0.9.0 for destination memo and webhook provider-status fields.

Upgrade guide: 0.2.0 → 0.3.0

Install the new SDK:

npm install @pegaroute/sdk@0.3.0

0.3.0 is additive over 0.2.0. Existing quote and swap calls remain valid. No catalog-specific SDK changes are required: chain and token IDs are already typed as strings.

To enable SwapSpace routes:

  1. Send the same userIp to both quotes.get() and swaps.create().
const quote = await pr.quotes.get({
  fromChain: "ETH",
  fromToken: "ETH",
  toChain: "CANTON",
  toToken: "CC",
  amount: "1",
  userIp: "203.0.113.7",
});

const route = quote.routes.find((candidate) => candidate.provider === "swapspace") ?? quote.routes[0];

const swap = await pr.swaps.create({
  fromChain: "ETH",
  fromToken: "ETH",
  toChain: "CANTON",
  toToken: "CC",
  amount: "1",
  senderAddress: "0x1111111111111111111111111111111111111111",
  destinationAddress: "canton-address",
  userIp: "203.0.113.7",
  quoteId: quote.quoteId,
  routeProvider: route?.provider,
});
  1. To send a destination memo, tag, or payment ID, pass destinationMemo to both calls.
const destinationMemo = "payment-id-1";

const quote = await pr.quotes.get({
  fromChain: "ETH",
  fromToken: "ETH",
  toChain: "CANTON",
  toToken: "CC",
  amount: "1",
  userIp: "203.0.113.7",
  destinationMemo,
});

const destinationMemoLabel = quote.routes[0]?.destinationMemoLabel;

const swap = await pr.swaps.create({
  fromChain: "ETH",
  fromToken: "ETH",
  toChain: "CANTON",
  toToken: "CC",
  amount: "1",
  senderAddress: "0x1111111111111111111111111111111111111111",
  destinationAddress: "canton-address",
  userIp: "203.0.113.7",
  destinationMemo,
  quoteId: quote.quoteId,
  routeProvider: quote.routes[0]?.provider,
});

Use destinationMemoLabel for the field label. It is the live provider label, such as Memo, Tag, or Payment ID. Do not add destinationMemo to execution.memo; it is not a source-chain signing memo.

  1. Handle the new errors.
import { PegarouteError } from "@pegaroute/sdk";

try {
  const quote = await pr.quotes.get(params);
} catch (error) {
  if (error instanceof PegarouteError) {
    if (error.code === "USER_IP_REQUIRED") {
      // Collect a valid end-user IP and retry the quote.
    }
    if (error.code === "DESTINATION_MEMO_UNSUPPORTED") {
      // Remove destinationMemo or choose a route that supports it.
    }
  }
}
  1. Read provider status evidence from webhooks when present.
if (event.data.input.providerStatus?.actionRequired) {
  showAction(event.data.input.providerStatus.message);
}