Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
stevieraykatz committed Sep 13, 2023
1 parent 60e457b commit 5e72c0f
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 45 deletions.
23 changes: 16 additions & 7 deletions contracts/core/accounts/facets/AccountsStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,10 @@ contract AccountsStrategy is
response.selector == IVault.deposit.selector &&
response.status == IVault.VaultActionStatus.FAIL_TOKENS_RETURNED
) {
state.Balances[response.accountId][IVault.VaultType.LOCKED][response.token] += response.lockAmt;
state.Balances[response.accountId][IVault.VaultType.LIQUID][response.token] += response.liqAmt;
state.Balances[response.accountId][IVault.VaultType.LOCKED][response.token] += response
.lockAmt;
state.Balances[response.accountId][IVault.VaultType.LIQUID][response.token] += response
.liqAmt;
emit EndowmentRedeemed(
response.accountId,
response.strategyId,
Expand All @@ -499,8 +501,10 @@ contract AccountsStrategy is
(response.selector == IVault.redeemAll.selector)
) {
if (response.status == IVault.VaultActionStatus.SUCCESS) {
state.Balances[response.accountId][IVault.VaultType.LOCKED][response.token] += response.lockAmt;
state.Balances[response.accountId][IVault.VaultType.LIQUID][response.token] += response.liqAmt;
state.Balances[response.accountId][IVault.VaultType.LOCKED][response.token] += response
.lockAmt;
state.Balances[response.accountId][IVault.VaultType.LIQUID][response.token] += response
.liqAmt;
emit EndowmentRedeemed(
response.accountId,
response.strategyId,
Expand All @@ -511,9 +515,14 @@ contract AccountsStrategy is
);
return true;
} else if (response.status == IVault.VaultActionStatus.POSITION_EXITED) {
state.Balances[response.accountId][IVault.VaultType.LOCKED][response.token] += response.lockAmt;
state.Balances[response.accountId][IVault.VaultType.LIQUID][response.token] += response.liqAmt;
IterableMappingStrategy.remove(state.ActiveStrategies[response.accountId], response.strategyId);
state.Balances[response.accountId][IVault.VaultType.LOCKED][response.token] += response
.lockAmt;
state.Balances[response.accountId][IVault.VaultType.LIQUID][response.token] += response
.liqAmt;
IterableMappingStrategy.remove(
state.ActiveStrategies[response.accountId],
response.strategyId
);
emit EndowmentRedeemed(
response.accountId,
response.strategyId,
Expand Down
4 changes: 2 additions & 2 deletions contracts/core/router/IRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface IRouter is IAxelarExecutable {

/*////////////////////////////////////////////////
CUSTOM TYPES
*/////////////////////////////////////////////////
*/ ////////////////////////////////////////////////

/// @notice Harvest request
/// @param strategyId The 4 byte truncated keccak256 hash of the strategy name, i.e. bytes4(keccak256("Goldfinch"))
Expand All @@ -31,7 +31,7 @@ interface IRouter is IAxelarExecutable {

/*////////////////////////////////////////////////
METHODS
*/////////////////////////////////////////////////
*/ ////////////////////////////////////////////////

function executeLocal(
string calldata sourceChain,
Expand Down
17 changes: 5 additions & 12 deletions contracts/core/router/Router.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,12 @@ contract Router is IRouter, Initializable, AxelarExecutable {
_;
}

modifier operatorOnly {
require(
registrar.getVaultOperatorApproved(msg.sender), "Operator only"
);
modifier operatorOnly() {
require(registrar.getVaultOperatorApproved(msg.sender), "Operator only");
_;
}

modifier validateDeposit(
IVault.VaultActionData memory action,
uint256 amount
) {
modifier validateDeposit(IVault.VaultActionData memory action, uint256 amount) {
// deposit only
require(action.selector == IVault.deposit.selector, "Only deposit accepts tokens");
// amt fwd equal expected amt
Expand Down Expand Up @@ -190,7 +185,7 @@ contract Router is IRouter, Initializable, AxelarExecutable {

// Pack and send the tokens back to Accounts contract
uint256 redeemedAmt = lockResponse.amount + liqResponse.amount;

if (
(lockResponse.status == IVault.VaultActionStatus.POSITION_EXITED) &&
(liqResponse.status == IVault.VaultActionStatus.POSITION_EXITED)
Expand Down Expand Up @@ -247,9 +242,7 @@ contract Router is IRouter, Initializable, AxelarExecutable {
}

// Vault action::Harvest
function harvest(
HarvestRequest memory _action
) external operatorOnly {
function harvest(HarvestRequest memory _action) external operatorOnly {
LocalRegistrarLib.StrategyParams memory params = registrar.getStrategyParamsById(
_action.strategyId
);
Expand Down
14 changes: 12 additions & 2 deletions contracts/core/vault/APVault_V1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,19 @@ contract APVault_V1 is IVault, ERC4626AP, Ownable {

// Call appropriate harvest method
if (vaultConfig.vaultType == VaultType.LIQUID) {
response.amount += _harvestLiquid(accountId, yieldBaseTokens, currentExRate_withPrecision, feeSetting);
response.amount += _harvestLiquid(
accountId,
yieldBaseTokens,
currentExRate_withPrecision,
feeSetting
);
} else {
response.amount += _harvestLocked(accountId, yieldBaseTokens, currentExRate_withPrecision, feeSetting);
response.amount += _harvestLocked(
accountId,
yieldBaseTokens,
currentExRate_withPrecision,
feeSetting
);
}
}

Expand Down
6 changes: 4 additions & 2 deletions contracts/core/vault/interfaces/IVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ abstract contract IVault {
/// on the target yield strategy and VaultType. Only callable by an Angel Protocol Keeper
/// @param accountIds Used to specify which accounts to call harvest against. Structured so that this can
/// be called in batches to avoid running out of gas.
/// @return address and qty of tokens harvested
function harvest(uint32[] calldata accountIds) external virtual returns (RedemptionResponse memory);
/// @return address and qty of tokens harvested
function harvest(
uint32[] calldata accountIds
) external virtual returns (RedemptionResponse memory);

/*////////////////////////////////////////////////
INTERNAL HELPER METHODS
Expand Down
15 changes: 9 additions & 6 deletions contracts/test/DummyVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,18 @@ contract DummyVault is IVault {
});
}

function harvest(uint32[] calldata accountIds) public override returns (RedemptionResponse memory) {
function harvest(
uint32[] calldata accountIds
) public override returns (RedemptionResponse memory) {
for (uint32 i; i < accountIds.length; i++) {
IVaultEmitter(emitterAddress).redeem(accountIds[i], address(this), dummyAmt, dummyAmt);
}
return RedemptionResponse({
token: vaultConfig.baseToken,
amount: dummyAmt,
status: VaultActionStatus.UNPROCESSED
});
return
RedemptionResponse({
token: vaultConfig.baseToken,
amount: dummyAmt,
status: VaultActionStatus.UNPROCESSED
});
}

function _isApprovedRouter() internal view override returns (bool) {}
Expand Down
18 changes: 6 additions & 12 deletions test/core/router/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ describe("Router", function () {
const TOTAL_AMT = LOCK_AMT + LIQ_AMT;
const getDefaultHarvestRequest = () => ({
...DEFAULT_HARVEST_REQUEST,
accountIds: [1]
accountIds: [1],
});

beforeEach(async function () {
Expand Down Expand Up @@ -1121,9 +1121,7 @@ describe("Router", function () {
amount: LIQ_AMT,
status: VaultActionStatus.SUCCESS,
});
expect(
await router.harvest(requestData)
).to.not.be.reverted;
expect(await router.harvest(requestData)).to.not.be.reverted;
expect(lockedVault.harvest).to.have.been.calledWith(requestData.accountIds);
expect(liquidVault.harvest).to.have.been.calledWith(requestData.accountIds);
expect(token.transfer).to.have.been.calledWith(router.address, LOCK_AMT);
Expand All @@ -1143,7 +1141,7 @@ describe("Router", function () {
const TOTAL_AMT = LOCK_AMT + LIQ_AMT;
const getDefaultHarvestRequest = () => ({
...DEFAULT_HARVEST_REQUEST,
accountIds: [1]
accountIds: [1],
});

beforeEach(async function () {
Expand Down Expand Up @@ -1192,10 +1190,8 @@ describe("Router", function () {
amount: LIQ_AMT,
status: VaultActionStatus.SUCCESS,
});
await expect(
router.connect(user).harvest(requestData)
).to.be.revertedWith("Operator only");
})
await expect(router.connect(user).harvest(requestData)).to.be.revertedWith("Operator only");
});

it("Harvests the targeted account and forwards tokens to the local collector", async function () {
let requestData = getDefaultHarvestRequest();
Expand All @@ -1209,9 +1205,7 @@ describe("Router", function () {
amount: LIQ_AMT,
status: VaultActionStatus.SUCCESS,
});
expect(
await router.harvest(requestData)
).to.not.be.reverted;
expect(await router.harvest(requestData)).to.not.be.reverted;
expect(lockedVault.harvest).to.have.been.calledWith(requestData.accountIds);
expect(liquidVault.harvest).to.have.been.calledWith(requestData.accountIds);
expect(token.transfer).to.have.been.calledWith(router.address, LOCK_AMT);
Expand Down
4 changes: 2 additions & 2 deletions test/utils/helpers/accounts/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {IVault} from "typechain-types/contracts/core/accounts/facets/AccountsStr
import {LocalRegistrarLib} from "typechain-types/contracts/core/registrar/LocalRegistrar";
import {ADDRESS_ZERO} from "utils";
import {DEFAULT_NETWORK} from "../../constants";
import { IRouter } from "typechain-types";
import {IRouter} from "typechain-types";

export const DEFAULT_PERMISSIONS_STRUCT: LibAccounts.SettingsPermissionStruct = {
locked: false,
Expand Down Expand Up @@ -155,4 +155,4 @@ export const DEFAULT_ACTION_DATA: IVault.VaultActionDataStruct = {
export const DEFAULT_HARVEST_REQUEST: IRouter.HarvestRequestStruct = {
strategyId: DEFAULT_STRATEGY_ID,
accountIds: [],
}
};

0 comments on commit 5e72c0f

Please sign in to comment.