@cfxlabsinc/b2b-services
    Preparing search index...

    Implements the creation of a Swap via a quote

    The operations in this class assume that the Customer is already validated (both AuthN and AuthZ).

    Hierarchy (View Summary)

    Index
    • Parameters

      • __namedParameters: {
            customerQueryService: CustomerQueryService;
            db: B2bDatabase;
            heliusRpcClient: HeliusRpcClient;
            jupiterClient: JupiterSwapClient;
            productQuoteService: ProductQuoteService;
            solanaBackofficeWalletService: SolanaBackofficeWalletService;
            solanaNonceService: SolanaNonceService;
            solanaTokenMintAddressService: SolanaTokenMintAddressService;
            solanaTokenService: SolanaTokenQueryService;
            solanaTransactionService: SolanaTransactionService;
            swapAdminService: SwapAdminService;
            temporalClient: Client;
            temporalTaskQueue: string;
            utilaSweepWalletQueryService: UtilaSweepWalletQueryService;
        }
        • customerQueryService: CustomerQueryService
        • db: B2bDatabase
        • heliusRpcClient: HeliusRpcClient
        • jupiterClient: JupiterSwapClient
        • productQuoteService: ProductQuoteService
        • solanaBackofficeWalletService: SolanaBackofficeWalletService
        • solanaNonceService: SolanaNonceService
        • solanaTokenMintAddressService: SolanaTokenMintAddressService
        • solanaTokenService: SolanaTokenQueryService
        • solanaTransactionService: SolanaTransactionService
        • swapAdminService: SwapAdminService
        • temporalClient: Client
        • temporalTaskQueue: string

          For swap workflow

        • utilaSweepWalletQueryService: UtilaSweepWalletQueryService

      Returns SwapQuoteService

    db: B2bDatabase
    jupiterClient: JupiterSwapClient
    productQuoteService: ProductQuoteService
    solanaTokenMintAddressService: SolanaTokenMintAddressService
    solanaTokenService: SolanaTokenQueryService
    • Parameters

      • __namedParameters: {
            customerId: string;
            entityId: string;
            id: string;
            originator?: string;
            transaction?:
                | Readonly<
                    { messageBytes: TransactionMessageBytes; signatures: SignaturesMap },
                >
                | null;
        }
        • customerId: string
        • entityId: string
        • id: string
        • Optionaloriginator?: string

          Workflow ID of the originator of this quote

          The originating workflows should expose a SWAP_COMPLETED signal that receives Swap (without quote) when the process is completed.

        • Optionaltransaction?:
              | Readonly<
                  { messageBytes: TransactionMessageBytes; signatures: SignaturesMap },
              >
              | null

      Returns Promise<
          | {
              ok: true;
              value: {
                  createdAt: Date;
                  id: string;
                  quote: SwapQuote;
                  receipt?: { id: string; type: "SOLANA_TRANSACTION_SIGNATURE" }[];
                  status: "COMPLETED" | "CREATED" | "FAILED" | "PENDING";
                  updatedAt: Date;
              };
          }
          | {
              error: | ServiceError<"INVALID_TRANSACTION">
              | ServiceError<"NOT_FOUND", { customerId?: string; entityId?: string }>
              | ServiceError<
                  "INSUFFICIENT_FUNDS",
                  { currency: string; walletAddress?: string },
              >
              | ServiceError<"LIMIT_REACHED", { violations: BigNumber }>;
              ok: false;
          },
      >

    • Build the SwapEstimate from an already-successful engine result's pricing block. Shared by the preview estimate() (fed by the engine's audit-free estimate()) and the authoritative create-time quote(), so both derive target amount + fees identically. The product_quote audit id is intentionally not threaded here — only create() produces one, and it pins that id onto the persisted swap_quote row directly.

      Parameters

      • __namedParameters: {
            quote: QuoteShape;
            sourceAmount: number;
            sourceCurrency: "MOVEUSD" | "USDC" | "SOL" | "WETH" | "WBTC";
            sourceToken: TokenData;
            targetCurrency: "MOVEUSD" | "USDC" | "SOL" | "WETH" | "WBTC";
            targetToken: TokenData;
        }

      Returns Promise<
          | { ok: true; value: SwapEstimate }
          | {
              error:
                  | ServiceError<"INVALID_INPUT" | "INVALID_AMOUNT">
                  | ServiceError<
                      "INVALID_AMOUNT_AFTER_FEES",
                      {
                          fees: Fees;
                          sourceAmount: number;
                          sourceAmountAfterFees: number;
                          sourceCurrency: "MOVEUSD"
                          | "USDC"
                          | "SOL"
                          | "WETH"
                          | "WBTC";
                          totalFees: BigNumber;
                      },
                  >;
              ok: false;
          },
      >

    • Quote with partially-signed transaction

      Parameters

      • __namedParameters: {
            customerId: string;
            depositId?: string;
            entityId: string;
            source: UnionOmit<SwapSide, "amountAfterFees">;
            target: UnionOmit<SwapSide, "amountAfterFees" | "amount">;
        }

      Returns Promise<
          | { ok: true; value: SwapQuote }
          | {
              error:
                  | ServiceError<
                      "NOT_FOUND",
                      { customerId?: string; entityId?: string },
                  >
                  | ServiceError<
                      "INSUFFICIENT_FUNDS",
                      { currency: string; walletAddress?: string },
                  >
                  | ServiceError<"LIMIT_REACHED", { violations: BigNumber }>
                  | ServiceError<
                      "NO_COUNTRY_FOR_IDENTITY"
                      | "INVALID_INPUT"
                      | "INVALID_AMOUNT",
                  >
                  | ServiceError<
                      "INVALID_AMOUNT_AFTER_FEES",
                      {
                          fees: Fees;
                          sourceAmount: number;
                          sourceAmountAfterFees: number;
                          sourceCurrency: "MOVEUSD"
                          | "USDC"
                          | "SOL"
                          | "WETH"
                          | "WBTC";
                          totalFees: BigNumber;
                      },
                  >;
              ok: false;
          },
      >

      insufficientFunds

    • Ephemeral (and entity-agnostic) quote of target amount and fees

      Parameters

      • __namedParameters: {
            customerId: string;
            entityId: string;
            sourceAmount: number;
            sourceCurrency: "MOVEUSD" | "USDC" | "SOL" | "WETH" | "WBTC";
            targetCurrency: "MOVEUSD" | "USDC" | "SOL" | "WETH" | "WBTC";
        }

      Returns Promise<
          | { ok: true; value: SwapEstimate }
          | {
              error:
                  | ServiceError<"INVALID_INPUT" | "INVALID_AMOUNT">
                  | ServiceError<
                      "INVALID_AMOUNT_AFTER_FEES",
                      {
                          fees: Fees;
                          sourceAmount: number;
                          sourceAmountAfterFees: number;
                          sourceCurrency: "MOVEUSD"
                          | "USDC"
                          | "SOL"
                          | "WETH"
                          | "WBTC";
                          totalFees: BigNumber;
                      },
                  >;
              ok: false;
          },
      >

      invalidAmount