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

[DO NOT MERGE]As/update flash mint module #140

Draft
wants to merge 8 commits into
base: automation_v2
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dotenv.config()
// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more

const blockNumber = process.env.BLOCK_NUMBER || '13559294'
const blockNumber = process.env.BLOCK_NUMBER || '15689000'

function createHardhatNetwork(network: string, node: string | undefined, key: string | undefined, gasPrice: number) {
if (!node || !key) {
Expand Down
4 changes: 2 additions & 2 deletions scripts/common/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const addresses = {
OSM_MOM: '0x76416A4d5190d071bfed309861527431304aA14f',
MCD_SPOT: '0x65C79fcB50Ca1594B025960e539eD7A9a6D434A3',
MCD_JOIN_ETH_A: '0x2F0b23f53734252Bda2277357e97e1517d6B042A',
MCD_FLASH: '0x1EB4CF3A948E7D72A198fe073cCb8C7a948cD853',
MCD_FLASH: '0x60744434d6339a6B27d73d9Eda62b6F66a0a04FA',
PROXY_REGISTRY: '0x4678f0a6958e4D2Bc4F1BAF7Bc52E8F3564f3fE4',
WETH: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
DAI: '0x6b175474e89094c44da98b954eedeac495271d0f',
Expand Down Expand Up @@ -56,7 +56,7 @@ const addresses = {
OSM_MOM: '0xEdB6b497D2e18A33130CB0D2b70343E6Dcd9EE86',
MCD_SPOT: '0xACe2A9106ec175bd56ec05C9E38FE1FDa8a1d758',
MCD_JOIN_ETH_A: '0x2372031bB0fC735722AA4009AeBf66E8BEAF4BA1',
MCD_FLASH: '0x0a6861D6200B519a8B9CFA1E7Edd582DD1573581',
MCD_FLASH: '0xAa5F7d5b29Fa366BB04F6E4c39ACF569d5214075',
PROXY_REGISTRY: '0x46759093D8158db8BB555aC7C6F98070c56169ce',
WETH: '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6',
DAI: '0x11fE4B6AE13d2a6055C8D9cF65c55bac32B5d844',
Expand Down
10 changes: 5 additions & 5 deletions test/auto-take-profit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '../scripts/common'
import { deploySystem } from '../scripts/common/deploy-system'

const testCdpId = parseInt(process.env.CDP_ID || '26125')
const testCdpId = parseInt(process.env.CDP_ID || '29031')

describe('AutoTakeProfitCommand', async () => {
/* this can be anabled only after whitelisting us on OSM */
Expand Down Expand Up @@ -132,7 +132,7 @@ describe('AutoTakeProfitCommand', async () => {
)
})

describe('when Trigger is below next price', async () => {
describe('when Trigger is above next price', async () => {
let triggerId: number
let triggerData: BytesLike
let executionData: BytesLike
Expand Down Expand Up @@ -193,7 +193,7 @@ describe('AutoTakeProfitCommand', async () => {
await expect(tx).to.be.revertedWith('bot/trigger-execution-illegal')
})
})
describe('when Trigger is above next price', async () => {
describe('when Trigger is below next price', async () => {
let triggerId: number
let triggerData: BytesLike
let executionData: BytesLike
Expand Down Expand Up @@ -243,7 +243,7 @@ describe('AutoTakeProfitCommand', async () => {
const nextPriceStorage = await hre.ethers.provider.getStorageAt(osmAddress, 4)
const updatedNextPrice = hre.ethers.utils.hexConcat([
hre.ethers.utils.hexZeroPad('0x1', 16),
hre.ethers.utils.hexZeroPad(EthersBN.from('3592759999999999999999').toHexString(), 16),
hre.ethers.utils.hexZeroPad(EthersBN.from(nextPrice.sub(10000)).toHexString(), 16),
])

await hre.ethers.provider.send('hardhat_setStorageAt', [osmAddress, '0x4', updatedNextPrice])
Expand Down Expand Up @@ -474,7 +474,7 @@ describe('AutoTakeProfitCommand', async () => {
const nextPriceStorage = await hre.ethers.provider.getStorageAt(osmAddress, 4)
const updatedNextPrice = hre.ethers.utils.hexConcat([
hre.ethers.utils.hexZeroPad('0x1', 16),
hre.ethers.utils.hexZeroPad(EthersBN.from('3592759999999999999999').toHexString(), 16),
hre.ethers.utils.hexZeroPad(EthersBN.from(nextPrice.sub(10000)).toHexString(), 16),
])

await hre.ethers.provider.send('hardhat_setStorageAt', [osmAddress, '0x4', updatedNextPrice])
Expand Down
2 changes: 1 addition & 1 deletion test/automation-aggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import { deploySystem } from '../scripts/common/deploy-system'
import { TestERC20 } from '../typechain/TestERC20'

const testCdpId = parseInt(process.env.CDP_ID || '26125')
const testCdpId = parseInt(process.env.CDP_ID || '29031')
const HARDHAT_DEFAULT_COINBASE = '0xc014ba5ec014ba5ec014ba5ec014ba5ec014ba5e'

const dummyTriggerData = utils.defaultAbiCoder.encode(['uint256', 'uint16', 'uint256'], [testCdpId, 1, 101])
Expand Down
2 changes: 1 addition & 1 deletion test/automation-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
MakerAdapter,
} from '../typechain'

const testCdpId = parseInt(process.env.CDP_ID || '26125')
const testCdpId = parseInt(process.env.CDP_ID || '29031')

const dummyTriggerDataNoReRegister = utils.defaultAbiCoder.encode(['uint256', 'uint16', 'uint256'], [testCdpId, 2, 101])

Expand Down
2 changes: 1 addition & 1 deletion test/automation-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import { deploySystem } from '../scripts/common/deploy-system'
import { TestERC20 } from '../typechain/TestERC20'

const testCdpId = parseInt(process.env.CDP_ID || '26125')
const testCdpId = parseInt(process.env.CDP_ID || '29031')
const HARDHAT_DEFAULT_COINBASE = '0xc014ba5ec014ba5ec014ba5ec014ba5ec014ba5e'

const dummyTriggerData = utils.defaultAbiCoder.encode(['uint256', 'uint16', 'uint256'], [testCdpId, 1, 101])
Expand Down
2 changes: 1 addition & 1 deletion test/basic-buy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { DeployedSystem, deploySystem } from '../scripts/common/deploy-system'
import { DsProxyLike, MPALike } from '../typechain'

const testCdpId = parseInt(process.env.CDP_ID || '13288')
const testCdpId = parseInt(process.env.CDP_ID || '29031')
const maxGweiPrice = 1000

describe('BasicBuyCommand', () => {
Expand Down
24 changes: 17 additions & 7 deletions test/basic-sell.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import hre from 'hardhat'
import hre, { ethers } from 'hardhat'
import { BytesLike, utils, BigNumber as EtherBN } from 'ethers'
import { expect } from 'chai'
import { getMultiplyParams } from '@oasisdex/multiply'
Expand All @@ -15,13 +15,13 @@ import {
import { DeployedSystem, deploySystem } from '../scripts/common/deploy-system'
import { DsProxyLike, MPALike } from '../typechain'

const testCdpId = parseInt(process.env.CDP_ID || '13288')
const testCdpId = parseInt(process.env.CDP_ID || '29031')
const maxGweiPrice = 1000

// BLOCK_NUMBER=14997398
describe('BasicSellCommand', () => {
const [correctExecutionRatio, correctTargetRatio] = [toRatio(2.6), toRatio(2.8)]
const [incorrectExecutionRatio, incorrectTargetRatio] = [toRatio(1.52), toRatio(1.51)]
describe.only('BasicSellCommand', async () => {
let [correctExecutionRatio, correctTargetRatio] = [toRatio(2.6), toRatio(2.8)]
let [incorrectExecutionRatio, incorrectTargetRatio] = [toRatio(1.52), toRatio(1.51)]
const ethAIlk = utils.formatBytes32String('ETH-A')
const hardhatUtils = new HardhatUtils(hre)

Expand Down Expand Up @@ -63,6 +63,16 @@ describe('BasicSellCommand', () => {
const osmMom = await hre.ethers.getContractAt('OsmMomLike', hardhatUtils.addresses.OSM_MOM)
const osm = await hre.ethers.getContractAt('OsmLike', await osmMom.osms(ethAIlk))
await hardhatUtils.setBudInOSM(osm.address, system.mcdView.address)

const collRatio = ethers.utils.formatEther(await system.mcdView.getRatio(testCdpId, true))

const collRationNum = Math.floor(10000 * parseFloat(collRatio))

correctExecutionRatio = collRationNum + 1000
correctTargetRatio = collRationNum + 2000

incorrectExecutionRatio = collRationNum - 1000
incorrectTargetRatio = collRationNum - 2000
})

beforeEach(async () => {
Expand Down Expand Up @@ -152,7 +162,7 @@ describe('BasicSellCommand', () => {
TriggerType.BASIC_SELL,
new BigNumber(executionRatio).toFixed(),
new BigNumber(targetRatio).toFixed(),
new BigNumber(4000).shiftedBy(18).toFixed(),
new BigNumber(1000).shiftedBy(18).toFixed(),
50,
maxBaseFee,
)
Expand Down Expand Up @@ -269,7 +279,7 @@ describe('BasicSellCommand', () => {
.execute(
system.mcdUtils.address,
system.mcdUtils.interface.encodeFunctionData('drawDebt', [
EtherBN.from(10).pow(18).mul(1_010_000),
EtherBN.from(10).pow(18).mul(22_284),
testCdpId,
hardhatUtils.addresses.CDP_MANAGER,
proxyOwnerAddress,
Expand Down
5 changes: 4 additions & 1 deletion test/close-operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '../scripts/common'
import { deploySystem } from '../scripts/common/deploy-system'

const testCdpId = parseInt(process.env.CDP_ID || '26125')
const testCdpId = parseInt(process.env.CDP_ID || '29031')

// Block dependent test, works for 13998517

Expand Down Expand Up @@ -554,6 +554,9 @@ describe('CloseCommand', async () => {
0,
178000,
hardhatUtils.addresses.DAI,
{
gasLimit:5000000
}
)

const afterBalance = await DAIInstance.balanceOf(receiverAddress)
Expand Down
2 changes: 1 addition & 1 deletion test/constant-multiple-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AutomationBot, AutomationBotStorage, DsProxyLike } from '../typechain'
import { TriggerGroupType, TriggerType } from '../scripts/common'
import BigNumber from 'bignumber.js'

const testCdpId = parseInt(process.env.CDP_ID || '26125')
const testCdpId = parseInt(process.env.CDP_ID || '29031')
const maxGweiPrice = 1000

function toRatio(units: number) {
Expand Down