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
1 change: 1 addition & 0 deletions EventTopics.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
| `OwnershipHandoverCanceled` | `(pendingOwner: address)` | `0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92` |
| `OwnershipHandoverRequested` | `(pendingOwner: address)` | `0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d` |
| `OwnershipTransferred` | `(oldOwner: address, newOwner: address)` | `0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0` |
| `WithdrawFailed` | `(payloadId: bytes32)` | `0xea147eb2109f71b4bda9e57528ba08b84821087a31cb43a7851dc6ff743d9be7` |

## FeesPool

Expand Down
2 changes: 2 additions & 0 deletions FunctionSignatures.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
| Function | Signature |
| -------------------------------- | ------------ |
| `addressResolver__` | `0x6a750469` |
| `approveAppGateway` | `0xa3b53d8b` |
| `approveAppGatewayWithSignature` | `0x94b649ec` |
| `approveAppGateways` | `0x86d23ab2` |
| `asyncDeployer__` | `0x2a39e801` |
Expand All @@ -137,6 +138,7 @@
| `feesPlugs` | `0x23f5ee8a` |
| `feesPool` | `0x6b259690` |
| `getAvailableCredits` | `0xb065a8e5` |
| `handleRevert` | `0x44792f25` |
| `initialize` | `0xbf2c8539` |
| `isApproved` | `0xa389783e` |
| `isCreditSpendable` | `0x4f8990fd` |
Expand Down
4 changes: 1 addition & 3 deletions contracts/evmx/base/AppGatewayBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,7 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway {
uint256 amount_,
address receiver_
) internal {
AppGatewayApprovals[] memory approvals = new AppGatewayApprovals[](1);
approvals[0] = AppGatewayApprovals({appGateway: address(feesManager__()), approval: true});
feesManager__().approveAppGateways(approvals);
feesManager__().approveAppGateway(address(feesManager__()), true);
feesManager__().withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_);
}

Expand Down
17 changes: 17 additions & 0 deletions contracts/evmx/fees/Credit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ abstract contract Credit is FeesManagerStorage, Initializable, Ownable, AddressR
/// @notice Emitted when fees pool is set
event FeesPoolSet(address indexed feesPool);

/// @notice Emitted when withdraw fails
event WithdrawFailed(bytes32 indexed payloadId);

function setFeesPlug(uint32 chainSlug_, address feesPlug_) external onlyOwner {
feesPlugs[chainSlug_] = feesPlug_;
emit FeesPlugSet(chainSlug_, feesPlug_);
Expand Down Expand Up @@ -196,6 +199,13 @@ abstract contract Credit is FeesManagerStorage, Initializable, Ownable, AddressR
emit CreditsTransferred(from_, to_, amount_);
}

/// @notice Approves app gateway for the caller
/// @param appGateway_ app gateway address
/// @param approval_ approval
function approveAppGateway(address appGateway_, bool approval_) external override {
isApproved[msg.sender][appGateway_] = approval_;
}

