Skip to content

Commit

Permalink
Return claimed assets for OsTokenVaultEscrow
Browse files Browse the repository at this point in the history
  • Loading branch information
tsudmi committed Sep 3, 2024
1 parent 0141279 commit c082e7c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
8 changes: 7 additions & 1 deletion abi/IOsTokenVaultEscrow.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,13 @@
}
],
"name": "claimExitedAssets",
"outputs": [],
"outputs": [
{
"internalType": "uint256",
"name": "claimedAssets",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
Expand Down
3 changes: 2 additions & 1 deletion contracts/interfaces/IOsTokenVaultEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,13 @@ interface IOsTokenVaultEscrow is IMulticall {
* @param vault The address of the vault
* @param exitPositionTicket The exit position ticket
* @param osTokenShares The amount of osToken shares to burn
* @return claimedAssets The amount of assets claimed
*/
function claimExitedAssets(
address vault,
uint256 exitPositionTicket,
uint256 osTokenShares
) external;
) external returns (uint256 claimedAssets);

/**
* @notice Liquidates the osToken shares
Expand Down
21 changes: 7 additions & 14 deletions contracts/tokens/OsTokenVaultEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ abstract contract OsTokenVaultEscrow is Ownable2Step, Multicall, IOsTokenVaultEs
address vault,
uint256 exitPositionTicket,
uint256 osTokenShares
) external override {
) external override returns (uint256 claimedAssets) {
// burn osToken shares
_osTokenVaultController.burnShares(msg.sender, osTokenShares);

Expand All @@ -167,33 +167,26 @@ abstract contract OsTokenVaultEscrow is Ownable2Step, Multicall, IOsTokenVaultEs
}

// calculate assets to withdraw
uint256 assetsToTransfer;
if (position.osTokenShares != osTokenShares) {
assetsToTransfer = Math.mulDiv(position.exitedAssets, osTokenShares, position.osTokenShares);
claimedAssets = Math.mulDiv(position.exitedAssets, osTokenShares, position.osTokenShares);

// update position osTokenShares
position.exitedAssets -= SafeCast.toUint96(assetsToTransfer);
position.exitedAssets -= SafeCast.toUint96(claimedAssets);
position.osTokenShares -= SafeCast.toUint128(osTokenShares);
_positions[vault][exitPositionTicket] = position;
} else {
assetsToTransfer = position.exitedAssets;
claimedAssets = position.exitedAssets;

// remove position as it is fully processed
delete _positions[vault][exitPositionTicket];
}
if (assetsToTransfer == 0) revert Errors.ExitRequestNotProcessed();
if (claimedAssets == 0) revert Errors.ExitRequestNotProcessed();

// transfer assets
_transferAssets(position.owner, assetsToTransfer);
_transferAssets(position.owner, claimedAssets);

// emit event
emit ExitedAssetsClaimed(
msg.sender,
vault,
exitPositionTicket,
osTokenShares,
assetsToTransfer
);
emit ExitedAssetsClaimed(msg.sender, vault, exitPositionTicket, osTokenShares, claimedAssets);
}

/// @inheritdoc IOsTokenVaultEscrow
Expand Down
8 changes: 4 additions & 4 deletions contracts/vaults/modules/VaultState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ abstract contract VaultState is VaultImmutables, Initializable, VaultAdmin, Vaul
}

/**
* @dev Internal function that must be used to process exit queue
* @dev Internal function that must be used to process exit queue
* @dev Make sure that sufficient time passed between exit queue updates (at least 1 day).
Currently it's restricted by the keeper's harvest interval
* Currently it's restricted by the keeper's harvest interval
* @return burnedShares The total amount of burned shares
*/
function _updateExitQueue() internal virtual returns (uint256 burnedShares) {
Expand Down Expand Up @@ -332,8 +332,8 @@ abstract contract VaultState is VaultImmutables, Initializable, VaultAdmin, Vaul
) internal virtual returns (int256, bool);

/**
* @dev Internal function for retrieving the total assets stored in the Vault.
NB! Assets can be forcibly sent to the vault, the returned value must be used with caution
* @dev Internal function for retrieving the total assets stored in the Vault.
* NB! Assets can be forcibly sent to the vault, the returned value must be used with caution
* @return The total amount of assets stored in the Vault
*/
function _vaultAssets() internal view virtual returns (uint256);
Expand Down
4 changes: 2 additions & 2 deletions test/__snapshots__/EthOsTokenVaultEscrow.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
exports[`EthOsTokenVaultEscrow claim exited assets succeeds succeeds for all osToken shares 1`] = `
Object {
"calldataByteLength": 100,
"gasUsed": 77090,
"gasUsed": 77117,
}
`;

exports[`EthOsTokenVaultEscrow claim exited assets succeeds succeeds for partial osToken shares 1`] = `
Object {
"calldataByteLength": 100,
"gasUsed": 87499,
"gasUsed": 87526,
}
`;

Expand Down

0 comments on commit c082e7c

Please sign in to comment.