Skip to content

Commit

Permalink
Kava mainnet 3pool deploy (saddle-finance#648)
Browse files Browse the repository at this point in the history
* kava mainnet deployment of 2pool

* changed deployment to 3pool

* added hardhat-deploy verification and pool registry

* updated token args

* updated deploys to not use multisig

* test commit

* fixed typo

* fixed typo is hardhat config

* added kava deployer account to hardhat config

* deployed to mainnet

* Add arbitrary API key for blockscout explorer

Co-authored-by: Jongseung Lim <[email protected]>
  • Loading branch information
lilPlumberBoy and penandlim authored Jul 29, 2022
1 parent fa44682 commit 22b8cb8
Show file tree
Hide file tree
Showing 32 changed files with 9,759 additions and 5 deletions.
30 changes: 30 additions & 0 deletions deploy/kava_mainnet/002_deploy_LPToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { HardhatRuntimeEnvironment } from "hardhat/types"
import { DeployFunction } from "hardhat-deploy/types"

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts, getChainId } = hre
const { deploy, execute, getOrNull, log } = deployments
const { libraryDeployer } = await getNamedAccounts()

const lpToken = await getOrNull("LPToken")
if (lpToken) {
log(`reusing "LPToken" at ${lpToken.address}`)
} else {
await deploy("LPToken", {
from: libraryDeployer,
log: true,
skipIfAlreadyDeployed: true,
waitConfirmations: 3,
})

await execute(
"LPToken",
{ from: libraryDeployer, log: true },
"initialize",
"Saddle LP Token (Target)",
"saddleLPTokenTarget",
)
}
}
export default func
func.tags = ["LPToken"]
16 changes: 16 additions & 0 deletions deploy/kava_mainnet/003_deploy_AmplificationUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { HardhatRuntimeEnvironment } from "hardhat/types"
import { DeployFunction } from "hardhat-deploy/types"

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts, getChainId } = hre
const { deploy } = deployments
const { libraryDeployer } = await getNamedAccounts()

await deploy("AmplificationUtils", {
from: libraryDeployer,
log: true,
skipIfAlreadyDeployed: true,
})
}
export default func
func.tags = ["AmplificationUtils"]
16 changes: 16 additions & 0 deletions deploy/kava_mainnet/004_deploy_SwapUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { HardhatRuntimeEnvironment } from "hardhat/types"
import { DeployFunction } from "hardhat-deploy/types"

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts, getChainId } = hre
const { deploy, get } = deployments
const { libraryDeployer } = await getNamedAccounts()

await deploy("SwapUtils", {
from: libraryDeployer,
log: true,
skipIfAlreadyDeployed: true,
})
}
export default func
func.tags = ["SwapUtils"]
16 changes: 16 additions & 0 deletions deploy/kava_mainnet/005_deploy_MetaSwapUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { HardhatRuntimeEnvironment } from "hardhat/types"
import { DeployFunction } from "hardhat-deploy/types"

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre
const { deploy, get } = deployments
const { libraryDeployer } = await getNamedAccounts()

await deploy("MetaSwapUtils", {
from: libraryDeployer,
log: true,
skipIfAlreadyDeployed: true,
})
}
export default func
func.tags = ["MetaSwapUtils"]
22 changes: 22 additions & 0 deletions deploy/kava_mainnet/006_deploy_SwapFlashLoan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { HardhatRuntimeEnvironment } from "hardhat/types"
import { DeployFunction } from "hardhat-deploy/types"

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts, getChainId } = hre
const { deploy, get } = deployments
const { libraryDeployer } = await getNamedAccounts()

await deploy("SwapFlashLoan", {
from: libraryDeployer,
log: true,
libraries: {
SwapUtils: (await get("SwapUtils")).address,
AmplificationUtils: (await get("AmplificationUtils")).address,
},
skipIfAlreadyDeployed: true,
waitConfirmations: 3,
})
}
export default func
func.tags = ["SwapFlashLoan"]
func.dependencies = ["AmplificationUtils", "SwapUtils"]
44 changes: 44 additions & 0 deletions deploy/kava_mainnet/110_check_Kava3PoolTokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { HardhatRuntimeEnvironment } from "hardhat/types"
import { DeployFunction } from "hardhat-deploy/types"
import { isTestNetwork } from "../../utils/network"
import { BigNumber } from "ethers"

