Skip to content

Commit 09c0b3d

Browse files
authored
Merge pull request #11 from flare-foundation:0.1.41
Update version to 0.1.41
2 parents 22cf844 + 17a376e commit 09c0b3d

19 files changed

+285
-39
lines changed

coston/IAssetManager.sol

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ interface IAssetManager is
130130
* to prevent current block being too outdated, which gives too short time for
131131
* minting or redemption payment.
132132
* NOTE: anybody can call.
133+
* NOTE: the block/timestamp will only be updated if it is strictly higher than the current value.
134+
* For mintings and redemptions we also add the duration from the last update (on this chain) to compensate
135+
* for the time that passed since the last update. This mechanism can be abused by providing old block proof
136+
* as fresh, which will distort the compensation accounting. Due to monotonicity such an attack will only work
137+
* if there was no block update for some time. Therefore it is enough to have at least one honest
138+
* current block updater regularly providing updates to avoid this issue.
133139
* @param _proof proof that a block with given number and timestamp exists
134140
*/
135141
function updateCurrentBlock(
@@ -280,17 +286,18 @@ interface IAssetManager is
280286
) external returns (uint256 _withdrawalAllowedAt);
281287

282288
/**
283-
* The agent is going to redeem `_valueWei` collateral pool tokens in the agent vault.
284-
* This has to be announced and the agent must then wait `withdrawalWaitMinSeconds` time.
285-
* After that time, the agent can call `redeemCollateralPoolTokens(_valueNATWei)` on the agent vault.
289+
* Agent is going to withdraw `_valuePoolTokenWei` of pool tokens from the agent vault
290+
* and redeem them for NAT from the collateral pool.
291+
* This has to be announced and the agent must then wait `withdrawalWaitMinSeconds`.
292+
* After that time, the agent can call redeemCollateralPoolTokens(_valuePoolTokenWei) on agent vault.
286293
* NOTE: may only be called by the agent vault owner.
287294
* @param _agentVault agent vault address
288-
* @param _valueNATWei the amount to be withdrawn
295+
* @param _valuePoolTokenWei the amount to be withdrawn
289296
* @return _redemptionAllowedAt the timestamp when the redemption can be made
290297
*/
291298
function announceAgentPoolTokenRedemption(
292299
address _agentVault,
293-
uint256 _valueNATWei
300+
uint256 _valuePoolTokenWei
294301
) external returns (uint256 _redemptionAllowedAt);
295302

296303
////////////////////////////////////////////////////////////////////////////////////
@@ -350,7 +357,7 @@ interface IAssetManager is
350357
// Agent information
351358

