Skip to content

Commit 0e76205

Browse files
committed
refactor: change registration process by adding collateral management for liquidity providers and sending assets to collateral contract
1 parent 77de69c commit 0e76205

1 file changed

Lines changed: 34 additions & 6 deletions

File tree

contracts/FlyoverDiscovery.sol

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ contract FlyoverDiscovery is
5858
Flyover.ProviderType providerType
5959
) external payable returns (uint) {
6060

61-
_validateRegistration(name, apiBaseUrl, providerType, msg.sender);
61+
_validateRegistration(name, apiBaseUrl, providerType, msg.sender, msg.value);
6262

6363
++lastProviderId;
6464
_liquidityProviders[lastProviderId] = Flyover.LiquidityProvider({
@@ -69,6 +69,7 @@ contract FlyoverDiscovery is
6969
status: status,
7070
providerType: providerType
7171
});
72+
_addCollateral(providerType, msg.sender, msg.value);
7273
emit Register(lastProviderId, msg.sender, msg.value);
7374
return (lastProviderId);
7475
}
@@ -161,6 +162,23 @@ contract FlyoverDiscovery is
161162
// FlyoverDiscovery Private Functions
162163
// ------------------------------------------------------------
163164

165+
function _addCollateral(
166+
Flyover.ProviderType providerType,
167+
address providerAddress,
168+
uint256 collateralAmount
169+
) private {
170+
if (providerType == Flyover.ProviderType.PegIn) {
171+
_collateralManagement.addPegInCollateralTo{value: collateralAmount}(providerAddress);
172+
} else if (providerType == Flyover.ProviderType.PegOut) {
173+
_collateralManagement.addPegOutCollateralTo{value: collateralAmount}(providerAddress);
174+
} else if (providerType == Flyover.ProviderType.Both) {
175+
uint256 halfAmount = collateralAmount / 2;
176+
uint256 remainder = collateralAmount % 2;
177+
_collateralManagement.addPegInCollateralTo{value: halfAmount + remainder}(providerAddress);
178+
_collateralManagement.addPegOutCollateralTo{value: halfAmount}(providerAddress);
179+
}
180+
}
181+
164182
function _shouldBeListed(Flyover.LiquidityProvider storage lp) private view returns(bool){
165183
return _collateralManagement.isRegistered(lp.providerType, lp.providerAddress) && lp.status;
166184
}
@@ -169,7 +187,8 @@ contract FlyoverDiscovery is
169187
string memory name,
170188
string memory apiBaseUrl,
171189
Flyover.ProviderType providerType,
172-
address providerAddress
190+
address providerAddress,
191+
uint256 collateralAmount
173192
) private view {
174193
if (providerAddress != msg.sender || providerAddress.code.length != 0) revert NotEOA(providerAddress);
175194

@@ -182,16 +201,25 @@ contract FlyoverDiscovery is
182201

183202
if (providerType > type(Flyover.ProviderType).max) revert InvalidProviderType(providerType);
184203

185-
if (_collateralManagement.isRegistered(providerType, providerAddress)) {
204+
if (
205+
_collateralManagement.getPegInCollateral(providerAddress) > 0 ||
206+
_collateralManagement.getPegOutCollateral(providerAddress) > 0 ||
207+
_collateralManagement.getResignationBlock(providerAddress) != 0
208+
) {
186209
revert AlreadyRegistered(providerAddress);
187210
}
188211

189212
// Check minimum collateral requirement
190-
uint256 requiredCollateral = _collateralManagement.getMinCollateral();
213+
uint256 minCollateral = _collateralManagement.getMinCollateral();
191214
if (providerType == Flyover.ProviderType.Both) {
192-
requiredCollateral = requiredCollateral * 2;
215+
if (collateralAmount < minCollateral * 2) {
216+
revert InsufficientCollateral(collateralAmount);
217+
}
218+
} else {
219+
if (collateralAmount < minCollateral) {
220+
revert InsufficientCollateral(collateralAmount);
221+
}
193222
}
194-
if (msg.value < requiredCollateral) revert InsufficientCollateral(msg.value);
195223
}
196224

197225
function _getProvider(address providerAddress) private view returns (Flyover.LiquidityProvider memory) {

0 commit comments

Comments
 (0)