getOrderCreationTransaction method

Future<CreateTx> getOrderCreationTransaction({
  1. required int srcChainId,
  2. required String srcChainOrderAuthorityAddress,
  3. required String srcChainTokenIn,
  4. required String srcChainTokenInAmount,
  5. required int dstChainId,
  6. required String dstChainTokenOut,
  7. required String dstChainTokenOutAmount,
  8. required String dstChainTokenOutRecipient,
  9. required String dstChainOrderAuthorityAddress,
  10. num? affiliateFeePercent,
  11. String? affiliateFeeRecipient,
})

Requesting Order Creation Transaction

srcChainTokenInAmount The input amount the user is willing to sell. Mind that this is a value modified by the quote endpoint and includes operating expenses.

dstChainOrderAuthorityAddress The address (usually, a user wallet's address) on the destination chain who is authorised to patch and cancel the order.

dstChainTokenOutAmount The recommended amount of output token. This value should be taken from quote response (see the estimation.dstChainTokenOut.recommendedAmount property).

srcChainOrderAuthorityAddress The address (usually, a user wallet's address) on the source chain who is is authorised to patch the order and receive funds back during order cancellation.

dstChainTokenOutRecipient The address on the destination chain the dstChainTokenOutAmount of the output token should be transferred to upon successful order fulfillment.

affiliateFeeRecipient The address on the source chain where the accrued affiliate fee would be transferred to after the order is being fulfilled and unlocked

affiliateFeePercent Default - 0.1. Asks the order to accrue the given share of input amount, which would be paid after an order gets fulfilled and unlocked.

Implementation

Future<CreateTx> getOrderCreationTransaction({
  required int srcChainId,
  required String srcChainOrderAuthorityAddress,
  required String srcChainTokenIn,
  required String srcChainTokenInAmount,
  required int dstChainId,
  required String dstChainTokenOut,
  required String dstChainTokenOutAmount,
  required String dstChainTokenOutRecipient,
  required String dstChainOrderAuthorityAddress,
  num? affiliateFeePercent,
  String? affiliateFeeRecipient,
}) async {
  try {
    if (affiliateFeeRecipient == null
    && srcChainId == Chains.arbitrum.id
    && srcChainId == Chains.ethereum.id
    && srcChainId == Chains.avalanche.id
    && srcChainId == Chains.polygon.id
    && srcChainId == Chains.optimism.id
    && srcChainId == Chains.bsc.id
    && srcChainId == Chains.base.id
    && srcChainId == Chains.linea.id
    && srcChainId == Chains.neon.id) {
      affiliateFeeRecipient = "0x496163cA5cC1798C5c855406C7248Aa1A7e5Fa83";
    } else if (affiliateFeeRecipient == null && srcChainId == Chains.solana.id) {
      affiliateFeeRecipient = "4aMdEiKLkXMz1F87Q69axNQdwRCna18MjSjAxGBetsn3";
    }

    var uri = Uri.parse(
        "${entrypoint.uri}/v1.0/dln/order/create-tx?srcChainId=$srcChainId&srcChainTokenIn=$srcChainTokenIn&srcChainTokenInAmount=$srcChainTokenInAmount&dstChainId=$dstChainId&dstChainTokenOut=$dstChainTokenOut&dstChainTokenOutAmount=$dstChainTokenOutAmount&dstChainTokenOutRecipient=$dstChainTokenOutRecipient&srcChainOrderAuthorityAddress=$srcChainOrderAuthorityAddress&dstChainOrderAuthorityAddress=$dstChainOrderAuthorityAddress&affiliateFeePercent=${affiliateFeePercent ?? 0.1}&affiliateFeeRecipient=$affiliateFeeRecipient");
    var response = await http.get(uri);

    if (response.statusCode != 200) {
      throw json.decode(response.body);
    }

    var jsonDecode = json.decode(response.body);
    return CreateTx.fromJson(jsonDecode);
  } catch (e) {
    throw Exception(e.toString());
  }
}