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
13 changes: 9 additions & 4 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
# RPCs
EVMX_RPC="https://rpc-evmx-devnet.socket.tech/"

SEPOLIA_RPC="https://ethereum-sepolia-rpc.publicnode.com"
ARBITRUM_SEPOLIA_RPC="https://sepolia-rollup.arbitrum.io/rpc"
OPTIMISM_SEPOLIA_RPC="https://sepolia.optimism.io"
BASE_SEPOLIA_RPC="https://sepolia.base.org"

ARBITRUM_RPC="https://arbitrum.drpc.org"
OPTIMISM_RPC="https://optimism.drpc.org"
BASE_RPC="https://base.drpc.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="0x21a9AFDfbEb0399D4a12f3AA1324042Be2B57F8e"
FEES_MANAGER="0x30e07016eB24570629Bc8765CA307394Af90B27C"
ARBITRUM_FEES_PLUG="0xDfE94B9b14de382Ed13C8A7F387884808D0f7E0b"
ARBITRUM_TEST_USDC="0xa03Cbf13f331aF7c0fD7F2E28E6Cbc13F879E3F3"
ADDRESS_RESOLVER="0x935b06902cA5C8bb4C76e18738561c294D377A93"
FEES_MANAGER="0xA07208F9e7aE243F922317ab6604DC9F86822406"
ARBITRUM_FEES_PLUG="0x501bdF8C7163ddD32172575C2836c5A7F556cbE7"
ARBITRUM_USDC="0xaf88d065e77c8cC2239327C5EDb3A432268e5831"

# 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 .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "lib/socket-protocol"]
path = lib/socket-protocol
url = https://github.com/SocketDotTech/socket-protocol.git
branch = master
branch = dev
2 changes: 1 addition & 1 deletion lib/socket-protocol
Submodule socket-protocol updated 142 files
11 changes: 9 additions & 2 deletions script/counter/DeployEVMxCounterApp.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.0;
import {Script} from "forge-std/Script.sol";
import {console} from "forge-std/console.sol";

import "socket-protocol/contracts/evmx/interfaces/IFeesManager.sol";
import {CounterAppGateway} from "../../src/counter/CounterAppGateway.sol";

