0

I am encountering a 'execution reverted: GS013' error when trying to execute a script that aims to fill an Over-the-Counter (OTC) transaction through Safe Wallet using the 0x protocol. This issue arises specifically during the gas estimation phase of the transaction. Despite several attempts to adjust the gasPrice and safeTxGas parameters, the error persists.

Scenario Overview:

Goal: Fill an OTC transaction via Safe Wallet and the 0x protocol.

Issue Encountered: Persistent 'execution reverted: GS013' error during gas estimation. Adjusted various gas-related parameters without resolution.

Code Snippet:

// Code snippet where the gas estimation fails
const fillOtcOrder = async ({
  otcOrder,
  pseudoSignature,
  takerUsdtAssetAmount,
  exchangeProxyContract,
  contractWrappers,
  exchangeProxyAddress,
  safeSdkTaker,
}: {
  otcOrder: OtcOrder;
  pseudoSignature: {
    r: string;
    s: string;
    v: number;
    signatureType: number;
  };
  takerUsdtAssetAmount: BigNumber;
  exchangeProxyContract: ethers.Contract;
  contractWrappers: ContractWrappers;
  exchangeProxyAddress: string;
  safeSdkTaker: Safe;
}) => {
  // Encode the `fillOtcOrder` function call using 0x Contract Wrappers
  const fillOtcOrderData = contractWrappers.exchangeProxy
    .fillOtcOrder(otcOrder, pseudoSignature, takerUsdtAssetAmount)
    .getABIEncodedTransactionData();

  // I tried to encode the function data with ethers.js and web3.js as well, but the error seems to be in safeWallet 

  // Encode the `fillOtcOrder` function call
  // const fillOtcOrderData = exchangeProxyContract.interface.encodeFunctionData(
  //   "fillOtcOrder",
  //   [otcOrder, pseudoSignature, takerUsdtAssetAmount]
  // );

  // const fillOtcOrderData = web3Provider.eth.abi.encodeFunctionCall(
  //   fillOtcOrderAbi,
  //   [
  //     {
  //       makerToken: otcOrder.makerToken,
  //       takerToken: otcOrder.takerToken,
  //       makerAmount: otcOrder.makerAmount.toString(),
  //       takerAmount: otcOrder.takerAmount.toString(),
  //       maker: otcOrder.maker,
  //       taker: otcOrder.taker,
  //       txOrigin: otcOrder.txOrigin,
  //       expiryAndNonce: otcOrder.expiryAndNonce.toString(),
  //     },
  //     pseudoSignature,
  //     takerUsdtAssetAmount.toString(),
  //   ]
  // );

  // Transform into SafeTransactionDataPartial object
  const fillOrderTransactionData = {
    to: exchangeProxyAddress,
    value: "0",
    data: fillOtcOrderData,
  };

  const { gasPrice } = await getGasGoal();

  // Create Safe transaction for fillOtcOrder
  const safeFillOrderTx = await safeSdkTaker.createTransaction({
    safeTransactionData: fillOrderTransactionData,
    options: {
      gasPrice: String(gasPrice), // setting gasPrice seems to make no effect
      // safeTxGas: String(gasPrice), // No matter what I put here, the error remains the same
    },
  });

  // Sign Safe transaction
  const signedFillOrderTx = await safeSdkTaker.signTransaction(safeFillOrderTx);


  // Execute fillOtcOrder transaction (the code breaks here)
  const executeFillOrderTxResponse = await safeSdkTaker.executeTransaction(
    signedFillOrderTx,
    { gasPrice }
  );
};

In this script, my objective is to seamlessly execute OTC transactions using Safe Wallet's capabilities in conjunction with the 0x protocol. Any insights or guidance on resolving this gas estimation issue would be immensely helpful.

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.