@@ -4,10 +4,9 @@ pragma solidity 0.8.28;
44
55import {ReentrancyGuardTransient} from 'src/dependencies/openzeppelin/ReentrancyGuardTransient.sol ' ;
66import {SafeTransferLib} from 'src/dependencies/solady/SafeTransferLib.sol ' ;
7- import {MathUtils } from 'src/libraries/math/MathUtils .sol ' ;
7+ import {GatewayBase } from 'src/position-manager/GatewayBase .sol ' ;
88import {ISpoke} from 'src/spoke/interfaces/ISpoke.sol ' ;
99import {INativeWrapper} from 'src/position-manager/interfaces/INativeWrapper.sol ' ;
10- import {GatewayBase} from 'src/position-manager/GatewayBase.sol ' ;
1110import {INativeTokenGateway} from 'src/position-manager/interfaces/INativeTokenGateway.sol ' ;
1211
1312/// @title NativeTokenGateway
@@ -42,61 +41,75 @@ contract NativeTokenGateway is INativeTokenGateway, GatewayBase, ReentrancyGuard
4241 address spoke ,
4342 uint256 reserveId ,
4443 uint256 amount
45- ) external payable nonReentrant onlyRegisteredSpoke (spoke) {
44+ ) external payable nonReentrant onlyRegisteredSpoke (spoke) returns ( uint256 , uint256 ) {
4645 require (msg .value == amount, NativeAmountMismatch ());
47- _supplyNative (spoke, reserveId, msg .sender , amount);
46+ return _supplyNative (spoke, reserveId, msg .sender , amount);
4847 }
4948
5049 /// @inheritdoc INativeTokenGateway
5150 function supplyAsCollateralNative (
5251 address spoke ,
5352 uint256 reserveId ,
5453 uint256 amount
55- ) external payable nonReentrant onlyRegisteredSpoke (spoke) {
54+ ) external payable nonReentrant onlyRegisteredSpoke (spoke) returns ( uint256 , uint256 ) {
5655 require (msg .value == amount, NativeAmountMismatch ());
57- _supplyNative (spoke, reserveId, msg .sender , amount);
56+ (uint256 suppliedShares , uint256 suppliedAmount ) = _supplyNative (
57+ spoke,
58+ reserveId,
59+ msg .sender ,
60+ amount
61+ );
5862 ISpoke (spoke).setUsingAsCollateral (reserveId, true , msg .sender );
63+
64+ return (suppliedShares, suppliedAmount);
5965 }
6066
6167 /// @inheritdoc INativeTokenGateway
6268 function withdrawNative (
6369 address spoke ,
6470 uint256 reserveId ,
6571 uint256 amount
66- ) external onlyRegisteredSpoke (spoke) {
72+ ) external onlyRegisteredSpoke (spoke) returns ( uint256 , uint256 ) {
6773 (address underlying , ) = _getReserveData (spoke, reserveId);
6874 _validateParams (underlying, amount);
6975
70- uint256 withdrawAmount = MathUtils.min (
76+ (uint256 withdrawnShares , uint256 withdrawnAmount ) = ISpoke (spoke).withdraw (
77+ reserveId,
7178 amount,
72- ISpoke (spoke). getUserSuppliedAssets (reserveId, msg .sender )
79+ msg .sender
7380 );
81+ _nativeWrapper.withdraw (withdrawnAmount);
82+ msg .sender .safeTransferETH (withdrawnAmount);
7483
75- ISpoke (spoke).withdraw (reserveId, withdrawAmount, msg .sender );
76- _nativeWrapper.withdraw (withdrawAmount);
77- msg .sender .safeTransferETH (withdrawAmount);
84+ return (withdrawnShares, withdrawnAmount);
7885 }
7986
8087 /// @inheritdoc INativeTokenGateway
8188 function borrowNative (
8289 address spoke ,
8390 uint256 reserveId ,
8491 uint256 amount
85- ) external onlyRegisteredSpoke (spoke) {
92+ ) external onlyRegisteredSpoke (spoke) returns ( uint256 , uint256 ) {
8693 (address underlying , ) = _getReserveData (spoke, reserveId);
8794 _validateParams (underlying, amount);
8895
89- ISpoke (spoke).borrow (reserveId, amount, msg .sender );
90- _nativeWrapper.withdraw (amount);
91- msg .sender .safeTransferETH (amount);
96+ (uint256 borrowedShares , uint256 borrowedAmount ) = ISpoke (spoke).borrow (
97+ reserveId,
98+ amount,
99+ msg .sender
100+ );
101+ _nativeWrapper.withdraw (borrowedAmount);
102+ msg .sender .safeTransferETH (borrowedAmount);
103+
104+ return (borrowedShares, borrowedAmount);
92105 }
93106
94107 /// @inheritdoc INativeTokenGateway
95108 function repayNative (
96109 address spoke ,
97110 uint256 reserveId ,
98111 uint256 amount
99- ) external payable nonReentrant onlyRegisteredSpoke (spoke) {
112+ ) external payable nonReentrant onlyRegisteredSpoke (spoke) returns ( uint256 , uint256 ) {
100113 require (msg .value == amount, NativeAmountMismatch ());
101114 (address underlying , address hub ) = _getReserveData (spoke, reserveId);
102115 _validateParams (underlying, amount);
@@ -111,11 +124,17 @@ contract NativeTokenGateway is INativeTokenGateway, GatewayBase, ReentrancyGuard
111124
112125 _nativeWrapper.deposit {value: repayAmount}();
113126 address (_nativeWrapper).safeApproveWithRetry (hub, repayAmount);
114- ISpoke (spoke).repay (reserveId, repayAmount, msg .sender );
127+ (uint256 repaidShares , uint256 repaidAmount ) = ISpoke (spoke).repay (
128+ reserveId,
129+ repayAmount,
130+ msg .sender
131+ );
115132
116133 if (leftovers > 0 ) {
117134 msg .sender .safeTransferETH (leftovers);
118135 }
136+
137+ return (repaidShares, repaidAmount);
119138 }
120139
121140 /// @inheritdoc INativeTokenGateway
@@ -124,13 +143,18 @@ contract NativeTokenGateway is INativeTokenGateway, GatewayBase, ReentrancyGuard
124143 }
125144
126145 /// @dev `msg.value` verification must be done before calling this.
127- function _supplyNative (address spoke , uint256 reserveId , address user , uint256 amount ) internal {
146+ function _supplyNative (
147+ address spoke ,
148+ uint256 reserveId ,
149+ address user ,
150+ uint256 amount
151+ ) internal returns (uint256 , uint256 ) {
128152 (address underlying , address hub ) = _getReserveData (spoke, reserveId);
129153 _validateParams (underlying, amount);
130154
131155 _nativeWrapper.deposit {value: amount}();
132156 address (_nativeWrapper).safeApproveWithRetry (hub, amount);
133- ISpoke (spoke).supply (reserveId, amount, user);
157+ return ISpoke (spoke).supply (reserveId, amount, user);
134158 }
135159
136160 function _validateParams (address underlying , uint256 amount ) internal view {
0 commit comments