From 23a07ebb7a5c63fe3fa283d1b97d1ac67af6b9ec Mon Sep 17 00:00:00 2001 From: Amrit Jain Date: Sat, 9 Sep 2023 11:37:13 +0530 Subject: [PATCH] feat: add fees --- .../abis/kwenta/PerpsV2MarketSettings.json | 1638 +++++++++++++++++ .../kwenta-optimism/configurations.json | 17 + .../config/templates/kwenta.template.yaml | 23 +- subgraphs/kwenta/schema.graphql | 25 + subgraphs/kwenta/src/mappings/handlers.ts | 54 +- subgraphs/kwenta/src/mappings/helpers.ts | 11 + subgraphs/kwenta/src/sdk/util/constants.ts | 30 +- 7 files changed, 1792 insertions(+), 6 deletions(-) create mode 100644 subgraphs/kwenta/abis/kwenta/PerpsV2MarketSettings.json diff --git a/subgraphs/kwenta/abis/kwenta/PerpsV2MarketSettings.json b/subgraphs/kwenta/abis/kwenta/PerpsV2MarketSettings.json new file mode 100644 index 0000000000..73e99c9346 --- /dev/null +++ b/subgraphs/kwenta/abis/kwenta/PerpsV2MarketSettings.json @@ -0,0 +1,1638 @@ +[ + { + "inputs": [ + { + "internalType": "address", + "name": "_owner", + "type": "address" + }, + { + "internalType": "address", + "name": "_resolver", + "type": "address" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "bytes32", + "name": "name", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "address", + "name": "destination", + "type": "address" + } + ], + "name": "CacheUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "keeperFee", + "type": "uint256" + } + ], + "name": "KeeperLiquidationFeeUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "bps", + "type": "uint256" + } + ], + "name": "LiquidationBufferRatioUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "bps", + "type": "uint256" + } + ], + "name": "LiquidationFeeRatioUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "sUSD", + "type": "uint256" + } + ], + "name": "MaxKeeperFeeUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "minMargin", + "type": "uint256" + } + ], + "name": "MinInitialMarginUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "sUSD", + "type": "uint256" + } + ], + "name": "MinKeeperFeeUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "oldOwner", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnerChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnerNominated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "marketKey", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "parameter", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "ParameterUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "marketKey", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "parameter", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "bytes32", + "name": "value", + "type": "bytes32" + } + ], + "name": "ParameterUpdatedBytes32", + "type": "event" + }, + { + "constant": true, + "inputs": [], + "name": "CONTRACT_NAME", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "acceptOwnership", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "delayedOrderConfirmWindow", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "isResolverCached", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "keeperLiquidationFee", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "liquidationBufferRatio", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "liquidationFeeRatio", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "liquidationPremiumMultiplier", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "makerFee", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "makerFeeDelayedOrder", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "makerFeeOffchainDelayedOrder", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "maxDelayTimeDelta", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "maxFundingVelocity", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "maxKeeperFee", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "maxLeverage", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "maxLiquidationDelta", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "maxMarketValue", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "maxPD", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "minDelayTimeDelta", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "minInitialMargin", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "minKeeperFee", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "nextPriceConfirmWindow", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "_owner", + "type": "address" + } + ], + "name": "nominateNewOwner", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "nominatedOwner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "offchainDelayedOrderMaxAge", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "offchainDelayedOrderMinAge", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "offchainMarketKey", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "offchainPriceDivergence", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "parameters", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "takerFee", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "makerFee", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "takerFeeDelayedOrder", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "makerFeeDelayedOrder", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "takerFeeOffchainDelayedOrder", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "makerFeeOffchainDelayedOrder", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxLeverage", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxMarketValue", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxFundingVelocity", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "skewScale", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nextPriceConfirmWindow", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "delayedOrderConfirmWindow", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minDelayTimeDelta", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxDelayTimeDelta", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "offchainDelayedOrderMinAge", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "offchainDelayedOrderMaxAge", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "offchainMarketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "offchainPriceDivergence", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidationPremiumMultiplier", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidationBufferRatio", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxLiquidationDelta", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxPD", + "type": "uint256" + } + ], + "internalType": "struct IPerpsV2MarketSettings.Parameters", + "name": "", + "type": "tuple" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "rebuildCache", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "resolver", + "outputs": [ + { + "internalType": "contract AddressResolver", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "resolverAddressesRequired", + "outputs": [ + { + "internalType": "bytes32[]", + "name": "addresses", + "type": "bytes32[]" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_delayedOrderConfirmWindow", + "type": "uint256" + } + ], + "name": "setDelayedOrderConfirmWindow", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "uint256", + "name": "_keeperFee", + "type": "uint256" + } + ], + "name": "setKeeperLiquidationFee", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_ratio", + "type": "uint256" + } + ], + "name": "setLiquidationBufferRatio", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "uint256", + "name": "_ratio", + "type": "uint256" + } + ], + "name": "setLiquidationFeeRatio", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_liquidationPremiumMultiplier", + "type": "uint256" + } + ], + "name": "setLiquidationPremiumMultiplier", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_makerFee", + "type": "uint256" + } + ], + "name": "setMakerFee", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_makerFeeDelayedOrder", + "type": "uint256" + } + ], + "name": "setMakerFeeDelayedOrder", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_makerFeeOffchainDelayedOrder", + "type": "uint256" + } + ], + "name": "setMakerFeeOffchainDelayedOrder", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_maxDelayTimeDelta", + "type": "uint256" + } + ], + "name": "setMaxDelayTimeDelta", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_maxFundingVelocity", + "type": "uint256" + } + ], + "name": "setMaxFundingVelocity", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "uint256", + "name": "_sUSD", + "type": "uint256" + } + ], + "name": "setMaxKeeperFee", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_maxLeverage", + "type": "uint256" + } + ], + "name": "setMaxLeverage", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_maxLiquidationDelta", + "type": "uint256" + } + ], + "name": "setMaxLiquidationDelta", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_maxMarketValue", + "type": "uint256" + } + ], + "name": "setMaxMarketValue", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_maxPD", + "type": "uint256" + } + ], + "name": "setMaxPD", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_minDelayTimeDelta", + "type": "uint256" + } + ], + "name": "setMinDelayTimeDelta", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "uint256", + "name": "_minMargin", + "type": "uint256" + } + ], + "name": "setMinInitialMargin", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "uint256", + "name": "_sUSD", + "type": "uint256" + } + ], + "name": "setMinKeeperFee", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_nextPriceConfirmWindow", + "type": "uint256" + } + ], + "name": "setNextPriceConfirmWindow", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_offchainDelayedOrderMaxAge", + "type": "uint256" + } + ], + "name": "setOffchainDelayedOrderMaxAge", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_offchainDelayedOrderMinAge", + "type": "uint256" + } + ], + "name": "setOffchainDelayedOrderMinAge", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "_offchainMarketKey", + "type": "bytes32" + } + ], + "name": "setOffchainMarketKey", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_offchainPriceDivergence", + "type": "uint256" + } + ], + "name": "setOffchainPriceDivergence", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "takerFee", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "makerFee", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "takerFeeDelayedOrder", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "makerFeeDelayedOrder", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "takerFeeOffchainDelayedOrder", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "makerFeeOffchainDelayedOrder", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxLeverage", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxMarketValue", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxFundingVelocity", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "skewScale", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nextPriceConfirmWindow", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "delayedOrderConfirmWindow", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minDelayTimeDelta", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxDelayTimeDelta", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "offchainDelayedOrderMinAge", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "offchainDelayedOrderMaxAge", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "offchainMarketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "offchainPriceDivergence", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidationPremiumMultiplier", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidationBufferRatio", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxLiquidationDelta", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxPD", + "type": "uint256" + } + ], + "internalType": "struct IPerpsV2MarketSettings.Parameters", + "name": "_parameters", + "type": "tuple" + } + ], + "name": "setParameters", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_skewScale", + "type": "uint256" + } + ], + "name": "setSkewScale", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_takerFee", + "type": "uint256" + } + ], + "name": "setTakerFee", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_takerFeeDelayedOrder", + "type": "uint256" + } + ], + "name": "setTakerFeeDelayedOrder", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_takerFeeOffchainDelayedOrder", + "type": "uint256" + } + ], + "name": "setTakerFeeOffchainDelayedOrder", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "skewScale", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "takerFee", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "takerFeeDelayedOrder", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "takerFeeOffchainDelayedOrder", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + } +] diff --git a/subgraphs/kwenta/protocols/kwenta/config/deployments/kwenta-optimism/configurations.json b/subgraphs/kwenta/protocols/kwenta/config/deployments/kwenta-optimism/configurations.json index a32a9bec4a..d237170e69 100644 --- a/subgraphs/kwenta/protocols/kwenta/config/deployments/kwenta-optimism/configurations.json +++ b/subgraphs/kwenta/protocols/kwenta/config/deployments/kwenta-optimism/configurations.json @@ -25,6 +25,23 @@ "startBlock": 92005505 } ], + "marketSettings": [ + { + "name": "PerpsV2MarketSettings1", + "address": "0xd442Dc2Ac1f3cA1C86C8329246e47Ca0C91D0471", + "startBlock": 52456606 + }, + { + "name": "PerpsV2MarketSettings2", + "address": "0x09793Aad1518B8d8CC72FDd356479E3CBa7B4Ad1", + "startBlock": 71308622 + }, + { + "name": "PerpsV2MarketSettings3", + "address": "0x649F44CAC3276557D03223Dbf6395Af65b11c11c", + "startBlock": 86524289 + } + ], "graftEnabled": false, "subgraphId": "QmfHRGh3tC4yb2bBRn5A6ctytG32Jwfi9eNo76EFjiWyrf", "graftStartBlock": 15217959 diff --git a/subgraphs/kwenta/protocols/kwenta/config/templates/kwenta.template.yaml b/subgraphs/kwenta/protocols/kwenta/config/templates/kwenta.template.yaml index 1d25793110..a647448f92 100644 --- a/subgraphs/kwenta/protocols/kwenta/config/templates/kwenta.template.yaml +++ b/subgraphs/kwenta/protocols/kwenta/config/templates/kwenta.template.yaml @@ -91,7 +91,28 @@ dataSources: file: ./src/mappings/handlers.ts {{/smartMarginFactory}} - + {{#marketSettings}} + - kind: ethereum/contract + name: {{ name }} + network: {{ network }} + source: + address: "{{ address }}" + abi: PerpsV2MarketSettings + startBlock: {{ startBlock }} + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + entities: + - DerivPerpProtocol + abis: + - name: PerpsV2MarketSettings + file: ./abis/kwenta/PerpsV2MarketSettings.json + eventHandlers: + - event: 'ParameterUpdated(indexed bytes32,indexed bytes32,uint256)' + handler: 'handleParameterUpdated' + file: ./src/mappings/handlers.ts + {{/marketSettings}} templates: - kind: ethereum/contract name: PerpsV2Market diff --git a/subgraphs/kwenta/schema.graphql b/subgraphs/kwenta/schema.graphql index 1ebbf33b8d..1640bad0b3 100644 --- a/subgraphs/kwenta/schema.graphql +++ b/subgraphs/kwenta/schema.graphql @@ -116,6 +116,24 @@ enum LiquidityPoolFeeType { " One-time fee charged by the protocol (e.g. GMX charges a fee from certain pools with withdrawing) during withdrawal, in percentages of the withdrawal token " WITHDRAWAL_FEE + + " Fee charged by Kwenta from Taker Orders " + DYNAMIC_TAKER_FEE + + " Fee charged by Kwenta from Taker Delayed Orders " + DYNAMIC_TAKER_DELAYED_FEE + + " Fee charged by Kwenta from Taker Delayed Offchain Orders " + DYNAMIC_TAKER_DELAYED_OFFCHAIN_FEE + + " Fee charged by Kwenta from Maker Orders " + DYNAMIC_MAKER_FEE + + " Fee charged by Kwenta from Maker Delayed Orders " + DYNAMIC_MAKER_DELAYED_FEE + + " Fee charged by Kwenta from Maker Delayed Offchain Orders " + DYNAMIC_MAKER_DELAYED_OFFCHAIN_FEE } type LiquidityPoolFee @entity @regularPolling { @@ -2014,3 +2032,10 @@ type _FundingRate @entity { "Funding Amount" funding: BigInt! } + +type _MarketKey @entity { + "Market Key" + id: Bytes! + + market: LiquidityPool! +} diff --git a/subgraphs/kwenta/src/mappings/handlers.ts b/subgraphs/kwenta/src/mappings/handlers.ts index 37e57e37d7..93d8fcdc78 100644 --- a/subgraphs/kwenta/src/mappings/handlers.ts +++ b/subgraphs/kwenta/src/mappings/handlers.ts @@ -6,6 +6,7 @@ import { _SmartMarginAccount, Token, _FundingRate, + _MarketKey, } from "../../generated/schema"; import { _ERC20 } from "../../generated/FuturesMarketManager2/_ERC20"; import { @@ -28,6 +29,9 @@ import { PositionSide, BIGINT_ZERO, BIGINT_TEN_TO_EIGHTEENTH, + LiquidityPoolFeeType, + ParameterKeys, + BIGDECIMAL_ZERO, } from "../sdk/util/constants"; import { MarketAdded as MarketAddedEvent } from "../../generated/FuturesMarketManager2/FuturesMarketManager"; import { @@ -42,8 +46,12 @@ import { getFundingRateId, updateOpenInterest, liquidation, + loadMarketKey, } from "./helpers"; import { NewAccount as NewSmartMarginAccountEvent } from "../../generated/SmartMarginFactory1/SmartMarginFactory"; + +import { ParameterUpdated as ParameterUpdatedEvent } from "../../generated/PerpsV2MarketSettings1/PerpsV2MarketSettings"; + import { TransactionType } from "../sdk/protocols/perpfutures/enums"; class Pricer implements TokenPricer { @@ -91,7 +99,6 @@ const conf = new ProtocolConfig( We just checks if it is a market, and then stores it */ export function handleMarketAdded(event: MarketAddedEvent): void { - const marketKey = event.params.marketKey.toString(); const sdk = SDK.initializeFromEvent( conf, new Pricer(), @@ -100,10 +107,10 @@ export function handleMarketAdded(event: MarketAddedEvent): void { ); // check that it's a v1 market before adding - if (marketKey.endsWith("PERP")) { - log.info("New market added: {}", [marketKey]); - + if (event.params.marketKey.toString().endsWith("PERP")) { const pool = sdk.Pools.loadPool(event.params.market); + const marketKey = loadMarketKey(event.params.marketKey, pool).toString(); + if (!pool.isInitialized) { const token = sdk.Tokens.getOrCreateToken( NetworkConfigs.getSUSDAddress() @@ -111,6 +118,26 @@ export function handleMarketAdded(event: MarketAddedEvent): void { pool.initialize(marketKey, marketKey, [token], null, "chainlink"); } + pool.setPoolFee(LiquidityPoolFeeType.DYNAMIC_TAKER_FEE, BIGDECIMAL_ZERO); + pool.setPoolFee( + LiquidityPoolFeeType.DYNAMIC_TAKER_DELAYED_FEE, + BIGDECIMAL_ZERO + ); + pool.setPoolFee( + LiquidityPoolFeeType.DYNAMIC_TAKER_DELAYED_OFFCHAIN_FEE, + BIGDECIMAL_ZERO + ); + pool.setPoolFee(LiquidityPoolFeeType.DYNAMIC_MAKER_FEE, null); + pool.setPoolFee(LiquidityPoolFeeType.DYNAMIC_MAKER_DELAYED_FEE, null); + pool.setPoolFee( + LiquidityPoolFeeType.DYNAMIC_MAKER_DELAYED_OFFCHAIN_FEE, + BIGDECIMAL_ZERO + ); + pool.setPoolFee( + LiquidityPoolFeeType.DYNAMIC_MAKER_DELAYED_OFFCHAIN_FEE, + BIGDECIMAL_ZERO + ); + // perps v2 market PerpsV2Market.create(event.params.market); } @@ -368,3 +395,22 @@ export function handlePositionLiquidated(event: PositionLiquidatedEvent): void { sdk ); } + +export function handleParameterUpdated(event: ParameterUpdatedEvent): void { + const sdk = SDK.initializeFromEvent( + conf, + new Pricer(), + new TokenInit(), + event + ); + + const marketKey = _MarketKey.load(event.params.marketKey); + if (marketKey != null) { + const paramKey = event.params.parameter.toString(); + const poolFee = ParameterKeys.get(paramKey); + if (poolFee != null) { + const market = sdk.Pools.loadPool(marketKey.market); + market.setPoolFee(poolFee!, bigIntToBigDecimal(event.params.value)); + } + } +} diff --git a/subgraphs/kwenta/src/mappings/helpers.ts b/subgraphs/kwenta/src/mappings/helpers.ts index b36f09c09b..96eac206e9 100644 --- a/subgraphs/kwenta/src/mappings/helpers.ts +++ b/subgraphs/kwenta/src/mappings/helpers.ts @@ -12,6 +12,7 @@ import { BIGINT_ZERO } from "../sdk/util/constants"; import { Token, _FundingRate, + _MarketKey, _SmartMarginAccount, } from "../../generated/schema"; import { SDK } from "../sdk/protocols/perpfutures"; @@ -128,3 +129,13 @@ export function updateOpenInterest( pool.setLongOpenInterest(longOpenInterstAmount, lastPrice); pool.setShortOpenInterest(shortOpenInterstAmount, lastPrice); } + +export function loadMarketKey(marketKey: Bytes, pool: Pool): Bytes { + let marketKeyEntity = _MarketKey.load(marketKey); + if (marketKeyEntity == null) { + marketKeyEntity = new _MarketKey(marketKey); + } + marketKeyEntity.market = pool.getBytesID(); + marketKeyEntity.save(); + return marketKeyEntity.id; +} diff --git a/subgraphs/kwenta/src/sdk/util/constants.ts b/subgraphs/kwenta/src/sdk/util/constants.ts index 185e7bf83d..3ca8c0090b 100644 --- a/subgraphs/kwenta/src/sdk/util/constants.ts +++ b/subgraphs/kwenta/src/sdk/util/constants.ts @@ -1,4 +1,4 @@ -import { BigDecimal, BigInt } from "@graphprotocol/graph-ts"; +import { BigDecimal, BigInt, TypedMap } from "@graphprotocol/graph-ts"; //////////////////////// ///// Schema Enums ///// @@ -116,9 +116,37 @@ export namespace LiquidityPoolFeeType { export const DYNAMIC_LP_FEE = "DYNAMIC_LP_FEE"; export const FIXED_PROTOCOL_FEE = "FIXED_PROTOCOL_FEE"; export const DYNAMIC_PROTOCOL_FEE = "DYNAMIC_PROTOCOL_FEE"; + export const DYNAMIC_TAKER_FEE = "DYNAMIC_TAKER_FEE"; + export const DYNAMIC_TAKER_DELAYED_FEE = "DYNAMIC_TAKER_DELAYED_FEE"; + export const DYNAMIC_TAKER_DELAYED_OFFCHAIN_FEE = + "DYNAMIC_TAKER_DELAYED_OFFCHAIN_FEE"; + export const DYNAMIC_MAKER_FEE = "DYNAMIC_MAKER_FEE"; + export const DYNAMIC_MAKER_DELAYED_FEE = "DYNAMIC_MAKER_DELAYED_FEE"; + export const DYNAMIC_MAKER_DELAYED_OFFCHAIN_FEE = + "DYNAMIC_MAKER_DELAYED_OFFCHAIN_FEE"; } export type LiquidityPoolFeeType = string; +export const ParameterKeys = new TypedMap(); +ParameterKeys.set("takerFee", LiquidityPoolFeeType.DYNAMIC_TAKER_FEE); +ParameterKeys.set( + "takerFeeDelayedOrder", + LiquidityPoolFeeType.DYNAMIC_TAKER_DELAYED_FEE +); +ParameterKeys.set( + "takerFeeOffchainDelayedOrder", + LiquidityPoolFeeType.DYNAMIC_TAKER_DELAYED_OFFCHAIN_FEE +); +ParameterKeys.set("makerFee", LiquidityPoolFeeType.DYNAMIC_MAKER_FEE); +ParameterKeys.set( + "makerFeeDelayedOrder", + LiquidityPoolFeeType.DYNAMIC_MAKER_DELAYED_FEE +); +ParameterKeys.set( + "makerFeeOffchainDelayedOrder", + LiquidityPoolFeeType.DYNAMIC_MAKER_DELAYED_OFFCHAIN_FEE +); + export namespace RewardTokenType { export const DEPOSIT = "DEPOSIT"; export const BORROW = "BORROW";