depositExchange method

Future<DepositResponse> depositExchange(
  1. DepositExchangeRequest request
)

If the anchor supports SEP-38 quotes, it can provide a deposit that makes a bridge between non-equivalent tokens by receiving, for instance BRL via bank transfer and in return sending the equivalent value (minus fees) as USDC to the user's Stellar account.

The /deposit-exchange endpoint allows a wallet to get deposit information from an anchor when the user intends to make a conversion between non-equivalent tokens. With this endpoint, a user has all the information needed to initiate a deposit and it also lets the anchor specify additional information (if desired) that the user must submit via SEP-12.

Implementation

Future<DepositResponse> depositExchange(
    DepositExchangeRequest request) async {
  Uri serverURI =
      Util.appendEndpointToUrl(_transferServiceAddress, 'deposit-exchange');

  _DepositRequestBuilder requestBuilder =
      _DepositRequestBuilder(httpClient, serverURI);

  final Map<String, String> queryParams = {
    "destination_asset": request.destinationAsset,
    "source_asset": request.sourceAsset,
    "amount": request.amount,
    "account": request.account,
  };

  if (request.quoteId != null) {
    queryParams["quote_id"] = request.quoteId!;
  }
  if (request.memoType != null) {
    queryParams["memo_type"] = request.memoType!;
  }
  if (request.memo != null) {
    queryParams["memo"] = request.memo!;
  }
  if (request.emailAddress != null) {
    queryParams["email_address"] = request.emailAddress!;
  }
  if (request.type != null) {
    queryParams["type"] = request.type!;
  }
  if (request.walletName != null) {
    queryParams["wallet_name"] = request.walletName!;
  }
  if (request.walletUrl != null) {
    queryParams["wallet_url"] = request.walletUrl!;
  }
  if (request.lang != null) {
    queryParams["lang"] = request.lang!;
  }
  if (request.onChangeCallback != null) {
    queryParams["on_change_callback"] = request.onChangeCallback!;
  }
  if (request.countryCode != null) {
    queryParams["country_code"] = request.countryCode!;
  }
  if (request.claimableBalanceSupported != null) {
    queryParams["claimable_balance_supported"] =
        request.claimableBalanceSupported!;
  }
  if (request.customerId != null) {
    queryParams["customer_id"] = request.customerId!;
  }
  if (request.locationId != null) {
    queryParams["location_id"] = request.locationId!;
  }

  try {
    return await requestBuilder
        .forQueryParameters(queryParams)
        .execute(request.jwt);
  } on ErrorResponse catch (e) {
    if (e.code == 403) {
      _handleForbiddenResponse(e);
    }
    throw e;
  }
}