Skip to content

Commit

Permalink
feat: added masset-swap HH task
Browse files Browse the repository at this point in the history
chore: verifyEtherscan to ignore local network
  • Loading branch information
naddison36 authored and doncesarts committed Nov 30, 2022
1 parent b344148 commit 8241406
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions tasks/masset.ts
@@ -1,6 +1,7 @@
import { subtask, task, types } from "hardhat/config"
import { Masset__factory } from "types/generated"
import { BN, simpleToExactAmount } from "@utils/math"
import { formatUnits } from "@ethersproject/units"
import { getSignerAccount } from "./utils/signerFactory"
import { logTxDetails } from "./utils/deploy-utils"
import { getChain, resolveAddress, resolveToken } from "./utils/networkAddressFactory"
Expand All @@ -27,9 +28,42 @@ subtask("masset-redeem", "Redeems a number of Save credits from a savings contra

const tx = await mAsset.redeem(bAsset.address, amount, minAmount, signerAccount.address)
await logTxDetails(tx, `redeem ${taskArgs.amount} ${taskArgs.masset} for ${taskArgs.basset}`)
const receipt = await tx.wait()
const event = receipt.events?.find((e) => e.event === "Redeemed")
console.log(`Redeemed ${event.args[4]} ${taskArgs.basset}`)
console.log(`Redeemed ${formatUnits(event.args[4], bAsset.decimals)} ${taskArgs.basset}`)
})
task("masset-redeem").setAction(async (_, __, runSuper) => {
await runSuper()
})

subtask("masset-swap", "Redeems a number of Save credits from a savings contract")
.addParam("masset", "Symbol of the mAsset. eg mUSD or mBTC", undefined, types.string)
.addParam("from", "Symbol of the bAsset. eg USDC, DAI, USDT or DAI", undefined, types.string)
.addParam("to", "Symbol of the bAsset. eg USDC, DAI, USDT or DAI", undefined, types.string)
.addParam("amount", "Amount of mAssets to be redeemed", undefined, types.float)
.addOptionalParam("speed", "Defender Relayer speed param: 'safeLow' | 'average' | 'fast' | 'fastest'", "fast", types.string)
.setAction(async (taskArgs, hre) => {
const { amount, from, to, masset, speed } = taskArgs
const chain = getChain(hre)
const signerAccount = await getSignerAccount(hre, speed)

const mAssetAddress = resolveAddress(masset, chain, "address")
const fromToken = resolveToken(from, chain, "address")
const toToken = resolveToken(to, chain, "address")

const mAsset = Masset__factory.connect(mAssetAddress, signerAccount.signer)

const input = simpleToExactAmount(amount)

const tx = await mAsset.swap(fromToken.address, toToken.address, input, 0, signerAccount.address)
await logTxDetails(tx, `swapped ${amount} ${fromToken.symbol} to ${toToken.symbol}`)
// const receipt = await tx.wait()
// const event = receipt.events?.find((e) => e.event === "Swapped")
// console.log(`Swapped ${formatUnits(event.args[4], bAsset.decimals)} ${taskArgs.basset}`)
})
task("masset-swap").setAction(async (_, __, runSuper) => {
await runSuper()
})

module.exports = {}
2 changes: 1 addition & 1 deletion tasks/utils/etherscan.ts
Expand Up @@ -13,7 +13,7 @@ interface VerifyEtherscan {
}

export const verifyEtherscan = async (hre: HardhatRuntimeEnvironment, contract: VerifyEtherscan): Promise<void> => {
if (hre.network.name !== "hardhat") {
if (hre.network.name !== "hardhat" && hre.network.name !== "local") {
// wait for the Etherscan backend to pick up the deployed contract
await sleep(10000)

Expand Down

0 comments on commit 8241406

Please sign in to comment.