Skip to content

Commit

Permalink
add initialize method to TokenRecoverPortal
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonberg1997 committed Dec 7, 2023
1 parent 8ccd11c commit 0b35b38
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
16 changes: 11 additions & 5 deletions contracts/BC_fusion/TokenRecoverPortal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ import "./lib/Utils.sol";
* The BC users can recover the token from TokenHub after the merkle tree root is generated.
* For more details, please refer to the BEP-299(https://github.com/bnb-chain/BEPs/pull/299).
*/
contract TokenRecoverPortal is ReentrancyGuardUpgradeable, System {
contract TokenRecoverPortal is System, Initializable, ReentrancyGuardUpgradeable {
using Utils for string;
using Utils for bytes;

/*----------------- init parameters -----------------*/
/*----------------- constants -----------------*/
string public constant SOURCE_CHAIN_ID = "Binance-Chain-Ganges";
address public approvalAddress = 0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa;
bytes32 public merkleRoot = 0x0000000000000000000000000000000000000000000000000000000000000000;
bool public merkleRootAlreadyInit = false;
address public constant INIT_APPROVAL_ADDRESS = 0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa;

/*----------------- storage -----------------*/
address public approvalAddress;
bytes32 public merkleRoot;
bool public merkleRootAlreadyInit;

// recoveredMap is used to record the recovered token.
mapping(bytes32 => bool) private recoveredMap;

Expand Down Expand Up @@ -93,6 +95,10 @@ contract TokenRecoverPortal is ReentrancyGuardUpgradeable, System {
// This event is triggered whenever a call to #recover succeeds.
event TokenRecoverRequested(bytes32 tokenSymbol, address account, uint256 amount);

function initialize() external initializer onlyCoinbase onlyZeroGasPrice {
approvalAddress = INIT_APPROVAL_ADDRESS;
}

/**
* isRecovered check if the token is recovered.
* @param node the leaf node of merkle tree.
Expand Down
38 changes: 23 additions & 15 deletions scripts/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ def generate_token_recover_portal(source_chain_id, approval_address, merkle_root
)

replace_parameter(contract, "string public constant SOURCE_CHAIN_ID", f"\"{source_chain_id}\"")
replace_parameter(contract, "address public approvalAddress", f"{approval_address}")
replace_parameter(contract, "bytes32 public merkleRoot", f"{merkle_root}")
replace_parameter(contract, "address public constant INIT_APPROVAL_ADDRESS", f"{approval_address}")

if merkle_root != "":
insert(contract, "approvalAddress = INIT_APPROVAL_ADDRESS;", f"\t\tmerkle_root = {merkle_root};")


def generate_validator_set(init_burn_ratio, init_validatorset_bytes):
Expand Down Expand Up @@ -228,7 +230,7 @@ def mainnet():
whitelist_2 = "0x446AA6E0DC65690403dF3F127750da1322941F3e"
source_chain_id = "Binance-Chain-Tigris"
approval_address = "0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa"
merkle_root = "0x0000000000000000000000000000000000000000000000000000000000000000"
merkle_root = ""

generate_system()
generate_cross_chain()
Expand All @@ -255,7 +257,7 @@ def testnet():
whitelist_2 = "0x37B8516a0F88E65D677229b402ec6C1e0E333004"
source_chain_id = "Binance-Chain-Ganges"
approval_address = "0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa"
merkle_root = "0x0000000000000000000000000000000000000000000000000000000000000000"
merkle_root = ""

generate_system()
generate_cross_chain()
Expand All @@ -269,7 +271,17 @@ def testnet():


@main.command(help="Generate contracts for qa network")
def qa():
def qa(
whitelist_1: Annotated[
str, typer.Option(help="whitelist relayer1's address")] = "0x88cb4D8F77742c24d647BEf8049D3f3C56067cDD",
whitelist_2: Annotated[
str, typer.Option(help="whitelist relayer2's address")] = "0x42D596440775C90db8d9187b47650986E1063493",
source_chain_id: Annotated[
str, typer.Option(help="source chain id of the token recover portal")] = "Binance-Chain-Ganges",
approval_address: Annotated[str, typer.Option(help="approval address of the token recover portal")
] = "0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa",
merkle_root: Annotated[str, typer.Option(help="merkle root of the token recover portal")] = ""
):
global network, chain_id, hex_chain_id
network = "qa"
chain_id = 714
Expand All @@ -278,11 +290,6 @@ def qa():
init_consensus_bytes = "42696e616e63652d436861696e2d47616e67657300000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000aea1ac326886b992a991d21a6eb155f41b77867cbf659e78f31d89d8205122a84d1be64f0e9a466c2e66a53433928192783e29f8fa21beb2133499b5ef770f60000000e8d4a5100099308aa365c40554bc89982af505d85da95251445d5dd4a9bb37dd2584fd92d3000000e8d4a5100001776920ff0b0f38d78cf95c033c21adf7045785114e392a7544179652e0a612000000e8d4a51000"
init_burn_ratio = "1000"
init_validatorset_bytes = "f901a880f901a4f844941284214b9b9c85549ab3d2b972df0deef66ac2c9946ddf42a51534fc98d0c0a3b42c963cace8441ddf946ddf42a51534fc98d0c0a3b42c963cace8441ddf8410000000f84494a2959d3f95eae5dc7d70144ce1b73b403b7eb6e0948081ef03f1d9e0bb4a5bf38f16285c879299f07f948081ef03f1d9e0bb4a5bf38f16285c879299f07f8410000000f8449435552c16704d214347f29fa77f77da6d75d7c75294dc4973e838e3949c77aced16ac2315dc2d7ab11194dc4973e838e3949c77aced16ac2315dc2d7ab1118410000000f84494980a75ecd1309ea12fa2ed87a8744fbfc9b863d594cc6ac05c95a99c1f7b5f88de0e3486c82293b27094cc6ac05c95a99c1f7b5f88de0e3486c82293b2708410000000f84494f474cf03cceff28abc65c9cbae594f725c80e12d94e61a183325a18a173319dd8e19c8d069459e217594e61a183325a18a173319dd8e19c8d069459e21758410000000f84494b71b214cb885500844365e95cd9942c7276e7fd894d22ca3ba2141d23adab65ce4940eb7665ea2b6a794d22ca3ba2141d23adab65ce4940eb7665ea2b6a78410000000"
whitelist_1 = "0x88cb4D8F77742c24d647BEf8049D3f3C56067cDD"
whitelist_2 = "0x42D596440775C90db8d9187b47650986E1063493"
source_chain_id = "Binance-Chain-Ganges"
approval_address = "0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa"
merkle_root = "0x0000000000000000000000000000000000000000000000000000000000000000"

generate_system()
generate_cross_chain()
Expand All @@ -300,21 +307,22 @@ def local(
local_chain_id: int = 714,
init_consensus_bytes:
str = "42696e616e63652d436861696e2d4e696c650000000000000000000000000000000000000000000229eca254b3859bffefaf85f4c95da9fbd26527766b784272789c30ec56b380b6eb96442aaab207bc59978ba3dd477690f5c5872334fc39e627723daa97e441e88ba4515150ec3182bc82593df36f8abb25a619187fcfab7e552b94e64ed2deed000000e8d4a51000",
init_burn_ratio: Annotated[str, typer.Option(help="init burn ratio of BscValidatorSet")] = "1000",
whitelist_1: Annotated[
str, typer.Option(help="whitelist relayer1's address")] = "0xA904540818AC9c47f2321F97F1069B9d8746c6DB",
whitelist_2: Annotated[
str, typer.Option(help="whitelist relayer2's address")] = "0x316b2Fa7C8a2ab7E21110a4B3f58771C01A71344",
source_chain_id: Annotated[
str, typer.Option(help="source chain id of the token recover portal")] = "Binance-Chain-Ganges",
approval_address: Annotated[str, typer.Option(help="approval address of the token recover portal")
] = "0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa",
merkle_root: Annotated[str, typer.Option(help="merkle root of the token recover portal")] = ""
):
global network, chain_id, hex_chain_id
network = "local"
chain_id = local_chain_id
hex_chain_id = convert_chain_id(chain_id)

init_burn_ratio = "1000"
source_chain_id = "Binance-Chain-Ganges"
approval_address = "0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa"
merkle_root = "0x0000000000000000000000000000000000000000000000000000000000000000"

try:
result = subprocess.run(
[
Expand Down

0 comments on commit 0b35b38

Please sign in to comment.