const USD_TOKENS_ARGS: { [token: string]: any[] } = {
USDC: ["USD Coin", "USDC", "6"],
USDT: ["Tether", "USDT", "6"],
DAI: ["Dai Stablecoin", "DAI", "18"],
}

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts, getChainId } = hre
const { deploy, execute, getOrNull, log } = deployments
const { deployer } = await getNamedAccounts()

for (const token in USD_TOKENS_ARGS) {
const token_contracts = await getOrNull(token)
if (!token_contracts) {
await deploy(token, {
from: deployer,
log: true,
contract: "GenericERC20",
args: USD_TOKENS_ARGS[token],
skipIfAlreadyDeployed: true,
})
// If it's on hardhat, mint test tokens
if (isTestNetwork(await getChainId())) {
const decimals = USD_TOKENS_ARGS[token][2]
await execute(
token,
{ from: deployer, log: true },
"mint",
deployer,
BigNumber.from(10).pow(decimals).mul(1000000),
)
}
} else {
log(`reusing ${token} at ${token_contracts.address}`)
}
}
}
export default func
func.tags = ["saddle3poolTokens"]
85 changes: 85 additions & 0 deletions deploy/kava_mainnet/111_deploy_Kava3Pool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { HardhatRuntimeEnvironment } from "hardhat/types"
import { DeployFunction } from "hardhat-deploy/types"
import { ZERO_ADDRESS } from "../../test/testUtils"

// Deployment Names
const POOL_NAME = "Saddle3Pool"

// Constructor arguments
const TOKEN_NAMES = ["USDC", "USDT", "DAI"]
const LP_TOKEN_NAME = "Saddle USDC/USDT/DAI LP Token"
const LP_TOKEN_SYMBOL = "saddle3Pool"
const INITIAL_A = 500
const SWAP_FEE = 4e6 // 4bps
const ADMIN_FEE = 5e9 // 50% of the 4bps

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre
const { execute, deploy, get, getOrNull, log, read, save } = deployments
const { deployer } = await getNamedAccounts()
const poolLpTokenName = `${POOL_NAME}LPToken`

// Manually check if the pool is already deployed
const poolContract = await getOrNull(POOL_NAME)

// Check if has been initialized
const isInitialized: boolean = poolContract
? (await read(POOL_NAME, "swapStorage")).lpToken !== ZERO_ADDRESS
: false

if (poolContract && isInitialized) {
log(`reusing ${POOL_NAME} at ${poolContract.address}`)
} else {
const TOKEN_ADDRESSES = await Promise.all(
TOKEN_NAMES.map(async (name) => (await get(name)).address),
)
const tokenDecimals = await Promise.all(
TOKEN_NAMES.map(async (name) => await read(name, "decimals")),
)

await deploy(POOL_NAME, {
from: deployer,
log: true,
contract: "SwapFlashLoan",
skipIfAlreadyDeployed: true,
libraries: {
SwapUtils: (await get("SwapUtils")).address,
AmplificationUtils: (await get("AmplificationUtils")).address,
},
})
await execute(
POOL_NAME,
{
from: deployer,
log: true,
},
"initialize",
TOKEN_ADDRESSES,
tokenDecimals,
LP_TOKEN_NAME,
LP_TOKEN_SYMBOL,
INITIAL_A,
SWAP_FEE,
ADMIN_FEE,
(
await get("LPToken")
).address,
)

const lpTokenAddress = (await read(POOL_NAME, "swapStorage")).lpToken
log(`deployed ${poolLpTokenName} at ${lpTokenAddress}`)

await save(poolLpTokenName, {
abi: (await get("LPToken")).abi, // LPToken ABI
address: lpTokenAddress,
})
}
}
export default func
func.tags = [POOL_NAME]
func.dependencies = [
"SwapUtils",
"SwapFlashLoan",
"SwapDeployer",
"saddle3poolTokens",
]
29 changes: 29 additions & 0 deletions deploy/kava_mainnet/120_deploy_Muticall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { DeployFunction } from "hardhat-deploy/types"
import { HardhatRuntimeEnvironment } from "hardhat/types"

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts, getChainId } = hre
const { deploy, save } = deployments
const { deployer } = await getNamedAccounts()

