Skip to content

Commit 3bf911c

Browse files
authored
Merge pull request #5 from flare-foundation/feat/fassets-core-vault
0.1.25: Add Core Vault functionality for FAssets
2 parents c449500 + 152e6dd commit 3bf911c

15 files changed

+835
-13
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.7.6 <0.9;
3+
4+
5+
interface IAgentAlwaysAllowedMinters {
6+
function addAlwaysAllowedMinterForAgent(address _agentVault, address _minter)
7+
external;
8+
9+
function removeAlwaysAllowedMinterForAgent(address _agentVault, address _minter)
10+
external;
11+
12+
function alwaysAllowedMintersForAgent(address _agentVault)
13+
external view
14+
returns (address[] memory);
15+
}

coston/IAssetManager.sol

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ import "./userInterfaces/data/AgentInfo.sol";
1010
import "./userInterfaces/data/AgentSettings.sol";
1111
import "./userInterfaces/data/AvailableAgentInfo.sol";
1212
import "./userInterfaces/data/RedemptionTicketInfo.sol";
13+
import "./userInterfaces/data/RedemptionRequestInfo.sol";
14+
import "./userInterfaces/data/CollateralReservationInfo.sol";
1315
import "./IAssetManagerEvents.sol";
1416
import "./IAgentPing.sol";
1517
import "./IRedemptionTimeExtension.sol";
1618
import "./ITransferFees.sol";
19+
import "./ICoreVault.sol";
20+
import "./ICoreVaultSettings.sol";
21+
import "./IAgentAlwaysAllowedMinters.sol";
1722

1823

