diff --git a/subgraphs/stakewise/config/gnosis.json b/subgraphs/stakewise/config/gnosis.json index c39963f..ca5087d 100644 --- a/subgraphs/stakewise/config/gnosis.json +++ b/subgraphs/stakewise/config/gnosis.json @@ -36,6 +36,10 @@ "address": "0x9b23e05aefb37d5ea9b525016d19eb82b65f255c", "startBlock": "21293582" }, + "opiumDepositScheduler": { + "address": "0x0000000000000000000000000000000000000000", + "startBlock": "21584842" + }, "distributorTokens": [ { "index": 0, diff --git a/subgraphs/stakewise/config/mainnet.json b/subgraphs/stakewise/config/mainnet.json index 7145450..fd569d1 100644 --- a/subgraphs/stakewise/config/mainnet.json +++ b/subgraphs/stakewise/config/mainnet.json @@ -36,6 +36,10 @@ "address": "0xc486c10e3611565f5b38b50ad68277b11c889623", "startBlock": "13776571" }, + "opiumDepositScheduler": { + "address": "0xe47b867b2b5b21a2022068c9ef1293783864b274", + "startBlock": "14108270" + }, "distributorTokens": [ { "index": 0, diff --git a/subgraphs/stakewise/packages/abis/OpiumDepositScheduler.json b/subgraphs/stakewise/packages/abis/OpiumDepositScheduler.json new file mode 100644 index 0000000..4800bb5 --- /dev/null +++ b/subgraphs/stakewise/packages/abis/OpiumDepositScheduler.json @@ -0,0 +1,429 @@ +[ + { + "inputs": [ + { + "internalType": "address", + "name": "_guardian", + "type": "address" + }, + { + "internalType": "address", + "name": "_reserveSetter", + "type": "address" + }, + { + "internalType": "address", + "name": "_reserveCollector", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_executor", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "_user", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "_pool", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "LogExecuted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "_token", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_reserveAmount", + "type": "uint256" + } + ], + "name": "LogReserveSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "_user", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "_token", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "_reserveAmount", + "type": "uint256" + } + ], + "name": "LogReserveWithdrawn", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "_user", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "_pool", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "LogScheduled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "_user", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "_pool", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "LogUnscheduled", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_tokenAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "_recipient", + "type": "address" + } + ], + "name": "emergencyRescue", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_user", + "type": "address" + }, + { + "internalType": "address", + "name": "_pool", + "type": "address" + } + ], + "name": "execute", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_token", + "type": "address" + } + ], + "name": "getAccumulatedTokenReserve", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_token", + "type": "address" + } + ], + "name": "getReserveCoefficient", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_pool", + "type": "address" + } + ], + "name": "getScheduled", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_user", + "type": "address" + }, + { + "internalType": "address", + "name": "_pool", + "type": "address" + } + ], + "name": "getScheduled", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "guardian", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_pool", + "type": "address" + } + ], + "name": "isScheduled", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "reserveCollector", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "reserveSetter", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_pool", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "scheduleDeposit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_newGuardian", + "type": "address" + } + ], + "name": "setGuardian", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_reserveCoefficient", + "type": "uint256" + } + ], + "name": "setReserveCoefficient", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_newReserveCollector", + "type": "address" + } + ], + "name": "setReserveCollector", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_newReserveSetter", + "type": "address" + } + ], + "name": "setReserveSetter", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_pool", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "unscheduleDeposit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_token", + "type": "address" + } + ], + "name": "withdrawReserve", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] \ No newline at end of file diff --git a/subgraphs/stakewise/src/mappings/distributorTokens.ts b/subgraphs/stakewise/src/mappings/distributorTokens.ts index d043972..b4c49e0 100644 --- a/subgraphs/stakewise/src/mappings/distributorTokens.ts +++ b/subgraphs/stakewise/src/mappings/distributorTokens.ts @@ -1,7 +1,8 @@ import { ADDRESS_ZERO } from "const"; -import { log } from "@graphprotocol/graph-ts"; -import { createOrLoadDistributorToken, createOrLoadDistributorTokenHolder } from "../entities"; +import { Address, log } from "@graphprotocol/graph-ts"; import { Transfer } from "../../generated/DistributorToken0/ERC20Token"; +import { LogScheduled, LogUnscheduled } from "../../generated/OpiumDepositScheduler/OpiumDepositScheduler"; +import { createOrLoadDistributorToken, createOrLoadDistributorTokenHolder } from "../entities"; export function handleTransfer(event: Transfer): void { createOrLoadDistributorToken(event.address); @@ -51,3 +52,55 @@ export function handleTransfer(event: Transfer): void { ] ); } + +export function handleOpiumDepositScheduled(event: LogScheduled): void { + createOrLoadDistributorToken(event.address); + + if (event.params._pool != Address.fromString("0x3ee101bf969fac08be892c737d2969b3db38d2b8")) { + return; + } + + let holder = createOrLoadDistributorTokenHolder( + event.params._user, + event.address, + event.block + ); + holder.amount = holder.amount.plus(event.params._amount); + holder.updatedAtBlock = event.block.number; + holder.updatedAtTimestamp = event.block.timestamp; + holder.save(); + + log.info( + "[DistributorTokenHolder] Opium LogScheduled user={} amount={}", + [ + event.params._user.toHexString(), + event.params._amount.toHexString(), + ] + ); +} + +export function handleOpiumDepositUnscheduled(event: LogUnscheduled): void { + createOrLoadDistributorToken(event.address); + + if (event.params._pool != Address.fromString("0x3ee101bf969fac08be892c737d2969b3db38d2b8")) { + return; + } + + let holder = createOrLoadDistributorTokenHolder( + event.params._user, + event.address, + event.block + ); + holder.amount = holder.amount.minus(event.params._amount); + holder.updatedAtBlock = event.block.number; + holder.updatedAtTimestamp = event.block.timestamp; + holder.save(); + + log.info( + "[DistributorTokenHolder] Opium LogUnscheduled user={} amount={}", + [ + event.params._user.toHexString(), + event.params._amount.toHexString(), + ] + ); +} diff --git a/subgraphs/stakewise/subgraph.template.yaml b/subgraphs/stakewise/subgraph.template.yaml index c0e27ff..1f77d08 100644 --- a/subgraphs/stakewise/subgraph.template.yaml +++ b/subgraphs/stakewise/subgraph.template.yaml @@ -405,6 +405,34 @@ dataSources: handler: handlePaused - event: Unpaused(address) handler: handleUnpaused + +{{#opiumDepositScheduler}} + - kind: ethereum/contract + name: OpiumDepositScheduler + network: {{ network }} + source: + address: '{{ opiumDepositScheduler.address }}' + abi: OpiumDepositScheduler + startBlock: {{ opiumDepositScheduler.startBlock }} + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + file: ./src/mappings/distributorTokens.ts + entities: + - DistributorToken + - DistributorTokenHolders + - RewardEthToken + abis: + - name: OpiumDepositScheduler + file: ./packages/abis/OpiumDepositScheduler.json + eventHandlers: + - event: LogScheduled(indexed address,indexed address,uint256) + handler: handleOpiumDepositScheduled + - event: LogUnscheduled(indexed address,indexed address,uint256) + handler: handleOpiumDepositUnscheduled +{{/opiumDepositScheduler}} + {{#distributorTokens}} - kind: ethereum/contract name: DistributorToken{{index}} diff --git a/yarn.lock b/yarn.lock index 0e39ef9..e27286f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1768,9 +1768,9 @@ globby@^11.0.4: merge2 "^1.4.1" slash "^3.0.0" -"gluegun@git+https://github.com/edgeandnode/gluegun.git#v4.3.1-pin-colors-dep": +"gluegun@https://github.com/edgeandnode/gluegun#v4.3.1-pin-colors-dep": version "4.3.1" - resolved "git+https://github.com/edgeandnode/gluegun.git#b34b9003d7bf556836da41b57ef36eb21570620a" + resolved "https://github.com/edgeandnode/gluegun#b34b9003d7bf556836da41b57ef36eb21570620a" dependencies: apisauce "^1.0.1" app-module-path "^2.2.0"