diff --git a/abis/InstaAutomation.json b/abis/InstaAutomation.json index 8fed5c2..f4254ef 100644 --- a/abis/InstaAutomation.json +++ b/abis/InstaAutomation.json @@ -169,6 +169,102 @@ "name": "LogExecutedAutomation", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint32", + "name": "id", + "type": "uint32" + }, + { + "indexed": true, + "internalType": "uint32", + "name": "nonce", + "type": "uint32" + }, + { + "components": [ + { + "internalType": "address", + "name": "collateralToken", + "type": "address" + }, + { "internalType": "address", "name": "debtToken", "type": "address" }, + { + "internalType": "uint256", + "name": "collateralAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "debtAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "collateralAmountWithTotalFee", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "address", + "name": "buyToken", + "type": "address" + }, + { + "internalType": "address", + "name": "sellToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "sellAmt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "unitAmt", + "type": "uint256" + }, + { "internalType": "bytes", "name": "callData", "type": "bytes" } + ], + "internalType": "struct Structs.Swap", + "name": "swap", + "type": "tuple" + }, + { "internalType": "uint256", "name": "route", "type": "uint256" }, + { "internalType": "uint256", "name": "rateMode", "type": "uint256" } + ], + "indexed": false, + "internalType": "struct Structs.ExecutionParams", + "name": "params", + "type": "tuple" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "metadata", + "type": "bytes" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "initialHf", + "type": "uint128" + } + ], + "name": "LogExecutionFailedAutomation", + "type": "event" + }, { "anonymous": false, "inputs": [ diff --git a/generated/InstaAutomation/InstaAutomation.ts b/generated/InstaAutomation/InstaAutomation.ts index 05c9240..b58e2dc 100644 --- a/generated/InstaAutomation/InstaAutomation.ts +++ b/generated/InstaAutomation/InstaAutomation.ts @@ -166,6 +166,104 @@ export class LogExecutedAutomationParamsSwapStruct extends ethereum.Tuple { } } +export class LogExecutionFailedAutomation extends ethereum.Event { + get params(): LogExecutionFailedAutomation__Params { + return new LogExecutionFailedAutomation__Params(this); + } +} + +export class LogExecutionFailedAutomation__Params { + _event: LogExecutionFailedAutomation; + + constructor(event: LogExecutionFailedAutomation) { + this._event = event; + } + + get user(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get id(): BigInt { + return this._event.parameters[1].value.toBigInt(); + } + + get nonce(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } + + get params(): LogExecutionFailedAutomationParamsStruct { + return changetype( + this._event.parameters[3].value.toTuple() + ); + } + + get metadata(): Bytes { + return this._event.parameters[4].value.toBytes(); + } + + get initialHf(): BigInt { + return this._event.parameters[5].value.toBigInt(); + } +} + +export class LogExecutionFailedAutomationParamsStruct extends ethereum.Tuple { + get collateralToken(): Address { + return this[0].toAddress(); + } + + get debtToken(): Address { + return this[1].toAddress(); + } + + get collateralAmount(): BigInt { + return this[2].toBigInt(); + } + + get debtAmount(): BigInt { + return this[3].toBigInt(); + } + + get collateralAmountWithTotalFee(): BigInt { + return this[4].toBigInt(); + } + + get swap(): LogExecutionFailedAutomationParamsSwapStruct { + return changetype( + this[5].toTuple() + ); + } + + get route(): BigInt { + return this[6].toBigInt(); + } + + get rateMode(): BigInt { + return this[7].toBigInt(); + } +} + +export class LogExecutionFailedAutomationParamsSwapStruct extends ethereum.Tuple { + get buyToken(): Address { + return this[0].toAddress(); + } + + get sellToken(): Address { + return this[1].toAddress(); + } + + get sellAmt(): BigInt { + return this[2].toBigInt(); + } + + get unitAmt(): BigInt { + return this[3].toBigInt(); + } + + get callData(): Bytes { + return this[4].toBytes(); + } +} + export class LogFeeTransferred extends ethereum.Event { get params(): LogFeeTransferred__Params { return new LogFeeTransferred__Params(this); diff --git a/generated/schema.ts b/generated/schema.ts index 2de81e5..2993905 100644 --- a/generated/schema.ts +++ b/generated/schema.ts @@ -394,6 +394,15 @@ export class Account extends Entity { set systemCancelData(value: Array) { this.set("systemCancelData", Value.fromStringArray(value)); } + + get failedExecutionData(): Array { + let value = this.get("failedExecutionData"); + return value!.toStringArray(); + } + + set failedExecutionData(value: Array) { + this.set("failedExecutionData", Value.fromStringArray(value)); + } } export class SubmitData extends Entity { @@ -1215,3 +1224,107 @@ export class Executor extends Entity { this.set("executors", Value.fromBytesArray(value)); } } + +export class FailedExecution extends Entity { + constructor(id: string) { + super(); + this.set("id", Value.fromString(id)); + } + + save(): void { + let id = this.get("id"); + assert(id != null, "Cannot save FailedExecution entity without an ID"); + if (id) { + assert( + id.kind == ValueKind.STRING, + `Entities of type FailedExecution must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}` + ); + store.set("FailedExecution", id.toString(), this); + } + } + + static load(id: string): FailedExecution | null { + return changetype(store.get("FailedExecution", id)); + } + + get id(): string { + let value = this.get("id"); + return value!.toString(); + } + + set id(value: string) { + this.set("id", Value.fromString(value)); + } + + get user(): Bytes { + let value = this.get("user"); + return value!.toBytes(); + } + + set user(value: Bytes) { + this.set("user", Value.fromBytes(value)); + } + + get account(): string { + let value = this.get("account"); + return value!.toString(); + } + + set account(value: string) { + this.set("account", Value.fromString(value)); + } + + get userId(): BigInt { + let value = this.get("userId"); + return value!.toBigInt(); + } + + set userId(value: BigInt) { + this.set("userId", Value.fromBigInt(value)); + } + + get nonce(): BigInt { + let value = this.get("nonce"); + return value!.toBigInt(); + } + + set nonce(value: BigInt) { + this.set("nonce", Value.fromBigInt(value)); + } + + get params(): string { + let value = this.get("params"); + return value!.toString(); + } + + set params(value: string) { + this.set("params", Value.fromString(value)); + } + + get metadata(): Bytes { + let value = this.get("metadata"); + return value!.toBytes(); + } + + set metadata(value: Bytes) { + this.set("metadata", Value.fromBytes(value)); + } + + get initialHf(): BigInt { + let value = this.get("initialHf"); + return value!.toBigInt(); + } + + set initialHf(value: BigInt) { + this.set("initialHf", Value.fromBigInt(value)); + } + + get transactionDetail(): string { + let value = this.get("transactionDetail"); + return value!.toString(); + } + + set transactionDetail(value: string) { + this.set("transactionDetail", Value.fromString(value)); + } +} diff --git a/networks.json b/networks.json index bc0c2e2..705eba0 100644 --- a/networks.json +++ b/networks.json @@ -10,5 +10,11 @@ "address": "0x08c1c01be430C9381AD2794412C3E940254CD97c", "startBlock": 18160000 } + }, + "mainnet": { + "InstaAutomation": { + "address": "0x08c1c01be430C9381AD2794412C3E940254CD97c", + "startBlock": 15435700 + } } } diff --git a/schema.graphql b/schema.graphql index 5524cd6..4989892 100644 --- a/schema.graphql +++ b/schema.graphql @@ -1,4 +1,4 @@ -type ExecutionParams @entity{ +type ExecutionParams @entity { id: ID! collateralToken: Bytes! debtToken: Bytes! @@ -37,10 +37,11 @@ type TransactionData @entity { type Account @entity { id: ID! user: Bytes! - submitAutomation: [SubmitData!]! @derivedFrom (field: "account") - executeAutomation: [ExecuteData!]! @derivedFrom (field: "account") - cancelData: [CancelData!]! @derivedFrom (field: "account") - systemCancelData: [SystemCancelData!]! @derivedFrom (field: "account") + submitAutomation: [SubmitData!]! @derivedFrom(field: "account") + executeAutomation: [ExecuteData!]! @derivedFrom(field: "account") + cancelData: [CancelData!]! @derivedFrom(field: "account") + systemCancelData: [SystemCancelData!]! @derivedFrom(field: "account") + failedExecutionData: [FailedExecution!]! @derivedFrom(field: "account") } type SubmitData @entity { @@ -51,7 +52,7 @@ type SubmitData @entity { thresholdHF: BigInt! currentHf: BigInt! account: Account! - transactionDetail: TransactionData! + transactionDetail: TransactionData! } type ExecuteData @entity { @@ -75,7 +76,7 @@ type CancelData @entity { userId: BigInt! nonce: BigInt! account: Account! - transactionDetail: TransactionData! + transactionDetail: TransactionData! } type SystemCancelData @entity { @@ -85,14 +86,14 @@ type SystemCancelData @entity { nonce: BigInt! errorCode: Int! account: Account! - transactionDetail: TransactionData! + transactionDetail: TransactionData! } type ChangedOwner @entity { id: ID! oldOwner: Bytes! newOwner: Bytes! - transactionDetail: TransactionData! + transactionDetail: TransactionData! } type FeeTransferData @entity { @@ -101,7 +102,7 @@ type FeeTransferData @entity { tokens: [Bytes!]! amount: [BigInt!]! from: Bytes! - transactionDetail: TransactionData! + transactionDetail: TransactionData! } type SystemCallData @entity { @@ -109,14 +110,14 @@ type SystemCallData @entity { sender: Bytes! actionId: String! metaData: Bytes! - transactionDetail: TransactionData! + transactionDetail: TransactionData! } type UpdateAutomationFeeData @entity { id: ID! oldAutomationFee: Int! newAutomationFee: Int! - transactionDetail: TransactionData! + transactionDetail: TransactionData! } type UpdateBufferHfData @entity { @@ -130,10 +131,22 @@ type UpdateMinHfData @entity { id: ID! oldMinHf: BigInt! newMinHf: BigInt! - transactionDetail: TransactionData! + transactionDetail: TransactionData! } type Executor @entity { id: ID! executors: [Bytes!]! -} \ No newline at end of file +} + +type FailedExecution @entity { + id: ID! + user: Bytes! + account: Account! + userId: BigInt! + nonce: BigInt! + params: ExecutionParams! + metadata: Bytes! + initialHf: BigInt! + transactionDetail: TransactionData! +} diff --git a/src/insta-automation.ts b/src/insta-automation.ts index ae70de5..fe67764 100644 --- a/src/insta-automation.ts +++ b/src/insta-automation.ts @@ -10,6 +10,7 @@ import { LogCancelledAutomation, LogChangedOwner, LogExecutedAutomation, + LogExecutionFailedAutomation, LogFeeTransferred, LogFlippedExecutors, LogSubmittedAutomation, @@ -36,6 +37,7 @@ import { createOrLoadDsa, createOrLoadExecute, createOrLoadExecutionParams, + createOrLoadFailedExecution, createOrLoadFeeTransferData, createOrLoadSubmit, createOrLoadSwap, @@ -108,7 +110,7 @@ export function handleLogCancelAutomation(event: LogCancelledAutomation): void { transaction.transactionHash = event.transaction.hash; transaction.transactionLogIndex = event.transactionLogIndex; cancelData.transactionDetail = transaction.id; - + transaction.save(); cancelData.save(); dsa.save(); @@ -144,15 +146,13 @@ export function handleSystemCancelledAutomation( transaction.transactionHash = event.transaction.hash; transaction.transactionLogIndex = event.transactionLogIndex; cancelData.transactionDetail = transaction.id; - + transaction.save(); cancelData.save(); dsa.save(); } -export function handleLogExecuteAutomation( - event: LogExecutedAutomation -): void { +export function handleLogExecuteAutomation(event: LogExecutedAutomation): void { let dsaId = event.params.user.toHexString() + "#" + event.params.id.toString(); let eventId = @@ -199,7 +199,7 @@ export function handleLogExecuteAutomation( transaction.transactionHash = event.transaction.hash; transaction.transactionLogIndex = event.transactionLogIndex; executeData.transactionDetail = transaction.id; - + transaction.save(); params.save(); swaps.save(); @@ -221,10 +221,10 @@ export function handleLogChangedOwner(event: LogChangedOwner): void { transaction.transactionHash = event.transaction.hash; transaction.transactionLogIndex = event.transactionLogIndex; changeOwnerData.transactionDetail = transaction.id; - + transaction.save(); changeOwnerData.save(); -} +} export function handleLogFeeTransferred(event: LogFeeTransferred): void { let eventId = @@ -238,7 +238,7 @@ export function handleLogFeeTransferred(event: LogFeeTransferred): void { let dataTokens = data.tokens; let dataAmounts = data.amount; - for(let i = 0; i