352359
/**
353-
* Get (a part of) the list of all agents.
360+
* Get (a part of) the list of all active (not destroyed) agents.
354361
* The list must be retrieved in parts since retrieving the whole list can consume too much gas for one block.
355362
* @param _start first index to return from the available agent's list
356363
* @param _end end index (one above last) to return from the available agent's list
@@ -519,6 +526,9 @@ interface IAssetManager is
519526
* If the minter pays the underlying amount, minter obtains f-assets.
520527
* The collateral reservation fee is split between the agent and the collateral pool.
521528
* NOTE: the owner of the agent vault must be in the AgentOwnerRegistry.
529+
* NOTE: if the underlying block isn't updated regularly, it can happen that there is not enough time for
530+
* the underlying payment. Therefore minters have to verify the current underlying before minting and,
531+
* if needed, update it by calling `updateCurrentBlock`.
522532
* @param _agentVault agent vault address
523533
* @param _lots the number of lots for which to reserve collateral
524534
* @param _maxMintingFeeBIPS maximum minting fee (BIPS) that can be charged by the agent - best is just to
@@ -662,6 +672,9 @@ interface IAssetManager is
662672
* of remaining lots.
663673
* Agent receives redemption request id and instructions for underlying payment in
664674
* RedemptionRequested event and has to pay `value - fee` and use the provided payment reference.
675+
* NOTE: if the underlying block isn't updated regularly, it can happen that there is no time for underlying
676+
* payment. Since the agents cannot know when the next redemption will happen, they should regularly update the
677+
* underlying time by obtaining fresh proof of latest underlying block and calling `updateCurrentBlock`.
665678
* @param _lots number of lots to redeem
666679
* @param _redeemerUnderlyingAddressString the address to which the agent must transfer underlying amount
667680
* @param _executor the account that is allowed to execute redemption default (besides redeemer and agent)
@@ -831,7 +844,7 @@ interface IAssetManager is
831844
* among the first `maxRedeemedTickets` tickets.
832845
* To fix this, call this method. It converts small tickets to dust and when the dust exceeds one lot
833846
* adds it to the ticket.
834-
* Since the method just cleans the redemption queue it can be called by anybody.
847+
* NOTE: this method can be called by the governance or its executor.
835848
* @param _firstTicketId if nonzero, the ticket id of starting ticket; if zero, the starting ticket will
836849
* be the redemption queue's first ticket id.
837850
* When the method finishes, it emits RedemptionTicketsConsolidated event with the nextTicketId

coston/IAssetManagerController.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ pragma solidity >=0.7.6 <0.9;
44
import {IAssetManager} from "./IAssetManager.sol";
55

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

coston/IAssetManagerEvents.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,4 +548,14 @@ interface IAssetManagerEvents {
548548
* Emergency pause was canceled.
549549
*/
550550
event EmergencyPauseCanceled();
551+
552+
/**
553+
* Emergency pause total duration was reset by the governance.
554+
*/
555+
event EmergencyPauseTotalDurationReset();
556+
557+
/**
558+
* Minting was paused/unpaused by the governance.
559+
*/
560+
event MintingPaused(bool paused);
551561
}

coston2/IAssetManager.sol

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ interface IAssetManager is
130130
* to prevent current block being too outdated, which gives too short time for
131131
* minting or redemption payment.
132132
* NOTE: anybody can call.
133+
* NOTE: the block/timestamp will only be updated if it is strictly higher than the current value.
134+
* For mintings and redemptions we also add the duration from the last update (on this chain) to compensate
135+
* for the time that passed since the last update. This mechanism can be abused by providing old block proof
136+
* as fresh, which will distort the compensation accounting. Due to monotonicity such an attack will only work
137+
* if there was no block update for some time. Therefore it is enough to have at least one honest
138+
* current block updater regularly providing updates to avoid this issue.
133139
* @param _proof proof that a block with given number and timestamp exists
134140
*/
135141
function updateCurrentBlock(
@@ -280,17 +286,18 @@ interface IAssetManager is
280286
) external returns (uint256 _withdrawalAllowedAt);
281287

282288
/**
283-
* The agent is going to redeem `_valueWei` collateral pool tokens in the agent vault.
284-
* This has to be announced and the agent must then wait `withdrawalWaitMinSeconds` time.
285-
* After that time, the agent can call `redeemCollateralPoolTokens(_valueNATWei)` on the agent vault.
289+
* Agent is going to withdraw `_valuePoolTokenWei` of pool tokens from the agent vault
290+
* and redeem them for NAT from the collateral pool.
291+
* This has to be announced and the agent must then wait `withdrawalWaitMinSeconds`.
292+
* After that time, the agent can call redeemCollateralPoolTokens(_valuePoolTokenWei) on agent vault.
286293
* NOTE: may only be called by the agent vault owner.
287294
* @param _agentVault agent vault address
288-
* @param _valueNATWei the amount to be withdrawn
295+
* @param _valuePoolTokenWei the amount to be withdrawn
289296
* @return _redemptionAllowedAt the timestamp when the redemption can be made
290297
*/
291298
function announceAgentPoolTokenRedemption(
292299
address _agentVault,
293-
uint256 _valueNATWei
300+
uint256 _valuePoolTokenWei
294301
) external returns (uint256 _redemptionAllowedAt);
295302

296303
////////////////////////////////////////////////////////////////////////////////////
@@ -350,7 +357,7 @@ interface IAssetManager is
350357
// Agent information
351358

