From b55b5eb8494d02fbfb48cfd922ca3549e3d9a41b Mon Sep 17 00:00:00 2001 From: Dhruv Chauhan Date: Thu, 7 Nov 2024 20:04:00 +0530 Subject: [PATCH] feat(#major); stakewise-v2; add subgraph (#2645) --- deployment/deployment.json | 60 + subgraphs/stakewise-v2/.gitignore | 4 + subgraphs/stakewise-v2/README.md | 17 + .../Stakewise/OsTokenVaultController.json | 428 ++++++ .../abis/Stakewise/RewardEthToken.json | 695 ++++++++++ .../stakewise-v2/abis/Stakewise/Solos.json | 527 ++++++++ .../abis/Stakewise/StakedEthToken.json | 477 +++++++ .../abis/Stakewise/StakedGnoToken.json | 477 +++++++ .../stakewise-v2/abis/Stakewise/Vault.json | 1166 +++++++++++++++++ .../abis/Stakewise/VaultsRegistry.json | 242 ++++ .../abis/Tokens/ChainlinkDataFeed.json | 509 +++++++ subgraphs/stakewise-v2/abis/Tokens/ERC20.json | 222 ++++ .../abis/Tokens/ERC20NameBytes.json | 17 + .../abis/Tokens/ERC20SymbolBytes.json | 17 + .../stakewise-v2/abis/Tokens/_ERC20.json | 828 ++++++++++++ .../configurations/configurations.ts | 24 + .../configurations/configurations/deploy.ts | 4 + .../configurations/interface.ts | 6 + .../configurations/configure.mustache | 6 + subgraphs/stakewise-v2/package.json | 15 + .../stakewise-v2-ethereum/configurations.json | 29 + .../stakewise-v2-ethereum/configurations.ts | 21 + .../stakewise-v2-gnosis/configurations.json | 13 + .../stakewise-v2-gnosis/configurations.ts | 21 + .../templates/stakewise-v2.template.yaml | 344 +++++ subgraphs/stakewise-v2/schema.graphql | 352 +++++ .../stakewise-v2/src/common/constants.ts | 6 + .../src/mappings/handlers-gnosis.ts | 99 ++ .../stakewise-v2/src/mappings/handlers.ts | 272 ++++ subgraphs/stakewise-v2/src/sdk/README.md | 25 + .../stakewise-v2/src/sdk/protocols/config.ts | 45 + .../src/sdk/protocols/generic/account.ts | 93 ++ .../src/sdk/protocols/generic/index.ts | 72 + .../src/sdk/protocols/generic/pool.ts | 339 +++++ .../src/sdk/protocols/generic/poolSnapshot.ts | 93 ++ .../src/sdk/protocols/generic/protocol.ts | 257 ++++ .../sdk/protocols/generic/protocolSnapshot.ts | 165 +++ .../src/sdk/protocols/generic/tokens.ts | 58 + subgraphs/stakewise-v2/src/sdk/util/arrays.ts | 103 ++ .../stakewise-v2/src/sdk/util/constants.ts | 236 ++++ subgraphs/stakewise-v2/src/sdk/util/events.ts | 70 + .../stakewise-v2/src/sdk/util/numbers.ts | 61 + .../stakewise-v2/src/sdk/util/rewards.ts | 295 +++++ subgraphs/stakewise-v2/tsconfig.json | 4 + 44 files changed, 8814 insertions(+) create mode 100644 subgraphs/stakewise-v2/.gitignore create mode 100644 subgraphs/stakewise-v2/README.md create mode 100644 subgraphs/stakewise-v2/abis/Stakewise/OsTokenVaultController.json create mode 100644 subgraphs/stakewise-v2/abis/Stakewise/RewardEthToken.json create mode 100644 subgraphs/stakewise-v2/abis/Stakewise/Solos.json create mode 100644 subgraphs/stakewise-v2/abis/Stakewise/StakedEthToken.json create mode 100644 subgraphs/stakewise-v2/abis/Stakewise/StakedGnoToken.json create mode 100644 subgraphs/stakewise-v2/abis/Stakewise/Vault.json create mode 100644 subgraphs/stakewise-v2/abis/Stakewise/VaultsRegistry.json create mode 100644 subgraphs/stakewise-v2/abis/Tokens/ChainlinkDataFeed.json create mode 100644 subgraphs/stakewise-v2/abis/Tokens/ERC20.json create mode 100644 subgraphs/stakewise-v2/abis/Tokens/ERC20NameBytes.json create mode 100644 subgraphs/stakewise-v2/abis/Tokens/ERC20SymbolBytes.json create mode 100644 subgraphs/stakewise-v2/abis/Tokens/_ERC20.json create mode 100644 subgraphs/stakewise-v2/configurations/configurations/configurations.ts create mode 100644 subgraphs/stakewise-v2/configurations/configurations/deploy.ts create mode 100644 subgraphs/stakewise-v2/configurations/configurations/interface.ts create mode 100644 subgraphs/stakewise-v2/configurations/configure.mustache create mode 100644 subgraphs/stakewise-v2/package.json create mode 100644 subgraphs/stakewise-v2/protocols/stakewise-v2/config/deployments/stakewise-v2-ethereum/configurations.json create mode 100644 subgraphs/stakewise-v2/protocols/stakewise-v2/config/deployments/stakewise-v2-ethereum/configurations.ts create mode 100644 subgraphs/stakewise-v2/protocols/stakewise-v2/config/deployments/stakewise-v2-gnosis/configurations.json create mode 100644 subgraphs/stakewise-v2/protocols/stakewise-v2/config/deployments/stakewise-v2-gnosis/configurations.ts create mode 100644 subgraphs/stakewise-v2/protocols/stakewise-v2/config/templates/stakewise-v2.template.yaml create mode 100644 subgraphs/stakewise-v2/schema.graphql create mode 100644 subgraphs/stakewise-v2/src/common/constants.ts create mode 100644 subgraphs/stakewise-v2/src/mappings/handlers-gnosis.ts create mode 100644 subgraphs/stakewise-v2/src/mappings/handlers.ts create mode 100644 subgraphs/stakewise-v2/src/sdk/README.md create mode 100644 subgraphs/stakewise-v2/src/sdk/protocols/config.ts create mode 100644 subgraphs/stakewise-v2/src/sdk/protocols/generic/account.ts create mode 100644 subgraphs/stakewise-v2/src/sdk/protocols/generic/index.ts create mode 100644 subgraphs/stakewise-v2/src/sdk/protocols/generic/pool.ts create mode 100644 subgraphs/stakewise-v2/src/sdk/protocols/generic/poolSnapshot.ts create mode 100644 subgraphs/stakewise-v2/src/sdk/protocols/generic/protocol.ts create mode 100644 subgraphs/stakewise-v2/src/sdk/protocols/generic/protocolSnapshot.ts create mode 100644 subgraphs/stakewise-v2/src/sdk/protocols/generic/tokens.ts create mode 100644 subgraphs/stakewise-v2/src/sdk/util/arrays.ts create mode 100644 subgraphs/stakewise-v2/src/sdk/util/constants.ts create mode 100644 subgraphs/stakewise-v2/src/sdk/util/events.ts create mode 100644 subgraphs/stakewise-v2/src/sdk/util/numbers.ts create mode 100644 subgraphs/stakewise-v2/src/sdk/util/rewards.ts create mode 100644 subgraphs/stakewise-v2/tsconfig.json diff --git a/deployment/deployment.json b/deployment/deployment.json index ba7d5b2ae1..1188a2d908 100644 --- a/deployment/deployment.json +++ b/deployment/deployment.json @@ -13158,5 +13158,65 @@ } } } + }, + "stakewise-v2": { + "schema": "generic", + "base": "stakewise-v2", + "protocol": "stakewise-v2", + "project": "stakewise-v2", + "deployments": { + "stakewise-v2-ethereum": { + "network": "ethereum", + "status": "prod", + "versions": { + "schema": "3.0.0", + "subgraph": "1.0.0", + "methodology": "1.0.0" + }, + "files": { + "template": "stakewise-v2.template.yaml" + }, + "options": { + "prepare:yaml": true, + "prepare:constants": true + }, + "services": { + "hosted-service": { + "slug": "stakewise-v2-ethereum", + "query-id": "stakewise-v2-ethereum" + }, + "decentralized-network": { + "slug": "stakewise-v2-ethereum", + "query-id": "todo" + } + } + }, + "stakewise-v2-gnosis": { + "network": "gnosis", + "status": "prod", + "versions": { + "schema": "3.0.0", + "subgraph": "1.0.0", + "methodology": "1.0.0" + }, + "files": { + "template": "stakewise-v2.template.yaml" + }, + "options": { + "prepare:yaml": true, + "prepare:constants": true + }, + "services": { + "hosted-service": { + "slug": "stakewise-v2-gnosis", + "query-id": "stakewise-v2-gnosis" + }, + "decentralized-network": { + "slug": "stakewise-v2-gnosis", + "query-id": "todo" + } + } + } + } } } diff --git a/subgraphs/stakewise-v2/.gitignore b/subgraphs/stakewise-v2/.gitignore new file mode 100644 index 0000000000..09140957fa --- /dev/null +++ b/subgraphs/stakewise-v2/.gitignore @@ -0,0 +1,4 @@ +.DS_Store +configure.ts +docs/ +package-lock.json diff --git a/subgraphs/stakewise-v2/README.md b/subgraphs/stakewise-v2/README.md new file mode 100644 index 0000000000..8536cdcb86 --- /dev/null +++ b/subgraphs/stakewise-v2/README.md @@ -0,0 +1,17 @@ +# Stakewise V2 Subgraph + +## Methodology v1.0.0 + +## Metrics + +### Usage and Transactions + +### TVL + +### Revenue + +## Useful Links + +- Landing Page: +- Docs: +- Contracts: diff --git a/subgraphs/stakewise-v2/abis/Stakewise/OsTokenVaultController.json b/subgraphs/stakewise-v2/abis/Stakewise/OsTokenVaultController.json new file mode 100644 index 0000000000..49f1bdf613 --- /dev/null +++ b/subgraphs/stakewise-v2/abis/Stakewise/OsTokenVaultController.json @@ -0,0 +1,428 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "_keeper", "type": "address" }, + { "internalType": "address", "name": "registry", "type": "address" }, + { "internalType": "address", "name": "osToken", "type": "address" }, + { "internalType": "address", "name": "_treasury", "type": "address" }, + { "internalType": "address", "name": "_owner", "type": "address" }, + { "internalType": "uint16", "name": "_feePercent", "type": "uint16" }, + { "internalType": "uint256", "name": "_capacity", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { "inputs": [], "name": "AccessDenied", "type": "error" }, + { "inputs": [], "name": "CapacityExceeded", "type": "error" }, + { "inputs": [], "name": "InvalidFeePercent", "type": "error" }, + { "inputs": [], "name": "InvalidShares", "type": "error" }, + { "inputs": [], "name": "MathOverflowedMulDiv", "type": "error" }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" } + ], + "name": "OwnableInvalidOwner", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "OwnableUnauthorizedAccount", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint8", "name": "bits", "type": "uint8" }, + { "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "SafeCastOverflowedUintDowncast", + "type": "error" + }, + { "inputs": [], "name": "ZeroAddress", "type": "error" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "avgRewardPerSecond", + "type": "uint256" + } + ], + "name": "AvgRewardPerSecondUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "vault", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "assets", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + } + ], + "name": "Burn", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "capacity", + "type": "uint256" + } + ], + "name": "CapacityUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint16", + "name": "feePercent", + "type": "uint16" + } + ], + "name": "FeePercentUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "keeper", + "type": "address" + } + ], + "name": "KeeperUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "vault", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "assets", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + } + ], + "name": "Mint", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferStarted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "profitAccrued", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "treasuryShares", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "treasuryAssets", + "type": "uint256" + } + ], + "name": "StateUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "treasury", + "type": "address" + } + ], + "name": "TreasuryUpdated", + "type": "event" + }, + { + "inputs": [], + "name": "acceptOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "avgRewardPerSecond", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "uint256", "name": "shares", "type": "uint256" } + ], + "name": "burnShares", + "outputs": [ + { "internalType": "uint256", "name": "assets", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "capacity", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "shares", "type": "uint256" } + ], + "name": "convertToAssets", + "outputs": [ + { "internalType": "uint256", "name": "assets", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "assets", "type": "uint256" } + ], + "name": "convertToShares", + "outputs": [ + { "internalType": "uint256", "name": "shares", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "cumulativeFeePerShare", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "feePercent", + "outputs": [{ "internalType": "uint64", "name": "", "type": "uint64" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "keeper", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "uint256", "name": "shares", "type": "uint256" } + ], + "name": "mintShares", + "outputs": [ + { "internalType": "uint256", "name": "assets", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "pendingOwner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_avgRewardPerSecond", + "type": "uint256" + } + ], + "name": "setAvgRewardPerSecond", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "_capacity", "type": "uint256" } + ], + "name": "setCapacity", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint16", "name": "_feePercent", "type": "uint16" } + ], + "name": "setFeePercent", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_keeper", "type": "address" } + ], + "name": "setKeeper", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_treasury", "type": "address" } + ], + "name": "setTreasury", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "totalAssets", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalShares", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "newOwner", "type": "address" } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "treasury", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "updateState", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/subgraphs/stakewise-v2/abis/Stakewise/RewardEthToken.json b/subgraphs/stakewise-v2/abis/Stakewise/RewardEthToken.json new file mode 100644 index 0000000000..20aee467fc --- /dev/null +++ b/subgraphs/stakewise-v2/abis/Stakewise/RewardEthToken.json @@ -0,0 +1,695 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "_vault", "type": "address" }, + { "internalType": "address", "name": "_pool", "type": "address" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "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": "recipient", + "type": "address" + } + ], + "name": "ProtocolFeeRecipientUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "protocolFee", + "type": "uint256" + } + ], + "name": "ProtocolFeeUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": false, + "internalType": "bool", + "name": "isDisabled", + "type": "bool" + } + ], + "name": "RewardsToggled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "periodRewards", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "totalRewards", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "rewardPerToken", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "distributorReward", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "protocolReward", + "type": "uint256" + } + ], + "name": "RewardsUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "previousAdminRole", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "newAdminRole", + "type": "bytes32" + } + ], + "name": "RoleAdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "RoleGranted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "RoleRevoked", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Unpaused", + "type": "event" + }, + { + "inputs": [], + "name": "DEFAULT_ADMIN_ROLE", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PAUSER_ROLE", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "addAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "addPauser", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" } + ], + "name": "allowance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "approve", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "checkpoints", + "outputs": [ + { "internalType": "uint128", "name": "reward", "type": "uint128" }, + { "internalType": "uint128", "name": "rewardPerToken", "type": "uint128" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "claim", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { + "internalType": "uint256", + "name": "subtractedValue", + "type": "uint256" + } + ], + "name": "decreaseAllowance", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" } + ], + "name": "getRoleAdmin", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "uint256", "name": "index", "type": "uint256" } + ], + "name": "getRoleMember", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" } + ], + "name": "getRoleMemberCount", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "grantRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "hasRole", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "addedValue", "type": "uint256" } + ], + "name": "increaseAllowance", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "isAdmin", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "isPauser", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "lastUpdateBlockNumber", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "merkleDistributor", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "uint256", "name": "principal", "type": "uint256" }, + { "internalType": "uint256", "name": "reward", "type": "uint256" } + ], + "name": "migrate", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" } + ], + "name": "nonces", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "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": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "value", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "permit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "protocolFee", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "protocolFeeRecipient", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "removeAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "removePauser", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "renounceRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "revokeRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "rewardPerToken", + "outputs": [{ "internalType": "uint128", "name": "", "type": "uint128" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "rewardsDisabled", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "_protocolFee", "type": "uint256" } + ], + "name": "setProtocolFee", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "recipient", "type": "address" } + ], + "name": "setProtocolFeeRecipient", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" }, + { "internalType": "bool", "name": "isDisabled", "type": "bool" } + ], + "name": "setRewardsDisabled", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalAssets", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalPenalty", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalRewards", + "outputs": [{ "internalType": "uint128", "name": "", "type": "uint128" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transfer", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "sender", "type": "address" }, + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "unpause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "updateRewardCheckpoint", + "outputs": [ + { "internalType": "bool", "name": "accRewardsDisabled", "type": "bool" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "account1", "type": "address" }, + { "internalType": "address", "name": "account2", "type": "address" } + ], + "name": "updateRewardCheckpoints", + "outputs": [ + { "internalType": "bool", "name": "rewardsDisabled1", "type": "bool" }, + { "internalType": "bool", "name": "rewardsDisabled2", "type": "bool" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "int256", "name": "rewardsDelta", "type": "int256" } + ], + "name": "updateTotalRewards", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "vault", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + } +] diff --git a/subgraphs/stakewise-v2/abis/Stakewise/Solos.json b/subgraphs/stakewise-v2/abis/Stakewise/Solos.json new file mode 100644 index 0000000000..51cb82ca1d --- /dev/null +++ b/subgraphs/stakewise-v2/abis/Stakewise/Solos.json @@ -0,0 +1,527 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "_admin", "type": "address" }, + { + "internalType": "address", + "name": "_validatorRegistration", + "type": "address" + }, + { "internalType": "address", "name": "_validators", "type": "address" }, + { + "internalType": "uint256", + "name": "_validatorPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_cancelLockDuration", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "cancelLockDuration", + "type": "uint256" + } + ], + "name": "CancelLockDurationUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "soloId", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "bytes32", + "name": "withdrawalCredentials", + "type": "bytes32" + } + ], + "name": "DepositAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "soloId", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "bytes32", + "name": "withdrawalCredentials", + "type": "bytes32" + } + ], + "name": "DepositCanceled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Paused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "previousAdminRole", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "newAdminRole", + "type": "bytes32" + } + ], + "name": "RoleAdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "RoleGranted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "RoleRevoked", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Unpaused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "validatorPrice", + "type": "uint256" + } + ], + "name": "ValidatorPriceUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "soloId", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "publicKey", + "type": "bytes" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "operator", + "type": "address" + } + ], + "name": "ValidatorRegistered", + "type": "event" + }, + { + "inputs": [], + "name": "DEFAULT_ADMIN_ROLE", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PAUSER_ROLE", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "VALIDATOR_DEPOSIT", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "addAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "_withdrawalCredentials", + "type": "bytes32" + } + ], + "name": "addDeposit", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "addPauser", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "_withdrawalCredentials", + "type": "bytes32" + }, + { "internalType": "uint256", "name": "_amount", "type": "uint256" } + ], + "name": "cancelDeposit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "cancelLockDuration", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" } + ], + "name": "getRoleAdmin", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "uint256", "name": "index", "type": "uint256" } + ], + "name": "getRoleMember", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" } + ], + "name": "getRoleMemberCount", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "grantRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "hasRole", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "isAdmin", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "isPauser", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "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": [ + { + "components": [ + { "internalType": "bytes", "name": "publicKey", "type": "bytes" }, + { "internalType": "bytes", "name": "signature", "type": "bytes" }, + { + "internalType": "bytes32", + "name": "depositDataRoot", + "type": "bytes32" + }, + { "internalType": "bytes32", "name": "soloId", "type": "bytes32" } + ], + "internalType": "struct ISolos.Validator", + "name": "_validator", + "type": "tuple" + } + ], + "name": "registerValidator", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "removeAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "removePauser", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "renounceRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "revokeRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_cancelLockDuration", + "type": "uint256" + } + ], + "name": "setCancelLockDuration", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_validatorPrice", + "type": "uint256" + } + ], + "name": "setValidatorPrice", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "name": "solos", + "outputs": [ + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { + "internalType": "bytes32", + "name": "withdrawalCredentials", + "type": "bytes32" + }, + { "internalType": "uint256", "name": "releaseTime", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "unpause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "validatorPrice", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "validatorRegistration", + "outputs": [ + { + "internalType": "contract IDepositContract", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/subgraphs/stakewise-v2/abis/Stakewise/StakedEthToken.json b/subgraphs/stakewise-v2/abis/Stakewise/StakedEthToken.json new file mode 100644 index 0000000000..fbd4e135de --- /dev/null +++ b/subgraphs/stakewise-v2/abis/Stakewise/StakedEthToken.json @@ -0,0 +1,477 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Paused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "previousAdminRole", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "newAdminRole", + "type": "bytes32" + } + ], + "name": "RoleAdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "RoleGranted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "RoleRevoked", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Unpaused", + "type": "event" + }, + { + "inputs": [], + "name": "DEFAULT_ADMIN_ROLE", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PAUSER_ROLE", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "addAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "addPauser", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" } + ], + "name": "allowance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "approve", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "burn", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { + "internalType": "uint256", + "name": "subtractedValue", + "type": "uint256" + } + ], + "name": "decreaseAllowance", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "distributorPrincipal", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" } + ], + "name": "getRoleAdmin", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "uint256", "name": "index", "type": "uint256" } + ], + "name": "getRoleMember", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" } + ], + "name": "getRoleMemberCount", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "grantRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "hasRole", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "addedValue", "type": "uint256" } + ], + "name": "increaseAllowance", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "isAdmin", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "isPauser", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" } + ], + "name": "nonces", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "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": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "value", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "permit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "removeAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "removePauser", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "renounceRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "revokeRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" }, + { "internalType": "bool", "name": "isDisabled", "type": "bool" } + ], + "name": "toggleRewards", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "totalDeposits", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transfer", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "sender", "type": "address" }, + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "unpause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/subgraphs/stakewise-v2/abis/Stakewise/StakedGnoToken.json b/subgraphs/stakewise-v2/abis/Stakewise/StakedGnoToken.json new file mode 100644 index 0000000000..fbd4e135de --- /dev/null +++ b/subgraphs/stakewise-v2/abis/Stakewise/StakedGnoToken.json @@ -0,0 +1,477 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Paused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "previousAdminRole", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "newAdminRole", + "type": "bytes32" + } + ], + "name": "RoleAdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "RoleGranted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "RoleRevoked", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Unpaused", + "type": "event" + }, + { + "inputs": [], + "name": "DEFAULT_ADMIN_ROLE", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PAUSER_ROLE", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "addAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "addPauser", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" } + ], + "name": "allowance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "approve", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "burn", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { + "internalType": "uint256", + "name": "subtractedValue", + "type": "uint256" + } + ], + "name": "decreaseAllowance", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "distributorPrincipal", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" } + ], + "name": "getRoleAdmin", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "uint256", "name": "index", "type": "uint256" } + ], + "name": "getRoleMember", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" } + ], + "name": "getRoleMemberCount", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "grantRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "hasRole", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "addedValue", "type": "uint256" } + ], + "name": "increaseAllowance", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "isAdmin", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "isPauser", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" } + ], + "name": "nonces", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "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": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "value", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "permit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "removeAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_account", "type": "address" } + ], + "name": "removePauser", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "renounceRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "revokeRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" }, + { "internalType": "bool", "name": "isDisabled", "type": "bool" } + ], + "name": "toggleRewards", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "totalDeposits", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transfer", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "sender", "type": "address" }, + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "unpause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/subgraphs/stakewise-v2/abis/Stakewise/Vault.json b/subgraphs/stakewise-v2/abis/Stakewise/Vault.json new file mode 100644 index 0000000000..cef6a3ea91 --- /dev/null +++ b/subgraphs/stakewise-v2/abis/Stakewise/Vault.json @@ -0,0 +1,1166 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "_keeper", "type": "address" }, + { + "internalType": "address", + "name": "_vaultsRegistry", + "type": "address" + }, + { + "internalType": "address", + "name": "_validatorsRegistry", + "type": "address" + }, + { + "internalType": "address", + "name": "osTokenVaultController", + "type": "address" + }, + { "internalType": "address", "name": "osTokenConfig", "type": "address" }, + { + "internalType": "address", + "name": "sharedMevEscrow", + "type": "address" + }, + { + "internalType": "address", + "name": "depositDataRegistry", + "type": "address" + }, + { + "internalType": "uint256", + "name": "exitingAssetsClaimDelay", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { "inputs": [], "name": "AccessDenied", "type": "error" }, + { + "inputs": [ + { "internalType": "address", "name": "target", "type": "address" } + ], + "name": "AddressEmptyCode", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "AddressInsufficientBalance", + "type": "error" + }, + { "inputs": [], "name": "CapacityExceeded", "type": "error" }, + { + "inputs": [ + { "internalType": "address", "name": "implementation", "type": "address" } + ], + "name": "ERC1967InvalidImplementation", + "type": "error" + }, + { "inputs": [], "name": "ERC1967NonPayable", "type": "error" }, + { "inputs": [], "name": "ExitRequestNotProcessed", "type": "error" }, + { "inputs": [], "name": "FailedInnerCall", "type": "error" }, + { "inputs": [], "name": "InsufficientAssets", "type": "error" }, + { "inputs": [], "name": "InvalidAssets", "type": "error" }, + { "inputs": [], "name": "InvalidCapacity", "type": "error" }, + { "inputs": [], "name": "InvalidCheckpointIndex", "type": "error" }, + { "inputs": [], "name": "InvalidCheckpointValue", "type": "error" }, + { "inputs": [], "name": "InvalidFeePercent", "type": "error" }, + { "inputs": [], "name": "InvalidFeeRecipient", "type": "error" }, + { "inputs": [], "name": "InvalidHealthFactor", "type": "error" }, + { "inputs": [], "name": "InvalidInitialization", "type": "error" }, + { "inputs": [], "name": "InvalidPosition", "type": "error" }, + { "inputs": [], "name": "InvalidReceivedAssets", "type": "error" }, + { "inputs": [], "name": "InvalidSecurityDeposit", "type": "error" }, + { "inputs": [], "name": "InvalidShares", "type": "error" }, + { "inputs": [], "name": "InvalidValidators", "type": "error" }, + { "inputs": [], "name": "LiquidationDisabled", "type": "error" }, + { "inputs": [], "name": "LowLtv", "type": "error" }, + { "inputs": [], "name": "MathOverflowedMulDiv", "type": "error" }, + { "inputs": [], "name": "NotCollateralized", "type": "error" }, + { "inputs": [], "name": "NotHarvested", "type": "error" }, + { "inputs": [], "name": "NotInitializing", "type": "error" }, + { "inputs": [], "name": "ReentrancyGuardReentrantCall", "type": "error" }, + { + "inputs": [ + { "internalType": "uint8", "name": "bits", "type": "uint8" }, + { "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "SafeCastOverflowedUintDowncast", + "type": "error" + }, + { "inputs": [], "name": "UUPSUnauthorizedCallContext", "type": "error" }, + { + "inputs": [ + { "internalType": "bytes32", "name": "slot", "type": "bytes32" } + ], + "name": "UUPSUnsupportedProxiableUUID", + "type": "error" + }, + { "inputs": [], "name": "UpgradeFailed", "type": "error" }, + { "inputs": [], "name": "ZeroAddress", "type": "error" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "assets", + "type": "uint256" + } + ], + "name": "CheckpointCreated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "assets", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "referrer", + "type": "address" + } + ], + "name": "Deposited", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "positionTicket", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + } + ], + "name": "ExitQueueEntered", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "prevPositionTicket", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "newPositionTicket", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "withdrawnAssets", + "type": "uint256" + } + ], + "name": "ExitedAssetsClaimed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "penalty", + "type": "uint256" + } + ], + "name": "ExitingAssetsPenalized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "feeRecipient", + "type": "address" + } + ], + "name": "FeeRecipientUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "assets", + "type": "uint256" + } + ], + "name": "FeeSharesMinted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint64", + "name": "version", + "type": "uint64" + } + ], + "name": "Initialized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "keysManager", + "type": "address" + } + ], + "name": "KeysManagerUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": false, + "internalType": "string", + "name": "metadataIpfsHash", + "type": "string" + } + ], + "name": "MetadataUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "assets", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + } + ], + "name": "OsTokenBurned", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "osTokenShares", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "receivedAssets", + "type": "uint256" + } + ], + "name": "OsTokenLiquidated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "assets", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "referrer", + "type": "address" + } + ], + "name": "OsTokenMinted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "osTokenShares", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "assets", + "type": "uint256" + } + ], + "name": "OsTokenRedeemed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "assets", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + } + ], + "name": "Redeemed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "implementation", + "type": "address" + } + ], + "name": "Upgraded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "positionTicket", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "assets", + "type": "uint256" + } + ], + "name": "V2ExitQueueEntered", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "bytes", + "name": "publicKey", + "type": "bytes" + } + ], + "name": "ValidatorRegistered", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "validatorsManager", + "type": "address" + } + ], + "name": "ValidatorsManagerUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "validatorsRoot", + "type": "bytes32" + } + ], + "name": "ValidatorsRootUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": false, + "internalType": "bool", + "name": "approved", + "type": "bool" + } + ], + "name": "WhitelistUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "whitelister", + "type": "address" + } + ], + "name": "WhitelisterUpdated", + "type": "event" + }, + { + "inputs": [], + "name": "UPGRADE_INTERFACE_VERSION", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "admin", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint128", "name": "osTokenShares", "type": "uint128" } + ], + "name": "burnOsToken", + "outputs": [ + { "internalType": "uint256", "name": "assets", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "receiver", "type": "address" }, + { + "internalType": "uint256", + "name": "positionTicket", + "type": "uint256" + }, + { "internalType": "uint256", "name": "timestamp", "type": "uint256" }, + { "internalType": "uint256", "name": "exitQueueIndex", "type": "uint256" } + ], + "name": "calculateExitedAssets", + "outputs": [ + { "internalType": "uint256", "name": "leftTickets", "type": "uint256" }, + { "internalType": "uint256", "name": "exitedTickets", "type": "uint256" }, + { "internalType": "uint256", "name": "exitedAssets", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "capacity", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "positionTicket", + "type": "uint256" + }, + { "internalType": "uint256", "name": "timestamp", "type": "uint256" }, + { "internalType": "uint256", "name": "exitQueueIndex", "type": "uint256" } + ], + "name": "claimExitedAssets", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "shares", "type": "uint256" } + ], + "name": "convertToAssets", + "outputs": [ + { "internalType": "uint256", "name": "assets", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "assets", "type": "uint256" } + ], + "name": "convertToShares", + "outputs": [ + { "internalType": "uint256", "name": "shares", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "address", "name": "referrer", "type": "address" } + ], + "name": "deposit", + "outputs": [ + { "internalType": "uint256", "name": "shares", "type": "uint256" } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "uint256", "name": "osTokenShares", "type": "uint256" }, + { "internalType": "address", "name": "referrer", "type": "address" } + ], + "name": "depositAndMintOsToken", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "shares", "type": "uint256" }, + { "internalType": "address", "name": "receiver", "type": "address" } + ], + "name": "enterExitQueue", + "outputs": [ + { "internalType": "uint256", "name": "positionTicket", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "feePercent", + "outputs": [{ "internalType": "uint16", "name": "", "type": "uint16" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "feeRecipient", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "positionTicket", "type": "uint256" } + ], + "name": "getExitQueueIndex", + "outputs": [{ "internalType": "int256", "name": "", "type": "int256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "getShares", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "implementation", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes", "name": "params", "type": "bytes" }], + "name": "initialize", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "isStateUpdateRequired", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "osTokenShares", "type": "uint256" }, + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "receiver", "type": "address" } + ], + "name": "liquidateOsToken", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "mevEscrow", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "uint256", "name": "osTokenShares", "type": "uint256" }, + { "internalType": "address", "name": "referrer", "type": "address" } + ], + "name": "mintOsToken", + "outputs": [ + { "internalType": "uint256", "name": "assets", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes[]", "name": "data", "type": "bytes[]" } + ], + "name": "multicall", + "outputs": [ + { "internalType": "bytes[]", "name": "results", "type": "bytes[]" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "user", "type": "address" } + ], + "name": "osTokenPositions", + "outputs": [ + { "internalType": "uint128", "name": "shares", "type": "uint128" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "proxiableUUID", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "queuedShares", + "outputs": [{ "internalType": "uint128", "name": "", "type": "uint128" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "receiveFromMevEscrow", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "osTokenShares", "type": "uint256" }, + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "receiver", "type": "address" } + ], + "name": "redeemOsToken", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "bytes32", + "name": "validatorsRegistryRoot", + "type": "bytes32" + }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { "internalType": "bytes", "name": "validators", "type": "bytes" }, + { "internalType": "bytes", "name": "signatures", "type": "bytes" }, + { + "internalType": "string", + "name": "exitSignaturesIpfsHash", + "type": "string" + } + ], + "internalType": "struct IKeeperValidators.ApprovalParams", + "name": "keeperParams", + "type": "tuple" + }, + { + "internalType": "bytes", + "name": "validatorsManagerSignature", + "type": "bytes" + } + ], + "name": "registerValidators", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_feeRecipient", "type": "address" } + ], + "name": "setFeeRecipient", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "string", "name": "metadataIpfsHash", "type": "string" } + ], + "name": "setMetadata", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "validatorsManager_", + "type": "address" + } + ], + "name": "setValidatorsManager", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_whitelister", "type": "address" } + ], + "name": "setWhitelister", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "totalAssets", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalExitingAssets", + "outputs": [{ "internalType": "uint128", "name": "", "type": "uint128" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalShares", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "bytes32", + "name": "rewardsRoot", + "type": "bytes32" + }, + { "internalType": "int160", "name": "reward", "type": "int160" }, + { + "internalType": "uint160", + "name": "unlockedMevReward", + "type": "uint160" + }, + { "internalType": "bytes32[]", "name": "proof", "type": "bytes32[]" } + ], + "internalType": "struct IKeeperRewards.HarvestParams", + "name": "harvestParams", + "type": "tuple" + } + ], + "name": "updateState", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "address", "name": "referrer", "type": "address" }, + { + "components": [ + { + "internalType": "bytes32", + "name": "rewardsRoot", + "type": "bytes32" + }, + { "internalType": "int160", "name": "reward", "type": "int160" }, + { + "internalType": "uint160", + "name": "unlockedMevReward", + "type": "uint160" + }, + { "internalType": "bytes32[]", "name": "proof", "type": "bytes32[]" } + ], + "internalType": "struct IKeeperRewards.HarvestParams", + "name": "harvestParams", + "type": "tuple" + } + ], + "name": "updateStateAndDeposit", + "outputs": [ + { "internalType": "uint256", "name": "shares", "type": "uint256" } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "uint256", "name": "osTokenShares", "type": "uint256" }, + { "internalType": "address", "name": "referrer", "type": "address" }, + { + "components": [ + { + "internalType": "bytes32", + "name": "rewardsRoot", + "type": "bytes32" + }, + { "internalType": "int160", "name": "reward", "type": "int160" }, + { + "internalType": "uint160", + "name": "unlockedMevReward", + "type": "uint160" + }, + { "internalType": "bytes32[]", "name": "proof", "type": "bytes32[]" } + ], + "internalType": "struct IKeeperRewards.HarvestParams", + "name": "harvestParams", + "type": "tuple" + } + ], + "name": "updateStateAndDepositAndMintOsToken", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" }, + { "internalType": "bool", "name": "approved", "type": "bool" } + ], + "name": "updateWhitelist", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation", + "type": "address" + }, + { "internalType": "bytes", "name": "data", "type": "bytes" } + ], + "name": "upgradeToAndCall", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "validatorsManager", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "vaultId", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [], + "name": "version", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "whitelistedAccounts", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "whitelister", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "withdrawableAssets", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { "stateMutability": "payable", "type": "receive" } +] diff --git a/subgraphs/stakewise-v2/abis/Stakewise/VaultsRegistry.json b/subgraphs/stakewise-v2/abis/Stakewise/VaultsRegistry.json new file mode 100644 index 0000000000..14a88b63e1 --- /dev/null +++ b/subgraphs/stakewise-v2/abis/Stakewise/VaultsRegistry.json @@ -0,0 +1,242 @@ +[ + { "inputs": [], "stateMutability": "nonpayable", "type": "constructor" }, + { "inputs": [], "name": "AccessDenied", "type": "error" }, + { "inputs": [], "name": "AlreadyAdded", "type": "error" }, + { "inputs": [], "name": "AlreadyRemoved", "type": "error" }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" } + ], + "name": "OwnableInvalidOwner", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "OwnableUnauthorizedAccount", + "type": "error" + }, + { "inputs": [], "name": "ZeroAddress", "type": "error" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "factory", + "type": "address" + } + ], + "name": "FactoryAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "factory", + "type": "address" + } + ], + "name": "FactoryRemoved", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferStarted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "vault", + "type": "address" + } + ], + "name": "VaultAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "impl", + "type": "address" + } + ], + "name": "VaultImplAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "impl", + "type": "address" + } + ], + "name": "VaultImplRemoved", + "type": "event" + }, + { + "inputs": [], + "name": "acceptOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "factory", "type": "address" } + ], + "name": "addFactory", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "vault", "type": "address" } + ], + "name": "addVault", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "newImpl", "type": "address" } + ], + "name": "addVaultImpl", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "factories", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_owner", "type": "address" } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "pendingOwner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "factory", "type": "address" } + ], + "name": "removeFactory", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "impl", "type": "address" } + ], + "name": "removeVaultImpl", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "newOwner", "type": "address" } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "vaultImpls", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "vaults", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + } +] diff --git a/subgraphs/stakewise-v2/abis/Tokens/ChainlinkDataFeed.json b/subgraphs/stakewise-v2/abis/Tokens/ChainlinkDataFeed.json new file mode 100644 index 0000000000..bca8a84144 --- /dev/null +++ b/subgraphs/stakewise-v2/abis/Tokens/ChainlinkDataFeed.json @@ -0,0 +1,509 @@ +[ + { + "inputs": [ + { + "internalType": "address", + "name": "_aggregator", + "type": "address" + }, + { + "internalType": "address", + "name": "_accessController", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "int256", + "name": "current", + "type": "int256" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "roundId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "updatedAt", + "type": "uint256" + } + ], + "name": "AnswerUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "roundId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "startedBy", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "startedAt", + "type": "uint256" + } + ], + "name": "NewRound", + "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" + }, + { + "inputs": [], + "name": "acceptOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "accessController", + "outputs": [ + { + "internalType": "contract AccessControllerInterface", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "aggregator", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_aggregator", + "type": "address" + } + ], + "name": "confirmAggregator", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "description", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_roundId", + "type": "uint256" + } + ], + "name": "getAnswer", + "outputs": [ + { + "internalType": "int256", + "name": "", + "type": "int256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint80", + "name": "_roundId", + "type": "uint80" + } + ], + "name": "getRoundData", + "outputs": [ + { + "internalType": "uint80", + "name": "roundId", + "type": "uint80" + }, + { + "internalType": "int256", + "name": "answer", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "startedAt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "updatedAt", + "type": "uint256" + }, + { + "internalType": "uint80", + "name": "answeredInRound", + "type": "uint80" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_roundId", + "type": "uint256" + } + ], + "name": "getTimestamp", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "latestAnswer", + "outputs": [ + { + "internalType": "int256", + "name": "", + "type": "int256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "latestRound", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "latestRoundData", + "outputs": [ + { + "internalType": "uint80", + "name": "roundId", + "type": "uint80" + }, + { + "internalType": "int256", + "name": "answer", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "startedAt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "updatedAt", + "type": "uint256" + }, + { + "internalType": "uint80", + "name": "answeredInRound", + "type": "uint80" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "latestTimestamp", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "name": "phaseAggregators", + "outputs": [ + { + "internalType": "contract AggregatorV2V3Interface", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "phaseId", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_aggregator", + "type": "address" + } + ], + "name": "proposeAggregator", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "proposedAggregator", + "outputs": [ + { + "internalType": "contract AggregatorV2V3Interface", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint80", + "name": "_roundId", + "type": "uint80" + } + ], + "name": "proposedGetRoundData", + "outputs": [ + { + "internalType": "uint80", + "name": "roundId", + "type": "uint80" + }, + { + "internalType": "int256", + "name": "answer", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "startedAt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "updatedAt", + "type": "uint256" + }, + { + "internalType": "uint80", + "name": "answeredInRound", + "type": "uint80" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "proposedLatestRoundData", + "outputs": [ + { + "internalType": "uint80", + "name": "roundId", + "type": "uint80" + }, + { + "internalType": "int256", + "name": "answer", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "startedAt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "updatedAt", + "type": "uint256" + }, + { + "internalType": "uint80", + "name": "answeredInRound", + "type": "uint80" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_accessController", + "type": "address" + } + ], + "name": "setController", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_to", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "version", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/subgraphs/stakewise-v2/abis/Tokens/ERC20.json b/subgraphs/stakewise-v2/abis/Tokens/ERC20.json new file mode 100644 index 0000000000..405d6b3648 --- /dev/null +++ b/subgraphs/stakewise-v2/abis/Tokens/ERC20.json @@ -0,0 +1,222 @@ +[ + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [ + { + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_spender", + "type": "address" + }, + { + "name": "_value", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_from", + "type": "address" + }, + { + "name": "_to", + "type": "address" + }, + { + "name": "_value", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [ + { + "name": "", + "type": "uint8" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "_owner", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "name": "balance", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [ + { + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_to", + "type": "address" + }, + { + "name": "_value", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "_owner", + "type": "address" + }, + { + "name": "_spender", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "payable": true, + "stateMutability": "payable", + "type": "fallback" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "from", + "type": "address" + }, + { + "indexed": true, + "name": "to", + "type": "address" + }, + { + "indexed": false, + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + } +] diff --git a/subgraphs/stakewise-v2/abis/Tokens/ERC20NameBytes.json b/subgraphs/stakewise-v2/abis/Tokens/ERC20NameBytes.json new file mode 100644 index 0000000000..2d3c877a8c --- /dev/null +++ b/subgraphs/stakewise-v2/abis/Tokens/ERC20NameBytes.json @@ -0,0 +1,17 @@ +[ + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + } +] diff --git a/subgraphs/stakewise-v2/abis/Tokens/ERC20SymbolBytes.json b/subgraphs/stakewise-v2/abis/Tokens/ERC20SymbolBytes.json new file mode 100644 index 0000000000..a76d616366 --- /dev/null +++ b/subgraphs/stakewise-v2/abis/Tokens/ERC20SymbolBytes.json @@ -0,0 +1,17 @@ +[ + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + } +] diff --git a/subgraphs/stakewise-v2/abis/Tokens/_ERC20.json b/subgraphs/stakewise-v2/abis/Tokens/_ERC20.json new file mode 100644 index 0000000000..5c47f76a53 --- /dev/null +++ b/subgraphs/stakewise-v2/abis/Tokens/_ERC20.json @@ -0,0 +1,828 @@ +[ + { + "name": "Transfer", + "inputs": [ + { "type": "address", "name": "sender", "indexed": true }, + { "type": "address", "name": "receiver", "indexed": true }, + { "type": "uint256", "name": "value", "indexed": false } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "Approval", + "inputs": [ + { "type": "address", "name": "owner", "indexed": true }, + { "type": "address", "name": "spender", "indexed": true }, + { "type": "uint256", "name": "value", "indexed": false } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "StrategyAdded", + "inputs": [ + { "type": "address", "name": "strategy", "indexed": true }, + { "type": "uint256", "name": "debtRatio", "indexed": false }, + { "type": "uint256", "name": "rateLimit", "indexed": false }, + { "type": "uint256", "name": "performanceFee", "indexed": false } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "StrategyReported", + "inputs": [ + { "type": "address", "name": "strategy", "indexed": true }, + { "type": "uint256", "name": "gain", "indexed": false }, + { "type": "uint256", "name": "loss", "indexed": false }, + { "type": "uint256", "name": "totalGain", "indexed": false }, + { "type": "uint256", "name": "totalLoss", "indexed": false }, + { "type": "uint256", "name": "totalDebt", "indexed": false }, + { "type": "uint256", "name": "debtAdded", "indexed": false }, + { "type": "uint256", "name": "debtRatio", "indexed": false } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "UpdateGovernance", + "inputs": [{ "type": "address", "name": "governance", "indexed": false }], + "anonymous": false, + "type": "event" + }, + { + "name": "UpdateManagement", + "inputs": [{ "type": "address", "name": "management", "indexed": false }], + "anonymous": false, + "type": "event" + }, + { + "name": "UpdateGuestList", + "inputs": [{ "type": "address", "name": "guestList", "indexed": false }], + "anonymous": false, + "type": "event" + }, + { + "name": "UpdateRewards", + "inputs": [{ "type": "address", "name": "rewards", "indexed": false }], + "anonymous": false, + "type": "event" + }, + { + "name": "UpdateDepositLimit", + "inputs": [{ "type": "uint256", "name": "depositLimit", "indexed": false }], + "anonymous": false, + "type": "event" + }, + { + "name": "UpdatePerformanceFee", + "inputs": [ + { "type": "uint256", "name": "performanceFee", "indexed": false } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "UpdateManagementFee", + "inputs": [ + { "type": "uint256", "name": "managementFee", "indexed": false } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "UpdateGuardian", + "inputs": [{ "type": "address", "name": "guardian", "indexed": false }], + "anonymous": false, + "type": "event" + }, + { + "name": "EmergencyShutdown", + "inputs": [{ "type": "bool", "name": "active", "indexed": false }], + "anonymous": false, + "type": "event" + }, + { + "name": "UpdateWithdrawalQueue", + "inputs": [{ "type": "address[20]", "name": "queue", "indexed": false }], + "anonymous": false, + "type": "event" + }, + { + "name": "StrategyUpdateDebtRatio", + "inputs": [ + { "type": "address", "name": "strategy", "indexed": true }, + { "type": "uint256", "name": "debtRatio", "indexed": false } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "StrategyUpdateRateLimit", + "inputs": [ + { "type": "address", "name": "strategy", "indexed": true }, + { "type": "uint256", "name": "rateLimit", "indexed": false } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "StrategyUpdatePerformanceFee", + "inputs": [ + { "type": "address", "name": "strategy", "indexed": true }, + { "type": "uint256", "name": "performanceFee", "indexed": false } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "StrategyMigrated", + "inputs": [ + { "type": "address", "name": "oldVersion", "indexed": true }, + { "type": "address", "name": "newVersion", "indexed": true } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "StrategyRevoked", + "inputs": [{ "type": "address", "name": "strategy", "indexed": true }], + "anonymous": false, + "type": "event" + }, + { + "name": "StrategyRemovedFromQueue", + "inputs": [{ "type": "address", "name": "strategy", "indexed": true }], + "anonymous": false, + "type": "event" + }, + { + "name": "StrategyAddedToQueue", + "inputs": [{ "type": "address", "name": "strategy", "indexed": true }], + "anonymous": false, + "type": "event" + }, + { + "name": "initialize", + "outputs": [], + "inputs": [ + { "type": "address", "name": "token" }, + { "type": "address", "name": "governance" }, + { "type": "address", "name": "rewards" }, + { "type": "string", "name": "nameOverride" }, + { "type": "string", "name": "symbolOverride" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "initialize", + "outputs": [], + "inputs": [ + { "type": "address", "name": "token" }, + { "type": "address", "name": "governance" }, + { "type": "address", "name": "rewards" }, + { "type": "string", "name": "nameOverride" }, + { "type": "string", "name": "symbolOverride" }, + { "type": "address", "name": "guardian" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "apiVersion", + "outputs": [{ "type": "string", "name": "" }], + "inputs": [], + "stateMutability": "pure", + "type": "function", + "gas": 4519 + }, + { + "name": "setName", + "outputs": [], + "inputs": [{ "type": "string", "name": "name" }], + "stateMutability": "nonpayable", + "type": "function", + "gas": 107017 + }, + { + "name": "setSymbol", + "outputs": [], + "inputs": [{ "type": "string", "name": "symbol" }], + "stateMutability": "nonpayable", + "type": "function", + "gas": 71867 + }, + { + "name": "setGovernance", + "outputs": [], + "inputs": [{ "type": "address", "name": "governance" }], + "stateMutability": "nonpayable", + "type": "function", + "gas": 36338 + }, + { + "name": "acceptGovernance", + "outputs": [], + "inputs": [], + "stateMutability": "nonpayable", + "type": "function", + "gas": 37610 + }, + { + "name": "setManagement", + "outputs": [], + "inputs": [{ "type": "address", "name": "management" }], + "stateMutability": "nonpayable", + "type": "function", + "gas": 37748 + }, + { + "name": "setGuestList", + "outputs": [], + "inputs": [{ "type": "address", "name": "guestList" }], + "stateMutability": "nonpayable", + "type": "function", + "gas": 37778 + }, + { + "name": "setRewards", + "outputs": [], + "inputs": [{ "type": "address", "name": "rewards" }], + "stateMutability": "nonpayable", + "type": "function", + "gas": 37808 + }, + { + "name": "setDepositLimit", + "outputs": [], + "inputs": [{ "type": "uint256", "name": "limit" }], + "stateMutability": "nonpayable", + "type": "function", + "gas": 37738 + }, + { + "name": "setPerformanceFee", + "outputs": [], + "inputs": [{ "type": "uint256", "name": "fee" }], + "stateMutability": "nonpayable", + "type": "function", + "gas": 37872 + }, + { + "name": "setManagementFee", + "outputs": [], + "inputs": [{ "type": "uint256", "name": "fee" }], + "stateMutability": "nonpayable", + "type": "function", + "gas": 37902 + }, + { + "name": "setGuardian", + "outputs": [], + "inputs": [{ "type": "address", "name": "guardian" }], + "stateMutability": "nonpayable", + "type": "function", + "gas": 39146 + }, + { + "name": "setEmergencyShutdown", + "outputs": [], + "inputs": [{ "type": "bool", "name": "active" }], + "stateMutability": "nonpayable", + "type": "function", + "gas": 39217 + }, + { + "name": "setWithdrawalQueue", + "outputs": [], + "inputs": [{ "type": "address[20]", "name": "queue" }], + "stateMutability": "nonpayable", + "type": "function", + "gas": 763893 + }, + { + "name": "transfer", + "outputs": [{ "type": "bool", "name": "" }], + "inputs": [ + { "type": "address", "name": "receiver" }, + { "type": "uint256", "name": "amount" } + ], + "stateMutability": "nonpayable", + "type": "function", + "gas": 76733 + }, + { + "name": "transferFrom", + "outputs": [{ "type": "bool", "name": "" }], + "inputs": [ + { "type": "address", "name": "sender" }, + { "type": "address", "name": "receiver" }, + { "type": "uint256", "name": "amount" } + ], + "stateMutability": "nonpayable", + "type": "function", + "gas": 116496 + }, + { + "name": "approve", + "outputs": [{ "type": "bool", "name": "" }], + "inputs": [ + { "type": "address", "name": "spender" }, + { "type": "uint256", "name": "amount" } + ], + "stateMutability": "nonpayable", + "type": "function", + "gas": 38244 + }, + { + "name": "increaseAllowance", + "outputs": [{ "type": "bool", "name": "" }], + "inputs": [ + { "type": "address", "name": "spender" }, + { "type": "uint256", "name": "amount" } + ], + "stateMutability": "nonpayable", + "type": "function", + "gas": 40285 + }, + { + "name": "decreaseAllowance", + "outputs": [{ "type": "bool", "name": "" }], + "inputs": [ + { "type": "address", "name": "spender" }, + { "type": "uint256", "name": "amount" } + ], + "stateMutability": "nonpayable", + "type": "function", + "gas": 40309 + }, + { + "name": "permit", + "outputs": [{ "type": "bool", "name": "" }], + "inputs": [ + { "type": "address", "name": "owner" }, + { "type": "address", "name": "spender" }, + { "type": "uint256", "name": "amount" }, + { "type": "uint256", "name": "expiry" }, + { "type": "bytes", "name": "signature" } + ], + "stateMutability": "nonpayable", + "type": "function", + "gas": 81237 + }, + { + "name": "totalAssets", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 4123 + }, + { + "name": "deposit", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "deposit", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [{ "type": "uint256", "name": "_amount" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "deposit", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [ + { "type": "uint256", "name": "_amount" }, + { "type": "address", "name": "recipient" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "maxAvailableShares", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 364171 + }, + { + "name": "withdraw", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "withdraw", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [{ "type": "uint256", "name": "maxShares" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "withdraw", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [ + { "type": "uint256", "name": "maxShares" }, + { "type": "address", "name": "recipient" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "withdraw", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [ + { "type": "uint256", "name": "maxShares" }, + { "type": "address", "name": "recipient" }, + { "type": "uint256", "name": "maxLoss" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "pricePerShare", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 12412 + }, + { + "name": "addStrategy", + "outputs": [], + "inputs": [ + { "type": "address", "name": "strategy" }, + { "type": "uint256", "name": "debtRatio" }, + { "type": "uint256", "name": "rateLimit" }, + { "type": "uint256", "name": "performanceFee" } + ], + "stateMutability": "nonpayable", + "type": "function", + "gas": 1450351 + }, + { + "name": "updateStrategyDebtRatio", + "outputs": [], + "inputs": [ + { "type": "address", "name": "strategy" }, + { "type": "uint256", "name": "debtRatio" } + ], + "stateMutability": "nonpayable", + "type": "function", + "gas": 115316 + }, + { + "name": "updateStrategyRateLimit", + "outputs": [], + "inputs": [ + { "type": "address", "name": "strategy" }, + { "type": "uint256", "name": "rateLimit" } + ], + "stateMutability": "nonpayable", + "type": "function", + "gas": 41467 + }, + { + "name": "updateStrategyPerformanceFee", + "outputs": [], + "inputs": [ + { "type": "address", "name": "strategy" }, + { "type": "uint256", "name": "performanceFee" } + ], + "stateMutability": "nonpayable", + "type": "function", + "gas": 41344 + }, + { + "name": "migrateStrategy", + "outputs": [], + "inputs": [ + { "type": "address", "name": "oldVersion" }, + { "type": "address", "name": "newVersion" } + ], + "stateMutability": "nonpayable", + "type": "function", + "gas": 1105801 + }, + { + "name": "revokeStrategy", + "outputs": [], + "inputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "revokeStrategy", + "outputs": [], + "inputs": [{ "type": "address", "name": "strategy" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "addStrategyToQueue", + "outputs": [], + "inputs": [{ "type": "address", "name": "strategy" }], + "stateMutability": "nonpayable", + "type": "function", + "gas": 1196920 + }, + { + "name": "removeStrategyFromQueue", + "outputs": [], + "inputs": [{ "type": "address", "name": "strategy" }], + "stateMutability": "nonpayable", + "type": "function", + "gas": 23091666 + }, + { + "name": "debtOutstanding", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function" + }, + { + "name": "debtOutstanding", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [{ "type": "address", "name": "strategy" }], + "stateMutability": "view", + "type": "function" + }, + { + "name": "creditAvailable", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function" + }, + { + "name": "creditAvailable", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [{ "type": "address", "name": "strategy" }], + "stateMutability": "view", + "type": "function" + }, + { + "name": "availableDepositLimit", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 9808 + }, + { + "name": "expectedReturn", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function" + }, + { + "name": "expectedReturn", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [{ "type": "address", "name": "strategy" }], + "stateMutability": "view", + "type": "function" + }, + { + "name": "report", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [ + { "type": "uint256", "name": "gain" }, + { "type": "uint256", "name": "loss" }, + { "type": "uint256", "name": "_debtPayment" } + ], + "stateMutability": "nonpayable", + "type": "function", + "gas": 937520 + }, + { + "name": "sweep", + "outputs": [], + "inputs": [{ "type": "address", "name": "token" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "sweep", + "outputs": [], + "inputs": [ + { "type": "address", "name": "token" }, + { "type": "uint256", "name": "amount" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "name": "name", + "outputs": [{ "type": "string", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 9053 + }, + { + "name": "symbol", + "outputs": [{ "type": "string", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 8106 + }, + { + "name": "decimals", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 2711 + }, + { + "name": "balanceOf", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [{ "type": "address", "name": "arg0" }], + "stateMutability": "view", + "type": "function", + "gas": 2956 + }, + { + "name": "allowance", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [ + { "type": "address", "name": "arg0" }, + { "type": "address", "name": "arg1" } + ], + "stateMutability": "view", + "type": "function", + "gas": 3201 + }, + { + "name": "totalSupply", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 2801 + }, + { + "name": "token", + "outputs": [{ "type": "address", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 2831 + }, + { + "name": "governance", + "outputs": [{ "type": "address", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 2861 + }, + { + "name": "management", + "outputs": [{ "type": "address", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 2891 + }, + { + "name": "guardian", + "outputs": [{ "type": "address", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 2921 + }, + { + "name": "guestList", + "outputs": [{ "type": "address", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 2951 + }, + { + "name": "strategies", + "outputs": [ + { "type": "uint256", "name": "performanceFee" }, + { "type": "uint256", "name": "activation" }, + { "type": "uint256", "name": "debtRatio" }, + { "type": "uint256", "name": "rateLimit" }, + { "type": "uint256", "name": "lastReport" }, + { "type": "uint256", "name": "totalDebt" }, + { "type": "uint256", "name": "totalGain" }, + { "type": "uint256", "name": "totalLoss" } + ], + "inputs": [{ "type": "address", "name": "arg0" }], + "stateMutability": "view", + "type": "function", + "gas": 10322 + }, + { + "name": "withdrawalQueue", + "outputs": [{ "type": "address", "name": "" }], + "inputs": [{ "type": "uint256", "name": "arg0" }], + "stateMutability": "view", + "type": "function", + "gas": 3120 + }, + { + "name": "emergencyShutdown", + "outputs": [{ "type": "bool", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 3041 + }, + { + "name": "depositLimit", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 3071 + }, + { + "name": "debtRatio", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 3101 + }, + { + "name": "totalDebt", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 3131 + }, + { + "name": "lastReport", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 3161 + }, + { + "name": "activation", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 3191 + }, + { + "name": "rewards", + "outputs": [{ "type": "address", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 3221 + }, + { + "name": "managementFee", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 3251 + }, + { + "name": "performanceFee", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 3281 + }, + { + "name": "nonces", + "outputs": [{ "type": "uint256", "name": "" }], + "inputs": [{ "type": "address", "name": "arg0" }], + "stateMutability": "view", + "type": "function", + "gas": 3526 + }, + { + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "type": "bytes32", "name": "" }], + "inputs": [], + "stateMutability": "view", + "type": "function", + "gas": 3341 + } +] diff --git a/subgraphs/stakewise-v2/configurations/configurations/configurations.ts b/subgraphs/stakewise-v2/configurations/configurations/configurations.ts new file mode 100644 index 0000000000..045e3c8c8c --- /dev/null +++ b/subgraphs/stakewise-v2/configurations/configurations/configurations.ts @@ -0,0 +1,24 @@ +import { log } from "@graphprotocol/graph-ts"; + +import { Configurations } from "./interface"; +import { Deploy } from "./deploy"; +import { StakewiseV2EthereumConfigurations } from "../../protocols/stakewise-v2/config/deployments/stakewise-v2-ethereum/configurations"; +import { StakewiseV2GnosisConfigurations } from "../../protocols/stakewise-v2/config/deployments/stakewise-v2-gnosis/configurations"; + +export function getNetworkConfigurations(deploy: i32): Configurations { + switch (deploy) { + case Deploy.STAKEWISE_V2_ETHEREUM: { + return new StakewiseV2EthereumConfigurations(); + } + case Deploy.STAKEWISE_V2_GNOSIS: { + return new StakewiseV2GnosisConfigurations(); + } + default: { + log.critical( + "No configurations found for deployment protocol/network", + [] + ); + return new StakewiseV2EthereumConfigurations(); + } + } +} diff --git a/subgraphs/stakewise-v2/configurations/configurations/deploy.ts b/subgraphs/stakewise-v2/configurations/configurations/deploy.ts new file mode 100644 index 0000000000..71e4978681 --- /dev/null +++ b/subgraphs/stakewise-v2/configurations/configurations/deploy.ts @@ -0,0 +1,4 @@ +export namespace Deploy { + export const STAKEWISE_V2_ETHEREUM = 0; + export const STAKEWISE_V2_GNOSIS = 1; +} diff --git a/subgraphs/stakewise-v2/configurations/configurations/interface.ts b/subgraphs/stakewise-v2/configurations/configurations/interface.ts new file mode 100644 index 0000000000..42853be02d --- /dev/null +++ b/subgraphs/stakewise-v2/configurations/configurations/interface.ts @@ -0,0 +1,6 @@ +export interface Configurations { + getNetwork(): string; + getProtocolId(): string; + getProtocolName(): string; + getProtocolSlug(): string; +} diff --git a/subgraphs/stakewise-v2/configurations/configure.mustache b/subgraphs/stakewise-v2/configurations/configure.mustache new file mode 100644 index 0000000000..971ba89573 --- /dev/null +++ b/subgraphs/stakewise-v2/configurations/configure.mustache @@ -0,0 +1,6 @@ +import { getNetworkConfigurations } from "./configurations/configurations"; +import { Deploy } from "./configurations/deploy"; + +let deployment = Deploy.{{ deployment }}; + +export const NetworkConfigs = getNetworkConfigurations(deployment); diff --git a/subgraphs/stakewise-v2/package.json b/subgraphs/stakewise-v2/package.json new file mode 100644 index 0000000000..f55caf6ad7 --- /dev/null +++ b/subgraphs/stakewise-v2/package.json @@ -0,0 +1,15 @@ +{ + "name": "stakewise-v2", + "license": "MIT", + "scripts": { + "format": "npx prettier --write .", + "prepare:constants": "mustache protocols/${npm_config_protocol}/config/deployments/${npm_config_id}/configurations.json configurations/configure.mustache > configurations/configure.ts" + }, + "dependencies": { + "@graphprotocol/graph-cli": "^0.80.1", + "@graphprotocol/graph-ts": "^0.35.1" + }, + "devDependencies": { + "prettier": "^3.2.5" + } +} diff --git a/subgraphs/stakewise-v2/protocols/stakewise-v2/config/deployments/stakewise-v2-ethereum/configurations.json b/subgraphs/stakewise-v2/protocols/stakewise-v2/config/deployments/stakewise-v2-ethereum/configurations.json new file mode 100644 index 0000000000..4ba2e74ef5 --- /dev/null +++ b/subgraphs/stakewise-v2/protocols/stakewise-v2/config/deployments/stakewise-v2-ethereum/configurations.json @@ -0,0 +1,29 @@ +{ + "deployment": "STAKEWISE_V2_ETHEREUM", + "network": "mainnet", + "file": "./src/mappings/handlers.ts", + "RewardEthToken": { + "address": "0x20bc832ca081b91433ff6c17f85701b6e92486c5", + "startBlock": "11726341" + }, + "StakedEthToken": { + "address": "0xfe2e637202056d30016725477c5da089ab0a043a", + "startBlock": "11726304" + }, + "Solos": { + "address": "0xeadcba8bf9aca93f627f31fb05470f5a0686ceca", + "startBlock": "11726299" + }, + "VaultsRegistry": { + "address": "0x3a0008a588772446f6e656133c2d5029cc4fc20e", + "startBlock": "18470079" + }, + "OsTokenVaultController": { + "address": "0x2a261e60fb14586b474c208b1b7ac6d0f5000306", + "startBlock": "18470083" + }, + "onEthereum": true, + "graftEnabled": false, + "subgraphId": "", + "graftStartBlock": 0 +} diff --git a/subgraphs/stakewise-v2/protocols/stakewise-v2/config/deployments/stakewise-v2-ethereum/configurations.ts b/subgraphs/stakewise-v2/protocols/stakewise-v2/config/deployments/stakewise-v2-ethereum/configurations.ts new file mode 100644 index 0000000000..9e9da627e9 --- /dev/null +++ b/subgraphs/stakewise-v2/protocols/stakewise-v2/config/deployments/stakewise-v2-ethereum/configurations.ts @@ -0,0 +1,21 @@ +import { Configurations } from "../../../../../configurations/configurations/interface"; +import { + PROTOCOL_NAME, + PROTOCOL_SLUG, +} from "../../../../../src/common/constants"; +import { Network } from "../../../../../src/sdk/util/constants"; + +export class StakewiseV2EthereumConfigurations implements Configurations { + getNetwork(): string { + return Network.MAINNET; + } + getProtocolId(): string { + return "0xfe2e637202056d30016725477c5da089ab0a043a"; + } + getProtocolName(): string { + return PROTOCOL_NAME; + } + getProtocolSlug(): string { + return PROTOCOL_SLUG; + } +} diff --git a/subgraphs/stakewise-v2/protocols/stakewise-v2/config/deployments/stakewise-v2-gnosis/configurations.json b/subgraphs/stakewise-v2/protocols/stakewise-v2/config/deployments/stakewise-v2-gnosis/configurations.json new file mode 100644 index 0000000000..644d3c30c2 --- /dev/null +++ b/subgraphs/stakewise-v2/protocols/stakewise-v2/config/deployments/stakewise-v2-gnosis/configurations.json @@ -0,0 +1,13 @@ +{ + "deployment": "STAKEWISE_V2_GNOSIS", + "network": "gnosis", + "file": "./src/mappings/handlers-gnosis.ts", + "StakedGnoToken": { + "address": "0xa4ef9da5ba71cc0d2e5e877a910a37ec43420445", + "startBlock": "21275850" + }, + "onGnosis": true, + "graftEnabled": false, + "subgraphId": "", + "graftStartBlock": 0 +} diff --git a/subgraphs/stakewise-v2/protocols/stakewise-v2/config/deployments/stakewise-v2-gnosis/configurations.ts b/subgraphs/stakewise-v2/protocols/stakewise-v2/config/deployments/stakewise-v2-gnosis/configurations.ts new file mode 100644 index 0000000000..b9fff1e386 --- /dev/null +++ b/subgraphs/stakewise-v2/protocols/stakewise-v2/config/deployments/stakewise-v2-gnosis/configurations.ts @@ -0,0 +1,21 @@ +import { Configurations } from "../../../../../configurations/configurations/interface"; +import { + PROTOCOL_NAME, + PROTOCOL_SLUG, +} from "../../../../../src/common/constants"; +import { Network } from "../../../../../src/sdk/util/constants"; + +export class StakewiseV2GnosisConfigurations implements Configurations { + getNetwork(): string { + return Network.GNOSIS; + } + getProtocolId(): string { + return "0xa4ef9da5ba71cc0d2e5e877a910a37ec43420445"; + } + getProtocolName(): string { + return PROTOCOL_NAME; + } + getProtocolSlug(): string { + return PROTOCOL_SLUG; + } +} diff --git a/subgraphs/stakewise-v2/protocols/stakewise-v2/config/templates/stakewise-v2.template.yaml b/subgraphs/stakewise-v2/protocols/stakewise-v2/config/templates/stakewise-v2.template.yaml new file mode 100644 index 0000000000..07f16dc5d9 --- /dev/null +++ b/subgraphs/stakewise-v2/protocols/stakewise-v2/config/templates/stakewise-v2.template.yaml @@ -0,0 +1,344 @@ +specVersion: 0.0.8 +schema: + file: ./schema.graphql +{{#graftEnabled}} +features: + - grafting +graft: + base: {{ subgraphId }} # Subgraph ID of base subgraph + block: {{ graftStartBlock }} # Block number +{{/graftEnabled}} +dataSources: +{{#onEthereum}} + - kind: ethereum + name: RewardEthToken + network: {{ network }} + source: + address: "{{ RewardEthToken.address }}" + abi: RewardEthToken + startBlock: {{ RewardEthToken.startBlock }} + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + entities: + - Token + - Pool + - PoolDailySnapshot + - PoolHourlySnapshot + - Protocol + - FinancialsDailySnapshot + - UsageMetricsDailySnapshot + - UsageMetricsHourlySnapshot + abis: + - name: RewardEthToken + file: ./abis/Stakewise/RewardEthToken.json + - name: StakedEthToken + file: ./abis/Stakewise/StakedEthToken.json + - name: Solos + file: ./abis/Stakewise/Solos.json + - name: VaultsRegistry + file: ./abis/Stakewise/VaultsRegistry.json + - name: Vault + file: ./abis/Stakewise/Vault.json + - name: OsTokenVaultController + file: ./abis/Stakewise/OsTokenVaultController.json + + - name: ERC20 + file: ./abis/Tokens/ERC20.json + - name: _ERC20 + file: ./abis/Tokens/_ERC20.json + - name: ERC20SymbolBytes + file: ./abis/Tokens/ERC20SymbolBytes.json + - name: ERC20NameBytes + file: ./abis/Tokens/ERC20NameBytes.json + - name: ChainlinkDataFeed + file: ./abis/Tokens/ChainlinkDataFeed.json + eventHandlers: + - event: Transfer(indexed address,indexed address,uint256) + handler: handleTransferRewardEthToken + - event: RewardsUpdated(uint256,uint256,uint256,uint256,uint256) + handler: handleRewardsUpdated + file: {{{ file }}} + - kind: ethereum + name: StakedEthToken + network: {{ network }} + source: + address: "{{ StakedEthToken.address }}" + abi: StakedEthToken + startBlock: {{ StakedEthToken.startBlock }} + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + entities: + - Token + - Pool + - PoolDailySnapshot + - PoolHourlySnapshot + - Protocol + - FinancialsDailySnapshot + - UsageMetricsDailySnapshot + - UsageMetricsHourlySnapshot + abis: + - name: RewardEthToken + file: ./abis/Stakewise/RewardEthToken.json + - name: StakedEthToken + file: ./abis/Stakewise/StakedEthToken.json + - name: Solos + file: ./abis/Stakewise/Solos.json + - name: VaultsRegistry + file: ./abis/Stakewise/VaultsRegistry.json + - name: Vault + file: ./abis/Stakewise/Vault.json + - name: OsTokenVaultController + file: ./abis/Stakewise/OsTokenVaultController.json + + - name: ERC20 + file: ./abis/Tokens/ERC20.json + - name: _ERC20 + file: ./abis/Tokens/_ERC20.json + - name: ERC20SymbolBytes + file: ./abis/Tokens/ERC20SymbolBytes.json + - name: ERC20NameBytes + file: ./abis/Tokens/ERC20NameBytes.json + - name: ChainlinkDataFeed + file: ./abis/Tokens/ChainlinkDataFeed.json + eventHandlers: + - event: Transfer(indexed address,indexed address,uint256) + handler: handleTransferStakedEthToken + file: {{{ file }}} + - kind: ethereum + name: Solos + network: {{ network }} + source: + address: "{{ Solos.address }}" + abi: Solos + startBlock: {{ Solos.startBlock }} + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + entities: + - Token + - Pool + - PoolDailySnapshot + - PoolHourlySnapshot + - Protocol + - FinancialsDailySnapshot + - UsageMetricsDailySnapshot + - UsageMetricsHourlySnapshot + abis: + - name: RewardEthToken + file: ./abis/Stakewise/RewardEthToken.json + - name: StakedEthToken + file: ./abis/Stakewise/StakedEthToken.json + - name: Solos + file: ./abis/Stakewise/Solos.json + - name: VaultsRegistry + file: ./abis/Stakewise/VaultsRegistry.json + - name: Vault + file: ./abis/Stakewise/Vault.json + - name: OsTokenVaultController + file: ./abis/Stakewise/OsTokenVaultController.json + + - name: ERC20 + file: ./abis/Tokens/ERC20.json + - name: _ERC20 + file: ./abis/Tokens/_ERC20.json + - name: ERC20SymbolBytes + file: ./abis/Tokens/ERC20SymbolBytes.json + - name: ERC20NameBytes + file: ./abis/Tokens/ERC20NameBytes.json + - name: ChainlinkDataFeed + file: ./abis/Tokens/ChainlinkDataFeed.json + eventHandlers: + - event: ValidatorRegistered(indexed bytes32,bytes,uint256,address) + handler: handleValidatorRegistered + file: {{{ file }}} + - kind: ethereum + name: VaultsRegistry + network: {{ network }} + source: + address: "{{ VaultsRegistry.address }}" + abi: VaultsRegistry + startBlock: {{ VaultsRegistry.startBlock }} + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + entities: + - Token + - Pool + - PoolDailySnapshot + - PoolHourlySnapshot + - Protocol + - FinancialsDailySnapshot + - UsageMetricsDailySnapshot + - UsageMetricsHourlySnapshot + abis: + - name: RewardEthToken + file: ./abis/Stakewise/RewardEthToken.json + - name: StakedEthToken + file: ./abis/Stakewise/StakedEthToken.json + - name: Solos + file: ./abis/Stakewise/Solos.json + - name: VaultsRegistry + file: ./abis/Stakewise/VaultsRegistry.json + - name: Vault + file: ./abis/Stakewise/Vault.json + - name: OsTokenVaultController + file: ./abis/Stakewise/OsTokenVaultController.json + + - name: ERC20 + file: ./abis/Tokens/ERC20.json + - name: _ERC20 + file: ./abis/Tokens/_ERC20.json + - name: ERC20SymbolBytes + file: ./abis/Tokens/ERC20SymbolBytes.json + - name: ERC20NameBytes + file: ./abis/Tokens/ERC20NameBytes.json + - name: ChainlinkDataFeed + file: ./abis/Tokens/ChainlinkDataFeed.json + eventHandlers: + - event: VaultAdded(indexed address,indexed address) + handler: handleVaultAdded + file: {{{ file }}} + - kind: ethereum + name: OsTokenVaultController + network: {{ network }} + source: + address: "{{ OsTokenVaultController.address }}" + abi: OsTokenVaultController + startBlock: {{ OsTokenVaultController.startBlock }} + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + entities: + - Token + - Pool + - PoolDailySnapshot + - PoolHourlySnapshot + - Protocol + - FinancialsDailySnapshot + - UsageMetricsDailySnapshot + - UsageMetricsHourlySnapshot + abis: + - name: RewardEthToken + file: ./abis/Stakewise/RewardEthToken.json + - name: StakedEthToken + file: ./abis/Stakewise/StakedEthToken.json + - name: Solos + file: ./abis/Stakewise/Solos.json + - name: VaultsRegistry + file: ./abis/Stakewise/VaultsRegistry.json + - name: Vault + file: ./abis/Stakewise/Vault.json + - name: OsTokenVaultController + file: ./abis/Stakewise/OsTokenVaultController.json + + - name: ERC20 + file: ./abis/Tokens/ERC20.json + - name: _ERC20 + file: ./abis/Tokens/_ERC20.json + - name: ERC20SymbolBytes + file: ./abis/Tokens/ERC20SymbolBytes.json + - name: ERC20NameBytes + file: ./abis/Tokens/ERC20NameBytes.json + - name: ChainlinkDataFeed + file: ./abis/Tokens/ChainlinkDataFeed.json + eventHandlers: + - event: StateUpdated(uint256,uint256,uint256) + handler: handleStateUpdated + file: {{{ file }}} +templates: + - kind: ethereum + name: Vault + network: {{ network }} + source: + abi: Vault + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + entities: + - Token + - Pool + - PoolDailySnapshot + - PoolHourlySnapshot + - Protocol + - FinancialsDailySnapshot + - UsageMetricsDailySnapshot + - UsageMetricsHourlySnapshot + abis: + - name: RewardEthToken + file: ./abis/Stakewise/RewardEthToken.json + - name: StakedEthToken + file: ./abis/Stakewise/StakedEthToken.json + - name: Solos + file: ./abis/Stakewise/Solos.json + - name: VaultsRegistry + file: ./abis/Stakewise/VaultsRegistry.json + - name: Vault + file: ./abis/Stakewise/Vault.json + - name: OsTokenVaultController + file: ./abis/Stakewise/OsTokenVaultController.json + + - name: ERC20 + file: ./abis/Tokens/ERC20.json + - name: _ERC20 + file: ./abis/Tokens/_ERC20.json + - name: ERC20SymbolBytes + file: ./abis/Tokens/ERC20SymbolBytes.json + - name: ERC20NameBytes + file: ./abis/Tokens/ERC20NameBytes.json + - name: ChainlinkDataFeed + file: ./abis/Tokens/ChainlinkDataFeed.json + eventHandlers: + - event: Deposited(indexed address,indexed address,uint256,uint256,address) + handler: handleDeposited + - event: Redeemed(indexed address,indexed address,uint256,uint256) + handler: handleRedeemed + file: {{{ file }}} +{{/onEthereum}} +{{#onGnosis}} + - kind: ethereum + name: StakedGnoToken + network: {{ network }} + source: + address: "{{ StakedGnoToken.address }}" + abi: StakedGnoToken + startBlock: {{ StakedGnoToken.startBlock }} + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + entities: + - Token + - Pool + - PoolDailySnapshot + - PoolHourlySnapshot + - Protocol + - FinancialsDailySnapshot + - UsageMetricsDailySnapshot + - UsageMetricsHourlySnapshot + abis: + - name: StakedGnoToken + file: ./abis/Stakewise/StakedGnoToken.json + + - name: ERC20 + file: ./abis/Tokens/ERC20.json + - name: _ERC20 + file: ./abis/Tokens/_ERC20.json + - name: ERC20SymbolBytes + file: ./abis/Tokens/ERC20SymbolBytes.json + - name: ERC20NameBytes + file: ./abis/Tokens/ERC20NameBytes.json + - name: ChainlinkDataFeed + file: ./abis/Tokens/ChainlinkDataFeed.json + eventHandlers: + - event: Transfer(indexed address,indexed address,uint256) + handler: handleTransferStakedGnoToken + file: {{{ file }}} +{{/onGnosis}} \ No newline at end of file diff --git a/subgraphs/stakewise-v2/schema.graphql b/subgraphs/stakewise-v2/schema.graphql new file mode 100644 index 0000000000..f063900b3e --- /dev/null +++ b/subgraphs/stakewise-v2/schema.graphql @@ -0,0 +1,352 @@ +# Subgraph Schema: Generic +# Version: 3.0.0 +# See https://github.com/messari/subgraphs/blob/master/docs/SCHEMA.md for details + +enum Network { + ARBITRUM_ONE + ARWEAVE_MAINNET + AURORA + AVALANCHE + BOBA + BSC # aka BNB Chain + CELO + COSMOS + CRONOS + MAINNET # Ethereum Mainnet + FANTOM + FUSE + GNOSIS + HARMONY + JUNO + MOONBEAM + MOONRIVER + NEAR_MAINNET + OPTIMISM + OSMOSIS + MATIC # aka Polygon + GNOSIS +} + +enum ProtocolType { + EXCHANGE + LENDING + YIELD + BRIDGE + GENERIC + # Will add more +} + +enum TokenType { + MULTIPLE + UNKNOWN + ERC20 + ERC721 + ERC1155 + BEP20 + BEP721 + BEP1155 + # Will add more +} + +type Token @entity @regularPolling { + " Smart contract address of the token " + id: Bytes! + + " Name of the token, mirrored from the smart contract " + name: String! + + " Symbol of the token, mirrored from the smart contract " + symbol: String! + + " The number of decimal places this token uses, default to 18 " + decimals: Int! + + " Optional field to track the price of a token, mostly for caching purposes " + lastPriceUSD: BigDecimal + + " Optional field to track the block number of the last token price " + lastPriceBlockNumber: BigInt +} + +############################# +##### Protocol Metadata ##### +############################# + +type Protocol @entity @regularPolling { + " Smart contract address of the protocol's main contract (Factory, Registry, etc) " + id: Bytes! + + " Name of the protocol, including version. e.g. Uniswap v3 " + name: String! + + " Slug of protocol, including version. e.g. uniswap-v3 " + slug: String! + + " Version of the subgraph schema, in SemVer format (e.g. 1.0.0) " + schemaVersion: String! + + " Version of the subgraph implementation, in SemVer format (e.g. 1.0.0) " + subgraphVersion: String! + + " Version of the methodology used to compute metrics, loosely based on SemVer format (e.g. 1.0.0) " + methodologyVersion: String! + + " The blockchain network this subgraph is indexing on " + network: Network! + + " The type of protocol (e.g. DEX, Lending, Yield, etc) " + type: ProtocolType! + + ##### Quantitative Data ##### + + " Current TVL (Total Value Locked) of the entire protocol " + totalValueLockedUSD: BigDecimal! + + " Revenue claimed by suppliers to the protocol. LPs on DEXs (e.g. 0.25% of the swap fee in Sushiswap). Depositors on Lending Protocols. NFT sellers on OpenSea. " + cumulativeSupplySideRevenueUSD: BigDecimal! + + " Gross revenue for the protocol (revenue claimed by protocol). Examples: AMM protocol fee (Sushi’s 0.05%). OpenSea 10% sell fee. " + cumulativeProtocolSideRevenueUSD: BigDecimal! + + " All revenue generated by the protocol. e.g. 0.30% of swap fee in Sushiswap, all yield generated by Yearn. " + cumulativeTotalRevenueUSD: BigDecimal! + + " Total number of transactions. Transactions include events triggered by outside users (ie, deposit, withdraw, etc.)" + cumulativeTransactionCount: Int! + + " Number of cumulative unique users " + cumulativeUniqueUsers: Int! + + " Total number of pools " + totalPoolCount: Int! + + " Day ID of the most recent daily snapshot " + lastSnapshotDayID: Int! + + " Timestamp of the last time this entity was updated " + lastUpdateTimestamp: BigInt! + + ##### Snapshots ##### + + " Daily usage metrics for this protocol " + dailyUsageMetrics: [UsageMetricsDailySnapshot!]! + @derivedFrom(field: "protocol") + + " Daily financial metrics for this protocol " + financialMetrics: [FinancialsDailySnapshot!]! @derivedFrom(field: "protocol") + + ##### Pools ##### + + " All pools that belong to this protocol " + pools: [Pool!]! @derivedFrom(field: "protocol") +} + +############################### +##### Protocol Timeseries ##### +############################### + +type UsageMetricsDailySnapshot @entity @dailySnapshot { + " ID is # of days since Unix epoch time " + id: Bytes! + + " Number of days since Unix epoch time " + day: Int! + + " Protocol this snapshot is associated with " + protocol: Protocol! + + " Number of unique daily active users " + dailyActiveUsers: Int! + + " Number of cumulative unique users " + cumulativeUniqueUsers: Int! + + " Total number of transactions occurred in a day. Transactions include all entities that implement the Event interface. " + dailyTransactionCount: Int! + + " Total number of transactions. Transactions include events triggered by outside users (ie, deposit, withdraw, etc.)" + cumulativeTransactionCount: Int! + + " Total number of pools " + totalPoolCount: Int! + + " Timestamp of when this snapshot was taken/last modified (May be taken after interval has passed) " + timestamp: BigInt! + + " Block number of when this snapshot was taken/last modified (May be taken after interval has passed) " + blockNumber: BigInt! +} + +type FinancialsDailySnapshot @entity @dailySnapshot { + " ID is # of days since Unix epoch time " + id: Bytes! + + " Number of days since Unix epoch time " + day: Int! + + " Protocol this snapshot is associated with " + protocol: Protocol! + + " Current TVL (Total Value Locked) of the entire protocol " + totalValueLockedUSD: BigDecimal! + + " Revenue claimed by suppliers to the protocol. LPs on DEXs (e.g. 0.25% of the swap fee in Sushiswap). Depositors on Lending Protocols. NFT sellers on OpenSea. " + dailySupplySideRevenueUSD: BigDecimal! + + " Revenue claimed by suppliers to the protocol. LPs on DEXs (e.g. 0.25% of the swap fee in Sushiswap). Depositors on Lending Protocols. NFT sellers on OpenSea. " + cumulativeSupplySideRevenueUSD: BigDecimal! + + " Gross revenue for the protocol (revenue claimed by protocol). Examples: AMM protocol fee (Sushi’s 0.05%). OpenSea 10% sell fee. " + dailyProtocolSideRevenueUSD: BigDecimal! + + " Gross revenue for the protocol (revenue claimed by protocol). Examples: AMM protocol fee (Sushi’s 0.05%). OpenSea 10% sell fee. " + cumulativeProtocolSideRevenueUSD: BigDecimal! + + " All revenue generated by the protocol. e.g. 0.30% of swap fee in Sushiswap, all yield generated by Yearn. " + dailyTotalRevenueUSD: BigDecimal! + + " All revenue generated by the protocol. e.g. 0.30% of swap fee in Sushiswap, all yield generated by Yearn. " + cumulativeTotalRevenueUSD: BigDecimal! + + " Timestamp of when this snapshot was taken/last modified (May be taken after interval has passed) " + timestamp: BigInt! + + " Block number of when this snapshot was taken/last modified (May be taken after interval has passed) " + blockNumber: BigInt! +} + +########################### +##### Pool-Level Data ##### +########################### + +type Pool @entity @regularPolling { + " Smart contract address of the pool " + id: Bytes! + + " The protocol this pool belongs to " + protocol: Protocol! + + " Name of the pool (e.g. Curve.fi DAI/USDC/USDT) " + name: String + + " Symbol of liquidity pool (e.g. 3CRV) " + symbol: String + + # Generally protocols accept one or multiple tokens and mint tokens to the depositor to track ownership + # Some protocols don't mint any tokens to track ownership, in that case outputToken is null. + + " Token that is minted to track ownership of position in protocol " + outputToken: Token + + " Tokens that need to be deposited to take a position in protocol. e.g. WETH and USDC to deposit into the WETH-USDC pool. Array to account for multi-asset pools like Curve and Balancer " + inputTokens: [Token!]! + + " Creation timestamp " + createdTimestamp: BigInt! + + " Creation block number " + createdBlockNumber: BigInt! + + ##### Quantitative Data ##### + + " Current TVL (Total Value Locked) of this pool in USD " + totalValueLockedUSD: BigDecimal! + + " All revenue generated by the pool, accrued to the supply side. " + cumulativeSupplySideRevenue: BigInt! + cumulativeSupplySideRevenueUSD: BigDecimal! + + " All revenue generated by the pool, accrued to the protocol. " + cumulativeProtocolSideRevenue: BigInt! + cumulativeProtocolSideRevenueUSD: BigDecimal! + + " All revenue generated by the pool. " + cumulativeTotalRevenueUSD: BigDecimal! + + " Amount of input tokens in the pool. The ordering should be the same as the pool's `inputTokens` field. " + inputTokenBalances: [BigInt!]! + + " The USD value of input tokens in this pool. Should be the same order as the pool's `inputTokens` field. " + inputTokenBalancesUSD: [BigDecimal!]! + + " Total supply of output token. Note that certain DEXes don't have an output token (e.g. Bancor) " + outputTokenSupply: BigInt + + " Day ID of the most recent daily snapshot " + lastSnapshotDayID: Int! + + " Timestamp of the last time this entity was updated " + lastUpdateTimestamp: BigInt! +} + +type PoolDailySnapshot @entity @dailySnapshot { + " { Smart contract address of the pool }-{ # of days since Unix epoch time } " + id: Bytes! + + " Number of days since Unix epoch time " + day: Int! + + " The protocol this snapshot belongs to " + protocol: Protocol! + + " The pool this snapshot belongs to " + pool: Pool! + + ##### Quantitative Data ##### + + " Current TVL (Total Value Locked) of this pool " + totalValueLockedUSD: BigDecimal! + + " All revenue generated by the pool, accrued to the supply side. " + cumulativeSupplySideRevenueUSD: BigDecimal! + + " Daily revenue generated by the pool, accrued to the supply side. " + dailySupplySideRevenueUSD: BigDecimal! + + " All revenue generated by the pool, accrued to the protocol. " + cumulativeProtocolSideRevenueUSD: BigDecimal! + + " Daily revenue generated by the pool, accrued to the protocol. " + dailyProtocolSideRevenueUSD: BigDecimal! + + " All revenue generated by the pool. " + cumulativeTotalRevenueUSD: BigDecimal! + + " Daily revenue generated by the pool. " + dailyTotalRevenueUSD: BigDecimal! + + " Amount of input tokens in the pool. The ordering should be the same as the pool's `inputTokens` field. " + inputTokenBalances: [BigInt!]! + + " The USD value of input tokens in this pool. Should be the same order as the pool's `inputTokens` field. " + inputTokenBalancesUSD: [BigDecimal!]! + + " Total supply of output token. Note that certain DEXes don't have an output token (e.g. Bancor) " + outputTokenSupply: BigInt + + " Timestamp of when this snapshot was taken/last modified (May be taken after interval has passed) " + timestamp: BigInt! + + " Block number of when this snapshot was taken/last modified (May be taken after interval has passed) " + blockNumber: BigInt! +} + +# An account is a unique Ethereum address +# Helps to accumulate total unique users +type Account @entity @regularPolling { + " Address of the account " + id: ID! +} + +# Helper entity for calculating daily active users +type ActiveAccount @entity { + " { daily }-{ Address of the account }-{ Days since Unix epoch } " + id: ID! +} + +type _ActivityHelper @entity { + " { daily }-{ Days since Unix epoch} " + id: Bytes! + + dailyActiveUsers: Int! +} diff --git a/subgraphs/stakewise-v2/src/common/constants.ts b/subgraphs/stakewise-v2/src/common/constants.ts new file mode 100644 index 0000000000..d60635d4cc --- /dev/null +++ b/subgraphs/stakewise-v2/src/common/constants.ts @@ -0,0 +1,6 @@ +////////////////////////////// +///// Protocol Constants ///// +////////////////////////////// + +export const PROTOCOL_NAME = "Stakewise V2"; +export const PROTOCOL_SLUG = "stakewise-v2"; diff --git a/subgraphs/stakewise-v2/src/mappings/handlers-gnosis.ts b/subgraphs/stakewise-v2/src/mappings/handlers-gnosis.ts new file mode 100644 index 0000000000..a511ed07f5 --- /dev/null +++ b/subgraphs/stakewise-v2/src/mappings/handlers-gnosis.ts @@ -0,0 +1,99 @@ +import { Address, BigDecimal, BigInt } from "@graphprotocol/graph-ts"; + +import { Versions } from "../versions"; +import { NetworkConfigs } from "../../configurations/configure"; + +import { SDK } from "../sdk/protocols/generic"; +import { ProtocolConfig, TokenPricer } from "../sdk/protocols/config"; +import { TokenInitializer, TokenParams } from "../sdk/protocols/generic/tokens"; +import { bigIntToBigDecimal } from "../sdk/util/numbers"; +import { BIGDECIMAL_ZERO, INT_ZERO, ZERO_ADDRESS } from "../sdk/util/constants"; + +import { + Transfer as TransferStakedGnoToken, + StakedGnoToken, +} from "../../generated/StakedGnoToken/StakedGnoToken"; +import { _ERC20 } from "../../generated/StakedGnoToken/_ERC20"; +import { ChainlinkDataFeed } from "../../generated/StakedGnoToken/ChainlinkDataFeed"; +import { Token } from "../../generated/schema"; + +const conf = new ProtocolConfig( + NetworkConfigs.getProtocolId(), + NetworkConfigs.getProtocolName(), + NetworkConfigs.getProtocolSlug(), + Versions +); + +const GNO_ADDRESS = "0x9c58bacc331c9aa871afd802db6379a98e80cedb"; + +class Pricer implements TokenPricer { + getTokenPrice(token: Token): BigDecimal { + if (Address.fromBytes(token.id) == Address.fromString(GNO_ADDRESS)) { + const chainlinkDataFeedContract = ChainlinkDataFeed.bind( + Address.fromString("0x22441d81416430a54336ab28765abd31a792ad37") // GNO / USD feed + ); + const result = chainlinkDataFeedContract.latestAnswer(); + const decimals = chainlinkDataFeedContract.decimals(); + return bigIntToBigDecimal(result, decimals); + } + return BIGDECIMAL_ZERO; + } + + getAmountValueUSD(token: Token, amount: BigInt): BigDecimal { + const usdPrice = this.getTokenPrice(token); + const _amount = bigIntToBigDecimal(amount, token.decimals); + + return usdPrice.times(_amount); + } +} + +class TokenInit implements TokenInitializer { + getTokenParams(address: Address): TokenParams { + let name = "unknown"; + let symbol = "UNKNOWN"; + let decimals = INT_ZERO as i32; + + if (address == Address.fromString(GNO_ADDRESS)) { + name = "Gnosis Token on xDai"; + symbol = "GNO"; + decimals = 18 as i32; + } else { + const erc20 = _ERC20.bind(address); + name = erc20.name(); + symbol = erc20.symbol(); + decimals = erc20.decimals().toI32(); + } + return new TokenParams(name, symbol, decimals); + } +} + +export function handleTransferStakedGnoToken( + event: TransferStakedGnoToken +): void { + const sdk = SDK.initializeFromEvent( + conf, + new Pricer(), + new TokenInit(), + event + ); + const token = sdk.Tokens.getOrCreateToken(Address.fromString(GNO_ADDRESS)); + const pool = sdk.Pools.loadPool(event.address); + if (!pool.isInitialized) { + pool.initialize("Staked Gno Token", "sGNO", [token.id], null); + } + + const contract = StakedGnoToken.bind(event.address); + const supply = contract.totalSupply(); + pool.setInputTokenBalances([supply], true); + + if (event.params.from == Address.fromString(ZERO_ADDRESS)) { + const user = event.params.to; + const account = sdk.Accounts.loadAccount(user); + account.trackActivity(); + } + if (event.params.to == Address.fromString(ZERO_ADDRESS)) { + const user = event.params.from; + const account = sdk.Accounts.loadAccount(user); + account.trackActivity(); + } +} diff --git a/subgraphs/stakewise-v2/src/mappings/handlers.ts b/subgraphs/stakewise-v2/src/mappings/handlers.ts new file mode 100644 index 0000000000..c58dab023f --- /dev/null +++ b/subgraphs/stakewise-v2/src/mappings/handlers.ts @@ -0,0 +1,272 @@ +import { Address, BigDecimal, BigInt } from "@graphprotocol/graph-ts"; + +import { Versions } from "../versions"; +import { NetworkConfigs } from "../../configurations/configure"; + +import { SDK } from "../sdk/protocols/generic"; +import { ProtocolConfig, TokenPricer } from "../sdk/protocols/config"; +import { TokenInitializer, TokenParams } from "../sdk/protocols/generic/tokens"; +import { bigDecimalToBigInt, bigIntToBigDecimal } from "../sdk/util/numbers"; +import { + BIGDECIMAL_ZERO, + BIGINT_TEN_TO_EIGHTEENTH, + ETH_ADDRESS, + INT_ZERO, + ZERO_ADDRESS, +} from "../sdk/util/constants"; + +import { + Transfer as TransferRewardEthToken, + RewardEthToken, + RewardsUpdated, +} from "../../generated/RewardEthToken/RewardEthToken"; +import { + Transfer as TransferStakedEthToken, + StakedEthToken, +} from "../../generated/StakedEthToken/StakedEthToken"; +import { ValidatorRegistered } from "../../generated/Solos/Solos"; +import { VaultAdded } from "../../generated/VaultsRegistry/VaultsRegistry"; +import { Vault } from "../../generated/VaultsRegistry/Vault"; +import { StateUpdated } from "../../generated/OsTokenVaultController/OsTokenVaultController"; +import { Vault as VaultTemplate } from "../../generated/templates"; +import { Deposited, Redeemed } from "../../generated/VaultsRegistry/Vault"; +import { _ERC20 } from "../../generated/RewardEthToken/_ERC20"; +import { ChainlinkDataFeed } from "../../generated/RewardEthToken/ChainlinkDataFeed"; +import { Token } from "../../generated/schema"; + +const conf = new ProtocolConfig( + NetworkConfigs.getProtocolId(), + NetworkConfigs.getProtocolName(), + NetworkConfigs.getProtocolSlug(), + Versions +); + +class Pricer implements TokenPricer { + getTokenPrice(token: Token): BigDecimal { + if (Address.fromBytes(token.id) == Address.fromString(ETH_ADDRESS)) { + const chainlinkDataFeedContract = ChainlinkDataFeed.bind( + Address.fromString("0x5f4ec3df9cbd43714fe2740f5e3616155c5b8419") // ETH / USD feed + ); + const result = chainlinkDataFeedContract.latestAnswer(); + const decimals = chainlinkDataFeedContract.decimals(); + return bigIntToBigDecimal(result, decimals); + } + return BIGDECIMAL_ZERO; + } + + getAmountValueUSD(token: Token, amount: BigInt): BigDecimal { + const usdPrice = this.getTokenPrice(token); + const _amount = bigIntToBigDecimal(amount, token.decimals); + + return usdPrice.times(_amount); + } +} + +class TokenInit implements TokenInitializer { + getTokenParams(address: Address): TokenParams { + let name = "unknown"; + let symbol = "UNKNOWN"; + let decimals = INT_ZERO as i32; + + if (address == Address.fromString(ETH_ADDRESS)) { + name = "eth"; + symbol = "ETH"; + decimals = 18 as i32; + } else { + const erc20 = _ERC20.bind(address); + name = erc20.name(); + symbol = erc20.symbol(); + decimals = erc20.decimals().toI32(); + } + return new TokenParams(name, symbol, decimals); + } +} + +export function handleTransferRewardEthToken( + event: TransferRewardEthToken +): void { + const sdk = SDK.initializeFromEvent( + conf, + new Pricer(), + new TokenInit(), + event + ); + const token = sdk.Tokens.getOrCreateToken(Address.fromString(ETH_ADDRESS)); + const pool = sdk.Pools.loadPool(event.address); + if (!pool.isInitialized) { + pool.initialize("Reward Eth Token", "rETH2", [token.id], null); + } + + const contract = RewardEthToken.bind(event.address); + const supply = contract.totalSupply(); + pool.setInputTokenBalances([supply], true); + + if (event.params.from == Address.fromString(ZERO_ADDRESS)) { + const user = event.params.to; + const account = sdk.Accounts.loadAccount(user); + account.trackActivity(); + } + if (event.params.to == Address.fromString(ZERO_ADDRESS)) { + const user = event.params.from; + const account = sdk.Accounts.loadAccount(user); + account.trackActivity(); + } +} + +export function handleTransferStakedEthToken( + event: TransferStakedEthToken +): void { + const sdk = SDK.initializeFromEvent( + conf, + new Pricer(), + new TokenInit(), + event + ); + const token = sdk.Tokens.getOrCreateToken(Address.fromString(ETH_ADDRESS)); + const pool = sdk.Pools.loadPool(event.address); + if (!pool.isInitialized) { + pool.initialize("Staked Eth Token", "sETH2", [token.id], null); + } + + const contract = StakedEthToken.bind(event.address); + const supply = contract.totalSupply(); + pool.setInputTokenBalances([supply], true); + + if (event.params.from == Address.fromString(ZERO_ADDRESS)) { + const user = event.params.to; + const account = sdk.Accounts.loadAccount(user); + account.trackActivity(); + } + if (event.params.to == Address.fromString(ZERO_ADDRESS)) { + const user = event.params.from; + const account = sdk.Accounts.loadAccount(user); + account.trackActivity(); + } +} + +export function handleValidatorRegistered(event: ValidatorRegistered): void { + const sdk = SDK.initializeFromEvent( + conf, + new Pricer(), + new TokenInit(), + event + ); + const token = sdk.Tokens.getOrCreateToken(Address.fromString(ETH_ADDRESS)); + const pool = sdk.Pools.loadPool(event.address); + if (!pool.isInitialized) { + pool.initialize("Solos", "solo", [token.id], null); + } + + pool.addInputTokenBalances( + [BigInt.fromI32(32).times(BIGINT_TEN_TO_EIGHTEENTH)], + true + ); + + const user = event.transaction.from; + const account = sdk.Accounts.loadAccount(user); + account.trackActivity(); +} + +export function handleVaultAdded(event: VaultAdded): void { + VaultTemplate.create(event.params.vault); +} + +export function handleDeposited(event: Deposited): void { + const sdk = SDK.initializeFromEvent( + conf, + new Pricer(), + new TokenInit(), + event + ); + const token = sdk.Tokens.getOrCreateToken(Address.fromString(ETH_ADDRESS)); + const pool = sdk.Pools.loadPool(event.address); + if (!pool.isInitialized) { + pool.initialize( + event.address.toHexString(), + event.address.toHexString(), + [token.id], + null + ); + } + + const contract = Vault.bind(event.address); + const supply = contract.totalAssets(); + pool.setInputTokenBalances([supply], true); + + const user = event.transaction.from; + const account = sdk.Accounts.loadAccount(user); + account.trackActivity(); +} + +export function handleRedeemed(event: Redeemed): void { + const sdk = SDK.initializeFromEvent( + conf, + new Pricer(), + new TokenInit(), + event + ); + const token = sdk.Tokens.getOrCreateToken(Address.fromString(ETH_ADDRESS)); + const pool = sdk.Pools.loadPool(event.address); + if (!pool.isInitialized) { + pool.initialize( + event.address.toHexString(), + event.address.toHexString(), + [token.id], + null + ); + } + + const contract = Vault.bind(event.address); + const supply = contract.totalAssets(); + pool.setInputTokenBalances([supply], true); + + const user = event.transaction.from; + const account = sdk.Accounts.loadAccount(user); + account.trackActivity(); +} + +export function handleRewardsUpdated(event: RewardsUpdated): void { + const sdk = SDK.initializeFromEvent( + conf, + new Pricer(), + new TokenInit(), + event + ); + const token = sdk.Tokens.getOrCreateToken(Address.fromString(ETH_ADDRESS)); + const pool = sdk.Pools.loadPool(event.address); + if (!pool.isInitialized) { + pool.initialize("Reward Eth Token", "rETH2", [token.id], null); + } + + const amount = event.params.periodRewards; + const fees = amount.toBigDecimal().times(BigDecimal.fromString("0.05")); + const rewards = amount.toBigDecimal().minus(fees); + pool.addRevenueNative( + token, + bigDecimalToBigInt(rewards), + bigDecimalToBigInt(fees) + ); +} + +export function handleStateUpdated(event: StateUpdated): void { + const sdk = SDK.initializeFromEvent( + conf, + new Pricer(), + new TokenInit(), + event + ); + const token = sdk.Tokens.getOrCreateToken(Address.fromString(ETH_ADDRESS)); + const pool = sdk.Pools.loadPool(event.address); + if (!pool.isInitialized) { + pool.initialize("OsToken Rewards", "OsToken", [token.id], null); + } + + const amount = event.params.profitAccrued; + const fees = amount.toBigDecimal().times(BigDecimal.fromString("0.1")); + const rewards = amount.toBigDecimal().minus(fees); + pool.addRevenueNative( + token, + bigDecimalToBigInt(rewards), + bigDecimalToBigInt(fees) + ); +} diff --git a/subgraphs/stakewise-v2/src/sdk/README.md b/subgraphs/stakewise-v2/src/sdk/README.md new file mode 100644 index 0000000000..c8e3bddd41 --- /dev/null +++ b/subgraphs/stakewise-v2/src/sdk/README.md @@ -0,0 +1,25 @@ +## Wat dis? + +This folder contains a library which abstracts the developer from most of the _schema related_ functionality. Ideally, building a subgraph should only consist on understading a protocol and translating certain events into actions and metrics. But the particularities of how this metrics are stored and how they relate to each other inside the schema can and should be abstracted away. Things like taking snapshots of entities every X amount of time, updating TVL every time there is a deposit/withdrawal, updating fees at _swap & pool & protocol & snapshot levels_, etc ... This library aims to do that. + +When using this library, entities should not be updated directly, but always through the library unless absolutely needed. An exception to this is if you create your own auxiliary entity to aid on the handling of some events. + +## How It's Organized + +Pretty straightforward, `/protocols` and `/util`. + +Because we are currently experimenting different approaches, each protocol type has a different schema, and AssemblyScript has some limitations when dealing with interfaces, so far, each protocol type has its own implementation. They all live in their respective folders under `/protocols`, and have very little shared code. + +`/util` contains all these common functions and constants we use over and over. + +## Setting it up + +It would be ideal to have the library to get setup automatically with the messari-cli, in a similar way as we do to generate versions. We might eventually get there, but so far it consists on a manual copy process. + +Refer to each protocol type readme, since requirements might vary: + +- [Bridges](./protocols/bridge/README.md) +- [Lending](./protocols/lending/README.md) +- [Perpetual Futures](./protocols/perpfutures/README.md) +- DEX +- Yield diff --git a/subgraphs/stakewise-v2/src/sdk/protocols/config.ts b/subgraphs/stakewise-v2/src/sdk/protocols/config.ts new file mode 100644 index 0000000000..f75004e165 --- /dev/null +++ b/subgraphs/stakewise-v2/src/sdk/protocols/config.ts @@ -0,0 +1,45 @@ +import { BigDecimal, BigInt } from "@graphprotocol/graph-ts"; +import { Token } from "../../../generated/schema"; +import { Versions } from "../../../../../deployment/context/interface"; + +export interface ProtocolConfigurer { + getID(): string; + getName(): string; + getSlug(): string; + getVersions(): Versions; +} + +export class ProtocolConfig implements ProtocolConfigurer { + id: string; + name: string; + slug: string; + versions: Versions; + + constructor(id: string, name: string, slug: string, versions: Versions) { + this.id = id; + this.name = name; + this.slug = slug; + this.versions = versions; + } + + getID(): string { + return this.id; + } + + getName(): string { + return this.name; + } + + getSlug(): string { + return this.slug; + } + + getVersions(): Versions { + return this.versions; + } +} + +export interface TokenPricer { + getTokenPrice(token: Token): BigDecimal; + getAmountValueUSD(token: Token, amount: BigInt): BigDecimal; +} diff --git a/subgraphs/stakewise-v2/src/sdk/protocols/generic/account.ts b/subgraphs/stakewise-v2/src/sdk/protocols/generic/account.ts new file mode 100644 index 0000000000..b962ef2360 --- /dev/null +++ b/subgraphs/stakewise-v2/src/sdk/protocols/generic/account.ts @@ -0,0 +1,93 @@ +import { + ActiveAccount, + Account as AccountSchema, +} from "../../../../generated/schema"; +import { TokenManager } from "./tokens"; +import { ProtocolManager } from "./protocol"; +import { Address } from "@graphprotocol/graph-ts"; +import { CustomEventType, getUnixDays, getUnixHours } from "../../util/events"; + +/** + * This file contains the AccountClass, which does + * the operations on the Account entity. This includes: + * - Creating a new Account + * - Updating an existing Account + * + * Schema Version: 3.0.0 + * SDK Version: 1.1.0 + * Author(s): + * - @steegecs + * - @shashwatS22 + */ + +export class AccountManager { + protocol: ProtocolManager; + tokens: TokenManager; + + constructor(protocol: ProtocolManager, tokens: TokenManager) { + this.protocol = protocol; + this.tokens = tokens; + } + + loadAccount(address: Address): Account { + let acc = AccountSchema.load(address.toHexString()); + if (acc) { + return new Account(this.protocol, acc, this.tokens); + } + + acc = new AccountSchema(address.toHexString()); + acc.save(); + + this.protocol.addUser(); + + return new Account(this.protocol, acc, this.tokens); + } +} + +export class AccountWasActive { + hourly: boolean; + daily: boolean; +} + +export class Account { + account: AccountSchema; + event: CustomEventType; + protocol: ProtocolManager; + tokens: TokenManager; + + constructor( + protocol: ProtocolManager, + account: AccountSchema, + tokens: TokenManager + ) { + this.account = account; + this.protocol = protocol; + this.event = protocol.getCurrentEvent(); + this.tokens = tokens; + } + + trackActivity(): void { + const days = getUnixDays(this.event.block); + const hours = getUnixHours(this.event.block); + + const generalHourlyID = `${this.account.id}-hourly-${hours}`; + const generalDailyID = `${this.account.id}-daily-${days}`; + + const generalActivity: AccountWasActive = { + daily: this.isActiveByActivityID(generalDailyID), + hourly: this.isActiveByActivityID(generalHourlyID), + }; + + this.protocol.addActiveUser(generalActivity); + this.protocol.addTransaction(); + } + + private isActiveByActivityID(id: string): boolean { + const dAct = ActiveAccount.load(id); + if (!dAct) { + new ActiveAccount(id).save(); + return true; + } + return false; + } +} diff --git a/subgraphs/stakewise-v2/src/sdk/protocols/generic/index.ts b/subgraphs/stakewise-v2/src/sdk/protocols/generic/index.ts new file mode 100644 index 0000000000..59f201e67f --- /dev/null +++ b/subgraphs/stakewise-v2/src/sdk/protocols/generic/index.ts @@ -0,0 +1,72 @@ +import { PoolManager } from "./pool"; +import { AccountManager } from "./account"; +import { ProtocolManager } from "./protocol"; +import { BIGINT_ZERO } from "../../util/constants"; +import { ethereum } from "@graphprotocol/graph-ts"; +import { CustomEventType } from "../../util/events"; +import { TokenManager, TokenInitializer } from "./tokens"; +import { ProtocolConfigurer, TokenPricer } from "../config"; + +/** + * This file contains the SDK class, which initializes + * all managers from event or call. + * + * Schema Version: 3.0.0 + * SDK Version: 1.1.0 + * Author(s): + * - @steegecs + * - @shashwatS22 + + */ + +export class SDK { + Protocol: ProtocolManager; + Accounts: AccountManager; + Pools: PoolManager; + Tokens: TokenManager; + Pricer: TokenPricer; + + constructor( + config: ProtocolConfigurer, + pricer: TokenPricer, + tokenInitializer: TokenInitializer, + event: CustomEventType + ) { + this.Protocol = ProtocolManager.load(config, pricer, event); + this.Tokens = new TokenManager(this.Protocol, tokenInitializer); + this.Accounts = new AccountManager(this.Protocol, this.Tokens); + this.Pools = new PoolManager(this.Protocol, this.Tokens); + this.Pricer = pricer; + + this.Protocol.sdk = this; + } + + static initializeFromEvent( + config: ProtocolConfigurer, + pricer: TokenPricer, + tokenInitializer: TokenInitializer, + event: ethereum.Event + ): SDK { + const customEvent = CustomEventType.initialize( + event.block, + event.transaction, + event.logIndex, + event + ); + return new SDK(config, pricer, tokenInitializer, customEvent); + } + + static initializeFromCall( + config: ProtocolConfigurer, + pricer: TokenPricer, + tokenInitializer: TokenInitializer, + event: ethereum.Call + ): SDK { + const customEvent = CustomEventType.initialize( + event.block, + event.transaction, + BIGINT_ZERO + ); + return new SDK(config, pricer, tokenInitializer, customEvent); + } +} diff --git a/subgraphs/stakewise-v2/src/sdk/protocols/generic/pool.ts b/subgraphs/stakewise-v2/src/sdk/protocols/generic/pool.ts new file mode 100644 index 0000000000..007e801ea5 --- /dev/null +++ b/subgraphs/stakewise-v2/src/sdk/protocols/generic/pool.ts @@ -0,0 +1,339 @@ +import { TokenManager } from "./tokens"; +import { ProtocolManager } from "./protocol"; +import { PoolSnapshot } from "./poolSnapshot"; +import { BIGDECIMAL_ZERO, BIGINT_ZERO } from "../../util/constants"; +import { Pool as PoolSchema, Token } from "../../../../generated/schema"; +import { Bytes, BigDecimal, BigInt, Address } from "@graphprotocol/graph-ts"; + +/** + * This file contains the PoolManager, which is used to + * initialize new pools in the protocol. + * + * Schema Version: 3.0.0 + * SDK Version: 1.1.0 + * Author(s): + * - @steegecs + * - @shashwatS22 + */ + +export class PoolManager { + protocol: ProtocolManager; + tokens: TokenManager; + + constructor(protocol: ProtocolManager, tokens: TokenManager) { + this.protocol = protocol; + this.tokens = tokens; + } + + loadPool(id: Bytes): Pool { + let entity = PoolSchema.load(id); + if (entity) { + return new Pool(this.protocol, entity, this.tokens, true); + } + + entity = new PoolSchema(id); + entity.protocol = this.protocol.getBytesID(); + + const pool = new Pool(this.protocol, entity, this.tokens, false); + pool.isInitialized = false; + return pool; + } +} + +export class Pool { + pool: PoolSchema; + protocol: ProtocolManager; + tokens: TokenManager; + snapshoter: PoolSnapshot | null = null; + + public isInitialized: boolean = true; + + constructor( + protocol: ProtocolManager, + pool: PoolSchema, + tokens: TokenManager, + isInitialized: bool + ) { + this.pool = pool; + this.protocol = protocol; + this.tokens = tokens; + + if (isInitialized) { + this.snapshoter = new PoolSnapshot(pool, protocol.event); + this.pool.lastUpdateTimestamp = protocol.event.block.timestamp; + this.save(); + } + } + + private save(): void { + this.pool.save(); + } + + initialize( + name: string, + symbol: string, + inputTokens: Bytes[], + outputToken: Token | null + ): void { + if (this.isInitialized) { + return; + } + + const event = this.protocol.getCurrentEvent(); + this.pool.protocol = this.protocol.getBytesID(); + this.pool.name = name; + this.pool.symbol = symbol; + this.pool.inputTokens = inputTokens; + this.pool.outputToken = outputToken ? outputToken.id : null; + this.pool.createdTimestamp = event.block.timestamp; + this.pool.createdBlockNumber = event.block.number; + + const inputTokenBalances: BigInt[] = []; + const inputTokenBalancesUSD: BigDecimal[] = []; + for (let i = 0; i < inputTokens.length; i++) { + inputTokenBalances.push(BIGINT_ZERO); + inputTokenBalancesUSD.push(BIGDECIMAL_ZERO); + } + this.pool.inputTokenBalances = inputTokenBalances; + this.pool.inputTokenBalancesUSD = inputTokenBalancesUSD; + this.pool.totalValueLockedUSD = BIGDECIMAL_ZERO; + this.pool.cumulativeSupplySideRevenue = BIGINT_ZERO; + this.pool.cumulativeSupplySideRevenueUSD = BIGDECIMAL_ZERO; + this.pool.cumulativeProtocolSideRevenue = BIGINT_ZERO; + this.pool.cumulativeProtocolSideRevenueUSD = BIGDECIMAL_ZERO; + this.pool.cumulativeTotalRevenueUSD = BIGDECIMAL_ZERO; + + this.pool.lastSnapshotDayID = 0; + this.pool.lastUpdateTimestamp = BIGINT_ZERO; + this.save(); + + this.protocol.addPool(); + } + + /** + * Recalculates the total value locked for this pool based on its current input token balance. + * This function will also update the protocol's total value locked based on the change in this pool's. + */ + private refreshTotalValueLocked(): void { + let totalValueLockedUSD = BIGDECIMAL_ZERO; + + for (let idx = 0; idx < this.pool.inputTokens.length; idx++) { + const inputTokenBalanceUSD = this.pool.inputTokenBalancesUSD[idx]; + totalValueLockedUSD = totalValueLockedUSD.plus(inputTokenBalanceUSD); + } + + this.setTotalValueLocked(totalValueLockedUSD); + } + + /** + * Updates the total value locked for this pool to the given value. + * Will also update the protocol's total value locked based on the change in this pool's. + */ + setTotalValueLocked(newTVL: BigDecimal): void { + const delta = newTVL.minus(this.pool.totalValueLockedUSD); + this.addTotalValueLocked(delta); + this.save(); + } + + /** + * Adds the given delta to the total value locked for this pool. + * Will also update the protocol's total value locked based on the change in this pool's. + * + * @param delta The change in total value locked for this pool. + */ + addTotalValueLocked(delta: BigDecimal): void { + this.pool.totalValueLockedUSD = this.pool.totalValueLockedUSD.plus(delta); + this.protocol.addTotalValueLocked(delta); + this.save(); + } + + /** + * Utility function to update token price. + * + * @param token + * @returns + */ + setTokenPrice(token: Token): void { + if ( + !token.lastPriceBlockNumber || + (token.lastPriceBlockNumber && + token.lastPriceBlockNumber! < this.protocol.event.block.number) + ) { + const pricePerToken = this.protocol.getTokenPricer().getTokenPrice(token); + token.lastPriceUSD = pricePerToken; + token.lastPriceBlockNumber = this.protocol.event.block.number; + token.save(); + } + } + + /** + * Utility function to convert some amount of input token to USD. + * + * @param token + * @param amount the amount of inputToken to convert to USD + * @returns The converted amount. + */ + getInputTokenAmountPrice(token: Token, amount: BigInt): BigDecimal { + this.setTokenPrice(token); + + return this.protocol.getTokenPricer().getAmountValueUSD(token, amount); + } + + addInputTokenBalances( + amounts: BigInt[], + updateMetrics: boolean = true + ): void { + if (amounts.length != this.pool.inputTokenBalances.length) return; + + const newBalances: BigInt[] = []; + for (let idx = 0; idx < this.pool.inputTokenBalances.length; idx++) { + newBalances[idx] = this.pool.inputTokenBalances[idx].plus(amounts[idx]); + } + this.setInputTokenBalances(newBalances, updateMetrics); + } + + /** + * Sets the pool's input token balance to the given amount. It will optionally + * update the pool's and protocol's total value locked. If not stated, will default to true. + * + * @param amount amount to be set as the pool's input token balance. + * @param updateMetrics optional parameter to indicate whether to update the pool's and protocol's total value locked. + */ + setInputTokenBalances( + newBalances: BigInt[], + updateMetrics: boolean = true + ): void { + this.pool.inputTokenBalances = newBalances; + this.setInputTokenBalancesUSD(); + if (updateMetrics) { + this.refreshTotalValueLocked(); + } + } + + /** + * Sets the pool's input token balance USD by calculating it for each token. + */ + private setInputTokenBalancesUSD(): void { + const inputTokenBalancesUSD: BigDecimal[] = []; + for (let idx = 0; idx < this.pool.inputTokens.length; idx++) { + const inputTokenBalance = this.pool.inputTokenBalances[idx]; + const inputToken = this.tokens.getOrCreateToken( + Address.fromBytes(this.pool.inputTokens[idx]) + ); + + const amountUSD = this.getInputTokenAmountPrice( + inputToken, + inputTokenBalance + ); + inputTokenBalancesUSD.push(amountUSD); + } + this.pool.inputTokenBalancesUSD = inputTokenBalancesUSD; + } + + getBytesID(): Bytes { + return this.pool.id; + } + + /** + * Adds a given USD value to the pool and protocol supplySideRevenue. It can be a positive or negative amount. + * Same as for the rest of setters, this is mostly to be called internally by the library. + * But you can use it if you need to. It will also update the protocol's snapshots. + * @param rev {BigDecimal} The value to add to the protocol's supplySideRevenue. + */ + addSupplySideRevenueUSD(rev: BigDecimal): void { + this.pool.cumulativeTotalRevenueUSD = + this.pool.cumulativeTotalRevenueUSD.plus(rev); + this.pool.cumulativeSupplySideRevenueUSD = + this.pool.cumulativeSupplySideRevenueUSD.plus(rev); + this.save(); + + this.protocol.addSupplySideRevenueUSD(rev); + } + + /** + * Adds a given USD value to the pool and protocol protocolSideRevenue. It can be a positive or negative amount. + * Same as for the rest of setters, this is mostly to be called internally by the library. + * But you can use it if you need to. It will also update the protocol's snapshots. + * @param rev {BigDecimal} The value to add to the protocol's protocolSideRevenue. + */ + addProtocolSideRevenueUSD(rev: BigDecimal): void { + this.pool.cumulativeTotalRevenueUSD = + this.pool.cumulativeTotalRevenueUSD.plus(rev); + this.pool.cumulativeProtocolSideRevenueUSD = + this.pool.cumulativeProtocolSideRevenueUSD.plus(rev); + this.save(); + + this.protocol.addProtocolSideRevenueUSD(rev); + } + + /** + * Adds a given USD value to the pool and protocol's supplySideRevenue and protocolSideRevenue. It can be a positive or negative amount. + * Same as for the rest of setters, this is mostly to be called internally by the library. + * But you can use it if you need to. It will also update the protocol's snapshots. + * @param protocolSide {BigDecimal} The value to add to the protocol's protocolSideRevenue. + * @param supplySide {BigDecimal} The value to add to the protocol's supplySideRevenue. + */ + addRevenueUSD(protocolSide: BigDecimal, supplySide: BigDecimal): void { + this.addSupplySideRevenueUSD(supplySide); + this.addProtocolSideRevenueUSD(protocolSide); + } + + /** + * Convenience method to add revenue denominated in the pool's input token. It converts it to USD + * under the hood and calls addRevenueUSD. + */ + addRevenueNative( + inputToken: Token, + supplySide: BigInt, + protocolSide: BigInt + ): void { + const pricer = this.protocol.pricer; + + const pAmountUSD = pricer.getAmountValueUSD(inputToken, protocolSide); + const sAmountUSD = pricer.getAmountValueUSD(inputToken, supplySide); + + this.pool.cumulativeProtocolSideRevenue = + this.pool.cumulativeProtocolSideRevenue.plus(protocolSide); + this.pool.cumulativeSupplySideRevenue = + this.pool.cumulativeSupplySideRevenue.plus(supplySide); + + this.addRevenueUSD(pAmountUSD, sAmountUSD); + } + + getRevenueUSD(): BigDecimal[] { + return [ + this.pool.cumulativeProtocolSideRevenueUSD, + this.pool.cumulativeSupplySideRevenueUSD, + ]; + } + + getRevenue(): BigInt[] { + return [ + this.pool.cumulativeProtocolSideRevenue, + this.pool.cumulativeSupplySideRevenue, + ]; + } + + /** + * Adds a given amount to the pool's outputTokenSupply. It should only be used for pools + * of type LIQUIDITY. Or pools that emit some kind of LP token on deposit. + * @param amount + */ + addOutputTokenSupply(amount: BigInt): void { + if (!this.pool.outputTokenSupply) { + this.pool.outputTokenSupply = BIGINT_ZERO; + } + this.pool.outputTokenSupply = this.pool.outputTokenSupply!.plus(amount); + this.save(); + } + + /** + * Sets the pool's outputTokenSupply value. It should only be used for pools + * of type LIQUIDITY. Or pools that emit some kind of LP token on deposit. + * @param amount + */ + setOutputTokenSupply(amount: BigInt): void { + this.pool.outputTokenSupply = amount; + this.save(); + } +} diff --git a/subgraphs/stakewise-v2/src/sdk/protocols/generic/poolSnapshot.ts b/subgraphs/stakewise-v2/src/sdk/protocols/generic/poolSnapshot.ts new file mode 100644 index 0000000000..c7945dbb64 --- /dev/null +++ b/subgraphs/stakewise-v2/src/sdk/protocols/generic/poolSnapshot.ts @@ -0,0 +1,93 @@ +import { + Pool as PoolSchema, + PoolDailySnapshot, +} from "../../../../generated/schema"; +import { SECONDS_PER_DAY } from "../../util/constants"; +import { CustomEventType, getUnixDays, getUnixHours } from "../../util/events"; + +/** + * This file contains the PoolSnapshot, which is used to + * make all of the storage changes that occur in the pool daily and hourly snapshots. + * + * Schema Version: 3.0.0 + * SDK Version: 1.1.0 + * Author(s): + * - @steegecs + * - @shashwatS22 + */ + +export class PoolSnapshot { + pool: PoolSchema; + event: CustomEventType; + dayID: i32; + hourID: i32; + + constructor(pool: PoolSchema, event: CustomEventType) { + this.pool = pool; + this.event = event; + this.dayID = getUnixDays(event.block); + this.hourID = getUnixHours(event.block); + this.takeSnapshots(); + } + + private takeSnapshots(): void { + if (!this.pool.lastUpdateTimestamp) return; + + const snapshotDayID = + this.pool.lastUpdateTimestamp.toI32() / SECONDS_PER_DAY; + + if (snapshotDayID != this.dayID) { + this.takeDailySnapshot(snapshotDayID); + this.pool.lastSnapshotDayID = snapshotDayID; + this.pool.save(); + } + } + + private takeDailySnapshot(day: i32): void { + const snapshot = new PoolDailySnapshot(this.pool.id.concatI32(day)); + const previousSnapshot = PoolDailySnapshot.load( + this.pool.id.concatI32(this.pool.lastSnapshotDayID) + ); + + snapshot.day = day; + snapshot.protocol = this.pool.protocol; + snapshot.pool = this.pool.id; + snapshot.timestamp = this.event.block.timestamp; + snapshot.blockNumber = this.event.block.number; + + // tvl and balances + snapshot.totalValueLockedUSD = this.pool.totalValueLockedUSD; + snapshot.inputTokenBalances = this.pool.inputTokenBalances; + snapshot.inputTokenBalancesUSD = this.pool.inputTokenBalancesUSD; + + // revenues + snapshot.cumulativeSupplySideRevenueUSD = + this.pool.cumulativeSupplySideRevenueUSD; + snapshot.cumulativeProtocolSideRevenueUSD = + this.pool.cumulativeProtocolSideRevenueUSD; + snapshot.cumulativeTotalRevenueUSD = this.pool.cumulativeTotalRevenueUSD; + + // deltas + let supplySideRevenueDelta = snapshot.cumulativeSupplySideRevenueUSD; + let protocolSideRevenueDelta = snapshot.cumulativeProtocolSideRevenueUSD; + let totalRevenueDelta = snapshot.cumulativeTotalRevenueUSD; + + if (previousSnapshot) { + supplySideRevenueDelta = snapshot.cumulativeSupplySideRevenueUSD.minus( + previousSnapshot.cumulativeSupplySideRevenueUSD + ); + protocolSideRevenueDelta = + snapshot.cumulativeProtocolSideRevenueUSD.minus( + previousSnapshot.cumulativeProtocolSideRevenueUSD + ); + totalRevenueDelta = snapshot.cumulativeTotalRevenueUSD.minus( + previousSnapshot.cumulativeTotalRevenueUSD + ); + } + snapshot.dailySupplySideRevenueUSD = supplySideRevenueDelta; + snapshot.dailyProtocolSideRevenueUSD = protocolSideRevenueDelta; + snapshot.dailyTotalRevenueUSD = totalRevenueDelta; + + snapshot.save(); + } +} diff --git a/subgraphs/stakewise-v2/src/sdk/protocols/generic/protocol.ts b/subgraphs/stakewise-v2/src/sdk/protocols/generic/protocol.ts new file mode 100644 index 0000000000..c09aac2905 --- /dev/null +++ b/subgraphs/stakewise-v2/src/sdk/protocols/generic/protocol.ts @@ -0,0 +1,257 @@ +import { SDK } from "."; +import { + dataSource, + Address, + Bytes, + BigDecimal, +} from "@graphprotocol/graph-ts"; +import { AccountWasActive } from "./account"; +import * as constants from "../../util/constants"; +import { BIGINT_ZERO } from "../../util/constants"; +import { CustomEventType } from "../../util/events"; +import { ProtocolSnapshot } from "./protocolSnapshot"; +import { ProtocolConfigurer, TokenPricer } from "../config"; +import { Protocol as ProtocolSchema } from "../../../../generated/schema"; +import { Versions } from "../../../../../../deployment/context/interface"; + +/** + * This file contains the ProtocolManager class, which is used to + * make all of the storage changes that occur in a protocol. + * + * Schema Version: 3.0.0 + * SDK Version: 1.1.0 + * Author(s): + * - @steegecs + * - @shashwatS22 + */ + +/** + * ProtocolManager is a wrapper around the ProtocolSchema entity that takes care of + * safely and conveniently updating the entity. Updating the Protocol entity using this + * wrapper also takes care of the Financials and Usage snapshots. + */ +export class ProtocolManager { + protocol: ProtocolSchema; + event: CustomEventType; + pricer: TokenPricer; + snapshoter: ProtocolSnapshot; + sdk: SDK | null = null; + /** + * Creates a new Protocol instance. This should only be called by the Protocol.load + * @private + */ + private constructor( + protocol: ProtocolSchema, + pricer: TokenPricer, + event: CustomEventType + ) { + this.protocol = protocol; + this.event = event; + this.pricer = pricer; + this.snapshoter = new ProtocolSnapshot(protocol, event); + this.protocol.lastUpdateTimestamp = event.block.timestamp; + } + + /** + * This is the main function to instantiate a Protocol entity. Most times it is not called directly, but from the SDK initializer. + * + * @param conf {ProtocolConfigurer} An object that implements the ProtocolConfigurer interface, to set some of the protocol's properties + * @param pricer {TokenPricer} An object that implements the TokenPricer interface, to allow the wrapper to access pricing data + * @param event {CustomEventType} The event being handled at a time. + * @returns Protocol + */ + static load( + conf: ProtocolConfigurer, + pricer: TokenPricer, + event: CustomEventType + ): ProtocolManager { + const id = Address.fromString(conf.getID()); + let protocol = ProtocolSchema.load(id); + if (protocol) { + const proto = new ProtocolManager(protocol, pricer, event); + proto.setVersions(conf.getVersions()); + return proto; + } + + protocol = new ProtocolSchema(id); + protocol.name = conf.getName(); + protocol.slug = conf.getSlug(); + protocol.network = dataSource.network().toUpperCase().replace("-", "_"); + protocol.type = constants.ProtocolType.GENERIC; + protocol.totalValueLockedUSD = constants.BIGDECIMAL_ZERO; + protocol.cumulativeSupplySideRevenueUSD = constants.BIGDECIMAL_ZERO; + protocol.cumulativeProtocolSideRevenueUSD = constants.BIGDECIMAL_ZERO; + protocol.cumulativeTotalRevenueUSD = constants.BIGDECIMAL_ZERO; + + protocol.cumulativeTransactionCount = 0; + protocol.cumulativeUniqueUsers = 0; + protocol.totalPoolCount = 0; + + protocol.lastSnapshotDayID = 0; + protocol.lastUpdateTimestamp = BIGINT_ZERO; + + protocol.schemaVersion = conf.getVersions().getSchemaVersion(); + protocol.subgraphVersion = conf.getVersions().getSubgraphVersion(); + protocol.methodologyVersion = conf.getVersions().getMethodologyVersion(); + + const proto = new ProtocolManager(protocol, pricer, event); + proto.save(); + return proto; + } + + /** + * Updates the protocol entity versions. This is called on load to make sure we update the version + * if we've grafted the subgraph. + * + * @param versions {Versions} An object that implements the Versions interface, to get the protocol's versions + */ + private setVersions(versions: Versions): void { + this.protocol.schemaVersion = versions.getSchemaVersion(); + this.protocol.subgraphVersion = versions.getSubgraphVersion(); + this.protocol.methodologyVersion = versions.getMethodologyVersion(); + this.save(); + } + + /** + * This will save the entity to storage. If any other action needs to be performed on + * save, it should be added here. + * It is meant to be used internally. If you need to save the entity from outside the wrapper + * you should probably be using some of the setters instead. + * @private + */ + private save(): void { + this.protocol.save(); + } + + /** + * + * @returns {string} The ID of the protocol entity. + */ + getID(): string { + return this.protocol.id.toHexString(); + } + + /** + * + * @returns {Bytes} The ID of the protocol entity, as Bytes. + */ + getBytesID(): Bytes { + return this.protocol.id; + } + + /** + * + * @returns {CustomEventType} the event currently being handled. + */ + getCurrentEvent(): CustomEventType { + return this.event; + } + + /** + * + * @returns {TokenPricer} The pricer object used by the wrapper. + * @see TokenPricer + */ + getTokenPricer(): TokenPricer { + return this.pricer; + } + + /** + * Sets the TVL in USD for the protocol. Most times this will be called internally by + * other members of the library when TVL changes are made to them. But if the library + * is not well fitted to a given protocol and you need to set the TVL manually, you can + * use this method. + * It will also update the protocol's snapshots. + * @param tvl {BigDecimal} The new total value locked for the protocol. + */ + setTotalValueLocked(tvl: BigDecimal): void { + this.protocol.totalValueLockedUSD = tvl; + this.save(); + } + + /** + * Adds a given USD value to the protocol's TVL. It can be a positive or negative amount. + * Same as for setTotalValueLocked, this is mostly to be called internally by the library. + * But you can use it if you need to. It will also update the protocol's snapshots. + * @param tvl {BigDecimal} The value to add to the protocol's TVL. + */ + addTotalValueLocked(tvl: BigDecimal): void { + this.protocol.totalValueLockedUSD = + this.protocol.totalValueLockedUSD.plus(tvl); + this.save(); + } + + /** + * Adds a given USD value to the protocol supplySideRevenue. It can be a positive or negative amount. + * Same as for the rest of setters, this is mostly to be called internally by the library. + * But you can use it if you need to. It will also update the protocol's snapshots. + * @param rev {BigDecimal} The value to add to the protocol's supplySideRevenue. + */ + addSupplySideRevenueUSD(rev: BigDecimal): void { + this.protocol.cumulativeTotalRevenueUSD = + this.protocol.cumulativeTotalRevenueUSD.plus(rev); + this.protocol.cumulativeSupplySideRevenueUSD = + this.protocol.cumulativeSupplySideRevenueUSD.plus(rev); + this.save(); + } + + /** + * Adds a given USD value to the protocol protocolSideRevenue. It can be a positive or negative amount. + * Same as for the rest of setters, this is mostly to be called internally by the library. + * But you can use it if you need to. It will also update the protocol's snapshots. + * @param rev {BigDecimal} The value to add to the protocol's protocolSideRevenue. + */ + addProtocolSideRevenueUSD(rev: BigDecimal): void { + this.protocol.cumulativeTotalRevenueUSD = + this.protocol.cumulativeTotalRevenueUSD.plus(rev); + this.protocol.cumulativeProtocolSideRevenueUSD = + this.protocol.cumulativeProtocolSideRevenueUSD.plus(rev); + this.save(); + } + + /** + * Adds a given USD value to the protocol's supplySideRevenue and protocolSideRevenue. It can be a positive or negative amount. + * Same as for the rest of setters, this is mostly to be called internally by the library. + * But you can use it if you need to. It will also update the protocol's snapshots. + * @param protocolSide {BigDecimal} The value to add to the protocol's protocolSideRevenue. + * @param supplySide {BigDecimal} The value to add to the protocol's supplySideRevenue. + */ + addRevenueUSD(protocolSide: BigDecimal, supplySide: BigDecimal): void { + this.addSupplySideRevenueUSD(supplySide); + this.addProtocolSideRevenueUSD(protocolSide); + } + + /** + * Adds some value to the cumulativeUniqueUsers counter. If the value is omitted it will default to 1. + * If you are loading accounts with the AccountManager you won't need to use this method. + * @param count {u8} The value to add to the counter. + */ + addUser(count: u8 = 1): void { + this.protocol.cumulativeUniqueUsers += count; + this.save(); + } + + /** + * Will increase the hourly and daily active users counters. These will be reflected + * on the next Usage snapshot whenever it comes up. + */ + addActiveUser(activity: AccountWasActive): void { + this.snapshoter.addActiveUser(activity); + } + + /** + * Increases the totalPoolCount counter by the given value. + * If you are using the PoolManager class you won't need to use this method. + * @param count {u8} The value to add to the counter. + * @see PoolManager + */ + addPool(count: u8 = 1): void { + this.protocol.totalPoolCount += count; + this.save(); + } + + addTransaction(): void { + this.protocol.cumulativeTransactionCount += 1; + this.save(); + } +} diff --git a/subgraphs/stakewise-v2/src/sdk/protocols/generic/protocolSnapshot.ts b/subgraphs/stakewise-v2/src/sdk/protocols/generic/protocolSnapshot.ts new file mode 100644 index 0000000000..85d80bbc36 --- /dev/null +++ b/subgraphs/stakewise-v2/src/sdk/protocols/generic/protocolSnapshot.ts @@ -0,0 +1,165 @@ +import { + _ActivityHelper, + FinancialsDailySnapshot, + UsageMetricsDailySnapshot, + Protocol as ProtocolSchema, +} from "../../../../generated/schema"; +import { AccountWasActive } from "./account"; +import { Bytes } from "@graphprotocol/graph-ts"; +import { SECONDS_PER_DAY } from "../../util/constants"; +import { CustomEventType, getUnixDays, getUnixHours } from "../../util/events"; + +const ActivityHelperID = Bytes.fromUTF8("_ActivityHelper"); + +/** + * This file contains the ProtocolSnapshot, which is used to + * make all of the storage changes that occur in the protocol's + * daily and hourly snapshots. + * + * Schema Version: 3.0.0 + * SDK Version: 1.1.0 + * Author(s): + * - @steegecs + * - @shashwatS22 + */ + +/** + * Helper class to manage Financials and Usage snapshots. + * It is not meant to be used directly, but rather by the Protocol and Account lib classes. + * Whenever it is instantiated it will check if it is time to take any of the + * dailyFinancials, dailyUsage or hourlyUsage snapshots. + * + * Snapshots are taken in a way that allows the snapshot entity to be immutable. + */ +export class ProtocolSnapshot { + protocol: ProtocolSchema; + event: CustomEventType; + dayID: i32; + hourID: i32; + activityHelper: _ActivityHelper; + + constructor(protocol: ProtocolSchema, event: CustomEventType) { + this.protocol = protocol; + this.event = event; + this.dayID = getUnixDays(event.block); + this.hourID = getUnixHours(event.block); + this.activityHelper = initActivityHelper(); + this.takeSnapshots(); + } + + addActiveUser(activity: AccountWasActive): void { + this.activityHelper.dailyActiveUsers += activity.daily ? 1 : 0; + this.activityHelper.save(); + } + + private takeSnapshots(): void { + const snapshotDayID = + this.protocol.lastUpdateTimestamp.toI32() / SECONDS_PER_DAY; + + if (snapshotDayID != this.dayID) { + this.takeFinancialsDailySnapshot(snapshotDayID); + this.takeUsageDailySnapshot(snapshotDayID); + this.protocol.lastSnapshotDayID = snapshotDayID; + this.protocol.save(); + } + } + + private takeFinancialsDailySnapshot(day: i32): void { + const snapshot = new FinancialsDailySnapshot(Bytes.fromI32(day)); + const previousSnapshot = FinancialsDailySnapshot.load( + Bytes.fromI32(this.protocol.lastSnapshotDayID) + ); + + snapshot.day = day; + snapshot.protocol = this.protocol.id; + snapshot.blockNumber = this.event.block.number; + snapshot.timestamp = this.event.block.timestamp; + + // tvl + snapshot.totalValueLockedUSD = this.protocol.totalValueLockedUSD; + + // revenues + snapshot.cumulativeSupplySideRevenueUSD = + this.protocol.cumulativeSupplySideRevenueUSD; + snapshot.cumulativeProtocolSideRevenueUSD = + this.protocol.cumulativeProtocolSideRevenueUSD; + snapshot.cumulativeTotalRevenueUSD = + this.protocol.cumulativeTotalRevenueUSD; + + // deltas + let supplySideRevenueDelta = snapshot.cumulativeSupplySideRevenueUSD; + let protocolSideRevenueDelta = snapshot.cumulativeProtocolSideRevenueUSD; + let totalRevenueDelta = snapshot.cumulativeTotalRevenueUSD; + + if (previousSnapshot) { + supplySideRevenueDelta = snapshot.cumulativeSupplySideRevenueUSD.minus( + previousSnapshot.cumulativeSupplySideRevenueUSD + ); + protocolSideRevenueDelta = + snapshot.cumulativeProtocolSideRevenueUSD.minus( + previousSnapshot.cumulativeProtocolSideRevenueUSD + ); + totalRevenueDelta = snapshot.cumulativeTotalRevenueUSD.minus( + previousSnapshot.cumulativeTotalRevenueUSD + ); + } + snapshot.dailySupplySideRevenueUSD = supplySideRevenueDelta; + snapshot.dailyProtocolSideRevenueUSD = protocolSideRevenueDelta; + snapshot.dailyTotalRevenueUSD = totalRevenueDelta; + + snapshot.save(); + } + + private takeUsageDailySnapshot(day: i32): void { + const activity = this.activityHelper; + + const snapshot = new UsageMetricsDailySnapshot(Bytes.fromI32(day)); + const previousSnapshot = UsageMetricsDailySnapshot.load( + Bytes.fromI32(this.protocol.lastSnapshotDayID) + ); + + snapshot.protocol = this.protocol.id; + snapshot.day = day; + snapshot.blockNumber = this.event.block.number; + snapshot.timestamp = this.event.block.timestamp; + + // unique users + snapshot.cumulativeUniqueUsers = this.protocol.cumulativeUniqueUsers; + + // daily activity + snapshot.dailyActiveUsers = activity.dailyActiveUsers; + + // transaction counts + snapshot.cumulativeTransactionCount = + this.protocol.cumulativeTransactionCount; + + // misc + snapshot.totalPoolCount = this.protocol.totalPoolCount; + + // deltas + let transactionDelta = snapshot.cumulativeTransactionCount; + + if (previousSnapshot) { + transactionDelta = + snapshot.cumulativeTransactionCount - + previousSnapshot.cumulativeTransactionCount; + } + snapshot.dailyTransactionCount = transactionDelta; + snapshot.save(); + + activity.dailyActiveUsers = 0; + activity.save(); + } +} + +function initActivityHelper(): _ActivityHelper { + let helper = _ActivityHelper.load(ActivityHelperID); + if (helper) { + return helper; + } + helper = new _ActivityHelper(ActivityHelperID); + helper.dailyActiveUsers = 0; + + helper.save(); + return helper; +} diff --git a/subgraphs/stakewise-v2/src/sdk/protocols/generic/tokens.ts b/subgraphs/stakewise-v2/src/sdk/protocols/generic/tokens.ts new file mode 100644 index 0000000000..7095cf896c --- /dev/null +++ b/subgraphs/stakewise-v2/src/sdk/protocols/generic/tokens.ts @@ -0,0 +1,58 @@ +import { ProtocolManager } from "./protocol"; +import { Address } from "@graphprotocol/graph-ts"; +import { Token } from "../../../../generated/schema"; +import { BIGDECIMAL_ZERO } from "../../util/constants"; + +/** + * This file contains the TokenManagerClass, which initializes + * token entities. + * + * Schema Version: 3.0.0 + * SDK Version: 1.1.0 + * Author(s): + * - @steegecs + * - @shashwatS22 + */ + +export interface TokenInitializer { + getTokenParams(address: Address): TokenParams; +} + +export class TokenParams { + name: string; + symbol: string; + decimals: i32; + + constructor(name: string, symbol: string, decimals: i32) { + this.name = name; + this.symbol = symbol; + this.decimals = decimals; + } +} + +export class TokenManager { + protocol: ProtocolManager; + initializer: TokenInitializer; + + constructor(protocol: ProtocolManager, init: TokenInitializer) { + this.protocol = protocol; + this.initializer = init; + } + + getOrCreateToken(address: Address): Token { + let token = Token.load(address); + if (token) { + return token; + } + + const params = this.initializer.getTokenParams(address); + token = new Token(address); + token.name = params.name; + token.symbol = params.symbol; + token.decimals = params.decimals; + token.lastPriceUSD = BIGDECIMAL_ZERO; + token.save(); + + return token; + } +} diff --git a/subgraphs/stakewise-v2/src/sdk/util/arrays.ts b/subgraphs/stakewise-v2/src/sdk/util/arrays.ts new file mode 100644 index 0000000000..d610008f16 --- /dev/null +++ b/subgraphs/stakewise-v2/src/sdk/util/arrays.ts @@ -0,0 +1,103 @@ +import { Bytes } from "@graphprotocol/graph-ts"; + +// A function which given 3 arrays of arbitrary types of the same length, +// where the first one holds the reference order, the second one holds the same elements +// as the first but in different order, and the third any arbitrary elements. It will return +// the third array after sorting it according to the order of the first one. +// For example: +// sortArrayByReference(['a', 'c', 'b'], ['a', 'b', 'c'], [1, 2, 3]) => [1, 3, 2] +export function sortArrayByReference( + reference: T[], + array: T[], + toSort: K[] +): K[] { + const sorted: K[] = new Array(); + for (let i = 0; i < reference.length; i++) { + const index = array.indexOf(reference[i]); + sorted.push(toSort[index]); + } + return sorted; +} + +// sortBytesArray will sort an array of Bytes in ascending order +// by comparing their hex string representation. +export function sortBytesArray(array: Bytes[]): Bytes[] { + const toSort = array.map((item) => item.toHexString()); + toSort.sort(); + return toSort.map((item) => Bytes.fromHexString(item)); +} + +export function updateArrayAtIndex(x: T[], item: T, index: i32): T[] { + if (x.length == 0) { + return [item]; + } + if (index == -1 || index > x.length) { + index = x.length; + } + const retval = new Array(); + let i = 0; + while (i < index) { + retval.push(x[i]); + i += 1; + } + retval.push(item); + i += 1; + while (i < x.length) { + retval.push(x[i]); + i += 1; + } + return retval; +} + +export function addToArrayAtIndex(x: T[], item: T, index: i32 = -1): T[] { + if (x.length == 0) { + return [item]; + } + if (index == -1 || index > x.length) { + index = x.length; + } + const retval = new Array(); + let i = 0; + while (i < index) { + retval.push(x[i]); + i += 1; + } + retval.push(item); + while (i < x.length) { + retval.push(x[i]); + i += 1; + } + return retval; +} + +export function addArrays(a: T[], b: T[]): T[] { + const retval = new Array(); + const arraysByLength = a.length <= b.length ? [a, b] : [b, a]; + + let i = 0; + while (i < arraysByLength[0].length) { + retval.push(a[i].plus(b[i])); + i += 1; + } + while (i < arraysByLength[1].length) { + retval.push(arraysByLength[1][i]); + i += 1; + } + return retval; +} + +export function subtractArrays(a: T[], b: T[]): T[] { + const retval = new Array(); + const arraysByLength = a.length <= b.length ? [a, b] : [b, a]; + + let i = 0; + while (i < arraysByLength[0].length) { + retval.push(a[i].minus(b[i])); + i += 1; + } + while (i < arraysByLength[1].length) { + retval.push(arraysByLength[1][i]); + i += 1; + } + return retval; +} diff --git a/subgraphs/stakewise-v2/src/sdk/util/constants.ts b/subgraphs/stakewise-v2/src/sdk/util/constants.ts new file mode 100644 index 0000000000..2501b21abe --- /dev/null +++ b/subgraphs/stakewise-v2/src/sdk/util/constants.ts @@ -0,0 +1,236 @@ +import { BigDecimal, BigInt } from "@graphprotocol/graph-ts"; + +//////////////////////// +///// Schema Enums ///// +//////////////////////// + +// The network names corresponding to the Network enum in the schema. +// They also correspond to the ones in `dataSource.network()` after converting to lower case. +// See below for a complete list: +// https://thegraph.com/docs/en/hosted-service/what-is-hosted-service/#supported-networks-on-the-hosted-service +export namespace Network { + export const ARBITRUM_ONE = "ARBITRUM_ONE"; + export const AVALANCHE = "AVALANCHE"; + export const AURORA = "AURORA"; + export const BASE = "BASE"; + export const BSC = "BSC"; // aka BNB Chain + export const CELO = "CELO"; + export const MAINNET = "MAINNET"; // Ethereum mainnet + export const FANTOM = "FANTOM"; + export const FUSE = "FUSE"; + export const MOONBEAM = "MOONBEAM"; + export const MOONRIVER = "MOONRIVER"; + export const NEAR_MAINNET = "NEAR_MAINNET"; + export const OPTIMISM = "OPTIMISM"; + export const MATIC = "MATIC"; // aka Polygon + export const XDAI = "XDAI"; // aka Gnosis Chain + export const GNOSIS = "GNOSIS"; + + // other networks + export const UBIQ = "UBIQ"; + export const SONGBIRD = "SONGBIRD"; + export const ELASTOS = "ELASTOS"; + export const KARDIACHAIN = "KARDIACHAIN"; + export const CRONOS = "CRONOS"; + export const RSK = "RSK"; + export const TELOS = "TELOS"; + export const XDC = "XDC"; + export const ZYX = "ZYX"; + export const CSC = "CSC"; + export const SYSCOIN = "SYSCOIN"; + export const GOCHAIN = "GOCHAIN"; + export const ETHEREUMCLASSIC = "ETHEREUMCLASSIC"; + export const OKEXCHAIN = "OKEXCHAIN"; + export const HOO = "HOO"; + export const METER = "METER"; + export const NOVA_NETWORK = "NOVA_NETWORK"; + export const TOMOCHAIN = "TOMOCHAIN"; + export const VELAS = "VELAS"; + export const THUNDERCORE = "THUNDERCORE"; + export const HECO = "HECO"; + export const XDAIARB = "XDAIARB"; + export const ENERGYWEB = "ENERGYWEB"; + export const HPB = "HPB"; + export const BOBA = "BOBA"; + export const KUCOIN = "KUCOIN"; + export const SHIDEN = "SHIDEN"; + export const THETA = "THETA"; + export const SX = "SX"; + export const CANDLE = "CANDLE"; + export const ASTAR = "ASTAR"; + export const CALLISTO = "CALLISTO"; + export const WANCHAIN = "WANCHAIN"; + export const METIS = "METIS"; + export const ULTRON = "ULTRON"; + export const STEP = "STEP"; + export const DOGECHAIN = "DOGECHAIN"; + export const RONIN = "RONIN"; + export const KAVA = "KAVA"; + export const IOTEX = "IOTEX"; + export const XLC = "XLC"; + export const NAHMII = "NAHMII"; + export const TOMBCHAIN = "TOMBCHAIN"; + export const CANTO = "CANTO"; + export const KLAYTN = "KLAYTN"; + export const EVMOS = "EVMOS"; + export const SMARTBCH = "SMARTBCH"; + export const BITGERT = "BITGERT"; + export const FUSION = "FUSION"; + export const OHO = "OHO"; + export const ARB_NOVA = "ARB_NOVA"; + export const OASIS = "OASIS"; + export const REI = "REI"; + export const REICHAIN = "REICHAIN"; + export const GODWOKEN = "GODWOKEN"; + export const POLIS = "POLIS"; + export const KEKCHAIN = "KEKCHAIN"; + export const VISION = "VISION"; + export const HARMONY = "HARMONY"; + export const PALM = "PALM"; + export const CURIO = "CURIO"; + + export const UNKNOWN_NETWORK = "UNKNOWN_NETWORK"; +} +export type Network = string; + +export namespace ProtocolType { + export const EXCHANGE = "EXCHANGE"; + export const LENDING = "LENDING"; + export const YIELD = "YIELD"; + export const BRIDGE = "BRIDGE"; + export const OPTION = "OPTION"; + export const PERPETUAL = "PERPETUAL"; + export const GENERIC = "GENERIC"; +} + +export namespace VaultFeeType { + export const MANAGEMENT_FEE = "MANAGEMENT_FEE"; + export const PERFORMANCE_FEE = "PERFORMANCE_FEE"; + export const DEPOSIT_FEE = "DEPOSIT_FEE"; + export const WITHDRAWAL_FEE = "WITHDRAWAL_FEE"; +} + +export namespace LiquidityPoolFeeType { + export const FIXED_TRADING_FEE = "FIXED_TRADING_FEE"; + export const TIERED_TRADING_FEE = "TIERED_TRADING_FEE"; + export const DYNAMIC_TRADING_FEE = "DYNAMIC_TRADING_FEE"; + export const FIXED_LP_FEE = "FIXED_LP_FEE"; + export const DYNAMIC_LP_FEE = "DYNAMIC_LP_FEE"; + export const FIXED_PROTOCOL_FEE = "FIXED_PROTOCOL_FEE"; + export const DYNAMIC_PROTOCOL_FEE = "DYNAMIC_PROTOCOL_FEE"; +} +export type LiquidityPoolFeeType = string; + +export namespace RewardTokenType { + export const DEPOSIT = "DEPOSIT"; + export const BORROW = "BORROW"; + export const STAKE = "STAKE"; +} +export type RewardTokenType = string; + +export namespace ActivityInterval { + export const HOURLY = "HOURLY"; + export const DAILY = "DAILY"; +} + +export namespace LendingType { + export const CDP = "CDP"; + export const POOLED = "POOLED"; +} + +export namespace RiskType { + export const GLOBAL = "GLOBAL"; + export const ISOLATED = "ISOLATED"; +} + +export namespace InterestRateType { + export const STABLE = "STABLE"; + export const VARIABLE = "VARIABLE"; + export const FIXED_TERM = "FIXED_TERM"; +} + +export namespace InterestRateSide { + export const LENDER = "LENDER"; + export const BORROWER = "BORROWER"; +} + +export namespace UsageType { + export const DEPOSIT = "DEPOSIT"; + export const WITHDRAW = "WITHDRAW"; + export const SWAP = "SWAP"; +} + +export namespace PositionSide { + export const LONG = "LONG"; + export const SHORT = "SHORT"; +} +export type PositionSide = string; + +////////////////////////////// +///// Ethereum Addresses ///// +////////////////////////////// + +export const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000"; +export const ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"; + +//////////////////////// +///// Type Helpers ///// +//////////////////////// + +export const DEFAULT_DECIMALS = 18; + +export const USDC_DECIMALS = 6; +export const USDC_DENOMINATOR = BigDecimal.fromString("1000000"); + +export const BIGINT_ZERO = BigInt.fromI32(0); +export const BIGINT_ONE = BigInt.fromI32(1); +export const BIGINT_TWO = BigInt.fromI32(2); +export const BIGINT_NINE = BigInt.fromI32(9); +export const BIGINT_TEN = BigInt.fromI32(10); +export const BIGINT_HUNDRED = BigInt.fromI32(100); +export const BIGINT_THOUSAND = BigInt.fromI32(1000); +export const BIGINT_TEN_TO_EIGHTEENTH = BigInt.fromString("10").pow(18); +export const BIGINT_MINUS_ONE = BigInt.fromI32(-1); +export const BIGINT_MAX = BigInt.fromString( + "115792089237316195423570985008687907853269984665640564039457584007913129639935" +); + +export const INT_NEGATIVE_ONE = -1 as i32; +export const INT_ZERO = 0 as i32; +export const INT_ONE = 1 as i32; +export const INT_TWO = 2 as i32; +export const INT_FOUR = 4 as i32; + +export const BIGDECIMAL_ZERO = new BigDecimal(BIGINT_ZERO); +export const BIGDECIMAL_ONE = new BigDecimal(BIGINT_ONE); +export const BIGDECIMAL_TWO = new BigDecimal(BIGINT_TWO); +export const BIGDECIMAL_TEN = new BigDecimal(BIGINT_TEN); +export const BIGDECIMAL_HUNDRED = new BigDecimal(BIGINT_HUNDRED); +export const BIGDECIMAL_THOUSAND = new BigDecimal(BIGINT_THOUSAND); +export const BIGDECIMAL_MINUS_ONE = new BigDecimal(BIGINT_MINUS_ONE); + +export const MAX_UINT = BigInt.fromI32(2).times(BigInt.fromI32(255)); +export const QI92 = BigDecimal.fromString( + "6277101735386680763835789423207666416102355444464034512896" +); // 2 ** 192 + +///////////////////// +///// Date/Time ///// +///////////////////// + +export const SECONDS_PER_DAY = 60 * 60 * 24; // 86400 +export const SECONDS_PER_HOUR = 60 * 60; // 3600 +export const SECONDS_PER_DAY_BI = BigInt.fromI32(SECONDS_PER_DAY); +export const SECONDS_PER_HOUR_BI = BigInt.fromI32(SECONDS_PER_HOUR); +export const MS_PER_DAY = new BigDecimal(BigInt.fromI32(24 * 60 * 60 * 1000)); +export const DAYS_PER_YEAR = new BigDecimal(BigInt.fromI32(365)); +export const MS_PER_YEAR = DAYS_PER_YEAR.times( + new BigDecimal(BigInt.fromI32(24 * 60 * 60 * 1000)) +); + +//////////////// +///// Misc ///// +//////////////// + +export const ETH_SYMBOL = "ETH"; +export const ETH_NAME = "Ether"; diff --git a/subgraphs/stakewise-v2/src/sdk/util/events.ts b/subgraphs/stakewise-v2/src/sdk/util/events.ts new file mode 100644 index 0000000000..5c6ee1e4d1 --- /dev/null +++ b/subgraphs/stakewise-v2/src/sdk/util/events.ts @@ -0,0 +1,70 @@ +import { BigInt, Address, Bytes, ethereum } from "@graphprotocol/graph-ts"; +import { + BIGINT_ZERO, + SECONDS_PER_DAY, + SECONDS_PER_HOUR, + ZERO_ADDRESS, +} from "./constants"; + +export class CustomEventType { + block: ethereum.Block; + transaction: ethereum.Transaction; + logIndex: BigInt; + event: ethereum.Event | null; + + constructor() { + this.block = new ethereum.Block( + Bytes.empty(), + Bytes.empty(), + Bytes.empty(), + Address.fromString(ZERO_ADDRESS), + Bytes.empty(), + Bytes.empty(), + Bytes.empty(), + BIGINT_ZERO, + BIGINT_ZERO, + BIGINT_ZERO, + BIGINT_ZERO, + BIGINT_ZERO, + BIGINT_ZERO, + null, + null + ); + this.transaction = new ethereum.Transaction( + Bytes.empty(), + BIGINT_ZERO, + Address.fromString(ZERO_ADDRESS), + null, + BIGINT_ZERO, + BIGINT_ZERO, + BIGINT_ZERO, + Bytes.empty(), + BIGINT_ZERO + ); + this.logIndex = BIGINT_ZERO; + this.event = null; + } + + static initialize( + block: ethereum.Block, + transaction: ethereum.Transaction, + logIndex: BigInt, + event: ethereum.Event | null = null + ): CustomEventType { + const customEvent = new CustomEventType(); + customEvent.block = block; + customEvent.transaction = transaction; + customEvent.logIndex = logIndex; + customEvent.event = event; + + return customEvent; + } +} + +export function getUnixDays(block: ethereum.Block): i32 { + return block.timestamp.toI32() / SECONDS_PER_DAY; +} + +export function getUnixHours(block: ethereum.Block): i32 { + return block.timestamp.toI32() / SECONDS_PER_HOUR; +} diff --git a/subgraphs/stakewise-v2/src/sdk/util/numbers.ts b/subgraphs/stakewise-v2/src/sdk/util/numbers.ts new file mode 100644 index 0000000000..725140a922 --- /dev/null +++ b/subgraphs/stakewise-v2/src/sdk/util/numbers.ts @@ -0,0 +1,61 @@ +import { BigDecimal, BigInt } from "@graphprotocol/graph-ts"; +import { + BIGDECIMAL_ZERO, + BIGINT_TEN, + DEFAULT_DECIMALS, + INT_TWO, +} from "./constants"; + +export function bigIntToBigDecimal( + quantity: BigInt, + decimals: i32 = DEFAULT_DECIMALS +): BigDecimal { + return quantity.divDecimal(BIGINT_TEN.pow(decimals as u8).toBigDecimal()); +} + +export function bigDecimalToBigInt(input: BigDecimal): BigInt { + const str = input.truncate(0).toString(); + return BigInt.fromString(str); +} + +// returns 10^exp +export function exponentToBigDecimal(exp: i32 = DEFAULT_DECIMALS): BigDecimal { + let bd = BigDecimal.fromString("1"); + const ten = BigDecimal.fromString("10"); + for (let i = 0; i < exp; i++) { + bd = bd.times(ten); + } + return bd; +} + +export function calculateAverage(prices: BigDecimal[]): BigDecimal { + let sum = BigDecimal.fromString("0"); + for (let i = 0; i < prices.length; i++) { + sum = sum.plus(prices[i]); + } + + return sum.div( + BigDecimal.fromString(BigInt.fromI32(prices.length).toString()) + ); +} + +export function calculateMedian(prices: BigDecimal[]): BigDecimal { + const sorted = prices.sort((a, b) => { + return a.equals(b) ? 0 : a.gt(b) ? 1 : -1; + }); + + const mid = Math.ceil(sorted.length / 2) as i32; + if (sorted.length % 2 == 0) { + return sorted[mid] + .plus(sorted[mid - 1]) + .div(BigDecimal.fromString(INT_TWO.toString())); + } + + return sorted[mid - 1]; +} + +export function safeDivide(a: BigDecimal, b: BigDecimal): BigDecimal { + if (b == BIGDECIMAL_ZERO) return BIGDECIMAL_ZERO; + + return a.div(b); +} diff --git a/subgraphs/stakewise-v2/src/sdk/util/rewards.ts b/subgraphs/stakewise-v2/src/sdk/util/rewards.ts new file mode 100644 index 0000000000..ad68987205 --- /dev/null +++ b/subgraphs/stakewise-v2/src/sdk/util/rewards.ts @@ -0,0 +1,295 @@ +///////////////////// +// VERSION 1.0.3 //// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// The purpose of this program is to dynamically estimate the blocks generated for the 24 HR period following the most recent update. // +// It does so by calculating the moving average block rate for an arbitrary length of time preceding the current block. // +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +import { log, BigDecimal, BigInt, dataSource } from "@graphprotocol/graph-ts"; +import { _CircularBuffer } from "../../../generated/schema"; +import { + Network, + BIGDECIMAL_ZERO, + INT_FOUR, + INT_NEGATIVE_ONE, + INT_ONE, + INT_TWO, + INT_ZERO, +} from "./constants"; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// WINDOW_SIZE_SECONDS, TIMESTAMP_STORAGE_INTERVALS, and BUFFER_SIZE can be modified. These are just recommended values - 'somewhat' arbitrary. // +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +// The storage interval tells you to only store blocks where the timestamps are separated by at least this amount. +// Increasing this value will mean less blocks stored and less frequently computes blocksSpeed. +export const TIMESTAMP_STORAGE_INTERVAL = 600; + +// The window size determines the range of blocks that you track from the current block minus the window size. +// Window of block time used to calculate the moving average. +// Increasing means less deviation but also less sensitivity to changing block speeds. +export const WINDOW_SIZE_SECONDS = 86400; + +// BUFFER_SIZE determined the size of the array +// Makes the buffer the maximum amount of blocks that can be stored given the block rate and storage interval +// Recommended value is (RATE_IN_SECODNDS / TIMESTAMP_STORAGE_INTERVAL) * 2 - > Round up to nearest even integer +export const BUFFER_SIZE = 288; + +// Add this entity to the schema. +// type _CircularBuffer @entity { +// " 'CIRCULAR_BUFFER' " +// id: ID! + +// " Array of sorted block numbers sorted continuously " +// blocks: [Int!]! + +// " The index in the blocks array which will be used with the newest block to calculate block speed (Usally set to about a day before newest block) " +// windowStartIndex: Int! + +// " The next index in the blocks array that will be replaced with the newest block " +// nextIndex: Int! + +// " This determines the size of the blocks array. Should be set to contain at least a days worth of blocks according to a 1 day window for measuring speed" +// bufferSize: Int! + +// " The current calculated number of blocks per day based on calculated block speed " +// blocksPerDay: BigDecimal! + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +export const CIRCULAR_BUFFER = "CIRCULAR_BUFFER"; + +// Describes whether the interval for which rewards are emitted is done by block or timestamp +export namespace RewardIntervalType { + export const BLOCK = "BLOCK"; + export const TIMESTAMP = "TIMESTAMP"; +} + +// Forecast period. This gives you the time period that you want to estimate count of blocks per interval, based on moving average block speed. +// 86400 = 1 Day +export const RATE_IN_SECONDS = 86400; +export const RATE_IN_SECONDS_BD = BigDecimal.fromString( + RATE_IN_SECONDS.toString() +); + +// Estimated seconds per block of the protocol +export const STARTING_BLOCKS_PER_DAY = RATE_IN_SECONDS_BD.div( + getStartingBlockRate() +); + +export const WINDOW_SIZE_SECONDS_BD = BigDecimal.fromString( + WINDOW_SIZE_SECONDS.toString() +); + +// Call this function in event handlers frequently enough so that it calls on blocks frequently enough +/** + * @param {BigInt} currentTimestamp - Timestamp for current event + * @param {BigInt} currentBlockNumber - Block nunmber of current event + * @param {BigInt} rewardRate - Rate of reward emissions per reward interval + * @param {BigInt} rewardType - Describes whether rewards are given per block or timestamp + * @returns {BigDecimal} - Returns estimated blocks for specified rate + */ +export function getRewardsPerDay( + currentTimestamp: BigInt, + currentBlockNumber: BigInt, + rewardRate: BigDecimal, + rewardType: string +): BigDecimal { + const circularBuffer = getOrCreateCircularBuffer(); + + // Create entity for the current block + const currentTimestampI32 = currentTimestamp.toI32(); + const currentBlockNumberI32 = currentBlockNumber.toI32(); + + const blocks = circularBuffer.blocks; + + // Interval between index and the index of the start of the window block + const windowWidth = abs( + circularBuffer.windowStartIndex - circularBuffer.nextIndex + ); + if (windowWidth == INT_ZERO) { + if (circularBuffer.nextIndex >= circularBuffer.bufferSize) { + blocks[INT_ZERO] = currentTimestampI32; + blocks[INT_ONE] = currentBlockNumberI32; + circularBuffer.nextIndex = INT_TWO; + } else { + blocks[circularBuffer.nextIndex] = currentTimestampI32; + blocks[circularBuffer.nextIndex + INT_ONE] = currentBlockNumberI32; + circularBuffer.nextIndex += INT_TWO; + } + + circularBuffer.save(); + + // return because there is only 1 reference point. + if (rewardType == RewardIntervalType.TIMESTAMP) { + return rewardRate.times(RATE_IN_SECONDS_BD); + } else { + return circularBuffer.blocksPerDay.times(rewardRate); + } + } + + // Add current timestamp and block numnber to array if new block is at least X blocks later than previously stored. + // Used to save memory and efficiency on array resizing. + let recentSavedTimestamp: i32; + if (circularBuffer.nextIndex == INT_ZERO) { + recentSavedTimestamp = blocks[circularBuffer.bufferSize - INT_TWO]; + } else { + recentSavedTimestamp = blocks[circularBuffer.nextIndex - INT_TWO]; + } + + if ( + currentTimestampI32 - recentSavedTimestamp <= + TIMESTAMP_STORAGE_INTERVAL + ) { + if (rewardType == RewardIntervalType.TIMESTAMP) { + return rewardRate.times(RATE_IN_SECONDS_BD); + } else { + return circularBuffer.blocksPerDay.times(rewardRate); + } + } + + blocks[circularBuffer.nextIndex] = currentTimestampI32; + blocks[circularBuffer.nextIndex + INT_ONE] = currentBlockNumberI32; + if (circularBuffer.nextIndex >= BUFFER_SIZE - INT_TWO) { + circularBuffer.nextIndex = INT_ZERO; + } else { + circularBuffer.nextIndex += INT_TWO; + } + // The timestamp at the start of the window (default 24 hours in seconds). + const startTimestamp = currentTimestampI32 - WINDOW_SIZE_SECONDS; + + // Make sure to still have 2 blocks to calculate rate (This shouldn't happen past the beginning). + while (true) { + if (circularBuffer.nextIndex > circularBuffer.windowStartIndex) { + if ( + circularBuffer.nextIndex - circularBuffer.windowStartIndex <= + INT_FOUR + ) { + break; + } + } else { + if ( + BUFFER_SIZE - + circularBuffer.windowStartIndex + + circularBuffer.nextIndex <= + INT_FOUR + ) { + break; + } + } + const windowIndexBlockTimestamp = blocks[circularBuffer.windowStartIndex]; + + // Shift the start of the window if the current timestamp moves out of desired rate window + if (windowIndexBlockTimestamp < startTimestamp) { + circularBuffer.windowStartIndex = + circularBuffer.windowStartIndex + INT_TWO; + if (circularBuffer.windowStartIndex >= circularBuffer.bufferSize) { + circularBuffer.windowStartIndex = INT_ZERO; + } + } else { + break; + } + } + + // Wideness of the window in seconds. + const windowSecondsCount = BigDecimal.fromString( + (currentTimestampI32 - blocks[circularBuffer.windowStartIndex]).toString() + ); + + // Wideness of the window in blocks. + const windowBlocksCount = BigDecimal.fromString( + ( + currentBlockNumberI32 - blocks[circularBuffer.windowStartIndex + INT_ONE] + ).toString() + ); + + // Estimate block speed for the window in seconds. + const unnormalizedBlockSpeed = + WINDOW_SIZE_SECONDS_BD.div(windowSecondsCount).times(windowBlocksCount); + + // block speed converted to specified rate. + const normalizedBlockSpeed = RATE_IN_SECONDS_BD.div( + WINDOW_SIZE_SECONDS_BD + ).times(unnormalizedBlockSpeed); + + // Update BlockTracker with new values. + circularBuffer.blocksPerDay = normalizedBlockSpeed; + circularBuffer.blocks = blocks; + + circularBuffer.save(); + + if (rewardType == RewardIntervalType.TIMESTAMP) { + return rewardRate.times(RATE_IN_SECONDS_BD); + } else { + return rewardRate.times(circularBuffer.blocksPerDay); + } +} + +function getOrCreateCircularBuffer(): _CircularBuffer { + let circularBuffer = _CircularBuffer.load(CIRCULAR_BUFFER); + + if (!circularBuffer) { + circularBuffer = new _CircularBuffer(CIRCULAR_BUFFER); + + const blocks = new Array(BUFFER_SIZE); + for (let i = INT_ZERO; i < BUFFER_SIZE; i += INT_TWO) { + blocks[i] = INT_NEGATIVE_ONE; + blocks[i + INT_ONE] = INT_NEGATIVE_ONE; + } + + circularBuffer.blocks = blocks; + circularBuffer.windowStartIndex = INT_ZERO; + circularBuffer.nextIndex = INT_ZERO; + circularBuffer.bufferSize = BUFFER_SIZE; + circularBuffer.blocksPerDay = STARTING_BLOCKS_PER_DAY; + + circularBuffer.save(); + } + + return circularBuffer; +} + +function getStartingBlockRate(): BigDecimal { + // Block rates pulled from google searches - rough estimates + + const network = dataSource.network().toUpperCase().replace("-", "_"); + if (network == Network.MAINNET) { + return BigDecimal.fromString("13.39"); + } else if (network == Network.ARBITRUM_ONE) { + return BigDecimal.fromString("15"); + } else if (network == Network.AURORA) { + return BigDecimal.fromString("1.03"); + } else if (network == Network.BSC) { + return BigDecimal.fromString("5"); + } else if (network == Network.CELO) { + return BigDecimal.fromString("5"); + } else if (network == Network.FANTOM) { + return BigDecimal.fromString("1"); + } else if (network == Network.FUSE) { + return BigDecimal.fromString("1"); + } else if (network == Network.OPTIMISM) { + return BigDecimal.fromString("12.5"); + } else if (network == Network.MATIC) { + return BigDecimal.fromString("2"); + } else if (network == Network.XDAI) { + return BigDecimal.fromString("5"); + } else if (network == Network.MOONBEAM) { + return BigDecimal.fromString("13.39"); + } else if (network == Network.MOONRIVER) { + return BigDecimal.fromString("13.39"); + } else if (network == Network.AVALANCHE) { + return BigDecimal.fromString("13.39"); + } else if (network == Network.CRONOS) { + return BigDecimal.fromString("5.5"); + } else if (network == Network.BASE) { + // assuming same block rate as OPTIMISM + return BigDecimal.fromString("12.5"); + } + + // else if (network == SubgraphNetwork.AVALANCHE) return BigDecimal.fromString("2.5") + // else if (dataSource.network() == "harmony") return BigDecimal.fromString("13.39") + else { + log.warning("getStartingBlockRate(): Network not found", []); + return BIGDECIMAL_ZERO; + } +} diff --git a/subgraphs/stakewise-v2/tsconfig.json b/subgraphs/stakewise-v2/tsconfig.json new file mode 100644 index 0000000000..5c5d17c928 --- /dev/null +++ b/subgraphs/stakewise-v2/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", + "include": ["src"] +}