-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathvault.ts
142 lines (119 loc) · 6.99 KB
/
vault.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { subtask, task, types } from "hardhat/config"
import { BoostedVault__factory, StakingRewards__factory } from "types/generated"
import { simpleToExactAmount } from "@utils/math"
import { formatUnits } from "ethers/lib/utils"
import { getSignerAccount } from "./utils/signerFactory"
import { logTxDetails } from "./utils/deploy-utils"
import { getChain, resolveAddress } from "./utils/networkAddressFactory"
import { usdFormatter } from "./utils/quantity-formatters"
import { getBlock } from "./utils/snap-utils"
subtask("vault-snap", "Dumps user data for a vault")
.addParam("user", "Address or contract name of user", undefined, types.string)
.addOptionalParam("asset", "Symbol of the asset that has a mStable vault. eg mUSD, alUSD, MTA", "mUSD", types.string)
.addOptionalParam("block", "Block number to compare rates at. (default: current block)", 0, types.int)
.setAction(async (taskArgs, hre) => {
const chain = getChain(hre)
const signerAccount = await getSignerAccount(hre, taskArgs.speed)
const userAddress = resolveAddress(taskArgs.user, chain)
const block = await getBlock(hre.ethers, taskArgs.block)
const overrides = {
blockTag: block.blockNumber,
}
console.log(`\nGetting vault data for user ${taskArgs.user} at block ${block.blockNumber}, ${block.blockTime}`)
const vaultAddress = resolveAddress(taskArgs.asset, chain, "vault")
const vault = BoostedVault__factory.connect(vaultAddress, signerAccount.signer)
// Balances
const rawBalance = await vault.rawBalanceOf(userAddress, overrides)
const boostedBalance = await vault.balanceOf(userAddress, overrides)
console.log(`Raw balance ${usdFormatter(rawBalance)}`)
console.log(`Boosted balance ${usdFormatter(boostedBalance)}`)
// Boost
if (rawBalance.gt(0)) {
const effectiveBoost = boostedBalance.mul(10000).div(rawBalance)
const boost = await vault.getBoost(userAddress, overrides)
console.log(`Effective boost ${formatUnits(effectiveBoost, 4).padStart(14)}x`)
console.log(`getBoost ${formatUnits(boost, 18).padStart(14)}x`)
}
// Rewards
const rewardsUnclaimed = await vault.unclaimedRewards(userAddress, overrides)
const rewardsClaimed = await vault.userClaim(userAddress, overrides)
const rewardsEarned = await vault.earned(userAddress, overrides)
const userData = await vault.userData(userAddress, overrides)
console.log(`Unclaimed ${usdFormatter(rewardsUnclaimed.amount)}`)
console.log(`Claimed ${usdFormatter(rewardsClaimed)}`)
console.log(`Earned ${usdFormatter(rewardsEarned)}`)
console.log(`Last action ${new Date(userData.lastAction.toNumber() * 1000)}`)
if (rewardsUnclaimed.first.gt(0)) {
console.log(`First claim ${new Date(rewardsUnclaimed.first.toNumber() * 1000)}`)
console.log(`Last claim ${new Date(rewardsUnclaimed.last.toNumber() * 1000)}`)
}
if (hre.network.name === "hardhat") {
await vault.pokeBoost(userAddress)
const boost = await vault.getBoost(userAddress)
console.log(`getBoost after poke ${formatUnits(boost, 18).padStart(14)}x`)
}
})
task("vault-snap").setAction(async (_, __, runSuper) => {
await runSuper()
})
subtask("vault-stake", "Stake into a vault")
.addParam("asset", "Symbol of the asset that has a mStable vault. eg mUSD, alUSD, MTA", 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 vaultAddress = resolveAddress(taskArgs.asset, chain, "vault")
const vault = StakingRewards__factory.connect(vaultAddress, signerAccount.signer)
const amount = simpleToExactAmount(taskArgs.amount)
const tx = await vault["stake(uint256)"](amount)
await logTxDetails(tx, `${signerAccount.address} stakes ${taskArgs.amount} ${taskArgs.asset} in vault`)
})
task("vault-stake").setAction(async (_, __, runSuper) => {
await runSuper()
})
subtask("vault-withdraw", "Withdraw from a vault")
.addParam("asset", "Symbol of the asset that has a mStable vault. eg mUSD, alUSD, MTA", undefined, types.string)
.addParam("amount", "Amount to be withdrawn", 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 vaultAddress = resolveAddress(taskArgs.asset, chain, "vault")
const vault = StakingRewards__factory.connect(vaultAddress, signerAccount.signer)
const amount = simpleToExactAmount(taskArgs.amount)
const tx = await vault.withdraw(amount)
await logTxDetails(tx, `${signerAccount.address} withdraw ${taskArgs.amount} ${taskArgs.asset} from vault`)
})
task("vault-withdraw").setAction(async (_, __, runSuper) => {
await runSuper()
})
subtask("vault-exit", "Exit from vault claiming rewards")
.addParam("asset", "Symbol of the asset that has a mStable vault. eg mUSD, alUSD, MTA", undefined, types.string)
.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 vaultAddress = resolveAddress(taskArgs.asset, chain, "vault")
const vault = StakingRewards__factory.connect(vaultAddress, signerAccount.signer)
const tx = await vault.exit()
await logTxDetails(tx, `${signerAccount.address} exits ${taskArgs.asset} vault`)
})
task("vault-exit").setAction(async (_, __, runSuper) => {
await runSuper()
})
subtask("vault-claim", "Claim rewards from vault")
.addParam("asset", "Symbol of the asset that has a mStable vault. eg mUSD, alUSD, MTA", undefined, types.string)
.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 vaultAddress = resolveAddress(taskArgs.asset, chain, "vault")
const vault = StakingRewards__factory.connect(vaultAddress, signerAccount.signer)
const tx = await vault.claimReward()
await logTxDetails(tx, `${signerAccount.address} claim rewards from ${taskArgs.asset} vault`)
})
task("vault-claim").setAction(async (_, __, runSuper) => {
await runSuper()
})
module.exports = {}