diff --git a/src/apps/metastreet/assets/logo.png b/src/apps/metastreet/assets/logo.png new file mode 100644 index 000000000..4a65e8b8c Binary files /dev/null and b/src/apps/metastreet/assets/logo.png differ diff --git a/src/apps/metastreet/contracts/abis/pool.json b/src/apps/metastreet/contracts/abis/pool.json new file mode 100644 index 000000000..f48f83b17 --- /dev/null +++ b/src/apps/metastreet/contracts/abis/pool.json @@ -0,0 +1,1413 @@ +[ + { + "inputs": [ + { + "internalType": "address", + "name": "collateralLiquidator", + "type": "address" + }, + { + "internalType": "address", + "name": "delegationRegistry", + "type": "address" + }, + { + "internalType": "address[]", + "name": "collateralWrappers", + "type": "address[]" + }, + { + "components": [ + { + "internalType": "uint64", + "name": "tickThreshold", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "tickExponential", + "type": "uint64" + } + ], + "internalType": "struct WeightedInterestRateModel.Parameters", + "name": "parameters", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [], + "name": "InactiveLiquidity", + "type": "error" + }, + { + "inputs": [], + "name": "InsufficientLiquidity", + "type": "error" + }, + { + "inputs": [], + "name": "InsufficientShares", + "type": "error" + }, + { + "inputs": [], + "name": "InsufficientTickSpacing", + "type": "error" + }, + { + "inputs": [], + "name": "InsufficientUtilization", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidBorrowOptions", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidCaller", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidCollateralFilterParameters", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidInterestRateModelParameters", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidLoanReceipt", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidParameters", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidReceiptEncoding", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidRedemptionStatus", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidTick", + "type": "error" + }, + { + "inputs": [], + "name": "LoanNotExpired", + "type": "error" + }, + { + "inputs": [], + "name": "RepaymentTooHigh", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "UnsupportedCollateral", + "type": "error" + }, + { + "inputs": [], + "name": "UnsupportedLoanDuration", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "rate", + "type": "uint256" + } + ], + "name": "AdminFeeRateUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "AdminFeesWithdrawn", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "loanReceiptHash", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "proceeds", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "borrowerProceeds", + "type": "uint256" + } + ], + "name": "CollateralLiquidated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint128", + "name": "tick", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + } + ], + "name": "Deposited", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "loanReceiptHash", + "type": "bytes32" + } + ], + "name": "LoanLiquidated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "loanReceiptHash", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "loanReceipt", + "type": "bytes" + } + ], + "name": "LoanOriginated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "loanReceiptHash", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "repayment", + "type": "uint256" + } + ], + "name": "LoanRepaid", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint128", + "name": "tick", + "type": "uint128" + }, + { + "indexed": true, + "internalType": "uint128", + "name": "redemptionId", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + } + ], + "name": "Redeemed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint128", + "name": "tick", + "type": "uint128" + }, + { + "indexed": true, + "internalType": "uint128", + "name": "redemptionId", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "Withdrawn", + "type": "event" + }, + { + "inputs": [], + "name": "BORROWER_SURPLUS_SPLIT_BASIS_POINTS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "COLLATERAL_FILTER_NAME", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [], + "name": "COLLATERAL_FILTER_VERSION", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [], + "name": "IMPLEMENTATION_NAME", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [], + "name": "IMPLEMENTATION_VERSION", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [], + "name": "INTEREST_RATE_MODEL_NAME", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [], + "name": "INTEREST_RATE_MODEL_VERSION", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [], + "name": "TICK_LIMIT_SPACING_BASIS_POINTS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "admin", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "adminFeeBalance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "adminFeeRate", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "principal", + "type": "uint256" + }, + { + "internalType": "uint64", + "name": "duration", + "type": "uint64" + }, + { + "internalType": "address", + "name": "collateralToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "collateralTokenId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxRepayment", + "type": "uint256" + }, + { + "internalType": "uint128[]", + "name": "ticks", + "type": "uint128[]" + }, + { + "internalType": "bytes", + "name": "options", + "type": "bytes" + } + ], + "name": "borrow", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "collateralLiquidator", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "collateralToken", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "collateralWrappers", + "outputs": [ + { + "internalType": "address[]", + "name": "", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "currencyToken", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "loanReceipt", + "type": "bytes" + } + ], + "name": "decodeLoanReceipt", + "outputs": [ + { + "components": [ + { + "internalType": "uint8", + "name": "version", + "type": "uint8" + }, + { + "internalType": "uint256", + "name": "principal", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "repayment", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "adminFee", + "type": "uint256" + }, + { + "internalType": "address", + "name": "borrower", + "type": "address" + }, + { + "internalType": "uint64", + "name": "maturity", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "duration", + "type": "uint64" + }, + { + "internalType": "address", + "name": "collateralToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "collateralTokenId", + "type": "uint256" + }, + { + "internalType": "uint16", + "name": "collateralWrapperContextLen", + "type": "uint16" + }, + { + "internalType": "bytes", + "name": "collateralWrapperContext", + "type": "bytes" + }, + { + "components": [ + { + "internalType": "uint128", + "name": "tick", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "used", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "pending", + "type": "uint128" + } + ], + "internalType": "struct LoanReceipt.NodeReceipt[]", + "name": "nodeReceipts", + "type": "tuple[]" + } + ], + "internalType": "struct LoanReceipt.LoanReceiptV2", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [], + "name": "delegationRegistry", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint128", + "name": "tick", + "type": "uint128" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minShares", + "type": "uint256" + } + ], + "name": "deposit", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "uint128", + "name": "tick", + "type": "uint128" + } + ], + "name": "deposits", + "outputs": [ + { + "internalType": "uint128", + "name": "shares", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "redemptionId", + "type": "uint128" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "durations", + "outputs": [ + { + "internalType": "uint64[]", + "name": "", + "type": "uint64[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "params", + "type": "bytes" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "encodedLoanReceipt", + "type": "bytes" + } + ], + "name": "liquidate", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint128", + "name": "tick", + "type": "uint128" + } + ], + "name": "liquidityNode", + "outputs": [ + { + "components": [ + { + "internalType": "uint128", + "name": "tick", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "value", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "shares", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "available", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "pending", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "redemptions", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "prev", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "next", + "type": "uint128" + } + ], + "internalType": "struct ILiquidity.NodeInfo", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint128", + "name": "tick", + "type": "uint128" + } + ], + "name": "liquidityNodeWithAccrual", + "outputs": [ + { + "components": [ + { + "internalType": "uint128", + "name": "tick", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "value", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "shares", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "available", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "pending", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "redemptions", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "prev", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "next", + "type": "uint128" + } + ], + "internalType": "struct ILiquidity.NodeInfo", + "name": "", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint128", + "name": "accrued", + "type": "uint128" + }, + { + "internalType": "uint64", + "name": "rate", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "timestamp", + "type": "uint64" + } + ], + "internalType": "struct ILiquidity.AccrualInfo", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint128", + "name": "startTick", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "endTick", + "type": "uint128" + } + ], + "name": "liquidityNodes", + "outputs": [ + { + "components": [ + { + "internalType": "uint128", + "name": "tick", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "value", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "shares", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "available", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "pending", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "redemptions", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "prev", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "next", + "type": "uint128" + } + ], + "internalType": "struct ILiquidity.NodeInfo[]", + "name": "", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "receiptHash", + "type": "bytes32" + } + ], + "name": "loans", + "outputs": [ + { + "internalType": "enum Pool.LoanStatus", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes[]", + "name": "data", + "type": "bytes[]" + } + ], + "name": "multicall", + "outputs": [ + { + "internalType": "bytes[]", + "name": "results", + "type": "bytes[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "encodedLoanReceipt", + "type": "bytes" + }, + { + "internalType": "uint256", + "name": "proceeds", + "type": "uint256" + } + ], + "name": "onCollateralLiquidated", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "principal", + "type": "uint256" + }, + { + "internalType": "uint64", + "name": "duration", + "type": "uint64" + }, + { + "internalType": "address", + "name": "collateralToken", + "type": "address" + }, + { + "internalType": "uint256[]", + "name": "collateralTokenIds", + "type": "uint256[]" + }, + { + "internalType": "uint256", + "name": "collateralTokenCount", + "type": "uint256" + }, + { + "internalType": "uint128[]", + "name": "ticks", + "type": "uint128[]" + }, + { + "internalType": "bytes", + "name": "options", + "type": "bytes" + } + ], + "name": "quote", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "rates", + "outputs": [ + { + "internalType": "uint64[]", + "name": "", + "type": "uint64[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint128", + "name": "srcTick", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "dstTick", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "redemptionId", + "type": "uint128" + }, + { + "internalType": "uint256", + "name": "minShares", + "type": "uint256" + } + ], + "name": "rebalance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint128", + "name": "tick", + "type": "uint128" + }, + { + "internalType": "uint256", + "name": "shares", + "type": "uint256" + } + ], + "name": "redeem", + "outputs": [ + { + "internalType": "uint128", + "name": "", + "type": "uint128" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "uint128", + "name": "tick", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "redemptionId", + "type": "uint128" + } + ], + "name": "redemptionAvailable", + "outputs": [ + { + "internalType": "uint256", + "name": "shares", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "sharesAhead", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "uint128", + "name": "tick", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "redemptionId", + "type": "uint128" + } + ], + "name": "redemptions", + "outputs": [ + { + "components": [ + { + "internalType": "uint128", + "name": "pending", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "index", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "target", + "type": "uint128" + } + ], + "internalType": "struct Pool.Redemption", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "encodedLoanReceipt", + "type": "bytes" + }, + { + "internalType": "uint256", + "name": "principal", + "type": "uint256" + }, + { + "internalType": "uint64", + "name": "duration", + "type": "uint64" + }, + { + "internalType": "uint256", + "name": "maxRepayment", + "type": "uint256" + }, + { + "internalType": "uint128[]", + "name": "ticks", + "type": "uint128[]" + } + ], + "name": "refinance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "encodedLoanReceipt", + "type": "bytes" + } + ], + "name": "repay", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint32", + "name": "rate", + "type": "uint32" + } + ], + "name": "setAdminFeeRate", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes4", + "name": "interfaceId", + "type": "bytes4" + } + ], + "name": "supportsInterface", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint128", + "name": "tick", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "redemptionId", + "type": "uint128" + } + ], + "name": "withdraw", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "withdrawAdminFees", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/src/apps/metastreet/contracts/ethers/Pool.ts b/src/apps/metastreet/contracts/ethers/Pool.ts new file mode 100644 index 000000000..c822621ec --- /dev/null +++ b/src/apps/metastreet/contracts/ethers/Pool.ts @@ -0,0 +1,1464 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BigNumber, + BigNumberish, + BytesLike, + CallOverrides, + ContractTransaction, + Overrides, + PopulatedTransaction, + Signer, + utils, +} from 'ethers'; +import type { FunctionFragment, Result, EventFragment } from '@ethersproject/abi'; +import type { Listener, Provider } from '@ethersproject/providers'; +import type { TypedEventFilter, TypedEvent, TypedListener, OnEvent, PromiseOrValue } from './common'; + +export declare namespace WeightedInterestRateModel { + export type ParametersStruct = { + tickThreshold: PromiseOrValue; + tickExponential: PromiseOrValue; + }; + + export type ParametersStructOutput = [BigNumber, BigNumber] & { + tickThreshold: BigNumber; + tickExponential: BigNumber; + }; +} + +export declare namespace LoanReceipt { + export type NodeReceiptStruct = { + tick: PromiseOrValue; + used: PromiseOrValue; + pending: PromiseOrValue; + }; + + export type NodeReceiptStructOutput = [BigNumber, BigNumber, BigNumber] & { + tick: BigNumber; + used: BigNumber; + pending: BigNumber; + }; + + export type LoanReceiptV2Struct = { + version: PromiseOrValue; + principal: PromiseOrValue; + repayment: PromiseOrValue; + adminFee: PromiseOrValue; + borrower: PromiseOrValue; + maturity: PromiseOrValue; + duration: PromiseOrValue; + collateralToken: PromiseOrValue; + collateralTokenId: PromiseOrValue; + collateralWrapperContextLen: PromiseOrValue; + collateralWrapperContext: PromiseOrValue; + nodeReceipts: LoanReceipt.NodeReceiptStruct[]; + }; + + export type LoanReceiptV2StructOutput = [ + number, + BigNumber, + BigNumber, + BigNumber, + string, + BigNumber, + BigNumber, + string, + BigNumber, + number, + string, + LoanReceipt.NodeReceiptStructOutput[], + ] & { + version: number; + principal: BigNumber; + repayment: BigNumber; + adminFee: BigNumber; + borrower: string; + maturity: BigNumber; + duration: BigNumber; + collateralToken: string; + collateralTokenId: BigNumber; + collateralWrapperContextLen: number; + collateralWrapperContext: string; + nodeReceipts: LoanReceipt.NodeReceiptStructOutput[]; + }; +} + +export declare namespace ILiquidity { + export type NodeInfoStruct = { + tick: PromiseOrValue; + value: PromiseOrValue; + shares: PromiseOrValue; + available: PromiseOrValue; + pending: PromiseOrValue; + redemptions: PromiseOrValue; + prev: PromiseOrValue; + next: PromiseOrValue; + }; + + export type NodeInfoStructOutput = [ + BigNumber, + BigNumber, + BigNumber, + BigNumber, + BigNumber, + BigNumber, + BigNumber, + BigNumber, + ] & { + tick: BigNumber; + value: BigNumber; + shares: BigNumber; + available: BigNumber; + pending: BigNumber; + redemptions: BigNumber; + prev: BigNumber; + next: BigNumber; + }; + + export type AccrualInfoStruct = { + accrued: PromiseOrValue; + rate: PromiseOrValue; + timestamp: PromiseOrValue; + }; + + export type AccrualInfoStructOutput = [BigNumber, BigNumber, BigNumber] & { + accrued: BigNumber; + rate: BigNumber; + timestamp: BigNumber; + }; +} + +export declare namespace Pool { + export type RedemptionStruct = { + pending: PromiseOrValue; + index: PromiseOrValue; + target: PromiseOrValue; + }; + + export type RedemptionStructOutput = [BigNumber, BigNumber, BigNumber] & { + pending: BigNumber; + index: BigNumber; + target: BigNumber; + }; +} + +export interface PoolInterface extends utils.Interface { + functions: { + 'BORROWER_SURPLUS_SPLIT_BASIS_POINTS()': FunctionFragment; + 'COLLATERAL_FILTER_NAME()': FunctionFragment; + 'COLLATERAL_FILTER_VERSION()': FunctionFragment; + 'IMPLEMENTATION_NAME()': FunctionFragment; + 'IMPLEMENTATION_VERSION()': FunctionFragment; + 'INTEREST_RATE_MODEL_NAME()': FunctionFragment; + 'INTEREST_RATE_MODEL_VERSION()': FunctionFragment; + 'TICK_LIMIT_SPACING_BASIS_POINTS()': FunctionFragment; + 'admin()': FunctionFragment; + 'adminFeeBalance()': FunctionFragment; + 'adminFeeRate()': FunctionFragment; + 'borrow(uint256,uint64,address,uint256,uint256,uint128[],bytes)': FunctionFragment; + 'collateralLiquidator()': FunctionFragment; + 'collateralToken()': FunctionFragment; + 'collateralWrappers()': FunctionFragment; + 'currencyToken()': FunctionFragment; + 'decodeLoanReceipt(bytes)': FunctionFragment; + 'delegationRegistry()': FunctionFragment; + 'deposit(uint128,uint256,uint256)': FunctionFragment; + 'deposits(address,uint128)': FunctionFragment; + 'durations()': FunctionFragment; + 'initialize(bytes)': FunctionFragment; + 'liquidate(bytes)': FunctionFragment; + 'liquidityNode(uint128)': FunctionFragment; + 'liquidityNodeWithAccrual(uint128)': FunctionFragment; + 'liquidityNodes(uint128,uint128)': FunctionFragment; + 'loans(bytes32)': FunctionFragment; + 'multicall(bytes[])': FunctionFragment; + 'onCollateralLiquidated(bytes,uint256)': FunctionFragment; + 'quote(uint256,uint64,address,uint256[],uint256,uint128[],bytes)': FunctionFragment; + 'rates()': FunctionFragment; + 'rebalance(uint128,uint128,uint128,uint256)': FunctionFragment; + 'redeem(uint128,uint256)': FunctionFragment; + 'redemptionAvailable(address,uint128,uint128)': FunctionFragment; + 'redemptions(address,uint128,uint128)': FunctionFragment; + 'refinance(bytes,uint256,uint64,uint256,uint128[])': FunctionFragment; + 'repay(bytes)': FunctionFragment; + 'setAdminFeeRate(uint32)': FunctionFragment; + 'supportsInterface(bytes4)': FunctionFragment; + 'withdraw(uint128,uint128)': FunctionFragment; + 'withdrawAdminFees(address,uint256)': FunctionFragment; + }; + + getFunction( + nameOrSignatureOrTopic: + | 'BORROWER_SURPLUS_SPLIT_BASIS_POINTS' + | 'COLLATERAL_FILTER_NAME' + | 'COLLATERAL_FILTER_VERSION' + | 'IMPLEMENTATION_NAME' + | 'IMPLEMENTATION_VERSION' + | 'INTEREST_RATE_MODEL_NAME' + | 'INTEREST_RATE_MODEL_VERSION' + | 'TICK_LIMIT_SPACING_BASIS_POINTS' + | 'admin' + | 'adminFeeBalance' + | 'adminFeeRate' + | 'borrow' + | 'collateralLiquidator' + | 'collateralToken' + | 'collateralWrappers' + | 'currencyToken' + | 'decodeLoanReceipt' + | 'delegationRegistry' + | 'deposit' + | 'deposits' + | 'durations' + | 'initialize' + | 'liquidate' + | 'liquidityNode' + | 'liquidityNodeWithAccrual' + | 'liquidityNodes' + | 'loans' + | 'multicall' + | 'onCollateralLiquidated' + | 'quote' + | 'rates' + | 'rebalance' + | 'redeem' + | 'redemptionAvailable' + | 'redemptions' + | 'refinance' + | 'repay' + | 'setAdminFeeRate' + | 'supportsInterface' + | 'withdraw' + | 'withdrawAdminFees', + ): FunctionFragment; + + encodeFunctionData(functionFragment: 'BORROWER_SURPLUS_SPLIT_BASIS_POINTS', values?: undefined): string; + encodeFunctionData(functionFragment: 'COLLATERAL_FILTER_NAME', values?: undefined): string; + encodeFunctionData(functionFragment: 'COLLATERAL_FILTER_VERSION', values?: undefined): string; + encodeFunctionData(functionFragment: 'IMPLEMENTATION_NAME', values?: undefined): string; + encodeFunctionData(functionFragment: 'IMPLEMENTATION_VERSION', values?: undefined): string; + encodeFunctionData(functionFragment: 'INTEREST_RATE_MODEL_NAME', values?: undefined): string; + encodeFunctionData(functionFragment: 'INTEREST_RATE_MODEL_VERSION', values?: undefined): string; + encodeFunctionData(functionFragment: 'TICK_LIMIT_SPACING_BASIS_POINTS', values?: undefined): string; + encodeFunctionData(functionFragment: 'admin', values?: undefined): string; + encodeFunctionData(functionFragment: 'adminFeeBalance', values?: undefined): string; + encodeFunctionData(functionFragment: 'adminFeeRate', values?: undefined): string; + encodeFunctionData( + functionFragment: 'borrow', + values: [ + PromiseOrValue, + PromiseOrValue, + PromiseOrValue, + PromiseOrValue, + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue, + ], + ): string; + encodeFunctionData(functionFragment: 'collateralLiquidator', values?: undefined): string; + encodeFunctionData(functionFragment: 'collateralToken', values?: undefined): string; + encodeFunctionData(functionFragment: 'collateralWrappers', values?: undefined): string; + encodeFunctionData(functionFragment: 'currencyToken', values?: undefined): string; + encodeFunctionData(functionFragment: 'decodeLoanReceipt', values: [PromiseOrValue]): string; + encodeFunctionData(functionFragment: 'delegationRegistry', values?: undefined): string; + encodeFunctionData( + functionFragment: 'deposit', + values: [PromiseOrValue, PromiseOrValue, PromiseOrValue], + ): string; + encodeFunctionData( + functionFragment: 'deposits', + values: [PromiseOrValue, PromiseOrValue], + ): string; + encodeFunctionData(functionFragment: 'durations', values?: undefined): string; + encodeFunctionData(functionFragment: 'initialize', values: [PromiseOrValue]): string; + encodeFunctionData(functionFragment: 'liquidate', values: [PromiseOrValue]): string; + encodeFunctionData(functionFragment: 'liquidityNode', values: [PromiseOrValue]): string; + encodeFunctionData(functionFragment: 'liquidityNodeWithAccrual', values: [PromiseOrValue]): string; + encodeFunctionData( + functionFragment: 'liquidityNodes', + values: [PromiseOrValue, PromiseOrValue], + ): string; + encodeFunctionData(functionFragment: 'loans', values: [PromiseOrValue]): string; + encodeFunctionData(functionFragment: 'multicall', values: [PromiseOrValue[]]): string; + encodeFunctionData( + functionFragment: 'onCollateralLiquidated', + values: [PromiseOrValue, PromiseOrValue], + ): string; + encodeFunctionData( + functionFragment: 'quote', + values: [ + PromiseOrValue, + PromiseOrValue, + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue, + PromiseOrValue[], + PromiseOrValue, + ], + ): string; + encodeFunctionData(functionFragment: 'rates', values?: undefined): string; + encodeFunctionData( + functionFragment: 'rebalance', + values: [ + PromiseOrValue, + PromiseOrValue, + PromiseOrValue, + PromiseOrValue, + ], + ): string; + encodeFunctionData( + functionFragment: 'redeem', + values: [PromiseOrValue, PromiseOrValue], + ): string; + encodeFunctionData( + functionFragment: 'redemptionAvailable', + values: [PromiseOrValue, PromiseOrValue, PromiseOrValue], + ): string; + encodeFunctionData( + functionFragment: 'redemptions', + values: [PromiseOrValue, PromiseOrValue, PromiseOrValue], + ): string; + encodeFunctionData( + functionFragment: 'refinance', + values: [ + PromiseOrValue, + PromiseOrValue, + PromiseOrValue, + PromiseOrValue, + PromiseOrValue[], + ], + ): string; + encodeFunctionData(functionFragment: 'repay', values: [PromiseOrValue]): string; + encodeFunctionData(functionFragment: 'setAdminFeeRate', values: [PromiseOrValue]): string; + encodeFunctionData(functionFragment: 'supportsInterface', values: [PromiseOrValue]): string; + encodeFunctionData( + functionFragment: 'withdraw', + values: [PromiseOrValue, PromiseOrValue], + ): string; + encodeFunctionData( + functionFragment: 'withdrawAdminFees', + values: [PromiseOrValue, PromiseOrValue], + ): string; + + decodeFunctionResult(functionFragment: 'BORROWER_SURPLUS_SPLIT_BASIS_POINTS', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'COLLATERAL_FILTER_NAME', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'COLLATERAL_FILTER_VERSION', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'IMPLEMENTATION_NAME', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'IMPLEMENTATION_VERSION', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'INTEREST_RATE_MODEL_NAME', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'INTEREST_RATE_MODEL_VERSION', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'TICK_LIMIT_SPACING_BASIS_POINTS', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'admin', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'adminFeeBalance', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'adminFeeRate', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'borrow', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'collateralLiquidator', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'collateralToken', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'collateralWrappers', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'currencyToken', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'decodeLoanReceipt', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'delegationRegistry', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'deposit', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'deposits', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'durations', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'initialize', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'liquidate', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'liquidityNode', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'liquidityNodeWithAccrual', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'liquidityNodes', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'loans', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'multicall', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'onCollateralLiquidated', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'quote', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'rates', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'rebalance', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'redeem', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'redemptionAvailable', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'redemptions', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'refinance', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'repay', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setAdminFeeRate', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'supportsInterface', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'withdraw', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'withdrawAdminFees', data: BytesLike): Result; + + events: { + 'AdminFeeRateUpdated(uint256)': EventFragment; + 'AdminFeesWithdrawn(address,uint256)': EventFragment; + 'CollateralLiquidated(bytes32,uint256,uint256)': EventFragment; + 'Deposited(address,uint128,uint256,uint256)': EventFragment; + 'LoanLiquidated(bytes32)': EventFragment; + 'LoanOriginated(bytes32,bytes)': EventFragment; + 'LoanRepaid(bytes32,uint256)': EventFragment; + 'Redeemed(address,uint128,uint128,uint256)': EventFragment; + 'Withdrawn(address,uint128,uint128,uint256,uint256)': EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: 'AdminFeeRateUpdated'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'AdminFeesWithdrawn'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'CollateralLiquidated'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'Deposited'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LoanLiquidated'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LoanOriginated'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LoanRepaid'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'Redeemed'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'Withdrawn'): EventFragment; +} + +export interface AdminFeeRateUpdatedEventObject { + rate: BigNumber; +} +export type AdminFeeRateUpdatedEvent = TypedEvent<[BigNumber], AdminFeeRateUpdatedEventObject>; + +export type AdminFeeRateUpdatedEventFilter = TypedEventFilter; + +export interface AdminFeesWithdrawnEventObject { + account: string; + amount: BigNumber; +} +export type AdminFeesWithdrawnEvent = TypedEvent<[string, BigNumber], AdminFeesWithdrawnEventObject>; + +export type AdminFeesWithdrawnEventFilter = TypedEventFilter; + +export interface CollateralLiquidatedEventObject { + loanReceiptHash: string; + proceeds: BigNumber; + borrowerProceeds: BigNumber; +} +export type CollateralLiquidatedEvent = TypedEvent<[string, BigNumber, BigNumber], CollateralLiquidatedEventObject>; + +export type CollateralLiquidatedEventFilter = TypedEventFilter; + +export interface DepositedEventObject { + account: string; + tick: BigNumber; + amount: BigNumber; + shares: BigNumber; +} +export type DepositedEvent = TypedEvent<[string, BigNumber, BigNumber, BigNumber], DepositedEventObject>; + +export type DepositedEventFilter = TypedEventFilter; + +export interface LoanLiquidatedEventObject { + loanReceiptHash: string; +} +export type LoanLiquidatedEvent = TypedEvent<[string], LoanLiquidatedEventObject>; + +export type LoanLiquidatedEventFilter = TypedEventFilter; + +export interface LoanOriginatedEventObject { + loanReceiptHash: string; + loanReceipt: string; +} +export type LoanOriginatedEvent = TypedEvent<[string, string], LoanOriginatedEventObject>; + +export type LoanOriginatedEventFilter = TypedEventFilter; + +export interface LoanRepaidEventObject { + loanReceiptHash: string; + repayment: BigNumber; +} +export type LoanRepaidEvent = TypedEvent<[string, BigNumber], LoanRepaidEventObject>; + +export type LoanRepaidEventFilter = TypedEventFilter; + +export interface RedeemedEventObject { + account: string; + tick: BigNumber; + redemptionId: BigNumber; + shares: BigNumber; +} +export type RedeemedEvent = TypedEvent<[string, BigNumber, BigNumber, BigNumber], RedeemedEventObject>; + +export type RedeemedEventFilter = TypedEventFilter; + +export interface WithdrawnEventObject { + account: string; + tick: BigNumber; + redemptionId: BigNumber; + shares: BigNumber; + amount: BigNumber; +} +export type WithdrawnEvent = TypedEvent<[string, BigNumber, BigNumber, BigNumber, BigNumber], WithdrawnEventObject>; + +export type WithdrawnEventFilter = TypedEventFilter; + +export interface Pool extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + interface: PoolInterface; + + queryFilter( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined, + ): Promise>; + + listeners(eventFilter?: TypedEventFilter): Array>; + listeners(eventName?: string): Array; + removeAllListeners(eventFilter: TypedEventFilter): this; + removeAllListeners(eventName?: string): this; + off: OnEvent; + on: OnEvent; + once: OnEvent; + removeListener: OnEvent; + + functions: { + BORROWER_SURPLUS_SPLIT_BASIS_POINTS(overrides?: CallOverrides): Promise<[BigNumber]>; + + COLLATERAL_FILTER_NAME(overrides?: CallOverrides): Promise<[string]>; + + COLLATERAL_FILTER_VERSION(overrides?: CallOverrides): Promise<[string]>; + + IMPLEMENTATION_NAME(overrides?: CallOverrides): Promise<[string]>; + + IMPLEMENTATION_VERSION(overrides?: CallOverrides): Promise<[string]>; + + INTEREST_RATE_MODEL_NAME(overrides?: CallOverrides): Promise<[string]>; + + INTEREST_RATE_MODEL_VERSION(overrides?: CallOverrides): Promise<[string]>; + + TICK_LIMIT_SPACING_BASIS_POINTS(overrides?: CallOverrides): Promise<[BigNumber]>; + + admin(overrides?: CallOverrides): Promise<[string]>; + + adminFeeBalance(overrides?: CallOverrides): Promise<[BigNumber]>; + + adminFeeRate(overrides?: CallOverrides): Promise<[number]>; + + borrow( + principal: PromiseOrValue, + duration: PromiseOrValue, + collateralToken: PromiseOrValue, + collateralTokenId: PromiseOrValue, + maxRepayment: PromiseOrValue, + ticks: PromiseOrValue[], + options: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + collateralLiquidator(overrides?: CallOverrides): Promise<[string]>; + + collateralToken(overrides?: CallOverrides): Promise<[string]>; + + collateralWrappers(overrides?: CallOverrides): Promise<[string[]]>; + + currencyToken(overrides?: CallOverrides): Promise<[string]>; + + decodeLoanReceipt( + loanReceipt: PromiseOrValue, + overrides?: CallOverrides, + ): Promise<[LoanReceipt.LoanReceiptV2StructOutput]>; + + delegationRegistry(overrides?: CallOverrides): Promise<[string]>; + + deposit( + tick: PromiseOrValue, + amount: PromiseOrValue, + minShares: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + deposits( + account: PromiseOrValue, + tick: PromiseOrValue, + overrides?: CallOverrides, + ): Promise<[BigNumber, BigNumber] & { shares: BigNumber; redemptionId: BigNumber }>; + + durations(overrides?: CallOverrides): Promise<[BigNumber[]]>; + + initialize( + params: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + liquidate( + encodedLoanReceipt: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + liquidityNode( + tick: PromiseOrValue, + overrides?: CallOverrides, + ): Promise<[ILiquidity.NodeInfoStructOutput]>; + + liquidityNodeWithAccrual( + tick: PromiseOrValue, + overrides?: CallOverrides, + ): Promise<[ILiquidity.NodeInfoStructOutput, ILiquidity.AccrualInfoStructOutput]>; + + liquidityNodes( + startTick: PromiseOrValue, + endTick: PromiseOrValue, + overrides?: CallOverrides, + ): Promise<[ILiquidity.NodeInfoStructOutput[]]>; + + loans(receiptHash: PromiseOrValue, overrides?: CallOverrides): Promise<[number]>; + + multicall( + data: PromiseOrValue[], + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + onCollateralLiquidated( + encodedLoanReceipt: PromiseOrValue, + proceeds: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + quote( + principal: PromiseOrValue, + duration: PromiseOrValue, + collateralToken: PromiseOrValue, + collateralTokenIds: PromiseOrValue[], + collateralTokenCount: PromiseOrValue, + ticks: PromiseOrValue[], + options: PromiseOrValue, + overrides?: CallOverrides, + ): Promise<[BigNumber]>; + + rates(overrides?: CallOverrides): Promise<[BigNumber[]]>; + + rebalance( + srcTick: PromiseOrValue, + dstTick: PromiseOrValue, + redemptionId: PromiseOrValue, + minShares: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + redeem( + tick: PromiseOrValue, + shares: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + redemptionAvailable( + account: PromiseOrValue, + tick: PromiseOrValue, + redemptionId: PromiseOrValue, + overrides?: CallOverrides, + ): Promise< + [BigNumber, BigNumber, BigNumber] & { + shares: BigNumber; + amount: BigNumber; + sharesAhead: BigNumber; + } + >; + + redemptions( + account: PromiseOrValue, + tick: PromiseOrValue, + redemptionId: PromiseOrValue, + overrides?: CallOverrides, + ): Promise<[Pool.RedemptionStructOutput]>; + + refinance( + encodedLoanReceipt: PromiseOrValue, + principal: PromiseOrValue, + duration: PromiseOrValue, + maxRepayment: PromiseOrValue, + ticks: PromiseOrValue[], + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + repay( + encodedLoanReceipt: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + setAdminFeeRate( + rate: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + supportsInterface(interfaceId: PromiseOrValue, overrides?: CallOverrides): Promise<[boolean]>; + + withdraw( + tick: PromiseOrValue, + redemptionId: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + withdrawAdminFees( + recipient: PromiseOrValue, + amount: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + }; + + BORROWER_SURPLUS_SPLIT_BASIS_POINTS(overrides?: CallOverrides): Promise; + + COLLATERAL_FILTER_NAME(overrides?: CallOverrides): Promise; + + COLLATERAL_FILTER_VERSION(overrides?: CallOverrides): Promise; + + IMPLEMENTATION_NAME(overrides?: CallOverrides): Promise; + + IMPLEMENTATION_VERSION(overrides?: CallOverrides): Promise; + + INTEREST_RATE_MODEL_NAME(overrides?: CallOverrides): Promise; + + INTEREST_RATE_MODEL_VERSION(overrides?: CallOverrides): Promise; + + TICK_LIMIT_SPACING_BASIS_POINTS(overrides?: CallOverrides): Promise; + + admin(overrides?: CallOverrides): Promise; + + adminFeeBalance(overrides?: CallOverrides): Promise; + + adminFeeRate(overrides?: CallOverrides): Promise; + + borrow( + principal: PromiseOrValue, + duration: PromiseOrValue, + collateralToken: PromiseOrValue, + collateralTokenId: PromiseOrValue, + maxRepayment: PromiseOrValue, + ticks: PromiseOrValue[], + options: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + collateralLiquidator(overrides?: CallOverrides): Promise; + + collateralToken(overrides?: CallOverrides): Promise; + + collateralWrappers(overrides?: CallOverrides): Promise; + + currencyToken(overrides?: CallOverrides): Promise; + + decodeLoanReceipt( + loanReceipt: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + delegationRegistry(overrides?: CallOverrides): Promise; + + deposit( + tick: PromiseOrValue, + amount: PromiseOrValue, + minShares: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + deposits( + account: PromiseOrValue, + tick: PromiseOrValue, + overrides?: CallOverrides, + ): Promise<[BigNumber, BigNumber] & { shares: BigNumber; redemptionId: BigNumber }>; + + durations(overrides?: CallOverrides): Promise; + + initialize( + params: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + liquidate( + encodedLoanReceipt: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + liquidityNode( + tick: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + liquidityNodeWithAccrual( + tick: PromiseOrValue, + overrides?: CallOverrides, + ): Promise<[ILiquidity.NodeInfoStructOutput, ILiquidity.AccrualInfoStructOutput]>; + + liquidityNodes( + startTick: PromiseOrValue, + endTick: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + loans(receiptHash: PromiseOrValue, overrides?: CallOverrides): Promise; + + multicall( + data: PromiseOrValue[], + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + onCollateralLiquidated( + encodedLoanReceipt: PromiseOrValue, + proceeds: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + quote( + principal: PromiseOrValue, + duration: PromiseOrValue, + collateralToken: PromiseOrValue, + collateralTokenIds: PromiseOrValue[], + collateralTokenCount: PromiseOrValue, + ticks: PromiseOrValue[], + options: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + rates(overrides?: CallOverrides): Promise; + + rebalance( + srcTick: PromiseOrValue, + dstTick: PromiseOrValue, + redemptionId: PromiseOrValue, + minShares: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + redeem( + tick: PromiseOrValue, + shares: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + redemptionAvailable( + account: PromiseOrValue, + tick: PromiseOrValue, + redemptionId: PromiseOrValue, + overrides?: CallOverrides, + ): Promise< + [BigNumber, BigNumber, BigNumber] & { + shares: BigNumber; + amount: BigNumber; + sharesAhead: BigNumber; + } + >; + + redemptions( + account: PromiseOrValue, + tick: PromiseOrValue, + redemptionId: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + refinance( + encodedLoanReceipt: PromiseOrValue, + principal: PromiseOrValue, + duration: PromiseOrValue, + maxRepayment: PromiseOrValue, + ticks: PromiseOrValue[], + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + repay( + encodedLoanReceipt: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + setAdminFeeRate( + rate: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + supportsInterface(interfaceId: PromiseOrValue, overrides?: CallOverrides): Promise; + + withdraw( + tick: PromiseOrValue, + redemptionId: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + withdrawAdminFees( + recipient: PromiseOrValue, + amount: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + callStatic: { + BORROWER_SURPLUS_SPLIT_BASIS_POINTS(overrides?: CallOverrides): Promise; + + COLLATERAL_FILTER_NAME(overrides?: CallOverrides): Promise; + + COLLATERAL_FILTER_VERSION(overrides?: CallOverrides): Promise; + + IMPLEMENTATION_NAME(overrides?: CallOverrides): Promise; + + IMPLEMENTATION_VERSION(overrides?: CallOverrides): Promise; + + INTEREST_RATE_MODEL_NAME(overrides?: CallOverrides): Promise; + + INTEREST_RATE_MODEL_VERSION(overrides?: CallOverrides): Promise; + + TICK_LIMIT_SPACING_BASIS_POINTS(overrides?: CallOverrides): Promise; + + admin(overrides?: CallOverrides): Promise; + + adminFeeBalance(overrides?: CallOverrides): Promise; + + adminFeeRate(overrides?: CallOverrides): Promise; + + borrow( + principal: PromiseOrValue, + duration: PromiseOrValue, + collateralToken: PromiseOrValue, + collateralTokenId: PromiseOrValue, + maxRepayment: PromiseOrValue, + ticks: PromiseOrValue[], + options: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + collateralLiquidator(overrides?: CallOverrides): Promise; + + collateralToken(overrides?: CallOverrides): Promise; + + collateralWrappers(overrides?: CallOverrides): Promise; + + currencyToken(overrides?: CallOverrides): Promise; + + decodeLoanReceipt( + loanReceipt: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + delegationRegistry(overrides?: CallOverrides): Promise; + + deposit( + tick: PromiseOrValue, + amount: PromiseOrValue, + minShares: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + deposits( + account: PromiseOrValue, + tick: PromiseOrValue, + overrides?: CallOverrides, + ): Promise<[BigNumber, BigNumber] & { shares: BigNumber; redemptionId: BigNumber }>; + + durations(overrides?: CallOverrides): Promise; + + initialize(params: PromiseOrValue, overrides?: CallOverrides): Promise; + + liquidate(encodedLoanReceipt: PromiseOrValue, overrides?: CallOverrides): Promise; + + liquidityNode( + tick: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + liquidityNodeWithAccrual( + tick: PromiseOrValue, + overrides?: CallOverrides, + ): Promise<[ILiquidity.NodeInfoStructOutput, ILiquidity.AccrualInfoStructOutput]>; + + liquidityNodes( + startTick: PromiseOrValue, + endTick: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + loans(receiptHash: PromiseOrValue, overrides?: CallOverrides): Promise; + + multicall(data: PromiseOrValue[], overrides?: CallOverrides): Promise; + + onCollateralLiquidated( + encodedLoanReceipt: PromiseOrValue, + proceeds: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + quote( + principal: PromiseOrValue, + duration: PromiseOrValue, + collateralToken: PromiseOrValue, + collateralTokenIds: PromiseOrValue[], + collateralTokenCount: PromiseOrValue, + ticks: PromiseOrValue[], + options: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + rates(overrides?: CallOverrides): Promise; + + rebalance( + srcTick: PromiseOrValue, + dstTick: PromiseOrValue, + redemptionId: PromiseOrValue, + minShares: PromiseOrValue, + overrides?: CallOverrides, + ): Promise<[BigNumber, BigNumber, BigNumber]>; + + redeem( + tick: PromiseOrValue, + shares: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + redemptionAvailable( + account: PromiseOrValue, + tick: PromiseOrValue, + redemptionId: PromiseOrValue, + overrides?: CallOverrides, + ): Promise< + [BigNumber, BigNumber, BigNumber] & { + shares: BigNumber; + amount: BigNumber; + sharesAhead: BigNumber; + } + >; + + redemptions( + account: PromiseOrValue, + tick: PromiseOrValue, + redemptionId: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + refinance( + encodedLoanReceipt: PromiseOrValue, + principal: PromiseOrValue, + duration: PromiseOrValue, + maxRepayment: PromiseOrValue, + ticks: PromiseOrValue[], + overrides?: CallOverrides, + ): Promise; + + repay(encodedLoanReceipt: PromiseOrValue, overrides?: CallOverrides): Promise; + + setAdminFeeRate(rate: PromiseOrValue, overrides?: CallOverrides): Promise; + + supportsInterface(interfaceId: PromiseOrValue, overrides?: CallOverrides): Promise; + + withdraw( + tick: PromiseOrValue, + redemptionId: PromiseOrValue, + overrides?: CallOverrides, + ): Promise<[BigNumber, BigNumber]>; + + withdrawAdminFees( + recipient: PromiseOrValue, + amount: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + }; + + filters: { + 'AdminFeeRateUpdated(uint256)'(rate?: null): AdminFeeRateUpdatedEventFilter; + AdminFeeRateUpdated(rate?: null): AdminFeeRateUpdatedEventFilter; + + 'AdminFeesWithdrawn(address,uint256)'( + account?: PromiseOrValue | null, + amount?: null, + ): AdminFeesWithdrawnEventFilter; + AdminFeesWithdrawn(account?: PromiseOrValue | null, amount?: null): AdminFeesWithdrawnEventFilter; + + 'CollateralLiquidated(bytes32,uint256,uint256)'( + loanReceiptHash?: PromiseOrValue | null, + proceeds?: null, + borrowerProceeds?: null, + ): CollateralLiquidatedEventFilter; + CollateralLiquidated( + loanReceiptHash?: PromiseOrValue | null, + proceeds?: null, + borrowerProceeds?: null, + ): CollateralLiquidatedEventFilter; + + 'Deposited(address,uint128,uint256,uint256)'( + account?: PromiseOrValue | null, + tick?: PromiseOrValue | null, + amount?: null, + shares?: null, + ): DepositedEventFilter; + Deposited( + account?: PromiseOrValue | null, + tick?: PromiseOrValue | null, + amount?: null, + shares?: null, + ): DepositedEventFilter; + + 'LoanLiquidated(bytes32)'(loanReceiptHash?: PromiseOrValue | null): LoanLiquidatedEventFilter; + LoanLiquidated(loanReceiptHash?: PromiseOrValue | null): LoanLiquidatedEventFilter; + + 'LoanOriginated(bytes32,bytes)'( + loanReceiptHash?: PromiseOrValue | null, + loanReceipt?: null, + ): LoanOriginatedEventFilter; + LoanOriginated(loanReceiptHash?: PromiseOrValue | null, loanReceipt?: null): LoanOriginatedEventFilter; + + 'LoanRepaid(bytes32,uint256)'( + loanReceiptHash?: PromiseOrValue | null, + repayment?: null, + ): LoanRepaidEventFilter; + LoanRepaid(loanReceiptHash?: PromiseOrValue | null, repayment?: null): LoanRepaidEventFilter; + + 'Redeemed(address,uint128,uint128,uint256)'( + account?: PromiseOrValue | null, + tick?: PromiseOrValue | null, + redemptionId?: PromiseOrValue | null, + shares?: null, + ): RedeemedEventFilter; + Redeemed( + account?: PromiseOrValue | null, + tick?: PromiseOrValue | null, + redemptionId?: PromiseOrValue | null, + shares?: null, + ): RedeemedEventFilter; + + 'Withdrawn(address,uint128,uint128,uint256,uint256)'( + account?: PromiseOrValue | null, + tick?: PromiseOrValue | null, + redemptionId?: PromiseOrValue | null, + shares?: null, + amount?: null, + ): WithdrawnEventFilter; + Withdrawn( + account?: PromiseOrValue | null, + tick?: PromiseOrValue | null, + redemptionId?: PromiseOrValue | null, + shares?: null, + amount?: null, + ): WithdrawnEventFilter; + }; + + estimateGas: { + BORROWER_SURPLUS_SPLIT_BASIS_POINTS(overrides?: CallOverrides): Promise; + + COLLATERAL_FILTER_NAME(overrides?: CallOverrides): Promise; + + COLLATERAL_FILTER_VERSION(overrides?: CallOverrides): Promise; + + IMPLEMENTATION_NAME(overrides?: CallOverrides): Promise; + + IMPLEMENTATION_VERSION(overrides?: CallOverrides): Promise; + + INTEREST_RATE_MODEL_NAME(overrides?: CallOverrides): Promise; + + INTEREST_RATE_MODEL_VERSION(overrides?: CallOverrides): Promise; + + TICK_LIMIT_SPACING_BASIS_POINTS(overrides?: CallOverrides): Promise; + + admin(overrides?: CallOverrides): Promise; + + adminFeeBalance(overrides?: CallOverrides): Promise; + + adminFeeRate(overrides?: CallOverrides): Promise; + + borrow( + principal: PromiseOrValue, + duration: PromiseOrValue, + collateralToken: PromiseOrValue, + collateralTokenId: PromiseOrValue, + maxRepayment: PromiseOrValue, + ticks: PromiseOrValue[], + options: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + collateralLiquidator(overrides?: CallOverrides): Promise; + + collateralToken(overrides?: CallOverrides): Promise; + + collateralWrappers(overrides?: CallOverrides): Promise; + + currencyToken(overrides?: CallOverrides): Promise; + + decodeLoanReceipt(loanReceipt: PromiseOrValue, overrides?: CallOverrides): Promise; + + delegationRegistry(overrides?: CallOverrides): Promise; + + deposit( + tick: PromiseOrValue, + amount: PromiseOrValue, + minShares: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + deposits( + account: PromiseOrValue, + tick: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + durations(overrides?: CallOverrides): Promise; + + initialize( + params: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + liquidate( + encodedLoanReceipt: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + liquidityNode(tick: PromiseOrValue, overrides?: CallOverrides): Promise; + + liquidityNodeWithAccrual(tick: PromiseOrValue, overrides?: CallOverrides): Promise; + + liquidityNodes( + startTick: PromiseOrValue, + endTick: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + loans(receiptHash: PromiseOrValue, overrides?: CallOverrides): Promise; + + multicall( + data: PromiseOrValue[], + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + onCollateralLiquidated( + encodedLoanReceipt: PromiseOrValue, + proceeds: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + quote( + principal: PromiseOrValue, + duration: PromiseOrValue, + collateralToken: PromiseOrValue, + collateralTokenIds: PromiseOrValue[], + collateralTokenCount: PromiseOrValue, + ticks: PromiseOrValue[], + options: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + rates(overrides?: CallOverrides): Promise; + + rebalance( + srcTick: PromiseOrValue, + dstTick: PromiseOrValue, + redemptionId: PromiseOrValue, + minShares: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + redeem( + tick: PromiseOrValue, + shares: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + redemptionAvailable( + account: PromiseOrValue, + tick: PromiseOrValue, + redemptionId: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + redemptions( + account: PromiseOrValue, + tick: PromiseOrValue, + redemptionId: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + refinance( + encodedLoanReceipt: PromiseOrValue, + principal: PromiseOrValue, + duration: PromiseOrValue, + maxRepayment: PromiseOrValue, + ticks: PromiseOrValue[], + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + repay( + encodedLoanReceipt: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + setAdminFeeRate( + rate: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + supportsInterface(interfaceId: PromiseOrValue, overrides?: CallOverrides): Promise; + + withdraw( + tick: PromiseOrValue, + redemptionId: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + withdrawAdminFees( + recipient: PromiseOrValue, + amount: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + }; + + populateTransaction: { + BORROWER_SURPLUS_SPLIT_BASIS_POINTS(overrides?: CallOverrides): Promise; + + COLLATERAL_FILTER_NAME(overrides?: CallOverrides): Promise; + + COLLATERAL_FILTER_VERSION(overrides?: CallOverrides): Promise; + + IMPLEMENTATION_NAME(overrides?: CallOverrides): Promise; + + IMPLEMENTATION_VERSION(overrides?: CallOverrides): Promise; + + INTEREST_RATE_MODEL_NAME(overrides?: CallOverrides): Promise; + + INTEREST_RATE_MODEL_VERSION(overrides?: CallOverrides): Promise; + + TICK_LIMIT_SPACING_BASIS_POINTS(overrides?: CallOverrides): Promise; + + admin(overrides?: CallOverrides): Promise; + + adminFeeBalance(overrides?: CallOverrides): Promise; + + adminFeeRate(overrides?: CallOverrides): Promise; + + borrow( + principal: PromiseOrValue, + duration: PromiseOrValue, + collateralToken: PromiseOrValue, + collateralTokenId: PromiseOrValue, + maxRepayment: PromiseOrValue, + ticks: PromiseOrValue[], + options: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + collateralLiquidator(overrides?: CallOverrides): Promise; + + collateralToken(overrides?: CallOverrides): Promise; + + collateralWrappers(overrides?: CallOverrides): Promise; + + currencyToken(overrides?: CallOverrides): Promise; + + decodeLoanReceipt(loanReceipt: PromiseOrValue, overrides?: CallOverrides): Promise; + + delegationRegistry(overrides?: CallOverrides): Promise; + + deposit( + tick: PromiseOrValue, + amount: PromiseOrValue, + minShares: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + deposits( + account: PromiseOrValue, + tick: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + durations(overrides?: CallOverrides): Promise; + + initialize( + params: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + liquidate( + encodedLoanReceipt: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + liquidityNode(tick: PromiseOrValue, overrides?: CallOverrides): Promise; + + liquidityNodeWithAccrual( + tick: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + liquidityNodes( + startTick: PromiseOrValue, + endTick: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + loans(receiptHash: PromiseOrValue, overrides?: CallOverrides): Promise; + + multicall( + data: PromiseOrValue[], + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + onCollateralLiquidated( + encodedLoanReceipt: PromiseOrValue, + proceeds: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + quote( + principal: PromiseOrValue, + duration: PromiseOrValue, + collateralToken: PromiseOrValue, + collateralTokenIds: PromiseOrValue[], + collateralTokenCount: PromiseOrValue, + ticks: PromiseOrValue[], + options: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + rates(overrides?: CallOverrides): Promise; + + rebalance( + srcTick: PromiseOrValue, + dstTick: PromiseOrValue, + redemptionId: PromiseOrValue, + minShares: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + redeem( + tick: PromiseOrValue, + shares: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + redemptionAvailable( + account: PromiseOrValue, + tick: PromiseOrValue, + redemptionId: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + redemptions( + account: PromiseOrValue, + tick: PromiseOrValue, + redemptionId: PromiseOrValue, + overrides?: CallOverrides, + ): Promise; + + refinance( + encodedLoanReceipt: PromiseOrValue, + principal: PromiseOrValue, + duration: PromiseOrValue, + maxRepayment: PromiseOrValue, + ticks: PromiseOrValue[], + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + repay( + encodedLoanReceipt: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + setAdminFeeRate( + rate: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + supportsInterface(interfaceId: PromiseOrValue, overrides?: CallOverrides): Promise; + + withdraw( + tick: PromiseOrValue, + redemptionId: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + + withdrawAdminFees( + recipient: PromiseOrValue, + amount: PromiseOrValue, + overrides?: Overrides & { from?: PromiseOrValue }, + ): Promise; + }; +} diff --git a/src/apps/metastreet/contracts/ethers/common.ts b/src/apps/metastreet/contracts/ethers/common.ts new file mode 100644 index 000000000..35f31be99 --- /dev/null +++ b/src/apps/metastreet/contracts/ethers/common.ts @@ -0,0 +1,32 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { Listener } from '@ethersproject/providers'; +import type { Event, EventFilter } from 'ethers'; + +export interface TypedEvent = any, TArgsObject = any> extends Event { + args: TArgsArray & TArgsObject; +} + +export interface TypedEventFilter<_TEvent extends TypedEvent> extends EventFilter {} + +export interface TypedListener { + (...listenerArg: [...__TypechainArgsArray, TEvent]): void; +} + +type __TypechainArgsArray = T extends TypedEvent ? U : never; + +export interface OnEvent { + (eventFilter: TypedEventFilter, listener: TypedListener): TRes; + (eventName: string, listener: Listener): TRes; +} + +export type MinEthersFactory = { + deploy(...a: ARGS[]): Promise; +}; + +export type GetContractTypeFromFactory = F extends MinEthersFactory ? C : never; + +export type GetARGsTypeFromFactory = F extends MinEthersFactory ? Parameters : never; + +export type PromiseOrValue = T | Promise; diff --git a/src/apps/metastreet/contracts/ethers/factories/Pool__factory.ts b/src/apps/metastreet/contracts/ethers/factories/Pool__factory.ts new file mode 100644 index 000000000..3a7b940a3 --- /dev/null +++ b/src/apps/metastreet/contracts/ethers/factories/Pool__factory.ts @@ -0,0 +1,1431 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from 'ethers'; +import type { Provider } from '@ethersproject/providers'; +import type { Pool, PoolInterface, WeightedInterestRateModel } from '../Pool'; + +const _abi = [ + { + inputs: [ + { + internalType: 'address', + name: 'collateralLiquidator', + type: 'address', + }, + { + internalType: 'address', + name: 'delegationRegistry', + type: 'address', + }, + { + internalType: 'address[]', + name: 'collateralWrappers', + type: 'address[]', + }, + { + components: [ + { + internalType: 'uint64', + name: 'tickThreshold', + type: 'uint64', + }, + { + internalType: 'uint64', + name: 'tickExponential', + type: 'uint64', + }, + ], + internalType: 'struct WeightedInterestRateModel.Parameters', + name: 'parameters', + type: 'tuple', + }, + ], + stateMutability: 'nonpayable', + type: 'constructor', + }, + { + inputs: [], + name: 'InactiveLiquidity', + type: 'error', + }, + { + inputs: [], + name: 'InsufficientLiquidity', + type: 'error', + }, + { + inputs: [], + name: 'InsufficientShares', + type: 'error', + }, + { + inputs: [], + name: 'InsufficientTickSpacing', + type: 'error', + }, + { + inputs: [], + name: 'InsufficientUtilization', + type: 'error', + }, + { + inputs: [], + name: 'InvalidBorrowOptions', + type: 'error', + }, + { + inputs: [], + name: 'InvalidCaller', + type: 'error', + }, + { + inputs: [], + name: 'InvalidCollateralFilterParameters', + type: 'error', + }, + { + inputs: [], + name: 'InvalidInterestRateModelParameters', + type: 'error', + }, + { + inputs: [], + name: 'InvalidLoanReceipt', + type: 'error', + }, + { + inputs: [], + name: 'InvalidParameters', + type: 'error', + }, + { + inputs: [], + name: 'InvalidReceiptEncoding', + type: 'error', + }, + { + inputs: [], + name: 'InvalidRedemptionStatus', + type: 'error', + }, + { + inputs: [], + name: 'InvalidTick', + type: 'error', + }, + { + inputs: [], + name: 'LoanNotExpired', + type: 'error', + }, + { + inputs: [], + name: 'RepaymentTooHigh', + type: 'error', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'index', + type: 'uint256', + }, + ], + name: 'UnsupportedCollateral', + type: 'error', + }, + { + inputs: [], + name: 'UnsupportedLoanDuration', + type: 'error', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint256', + name: 'rate', + type: 'uint256', + }, + ], + name: 'AdminFeeRateUpdated', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'account', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'AdminFeesWithdrawn', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'loanReceiptHash', + type: 'bytes32', + }, + { + indexed: false, + internalType: 'uint256', + name: 'proceeds', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'borrowerProceeds', + type: 'uint256', + }, + ], + name: 'CollateralLiquidated', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'account', + type: 'address', + }, + { + indexed: true, + internalType: 'uint128', + name: 'tick', + type: 'uint128', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'shares', + type: 'uint256', + }, + ], + name: 'Deposited', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'loanReceiptHash', + type: 'bytes32', + }, + ], + name: 'LoanLiquidated', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'loanReceiptHash', + type: 'bytes32', + }, + { + indexed: false, + internalType: 'bytes', + name: 'loanReceipt', + type: 'bytes', + }, + ], + name: 'LoanOriginated', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'loanReceiptHash', + type: 'bytes32', + }, + { + indexed: false, + internalType: 'uint256', + name: 'repayment', + type: 'uint256', + }, + ], + name: 'LoanRepaid', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'account', + type: 'address', + }, + { + indexed: true, + internalType: 'uint128', + name: 'tick', + type: 'uint128', + }, + { + indexed: true, + internalType: 'uint128', + name: 'redemptionId', + type: 'uint128', + }, + { + indexed: false, + internalType: 'uint256', + name: 'shares', + type: 'uint256', + }, + ], + name: 'Redeemed', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'account', + type: 'address', + }, + { + indexed: true, + internalType: 'uint128', + name: 'tick', + type: 'uint128', + }, + { + indexed: true, + internalType: 'uint128', + name: 'redemptionId', + type: 'uint128', + }, + { + indexed: false, + internalType: 'uint256', + name: 'shares', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'Withdrawn', + type: 'event', + }, + { + inputs: [], + name: 'BORROWER_SURPLUS_SPLIT_BASIS_POINTS', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'COLLATERAL_FILTER_NAME', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'pure', + type: 'function', + }, + { + inputs: [], + name: 'COLLATERAL_FILTER_VERSION', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'pure', + type: 'function', + }, + { + inputs: [], + name: 'IMPLEMENTATION_NAME', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'pure', + type: 'function', + }, + { + inputs: [], + name: 'IMPLEMENTATION_VERSION', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'pure', + type: 'function', + }, + { + inputs: [], + name: 'INTEREST_RATE_MODEL_NAME', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'pure', + type: 'function', + }, + { + inputs: [], + name: 'INTEREST_RATE_MODEL_VERSION', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'pure', + type: 'function', + }, + { + inputs: [], + name: 'TICK_LIMIT_SPACING_BASIS_POINTS', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'admin', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'adminFeeBalance', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'adminFeeRate', + outputs: [ + { + internalType: 'uint32', + name: '', + type: 'uint32', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'principal', + type: 'uint256', + }, + { + internalType: 'uint64', + name: 'duration', + type: 'uint64', + }, + { + internalType: 'address', + name: 'collateralToken', + type: 'address', + }, + { + internalType: 'uint256', + name: 'collateralTokenId', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'maxRepayment', + type: 'uint256', + }, + { + internalType: 'uint128[]', + name: 'ticks', + type: 'uint128[]', + }, + { + internalType: 'bytes', + name: 'options', + type: 'bytes', + }, + ], + name: 'borrow', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'collateralLiquidator', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'collateralToken', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'collateralWrappers', + outputs: [ + { + internalType: 'address[]', + name: '', + type: 'address[]', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'currencyToken', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes', + name: 'loanReceipt', + type: 'bytes', + }, + ], + name: 'decodeLoanReceipt', + outputs: [ + { + components: [ + { + internalType: 'uint8', + name: 'version', + type: 'uint8', + }, + { + internalType: 'uint256', + name: 'principal', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'repayment', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'adminFee', + type: 'uint256', + }, + { + internalType: 'address', + name: 'borrower', + type: 'address', + }, + { + internalType: 'uint64', + name: 'maturity', + type: 'uint64', + }, + { + internalType: 'uint64', + name: 'duration', + type: 'uint64', + }, + { + internalType: 'address', + name: 'collateralToken', + type: 'address', + }, + { + internalType: 'uint256', + name: 'collateralTokenId', + type: 'uint256', + }, + { + internalType: 'uint16', + name: 'collateralWrapperContextLen', + type: 'uint16', + }, + { + internalType: 'bytes', + name: 'collateralWrapperContext', + type: 'bytes', + }, + { + components: [ + { + internalType: 'uint128', + name: 'tick', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'used', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'pending', + type: 'uint128', + }, + ], + internalType: 'struct LoanReceipt.NodeReceipt[]', + name: 'nodeReceipts', + type: 'tuple[]', + }, + ], + internalType: 'struct LoanReceipt.LoanReceiptV2', + name: '', + type: 'tuple', + }, + ], + stateMutability: 'pure', + type: 'function', + }, + { + inputs: [], + name: 'delegationRegistry', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint128', + name: 'tick', + type: 'uint128', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'minShares', + type: 'uint256', + }, + ], + name: 'deposit', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + { + internalType: 'uint128', + name: 'tick', + type: 'uint128', + }, + ], + name: 'deposits', + outputs: [ + { + internalType: 'uint128', + name: 'shares', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'redemptionId', + type: 'uint128', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'durations', + outputs: [ + { + internalType: 'uint64[]', + name: '', + type: 'uint64[]', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes', + name: 'params', + type: 'bytes', + }, + ], + name: 'initialize', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes', + name: 'encodedLoanReceipt', + type: 'bytes', + }, + ], + name: 'liquidate', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint128', + name: 'tick', + type: 'uint128', + }, + ], + name: 'liquidityNode', + outputs: [ + { + components: [ + { + internalType: 'uint128', + name: 'tick', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'value', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'shares', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'available', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'pending', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'redemptions', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'prev', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'next', + type: 'uint128', + }, + ], + internalType: 'struct ILiquidity.NodeInfo', + name: '', + type: 'tuple', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint128', + name: 'tick', + type: 'uint128', + }, + ], + name: 'liquidityNodeWithAccrual', + outputs: [ + { + components: [ + { + internalType: 'uint128', + name: 'tick', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'value', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'shares', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'available', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'pending', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'redemptions', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'prev', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'next', + type: 'uint128', + }, + ], + internalType: 'struct ILiquidity.NodeInfo', + name: '', + type: 'tuple', + }, + { + components: [ + { + internalType: 'uint128', + name: 'accrued', + type: 'uint128', + }, + { + internalType: 'uint64', + name: 'rate', + type: 'uint64', + }, + { + internalType: 'uint64', + name: 'timestamp', + type: 'uint64', + }, + ], + internalType: 'struct ILiquidity.AccrualInfo', + name: '', + type: 'tuple', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint128', + name: 'startTick', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'endTick', + type: 'uint128', + }, + ], + name: 'liquidityNodes', + outputs: [ + { + components: [ + { + internalType: 'uint128', + name: 'tick', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'value', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'shares', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'available', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'pending', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'redemptions', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'prev', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'next', + type: 'uint128', + }, + ], + internalType: 'struct ILiquidity.NodeInfo[]', + name: '', + type: 'tuple[]', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'receiptHash', + type: 'bytes32', + }, + ], + name: 'loans', + outputs: [ + { + internalType: 'enum Pool.LoanStatus', + name: '', + type: 'uint8', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes[]', + name: 'data', + type: 'bytes[]', + }, + ], + name: 'multicall', + outputs: [ + { + internalType: 'bytes[]', + name: 'results', + type: 'bytes[]', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes', + name: 'encodedLoanReceipt', + type: 'bytes', + }, + { + internalType: 'uint256', + name: 'proceeds', + type: 'uint256', + }, + ], + name: 'onCollateralLiquidated', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'principal', + type: 'uint256', + }, + { + internalType: 'uint64', + name: 'duration', + type: 'uint64', + }, + { + internalType: 'address', + name: 'collateralToken', + type: 'address', + }, + { + internalType: 'uint256[]', + name: 'collateralTokenIds', + type: 'uint256[]', + }, + { + internalType: 'uint256', + name: 'collateralTokenCount', + type: 'uint256', + }, + { + internalType: 'uint128[]', + name: 'ticks', + type: 'uint128[]', + }, + { + internalType: 'bytes', + name: 'options', + type: 'bytes', + }, + ], + name: 'quote', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'rates', + outputs: [ + { + internalType: 'uint64[]', + name: '', + type: 'uint64[]', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint128', + name: 'srcTick', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'dstTick', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'redemptionId', + type: 'uint128', + }, + { + internalType: 'uint256', + name: 'minShares', + type: 'uint256', + }, + ], + name: 'rebalance', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint128', + name: 'tick', + type: 'uint128', + }, + { + internalType: 'uint256', + name: 'shares', + type: 'uint256', + }, + ], + name: 'redeem', + outputs: [ + { + internalType: 'uint128', + name: '', + type: 'uint128', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + { + internalType: 'uint128', + name: 'tick', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'redemptionId', + type: 'uint128', + }, + ], + name: 'redemptionAvailable', + outputs: [ + { + internalType: 'uint256', + name: 'shares', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'sharesAhead', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + { + internalType: 'uint128', + name: 'tick', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'redemptionId', + type: 'uint128', + }, + ], + name: 'redemptions', + outputs: [ + { + components: [ + { + internalType: 'uint128', + name: 'pending', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'index', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'target', + type: 'uint128', + }, + ], + internalType: 'struct Pool.Redemption', + name: '', + type: 'tuple', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes', + name: 'encodedLoanReceipt', + type: 'bytes', + }, + { + internalType: 'uint256', + name: 'principal', + type: 'uint256', + }, + { + internalType: 'uint64', + name: 'duration', + type: 'uint64', + }, + { + internalType: 'uint256', + name: 'maxRepayment', + type: 'uint256', + }, + { + internalType: 'uint128[]', + name: 'ticks', + type: 'uint128[]', + }, + ], + name: 'refinance', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes', + name: 'encodedLoanReceipt', + type: 'bytes', + }, + ], + name: 'repay', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint32', + name: 'rate', + type: 'uint32', + }, + ], + name: 'setAdminFeeRate', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes4', + name: 'interfaceId', + type: 'bytes4', + }, + ], + name: 'supportsInterface', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint128', + name: 'tick', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'redemptionId', + type: 'uint128', + }, + ], + name: 'withdraw', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'recipient', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'withdrawAdminFees', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, +]; + +export class Pool__factory { + static readonly abi = _abi; + static createInterface(): PoolInterface { + return new utils.Interface(_abi) as PoolInterface; + } + static connect(address: string, signerOrProvider: Signer | Provider): Pool { + return new Contract(address, _abi, signerOrProvider) as Pool; + } +} diff --git a/src/apps/metastreet/contracts/ethers/factories/index.ts b/src/apps/metastreet/contracts/ethers/factories/index.ts new file mode 100644 index 000000000..971eb52be --- /dev/null +++ b/src/apps/metastreet/contracts/ethers/factories/index.ts @@ -0,0 +1,4 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export { Pool__factory } from './Pool__factory'; diff --git a/src/apps/metastreet/contracts/ethers/index.ts b/src/apps/metastreet/contracts/ethers/index.ts new file mode 100644 index 000000000..54fa77d8f --- /dev/null +++ b/src/apps/metastreet/contracts/ethers/index.ts @@ -0,0 +1,6 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export type { Pool } from './Pool'; +export * as factories from './factories'; +export { Pool__factory } from './factories/Pool__factory'; diff --git a/src/apps/metastreet/contracts/index.ts b/src/apps/metastreet/contracts/index.ts new file mode 100644 index 000000000..82f8699ec --- /dev/null +++ b/src/apps/metastreet/contracts/index.ts @@ -0,0 +1,23 @@ +import { Injectable, Inject } from '@nestjs/common'; + +import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; +import { ContractFactory } from '~contract/contracts'; +import { Network } from '~types/network.interface'; + +import { Pool__factory } from './ethers'; + +// eslint-disable-next-line +type ContractOpts = { address: string; network: Network }; + +@Injectable() +export class MetastreetContractFactory extends ContractFactory { + constructor(@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit) { + super((network: Network) => appToolkit.getNetworkProvider(network)); + } + + pool({ address, network }: ContractOpts) { + return Pool__factory.connect(address, this.appToolkit.getNetworkProvider(network)); + } +} + +export type { Pool } from './ethers'; diff --git a/src/apps/metastreet/ethereum/metastreet.lending-v2.contract-position-fetcher.ts b/src/apps/metastreet/ethereum/metastreet.lending-v2.contract-position-fetcher.ts new file mode 100644 index 000000000..52130267c --- /dev/null +++ b/src/apps/metastreet/ethereum/metastreet.lending-v2.contract-position-fetcher.ts @@ -0,0 +1,311 @@ +import { Inject } from '@nestjs/common'; +import { BigNumberish, BigNumber, ethers } from 'ethers'; +import { gql } from 'graphql-request'; +import { sumBy } from 'lodash'; + +import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; +import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; + +import { ContractPositionTemplatePositionFetcher } from '~position/template/contract-position.template.position-fetcher'; +import { + GetDefinitionsParams, + GetTokenDefinitionsParams, + UnderlyingTokenDefinition, + GetDisplayPropsParams, + GetTokenBalancesParams, + GetDataPropsParams, +} from '~position/template/contract-position.template.types'; +import { ContractPositionBalance } from '~position/position-balance.interface'; +import { ContractPosition, MetaType } from '~position/position.interface'; + +import { MetastreetContractFactory, Pool } from '../contracts'; +import { DefaultDataProps } from '~position/display.interface'; + +export const GET_POOLS_QUERY = gql` + { + pools { + id + ticks { + id + limit + duration + rate + raw + } + currencyToken { + symbol + } + collateralToken { + name + } + } + } +`; + +function getDepositsQuery(address: string, pool: string) { + return gql` + { + pool(id: "${pool}") { + deposits(where: { account: "${address}" }) { + shares + tick { + id + value + shares + } + redemptions { + shares + } + } + } + } + `; +} + +function getAllDepositsQuery(address: string) { + return gql` + { + pools { + deposits(where: { account: "${address}" }) { + shares + tick { + id + value + shares + } + redemptions { + shares + } + } + } + } + `; +} + +export type GetPoolsResponse = { + pools: { + id: string; + ticks: { + id: string; + limit: BigNumber; + duration: BigNumber; + rate: BigNumber; + raw: BigNumber; + }[]; + currencyToken: string; + collateralToken: string; + }[]; +}; + +export type GetAllDepositsResponse = { + pools: { + deposits: { + shares: BigNumber; + tick: { + id: string; + shares: BigNumber; + value: BigNumber; + }; + redemptions: { + shares: BigNumber; + }[]; + }[]; + }[]; +}; + +export type GetDepositsResponse = { + pool: { + deposits: { + shares: BigNumber; + tick: { + id: string; + shares: BigNumber; + value: BigNumber; + }; + redemptions: { + shares: BigNumber; + }[]; + }[]; + }; +}; + +export const SUBGRAPH_URL = 'https://api.thegraph.com/subgraphs/name/metastreet-labs/metastreet-v2-beta'; + +export type ContractPositionDefinition = { + address: string; + tickId: string; + tick: BigNumber; + limit: BigNumber; + duration: BigNumber; + rate: BigNumber; + currencyTokenSymbol: string; + collateralTokenName: string; +}; + +export type DataProps = { + positionKey: string; // tick id + tick: BigNumber; // encoded tick +}; + +@PositionTemplate() +export class EthereumMetastreetLendingV2ContractPositionFetcher extends ContractPositionTemplatePositionFetcher { + groupLabel: string = 'Lending'; + + constructor( + @Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit, + @Inject(MetastreetContractFactory) protected readonly metastreetContractFactory: MetastreetContractFactory, + ) { + super(appToolkit); + } + + getContract(_address: string): Pool { + return this.metastreetContractFactory.pool({ address: _address, network: this.network }); + } + + async getDefinitions(_params: GetDefinitionsParams): Promise { + const data = await gqlFetch({ + endpoint: SUBGRAPH_URL, + query: GET_POOLS_QUERY, + }); + + return data.pools.flatMap(p => { + return p.ticks.map(t => ({ + address: p.id, + tickId: t.id, + tick: t.raw, + limit: t.limit, + duration: t.duration, + rate: t.rate, + currencyTokenSymbol: p.currencyToken['symbol'], + collateralTokenName: p.collateralToken['name'], + })); + }); + } + + async getTokenDefinitions( + _params: GetTokenDefinitionsParams, + ): Promise { + const pool: Pool = _params.contract; + return [ + { + metaType: MetaType.CLAIMABLE, + address: await pool.currencyToken(), + network: this.network, + }, + ]; + } + + async getDataProps(_params: GetDataPropsParams): Promise { + return { + positionKey: `${_params.definition.tickId}`, + tick: _params.definition.tick, + }; + } + + async getLabel(_params: GetDisplayPropsParams): Promise { + const collateralTokenName: string = _params.definition.collateralTokenName; // e.g. Wrapped Cryptopunks + const currencyTokenSymbol: string = _params.definition.currencyTokenSymbol; // e.g. WETH + const duration: string = BigNumber.from(_params.definition.duration).lt(86400) + ? '0' + : BigNumber.from(_params.definition.duration).div(86400).mask(17).toString(); // round to closest days + const limit: number = BigNumber.from(_params.definition.limit).lt(1e15) + ? 0 + : BigNumber.from(_params.definition.limit).div(1e15).toNumber() / 1000; + const apr: BigNumber = BigNumber.from(_params.definition.rate).mul(365 * 86400); + const rate: number = Math.round(apr.lt(1e15) ? 0 : apr.div(1e15).toNumber() / 10); + const labelPrefix = + collateralTokenName && currencyTokenSymbol ? `${collateralTokenName} / ${currencyTokenSymbol} - ` : ''; + + // e.g. "Wrapped Cryptopunks / DAI - 30 Day, 10%, 630000 DAI" + return `${labelPrefix}${duration} Day, ${rate}%, ${limit} ${currencyTokenSymbol}`; + } + + async getBalances(_address: string): Promise[]> { + const address = await this.getAccountAddress(_address); + if (address === ZERO_ADDRESS) return []; + + /* Get ticks that the account has interacted with */ + const data = await gqlFetch({ + endpoint: SUBGRAPH_URL, + query: getAllDepositsQuery(address), + }); + + /* tick id as key, balances as value */ + const tickBalances = {}; + + /* compute account balance for each tick and add an entry to tickBalances */ + data.pools.forEach(p => { + p.deposits.forEach(d => { + const tickShares = BigNumber.from(d.tick.shares); + const tickValue = BigNumber.from(d.tick.value); + const redeemedShares = BigNumber.from( + d.redemptions.reduce((partialSum, r) => partialSum.add(r.shares), ethers.constants.Zero), + ); + const userShares = BigNumber.from(d.shares).add(redeemedShares); + const balance = tickShares.eq(ethers.constants.Zero) + ? ethers.constants.Zero + : tickValue.mul(userShares).div(tickShares); + + /* only add an etnry if balance is non-zero */ + if (balance.gt(ethers.constants.Zero)) { + tickBalances[d.tick.id] = [balance]; + } + }); + }); + + /* Get all positions from all pools */ + const contractPositions = await this.getPositionsForBalances(); + + /* Filter out positions based on account's tick balances */ + const filteredPositions = contractPositions.reduce( + (positions: [ContractPosition, BigNumber][], cp: ContractPosition) => { + if (cp.dataProps.positionKey in tickBalances) { + positions.push([cp, tickBalances[cp.dataProps.positionKey]]); + } + return positions; + }, + [], + ); + + const balances = await Promise.all( + filteredPositions.map(async contractPositionAndBalance => { + const [contractPosition, balancesRaw] = contractPositionAndBalance; + const allTokens = contractPosition.tokens.map((cp, idx) => + drillBalance(cp, balancesRaw[idx]?.toString() ?? '0', { isDebt: cp.metaType === MetaType.BORROWED }), + ); + + const tokens = allTokens.filter(v => Math.abs(v.balanceUSD) > 0.01); + const balanceUSD = sumBy(tokens, t => t.balanceUSD); + + const balance = { ...contractPosition, tokens, balanceUSD }; + return balance; + }), + ); + return balances; + } + + async getTokenBalancesPerPosition(_params: GetTokenBalancesParams): Promise { + const data = await gqlFetch({ + endpoint: SUBGRAPH_URL, + query: getDepositsQuery(_params.address, _params.contractPosition.address), + }); + let balance = ethers.constants.Zero; + data.pool.deposits.forEach(d => { + if (d.tick.id === _params.contractPosition.dataProps.positionKey) { + const tickShares = BigNumber.from(d.tick.shares); + const tickValue = BigNumber.from(d.tick.value); + const redeemedShares = BigNumber.from( + d.redemptions.reduce((partialSum, r) => partialSum.add(r.shares), ethers.constants.Zero), + ); + const userShares = BigNumber.from(d.shares).add(redeemedShares); + balance = balance.add( + tickShares.eq(ethers.constants.Zero) ? ethers.constants.Zero : tickValue.mul(userShares).div(tickShares), + ); + } + }); + return [balance]; + } +} diff --git a/src/apps/metastreet/metastreet.module.ts b/src/apps/metastreet/metastreet.module.ts new file mode 100644 index 000000000..b86ef59f1 --- /dev/null +++ b/src/apps/metastreet/metastreet.module.ts @@ -0,0 +1,11 @@ +import { Module } from '@nestjs/common'; + +import { AbstractApp } from '~app/app.dynamic-module'; + +import { MetastreetContractFactory } from './contracts'; +import { EthereumMetastreetLendingV2ContractPositionFetcher } from './ethereum/metastreet.lending-v2.contract-position-fetcher'; + +@Module({ + providers: [EthereumMetastreetLendingV2ContractPositionFetcher, MetastreetContractFactory], +}) +export class MetastreetAppModule extends AbstractApp() {}