diff --git a/spot-staking-subgraph/abis/BillBroker.json b/spot-staking-subgraph/abis/BillBroker.json new file mode 100644 index 00000000..ab4ff3a8 --- /dev/null +++ b/spot-staking-subgraph/abis/BillBroker.json @@ -0,0 +1,1691 @@ +[ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [], + "name": "InvalidARBound", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidPerc", + "type": "error" + }, + { + "inputs": [], + "name": "SlippageTooHigh", + "type": "error" + }, + { + "inputs": [], + "name": "UnacceptableSwap", + "type": "error" + }, + { + "inputs": [], + "name": "UnauthorizedCall", + "type": "error" + }, + { + "inputs": [], + "name": "UnexpectedARDelta", + "type": "error" + }, + { + "inputs": [], + "name": "UnexpectedDecimals", + "type": "error" + }, + { + "inputs": [], + "name": "UnreliablePrice", + "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": false, + "internalType": "uint256", + "name": "perpAmtIn", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "usdBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "usdPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpPrice", + "type": "uint256" + } + ], + "indexed": false, + "internalType": "struct ReserveState", + "name": "preOpState", + "type": "tuple" + } + ], + "name": "DepositPerp", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "usdAmtIn", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "usdBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "usdPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpPrice", + "type": "uint256" + } + ], + "indexed": false, + "internalType": "struct ReserveState", + "name": "preOpState", + "type": "tuple" + } + ], + "name": "DepositUSD", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "version", + "type": "uint8" + } + ], + "name": "Initialized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Paused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "perpAmtIn", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "usdBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "usdPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpPrice", + "type": "uint256" + } + ], + "indexed": false, + "internalType": "struct ReserveState", + "name": "preOpState", + "type": "tuple" + } + ], + "name": "SwapPerpsForUSD", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "usdAmtIn", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "usdBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "usdPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpPrice", + "type": "uint256" + } + ], + "indexed": false, + "internalType": "struct ReserveState", + "name": "preOpState", + "type": "tuple" + } + ], + "name": "SwapUSDForPerps", + "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" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Unpaused", + "type": "event" + }, + { + "inputs": [], + "name": "DECIMALS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MINIMUM_LIQUIDITY", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ONE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "arHardBound", + "outputs": [ + { + "internalType": "uint256", + "name": "lower", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upper", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "arSoftBound", + "outputs": [ + { + "internalType": "uint256", + "name": "lower", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upper", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "usdBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "usdPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpPrice", + "type": "uint256" + } + ], + "internalType": "struct ReserveState", + "name": "s", + "type": "tuple" + } + ], + "name": "assetRatio", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "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": [ + { + "internalType": "uint256", + "name": "usdAmtMax", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpAmtMax", + "type": "uint256" + } + ], + "name": "computeMintAmt", + "outputs": [ + { + "internalType": "uint256", + "name": "mintAmt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "usdAmtIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpAmtIn", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "isFirstMint", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "perpAmtIn", + "type": "uint256" + } + ], + "name": "computeMintAmtWithPerp", + "outputs": [ + { + "internalType": "uint256", + "name": "mintAmt", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "perpAmtIn", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "usdBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "usdPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpPrice", + "type": "uint256" + } + ], + "internalType": "struct ReserveState", + "name": "s", + "type": "tuple" + } + ], + "name": "computeMintAmtWithPerp", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "usdAmtIn", + "type": "uint256" + } + ], + "name": "computeMintAmtWithUSD", + "outputs": [ + { + "internalType": "uint256", + "name": "mintAmt", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "usdAmtIn", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "usdBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "usdPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpPrice", + "type": "uint256" + } + ], + "internalType": "struct ReserveState", + "name": "s", + "type": "tuple" + } + ], + "name": "computeMintAmtWithUSD", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "perpAmtIn", + "type": "uint256" + } + ], + "name": "computePerpToUSDSwapAmt", + "outputs": [ + { + "internalType": "uint256", + "name": "usdAmtOut", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "perpAmtIn", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "usdBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "usdPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpPrice", + "type": "uint256" + } + ], + "internalType": "struct ReserveState", + "name": "s", + "type": "tuple" + } + ], + "name": "computePerpToUSDSwapAmt", + "outputs": [ + { + "internalType": "uint256", + "name": "usdAmtOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lpFeeUsdAmt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "protocolFeeUsdAmt", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "arPre", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "arPost", + "type": "uint256" + } + ], + "name": "computePerpToUSDSwapFeePerc", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "burnAmt", + "type": "uint256" + } + ], + "name": "computeRedemptionAmts", + "outputs": [ + { + "internalType": "uint256", + "name": "usdAmtOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpAmtOut", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "usdAmtIn", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "usdBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "usdPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpPrice", + "type": "uint256" + } + ], + "internalType": "struct ReserveState", + "name": "s", + "type": "tuple" + } + ], + "name": "computeUSDToPerpSwapAmt", + "outputs": [ + { + "internalType": "uint256", + "name": "perpAmtOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lpFeePerpAmt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "protocolFeePerpAmt", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "usdAmtIn", + "type": "uint256" + } + ], + "name": "computeUSDToPerpSwapAmt", + "outputs": [ + { + "internalType": "uint256", + "name": "perpAmtOut", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "arPre", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "arPost", + "type": "uint256" + } + ], + "name": "computeUSDToPerpSwapFeePerc", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "subtractedValue", + "type": "uint256" + } + ], + "name": "decreaseAllowance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "usdAmtMax", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpAmtMax", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "usdAmtMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpAmtMin", + "type": "uint256" + } + ], + "name": "deposit", + "outputs": [ + { + "internalType": "uint256", + "name": "mintAmt", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "perpAmtIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "postOpAssetRatioMin", + "type": "uint256" + } + ], + "name": "depositPerp", + "outputs": [ + { + "internalType": "uint256", + "name": "mintAmt", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "usdAmtIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "postOpAssetRatioMax", + "type": "uint256" + } + ], + "name": "depositUSD", + "outputs": [ + { + "internalType": "uint256", + "name": "mintAmt", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "fees", + "outputs": [ + { + "internalType": "uint256", + "name": "mintFeePerc", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "burnFeePerc", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "lower", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upper", + "type": "uint256" + } + ], + "internalType": "struct Range", + "name": "perpToUSDSwapFeePercs", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "lower", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upper", + "type": "uint256" + } + ], + "internalType": "struct Range", + "name": "usdToPerpSwapFeePercs", + "type": "tuple" + }, + { + "internalType": "uint256", + "name": "protocolSwapSharePerc", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "addedValue", + "type": "uint256" + } + ], + "name": "increaseAllowance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "name", + "type": "string" + }, + { + "internalType": "string", + "name": "symbol", + "type": "string" + }, + { + "internalType": "contract IERC20Upgradeable", + "name": "usd_", + "type": "address" + }, + { + "internalType": "contract IPerpetualTranche", + "name": "perp_", + "type": "address" + }, + { + "internalType": "contract ISpotPricingStrategy", + "name": "pricingStrategy_", + "type": "address" + } + ], + "name": "init", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "keeper", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "pause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "paused", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "perp", + "outputs": [ + { + "internalType": "contract IPerpetualTranche", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "perpBalance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "perpPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "perpUnitAmt", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "pricingStrategy", + "outputs": [ + { + "internalType": "contract ISpotPricingStrategy", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "protocolFeeCollector", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "burnAmt", + "type": "uint256" + } + ], + "name": "redeem", + "outputs": [ + { + "internalType": "uint256", + "name": "usdAmtOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpAmtOut", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "reserveState", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "usdBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "usdPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpPrice", + "type": "uint256" + } + ], + "internalType": "struct ReserveState", + "name": "s", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "perpAmtIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "usdAmtMin", + "type": "uint256" + } + ], + "name": "swapPerpsForUSD", + "outputs": [ + { + "internalType": "uint256", + "name": "usdAmtOut", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "usdAmtIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "perpAmtMin", + "type": "uint256" + } + ], + "name": "swapUSDForPerps", + "outputs": [ + { + "internalType": "uint256", + "name": "perpAmtOut", + "type": "uint256" + } + ], + "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": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "unpause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "lower", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upper", + "type": "uint256" + } + ], + "internalType": "struct Range", + "name": "arSoftBound_", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "lower", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upper", + "type": "uint256" + } + ], + "internalType": "struct Range", + "name": "arHardBound_", + "type": "tuple" + } + ], + "name": "updateARBounds", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "mintFeePerc", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "burnFeePerc", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "lower", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upper", + "type": "uint256" + } + ], + "internalType": "struct Range", + "name": "perpToUSDSwapFeePercs", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "lower", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upper", + "type": "uint256" + } + ], + "internalType": "struct Range", + "name": "usdToPerpSwapFeePercs", + "type": "tuple" + }, + { + "internalType": "uint256", + "name": "protocolSwapSharePerc", + "type": "uint256" + } + ], + "internalType": "struct BillBrokerFees", + "name": "fees_", + "type": "tuple" + } + ], + "name": "updateFees", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "keeper_", + "type": "address" + } + ], + "name": "updateKeeper", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract ISpotPricingStrategy", + "name": "pricingStrategy_", + "type": "address" + } + ], + "name": "updatePricingStrategy", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "usd", + "outputs": [ + { + "internalType": "contract IERC20Upgradeable", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "usdBalance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "usdPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "usdUnitAmt", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + } +] \ No newline at end of file diff --git a/spot-staking-subgraph/schema.graphql b/spot-staking-subgraph/schema.graphql index 82f2139a..fd736b44 100644 --- a/spot-staking-subgraph/schema.graphql +++ b/spot-staking-subgraph/schema.graphql @@ -1,47 +1,54 @@ -type CharmVault @entity { +type BillBroker @entity { " the vault address " id: ID! - pool: String! name: String! symbol: String! decimals: BigInt! - token0: String! - token0Name: String! - token0Symbol: String! - token0Decimals: BigInt! - token1: String! - token1Name: String! - token1Symbol: String! - token1Decimals: BigInt! - token0Bal: BigDecimal! - token1Bal: BigDecimal! - token0BalIn: BigDecimal! - token1BalIn: BigDecimal! - token0Price: BigDecimal! - token1Price: BigDecimal! - tvl: BigDecimal! - valueIn: BigDecimal! - price: BigDecimal! + perp: String! + perpName: String! + perpSymbol: String! + perpDecimals: BigInt! + usd: String! + usdName: String! + usdSymbol: String! + usdDecimals: BigInt! + perpBal: BigDecimal! + usdBal: BigDecimal! + perpPrice: BigDecimal! + usdPrice: BigDecimal! totalSupply: BigDecimal! - unusedToken0Bal: BigDecimal! - unusedToken1Bal: BigDecimal! - unusedTVL: BigDecimal! - dailyStats: [CharmVaultDailyStat!]! @derivedFrom(field: "vault") + tvl:BigDecimal! + price:BigDecimal! + dailyStats: [BillBrokerDailyStat!]! @derivedFrom(field: "vault") + swapNonce: BigInt! + swaps: [BillBrokerSwap!]! @derivedFrom(field: "vault") } -type CharmVaultDailyStat @entity { +type BillBrokerDailyStat @entity { "-" id: ID! - vault: CharmVault! + vault: BillBroker! timestamp: BigInt! - token0Bal: BigDecimal! - token1Bal: BigDecimal! - token0BalIn: BigDecimal! - token1BalIn: BigDecimal! - token0Price: BigDecimal! - token1Price: BigDecimal! - tvl: BigDecimal! - valueIn: BigDecimal! - price: BigDecimal! + perpBal: BigDecimal! + usdBal: BigDecimal! + perpPrice: BigDecimal! + usdPrice: BigDecimal! totalSupply: BigDecimal! + usdSwapAmt: BigDecimal! + perpSwapAmt: BigDecimal! + usdFeeAmt: BigDecimal! + perpFeeAmt: BigDecimal! + tvl:BigDecimal! + price:BigDecimal! +} + +type BillBrokerSwap @entity { + "-" + id: ID! + vault: BillBroker! + nonce: BigInt! + type: String! + swapAmt: BigDecimal! + feeAmt: BigDecimal! + tx: String! } \ No newline at end of file diff --git a/spot-staking-subgraph/src/mappings.ts b/spot-staking-subgraph/src/mappings.ts index d1430dc8..9eb7e6df 100644 --- a/spot-staking-subgraph/src/mappings.ts +++ b/spot-staking-subgraph/src/mappings.ts @@ -1,11 +1,22 @@ import { log, ethereum, BigInt, BigDecimal, Address } from '@graphprotocol/graph-ts' -import { Deposit, Withdraw, Snapshot } from '../generated/CharmVault/CharmVault' -import { CharmVault as CharmVaultABI } from '../generated/CharmVault/CharmVault' -import { UniV3Pool as UniV3PoolABI } from '../generated/CharmVault/UniV3Pool' -import { ERC20 as ERC20ABI } from '../generated/CharmVault/ERC20' -import { CharmVault, CharmVaultDailyStat } from '../generated/schema' +import { + DepositCall, + RedeemCall, + DepositUSD, + DepositPerp, + SwapPerpsForUSD, + SwapUSDForPerps, +} from '../generated/BillBroker/BillBroker' +import { + BillBroker__computePerpToUSDSwapAmt1InputSStruct, + BillBroker__computeUSDToPerpSwapAmtInputSStruct, +} from '../generated/BillBroker/BillBroker' +import { BillBroker as BillBrokerABI } from '../generated/BillBroker/BillBroker' +import { ERC20 as ERC20ABI } from '../generated/BillBroker/ERC20' +import { BillBroker, BillBrokerDailyStat, BillBrokerSwap } from '../generated/schema' let BIGINT_ZERO = BigInt.fromI32(0) +let BIGINT_ONE = BigInt.fromI32(1) let BIGDECIMAL_ZERO = BigDecimal.fromString('0') let BIGDECIMAL_ONE = BigDecimal.fromString('1') @@ -27,188 +38,247 @@ const formatBalance = (wei: BigInt, decimals: BigInt): BigDecimal => { ) } -// https://github.com/Uniswap/v3-subgraph/blob/main/src/utils/index.ts#L30 -function exponentToBigDecimal(decimals: BigInt): BigDecimal { - let resultString = '1' - for (let i = 0; i < decimals.toI32(); i++) { - resultString += '0' - } - return BigDecimal.fromString(resultString) -} -function safeDiv(amount0: BigDecimal, amount1: BigDecimal): BigDecimal { - if (amount1.equals(BIGDECIMAL_ZERO)) { - return BIGDECIMAL_ZERO - } else { - return amount0.div(amount1) - } -} -function sqrtPriceX96ToTokenPrices( - sqrtPriceX96: BigInt, - token0Decimals: BigInt, - token1Decimals: BigInt, -): BigDecimal[] { - let Q192 = BigInt.fromI32(2).pow(192 as u8) - let num = sqrtPriceX96.times(sqrtPriceX96).toBigDecimal() - let denom = BigDecimal.fromString(Q192.toString()) - let price1 = num - .div(denom) - .times(exponentToBigDecimal(token0Decimals)) - .div(exponentToBigDecimal(token1Decimals)) - let price0 = safeDiv(BigDecimal.fromString('1'), price1) - return [price0, price1] -} - -function fetchCharmVault(address: Address): CharmVault { +function fetchBillBroker(address: Address): BillBroker { let id = address.toHexString() - let vault = CharmVault.load(id) + let vault = BillBroker.load(id) if (vault === null) { - vault = new CharmVault(id) - let vaultContract = CharmVaultABI.bind(address) - vault.pool = vaultContract.pool().toHexString() + vault = new BillBroker(id) + let vaultContract = BillBrokerABI.bind(address) vault.name = vaultContract.name() vault.symbol = vaultContract.symbol() vault.decimals = BigInt.fromI32(vaultContract.decimals()) - let token0Address = vaultContract.token0() - let token0Contract = ERC20ABI.bind(token0Address) - vault.token0 = token0Address.toHexString() - vault.token0Name = token0Contract.name() - vault.token0Symbol = token0Contract.symbol() - vault.token0Decimals = BigInt.fromI32(token0Contract.decimals()) - - let token1Address = vaultContract.token1() - let token1Contract = ERC20ABI.bind(token1Address) - vault.token1 = token1Address.toHexString() - vault.token1Name = token1Contract.name() - vault.token1Symbol = token1Contract.symbol() - vault.token1Decimals = BigInt.fromI32(token1Contract.decimals()) - - vault.token0Bal = BIGDECIMAL_ZERO - vault.token1Bal = BIGDECIMAL_ZERO - vault.token0BalIn = BIGDECIMAL_ZERO - vault.token1BalIn = BIGDECIMAL_ZERO - vault.token0Price = BIGDECIMAL_ZERO - vault.token1Price = BIGDECIMAL_ZERO + let perpAddress = vaultContract.perp() + let perpContract = ERC20ABI.bind(perpAddress) + vault.perp = perpAddress.toHexString() + vault.perpName = perpContract.name() + vault.perpSymbol = perpContract.symbol() + vault.perpDecimals = BigInt.fromI32(perpContract.decimals()) + + let usdAddress = vaultContract.usd() + let usdContract = ERC20ABI.bind(usdAddress) + vault.usd = usdAddress.toHexString() + vault.usdName = usdContract.name() + vault.usdSymbol = usdContract.symbol() + vault.usdDecimals = BigInt.fromI32(usdContract.decimals()) + + vault.perpBal = BIGDECIMAL_ZERO + vault.usdBal = BIGDECIMAL_ZERO + vault.perpPrice = BIGDECIMAL_ZERO + vault.usdPrice = BIGDECIMAL_ZERO + vault.totalSupply = BIGDECIMAL_ZERO vault.tvl = BIGDECIMAL_ZERO - vault.valueIn = BIGDECIMAL_ZERO vault.price = BIGDECIMAL_ZERO - vault.totalSupply = BIGDECIMAL_ZERO - vault.unusedToken0Bal = BIGDECIMAL_ZERO - vault.unusedToken1Bal = BIGDECIMAL_ZERO - vault.unusedTVL = BIGDECIMAL_ZERO + vault.swapNonce = BIGINT_ZERO vault.save() } - return vault as CharmVault + return vault as BillBroker } -function fetchCharmVaultDailyStat(vault: CharmVault, timestamp: BigInt): CharmVaultDailyStat { +function fetchBillBrokerDailyStat(vault: BillBroker, timestamp: BigInt): BillBrokerDailyStat { let id = vault.id.concat('-').concat(timestamp.toString()) - let dailyStat = CharmVaultDailyStat.load(id) + let dailyStat = BillBrokerDailyStat.load(id) if (dailyStat === null) { - dailyStat = new CharmVaultDailyStat(id) + dailyStat = new BillBrokerDailyStat(id) dailyStat.vault = vault.id dailyStat.timestamp = timestamp - dailyStat.token0Bal = BIGDECIMAL_ZERO - dailyStat.token1Bal = BIGDECIMAL_ZERO - dailyStat.token0BalIn = BIGDECIMAL_ZERO - dailyStat.token1BalIn = BIGDECIMAL_ZERO - dailyStat.token0Price = BIGDECIMAL_ZERO - dailyStat.token1Price = BIGDECIMAL_ZERO + dailyStat.perpBal = BIGDECIMAL_ZERO + dailyStat.usdBal = BIGDECIMAL_ZERO + dailyStat.perpPrice = BIGDECIMAL_ZERO + dailyStat.usdPrice = BIGDECIMAL_ZERO + dailyStat.totalSupply = BIGDECIMAL_ZERO + dailyStat.usdSwapAmt = BIGDECIMAL_ZERO + dailyStat.perpSwapAmt = BIGDECIMAL_ZERO + dailyStat.usdFeeAmt = BIGDECIMAL_ZERO + dailyStat.perpFeeAmt = BIGDECIMAL_ZERO dailyStat.tvl = BIGDECIMAL_ZERO - dailyStat.valueIn = BIGDECIMAL_ZERO dailyStat.price = BIGDECIMAL_ZERO - dailyStat.totalSupply = BIGDECIMAL_ZERO dailyStat.save() } - return dailyStat as CharmVaultDailyStat + return dailyStat as BillBrokerDailyStat } -function refreshCharmVaultStats(vault: CharmVault, dailyStat: CharmVaultDailyStat): void { - let vaultContract = CharmVaultABI.bind(stringToAddress(vault.id)) - let tokenBals = vaultContract.getTotalAmounts() - let uniPoolContract = UniV3PoolABI.bind(stringToAddress(vault.pool)) - let slot0 = uniPoolContract.slot0() - let sqrtPrice = slot0.value0 - let prices = sqrtPriceX96ToTokenPrices(sqrtPrice, vault.token0Decimals, vault.token1Decimals) - - vault.token0Bal = formatBalance(tokenBals.value0, vault.token0Decimals) - vault.token1Bal = formatBalance(tokenBals.value1, vault.token1Decimals) - vault.token0Price = prices[0] - vault.token1Price = prices[1] - vault.tvl = vault.token0Bal.plus(vault.token1Bal.times(vault.token0Price)) +function fetchBillBrokerSwap(vault: BillBroker, nonce:BigInt): BillBrokerSwap { + let id = vault.id.concat('-').concat(nonce.toString()) + let swap = BillBrokerSwap.load(id) + if (swap === null) { + swap = new BillBrokerSwap(id) + swap.vault = vault.id + swap.nonce = nonce + swap.type = "" + swap.swapAmt = BIGDECIMAL_ZERO + swap.feeAmt = BIGDECIMAL_ZERO + swap.tx = "0x" + swap.save() + } + return swap as BillBrokerSwap +} + +function refreshBillBrokerStats(vault: BillBroker, dailyStat: BillBrokerDailyStat): void { + let vaultContract = BillBrokerABI.bind(stringToAddress(vault.id)) + vault.perpBal = formatBalance(vaultContract.perpBalance(), vault.perpDecimals) + vault.usdBal = formatBalance(vaultContract.usdBalance(), vault.usdDecimals) vault.totalSupply = formatBalance(vaultContract.totalSupply(), vault.decimals) - vault.price = vault.tvl.div(vault.totalSupply) - vault.unusedToken0Bal = formatBalance(vaultContract.getBalance0(), vault.token0Decimals) - vault.unusedToken1Bal = formatBalance(vaultContract.getBalance1(), vault.token1Decimals) - vault.unusedTVL = vault.unusedToken0Bal.plus(vault.unusedToken1Bal.times(vault.token0Price)) vault.save() - dailyStat.token0Bal = vault.token0Bal - dailyStat.token1Bal = vault.token1Bal - dailyStat.token0Price = vault.token0Price - dailyStat.token1Price = vault.token1Price - dailyStat.tvl = vault.tvl + dailyStat.perpBal = vault.perpBal + dailyStat.usdBal = vault.usdBal dailyStat.totalSupply = vault.totalSupply - dailyStat.price = vault.price dailyStat.save() } -export function handleDeposit(event: Deposit): void { +export function handleDeposit(call: DepositCall): void { log.debug('triggered deposit', []) - let vault = fetchCharmVault(event.address) - let dailyStat = fetchCharmVaultDailyStat(vault, dayTimestamp(event.block.timestamp)) - refreshCharmVaultStats(vault, dailyStat) - vault.token0BalIn = vault.token0BalIn.plus( - formatBalance(event.params.amount0, vault.token0Decimals), - ) - vault.token1BalIn = vault.token1BalIn.plus( - formatBalance(event.params.amount1, vault.token1Decimals), - ) - vault.valueIn = vault.token0BalIn.plus(vault.token1BalIn.times(vault.token0Price)) + let vault = fetchBillBroker(call.to) + let dailyStat = fetchBillBrokerDailyStat(vault, dayTimestamp(call.block.timestamp)) + refreshBillBrokerStats(vault, dailyStat) +} + +export function handleRedeem(call: RedeemCall): void { + log.debug('triggered redeem', []) + let vault = fetchBillBroker(call.to) + let dailyStat = fetchBillBrokerDailyStat(vault, dayTimestamp(call.block.timestamp)) + refreshBillBrokerStats(vault, dailyStat) +} + +export function handleSwapPerpsForUSD(event: SwapPerpsForUSD): void { + log.debug('triggered swap perps', []) + let vault = fetchBillBroker(event.address) + let dailyStat = fetchBillBrokerDailyStat(vault, dayTimestamp(event.block.timestamp)) + let swap = fetchBillBrokerSwap(vault, vault.swapNonce.plus(BIGINT_ONE)) + refreshBillBrokerStats(vault, dailyStat) + + vault.perpPrice = formatBalance(event.params.preOpState.perpPrice, vault.decimals) + vault.usdPrice = formatBalance(event.params.preOpState.usdPrice, vault.decimals) + vault.tvl = vault.usdBal.times(vault.usdPrice).plus(vault.perpBal.times(vault.perpPrice)) + vault.price = vault.tvl.div(vault.totalSupply) vault.save() - dailyStat.token0BalIn = vault.token0BalIn - dailyStat.token1BalIn = vault.token1BalIn - dailyStat.valueIn = vault.valueIn + dailyStat.perpPrice = vault.perpPrice + dailyStat.usdPrice = vault.usdPrice + dailyStat.tvl = vault.tvl + dailyStat.price = vault.price dailyStat.save() -} -export function handleWithdraw(event: Withdraw): void { - log.debug('triggered withdraw', []) - let vault = fetchCharmVault(event.address) - let dailyStat = fetchCharmVaultDailyStat(vault, dayTimestamp(event.block.timestamp)) - refreshCharmVaultStats(vault, dailyStat) - vault.token0BalIn = vault.token0BalIn.minus( - formatBalance(event.params.amount0, vault.token0Decimals), - ) - vault.token1BalIn = vault.token1BalIn.minus( - formatBalance(event.params.amount1, vault.token1Decimals), + swap.type = "perps" + swap.swapAmt = formatBalance(event.params.perpAmtIn, vault.perpDecimals) + swap.tx = event.transaction.hash.toHex() + swap.save() + + let vaultContract = BillBrokerABI.bind(stringToAddress(vault.id)) + let reserveStateValues: Array = [ + ethereum.Value.fromUnsignedBigInt(event.params.preOpState.usdBalance), + ethereum.Value.fromUnsignedBigInt(event.params.preOpState.perpBalance), + ethereum.Value.fromUnsignedBigInt(event.params.preOpState.usdPrice), + ethereum.Value.fromUnsignedBigInt(event.params.preOpState.perpPrice), + ] + let reserveStateTuple = changetype(reserveStateValues) + let reserveStateStruct = changetype( + reserveStateTuple, ) - vault.valueIn = vault.token0BalIn.plus(vault.token1BalIn.times(vault.token0Price)) + let r = vaultContract.try_computePerpToUSDSwapAmt1(event.params.perpAmtIn, reserveStateStruct) + if (!r.reverted) { + let swapAmts = r.value + dailyStat.perpSwapAmt = dailyStat.perpSwapAmt.plus( + formatBalance(event.params.perpAmtIn, vault.perpDecimals), + ) + dailyStat.usdFeeAmt = dailyStat.usdFeeAmt.plus( + formatBalance(swapAmts.value1, vault.usdDecimals), + ) + dailyStat.save() + + swap.feeAmt = dailyStat.usdFeeAmt + swap.save() + } + +} + +export function handleSwapUSDForPerps(event: SwapUSDForPerps): void { + log.debug('triggered swap usd', []) + let vault = fetchBillBroker(event.address) + let dailyStat = fetchBillBrokerDailyStat(vault, dayTimestamp(event.block.timestamp)) + let swap = fetchBillBrokerSwap(vault, vault.swapNonce.plus(BIGINT_ONE)) + refreshBillBrokerStats(vault, dailyStat) + + vault.perpPrice = formatBalance(event.params.preOpState.perpPrice, vault.decimals) + vault.usdPrice = formatBalance(event.params.preOpState.usdPrice, vault.decimals) + vault.tvl = vault.usdBal.times(vault.usdPrice).plus(vault.perpBal.times(vault.perpPrice)) + vault.price = vault.tvl.div(vault.totalSupply) vault.save() - dailyStat.token0BalIn = vault.token0BalIn - dailyStat.token1BalIn = vault.token1BalIn - dailyStat.valueIn = vault.valueIn - dailyStat.save() + dailyStat.perpPrice = vault.perpPrice + dailyStat.usdPrice = vault.usdPrice + dailyStat.tvl = vault.tvl + dailyStat.price = vault.price dailyStat.save() + + swap.type = "usd" + swap.swapAmt = formatBalance(event.params.usdAmtIn, vault.perpDecimals) + swap.tx = event.transaction.hash.toHex() + swap.save() + + let vaultContract = BillBrokerABI.bind(stringToAddress(vault.id)) + let reserveStateValues: Array = [ + ethereum.Value.fromUnsignedBigInt(event.params.preOpState.usdBalance), + ethereum.Value.fromUnsignedBigInt(event.params.preOpState.perpBalance), + ethereum.Value.fromUnsignedBigInt(event.params.preOpState.usdPrice), + ethereum.Value.fromUnsignedBigInt(event.params.preOpState.perpPrice), + ] + let reserveStateTuple = changetype(reserveStateValues) + let reserveStateStruct = changetype( + reserveStateTuple, + ) + let r = vaultContract.try_computeUSDToPerpSwapAmt(event.params.usdAmtIn, reserveStateStruct) + if (!r.reverted) { + let swapAmts = r.value + dailyStat.usdSwapAmt = dailyStat.usdSwapAmt.plus( + formatBalance(event.params.usdAmtIn, vault.usdDecimals), + ) + dailyStat.perpFeeAmt = dailyStat.perpFeeAmt.plus( + formatBalance(swapAmts.value1, vault.perpDecimals), + ) + dailyStat.save() + + swap.feeAmt = dailyStat.perpFeeAmt + swap.save() + } } -export function handleSnapshot(event: Snapshot): void { - log.debug('triggered snapshot', []) - let vault = fetchCharmVault(event.address) - let dailyStat = fetchCharmVaultDailyStat(vault, dayTimestamp(event.block.timestamp)) - refreshCharmVaultStats(vault, dailyStat) +export function handleDepositUSD(event: DepositUSD): void { + log.debug('triggered single sided deposit', []) + let vault = fetchBillBroker(event.address) + let dailyStat = fetchBillBrokerDailyStat(vault, dayTimestamp(event.block.timestamp)) + refreshBillBrokerStats(vault, dailyStat) + + vault.perpPrice = formatBalance(event.params.preOpState.perpPrice, vault.decimals) + vault.usdPrice = formatBalance(event.params.preOpState.usdPrice, vault.decimals) + vault.tvl = vault.usdBal.times(vault.usdPrice).plus(vault.perpBal.times(vault.perpPrice)) + vault.price = vault.tvl.div(vault.totalSupply) + vault.save() + + dailyStat.perpPrice = vault.perpPrice + dailyStat.usdPrice = vault.usdPrice + dailyStat.tvl = vault.tvl + dailyStat.price = vault.price + dailyStat.save() } -export function refreshStore(block: ethereum.Block): void { - let timeForUpdate = - block.number.gt(CHARM_VAULT_UPDATE_BLOCK) && - block.number.mod(BLOCK_UPDATE_INTERVAL).equals(BIGINT_ZERO) - if (timeForUpdate) { - log.debug('triggered store refresh', []) - let vault = fetchCharmVault(stringToAddress(CHARM_VAULT_ID)) - let dailyStat = fetchCharmVaultDailyStat(vault, dayTimestamp(block.timestamp)) - refreshCharmVaultStats(vault, dailyStat) - } + +export function handleDepositPerp(event: DepositPerp): void { + log.debug('triggered single sided deposit', []) + let vault = fetchBillBroker(event.address) + let dailyStat = fetchBillBrokerDailyStat(vault, dayTimestamp(event.block.timestamp)) + refreshBillBrokerStats(vault, dailyStat) + + vault.perpPrice = formatBalance(event.params.preOpState.perpPrice, vault.decimals) + vault.usdPrice = formatBalance(event.params.preOpState.usdPrice, vault.decimals) + vault.tvl = vault.usdBal.times(vault.usdPrice).plus(vault.perpBal.times(vault.perpPrice)) + vault.price = vault.tvl.div(vault.totalSupply) + vault.save() + + dailyStat.perpPrice = vault.perpPrice + dailyStat.usdPrice = vault.usdPrice + dailyStat.tvl = vault.tvl + dailyStat.price = vault.price + dailyStat.save() } diff --git a/spot-staking-subgraph/subgraph.yaml b/spot-staking-subgraph/subgraph.yaml index 007875fc..15c7fbcc 100644 --- a/spot-staking-subgraph/subgraph.yaml +++ b/spot-staking-subgraph/subgraph.yaml @@ -5,34 +5,36 @@ schema: file: ./schema.graphql dataSources: - kind: ethereum/contract - name: CharmVault + name: BillBroker network: mainnet source: - address: "0x2dcaff0f75765d7867887fc402b71c841b3a4bfb" - abi: CharmVault - startBlock: 19792510 + address: "0xA088Aef966CAD7fE0B38e28c2E07590127Ab4ccB" + abi: BillBroker + startBlock: 20127140 mapping: kind: ethereum/events apiVersion: 0.0.4 language: wasm/assemblyscript entities: - - CharmVault - - UniV3Pool + - BillBroker - ERC20 abis: - - name: CharmVault - file: ./abis/CharmVault.json - - name: UniV3Pool - file: ./abis/UniV3Pool.json + - name: BillBroker + file: ./abis/BillBroker.json - name: ERC20 file: ./abis/ERC20.json eventHandlers: - - event: Deposit(indexed address,indexed address,uint256,uint256,uint256) - handler: handleDeposit - - event: Withdraw(indexed address,indexed address,uint256,uint256,uint256) - handler: handleWithdraw - - event: Snapshot(int24,uint256,uint256,uint256) - handler: handleSnapshot - blockHandlers: - - handler: refreshStore + - event: DepositUSD(uint256,(uint256,uint256,uint256,uint256)) + handler: handleDepositUSD + - event: DepositPerp(uint256,(uint256,uint256,uint256,uint256)) + handler: handleDepositPerp + - event: SwapPerpsForUSD(uint256,(uint256,uint256,uint256,uint256)) + handler: handleSwapPerpsForUSD + - event: SwapUSDForPerps(uint256,(uint256,uint256,uint256,uint256)) + handler: handleSwapUSDForPerps + callHandlers: + - function: deposit(uint256,uint256,uint256,uint256) + handler: handleDeposit + - function: redeem(uint256) + handler: handleRedeem file: ./src/mappings.ts \ No newline at end of file