Skip to content

Commit b5b5c7f

Browse files
authored
Merge pull request #161 from SocketDotTech/dev
Dev
2 parents 7ece1fa + 5a99770 commit b5b5c7f

File tree

19 files changed

+279
-166
lines changed

19 files changed

+279
-166
lines changed

EventTopics.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
| `OwnershipHandoverCanceled` | `(pendingOwner: address)` | `0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92` |
7272
| `OwnershipHandoverRequested` | `(pendingOwner: address)` | `0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d` |
7373
| `OwnershipTransferred` | `(oldOwner: address, newOwner: address)` | `0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0` |
74+
| `WithdrawFailed` | `(payloadId: bytes32)` | `0xea147eb2109f71b4bda9e57528ba08b84821087a31cb43a7851dc6ff743d9be7` |
7475

7576
## FeesPool
7677

FunctionSignatures.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
| Function | Signature |
125125
| -------------------------------- | ------------ |
126126
| `addressResolver__` | `0x6a750469` |
127+
| `approveAppGateway` | `0xa3b53d8b` |
127128
| `approveAppGatewayWithSignature` | `0x94b649ec` |
128129
| `approveAppGateways` | `0x86d23ab2` |
129130
| `asyncDeployer__` | `0x2a39e801` |
@@ -137,6 +138,7 @@
137138
| `feesPlugs` | `0x23f5ee8a` |
138139
| `feesPool` | `0x6b259690` |
139140
| `getAvailableCredits` | `0xb065a8e5` |
141+
| `handleRevert` | `0x44792f25` |
140142
| `initialize` | `0xbf2c8539` |
141143
| `isApproved` | `0xa389783e` |
142144
| `isCreditSpendable` | `0x4f8990fd` |

contracts/evmx/base/AppGatewayBase.sol

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,7 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway {
236236
uint256 amount_,
237237
address receiver_
238238
) internal {
239-
AppGatewayApprovals[] memory approvals = new AppGatewayApprovals[](1);
240-
approvals[0] = AppGatewayApprovals({appGateway: address(feesManager__()), approval: true});
241-
feesManager__().approveAppGateways(approvals);
239+
feesManager__().approveAppGateway(address(feesManager__()), true);
242240
feesManager__().withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_);
243241
}
244242

contracts/evmx/fees/Credit.sol

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ abstract contract Credit is FeesManagerStorage, Initializable, Ownable, AddressR
9797
/// @notice Emitted when fees pool is set
9898
event FeesPoolSet(address indexed feesPool);
9999

100+
/// @notice Emitted when withdraw fails
101+
event WithdrawFailed(bytes32 indexed payloadId);
102+
100103
function setFeesPlug(uint32 chainSlug_, address feesPlug_) external onlyOwner {
101104
feesPlugs[chainSlug_] = feesPlug_;
102105
emit FeesPlugSet(chainSlug_, feesPlug_);
@@ -196,6 +199,13 @@ abstract contract Credit is FeesManagerStorage, Initializable, Ownable, AddressR
196199
emit CreditsTransferred(from_, to_, amount_);
197200
}
198201

202+
/// @notice Approves app gateway for the caller
203+
/// @param appGateway_ app gateway address
204+
/// @param approval_ approval
205+
function approveAppGateway(address appGateway_, bool approval_) external override {
206+
isApproved[msg.sender][appGateway_] = approval_;
207+
}
208+
199209
/// @notice Approves multiple app gateways for the caller
200210
/// @param params_ Array of app gateway addresses to approve
201211
function approveAppGateways(AppGatewayApprovals[] calldata params_) external override {
@@ -305,4 +315,11 @@ abstract contract Credit is FeesManagerStorage, Initializable, Ownable, AddressR
305315

306316
/// @notice hook called by watcher precompile when request is finished
307317
function onRequestComplete(uint40, bytes memory) external {}
318+
319+
/// @notice hook to handle the revert while withdrawing credits
320+
/// @param payloadId_ The payload ID
321+
function handleRevert(bytes32 payloadId_) external {
322+
if (watcher__().getPayloadParams(payloadId_).asyncPromise != msg.sender) return;
323+
emit WithdrawFailed(payloadId_);
324+
}
308325
}

