@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

    Constructors

    Properties

    jupiterClient: JupiterSwapClient
    solanaTokenService: SolanaTokenService

    Methods

    • Parameters

      • __namedParameters: {
            customerId: string;
            entityId: string;
            id: string;
            originator?: string;
            transaction?: VersionedTransaction | 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?: VersionedTransaction | null

      Returns Promise<
          | {
              ok: true;
              value: {
                  createdAt: Date;
                  id: string;
                  quote: SwapQuote;
                  receipt?: {
                      id: string;
                      type: "SOLANA_TRANSACTION_SIGNATURE"
                      | "REWARD_ID"
                      | "REWARD_CLAIM_ID";
                  }[];
                  status: "CREATED"
                  | "PENDING"
                  | "COMPLETED"
                  | "FAILED";
                  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;
          },
      >

    • Quote with partially-signed transaction

      Parameters

      • __namedParameters: {
            customerId: string;
            depositId?: string;
            entityId: string;
            source:
                | Omit<
                    { amount: number; amountAfterFees: number } & {
                        currency: "MOVEUSD" | "USDC" | "SOL" | "WETH" | "WBTC";
                        wallet: { address: PublicKey; chain: "SOLANA" };
                    },
                    "amountAfterFees",
                >
                | Omit<
                    { amount: number; amountAfterFees: number } & {
                        currency: "REWARD";
                        wallet?: undefined;
                    },
                    "amountAfterFees",
                >;
            target: | Omit<
                { amount: number; amountAfterFees: number } & {
                    currency: "MOVEUSD" | "USDC" | "SOL" | "WETH" | "WBTC";
                    wallet: { address: PublicKey; chain: "SOLANA" };
                },
                "amount"
                | "amountAfterFees",
            >
            | Omit<
                { amount: number; amountAfterFees: number } & {
                    currency: "REWARD";
                    wallet?: undefined;
                },
                "amount"
                | "amountAfterFees",
            >;
        }

      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<
                      "INVALID_AMOUNT"
                      | "NO_COUNTRY_FOR_IDENTITY"
                      | "INVALID_INPUT",
                  >
                  | ServiceError<
                      "INVALID_AMOUNT_AFTER_FEES",
                      {
                          fees: Fees;
                          sourceAmount: number;
                          sourceAmountAfterFees: number;
                          sourceCurrency: "MOVEUSD"
                          | "USDC"
                          | "SOL"
                          | "WETH"
                          | "WBTC"
                          | "REWARD";
                          totalFees: BigNumber;
                      },
                  >;
              ok: false;
          },
      >

      insufficientFunds

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

      Parameters

      • __namedParameters: {
            countryCode: string;
            customerId: string;
            entityType: "IDENTITY" | "ORGANIZATION";
            sourceAmount: number;
            sourceCurrency: "MOVEUSD" | "USDC" | "SOL" | "WETH" | "WBTC" | "REWARD";
            targetCurrency: "MOVEUSD" | "USDC" | "SOL" | "WETH" | "WBTC" | "REWARD";
        }
        • countryCode: string

          The country of the entity that may perform the swap

        • customerId: string
        • entityType: "IDENTITY" | "ORGANIZATION"

          The type of the entity that may perform the swap

        • sourceAmount: number
        • sourceCurrency: "MOVEUSD" | "USDC" | "SOL" | "WETH" | "WBTC" | "REWARD"
        • targetCurrency: "MOVEUSD" | "USDC" | "SOL" | "WETH" | "WBTC" | "REWARD"

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

      invalidAmount

    • Parameters

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

      Returns Promise<{ ok: true; value: { id: string } }>