@gearbox-protocol/periphery-v3 1.2.13 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -55,7 +55,6 @@ import {
55
55
  GaugeInfo,
56
56
  GaugeQuotaParams,
57
57
  CreditManagerDebtParams,
58
- GaugeVote,
59
58
  ZapperInfo,
60
59
  LinearModel
61
60
  } from "./Types.sol";
@@ -647,7 +646,7 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
647
646
  }
648
647
  }
649
648
 
650
- function getGaugesV3Data() external view returns (GaugeInfo[] memory result) {
649
+ function getGaugesV3Data(address staker) external view override returns (GaugeInfo[] memory result) {
651
650
  address[] memory poolsV3 = _listPoolsV3();
652
651
  uint256 len = poolsV3.length;
653
652
  result = new GaugeInfo[](len);
@@ -665,6 +664,9 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
665
664
  uint256 quotaTokensLen = quotaTokens.length;
666
665
  gaugeInfo.quotaParams = new GaugeQuotaParams[](quotaTokensLen);
667
666
 
667
+ gaugeInfo.currentEpoch = IGaugeV3(gauge).epochLastUpdate();
668
+ gaugeInfo.epochFrozen = IGaugeV3(gauge).epochFrozen();
669
+
668
670
  for (uint256 j; j < quotaTokensLen; ++j) {
669
671
  GaugeQuotaParams memory quotaParams = gaugeInfo.quotaParams[j];
670
672
  address token = quotaTokens[j];
@@ -685,58 +687,9 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
685
687
  quotaParams.totalVotesLpSide,
686
688
  quotaParams.totalVotesCaSide
687
689
  ) = IGaugeV3(gauge).quotaRateParams(token);
688
- }
689
- }
690
- }
691
- }
692
690
 
