From ed68ef2c44a5e60fe806cedf77aa12350c4d3318 Mon Sep 17 00:00:00 2001 From: PatricioHenderson <72527088+PatricioHenderson@users.noreply.github.com> Date: Wed, 13 Sep 2023 18:57:59 -0300 Subject: [PATCH] Tasks: Track bridge tasks base config (#15) --- abis/IAllTasks.json | 45 ++++++++++++++++++++++++++++++++++++++++++ schema.graphql | 40 +++++++++++++++++++++++-------------- src/Task.ts | 35 +++++++++++++++++++++++++++++++- subgraph.template.yaml | 6 ++++++ 4 files changed, 110 insertions(+), 16 deletions(-) diff --git a/abis/IAllTasks.json b/abis/IAllTasks.json index c6aef5a..986701b 100644 --- a/abis/IAllTasks.json +++ b/abis/IAllTasks.json @@ -1606,5 +1606,50 @@ "outputs": [], "stateMutability": "nonpayable", "type": "function" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "recipient", + "type": "address" + } + ], + "name": "RecipientSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "defaultDestinationChain", + "type": "uint256" + } + ], + "name": "DefaultDestinationChainSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "destinationChain", + "type": "uint256" + } + ], + "name": "CustomDestinationChainSet", + "type": "event" } ] \ No newline at end of file diff --git a/schema.graphql b/schema.graphql index 89369dd..0038bf1 100644 --- a/schema.graphql +++ b/schema.graphql @@ -95,12 +95,22 @@ type Task @entity { customTokenThreshold: [CustomTokenThreshold!] @derivedFrom(field: "task") # Specific tasks config connector: String - defaultTokenOut: ERC20 + defaultDestinationChain: BigInt defaultMaxSlippage: BigInt + defaultTokenOut: ERC20 + recipient: String + customDestinationChain: [CustomDestinationChain!] @derivedFrom(field: "task") customTokenOut: [CustomTokenOut!] @derivedFrom(field: "task") customMaxSlippage: [CustomMaxSlippage!] @derivedFrom(field: "task") } +type AcceptanceList @entity { + id: ID! + task: Task! + type: String! + tokens: [String!]! +} + type VolumeLimit @entity { id: ID! token: ERC20! @@ -108,18 +118,25 @@ type VolumeLimit @entity { amount: BigInt! } -type CustomVolumeLimit @entity { +type CustomDestinationChain @entity { id: ID! task: Task! token: ERC20! - volumeLimit: VolumeLimit! + destinationChain: BigInt! } -type AcceptanceList @entity { +type CustomMaxSlippage @entity { id: ID! task: Task! - type: String! - tokens: [String!]! + token: ERC20! + maxSlippage: BigInt! +} + +type CustomTokenOut @entity { + id: ID! + task: Task! + token: ERC20! + tokenOut: ERC20! } type TokenThreshold @entity { @@ -136,18 +153,11 @@ type CustomTokenThreshold @entity { threshold: TokenThreshold! } -type CustomMaxSlippage @entity { - id: ID! - task: Task! - token: ERC20! - slippage: BigInt! -} - -type CustomTokenOut @entity { +type CustomVolumeLimit @entity { id: ID! task: Task! token: ERC20! - tokenOut: ERC20! + volumeLimit: VolumeLimit! } type Movement @entity { diff --git a/src/Task.ts b/src/Task.ts index 18a6535..0ce8aad 100644 --- a/src/Task.ts +++ b/src/Task.ts @@ -2,6 +2,7 @@ import { Address, Bytes, log } from '@graphprotocol/graph-ts' import { AcceptanceList, + CustomDestinationChain, CustomMaxSlippage, CustomTokenOut, CustomTokenThreshold, @@ -13,16 +14,19 @@ import { import { BalanceConnectorsSet, ConnectorSet, + CustomDestinationChainSet, CustomMaxSlippageSet, CustomTokenOutSet, CustomTokenThresholdSet, CustomVolumeLimitSet, + DefaultDestinationChainSet, DefaultMaxSlippageSet, DefaultTokenOutSet, DefaultTokenThresholdSet, DefaultVolumeLimitSet, GasPriceLimitSet, PriorityFeeLimitSet, + RecipientSet, Task as TaskContract, TimeLockDelaySet, TimeLockExecutionPeriodSet, @@ -60,10 +64,23 @@ export function handleCustomMaxSlippageSet(event: CustomMaxSlippageSet): void { if (customMaxSlippage === null) customMaxSlippage = new CustomMaxSlippage(customMaxSlippageId) customMaxSlippage.task = task.id customMaxSlippage.token = loadOrCreateERC20(event.params.token).id - customMaxSlippage.slippage = event.params.maxSlippage + customMaxSlippage.maxSlippage = event.params.maxSlippage customMaxSlippage.save() } +export function handleCustomDestinationChainSet(event: CustomDestinationChainSet): void { + const task = Task.load(event.address.toHexString()) + if (task == null) return log.warning('Missing task entity {}', [event.address.toHexString()]) + + const customDestinationChainId = getTaskCustomConfigId(task, event.params.token) + let customDestinationChain = CustomDestinationChain.load(customDestinationChainId) + if (customDestinationChain === null) customDestinationChain = new CustomDestinationChain(customDestinationChainId) + customDestinationChain.task = task.id + customDestinationChain.token = loadOrCreateERC20(event.params.token).id + customDestinationChain.destinationChain = event.params.destinationChain + customDestinationChain.save() +} + export function handleCustomTokenOutSet(event: CustomTokenOutSet): void { const task = Task.load(event.address.toHexString()) if (task == null) return log.warning('Missing task entity {}', [event.address.toHexString()]) @@ -116,6 +133,14 @@ export function handleCustomVolumeLimitSet(event: CustomVolumeLimitSet): void { customVolumeLimit.save() } +export function handleDefaultDestinationChainSet(event: DefaultDestinationChainSet): void { + const task = Task.load(event.address.toHexString()) + if (task == null) return log.warning('Missing task entity {}', [event.address.toHexString()]) + + task.defaultDestinationChain = event.params.defaultDestinationChain + task.save() +} + export function handleDefaultMaxSlippageSet(event: DefaultMaxSlippageSet): void { const task = Task.load(event.address.toHexString()) if (task == null) return log.warning('Missing task entity {}', [event.address.toHexString()]) @@ -174,6 +199,14 @@ export function handlePriorityFeeLimitSet(event: PriorityFeeLimitSet): void { task.save() } +export function handleRecipientSet(event: RecipientSet): void { + const task = Task.load(event.address.toHexString()) + if (task == null) return log.warning('Missing task entity {}', [event.address.toHexString()]) + + task.recipient = event.params.recipient.toHexString() + task.save() +} + export function handleTimeLockDelaySet(event: TimeLockDelaySet): void { const task = Task.load(event.address.toHexString()) if (task == null) return log.warning('Missing task entity {}', [event.address.toHexString()]) diff --git a/subgraph.template.yaml b/subgraph.template.yaml index 5c69198..88e0635 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -220,5 +220,11 @@ templates: handler: handleCustomMaxSlippageSet - event: CustomTokenOutSet(indexed address,address) handler: handleCustomTokenOutSet + - event: RecipientSet(indexed address) + handler: handleRecipientSet + - event: DefaultDestinationChainSet(indexed uint256) + handler: handleDefaultDestinationChainSet + - event: CustomDestinationChainSet(indexed address,indexed uint256) + handler: handleCustomDestinationChainSet file: ./src/Task.ts