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

Commit

Permalink
Adjustments to Accounts to reflect new Iface, bug fixes to harvest me…
Browse files Browse the repository at this point in the history
…thod in router
  • Loading branch information
stevieraykatz committed Sep 13, 2023
1 parent 0da2d24 commit e5a7029
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 34 deletions.
40 changes: 16 additions & 24 deletions contracts/core/accounts/facets/AccountsStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ contract AccountsStrategy is

uint256 investAmt = investRequest.lockAmt + investRequest.liquidAmt;

uint32[] memory accts = new uint32[](1);
accts[0] = id;

state.Balances[id][IVault.VaultType.LOCKED][tokenAddress] -= investRequest.lockAmt;
state.Balances[id][IVault.VaultType.LIQUID][tokenAddress] -= investRequest.liquidAmt;
IterableMappingStrategy.set(state.ActiveStrategies[id], investRequest.strategy, true);
Expand All @@ -130,7 +127,7 @@ contract AccountsStrategy is
destinationChain: state.config.networkName,
strategyId: investRequest.strategy,
selector: IVault.deposit.selector,
accountIds: accts,
accountId: id,
token: tokenAddress,
lockAmt: investRequest.lockAmt,
liqAmt: investRequest.liquidAmt,
Expand Down Expand Up @@ -159,7 +156,7 @@ contract AccountsStrategy is
destinationChain: stratParams.network,
strategyId: investRequest.strategy,
selector: IVault.deposit.selector,
accountIds: accts,
accountId: id,
token: tokenAddress,
lockAmt: investRequest.lockAmt,
liqAmt: investRequest.liquidAmt,
Expand Down Expand Up @@ -252,16 +249,14 @@ contract AccountsStrategy is
address tokenAddress = IAxelarGateway(thisNetwork.axelarGateway).tokenAddresses(
redeemRequest.token
);
uint32[] memory accts = new uint32[](1);
accts[0] = id;

