Skip to content

Commit

Permalink
Merge branch 'main' into remove_approved_fee_spenders
Browse files Browse the repository at this point in the history
  • Loading branch information
F3kilo committed Nov 12, 2024
2 parents 2d0d21f + b2e9642 commit 28b6278
Show file tree
Hide file tree
Showing 100 changed files with 683 additions and 699 deletions.
6 changes: 3 additions & 3 deletions docs/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ All commands of bridge deployer require a private key of you EVM wallet to run E

### Erc20 bridge

Deploy bridge canister and BFT bridge contract:
Deploy bridge canister and BTF bridge contract:

```shell
cargo run -p bridge-deployer -- deploy --wasm .artifact/erc20-bridge.wasm.gz \
Expand All @@ -98,7 +98,7 @@ After the bridge was deployed, create a wrapped token (using addresses from the
```shell
cargo run -p bridge-deployer -- wrap erc20 \
--base-evm-url https://testnet.bitfinity.network \
--base-bft-address <BASE_BFT_CONTRACT_ADDRESS> \
--wrapped-bft-address <WRAPPED_BFT_CONTRACT_ADDRESS> \
--base-btf-address <BASE_BTF_CONTRACT_ADDRESS> \
--wrapped-btf-address <WRAPPED_BTF_CONTRACT_ADDRESS> \
--token-address <BASE_TOKEN_ADDRESS>
```
32 changes: 16 additions & 16 deletions solidity/docs.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# BFT Bridge Forge Scripts
# BTF Bridge Forge Scripts

This comprehensive guide provides detailed instructions for running various Forge scripts within the project. These scripts are essential for deploying, upgrading, and managing the BFT Bridge and related contracts.
This comprehensive guide provides detailed instructions for running various Forge scripts within the project. These scripts are essential for deploying, upgrading, and managing the BTF Bridge and related contracts.

## Table of Contents

1. [DeployBFT.s.sol](#deploybftssol)
2. [UpgradeBFT.s.sol](#upgradebftssol)
1. [DeployBTF.s.sol](#deploybtfssol)
2. [UpgradeBTF.s.sol](#upgradebtfssol)
3. [PauseUnpause.s.sol](#pauseunpausessol)
4. [DeployFeeCharge.s.sol](#deployfeechargessol)
5. [DeployWrappedToken.s.sol](#deploywrappedtokenssol)
Expand All @@ -19,15 +19,15 @@ Before running any scripts, ensure you have the following:
- Access to an Ethereum RPC endpoint
- A funded account with the necessary permissions

## DeployBFT.s.sol
## DeployBTF.s.sol

This script is responsible for deploying the BFTBridge contract, a crucial component of the BFT Bridge system.
This script is responsible for deploying the BTFBridge contract, a crucial component of the BTF Bridge system.

### Usage

Execute the following command to deploy the BFTBridge:
Execute the following command to deploy the BTFBridge:

forge script script/DeployBFT.s.sol:DeployBFTBridge --rpc-url <your_rpc_url> --broadcast --private-key <your_private_key> --sender <your_sender_address>
forge script script/DeployBTF.s.sol:DeployBTFBridge --rpc-url <your_rpc_url> --broadcast --private-key <your_private_key> --sender <your_sender_address>

### Environment Variables

Expand All @@ -41,25 +41,25 @@ To customize the deployment, set the following environment variables:
- `OWNER`: (Optional) Address of the contract owner
- `CONTROLLERS`: (Optional) Comma-separated list of controller addresses

## UpgradeBFT.s.sol
## UpgradeBTF.s.sol

This script facilitates the upgrade process for the BFTBridge contract. It consists of three separate contracts, each handling a specific step in the upgrade process.
This script facilitates the upgrade process for the BTFBridge contract. It consists of three separate contracts, each handling a specific step in the upgrade process.

#### Usage

Execute the following commands in sequence to perform the upgrade:

1. Deploy the new implementation:

forge script script/UpgradeBFT.s.sol:PrepareUpgrade --rpc-url <your_rpc_url> --broadcast --private-key <your_private_key> --sender <your_sender_address>
forge script script/UpgradeBTF.s.sol:PrepareUpgrade --rpc-url <your_rpc_url> --broadcast --private-key <your_private_key> --sender <your_sender_address>

2. Add the new implementation to the proxy's allowed implementations:

forge script script/UpgradeBFT.s.sol:AddNewImplementation --rpc-url <your_rpc_url> --broadcast --private-key <your_private_key> --sender <your_sender_address>
forge script script/UpgradeBTF.s.sol:AddNewImplementation --rpc-url <your_rpc_url> --broadcast --private-key <your_private_key> --sender <your_sender_address>

3. Upgrade the proxy to use the new implementation:

forge script script/UpgradeBFT.s.sol:UpgradeProxy --rpc-url <your_rpc_url> --broadcast --private-key <your_private_key> --sender <your_sender_address>
forge script script/UpgradeBTF.s.sol:UpgradeProxy --rpc-url <your_rpc_url> --broadcast --private-key <your_private_key> --sender <your_sender_address>

### Environment Variables

Expand All @@ -70,7 +70,7 @@ Set the following environment variables for the upgrade process:

## PauseUnpause.s.sol

This script allows for the pausing and unpausing of the BFTBridge contract, providing an essential safety mechanism.
This script allows for the pausing and unpausing of the BTFBridge contract, providing an essential safety mechanism.

### Usage

Expand All @@ -84,7 +84,7 @@ forge script script/PauseUnpause.s.sol:PauseUnpauseScript --rpc-url <your_rpc_ur

## DeployFeeCharge.s.sol

This script deploys the FeeCharge contract, which handles fee collection for the BFT Bridge system.
This script deploys the FeeCharge contract, which handles fee collection for the BTF Bridge system.

### Usage

Expand Down Expand Up @@ -132,4 +132,4 @@ forge script script/DeployWrappedTokenDeployer.s.sol:DeployWrappedTokenDeployer
No specific environment variables are required for this script.

---
NOTE: By following these instructions, you can effectively manage and deploy various components of the BFT Bridge system using Forge scripts. Always ensure you're using the correct RPC URL, private key, and sender address when executing these scripts.
NOTE: By following these instructions, you can effectively manage and deploy various components of the BTF Bridge system using Forge scripts. Always ensure you're using the correct RPC URL, private key, and sender address when executing these scripts.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ pragma solidity ^0.8.20;
import "forge-std/Script.sol";
import "forge-std/Vm.sol";
import "@openzeppelin/foundry-upgrades/Upgrades.sol";
import { BFTBridge } from "src/BftBridge.sol";
import { BTFBridge } from "src/BTFBridge.sol";

abstract contract DeployScript is Script {
uint256 public immutable privateKey;
bytes public data;
address public proxyAddress;

// contract name
string public contractName = "BftBridge.sol:BFTBridge";
string public contractName = "BTFBridge.sol:BTFBridge";

error InvalidAddress(string reason);

Expand Down Expand Up @@ -43,7 +43,7 @@ abstract contract DeployScript is Script {
}
}

contract DeployBFTBridge is DeployScript {
contract DeploBTFTBridge is DeployScript {
constructor() DeployScript(vm.envUint("PRIVATE_KEY")) { }

address minterAddress = vm.envAddress("MINTER_ADDRESS");
Expand All @@ -57,7 +57,7 @@ contract DeployBFTBridge is DeployScript {

function _run() internal override create {
data = abi.encodeWithSelector(
BFTBridge.initialize.selector,
BTFBridge.initialize.selector,
minterAddress,
feeChargeAddress,
wrappedTokenDeployer,
Expand Down
8 changes: 4 additions & 4 deletions solidity/script/DeployWrappedToken.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ pragma solidity ^0.8.20;

import "forge-std/Script.sol";
import "forge-std/console.sol";
import "src/BftBridge.sol";
import "src/BTFBridge.sol";

contract DeployWrappedToken is Script {
function run() external {
// Load environment variables or parameters
address bftBridgeAddress = vm.envAddress("BFT_BRIDGE");
address btfBridgeAddress = vm.envAddress("BTF_BRIDGE");
string memory name = vm.envString("NAME");
string memory symbol = vm.envString("SYMBOL");
uint8 decimals = uint8(vm.envUint("DECIMALS"));
Expand All @@ -22,10 +22,10 @@ contract DeployWrappedToken is Script {
vm.startBroadcast();

// Get contract instance
BFTBridge bftBridge = BFTBridge(bftBridgeAddress);
BTFBridge btfBridge = BTFBridge(btfBridgeAddress);

// Deploy ERC20 token
address tokenAddress = bftBridge.deployERC20(name, symbol, decimals, baseTokenId);
address tokenAddress = btfBridge.deployERC20(name, symbol, decimals, baseTokenId);

// Stop broadcasting transactions
vm.stopBroadcast();
Expand Down
6 changes: 3 additions & 3 deletions solidity/script/PauseUnpause.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
pragma solidity ^0.8.20;

import "forge-std/Script.sol";
import "src/BftBridge.sol";
import "src/BTFBridge.sol";

/**
* @title PauseUnpauseScript
* @dev This script allows pausing and unpausing of the BFTBridge contract
* @dev This script allows pausing and unpausing of the BTFBridge contract
*
* To run this script:
* forge script script/PauseUnpause.s.sol:PauseUnpauseScript --rpc-url <your_rpc_url> --private-key <your_private_key> --broadcast
Expand All @@ -22,7 +22,7 @@ contract PauseUnpauseScript is Script {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);

BFTBridge bridge = BFTBridge(contractAddress);
BTFBridge bridge = BTFBridge(contractAddress);

if (shouldPause) {
bridge.pause();
Expand Down
14 changes: 7 additions & 7 deletions solidity/script/UpgradeBFT.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Options } from "@openzeppelin/foundry-upgrades/Options.sol";
/**
* @title PrepareUpgradeScript
* @dev Step 1: Deploys the new implementation contract.
* Running this script will deploy the updated contract (BFTBridgeV2).
* Running this script will deploy the updated contract (BTFBridgeV2).
*/
contract PrepareUpgrade is Script {
address proxyAddress;
Expand All @@ -27,8 +27,8 @@ contract PrepareUpgrade is Script {
// Start broadcasting to the network
vm.startBroadcast();

// Deploy the new implementation contract (BFTBridgeV2)
string memory contractName = "BftBridge.sol:BFTBridgeV2";
// Deploy the new implementation contract (BTFBridgeV2)
string memory contractName = "BTFBridge.sol:BTFBridgeV2";
Options memory opts;
newImplementationAddress = Upgrades.prepareUpgrade(contractName, opts);

Expand Down Expand Up @@ -74,7 +74,7 @@ contract AddNewImplementation is Script {
bytes32 bytecodeHash = keccak256(deployedBytecode);

// Interface to interact with the proxy contract (assuming it's an Ownable UUPS proxy)
IBFTBridge proxyContract = IBFTBridge(proxyAddress);
IBTFBridge proxyContract = IBTFBridge(proxyAddress);

// Add the new implementation's bytecode hash to allowed implementations
proxyContract.addAllowedImplementation(bytecodeHash);
Expand Down Expand Up @@ -110,7 +110,7 @@ contract UpgradeProxy is Script {
vm.startBroadcast();

// Interface to interact with the proxy contract
IBFTBridge proxyContract = IBFTBridge(proxyAddress);
IBTFBridge proxyContract = IBTFBridge(proxyAddress);

// Prepare the initialization data
bytes memory initData = abi.encodeWithSignature("__BridgeV2_init()");
Expand All @@ -126,10 +126,10 @@ contract UpgradeProxy is Script {
}

/**
* @dev Interface to interact with the BFTBridge proxy contract.
* @dev Interface to interact with the BTFBridge proxy contract.
* Include the functions needed for the upgrade process.
*/
interface IBFTBridge {
interface IBTFBridge {
function addAllowedImplementation(
bytes32 bytecodeHash
) external;
Expand Down
6 changes: 3 additions & 3 deletions solidity/src/BftBridge.sol → solidity/src/BTFBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";

contract BFTBridge is TokenManager, UUPSUpgradeable, OwnableUpgradeable, PausableUpgradeable {
contract BTFBridge is TokenManager, UUPSUpgradeable, OwnableUpgradeable, PausableUpgradeable {
using RingBuffer for RingBuffer.RingBufferUint32;
using SafeERC20 for IERC20;

Expand Down Expand Up @@ -112,7 +112,7 @@ contract BFTBridge is TokenManager, UUPSUpgradeable, OwnableUpgradeable, Pausabl
_disableInitializers();
}

/// Initializes the BftBridge contract.
/// Initializes the BTFBridge contract.
///
/// @param minterAddress The address of the minter canister.
/// @param feeChargeAddress The address of the fee charge contract.
Expand Down Expand Up @@ -339,7 +339,7 @@ contract BFTBridge is TokenManager, UUPSUpgradeable, OwnableUpgradeable, Pausabl
bytes memory recipientID,
bytes32 memo
) public whenNotPaused returns (uint32) {
require(fromERC20 != address(this), "From address must not be BFT bridge address");
require(fromERC20 != address(this), "From address must not be BTF bridge address");
require(fromERC20 != address(0), "Invalid from address; must not be zero address");
// Check if the token is registered on the bridge or the side is base
require(
Expand Down
6 changes: 3 additions & 3 deletions solidity/src/abstract/TokenManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ abstract contract TokenManager is Initializable {
) internal view returns (TokenMetadata memory meta) {
try IERC20Metadata(token).name() returns (string memory _name) {
meta.name = StringUtils.truncateUTF8(_name);
} catch {}
} catch { }
try IERC20Metadata(token).symbol() returns (string memory _symbol) {
meta.symbol = bytes16(StringUtils.truncateUTF8(_symbol));
} catch {}
} catch { }
try IERC20Metadata(token).decimals() returns (uint8 _decimals) {
meta.decimals = _decimals;
} catch {}
} catch { }
}

/// Returns wrapped token for the given base token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.7;
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "src/WrappedToken.sol";
import "src/BftBridge.sol";
import "src/BTFBridge.sol";
import "src/interfaces/IFeeCharge.sol";
import { RingBuffer } from "src/libraries/RingBuffer.sol";
import "src/abstract/TokenManager.sol";
Expand All @@ -14,8 +14,8 @@ import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";

/// Make sure you add the reference contracts to the `import` statement above.
/// @custom:oz-upgrades-from src/BftBridge.sol:BFTBridge
contract BFTBridgeV2 is BFTBridge {
/// @custom:oz-upgrades-from src/BTFBridge.sol:BTFBridge
contract BTFBridgeV2 is BTFBridge {
// Hello World
function helloWorld(
string memory name
Expand Down
Loading

0 comments on commit 28b6278

Please sign in to comment.