From 22417b41babf7a111fe3149998952f045d3434c2 Mon Sep 17 00:00:00 2001 From: mihaisc Date: Tue, 18 Jan 2022 06:20:02 -0800 Subject: [PATCH] Various fixes (#294) * small cleanup * fix pools * fixes * cleanup * cleanup --- abis/BToken.json | 976 ++++++++++++++++---------------- schema.graphql | 18 +- src/helpers.ts | 2 - src/mappings/dispenser.ts | 1 - src/mappings/pool.ts | 111 ++-- src/mappings/utils/constants.ts | 1 + src/mappings/utils/poolUtils.ts | 20 +- subgraph.rinkeby.yaml | 4 +- subgraph.yaml | 22 +- 9 files changed, 592 insertions(+), 563 deletions(-) diff --git a/abis/BToken.json b/abis/BToken.json index 9487e2e..ff8b3d4 100644 --- a/abis/BToken.json +++ b/abis/BToken.json @@ -1,489 +1,489 @@ { - "_format": "hh-sol-artifact-1", - "contractName": "BToken", - "sourceName": "contracts/pools/balancer/BToken.sol", - "abi": [ - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "src", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "dst", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amt", - "type": "uint256" - } - ], - "name": "Approval", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "src", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "dst", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amt", - "type": "uint256" - } - ], - "name": "Transfer", - "type": "event" - }, - { - "inputs": [], - "name": "BONE", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "BPOW_PRECISION", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "EXIT_FEE", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "INIT_POOL_SUPPLY", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "MAX_BOUND_TOKENS", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "MAX_BPOW_BASE", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "MAX_FEE", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "MAX_IN_RATIO", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "MAX_OUT_RATIO", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "MAX_TOTAL_WEIGHT", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "MAX_WEIGHT", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "MIN_BALANCE", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "MIN_BOUND_TOKENS", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "MIN_BPOW_BASE", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "MIN_FEE", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "MIN_WEIGHT", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "src", - "type": "address" - }, - { - "internalType": "address", - "name": "dst", - "type": "address" - } - ], - "name": "allowance", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dst", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amt", - "type": "uint256" - } - ], - "name": "approve", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "whom", - "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": "dst", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amt", - "type": "uint256" - } - ], - "name": "decreaseApproval", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dst", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amt", - "type": "uint256" - } - ], - "name": "increaseApproval", - "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": "dst", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amt", - "type": "uint256" - } - ], - "name": "transfer", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "src", - "type": "address" - }, - { - "internalType": "address", - "name": "dst", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amt", - "type": "uint256" - } - ], - "name": "transferFrom", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - } - ], - "bytecode": "0x60c0604052601360808190527f42616c616e63657220506f6f6c20546f6b656e0000000000000000000000000060a090815261003e9160039190610089565b506040805180820190915260038082526210941560ea1b602090920191825261006991600491610089565b506005805460ff1916601217905534801561008357600080fd5b5061015d565b82805461009590610122565b90600052602060002090601f0160209004810192826100b757600085556100fd565b82601f106100d057805160ff19168380011785556100fd565b828001600101855582156100fd579182015b828111156100fd5782518255916020019190600101906100e2565b5061010992915061010d565b5090565b5b80821115610109576000815560010161010e565b600181811c9082168061013657607f821691505b6020821081141561015757634e487b7160e01b600052602260045260246000fd5b50919050565b610bf4806200016d6000396000f3fe608060405234801561001057600080fd5b50600436106101a95760003560e01c806395d89b41116100f9578063bc694ea211610097578063d73dd62311610071578063d73dd623146102eb578063dd62ed3e146102fe578063e4a28a52146101ef578063ec0930211461033757600080fd5b8063bc694ea2146102db578063c36596a614610215578063c6580d12146102e357600080fd5b8063b0e0d136116100d3578063b0e0d136146102c3578063b7b800a4146102c3578063ba019dab146102cb578063bc063e1a146102d357600080fd5b806395d89b41146102a0578063992e2a92146102a8578063a9059cbb146102b057600080fd5b806323b872dd1161016657806370a082311161014057806370a082311461025f57806376c7a3c714610288578063867378c5146102905780639381cd2b1461029857600080fd5b806323b872dd14610224578063313ce56714610237578063661884631461024c57600080fd5b806306fdde03146101ae578063095ea7b3146101cc57806309a3bbe4146101ef57806318160ddd14610205578063189d00ca1461020d578063218b538214610215575b600080fd5b6101b661033f565b6040516101c39190610a88565b60405180910390f35b6101df6101da366004610a5e565b6103d1565b60405190151581526020016101c3565b6101f761042b565b6040519081526020016101c3565b6002546101f7565b6101f7610441565b6101f7670de0b6b3a764000081565b6101df610232366004610a22565b610458565b60055460405160ff90911681526020016101c3565b6101df61025a366004610a5e565b6105b1565b6101f761026d3660046109d4565b6001600160a01b031660009081526020819052604090205490565b6101f7610687565b6101f761069c565b6101f76106b3565b6101b66106c6565b6101f76106d5565b6101df6102be366004610a5e565b6106f3565b6101f7600281565b6101f7600181565b6101f7610709565b6101f761071c565b6101f7600081565b6101df6102f9366004610a5e565b61073b565b6101f761030c3660046109ef565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6101f76107ae565b60606003805461034e90610b4d565b80601f016020809104026020016040519081016040528092919081815260200182805461037a90610b4d565b80156103c75780601f1061039c576101008083540402835291602001916103c7565b820191906000526020600020905b8154815290600101906020018083116103aa57829003601f168201915b5050505050905090565b3360008181526001602090815260408083206001600160a01b03871680855292528083208590555191929091600080516020610b9f8339815191529061041a9086815260200190565b60405180910390a350600192915050565b61043e670de0b6b3a76400006032610b17565b81565b61043e6402540be400670de0b6b3a7640000610af5565b6000336001600160a01b038516148061049457506001600160a01b03841660009081526001602090815260408083203384529091529020548211155b6104dd5760405162461bcd60e51b815260206004820152601560248201527422a9292fa12a27a5a2a72fa120a22fa1a0a62622a960591b60448201526064015b60405180910390fd5b6104e88484846107c1565b336001600160a01b0385161480159061052657506001600160a01b038416600090815260016020908152604080832033845290915290205460001914155b156105a7576001600160a01b038416600090815260016020908152604080832033845290915290205461055990836108cb565b6001600160a01b038581166000908152600160209081526040808320338085529083529281902085905551938452918616929091600080516020610b9f833981519152910160405180910390a35b5060019392505050565b3360009081526001602090815260408083206001600160a01b038616845290915281205480831115610606573360009081526001602090815260408083206001600160a01b0388168452909152812055610635565b61061081846108cb565b3360009081526001602090815260408083206001600160a01b03891684529091529020555b3360008181526001602090815260408083206001600160a01b03891680855290835292819020549051908152919291600080516020610b9f833981519152910160405180910390a35060019392505050565b61043e620f4240670de0b6b3a7640000610af5565b61043e64e8d4a51000670de0b6b3a7640000610af5565b61043e670de0b6b3a76400006064610b17565b60606004805461034e90610b4d565b6106e86003670de0b6b3a7640000610af5565b61043e906001610add565b60006107003384846107c1565b50600192915050565b61043e600a670de0b6b3a7640000610af5565b6001610731670de0b6b3a76400006002610b17565b61043e9190610b36565b3360009081526001602090815260408083206001600160a01b03861684529091528120546107699083610928565b3360008181526001602090815260408083206001600160a01b03891680855290835292819020859055519384529092600080516020610b9f833981519152910161041a565b61043e6002670de0b6b3a7640000610af5565b6001600160a01b0383166000908152602081905260409020548111156108205760405162461bcd60e51b815260206004820152601460248201527311549497d25394d551919250d251539517d0905360621b60448201526064016104d4565b6001600160a01b03831660009081526020819052604090205461084390826108cb565b6001600160a01b0380851660009081526020819052604080822093909355908416815220546108729082610928565b6001600160a01b038381166000818152602081815260409182902094909455518481529092918616917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b60008060006108da8585610981565b9150915080156109205760405162461bcd60e51b81526020600482015260116024820152704552525f5355425f554e444552464c4f5760781b60448201526064016104d4565b509392505050565b6000806109358385610add565b90508381101561097a5760405162461bcd60e51b815260206004820152601060248201526f4552525f4144445f4f564552464c4f5760801b60448201526064016104d4565b9392505050565b6000808284106109a0576109958385610b36565b6000915091506109b1565b6109aa8484610b36565b6001915091505b9250929050565b80356001600160a01b03811681146109cf57600080fd5b919050565b6000602082840312156109e657600080fd5b61097a826109b8565b60008060408385031215610a0257600080fd5b610a0b836109b8565b9150610a19602084016109b8565b90509250929050565b600080600060608486031215610a3757600080fd5b610a40846109b8565b9250610a4e602085016109b8565b9150604084013590509250925092565b60008060408385031215610a7157600080fd5b610a7a836109b8565b946020939093013593505050565b600060208083528351808285015260005b81811015610ab557858101830151858201604001528201610a99565b81811115610ac7576000604083870101525b50601f01601f1916929092016040019392505050565b60008219821115610af057610af0610b88565b500190565b600082610b1257634e487b7160e01b600052601260045260246000fd5b500490565b6000816000190483118215151615610b3157610b31610b88565b500290565b600082821015610b4857610b48610b88565b500390565b600181811c90821680610b6157607f821691505b60208210811415610b8257634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fdfe8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925a264697066735822122042315cae853ba051f80739ee06e5213d0a841ec0cbd53c448178f4aeb32d2b9064736f6c63430008070033", - "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106101a95760003560e01c806395d89b41116100f9578063bc694ea211610097578063d73dd62311610071578063d73dd623146102eb578063dd62ed3e146102fe578063e4a28a52146101ef578063ec0930211461033757600080fd5b8063bc694ea2146102db578063c36596a614610215578063c6580d12146102e357600080fd5b8063b0e0d136116100d3578063b0e0d136146102c3578063b7b800a4146102c3578063ba019dab146102cb578063bc063e1a146102d357600080fd5b806395d89b41146102a0578063992e2a92146102a8578063a9059cbb146102b057600080fd5b806323b872dd1161016657806370a082311161014057806370a082311461025f57806376c7a3c714610288578063867378c5146102905780639381cd2b1461029857600080fd5b806323b872dd14610224578063313ce56714610237578063661884631461024c57600080fd5b806306fdde03146101ae578063095ea7b3146101cc57806309a3bbe4146101ef57806318160ddd14610205578063189d00ca1461020d578063218b538214610215575b600080fd5b6101b661033f565b6040516101c39190610a88565b60405180910390f35b6101df6101da366004610a5e565b6103d1565b60405190151581526020016101c3565b6101f761042b565b6040519081526020016101c3565b6002546101f7565b6101f7610441565b6101f7670de0b6b3a764000081565b6101df610232366004610a22565b610458565b60055460405160ff90911681526020016101c3565b6101df61025a366004610a5e565b6105b1565b6101f761026d3660046109d4565b6001600160a01b031660009081526020819052604090205490565b6101f7610687565b6101f761069c565b6101f76106b3565b6101b66106c6565b6101f76106d5565b6101df6102be366004610a5e565b6106f3565b6101f7600281565b6101f7600181565b6101f7610709565b6101f761071c565b6101f7600081565b6101df6102f9366004610a5e565b61073b565b6101f761030c3660046109ef565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6101f76107ae565b60606003805461034e90610b4d565b80601f016020809104026020016040519081016040528092919081815260200182805461037a90610b4d565b80156103c75780601f1061039c576101008083540402835291602001916103c7565b820191906000526020600020905b8154815290600101906020018083116103aa57829003601f168201915b5050505050905090565b3360008181526001602090815260408083206001600160a01b03871680855292528083208590555191929091600080516020610b9f8339815191529061041a9086815260200190565b60405180910390a350600192915050565b61043e670de0b6b3a76400006032610b17565b81565b61043e6402540be400670de0b6b3a7640000610af5565b6000336001600160a01b038516148061049457506001600160a01b03841660009081526001602090815260408083203384529091529020548211155b6104dd5760405162461bcd60e51b815260206004820152601560248201527422a9292fa12a27a5a2a72fa120a22fa1a0a62622a960591b60448201526064015b60405180910390fd5b6104e88484846107c1565b336001600160a01b0385161480159061052657506001600160a01b038416600090815260016020908152604080832033845290915290205460001914155b156105a7576001600160a01b038416600090815260016020908152604080832033845290915290205461055990836108cb565b6001600160a01b038581166000908152600160209081526040808320338085529083529281902085905551938452918616929091600080516020610b9f833981519152910160405180910390a35b5060019392505050565b3360009081526001602090815260408083206001600160a01b038616845290915281205480831115610606573360009081526001602090815260408083206001600160a01b0388168452909152812055610635565b61061081846108cb565b3360009081526001602090815260408083206001600160a01b03891684529091529020555b3360008181526001602090815260408083206001600160a01b03891680855290835292819020549051908152919291600080516020610b9f833981519152910160405180910390a35060019392505050565b61043e620f4240670de0b6b3a7640000610af5565b61043e64e8d4a51000670de0b6b3a7640000610af5565b61043e670de0b6b3a76400006064610b17565b60606004805461034e90610b4d565b6106e86003670de0b6b3a7640000610af5565b61043e906001610add565b60006107003384846107c1565b50600192915050565b61043e600a670de0b6b3a7640000610af5565b6001610731670de0b6b3a76400006002610b17565b61043e9190610b36565b3360009081526001602090815260408083206001600160a01b03861684529091528120546107699083610928565b3360008181526001602090815260408083206001600160a01b03891680855290835292819020859055519384529092600080516020610b9f833981519152910161041a565b61043e6002670de0b6b3a7640000610af5565b6001600160a01b0383166000908152602081905260409020548111156108205760405162461bcd60e51b815260206004820152601460248201527311549497d25394d551919250d251539517d0905360621b60448201526064016104d4565b6001600160a01b03831660009081526020819052604090205461084390826108cb565b6001600160a01b0380851660009081526020819052604080822093909355908416815220546108729082610928565b6001600160a01b038381166000818152602081815260409182902094909455518481529092918616917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b60008060006108da8585610981565b9150915080156109205760405162461bcd60e51b81526020600482015260116024820152704552525f5355425f554e444552464c4f5760781b60448201526064016104d4565b509392505050565b6000806109358385610add565b90508381101561097a5760405162461bcd60e51b815260206004820152601060248201526f4552525f4144445f4f564552464c4f5760801b60448201526064016104d4565b9392505050565b6000808284106109a0576109958385610b36565b6000915091506109b1565b6109aa8484610b36565b6001915091505b9250929050565b80356001600160a01b03811681146109cf57600080fd5b919050565b6000602082840312156109e657600080fd5b61097a826109b8565b60008060408385031215610a0257600080fd5b610a0b836109b8565b9150610a19602084016109b8565b90509250929050565b600080600060608486031215610a3757600080fd5b610a40846109b8565b9250610a4e602085016109b8565b9150604084013590509250925092565b60008060408385031215610a7157600080fd5b610a7a836109b8565b946020939093013593505050565b600060208083528351808285015260005b81811015610ab557858101830151858201604001528201610a99565b81811115610ac7576000604083870101525b50601f01601f1916929092016040019392505050565b60008219821115610af057610af0610b88565b500190565b600082610b1257634e487b7160e01b600052601260045260246000fd5b500490565b6000816000190483118215151615610b3157610b31610b88565b500290565b600082821015610b4857610b48610b88565b500390565b600181811c90821680610b6157607f821691505b60208210811415610b8257634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fdfe8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925a264697066735822122042315cae853ba051f80739ee06e5213d0a841ec0cbd53c448178f4aeb32d2b9064736f6c63430008070033", - "linkReferences": {}, - "deployedLinkReferences": {} - } \ No newline at end of file + "_format": "hh-sol-artifact-1", + "contractName": "BToken", + "sourceName": "contracts/pools/balancer/BToken.sol", + "abi": [ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "inputs": [], + "name": "BONE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "BPOW_PRECISION", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "EXIT_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "INIT_POOL_SUPPLY", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_IN_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_OUT_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_TOTAL_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MIN_BALANCE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MIN_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MIN_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MIN_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MIN_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "internalType": "address", + "name": "dst", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "whom", + "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": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "decreaseApproval", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "increaseApproval", + "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": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + } + ], + "bytecode": "0x60c0604052601360808190527f42616c616e63657220506f6f6c20546f6b656e0000000000000000000000000060a09081526200004091600391906200008f565b506040805180820190915260038082526210941560ea1b60209092019182526200006d916004916200008f565b506005805460ff191660121790553480156200008857600080fd5b5062000172565b8280546200009d9062000135565b90600052602060002090601f016020900481019282620000c157600085556200010c565b82601f10620000dc57805160ff19168380011785556200010c565b828001600101855582156200010c579182015b828111156200010c578251825591602001919060010190620000ef565b506200011a9291506200011e565b5090565b5b808211156200011a57600081556001016200011f565b600181811c908216806200014a57607f821691505b602082108114156200016c57634e487b7160e01b600052602260045260246000fd5b50919050565b610bf480620001826000396000f3fe608060405234801561001057600080fd5b50600436106101a95760003560e01c806395d89b41116100f9578063bc694ea211610097578063d73dd62311610071578063d73dd623146102eb578063dd62ed3e146102fe578063e4a28a52146101ef578063ec0930211461033757600080fd5b8063bc694ea2146102db578063c36596a614610215578063c6580d12146102e357600080fd5b8063b0e0d136116100d3578063b0e0d136146102c3578063b7b800a4146102c3578063ba019dab146102cb578063bc063e1a146102d357600080fd5b806395d89b41146102a0578063992e2a92146102a8578063a9059cbb146102b057600080fd5b806323b872dd1161016657806370a082311161014057806370a082311461025f57806376c7a3c714610288578063867378c5146102905780639381cd2b1461029857600080fd5b806323b872dd14610224578063313ce56714610237578063661884631461024c57600080fd5b806306fdde03146101ae578063095ea7b3146101cc57806309a3bbe4146101ef57806318160ddd14610205578063189d00ca1461020d578063218b538214610215575b600080fd5b6101b661033f565b6040516101c391906109b8565b60405180910390f35b6101df6101da366004610a29565b6103d1565b60405190151581526020016101c3565b6101f761042b565b6040519081526020016101c3565b6002546101f7565b6101f7610441565b6101f7670de0b6b3a764000081565b6101df610232366004610a53565b610458565b60055460405160ff90911681526020016101c3565b6101df61025a366004610a29565b6105b1565b6101f761026d366004610a8f565b6001600160a01b031660009081526020819052604090205490565b6101f7610687565b6101f761069c565b6101f76106b3565b6101b66106c6565b6101f76106d5565b6101df6102be366004610a29565b6106f3565b6101f7600281565b6101f7600181565b6101f7610709565b6101f761071c565b6101f7600081565b6101df6102f9366004610a29565b61073b565b6101f761030c366004610aaa565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6101f76107ae565b60606003805461034e90610add565b80601f016020809104026020016040519081016040528092919081815260200182805461037a90610add565b80156103c75780601f1061039c576101008083540402835291602001916103c7565b820191906000526020600020905b8154815290600101906020018083116103aa57829003601f168201915b5050505050905090565b3360008181526001602090815260408083206001600160a01b03871680855292528083208590555191929091600080516020610b9f8339815191529061041a9086815260200190565b60405180910390a350600192915050565b61043e670de0b6b3a76400006032610b2e565b81565b61043e6402540be400670de0b6b3a7640000610b4d565b6000336001600160a01b038516148061049457506001600160a01b03841660009081526001602090815260408083203384529091529020548211155b6104dd5760405162461bcd60e51b815260206004820152601560248201527422a9292fa12a27a5a2a72fa120a22fa1a0a62622a960591b60448201526064015b60405180910390fd5b6104e88484846107c1565b336001600160a01b0385161480159061052657506001600160a01b038416600090815260016020908152604080832033845290915290205460001914155b156105a7576001600160a01b038416600090815260016020908152604080832033845290915290205461055990836108cb565b6001600160a01b038581166000908152600160209081526040808320338085529083529281902085905551938452918616929091600080516020610b9f833981519152910160405180910390a35b5060019392505050565b3360009081526001602090815260408083206001600160a01b038616845290915281205480831115610606573360009081526001602090815260408083206001600160a01b0388168452909152812055610635565b61061081846108cb565b3360009081526001602090815260408083206001600160a01b03891684529091529020555b3360008181526001602090815260408083206001600160a01b03891680855290835292819020549051908152919291600080516020610b9f833981519152910160405180910390a35060019392505050565b61043e620f4240670de0b6b3a7640000610b4d565b61043e64e8d4a51000670de0b6b3a7640000610b4d565b61043e670de0b6b3a76400006064610b2e565b60606004805461034e90610add565b6106e86003670de0b6b3a7640000610b4d565b61043e906001610b6f565b60006107003384846107c1565b50600192915050565b61043e600a670de0b6b3a7640000610b4d565b6001610731670de0b6b3a76400006002610b2e565b61043e9190610b87565b3360009081526001602090815260408083206001600160a01b03861684529091528120546107699083610928565b3360008181526001602090815260408083206001600160a01b03891680855290835292819020859055519384529092600080516020610b9f833981519152910161041a565b61043e6002670de0b6b3a7640000610b4d565b6001600160a01b0383166000908152602081905260409020548111156108205760405162461bcd60e51b815260206004820152601460248201527311549497d25394d551919250d251539517d0905360621b60448201526064016104d4565b6001600160a01b03831660009081526020819052604090205461084390826108cb565b6001600160a01b0380851660009081526020819052604080822093909355908416815220546108729082610928565b6001600160a01b038381166000818152602081815260409182902094909455518481529092918616917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b60008060006108da8585610981565b9150915080156109205760405162461bcd60e51b81526020600482015260116024820152704552525f5355425f554e444552464c4f5760781b60448201526064016104d4565b509392505050565b6000806109358385610b6f565b90508381101561097a5760405162461bcd60e51b815260206004820152601060248201526f4552525f4144445f4f564552464c4f5760801b60448201526064016104d4565b9392505050565b6000808284106109a0576109958385610b87565b6000915091506109b1565b6109aa8484610b87565b6001915091505b9250929050565b600060208083528351808285015260005b818110156109e5578581018301518582016040015282016109c9565b818111156109f7576000604083870101525b50601f01601f1916929092016040019392505050565b80356001600160a01b0381168114610a2457600080fd5b919050565b60008060408385031215610a3c57600080fd5b610a4583610a0d565b946020939093013593505050565b600080600060608486031215610a6857600080fd5b610a7184610a0d565b9250610a7f60208501610a0d565b9150604084013590509250925092565b600060208284031215610aa157600080fd5b61097a82610a0d565b60008060408385031215610abd57600080fd5b610ac683610a0d565b9150610ad460208401610a0d565b90509250929050565b600181811c90821680610af157607f821691505b60208210811415610b1257634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b6000816000190483118215151615610b4857610b48610b18565b500290565b600082610b6a57634e487b7160e01b600052601260045260246000fd5b500490565b60008219821115610b8257610b82610b18565b500190565b600082821015610b9957610b99610b18565b50039056fe8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925a264697066735822122041ff4e5792568228c9a659d28738fb75ea2da505335d21306fba6d9b736fd72964736f6c634300080a0033", + "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106101a95760003560e01c806395d89b41116100f9578063bc694ea211610097578063d73dd62311610071578063d73dd623146102eb578063dd62ed3e146102fe578063e4a28a52146101ef578063ec0930211461033757600080fd5b8063bc694ea2146102db578063c36596a614610215578063c6580d12146102e357600080fd5b8063b0e0d136116100d3578063b0e0d136146102c3578063b7b800a4146102c3578063ba019dab146102cb578063bc063e1a146102d357600080fd5b806395d89b41146102a0578063992e2a92146102a8578063a9059cbb146102b057600080fd5b806323b872dd1161016657806370a082311161014057806370a082311461025f57806376c7a3c714610288578063867378c5146102905780639381cd2b1461029857600080fd5b806323b872dd14610224578063313ce56714610237578063661884631461024c57600080fd5b806306fdde03146101ae578063095ea7b3146101cc57806309a3bbe4146101ef57806318160ddd14610205578063189d00ca1461020d578063218b538214610215575b600080fd5b6101b661033f565b6040516101c391906109b8565b60405180910390f35b6101df6101da366004610a29565b6103d1565b60405190151581526020016101c3565b6101f761042b565b6040519081526020016101c3565b6002546101f7565b6101f7610441565b6101f7670de0b6b3a764000081565b6101df610232366004610a53565b610458565b60055460405160ff90911681526020016101c3565b6101df61025a366004610a29565b6105b1565b6101f761026d366004610a8f565b6001600160a01b031660009081526020819052604090205490565b6101f7610687565b6101f761069c565b6101f76106b3565b6101b66106c6565b6101f76106d5565b6101df6102be366004610a29565b6106f3565b6101f7600281565b6101f7600181565b6101f7610709565b6101f761071c565b6101f7600081565b6101df6102f9366004610a29565b61073b565b6101f761030c366004610aaa565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6101f76107ae565b60606003805461034e90610add565b80601f016020809104026020016040519081016040528092919081815260200182805461037a90610add565b80156103c75780601f1061039c576101008083540402835291602001916103c7565b820191906000526020600020905b8154815290600101906020018083116103aa57829003601f168201915b5050505050905090565b3360008181526001602090815260408083206001600160a01b03871680855292528083208590555191929091600080516020610b9f8339815191529061041a9086815260200190565b60405180910390a350600192915050565b61043e670de0b6b3a76400006032610b2e565b81565b61043e6402540be400670de0b6b3a7640000610b4d565b6000336001600160a01b038516148061049457506001600160a01b03841660009081526001602090815260408083203384529091529020548211155b6104dd5760405162461bcd60e51b815260206004820152601560248201527422a9292fa12a27a5a2a72fa120a22fa1a0a62622a960591b60448201526064015b60405180910390fd5b6104e88484846107c1565b336001600160a01b0385161480159061052657506001600160a01b038416600090815260016020908152604080832033845290915290205460001914155b156105a7576001600160a01b038416600090815260016020908152604080832033845290915290205461055990836108cb565b6001600160a01b038581166000908152600160209081526040808320338085529083529281902085905551938452918616929091600080516020610b9f833981519152910160405180910390a35b5060019392505050565b3360009081526001602090815260408083206001600160a01b038616845290915281205480831115610606573360009081526001602090815260408083206001600160a01b0388168452909152812055610635565b61061081846108cb565b3360009081526001602090815260408083206001600160a01b03891684529091529020555b3360008181526001602090815260408083206001600160a01b03891680855290835292819020549051908152919291600080516020610b9f833981519152910160405180910390a35060019392505050565b61043e620f4240670de0b6b3a7640000610b4d565b61043e64e8d4a51000670de0b6b3a7640000610b4d565b61043e670de0b6b3a76400006064610b2e565b60606004805461034e90610add565b6106e86003670de0b6b3a7640000610b4d565b61043e906001610b6f565b60006107003384846107c1565b50600192915050565b61043e600a670de0b6b3a7640000610b4d565b6001610731670de0b6b3a76400006002610b2e565b61043e9190610b87565b3360009081526001602090815260408083206001600160a01b03861684529091528120546107699083610928565b3360008181526001602090815260408083206001600160a01b03891680855290835292819020859055519384529092600080516020610b9f833981519152910161041a565b61043e6002670de0b6b3a7640000610b4d565b6001600160a01b0383166000908152602081905260409020548111156108205760405162461bcd60e51b815260206004820152601460248201527311549497d25394d551919250d251539517d0905360621b60448201526064016104d4565b6001600160a01b03831660009081526020819052604090205461084390826108cb565b6001600160a01b0380851660009081526020819052604080822093909355908416815220546108729082610928565b6001600160a01b038381166000818152602081815260409182902094909455518481529092918616917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b60008060006108da8585610981565b9150915080156109205760405162461bcd60e51b81526020600482015260116024820152704552525f5355425f554e444552464c4f5760781b60448201526064016104d4565b509392505050565b6000806109358385610b6f565b90508381101561097a5760405162461bcd60e51b815260206004820152601060248201526f4552525f4144445f4f564552464c4f5760801b60448201526064016104d4565b9392505050565b6000808284106109a0576109958385610b87565b6000915091506109b1565b6109aa8484610b87565b6001915091505b9250929050565b600060208083528351808285015260005b818110156109e5578581018301518582016040015282016109c9565b818111156109f7576000604083870101525b50601f01601f1916929092016040019392505050565b80356001600160a01b0381168114610a2457600080fd5b919050565b60008060408385031215610a3c57600080fd5b610a4583610a0d565b946020939093013593505050565b600080600060608486031215610a6857600080fd5b610a7184610a0d565b9250610a7f60208501610a0d565b9150604084013590509250925092565b600060208284031215610aa157600080fd5b61097a82610a0d565b60008060408385031215610abd57600080fd5b610ac683610a0d565b9150610ad460208401610a0d565b90509250929050565b600181811c90821680610af157607f821691505b60208210811415610b1257634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b6000816000190483118215151615610b4857610b48610b18565b500290565b600082610b6a57634e487b7160e01b600052601260045260246000fd5b500490565b60008219821115610b8257610b82610b18565b500190565b600082821015610b9957610b99610b18565b50039056fe8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925a264697066735822122041ff4e5792568228c9a659d28738fb75ea2da505335d21306fba6d9b736fd72964736f6c634300080a0033", + "linkReferences": {}, + "deployedLinkReferences": {} +} \ No newline at end of file diff --git a/schema.graphql b/schema.graphql index 8e111a3..fef8183 100644 --- a/schema.graphql +++ b/schema.graphql @@ -167,12 +167,12 @@ type Pool @entity { "block number when it was created" block: Int - shares: [PoolShares!] @derivedFrom(field: "pool") + shares: [PoolShare!] @derivedFrom(field: "pool") transactions: [PoolTransaction!] @derivedFrom(field: "pool") } # we will need to track pool share tx between users - bpool transfer tx event -type PoolShares @entity { +type PoolShare @entity { "poolAddress + userAddress" id: ID! user: User! @@ -197,7 +197,7 @@ type PoolTransaction @entity { type: PoolTransactionType! "number of shares transfered" - sharesTransferAmount: BigDecimal + sharesTransferAmount: BigDecimal! "pool fee value, fee goes to all liquidity providers : SWAP, JOIN , EXIT" poolFee: BigDecimal! @@ -220,15 +220,15 @@ type PoolTransaction @entity { gasPrice: BigDecimal! "base tokens transfered" - baseToken: TokenValuePair + baseToken: Token - "number of tokens transfered" + "number of base tokens transfered, if value is negative it means it was removed" baseTokenValue: BigDecimal - "datatokens transfered , if value is negative it means it was removed" - datatoken: TokenValuePair + "datatokens transfered" + datatoken: Token - "number of tokens transfered, if value is negative it means it was removed" + "number of datatokens transfered, if value is negative it means it was removed" datatokenValue: BigDecimal } @@ -273,7 +273,7 @@ type TokenTransaction @entity { type User @entity { id: ID! - sharesOwned: [PoolShares!] @derivedFrom(field: "user") + sharesOwned: [PoolShare!] @derivedFrom(field: "user") tokenBalancesOwned: [TokenValuePair!] tokensOwned: [Token!] @derivedFrom(field: "minter") poolTransactions: [PoolTransaction!] @derivedFrom(field: "user") diff --git a/src/helpers.ts b/src/helpers.ts index c404399..68ccfb8 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -1,5 +1,3 @@ - - // export function getGlobalStats(): Global { // let gStats: Global | null = Global.load('1') // if (gStats == null) { diff --git a/src/mappings/dispenser.ts b/src/mappings/dispenser.ts index 5dc4a03..c4730f1 100644 --- a/src/mappings/dispenser.ts +++ b/src/mappings/dispenser.ts @@ -1,4 +1,3 @@ -import { log } from '@graphprotocol/graph-ts' import { DispenserActivated, DispenserAllowedSwapperChanged, diff --git a/src/mappings/pool.ts b/src/mappings/pool.ts index ad66ccf..5598571 100644 --- a/src/mappings/pool.ts +++ b/src/mappings/pool.ts @@ -1,21 +1,19 @@ import { log } from '@graphprotocol/graph-ts' -import { PoolTransaction } from '../@types/schema' import { - LOG_BPT, LOG_EXIT, LOG_JOIN, LOG_SETUP, LOG_SWAP } from '../@types/templates/BPool/BPool' import { Transfer } from '../@types/templates/BPool/BToken' -import { integer, PoolTransactionType } from './utils/constants' +import { integer, PoolTransactionType, ZERO_ADDRESS } from './utils/constants' import { weiToDecimal } from './utils/generic' import { getGlobalStats } from './utils/globalUtils' import { calcSpotPrice, getPool, getPoolTransaction, - getPoolShares, + getPoolShare, getPoolSnapshot } from './utils/poolUtils' import { getToken } from './utils/tokenUtils' @@ -183,7 +181,7 @@ export function handleSwap(event: LOG_SWAP): void { // setup is just to set token weight(it will mostly be 50:50) and spotPrice export function handleSetup(event: LOG_SETUP): void { - log.warning('new Pool ', []) + log.warning('new Pool from {} ', [event.transaction.from.toHexString()]) const pool = getPool(event.address.toHex()) pool.controller = event.params.caller.toHexString() @@ -211,12 +209,21 @@ export function handleSetup(event: LOG_SETUP): void { ) pool.spotPrice = spotPrice pool.isFinalized = true - const poolTx = PoolTransaction.load(event.transaction.hash.toHex()) - if (poolTx) { - poolTx.type = PoolTransactionType.SETUP - poolTx.save() - } + // TODO: proper tx , add baseToken, datatoken + const fromUser = getUser(event.transaction.from.toHexString()) + const poolTx = getPoolTransaction( + event, + fromUser.id, + PoolTransactionType.SETUP + ) + poolTx.type = PoolTransactionType.SETUP + poolTx.baseToken = token.id + poolTx.datatoken = datatoken.id + const poolSnapshot = getPoolSnapshot(pool.id, event.block.timestamp.toI32()) + poolSnapshot.spotPrice = spotPrice + poolTx.save() + poolSnapshot.save() const globalStats = getGlobalStats() globalStats.poolCount = globalStats.poolCount + 1 globalStats.save() @@ -224,42 +231,60 @@ export function handleSetup(event: LOG_SETUP): void { datatoken.save() } -export function handleBpt(event: LOG_BPT): void { - const pool = getPool(event.address.toHex()) - const poolShares = getPoolShares(pool.id, event.transaction.from.toHex()) - const poolTx = PoolTransaction.load(event.transaction.hash.toHex()) - // TODO: should we return here if null? theoretically this should not be null since LOG_BPT is after the other events - if (!poolTx) return - - const decimalBpt = weiToDecimal(event.params.bptAmount.toBigDecimal(), 18) - - // for some reason switch is broken so reverting to good old if - if (poolTx.type === PoolTransactionType.JOIN) { - poolShares.shares = poolShares.shares.plus(decimalBpt) - pool.totalShares.plus(decimalBpt) - } - if (poolTx.type === PoolTransactionType.EXIT) { - poolShares.shares = poolShares.shares.minus(decimalBpt) - pool.totalShares.minus(decimalBpt) - } - - poolShares.shares = weiToDecimal(event.params.bptAmount.toBigDecimal(), 18) - - pool.save() - poolShares.save() -} - export function handlerBptTransfer(event: Transfer): void { - const fromUser = getPoolShares( - event.address.toHex(), - event.params.src.toHex() + const fromAddress = event.params.src.toHexString() + const toAddress = event.params.dst.toHexString() + const poolAddress = event.address.toHex() + const caller = getUser(event.transaction.from.toHex()) + const poolTx = getPoolTransaction(event, caller.id, PoolTransactionType.SWAP) + const poolSnapshot = getPoolSnapshot( + poolAddress, + event.block.timestamp.toI32() ) - const toUser = getPoolShares(event.address.toHex(), event.params.dst.toHex()) + log.warning('bpt transfer tx: {} from: {} | to {} | ammount {} ', [ + event.transaction.hash.toHex(), + fromAddress, + toAddress, + event.params.amt.toString() + ]) + + // btoken has 18 decimals const ammount = weiToDecimal(event.params.amt.toBigDecimal(), 18) - fromUser.shares = fromUser.shares.minus(ammount) - toUser.shares = toUser.shares.plus(ammount) + if (fromAddress != ZERO_ADDRESS && toAddress != ZERO_ADDRESS) { + poolTx.sharesTransferAmount = poolTx.sharesTransferAmount.plus(ammount) + } - fromUser.save() - toUser.save() + if (fromAddress == ZERO_ADDRESS) { + // add total + const pool = getPool(poolAddress) + pool.totalShares = pool.totalShares.plus(ammount) + + // check tx? + poolSnapshot.totalShares = pool.totalShares + pool.save() + } else { + if (poolAddress != fromAddress) { + const fromUser = getPoolShare(poolAddress, fromAddress) + fromUser.shares = fromUser.shares.minus(ammount) + fromUser.save() + } + } + + if (toAddress == ZERO_ADDRESS) { + // remove + const pool = getPool(poolAddress) + pool.totalShares = pool.totalShares.minus(ammount) + poolSnapshot.totalShares = pool.totalShares + pool.save() + } else { + if (poolAddress != toAddress) { + const toUser = getPoolShare(poolAddress, toAddress) + toUser.shares = toUser.shares.plus(ammount) + toUser.save() + } + } + + poolTx.save() + poolSnapshot.save() } diff --git a/src/mappings/utils/constants.ts b/src/mappings/utils/constants.ts index 706ff52..895b18b 100644 --- a/src/mappings/utils/constants.ts +++ b/src/mappings/utils/constants.ts @@ -1,6 +1,7 @@ import { BigDecimal, BigInt } from '@graphprotocol/graph-ts' export const ENABLE_DEBUG = true +export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' export const DAY = 24 * 60 * 60 diff --git a/src/mappings/utils/poolUtils.ts b/src/mappings/utils/poolUtils.ts index b0c0a24..95ae05a 100644 --- a/src/mappings/utils/poolUtils.ts +++ b/src/mappings/utils/poolUtils.ts @@ -1,15 +1,16 @@ import { Address, BigDecimal, ethereum } from '@graphprotocol/graph-ts' import { Pool, - PoolShares, + PoolShare, PoolSnapshot, PoolTransaction } from '../../@types/schema' import { BPool } from '../../@types/templates/BPool/BPool' import { DAY, decimal, integer } from './constants' import { gweiToEth, weiToDecimal } from './generic' +import { getUser } from './userUtils' -export function getPoolSharesId( +export function getPoolShareId( poolAddress: string, userAddress: string ): string { @@ -42,15 +43,18 @@ export function getPoolTransaction( return poolTx } -export function getPoolShares( +export function getPoolShare( poolAddress: string, userAddress: string -): PoolShares { - let poolShares = PoolShares.load(getPoolSharesId(poolAddress, userAddress)) - if (poolShares === null) { - poolShares = new PoolShares(getPoolSharesId(poolAddress, userAddress)) +): PoolShare { + let poolShare = PoolShare.load(getPoolShareId(poolAddress, userAddress)) + if (poolShare === null) { + poolShare = new PoolShare(getPoolShareId(poolAddress, userAddress)) + poolShare.user = getUser(userAddress).id + poolShare.pool = poolAddress + poolShare.save() } - return poolShares + return poolShare } export function getPool(poolAddress: string): Pool { diff --git a/subgraph.rinkeby.yaml b/subgraph.rinkeby.yaml index bd8d8c8..cadbded 100644 --- a/subgraph.rinkeby.yaml +++ b/subgraph.rinkeby.yaml @@ -174,8 +174,8 @@ templates: handler: handleExit - event: LOG_SETUP(indexed address,indexed address,uint256,uint256,indexed address,uint256,uint256) handler: handleSetup - - + - event: Transfer(indexed address,indexed address,uint256) + handler: handlerBptTransfer - name: ERC721Template kind: ethereum/contract network: rinkeby diff --git a/subgraph.yaml b/subgraph.yaml index d838b6e..cadbded 100644 --- a/subgraph.yaml +++ b/subgraph.yaml @@ -8,9 +8,9 @@ dataSources: name: ERC721Factory network: rinkeby source: - address: '0xe4B39C90355899DB8f625D879B44Fa9C5Cdde550' + address: '0x15087E3E9eAAAb37d32d9D06Fa4000309BD7Ee6D' abi: ERC721Factory - startBlock: 9984045 + startBlock: 9989814 mapping: kind: ethereum/events apiVersion: 0.0.6 @@ -30,9 +30,9 @@ dataSources: name: FixedRateExchange network: rinkeby source: - address: '0x7084f7353bB7cfc92A65e7d23987Cb5D1A3Fb9b2' + address: '0xB5f34bd0B3E8e59447fD5a750F2dE4262BABE66C' abi: FixedRateExchange - startBlock: 9984045 + startBlock: 9989814 mapping: kind: ethereum/events apiVersion: 0.0.6 @@ -64,9 +64,9 @@ dataSources: name: Dispenser network: rinkeby source: - address: '0xa8fFDd525835795C940370FB816f82a5F7F5F860' + address: '0x17b1760c20eAc7A2656412412F6020e6c00b78BD' abi: Dispenser - startBlock: 9984045 + startBlock: 9989814 mapping: kind: ethereum/events apiVersion: 0.0.6 @@ -95,9 +95,9 @@ dataSources: name: FactoryRouter network: rinkeby source: - address: '0xAB4FD86E4aaAb2243463Cbe92CD5194C1593fb9A' + address: '0x31066E8eFe281C755dC21d828bdF30363D055baB' abi: FactoryRouter - startBlock: 9984045 + startBlock: 9989814 mapping: kind: ethereum/events apiVersion: 0.0.6 @@ -163,6 +163,8 @@ templates: file: ./abis/BToken.json - name: BMath file: ./abis/BMath.json + - name: ERC20 + file: ./abis/ERC20.json eventHandlers: - event: LOG_SWAP(indexed address,indexed address,indexed address,uint256,uint256,uint256) handler: handleSwap @@ -172,8 +174,8 @@ templates: handler: handleExit - event: LOG_SETUP(indexed address,indexed address,uint256,uint256,indexed address,uint256,uint256) handler: handleSetup - - + - event: Transfer(indexed address,indexed address,uint256) + handler: handlerBptTransfer - name: ERC721Template kind: ethereum/contract network: rinkeby