Skip to content
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
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ task("update-routes-repayer", "Update Repayer routes based on current network co
}
}
}
await addLocalPools(config, network, localConfig);
await addLocalPools(config, network, localConfig, false);
sortRoutes(onchainConfig);
sortRoutes(localConfig);

Expand Down
40 changes: 32 additions & 8 deletions network.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import * as AAVEPools from "@bgd-labs/aave-address-book";
// Subsequent versions use version suffix plus a git commit from the main branch.
export const LiquidityPoolAaveUSDC = "LiquidityPoolAaveUSDC";
export const LiquidityPoolUSDC = "LiquidityPoolUSDC";
export const LiquidityPoolPublicUSDC = "LiquidityPoolPublicUSDC";
export const LiquidityPoolUSDCStablecoin = "LiquidityPoolUSDCStablecoin";
export const LiquidityPoolAaveUSDCLongTerm = "LiquidityPoolAaveUSDCLongTerm";
export const ERC4626AdapterUSDC = "ERC4626AdapterUSDC";
export const LiquidityPoolAaveUSDCLongTermV2 = "LiquidityPoolAaveUSDCLongTerm-V2-e09cc75";
export const LiquidityPoolAaveUSDCV2 = "LiquidityPoolAaveUSDC-V2-3601cc4";
export const LiquidityPoolUSDCV2 = "LiquidityPoolUSDC-V2-3601cc4";
Expand All @@ -34,6 +36,12 @@ export const LiquidityPoolUSDCStablecoinVersions = [
LiquidityPoolUSDCStablecoinV2,
LiquidityPoolUSDCStablecoinV3,
] as const;
export const LiquidityPoolPublicUSDCVersions = [
LiquidityPoolPublicUSDC,
] as const;
export const ERC4626AdapterUSDCVersions = [
ERC4626AdapterUSDC,
] as const;

export enum Network {
ETHEREUM = "ETHEREUM",
Expand All @@ -51,7 +59,7 @@ export enum Network {
UNICHAIN = "UNICHAIN",
BSC = "BSC",
LINEA = "LINEA",
};
}

export enum Provider {
LOCAL = "LOCAL",
Expand All @@ -60,12 +68,12 @@ export enum Provider {
EVERCLEAR = "EVERCLEAR",
STARGATE = "STARGATE",
OPTIMISM_STANDARD_BRIDGE = "OPTIMISM_STANDARD_BRIDGE",
};
}

interface CCTPConfig {
TokenMessenger: string;
MessageTransmitter: string;
};
}

export interface RebalancerRoutesConfig {
[Pool: string]: {
Expand All @@ -82,19 +90,26 @@ export interface RepayerRoutesConfig {
};
}

interface PublicPoolConfig {
Name: string;
Symbol: string;
ProtocolFeeRate: number;
FeeSetter: string;
}

interface AavePoolConfig {
AaveAddressesProvider: string;
MinHealthFactor: number; // Value 500 will result in health factor 5.
DefaultLTV: number; // Value 20 will result in LTV 20%.
TokenLTVs?: {
[token: string]: number;
};
};
}

interface AavePoolLongTermConfig extends AavePoolConfig {
BorrowLongTermAdmin: string;
RepayCaller: string;
};
}

// Liquidity mining tiers.
// period is in seconds.
Expand All @@ -104,7 +119,7 @@ interface AavePoolLongTermConfig extends AavePoolConfig {
interface Tier {
period: bigint;
multiplier: bigint;
};
}

interface HubConfig {
AssetsAdjuster: string; // Address that can increase/decrease LP conversion rate.
Expand All @@ -116,7 +131,7 @@ interface HubConfig {
| (typeof LiquidityPoolAaveUSDCVersions)[number]
| (typeof LiquidityPoolUSDCStablecoinVersions)[number]
| (typeof LiquidityPoolAaveUSDCLongTermVersions)[number];
};
}

export interface NetworkConfig {
ChainId: number;
Expand All @@ -142,8 +157,10 @@ export interface NetworkConfig {
AavePoolLongTerm?: AavePoolLongTermConfig;
USDCPool?: boolean;
USDCStablecoinPool?: boolean;
USDCPublicPool?: PublicPoolConfig;
ERC4626AdapterUSDCTargetVault?: string;
Stage?: NetworkConfig;
};
}

