diff --git a/bridgeToZksync.sh b/bridgeToZksync.sh index b0e9dfd..7d70c7d 100755 --- a/bridgeToZksync.sh +++ b/bridgeToZksync.sh @@ -1,7 +1,7 @@ #!/bin/bash # Define constants -ALLOWLIST="[]" # empty array +AMOUNT=100000 DEFAULT_ZKSYNC_LOCAL_KEY="0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110" DEFAULT_ZKSYNC_ADDRESS="0x36615Cf349d7F6344891B1e7CA7C72883F5dc049" @@ -21,6 +21,7 @@ SEPOLIA_CHAIN_SELECTOR="16015286601757825753" SEPOLIA_LINK_ADDRESS="0x779877A7B0D9E8603169DdbD7836e478b4624789" # Compile and deploy the Rebase Token contract +source .env forge build --zksync echo "Compiling and deploying the Rebase Token contract on ZKsync..." ZKSYNC_REBASE_TOKEN_ADDRESS=$(forge create src/RebaseToken.sol:RebaseToken --rpc-url ${ZKSYNC_SEPOLIA_RPC_URL} --account updraft --legacy --zksync | awk '/Deployed to:/ {print $3}') @@ -46,7 +47,7 @@ echo "CCIP roles and permissions set" # 2. On Sepolia! echo "Running the script to deploy the contracts on Sepolia..." -output=$(forge script ./script/Deployer.s.sol:TokenDeployer --rpc-url ${SEPOLIA_RPC_URL} --account updraft --broadcast) +output=$(forge script ./script/Deployer.s.sol:TokenAndPoolDeployer --rpc-url ${SEPOLIA_RPC_URL} --account updraft --broadcast) echo "Contracts deployed and permission set on Sepolia" # Extract the addresses from the output @@ -76,7 +77,7 @@ forge script ./script/ConfigurePool.s.sol:ConfigurePoolScript --rpc-url ${SEPOLI # Deposit funds to the vault echo "Depositing funds to the vault on Sepolia..." -cast send ${VAULT_ADDRESS} --value 100000000000000 --rpc-url ${SEPOLIA_RPC_URL} --account updraft "deposit()" +cast send ${VAULT_ADDRESS} --value ${AMOUNT} --rpc-url ${SEPOLIA_RPC_URL} --account updraft "deposit()" # Wait a beat for some interest to accrue @@ -88,7 +89,7 @@ cast send ${ZKSYNC_POOL_ADDRESS} --rpc-url ${ZKSYNC_SEPOLIA_RPC_URL} --account echo "Bridging the funds using the script to ZKsync..." SEPOLIA_BALANCE_BEFORE=$(cast balance $(cast wallet address --account updraft) --erc20 ${SEPOLIA_REBASE_TOKEN_ADDRESS} --rpc-url ${SEPOLIA_RPC_URL}) echo "Sepolia balance before bridging: $SEPOLIA_BALANCE_BEFORE" -forge script ./script/BridgeTokens.s.sol:BridgeTokensScript --rpc-url ${SEPOLIA_RPC_URL} --account updraft --broadcast --sig "sendMessage(address,uint64,address,uint256,address,address)" $(cast wallet address --account updraft) ${ZKSYNC_SEPOLIA_CHAIN_SELECTOR} ${SEPOLIA_REBASE_TOKEN_ADDRESS} 100000000000000 ${SEPOLIA_LINK_ADDRESS} ${SEPOLIA_ROUTER} +forge script ./script/BridgeTokens.s.sol:BridgeTokensScript --rpc-url ${SEPOLIA_RPC_URL} --account updraft --broadcast --sig "sendMessage(address,uint64,address,uint256,address,address)" $(cast wallet address --account updraft) ${ZKSYNC_SEPOLIA_CHAIN_SELECTOR} ${SEPOLIA_REBASE_TOKEN_ADDRESS} ${AMOUNT} ${SEPOLIA_LINK_ADDRESS} ${SEPOLIA_ROUTER} echo "Funds bridged to ZKsync" SEPOLIA_BALANCE_AFTER=$(cast balance $(cast wallet address --account updraft) --erc20 ${SEPOLIA_REBASE_TOKEN_ADDRESS} --rpc-url ${SEPOLIA_RPC_URL}) echo "Sepolia balance after bridging: $SEPOLIA_BALANCE_AFTER" diff --git a/foundry.toml b/foundry.toml index b062ec1..065b10f 100644 --- a/foundry.toml +++ b/foundry.toml @@ -7,7 +7,7 @@ rpc_endpoints = { eth = "https://eth-sepolia.g.alchemy.com/v2/mwHkM74gwkO6kdWQKC remappings = [ '@openzeppelin/=lib/openzeppelin-contracts/', '@ccip=lib/ccip/', - '@chainlink/local/=lib/chainlink-local/', + '@chainlink-local/=lib/chainlink-local/', ] # See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options diff --git a/script/BridgeTokens.s.sol b/script/BridgeTokens.s.sol index 47560e3..a50cd3c 100644 --- a/script/BridgeTokens.s.sol +++ b/script/BridgeTokens.s.sol @@ -25,7 +25,7 @@ contract BridgeTokensScript is Script { Client.EVMTokenAmount[] memory tokenAmounts = new Client.EVMTokenAmount[](1); tokenAmounts[0] = Client.EVMTokenAmount({token: tokenToSendAddress, amount: amountToSend}); vm.startBroadcast(); - Client.EVM2AnyMessage message = Client.EVM2AnyMessage({ + Client.EVM2AnyMessage memory message = Client.EVM2AnyMessage({ receiver: abi.encode(receiverAddress), data: "", tokenAmounts: tokenAmounts, diff --git a/src/RebaseToken.sol b/src/RebaseToken.sol index c3402d1..909377d 100644 --- a/src/RebaseToken.sol +++ b/src/RebaseToken.sol @@ -13,6 +13,8 @@ import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol"; * @notice Each will user will have their own interest rate that is the global interest rate at the time of depositing. */ contract RebaseToken is ERC20, Ownable, AccessControl { + error RebaseToken__InterestRateCanOnlyDecrease(uint256 currentInterestRate, uint256 newInterestRate); + ///////////////////// // State Variables ///////////////////// @@ -26,7 +28,11 @@ contract RebaseToken is ERC20, Ownable, AccessControl { ///////////////////// // Events ///////////////////// - event InterestRateUpdated(uint256 newInterestRate); + event InterestRateSet(uint256 newInterestRate); + + ///////////////////// + // Constructor + ///////////////////// constructor() Ownable(msg.sender) ERC20("RebaseToken", "RBT") {} @@ -75,26 +81,26 @@ contract RebaseToken is ERC20, Ownable, AccessControl { } /// @notice Mints new tokens for a given address. Called when a user either deposits or bridges tokens to this chain. - /// @param _account The address to mint the tokens to. + /// @param _to The address to mint the tokens to. /// @param _value The number of tokens to mint. - /// @param _interestRate The interest rate of the user. This is either the contract interest rate if the user is depositing or the user's interest rate from the source token if the user is bridging. + /// @param _userInterestRate The interest rate of the user. This is either the contract interest rate if the user is depositing or the user's interest rate from the source token if the user is bridging. /// @dev this function increases the total supply. - function mint(address _account, uint256 _value, uint256 _interestRate) public onlyRole(MINT_AND_BURN_ROLE) { + function mint(address _to, uint256 _value, uint256 _userInterestRate) public onlyRole(MINT_AND_BURN_ROLE) { // Mints any existing interest that has accrued since the last time the user's balance was updated. _mintAccruedInterest(_to); // Sets the users interest rate to either their bridged value if they are bridging or to the current interest rate if they are depositing. s_userInterestRate[_to] = _userInterestRate; - _mint(_account, _value); + _mint(_to, _value); } /// @notice Burns tokens from the sender. - /// @param _account The address to burn the tokens from. + /// @param _from The address to burn the tokens from. /// @param _value The number of tokens to be burned /// @dev this function decreases the total supply. - function burn(address _account, uint256 _value) public onlyRole(MINT_AND_BURN_ROLE) { + function burn(address _from, uint256 _value) public onlyRole(MINT_AND_BURN_ROLE) { // Mints any existing interest that has accrued since the last time the user's balance was updated. _mintAccruedInterest(_from); - _burn(_account, _value); + _burn(_from, _value); } /** @@ -175,7 +181,6 @@ contract RebaseToken is ERC20, Ownable, AccessControl { /** * @dev accumulates the accrued interest of the user to the principal balance. This function mints the users accrued interest since they last transferred or bridged tokens. * @param _user the address of the user for which the interest is being minted - * @return currentBalance users new balance * */ function _mintAccruedInterest(address _user) internal { diff --git a/test/CrossChain.t.sol b/test/CrossChain.t.sol index 14e68e0..4eae0d6 100644 --- a/test/CrossChain.t.sol +++ b/test/CrossChain.t.sol @@ -3,7 +3,7 @@ pragma solidity 0.8.24; import {console, Test} from "forge-std/Test.sol"; -import {CCIPLocalSimulatorFork, Register} from "@chainlink/local/src/ccip/CCIPLocalSimulatorFork.sol"; +import {CCIPLocalSimulatorFork, Register} from "@chainlink-local/src/ccip/CCIPLocalSimulatorFork.sol"; import {TokenPool} from "@ccip/contracts/src/v0.8/ccip/pools/TokenPool.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"; @@ -19,10 +19,6 @@ import {RebaseTokenPool} from "../src/RebaseTokenPool.sol"; import {Vault} from "../src/Vault.sol"; import {IRebaseToken} from "../src/interfaces/IRebaseToken.sol"; -import {TokenDeployer} from "../script/Deployer.s.sol"; -import {VaultDeployer} from "../script/Deployer.s.sol"; -import {BridgeTokensScript} from "../script/BridgeTokens.s.sol"; - // Tests to include // Test you can bridge tokens - check the balance is correct // test you can bridge a portion of tokens - check balances are correct