Skip to content

Commit

Permalink
chore: base for mech fixed price
Browse files Browse the repository at this point in the history
  • Loading branch information
kupermind committed Jan 8, 2025
1 parent 79616da commit ccc1abc
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 71 deletions.
32 changes: 16 additions & 16 deletions abis/0.8.28/BalanceTrackerFixedPriceToken.json

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions contracts/MechFixedPriceBase.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import {OlasMech} from "./OlasMech.sol";

/// @title MechFixedPriceBase - Smart contract for OlasMech that accepts a fixed price payment for services.
abstract contract MechFixedPriceBase is OlasMech {
/// @dev MechFixedPriceBase constructor.
/// @param _mechMarketplace Mech marketplace address.
/// @param _serviceRegistry Address of the token contract.
/// @param _serviceId Service Id.
/// @param _maxDeliveryRate The maximum delivery rate.
/// @param _paymentType Payment type.
constructor(address _mechMarketplace, address _serviceRegistry, uint256 _serviceId, uint256 _maxDeliveryRate, bytes32 _paymentType)
OlasMech(_mechMarketplace, _serviceRegistry, _serviceId, _maxDeliveryRate, _paymentType)
{}

/// @dev Performs actions before the delivery of a request.
/// @param data Self-descriptive opaque data-blob.
/// @return requestData Data for the request processing.
function _preDeliver(address, uint256, bytes memory data) internal virtual override returns (bytes memory requestData) {
requestData = data;
}

/// @dev Gets finalized delivery rate for a request Id.
/// @return Finalized delivery rate.
function getFinalizedDeliveryRate(uint256) external virtual override returns (uint256) {
return maxDeliveryRate;
}
}
21 changes: 4 additions & 17 deletions contracts/mechs/native/MechFixedPriceNative.sol
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import {OlasMech} from "../../OlasMech.sol";
import {MechFixedPriceBase} from "../../MechFixedPriceBase.sol";

