Skip to content

Commit

Permalink
Merge pull request #204 from stabilitydao/sonic
Browse files Browse the repository at this point in the history
Zap 1.0.3: bugfix for Ichi deposit
  • Loading branch information
a17 authored Jan 8, 2025
2 parents 71badd2 + 3b32a58 commit d5d78ab
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ pragma solidity ^0.8.23;

import {console} from "forge-std/Test.sol";
import "forge-std/Script.sol";
import "../../chains/PolygonLib.sol";
import "../../src/core/Factory.sol";
import "../../src/core/Zap.sol";
import "../../src/core/vaults/CVault.sol";
import "../../src/core/vaults/RVault.sol";
import "../../src/core/vaults/RMVault.sol";

contract PrepareUpgrade1Polygon is Script {
contract PrepareUpgrade1 is Script {
function run() external {
uint deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);
Expand All @@ -31,5 +30,5 @@ contract PrepareUpgrade1Polygon is Script {
vm.stopBroadcast();
}

function testDeployPolygon() external {}
function testPrepareUpgrade() external {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@ import "../../src/adapters/AlgebraAdapter.sol";
import "../../src/adapters/UniswapV3Adapter.sol";
import "../../src/adapters/KyberAdapter.sol";
import "../../src/core/Zap.sol";
// import "../../src/strategies/QuickswapV3StaticFarmStrategy.sol";

contract PrepareUpgrade2Polygon is Script {
contract PrepareUpgrade2 is Script {
function run() external {
uint deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);
new AlgebraAdapter();
new UniswapV3Adapter();
new KyberAdapter();
new Zap();
// new QuickSwapV3StaticFarmStrategy();
vm.stopBroadcast();
}

function testDeployPolygon() external {}
function testPrepareUpgrade() external {}
}
75 changes: 0 additions & 75 deletions script/upgrade-core/PrepareUpgrade.24.01.0-alpha.Polygon.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ import "../../src/core/Factory.sol";
import "../../src/core/vaults/CVault.sol";
import "../../src/core/vaults/RVault.sol";
import "../../src/core/vaults/RMVault.sol";
// import "../../src/strategies/QuickswapV3StaticFarmStrategy.sol";

contract PrepareUpgrade3Polygon is Script {
address public constant PLATFORM = 0xb2a0737ef27b5Cc474D24c779af612159b1c3e60;
string public constant ALGEBRA = "Algebra";
string internal constant COMPOUNDING = "Compounding";
string internal constant REWARDING = "Rewarding";
string internal constant REWARDING_MANAGED = "Rewarding Managed";
// string public constant QUICKSWAPV3_STATIC_FARM = "QuickSwapV3 Static Farm";
address public constant TOKEN_USDCe = 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174;
address public constant TOKEN_USDC = 0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359;
address public constant TOKEN_dQUICK = 0x958d208Cdf087843e9AD98d23823d32E17d723A1;
Expand All @@ -25,58 +23,15 @@ contract PrepareUpgrade3Polygon is Script {

function run() external {
uint deployerPrivateKey = vm.envUint("PRIVATE_KEY");
// IFactory factory = IFactory(IPlatform(PLATFORM).factory());

vm.startBroadcast(deployerPrivateKey);

// Factory 1.0.2: setVaultStatus updated
new Factory();

// QSF 1.0.2: getRevenue fixed
// new QuickSwapV3StaticFarmStrategy();
// factory.setStrategyLogicConfig(
// IFactory.StrategyLogicConfig({
// id: QUICKSWAPV3_STATIC_FARM,
// implementation: impl,
// deployAllowed: true,
// upgradeAllowed: true,
// farming: true,
// tokenId: 0
// }),
// address(0)
// );

// Vaults 1.1.0: setName, setSymbol, gas optimization
new CVault();
// factory.setVaultConfig(
// IFactory.VaultConfig({
// vaultType: COMPOUNDING,
// implementation: impl,
// deployAllowed: true,
// upgradeAllowed: true,
// buildingPrice: 50_000e18
// })
// );
new RVault();
// factory.setVaultConfig(
// IFactory.VaultConfig({
// vaultType: REWARDING,
// implementation: impl,
// deployAllowed: true,
// upgradeAllowed: true,
// buildingPrice: 50_000e18
// })
// );
new RMVault();
// factory.setVaultConfig(
// IFactory.VaultConfig({
// vaultType: REWARDING_MANAGED,
// implementation: impl,
// deployAllowed: false,
// upgradeAllowed: false,
// buildingPrice: 100_000e18
// })
// );

// route for native USDC
ISwapper.AddPoolData[] memory pools = new ISwapper.AddPoolData[](1);
Expand All @@ -94,36 +49,6 @@ contract PrepareUpgrade3Polygon is Script {
thresholdAmount[0] = 1e3;
swapper.setThresholds(tokenIn, thresholdAmount);

// new farm for QSF
// IFactory.Farm[] memory _farms = new IFactory.Farm[](1);
// address[] memory rewardAssets;
// address[] memory addresses;
// uint[] memory nums;
// int24[] memory ticks;
// [17] Earn dQUICK, WMATIC by static position in USDCe/USDC pool on QuickSwap V3
// rewardAssets = new address[](2);
// rewardAssets[0] = TOKEN_dQUICK;
// rewardAssets[1] = TOKEN_WMATIC;
// addresses = new address[](2);
// addresses[0] = QUICKSWAP_POSITION_MANAGER;
// addresses[1] = QUICKSWAP_FARMING_CENTER;
// nums = new uint[](2);
// nums[0] = 1700454552;
// nums[1] = 4104559500;
// ticks = new int24[](2);
// ticks[0] = -60;
// ticks[1] = 60;
// _farms[0] = IFactory.Farm({
// status: 0,
// pool: POOL_QUICKSWAPV3_USDCe_USDC,
// strategyLogicId: StrategyIdLib.QUICKSWAPV3_STATIC_FARM,
// rewardAssets: rewardAssets,
// addresses: addresses,
// nums: nums,
// ticks: ticks
// });
// factory.addFarms(_farms);

vm.stopBroadcast();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "../../src/core/vaults/RVault.sol";
import "../../src/core/vaults/RMVault.sol";
import "../../src/strategies/YearnStrategy.sol";

contract PrepareUpgrade5Polygon is Script {
contract PrepareUpgrade5 is Script {
function run() external {
uint deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);
Expand All @@ -31,5 +31,5 @@ contract PrepareUpgrade5Polygon is Script {
vm.stopBroadcast();
}

function testDeployPolygon() external {}
function testPrepareUpgrade() external {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ pragma solidity ^0.8.23;

import "forge-std/Script.sol";
import "../../src/core/Factory.sol";
import "../../src/core/vaults/CVault.sol";
import "../../src/core/vaults/RVault.sol";
import "../../src/core/vaults/RMVault.sol";
import "../../src/strategies/YearnStrategy.sol";

contract PrepareUpgrade5Polygon is Script {
contract PrepareUpgrade6 is Script {
function run() external {
uint deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);
Expand All @@ -19,5 +15,5 @@ contract PrepareUpgrade5Polygon is Script {
vm.stopBroadcast();
}

function testDeployPolygon() external {}
function testPrepareUpgrade() external {}
}
19 changes: 19 additions & 0 deletions script/upgrade-core/PrepareUpgrade.25.01.1-alpha.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import "forge-std/Script.sol";
import "../../src/core/Zap.sol";

contract PrepareUpgrade7 is Script {
function run() external {
uint deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);

// Zap 1.0.3: bugfix for Ichi deposit
new Zap();

vm.stopBroadcast();
}

function testPrepareUpgrade() external {}
}
7 changes: 4 additions & 3 deletions src/core/Zap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract Zap is Controllable, ReentrancyGuardUpgradeable, IZap {
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

/// @inheritdoc IControllable
string public constant VERSION = "1.0.2";
string public constant VERSION = "1.0.3";

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* INITIALIZATION */
Expand All @@ -51,8 +51,6 @@ contract Zap is Controllable, ReentrancyGuardUpgradeable, IZap {
uint minSharesOut,
address receiver
) external nonReentrant {
// todo check vault

if (amountIn == 0) {
revert IControllable.IncorrectZeroArgument();
}
Expand All @@ -78,6 +76,9 @@ contract Zap is Controllable, ReentrancyGuardUpgradeable, IZap {
if (tokenIn == assets[i]) {
continue;
}
if (swapData[i].length == 0) {
continue;
}
//slither-disable-next-line low-level-calls
(bool success, bytes memory result) = agg.call(swapData[i]);
if (!success) {
Expand Down
65 changes: 65 additions & 0 deletions test/core/Zap.Upgrade.Sonic.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {console, Test} from "forge-std/Test.sol";
import {Zap} from "../../src/core/Zap.sol";
import {IPlatform} from "../../src/interfaces/IPlatform.sol";
import {IStrategy} from "../../src/interfaces/IStrategy.sol";
import {IVault} from "../../src/interfaces/IVault.sol";
import {IZap} from "../../src/interfaces/IZap.sol";
import {ISwapper} from "../../src/interfaces/ISwapper.sol";
import {SonicLib} from "../../chains/SonicLib.sol";

contract ZapUpgradeSonic is Test {
address public constant PLATFORM = 0x4Aca671A420eEB58ecafE83700686a2AD06b20D8;

struct ZapTestVars {
address depositToken;
address[] assets;
IStrategy strategy;
uint depositAmount;
uint[] swapAmounts;
}

constructor() {
vm.selectFork(vm.createFork(vm.envString("SONIC_RPC_URL")));
vm.rollFork(3032000); // Jan-08-2025 08:39:58 PM +UTC
}

function testZapUpgrade() public {
address multisig = IPlatform(PLATFORM).multisig();
IZap zap = IZap(IPlatform(PLATFORM).zap());
address swapper = IPlatform(PLATFORM).swapper();
// C-wSSACRA-ISF
address vault = 0x3037a9ec06c25a2190794B533703755cDD137079;

ZapTestVars memory v;
v.strategy = IVault(vault).strategy();
v.assets = v.strategy.assets();
v.depositToken = SonicLib.TOKEN_USDC;
v.depositAmount = 100e6;
(, v.swapAmounts) = zap.getDepositSwapAmounts(vault, v.depositToken, v.depositAmount);
//console.log(v.swapAmounts[0],v.swapAmounts[1]);

bytes[] memory swapData = new bytes[](2);
swapData[1] = abi.encodeCall(ISwapper.swap, (v.depositToken, v.assets[1], v.swapAmounts[1], 1_000));
deal(v.depositToken, address(this), v.depositAmount);
IERC20(v.depositToken).approve(address(zap), v.depositAmount);
vm.expectRevert();
zap.deposit(vault, v.depositToken, v.depositAmount, swapper, swapData, 1, address(this));

address newZapImplementation = address(new Zap());
address[] memory proxies = new address[](1);
proxies[0] = address(address(zap));
address[] memory implementations = new address[](1);
implementations[0] = newZapImplementation;
vm.startPrank(multisig);
IPlatform(PLATFORM).announcePlatformUpgrade("2025.01.1-alpha", proxies, implementations);
skip(1 days);
IPlatform(PLATFORM).upgrade();
vm.stopPrank();

zap.deposit(vault, v.depositToken, v.depositAmount, swapper, swapData, 1, address(this));
}
}

0 comments on commit d5d78ab

Please sign in to comment.