Skip to content

Commit 7a7c33f

Browse files
authored
Merge pull request #937 from oceanprotocol/feature/enterprise_fre
Feature/enterprise_fre
2 parents a1a2fda + 33ad956 commit 7a7c33f

File tree

12 files changed

+2837
-16
lines changed

12 files changed

+2837
-16
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ jobs:
139139
- name: Run Ganache with Barge
140140
working-directory: ${{ github.workspace }}/barge
141141
run: |
142-
bash -x start_ocean.sh --no-aquarius --no-elasticsearch --no-provider --no-dashboard 2>&1 > start_ocean.log &
142+
bash -x start_ocean.sh --no-elasticsearch --no-node --no-ipfs 2>&1 > start_ocean.log &
143143
env:
144144
CONTRACTS_VERSION: test
145145
- run: npm ci

.github/workflows/deployment_check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
- name: Run Ganache with Barge
4242
working-directory: ${{ github.workspace }}/barge
4343
run: |
44-
bash -x start_ocean.sh --no-aquarius --no-elasticsearch --no-provider --no-dashboard 2>&1 > start_ocean.log &
44+
bash -x start_ocean.sh --no-node --no-ipfs --no-elasticsearch 2>&1 > start_ocean.log &
4545
env:
4646
CONTRACTS_VERSION: test
4747
- run: npm ci

