From 253f6748cc597dc6b7ea37c4a8bce2e96b7b4e8b Mon Sep 17 00:00:00 2001 From: mendesfabio Date: Fri, 24 Nov 2023 19:10:43 -0300 Subject: [PATCH 1/4] set up gauge injectors --- abis/ChildChainGaugeInjector.json | 656 ++++++++++++++++++++++++++++++ manifest.template.yaml | 21 +- schema.graphql | 5 + 3 files changed, 681 insertions(+), 1 deletion(-) create mode 100644 abis/ChildChainGaugeInjector.json diff --git a/abis/ChildChainGaugeInjector.json b/abis/ChildChainGaugeInjector.json new file mode 100644 index 0000000..cc811e4 --- /dev/null +++ b/abis/ChildChainGaugeInjector.json @@ -0,0 +1,656 @@ +[ + { + "inputs": [ + { + "internalType": "address", + "name": "keeperRegistryAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "minWaitPeriodSeconds", + "type": "uint256" + }, + { + "internalType": "address", + "name": "injectTokenAddress", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [], + "name": "BalancesMismatch", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "duplicate", + "type": "address" + } + ], + "name": "DuplicateAddress", + "type": "error" + }, + { + "inputs": [], + "name": "ListLengthMismatch", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "OnlyKeeperRegistry", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "periodNumber", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxPeriods", + "type": "uint256" + } + ], + "name": "PeriodNotFinished", + "type": "error" + }, + { + "inputs": [], + "name": "RewardTokenError", + "type": "error" + }, + { + "inputs": [], + "name": "ZeroAddress", + "type": "error" + }, + { + "inputs": [], + "name": "ZeroAmount", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "ERC20Swept", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "gauge", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "EmissionsInjection", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "amountWithdrawn", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "recipient", + "type": "address" + } + ], + "name": "GasTokenWithdrawn", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "oldAddress", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "newAddress", + "type": "address" + } + ], + "name": "KeeperRegistryAddressUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "oldMinWaitPeriod", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "newMinWaitPeriod", + "type": "uint256" + } + ], + "name": "MinWaitPeriodUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "OwnershipTransferRequested", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Paused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address[]", + "name": "needsFunding", + "type": "address[]" + } + ], + "name": "PerformedUpkeep", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "token", + "type": "address" + } + ], + "name": "SetHandlingToken", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Unpaused", + "type": "event" + }, + { + "inputs": [], + "name": "acceptOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "checkSufficientBalances", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "name": "checkUpkeep", + "outputs": [ + { + "internalType": "bool", + "name": "upkeepNeeded", + "type": "bool" + }, + { + "internalType": "bytes", + "name": "performData", + "type": "bytes" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "targetAddress", + "type": "address" + } + ], + "name": "getAccountInfo", + "outputs": [ + { + "internalType": "uint256", + "name": "amountPerPeriod", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "isActive", + "type": "bool" + }, + { + "internalType": "uint8", + "name": "maxPeriods", + "type": "uint8" + }, + { + "internalType": "uint8", + "name": "periodNumber", + "type": "uint8" + }, + { + "internalType": "uint56", + "name": "lastInjectionTimeStamp", + "type": "uint56" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getInjectTokenAddress", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getKeeperRegistryAddress", + "outputs": [ + { + "internalType": "address", + "name": "keeperRegistryAddress", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getMinWaitPeriodSeconds", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getReadyGauges", + "outputs": [ + { + "internalType": "address[]", + "name": "", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getWatchList", + "outputs": [ + { + "internalType": "address[]", + "name": "", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "gauges", + "type": "address[]" + } + ], + "name": "injectFunds", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "gauge", + "type": "address" + }, + { + "internalType": "address", + "name": "reward_token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "manualDeposit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "pause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "paused", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "performData", + "type": "bytes" + } + ], + "name": "performUpkeep", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "gauge", + "type": "address" + }, + { + "internalType": "address", + "name": "reward_token", + "type": "address" + } + ], + "name": "setDistributorToOwner", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "ERC20token", + "type": "address" + } + ], + "name": "setInjectTokenAddress", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "keeperRegistryAddress", + "type": "address" + } + ], + "name": "setKeeperRegistryAddress", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "period", + "type": "uint256" + } + ], + "name": "setMinWaitPeriodSeconds", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "gaugeAddresses", + "type": "address[]" + }, + { + "internalType": "uint256[]", + "name": "amountsPerPeriod", + "type": "uint256[]" + }, + { + "internalType": "uint8[]", + "name": "maxPeriods", + "type": "uint8[]" + } + ], + "name": "setRecipientList", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "gaugeAddresses", + "type": "address[]" + }, + { + "internalType": "uint256[]", + "name": "amountsPerPeriod", + "type": "uint256[]" + }, + { + "internalType": "uint8[]", + "name": "maxPeriods", + "type": "uint8[]" + } + ], + "name": "setValidatedRecipientList", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + } + ], + "name": "sweep", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "unpause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "withdrawGasToken", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } + ] \ No newline at end of file diff --git a/manifest.template.yaml b/manifest.template.yaml index ecfbfd1..d6f044c 100644 --- a/manifest.template.yaml +++ b/manifest.template.yaml @@ -803,4 +803,23 @@ templates: handler: handleSingleRecipientKillGauge - function: unkillGauge() handler: handleSingleRecipientUnkillGauge - {{/if}} \ No newline at end of file + {{/if}} + - kind: ethereum/contract + name: GaugeInjector + # prettier-ignore + network: {{network}} + source: + abi: GaugeInjector + mapping: + kind: ethereum/events + apiVersion: 0.0.5 + language: wasm/assemblyscript + file: ./src/gaugeInjection.ts + entities: + - GaugeInjector + abis: + - name: GaugeInjector + file: ./abis/ChildChainGaugeInjector.json + eventHandlers: + - event: EmissionsInjection(address,address,uint256) + handler: handleEmissionsInjection diff --git a/schema.graphql b/schema.graphql index 74b0044..e3ed3bf 100644 --- a/schema.graphql +++ b/schema.graphql @@ -313,3 +313,8 @@ type User @entity { " List of omni locks the user created " omniVotingLocks: [OmniVotingEscrowLock!] @derivedFrom(field: "localUser") } + +type GaugeInjector @entity { + " GaugeInjector contract address " + id: ID! +} From 14ba1ceb66a8e1dceeb3e6474d8b463a2f43bc65 Mon Sep 17 00:00:00 2001 From: mendesfabio Date: Fri, 24 Nov 2023 19:11:04 -0300 Subject: [PATCH 2/4] create injector event handlers --- src/eventEmitter.ts | 29 ++++++++++++++++++++++++++++- src/gaugeInjection.ts | 6 ++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/gaugeInjection.ts diff --git a/src/eventEmitter.ts b/src/eventEmitter.ts index 124a210..474b38f 100644 --- a/src/eventEmitter.ts +++ b/src/eventEmitter.ts @@ -1,5 +1,7 @@ +import { ChildChainGaugeInjector } from './types/EventEmitter/ChildChainGaugeInjector'; import { LogArgument } from './types/EventEmitter/EventEmitter'; -import { Pool, LiquidityGauge } from './types/schema'; +import { Pool, LiquidityGauge, GaugeInjector } from './types/schema'; +import { GaugeInjector as GaugeInjectorTemplate } from './types/templates'; import { setRewardData } from './utils/gauge'; import { bytesToAddress } from './utils/misc'; @@ -21,6 +23,13 @@ export function handleLogArgument(event: LogArgument): void { ) { setGaugeRewardsData(event); } + // keccak256(setGaugeInjector) = 0x109783b117ecbf8caf4e937abaf494b965e5d90c4d1b010b27eb2a3be80eaf21 + if ( + identifier == + '0x109783b117ecbf8caf4e937abaf494b965e5d90c4d1b010b27eb2a3be80eaf21' + ) { + setGaugeInjector(event); + } } function setGaugeRewardsData(event: LogArgument): void { @@ -83,3 +92,21 @@ function setPreferentialGauge(event: LogArgument): void { } gauge.save(); } + +export function setGaugeInjector(event: LogArgument): void { + /** + * Sets a new GaugeInjector - creates entity and template + * + * @param message - The GaugeInjector address (eg. 0x12345abce... - all lowercase) + */ + const injectorId = event.params.message.toHexString(); + + let injector = GaugeInjector.load(injectorId); + if (injector) return; // already exists, no need to re-create it + + injector = new GaugeInjector(injectorId); + injector.save(); + + const injectorAddress = bytesToAddress(event.params.message); + GaugeInjectorTemplate.create(injectorAddress); +} diff --git a/src/gaugeInjection.ts b/src/gaugeInjection.ts new file mode 100644 index 0000000..21223ef --- /dev/null +++ b/src/gaugeInjection.ts @@ -0,0 +1,6 @@ +import { EmissionsInjection } from './types/templates/GaugeInjector/GaugeInjector'; +import { setRewardData } from './utils/gauge'; + +export function handleEmissionsInjection(event: EmissionsInjection): void { + setRewardData(event.params.gauge, event.params.token); +} From 23355f51818b28390923d8995e4bb8034a578c7c Mon Sep 17 00:00:00 2001 From: mendesfabio Date: Fri, 24 Nov 2023 19:27:36 -0300 Subject: [PATCH 3/4] rename gauge injector mapping --- manifest.template.yaml | 2 +- src/{gaugeInjection.ts => gaugeInjector.ts} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/{gaugeInjection.ts => gaugeInjector.ts} (100%) diff --git a/manifest.template.yaml b/manifest.template.yaml index d6f044c..83f48e9 100644 --- a/manifest.template.yaml +++ b/manifest.template.yaml @@ -814,7 +814,7 @@ templates: kind: ethereum/events apiVersion: 0.0.5 language: wasm/assemblyscript - file: ./src/gaugeInjection.ts + file: ./src/gaugeInjector.ts entities: - GaugeInjector abis: diff --git a/src/gaugeInjection.ts b/src/gaugeInjector.ts similarity index 100% rename from src/gaugeInjection.ts rename to src/gaugeInjector.ts From 3fba478d031df4c31d23e13a4a1e480f5c0f8793 Mon Sep 17 00:00:00 2001 From: mendesfabio Date: Fri, 24 Nov 2023 19:29:19 -0300 Subject: [PATCH 4/4] remove unused imports --- src/eventEmitter.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/eventEmitter.ts b/src/eventEmitter.ts index 474b38f..dedd771 100644 --- a/src/eventEmitter.ts +++ b/src/eventEmitter.ts @@ -1,4 +1,3 @@ -import { ChildChainGaugeInjector } from './types/EventEmitter/ChildChainGaugeInjector'; import { LogArgument } from './types/EventEmitter/EventEmitter'; import { Pool, LiquidityGauge, GaugeInjector } from './types/schema'; import { GaugeInjector as GaugeInjectorTemplate } from './types/templates';