22pragma solidity 0.8.25 ;
33
44library 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