/// @notice Approves multiple app gateways for the caller
/// @param params_ Array of app gateway addresses to approve
function approveAppGateways(AppGatewayApprovals[] calldata params_) external override {
Expand Down Expand Up @@ -305,4 +315,11 @@ abstract contract Credit is FeesManagerStorage, Initializable, Ownable, AddressR

/// @notice hook called by watcher precompile when request is finished
function onRequestComplete(uint40, bytes memory) external {}

/// @notice hook to handle the revert while withdrawing credits
/// @param payloadId_ The payload ID
function handleRevert(bytes32 payloadId_) external {
if (watcher__().getPayloadParams(payloadId_).asyncPromise != msg.sender) return;
emit WithdrawFailed(payloadId_);
}
}
2 changes: 2 additions & 0 deletions contracts/evmx/interfaces/IFeesManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ interface IFeesManager {

function transferCredits(address from_, address to_, uint256 amount_) external;

function approveAppGateway(address appGateway_, bool approval_) external;

function approveAppGateways(AppGatewayApprovals[] calldata params_) external;

function approveAppGatewayWithSignature(
Expand Down
2 changes: 2 additions & 0 deletions contracts/evmx/plugs/ContractFactoryPlug.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ contract ContractFactoryPlug is PlugBase, AccessControl, IContractFactoryPlug {
constructor(address socket_, address owner_) {
_initializeOwner(owner_);
_setSocket(socket_);

isSocketInitialized = 1;
}

/// @notice Deploys a contract
Expand Down
11 changes: 11 additions & 0 deletions contracts/evmx/plugs/FeesPlug.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {InvalidTokenAddress} from "../../utils/common/Errors.sol";

interface IERC20 {
function balanceOf(address account) external view returns (uint256);

function decimals() external view returns (uint8);
}

/// @title FeesPlug
Expand All @@ -36,6 +38,8 @@ contract FeesPlug is IFeesPlug, PlugBase, AccessControl {
constructor(address socket_, address owner_) {
_setSocket(socket_);
_initializeOwner(owner_);

isSocketInitialized = 1;
}

/////////////////////// DEPOSIT AND WITHDRAWAL ///////////////////////
Expand Down Expand Up @@ -82,6 +86,13 @@ contract FeesPlug is IFeesPlug, PlugBase, AccessControl {
uint256 amount_
) external override onlySocket {
uint256 balance = IERC20(token_).balanceOf(address(this));
uint8 decimals = IERC20(token_).decimals();

if (decimals < 18) {
amount_ = amount_ / 10 ** (18 - decimals);
} else if (decimals > 18) {
amount_ = amount_ * 10 ** (decimals - 18);
}
if (balance < amount_) revert InsufficientTokenBalance(token_, balance, amount_);

token_.safeTransfer(receiver_, amount_);
Expand Down
6 changes: 3 additions & 3 deletions deployments/dev_addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"421614": {
"ContractFactoryPlug": "0x7b9928b01272b915050aDfcba7e0a11b22271BAd",
"FastSwitchboard": "0x2974E94c0d1323D3A24f7B4F924fbdB325Be1aa3",
"FeesPlug": "0x6FdF04Cbcbd40414BF12e0b4Ce0e331e4657EB03",
"FeesPlug": "0xaFD76cADB518E7e5131991Fe4403e00297916957",
"Socket": "0xb7378ae43b135988C8a83dfD1AcD71Ff39381396",
"SocketBatcher": "0x60541d31Fda60163480CAb486be3762b5793B650",
"startBlock": 159641867
Expand All @@ -20,7 +20,7 @@
"DeployForwarderImpl": "0xCe95fca954a0BF43c299c79d5152f2c164C02b7A",
"ERC1967Factory": "0xb0364Fd8f158071831ac87E7EE2C792Ab509a524",
"FeesManager": "0x09F824Eae77f71279d73Ae24FEb2163FCe88B25D",
"FeesManagerImpl": "0x6975302A1B7aF61d89F85a13855B66D15221Cf8D",
"FeesManagerImpl": "0x5b460B29750648f6D569Ed57139967BE589174F8",
"FeesPool": "0xc20Be67ef742202dc93A78aa741E7C3715eA1DFd",
"PromiseResolver": "0xcfFda1dF8668266E6A77809EcA9CCA8A632ecaF3",
"ReadPrecompile": "0x254Dc9e0623426A79F02D2001E367cd32B50aaaA",
Expand All @@ -36,7 +36,7 @@
"11155420": {
"ContractFactoryPlug": "0x0279A18d5FC235A92fB4ABd5F7e9258e78E27948",
"FastSwitchboard": "0x6b4EF1452265193798bfa3ef6D29421da9e7E222",
"FeesPlug": "0x99f7441292EB7f0b127Db204ba269Abd9F912d4C",
"FeesPlug": "0x5E175fD699E066D6536054198d57AF0De88C7c4E",
"Socket": "0xB260A4DD0952e9A5b5F6652019469F05Fb137dC5",
"SocketBatcher": "0xc320FC7b06D4491A9E7e6fa55a3305b12548519e",
"startBlock": 28568337
Expand Down
96 changes: 7 additions & 89 deletions deployments/dev_verification.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,12 @@
{
"421614": [
[
"0x7b9928b01272b915050aDfcba7e0a11b22271BAd",
"ContractFactoryPlug",
"contracts/evmx/plugs/ContractFactoryPlug.sol",
[
"0xb7378ae43b135988C8a83dfD1AcD71Ff39381396",
"0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18"
]
],
[
"0x6FdF04Cbcbd40414BF12e0b4Ce0e331e4657EB03",
"FeesPlug",
"contracts/evmx/plugs/FeesPlug.sol",
[
"0xb7378ae43b135988C8a83dfD1AcD71Ff39381396",
"0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18"
]
],
[
"0x2974E94c0d1323D3A24f7B4F924fbdB325Be1aa3",
"FastSwitchboard",
"contracts/protocol/switchboard/FastSwitchboard.sol",
[
421614,
"0xb7378ae43b135988C8a83dfD1AcD71Ff39381396",
"0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18"
]
],
"421614": [],
"7625382": [
[
"0x60541d31Fda60163480CAb486be3762b5793B650",
"SocketBatcher",
"contracts/protocol/SocketBatcher.sol",
[
"0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18",
"0xb7378ae43b135988C8a83dfD1AcD71Ff39381396"
]
"0x5b460B29750648f6D569Ed57139967BE589174F8",
"FeesManager",
"contracts/evmx/fees/FeesManager.sol",
[]
],
[
"0xb7378ae43b135988C8a83dfD1AcD71Ff39381396",
"Socket",
"contracts/protocol/Socket.sol",
[421614, "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18", "EVMX"]
]
],
"7625382": [
[
"0x872bb254118a2210e3C491918133F2ab4D7Bc362",
"Watcher",
Expand Down Expand Up @@ -258,49 +220,5 @@
[]
]
],
"11155420": [
[
"0x0279A18d5FC235A92fB4ABd5F7e9258e78E27948",
"ContractFactoryPlug",
"contracts/evmx/plugs/ContractFactoryPlug.sol",
[
"0xB260A4DD0952e9A5b5F6652019469F05Fb137dC5",
"0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18"
]
],
[
"0x99f7441292EB7f0b127Db204ba269Abd9F912d4C",
"FeesPlug",
"contracts/evmx/plugs/FeesPlug.sol",
[
"0xB260A4DD0952e9A5b5F6652019469F05Fb137dC5",
"0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18"
]
],
[
"0x6b4EF1452265193798bfa3ef6D29421da9e7E222",
"FastSwitchboard",
"contracts/protocol/switchboard/FastSwitchboard.sol",
[
11155420,
"0xB260A4DD0952e9A5b5F6652019469F05Fb137dC5",
"0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18"
]
],
[
"0xc320FC7b06D4491A9E7e6fa55a3305b12548519e",
"SocketBatcher",
"contracts/protocol/SocketBatcher.sol",
[
"0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18",
"0xB260A4DD0952e9A5b5F6652019469F05Fb137dC5"
]
],
[
"0xB260A4DD0952e9A5b5F6652019469F05Fb137dC5",
"Socket",
"contracts/protocol/Socket.sol",
[11155420, "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18", "EVMX"]
]
]
"11155420": []
}
8 changes: 4 additions & 4 deletions deployments/stage_addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"10": {
"ContractFactoryPlug": "0xee1Aef0b06f63Aa1c881838794Dd0876462c2B0d",
"FastSwitchboard": "0xbDE0D2da12F703Ccd275d721214745BccDCAD124",
"FeesPlug": "0x5F77550E3072c913A20B2fbdAb14026fe0E8B450",
"FeesPlug": "0x501bdF8C7163ddD32172575C2836c5A7F556cbE7",
"Socket": "0x5e1641B190B71ECCc85b1ECe934F31cD9b3dcF7a",
"SocketBatcher": "0xaC61f5696e0E2636dA7bD69827380f2Ab41A3C38",
"startBlock": 136685079
Expand All @@ -20,7 +20,7 @@
"DeployForwarderImpl": "0x1b7752F0039E80Aa38f7CF8b5d18798dD2ac1597",
"ERC1967Factory": "0x526796AC60e45CBB9b17c654C9447Baf160C084d",
"FeesManager": "0xA07208F9e7aE243F922317ab6604DC9F86822406",
"FeesManagerImpl": "0xbD22EDD6559B28614f44D1c768EC26491CDE1cDD",
"FeesManagerImpl": "0xC7A525A5D78610A9B7154315F3eC39Aa62594d1f",
"FeesPool": "0xe2054B575664dfDBD7a7FbAf2B12420ae88DE0FF",
"PromiseResolver": "0x38e24A2F157817b830F36A35b862F24B1494d1aD",
"ReadPrecompile": "0x39b5D3FBBa1BC28438e25955aaB412C7576eCd61",
Expand All @@ -36,15 +36,15 @@
"8453": {
"ContractFactoryPlug": "0x3aac37DC85C522c09A3DDdA44D181E6aCCD2f9F0",
"FastSwitchboard": "0xa33ACE59E4b0d9a45Cd4a3F0DBAB86D87BDd67e2",
"FeesPlug": "0xfE34ACE07836F7F05f485EAc7122D0CD58BAC047",
"FeesPlug": "0x79EB309890F4A797816478dB7D9d57A1e63CeeC2",
"Socket": "0xee1Aef0b06f63Aa1c881838794Dd0876462c2B0d",
"SocketBatcher": "0x9EDfb162b725CF6d628D68af200cAe8b624111eD",
"startBlock": 31089766
},
"42161": {
"ContractFactoryPlug": "0x5F77550E3072c913A20B2fbdAb14026fe0E8B450",
"FastSwitchboard": "0xbDE0D2da12F703Ccd275d721214745BccDCAD124",
"FeesPlug": "0xee1Aef0b06f63Aa1c881838794Dd0876462c2B0d",
"FeesPlug": "0x501bdF8C7163ddD32172575C2836c5A7F556cbE7",
"Socket": "0x5e1641B190B71ECCc85b1ECe934F31cD9b3dcF7a",
"SocketBatcher": "0xaC61f5696e0E2636dA7bD69827380f2Ab41A3C38",
"startBlock": 343531414
Expand Down
22 changes: 10 additions & 12 deletions deployments/stage_verification.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"10": [],
"43": [
[
"0xC7A525A5D78610A9B7154315F3eC39Aa62594d1f",
"FeesManager",
"contracts/evmx/fees/FeesManager.sol",
[]
],
[
"0x0026c4736E57fE2817b53f6df1E0808c3a61984d",
"WritePrecompile",
Expand All @@ -11,9 +17,7 @@
"0x38e24A2F157817b830F36A35b862F24B1494d1aD",
"PromiseResolver",
"contracts/evmx/watcher/PromiseResolver.sol",
[
"0x4C846eCa55ad8cF19B9D5d906225da7b565174C1"
]
["0x4C846eCa55ad8cF19B9D5d906225da7b565174C1"]
],
[
"0xD38ae1a6C410c7681ac464bd60009198406035Ed",
Expand Down Expand Up @@ -67,9 +71,7 @@
"0xe2054B575664dfDBD7a7FbAf2B12420ae88DE0FF",
"FeesPool",
"contracts/evmx/fees/FeesPool.sol",
[
"0xb62505feacC486e809392c65614Ce4d7b051923b"
]
["0xb62505feacC486e809392c65614Ce4d7b051923b"]
],
[
"0x526796AC60e45CBB9b17c654C9447Baf160C084d",
Expand Down Expand Up @@ -118,9 +120,7 @@
"0xd0bd7837E66eEd7Be04C88354e75F5bA3cd19959",
"PromiseResolver",
"contracts/evmx/watcher/PromiseResolver.sol",
[
"0x03Aa399188E2741f89cc4265493DC5b544C52134"
]
["0x03Aa399188E2741f89cc4265493DC5b544C52134"]
],
[
"0x446C6B4086d1888cB15cF62735Bf57A4647E31A4",
Expand Down Expand Up @@ -156,9 +156,7 @@
"0x69DD00B8a250e0A1bFF1b59db2EA99792faAbC66",
"FeesPool",
"contracts/evmx/fees/FeesPool.sol",
[
"0xb62505feacC486e809392c65614Ce4d7b051923b"
]
["0xb62505feacC486e809392c65614Ce4d7b051923b"]
],
[
"0xfddb38811a0774E66ABD5F3Ae960bFB7E7415029",
Expand Down
Loading