352359
/**
353-
* Get (a part of) the list of all agents.
360+
* Get (a part of) the list of all active (not destroyed) agents.
354361
* The list must be retrieved in parts since retrieving the whole list can consume too much gas for one block.
355362
* @param _start first index to return from the available agent's list
356363
* @param _end end index (one above last) to return from the available agent's list
@@ -519,6 +526,9 @@ interface IAssetManager is
519526
* If the minter pays the underlying amount, minter obtains f-assets.
520527
* The collateral reservation fee is split between the agent and the collateral pool.
521528
* NOTE: the owner of the agent vault must be in the AgentOwnerRegistry.
529+
* NOTE: if the underlying block isn't updated regularly, it can happen that there is not enough time for
530+
* the underlying payment. Therefore minters have to verify the current underlying before minting and,
531+
* if needed, update it by calling `updateCurrentBlock`.
522532
* @param _agentVault agent vault address
523533
* @param _lots the number of lots for which to reserve collateral
524534
* @param _maxMintingFeeBIPS maximum minting fee (BIPS) that can be charged by the agent - best is just to
@@ -662,6 +672,9 @@ interface IAssetManager is
662672
* of remaining lots.
663673
* Agent receives redemption request id and instructions for underlying payment in
664674
* RedemptionRequested event and has to pay `value - fee` and use the provided payment reference.
675+
* NOTE: if the underlying block isn't updated regularly, it can happen that there is no time for underlying
676+
* payment. Since the agents cannot know when the next redemption will happen, they should regularly update the
677+
* underlying time by obtaining fresh proof of latest underlying block and calling `updateCurrentBlock`.
665678
* @param _lots number of lots to redeem
666679
* @param _redeemerUnderlyingAddressString the address to which the agent must transfer underlying amount
667680
* @param _executor the account that is allowed to execute redemption default (besides redeemer and agent)
@@ -831,7 +844,7 @@ interface IAssetManager is
831844
* among the first `maxRedeemedTickets` tickets.
832845
* To fix this, call this method. It converts small tickets to dust and when the dust exceeds one lot
833846
* adds it to the ticket.
834-
* Since the method just cleans the redemption queue it can be called by anybody.
847+
* NOTE: this method can be called by the governance or its executor.
835848
* @param _firstTicketId if nonzero, the ticket id of starting ticket; if zero, the starting ticket will
836849
* be the redemption queue's first ticket id.
837850
* When the method finishes, it emits RedemptionTicketsConsolidated event with the nextTicketId

coston2/IAssetManagerController.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ pragma solidity >=0.7.6 <0.9;
44
import {IAssetManager} from "./IAssetManager.sol";
55

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

coston2/IAssetManagerEvents.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,4 +548,14 @@ interface IAssetManagerEvents {
548548
* Emergency pause was canceled.
549549
*/
550550
event EmergencyPauseCanceled();
551+
552+
/**
553+
* Emergency pause total duration was reset by the governance.
554+
*/
555+
event EmergencyPauseTotalDurationReset();
556+
557+
/**
558+
* Minting was paused/unpaused by the governance.
559+
*/
560+
event MintingPaused(bool paused);
551561
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
/// @notice Struct containing custom call information
10+
struct CustomCall {
11+
/// @notice Target contract address
12+
address targetContract;
13+
/// @notice value (in wei) to send with the call
14+
uint256 value;
15+
/// @notice Call data
16+
bytes data;
17+
}
18+
19+
/**
20+
* @notice Emitted when a custom instruction is registered.
21+
* @param customInstructionHash The hash representing the registered instructions.
22+
*/
23+
event CustomInstructionRegistered(bytes32 indexed customInstructionHash);
24+
25+
/**
26+
* @notice Emitted when a custom instruction is already registered.
27+
* @param customInstructionHash The hash representing the already registered instructions.
28+
*/
29+
event CustomInstructionAlreadyRegistered(
30+
bytes32 indexed customInstructionHash
31+
);
32+
33+
/**
34+
* @notice Reverts if the custom instruction is empty (zero custom calls).
35+
*/
36+
error EmptyCustomInstruction();
37+
38+
/**
39+
* @notice Reverts if the target address of a custom call is zero.
40+
*/
41+
error TargetAddressZero();
42+
43+
/**
44+
* @notice Reverts if the target address of a custom call is not a contract.
45+
* @param target The target address.
46+
*/
47+
error TargetNotAContract(address target);
48+
49+
/**
50+
* @notice Register custom instruction and return the call hash.
51+
* @param _customInstruction Custom instruction (array of custom calls) to register.
52+
* @return _customInstructionHash The hash representing the registered custom instruction.
53+
*/
54+
function registerCustomInstruction(
55+
CustomCall[] memory _customInstruction
56+
) external returns (bytes32 _customInstructionHash);
57+
58+
/**
59+
* @notice Get a custom instruction for a given call hash.
60+
* @param _customInstructionHash The hash representing the custom instruction.
61+
* @return _customInstruction Custom instruction (array of custom calls) for the hash.
62+
*/
63+
function getCustomInstruction(
64+
bytes32 _customInstructionHash
65+
) external view returns (CustomCall[] memory _customInstruction);
66+
/**
67+
* @notice Get paginated custom instruction hashes.
68+
* @param _start The starting index.
69+
* @param _end The ending index.
70+
* @return _customInstructionHashes Array of custom instruction hashes for the requested page.
71+
* @return _totalLength The total number of custom instruction hashes.
72+
*/
73+
function getCustomInstructionHashes(
74+
uint256 _start,
75+
uint256 _end
76+
)
77+
external
78+
view
79+
returns (
80+
bytes32[] memory _customInstructionHashes,
81+
uint256 _totalLength
82+
);
83+
84+
/**
85+
* @notice Encode a custom instruction to get its call hash.
86+
* @param _customInstruction Custom instruction (array of custom calls) to encode.
87+
* @return _customInstructionHash The hash representing the custom instruction.
88+
*/
89+
function encodeCustomInstruction(
90+
CustomCall[] memory _customInstruction
91+
) external pure returns (bytes32 _customInstructionHash);
92+
}

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
@@ -172,6 +173,18 @@ interface IInstructionsFacet {
172173
uint256 amount
173174
);
174175

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

