Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VAL-124] Rename crank to snapshot #155

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions contracts/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ contract Pool is IPool, ERC20Upgradeable, BeaconImplementation {
}

/**
* @dev Modifier to ensure the Pool is cranked.
* @dev Modifier to ensure the Pool is snapshotted.
*/
modifier onlyCrankedPool() {
_crank();
modifier onlySnapshottedPool() {
_performSnapshot();
_;
}

Expand Down Expand Up @@ -249,7 +249,7 @@ contract Pool is IPool, ERC20Upgradeable, BeaconImplementation {
external
onlyNotPaused
onlyPoolController
onlyCrankedPool
onlySnapshottedPool
{
require(!_fundedLoans[addr], "Pool: already funded");
_fundedLoans[addr] = true;
Expand Down Expand Up @@ -381,7 +381,7 @@ contract Pool is IPool, ERC20Upgradeable, BeaconImplementation {
address recipient,
uint256 fixedFee,
uint256 fixedFeeInterval
) external onlyNotPaused onlyPoolController onlyCrankedPool {
) external onlyNotPaused onlyPoolController onlySnapshottedPool {
require(
_accountings.fixedFeeDueDate < block.timestamp,
"Pool: fixed fee not due"
Expand Down Expand Up @@ -464,7 +464,7 @@ contract Pool is IPool, ERC20Upgradeable, BeaconImplementation {
onlyActivatedPool
onlyPermittedLender
onlyLender
onlyCrankedPool
onlySnapshottedPool
returns (uint256 assets)
{
assets = convertToAssets(shares);
Expand All @@ -480,7 +480,7 @@ contract Pool is IPool, ERC20Upgradeable, BeaconImplementation {
onlyActivatedPool
onlyPermittedLender
onlyLender
onlyCrankedPool
onlySnapshottedPool
returns (uint256 shares)
{
shares = convertToShares(assets);
Expand Down Expand Up @@ -535,7 +535,7 @@ contract Pool is IPool, ERC20Upgradeable, BeaconImplementation {
onlyActivatedPool
onlyPermittedLender
onlyLender
onlyCrankedPool
onlySnapshottedPool
returns (uint256 assets)
{
assets = convertToAssets(shares);
Expand All @@ -555,7 +555,7 @@ contract Pool is IPool, ERC20Upgradeable, BeaconImplementation {
onlyActivatedPool
onlyPermittedLender
onlyLender
onlyCrankedPool
onlySnapshottedPool
returns (uint256 shares)
{
shares = convertToShares(assets);
Expand Down Expand Up @@ -583,28 +583,28 @@ contract Pool is IPool, ERC20Upgradeable, BeaconImplementation {
}

/*//////////////////////////////////////////////////////////////
Crank
Snapshot
//////////////////////////////////////////////////////////////*/

/**
* @inheritdoc IPool
*/
function crank() public virtual onlyNotPaused {
_crank();
function snapshot() public virtual onlyNotPaused {
_performSnapshot();
}

/**
* @dev Internal crank function run lazily.
* @dev Internal snapshot function run lazily.
*/
function _crank() internal {
function _performSnapshot() internal {
(
uint256 period,
uint256 redeemableShares,
uint256 withdrawableAssets,
bool periodCranked
) = withdrawController.crank(poolController.withdrawGate());
if (periodCranked) {
emit PoolCranked(period, redeemableShares, withdrawableAssets);
bool periodSnapshotted
) = withdrawController.snapshot(poolController.withdrawGate());
if (periodSnapshotted) {
emit PoolSnapshotted(period, redeemableShares, withdrawableAssets);
}
}

Expand Down Expand Up @@ -715,7 +715,7 @@ contract Pool is IPool, ERC20Upgradeable, BeaconImplementation {
onlyNotPaused
atState(IPoolLifeCycleState.Active)
onlyPermittedLender
onlyCrankedPool
onlySnapshottedPool
returns (uint256 shares)
{
require(msg.sender == receiver, "Pool: invalid receiver");
Expand Down Expand Up @@ -774,7 +774,7 @@ contract Pool is IPool, ERC20Upgradeable, BeaconImplementation {
onlyNotPaused
atState(IPoolLifeCycleState.Active)
onlyPermittedLender
onlyCrankedPool
onlySnapshottedPool
returns (uint256 assets)
{
require(msg.sender == receiver, "Pool: invalid receiver");
Expand Down Expand Up @@ -830,7 +830,7 @@ contract Pool is IPool, ERC20Upgradeable, BeaconImplementation {
virtual
onlyNotPaused
onlyPermittedLender
onlyCrankedPool
onlySnapshottedPool
returns (uint256 shares)
{
require(receiver == owner, "Pool: Withdrawal to unrelated address");
Expand Down Expand Up @@ -885,7 +885,7 @@ contract Pool is IPool, ERC20Upgradeable, BeaconImplementation {
virtual
onlyNotPaused
onlyPermittedLender
onlyCrankedPool
onlySnapshottedPool
returns (uint256 assets)
{
require(receiver == owner, "Pool: Withdrawal to unrelated address");
Expand Down
14 changes: 7 additions & 7 deletions contracts/controllers/PoolController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ contract PoolController is IPoolController, BeaconImplementation {
}

/**
* @dev Modifier to ensure that the Pool is cranked.
* @dev Modifier to ensure that the Pool is snapshotted.
*/
modifier onlyCrankedPool() {
pool.crank();
modifier onlySnapshottedPool() {
pool.snapshot();
_;
}

Expand Down Expand Up @@ -436,7 +436,7 @@ contract PoolController is IPoolController, BeaconImplementation {
onlyNotPaused
onlyAdmin
atActiveOrClosedState
onlyCrankedPool
onlySnapshottedPool
{
require(loan != address(0), "Pool: 0 address");
require(pool.isActiveLoan(loan), "Pool: not active loan");
Expand All @@ -462,10 +462,10 @@ contract PoolController is IPoolController, BeaconImplementation {
}

/*//////////////////////////////////////////////////////////////
Crank
Snapshot
//////////////////////////////////////////////////////////////*/

function crank() external override onlyNotPaused onlyAdmin {
pool.crank();
function snapshot() external override onlyNotPaused onlyAdmin {
pool.snapshot();
}
}
46 changes: 23 additions & 23 deletions contracts/controllers/WithdrawController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ contract WithdrawController is IWithdrawController, BeaconImplementation {
currentPeriod
);

return simulateCrank(state);
return simulateSnapshot(state);
}

/**
Expand Down Expand Up @@ -276,7 +276,7 @@ contract WithdrawController is IWithdrawController, BeaconImplementation {
* @inheritdoc IWithdrawController
*/
function performRequest(address owner, uint256 shares) external onlyPool {
crankLender(owner); // Get them up-to-date
snapshotLender(owner); // Get them up-to-date

uint256 currentPeriod = withdrawPeriod();

Expand All @@ -286,8 +286,8 @@ contract WithdrawController is IWithdrawController, BeaconImplementation {
currentPeriod,
shares
);
_withdrawState[owner].latestCrankPeriod = _globalWithdrawState
.latestCrankPeriod;
_withdrawState[owner].latestSnapshotPeriod = _globalWithdrawState
.latestSnapshotPeriod;

// Update the global amount
_globalWithdrawState = PoolLib.calculateWithdrawStateForRequest(
Expand Down Expand Up @@ -322,7 +322,7 @@ contract WithdrawController is IWithdrawController, BeaconImplementation {
external
onlyPool
{
crankLender(owner);
snapshotLender(owner);
uint256 currentPeriod = withdrawPeriod();

// Update the requested amount from the user
Expand All @@ -341,25 +341,25 @@ contract WithdrawController is IWithdrawController, BeaconImplementation {
}

/*//////////////////////////////////////////////////////////////
Crank
Snapshot
//////////////////////////////////////////////////////////////*/

/**
* @inheritdoc IWithdrawController
*/
function crank(uint256 withdrawGate)
function snapshot(uint256 withdrawGate)
external
onlyPool
returns (
uint256 period,
uint256 redeemableShares,
uint256 withdrawableAssets,
bool periodCranked
bool periodSnapshotted
)
{
period = withdrawPeriod();
IPoolWithdrawState memory globalState = _currentGlobalWithdrawState();
if (globalState.latestCrankPeriod == period) {
if (globalState.latestSnapshotPeriod == period) {
return (period, 0, 0, false);
}

Expand All @@ -381,12 +381,12 @@ contract WithdrawController is IWithdrawController, BeaconImplementation {

if (redeemableShares == 0) {
// unable to redeem anything, so the snapshot is unchanged from the last
_globalWithdrawState.latestCrankPeriod = period;
_snapshots[period] = _snapshots[globalState.latestCrankPeriod];
_globalWithdrawState.latestSnapshotPeriod = period;
_snapshots[period] = _snapshots[globalState.latestSnapshotPeriod];
return (period, 0, 0, true);
}

periodCranked = true;
periodSnapshotted = true;
withdrawableAssets = _pool.convertToAssets(redeemableShares);

// Calculate the redeemable rate for each lender
Expand All @@ -401,7 +401,7 @@ contract WithdrawController is IWithdrawController, BeaconImplementation {

// Pull up the prior snapshot
IPoolSnapshotState memory lastSnapshot = _snapshots[
globalState.latestCrankPeriod
globalState.latestSnapshotPeriod
];

// Cache the last aggregate difference. This is set to 1 * RAY if it
Expand Down Expand Up @@ -432,27 +432,27 @@ contract WithdrawController is IWithdrawController, BeaconImplementation {
withdrawableAssets,
redeemableShares
);
globalState.latestCrankPeriod = period;
globalState.latestSnapshotPeriod = period;
_globalWithdrawState = globalState;
}

/**
* @dev Simulates the effects of multiple snapshots against a lenders
* requested withdrawal.
*/
function simulateCrank(IPoolWithdrawState memory withdrawState)
function simulateSnapshot(IPoolWithdrawState memory withdrawState)
internal
view
returns (IPoolWithdrawState memory)
{
uint256 lastPoolCrank = _globalWithdrawState.latestCrankPeriod;
uint256 lastPoolSnapshot = _globalWithdrawState.latestSnapshotPeriod;

// Current snaphot
IPoolSnapshotState memory endingSnapshot = _snapshots[lastPoolCrank];
IPoolSnapshotState memory endingSnapshot = _snapshots[lastPoolSnapshot];

// Offset snapshot
IPoolSnapshotState memory offsetSnapshot = _snapshots[
withdrawState.latestCrankPeriod
withdrawState.latestSnapshotPeriod
];

// Calculate shares now redeemable
Expand Down Expand Up @@ -487,15 +487,15 @@ contract WithdrawController is IWithdrawController, BeaconImplementation {
withdrawState.redeemableShares += sharesRedeemable;
withdrawState.eligibleShares -= sharesRedeemable;

withdrawState.latestCrankPeriod = lastPoolCrank;
withdrawState.latestSnapshotPeriod = lastPoolSnapshot;

return withdrawState;
}

/**
* @dev Cranks a lender
* @dev Snapshots a lender
*/
function crankLender(address addr)
function snapshotLender(address addr)
internal
returns (IPoolWithdrawState memory state)
{
Expand All @@ -515,7 +515,7 @@ contract WithdrawController is IWithdrawController, BeaconImplementation {
onlyPool
returns (uint256 assets)
{
IPoolWithdrawState memory state = crankLender(owner);
IPoolWithdrawState memory state = snapshotLender(owner);

// Calculate how many assets should be transferred
assets = PoolLib.calculateAssetsFromShares(
Expand All @@ -536,7 +536,7 @@ contract WithdrawController is IWithdrawController, BeaconImplementation {
onlyPool
returns (uint256 shares)
{
IPoolWithdrawState memory state = crankLender(owner);
IPoolWithdrawState memory state = snapshotLender(owner);

// Calculate how many shares should be burned
shares = PoolLib.calculateSharesFromAssets(
Expand Down
6 changes: 3 additions & 3 deletions contracts/controllers/interfaces/IPoolController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ interface IPoolController {
function claimFixedFee() external;

/*//////////////////////////////////////////////////////////////
Crank
Snapshot
//////////////////////////////////////////////////////////////*/

/**
* @dev Cranks the Pool.
* @dev Snapshots the Pool.
*/
function crank() external;
function snapshot() external;
}
14 changes: 7 additions & 7 deletions contracts/controllers/interfaces/IWithdrawController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ pragma solidity ^0.8.16;
*/
struct IPoolWithdrawState {
uint256 requestedShares; // Number of shares requested in the `latestPeriod`
uint256 eligibleShares; // Number of shares that are eligibble to be CONSIDERED for withdraw by the crank
uint256 eligibleShares; // Number of shares that are eligibble to be CONSIDERED for withdraw by the snapshot
uint256 latestRequestPeriod; // Period where this was last updated
uint256 redeemableShares; // The shares that are currently withdrawable
uint256 withdrawableAssets; // The assets that are currently withdrawable
uint256 latestCrankPeriod; // window last cranked in
uint256 crankOffsetPeriod; // At the time of request, this is set to the last successful crank.
uint256 latestSnapshotPeriod; // window last snapshotted in
uint256 snapshotOffsetPeriod; // At the time of request, this is set to the last successful snapshot.
}

/**
Expand Down Expand Up @@ -169,19 +169,19 @@ interface IWithdrawController {
function performRequestCancellation(address, uint256) external;

/*//////////////////////////////////////////////////////////////
Crank
Snapshot
//////////////////////////////////////////////////////////////*/

/**
* @dev Crank the protocol. Performs accounting for withdrawals
* @dev Snapshot the protocol. Performs accounting for withdrawals
*/
function crank(uint256 withdrawGate)
function snapshot(uint256 withdrawGate)
external
returns (
uint256 period,
uint256 shares,
uint256 assets,
bool periodCranked
bool periodSnapshotted
);

/*//////////////////////////////////////////////////////////////
Expand Down
Loading