From caf94d7fa58c4b1f7169a34606aceed26cf1477b Mon Sep 17 00:00:00 2001 From: Lorgansar Date: Thu, 11 Jul 2024 18:31:47 +0500 Subject: [PATCH 1/3] Add bitfinity support --- .env.example | 39 ++++++++++++++++++++++++++++++ Modules/BitfinityERC1155Module.php | 20 +++++++++++++++ Modules/BitfinityERC20Module.php | 20 +++++++++++++++ Modules/BitfinityERC721Module.php | 20 +++++++++++++++ Modules/BitfinityMainModule.php | 34 ++++++++++++++++++++++++++ Modules/BitfinityTraceModule.php | 23 ++++++++++++++++++ Modules/Common/EVMMainModule.php | 10 +++++--- Modules/Common/EVMTraits.php | 2 +- 8 files changed, 163 insertions(+), 5 deletions(-) create mode 100644 Modules/BitfinityERC1155Module.php create mode 100644 Modules/BitfinityERC20Module.php create mode 100644 Modules/BitfinityERC721Module.php create mode 100644 Modules/BitfinityMainModule.php create mode 100644 Modules/BitfinityTraceModule.php diff --git a/.env.example b/.env.example index d7379cb..7974853 100644 --- a/.env.example +++ b/.env.example @@ -1545,3 +1545,42 @@ MODULE_groestlcoin-main_NODES[]=http://login:password@127.0.0.1:1234/ MODULE_groestlcoin-main_NODES[]=http://login:password@127.0.0.2:1234/ MODULE_groestlcoin-main_REQUESTER_TIMEOUT=60 MODULE_groestlcoin-main_REQUESTER_THREADS=12 + +############### +## Bitfinity ## +############### + +MODULES[]=bitfinity-main +MODULE_bitfinity-main_CLASS=BitfinityMainModule +MODULE_bitfinity-main_NODES[]=http://login:password@127.0.0.1:1234/ +MODULE_bitfinity-main_NODES[]=http://login:password@127.0.0.1:1234/ +MODULE_bitfinity-main_REQUESTER_TIMEOUT=60 +MODULE_bitfinity-main_REQUESTER_THREADS=12 + +MODULES[]=bitfinity-trace +MODULE_bitfinity-trace_CLASS=BitfinityTraceModule +MODULE_bitfinity-trace_NODES[]=http://login:password@127.0.0.1:1234/ +MODULE_bitfinity-trace_NODES[]=http://login:password@127.0.0.1:1234/ +MODULE_bitfinity-trace_REQUESTER_TIMEOUT=60 +MODULE_bitfinity-trace_REQUESTER_THREADS=12 + +MODULES[]=bitfinity-erc-20 +MODULE_bitfinity-erc-20_CLASS=BitfinityERC20Module +MODULE_bitfinity-erc-20_NODES[]=http://login:password@127.0.0.1:1234/ +MODULE_bitfinity-erc-20_NODES[]=http://login:password@127.0.0.1:1234/ +MODULE_bitfinity-erc-20_REQUESTER_TIMEOUT=60 +MODULE_bitfinity-erc-20_REQUESTER_THREADS=12 + +MODULES[]=bitfinity-erc-721 +MODULE_bitfinity-erc-721_CLASS=BitfinityERC721Module +MODULE_bitfinity-erc-721_NODES[]=http://login:password@127.0.0.1:1234/ +MODULE_bitfinity-erc-721_NODES[]=http://login:password@127.0.0.1:1234/ +MODULE_bitfinity-erc-721_REQUESTER_TIMEOUT=60 +MODULE_bitfinity-erc-721_REQUESTER_THREADS=12 + +MODULES[]=bitfinity-erc-1155 +MODULE_bitfinity-erc-1155_CLASS=BitfinityERC1155Module +MODULE_bitfinity-erc-1155_NODES[]=http://login:password@127.0.0.1:1234/ +MODULE_bitfinity-erc-1155_NODES[]=http://login:password@127.0.0.1:1234/ +MODULE_bitfinity-erc-1155_REQUESTER_TIMEOUT=60 +MODULE_bitfinity-erc-1155_REQUESTER_THREADS=12 diff --git a/Modules/BitfinityERC1155Module.php b/Modules/BitfinityERC1155Module.php new file mode 100644 index 0000000..d3a2f55 --- /dev/null +++ b/Modules/BitfinityERC1155Module.php @@ -0,0 +1,20 @@ +blockchain = 'bitfinity'; + $this->module = 'bitfinity-erc-1155'; + $this->is_main = false; + $this->first_block_date = '2024-06-17'; + $this->first_block_id = 0; + } +} diff --git a/Modules/BitfinityERC20Module.php b/Modules/BitfinityERC20Module.php new file mode 100644 index 0000000..ac148f7 --- /dev/null +++ b/Modules/BitfinityERC20Module.php @@ -0,0 +1,20 @@ +blockchain = 'bitfinity'; + $this->module = 'bitfinity-erc-20'; + $this->is_main = false; + $this->first_block_date = '2024-06-17'; + $this->first_block_id = 0; + } +} diff --git a/Modules/BitfinityERC721Module.php b/Modules/BitfinityERC721Module.php new file mode 100644 index 0000000..76114ed --- /dev/null +++ b/Modules/BitfinityERC721Module.php @@ -0,0 +1,20 @@ +blockchain = 'bitfinity'; + $this->module = 'bitfinity-erc-721'; + $this->is_main = false; + $this->first_block_date = '2024-06-17'; + $this->first_block_id = 0; + } +} diff --git a/Modules/BitfinityMainModule.php b/Modules/BitfinityMainModule.php new file mode 100644 index 0000000..b41a7a9 --- /dev/null +++ b/Modules/BitfinityMainModule.php @@ -0,0 +1,34 @@ +blockchain = 'bitfinity'; + $this->module = 'bitfinity-main'; + $this->is_main = true; + $this->first_block_date = '2024-06-17'; + $this->currency = 'BITFINITY'; + $this->currency_details = ['name' => 'BITFINITY', 'symbol' => 'BFT', 'decimals' => 18, 'description' => null]; + + // EVMMainModule + $this->evm_implementation = EVMImplementation::geth; + $this->extra_features = [ + EVMSpecialFeatures::EffectiveGasPriceCanBeZeroOrNull, + ]; + $this->reward_function = function($block_id) + { + return '0'; + }; + + // Handles + $this->handles_implemented = false; + } +} diff --git a/Modules/BitfinityTraceModule.php b/Modules/BitfinityTraceModule.php new file mode 100644 index 0000000..0b9ead6 --- /dev/null +++ b/Modules/BitfinityTraceModule.php @@ -0,0 +1,23 @@ +blockchain = 'bitfinity'; + $this->module = 'bitfinity-trace'; + $this->complements = 'bitfinity-main'; + $this->is_main = false; + $this->first_block_date = '2024-06-17'; + + // EVMTraceModule + $this->evm_implementation = EVMImplementation::geth; + } +} diff --git a/Modules/Common/EVMMainModule.php b/Modules/Common/EVMMainModule.php index 6bb75b2..4d76503 100644 --- a/Modules/Common/EVMMainModule.php +++ b/Modules/Common/EVMMainModule.php @@ -265,7 +265,7 @@ final public function pre_process_block($block_id) if (in_array(EVMSpecialFeatures::HasSystemTransactions, $this->extra_features)) $transaction_data[($general_data[$i]['hash'])]['type'] = $receipt_data[$i]['type']; - + if (in_array(EVMSpecialFeatures::EIP4844, $this->extra_features)) { $transaction_data[($general_data[$i]['hash'])]['type'] = $receipt_data[$i]['type']; @@ -398,10 +398,12 @@ final public function pre_process_block($block_id) { $this_gas_used = to_int256_from_0xhex($transaction['gasUsed']); $this_burned = (!is_null($base_fee_per_gas)) ? bcmul($base_fee_per_gas, $this_gas_used) : '0'; - $this_to_miner = bcsub(bcmul(to_int256_from_0xhex($transaction['effectiveGasPrice']), $this_gas_used), $this_burned); + $this_effective_gas_price = (!is_null($transaction['effectiveGasPrice'])) ? to_int256_from_0xhex($transaction['effectiveGasPrice']) : '0'; + + $this_to_miner = bcsub(bcmul($this_effective_gas_price, $this_gas_used), $this_burned); - if (in_array(EVMSpecialFeatures::EffectiveGasPriceCanBeZero, $this->extra_features)) - if ($transaction['effectiveGasPrice'] === '0x0') + if (in_array(EVMSpecialFeatures::EffectiveGasPriceCanBeZeroOrNull, $this->extra_features)) + if ($transaction['effectiveGasPrice'] === '0x0' || is_null($transaction['effectiveGasPrice'])) $this_to_miner = '0'; // The fee is $this_burned + $this_to_miner diff --git a/Modules/Common/EVMTraits.php b/Modules/Common/EVMTraits.php index 880732a..f818c2a 100644 --- a/Modules/Common/EVMTraits.php +++ b/Modules/Common/EVMTraits.php @@ -33,7 +33,7 @@ enum EVMSpecialFeatures case zkEVM; case SpecialSenderPaysNoFee; case HasSystemTransactions; - case EffectiveGasPriceCanBeZero; + case EffectiveGasPriceCanBeZeroOrNull; case NoEIP1559BurnFee; // Linea does this case rskEVM; // Rootstock has different traces and deferred validators rewards (in N+4000 block). case TraceBlockSupport; // Support for `trace_block` in RPC API From 642f036538b5bcf1e2f3959c836f765afb24f067 Mon Sep 17 00:00:00 2001 From: Lorgansar Date: Fri, 12 Jul 2024 16:49:04 +0500 Subject: [PATCH 2/3] fix compatibility with other modules using EffectiveGasPriceCanBeZero --- Modules/BOBMainModule.php | 2 +- Modules/GnosisChainMainModule.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/BOBMainModule.php b/Modules/BOBMainModule.php index 4de0ef2..65eaedd 100644 --- a/Modules/BOBMainModule.php +++ b/Modules/BOBMainModule.php @@ -21,7 +21,7 @@ function initialize() // EVMMainModule $this->evm_implementation = EVMImplementation::geth; - $this->extra_features = [EVMSpecialFeatures::EffectiveGasPriceCanBeZero]; + $this->extra_features = [EVMSpecialFeatures::EffectiveGasPriceCanBeZeroOrNull]; $this->reward_function = function($block_id) { return '0'; diff --git a/Modules/GnosisChainMainModule.php b/Modules/GnosisChainMainModule.php index b384092..a2112f8 100644 --- a/Modules/GnosisChainMainModule.php +++ b/Modules/GnosisChainMainModule.php @@ -24,7 +24,7 @@ function initialize() // EVMMainModule $this->evm_implementation = EVMImplementation::Erigon; // Change to geth if you're running Nethermind, but this would be slower - $this->extra_features = [EVMSpecialFeatures::EffectiveGasPriceCanBeZero]; + $this->extra_features = [EVMSpecialFeatures::EffectiveGasPriceCanBeZeroOrNull]; $this->reward_function = function($block_id) { return '0'; From 6682e65c3684164e14560fcc310cb6fd0cc5e46e Mon Sep 17 00:00:00 2001 From: Lorgansar Date: Wed, 17 Jul 2024 22:24:07 +0500 Subject: [PATCH 3/3] bitfinity - tests and feature-interfaces --- Modules/BitfinityERC1155Module.php | 4 +++- Modules/BitfinityERC20Module.php | 4 +++- Modules/BitfinityERC721Module.php | 4 +++- Modules/BitfinityMainModule.php | 8 +++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Modules/BitfinityERC1155Module.php b/Modules/BitfinityERC1155Module.php index d3a2f55..b9ab452 100644 --- a/Modules/BitfinityERC1155Module.php +++ b/Modules/BitfinityERC1155Module.php @@ -6,7 +6,7 @@ /* This module processes ERC-1155 MT transfers in Bitfinity (EVM-like L2 for Bitcoin). */ -final class BitfinityERC1155Module extends EVMERC1155Module implements Module +final class BitfinityERC1155Module extends EVMERC1155Module implements Module, MultipleBalanceSpecial { function initialize() { @@ -16,5 +16,7 @@ function initialize() $this->is_main = false; $this->first_block_date = '2024-06-17'; $this->first_block_id = 0; + + $this->tests = []; // currently, only testnet contains erc1155 activity } } diff --git a/Modules/BitfinityERC20Module.php b/Modules/BitfinityERC20Module.php index ac148f7..379e7bf 100644 --- a/Modules/BitfinityERC20Module.php +++ b/Modules/BitfinityERC20Module.php @@ -6,7 +6,7 @@ /* This module processes ERC-20 token transfers in Bitfinity (EVM-like L2 for Bitcoin). */ -final class BitfinityERC20Module extends EVMERC20Module implements Module +final class BitfinityERC20Module extends EVMERC20Module implements Module, MultipleBalanceSpecial, SupplySpecial { function initialize() { @@ -16,5 +16,7 @@ function initialize() $this->is_main = false; $this->first_block_date = '2024-06-17'; $this->first_block_id = 0; + + $this->tests = []; // currently, only testnet contains erc20 activity } } diff --git a/Modules/BitfinityERC721Module.php b/Modules/BitfinityERC721Module.php index 76114ed..ef42644 100644 --- a/Modules/BitfinityERC721Module.php +++ b/Modules/BitfinityERC721Module.php @@ -6,7 +6,7 @@ /* This module processes ERC-721 NFT transfers in Bitfinity (EVM-like L2 for Bitcoin). */ -final class BitfinityERC721Module extends EVMERC721Module implements Module +final class BitfinityERC721Module extends EVMERC721Module implements Module, MultipleBalanceSpecial { function initialize() { @@ -16,5 +16,7 @@ function initialize() $this->is_main = false; $this->first_block_date = '2024-06-17'; $this->first_block_id = 0; + + $this->tests = []; // currently, only testnet contains erc721 activity } } diff --git a/Modules/BitfinityMainModule.php b/Modules/BitfinityMainModule.php index b41a7a9..0b68243 100644 --- a/Modules/BitfinityMainModule.php +++ b/Modules/BitfinityMainModule.php @@ -6,7 +6,7 @@ /* This is the main Bitfinity (EVM-like L2 for Bitcoin) module. */ -final class BitfinityMainModule extends EVMMainModule implements Module +final class BitfinityMainModule extends EVMMainModule implements Module, BalanceSpecial, TransactionSpecials, AddressSpecials { function initialize() { @@ -30,5 +30,11 @@ function initialize() // Handles $this->handles_implemented = false; + + // Tests + $this->tests = [ + ['block' => 0, 'result' => 'a:2:{s:6:"events";a:2:{i:0;a:8:{s:11:"transaction";N;s:7:"address";s:4:"0x00";s:6:"effect";s:2:"-0";s:6:"failed";s:1:"f";s:5:"extra";s:1:"r";s:5:"block";i:0;s:4:"time";s:19:"2024-06-17 14:04:47";s:8:"sort_key";i:0;}i:1;a:8:{s:11:"transaction";N;s:7:"address";s:42:"0x0000000000000000000000000000000000000000";s:6:"effect";s:1:"0";s:6:"failed";s:1:"f";s:5:"extra";s:1:"r";s:5:"block";i:0;s:4:"time";s:19:"2024-06-17 14:04:47";s:8:"sort_key";i:1;}}s:10:"currencies";N;}'], + ['block' => 583440, 'result' => 'a:2:{s:6:"events";a:6:{i:0;a:8:{s:11:"transaction";s:66:"0x767378c389899012ee2052ac43a62af9a18cbe0150ea4243d2dcd9a8728931f9";s:7:"address";s:42:"0xba819e618e7fb8edc2d83763d97b96d94281dc44";s:6:"effect";s:7:"-147000";s:6:"failed";s:1:"f";s:5:"extra";s:1:"b";s:5:"block";i:583440;s:4:"time";s:19:"2024-07-09 15:38:39";s:8:"sort_key";i:0;}i:1;a:8:{s:11:"transaction";s:66:"0x767378c389899012ee2052ac43a62af9a18cbe0150ea4243d2dcd9a8728931f9";s:7:"address";s:4:"0x00";s:6:"effect";s:6:"147000";s:6:"failed";s:1:"f";s:5:"extra";s:1:"b";s:5:"block";i:583440;s:4:"time";s:19:"2024-07-09 15:38:39";s:8:"sort_key";i:1;}i:2;a:8:{s:11:"transaction";s:66:"0x767378c389899012ee2052ac43a62af9a18cbe0150ea4243d2dcd9a8728931f9";s:7:"address";s:42:"0xba819e618e7fb8edc2d83763d97b96d94281dc44";s:6:"effect";s:12:"-10000000000";s:6:"failed";s:1:"f";s:5:"extra";N;s:5:"block";i:583440;s:4:"time";s:19:"2024-07-09 15:38:39";s:8:"sort_key";i:2;}i:3;a:8:{s:11:"transaction";s:66:"0x767378c389899012ee2052ac43a62af9a18cbe0150ea4243d2dcd9a8728931f9";s:7:"address";s:42:"0xc0f8c3ec1b30933a7b7e7df4dfa49324b9598ea9";s:6:"effect";s:11:"10000000000";s:6:"failed";s:1:"f";s:5:"extra";N;s:5:"block";i:583440;s:4:"time";s:19:"2024-07-09 15:38:39";s:8:"sort_key";i:3;}i:4;a:8:{s:11:"transaction";N;s:7:"address";s:4:"0x00";s:6:"effect";s:2:"-0";s:6:"failed";s:1:"f";s:5:"extra";s:1:"r";s:5:"block";i:583440;s:4:"time";s:19:"2024-07-09 15:38:39";s:8:"sort_key";i:4;}i:5;a:8:{s:11:"transaction";N;s:7:"address";s:42:"0x0000000000000000000000000000000000000000";s:6:"effect";s:1:"0";s:6:"failed";s:1:"f";s:5:"extra";s:1:"r";s:5:"block";i:583440;s:4:"time";s:19:"2024-07-09 15:38:39";s:8:"sort_key";i:5;}}s:10:"currencies";N;}'] + ]; } }