Skip to content

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

@mpaya5

Description

@mpaya5

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

  • genlayer-js version: 10.9.0
  • Node.js version: v22.11.0
  • Operating System: Ubuntu 24.04

Additional Context

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions