Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bitfinity support #92

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Modules/BOBMainModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
22 changes: 22 additions & 0 deletions Modules/BitfinityERC1155Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types = 1);

/* Idea (c) 2023 Nikita Zhavoronkov, nikzh@nikzh.com
* Copyright (c) 2023-2024 3xpl developers, 3@3xpl.com, see CONTRIBUTORS.md
* Distributed under the MIT software license, see LICENSE.md */

/* This module processes ERC-1155 MT transfers in Bitfinity (EVM-like L2 for Bitcoin). */

final class BitfinityERC1155Module extends EVMERC1155Module implements Module, MultipleBalanceSpecial
{
function initialize()
{
// CoreModule
$this->blockchain = 'bitfinity';
$this->module = 'bitfinity-erc-1155';
$this->is_main = false;
$this->first_block_date = '2024-06-17';
$this->first_block_id = 0;

$this->tests = []; // currently, only testnet contains erc1155 activity
}
}
22 changes: 22 additions & 0 deletions Modules/BitfinityERC20Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types = 1);

/* Idea (c) 2023 Nikita Zhavoronkov, nikzh@nikzh.com
* Copyright (c) 2023-2024 3xpl developers, 3@3xpl.com, see CONTRIBUTORS.md
* Distributed under the MIT software license, see LICENSE.md */

/* This module processes ERC-20 token transfers in Bitfinity (EVM-like L2 for Bitcoin). */

final class BitfinityERC20Module extends EVMERC20Module implements Module, MultipleBalanceSpecial, SupplySpecial
{
function initialize()
{
// CoreModule
$this->blockchain = 'bitfinity';
$this->module = 'bitfinity-erc-20';
$this->is_main = false;
$this->first_block_date = '2024-06-17';
$this->first_block_id = 0;

$this->tests = []; // currently, only testnet contains erc20 activity
}
}
22 changes: 22 additions & 0 deletions Modules/BitfinityERC721Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types = 1);

/* Idea (c) 2023 Nikita Zhavoronkov, nikzh@nikzh.com
* Copyright (c) 2023-2024 3xpl developers, 3@3xpl.com, see CONTRIBUTORS.md
* Distributed under the MIT software license, see LICENSE.md */

/* This module processes ERC-721 NFT transfers in Bitfinity (EVM-like L2 for Bitcoin). */

final class BitfinityERC721Module extends EVMERC721Module implements Module, MultipleBalanceSpecial
{
function initialize()
{
// CoreModule
$this->blockchain = 'bitfinity';
$this->module = 'bitfinity-erc-721';
$this->is_main = false;
$this->first_block_date = '2024-06-17';
$this->first_block_id = 0;

$this->tests = []; // currently, only testnet contains erc721 activity
}
}
40 changes: 40 additions & 0 deletions Modules/BitfinityMainModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php declare(strict_types = 1);

/* Idea (c) 2023 Nikita Zhavoronkov, nikzh@nikzh.com
* Copyright (c) 2023-2024 3xpl developers, 3@3xpl.com, see CONTRIBUTORS.md
* Distributed under the MIT software license, see LICENSE.md */

/* This is the main Bitfinity (EVM-like L2 for Bitcoin) module. */

final class BitfinityMainModule extends EVMMainModule implements Module, BalanceSpecial, TransactionSpecials, AddressSpecials
{
function initialize()
{
// CoreModule
$this->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;

// 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;}']
];
}
}
23 changes: 23 additions & 0 deletions Modules/BitfinityTraceModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php declare(strict_types = 1);

/* Idea (c) 2023 Nikita Zhavoronkov, nikzh@nikzh.com
* Copyright (c) 2023-2024 3xpl developers, 3@3xpl.com, see CONTRIBUTORS.md
* Distributed under the MIT software license, see LICENSE.md */

/* This module processes internal Bitfinity transactions (using block tracing). It requires an archival node to run. */

final class BitfinityTraceModule extends EVMTraceModule implements Module
{
function initialize()
{
// CoreModule
$this->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;
}
}
10 changes: 6 additions & 4 deletions Modules/Common/EVMMainModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Modules/Common/EVMTraits.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Modules/GnosisChainMainModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down