Skip to content

Commit

Permalink
chore: use type conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
antoncoding committed Jan 3, 2024
1 parent f369fc6 commit 30561ab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 38 deletions.
18 changes: 0 additions & 18 deletions src/libraries/BytesLib.sol

This file was deleted.

17 changes: 8 additions & 9 deletions src/periphery/CompressedSubmitter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.18;

import "openzeppelin/access/Ownable2Step.sol";
import "../libraries/BytesLib.sol";
import "../interfaces/IBaseManager.sol";
import "../interfaces/IDataReceiver.sol";
import "../interfaces/IBaseLyraFeed.sol";
Expand Down Expand Up @@ -54,18 +53,18 @@ contract CompressedSubmitter is IDataReceiver, Ownable2Step {
// first byte of each byte array is number of feeds
uint offset = 0;

uint8 numFeeds = uint8(BytesLib.bytesToUint(data[offset:offset + 1]));
uint8 numFeeds = uint8(bytes1(data[offset:offset + 1]));
offset += 1;

IBaseManager.ManagerData[] memory feedDatas = new IBaseManager.ManagerData[](numFeeds);

for (uint i; i < numFeeds; i++) {
// 1 bytes of ID
uint8 feedId = uint8(BytesLib.bytesToUint(data[offset:offset + 1]));
uint8 feedId = uint8(bytes1(data[offset:offset + 1]));
offset += 1;

// 4 bytes of data length
uint length = BytesLib.bytesToUint(data[offset:offset + 4]);
uint length = uint32(bytes4(data[offset:offset + 4]));
offset += 4;

// [length] bytes of data
Expand Down Expand Up @@ -96,7 +95,7 @@ contract CompressedSubmitter is IDataReceiver, Ownable2Step {
uint offset = 0;

// 4 bytes of data length
uint length = BytesLib.bytesToUint(data[offset:offset + 4]);
uint length = uint32(bytes4(data[offset:offset + 4]));
offset += 4;

// [length] bytes of data
Expand All @@ -108,22 +107,22 @@ contract CompressedSubmitter is IDataReceiver, Ownable2Step {
}

// 8 bytes of deadline
feedData.deadline = uint64(BytesLib.bytesToUint(data[offset:offset + 8]));
feedData.deadline = uint64(bytes8(data[offset:offset + 8]));
offset += 8;

// 8 bytes of timestamp
feedData.timestamp = uint64(BytesLib.bytesToUint(data[offset:offset + 8]));
feedData.timestamp = uint64(bytes8(data[offset:offset + 8]));
offset += 8;

{
// 1 byte of number of signers
uint8 numSigners = uint8(BytesLib.bytesToUint(data[offset:offset + 1]));
uint8 numSigners = uint8(bytes1(data[offset:offset + 1]));
offset += 1;

// [20 x k] bytes of signer addresses;
address[] memory _signers = new address[](numSigners);
for (uint i; i < numSigners; i++) {
_signers[i] = address(uint160(BytesLib.bytesToUint(data[offset:offset + 20])));
_signers[i] = address(uint160(bytes20(data[offset:offset + 20])));
offset += 20;
}
feedData.signers = _signers;
Expand Down
21 changes: 10 additions & 11 deletions src/periphery/VolFeedDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
pragma solidity ^0.8.18;

import "../interfaces/IDecoder.sol";
import "../libraries/BytesLib.sol";

/**
* @dev VolFeedDecoder is for CompressedSubmitter to decode the compressed vol feed data, for LyraVolFeed
*/

contract VolFeedDecoder is IDecoder {
/**
* @dev Decode the compressed vol feed Data
Expand All @@ -18,34 +17,34 @@ contract VolFeedDecoder is IDecoder {
uint offset = 0;

// expires can be fit in uint64
uint64 expiry = uint64(BytesLib.bytesToUint(data[offset:offset + 8]));
uint64 expiry = uint64(bytes8(data[offset:offset + 8]));
offset += 8;

int SVI_a = int80(uint80(BytesLib.bytesToUint(data[offset:offset + 10])));
int SVI_a = int80(uint80(bytes10(data[offset:offset + 10])));
offset += 10;

uint SVI_b = uint(BytesLib.bytesToUint(data[offset:offset + 10]));
uint SVI_b = uint80(bytes10(data[offset:offset + 10]));
offset += 10;

int SVI_rho = int80(uint80(BytesLib.bytesToUint(data[offset:offset + 10])));
int SVI_rho = int80(uint80(bytes10(data[offset:offset + 10])));
offset += 10;

int SVI_m = int80(uint80(BytesLib.bytesToUint(data[offset:offset + 10])));
int SVI_m = int80(uint80(bytes10(data[offset:offset + 10])));
offset += 10;

uint SVI_sigma = uint(BytesLib.bytesToUint(data[offset:offset + 10]));
uint SVI_sigma = uint80(bytes10(data[offset:offset + 10]));
offset += 10;

// extra 2 bytes for forward price
uint SVI_fwd = uint(BytesLib.bytesToUint(data[offset:offset + 12]));
uint SVI_fwd = uint96(bytes12(data[offset:offset + 12]));
offset += 12;

// vol feed can be fit in uint64 (0, 1e18)
uint64 SVI_refTau = uint64(BytesLib.bytesToUint(data[offset:offset + 8]));
uint64 SVI_refTau = uint64(bytes8(data[offset:offset + 8]));
offset += 8;

// confidence is between [0, 1e18]
uint64 confidence = uint64(BytesLib.bytesToUint(data[offset:offset + 8]));
uint64 confidence = uint64(bytes8(data[offset:offset + 8]));

return abi.encode(expiry, SVI_a, SVI_b, SVI_rho, SVI_m, SVI_sigma, SVI_fwd, SVI_refTau, confidence);
}
Expand Down

0 comments on commit 30561ab

Please sign in to comment.