-
Notifications
You must be signed in to change notification settings - Fork 1
/
Strategy.sol
executable file
·68 lines (45 loc) · 1.87 KB
/
Strategy.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
pragma solidity ^ 0.5.1;
/// @title Strategy contract
/// @author Andrea Bruno 585457
/// @notice This abstract contract describes what a strategy should implement.
/// @dev The following comments are written using the Solidity NatSpec Format.
contract Strategy {
/// @notice This function compute the price.
/// @param _actualPrice is the current price of the item
/// @param _deltaBlocks the blocks elapsed.
/// @return The updated current price.
function getPrice(uint _actualPrice, uint _deltaBlocks) public view returns(uint);
}
/// @title NormalStrategy contract
/// @notice This contract implement a linear decrease function.
/// @dev This contract extends `Strategy`
contract NormalStrategy is Strategy {
function getPrice(uint _actualPrice, uint _deltaBlocks) public view returns(uint) {
uint tmp = _actualPrice - _deltaBlocks;
//in case of underflow
if (tmp > _actualPrice) return 0;
else return tmp;
}
}
/// @title FastStrategy contract
/// @notice This contract implement a linear decrease function, twice faster than `NormalStrategy`
/// @dev This contract extends `Strategy`
contract FastStrategy is Strategy {
function getPrice(uint _actualPrice, uint _deltaBlocks) public view returns(uint) {
uint tmp = _actualPrice - (2 * _deltaBlocks);
//in case of underflow
if (tmp > _actualPrice) return 0;
else return tmp;
}
}
/// @title SlowStrategy contract
/// @notice This contract implement a linear decrease function, twice slower than `NormalStrategy`
/// @dev This contract extends `Strategy`
contract SlowStrategy is Strategy {
function getPrice(uint _actualPrice, uint _deltaBlocks) public view returns(uint) {
uint tmp = _actualPrice - (_deltaBlocks / 2);
//in case of underflow
if (tmp > _actualPrice) return 0;
else return tmp;
}
}