├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── .gitmodules ├── 1inch ├── .gitignore ├── README.md ├── abis │ ├── ERC20.json │ ├── Mooniswap.json │ └── MooniswapFactory.json ├── config │ └── mainnet.json ├── package.json ├── schema.graphql ├── src │ ├── Mooniswap.ts │ ├── MooniswapFactory.ts │ ├── common.ts │ └── constants.ts └── subgraph.template.yaml ├── README.md ├── aave-v2 ├── .gitignore ├── README.md ├── abis │ ├── AToken.json │ ├── AaveIncentivesController.json │ ├── IERC20.json │ ├── IPriceOracleGetter.json │ ├── LendingPool.json │ ├── LendingPoolAddressesProvider.json │ ├── LendingPoolAddressesProviderRegistry.json │ ├── LendingPoolConfigurator.json │ ├── StableDebtToken.json │ └── VariableDebtToken.json ├── config │ ├── avalanche.json │ ├── mainnet.json │ └── matic.json ├── docs │ └── aave-subgraph-overview.md ├── package.json ├── schema.graphql ├── src │ ├── library │ │ ├── common.ts │ │ ├── constants.ts │ │ ├── lendingPoolUtils.ts │ │ └── math.ts │ └── mappings │ │ ├── aToken.ts │ │ ├── incentivesController.ts │ │ ├── lendingPool.ts │ │ ├── lendingPoolAddressProvider.ts │ │ ├── lendingPoolConfigurator.ts │ │ ├── stableDebtToken.ts │ │ └── variableDebtToken.ts └── subgraph.template.yaml ├── balancer-v2 ├── .gitignore ├── README.md ├── abis │ ├── IERC20.json │ ├── InvestmentPool.json │ ├── InvestmentPoolFactory.json │ ├── LiquidityBootstrappingPool.json │ ├── LiquidityBootstrappingPoolFactory.json │ ├── MetastablePool.json │ ├── MetastablePoolFactory.json │ ├── StablePool.json │ ├── StablePoolFactory.json │ ├── Vault.json │ ├── WeightedPool.json │ ├── WeightedPool2Tokens.json │ ├── WeightedPool2TokensFactory.json │ └── WeightedPoolFactory.json ├── config │ ├── arbitrum.json │ ├── mainnet.json │ └── polygon.json ├── package.json ├── schema.graphql ├── src │ ├── common.ts │ ├── constants.ts │ ├── investmentPoolFactory.ts │ ├── liquidityBootstrappingPoolFactory.ts │ ├── market.ts │ ├── metastablePoolFactory.ts │ ├── noProtocolFeeLiquidityBootstrappingPoolFactory.ts │ ├── pool.ts │ ├── stablePoolFactory.ts │ ├── vault.ts │ ├── weightedPool2TokensFactory.ts │ └── weightedPoolFactory.ts └── subgraph.template.yaml ├── compound ├── .gitignore ├── abis │ ├── CToken.json │ ├── Comptroller.json │ └── IERC20.json ├── package.json ├── schema.graphql ├── src │ ├── library │ │ ├── cTokenUtils.ts │ │ ├── common.ts │ │ └── constants.ts │ └── mappings │ │ ├── cToken.ts │ │ └── comptroller.ts └── subgraph.yaml ├── curve-exchange ├── .gitignore ├── README.md ├── abis │ ├── AddressProvider.json │ ├── CurvePool.json │ ├── CurveRegistry.json │ ├── IERC20.json │ └── MetaPoolFactory.json ├── package.json ├── schema.graphql ├── src │ ├── addressProvider.ts │ ├── common.ts │ ├── constants.ts │ ├── curveUtil.ts │ ├── metaPoolFactory.ts │ ├── pool.ts │ └── poolRegistry.ts └── templates │ ├── constants.arbitrum.ts │ ├── constants.avalanche.ts │ ├── constants.fantom.ts │ ├── constants.gnosis.ts │ ├── constants.mainnet.ts │ ├── constants.optimism.ts │ ├── constants.polygon.ts │ ├── subgraph.arbitrum.yaml │ ├── subgraph.avalanche.yaml │ ├── subgraph.fantom.yaml │ ├── subgraph.gnosis.yaml │ ├── subgraph.mainnet.yaml │ ├── subgraph.optimism.yaml │ └── subgraph.polygon.yaml ├── curve-gauges-multichain ├── .gitignore ├── README.md ├── abis │ ├── ERC20.json │ ├── GaugeController.json │ ├── GaugeFactory.json │ ├── LiquidityGauge.json │ ├── MetaPoolFactory.json │ └── Minter.json ├── package.json ├── schema.graphql ├── src │ ├── common.ts │ ├── constants.ts │ ├── gauge.ts │ ├── gaugeFactory.ts │ ├── gaugeUtils.ts │ └── metaPoolFactory.ts └── templates │ ├── subgraph.arbitrum.yaml │ ├── subgraph.avalanche.yaml │ ├── subgraph.fantom.yaml │ ├── subgraph.gnosis.yaml │ ├── subgraph.optimism.yaml │ └── subgraph.polygon.yaml ├── curve-gauges ├── .gitignore ├── README.md ├── abis │ ├── ERC20.json │ ├── GaugeController.json │ ├── LiquidityGauge.json │ └── Minter.json ├── package.json ├── schema.graphql ├── src │ ├── common.ts │ ├── constants.ts │ ├── gauge.ts │ └── gaugeController.ts └── subgraph.yaml ├── harvest-finance ├── .gitignore ├── README.md ├── abis │ ├── FeeRewardForwarder.json │ ├── HarvestEthController.json │ ├── IERC20.json │ ├── NotifyHelper.json │ ├── ProfitSharingPool.json │ ├── RewardPool.json │ └── Vault.json ├── package.json ├── schema.graphql ├── src │ ├── ProfitSharingPool.ts │ ├── common.ts │ ├── constants.ts │ ├── controller.ts │ ├── feeRewardForwarder.ts │ ├── harvestUtils.ts │ ├── notifyHelper.ts │ ├── rewardPool.ts │ └── vault.ts ├── subgraph.yaml └── tsconfig.json ├── minichef ├── README ├── abis │ ├── IERC20.json │ ├── IRewarder.json │ ├── MasterChefJoe.json │ ├── MiniApe.json │ └── MiniChef.json ├── config │ ├── apeswap-polygon.json │ ├── sushiswap-arbitrum.json │ ├── sushiswap-celo.json │ ├── sushiswap-polygon.json │ └── sushiswap-xdai.json ├── docs │ └── developer_reference.md ├── package.json ├── schema.graphql ├── src │ ├── library │ │ ├── common.ts │ │ ├── constants.ts │ │ └── masterChefUtils.ts │ └── mappings │ │ ├── minichef-apeswap.ts │ │ ├── minichef-joe.ts │ │ └── minichef.ts ├── subgraph.apeswap.template.yaml ├── subgraph.joe.yaml └── subgraph.template.yaml ├── mstable-v2 ├── .gitignore ├── README.md ├── abis │ ├── AssetProxy.json │ ├── FeederPool.json │ ├── IERC20.json │ ├── IMAsset.json │ ├── MAsset.json │ └── VIMAsset.json ├── package.json ├── schema.graphql ├── src │ ├── common.ts │ ├── constants.ts │ ├── feederPool.ts │ ├── fpmBTCHBTC.ts │ ├── fpmBTCTBTC.ts │ ├── imAsset.ts │ ├── imBTC.ts │ ├── mAsset.ts │ ├── mBTC.ts │ ├── vimAsset.ts │ └── vimBTC.ts └── subgraph.yaml ├── near-template ├── .gitignore ├── README.md ├── package.json ├── schema.graphql ├── src │ ├── common.ts │ ├── constants.ts │ └── near.ts ├── subgraph.yaml └── tsconfig.json ├── protocol-volumes └── uniswap-v2 │ ├── .gitignore │ ├── README.md │ ├── abis │ ├── IERC20.json │ ├── IUniswapV2Factory.json │ └── IUniswapV2Pair.json │ ├── config │ ├── apeswap-bsc.json │ ├── apeswap-polygon.json │ ├── auroraswap-aurora.json │ ├── biswap-bsc.json │ ├── cometh-polygon.json │ ├── pancakeswap-bsc.json │ ├── pangolin-avalanche.json │ ├── quickswap-polygon.json │ ├── sushiswap-arbitrum.json │ ├── sushiswap-avalanche.json │ ├── sushiswap-bsc.json │ ├── sushiswap-celo.json │ ├── sushiswap-fantom.json │ ├── sushiswap-mainnet.json │ ├── sushiswap-polygon.json │ ├── sushiswap-xdai.json │ ├── traderjoe-avalanche.json │ ├── trisolaris-aurora.json │ ├── uniswap-v2-mainnet.json │ └── wannaswap-aurora.json │ ├── package.json │ ├── schema.graphql │ ├── src │ ├── constants.ts │ ├── uniswapV2Factory.ts │ ├── uniswapV2Pair.ts │ └── utils.ts │ └── subgraph.template.yaml ├── ref-finance-farms ├── .gitignore ├── README.md ├── package.json ├── schema.graphql ├── src │ ├── common.ts │ ├── constants.ts │ ├── farm │ │ ├── farm.ts │ │ ├── tokenReceiver.ts │ │ └── util.ts │ └── near.ts ├── subgraph.yaml └── tsconfig.json ├── ref-finance ├── .gitignore ├── README.md ├── deployments.txt ├── package.json ├── schema.graphql ├── src │ ├── common.ts │ ├── constants.ts │ ├── exchange │ │ ├── accountDeposit.ts │ │ ├── commonExchange.ts │ │ ├── exchange.ts │ │ ├── mft.ts │ │ ├── owner.ts │ │ ├── ratedExchange.ts │ │ ├── ratedSwap.ts │ │ ├── simpleExchange.ts │ │ ├── stableExchange.ts │ │ ├── stableSwap.ts │ │ └── tokenReceiver.ts │ └── near.ts ├── subgraph.yaml └── tsconfig.json ├── schema-common.graphql ├── stake-dao ├── .gitignore ├── abis │ ├── IERC20.json │ ├── StakeDAOController.json │ ├── StakeDAOMasterChef.json │ ├── StakeDAOStrategy.json │ └── StakeDAOVault.json ├── package.json ├── schema.graphql ├── src │ ├── common.ts │ ├── constants.ts │ ├── stakeDAOController.ts │ ├── stakeDAOMasterChef.ts │ └── stakeDAOVault.ts └── subgraph.yaml ├── staking-rewards ├── .DS_Store ├── .gitignore ├── README.md ├── abis │ ├── IERC20.json │ └── StakingRewards.json ├── package.json ├── schema.graphql ├── src │ ├── lib │ │ ├── common.ts │ │ └── constants.ts │ └── stakingRewards.ts └── templates │ ├── subgraph.mainnet.yaml │ └── subgraph.optimism.yaml ├── sushiswap-farms ├── .gitignore ├── README.md ├── abis │ ├── IERC20.json │ ├── IRewarder.json │ ├── MasterChef.json │ └── MasterChefV2.json ├── docs │ └── developer_reference.md ├── package.json ├── schema.graphql ├── src │ ├── library │ │ ├── common.ts │ │ ├── constants.ts │ │ └── masterChefUtils.ts │ └── mappings │ │ ├── masterChef.ts │ │ └── masterChefV2.ts └── subgraph.yaml └── uniswap-v2 ├── .gitignore ├── README.md ├── abis ├── IERC20.json ├── IUniswapV2Factory.json └── IUniswapV2Pair.json ├── config ├── apeswap-bsc.json ├── apeswap-polygon.json ├── auroraswap-aurora.json ├── biswap-bsc.json ├── cometh-polygon.json ├── pancakeswap-bsc.json ├── pangolin-avalanche.json ├── quickswap-polygon.json ├── sushiswap-arbitrum.json ├── sushiswap-avalanche.json ├── sushiswap-bsc.json ├── sushiswap-celo.json ├── sushiswap-fantom.json ├── sushiswap-mainnet.json ├── sushiswap-polygon.json ├── sushiswap-xdai.json ├── traderjoe-avalanche.json ├── trisolaris-aurora.json ├── uniswap-v2-mainnet.json └── wannaswap-aurora.json ├── package.json ├── schema.graphql ├── src ├── common.ts ├── constants.ts ├── factories │ ├── apeswap.ts │ ├── auroraswap.ts │ ├── biswap.ts │ ├── cometh.ts │ ├── pancakeswap.ts │ ├── pangolin.ts │ ├── quickswap.ts │ ├── sushiswap.ts │ ├── traderjoe.ts │ ├── trisolaris.ts │ ├── uniswap.ts │ └── wannaswap.ts ├── uniswapV2Factory.ts └── uniswapV2Pair.ts └── subgraph.template.yaml /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | package-lock.json 107 | 108 | build/ 109 | generated/ 110 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "simple-fi-aave/submodules/protocol-v2"] 2 | path = simple-fi-aave/submodules/protocol-v2 3 | url = git@github.com:aave/protocol-v2.git -------------------------------------------------------------------------------- /1inch/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | package-lock.json 107 | 108 | build/ 109 | generated/ 110 | subgraph.yaml 111 | -------------------------------------------------------------------------------- /1inch/README.md: -------------------------------------------------------------------------------- 1 | # 1inch -------------------------------------------------------------------------------- /1inch/config/mainnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "mainnet", 3 | "factoryAddress": "0xbAF9A5d4b0052359326A6CDAb54BABAa3a3A9643", 4 | "factoryAddressStartBlock": 11607841 5 | } 6 | -------------------------------------------------------------------------------- /1inch/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simplefi-1inch", 3 | "license": "UNLICENSED", 4 | "scripts": { 5 | "codegen": "graph codegen", 6 | "build": "graph build", 7 | "prepare-mainnet": "mustache ./config/mainnet.json subgraph.template.yaml > subgraph.yaml && npm run codegen", 8 | "deploy-mainnet": "npm run prepare-mainnet && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/oneinch", 9 | "create-local": "graph create --node http://localhost:8020/ simplefi-finance/oneinch", 10 | "remove-local": "graph remove --node http://localhost:8020/ simplefi-finance/oneinch", 11 | "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 simplefi-finance/oneinch" 12 | }, 13 | "dependencies": { 14 | "@graphprotocol/graph-cli": "^0.25.1", 15 | "@graphprotocol/graph-ts": "0.24.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /1inch/src/MooniswapFactory.ts: -------------------------------------------------------------------------------- 1 | import { Address, BigInt } from "@graphprotocol/graph-ts" 2 | 3 | import { Pair as PairEntity } from "../generated/schema" 4 | 5 | import { Mooniswap } from "../generated/templates" 6 | 7 | import { 8 | Deployed 9 | } from "../generated/MooniswapFactory/MooniswapFactory" 10 | 11 | import { 12 | ADDRESS_ZERO, 13 | ADDRESS_ETH, 14 | getOrCreateAccount, 15 | getOrCreateERC20Token, 16 | getOrCreateMarket 17 | } from "./common" 18 | 19 | import { ProtocolName, ProtocolType } from "./constants" 20 | 21 | export function handleDeployed(event: Deployed): void { 22 | // Protocol is not consistent with token index, sometimes it uses 0-1 and sometimes 1-2. 23 | // We use 0-1 across the board and map params accordingly 24 | // Create a tokens and market entity 25 | let token0 = getOrCreateERC20Token(event, getTokenAddress(event.params.token1)) 26 | let token1 = getOrCreateERC20Token(event, getTokenAddress(event.params.token2)) 27 | let lpToken = getOrCreateERC20Token(event, event.params.mooniswap) 28 | 29 | let market = getOrCreateMarket( 30 | event, 31 | event.params.mooniswap, 32 | ProtocolName.ONEINCH, 33 | ProtocolType.EXCHANGE, 34 | [token0, token1], 35 | lpToken, 36 | [] 37 | ) 38 | 39 | lpToken.mintedByMarket = market.id 40 | lpToken.save() 41 | 42 | // Create pair 43 | let pair = new PairEntity(event.params.mooniswap.toHexString()) 44 | pair.factory = getOrCreateAccount(event.address).id 45 | pair.token0 = token0.id 46 | pair.token1 = token1.id 47 | pair.totalSupply = BigInt.fromI32(0) 48 | pair.reserve0 = BigInt.fromI32(0) 49 | pair.reserve1 = BigInt.fromI32(0) 50 | pair.blockNumber = event.block.number 51 | pair.timestamp = event.block.timestamp 52 | pair.save() 53 | 54 | // Start listening for market events 55 | Mooniswap.create(event.params.mooniswap) 56 | } 57 | 58 | function getTokenAddress(token: Address) : Address { 59 | // Standard ETH Address for protocols that don't use WETH 60 | if (token.toHexString() == ADDRESS_ZERO) { 61 | return Address.fromString(ADDRESS_ETH) 62 | } 63 | 64 | return token 65 | } 66 | -------------------------------------------------------------------------------- /1inch/src/constants.ts: -------------------------------------------------------------------------------- 1 | export namespace Blockchain { 2 | export const ETHEREUM = "ETHEREUM" 3 | export const BSC = "BSC" 4 | export const XDAI = "XDAI" 5 | export const POLYGON = "POLYGON" 6 | export const OPTIMISM = "OPTIMISM" 7 | export const AVALANCHE = "AVALANCE" 8 | export const NEAR = "NEAR" 9 | } 10 | 11 | export namespace TokenStandard { 12 | export const ERC20 = "ERC20" 13 | export const ERC721 = "ERC721" 14 | export const ERC1155 = "ERC1155" 15 | } 16 | 17 | export namespace ProtocolName { 18 | export const UNISWAP_V2 = "UNISWAP_V2" 19 | export const ONEINCH = "ONEINCH" 20 | } 21 | 22 | export namespace ProtocolType { 23 | export const STAKING = "STAKING" 24 | export const LENDING = "LENDING" 25 | export const EXCHANGE = "EXCHANGE" 26 | export const INSURANCE = "INSURANCE" 27 | export const STABLECOIN = "STABLECOIN" 28 | export const DERIVATIVE = "DERIVATIVE" 29 | export const SYNTHETIC_TOKEN = "SYNTHETIC_TOKEN" 30 | export const TOKEN_MANAGEMENT = "TOKEN_MANAGEMENT" 31 | export const PREDICTION_MARKET = "PREDICTION_MARKET" 32 | } 33 | 34 | export namespace PositionType { 35 | export const INVESTMENT = "INVESTMENT" 36 | export const DEBT = "DEBT" 37 | } 38 | 39 | export namespace TransactionType { 40 | export const INVEST = "INVEST" 41 | export const REDEEM = "REDEEM" 42 | export const BORROW = "BORROW" 43 | export const REPAY = "REPAY" 44 | export const TRANSFER_IN = "TRANSFER_IN" 45 | export const TRANSFER_OUT = "TRANSFER_OUT" 46 | } 47 | -------------------------------------------------------------------------------- /1inch/subgraph.template.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.2 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: MooniswapFactory 7 | network: {{network}} 8 | source: 9 | address: "{{factoryAddress}}" 10 | abi: MooniswapFactory 11 | startBlock: {{factoryAddressStartBlock}} 12 | mapping: 13 | kind: ethereum/events 14 | apiVersion: 0.0.5 15 | language: wasm/assemblyscript 16 | entities: 17 | - Block 18 | - Account 19 | - Token 20 | - Market 21 | - Pair 22 | abis: 23 | - name: ERC20 24 | file: ./abis/ERC20.json 25 | - name: MooniswapFactory 26 | file: ./abis/MooniswapFactory.json 27 | eventHandlers: 28 | - event: Deployed(indexed address,indexed address,indexed address) 29 | handler: handleDeployed 30 | file: ./src/MooniswapFactory.ts 31 | templates: 32 | - kind: ethereum/contract 33 | name: Mooniswap 34 | network: {{network}} 35 | source: 36 | abi: Mooniswap 37 | mapping: 38 | kind: ethereum/events 39 | apiVersion: 0.0.5 40 | language: wasm/assemblyscript 41 | file: ./src/Mooniswap.ts 42 | entities: 43 | - Block 44 | - Account 45 | - Token 46 | - Market 47 | - Transaction 48 | - Transfer 49 | - Position 50 | - PositionSnapshot 51 | - Pair 52 | - PairSnapshot 53 | abis: 54 | - name: ERC20 55 | file: ./abis/ERC20.json 56 | - name: MooniswapFactory 57 | file: ./abis/MooniswapFactory.json 58 | - name: Mooniswap 59 | file: ./abis/Mooniswap.json 60 | eventHandlers: 61 | - event: Transfer(indexed address,indexed address,uint256) 62 | handler: handleTransfer 63 | - event: Deposited(indexed address,indexed address,uint256,uint256,uint256) 64 | handler: handleMint 65 | - event: Withdrawn(indexed address,indexed address,uint256,uint256,uint256) 66 | handler: handleBurn 67 | -------------------------------------------------------------------------------- /aave-v2/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | package-lock.json 107 | 108 | build/ 109 | generated/ 110 | subgraph.yaml 111 | -------------------------------------------------------------------------------- /aave-v2/abis/IPriceOracleGetter.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [ 4 | { 5 | "internalType": "address", 6 | "name": "asset", 7 | "type": "address" 8 | } 9 | ], 10 | "name": "getAssetPrice", 11 | "outputs": [ 12 | { 13 | "internalType": "uint256", 14 | "name": "", 15 | "type": "uint256" 16 | } 17 | ], 18 | "stateMutability": "view", 19 | "type": "function" 20 | } 21 | ] -------------------------------------------------------------------------------- /aave-v2/config/avalanche.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "avalanche", 3 | "LendingPoolAddressesProviderRegistryAddress": "0x4235e22d9c3f28dcda82b58276cb6370b01265c2", 4 | "LendingPoolAddressesProviderRegistryStartBlock": 4606878 5 | } -------------------------------------------------------------------------------- /aave-v2/config/mainnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "mainnet", 3 | "LendingPoolAddressesProviderRegistryAddress": "0x52d306e36e3b6b02c153d0266ff0f85d18bcd413", 4 | "LendingPoolAddressesProviderRegistryStartBlock": 11360925 5 | } -------------------------------------------------------------------------------- /aave-v2/config/matic.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "matic", 3 | "LendingPoolAddressesProviderRegistryAddress": "0x3ac4e9aa29940770aeC38fe853a4bbabb2dA9C19", 4 | "LendingPoolAddressesProviderRegistryStartBlock": 12687211 5 | } -------------------------------------------------------------------------------- /aave-v2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "aave-v2", 3 | "license": "UNLICENSED", 4 | "scripts": { 5 | "codegen": "graph codegen", 6 | "build": "graph build", 7 | "clean": "rm -rf ./build && rm -rf ./generated && rm subgraph.yaml", 8 | "prepare-mainnet": "mustache ./config/mainnet.json subgraph.template.yaml > subgraph.yaml && npm run codegen", 9 | "prepare-polygon": "mustache ./config/matic.json subgraph.template.yaml > subgraph.yaml && npm run codegen", 10 | "prepare-avalanche": "mustache ./config/avalanche.json subgraph.template.yaml > subgraph.yaml && npm run codegen", 11 | "deploy-mainnet": "npm run prepare-mainnet && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/aave-v2", 12 | "deploy-polygon": "npm run prepare-polygon && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/aave-v2-polygon", 13 | "deploy-avalanche": "npm run prepare-avalanche && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/aave-v2-avalanche", 14 | "deploy-all": "npm run clean && npm run deploy-mainnet && npm run clean && npm run deploy-polygon && npm run clean && npm run deploy-avalanche", 15 | "create-local": "graph create --node http://localhost:8020/ simplefi-finance/aave-v2", 16 | "remove-local": "graph remove --node http://localhost:8020/ simplefi-finance/aave-v2", 17 | "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 simplefi-finance/aave-v2" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/SimpleFi-finance/subgraphs.git" 22 | }, 23 | "author": "SimpleFi", 24 | "bugs": { 25 | "url": "https://github.com/SimpleFi-finance/subgraphs.git/issues" 26 | }, 27 | "homepage": "https://docs.simplefi.finance/subgraph-development-documentation", 28 | "dependencies": { 29 | "@graphprotocol/graph-cli": "0.20.0", 30 | "@graphprotocol/graph-ts": "0.20.0", 31 | "mustache": "^4.2.0" 32 | } 33 | } -------------------------------------------------------------------------------- /aave-v2/src/library/math.ts: -------------------------------------------------------------------------------- 1 | import { BigInt } from "@graphprotocol/graph-ts"; 2 | 3 | let RAY = BigInt.fromI32(10).pow(27); 4 | let WAD_RAY_RATIO = BigInt.fromI32(10).pow(9); 5 | let WAD = BigInt.fromI32(10).pow(18); 6 | let halfRAY = RAY.div(BigInt.fromI32(2)); 7 | let SECONDS_PER_YEAR = BigInt.fromI32(31556952); 8 | 9 | /** 10 | * Math functions based on Aave smart contract implementation. 11 | */ 12 | 13 | export function rayToWad(a: BigInt): BigInt { 14 | let halfRatio = WAD_RAY_RATIO.div(BigInt.fromI32(2)); 15 | return halfRatio.plus(a).div(WAD_RAY_RATIO); 16 | } 17 | 18 | export function wadToRay(a: BigInt): BigInt { 19 | let result = a.times(WAD_RAY_RATIO); 20 | return result; 21 | } 22 | 23 | export function rayDiv(a: BigInt, b: BigInt): BigInt { 24 | let halfB = b.div(BigInt.fromI32(2)); 25 | let result = a.times(RAY); 26 | result = result.plus(halfB); 27 | let division = result.div(b); 28 | return division; 29 | } 30 | 31 | export function rayMul(a: BigInt, b: BigInt): BigInt { 32 | let result = a.times(b); 33 | result = result.plus(halfRAY); 34 | let mult = result.div(RAY); 35 | return mult; 36 | } 37 | 38 | export function calculateCompoundedInterest( 39 | rate: BigInt, 40 | lastUpdatedTimestamp: BigInt, 41 | nowTimestamp: BigInt 42 | ): BigInt { 43 | let timeDiff = nowTimestamp.minus(lastUpdatedTimestamp); 44 | 45 | if (timeDiff.equals(BigInt.fromI32(0))) { 46 | return RAY; 47 | } 48 | 49 | let expMinusOne = timeDiff.minus(BigInt.fromI32(1)); 50 | 51 | let expMinusTwo = timeDiff.gt(BigInt.fromI32(2)) 52 | ? timeDiff.minus(BigInt.fromI32(2)) 53 | : BigInt.fromI32(0); 54 | 55 | let ratePerSecond = rate.div(SECONDS_PER_YEAR); 56 | 57 | let basePowerTwo = rayMul(ratePerSecond, ratePerSecond); 58 | let basePowerThree = rayMul(basePowerTwo, ratePerSecond); 59 | 60 | let secondTerm = timeDiff 61 | .times(expMinusOne) 62 | .times(basePowerTwo) 63 | .div(BigInt.fromI32(2)); 64 | let thirdTerm = timeDiff 65 | .times(expMinusOne) 66 | .times(expMinusTwo) 67 | .times(basePowerThree) 68 | .div(BigInt.fromI32(6)); 69 | 70 | return RAY.plus(ratePerSecond.times(timeDiff)) 71 | .plus(secondTerm) 72 | .plus(thirdTerm); 73 | } 74 | 75 | export function calculateLinearInterest( 76 | rate: BigInt, 77 | lastUpdatedTimestamp: BigInt, 78 | nowTimestamp: BigInt 79 | ): BigInt { 80 | let timeDifference = nowTimestamp.minus(lastUpdatedTimestamp); 81 | 82 | let timeDelta = rayDiv(wadToRay(timeDifference), wadToRay(SECONDS_PER_YEAR)); 83 | 84 | return rayMul(rate, timeDelta); 85 | } 86 | 87 | export function calculateGrowth( 88 | amount: BigInt, 89 | rate: BigInt, 90 | lastUpdatedTimestamp: BigInt, 91 | nowTimestamp: BigInt 92 | ): BigInt { 93 | let growthRate = calculateLinearInterest(rate, lastUpdatedTimestamp, nowTimestamp); 94 | 95 | let growth = rayMul(wadToRay(amount), growthRate); 96 | 97 | return rayToWad(growth); 98 | } 99 | -------------------------------------------------------------------------------- /balancer-v2/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | package-lock.json 107 | 108 | build/ 109 | generated/ 110 | subgraph.yaml -------------------------------------------------------------------------------- /balancer-v2/README.md: -------------------------------------------------------------------------------- 1 | # Balancer V2 2 | -------------------------------------------------------------------------------- /balancer-v2/abis/StablePoolFactory.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [ 4 | { 5 | "internalType": "contract IVault", 6 | "name": "vault", 7 | "type": "address" 8 | } 9 | ], 10 | "stateMutability": "nonpayable", 11 | "type": "constructor" 12 | }, 13 | { 14 | "anonymous": false, 15 | "inputs": [ 16 | { 17 | "indexed": true, 18 | "internalType": "address", 19 | "name": "pool", 20 | "type": "address" 21 | } 22 | ], 23 | "name": "PoolCreated", 24 | "type": "event" 25 | }, 26 | { 27 | "inputs": [ 28 | { 29 | "internalType": "string", 30 | "name": "name", 31 | "type": "string" 32 | }, 33 | { 34 | "internalType": "string", 35 | "name": "symbol", 36 | "type": "string" 37 | }, 38 | { 39 | "internalType": "contract IERC20[]", 40 | "name": "tokens", 41 | "type": "address[]" 42 | }, 43 | { 44 | "internalType": "uint256", 45 | "name": "amplificationParameter", 46 | "type": "uint256" 47 | }, 48 | { 49 | "internalType": "uint256", 50 | "name": "swapFeePercentage", 51 | "type": "uint256" 52 | }, 53 | { 54 | "internalType": "address", 55 | "name": "owner", 56 | "type": "address" 57 | } 58 | ], 59 | "name": "create", 60 | "outputs": [ 61 | { 62 | "internalType": "address", 63 | "name": "", 64 | "type": "address" 65 | } 66 | ], 67 | "stateMutability": "nonpayable", 68 | "type": "function" 69 | }, 70 | { 71 | "inputs": [], 72 | "name": "getPauseConfiguration", 73 | "outputs": [ 74 | { 75 | "internalType": "uint256", 76 | "name": "pauseWindowDuration", 77 | "type": "uint256" 78 | }, 79 | { 80 | "internalType": "uint256", 81 | "name": "bufferPeriodDuration", 82 | "type": "uint256" 83 | } 84 | ], 85 | "stateMutability": "view", 86 | "type": "function" 87 | }, 88 | { 89 | "inputs": [], 90 | "name": "getVault", 91 | "outputs": [ 92 | { 93 | "internalType": "contract IVault", 94 | "name": "", 95 | "type": "address" 96 | } 97 | ], 98 | "stateMutability": "view", 99 | "type": "function" 100 | }, 101 | { 102 | "inputs": [ 103 | { 104 | "internalType": "address", 105 | "name": "pool", 106 | "type": "address" 107 | } 108 | ], 109 | "name": "isPoolFromFactory", 110 | "outputs": [ 111 | { 112 | "internalType": "bool", 113 | "name": "", 114 | "type": "bool" 115 | } 116 | ], 117 | "stateMutability": "view", 118 | "type": "function" 119 | } 120 | ] 121 | -------------------------------------------------------------------------------- /balancer-v2/abis/WeightedPool2TokensFactory.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [ 4 | { 5 | "internalType": "contract IVault", 6 | "name": "vault", 7 | "type": "address" 8 | } 9 | ], 10 | "stateMutability": "nonpayable", 11 | "type": "constructor" 12 | }, 13 | { 14 | "anonymous": false, 15 | "inputs": [ 16 | { 17 | "indexed": true, 18 | "internalType": "address", 19 | "name": "pool", 20 | "type": "address" 21 | } 22 | ], 23 | "name": "PoolCreated", 24 | "type": "event" 25 | }, 26 | { 27 | "inputs": [ 28 | { 29 | "internalType": "string", 30 | "name": "name", 31 | "type": "string" 32 | }, 33 | { 34 | "internalType": "string", 35 | "name": "symbol", 36 | "type": "string" 37 | }, 38 | { 39 | "internalType": "contract IERC20[]", 40 | "name": "tokens", 41 | "type": "address[]" 42 | }, 43 | { 44 | "internalType": "uint256[]", 45 | "name": "weights", 46 | "type": "uint256[]" 47 | }, 48 | { 49 | "internalType": "uint256", 50 | "name": "swapFeePercentage", 51 | "type": "uint256" 52 | }, 53 | { 54 | "internalType": "bool", 55 | "name": "oracleEnabled", 56 | "type": "bool" 57 | }, 58 | { 59 | "internalType": "address", 60 | "name": "owner", 61 | "type": "address" 62 | } 63 | ], 64 | "name": "create", 65 | "outputs": [ 66 | { 67 | "internalType": "address", 68 | "name": "", 69 | "type": "address" 70 | } 71 | ], 72 | "stateMutability": "nonpayable", 73 | "type": "function" 74 | }, 75 | { 76 | "inputs": [], 77 | "name": "getPauseConfiguration", 78 | "outputs": [ 79 | { 80 | "internalType": "uint256", 81 | "name": "pauseWindowDuration", 82 | "type": "uint256" 83 | }, 84 | { 85 | "internalType": "uint256", 86 | "name": "bufferPeriodDuration", 87 | "type": "uint256" 88 | } 89 | ], 90 | "stateMutability": "view", 91 | "type": "function" 92 | }, 93 | { 94 | "inputs": [], 95 | "name": "getVault", 96 | "outputs": [ 97 | { 98 | "internalType": "contract IVault", 99 | "name": "", 100 | "type": "address" 101 | } 102 | ], 103 | "stateMutability": "view", 104 | "type": "function" 105 | }, 106 | { 107 | "inputs": [ 108 | { 109 | "internalType": "address", 110 | "name": "pool", 111 | "type": "address" 112 | } 113 | ], 114 | "name": "isPoolFromFactory", 115 | "outputs": [ 116 | { 117 | "internalType": "bool", 118 | "name": "", 119 | "type": "bool" 120 | } 121 | ], 122 | "stateMutability": "view", 123 | "type": "function" 124 | } 125 | ] 126 | -------------------------------------------------------------------------------- /balancer-v2/abis/WeightedPoolFactory.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [ 4 | { 5 | "internalType": "contract IVault", 6 | "name": "vault", 7 | "type": "address" 8 | } 9 | ], 10 | "stateMutability": "nonpayable", 11 | "type": "constructor" 12 | }, 13 | { 14 | "anonymous": false, 15 | "inputs": [ 16 | { 17 | "indexed": true, 18 | "internalType": "address", 19 | "name": "pool", 20 | "type": "address" 21 | } 22 | ], 23 | "name": "PoolCreated", 24 | "type": "event" 25 | }, 26 | { 27 | "inputs": [ 28 | { 29 | "internalType": "string", 30 | "name": "name", 31 | "type": "string" 32 | }, 33 | { 34 | "internalType": "string", 35 | "name": "symbol", 36 | "type": "string" 37 | }, 38 | { 39 | "internalType": "contract IERC20[]", 40 | "name": "tokens", 41 | "type": "address[]" 42 | }, 43 | { 44 | "internalType": "uint256[]", 45 | "name": "weights", 46 | "type": "uint256[]" 47 | }, 48 | { 49 | "internalType": "uint256", 50 | "name": "swapFeePercentage", 51 | "type": "uint256" 52 | }, 53 | { 54 | "internalType": "address", 55 | "name": "owner", 56 | "type": "address" 57 | } 58 | ], 59 | "name": "create", 60 | "outputs": [ 61 | { 62 | "internalType": "address", 63 | "name": "", 64 | "type": "address" 65 | } 66 | ], 67 | "stateMutability": "nonpayable", 68 | "type": "function" 69 | }, 70 | { 71 | "inputs": [], 72 | "name": "getPauseConfiguration", 73 | "outputs": [ 74 | { 75 | "internalType": "uint256", 76 | "name": "pauseWindowDuration", 77 | "type": "uint256" 78 | }, 79 | { 80 | "internalType": "uint256", 81 | "name": "bufferPeriodDuration", 82 | "type": "uint256" 83 | } 84 | ], 85 | "stateMutability": "view", 86 | "type": "function" 87 | }, 88 | { 89 | "inputs": [], 90 | "name": "getVault", 91 | "outputs": [ 92 | { 93 | "internalType": "contract IVault", 94 | "name": "", 95 | "type": "address" 96 | } 97 | ], 98 | "stateMutability": "view", 99 | "type": "function" 100 | }, 101 | { 102 | "inputs": [ 103 | { 104 | "internalType": "address", 105 | "name": "pool", 106 | "type": "address" 107 | } 108 | ], 109 | "name": "isPoolFromFactory", 110 | "outputs": [ 111 | { 112 | "internalType": "bool", 113 | "name": "", 114 | "type": "bool" 115 | } 116 | ], 117 | "stateMutability": "view", 118 | "type": "function" 119 | } 120 | ] 121 | -------------------------------------------------------------------------------- /balancer-v2/config/arbitrum.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "arbitrum-one", 3 | "vaultAddress": "0xBA12222222228d8Ba445958a75a0704d566BF2C8", 4 | "vaultStartBlock": 222832, 5 | "weightedPoolFactoryAddress": "0x7dFdEF5f355096603419239CE743BfaF1120312B", 6 | "weightedPoolFactoryStartBlock": 222863, 7 | "weightedPool2TokensFactoryAddress": "0xCF0a32Bbef8F064969F21f7e02328FB577382018", 8 | "weightedPool2TokensFactoryStartBlock": 222864, 9 | "investmentPoolFactoryAddress": "0xaCd615B3705B9c880E4E7293f1030B34e57B4c1c", 10 | "investmentPoolFactoryStartBlock": 1488052, 11 | "metastablePoolFactoryAddress": "0xEBFD5681977E38Af65A7487DC70B8221D089cCAD", 12 | "metastablePoolFactoryStartBlock": 222868, 13 | "stablePoolFactoryAddress": "0x2433477A10FC5d31B9513C638F19eE85CaED53Fd", 14 | "stablePoolFactoryStartBlock": 222866 15 | } 16 | -------------------------------------------------------------------------------- /balancer-v2/config/mainnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "mainnet", 3 | "vaultAddress": "0xBA12222222228d8Ba445958a75a0704d566BF2C8", 4 | "vaultStartBlock": 12272146, 5 | "weightedPoolFactoryAddress": "0x8E9aa87E45e92bad84D5F8DD1bff34Fb92637dE9", 6 | "weightedPoolFactoryStartBlock": 12272147, 7 | "weightedPool2TokensFactoryAddress": "0xA5bf2ddF098bb0Ef6d120C98217dD6B141c74EE0", 8 | "weightedPool2TokensFactoryStartBlock": 12349891, 9 | "investmentPoolFactoryAddress": "0x48767F9F868a4A7b86A90736632F6E44C2df7fa9", 10 | "investmentPoolFactoryStartBlock": 13279079, 11 | "liquidityBootstrappingPoolFactoryAddress": "0x751A0bC0e3f75b38e01Cf25bFCE7fF36DE1C87DE", 12 | "liquidityBootstrappingPoolFactoryStartBlock": 12871780, 13 | "noProtocolFeeLiquidityBootstrappingPoolFactoryAddress": "0x0F3e0c4218b7b0108a3643cFe9D3ec0d4F57c54e", 14 | "noProtocolFeeLiquidityBootstrappingPoolFactoryStartBlock": 13730248, 15 | "metastablePoolFactoryAddress": "0x67d27634E44793fE63c467035E31ea8635117cd4", 16 | "metastablePoolFactoryStartBlock": 13011941, 17 | "stablePoolFactoryAddress": "0xc66Ba2B6595D3613CCab350C886aCE23866EDe24", 18 | "stablePoolFactoryStartBlock": 12703127 19 | } 20 | -------------------------------------------------------------------------------- /balancer-v2/config/polygon.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "matic", 3 | "vaultAddress": "0xBA12222222228d8Ba445958a75a0704d566BF2C8", 4 | "vaultStartBlock": 15832990, 5 | "weightedPoolFactoryAddress": "0x8E9aa87E45e92bad84D5F8DD1bff34Fb92637dE9", 6 | "weightedPoolFactoryStartBlock": 15832998, 7 | "weightedPool2TokensFactoryAddress": "0xA5bf2ddF098bb0Ef6d120C98217dD6B141c74EE0", 8 | "weightedPool2TokensFactoryStartBlock": 15869090, 9 | "investmentPoolFactoryAddress": "0x0f7bb7ce7b6ed9366F9b6B910AdeFE72dC538193", 10 | "investmentPoolFactoryStartBlock": 19404118, 11 | "noProtocolFeeLiquidityBootstrappingPoolFactoryAddress": "0x41B953164995c11C81DA73D212ED8Af25741b7Ac", 12 | "noProtocolFeeLiquidityBootstrappingPoolFactoryStartBlock": 22067480, 13 | "metastablePoolFactoryAddress": "0xdAE7e32ADc5d490a43cCba1f0c736033F2b4eFca", 14 | "metastablePoolFactoryStartBlock": 17913016, 15 | "stablePoolFactoryAddress": "0xc66Ba2B6595D3613CCab350C886aCE23866EDe24", 16 | "stablePoolFactoryStartBlock": 16138680 17 | } 18 | -------------------------------------------------------------------------------- /balancer-v2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simplefi-balancer-v2", 3 | "license": "UNLICENSED", 4 | "scripts": { 5 | "codegen": "graph codegen", 6 | "build": "graph build", 7 | "clean": "rm -rf ./build && rm -rf ./generated && rm subgraph.yaml", 8 | "prepare-mainnet": "mustache ./config/mainnet.json subgraph.template.yaml > subgraph.yaml && npm run codegen", 9 | "prepare-polygon": "mustache ./config/polygon.json subgraph.template.yaml > subgraph.yaml && npm run codegen", 10 | "prepare-arbitrum": "mustache ./config/arbitrum.json subgraph.template.yaml > subgraph.yaml && npm run codegen", 11 | "deploy-mainnet": "npm run prepare-mainnet && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/balancer-v2", 12 | "deploy-polygon": "npm run prepare-polygon && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/balancer-v2-polygon", 13 | "deploy-arbitrum": "npm run prepare-arbitrum && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/balancer-v2-arbitrum", 14 | "deploy-all": "npm run clean && npm run deploy-mainnet && npm run clean && npm run deploy-polygon && npm run clean && npm run deploy-arbitrum", 15 | "create-local": "graph create --node http://localhost:8020/ simplefi-finance/balancer-v2", 16 | "remove-local": "graph remove --node http://localhost:8020/ simplefi-finance/balancer-v2", 17 | "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 simplefi-finance/balancer-v2" 18 | }, 19 | "dependencies": { 20 | "@graphprotocol/graph-cli": "0.21.1", 21 | "@graphprotocol/graph-ts": "0.20.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /balancer-v2/src/constants.ts: -------------------------------------------------------------------------------- 1 | export namespace Blockchain { 2 | export const ETHEREUM = "ETHEREUM" 3 | export const BSC = "BSC" 4 | export const XDAI = "XDAI" 5 | export const POLYGON = "POLYGON" 6 | export const OPTIMISM = "OPTIMISM" 7 | export const AVALANCHE = "AVALANCE" 8 | export const NEAR = "NEAR" 9 | } 10 | 11 | export namespace TokenStandard { 12 | export const ERC20 = "ERC20" 13 | export const ERC721 = "ERC721" 14 | export const ERC1155 = "ERC1155" 15 | } 16 | 17 | export namespace ProtocolName { 18 | export const UNISWAP_V2 = "UNISWAP_V2" 19 | export const BALANCER_V2 = "BALANCER_V2" 20 | } 21 | 22 | export namespace ProtocolType { 23 | export const STAKING = "STAKING" 24 | export const LENDING = "LENDING" 25 | export const EXCHANGE = "EXCHANGE" 26 | export const INSURANCE = "INSURANCE" 27 | export const STABLECOIN = "STABLECOIN" 28 | export const DERIVATIVE = "DERIVATIVE" 29 | export const SYNTHETIC_TOKEN = "SYNTHETIC_TOKEN" 30 | export const TOKEN_MANAGEMENT = "TOKEN_MANAGEMENT" 31 | export const PREDICTION_MARKET = "PREDICTION_MARKET" 32 | } 33 | 34 | export namespace PositionType { 35 | export const INVESTMENT = "INVESTMENT" 36 | export const DEBT = "DEBT" 37 | } 38 | 39 | export namespace TransactionType { 40 | export const INVEST = "INVEST" 41 | export const REDEEM = "REDEEM" 42 | export const BORROW = "BORROW" 43 | export const REPAY = "REPAY" 44 | export const TRANSFER_IN = "TRANSFER_IN" 45 | export const TRANSFER_OUT = "TRANSFER_OUT" 46 | } 47 | 48 | export namespace PoolSpecialization { 49 | export const GENERAL = "GENERAL" 50 | export const MINIMAL_SWAP_INFO = "MINIMAL_SWAP_INFO" 51 | export const TWO_TOKEN = "TWO_TOKEN" 52 | } 53 | 54 | export namespace PoolType { 55 | export const WEIGHTED_POOL = "WEIGHTED_POOL" 56 | export const WEIGHTED_POOL_2_TOKENS = "WEIGHTED_POOL_2_TOKENS" 57 | export const STABLE_POOL = "STABLE_POOL" 58 | export const METASTABLE_POOL = "METASTABLE_POOL" 59 | export const LIQUIDITY_BOOTSTRAPPING_POOL = "LIQUIDITY_BOOTSTRAPPING_POOL" 60 | export const INVESTMENT_POOL = "INVESTMENT_POOL" 61 | } 62 | -------------------------------------------------------------------------------- /balancer-v2/src/investmentPoolFactory.ts: -------------------------------------------------------------------------------- 1 | import { PoolType } from "./constants" 2 | import { Pool, PoolId } from "../generated/schema" 3 | import { InvestmentPool } from "../generated/templates" 4 | import { PoolCreated } from "../generated/InvestmentPoolFactory/InvestmentPoolFactory" 5 | import { getOrCreateAccount } from "./common" 6 | 7 | export function handlePoolCreated(event: PoolCreated): void { 8 | let poolId = PoolId.load(event.params.pool.toHexString()) 9 | let pool = Pool.load(poolId.poolId) 10 | 11 | pool.factory = getOrCreateAccount(event.address).id 12 | pool.poolType = PoolType.INVESTMENT_POOL 13 | pool.save() 14 | 15 | InvestmentPool.create(event.params.pool) 16 | } 17 | -------------------------------------------------------------------------------- /balancer-v2/src/liquidityBootstrappingPoolFactory.ts: -------------------------------------------------------------------------------- 1 | import { PoolType } from "./constants" 2 | import { Pool, PoolId } from "../generated/schema" 3 | import { LiquidityBootstrappingPool } from "../generated/templates" 4 | import { PoolCreated } from "../generated/LiquidityBootstrappingPoolFactory/LiquidityBootstrappingPoolFactory" 5 | import { getOrCreateAccount } from "./common" 6 | 7 | export function handlePoolCreated(event: PoolCreated): void { 8 | let poolId = PoolId.load(event.params.pool.toHexString()) 9 | let pool = Pool.load(poolId.poolId) 10 | 11 | pool.factory = getOrCreateAccount(event.address).id 12 | pool.poolType = PoolType.LIQUIDITY_BOOTSTRAPPING_POOL 13 | pool.save() 14 | 15 | LiquidityBootstrappingPool.create(event.params.pool) 16 | } 17 | -------------------------------------------------------------------------------- /balancer-v2/src/metastablePoolFactory.ts: -------------------------------------------------------------------------------- 1 | import { PoolType } from "./constants" 2 | import { Pool, PoolId } from "../generated/schema" 3 | import { MetastablePool } from "../generated/templates" 4 | import { PoolCreated } from "../generated/MetastablePoolFactory/MetastablePoolFactory" 5 | import { getOrCreateAccount } from "./common" 6 | 7 | export function handlePoolCreated(event: PoolCreated): void { 8 | let poolId = PoolId.load(event.params.pool.toHexString()) 9 | let pool = Pool.load(poolId.poolId) 10 | 11 | pool.factory = getOrCreateAccount(event.address).id 12 | pool.poolType = PoolType.LIQUIDITY_BOOTSTRAPPING_POOL 13 | pool.save() 14 | 15 | MetastablePool.create(event.params.pool) 16 | } 17 | -------------------------------------------------------------------------------- /balancer-v2/src/noProtocolFeeLiquidityBootstrappingPoolFactory.ts: -------------------------------------------------------------------------------- 1 | import { PoolType } from "./constants" 2 | import { Pool, PoolId } from "../generated/schema" 3 | import { LiquidityBootstrappingPool } from "../generated/templates" 4 | import { PoolCreated } from "../generated/NoProtocolFeeLiquidityBootstrappingPoolFactory/LiquidityBootstrappingPoolFactory" 5 | import { getOrCreateAccount } from "./common" 6 | 7 | export function handlePoolCreated(event: PoolCreated): void { 8 | let poolId = PoolId.load(event.params.pool.toHexString()) 9 | let pool = Pool.load(poolId.poolId) 10 | 11 | pool.factory = getOrCreateAccount(event.address).id 12 | pool.poolType = PoolType.LIQUIDITY_BOOTSTRAPPING_POOL 13 | pool.save() 14 | 15 | LiquidityBootstrappingPool.create(event.params.pool) 16 | } 17 | -------------------------------------------------------------------------------- /balancer-v2/src/stablePoolFactory.ts: -------------------------------------------------------------------------------- 1 | import { PoolType } from "./constants" 2 | import { Pool, PoolId } from "../generated/schema" 3 | import { StablePool } from "../generated/templates" 4 | import { PoolCreated } from "../generated/StablePoolFactory/StablePoolFactory" 5 | import { getOrCreateAccount } from "./common" 6 | 7 | export function handlePoolCreated(event: PoolCreated): void { 8 | let poolId = PoolId.load(event.params.pool.toHexString()) 9 | let pool = Pool.load(poolId.poolId) 10 | 11 | pool.factory = getOrCreateAccount(event.address).id 12 | pool.poolType = PoolType.LIQUIDITY_BOOTSTRAPPING_POOL 13 | pool.save() 14 | 15 | StablePool.create(event.params.pool) 16 | } 17 | -------------------------------------------------------------------------------- /balancer-v2/src/weightedPool2TokensFactory.ts: -------------------------------------------------------------------------------- 1 | import { PoolType } from "./constants" 2 | import { Pool, PoolId } from "../generated/schema" 3 | import { WeightedPool2Tokens } from "../generated/templates" 4 | import { PoolCreated } from "../generated/WeightedPool2TokensFactory/WeightedPool2TokensFactory" 5 | import { getOrCreateAccount } from "./common" 6 | 7 | export function handlePoolCreated(event: PoolCreated): void { 8 | let poolId = PoolId.load(event.params.pool.toHexString()) 9 | let pool = Pool.load(poolId.poolId) 10 | 11 | pool.factory = getOrCreateAccount(event.address).id 12 | pool.poolType = PoolType.WEIGHTED_POOL_2_TOKENS 13 | pool.save() 14 | 15 | WeightedPool2Tokens.create(event.params.pool) 16 | } 17 | -------------------------------------------------------------------------------- /balancer-v2/src/weightedPoolFactory.ts: -------------------------------------------------------------------------------- 1 | import { PoolType } from "./constants" 2 | import { Pool, PoolId } from "../generated/schema" 3 | import { WeightedPool } from "../generated/templates" 4 | import { PoolCreated } from "../generated/WeightedPoolFactory/WeightedPoolFactory" 5 | import { getOrCreateAccount } from "./common" 6 | 7 | export function handlePoolCreated(event: PoolCreated): void { 8 | let poolId = PoolId.load(event.params.pool.toHexString()) 9 | let pool = Pool.load(poolId.poolId) 10 | 11 | pool.factory = getOrCreateAccount(event.address).id 12 | pool.poolType = PoolType.WEIGHTED_POOL 13 | pool.save() 14 | 15 | WeightedPool.create(event.params.pool) 16 | } 17 | -------------------------------------------------------------------------------- /compound/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | package-lock.json 107 | 108 | build/ 109 | generated/ 110 | -------------------------------------------------------------------------------- /compound/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simplefi-compound", 3 | "license": "UNLICENSED", 4 | "scripts": { 5 | "codegen": "graph codegen", 6 | "build": "graph build", 7 | "deploy": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/compound", 8 | "create-local": "graph create --node http://localhost:8020/ simplefi-finance/compound", 9 | "remove-local": "graph remove --node http://localhost:8020/ simplefi-finance/compound", 10 | "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 simplefi-finance/compound" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/SimpleFi-finance/subgraphs.git" 15 | }, 16 | "author": "SimpleFi", 17 | "bugs": { 18 | "url": "https://github.com/SimpleFi-finance/subgraphs.git/issues" 19 | }, 20 | "homepage": "https://docs.simplefi.finance/subgraph-development-documentation", 21 | "dependencies": { 22 | "@graphprotocol/graph-cli": "0.24.0", 23 | "@graphprotocol/graph-ts": "0.24.0" 24 | } 25 | } -------------------------------------------------------------------------------- /curve-exchange/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | package-lock.json 107 | 108 | build/ 109 | generated/ 110 | -------------------------------------------------------------------------------- /curve-exchange/README.md: -------------------------------------------------------------------------------- 1 | # Curve Positions 2 | 3 | ## Usecase 4 | 5 | This subgraph is used track invstments of liquidity providers in Curve pools. In this subgraph we track all the positions ever taken by an account. How this position changes over time. 6 | 7 | ## Pool Types 8 | 9 | LP token of pool - pool.lp_token - it may be private in old pools 10 | 11 | ### Base Pool 12 | 13 | - StableSwap.coins(i: uint256) → address: view 14 | - StableSwap.balances(i: uint256) → uint256: view 15 | - StableSwap.lp_token() → address: view 16 | 17 | ### Lending Pool 18 | 19 | Implementation of lending pools may differ with respect to how wrapped tokens accrue interest. There are two main types of wrapped tokens that are used by lending pools: 20 | 21 | - cToken-style tokens: These are tokens, such as interest-bearing cTokens on Compound (e.g., cDAI) or on yTokens on Yearn, where interest accrues as the rate of the token increases. 22 | 23 | - aToken-style tokens: These are tokens, such as aTokens on AAVE (e.g., aDAI), where interest accrues as the balance of the token increases. 24 | 25 | #### Methods 26 | 27 | - StableSwap.underlying_coins(i: uint256) → address: view 28 | 29 | ### Metapool 30 | 31 | A metapool is a pool where a stablecoin is paired against the LP token from another pool, a so-called base pool. 32 | 33 | - StableSwap.base_coins(i: uint256) → address: view 34 | - StableSwap.coins(i: uint256) → address: view 35 | - StableSwap.base_pool() → address: view 36 | 37 | ## LP Tokens 38 | 39 | The following versions of Curve pool LP tokens exist: 40 | 41 | - CurveTokenV1: LP token targetting Vyper ^0.1.0-beta.16 42 | - CurveTokenV2: LP token targetting Vyper ^0.2.0 43 | - CurveTokenV3: LP token targetting Vyper ^0.2.0 with gas optimizations 44 | 45 | ## Events 46 | 47 | ### Add Liquidity 48 | 49 | - Transfer(zero_address, to, value) 50 | - AddLiquidity(provider: indexed(address), token_amounts: uint256[N_COINS], fees: uint256[N_COINS], invariant: uint256, token_supply: uint256) 51 | 52 | ### Remove Liquidity 53 | 54 | - Transfer(to, zero, value) 55 | - RemoveLiquidity(provider: indexed(address), token_amounts: uint256[N_COINS], fees: uint256[N_COINS], token_supply: uint256) 56 | - RemoveLiquidityImbalance(provider: indexed(address), token_amounts: uint256[N_COINS], fees: uint256[N_COINS], invariant: uint256, token_supply: uint256) 57 | - RemoveLiquidityOne(provider: indexed(address), token_amount: uint256, coin_amount: uint256) 58 | 59 | ### Exchange 60 | 61 | - TokenExchange(buyer: indexed(address), sold_id: int128, tokens_sold: uint256, bought_id: int128, tokens_bought: uint256) 62 | 63 | ### Change Fee 64 | 65 | We need to track fee so that we can track balances 66 | 67 | - NewFee(fee: uint256, admin_fee: uint256) 68 | - NewParameters(A: uint256, fee: uint256, admin_fee: uint256) 69 | -------------------------------------------------------------------------------- /curve-exchange/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simplefi-curve-exchange", 3 | "license": "UNLICENSED", 4 | "scripts": { 5 | "codegen": "graph codegen", 6 | "build": "graph build", 7 | "prepare-curve-arbitrum": "cp templates/constants.arbitrum.ts src/constants.ts && cp templates/subgraph.arbitrum.yaml subgraph.yaml && npm run codegen", 8 | "prepare-curve-avalanche": "cp templates/constants.avalanche.ts src/constants.ts && cp templates/subgraph.avalanche.yaml subgraph.yaml && npm run codegen", 9 | "prepare-curve-fantom": "cp templates/constants.fantom.ts src/constants.ts && cp templates/subgraph.fantom.yaml subgraph.yaml && npm run codegen", 10 | "prepare-curve-gnosis": "cp templates/constants.gnosis.ts src/constants.ts && cp templates/subgraph.gnosis.yaml subgraph.yaml && npm run codegen", 11 | "prepare-curve-mainnet": "cp templates/constants.mainnet.ts src/constants.ts && cp templates/subgraph.mainnet.yaml subgraph.yaml && npm run codegen", 12 | "prepare-curve-optimism": "cp templates/constants.optimism.ts src/constants.ts && cp templates/subgraph.optimism.yaml subgraph.yaml && npm run codegen", 13 | "prepare-curve-polygon": "cp templates/constants.polygon.ts src/constants.ts && cp templates/subgraph.polygon.yaml subgraph.yaml && npm run codegen", 14 | "deploy-curve-arbitrum": "npm run clean && npm run prepare-curve-arbitrum && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/curve-arbitrum", 15 | "deploy-curve-avalanche": "npm run clean && npm run prepare-curve-avalanche && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/curve-avalanche", 16 | "deploy-curve-fantom": "npm run clean && npm run prepare-curve-fantom && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/curve-fantom", 17 | "deploy-curve-gnosis": "npm run clean && npm run prepare-curve-gnosis && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/curve-gnosis", 18 | "deploy-curve-mainnet": "npm run clean && npm run prepare-curve-mainnet && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/curve", 19 | "deploy-curve-optimism": "npm run clean && npm run prepare-curve-optimism && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/curve-optimism", 20 | "deploy-curve-polygon": "npm run clean && npm run prepare-curve-polygon && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/curve-polygon", 21 | "deploy-debug": "npm run clean && npm run prepare-curve-mainnet && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ gvladika/debug-curve", 22 | "create-local": "graph create --node http://localhost:8020/ simplefi-finance/curve-exchange", 23 | "remove-local": "graph remove --node http://localhost:8020/ simplefi-finance/curve-exchange", 24 | "deploy-local": "npm run clean && npm run prepare-curve-mainnet && graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 simplefi-finance/curve-exchange", 25 | "clean": "rm -rf ./build && rm -rf ./generated" 26 | }, 27 | "dependencies": { 28 | "@graphprotocol/graph-cli": "0.20.0", 29 | "@graphprotocol/graph-ts": "0.20.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /curve-exchange/src/addressProvider.ts: -------------------------------------------------------------------------------- 1 | import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts"; 2 | import { 3 | AddressModified, 4 | NewAddressIdentifier, 5 | } from "../generated/CurveExchangeAddressProvider/AddressProvider"; 6 | 7 | import { PoolRegistry, AddressProvider, MetaPoolFactory } from "../generated/schema"; 8 | 9 | import { MetaPoolFactory as FactoryContract } from "../generated/templates/MetaPoolFactory/MetaPoolFactory"; 10 | 11 | import { 12 | PoolRegistry as PoolRegistryTemplate, 13 | MetaPoolFactory as MetaPoolFactoryTemplate, 14 | } from "../generated/templates"; 15 | 16 | const REGISTRY_ID = 0; 17 | const METAPOOL_FACTORY_ID = 3; 18 | 19 | export function handleAddressModified(event: AddressModified): void { 20 | let id = event.params.id; 21 | let newAddress = event.params.new_address; 22 | addNewSource(event, id, newAddress); 23 | } 24 | 25 | export function handleNewAddressIdentifier(event: NewAddressIdentifier): void { 26 | let id = event.params.id; 27 | let newAddress = event.params.addr; 28 | addNewSource(event, id, newAddress); 29 | } 30 | 31 | /** 32 | * Add new registry or metapool factory 33 | * @param event 34 | * @param id 35 | * @param newAddress 36 | */ 37 | function addNewSource(event: ethereum.Event, id: BigInt, newAddress: Address): void { 38 | let addressProvider = AddressProvider.load(event.address.toHexString()); 39 | 40 | if (addressProvider == null) { 41 | addressProvider = new AddressProvider(event.address.toHexString()); 42 | addressProvider.save(); 43 | } 44 | 45 | // create registry entity 46 | if (id == BigInt.fromI32(REGISTRY_ID)) { 47 | let poolRegistry = PoolRegistry.load(newAddress.toHexString()); 48 | if (poolRegistry == null) { 49 | poolRegistry = new PoolRegistry(newAddress.toHexString()); 50 | poolRegistry.save(); 51 | 52 | // don't use this address as that registry is not functioning 53 | if (poolRegistry.id.toLowerCase() != "0xe2470c5e330a34d706f93d50658ba52d18512f7a") { 54 | addressProvider.registry = poolRegistry.id; 55 | addressProvider.save(); 56 | } 57 | 58 | // start indexing registry 59 | PoolRegistryTemplate.create(newAddress); 60 | } 61 | } else if (id == BigInt.fromI32(METAPOOL_FACTORY_ID)) { 62 | // 3 == metapool factory 63 | let metapoolFactory = MetaPoolFactory.load(newAddress.toHexString()); 64 | if (metapoolFactory == null) { 65 | metapoolFactory = new MetaPoolFactory(newAddress.toHexString()); 66 | // fetch pool count from the contract (might not be 0 if we learned about factory only when it was added to AddressProvider) 67 | metapoolFactory.poolCount = FactoryContract.bind(newAddress).pool_count(); 68 | metapoolFactory.save(); 69 | 70 | // start indexing metapool factory 71 | MetaPoolFactoryTemplate.create(newAddress); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /curve-exchange/src/metaPoolFactory.ts: -------------------------------------------------------------------------------- 1 | import { BigInt, log } from "@graphprotocol/graph-ts"; 2 | import { 3 | Add_existing_metapoolsCall, 4 | MetaPoolFactory as MetaPoolFactoryContract, 5 | PlainPoolDeployed, 6 | } from "../generated/templates/MetaPoolFactory/MetaPoolFactory"; 7 | import { MetaPoolDeployed } from "../generated/templates/MetaPoolFactory/MetaPoolFactory"; 8 | import { ADDRESS_ZERO } from "./common"; 9 | import { getOrCreateMetaPoolFactory, getOrCreatePoolViaFactory } from "./curveUtil"; 10 | 11 | export function handleMetaPoolDeployedEvent(event: MetaPoolDeployed): void { 12 | let factory = getOrCreateMetaPoolFactory(event.address); 13 | 14 | // fetch contract address of new pool from the contract 15 | let newCurvePoolAddress = MetaPoolFactoryContract.bind(event.address).pool_list( 16 | factory.poolCount 17 | ); 18 | 19 | // ++poolCount 20 | factory.poolCount = factory.poolCount.plus(BigInt.fromI32(1)); 21 | factory.save(); 22 | 23 | // create new pool 24 | getOrCreatePoolViaFactory(event, newCurvePoolAddress, event.address); 25 | } 26 | 27 | export function handlePlainPoolDeployedEvent(event: PlainPoolDeployed): void { 28 | let factory = getOrCreateMetaPoolFactory(event.address); 29 | 30 | // fetch contract address of new pool from the contract 31 | let newCurvePoolAddress = MetaPoolFactoryContract.bind(event.address).pool_list( 32 | factory.poolCount 33 | ); 34 | 35 | // ++poolCount 36 | factory.poolCount = factory.poolCount.plus(BigInt.fromI32(1)); 37 | factory.save(); 38 | 39 | // create new pool 40 | getOrCreatePoolViaFactory(event, newCurvePoolAddress, event.address); 41 | } 42 | 43 | export function handleAddExistingMetapoolCall(call: Add_existing_metapoolsCall): void { 44 | let factory = getOrCreateMetaPoolFactory(call.to); 45 | 46 | // increase pool counter by the number of pools added 47 | let pools = call.inputs._pools; 48 | let newPoolCounter = 0; 49 | 50 | for (let i = 0; i < pools.length; i++) { 51 | if (pools[i].toHexString() == ADDRESS_ZERO) { 52 | break; 53 | } 54 | newPoolCounter++; 55 | } 56 | 57 | factory.poolCount = factory.poolCount.plus(BigInt.fromI32(newPoolCounter)); 58 | factory.save(); 59 | } 60 | -------------------------------------------------------------------------------- /curve-exchange/src/poolRegistry.ts: -------------------------------------------------------------------------------- 1 | import { Pool } from "../generated/schema"; 2 | import { PoolAdded, PoolRemoved } from "../generated/templates/PoolRegistry/PoolRegistry"; 3 | import { getOrCreatePoolViaRegistry } from "./curveUtil"; 4 | 5 | /** 6 | * Create pool entity if there is no already one, add registry reference 7 | * @param event 8 | */ 9 | export function handlePoolAdded(event: PoolAdded): void { 10 | let curvePoolAddress = event.params.pool; 11 | let pool = getOrCreatePoolViaRegistry(event, curvePoolAddress, event.address); 12 | 13 | if (!pool.isInRegistry) { 14 | pool.isInRegistry = true; 15 | pool.registry = event.address.toHexString(); 16 | pool.save(); 17 | } 18 | } 19 | 20 | /** 21 | * Remove registry ref from pool entity 22 | * @param event 23 | * @returns 24 | */ 25 | export function handlePoolRemoved(event: PoolRemoved): void { 26 | let curvePoolAddress = event.params.pool; 27 | let pool = Pool.load(curvePoolAddress.toHexString()); 28 | 29 | if (pool == null) { 30 | return; 31 | } 32 | 33 | // remove registry ref 34 | if (pool.isInRegistry) { 35 | pool.isInRegistry = false; 36 | pool.registry = null; 37 | pool.save(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /curve-exchange/templates/constants.gnosis.ts: -------------------------------------------------------------------------------- 1 | import { TypedMap } from "@graphprotocol/graph-ts"; 2 | 3 | export namespace Blockchain { 4 | export const ETHEREUM = "ETHEREUM"; 5 | export const BSC = "BSC"; 6 | export const XDAI = "XDAI"; 7 | export const ARBITRUM = "ARBITRUM"; 8 | export const OPTIMISM = "OPTIMISM"; 9 | export const AVALANCHE = "AVALANCE"; 10 | export const NEAR = "NEAR"; 11 | } 12 | 13 | export namespace TokenStandard { 14 | export const ERC20 = "ERC20"; 15 | export const ERC721 = "ERC721"; 16 | export const ERC1155 = "ERC1155"; 17 | } 18 | 19 | export namespace ProtocolName { 20 | export const UNISWAP_V2 = "UNISWAP_V2"; 21 | export const CURVE_POOL = "CURVE_POOL"; 22 | } 23 | 24 | export namespace ProtocolType { 25 | export const STAKING = "STAKING"; 26 | export const LENDING = "LENDING"; 27 | export const EXCHANGE = "EXCHANGE"; 28 | export const INSURANCE = "INSURANCE"; 29 | export const STABLECOIN = "STABLECOIN"; 30 | export const DERIVATIVE = "DERIVATIVE"; 31 | export const SYNTHETIC_TOKEN = "SYNTHETIC_TOKEN"; 32 | export const TOKEN_MANAGEMENT = "TOKEN_MANAGEMENT"; 33 | export const PREDICTION_MARKET = "PREDICTION_MARKET"; 34 | } 35 | 36 | export namespace PositionType { 37 | export const INVESTMENT = "INVESTMENT"; 38 | export const DEBT = "DEBT"; 39 | } 40 | 41 | export namespace TransactionType { 42 | export const INVEST = "INVEST"; 43 | export const REDEEM = "REDEEM"; 44 | export const BORROW = "BORROW"; 45 | export const REPAY = "REPAY"; 46 | export const TRANSFER_IN = "TRANSFER_IN"; 47 | export const TRANSFER_OUT = "TRANSFER_OUT"; 48 | } 49 | 50 | // for some contracts it's not possible to get LP token address or coin count 51 | // from pool contract, so static mapping is defined here 52 | export class PoolStaticInfo { 53 | poolAddress: string; 54 | lpTokenAddress: string; 55 | coinCount: i32; 56 | poolType: string; 57 | is_v1: boolean; 58 | rewardTokens: string[]; 59 | 60 | constructor( 61 | poolAddress: string, 62 | lpTokenAddress: string, 63 | coinCount: i32, 64 | poolType: string, 65 | is_v1: boolean, 66 | rewardTokens: string[] 67 | ) { 68 | this.poolAddress = poolAddress; 69 | this.lpTokenAddress = lpTokenAddress; 70 | this.coinCount = coinCount; 71 | this.poolType = poolType; 72 | this.is_v1 = is_v1; 73 | this.rewardTokens = rewardTokens; 74 | } 75 | } 76 | 77 | ///////////////////////////////// 78 | 79 | //// GNOSIS 80 | 81 | ///////////////////////////////// 82 | export let addressToPool = new TypedMap(); 83 | export let lpTokenToPool = new TypedMap(); 84 | 85 | // 3pool 86 | export const TRI_POOL_GNOSIS = "0x7f90122bf0700f9e7e1f688fe926940e8839f353"; 87 | export const TRI_GNOSIS_LP_TOKEN = "0x1337bedc9d22ecbe766df105c9623922a27963ec"; 88 | addressToPool.set( 89 | TRI_POOL_GNOSIS, 90 | new PoolStaticInfo(TRI_POOL_GNOSIS, TRI_GNOSIS_LP_TOKEN, 3, "PLAIN", false, []) 91 | ); 92 | lpTokenToPool.set(TRI_GNOSIS_LP_TOKEN, TRI_POOL_GNOSIS); 93 | 94 | // Rai 95 | export const RAI_POOL_GNOSIS = "0x85ba9dfb4a3e4541420fc75be02e2b42042d7e46"; 96 | export const RAI_GNOSIS_LP_TOKEN = "0x36390a1ae126f16c5d222cb1f2ab341dd09f2fec"; 97 | addressToPool.set( 98 | RAI_POOL_GNOSIS, 99 | new PoolStaticInfo(RAI_POOL_GNOSIS, RAI_GNOSIS_LP_TOKEN, 2, "META", false, []) 100 | ); 101 | lpTokenToPool.set(RAI_GNOSIS_LP_TOKEN, RAI_POOL_GNOSIS); 102 | -------------------------------------------------------------------------------- /curve-exchange/templates/constants.optimism.ts: -------------------------------------------------------------------------------- 1 | import { TypedMap } from "@graphprotocol/graph-ts"; 2 | 3 | export namespace Blockchain { 4 | export const ETHEREUM = "ETHEREUM"; 5 | export const BSC = "BSC"; 6 | export const XDAI = "XDAI"; 7 | export const ARBITRUM = "ARBITRUM"; 8 | export const OPTIMISM = "OPTIMISM"; 9 | export const AVALANCHE = "AVALANCE"; 10 | export const NEAR = "NEAR"; 11 | } 12 | 13 | export namespace TokenStandard { 14 | export const ERC20 = "ERC20"; 15 | export const ERC721 = "ERC721"; 16 | export const ERC1155 = "ERC1155"; 17 | } 18 | 19 | export namespace ProtocolName { 20 | export const UNISWAP_V2 = "UNISWAP_V2"; 21 | export const CURVE_POOL = "CURVE_POOL"; 22 | } 23 | 24 | export namespace ProtocolType { 25 | export const STAKING = "STAKING"; 26 | export const LENDING = "LENDING"; 27 | export const EXCHANGE = "EXCHANGE"; 28 | export const INSURANCE = "INSURANCE"; 29 | export const STABLECOIN = "STABLECOIN"; 30 | export const DERIVATIVE = "DERIVATIVE"; 31 | export const SYNTHETIC_TOKEN = "SYNTHETIC_TOKEN"; 32 | export const TOKEN_MANAGEMENT = "TOKEN_MANAGEMENT"; 33 | export const PREDICTION_MARKET = "PREDICTION_MARKET"; 34 | } 35 | 36 | export namespace PositionType { 37 | export const INVESTMENT = "INVESTMENT"; 38 | export const DEBT = "DEBT"; 39 | } 40 | 41 | export namespace TransactionType { 42 | export const INVEST = "INVEST"; 43 | export const REDEEM = "REDEEM"; 44 | export const BORROW = "BORROW"; 45 | export const REPAY = "REPAY"; 46 | export const TRANSFER_IN = "TRANSFER_IN"; 47 | export const TRANSFER_OUT = "TRANSFER_OUT"; 48 | } 49 | 50 | // for some contracts it's not possible to get LP token address or coin count 51 | // from pool contract, so static mapping is defined here 52 | export class PoolStaticInfo { 53 | poolAddress: string; 54 | lpTokenAddress: string; 55 | coinCount: i32; 56 | poolType: string; 57 | is_v1: boolean; 58 | rewardTokens: string[]; 59 | 60 | constructor( 61 | poolAddress: string, 62 | lpTokenAddress: string, 63 | coinCount: i32, 64 | poolType: string, 65 | is_v1: boolean, 66 | rewardTokens: string[] 67 | ) { 68 | this.poolAddress = poolAddress; 69 | this.lpTokenAddress = lpTokenAddress; 70 | this.coinCount = coinCount; 71 | this.poolType = poolType; 72 | this.is_v1 = is_v1; 73 | this.rewardTokens = rewardTokens; 74 | } 75 | } 76 | 77 | ///////////////////////////////// 78 | 79 | //// OPTIMISM 80 | 81 | ///////////////////////////////// 82 | export let addressToPool = new TypedMap(); 83 | export let lpTokenToPool = new TypedMap(); 84 | 85 | // 3pool 86 | export const TRI_POOL_OPTIMISM = "0x1337bedc9d22ecbe766df105c9623922a27963ec"; 87 | export const TRI_OPTIMISM_LP_TOKEN = "0x1337bedc9d22ecbe766df105c9623922a27963ec"; 88 | addressToPool.set( 89 | TRI_POOL_OPTIMISM, 90 | new PoolStaticInfo(TRI_POOL_OPTIMISM, TRI_OPTIMISM_LP_TOKEN, 3, "PLAIN", false, []) 91 | ); 92 | lpTokenToPool.set(TRI_OPTIMISM_LP_TOKEN, TRI_POOL_OPTIMISM); 93 | 94 | // SUSD 95 | export const SUSD_OPTIMISM = "0x061b87122ed14b9526a813209c8a59a633257bab"; 96 | export const SUSD_OPTIMISM_LP_TOKEN = "0x061b87122ed14b9526a813209c8a59a633257bab"; 97 | addressToPool.set( 98 | SUSD_OPTIMISM, 99 | new PoolStaticInfo(SUSD_OPTIMISM, SUSD_OPTIMISM_LP_TOKEN, 2, "META", false, []) 100 | ); 101 | lpTokenToPool.set(SUSD_OPTIMISM_LP_TOKEN, SUSD_OPTIMISM); 102 | -------------------------------------------------------------------------------- /curve-gauges-multichain/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | package-lock.json 107 | 108 | build/ 109 | generated/ 110 | -------------------------------------------------------------------------------- /curve-gauges-multichain/README.md: -------------------------------------------------------------------------------- 1 | ## Curve gauges subgraphs 2 | 3 | This subgraph is used to track state of user investments in Curve gauges on non-mainnet chains. 4 | 5 | ### Docs 6 | 7 | Developer subgraph docs: 8 | https://docs.simplefi.finance/subgraph-development-documentation/dashboard-integration 9 | 10 | Common subgraph schema: 11 | https://docs.simplefi.finance/subgraph-development-documentation/common-subgraph-schema 12 | -------------------------------------------------------------------------------- /curve-gauges-multichain/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simplefi-curve-gauges-multichain", 3 | "license": "UNLICENSED", 4 | "scripts": { 5 | "codegen": "graph codegen", 6 | "build": "graph build", 7 | "clean": "rm -rf ./build && rm -rf ./generated", 8 | "prepare-arbitrum": "cp templates/subgraph.arbitrum.yaml subgraph.yaml && npm run codegen", 9 | "prepare-avalanche": "cp templates/subgraph.avalanche.yaml subgraph.yaml && npm run codegen", 10 | "prepare-fantom": "cp templates/subgraph.fantom.yaml subgraph.yaml && npm run codegen", 11 | "prepare-gnosis": "cp templates/subgraph.gnosis.yaml subgraph.yaml && npm run codegen", 12 | "prepare-optimism": "cp templates/subgraph.optimism.yaml subgraph.yaml && npm run codegen", 13 | "prepare-polygon": "cp templates/subgraph.polygon.yaml subgraph.yaml && npm run codegen", 14 | "deploy-arbitrum": "npm run clean && npm run prepare-arbitrum && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/curve-gauges-arbitrum", 15 | "deploy-avalanche": "npm run clean && npm run prepare-avalanche && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/curve-gauges-avalanche", 16 | "deploy-fantom": "npm run clean && npm run prepare-fantom && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/curve-gauges-fantom", 17 | "deploy-gnosis": "npm run clean && npm run prepare-gnosis && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/curve-gauges-gnosis", 18 | "deploy-optimism": "npm run clean && npm run prepare-optimism && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/curve-gauges-optimism", 19 | "deploy-polygon": "npm run clean && npm run prepare-polygon && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/curve-gauges-polygon", 20 | "create-local": "graph create --node http://localhost:8020/ simplefi-finance/curve-gauges", 21 | "remove-local": "graph remove --node http://localhost:8020/ simplefi-finance/curve-gauges", 22 | "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 simplefi-finance/curve-gauges" 23 | }, 24 | "dependencies": { 25 | "@graphprotocol/graph-cli": "0.20.0", 26 | "@graphprotocol/graph-ts": "0.20.0" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /curve-gauges-multichain/src/gaugeFactory.ts: -------------------------------------------------------------------------------- 1 | import { DeployedGauge } from "../generated/GaugeFactory/GaugeFactory"; 2 | import { LiquidityGauge as GaugeContract } from "../generated/templates/LiquidityGauge/LiquidityGauge"; 3 | import { getOrCreateGauge } from "./gaugeUtils"; 4 | 5 | export function handleDeployedGauge(event: DeployedGauge): void { 6 | let gaugeAddress = event.params._gauge; 7 | 8 | let gaugeContract = GaugeContract.bind(gaugeAddress); 9 | if (gaugeContract.try_lp_token().reverted) { 10 | // contracts without LP (input) token are not real gauges 11 | return; 12 | } 13 | 14 | getOrCreateGauge(event, gaugeAddress); 15 | } 16 | -------------------------------------------------------------------------------- /curve-gauges-multichain/src/metaPoolFactory.ts: -------------------------------------------------------------------------------- 1 | import { LiquidityGaugeDeployed } from "../generated/Factory/MetaPoolFactory"; 2 | import { LiquidityGauge as GaugeContract } from "../generated/templates/LiquidityGauge/LiquidityGauge"; 3 | import { getOrCreateGauge } from "./gaugeUtils"; 4 | 5 | export function handleLiquidityGaugeDeployed(event: LiquidityGaugeDeployed): void { 6 | let gaugeAddress = event.params.gauge; 7 | let pool = event.params.pool; 8 | 9 | let gaugeContract = GaugeContract.bind(gaugeAddress); 10 | if (gaugeContract.try_lp_token().reverted) { 11 | // contracts without LP (input) token are not real gauges 12 | return; 13 | } 14 | 15 | getOrCreateGauge(event, gaugeAddress); 16 | } 17 | -------------------------------------------------------------------------------- /curve-gauges/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | package-lock.json 107 | 108 | build/ 109 | generated/ 110 | -------------------------------------------------------------------------------- /curve-gauges/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simplefi-curve-gauges", 3 | "license": "UNLICENSED", 4 | "scripts": { 5 | "codegen": "graph codegen", 6 | "build": "graph build", 7 | "deploy": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/curve-gauges", 8 | "create-local": "graph create --node http://localhost:8020/ simplefi-finance/curve-gauges", 9 | "remove-local": "graph remove --node http://localhost:8020/ simplefi-finance/curve-gauges", 10 | "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 simplefi-finance/curve-gauges" 11 | }, 12 | "dependencies": { 13 | "@graphprotocol/graph-cli": "0.20.0", 14 | "@graphprotocol/graph-ts": "0.20.0" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /harvest-finance/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | package-lock.json 107 | 108 | build/ 109 | generated/ 110 | -------------------------------------------------------------------------------- /harvest-finance/README.md: -------------------------------------------------------------------------------- 1 | ## Harvest Finance subgraph 2 | 3 | https://harvest.finance 4 | 5 | This subgraph tracks user positions in Harvest vaults, reward pools and profit sharing pools. Currently only mainnet version of protocol is indexed. 6 | 7 | There are 3 types of Market entities: 8 | 9 | - HARVEST_FINANCE (vaults) 10 | - type TOKEN_MANAGEMENT 11 | - input token - underlying base token (ie. DAI) 12 | - output token - fToken (ie. fDAI) 13 | - HARVEST_FINANCE_REWARD_POOL (reward pools, every reward pools matches one vault) 14 | - type LP_FARMING 15 | - input token - fToken 16 | - output token - no actual token, but represented with reward pool address 17 | - reward token - mostly FARM token 18 | - HARVEST_FINANCE_STAKING_POOL (profit sharing pools) 19 | - type STAKING 20 | - input token - FARM 21 | - output token - no actual token, but represented with profit sharing pool address 22 | - reward token - FARM token 23 | -------------------------------------------------------------------------------- /harvest-finance/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simplefi-harvest-finance", 3 | "license": "UNLICENSED", 4 | "repository": { 5 | "type": "git", 6 | "url": "git+https://github.com/SimpleFi-finance/subgraphs.git" 7 | }, 8 | "author": "SimpleFi", 9 | "bugs": { 10 | "url": "https://github.com/SimpleFi-finance/subgraphs.git/issues" 11 | }, 12 | "scripts": { 13 | "codegen": "graph codegen", 14 | "build": "graph build", 15 | "deploy": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/harvest", 16 | "create-local": "graph create --node http://localhost:8020/ harvest-finance", 17 | "remove-local": "graph remove --node http://localhost:8020/ harvest-finance", 18 | "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 harvest-finance" 19 | }, 20 | "dependencies": { 21 | "@graphprotocol/graph-cli": "0.23.2", 22 | "@graphprotocol/graph-ts": "0.23.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /harvest-finance/src/constants.ts: -------------------------------------------------------------------------------- 1 | import { Address } from "@graphprotocol/graph-ts" 2 | 3 | export namespace Blockchain { 4 | export const ETHEREUM = "ETHEREUM" 5 | export const BSC = "BSC" 6 | export const XDAI = "XDAI" 7 | export const POLYGON = "POLYGON" 8 | export const OPTIMISM = "OPTIMISM" 9 | export const AVALANCHE = "AVALANCE" 10 | export const NEAR = "NEAR" 11 | } 12 | 13 | export namespace TokenStandard { 14 | export const ERC20 = "ERC20" 15 | export const ERC721 = "ERC721" 16 | export const ERC1155 = "ERC1155" 17 | } 18 | 19 | export namespace ProtocolName { 20 | export const HARVEST_FINANCE = "HARVEST_FINANCE" 21 | export const HARVEST_FINANCE_REWARD_POOL = "HARVEST_FINANCE_REWARD_POOL" 22 | export const HARVEST_FINANCE_STAKING_POOL = "HARVEST_FINANCE_STAKING_POOL" 23 | } 24 | 25 | export namespace ProtocolType { 26 | export const STAKING = "STAKING" 27 | export const LENDING = "LENDING" 28 | export const EXCHANGE = "EXCHANGE" 29 | export const INSURANCE = "INSURANCE" 30 | export const STABLECOIN = "STABLECOIN" 31 | export const DERIVATIVE = "DERIVATIVE" 32 | export const SYNTHETIC_TOKEN = "SYNTHETIC_TOKEN" 33 | export const TOKEN_MANAGEMENT = "TOKEN_MANAGEMENT" 34 | export const PREDICTION_MARKET = "PREDICTION_MARKET" 35 | export const LP_FARMING = "LP_FARMING" 36 | } 37 | 38 | export namespace PositionType { 39 | export const INVESTMENT = "INVESTMENT" 40 | export const DEBT = "DEBT" 41 | } 42 | 43 | export namespace TransactionType { 44 | export const INVEST = "INVEST" 45 | export const REDEEM = "REDEEM" 46 | export const BORROW = "BORROW" 47 | export const REPAY = "REPAY" 48 | export const TRANSFER_IN = "TRANSFER_IN" 49 | export const TRANSFER_OUT = "TRANSFER_OUT" 50 | } 51 | 52 | export const FARM_TOKEN_ADDRESS = Address.fromString("0xa0246c9032bc3a600820415ae600c6388619a14d"); 53 | -------------------------------------------------------------------------------- /harvest-finance/src/controller.ts: -------------------------------------------------------------------------------- 1 | import { 2 | AddVaultAndStrategyCall, 3 | SetFeeRewardForwarderCall, 4 | SharePriceChangeLog, 5 | } from "../generated/HarvestEthController1/HarvestEthController"; 6 | import { Market } from "../generated/schema"; 7 | import { TokenBalance, updateMarket } from "./common"; 8 | import { 9 | createFakeEventFromCall, 10 | getOrCreateFeeRewardForwarder, 11 | getOrCreateHarvestController, 12 | getOrCreateVault, 13 | } from "./harvestUtils"; 14 | import { Vault as VaultContract } from "../generated/templates/Vault/Vault"; 15 | 16 | /** 17 | * Call handler used to listen for new vaults 18 | * @param call 19 | */ 20 | export function addVaultAndStrategy(call: AddVaultAndStrategyCall): void { 21 | getOrCreateHarvestController(createFakeEventFromCall(call), call.to.toHexString()); 22 | 23 | let vaultAddress = call.inputs._vault; 24 | 25 | // quick check if contract implements IVault interface 26 | let vaultContract = VaultContract.bind(vaultAddress); 27 | if ( 28 | vaultContract.try_getPricePerFullShare().reverted || 29 | vaultContract.try_underlyingUnit().reverted 30 | ) { 31 | return; 32 | } 33 | 34 | // create new vault 35 | getOrCreateVault(createFakeEventFromCall(call), vaultAddress); 36 | } 37 | 38 | /** 39 | * Call handler used to track fee reward forwarder 40 | * @param call 41 | */ 42 | export function setFeeRewardForwarder(call: SetFeeRewardForwarderCall): void { 43 | let controller = getOrCreateHarvestController( 44 | createFakeEventFromCall(call), 45 | call.to.toHexString() 46 | ); 47 | 48 | let forwarderAddress = call.inputs._feeRewardForwarder; 49 | let forwarder = getOrCreateFeeRewardForwarder( 50 | createFakeEventFromCall(call), 51 | forwarderAddress.toHexString() 52 | ); 53 | 54 | controller.feeRewardForwarder = forwarder.id; 55 | controller.save(); 56 | } 57 | 58 | /** 59 | * Update vault's input token balances when share price is changed 60 | * @param event 61 | */ 62 | export function handleSharePriceChangeLog(event: SharePriceChangeLog): void { 63 | getOrCreateHarvestController(event, event.address.toHexString()); 64 | 65 | // quick check if contract implements IVault interface 66 | let vaultContract = VaultContract.bind(event.params.vault); 67 | if ( 68 | vaultContract.try_getPricePerFullShare().reverted || 69 | vaultContract.try_underlyingUnit().reverted 70 | ) { 71 | return; 72 | } 73 | 74 | // update vault's pricePerShare 75 | let vault = getOrCreateVault(event, event.params.vault); 76 | vault.pricePerShare = event.params.newSharePrice; 77 | vault.save(); 78 | 79 | // update market state 80 | let market = Market.load(event.params.vault.toHexString()) as Market; 81 | let outputTokenBalance = market.outputTokenTotalSupply; 82 | let inputTokenBalance = outputTokenBalance.times(vault.pricePerShare).div(vault.underlyingUnit); 83 | let inputTokenBalances: TokenBalance[] = [ 84 | new TokenBalance(vault.underlyingToken, event.params.vault.toHexString(), inputTokenBalance), 85 | ]; 86 | 87 | updateMarket(event, market, inputTokenBalances, market.outputTokenTotalSupply); 88 | } 89 | -------------------------------------------------------------------------------- /harvest-finance/src/feeRewardForwarder.ts: -------------------------------------------------------------------------------- 1 | import { TokenPoolSet } from "../generated/templates/FeeRewardForwarder/FeeRewardForwarder"; 2 | import { getOrCreateProfitSharingPool } from "./harvestUtils"; 3 | 4 | /** 5 | * Handle new reward pools 6 | * @param event 7 | */ 8 | export function handleTokenPoolSet(event: TokenPoolSet): void { 9 | let profitSharingPool = event.params.pool; 10 | getOrCreateProfitSharingPool(event, profitSharingPool.toHexString()); 11 | } 12 | -------------------------------------------------------------------------------- /harvest-finance/src/notifyHelper.ts: -------------------------------------------------------------------------------- 1 | import { NotifyPoolsCall } from "../generated/NotifyHelper/NotifyHelper"; 2 | import { createFakeEventFromCall, getOrCreateRewardPool, getOrCreateVault } from "./harvestUtils"; 3 | import { RewardPool as RewardPoolContract } from "../generated/templates/RewardPool/RewardPool"; 4 | import { Vault as VaultContract } from "../generated/templates/Vault/Vault"; 5 | 6 | export function handleNotifyPools(call: NotifyPoolsCall): void { 7 | let rewardPoolAddresses = call.inputs.pools; 8 | for (let i = 0; i < rewardPoolAddresses.length; i++) { 9 | // get vault 10 | let rewardPoolContract = RewardPoolContract.bind(rewardPoolAddresses[i]); 11 | let vaultAddress = rewardPoolContract.lpToken(); 12 | 13 | // quick check if contract implements IVault interface 14 | let vaultContract = VaultContract.bind(vaultAddress); 15 | if ( 16 | vaultContract.try_getPricePerFullShare().reverted || 17 | vaultContract.try_underlyingUnit().reverted 18 | ) { 19 | continue; 20 | } 21 | // create vault 22 | getOrCreateVault(createFakeEventFromCall(call), vaultAddress); 23 | 24 | // create reward pool if it doesn't exist 25 | getOrCreateRewardPool(createFakeEventFromCall(call), rewardPoolAddresses[i].toHexString()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /harvest-finance/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", 3 | "include": ["src"] 4 | } 5 | -------------------------------------------------------------------------------- /minichef/README: -------------------------------------------------------------------------------- 1 | MiniChef subgraphs cover different versions of MasterChef(v2) contract deploy out there. 2 | 3 | So far we have covered: 4 | - Sushiswap Farms on Arbitrum 5 | - Sushiswap Farms on Celo 6 | - Sushiswap Farms on Polygon 7 | - Sushiswap Farms on Gnosis 8 | - Apeswap Farms on Polygon 9 | - TraderJoe Farms on Avalanche 10 | -------------------------------------------------------------------------------- /minichef/abis/IRewarder.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [ 4 | { 5 | "internalType": "uint256", 6 | "name": "pid", 7 | "type": "uint256" 8 | }, 9 | { 10 | "internalType": "address", 11 | "name": "user", 12 | "type": "address" 13 | }, 14 | { 15 | "internalType": "address", 16 | "name": "recipient", 17 | "type": "address" 18 | }, 19 | { 20 | "internalType": "uint256", 21 | "name": "sushiAmount", 22 | "type": "uint256" 23 | }, 24 | { 25 | "internalType": "uint256", 26 | "name": "newLpAmount", 27 | "type": "uint256" 28 | } 29 | ], 30 | "name": "onSushiReward", 31 | "outputs": [], 32 | "stateMutability": "nonpayable", 33 | "type": "function" 34 | }, 35 | { 36 | "inputs": [ 37 | { 38 | "internalType": "uint256", 39 | "name": "pid", 40 | "type": "uint256" 41 | }, 42 | { 43 | "internalType": "address", 44 | "name": "user", 45 | "type": "address" 46 | }, 47 | { 48 | "internalType": "uint256", 49 | "name": "sushiAmount", 50 | "type": "uint256" 51 | } 52 | ], 53 | "name": "pendingTokens", 54 | "outputs": [ 55 | { 56 | "internalType": "contract IERC20[]", 57 | "name": "", 58 | "type": "address[]" 59 | }, 60 | { 61 | "internalType": "uint256[]", 62 | "name": "", 63 | "type": "uint256[]" 64 | } 65 | ], 66 | "stateMutability": "view", 67 | "type": "function" 68 | } 69 | ] -------------------------------------------------------------------------------- /minichef/config/apeswap-polygon.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "matic", 3 | "contractAddress": "0x54aff400858Dcac39797a81894D9920f16972D1D", 4 | "startBlock": 15797922 5 | } -------------------------------------------------------------------------------- /minichef/config/sushiswap-arbitrum.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "arbitrum-one", 3 | "contractAddress": "0xF4d73326C13a4Fc5FD7A064217e12780e9Bd62c3", 4 | "startBlock": 226981 5 | } -------------------------------------------------------------------------------- /minichef/config/sushiswap-celo.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "celo", 3 | "contractAddress": "0x0769fd68dFb93167989C6f7254cd0D766Fb2841F", 4 | "startBlock": 9269518 5 | } -------------------------------------------------------------------------------- /minichef/config/sushiswap-polygon.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "matic", 3 | "contractAddress": "0x0769fd68dFb93167989C6f7254cd0D766Fb2841F", 4 | "startBlock": 13911377 5 | } -------------------------------------------------------------------------------- /minichef/config/sushiswap-xdai.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "xdai", 3 | "contractAddress": "0xdDCbf776dF3dE60163066A5ddDF2277cB445E0F3", 4 | "startBlock": 16655565 5 | } -------------------------------------------------------------------------------- /minichef/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simplefi-sushiswap-farms", 3 | "license": "UNLICENSED", 4 | "scripts": { 5 | "codegen": "graph codegen", 6 | "build": "graph build", 7 | "prepare-apeswap-polygon": "mustache ./config/apeswap-polygon.json subgraph.apeswap.template.yaml > subgraph.yaml && npm run codegen", 8 | "prepare-sushiswap-arbitrum": "mustache ./config/sushiswap-arbitrum.json subgraph.template.yaml > subgraph.yaml && npm run codegen", 9 | "prepare-sushiswap-celo": "mustache ./config/sushiswap-celo.json subgraph.template.yaml > subgraph.yaml && npm run codegen", 10 | "prepare-sushiswap-polygon": "mustache ./config/sushiswap-polygon.json subgraph.template.yaml > subgraph.yaml && npm run codegen", 11 | "prepare-sushiswap-gnosis": "mustache ./config/sushiswap-xdai.json subgraph.template.yaml > subgraph.yaml && npm run codegen", 12 | "prepare-traderjoe-avalanche": "cp subgraph.joe.yaml subgraph.yaml && npm run codegen", 13 | "deploy-apeswap-polygon": "npm run prepare-apeswap-polygon && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/apeswap-farms-polygon", 14 | "deploy-sushiswap-arbitrum": "npm run prepare-sushiswap-arbitrum && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/sushiswap-farms-arbitrum", 15 | "deploy-sushiswap-celo": "npm run prepare-sushiswap-celo && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/sushiswap-farms-celo", 16 | "deploy-sushiswap-polygon": "npm run prepare-sushiswap-polygon && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/sushiswap-farms-polygon", 17 | "deploy-sushiswap-gnosis": "npm run prepare-sushiswap-xdai && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/sushiswap-farms-gnosis", 18 | "deploy-traderjoe-avalanche": "npm run prepare-traderjoe-avalanche && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/traderjoe-farms-avalanche" 19 | }, 20 | "dependencies": { 21 | "@graphprotocol/graph-cli": "0.20.0", 22 | "@graphprotocol/graph-ts": "0.20.0", 23 | "mustache": "^4.2.0" 24 | } 25 | } -------------------------------------------------------------------------------- /minichef/subgraph.apeswap.template.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.2 2 | description: ApeSwap farms subgraph 3 | schema: 4 | file: ./schema.graphql 5 | 6 | dataSources: 7 | # Controls pools (farms) and SUSHI issuance - V2 version 8 | - name: MiniChef 9 | kind: ethereum/contract 10 | network: {{network}} 11 | source: 12 | abi: MiniChef 13 | address: "{{contractAddress}}" 14 | startBlock: {{startBlock}} 15 | mapping: 16 | kind: ethereum/events 17 | apiVersion: 0.0.4 18 | language: wasm/assemblyscript 19 | file: ./src/mappings/minichef-apeswap.ts 20 | abis: 21 | - name: MiniChef 22 | file: ./abis/MiniApe.json 23 | - name: IERC20 24 | file: ./abis/IERC20.json 25 | - name: IRewarder 26 | file: ./abis/IRewarder.json 27 | entities: 28 | - MiniChef 29 | - Block 30 | - Account 31 | - Token 32 | - Market 33 | - Transaction 34 | - Transfer 35 | - Position 36 | - PositionSnapshot 37 | eventHandlers: 38 | - event: Deposit(indexed address,indexed uint256,uint256,indexed address) 39 | handler: handleDeposit 40 | - event: Withdraw(indexed address,indexed uint256,uint256,indexed address) 41 | handler: handleWithdraw 42 | - event: EmergencyWithdraw(indexed address,indexed uint256,uint256,indexed address) 43 | handler: handleEmergencyWithdraw 44 | - event: Harvest(indexed address,indexed uint256,uint256) 45 | handler: handleHarvest 46 | - event: LogPoolAddition(indexed uint256,uint256,indexed address,indexed address) 47 | handler: handleLogPoolAddition 48 | - event: LogSetPool(indexed uint256,uint256,indexed address,bool) 49 | handler: handleLogSetPool 50 | - event: LogUpdatePool(indexed uint256,uint64,uint256,uint256) 51 | handler: handleLogUpdatePool 52 | - event: LogBananaPerSecond(uint256) 53 | handler: handleLogSushiPerSecond 54 | 55 | templates: 56 | - kind: ethereum/contract 57 | name: RewardToken 58 | network: {{network}} 59 | source: 60 | abi: IERC20 61 | mapping: 62 | kind: ethereum/events 63 | apiVersion: 0.0.4 64 | language: wasm/assemblyscript 65 | entities: 66 | - Block 67 | - Account 68 | - Token 69 | - Market 70 | - Transaction 71 | - Transfer 72 | - Position 73 | - PositionSnapshot 74 | abis: 75 | - name: IERC20 76 | file: ./abis/IERC20.json 77 | eventHandlers: 78 | - event: Transfer(indexed address,indexed address,uint256) 79 | handler: handleRewardTokenTransfer 80 | file: ./src/mappings/minichef-apeswap.ts 81 | -------------------------------------------------------------------------------- /minichef/subgraph.joe.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.2 2 | description: TraderJoe farms subgraph 3 | schema: 4 | file: ./schema.graphql 5 | 6 | dataSources: 7 | # Controls pools (farms) and JOE issuance - V2 version 8 | - name: MiniChef 9 | kind: ethereum/contract 10 | network: avalanche 11 | source: 12 | abi: MiniChef 13 | address: "0xd6a4F121CA35509aF06A0Be99093d08462f53052" 14 | startBlock: 2486444 15 | mapping: 16 | kind: ethereum/events 17 | apiVersion: 0.0.4 18 | language: wasm/assemblyscript 19 | file: ./src/mappings/minichef-joe.ts 20 | abis: 21 | - name: MiniChef 22 | file: ./abis/MasterChefJoe.json 23 | - name: IERC20 24 | file: ./abis/IERC20.json 25 | - name: IRewarder 26 | file: ./abis/IRewarder.json 27 | entities: 28 | - MasterChef 29 | - Block 30 | - Account 31 | - Token 32 | - Market 33 | - Transaction 34 | - Transfer 35 | - Position 36 | - PositionSnapshot 37 | eventHandlers: 38 | - event: Add(indexed uint256,uint256,indexed address,indexed address) 39 | handler: handleAdd 40 | - event: Set(indexed uint256,uint256,indexed address,bool) 41 | handler: handleSet 42 | - event: Deposit(indexed address,indexed uint256,uint256) 43 | handler: handleDeposit 44 | - event: Withdraw(indexed address,indexed uint256,uint256) 45 | handler: handleWithdraw 46 | - event: UpdatePool(indexed uint256,uint256,uint256,uint256) 47 | handler: handleUpdatePool 48 | - event: Harvest(indexed address,indexed uint256,uint256) 49 | handler: handleHarvest 50 | - event: EmergencyWithdraw(indexed address,indexed uint256,uint256) 51 | handler: handleEmergencyWithdraw 52 | - event: UpdateEmissionRate(indexed address,uint256) 53 | handler: handleUpdateEmissionRate 54 | 55 | templates: 56 | - kind: ethereum/contract 57 | name: RewardToken 58 | network: avalanche 59 | source: 60 | abi: IERC20 61 | mapping: 62 | kind: ethereum/events 63 | apiVersion: 0.0.4 64 | language: wasm/assemblyscript 65 | entities: 66 | - Block 67 | - Account 68 | - Token 69 | - Market 70 | - Transaction 71 | - Transfer 72 | - Position 73 | - PositionSnapshot 74 | abis: 75 | - name: IERC20 76 | file: ./abis/IERC20.json 77 | eventHandlers: 78 | - event: Transfer(indexed address,indexed address,uint256) 79 | handler: handleRewardTokenTransfer 80 | file: ./src/mappings/minichef-joe.ts 81 | -------------------------------------------------------------------------------- /minichef/subgraph.template.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.2 2 | description: MasterChef farms subgraph 3 | schema: 4 | file: ./schema.graphql 5 | 6 | dataSources: 7 | # Controls pools (farms) and SUSHI issuance - V2 version 8 | - name: MiniChef 9 | kind: ethereum/contract 10 | network: {{network}} 11 | source: 12 | abi: MiniChef 13 | address: "{{contractAddress}}" 14 | startBlock: {{startBlock}} 15 | mapping: 16 | kind: ethereum/events 17 | apiVersion: 0.0.4 18 | language: wasm/assemblyscript 19 | file: ./src/mappings/minichef.ts 20 | abis: 21 | - name: MiniChef 22 | file: ./abis/MiniChef.json 23 | - name: IERC20 24 | file: ./abis/IERC20.json 25 | - name: IRewarder 26 | file: ./abis/IRewarder.json 27 | entities: 28 | - MiniChef 29 | - Block 30 | - Account 31 | - Token 32 | - Market 33 | - Transaction 34 | - Transfer 35 | - Position 36 | - PositionSnapshot 37 | eventHandlers: 38 | - event: Deposit(indexed address,indexed uint256,uint256,indexed address) 39 | handler: handleDeposit 40 | - event: Withdraw(indexed address,indexed uint256,uint256,indexed address) 41 | handler: handleWithdraw 42 | - event: EmergencyWithdraw(indexed address,indexed uint256,uint256,indexed address) 43 | handler: handleEmergencyWithdraw 44 | - event: Harvest(indexed address,indexed uint256,uint256) 45 | handler: handleHarvest 46 | - event: LogPoolAddition(indexed uint256,uint256,indexed address,indexed address) 47 | handler: handleLogPoolAddition 48 | - event: LogSetPool(indexed uint256,uint256,indexed address,bool) 49 | handler: handleLogSetPool 50 | - event: LogUpdatePool(indexed uint256,uint64,uint256,uint256) 51 | handler: handleLogUpdatePool 52 | - event: LogSushiPerSecond(uint256) 53 | handler: handleLogSushiPerSecond 54 | 55 | templates: 56 | - kind: ethereum/contract 57 | name: RewardToken 58 | network: {{network}} 59 | source: 60 | abi: IERC20 61 | mapping: 62 | kind: ethereum/events 63 | apiVersion: 0.0.4 64 | language: wasm/assemblyscript 65 | entities: 66 | - Block 67 | - Account 68 | - Token 69 | - Market 70 | - Transaction 71 | - Transfer 72 | - Position 73 | - PositionSnapshot 74 | abis: 75 | - name: IERC20 76 | file: ./abis/IERC20.json 77 | eventHandlers: 78 | - event: Transfer(indexed address,indexed address,uint256) 79 | handler: handleRewardTokenTransfer 80 | file: ./src/mappings/minichef.ts 81 | -------------------------------------------------------------------------------- /mstable-v2/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | package-lock.json 107 | 108 | build/ 109 | generated/ 110 | -------------------------------------------------------------------------------- /mstable-v2/README.md: -------------------------------------------------------------------------------- 1 | # Mstable # 2 | 3 | ## Version 3.0 ## 4 | 5 | Uses Manager library contract at - 0x1e91f826fa8aa4fa4d3f595898af3a64dd188848 instead of BasketManager 6 | 7 | ### Events ### 8 | 9 | `Minted(address indexed minter, address recipient, uint256 mAssetQuantity, address input, uint256 inputQuantity)` 10 | 11 | `MintedMulti(address indexed minter, address recipient, uint256 mAssetQuantity, address[] inputs, uint256[] inputQuantities)` 12 | 13 | `Swapped(address indexed swapper, address input, address output, uint256 outputAmount, uint256 scaledFee, address recipient)` 14 | 15 | `Redeemed(address indexed redeemer, address recipient, uint256 mAssetQuantity, address output, uint256 outputQuantity, uint256 scaledFee)` 16 | 17 | `RedeemedMulti(address indexed redeemer, address recipient, uint256 mAssetQuantity, address[] outputs, uint256[] outputQuantity, uint256 scaledFee)` 18 | -------------------------------------------------------------------------------- /mstable-v2/abis/AssetProxy.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [ 4 | { 5 | "internalType": "address", 6 | "name": "_logic", 7 | "type": "address" 8 | }, 9 | { 10 | "internalType": "address", 11 | "name": "admin_", 12 | "type": "address" 13 | }, 14 | { 15 | "internalType": "bytes", 16 | "name": "_data", 17 | "type": "bytes" 18 | } 19 | ], 20 | "stateMutability": "payable", 21 | "type": "constructor" 22 | }, 23 | { 24 | "anonymous": false, 25 | "inputs": [ 26 | { 27 | "indexed": false, 28 | "internalType": "address", 29 | "name": "previousAdmin", 30 | "type": "address" 31 | }, 32 | { 33 | "indexed": false, 34 | "internalType": "address", 35 | "name": "newAdmin", 36 | "type": "address" 37 | } 38 | ], 39 | "name": "AdminChanged", 40 | "type": "event" 41 | }, 42 | { 43 | "anonymous": false, 44 | "inputs": [ 45 | { 46 | "indexed": true, 47 | "internalType": "address", 48 | "name": "implementation", 49 | "type": "address" 50 | } 51 | ], 52 | "name": "Upgraded", 53 | "type": "event" 54 | }, 55 | { 56 | "stateMutability": "payable", 57 | "type": "fallback" 58 | }, 59 | { 60 | "inputs": [], 61 | "name": "admin", 62 | "outputs": [ 63 | { 64 | "internalType": "address", 65 | "name": "admin_", 66 | "type": "address" 67 | } 68 | ], 69 | "stateMutability": "nonpayable", 70 | "type": "function" 71 | }, 72 | { 73 | "inputs": [ 74 | { 75 | "internalType": "address", 76 | "name": "newAdmin", 77 | "type": "address" 78 | } 79 | ], 80 | "name": "changeAdmin", 81 | "outputs": [], 82 | "stateMutability": "nonpayable", 83 | "type": "function" 84 | }, 85 | { 86 | "inputs": [], 87 | "name": "implementation", 88 | "outputs": [ 89 | { 90 | "internalType": "address", 91 | "name": "implementation_", 92 | "type": "address" 93 | } 94 | ], 95 | "stateMutability": "nonpayable", 96 | "type": "function" 97 | }, 98 | { 99 | "inputs": [ 100 | { 101 | "internalType": "address", 102 | "name": "newImplementation", 103 | "type": "address" 104 | } 105 | ], 106 | "name": "upgradeTo", 107 | "outputs": [], 108 | "stateMutability": "nonpayable", 109 | "type": "function" 110 | }, 111 | { 112 | "inputs": [ 113 | { 114 | "internalType": "address", 115 | "name": "newImplementation", 116 | "type": "address" 117 | }, 118 | { 119 | "internalType": "bytes", 120 | "name": "data", 121 | "type": "bytes" 122 | } 123 | ], 124 | "name": "upgradeToAndCall", 125 | "outputs": [], 126 | "stateMutability": "payable", 127 | "type": "function" 128 | }, 129 | { 130 | "stateMutability": "payable", 131 | "type": "receive" 132 | } 133 | ] -------------------------------------------------------------------------------- /mstable-v2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simplefi-mstable-v2", 3 | "license": "UNLICENSED", 4 | "scripts": { 5 | "codegen": "graph codegen", 6 | "build": "graph build", 7 | "deploy": "graph deploy --node https://api.thegraph.com/deploy/ simplefi-finance/mstable-v2", 8 | "create-local": "graph create --node http://localhost:8020/ simplefi-finance/mstable-v2", 9 | "remove-local": "graph remove --node http://localhost:8020/ simplefi-finance/mstable-v2", 10 | "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 simplefi-finance/mstable-v2" 11 | }, 12 | "dependencies": { 13 | "@graphprotocol/graph-cli": "0.21.1", 14 | "@graphprotocol/graph-ts": "0.20.0" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /mstable-v2/src/constants.ts: -------------------------------------------------------------------------------- 1 | export namespace Blockchain { 2 | export const ETHEREUM = "ETHEREUM" 3 | export const BSC = "BSC" 4 | export const XDAI = "XDAI" 5 | export const POLYGON = "POLYGON" 6 | export const OPTIMISM = "OPTIMISM" 7 | export const AVALANCHE = "AVALANCE" 8 | export const NEAR = "NEAR" 9 | } 10 | 11 | export namespace TokenStandard { 12 | export const ERC20 = "ERC20" 13 | export const ERC721 = "ERC721" 14 | export const ERC1155 = "ERC1155" 15 | } 16 | 17 | export namespace ProtocolName { 18 | export const UNISWAP_V2 = "UNISWAP_V2" 19 | export const MSTABLE = "MSTABLE" 20 | } 21 | 22 | export namespace ProtocolType { 23 | export const STAKING = "STAKING" 24 | export const LENDING = "LENDING" 25 | export const EXCHANGE = "EXCHANGE" 26 | export const INSURANCE = "INSURANCE" 27 | export const STABLECOIN = "STABLECOIN" 28 | export const DERIVATIVE = "DERIVATIVE" 29 | export const SYNTHETIC_TOKEN = "SYNTHETIC_TOKEN" 30 | export const TOKEN_MANAGEMENT = "TOKEN_MANAGEMENT" 31 | export const PREDICTION_MARKET = "PREDICTION_MARKET" 32 | } 33 | 34 | export namespace PositionType { 35 | export const INVESTMENT = "INVESTMENT" 36 | export const DEBT = "DEBT" 37 | } 38 | 39 | export namespace TransactionType { 40 | export const INVEST = "INVEST" 41 | export const REDEEM = "REDEEM" 42 | export const BORROW = "BORROW" 43 | export const REPAY = "REPAY" 44 | export const TRANSFER_IN = "TRANSFER_IN" 45 | export const TRANSFER_OUT = "TRANSFER_OUT" 46 | } -------------------------------------------------------------------------------- /mstable-v2/src/fpmBTCHBTC.ts: -------------------------------------------------------------------------------- 1 | import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts" 2 | import { 3 | InitializeCall 4 | } from "../generated/fpmBTCHBTC/FeederPool" 5 | import { 6 | FeederPool as FeederPoolEntity, 7 | Token as TokenEntity 8 | } from "../generated/schema" 9 | import { 10 | FeederPool as FeederPoolTemplate 11 | } from "../generated/templates" 12 | import { 13 | getOrCreateERC20Token, 14 | getOrCreateMarket 15 | } from "./common" 16 | import { ProtocolName, ProtocolType } from "./constants" 17 | 18 | 19 | export function handleInitialize(call: InitializeCall): void { 20 | let fpmAssetAddress = Address.fromString("0x48c59199Da51B7E30Ea200a74Ea07974e62C4bA7") 21 | let fakeEvent = new ethereum.Event() 22 | fakeEvent.address = call.to 23 | fakeEvent.block = call.block 24 | 25 | let exists = FeederPoolEntity.load(fpmAssetAddress.toHexString()) 26 | if (exists != null) { 27 | return 28 | } 29 | 30 | let feederPool = new FeederPoolEntity(fpmAssetAddress.toHexString()) 31 | feederPool.impl = call.to.toHexString() 32 | feederPool.mAsset = call.inputs._mAsset.addr.toHexString() 33 | feederPool.fAsset = call.inputs._fAsset.addr.toHexString() 34 | feederPool.mAssetBalance = BigInt.fromI32(0) 35 | feederPool.fAssetBalance = BigInt.fromI32(0) 36 | feederPool.totalSupply = BigInt.fromI32(0) 37 | feederPool.save() 38 | 39 | let inputTokens: TokenEntity[] = [] 40 | let mToken = getOrCreateERC20Token(fakeEvent, call.inputs._mAsset.addr) 41 | let fToken = getOrCreateERC20Token(fakeEvent, call.inputs._fAsset.addr) 42 | inputTokens.push(mToken) 43 | inputTokens.push(fToken) 44 | let outputToken = getOrCreateERC20Token(fakeEvent, fpmAssetAddress) 45 | 46 | // Create market 47 | let market = getOrCreateMarket( 48 | fakeEvent, 49 | fpmAssetAddress, 50 | ProtocolName.MSTABLE, 51 | ProtocolType.EXCHANGE, 52 | inputTokens, 53 | outputToken, 54 | [] 55 | ) 56 | 57 | outputToken.mintedByMarket = market.id 58 | outputToken.save() 59 | 60 | // Create basket manager proxy listener 61 | FeederPoolTemplate.create(fpmAssetAddress) 62 | } 63 | -------------------------------------------------------------------------------- /mstable-v2/src/fpmBTCTBTC.ts: -------------------------------------------------------------------------------- 1 | import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts" 2 | import { 3 | InitializeCall 4 | } from "../generated/fpmBTCHBTC/FeederPool" 5 | import { 6 | FeederPool as FeederPoolEntity, 7 | Token as TokenEntity 8 | } from "../generated/schema" 9 | import { 10 | FeederPool as FeederPoolTemplate 11 | } from "../generated/templates" 12 | import { 13 | getOrCreateERC20Token, 14 | getOrCreateMarket 15 | } from "./common" 16 | import { ProtocolName, ProtocolType } from "./constants" 17 | 18 | 19 | export function handleInitialize(call: InitializeCall): void { 20 | let fpmAssetAddress = Address.fromString("0xb61A6F928B3f069A68469DDb670F20eEeB4921e0") 21 | let fakeEvent = new ethereum.Event() 22 | fakeEvent.address = call.to 23 | fakeEvent.block = call.block 24 | 25 | let exists = FeederPoolEntity.load(fpmAssetAddress.toHexString()) 26 | if (exists != null) { 27 | return 28 | } 29 | 30 | let feederPool = new FeederPoolEntity(fpmAssetAddress.toHexString()) 31 | feederPool.impl = call.to.toHexString() 32 | feederPool.mAsset = call.inputs._mAsset.addr.toHexString() 33 | feederPool.fAsset = call.inputs._fAsset.addr.toHexString() 34 | feederPool.mAssetBalance = BigInt.fromI32(0) 35 | feederPool.fAssetBalance = BigInt.fromI32(0) 36 | feederPool.totalSupply = BigInt.fromI32(0) 37 | feederPool.save() 38 | 39 | let inputTokens: TokenEntity[] = [] 40 | let mToken = getOrCreateERC20Token(fakeEvent, call.inputs._mAsset.addr) 41 | let fToken = getOrCreateERC20Token(fakeEvent, call.inputs._fAsset.addr) 42 | inputTokens.push(mToken) 43 | inputTokens.push(fToken) 44 | let outputToken = getOrCreateERC20Token(fakeEvent, fpmAssetAddress) 45 | 46 | // Create market 47 | let market = getOrCreateMarket( 48 | fakeEvent, 49 | fpmAssetAddress, 50 | ProtocolName.MSTABLE, 51 | ProtocolType.EXCHANGE, 52 | inputTokens, 53 | outputToken, 54 | [] 55 | ) 56 | 57 | outputToken.mintedByMarket = market.id 58 | outputToken.save() 59 | 60 | // Create basket manager proxy listener 61 | FeederPoolTemplate.create(fpmAssetAddress) 62 | } 63 | -------------------------------------------------------------------------------- /mstable-v2/src/imBTC.ts: -------------------------------------------------------------------------------- 1 | import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts" 2 | import { 3 | IMAsset, 4 | InitializeCall 5 | } from "../generated/iMBTC/IMAsset" 6 | import { 7 | IMAsset as IMAssetEntity 8 | } from "../generated/schema" 9 | import { 10 | IMAsset as IMAssetTemplate 11 | } from "../generated/templates" 12 | import { 13 | getOrCreateERC20Token, 14 | getOrCreateMarket 15 | } from "./common" 16 | import { ProtocolName, ProtocolType } from "./constants" 17 | 18 | 19 | export function handleInitialize(call: InitializeCall): void { 20 | let imAssetAddress = Address.fromString("0x17d8CBB6Bce8cEE970a4027d1198F6700A7a6c24") 21 | let fakeEvent = new ethereum.Event() 22 | fakeEvent.address = call.to 23 | fakeEvent.block = call.block 24 | 25 | let exists = IMAssetEntity.load(imAssetAddress.toHexString()) 26 | if (exists != null) { 27 | return 28 | } 29 | 30 | let contract = IMAsset.bind(imAssetAddress) 31 | let mBTC = contract.underlying() 32 | 33 | let imAsset = new IMAssetEntity(imAssetAddress.toHexString()) 34 | imAsset.mAsset = mBTC.toHexString() 35 | imAsset.totalSavings = BigInt.fromI32(0) 36 | imAsset.totalSupply = BigInt.fromI32(0) 37 | imAsset.exchangeRate = BigInt.fromI32(10) 38 | imAsset.save() 39 | 40 | let inputToken = getOrCreateERC20Token(fakeEvent, mBTC) 41 | let outputToken = getOrCreateERC20Token(fakeEvent, imAssetAddress) 42 | 43 | // Create market 44 | let market = getOrCreateMarket( 45 | fakeEvent, 46 | imAssetAddress, 47 | ProtocolName.MSTABLE, 48 | ProtocolType.TOKEN_MANAGEMENT, 49 | [inputToken], 50 | outputToken, 51 | [] 52 | ) 53 | 54 | outputToken.mintedByMarket = market.id 55 | outputToken.save() 56 | 57 | // Create basket manager proxy listener 58 | IMAssetTemplate.create(imAssetAddress) 59 | } 60 | -------------------------------------------------------------------------------- /mstable-v2/src/mBTC.ts: -------------------------------------------------------------------------------- 1 | import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts" 2 | import { 3 | InitializeCall 4 | } from "../generated/MBTC/MAsset" 5 | import { 6 | MAsset as MAssetEntity, 7 | Token as TokenEntity 8 | } from "../generated/schema" 9 | import { 10 | MAsset as MAssetTemplate 11 | } from "../generated/templates" 12 | import { 13 | ADDRESS_ZERO, 14 | getOrCreateERC20Token, 15 | getOrCreateMarket, 16 | TokenBalance 17 | } from "./common" 18 | import { ProtocolName, ProtocolType } from "./constants" 19 | 20 | 21 | export function handleInitialize(call: InitializeCall): void { 22 | let mAssetAddress = Address.fromString("0x945Facb997494CC2570096c74b5F66A3507330a1") 23 | let fakeEvent = new ethereum.Event() 24 | fakeEvent.address = call.to 25 | fakeEvent.block = call.block 26 | 27 | let exists = MAssetEntity.load(mAssetAddress.toHexString()) 28 | if (exists != null) { 29 | return 30 | } 31 | 32 | let mAsset = new MAssetEntity(mAssetAddress.toHexString()) 33 | let forgeValidator = call.inputs._forgeValidator 34 | let bAssetsData = call.inputs._bAssets 35 | 36 | mAsset.impl = call.to.toHexString() 37 | mAsset.basketManager = ADDRESS_ZERO 38 | mAsset.forgeValidator = forgeValidator.toHexString() 39 | mAsset.swapFee = BigInt.fromI32(0) 40 | 41 | let bAssets: string[] = [] 42 | let inputTokens: TokenEntity[] = [] 43 | let bAssetBalances: TokenBalance[] = [] 44 | for (let i = 0; i < bAssetsData.length; i++) { 45 | let bAsset = bAssetsData[i] 46 | let token = getOrCreateERC20Token(fakeEvent, bAsset.addr) 47 | bAssets.push(bAsset.addr.toHexString()) 48 | inputTokens.push(token) 49 | bAssetBalances.push(new TokenBalance(bAsset.addr.toHexString(), mAsset.id, BigInt.fromI32(0))) 50 | } 51 | let bAssetBalancesString = bAssetBalances.map(tb => tb.toString()) 52 | 53 | mAsset.bAssets = bAssets 54 | mAsset.bAssetBalances = bAssetBalancesString 55 | mAsset.totalSupply = BigInt.fromI32(0) 56 | mAsset.save() 57 | 58 | let outputToken = getOrCreateERC20Token(fakeEvent, mAssetAddress) 59 | 60 | // Create market 61 | let market = getOrCreateMarket( 62 | fakeEvent, 63 | mAssetAddress, 64 | ProtocolName.MSTABLE, 65 | ProtocolType.STABLECOIN, 66 | inputTokens, 67 | outputToken, 68 | [] 69 | ) 70 | 71 | outputToken.mintedByMarket = market.id 72 | outputToken.save() 73 | 74 | // Create basket manager proxy listener 75 | MAssetTemplate.create(mAssetAddress) 76 | } 77 | -------------------------------------------------------------------------------- /mstable-v2/src/vimBTC.ts: -------------------------------------------------------------------------------- 1 | import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts" 2 | import { 3 | VIMAsset as VIMAssetEntity 4 | } from "../generated/schema" 5 | import { 6 | VIMAsset as VIMAssetTemplate 7 | } from "../generated/templates" 8 | import { 9 | InitializeCall, 10 | VIMAsset 11 | } from "../generated/viMBTC/VIMAsset" 12 | import { 13 | getOrCreateERC20Token, 14 | getOrCreateMarket 15 | } from "./common" 16 | import { ProtocolName, ProtocolType } from "./constants" 17 | 18 | 19 | export function handleInitialize(call: InitializeCall): void { 20 | let vimAssetAddress = Address.fromString("0xF38522f63f40f9Dd81aBAfD2B8EFc2EC958a3016") 21 | let fakeEvent = new ethereum.Event() 22 | fakeEvent.address = call.to 23 | fakeEvent.block = call.block 24 | 25 | let exists = VIMAssetEntity.load(vimAssetAddress.toHexString()) 26 | if (exists != null) { 27 | return 28 | } 29 | 30 | let contract = VIMAsset.bind(vimAssetAddress) 31 | let imBTC = contract.stakingToken() 32 | let mta = contract.rewardsToken() 33 | 34 | let vimAsset = new VIMAssetEntity(vimAssetAddress.toHexString()) 35 | vimAsset.imAsset = imBTC.toHexString() 36 | vimAsset.rewardToken = mta.toHexString() 37 | vimAsset.imAssetBalance = BigInt.fromI32(0) 38 | vimAsset.rewardBalance = BigInt.fromI32(0) 39 | vimAsset.totalSupply = BigInt.fromI32(0) 40 | vimAsset.save() 41 | 42 | let inputToken = getOrCreateERC20Token(fakeEvent, imBTC) 43 | let outputToken = getOrCreateERC20Token(fakeEvent, vimAssetAddress) 44 | let rewardToken = getOrCreateERC20Token(fakeEvent, mta) 45 | 46 | // Create market 47 | let market = getOrCreateMarket( 48 | fakeEvent, 49 | vimAssetAddress, 50 | ProtocolName.MSTABLE, 51 | ProtocolType.TOKEN_MANAGEMENT, 52 | [inputToken], 53 | outputToken, 54 | [rewardToken] 55 | ) 56 | 57 | outputToken.mintedByMarket = market.id 58 | outputToken.save() 59 | 60 | // Create basket manager proxy listener 61 | VIMAssetTemplate.create(vimAssetAddress) 62 | } 63 | 64 | -------------------------------------------------------------------------------- /near-template/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | package-lock.json 107 | 108 | build/ 109 | generated/ -------------------------------------------------------------------------------- /near-template/README.md: -------------------------------------------------------------------------------- 1 | ## NEAR subgraph template 2 | 3 | This is a template subgraph for developing subgraphs for protocols on NEAR blockchain. It can be used to develop a subgraph for integration with SimpleFi dashboard or a standalone subgraph. 4 | 5 | ### Features 6 | 7 | - Pre defined common schema for SimpleFi Dashboard integration 8 | - Pre defined methods to populate SimpleFi common schema entities 9 | - Stub functions for all type of actions a NEAR account 10 | - Boilerplate for function call action handler 11 | - `parseNullableJSONAtrribute` function in common.ts 12 | - `debugNEARLogs` function to log all receipt data for debugging 13 | - Bonus - can be deployed to index contract deployments 14 | - Deployed at - [Near Template Subgraph](https://thegraph.com/hosted-service/subgraph/simplefi-finance/near-template) 15 | 16 | ### Example subgraph 17 | 18 | An example subgraph using this template can be found at [link-to-be-published-soon] 19 | 20 | ### Notes 21 | 22 | These are notes that may be useful for developing NEAR subgraphs when coming from EVM subgraph development experience - 23 | 24 | - NEAR subgraph listner gets triggered for account creation, contract deployment and new function call. This allows us to create entity to track constructor parameters. We can not index constructor params on EVM subgraphs 25 | 26 | - NEAR subgraph does not support contract calls for view function 27 | 28 | - Return value of a function is included in outcome.status, it can be 29 | 30 | - A value if the function returns a value, which can be parsed by converting outcome.status to bytes and then parsed as JSON 31 | - A receipt id if the function returns a promise, which can be parsed by converting outcome.status to a receipt id 32 | 33 | -------------------------------------------------------------------------------- /near-template/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "NEAT template subgraph", 3 | "license": "UNLICENSED", 4 | "scripts": { 5 | "codegen": "graph codegen", 6 | "build": "graph build", 7 | "deploy": "graph deploy --node https://api.thegraph.com/deploy/ simplefi-finance/near-template", 8 | "create-local": "graph create --node http://localhost:8020/ simplefi-finance/near-template", 9 | "remove-local": "graph remove --node http://localhost:8020/ simplefi-finance/near-template", 10 | "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 simplefi-finance/near-template" 11 | }, 12 | "dependencies": { 13 | "@graphprotocol/graph-cli": "0.26.0", 14 | "@graphprotocol/graph-ts": "0.24.1" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /near-template/src/constants.ts: -------------------------------------------------------------------------------- 1 | export namespace Blockchain { 2 | export const ETHEREUM = "ETHEREUM" 3 | export const BSC = "BSC" 4 | export const XDAI = "XDAI" 5 | export const POLYGON = "POLYGON" 6 | export const OPTIMISM = "OPTIMISM" 7 | export const AVALANCHE = "AVALANCE" 8 | export const NEAR = "NEAR" 9 | } 10 | 11 | export namespace TokenStandard { 12 | export const NEP141 = "NEP141" 13 | export const NEP171 = "NEP171" 14 | export const NEP245 = "NEP245" 15 | } 16 | 17 | export namespace ProtocolName { 18 | export const REF_FINANCE = "REF_FINANCE" 19 | } 20 | 21 | export namespace ProtocolType { 22 | export const STAKING = "STAKING" 23 | export const LENDING = "LENDING" 24 | export const EXCHANGE = "EXCHANGE" 25 | export const INSURANCE = "INSURANCE" 26 | export const STABLECOIN = "STABLECOIN" 27 | export const DERIVATIVE = "DERIVATIVE" 28 | export const SYNTHETIC_TOKEN = "SYNTHETIC_TOKEN" 29 | export const TOKEN_MANAGEMENT = "TOKEN_MANAGEMENT" 30 | export const PREDICTION_MARKET = "PREDICTION_MARKET" 31 | } 32 | 33 | export namespace PositionType { 34 | export const INVESTMENT = "INVESTMENT" 35 | export const DEBT = "DEBT" 36 | } 37 | 38 | export namespace TransactionType { 39 | export const INVEST = "INVEST" 40 | export const REDEEM = "REDEEM" 41 | export const BORROW = "BORROW" 42 | export const REPAY = "REPAY" 43 | export const TRANSFER_IN = "TRANSFER_IN" 44 | export const TRANSFER_OUT = "TRANSFER_OUT" 45 | } 46 | -------------------------------------------------------------------------------- /near-template/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.4 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: near 6 | name: RefFinanceV2 7 | network: near-mainnet 8 | source: 9 | account: "v2.ref-finance.near" 10 | startBlock: 45752812 11 | mapping: 12 | apiVersion: 0.0.5 13 | language: wasm/assemblyscript 14 | entities: 15 | - Account 16 | receiptHandlers: 17 | - handler: handleReceipt 18 | file: ./src/near.ts 19 | -------------------------------------------------------------------------------- /near-template/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", 3 | "include": ["src"] 4 | } 5 | -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | package-lock.json 107 | 108 | build/ 109 | generated/ 110 | subgraph.yaml 111 | -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/README.md: -------------------------------------------------------------------------------- 1 | # Daily market data 2 | 3 | SimpleFi's main subgraphs are focused on tracking historical and current user positions. But we also want to track market-level (amm pair, lending pair, farm) volume data in order to have even more complete analytics. For that purpose we deploy complementray 'protocol-data' subgraph for every main subgraph. 4 | 5 | These subgraphs are quite simpler. Focus is on collecting aggregate volume data on daily level. This is the main entity: 6 | 7 | ``` 8 | type MarketDayData @entity { 9 | " marketAddress + dayId " 10 | id: ID! 11 | 12 | " first trade of the day timestamp " 13 | timestamp: BigInt! 14 | 15 | " market id - pair address " 16 | market: String! 17 | 18 | " swap volume -> amount of input tokens swapped in or out " 19 | inputTokensDailySwapVolume: [BigInt!]! 20 | 21 | " total amount of reserves per input token " 22 | inputTokenTotalBalances: [BigInt!]! 23 | 24 | " reserve amount per input token this day " 25 | inputTokenDailyInflow: [BigInt!]! 26 | 27 | " reserve amount per input token this day " 28 | inputTokenDailyOutflow: [BigInt!]! 29 | 30 | " total balance of LP tokens " 31 | outputTokenTotalBalance: BigInt! 32 | 33 | " amount of LP tokens minted this day " 34 | outputTokenDailyInflowVolume: BigInt! 35 | 36 | " amount of LP tokens burned this day " 37 | outputTokenDailyOutflowVolume: BigInt! 38 | 39 | " number of TXs this day swap " 40 | dailySwapTXs: BigInt! 41 | 42 | " number of TXs this day mint " 43 | dailyMintTXs: BigInt! 44 | 45 | " number of TXs this day burn " 46 | dailyBurnTXs: BigInt! 47 | 48 | " dayId - timestamp/86400 " 49 | dayId: BigInt! 50 | } 51 | ``` 52 | -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/config/apeswap-bsc.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "bsc", 3 | "factoryAddress": "0x0841BD0B734E4F5853f0dD8d7Ea041c241fb0Da6", 4 | "factoryStartBlock": 4855901, 5 | "factoryMappingPath": "apeswap.ts" 6 | } -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/config/apeswap-polygon.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "matic", 3 | "factoryAddress": "0xCf083Be4164828f00cAE704EC15a36D711491284", 4 | "factoryStartBlock": 15298801, 5 | "factoryMappingPath": "apeswap.ts" 6 | } -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/config/auroraswap-aurora.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "aurora", 3 | "factoryAddress": "0xC5E1DaeC2ad401eBEBdd3E32516d90Ab251A3aA3", 4 | "factoryStartBlock": 55447057 5 | } 6 | -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/config/biswap-bsc.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "bsc", 3 | "factoryAddress": "0x858E3312ed3A876947EA49d572A7C42DE08af7EE", 4 | "factoryStartBlock": 7664646, 5 | "factoryMappingPath": "biswap.ts" 6 | } -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/config/cometh-polygon.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "matic", 3 | "factoryAddress": "0x800b052609c355cA8103E06F022aA30647eAd60a", 4 | "factoryStartBlock": 11633169, 5 | "factoryMappingPath": "cometh.ts" 6 | } -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/config/pancakeswap-bsc.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "bsc", 3 | "factoryAddress": "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73", 4 | "factoryStartBlock": 6809737, 5 | "factoryMappingPath": "pancakeswap.ts" 6 | } 7 | -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/config/pangolin-avalanche.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "avalanche", 3 | "factoryAddress": "0xefa94DE7a4656D787667C749f7E1223D71E9FD88", 4 | "factoryStartBlock": 56877, 5 | "factoryMappingPath": "pangolin.ts" 6 | } -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/config/quickswap-polygon.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "matic", 3 | "factoryAddress": "0x5757371414417b8C6CAad45bAeF941aBc7d3Ab32", 4 | "factoryStartBlock": 4931780, 5 | "factoryMappingPath": "quickswap.ts" 6 | } 7 | -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/config/sushiswap-arbitrum.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "arbitrum-one", 3 | "factoryAddress": "0xc35DADB65012eC5796536bD9864eD8773aBc74C4", 4 | "factoryStartBlock": 70, 5 | "factoryMappingPath": "sushiswap.ts" 6 | } -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/config/sushiswap-avalanche.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "avalanche", 3 | "factoryAddress": "0xc35DADB65012eC5796536bD9864eD8773aBc74C4", 4 | "factoryStartBlock": 506190, 5 | "factoryMappingPath": "sushiswap.ts" 6 | } -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/config/sushiswap-bsc.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "bsc", 3 | "factoryAddress": "0xc35DADB65012eC5796536bD9864eD8773aBc74C4", 4 | "factoryStartBlock": 5205068, 5 | "factoryMappingPath": "sushiswap.ts" 6 | } 7 | -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/config/sushiswap-celo.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "celo", 3 | "factoryAddress": "0xc35DADB65012eC5796536bD9864eD8773aBc74C4", 4 | "factoryStartBlock": 7253488, 5 | "factoryMappingPath": "sushiswap.ts" 6 | } -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/config/sushiswap-fantom.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "fantom", 3 | "factoryAddress": "0xc35DADB65012eC5796536bD9864eD8773aBc74C4", 4 | "factoryStartBlock": 2457879, 5 | "factoryMappingPath": "sushiswap.ts" 6 | } -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/config/sushiswap-mainnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "mainnet", 3 | "factoryAddress": "0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac", 4 | "factoryStartBlock": 10794228, 5 | "factoryMappingPath": "sushiswap.ts" 6 | } -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/config/sushiswap-polygon.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "matic", 3 | "factoryAddress": "0xc35DADB65012eC5796536bD9864eD8773aBc74C4", 4 | "factoryStartBlock": 11333217, 5 | "factoryMappingPath": "sushiswap.ts" 6 | } -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/config/sushiswap-xdai.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "xdai", 3 | "factoryAddress": "0xc35DADB65012eC5796536bD9864eD8773aBc74C4", 4 | "factoryStartBlock": 14735904, 5 | "factoryMappingPath": "sushiswap.ts" 6 | } -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/config/traderjoe-avalanche.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "avalanche", 3 | "factoryAddress": "0x9Ad6C38BE94206cA50bb0d90783181662f0Cfa10", 4 | "factoryStartBlock": 2486392, 5 | "factoryMappingPath": "traderjoe.ts" 6 | } -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/config/trisolaris-aurora.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "aurora", 3 | "factoryAddress": "0xc66F594268041dB60507F00703b152492fb176E7", 4 | "factoryStartBlock": 49000000, 5 | "factoryMappingPath": "trisolaris.ts" 6 | } -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/config/uniswap-v2-mainnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "mainnet", 3 | "factoryAddress": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f", 4 | "factoryStartBlock": 10000834, 5 | "factoryMappingPath": "uniswap.ts" 6 | } 7 | -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/config/wannaswap-aurora.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "aurora", 3 | "factoryAddress": "0x7928D4FeA7b2c90C732c10aFF59cf403f0C38246", 4 | "factoryStartBlock": 54112812, 5 | "factoryMappingPath": "wannaswap.ts" 6 | } -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/schema.graphql: -------------------------------------------------------------------------------- 1 | type MarketDayData @entity { 2 | " marketAddress + dayId " 3 | id: ID! 4 | 5 | " first trade of the day timestamp " 6 | timestamp: BigInt! 7 | 8 | " market id - pair address " 9 | market: String! 10 | 11 | "amount of input tokens swapped in " 12 | inputTokensDailySwapInVolume: [String!]! 13 | 14 | " amount of input tokens swapped out " 15 | inputTokensDailySwapOutVolume: [String!]! 16 | 17 | " total amount of reserves per input token " 18 | inputTokenTotalBalances: [String!]! 19 | 20 | " reserve amount per input token this day " 21 | inputTokenDailyInflow: [String!]! 22 | 23 | " reserve amount per input token this day " 24 | inputTokenDailyOutflow: [String!]! 25 | 26 | " total balance of LP tokens " 27 | outputTokenTotalBalance: BigInt! 28 | 29 | " amount of LP tokens minted this day " 30 | outputTokenDailyInflowVolume: BigInt! 31 | 32 | " amount of LP tokens burned this day " 33 | outputTokenDailyOutflowVolume: BigInt! 34 | 35 | " fee percentage, applied to swap-in amount, taken by protocol " 36 | protocolFee: BigInt! 37 | 38 | " amount of fees generated this day, per token " 39 | feesGenerated: [String!]! 40 | 41 | " number of TXs this day swap " 42 | dailySwapTXs: BigInt! 43 | 44 | " number of TXs this day mint " 45 | dailyMintTXs: BigInt! 46 | 47 | " number of TXs this day burn " 48 | dailyBurnTXs: BigInt! 49 | 50 | " dayId - timestamp/86400 " 51 | dayId: BigInt! 52 | } 53 | 54 | ############# Uniswap specific entities 55 | 56 | type Pair @entity { 57 | " pair contract address " 58 | id: ID! 59 | 60 | " dex factory address " 61 | factory: String! 62 | 63 | " token0 address " 64 | token0: String! 65 | 66 | " token1 address " 67 | token1: String! 68 | 69 | " balance of token0 " 70 | reserve0: BigInt! 71 | 72 | " balance of token1 " 73 | reserve1: BigInt! 74 | 75 | " balance of LP tokens " 76 | totalSupply: BigInt! 77 | 78 | " pair creation block " 79 | blockNumber: BigInt! 80 | 81 | " pair creation timestamp " 82 | timestamp: BigInt! 83 | } 84 | -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/src/uniswapV2Factory.ts: -------------------------------------------------------------------------------- 1 | import { BigInt, DataSourceContext } from "@graphprotocol/graph-ts"; 2 | import { Pair } from "../generated/schema"; 3 | import { UniswapV2Pair } from "../generated/templates"; 4 | import { PairCreated } from "../generated/UniswapV2Factory/UniswapV2Factory"; 5 | import { FEE_30_BASE_POINTS, protocolToFee } from "./constants"; 6 | 7 | /** 8 | * Create Pair entity and start indexing pair contract 9 | * @param event 10 | */ 11 | export function handlePairCreated(event: PairCreated): void { 12 | // Create a tokens and market entity 13 | let token0 = event.params.token0.toHexString(); 14 | let token1 = event.params.token1.toHexString(); 15 | 16 | // Create pair 17 | let pair = new Pair(event.params.pair.toHexString()); 18 | pair.factory = event.address.toHexString(); 19 | pair.token0 = token0; 20 | pair.token1 = token1; 21 | pair.totalSupply = BigInt.fromI32(0); 22 | pair.reserve0 = BigInt.fromI32(0); 23 | pair.reserve1 = BigInt.fromI32(0); 24 | pair.blockNumber = event.block.number; 25 | pair.timestamp = event.block.timestamp; 26 | pair.save(); 27 | 28 | // Start listening for market events 29 | let context = new DataSourceContext(); 30 | context.setBigInt("protocolFee", getProtocolFee(event.address.toHexString())); 31 | UniswapV2Pair.createWithContext(event.params.pair, context); 32 | } 33 | 34 | /** 35 | * Get protocol's swap fee by looking at static mapping in constants 36 | * @param address 37 | * @returns 38 | */ 39 | function getProtocolFee(address: string): BigInt { 40 | let fee = protocolToFee.get(address); 41 | 42 | if (fee == null) { 43 | // if not found, use Uniswap default of 0.3% swap fee (30 bps) 44 | fee = BigInt.fromI32(FEE_30_BASE_POINTS); 45 | } 46 | 47 | return fee as BigInt; 48 | } 49 | -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/src/utils.ts: -------------------------------------------------------------------------------- 1 | import { BigInt } from "@graphprotocol/graph-ts"; 2 | 3 | /** 4 | * Account's balance of specific token 5 | * 6 | * @export 7 | * @class TokenBalance 8 | */ 9 | export class TokenBalance { 10 | tokenAddress: string; 11 | accountAddress: string; 12 | balance: BigInt; 13 | 14 | constructor(tokenAddress: string, accountAddress: string, balance: BigInt) { 15 | this.tokenAddress = tokenAddress; 16 | this.accountAddress = accountAddress; 17 | this.balance = balance; 18 | } 19 | 20 | // Does not modify this or b TokenBalance, return new TokenBalance 21 | add(b: TokenBalance): TokenBalance { 22 | if (this.tokenAddress == b.tokenAddress) { 23 | return new TokenBalance(this.tokenAddress, this.accountAddress, this.balance.plus(b.balance)); 24 | } else { 25 | return this; 26 | } 27 | } 28 | 29 | toString(): string { 30 | return this.tokenAddress 31 | .concat("|") 32 | .concat(this.accountAddress) 33 | .concat("|") 34 | .concat(this.balance.toString()); 35 | } 36 | 37 | static fromString(tb: string): TokenBalance { 38 | let parts = tb.split("|"); 39 | let tokenAddress = parts[0]; 40 | let accountAddress = parts[1]; 41 | let balance = BigInt.fromString(parts[2]); 42 | return new TokenBalance(tokenAddress, accountAddress, balance); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /protocol-volumes/uniswap-v2/subgraph.template.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.2 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: UniswapV2Factory 7 | network: {{network}} 8 | source: 9 | address: "{{factoryAddress}}" 10 | abi: UniswapV2Factory 11 | startBlock: {{factoryStartBlock}} 12 | mapping: 13 | kind: ethereum/events 14 | apiVersion: 0.0.4 15 | language: wasm/assemblyscript 16 | entities: 17 | - Block 18 | - Account 19 | - Token 20 | - Market 21 | - Pair 22 | abis: 23 | - name: ERC20 24 | file: ./abis/IERC20.json 25 | - name: UniswapV2Factory 26 | file: ./abis/IUniswapV2Factory.json 27 | eventHandlers: 28 | - event: PairCreated(indexed address,indexed address,address,uint256) 29 | handler: handlePairCreated 30 | file: ./src/uniswapV2Factory.ts 31 | templates: 32 | - kind: ethereum/contract 33 | name: UniswapV2Pair 34 | network: {{network}} 35 | source: 36 | abi: UniswapV2Pair 37 | mapping: 38 | kind: ethereum/events 39 | apiVersion: 0.0.4 40 | language: wasm/assemblyscript 41 | file: ./src/uniswapV2Pair.ts 42 | entities: 43 | - Market 44 | - Pair 45 | - MarketData 46 | abis: 47 | - name: ERC20 48 | file: ./abis/IERC20.json 49 | - name: UniswapV2Factory 50 | file: ./abis/IUniswapV2Factory.json 51 | - name: UniswapV2Pair 52 | file: ./abis/IUniswapV2Pair.json 53 | eventHandlers: 54 | - event: Transfer(indexed address,indexed address,uint256) 55 | handler: handleTransfer 56 | - event: Sync(uint112,uint112) 57 | handler: handleSync 58 | - event: Mint(indexed address,uint256,uint256) 59 | handler: handleMint 60 | - event: Burn(indexed address,uint256,uint256,indexed address) 61 | handler: handleBurn 62 | - event: Swap(indexed address,uint256,uint256,uint256,uint256,indexed address) 63 | handler: handleSwap -------------------------------------------------------------------------------- /ref-finance-farms/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | package-lock.json 107 | 108 | build/ 109 | generated/ -------------------------------------------------------------------------------- /ref-finance-farms/README.md: -------------------------------------------------------------------------------- 1 | ## Ref Finance Subgraph development docs 2 | 3 | We will be documenting our learning from NEAR subgraph development process for ref finance protocol. 4 | 5 | - NEAR subgraph listner gets triggered for account creation, contract deployment and new function call. This allows us to create entity to track constructor parameters that will be used to cumpute values from user interaction like protocol fee. 6 | 7 | - To be able to connect multiple receipts of a single transaction we can use `outcome.receiptIds` which is same as `execution_outcome.produced_receipt_id` as defined in official NEAR indexer schema at https://github.com/near/near-indexer-for-explorer/blob/master/docs/near-indexer-for-explorer-db.png 8 | 9 | - Return value of a function can be is included in outcome.status, it can either 10 | 11 | - A value if the function returns a value, which can be parsed by converting outcome.status to bytes and then parsed as JSON 12 | - A receipt id if the function returns a promise, which can be parsed by converting outcome.status to a receipt id 13 | 14 | - We may need to adapt common.ts to NEAR blockchain because it has following limitations 15 | 16 | - NEAR subgraph does not support contract calls for view function 17 | - NEAR subgraph does not support ABI specification -------------------------------------------------------------------------------- /ref-finance-farms/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Ref Finance", 3 | "license": "UNLICENSED", 4 | "scripts": { 5 | "codegen": "graph codegen", 6 | "build": "graph build", 7 | "deploy": "graph deploy --node https://api.thegraph.com/deploy/ simplefi-finance/ref-finance-farms-near", 8 | "create-local": "graph create --node http://localhost:8020/ simplefi-finance/ref-finance-farms-near", 9 | "remove-local": "graph remove --node http://localhost:8020/ simplefi-finance/ref-finance-farms-near", 10 | "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 simplefi-finance/ref-finance-farms-near" 11 | }, 12 | "dependencies": { 13 | "@graphprotocol/graph-cli": "0.26.0", 14 | "@graphprotocol/graph-ts": "0.24.1" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ref-finance-farms/src/constants.ts: -------------------------------------------------------------------------------- 1 | export namespace Blockchain { 2 | export const ETHEREUM = "ETHEREUM" 3 | export const BSC = "BSC" 4 | export const XDAI = "XDAI" 5 | export const POLYGON = "POLYGON" 6 | export const OPTIMISM = "OPTIMISM" 7 | export const AVALANCHE = "AVALANCE" 8 | export const NEAR = "NEAR" 9 | } 10 | 11 | export namespace TokenStandard { 12 | export const NEP141 = "NEP141" 13 | export const NEP171 = "NEP171" 14 | export const NEP245 = "NEP245" 15 | } 16 | 17 | export namespace ProtocolName { 18 | export const REF_FINANCE = "REF_FINANCE" 19 | } 20 | 21 | export namespace ProtocolType { 22 | export const STAKING = "STAKING" 23 | export const LENDING = "LENDING" 24 | export const EXCHANGE = "EXCHANGE" 25 | export const INSURANCE = "INSURANCE" 26 | export const STABLECOIN = "STABLECOIN" 27 | export const DERIVATIVE = "DERIVATIVE" 28 | export const SYNTHETIC_TOKEN = "SYNTHETIC_TOKEN" 29 | export const TOKEN_MANAGEMENT = "TOKEN_MANAGEMENT" 30 | export const PREDICTION_MARKET = "PREDICTION_MARKET" 31 | } 32 | 33 | export namespace PositionType { 34 | export const INVESTMENT = "INVESTMENT" 35 | export const DEBT = "DEBT" 36 | } 37 | 38 | export namespace TransactionType { 39 | export const INVEST = "INVEST" 40 | export const REDEEM = "REDEEM" 41 | export const BORROW = "BORROW" 42 | export const REPAY = "REPAY" 43 | export const TRANSFER_IN = "TRANSFER_IN" 44 | export const TRANSFER_OUT = "TRANSFER_OUT" 45 | } 46 | -------------------------------------------------------------------------------- /ref-finance-farms/src/farm/tokenReceiver.ts: -------------------------------------------------------------------------------- 1 | import { BigInt, json, JSONValue, near } from "@graphprotocol/graph-ts"; 2 | import { addRewardToSimpleFarm, depositSeedSimpleFarm } from "./farm"; 3 | 4 | /** 5 | fn ft_on_transfer( 6 | &mut self, 7 | sender_id: ValidAccountId, 8 | amount: U128, 9 | msg: String, 10 | ) -> PromiseOrValue 11 | */ 12 | export function ftOnTransfer( 13 | functionCall: near.FunctionCallAction, 14 | receipt: near.ActionReceipt, 15 | outcome: near.ExecutionOutcome, 16 | block: near.Block 17 | ): void { 18 | const args = json.fromBytes(functionCall.args).toObject(); 19 | const senderId = (args.get("sender_id") as JSONValue).toString(); 20 | const amount = BigInt.fromString((args.get("amount") as JSONValue).toString()); 21 | const msg = (args.get("msg") as JSONValue).toString(); 22 | 23 | if (msg == "") { 24 | depositSeedSimpleFarm(receipt, outcome, block, receipt.predecessorId, senderId, amount, "FT"); 25 | } else { 26 | addRewardToSimpleFarm(msg, amount, BigInt.fromU64(block.header.timestampNanosec)); 27 | } 28 | } 29 | 30 | /** 31 | fn mft_on_transfer( 32 | &mut self, 33 | token_id: String, 34 | sender_id: AccountId, 35 | amount: U128, 36 | msg: String, 37 | ) -> PromiseOrValue 38 | */ 39 | export function mftOnTransfer( 40 | functionCall: near.FunctionCallAction, 41 | receipt: near.ActionReceipt, 42 | outcome: near.ExecutionOutcome, 43 | block: near.Block 44 | ): void { 45 | const args = json.fromBytes(functionCall.args).toObject(); 46 | const tokenId = (args.get("token_id") as JSONValue).toString(); 47 | const senderId = (args.get("sender_id") as JSONValue).toString(); 48 | const amount = BigInt.fromString((args.get("amount") as JSONValue).toString()); 49 | const msg = (args.get("msg") as JSONValue).toString(); 50 | 51 | // This will receipt panic and fail if it's called with a non MFT 52 | // Therefore we can safly assume the tokenId to be a MFT format poolId 53 | const poolId = tokenId.slice(1); 54 | const seedId = receipt.predecessorId.concat("@").concat(poolId); 55 | 56 | if (msg == "") { 57 | depositSeedSimpleFarm(receipt, outcome, block, seedId, senderId, amount, "MFT"); 58 | } 59 | // No need to handle non empty case because receipt will panic and fail 60 | } -------------------------------------------------------------------------------- /ref-finance-farms/src/farm/util.ts: -------------------------------------------------------------------------------- 1 | import { BigInt } from "@graphprotocol/graph-ts"; 2 | 3 | const NANO = BigInt.fromI32(10).pow(9); 4 | 5 | export function parseSeedId(seedId: string): string[] { 6 | const parsedSeed: string[] = seedId.split("@"); 7 | if (parsedSeed.length == 1) { 8 | parsedSeed[1] = parsedSeed[0]; 9 | } 10 | return parsedSeed; 11 | } 12 | 13 | export function parseFarmId(farmId: string): string[] { 14 | return farmId.split("#"); 15 | } 16 | 17 | export function toSec(timestamp: BigInt): BigInt { 18 | return timestamp.div(NANO); 19 | } 20 | 21 | export function toNanoSec(timestamp: BigInt): BigInt { 22 | return timestamp.times(NANO); 23 | } -------------------------------------------------------------------------------- /ref-finance-farms/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.4 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: near 6 | name: RefFarmingV2 7 | network: near-mainnet 8 | source: 9 | account: "v2.ref-farming.near" 10 | startBlock: 46746775 11 | mapping: 12 | apiVersion: 0.0.5 13 | language: wasm/assemblyscript 14 | entities: 15 | - Account 16 | receiptHandlers: 17 | - handler: handleReceipt 18 | file: ./src/near.ts 19 | -------------------------------------------------------------------------------- /ref-finance-farms/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", 3 | "include": ["src"] 4 | } 5 | -------------------------------------------------------------------------------- /ref-finance/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | package-lock.json 107 | 108 | build/ 109 | generated/ -------------------------------------------------------------------------------- /ref-finance/README.md: -------------------------------------------------------------------------------- 1 | ## Ref Finance Subgraph development docs 2 | 3 | We will be documenting our learning from NEAR subgraph development process for ref finance protocol. 4 | 5 | - NEAR subgraph listner gets triggered for account creation, contract deployment and new function call. This allows us to create entity to track constructor parameters that will be used to cumpute values from user interaction like protocol fee. 6 | 7 | - To be able to connect multiple receipts of a single transaction we can use `outcome.receiptIds` which is same as `execution_outcome.produced_receipt_id` as defined in official NEAR indexer schema at https://github.com/near/near-indexer-for-explorer/blob/master/docs/near-indexer-for-explorer-db.png 8 | 9 | - Return value of a function can be is included in outcome.status, it can either 10 | 11 | - A value if the function returns a value, which can be parsed by converting outcome.status to bytes and then parsed as JSON 12 | - A receipt id if the function returns a promise, which can be parsed by converting outcome.status to a receipt id 13 | 14 | - We may need to adapt common.ts to NEAR blockchain because it has following limitations 15 | 16 | - NEAR subgraph does not support contract calls for view function 17 | - NEAR subgraph does not support ABI specification -------------------------------------------------------------------------------- /ref-finance/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Ref Finance", 3 | "license": "UNLICENSED", 4 | "scripts": { 5 | "codegen": "graph codegen", 6 | "build": "graph build", 7 | "deploy": "graph deploy --node https://api.thegraph.com/deploy/ simplefi-finance/ref-finance-v2-near", 8 | "create-local": "graph create --node http://localhost:8020/ simplefi-finance/ref-finance-v2-near", 9 | "remove-local": "graph remove --node http://localhost:8020/ simplefi-finance/ref-finance-v2-near", 10 | "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 simplefi-finance/ref-finance-v2-near" 11 | }, 12 | "dependencies": { 13 | "@graphprotocol/graph-cli": "0.26.0", 14 | "@graphprotocol/graph-ts": "0.24.1" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ref-finance/src/constants.ts: -------------------------------------------------------------------------------- 1 | export namespace Blockchain { 2 | export const ETHEREUM = "ETHEREUM" 3 | export const BSC = "BSC" 4 | export const XDAI = "XDAI" 5 | export const POLYGON = "POLYGON" 6 | export const OPTIMISM = "OPTIMISM" 7 | export const AVALANCHE = "AVALANCE" 8 | export const NEAR = "NEAR" 9 | } 10 | 11 | export namespace TokenStandard { 12 | export const NEP141 = "NEP141" 13 | export const NEP171 = "NEP171" 14 | export const NEP245 = "NEP245" 15 | } 16 | 17 | export namespace ProtocolName { 18 | export const REF_FINANCE = "REF_FINANCE" 19 | } 20 | 21 | export namespace ProtocolType { 22 | export const STAKING = "STAKING" 23 | export const LENDING = "LENDING" 24 | export const EXCHANGE = "EXCHANGE" 25 | export const INSURANCE = "INSURANCE" 26 | export const STABLECOIN = "STABLECOIN" 27 | export const DERIVATIVE = "DERIVATIVE" 28 | export const SYNTHETIC_TOKEN = "SYNTHETIC_TOKEN" 29 | export const TOKEN_MANAGEMENT = "TOKEN_MANAGEMENT" 30 | export const PREDICTION_MARKET = "PREDICTION_MARKET" 31 | } 32 | 33 | export namespace PositionType { 34 | export const INVESTMENT = "INVESTMENT" 35 | export const DEBT = "DEBT" 36 | } 37 | 38 | export namespace TransactionType { 39 | export const INVEST = "INVEST" 40 | export const REDEEM = "REDEEM" 41 | export const BORROW = "BORROW" 42 | export const REPAY = "REPAY" 43 | export const TRANSFER_IN = "TRANSFER_IN" 44 | export const TRANSFER_OUT = "TRANSFER_OUT" 45 | } 46 | -------------------------------------------------------------------------------- /ref-finance/src/exchange/accountDeposit.ts: -------------------------------------------------------------------------------- 1 | import { near } from "@graphprotocol/graph-ts"; 2 | 3 | /** 4 | pub fn withdraw( 5 | &mut self, 6 | token_id: ValidAccountId, 7 | amount: U128, 8 | unregister: Option, 9 | ) -> Promise 10 | */ 11 | export function withdraw( 12 | functionCall: near.FunctionCallAction, 13 | receipt: near.ActionReceipt, 14 | outcome: near.ExecutionOutcome, 15 | block: near.Block 16 | ): void { 17 | 18 | } 19 | 20 | /** 21 | pub fn exchange_callback_post_withdraw( 22 | &mut self, 23 | token_id: AccountId, 24 | sender_id: AccountId, 25 | amount: U128, 26 | ) 27 | */ 28 | export function callbakPostWithdraw( 29 | functionCall: near.FunctionCallAction, 30 | receipt: near.ActionReceipt, 31 | outcome: near.ExecutionOutcome, 32 | block: near.Block 33 | ): void { 34 | 35 | } -------------------------------------------------------------------------------- /ref-finance/src/exchange/commonExchange.ts: -------------------------------------------------------------------------------- 1 | import { BigInt, json, JSONValue, near } from "@graphprotocol/graph-ts"; 2 | import { Share } from "../../generated/schema"; 3 | import { parseNullableJSONAtrribute } from "../common"; 4 | 5 | 6 | export function getOrCreateShare(accountId: string, poolId: string): Share { 7 | const sahreId = accountId.concat("-").concat(poolId); 8 | let share = Share.load(sahreId); 9 | if (share == null) { 10 | share = new Share(sahreId); 11 | share.accountId = accountId; 12 | share.poolId = poolId; 13 | share.amount = BigInt.fromI32(0); 14 | share.save(); 15 | } 16 | 17 | return share as Share; 18 | } 19 | 20 | export class SwapAction { 21 | poolId: BigInt 22 | tokenIn: string 23 | amountIn: BigInt | null 24 | tokenOut: string 25 | referralId: string | null 26 | 27 | constructor(jv: JSONValue) { 28 | const obj = jv.toObject(); 29 | this.poolId = (obj.get("pool_id") as JSONValue).toBigInt(); 30 | this.tokenIn = (obj.get("token_in") as JSONValue).toString(); 31 | this.amountIn = parseNullableJSONAtrribute( 32 | obj, 33 | "amount_in", 34 | (jv) => BigInt.fromString(jv.toString()) 35 | ); 36 | this.tokenOut = (obj.get("token_out") as JSONValue).toString(); 37 | this.referralId = null; 38 | } 39 | 40 | toString(): string { 41 | const ai = this.amountIn; 42 | const as = ai ? ai.toString() : "null"; 43 | const ri = this.referralId; 44 | const rs = ri ? ri : "null"; 45 | return this.poolId.toString().concat("|").concat(this.tokenIn).concat("|").concat(as).concat("|").concat(this.tokenOut).concat("|").concat(rs); 46 | } 47 | } -------------------------------------------------------------------------------- /ref-finance/src/exchange/tokenReceiver.ts: -------------------------------------------------------------------------------- 1 | import { BigInt, json, JSONValue, near } from "@graphprotocol/graph-ts"; 2 | import { parseNullableJSONAtrribute } from "../common"; 3 | import { SwapAction } from "./commonExchange"; 4 | import { executeSwapAction } from "./exchange"; 5 | 6 | /** 7 | fn ft_on_transfer( 8 | &mut self, 9 | sender_id: ValidAccountId, 10 | amount: U128, 11 | msg: String, 12 | ) -> PromiseOrValue 13 | */ 14 | export function ftOnTransfer( 15 | functionCall: near.FunctionCallAction, 16 | receipt: near.ActionReceipt, 17 | outcome: near.ExecutionOutcome, 18 | block: near.Block 19 | ): void { 20 | const args = json.fromBytes(functionCall.args).toObject(); 21 | const msg = (args.get("msg") as JSONValue).toString(); 22 | const amount = BigInt.fromString((args.get("amount") as JSONValue).toString()); 23 | 24 | if (msg == "") { 25 | return 26 | } 27 | 28 | const msgArgs = json.fromString(msg).toObject(); 29 | const actions = (msgArgs.get("actions") as JSONValue).toArray().map(jv => new SwapAction(jv)); 30 | const referralId: string | null = parseNullableJSONAtrribute( 31 | msgArgs, 32 | "referral_id", 33 | (jv) => jv.toString() 34 | ); 35 | let result: BigInt = amount; 36 | 37 | for (let i = 0; i < actions.length; i++) { 38 | actions[i].amountIn = actions[i].amountIn ? actions[i].amountIn : result; 39 | actions[i].referralId = referralId; 40 | result = executeSwapAction(actions[i], receipt, outcome, block); 41 | } 42 | } -------------------------------------------------------------------------------- /ref-finance/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.4 2 | graft: 3 | base: QmPqDoer4C7FY4JZ6FjDbLQKC5zhgLTWxEPJETDrLXQVVD 4 | block: 55263101 5 | features: 6 | - grafting 7 | schema: 8 | file: ./schema.graphql 9 | dataSources: 10 | - kind: near 11 | name: RefFinanceV2 12 | network: near-mainnet 13 | source: 14 | account: "v2.ref-finance.near" 15 | startBlock: 45753042 16 | mapping: 17 | apiVersion: 0.0.5 18 | language: wasm/assemblyscript 19 | entities: 20 | - Account 21 | receiptHandlers: 22 | - handler: handleReceipt 23 | file: ./src/near.ts 24 | -------------------------------------------------------------------------------- /ref-finance/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", 3 | "include": ["src"] 4 | } 5 | -------------------------------------------------------------------------------- /stake-dao/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | package-lock.json 107 | 108 | build/ 109 | generated/ 110 | -------------------------------------------------------------------------------- /stake-dao/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simplefi-stake-dao-fixed", 3 | "license": "UNLICENSED", 4 | "scripts": { 5 | "codegen": "graph codegen", 6 | "build": "graph build", 7 | "deploy": "graph deploy --node https://api.thegraph.com/deploy/ simplefi-finance/stake-dao", 8 | "create-local": "graph create --node http://localhost:8020/ simplefi-finance/stake-dao", 9 | "remove-local": "graph remove --node http://localhost:8020/ simplefi-finance/stake-dao", 10 | "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 simplefi-finance/stake-dao" 11 | }, 12 | "dependencies": { 13 | "@graphprotocol/graph-cli": "0.21.1", 14 | "@graphprotocol/graph-ts": "0.20.0" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /stake-dao/src/constants.ts: -------------------------------------------------------------------------------- 1 | export namespace Blockchain { 2 | export const ETHEREUM = "ETHEREUM" 3 | export const BSC = "BSC" 4 | export const XDAI = "XDAI" 5 | export const POLYGON = "POLYGON" 6 | export const OPTIMISM = "OPTIMISM" 7 | export const AVALANCHE = "AVALANCE" 8 | export const NEAR = "NEAR" 9 | } 10 | 11 | export namespace TokenStandard { 12 | export const ERC20 = "ERC20" 13 | export const ERC721 = "ERC721" 14 | export const ERC1155 = "ERC1155" 15 | } 16 | 17 | export namespace ProtocolName { 18 | export const UNISWAP_V2 = "UNISWAP_V2" 19 | export const CURVE_POOL = "CURVE_POOL" 20 | export const STAKE_DAO = "STAKE_DAO" 21 | } 22 | 23 | export namespace ProtocolType { 24 | export const STAKING = "STAKING" 25 | export const LENDING = "LENDING" 26 | export const EXCHANGE = "EXCHANGE" 27 | export const INSURANCE = "INSURANCE" 28 | export const STABLECOIN = "STABLECOIN" 29 | export const DERIVATIVE = "DERIVATIVE" 30 | export const SYNTHETIC_TOKEN = "SYNTHETIC_TOKEN" 31 | export const TOKEN_MANAGEMENT = "TOKEN_MANAGEMENT" 32 | export const PREDICTION_MARKET = "PREDICTION_MARKET" 33 | export const LP_FARMING = "LP_FARMING" 34 | } 35 | 36 | export namespace PositionType { 37 | export const INVESTMENT = "INVESTMENT" 38 | export const DEBT = "DEBT" 39 | } 40 | 41 | export namespace TransactionType { 42 | export const INVEST = "INVEST" 43 | export const REDEEM = "REDEEM" 44 | export const BORROW = "BORROW" 45 | export const REPAY = "REPAY" 46 | export const TRANSFER_IN = "TRANSFER_IN" 47 | export const TRANSFER_OUT = "TRANSFER_OUT" 48 | } -------------------------------------------------------------------------------- /stake-dao/src/stakeDAOController.ts: -------------------------------------------------------------------------------- 1 | import { BigInt, DataSourceContext, ethereum } from "@graphprotocol/graph-ts" 2 | import { 3 | TokenStrategy as TokenStrategyEntity, 4 | Vault as VaultEntity, 5 | VaultInputToken as VaultInputTokenEntity 6 | } from "../generated/schema" 7 | import { 8 | SetStrategyCall, 9 | SetVaultCall 10 | } from "../generated/StakeDAOController/StakeDAOController" 11 | import { 12 | StakeDAOVault, 13 | StakeDAOVaultInputToken 14 | } from "../generated/templates" 15 | import { 16 | getOrCreateERC20Token, 17 | getOrCreateMarket 18 | } from "./common" 19 | import { ProtocolName, ProtocolType } from "./constants" 20 | 21 | export function handleSetVault(call: SetVaultCall): void { 22 | let fakeEvent = new ethereum.Event() 23 | fakeEvent.block = call.block 24 | let token = getOrCreateERC20Token(fakeEvent, call.inputs._token) 25 | let vaultToken = getOrCreateERC20Token(fakeEvent, call.inputs._vault) 26 | 27 | let vault = new VaultEntity(call.inputs._vault.toHexString()) 28 | vault.token = token.id 29 | vault.controller = call.to.toHexString() 30 | vault.balance = BigInt.fromI32(0) 31 | vault.totalSupply = BigInt.fromI32(0) 32 | vault.save() 33 | 34 | let vaultInputToken = new VaultInputTokenEntity(token.id) 35 | vaultInputToken.vault = vault.id 36 | vaultInputToken.save() 37 | 38 | // Create market 39 | getOrCreateMarket( 40 | fakeEvent, 41 | call.inputs._vault, 42 | ProtocolName.STAKE_DAO, 43 | ProtocolType.TOKEN_MANAGEMENT, 44 | [token], 45 | vaultToken, 46 | [] 47 | ) 48 | 49 | let context = new DataSourceContext() 50 | context.setString('vaultId', vault.id) 51 | StakeDAOVault.createWithContext(call.inputs._vault, context) 52 | StakeDAOVaultInputToken.createWithContext(call.inputs._token, context) 53 | } 54 | 55 | export function handleSetStrategy(call: SetStrategyCall): void { 56 | let tokenStrategy = new TokenStrategyEntity(call.inputs._token.toHexString()) 57 | tokenStrategy.strategy = call.inputs._strategy.toHexString() 58 | tokenStrategy.save() 59 | } -------------------------------------------------------------------------------- /staking-rewards/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SimpleFi-finance/subgraphs/534fe1ed7a4a8f9dec675ade7ae7cf912d96a801/staking-rewards/.DS_Store -------------------------------------------------------------------------------- /staking-rewards/.gitignore: -------------------------------------------------------------------------------- 1 | subgraph.yaml 2 | 3 | # Logs 4 | logs 5 | *.log 6 | npm-debug.log* 7 | yarn-debug.log* 8 | yarn-error.log* 9 | lerna-debug.log* 10 | 11 | # Diagnostic reports (https://nodejs.org/api/report.html) 12 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 13 | 14 | # Runtime data 15 | pids 16 | *.pid 17 | *.seed 18 | *.pid.lock 19 | 20 | # Directory for instrumented libs generated by jscoverage/JSCover 21 | lib-cov 22 | 23 | # Coverage directory used by tools like istanbul 24 | coverage 25 | *.lcov 26 | 27 | # nyc test coverage 28 | .nyc_output 29 | 30 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 31 | .grunt 32 | 33 | # Bower dependency directory (https://bower.io/) 34 | bower_components 35 | 36 | # node-waf configuration 37 | .lock-wscript 38 | 39 | # Compiled binary addons (https://nodejs.org/api/addons.html) 40 | build/Release 41 | 42 | # Dependency directories 43 | node_modules/ 44 | jspm_packages/ 45 | 46 | # TypeScript v1 declaration files 47 | typings/ 48 | 49 | # TypeScript cache 50 | *.tsbuildinfo 51 | 52 | # Optional npm cache directory 53 | .npm 54 | 55 | # Optional eslint cache 56 | .eslintcache 57 | 58 | # Microbundle cache 59 | .rpt2_cache/ 60 | .rts2_cache_cjs/ 61 | .rts2_cache_es/ 62 | .rts2_cache_umd/ 63 | 64 | # Optional REPL history 65 | .node_repl_history 66 | 67 | # Output of 'npm pack' 68 | *.tgz 69 | 70 | # Yarn Integrity file 71 | .yarn-integrity 72 | 73 | # dotenv environment variables file 74 | .env 75 | .env.test 76 | 77 | # parcel-bundler cache (https://parceljs.org/) 78 | .cache 79 | 80 | # Next.js build output 81 | .next 82 | 83 | # Nuxt.js build / generate output 84 | .nuxt 85 | dist 86 | 87 | # Gatsby files 88 | .cache/ 89 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 90 | # https://nextjs.org/blog/next-9-1#public-directory-support 91 | # public 92 | 93 | # vuepress build output 94 | .vuepress/dist 95 | 96 | # Serverless directories 97 | .serverless/ 98 | 99 | # FuseBox cache 100 | .fusebox/ 101 | 102 | # DynamoDB Local files 103 | .dynamodb/ 104 | 105 | # TernJS port file 106 | .tern-port 107 | 108 | package-lock.json 109 | 110 | build/ 111 | generated/ 112 | -------------------------------------------------------------------------------- /staking-rewards/README.md: -------------------------------------------------------------------------------- 1 | ### StakingRewards 2 | 3 | Subgraph for Synthetix's StakingRewards contracts. Tracks user positions and rewards. 4 | 5 | It covers Synthetix contracts, but can be used for any StakingRewards fork on any chain 6 | -------------------------------------------------------------------------------- /staking-rewards/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "staking-rewards", 3 | "repository": { 4 | "type": "git", 5 | "url": "git+https://github.com/SimpleFi-finance/subgraphs.git" 6 | }, 7 | "author": "SimpleFi", 8 | "bugs": { 9 | "url": "https://github.com/SimpleFi-finance/subgraphs.git/issues" 10 | }, 11 | "scripts": { 12 | "codegen": "graph codegen", 13 | "build": "graph build", 14 | "clean": "rm -rf ./build && rm -rf ./generated", 15 | "prepare-mainnet": "cp templates/subgraph.mainnet.yaml subgraph.yaml && npm run codegen", 16 | "prepare-optimism": "cp templates/subgraph.optimism.yaml subgraph.yaml && npm run codegen", 17 | "deploy-mainnet": "npm run clean && npm run prepare-mainnet && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/synthetix-rewards", 18 | "deploy-optimism": "npm run clean && npm run prepare-optimism && graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/synthetix-rewards-optimism", 19 | "create-local": "graph create --node http://localhost:8020/ staking-rewards", 20 | "remove-local": "graph remove --node http://localhost:8020/ staking-rewards", 21 | "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 staking-rewards" 22 | }, 23 | "dependencies": { 24 | "@graphprotocol/graph-cli": "0.23.2", 25 | "@graphprotocol/graph-ts": "0.23.1" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /staking-rewards/src/lib/constants.ts: -------------------------------------------------------------------------------- 1 | import { Address } from "@graphprotocol/graph-ts"; 2 | 3 | export namespace Blockchain { 4 | export const ETHEREUM = "ETHEREUM"; 5 | export const BSC = "BSC"; 6 | export const XDAI = "XDAI"; 7 | export const POLYGON = "POLYGON"; 8 | export const OPTIMISM = "OPTIMISM"; 9 | export const AVALANCHE = "AVALANCE"; 10 | export const NEAR = "NEAR"; 11 | } 12 | 13 | export namespace TokenStandard { 14 | export const ERC20 = "ERC20"; 15 | export const ERC721 = "ERC721"; 16 | export const ERC1155 = "ERC1155"; 17 | } 18 | 19 | export namespace ProtocolName { 20 | export const UNISWAP_V2 = "UNISWAP_V2"; 21 | export const SYNTHETIX_STAKING_REWARDS = "SYNTHETIX_STAKING_REWARDS"; 22 | } 23 | 24 | export namespace ProtocolType { 25 | export const STAKING = "STAKING"; 26 | export const LENDING = "LENDING"; 27 | export const EXCHANGE = "EXCHANGE"; 28 | export const INSURANCE = "INSURANCE"; 29 | export const STABLECOIN = "STABLECOIN"; 30 | export const DERIVATIVE = "DERIVATIVE"; 31 | export const SYNTHETIC_TOKEN = "SYNTHETIC_TOKEN"; 32 | export const TOKEN_MANAGEMENT = "TOKEN_MANAGEMENT"; 33 | export const PREDICTION_MARKET = "PREDICTION_MARKET"; 34 | export const LP_FARMING = "LP_FARMING"; 35 | } 36 | 37 | export namespace PositionType { 38 | export const INVESTMENT = "INVESTMENT"; 39 | export const DEBT = "DEBT"; 40 | } 41 | 42 | export namespace TransactionType { 43 | export const INVEST = "INVEST"; 44 | export const REDEEM = "REDEEM"; 45 | export const BORROW = "BORROW"; 46 | export const REPAY = "REPAY"; 47 | export const TRANSFER_IN = "TRANSFER_IN"; 48 | export const TRANSFER_OUT = "TRANSFER_OUT"; 49 | } 50 | 51 | export const FARM_TOKEN_ADDRESS = Address.fromString("0xa0246c9032bc3a600820415ae600c6388619a14d"); 52 | -------------------------------------------------------------------------------- /staking-rewards/templates/subgraph.optimism.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.2 2 | schema: 3 | file: ./schema.graphql 4 | 5 | dataSources: 6 | - kind: ethereum/contract 7 | name: StakingRewardsSNXWETHUniswapV3 8 | network: optimism 9 | source: 10 | address: "0xfD49C7EE330fE060ca66feE33d49206eB96F146D" 11 | abi: StakingRewards 12 | startBlock: 2335790 13 | mapping: 14 | kind: ethereum/events 15 | apiVersion: 0.0.5 16 | language: wasm/assemblyscript 17 | entities: &staking_rewards_entities 18 | - Vault 19 | abis: &staking_rewards_abis 20 | - name: StakingRewards 21 | file: ./abis/StakingRewards.json 22 | - name: IERC20 23 | file: ./abis/IERC20.json 24 | eventHandlers: &staking_rewards_events 25 | - event: Staked(indexed address,uint256) 26 | handler: handleStaked 27 | - event: Withdrawn(indexed address,uint256) 28 | handler: handleWithdrawn 29 | - event: RewardPaid(indexed address,uint256) 30 | handler: handleRewardPaid 31 | file: ./src/stakingRewards.ts 32 | 33 | - kind: ethereum/contract 34 | name: StakingRewardssUSDDAIUniswapV3 35 | network: optimism 36 | source: 37 | address: "0x7E11c004d20b502729918687E6E6777b28499085" 38 | abi: StakingRewards 39 | startBlock: 2335788 40 | mapping: 41 | kind: ethereum/events 42 | apiVersion: 0.0.5 43 | language: wasm/assemblyscript 44 | entities: *staking_rewards_entities 45 | abis: *staking_rewards_abis 46 | eventHandlers: *staking_rewards_events 47 | file: ./src/stakingRewards.ts 48 | 49 | templates: 50 | - kind: ethereum/contract 51 | name: StakingRewards 52 | network: optimism 53 | source: 54 | abi: StakingRewards 55 | mapping: 56 | kind: ethereum/events 57 | apiVersion: 0.0.5 58 | language: wasm/assemblyscript 59 | entities: *staking_rewards_entities 60 | abis: *staking_rewards_abis 61 | eventHandlers: *staking_rewards_events 62 | file: ./src/stakingRewards.ts 63 | -------------------------------------------------------------------------------- /sushiswap-farms/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | package-lock.json 107 | 108 | build/ 109 | generated/ 110 | -------------------------------------------------------------------------------- /sushiswap-farms/README.md: -------------------------------------------------------------------------------- 1 | ## Sushi farms subgraph 2 | 3 | This subgraph is tracking state of user positions and market state of Sushiswap farms. Sushi farms are implemented by MasterChef contract. Currently there are 2 implementations - [V1](https://etherscan.io/address/0xc2edad668740f1aa35e4d8f227fb8e17dca888cd) and [V2](https://etherscan.io/address/0xef0881ec094552b2e128cf945ef17a6752b4ec5d). We are tracking both within single subgraph. 4 | 5 | ### Docs 6 | 7 | Developer subgraph docs: 8 | https://docs.simplefi.finance/subgraph-development-documentation/dashboard-integration 9 | 10 | Common subgraph schema: 11 | https://docs.simplefi.finance/subgraph-development-documentation/common-subgraph-schema 12 | 13 | Sushi Farms subgraph walkthrough: 14 | https://docs.simplefi.finance/sushi-farms-masterchef-subgraph 15 | -------------------------------------------------------------------------------- /sushiswap-farms/abis/IRewarder.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [ 4 | { 5 | "internalType": "uint256", 6 | "name": "pid", 7 | "type": "uint256" 8 | }, 9 | { 10 | "internalType": "address", 11 | "name": "user", 12 | "type": "address" 13 | }, 14 | { 15 | "internalType": "address", 16 | "name": "recipient", 17 | "type": "address" 18 | }, 19 | { 20 | "internalType": "uint256", 21 | "name": "sushiAmount", 22 | "type": "uint256" 23 | }, 24 | { 25 | "internalType": "uint256", 26 | "name": "newLpAmount", 27 | "type": "uint256" 28 | } 29 | ], 30 | "name": "onSushiReward", 31 | "outputs": [], 32 | "stateMutability": "nonpayable", 33 | "type": "function" 34 | }, 35 | { 36 | "inputs": [ 37 | { 38 | "internalType": "uint256", 39 | "name": "pid", 40 | "type": "uint256" 41 | }, 42 | { 43 | "internalType": "address", 44 | "name": "user", 45 | "type": "address" 46 | }, 47 | { 48 | "internalType": "uint256", 49 | "name": "sushiAmount", 50 | "type": "uint256" 51 | } 52 | ], 53 | "name": "pendingTokens", 54 | "outputs": [ 55 | { 56 | "internalType": "contract IERC20[]", 57 | "name": "", 58 | "type": "address[]" 59 | }, 60 | { 61 | "internalType": "uint256[]", 62 | "name": "", 63 | "type": "uint256[]" 64 | } 65 | ], 66 | "stateMutability": "view", 67 | "type": "function" 68 | } 69 | ] -------------------------------------------------------------------------------- /sushiswap-farms/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simplefi-sushiswap-farms", 3 | "license": "UNLICENSED", 4 | "scripts": { 5 | "codegen": "graph codegen", 6 | "build": "graph build", 7 | "deploy": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ simplefi-finance/sushiswap-farms", 8 | "create-local": "graph create --node http://localhost:8020/ simplefi-finance/sushiswap-farms", 9 | "remove-local": "graph remove --node http://localhost:8020/ simplefi-finance/sushiswap-farms", 10 | "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 simplefi-finance/sushiswap-farms" 11 | }, 12 | "dependencies": { 13 | "@graphprotocol/graph-cli": "0.20.0", 14 | "@graphprotocol/graph-ts": "0.20.0" 15 | } 16 | } -------------------------------------------------------------------------------- /sushiswap-farms/src/library/masterChefUtils.ts: -------------------------------------------------------------------------------- 1 | import { BigInt } from "@graphprotocol/graph-ts"; 2 | 3 | import { UserInfo } from "../../generated/schema"; 4 | 5 | /** 6 | * Create UserInfo entity which tracks how many LP tokens user provided and how many Sushi rewards he claimed 7 | * @param user 8 | * @param farmId 9 | * @returns 10 | */ 11 | export function getOrCreateUserInfo(user: string, farmId: string): UserInfo { 12 | let id = user + "-" + farmId; 13 | let userInfo = UserInfo.load(id) as UserInfo; 14 | 15 | if (userInfo == null) { 16 | userInfo = new UserInfo(id); 17 | userInfo.amount = BigInt.fromI32(0); 18 | userInfo.rewardDebt = BigInt.fromI32(0); 19 | userInfo.user = user; 20 | userInfo.farm = farmId; 21 | userInfo.save(); 22 | } 23 | 24 | return userInfo; 25 | } 26 | -------------------------------------------------------------------------------- /uniswap-v2/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | package-lock.json 107 | 108 | build/ 109 | generated/ 110 | 111 | subgraph.yaml -------------------------------------------------------------------------------- /uniswap-v2/README.md: -------------------------------------------------------------------------------- 1 | # Uniswap V2 Positions 2 | 3 | ## Usecase 4 | 5 | This subgraph is used track invstments of liquidity providers in Uniswap V2 pools. In this subgraph we track all the positions ever taken by an account. How this position changes over time. What are the returns on this position over time in ETH currency 6 | 7 | ## Mappings 8 | 9 | A position's lifecycle starts with `Mint` or `Transfer` event on a pool contrat with a new address as `to` argument. 10 | 11 | Once a new position has been added this position is updated on `Mint`, `Burn`, `Transfer` events based on amount argument of these events. 12 | 13 | If we find that `Burn` or `Transfer` has same amount as current saved `outputTokenBalance` then we close this position and once it is closed we create a new one on new `Mint` or `Transfer` event. 14 | 15 | In uniswap returns of an account's positions also change when other accounts do activity on the pool. Pool contract emits `Sync` event everything there is a change in reserves of assets in a pool. We can not have indexer update all positions on every `Sync` event therefore we store changes in pool variables on every `Sync` event. Our backend can then fetch list of all poolVariables between specific blockNumbers to calcualte changes in postions over time. 16 | 17 | **Note:** We are not handling `Swap` event. Every `swap` action emits `Sync` event before `Swap` event so changes in reserves on `swap` call has been taken care of by handling `Sync` event. 18 | 19 | Ordering of events in calls - 20 | 21 | * Mint call - 22 | * Transfer with from = zero, to = feeTo - changes total supply 23 | * Transfer with from = zero, to != feeTo - start MintTransaction - changes total supply 24 | * Sync - updates reserves 25 | * Mint with sender, amount0, amount1 transferred to pool - Complete MintTransaction 26 | 27 | * Burn call - 28 | * Transfer with from = any, to = pair - start BurnTransaction 29 | * Transfer with from = zero, to = feeTo - ignore 30 | * Transfer with from = pair, to = zero - changes total supply 31 | * Sync - updates reserves 32 | * Burn with sender, amount0, amount1, to - complete BurnTransaction 33 | 34 | * Transfer call- 35 | * Transfer with from = any, to = any - it effects two positions 36 | 37 | So when we receive a transfer event we check - 38 | * if it is from zero address then it starts MintTransaction 39 | * if it is to pair address then it starts BurnTransaction 40 | * otherwise it is a transfer between two external accounts 41 | 42 | and start a MintTransaction or BurnTransaction accordingly and then - 43 | * Mint event completes a MintTransaction 44 | * Burn event completes a BurnTransaction 45 | 46 | Because we can not rely on ordering of event triggers in graph node we need to implement reverse order of events as well in which - 47 | * Mint event starts a MintTransaction and then Transfer event completes it 48 | * Burn event starts a BurnTransaction and then Transfer event completes it -------------------------------------------------------------------------------- /uniswap-v2/config/apeswap-bsc.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "bsc", 3 | "factoryAddress": "0x0841BD0B734E4F5853f0dD8d7Ea041c241fb0Da6", 4 | "factoryStartBlock": 4855901, 5 | "factoryMappingPath": "apeswap.ts" 6 | } -------------------------------------------------------------------------------- /uniswap-v2/config/apeswap-polygon.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "matic", 3 | "factoryAddress": "0xCf083Be4164828f00cAE704EC15a36D711491284", 4 | "factoryStartBlock": 15298801, 5 | "factoryMappingPath": "apeswap.ts" 6 | } -------------------------------------------------------------------------------- /uniswap-v2/config/auroraswap-aurora.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "aurora", 3 | "factoryAddress": "0xC5E1DaeC2ad401eBEBdd3E32516d90Ab251A3aA3", 4 | "factoryStartBlock": 55447057, 5 | "factoryMappingPath": "auroraswap.ts" 6 | } -------------------------------------------------------------------------------- /uniswap-v2/config/biswap-bsc.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "bsc", 3 | "factoryAddress": "0x858E3312ed3A876947EA49d572A7C42DE08af7EE", 4 | "factoryStartBlock": 7664646, 5 | "factoryMappingPath": "biswap.ts" 6 | } -------------------------------------------------------------------------------- /uniswap-v2/config/cometh-polygon.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "matic", 3 | "factoryAddress": "0x800b052609c355cA8103E06F022aA30647eAd60a", 4 | "factoryStartBlock": 11633169, 5 | "factoryMappingPath": "cometh.ts" 6 | } -------------------------------------------------------------------------------- /uniswap-v2/config/pancakeswap-bsc.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "bsc", 3 | "factoryAddress": "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73", 4 | "factoryStartBlock": 6809737, 5 | "factoryMappingPath": "pancakeswap.ts" 6 | } 7 | -------------------------------------------------------------------------------- /uniswap-v2/config/pangolin-avalanche.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "avalanche", 3 | "factoryAddress": "0xefa94DE7a4656D787667C749f7E1223D71E9FD88", 4 | "factoryStartBlock": 56877, 5 | "factoryMappingPath": "pangolin.ts" 6 | } -------------------------------------------------------------------------------- /uniswap-v2/config/quickswap-polygon.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "matic", 3 | "factoryAddress": "0x5757371414417b8C6CAad45bAeF941aBc7d3Ab32", 4 | "factoryStartBlock": 4931780, 5 | "factoryMappingPath": "quickswap.ts" 6 | } 7 | -------------------------------------------------------------------------------- /uniswap-v2/config/sushiswap-arbitrum.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "arbitrum-one", 3 | "factoryAddress": "0xc35DADB65012eC5796536bD9864eD8773aBc74C4", 4 | "factoryStartBlock": 70, 5 | "factoryMappingPath": "sushiswap.ts" 6 | } -------------------------------------------------------------------------------- /uniswap-v2/config/sushiswap-avalanche.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "avalanche", 3 | "factoryAddress": "0xc35DADB65012eC5796536bD9864eD8773aBc74C4", 4 | "factoryStartBlock": 506190, 5 | "factoryMappingPath": "sushiswap.ts" 6 | } -------------------------------------------------------------------------------- /uniswap-v2/config/sushiswap-bsc.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "bsc", 3 | "factoryAddress": "0xc35DADB65012eC5796536bD9864eD8773aBc74C4", 4 | "factoryStartBlock": 5205068, 5 | "factoryMappingPath": "sushiswap.ts" 6 | } 7 | -------------------------------------------------------------------------------- /uniswap-v2/config/sushiswap-celo.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "celo", 3 | "factoryAddress": "0xc35DADB65012eC5796536bD9864eD8773aBc74C4", 4 | "factoryStartBlock": 7253488, 5 | "factoryMappingPath": "sushiswap.ts" 6 | } -------------------------------------------------------------------------------- /uniswap-v2/config/sushiswap-fantom.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "fantom", 3 | "factoryAddress": "0xc35DADB65012eC5796536bD9864eD8773aBc74C4", 4 | "factoryStartBlock": 2457879, 5 | "factoryMappingPath": "sushiswap.ts" 6 | } -------------------------------------------------------------------------------- /uniswap-v2/config/sushiswap-mainnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "mainnet", 3 | "factoryAddress": "0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac", 4 | "factoryStartBlock": 10794228, 5 | "factoryMappingPath": "sushiswap.ts" 6 | } -------------------------------------------------------------------------------- /uniswap-v2/config/sushiswap-polygon.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "matic", 3 | "factoryAddress": "0xc35DADB65012eC5796536bD9864eD8773aBc74C4", 4 | "factoryStartBlock": 11333217, 5 | "factoryMappingPath": "sushiswap.ts" 6 | } -------------------------------------------------------------------------------- /uniswap-v2/config/sushiswap-xdai.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "xdai", 3 | "factoryAddress": "0xc35DADB65012eC5796536bD9864eD8773aBc74C4", 4 | "factoryStartBlock": 14735904, 5 | "factoryMappingPath": "sushiswap.ts" 6 | } -------------------------------------------------------------------------------- /uniswap-v2/config/traderjoe-avalanche.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "avalanche", 3 | "factoryAddress": "0x9Ad6C38BE94206cA50bb0d90783181662f0Cfa10", 4 | "factoryStartBlock": 2486392, 5 | "factoryMappingPath": "traderjoe.ts" 6 | } -------------------------------------------------------------------------------- /uniswap-v2/config/trisolaris-aurora.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "aurora", 3 | "factoryAddress": "0xc66F594268041dB60507F00703b152492fb176E7", 4 | "factoryStartBlock": 49000000, 5 | "factoryMappingPath": "trisolaris.ts" 6 | } -------------------------------------------------------------------------------- /uniswap-v2/config/uniswap-v2-mainnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "mainnet", 3 | "factoryAddress": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f", 4 | "factoryStartBlock": 10000834, 5 | "factoryMappingPath": "uniswap.ts" 6 | } 7 | -------------------------------------------------------------------------------- /uniswap-v2/config/wannaswap-aurora.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": "aurora", 3 | "factoryAddress": "0x7928D4FeA7b2c90C732c10aFF59cf403f0C38246", 4 | "factoryStartBlock": 54112812, 5 | "factoryMappingPath": "wannaswap.ts" 6 | } -------------------------------------------------------------------------------- /uniswap-v2/src/constants.ts: -------------------------------------------------------------------------------- 1 | export namespace Blockchain { 2 | export const ETHEREUM = "ETHEREUM" 3 | export const BSC = "BSC" 4 | export const XDAI = "XDAI" 5 | export const POLYGON = "POLYGON" 6 | export const OPTIMISM = "OPTIMISM" 7 | export const AVALANCHE = "AVALANCE" 8 | export const NEAR = "NEAR" 9 | } 10 | 11 | export namespace TokenStandard { 12 | export const ERC20 = "ERC20" 13 | export const ERC721 = "ERC721" 14 | export const ERC1155 = "ERC1155" 15 | } 16 | 17 | export namespace ProtocolName { 18 | export const UNISWAP_V2 = "UNISWAP_V2" 19 | export const SUSHISWAP = "SUSHISWAP" 20 | export const QUICKSWAP = "QUICKSWAP" 21 | export const TRISOLARIS = "TRISOLARIS" 22 | export const PANCAKESWAP = "PANCAKESWAP" 23 | export const APESWAP = "APESWAP" 24 | export const BISWAP = "BISWAP" 25 | export const COMETH = "COMETH" 26 | export const PANGOLIN = "PANGOLIN" 27 | export const TRADER_JOE = "TRADER_JOE" 28 | export const WANNASWAP = "WANNASWAP" 29 | export const AURORASWAP = "AURORASWAP" 30 | } 31 | 32 | export namespace ProtocolType { 33 | export const STAKING = "STAKING" 34 | export const LENDING = "LENDING" 35 | export const EXCHANGE = "EXCHANGE" 36 | export const INSURANCE = "INSURANCE" 37 | export const STABLECOIN = "STABLECOIN" 38 | export const DERIVATIVE = "DERIVATIVE" 39 | export const SYNTHETIC_TOKEN = "SYNTHETIC_TOKEN" 40 | export const TOKEN_MANAGEMENT = "TOKEN_MANAGEMENT" 41 | export const PREDICTION_MARKET = "PREDICTION_MARKET" 42 | } 43 | 44 | export namespace PositionType { 45 | export const INVESTMENT = "INVESTMENT" 46 | export const DEBT = "DEBT" 47 | } 48 | 49 | export namespace TransactionType { 50 | export const INVEST = "INVEST" 51 | export const REDEEM = "REDEEM" 52 | export const BORROW = "BORROW" 53 | export const REPAY = "REPAY" 54 | export const TRANSFER_IN = "TRANSFER_IN" 55 | export const TRANSFER_OUT = "TRANSFER_OUT" 56 | } 57 | -------------------------------------------------------------------------------- /uniswap-v2/src/factories/apeswap.ts: -------------------------------------------------------------------------------- 1 | import { PairCreated } from "../../generated/UniswapV2Factory/UniswapV2Factory"; 2 | 3 | import { ProtocolName } from "../constants"; 4 | import { handlePairCreated as PairCreatedHandler } from "../uniswapV2Factory"; 5 | 6 | export function handlePairCreated(event: PairCreated): void { 7 | PairCreatedHandler(event, ProtocolName.APESWAP); 8 | } 9 | -------------------------------------------------------------------------------- /uniswap-v2/src/factories/auroraswap.ts: -------------------------------------------------------------------------------- 1 | import { PairCreated } from "../../generated/UniswapV2Factory/UniswapV2Factory"; 2 | 3 | import { ProtocolName } from "../constants"; 4 | import { handlePairCreated as PairCreatedHandler } from "../uniswapV2Factory"; 5 | 6 | export function handlePairCreated(event: PairCreated): void { 7 | PairCreatedHandler(event, ProtocolName.AURORASWAP); 8 | } 9 | -------------------------------------------------------------------------------- /uniswap-v2/src/factories/biswap.ts: -------------------------------------------------------------------------------- 1 | import { PairCreated } from "../../generated/UniswapV2Factory/UniswapV2Factory"; 2 | 3 | import { ProtocolName } from "../constants"; 4 | import { handlePairCreated as PairCreatedHandler } from "../uniswapV2Factory"; 5 | 6 | export function handlePairCreated(event: PairCreated): void { 7 | PairCreatedHandler(event, ProtocolName.BISWAP); 8 | } 9 | -------------------------------------------------------------------------------- /uniswap-v2/src/factories/cometh.ts: -------------------------------------------------------------------------------- 1 | import { PairCreated } from "../../generated/UniswapV2Factory/UniswapV2Factory"; 2 | 3 | import { ProtocolName } from "../constants"; 4 | import { handlePairCreated as PairCreatedHandler } from "../uniswapV2Factory"; 5 | 6 | export function handlePairCreated(event: PairCreated): void { 7 | PairCreatedHandler(event, ProtocolName.COMETH); 8 | } 9 | -------------------------------------------------------------------------------- /uniswap-v2/src/factories/pancakeswap.ts: -------------------------------------------------------------------------------- 1 | import { 2 | PairCreated 3 | } from "../../generated/UniswapV2Factory/UniswapV2Factory" 4 | 5 | import { ProtocolName } from "../constants" 6 | import { handlePairCreated as PairCreatedHandler } from "../uniswapV2Factory" 7 | 8 | export function handlePairCreated(event: PairCreated): void { 9 | PairCreatedHandler(event, ProtocolName.PANCAKESWAP) 10 | } 11 | -------------------------------------------------------------------------------- /uniswap-v2/src/factories/pangolin.ts: -------------------------------------------------------------------------------- 1 | import { PairCreated } from "../../generated/UniswapV2Factory/UniswapV2Factory"; 2 | 3 | import { ProtocolName } from "../constants"; 4 | import { handlePairCreated as PairCreatedHandler } from "../uniswapV2Factory"; 5 | 6 | export function handlePairCreated(event: PairCreated): void { 7 | PairCreatedHandler(event, ProtocolName.PANGOLIN); 8 | } 9 | -------------------------------------------------------------------------------- /uniswap-v2/src/factories/quickswap.ts: -------------------------------------------------------------------------------- 1 | import { 2 | PairCreated 3 | } from "../../generated/UniswapV2Factory/UniswapV2Factory" 4 | 5 | import { ProtocolName } from "../constants" 6 | import { handlePairCreated as PairCreatedHandler } from "../uniswapV2Factory" 7 | 8 | export function handlePairCreated(event: PairCreated): void { 9 | PairCreatedHandler(event, ProtocolName.QUICKSWAP) 10 | } 11 | -------------------------------------------------------------------------------- /uniswap-v2/src/factories/sushiswap.ts: -------------------------------------------------------------------------------- 1 | import { 2 | PairCreated 3 | } from "../../generated/UniswapV2Factory/UniswapV2Factory" 4 | 5 | import { ProtocolName } from "../constants" 6 | import { handlePairCreated as PairCreatedHandler } from "../uniswapV2Factory" 7 | 8 | export function handlePairCreated(event: PairCreated): void { 9 | PairCreatedHandler(event, ProtocolName.SUSHISWAP) 10 | } 11 | -------------------------------------------------------------------------------- /uniswap-v2/src/factories/traderjoe.ts: -------------------------------------------------------------------------------- 1 | import { PairCreated } from "../../generated/UniswapV2Factory/UniswapV2Factory"; 2 | 3 | import { ProtocolName } from "../constants"; 4 | import { handlePairCreated as PairCreatedHandler } from "../uniswapV2Factory"; 5 | 6 | export function handlePairCreated(event: PairCreated): void { 7 | PairCreatedHandler(event, ProtocolName.TRADER_JOE); 8 | } 9 | -------------------------------------------------------------------------------- /uniswap-v2/src/factories/trisolaris.ts: -------------------------------------------------------------------------------- 1 | import { 2 | PairCreated 3 | } from "../../generated/UniswapV2Factory/UniswapV2Factory" 4 | 5 | import { ProtocolName } from "../constants" 6 | import { handlePairCreated as PairCreatedHandler } from "../uniswapV2Factory" 7 | 8 | export function handlePairCreated(event: PairCreated): void { 9 | PairCreatedHandler(event, ProtocolName.TRISOLARIS) 10 | } 11 | -------------------------------------------------------------------------------- /uniswap-v2/src/factories/uniswap.ts: -------------------------------------------------------------------------------- 1 | import { 2 | PairCreated 3 | } from "../../generated/UniswapV2Factory/UniswapV2Factory" 4 | 5 | import { ProtocolName } from "../constants" 6 | import { handlePairCreated as PairCreatedHandler } from "../uniswapV2Factory" 7 | 8 | export function handlePairCreated(event: PairCreated): void { 9 | PairCreatedHandler(event, ProtocolName.UNISWAP_V2) 10 | } 11 | -------------------------------------------------------------------------------- /uniswap-v2/src/factories/wannaswap.ts: -------------------------------------------------------------------------------- 1 | import { PairCreated } from "../../generated/UniswapV2Factory/UniswapV2Factory"; 2 | 3 | import { ProtocolName } from "../constants"; 4 | import { handlePairCreated as PairCreatedHandler } from "../uniswapV2Factory"; 5 | 6 | export function handlePairCreated(event: PairCreated): void { 7 | PairCreatedHandler(event, ProtocolName.WANNASWAP); 8 | } 9 | -------------------------------------------------------------------------------- /uniswap-v2/src/uniswapV2Factory.ts: -------------------------------------------------------------------------------- 1 | import { BigInt } from "@graphprotocol/graph-ts" 2 | import { Pair as PairEntity } from "../generated/schema" 3 | import { UniswapV2Pair } from "../generated/templates" 4 | import { 5 | PairCreated 6 | } from "../generated/UniswapV2Factory/UniswapV2Factory" 7 | import { 8 | getOrCreateAccount, 9 | getOrCreateERC20Token, 10 | getOrCreateMarket 11 | } from "./common" 12 | import { ProtocolType } from "./constants" 13 | 14 | export function handlePairCreated(event: PairCreated, protocolName: string): void { 15 | // Create a tokens and market entity 16 | let token0 = getOrCreateERC20Token(event, event.params.token0) 17 | let token1 = getOrCreateERC20Token(event, event.params.token1) 18 | let lpToken = getOrCreateERC20Token(event, event.params.pair) 19 | 20 | let market = getOrCreateMarket( 21 | event, 22 | event.params.pair, 23 | protocolName, 24 | ProtocolType.EXCHANGE, 25 | [token0, token1], 26 | lpToken, 27 | [] 28 | ) 29 | 30 | lpToken.mintedByMarket = market.id 31 | lpToken.save() 32 | 33 | // Create pair 34 | let pair = new PairEntity(event.params.pair.toHexString()) 35 | pair.factory = getOrCreateAccount(event.address).id 36 | pair.token0 = token0.id 37 | pair.token1 = token1.id 38 | pair.totalSupply = BigInt.fromI32(0) 39 | pair.reserve0 = BigInt.fromI32(0) 40 | pair.reserve1 = BigInt.fromI32(0) 41 | pair.blockNumber = event.block.number 42 | pair.timestamp = event.block.timestamp 43 | pair.save() 44 | 45 | // Start listening for market events 46 | UniswapV2Pair.create(event.params.pair) 47 | } 48 | -------------------------------------------------------------------------------- /uniswap-v2/subgraph.template.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.2 2 | schema: 3 | file: ./schema.graphql 4 | dataSources: 5 | - kind: ethereum/contract 6 | name: UniswapV2Factory 7 | network: {{network}} 8 | source: 9 | address: "{{factoryAddress}}" 10 | abi: UniswapV2Factory 11 | startBlock: {{factoryStartBlock}} 12 | mapping: 13 | kind: ethereum/events 14 | apiVersion: 0.0.4 15 | language: wasm/assemblyscript 16 | entities: 17 | - Block 18 | - Account 19 | - Token 20 | - Market 21 | - Pair 22 | abis: 23 | - name: ERC20 24 | file: ./abis/IERC20.json 25 | - name: UniswapV2Factory 26 | file: ./abis/IUniswapV2Factory.json 27 | eventHandlers: 28 | - event: PairCreated(indexed address,indexed address,address,uint256) 29 | handler: handlePairCreated 30 | file: ./src/factories/{{factoryMappingPath}} 31 | templates: 32 | - kind: ethereum/contract 33 | name: UniswapV2Pair 34 | network: {{network}} 35 | source: 36 | abi: UniswapV2Pair 37 | mapping: 38 | kind: ethereum/events 39 | apiVersion: 0.0.4 40 | language: wasm/assemblyscript 41 | file: ./src/uniswapV2Pair.ts 42 | entities: 43 | - Block 44 | - Account 45 | - Token 46 | - Market 47 | - Transaction 48 | - Transfer 49 | - Position 50 | - PositionSnapshot 51 | - Pair 52 | - PairSnapshot 53 | abis: 54 | - name: ERC20 55 | file: ./abis/IERC20.json 56 | - name: UniswapV2Factory 57 | file: ./abis/IUniswapV2Factory.json 58 | - name: UniswapV2Pair 59 | file: ./abis/IUniswapV2Pair.json 60 | eventHandlers: 61 | - event: Transfer(indexed address,indexed address,uint256) 62 | handler: handleTransfer 63 | - event: Sync(uint112,uint112) 64 | handler: handleSync 65 | - event: Mint(indexed address,uint256,uint256) 66 | handler: handleMint 67 | - event: Burn(indexed address,uint256,uint256,indexed address) 68 | handler: handleBurn 69 | --------------------------------------------------------------------------------