-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathsave.ts
48 lines (39 loc) · 2.29 KB
/
save.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { subtask, task, types } from "hardhat/config"
import { SavingsContract__factory } from "types/generated"
import { simpleToExactAmount } from "@utils/math"
import { getSignerAccount } from "./utils/signerFactory"
import { logTxDetails } from "./utils/deploy-utils"
import { getChain, resolveAddress } from "./utils/networkAddressFactory"
subtask("save-deposit", "Deposit to savings contract")
.addParam("masset", "Symbol of the mAsset. eg mUSD or mBTC", undefined, types.string)
.addParam("amount", "Amount to be staked", undefined, types.float)
.addOptionalParam("speed", "Defender Relayer speed param: 'safeLow' | 'average' | 'fast' | 'fastest'", "fast", types.string)
.setAction(async (taskArgs, hre) => {
const chain = getChain(hre)
const signerAccount = await getSignerAccount(hre, taskArgs.speed)
const saveAddress = resolveAddress(taskArgs.masset, chain, "savings")
const save = SavingsContract__factory.connect(saveAddress, signerAccount.signer)
const amount = simpleToExactAmount(taskArgs.amount)
const tx = await save["depositSavings(uint256)"](amount)
await logTxDetails(tx, `deposit ${taskArgs.amount} ${taskArgs.masset} in Save`)
})
task("save-deposit").setAction(async (_, __, runSuper) => {
await runSuper()
})
subtask("save-redeem", "Redeems a number of Save credits from a savings contract")
.addParam("masset", "Symbol of the mAsset. eg mUSD or mBTC", undefined, types.string)
.addParam("amount", "Amount of Save credits to be redeemed", undefined, types.float)
.addOptionalParam("speed", "Defender Relayer speed param: 'safeLow' | 'average' | 'fast' | 'fastest'", "fast", types.string)
.setAction(async (taskArgs, hre) => {
const chain = getChain(hre)
const signerAccount = await getSignerAccount(hre, taskArgs.speed)
const saveAddress = resolveAddress(taskArgs.masset, chain, "savings")
const save = SavingsContract__factory.connect(saveAddress, signerAccount.signer)
const amount = simpleToExactAmount(taskArgs.amount)
const tx = await save["redeem(uint256)"](amount)
await logTxDetails(tx, `redeem ${taskArgs.amount} ${taskArgs.masset} in Save`)
})
task("save-redeem").setAction(async (_, __, runSuper) => {
await runSuper()
})
module.exports = {}