Skip to content

Commit 259853f

Browse files
Axel ValavaaraAxel Valavaara
authored andcommitted
changed withdraw feature
1 parent 395d120 commit 259853f

5 files changed

Lines changed: 427 additions & 103 deletions

File tree

broadcast/DeployOrderContract.s.sol/11155111/run-1760904010014.json

Lines changed: 169 additions & 0 deletions
Large diffs are not rendered by default.

broadcast/DeployOrderContract.s.sol/11155111/run-1760989140248.json

Lines changed: 169 additions & 0 deletions
Large diffs are not rendered by default.

broadcast/DeployOrderContract.s.sol/11155111/run-latest.json

Lines changed: 63 additions & 62 deletions
Large diffs are not rendered by default.

src/OrderContract.sol

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,14 @@ contract OrderContract is ReentrancyGuard{
168168
revert OrderContract__OrderCannotBeConfirmedInCurrentState();
169169
}
170170
// update amount paid for the offer by the user
171-
uint256 amountToPay = offers[offerId].price + AGENT_FEE;
171+
uint256 amountToPay = offers[offerId].price;
172172

173173
offers[offerId].paid = amountToPay;
174174
offers[offerId].status = OrderStatus.Confirmed;
175175

176176
offers[offerId].timestamp = block.timestamp;
177177
bool success= ERC20(i_pyUSD).transferFrom(msg.sender, address(this), amountToPay);
178-
178+
_burnA3A(100 ether, msg.sender); // Burn 5 A3A tokens from user as confirmation fee.
179179
if (!success) {
180180
revert OrderContract__ERC20TransferFailed();
181181
}
@@ -258,16 +258,14 @@ contract OrderContract is ReentrancyGuard{
258258
if (!success) {
259259
revert OrderContract__ERC20TransferFailed();
260260
}
261-
A3AToken(i_a3aToken).mint(msg.sender, (PyUsdAmount*ADDITIONAL_PRECISION)*100);
262-
}
263-
264-
function withdrawPyUSD(uint256 amount) external onlyOwner nonReentrant {
265-
bool success = ERC20(i_pyUSD).transfer(msg.sender, amount);
266-
if (!success) {
261+
bool transferSuccess = ERC20(i_pyUSD).transfer(i_owner,PyUsdAmount);
262+
if (!transferSuccess) {
267263
revert OrderContract__ERC20TransferFailed();
268264
}
265+
A3AToken(i_a3aToken).mint(msg.sender, (PyUsdAmount*ADDITIONAL_PRECISION)*100);
269266
}
270-
267+
268+
271269

272270
/*//////////////////////////////////////////////////////////////
273271
INTERNAL AND PRIVATE FUNCTIONS

test/unit/OrderContractTest.t.sol

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ contract OrderContractTest is Test {
148148
// Arrange
149149
uint64 offerId = 1;
150150
uint256 priceForOffer = 5 ether;
151-
uint256 expectedAmountPaid = priceForOffer + orderContract.getAgentFee(); // AGENT_FEE i 1 ether
151+
uint256 expectedAmountPaid = priceForOffer;
152152
uint256 expectedTimeStamp = block.timestamp;
153153
// Act
154154
vm.startPrank(USER);
@@ -165,7 +165,7 @@ contract OrderContractTest is Test {
165165
// Arrange
166166
uint64 offerId = 1;
167167
uint256 priceForOffer = 5 ether;
168-
uint256 expectedAmountPaid = priceForOffer + orderContract.getAgentFee(); // AGENT_FEE is 1 ether
168+
uint256 expectedAmountPaid = priceForOffer;
169169

170170

171171
// Act
@@ -188,6 +188,22 @@ contract OrderContractTest is Test {
188188
orderContract.confirmOrder(offerId);
189189
}
190190

191+
function testConfirmOrderBurnsA3ATokens() public proposeOrderForUser orderProposedAnsweredByAgent {
192+
// Arrange
193+
uint64 offerId = 1;
194+
uint256 priceForOffer = 5 ether;
195+
uint256 userA3ABalanceBefore = a3aToken.balanceOf(USER);
196+
uint256 expectedA3ABurned = 100 ether;
197+
// Act
198+
vm.startPrank(USER);
199+
ERC20Mock(pyUSD).approve(address(orderContract), priceForOffer);
200+
orderContract.confirmOrder(offerId);
201+
vm.stopPrank();
202+
uint256 userA3ABalanceAfter = a3aToken.balanceOf(USER);
203+
// Assert
204+
assertEq(userA3ABalanceBefore - userA3ABalanceAfter, expectedA3ABurned);
205+
}
206+
191207

192208
/*//////////////////////////////////////////////////////////////
193209
PROPOSE ORDER ANSWER TESTS
@@ -271,7 +287,7 @@ contract OrderContractTest is Test {
271287
// Arrange
272288
uint64 offerId = 1;
273289
uint256 sellerBalanceBefore = ERC20Mock(pyUSD).balanceOf(SELLER);
274-
uint256 expectedAmountPaid = 5 ether + orderContract.getAgentFee();
290+
uint256 expectedAmountPaid = 5 ether;
275291
// Act
276292
vm.prank(addressController);
277293
orderContract.finalizeOrder(offerId);
@@ -334,35 +350,6 @@ contract OrderContractTest is Test {
334350
assertEq(uint8(offer.status), uint8(OrderContract.OrderStatus.Proposed));
335351
}
336352

337-
338-
/*//////////////////////////////////////////////////////////////
339-
WITHDRAW PYUSD TESTS
340-
//////////////////////////////////////////////////////////////*/
341-
function testOnlyOwnerCanWithdrawFunds() public orderConfirmed {
342-
// Arrange
343-
uint64 offerId = 1;
344-
// Act / Assert
345-
vm.prank(address(0x123));
346-
vm.expectRevert(OrderContract.OrderContract__onlyOwnerCanWithdrawFunds.selector);
347-
orderContract.withdrawPyUSD(offerId);
348-
}
349-
350-
function testWithdrawFunds() public orderConfirmed {
351-
// Arrange
352-
353-
354-
uint256 contractBalanceBefore = ERC20Mock(pyUSD).balanceOf(address(orderContract));
355-
uint256 ownerBalanceBefore = ERC20Mock(pyUSD).balanceOf(owner);
356-
uint256 amountToWithdraw = 0.5e6;
357-
// Act
358-
vm.prank(owner);
359-
orderContract.withdrawPyUSD(amountToWithdraw);
360-
uint256 contractBalanceAfter = ERC20Mock(pyUSD).balanceOf(address(orderContract));
361-
uint256 ownerBalanceAfter = ERC20Mock(pyUSD).balanceOf(owner);
362-
// Assert
363-
assertEq(contractBalanceBefore - contractBalanceAfter, amountToWithdraw);
364-
assertEq(ownerBalanceAfter - ownerBalanceBefore, amountToWithdraw);
365-
}
366353
/*//////////////////////////////////////////////////////////////
367354
USER ORDER MAPPINGS TESTS
368355
//////////////////////////////////////////////////////////////*/

0 commit comments

Comments
 (0)