1924
/**
@@ -25,7 +30,10 @@ interface IAssetManager is
2530
IAssetManagerEvents,
2631
IAgentPing,
2732
IRedemptionTimeExtension,
28-
ITransferFees
33+
ITransferFees,
34+
ICoreVault,
35+
ICoreVaultSettings,
36+
IAgentAlwaysAllowedMinters
2937
{
3038
////////////////////////////////////////////////////////////////////////////////////
3139
// Basic system information
@@ -284,6 +292,8 @@ interface IAssetManager is
284292
* Due to the effect on the pool, all agent settings are timelocked.
285293
* This method announces a setting change. The change can be executed after the timelock expires.
286294
* NOTE: may only be called by the agent vault owner.
295+
* @param _agentVault agent vault address
296+
* @param _name setting name, same as for `getAgentSetting`
287297
* @return _updateAllowedAt the timestamp at which the update can be executed
288298
*/
289299
function announceAgentSettingUpdate(
@@ -297,6 +307,8 @@ interface IAssetManager is
297307
* Due to the effect on the pool, all agent settings are timelocked.
298308
* This method executes a setting change after the timelock expires.
299309
* NOTE: may only be called by the agent vault owner.
310+
* @param _agentVault agent vault address
311+
* @param _name setting name, same as for `getAgentSetting`
300312
*/
301313
function executeAgentSettingUpdate(
302314
address _agentVault,
@@ -455,6 +467,19 @@ interface IAssetManager is
455467
external view
456468
returns (AgentInfo.Info memory);
457469

470+
/**
471+
* Get agent's setting by name.
472+
* This allows reading individual settings.
473+
* @param _agentVault agent vault address
474+
* @param _name setting name, one of: `feeBIPS`, `poolFeeShareBIPS`, `redemptionPoolFeeShareBIPS`,
475+
* `mintingVaultCollateralRatioBIPS`, `mintingPoolCollateralRatioBIPS`,`buyFAssetByAgentFactorBIPS`,
476+
* `poolExitCollateralRatioBIPS`, `poolTopupCollateralRatioBIPS`, `poolTopupTokenPriceFactorBIPS`,
477+
* `handshakeType`
478+
*/
479+
function getAgentSetting(address _agentVault, string memory _name)
480+
external view
481+
returns (uint256);
482+
458483
/**
459484
* Returns the collateral pool address of the agent identified by `_agentVault`.
460485
*/
@@ -638,17 +663,26 @@ interface IAssetManager is
638663

639664
/**
640665
* Return the collateral reservation fee amount that has to be passed to the `reserveCollateral` method.
641-
* NOTE: the *exact* amount of the collateral fee must be paid. Even if the amount paid in `reserveCollateral` is
642-
* more than required, the transaction will revert. This is intentional to protect the minter from accidentally
643-
* overpaying, but may cause unexpected reverts if the FTSO prices get published between calls to
644-
* `collateralReservationFee` and `reserveCollateral`.
666+
* NOTE: the amount paid may be larger than the required amount, but the difference is not returned.
667+
* It is advised that the minter pays the exact amount, but when the amount is so small that the revert
668+
* would cost more than the lost difference, the minter may want to send a slightly larger amount to compensate
669+
* for the possibility of a FTSO price change between obtaining this value and calling `reserveCollateral`.
645670
* @param _lots the number of lots for which to reserve collateral
646671
* @return _reservationFeeNATWei the amount of reservation fee in NAT wei
647672
*/
648673
function collateralReservationFee(uint256 _lots)
649674
external view
650675
returns (uint256 _reservationFeeNATWei);
651676

677+
/**
678+
* Returns the data about the collateral reservation for an ongoing minting.
679+
* Note: once the minting is executed or defaulted, the collateral reservation is deleted and this method fails.
680+
* @param _collateralReservationId the collateral reservation id, as used for executing or defaulting the minting
681+
*/
682+
function collateralReservationInfo(uint256 _collateralReservationId)
683+
external view
684+
returns (CollateralReservationInfo.Data memory);
685+
652686
/**
653687
* After obtaining proof of underlying payment, the minter calls this method to finish the minting
654688
* and collect the minted f-assets.
@@ -859,6 +893,16 @@ interface IAssetManager is
859893
uint256 _redemptionRequestId
860894
) external;
861895

896+
/**
897+
* Returns the data about an ongoing redemption request.
898+
* Note: once the redemptions is confirmed, the request is deleted and this method fails.
899+
* However, if there is no payment and the redemption defaults, the method works and returns status DEFAULTED.
900+
* @param _redemptionRequestId the redemption request id, as used for confirming or defaulting the redemption
901+
*/
902+
function redemptionRequestInfo(uint256 _redemptionRequestId)
903+
external view
904+
returns (RedemptionRequestInfo.Data memory);
905+
862906
/**
863907
* Agent can "redeem against himself" by calling `selfClose`, which burns agent's own f-assets
864908
* and unlocks agent's collateral. The underlying funds backing the f-assets are released
@@ -876,7 +920,7 @@ interface IAssetManager is
876920
returns (uint256 _closedAmountUBA);
877921

878922
////////////////////////////////////////////////////////////////////////////////////
879-
// Redemption info
923+
// Redemption queue info
880924

881925
/**
882926
* Return (part of) the redemption queue.

coston/IAssetManagerEvents.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,15 @@ interface IAssetManagerEvents {
319319
int256 spentUnderlyingUBA,
320320
string failureReason);
321321

322+
/**
323+
* At the end of a successful redemption, part of the redemption fee is re-minted as FAssets
324+
* and paid to the agent's collateral pool as fee.
325+
*/
326+
event RedemptionPoolFeeMinted(
327+
address indexed agentVault,
328+
uint64 indexed requestId,
329+
uint256 poolFeeUBA);
330+
322331
/**
323332
* Due to self-close exit, some of the agent's backed fAssets were redeemed,
324333
* but the redemption was immediately paid in collateral so no redemption process is started.

coston/ICoreVault.sol

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.7.6 <0.9;
3+
4+
import "./IFdcVerification.sol";
5+
6+
7+
/**
8+
* Core vault
9+
*/
10+
interface ICoreVault {
11+
/**
12+
* Agent has requested transfer of (some of) their backing to the core vault.
13+
*/
14+
event TransferToCoreVaultStarted(
15+
address indexed agentVault,
16+
uint256 indexed transferRedemptionRequestId,
17+
uint256 valueUBA);
18+
19+
/**
20+
* Agent has cancelled transfer to the core vault without paying.
21+
* The amount of `valueUBA` has been re-minted./
22+
*/
23+
event TransferToCoreVaultDefaulted(
24+
address indexed agentVault,
25+
uint256 indexed transferRedemptionRequestId,
26+
uint256 remintedUBA);
27+
28+
/**
29+
* The transfer of underlying to the core vault was successfully completed.
30+
*/
31+
event TransferToCoreVaultSuccessful(
32+
address indexed agentVault,
33+
uint256 indexed transferRedemptionRequestId,
34+
uint256 valueUBA);
35+
36+
/**
37+
* The agent has requested return of some of the underlying from the core vault to the agent's underlying address.
38+
*/
39+
event ReturnFromCoreVaultRequested(
40+
address indexed agentVault,
41+
uint256 indexed requestId,
42+
bytes32 paymentReference,
43+
uint256 valueUBA);
44+
45+
/**
46+
* The agent has cancelled the return request.
47+
*/
48+
event ReturnFromCoreVaultCancelled(
49+
address indexed agentVault,
50+
uint256 indexed requestId);
51+
52+
/**
53+
* The payment from core vault to the agent's underlying address has been confirmed.
54+
*/
55+
event ReturnFromCoreVaultConfirmed(
56+
address indexed agentVault,
57+
uint256 indexed requestId,
58+
uint256 receivedUnderlyingUBA,
59+
uint256 remintedUBA);
60+
61+
/**
62+
* Redemption was requested from a core vault.
63+
* Can only be redeemed to a payment address from to the `allowedDestinations` list in the core vault manager.
64+
*/
65+
event CoreVaultRedemptionRequested(
66+
address indexed redeemer,
67+
string paymentAddress,
68+
bytes32 paymentReference,
69+
uint256 valueUBA,
70+
uint256 feeUBA);
71+
72+
/**
73+
* Agent can transfer their backing to core vault.
74+
* They then get a redemption requests which the owner pays just like any other redemption request.
75+
* After that, the agent's collateral is released.
76+
* NOTE: only agent vault owner can call
77+
* @param _agentVault the agent vault address
78+
* @param _amountUBA the amount to transfer to the core vault
79+
*/
80+
function transferToCoreVault(address _agentVault, uint256 _amountUBA)
81+
external payable;
82+
83+
/**
84+
* Request that core vault transfers funds to the agent's underlying address,
85+
* which makes them available for redemptions. This method reserves agent's collateral.
86+
* This may be sent by an agent when redemptions dominate mintings, so that the agents
87+
* are empty but want to earn from redemptions.
88+
* NOTE: only agent vault owner can call
89+
* NOTE: there can be only one active return request (until it is confirmed or cancelled).
90+
* @param _agentVault the agent vault address
91+
* @param _lots number of lots (same lots as for minting and redemptions)
92+
*/
93+
function requestReturnFromCoreVault(address _agentVault, uint64 _lots)
94+
external;
95+
96+
/**
97+
* Before the return request is processed, it can be cancelled, releasing the agent's reserved collateral.
98+
* @param _agentVault the agent vault address
99+
*/
100+
function cancelReturnFromCoreVault(address _agentVault)
101+
external;
102+
103+
/**
104+
* Confirm the payment from core vault to the agent's underlying address.
105+
* This adds the reserved funds to the agent's backing.
106+
* @param _payment FDC payment proof
107+
* @param _agentVault the agent vault address
108+
*/
109+
function confirmReturnFromCoreVault(IPayment.Proof calldata _payment, address _agentVault)
110+
external;
111+
112+
/**
113+
* Directly redeem from core vault by a user holding FAssets.
114+
* This is like ordinary redemption, but the redemption time is much longer (a day or more)
115+
* and there is no possibility of redemption default.
116+
* @param _lots the number of lots, must be larger than `coreVaultMinimumRedeemLots` setting
117+
* @param _redeemerUnderlyingAddress the underlying address to which the assets will be redeemed;
118+
* must have been added to the `allowedDestinations` list in the core vault manager by
119+
* the governance before the redemption request.
120+
*/
121+
function redeemFromCoreVault(uint64 _lots, string memory _redeemerUnderlyingAddress)
122+
external;
123+
124+
/**
125+
* Return the amount of NAT that has to be paid in `transferToCoreVault` call.
126+
* @param _amountUBA the amount to transfer to the core vault
127+
* @return _transferFeeNatWei the amount that has to be included as `msg.value` and is paid to the core vault
128+
*/
129+
function transferToCoreVaultFee(
130+
uint256 _amountUBA
131+
) external view
132+
returns (uint256 _transferFeeNatWei);
133+
134+
/**
135+
* Return the maximum amount that can be transferred and the minimum amount that
136+
* has to remain on the agent vault's underlying address.
137+
* @param _agentVault the agent vault address
138+
* @return _maximumTransferUBA maximum amount that can be transferred
139+
* @return _minimumLeftAmountUBA the minimum amount that has to remain on the agent vault's underlying address
140+
* after the transfer
141+
*/
142+
function maximumTransferToCoreVault(
143+
address _agentVault
144+
) external view
145+
returns (uint256 _maximumTransferUBA, uint256 _minimumLeftAmountUBA);
146+
147+
/**
148+
* Returns the amount available on the core vault - this is the maximum amount that can be returned to agent or
149+
* redeemed directly from the core vault.
150+
* @return _immediatelyAvailableUBA the amount on the core vault operating account - returns and redemptions
151+
* within this amount will be paid out quickly
152+
* @return _totalAvailableUBA the total amount on the core vault, including all escrows
153+
*/
154+
function coreVaultAvailableAmount()
155+
external view
156+
returns (uint256 _immediatelyAvailableUBA, uint256 _totalAvailableUBA);
157+
}

coston/ICoreVaultSettings.sol

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.7.6 <0.9;
3+
4+
/**
5+
* Core vault settings
6+
*/
7+
interface ICoreVaultSettings {
8+
function setCoreVaultManager(address _coreVaultManager)
9+
external;
10+
11+
function setCoreVaultNativeAddress(address payable _nativeAddress)
12+
external;
13+
14+
function setCoreVaultTransferFeeBIPS(uint256 _transferFeeBIPS)
15+
external;
16+
17+
function setCoreVaultTransferTimeExtensionSeconds(uint256 _transferTimeExtensionSeconds)
18+
external;
19+
20+
function setCoreVaultRedemptionFeeBIPS(uint256 _redemptionFeeBIPS)
21+
external;
22+
23+
function setCoreVaultMinimumAmountLeftBIPS(uint256 _minimumAmountLeftBIPS)
24+
external;
25+
26+
function setCoreVaultMinimumRedeemLots(uint256 _minimumRedeemLots)
27+
external;
28+
29+
function getCoreVaultManager()
30+
external view
31+
returns (address);
32+
33+
function getCoreVaultNativeAddress()
34+
external view
35+
returns (address);
36+
37+
function getCoreVaultTransferFeeBIPS()
38+
external view
39+
returns (uint256);
40+
41+
function getCoreVaultTransferTimeExtensionSeconds()
42+
external view
43+
returns (uint256);
44+
45+
function getCoreVaultRedemptionFeeBIPS()
46+
external view
47+
returns (uint256);
48+
49+
function getCoreVaultMinimumAmountLeftBIPS()
50+
external view
51+
returns (uint256);
52+
53+
function getCoreVaultMinimumRedeemLots()
54+
external view
55+
returns (uint256);
56+
}

0 commit comments

Comments
 (0)