/**
Expand All @@ -23,18 +24,24 @@ import {CounterAppGateway} from "../../src/counter/CounterAppGateway.sol";
contract CounterDeploy is Script {
function run() external {
address addressResolver = vm.envAddress("ADDRESS_RESOLVER");
IFeesManager feesManager = IFeesManager(payable(vm.envAddress("FEES_MANAGER")));
string memory rpc = vm.envString("EVMX_RPC");
vm.createSelectFork(rpc);

uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);

// Setting fee payment on Arbitrum Sepolia
uint256 fees = 10 ether;
uint256 fees = 0.1 ether;

CounterAppGateway appGateway = new CounterAppGateway(addressResolver, fees);

console.log("CounterAppGateway contract:", address(appGateway));
console.log("See AppGateway on EVMx: https://evmx.cloud.blockscout.com/address/%s", address(appGateway));
console.log("Do not forget to add the contract address to the .env file!");

console.log("Approving AppGateway to spend from funds in EOA");
AppGatewayApprovals[] memory approvals = new AppGatewayApprovals[](1);
approvals[0] = AppGatewayApprovals({appGateway: address(appGateway), approval: true});
feesManager.approveAppGateways(approvals);
}
}
74 changes: 0 additions & 74 deletions script/counter/WithdrawFeesArbitrumFeesPlug.s.sol

This file was deleted.

22 changes: 0 additions & 22 deletions script/helpers/AppGatewayFeeBalance.s.sol

This file was deleted.

25 changes: 25 additions & 0 deletions script/helpers/CheckAvailableCredits.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: MIT
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/evmx/fees/FeesManager.sol";

contract CheckAvailableCredits is Script {
function run() external {
FeesManager feesManager = FeesManager(payable(vm.envAddress("FEES_MANAGER")));

uint256 privateKey = vm.envUint("PRIVATE_KEY");
address sender = vm.addr(privateKey);
console.log("Sender address:", sender);

vm.createSelectFork(vm.envString("EVMX_RPC"));

(uint256 deposited, uint256 blocked) = feesManager.userCredits(sender);
console.log("Total balance of available credits for this address: %s", deposited);
console.log("Credits being locked due to existing transactions: %s", blocked);

uint256 availableFees = feesManager.getAvailableCredits(sender);
console.log("Credits available to be spent on transactions: %s", availableFees);
}
}
41 changes: 41 additions & 0 deletions script/helpers/DepositCreditAndNative.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.21;

import {Script} from "forge-std/Script.sol";
import {console} from "forge-std/console.sol";
import {FeesPlug} from "socket-protocol/contracts/evmx/plugs/FeesPlug.sol";
// source .env && forge script script/helpers/DepositCreditAndNative.s.sol --broadcast --skip-simulation

interface IERC20 {
function approve(address spender, uint256 value) external returns (bool);
function balanceOf(address account) external view returns (uint256);
}

contract DepositCredit is Script {
function run() external {
uint256 privateKey = vm.envUint("PRIVATE_KEY");
address sender = vm.addr(privateKey);
console.log("Sender address:", sender);

FeesPlug feesPlug = FeesPlug(payable(vm.envAddress("ARBITRUM_FEES_PLUG")));
address arbitrumUSDC = vm.envAddress("ARBITRUM_USDC");
IERC20 USDCContract = IERC20(arbitrumUSDC);

vm.createSelectFork(vm.envString("ARBITRUM_RPC"));
vm.startBroadcast(privateKey);
uint256 balance = USDCContract.balanceOf(sender);

uint256 feesAmount = 1000000; // 1 USDC
if (balance < feesAmount) {
console.log("Sender USDC balance:", balance);
revert("Sender does not have enough USDC. Requires 1 USDC.");
}

console.log("Depositing", feesAmount, " - 1 USDC to Arbitrum FeesPlug:", address(feesPlug));
console.log("Approving Spending...");
USDCContract.approve(address(feesPlug), feesAmount);

feesPlug.depositCreditAndNative(arbitrumUSDC, sender, feesAmount);
console.log("Corresponding EVMx credits will show up on your account");
}
}
36 changes: 0 additions & 36 deletions script/helpers/PayFeesInArbitrumTestUSDC.s.sol

This file was deleted.

51 changes: 51 additions & 0 deletions script/helpers/WithdrawCreditsArbitrumFeesPlug.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {Script} from "forge-std/Script.sol";
import {console} from "forge-std/console.sol";
import "socket-protocol/contracts/evmx/interfaces/IFeesManager.sol";

import {CounterAppGateway} from "../../src/counter/CounterAppGateway.sol";

/**
* @title WithdrawCredits Script
* @notice Withdraws accumulated fees from EVMX to Arbitrum Sepolia
* @dev This script:
* 1. Checks available fees on EVMX
* 2. Performs the withdrawal if the amount is positive
*
* This demonstrates how developers can retrieve fees that their application has earned
* through SOCKET Protocol's fee system.
*/
contract WithdrawCredits is Script {
function run() external {
// EVMX Check available fees
vm.createSelectFork(vm.envString("EVMX_RPC"));
IFeesManager feesManager = IFeesManager(payable(vm.envAddress("FEES_MANAGER")));
address token = vm.envAddress("ARBITRUM_USDC");
uint256 privateKey = vm.envUint("PRIVATE_KEY");
address sender = vm.addr(privateKey);

uint256 availableCredits = feesManager.getAvailableCredits(sender);
console.log("Available credits:", availableCredits);
//consfeesManager.tokenOntokenOnChainBalances[42161][token];

if (availableCredits > 0) {
uint256 maxFees = 10000000000000000; // Static 1 cent USDC credit (18 decimals)
// TODO: Also wrap native amount to be able to max withdraw
uint256 amountToWithdraw = availableCredits - maxFees;

if (amountToWithdraw > 0) {
vm.startBroadcast(privateKey);
AppGatewayApprovals[] memory approvals = new AppGatewayApprovals[](1);
approvals[0] = AppGatewayApprovals({appGateway: address(feesManager), approval: true});
feesManager.approveAppGateways(approvals);
console.log("Withdrawing amount:", amountToWithdraw);
feesManager.withdrawCredits(42161, token, amountToWithdraw, maxFees, sender);
vm.stopBroadcast();
} else {
console.log("Available fees less than estimated gas cost");
}
}
}
}
27 changes: 11 additions & 16 deletions src/counter/CounterAppGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ 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_, uint256 fees_) AppGatewayBase(addressResolver_) {
constructor(address addressResolver_, uint256 fees_) {
creationCodeWithArgs[counter] = abi.encodePacked(type(Counter).creationCode);
_setMaxFees(fees_);
_initializeOwner(msg.sender);
_initializeAppGateway(addressResolver_);
}

/**
Expand All @@ -42,7 +43,10 @@ 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(bytes("")) {
function deployContracts(uint32 chainSlug_) external async {
// This ensures the msg.sender is the one paying for the fees
// for more information see: https://docs.socket.tech/fees
_setOverrides(msg.sender);
_deploy(counter, chainSlug_, IsPlug.YES);
}

Expand All @@ -53,7 +57,7 @@ contract CounterAppGateway is AppGatewayBase, Ownable {
* For more information on the initialize function, see:
* https://docs.socket.tech/deploy#initialize
*/
function initialize(uint32 /* chainSlug_ */ ) public pure override {
function initializeOnChain(uint32 /* chainSlug_ */ ) public pure override {
return;
}

Expand All @@ -62,7 +66,10 @@ 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(bytes("")) {
function incrementCounters(address[] memory instances_) public async {
// This ensures the msg.sender is the one paying for the fees
// for more information see: https://docs.socket.tech/fees
_setOverrides(msg.sender);
for (uint256 i = 0; i < instances_.length; i++) {
ICounter(instances_[i]).increase();
}
Expand All @@ -76,16 +83,4 @@ contract CounterAppGateway is AppGatewayBase, Ownable {
function setMaxFees(uint256 fees_) public {
maxFees = fees_;
}

/**
* @notice Withdraws fee tokens from the SOCKET Protocol
* @dev Allows withdrawal of accumulated fees to a specified receiver
* @param chainSlug_ The chain from which to withdraw fees
* @param token_ The token address to withdraw
* @param amount_ The amount to withdraw
* @param receiver_ The address that will receive the withdrawn fees
*/
function withdrawFeeTokens(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external {
_withdrawFeeTokens(chainSlug_, token_, amount_, receiver_);
}
}
Loading