Skip to content

Commit

Permalink
Merge pull request #184 from stabilitydao/tpf-upgrade
Browse files Browse the repository at this point in the history
TPF 1.1.0: zero pool price bugfix
  • Loading branch information
a17 authored Nov 15, 2024
2 parents 6a07076 + 2c51274 commit ba64fb8
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/strategies/TridentPearlFarmStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract TridentPearlFarmStrategy is LPStrategyBase, FarmingStrategyBase {
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

/// @inheritdoc IControllable
string public constant VERSION = "1.0.0";
string public constant VERSION = "1.1.0";

uint internal constant _PRECISION = 10 ** 36;

Expand Down Expand Up @@ -147,7 +147,11 @@ contract TridentPearlFarmStrategy is LPStrategyBase, FarmingStrategyBase {
(uint total0, uint total1,,,) = ILiquidBox(__$__._underlying).getTotalAmounts();
uint price = _getPoolPrice($lp.pool);
uint pool0PricedInToken1 = UniswapV3MathLib.mulDiv(total0, price, _PRECISION);
proportions[0] = pool0PricedInToken1 * 1e18 / (pool0PricedInToken1 + total1);
if (pool0PricedInToken1 + total1 != 0) {
proportions[0] = pool0PricedInToken1 * 1e18 / (pool0PricedInToken1 + total1);
} else {
proportions[0] = 1e18;
}
proportions[1] = 1e18 - proportions[0];
}

Expand Down
76 changes: 76 additions & 0 deletions test/strategies/TPF.Upgrade.Real.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import "forge-std/Test.sol";
import {IVaultManager} from "../../src/interfaces/IVaultManager.sol";
import {IPlatform} from "../../src/interfaces/IPlatform.sol";
import {IFactory} from "../../src/interfaces/IFactory.sol";
import "../../src/strategies/TridentPearlFarmStrategy.sol";
import {IHardWorker} from "../../src/interfaces/IHardWorker.sol";
import {RealLib} from "../../chains/RealLib.sol";

contract TPFUpgradeTest is Test {
address public constant PLATFORM = 0xB7838d447deece2a9A5794De0f342B47d0c1B9DC;
address public constant STRATEGY = 0xF85530577DCB8A00C2254a1C7885F847230C3097;

constructor() {
vm.selectFork(vm.createFork(vm.envString("REAL_RPC_URL")));
vm.rollFork(1126880); // Nov 15 2024 09:17:19 AM
}

function testTPFUpgrade() public {
IVaultManager vaultManager = IVaultManager(IPlatform(PLATFORM).vaultManager());
IFactory factory = IFactory(IPlatform(PLATFORM).factory());
// IHardWorker hw = IHardWorker(IPlatform(PLATFORM).hardWorker());
// ISwapper swapper = ISwapper(IPlatform(PLATFORM).swapper());
address multisig = IPlatform(PLATFORM).multisig();

vm.expectRevert();
vaultManager.vaults();

// deploy new impl and upgrade
address strategyImplementation = address(new TridentPearlFarmStrategy());
vm.prank(multisig);
IPlatform(PLATFORM).addOperator(multisig);
vm.prank(multisig);
factory.setStrategyLogicConfig(
IFactory.StrategyLogicConfig({
id: StrategyIdLib.TRIDENT_PEARL_FARM,
implementation: strategyImplementation,
deployAllowed: true,
upgradeAllowed: true,
farming: true,
tokenId: 0
}),
address(this)
);
factory.upgradeStrategyProxy(STRATEGY);

vaultManager.vaults();

// setup swapper
/*ISwapper.AddPoolData[] memory pools = new ISwapper.AddPoolData[](3);
uint i;
pools[i++] = _makePoolData(RealLib.POOL_PEARL_MORE_USTB_100, AmmAdapterIdLib.UNISWAPV3, RealLib.TOKEN_MORE, RealLib.TOKEN_USTB);
pools[i++] = _makePoolData(RealLib.POOL_PEARL_DAI_USTB_100, AmmAdapterIdLib.UNISWAPV3, RealLib.TOKEN_USTB, RealLib.TOKEN_DAI);
pools[i++] = _makePoolData(RealLib.POOL_PEARL_USTB_arcUSD_100, AmmAdapterIdLib.UNISWAPV3, RealLib.TOKEN_arcUSD, RealLib.TOKEN_USTB);
vm.prank(multisig);
swapper.addPools(pools, true);
// also hardwork
vm.prank(multisig);
hw.setDedicatedServerMsgSender(address(this), true);
address[] memory vaultsForHardWork = new address[](1);
vaultsForHardWork[0] = IStrategy(STRATEGY).vault();
hw.call(vaultsForHardWork);*/
}

function _makePoolData(
address pool,
string memory ammAdapterId,
address tokenIn,
address tokenOut
) internal pure returns (ISwapper.AddPoolData memory) {
return ISwapper.AddPoolData({pool: pool, ammAdapterId: ammAdapterId, tokenIn: tokenIn, tokenOut: tokenOut});
}
}

0 comments on commit ba64fb8

Please sign in to comment.