yeagerai / genlayer-js

MIT License
1 stars 1 forks source link

fix(genlayer-js): TypeError when passing float values in writeContract args #27

Open mpaya5 opened 2 hours ago

mpaya5 commented 2 hours ago

Description

The writeContract method from genlayer-js throws a TypeError when passing float values in the args array. This issue specifically impacts Adaptive AMM contracts that require float parameters for configuration.

Current Behavior

When calling writeContract with float values in the arguments array, the following error is thrown:

Error: invalid calldata input '0.5'
at AMMAdaptiveSimulated.resolve (AMMAdaptativeSimulat…1731913010393:56:38)
at resolveOrders (AMMAdaptativeSimulatedScreen.vue:111:38)

Expected Behavior

The library should handle and serialize float values properly, allowing them to be passed as arguments without errors.

Steps to Reproduce

  1. Create a client instance using genlayer-js
  2. Attempt to call a contract function with float parameters
  3. The TypeError occurs when executing the transaction

Minimal Reproduction Code

import { createClient } from "genlayer-js";
import { simulator } from "genlayer-js/chains";

const config = { chain: simulator, ...(account ? { account } : {}) };
this.client = createClient(config);

const order_book = {
      "bids": [
          [3.2, 10000],
          [3.198, 38000],
          [3.195, 45000]
      ],
      "asks": [
          [3.221, 6700],
          [3.224, 49000],
          [3.225, 70000]
      ]
    };
const price =  3.22;
const volume = 1000000;
const open_orders = [
      {"id": 1, "side": "buy", "price": 3.198, "amount": 20000},
      {"id": 2, "side": "buy", "price": 3.195, "amount": 37000},
      {"id": 3, "side": "sell", "price": 3.224, "amount": 25000},
      {"id": 4, "side": "sell", "price": 3.225, "amount": 55000}
    ];
const balance = {"SUI": 300000, "USDT": 12999};

const resolve = async () => {
  const contractAddress = "0x...";
  await client.writeContract({
    address: contractAddress,
    functionName: "resolve",
    args: [
            "SUI/USDT", "kucoin", 0.5, 0.1, 0.01, 0.02, 10000.0, 1000.0, order_book, price, volume, open_orders, balance
        ]
  });
};

resolve().catch(console.error);

Environment

Additional Context

This issue affects the functionality of Adaptive AMM contracts that require float parameters for their configuration. There is no current workaround available.

mpaya5 commented 2 hours ago

I suspect this issue might be related to how floats are encoded when passed to the writeContract function. It could require additional serialization or handling within the library.