Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/socket-protocol
Submodule socket-protocol updated 135 files
7 changes: 1 addition & 6 deletions script/counter/DeployEVMxCounterApp.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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);

Expand Down
1 change: 0 additions & 1 deletion script/counter/DeployOnchainCounters.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
15 changes: 6 additions & 9 deletions script/counter/WithdrawFeesArbitrumFeesPlug.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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");
}
Expand Down
8 changes: 3 additions & 5 deletions script/helpers/AppGatewayFeeBalance.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@ 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 {
vm.createSelectFork(vm.envString("EVMX_RPC"));
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);
}
}
52 changes: 0 additions & 52 deletions script/helpers/CheckAppEVMxLimits.s.sol

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/counter/Counter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions src/counter/CounterAppGateway.sol
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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();
}
Expand All @@ -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_;
}

/**
Expand Down
9 changes: 6 additions & 3 deletions test/apps/Counter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down