Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Curve Hardhat task #2282

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
58 changes: 33 additions & 25 deletions contracts/tasks/amoStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
displayPortion,
displayRatio,
} = require("./curve");
const { logTxDetails } = require("../utils/txLogger");

const log = require("../utils/logger")("task:curve");

Expand Down Expand Up @@ -49,7 +50,7 @@ async function amoStrategyTask(taskArguments) {
vault,
} = await curveContracts(poolOTokenSymbol);

// Strategy's Metapool LPs in the Convex pool
// Strategy's Curve LPs in the Convex pool
const vaultLPsBefore =
diffBlocks &&
(await cvxRewardPool.balanceOf(amoStrategy.address, {
Expand Down Expand Up @@ -83,9 +84,9 @@ async function amoStrategyTask(taskArguments) {
diffBlocks && oTokenSupplyBefore.sub(strategyOTokensInPoolBefore);
const vaultAdjustedTotalSupply = oTokenSupply.sub(strategyOTokensInPool);

// Strategy's Metapool LPs in the Convex pool
// Strategy's LPs in the Convex pool
output(
`\nvault Metapool LPs : ${displayPortion(
`\nStrategy's Curve LPs : ${displayPortion(
vaultLPs,
totalLPs,
poolLPSymbol,
Expand All @@ -94,7 +95,7 @@ async function amoStrategyTask(taskArguments) {
);
// Strategy's share of the assets in the pool
output(
`assets owned by strategy : ${displayPortion(
`Assets owned by strategy : ${displayPortion(
strategyAssetsInPool,
vaultAdjustedTotalValue,
assetSymbol,
Expand All @@ -112,15 +113,15 @@ async function amoStrategyTask(taskArguments) {
strategyOTokensInPool,
vaultAdjustedTotalValue,
oTokenSymbol,
"OToken supply"
"adjusted vault value"
)} ${displayDiff(
diffBlocks,
strategyOTokensInPool,
strategyOTokensInPoolBefore
)}`
);
const stratTotalInPool = strategyAssetsInPool.add(strategyOTokensInPool);
output(`both owned by strategy : ${formatUnits(stratTotalInPool)}`);
output(`Both owned by strategy : ${formatUnits(stratTotalInPool)}`);

// Strategy asset values
let totalStrategyAssetsValueBefore = BigNumber.from(0);
Expand Down Expand Up @@ -151,7 +152,7 @@ async function amoStrategyTask(taskArguments) {
strategyAssetsValueScaled
);
output(
`strategy ${symbol.padEnd(4)} value : ${displayPortion(
`Strategy ${symbol.padEnd(4)} value : ${displayPortion(
strategyAssetsValueScaled,
vaultTotalValue,
symbol,
Expand All @@ -164,7 +165,7 @@ async function amoStrategyTask(taskArguments) {
);
}
output(
`strategy total value : ${displayPortion(
`Strategy total value : ${displayPortion(
totalStrategyAssetsValue,
vaultTotalValue,
assetSymbol,
Expand All @@ -186,7 +187,7 @@ async function amoStrategyTask(taskArguments) {
strategyOTokensInPool
);
output(
`strategy adjusted value : ${displayPortion(
`Strategy adjusted value : ${displayPortion(
strategyAdjustedValue,
vaultAdjustedTotalValue,
assetSymbol,
Expand All @@ -206,6 +207,7 @@ async function amoStrategyTask(taskArguments) {
)}`
);

console.log("");
for (const asset of assets) {
const assetsInVaultBefore =
diffBlocks &&
Expand All @@ -226,28 +228,29 @@ async function amoStrategyTask(taskArguments) {
)
);
}

// Vault's total value v total supply
output(
displayProperty(
"\nOToken total supply",
"\nOToken total supply ",
oTokenSymbol,
oTokenSupply,
oTokenSupplyBefore
)
);
output(
displayProperty(
"vault assets value",
"Vault assets value",
assetSymbol,
totalStrategyAssetsValue,
totalStrategyAssetsValueBefore
vaultTotalValue,
vaultTotalValueBefore
)
);
output(
`total value - supply : ${displayRatio(
totalStrategyAssetsValue,
`Total value - supply : ${displayRatio(
vaultTotalValue,
oTokenSupply,
totalStrategyAssetsValueBefore,
vaultTotalValueBefore,
oTokenSupplyBefore
)}`
);
Expand All @@ -262,14 +265,14 @@ async function amoStrategyTask(taskArguments) {
);
output(
displayProperty(
"vault adjusted value",
"Vault adjusted value",
assetSymbol,
vaultAdjustedTotalValue,
vaultAdjustedTotalValueBefore
)
);
output(
`adjusted value - supply : ${displayRatio(
`Adjusted value - supply : ${displayRatio(
vaultAdjustedTotalValue,
vaultAdjustedTotalSupply,
vaultAdjustedTotalValueBefore,
Expand All @@ -288,7 +291,7 @@ async function amoStrategyTask(taskArguments) {

output(
displayProperty(
"\nNet minted for strategy",
"\nNet minted for strategy ",
assetSymbol,
netMintedForStrategy
)
Expand Down Expand Up @@ -329,9 +332,10 @@ async function mintAndAddOTokensTask(taskArguments) {
const signer = await getSigner();

const amountUnits = parseUnits(amount.toString());
log(`Minting ${formatUnits(amountUnits)} ${symbol} and adding to Metapool`);
log(`Minting ${formatUnits(amountUnits)} ${symbol} and adding to Curve pool`);

await amoStrategy.connect(signer).mintAndAddOTokens(amountUnits);
const tx = await amoStrategy.connect(signer).mintAndAddOTokens(amountUnits);
await logTxDetails(tx, "mintAndAddOTokens");
}

async function removeAndBurnOTokensTask(taskArguments) {
Expand All @@ -353,10 +357,13 @@ async function removeAndBurnOTokensTask(taskArguments) {
log(
`Remove OTokens using ${formatUnits(
amountUnits
)} ${symbol} Metapool LP tokens and burn the OTokens`
)} ${symbol} Curve LP tokens and burn the OTokens`
);

await amoStrategy.connect(signer).removeAndBurnOTokens(amountUnits);
const tx = await amoStrategy
.connect(signer)
.removeAndBurnOTokens(amountUnits);
await logTxDetails(tx, "removeAndBurnOTokens");
}

async function removeOnlyAssetsTask(taskArguments) {
Expand All @@ -378,10 +385,11 @@ async function removeOnlyAssetsTask(taskArguments) {
log(
`Remove ETH using ${formatUnits(
amountUnits
)} ${symbol} Metapool LP tokens and add to ${symbol} Vault`
)} ${symbol} Curve LP tokens and add to ${symbol} Vault`
);

await amoStrategy.connect(signer).removeOnlyAssets(amountUnits);
const tx = await amoStrategy.connect(signer).removeOnlyAssets(amountUnits);
await logTxDetails(tx, "removeOnlyAssets");
}

module.exports = {
Expand Down
36 changes: 31 additions & 5 deletions contracts/tasks/curve.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,19 @@ async function curvePool({

// Total Metapool assets
const totalBalances = poolBalances[0].add(poolBalances[1]);
const excessAssetsBefore =
diffBlocks &&
(poolBalancesBefore[1].gt(poolBalancesBefore[0])
? poolBalancesBefore[1].sub(poolBalancesBefore[0])
: poolBalancesBefore[0].sub(poolBalancesBefore[1]));
const excessAssets = poolBalances[1].gt(poolBalances[0])
? poolBalances[1].sub(poolBalances[0])
: poolBalances[0].sub(poolBalances[1]);
const excessAssetsSymbol = poolBalances[1].gt(poolBalances[0])
? oTokenSymbol
: assetSymbol;
output(
`total assets in pool : ${displayPortion(
`Total assets in pool : ${displayPortion(
poolBalances[0],
totalBalances,
assetSymbol,
Expand All @@ -147,14 +158,23 @@ async function curvePool({
)} ${displayDiff(diffBlocks, poolBalances[0], poolBalancesBefore[0])}`
);
output(
`total OTokens in pool : ${displayPortion(
`Total OTokens in pool : ${displayPortion(
poolBalances[1],
totalBalances,
oTokenSymbol,
"pool",
4
)} ${displayDiff(diffBlocks, poolBalances[1], poolBalancesBefore[1])}`
);
output(
displayProperty(
`Excess assets`,
`${excessAssetsSymbol}`,
excessAssets,
excessAssetsBefore,
4
)
);

return {
totalLPsBefore,
Expand Down Expand Up @@ -280,17 +300,22 @@ async function curveSwapTask(taskArguments) {

const signer = await getSigner();

const fromAmount = parseUnits(from.toString());
const fromAmount = parseUnits(amount.toString());
const minAmount = parseUnits(min.toString());
log(`Swapping ${formatUnits(fromAmount)} ${from}`);

const fromIndex = from === "ETH" || from === "3CRV" ? 0 : 1;
const toIndex = from === "ETH" || from === "3CRV" ? 1 : 0;

const override = from === "ETH" ? { value: amount } : {};

log(
`Swapping ${formatUnits(
fromAmount
)} ${from} from index ${fromIndex} to index ${toIndex}`
);
// prettier-ignore
await pool
.connect(signer).exchange(
.connect(signer)["exchange(int128,int128,uint256,uint256)"](
fromIndex,
toIndex,
fromAmount,
Expand All @@ -310,6 +335,7 @@ async function curveContracts(oTokenSymbol) {
oTokenSymbol === "OETH"
? addresses.mainnet.CurveOETHMetaPool
: addresses.mainnet.CurveOUSDMetaPool;
log(`Resolved ${oTokenSymbol} Curve pool to ${poolAddr}`);
const strategyAddr =
oTokenSymbol === "OETH"
? addresses.mainnet.ConvexOETHAMOStrategy
Expand Down
2 changes: 1 addition & 1 deletion contracts/tasks/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ subtask(
)
.addParam(
"amount",
"Amount of Metapool LP tokens to burn for removed OTokens",
"Amount of Curve LP tokens to burn for removed OTokens",
0,
types.float
)
Expand Down
Loading