Skip to content

Commit 8cda64a

Browse files
committed
refactor: move QuotesV2 to legacy directory
1 parent a97f51f commit 8cda64a

File tree

12 files changed

+257
-81
lines changed

12 files changed

+257
-81
lines changed

.solhint.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"comprehensive-interface": "error",
2727
"explicit-types": "off",
2828

29-
3029
"use-natspec": "off"
3130
}
3231
}

contracts/interfaces/Legacy.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.25;
3+
4+
import {QuotesV2} from "../legacy/QuotesV2.sol";
5+
6+
interface ILegacyLiquidityBridgeContract {
7+
function register(
8+
string memory name,
9+
string memory apiBaseUrl,
10+
bool status,
11+
string memory providerType
12+
) external payable returns (uint);
13+
14+
function depositPegout(
15+
QuotesV2.PegOutQuote memory quote,
16+
bytes memory signature
17+
) external payable;
18+
}

contracts/legacy/LiquidityBridgeContract.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pragma solidity 0.8.25;
33
pragma experimental ABIEncoderV2;
44

55
import "../interfaces/Bridge.sol";
6-
import "../legacy/Quotes.sol";
6+
import "./Quotes.sol";
77
import "../libraries/SignatureValidator.sol";
88
import "@rsksmart/btc-transaction-solidity-helper/contracts/BtcUtils.sol";
99
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

contracts/legacy/LiquidityBridgeContractV2.sol

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pragma solidity 0.8.25;
33
pragma experimental ABIEncoderV2;
44