addresses/address.json

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@
144144
"VestingWalletB": "0xf02e3163Dc3409D69D88D7AcDA613432E9A18741",
145145
"VestingWalletC": "0x29F74B853C4B8D36273666FB63a3b71c754424Ed",
146146
"OceanNodesBooster": "0x73558Ef3bb6543A8107ac032C5a98Da03ceb0eEf",
147-
"OPFCommunityFeeCollectorCompute":"0x1705CaF86B86e85804e20FE342f39B17322Ff592",
148-
"Escrow":"0x5D7a9F0c8E9E9af5674DEE832Cc97FC425b655Bc"
147+
"OPFCommunityFeeCollectorCompute": "0x1705CaF86B86e85804e20FE342f39B17322Ff592",
148+
"Escrow": "0x5D7a9F0c8E9E9af5674DEE832Cc97FC425b655Bc"
149149
},
150150
"goerli": {
151151
"chainId": 5,
@@ -300,8 +300,10 @@
300300
},
301301
"Dispenser": "0x2720d405ef7cDC8a2E2e5AeBC8883C99611d893C",
302302
"ERC721Factory": "0xEF62FB495266C72a5212A11Dce8baa79Ec0ABeB1",
303-
"OPFCommunityFeeCollectorCompute":"0x0Ee8b03Dafc868a0899ebE1c12d734D53A957250",
304-
"Escrow":"0x86F2BB9F8f18B5a836b342199a3eC89F282E4018"
303+
"OPFCommunityFeeCollectorCompute": "0x0Ee8b03Dafc868a0899ebE1c12d734D53A957250",
304+
"Escrow": "0x86F2BB9F8f18B5a836b342199a3eC89F282E4018",
305+
"EnterpriseFeeCollector": "0x4D49eEedFac8Ea03328c0E4871b680C06d892092",
306+
"FixedPriceEnterprise": "0xEcD0C3519a081e3924D6F3197f86980eA7dfCf71"
305307
},
306308
"oasis_sapphire": {
307309
"chainId": 23294,
@@ -327,8 +329,8 @@
327329
"PredictoorHelper": "0xE9397625Df9B63f0C152f975234b7988b54710B8",
328330
"AccessListFactory": "0x12bB8D85a091A69A07E22E52d4567dBB91568f52",
329331
"BatchPayments": "0x9497d1d64F2aFeBcd4f9916Eef3d9094E5Df962f",
330-
"OPFCommunityFeeCollectorCompute":"0xE5aa2C9B551aFcA4C0A98BB3B37D7A43084d0a66",
331-
"Escrow":"0xf0c7A31D7Ee26bEBfb4BAD8e37490bEadE3F846f"
332+
"OPFCommunityFeeCollectorCompute": "0xE5aa2C9B551aFcA4C0A98BB3B37D7A43084d0a66",
333+
"Escrow": "0xf0c7A31D7Ee26bEBfb4BAD8e37490bEadE3F846f"
332334
},
333335
"optimism_sepolia": {
334336
"chainId": 11155420,
@@ -346,8 +348,8 @@
346348
},
347349
"Dispenser": "0x30E4CC2C7A9c6aA2b2Ce93586E3Df24a3A00bcDD",
348350
"ERC721Factory": "0xDEfD0018969cd2d4E648209F876ADe184815f038",
349-
"OPFCommunityFeeCollectorCompute":"0xe47991939632757DEe324E8ec9A3268c62C0DB76",
350-
"Escrow":"0x4D49eEedFac8Ea03328c0E4871b680C06d892092"
351+
"OPFCommunityFeeCollectorCompute": "0xe47991939632757DEe324E8ec9A3268c62C0DB76",
352+
"Escrow": "0x4D49eEedFac8Ea03328c0E4871b680C06d892092"
351353
},
352354
"optimism": {
353355
"chainId": 10,
@@ -365,8 +367,8 @@
365367
},
366368
"Dispenser": "0x2112Eb973af1DBf83a4f11eda82f7a7527D7Fde5",
367369
"ERC721Factory": "0x80E63f73cAc60c1662f27D2DFd2EA834acddBaa8",
368-
"OPFCommunityFeeCollectorCompute":"0xc37F8341Ac6e4a94538302bCd4d49Cf0852D30C0",
369-
"Escrow":"0x3c21a90599b5B7f37014cA5Bf30d3f1b73d7e391"
370+
"OPFCommunityFeeCollectorCompute": "0xc37F8341Ac6e4a94538302bCd4d49Cf0852D30C0",
371+
"Escrow": "0x3c21a90599b5B7f37014cA5Bf30d3f1b73d7e391"
370372
},
371373
"pontus-x-devnet": {
372374
"chainId": 32456,
@@ -401,7 +403,7 @@
401403
"Dispenser": "0xE9397625Df9B63f0C152f975234b7988b54710B8",
402404
"ERC721Factory": "0x159924ca0F47D6F704B97E29099b89e518A17B5E",
403405
"BatchPayments": "0xFe7967A5176fDAFa8DE109b3507016B885a82D6e",
404-
"OPFCommunityFeeCollectorCompute":"0x7b0576CF01E868bce46cca91b2a8E674141b0355",
405-
"Escrow":"0x8389bC1306208488D665F939AFB4079adf6f5a06"
406+
"OPFCommunityFeeCollectorCompute": "0x7b0576CF01E868bce46cca91b2a8E674141b0355",
407+
"Escrow": "0x8389bC1306208488D665F939AFB4079adf6f5a06"
406408
}
407409
}
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
pragma solidity 0.8.12;
2+
// Copyright BigchainDB GmbH and Ocean Protocol contributors
3+
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
4+
// Code is Apache-2.0 and docs are CC-BY-4.0
5+
import '../interfaces/IERC20.sol';
6+
import '@openzeppelin/contracts/access/Ownable.sol';
7+
import '../utils/SafeERC20.sol';
8+
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
9+
10+
11+
/**
12+
* @title EnterpriseFeeCollector
13+
* @dev Ocean Protocol Enterprise Fee Collector contract
14+
*/
15+
contract EnterpriseFeeCollector is Ownable {
16+
using SafeERC20 for IERC20;
17+
using SafeMath for uint256;
18+
uint256 private constant BASE = 1e18;
19+
address payable collector;
20+
struct Token {
21+
bool allowed;
22+
uint256 minFee;
23+
uint256 maxFee;
24+
uint256 feePercentage; // ie: 1e15 = 0.1%
25+
}
26+
// maps an exchangeId to an exchange
27+
mapping(address => Token) public tokenList;
28+
/**
29+
* @dev constructor
30+
* Called prior contract deployment. set the controller address and
31+
* the contract owner address
32+
* @param newCollector the fee collector address.
33+
* @param OwnerAddress the contract owner address
34+
*/
35+
constructor(
36+
address payable newCollector,
37+
address OwnerAddress
38+
)
39+
Ownable()
40+
{
41+
require(
42+
newCollector != address(0)&&
43+
OwnerAddress != address(0),
44+
'OPFCommunityFeeCollector: collector address or owner is invalid address'
45+
);
46+
collector = newCollector;
47+
transferOwnership(OwnerAddress);
48+
}
49+
/**
50+
* @dev fallback function
51+
* this is a default fallback function in which receives
52+
* the collected ether.
53+
*/
54+
fallback() external payable {}
55+
56+
/**
57+
* @dev receive function
58+
* this is a default receive function in which receives
59+
* the collected ether.
60+
*/
61+
receive() external payable {}
62+
63+
/**
64+
* @dev withdrawETH
65+
* transfers all the accumlated ether the collector address
66+
*/
67+
function withdrawETH()
68+
external
69+
payable
70+
{
71+
(bool sent, ) = collector.call{value: address(this).balance}("");
72+
require(sent, "Failed to send Ether");
73+
}
74+
75+
/**
76+
* @dev withdrawToken
77+
* transfers all the accumlated tokens the collector address
78+
* @param tokenAddress the token contract address
79+
*/
80+
function withdrawToken(
81+
address tokenAddress
82+
)
83+
external
84+
{
85+
require(
86+
tokenAddress != address(0),
87+
'OPFCommunityFeeCollector: invalid token contract address'
88+
);
89+
90+
IERC20(tokenAddress).safeTransfer(
91+
collector,
92+
IERC20(tokenAddress).balanceOf(address(this))
93+
);
94+
}
95+
96+
/**
97+
* @dev changeCollector
98+
* change the current collector address. Only owner can do that.
99+
* @param newCollector the new collector address
100+
*/
101+
function changeCollector(
102+
address payable newCollector
103+
)
104+
external
105+
onlyOwner
106+
{
107+
require(
108+
newCollector != address(0),
109+
'OPFCommunityFeeCollector: invalid collector address'
110+
);
111+
collector = newCollector;
112+
}
113+
114+
/**
115+
* @dev isTokenAllowed
116+
* checks if the token is allowed to be used in the fee calculation.
117+
* @param tokenAddress the token contract address
118+
* @return true if the token is allowed, false otherwise
119+
*/
120+
121+
function isTokenAllowed(address tokenAddress)
122+
external
123+
view
124+
returns (bool)
125+
{
126+
return tokenList[tokenAddress].allowed;
127+
}
128+
/**
129+
* @dev getToken
130+
* returns the token details.
131+
* @param tokenAddress the token contract address
132+
* @return Token struct containing the token details
133+
*/
134+
function getToken(address tokenAddress)
135+
external
136+
view
137+
returns (Token memory)
138+
{
139+
return tokenList[tokenAddress];
140+
}
141+
142+
/**
143+
* @dev updateToken
144+
* updateToken a token in the allowed list.
145+
* @param tokenAddress the token contract address
146+
* @param minFee the minimum fee for the token
147+
* @param maxFee the maximum fee for the token
148+
* @param feePercentage the fee percentage for the token
149+
*/
150+
function updateToken(
151+
address tokenAddress,
152+
uint256 minFee,
153+
uint256 maxFee,
154+
uint256 feePercentage,
155+
bool allowed
156+
)
157+
external
158+
onlyOwner
159+
{
160+
require(
161+
tokenAddress != address(0),
162+
'OPFCommunityFeeCollector: invalid token contract address'
163+
);
164+
require(
165+
minFee < maxFee,
166+
'OPFCommunityFeeCollector: minFee should be less than maxFee'
167+
);
168+
require(
169+
feePercentage > 0 && feePercentage <= BASE,
170+
'OPFCommunityFeeCollector: feePercentage should be greater than 0 and less than or equal to 1e18'
171+
);
172+
tokenList[tokenAddress] = Token({
173+
allowed: allowed,
174+
minFee: minFee,
175+
maxFee: maxFee,
176+
feePercentage: feePercentage
177+
});
178+
}
179+
180+
function calculateFee(address tokenAddress, uint256 amount)
181+
external
182+
view
183+
returns (uint256)
184+
{
185+
uint256 fee;
186+
if(tokenList[tokenAddress].feePercentage>0)
187+
fee=amount.mul(tokenList[tokenAddress].feePercentage).div(BASE);
188+
else
189+
fee=0;
190+
if (fee < tokenList[tokenAddress].minFee) {
191+
return tokenList[tokenAddress].minFee;
192+
}
193+
if (fee > tokenList[tokenAddress].maxFee) {
194+
return tokenList[tokenAddress].maxFee;
195+
}
196+
return fee;
197+
}
198+
199+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
pragma solidity 0.8.12;
2+
// Copyright BigchainDB GmbH and Ocean Protocol contributors
3+
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
4+
// Code is Apache-2.0 and docs are CC-BY-4.0
5+
6+
interface IEnterpriseFeeCollector {
7+
function calculateFee(
8+
address baseTokenAddress,
9+
uint256 amount
10+
) external view returns (uint256);
11+
function isTokenAllowed(address tokenAddress)
12+
external
13+
view
14+
returns (bool);
15+
}

0 commit comments

Comments
 (0)