-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: addressing issues 3, 9 and 36 #100
Open
kupermind
wants to merge
10
commits into
issue_18_34
Choose a base branch
from
issue_3_9
base: issue_18_34
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+56
−61
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
38b297c
chore: addressing issues 3 and 9
kupermind 31da376
doc
mariapiamo b689ec1
chore: optimizing mech vars
kupermind 9d7e117
chore: event
kupermind e48bfe8
refactor: requester balance adjustment optimization
kupermind 1b96747
chore and test: correcting calldata and more tests
kupermind 21d4a13
chore: interface correction
kupermind 71b10e0
fix: addressing issue 36
kupermind 6585fa7
chore: clean up of unused events / errors
kupermind 554fd38
chore: clean up of unused events / errors
kupermind File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,9 +58,9 @@ | |
uint256 public constant MIN_MECH_BALANCE = 2; | ||
|
||
// Mech marketplace address | ||
address public immutable mechMarketplace; | ||
// Drainer address | ||
address public immutable drainer; | ||
// Collected fees | ||
uint256 public collectedFees; | ||
// Reentrancy lock | ||
|
@@ -111,11 +111,11 @@ | |
} | ||
|
||
/// @dev Adjusts final requester balance accounting for possible delivery rate difference (debit). | ||
/// @param requester Requester address. | ||
/// @param requesterBalance Requester balance. | ||
/// @param rateDiff Delivery rate difference. | ||
/// @return Adjusted balance. | ||
function _adjustFinalBalance(address requester, uint256 rateDiff) internal virtual returns (uint256) { | ||
return mapRequesterBalances[requester] + rateDiff; | ||
function _adjustFinalBalance(uint256 requesterBalance, uint256 rateDiff) internal virtual returns (uint256) { | ||
return requesterBalance + rateDiff; | ||
} | ||
|
||
/// @dev Drains specified amount. | ||
|
@@ -189,7 +189,7 @@ | |
address requester, | ||
uint256 numRequests, | ||
uint256 deliveryRate, | ||
bytes memory paymentData | ||
bytes calldata paymentData | ||
) external virtual payable { | ||
// Reentrancy guard | ||
if (_locked == 2) { | ||
|
@@ -246,13 +246,11 @@ | |
|
||
// Get total mech and requester delivery rates | ||
uint256 totalMechDeliveryRate; | ||
uint256 totalRequesterDeliveryRate; | ||
uint256 totalRateDiff; | ||
for (uint256 i = 0; i < deliveredRequests.length; ++i) { | ||
// Check if request was delivered | ||
if (deliveredRequests[i]) { | ||
totalMechDeliveryRate += mechDeliveryRates[i]; | ||
totalRequesterDeliveryRate += requesterDeliveryRates[i]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not actually needed, it reflects delivery rates of all the requesters in this batch, not relevant. |
||
|
||
// Check for delivery rate difference | ||
if (requesterDeliveryRates[i] > mechDeliveryRates[i]) { | ||
|
@@ -261,7 +259,8 @@ | |
totalRateDiff += rateDiff; | ||
|
||
// Adjust requester balance | ||
mapRequesterBalances[requesters[i]] = _adjustFinalBalance(requesters[i], rateDiff); | ||
uint256 requesterBalance = mapRequesterBalances[requesters[i]]; | ||
mapRequesterBalances[requesters[i]] = _adjustFinalBalance(requesterBalance, rateDiff); | ||
} | ||
} | ||
} | ||
|
@@ -291,7 +290,7 @@ | |
address mech, | ||
address requester, | ||
uint256[] calldata mechDeliveryRates, | ||
bytes memory paymentData | ||
bytes calldata paymentData | ||
) external virtual { | ||
// Reentrancy guard | ||
if (_locked == 2) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ | |
mapping(address => mapping(address => int256)) public mapRequesterMechKarma; | ||
|
||
/// @dev Karma initializer. | ||
function initialize() external{ | ||
function initialize() external { | ||
if (owner != address(0)) { | ||
revert AlreadyInitialized(); | ||
} | ||
|
@@ -68,7 +68,7 @@ | |
|
||
// Store the karma implementation address | ||
// solhint-disable-next-line avoid-low-level-calls | ||
assembly { | ||
sstore(KARMA_PROXY, newImplementation) | ||
} | ||
|
||
|
@@ -147,13 +147,4 @@ | |
|
||
emit RequesterMechKarmaChanged(requester, mech, karmaChange); | ||
} | ||
|
||
/// @dev Gets the implementation address. | ||
/// @return implementation Implementation address. | ||
function getImplementation() external view returns (address implementation) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving this into the proxy as suggested. |
||
// solhint-disable-next-line avoid-low-level-calls | ||
assembly { | ||
implementation := sload(KARMA_PROXY) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,8 +50,9 @@ | |
/// @title Mech Marketplace - Marketplace for posting and delivering requests served by mechs | ||
/// @author Aleksandr Kuperman - <[email protected]> | ||
/// @author Andrey Lebedev - <[email protected]> | ||
/// @author Mariapia Moscatiello - <[email protected]> | ||
/// @author Silvere Gangloff - <[email protected]> | ||
contract MechMarketplace is IErrorsMarketplace { | ||
event CreateMech(address indexed mech, uint256 indexed serviceId, address indexed mechFactory); | ||
event RemoveMech(address indexed mech, uint256 indexed serviceId); | ||
event OwnerUpdated(address indexed owner); | ||
|
@@ -63,10 +64,10 @@ | |
bytes32[] requestIds); | ||
event MarketplaceDelivery(address indexed deliveryMech, address[] indexed requesters, uint256 numDeliveries, | ||
bytes32[] requestIds, bool[] deliveredRequests); | ||
event Deliver(address indexed mech, address indexed mechServiceMultisig, bytes32 requestId, bytes data); | ||
event Deliver(address indexed mech, address indexed mechServiceMultisig, bytes32 requestId, uint256 deliveryRate, | ||
bytes data); | ||
event MarketplaceDeliveryWithSignatures(address indexed deliveryMech, address indexed requester, | ||
uint256 numDeliveries, bytes32[] requestIds); | ||
event RequesterHashApproved(address indexed requester, bytes32 hash); | ||
|
||
enum RequestStatus { | ||
DoesNotExist, | ||
|
@@ -88,11 +89,11 @@ | |
uint256 public constant MAX_FEE_FACTOR = 10_000; | ||
|
||
// Original chain Id | ||
uint256 public immutable chainId; | ||
// Mech karma contract address | ||
address public immutable karma; | ||
// Service registry contract address | ||
address public immutable serviceRegistry; | ||
|
||
// Domain separator value | ||
bytes32 public domainSeparator; | ||
|
@@ -257,7 +258,8 @@ | |
nonce++; | ||
|
||
// Symmetrical delivery mech event that in general happens when delivery is called directly through the mech | ||
emit Deliver(msg.sender, mechServiceMultisig, requestIds[i], deliverWithSignatures[i].deliveryData); | ||
emit Deliver(msg.sender, mechServiceMultisig, requestIds[i], deliveryRates[i], | ||
deliverWithSignatures[i].deliveryData); | ||
} | ||
|
||
// Adjust requester nonce values | ||
|
@@ -725,7 +727,7 @@ | |
/// @return deliveredRequests Corresponding set of successful / failed deliveries. | ||
function deliverMarketplace( | ||
bytes32[] calldata requestIds, | ||
uint256[] memory deliveryRates | ||
uint256[] calldata deliveryRates | ||
) external returns (bool[] memory deliveredRequests) { | ||
// Reentrancy guard | ||
if (_locked == 2) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,13 @@ | |
} | ||
|
||
/// @dev A Mech that is operated by the multisig of an Olas service | ||
/// @author Aleksandr Kuperman - <[email protected]> | ||
/// @author Andrey Lebedev - <[email protected]> | ||
/// @author Mariapia Moscatiello - <[email protected]> | ||
abstract contract OlasMech is Mech, IErrorsMech, ImmutableStorage { | ||
event MaxDeliveryRateUpdated(uint256 maxDeliveryRate); | ||
event Deliver(address indexed mech, address indexed mechServiceMultisig, bytes32 requestId, bytes data); | ||
event Deliver(address indexed mech, address indexed mechServiceMultisig, bytes32 requestId, uint256 deliveryRate, | ||
bytes data); | ||
event Request(address indexed mech, bytes32 requestId, bytes data); | ||
event RevokeRequest(bytes32 requestId); | ||
event NumRequestsIncrease(uint256 numRequests); | ||
|
@@ -28,7 +32,11 @@ | |
// Olas mech version number | ||
string public constant VERSION = "1.0.0"; | ||
// Mech marketplace address | ||
address public immutable mechMarketplace; | ||
// Service Registry address | ||
address public immutable serviceRegistry; | ||
// Service Id | ||
uint256 public immutable serviceId; | ||
// Mech payment type | ||
bytes32 public immutable paymentType; | ||
|
||
|
@@ -92,6 +100,8 @@ | |
setUp(initParams); | ||
|
||
mechMarketplace = _mechMarketplace; | ||
serviceRegistry = _serviceRegistry; | ||
serviceId = _serviceId; | ||
maxDeliveryRate = _maxDeliveryRate; | ||
paymentType = _paymentType; | ||
} | ||
|
@@ -260,7 +270,7 @@ | |
for (uint256 i = 0; i < numRequests; ++i) { | ||
if (deliveredRequests[i]) { | ||
numDeliveries++; | ||
emit Deliver(address(this), msg.sender, requestIds[i], deliveryDatas[i]); | ||
emit Deliver(address(this), msg.sender, requestIds[i], deliveryRates[i], deliveryDatas[i]); | ||
} else { | ||
emit RevokeRequest(requestIds[i]); | ||
} | ||
|
@@ -281,7 +291,7 @@ | |
address requester, | ||
DeliverWithSignature[] calldata deliverWithSignatures, | ||
uint256[] calldata deliveryRates, | ||
bytes memory paymentData | ||
bytes calldata paymentData | ||
) external onlyOperator { | ||
IMechMarketplace(mechMarketplace).deliverMarketplaceWithSignatures(requester, deliverWithSignatures, | ||
deliveryRates, paymentData); | ||
|
@@ -298,24 +308,19 @@ | |
|
||
/// @dev Gets mech token (service registry) address. | ||
/// @return serviceRegistry Service registry address. | ||
function token() external view returns (address serviceRegistry) { | ||
// Get service registry | ||
serviceRegistry = abi.decode(readImmutable(), (address)); | ||
function token() external view returns (address ) { | ||
return serviceRegistry; | ||
} | ||
|
||
/// @dev Gets mech token Id (service Id). | ||
/// @return serviceId Service Id. | ||
function tokenId() external view returns (uint256 serviceId) { | ||
// Get service Id | ||
(, serviceId) = abi.decode(readImmutable(), (address, uint256)); | ||
function tokenId() external view returns (uint256) { | ||
return serviceId; | ||
} | ||
|
||
/// @dev Gets mech operator (service multisig). | ||
/// @return Service multisig address. | ||
function getOperator() public view returns (address) { | ||
// Get service registry and service Id | ||
(address serviceRegistry, uint256 serviceId) = abi.decode(readImmutable(), (address, uint256)); | ||
|
||
(, address multisig, , , , , IServiceRegistry.ServiceState state) = | ||
IServiceRegistry(serviceRegistry).mapServices(serviceId); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
contracts/mechs/nevermined/BalanceTrackerNvmSubscriptionNative.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optimize for gas usage, no need to read from storage the second time.