type NetworksConfig = {
[key in Network]: NetworkConfig;
Expand Down Expand Up @@ -675,6 +692,13 @@ export const networkConfig: NetworksConfig = {
BorrowLongTermAdmin: "0x2D5B6C193C39D2AECb4a99052074E6F325258a0f",
RepayCaller: "0xc1d6EEa5ce163d7D9f1952Db220830Aae16Cb607",
},
USDCPublicPool: {
Name: "Sprinter-Lighter Fast Withdrawal Pool",
Symbol: "SLFWP",
ProtocolFeeRate: 20,
FeeSetter: "0x2D5B6C193C39D2AECb4a99052074E6F325258a0f",
},
ERC4626AdapterUSDCTargetVault: LiquidityPoolPublicUSDC,
},
},
BASE: {
Expand Down
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@
"deploy-censoredmulticall-ethereum": "hardhat run ./scripts/deployCensoredMulticall.ts --network ETHEREUM",
"deploy-usdcpoolaavelongterm-ethereum": "hardhat run ./scripts/deployUSDCPoolAaveLongTerm.ts --network ETHEREUM",
"deploy-usdcpool-ethereum": "hardhat run ./scripts/deployUSDCPool.ts --network ETHEREUM",
"deploy-usdcpublicpool-arbitrumone": "hardhat run ./scripts/deployUSDCPublicPool.ts --network ARBITRUM_ONE",
"deploy-erc4626adapterusdc-arbitrumone": "hardhat run ./scripts/deployERC4626Adapter.ts --network ARBITRUM_ONE",
"deploy-usdcpool-base-stage": "DEPLOY_TYPE=STAGE hardhat run ./scripts/deployUSDCPool.ts --network BASE",
"deploy-usdcpoolaave-base-stage": "DEPLOY_TYPE=STAGE hardhat run ./scripts/deployUSDCPoolAave.ts --network BASE",
"deploy-usdcstablecoinpool-base-stage": "DEPLOY_TYPE=STAGE hardhat run ./scripts/deployUSDCStablecoinPool.ts --network BASE",
"deploy-usdcpool-arbitrumone-stage": "DEPLOY_TYPE=STAGE hardhat run ./scripts/deployUSDCPool.ts --network ARBITRUM_ONE",
"deploy-usdcpoolaave-arbitrumone-stage": "DEPLOY_TYPE=STAGE hardhat run ./scripts/deployUSDCPoolAave.ts --network ARBITRUM_ONE",
"deploy-usdcpoolaavelongterm-arbitrumone-stage": "DEPLOY_TYPE=STAGE hardhat run ./scripts/deployUSDCPoolAaveLongTerm.ts --network ARBITRUM_ONE",
"deploy-usdcpublicpool-arbitrumone-stage": "DEPLOY_TYPE=STAGE hardhat run ./scripts/deployUSDCPublicPool.ts --network ARBITRUM_ONE",
"deploy-erc4626adapterusdc-arbitrumone-stage": "DEPLOY_TYPE=STAGE hardhat run ./scripts/deployERC4626Adapter.ts --network ARBITRUM_ONE",
"deploy-usdcpool-opmainnet-stage": "DEPLOY_TYPE=STAGE hardhat run ./scripts/deployUSDCPool.ts --network OP_MAINNET",
"deploy-usdcpoolaave-opmainnet-stage": "DEPLOY_TYPE=STAGE hardhat run ./scripts/deployUSDCPoolAave.ts --network OP_MAINNET",
"deploy-repayer-base": "hardhat run ./scripts/deployRepayer.ts --network BASE",
Expand Down Expand Up @@ -84,6 +88,8 @@
"dry:deploy-censoredmulticall-ethereum": "DRY_RUN=ETHEREUM VERIFY=false ts-node --files ./scripts/deployCensoredMulticall.ts",
"dry:deploy-usdcpoolaavelongterm-ethereum": "DRY_RUN=ETHEREUM VERIFY=false ts-node --files ./scripts/deployUSDCPoolAaveLongTerm.ts",
"dry:deploy-usdcpool-ethereum": "DRY_RUN=ETHEREUM VERIFY=false ts-node --files ./scripts/deployUSDCPool.ts",
"dry:deploy-usdcpublicpool-arbitrumone": "DRY_RUN=ARBITRUM_ONE VERIFY=false ts-node --files ./scripts/deployUSDCPublicPool.ts",
"dry:deploy-erc4626adapterusdc-arbitrumone": "DRY_RUN=ARBITRUM_ONE VERIFY=false ts-node --files ./scripts/deployERC4626Adapter.ts",
"dry:deploy-usdcpool-base-stage": "DRY_RUN=BASE DEPLOY_TYPE=STAGE VERIFY=false ts-node --files ./scripts/deployUSDCPool.ts",
"dry:deploy-usdcpoolaave-base-stage": "DRY_RUN=BASE DEPLOY_TYPE=STAGE VERIFY=false ts-node --files ./scripts/deployUSDCPoolAave.ts",
"dry:deploy-usdcstablecoinpool-base-stage": "DRY_RUN=BASE DEPLOY_TYPE=STAGE VERIFY=false ts-node --files ./scripts/deployUSDCStablecoinPool.ts",
Expand All @@ -92,6 +98,8 @@
"dry:deploy-usdcpool-arbitrumone-stage": "DRY_RUN=ARBITRUM_ONE DEPLOY_TYPE=STAGE VERIFY=false ts-node --files ./scripts/deployUSDCPool.ts",
"dry:deploy-usdcpoolaave-arbitrumone-stage": "DRY_RUN=ARBITRUM_ONE DEPLOY_TYPE=STAGE VERIFY=false ts-node --files ./scripts/deployUSDCPoolAave.ts",
"dry:deploy-usdcpoolaavelongterm-arbitrumone-stage": "DRY_RUN=ARBITRUM_ONE DEPLOY_TYPE=STAGE VERIFY=false ts-node --files ./scripts/deployUSDCPoolAaveLongTerm.ts",
"dry:deploy-usdcpublicpool-arbitrumone-stage": "DRY_RUN=ARBITRUM_ONE DEPLOY_TYPE=STAGE VERIFY=false ts-node --files ./scripts/deployUSDCPublicPool.ts",
"dry:deploy-erc4626adapterusdc-arbitrumone-stage": "DRY_RUN=ARBITRUM_ONE DEPLOY_TYPE=STAGE VERIFY=false ts-node --files ./scripts/deployERC4626Adapter.ts",
"dry:deploy-repayer-base": "DRY_RUN=BASE VERIFY=false ts-node --files ./scripts/deployRepayer.ts",
"dry:deploy-repayer-arbitrumone": "DRY_RUN=ARBITRUM_ONE VERIFY=false ts-node --files ./scripts/deployRepayer.ts",
"dry:deploy-repayer-opmainnet": "DRY_RUN=OP_MAINNET VERIFY=false ts-node --files ./scripts/deployRepayer.ts",
Expand Down
97 changes: 86 additions & 11 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dotenv from "dotenv";
dotenv.config();
import hre from "hardhat";
import {MaxUint256, isAddress} from "ethers";
import {MaxUint256} from "ethers";
import {toBytes32, resolveProxyXAddress, resolveXAddress, getContractAt, resolveXAddresses} from "../test/helpers";
import {
getVerifier, deployProxyX, getHardhatNetworkConfig, getNetworkConfig, percentsToBps,
Expand All @@ -10,18 +10,21 @@ import {
import {
assert, isSet, ProviderSolidity, DomainSolidity, DEFAULT_ADMIN_ROLE, ZERO_ADDRESS,
sameAddress,
assertAddress,
} from "./common";
import {
SprinterUSDCLPShare, LiquidityHub, SprinterLiquidityMining,
Rebalancer, Repayer, LiquidityPool, LiquidityPoolAave, LiquidityPoolStablecoin, LiquidityPoolAaveLongTerm,
ProxyAdmin,
ProxyAdmin, PublicLiquidityPool, ERC4626Adapter,
} from "../typechain-types";
import {
Network, Provider, NetworkConfig,
LiquidityPoolAaveUSDCVersions,
LiquidityPoolAaveUSDCLongTermVersions,
LiquidityPoolUSDCVersions,
LiquidityPoolUSDCStablecoinVersions,
LiquidityPoolPublicUSDCVersions,
ERC4626AdapterUSDCVersions,
} from "../network.config";

export async function main() {
Expand All @@ -32,6 +35,7 @@ export async function main() {
const PAUSER_ROLE = toBytes32("PAUSER_ROLE");
const BORROW_LONG_TERM_ROLE = toBytes32("BORROW_LONG_TERM_ROLE");
const REPAYER_ROLE = toBytes32("REPAYER_ROLE");
const FEE_SETTER_ROLE = toBytes32("FEE_SETTER_ROLE");

assert(isSet(process.env.DEPLOY_ID), "DEPLOY_ID must be set");
const verifier = getVerifier(process.env.DEPLOY_ID);
Expand All @@ -47,15 +51,15 @@ export async function main() {

assert(config.AavePool! || config.AavePoolLongTerm! || config.USDCPool! || config.USDCStablecoinPool!,
"At least one pool should be present.");
assert(isAddress(config.USDC), "USDC must be an address");
assert(isAddress(config.Admin), "Admin must be an address");
assert(isAddress(config.WithdrawProfit), "WithdrawProfit must be an address");
assert(isAddress(config.Pauser), "Pauser must be an address");
assert(isAddress(config.RebalanceCaller), "RebalanceCaller must be an address");
assert(isAddress(config.RepayerCaller), "RepayerCaller must be an address");
assert(isAddress(config.MpcAddress), "MpcAddress must be an address");
assert(isAddress(config.SignerAddress), "SignerAddress must be an address");
assert(isAddress(config.WrappedNativeToken), "WrappedNativeToken must be an address");
assertAddress(config.USDC, "USDC must be an address");
assertAddress(config.Admin, "Admin must be an address");
assertAddress(config.WithdrawProfit, "WithdrawProfit must be an address");
assertAddress(config.Pauser, "Pauser must be an address");
assertAddress(config.RebalanceCaller, "RebalanceCaller must be an address");
assertAddress(config.RepayerCaller, "RepayerCaller must be an address");
assertAddress(config.MpcAddress, "MpcAddress must be an address");
assertAddress(config.SignerAddress, "SignerAddress must be an address");
assertAddress(config.WrappedNativeToken, "WrappedNativeToken must be an address");

if (!config.CCTP) {
config.CCTP = {
Expand Down Expand Up @@ -265,6 +269,55 @@ export async function main() {
}
}

let usdcPublicPool: PublicLiquidityPool;
if (config.USDCPublicPool) {
assertAddress(config.USDCPublicPool.FeeSetter, "FeeSetter must be an address");
const id = LiquidityPoolPublicUSDCVersions.at(-1);
console.log("Deploying USDC Public Liquidity Pool");
usdcPublicPool = (await verifier.deployX(
"PublicLiquidityPool",
deployer,
{},
[
config.USDC,
deployer,
config.MpcAddress,
config.WrappedNativeToken,
config.SignerAddress,
config.USDCPublicPool.Name,
config.USDCPublicPool.Symbol,
config.USDCPublicPool.ProtocolFeeRate * 10000 / 100,
],
id
)) as PublicLiquidityPool;
console.log(`${id}: ${usdcPublicPool.target}`);
}

let erc4626AdapterUSDC: ERC4626Adapter;
if (config.ERC4626AdapterUSDCTargetVault) {
const id = ERC4626AdapterUSDCVersions.at(-1);
const targetVault = await resolveXAddress(config.ERC4626AdapterUSDCTargetVault);
console.log(`Target Vault: ${targetVault}`);

console.log("Deploying ERC4626 Adapter USDC");
erc4626AdapterUSDC = (await verifier.deployX(
"ERC4626Adapter",
deployer,
{},
[
config.USDC,
targetVault,
deployer,
],
id
)) as ERC4626Adapter;
console.log(`${id}: ${erc4626AdapterUSDC.target}`);

rebalancerRoutes.Pools.push(await erc4626AdapterUSDC.getAddress());
rebalancerRoutes.Domains.push(network);
rebalancerRoutes.Providers.push(Provider.LOCAL);
}

assert(mainPool, "Main pool is not defined");
const rebalancerVersion = config.IsTest ? "TestRebalancer" : "Rebalancer";

Expand Down Expand Up @@ -313,6 +366,18 @@ export async function main() {
await usdcStablecoinPool!.grantRole(PAUSER_ROLE, config.Pauser);
}

if (config.USDCPublicPool) {
await usdcPublicPool!.grantRole(WITHDRAW_PROFIT_ROLE, config.WithdrawProfit);
await usdcPublicPool!.grantRole(PAUSER_ROLE, config.Pauser);
await usdcPublicPool!.grantRole(FEE_SETTER_ROLE, config.USDCPublicPool.FeeSetter);
}

if (config.ERC4626AdapterUSDCTargetVault) {
await erc4626AdapterUSDC!.grantRole(LIQUIDITY_ADMIN_ROLE, rebalancer);
await erc4626AdapterUSDC!.grantRole(WITHDRAW_PROFIT_ROLE, config.WithdrawProfit);
await erc4626AdapterUSDC!.grantRole(PAUSER_ROLE, config.Pauser);
}

const repayerVersion = config.IsTest ? "TestRepayer" : "Repayer";

repayerRoutes.Pools = await resolveXAddresses(repayerRoutes.Pools || [], false);
Expand Down Expand Up @@ -432,6 +497,16 @@ export async function main() {
await usdcStablecoinPool!.grantRole(DEFAULT_ADMIN_ROLE, config.Admin);
await usdcStablecoinPool!.renounceRole(DEFAULT_ADMIN_ROLE, deployer);
}

if (config.USDCPublicPool) {
await usdcPublicPool!.grantRole(DEFAULT_ADMIN_ROLE, config.Admin);
await usdcPublicPool!.renounceRole(DEFAULT_ADMIN_ROLE, deployer);
}

if (config.ERC4626AdapterUSDCTargetVault) {
await erc4626AdapterUSDC!.grantRole(DEFAULT_ADMIN_ROLE, config.Admin);
await erc4626AdapterUSDC!.renounceRole(DEFAULT_ADMIN_ROLE, deployer);
}
}

let multicall: string;
Expand Down
67 changes: 67 additions & 0 deletions scripts/deployERC4626Adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import dotenv from "dotenv";
dotenv.config();
import hre from "hardhat";
import {getVerifier, getHardhatNetworkConfig, getNetworkConfig} from "./helpers";
import {resolveProxyXAddress, toBytes32, resolveXAddress} from "../test/helpers";
import {isSet, assert, DEFAULT_ADMIN_ROLE, sameAddress} from "./common";
import {ERC4626Adapter} from "../typechain-types";
import {Network, NetworkConfig, ERC4626AdapterUSDCVersions} from "../network.config";

export async function main() {
const [deployer] = await hre.ethers.getSigners();

const LIQUIDITY_ADMIN_ROLE = toBytes32("LIQUIDITY_ADMIN_ROLE");
const WITHDRAW_PROFIT_ROLE = toBytes32("WITHDRAW_PROFIT_ROLE");
const PAUSER_ROLE = toBytes32("PAUSER_ROLE");

assert(isSet(process.env.DEPLOY_ID), "DEPLOY_ID must be set");
const verifier = getVerifier(process.env.DEPLOY_ID);
console.log(`Deployment ID: ${process.env.DEPLOY_ID}`);
let id = ERC4626AdapterUSDCVersions.at(-1);

let network: Network;
let config: NetworkConfig;
console.log("Deploying ERC4626 Adapter USDC");
({network, config} = await getNetworkConfig());
if (!network) {
({network, config} = await getHardhatNetworkConfig());
id += "-DeployTest";
}

assert(config.ERC4626AdapterUSDCTargetVault, "ERC4626AdapterUSDCTargetVault must be configured");

const rebalancer = await resolveProxyXAddress("Rebalancer");
console.log(`Rebalancer: ${rebalancer}`);

const targetVault = await resolveXAddress(config.ERC4626AdapterUSDCTargetVault);
console.log(`Target Vault: ${targetVault}`);

console.log("Deploying ERC4626 Adapter USDC");
const erc4626AdapterUSDC: ERC4626Adapter = (await verifier.deployX(
"ERC4626Adapter",
deployer,
{},
[
config.USDC,
targetVault,
deployer,
],
id
)) as ERC4626Adapter;
console.log(`${id}: ${erc4626AdapterUSDC.target}`);

await erc4626AdapterUSDC!.grantRole(LIQUIDITY_ADMIN_ROLE, rebalancer);
await erc4626AdapterUSDC!.grantRole(WITHDRAW_PROFIT_ROLE, config.WithdrawProfit);
await erc4626AdapterUSDC!.grantRole(PAUSER_ROLE, config.Pauser);

if (!sameAddress(deployer.address, config.Admin)) {
await erc4626AdapterUSDC!.grantRole(DEFAULT_ADMIN_ROLE, config.Admin);
await erc4626AdapterUSDC!.renounceRole(DEFAULT_ADMIN_ROLE, deployer);
}

await verifier.verify(process.env.VERIFY === "true");
}

if (process.env.SCRIPT_ENV !== "CI") {
main();
}
2 changes: 1 addition & 1 deletion scripts/deployRepayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function main() {
}
}
}
await addLocalPools(config, network, repayerRoutes);
await addLocalPools(config, network, repayerRoutes, false);

if (!config.CCTP) {
config.CCTP = {
Expand Down
Loading
Loading