-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDebitaPyth.sol
101 lines (83 loc) · 3.5 KB
/
DebitaPyth.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "@pythnetwork/pyth-sdk-solidity/IPyth.sol";
contract DebitaPyth {
mapping(address => bytes32) public priceIdPerToken;
mapping(bytes32 => bool) public isFeedAvailable;
// Managers will be able to pause the contract or specific price feeds but not set them
mapping(address => bool) public isSenderAManager;
// MultiSig will be able to set price feeds, change multisig, change status of the contract and change status of price feeds
address public multiSig;
bool public isPaused;
IPyth pyth;
// _pyth contract address and _multisig address
constructor(address _pyth, address _multisig) {
pyth = IPyth(_pyth);
isSenderAManager[msg.sender] = true;
multiSig = _multisig;
}
function getThePrice(address tokenAddress) public view returns (int) {
// falta hacer un chequeo para las l2
bytes32 _priceFeed = priceIdPerToken[tokenAddress];
require(_priceFeed != bytes32(0), "Price feed not set");
require(!isPaused, "Contract is paused");
// Get the price from the pyth contract, no older than 90 seconds
PythStructs.Price memory priceData = pyth.getPriceNoOlderThan(
_priceFeed,
600
);
// Check if the price feed is available and the price is valid
require(isFeedAvailable[_priceFeed], "Price feed not available");
require(priceData.price > 0, "Invalid price");
return priceData.price;
}
/*
Managers can pause the contract or specific price feeds but not set them or reactivate them (That's for the multisig)
*/
// only the multisig can set the price feeds. The price feeds can only be set once
function setPriceFeeds(address tokenAddress, bytes32 priceId) public {
require(msg.sender == multiSig, "Only multiSig can set price feeds");
require(
priceIdPerToken[tokenAddress] == bytes32(0),
"Price feed already set"
);
isFeedAvailable[priceId] = true;
priceIdPerToken[tokenAddress] = priceId;
}
function pauseContract() public {
require(
isSenderAManager[msg.sender],
"Only manager can pause contract"
);
isPaused = true;
}
function reactivateContract() public {
require(msg.sender == multiSig, "Only multiSig can change status");
isPaused = false;
}
function pauseStatusPriceId(bytes32 priceId) public {
require(isSenderAManager[msg.sender], "Only manager can change status");
isFeedAvailable[priceId] = false;
}
function reactivateStatusPriceId(bytes32 priceId) public {
require(msg.sender == multiSig, "Only multiSig can change status");
isFeedAvailable[priceId] = true;
}
function changeMultisig(address newMultisig) public {
require(msg.sender == multiSig, "Only multiSig can change multisig");
multiSig = newMultisig;
}
function getDecimals(address token) public view returns (uint) {
bytes32 _priceFeed = priceIdPerToken[token];
PythStructs.Price memory priceData = pyth.getPriceNoOlderThan(
_priceFeed,
1800
);
uint decimals = uint(int(priceData.expo) * -1);
return decimals;
}
function changeManager(address newManager, bool available) public {
require(msg.sender == multiSig, "Only multiSig can change manager");
isSenderAManager[newManager] = available;
}
}