From 08221129c82d2344a142f473ca7190f1af41d0ce Mon Sep 17 00:00:00 2001 From: Dmitry Zakharov Date: Thu, 27 Jun 2024 23:20:13 +0400 Subject: [PATCH] BigInt clean up (#48) * Remove BigInt from Ethers * Remove BigInt.t in favor of bigint --- .../cli/src/config_parsing/entity_parsing.rs | 6 +- .../cli/src/config_parsing/event_parsing.rs | 9 +-- codegenerator/cli/src/rescript_types.rs | 6 +- .../dynamic/codegen/src/ContextEnv.res.hbs | 2 +- .../codegen/src/EventProcessing.res.hbs | 4 +- .../dynamic/codegen/src/LoadLayer.res.hbs | 2 +- .../codegen/src/TestHelpers_MockDb.res.hbs | 2 +- .../static/codegen/src/ConfigYAML.res | 2 +- .../codegen/src/ContractAddressingMap.res | 4 +- .../codegen/src/ContractInterfaceManager.res | 2 +- .../static/codegen/src/EventUtils.res | 40 ++++++------- .../static/codegen/src/InMemoryTable.res | 2 +- .../static/codegen/src/LazyLoader.res | 6 +- .../static/codegen/src/RegisteredEvents.res | 4 +- .../codegen/src/bindings/BigDecimal.res | 2 +- .../static/codegen/src/bindings/BigInt.res | 50 ++++++++-------- .../static/codegen/src/bindings/Ethers.res | 8 +-- .../codegen/src/bindings/HyperSyncClient.res | 30 +++++----- .../codegen/src/bindings/OpaqueTypes.ts | 1 - .../static/codegen/src/bindings/Pino.res | 6 +- .../static/codegen/src/db/DbFunctions.res | 10 ++-- .../static/codegen/src/db/Schema.res | 2 +- .../static/codegen/src/db/TablesStatic.res | 2 +- .../chainWorkers/RawEventsWorker.res | 27 ++++----- .../src/eventFetching/hypersync/HyperSync.res | 4 +- .../hypersync/HyperSyncJsonApi.res | 60 +++++++++---------- .../rescript/src/EventHandlers.res | 8 +-- .../erc20_template/rescript/test/Test.res | 8 +-- .../src/EventHandlers.res | 6 +- .../test/Handler_Test.res | 8 +-- .../test/RollbackDynamicContract_test.res | 6 +- .../test/RollbackMultichain_test.res | 6 +- .../test/TestDeleteEntity.res | 2 +- scenarios/gravatar/src/EventHandlers.res | 6 +- scenarios/nft-factory/README.md | 10 +--- .../ploffen/indexer/src/EventHandlers.res | 10 ++-- scenarios/test_codegen/package.json | 2 +- scenarios/test_codegen/src/EventHandlers.res | 14 ++--- .../test_codegen/test/EventParsing_test.res | 2 +- scenarios/test_codegen/test/Mock_test.res | 6 +- .../test_codegen/test/__mocks__/DbStub.res | 4 +- .../test/__mocks__/MockEntities.res | 6 +- .../test/__mocks__/MockEvents.res | 16 ++--- .../test/rollback/Rollback_test.res | 4 +- 44 files changed, 202 insertions(+), 215 deletions(-) diff --git a/codegenerator/cli/src/config_parsing/entity_parsing.rs b/codegenerator/cli/src/config_parsing/entity_parsing.rs index 7199f9620..df475acb7 100644 --- a/codegenerator/cli/src/config_parsing/entity_parsing.rs +++ b/codegenerator/cli/src/config_parsing/entity_parsing.rs @@ -843,7 +843,7 @@ impl RescriptType { match self { RescriptType::Int => "int".to_string(), RescriptType::Float => "GqlDbCustomTypes.Float.t".to_string(), - RescriptType::BigInt => "Ethers.BigInt.t".to_string(), + RescriptType::BigInt => "bigint".to_string(), RescriptType::BigDecimal => "BigDecimal.t".to_string(), RescriptType::Address => "Ethers.ethAddress".to_string(), RescriptType::String => "string".to_string(), @@ -871,7 +871,7 @@ impl RescriptType { match self { RescriptType::Int => "S.int".to_string(), RescriptType::Float => "GqlDbCustomTypes.Float.schema".to_string(), - RescriptType::BigInt => "Ethers.BigInt.schema".to_string(), + RescriptType::BigInt => "BigInt.schema".to_string(), RescriptType::BigDecimal => "BigDecimal.schema".to_string(), RescriptType::Address => "Ethers.ethAddressSchema".to_string(), RescriptType::String => "S.string".to_string(), @@ -904,7 +904,7 @@ impl RescriptType { match self { RescriptType::Int => "0".to_string(), RescriptType::Float => "0.0".to_string(), - RescriptType::BigInt => "Ethers.BigInt.zero".to_string(), //TODO: Migrate to RescriptCore on ReScript migration + RescriptType::BigInt => "BigInt.zero".to_string(), //TODO: Migrate to RescriptCore on ReScript migration RescriptType::BigDecimal => "BigDecimal.zero".to_string(), RescriptType::Address => "TestHelpers_MockAddresses.defaultAddress".to_string(), RescriptType::String => "\"foo\"".to_string(), diff --git a/codegenerator/cli/src/config_parsing/event_parsing.rs b/codegenerator/cli/src/config_parsing/event_parsing.rs index 81362024b..55d9f077b 100644 --- a/codegenerator/cli/src/config_parsing/event_parsing.rs +++ b/codegenerator/cli/src/config_parsing/event_parsing.rs @@ -110,7 +110,7 @@ mod tests { assert_eq!( parsed_rescript_string.to_string(), - String::from("(string, Ethers.BigInt.t)") + String::from("(string, bigint)") ) } @@ -136,10 +136,7 @@ mod tests { user_address_res_type.to_string(), "Ethers.ethAddress".to_string() ); - assert_eq!( - amount_uint256_res_type.to_string(), - "Ethers.BigInt.t".to_string() - ); + assert_eq!(amount_uint256_res_type.to_string(), "bigint".to_string()); assert_eq!( tuple_bool_string_res_type.to_string(), "(bool, Ethers.ethAddress)".to_string() @@ -152,7 +149,7 @@ mod tests { ); assert_eq!( amount_uint256_res_type.get_default_value_rescript(), - "Ethers.BigInt.zero".to_string() + "BigInt.zero".to_string() ); assert_eq!( tuple_bool_string_res_type.get_default_value_rescript(), diff --git a/codegenerator/cli/src/rescript_types.rs b/codegenerator/cli/src/rescript_types.rs index 5606567e6..d9da791ac 100644 --- a/codegenerator/cli/src/rescript_types.rs +++ b/codegenerator/cli/src/rescript_types.rs @@ -243,7 +243,7 @@ impl RescriptTypeIdent { RescriptTypeIdent::Unit => "unit".to_string(), RescriptTypeIdent::Int => "int".to_string(), RescriptTypeIdent::Float => "GqlDbCustomTypes.Float.t".to_string(), - RescriptTypeIdent::BigInt => "Ethers.BigInt.t".to_string(), + RescriptTypeIdent::BigInt => "bigint".to_string(), RescriptTypeIdent::Address => "Ethers.ethAddress".to_string(), RescriptTypeIdent::String => "string".to_string(), RescriptTypeIdent::ID => "id".to_string(), @@ -289,7 +289,7 @@ impl RescriptTypeIdent { RescriptTypeIdent::Unit => "S.unit".to_string(), RescriptTypeIdent::Int => "S.int".to_string(), RescriptTypeIdent::Float => "GqlDbCustomTypes.Float.schema".to_string(), - RescriptTypeIdent::BigInt => "Ethers.BigInt.schema".to_string(), + RescriptTypeIdent::BigInt => "BigInt.schema".to_string(), RescriptTypeIdent::Address => "Ethers.ethAddressSchema".to_string(), RescriptTypeIdent::String => "S.string".to_string(), RescriptTypeIdent::ID => "S.string".to_string(), @@ -355,7 +355,7 @@ impl RescriptTypeIdent { RescriptTypeIdent::Unit => "()".to_string(), RescriptTypeIdent::Int => "0".to_string(), RescriptTypeIdent::Float => "0.0".to_string(), - RescriptTypeIdent::BigInt => "Ethers.BigInt.zero".to_string(), // TODO: Migrate to RescriptCore on ReScript migration + RescriptTypeIdent::BigInt => "BigInt.zero".to_string(), // TODO: Migrate to RescriptCore on ReScript migration RescriptTypeIdent::Address => "TestHelpers_MockAddresses.defaultAddress".to_string(), RescriptTypeIdent::String => "\"foo\"".to_string(), RescriptTypeIdent::ID => "\"my_id\"".to_string(), diff --git a/codegenerator/cli/templates/dynamic/codegen/src/ContextEnv.res.hbs b/codegenerator/cli/templates/dynamic/codegen/src/ContextEnv.res.hbs index 3fbf981a5..3000fa489 100644 --- a/codegenerator/cli/templates/dynamic/codegen/src/ContextEnv.res.hbs +++ b/codegenerator/cli/templates/dynamic/codegen/src/ContextEnv.res.hbs @@ -1,7 +1,7 @@ open Types module EntityIdsMap = { - type t = Js.Dict.t> + type t = dict> let makeEmptyEntityIdsMap = (): t => { Entities.allTables->Belt.Array.map(table => (table.tableName, Set.make()))->Js.Dict.fromArray diff --git a/codegenerator/cli/templates/dynamic/codegen/src/EventProcessing.res.hbs b/codegenerator/cli/templates/dynamic/codegen/src/EventProcessing.res.hbs index ab162d911..aea1765e9 100644 --- a/codegenerator/cli/templates/dynamic/codegen/src/EventProcessing.res.hbs +++ b/codegenerator/cli/templates/dynamic/codegen/src/EventProcessing.res.hbs @@ -168,7 +168,7 @@ let addEventToRawEvents = ( let eventId = EventUtils.packEventIndex(~logIndex, ~blockNumber) let rawEvent: TablesStatic.RawEvents.t = { chainId, - eventId: eventId->Ethers.BigInt.toString, + eventId: eventId->BigInt.toString, blockNumber, logIndex, transactionIndex, @@ -183,7 +183,7 @@ let addEventToRawEvents = ( }, } - let eventIdStr = eventId->Ethers.BigInt.toString + let eventIdStr = eventId->BigInt.toString inMemoryStore.rawEvents->InMemoryTable.set({chainId, eventId: eventIdStr}, rawEvent) } diff --git a/codegenerator/cli/templates/dynamic/codegen/src/LoadLayer.res.hbs b/codegenerator/cli/templates/dynamic/codegen/src/LoadLayer.res.hbs index 7989b80dc..4ab0075da 100644 --- a/codegenerator/cli/templates/dynamic/codegen/src/LoadLayer.res.hbs +++ b/codegenerator/cli/templates/dynamic/codegen/src/LoadLayer.res.hbs @@ -5,7 +5,7 @@ module LoadActionMap = { type key = string type value<'entity> = array> - type t<'entity> = Js.Dict.t> + type t<'entity> = dict> let empty: unit => t<'entity> = Js.Dict.empty let getIds = (map: t<'entity>) => map->Js.Dict.keys let entries: t<'entity> => array<(key, value<'entity>)> = Js.Dict.entries diff --git a/codegenerator/cli/templates/dynamic/codegen/src/TestHelpers_MockDb.res.hbs b/codegenerator/cli/templates/dynamic/codegen/src/TestHelpers_MockDb.res.hbs index cf4e4c99c..aaba3adce 100644 --- a/codegenerator/cli/templates/dynamic/codegen/src/TestHelpers_MockDb.res.hbs +++ b/codegenerator/cli/templates/dynamic/codegen/src/TestHelpers_MockDb.res.hbs @@ -34,7 +34,7 @@ open Belt /** A raw js binding to allow deleting from a dict. Used in store delete operation */ -let deleteDictKey: (Js.Dict.t<'a>, string) => unit = %raw(` +let deleteDictKey: (dict<'a>, string) => unit = %raw(` function(dict, key) { delete dict[key] } diff --git a/codegenerator/cli/templates/static/codegen/src/ConfigYAML.res b/codegenerator/cli/templates/static/codegen/src/ConfigYAML.res index 63ee51dca..2c6e784fe 100644 --- a/codegenerator/cli/templates/static/codegen/src/ConfigYAML.res +++ b/codegenerator/cli/templates/static/codegen/src/ConfigYAML.res @@ -15,7 +15,7 @@ type configYaml = { syncSource: aliasSyncSource, startBlock: int, confirmedBlockThreshold: int, - contracts: Js.Dict.t, + contracts: dict, } let mapChainConfigToConfigYaml: Config.chainConfig => configYaml = chainConfig => { diff --git a/codegenerator/cli/templates/static/codegen/src/ContractAddressingMap.res b/codegenerator/cli/templates/static/codegen/src/ContractAddressingMap.res index 18597a043..aab89f332 100644 --- a/codegenerator/cli/templates/static/codegen/src/ContractAddressingMap.res +++ b/codegenerator/cli/templates/static/codegen/src/ContractAddressingMap.res @@ -7,8 +7,8 @@ exception UndefinedContractAddress(Ethers.ethAddress) // protecting static addresses from de-registration. type mapping = { - nameByAddress: Js.Dict.t, - addressesByName: Js.Dict.t, + nameByAddress: dict, + addressesByName: dict, } let addAddress = (map: mapping, ~name: string, ~address: Ethers.ethAddress) => { diff --git a/codegenerator/cli/templates/static/codegen/src/ContractInterfaceManager.res b/codegenerator/cli/templates/static/codegen/src/ContractInterfaceManager.res index c30baa883..70c0b9018 100644 --- a/codegenerator/cli/templates/static/codegen/src/ContractInterfaceManager.res +++ b/codegenerator/cli/templates/static/codegen/src/ContractInterfaceManager.res @@ -10,7 +10,7 @@ type interfaceAndAbi = { } type t = { contractAddressMapping: ContractAddressingMap.mapping, - contractNameInterfaceMapping: Js.Dict.t, + contractNameInterfaceMapping: dict, } let make = ( diff --git a/codegenerator/cli/templates/static/codegen/src/EventUtils.res b/codegenerator/cli/templates/static/codegen/src/EventUtils.res index 0fce3f9a6..081f90812 100644 --- a/codegenerator/cli/templates/static/codegen/src/EventUtils.res +++ b/codegenerator/cli/templates/static/codegen/src/EventUtils.res @@ -31,42 +31,42 @@ type eventIndex = { // takes blockNumber, logIndex and packs them into a number with //32 bits, 16 bits and 16 bits respectively let packEventIndex = (~blockNumber, ~logIndex) => { - let blockNumber = blockNumber->Ethers.BigInt.fromInt - let logIndex = logIndex->Ethers.BigInt.fromInt - let blockNumber = Ethers.BigInt.Bitwise.shift_left(blockNumber, 16->Ethers.BigInt.fromInt) + let blockNumber = blockNumber->BigInt.fromInt + let logIndex = logIndex->BigInt.fromInt + let blockNumber = BigInt.Bitwise.shift_left(blockNumber, 16->BigInt.fromInt) - blockNumber->Ethers.BigInt.Bitwise.logor(logIndex) + blockNumber->BigInt.Bitwise.logor(logIndex) } //Currently not used but keeping in utils //using @live flag for dead code analyser @live let packMultiChainEventIndex = (~timestamp, ~chainId, ~blockNumber, ~logIndex) => { - let timestamp = timestamp->Ethers.BigInt.fromInt - let chainId = chainId->Ethers.BigInt.fromInt - let blockNumber = blockNumber->Ethers.BigInt.fromInt - let logIndex = logIndex->Ethers.BigInt.fromInt + let timestamp = timestamp->BigInt.fromInt + let chainId = chainId->BigInt.fromInt + let blockNumber = blockNumber->BigInt.fromInt + let logIndex = logIndex->BigInt.fromInt - let timestamp = Ethers.BigInt.Bitwise.shift_left(timestamp, 48->Ethers.BigInt.fromInt) - let chainId = Ethers.BigInt.Bitwise.shift_left(chainId, 16->Ethers.BigInt.fromInt) - let blockNumber = Ethers.BigInt.Bitwise.shift_left(blockNumber, 16->Ethers.BigInt.fromInt) + let timestamp = BigInt.Bitwise.shift_left(timestamp, 48->BigInt.fromInt) + let chainId = BigInt.Bitwise.shift_left(chainId, 16->BigInt.fromInt) + let blockNumber = BigInt.Bitwise.shift_left(blockNumber, 16->BigInt.fromInt) timestamp - ->Ethers.BigInt.Bitwise.logor(chainId) - ->Ethers.BigInt.Bitwise.logor(blockNumber) - ->Ethers.BigInt.Bitwise.logor(logIndex) + ->BigInt.Bitwise.logor(chainId) + ->BigInt.Bitwise.logor(blockNumber) + ->BigInt.Bitwise.logor(logIndex) } //Currently not used but keeping in utils //using @live flag for dead code analyser @live -let unpackEventIndex = (packedEventIndex: Ethers.BigInt.t) => { - let blockNumber = packedEventIndex->Ethers.BigInt.Bitwise.shift_right(16->Ethers.BigInt.fromInt) - let logIndexMask = 65535->Ethers.BigInt.fromInt - let logIndex = packedEventIndex->Ethers.BigInt.Bitwise.logand(logIndexMask) +let unpackEventIndex = (packedEventIndex: bigint) => { + let blockNumber = packedEventIndex->BigInt.Bitwise.shift_right(16->BigInt.fromInt) + let logIndexMask = 65535->BigInt.fromInt + let logIndex = packedEventIndex->BigInt.Bitwise.logand(logIndexMask) { - blockNumber: blockNumber->Ethers.BigInt.toString->Belt.Int.fromString->Belt.Option.getUnsafe, - logIndex: logIndex->Ethers.BigInt.toString->Belt.Int.fromString->Belt.Option.getUnsafe, + blockNumber: blockNumber->BigInt.toString->Belt.Int.fromString->Belt.Option.getUnsafe, + logIndex: logIndex->BigInt.toString->Belt.Int.fromString->Belt.Option.getUnsafe, } } diff --git a/codegenerator/cli/templates/static/codegen/src/InMemoryTable.res b/codegenerator/cli/templates/static/codegen/src/InMemoryTable.res index 0b7d02446..197c56646 100644 --- a/codegenerator/cli/templates/static/codegen/src/InMemoryTable.res +++ b/codegenerator/cli/templates/static/codegen/src/InMemoryTable.res @@ -1,7 +1,7 @@ open Belt type t<'key, 'val> = { - dict: Js.Dict.t<'val>, + dict: dict<'val>, hash: 'key => string, } diff --git a/codegenerator/cli/templates/static/codegen/src/LazyLoader.res b/codegenerator/cli/templates/static/codegen/src/LazyLoader.res index 1f20ccbbc..988124c2f 100644 --- a/codegenerator/cli/templates/static/codegen/src/LazyLoader.res +++ b/codegenerator/cli/templates/static/codegen/src/LazyLoader.res @@ -17,9 +17,9 @@ type asyncMap<'a> = { // How long to wait before cancelling a load request _timeoutMillis: int, // The promises we return to callers. We satisfy them asynchronously. - externalPromises: Js.Dict.t>, + externalPromises: dict>, // The handled used to populate the external promises once we have loaded their data. - resolvers: Js.Dict.t<(. 'a) => unit>, + resolvers: dict<(. 'a) => unit>, // The keys currently being loaded inProgress: Belt.MutableSet.Int.t, // Keys for items that we have not started loading yet. @@ -54,7 +54,7 @@ let make = ( metadata, } -let deleteKey: (Js.Dict.t<'a>, string) => unit = (_obj, _k) => %raw(`delete _obj[_k]`) +let deleteKey: (dict<'a>, string) => unit = (_obj, _k) => %raw(`delete _obj[_k]`) // If something takes longer than this to load, reject the promise and try again let timeoutAfter = timeoutMillis => diff --git a/codegenerator/cli/templates/static/codegen/src/RegisteredEvents.res b/codegenerator/cli/templates/static/codegen/src/RegisteredEvents.res index a94b95af5..4cf98ae49 100644 --- a/codegenerator/cli/templates/static/codegen/src/RegisteredEvents.res +++ b/codegenerator/cli/templates/static/codegen/src/RegisteredEvents.res @@ -28,8 +28,8 @@ type registeredEvent<'eventArgs, 'loaderReturn> = { } type t = { - loaderHandlers: Js.Dict.t>, - contractRegisters: Js.Dict.t>, + loaderHandlers: dict>, + contractRegisters: dict>, } let make = () => { diff --git a/codegenerator/cli/templates/static/codegen/src/bindings/BigDecimal.res b/codegenerator/cli/templates/static/codegen/src/bindings/BigDecimal.res index 370d3deef..4f31b7de9 100644 --- a/codegenerator/cli/templates/static/codegen/src/bindings/BigDecimal.res +++ b/codegenerator/cli/templates/static/codegen/src/bindings/BigDecimal.res @@ -14,7 +14,7 @@ type rec t = { } // Constructors -@new @module external fromBigInt: Ethers.BigInt.t => t = "bignumber.js" +@new @module external fromBigInt: bigint => t = "bignumber.js" @new @module external fromFloat: float => t = "bignumber.js" @new @module external fromInt: int => t = "bignumber.js" @new @module external fromStringUnsafe: string => t = "bignumber.js" diff --git a/codegenerator/cli/templates/static/codegen/src/bindings/BigInt.res b/codegenerator/cli/templates/static/codegen/src/bindings/BigInt.res index 8a235d87e..a34c0a685 100644 --- a/codegenerator/cli/templates/static/codegen/src/bindings/BigInt.res +++ b/codegenerator/cli/templates/static/codegen/src/bindings/BigInt.res @@ -1,7 +1,5 @@ -@genType.import(("./OpaqueTypes.ts", "GenericBigInt")) -type t - -module Misc = { +%%private( + @inline let unsafeToOption: (unit => 'a) => option<'a> = unsafeFunc => { try { unsafeFunc()->Some @@ -9,38 +7,38 @@ module Misc = { | Js.Exn.Error(_obj) => None } } -} +) // constructors and methods -@val external fromInt: int => t = "BigInt" -@val external fromStringUnsafe: string => t = "BigInt" -let fromString = str => Misc.unsafeToOption(() => str->fromStringUnsafe) -@send external toString: t => string = "toString" -let toInt = (b: t): option => b->toString->Belt.Int.fromString +@val external fromInt: int => bigint = "BigInt" +@val external fromStringUnsafe: string => bigint = "BigInt" +let fromString = str => unsafeToOption(() => str->fromStringUnsafe) +@send external toString: bigint => string = "toString" +let toInt = (b: bigint): option => b->toString->Belt.Int.fromString //silence unused var warnings for raw bindings @@warning("-27") // operation -let add = (a: t, b: t): t => %raw("a + b") -let sub = (a: t, b: t): t => %raw("a - b") -let mul = (a: t, b: t): t => %raw("a * b") -let div = (a: t, b: t): t => %raw("b > 0n ? a / b : 0n") -let pow = (a: t, b: t): t => %raw("a ** b") -let mod = (a: t, b: t): t => %raw("b > 0n ? a % b : 0n") +let add = (a: bigint, b: bigint): bigint => %raw("a + b") +let sub = (a: bigint, b: bigint): bigint => %raw("a - b") +let mul = (a: bigint, b: bigint): bigint => %raw("a * b") +let div = (a: bigint, b: bigint): bigint => %raw("b > 0n ? a / b : 0n") +let pow = (a: bigint, b: bigint): bigint => %raw("a ** b") +let mod = (a: bigint, b: bigint): bigint => %raw("b > 0n ? a % b : 0n") // comparison -let eq = (a: t, b: t): bool => %raw("a === b") -let neq = (a: t, b: t): bool => %raw("a !== b") -let gt = (a: t, b: t): bool => %raw("a > b") -let gte = (a: t, b: t): bool => %raw("a >= b") -let lt = (a: t, b: t): bool => %raw("a < b") -let lte = (a: t, b: t): bool => %raw("a <= b") +let eq = (a: bigint, b: bigint): bool => %raw("a === b") +let neq = (a: bigint, b: bigint): bool => %raw("a !== b") +let gt = (a: bigint, b: bigint): bool => %raw("a > b") +let gte = (a: bigint, b: bigint): bool => %raw("a >= b") +let lt = (a: bigint, b: bigint): bool => %raw("a < b") +let lte = (a: bigint, b: bigint): bool => %raw("a <= b") module Bitwise = { - let shift_left = (a: t, b: t): t => %raw("a << b") - let shift_right = (a: t, b: t): t => %raw("a >> b") - let logor = (a: t, b: t): t => %raw("a | b") - let logand = (a: t, b: t): t => %raw("a & b") + let shift_left = (a: bigint, b: bigint): bigint => %raw("a << b") + let shift_right = (a: bigint, b: bigint): bigint => %raw("a >> b") + let logor = (a: bigint, b: bigint): bigint => %raw("a | b") + let logand = (a: bigint, b: bigint): bigint => %raw("a & b") } let zero = fromInt(0) diff --git a/codegenerator/cli/templates/static/codegen/src/bindings/Ethers.res b/codegenerator/cli/templates/static/codegen/src/bindings/Ethers.res index cabb76d0a..4ad8166a2 100644 --- a/codegenerator/cli/templates/static/codegen/src/bindings/Ethers.res +++ b/codegenerator/cli/templates/static/codegen/src/bindings/Ethers.res @@ -11,8 +11,6 @@ module Misc = { } } -module BigInt = BigInt - type abi let makeHumanReadableAbi = (abiArray: array): abi => abiArray->Obj.magic @@ -232,11 +230,11 @@ module JsonRpcProvider = { external getBlockNumber: t => promise = "getBlockNumber" type block = { - _difficulty: BigInt.t, + _difficulty: bigint, difficulty: int, extraData: ethAddress, - gasLimit: BigInt.t, - gasUsed: BigInt.t, + gasLimit: bigint, + gasUsed: bigint, hash: string, miner: ethAddress, nonce: int, diff --git a/codegenerator/cli/templates/static/codegen/src/bindings/HyperSyncClient.res b/codegenerator/cli/templates/static/codegen/src/bindings/HyperSyncClient.res index 55f061bcf..158dd8472 100644 --- a/codegenerator/cli/templates/static/codegen/src/bindings/HyperSyncClient.res +++ b/codegenerator/cli/templates/static/codegen/src/bindings/HyperSyncClient.res @@ -121,15 +121,15 @@ module ResponseTypes = { stateRoot?: string, receiptsRoot?: string, miner?: unchecksummedEthAddress, - difficulty?: Ethers.BigInt.t, //nullable - totalDifficulty?: Ethers.BigInt.t, //nullable + difficulty?: bigint, //nullable + totalDifficulty?: bigint, //nullable extraData?: string, - size?: Ethers.BigInt.t, - gasLimit?: Ethers.BigInt.t, - gasUsed?: Ethers.BigInt.t, + size?: bigint, + gasLimit?: bigint, + gasUsed?: bigint, timestamp?: int, uncles?: string, //nullable - baseFeePerGas?: Ethers.BigInt.t, //nullable + baseFeePerGas?: bigint, //nullable } //Note all fields marked as "nullable" are not explicitly null since @@ -139,23 +139,23 @@ module ResponseTypes = { blockHash?: string, blockNumber?: int, from?: unchecksummedEthAddress, //nullable - gas?: Ethers.BigInt.t, - gasPrice?: Ethers.BigInt.t, //nullable + gas?: bigint, + gasPrice?: bigint, //nullable hash?: string, input?: string, nonce?: int, to?: unchecksummedEthAddress, //nullable @as("transactionIndex") transactionIndex?: int, - value?: Ethers.BigInt.t, + value?: bigint, v?: string, //nullable r?: string, //nullable s?: string, //nullable - maxPriorityFeePerGas?: Ethers.BigInt.t, //nullable - maxFeePerGas?: Ethers.BigInt.t, //nullable + maxPriorityFeePerGas?: bigint, //nullable + maxFeePerGas?: bigint, //nullable chainId?: int, //nullable - cumulativeGasUsed?: Ethers.BigInt.t, - effectiveGasPrice?: Ethers.BigInt.t, - gasUsed?: Ethers.BigInt.t, + cumulativeGasUsed?: bigint, + effectiveGasPrice?: bigint, + gasUsed?: bigint, contractAddress?: unchecksummedEthAddress, //nullable logsBoom?: string, type_?: int, //nullable @@ -238,7 +238,7 @@ let make = (cfg: cfg) => { let sendEventsReq = Internal.sendEventsReq module Decoder = { - type abiMapping = Js.Dict.t + type abiMapping = dict type constructor @module("@envio-dev/hypersync-client") external constructor: constructor = "Decoder" diff --git a/codegenerator/cli/templates/static/codegen/src/bindings/OpaqueTypes.ts b/codegenerator/cli/templates/static/codegen/src/bindings/OpaqueTypes.ts index 4d5898c88..c71d1b05d 100644 --- a/codegenerator/cli/templates/static/codegen/src/bindings/OpaqueTypes.ts +++ b/codegenerator/cli/templates/static/codegen/src/bindings/OpaqueTypes.ts @@ -1,3 +1,2 @@ -export type GenericBigInt = bigint; export type EthersAddress = string; export type Nullable = null | T; diff --git a/codegenerator/cli/templates/static/codegen/src/bindings/Pino.res b/codegenerator/cli/templates/static/codegen/src/bindings/Pino.res index f3650e37a..69e59b388 100644 --- a/codegenerator/cli/templates/static/codegen/src/bindings/Pino.res +++ b/codegenerator/cli/templates/static/codegen/src/bindings/Pino.res @@ -60,7 +60,7 @@ module Transport = { target?: string, targets?: array, options?: optionsObject, - levels?: Js.Dict.t, + levels?: dict, level?: logLevel, } @module("pino") @@ -82,7 +82,7 @@ type serializers = {err: Js.Json.t => Js.Json.t} type options = { name?: string, level?: logLevel, - customLevels?: Js.Dict.t, + customLevels?: dict, useOnlyCustomLevels?: bool, depthLimit?: int, edgeLimit?: int, @@ -158,7 +158,7 @@ module MultiStreamLogger = { let make = ( ~userLogLevel: logLevel, - ~customLevels: Js.Dict.t, + ~customLevels: dict, ~logFile: option, ~options: option, ~defaultFileLogLevel, diff --git a/codegenerator/cli/templates/static/codegen/src/db/DbFunctions.res b/codegenerator/cli/templates/static/codegen/src/db/DbFunctions.res index 3510a0fa5..bfeab1c43 100644 --- a/codegenerator/cli/templates/static/codegen/src/db/DbFunctions.res +++ b/codegenerator/cli/templates/static/codegen/src/db/DbFunctions.res @@ -126,7 +126,7 @@ module RawEvents = { external getRawEventsPageGtOrEqEventId: ( Postgres.sql, ~chainId: chainId, - ~eventId: Ethers.BigInt.t, + ~eventId: bigint, ~limit: int, ~contractAddresses: array, ) => promise> = "getRawEventsPageGtOrEqEventId" @@ -135,8 +135,8 @@ module RawEvents = { external getRawEventsPageWithinEventIdRangeInclusive: ( Postgres.sql, ~chainId: chainId, - ~fromEventIdInclusive: Ethers.BigInt.t, - ~toEventIdInclusive: Ethers.BigInt.t, + ~fromEventIdInclusive: bigint, + ~toEventIdInclusive: bigint, ~limit: int, ~contractAddresses: array, ) => promise> = "getRawEventsPageWithinEventIdRangeInclusive" @@ -184,13 +184,13 @@ module DynamicContractRegistry = { type contractTypeAndAddress = { @as("contract_address") contractAddress: Ethers.ethAddress, @as("contract_type") contractType: string, - @as("event_id") eventId: Ethers.BigInt.t, + @as("event_id") eventId: bigint, } let contractTypeAndAddressSchema = S.object((. s) => { contractAddress: s.field("contract_address", Ethers.ethAddressSchema), contractType: s.field("contract_type", S.string), - eventId: s.field("event_id", Ethers.BigInt.schema), + eventId: s.field("event_id", BigInt.schema), }) let contractTypeAndAddressArraySchema = S.array(contractTypeAndAddressSchema) diff --git a/codegenerator/cli/templates/static/codegen/src/db/Schema.res b/codegenerator/cli/templates/static/codegen/src/db/Schema.res index 7bc513f98..acbc8c956 100644 --- a/codegenerator/cli/templates/static/codegen/src/db/Schema.res +++ b/codegenerator/cli/templates/static/codegen/src/db/Schema.res @@ -1,5 +1,5 @@ open Belt -type t = Js.Dict.t +type t = dict let make = (tables: array) => { tables->Array.map(table => (table.tableName, table))->Js.Dict.fromArray diff --git a/codegenerator/cli/templates/static/codegen/src/db/TablesStatic.res b/codegenerator/cli/templates/static/codegen/src/db/TablesStatic.res index 4eaf2168c..1e0e30e66 100644 --- a/codegenerator/cli/templates/static/codegen/src/db/TablesStatic.res +++ b/codegenerator/cli/templates/static/codegen/src/db/TablesStatic.res @@ -145,7 +145,7 @@ module DynamicContractRegistry = { @genType type t = { @as("chain_id") chainId: int, - @as("event_id") eventId: Ethers.BigInt.t, + @as("event_id") eventId: bigint, @as("block_timestamp") blockTimestamp: int, @as("contract_address") contractAddress: Ethers.ethAddress, @as("contract_type") contractType: Enums.ContractType.t, diff --git a/codegenerator/cli/templates/static/codegen/src/eventFetching/chainWorkers/RawEventsWorker.res b/codegenerator/cli/templates/static/codegen/src/eventFetching/chainWorkers/RawEventsWorker.res index 5da71694c..653b106a8 100644 --- a/codegenerator/cli/templates/static/codegen/src/eventFetching/chainWorkers/RawEventsWorker.res +++ b/codegenerator/cli/templates/static/codegen/src/eventFetching/chainWorkers/RawEventsWorker.res @@ -4,21 +4,20 @@ let pageLimitSize = 50_000 module PreviousDynamicContractAddresses: { - type registration = {address: Ethers.ethAddress, eventId: Ethers.BigInt.t} + type registration = {address: Ethers.ethAddress, eventId: bigint} type matchingRegistration = SameOrLater(registration) | Earlier(registration) type t let make: unit => t let add: (t, registration) => unit - let getRegistration: (t, Ethers.ethAddress, Ethers.BigInt.t) => option + let getRegistration: (t, Ethers.ethAddress, bigint) => option let getUnusedContractRegistrations: (t, ContractAddressingMap.mapping) => array } = { - type registration = {address: Ethers.ethAddress, eventId: Ethers.BigInt.t} - type t = Js.Dict.t + type registration = {address: Ethers.ethAddress, eventId: bigint} + type t = dict let make = () => Js.Dict.empty() let ethAddressToString = Ethers.ethAddressToString - module BigInt = Ethers.BigInt let add = (self: t, registration: registration) => self->Js.Dict.set(registration.address->ethAddressToString, registration) @@ -29,11 +28,11 @@ module PreviousDynamicContractAddresses: { type matchingRegistration = SameOrLater(registration) | Earlier(registration) - let getRegistration = (self: t, address, eventId: BigInt.t) => { + let getRegistration = (self: t, address, eventId: bigint) => { self ->get(address) ->Belt.Option.map(reg => { - reg.eventId->Ethers.BigInt.gte(eventId) ? SameOrLater(reg) : Earlier(reg) + reg.eventId->BigInt.gte(eventId) ? SameOrLater(reg) : Earlier(reg) }) } @@ -57,7 +56,7 @@ module PreviousDynamicContractAddresses: { type rec t = { mutable latestFetchedBlockTimestamp: int, - mutable latestFetchedEventId: promise, + mutable latestFetchedEventId: promise, chain: ChainMap.Chain.t, newRangeQueriedCallBacks: SDSL.Queue.t unit>, previousDynamicContractAddresses: PreviousDynamicContractAddresses.t, @@ -103,7 +102,7 @@ let make = (~caughtUpToHeadHook=?, ~contractAddressMapping=?, chainConfig: Confi contractAddressMapping->ContractAddressingMap.registerStaticAddresses(~chainConfig, ~logger) { latestFetchedBlockTimestamp: 0, - latestFetchedEventId: Ethers.BigInt.fromInt(0)->Promise.resolve, + latestFetchedEventId: BigInt.fromInt(0)->Promise.resolve, chain: chainConfig.chain, newRangeQueriedCallBacks: SDSL.Queue.make(), contractAddressMapping, @@ -123,7 +122,7 @@ let startWorker = async ( //ignore these two values let _ = (startBlock, logger, checkHasReorgOccurred) - let eventIdRef = ref(0->Ethers.BigInt.fromInt) + let eventIdRef = ref(0->BigInt.fromInt) let hasMoreRawEvents = ref(true) @@ -182,9 +181,9 @@ let startWorker = async ( latestEventIdResolve(lastFetchedEventId) hasMoreRawEvents := false | Some(item) => - let lastEventId = item.eventId->Ethers.BigInt.fromStringUnsafe + let lastEventId = item.eventId->BigInt.fromStringUnsafe latestEventIdResolve(lastEventId) - eventIdRef := lastEventId->Ethers.BigInt.add(1->Ethers.BigInt.fromInt) + eventIdRef := lastEventId->BigInt.add(1->BigInt.fromInt) self.latestFetchedBlockTimestamp = item.blockTimestamp } } @@ -339,11 +338,11 @@ let addDynamicContractAndFetchMissingEvents = async ( //Recursively collect all existing raw events in relation to dynamic contracts let rec getExistingFromRawEvents: ( ~queueItems: array=?, - ~fromEventId: Ethers.BigInt.t, + ~fromEventId: bigint, unit, ) => promise> = async ( ~queueItems: option>=?, - ~fromEventId: Ethers.BigInt.t, + ~fromEventId: bigint, (), ) => { let page = await getPageFromRawEvents(~fromEventId) diff --git a/codegenerator/cli/templates/static/codegen/src/eventFetching/hypersync/HyperSync.res b/codegenerator/cli/templates/static/codegen/src/eventFetching/hypersync/HyperSync.res index 29532f2de..7869d30d0 100644 --- a/codegenerator/cli/templates/static/codegen/src/eventFetching/hypersync/HyperSync.res +++ b/codegenerator/cli/templates/static/codegen/src/eventFetching/hypersync/HyperSync.res @@ -76,7 +76,7 @@ let getExn = (queryResponse: queryResponse<'a>) => //Ideally client should be passed in as a param to the functions but //we are still sharing the same signature with eth archive query builder module CachedClients = { - let cache: Js.Dict.t = Js.Dict.empty() + let cache: dict = Js.Dict.empty() let getClient = url => { switch cache->Js.Dict.get(url) { @@ -296,7 +296,7 @@ module BlockData = { block => { switch block { | {number: blockNumber, timestamp, hash: blockHash} => - let blockTimestamp = timestamp->Ethers.BigInt.toInt->Belt.Option.getExn + let blockTimestamp = timestamp->BigInt.toInt->Belt.Option.getExn Ok( ( { diff --git a/codegenerator/cli/templates/static/codegen/src/eventFetching/hypersync/HyperSyncJsonApi.res b/codegenerator/cli/templates/static/codegen/src/eventFetching/hypersync/HyperSyncJsonApi.res index 72de79bfb..4f1ee13b7 100644 --- a/codegenerator/cli/templates/static/codegen/src/eventFetching/hypersync/HyperSyncJsonApi.res +++ b/codegenerator/cli/templates/static/codegen/src/eventFetching/hypersync/HyperSyncJsonApi.res @@ -209,15 +209,15 @@ module ResponseTypes = { stateRoot?: string, receiptsRoot?: string, miner?: unchecksummedEthAddress, - difficulty?: option, - totalDifficulty?: option, + difficulty?: option, + totalDifficulty?: option, extraData?: string, - size?: Ethers.BigInt.t, - gasLimit?: Ethers.BigInt.t, - gasUsed?: Ethers.BigInt.t, - timestamp?: Ethers.BigInt.t, + size?: bigint, + gasLimit?: bigint, + gasUsed?: bigint, + timestamp?: bigint, uncles?: option, - baseFeePerGas?: option, + baseFeePerGas?: option, } let blockDataSchema = S.object((. s) => { @@ -231,38 +231,38 @@ module ResponseTypes = { stateRoot: ?s.field("state_root", S.option(S.string)), receiptsRoot: ?s.field("receipts_root", S.option(S.string)), miner: ?s.field("miner", S.option(S.string)), - difficulty: ?s.field("difficulty", S.option(S.null(Ethers.BigInt.schema))), - totalDifficulty: ?s.field("total_difficulty", S.option(S.null(Ethers.BigInt.schema))), + difficulty: ?s.field("difficulty", S.option(S.null(BigInt.schema))), + totalDifficulty: ?s.field("total_difficulty", S.option(S.null(BigInt.schema))), extraData: ?s.field("extra_data", S.option(S.string)), - size: ?s.field("size", S.option(Ethers.BigInt.schema)), - gasLimit: ?s.field("gas_limit", S.option(Ethers.BigInt.schema)), - gasUsed: ?s.field("gas_used", S.option(Ethers.BigInt.schema)), - timestamp: ?s.field("timestamp", S.option(Ethers.BigInt.schema)), + size: ?s.field("size", S.option(BigInt.schema)), + gasLimit: ?s.field("gas_limit", S.option(BigInt.schema)), + gasUsed: ?s.field("gas_used", S.option(BigInt.schema)), + timestamp: ?s.field("timestamp", S.option(BigInt.schema)), uncles: ?s.field("unclus", S.option(S.null(S.string))), - baseFeePerGas: ?s.field("base_fee_per_gas", S.option(S.null(Ethers.BigInt.schema))), + baseFeePerGas: ?s.field("base_fee_per_gas", S.option(S.null(BigInt.schema))), }) type transactionData = { blockHash?: string, blockNumber?: int, from?: option, - gas?: Ethers.BigInt.t, - gasPrice?: option, + gas?: bigint, + gasPrice?: option, hash?: string, input?: string, nonce?: int, to?: option, transactionIndex?: int, - value?: Ethers.BigInt.t, + value?: bigint, v?: option, r?: option, s?: option, - maxPriorityFeePerGas?: option, - maxFeePerGas?: option, + maxPriorityFeePerGas?: option, + maxFeePerGas?: option, chainId?: option, - cumulativeGasUsed?: Ethers.BigInt.t, - effectiveGasPrice?: Ethers.BigInt.t, - gasUsed?: Ethers.BigInt.t, + cumulativeGasUsed?: bigint, + effectiveGasPrice?: bigint, + gasUsed?: bigint, contractAddress?: option, logsBoom?: string, type_?: option, @@ -275,26 +275,26 @@ module ResponseTypes = { blockHash: ?s.field("block_hash", S.option(S.string)), blockNumber: ?s.field("block_number", S.option(S.int)), from: ?s.field("from", S.option(S.null(S.string))), - gas: ?s.field("gas", S.option(Ethers.BigInt.schema)), - gasPrice: ?s.field("gas_price", S.option(S.null(Ethers.BigInt.schema))), + gas: ?s.field("gas", S.option(BigInt.schema)), + gasPrice: ?s.field("gas_price", S.option(S.null(BigInt.schema))), hash: ?s.field("hash", S.option(S.string)), input: ?s.field("input", S.option(S.string)), nonce: ?s.field("nonce", S.option(S.int)), to: ?s.field("to", S.option(S.null(S.string))), transactionIndex: ?s.field("transaction_index", S.option(S.int)), - value: ?s.field("value", S.option(Ethers.BigInt.schema)), + value: ?s.field("value", S.option(BigInt.schema)), v: ?s.field("v", S.option(S.null(S.string))), r: ?s.field("r", S.option(S.null(S.string))), s: ?s.field("s", S.option(S.null(S.string))), maxPriorityFeePerGas: ?s.field( "max_priority_fee_per_gas", - S.option(S.null(Ethers.BigInt.schema)), + S.option(S.null(BigInt.schema)), ), - maxFeePerGas: ?s.field("max_fee_per_gas", S.option(S.null(Ethers.BigInt.schema))), + maxFeePerGas: ?s.field("max_fee_per_gas", S.option(S.null(BigInt.schema))), chainId: ?s.field("chain_id", S.option(S.null(S.int))), - cumulativeGasUsed: ?s.field("cumulative_gas_used", S.option(Ethers.BigInt.schema)), - effectiveGasPrice: ?s.field("effective_gas_price", S.option(Ethers.BigInt.schema)), - gasUsed: ?s.field("gas_used", S.option(Ethers.BigInt.schema)), + cumulativeGasUsed: ?s.field("cumulative_gas_used", S.option(BigInt.schema)), + effectiveGasPrice: ?s.field("effective_gas_price", S.option(BigInt.schema)), + gasUsed: ?s.field("gas_used", S.option(BigInt.schema)), contractAddress: ?s.field("contract_address", S.option(S.null(S.string))), logsBoom: ?s.field("logs_bloom", S.option(S.string)), type_: ?s.field("type", S.option(S.null(S.int))), diff --git a/codegenerator/cli/templates/static/erc20_template/rescript/src/EventHandlers.res b/codegenerator/cli/templates/static/erc20_template/rescript/src/EventHandlers.res index c8082ba8d..f92781e08 100644 --- a/codegenerator/cli/templates/static/erc20_template/rescript/src/EventHandlers.res +++ b/codegenerator/cli/templates/static/erc20_template/rescript/src/EventHandlers.res @@ -8,7 +8,7 @@ Handlers.ERC20.Approval.handler(async ({event, context}) => { // setting Entities.Account.t object let accountObject: Entities.Account.t = { id: event.params.owner->Ethers.ethAddressToString, - balance: Ethers.BigInt.fromInt(0), + balance: BigInt.fromInt(0), } // setting the account-entity with the new transfer field value @@ -38,7 +38,7 @@ Handlers.ERC20.Transfer.handler(async ({event, context}) => { // subtract the balance from the existing users balance let accountObject: Entities.Account.t = { id: existingSenderAccount.id, - balance: existingSenderAccount.balance->Ethers.BigInt.sub(event.params.value), + balance: existingSenderAccount.balance->BigInt.sub(event.params.value), } context.account.set(accountObject) } @@ -48,7 +48,7 @@ Handlers.ERC20.Transfer.handler(async ({event, context}) => { // This is likely only ever going to be the zero address in the case of the first mint let accountObject: Entities.Account.t = { id: event.params.from->Ethers.ethAddressToString, - balance: Ethers.BigInt.fromInt(0)->Ethers.BigInt.sub(event.params.value), + balance: BigInt.fromInt(0)->BigInt.sub(event.params.value), } // setting the account-entity with the new transfer field value @@ -63,7 +63,7 @@ Handlers.ERC20.Transfer.handler(async ({event, context}) => { // update existing account's added balance let accountObject: Entities.Account.t = { id: existingReceiverAccount.id, - balance: existingReceiverAccount.balance->Ethers.BigInt.add(event.params.value), + balance: existingReceiverAccount.balance->BigInt.add(event.params.value), } context.account.set(accountObject) diff --git a/codegenerator/cli/templates/static/erc20_template/rescript/test/Test.res b/codegenerator/cli/templates/static/erc20_template/rescript/test/Test.res index ec080d9d5..aebc02af7 100644 --- a/codegenerator/cli/templates/static/erc20_template/rescript/test/Test.res +++ b/codegenerator/cli/templates/static/erc20_template/rescript/test/Test.res @@ -15,7 +15,7 @@ describe("Transfers", () => { //Make a mock entity to set the initial state of the mock db let mockAccountEntity: Entities.Account.t = { id: userAddress1->Ethers.ethAddressToString, - balance: Ethers.BigInt.fromInt(5), + balance: BigInt.fromInt(5), } //Set an initial state for the user @@ -27,7 +27,7 @@ describe("Transfers", () => { let mockTransfer = ERC20.Transfer.createMockEvent({ from: userAddress1, to: userAddress2, - value: Ethers.BigInt.fromInt(3), + value: BigInt.fromInt(3), }) //Process the mockEvent @@ -46,7 +46,7 @@ describe("Transfers", () => { //Assert the expected balance Assert.equal( - Some(Ethers.BigInt.fromInt(2)), + Some(BigInt.fromInt(2)), account1Balance, ~message="Should have subtracted transfer amount 3 from userAddress1 balance 5", ) @@ -58,7 +58,7 @@ describe("Transfers", () => { ) //Assert the expected balance Assert.equal( - Some(Ethers.BigInt.fromInt(3)), + Some(BigInt.fromInt(3)), account2Balance, ~message="Should have added transfer amount 3 to userAddress2 balance 0", ) diff --git a/scenarios/erc20_multichain_factory/src/EventHandlers.res b/scenarios/erc20_multichain_factory/src/EventHandlers.res index b1d7b38c3..08ba0bdaf 100644 --- a/scenarios/erc20_multichain_factory/src/EventHandlers.res +++ b/scenarios/erc20_multichain_factory/src/EventHandlers.res @@ -41,7 +41,7 @@ let createNewAccountWithZeroBalance = ( // setting the accountEntity with the new transfer field value setAccount(accountObject) - let accountToken = makeAccountToken(~account_id, ~tokenAddress, ~balance=Ethers.BigInt.fromInt(0)) + let accountToken = makeAccountToken(~account_id, ~tokenAddress, ~balance=BigInt.fromInt(0)) setAccountToken(accountToken) @@ -84,8 +84,8 @@ let manipulateAccountTokenBalance = (fn, accountToken: AccountToken.t, amount): {...accountToken, balance: accountToken.balance->fn(amount)} } -let addToBalance = manipulateAccountTokenBalance(Ethers.BigInt.add) -let subFromBalance = manipulateAccountTokenBalance(Ethers.BigInt.sub) +let addToBalance = manipulateAccountTokenBalance(BigInt.add) +let subFromBalance = manipulateAccountTokenBalance(BigInt.sub) let manipulateAccountBalance = ( optAccountToken, diff --git a/scenarios/erc20_multichain_factory/test/Handler_Test.res b/scenarios/erc20_multichain_factory/test/Handler_Test.res index 9602fe38c..c0fc0b25b 100644 --- a/scenarios/erc20_multichain_factory/test/Handler_Test.res +++ b/scenarios/erc20_multichain_factory/test/Handler_Test.res @@ -27,7 +27,7 @@ describe("Transfers", () => { let mockAccountTokenEntity = EventHandlers.makeAccountToken( ~account_id, ~tokenAddress, - ~balance=Ethers.BigInt.fromInt(5), + ~balance=BigInt.fromInt(5), ) //Set an initial state for the user @@ -41,7 +41,7 @@ describe("Transfers", () => { let mockTransfer = ERC20.Transfer.createMockEvent({ from: userAddress1, to: userAddress2, - value: Ethers.BigInt.fromInt(3), + value: BigInt.fromInt(3), }) //Process the mockEvent @@ -61,7 +61,7 @@ describe("Transfers", () => { //Assert the expected balance Assert.equal( account1Balance, - Some(Ethers.BigInt.fromInt(2)), + Some(BigInt.fromInt(2)), ~message="Should have subtracted transfer amount 3 from userAddress1 balance 5", ) @@ -75,7 +75,7 @@ describe("Transfers", () => { )->Option.map(a => a.balance) //Assert the expected balance Assert.equal( - Some(Ethers.BigInt.fromInt(3)), + Some(BigInt.fromInt(3)), account2Balance, ~message="Should have added transfer amount 3 to userAddress2 balance 0", ) diff --git a/scenarios/erc20_multichain_factory/test/RollbackDynamicContract_test.res b/scenarios/erc20_multichain_factory/test/RollbackDynamicContract_test.res index cc1863516..b79c1e880 100644 --- a/scenarios/erc20_multichain_factory/test/RollbackDynamicContract_test.res +++ b/scenarios/erc20_multichain_factory/test/RollbackDynamicContract_test.res @@ -23,7 +23,7 @@ ensure that this doesn't trigger a reorg let makeTransferMock = (~from, ~to, ~value): Types.ERC20.Transfer.eventArgs => { from, to, - value: value->Ethers.BigInt.fromInt, + value: value->BigInt.fromInt, } let makeTokenCreatedMock = (~token): Types.ERC20Factory.TokenCreated.eventArgs => { @@ -216,7 +216,7 @@ describe("Dynamic contract rollback test", () => { ~message=`Query ${queryName} should have returned ${totalQueueSize->Int.toString} events`, ) - let toBigInt = Ethers.BigInt.fromInt + let toBigInt = BigInt.fromInt let optIntToString = optInt => switch optInt { | Some(n) => `Some(${n->Int.toString})` @@ -236,7 +236,7 @@ describe("Dynamic contract rollback test", () => { balance, expectedBalance->Option.map(toBigInt), ~message=`Chain ${chain->ChainMap.Chain.toString} after processing blocks in batch ${batchName}, User ${user->Int.toString} should have a balance of ${expectedBalance->optIntToString} but has ${balance - ->Option.flatMap(Ethers.BigInt.toInt) + ->Option.flatMap(BigInt.toInt) ->optIntToString}`, ) } diff --git a/scenarios/erc20_multichain_factory/test/RollbackMultichain_test.res b/scenarios/erc20_multichain_factory/test/RollbackMultichain_test.res index 593a7e669..d6acbd9ad 100644 --- a/scenarios/erc20_multichain_factory/test/RollbackMultichain_test.res +++ b/scenarios/erc20_multichain_factory/test/RollbackMultichain_test.res @@ -39,7 +39,7 @@ module Mock = { let makeTransferMock = (~from, ~to, ~value): Types.ERC20.Transfer.eventArgs => { from, to, - value: value->Ethers.BigInt.fromInt, + value: value->BigInt.fromInt, } let mintAddress = Ethers.Constants.zeroAddress @@ -319,7 +319,7 @@ describe("Multichain rollback test", () => { ~message=`Query ${queryName} should have returned ${totalQueueSize->Int.toString} events`, ) - let toBigInt = Ethers.BigInt.fromInt + let toBigInt = BigInt.fromInt let optIntToString = optInt => switch optInt { | Some(n) => `Some(${n->Int.toString})` @@ -339,7 +339,7 @@ describe("Multichain rollback test", () => { expectedBalance->Option.map(toBigInt), balance, ~message=`Chain ${chain->ChainMap.Chain.toString} after processing blocks in batch ${batchName}, User ${user->Int.toString} should have a balance of ${expectedBalance->optIntToString} but has ${balance - ->Option.flatMap(Ethers.BigInt.toInt) + ->Option.flatMap(BigInt.toInt) ->optIntToString}`, ) } diff --git a/scenarios/erc20_multichain_factory/test/TestDeleteEntity.res b/scenarios/erc20_multichain_factory/test/TestDeleteEntity.res index 259f4fe47..fa930fddd 100644 --- a/scenarios/erc20_multichain_factory/test/TestDeleteEntity.res +++ b/scenarios/erc20_multichain_factory/test/TestDeleteEntity.res @@ -17,7 +17,7 @@ module Mock = { let makeTransferMock = (~from, ~to, ~value): Types.ERC20.Transfer.eventArgs => { from, to, - value: value->Ethers.BigInt.fromInt, + value: value->BigInt.fromInt, } let makeDeleteUserMock = (~user): Types.ERC20Factory.DeleteUser.eventArgs => { diff --git a/scenarios/gravatar/src/EventHandlers.res b/scenarios/gravatar/src/EventHandlers.res index ecc001541..5b4a52936 100644 --- a/scenarios/gravatar/src/EventHandlers.res +++ b/scenarios/gravatar/src/EventHandlers.res @@ -6,7 +6,7 @@ Handlers.GravatarContract.NewGravatar.loader((~event as _, ~context as _) => { Handlers.GravatarContract.NewGravatar.handler((~event, ~context) => { let gravatarObject: gravatarEntity = { - id: event.params.id->Ethers.BigInt.toString, + id: event.params.id->BigInt.toString, owner: event.params.owner->Ethers.ethAddressToString, displayName: event.params.displayName, imageUrl: event.params.imageUrl, @@ -17,7 +17,7 @@ Handlers.GravatarContract.NewGravatar.handler((~event, ~context) => { }) Handlers.GravatarContract.UpdatedGravatar.loader((~event, ~context) => { - let _ = context.gravatar.gravatarWithChangesLoad(event.params.id->Ethers.BigInt.toString) + let _ = context.gravatar.gravatarWithChangesLoad(event.params.id->BigInt.toString) }) Handlers.GravatarContract.UpdatedGravatar.handler((~event, ~context) => { @@ -27,7 +27,7 @@ Handlers.GravatarContract.UpdatedGravatar.handler((~event, ~context) => { ) let gravatar: gravatarEntity = { - id: event.params.id->Ethers.BigInt.toString, + id: event.params.id->BigInt.toString, owner: event.params.owner->Ethers.ethAddressToString, displayName: event.params.displayName, imageUrl: event.params.imageUrl, diff --git a/scenarios/nft-factory/README.md b/scenarios/nft-factory/README.md index b3e924a37..db14b54df 100644 --- a/scenarios/nft-factory/README.md +++ b/scenarios/nft-factory/README.md @@ -15,8 +15,7 @@ name: Gravatar description: Gravatar for Ethereum networks: - id: 137 - rpc_config: - https://polygon-rpc.com + rpc_config: https://polygon-rpc.com start_block: 34316032 contracts: - name: Gravatar @@ -86,7 +85,7 @@ The required functions to be registered are: ```rescript Handlers.GravatarContract.registerUpdatedGravatarLoadEntities((event, contextUpdator) => { - contextUpdator.gravatar.gravatarWithChangesLoad(event.params.id->Ethers.BigInt.toString) + contextUpdator.gravatar.gravatarWithChangesLoad(event.params.id->BigInt.toString) }) ``` @@ -115,7 +114,7 @@ Handlers.GravatarContract.registerUpdatedGravatarHandler((event, context) => { ) let gravatar: gravatarEntity = { - id: event.params.id->Ethers.BigInt.toString, + id: event.params.id->BigInt.toString, owner: event.params.owner->Ethers.ethAddressToString, displayName: event.params.displayName, imageUrl: event.params.imageUrl, @@ -169,6 +168,3 @@ pnpm run build pnpm run watch ``` - - - diff --git a/scenarios/ploffen/indexer/src/EventHandlers.res b/scenarios/ploffen/indexer/src/EventHandlers.res index 506cb4e35..d3d69fe97 100644 --- a/scenarios/ploffen/indexer/src/EventHandlers.res +++ b/scenarios/ploffen/indexer/src/EventHandlers.res @@ -12,10 +12,10 @@ Handlers.PloffenContract.CreatePloffen.handler((~event, ~context) => { let ploffenObject: ploffengameEntity = { id: "MASTER_GAME", gameToken: event.params.tokenGameAddress->Ethers.ethAddressToString, - seedAmount: Ethers.BigInt.fromInt(0), + seedAmount: BigInt.fromInt(0), gameStartTime: 0, status: "Created", - totalPot: Ethers.BigInt.fromInt(0), + totalPot: BigInt.fromInt(0), users: None, winner: None, possibleWinner: None, @@ -72,13 +72,13 @@ Handlers.PloffenContract.registerPlayPloffenHandler((~event, ~context) => { let userObject: userEntity = { ...user, numberOfTimesPlayed: user.numberOfTimesPlayed + 1, - totalContributed: user.totalContributed->Ethers.BigInt.add(event.params.amount), + totalContributed: user.totalContributed->BigInt.add(event.params.amount), } context.user.set(userObject) let ploffenObject: ploffengameEntity = { ...ploffen, - totalPot: ploffen.totalPot->Ethers.BigInt.add(event.params.amount), + totalPot: ploffen.totalPot->BigInt.add(event.params.amount), possibleGameWinTime: event.blockTimestamp + 3600, possibleWinner: Some(user.id), } @@ -96,7 +96,7 @@ Handlers.PloffenContract.registerPlayPloffenHandler((~event, ~context) => { let ploffenObject: ploffengameEntity = { ...ploffen, - totalPot: ploffen.totalPot->Ethers.BigInt.add(event.params.amount), + totalPot: ploffen.totalPot->BigInt.add(event.params.amount), possibleGameWinTime: event.blockTimestamp + 3600, possibleWinner: Some(userObject.id), users: Some(Array.append(ploffen.users->Belt.Option.getWithDefault([]), [userObject.id])), diff --git a/scenarios/test_codegen/package.json b/scenarios/test_codegen/package.json index 27a0147da..0c5151df6 100644 --- a/scenarios/test_codegen/package.json +++ b/scenarios/test_codegen/package.json @@ -20,7 +20,7 @@ "docker-down": "cargo run --manifest-path ../../codegenerator/cli/Cargo.toml -- local docker down", "db-setup": "cargo run --manifest-path ../../codegenerator/cli/Cargo.toml -- local db-migrate setup", "envio": "cargo run --manifest-path ../../codegenerator/cli/Cargo.toml --", - "start": "node ./generated/src/Index.bs.js" + "start": "ts-node ./generated/src/Index.bs.js" }, "keywords": [ "ReScript" diff --git a/scenarios/test_codegen/src/EventHandlers.res b/scenarios/test_codegen/src/EventHandlers.res index bc6ea7da3..a4d05e244 100644 --- a/scenarios/test_codegen/src/EventHandlers.res +++ b/scenarios/test_codegen/src/EventHandlers.res @@ -3,11 +3,11 @@ open Types Handlers.Gravatar.NewGravatar.handler(async ({event, context}) => { let gravatarSize: Enums.GravatarSize.t = SMALL let gravatarObject: gravatar = { - id: event.params.id->Ethers.BigInt.toString, + id: event.params.id->BigInt.toString, owner_id: event.params.owner->Ethers.ethAddressToString, displayName: event.params.displayName, imageUrl: event.params.imageUrl, - updatesCount: Ethers.BigInt.fromInt(1), + updatesCount: BigInt.fromInt(1), size: gravatarSize, } @@ -16,7 +16,7 @@ Handlers.Gravatar.NewGravatar.handler(async ({event, context}) => { Handlers.Gravatar.UpdatedGravatar.handlerWithLoader({ loader: ({event, context}) => { - context.gravatar.get(event.params.id->Ethers.BigInt.toString) + context.gravatar.get(event.params.id->BigInt.toString) }, handler: async ({event, context, loaderReturn}) => { /// Some examples of user logging @@ -57,13 +57,13 @@ Handlers.Gravatar.UpdatedGravatar.handlerWithLoader({ ) let updatesCount = - loaderReturn->Belt.Option.mapWithDefault(Ethers.BigInt.fromInt(1), gravatar => - gravatar.Entities.Gravatar.updatesCount->Ethers.BigInt.add(Ethers.BigInt.fromInt(1)) + loaderReturn->Belt.Option.mapWithDefault(BigInt.fromInt(1), gravatar => + gravatar.Entities.Gravatar.updatesCount->BigInt.add(BigInt.fromInt(1)) ) let gravatarSize: Enums.GravatarSize.t = MEDIUM let gravatar: Entities.Gravatar.t = { - id: event.params.id->Ethers.BigInt.toString, + id: event.params.id->BigInt.toString, owner_id: event.params.owner->Ethers.ethAddressToString, displayName: event.params.displayName, imageUrl: event.params.imageUrl, @@ -71,7 +71,7 @@ Handlers.Gravatar.UpdatedGravatar.handlerWithLoader({ size: gravatarSize, } - if event.params.id->Ethers.BigInt.toString == "1001" { + if event.params.id->BigInt.toString == "1001" { context.log.info("id matched, deleting gravatar 1004") context.gravatar.deleteUnsafe("1004") } diff --git a/scenarios/test_codegen/test/EventParsing_test.res b/scenarios/test_codegen/test/EventParsing_test.res index 5ed515d64..84b1b3b47 100644 --- a/scenarios/test_codegen/test/EventParsing_test.res +++ b/scenarios/test_codegen/test/EventParsing_test.res @@ -4,7 +4,7 @@ open Mocha describe("Parsing Raw Events", () => { it("Parses a raw event entity into a batch queue item", () => { let params: Types.Gravatar.NewGravatar.eventArgs = { - id: 1->Ethers.BigInt.fromInt, + id: 1->BigInt.fromInt, owner: "0xc944E90C64B2c07662A292be6244BDf05Cda44a7"->Ethers.getAddressFromStringUnsafe, displayName: "Testname", imageUrl: "myurl.com", diff --git a/scenarios/test_codegen/test/Mock_test.res b/scenarios/test_codegen/test/Mock_test.res index 1dfba49f2..13740913b 100644 --- a/scenarios/test_codegen/test/Mock_test.res +++ b/scenarios/test_codegen/test/Mock_test.res @@ -100,7 +100,7 @@ describe_skip("E2E Db check", () => { owner_id: "0x1230000000000000000000000000000000000000", displayName: "update1", imageUrl: "https://gravatar1.com", - updatesCount: Ethers.BigInt.fromInt(2), + updatesCount: BigInt.fromInt(2), size: MEDIUM, }, { @@ -108,7 +108,7 @@ describe_skip("E2E Db check", () => { owner_id: "0x4560000000000000000000000000000000000000", displayName: "update2", imageUrl: "https://gravatar2.com", - updatesCount: Ethers.BigInt.fromInt(2), + updatesCount: BigInt.fromInt(2), size: MEDIUM, }, { @@ -116,7 +116,7 @@ describe_skip("E2E Db check", () => { owner_id: "0x7890000000000000000000000000000000000000", displayName: "update3", imageUrl: "https://gravatar3.com", - updatesCount: Ethers.BigInt.fromInt(2), + updatesCount: BigInt.fromInt(2), size: MEDIUM, }, ], diff --git a/scenarios/test_codegen/test/__mocks__/DbStub.res b/scenarios/test_codegen/test/__mocks__/DbStub.res index c74385cc8..7d67621c5 100644 --- a/scenarios/test_codegen/test/__mocks__/DbStub.res +++ b/scenarios/test_codegen/test/__mocks__/DbStub.res @@ -1,6 +1,6 @@ -let deleteDictKey = (_dict: Js.Dict.t<'a>, _key: string) => %raw(`delete _dict[_key]`) +let deleteDictKey = (_dict: dict<'a>, _key: string) => %raw(`delete _dict[_key]`) -let databaseDict: Js.Dict.t = Js.Dict.empty() +let databaseDict: dict = Js.Dict.empty() let getGravatarDb = (~id: string) => { Js.Dict.get(databaseDict, id) diff --git a/scenarios/test_codegen/test/__mocks__/MockEntities.res b/scenarios/test_codegen/test/__mocks__/MockEntities.res index 53c9d8bc8..1ee2f4a94 100644 --- a/scenarios/test_codegen/test/__mocks__/MockEntities.res +++ b/scenarios/test_codegen/test/__mocks__/MockEntities.res @@ -3,7 +3,7 @@ let gravatarEntity0_delete: Entities.Gravatar.t = { owner_id: "0x123", displayName: "gravatar1", imageUrl: "https://gravatar1.com", - updatesCount: Ethers.BigInt.fromInt(0), + updatesCount: BigInt.fromInt(0), size: LARGE, } @@ -12,7 +12,7 @@ let gravatarEntity1: Entities.Gravatar.t = { owner_id: "0x123", displayName: "gravatar1", imageUrl: "https://gravatar1.com", - updatesCount: Ethers.BigInt.fromInt(0), + updatesCount: BigInt.fromInt(0), size: LARGE, } @@ -21,7 +21,7 @@ let gravatarEntity2: Entities.Gravatar.t = { owner_id: "0x678", displayName: "gravatar2", imageUrl: "https://gravatar2.com", - updatesCount: Ethers.BigInt.fromInt(1), + updatesCount: BigInt.fromInt(1), size: MEDIUM, } let logIndexIncrement = ref(0) diff --git a/scenarios/test_codegen/test/__mocks__/MockEvents.res b/scenarios/test_codegen/test/__mocks__/MockEvents.res index 1ac124853..077dc39d2 100644 --- a/scenarios/test_codegen/test/__mocks__/MockEvents.res +++ b/scenarios/test_codegen/test/__mocks__/MockEvents.res @@ -1,53 +1,53 @@ let newGravatar1: Types.Gravatar.NewGravatar.eventArgs = { - id: 1001->Ethers.BigInt.fromInt, + id: 1001->BigInt.fromInt, owner: "0x1230000000000000000000000000000000000000"->Ethers.getAddressFromStringUnsafe, displayName: "gravatar1", imageUrl: "https://gravatar1.com", } let newGravatar2: Types.Gravatar.NewGravatar.eventArgs = { - id: 1002->Ethers.BigInt.fromInt, + id: 1002->BigInt.fromInt, owner: "0x4560000000000000000000000000000000000000"->Ethers.getAddressFromStringUnsafe, displayName: "gravatar2", imageUrl: "https://gravatar2.com", } let newGravatar3: Types.Gravatar.NewGravatar.eventArgs = { - id: 1003->Ethers.BigInt.fromInt, + id: 1003->BigInt.fromInt, owner: "0x7890000000000000000000000000000000000000"->Ethers.getAddressFromStringUnsafe, displayName: "gravatar3", imageUrl: "https://gravatar3.com", } let newGravatar4_deleted: Types.Gravatar.NewGravatar.eventArgs = { - id: 1004->Ethers.BigInt.fromInt, + id: 1004->BigInt.fromInt, owner: "0x9990000000000000000000000000000000000000"->Ethers.getAddressFromStringUnsafe, displayName: "gravatar4_deleted", imageUrl: "https://gravatar4.com", } let setGravatar1: Types.Gravatar.UpdatedGravatar.eventArgs = { - id: 1001->Ethers.BigInt.fromInt, + id: 1001->BigInt.fromInt, owner: "0x1230000000000000000000000000000000000000"->Ethers.getAddressFromStringUnsafe, displayName: "update1", imageUrl: "https://gravatar1.com", } let setGravatar2: Types.Gravatar.UpdatedGravatar.eventArgs = { - id: 1002->Ethers.BigInt.fromInt, + id: 1002->BigInt.fromInt, owner: "0x4560000000000000000000000000000000000000"->Ethers.getAddressFromStringUnsafe, displayName: "update2", imageUrl: "https://gravatar2.com", } let setGravatar3: Types.Gravatar.UpdatedGravatar.eventArgs = { - id: 1003->Ethers.BigInt.fromInt, + id: 1003->BigInt.fromInt, owner: "0x7890000000000000000000000000000000000000"->Ethers.getAddressFromStringUnsafe, displayName: "update3", imageUrl: "https://gravatar3.com", } let setGravatar4: Types.Gravatar.UpdatedGravatar.eventArgs = { - id: 1004->Ethers.BigInt.fromInt, + id: 1004->BigInt.fromInt, owner: "0x9990000000000000000000000000000000000000"->Ethers.getAddressFromStringUnsafe, displayName: "update4", imageUrl: "https://gravatar4.com", diff --git a/scenarios/test_codegen/test/rollback/Rollback_test.res b/scenarios/test_codegen/test/rollback/Rollback_test.res index 3e6aa3b57..30e56e828 100644 --- a/scenarios/test_codegen/test/rollback/Rollback_test.res +++ b/scenarios/test_codegen/test/rollback/Rollback_test.res @@ -283,8 +283,8 @@ describe("Single Chain Simple Rollback", () => { let gravatars = await getAllGravatars() - let toBigInt = Ethers.BigInt.fromInt - let toString = Ethers.BigInt.toString + let toBigInt = BigInt.fromInt + let toString = BigInt.toString let expectedGravatars: array = [ {