diff --git a/subgraphs/user-position-v3/template/abis/ERC20.json b/subgraphs/user-position-v3/template/abis/ERC20.json new file mode 100644 index 00000000..405d6b36 --- /dev/null +++ b/subgraphs/user-position-v3/template/abis/ERC20.json @@ -0,0 +1,222 @@ +[ + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [ + { + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_spender", + "type": "address" + }, + { + "name": "_value", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_from", + "type": "address" + }, + { + "name": "_to", + "type": "address" + }, + { + "name": "_value", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [ + { + "name": "", + "type": "uint8" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "_owner", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "name": "balance", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [ + { + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_to", + "type": "address" + }, + { + "name": "_value", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "_owner", + "type": "address" + }, + { + "name": "_spender", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "payable": true, + "stateMutability": "payable", + "type": "fallback" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "from", + "type": "address" + }, + { + "indexed": true, + "name": "to", + "type": "address" + }, + { + "indexed": false, + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + } +] diff --git a/subgraphs/user-position-v3/template/abis/ERC20NameBytes.json b/subgraphs/user-position-v3/template/abis/ERC20NameBytes.json new file mode 100644 index 00000000..2d3c877a --- /dev/null +++ b/subgraphs/user-position-v3/template/abis/ERC20NameBytes.json @@ -0,0 +1,17 @@ +[ + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + } +] diff --git a/subgraphs/user-position-v3/template/abis/ERC20SymbolBytes.json b/subgraphs/user-position-v3/template/abis/ERC20SymbolBytes.json new file mode 100644 index 00000000..a76d6163 --- /dev/null +++ b/subgraphs/user-position-v3/template/abis/ERC20SymbolBytes.json @@ -0,0 +1,17 @@ +[ + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + } +] diff --git a/subgraphs/user-position-v3/template/abis/NonfungiblePositionManager.json b/subgraphs/user-position-v3/template/abis/NonfungiblePositionManager.json new file mode 100644 index 00000000..fd43c808 --- /dev/null +++ b/subgraphs/user-position-v3/template/abis/NonfungiblePositionManager.json @@ -0,0 +1,505 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "_deployer", "type": "address" }, + { "internalType": "address", "name": "_factory", "type": "address" }, + { "internalType": "address", "name": "_WETH9", "type": "address" }, + { "internalType": "address", "name": "_tokenDescriptor_", "type": "address" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "approved", "type": "address" }, + { "indexed": true, "internalType": "uint256", "name": "tokenId", "type": "uint256" } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "operator", "type": "address" }, + { "indexed": false, "internalType": "bool", "name": "approved", "type": "bool" } + ], + "name": "ApprovalForAll", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "uint256", "name": "tokenId", "type": "uint256" }, + { "indexed": false, "internalType": "address", "name": "recipient", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount0", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "amount1", "type": "uint256" } + ], + "name": "Collect", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "uint256", "name": "tokenId", "type": "uint256" }, + { "indexed": false, "internalType": "uint128", "name": "liquidity", "type": "uint128" }, + { "indexed": false, "internalType": "uint256", "name": "amount0", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "amount1", "type": "uint256" } + ], + "name": "DecreaseLiquidity", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "uint256", "name": "tokenId", "type": "uint256" }, + { "indexed": false, "internalType": "uint128", "name": "liquidity", "type": "uint128" }, + { "indexed": false, "internalType": "uint256", "name": "amount0", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "amount1", "type": "uint256" } + ], + "name": "IncreaseLiquidity", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "from", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, + { "indexed": true, "internalType": "uint256", "name": "tokenId", "type": "uint256" } + ], + "name": "Transfer", + "type": "event" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PERMIT_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "WETH9", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "tokenId", "type": "uint256" } + ], + "name": "approve", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "owner", "type": "address" }], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "baseURI", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }], + "name": "burn", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "uint256", "name": "tokenId", "type": "uint256" }, + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint128", "name": "amount0Max", "type": "uint128" }, + { "internalType": "uint128", "name": "amount1Max", "type": "uint128" } + ], + "internalType": "struct INonfungiblePositionManager.CollectParams", + "name": "params", + "type": "tuple" + } + ], + "name": "collect", + "outputs": [ + { "internalType": "uint256", "name": "amount0", "type": "uint256" }, + { "internalType": "uint256", "name": "amount1", "type": "uint256" } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "token0", "type": "address" }, + { "internalType": "address", "name": "token1", "type": "address" }, + { "internalType": "uint24", "name": "fee", "type": "uint24" }, + { "internalType": "uint160", "name": "sqrtPriceX96", "type": "uint160" } + ], + "name": "createAndInitializePoolIfNecessary", + "outputs": [{ "internalType": "address", "name": "pool", "type": "address" }], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "uint256", "name": "tokenId", "type": "uint256" }, + { "internalType": "uint128", "name": "liquidity", "type": "uint128" }, + { "internalType": "uint256", "name": "amount0Min", "type": "uint256" }, + { "internalType": "uint256", "name": "amount1Min", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" } + ], + "internalType": "struct INonfungiblePositionManager.DecreaseLiquidityParams", + "name": "params", + "type": "tuple" + } + ], + "name": "decreaseLiquidity", + "outputs": [ + { "internalType": "uint256", "name": "amount0", "type": "uint256" }, + { "internalType": "uint256", "name": "amount1", "type": "uint256" } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "deployer", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "factory", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }], + "name": "getApproved", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "uint256", "name": "tokenId", "type": "uint256" }, + { "internalType": "uint256", "name": "amount0Desired", "type": "uint256" }, + { "internalType": "uint256", "name": "amount1Desired", "type": "uint256" }, + { "internalType": "uint256", "name": "amount0Min", "type": "uint256" }, + { "internalType": "uint256", "name": "amount1Min", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" } + ], + "internalType": "struct INonfungiblePositionManager.IncreaseLiquidityParams", + "name": "params", + "type": "tuple" + } + ], + "name": "increaseLiquidity", + "outputs": [ + { "internalType": "uint128", "name": "liquidity", "type": "uint128" }, + { "internalType": "uint256", "name": "amount0", "type": "uint256" }, + { "internalType": "uint256", "name": "amount1", "type": "uint256" } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "operator", "type": "address" } + ], + "name": "isApprovedForAll", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "address", "name": "token0", "type": "address" }, + { "internalType": "address", "name": "token1", "type": "address" }, + { "internalType": "uint24", "name": "fee", "type": "uint24" }, + { "internalType": "int24", "name": "tickLower", "type": "int24" }, + { "internalType": "int24", "name": "tickUpper", "type": "int24" }, + { "internalType": "uint256", "name": "amount0Desired", "type": "uint256" }, + { "internalType": "uint256", "name": "amount1Desired", "type": "uint256" }, + { "internalType": "uint256", "name": "amount0Min", "type": "uint256" }, + { "internalType": "uint256", "name": "amount1Min", "type": "uint256" }, + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" } + ], + "internalType": "struct INonfungiblePositionManager.MintParams", + "name": "params", + "type": "tuple" + } + ], + "name": "mint", + "outputs": [ + { "internalType": "uint256", "name": "tokenId", "type": "uint256" }, + { "internalType": "uint128", "name": "liquidity", "type": "uint128" }, + { "internalType": "uint256", "name": "amount0", "type": "uint256" }, + { "internalType": "uint256", "name": "amount1", "type": "uint256" } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes[]", "name": "data", "type": "bytes[]" }], + "name": "multicall", + "outputs": [{ "internalType": "bytes[]", "name": "results", "type": "bytes[]" }], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }], + "name": "ownerOf", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "amount0Owed", "type": "uint256" }, + { "internalType": "uint256", "name": "amount1Owed", "type": "uint256" }, + { "internalType": "bytes", "name": "data", "type": "bytes" } + ], + "name": "pancakeV3MintCallback", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "tokenId", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "permit", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }], + "name": "positions", + "outputs": [ + { "internalType": "uint96", "name": "nonce", "type": "uint96" }, + { "internalType": "address", "name": "operator", "type": "address" }, + { "internalType": "address", "name": "token0", "type": "address" }, + { "internalType": "address", "name": "token1", "type": "address" }, + { "internalType": "uint24", "name": "fee", "type": "uint24" }, + { "internalType": "int24", "name": "tickLower", "type": "int24" }, + { "internalType": "int24", "name": "tickUpper", "type": "int24" }, + { "internalType": "uint128", "name": "liquidity", "type": "uint128" }, + { "internalType": "uint256", "name": "feeGrowthInside0LastX128", "type": "uint256" }, + { "internalType": "uint256", "name": "feeGrowthInside1LastX128", "type": "uint256" }, + { "internalType": "uint128", "name": "tokensOwed0", "type": "uint128" }, + { "internalType": "uint128", "name": "tokensOwed1", "type": "uint128" } + ], + "stateMutability": "view", + "type": "function" + }, + { "inputs": [], "name": "refundETH", "outputs": [], "stateMutability": "payable", "type": "function" }, + { + "inputs": [ + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "tokenId", "type": "uint256" } + ], + "name": "safeTransferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "tokenId", "type": "uint256" }, + { "internalType": "bytes", "name": "_data", "type": "bytes" } + ], + "name": "safeTransferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "token", "type": "address" }, + { "internalType": "uint256", "name": "value", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "selfPermit", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "token", "type": "address" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "selfPermitAllowed", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "token", "type": "address" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "selfPermitAllowedIfNecessary", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "token", "type": "address" }, + { "internalType": "uint256", "name": "value", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "selfPermitIfNecessary", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "operator", "type": "address" }, + { "internalType": "bool", "name": "approved", "type": "bool" } + ], + "name": "setApprovalForAll", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes4", "name": "interfaceId", "type": "bytes4" }], + "name": "supportsInterface", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "token", "type": "address" }, + { "internalType": "uint256", "name": "amountMinimum", "type": "uint256" }, + { "internalType": "address", "name": "recipient", "type": "address" } + ], + "name": "sweepToken", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "index", "type": "uint256" }], + "name": "tokenByIndex", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "uint256", "name": "index", "type": "uint256" } + ], + "name": "tokenOfOwnerByIndex", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }], + "name": "tokenURI", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "tokenId", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "amountMinimum", "type": "uint256" }, + { "internalType": "address", "name": "recipient", "type": "address" } + ], + "name": "unwrapWETH9", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { "stateMutability": "payable", "type": "receive" } +] diff --git a/subgraphs/user-position-v3/template/abis/factory.json b/subgraphs/user-position-v3/template/abis/factory.json new file mode 100644 index 00000000..6892ca46 --- /dev/null +++ b/subgraphs/user-position-v3/template/abis/factory.json @@ -0,0 +1,203 @@ +[ + { + "inputs": [{ "internalType": "address", "name": "_poolDeployer", "type": "address" }], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "uint24", "name": "fee", "type": "uint24" }, + { "indexed": true, "internalType": "int24", "name": "tickSpacing", "type": "int24" } + ], + "name": "FeeAmountEnabled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "uint24", "name": "fee", "type": "uint24" }, + { "indexed": false, "internalType": "bool", "name": "whitelistRequested", "type": "bool" }, + { "indexed": false, "internalType": "bool", "name": "enabled", "type": "bool" } + ], + "name": "FeeAmountExtraInfoUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "oldOwner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" } + ], + "name": "OwnerChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "token0", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "token1", "type": "address" }, + { "indexed": true, "internalType": "uint24", "name": "fee", "type": "uint24" }, + { "indexed": false, "internalType": "int24", "name": "tickSpacing", "type": "int24" }, + { "indexed": false, "internalType": "address", "name": "pool", "type": "address" } + ], + "name": "PoolCreated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "internalType": "address", "name": "lmPoolDeployer", "type": "address" }], + "name": "SetLmPoolDeployer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": false, "internalType": "bool", "name": "verified", "type": "bool" } + ], + "name": "WhiteListAdded", + "type": "event" + }, + { + "inputs": [ + { "internalType": "address", "name": "pool", "type": "address" }, + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint128", "name": "amount0Requested", "type": "uint128" }, + { "internalType": "uint128", "name": "amount1Requested", "type": "uint128" } + ], + "name": "collectProtocol", + "outputs": [ + { "internalType": "uint128", "name": "amount0", "type": "uint128" }, + { "internalType": "uint128", "name": "amount1", "type": "uint128" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "tokenA", "type": "address" }, + { "internalType": "address", "name": "tokenB", "type": "address" }, + { "internalType": "uint24", "name": "fee", "type": "uint24" } + ], + "name": "createPool", + "outputs": [{ "internalType": "address", "name": "pool", "type": "address" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint24", "name": "fee", "type": "uint24" }, + { "internalType": "int24", "name": "tickSpacing", "type": "int24" } + ], + "name": "enableFeeAmount", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint24", "name": "", "type": "uint24" }], + "name": "feeAmountTickSpacing", + "outputs": [{ "internalType": "int24", "name": "", "type": "int24" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint24", "name": "", "type": "uint24" }], + "name": "feeAmountTickSpacingExtraInfo", + "outputs": [ + { "internalType": "bool", "name": "whitelistRequested", "type": "bool" }, + { "internalType": "bool", "name": "enabled", "type": "bool" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "", "type": "address" }, + { "internalType": "address", "name": "", "type": "address" }, + { "internalType": "uint24", "name": "", "type": "uint24" } + ], + "name": "getPool", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "lmPoolDeployer", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "poolDeployer", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint24", "name": "fee", "type": "uint24" }, + { "internalType": "bool", "name": "whitelistRequested", "type": "bool" }, + { "internalType": "bool", "name": "enabled", "type": "bool" } + ], + "name": "setFeeAmountExtraInfo", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "pool", "type": "address" }, + { "internalType": "uint32", "name": "feeProtocol0", "type": "uint32" }, + { "internalType": "uint32", "name": "feeProtocol1", "type": "uint32" } + ], + "name": "setFeeProtocol", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "pool", "type": "address" }, + { "internalType": "address", "name": "lmPool", "type": "address" } + ], + "name": "setLmPool", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "_lmPoolDeployer", "type": "address" }], + "name": "setLmPoolDeployer", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "_owner", "type": "address" }], + "name": "setOwner", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "user", "type": "address" }, + { "internalType": "bool", "name": "verified", "type": "bool" } + ], + "name": "setWhiteListAddress", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/subgraphs/user-position-v3/template/abis/pool.json b/subgraphs/user-position-v3/template/abis/pool.json new file mode 100644 index 00000000..a64d710f --- /dev/null +++ b/subgraphs/user-position-v3/template/abis/pool.json @@ -0,0 +1,404 @@ +[ + { "inputs": [], "stateMutability": "nonpayable", "type": "constructor" }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, + { "indexed": true, "internalType": "int24", "name": "tickLower", "type": "int24" }, + { "indexed": true, "internalType": "int24", "name": "tickUpper", "type": "int24" }, + { "indexed": false, "internalType": "uint128", "name": "amount", "type": "uint128" }, + { "indexed": false, "internalType": "uint256", "name": "amount0", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "amount1", "type": "uint256" } + ], + "name": "Burn", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, + { "indexed": false, "internalType": "address", "name": "recipient", "type": "address" }, + { "indexed": true, "internalType": "int24", "name": "tickLower", "type": "int24" }, + { "indexed": true, "internalType": "int24", "name": "tickUpper", "type": "int24" }, + { "indexed": false, "internalType": "uint128", "name": "amount0", "type": "uint128" }, + { "indexed": false, "internalType": "uint128", "name": "amount1", "type": "uint128" } + ], + "name": "Collect", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "sender", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "recipient", "type": "address" }, + { "indexed": false, "internalType": "uint128", "name": "amount0", "type": "uint128" }, + { "indexed": false, "internalType": "uint128", "name": "amount1", "type": "uint128" } + ], + "name": "CollectProtocol", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "sender", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "recipient", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount0", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "amount1", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "paid0", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "paid1", "type": "uint256" } + ], + "name": "Flash", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "uint16", "name": "observationCardinalityNextOld", "type": "uint16" }, + { "indexed": false, "internalType": "uint16", "name": "observationCardinalityNextNew", "type": "uint16" } + ], + "name": "IncreaseObservationCardinalityNext", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "uint160", "name": "sqrtPriceX96", "type": "uint160" }, + { "indexed": false, "internalType": "int24", "name": "tick", "type": "int24" } + ], + "name": "Initialize", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "address", "name": "sender", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, + { "indexed": true, "internalType": "int24", "name": "tickLower", "type": "int24" }, + { "indexed": true, "internalType": "int24", "name": "tickUpper", "type": "int24" }, + { "indexed": false, "internalType": "uint128", "name": "amount", "type": "uint128" }, + { "indexed": false, "internalType": "uint256", "name": "amount0", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "amount1", "type": "uint256" } + ], + "name": "Mint", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "uint32", "name": "feeProtocol0Old", "type": "uint32" }, + { "indexed": false, "internalType": "uint32", "name": "feeProtocol1Old", "type": "uint32" }, + { "indexed": false, "internalType": "uint32", "name": "feeProtocol0New", "type": "uint32" }, + { "indexed": false, "internalType": "uint32", "name": "feeProtocol1New", "type": "uint32" } + ], + "name": "SetFeeProtocol", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "address", "name": "addr", "type": "address" }], + "name": "SetLmPoolEvent", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "sender", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "recipient", "type": "address" }, + { "indexed": false, "internalType": "int256", "name": "amount0", "type": "int256" }, + { "indexed": false, "internalType": "int256", "name": "amount1", "type": "int256" }, + { "indexed": false, "internalType": "uint160", "name": "sqrtPriceX96", "type": "uint160" }, + { "indexed": false, "internalType": "uint128", "name": "liquidity", "type": "uint128" }, + { "indexed": false, "internalType": "int24", "name": "tick", "type": "int24" }, + { "indexed": false, "internalType": "uint128", "name": "protocolFeesToken0", "type": "uint128" }, + { "indexed": false, "internalType": "uint128", "name": "protocolFeesToken1", "type": "uint128" } + ], + "name": "Swap", + "type": "event" + }, + { + "inputs": [ + { "internalType": "int24", "name": "tickLower", "type": "int24" }, + { "internalType": "int24", "name": "tickUpper", "type": "int24" }, + { "internalType": "uint128", "name": "amount", "type": "uint128" } + ], + "name": "burn", + "outputs": [ + { "internalType": "uint256", "name": "amount0", "type": "uint256" }, + { "internalType": "uint256", "name": "amount1", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "int24", "name": "tickLower", "type": "int24" }, + { "internalType": "int24", "name": "tickUpper", "type": "int24" }, + { "internalType": "uint128", "name": "amount0Requested", "type": "uint128" }, + { "internalType": "uint128", "name": "amount1Requested", "type": "uint128" } + ], + "name": "collect", + "outputs": [ + { "internalType": "uint128", "name": "amount0", "type": "uint128" }, + { "internalType": "uint128", "name": "amount1", "type": "uint128" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint128", "name": "amount0Requested", "type": "uint128" }, + { "internalType": "uint128", "name": "amount1Requested", "type": "uint128" } + ], + "name": "collectProtocol", + "outputs": [ + { "internalType": "uint128", "name": "amount0", "type": "uint128" }, + { "internalType": "uint128", "name": "amount1", "type": "uint128" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "factory", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "fee", + "outputs": [{ "internalType": "uint24", "name": "", "type": "uint24" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "feeGrowthGlobal0X128", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "feeGrowthGlobal1X128", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount0", "type": "uint256" }, + { "internalType": "uint256", "name": "amount1", "type": "uint256" }, + { "internalType": "bytes", "name": "data", "type": "bytes" } + ], + "name": "flash", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint16", "name": "observationCardinalityNext", "type": "uint16" }], + "name": "increaseObservationCardinalityNext", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint160", "name": "sqrtPriceX96", "type": "uint160" }], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "liquidity", + "outputs": [{ "internalType": "uint128", "name": "", "type": "uint128" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "lmPool", + "outputs": [{ "internalType": "contract IPancakeV3LmPool", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "maxLiquidityPerTick", + "outputs": [{ "internalType": "uint128", "name": "", "type": "uint128" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "int24", "name": "tickLower", "type": "int24" }, + { "internalType": "int24", "name": "tickUpper", "type": "int24" }, + { "internalType": "uint128", "name": "amount", "type": "uint128" }, + { "internalType": "bytes", "name": "data", "type": "bytes" } + ], + "name": "mint", + "outputs": [ + { "internalType": "uint256", "name": "amount0", "type": "uint256" }, + { "internalType": "uint256", "name": "amount1", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "name": "observations", + "outputs": [ + { "internalType": "uint32", "name": "blockTimestamp", "type": "uint32" }, + { "internalType": "int56", "name": "tickCumulative", "type": "int56" }, + { "internalType": "uint160", "name": "secondsPerLiquidityCumulativeX128", "type": "uint160" }, + { "internalType": "bool", "name": "initialized", "type": "bool" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint32[]", "name": "secondsAgos", "type": "uint32[]" }], + "name": "observe", + "outputs": [ + { "internalType": "int56[]", "name": "tickCumulatives", "type": "int56[]" }, + { "internalType": "uint160[]", "name": "secondsPerLiquidityCumulativeX128s", "type": "uint160[]" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "name": "positions", + "outputs": [ + { "internalType": "uint128", "name": "liquidity", "type": "uint128" }, + { "internalType": "uint256", "name": "feeGrowthInside0LastX128", "type": "uint256" }, + { "internalType": "uint256", "name": "feeGrowthInside1LastX128", "type": "uint256" }, + { "internalType": "uint128", "name": "tokensOwed0", "type": "uint128" }, + { "internalType": "uint128", "name": "tokensOwed1", "type": "uint128" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "protocolFees", + "outputs": [ + { "internalType": "uint128", "name": "token0", "type": "uint128" }, + { "internalType": "uint128", "name": "token1", "type": "uint128" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint32", "name": "feeProtocol0", "type": "uint32" }, + { "internalType": "uint32", "name": "feeProtocol1", "type": "uint32" } + ], + "name": "setFeeProtocol", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "_lmPool", "type": "address" }], + "name": "setLmPool", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "slot0", + "outputs": [ + { "internalType": "uint160", "name": "sqrtPriceX96", "type": "uint160" }, + { "internalType": "int24", "name": "tick", "type": "int24" }, + { "internalType": "uint16", "name": "observationIndex", "type": "uint16" }, + { "internalType": "uint16", "name": "observationCardinality", "type": "uint16" }, + { "internalType": "uint16", "name": "observationCardinalityNext", "type": "uint16" }, + { "internalType": "uint32", "name": "feeProtocol", "type": "uint32" }, + { "internalType": "bool", "name": "unlocked", "type": "bool" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "int24", "name": "tickLower", "type": "int24" }, + { "internalType": "int24", "name": "tickUpper", "type": "int24" } + ], + "name": "snapshotCumulativesInside", + "outputs": [ + { "internalType": "int56", "name": "tickCumulativeInside", "type": "int56" }, + { "internalType": "uint160", "name": "secondsPerLiquidityInsideX128", "type": "uint160" }, + { "internalType": "uint32", "name": "secondsInside", "type": "uint32" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "bool", "name": "zeroForOne", "type": "bool" }, + { "internalType": "int256", "name": "amountSpecified", "type": "int256" }, + { "internalType": "uint160", "name": "sqrtPriceLimitX96", "type": "uint160" }, + { "internalType": "bytes", "name": "data", "type": "bytes" } + ], + "name": "swap", + "outputs": [ + { "internalType": "int256", "name": "amount0", "type": "int256" }, + { "internalType": "int256", "name": "amount1", "type": "int256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "int16", "name": "", "type": "int16" }], + "name": "tickBitmap", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "tickSpacing", + "outputs": [{ "internalType": "int24", "name": "", "type": "int24" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "int24", "name": "", "type": "int24" }], + "name": "ticks", + "outputs": [ + { "internalType": "uint128", "name": "liquidityGross", "type": "uint128" }, + { "internalType": "int128", "name": "liquidityNet", "type": "int128" }, + { "internalType": "uint256", "name": "feeGrowthOutside0X128", "type": "uint256" }, + { "internalType": "uint256", "name": "feeGrowthOutside1X128", "type": "uint256" }, + { "internalType": "int56", "name": "tickCumulativeOutside", "type": "int56" }, + { "internalType": "uint160", "name": "secondsPerLiquidityOutsideX128", "type": "uint160" }, + { "internalType": "uint32", "name": "secondsOutside", "type": "uint32" }, + { "internalType": "bool", "name": "initialized", "type": "bool" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "token0", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "token1", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + } +] diff --git a/subgraphs/user-position-v3/template/mappings/factory.ts b/subgraphs/user-position-v3/template/mappings/factory.ts new file mode 100644 index 00000000..7554f1d4 --- /dev/null +++ b/subgraphs/user-position-v3/template/mappings/factory.ts @@ -0,0 +1,54 @@ +/* eslint-disable prefer-const */ +import { log } from "@graphprotocol/graph-ts"; +import { PoolCreated } from "../generated/Factory/Factory"; +import { Pool, Token } from "../generated/schema"; +import { Pool as PoolTemplate } from "../generated/templates"; +import { fetchTokenSymbol, fetchTokenName, fetchTokenDecimals } from "../utils/token"; +import { ZERO_BI } from "../utils/constants"; + +export function handlePoolCreated(event: PoolCreated): void { + let pool = new Pool(event.params.pool.toHexString()) as Pool; + let token0 = Token.load(event.params.token0.toHexString()); + let token1 = Token.load(event.params.token1.toHexString()); + + // fetch info if null + if (token0 === null) { + token0 = new Token(event.params.token0.toHexString()); + token0.symbol = fetchTokenSymbol(event.params.token0); + token0.name = fetchTokenName(event.params.token0); + let decimals = fetchTokenDecimals(event.params.token0); + + // bail if we couldn't figure out the decimals + if (decimals === null) { + log.debug("mybug the decimal on token 0 was null", []); + return; + } + + token0.decimals = decimals; + } + + if (token1 === null) { + token1 = new Token(event.params.token1.toHexString()); + token1.symbol = fetchTokenSymbol(event.params.token1); + token1.name = fetchTokenName(event.params.token1); + let decimals = fetchTokenDecimals(event.params.token1); + // bail if we couldn't figure out the decimals + if (decimals === null) { + log.debug("mybug the decimal on token 0 was null", []); + return; + } + token1.decimals = decimals; + } + + pool.token0 = token0.id; + pool.token1 = token1.id; + pool.txCount = ZERO_BI; + pool.createdAtTimestamp = event.block.timestamp; + pool.createdAtBlockNumber = event.block.number; + + pool.save(); + // create the tracked contract based on the template + PoolTemplate.create(event.params.pool); + token0.save(); + token1.save(); +} diff --git a/subgraphs/user-position-v3/template/mappings/pool.ts b/subgraphs/user-position-v3/template/mappings/pool.ts new file mode 100644 index 00000000..3bded71e --- /dev/null +++ b/subgraphs/user-position-v3/template/mappings/pool.ts @@ -0,0 +1,86 @@ +/* eslint-disable prefer-const */ +import { BigInt } from "@graphprotocol/graph-ts"; +import { Burn as BurnEvent, Mint as MintEvent } from "../generated/templates/Pool/Pool"; +import { Burn, Mint, Pool, Token } from "../generated/schema"; +import { convertTokenToDecimal } from "../utils"; +import { loadTransaction, updateUserPosition } from "../utils/schema"; +import { ONE_BI } from "../utils/constants"; + +export function handleMint(event: MintEvent): void { + let transaction = loadTransaction(event); + let poolAddress = event.address.toHexString(); + let pool = Pool.load(poolAddress); + let token0 = Token.load(pool.token0); + let token1 = Token.load(pool.token1); + + let amount0 = convertTokenToDecimal(event.params.amount0, token0.decimals); + let amount1 = convertTokenToDecimal(event.params.amount1, token1.decimals); + + let mint = new Mint(transaction.id.toString() + "#" + pool.txCount.toString()); + mint.transaction = transaction.id; + mint.timestamp = transaction.timestamp; + mint.pool = pool.id; + mint.token0 = pool.token0; + mint.token1 = pool.token1; + mint.owner = event.params.owner; + mint.sender = event.params.sender; + mint.origin = event.transaction.from; + mint.amount = event.params.amount; + mint.amount0 = amount0; + mint.amount1 = amount1; + mint.tickLower = BigInt.fromI32(event.params.tickLower); + mint.tickUpper = BigInt.fromI32(event.params.tickUpper); + mint.logIndex = event.logIndex; + mint.save(); + + pool.txCount = pool.txCount.plus(ONE_BI); + pool.save(); + + transaction.tickLower = BigInt.fromI32(event.params.tickLower); + transaction.tickUpper = BigInt.fromI32(event.params.tickUpper); + transaction.increaseLiquidityAmount = event.params.amount; + transaction.pool = pool.id; + + transaction.save(); + + updateUserPosition(event, transaction); +} + +export function handleBurn(event: BurnEvent): void { + let transaction = loadTransaction(event); + let poolAddress = event.address.toHexString(); + let pool = Pool.load(poolAddress); + let token0 = Token.load(pool.token0); + let token1 = Token.load(pool.token1); + + let amount0 = convertTokenToDecimal(event.params.amount0, token0.decimals); + let amount1 = convertTokenToDecimal(event.params.amount1, token1.decimals); + + let burn = new Burn(transaction.id + "#" + pool.txCount.toString()); + burn.transaction = transaction.id; + burn.timestamp = transaction.timestamp; + burn.pool = pool.id; + burn.token0 = pool.token0; + burn.token1 = pool.token1; + burn.owner = event.params.owner; + burn.origin = event.transaction.from; + burn.amount = event.params.amount; + burn.amount0 = amount0; + burn.amount1 = amount1; + burn.tickLower = BigInt.fromI32(event.params.tickLower); + burn.tickUpper = BigInt.fromI32(event.params.tickUpper); + burn.logIndex = event.logIndex; + burn.save(); + + pool.txCount = pool.txCount.plus(ONE_BI); + pool.save(); + + transaction.tickLower = BigInt.fromI32(event.params.tickLower); + transaction.tickUpper = BigInt.fromI32(event.params.tickUpper); + transaction.decreaseLiquidityAmount = event.params.amount; + transaction.pool = pool.id; + + transaction.save(); + + updateUserPosition(event, transaction); +} diff --git a/subgraphs/user-position-v3/template/mappings/position-manager.ts b/subgraphs/user-position-v3/template/mappings/position-manager.ts new file mode 100644 index 00000000..ceaccf02 --- /dev/null +++ b/subgraphs/user-position-v3/template/mappings/position-manager.ts @@ -0,0 +1,36 @@ +/* eslint-disable prefer-const */ +import { Address } from "@graphprotocol/graph-ts"; +import { + DecreaseLiquidity, + IncreaseLiquidity, + Transfer, +} from "../generated/NonfungiblePositionManager/NonfungiblePositionManager"; +import { loadTransaction, updateUserPosition } from "../utils/schema"; +import { ADDRESS_ZERO } from "../utils/constants"; +import { UserPosition } from "../generated/schema"; + +export function handleIncreaseLiquidity(event: IncreaseLiquidity): void { + let transaction = loadTransaction(event); + transaction.tokenId = event.params.tokenId; + transaction.save(); + updateUserPosition(event, transaction); +} + +export function handleDecreaseLiquidity(event: DecreaseLiquidity): void { + let transaction = loadTransaction(event); + transaction.tokenId = event.params.tokenId; + transaction.save(); + updateUserPosition(event, transaction); +} + +export function handleTransfer(event: Transfer): void { + let transaction = loadTransaction(event); + if (event.params.from.equals(Address.fromString(ADDRESS_ZERO))) { + transaction.positionOwner = event.params.to; + } else { + let userPosition = UserPosition.load(event.params.tokenId.toString()); + userPosition.owner = event.params.to; + userPosition.save(); + } + transaction.save(); +} diff --git a/subgraphs/user-position-v3/template/package.json b/subgraphs/user-position-v3/template/package.json new file mode 100644 index 00000000..dd98a6e8 --- /dev/null +++ b/subgraphs/user-position-v3/template/package.json @@ -0,0 +1,18 @@ +{ + "name": "user-position-v3", + "description": "PancakeSwap Subgraph for User positions V3", + "version": "1.0.0", + "repository": "git@github.com:pancakeswap/pancake-subgraph.git", + "author": "PancakeSwap", + "license": "GPL-3.0-or-later", + "scripts": { + "template": "mustache ../../../config/bsc.js subgraph.template.yaml > subgraph.yaml", + "auth": "graph auth --product hosted-service f4b727b41dd3465f461ee000115b1102", + "codegen": "graph codegen subgraph.yaml", + "build": "graph build subgraph.yaml", + "deploy:goerli": "graph deploy --product hosted-service --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ pancakeswap/user-position-v3-goerli subgraph.yaml", + "deploy:chapel": "graph deploy --product hosted-service --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ pancakeswap/user-position-v3-chapel subgraph.yaml", + "deploy:eth": "graph deploy --product hosted-service --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ pancakeswap/user-position-v3-eth subgraph.yaml", + "deploy:bsc": "graph deploy --product hosted-service --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ pancakeswap/user-position-v3-bsc subgraph.yaml" + } +} diff --git a/subgraphs/user-position-v3/template/schema.graphql b/subgraphs/user-position-v3/template/schema.graphql new file mode 100644 index 00000000..ab2d3cfe --- /dev/null +++ b/subgraphs/user-position-v3/template/schema.graphql @@ -0,0 +1,135 @@ +type Token @entity { + # token address + id: ID! + # token symbol + symbol: String! + # token name + name: String! + # token decimals + decimals: BigInt! +} + +type Pool @entity { + # pool address + id: ID! + # creation + createdAtTimestamp: BigInt! + # block pool was created at + createdAtBlockNumber: BigInt! + txCount: BigInt! + # token0 + token0: Token! + # token1 + token1: Token! + + # derived fields + mints: [Mint!]! @derivedFrom(field: "pool") + burns: [Burn!]! @derivedFrom(field: "pool") +} + +type Transaction @entity { + # txn hash + id: ID! + pool: Pool + # block txn was included in + blockNumber: BigInt! + # timestamp txn was confirmed + timestamp: BigInt! + # gas used during txn execution + gasUsed: BigInt! + gasPrice: BigInt! + + # position data from Pool and NonfungiblePositionManager SC + positionOwner: Bytes + tokenId: BigInt + increaseLiquidityAmount: BigInt + decreaseLiquidityAmount: BigInt + tickLower: BigInt + tickUpper: BigInt + + isPositionUpdated: Boolean! + + # derived values + mints: [Mint]! @derivedFrom(field: "transaction") + burns: [Burn]! @derivedFrom(field: "transaction") +} + +type Mint @entity { + # transaction hash + "#" + index in mints Transaction array + id: ID! + # which txn the mint was included in + transaction: Transaction! + # time of txn + timestamp: BigInt! + # pool position is within + pool: Pool! + # allow indexing by tokens + token0: Token! + # allow indexing by tokens + token1: Token! + # owner of position where liquidity minted to + owner: Bytes! + # the address that minted the liquidity + sender: Bytes + # txn origin + origin: Bytes! # the EOA that initiated the txn + # amount of liquidity minted + amount: BigInt! + # amount of token 0 minted + amount0: BigDecimal! + # amount of token 1 minted + amount1: BigDecimal! + # lower tick of the position + tickLower: BigInt! + # upper tick of the position + tickUpper: BigInt! + # order within the txn + logIndex: BigInt +} + +type Burn @entity { + # transaction hash + "#" + index in mints Transaction array + id: ID! + # txn burn was included in + transaction: Transaction! + # pool position is within + pool: Pool! + # allow indexing by tokens + token0: Token! + # allow indexing by tokens + token1: Token! + # need this to pull recent txns for specific token or pool + timestamp: BigInt! + # owner of position where liquidity was burned + owner: Bytes + # txn origin + origin: Bytes! # the EOA that initiated the txn + # amouny of liquidity burned + amount: BigInt! + # amount of token 0 burned + amount0: BigDecimal! + # amount of token 1 burned + amount1: BigDecimal! + # lower tick of position + tickLower: BigInt! + # upper tick of position + tickUpper: BigInt! + # position within the transactions + logIndex: BigInt +} + +type UserPosition @entity { + # tokenId + id: ID! + owner: Bytes! + # pool position is within + pool: Pool + + liquidity: BigInt! + tickLower: BigInt! + tickUpper: BigInt! + # creation + createdAtTimestamp: BigInt! + # block pool was created at + createdAtBlockNumber: BigInt! +} diff --git a/subgraphs/user-position-v3/template/subgraph.template.yaml b/subgraphs/user-position-v3/template/subgraph.template.yaml new file mode 100644 index 00000000..925bc75c --- /dev/null +++ b/subgraphs/user-position-v3/template/subgraph.template.yaml @@ -0,0 +1,94 @@ +specVersion: 0.0.2 +description: PancakeSwap is a multi-chain decentralized exchange and automated market maker protocol. +repository: https://github.com/pancakeswap/pancake-subgraph +schema: + file: ./schema.graphql +features: + - nonFatalErrors +dataSources: + - kind: ethereum/contract + name: Factory + network: {{ network }} + source: + address: "{{v3.factoryAddress}}" + abi: Factory + startBlock: {{ v3.startBlock }} + mapping: + kind: ethereum/events + apiVersion: 0.0.4 + language: wasm/assemblyscript + file: ./mappings/factory.ts + entities: + - Pool + - Token + abis: + - name: Factory + file: ./abis/factory.json + - name: ERC20 + file: ./abis/ERC20.json + - name: ERC20SymbolBytes + file: ./abis/ERC20SymbolBytes.json + - name: ERC20NameBytes + file: ./abis/ERC20NameBytes.json + - name: Pool + file: ./abis/pool.json + eventHandlers: + - event: PoolCreated(indexed address,indexed address,indexed uint24,int24,address) + handler: handlePoolCreated + - kind: ethereum/contract + name: NonfungiblePositionManager + network: {{network}} + source: + address: "{{v3.nonfungiblePositionManagerAddress}}" + abi: NonfungiblePositionManager + startBlock: {{ v3.nonfungiblePositionManagerStartBlock }} + mapping: + kind: ethereum/events + apiVersion: 0.0.4 + language: wasm/assemblyscript + file: ./mappings/position-manager.ts + entities: + - Pool + - Token + abis: + - name: NonfungiblePositionManager + file: ./abis/NonfungiblePositionManager.json + - name: Pool + file: ./abis/pool.json + - name: Factory + file: ./abis/factory.json + - name: ERC20 + file: ./abis/ERC20.json + eventHandlers: + - event: IncreaseLiquidity(indexed uint256,uint128,uint256,uint256) + handler: handleIncreaseLiquidity + - event: DecreaseLiquidity(indexed uint256,uint128,uint256,uint256) + handler: handleDecreaseLiquidity + - event: Transfer(indexed address,indexed address,indexed uint256) + handler: handleTransfer +templates: + - kind: ethereum/contract + name: Pool + network: {{ network }} + source: + abi: Pool + mapping: + kind: ethereum/events + apiVersion: 0.0.4 + language: wasm/assemblyscript + file: ./mappings/pool.ts + entities: + - Pool + - Token + abis: + - name: Pool + file: ./abis/pool.json + - name: Factory + file: ./abis/factory.json + - name: ERC20 + file: ./abis/ERC20.json + eventHandlers: + - event: Mint(address,indexed address,indexed int24,indexed int24,uint128,uint256,uint256) + handler: handleMint + - event: Burn(indexed address,indexed int24,indexed int24,uint128,uint256,uint256) + handler: handleBurn diff --git a/subgraphs/user-position-v3/template/subgraph.yaml b/subgraphs/user-position-v3/template/subgraph.yaml new file mode 100644 index 00000000..3c24e33d --- /dev/null +++ b/subgraphs/user-position-v3/template/subgraph.yaml @@ -0,0 +1,94 @@ +specVersion: 0.0.2 +description: PancakeSwap is a multi-chain decentralized exchange and automated market maker protocol. +repository: https://github.com/pancakeswap/pancake-subgraph +schema: + file: ./schema.graphql +features: + - nonFatalErrors +dataSources: + - kind: ethereum/contract + name: Factory + network: bsc + source: + address: "0x0bfbcf9fa4f9c56b0f40a671ad40e0805a091865" + abi: Factory + startBlock: 26956207 + mapping: + kind: ethereum/events + apiVersion: 0.0.4 + language: wasm/assemblyscript + file: ./mappings/factory.ts + entities: + - Pool + - Token + abis: + - name: Factory + file: ./abis/factory.json + - name: ERC20 + file: ./abis/ERC20.json + - name: ERC20SymbolBytes + file: ./abis/ERC20SymbolBytes.json + - name: ERC20NameBytes + file: ./abis/ERC20NameBytes.json + - name: Pool + file: ./abis/pool.json + eventHandlers: + - event: PoolCreated(indexed address,indexed address,indexed uint24,int24,address) + handler: handlePoolCreated + - kind: ethereum/contract + name: NonfungiblePositionManager + network: bsc + source: + address: "0x46a15b0b27311cedf172ab29e4f4766fbe7f4364" + abi: NonfungiblePositionManager + startBlock: 26931961 + mapping: + kind: ethereum/events + apiVersion: 0.0.4 + language: wasm/assemblyscript + file: ./mappings/position-manager.ts + entities: + - Pool + - Token + abis: + - name: NonfungiblePositionManager + file: ./abis/NonfungiblePositionManager.json + - name: Pool + file: ./abis/pool.json + - name: Factory + file: ./abis/factory.json + - name: ERC20 + file: ./abis/ERC20.json + eventHandlers: + - event: IncreaseLiquidity(indexed uint256,uint128,uint256,uint256) + handler: handleIncreaseLiquidity + - event: DecreaseLiquidity(indexed uint256,uint128,uint256,uint256) + handler: handleDecreaseLiquidity + - event: Transfer(indexed address,indexed address,indexed uint256) + handler: handleTransfer +templates: + - kind: ethereum/contract + name: Pool + network: bsc + source: + abi: Pool + mapping: + kind: ethereum/events + apiVersion: 0.0.4 + language: wasm/assemblyscript + file: ./mappings/pool.ts + entities: + - Pool + - Token + abis: + - name: Pool + file: ./abis/pool.json + - name: Factory + file: ./abis/factory.json + - name: ERC20 + file: ./abis/ERC20.json + eventHandlers: + - event: Mint(address,indexed address,indexed int24,indexed int24,uint128,uint256,uint256) + handler: handleMint + - event: Burn(indexed address,indexed int24,indexed int24,uint128,uint256,uint256) + handler: handleBurn diff --git a/subgraphs/user-position-v3/template/tsconfig.json b/subgraphs/user-position-v3/template/tsconfig.json new file mode 100644 index 00000000..3df75a02 --- /dev/null +++ b/subgraphs/user-position-v3/template/tsconfig.json @@ -0,0 +1,8 @@ +{ + // "extends": "../../../tsconfig.json", + "compilerOptions": { + "types": ["@graphprotocol/graph-ts"], + "strict": false, + "strictNullChecks": false + } +} diff --git a/subgraphs/user-position-v3/template/utils/constants.ts b/subgraphs/user-position-v3/template/utils/constants.ts new file mode 100644 index 00000000..9bd14bc8 --- /dev/null +++ b/subgraphs/user-position-v3/template/utils/constants.ts @@ -0,0 +1,9 @@ +/* eslint-disable prefer-const */ +import { BigInt, BigDecimal } from "@graphprotocol/graph-ts"; + +export const ADDRESS_ZERO = "0x0000000000000000000000000000000000000000"; + +export let ZERO_BI = BigInt.fromI32(0); +export let ONE_BI = BigInt.fromI32(1); +export let ZERO_BD = BigDecimal.fromString("0"); +export let ONE_BD = BigDecimal.fromString("1"); diff --git a/subgraphs/user-position-v3/template/utils/index.ts b/subgraphs/user-position-v3/template/utils/index.ts new file mode 100644 index 00000000..dacb7c7a --- /dev/null +++ b/subgraphs/user-position-v3/template/utils/index.ts @@ -0,0 +1,22 @@ +/* eslint-disable prefer-const */ +import { BigInt, BigDecimal } from "@graphprotocol/graph-ts"; +import { ONE_BI, ZERO_BI } from "./constants"; + +export function exponentToBigDecimal(decimals: BigInt): BigDecimal { + let bd = BigDecimal.fromString("1"); + for (let i = ZERO_BI; i.lt(decimals as BigInt); i = i.plus(ONE_BI)) { + bd = bd.times(BigDecimal.fromString("10")); + } + return bd; +} + +export function isNullEthValue(value: string): boolean { + return value == "0x0000000000000000000000000000000000000000000000000000000000000001"; +} + +export function convertTokenToDecimal(tokenAmount: BigInt, exchangeDecimals: BigInt): BigDecimal { + if (exchangeDecimals == ZERO_BI) { + return tokenAmount.toBigDecimal(); + } + return tokenAmount.toBigDecimal().div(exponentToBigDecimal(exchangeDecimals)); +} diff --git a/subgraphs/user-position-v3/template/utils/schema.ts b/subgraphs/user-position-v3/template/utils/schema.ts new file mode 100644 index 00000000..a974264a --- /dev/null +++ b/subgraphs/user-position-v3/template/utils/schema.ts @@ -0,0 +1,50 @@ +import { BigInt, Bytes, ethereum } from "@graphprotocol/graph-ts"; +import { Transaction, UserPosition } from "../generated/schema"; +import { ZERO_BI } from "./constants"; + +export function loadTransaction(event: ethereum.Event): Transaction { + let transaction = Transaction.load(event.transaction.hash.toHexString()); + if (transaction === null) { + transaction = new Transaction(event.transaction.hash.toHexString()); + } + transaction.blockNumber = event.block.number; + transaction.timestamp = event.block.timestamp; + transaction.gasUsed = event.transaction.gasUsed; + transaction.gasPrice = event.transaction.gasPrice; + transaction.isPositionUpdated = false; + transaction.save(); + return transaction as Transaction; +} + +export function updateUserPosition(event: ethereum.Event, tx: Transaction): void { + if ( + tx.isPositionUpdated === false && + tx.tickLower !== null && + tx.tickUpper !== null && + tx.tokenId !== null && + tx.positionOwner !== null && + (tx.increaseLiquidityAmount !== null || tx.decreaseLiquidityAmount !== null) + ) { + let userPosition = UserPosition.load(tx.tokenId.toString()); + if (userPosition === null) { + userPosition = new UserPosition(tx.tokenId.toString()); + userPosition.liquidity = ZERO_BI; + userPosition.pool = tx.pool; + userPosition.createdAtBlockNumber = event.block.number; + userPosition.createdAtTimestamp = event.block.timestamp; + } + userPosition.tickLower = tx.tickLower as BigInt; + userPosition.tickUpper = tx.tickUpper as BigInt; + userPosition.owner = tx.positionOwner as Bytes; + if (tx.increaseLiquidityAmount !== null) { + userPosition.liquidity = userPosition.liquidity.plus(tx.increaseLiquidityAmount as BigInt); + } + if (tx.decreaseLiquidityAmount !== null) { + userPosition.liquidity = userPosition.liquidity.minus(tx.decreaseLiquidityAmount as BigInt); + } + + tx.isPositionUpdated = true; + tx.save(); + userPosition.save(); + } +} diff --git a/subgraphs/user-position-v3/template/utils/token.ts b/subgraphs/user-position-v3/template/utils/token.ts new file mode 100644 index 00000000..cd22f559 --- /dev/null +++ b/subgraphs/user-position-v3/template/utils/token.ts @@ -0,0 +1,62 @@ +/* eslint-disable prefer-const */ +import { BigInt, Address } from "@graphprotocol/graph-ts"; +import { ERC20 } from "../generated/Factory/ERC20"; +import { ERC20SymbolBytes } from "../generated/Factory/ERC20SymbolBytes"; +import { ERC20NameBytes } from "../generated/Factory/ERC20NameBytes"; +import { isNullEthValue } from "."; + +export function fetchTokenSymbol(tokenAddress: Address): string { + let contract = ERC20.bind(tokenAddress); + let contractSymbolBytes = ERC20SymbolBytes.bind(tokenAddress); + + // try types string and bytes32 for symbol + let symbolValue = "unknown"; + let symbolResult = contract.try_symbol(); + if (symbolResult.reverted) { + let symbolResultBytes = contractSymbolBytes.try_symbol(); + if (!symbolResultBytes.reverted) { + // for broken pairs that have no symbol function exposed + if (!isNullEthValue(symbolResultBytes.value.toHexString())) { + symbolValue = symbolResultBytes.value.toString(); + } + } + } else { + symbolValue = symbolResult.value; + } + + return symbolValue; +} + +export function fetchTokenName(tokenAddress: Address): string { + let contract = ERC20.bind(tokenAddress); + let contractNameBytes = ERC20NameBytes.bind(tokenAddress); + + // try types string and bytes32 for name + let nameValue = "unknown"; + let nameResult = contract.try_name(); + if (nameResult.reverted) { + let nameResultBytes = contractNameBytes.try_name(); + if (!nameResultBytes.reverted) { + // for broken exchanges that have no name function exposed + if (!isNullEthValue(nameResultBytes.value.toHexString())) { + nameValue = nameResultBytes.value.toString(); + } + } + } else { + nameValue = nameResult.value; + } + + return nameValue; +} + +export function fetchTokenDecimals(tokenAddress: Address): BigInt { + let contract = ERC20.bind(tokenAddress); + // try types uint8 for decimals + let decimalValue = null; + let decimalResult = contract.try_decimals(); + if (!decimalResult.reverted) { + decimalValue = decimalResult.value; + } + + return BigInt.fromI32(decimalValue as i32); +}