-
Notifications
You must be signed in to change notification settings - Fork 1
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
refactor and fix: addressing recent changes #62
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
pragma solidity ^0.8.28; | ||
|
||
import {BalanceTrackerFixedPriceBase, ZeroAddress, NoDepositAllowed, TransferFailed} from "./BalanceTrackerFixedPriceBase.sol"; | ||
import {IMech} from "./interfaces/IMech.sol"; | ||
|
||
interface IToken { | ||
/// @dev Transfers the token amount. | ||
|
@@ -17,11 +17,16 @@ | |
/// @param amount Amount to transfer to. | ||
/// @return True if the function execution is successful. | ||
function transferFrom(address from, address to, uint256 amount) external returns (bool); | ||
|
||
/// @dev Gets the amount of tokens owned by a specified account. | ||
/// @param account Account address. | ||
/// @return Amount of tokens owned. | ||
function balanceOf(address account) external view returns (uint256); | ||
} | ||
|
||
contract BalanceTrackerFixedPriceNative is BalanceTrackerFixedPriceBase { | ||
// OLAS token address | ||
address public immutable olas; | ||
|
||
/// @dev BalanceTrackerFixedPrice constructor. | ||
/// @param _mechMarketplace Mech marketplace address. | ||
|
@@ -38,16 +43,29 @@ | |
olas = _olas; | ||
} | ||
|
||
function _checkNativeValue() internal virtual override { | ||
function _getOrRestrictNativeValue() internal virtual override returns (uint256) { | ||
// Check for msg.value | ||
if (msg.value > 0) { | ||
revert NoDepositAllowed(msg.value); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
function _getRequiredFunds(address requester, uint256 balanceDiff) internal virtual override returns (uint256) { | ||
// TODO check balances before and after | ||
uint256 balanceBefore = IToken(olas).balanceOf(address(this)); | ||
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. Additional check, although with OLAS it's pretty much safe by default. |
||
// Get tokens from requester | ||
IToken(olas).transferFrom(requester, address(this), balanceDiff); | ||
uint256 balanceAfter = IToken(olas).balanceOf(address(this)); | ||
|
||
// Check the balance | ||
uint256 diff = balanceAfter - balanceBefore; | ||
if (diff != balanceDiff) { | ||
revert TransferFailed(olas, requester, address(this), balanceDiff); | ||
} | ||
|
||
emit Deposit(msg.sender, olas, balanceDiff); | ||
|
||
return balanceDiff; | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -8,12 +8,22 @@ import {MechFixedPriceNative} from "./MechFixedPriceNative.sol"; | |
/// @param expected Expected data length. | ||
error IncorrectDataLength(uint256 provided, uint256 expected); | ||
|
||
/// @dev Only `marketplace` has a privilege, but the `sender` was provided. | ||
/// @param sender Sender address. | ||
/// @param marketplace Required marketplace address. | ||
error MarketplaceOnly(address sender, address marketplace); | ||
|
||
/// @dev Provided zero address. | ||
error ZeroAddress(); | ||
|
||
/// @title Mech Factory Basic - Periphery smart contract for managing basic mech creation | ||
contract MechFactoryFixedPriceNative { | ||
event CreateFixedPriceMech(address indexed mech, uint256 indexed serviceId, uint256 maxDeliveryRate); | ||
|
||
// Agent factory version number | ||
string public constant VERSION = "0.1.0"; | ||
// Nonce | ||
uint256 internal _nonce; | ||
|
||
/// @dev Registers service as a mech. | ||
/// @param mechMarketplace Mech marketplace address. | ||
|
@@ -27,7 +37,10 @@ contract MechFactoryFixedPriceNative { | |
uint256 serviceId, | ||
bytes memory payload | ||
) external returns (address mech) { | ||
// TODO: restrict all factories to be called from marketplace only - makes it easier to monitor the system | ||
// Check for marketplace access | ||
if (msg.sender != mechMarketplace) { | ||
revert MarketplaceOnly(msg.sender, mechMarketplace); | ||
} | ||
|
||
// Check payload length | ||
if (payload.length != 32) { | ||
|
@@ -37,12 +50,19 @@ contract MechFactoryFixedPriceNative { | |
// Decode max delivery rate | ||
uint256 maxDeliveryRate = abi.decode(payload, (uint256)); | ||
|
||
uint256 localNonce = _nonce; | ||
// Get salt | ||
bytes32 salt = keccak256(abi.encode(block.timestamp, msg.sender, serviceId)); | ||
bytes32 salt = keccak256(abi.encode(block.timestamp, msg.sender, serviceId, localNonce)); | ||
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. Adding nonce as per audit suggestion |
||
_nonce = localNonce + 1; | ||
|
||
// Service multisig is isOperator() for the mech | ||
mech = address((new MechFixedPriceNative){salt: salt}(mechMarketplace, serviceRegistry, serviceId, maxDeliveryRate)); | ||
|
||
// Check for zero address | ||
if (mech == address(0)) { | ||
revert ZeroAddress(); | ||
} | ||
|
||
emit CreateFixedPriceMech(mech, serviceId, maxDeliveryRate); | ||
} | ||
} |
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.
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.
This is the current refactor of incoming payment.