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
1,120 changes: 0 additions & 1,120 deletions TokenStaking.json

This file was deleted.

31 changes: 14 additions & 17 deletions deploy/07_deploy_token_staking.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HardhatRuntimeEnvironment } from "hardhat/types"
import { DeployFunction } from "hardhat-deploy/types"
import * as fs from "fs"

import { ethers, upgrades } from "hardhat"

Expand All @@ -15,7 +16,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

// TODO: Consider upgradable deployment also for sepolia.
let tokenStakingAddress
if (hre.network.name == "mainnet" || hre.network.name == "sepolia") {
if (hre.network.name === "mainnet" || hre.network.name === "sepolia") {
const TokenStaking = await ethers.getContractFactory("TokenStaking")

const tokenStaking = await upgrades.deployProxy(
Expand All @@ -29,34 +30,30 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
log(`Deployed TokenStaking with TransparentProxy at ${tokenStakingAddress}`)

const implementationInterface = tokenStaking.interface
let jsonAbi = implementationInterface.format(ethers.utils.FormatTypes.json)
const jsonAbi = implementationInterface.format(ethers.utils.FormatTypes.json)

let parsedAbi: unknown[]
try {
parsedAbi = JSON.parse(jsonAbi as string) as unknown[]
} catch (e) {
throw new Error(`Failed to parse ABI from contract interface: ${e}`)
}

const tokenStakingDeployment = {
address: tokenStakingAddress,
abi: JSON.parse(jsonAbi as string),
abi: parsedAbi,
}
const fs = require("fs")
const deploymentsDir = `deployments/${hre.network.name}`
fs.mkdirSync(deploymentsDir, { recursive: true })
await fs.promises.mkdir(deploymentsDir, { recursive: true })

await deployments.save("TokenStaking", tokenStakingDeployment)

fs.writeFileSync(
"TokenStaking.json",
JSON.stringify(tokenStakingDeployment, null, 2),
"utf8",
function (err) {
if (err) {
console.log(err)
}
}
)
fs.writeFileSync(
await fs.promises.writeFile(
`${deploymentsDir}/TokenStaking.json`,
JSON.stringify(tokenStakingDeployment, null, 2),
"utf8"
)
log(`Saved TokenStaking address and ABI in TokenStaking.json`)
log(`Saved TokenStaking address and ABI in ${deploymentsDir}/TokenStaking.json`)
} else {
const TokenStaking = await deployments.deploy("TokenStaking", {
from: deployer,
Expand Down
22 changes: 16 additions & 6 deletions deploy/54_upgrade_token_staking_extended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import { ethers, upgrades } from "hardhat"
* npx hardhat deploy --network sepolia --tags UpgradeTokenStaking
*/
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre
const { deployments } = hre
const { log } = deployments
const { deployer } = await getNamedAccounts()

if (hre.network.name !== "sepolia") {
log("Skipping TokenStaking upgrade (only for sepolia)")
Expand All @@ -31,11 +30,15 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
} else {
// 07_deploy_token_staking saves to TokenStaking.json in deployments dir
const deploymentPath = `deployments/${hre.network.name}/TokenStaking.json`
if (!fs.existsSync(deploymentPath)) {
try {
await fs.promises.access(deploymentPath)
} catch {
log("TokenStaking not deployed, skipping upgrade")
return
}
const deployment = JSON.parse(fs.readFileSync(deploymentPath, "utf8"))
const deployment = JSON.parse(
await fs.promises.readFile(deploymentPath, "utf8")
)
proxyAddress = deployment.address
}

Expand All @@ -57,6 +60,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
ExtendedTokenStaking,
{
constructorArgs: [T.address],
kind: "transparent",
}
)
await upgraded.deployed()
Expand All @@ -66,12 +70,18 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// Update deployment JSON with new ABI (includes stake)
const implementationInterface = upgraded.interface
const jsonAbi = implementationInterface.format(ethers.utils.FormatTypes.json)
let parsedAbi: unknown[]
try {
parsedAbi = JSON.parse(jsonAbi as string) as unknown[]
} catch (e) {
throw new Error(`Failed to parse ABI from contract interface: ${e}`)
}
const tokenStakingDeployment = {
address: upgraded.address,
abi: JSON.parse(jsonAbi as string),
abi: parsedAbi,
}
const deploymentsDir = `deployments/${hre.network.name}`
fs.writeFileSync(
await fs.promises.writeFile(
`${deploymentsDir}/TokenStaking.json`,
JSON.stringify(tokenStakingDeployment, null, 2),
"utf8"
Expand Down
Loading
Loading