diff --git a/EventTopics.md b/EventTopics.md index 9c39c004..b6bdc3df 100644 --- a/EventTopics.md +++ b/EventTopics.md @@ -80,9 +80,7 @@ | `OwnershipHandoverCanceled` | `(pendingOwner: address)` | `0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92` | | `OwnershipHandoverRequested` | `(pendingOwner: address)` | `0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d` | | `OwnershipTransferred` | `(oldOwner: address, newOwner: address)` | `0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0` | -| `SusdcTokenSet` | `(chainSlug: uint32, susdcToken: bytes32)` | `0xa268c0ce0f78082ba676c10a8a79a2785e196d85b3e883f8368f663536189525` | | `Transfer` | `(from: address, to: address, amount: uint256)` | `0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef` | -| `WhitelistedReceiverSet` | `(receiver: address, isWhitelisted: bool)` | `0x1fc608eb6791d1ef5d49904b6fc17867efb0319743013f69d29403e20741e53b` | | `WithdrawFailed` | `(payloadId: bytes32)` | `0xea147eb2109f71b4bda9e57528ba08b84821087a31cb43a7851dc6ff743d9be7` | ## FeesPool @@ -174,33 +172,18 @@ ## FeesPlug -| Event | Arguments | Topic | -| ---------------------------- | ------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------- | -| `ConnectorPlugDisconnected` | `()` | `0xc2af098c82dba3c4b00be8bda596d62d13b98a87b42626fefa67e0bb0e198fdd` | -| `FeesDeposited` | `(token: address, receiver: address, creditAmount: uint256, nativeAmount: uint256, data: bytes)` | `0x91f985f17a8632ae2e0a009d65ae250f373d82359d2389b58ea50ada6436682a` | -| `FeesWithdrawn` | `(token: address, receiver: address, amount: uint256)` | `0x5e110f8bc8a20b65dcc87f224bdf1cc039346e267118bae2739847f07321ffa8` | -| `OwnershipHandoverCanceled` | `(pendingOwner: address)` | `0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92` | -| `OwnershipHandoverRequested` | `(pendingOwner: address)` | `0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d` | -| `OwnershipTransferred` | `(oldOwner: address, newOwner: address)` | `0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0` | -| `RoleGranted` | `(role: bytes32, grantee: address)` | `0x2ae6a113c0ed5b78a53413ffbb7679881f11145ccfba4fb92e863dfcd5a1d2f3` | -| `RoleRevoked` | `(role: bytes32, revokee: address)` | `0x155aaafb6329a2098580462df33ec4b7441b19729b9601c5fc17ae1cf99a8a52` | -| `TokenRemovedFromWhitelist` | `(token: address)` | `0xdd2e6d9f52cbe8f695939d018b7d4a216dc613a669876163ac548b916489d917` | -| `TokenWhitelisted` | `(token: address)` | `0x6a65f90b1a644d2faac467a21e07e50e3f8fa5846e26231d30ae79a417d3d262` | - -## SUSDC - -| Event | Arguments | Topic | -| ---------------------------- | ------------------------------------------------------------ | -------------------------------------------------------------------- | -| `Approval` | `(owner: address, spender: address, amount: uint256)` | `0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925` | -| `ConnectorPlugDisconnected` | `()` | `0xc2af098c82dba3c4b00be8bda596d62d13b98a87b42626fefa67e0bb0e198fdd` | -| `OwnershipHandoverCanceled` | `(pendingOwner: address)` | `0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92` | -| `OwnershipHandoverRequested` | `(pendingOwner: address)` | `0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d` | -| `OwnershipTransferred` | `(oldOwner: address, newOwner: address)` | `0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0` | -| `RoleGranted` | `(role: bytes32, grantee: address)` | `0x2ae6a113c0ed5b78a53413ffbb7679881f11145ccfba4fb92e863dfcd5a1d2f3` | -| `RoleRevoked` | `(role: bytes32, revokee: address)` | `0x155aaafb6329a2098580462df33ec4b7441b19729b9601c5fc17ae1cf99a8a52` | -| `TokensBurned` | `(from: address, to: address, amount: uint256, data: bytes)` | `0x568ab03f32147bb501e2805da5910cb00bfca97231507d615ce5326dcf93eae6` | -| `TokensMinted` | `(to: address, amount: uint256)` | `0x3f2c9d57c068687834f0de942a9babb9e5acab57d516d3480a3c16ee165a4273` | -| `Transfer` | `(from: address, to: address, amount: uint256)` | `0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef` | +| Event | Arguments | Topic | +| ---------------------------- | ----------------------------------------------------------------------------------- | -------------------------------------------------------------------- | +| `ConnectorPlugDisconnected` | `()` | `0xc2af098c82dba3c4b00be8bda596d62d13b98a87b42626fefa67e0bb0e198fdd` | +| `FeesDeposited` | `(token: address, receiver: address, creditAmount: uint256, nativeAmount: uint256)` | `0xeb4e1b24b7fe377de69f80f7380bda5ba4b43176c6a4d300a3be9009c49f4228` | +| `FeesWithdrawn` | `(token: address, receiver: address, amount: uint256)` | `0x5e110f8bc8a20b65dcc87f224bdf1cc039346e267118bae2739847f07321ffa8` | +| `OwnershipHandoverCanceled` | `(pendingOwner: address)` | `0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92` | +| `OwnershipHandoverRequested` | `(pendingOwner: address)` | `0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d` | +| `OwnershipTransferred` | `(oldOwner: address, newOwner: address)` | `0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0` | +| `RoleGranted` | `(role: bytes32, grantee: address)` | `0x2ae6a113c0ed5b78a53413ffbb7679881f11145ccfba4fb92e863dfcd5a1d2f3` | +| `RoleRevoked` | `(role: bytes32, revokee: address)` | `0x155aaafb6329a2098580462df33ec4b7441b19729b9601c5fc17ae1cf99a8a52` | +| `TokenRemovedFromWhitelist` | `(token: address)` | `0xdd2e6d9f52cbe8f695939d018b7d4a216dc613a669876163ac548b916489d917` | +| `TokenWhitelisted` | `(token: address)` | `0x6a65f90b1a644d2faac467a21e07e50e3f8fa5846e26231d30ae79a417d3d262` | ## Configurations @@ -219,6 +202,7 @@ | Event | Arguments | Topic | | -------------------- | ------------------------------------------------ | -------------------------------------------------------------------- | +| `Initialized` | `(version: uint64)` | `0xc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d2` | | `MarkedRevert` | `(payloadId: bytes32, isRevertingOnchain: bool)` | `0xcf1fd844cb4d32cbebb5ca6ce4ac834fe98da3ddac44deb77fffd22ad933824c` | | `PromiseNotResolved` | `(payloadId: bytes32, asyncPromise: address)` | `0xbcf0d0c678940566e9e64f0c871439395bd5fb5c39bca3547b126fe6ee467937` | | `PromiseResolved` | `(payloadId: bytes32, asyncPromise: address)` | `0x1b1b5810494fb3e17f7c46547e6e67cd6ad3e6001ea6fb7d12ea0241ba13c4ba` | diff --git a/FunctionSignatures.md b/FunctionSignatures.md index be7db21c..858e5b70 100644 --- a/FunctionSignatures.md +++ b/FunctionSignatures.md @@ -115,30 +115,40 @@ | Function | Signature | | ---------------------------- | ------------ | +| `DOMAIN_SEPARATOR` | `0x3644e515` | | `addressResolver__` | `0x6a750469` | -| `approve` | `0xa3b53d8b` | -| `approveWithSignature` | `0x94b649ec` | -| `approveAppGateways` | `0x86d23ab2` | +| `allowance` | `0xdd62ed3e` | +| `approve` | `0x095ea7b3` | +| `approveWithSignature` | `0xf65de26c` | | `asyncDeployer__` | `0x2a39e801` | | `auctionManager` | `0xb0192f9a` | +| `balanceOf` | `0x70a08231` | +| `batchApprove` | `0x525b3861` | | `blockCredits` | `0x9e434307` | | `cancelOwnershipHandover` | `0x54d1f13d` | | `completeOwnershipHandover` | `0xf04e283e` | | `consumeFrom` | `0x40dd78be` | | `creationCodeWithArgs` | `0xc126dcc4` | +| `decimals` | `0x313ce567` | | `deployForwarder__` | `0xd4e3b034` | | `deposit` | `0x5671d329` | +| `deprecated2` | `0x9897ed76` | +| `deprecated3` | `0x690e4d24` | +| `deprecated4` | `0xefe1358a` | | `deprecatedSbType` | `0x5a783900` | | `evmxSlug` | `0x8bae77c2` | | `feesManager__` | `0x70568b58` | | `feesPlugs` | `0x23f5ee8a` | | `feesPool` | `0x6b259690` | | `forwarderAddresses` | `0x5390fdcb` | -| `balanceOf` | `0xb065a8e5` | +| `getBlockedCredits` | `0x7987deca` | +| `getChainMaxFees` | `0xd26d8bf2` | +| `getMaxFees` | `0x64fe97fa` | | `getOnChainAddress` | `0xb6abffd7` | | `getOverrideParams` | `0x54f0a866` | | `handleRevert` | `0x44792f25` | -| `initialize` | `0xbf2c8539` | +| `increaseFees` | `0xe9b304da` | +| `initialize` | `0xc13547c5` | | `initializeOnChain` | `0x86f01739` | | `isApproved` | `0xa389783e` | | `isAsyncModifierSet` | `0xb69e0c4a` | @@ -146,26 +156,36 @@ | `isNonceUsed` | `0xcab7e8eb` | | `isValidPromise` | `0xb690b962` | | `maxFees` | `0xe83e34b1` | +| `maxFeesPerChainSlug` | `0xe06340d4` | +| `name` | `0x06fdde03` | +| `nonces` | `0x7ecebe00` | | `onCompleteData` | `0xb52fa926` | | `onDeployComplete` | `0xfa3dbd1e` | | `overrideParams` | `0xec5490fe` | | `owner` | `0x8da5cb5b` | | `ownershipHandoverExpiresAt` | `0xfee81cf4` | +| `permit` | `0xd505accf` | | `renounceOwnership` | `0x715018a6` | | `requestBlockedCredits` | `0xb62d25ac` | | `requestOwnershipHandover` | `0x25692962` | | `rescueFunds` | `0x6ccae054` | | `sbType` | `0x745de344` | | `setAddress` | `0x85bf312c` | +| `setChainMaxFees` | `0x7a3c3970` | | `setFeesPlug` | `0xd6a9a8b7` | | `setFeesPool` | `0xd6684588` | +| `setMaxFees` | `0xd865104d` | +| `symbol` | `0x95d89b41` | | `tokenOnChainBalances` | `0x3b27866d` | -| `transferFrom` | `0xf1686c89` | +| `totalBalanceOf` | `0x4b0ee02a` | +| `totalSupply` | `0x18160ddd` | +| `transfer` | `0xa9059cbb` | +| `transferFrom` | `0x23b872dd` | | `transferOwnership` | `0xf2fde38b` | | `unblockAndAssignCredits` | `0x01958181` | | `unblockCredits` | `0xa0b32314` | | `unwrap` | `0x7647691d` | -| `userCredits` | `0x20babb92` | +| `userBlockedCredits` | `0x17fa5fb9` | | `watcher__` | `0x300bb063` | | `withdrawCredits` | `0xcfc6dbd9` | | `wrap` | `0x023276f0` | @@ -361,6 +381,36 @@ | `socket__` | `0xc6a261d2` | | `transferOwnership` | `0xf2fde38b` | +## FeesPlug + +| Function | Signature | +| ---------------------------- | ------------ | +| `appGatewayId` | `0x1c335f49` | +| `cancelOwnershipHandover` | `0x54d1f13d` | +| `completeOwnershipHandover` | `0xf04e283e` | +| `connectSocket` | `0x943103c3` | +| `depositCredit` | `0x34d83f58` | +| `depositCreditAndNative` | `0x9d55f674` | +| `depositToNative` | `0xe2665889` | +| `disconnectSocket` | `0xe90e5cc1` | +| `grantRole` | `0x2f2ff15d` | +| `hasRole` | `0x91d14854` | +| `initSocket` | `0x18b7ff72` | +| `isSocketInitialized` | `0x9a7d9a9b` | +| `overrides` | `0x4a85f041` | +| `owner` | `0x8da5cb5b` | +| `ownershipHandoverExpiresAt` | `0xfee81cf4` | +| `removeTokenFromWhitelist` | `0x306275be` | +| `renounceOwnership` | `0x715018a6` | +| `requestOwnershipHandover` | `0x25692962` | +| `rescueFunds` | `0x6ccae054` | +| `revokeRole` | `0xd547741f` | +| `socket__` | `0xc6a261d2` | +| `transferOwnership` | `0xf2fde38b` | +| `whitelistToken` | `0x6247f6f2` | +| `whitelistedTokens` | `0xdaf9c210` | +| `withdrawFees` | `0xe55dc4e6` | + ## Configurations | Function | Signature | @@ -389,6 +439,7 @@ | Function | Signature | | ----------------- | ------------ | +| `initialize` | `0xc4d66de8` | | `markRevert` | `0x56501015` | | `rescueFunds` | `0x6ccae054` | | `resolvePromises` | `0xbf8484b8` | @@ -467,6 +518,7 @@ | `requestHandler__` | `0x55184561` | | `requestOwnershipHandover` | `0x25692962` | | `rescueFunds` | `0xa58c6fc5` | +| `resetIsAppGatewayCalled` | `0xd19cd269` | | `setCoreContracts` | `0xefa891c4` | | `setIsValidPlug` | `0x06c0a40a` | | `setTriggerFees` | `0xaeb30511` | diff --git a/contracts/evmx/base/AppGatewayBase.sol b/contracts/evmx/base/AppGatewayBase.sol index 2a931237..58040306 100644 --- a/contracts/evmx/base/AppGatewayBase.sol +++ b/contracts/evmx/base/AppGatewayBase.sol @@ -5,6 +5,7 @@ import "../helpers/AddressResolverUtil.sol"; import "../interfaces/IAppGateway.sol"; import "../interfaces/IForwarder.sol"; import "../interfaces/IPromise.sol"; +import "../interfaces/IERC20.sol"; import {InvalidPromise, AsyncModifierNotSet} from "../../utils/common/Errors.sol"; import {FAST, READ, WRITE, SCHEDULE} from "../../utils/common/Constants.sol"; @@ -242,7 +243,7 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway { uint256 amount_, address receiver_ ) internal { - feesManager__().approve(address(feesManager__()), true); + IERC20(address(feesManager__())).approve(address(feesManager__()), type(uint256).max); feesManager__().withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); } diff --git a/contracts/evmx/fees/Credit.sol b/contracts/evmx/fees/Credit.sol index c9234141..44272045 100644 --- a/contracts/evmx/fees/Credit.sol +++ b/contracts/evmx/fees/Credit.sol @@ -19,10 +19,6 @@ import "../../utils/RescueFundsLib.sol"; import "../base/AppGatewayBase.sol"; import {toBytes32Format} from "../../utils/common/Converters.sol"; -interface ISUSDCPlug { - function mint(address receiver_, uint256 amount_) external; -} - abstract contract FeesManagerStorage is IFeesManager { // slots [0-49] reserved for gap uint256[50] _gap_before; @@ -69,12 +65,12 @@ abstract contract FeesManagerStorage is IFeesManager { // slot 58 /// @notice Mapping to track token for each chain slug /// @dev chainSlug => token address - bytes32 public susdcToken; + bytes32 public deprecated4; // slot 59 /// @notice Mapping to track whitelisted receivers /// @dev receiver address => bool - mapping(address => bool) public whitelistedReceivers; + mapping(address => bool) public deprecated3; /// @notice Mapping to track max fees per chain slug /// @dev chainSlug => max fees @@ -119,12 +115,6 @@ abstract contract Credit is FeesManagerStorage, Initializable, Ownable, AppGatew /// @notice Emitted when withdraw fails event WithdrawFailed(bytes32 indexed payloadId); - /// @notice Emitted when susdc token is set - event SusdcTokenSet(uint32 indexed chainSlug, bytes32 indexed susdcToken); - - /// @notice Emitted when whitelisted receiver is set - event WhitelistedReceiverSet(address indexed receiver, bool isWhitelisted); - function setFeesPlug(uint32 chainSlug_, bytes32 feesPlug_) external onlyOwner { feesPlugs[chainSlug_] = feesPlug_; emit FeesPlugSet(chainSlug_, feesPlug_); @@ -135,20 +125,6 @@ abstract contract Credit is FeesManagerStorage, Initializable, Ownable, AppGatew emit FeesPoolSet(feesPool_); } - function setSusdcToken(uint32 chainSlug_, bytes32 susdcToken_) external onlyOwner { - forwarderAddresses[susdcToken][chainSlug_] = asyncDeployer__().getOrDeployForwarderContract( - susdcToken_, - chainSlug_ - ); - _setValidPlug(true, chainSlug_, susdcToken); - emit SusdcTokenSet(chainSlug_, susdcToken_); - } - - function setWhitelistedReceiver(address receiver_, bool isWhitelisted_) external onlyOwner { - whitelistedReceivers[receiver_] = isWhitelisted_; - emit WhitelistedReceiverSet(receiver_, isWhitelisted_); - } - function getMaxFees(uint32 chainSlug_) public view returns (uint256) { return maxFeesPerChainSlug[chainSlug_] == 0 @@ -171,10 +147,8 @@ abstract contract Credit is FeesManagerStorage, Initializable, Ownable, AppGatew address token_, address depositTo_, uint256 nativeAmount_, - uint256 creditAmount_, - bytes memory data_ + uint256 creditAmount_ ) external override onlyWatcher { - if (!whitelistedReceivers[depositTo_]) revert InvalidReceiver(); tokenOnChainBalances[chainSlug_][token_] += creditAmount_ + nativeAmount_; // Mint tokens to the user @@ -191,15 +165,6 @@ abstract contract Credit is FeesManagerStorage, Initializable, Ownable, AppGatew } } - if (data_.length > 0) - IReceiver(depositTo_).onTransfer( - chainSlug_, - token_, - creditAmount_, - nativeAmount_, - data_ - ); - emit Deposited(chainSlug_, token_, depositTo_, creditAmount_, nativeAmount_); } @@ -227,23 +192,6 @@ abstract contract Credit is FeesManagerStorage, Initializable, Ownable, AppGatew emit CreditsUnwrapped(receiver_, amount_); } - function mint(address to, uint256 amount, bytes memory data_) external onlyWatcher { - _mintWithData(to, amount, data_); - } - - function _mintWithData(address to, uint256 amount, bytes memory data_) internal { - _mint(to, amount); - if (data_.length > 0) { - IReceiver(to).onTransfer(evmxSlug, address(this), amount, 0, data_); - } - } - - function burn(uint32 chainSlug_, address receiver_, uint256 amount_) external async { - _setMaxFees(getMaxFees(chainSlug_)); - _burn(msg.sender, amount_); - ISUSDCPlug(forwarderAddresses[susdcToken][chainSlug_]).mint(receiver_, amount_); - } - /// @notice Override balanceOf to return available (unblocked) credits function balanceOf(address account) public view override returns (uint256) { return super.balanceOf(account) - userBlockedCredits[account]; @@ -297,26 +245,15 @@ abstract contract Credit is FeesManagerStorage, Initializable, Ownable, AppGatew return super.transferFrom(from_, to_, amount_); } - /// @notice Approves app gateway for the caller - /// @param appGateway_ app gateway address - /// @param approval_ approval - function approve(address appGateway_, bool approval_) external override { - _approve(msg.sender, appGateway_, approval_ ? type(uint256).max : 0); - } - function approve(address spender, uint256 amount) public override returns (bool) { - return super.approve(spender, amount > 0 ? type(uint256).max : 0); + return super.approve(spender, amount); } /// @notice Approves multiple app gateways for the caller /// @param params_ Array of app gateway addresses to approve function batchApprove(AppGatewayApprovals[] calldata params_) external override { for (uint256 i = 0; i < params_.length; i++) { - _approve( - msg.sender, - params_[i].appGateway, - params_[i].approval ? type(uint256).max : 0 - ); + _approve(msg.sender, params_[i].appGateway, params_[i].approval); } } @@ -328,19 +265,19 @@ abstract contract Credit is FeesManagerStorage, Initializable, Ownable, AppGatew /// @return approval The approval status function approveWithSignature( bytes memory feeApprovalData_ - ) external returns (address consumeFrom, address spender, bool approval) { + ) external returns (address consumeFrom, address spender, uint256 approval) { uint256 nonce; bytes memory signature_; (spender, approval, nonce, signature_) = abi.decode( feeApprovalData_, - (address, bool, uint256, bytes) + (address, uint256, uint256, bytes) ); bytes32 digest = keccak256(abi.encode(address(this), evmxSlug, spender, nonce, approval)); consumeFrom = _recoverSigner(digest, signature_); if (isNonceUsed[consumeFrom][nonce]) revert NonceUsed(); isNonceUsed[consumeFrom][nonce] = true; - _approve(consumeFrom, spender, approval ? type(uint256).max : 0); + _approve(consumeFrom, spender, approval); return (consumeFrom, spender, approval); } @@ -422,11 +359,11 @@ abstract contract Credit is FeesManagerStorage, Initializable, Ownable, AppGatew // ERC20 metadata function name() public pure override returns (string memory) { - return "Socket USDC"; + return "Socket Credits"; } function symbol() public pure override returns (string memory) { - return "sUSDC"; + return "credits"; } function decimals() public pure override returns (uint8) { diff --git a/contracts/evmx/fees/FeesManager.sol b/contracts/evmx/fees/FeesManager.sol index 8b26e810..a4330222 100644 --- a/contracts/evmx/fees/FeesManager.sol +++ b/contracts/evmx/fees/FeesManager.sol @@ -58,10 +58,9 @@ contract FeesManager is Credit { evmxSlug = evmxSlug_; sbType = sbType_; feesPool = IFeesPool(feesPool_); - susdcToken = _createContractId("susdc token"); maxFeesPerChainSlug[evmxSlug_] = fees_; - _setMaxFees(fees_); + _setMaxFees(fees_); _initializeOwner(owner_); _initializeAppGateway(addressResolver_); } diff --git a/contracts/evmx/helpers/AsyncPromise.sol b/contracts/evmx/helpers/AsyncPromise.sol index f727947d..012b9a4e 100644 --- a/contracts/evmx/helpers/AsyncPromise.sol +++ b/contracts/evmx/helpers/AsyncPromise.sol @@ -38,8 +38,16 @@ abstract contract AsyncPromiseStorage is IPromise { /// @notice The callback data to be used when the promise is resolved. bytes public callbackData; - // slots [53-102] reserved for gap - uint256[50] _gap_after; + // slot 53 + /// @notice The revert handler selector of the promise + bytes4 public revertHandlerSelector; + + // slot 54 + /// @notice The revert handler data of the promise + bytes public revertHandlerData; + + // slots [55-102] reserved for gap + uint256[48] _gap_after; // slots 103-154 (51) reserved for addr resolver util } @@ -133,7 +141,14 @@ contract AsyncPromise is AsyncPromiseStorage, Initializable, AddressResolverUtil /// @dev Only callable by the watcher. /// @dev handleRevert function can be retried till it succeeds function _handleRevert(bytes32 payloadId_) internal { - try IAppGateway(localInvoker).handleRevert(payloadId_) {} catch { + bytes memory combinedCalldata = abi.encodePacked( + revertHandlerSelector, + abi.encode(revertHandlerData, payloadId_) + ); + + (bool success, , ) = localInvoker.tryCall(0, gasleft(), 0, combinedCalldata); + + if (!success) { // todo: in this case, promise will stay unresolved revert PromiseRevertFailed(); } @@ -143,20 +158,31 @@ contract AsyncPromise is AsyncPromiseStorage, Initializable, AddressResolverUtil /// @param selector_ The function selector for the callback. /// @param data_ The data to be passed to the callback. function then(bytes4 selector_, bytes memory data_) external override { - if (msg.sender != localInvoker) revert NotInvoker(); // if the promise is already set up, revert if (state != AsyncPromiseState.WAITING_FOR_CALLBACK_SELECTOR) { revert PromiseAlreadySetUp(); } - if (watcher__().latestAsyncPromise() != address(this)) revert NotLatestPromise(); - if (requestCount != watcher__().getCurrentRequestCount()) revert RequestCountMismatch(); - + _validate(); // if the promise is waiting for the callback selector, set it and update the state callbackSelector = selector_; callbackData = data_; state = AsyncPromiseState.WAITING_FOR_CALLBACK_EXECUTION; } + function error(bytes4 selector_, bytes memory data_) external override { + _validate(); + // if the promise is waiting for the callback selector, set it and update the state + revertHandlerSelector = selector_; + revertHandlerData = data_; + state = AsyncPromiseState.WAITING_FOR_CALLBACK_EXECUTION; + } + + function _validate() internal { + if (msg.sender != localInvoker) revert NotInvoker(); + if (watcher__().latestAsyncPromise() != address(this)) revert NotLatestPromise(); + if (requestCount != watcher__().getCurrentRequestCount()) revert RequestCountMismatch(); + } + /** * @notice Rescues funds from the contract if they are locked by mistake. This contract does not * theoretically need this function but it is added for safety. diff --git a/contracts/evmx/interfaces/IFeesManager.sol b/contracts/evmx/interfaces/IFeesManager.sol index 01555b26..e3074765 100644 --- a/contracts/evmx/interfaces/IFeesManager.sol +++ b/contracts/evmx/interfaces/IFeesManager.sol @@ -8,8 +8,7 @@ interface IFeesManager { address token_, address depositTo_, uint256 nativeAmount_, - uint256 creditAmount_, - bytes memory data_ + uint256 creditAmount_ ) external; function wrap(address receiver_) external payable; @@ -22,13 +21,11 @@ interface IFeesManager { uint256 amount_ ) external view returns (bool); - function approve(address appGateway_, bool approval_) external; - function batchApprove(AppGatewayApprovals[] calldata params_) external; function approveWithSignature( bytes memory feeApprovalData_ - ) external returns (address consumeFrom, address spender, bool approval); + ) external returns (address consumeFrom, address spender, uint256 approval); function withdrawCredits( uint32 chainSlug_, @@ -46,9 +43,5 @@ interface IFeesManager { function isApproved(address appGateway_, address user_) external view returns (bool); - function burn(uint32 chainSlug_, address receiver_, uint256 amount_) external; - - function mint(address to, uint256 amount, bytes memory data_) external; - function setMaxFees(uint256 fees_) external; } diff --git a/contracts/evmx/interfaces/IFeesPlug.sol b/contracts/evmx/interfaces/IFeesPlug.sol index 85cf0c25..24cc719a 100644 --- a/contracts/evmx/interfaces/IFeesPlug.sol +++ b/contracts/evmx/interfaces/IFeesPlug.sol @@ -7,8 +7,7 @@ interface IFeesPlug { address token, address receiver, uint256 creditAmount, - uint256 nativeAmount, - bytes data + uint256 nativeAmount ); /// @notice Event emitted when fees are withdrawn event FeesWithdrawn(address token, address receiver, uint256 amount); @@ -17,26 +16,11 @@ interface IFeesPlug { /// @notice Event emitted when a token is removed from whitelist event TokenRemovedFromWhitelist(address token); - function depositCredit( - address token_, - address receiver_, - uint256 amount_, - bytes memory data_ - ) external; + function depositCredit(address token_, address receiver_, uint256 amount_) external; - function depositCreditAndNative( - address token_, - address receiver_, - uint256 amount_, - bytes memory data_ - ) external; + function depositCreditAndNative(address token_, address receiver_, uint256 amount_) external; - function depositToNative( - address token_, - address receiver_, - uint256 amount_, - bytes memory data_ - ) external; + function depositToNative(address token_, address receiver_, uint256 amount_) external; function withdrawFees(address token_, address receiver_, uint256 amount_) external; } diff --git a/contracts/evmx/interfaces/IPromise.sol b/contracts/evmx/interfaces/IPromise.sol index f323ae69..c898e16e 100644 --- a/contracts/evmx/interfaces/IPromise.sol +++ b/contracts/evmx/interfaces/IPromise.sol @@ -32,6 +32,11 @@ interface IPromise { /// @param data_ The data to be passed to the callback. function then(bytes4 selector_, bytes memory data_) external; + /// @notice Sets the revert handler selector and data for the promise. + /// @param selector_ The function selector for the revert handler. + /// @param data_ The data to be passed to the revert handler. + function error(bytes4 selector_, bytes memory data_) external; + /// @notice Marks the promise as resolved and executes the callback if set. /// @dev Only callable by the watcher precompile. /// @param resolvedPromise_ The data returned from the async payload execution. diff --git a/contracts/evmx/interfaces/ISUSDC.sol b/contracts/evmx/interfaces/ISUSDC.sol deleted file mode 100644 index 985dedbc..00000000 --- a/contracts/evmx/interfaces/ISUSDC.sol +++ /dev/null @@ -1,8 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -pragma solidity ^0.8.21; - -interface ISUSDC { - function mint(address to, uint256 amount) external; - - function burn(address receiver_, uint256 amount, bytes memory data_) external; -} diff --git a/contracts/evmx/plugs/FeesPlug.sol b/contracts/evmx/plugs/FeesPlug.sol index b46baab1..8320db52 100644 --- a/contracts/evmx/plugs/FeesPlug.sol +++ b/contracts/evmx/plugs/FeesPlug.sol @@ -38,32 +38,21 @@ contract FeesPlug is IFeesPlug, PlugBase, AccessControl { } /////////////////////// DEPOSIT AND WITHDRAWAL /////////////////////// - function depositCredit( - address token_, - address receiver_, - uint256 amount_, - bytes memory data_ - ) external override { - _deposit(token_, receiver_, amount_, 0, data_); + function depositCredit(address token_, address receiver_, uint256 amount_) external override { + _deposit(token_, receiver_, amount_, 0); } function depositCreditAndNative( address token_, address receiver_, - uint256 amount_, - bytes memory data_ + uint256 amount_ ) external override { uint256 nativeAmount_ = amount_ / 10; - _deposit(token_, receiver_, amount_ - nativeAmount_, nativeAmount_, data_); + _deposit(token_, receiver_, amount_ - nativeAmount_, nativeAmount_); } - function depositToNative( - address token_, - address receiver_, - uint256 amount_, - bytes memory data_ - ) external override { - _deposit(token_, receiver_, 0, amount_, data_); + function depositToNative(address token_, address receiver_, uint256 amount_) external override { + _deposit(token_, receiver_, 0, amount_); } /// @notice Deposits funds @@ -75,12 +64,11 @@ contract FeesPlug is IFeesPlug, PlugBase, AccessControl { address token_, address receiver_, uint256 creditAmount_, - uint256 nativeAmount_, - bytes memory data_ + uint256 nativeAmount_ ) internal { if (!whitelistedTokens[token_]) revert TokenNotWhitelisted(token_); token_.safeTransferFrom(msg.sender, address(this), creditAmount_ + nativeAmount_); - emit FeesDeposited(token_, receiver_, creditAmount_, nativeAmount_, data_); + emit FeesDeposited(token_, receiver_, creditAmount_, nativeAmount_); } /// @notice Withdraws fees diff --git a/contracts/evmx/plugs/SUSDC.sol b/contracts/evmx/plugs/SUSDC.sol deleted file mode 100644 index 7272d775..00000000 --- a/contracts/evmx/plugs/SUSDC.sol +++ /dev/null @@ -1,136 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -import "solady/tokens/ERC20.sol"; -import "../../utils/AccessControl.sol"; -import "../../utils/RescueFundsLib.sol"; - -import "../../protocol/base/PlugBase.sol"; -import {RESCUE_ROLE} from "../../utils/common/AccessRoles.sol"; - -import "../interfaces/IFeesManager.sol"; - -/// @title AdvancedToken -/// @notice An advanced ERC20 token with minting, burning, and pausing capabilities -/// @author Your Name -contract SUSDC is ERC20, AccessControl, PlugBase { - /// @notice The name of the token - string private _name; - - /// @notice The symbol of the token - string private _symbol; - - /// @notice The number of decimals for the token - uint8 private _decimals; - - /// @notice Emitted when tokens are minted - event TokensMinted(address indexed to, uint256 amount); - - /// @notice Emitted when tokens are burned - event TokensBurned(address indexed from, address indexed to, uint256 amount, bytes data); - - /// @notice Constructor that sets token metadata and mints initial supply - /// @param initialOwner The address to receive the initial supply and ownership - /// @param tokenName The name of the token - /// @param tokenSymbol The symbol of the token - /// @param tokenDecimals The number of decimals for the token - constructor( - uint8 tokenDecimals, - address initialOwner, - address socket, - string memory tokenName, - string memory tokenSymbol - ) { - isSocketInitialized = 1; - _decimals = tokenDecimals; - _name = tokenName; - _symbol = tokenSymbol; - - _setSocket(socket); - _initializeOwner(initialOwner); - } - - /// @notice Returns the name of the token - /// @return The name of the token - function name() public view override returns (string memory) { - return _name; - } - - /// @notice Returns the symbol of the token - /// @return The symbol of the token - function symbol() public view override returns (string memory) { - return _symbol; - } - - /// @notice Returns the number of decimals used to get its user representation - /// @return The number of decimals - function decimals() public view override returns (uint8) { - return _decimals; - } - - /// @notice Mints new tokens (only owner) - /// @param to The address to mint tokens to - /// @param amount The amount of tokens to mint - function mint(address to, uint256 amount) external onlySocket { - require(to != address(0), "Cannot mint to zero address"); - require(amount > 0, "Amount must be greater than 0"); - - _mint(to, amount); - emit TokensMinted(to, amount); - } - - /// @notice Burns tokens from the caller's balance - /// @param amount The amount of tokens to burn - function burn(address receiver_, uint256 amount, bytes memory data_) external { - require(amount > 0, "Amount must be greater than 0"); - require(balanceOf(msg.sender) >= amount, "Insufficient balance"); - - _burn(msg.sender, amount); - IFeesManager(address(socket__)).mint(receiver_, amount, data_); - emit TokensBurned(msg.sender, receiver_, amount, data_); - } - - /// @notice Override transfer function to check for paused state - /// @param to The address to transfer tokens to - /// @param amount The amount of tokens to transfer - /// @return True if the transfer was successful - function transfer(address to, uint256 amount) public override returns (bool) { - return super.transfer(to, amount); - } - - /// @notice Override transferFrom function to check for paused state - /// @param from The address to transfer tokens from - /// @param to The address to transfer tokens to - /// @param amount The amount of tokens to transfer - /// @return True if the transfer was successful - function transferFrom(address from, address to, uint256 amount) public override returns (bool) { - return super.transferFrom(from, to, amount); - } - - function connectSocket( - bytes32 appGatewayId_, - address socket_, - uint64 switchboardId_ - ) external onlyOwner { - _connectSocket(appGatewayId_, socket_, switchboardId_); - } - - function disconnectSocket() external onlyOwner { - socket__.disconnect(); - } - - /** - * @notice Rescues funds from the contract if they are locked by mistake. This contract does not - * theoretically need this function but it is added for safety. - * @param token_ The address of the token contract. - * @param rescueTo_ The address where rescued tokens need to be sent. - * @param amount_ The amount of tokens to be rescued. - */ - function rescueFunds( - address token_, - address rescueTo_, - uint256 amount_ - ) external onlyRole(RESCUE_ROLE) { - RescueFundsLib._rescueFunds(token_, rescueTo_, amount_); - } -} diff --git a/contracts/evmx/watcher/PromiseResolver.sol b/contracts/evmx/watcher/PromiseResolver.sol index 7f014671..796054ea 100644 --- a/contracts/evmx/watcher/PromiseResolver.sol +++ b/contracts/evmx/watcher/PromiseResolver.sol @@ -90,7 +90,7 @@ contract PromiseResolver is IPromiseResolver, WatcherBase, Initializable { // Get payload params from Watcher bytes32 payloadId = resolvedPromise_.payloadId; PayloadParams memory payloadParams = watcher__.getPayloadParams(payloadId); - // if (payloadParams.deadline > block.timestamp) revert DeadlineNotPassedForOnChainRevert(); + if (payloadParams.deadline > block.timestamp) revert DeadlineNotPassedForOnChainRevert(); // marks the request as cancelled and settles the fees requestHandler__().cancelRequestForReverts(uint40(payloadParams.payloadPointer >> 120)); diff --git a/contracts/evmx/watcher/RequestHandler.sol b/contracts/evmx/watcher/RequestHandler.sol index a5d793e0..bde650c7 100644 --- a/contracts/evmx/watcher/RequestHandler.sol +++ b/contracts/evmx/watcher/RequestHandler.sol @@ -197,8 +197,8 @@ contract RequestHandler is RequestHandlerStorage, Initializable, Ownable, Addres // todo: remove after game // also this overrides a payload deadline hence an unexecuted payload can // be executed by new added transmitters. need to fix this by marking req deadline or something. - // if (r.requestFeesDetails.winningBid.transmitter == bid_.transmitter) - // revert AlreadyAssigned(); + if (r.requestFeesDetails.winningBid.transmitter == bid_.transmitter) + revert AlreadyAssigned(); // If a transmitter was already assigned previously, unblock the credits if (r.requestFeesDetails.winningBid.transmitter != address(0)) { diff --git a/contracts/evmx/watcher/Trigger.sol b/contracts/evmx/watcher/Trigger.sol index 181c2367..55d92cc6 100644 --- a/contracts/evmx/watcher/Trigger.sol +++ b/contracts/evmx/watcher/Trigger.sol @@ -55,9 +55,4 @@ abstract contract Trigger is WatcherStorage, AddressResolverUtil { triggerFromChainSlug = 0; triggerFromPlug = bytes32(0); } - - // todo: add onlyWatcher modifier - function resetIsAppGatewayCalled(bytes32 triggerId_) external { - isAppGatewayCalled[triggerId_] = false; - } } diff --git a/contracts/utils/common/Structs.sol b/contracts/utils/common/Structs.sol index 4503068d..2636db28 100644 --- a/contracts/utils/common/Structs.sol +++ b/contracts/utils/common/Structs.sol @@ -46,7 +46,7 @@ enum ExecutionStatus { struct AppGatewayApprovals { address appGateway; - bool approval; + uint256 approval; } //// STRUCTS //// diff --git a/foundry.toml b/foundry.toml index 9ac8bc70..c21573c5 100644 --- a/foundry.toml +++ b/foundry.toml @@ -10,27 +10,28 @@ evm_version = 'paris' via_ir = false [labels] -0xcA99D298B5290558660b4D5C1019Be145FaB6020 = "AddressResolver" -0x39b5D3FBBa1BC28438e25955aaB412C7576eCd61 = "AddressResolverImpl" -0xd608e1345281dE0675e2Cc1E8D0B31aD167618Ad = "AsyncDeployer" -0x2F0E83Fcd03A191D280598c33d278AF8A7e9076a = "AsyncDeployerImpl" -0xED848E9e0CCA0868484353B529E04861Fd8F04Bd = "AuctionManager" -0x2752caa4060bC744216515c247C54Ae5bB873DF2 = "AuctionManagerImpl" -0xf50A9785aef5ADeA0659609e9FF1de8578aF0b4f = "Configurations" -0xa1780f9F81090737267ccd3A5663E058AfE73A49 = "ConfigurationsImpl" -0xffF606007317cb7a1CC4C701d62C38c7734dfb15 = "DeployForwarder" -0x69e3Dc5667f7413039fE3bFd335660A99DA869A9 = "DeployForwarderImpl" -0x4f1Cd0CdBc7EA445b8B34Af8844fA4D4B5f48b79 = "ERC1967Factory" -0xbCFf8224d89f0b4e9B14c4356720439111BAC2bC = "FeesManager" -0x5E0dF9484D5ACd94028459fA7E90F4c3280147CA = "FeesManagerImpl" -0x13A3018920c7b56B20dd34E29C298121025E6de4 = "FeesPool" -0xed318668898303141EA6B9c2a9F97D0622b0a530 = "PromiseResolver" -0x7C82C3d2aE1bFB4b1D294e5181bCd7489EF554d1 = "ReadPrecompile" -0xf053AB14323FF52e7e65D6Fb12f86896F0865a36 = "RequestHandler" -0x751085cA028D2BCfC58Cee2514DeF1ed72c843cd = "RequestHandlerImpl" -0x4660c5fF2762E688f8D0def828ad161AE4940F57 = "SchedulePrecompile" -0xCeEc354B7784C667Bd661483Ae30C8d4eBA96e1d = "Watcher" -0x2996bD0DCB7C349340715472518E76342AC31b1a = "WatcherImpl" -0x9a580f1A4AE6A37CCEe73261B796F85EFbE55B15 = "WritePrecompile" -0xd50ca68c3d0f8341CC19B7eFE7e564971ba52A1D = "WritePrecompileImpl" -0x075A9bD30ce5E0Bb08994774bD55Afcadd96950A = "APP_GATEWAY" +0x3d6EB76db49BF4b9aAf01DBB79fCEC2Ee71e44e2 = "AddressResolver" +0xe37aFa3Aa95E153B8dD0FE8456CBF345cB4C51F7 = "AddressResolverImpl" +0xFA19dDA03A79f8Aef83C0505BF70ECa0Ac42608E = "AsyncDeployer" +0xb3A5132Df72F1597ab474d73d387ecF8647af669 = "AsyncDeployerImpl" +0xe2B1A11E8473095581DEF8d9D11eC63BBdd62ceE = "AsyncPromiseImpl" +0xcd5e9029a73890A5A3146bAddd272D65ac11521c = "AuctionManager" +0xB604FBcA01897315D2d62A346DBf29796A4825D9 = "AuctionManagerImpl" +0x71B89bA78B9431d4E984893cD6885d39AD6c3c7A = "Configurations" +0x117c63A8c9a980ddC60B2bF2b4701C9267f66394 = "ConfigurationsImpl" +0xb6E6e6FCd2636B83C443628f3f5e42cB5Fcd44fD = "DeployForwarder" +0xf05f680E0611b81eD0255A1Cd829540504765711 = "DeployForwarderImpl" +0x4023941D9AB563b1c4d447B3f2A9dd2F1eF19fCA = "ERC1967Factory" +0xB63ab15c208A16a0480036C06e8828A4682E0B34 = "FeesManager" +0x9f3CDba2262DF94e415E092A4228ee7E6846ea1b = "FeesManagerImpl" +0x3B1f4ABA1667EeB992B623E7c6d119728cEd3b15 = "FeesPool" +0xB1a504eC5C2d8206Fc73a46EeF5E5018585Eb240 = "ForwarderImpl" +0xFB349dcc5A1cB87Ff3A2b91C343814647AE820FC = "PromiseResolver" +0x74D52027137a450b68315478AAE4528Ba839ea13 = "ReadPrecompile" +0x3C183Ad26A11A6691d43D031Fae3D51DaDC643Df = "RequestHandler" +0x0303B6f54afA36B0808FDE6aaE9c3eD271b01119 = "RequestHandlerImpl" +0xEE7b72D53FeC4Bed9F56CcEaD49217d152A22aC5 = "SchedulePrecompile" +0x2566Bef2e914c7482d6FCB4955403fb0865951A5 = "Watcher" +0x03029500B038980745c5a671f271340CF9AF5830 = "WatcherImpl" +0xc6506b1C3f34297B4de32f08d8d50CB0E9e64842 = "WritePrecompile" +0xcd460687fe2a74ddEE8f2E3d791e1df306713353 = "WritePrecompileImpl" diff --git a/hardhat-scripts/deploy/1.deploy.ts b/hardhat-scripts/deploy/1.deploy.ts index fa763226..734c8c23 100644 --- a/hardhat-scripts/deploy/1.deploy.ts +++ b/hardhat-scripts/deploy/1.deploy.ts @@ -382,16 +382,6 @@ const deploySocketContracts = async () => { ); deployUtils.addresses[contractName] = feesPlug.address; - contractName = Contracts.SUSDC; - const susdcPlug: Contract = await getOrDeploy( - contractName, - contractName, - `contracts/evmx/plugs/${contractName}.sol`, - [18, socketOwner, socket.address, "SUSDC", "SUSDC"], - deployUtils - ); - deployUtils.addresses[contractName] = susdcPlug.address; - contractName = Contracts.ContractFactoryPlug; const contractFactoryPlug: Contract = await getOrDeploy( contractName, diff --git a/hardhat-scripts/deploy/3.configureChains.ts b/hardhat-scripts/deploy/3.configureChains.ts index 7c6a65de..8effd77d 100644 --- a/hardhat-scripts/deploy/3.configureChains.ts +++ b/hardhat-scripts/deploy/3.configureChains.ts @@ -116,13 +116,6 @@ export const configureChains = async (addresses: DeploymentAddresses) => { // await setSiblingConfig(chain, addresses, signer); - if (chainAddresses[Contracts.SUSDC]) - await setSUSDCToken( - chain, - addresses[EVMX_CHAIN_ID]?.[Contracts.FeesManager]!, - chainAddresses[Contracts.SUSDC] - ); - await storeAddresses(deployUtils.addresses, chain, mode); } }; @@ -436,50 +429,6 @@ export const whitelistToken = async ( } }; -export const setSUSDCToken = async ( - chain: number, - feesManagerAddress: string, - susdcAddress: string -) => { - let contractInstance = await getInstance( - Contracts.FeesManager, - feesManagerAddress - ); - contractInstance = await contractInstance.connect(getWatcherSigner()); - - const susdcToken = contractInstance.susdcToken(); - const forwarderAddress = await contractInstance.forwarderAddresses( - susdcToken, - chain - ); - - if (forwarderAddress != constants.AddressZero) { - const forwarderABI = [ - "function getOnChainAddress() external view returns (bytes32)", - ]; - const forwarderContract = new ethers.Contract( - forwarderAddress, - forwarderABI, - getWatcherSigner() - ); - const onChainAddress = await forwarderContract.getOnChainAddress(); - - if ( - onChainAddress.toLowerCase() == - toBytes32FormatHexString(susdcAddress).toLowerCase() - ) { - console.log(`SUSDC token is already set to ${susdcAddress}`); - return; - } - } - const tx = await contractInstance.setSusdcToken( - chain, - toBytes32FormatHexString(susdcAddress) - ); - console.log(`Setting SUSDC token to ${susdcAddress}, txHash: ${tx.hash}`); - await tx.wait(); -}; - main() .then(() => process.exit(0)) .catch((error: Error) => { diff --git a/hardhat-scripts/deploy/6.connect.ts b/hardhat-scripts/deploy/6.connect.ts index 460b4b6f..a0f09b7c 100644 --- a/hardhat-scripts/deploy/6.connect.ts +++ b/hardhat-scripts/deploy/6.connect.ts @@ -15,11 +15,7 @@ import { getWatcherSigner, sendWatcherMultiCallWithNonce } from "../utils/sign"; import { isConfigSetOnEVMx, isConfigSetOnSocket } from "../utils"; import pLimit from "p-limit"; -const plugs = [ - Contracts.ContractFactoryPlug, - Contracts.FeesPlug, - Contracts.SUSDC, -]; +const plugs = [Contracts.ContractFactoryPlug, Contracts.FeesPlug]; // Main function to connect plugs on all chains export const main = async () => { diff --git a/hardhat-scripts/deploy/deployTestUSDC.ts b/hardhat-scripts/deploy/deployTestUSDC.ts index b4348718..7d007046 100644 --- a/hardhat-scripts/deploy/deployTestUSDC.ts +++ b/hardhat-scripts/deploy/deployTestUSDC.ts @@ -14,6 +14,7 @@ import { deployContractWithArgs } from "../utils"; import { getSocketSigner, getWatcherSigner } from "../utils/sign"; import { tokens } from "../constants/feeConstants"; +// npx hardhat run hardhat - scripts / deploy / deployTestUSDC.ts--no - compile const main = async () => { logConfig(); await logBalances(); diff --git a/hardhat-scripts/utils/gatewayId.ts b/hardhat-scripts/utils/gatewayId.ts index fcc4c3d7..a24fc02d 100644 --- a/hardhat-scripts/utils/gatewayId.ts +++ b/hardhat-scripts/utils/gatewayId.ts @@ -14,7 +14,6 @@ export const getAppGatewayId = ( if (!address) throw new Error(`WritePrecompile not found on EVMX`); return ethers.utils.hexZeroPad(address, 32); case Contracts.FeesPlug: - case Contracts.SUSDC: address = addresses?.[EVMX_CHAIN_ID]?.[Contracts.FeesManager]; if (!address) throw new Error(`FeesManager not found on EVMX`); return ethers.utils.hexZeroPad(address, 32); diff --git a/script/helpers/DepositCredit.s.sol b/script/helpers/DepositCredit.s.sol index 49e94fe0..b8d432f8 100644 --- a/script/helpers/DepositCredit.s.sol +++ b/script/helpers/DepositCredit.s.sol @@ -30,6 +30,6 @@ contract DepositCredit is Script { console.log("App Gateway:", appGateway); console.log("Fees Plug:", address(feesPlug)); console.log("Fees Amount:", feesAmount); - feesPlug.depositCredit(address(testUSDCContract), appGateway, feesAmount, bytes("")); + feesPlug.depositCredit(address(testUSDCContract), appGateway, feesAmount); } } diff --git a/script/helpers/DepositCreditAndNative.s.sol b/script/helpers/DepositCreditAndNative.s.sol index 47a0cf0d..629a3998 100644 --- a/script/helpers/DepositCreditAndNative.s.sol +++ b/script/helpers/DepositCreditAndNative.s.sol @@ -30,11 +30,6 @@ contract DepositCreditAndNative is Script { console.log("App Gateway:", appGateway); console.log("Fees Plug:", address(feesPlug)); console.log("Fees Amount:", feesAmount); - feesPlug.depositCreditAndNative( - address(testUSDCContract), - appGateway, - feesAmount, - bytes("") - ); + feesPlug.depositCreditAndNative(address(testUSDCContract), appGateway, feesAmount); } } diff --git a/script/helpers/DepositCreditMainnet.s.sol b/script/helpers/DepositCreditMainnet.s.sol index 06b58eab..4e1a8e33 100644 --- a/script/helpers/DepositCreditMainnet.s.sol +++ b/script/helpers/DepositCreditMainnet.s.sol @@ -31,6 +31,6 @@ contract DepositCredit is Script { console.log("App Gateway:", appGateway); console.log("Fees Plug:", address(feesPlug)); console.log("Fees Amount:", feesAmount); - feesPlug.depositCredit(address(USDCContract), appGateway, feesAmount, bytes("")); + feesPlug.depositCredit(address(USDCContract), appGateway, feesAmount); } } diff --git a/setupInfraContracts.sh b/setupInfraContracts.sh index 9ccfe59b..347adff5 100644 --- a/setupInfraContracts.sh +++ b/setupInfraContracts.sh @@ -17,5 +17,3 @@ time npx hardhat run hardhat-scripts/misc-scripts/functionSigs.ts --no-compile time npx ts-node hardhat-scripts/misc-scripts/createLabels.ts yarn lint time npx hardhat run hardhat-scripts/verify/verify.ts --no-compile - -time npx hardhat run hardhat-scripts/deploy/deployTestUSDC.ts --no-compile diff --git a/src/enums.ts b/src/enums.ts index ac982921..89d2aef3 100644 --- a/src/enums.ts +++ b/src/enums.ts @@ -53,7 +53,6 @@ export enum Events { export enum Contracts { Socket = "Socket", FeesPlug = "FeesPlug", - SUSDC = "SUSDC", ContractFactoryPlug = "ContractFactoryPlug", FastSwitchboard = "FastSwitchboard", FastSwitchboardId = "FastSwitchboardId", diff --git a/src/types.ts b/src/types.ts index 1a961484..87efd831 100644 --- a/src/types.ts +++ b/src/types.ts @@ -27,7 +27,6 @@ export type ChainAddressesObj = { ContractFactoryPlug: string; SocketFeesManager?: string; FeesPlug?: string; - SUSDC?: string; startBlock: number; SwitchboardIdToAddressMap: { [switchboardId: string]: string }; }; diff --git a/test/SetupTest.t.sol b/test/SetupTest.t.sol index 58d9bc21..ee4cec44 100644 --- a/test/SetupTest.t.sol +++ b/test/SetupTest.t.sol @@ -35,7 +35,6 @@ import "../contracts/evmx/fees/FeesPool.sol"; import "../contracts/evmx/plugs/FeesPlug.sol"; import "../contracts/evmx/AuctionManager.sol"; import "../contracts/evmx/mocks/TestUSDC.sol"; -import "../contracts/evmx/plugs/SUSDC.sol"; import "./mock/CCTPMessageTransmitter.sol"; @@ -89,7 +88,6 @@ contract SetupStore is Test { SocketBatcher socketBatcher; ContractFactoryPlug contractFactoryPlug; FeesPlug feesPlug; - SUSDC susdcPlug; TestUSDC testUSDC; } SocketContracts public arbConfig; @@ -156,8 +154,6 @@ contract DeploySetup is SetupStore { address(configurations), address(promiseResolver) ); - feesManager.setSusdcToken(arbChainSlug, toBytes32Format(address(arbConfig.susdcPlug))); - feesManager.setSusdcToken(optChainSlug, toBytes32Format(address(optConfig.susdcPlug))); vm.stopPrank(); @@ -202,16 +198,15 @@ contract DeploySetup is SetupStore { arbConfig.feesPlug.depositCreditAndNative( address(arbConfig.testUSDC), address(transmitterEOA), - 100 ether, - bytes("") + 100 ether ); - feesManager.approve(address(auctionManager), true); + feesManager.approve(address(auctionManager), type(uint256).max); vm.stopPrank(); } function _connectCorePlugs() internal { - AppGatewayConfig[] memory configs = new AppGatewayConfig[](6); + AppGatewayConfig[] memory configs = new AppGatewayConfig[](4); configs[0] = AppGatewayConfig({ chainSlug: arbChainSlug, plug: toBytes32Format(address(arbConfig.feesPlug)), @@ -244,22 +239,6 @@ contract DeploySetup is SetupStore { switchboardId: optConfig.switchboard.switchboardId() }) }); - configs[4] = AppGatewayConfig({ - chainSlug: optChainSlug, - plug: toBytes32Format(address(optConfig.susdcPlug)), - plugConfig: PlugConfigGeneric({ - appGatewayId: toBytes32Format(address(feesManager)), - switchboardId: optConfig.switchboard.switchboardId() - }) - }); - configs[5] = AppGatewayConfig({ - chainSlug: arbChainSlug, - plug: toBytes32Format(address(arbConfig.susdcPlug)), - plugConfig: PlugConfigGeneric({ - appGatewayId: toBytes32Format(address(feesManager)), - switchboardId: arbConfig.switchboard.switchboardId() - }) - }); watcherMultiCall( address(configurations), @@ -293,7 +272,6 @@ contract DeploySetup is SetupStore { socketBatcher: new SocketBatcher(socketOwner, socket), contractFactoryPlug: new ContractFactoryPlug(address(socket), socketOwner), feesPlug: new FeesPlug(address(socket), socketOwner), - susdcPlug: new SUSDC(18, address(socketOwner), address(socket), "susdc", "SUSDC"), testUSDC: new TestUSDC("USDC", "USDC", 6, socketOwner, 1000000000000000000000000) }); } @@ -355,14 +333,6 @@ contract DeploySetup is SetupStore { toBytes32Format(address(contractFactoryPlug)) ); vm.stopPrank(); - - uint64 sbId = socketConfig.switchboard.switchboardId(); - hoax(socketOwner); - socketConfig.susdcPlug.connectSocket( - toBytes32Format(address(feesManager)), - address(socketConfig.socket), - sbId - ); } function _deployEVMxCore() internal { @@ -603,7 +573,7 @@ contract FeesSetup is DeploySetup { uint256 native_, address user_ ) internal { - depositNativeAndCreditsWithData(chainSlug_, credits_, native_, user_, user_, bytes("")); + depositNativeAndCreditsWithData(chainSlug_, credits_, native_, user_, user_); } // mints test token and deposits the given native and credits to given `user_` @@ -612,39 +582,35 @@ contract FeesSetup is DeploySetup { uint256 credits_, uint256 native_, address user_, - address receiver_, - bytes memory data_ + address receiver_ ) internal { SocketContracts memory socketConfig = getSocketConfig(chainSlug_); TestUSDC token = socketConfig.testUSDC; - // uint256 userBalance = token.balanceOf(user_); - // uint256 feesPlugBalance = token.balanceOf(address(socketConfig.feesPlug)); + uint256 userBalance = token.balanceOf(user_); + uint256 feesPlugBalance = token.balanceOf(address(socketConfig.feesPlug)); token.mint(address(user_), 100 ether); - // assertEq( - // token.balanceOf(user_), - // userBalance + 100 ether, - // "User should have 100 more test tokens" - // ); + assertEq( + token.balanceOf(user_), + userBalance + 100 ether, + "User should have 100 more test tokens" + ); vm.startPrank(user_); token.approve(address(socketConfig.feesPlug), 100 ether); - socketConfig.feesPlug.depositCreditAndNative(address(token), user_, 100 ether, data_); + socketConfig.feesPlug.depositCreditAndNative(address(token), user_, 100 ether); vm.stopPrank(); - // assertEq( - // token.balanceOf(address(socketConfig.feesPlug)), - // feesPlugBalance + 100 ether, - // "Fees plug should have 100 more test tokens" - // ); + assertEq( + token.balanceOf(address(socketConfig.feesPlug)), + feesPlugBalance + 100 ether, + "Fees plug should have 100 more test tokens" + ); // uint256 currentCredits = feesManager.balanceOf(user_); // uint256 currentNative = address(user_).balance; - hoax(watcherEOA); - feesManager.setWhitelistedReceiver(receiver_, true); - vm.expectEmit(true, true, true, false); emit Deposited(chainSlug_, address(token), receiver_, credits_, native_); @@ -656,8 +622,7 @@ contract FeesSetup is DeploySetup { address(token), receiver_, native_, - credits_, - data_ + credits_ ) ); @@ -670,11 +635,11 @@ contract FeesSetup is DeploySetup { } function approve(address appGateway_, address user_) internal { - bool approval = feesManager.isApproved(user_, appGateway_); - if (approval) return; + uint256 approval = feesManager.allowance(user_, appGateway_); + if (approval > 0) return; hoax(user_); - feesManager.approve(appGateway_, true); + feesManager.approve(appGateway_, type(uint256).max); assertEq( feesManager.isApproved(user_, appGateway_), diff --git a/test/SocketUSDC.sol b/test/SocketUSDC.sol deleted file mode 100644 index 987d5705..00000000 --- a/test/SocketUSDC.sol +++ /dev/null @@ -1,30 +0,0 @@ -import {ERC20} from "solady/tokens/ERC20.sol"; - -contract SocketUSDC is ERC20 { - string public _name; - string public _symbol; - uint8 public _decimals; - - constructor() ERC20() { - _name = "SocketUSDC"; - _symbol = "SUSDC"; - _decimals = 18; - _mint(msg.sender, 1000000000 ether); - } - - function name() public view override returns (string memory) { - return _name; - } - - function symbol() public view override returns (string memory) { - return _symbol; - } - - function decimals() public view override returns (uint8) { - return _decimals; - } - - function mint(address to, uint256 amount) public { - _mint(to, amount); - } -} diff --git a/test/evmx/FeesTest.t.sol b/test/evmx/FeesTest.t.sol index e3286bd8..135e7a39 100644 --- a/test/evmx/FeesTest.t.sol +++ b/test/evmx/FeesTest.t.sol @@ -36,110 +36,6 @@ contract FeesTest is AppGatewayBaseSetup { counterPlug = counterGateway.forwarderAddresses(contractIds[0], feesChainSlug); } - function testDepositAndMintSusdc() public { - address counterGatewayAddress = address(counterGateway); - // deposit usdc on fees plug and mint susdc on evmx with data execution - uint256 susdcBalanceBefore = feesManager.balanceOf(counterGatewayAddress); - assertFalse(counterGateway.feesManagerSwitch(), "should be false"); - depositNativeAndCreditsWithData( - feesChainSlug, - 100 ether, - 0, - user, - counterGatewayAddress, - abi.encode(true) - ); - - assertTrue(counterGateway.feesManagerSwitch(), "Fees manager should be called"); - assertEq( - feesManager.balanceOf(counterGatewayAddress), - susdcBalanceBefore + 100 ether, - "Susdc balance should be correct" - ); - - // burn susdc on evmx and mint susdc on chain - uint256 susdcChainBalanceBefore = feesConfig.susdcPlug.balanceOf(counterPlug); - - hoax(counterGatewayAddress); - feesManager.burn(feesChainSlug, address(counterPlug), 5 ether); - executeRequest(); - - assertEq( - feesManager.balanceOf(counterGatewayAddress), - susdcBalanceBefore + 95 ether, - "Susdc balance should be correct" - ); - assertEq( - feesConfig.susdcPlug.balanceOf(counterPlug), - susdcChainBalanceBefore + 5 ether, - "Susdc balance should be correct" - ); - - // burn susdc from chain and mint on evmx - uint256 burnAmount = 2 ether; - bytes32 triggerId = _encodeTriggerId(address(feesConfig.socket), feesChainSlug); - bytes memory payload = abi.encodeWithSelector( - Credit.mint.selector, - counterGatewayAddress, - burnAmount, - abi.encode(false) - ); - - assertTrue(counterGateway.feesManagerSwitch(), "switch should be true"); - - hoax(counterPlug); - feesConfig.susdcPlug.burn(counterGatewayAddress, burnAmount, abi.encode(false)); - - TriggerParams[] memory params = new TriggerParams[](1); - params[0] = TriggerParams({ - triggerId: triggerId, - chainSlug: feesChainSlug, - appGatewayId: toBytes32Format(address(feesManager)), - plug: toBytes32Format(address(feesConfig.susdcPlug)), - payload: payload, - overrides: bytes("") - }); - bytes memory data = abi.encode(params); - - WatcherMultiCallParams memory watcherParams = WatcherMultiCallParams({ - contractAddress: address(watcher), - data: data, - nonce: watcherNonce, - signature: _createWatcherSignature(address(watcher), data) - }); - watcherNonce++; - watcher.callAppGateways(watcherParams); - - assertFalse(counterGateway.feesManagerSwitch(), "switch should be false"); - assertEq( - feesManager.balanceOf(counterGatewayAddress), - susdcBalanceBefore + 95 ether + burnAmount, - "Susdc balance should be correct" - ); - assertEq( - feesConfig.susdcPlug.balanceOf(counterPlug), - susdcChainBalanceBefore + 5 ether - burnAmount, - "Susdc balance should be correct" - ); - - // burn susdc on evmx and withdraw usdc - uint256 withdrawAmount = 1 ether; - uint256 receiverBalanceBefore = feesConfig.testUSDC.balanceOf(receiver); - withdrawCredits(counterGatewayAddress, withdrawAmount); - - uint256 withdrawAmountInTokens = withdrawAmount / 10 ** (18 - 6); - assertEq( - receiverBalanceBefore + withdrawAmountInTokens, - feesConfig.testUSDC.balanceOf(receiver), - "Receiver Balance should be correct after burn" - ); - assertEq( - feesConfig.susdcPlug.balanceOf(counterPlug), - susdcChainBalanceBefore + 5 ether - burnAmount, - "Susdc balance should be correct after burn" - ); - } - function withdrawCredits(address from, uint256 withdrawAmount) public { approve(address(feesManager), from);