Skip to content

Commit 1334556

Browse files
authored
Merge pull request #212 from SocketDotTech/fix/fee-deposit-to-trigger
feat: updated deposit to trigger
2 parents 3c8f98f + 933900b commit 1334556

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

contracts/evmx/fees/Credit.sol

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,12 @@ abstract contract Credit is FeesManagerStorage, Initializable, Ownable, AppGatew
121121
}
122122

123123
/// @notice Deposits credits and native tokens to a user
124-
/// @param depositTo_ The address to deposit the credits to
125-
/// @param chainSlug_ The chain slug
126-
/// @param token_ The token address
127-
/// @param nativeAmount_ The native amount
128-
/// @param creditAmount_ The credit amount
129-
function deposit(
130-
uint32 chainSlug_,
131-
address token_,
132-
address depositTo_,
133-
uint256 nativeAmount_,
134-
uint256 creditAmount_
135-
) external override onlyWatcher {
124+
/// @param payload_ Encoded deposit parameters: (chainSlug, token, receiver, creditAmount, nativeAmount)
125+
function deposit(bytes calldata payload_) external override onlyWatcher {
126+
// Decode payload: (chainSlug, token, receiver, creditAmount, nativeAmount)
127+
(uint32 chainSlug_, address token_, address depositTo_, uint256 creditAmount_, uint256 nativeAmount_) =
128+
abi.decode(payload_, (uint32, address, address, uint256, uint256));
129+
136130
tokenOnChainBalances[chainSlug_][token_] += creditAmount_ + nativeAmount_;
137131

138132
// Mint tokens to the user
@@ -142,9 +136,10 @@ abstract contract Credit is FeesManagerStorage, Initializable, Ownable, AppGatew
142136
bool success = feesPool.withdraw(depositTo_, nativeAmount_);
143137

144138
if (!success) {
145-
_mint(depositTo_, creditAmount_);
146-
nativeAmount_ = 0;
139+
// Convert failed native amount to credits
140+
_mint(depositTo_, nativeAmount_);
147141
creditAmount_ += nativeAmount_;
142+
nativeAmount_ = 0;
148143
}
149144
}
150145

contracts/evmx/interfaces/IFeesManager.sol

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@ pragma solidity ^0.8.21;
33
import {WriteFinality, AppGatewayApprovals, OverrideParams, Transaction, RawPayload, Payload} from "../../utils/common/Structs.sol";
44

55
interface IFeesManager {
6-
function deposit(
7-
uint32 chainSlug_,
8-
address token_,
9-
address depositTo_,
10-
uint256 nativeAmount_,
11-
uint256 creditAmount_
12-
) external;
6+
function deposit(bytes calldata payload_) external;
137

148
function wrap(address receiver_) external payable;
159

contracts/evmx/interfaces/IFeesPlug.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ interface IFeesPlug {
77
address token,
88
address receiver,
99
uint256 creditAmount,
10-
uint256 nativeAmount
10+
uint256 nativeAmount,
11+
bytes32 payloadId
1112
);
1213
/// @notice Event emitted when fees are withdrawn
1314
event FeesWithdrawn(address token, address receiver, uint256 amount);

contracts/evmx/plugs/FeesPlug.sol

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,17 @@ contract FeesPlug is IFeesPlug, PlugBase, AccessControl {
6767
) internal {
6868
if (!whitelistedTokens[token_]) revert TokenNotWhitelisted(token_);
6969
token_.safeTransferFrom(msg.sender, address(this), creditAmount_ + nativeAmount_);
70-
emit FeesDeposited(token_, receiver_, creditAmount_, nativeAmount_);
70+
71+
// Get chain slug from socket
72+
uint32 chainSlug_ = socket__.chainSlug();
73+
74+
// Encode deposit parameters: (chainSlug, token, receiver, creditAmount, nativeAmount)
75+
bytes memory payload = abi.encode(chainSlug_, token_, receiver_, creditAmount_, nativeAmount_);
76+
77+
// Create trigger via Socket to get unique payloadId
78+
bytes32 payloadId = socket__.sendPayload(payload);
79+
80+
emit FeesDeposited(token_, receiver_, creditAmount_, nativeAmount_, payloadId);
7181
}
7282

7383
/// @notice Withdraws fees

test/SetupTest.t.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ contract DeploySetup is SetupStore {
218218

219219
// switchboard
220220
switchboard.registerSwitchboard();
221+
switchboard.setEvmxConfig(evmxSlug, 1); // Set EVMX config for trigger payloads
221222
switchboard.grantRole(WATCHER_ROLE, watcherEOA);
222223
switchboard.grantRole(RESCUE_ROLE, address(socketOwner));
223224

@@ -430,7 +431,7 @@ contract FeesSetup is DeploySetup {
430431
vm.expectEmit(true, true, true, false);
431432
emit Deposited(chainSlug_, address(token), user_, credits_, native_);
432433
hoax(watcherEOA);
433-
feesManager.deposit(chainSlug_, address(token), user_, native_, credits_);
434+
feesManager.deposit(abi.encode(chainSlug_, address(token), user_, native_, credits_));
434435

435436
assertEq(
436437
feesManager.balanceOf(user_),

0 commit comments

Comments
 (0)