await deploy("Multicall", {
from: deployer,
log: true,
skipIfAlreadyDeployed: true,
})

await deploy("Multicall2", {
from: deployer,
log: true,
skipIfAlreadyDeployed: true,
})

await deploy("Multicall3", {
from: deployer,
log: true,
skipIfAlreadyDeployed: true,
})
}

export default func
func.tags = ["Multicall"]
18 changes: 18 additions & 0 deletions deploy/kava_mainnet/160_deploy_PoolRegistry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { HardhatRuntimeEnvironment } from "hardhat/types"
import { DeployFunction } from "hardhat-deploy/types"

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts, getChainId } = hre
const { deploy } = deployments
const { deployer } = await getNamedAccounts()

await deploy("PoolRegistry", {
from: deployer,
log: true,
skipIfAlreadyDeployed: true,
args: [deployer, deployer],
})
// NOTE: both manager and admin role are given to deployer since gnosis safe is not working on kava
}
export default func
func.tags = ["PoolRegistry"]
56 changes: 56 additions & 0 deletions deploy/kava_mainnet/161_add_to_PoolRegistry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { HardhatRuntimeEnvironment } from "hardhat/types"
import { DeployFunction } from "hardhat-deploy/types"
import { PoolRegistry } from "../../build/typechain"
import { ZERO_ADDRESS } from "../../test/testUtils"
import { PoolType } from "../../utils/constants"
import { IPoolRegistry } from "../../build/typechain/"

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts, getChainId, ethers } = hre
const { deploy, get, getOrNull, execute, read, log } = deployments
const { deployer } = await getNamedAccounts()

const poolRegistry: PoolRegistry = await ethers.getContract("PoolRegistry")

const pools: IPoolRegistry.PoolInputDataStruct[] = [
{
// Saddle3Pool
poolAddress: (await get("Saddle3Pool")).address,
typeOfAsset: PoolType.USD,
poolName: ethers.utils.formatBytes32String("USDC-USDT-DAI"),
targetAddress: (await get("SwapFlashLoan")).address,
metaSwapDepositAddress: ZERO_ADDRESS,
isSaddleApproved: true,
isRemoved: false,
isGuarded: false,
},
]

await poolRegistry
.getPoolDataByName(pools[0].poolName)
.then(() => {
log("Skipping adding pools to registry because they are already added")
})
.catch(async () => {
log("Adding pools to registry")

const batchCall = await Promise.all(
pools.map(
async (pool) => await poolRegistry.populateTransaction.addPool(pool),
),
)

const batchCallData = batchCall
.map((x) => x.data)
.filter((x): x is string => !!x)

await execute(
"PoolRegistry",
{ from: deployer, log: true },
"batch",
batchCallData,
true,
)
})
}
export default func
41 changes: 41 additions & 0 deletions deploy/kava_mainnet/999_verify_all_contracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { HardhatRuntimeEnvironment } from "hardhat/types"
import { DeployFunction } from "hardhat-deploy/types"
import { CHAIN_ID } from "../../utils/network"

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getChainId, ethers } = hre
const { log } = deployments
const contracts: string[] = [
"LPToken",
"AmplificationUtils",
"SwapUtils",
"MetaSwapUtils",
"SwapFlashLoan",
"Saddle3Pool",
"Muticall",
"Muticall2",
"Muticall3",
]

if ((await getChainId()) === CHAIN_ID.KAVA_MAINNET) {
for (let i = 0; i < contracts.length; i++) {
const contractName = contracts[i]
const contract = await ethers.getContract(contracts[i])
try {
await hre.run("etherscan-verify", {
contractName: contractName,
})
console.log(
`Successfully verified ${contractName} at ${contract.address}`,
)
} catch (error) {
console.log("verification failed with: ", error)
}
}
} else {
log(
`Skipping verification since this is not running on ${CHAIN_ID.KAVA_MAINNET}`,
)
}
}
export default func
1 change: 1 addition & 0 deletions deployments/kava_mainnet/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2222
Loading

0 comments on commit 22b8cb8

Please sign in to comment.