@@ -19,6 +19,7 @@ contract Exchange is ReentrancyGuard, Ownable {
1919
2020 Registry public immutable registry;
2121 IERC20 public immutable usdcToken;
22+ IERC20 public immutable xsgdToken;
2223 IERC4626 public immutable vault;
2324
2425 uint256 public fee = 100 ; // 100 basis points fee (1%)
@@ -34,12 +35,16 @@ contract Exchange is ReentrancyGuard, Ownable {
3435 event VaultDeposit (address indexed merchant , uint256 assets , uint256 shares );
3536 event VaultWithdraw (address indexed merchant , uint256 assets , uint256 shares );
3637
37- constructor (address _registryAddress , address _usdcAddress , address _vaultAddress ) Ownable (msg .sender ) {
38+ constructor (address _registryAddress , address _usdcAddress , address _xsgdAddress , address _vaultAddress )
39+ Ownable (msg .sender )
40+ {
3841 require (_registryAddress != address (0 ), "Invalid registry address " );
3942 require (_usdcAddress != address (0 ), "Invalid USDC address " );
43+ require (_xsgdAddress != address (0 ), "Invalid xSGD address " );
4044 require (_vaultAddress != address (0 ), "Invalid vault address " );
4145 registry = Registry (_registryAddress);
4246 usdcToken = IERC20 (_usdcAddress);
47+ xsgdToken = IERC20 (_xsgdAddress);
4348 feeCollector = address (this );
4449 vault = IERC4626 (_vaultAddress);
4550 lastUpdateTime = block .timestamp ;
@@ -55,7 +60,7 @@ contract Exchange is ReentrancyGuard, Ownable {
5560 * @param _uen Merchant's UEN.
5661 * @param _amount Amount of USDC to transfer to merchant.
5762 */
58- function transferToMerchant (string memory _uen , uint256 _amount ) external nonReentrant {
63+ function transferUsdcToMerchant (string memory _uen , uint256 _amount ) external nonReentrant {
5964 require (_amount > 0 , "Amount must be greater than zero " );
6065
6166 address merchantWalletAddress = registry.getMerchantByUEN (_uen).wallet_address;
@@ -72,6 +77,23 @@ contract Exchange is ReentrancyGuard, Ownable {
7277 emit Transfer (msg .sender , merchantWalletAddress, merchantAmount, _uen);
7378 }
7479
80+ function transferXsgdToMerchant (string memory _uen , uint256 _amount ) external nonReentrant {
81+ require (_amount > 0 , "Amount must be greater than zero " );
82+
83+ address merchantWalletAddress = registry.getMerchantByUEN (_uen).wallet_address;
84+ require (merchantWalletAddress != address (0 ), "Invalid merchant wallet address " );
85+
86+ uint256 feeAmount = (_amount * fee) / 10000 ;
87+ uint256 merchantAmount = _amount - feeAmount;
88+
89+ xsgdToken.safeTransferFrom (msg .sender , merchantWalletAddress, merchantAmount);
90+ if (feeAmount > 0 ) {
91+ xsgdToken.safeTransferFrom (msg .sender , feeCollector, feeAmount);
92+ }
93+
94+ emit Transfer (msg .sender , merchantWalletAddress, merchantAmount, _uen);
95+ }
96+
7597 /**
7698 * @notice Transfer USDC to vault.
7799 * @param _uen Merchant's UEN.
@@ -154,11 +176,11 @@ contract Exchange is ReentrancyGuard, Ownable {
154176 }
155177
156178 /**
157- * @notice Withdraw fees.
179+ * @notice Withdraw USDC fees.
158180 * @param _to Withdrawal address.
159181 * @param _amount Amount of USDC to withdraw.
160182 */
161- function withdrawFees (address _to , uint256 _amount ) external onlyOwner {
183+ function withdrawUsdcFees (address _to , uint256 _amount ) external onlyOwner {
162184 require (_to != address (0 ), "Invalid withdrawal address " );
163185 require (_amount > 0 , "Withdrawal amount must be greater than zero " );
164186 require (_amount <= usdcToken.balanceOf (address (this )), "Insufficient balance " );
@@ -167,6 +189,24 @@ contract Exchange is ReentrancyGuard, Ownable {
167189 emit FeesWithdrawn (_to, _amount);
168190 }
169191
192+ /**
193+ * @notice Withdraw XSGD fees.
194+ * @param _to Withdrawal address.
195+ * @param _amount Amount of XSGD to withdraw.
196+ */
197+ function withdrawXsgdFees (address _to , uint256 _amount ) external onlyOwner {
198+ require (_to != address (0 ), "Invalid withdrawal address " );
199+ require (_amount > 0 , "Withdrawal amount must be greater than zero " );
200+ require (_amount <= xsgdToken.balanceOf (address (this )), "Insufficient balance " );
201+
202+ xsgdToken.safeTransfer (_to, _amount);
203+ emit FeesWithdrawn (_to, _amount);
204+ }
205+
206+ ///////////////////
207+ // VAULT HELPERS //
208+ ///////////////////
209+
170210 /**
171211 * @notice Get current price per share
172212 * @return Current price of 1 share in terms of assets (USDC)
0 commit comments