Skip to content

Commit

Permalink
modifications from recording
Browse files Browse the repository at this point in the history
  • Loading branch information
ciaranightingale committed Dec 17, 2024
1 parent 6f776b6 commit 11aeffe
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 234 deletions.
31 changes: 0 additions & 31 deletions bridgeToSepolia.sh

This file was deleted.

61 changes: 23 additions & 38 deletions script/BridgeTokens.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,40 @@
pragma solidity ^0.8.24;

import {Script} from "forge-std/Script.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IRouterClient} from "@ccip/contracts/src/v0.8/ccip/interfaces/IRouterClient.sol";
import {Client} from "@ccip/contracts/src/v0.8/ccip/libraries/Client.sol";
import {IERC20} from "@ccip/contracts/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";

contract BridgeTokensScript is Script {
function createCCIPMessage(
address receiverAddress,
address tokenToSendAddress,
uint256 amountToSend,
address linkTokenAddress
) public pure returns (Client.EVM2AnyMessage memory) {
// 1. Create the token struct array
Client.EVMTokenAmount[] memory tokenToSendDetails = new Client.EVMTokenAmount[](1);
Client.EVMTokenAmount memory tokenAmount =
Client.EVMTokenAmount({token: tokenToSendAddress, amount: amountToSend});
tokenToSendDetails[0] = tokenAmount;
// 3. Create the message struct with no data and the designated amount of tokens
Client.EVM2AnyMessage memory message = Client.EVM2AnyMessage({
receiver: abi.encode(receiverAddress), // we need to encode the address to bytes
data: "", // We don't need any data for this example
tokenAmounts: tokenToSendDetails, // this needs to be of type EVMTokenAmount[] as you could send multiple tokens
feeToken: linkTokenAddress, // The token used to pay for the fee
extraArgs: Client._argsToBytes(Client.EVMExtraArgsV1({gasLimit: 0})) // We don't need any extra args for this example
});
return message;
}

function sendMessage(
function run(
address receiverAddress,
uint64 destinationChainSelector,
address tokenToSendAddress,
uint256 amountToSend,
address linkTokenAddress,
address ccipRouterAddress
address routerAddress
) public {
// struct EVM2AnyMessage {
// bytes receiver; // abi.encode(receiver address) for dest EVM chains
// bytes data; // Data payload
// EVMTokenAmount[] tokenAmounts; // Token transfers
// address feeToken; // Address of feeToken. address(0) means you will send msg.value.
// bytes extraArgs; // Populate this with _argsToBytes(EVMExtraArgsV2)
// }
Client.EVMTokenAmount[] memory tokenAmounts = new Client.EVMTokenAmount[](1);
tokenAmounts[0] = Client.EVMTokenAmount({token: tokenToSendAddress, amount: amountToSend});
vm.startBroadcast();
// 1. Create the CCIP message
Client.EVM2AnyMessage memory message =
createCCIPMessage(receiverAddress, tokenToSendAddress, amountToSend, linkTokenAddress);

// 2. Approve the router to burn the tokens
IERC20(tokenToSendAddress).approve(ccipRouterAddress, amountToSend);

// 4. Approve the router to spend the fees
uint256 ccipFee = IRouterClient(ccipRouterAddress).getFee(destinationChainSelector, message);
IERC20(linkTokenAddress).approve(ccipRouterAddress, ccipFee); // Approve the fee
// 5. Send the message to the router!!
IRouterClient(ccipRouterAddress).ccipSend(destinationChainSelector, message); // Send the message

Client.EVM2AnyMessage message = Client.EVM2AnyMessage({
receiver: abi.encode(receiverAddress),
data: "",
tokenAmounts: tokenAmounts,
feeToken: linkTokenAddress,
extraArgs: Client._argsToBytes(Client.EVMExtraArgsV1({gasLimit: 0}))
});
uint256 ccipFee = IRouterClient(routerAddress).getFee(destinationChainSelector, message);
IERC20(linkTokenAddress).approve(routerAddress, ccipFee);
IERC20(tokenToSendAddress).approve(routerAddress, amountToSend);
IRouterClient(routerAddress).ccipSend(destinationChainSelector, message);
vm.stopBroadcast();
}
}
55 changes: 12 additions & 43 deletions script/ConfigurePool.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@
pragma solidity ^0.8.24;

import {Script} from "forge-std/Script.sol";
import {TokenPool} from "@ccip/contracts/src/v0.8/ccip/pools/BurnMintTokenPool.sol";
import {TokenPool} from "@ccip/contracts/src/v0.8/ccip/pools/TokenPool.sol";
import {RateLimiter} from "@ccip/contracts/src/v0.8/ccip/libraries/RateLimiter.sol";

contract ConfigurePoolScript is Script {
function createChainUpdateObject(
function run(
address localPool,
uint64 remoteChainSelector,
address remotePoolAddress,
address remoteTokenAddress,
address remotePool,
address remoteToken,
bool outboundRateLimiterIsEnabled,
uint128 outboundRateLimiterCapacity,
uint128 outboundRateLimiterRate,
bool inboundRateLimiterIsEnabled,
uint128 inboundRateLimiterCapacity,
uint128 inboundRateLimiterRate
) public pure returns (TokenPool.ChainUpdate[] memory) {
) public {
vm.startBroadcast();
bytes[] memory remotePoolAddresses = new bytes[](1);
remotePoolAddresses[0] = abi.encode(address(remotePoolAddress));

TokenPool.ChainUpdate[] memory chains = new TokenPool.ChainUpdate[](1);
chains[0] = TokenPool.ChainUpdate({
remotePoolAddresses[0] = abi.encode(remotePool);
TokenPool.ChainUpdate[] memory chainsToAdd = new TokenPool.ChainUpdate[](1);
chainsToAdd[0] = TokenPool.ChainUpdate({
remoteChainSelector: remoteChainSelector,
remotePoolAddresses: remotePoolAddresses,
remoteTokenAddress: abi.encode(remoteTokenAddress),
remoteTokenAddress: abi.encode(remoteToken),
outboundRateLimiterConfig: RateLimiter.Config({
isEnabled: outboundRateLimiterIsEnabled,
capacity: outboundRateLimiterCapacity,
Expand All @@ -36,38 +37,6 @@ contract ConfigurePoolScript is Script {
rate: inboundRateLimiterRate
})
});
return chains;
}

function run(
address ccipChainPoolAddress,
uint64 remoteChainSelector,
address remotePoolAddress,
address remoteTokenAddress,
bool outboundRateLimiterIsEnabled,
uint128 outboundRateLimiterCapacity,
uint128 outboundRateLimiterRate,
bool inboundRateLimiterIsEnabled,
uint128 inboundRateLimiterCapacity,
uint128 inboundRateLimiterRate
) public {
vm.startBroadcast();

TokenPool tokenPool = TokenPool(ccipChainPoolAddress);
TokenPool.ChainUpdate[] memory chains = createChainUpdateObject(
remoteChainSelector,
remotePoolAddress,
remoteTokenAddress,
outboundRateLimiterIsEnabled,
outboundRateLimiterCapacity,
outboundRateLimiterRate,
inboundRateLimiterIsEnabled,
inboundRateLimiterCapacity,
inboundRateLimiterRate
);
uint64[] memory remoteChainSelectorsToRemove = new uint64[](0);
tokenPool.applyChainUpdates(remoteChainSelectorsToRemove, chains);

vm.stopBroadcast();
TokenPool(localPool).applyChainUpdates(new uint64[](0), chainsToAdd);
}
}
51 changes: 12 additions & 39 deletions script/Deployer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,41 @@
pragma solidity ^0.8.24;

import {Script} from "forge-std/Script.sol";
import {CCIPLocalSimulatorFork, Register} from "@chainlink/local/src/ccip/CCIPLocalSimulatorFork.sol";

import {CCIPLocalSimulatorFork, Register} from "@chainlink-local/src/ccip/CCIPLocalSimulatorFork.sol";

import {IERC20} from "@ccip/contracts/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {RegistryModuleOwnerCustom} from "@ccip/contracts/src/v0.8/ccip/tokenAdminRegistry/RegistryModuleOwnerCustom.sol";
import {TokenAdminRegistry} from "@ccip/contracts/src/v0.8/ccip/tokenAdminRegistry/TokenAdminRegistry.sol";
import {IERC20} from "@ccip/contracts/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";

import {RebaseToken} from "../src/RebaseToken.sol";
import {IRebaseToken} from "../src/interfaces/IRebaseToken.sol";
import {RebaseTokenPool} from "../src/RebaseTokenPool.sol";
import {Vault} from "../src/Vault.sol";

contract TokenDeployer is Script {
CCIPLocalSimulatorFork public ccipLocalSimulatorFork;
Register.NetworkDetails public networkDetails;

RegistryModuleOwnerCustom public registryModuleOwnerCustom;
TokenAdminRegistry public tokenAdminRegistry;
import {IRebaseToken} from "../src/interfaces/IRebaseToken.sol";

contract TokenAndPoolDeployer is Script {
function run() public returns (RebaseToken token, RebaseTokenPool pool) {
ccipLocalSimulatorFork = new CCIPLocalSimulatorFork();
networkDetails = ccipLocalSimulatorFork.getNetworkDetails(block.chainid);

registryModuleOwnerCustom = RegistryModuleOwnerCustom(networkDetails.registryModuleOwnerCustomAddress);
tokenAdminRegistry = TokenAdminRegistry(networkDetails.tokenAdminRegistryAddress);
CCIPLocalSimulatorFork ccipLocalSimulatorFork = new CCIPLocalSimulatorFork();
Register.NetworkDetails memory networkDetails = ccipLocalSimulatorFork.getNetworkDetails(block.chainid);
vm.startBroadcast();

// Step 1) Deploy token
token = new RebaseToken();

// Step 2) Deploy pool
address[] memory allowlist = new address[](0);
pool = new RebaseTokenPool(
IERC20(address(token)), allowlist, networkDetails.rmnProxyAddress, networkDetails.routerAddress
IERC20(address(token)), new address[](0), networkDetails.rmnProxyAddress, networkDetails.routerAddress
);

token.grantMintAndBurnRole(address(pool));

// Step 4) Claim Admin role
registryModuleOwnerCustom.registerAdminViaOwner(address(token));

// Step 5) Accept Admin role
tokenAdminRegistry.acceptAdminRole(address(token));

// Step 6) Link token to pool
tokenAdminRegistry.setPool(address(token), address(pool));

RegistryModuleOwnerCustom(networkDetails.registryModuleOwnerCustomAddress).registerAdminViaOwner(address(token));
TokenAdminRegistry(networkDetails.tokenAdminRegistryAddress).acceptAdminRole(address(token));
TokenAdminRegistry(networkDetails.tokenAdminRegistryAddress).setPool(address(token), address(pool));
vm.stopBroadcast();
}
}

// Only on the source chain!
contract VaultDeployer is Script {
function run(address _rebaseToken) public returns (Vault vault) {
// NOTE: what can I do instead of this by making it interactive? Do I even need this line if I'm using a wallet for this?
//uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast();

// Step 1) Deploy the vault
vault = new Vault(IRebaseToken(_rebaseToken));

// Step 2) Claim burn and mint role
IRebaseToken(_rebaseToken).grantMintAndBurnRole(address(vault));

vm.stopBroadcast();
}
}
Loading

0 comments on commit 11aeffe

Please sign in to comment.