Skip to content

Commit 920e2d8

Browse files
authored
Merge pull request #7 from flare-foundation:0.1.41
Update version to 0.1.41
2 parents b190c87 + 2b04f56 commit 920e2d8

18 files changed

+267
-30
lines changed

foundry.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "flare-periphery"
3-
version = "0.1.40"
3+
version = "0.1.41"
44

55
[profile.default]
66
src = "src"

src/coston/IAssetManager.sol

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ interface IAssetManager is
154154
* to prevent current block being too outdated, which gives too short time for
155155
* minting or redemption payment.
156156
* NOTE: anybody can call.
157+
* NOTE: the block/timestamp will only be updated if it is strictly higher than the current value.
158+
* For mintings and redemptions we also add the duration from the last update (on this chain) to compensate
159+
* for the time that passed since the last update. This mechanism can be abused by providing old block proof
160+
* as fresh, which will distort the compensation accounting. Due to monotonicity such an attack will only work
161+
* if there was no block update for some time. Therefore it is enough to have at least one honest
162+
* current block updater regularly providing updates to avoid this issue.
157163
* @param _proof proof that a block with given number and timestamp exists
158164
*/
159165
function updateCurrentBlock(
@@ -304,17 +310,18 @@ interface IAssetManager is
304310
returns (uint256 _withdrawalAllowedAt);
305311

306312
/**
307-
* The agent is going to redeem `_valueWei` collateral pool tokens in the agent vault.
308-
* This has to be announced and the agent must then wait `withdrawalWaitMinSeconds` time.
309-
* After that time, the agent can call `redeemCollateralPoolTokens(_valueNATWei)` on the agent vault.
313+
* Agent is going to withdraw `_valuePoolTokenWei` of pool tokens from the agent vault
314+
* and redeem them for NAT from the collateral pool.
315+
* This has to be announced and the agent must then wait `withdrawalWaitMinSeconds`.
316+
* After that time, the agent can call redeemCollateralPoolTokens(_valuePoolTokenWei) on agent vault.
310317
* NOTE: may only be called by the agent vault owner.
311318
* @param _agentVault agent vault address
312-
* @param _valueNATWei the amount to be withdrawn
319+
* @param _valuePoolTokenWei the amount to be withdrawn
313320
* @return _redemptionAllowedAt the timestamp when the redemption can be made
314321
*/
315322
function announceAgentPoolTokenRedemption(
316323
address _agentVault,
317-
uint256 _valueNATWei
324+
uint256 _valuePoolTokenWei
318325
) external
319326
returns (uint256 _redemptionAllowedAt);
320327

@@ -379,7 +386,7 @@ interface IAssetManager is
379386
// Agent information
380387

381388
/**
382-
* Get (a part of) the list of all agents.
389+
* Get (a part of) the list of all active (not destroyed) agents.
383390
* The list must be retrieved in parts since retrieving the whole list can consume too much gas for one block.
384391
* @param _start first index to return from the available agent's list
385392
* @param _end end index (one above last) to return from the available agent's list
@@ -540,6 +547,9 @@ interface IAssetManager is
540547
* If the minter pays the underlying amount, minter obtains f-assets.
541548
* The collateral reservation fee is split between the agent and the collateral pool.
542549
* NOTE: the owner of the agent vault must be in the AgentOwnerRegistry.
550+
* NOTE: if the underlying block isn't updated regularly, it can happen that there is not enough time for
551+
* the underlying payment. Therefore minters have to verify the current underlying before minting and,
552+
* if needed, update it by calling `updateCurrentBlock`.
543553
* @param _agentVault agent vault address
544554
* @param _lots the number of lots for which to reserve collateral
545555
* @param _maxMintingFeeBIPS maximum minting fee (BIPS) that can be charged by the agent - best is just to
@@ -687,6 +697,9 @@ interface IAssetManager is
687697
* of remaining lots.
688698
* Agent receives redemption request id and instructions for underlying payment in
689699
* RedemptionRequested event and has to pay `value - fee` and use the provided payment reference.
700+
* NOTE: if the underlying block isn't updated regularly, it can happen that there is no time for underlying
701+
* payment. Since the agents cannot know when the next redemption will happen, they should regularly update the
702+
* underlying time by obtaining fresh proof of latest underlying block and calling `updateCurrentBlock`.
690703
* @param _lots number of lots to redeem
691704
* @param _redeemerUnderlyingAddressString the address to which the agent must transfer underlying amount
692705
* @param _executor the account that is allowed to execute redemption default (besides redeemer and agent)
@@ -850,7 +863,7 @@ interface IAssetManager is
850863
* among the first `maxRedeemedTickets` tickets.
851864
* To fix this, call this method. It converts small tickets to dust and when the dust exceeds one lot
852865
* adds it to the ticket.
853-
* Since the method just cleans the redemption queue it can be called by anybody.
866+
* NOTE: this method can be called by the governance or its executor.
854867
* @param _firstTicketId if nonzero, the ticket id of starting ticket; if zero, the starting ticket will
855868
* be the redemption queue's first ticket id.
856869
* When the method finishes, it emits RedemptionTicketsConsolidated event with the nextTicketId

src/coston/IAssetManagerController.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import {IAssetManager} from "./IAssetManager.sol";
55

66

77
interface IAssetManagerController {
8+
event AssetManagerAdded(address assetManager);
9+
event AssetManagerRemoved(address assetManager);
10+
811
/**
912
* Return the list of all asset managers managed by this controller.
1013
*/

src/coston/IAssetManagerEvents.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,4 +525,14 @@ interface IAssetManagerEvents {
525525
* Emergency pause was canceled.
526526
*/
527527
event EmergencyPauseCanceled();
528+
529+
/**
530+
* Emergency pause total duration was reset by the governance.
531+
*/
532+
event EmergencyPauseTotalDurationReset();
533+
534+
/**
535+
* Minting was paused/unpaused by the governance.
536+
*/
537+
event MintingPaused(bool paused);
528538
}

src/coston2/IAssetManager.sol

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ interface IAssetManager is
154154
* to prevent current block being too outdated, which gives too short time for
155155
* minting or redemption payment.
156156
* NOTE: anybody can call.
157+
* NOTE: the block/timestamp will only be updated if it is strictly higher than the current value.
158+
* For mintings and redemptions we also add the duration from the last update (on this chain) to compensate
159+
* for the time that passed since the last update. This mechanism can be abused by providing old block proof
160+
* as fresh, which will distort the compensation accounting. Due to monotonicity such an attack will only work
161+
* if there was no block update for some time. Therefore it is enough to have at least one honest
162+
* current block updater regularly providing updates to avoid this issue.
157163
* @param _proof proof that a block with given number and timestamp exists
158164
*/
159165
function updateCurrentBlock(
@@ -304,17 +310,18 @@ interface IAssetManager is
304310
returns (uint256 _withdrawalAllowedAt);
305311

306312
/**
307-
* The agent is going to redeem `_valueWei` collateral pool tokens in the agent vault.
308-
* This has to be announced and the agent must then wait `withdrawalWaitMinSeconds` time.
309-
* After that time, the agent can call `redeemCollateralPoolTokens(_valueNATWei)` on the agent vault.
313+
* Agent is going to withdraw `_valuePoolTokenWei` of pool tokens from the agent vault
314+
* and redeem them for NAT from the collateral pool.
315+
* This has to be announced and the agent must then wait `withdrawalWaitMinSeconds`.
316+
* After that time, the agent can call redeemCollateralPoolTokens(_valuePoolTokenWei) on agent vault.
310317
* NOTE: may only be called by the agent vault owner.
311318
* @param _agentVault agent vault address
312-
* @param _valueNATWei the amount to be withdrawn
319+
* @param _valuePoolTokenWei the amount to be withdrawn
313320
* @return _redemptionAllowedAt the timestamp when the redemption can be made
314321
*/
315322
function announceAgentPoolTokenRedemption(
316323
address _agentVault,
317-
uint256 _valueNATWei
324+
uint256 _valuePoolTokenWei
318325
) external
319326
returns (uint256 _redemptionAllowedAt);
320327

@@ -379,7 +386,7 @@ interface IAssetManager is
379386
// Agent information
380387

381388
/**
382-
* Get (a part of) the list of all agents.
389+
* Get (a part of) the list of all active (not destroyed) agents.
383390
* The list must be retrieved in parts since retrieving the whole list can consume too much gas for one block.
384391
* @param _start first index to return from the available agent's list
385392
* @param _end end index (one above last) to return from the available agent's list
@@ -540,6 +547,9 @@ interface IAssetManager is
540547
* If the minter pays the underlying amount, minter obtains f-assets.
541548
* The collateral reservation fee is split between the agent and the collateral pool.
542549
* NOTE: the owner of the agent vault must be in the AgentOwnerRegistry.
550+
* NOTE: if the underlying block isn't updated regularly, it can happen that there is not enough time for
551+
* the underlying payment. Therefore minters have to verify the current underlying before minting and,
552+
* if needed, update it by calling `updateCurrentBlock`.
543553
* @param _agentVault agent vault address
544554
* @param _lots the number of lots for which to reserve collateral
545555
* @param _maxMintingFeeBIPS maximum minting fee (BIPS) that can be charged by the agent - best is just to
@@ -687,6 +697,9 @@ interface IAssetManager is
687697
* of remaining lots.
688698
* Agent receives redemption request id and instructions for underlying payment in
689699
* RedemptionRequested event and has to pay `value - fee` and use the provided payment reference.
700+
* NOTE: if the underlying block isn't updated regularly, it can happen that there is no time for underlying
701+
* payment. Since the agents cannot know when the next redemption will happen, they should regularly update the
702+
* underlying time by obtaining fresh proof of latest underlying block and calling `updateCurrentBlock`.
690703
* @param _lots number of lots to redeem
691704
* @param _redeemerUnderlyingAddressString the address to which the agent must transfer underlying amount
692705
* @param _executor the account that is allowed to execute redemption default (besides redeemer and agent)
@@ -850,7 +863,7 @@ interface IAssetManager is
850863
* among the first `maxRedeemedTickets` tickets.
851864
* To fix this, call this method. It converts small tickets to dust and when the dust exceeds one lot
852865
* adds it to the ticket.
853-
* Since the method just cleans the redemption queue it can be called by anybody.
866+
* NOTE: this method can be called by the governance or its executor.
854867
* @param _firstTicketId if nonzero, the ticket id of starting ticket; if zero, the starting ticket will
855868
* be the redemption queue's first ticket id.
856869
* When the method finishes, it emits RedemptionTicketsConsolidated event with the nextTicketId

src/coston2/IAssetManagerController.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import {IAssetManager} from "./IAssetManager.sol";
55

66

77
interface IAssetManagerController {
8+
event AssetManagerAdded(address assetManager);
9+
event AssetManagerRemoved(address assetManager);
10+
811
/**
912
* Return the list of all asset managers managed by this controller.
1013
*/

src/coston2/IAssetManagerEvents.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,4 +525,14 @@ interface IAssetManagerEvents {
525525
* Emergency pause was canceled.
526526
*/
527527
event EmergencyPauseCanceled();
528+
529+
/**
530+
* Emergency pause total duration was reset by the governance.
531+
*/
532+
event EmergencyPauseTotalDurationReset();
533+
534+
/**
535+
* Minting was paused/unpaused by the governance.
536+
*/
537+
event MintingPaused(bool paused);
528538
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.8.4 <0.9;
3+
4+
/**
5+
* @title ICustomInstructionsFacet
6+
* @notice Interface for the CustomInstructionsFacet contract.
7+
*/
8+
interface ICustomInstructionsFacet {
9+
10+
/// @notice Struct containing custom call information
11+
struct CustomCall {
12+
/// @notice Target contract address
13+
address targetContract;
14+
/// @notice value (in wei) to send with the call
15+
uint256 value;
16+
/// @notice Call data
17+
bytes data;
18+
}
19+
20+
/**
21+
* @notice Emitted when a custom instruction is registered.
22+
* @param customInstructionHash The hash representing the registered instructions.
23+
*/
24+
event CustomInstructionRegistered(bytes32 indexed customInstructionHash);
25+
26+
/**
27+
* @notice Emitted when a custom instruction is already registered.
28+
* @param customInstructionHash The hash representing the already registered instructions.
29+
*/
30+
event CustomInstructionAlreadyRegistered(bytes32 indexed customInstructionHash);
31+
32+
/**
33+
* @notice Reverts if the custom instruction is empty (zero custom calls).
34+
*/
35+
error EmptyCustomInstruction();
36+
37+
/**
38+
* @notice Reverts if the target address of a custom call is zero.
39+
*/
40+
error TargetAddressZero();
41+
42+
/**
43+
* @notice Reverts if the target address of a custom call is not a contract.
44+
* @param target The target address.
45+
*/
46+
error TargetNotAContract(address target);
47+
48+
/**
49+
* @notice Register custom instruction and return the call hash.
50+
* @param _customInstruction Custom instruction (array of custom calls) to register.
51+
* @return _customInstructionHash The hash representing the registered custom instruction.
52+
*/
53+
function registerCustomInstruction(
54+
CustomCall[] memory _customInstruction
55+
) external returns (bytes32 _customInstructionHash);
56+
57+
/**
58+
* @notice Get a custom instruction for a given call hash.
59+
* @param _customInstructionHash The hash representing the custom instruction.
60+
* @return _customInstruction Custom instruction (array of custom calls) for the hash.
61+
*/
62+
function getCustomInstruction(
63+
bytes32 _customInstructionHash
64+
) external view returns (CustomCall[] memory _customInstruction);
65+
/**
66+
* @notice Get paginated custom instruction hashes.
67+
* @param _start The starting index.
68+
* @param _end The ending index.
69+
* @return _customInstructionHashes Array of custom instruction hashes for the requested page.
70+
* @return _totalLength The total number of custom instruction hashes.
71+
*/
72+
function getCustomInstructionHashes(
73+
uint256 _start,
74+
uint256 _end
75+
) external view returns (bytes32[] memory _customInstructionHashes, uint256 _totalLength);
76+
77+
/**
78+
* @notice Encode a custom instruction to get its call hash.
79+
* @param _customInstruction Custom instruction (array of custom calls) to encode.
80+
* @return _customInstructionHash The hash representing the custom instruction.
81+
*/
82+
function encodeCustomInstruction(
83+
CustomCall[] memory _customInstruction
84+
) external pure returns (bytes32 _customInstructionHash);
85+
}

src/coston2/IInstructionsFacet.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
pragma solidity >=0.8.4 <0.9;
33

44
import {IPayment} from "./IPayment.sol";
5+
import {ICustomInstructionsFacet} from "./ICustomInstructionsFacet.sol";
56

67
/**
78
* @title IInstructionsFacet
@@ -173,6 +174,18 @@ interface IInstructionsFacet {
173174
uint256 amount
174175
);
175176

177+
/**
178+
* @notice Emitted when a custom instruction is executed.
179+
* @param personalAccount The personal account address.
180+
* @param callHash The call hash of the custom instruction.
181+
* @param customInstruction The custom instruction.
182+
*/
183+
event CustomInstructionExecuted(
184+
address indexed personalAccount,
185+
bytes32 indexed callHash,
186+
ICustomInstructionsFacet.CustomCall[] customInstruction
187+
);
188+
176189
/**
177190
* @notice Reverts if the payment amount is invalid.
178191
* @param requiredAmount The required payment amount.
@@ -239,6 +252,11 @@ interface IInstructionsFacet {
239252
*/
240253
error InvalidMinter();
241254

255+
/**
256+
* @notice Reverts if the provided custom instruction hash is invalid (not registered).
257+
*/
258+
error InvalidCustomInstructionHash();
259+
242260
/**
243261
* @notice Reserve collateral for minting operation.
244262
* @param _xrplAddress The XRPL address requesting the collateral reservation.

src/coston2/IMasterAccountController.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {ISwapFacet} from "./ISwapFacet.sol";
1616
import {ITimelockFacet} from "./ITimelockFacet.sol";
1717
import {IVaultsFacet} from "./IVaultsFacet.sol";
1818
import {IXrplProviderWalletsFacet} from "./IXrplProviderWalletsFacet.sol";
19+
import {ICustomInstructionsFacet} from "./ICustomInstructionsFacet.sol";
1920

2021
/**
2122
* @title IMasterAccountController
@@ -36,5 +37,6 @@ interface IMasterAccountController is
3637
ISwapFacet,
3738
ITimelockFacet,
3839
IVaultsFacet,
39-
IXrplProviderWalletsFacet
40+
IXrplProviderWalletsFacet,
41+
ICustomInstructionsFacet
4042
{}

0 commit comments

Comments
 (0)