/// @title MechFixedPriceNative - Smart contract for OlasMech that accepts a fixed price payment for services in native token.
contract MechFixedPriceNative is OlasMech {
contract MechFixedPriceNative is MechFixedPriceBase {
// keccak256(FixedPriceNative) = ba699a34be8fe0e7725e93dcbce1701b0211a8ca61330aaeb8a05bf2ec7abed1
bytes32 public constant PAYMENT_TYPE = 0xba699a34be8fe0e7725e93dcbce1701b0211a8ca61330aaeb8a05bf2ec7abed1;

/// @dev AgentMech constructor.
/// @dev MechFixedPriceNative constructor.
/// @param _mechMarketplace Mech marketplace address.
/// @param _serviceRegistry Address of the token contract.
/// @param _serviceId Service Id.
/// @param _maxDeliveryRate The maximum delivery rate.
constructor(address _mechMarketplace, address _serviceRegistry, uint256 _serviceId, uint256 _maxDeliveryRate)
OlasMech(_mechMarketplace, _serviceRegistry, _serviceId, _maxDeliveryRate, PAYMENT_TYPE)
MechFixedPriceBase(_mechMarketplace, _serviceRegistry, _serviceId, _maxDeliveryRate, PAYMENT_TYPE)
{}

/// @dev Performs actions before the delivery of a request.
/// @param data Self-descriptive opaque data-blob.
/// @return requestData Data for the request processing.
function _preDeliver(address, uint256, bytes memory data) internal virtual override returns (bytes memory requestData) {
requestData = data;
}

/// @dev Gets finalized delivery rate for a request Id.
/// @return Finalized delivery rate.
function getFinalizedDeliveryRate(uint256) external virtual override returns (uint256) {
return maxDeliveryRate;
}
}
9 changes: 2 additions & 7 deletions contracts/mechs/nevermined/MechNvmSubscription.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,12 @@ contract MechNvmSubscription is OlasMech {
// Mapping for requestId => finalized delivery rates
mapping(uint256 => uint256) public mapRequestIdFinalizedRates;

/// @dev AgentMechSubscription constructor.
/// @dev MechNvmSubscription constructor.
/// @param _mechMarketplace Mech marketplace address.
/// @param _serviceRegistry Address of the token contract.
/// @param _serviceId Service Id.
/// @param _maxDeliveryRate The maximum delivery rate.
constructor(
address _mechMarketplace,
address _serviceRegistry,
uint256 _serviceId,
uint256 _maxDeliveryRate
)
constructor(address _mechMarketplace, address _serviceRegistry, uint256 _serviceId,uint256 _maxDeliveryRate)
OlasMech(_mechMarketplace, _serviceRegistry, _serviceId, _maxDeliveryRate, PAYMENT_TYPE)
{}

Expand Down
28 changes: 14 additions & 14 deletions contracts/mechs/token/BalanceTrackerFixedPriceToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ interface IToken {
error NoDepositAllowed(uint256 amount);

contract BalanceTrackerFixedPriceToken is BalanceTrackerFixedPriceBase {
// OLAS token address
address public immutable olas;
// Token address
address public immutable token;

/// @dev BalanceTrackerFixedPrice constructor.
/// @param _mechMarketplace Mech marketplace address.
/// @param _buyBackBurner Buy back burner address.
/// @param _olas OLAS token address.
constructor(address _mechMarketplace, address _buyBackBurner, address _olas)
/// @param _token Token address.
constructor(address _mechMarketplace, address _buyBackBurner, address _token)
BalanceTrackerFixedPriceBase(_mechMarketplace, _buyBackBurner)
{
// Check for zero address
if (_olas == address(0)) {
if (_token == address(0)) {
revert ZeroAddress();
}

olas = _olas;
token = _token;
}

/// @dev Drains specified amount.
/// @param amount Token amount.
function _drain(uint256 amount) internal virtual override {
// Transfer to Buy back burner
IToken(olas).transfer(buyBackBurner, amount);
IToken(token).transfer(buyBackBurner, amount);

emit Drained(olas, amount);
emit Drained(token, amount);
}

/// @dev Gets native token value or restricts receiving one.
Expand All @@ -68,9 +68,9 @@ contract BalanceTrackerFixedPriceToken is BalanceTrackerFixedPriceBase {
/// @return Received amount.
function _getRequiredFunds(address requester, uint256 amount) internal virtual override returns (uint256) {
// Get tokens from requester
IToken(olas).transferFrom(requester, address(this), amount);
IToken(token).transferFrom(requester, address(this), amount);

emit Deposit(msg.sender, olas, amount);
emit Deposit(msg.sender, token, amount);

return amount;
}
Expand All @@ -80,9 +80,9 @@ contract BalanceTrackerFixedPriceToken is BalanceTrackerFixedPriceBase {
/// @param amount Token amount.
function _withdraw(address account, uint256 amount) internal virtual override {
// Transfer tokens
IToken(olas).transfer(account, amount);
IToken(token).transfer(account, amount);

emit Withdraw(msg.sender, olas, amount);
emit Withdraw(msg.sender, token, amount);
}

/// @dev Deposits token funds for requester.
Expand All @@ -92,8 +92,8 @@ contract BalanceTrackerFixedPriceToken is BalanceTrackerFixedPriceBase {
mapRequesterBalances[msg.sender] += amount;

// Get tokens
IToken(olas).transferFrom(msg.sender, address(this), amount);
IToken(token).transferFrom(msg.sender, address(this), amount);

emit Deposit(msg.sender, olas, amount);
emit Deposit(msg.sender, token, amount);
}
}
21 changes: 4 additions & 17 deletions contracts/mechs/token/MechFixedPriceToken.sol
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import {OlasMech} from "../../OlasMech.sol";
import {MechFixedPriceBase} from "../../MechFixedPriceBase.sol";

/// @title MechFixedPriceToken - Smart contract for OlasMech that accepts a fixed price payment for services in native token.
contract MechFixedPriceToken is OlasMech {
contract MechFixedPriceToken is MechFixedPriceBase {
// keccak256(FixedPriceToken) = 3679d66ef546e66ce9057c4a052f317b135bc8e8c509638f7966edfd4fcf45e9
bytes32 public constant PAYMENT_TYPE = 0x3679d66ef546e66ce9057c4a052f317b135bc8e8c509638f7966edfd4fcf45e9;

/// @dev AgentMech constructor.
/// @dev MechFixedPriceToken constructor.
/// @param _mechMarketplace Mech marketplace address.
/// @param _serviceRegistry Address of the token contract.
/// @param _serviceId Service Id.
/// @param _maxDeliveryRate The maximum delivery rate.
constructor(address _mechMarketplace, address _serviceRegistry, uint256 _serviceId, uint256 _maxDeliveryRate)
OlasMech(_mechMarketplace, _serviceRegistry, _serviceId, _maxDeliveryRate, PAYMENT_TYPE)
MechFixedPriceBase(_mechMarketplace, _serviceRegistry, _serviceId, _maxDeliveryRate, PAYMENT_TYPE)
{}

/// @dev Performs actions before the delivery of a request.
/// @param data Self-descriptive opaque data-blob.
/// @return requestData Data for the request processing.
function _preDeliver(address, uint256, bytes memory data) internal virtual override returns (bytes memory requestData) {
requestData = data;
}

/// @dev Gets finalized delivery rate for a request Id.
/// @return Finalized delivery rate.
function getFinalizedDeliveryRate(uint256) external virtual override returns (uint256) {
return maxDeliveryRate;
}
}

0 comments on commit ccc1abc

Please sign in to comment.