250+
/**
251+
* @notice Reverts if the provided custom instruction hash is invalid (not registered).
252+
*/
253+
error InvalidCustomInstructionHash();
254+
237255
/**
238256
* @notice Reserve collateral for minting operation.
239257
* @param _xrplAddress The XRPL address requesting the collateral reservation.

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
{}

coston2/IPersonalAccount.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity >=0.8.4 <0.9;
33

4+
import {ICustomInstructionsFacet} from "./ICustomInstructionsFacet.sol";
5+
46
/**
57
* @title IPersonalAccount
68
* @notice Interface for PersonalAccount contract.
@@ -129,6 +131,14 @@ interface IPersonalAccount {
129131
uint256 amountOut
130132
);
131133

134+
/**
135+
* @notice Emitted when a custom instruction is executed.
136+
* @param customInstruction The custom instruction.
137+
*/
138+
event CustomInstructionExecuted(
139+
ICustomInstructionsFacet.CustomCall[] indexed customInstruction
140+
);
141+
132142
/**
133143
* @notice Reverts if the sent value is insufficient for collateral reservation.
134144
* @param collateralReservationFee The required collateral reservation fee.
@@ -175,6 +185,14 @@ interface IPersonalAccount {
175185
*/
176186
error ApprovalFailed();
177187

188+
/**
189+
* @notice Reverts if the custom call fails.
190+
* @param customCall The custom call that failed.
191+
*/
192+
error CustomInstructionCallFailed(
193+
ICustomInstructionsFacet.CustomCall customCall
194+
);
195+
178196
/**
179197
* @notice Returns the XRPL owner address associated with this personal account.
180198
* @return The XRPL owner address

0 commit comments

Comments
 (0)