@@ -25,6 +25,7 @@ pragma solidity ^0.8.18;
2525
2626import {ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol " ;
2727import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol " ;
28+ import {A3AToken} from "./A3Atoken.sol " ;
2829
2930contract OrderContract is ReentrancyGuard {
3031 /* errors */
@@ -57,11 +58,13 @@ contract OrderContract is ReentrancyGuard{
5758 OrderStatus status;
5859 }
5960 /* state variables */
60- uint256 private constant AGENT_FEE = 1 ether ; // Fee for agent services. Adjust as needed.
61+ uint256 private constant ADDITIONAL_PRECISION = 1e12 ; // To handle decimals for tokens with less than 18 decimals
62+ uint256 private constant AGENT_FEE = 1e6 ; // Fee for agent services. Adjust as needed.
6163 uint256 private constant HOLD_UNTIL = 600 ; // Time in seconds to hold the order. Adjust as needed.
6264 uint64 private offerID = 0 ; // Counter for offer IDs
6365 address private immutable agentController; // Address of the agent controller
6466 address private immutable pyUSD; // Address of the pyUSD token contract
67+ address private immutable a3aToken; // Address of the A3A token contract
6568
6669 // will make mappings to struct!!! thus too messy.
6770 //////////////////////////////////////////////
@@ -104,10 +107,11 @@ contract OrderContract is ReentrancyGuard{
104107 _;
105108
106109 }
107- constructor (address agentControllerAddress , address pyUSDAddress ) {
110+ constructor (address agentControllerAddress , address pyUSDAddress , address a3aTokenAddress ) {
108111 // Initialization logic if needed
109112 agentController = agentControllerAddress;
110113 pyUSD = pyUSDAddress;
114+ a3aToken = a3aTokenAddress;
111115 }
112116 function proposeOrder (bytes32 promptHash ) external returns (uint64 offerId ) {
113117
@@ -125,12 +129,23 @@ contract OrderContract is ReentrancyGuard{
125129
126130 // addressToOfferIdToPromptHash[msg.sender][offerID] = promptHash;
127131 // offerIdToUser[offerID] = msg.sender;
132+
128133 emit OrderProposed (offers[offerID].buyer, offerID, offers[offerID].promptHash);
129-
134+ // Burn 10 A3A tokens from uses. This acts as Fee for using the platform.
135+ _burnA3A (10 ether, msg .sender );
130136 return offerID;
131137
132138 }
133139
140+ function _burnA3A (uint256 amount ,address A3AFrom ) private {
141+
142+ bool success = A3AToken (a3aToken).transferFrom (A3AFrom, address (this ), amount);
143+ if (! success) {
144+ revert OrderContract__ERC20TransferFailed ();
145+ }
146+ A3AToken (a3aToken).burn (amount);
147+ }
148+
134149
135150
136151 function confirmOrder (uint64 offerId ) external nonReentrant onlyUserWithOffer (offerId) {
@@ -203,6 +218,16 @@ contract OrderContract is ReentrancyGuard{
203218 }
204219
205220
221+ function buyA3AToken (uint256 PyUsdAmount ) external nonReentrant {
222+
223+ bool success = ERC20 (pyUSD).transferFrom (msg .sender , address (this ), PyUsdAmount);
224+ if (! success) {
225+ revert OrderContract__ERC20TransferFailed ();
226+ }
227+ A3AToken (a3aToken).mint (msg .sender , (PyUsdAmount* ADDITIONAL_PRECISION)* 10 );
228+ }
229+
230+
206231
207232 /* getter functions */
208233 function getPromptHash (uint64 offerId ) external view returns (bytes32 ) {
@@ -334,5 +359,4 @@ contract OrderContract is ReentrancyGuard{
334359 }
335360
336361
337-
338- }
362+ }
0 commit comments