55
import "../interfaces/Bridge.sol";
6-
import "../libraries/QuotesV2.sol";
6+
import "./QuotesV2.sol";
77
import "../libraries/SignatureValidator.sol";
88
import "@rsksmart/btc-transaction-solidity-helper/contracts/BtcUtils.sol";
99
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
@@ -373,7 +373,7 @@ contract LiquidityBridgeContractV2 is OwnableUpgradeable, ReentrancyGuardUpgrade
373373
@return Boolean indicating whether the call was successful
374374
*/
375375
function callForUser(
376-
QuotesV2.PegInQuote memory quote
376+
QuotesV2.PeginQuote memory quote
377377
) external payable onlyRegistered nonReentrant returns (bool) {
378378
require(
379379
msg.sender == quote.liquidityProviderRskAddress,
@@ -433,7 +433,7 @@ contract LiquidityBridgeContractV2 is OwnableUpgradeable, ReentrancyGuardUpgrade
433433
@return The total peg-in amount received from the bridge contract or an error code
434434
*/
435435
function registerPegIn(
436-
QuotesV2.PegInQuote memory quote,
436+
QuotesV2.PeginQuote memory quote,
437437
bytes memory signature,
438438
bytes memory btcRawTransaction,
439439
bytes memory partialMerkleTree,
@@ -710,7 +710,7 @@ contract LiquidityBridgeContractV2 is OwnableUpgradeable, ReentrancyGuardUpgrade
710710
outputs[PAY_TO_ADDRESS_OUTPUT].pkScript,
711711
mainnet
712712
);
713-
require(keccak256(quote.depositAddress) == keccak256(btcTxDestination), "LBC068");
713+
require(keccak256(quote.deposityAddress) == keccak256(btcTxDestination), "LBC068");
714714

715715
if (
716716
shouldPenalizePegOutLP(
@@ -740,7 +740,7 @@ contract LiquidityBridgeContractV2 is OwnableUpgradeable, ReentrancyGuardUpgrade
740740
}
741741

742742
function validatePeginDepositAddress(
743-
QuotesV2.PegInQuote memory quote,
743+
QuotesV2.PeginQuote memory quote,
744744
bytes memory depositAddress
745745
) external view returns (bool) {
746746
bytes32 derivationValue = keccak256(
@@ -765,7 +765,7 @@ contract LiquidityBridgeContractV2 is OwnableUpgradeable, ReentrancyGuardUpgrade
765765
@param quote The quote of the service
766766
@return The hash of a quote
767767
*/
768-
function hashQuote(QuotesV2.PegInQuote memory quote) public view returns (bytes32) {
768+
function hashQuote(QuotesV2.PeginQuote memory quote) public view returns (bytes32) {
769769
return validateAndHashQuote(quote);
770770
}
771771

@@ -776,7 +776,7 @@ contract LiquidityBridgeContractV2 is OwnableUpgradeable, ReentrancyGuardUpgrade
776776
}
777777

778778
function validateAndHashQuote(
779-
QuotesV2.PegInQuote memory quote
779+
QuotesV2.PeginQuote memory quote
780780
) private view returns (bytes32) {
781781
require(address(this) == quote.lbcAddress, "LBC051");
782782
require(
@@ -849,7 +849,7 @@ contract LiquidityBridgeContractV2 is OwnableUpgradeable, ReentrancyGuardUpgrade
849849
@return The total peg-in amount received from the bridge contract or an error code
850850
*/
851851
function registerBridge(
852-
QuotesV2.PegInQuote memory quote,
852+
QuotesV2.PeginQuote memory quote,
853853
bytes memory btcRawTransaction,
854854
bytes memory partialMerkleTree,
855855
uint256 height,
@@ -877,7 +877,7 @@ contract LiquidityBridgeContractV2 is OwnableUpgradeable, ReentrancyGuardUpgrade
877877
@return Boolean indicating whether the penalty applies
878878
*/
879879
function shouldPenalizeLP(
880-
QuotesV2.PegInQuote memory quote,
880+
QuotesV2.PeginQuote memory quote,
881881
int256 amount,
882882
uint256 callTimestamp,
883883
uint256 height
Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,85 +2,67 @@
22
pragma solidity 0.8.25;
33

44
library QuotesV2 {
5-
struct PegInQuote {
6-
uint256 callFee;
7-
uint256 penaltyFee;
8-
uint256 value;
9-
uint256 productFeeAmount;
10-
uint256 gasFee;
5+
struct PeginQuote {
116
bytes20 fedBtcAddress;
127
address lbcAddress;
138
address liquidityProviderRskAddress;
14-
address contractAddress;
9+
bytes btcRefundAddress;
1510
address payable rskRefundAddress;
16-
int64 nonce;
11+
bytes liquidityProviderBtcAddress;
12+
uint256 callFee;
13+
uint256 penaltyFee;
14+
address contractAddress;
15+
bytes data;
1716
uint32 gasLimit;
17+
int64 nonce;
18+
uint256 value;
1819
uint32 agreementTimestamp;
1920
uint32 timeForDeposit;
2021
uint32 callTime;
2122
uint16 depositConfirmations;
2223
bool callOnRegister;
23-
bytes btcRefundAddress;
24-
bytes liquidityProviderBtcAddress;
25-
bytes data;
24+
uint256 productFeeAmount;
25+
uint256 gasFee;
2626
}
2727

2828
struct PegOutQuote {
29+
address lbcAddress;
30+
address lpRskAddress;
31+
bytes btcRefundAddress;
32+
address rskRefundAddress;
33+
bytes lpBtcAddress;
2934
uint256 callFee;
3035
uint256 penaltyFee;
36+
int64 nonce;
37+
bytes deposityAddress;
3138
uint256 value;
39+
uint32 agreementTimestamp;
40+
uint32 depositDateLimit;
41+
uint16 depositConfirmations;
42+
uint16 transferConfirmations;
43+
uint32 transferTime;
44+
uint32 expireDate;
45+
uint32 expireBlock;
3246
uint256 productFeeAmount;
3347
uint256 gasFee;
34-
address lbcAddress;
35-
address lpRskAddress;
36-
address rskRefundAddress;
37-
int64 nonce;
38-
uint32 agreementTimestamp;
39-
uint32 depositDateLimit;
40-
uint32 transferTime;
41-
uint32 expireDate;
42-
uint32 expireBlock;
43-
uint16 depositConfirmations;
44-
uint16 transferConfirmations;
45-
bytes depositAddress;
46-
bytes btcRefundAddress;
47-
bytes lpBtcAddress;
48-
}
49-
50-
error AmountTooLow(uint256 value, uint256 target);
51-
52-
function checkAgreedAmount(
53-
PegInQuote calldata quote,
54-
uint transferredAmount
55-
) external pure {
56-
uint agreedAmount = 0;
57-
agreedAmount = quote.value + quote.callFee + quote.productFeeAmount + quote.gasFee;
58-
59-
60-
uint delta = agreedAmount / 10000;
61-
// transferred amount should not be lower than (agreed amount - delta),
62-
// where delta is intended to tackle rounding problems
63-
if (agreedAmount - delta > transferredAmount) {
64-
revert AmountTooLow(transferredAmount, agreedAmount - delta);
65-
}
6648
}
6749

6850
function encodeQuote(
69-
PegInQuote calldata quote
51+
PeginQuote memory quote
7052
) external pure returns (bytes memory) {
7153
// Encode in two parts because abi.encode cannot take more than 12 parameters due to stack depth limits.
72-
return abi.encode(_encodePart1(quote), _encodePart2(quote));
54+
return abi.encode(encodePart1(quote), encodePart2(quote));
7355
}
7456

7557
function encodePegOutQuote(
76-
PegOutQuote calldata quote
58+
PegOutQuote memory quote
7759
) external pure returns (bytes memory) {
7860
// Encode in two parts because abi.encode cannot take more than 12 parameters due to stack depth limits.
79-
return abi.encode(_encodePegOutPart1(quote), _encodePegOutPart2(quote));
61+
return abi.encode(encodePegOutPart1(quote), encodePegOutPart2(quote));
8062
}
8163

82-
function _encodePart1(
83-
PegInQuote calldata quote
64+
function encodePart1(
65+
PeginQuote memory quote
8466
) private pure returns (bytes memory) {
8567
return
8668
abi.encode(
@@ -96,8 +78,8 @@ library QuotesV2 {
9678
);
9779
}
9880

99-
function _encodePart2(
100-
PegInQuote calldata quote
81+
function encodePart2(
82+
PeginQuote memory quote
10183
) private pure returns (bytes memory) {
10284
return
10385
abi.encode(
@@ -115,8 +97,8 @@ library QuotesV2 {
11597
);
11698
}
11799

118-
function _encodePegOutPart1(
119-
PegOutQuote calldata quote
100+
function encodePegOutPart1(
101+
PegOutQuote memory quote
120102
) private pure returns (bytes memory) {
121103
return
122104
abi.encode(
@@ -128,12 +110,12 @@ library QuotesV2 {
128110
quote.callFee,
129111
quote.penaltyFee,
130112
quote.nonce,
131-
quote.depositAddress
113+
quote.deposityAddress
132114
);
133115
}
134116

135-
function _encodePegOutPart2(
136-
PegOutQuote calldata quote
117+
function encodePegOutPart2(
118+
PegOutQuote memory quote
137119
) private pure returns (bytes memory) {
138120
return
139121
abi.encode(
@@ -149,4 +131,22 @@ library QuotesV2 {
149131
quote.gasFee
150132
);
151133
}
134+
135+
function checkAgreedAmount(
136+
PeginQuote memory quote,
137+
uint transferredAmount
138+
) external pure {
139+
uint agreedAmount = 0;
140+
agreedAmount = quote.value + quote.callFee + quote.productFeeAmount + quote.gasFee;
141+
142+
143+
uint delta = agreedAmount / 10000;
144+
// transferred amount should not be lower than (agreed amount - delta),
145+
// where delta is intended to tackle rounding problems
146+
require(
147+
transferredAmount >= agreedAmount - delta,
148+
"LBC057"
149+
);
150+
}
151+
152152
}

0 commit comments

Comments
 (0)