diff --git a/.env.sample b/.env.sample index 625c696..5caa12b 100644 --- a/.env.sample +++ b/.env.sample @@ -8,9 +8,10 @@ BASE_SEPOLIA_RPC="https://sepolia.base.org" # EVMx key addresses # Find the most up to date addresses at: # https://github.com/SocketDotTech/socket-protocol/blob/master/deployments/stage_addresses.json -ADDRESS_RESOLVER="0x4846430BB142385e581C894AE92a4CF0722aEC21" -FEES_MANAGER="0x9745623Aaa299500F93d2B1B4Efb7b3EC5e60FFc" -ARBITRUM_FEES_PLUG="0x9E263f6c7C199d9c147E30764A8cae1175184CB8" +ADDRESS_RESOLVER="0x21a9AFDfbEb0399D4a12f3AA1324042Be2B57F8e" +FEES_MANAGER="0x30e07016eB24570629Bc8765CA307394Af90B27C" +ARBITRUM_FEES_PLUG="0xDfE94B9b14de382Ed13C8A7F387884808D0f7E0b" +ARBITRUM_TEST_USDC="0xa03Cbf13f331aF7c0fD7F2E28E6Cbc13F879E3F3" # Add your deployer private key here # or remove it from this file if it is already an env var diff --git a/lib/socket-protocol b/lib/socket-protocol index aa83294..38accd5 160000 --- a/lib/socket-protocol +++ b/lib/socket-protocol @@ -1 +1 @@ -Subproject commit aa832943bc2a943a6e7c2c5d69ef1cd1412226c5 +Subproject commit 38accd5f8a4144297048940122d56a08578c1783 diff --git a/script/counter/DeployEVMxCounterApp.s.sol b/script/counter/DeployEVMxCounterApp.s.sol index ce933b2..bf17987 100644 --- a/script/counter/DeployEVMxCounterApp.s.sol +++ b/script/counter/DeployEVMxCounterApp.s.sol @@ -3,8 +3,6 @@ pragma solidity ^0.8.0; import {Script} from "forge-std/Script.sol"; import {console} from "forge-std/console.sol"; -import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol"; -import {ETH_ADDRESS} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; import {CounterAppGateway} from "../../src/counter/CounterAppGateway.sol"; @@ -32,10 +30,7 @@ contract CounterDeploy is Script { vm.startBroadcast(deployerPrivateKey); // Setting fee payment on Arbitrum Sepolia - // amount: Minimum fee required in contract and maximum user is willing to pay - // User must have deposited >= amount, ensuring transmitter gets compensated for including this tx in a batch - // Current Counter example costs 0.000105 eth - Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.0005 ether}); + uint256 fees = 10 ether; CounterAppGateway appGateway = new CounterAppGateway(addressResolver, fees); diff --git a/script/counter/DeployOnchainCounters.s.sol b/script/counter/DeployOnchainCounters.s.sol index fc55eba..0c0b007 100644 --- a/script/counter/DeployOnchainCounters.s.sol +++ b/script/counter/DeployOnchainCounters.s.sol @@ -3,7 +3,6 @@ pragma solidity ^0.8.0; import {Script} from "forge-std/Script.sol"; import {console} from "forge-std/console.sol"; -import {ETH_ADDRESS} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; import {CounterAppGateway} from "../../src/counter/CounterAppGateway.sol"; diff --git a/script/counter/WithdrawFeesArbitrumFeesPlug.s.sol b/script/counter/WithdrawFeesArbitrumFeesPlug.s.sol index 894ff24..7b35584 100644 --- a/script/counter/WithdrawFeesArbitrumFeesPlug.s.sol +++ b/script/counter/WithdrawFeesArbitrumFeesPlug.s.sol @@ -3,8 +3,8 @@ pragma solidity ^0.8.0; import {Script} from "forge-std/Script.sol"; import {console} from "forge-std/console.sol"; -import {FeesManager} from "socket-protocol/contracts/protocol/payload-delivery/FeesManager.sol"; -import {ETH_ADDRESS} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; +import {FeesManager} from "socket-protocol/contracts/evmx/payload-delivery/FeesManager.sol"; +import {TestUSDC} from "socket-protocol/contracts/evmx/helpers/TestUSDC.sol"; import {CounterAppGateway} from "../../src/counter/CounterAppGateway.sol"; @@ -35,9 +35,10 @@ contract WithdrawFees is Script { vm.createSelectFork(vm.envString("EVMX_RPC")); FeesManager feesManager = FeesManager(payable(vm.envAddress("FEES_MANAGER"))); address appGatewayAddress = vm.envAddress("APP_GATEWAY"); + TestUSDC testUSDCContract = TestUSDC(vm.envAddress("ARBITRUM_TEST_USDC")); CounterAppGateway appGateway = CounterAppGateway(appGatewayAddress); - uint256 availableFees = feesManager.getAvailableFees(421614, appGatewayAddress, ETH_ADDRESS); + uint256 availableFees = feesManager.getMaxCreditsAvailableForWithdraw(appGatewayAddress); console.log("Available fees:", availableFees); if (availableFees > 0) { @@ -48,7 +49,7 @@ contract WithdrawFees is Script { // Gas price from Arbitrum uint256 arbitrumGasPrice = block.basefee + 0.1 gwei; // With buffer - uint256 gasLimit = 3_000_000; // Estimate + uint256 gasLimit = 50_000_000_000; // Estimate uint256 estimatedGasCost = gasLimit * arbitrumGasPrice; console.log("Arbitrum gas price (wei):", arbitrumGasPrice); @@ -63,12 +64,8 @@ contract WithdrawFees is Script { vm.createSelectFork(vm.envString("EVMX_RPC")); vm.startBroadcast(privateKey); console.log("Withdrawing amount:", amountToWithdraw); - appGateway.withdrawFeeTokens(421614, ETH_ADDRESS, amountToWithdraw, sender); + appGateway.withdrawFeeTokens(421614, address(testUSDCContract), amountToWithdraw, sender); vm.stopBroadcast(); - - // Switch back to Arbitrum Sepolia to check final balance - vm.createSelectFork(vm.envString("ARBITRUM_SEPOLIA_RPC")); - console.log("Final sender balance:", sender.balance); } else { console.log("Available fees less than estimated gas cost"); } diff --git a/script/helpers/AppGatewayFeeBalance.s.sol b/script/helpers/AppGatewayFeeBalance.s.sol index d4f3972..b1bb48e 100644 --- a/script/helpers/AppGatewayFeeBalance.s.sol +++ b/script/helpers/AppGatewayFeeBalance.s.sol @@ -3,9 +3,7 @@ pragma solidity ^0.8.0; import {Script} from "forge-std/Script.sol"; import {console} from "forge-std/console.sol"; -import {FeesManager} from "socket-protocol/contracts/protocol/payload-delivery/FeesManager.sol"; -import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol"; -import {ETH_ADDRESS} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; +import {FeesManager} from "socket-protocol/contracts/evmx/payload-delivery/FeesManager.sol"; contract CheckDepositedFees is Script { function run() external { @@ -13,12 +11,12 @@ contract CheckDepositedFees is Script { FeesManager feesManager = FeesManager(payable(vm.envAddress("FEES_MANAGER"))); address appGateway = vm.envAddress("APP_GATEWAY"); - (uint256 deposited, uint256 blocked) = feesManager.appGatewayFeeBalances(appGateway, 421614, ETH_ADDRESS); + (uint256 deposited, uint256 blocked) = feesManager.userCredits(appGateway); console.log("AppGateway:", appGateway); console.log("Total balance of available fees for this AppGateway: %s", deposited); console.log("Fees being locked due to existing transactions: %s", blocked); - uint256 availableFees = feesManager.getAvailableFees(421614, appGateway, ETH_ADDRESS); + uint256 availableFees = feesManager.getAvailableCredits(appGateway); console.log("Fees available to be spent on transactions: %s", availableFees); } } diff --git a/script/helpers/CheckAppEVMxLimits.s.sol b/script/helpers/CheckAppEVMxLimits.s.sol deleted file mode 100644 index b570fd2..0000000 --- a/script/helpers/CheckAppEVMxLimits.s.sol +++ /dev/null @@ -1,52 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.13; - -import "forge-std/Script.sol"; -import {WatcherPrecompile} from "socket-protocol/contracts/protocol/watcherPrecompile/WatcherPrecompile.sol"; -import {LimitParams} from "socket-protocol/contracts/protocol/utils/common/Structs.sol"; -import {SCHEDULE, QUERY, FINALIZE} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; - -contract CheckLimitsScript is Script { - function run() external { - string memory rpc = vm.envString("EVMX_RPC"); - vm.createSelectFork(rpc); - - address watcherPrecompile = vm.envAddress("WATCHER_PRECOMPILE"); - address appGateway = vm.envAddress("APP_GATEWAY"); - - console.log("WatcherPrecompile address:", watcherPrecompile); - console.log("AppGateway address:", appGateway); - WatcherPrecompile watcherContract = WatcherPrecompile(watcherPrecompile); - - LimitParams memory scheduleLimit = - watcherContract.watcherPrecompileLimits__().getLimitParams(SCHEDULE, appGateway); - LimitParams memory queryLimit = watcherContract.watcherPrecompileLimits__().getLimitParams(QUERY, appGateway); - LimitParams memory finalizeLimit = - watcherContract.watcherPrecompileLimits__().getLimitParams(FINALIZE, appGateway); - - uint256 scheduleCurrentLimit = watcherContract.watcherPrecompileLimits__().getCurrentLimit(SCHEDULE, appGateway); - uint256 queryCurrentLimit = watcherContract.watcherPrecompileLimits__().getCurrentLimit(QUERY, appGateway); - uint256 finalizeCurrentLimit = watcherContract.watcherPrecompileLimits__().getCurrentLimit(FINALIZE, appGateway); - - console.log("Schedule max limit:"); - console.log(scheduleLimit.maxLimit); - console.log("Schedule rate per second:"); - console.log(scheduleLimit.ratePerSecond); - console.log("Schedule current limit:"); - console.log(scheduleCurrentLimit); - - console.log("Query max limit:"); - console.log(queryLimit.maxLimit); - console.log("Query rate per second:"); - console.log(queryLimit.ratePerSecond); - console.log("Query current limit:"); - console.log(queryCurrentLimit); - - console.log("Finalize max limit:"); - console.log(finalizeLimit.maxLimit); - console.log("Finalize rate per second:"); - console.log(finalizeLimit.ratePerSecond); - console.log("Finalize current limit:"); - console.log(finalizeCurrentLimit); - } -} diff --git a/script/helpers/PayFeesInArbitrumETH.s.sol b/script/helpers/PayFeesInArbitrumTestUSDC.s.sol similarity index 51% rename from script/helpers/PayFeesInArbitrumETH.s.sol rename to script/helpers/PayFeesInArbitrumTestUSDC.s.sol index 36cfdb4..b016261 100644 --- a/script/helpers/PayFeesInArbitrumETH.s.sol +++ b/script/helpers/PayFeesInArbitrumTestUSDC.s.sol @@ -3,26 +3,32 @@ pragma solidity ^0.8.0; import {Script} from "forge-std/Script.sol"; import {console} from "forge-std/console.sol"; -import {FeesPlug} from "socket-protocol/contracts/protocol/payload-delivery/FeesPlug.sol"; -import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol"; -import {ETH_ADDRESS} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; +import {FeesPlug} from "socket-protocol/contracts/evmx/payload-delivery/FeesPlug.sol"; +import {TestUSDC} from "socket-protocol/contracts/evmx/helpers/TestUSDC.sol"; contract DepositFees is Script { function run() external { vm.createSelectFork(vm.envString("ARBITRUM_SEPOLIA_RPC")); uint256 privateKey = vm.envUint("PRIVATE_KEY"); - vm.startBroadcast(privateKey); + address sender = vm.addr(privateKey); + + uint256 feesAmount = 100000000; // 10 USDC FeesPlug feesPlug = FeesPlug(payable(vm.envAddress("ARBITRUM_FEES_PLUG"))); address appGateway = vm.envAddress("APP_GATEWAY"); + TestUSDC testUSDCContract = TestUSDC(vm.envAddress("ARBITRUM_TEST_USDC")); - address sender = vm.addr(privateKey); - uint256 balance = sender.balance; + vm.startBroadcast(privateKey); + // mint test USDC to sender + testUSDCContract.mint(sender, feesAmount); + // approve fees plug to spend test USDC + testUSDCContract.approve(address(feesPlug), feesAmount); + + uint256 balance = testUSDCContract.balanceOf(sender); console.log("Using address %s with %s balance in wei", sender, balance); - uint256 feesAmount = 0.001 ether; - console.log("Depositing 0.001 ether on Arbitrum FeesPlug %s", address(feesPlug)); - feesPlug.deposit{value: feesAmount}(ETH_ADDRESS, appGateway, feesAmount); + console.log("Depositing 10 TestUSDC on Arbitrum FeesPlug %s", address(feesPlug)); + feesPlug.depositToFeeAndNative(address(testUSDCContract), appGateway, feesAmount); console.log("Added fee balance for AppGateway %s", feesAmount, appGateway); } } diff --git a/src/counter/Counter.sol b/src/counter/Counter.sol index 29c97e5..d38a75b 100644 --- a/src/counter/Counter.sol +++ b/src/counter/Counter.sol @@ -2,7 +2,7 @@ pragma solidity >=0.7.0 <0.9.0; import "solady/auth/Ownable.sol"; -import "socket-protocol/contracts/base/PlugBase.sol"; +import "socket-protocol/contracts/protocol/base/PlugBase.sol"; /** * @title Counter diff --git a/src/counter/CounterAppGateway.sol b/src/counter/CounterAppGateway.sol index 4d2055b..b7c8798 100644 --- a/src/counter/CounterAppGateway.sol +++ b/src/counter/CounterAppGateway.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; -import "socket-protocol/contracts/base/AppGatewayBase.sol"; -import "socket-protocol/contracts/interfaces/IForwarder.sol"; -import "socket-protocol/contracts/interfaces/IPromise.sol"; +import "socket-protocol/contracts/evmx/base/AppGatewayBase.sol"; +import "socket-protocol/contracts/evmx/interfaces/IForwarder.sol"; +import "socket-protocol/contracts/evmx/interfaces/IPromise.sol"; import "./Counter.sol"; import "./ICounter.sol"; @@ -29,9 +29,9 @@ contract CounterAppGateway is AppGatewayBase, Ownable { * @param addressResolver_ Address of the SOCKET Protocol's AddressResolver contract * @param fees_ Fee configuration for multi-chain operations */ - constructor(address addressResolver_, Fees memory fees_) AppGatewayBase(addressResolver_) { + constructor(address addressResolver_, uint256 fees_) AppGatewayBase(addressResolver_) { creationCodeWithArgs[counter] = abi.encodePacked(type(Counter).creationCode); - _setOverrides(fees_); + _setMaxFees(fees_); _initializeOwner(msg.sender); } @@ -42,7 +42,7 @@ contract CounterAppGateway is AppGatewayBase, Ownable { * https://docs.socket.tech/writing-apps#onchain-contract-deployment-with-the-appgateway-contract * @param chainSlug_ The identifier of the target chain */ - function deployContracts(uint32 chainSlug_) external async { + function deployContracts(uint32 chainSlug_) external async(bytes("")) { _deploy(counter, chainSlug_, IsPlug.YES); } @@ -62,7 +62,7 @@ contract CounterAppGateway is AppGatewayBase, Ownable { * @dev Calls the increase function on each counter instance provided * @param instances_ Array of counter contract addresses to increment */ - function incrementCounters(address[] memory instances_) public async { + function incrementCounters(address[] memory instances_) public async(bytes("")) { for (uint256 i = 0; i < instances_.length; i++) { ICounter(instances_[i]).increase(); } @@ -73,8 +73,8 @@ contract CounterAppGateway is AppGatewayBase, Ownable { * @dev Allows the owner to modify fee settings for multi-chain operations * @param fees_ New fee configuration */ - function setFees(Fees memory fees_) public { - fees = fees_; + function setMaxFees(uint256 fees_) public { + maxFees = fees_; } /** diff --git a/test/apps/Counter.t.sol b/test/apps/Counter.t.sol index dcba950..066c298 100644 --- a/test/apps/Counter.t.sol +++ b/test/apps/Counter.t.sol @@ -16,15 +16,18 @@ contract CounterTest is DeliveryHelperTest { function deploySetup() internal { setUpDeliveryHelper(); - counterGateway = new CounterAppGateway(address(addressResolver), createFees(feesAmount)); - depositFees(address(counterGateway), createFees(1 ether)); + counterGateway = new CounterAppGateway(address(addressResolver), feesAmount); + depositUSDCFees( + address(counterGateway), + OnChainFees({chainSlug: arbChainSlug, token: address(arbConfig.feesTokenUSDC), amount: 1 ether}) + ); counterId = counterGateway.counter(); contractIds[0] = counterId; } function deployCounterApp(uint32 chainSlug) internal returns (uint40 requestCount) { - requestCount = _deploy(chainSlug, IAppGateway(counterGateway), contractIds); + requestCount = _deploy(chainSlug, counterGateway, contractIds); } function testCounterDeployment() external {