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

Lw/6242 fix hh tasks v2 #145

Open
wants to merge 10 commits into
base: automation_v2
Choose a base branch
from
9 changes: 8 additions & 1 deletion scripts/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,17 @@ function getTriggerDataTypes(triggerType: TriggerType) {
throw new Error(`Error determining trigger data types. Unsupported trigger type: ${triggerType}`)
}
}

// replace with common encodeTriggerDataByType ?
export function encodeTriggerData(vaultId: number, triggerType: TriggerType, ...rest: any[]): BytesLike {
const args = [vaultId, triggerType, ...rest]
const types = getTriggerDataTypes(triggerType)
// TODO ŁW I want to use methods from common to be consistent with oasis-borrow
// const types = getDefinitionForCommandType(triggerType),

console.log('args')
console.log(args)
console.log('types')
console.log(types)
return utils.defaultAbiCoder.encode(types, args)
}

Expand Down
38 changes: 33 additions & 5 deletions scripts/tasks/create-trigger.task.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TriggerGroupType, TriggerType } from '@oasisdex/automation'
import { CommandContractType, encodeTriggerDataByType, TriggerGroupType, TriggerType } from '@oasisdex/automation'
import { BigNumber } from 'bignumber.js'
import { Signer, BigNumber as EthersBN } from 'ethers'
import { types } from 'hardhat/config'
Expand Down Expand Up @@ -27,6 +27,7 @@ interface CreateTriggerArgs extends BaseTaskArgs {
createTask<CreateTriggerArgs>('create-trigger', 'Creates an automation trigger for a user')
.addParam('vault', 'The vault (cdp) ID', undefined, params.bignumber, false)
.addParam('type', 'The trigger type', TriggerType.StopLossToDai, types.int)
.addParam('continuous', 'Is trigger supposed to be continuous', false, types.boolean)
.addParam(
'params',
"The remaining args for the trigger data (i.e. 170). See `encodeTriggerData` for more info.\n For BasicBuy it's [execCollRatio,targetCollRatio,maxBuyPrice,contnuous,deviation,maxBaseFeeInGwei] eg '[23200,21900,'0',true,100,200]'",
Expand Down Expand Up @@ -75,7 +76,20 @@ createTask<CreateTriggerArgs>('create-trigger', 'Creates an automation trigger f
)}`,
)
}
triggerIdToReplace = Math.max(...activeTriggerIds) ?? 0
console.log('activeTriggerIds')
console.log(activeTriggerIds)
console.log('Trigger ID to replace')
console.log(Math.max(...activeTriggerIds))
console.log('Array.isArray(activeTriggerIds)')
console.log(Array.isArray(activeTriggerIds))
console.log('!activeTriggerIds.length')
console.log(!activeTriggerIds.length)
console.log('Array.isArray(activeTriggerIds) && activeTriggerIds.length !== 0')
console.log(Array.isArray(activeTriggerIds) && activeTriggerIds.length !== 0)
triggerIdToReplace =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was returning -Infinity for an empty array

Array.isArray(activeTriggerIds) && activeTriggerIds.length !== 0
? Math.max(...activeTriggerIds) ?? 0
: 0
}

let signer: Signer = hre.ethers.provider.getSigner(0)
Expand All @@ -100,8 +114,22 @@ createTask<CreateTriggerArgs>('create-trigger', 'Creates an automation trigger f
})
).wait()
}

const triggerData = encodeTriggerData(args.vault.toNumber(), args.type, ...args.params)
console.log('args')
console.log(args)
const commands = {
[TriggerType.BasicBuy]: CommandContractType.BasicBuyCommand,
[TriggerType.BasicSell]: CommandContractType.BasicSellCommand,
}
// const triggerData = encodeTriggerData(args.vault.toNumber(), args.type, ...args.params)
const type = commands[(args.type as 3) || 4]
const triggerData = encodeTriggerDataByType(type, [args.vault.toNumber(), args.type, ...args.params])
// TODO ŁW fix here
console.log(`Trigger data: ${triggerData}`)
console.log(`Trigger id to replace: ${triggerIdToReplace}`)
console.log(`Continuous: ${args.continuous}`)
console.log(`Signer: ${await signer.getAddress()}`)
console.log('args.type', args.type)
// need to deploy automation v2 to hh/testnet
const addTriggerData = bot.interface.encodeFunctionData('addTriggers', [
TriggerGroupType.SingleTrigger,
[args.continuous],
Expand All @@ -126,7 +154,7 @@ createTask<CreateTriggerArgs>('create-trigger', 'Creates an automation trigger f

const tx = await proxy.connect(signer).execute(bot.address, addTriggerData, await hardhatUtils.getGasSettings())
const receipt = await tx.wait()

// check if it works
const [triggerAddedEvent] = getEvents(receipt, bot.interface.getEvent('TriggerAdded'))

if (!triggerAddedEvent) {
Expand Down