Zondax / filecoin-solidity

Filecoin Solidity API Library
Apache License 2.0
94 stars 43 forks source link

Move BigNumber Struct and BigInt Struct out of BigNumbers.sol and BigIntCbor.sol respectively #294

Closed ZakAyesh closed 1 year ago

ZakAyesh commented 1 year ago

Within BigNumbers.sol, but outside of the library definition, a BigNumber struct is defined. This makes using the library confusing for developers as they may opt to specifically import the library using the "from" syntax and this excludes the data struct. I.e.

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;

import { BigNumbers } from "https://github.com/Zondax/filecoin-solidity/blob/master/contracts/v0.8/external/BigNumbers.sol";
import { BigInt } from "@zondax/filecoin-solidity/contracts/v0.8/cbor/BigIntCbor.sol";

contract Test {
    function uintToBigInt(uint value) internal view returns(BigInt memory) {
        BigNumber memory bigNumVal = BigNumbers.init(value, true);
        BigInt memory bigIntVal = BigInt(bigNumVal.val, bigNumVal.neg);
        return bigIntVal;
    }
}

This will error. The same goes for the BigInt library. Creating separate libraries for those structs, placing them within the library or placing them within another type library (such as commontypes) would be great. I am partial to the last option (placing them in a location such as CommonTypes).

:link: zboto Link

emmanuelm41 commented 1 year ago

@ZakAyesh I like the idea you have. Unfortunately, BigNumbers library is external to the repository. I think I will move BigNumber inside the BigNumbers lib, and BigInt to CommonTypes as you suggested.