-
Notifications
You must be signed in to change notification settings - Fork 83
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
Hardhat tasks #2234
Hardhat tasks #2234
Changes from 9 commits
1905e81
4f68266
b380bcf
7b887b1
e4f879f
91cd715
63cc9e2
b9cf497
57ad699
6c01fbe
09967c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
contract ForceEtherSender { | ||
// Constructor to optionally receive Ether upon deployment | ||
constructor() payable {} | ||
|
||
// Function to allow the contract to receive Ether | ||
receive() external payable {} | ||
|
||
// Function to self-destruct and force-send Ether to an address | ||
function forceSend(address payable recipient) external { | ||
// Requires that the contract has a balance greater than 0 | ||
require(address(this).balance > 0, "No Ether to send"); | ||
|
||
// selfdestruct sends all Ether held by the contract to the recipient | ||
selfdestruct(recipient); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
const { formatUnits } = require("ethers").utils; | ||
const { BigNumber } = require("ethers"); | ||
const { getBlock } = require("./block"); | ||
const { resolveAsset, resolveContract } = require("../utils/resolvers"); | ||
const { getSigner } = require("../utils/signers"); | ||
const { base } = require("../utils/addresses"); | ||
|
||
const snapAero = async ({ block }) => { | ||
const signer = await getSigner(); | ||
const blockTag = await getBlock(block); | ||
|
||
const weth = await resolveAsset("WETH"); | ||
const vault = await resolveContract("OETHBaseVaultProxy", "IVault"); | ||
const oeth = await resolveContract("OETHBaseProxy", "OETHBase"); | ||
const pool = await resolveContract(base.aerodromeOETHbWETHClPool, "ICLPool"); | ||
const aeroStrat = await resolveContract( | ||
`AerodromeAMOStrategyProxy`, | ||
"AerodromeAMOStrategy" | ||
); | ||
const sugarHelper = await resolveContract(base.sugarHelper, "ISugarHelper"); | ||
|
||
const Q96 = BigNumber.from(2).pow(96); | ||
const sqrtRatioX96TickLower = BigNumber.from("79224201403219477170569942574"); // -1 tick | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These could be read from the strategy contract. Would make it easier to use the same script for different strategies: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. I'll add |
||
const sqrtRatioX96TickHigher = BigNumber.from( | ||
"79228162514264337593543950336" | ||
); // 0 tick | ||
|
||
const { tick, sqrtPriceX96 } = await pool.connect(signer).slot0({ blockTag }); | ||
const { liquidityGross } = await pool.connect(signer).ticks(-1, { blockTag }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the -1 tick is true for this strategy, might be a different thing for other chain strategies. Available as a constant here: https://github.com/OriginProtocol/origin-dollar/blob/master/contracts/contracts/strategies/aerodrome/AerodromeAMOStrategy.sol#L67 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea. I'll change |
||
const { amount0: tickWethBalance, amount1: tickOethBalance } = | ||
await sugarHelper | ||
.connect(signer) | ||
.getAmountsForLiquidity( | ||
sqrtPriceX96, | ||
sqrtRatioX96TickLower, | ||
sqrtRatioX96TickHigher, | ||
liquidityGross, | ||
{ blockTag } | ||
); | ||
|
||
// Pool balances | ||
const poolPrice = sqrtPriceX96 | ||
.mul(sqrtPriceX96) | ||
.mul(10000000000) | ||
.div(Q96) | ||
.div(Q96); | ||
const poolWethBalance = await weth | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good to know this isn't WETH liquidity in the pool, rather WETH balance/tokens of the pool. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add the pool balances so we can see when its different to the actual WETH balance There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought there was a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it is pretty annoying that there isn't a simple way to get that data off of the contract |
||
.connect(signer) | ||
.balanceOf(base.aerodromeOETHbWETHClPool, { blockTag }); | ||
const poolOethBalance = await oeth | ||
.connect(signer) | ||
.balanceOf(base.aerodromeOETHbWETHClPool, { blockTag }); | ||
const poolTotal = poolWethBalance.add(poolOethBalance); | ||
const poolWethPercentage = poolWethBalance.mul(10000).div(poolTotal); | ||
const poolOethPercentage = poolOethBalance.mul(10000).div(poolTotal); | ||
|
||
// Tick balances | ||
const tickTotal = tickWethBalance.add(tickOethBalance); | ||
const tickWethPercentage = tickWethBalance.mul(10000).div(tickTotal); | ||
const tickOethPercentage = tickOethBalance.mul(10000).div(tickTotal); | ||
const tickTotalPercentage = tickTotal.mul(10000).div(poolTotal); | ||
|
||
// Strategy's tick position | ||
const { | ||
_amountWeth: tickStratWethBalance, | ||
_amountOethb: tickStratOethBalance, | ||
} = await aeroStrat.getPositionPrincipal(); | ||
const tickStratTotal = tickStratWethBalance.add(tickStratOethBalance); | ||
const tickStratWethPercentage = tickStratWethBalance | ||
.mul(10000) | ||
.div(tickStratTotal); | ||
const tickStratOethPercentage = tickStratOethBalance | ||
.mul(10000) | ||
.div(tickStratTotal); | ||
const tickStratTotalOfTickPercentage = tickStratTotal | ||
.mul(10000) | ||
.div(tickTotal); | ||
const tickStratTotalOfPoolPercentage = tickStratTotal | ||
.mul(10000) | ||
.div(poolTotal); | ||
|
||
const checkBalance = await aeroStrat | ||
.connect(signer) | ||
.checkBalance(weth.address, { blockTag }); | ||
|
||
const vaultWethBalance = await weth | ||
.connect(signer) | ||
.balanceOf(vault.address, { blockTag }); | ||
|
||
// Pool balances | ||
console.log( | ||
`Pool price : ${formatUnits(poolPrice, 10)} OETHb/WETH, ${tick} tick` | ||
); | ||
console.log( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these are fine, maybe there should be just additional notice, that these balances include unclaimed WETH/OETH from swap fees and liquidity decreases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added a comment |
||
`Pool WETH : ${formatUnits(poolWethBalance)} (${formatUnits( | ||
poolWethPercentage, | ||
2 | ||
)}%), ${poolWethBalance} wei` | ||
); | ||
console.log( | ||
`Pool OETH : ${formatUnits(poolOethBalance)} (${formatUnits( | ||
poolOethPercentage, | ||
2 | ||
)}%), ${poolOethBalance} wei` | ||
); | ||
console.log(`Pool total : ${formatUnits(poolTotal)}`); | ||
|
||
// Tick balances | ||
console.log( | ||
`\nTick WETH : ${formatUnits(tickWethBalance)} (${formatUnits( | ||
tickWethPercentage, | ||
2 | ||
)}%), ${tickWethBalance} wei` | ||
); | ||
console.log( | ||
`Tick OETH : ${formatUnits(tickOethBalance)} (${formatUnits( | ||
tickOethPercentage, | ||
2 | ||
)}%), ${tickOethBalance} wei` | ||
); | ||
console.log( | ||
`Tick total : ${formatUnits(tickStratTotal)} ${formatUnits( | ||
tickTotalPercentage, | ||
2 | ||
)}% of pool` | ||
); | ||
|
||
// Strategy's tick position | ||
console.log( | ||
`\nTick strat WETH : ${formatUnits(tickStratWethBalance)} (${formatUnits( | ||
tickStratWethPercentage, | ||
2 | ||
)}%), ${poolWethBalance} wei` | ||
); | ||
console.log( | ||
`Tick strat OETH : ${formatUnits(tickStratOethBalance)} (${formatUnits( | ||
tickStratOethPercentage, | ||
2 | ||
)}%), ${poolOethBalance} wei` | ||
); | ||
console.log( | ||
`Tick strat total : ${formatUnits(tickStratTotal)} ${formatUnits( | ||
tickStratTotalOfTickPercentage, | ||
2 | ||
)}% of tick, ${formatUnits(tickStratTotalOfPoolPercentage, 2)}% of pool` | ||
); | ||
|
||
console.log( | ||
`\nStrategy balance : ${formatUnits( | ||
checkBalance | ||
)} ether, ${checkBalance} wei` | ||
); | ||
console.log( | ||
`Vault WETH : ${formatUnits( | ||
vaultWethBalance | ||
)}, ${vaultWethBalance} wei` | ||
); | ||
}; | ||
|
||
module.exports = { | ||
snapAero, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const { formatUnits } = require("ethers").utils; | ||
const { getSigner } = require("../utils/signers"); | ||
const { logTxDetails } = require("../utils/txLogger"); | ||
|
||
const log = require("../utils/logger")("task:simulation"); | ||
|
||
const deployForceEtherSender = async () => { | ||
const signer = await getSigner(); | ||
|
||
log(`About to deploy the ForceEtherSender contract`); | ||
|
||
// Get the contract factory | ||
const ForceEtherSenderFactory = await ethers.getContractFactory( | ||
"ForceEtherSender", | ||
signer | ||
); | ||
|
||
// Deploy the contract with an initial message | ||
const forceEtherSender = await ForceEtherSenderFactory.deploy(); | ||
|
||
// Wait for the contract to be deployed | ||
await forceEtherSender.deployed(); | ||
|
||
log("ForceEtherSender contract deployed to:", forceEtherSender.address); | ||
}; | ||
|
||
const forceSend = async ({ sender, recipient }) => { | ||
const signer = await getSigner(); | ||
const balance = await ethers.provider.getBalance(sender); | ||
log(`About to forceSend ${formatUnits(balance)} ETH to ${recipient}`); | ||
|
||
const forceEtherSender = await ethers.getContractAt( | ||
"ForceEtherSender", | ||
sender | ||
); | ||
const tx = await forceEtherSender.connect(signer).forceSend(recipient); | ||
await logTxDetails(tx, "forceSend"); | ||
}; | ||
|
||
module.exports = { | ||
deployForceEtherSender, | ||
forceSend, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could be read from the strategy contract:
https://github.com/OriginProtocol/origin-dollar/blob/master/contracts/contracts/strategies/aerodrome/AerodromeAMOStrategy.sol#L75
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could, but I'll leave it from addresses.js