-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
463 additions
and
522 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,63 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.13; | ||
|
||
import {Ownable} from "openzeppelin-contracts/contracts/access/Ownable.sol"; | ||
import {Collateralization, Deposit} from "../Collateralization.sol"; | ||
import {IDataService} from "./LoanAggregator.sol"; | ||
|
||
contract DataService is Ownable, IDataService { | ||
struct ProviderState { | ||
uint128 deposit; | ||
uint128 payment; | ||
} | ||
|
||
Collateralization public collateralization; | ||
mapping(address => ProviderState) public providers; | ||
uint128 public disputePeriod; | ||
|
||
constructor(Collateralization _collateralization, uint128 _disputePeriod) { | ||
collateralization = _collateralization; | ||
disputePeriod = _disputePeriod; | ||
} | ||
|
||
/// Add provider and fund their future payment. | ||
function addProvider(address _provider, uint128 _payment) public onlyOwner { | ||
require(_payment > 0); | ||
require(providers[_provider].payment == 0, "provider exists"); | ||
providers[_provider] = ProviderState({deposit: 0, payment: _payment}); | ||
collateralization.token().transferFrom(msg.sender, address(this), _payment); | ||
} | ||
|
||
function removeProvider(address _provider) public onlyOwner { | ||
ProviderState memory _state = getProviderState(_provider); | ||
require(_state.deposit == 0, "payment already made"); | ||
delete providers[_provider]; | ||
} | ||
|
||
/// Slash the provider's deposit. | ||
function slash(address _provider, uint256 _amount) public onlyOwner { | ||
ProviderState memory _state = getProviderState(_provider); | ||
collateralization.slash(_state.deposit, _amount); | ||
} | ||
|
||
/// Called by data service provider to receive payment. This locks the given deposit to begin a dispute period. | ||
function remitPayment(address _providerAddr, uint128 _depositID) public { | ||
ProviderState memory _provider = getProviderState(_providerAddr); | ||
Deposit memory _deposit = collateralization.getDeposit(_depositID); | ||
|
||
uint256 minCollateral = uint256(_provider.payment) * 10; | ||
require(_deposit.value >= minCollateral, "collateral below minimum"); | ||
uint128 disputePeriodEnd = uint128(block.timestamp + disputePeriod); | ||
require(_deposit.expiration >= disputePeriodEnd, "collateral expiration before end of dispute period"); | ||
|
||
providers[_providerAddr].deposit = _depositID; | ||
collateralization.lock(_depositID); | ||
collateralization.token().transfer(_providerAddr, _provider.payment); | ||
} | ||
|
||
function getProviderState(address _provider) public view returns (ProviderState memory) { | ||
ProviderState memory _state = providers[_provider]; | ||
require(_state.payment != 0, "provider not found"); | ||
return _state; | ||
} | ||
} | ||
// import {Ownable} from "openzeppelin-contracts/contracts/access/Ownable.sol"; | ||
// import {Collateralization, Deposit} from "../Collateralization.sol"; | ||
// import {IDataService} from "./LoanAggregator.sol"; | ||
|
||
// contract DataService is Ownable, IDataService { | ||
// struct ProviderState { | ||
// uint128 deposit; | ||
// uint128 payment; | ||
// } | ||
|
||
// Collateralization public collateralization; | ||
// mapping(address => ProviderState) public providers; | ||
// uint128 public disputePeriod; | ||
|
||
// constructor(Collateralization _collateralization, uint128 _disputePeriod) { | ||
// collateralization = _collateralization; | ||
// disputePeriod = _disputePeriod; | ||
// } | ||
|
||
// /// Add provider and fund their future payment. | ||
// function addProvider(address _provider, uint128 _payment) public onlyOwner { | ||
// require(_payment > 0); | ||
// require(providers[_provider].payment == 0, "provider exists"); | ||
// providers[_provider] = ProviderState({deposit: 0, payment: _payment}); | ||
// collateralization.token().transferFrom(msg.sender, address(this), _payment); | ||
// } | ||
|
||
// function removeProvider(address _provider) public onlyOwner { | ||
// ProviderState memory _state = getProviderState(_provider); | ||
// require(_state.deposit == 0, "payment already made"); | ||
// delete providers[_provider]; | ||
// } | ||
|
||
// /// Slash the provider's deposit. | ||
// function slash(address _provider, uint256 _amount) public onlyOwner { | ||
// ProviderState memory _state = getProviderState(_provider); | ||
// collateralization.slash(_state.deposit, _amount); | ||
// } | ||
|
||
// /// Called by data service provider to receive payment. This locks the given deposit to begin a dispute period. | ||
// function remitPayment(address _providerAddr, uint128 _depositID) public { | ||
// ProviderState memory _provider = getProviderState(_providerAddr); | ||
// Deposit memory _deposit = collateralization.getDeposit(_depositID); | ||
|
||
// uint256 minCollateral = uint256(_provider.payment) * 10; | ||
// require(_deposit.value >= minCollateral, "collateral below minimum"); | ||
// uint128 disputePeriodEnd = uint128(block.timestamp + disputePeriod); | ||
// require(_deposit.expiration >= disputePeriodEnd, "collateral expiration before end of dispute period"); | ||
|
||
// providers[_providerAddr].deposit = _depositID; | ||
// collateralization.lock(_depositID); | ||
// collateralization.token().transfer(_providerAddr, _provider.payment); | ||
// } | ||
|
||
// function getProviderState(address _provider) public view returns (ProviderState memory) { | ||
// ProviderState memory _state = providers[_provider]; | ||
// require(_state.payment != 0, "provider not found"); | ||
// return _state; | ||
// } | ||
// } |
Oops, something went wrong.