// Strategy exists on the local network
if (Validator.compareStrings(state.config.networkName, stratParams.network)) {
IVault.VaultActionData memory payload = IVault.VaultActionData({
destinationChain: state.config.networkName,
strategyId: redeemRequest.strategy,
selector: IVault.redeem.selector,
accountIds: accts,
accountId: id,
token: tokenAddress,
lockAmt: redeemRequest.lockAmt,
liqAmt: redeemRequest.liquidAmt,
Expand Down Expand Up @@ -300,7 +295,7 @@ contract AccountsStrategy is
destinationChain: stratParams.network,
strategyId: redeemRequest.strategy,
selector: IVault.redeem.selector,
accountIds: accts,
accountId: id,
token: tokenAddress,
lockAmt: redeemRequest.lockAmt,
liqAmt: redeemRequest.liquidAmt,
Expand Down Expand Up @@ -390,15 +385,13 @@ contract AccountsStrategy is
address tokenAddress = IAxelarGateway(thisNetwork.axelarGateway).tokenAddresses(
redeemAllRequest.token
);
uint32[] memory accts = new uint32[](1);
accts[0] = id;

if (Validator.compareStrings(state.config.networkName, stratParams.network)) {
IVault.VaultActionData memory payload = IVault.VaultActionData({
destinationChain: state.config.networkName,
strategyId: redeemAllRequest.strategy,
selector: IVault.redeemAll.selector,
accountIds: accts,
accountId: id,
token: tokenAddress,
lockAmt: redeemAllRequest.redeemLocked ? 1 : 0,
liqAmt: redeemAllRequest.redeemLiquid ? 1 : 0,
Expand Down Expand Up @@ -436,7 +429,7 @@ contract AccountsStrategy is
destinationChain: stratParams.network,
strategyId: redeemAllRequest.strategy,
selector: IVault.redeemAll.selector,
accountIds: accts,
accountId: id,
token: tokenAddress,
lockAmt: redeemAllRequest.redeemLocked ? 1 : 0,
liqAmt: redeemAllRequest.redeemLiquid ? 1 : 0,
Expand Down Expand Up @@ -477,7 +470,6 @@ contract AccountsStrategy is
IVault.VaultActionData memory response
) internal returns (bool success_) {
AccountStorage.State storage state = LibAccounts.diamondStorage();
uint32 id = response.accountIds[0];

// Invest Cases
// FAIL_TOKENS_RETURNED => Refund upon failed invest call
Expand All @@ -486,10 +478,10 @@ contract AccountsStrategy is
response.selector == IVault.deposit.selector &&
response.status == IVault.VaultActionStatus.FAIL_TOKENS_RETURNED
) {
state.Balances[id][IVault.VaultType.LOCKED][response.token] += response.lockAmt;
state.Balances[id][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(
id,
response.accountId,
response.strategyId,
response.destinationChain,
response.token,
Expand All @@ -507,10 +499,10 @@ contract AccountsStrategy is
(response.selector == IVault.redeemAll.selector)
) {
if (response.status == IVault.VaultActionStatus.SUCCESS) {
state.Balances[id][IVault.VaultType.LOCKED][response.token] += response.lockAmt;
state.Balances[id][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(
id,
response.accountId,
response.strategyId,
response.destinationChain,
response.token,
Expand All @@ -519,11 +511,11 @@ contract AccountsStrategy is
);
return true;
} else if (response.status == IVault.VaultActionStatus.POSITION_EXITED) {
state.Balances[id][IVault.VaultType.LOCKED][response.token] += response.lockAmt;
state.Balances[id][IVault.VaultType.LIQUID][response.token] += response.liqAmt;
IterableMappingStrategy.remove(state.ActiveStrategies[id], 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(
id,
response.accountId,
response.strategyId,
response.destinationChain,
response.token,
Expand Down
20 changes: 10 additions & 10 deletions contracts/core/router/Router.sol
Original file line number Diff line number Diff line change
Expand Up @@ -260,29 +260,29 @@ contract Router is IRouter, Initializable, AxelarExecutable {
IVault lockedVault = IVault(params.lockedVaultAddr);

// Harvest token, transfer to self and update action data
IVault.RedemptionResponse memory _harvestLiq = liquidVault.harvest(_action.accountIds);
IERC20Metadata(_harvestLiq.token).safeTransfer(address(this), _harvestLiq.liqAmt);
IVault.RedemptionResponse memory _harvestLock = lockedVault.harvest(_action.accountIds);
IERC20Metadata(_harvestLock.token).safeTransfer(address(this), _harvestLock.lockAmt);
IVault.RedemptionResponse memory liqResponse = liquidVault.harvest(_action.accountIds);
IERC20Metadata(liqResponse.token).safeTransfer(address(this), liqResponse.amount);
IVault.RedemptionResponse memory lockResponse = lockedVault.harvest(_action.accountIds);
IERC20Metadata(lockResponse.token).safeTransfer(address(this), lockResponse.amount);

// Send tokens to receiver
uint256 totalAmt = _harvestLiq.amount + _harvestLock.amount;
uint256 totalAmt = liqResponse.amount + lockResponse.amount;
if (totalAmt == 0) return;

LibAccounts.FeeSetting memory feeSetting = registrar.getFeeSettingsByFeeType(
LibAccounts.FeeTypes.Harvest
);
// If returning locally
if (_stringCompare(registrar.thisChain(), _action.destinationChain)) {
IERC20Metadata(_action.token).safeTransfer(feeSetting.payoutAddress, totalAmt);
if (_stringCompare(registrar.thisChain(), PRIMARY_CHAIN)) {
IERC20Metadata(lockResponse.token).safeTransfer(feeSetting.payoutAddress, totalAmt);
}
// Or return via GMP
else {
IERC20Metadata(_action.token).safeApprove(address(_gateway()), totalAmt);
IERC20Metadata(lockResponse.token).safeApprove(address(_gateway()), totalAmt);
_gateway().sendToken(
_action.destinationChain,
PRIMARY_CHAIN,
AddressToString.toString(feeSetting.payoutAddress),
IERC20Metadata(_action.token).symbol(),
IERC20Metadata(lockResponse.token).symbol(),
totalAmt
);
}
Expand Down

0 comments on commit e5a7029

Please sign in to comment.