Skip to content

Commit

Permalink
Tasks: Track bridge tasks base config (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
PatricioHenderson authored Sep 13, 2023
1 parent 9201613 commit ed68ef2
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 16 deletions.
45 changes: 45 additions & 0 deletions abis/IAllTasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
40 changes: 25 additions & 15 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -95,31 +95,48 @@ 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!
period: BigInt!
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 {
Expand All @@ -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 {
Expand Down
35 changes: 34 additions & 1 deletion src/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Address, Bytes, log } from '@graphprotocol/graph-ts'

import {
AcceptanceList,
CustomDestinationChain,
CustomMaxSlippage,
CustomTokenOut,
CustomTokenThreshold,
Expand All @@ -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,
Expand Down Expand Up @@ -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()])
Expand Down Expand Up @@ -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()])
Expand Down Expand Up @@ -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()])
Expand Down
6 changes: 6 additions & 0 deletions subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ed68ef2

Please sign in to comment.