@@ -11,57 +11,57 @@ contract Delivery {
1111
1212 // ======== State Variables ========
1313 Contractly public contractly;
14+ uint256 private lastAutomationUpdate;
1415 mapping (uint256 agreementId = > bool hasVendorAssigned ) private hasVendorAssigned;
1516
1617 // ======== Events ========
17- event AgreementCreated (uint256 indexed agreementId , string title , address creator );
18- event DeliveryCreated (uint256 indexed agreementId , string title , address vendor , address customer );
19- event BatchDeliveryCreated (string [] titles , uint256 [] expirationTimes , uint256 [] totalStakingAmounts , address [] customerAddresses );
18+ event AgreementCreated (uint256 indexed agreementId , address creator );
19+ event DeliveryCreated (uint256 indexed agreementId , address vendor , address customer );
20+ event BatchDeliveryCreated (uint256 [] expirationTimes , uint256 [] totalStakingAmounts , address [] customerAddresses );
2021
2122 // ======== Constructor ========
2223 constructor (address _contractlyAddress ) {
2324 contractly = Contractly (_contractlyAddress);
25+ lastAutomationUpdate = 0 ;
2426 }
2527
2628 // ======== Core Functions ========
2729
2830 /**
2931 * @dev Creates a new delivery (vendor -> customer) agreement
30- * @param _title The title of the agreement
3132 * @param _expirationTime The timestamp when the agreement expires
3233 * @param _totalStakingAmount The total amount that needs to be staked across all parties
3334 * @param _customerAddress The address of the customer
3435 */
35- function createDelivery (string memory _title , uint256 _expirationTime , uint256 _totalStakingAmount , address _customerAddress ) public payable returns (uint256 ) {
36- uint256 agreementId = _createAgreement (_title, _expirationTime, _totalStakingAmount);
36+ function createDelivery (uint256 _expirationTime , uint256 _totalStakingAmount , address _customerAddress ) public payable returns (uint256 ) {
37+ uint256 agreementId = _createAgreement (_expirationTime, _totalStakingAmount);
3738 _addVendorParty (agreementId, msg .sender );
3839 _addCustomerParty (agreementId, _customerAddress);
3940 _signAgreement (agreementId);
4041 stakeAgreement (agreementId, _totalStakingAmount);
4142 contractly.lockAgreement (agreementId);
42- emit DeliveryCreated (agreementId, _title, msg .sender , _customerAddress);
43+ emit DeliveryCreated (agreementId, msg .sender , _customerAddress);
4344 return agreementId;
4445 }
4546
4647 /**
4748 * @dev Creates multiple delivery (vendor -> customer)[] agreements.
48- * @param _titles The titles of the agreements
4949 * @param _expirationTimes The timestamps when the agreements expire
5050 * @param _totalStakingAmounts The total amounts that need to be staked across all parties
5151 * @param _customerAddresses The addresses of the customers
5252 */
53- function batchCreateDelivery (string [] memory _titles , uint256 [] memory _expirationTimes , uint256 [] memory _totalStakingAmounts , address [] memory _customerAddresses ) public payable returns (uint256 [] memory ) {
53+ function batchCreateDelivery (uint256 [] memory _expirationTimes , uint256 [] memory _totalStakingAmounts , address [] memory _customerAddresses ) public payable returns (uint256 [] memory ) {
5454 uint256 [] memory agreementIds = new uint256 [](_customerAddresses.length );
5555 for (uint256 i = 0 ; i < _customerAddresses.length ; i++ ) {
56- uint256 agreementId = _createAgreement (_titles[i], _expirationTimes[i], _totalStakingAmounts[i]);
56+ uint256 agreementId = _createAgreement (_expirationTimes[i], _totalStakingAmounts[i]);
5757 _addVendorParty (agreementId, msg .sender );
5858 _addCustomerParty (agreementId, _customerAddresses[i]);
5959 _signAgreement (agreementId);
6060 stakeAgreement (agreementId, _totalStakingAmounts[i]);
6161 contractly.lockAgreement (agreementId);
6262 agreementIds[i] = agreementId;
6363 }
64- emit BatchDeliveryCreated (_titles, _expirationTimes, _totalStakingAmounts, _customerAddresses);
64+ emit BatchDeliveryCreated (_expirationTimes, _totalStakingAmounts, _customerAddresses);
6565 return agreementIds;
6666 }
6767
@@ -71,7 +71,7 @@ contract Delivery {
7171 }
7272 contractly.stakeAgreement { value: _amount }(_agreementId, msg .sender );
7373 // Check if all parties have staked to automatically lock the agreement
74- (,,,,,,,, address [] memory parties ) = getAgreementDetails (_agreementId);
74+ (,,,,,,, address [] memory parties ) = getAgreementDetails (_agreementId);
7575 bool allPartiesStaked = true ;
7676 for (uint256 i = 0 ; i < parties.length ; i++ ) {
7777 if (contractly.stakedFunds (_agreementId, parties[i]) == 0 ) {
@@ -89,34 +89,26 @@ contract Delivery {
8989 }
9090
9191 function breachAgreement (uint256 _agreementId , address _breachingParty ) public {
92- console.log ("breaching party " , _breachingParty);
93- console.log ("agreement id " , _agreementId);
94- console.log ("status " , uint256 (contractly.getAgreementStatus (_agreementId)));
95- console.log ("party count " , contractly.getPartyCount (_agreementId));
96- console.log ("party address at index 0 " , contractly.getPartyAddressAtIndex (_agreementId, 0 ));
97- console.log ("party address at index 1 " , contractly.getPartyAddressAtIndex (_agreementId, 1 ));
98- console.log ("party stake amount at index 0 " , contractly.getPartyStakeAmount (_agreementId, contractly.getPartyAddressAtIndex (_agreementId, 0 )));
99- console.log ("party stake amount at index 1 " , contractly.getPartyStakeAmount (_agreementId, contractly.getPartyAddressAtIndex (_agreementId, 1 )));
10092 contractly.breachAgreement (_agreementId, _breachingParty);
93+ }
10194
102- console.log ("After breach " );
103- console.log ("breaching party " , _breachingParty);
104- console.log ("agreement id " , _agreementId);
105- console.log ("status " , uint256 (contractly.getAgreementStatus (_agreementId)));
106- console.log ("party count " , contractly.getPartyCount (_agreementId));
107- console.log ("party address at index 0 " , contractly.getPartyAddressAtIndex (_agreementId, 0 ));
108- console.log ("party address at index 1 " , contractly.getPartyAddressAtIndex (_agreementId, 1 ));
109- console.log ("party stake amount at index 0 " , contractly.getPartyStakeAmount (_agreementId, contractly.getPartyAddressAtIndex (_agreementId, 0 )));
110- console.log ("party stake amount at index 1 " , contractly.getPartyStakeAmount (_agreementId, contractly.getPartyAddressAtIndex (_agreementId, 1 )));
95+ function checkDeliveryStatus (uint256 _agreementId ) public {
96+ if (true ){
97+ fulfillAgreement (_agreementId);
98+ }
99+ else {
100+ breachAgreement (_agreementId, msg .sender );
101+ }
102+ lastAutomationUpdate = block .timestamp ;
111103 }
112104
113105 // ======== Internal Functions ========
114106
115- function _createAgreement (string memory _title , uint256 _expirationTime , uint256 _totalStakingAmount ) internal returns (uint256 ) {
107+ function _createAgreement (uint256 _expirationTime , uint256 _totalStakingAmount ) internal returns (uint256 ) {
116108 // Create the agreement in Contractly
117- uint256 agreementId = contractly.createAgreement (_title, msg .sender , _expirationTime, _totalStakingAmount);
109+ uint256 agreementId = contractly.createAgreement (msg .sender , _expirationTime, _totalStakingAmount);
118110
119- emit AgreementCreated (agreementId, _title, msg .sender );
111+ emit AgreementCreated (agreementId, msg .sender );
120112
121113 return agreementId;
122114 }
@@ -139,11 +131,15 @@ contract Delivery {
139131
140132 // ======== Getters ========
141133
142- function getAgreementDetails (uint256 _agreementId ) public view returns (uint256 id , string memory title , address creator , uint256 creationTime , uint256 expirationTime , uint256 disputeWindowDuration , uint256 totalStakingAmount , Contractly.AgreementStatus status , address [] memory partyAddresses ) {
134+ function getAgreementDetails (uint256 _agreementId ) public view returns (uint256 id , address creator , uint256 creationTime , uint256 expirationTime , uint256 disputeWindowDuration , uint256 totalStakingAmount , Contractly.AgreementStatus status , address [] memory partyAddresses ) {
143135 return contractly.getAgreement (_agreementId);
144136 }
145137
146138 function getHasVendorAssigned (uint256 _agreementId ) public view returns (bool ) {
147139 return hasVendorAssigned[_agreementId];
148140 }
141+
142+ function getLastAutomationUpdate () public view returns (uint256 ) {
143+ return lastAutomationUpdate;
144+ }
149145}
0 commit comments