contracts/evmx/interfaces/IFeesManager.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ interface IFeesManager {
2525

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

28+
function approveAppGateway(address appGateway_, bool approval_) external;
29+
2830
function approveAppGateways(AppGatewayApprovals[] calldata params_) external;
2931

3032
function approveAppGatewayWithSignature(

contracts/evmx/plugs/ContractFactoryPlug.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ contract ContractFactoryPlug is PlugBase, AccessControl, IContractFactoryPlug {
2727
constructor(address socket_, address owner_) {
2828
_initializeOwner(owner_);
2929
_setSocket(socket_);
30+
31+
isSocketInitialized = 1;
3032
}
3133

3234
/// @notice Deploys a contract

contracts/evmx/plugs/FeesPlug.sol

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {InvalidTokenAddress} from "../../utils/common/Errors.sol";
1111

1212
interface IERC20 {
1313
function balanceOf(address account) external view returns (uint256);
14+
15+
function decimals() external view returns (uint8);
1416
}
1517

1618
/// @title FeesPlug
@@ -36,6 +38,8 @@ contract FeesPlug is IFeesPlug, PlugBase, AccessControl {
3638
constructor(address socket_, address owner_) {
3739
_setSocket(socket_);
3840
_initializeOwner(owner_);
41+
42+
isSocketInitialized = 1;
3943
}
4044

4145
/////////////////////// DEPOSIT AND WITHDRAWAL ///////////////////////
@@ -82,6 +86,13 @@ contract FeesPlug is IFeesPlug, PlugBase, AccessControl {
8286
uint256 amount_
8387
) external override onlySocket {
8488
uint256 balance = IERC20(token_).balanceOf(address(this));
89+
uint8 decimals = IERC20(token_).decimals();
90+
91+
if (decimals < 18) {
92+
amount_ = amount_ / 10 ** (18 - decimals);
93+
} else if (decimals > 18) {
94+
amount_ = amount_ * 10 ** (decimals - 18);
95+
}
8596
if (balance < amount_) revert InsufficientTokenBalance(token_, balance, amount_);
8697

8798
token_.safeTransfer(receiver_, amount_);

deployments/dev_addresses.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"421614": {
33
"ContractFactoryPlug": "0x7b9928b01272b915050aDfcba7e0a11b22271BAd",
44
"FastSwitchboard": "0x2974E94c0d1323D3A24f7B4F924fbdB325Be1aa3",
5-
"FeesPlug": "0x6FdF04Cbcbd40414BF12e0b4Ce0e331e4657EB03",
5+
"FeesPlug": "0xaFD76cADB518E7e5131991Fe4403e00297916957",
66
"Socket": "0xb7378ae43b135988C8a83dfD1AcD71Ff39381396",
77
"SocketBatcher": "0x60541d31Fda60163480CAb486be3762b5793B650",
88
"startBlock": 159641867
@@ -20,7 +20,7 @@
2020
"DeployForwarderImpl": "0xCe95fca954a0BF43c299c79d5152f2c164C02b7A",
2121
"ERC1967Factory": "0xb0364Fd8f158071831ac87E7EE2C792Ab509a524",
2222
"FeesManager": "0x09F824Eae77f71279d73Ae24FEb2163FCe88B25D",
23-
"FeesManagerImpl": "0x6975302A1B7aF61d89F85a13855B66D15221Cf8D",
23+
"FeesManagerImpl": "0x5b460B29750648f6D569Ed57139967BE589174F8",
2424
"FeesPool": "0xc20Be67ef742202dc93A78aa741E7C3715eA1DFd",
2525
"PromiseResolver": "0xcfFda1dF8668266E6A77809EcA9CCA8A632ecaF3",
2626
"ReadPrecompile": "0x254Dc9e0623426A79F02D2001E367cd32B50aaaA",
@@ -36,7 +36,7 @@
3636
"11155420": {
3737
"ContractFactoryPlug": "0x0279A18d5FC235A92fB4ABd5F7e9258e78E27948",
3838
"FastSwitchboard": "0x6b4EF1452265193798bfa3ef6D29421da9e7E222",
39-
"FeesPlug": "0x99f7441292EB7f0b127Db204ba269Abd9F912d4C",
39+
"FeesPlug": "0x5E175fD699E066D6536054198d57AF0De88C7c4E",
4040
"Socket": "0xB260A4DD0952e9A5b5F6652019469F05Fb137dC5",
4141
"SocketBatcher": "0xc320FC7b06D4491A9E7e6fa55a3305b12548519e",
4242
"startBlock": 28568337

deployments/dev_verification.json

Lines changed: 7 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,12 @@
11
{
2-
"421614": [
3-
[
4-
"0x7b9928b01272b915050aDfcba7e0a11b22271BAd",
5-
"ContractFactoryPlug",
6-
"contracts/evmx/plugs/ContractFactoryPlug.sol",
7-
[
8-
"0xb7378ae43b135988C8a83dfD1AcD71Ff39381396",
9-
"0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18"
10-
]
11-
],
12-
[
13-
"0x6FdF04Cbcbd40414BF12e0b4Ce0e331e4657EB03",
14-
"FeesPlug",
15-
"contracts/evmx/plugs/FeesPlug.sol",
16-
[
17-
"0xb7378ae43b135988C8a83dfD1AcD71Ff39381396",
18-
"0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18"
19-
]
20-
],
21-
[
22-
"0x2974E94c0d1323D3A24f7B4F924fbdB325Be1aa3",
23-
"FastSwitchboard",
24-
"contracts/protocol/switchboard/FastSwitchboard.sol",
25-
[
26-
421614,
27-
"0xb7378ae43b135988C8a83dfD1AcD71Ff39381396",
28-
"0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18"
29-
]
30-
],
2+
"421614": [],
3+
"7625382": [
314
[
32-
"0x60541d31Fda60163480CAb486be3762b5793B650",
33-
"SocketBatcher",
34-
"contracts/protocol/SocketBatcher.sol",
35-
[
36-
"0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18",
37-
"0xb7378ae43b135988C8a83dfD1AcD71Ff39381396"
38-
]
5+
"0x5b460B29750648f6D569Ed57139967BE589174F8",
6+
"FeesManager",
7+
"contracts/evmx/fees/FeesManager.sol",
8+
[]
399
],
40-
[
41-
"0xb7378ae43b135988C8a83dfD1AcD71Ff39381396",
42-
"Socket",
43-
"contracts/protocol/Socket.sol",
44-
[421614, "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18", "EVMX"]
45-
]
46-
],
47-
"7625382": [
4810
[
4911
"0x872bb254118a2210e3C491918133F2ab4D7Bc362",
5012
"Watcher",
@@ -258,49 +220,5 @@
258220
[]
259221
]
260222
],
261-
"11155420": [
262-
[
263-
"0x0279A18d5FC235A92fB4ABd5F7e9258e78E27948",
264-
"ContractFactoryPlug",
265-
"contracts/evmx/plugs/ContractFactoryPlug.sol",
266-
[
267-
"0xB260A4DD0952e9A5b5F6652019469F05Fb137dC5",
268-
"0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18"
269-
]
270-
],
271-
[
272-
"0x99f7441292EB7f0b127Db204ba269Abd9F912d4C",
273-
"FeesPlug",
274-
"contracts/evmx/plugs/FeesPlug.sol",
275-
[
276-
"0xB260A4DD0952e9A5b5F6652019469F05Fb137dC5",
277-
"0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18"
278-
]
279-
],
280-
[
281-
"0x6b4EF1452265193798bfa3ef6D29421da9e7E222",
282-
"FastSwitchboard",
283-
"contracts/protocol/switchboard/FastSwitchboard.sol",
284-
[
285-
11155420,
286-
"0xB260A4DD0952e9A5b5F6652019469F05Fb137dC5",
287-
"0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18"
288-
]
289-
],
290-
[
291-
"0xc320FC7b06D4491A9E7e6fa55a3305b12548519e",
292-
"SocketBatcher",
293-
"contracts/protocol/SocketBatcher.sol",
294-
[
295-
"0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18",
296-
"0xB260A4DD0952e9A5b5F6652019469F05Fb137dC5"
297-
]
298-
],
299-
[
300-
"0xB260A4DD0952e9A5b5F6652019469F05Fb137dC5",
301-
"Socket",
302-
"contracts/protocol/Socket.sol",
303-
[11155420, "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18", "EVMX"]
304-
]
305-
]
223+
"11155420": []
306224
}

deployments/stage_addresses.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"10": {
33
"ContractFactoryPlug": "0xee1Aef0b06f63Aa1c881838794Dd0876462c2B0d",
44
"FastSwitchboard": "0xbDE0D2da12F703Ccd275d721214745BccDCAD124",
5-
"FeesPlug": "0x5F77550E3072c913A20B2fbdAb14026fe0E8B450",
5+
"FeesPlug": "0x501bdF8C7163ddD32172575C2836c5A7F556cbE7",
66
"Socket": "0x5e1641B190B71ECCc85b1ECe934F31cD9b3dcF7a",
77
"SocketBatcher": "0xaC61f5696e0E2636dA7bD69827380f2Ab41A3C38",
88
"startBlock": 136685079
@@ -20,7 +20,7 @@
2020
"DeployForwarderImpl": "0x1b7752F0039E80Aa38f7CF8b5d18798dD2ac1597",
2121
"ERC1967Factory": "0x526796AC60e45CBB9b17c654C9447Baf160C084d",
2222
"FeesManager": "0xA07208F9e7aE243F922317ab6604DC9F86822406",
23-
"FeesManagerImpl": "0xbD22EDD6559B28614f44D1c768EC26491CDE1cDD",
23+
"FeesManagerImpl": "0xC7A525A5D78610A9B7154315F3eC39Aa62594d1f",
2424
"FeesPool": "0xe2054B575664dfDBD7a7FbAf2B12420ae88DE0FF",
2525
"PromiseResolver": "0x38e24A2F157817b830F36A35b862F24B1494d1aD",
2626
"ReadPrecompile": "0x39b5D3FBBa1BC28438e25955aaB412C7576eCd61",
@@ -36,15 +36,15 @@
3636
"8453": {
3737
"ContractFactoryPlug": "0x3aac37DC85C522c09A3DDdA44D181E6aCCD2f9F0",
3838
"FastSwitchboard": "0xa33ACE59E4b0d9a45Cd4a3F0DBAB86D87BDd67e2",
39-
"FeesPlug": "0xfE34ACE07836F7F05f485EAc7122D0CD58BAC047",
39+
"FeesPlug": "0x79EB309890F4A797816478dB7D9d57A1e63CeeC2",
4040
"Socket": "0xee1Aef0b06f63Aa1c881838794Dd0876462c2B0d",
4141
"SocketBatcher": "0x9EDfb162b725CF6d628D68af200cAe8b624111eD",
4242
"startBlock": 31089766
4343
},
4444
"42161": {
4545
"ContractFactoryPlug": "0x5F77550E3072c913A20B2fbdAb14026fe0E8B450",
4646
"FastSwitchboard": "0xbDE0D2da12F703Ccd275d721214745BccDCAD124",
47-
"FeesPlug": "0xee1Aef0b06f63Aa1c881838794Dd0876462c2B0d",
47+
"FeesPlug": "0x501bdF8C7163ddD32172575C2836c5A7F556cbE7",
4848
"Socket": "0x5e1641B190B71ECCc85b1ECe934F31cD9b3dcF7a",
4949
"SocketBatcher": "0xaC61f5696e0E2636dA7bD69827380f2Ab41A3C38",
5050
"startBlock": 343531414

0 commit comments

Comments
 (0)