From 27e4f09faa5d1415335de08b87b3c207bfe36150 Mon Sep 17 00:00:00 2001 From: Ed Noepel <46749157+EdNoepel@users.noreply.github.com> Date: Tue, 15 Aug 2023 07:18:34 -0400 Subject: [PATCH] Burn Wrapper (#50) * update for rc7 testnet * burnwrapper * manually adjusted ABI to correct event names * only handle mints --- abis/BurnWrappedAjna.json | 246 ++++++++++++++++++++++++++++++++++++++ add-commands.txt | 5 +- local/docker-compose.yml | 2 +- networks.json | 25 +++- schema.graphql | 14 +++ src/burn-wrapped-ajna.ts | 25 ++++ subgraph.yaml | 59 ++++++--- 7 files changed, 350 insertions(+), 26 deletions(-) create mode 100644 abis/BurnWrappedAjna.json create mode 100644 src/burn-wrapped-ajna.ts diff --git a/abis/BurnWrappedAjna.json b/abis/BurnWrappedAjna.json new file mode 100644 index 0000000..63f9b2d --- /dev/null +++ b/abis/BurnWrappedAjna.json @@ -0,0 +1,246 @@ +[ + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "wrappedToken", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { "inputs": [], "name": "InvalidWrappedToken", "type": "error" }, + { "inputs": [], "name": "UnwrapNotAllowed", "type": "error" }, + { + "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": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "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": "account", "type": "address" } + ], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "burn", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "burnFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "stateMutability": "pure", + "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": "account", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "depositFor", + "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": [ + { "internalType": "address", "name": "owner", "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" }, + { "internalType": "uint256", "name": "value", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "permit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "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": "to", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transfer", + "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": "amount", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "underlying", + "outputs": [ + { "internalType": "contract IERC20", "name": "", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "", "type": "address" }, + { "internalType": "uint256", "name": "", "type": "uint256" } + ], + "name": "withdrawTo", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "pure", + "type": "function" + } +] diff --git a/add-commands.txt b/add-commands.txt index f57635c..beab5b2 100644 --- a/add-commands.txt +++ b/add-commands.txt @@ -17,4 +17,7 @@ graph add 0xEd6890d748e62ddbb3f80e7256Deeb2fBb853476 --abi ../contracts/forge_ou graph add 0xaeB91e664A49829FaBf06BE35d4447938d83A271 --abi ../ecosystem-coordination/out/GrantFund.sol/GrantFund.json --contract-name GrantFund # Goerli AjnaToken -graph add 0xaadebCF61AA7Da0573b524DE57c67aDa797D46c5 --abi ../ecosystem-coordination/out/AjnaToken.sol/AjnaToken.json --contract-name AjnaToken \ No newline at end of file +graph add 0xaadebCF61AA7Da0573b524DE57c67aDa797D46c5 --abi ../ecosystem-coordination/out/AjnaToken.sol/AjnaToken.json --contract-name AjnaToken + +# Goerli BurnWrapper +graph add 0xE38DFd7aB36806B882bD7332a8aE454f2273D015 --abi ../ecosystem-coordination/out/BurnWrapper.sol/BurnWrappedAjna.json --contract-name BurnWrappedAjna \ No newline at end of file diff --git a/local/docker-compose.yml b/local/docker-compose.yml index 3623893..e90ee03 100644 --- a/local/docker-compose.yml +++ b/local/docker-compose.yml @@ -2,7 +2,7 @@ version: '3.7' services: ajna-testnet: - image: ghcr.io/ajna-finance/ajna-testnet:rc6 + image: ghcr.io/ajna-finance/ajna-testnet:rc7 ports: - 8555:8555 container_name: ajna-testnet-devenv diff --git a/networks.json b/networks.json index 57bff8d..ea3c0c3 100644 --- a/networks.json +++ b/networks.json @@ -23,6 +23,10 @@ "AjnaToken": { "address": "0x9a96ec9B57Fb64FbC60B423d1f4da7691Bd35079", "startBlock": 17622995 + }, + "BurnWrappedAjna": { + "address": "0x936Ab482d6bd111910a42849D3A51Ff80BB0A711", + "startBlock": 17913208 } }, "goerli": { @@ -49,6 +53,10 @@ "AjnaToken": { "address": "0xaadebCF61AA7Da0573b524DE57c67aDa797D46c5", "startBlock": 9297080 + }, + "BurnWrappedAjna": { + "address": "0xE38DFd7aB36806B882bD7332a8aE454f2273D015", + "startBlock": 9445944 } }, "mumbai": { @@ -75,31 +83,38 @@ "AjnaToken": { "address": "0x5BC519744f3f0b324E3D5c031e6D18326FD0e8ce", "startBlock": 38580888 + }, + "BurnWrappedAjna": { + "address": "0x0000000000000000000000000000000000000000", + "startBlock": 38580888 } }, "ganache": { "ERC20PoolFactory": { - "address": "0xD86c4A8b172170Da0d5C0C1F12455bA80Eaa42AD", + "address": "0x9617ABE221F9A9c492D5348be56aef4Db75A692d", "startBlock": 0 }, "ERC721PoolFactory": { - "address": "0x9617ABE221F9A9c492D5348be56aef4Db75A692d", + "address": "0x4f05DA51eAAB00e5812c54e370fB95D4C9c51F21", "startBlock": 0 }, "PositionManager": { - "address": "0x6c5c7fD98415168ada1930d44447790959097482", + "address": "0x6548dF23A854f72335902e58a1e59B50bb3f11F1", "startBlock": 0 }, "RewardsManager": { - "address": "0x6548dF23A854f72335902e58a1e59B50bb3f11F1", + "address": "0xdF7403003a16c49ebA5883bB5890d474794cea5a", "startBlock": 0 }, "GrantFund": { - "address": "0xE340B87CEd1af1AbE1CE8D617c84B7f168e3b18b", + "address": "0x0b3A0ea1Fc7207d3e3ed9973025dA9d0e8fb0F3f", "startBlock": 0 }, "AjnaToken": { "address": "0x25Af17eF4E2E6A4A2CE586C9D25dF87FD84D4a7d" + }, + "BurnWrappedAjna": { + "address": "0xE340B87CEd1af1AbE1CE8D617c84B7f168e3b18b" } } } \ No newline at end of file diff --git a/schema.graphql b/schema.graphql index b4c30d7..7444570 100644 --- a/schema.graphql +++ b/schema.graphql @@ -753,6 +753,20 @@ type RedeemPosition @entity(immutable: true) { transactionHash: Bytes! } + # # # # # # # # # # # # + # BURN WRAPPER EVENTS # + # # # # # # # # # # # # + +type BurnWrap @entity(immutable: true) { + id: Bytes! + wrapper: Bytes! # address + account: Account # null if does not already exist + amount: BigDecimal! # uint256 + blockNumber: BigInt! + blockTimestamp: BigInt! + transactionHash: Bytes! +} + # # # # # # # # # # # # # # # # REWARDS MANAGER ENTITIES # # # # # # # # # # # # # # # # diff --git a/src/burn-wrapped-ajna.ts b/src/burn-wrapped-ajna.ts new file mode 100644 index 0000000..7e41a85 --- /dev/null +++ b/src/burn-wrapped-ajna.ts @@ -0,0 +1,25 @@ +import { + Transfer as TransferEvent +} from "../generated/BurnWrappedAjna/BurnWrappedAjna" +import { BurnWrap } from "../generated/schema" +import { ZERO_ADDRESS } from "./utils/constants" +import { addressToBytes, wadToDecimal } from "./utils/convert" + +export function handleTransfer( + event: TransferEvent +): void { + if (event.params.from == ZERO_ADDRESS) { + let entity = new BurnWrap( + event.transaction.hash.concatI32(event.logIndex.toI32()) + ) + entity.wrapper = event.params.to + entity.account = addressToBytes(event.params.from) + entity.amount = wadToDecimal(event.params.value) + + entity.blockNumber = event.block.number + entity.blockTimestamp = event.block.timestamp + entity.transactionHash = event.transaction.hash + + entity.save() + } +} diff --git a/subgraph.yaml b/subgraph.yaml index 533b673..fb957cb 100644 --- a/subgraph.yaml +++ b/subgraph.yaml @@ -6,8 +6,8 @@ dataSources: name: PositionManager source: abi: PositionManager - address: "0x6c5c7fD98415168ada1930d44447790959097482" - startBlock: 0 + address: "0x23E2EFF19bd50BfCF0364B7dCA01004D5cce41f9" + startBlock: 9289397 mapping: kind: ethereum/events apiVersion: 0.0.7 @@ -46,13 +46,13 @@ dataSources: - event: Transfer(indexed address,indexed address,indexed uint256) handler: handleTransfer file: ./src/position-manager.ts - network: ganache + network: goerli - kind: ethereum name: ERC20PoolFactory source: abi: ERC20PoolFactory - address: "0xD86c4A8b172170Da0d5C0C1F12455bA80Eaa42AD" - startBlock: 0 + address: "0x01Da8a85A5B525D476cA2b51e44fe7087fFafaFF" + startBlock: 9289397 mapping: kind: ethereum/events apiVersion: 0.0.7 @@ -72,13 +72,13 @@ dataSources: - event: PoolCreated(address) handler: handlePoolCreated file: ./src/erc-20-pool-factory.ts - network: ganache + network: goerli - kind: ethereum name: RewardsManager source: abi: RewardsManager - address: "0x6548dF23A854f72335902e58a1e59B50bb3f11F1" - startBlock: 0 + address: "0x994dE190dd763Af3126FcC8EdC139275937d800b" + startBlock: 9289397 mapping: kind: ethereum/events apiVersion: 0.0.7 @@ -107,13 +107,13 @@ dataSources: - event: UpdateExchangeRates(indexed address,indexed address,uint256[],uint256) handler: handleUpdateExchangeRates file: ./src/rewards-manager.ts - network: ganache + network: goerli - kind: ethereum name: ERC721PoolFactory source: abi: ERC721PoolFactory - address: "0x9617ABE221F9A9c492D5348be56aef4Db75A692d" - startBlock: 0 + address: "0x37048D43A65748409B04f4051eEd9480BEf68c82" + startBlock: 9289397 mapping: kind: ethereum/events apiVersion: 0.0.7 @@ -135,13 +135,13 @@ dataSources: - event: PoolCreated(address) handler: handlePoolCreated file: ./src/erc-721-pool-factory.ts - network: ganache + network: goerli - kind: ethereum name: GrantFund source: abi: GrantFund - address: "0xE340B87CEd1af1AbE1CE8D617c84B7f168e3b18b" - startBlock: 0 + address: "0x881b4dFF6C72babA6f5eA60f34A61410c1EA1ec2" + startBlock: 9297080 mapping: kind: ethereum/events apiVersion: 0.0.7 @@ -173,13 +173,14 @@ dataSources: - event: VoteCast(indexed address,uint256,uint8,uint256,string) handler: handleVoteCast file: ./src/grant-fund.ts - network: ganache + network: goerli - kind: ethereum name: AjnaToken - network: ganache + network: goerli source: abi: AjnaToken - address: "0x25Af17eF4E2E6A4A2CE586C9D25dF87FD84D4a7d" + address: "0xaadebCF61AA7Da0573b524DE57c67aDa797D46c5" + startBlock: 9297080 mapping: kind: ethereum/events apiVersion: 0.0.7 @@ -196,6 +197,26 @@ dataSources: - event: DelegateVotesChanged(indexed address,uint256,uint256) handler: handleDelegateVotesChanged file: ./src/ajna-token.ts + - kind: ethereum + name: BurnWrappedAjna + network: goerli + source: + abi: BurnWrappedAjna + address: "0xE38DFd7aB36806B882bD7332a8aE454f2273D015" + startBlock: 9445944 + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + entities: + - BurnWrap + abis: + - name: BurnWrappedAjna + file: ./abis/BurnWrappedAjna.json + eventHandlers: + - event: Transfer(indexed address,indexed address,uint256) + handler: handleTransfer + file: ./src/burn-wrapped-ajna.ts templates: - kind: ethereum name: ERC20Pool @@ -299,7 +320,7 @@ templates: - event: UpdateInterestRate(uint256,uint256) handler: handleUpdateInterestRate file: ./src/erc-20-pool.ts - network: ganache + network: goerli - kind: ethereum name: ERC721Pool source: @@ -407,4 +428,4 @@ templates: - event: UpdateInterestRate(uint256,uint256) handler: handleUpdateInterestRate file: ./src/erc-721-pool.ts - network: ganache + network: goerli