-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7452be
commit 30eb556
Showing
5 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { Address, Bytes, crypto, log } from '@graphprotocol/graph-ts' | ||
|
||
import { Authorizer, Environment, PriceOracle, SmartVault, Task } from '../types/schema' | ||
import { AuthorizerDeployed, PriceOracleDeployed, SmartVaultDeployed, TaskDeployed } from '../types/Deployer/Deployer' | ||
|
||
import { getSmartVault } from './Task' | ||
import { loadOrCreateImplementation } from './Registry' | ||
import { getAuthorizer, getPriceOracle, getRegistry } from './SmartVault' | ||
|
||
export function handleAuthorizerDeployed(event: AuthorizerDeployed): void { | ||
log.warning('New authorizer deployed {}', [event.params.instance.toHexString()]) | ||
let implementation = loadOrCreateImplementation(event.params.implementation) | ||
let environment = loadOrCreateEnvironment(event.transaction.from, event.params.namespace) | ||
|
||
let authorizerId = event.params.instance.toHexString() | ||
let authorizer = new Authorizer(authorizerId) | ||
authorizer.name = event.params.name | ||
authorizer.implementation = implementation.id | ||
authorizer.environment = environment.id | ||
authorizer.save() | ||
} | ||
|
||
export function handlePriceOracleDeployed(event: PriceOracleDeployed): void { | ||
log.warning('New price oracle deployed {}', [event.params.instance.toHexString()]) | ||
let implementation = loadOrCreateImplementation(event.params.implementation) | ||
let environment = loadOrCreateEnvironment(event.transaction.from, event.params.namespace) | ||
|
||
let priceOracleId = event.params.instance.toHexString() | ||
let priceOracle = new PriceOracle(priceOracleId) | ||
priceOracle.name = event.params.name | ||
priceOracle.implementation = implementation.id | ||
priceOracle.environment = environment.id | ||
priceOracle.save() | ||
} | ||
|
||
export function handleSmartVaultDeployed(event: SmartVaultDeployed): void { | ||
log.warning('New smart vault deployed {}', [event.params.instance.toHexString()]) | ||
let implementation = loadOrCreateImplementation(event.params.implementation) | ||
let environment = loadOrCreateEnvironment(event.transaction.from, event.params.namespace) | ||
|
||
let smartVaultId = event.params.instance.toHexString() | ||
let smartVault = new SmartVault(smartVaultId) | ||
smartVault.name = event.params.name | ||
smartVault.implementation = implementation.id | ||
smartVault.environment = environment.id | ||
smartVault.registry = getRegistry(event.params.instance).toHexString() | ||
smartVault.authorizer = getAuthorizer(event.params.instance).toHexString() | ||
smartVault.priceOracle = getPriceOracle(event.params.instance).toHexString() | ||
smartVault.save() | ||
} | ||
|
||
export function handleTaskDeployed(event: TaskDeployed): void { | ||
log.warning('New task deployed {}', [event.params.instance.toHexString()]) | ||
let implementation = loadOrCreateImplementation(event.params.implementation) | ||
let environment = loadOrCreateEnvironment(event.transaction.from, event.params.namespace) | ||
|
||
let taskId = event.params.instance.toHexString() | ||
let task = new Task(taskId) | ||
task.name = event.params.name | ||
task.implementation = implementation.id | ||
task.environment = environment.id | ||
task.smartVault = getSmartVault(event.params.instance).toHexString() | ||
task.save() | ||
} | ||
|
||
export function loadOrCreateEnvironment(creator: Address, namespace: String): Environment { | ||
let rawId = Bytes.fromHexString(creator.toHexString() + Bytes.fromUTF8(namespace.toString()).toHexString().slice(2)) | ||
let id = crypto.keccak256(rawId).toHexString() | ||
let environment = Environment.load(id) | ||
|
||
if (environment === null) { | ||
environment = new Environment(id) | ||
environment.creator = creator.toHexString() | ||
environment.namespace = namespace | ||
environment.save() | ||
} | ||
|
||
return environment | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Address, log } from '@graphprotocol/graph-ts' | ||
|
||
import { SmartVault as SmartVaultContract } from '../types/templates/SmartVault/SmartVault' | ||
|
||
export function getRegistry(address: Address): Address { | ||
let smartVaultContract = SmartVaultContract.bind(address) | ||
let registryCall = smartVaultContract.try_registry() | ||
|
||
if (!registryCall.reverted) { | ||
return registryCall.value | ||
} | ||
|
||
log.warning('registry() call reverted for smart vault {}', [address.toHexString()]) | ||
return Address.zero() | ||
} | ||
|
||
export function getAuthorizer(address: Address): Address { | ||
let smartVaultContract = SmartVaultContract.bind(address) | ||
let authorizerCall = smartVaultContract.try_authorizer() | ||
|
||
if (!authorizerCall.reverted) { | ||
return authorizerCall.value | ||
} | ||
|
||
log.warning('authorizer() call reverted for smart vault {}', [address.toHexString()]) | ||
return Address.zero() | ||
} | ||
|
||
export function getPriceOracle(address: Address): Address { | ||
let smartVaultContract = SmartVaultContract.bind(address) | ||
let priceOracleCall = smartVaultContract.try_priceOracle() | ||
|
||
if (!priceOracleCall.reverted) { | ||
return priceOracleCall.value | ||
} | ||
|
||
log.warning('priceOracle() call reverted for smart vault {}', [address.toHexString()]) | ||
return Address.zero() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Address, log } from '@graphprotocol/graph-ts' | ||
|
||
import { Task as TaskContract } from '../types/templates/Task/Task' | ||
|
||
export function getSmartVault(address: Address): Address { | ||
let taskContract = TaskContract.bind(address) | ||
let smartVaultCall = taskContract.try_smartVault() | ||
|
||
if (!smartVaultCall.reverted) { | ||
return smartVaultCall.value | ||
} | ||
|
||
log.warning('smartVault() call reverted for task {}', [address.toHexString()]) | ||
return Address.zero() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters