From 0d16f1ed106ef8324c06e697fa0a40310da5176d Mon Sep 17 00:00:00 2001 From: michelet Date: Sat, 15 Jan 2022 19:09:10 -0300 Subject: [PATCH 01/24] Refactoring to new structure. WIP. --- src/Mai/abis/CamToken.json | 305 ++++++++++++++++++++++++++++++++++++ src/Mai/abis/Farm.json | 0 src/Mai/abis/Token.json | 119 ++++++++++++++ src/Mai/config/polygon.json | 192 +++++++++++++++++++++++ src/Mai/schema.graphql | 0 5 files changed, 616 insertions(+) create mode 100644 src/Mai/abis/CamToken.json create mode 100644 src/Mai/abis/Farm.json create mode 100644 src/Mai/abis/Token.json create mode 100644 src/Mai/config/polygon.json create mode 100644 src/Mai/schema.graphql diff --git a/src/Mai/abis/CamToken.json b/src/Mai/abis/CamToken.json new file mode 100644 index 0000000..dd33233 --- /dev/null +++ b/src/Mai/abis/CamToken.json @@ -0,0 +1,305 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "amToken", "type": "address" }, + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "string", "name": "name", "type": "string" }, + { "internalType": "string", "name": "symbol", "type": "string" }, + { "internalType": "uint8", "name": "decimals", "type": "uint8" } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "spender", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "from", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "Transfer", + "type": "event" + }, + { + "constant": true, + "inputs": [], + "name": "AaveContract", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "LENDING_POOL", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "Token", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" } + ], + "name": "allowance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "approve", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "internalType": "address", "name": "account", "type": "address" }], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "claimAaveRewards", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "subtractedValue", "type": "uint256" } + ], + "name": "decreaseAllowance", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "depositFeeBP", + "outputs": [{ "internalType": "uint16", "name": "", "type": "uint16" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "uint256", "name": "_amount", "type": "uint256" }], + "name": "enter", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "harvestMaticIntoToken", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "addedValue", "type": "uint256" } + ], + "name": "increaseAllowance", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "uint256", "name": "_share", "type": "uint256" }], + "name": "leave", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "operator", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transfer", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "sender", "type": "address" }, + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "treasury", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "uni", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "uint16", "name": "_depositFee", "type": "uint16" }], + "name": "updateDepositFee", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "address", "name": "_operator", "type": "address" }], + "name": "updateOperator", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "address", "name": "_treasury", "type": "address" }], + "name": "updateTreasury", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "address", "name": "_router", "type": "address" }], + "name": "updateUniV2Router", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "usdc", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "wMatic", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + } +] diff --git a/src/Mai/abis/Farm.json b/src/Mai/abis/Farm.json new file mode 100644 index 0000000..e69de29 diff --git a/src/Mai/abis/Token.json b/src/Mai/abis/Token.json new file mode 100644 index 0000000..6b6018b --- /dev/null +++ b/src/Mai/abis/Token.json @@ -0,0 +1,119 @@ +[ + { "inputs": [], "stateMutability": "nonpayable", "type": "constructor" }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "spender", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "from", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "Transfer", + "type": "event" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" } + ], + "name": "allowance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "approve", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "account", "type": "address" }], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "subtractedValue", "type": "uint256" } + ], + "name": "decreaseAllowance", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "addedValue", "type": "uint256" } + ], + "name": "increaseAllowance", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "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": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transfer", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "sender", "type": "address" }, + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/src/Mai/config/polygon.json b/src/Mai/config/polygon.json new file mode 100644 index 0000000..1a5cb2d --- /dev/null +++ b/src/Mai/config/polygon.json @@ -0,0 +1,192 @@ +{ + "blockchain": "ethereum", + "network": "matic", + "adapters": [ + { + "adapter": "Mai", + "contracts": [ + { + "contract": "QiStableCoin", + "abis": ["QiStableCoin", "Farm", "eQi", "Token"], + "entities": ["MaiTokenData", "MaiPoolData"], + "events": [ + { + "event-name": "CreateVault", + "event-params": "(uint256,address)" + }, + { + "event-name": "DestroyVault", + "event-params": "(uint256)" + }, + { + "event-name": "TransferVault", + "event-params": "(uint256,address,address)" + }, + { + "event-name": "DepositCollateral", + "event-params": "(uint256,uint256)" + }, + { + "event-name": "WithdrawCollateral", + "event-params": "(uint256,uint256)" + }, + { + "event-name": "BorrowToken", + "event-params": "(uint256,uint256)" + }, + { + "event-name": "PayBackToken", + "event-params": "(uint256,uint256,uint256)" + }, + { + "event-name": "BuyRiskyVault", + "event-params": "(uint256,address,address,uint256)" + } + ], + "instances": [ + { + "address": "0xa3Fa99A148fA48D14Ed51d610c367C61876997F1", + "startBlock": "13976458", + "symbol": "miMATIC" + }, + { + "address": "0x3fd939B017b31eaADF9ae50C7fF7Fa5c0661d47C", + "startBlock": "17116398", + "symbol": "WETH-mai-vault" + }, + { + "address": "0x61167073E31b1DAd85a3E531211c7B8F1E5cAE72", + "startBlock": "17202893", + "symbol": "LINK-mai-vault" + }, + { + "address": "0x87ee36f780ae843A78D5735867bc1c13792b7b11", + "startBlock": "17202864", + "symbol": "AAVE-mai-vault" + }, + { + "address": "0x98B5F32dd9670191568b661a3e847Ed764943875", + "startBlock": "17329441", + "symbol": "CRV-mai-vault" + }, + { + "address": "0x701A1824e5574B0b6b1c8dA808B184a7AB7A2867", + "startBlock": "19667216", + "symbol": "BAL-mai-vault" + }, + { + "address": "0x649Aa6E6b6194250C077DF4fB37c23EE6c098513", + "startBlock": "19667294", + "symbol": "dQuick-mai-vault" + }, + { + "address": "0x37131aEDd3da288467B6EBe9A77C523A700E6Ca1", + "startBlock": "18135222", + "symbol": "WBTC-mai-vault" + }, + { + "address": "0xF086dEdf6a89e7B16145b03a6CB0C0a9979F1433", + "startBlock": "19722911", + "symbol": "GHST-mai-vault" + }, + { + "address": "0x88d84a85A87ED12B8f098e8953B322fF789fCD1a", + "startBlock": "16898638", + "symbol": "camWMATIC-mai-vault" + }, + { + "address": "0x11A33631a5B5349AF3F165d2B7901A4d67e561ad", + "startBlock": "17124772", + "symbol": "camWETH-mai-vault" + }, + { + "address": "0x578375c3af7d61586c2C3A7BA87d2eEd640EFA40", + "startBlock": "17203020", + "symbol": "camAAVE-mai-vault" + }, + { + "address": "0x7dda5e1a389e0c1892caf55940f5fce6588a9ae0", + "startBlock": "18135281", + "symbol": "camWBTC-mai-vault" + }, + { + "address": "0xD2FE44055b5C874feE029119f70336447c8e8827", + "startBlock": "20285158", + "symbol": "camDAI-mai-vault" + } + ] + }, + { + "contract": "CamToken", + "abis": ["CamToken"], + "entities": ["MaiCamTokenData"], + "events": [ + { + "event-name": "Transfer", + "event-params": "(indexed address,indexed address,uint256)" + } + ], + "instances": [ + { + "address": "0x22965e296d9a0Cd0E917d6D70EF2573009F8a1bB", + "startBlock": "15723190", + "symbol": "camUSDC" + }, + { + "address": "0xE6C23289Ba5A9F0Ef31b8EB36241D5c800889b7b", + "startBlock": "15723203", + "symbol": "camDAI" + }, + { + "address": "0x0470CD31C8FcC42671465880BA81D631F0B76C1D", + "startBlock": "15723236", + "symbol": "camWETH" + }, + { + "address": "0xB3911259f435b28EC072E4Ff6fF5A2C604fea0Fb", + "startBlock": "16062135", + "symbol": "camUSDT" + }, + { + "address": "0x7068Ea5255cb05931EFa8026Bd04b18F3DeB8b0B", + "startBlock": "15683191", + "symbol": "camWMATIC" + }, + { + "address": "0xeA4040B21cb68afb94889cB60834b13427CFc4EB", + "startBlock": "17151560", + "symbol": "camAAVE" + }, + { + "address": "0xBa6273A78a23169e01317bd0f6338547F869E8Df", + "startBlock": "17151483", + "symbol": "camWBTC" + } + ] + }, + { + "contract": "Farm", + "abis": ["QiStableCoin", "Farm", "eQi", "Token"], + "entities": ["MaiTokenData", "MaiPoolData"], + "events": [ + { + "event-name": "Withdraw", + "event-params": "(indexed address,indexed uint256,uint256)" + }, + { + "event-name": "Deposit", + "event-params": "(indexed address,indexed uint256,uint256)" + }, + { + "event-name": "EmergencyWithdraw", + "event-params": "(indexed address,indexed uint256,uint256)" + } + ], + "instances": [ + { "address": "0x574Fe4E8120C4Da1741b5Fd45584de7A5b521F0F", "startBlock": "14126699", "symbol": "" } + ] + } + ] + } + ] +} diff --git a/src/Mai/schema.graphql b/src/Mai/schema.graphql new file mode 100644 index 0000000..e69de29 From 0197b07b117da97e12a951bf98cb682463b2733d Mon Sep 17 00:00:00 2001 From: michelet Date: Sat, 15 Jan 2022 19:19:09 -0300 Subject: [PATCH 02/24] WIP --- src/Mai/config/polygon.json | 240 +++++++++--------------------------- src/utils/constants.ts | 1 + 2 files changed, 62 insertions(+), 179 deletions(-) diff --git a/src/Mai/config/polygon.json b/src/Mai/config/polygon.json index 1a5cb2d..17a50ce 100644 --- a/src/Mai/config/polygon.json +++ b/src/Mai/config/polygon.json @@ -1,192 +1,74 @@ { - "blockchain": "ethereum", "network": "matic", - "adapters": [ + "adapter": "Mai", + "contracts": [ { - "adapter": "Mai", - "contracts": [ + "contract": "CamToken", + "abis": ["CamToken"], + "entities": ["MaiCamTokenData"], + "events": [ { - "contract": "QiStableCoin", - "abis": ["QiStableCoin", "Farm", "eQi", "Token"], - "entities": ["MaiTokenData", "MaiPoolData"], - "events": [ - { - "event-name": "CreateVault", - "event-params": "(uint256,address)" - }, - { - "event-name": "DestroyVault", - "event-params": "(uint256)" - }, - { - "event-name": "TransferVault", - "event-params": "(uint256,address,address)" - }, - { - "event-name": "DepositCollateral", - "event-params": "(uint256,uint256)" - }, - { - "event-name": "WithdrawCollateral", - "event-params": "(uint256,uint256)" - }, - { - "event-name": "BorrowToken", - "event-params": "(uint256,uint256)" - }, - { - "event-name": "PayBackToken", - "event-params": "(uint256,uint256,uint256)" - }, - { - "event-name": "BuyRiskyVault", - "event-params": "(uint256,address,address,uint256)" - } - ], - "instances": [ - { - "address": "0xa3Fa99A148fA48D14Ed51d610c367C61876997F1", - "startBlock": "13976458", - "symbol": "miMATIC" - }, - { - "address": "0x3fd939B017b31eaADF9ae50C7fF7Fa5c0661d47C", - "startBlock": "17116398", - "symbol": "WETH-mai-vault" - }, - { - "address": "0x61167073E31b1DAd85a3E531211c7B8F1E5cAE72", - "startBlock": "17202893", - "symbol": "LINK-mai-vault" - }, - { - "address": "0x87ee36f780ae843A78D5735867bc1c13792b7b11", - "startBlock": "17202864", - "symbol": "AAVE-mai-vault" - }, - { - "address": "0x98B5F32dd9670191568b661a3e847Ed764943875", - "startBlock": "17329441", - "symbol": "CRV-mai-vault" - }, - { - "address": "0x701A1824e5574B0b6b1c8dA808B184a7AB7A2867", - "startBlock": "19667216", - "symbol": "BAL-mai-vault" - }, - { - "address": "0x649Aa6E6b6194250C077DF4fB37c23EE6c098513", - "startBlock": "19667294", - "symbol": "dQuick-mai-vault" - }, - { - "address": "0x37131aEDd3da288467B6EBe9A77C523A700E6Ca1", - "startBlock": "18135222", - "symbol": "WBTC-mai-vault" - }, - { - "address": "0xF086dEdf6a89e7B16145b03a6CB0C0a9979F1433", - "startBlock": "19722911", - "symbol": "GHST-mai-vault" - }, - { - "address": "0x88d84a85A87ED12B8f098e8953B322fF789fCD1a", - "startBlock": "16898638", - "symbol": "camWMATIC-mai-vault" - }, - { - "address": "0x11A33631a5B5349AF3F165d2B7901A4d67e561ad", - "startBlock": "17124772", - "symbol": "camWETH-mai-vault" - }, - { - "address": "0x578375c3af7d61586c2C3A7BA87d2eEd640EFA40", - "startBlock": "17203020", - "symbol": "camAAVE-mai-vault" - }, - { - "address": "0x7dda5e1a389e0c1892caf55940f5fce6588a9ae0", - "startBlock": "18135281", - "symbol": "camWBTC-mai-vault" - }, - { - "address": "0xD2FE44055b5C874feE029119f70336447c8e8827", - "startBlock": "20285158", - "symbol": "camDAI-mai-vault" - } - ] + "event-name": "Transfer", + "event-params": "(indexed address,indexed address,uint256)" + } + ], + "instances": [ + { + "address": "0x22965e296d9a0Cd0E917d6D70EF2573009F8a1bB", + "startBlock": "15723190", + "symbol": "camUSDC" }, { - "contract": "CamToken", - "abis": ["CamToken"], - "entities": ["MaiCamTokenData"], - "events": [ - { - "event-name": "Transfer", - "event-params": "(indexed address,indexed address,uint256)" - } - ], - "instances": [ - { - "address": "0x22965e296d9a0Cd0E917d6D70EF2573009F8a1bB", - "startBlock": "15723190", - "symbol": "camUSDC" - }, - { - "address": "0xE6C23289Ba5A9F0Ef31b8EB36241D5c800889b7b", - "startBlock": "15723203", - "symbol": "camDAI" - }, - { - "address": "0x0470CD31C8FcC42671465880BA81D631F0B76C1D", - "startBlock": "15723236", - "symbol": "camWETH" - }, - { - "address": "0xB3911259f435b28EC072E4Ff6fF5A2C604fea0Fb", - "startBlock": "16062135", - "symbol": "camUSDT" - }, - { - "address": "0x7068Ea5255cb05931EFa8026Bd04b18F3DeB8b0B", - "startBlock": "15683191", - "symbol": "camWMATIC" - }, - { - "address": "0xeA4040B21cb68afb94889cB60834b13427CFc4EB", - "startBlock": "17151560", - "symbol": "camAAVE" - }, - { - "address": "0xBa6273A78a23169e01317bd0f6338547F869E8Df", - "startBlock": "17151483", - "symbol": "camWBTC" - } - ] + "address": "0xE6C23289Ba5A9F0Ef31b8EB36241D5c800889b7b", + "startBlock": "15723203", + "symbol": "camDAI" }, { - "contract": "Farm", - "abis": ["QiStableCoin", "Farm", "eQi", "Token"], - "entities": ["MaiTokenData", "MaiPoolData"], - "events": [ - { - "event-name": "Withdraw", - "event-params": "(indexed address,indexed uint256,uint256)" - }, - { - "event-name": "Deposit", - "event-params": "(indexed address,indexed uint256,uint256)" - }, - { - "event-name": "EmergencyWithdraw", - "event-params": "(indexed address,indexed uint256,uint256)" - } - ], - "instances": [ - { "address": "0x574Fe4E8120C4Da1741b5Fd45584de7A5b521F0F", "startBlock": "14126699", "symbol": "" } - ] + "address": "0x0470CD31C8FcC42671465880BA81D631F0B76C1D", + "startBlock": "15723236", + "symbol": "camWETH" + }, + { + "address": "0xB3911259f435b28EC072E4Ff6fF5A2C604fea0Fb", + "startBlock": "16062135", + "symbol": "camUSDT" + }, + { + "address": "0x7068Ea5255cb05931EFa8026Bd04b18F3DeB8b0B", + "startBlock": "15683191", + "symbol": "camWMATIC" + }, + { + "address": "0xeA4040B21cb68afb94889cB60834b13427CFc4EB", + "startBlock": "17151560", + "symbol": "camAAVE" + }, + { + "address": "0xBa6273A78a23169e01317bd0f6338547F869E8Df", + "startBlock": "17151483", + "symbol": "camWBTC" } ] + }, + { + "contract": "Farm", + "abis": ["Farm", "CamToken"], + "entities": ["MaiCamTokenData", "MaiPoolData"], + "events": [ + { + "event-name": "Withdraw", + "event-params": "(indexed address,indexed uint256,uint256)" + }, + { + "event-name": "Deposit", + "event-params": "(indexed address,indexed uint256,uint256)" + }, + { + "event-name": "EmergencyWithdraw", + "event-params": "(indexed address,indexed uint256,uint256)" + } + ], + "instances": [{ "address": "0x574Fe4E8120C4Da1741b5Fd45584de7A5b521F0F", "startBlock": "14126699", "symbol": "" }] } ] } diff --git a/src/utils/constants.ts b/src/utils/constants.ts index d5d23d4..f6398cf 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -38,3 +38,4 @@ export let LidoNodeOperatorsRegistryAddress: Address = toAddress("0x55032650b14d export let LidoTreasuryAddress: Address = toAddress("0x4333218072D5d7008546737786663c38B4D561A4"); export let SushiMiniChefAddress = toAddress("0x0769fd68dFb93167989C6f7254cd0D766Fb2841F"); +export let MaiFinanceFarmAddress = toAddress("0x574Fe4E8120C4Da1741b5Fd45584de7A5b521F0F"); From 3b4d2b08d58ffb8738be03b7234a7c066aced0ab Mon Sep 17 00:00:00 2001 From: michelet Date: Sat, 15 Jan 2022 19:37:20 -0300 Subject: [PATCH 03/24] wip --- schema.graphql | 12 ------------ src/Mai/mappings/CamToken.ts | 0 src/Mai/mappings/handlers.ts | 1 + src/QuickSwap/mappings/Farm.ts | 0 4 files changed, 1 insertion(+), 12 deletions(-) delete mode 100644 schema.graphql create mode 100644 src/Mai/mappings/CamToken.ts create mode 100644 src/Mai/mappings/handlers.ts create mode 100644 src/QuickSwap/mappings/Farm.ts diff --git a/schema.graphql b/schema.graphql deleted file mode 100644 index cbd427b..0000000 --- a/schema.graphql +++ /dev/null @@ -1,12 +0,0 @@ -# ---------------------------------------- -# QuickSwap -# ---------------------------------------- -type QuickSwapPoolData @entity { - id: ID! - blockNumber: BigInt! - blockTimestamp: BigInt! - stakingToken: Bytes - rewardsToken: Bytes - rewardRate: BigDecimal - totalSupply: BigInt -} diff --git a/src/Mai/mappings/CamToken.ts b/src/Mai/mappings/CamToken.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/Mai/mappings/handlers.ts b/src/Mai/mappings/handlers.ts new file mode 100644 index 0000000..d215a03 --- /dev/null +++ b/src/Mai/mappings/handlers.ts @@ -0,0 +1 @@ +import { Address, BigInt, Bytes, log } from "@graphprotocol/graph-ts"; diff --git a/src/QuickSwap/mappings/Farm.ts b/src/QuickSwap/mappings/Farm.ts new file mode 100644 index 0000000..e69de29 From 028891244c205f255e0bfd1ce52df5a138e98572 Mon Sep 17 00:00:00 2001 From: michelet Date: Sat, 15 Jan 2022 19:40:35 -0300 Subject: [PATCH 04/24] wip farm --- src/Mai/mappings/Farm.ts | 0 src/Mai/schema.graphql | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/Mai/mappings/Farm.ts diff --git a/src/Mai/mappings/Farm.ts b/src/Mai/mappings/Farm.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/Mai/schema.graphql b/src/Mai/schema.graphql index e69de29..9355ae2 100644 --- a/src/Mai/schema.graphql +++ b/src/Mai/schema.graphql @@ -0,0 +1,21 @@ +# ---------------------------------------- +# Mai Finance +# ---------------------------------------- +type MaiCamTokenData @entity { + id: ID! + blockNumber: BigInt! + blockTimestamp: BigInt! +} +type MaiPoolData @entity { + id: ID! + blockNumber: BigInt + blockTimestamp: BigInt + vault: Bytes + deposited: BigInt + borrowed: BigInt + closingFees: BigInt + symbol: String + txHash: String + tokenPrice: BigInt + ethPrice: BigInt +} From a4eae1547a21b0f9f6e132f738bb5892091b75b4 Mon Sep 17 00:00:00 2001 From: michelet Date: Sat, 15 Jan 2022 19:41:31 -0300 Subject: [PATCH 05/24] wip --- src/Mai/abis/Farm.json | 247 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 247 insertions(+) diff --git a/src/Mai/abis/Farm.json b/src/Mai/abis/Farm.json index e69de29..3f51ca3 100644 --- a/src/Mai/abis/Farm.json +++ b/src/Mai/abis/Farm.json @@ -0,0 +1,247 @@ +[ + { + "inputs": [ + { "internalType": "contract IERC20", "name": "_erc20", "type": "address" }, + { "internalType": "uint256", "name": "_rewardPerBlock", "type": "uint256" }, + { "internalType": "uint256", "name": "_startBlock", "type": "uint256" }, + { "internalType": "address", "name": "_feeAddress", "type": "address" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": true, "internalType": "uint256", "name": "pid", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "Deposit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": true, "internalType": "uint256", "name": "pid", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "EmergencyWithdraw", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": true, "internalType": "uint256", "name": "pid", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "Withdraw", + "type": "event" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "_allocPoint", "type": "uint256" }, + { "internalType": "contract IERC20", "name": "_lpToken", "type": "address" }, + { "internalType": "bool", "name": "_withUpdate", "type": "bool" }, + { "internalType": "uint16", "name": "_depositFeeBP", "type": "uint16" } + ], + "name": "add", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "_pid", "type": "uint256" }, + { "internalType": "uint256", "name": "_amount", "type": "uint256" } + ], + "name": "deposit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "_pid", "type": "uint256" }, + { "internalType": "address", "name": "_user", "type": "address" } + ], + "name": "deposited", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "_pid", "type": "uint256" }], + "name": "emergencyWithdraw", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "endBlock", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "erc20", + "outputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "feeAddress", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "_amount", "type": "uint256" }], + "name": "fund", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { "inputs": [], "name": "massUpdatePools", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "owner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "paidOut", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "_pid", "type": "uint256" }, + { "internalType": "address", "name": "_user", "type": "address" } + ], + "name": "pending", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "name": "poolInfo", + "outputs": [ + { "internalType": "contract IERC20", "name": "lpToken", "type": "address" }, + { "internalType": "uint256", "name": "allocPoint", "type": "uint256" }, + { "internalType": "uint256", "name": "lastRewardBlock", "type": "uint256" }, + { "internalType": "uint256", "name": "accERC20PerShare", "type": "uint256" }, + { "internalType": "uint16", "name": "depositFeeBP", "type": "uint16" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "poolLength", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { "inputs": [], "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "rewardPerBlock", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "_pid", "type": "uint256" }, + { "internalType": "uint256", "name": "_allocPoint", "type": "uint256" }, + { "internalType": "bool", "name": "_withUpdate", "type": "bool" } + ], + "name": "set", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "_feeAddress", "type": "address" }], + "name": "setFeeAddress", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "startBlock", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalAllocPoint", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalPending", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "_pid", "type": "uint256" }], + "name": "updatePool", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "", "type": "uint256" }, + { "internalType": "address", "name": "", "type": "address" } + ], + "name": "userInfo", + "outputs": [ + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "uint256", "name": "rewardDebt", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "_pid", "type": "uint256" }, + { "internalType": "uint256", "name": "_amount", "type": "uint256" } + ], + "name": "withdraw", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] From f54c385e5181de48fc93e87df4ebb5ce0eea08a2 Mon Sep 17 00:00:00 2001 From: michelet Date: Sat, 15 Jan 2022 20:14:08 -0300 Subject: [PATCH 06/24] Updating the config, removing file --- src/Mai/mappings/CamToken.ts | 12 ++++++++++++ src/Mai/mappings/handlers.ts | 15 +++++++++++++++ src/Mai/schema.graphql | 3 +++ src/QuickSwap/mappings/Farm.ts | 0 4 files changed, 30 insertions(+) delete mode 100644 src/QuickSwap/mappings/Farm.ts diff --git a/src/Mai/mappings/CamToken.ts b/src/Mai/mappings/CamToken.ts index e69de29..7c4982e 100644 --- a/src/Mai/mappings/CamToken.ts +++ b/src/Mai/mappings/CamToken.ts @@ -0,0 +1,12 @@ +import { Transfer as TransferEvent } from "../../../generated/MaiCamTokencamWMATIC/MaiCamToken"; +import { ZERO_ADDRESS } from "../../utils/constants"; +import { handleCamToken } from "./handlers"; +export function handleTransfer(event: TransferEvent): void { + let from = event.params.from; + let to = event.params.to; + let value = event.params.value; + if (from == ZERO_ADDRESS) { + } else if (to == ZERO_ADDRESS) { + } + handleCamToken(event.transaction.hash, event.block.number, event.block.timestamp, event.address); +} diff --git a/src/Mai/mappings/handlers.ts b/src/Mai/mappings/handlers.ts index d215a03..2667e6a 100644 --- a/src/Mai/mappings/handlers.ts +++ b/src/Mai/mappings/handlers.ts @@ -1 +1,16 @@ import { Address, BigInt, Bytes, log } from "@graphprotocol/graph-ts"; +import { MaiCamTokenData } from "../../../generated/schema"; +import { MaiCamToken } from "../../../generated/MaiCamTokencamWMATIC/MaiCamToken"; +import { MaiFinanceFarmAddress, ZERO_BD, ZERO_BI } from "../../utils/constants"; +export function handleCamToken(txnHash: Bytes, blockNumber: BigInt, timestamp: BigInt, camTokenAddress: Address) { + let entity = MaiCamTokenData.load(txnHash.toHex()); + if (!entity) entity = new MaiCamTokenData(txnHash.toHex()); + let camContract = MaiCamToken.bind(camTokenAddress); + entity.blockNumber = blockNumber; + entity.blockTimestamp = timestamp; + let totalSupplyResult = camContract.try_totalSupply(); + if (totalSupplyResult.reverted) { + log.warning("totalSupply() reverted", []); + } else { + } +} diff --git a/src/Mai/schema.graphql b/src/Mai/schema.graphql index 9355ae2..a0f94e0 100644 --- a/src/Mai/schema.graphql +++ b/src/Mai/schema.graphql @@ -5,6 +5,9 @@ type MaiCamTokenData @entity { id: ID! blockNumber: BigInt! blockTimestamp: BigInt! + vault: Bytes + totalSupply: BigInt + rewardRate: BigDecimal } type MaiPoolData @entity { id: ID! diff --git a/src/QuickSwap/mappings/Farm.ts b/src/QuickSwap/mappings/Farm.ts deleted file mode 100644 index e69de29..0000000 From c44fd6c4cfafacfb6dc3114b0c50a2429b2126e0 Mon Sep 17 00:00:00 2001 From: michelet Date: Sat, 15 Jan 2022 20:35:07 -0300 Subject: [PATCH 07/24] working with the supply --- src/Mai/config/polygon.json | 20 -------------------- src/Mai/mappings/Farm.ts | 0 src/Mai/mappings/handlers.ts | 14 +++++++++++++- src/Mai/schema.graphql | 1 + 4 files changed, 14 insertions(+), 21 deletions(-) delete mode 100644 src/Mai/mappings/Farm.ts diff --git a/src/Mai/config/polygon.json b/src/Mai/config/polygon.json index 17a50ce..23a78a1 100644 --- a/src/Mai/config/polygon.json +++ b/src/Mai/config/polygon.json @@ -49,26 +49,6 @@ "symbol": "camWBTC" } ] - }, - { - "contract": "Farm", - "abis": ["Farm", "CamToken"], - "entities": ["MaiCamTokenData", "MaiPoolData"], - "events": [ - { - "event-name": "Withdraw", - "event-params": "(indexed address,indexed uint256,uint256)" - }, - { - "event-name": "Deposit", - "event-params": "(indexed address,indexed uint256,uint256)" - }, - { - "event-name": "EmergencyWithdraw", - "event-params": "(indexed address,indexed uint256,uint256)" - } - ], - "instances": [{ "address": "0x574Fe4E8120C4Da1741b5Fd45584de7A5b521F0F", "startBlock": "14126699", "symbol": "" }] } ] } diff --git a/src/Mai/mappings/Farm.ts b/src/Mai/mappings/Farm.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/Mai/mappings/handlers.ts b/src/Mai/mappings/handlers.ts index 2667e6a..9059e6b 100644 --- a/src/Mai/mappings/handlers.ts +++ b/src/Mai/mappings/handlers.ts @@ -2,7 +2,8 @@ import { Address, BigInt, Bytes, log } from "@graphprotocol/graph-ts"; import { MaiCamTokenData } from "../../../generated/schema"; import { MaiCamToken } from "../../../generated/MaiCamTokencamWMATIC/MaiCamToken"; import { MaiFinanceFarmAddress, ZERO_BD, ZERO_BI } from "../../utils/constants"; -export function handleCamToken(txnHash: Bytes, blockNumber: BigInt, timestamp: BigInt, camTokenAddress: Address) { + +export function handleCamToken(txnHash: Bytes, blockNumber: BigInt, timestamp: BigInt, camTokenAddress: Address): void { let entity = MaiCamTokenData.load(txnHash.toHex()); if (!entity) entity = new MaiCamTokenData(txnHash.toHex()); let camContract = MaiCamToken.bind(camTokenAddress); @@ -12,5 +13,16 @@ export function handleCamToken(txnHash: Bytes, blockNumber: BigInt, timestamp: B if (totalSupplyResult.reverted) { log.warning("totalSupply() reverted", []); } else { + entity.totalSupply = totalSupplyResult.value; } + let symbolResult = camContract.try_symbol(); + if (symbolResult.reverted) { + log.warning("totalSupply() reverted", []); + } else { + entity.symbol = symbolResult.value; + } + + entity.vault = camTokenAddress; + + entity.save(); } diff --git a/src/Mai/schema.graphql b/src/Mai/schema.graphql index a0f94e0..11bf966 100644 --- a/src/Mai/schema.graphql +++ b/src/Mai/schema.graphql @@ -7,6 +7,7 @@ type MaiCamTokenData @entity { blockTimestamp: BigInt! vault: Bytes totalSupply: BigInt + symbol: String rewardRate: BigDecimal } type MaiPoolData @entity { From e1669f484fc9ae5075e785c26836720c345be229 Mon Sep 17 00:00:00 2001 From: michelet Date: Tue, 18 Jan 2022 13:47:29 -0300 Subject: [PATCH 08/24] WIP, figuring out the TVL for the camTokens --- src/Mai/abis/AToken.json | 347 ++++++++++++++++ src/Mai/abis/CamAave.json | 314 ++++++++++++++ src/Mai/abis/{Token.json => CamWMatic.json} | 141 ++++++- src/Mai/abis/IncentivesController.json | 294 +++++++++++++ src/Mai/abis/LendingPool.json | 433 ++++++++++++++++++++ src/Mai/config/polygon.json | 4 +- src/Mai/mappings/CamToken.ts | 3 +- src/Mai/mappings/handlers.ts | 150 ++++++- src/Mai/schema.graphql | 35 +- src/utils/constants.ts | 1 - 10 files changed, 1691 insertions(+), 31 deletions(-) create mode 100644 src/Mai/abis/AToken.json create mode 100644 src/Mai/abis/CamAave.json rename src/Mai/abis/{Token.json => CamWMatic.json} (51%) create mode 100644 src/Mai/abis/IncentivesController.json create mode 100644 src/Mai/abis/LendingPool.json diff --git a/src/Mai/abis/AToken.json b/src/Mai/abis/AToken.json new file mode 100644 index 0000000..2efe263 --- /dev/null +++ b/src/Mai/abis/AToken.json @@ -0,0 +1,347 @@ +[ + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "spender", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "from", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "index", "type": "uint256" } + ], + "name": "BalanceTransfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "from", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "target", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "index", "type": "uint256" } + ], + "name": "Burn", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "underlyingAsset", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "pool", "type": "address" }, + { "indexed": false, "internalType": "address", "name": "treasury", "type": "address" }, + { "indexed": false, "internalType": "address", "name": "incentivesController", "type": "address" }, + { "indexed": false, "internalType": "uint8", "name": "aTokenDecimals", "type": "uint8" }, + { "indexed": false, "internalType": "string", "name": "aTokenName", "type": "string" }, + { "indexed": false, "internalType": "string", "name": "aTokenSymbol", "type": "string" }, + { "indexed": false, "internalType": "bytes", "name": "params", "type": "bytes" } + ], + "name": "Initialized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "from", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "index", "type": "uint256" } + ], + "name": "Mint", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "from", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "Transfer", + "type": "event" + }, + { + "inputs": [], + "name": "ATOKEN_REVISION", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "EIP712_REVISION", + "outputs": [{ "internalType": "bytes", "name": "", "type": "bytes" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PERMIT_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "POOL", + "outputs": [{ "internalType": "contract ILendingPool", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "RESERVE_TREASURY_ADDRESS", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "UNDERLYING_ASSET_ADDRESS", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "_nonces", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" } + ], + "name": "allowance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "approve", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "user", "type": "address" }], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "user", "type": "address" }, + { "internalType": "address", "name": "receiverOfUnderlying", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "uint256", "name": "index", "type": "uint256" } + ], + "name": "burn", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "subtractedValue", "type": "uint256" } + ], + "name": "decreaseAllowance", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "getIncentivesController", + "outputs": [{ "internalType": "contract IAaveIncentivesController", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "user", "type": "address" }], + "name": "getScaledUserBalanceAndSupply", + "outputs": [ + { "internalType": "uint256", "name": "", "type": "uint256" }, + { "internalType": "uint256", "name": "", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "user", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "handleRepayment", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "addedValue", "type": "uint256" } + ], + "name": "increaseAllowance", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract ILendingPool", "name": "pool", "type": "address" }, + { "internalType": "address", "name": "treasury", "type": "address" }, + { "internalType": "address", "name": "underlyingAsset", "type": "address" }, + { "internalType": "contract IAaveIncentivesController", "name": "incentivesController", "type": "address" }, + { "internalType": "uint8", "name": "aTokenDecimals", "type": "uint8" }, + { "internalType": "string", "name": "aTokenName", "type": "string" }, + { "internalType": "string", "name": "aTokenSymbol", "type": "string" }, + { "internalType": "bytes", "name": "params", "type": "bytes" } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "user", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "uint256", "name": "index", "type": "uint256" } + ], + "name": "mint", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "uint256", "name": "index", "type": "uint256" } + ], + "name": "mintToTreasury", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "value", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "permit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "user", "type": "address" }], + "name": "scaledBalanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "scaledTotalSupply", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "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": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transfer", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "sender", "type": "address" }, + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "transferOnLiquidation", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "target", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transferUnderlyingTo", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/src/Mai/abis/CamAave.json b/src/Mai/abis/CamAave.json new file mode 100644 index 0000000..e3b86da --- /dev/null +++ b/src/Mai/abis/CamAave.json @@ -0,0 +1,314 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "amToken", "type": "address" }, + { "internalType": "address", "name": "underlying", "type": "address" }, + { "internalType": "string", "name": "name", "type": "string" }, + { "internalType": "string", "name": "symbol", "type": "string" }, + { "internalType": "uint8", "name": "decimals", "type": "uint8" } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "spender", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "from", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "Transfer", + "type": "event" + }, + { + "constant": true, + "inputs": [], + "name": "AaveContract", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "LENDING_POOL", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "Token", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "aave", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" } + ], + "name": "allowance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "approve", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "internalType": "address", "name": "account", "type": "address" }], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "claimAaveRewards", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "subtractedValue", "type": "uint256" } + ], + "name": "decreaseAllowance", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "depositFeeBP", + "outputs": [{ "internalType": "uint16", "name": "", "type": "uint16" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "uint256", "name": "_amount", "type": "uint256" }], + "name": "enter", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "harvestMaticIntoToken", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "addedValue", "type": "uint256" } + ], + "name": "increaseAllowance", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "uint256", "name": "_share", "type": "uint256" }], + "name": "leave", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "operator", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transfer", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "sender", "type": "address" }, + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "treasury", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "uni", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "uint16", "name": "_depositFee", "type": "uint16" }], + "name": "updateDepositFee", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "address", "name": "_operator", "type": "address" }], + "name": "updateOperator", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "address", "name": "_treasury", "type": "address" }], + "name": "updateTreasury", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "address", "name": "_router", "type": "address" }], + "name": "updateUniV2Router", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "wMatic", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "weth", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + } +] diff --git a/src/Mai/abis/Token.json b/src/Mai/abis/CamWMatic.json similarity index 51% rename from src/Mai/abis/Token.json rename to src/Mai/abis/CamWMatic.json index 6b6018b..6ff4cab 100644 --- a/src/Mai/abis/Token.json +++ b/src/Mai/abis/CamWMatic.json @@ -1,5 +1,5 @@ [ - { "inputs": [], "stateMutability": "nonpayable", "type": "constructor" }, + { "inputs": [], "payable": false, "stateMutability": "nonpayable", "type": "constructor" }, { "anonymous": false, "inputs": [ @@ -21,91 +21,184 @@ "type": "event" }, { + "constant": true, + "inputs": [], + "name": "AaveContract", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "LENDING_POOL", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "Token", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, "inputs": [ { "internalType": "address", "name": "owner", "type": "address" }, { "internalType": "address", "name": "spender", "type": "address" } ], "name": "allowance", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, "stateMutability": "view", "type": "function" }, { + "constant": false, "inputs": [ { "internalType": "address", "name": "spender", "type": "address" }, { "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "approve", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, "stateMutability": "nonpayable", "type": "function" }, { + "constant": true, "inputs": [{ "internalType": "address", "name": "account", "type": "address" }], "name": "balanceOf", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, "stateMutability": "view", "type": "function" }, { + "constant": false, + "inputs": [], + "name": "claimAaveRewards", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, "inputs": [], "name": "decimals", "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "payable": false, "stateMutability": "view", "type": "function" }, { + "constant": false, "inputs": [ { "internalType": "address", "name": "spender", "type": "address" }, { "internalType": "uint256", "name": "subtractedValue", "type": "uint256" } ], "name": "decreaseAllowance", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, "stateMutability": "nonpayable", "type": "function" }, { + "constant": true, + "inputs": [], + "name": "depositFeeBP", + "outputs": [{ "internalType": "uint16", "name": "", "type": "uint16" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "uint256", "name": "_amount", "type": "uint256" }], + "name": "enter", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, "inputs": [ { "internalType": "address", "name": "spender", "type": "address" }, { "internalType": "uint256", "name": "addedValue", "type": "uint256" } ], "name": "increaseAllowance", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "uint256", "name": "_share", "type": "uint256" }], + "name": "leave", + "outputs": [], + "payable": false, "stateMutability": "nonpayable", "type": "function" }, { + "constant": true, "inputs": [], "name": "name", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "operator", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, "stateMutability": "view", "type": "function" }, { + "constant": true, "inputs": [], "name": "symbol", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "payable": false, "stateMutability": "view", "type": "function" }, { + "constant": true, "inputs": [], "name": "totalSupply", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, "stateMutability": "view", "type": "function" }, { + "constant": false, "inputs": [ { "internalType": "address", "name": "recipient", "type": "address" }, { "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "transfer", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, "stateMutability": "nonpayable", "type": "function" }, { + "constant": false, "inputs": [ { "internalType": "address", "name": "sender", "type": "address" }, { "internalType": "address", "name": "recipient", "type": "address" }, @@ -113,7 +206,53 @@ ], "name": "transferFrom", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "treasury", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "uint16", "name": "_depositFee", "type": "uint16" }], + "name": "updateDepositFee", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "address", "name": "_operator", "type": "address" }], + "name": "updateOperator", + "outputs": [], + "payable": false, "stateMutability": "nonpayable", "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "address", "name": "_treasury", "type": "address" }], + "name": "updateTreasury", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "wMatic", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" } ] diff --git a/src/Mai/abis/IncentivesController.json b/src/Mai/abis/IncentivesController.json new file mode 100644 index 0000000..2de08ad --- /dev/null +++ b/src/Mai/abis/IncentivesController.json @@ -0,0 +1,294 @@ +[ + { + "inputs": [ + { "internalType": "contract IERC20", "name": "rewardToken", "type": "address" }, + { "internalType": "address", "name": "emissionManager", "type": "address" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "asset", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "emission", "type": "uint256" } + ], + "name": "AssetConfigUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "asset", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "index", "type": "uint256" } + ], + "name": "AssetIndexUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "claimer", "type": "address" } + ], + "name": "ClaimerSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "uint256", "name": "ditributionEnd", "type": "uint256" }], + "name": "DistributionEndUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "internalType": "address", "name": "newPendingAdmin", "type": "address" }], + "name": "PendingAdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "RewardsAccrued", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "claimer", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "RewardsClaimed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "internalType": "address", "name": "vault", "type": "address" }], + "name": "RewardsVaultUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "newAdming", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "role", "type": "uint256" } + ], + "name": "RoleClaimed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "asset", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "index", "type": "uint256" } + ], + "name": "UserIndexUpdated", + "type": "event" + }, + { + "inputs": [], + "name": "DISTRIBUTION_END", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "EMISSION_MANAGER", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PRECISION", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "REVISION", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "REWARD_TOKEN", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "assets", + "outputs": [ + { "internalType": "uint128", "name": "emissionPerSecond", "type": "uint128" }, + { "internalType": "uint128", "name": "lastUpdateTimestamp", "type": "uint128" }, + { "internalType": "uint256", "name": "index", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address[]", "name": "assets", "type": "address[]" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "address", "name": "to", "type": "address" } + ], + "name": "claimRewards", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address[]", "name": "assets", "type": "address[]" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "address", "name": "user", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" } + ], + "name": "claimRewardsOnBehalf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "role", "type": "uint256" }], + "name": "claimRoleAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address[]", "name": "assets", "type": "address[]" }, + { "internalType": "uint256[]", "name": "emissionsPerSecond", "type": "uint256[]" } + ], + "name": "configureAssets", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "role", "type": "uint256" }], + "name": "getAdmin", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "user", "type": "address" }], + "name": "getClaimer", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getDistributionEnd", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "role", "type": "uint256" }], + "name": "getPendingAdmin", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address[]", "name": "assets", "type": "address[]" }, + { "internalType": "address", "name": "user", "type": "address" } + ], + "name": "getRewardsBalance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getRewardsVault", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "user", "type": "address" }, + { "internalType": "address", "name": "asset", "type": "address" } + ], + "name": "getUserAssetData", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "_user", "type": "address" }], + "name": "getUserUnclaimedRewards", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "user", "type": "address" }, + { "internalType": "uint256", "name": "totalSupply", "type": "uint256" }, + { "internalType": "uint256", "name": "userBalance", "type": "uint256" } + ], + "name": "handleAction", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "rewardsVault", "type": "address" }], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "user", "type": "address" }, + { "internalType": "address", "name": "caller", "type": "address" } + ], + "name": "setClaimer", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "distributionEnd", "type": "uint256" }], + "name": "setDistributionEnd", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "role", "type": "uint256" }, + { "internalType": "address", "name": "newPendingAdmin", "type": "address" } + ], + "name": "setPendingAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "rewardsVault", "type": "address" }], + "name": "setRewardsVault", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/src/Mai/abis/LendingPool.json b/src/Mai/abis/LendingPool.json new file mode 100644 index 0000000..af5bdcd --- /dev/null +++ b/src/Mai/abis/LendingPool.json @@ -0,0 +1,433 @@ +[ + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "reserve", "type": "address" }, + { "indexed": false, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "onBehalfOf", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "borrowRateMode", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, + { "indexed": true, "internalType": "uint16", "name": "referral", "type": "uint16" } + ], + "name": "Borrow", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "reserve", "type": "address" }, + { "indexed": false, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "onBehalfOf", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "indexed": true, "internalType": "uint16", "name": "referral", "type": "uint16" } + ], + "name": "Deposit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "target", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "initiator", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "asset", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "premium", "type": "uint256" }, + { "indexed": false, "internalType": "uint16", "name": "referralCode", "type": "uint16" } + ], + "name": "FlashLoan", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "collateralAsset", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "debtAsset", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "debtToCover", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "liquidatedCollateralAmount", "type": "uint256" }, + { "indexed": false, "internalType": "address", "name": "liquidator", "type": "address" }, + { "indexed": false, "internalType": "bool", "name": "receiveAToken", "type": "bool" } + ], + "name": "LiquidationCall", + "type": "event" + }, + { "anonymous": false, "inputs": [], "name": "Paused", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "reserve", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "user", "type": "address" } + ], + "name": "RebalanceStableBorrowRate", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "reserve", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "repayer", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "Repay", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "reserve", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "liquidityRate", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "stableBorrowRate", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "variableBorrowRate", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "liquidityIndex", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "variableBorrowIndex", "type": "uint256" } + ], + "name": "ReserveDataUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "reserve", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "user", "type": "address" } + ], + "name": "ReserveUsedAsCollateralDisabled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "reserve", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "user", "type": "address" } + ], + "name": "ReserveUsedAsCollateralEnabled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "reserve", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "rateMode", "type": "uint256" } + ], + "name": "Swap", + "type": "event" + }, + { "anonymous": false, "inputs": [], "name": "Unpaused", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "reserve", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "Withdraw", + "type": "event" + }, + { + "inputs": [], + "name": "FLASHLOAN_PREMIUM_TOTAL", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LENDINGPOOL_REVISION", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_NUMBER_RESERVES", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_STABLE_RATE_BORROW_SIZE_PERCENT", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "asset", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "uint256", "name": "interestRateMode", "type": "uint256" }, + { "internalType": "uint16", "name": "referralCode", "type": "uint16" }, + { "internalType": "address", "name": "onBehalfOf", "type": "address" } + ], + "name": "borrow", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "asset", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "address", "name": "onBehalfOf", "type": "address" }, + { "internalType": "uint16", "name": "referralCode", "type": "uint16" } + ], + "name": "deposit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "asset", "type": "address" }, + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "uint256", "name": "balanceFromBefore", "type": "uint256" }, + { "internalType": "uint256", "name": "balanceToBefore", "type": "uint256" } + ], + "name": "finalizeTransfer", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "receiverAddress", "type": "address" }, + { "internalType": "address[]", "name": "assets", "type": "address[]" }, + { "internalType": "uint256[]", "name": "amounts", "type": "uint256[]" }, + { "internalType": "uint256[]", "name": "modes", "type": "uint256[]" }, + { "internalType": "address", "name": "onBehalfOf", "type": "address" }, + { "internalType": "bytes", "name": "params", "type": "bytes" }, + { "internalType": "uint16", "name": "referralCode", "type": "uint16" } + ], + "name": "flashLoan", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "getAddressesProvider", + "outputs": [{ "internalType": "contract ILendingPoolAddressesProvider", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "asset", "type": "address" }], + "name": "getConfiguration", + "outputs": [ + { + "components": [{ "internalType": "uint256", "name": "data", "type": "uint256" }], + "internalType": "struct DataTypes.ReserveConfigurationMap", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "asset", "type": "address" }], + "name": "getReserveData", + "outputs": [ + { + "components": [ + { + "components": [{ "internalType": "uint256", "name": "data", "type": "uint256" }], + "internalType": "struct DataTypes.ReserveConfigurationMap", + "name": "configuration", + "type": "tuple" + }, + { "internalType": "uint128", "name": "liquidityIndex", "type": "uint128" }, + { "internalType": "uint128", "name": "variableBorrowIndex", "type": "uint128" }, + { "internalType": "uint128", "name": "currentLiquidityRate", "type": "uint128" }, + { "internalType": "uint128", "name": "currentVariableBorrowRate", "type": "uint128" }, + { "internalType": "uint128", "name": "currentStableBorrowRate", "type": "uint128" }, + { "internalType": "uint40", "name": "lastUpdateTimestamp", "type": "uint40" }, + { "internalType": "address", "name": "aTokenAddress", "type": "address" }, + { "internalType": "address", "name": "stableDebtTokenAddress", "type": "address" }, + { "internalType": "address", "name": "variableDebtTokenAddress", "type": "address" }, + { "internalType": "address", "name": "interestRateStrategyAddress", "type": "address" }, + { "internalType": "uint8", "name": "id", "type": "uint8" } + ], + "internalType": "struct DataTypes.ReserveData", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "asset", "type": "address" }], + "name": "getReserveNormalizedIncome", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "asset", "type": "address" }], + "name": "getReserveNormalizedVariableDebt", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getReservesList", + "outputs": [{ "internalType": "address[]", "name": "", "type": "address[]" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "user", "type": "address" }], + "name": "getUserAccountData", + "outputs": [ + { "internalType": "uint256", "name": "totalCollateralETH", "type": "uint256" }, + { "internalType": "uint256", "name": "totalDebtETH", "type": "uint256" }, + { "internalType": "uint256", "name": "availableBorrowsETH", "type": "uint256" }, + { "internalType": "uint256", "name": "currentLiquidationThreshold", "type": "uint256" }, + { "internalType": "uint256", "name": "ltv", "type": "uint256" }, + { "internalType": "uint256", "name": "healthFactor", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "user", "type": "address" }], + "name": "getUserConfiguration", + "outputs": [ + { + "components": [{ "internalType": "uint256", "name": "data", "type": "uint256" }], + "internalType": "struct DataTypes.UserConfigurationMap", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "asset", "type": "address" }, + { "internalType": "address", "name": "aTokenAddress", "type": "address" }, + { "internalType": "address", "name": "stableDebtAddress", "type": "address" }, + { "internalType": "address", "name": "variableDebtAddress", "type": "address" }, + { "internalType": "address", "name": "interestRateStrategyAddress", "type": "address" } + ], + "name": "initReserve", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "contract ILendingPoolAddressesProvider", "name": "provider", "type": "address" }], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "collateralAsset", "type": "address" }, + { "internalType": "address", "name": "debtAsset", "type": "address" }, + { "internalType": "address", "name": "user", "type": "address" }, + { "internalType": "uint256", "name": "debtToCover", "type": "uint256" }, + { "internalType": "bool", "name": "receiveAToken", "type": "bool" } + ], + "name": "liquidationCall", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "paused", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "asset", "type": "address" }, + { "internalType": "address", "name": "user", "type": "address" } + ], + "name": "rebalanceStableBorrowRate", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "asset", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "uint256", "name": "rateMode", "type": "uint256" }, + { "internalType": "address", "name": "onBehalfOf", "type": "address" } + ], + "name": "repay", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "asset", "type": "address" }, + { "internalType": "uint256", "name": "configuration", "type": "uint256" } + ], + "name": "setConfiguration", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bool", "name": "val", "type": "bool" }], + "name": "setPause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "asset", "type": "address" }, + { "internalType": "address", "name": "rateStrategyAddress", "type": "address" } + ], + "name": "setReserveInterestRateStrategyAddress", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "asset", "type": "address" }, + { "internalType": "bool", "name": "useAsCollateral", "type": "bool" } + ], + "name": "setUserUseReserveAsCollateral", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "asset", "type": "address" }, + { "internalType": "uint256", "name": "rateMode", "type": "uint256" } + ], + "name": "swapBorrowRateMode", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "asset", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "address", "name": "to", "type": "address" } + ], + "name": "withdraw", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/src/Mai/config/polygon.json b/src/Mai/config/polygon.json index 23a78a1..2cc3ff7 100644 --- a/src/Mai/config/polygon.json +++ b/src/Mai/config/polygon.json @@ -4,8 +4,8 @@ "contracts": [ { "contract": "CamToken", - "abis": ["CamToken"], - "entities": ["MaiCamTokenData"], + "abis": ["CamToken", "LendingPool", "IncentivesController", "CamAave", "CamWMatic", "AToken"], + "entities": ["MaiCamTokenData, MaiAmTokenData"], "events": [ { "event-name": "Transfer", diff --git a/src/Mai/mappings/CamToken.ts b/src/Mai/mappings/CamToken.ts index 7c4982e..c69f40f 100644 --- a/src/Mai/mappings/CamToken.ts +++ b/src/Mai/mappings/CamToken.ts @@ -6,7 +6,8 @@ export function handleTransfer(event: TransferEvent): void { let to = event.params.to; let value = event.params.value; if (from == ZERO_ADDRESS) { + handleCamToken(event.transaction.hash, event.block.number, event.block.timestamp, event.address, value); } else if (to == ZERO_ADDRESS) { + handleCamToken(event.transaction.hash, event.block.number, event.block.timestamp, event.address, value.neg()); } - handleCamToken(event.transaction.hash, event.block.number, event.block.timestamp, event.address); } diff --git a/src/Mai/mappings/handlers.ts b/src/Mai/mappings/handlers.ts index 9059e6b..9452691 100644 --- a/src/Mai/mappings/handlers.ts +++ b/src/Mai/mappings/handlers.ts @@ -1,20 +1,56 @@ import { Address, BigInt, Bytes, log } from "@graphprotocol/graph-ts"; -import { MaiCamTokenData } from "../../../generated/schema"; -import { MaiCamToken } from "../../../generated/MaiCamTokencamWMATIC/MaiCamToken"; -import { MaiFinanceFarmAddress, ZERO_BD, ZERO_BI } from "../../utils/constants"; +import { MaiCamTokenData, MaiAmTokenData } from "../../../generated/schema"; +import { MaiCamToken } from "../../../generated/MaiCamTokencamUSDC/MaiCamToken"; +import { MaiCamWMatic } from "../../../generated/MaiCamTokencamWMATIC/MaiCamWMatic"; +import { MaiCamAave } from "../../../generated/MaiCamTokencamWMATIC/MaiCamAave"; +import { MaiAToken } from "../../../generated/MaiCamTokencamWMATIC/MaiAToken"; +import { MaiLendingPool } from "../../../generated/MaiCamTokencamWMATIC/MaiLendingPool"; +import { convertBINumToDesiredDecimals } from "../../utils/converters"; -export function handleCamToken(txnHash: Bytes, blockNumber: BigInt, timestamp: BigInt, camTokenAddress: Address): void { +import { MaiIncentivesController } from "../../../generated/MaiCamTokencamWMATIC/MaiIncentivesController"; +import { ZERO_ADDRESS, ZERO_BI } from "../../utils/constants"; + +export function handleCamToken( + txnHash: Bytes, + blockNumber: BigInt, + timestamp: BigInt, + camTokenAddress: Address, + value: BigInt, +): void { let entity = MaiCamTokenData.load(txnHash.toHex()); if (!entity) entity = new MaiCamTokenData(txnHash.toHex()); - let camContract = MaiCamToken.bind(camTokenAddress); entity.blockNumber = blockNumber; entity.blockTimestamp = timestamp; - let totalSupplyResult = camContract.try_totalSupply(); - if (totalSupplyResult.reverted) { - log.warning("totalSupply() reverted", []); + let amLiquidity = ZERO_BI; + // get right underlying reserve contract. + let reserveAddress = ZERO_ADDRESS; + + // lending pool is the same for camToken, camAave and camWMatic + // the abi for the are the same, except for the + let camContract = MaiCamToken.bind(camTokenAddress); + let amTokenResult = camContract.try_usdc(); + if (amTokenResult.reverted) { + log.warning("try_usdc() reverted", []); + // try aave + let camAaveContract = MaiCamAave.bind(camTokenAddress); + let amWethResult = camAaveContract.try_aave(); + if (amWethResult.reverted) { + log.warning("try_weth() reverted", []); + // try WMatic + let camWMaticContract = MaiCamWMatic.bind(camTokenAddress); + let amWMaticResult = camWMaticContract.try_wMatic(); + if (amWMaticResult.reverted) { + log.warning("try_wmatic() reverted", []); + } else { + reserveAddress = amWMaticResult.value; + } + } else { + reserveAddress = amWethResult.value; + } } else { - entity.totalSupply = totalSupplyResult.value; + reserveAddress = amTokenResult.value; } + let symbolResult = camContract.try_symbol(); if (symbolResult.reverted) { log.warning("totalSupply() reverted", []); @@ -22,7 +58,101 @@ export function handleCamToken(txnHash: Bytes, blockNumber: BigInt, timestamp: B entity.symbol = symbolResult.value; } - entity.vault = camTokenAddress; + let decimalsResult = camContract.try_decimals(); + if (decimalsResult.reverted) { + log.warning("try_decimals() reverted", []); + } else { + entity.decimals = decimalsResult.value; + } + + // get emissions per second through the amToken incentives controller + let amContractResult = camContract.try_Token(); + if (amContractResult.reverted) { + log.error("try_Token() reverted", []); + } else { + let amContract = amContractResult.value; + let amATokenContract = MaiAToken.bind(amContract); + let amTokenId = amContract.toHexString(); + + let amToken = MaiAmTokenData.load(amTokenId); + if (!amToken) { + amToken = new MaiAmTokenData(amTokenId); + amToken.symbol = entity.symbol; + amToken.totalLiquidity = BigInt.fromI32(0); + amToken.decimals = 0; + } + let aTokenScaledTotalSupplyResult = amATokenContract.try_scaledTotalSupply(); + + let aTokenDecimalsResult = amATokenContract.try_decimals(); + + if (aTokenScaledTotalSupplyResult.reverted) { + log.warning("total_supply() reverted", []); + } else { + if (aTokenDecimalsResult.reverted) { + log.warning("aToken.try_decimals() reverted", []); + } else { + amLiquidity = aTokenScaledTotalSupplyResult.value; + amToken.decimals = aTokenDecimalsResult.value; + } + } + + let incentivesControllerResult = camContract.try_AaveContract(); + if (incentivesControllerResult.reverted) { + log.error("tokenContract at {} call getAaveContract() reverted", [camContract._address.toHex()]); + } else { + let incentivesControllerAddress = incentivesControllerResult.value; + let incentivesControllerContract = MaiIncentivesController.bind(incentivesControllerAddress); + let assetsResult = incentivesControllerContract.try_assets(amContract); + + if (assetsResult.reverted) { + log.error("AaveincentivesControler at {} call assets({}) reverted", [ + incentivesControllerContract._address.toHex(), + camContract._address.toHex(), + ]); + } else { + let assets = assetsResult.value; + entity.aEmissionPerSecond = assets.value0; //emissionPerSecond + } + } + + //amToken.totalLiquidity = amToken.totalLiquidity.plus(value); + amToken.totalLiquidity = amLiquidity; + amToken.save(); + entity.aTvl = convertBINumToDesiredDecimals(amToken.totalLiquidity, entity.decimals); + // get camToken info through it's lending controller + let lendingControllerResult = camContract.try_LENDING_POOL(); + if (lendingControllerResult.reverted) { + log.error("try_LENDING_POOL() reverted", []); + } else { + let lendingControllerAddress = lendingControllerResult.value; + let lendingPoolContract = MaiLendingPool.bind(lendingControllerAddress); + let camTokenReserveDataResult = lendingPoolContract.try_getReserveData(reserveAddress); + if (camTokenReserveDataResult.reverted) { + log.error("try_getReserveData() reverted", []); + } else { + let camTokenConfiguration = camTokenReserveDataResult.value; + let aTokenAddress = camTokenConfiguration.aTokenAddress; + + let liquidityRate = camTokenConfiguration.currentLiquidityRate; + let stableBorrowRate = camTokenConfiguration.currentStableBorrowRate; + let variableBorrowRate = camTokenConfiguration.currentVariableBorrowRate; + let liquidityIndex = camTokenConfiguration.liquidityIndex; + let variableBorrowIndex = camTokenConfiguration.variableBorrowIndex; + entity.aTokenAddress = aTokenAddress; + entity.liquidityRate = convertBINumToDesiredDecimals(liquidityRate, entity.decimals); + entity.stableBorrowRate = convertBINumToDesiredDecimals(stableBorrowRate, entity.decimals); + entity.variableBorrowRate = convertBINumToDesiredDecimals(variableBorrowRate, entity.decimals); + entity.liquidityIndex = convertBINumToDesiredDecimals(liquidityIndex, entity.decimals); + entity.variableBorrowRate = convertBINumToDesiredDecimals(variableBorrowIndex, entity.decimals); + } + } + } + let totalSupplyResult = camContract.try_totalSupply(); + if (totalSupplyResult.reverted) { + log.warning("totalSupply() reverted", []); + } else { + entity.totalLiquidity = totalSupplyResult.value; + } entity.save(); } diff --git a/src/Mai/schema.graphql b/src/Mai/schema.graphql index 11bf966..273117a 100644 --- a/src/Mai/schema.graphql +++ b/src/Mai/schema.graphql @@ -4,22 +4,25 @@ type MaiCamTokenData @entity { id: ID! blockNumber: BigInt! - blockTimestamp: BigInt! - vault: Bytes - totalSupply: BigInt - symbol: String - rewardRate: BigDecimal + blockTimestamp: BigInt! + decimals: Int + symbol: String + totalLiquidity: BigInt + aEmissionPerSecond: BigInt + aTvl: BigDecimal! + + aTokenAddress: Bytes + liquidityRate: BigDecimal + stableBorrowRate: BigDecimal + variableBorrowRate: BigDecimal + liquidityIndex: BigDecimal + + } -type MaiPoolData @entity { - id: ID! - blockNumber: BigInt - blockTimestamp: BigInt - vault: Bytes - deposited: BigInt - borrowed: BigInt - closingFees: BigInt + +type MaiAmTokenData @entity { + id: ID! symbol: String - txHash: String - tokenPrice: BigInt - ethPrice: BigInt + totalLiquidity: BigInt! + decimals: Int } diff --git a/src/utils/constants.ts b/src/utils/constants.ts index f6398cf..d5d23d4 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -38,4 +38,3 @@ export let LidoNodeOperatorsRegistryAddress: Address = toAddress("0x55032650b14d export let LidoTreasuryAddress: Address = toAddress("0x4333218072D5d7008546737786663c38B4D561A4"); export let SushiMiniChefAddress = toAddress("0x0769fd68dFb93167989C6f7254cd0D766Fb2841F"); -export let MaiFinanceFarmAddress = toAddress("0x574Fe4E8120C4Da1741b5Fd45584de7A5b521F0F"); From d9ecf99d175de362f918de811f0d3ee8ac56377d Mon Sep 17 00:00:00 2001 From: michelet Date: Tue, 18 Jan 2022 14:15:49 -0300 Subject: [PATCH 09/24] WIP: checking camToken supply --- src/Mai/mappings/handlers.ts | 26 ++++++++++++++------------ src/Mai/schema.graphql | 3 +++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/Mai/mappings/handlers.ts b/src/Mai/mappings/handlers.ts index 9452691..bd5edf9 100644 --- a/src/Mai/mappings/handlers.ts +++ b/src/Mai/mappings/handlers.ts @@ -81,22 +81,24 @@ export function handleCamToken( amToken.totalLiquidity = BigInt.fromI32(0); amToken.decimals = 0; } + amToken.blockNumber = blockNumber; + amToken.blockTimestamp = timestamp; - let aTokenScaledTotalSupplyResult = amATokenContract.try_scaledTotalSupply(); + // let aTokenScaledTotalSupplyResult = amATokenContract.try_scaledTotalSupply(); let aTokenDecimalsResult = amATokenContract.try_decimals(); - - if (aTokenScaledTotalSupplyResult.reverted) { - log.warning("total_supply() reverted", []); + if (aTokenDecimalsResult.reverted) { + log.warning("aToken.try_decimals() reverted", []); } else { - if (aTokenDecimalsResult.reverted) { - log.warning("aToken.try_decimals() reverted", []); - } else { - amLiquidity = aTokenScaledTotalSupplyResult.value; - amToken.decimals = aTokenDecimalsResult.value; - } + amToken.decimals = aTokenDecimalsResult.value; } + // if (aTokenScaledTotalSupplyResult.reverted) { + // log.warning("total_supply() reverted", []); + // } else { + // + // } + let incentivesControllerResult = camContract.try_AaveContract(); if (incentivesControllerResult.reverted) { log.error("tokenContract at {} call getAaveContract() reverted", [camContract._address.toHex()]); @@ -116,8 +118,8 @@ export function handleCamToken( } } - //amToken.totalLiquidity = amToken.totalLiquidity.plus(value); - amToken.totalLiquidity = amLiquidity; + amToken.totalLiquidity = amToken.totalLiquidity.plus(value); + //amToken.totalLiquidity = amLiquidity; amToken.save(); entity.aTvl = convertBINumToDesiredDecimals(amToken.totalLiquidity, entity.decimals); // get camToken info through it's lending controller diff --git a/src/Mai/schema.graphql b/src/Mai/schema.graphql index 273117a..6519e8f 100644 --- a/src/Mai/schema.graphql +++ b/src/Mai/schema.graphql @@ -22,7 +22,10 @@ type MaiCamTokenData @entity { type MaiAmTokenData @entity { id: ID! + blockNumber: BigInt + blockTimestamp: BigInt symbol: String totalLiquidity: BigInt! decimals: Int + } From aa50a11d1a42f33081b57a49283c847e805eb459 Mon Sep 17 00:00:00 2001 From: michelet Date: Tue, 18 Jan 2022 17:14:33 -0300 Subject: [PATCH 10/24] WIP: EmissionPerSecond issue --- src/Mai/mappings/handlers.ts | 57 +++++++++++++++++------------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/src/Mai/mappings/handlers.ts b/src/Mai/mappings/handlers.ts index bd5edf9..977c9e5 100644 --- a/src/Mai/mappings/handlers.ts +++ b/src/Mai/mappings/handlers.ts @@ -21,20 +21,19 @@ export function handleCamToken( if (!entity) entity = new MaiCamTokenData(txnHash.toHex()); entity.blockNumber = blockNumber; entity.blockTimestamp = timestamp; - let amLiquidity = ZERO_BI; - // get right underlying reserve contract. - let reserveAddress = ZERO_ADDRESS; // lending pool is the same for camToken, camAave and camWMatic - // the abi for the are the same, except for the let camContract = MaiCamToken.bind(camTokenAddress); + + // get correct underlying reserve contract address. + let reserveAddress = ZERO_ADDRESS; let amTokenResult = camContract.try_usdc(); if (amTokenResult.reverted) { log.warning("try_usdc() reverted", []); // try aave let camAaveContract = MaiCamAave.bind(camTokenAddress); - let amWethResult = camAaveContract.try_aave(); - if (amWethResult.reverted) { + let amAaveResult = camAaveContract.try_aave(); + if (amAaveResult.reverted) { log.warning("try_weth() reverted", []); // try WMatic let camWMaticContract = MaiCamWMatic.bind(camTokenAddress); @@ -45,27 +44,28 @@ export function handleCamToken( reserveAddress = amWMaticResult.value; } } else { - reserveAddress = amWethResult.value; + reserveAddress = amAaveResult.value; } } else { reserveAddress = amTokenResult.value; } + // reserveAddress found + // updating entity symbol let symbolResult = camContract.try_symbol(); if (symbolResult.reverted) { log.warning("totalSupply() reverted", []); } else { entity.symbol = symbolResult.value; } - + // updating entity decimals let decimalsResult = camContract.try_decimals(); if (decimalsResult.reverted) { log.warning("try_decimals() reverted", []); } else { entity.decimals = decimalsResult.value; } - - // get emissions per second through the amToken incentives controller + // finding amToken info and updating amToken let amContractResult = camContract.try_Token(); if (amContractResult.reverted) { log.error("try_Token() reverted", []); @@ -84,27 +84,23 @@ export function handleCamToken( amToken.blockNumber = blockNumber; amToken.blockTimestamp = timestamp; - // let aTokenScaledTotalSupplyResult = amATokenContract.try_scaledTotalSupply(); - let aTokenDecimalsResult = amATokenContract.try_decimals(); if (aTokenDecimalsResult.reverted) { log.warning("aToken.try_decimals() reverted", []); } else { amToken.decimals = aTokenDecimalsResult.value; } + amToken.totalLiquidity = amToken.totalLiquidity.plus(value); + amToken.save(); - // if (aTokenScaledTotalSupplyResult.reverted) { - // log.warning("total_supply() reverted", []); - // } else { - // - // } - + // get emissions per second through the amToken incentives controller let incentivesControllerResult = camContract.try_AaveContract(); if (incentivesControllerResult.reverted) { log.error("tokenContract at {} call getAaveContract() reverted", [camContract._address.toHex()]); } else { let incentivesControllerAddress = incentivesControllerResult.value; let incentivesControllerContract = MaiIncentivesController.bind(incentivesControllerAddress); + let assetsResult = incentivesControllerContract.try_assets(amContract); if (assetsResult.reverted) { @@ -114,13 +110,12 @@ export function handleCamToken( ]); } else { let assets = assetsResult.value; - entity.aEmissionPerSecond = assets.value0; //emissionPerSecond + // https://docs.aave.com/developers/guides/apy-and-apr + // + entity.aEmissionPerSecond = assets.value0; //emissionPerSecond, expressed in WEI } } - amToken.totalLiquidity = amToken.totalLiquidity.plus(value); - //amToken.totalLiquidity = amLiquidity; - amToken.save(); entity.aTvl = convertBINumToDesiredDecimals(amToken.totalLiquidity, entity.decimals); // get camToken info through it's lending controller let lendingControllerResult = camContract.try_LENDING_POOL(); @@ -142,19 +137,21 @@ export function handleCamToken( let liquidityIndex = camTokenConfiguration.liquidityIndex; let variableBorrowIndex = camTokenConfiguration.variableBorrowIndex; entity.aTokenAddress = aTokenAddress; - entity.liquidityRate = convertBINumToDesiredDecimals(liquidityRate, entity.decimals); - entity.stableBorrowRate = convertBINumToDesiredDecimals(stableBorrowRate, entity.decimals); - entity.variableBorrowRate = convertBINumToDesiredDecimals(variableBorrowRate, entity.decimals); - entity.liquidityIndex = convertBINumToDesiredDecimals(liquidityIndex, entity.decimals); - entity.variableBorrowRate = convertBINumToDesiredDecimals(variableBorrowIndex, entity.decimals); + // https://docs.aave.com/developers/guides/apy-and-apr + // Rates + entity.liquidityRate = convertBINumToDesiredDecimals(liquidityRate, 27); + entity.stableBorrowRate = convertBINumToDesiredDecimals(stableBorrowRate, 27); + entity.variableBorrowRate = convertBINumToDesiredDecimals(variableBorrowRate, 27); + entity.liquidityIndex = convertBINumToDesiredDecimals(liquidityIndex, 27); + entity.variableBorrowRate = convertBINumToDesiredDecimals(variableBorrowIndex, 27); } } } - let totalSupplyResult = camContract.try_totalSupply(); - if (totalSupplyResult.reverted) { + let camTokenTotalLiquidityResult = camContract.try_totalSupply(); + if (camTokenTotalLiquidityResult.reverted) { log.warning("totalSupply() reverted", []); } else { - entity.totalLiquidity = totalSupplyResult.value; + entity.totalLiquidity = camTokenTotalLiquidityResult.value; } entity.save(); } From 82692a8bcf6f4cd11c22463f34953fc036b31f79 Mon Sep 17 00:00:00 2001 From: michelet Date: Wed, 19 Jan 2022 18:23:46 -0300 Subject: [PATCH 11/24] wip: refactoring camToken --- src/Mai/abis/Farm.json | 247 ---------------------------------- src/Mai/config/polygon.json | 53 ++++++-- src/Mai/mappings/CamAave.ts | 41 ++++++ src/Mai/mappings/CamToken.ts | 33 ++++- src/Mai/mappings/CamWMatic.ts | 42 ++++++ src/Mai/mappings/handlers.ts | 53 +++----- src/Mai/schema.graphql | 9 +- 7 files changed, 177 insertions(+), 301 deletions(-) delete mode 100644 src/Mai/abis/Farm.json create mode 100644 src/Mai/mappings/CamAave.ts create mode 100644 src/Mai/mappings/CamWMatic.ts diff --git a/src/Mai/abis/Farm.json b/src/Mai/abis/Farm.json deleted file mode 100644 index 3f51ca3..0000000 --- a/src/Mai/abis/Farm.json +++ /dev/null @@ -1,247 +0,0 @@ -[ - { - "inputs": [ - { "internalType": "contract IERC20", "name": "_erc20", "type": "address" }, - { "internalType": "uint256", "name": "_rewardPerBlock", "type": "uint256" }, - { "internalType": "uint256", "name": "_startBlock", "type": "uint256" }, - { "internalType": "address", "name": "_feeAddress", "type": "address" } - ], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, - { "indexed": true, "internalType": "uint256", "name": "pid", "type": "uint256" }, - { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } - ], - "name": "Deposit", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, - { "indexed": true, "internalType": "uint256", "name": "pid", "type": "uint256" }, - { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } - ], - "name": "EmergencyWithdraw", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, - { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" } - ], - "name": "OwnershipTransferred", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, - { "indexed": true, "internalType": "uint256", "name": "pid", "type": "uint256" }, - { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } - ], - "name": "Withdraw", - "type": "event" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "_allocPoint", "type": "uint256" }, - { "internalType": "contract IERC20", "name": "_lpToken", "type": "address" }, - { "internalType": "bool", "name": "_withUpdate", "type": "bool" }, - { "internalType": "uint16", "name": "_depositFeeBP", "type": "uint16" } - ], - "name": "add", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "_pid", "type": "uint256" }, - { "internalType": "uint256", "name": "_amount", "type": "uint256" } - ], - "name": "deposit", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "_pid", "type": "uint256" }, - { "internalType": "address", "name": "_user", "type": "address" } - ], - "name": "deposited", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [{ "internalType": "uint256", "name": "_pid", "type": "uint256" }], - "name": "emergencyWithdraw", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "endBlock", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "erc20", - "outputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "feeAddress", - "outputs": [{ "internalType": "address", "name": "", "type": "address" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [{ "internalType": "uint256", "name": "_amount", "type": "uint256" }], - "name": "fund", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { "inputs": [], "name": "massUpdatePools", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, - { - "inputs": [], - "name": "owner", - "outputs": [{ "internalType": "address", "name": "", "type": "address" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "paidOut", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "_pid", "type": "uint256" }, - { "internalType": "address", "name": "_user", "type": "address" } - ], - "name": "pending", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "name": "poolInfo", - "outputs": [ - { "internalType": "contract IERC20", "name": "lpToken", "type": "address" }, - { "internalType": "uint256", "name": "allocPoint", "type": "uint256" }, - { "internalType": "uint256", "name": "lastRewardBlock", "type": "uint256" }, - { "internalType": "uint256", "name": "accERC20PerShare", "type": "uint256" }, - { "internalType": "uint16", "name": "depositFeeBP", "type": "uint16" } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "poolLength", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { "inputs": [], "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, - { - "inputs": [], - "name": "rewardPerBlock", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "_pid", "type": "uint256" }, - { "internalType": "uint256", "name": "_allocPoint", "type": "uint256" }, - { "internalType": "bool", "name": "_withUpdate", "type": "bool" } - ], - "name": "set", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [{ "internalType": "address", "name": "_feeAddress", "type": "address" }], - "name": "setFeeAddress", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "startBlock", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "totalAllocPoint", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "totalPending", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }], - "name": "transferOwnership", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [{ "internalType": "uint256", "name": "_pid", "type": "uint256" }], - "name": "updatePool", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "", "type": "uint256" }, - { "internalType": "address", "name": "", "type": "address" } - ], - "name": "userInfo", - "outputs": [ - { "internalType": "uint256", "name": "amount", "type": "uint256" }, - { "internalType": "uint256", "name": "rewardDebt", "type": "uint256" } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "_pid", "type": "uint256" }, - { "internalType": "uint256", "name": "_amount", "type": "uint256" } - ], - "name": "withdraw", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - } -] diff --git a/src/Mai/config/polygon.json b/src/Mai/config/polygon.json index 2cc3ff7..d990b8c 100644 --- a/src/Mai/config/polygon.json +++ b/src/Mai/config/polygon.json @@ -4,7 +4,7 @@ "contracts": [ { "contract": "CamToken", - "abis": ["CamToken", "LendingPool", "IncentivesController", "CamAave", "CamWMatic", "AToken"], + "abis": ["CamToken", "LendingPool", "IncentivesController", "AToken"], "entities": ["MaiCamTokenData, MaiAmTokenData"], "events": [ { @@ -23,30 +23,57 @@ "startBlock": "15723203", "symbol": "camDAI" }, - { - "address": "0x0470CD31C8FcC42671465880BA81D631F0B76C1D", - "startBlock": "15723236", - "symbol": "camWETH" - }, + { "address": "0xB3911259f435b28EC072E4Ff6fF5A2C604fea0Fb", "startBlock": "16062135", "symbol": "camUSDT" }, { - "address": "0x7068Ea5255cb05931EFa8026Bd04b18F3DeB8b0B", - "startBlock": "15683191", - "symbol": "camWMATIC" + "address": "0xBa6273A78a23169e01317bd0f6338547F869E8Df", + "startBlock": "17151483", + "symbol": "camWBTC" }, + { + "address": "0x0470CD31C8FcC42671465880BA81D631F0B76C1D", + "startBlock": "15723236", + "symbol": "camWETH" + } + ] + }, + { + "contract": "CamAave", + "abis": ["CamAave", "LendingPool", "IncentivesController", "AToken"], + "entities": ["MaiCamTokenData, MaiAmTokenData"], + "events": [ + { + "event-name": "Transfer", + "event-params": "(indexed address,indexed address,uint256)" + } + ], + "instances": [ { "address": "0xeA4040B21cb68afb94889cB60834b13427CFc4EB", "startBlock": "17151560", "symbol": "camAAVE" - }, + } + ] + }, + { + "contract": "CamWMatic", + "abis": ["LendingPool", "IncentivesController", "CamWMatic", "AToken"], + "entities": ["MaiCamTokenData, MaiAmTokenData"], + "events": [ { - "address": "0xBa6273A78a23169e01317bd0f6338547F869E8Df", - "startBlock": "17151483", - "symbol": "camWBTC" + "event-name": "Transfer", + "event-params": "(indexed address,indexed address,uint256)" + } + ], + "instances": [ + { + "address": "0x7068Ea5255cb05931EFa8026Bd04b18F3DeB8b0B", + "startBlock": "15683191", + "symbol": "camWMATIC" } ] } diff --git a/src/Mai/mappings/CamAave.ts b/src/Mai/mappings/CamAave.ts new file mode 100644 index 0000000..56dd131 --- /dev/null +++ b/src/Mai/mappings/CamAave.ts @@ -0,0 +1,41 @@ +import { Transfer as TransferEvent } from "../../../generated/MaiCamAavecamAAVE/MaiCamAave"; +import { log } from "@graphprotocol/graph-ts"; + +import { ZERO_ADDRESS } from "../../utils/constants"; +import { handleCamToken } from "./handlers"; +import { MaiCamAave } from "../../../generated/MaiCamAavecamAAVE/MaiCamAave"; + +export function handleTransfer(event: TransferEvent): void { + let from = event.params.from; + let to = event.params.to; + let value = event.params.value; + if (from != ZERO_ADDRESS && to != ZERO_ADDRESS) { + return; + } + let camType = "aave"; + + if (from == ZERO_ADDRESS) { + //mint + } else if (to == ZERO_ADDRESS) { + // burn + value = value.neg(); + } + let camContract = MaiCamAave.bind(event.address); + let reserveAddress = ZERO_ADDRESS; + let reserveResult = camContract.try_aave(); + if (reserveResult.reverted) { + log.error("try_usdc() reverted", []); + } else { + reserveAddress = reserveResult.value; + } + + handleCamToken( + event.transaction.hash, + event.block.number, + event.block.timestamp, + event.address, + value, + camType, + reserveAddress, + ); +} diff --git a/src/Mai/mappings/CamToken.ts b/src/Mai/mappings/CamToken.ts index c69f40f..7f2e92b 100644 --- a/src/Mai/mappings/CamToken.ts +++ b/src/Mai/mappings/CamToken.ts @@ -1,13 +1,40 @@ -import { Transfer as TransferEvent } from "../../../generated/MaiCamTokencamWMATIC/MaiCamToken"; +import { Transfer as TransferEvent } from "../../../generated/MaiCamTokencamDAI/MaiCamToken"; import { ZERO_ADDRESS } from "../../utils/constants"; +import { MaiCamToken } from "../../../generated/MaiCamTokencamUSDC/MaiCamToken"; +import { log } from "@graphprotocol/graph-ts"; + import { handleCamToken } from "./handlers"; export function handleTransfer(event: TransferEvent): void { let from = event.params.from; let to = event.params.to; let value = event.params.value; + + if (from != ZERO_ADDRESS && to != ZERO_ADDRESS) { + return; + } + let camType = "token"; + if (from == ZERO_ADDRESS) { - handleCamToken(event.transaction.hash, event.block.number, event.block.timestamp, event.address, value); + //mint } else if (to == ZERO_ADDRESS) { - handleCamToken(event.transaction.hash, event.block.number, event.block.timestamp, event.address, value.neg()); + // burn + value = value.neg(); + } + let reserveAddress = ZERO_ADDRESS; + let camContract = MaiCamToken.bind(event.address); + let reserveResult = camContract.try_usdc(); + if (reserveResult.reverted) { + log.error("try_usdc() reverted", []); + } else { + reserveAddress = reserveResult.value; } + handleCamToken( + event.transaction.hash, + event.block.number, + event.block.timestamp, + event.address, + value, + camType, + reserveAddress, + ); } diff --git a/src/Mai/mappings/CamWMatic.ts b/src/Mai/mappings/CamWMatic.ts new file mode 100644 index 0000000..931f452 --- /dev/null +++ b/src/Mai/mappings/CamWMatic.ts @@ -0,0 +1,42 @@ +import { Transfer as TransferEvent } from "../../../generated/MaiCamWMaticcamWMATIC/MaiCamWMatic"; +import { ZERO_ADDRESS } from "../../utils/constants"; +import { log } from "@graphprotocol/graph-ts"; + +import { MaiCamWMatic } from "../../../generated/MaiCamWMaticcamWMATIC/MaiCamWMatic"; + +import { handleCamToken } from "./handlers"; +export function handleTransfer(event: TransferEvent): void { + let from = event.params.from; + let to = event.params.to; + let value = event.params.value; + + if (from != ZERO_ADDRESS && to != ZERO_ADDRESS) { + return; + } + let camType = "token"; + + if (from == ZERO_ADDRESS) { + //mint + } else if (to == ZERO_ADDRESS) { + // burn + value = value.neg(); + } + let camContract = MaiCamWMatic.bind(event.address); + let reserveAddress = ZERO_ADDRESS; + let reserveResult = camContract.try_wMatic(); + if (reserveResult.reverted) { + log.error("try_usdc() reverted", []); + } else { + reserveAddress = reserveResult.value; + } + + handleCamToken( + event.transaction.hash, + event.block.number, + event.block.timestamp, + event.address, + value, + camType, + reserveAddress, + ); +} diff --git a/src/Mai/mappings/handlers.ts b/src/Mai/mappings/handlers.ts index 977c9e5..cf62661 100644 --- a/src/Mai/mappings/handlers.ts +++ b/src/Mai/mappings/handlers.ts @@ -1,14 +1,18 @@ import { Address, BigInt, Bytes, log } from "@graphprotocol/graph-ts"; import { MaiCamTokenData, MaiAmTokenData } from "../../../generated/schema"; import { MaiCamToken } from "../../../generated/MaiCamTokencamUSDC/MaiCamToken"; -import { MaiCamWMatic } from "../../../generated/MaiCamTokencamWMATIC/MaiCamWMatic"; -import { MaiCamAave } from "../../../generated/MaiCamTokencamWMATIC/MaiCamAave"; -import { MaiAToken } from "../../../generated/MaiCamTokencamWMATIC/MaiAToken"; -import { MaiLendingPool } from "../../../generated/MaiCamTokencamWMATIC/MaiLendingPool"; -import { convertBINumToDesiredDecimals } from "../../utils/converters"; +import { MaiCamWMatic } from "../../../generated/MaiCamWMaticcamWMATIC/MaiCamWMatic"; +import { MaiCamAave } from "../../../generated/MaiCamAavecamAAVE/MaiCamAave"; +import { MaiAToken } from "../../../generated/MaiCamAavecamAAVE/MaiAToken"; +import { MaiLendingPool } from "../../../generated/MaiCamAavecamAAVE/MaiLendingPool"; +import { convertBINumToDesiredDecimals, toAddress } from "../../utils/converters"; -import { MaiIncentivesController } from "../../../generated/MaiCamTokencamWMATIC/MaiIncentivesController"; +import { MaiIncentivesController } from "../../../generated/MaiCamWMaticcamWMATIC/MaiIncentivesController"; import { ZERO_ADDRESS, ZERO_BI } from "../../utils/constants"; +// TODO: Mapping for the reserve address +// get balance of the amToken so I don't use a state entity +let CAM_INCENTIVES_CONTROLLER_ADDRESS: Address = toAddress("0x357D51124f59836DeD84c8a1730D72B749d8BC23"); +let CAM_LENDING_POOL_ADDRESS: Address = toAddress("0x8dFf5E27EA6b7AC08EbFdf9eB090F32ee9a30fcf"); export function handleCamToken( txnHash: Bytes, @@ -16,41 +20,18 @@ export function handleCamToken( timestamp: BigInt, camTokenAddress: Address, value: BigInt, + camType: string, + reserveAddress: Address, ): void { let entity = MaiCamTokenData.load(txnHash.toHex()); if (!entity) entity = new MaiCamTokenData(txnHash.toHex()); entity.blockNumber = blockNumber; entity.blockTimestamp = timestamp; + let balanceOfCam = ZERO_BI; // lending pool is the same for camToken, camAave and camWMatic let camContract = MaiCamToken.bind(camTokenAddress); - // get correct underlying reserve contract address. - let reserveAddress = ZERO_ADDRESS; - let amTokenResult = camContract.try_usdc(); - if (amTokenResult.reverted) { - log.warning("try_usdc() reverted", []); - // try aave - let camAaveContract = MaiCamAave.bind(camTokenAddress); - let amAaveResult = camAaveContract.try_aave(); - if (amAaveResult.reverted) { - log.warning("try_weth() reverted", []); - // try WMatic - let camWMaticContract = MaiCamWMatic.bind(camTokenAddress); - let amWMaticResult = camWMaticContract.try_wMatic(); - if (amWMaticResult.reverted) { - log.warning("try_wmatic() reverted", []); - } else { - reserveAddress = amWMaticResult.value; - } - } else { - reserveAddress = amAaveResult.value; - } - } else { - reserveAddress = amTokenResult.value; - } - // reserveAddress found - // updating entity symbol let symbolResult = camContract.try_symbol(); if (symbolResult.reverted) { @@ -84,6 +65,12 @@ export function handleCamToken( amToken.blockNumber = blockNumber; amToken.blockTimestamp = timestamp; + let amBalanceResult = amATokenContract.try_balanceOf(camTokenAddress); + if (amBalanceResult.reverted) { + } else { + balanceOfCam = amBalanceResult.value; + } + let aTokenDecimalsResult = amATokenContract.try_decimals(); if (aTokenDecimalsResult.reverted) { log.warning("aToken.try_decimals() reverted", []); @@ -116,7 +103,7 @@ export function handleCamToken( } } - entity.aTvl = convertBINumToDesiredDecimals(amToken.totalLiquidity, entity.decimals); + entity.aTvl = convertBINumToDesiredDecimals(balanceOfCam, entity.decimals); // get camToken info through it's lending controller let lendingControllerResult = camContract.try_LENDING_POOL(); if (lendingControllerResult.reverted) { diff --git a/src/Mai/schema.graphql b/src/Mai/schema.graphql index 6519e8f..9a5081c 100644 --- a/src/Mai/schema.graphql +++ b/src/Mai/schema.graphql @@ -2,22 +2,21 @@ # Mai Finance # ---------------------------------------- type MaiCamTokenData @entity { - id: ID! + id: ID! #camToken address blockNumber: BigInt! - blockTimestamp: BigInt! + blockTimestamp: BigInt! + aTvl: BigDecimal! decimals: Int symbol: String totalLiquidity: BigInt aEmissionPerSecond: BigInt - aTvl: BigDecimal! - + txHash: Bytes aTokenAddress: Bytes liquidityRate: BigDecimal stableBorrowRate: BigDecimal variableBorrowRate: BigDecimal liquidityIndex: BigDecimal - } type MaiAmTokenData @entity { From bb1519538bdedc646a75317d9f19d05bea17d969 Mon Sep 17 00:00:00 2001 From: michelet Date: Thu, 20 Jan 2022 21:30:30 -0300 Subject: [PATCH 12/24] wip: changing file names --- src/Mai/config/polygon.json | 4 ++-- src/Mai/mappings/CamWMatic.ts | 7 +++---- src/Mai/mappings/handlers.ts | 4 +--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Mai/config/polygon.json b/src/Mai/config/polygon.json index d990b8c..46c061f 100644 --- a/src/Mai/config/polygon.json +++ b/src/Mai/config/polygon.json @@ -60,8 +60,8 @@ ] }, { - "contract": "CamWMatic", - "abis": ["LendingPool", "IncentivesController", "CamWMatic", "AToken"], + "contract": "CamWMATIC", + "abis": ["CamWMATIC", "LendingPool", "IncentivesController", "AToken"], "entities": ["MaiCamTokenData, MaiAmTokenData"], "events": [ { diff --git a/src/Mai/mappings/CamWMatic.ts b/src/Mai/mappings/CamWMatic.ts index 931f452..5696360 100644 --- a/src/Mai/mappings/CamWMatic.ts +++ b/src/Mai/mappings/CamWMatic.ts @@ -1,8 +1,7 @@ -import { Transfer as TransferEvent } from "../../../generated/MaiCamWMaticcamWMATIC/MaiCamWMatic"; +import { Transfer as TransferEvent } from "../../../generated/MaiCamWMATICcamWMATIC/MaiCamWMATIC"; import { ZERO_ADDRESS } from "../../utils/constants"; import { log } from "@graphprotocol/graph-ts"; - -import { MaiCamWMatic } from "../../../generated/MaiCamWMaticcamWMATIC/MaiCamWMatic"; +import { MaiCamWMATIC } from "../../../generated/MaiCamWMATICcamWMATIC/MaiCamWMATIC"; import { handleCamToken } from "./handlers"; export function handleTransfer(event: TransferEvent): void { @@ -21,7 +20,7 @@ export function handleTransfer(event: TransferEvent): void { // burn value = value.neg(); } - let camContract = MaiCamWMatic.bind(event.address); + let camContract = MaiCamWMATIC.bind(event.address); let reserveAddress = ZERO_ADDRESS; let reserveResult = camContract.try_wMatic(); if (reserveResult.reverted) { diff --git a/src/Mai/mappings/handlers.ts b/src/Mai/mappings/handlers.ts index cf62661..302b46f 100644 --- a/src/Mai/mappings/handlers.ts +++ b/src/Mai/mappings/handlers.ts @@ -1,14 +1,12 @@ import { Address, BigInt, Bytes, log } from "@graphprotocol/graph-ts"; import { MaiCamTokenData, MaiAmTokenData } from "../../../generated/schema"; import { MaiCamToken } from "../../../generated/MaiCamTokencamUSDC/MaiCamToken"; -import { MaiCamWMatic } from "../../../generated/MaiCamWMaticcamWMATIC/MaiCamWMatic"; -import { MaiCamAave } from "../../../generated/MaiCamAavecamAAVE/MaiCamAave"; import { MaiAToken } from "../../../generated/MaiCamAavecamAAVE/MaiAToken"; import { MaiLendingPool } from "../../../generated/MaiCamAavecamAAVE/MaiLendingPool"; import { convertBINumToDesiredDecimals, toAddress } from "../../utils/converters"; import { MaiIncentivesController } from "../../../generated/MaiCamWMaticcamWMATIC/MaiIncentivesController"; -import { ZERO_ADDRESS, ZERO_BI } from "../../utils/constants"; +import { ZERO_BI } from "../../utils/constants"; // TODO: Mapping for the reserve address // get balance of the amToken so I don't use a state entity let CAM_INCENTIVES_CONTROLLER_ADDRESS: Address = toAddress("0x357D51124f59836DeD84c8a1730D72B749d8BC23"); From c2cf8ab4c3f941b1c54a819976517ba4b08259ba Mon Sep 17 00:00:00 2001 From: michelet Date: Fri, 21 Jan 2022 15:29:08 -0300 Subject: [PATCH 13/24] Removing state entity, calculating right aTvl. --- src/Mai/config/polygon.json | 1 - src/Mai/mappings/CamAave.ts | 51 ++++++++-- src/Mai/mappings/CamToken.ts | 54 +++++++--- src/Mai/mappings/CamWMatic.ts | 50 ++++++++-- src/Mai/mappings/handlers.ts | 179 ++++++++++++---------------------- src/Mai/schema.graphql | 31 +++--- 6 files changed, 199 insertions(+), 167 deletions(-) diff --git a/src/Mai/config/polygon.json b/src/Mai/config/polygon.json index 46c061f..aecd380 100644 --- a/src/Mai/config/polygon.json +++ b/src/Mai/config/polygon.json @@ -23,7 +23,6 @@ "startBlock": "15723203", "symbol": "camDAI" }, - { "address": "0xB3911259f435b28EC072E4Ff6fF5A2C604fea0Fb", "startBlock": "16062135", diff --git a/src/Mai/mappings/CamAave.ts b/src/Mai/mappings/CamAave.ts index 56dd131..19c26c7 100644 --- a/src/Mai/mappings/CamAave.ts +++ b/src/Mai/mappings/CamAave.ts @@ -1,7 +1,8 @@ -import { Transfer as TransferEvent } from "../../../generated/MaiCamAavecamAAVE/MaiCamAave"; import { log } from "@graphprotocol/graph-ts"; -import { ZERO_ADDRESS } from "../../utils/constants"; +import { Transfer as TransferEvent } from "../../../generated/MaiCamAavecamAAVE/MaiCamAave"; + +import { ZERO_ADDRESS, ZERO_BI } from "../../utils/constants"; import { handleCamToken } from "./handlers"; import { MaiCamAave } from "../../../generated/MaiCamAavecamAAVE/MaiCamAave"; @@ -9,33 +10,65 @@ export function handleTransfer(event: TransferEvent): void { let from = event.params.from; let to = event.params.to; let value = event.params.value; + + // only interested on mints and burns. if (from != ZERO_ADDRESS && to != ZERO_ADDRESS) { return; } - let camType = "aave"; - if (from == ZERO_ADDRESS) { - //mint - } else if (to == ZERO_ADDRESS) { + if (to == ZERO_ADDRESS) { // burn value = value.neg(); } let camContract = MaiCamAave.bind(event.address); let reserveAddress = ZERO_ADDRESS; let reserveResult = camContract.try_aave(); + let symbol = ""; + let decimals: i32 = 0; + let amTokenAddress = ZERO_ADDRESS; if (reserveResult.reverted) { - log.error("try_usdc() reverted", []); + log.warning("try_wMatic() reverted", []); } else { reserveAddress = reserveResult.value; } + let symbolResult = camContract.try_symbol(); + if (symbolResult.reverted) { + log.warning("totalSupply() reverted", []); + } else { + symbol = symbolResult.value; + } + // updating entity decimals + let decimalsResult = camContract.try_decimals(); + if (decimalsResult.reverted) { + log.warning("try_decimals() reverted", []); + } else { + decimals = decimalsResult.value; + } + // finding amToken address + let amContractResult = camContract.try_Token(); + if (amContractResult.reverted) { + log.warning("try_Token() reverted", []); + } else { + let amContract = amContractResult.value; + amTokenAddress = amContract; + } + let totalLiquidity = ZERO_BI; + let totalLiquidityResult = camContract.try_totalSupply(); + if (totalLiquidityResult.reverted) { + log.warning("try_Token() reverted", []); + } else { + totalLiquidity = totalLiquidityResult.value; + } handleCamToken( event.transaction.hash, event.block.number, event.block.timestamp, event.address, - value, - camType, reserveAddress, + amTokenAddress, + decimals, + symbol, + totalLiquidity, ); } diff --git a/src/Mai/mappings/CamToken.ts b/src/Mai/mappings/CamToken.ts index 7f2e92b..4db0538 100644 --- a/src/Mai/mappings/CamToken.ts +++ b/src/Mai/mappings/CamToken.ts @@ -1,7 +1,7 @@ -import { Transfer as TransferEvent } from "../../../generated/MaiCamTokencamDAI/MaiCamToken"; -import { ZERO_ADDRESS } from "../../utils/constants"; -import { MaiCamToken } from "../../../generated/MaiCamTokencamUSDC/MaiCamToken"; import { log } from "@graphprotocol/graph-ts"; +import { Transfer as TransferEvent } from "../../../generated/MaiCamTokencamUSDC/MaiCamToken"; +import { ZERO_ADDRESS, ZERO_BI } from "../../utils/constants"; +import { MaiCamToken } from "../../../generated/MaiCamTokencamUSDC/MaiCamToken"; import { handleCamToken } from "./handlers"; export function handleTransfer(event: TransferEvent): void { @@ -9,32 +9,64 @@ export function handleTransfer(event: TransferEvent): void { let to = event.params.to; let value = event.params.value; + // only interested on mints and burns. if (from != ZERO_ADDRESS && to != ZERO_ADDRESS) { return; } - let camType = "token"; - if (from == ZERO_ADDRESS) { - //mint - } else if (to == ZERO_ADDRESS) { + if (to == ZERO_ADDRESS) { // burn value = value.neg(); } - let reserveAddress = ZERO_ADDRESS; let camContract = MaiCamToken.bind(event.address); + let reserveAddress = ZERO_ADDRESS; let reserveResult = camContract.try_usdc(); + let symbol = ""; + let decimals: i32 = 0; + let amTokenAddress = ZERO_ADDRESS; if (reserveResult.reverted) { - log.error("try_usdc() reverted", []); + log.warning("try_wMatic() reverted", []); } else { reserveAddress = reserveResult.value; } + let symbolResult = camContract.try_symbol(); + if (symbolResult.reverted) { + log.warning("totalSupply() reverted", []); + } else { + symbol = symbolResult.value; + } + // updating entity decimals + let decimalsResult = camContract.try_decimals(); + if (decimalsResult.reverted) { + log.warning("try_decimals() reverted", []); + } else { + decimals = decimalsResult.value; + } + // finding amToken address + let amContractResult = camContract.try_Token(); + if (amContractResult.reverted) { + log.warning("try_Token() reverted", []); + } else { + let amContract = amContractResult.value; + amTokenAddress = amContract; + } + let totalLiquidity = ZERO_BI; + let totalLiquidityResult = camContract.try_totalSupply(); + if (totalLiquidityResult.reverted) { + log.warning("try_Token() reverted", []); + } else { + totalLiquidity = totalLiquidityResult.value; + } + handleCamToken( event.transaction.hash, event.block.number, event.block.timestamp, event.address, - value, - camType, reserveAddress, + amTokenAddress, + decimals, + symbol, + totalLiquidity, ); } diff --git a/src/Mai/mappings/CamWMatic.ts b/src/Mai/mappings/CamWMatic.ts index 5696360..f898e33 100644 --- a/src/Mai/mappings/CamWMatic.ts +++ b/src/Mai/mappings/CamWMatic.ts @@ -1,41 +1,73 @@ import { Transfer as TransferEvent } from "../../../generated/MaiCamWMATICcamWMATIC/MaiCamWMATIC"; -import { ZERO_ADDRESS } from "../../utils/constants"; + import { log } from "@graphprotocol/graph-ts"; +import { ZERO_ADDRESS, ZERO_BI } from "../../utils/constants"; import { MaiCamWMATIC } from "../../../generated/MaiCamWMATICcamWMATIC/MaiCamWMATIC"; - import { handleCamToken } from "./handlers"; + export function handleTransfer(event: TransferEvent): void { let from = event.params.from; let to = event.params.to; let value = event.params.value; + // only interested on mints and burns. if (from != ZERO_ADDRESS && to != ZERO_ADDRESS) { return; } - let camType = "token"; - if (from == ZERO_ADDRESS) { - //mint - } else if (to == ZERO_ADDRESS) { + if (to == ZERO_ADDRESS) { // burn value = value.neg(); } let camContract = MaiCamWMATIC.bind(event.address); let reserveAddress = ZERO_ADDRESS; let reserveResult = camContract.try_wMatic(); + let symbol = ""; + let decimals: i32 = 0; + let amTokenAddress = ZERO_ADDRESS; if (reserveResult.reverted) { - log.error("try_usdc() reverted", []); + log.warning("try_wMatic() reverted", []); } else { reserveAddress = reserveResult.value; } + let symbolResult = camContract.try_symbol(); + if (symbolResult.reverted) { + log.warning("totalSupply() reverted", []); + } else { + symbol = symbolResult.value; + } + // updating entity decimals + let decimalsResult = camContract.try_decimals(); + if (decimalsResult.reverted) { + log.warning("try_decimals() reverted", []); + } else { + decimals = decimalsResult.value; + } + // finding amToken address + let amContractResult = camContract.try_Token(); + if (amContractResult.reverted) { + log.warning("try_Token() reverted", []); + } else { + let amContract = amContractResult.value; + amTokenAddress = amContract; + } + let totalLiquidity = ZERO_BI; + let totalLiquidityResult = camContract.try_totalSupply(); + if (totalLiquidityResult.reverted) { + log.warning("try_Token() reverted", []); + } else { + totalLiquidity = totalLiquidityResult.value; + } handleCamToken( event.transaction.hash, event.block.number, event.block.timestamp, event.address, - value, - camType, reserveAddress, + amTokenAddress, + decimals, + symbol, + totalLiquidity, ); } diff --git a/src/Mai/mappings/handlers.ts b/src/Mai/mappings/handlers.ts index 302b46f..a23f76e 100644 --- a/src/Mai/mappings/handlers.ts +++ b/src/Mai/mappings/handlers.ts @@ -1,142 +1,85 @@ import { Address, BigInt, Bytes, log } from "@graphprotocol/graph-ts"; -import { MaiCamTokenData, MaiAmTokenData } from "../../../generated/schema"; -import { MaiCamToken } from "../../../generated/MaiCamTokencamUSDC/MaiCamToken"; +import { MaiCamTokenData } from "../../../generated/schema"; import { MaiAToken } from "../../../generated/MaiCamAavecamAAVE/MaiAToken"; import { MaiLendingPool } from "../../../generated/MaiCamAavecamAAVE/MaiLendingPool"; import { convertBINumToDesiredDecimals, toAddress } from "../../utils/converters"; -import { MaiIncentivesController } from "../../../generated/MaiCamWMaticcamWMATIC/MaiIncentivesController"; -import { ZERO_BI } from "../../utils/constants"; -// TODO: Mapping for the reserve address -// get balance of the amToken so I don't use a state entity +import { MaiIncentivesController } from "../../../generated/MaiCamTokencamUSDC/MaiIncentivesController"; +import { ZERO_BD, ZERO_BI } from "../../utils/constants"; + let CAM_INCENTIVES_CONTROLLER_ADDRESS: Address = toAddress("0x357D51124f59836DeD84c8a1730D72B749d8BC23"); let CAM_LENDING_POOL_ADDRESS: Address = toAddress("0x8dFf5E27EA6b7AC08EbFdf9eB090F32ee9a30fcf"); +// Rates: https://docs.aave.com/developers/guides/apy-and-apr +let DECIMALS: i32 = 27; export function handleCamToken( txnHash: Bytes, blockNumber: BigInt, timestamp: BigInt, camTokenAddress: Address, - value: BigInt, - camType: string, reserveAddress: Address, + amTokenAddress: Address, + decimals: i32, + symbol: string, + totalLiquidity: BigInt, ): void { - let entity = MaiCamTokenData.load(txnHash.toHex()); - if (!entity) entity = new MaiCamTokenData(txnHash.toHex()); - entity.blockNumber = blockNumber; - entity.blockTimestamp = timestamp; - let balanceOfCam = ZERO_BI; - - // lending pool is the same for camToken, camAave and camWMatic - let camContract = MaiCamToken.bind(camTokenAddress); + let aTvl = ZERO_BI; + let aEmissionPerSecond = ZERO_BI; + let liquidityRate = ZERO_BD; + let liquidityIndex = ZERO_BD; + let stableBorrowRate = ZERO_BD; + let variableBorrowIndex = ZERO_BD; + let variableBorrowRate = ZERO_BD; - // updating entity symbol - let symbolResult = camContract.try_symbol(); - if (symbolResult.reverted) { - log.warning("totalSupply() reverted", []); + let amATokenContract = MaiAToken.bind(amTokenAddress); + let amBalanceResult = amATokenContract.try_balanceOf(camTokenAddress); + if (amBalanceResult.reverted) { + log.warning("try_balanceOf(camAddress) reverted", []); } else { - entity.symbol = symbolResult.value; + aTvl = amBalanceResult.value; } - // updating entity decimals - let decimalsResult = camContract.try_decimals(); - if (decimalsResult.reverted) { - log.warning("try_decimals() reverted", []); + let incentivesControllerContract = MaiIncentivesController.bind(CAM_INCENTIVES_CONTROLLER_ADDRESS); + let assetsResult = incentivesControllerContract.try_assets(amTokenAddress); + if (assetsResult.reverted) { + log.error("AaveincentivesControler at {} call assets({}) reverted", [ + incentivesControllerContract._address.toHex(), + camTokenAddress.toHex(), + ]); } else { - entity.decimals = decimalsResult.value; + let assets = assetsResult.value; + // https://docs.aave.com/developers/guides/apy-and-apr + aEmissionPerSecond = assets.value0; //emissionPerSecond, expressed in WEI } - // finding amToken info and updating amToken - let amContractResult = camContract.try_Token(); - if (amContractResult.reverted) { - log.error("try_Token() reverted", []); + let lendingPoolContract = MaiLendingPool.bind(CAM_LENDING_POOL_ADDRESS); + let camTokenReserveDataResult = lendingPoolContract.try_getReserveData(reserveAddress); + if (camTokenReserveDataResult.reverted) { + log.error("try_getReserveData() reverted", []); } else { - let amContract = amContractResult.value; - let amATokenContract = MaiAToken.bind(amContract); - let amTokenId = amContract.toHexString(); - - let amToken = MaiAmTokenData.load(amTokenId); - if (!amToken) { - amToken = new MaiAmTokenData(amTokenId); - amToken.symbol = entity.symbol; - amToken.totalLiquidity = BigInt.fromI32(0); - amToken.decimals = 0; - } - amToken.blockNumber = blockNumber; - amToken.blockTimestamp = timestamp; - - let amBalanceResult = amATokenContract.try_balanceOf(camTokenAddress); - if (amBalanceResult.reverted) { - } else { - balanceOfCam = amBalanceResult.value; - } - - let aTokenDecimalsResult = amATokenContract.try_decimals(); - if (aTokenDecimalsResult.reverted) { - log.warning("aToken.try_decimals() reverted", []); - } else { - amToken.decimals = aTokenDecimalsResult.value; - } - amToken.totalLiquidity = amToken.totalLiquidity.plus(value); - amToken.save(); - - // get emissions per second through the amToken incentives controller - let incentivesControllerResult = camContract.try_AaveContract(); - if (incentivesControllerResult.reverted) { - log.error("tokenContract at {} call getAaveContract() reverted", [camContract._address.toHex()]); - } else { - let incentivesControllerAddress = incentivesControllerResult.value; - let incentivesControllerContract = MaiIncentivesController.bind(incentivesControllerAddress); - - let assetsResult = incentivesControllerContract.try_assets(amContract); - - if (assetsResult.reverted) { - log.error("AaveincentivesControler at {} call assets({}) reverted", [ - incentivesControllerContract._address.toHex(), - camContract._address.toHex(), - ]); - } else { - let assets = assetsResult.value; - // https://docs.aave.com/developers/guides/apy-and-apr - // - entity.aEmissionPerSecond = assets.value0; //emissionPerSecond, expressed in WEI - } - } - - entity.aTvl = convertBINumToDesiredDecimals(balanceOfCam, entity.decimals); - // get camToken info through it's lending controller - let lendingControllerResult = camContract.try_LENDING_POOL(); - if (lendingControllerResult.reverted) { - log.error("try_LENDING_POOL() reverted", []); - } else { - let lendingControllerAddress = lendingControllerResult.value; - let lendingPoolContract = MaiLendingPool.bind(lendingControllerAddress); - let camTokenReserveDataResult = lendingPoolContract.try_getReserveData(reserveAddress); - if (camTokenReserveDataResult.reverted) { - log.error("try_getReserveData() reverted", []); - } else { - let camTokenConfiguration = camTokenReserveDataResult.value; - let aTokenAddress = camTokenConfiguration.aTokenAddress; - - let liquidityRate = camTokenConfiguration.currentLiquidityRate; - let stableBorrowRate = camTokenConfiguration.currentStableBorrowRate; - let variableBorrowRate = camTokenConfiguration.currentVariableBorrowRate; - let liquidityIndex = camTokenConfiguration.liquidityIndex; - let variableBorrowIndex = camTokenConfiguration.variableBorrowIndex; - entity.aTokenAddress = aTokenAddress; - // https://docs.aave.com/developers/guides/apy-and-apr - // Rates - entity.liquidityRate = convertBINumToDesiredDecimals(liquidityRate, 27); - entity.stableBorrowRate = convertBINumToDesiredDecimals(stableBorrowRate, 27); - entity.variableBorrowRate = convertBINumToDesiredDecimals(variableBorrowRate, 27); - entity.liquidityIndex = convertBINumToDesiredDecimals(liquidityIndex, 27); - entity.variableBorrowRate = convertBINumToDesiredDecimals(variableBorrowIndex, 27); - } - } - } - let camTokenTotalLiquidityResult = camContract.try_totalSupply(); - if (camTokenTotalLiquidityResult.reverted) { - log.warning("totalSupply() reverted", []); - } else { - entity.totalLiquidity = camTokenTotalLiquidityResult.value; + let camTokenConfiguration = camTokenReserveDataResult.value; + liquidityIndex = convertBINumToDesiredDecimals(camTokenConfiguration.liquidityIndex, DECIMALS); + liquidityRate = convertBINumToDesiredDecimals(camTokenConfiguration.currentLiquidityRate, DECIMALS); + stableBorrowRate = convertBINumToDesiredDecimals(camTokenConfiguration.currentStableBorrowRate, DECIMALS); + variableBorrowIndex = convertBINumToDesiredDecimals(camTokenConfiguration.variableBorrowIndex, DECIMALS); + variableBorrowRate = convertBINumToDesiredDecimals(camTokenConfiguration.currentVariableBorrowRate, DECIMALS); } + // handling the entity + let entity = MaiCamTokenData.load(txnHash.toHex()); + if (!entity) entity = new MaiCamTokenData(txnHash.toHex()); + entity.blockNumber = blockNumber; + entity.blockTimestamp = timestamp; + entity.address = camTokenAddress; + entity.aTvl = aTvl; + entity.symbol = symbol; + entity.decimals = decimals; + entity.totalLiquidity = totalLiquidity; + entity.aEmissionPerSecond = aEmissionPerSecond; + entity.aTokenAddress = amTokenAddress; + entity.liquidityIndex = liquidityIndex; + entity.liquidityRate = liquidityRate; + entity.stableBorrowRate = stableBorrowRate; + entity.variableBorrowIndex = variableBorrowIndex; + entity.variableBorrowRate = variableBorrowRate; + entity.save(); + // end handling } diff --git a/src/Mai/schema.graphql b/src/Mai/schema.graphql index 9a5081c..ee3a6fb 100644 --- a/src/Mai/schema.graphql +++ b/src/Mai/schema.graphql @@ -2,29 +2,22 @@ # Mai Finance # ---------------------------------------- type MaiCamTokenData @entity { - id: ID! #camToken address + id: ID! blockNumber: BigInt! blockTimestamp: BigInt! - aTvl: BigDecimal! - decimals: Int - symbol: String - totalLiquidity: BigInt + aTokenAddress: Bytes! + aTvl: BigInt! + decimals: Int! + symbol: String! + totalLiquidity: BigInt! aEmissionPerSecond: BigInt - txHash: Bytes - aTokenAddress: Bytes + address: Bytes! #camToken address + + liquidityIndex: BigDecimal liquidityRate: BigDecimal stableBorrowRate: BigDecimal - variableBorrowRate: BigDecimal - liquidityIndex: BigDecimal - -} - -type MaiAmTokenData @entity { - id: ID! - blockNumber: BigInt - blockTimestamp: BigInt - symbol: String - totalLiquidity: BigInt! - decimals: Int + variableBorrowIndex: BigDecimal + variableBorrowRate: BigDecimal } + From 410e4b5535f316152b618cb4850f73abfc7218a5 Mon Sep 17 00:00:00 2001 From: michelet Date: Sat, 22 Jan 2022 23:20:39 -0300 Subject: [PATCH 14/24] Removing 'value' variable, updating constants. --- src/Mai/mappings/CamAave.ts | 6 ------ src/Mai/mappings/CamToken.ts | 5 ----- src/Mai/mappings/CamWMatic.ts | 5 ----- src/Mai/mappings/handlers.ts | 9 +++------ src/utils/constants.ts | 3 +++ 5 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/Mai/mappings/CamAave.ts b/src/Mai/mappings/CamAave.ts index 19c26c7..ec29180 100644 --- a/src/Mai/mappings/CamAave.ts +++ b/src/Mai/mappings/CamAave.ts @@ -9,17 +9,11 @@ import { MaiCamAave } from "../../../generated/MaiCamAavecamAAVE/MaiCamAave"; export function handleTransfer(event: TransferEvent): void { let from = event.params.from; let to = event.params.to; - let value = event.params.value; - // only interested on mints and burns. if (from != ZERO_ADDRESS && to != ZERO_ADDRESS) { return; } - if (to == ZERO_ADDRESS) { - // burn - value = value.neg(); - } let camContract = MaiCamAave.bind(event.address); let reserveAddress = ZERO_ADDRESS; let reserveResult = camContract.try_aave(); diff --git a/src/Mai/mappings/CamToken.ts b/src/Mai/mappings/CamToken.ts index 4db0538..3c8bf86 100644 --- a/src/Mai/mappings/CamToken.ts +++ b/src/Mai/mappings/CamToken.ts @@ -7,17 +7,12 @@ import { handleCamToken } from "./handlers"; export function handleTransfer(event: TransferEvent): void { let from = event.params.from; let to = event.params.to; - let value = event.params.value; // only interested on mints and burns. if (from != ZERO_ADDRESS && to != ZERO_ADDRESS) { return; } - if (to == ZERO_ADDRESS) { - // burn - value = value.neg(); - } let camContract = MaiCamToken.bind(event.address); let reserveAddress = ZERO_ADDRESS; let reserveResult = camContract.try_usdc(); diff --git a/src/Mai/mappings/CamWMatic.ts b/src/Mai/mappings/CamWMatic.ts index f898e33..b192118 100644 --- a/src/Mai/mappings/CamWMatic.ts +++ b/src/Mai/mappings/CamWMatic.ts @@ -8,17 +8,12 @@ import { handleCamToken } from "./handlers"; export function handleTransfer(event: TransferEvent): void { let from = event.params.from; let to = event.params.to; - let value = event.params.value; // only interested on mints and burns. if (from != ZERO_ADDRESS && to != ZERO_ADDRESS) { return; } - if (to == ZERO_ADDRESS) { - // burn - value = value.neg(); - } let camContract = MaiCamWMATIC.bind(event.address); let reserveAddress = ZERO_ADDRESS; let reserveResult = camContract.try_wMatic(); diff --git a/src/Mai/mappings/handlers.ts b/src/Mai/mappings/handlers.ts index a23f76e..1571f9e 100644 --- a/src/Mai/mappings/handlers.ts +++ b/src/Mai/mappings/handlers.ts @@ -5,12 +5,7 @@ import { MaiLendingPool } from "../../../generated/MaiCamAavecamAAVE/MaiLendingP import { convertBINumToDesiredDecimals, toAddress } from "../../utils/converters"; import { MaiIncentivesController } from "../../../generated/MaiCamTokencamUSDC/MaiIncentivesController"; -import { ZERO_BD, ZERO_BI } from "../../utils/constants"; - -let CAM_INCENTIVES_CONTROLLER_ADDRESS: Address = toAddress("0x357D51124f59836DeD84c8a1730D72B749d8BC23"); -let CAM_LENDING_POOL_ADDRESS: Address = toAddress("0x8dFf5E27EA6b7AC08EbFdf9eB090F32ee9a30fcf"); -// Rates: https://docs.aave.com/developers/guides/apy-and-apr -let DECIMALS: i32 = 27; +import { ZERO_BD, ZERO_BI, CAM_INCENTIVES_CONTROLLER_ADDRESS, CAM_LENDING_POOL_ADDRESS } from "../../utils/constants"; export function handleCamToken( txnHash: Bytes, @@ -56,6 +51,8 @@ export function handleCamToken( log.error("try_getReserveData() reverted", []); } else { let camTokenConfiguration = camTokenReserveDataResult.value; + // Rates: https://docs.aave.com/developers/guides/apy-and-apr + let DECIMALS: i32 = 27; liquidityIndex = convertBINumToDesiredDecimals(camTokenConfiguration.liquidityIndex, DECIMALS); liquidityRate = convertBINumToDesiredDecimals(camTokenConfiguration.currentLiquidityRate, DECIMALS); stableBorrowRate = convertBINumToDesiredDecimals(camTokenConfiguration.currentStableBorrowRate, DECIMALS); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index d5d23d4..caa1450 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -38,3 +38,6 @@ export let LidoNodeOperatorsRegistryAddress: Address = toAddress("0x55032650b14d export let LidoTreasuryAddress: Address = toAddress("0x4333218072D5d7008546737786663c38B4D561A4"); export let SushiMiniChefAddress = toAddress("0x0769fd68dFb93167989C6f7254cd0D766Fb2841F"); + +export let CAM_INCENTIVES_CONTROLLER_ADDRESS: Address = toAddress("0x357D51124f59836DeD84c8a1730D72B749d8BC23"); +export let CAM_LENDING_POOL_ADDRESS: Address = toAddress("0x8dFf5E27EA6b7AC08EbFdf9eB090F32ee9a30fcf"); From 6aa0c495be8b0b9e5f6c28ec39e3db2db598d649 Mon Sep 17 00:00:00 2001 From: michelet Date: Fri, 25 Mar 2022 15:55:23 -0300 Subject: [PATCH 15/24] WIP: Pangolin swap data. --- .idea/vcs.xml | 6 + .idea/workspace.xml | 74 ++++++ src/Pangolin/abis/ERC20.json | 222 +++++++++++++++++ src/Pangolin/abis/Factory.json | 97 ++++++++ src/Pangolin/abis/Pair.json | 345 ++++++++++++++++++++++++++ src/Pangolin/abis/StakingRewards.json | 240 ++++++++++++++++++ src/Pangolin/config/avalanche.json | 37 +++ src/Pangolin/mappings/Factory.ts | 8 + src/Pangolin/mappings/Pair.ts | 85 +++++++ src/Pangolin/schema.graphql | 45 ++++ src/utils/constants.ts | 2 + subgraph.template.yaml | 27 ++ 12 files changed, 1188 insertions(+) create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 src/Pangolin/abis/ERC20.json create mode 100644 src/Pangolin/abis/Factory.json create mode 100644 src/Pangolin/abis/Pair.json create mode 100644 src/Pangolin/abis/StakingRewards.json create mode 100644 src/Pangolin/config/avalanche.json create mode 100644 src/Pangolin/mappings/Factory.ts create mode 100644 src/Pangolin/mappings/Pair.ts create mode 100644 src/Pangolin/schema.graphql diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..f2a7f5a --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + 1648131623706 + + + + + + + + + \ No newline at end of file diff --git a/src/Pangolin/abis/ERC20.json b/src/Pangolin/abis/ERC20.json new file mode 100644 index 0000000..405d6b3 --- /dev/null +++ b/src/Pangolin/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/src/Pangolin/abis/Factory.json b/src/Pangolin/abis/Factory.json new file mode 100644 index 0000000..792261a --- /dev/null +++ b/src/Pangolin/abis/Factory.json @@ -0,0 +1,97 @@ +[ + { + "inputs": [{ "internalType": "address", "name": "_feeToSetter", "type": "address" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "token0", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "token1", "type": "address" }, + { "indexed": false, "internalType": "address", "name": "pair", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "", "type": "uint256" } + ], + "name": "PairCreated", + "type": "event" + }, + { + "constant": true, + "inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "name": "allPairs", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "allPairsLength", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "tokenA", "type": "address" }, + { "internalType": "address", "name": "tokenB", "type": "address" } + ], + "name": "createPair", + "outputs": [{ "internalType": "address", "name": "pair", "type": "address" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "feeTo", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "feeToSetter", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { "internalType": "address", "name": "", "type": "address" }, + { "internalType": "address", "name": "", "type": "address" } + ], + "name": "getPair", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "address", "name": "_feeTo", "type": "address" }], + "name": "setFeeTo", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "address", "name": "_feeToSetter", "type": "address" }], + "name": "setFeeToSetter", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/src/Pangolin/abis/Pair.json b/src/Pangolin/abis/Pair.json new file mode 100644 index 0000000..809791b --- /dev/null +++ b/src/Pangolin/abis/Pair.json @@ -0,0 +1,345 @@ +[ + { "inputs": [], "payable": false, "stateMutability": "nonpayable", "type": "constructor" }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "spender", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "sender", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount0", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "amount1", "type": "uint256" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" } + ], + "name": "Burn", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "sender", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount0", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "amount1", "type": "uint256" } + ], + "name": "Mint", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "sender", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount0In", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "amount1In", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "amount0Out", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "amount1Out", "type": "uint256" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" } + ], + "name": "Swap", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "uint112", "name": "reserve0", "type": "uint112" }, + { "indexed": false, "internalType": "uint112", "name": "reserve1", "type": "uint112" } + ], + "name": "Sync", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "from", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "Transfer", + "type": "event" + }, + { + "constant": true, + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MINIMUM_LIQUIDITY", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "PERMIT_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { "internalType": "address", "name": "", "type": "address" }, + { "internalType": "address", "name": "", "type": "address" } + ], + "name": "allowance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "approve", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "address", "name": "to", "type": "address" }], + "name": "burn", + "outputs": [ + { "internalType": "uint256", "name": "amount0", "type": "uint256" }, + { "internalType": "uint256", "name": "amount1", "type": "uint256" } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "factory", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getReserves", + "outputs": [ + { "internalType": "uint112", "name": "_reserve0", "type": "uint112" }, + { "internalType": "uint112", "name": "_reserve1", "type": "uint112" }, + { "internalType": "uint32", "name": "_blockTimestampLast", "type": "uint32" } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "_token0", "type": "address" }, + { "internalType": "address", "name": "_token1", "type": "address" } + ], + "name": "initialize", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "kLast", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "address", "name": "to", "type": "address" }], + "name": "mint", + "outputs": [{ "internalType": "uint256", "name": "liquidity", "type": "uint256" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "nonces", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "value", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "permit", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "price0CumulativeLast", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "price1CumulativeLast", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "address", "name": "to", "type": "address" }], + "name": "skim", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "uint256", "name": "amount0Out", "type": "uint256" }, + { "internalType": "uint256", "name": "amount1Out", "type": "uint256" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "bytes", "name": "data", "type": "bytes" } + ], + "name": "swap", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "sync", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "token0", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "token1", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "transfer", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/src/Pangolin/abis/StakingRewards.json b/src/Pangolin/abis/StakingRewards.json new file mode 100644 index 0000000..9ebb02a --- /dev/null +++ b/src/Pangolin/abis/StakingRewards.json @@ -0,0 +1,240 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "_rewardsToken", "type": "address" }, + { "internalType": "address", "name": "_stakingToken", "type": "address" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "address", "name": "token", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "Recovered", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "uint256", "name": "reward", "type": "uint256" }], + "name": "RewardAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "reward", "type": "uint256" } + ], + "name": "RewardPaid", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "uint256", "name": "newDuration", "type": "uint256" }], + "name": "RewardsDurationUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "Staked", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "Withdrawn", + "type": "event" + }, + { + "inputs": [{ "internalType": "address", "name": "account", "type": "address" }], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "account", "type": "address" }], + "name": "earned", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { "inputs": [], "name": "exit", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { "inputs": [], "name": "getReward", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "getRewardForDuration", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "lastTimeRewardApplicable", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "lastUpdateTime", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "reward", "type": "uint256" }], + "name": "notifyRewardAmount", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "periodFinish", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "tokenAddress", "type": "address" }, + { "internalType": "uint256", "name": "tokenAmount", "type": "uint256" } + ], + "name": "recoverERC20", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { "inputs": [], "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "rewardPerToken", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "rewardPerTokenStored", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "rewardRate", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "rewards", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "rewardsDuration", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "rewardsToken", + "outputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "_rewardsDuration", "type": "uint256" }], + "name": "setRewardsDuration", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "amount", "type": "uint256" }], + "name": "stake", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "amount", "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": "stakeWithPermit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "stakingToken", + "outputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "userRewardPerTokenPaid", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "amount", "type": "uint256" }], + "name": "withdraw", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/src/Pangolin/config/avalanche.json b/src/Pangolin/config/avalanche.json new file mode 100644 index 0000000..c07dff0 --- /dev/null +++ b/src/Pangolin/config/avalanche.json @@ -0,0 +1,37 @@ +{ + "network": "avalanche", + "adapter": "Pangolin", + "contracts": [ + { + "contract": "Factory", + "abis": ["Factory", "Pair"], + "entities": ["PangolinSwapPair"], + "events": [ + { + "event-name": "PairCreated", + "event-params": "(indexed address,indexed address,address,uint256)" + } + ], + "instances": [ + { + "symbol": "", + "address": "0xefa94DE7a4656D787667C749f7E1223D71E9FD88", + "startBlock": 56877 + } + ] + } + ], + "templates": [ + { + "name": "Pair", + "abis": ["Pair", "Factory", "ERC20"], + "entities": ["PangolinSwapData"], + "events": [ + { + "event-name": "Swap", + "event-params": "(indexed address,uint256,uint256,uint256,uint256,indexed address)" + } + ] + } + ] +} diff --git a/src/Pangolin/mappings/Factory.ts b/src/Pangolin/mappings/Factory.ts new file mode 100644 index 0000000..99464ca --- /dev/null +++ b/src/Pangolin/mappings/Factory.ts @@ -0,0 +1,8 @@ +import { log } from "@graphprotocol/graph-ts"; +import { PangolinPair as PairTemplate } from "../../../generated/templates"; +import { PairCreated as PairCreatedEvent } from "../../../generated/PangolinFactory/PangolinFactory"; + +export function handlePairCreated(event: PairCreatedEvent): void { + log.info("handling create pool. pair: {}", [event.params.pair.toHex()]); + PairTemplate.create(event.params.pair); +} diff --git a/src/Pangolin/mappings/Pair.ts b/src/Pangolin/mappings/Pair.ts new file mode 100644 index 0000000..d747a76 --- /dev/null +++ b/src/Pangolin/mappings/Pair.ts @@ -0,0 +1,85 @@ +import { Swap as SwapEvent } from "../../../generated/templates/PangolinPair/PangolinPair"; +import { Address, BigInt, log } from "@graphprotocol/graph-ts"; +import { PangolinSwapData, PangolinSwapPair } from "../../../generated/schema"; +import { PangolinPair as PairContract } from "../../../generated/templates/PangolinPair/PangolinPair"; +import { PangolinERC20 as ERC20Contract } from "../../../generated/templates/PangolinPair/PangolinERC20"; + +import { convertBINumToDesiredDecimals } from "../../utils/converters"; + +export function handleSwap(event: SwapEvent): void { + let entity = PangolinSwapData.load(event.transaction.hash.toHex()); + if (!entity) entity = new PangolinSwapData(event.transaction.hash.toHex()); + + entity.blockNumber = event.block.number; + entity.blockTimestamp = event.block.timestamp; + let pair = getPair(event.address); + + let token0In = convertBINumToDesiredDecimals(event.params.amount0In, pair.token0Decimals.toI32()); + let token1In = convertBINumToDesiredDecimals(event.params.amount1In, pair.token1Decimals.toI32()); + let token0Out = convertBINumToDesiredDecimals(event.params.amount0Out, pair.token0Decimals.toI32()); + let token1Out = convertBINumToDesiredDecimals(event.params.amount1Out, pair.token1Decimals.toI32()); + + // calculate volumes + entity.token0Vol = token0Out.plus(token0In); + entity.token1Vol = token1Out.plus(token1In); + + entity.pair = pair.id; + entity.save(); +} + +export function getPair(address: Address): PangolinSwapPair | null { + let pair = PangolinSwapPair.load(address.toHex()); + + if (pair === null) { + let pairContract = PairContract.bind(address); + pair = new PangolinSwapPair(address.toHex()); + + let token0AddresResult = pairContract.try_token0(); + if (token0AddresResult.reverted) { + log.warning("try_token0() reverted", []); + return null; + } else { + pair.token0Address = token0AddresResult.value; + pair = updatePairTokens(pair as PangolinSwapPair, token0AddresResult.value, null); + } + let token1AddresResult = pairContract.try_token1(); + if (token1AddresResult.reverted) { + log.warning("try_token1() reverted", []); + return null; + } else { + pair.token1Address = token1AddresResult.value; + pair = updatePairTokens(pair as PangolinSwapPair, null, token1AddresResult.value); + } + pair.name = pair.token0Symbol.concat("-").concat(pair.token1Symbol); + + pair.save(); + } + + return pair as PangolinSwapPair; +} +function updatePairTokens(pair: PangolinSwapPair, token0: Address, token1: Address): PangolinSwapPair { + let tokenAddress = token0 == null ? token1 : token0; + + let tokenContract = ERC20Contract.bind(tokenAddress); + let tokenSymbolResult = tokenContract.try_symbol(); + if (tokenSymbolResult.reverted) { + log.warning("try_symbol() {} reverted", [tokenAddress.toHex()]); + } else { + if (token0 != null) { + pair.token0Symbol = tokenSymbolResult.value; + } else { + pair.token1Symbol = tokenSymbolResult.value; + } + } + let tokenDecimalsResult = tokenContract.try_decimals(); + if (tokenDecimalsResult.reverted) { + log.warning("try_symbol() token0 reverted", []); + } else { + if (token0 != null) { + pair.token0Decimals = BigInt.fromI32(tokenDecimalsResult.value); + } else { + pair.token1Decimals = BigInt.fromI32(tokenDecimalsResult.value); + } + } + return pair; +} diff --git a/src/Pangolin/schema.graphql b/src/Pangolin/schema.graphql new file mode 100644 index 0000000..dde69a1 --- /dev/null +++ b/src/Pangolin/schema.graphql @@ -0,0 +1,45 @@ +type PangolinFarmData @entity { + id: ID! + blockNumber: BigInt! + blockTimestamp: BigInt! + lpToken: Bytes! + poolId: BigInt! + version: String + accJoePerShare: BigDecimal + joePerSecond: BigDecimal + rewardToken: Bytes + rewarder: Bytes! + rewardPerSecond: BigDecimal + lastRewardTime: BigInt + event: String +} +type PangolinStakingData @entity { + id: ID! + blockNumber: BigInt! + blockTimestamp: BigInt! + xJoeSupply: BigDecimal + totalStakedPNG: BigDecimal + # Total Joe staked in USDT + tvlInUSDT: BigDecimal + # Mint or Burn + event: String +} +type PangolinSwapData @entity { + id: ID! + blockNumber: BigInt! + blockTimestamp: BigInt! + pair: PangolinSwapPair + token0Vol: BigDecimal + token1Vol: BigDecimal +} +type PangolinSwapPair @entity { + id: ID! # pool address + name: String! + token0Address: Bytes! + token1Address: Bytes! + token0Decimals: BigInt! + token1Decimals: BigInt! + token0Symbol: String! + token1Symbol: String! + +} \ No newline at end of file diff --git a/src/utils/constants.ts b/src/utils/constants.ts index caa1450..e7f916c 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -41,3 +41,5 @@ export let SushiMiniChefAddress = toAddress("0x0769fd68dFb93167989C6f7254cd0D766 export let CAM_INCENTIVES_CONTROLLER_ADDRESS: Address = toAddress("0x357D51124f59836DeD84c8a1730D72B749d8BC23"); export let CAM_LENDING_POOL_ADDRESS: Address = toAddress("0x8dFf5E27EA6b7AC08EbFdf9eB090F32ee9a30fcf"); + +export let PANGOLIN_FACTORY_ADDRESS: Address = toAddress("0xefa94DE7a4656D787667C749f7E1223D71E9FD88"); diff --git a/subgraph.template.yaml b/subgraph.template.yaml index 6528744..78107cf 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -39,3 +39,30 @@ dataSources: file: ./src/{{adapter}}/mappings/{{contract}}.ts {{/instances}} {{/contracts}} +{{#templates}} +templates: + - kind: ethereum/contract + name: {{adapter}}{{name}} + network: {{network}} + source: + abi: {{adapter}}{{name}} + mapping: + kind: ethereum/events + apiVersion: 0.0.4 + language: wasm/assemblyscript + file: ./src/{{adapter}}/mappings/{{name}}.ts + entities: + {{#entities}} + - {{.}} + {{/entities}} + abis: + {{#abis}} + - name: {{adapter}}{{.}} + file: ./src/{{adapter}}/abis/{{.}}.json + {{/abis}} + eventHandlers: + {{#events}} + - event: {{event-name}}{{event-params}} + handler: handle{{event-name}} + {{/events}} +{{/templates}} \ No newline at end of file From b5dd0af420239a9cfea415bf14f36e345c27c6c7 Mon Sep 17 00:00:00 2001 From: michelet Date: Fri, 25 Mar 2022 18:55:59 -0300 Subject: [PATCH 16/24] WIP: adding staking info, removing swap config. --- src/Pangolin/abis/PngToken.json | 274 +++++++++++++++++++ src/Pangolin/config/avalanche.json | 31 +-- src/Pangolin/mappings/StakingRewards.ts | 18 ++ src/Pangolin/mappings/handleStakingEntity.ts | 57 ++++ src/Pangolin/schema.graphql | 8 +- src/utils/constants.ts | 2 + 6 files changed, 365 insertions(+), 25 deletions(-) create mode 100644 src/Pangolin/abis/PngToken.json create mode 100644 src/Pangolin/mappings/StakingRewards.ts create mode 100644 src/Pangolin/mappings/handleStakingEntity.ts diff --git a/src/Pangolin/abis/PngToken.json b/src/Pangolin/abis/PngToken.json new file mode 100644 index 0000000..b309ff2 --- /dev/null +++ b/src/Pangolin/abis/PngToken.json @@ -0,0 +1,274 @@ +[ + { + "inputs": [{ "internalType": "address", "name": "account", "type": "address" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "spender", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "delegator", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "fromDelegate", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "toDelegate", "type": "address" } + ], + "name": "DelegateChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "delegate", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "previousBalance", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "newBalance", "type": "uint256" } + ], + "name": "DelegateVotesChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "from", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "Transfer", + "type": "event" + }, + { + "constant": true, + "inputs": [], + "name": "DELEGATION_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "DOMAIN_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "PERMIT_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" } + ], + "name": "allowance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "rawAmount", "type": "uint256" } + ], + "name": "approve", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "internalType": "address", "name": "account", "type": "address" }], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { "internalType": "address", "name": "", "type": "address" }, + { "internalType": "uint32", "name": "", "type": "uint32" } + ], + "name": "checkpoints", + "outputs": [ + { "internalType": "uint32", "name": "fromBlock", "type": "uint32" }, + { "internalType": "uint96", "name": "votes", "type": "uint96" } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "internalType": "address", "name": "delegatee", "type": "address" }], + "name": "delegate", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "delegatee", "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": "delegateBySig", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "delegates", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "internalType": "address", "name": "account", "type": "address" }], + "name": "getCurrentVotes", + "outputs": [{ "internalType": "uint96", "name": "", "type": "uint96" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" }, + { "internalType": "uint256", "name": "blockNumber", "type": "uint256" } + ], + "name": "getPriorVotes", + "outputs": [{ "internalType": "uint96", "name": "", "type": "uint96" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "nonces", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "numCheckpoints", + "outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "rawAmount", "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": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "dst", "type": "address" }, + { "internalType": "uint256", "name": "rawAmount", "type": "uint256" } + ], + "name": "transfer", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "src", "type": "address" }, + { "internalType": "address", "name": "dst", "type": "address" }, + { "internalType": "uint256", "name": "rawAmount", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/src/Pangolin/config/avalanche.json b/src/Pangolin/config/avalanche.json index c07dff0..25dad81 100644 --- a/src/Pangolin/config/avalanche.json +++ b/src/Pangolin/config/avalanche.json @@ -3,33 +3,24 @@ "adapter": "Pangolin", "contracts": [ { - "contract": "Factory", - "abis": ["Factory", "Pair"], - "entities": ["PangolinSwapPair"], + "contract": "StakingRewards", + "abis": ["StakingRewards", "Pair", "PngToken"], + "entities": ["PangolinStakingData"], "events": [ { - "event-name": "PairCreated", - "event-params": "(indexed address,indexed address,address,uint256)" + "event-name": "Staked", + "event-params": "(indexed address,uint256)" + }, + { + "event-name": "Withdrawn", + "event-params": "(indexed address,uint256)" } ], "instances": [ { "symbol": "", - "address": "0xefa94DE7a4656D787667C749f7E1223D71E9FD88", - "startBlock": 56877 - } - ] - } - ], - "templates": [ - { - "name": "Pair", - "abis": ["Pair", "Factory", "ERC20"], - "entities": ["PangolinSwapData"], - "events": [ - { - "event-name": "Swap", - "event-params": "(indexed address,uint256,uint256,uint256,uint256,indexed address)" + "address": "0x88afdaE1a9F58Da3E68584421937E5F564A0135b", + "startBlock": 7689920 } ] } diff --git a/src/Pangolin/mappings/StakingRewards.ts b/src/Pangolin/mappings/StakingRewards.ts new file mode 100644 index 0000000..f2672ed --- /dev/null +++ b/src/Pangolin/mappings/StakingRewards.ts @@ -0,0 +1,18 @@ +import { + Staked as StakeEvent, + Withdrawn as WithdrawnEvent, +} from "../../../generated/PangolinStakingRewards/PangolinStakingRewards"; +import { handleStakingEntity } from "./handleStakingEntity"; + +export function handleStaked(event: StakeEvent): void { + handleStakingEntity(event.transaction.hash, event.block.number, event.block.timestamp, "Stake", event.params.amount); +} +export function handleWithdrawn(event: WithdrawnEvent): void { + handleStakingEntity( + event.transaction.hash, + event.block.number, + event.block.timestamp, + "Withdraw", + event.params.amount, + ); +} diff --git a/src/Pangolin/mappings/handleStakingEntity.ts b/src/Pangolin/mappings/handleStakingEntity.ts new file mode 100644 index 0000000..54a89d6 --- /dev/null +++ b/src/Pangolin/mappings/handleStakingEntity.ts @@ -0,0 +1,57 @@ +import { Address, BigInt, Bytes, log } from "@graphprotocol/graph-ts"; +import { PangolinStakingData } from "../../../generated/schema"; + +// Is the same abi for both versions +import { PangolinStakingRewards as StakingRewardContract } from "../../../generated/PangolinStakingRewards/PangolinStakingRewards"; +import { PangolinPngToken as PngTokenContract } from "../../../generated/PangolinStakingRewards/PangolinPngToken"; +import { convertBINumToDesiredDecimals, convertBytesToAddress } from "../../utils/converters"; +import { + PANGOLIN_STAKING_REWARDS_ADDRESS, + PANGOLIN_PNG_TOKEN_ADDRESS, + ZERO_ADDRESS, + ZERO_BD, + ZERO_BI, +} from "../../utils/constants"; + +export function handleStakingEntity( + txHash: Bytes, + blockNumber: BigInt, + timestamp: BigInt, + eventType: string, + amount: BigInt, +): void { + let entity = PangolinStakingData.load(txHash.toHex()); + if (!entity) entity = new PangolinStakingData(txHash.toHex()); + entity.blockNumber = blockNumber; + entity.blockTimestamp = timestamp; + entity.event = eventType; + + // instantiate contracts + let stakingContract = StakingRewardContract.bind(PANGOLIN_STAKING_REWARDS_ADDRESS); + let pngTokenContract = PngTokenContract.bind(PANGOLIN_PNG_TOKEN_ADDRESS); + + let totalSupplyResult = stakingContract.try_totalSupply(); + if (totalSupplyResult.reverted) { + log.warning("try_totalSupply()", []); + } else { + entity.totalSupply = convertBINumToDesiredDecimals(totalSupplyResult.value, 18); + } + // let rewardPerTokenResult = stakingContract.try_rewardPerToken(); + let rewardRateResult = stakingContract.try_rewardRate(); + if (rewardRateResult.reverted) { + log.warning("try_rewardRate", []); + } else { + entity.rewardRate = convertBINumToDesiredDecimals(rewardRateResult.value, 18); + } + // let stakingTokenAddressResult = stakingContract.try_stakingToken(); + // let rewardTokenAddressResult = stakingContract.try_rewardsToken(); + // let rewardPerTokenStoredResult = stakingContract.try_rewardPerTokenStored(); + + let stakedPngResult = pngTokenContract.try_balanceOf(PANGOLIN_STAKING_REWARDS_ADDRESS); + if (stakedPngResult.reverted) { + log.warning("try_balanceOf", []); + } else { + entity.totalStakedPNG = convertBINumToDesiredDecimals(stakedPngResult.value, 18); + } + entity.save(); +} diff --git a/src/Pangolin/schema.graphql b/src/Pangolin/schema.graphql index dde69a1..2e72a91 100644 --- a/src/Pangolin/schema.graphql +++ b/src/Pangolin/schema.graphql @@ -17,12 +17,10 @@ type PangolinStakingData @entity { id: ID! blockNumber: BigInt! blockTimestamp: BigInt! - xJoeSupply: BigDecimal - totalStakedPNG: BigDecimal - # Total Joe staked in USDT - tvlInUSDT: BigDecimal - # Mint or Burn + rewardRate: BigDecimal + totalStakedPNG: BigDecimal event: String + totalSupply: BigDecimal } type PangolinSwapData @entity { id: ID! diff --git a/src/utils/constants.ts b/src/utils/constants.ts index e7f916c..25132d7 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -43,3 +43,5 @@ export let CAM_INCENTIVES_CONTROLLER_ADDRESS: Address = toAddress("0x357D51124f5 export let CAM_LENDING_POOL_ADDRESS: Address = toAddress("0x8dFf5E27EA6b7AC08EbFdf9eB090F32ee9a30fcf"); export let PANGOLIN_FACTORY_ADDRESS: Address = toAddress("0xefa94DE7a4656D787667C749f7E1223D71E9FD88"); +export let PANGOLIN_STAKING_REWARDS_ADDRESS: Address = toAddress("0x88afdaE1a9F58Da3E68584421937E5F564A0135b"); +export let PANGOLIN_PNG_TOKEN_ADDRESS: Address = toAddress("0x60781C2586D68229fde47564546784ab3fACA982"); From d6114aadbbb75e15bac2fc346950444857784146 Mon Sep 17 00:00:00 2001 From: michelet Date: Mon, 28 Mar 2022 15:24:23 -0300 Subject: [PATCH 17/24] Including farming events, abis. --- src/Pangolin/abis/MinichefV2.json | 489 +++++++++++++++++++ src/Pangolin/abis/RewarderViaMultiplier.json | 81 +++ src/Pangolin/config/avalanche.json | 34 +- src/Pangolin/mappings/MiniChefV2.ts | 65 +++ src/Pangolin/mappings/handleFarmEntity.ts | 26 + src/utils/constants.ts | 1 + 6 files changed, 687 insertions(+), 9 deletions(-) create mode 100644 src/Pangolin/abis/MinichefV2.json create mode 100644 src/Pangolin/abis/RewarderViaMultiplier.json create mode 100644 src/Pangolin/mappings/MiniChefV2.ts create mode 100644 src/Pangolin/mappings/handleFarmEntity.ts diff --git a/src/Pangolin/abis/MinichefV2.json b/src/Pangolin/abis/MinichefV2.json new file mode 100644 index 0000000..8cc2669 --- /dev/null +++ b/src/Pangolin/abis/MinichefV2.json @@ -0,0 +1,489 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "_rewardToken", "type": "address" }, + { "internalType": "address", "name": "_firstOwner", "type": "address" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": true, "internalType": "uint256", "name": "pid", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" } + ], + "name": "Deposit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": true, "internalType": "uint256", "name": "pid", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" } + ], + "name": "EmergencyWithdraw", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "address", "name": "funder", "type": "address" }], + "name": "FunderAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "address", "name": "funder", "type": "address" }], + "name": "FunderRemoved", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": true, "internalType": "uint256", "name": "pid", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "Harvest", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "uint256", "name": "rewardPerSecond", "type": "uint256" }], + "name": "LogRewardPerSecond", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "uint256", "name": "rewardsExpiration", "type": "uint256" }], + "name": "LogRewardsExpiration", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "uint256", "name": "pid", "type": "uint256" }], + "name": "Migrate", + "type": "event" + }, + { "anonymous": false, "inputs": [], "name": "MigratorDisabled", "type": "event" }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "address", "name": "migrator", "type": "address" }], + "name": "MigratorSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "uint256", "name": "pid", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "allocPoint", "type": "uint256" }, + { "indexed": true, "internalType": "contract IERC20", "name": "lpToken", "type": "address" }, + { "indexed": true, "internalType": "contract IRewarder", "name": "rewarder", "type": "address" } + ], + "name": "PoolAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "uint256", "name": "pid", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "allocPoint", "type": "uint256" }, + { "indexed": true, "internalType": "contract IRewarder", "name": "rewarder", "type": "address" }, + { "indexed": false, "internalType": "bool", "name": "overwrite", "type": "bool" } + ], + "name": "PoolSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "uint256", "name": "pid", "type": "uint256" }, + { "indexed": false, "internalType": "uint64", "name": "lastRewardTime", "type": "uint64" }, + { "indexed": false, "internalType": "uint256", "name": "lpSupply", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "accRewardPerShare", "type": "uint256" } + ], + "name": "PoolUpdate", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": true, "internalType": "uint256", "name": "pid", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" } + ], + "name": "Withdraw", + "type": "event" + }, + { + "inputs": [], + "name": "REWARD", + "outputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "_funder", "type": "address" }], + "name": "addFunder", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "_allocPoint", "type": "uint256" }, + { "internalType": "contract IERC20", "name": "_lpToken", "type": "address" }, + { "internalType": "contract IRewarder", "name": "_rewarder", "type": "address" } + ], + "name": "addPool", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256[]", "name": "_allocPoints", "type": "uint256[]" }, + { "internalType": "contract IERC20[]", "name": "_lpTokens", "type": "address[]" }, + { "internalType": "contract IRewarder[]", "name": "_rewarders", "type": "address[]" } + ], + "name": "addPools", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "addedTokens", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "pid", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "address", "name": "to", "type": "address" } + ], + "name": "deposit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "pid", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "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": "depositWithPermit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { "inputs": [], "name": "disableMigrator", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { "internalType": "uint256", "name": "pid", "type": "uint256" }, + { "internalType": "address", "name": "to", "type": "address" } + ], + "name": "emergencyWithdraw", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "extension", "type": "uint256" }, + { "internalType": "uint256", "name": "maxFunding", "type": "uint256" } + ], + "name": "extendRewardsViaDuration", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "funding", "type": "uint256" }, + { "internalType": "uint256", "name": "minExtension", "type": "uint256" } + ], + "name": "extendRewardsViaFunding", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "funding", "type": "uint256" }, + { "internalType": "uint256", "name": "duration", "type": "uint256" } + ], + "name": "fundRewards", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "pid", "type": "uint256" }, + { "internalType": "address", "name": "to", "type": "address" } + ], + "name": "harvest", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "_funder", "type": "address" }], + "name": "isFunder", + "outputs": [{ "internalType": "bool", "name": "allowed", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "name": "lpToken", + "outputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "lpTokens", + "outputs": [{ "internalType": "contract IERC20[]", "name": "", "type": "address[]" }], + "stateMutability": "view", + "type": "function" + }, + { "inputs": [], "name": "massUpdateAllPools", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [{ "internalType": "uint256[]", "name": "pids", "type": "uint256[]" }], + "name": "massUpdatePools", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "_pid", "type": "uint256" }], + "name": "migrate", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "migrationDisabled", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "migrator", + "outputs": [{ "internalType": "contract IMigratorChef", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "_pid", "type": "uint256" }, + { "internalType": "address", "name": "_user", "type": "address" } + ], + "name": "pendingReward", + "outputs": [{ "internalType": "uint256", "name": "pending", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "name": "poolInfo", + "outputs": [ + { "internalType": "uint128", "name": "accRewardPerShare", "type": "uint128" }, + { "internalType": "uint64", "name": "lastRewardTime", "type": "uint64" }, + { "internalType": "uint64", "name": "allocPoint", "type": "uint64" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "poolInfos", + "outputs": [ + { + "components": [ + { "internalType": "uint128", "name": "accRewardPerShare", "type": "uint128" }, + { "internalType": "uint64", "name": "lastRewardTime", "type": "uint64" }, + { "internalType": "uint64", "name": "allocPoint", "type": "uint64" } + ], + "internalType": "struct MiniChefV2.PoolInfo[]", + "name": "", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "poolLength", + "outputs": [{ "internalType": "uint256", "name": "pools", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "_funder", "type": "address" }], + "name": "removeFunder", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { "inputs": [], "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [{ "internalType": "uint256", "name": "duration", "type": "uint256" }], + "name": "resetRewardsDuration", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "rewardPerSecond", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "name": "rewarder", + "outputs": [{ "internalType": "contract IRewarder", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "rewardsExpiration", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "contract IMigratorChef", "name": "_migrator", "type": "address" }], + "name": "setMigrator", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "_pid", "type": "uint256" }, + { "internalType": "uint256", "name": "_allocPoint", "type": "uint256" }, + { "internalType": "contract IRewarder", "name": "_rewarder", "type": "address" }, + { "internalType": "bool", "name": "overwrite", "type": "bool" } + ], + "name": "setPool", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256[]", "name": "pids", "type": "uint256[]" }, + { "internalType": "uint256[]", "name": "allocPoints", "type": "uint256[]" }, + { "internalType": "contract IRewarder[]", "name": "rewarders", "type": "address[]" }, + { "internalType": "bool[]", "name": "overwrites", "type": "bool[]" } + ], + "name": "setPools", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "totalAllocPoint", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "pid", "type": "uint256" }], + "name": "updatePool", + "outputs": [ + { + "components": [ + { "internalType": "uint128", "name": "accRewardPerShare", "type": "uint128" }, + { "internalType": "uint64", "name": "lastRewardTime", "type": "uint64" }, + { "internalType": "uint64", "name": "allocPoint", "type": "uint64" } + ], + "internalType": "struct MiniChefV2.PoolInfo", + "name": "pool", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "", "type": "uint256" }, + { "internalType": "address", "name": "", "type": "address" } + ], + "name": "userInfo", + "outputs": [ + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "int256", "name": "rewardDebt", "type": "int256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "pid", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "address", "name": "to", "type": "address" } + ], + "name": "withdraw", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "pid", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "address", "name": "to", "type": "address" } + ], + "name": "withdrawAndHarvest", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/src/Pangolin/abis/RewarderViaMultiplier.json b/src/Pangolin/abis/RewarderViaMultiplier.json new file mode 100644 index 0000000..b7c000c --- /dev/null +++ b/src/Pangolin/abis/RewarderViaMultiplier.json @@ -0,0 +1,81 @@ +[ + { + "inputs": [ + { "internalType": "contract IERC20[]", "name": "_rewardTokens", "type": "address[]" }, + { "internalType": "uint256[]", "name": "_rewardMultipliers", "type": "uint256[]" }, + { "internalType": "uint256", "name": "_baseRewardTokenDecimals", "type": "uint256" }, + { "internalType": "address", "name": "_chefV2", "type": "address" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [], + "name": "getRewardMultipliers", + "outputs": [{ "internalType": "uint256[]", "name": "", "type": "uint256[]" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getRewardTokens", + "outputs": [{ "internalType": "contract IERC20[]", "name": "", "type": "address[]" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "", "type": "uint256" }, + { "internalType": "address", "name": "user", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "rewardAmount", "type": "uint256" }, + { "internalType": "uint256", "name": "", "type": "uint256" } + ], + "name": "onReward", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "", "type": "uint256" }, + { "internalType": "address", "name": "user", "type": "address" }, + { "internalType": "uint256", "name": "rewardAmount", "type": "uint256" } + ], + "name": "pendingTokens", + "outputs": [ + { "internalType": "contract IERC20[]", "name": "tokens", "type": "address[]" }, + { "internalType": "uint256[]", "name": "amounts", "type": "uint256[]" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "", "type": "uint256" }, + { "internalType": "address", "name": "user", "type": "address" }, + { "internalType": "uint256", "name": "rewardAmount", "type": "uint256" } + ], + "name": "pendingTokensDebt", + "outputs": [ + { "internalType": "contract IERC20[]", "name": "tokens", "type": "address[]" }, + { "internalType": "uint256[]", "name": "amounts", "type": "uint256[]" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "name": "rewardMultipliers", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "name": "rewardTokens", + "outputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + } +] diff --git a/src/Pangolin/config/avalanche.json b/src/Pangolin/config/avalanche.json index 25dad81..5910203 100644 --- a/src/Pangolin/config/avalanche.json +++ b/src/Pangolin/config/avalanche.json @@ -3,24 +3,40 @@ "adapter": "Pangolin", "contracts": [ { - "contract": "StakingRewards", - "abis": ["StakingRewards", "Pair", "PngToken"], - "entities": ["PangolinStakingData"], + "contract": "MiniChefV2", + "abis": ["MiniChefV2", "RewarderViaMultiplier"], + "entities": ["PangolinFarmData"], "events": [ { - "event-name": "Staked", - "event-params": "(indexed address,uint256)" + "event-name": "Deposit", + "event-params": "(indexed address,indexed uint256,uint256,indexed address)" }, { - "event-name": "Withdrawn", - "event-params": "(indexed address,uint256)" + "event-name": "Withdraw", + "event-params": "(indexed address,indexed uint256,uint256,indexed address)" + }, + { + "event-name": "Harvest", + "event-params": "(indexed address,indexed uint256,uint256)" + }, + { + "event-name": "PoolUpdate", + "event-params": "(indexed uint256,uint64,uint256,uint256)" + }, + { + "event-name": "PoolSet", + "event-params": "(indexed uint256,uint256,indexed address,bool)" + }, + { + "event-name": "PoolAdded", + "event-params": "(indexed uint256,uint256,indexed address,indexed address)" } ], "instances": [ { "symbol": "", - "address": "0x88afdaE1a9F58Da3E68584421937E5F564A0135b", - "startBlock": 7689920 + "address": "0x1f806f7C8dED893fd3caE279191ad7Aa3798E928", + "startBlock": 6987996 } ] } diff --git a/src/Pangolin/mappings/MiniChefV2.ts b/src/Pangolin/mappings/MiniChefV2.ts new file mode 100644 index 0000000..2647e1e --- /dev/null +++ b/src/Pangolin/mappings/MiniChefV2.ts @@ -0,0 +1,65 @@ +import { Address } from "@graphprotocol/graph-ts"; +import { + Deposit as DepositEvent, + Withdraw as WithdrawEvent, + Harvest as HarvestEvent, + PoolAdded as PoolAddedEvent, + PoolSet as PoolSetEvent, + PoolUpdate as PoolUpdateEvent, +} from "../../../generated/PangolinMiniChefV2/PangolinMiniChefV2"; +import { handleFarmEvent } from "./handleFarmEntity"; + +export function handleDeposit(event: DepositEvent): void { + let txnHash = event.transaction.hash; + let blockNumber = event.block.number; + let timestamp = event.block.timestamp; + let poolId = event.params.pid; + let amount = event.params.amount; + let eventType = "Deposit"; + + handleFarmEvent(txnHash, blockNumber, timestamp, poolId, eventType, null, amount, null); +} +export function handleWithdraw(event: WithdrawEvent): void { + let txnHash = event.transaction.hash; + let blockNumber = event.block.number; + let timestamp = event.block.timestamp; + let poolId = event.params.pid; + let eventType = "Withdraw"; + let amount = event.params.amount; + handleFarmEvent(txnHash, blockNumber, timestamp, poolId, eventType, null, amount, null); +} +export function handleHarvest(event: HarvestEvent): void { + let txnHash = event.transaction.hash; + let blockNumber = event.block.number; + let timestamp = event.block.timestamp; + let poolId = event.params.pid; + let amount = event.params.amount; + let eventType = "Harvest"; + handleFarmEvent(txnHash, blockNumber, timestamp, poolId, eventType, null, amount, null); +} +export function handlePoolAdded(event: PoolAddedEvent): void { + let txnHash = event.transaction.hash; + let blockNumber = event.block.number; + let timestamp = event.block.timestamp; + let poolId = event.params.pid; + let lpToken = event.params.lpToken; + let eventType = "PoolAdded"; + handleFarmEvent(txnHash, blockNumber, timestamp, poolId, eventType, lpToken, null, null); +} +export function handlePoolSet(event: PoolSetEvent): void { + let txnHash = event.transaction.hash; + let blockNumber = event.block.number; + let timestamp = event.block.timestamp; + let poolId = event.params.pid; + let eventType = "PoolSet"; + handleFarmEvent(txnHash, blockNumber, timestamp, poolId, eventType, null, null, null); +} +export function handlePoolUpdate(event: PoolUpdateEvent): void { + let txnHash = event.transaction.hash; + let blockNumber = event.block.number; + let timestamp = event.block.timestamp; + let poolId = event.params.pid; + let eventType = "PoolUpdate"; + let lpSupply = event.params.lpSupply; + handleFarmEvent(txnHash, blockNumber, timestamp, poolId, eventType, null, null, lpSupply); +} diff --git a/src/Pangolin/mappings/handleFarmEntity.ts b/src/Pangolin/mappings/handleFarmEntity.ts new file mode 100644 index 0000000..ac14ff5 --- /dev/null +++ b/src/Pangolin/mappings/handleFarmEntity.ts @@ -0,0 +1,26 @@ +import { Address, BigInt, Bytes, log } from "@graphprotocol/graph-ts"; +import { PangolinFarmData } from "../../../generated/schema"; +import { PangolinMiniChefV2 as PangolinMiniChefContract } from "../../../generated/PangolinMiniChefV2/PangolinMiniChefV2"; + +// Is the same abi for both versions +import { PangolinRewarderViaMultiplier as PangolinRewarderContract } from "../../../generated/PangolinMiniChefV2/PangolinRewarderViaMultiplier"; +import { convertBINumToDesiredDecimals, convertBytesToAddress } from "../../utils/converters"; +import { PANGOLIN_MINICHEFV2_ADDRESS, ZERO_ADDRESS, ZERO_BD, ZERO_BI } from "../../utils/constants"; +export function handleFarmEvent( + txnHash: Bytes, + blockNumber: BigInt, + timestamp: BigInt, + poolId: BigInt, + eventType: string, + lpToken: Address, + amount: BigInt, + lpSupply: BigInt, +): void { + let entity = PangolinFarmData.load(txnHash.toHex()); + if (!entity) entity = new PangolinFarmData(txnHash.toHex()); + entity.blockNumber = blockNumber; + entity.blockTimestamp = timestamp; + entity.poolId = poolId; + entity.event = eventType; + entity.lpToken = lpToken; +} diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 25132d7..9617584 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -45,3 +45,4 @@ export let CAM_LENDING_POOL_ADDRESS: Address = toAddress("0x8dFf5E27EA6b7AC08EbF export let PANGOLIN_FACTORY_ADDRESS: Address = toAddress("0xefa94DE7a4656D787667C749f7E1223D71E9FD88"); export let PANGOLIN_STAKING_REWARDS_ADDRESS: Address = toAddress("0x88afdaE1a9F58Da3E68584421937E5F564A0135b"); export let PANGOLIN_PNG_TOKEN_ADDRESS: Address = toAddress("0x60781C2586D68229fde47564546784ab3fACA982"); +export let PANGOLIN_MINICHEFV2_ADDRESS: Address = toAddress("0x1f806f7C8dED893fd3caE279191ad7Aa3798E928"); From ef2be13c88700094adfe03fdafa43346f836a23f Mon Sep 17 00:00:00 2001 From: michelet Date: Thu, 31 Mar 2022 08:45:36 -0300 Subject: [PATCH 18/24] WIP: Rewards. --- src/Pangolin/config/avalanche.json | 14 +-- src/Pangolin/mappings/MiniChefV2.ts | 60 ++++----- src/Pangolin/mappings/handleFarmEntity.ts | 93 +++++++++++++- src/Pangolin/schema.graphql | 22 ++-- src/TraderJoe/mappings/handleFarmEntity.ts | 136 +++++++++++++++++++++ 5 files changed, 271 insertions(+), 54 deletions(-) create mode 100644 src/TraderJoe/mappings/handleFarmEntity.ts diff --git a/src/Pangolin/config/avalanche.json b/src/Pangolin/config/avalanche.json index 5910203..8db74d2 100644 --- a/src/Pangolin/config/avalanche.json +++ b/src/Pangolin/config/avalanche.json @@ -7,18 +7,6 @@ "abis": ["MiniChefV2", "RewarderViaMultiplier"], "entities": ["PangolinFarmData"], "events": [ - { - "event-name": "Deposit", - "event-params": "(indexed address,indexed uint256,uint256,indexed address)" - }, - { - "event-name": "Withdraw", - "event-params": "(indexed address,indexed uint256,uint256,indexed address)" - }, - { - "event-name": "Harvest", - "event-params": "(indexed address,indexed uint256,uint256)" - }, { "event-name": "PoolUpdate", "event-params": "(indexed uint256,uint64,uint256,uint256)" @@ -36,7 +24,7 @@ { "symbol": "", "address": "0x1f806f7C8dED893fd3caE279191ad7Aa3798E928", - "startBlock": 6987996 + "startBlock": 9805993 } ] } diff --git a/src/Pangolin/mappings/MiniChefV2.ts b/src/Pangolin/mappings/MiniChefV2.ts index 2647e1e..8c8d212 100644 --- a/src/Pangolin/mappings/MiniChefV2.ts +++ b/src/Pangolin/mappings/MiniChefV2.ts @@ -1,42 +1,42 @@ import { Address } from "@graphprotocol/graph-ts"; import { - Deposit as DepositEvent, - Withdraw as WithdrawEvent, - Harvest as HarvestEvent, + // Deposit as DepositEvent, + // Withdraw as WithdrawEvent, + // Harvest as HarvestEvent, PoolAdded as PoolAddedEvent, PoolSet as PoolSetEvent, PoolUpdate as PoolUpdateEvent, } from "../../../generated/PangolinMiniChefV2/PangolinMiniChefV2"; import { handleFarmEvent } from "./handleFarmEntity"; -export function handleDeposit(event: DepositEvent): void { - let txnHash = event.transaction.hash; - let blockNumber = event.block.number; - let timestamp = event.block.timestamp; - let poolId = event.params.pid; - let amount = event.params.amount; - let eventType = "Deposit"; +// export function handleDeposit(event: DepositEvent): void { +// let txnHash = event.transaction.hash; +// let blockNumber = event.block.number; +// let timestamp = event.block.timestamp; +// let poolId = event.params.pid; +// let amount = event.params.amount; +// let eventType = "Deposit"; - handleFarmEvent(txnHash, blockNumber, timestamp, poolId, eventType, null, amount, null); -} -export function handleWithdraw(event: WithdrawEvent): void { - let txnHash = event.transaction.hash; - let blockNumber = event.block.number; - let timestamp = event.block.timestamp; - let poolId = event.params.pid; - let eventType = "Withdraw"; - let amount = event.params.amount; - handleFarmEvent(txnHash, blockNumber, timestamp, poolId, eventType, null, amount, null); -} -export function handleHarvest(event: HarvestEvent): void { - let txnHash = event.transaction.hash; - let blockNumber = event.block.number; - let timestamp = event.block.timestamp; - let poolId = event.params.pid; - let amount = event.params.amount; - let eventType = "Harvest"; - handleFarmEvent(txnHash, blockNumber, timestamp, poolId, eventType, null, amount, null); -} +// handleFarmEvent(txnHash, blockNumber, timestamp, poolId, eventType, null, amount, null); +// } +// export function handleWithdraw(event: WithdrawEvent): void { +// let txnHash = event.transaction.hash; +// let blockNumber = event.block.number; +// let timestamp = event.block.timestamp; +// let poolId = event.params.pid; +// let eventType = "Withdraw"; +// let amount = event.params.amount; +// handleFarmEvent(txnHash, blockNumber, timestamp, poolId, eventType, null, amount, null); +// } +// export function handleHarvest(event: HarvestEvent): void { +// let txnHash = event.transaction.hash; +// let blockNumber = event.block.number; +// let timestamp = event.block.timestamp; +// let poolId = event.params.pid; +// let amount = event.params.amount; +// let eventType = "Harvest"; +// handleFarmEvent(txnHash, blockNumber, timestamp, poolId, eventType, null, amount, null); +// } export function handlePoolAdded(event: PoolAddedEvent): void { let txnHash = event.transaction.hash; let blockNumber = event.block.number; diff --git a/src/Pangolin/mappings/handleFarmEntity.ts b/src/Pangolin/mappings/handleFarmEntity.ts index ac14ff5..8758399 100644 --- a/src/Pangolin/mappings/handleFarmEntity.ts +++ b/src/Pangolin/mappings/handleFarmEntity.ts @@ -1,5 +1,5 @@ import { Address, BigInt, Bytes, log } from "@graphprotocol/graph-ts"; -import { PangolinFarmData } from "../../../generated/schema"; +import { PangolinFarmData, PangolinFarmReward } from "../../../generated/schema"; import { PangolinMiniChefV2 as PangolinMiniChefContract } from "../../../generated/PangolinMiniChefV2/PangolinMiniChefV2"; // Is the same abi for both versions @@ -23,4 +23,95 @@ export function handleFarmEvent( entity.poolId = poolId; entity.event = eventType; entity.lpToken = lpToken; + + let poolAllocPoints = ZERO_BI; + let totalAllocPoints = ZERO_BI; + let totalPngPerSecond = ZERO_BD; + let rewarderAddress = ZERO_ADDRESS; + let farmContract = PangolinMiniChefContract.bind(PANGOLIN_MINICHEFV2_ADDRESS); + + let lpTokensResult = farmContract.try_lpTokens(); + if (lpTokensResult.reverted) { + log.warning("lp_tokens() reverted", []); + } else { + let lpTokens = lpTokensResult.value; + entity.lpToken = lpTokens[poolId.toI32()]; + } + + let totalPngPerSecondResult = farmContract.try_rewardPerSecond(); + if (totalPngPerSecondResult.reverted) { + log.warning("rewardPerSecond() reverted", []); + } else { + totalPngPerSecond = convertBINumToDesiredDecimals(totalPngPerSecondResult.value, 18); + } + let totalAllocPointResult = farmContract.try_totalAllocPoint(); + if (totalAllocPointResult.reverted) { + log.warning("totalAllocPoint() reverted", []); + } else { + totalAllocPoints = totalAllocPointResult.value; + } + + let poolInfoResult = farmContract.try_poolInfo(poolId); + if (poolInfoResult.reverted) { + log.warning("poolInfo() reverted", []); + } else { + let poolInfo = poolInfoResult.value; + entity.lastRewardTime = poolInfo.value1; + poolAllocPoints = poolInfo.value2; + entity.accRewardPerShare = convertBINumToDesiredDecimals(poolInfo.value0, 18); + if (totalAllocPoints > ZERO_BI) { + entity.pngPerSecond = totalPngPerSecond + .times(poolAllocPoints.toBigDecimal()) + .div(totalAllocPoints.toBigDecimal()); + } + } + let rewarderResult = farmContract.try_rewarder(poolId); + if (rewarderResult.reverted) { + log.warning("try_rewarder({}) reverted", [poolId.toString()]); + } else { + rewarderAddress = rewarderResult.value; + log.warning("try_rewarder({}) not reverted, {}", [poolId.toString(), rewarderAddress.toHexString()]); + } + + // Rewards + if (rewarderAddress != ZERO_ADDRESS) { + //log.debug("Inside rewards,poolid{}-rewardAddressHexString{}", [poolId.toString(), rewarderAddress.toHexString()]); + + let additionalRewards: Array = new Array(); + let rewarderContract = PangolinRewarderContract.bind(rewarderAddress); + let rewardIds: Array = []; + let multipliersResult = rewarderContract.try_getRewardMultipliers(); + let rewardTokensResult = rewarderContract.try_getRewardTokens(); + + if (rewardTokensResult.reverted) { + log.warning("try_getRewardTokens() on {} reverted", [rewarderAddress.toHexString()]); + } else { + let rewardTokens = rewardTokensResult.value; + //log.debug("{} rewardTokensResultValue[]", [rewardTokens.toString()]); + + for (let i = 0; i < rewardTokens.length; i++) { + // log.debug("rewardTokens[],poolid{}-iesimaAddress{}", [poolId.toHexString(), rewardTokens[i].toHexString()]); + let reward = new PangolinFarmReward(poolId.toHexString() + "-" + rewardTokens[i].toHexString()); + reward.rewardToken = rewardTokens[i]; + reward.save(); + additionalRewards.push(reward); + rewardIds.push(reward.id); + } + } + if (multipliersResult.reverted) { + log.warning("try_getRewardMultipliers() on {} reverted", [rewarderAddress.toHexString()]); + } else { + let rewardMultipliers = multipliersResult.value; + for (let i = 0; i < rewardMultipliers.length; i++) { + //log.debug("{} rewardTokens[{}],{}", [i.toString(), rewardMultipliers[i].toHexString()]); + let multiplier = convertBINumToDesiredDecimals(rewardMultipliers[i], 18); + additionalRewards[i].rewardMultiplier = multiplier; + additionalRewards[i].rewardTokenPerSecond = entity.pngPerSecond.times(multiplier); + additionalRewards[i].save(); + } + } + entity.additionalRewards = rewardIds; + } + + entity.save(); } diff --git a/src/Pangolin/schema.graphql b/src/Pangolin/schema.graphql index 2e72a91..26b4a24 100644 --- a/src/Pangolin/schema.graphql +++ b/src/Pangolin/schema.graphql @@ -1,17 +1,20 @@ type PangolinFarmData @entity { - id: ID! + id: ID! blockNumber: BigInt! blockTimestamp: BigInt! lpToken: Bytes! - poolId: BigInt! - version: String - accJoePerShare: BigDecimal - joePerSecond: BigDecimal - rewardToken: Bytes - rewarder: Bytes! - rewardPerSecond: BigDecimal + poolId: BigInt! + accRewardPerShare: BigDecimal + pngPerSecond: BigDecimal lastRewardTime: BigInt - event: String + event: String + additionalRewards: [PangolinFarmReward!] +} +type PangolinFarmReward @entity { + id: ID! # poolId - reward token address + rewardMultiplier: BigDecimal + rewardTokenPerSecond: BigDecimal + rewardToken: Bytes! } type PangolinStakingData @entity { id: ID! @@ -39,5 +42,4 @@ type PangolinSwapPair @entity { token1Decimals: BigInt! token0Symbol: String! token1Symbol: String! - } \ No newline at end of file diff --git a/src/TraderJoe/mappings/handleFarmEntity.ts b/src/TraderJoe/mappings/handleFarmEntity.ts new file mode 100644 index 0000000..e51fece --- /dev/null +++ b/src/TraderJoe/mappings/handleFarmEntity.ts @@ -0,0 +1,136 @@ +import { Address, BigInt, Bytes, log } from "@graphprotocol/graph-ts"; +import { TraderJoeFarmData } from "../../../generated/schema"; +import { TraderJoeMasterChefJoeV3 as MasterChefJoeV3Contract } from "../../../generated/TraderJoeMasterChefJoeV3/TraderJoeMasterChefJoeV3"; +import { TraderJoeMasterChefJoeV2 as MasterChefJoeV2Contract } from "../../../generated/TraderJoeMasterChefJoeV2/TraderJoeMasterChefJoeV2"; + +// Is the same abi for both versions +import { TraderJoeSimpleRewarderPerSec as RewarderContract } from "../../../generated/TraderJoeMasterChefJoeV2/TraderJoeSimpleRewarderPerSec"; +import { convertBINumToDesiredDecimals, convertBytesToAddress } from "../../utils/converters"; +import { + TRADER_JOE_MASTER_CHEF_V2_ADDRESS, + TRADER_JOE_MASTER_CHEF_V3_ADDRESS, + ZERO_ADDRESS, + ZERO_BD, + ZERO_BI, +} from "../../utils/constants"; + +export function handlePoolEvent( + txnHash: Bytes, + blockNumber: BigInt, + timestamp: BigInt, + poolId: BigInt, + eventType: string, + version: string, + lpToken: Address, +): void { + let entity = TraderJoeFarmData.load(txnHash.toHex()); + if (!entity) entity = new TraderJoeFarmData(txnHash.toHex()); + + entity.blockNumber = blockNumber; + entity.blockTimestamp = timestamp; + entity.poolId = poolId; + + entity.event = eventType; + entity.version = version; + + if (version == "V2") { + entity = updateEntityV2(entity as TraderJoeFarmData, poolId); + } else if (version == "V3") { + entity = updateEntityV3(entity as TraderJoeFarmData, poolId); + } + + // Rewards + let rewardAddress = convertBytesToAddress(entity.rewarder); + let rewarderContract = RewarderContract.bind(rewardAddress); + let rewarderTokenResult = rewarderContract.try_rewardToken(); + if (rewarderTokenResult.reverted) { + log.warning("rewardToken() reverted", []); + entity.rewardToken = ZERO_ADDRESS; + } else { + entity.rewardToken = rewarderTokenResult.value; + } + + let poolRewardPerSecondResult = rewarderContract.try_tokenPerSec(); + if (poolRewardPerSecondResult.reverted) { + log.warning("rewardPerSec() reverted", []); + entity.rewardPerSecond = ZERO_BD; + } else { + entity.rewardPerSecond = convertBINumToDesiredDecimals(poolRewardPerSecondResult.value, 18); + } + + if (lpToken != null) { + entity.lpToken = lpToken; + } + entity.save(); +} + +function updateEntityV2(entity: TraderJoeFarmData, poolId: BigInt): TraderJoeFarmData { + let poolAllocPoints = ZERO_BI; + let totalJoePerSec = ZERO_BD; + let totalAllocPoints = ZERO_BI; + let contract = MasterChefJoeV2Contract.bind(TRADER_JOE_MASTER_CHEF_V2_ADDRESS); + + let totalJoePerSecResult = contract.try_joePerSec(); + if (totalJoePerSecResult.reverted) { + log.warning("joePerSec() reverted", []); + } else { + totalJoePerSec = convertBINumToDesiredDecimals(totalJoePerSecResult.value, 18); + } + let totalAllocPointResult = contract.try_totalAllocPoint(); + if (totalAllocPointResult.reverted) { + log.warning("totalAllocPoint() reverted", []); + } else { + totalAllocPoints = totalAllocPointResult.value; + } + let poolResult = contract.try_poolInfo(poolId); + if (poolResult.reverted) { + log.warning("poolInfo() reverted", []); + } else { + let poolInfo = poolResult.value; + entity.lpToken = poolInfo.value0; + poolAllocPoints = poolInfo.value1; + entity.lastRewardTime = poolInfo.value2; + entity.accJoePerShare = convertBINumToDesiredDecimals(poolInfo.value3, 18); + if (totalAllocPoints > ZERO_BI) { + entity.joePerSecond = totalJoePerSec.times(poolAllocPoints.toBigDecimal()).div(totalAllocPoints.toBigDecimal()); + } + entity.rewarder = poolInfo.value4; + } + return entity; +} + +function updateEntityV3(entity: TraderJoeFarmData, poolId: BigInt): TraderJoeFarmData { + let poolAllocPoints = ZERO_BI; + let totalJoePerSec = ZERO_BD; + let totalAllocPoints = ZERO_BI; + let contract = MasterChefJoeV3Contract.bind(TRADER_JOE_MASTER_CHEF_V3_ADDRESS); + + let totalJoePerSecResult = contract.try_joePerSec(); + if (totalJoePerSecResult.reverted) { + log.warning("joePerSec() reverted", []); + } else { + totalJoePerSec = convertBINumToDesiredDecimals(totalJoePerSecResult.value, 18); + } + let totalAllocPointResult = contract.try_totalAllocPoint(); + if (totalAllocPointResult.reverted) { + log.warning("totalAllocPoint() reverted", []); + } else { + totalAllocPoints = totalAllocPointResult.value; + } + let poolResult = contract.try_poolInfo(poolId); + if (poolResult.reverted) { + log.warning("poolInfo() reverted", []); + } else { + let poolInfo = poolResult.value; + entity.lpToken = poolInfo.value0; + poolAllocPoints = poolInfo.value1; + entity.lastRewardTime = poolInfo.value2; + entity.accJoePerShare = convertBINumToDesiredDecimals(poolInfo.value3, 18); + if (totalAllocPoints > ZERO_BI) { + entity.joePerSecond = totalJoePerSec.times(poolAllocPoints.toBigDecimal()).div(totalAllocPoints.toBigDecimal()); + } + entity.rewarder = poolInfo.value4; + } + + return entity; +} From 7f5be22f23249c287a3aa7e2451904e9c220bb3a Mon Sep 17 00:00:00 2001 From: michelet Date: Thu, 31 Mar 2022 15:43:17 -0300 Subject: [PATCH 19/24] Updating Farm rewards, including multipliers. --- src/Pangolin/config/avalanche.json | 55 +++++++++++++++++++- src/Pangolin/mappings/MiniChefV2.ts | 38 ++------------ src/Pangolin/mappings/handleFarmEntity.ts | 16 ++---- src/Pangolin/mappings/handleStakingEntity.ts | 25 +++------ 4 files changed, 67 insertions(+), 67 deletions(-) diff --git a/src/Pangolin/config/avalanche.json b/src/Pangolin/config/avalanche.json index 8db74d2..62aa912 100644 --- a/src/Pangolin/config/avalanche.json +++ b/src/Pangolin/config/avalanche.json @@ -2,6 +2,28 @@ "network": "avalanche", "adapter": "Pangolin", "contracts": [ + { + "contract": "StakingRewards", + "abis": ["StakingRewards", "Pair", "PngToken"], + "entities": ["PangolinStakingData"], + "events": [ + { + "event-name": "Staked", + "event-params": "(indexed address,uint256)" + }, + { + "event-name": "Withdrawn", + "event-params": "(indexed address,uint256)" + } + ], + "instances": [ + { + "symbol": "", + "address": "0x88afdaE1a9F58Da3E68584421937E5F564A0135b", + "startBlock": 7689920 + } + ] + }, { "contract": "MiniChefV2", "abis": ["MiniChefV2", "RewarderViaMultiplier"], @@ -24,7 +46,38 @@ { "symbol": "", "address": "0x1f806f7C8dED893fd3caE279191ad7Aa3798E928", - "startBlock": 9805993 + "startBlock": 6987996 + } + ] + }, + { + "contract": "Factory", + "abis": ["Factory", "Pair"], + "entities": ["PangolinSwapPair"], + "events": [ + { + "event-name": "PairCreated", + "event-params": "(indexed address,indexed address,address,uint256)" + } + ], + "instances": [ + { + "symbol": "", + "address": "0xefa94DE7a4656D787667C749f7E1223D71E9FD88", + "startBlock": 56877 + } + ] + } + ], + "templates": [ + { + "name": "Pair", + "abis": ["Pair", "Factory", "ERC20"], + "entities": ["PangolinSwapData"], + "events": [ + { + "event-name": "Swap", + "event-params": "(indexed address,uint256,uint256,uint256,uint256,indexed address)" } ] } diff --git a/src/Pangolin/mappings/MiniChefV2.ts b/src/Pangolin/mappings/MiniChefV2.ts index 8c8d212..230d6d9 100644 --- a/src/Pangolin/mappings/MiniChefV2.ts +++ b/src/Pangolin/mappings/MiniChefV2.ts @@ -1,42 +1,10 @@ -import { Address } from "@graphprotocol/graph-ts"; import { - // Deposit as DepositEvent, - // Withdraw as WithdrawEvent, - // Harvest as HarvestEvent, PoolAdded as PoolAddedEvent, PoolSet as PoolSetEvent, PoolUpdate as PoolUpdateEvent, } from "../../../generated/PangolinMiniChefV2/PangolinMiniChefV2"; import { handleFarmEvent } from "./handleFarmEntity"; -// export function handleDeposit(event: DepositEvent): void { -// let txnHash = event.transaction.hash; -// let blockNumber = event.block.number; -// let timestamp = event.block.timestamp; -// let poolId = event.params.pid; -// let amount = event.params.amount; -// let eventType = "Deposit"; - -// handleFarmEvent(txnHash, blockNumber, timestamp, poolId, eventType, null, amount, null); -// } -// export function handleWithdraw(event: WithdrawEvent): void { -// let txnHash = event.transaction.hash; -// let blockNumber = event.block.number; -// let timestamp = event.block.timestamp; -// let poolId = event.params.pid; -// let eventType = "Withdraw"; -// let amount = event.params.amount; -// handleFarmEvent(txnHash, blockNumber, timestamp, poolId, eventType, null, amount, null); -// } -// export function handleHarvest(event: HarvestEvent): void { -// let txnHash = event.transaction.hash; -// let blockNumber = event.block.number; -// let timestamp = event.block.timestamp; -// let poolId = event.params.pid; -// let amount = event.params.amount; -// let eventType = "Harvest"; -// handleFarmEvent(txnHash, blockNumber, timestamp, poolId, eventType, null, amount, null); -// } export function handlePoolAdded(event: PoolAddedEvent): void { let txnHash = event.transaction.hash; let blockNumber = event.block.number; @@ -44,7 +12,7 @@ export function handlePoolAdded(event: PoolAddedEvent): void { let poolId = event.params.pid; let lpToken = event.params.lpToken; let eventType = "PoolAdded"; - handleFarmEvent(txnHash, blockNumber, timestamp, poolId, eventType, lpToken, null, null); + handleFarmEvent(txnHash, blockNumber, timestamp, poolId, eventType, lpToken); } export function handlePoolSet(event: PoolSetEvent): void { let txnHash = event.transaction.hash; @@ -52,7 +20,7 @@ export function handlePoolSet(event: PoolSetEvent): void { let timestamp = event.block.timestamp; let poolId = event.params.pid; let eventType = "PoolSet"; - handleFarmEvent(txnHash, blockNumber, timestamp, poolId, eventType, null, null, null); + handleFarmEvent(txnHash, blockNumber, timestamp, poolId, eventType, null); } export function handlePoolUpdate(event: PoolUpdateEvent): void { let txnHash = event.transaction.hash; @@ -61,5 +29,5 @@ export function handlePoolUpdate(event: PoolUpdateEvent): void { let poolId = event.params.pid; let eventType = "PoolUpdate"; let lpSupply = event.params.lpSupply; - handleFarmEvent(txnHash, blockNumber, timestamp, poolId, eventType, null, null, lpSupply); + handleFarmEvent(txnHash, blockNumber, timestamp, poolId, eventType, null); } diff --git a/src/Pangolin/mappings/handleFarmEntity.ts b/src/Pangolin/mappings/handleFarmEntity.ts index 8758399..8b3e0bf 100644 --- a/src/Pangolin/mappings/handleFarmEntity.ts +++ b/src/Pangolin/mappings/handleFarmEntity.ts @@ -2,9 +2,8 @@ import { Address, BigInt, Bytes, log } from "@graphprotocol/graph-ts"; import { PangolinFarmData, PangolinFarmReward } from "../../../generated/schema"; import { PangolinMiniChefV2 as PangolinMiniChefContract } from "../../../generated/PangolinMiniChefV2/PangolinMiniChefV2"; -// Is the same abi for both versions import { PangolinRewarderViaMultiplier as PangolinRewarderContract } from "../../../generated/PangolinMiniChefV2/PangolinRewarderViaMultiplier"; -import { convertBINumToDesiredDecimals, convertBytesToAddress } from "../../utils/converters"; +import { convertBINumToDesiredDecimals } from "../../utils/converters"; import { PANGOLIN_MINICHEFV2_ADDRESS, ZERO_ADDRESS, ZERO_BD, ZERO_BI } from "../../utils/constants"; export function handleFarmEvent( txnHash: Bytes, @@ -13,8 +12,6 @@ export function handleFarmEvent( poolId: BigInt, eventType: string, lpToken: Address, - amount: BigInt, - lpSupply: BigInt, ): void { let entity = PangolinFarmData.load(txnHash.toHex()); if (!entity) entity = new PangolinFarmData(txnHash.toHex()); @@ -70,16 +67,13 @@ export function handleFarmEvent( log.warning("try_rewarder({}) reverted", [poolId.toString()]); } else { rewarderAddress = rewarderResult.value; - log.warning("try_rewarder({}) not reverted, {}", [poolId.toString(), rewarderAddress.toHexString()]); } - // Rewards + // If there's additional rewards, query the rewarder address for the address tokens and its multipliers. if (rewarderAddress != ZERO_ADDRESS) { - //log.debug("Inside rewards,poolid{}-rewardAddressHexString{}", [poolId.toString(), rewarderAddress.toHexString()]); - let additionalRewards: Array = new Array(); let rewarderContract = PangolinRewarderContract.bind(rewarderAddress); - let rewardIds: Array = []; + let rewardIds: Array = []; let multipliersResult = rewarderContract.try_getRewardMultipliers(); let rewardTokensResult = rewarderContract.try_getRewardTokens(); @@ -87,10 +81,8 @@ export function handleFarmEvent( log.warning("try_getRewardTokens() on {} reverted", [rewarderAddress.toHexString()]); } else { let rewardTokens = rewardTokensResult.value; - //log.debug("{} rewardTokensResultValue[]", [rewardTokens.toString()]); for (let i = 0; i < rewardTokens.length; i++) { - // log.debug("rewardTokens[],poolid{}-iesimaAddress{}", [poolId.toHexString(), rewardTokens[i].toHexString()]); let reward = new PangolinFarmReward(poolId.toHexString() + "-" + rewardTokens[i].toHexString()); reward.rewardToken = rewardTokens[i]; reward.save(); @@ -103,9 +95,9 @@ export function handleFarmEvent( } else { let rewardMultipliers = multipliersResult.value; for (let i = 0; i < rewardMultipliers.length; i++) { - //log.debug("{} rewardTokens[{}],{}", [i.toString(), rewardMultipliers[i].toHexString()]); let multiplier = convertBINumToDesiredDecimals(rewardMultipliers[i], 18); additionalRewards[i].rewardMultiplier = multiplier; + // the farm additional rewards are based on PNG, so the rate is affected by the multiplier. additionalRewards[i].rewardTokenPerSecond = entity.pngPerSecond.times(multiplier); additionalRewards[i].save(); } diff --git a/src/Pangolin/mappings/handleStakingEntity.ts b/src/Pangolin/mappings/handleStakingEntity.ts index 54a89d6..2eb7842 100644 --- a/src/Pangolin/mappings/handleStakingEntity.ts +++ b/src/Pangolin/mappings/handleStakingEntity.ts @@ -1,17 +1,9 @@ -import { Address, BigInt, Bytes, log } from "@graphprotocol/graph-ts"; +import { BigInt, Bytes, log } from "@graphprotocol/graph-ts"; import { PangolinStakingData } from "../../../generated/schema"; - -// Is the same abi for both versions import { PangolinStakingRewards as StakingRewardContract } from "../../../generated/PangolinStakingRewards/PangolinStakingRewards"; import { PangolinPngToken as PngTokenContract } from "../../../generated/PangolinStakingRewards/PangolinPngToken"; -import { convertBINumToDesiredDecimals, convertBytesToAddress } from "../../utils/converters"; -import { - PANGOLIN_STAKING_REWARDS_ADDRESS, - PANGOLIN_PNG_TOKEN_ADDRESS, - ZERO_ADDRESS, - ZERO_BD, - ZERO_BI, -} from "../../utils/constants"; +import { convertBINumToDesiredDecimals } from "../../utils/converters"; +import { PANGOLIN_STAKING_REWARDS_ADDRESS, PANGOLIN_PNG_TOKEN_ADDRESS } from "../../utils/constants"; export function handleStakingEntity( txHash: Bytes, @@ -26,30 +18,25 @@ export function handleStakingEntity( entity.blockTimestamp = timestamp; entity.event = eventType; - // instantiate contracts let stakingContract = StakingRewardContract.bind(PANGOLIN_STAKING_REWARDS_ADDRESS); let pngTokenContract = PngTokenContract.bind(PANGOLIN_PNG_TOKEN_ADDRESS); let totalSupplyResult = stakingContract.try_totalSupply(); if (totalSupplyResult.reverted) { - log.warning("try_totalSupply()", []); + log.warning("try_totalSupply() reverted", []); } else { entity.totalSupply = convertBINumToDesiredDecimals(totalSupplyResult.value, 18); } - // let rewardPerTokenResult = stakingContract.try_rewardPerToken(); let rewardRateResult = stakingContract.try_rewardRate(); if (rewardRateResult.reverted) { - log.warning("try_rewardRate", []); + log.warning("try_rewardRate() reverted", []); } else { entity.rewardRate = convertBINumToDesiredDecimals(rewardRateResult.value, 18); } - // let stakingTokenAddressResult = stakingContract.try_stakingToken(); - // let rewardTokenAddressResult = stakingContract.try_rewardsToken(); - // let rewardPerTokenStoredResult = stakingContract.try_rewardPerTokenStored(); let stakedPngResult = pngTokenContract.try_balanceOf(PANGOLIN_STAKING_REWARDS_ADDRESS); if (stakedPngResult.reverted) { - log.warning("try_balanceOf", []); + log.warning("try_balanceOf() reverted", []); } else { entity.totalStakedPNG = convertBINumToDesiredDecimals(stakedPngResult.value, 18); } From f19ed75237a51fa7e211a801273a3947662f3d40 Mon Sep 17 00:00:00 2001 From: michelet Date: Thu, 31 Mar 2022 16:04:30 -0300 Subject: [PATCH 20/24] handling amount in staking. --- src/Pangolin/mappings/handleStakingEntity.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Pangolin/mappings/handleStakingEntity.ts b/src/Pangolin/mappings/handleStakingEntity.ts index 2eb7842..ca5b23b 100644 --- a/src/Pangolin/mappings/handleStakingEntity.ts +++ b/src/Pangolin/mappings/handleStakingEntity.ts @@ -40,5 +40,11 @@ export function handleStakingEntity( } else { entity.totalStakedPNG = convertBINumToDesiredDecimals(stakedPngResult.value, 18); } + let actualAmount = convertBINumToDesiredDecimals(amount, 18); + if (eventType == "Withdraw") { + entity.totalStakedPNG = entity.totalStakedPNG.minus(actualAmount); + } else { + entity.totalStakedPNG = entity.totalStakedPNG.plus(actualAmount); + } entity.save(); } From 23eccaf7313afb3761961ee4dfae13cfac46a7d8 Mon Sep 17 00:00:00 2001 From: michelet Date: Thu, 31 Mar 2022 16:50:50 -0300 Subject: [PATCH 21/24] Using contract data instead of amount in Staking. --- src/Pangolin/mappings/StakingRewards.ts | 10 ++-------- src/Pangolin/mappings/handleStakingEntity.ts | 15 ++------------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/src/Pangolin/mappings/StakingRewards.ts b/src/Pangolin/mappings/StakingRewards.ts index f2672ed..cf9cb4c 100644 --- a/src/Pangolin/mappings/StakingRewards.ts +++ b/src/Pangolin/mappings/StakingRewards.ts @@ -5,14 +5,8 @@ import { import { handleStakingEntity } from "./handleStakingEntity"; export function handleStaked(event: StakeEvent): void { - handleStakingEntity(event.transaction.hash, event.block.number, event.block.timestamp, "Stake", event.params.amount); + handleStakingEntity(event.transaction.hash, event.block.number, event.block.timestamp, "Stake"); } export function handleWithdrawn(event: WithdrawnEvent): void { - handleStakingEntity( - event.transaction.hash, - event.block.number, - event.block.timestamp, - "Withdraw", - event.params.amount, - ); + handleStakingEntity(event.transaction.hash, event.block.number, event.block.timestamp, "Withdraw"); } diff --git a/src/Pangolin/mappings/handleStakingEntity.ts b/src/Pangolin/mappings/handleStakingEntity.ts index ca5b23b..0598835 100644 --- a/src/Pangolin/mappings/handleStakingEntity.ts +++ b/src/Pangolin/mappings/handleStakingEntity.ts @@ -5,13 +5,7 @@ import { PangolinPngToken as PngTokenContract } from "../../../generated/Pangoli import { convertBINumToDesiredDecimals } from "../../utils/converters"; import { PANGOLIN_STAKING_REWARDS_ADDRESS, PANGOLIN_PNG_TOKEN_ADDRESS } from "../../utils/constants"; -export function handleStakingEntity( - txHash: Bytes, - blockNumber: BigInt, - timestamp: BigInt, - eventType: string, - amount: BigInt, -): void { +export function handleStakingEntity(txHash: Bytes, blockNumber: BigInt, timestamp: BigInt, eventType: string): void { let entity = PangolinStakingData.load(txHash.toHex()); if (!entity) entity = new PangolinStakingData(txHash.toHex()); entity.blockNumber = blockNumber; @@ -40,11 +34,6 @@ export function handleStakingEntity( } else { entity.totalStakedPNG = convertBINumToDesiredDecimals(stakedPngResult.value, 18); } - let actualAmount = convertBINumToDesiredDecimals(amount, 18); - if (eventType == "Withdraw") { - entity.totalStakedPNG = entity.totalStakedPNG.minus(actualAmount); - } else { - entity.totalStakedPNG = entity.totalStakedPNG.plus(actualAmount); - } + entity.save(); } From c41bee43cc1079ebee8e62a5f3238364af759da3 Mon Sep 17 00:00:00 2001 From: michelet Date: Wed, 6 Apr 2022 17:57:15 -0300 Subject: [PATCH 22/24] fix: remove unnecessary .idea folder --- .idea/vcs.xml | 6 ---- .idea/workspace.xml | 74 --------------------------------------------- 2 files changed, 80 deletions(-) delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/workspace.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index f2a7f5a..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - 1648131623706 - - - - - - - - - \ No newline at end of file From fd975a1c77d432bcde37346a9f0a79cc81b448f7 Mon Sep 17 00:00:00 2001 From: michelet Date: Thu, 7 Apr 2022 13:14:38 -0300 Subject: [PATCH 23/24] adding adding github build action for pangolin --- .github/workflows/main.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 473f6f4..45b54f9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,10 +2,9 @@ name: Megagraph CI on: push: - branches: [ master ] + branches: [master] pull_request: - branches: [ master ] - + branches: [master] jobs: build: @@ -17,7 +16,7 @@ jobs: uses: actions/cache@v2 id: cache with: - path: '**/node_modules' + path: "**/node_modules" key: npm-v2-${{ hashFiles('**/yarn.lock') }} restore-keys: npm-v2- - name: Install @@ -124,6 +123,11 @@ jobs: env: ADAPTER: Mai CONFIG: polygon + - name: Build Pangolin (Avalanche) + run: yarn build:dev + env: + ADAPTER: Pangolin + CONFIG: avalanche - name: Build QuickSwap (Polygon) run: yarn build:dev env: From 2d2e3aea942e3cfcd7fae27f4720d139d0f7bac1 Mon Sep 17 00:00:00 2001 From: miklt <43281125+miklt@users.noreply.github.com> Date: Thu, 7 Apr 2022 13:29:31 -0300 Subject: [PATCH 24/24] Rename MinichefV2.json to MiniChefV2.json --- src/Pangolin/abis/{MinichefV2.json => MiniChefV2.json} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/Pangolin/abis/{MinichefV2.json => MiniChefV2.json} (100%) diff --git a/src/Pangolin/abis/MinichefV2.json b/src/Pangolin/abis/MiniChefV2.json similarity index 100% rename from src/Pangolin/abis/MinichefV2.json rename to src/Pangolin/abis/MiniChefV2.json