-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathQuotes.sol
More file actions
141 lines (131 loc) · 4.13 KB
/
Quotes.sol
File metadata and controls
141 lines (131 loc) · 4.13 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
library Quotes {
struct PeginQuote {
bytes20 fedBtcAddress;
address lbcAddress;
address liquidityProviderRskAddress;
bytes btcRefundAddress;
address payable rskRefundAddress;
bytes liquidityProviderBtcAddress;
uint256 callFee;
uint256 penaltyFee;
address contractAddress;
bytes data;
uint32 gasLimit;
int64 nonce;
uint256 value;
uint32 agreementTimestamp;
uint32 timeForDeposit;
uint32 callTime;
uint16 depositConfirmations;
bool callOnRegister;
}
struct PegOutQuote {
address lbcAddress;
address lpRskAddress;
bytes btcRefundAddress;
address rskRefundAddress;
bytes lpBtcAddress;
uint256 callFee;
uint256 penaltyFee;
int64 nonce;
bytes deposityAddress;
uint256 value;
uint32 agreementTimestamp;
uint32 depositDateLimit;
uint16 depositConfirmations;
uint16 transferConfirmations;
uint32 transferTime;
uint32 expireDate;
uint32 expireBlock;
}
function encodeQuote(
PeginQuote memory quote
) external pure returns (bytes memory) {
// Encode in two parts because abi.encode cannot take more than 12 parameters due to stack depth limits.
return abi.encode(encodePart1(quote), encodePart2(quote));
}
function encodePegOutQuote(
PegOutQuote memory quote
) external pure returns (bytes memory) {
// Encode in two parts because abi.encode cannot take more than 12 parameters due to stack depth limits.
return abi.encode(encodePegOutPart1(quote), encodePegOutPart2(quote));
}
function encodePart1(
PeginQuote memory quote
) private pure returns (bytes memory) {
return
abi.encode(
quote.fedBtcAddress,
quote.lbcAddress,
quote.liquidityProviderRskAddress,
quote.btcRefundAddress,
quote.rskRefundAddress,
quote.liquidityProviderBtcAddress,
quote.callFee,
quote.penaltyFee,
quote.contractAddress
);
}
function encodePart2(
PeginQuote memory quote
) private pure returns (bytes memory) {
return
abi.encode(
quote.data,
quote.gasLimit,
quote.nonce,
quote.value,
quote.agreementTimestamp,
quote.timeForDeposit,
quote.callTime,
quote.depositConfirmations,
quote.callOnRegister
);
}
function encodePegOutPart1(
PegOutQuote memory quote
) private pure returns (bytes memory) {
return
abi.encode(
quote.lbcAddress,
quote.lpRskAddress,
quote.btcRefundAddress,
quote.rskRefundAddress,
quote.lpBtcAddress,
quote.callFee,
quote.penaltyFee,
quote.nonce,
quote.deposityAddress
);
}
function encodePegOutPart2(
PegOutQuote memory quote
) private pure returns (bytes memory) {
return
abi.encode(
quote.value,
quote.agreementTimestamp,
quote.depositDateLimit,
quote.depositConfirmations,
quote.transferConfirmations,
quote.transferTime,
quote.expireDate,
quote.expireBlock
);
}
function checkAgreedAmount(
PeginQuote memory quote,
uint transferredAmount
) external pure {
uint agreedAmount = quote.value + quote.callFee;
uint delta = agreedAmount / 10000;
// transferred amount should not be lower than (agreed amount - delta),
// where delta is intended to tackle rounding problems
require(
transferredAmount >= agreedAmount - delta,
"LBC057"
);
}
}