@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
    db: B2bDatabase
    jupiterClient: JupiterSwapClient
    pricers: { cfx: VenuePricer; jupiter: VenuePricer } = ...

    One pricer per venue: adding a venue to SWAP_VENUES adds one here.

    productQuoteService: ProductQuoteService
    solanaTokenMintAddressService: SolanaTokenMintAddressService
    solanaTokenService: SolanaTokenQueryService
    instance: (...args: []) => SwapQuoteService = ...

    The process service, starting swaps on the queue the temporal namespace names.

    • Accept the owner's quote: simulate its stored, unsigned transaction and start the swap. CFX signs as the ledger account when the swap runs.

      Parameters

      • __namedParameters: { customerId: string; entityId: string; id: string }

      Returns Promise<
          | {
              ok: true;
              value: {
                  amount: BigNumber
                  | null;
                  createdAt: Date;
                  depositAddressId: string | null;
                  filledAt: Date | null;
                  id: string;
                  ledgerAccountId: string | null;
                  quote: SwapQuote | null;
                  receipt?: (
                      | {
                          id: string;
                          leg?: SwapReceiptLeg;
                          type: "SOLANA_TRANSACTION_SIGNATURE";
                      }
                      | {
                          chain: string;
                          id: string;
                          leg?: SwapReceiptLeg;
                          logIndex: number;
                          type: "EVM_TRANSACTION_SIGNATURE";
                      }
                      | {
                          id: string;
                          leg?: SwapReceiptLeg;
                          type: "TRON_TRANSACTION_SIGNATURE";
                      }
                  )[];
                  source: "DEPOSIT"
                  | "ACCOUNT";
                  sourceDescription: string;
                  status: "PENDING" | "FAILED" | "PROCESSING" | "COMPLETED";
                  statusDescription: string;
                  token: { id: string; symbol: string } | null;
                  updatedAt: Date;
              } & { quote: SwapQuote };
          }
          | {
              error: | ServiceError<
                  | "SWAP_QUOTE_NOT_FOUND"
                  | "SWAP_NOT_AVAILABLE"
                  | "NOT_ACTIVE"
                  | "QUOTE_EXPIRED"
                  | SimulationRefusal,
              >
              | ServiceError<"LIMIT_REACHED", { violations: BigNumber }>;
              ok: false;
          },
      >

    • A binding quote that debits and credits sourceLedgerAccountId at its primary key's address, with the unsigned transaction CFX signs on accept.

      Parameters

      • __namedParameters: {
            customerId: string;
            entityId: string;
            source: Pick<SwapSide, "amount" | "symbol">;
            sourceLedgerAccountId: string;
            target: Pick<SwapSide, "symbol">;
        }
        • customerId: string
        • entityId: string
        • source: Pick<SwapSide, "amount" | "symbol">
        • sourceLedgerAccountId: string

          One of the owner's ledger accounts, whose primary key wallet-api holds.

        • target: Pick<SwapSide, "symbol">

      Returns Promise<
          | { ok: true; value: SwapQuote }
          | {
              error:
                  | PricingError
                  | ServiceError<"SWAP_NOT_AVAILABLE">
                  | ServiceError<"LIMIT_REACHED", { violations: BigNumber }>
                  | ServiceError<
                      | "INSUFFICIENT_FUNDS"
                      | "LEDGER_ACCOUNT_NOT_FOUND"
                      | "INVALID_AMOUNT"
                      | "NO_COUNTRY_FOR_IDENTITY"
                      | "LEDGER_ACCOUNT_CANNOT_SWAP"
                      | "SWAP_TOO_LARGE",
                  >;
              ok: false;
          },
      >

    • The audit-free engine estimate() of the swap: the route, fees and amount math, with no product_quote row and no limit enforcement. Refuses SWAP_NOT_AVAILABLE, as create() does, when the engine will not price the swap.

      Parameters

      • __namedParameters: Omit<PriceArgs, "quote" | "targetToken"> & {
            customerId: string;
            entityId: string;
        }

      Returns Promise<{ ok: true; value: QuoteOutput } | { error: ServiceError; ok: false }>

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

      Parameters

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

      Returns Promise<
          | { ok: true; value: SwapEstimate }
          | {
              error:
                  | ServiceError<
                      "INVALID_INPUT"
                      | "INVALID_AMOUNT"
                      | "SWAP_NOT_AVAILABLE",
                  >
                  | PricingError;
              ok: false;
          },
      >

      invalidAmount

    • Parameters

      • __namedParameters: { customerId: string; entityId?: string; id: string }
        • customerId: string
        • OptionalentityId?: string

          The identity or organization that must own the quote.

        • id: string

      Returns Promise<
          | { ok: true; value: SwapQuote }
          | {
              error:
                  | ServiceError<"SWAP_QUOTE_NOT_FOUND">
                  | ServiceError<
                      "NOT_ACTIVE",
                      { status: "ACTIVE"
                      | "ACCEPTED"
                      | "REJECTED"
                      | "EXPIRED" },
                  >;
              ok: false;
          },
      >