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..83f48e9 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/gaugeInjector.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! +} diff --git a/src/eventEmitter.ts b/src/eventEmitter.ts index 124a210..dedd771 100644 --- a/src/eventEmitter.ts +++ b/src/eventEmitter.ts @@ -1,5 +1,6 @@ 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 +22,13 @@ export function handleLogArgument(event: LogArgument): void { ) { setGaugeRewardsData(event); } + // keccak256(setGaugeInjector) = 0x109783b117ecbf8caf4e937abaf494b965e5d90c4d1b010b27eb2a3be80eaf21 + if ( + identifier == + '0x109783b117ecbf8caf4e937abaf494b965e5d90c4d1b010b27eb2a3be80eaf21' + ) { + setGaugeInjector(event); + } } function setGaugeRewardsData(event: LogArgument): void { @@ -83,3 +91,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/gaugeInjector.ts b/src/gaugeInjector.ts new file mode 100644 index 0000000..21223ef --- /dev/null +++ b/src/gaugeInjector.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); +}