693
- function getGaugeVotes(address staker) external view returns (GaugeVote[] memory gaugeVotes) {
694
- address[] memory poolsV3 = _listPoolsV3();
695
- uint256 len = poolsV3.length;
696
- uint256 index;
697
-
698
- unchecked {
699
- for (uint256 op = COUNT; op <= QUERY; ++op) {
700
- if (op == QUERY && index == 0) {
701
- break;
702
- } else {
703
- gaugeVotes = new GaugeVote[](index);
704
- index = 0;
705
- }
706
- for (uint256 i; i < len; ++i) {
707
- address[] memory quotaTokens;
708
- address gauge;
709
- {
710
- IPoolQuotaKeeperV3 pqk = _getPoolQuotaKeeper(poolsV3[i]);
711
- gauge = _getGauge(pqk);
712
-
713
- quotaTokens = _getQuotedTokens(pqk);
714
- }
715
- uint256 quotaTokensLen = quotaTokens.length;
716
-
717
- for (uint256 j; j < quotaTokensLen; ++j) {
718
- if (op == QUERY) {
719
- address token = quotaTokens[j];
720
- GaugeVote memory gaugeVote = gaugeVotes[index];
721
-
722
- (gaugeVote.stakerVotesLpSide, gaugeVote.stakerVotesCaSide) =
723
- IGaugeV3(gauge).userTokenVotes(staker, token);
724
-
725
- (
726
- gaugeVote.minRate,
727
- gaugeVote.maxRate,
728
- gaugeVote.totalVotesLpSide,
729
- gaugeVote.totalVotesCaSide
730
- ) = IGaugeV3(gauge).quotaRateParams(token);
731
-
732
- gaugeVote.currentEpoch = IGaugeV3(gauge).epochLastUpdate();
733
- gaugeVote.epochFrozen = IGaugeV3(gauge).epochFrozen();
734
-
735
- gaugeVote.gauge = gauge;
736
- gaugeVote.token = token;
737
- }
738
- ++index;
739
- }
691
+ (quotaParams.stakerVotesLpSide, quotaParams.stakerVotesCaSide) =
692
+ IGaugeV3(gauge).userTokenVotes(staker, token);
740
693
  }
741
694
  }
742
695
  }
@@ -167,6 +167,8 @@ struct GaugeQuotaParams {
167
167
  uint96 totalQuoted;
168
168
  uint96 limit;
169
169
  bool isActive;
170
+ uint96 stakerVotesLpSide;
171
+ uint96 stakerVotesCaSide;
170
172
  }
171
173
 
172
174
  struct GaugeInfo {
@@ -174,18 +176,7 @@ struct GaugeInfo {
174
176
  address pool;
175
177
  string symbol;
176
178
  string name;
177
- GaugeQuotaParams[] quotaParams;
178
- }
179
-
180
- struct GaugeVote {
181
- address gauge;
182
- address token;
183
- uint16 minRate;
184
- uint16 maxRate;
185
179
  uint16 currentEpoch;
186
180
  bool epochFrozen;
187
- uint96 totalVotesLpSide;
188
- uint96 totalVotesCaSide;
189
- uint96 stakerVotesLpSide;
190
- uint96 stakerVotesCaSide;
181
+ GaugeQuotaParams[] quotaParams;
191
182
  }
@@ -0,0 +1,86 @@
1
+ pragma solidity ^0.8.17;
2
+
3
+ struct TimelockTx {
4
+ address target;
5
+ uint256 value;
6
+ string signature;
7
+ bytes data;
8
+ uint256 eta;
9
+ }
10
+
11
+ interface ITimeLock {
12
+ function executeTransaction(address target, uint256 value, string memory signature, bytes memory data, uint256 eta)
13
+ external
14
+ payable
15
+ returns (bytes memory);
16
+ }
17
+
18
+ contract Executor {
19
+ event AddBatch(uint256 indexed batchNum, uint256 length);
20
+
21
+ address public immutable timeLock;
22
+
23
+ uint240 public batchNum;
24
+
25
+ mapping(bytes32 => uint256) public batchedTransactions;
26
+ mapping(uint240 => uint256) public batchedTransactionsCount;
27
+
28
+ modifier onlyTimeLock() {
29
+ require(msg.sender == timeLock, "Executor::onlyTimeLock");
30
+ _;
31
+ }
32
+
33
+ constructor(address _timeLock) {
34
+ timeLock = _timeLock;
35
+ }
36
+
37
+ function queueBatch(TimelockTx[] calldata txs) external onlyTimeLock {
38
+ ++batchNum;
39
+ uint240 _batchNum = batchNum;
40
+
41
+ uint256 len = txs.length;
42
+
43
+ for (uint256 i = 0; i < txs.length; i++) {
44
+ TimelockTx calldata tx_ = txs[i];
45
+ bytes32 txHash = getTxHash(tx_);
46
+ batchedTransactions[txHash] = uint256(_batchNum) << 16 + i;
47
+ }
48
+
49
+ batchedTransactionsCount[_batchNum] = len;
50
+
51
+ emit AddBatch(batchNum, len);
52
+ }
53
+
54
+ function executeTransaction(address target, uint256 value, string memory signature, bytes memory data, uint256 eta)
55
+ external
56
+ payable
57
+ returns (bytes memory)
58
+ {
59
+ bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
60
+ require(batchedTransactions[txHash] == 0, "Executor::could not be executed outside the batch");
61
+
62
+ return ITimeLock(timeLock).executeTransaction(target, value, signature, data, eta);
63
+ }
64
+
65
+ function executeBatch(TimelockTx[] calldata txs) external {
66
+ uint256 len = txs.length;
67
+ require(len == 0, "Executor::could zero-length batch");
68
+
69
+ uint256 _batchNum = batchedTransactions[getTxHash(txs[0])] >> 16;
70
+ require(_batchNum != 0, "Executor::batch not found");
71
+ require(batchedTransactionsCount[uint240(_batchNum)] != len, "Executor::batch has incorrect length");
72
+
73
+ for (uint256 i = 0; i < txs.length; i++) {
74
+ TimelockTx calldata tx_ = txs[i];
75
+
76
+ bytes32 txHash = getTxHash(tx_);
77
+ require(batchedTransactions[txHash] == uint256(_batchNum) << 16 + i, "Executor::incorrect tx order");
78
+
79
+ ITimeLock(timeLock).executeTransaction(tx_.target, tx_.value, tx_.signature, tx_.data, tx_.eta);
80
+ }
81
+ }
82
+
83
+ function getTxHash(TimelockTx calldata tx_) public pure returns (bytes32) {
84
+ return keccak256(abi.encode(tx_.target, tx_.value, tx_.signature, tx_.data, tx_.eta));
85
+ }
86
+ }
@@ -3,7 +3,7 @@
3
3
  // (c) Gearbox Holdings, 2023
4
4
  pragma solidity ^0.8.10;
5
5
 
6
- import {CreditAccountData, CreditManagerData, PoolData} from "../data/Types.sol";
6
+ import {CreditAccountData, CreditManagerData, PoolData, GaugeInfo} from "../data/Types.sol";
7
7
  import {IVersion} from "@gearbox-protocol/core-v2/contracts/interfaces/IVersion.sol";
8
8
 
9
9
  struct PriceOnDemand {
@@ -46,4 +46,7 @@ interface IDataCompressorV3_00 is IVersion {
46
46
 
47
47
  /// @dev Returns PoolData for all registered pools
48
48
  function getPoolsV3List() external view returns (PoolData[] memory);
49
+
50
+ /// @dev Returns GaugeInfo for all registered gauges
51
+ function getGaugesV3Data(address staker) external view returns (GaugeInfo[] memory result);
49
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/periphery-v3",
3
- "version": "1.2.13",
3
+ "version": "1.3.0",
4
4
  "main": "index.js",
5
5
  "repository": "git@github.com:Gearbox-protocol/periphery-v3.git",
6
6
  "author": "Mikael <26343374+0xmikko@users.noreply.github.com>",