diff --git a/apps/local b/apps/local deleted file mode 160000 index a4b70ab..0000000 --- a/apps/local +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a4b70ab823dc305df2fcf928d9155f923e13056f diff --git a/bun.lockb b/bun.lockb index 0537bbb..8e232c3 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/packages/subgraph/.gitignore b/packages/subgraph/.gitignore new file mode 100644 index 0000000..1373657 --- /dev/null +++ b/packages/subgraph/.gitignore @@ -0,0 +1,37 @@ +# Graph CLI generated artifacts +build/ +generated/ + +# Dependency directories +node_modules/ +jspm_packages/ + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# dotenv environment variables file +.env + +# Testing +coverage +coverage.json + +# Typechain +typechain +typechain-types + +# Hardhat files +cache + +# note: we commit subgraph.template.yaml, but the subgraph.yaml is generated +subgraph.yaml diff --git a/packages/subgraph/Dockerfile b/packages/subgraph/Dockerfile new file mode 100644 index 0000000..7ec4a54 --- /dev/null +++ b/packages/subgraph/Dockerfile @@ -0,0 +1,28 @@ +FROM --platform=linux/x86_64 ubuntu:22.04 + +ARG DEBIAN_FRONTEND=noninteractive + +ENV ARGS="" + +RUN apt update \ + && apt install -y sudo curl postgresql postgresql-contrib + +RUN curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - \ + && sudo apt-get install -y nodejs + +RUN curl -OL https://github.com/LimeChain/matchstick/releases/download/0.6.0/binary-linux-22 \ + && chmod a+x binary-linux-22 + +WORKDIR /app + +# Copy package files +COPY package.json . +COPY package-lock.json* . + +# Install dependencies +RUN npm install + +# Copy the rest of the application +COPY . . + +CMD ../binary-linux-22 ${ARGS} diff --git a/packages/subgraph/README.md b/packages/subgraph/README.md new file mode 100644 index 0000000..e83bbd6 --- /dev/null +++ b/packages/subgraph/README.md @@ -0,0 +1,7 @@ +# PWNDAO subgraph + +## How to build / run +1) `bun install` from root folder +2) `bunx nx codegen @pwndao/subgraph` +3) choose what network you want to build your subgraph on, and then run e.g. `bunx nx prepare:sepolia @pwndao/subgraph` +4) `bunx nx build @pwndao/subgraph` \ No newline at end of file diff --git a/packages/subgraph/abis/ChainlinkFeedRegistry.json b/packages/subgraph/abis/ChainlinkFeedRegistry.json new file mode 100644 index 0000000..5588293 --- /dev/null +++ b/packages/subgraph/abis/ChainlinkFeedRegistry.json @@ -0,0 +1,530 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "accessController", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "AccessControllerSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "asset", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "denomination", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "latestAggregator", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "previousAggregator", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint16", + "name": "nextPhaseId", + "type": "uint16" + }, + { + "indexed": false, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "FeedConfirmed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "asset", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "denomination", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "proposedAggregator", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "currentAggregator", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "FeedProposed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "OwnershipTransferRequested", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "inputs": [], + "name": "acceptOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" }, + { "internalType": "address", "name": "aggregator", "type": "address" } + ], + "name": "confirmFeed", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" } + ], + "name": "decimals", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" } + ], + "name": "description", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getAccessController", + "outputs": [ + { + "internalType": "contract AccessControllerInterface", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" }, + { "internalType": "uint256", "name": "roundId", "type": "uint256" } + ], + "name": "getAnswer", + "outputs": [ + { "internalType": "int256", "name": "answer", "type": "int256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" } + ], + "name": "getCurrentPhaseId", + "outputs": [ + { "internalType": "uint16", "name": "currentPhaseId", "type": "uint16" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" } + ], + "name": "getFeed", + "outputs": [ + { + "internalType": "contract AggregatorV2V3Interface", + "name": "aggregator", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" }, + { "internalType": "uint80", "name": "roundId", "type": "uint80" } + ], + "name": "getNextRoundId", + "outputs": [ + { "internalType": "uint80", "name": "nextRoundId", "type": "uint80" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" }, + { "internalType": "uint16", "name": "phaseId", "type": "uint16" } + ], + "name": "getPhase", + "outputs": [ + { + "components": [ + { "internalType": "uint16", "name": "phaseId", "type": "uint16" }, + { + "internalType": "uint80", + "name": "startingAggregatorRoundId", + "type": "uint80" + }, + { + "internalType": "uint80", + "name": "endingAggregatorRoundId", + "type": "uint80" + } + ], + "internalType": "struct FeedRegistryInterface.Phase", + "name": "phase", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" }, + { "internalType": "uint16", "name": "phaseId", "type": "uint16" } + ], + "name": "getPhaseFeed", + "outputs": [ + { + "internalType": "contract AggregatorV2V3Interface", + "name": "aggregator", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" }, + { "internalType": "uint16", "name": "phaseId", "type": "uint16" } + ], + "name": "getPhaseRange", + "outputs": [ + { "internalType": "uint80", "name": "startingRoundId", "type": "uint80" }, + { "internalType": "uint80", "name": "endingRoundId", "type": "uint80" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" }, + { "internalType": "uint80", "name": "roundId", "type": "uint80" } + ], + "name": "getPreviousRoundId", + "outputs": [ + { "internalType": "uint80", "name": "previousRoundId", "type": "uint80" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" } + ], + "name": "getProposedFeed", + "outputs": [ + { + "internalType": "contract AggregatorV2V3Interface", + "name": "proposedAggregator", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" }, + { "internalType": "uint80", "name": "_roundId", "type": "uint80" } + ], + "name": "getRoundData", + "outputs": [ + { "internalType": "uint80", "name": "roundId", "type": "uint80" }, + { "internalType": "int256", "name": "answer", "type": "int256" }, + { "internalType": "uint256", "name": "startedAt", "type": "uint256" }, + { "internalType": "uint256", "name": "updatedAt", "type": "uint256" }, + { "internalType": "uint80", "name": "answeredInRound", "type": "uint80" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" }, + { "internalType": "uint80", "name": "roundId", "type": "uint80" } + ], + "name": "getRoundFeed", + "outputs": [ + { + "internalType": "contract AggregatorV2V3Interface", + "name": "aggregator", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" }, + { "internalType": "uint256", "name": "roundId", "type": "uint256" } + ], + "name": "getTimestamp", + "outputs": [ + { "internalType": "uint256", "name": "timestamp", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "aggregator", "type": "address" } + ], + "name": "isFeedEnabled", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" } + ], + "name": "latestAnswer", + "outputs": [ + { "internalType": "int256", "name": "answer", "type": "int256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" } + ], + "name": "latestRound", + "outputs": [ + { "internalType": "uint256", "name": "roundId", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" } + ], + "name": "latestRoundData", + "outputs": [ + { "internalType": "uint80", "name": "roundId", "type": "uint80" }, + { "internalType": "int256", "name": "answer", "type": "int256" }, + { "internalType": "uint256", "name": "startedAt", "type": "uint256" }, + { "internalType": "uint256", "name": "updatedAt", "type": "uint256" }, + { "internalType": "uint80", "name": "answeredInRound", "type": "uint80" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" } + ], + "name": "latestTimestamp", + "outputs": [ + { "internalType": "uint256", "name": "timestamp", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" }, + { "internalType": "address", "name": "aggregator", "type": "address" } + ], + "name": "proposeFeed", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" }, + { "internalType": "uint80", "name": "roundId", "type": "uint80" } + ], + "name": "proposedGetRoundData", + "outputs": [ + { "internalType": "uint80", "name": "id", "type": "uint80" }, + { "internalType": "int256", "name": "answer", "type": "int256" }, + { "internalType": "uint256", "name": "startedAt", "type": "uint256" }, + { "internalType": "uint256", "name": "updatedAt", "type": "uint256" }, + { "internalType": "uint80", "name": "answeredInRound", "type": "uint80" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" } + ], + "name": "proposedLatestRoundData", + "outputs": [ + { "internalType": "uint80", "name": "id", "type": "uint80" }, + { "internalType": "int256", "name": "answer", "type": "int256" }, + { "internalType": "uint256", "name": "startedAt", "type": "uint256" }, + { "internalType": "uint256", "name": "updatedAt", "type": "uint256" }, + { "internalType": "uint80", "name": "answeredInRound", "type": "uint80" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract AccessControllerInterface", + "name": "_accessController", + "type": "address" + } + ], + "name": "setAccessController", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "to", "type": "address" }], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "typeAndVersion", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "base", "type": "address" }, + { "internalType": "address", "name": "quote", "type": "address" } + ], + "name": "version", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + } +] diff --git a/packages/subgraph/abis/Config.json b/packages/subgraph/abis/Config.json new file mode 100644 index 0000000..5fd650d --- /dev/null +++ b/packages/subgraph/abis/Config.json @@ -0,0 +1,357 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "_logic", "type": "address" }, + { "internalType": "address", "name": "admin_", "type": "address" }, + { "internalType": "bytes", "name": "_data", "type": "bytes" } + ], + "stateMutability": "payable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "previousAdmin", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "newAdmin", + "type": "address" + } + ], + "name": "AdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "beacon", + "type": "address" + } + ], + "name": "BeaconUpgraded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "implementation", + "type": "address" + } + ], + "name": "Upgraded", + "type": "event" + }, + { "stateMutability": "payable", "type": "fallback" }, + { "stateMutability": "payable", "type": "receive" }, + { "type": "constructor", "inputs": [], "stateMutability": "nonpayable" }, + { + "type": "function", + "name": "MAX_FEE", + "inputs": [], + "outputs": [{ "name": "", "type": "uint16", "internalType": "uint16" }], + "stateMutability": "view" + }, + { + "type": "function", + "name": "acceptOwnership", + "inputs": [], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "fee", + "inputs": [], + "outputs": [{ "name": "", "type": "uint16", "internalType": "uint16" }], + "stateMutability": "view" + }, + { + "type": "function", + "name": "feeCollector", + "inputs": [], + "outputs": [{ "name": "", "type": "address", "internalType": "address" }], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getPoolAdapter", + "inputs": [ + { "name": "pool", "type": "address", "internalType": "address" } + ], + "outputs": [ + { "name": "", "type": "address", "internalType": "contract IPoolAdapter" } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getStateFingerprintComputer", + "inputs": [ + { "name": "asset", "type": "address", "internalType": "address" } + ], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "contract IStateFingerpringComputer" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "initialize", + "inputs": [ + { "name": "_owner", "type": "address", "internalType": "address" }, + { "name": "_fee", "type": "uint16", "internalType": "uint16" }, + { "name": "_feeCollector", "type": "address", "internalType": "address" } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "loanMetadataUri", + "inputs": [ + { "name": "loanContract", "type": "address", "internalType": "address" } + ], + "outputs": [{ "name": "uri", "type": "string", "internalType": "string" }], + "stateMutability": "view" + }, + { + "type": "function", + "name": "owner", + "inputs": [], + "outputs": [{ "name": "", "type": "address", "internalType": "address" }], + "stateMutability": "view" + }, + { + "type": "function", + "name": "pendingOwner", + "inputs": [], + "outputs": [{ "name": "", "type": "address", "internalType": "address" }], + "stateMutability": "view" + }, + { + "type": "function", + "name": "registerPoolAdapter", + "inputs": [ + { "name": "pool", "type": "address", "internalType": "address" }, + { "name": "adapter", "type": "address", "internalType": "address" } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "registerStateFingerprintComputer", + "inputs": [ + { "name": "asset", "type": "address", "internalType": "address" }, + { "name": "computer", "type": "address", "internalType": "address" } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "renounceOwnership", + "inputs": [], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "setDefaultLOANMetadataUri", + "inputs": [ + { "name": "metadataUri", "type": "string", "internalType": "string" } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "setFee", + "inputs": [{ "name": "_fee", "type": "uint16", "internalType": "uint16" }], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "setFeeCollector", + "inputs": [ + { "name": "_feeCollector", "type": "address", "internalType": "address" } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "setLOANMetadataUri", + "inputs": [ + { "name": "loanContract", "type": "address", "internalType": "address" }, + { "name": "metadataUri", "type": "string", "internalType": "string" } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "transferOwnership", + "inputs": [ + { "name": "newOwner", "type": "address", "internalType": "address" } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "event", + "name": "DefaultLOANMetadataUriUpdated", + "inputs": [ + { + "name": "newUri", + "type": "string", + "indexed": false, + "internalType": "string" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "FeeCollectorUpdated", + "inputs": [ + { + "name": "oldFeeCollector", + "type": "address", + "indexed": false, + "internalType": "address" + }, + { + "name": "newFeeCollector", + "type": "address", + "indexed": false, + "internalType": "address" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "FeeUpdated", + "inputs": [ + { + "name": "oldFee", + "type": "uint16", + "indexed": false, + "internalType": "uint16" + }, + { + "name": "newFee", + "type": "uint16", + "indexed": false, + "internalType": "uint16" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "Initialized", + "inputs": [ + { + "name": "version", + "type": "uint8", + "indexed": false, + "internalType": "uint8" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "LOANMetadataUriUpdated", + "inputs": [ + { + "name": "loanContract", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "newUri", + "type": "string", + "indexed": false, + "internalType": "string" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "OwnershipTransferStarted", + "inputs": [ + { + "name": "previousOwner", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "newOwner", + "type": "address", + "indexed": true, + "internalType": "address" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "OwnershipTransferred", + "inputs": [ + { + "name": "previousOwner", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "newOwner", + "type": "address", + "indexed": true, + "internalType": "address" + } + ], + "anonymous": false + }, + { + "type": "error", + "name": "InvalidComputerContract", + "inputs": [ + { "name": "computer", "type": "address", "internalType": "address" }, + { "name": "asset", "type": "address", "internalType": "address" } + ] + }, + { + "type": "error", + "name": "InvalidFeeValue", + "inputs": [ + { "name": "fee", "type": "uint256", "internalType": "uint256" }, + { "name": "limit", "type": "uint256", "internalType": "uint256" } + ] + }, + { "type": "error", "name": "ZeroFeeCollector", "inputs": [] }, + { "type": "error", "name": "ZeroLoanContract", "inputs": [] } +] diff --git a/packages/subgraph/abis/Hub.json b/packages/subgraph/abis/Hub.json new file mode 100644 index 0000000..ed06efc --- /dev/null +++ b/packages/subgraph/abis/Hub.json @@ -0,0 +1,198 @@ +[ + { + "type": "constructor", + "inputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "acceptOwnership", + "inputs": [], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "hasTag", + "inputs": [ + { + "name": "_address", + "type": "address", + "internalType": "address" + }, + { + "name": "tag", + "type": "bytes32", + "internalType": "bytes32" + } + ], + "outputs": [ + { + "name": "", + "type": "bool", + "internalType": "bool" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "owner", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "pendingOwner", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "renounceOwnership", + "inputs": [], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "setTag", + "inputs": [ + { + "name": "_address", + "type": "address", + "internalType": "address" + }, + { + "name": "tag", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "_hasTag", + "type": "bool", + "internalType": "bool" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "setTags", + "inputs": [ + { + "name": "_addresses", + "type": "address[]", + "internalType": "address[]" + }, + { + "name": "_tags", + "type": "bytes32[]", + "internalType": "bytes32[]" + }, + { + "name": "_hasTag", + "type": "bool", + "internalType": "bool" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "transferOwnership", + "inputs": [ + { + "name": "newOwner", + "type": "address", + "internalType": "address" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "event", + "name": "OwnershipTransferStarted", + "inputs": [ + { + "name": "previousOwner", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "newOwner", + "type": "address", + "indexed": true, + "internalType": "address" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "OwnershipTransferred", + "inputs": [ + { + "name": "previousOwner", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "newOwner", + "type": "address", + "indexed": true, + "internalType": "address" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "TagSet", + "inputs": [ + { + "name": "_address", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "tag", + "type": "bytes32", + "indexed": true, + "internalType": "bytes32" + }, + { + "name": "hasTag", + "type": "bool", + "indexed": false, + "internalType": "bool" + } + ], + "anonymous": false + }, + { + "type": "error", + "name": "InvalidInputData", + "inputs": [] + } +] \ No newline at end of file diff --git a/packages/subgraph/abis/LoanToken.json b/packages/subgraph/abis/LoanToken.json new file mode 100644 index 0000000..04e4d18 --- /dev/null +++ b/packages/subgraph/abis/LoanToken.json @@ -0,0 +1,292 @@ +[ + { + "inputs": [{ "internalType": "address", "name": "hub", "type": "address" }], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "name": "CallerMissingHubTag", + "type": "error" + }, + { "inputs": [], "name": "InvalidLoanContractCaller", "type": "error" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "approved", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "operator", + "type": "address" + }, + { + "indexed": false, + "internalType": "bool", + "name": "approved", + "type": "bool" + } + ], + "name": "ApprovalForAll", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "loanId", + "type": "uint256" + } + ], + "name": "LOANBurned", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "loanId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "loanContract", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "LOANMinted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "inputs": [ + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "tokenId", "type": "uint256" } + ], + "name": "approve", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" } + ], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "loanId", "type": "uint256" } + ], + "name": "burn", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "tokenId", "type": "uint256" } + ], + "name": "getApproved", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "tokenId", "type": "uint256" } + ], + "name": "getStateFingerprint", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "operator", "type": "address" } + ], + "name": "isApprovedForAll", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "lastLoanId", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "name": "loanContract", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" } + ], + "name": "mint", + "outputs": [ + { "internalType": "uint256", "name": "loanId", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "tokenId", "type": "uint256" } + ], + "name": "ownerOf", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "tokenId", "type": "uint256" } + ], + "name": "safeTransferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "tokenId", "type": "uint256" }, + { "internalType": "bytes", "name": "data", "type": "bytes" } + ], + "name": "safeTransferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "operator", "type": "address" }, + { "internalType": "bool", "name": "approved", "type": "bool" } + ], + "name": "setApprovalForAll", + "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": [], + "name": "symbol", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "tokenId", "type": "uint256" } + ], + "name": "tokenURI", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "tokenId", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/packages/subgraph/abis/MultiTokenCategoryRegistry.json b/packages/subgraph/abis/MultiTokenCategoryRegistry.json new file mode 100644 index 0000000..6b9e61d --- /dev/null +++ b/packages/subgraph/abis/MultiTokenCategoryRegistry.json @@ -0,0 +1,154 @@ +[ + { "inputs": [], "name": "ReservedCategoryValue", "type": "error" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint8", + "name": "category", + "type": "uint8" + } + ], + "name": "CategoryRegistered", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "assetAddress", + "type": "address" + } + ], + "name": "CategoryUnregistered", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferStarted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "inputs": [], + "name": "CATEGORY_NOT_REGISTERED", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "acceptOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "pendingOwner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "assetAddress", "type": "address" }, + { "internalType": "uint8", "name": "category", "type": "uint8" } + ], + "name": "registerCategoryValue", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "assetAddress", "type": "address" } + ], + "name": "registeredCategoryValue", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "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": "address", "name": "newOwner", "type": "address" } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "assetAddress", "type": "address" } + ], + "name": "unregisterCategoryValue", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/packages/subgraph/abis/SimpleLoan.json b/packages/subgraph/abis/SimpleLoan.json new file mode 100644 index 0000000..be22f0a --- /dev/null +++ b/packages/subgraph/abis/SimpleLoan.json @@ -0,0 +1,1100 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "_hub", "type": "address" }, + { "internalType": "address", "name": "_loanToken", "type": "address" }, + { "internalType": "address", "name": "_config", "type": "address" }, + { "internalType": "address", "name": "_revokedNonce", "type": "address" }, + { + "internalType": "address", + "name": "_categoryRegistry", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" }, + { "internalType": "bytes32", "name": "tag", "type": "bytes32" } + ], + "name": "AddressMissingHubTag", + "type": "error" + }, + { "inputs": [], "name": "CallerNotLOANTokenHolder", "type": "error" }, + { "inputs": [], "name": "CallerNotVault", "type": "error" }, + { + "inputs": [ + { "internalType": "uint256", "name": "current", "type": "uint256" }, + { "internalType": "uint256", "name": "expiration", "type": "uint256" } + ], + "name": "Expired", + "type": "error" + }, + { "inputs": [], "name": "IncompleteTransfer", "type": "error" }, + { + "inputs": [ + { "internalType": "uint256", "name": "current", "type": "uint256" }, + { "internalType": "uint256", "name": "limit", "type": "uint256" } + ], + "name": "InterestAPROutOfBounds", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "current", "type": "uint256" }, + { "internalType": "uint256", "name": "limit", "type": "uint256" } + ], + "name": "InvalidDuration", + "type": "error" + }, + { "inputs": [], "name": "InvalidExtensionCaller", "type": "error" }, + { + "inputs": [ + { "internalType": "uint256", "name": "duration", "type": "uint256" }, + { "internalType": "uint256", "name": "limit", "type": "uint256" } + ], + "name": "InvalidExtensionDuration", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "allowed", "type": "address" }, + { "internalType": "address", "name": "current", "type": "address" } + ], + "name": "InvalidExtensionSigner", + "type": "error" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "current", "type": "bytes32" }, + { "internalType": "bytes32", "name": "expected", "type": "bytes32" } + ], + "name": "InvalidLenderSpecHash", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint8", "name": "category", "type": "uint8" }, + { "internalType": "address", "name": "addr", "type": "address" }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "InvalidMultiTokenAsset", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "signer", "type": "address" }, + { "internalType": "bytes32", "name": "digest", "type": "bytes32" } + ], + "name": "InvalidSignature", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "length", "type": "uint256" } + ], + "name": "InvalidSignatureLength", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "sourceOfFunds", "type": "address" } + ], + "name": "InvalidSourceOfFunds", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint40", "name": "timestap", "type": "uint40" } + ], + "name": "LoanDefaulted", + "type": "error" + }, + { "inputs": [], "name": "LoanNotAutoclaimable", "type": "error" }, + { "inputs": [], "name": "LoanNotRepaid", "type": "error" }, + { "inputs": [], "name": "LoanNotRunning", "type": "error" }, + { "inputs": [], "name": "LoanRepaid", "type": "error" }, + { "inputs": [], "name": "LoanRunning", "type": "error" }, + { "inputs": [], "name": "NonExistingLoan", "type": "error" }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" }, + { "internalType": "uint256", "name": "nonceSpace", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" } + ], + "name": "NonceNotUsable", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "currentBorrower", + "type": "address" + }, + { "internalType": "address", "name": "newBorrower", "type": "address" } + ], + "name": "RefinanceBorrowerMismatch", + "type": "error" + }, + { "inputs": [], "name": "RefinanceCollateralMismatch", "type": "error" }, + { "inputs": [], "name": "RefinanceCreditMismatch", "type": "error" }, + { + "inputs": [ + { "internalType": "uint8", "name": "categoryValue", "type": "uint8" } + ], + "name": "UnsupportedCategory", + "type": "error" + }, + { "inputs": [], "name": "UnsupportedTransferFunction", "type": "error" }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" } + ], + "name": "VaultTransferSameSourceAndDestination", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "extensionHash", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "proposer", + "type": "address" + }, + { + "components": [ + { "internalType": "uint256", "name": "loanId", "type": "uint256" }, + { + "internalType": "address", + "name": "compensationAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "compensationAmount", + "type": "uint256" + }, + { "internalType": "uint40", "name": "duration", "type": "uint40" }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" } + ], + "indexed": false, + "internalType": "struct PWNSimpleLoan.ExtensionProposal", + "name": "proposal", + "type": "tuple" + } + ], + "name": "ExtensionProposalMade", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "loanId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "bool", + "name": "defaulted", + "type": "bool" + } + ], + "name": "LOANClaimed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "loanId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "proposalHash", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "proposalContract", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "components": [ + { "internalType": "address", "name": "lender", "type": "address" }, + { "internalType": "address", "name": "borrower", "type": "address" }, + { "internalType": "uint32", "name": "duration", "type": "uint32" }, + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "internalType": "struct MultiToken.Asset", + "name": "collateral", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "internalType": "struct MultiToken.Asset", + "name": "credit", + "type": "tuple" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "bytes32", + "name": "lenderSpecHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "borrowerSpecHash", + "type": "bytes32" + } + ], + "indexed": false, + "internalType": "struct PWNSimpleLoan.Terms", + "name": "terms", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "address", + "name": "sourceOfFunds", + "type": "address" + } + ], + "indexed": false, + "internalType": "struct PWNSimpleLoan.LenderSpec", + "name": "lenderSpec", + "type": "tuple" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "extra", + "type": "bytes" + } + ], + "name": "LOANCreated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "loanId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint40", + "name": "originalDefaultTimestamp", + "type": "uint40" + }, + { + "indexed": false, + "internalType": "uint40", + "name": "extendedDefaultTimestamp", + "type": "uint40" + } + ], + "name": "LOANExtended", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "loanId", + "type": "uint256" + } + ], + "name": "LOANPaidBack", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "indexed": false, + "internalType": "struct MultiToken.Asset", + "name": "asset", + "type": "tuple" + }, + { + "indexed": true, + "internalType": "address", + "name": "poolAdapter", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "PoolSupply", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "indexed": false, + "internalType": "struct MultiToken.Asset", + "name": "asset", + "type": "tuple" + }, + { + "indexed": true, + "internalType": "address", + "name": "poolAdapter", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "PoolWithdraw", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "indexed": false, + "internalType": "struct MultiToken.Asset", + "name": "asset", + "type": "tuple" + }, + { + "indexed": true, + "internalType": "address", + "name": "origin", + "type": "address" + } + ], + "name": "VaultPull", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "indexed": false, + "internalType": "struct MultiToken.Asset", + "name": "asset", + "type": "tuple" + }, + { + "indexed": true, + "internalType": "address", + "name": "beneficiary", + "type": "address" + } + ], + "name": "VaultPush", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "indexed": false, + "internalType": "struct MultiToken.Asset", + "name": "asset", + "type": "tuple" + }, + { + "indexed": true, + "internalType": "address", + "name": "origin", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "beneficiary", + "type": "address" + } + ], + "name": "VaultPushFrom", + "type": "event" + }, + { + "inputs": [], + "name": "ACCRUING_INTEREST_APR_DECIMALS", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ACCRUING_INTEREST_APR_DENOMINATOR", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "EXTENSION_PROPOSAL_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_ACCRUING_INTEREST_APR", + "outputs": [{ "internalType": "uint40", "name": "", "type": "uint40" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_EXTENSION_DURATION", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MINUTES_IN_YEAR", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MIN_EXTENSION_DURATION", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MIN_LOAN_DURATION", + "outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "VERSION", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "categoryRegistry", + "outputs": [ + { + "internalType": "contract IMultiTokenCategoryRegistry", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "loanId", "type": "uint256" } + ], + "name": "claimLOAN", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "config", + "outputs": [ + { "internalType": "contract PWNConfig", "name": "", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "address", + "name": "proposalContract", + "type": "address" + }, + { "internalType": "bytes", "name": "proposalData", "type": "bytes" }, + { + "internalType": "bytes32[]", + "name": "proposalInclusionProof", + "type": "bytes32[]" + }, + { "internalType": "bytes", "name": "signature", "type": "bytes" } + ], + "internalType": "struct PWNSimpleLoan.ProposalSpec", + "name": "proposalSpec", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "address", + "name": "sourceOfFunds", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoan.LenderSpec", + "name": "lenderSpec", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { "internalType": "bool", "name": "revokeNonce", "type": "bool" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" } + ], + "internalType": "struct PWNSimpleLoan.CallerSpec", + "name": "callerSpec", + "type": "tuple" + }, + { "internalType": "bytes", "name": "extra", "type": "bytes" } + ], + "name": "createLOAN", + "outputs": [ + { "internalType": "uint256", "name": "loanId", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "uint256", "name": "loanId", "type": "uint256" }, + { + "internalType": "address", + "name": "compensationAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "compensationAmount", + "type": "uint256" + }, + { "internalType": "uint40", "name": "duration", "type": "uint40" }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" } + ], + "internalType": "struct PWNSimpleLoan.ExtensionProposal", + "name": "extension", + "type": "tuple" + }, + { "internalType": "bytes", "name": "signature", "type": "bytes" } + ], + "name": "extendLOAN", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "name": "extensionProposalsMade", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "uint256", "name": "loanId", "type": "uint256" }, + { + "internalType": "address", + "name": "compensationAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "compensationAmount", + "type": "uint256" + }, + { "internalType": "uint40", "name": "duration", "type": "uint40" }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" } + ], + "internalType": "struct PWNSimpleLoan.ExtensionProposal", + "name": "extension", + "type": "tuple" + } + ], + "name": "getExtensionHash", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "loanId", "type": "uint256" } + ], + "name": "getLOAN", + "outputs": [ + { "internalType": "uint8", "name": "status", "type": "uint8" }, + { "internalType": "uint40", "name": "startTimestamp", "type": "uint40" }, + { + "internalType": "uint40", + "name": "defaultTimestamp", + "type": "uint40" + }, + { "internalType": "address", "name": "borrower", "type": "address" }, + { + "internalType": "address", + "name": "originalLender", + "type": "address" + }, + { "internalType": "address", "name": "loanOwner", "type": "address" }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "internalType": "struct MultiToken.Asset", + "name": "credit", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "internalType": "struct MultiToken.Asset", + "name": "collateral", + "type": "tuple" + }, + { + "internalType": "address", + "name": "originalSourceOfFunds", + "type": "address" + }, + { + "internalType": "uint256", + "name": "repaymentAmount", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "address", + "name": "sourceOfFunds", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoan.LenderSpec", + "name": "lenderSpec", + "type": "tuple" + } + ], + "name": "getLenderSpecHash", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "tokenId", "type": "uint256" } + ], + "name": "getStateFingerprint", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "hub", + "outputs": [ + { "internalType": "contract PWNHub", "name": "", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "internalType": "struct MultiToken.Asset", + "name": "asset", + "type": "tuple" + } + ], + "name": "isValidAsset", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "loanMetadataUri", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "loanId", "type": "uint256" } + ], + "name": "loanRepaymentAmount", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "loanToken", + "outputs": [ + { "internalType": "contract PWNLOAN", "name": "", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "uint256", "name": "loanId", "type": "uint256" }, + { + "internalType": "address", + "name": "compensationAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "compensationAmount", + "type": "uint256" + }, + { "internalType": "uint40", "name": "duration", "type": "uint40" }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" } + ], + "internalType": "struct PWNSimpleLoan.ExtensionProposal", + "name": "extension", + "type": "tuple" + } + ], + "name": "makeExtensionProposal", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "", "type": "address" }, + { "internalType": "address", "name": "", "type": "address" }, + { "internalType": "uint256[]", "name": "", "type": "uint256[]" }, + { "internalType": "uint256[]", "name": "", "type": "uint256[]" }, + { "internalType": "bytes", "name": "", "type": "bytes" } + ], + "name": "onERC1155BatchReceived", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "operator", "type": "address" }, + { "internalType": "address", "name": "", "type": "address" }, + { "internalType": "uint256", "name": "", "type": "uint256" }, + { "internalType": "uint256", "name": "", "type": "uint256" }, + { "internalType": "bytes", "name": "", "type": "bytes" } + ], + "name": "onERC1155Received", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "operator", "type": "address" }, + { "internalType": "address", "name": "", "type": "address" }, + { "internalType": "uint256", "name": "", "type": "uint256" }, + { "internalType": "bytes", "name": "", "type": "bytes" } + ], + "name": "onERC721Received", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "loanId", "type": "uint256" } + ], + "name": "repayLOAN", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "revokedNonce", + "outputs": [ + { + "internalType": "contract PWNRevokedNonce", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes4", "name": "interfaceId", "type": "bytes4" } + ], + "name": "supportsInterface", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "loanId", "type": "uint256" }, + { "internalType": "uint256", "name": "creditAmount", "type": "uint256" }, + { "internalType": "address", "name": "loanOwner", "type": "address" } + ], + "name": "tryClaimRepaidLOAN", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/packages/subgraph/abis/SimpleLoanElasticChainlinkProposal.json b/packages/subgraph/abis/SimpleLoanElasticChainlinkProposal.json new file mode 100644 index 0000000..d2abe01 --- /dev/null +++ b/packages/subgraph/abis/SimpleLoanElasticChainlinkProposal.json @@ -0,0 +1,1080 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "_hub", "type": "address" }, + { "internalType": "address", "name": "_revokedNonce", "type": "address" }, + { "internalType": "address", "name": "_config", "type": "address" }, + { + "internalType": "address", + "name": "_utilizedCredit", + "type": "address" + }, + { + "internalType": "address", + "name": "_chainlinkFeedRegistry", + "type": "address" + }, + { + "internalType": "address", + "name": "_l2SequencerUptimeFeed", + "type": "address" + }, + { "internalType": "address", "name": "_weth", "type": "address" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" } + ], + "name": "AcceptorIsProposer", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" }, + { "internalType": "bytes32", "name": "tag", "type": "bytes32" } + ], + "name": "AddressMissingHubTag", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" } + ], + "name": "CallerIsNotStatedProposer", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "current", "type": "address" }, + { "internalType": "address", "name": "allowed", "type": "address" } + ], + "name": "CallerNotAllowedAcceptor", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "caller", "type": "address" }, + { "internalType": "address", "name": "loanContract", "type": "address" } + ], + "name": "CallerNotLoanContract", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "feed", "type": "address" }, + { "internalType": "uint256", "name": "updatedAt", "type": "uint256" } + ], + "name": "ChainlinkFeedPriceTooOld", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "feed", "type": "address" }, + { "internalType": "int256", "name": "price", "type": "int256" }, + { "internalType": "uint256", "name": "updatedAt", "type": "uint256" } + ], + "name": "ChainlinkFeedReturnedNegativePrice", + "type": "error" + }, + { "inputs": [], "name": "ChainlinkInvalidInputLenghts", "type": "error" }, + { + "inputs": [ + { "internalType": "uint32", "name": "defaultDate", "type": "uint32" }, + { "internalType": "uint32", "name": "current", "type": "uint32" } + ], + "name": "DefaultDateInPast", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "current", "type": "uint256" }, + { "internalType": "uint256", "name": "expiration", "type": "uint256" } + ], + "name": "Expired", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "timeSinceUp", "type": "uint256" }, + { "internalType": "uint256", "name": "gracePeriod", "type": "uint256" } + ], + "name": "GracePeriodNotOver", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "current", "type": "uint256" }, + { "internalType": "uint256", "name": "limit", "type": "uint256" } + ], + "name": "InsufficientCreditAmount", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "current", "type": "uint256" }, + { "internalType": "uint256", "name": "limit", "type": "uint256" } + ], + "name": "IntermediaryDenominationsOutOfBounds", + "type": "error" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "current", "type": "bytes32" }, + { "internalType": "bytes32", "name": "proposed", "type": "bytes32" } + ], + "name": "InvalidCollateralStateFingerprint", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + } + ], + "name": "InvalidRefinancingLoanId", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "signer", "type": "address" }, + { "internalType": "bytes32", "name": "digest", "type": "bytes32" } + ], + "name": "InvalidSignature", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "length", "type": "uint256" } + ], + "name": "InvalidSignatureLength", + "type": "error" + }, + { "inputs": [], "name": "L2SequencerDown", "type": "error" }, + { "inputs": [], "name": "MinCreditAmountNotSet", "type": "error" }, + { "inputs": [], "name": "MissingStateFingerprintComputer", "type": "error" }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" }, + { "internalType": "uint256", "name": "nonceSpace", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" } + ], + "name": "NonceNotUsable", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "proposalHash", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "proposer", + "type": "address" + }, + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "collateralCategory", + "type": "uint8" + }, + { + "internalType": "address", + "name": "collateralAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "checkCollateralStateFingerprint", + "type": "bool" + }, + { + "internalType": "bytes32", + "name": "collateralStateFingerprint", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "address[]", + "name": "feedIntermediaryDenominations", + "type": "address[]" + }, + { + "internalType": "bool[]", + "name": "feedInvertFlags", + "type": "bool[]" + }, + { + "internalType": "uint256", + "name": "loanToValue", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCreditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "allowedAcceptor", + "type": "address" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "indexed": false, + "internalType": "struct PWNSimpleLoanElasticChainlinkProposal.Proposal", + "name": "proposal", + "type": "tuple" + } + ], + "name": "ProposalMade", + "type": "event" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LOAN_TO_VALUE_DENOMINATOR", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_INTERMEDIARY_DENOMINATIONS", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MULTIPROPOSAL_DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MULTIPROPOSAL_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PROPOSAL_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "VERSION", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "WETH", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "acceptor", "type": "address" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { "internalType": "bytes", "name": "proposalData", "type": "bytes" }, + { + "internalType": "bytes32[]", + "name": "proposalInclusionProof", + "type": "bytes32[]" + }, + { "internalType": "bytes", "name": "signature", "type": "bytes" } + ], + "name": "acceptProposal", + "outputs": [ + { "internalType": "bytes32", "name": "proposalHash", "type": "bytes32" }, + { + "components": [ + { "internalType": "address", "name": "lender", "type": "address" }, + { "internalType": "address", "name": "borrower", "type": "address" }, + { "internalType": "uint32", "name": "duration", "type": "uint32" }, + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "internalType": "struct MultiToken.Asset", + "name": "collateral", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "internalType": "struct MultiToken.Asset", + "name": "credit", + "type": "tuple" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "bytes32", + "name": "lenderSpecHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "borrowerSpecHash", + "type": "bytes32" + } + ], + "internalType": "struct PWNSimpleLoan.Terms", + "name": "loanTerms", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "chainlinkFeedRegistry", + "outputs": [ + { + "internalType": "contract IChainlinkFeedRegistryLike", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "config", + "outputs": [ + { "internalType": "contract PWNConfig", "name": "", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes", "name": "proposalData", "type": "bytes" } + ], + "name": "decodeProposalData", + "outputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "collateralCategory", + "type": "uint8" + }, + { + "internalType": "address", + "name": "collateralAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "checkCollateralStateFingerprint", + "type": "bool" + }, + { + "internalType": "bytes32", + "name": "collateralStateFingerprint", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "address[]", + "name": "feedIntermediaryDenominations", + "type": "address[]" + }, + { + "internalType": "bool[]", + "name": "feedInvertFlags", + "type": "bool[]" + }, + { + "internalType": "uint256", + "name": "loanToValue", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCreditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "allowedAcceptor", + "type": "address" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanElasticChainlinkProposal.Proposal", + "name": "", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "creditAmount", + "type": "uint256" + } + ], + "internalType": "struct PWNSimpleLoanElasticChainlinkProposal.ProposalValues", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "collateralCategory", + "type": "uint8" + }, + { + "internalType": "address", + "name": "collateralAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "checkCollateralStateFingerprint", + "type": "bool" + }, + { + "internalType": "bytes32", + "name": "collateralStateFingerprint", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "address[]", + "name": "feedIntermediaryDenominations", + "type": "address[]" + }, + { + "internalType": "bool[]", + "name": "feedInvertFlags", + "type": "bool[]" + }, + { + "internalType": "uint256", + "name": "loanToValue", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCreditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "allowedAcceptor", + "type": "address" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanElasticChainlinkProposal.Proposal", + "name": "proposal", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "creditAmount", + "type": "uint256" + } + ], + "internalType": "struct PWNSimpleLoanElasticChainlinkProposal.ProposalValues", + "name": "proposalValues", + "type": "tuple" + } + ], + "name": "encodeProposalData", + "outputs": [{ "internalType": "bytes", "name": "", "type": "bytes" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "creditAddress", "type": "address" }, + { "internalType": "uint256", "name": "creditAmount", "type": "uint256" }, + { + "internalType": "address", + "name": "collateralAddress", + "type": "address" + }, + { + "internalType": "address[]", + "name": "feedIntermediaryDenominations", + "type": "address[]" + }, + { "internalType": "bool[]", "name": "feedInvertFlags", "type": "bool[]" }, + { "internalType": "uint256", "name": "loanToValue", "type": "uint256" } + ], + "name": "getCollateralAmount", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "bytes32", + "name": "multiproposalMerkleRoot", + "type": "bytes32" + } + ], + "internalType": "struct PWNSimpleLoanProposal.Multiproposal", + "name": "multiproposal", + "type": "tuple" + } + ], + "name": "getMultiproposalHash", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "collateralCategory", + "type": "uint8" + }, + { + "internalType": "address", + "name": "collateralAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "checkCollateralStateFingerprint", + "type": "bool" + }, + { + "internalType": "bytes32", + "name": "collateralStateFingerprint", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "address[]", + "name": "feedIntermediaryDenominations", + "type": "address[]" + }, + { + "internalType": "bool[]", + "name": "feedInvertFlags", + "type": "bool[]" + }, + { + "internalType": "uint256", + "name": "loanToValue", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCreditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "allowedAcceptor", + "type": "address" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanElasticChainlinkProposal.Proposal", + "name": "proposal", + "type": "tuple" + } + ], + "name": "getProposalHash", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "hub", + "outputs": [ + { "internalType": "contract PWNHub", "name": "", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "l2SequencerUptimeFeed", + "outputs": [ + { + "internalType": "contract IChainlinkAggregatorLike", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "collateralCategory", + "type": "uint8" + }, + { + "internalType": "address", + "name": "collateralAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "checkCollateralStateFingerprint", + "type": "bool" + }, + { + "internalType": "bytes32", + "name": "collateralStateFingerprint", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "address[]", + "name": "feedIntermediaryDenominations", + "type": "address[]" + }, + { + "internalType": "bool[]", + "name": "feedInvertFlags", + "type": "bool[]" + }, + { + "internalType": "uint256", + "name": "loanToValue", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCreditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "allowedAcceptor", + "type": "address" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanElasticChainlinkProposal.Proposal", + "name": "proposal", + "type": "tuple" + } + ], + "name": "makeProposal", + "outputs": [ + { "internalType": "bytes32", "name": "proposalHash", "type": "bytes32" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "name": "proposalsMade", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "nonceSpace", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" } + ], + "name": "revokeNonce", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "revokedNonce", + "outputs": [ + { + "internalType": "contract PWNRevokedNonce", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "utilizedCredit", + "outputs": [ + { + "internalType": "contract PWNUtilizedCredit", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/packages/subgraph/abis/SimpleLoanElasticProposal.json b/packages/subgraph/abis/SimpleLoanElasticProposal.json new file mode 100644 index 0000000..797ae04 --- /dev/null +++ b/packages/subgraph/abis/SimpleLoanElasticProposal.json @@ -0,0 +1,937 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "_hub", "type": "address" }, + { "internalType": "address", "name": "_revokedNonce", "type": "address" }, + { "internalType": "address", "name": "_config", "type": "address" }, + { + "internalType": "address", + "name": "_utilizedCredit", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" } + ], + "name": "AcceptorIsProposer", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" }, + { "internalType": "bytes32", "name": "tag", "type": "bytes32" } + ], + "name": "AddressMissingHubTag", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" } + ], + "name": "CallerIsNotStatedProposer", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "current", "type": "address" }, + { "internalType": "address", "name": "allowed", "type": "address" } + ], + "name": "CallerNotAllowedAcceptor", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "caller", "type": "address" }, + { "internalType": "address", "name": "loanContract", "type": "address" } + ], + "name": "CallerNotLoanContract", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint32", "name": "defaultDate", "type": "uint32" }, + { "internalType": "uint32", "name": "current", "type": "uint32" } + ], + "name": "DefaultDateInPast", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "current", "type": "uint256" }, + { "internalType": "uint256", "name": "expiration", "type": "uint256" } + ], + "name": "Expired", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "current", "type": "uint256" }, + { "internalType": "uint256", "name": "limit", "type": "uint256" } + ], + "name": "InsufficientCreditAmount", + "type": "error" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "current", "type": "bytes32" }, + { "internalType": "bytes32", "name": "proposed", "type": "bytes32" } + ], + "name": "InvalidCollateralStateFingerprint", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + } + ], + "name": "InvalidRefinancingLoanId", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "signer", "type": "address" }, + { "internalType": "bytes32", "name": "digest", "type": "bytes32" } + ], + "name": "InvalidSignature", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "length", "type": "uint256" } + ], + "name": "InvalidSignatureLength", + "type": "error" + }, + { "inputs": [], "name": "MinCreditAmountNotSet", "type": "error" }, + { "inputs": [], "name": "MissingStateFingerprintComputer", "type": "error" }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" }, + { "internalType": "uint256", "name": "nonceSpace", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" } + ], + "name": "NonceNotUsable", + "type": "error" + }, + { "inputs": [], "name": "ZeroCreditPerCollateralUnit", "type": "error" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "proposalHash", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "proposer", + "type": "address" + }, + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "collateralCategory", + "type": "uint8" + }, + { + "internalType": "address", + "name": "collateralAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "checkCollateralStateFingerprint", + "type": "bool" + }, + { + "internalType": "bytes32", + "name": "collateralStateFingerprint", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "creditPerCollateralUnit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCreditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "allowedAcceptor", + "type": "address" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "indexed": false, + "internalType": "struct PWNSimpleLoanElasticProposal.Proposal", + "name": "proposal", + "type": "tuple" + } + ], + "name": "ProposalMade", + "type": "event" + }, + { + "inputs": [], + "name": "CREDIT_PER_COLLATERAL_UNIT_DENOMINATOR", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MULTIPROPOSAL_DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MULTIPROPOSAL_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PROPOSAL_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "VERSION", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "acceptor", "type": "address" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { "internalType": "bytes", "name": "proposalData", "type": "bytes" }, + { + "internalType": "bytes32[]", + "name": "proposalInclusionProof", + "type": "bytes32[]" + }, + { "internalType": "bytes", "name": "signature", "type": "bytes" } + ], + "name": "acceptProposal", + "outputs": [ + { "internalType": "bytes32", "name": "proposalHash", "type": "bytes32" }, + { + "components": [ + { "internalType": "address", "name": "lender", "type": "address" }, + { "internalType": "address", "name": "borrower", "type": "address" }, + { "internalType": "uint32", "name": "duration", "type": "uint32" }, + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "internalType": "struct MultiToken.Asset", + "name": "collateral", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "internalType": "struct MultiToken.Asset", + "name": "credit", + "type": "tuple" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "bytes32", + "name": "lenderSpecHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "borrowerSpecHash", + "type": "bytes32" + } + ], + "internalType": "struct PWNSimpleLoan.Terms", + "name": "loanTerms", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "config", + "outputs": [ + { "internalType": "contract PWNConfig", "name": "", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes", "name": "proposalData", "type": "bytes" } + ], + "name": "decodeProposalData", + "outputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "collateralCategory", + "type": "uint8" + }, + { + "internalType": "address", + "name": "collateralAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "checkCollateralStateFingerprint", + "type": "bool" + }, + { + "internalType": "bytes32", + "name": "collateralStateFingerprint", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "creditPerCollateralUnit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCreditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "allowedAcceptor", + "type": "address" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanElasticProposal.Proposal", + "name": "", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "creditAmount", + "type": "uint256" + } + ], + "internalType": "struct PWNSimpleLoanElasticProposal.ProposalValues", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "collateralCategory", + "type": "uint8" + }, + { + "internalType": "address", + "name": "collateralAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "checkCollateralStateFingerprint", + "type": "bool" + }, + { + "internalType": "bytes32", + "name": "collateralStateFingerprint", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "creditPerCollateralUnit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCreditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "allowedAcceptor", + "type": "address" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanElasticProposal.Proposal", + "name": "proposal", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "creditAmount", + "type": "uint256" + } + ], + "internalType": "struct PWNSimpleLoanElasticProposal.ProposalValues", + "name": "proposalValues", + "type": "tuple" + } + ], + "name": "encodeProposalData", + "outputs": [{ "internalType": "bytes", "name": "", "type": "bytes" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "creditAmount", "type": "uint256" }, + { + "internalType": "uint256", + "name": "creditPerCollateralUnit", + "type": "uint256" + } + ], + "name": "getCollateralAmount", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "bytes32", + "name": "multiproposalMerkleRoot", + "type": "bytes32" + } + ], + "internalType": "struct PWNSimpleLoanProposal.Multiproposal", + "name": "multiproposal", + "type": "tuple" + } + ], + "name": "getMultiproposalHash", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "collateralCategory", + "type": "uint8" + }, + { + "internalType": "address", + "name": "collateralAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "checkCollateralStateFingerprint", + "type": "bool" + }, + { + "internalType": "bytes32", + "name": "collateralStateFingerprint", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "creditPerCollateralUnit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCreditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "allowedAcceptor", + "type": "address" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanElasticProposal.Proposal", + "name": "proposal", + "type": "tuple" + } + ], + "name": "getProposalHash", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "hub", + "outputs": [ + { "internalType": "contract PWNHub", "name": "", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "collateralCategory", + "type": "uint8" + }, + { + "internalType": "address", + "name": "collateralAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "checkCollateralStateFingerprint", + "type": "bool" + }, + { + "internalType": "bytes32", + "name": "collateralStateFingerprint", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "creditPerCollateralUnit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCreditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "allowedAcceptor", + "type": "address" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanElasticProposal.Proposal", + "name": "proposal", + "type": "tuple" + } + ], + "name": "makeProposal", + "outputs": [ + { "internalType": "bytes32", "name": "proposalHash", "type": "bytes32" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "name": "proposalsMade", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "nonceSpace", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" } + ], + "name": "revokeNonce", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "revokedNonce", + "outputs": [ + { + "internalType": "contract PWNRevokedNonce", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "utilizedCredit", + "outputs": [ + { + "internalType": "contract PWNUtilizedCredit", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/packages/subgraph/abis/SimpleLoanListProposal.json b/packages/subgraph/abis/SimpleLoanListProposal.json new file mode 100644 index 0000000..6df5603 --- /dev/null +++ b/packages/subgraph/abis/SimpleLoanListProposal.json @@ -0,0 +1,921 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "_hub", "type": "address" }, + { "internalType": "address", "name": "_revokedNonce", "type": "address" }, + { "internalType": "address", "name": "_config", "type": "address" }, + { + "internalType": "address", + "name": "_utilizedCredit", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" } + ], + "name": "AcceptorIsProposer", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" }, + { "internalType": "bytes32", "name": "tag", "type": "bytes32" } + ], + "name": "AddressMissingHubTag", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" } + ], + "name": "CallerIsNotStatedProposer", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "current", "type": "address" }, + { "internalType": "address", "name": "allowed", "type": "address" } + ], + "name": "CallerNotAllowedAcceptor", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "caller", "type": "address" }, + { "internalType": "address", "name": "loanContract", "type": "address" } + ], + "name": "CallerNotLoanContract", + "type": "error" + }, + { + "inputs": [{ "internalType": "uint256", "name": "id", "type": "uint256" }], + "name": "CollateralIdNotWhitelisted", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint32", "name": "defaultDate", "type": "uint32" }, + { "internalType": "uint32", "name": "current", "type": "uint32" } + ], + "name": "DefaultDateInPast", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "current", "type": "uint256" }, + { "internalType": "uint256", "name": "expiration", "type": "uint256" } + ], + "name": "Expired", + "type": "error" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "current", "type": "bytes32" }, + { "internalType": "bytes32", "name": "proposed", "type": "bytes32" } + ], + "name": "InvalidCollateralStateFingerprint", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + } + ], + "name": "InvalidRefinancingLoanId", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "signer", "type": "address" }, + { "internalType": "bytes32", "name": "digest", "type": "bytes32" } + ], + "name": "InvalidSignature", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "length", "type": "uint256" } + ], + "name": "InvalidSignatureLength", + "type": "error" + }, + { "inputs": [], "name": "MissingStateFingerprintComputer", "type": "error" }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" }, + { "internalType": "uint256", "name": "nonceSpace", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" } + ], + "name": "NonceNotUsable", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "proposalHash", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "proposer", + "type": "address" + }, + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "collateralCategory", + "type": "uint8" + }, + { + "internalType": "address", + "name": "collateralAddress", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "collateralIdsWhitelistMerkleRoot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "collateralAmount", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "checkCollateralStateFingerprint", + "type": "bool" + }, + { + "internalType": "bytes32", + "name": "collateralStateFingerprint", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "creditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "allowedAcceptor", + "type": "address" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "indexed": false, + "internalType": "struct PWNSimpleLoanListProposal.Proposal", + "name": "proposal", + "type": "tuple" + } + ], + "name": "ProposalMade", + "type": "event" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MULTIPROPOSAL_DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MULTIPROPOSAL_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PROPOSAL_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "VERSION", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "acceptor", "type": "address" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { "internalType": "bytes", "name": "proposalData", "type": "bytes" }, + { + "internalType": "bytes32[]", + "name": "proposalInclusionProof", + "type": "bytes32[]" + }, + { "internalType": "bytes", "name": "signature", "type": "bytes" } + ], + "name": "acceptProposal", + "outputs": [ + { "internalType": "bytes32", "name": "proposalHash", "type": "bytes32" }, + { + "components": [ + { "internalType": "address", "name": "lender", "type": "address" }, + { "internalType": "address", "name": "borrower", "type": "address" }, + { "internalType": "uint32", "name": "duration", "type": "uint32" }, + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "internalType": "struct MultiToken.Asset", + "name": "collateral", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "internalType": "struct MultiToken.Asset", + "name": "credit", + "type": "tuple" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "bytes32", + "name": "lenderSpecHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "borrowerSpecHash", + "type": "bytes32" + } + ], + "internalType": "struct PWNSimpleLoan.Terms", + "name": "loanTerms", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "config", + "outputs": [ + { "internalType": "contract PWNConfig", "name": "", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes", "name": "proposalData", "type": "bytes" } + ], + "name": "decodeProposalData", + "outputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "collateralCategory", + "type": "uint8" + }, + { + "internalType": "address", + "name": "collateralAddress", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "collateralIdsWhitelistMerkleRoot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "collateralAmount", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "checkCollateralStateFingerprint", + "type": "bool" + }, + { + "internalType": "bytes32", + "name": "collateralStateFingerprint", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "creditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "allowedAcceptor", + "type": "address" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanListProposal.Proposal", + "name": "", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "bytes32[]", + "name": "merkleInclusionProof", + "type": "bytes32[]" + } + ], + "internalType": "struct PWNSimpleLoanListProposal.ProposalValues", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "collateralCategory", + "type": "uint8" + }, + { + "internalType": "address", + "name": "collateralAddress", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "collateralIdsWhitelistMerkleRoot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "collateralAmount", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "checkCollateralStateFingerprint", + "type": "bool" + }, + { + "internalType": "bytes32", + "name": "collateralStateFingerprint", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "creditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "allowedAcceptor", + "type": "address" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanListProposal.Proposal", + "name": "proposal", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "bytes32[]", + "name": "merkleInclusionProof", + "type": "bytes32[]" + } + ], + "internalType": "struct PWNSimpleLoanListProposal.ProposalValues", + "name": "proposalValues", + "type": "tuple" + } + ], + "name": "encodeProposalData", + "outputs": [{ "internalType": "bytes", "name": "", "type": "bytes" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "bytes32", + "name": "multiproposalMerkleRoot", + "type": "bytes32" + } + ], + "internalType": "struct PWNSimpleLoanProposal.Multiproposal", + "name": "multiproposal", + "type": "tuple" + } + ], + "name": "getMultiproposalHash", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "collateralCategory", + "type": "uint8" + }, + { + "internalType": "address", + "name": "collateralAddress", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "collateralIdsWhitelistMerkleRoot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "collateralAmount", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "checkCollateralStateFingerprint", + "type": "bool" + }, + { + "internalType": "bytes32", + "name": "collateralStateFingerprint", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "creditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "allowedAcceptor", + "type": "address" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanListProposal.Proposal", + "name": "proposal", + "type": "tuple" + } + ], + "name": "getProposalHash", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "hub", + "outputs": [ + { "internalType": "contract PWNHub", "name": "", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "collateralCategory", + "type": "uint8" + }, + { + "internalType": "address", + "name": "collateralAddress", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "collateralIdsWhitelistMerkleRoot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "collateralAmount", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "checkCollateralStateFingerprint", + "type": "bool" + }, + { + "internalType": "bytes32", + "name": "collateralStateFingerprint", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "creditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "allowedAcceptor", + "type": "address" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanListProposal.Proposal", + "name": "proposal", + "type": "tuple" + } + ], + "name": "makeProposal", + "outputs": [ + { "internalType": "bytes32", "name": "proposalHash", "type": "bytes32" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "name": "proposalsMade", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "nonceSpace", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" } + ], + "name": "revokeNonce", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "revokedNonce", + "outputs": [ + { + "internalType": "contract PWNRevokedNonce", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "utilizedCredit", + "outputs": [ + { + "internalType": "contract PWNUtilizedCredit", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/packages/subgraph/abis/SimpleLoanSimpleProposal.json b/packages/subgraph/abis/SimpleLoanSimpleProposal.json new file mode 100644 index 0000000..e106bea --- /dev/null +++ b/packages/subgraph/abis/SimpleLoanSimpleProposal.json @@ -0,0 +1,882 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "_hub", "type": "address" }, + { "internalType": "address", "name": "_revokedNonce", "type": "address" }, + { "internalType": "address", "name": "_config", "type": "address" }, + { + "internalType": "address", + "name": "_utilizedCredit", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" } + ], + "name": "AcceptorIsProposer", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" }, + { "internalType": "bytes32", "name": "tag", "type": "bytes32" } + ], + "name": "AddressMissingHubTag", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" } + ], + "name": "CallerIsNotStatedProposer", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "current", "type": "address" }, + { "internalType": "address", "name": "allowed", "type": "address" } + ], + "name": "CallerNotAllowedAcceptor", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "caller", "type": "address" }, + { "internalType": "address", "name": "loanContract", "type": "address" } + ], + "name": "CallerNotLoanContract", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint32", "name": "defaultDate", "type": "uint32" }, + { "internalType": "uint32", "name": "current", "type": "uint32" } + ], + "name": "DefaultDateInPast", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "current", "type": "uint256" }, + { "internalType": "uint256", "name": "expiration", "type": "uint256" } + ], + "name": "Expired", + "type": "error" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "current", "type": "bytes32" }, + { "internalType": "bytes32", "name": "proposed", "type": "bytes32" } + ], + "name": "InvalidCollateralStateFingerprint", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + } + ], + "name": "InvalidRefinancingLoanId", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "signer", "type": "address" }, + { "internalType": "bytes32", "name": "digest", "type": "bytes32" } + ], + "name": "InvalidSignature", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "length", "type": "uint256" } + ], + "name": "InvalidSignatureLength", + "type": "error" + }, + { "inputs": [], "name": "MissingStateFingerprintComputer", "type": "error" }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" }, + { "internalType": "uint256", "name": "nonceSpace", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" } + ], + "name": "NonceNotUsable", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "proposalHash", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "proposer", + "type": "address" + }, + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "collateralCategory", + "type": "uint8" + }, + { + "internalType": "address", + "name": "collateralAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "collateralAmount", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "checkCollateralStateFingerprint", + "type": "bool" + }, + { + "internalType": "bytes32", + "name": "collateralStateFingerprint", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "creditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "allowedAcceptor", + "type": "address" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "indexed": false, + "internalType": "struct PWNSimpleLoanSimpleProposal.Proposal", + "name": "proposal", + "type": "tuple" + } + ], + "name": "ProposalMade", + "type": "event" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MULTIPROPOSAL_DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MULTIPROPOSAL_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PROPOSAL_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "VERSION", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "acceptor", "type": "address" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { "internalType": "bytes", "name": "proposalData", "type": "bytes" }, + { + "internalType": "bytes32[]", + "name": "proposalInclusionProof", + "type": "bytes32[]" + }, + { "internalType": "bytes", "name": "signature", "type": "bytes" } + ], + "name": "acceptProposal", + "outputs": [ + { "internalType": "bytes32", "name": "proposalHash", "type": "bytes32" }, + { + "components": [ + { "internalType": "address", "name": "lender", "type": "address" }, + { "internalType": "address", "name": "borrower", "type": "address" }, + { "internalType": "uint32", "name": "duration", "type": "uint32" }, + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "internalType": "struct MultiToken.Asset", + "name": "collateral", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "internalType": "struct MultiToken.Asset", + "name": "credit", + "type": "tuple" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "bytes32", + "name": "lenderSpecHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "borrowerSpecHash", + "type": "bytes32" + } + ], + "internalType": "struct PWNSimpleLoan.Terms", + "name": "loanTerms", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "config", + "outputs": [ + { "internalType": "contract PWNConfig", "name": "", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes", "name": "proposalData", "type": "bytes" } + ], + "name": "decodeProposalData", + "outputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "collateralCategory", + "type": "uint8" + }, + { + "internalType": "address", + "name": "collateralAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "collateralAmount", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "checkCollateralStateFingerprint", + "type": "bool" + }, + { + "internalType": "bytes32", + "name": "collateralStateFingerprint", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "creditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "allowedAcceptor", + "type": "address" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanSimpleProposal.Proposal", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "collateralCategory", + "type": "uint8" + }, + { + "internalType": "address", + "name": "collateralAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "collateralAmount", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "checkCollateralStateFingerprint", + "type": "bool" + }, + { + "internalType": "bytes32", + "name": "collateralStateFingerprint", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "creditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "allowedAcceptor", + "type": "address" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanSimpleProposal.Proposal", + "name": "proposal", + "type": "tuple" + } + ], + "name": "encodeProposalData", + "outputs": [{ "internalType": "bytes", "name": "", "type": "bytes" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "bytes32", + "name": "multiproposalMerkleRoot", + "type": "bytes32" + } + ], + "internalType": "struct PWNSimpleLoanProposal.Multiproposal", + "name": "multiproposal", + "type": "tuple" + } + ], + "name": "getMultiproposalHash", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "collateralCategory", + "type": "uint8" + }, + { + "internalType": "address", + "name": "collateralAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "collateralAmount", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "checkCollateralStateFingerprint", + "type": "bool" + }, + { + "internalType": "bytes32", + "name": "collateralStateFingerprint", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "creditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "allowedAcceptor", + "type": "address" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanSimpleProposal.Proposal", + "name": "proposal", + "type": "tuple" + } + ], + "name": "getProposalHash", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "hub", + "outputs": [ + { "internalType": "contract PWNHub", "name": "", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "collateralCategory", + "type": "uint8" + }, + { + "internalType": "address", + "name": "collateralAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "collateralAmount", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "checkCollateralStateFingerprint", + "type": "bool" + }, + { + "internalType": "bytes32", + "name": "collateralStateFingerprint", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "creditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "allowedAcceptor", + "type": "address" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanSimpleProposal.Proposal", + "name": "proposal", + "type": "tuple" + } + ], + "name": "makeProposal", + "outputs": [ + { "internalType": "bytes32", "name": "proposalHash", "type": "bytes32" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "name": "proposalsMade", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "nonceSpace", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" } + ], + "name": "revokeNonce", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "revokedNonce", + "outputs": [ + { + "internalType": "contract PWNRevokedNonce", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "utilizedCredit", + "outputs": [ + { + "internalType": "contract PWNUtilizedCredit", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/packages/subgraph/abis/SimpleLoanUniswapV3LPIndividualProposal.json b/packages/subgraph/abis/SimpleLoanUniswapV3LPIndividualProposal.json new file mode 100644 index 0000000..c17a665 --- /dev/null +++ b/packages/subgraph/abis/SimpleLoanUniswapV3LPIndividualProposal.json @@ -0,0 +1,1060 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "_hub", "type": "address" }, + { "internalType": "address", "name": "_revokedNonce", "type": "address" }, + { "internalType": "address", "name": "_config", "type": "address" }, + { + "internalType": "address", + "name": "_utilizedCredit", + "type": "address" + }, + { + "internalType": "address", + "name": "_uniswapV3Factory", + "type": "address" + }, + { + "internalType": "address", + "name": "_uniswapNFTPositionManager", + "type": "address" + }, + { + "internalType": "address", + "name": "_chainlinkFeedRegistry", + "type": "address" + }, + { + "internalType": "address", + "name": "_chainlinkL2SequencerUptimeFeed", + "type": "address" + }, + { "internalType": "address", "name": "_weth", "type": "address" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" } + ], + "name": "AcceptorIsProposer", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" }, + { "internalType": "bytes32", "name": "tag", "type": "bytes32" } + ], + "name": "AddressMissingHubTag", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" } + ], + "name": "CallerIsNotStatedProposer", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "caller", "type": "address" }, + { "internalType": "address", "name": "loanContract", "type": "address" } + ], + "name": "CallerNotLoanContract", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "feed", "type": "address" }, + { "internalType": "uint256", "name": "updatedAt", "type": "uint256" } + ], + "name": "ChainlinkFeedPriceTooOld", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "feed", "type": "address" }, + { "internalType": "int256", "name": "price", "type": "int256" }, + { "internalType": "uint256", "name": "updatedAt", "type": "uint256" } + ], + "name": "ChainlinkFeedReturnedNegativePrice", + "type": "error" + }, + { "inputs": [], "name": "ChainlinkInvalidInputLenghts", "type": "error" }, + { + "inputs": [ + { "internalType": "uint32", "name": "defaultDate", "type": "uint32" }, + { "internalType": "uint32", "name": "current", "type": "uint32" } + ], + "name": "DefaultDateInPast", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "current", "type": "uint256" }, + { "internalType": "uint256", "name": "expiration", "type": "uint256" } + ], + "name": "Expired", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "timeSinceUp", "type": "uint256" }, + { "internalType": "uint256", "name": "gracePeriod", "type": "uint256" } + ], + "name": "GracePeriodNotOver", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "current", "type": "uint256" }, + { "internalType": "uint256", "name": "limit", "type": "uint256" } + ], + "name": "InsufficientCreditAmount", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "current", "type": "uint256" }, + { "internalType": "uint256", "name": "limit", "type": "uint256" } + ], + "name": "IntermediaryDenominationsOutOfBounds", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "acceptorController", + "type": "address" + } + ], + "name": "InvalidAcceptorController", + "type": "error" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "current", "type": "bytes32" }, + { "internalType": "bytes32", "name": "proposed", "type": "bytes32" } + ], + "name": "InvalidCollateralStateFingerprint", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + } + ], + "name": "InvalidRefinancingLoanId", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "signer", "type": "address" }, + { "internalType": "bytes32", "name": "digest", "type": "bytes32" } + ], + "name": "InvalidSignature", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "length", "type": "uint256" } + ], + "name": "InvalidSignatureLength", + "type": "error" + }, + { "inputs": [], "name": "L2SequencerDown", "type": "error" }, + { "inputs": [], "name": "MinCreditAmountNotSet", "type": "error" }, + { "inputs": [], "name": "MissingStateFingerprintComputer", "type": "error" }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" }, + { "internalType": "uint256", "name": "nonceSpace", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" } + ], + "name": "NonceNotUsable", + "type": "error" + }, + { "inputs": [], "name": "T", "type": "error" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "proposalHash", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "proposer", + "type": "address" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "token0Denominator", + "type": "bool" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "address[]", + "name": "feedIntermediaryDenominations", + "type": "address[]" + }, + { + "internalType": "bool[]", + "name": "feedInvertFlags", + "type": "bool[]" + }, + { + "internalType": "uint256", + "name": "loanToValue", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCreditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "acceptorController", + "type": "address" + }, + { + "internalType": "bytes", + "name": "acceptorControllerData", + "type": "bytes" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "indexed": false, + "internalType": "struct PWNSimpleLoanUniswapV3LPIndividualProposal.Proposal", + "name": "proposal", + "type": "tuple" + } + ], + "name": "ProposalMade", + "type": "event" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LOAN_TO_VALUE_DENOMINATOR", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_INTERMEDIARY_DENOMINATIONS", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MULTIPROPOSAL_DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MULTIPROPOSAL_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PROPOSAL_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "VERSION", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "WETH", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "acceptor", "type": "address" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { "internalType": "bytes", "name": "proposalData", "type": "bytes" }, + { + "internalType": "bytes32[]", + "name": "proposalInclusionProof", + "type": "bytes32[]" + }, + { "internalType": "bytes", "name": "signature", "type": "bytes" } + ], + "name": "acceptProposal", + "outputs": [ + { "internalType": "bytes32", "name": "proposalHash", "type": "bytes32" }, + { + "components": [ + { "internalType": "address", "name": "lender", "type": "address" }, + { "internalType": "address", "name": "borrower", "type": "address" }, + { "internalType": "uint32", "name": "duration", "type": "uint32" }, + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "internalType": "struct MultiToken.Asset", + "name": "collateral", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "internalType": "struct MultiToken.Asset", + "name": "credit", + "type": "tuple" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "bytes32", + "name": "lenderSpecHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "borrowerSpecHash", + "type": "bytes32" + } + ], + "internalType": "struct PWNSimpleLoan.Terms", + "name": "loanTerms", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "chainlinkFeedRegistry", + "outputs": [ + { + "internalType": "contract IChainlinkFeedRegistryLike", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "chainlinkL2SequencerUptimeFeed", + "outputs": [ + { + "internalType": "contract IChainlinkAggregatorLike", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "config", + "outputs": [ + { "internalType": "contract PWNConfig", "name": "", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes", "name": "proposalData", "type": "bytes" } + ], + "name": "decodeProposalData", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "token0Denominator", + "type": "bool" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "address[]", + "name": "feedIntermediaryDenominations", + "type": "address[]" + }, + { + "internalType": "bool[]", + "name": "feedInvertFlags", + "type": "bool[]" + }, + { + "internalType": "uint256", + "name": "loanToValue", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCreditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "acceptorController", + "type": "address" + }, + { + "internalType": "bytes", + "name": "acceptorControllerData", + "type": "bytes" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanUniswapV3LPIndividualProposal.Proposal", + "name": "", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "bytes", + "name": "acceptorControllerData", + "type": "bytes" + } + ], + "internalType": "struct PWNSimpleLoanUniswapV3LPIndividualProposal.ProposalValues", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "token0Denominator", + "type": "bool" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "address[]", + "name": "feedIntermediaryDenominations", + "type": "address[]" + }, + { + "internalType": "bool[]", + "name": "feedInvertFlags", + "type": "bool[]" + }, + { + "internalType": "uint256", + "name": "loanToValue", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCreditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "acceptorController", + "type": "address" + }, + { + "internalType": "bytes", + "name": "acceptorControllerData", + "type": "bytes" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanUniswapV3LPIndividualProposal.Proposal", + "name": "proposal", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "bytes", + "name": "acceptorControllerData", + "type": "bytes" + } + ], + "internalType": "struct PWNSimpleLoanUniswapV3LPIndividualProposal.ProposalValues", + "name": "proposalValues", + "type": "tuple" + } + ], + "name": "encodeProposalData", + "outputs": [{ "internalType": "bytes", "name": "", "type": "bytes" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "creditAddress", "type": "address" }, + { "internalType": "uint256", "name": "collateralId", "type": "uint256" }, + { "internalType": "bool", "name": "token0Denominator", "type": "bool" }, + { + "internalType": "address[]", + "name": "feedIntermediaryDenominations", + "type": "address[]" + }, + { "internalType": "bool[]", "name": "feedInvertFlags", "type": "bool[]" }, + { "internalType": "uint256", "name": "loanToValue", "type": "uint256" } + ], + "name": "getCreditAmount", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "bytes32", + "name": "multiproposalMerkleRoot", + "type": "bytes32" + } + ], + "internalType": "struct PWNSimpleLoanProposal.Multiproposal", + "name": "multiproposal", + "type": "tuple" + } + ], + "name": "getMultiproposalHash", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "token0Denominator", + "type": "bool" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "address[]", + "name": "feedIntermediaryDenominations", + "type": "address[]" + }, + { + "internalType": "bool[]", + "name": "feedInvertFlags", + "type": "bool[]" + }, + { + "internalType": "uint256", + "name": "loanToValue", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCreditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "acceptorController", + "type": "address" + }, + { + "internalType": "bytes", + "name": "acceptorControllerData", + "type": "bytes" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanUniswapV3LPIndividualProposal.Proposal", + "name": "proposal", + "type": "tuple" + } + ], + "name": "getProposalHash", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "hub", + "outputs": [ + { "internalType": "contract PWNHub", "name": "", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "token0Denominator", + "type": "bool" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "address[]", + "name": "feedIntermediaryDenominations", + "type": "address[]" + }, + { + "internalType": "bool[]", + "name": "feedInvertFlags", + "type": "bool[]" + }, + { + "internalType": "uint256", + "name": "loanToValue", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCreditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "acceptorController", + "type": "address" + }, + { + "internalType": "bytes", + "name": "acceptorControllerData", + "type": "bytes" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanUniswapV3LPIndividualProposal.Proposal", + "name": "proposal", + "type": "tuple" + } + ], + "name": "makeProposal", + "outputs": [ + { "internalType": "bytes32", "name": "proposalHash", "type": "bytes32" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "name": "proposalsMade", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "nonceSpace", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" } + ], + "name": "revokeNonce", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "revokedNonce", + "outputs": [ + { + "internalType": "contract PWNRevokedNonce", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "uniswapNFTPositionManager", + "outputs": [ + { + "internalType": "contract INonfungiblePositionManager", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "uniswapV3Factory", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "utilizedCredit", + "outputs": [ + { + "internalType": "contract PWNUtilizedCredit", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/packages/subgraph/abis/SimpleLoanUniswapV3LPSetProposal.json b/packages/subgraph/abis/SimpleLoanUniswapV3LPSetProposal.json new file mode 100644 index 0000000..c487a89 --- /dev/null +++ b/packages/subgraph/abis/SimpleLoanUniswapV3LPSetProposal.json @@ -0,0 +1,1101 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "_hub", "type": "address" }, + { "internalType": "address", "name": "_revokedNonce", "type": "address" }, + { "internalType": "address", "name": "_config", "type": "address" }, + { + "internalType": "address", + "name": "_utilizedCredit", + "type": "address" + }, + { + "internalType": "address", + "name": "_uniswapV3Factory", + "type": "address" + }, + { + "internalType": "address", + "name": "_uniswapNFTPositionManager", + "type": "address" + }, + { + "internalType": "address", + "name": "_chainlinkFeedRegistry", + "type": "address" + }, + { + "internalType": "address", + "name": "_chainlinkL2SequencerUptimeFeed", + "type": "address" + }, + { "internalType": "address", "name": "_weth", "type": "address" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" } + ], + "name": "AcceptorIsProposer", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" }, + { "internalType": "bytes32", "name": "tag", "type": "bytes32" } + ], + "name": "AddressMissingHubTag", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" } + ], + "name": "CallerIsNotStatedProposer", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "caller", "type": "address" }, + { "internalType": "address", "name": "loanContract", "type": "address" } + ], + "name": "CallerNotLoanContract", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "feed", "type": "address" }, + { "internalType": "uint256", "name": "updatedAt", "type": "uint256" } + ], + "name": "ChainlinkFeedPriceTooOld", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "feed", "type": "address" }, + { "internalType": "int256", "name": "price", "type": "int256" }, + { "internalType": "uint256", "name": "updatedAt", "type": "uint256" } + ], + "name": "ChainlinkFeedReturnedNegativePrice", + "type": "error" + }, + { "inputs": [], "name": "ChainlinkInvalidInputLenghts", "type": "error" }, + { + "inputs": [ + { "internalType": "uint256", "name": "current", "type": "uint256" }, + { "internalType": "uint256", "name": "limit", "type": "uint256" } + ], + "name": "CreditAmountOutOfBounds", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint32", "name": "defaultDate", "type": "uint32" }, + { "internalType": "uint32", "name": "current", "type": "uint32" } + ], + "name": "DefaultDateInPast", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "current", "type": "uint256" }, + { "internalType": "uint256", "name": "expiration", "type": "uint256" } + ], + "name": "Expired", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "timeSinceUp", "type": "uint256" }, + { "internalType": "uint256", "name": "gracePeriod", "type": "uint256" } + ], + "name": "GracePeriodNotOver", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "current", "type": "uint256" }, + { "internalType": "uint256", "name": "limit", "type": "uint256" } + ], + "name": "IntermediaryDenominationsOutOfBounds", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "acceptorController", + "type": "address" + } + ], + "name": "InvalidAcceptorController", + "type": "error" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "current", "type": "bytes32" }, + { "internalType": "bytes32", "name": "proposed", "type": "bytes32" } + ], + "name": "InvalidCollateralStateFingerprint", + "type": "error" + }, + { "inputs": [], "name": "InvalidLPTokenPair", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + } + ], + "name": "InvalidRefinancingLoanId", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "signer", "type": "address" }, + { "internalType": "bytes32", "name": "digest", "type": "bytes32" } + ], + "name": "InvalidSignature", + "type": "error" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "length", "type": "uint256" } + ], + "name": "InvalidSignatureLength", + "type": "error" + }, + { "inputs": [], "name": "L2SequencerDown", "type": "error" }, + { "inputs": [], "name": "MinCreditAmountNotSet", "type": "error" }, + { "inputs": [], "name": "MissingStateFingerprintComputer", "type": "error" }, + { + "inputs": [ + { "internalType": "address", "name": "addr", "type": "address" }, + { "internalType": "uint256", "name": "nonceSpace", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" } + ], + "name": "NonceNotUsable", + "type": "error" + }, + { "inputs": [], "name": "T", "type": "error" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "proposalHash", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "proposer", + "type": "address" + }, + { + "components": [ + { + "internalType": "address[]", + "name": "tokenAAllowlist", + "type": "address[]" + }, + { + "internalType": "address[]", + "name": "tokenBAllowlist", + "type": "address[]" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "address[]", + "name": "feedIntermediaryDenominations", + "type": "address[]" + }, + { + "internalType": "bool[]", + "name": "feedInvertFlags", + "type": "bool[]" + }, + { + "internalType": "uint256", + "name": "loanToValue", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCreditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "acceptorController", + "type": "address" + }, + { + "internalType": "bytes", + "name": "acceptorControllerData", + "type": "bytes" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "indexed": false, + "internalType": "struct PWNSimpleLoanUniswapV3LPSetProposal.Proposal", + "name": "proposal", + "type": "tuple" + } + ], + "name": "ProposalMade", + "type": "event" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LOAN_TO_VALUE_DENOMINATOR", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_INTERMEDIARY_DENOMINATIONS", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MULTIPROPOSAL_DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MULTIPROPOSAL_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PROPOSAL_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "VERSION", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "WETH", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "acceptor", "type": "address" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { "internalType": "bytes", "name": "proposalData", "type": "bytes" }, + { + "internalType": "bytes32[]", + "name": "proposalInclusionProof", + "type": "bytes32[]" + }, + { "internalType": "bytes", "name": "signature", "type": "bytes" } + ], + "name": "acceptProposal", + "outputs": [ + { "internalType": "bytes32", "name": "proposalHash", "type": "bytes32" }, + { + "components": [ + { "internalType": "address", "name": "lender", "type": "address" }, + { "internalType": "address", "name": "borrower", "type": "address" }, + { "internalType": "uint32", "name": "duration", "type": "uint32" }, + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "internalType": "struct MultiToken.Asset", + "name": "collateral", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "enum MultiToken.Category", + "name": "category", + "type": "uint8" + }, + { + "internalType": "address", + "name": "assetAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "internalType": "struct MultiToken.Asset", + "name": "credit", + "type": "tuple" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "bytes32", + "name": "lenderSpecHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "borrowerSpecHash", + "type": "bytes32" + } + ], + "internalType": "struct PWNSimpleLoan.Terms", + "name": "loanTerms", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "chainlinkFeedRegistry", + "outputs": [ + { + "internalType": "contract IChainlinkFeedRegistryLike", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "chainlinkL2SequencerUptimeFeed", + "outputs": [ + { + "internalType": "contract IChainlinkAggregatorLike", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "config", + "outputs": [ + { "internalType": "contract PWNConfig", "name": "", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes", "name": "proposalData", "type": "bytes" } + ], + "name": "decodeProposalData", + "outputs": [ + { + "components": [ + { + "internalType": "address[]", + "name": "tokenAAllowlist", + "type": "address[]" + }, + { + "internalType": "address[]", + "name": "tokenBAllowlist", + "type": "address[]" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "address[]", + "name": "feedIntermediaryDenominations", + "type": "address[]" + }, + { + "internalType": "bool[]", + "name": "feedInvertFlags", + "type": "bool[]" + }, + { + "internalType": "uint256", + "name": "loanToValue", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCreditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "acceptorController", + "type": "address" + }, + { + "internalType": "bytes", + "name": "acceptorControllerData", + "type": "bytes" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanUniswapV3LPSetProposal.Proposal", + "name": "", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenAIndex", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenBIndex", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "creditAmount", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "acceptorControllerData", + "type": "bytes" + } + ], + "internalType": "struct PWNSimpleLoanUniswapV3LPSetProposal.ProposalValues", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "address[]", + "name": "tokenAAllowlist", + "type": "address[]" + }, + { + "internalType": "address[]", + "name": "tokenBAllowlist", + "type": "address[]" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "address[]", + "name": "feedIntermediaryDenominations", + "type": "address[]" + }, + { + "internalType": "bool[]", + "name": "feedInvertFlags", + "type": "bool[]" + }, + { + "internalType": "uint256", + "name": "loanToValue", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCreditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "acceptorController", + "type": "address" + }, + { + "internalType": "bytes", + "name": "acceptorControllerData", + "type": "bytes" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanUniswapV3LPSetProposal.Proposal", + "name": "proposal", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "collateralId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenAIndex", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenBIndex", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "creditAmount", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "acceptorControllerData", + "type": "bytes" + } + ], + "internalType": "struct PWNSimpleLoanUniswapV3LPSetProposal.ProposalValues", + "name": "proposalValues", + "type": "tuple" + } + ], + "name": "encodeProposalData", + "outputs": [{ "internalType": "bytes", "name": "", "type": "bytes" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "creditAddress", "type": "address" }, + { "internalType": "uint256", "name": "collateralId", "type": "uint256" }, + { "internalType": "bool", "name": "token0Denominator", "type": "bool" }, + { + "internalType": "address[]", + "name": "feedIntermediaryDenominations", + "type": "address[]" + }, + { "internalType": "bool[]", "name": "feedInvertFlags", "type": "bool[]" }, + { "internalType": "uint256", "name": "loanToValue", "type": "uint256" } + ], + "name": "getCreditAmount", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "bytes32", + "name": "multiproposalMerkleRoot", + "type": "bytes32" + } + ], + "internalType": "struct PWNSimpleLoanProposal.Multiproposal", + "name": "multiproposal", + "type": "tuple" + } + ], + "name": "getMultiproposalHash", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "address[]", + "name": "tokenAAllowlist", + "type": "address[]" + }, + { + "internalType": "address[]", + "name": "tokenBAllowlist", + "type": "address[]" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "address[]", + "name": "feedIntermediaryDenominations", + "type": "address[]" + }, + { + "internalType": "bool[]", + "name": "feedInvertFlags", + "type": "bool[]" + }, + { + "internalType": "uint256", + "name": "loanToValue", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCreditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "acceptorController", + "type": "address" + }, + { + "internalType": "bytes", + "name": "acceptorControllerData", + "type": "bytes" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanUniswapV3LPSetProposal.Proposal", + "name": "proposal", + "type": "tuple" + } + ], + "name": "getProposalHash", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "hub", + "outputs": [ + { "internalType": "contract PWNHub", "name": "", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "address[]", + "name": "tokenAAllowlist", + "type": "address[]" + }, + { + "internalType": "address[]", + "name": "tokenBAllowlist", + "type": "address[]" + }, + { + "internalType": "address", + "name": "creditAddress", + "type": "address" + }, + { + "internalType": "address[]", + "name": "feedIntermediaryDenominations", + "type": "address[]" + }, + { + "internalType": "bool[]", + "name": "feedInvertFlags", + "type": "bool[]" + }, + { + "internalType": "uint256", + "name": "loanToValue", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCreditAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableCreditLimit", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "utilizedCreditId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "fixedInterestAmount", + "type": "uint256" + }, + { + "internalType": "uint24", + "name": "accruingInterestAPR", + "type": "uint24" + }, + { + "internalType": "uint32", + "name": "durationOrDate", + "type": "uint32" + }, + { "internalType": "uint40", "name": "expiration", "type": "uint40" }, + { + "internalType": "address", + "name": "acceptorController", + "type": "address" + }, + { + "internalType": "bytes", + "name": "acceptorControllerData", + "type": "bytes" + }, + { "internalType": "address", "name": "proposer", "type": "address" }, + { + "internalType": "bytes32", + "name": "proposerSpecHash", + "type": "bytes32" + }, + { "internalType": "bool", "name": "isOffer", "type": "bool" }, + { + "internalType": "uint256", + "name": "refinancingLoanId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonceSpace", + "type": "uint256" + }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "internalType": "address", + "name": "loanContract", + "type": "address" + } + ], + "internalType": "struct PWNSimpleLoanUniswapV3LPSetProposal.Proposal", + "name": "proposal", + "type": "tuple" + } + ], + "name": "makeProposal", + "outputs": [ + { "internalType": "bytes32", "name": "proposalHash", "type": "bytes32" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "name": "proposalsMade", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "nonceSpace", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" } + ], + "name": "revokeNonce", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "revokedNonce", + "outputs": [ + { + "internalType": "contract PWNRevokedNonce", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "uniswapNFTPositionManager", + "outputs": [ + { + "internalType": "contract INonfungiblePositionManager", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "uniswapV3Factory", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "utilizedCredit", + "outputs": [ + { + "internalType": "contract PWNUtilizedCredit", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/packages/subgraph/config/mainnet.json b/packages/subgraph/config/mainnet.json new file mode 100644 index 0000000..12a28b9 --- /dev/null +++ b/packages/subgraph/config/mainnet.json @@ -0,0 +1,48 @@ +{ + "network": "mainnet", + "SimpleLoanSimpleProposal": { + "address": "0xe624E7D33baC728bE2bdB606Da0018B6E05A84D9", + "startBlock": 21628752 + }, + "SimpleLoanListProposal": { + "address": "0x7160Ec33788Df9AFb8AAEe777e7Ae21151B51eDd", + "startBlock": 21628752 + }, + "SimpleLoanElasticProposal": { + "address": "0xeC6390D4B22FFfD22E5C5FDB56DaF653C3Cd0626", + "startBlock": 21628752 + }, + "SimpleLoanElasticChainlinkProposal": { + "address": "0xBA58E16BE93dAdcBB74a194bDfD9E5933b24016B", + "startBlock": 21772404 + }, + "SimpleLoan": { + "address": "0x719A69d0dc67bd3Aa7648D4694081B3c87952797", + "startBlock": 21628749 + }, + "LoanToken": { + "address": "0x4440C069272cC34b80C7B11bEE657D0349Ba9C23", + "startBlock": 17289963 + }, + "Config": { + "address": "0xd52a2898d61636bB3eEF0d145f05352FF543bdCC", + "startBlock": 20046912 + }, + "Hub": { + "address": "0x37807A2F031b3B44081F4b21500E5D70EbaDAdd5", + "startBlock": 17289963 + }, + "ChainlinkFeedRegistry": { + "address": "0x8D5e90706E52a52853dA9A14fA1c63889a412851", + "startBlock": 21772404 + }, + "MultiTokenCategoryRegistry": { + "address": "0xbB2168d5546A94AE2DA9254e63D88F7f137B2534", + "startBlock": 20047106 + }, + "sepolia": { + "SimpleLoanUniswapV3LPSetProposal": { + "address": "0x7b48798CE8e95f1412078cF2e1a176CA12839AfA" + } + } +} \ No newline at end of file diff --git a/packages/subgraph/config/sepolia.json b/packages/subgraph/config/sepolia.json new file mode 100644 index 0000000..e6353bb --- /dev/null +++ b/packages/subgraph/config/sepolia.json @@ -0,0 +1,51 @@ +{ + "network": "sepolia", + "SimpleLoanSimpleProposal": { + "address": "0xe624E7D33baC728bE2bdB606Da0018B6E05A84D9", + "startBlock": 7298850 + }, + "SimpleLoanListProposal": { + "address": "0x7160Ec33788Df9AFb8AAEe777e7Ae21151B51eDd", + "startBlock": 7298850 + }, + "SimpleLoanElasticProposal": { + "address": "0xeC6390D4B22FFfD22E5C5FDB56DaF653C3Cd0626", + "startBlock": 7298851 + }, + "SimpleLoanElasticChainlinkProposal": { + "address": "0xC46170F43b97faE1A8B507d6fdDaFfBb7527D61B", + "startBlock": 8069855 + }, + "SimpleLoan": { + "address": "0x719A69d0dc67bd3Aa7648D4694081B3c87952797", + "startBlock": 7298850 + }, + "LoanToken": { + "address": "0x4440C069272cC34b80C7B11bEE657D0349Ba9C23", + "startBlock": 4435806 + }, + "Config": { + "address": "0xd52a2898d61636bB3eEF0d145f05352FF543bdCC", + "startBlock": 5953668 + }, + "Hub": { + "address": "0x37807A2F031b3B44081F4b21500E5D70EbaDAdd5", + "startBlock": 4435806 + }, + "ChainlinkFeedRegistry": { + "address": "0x8D5e90706E52a52853dA9A14fA1c63889a412851", + "startBlock": 7298850 + }, + "MultiTokenCategoryRegistry": { + "address": "0xbB2168d5546A94AE2DA9254e63D88F7f137B2534", + "startBlock": 5953672 + }, + "SimpleLoanUniswapV3LPIndividualProposal": { + "address": "0xF966696BE0623447679AC830FC5bB7bDB15FEAB4", + "startBlock": 8518575 + }, + "SimpleLoanUniswapV3LPSetProposal": { + "address": "0x7b48798CE8e95f1412078cF2e1a176CA12839AfA", + "startBlock": 8518575 + } +} \ No newline at end of file diff --git a/packages/subgraph/matchstick.yaml b/packages/subgraph/matchstick.yaml new file mode 100644 index 0000000..6a7c10d --- /dev/null +++ b/packages/subgraph/matchstick.yaml @@ -0,0 +1,3 @@ +testsFolder: tests +libsFolder: ./node_modules +manifestPath: subgraph.yaml \ No newline at end of file diff --git a/packages/subgraph/package.json b/packages/subgraph/package.json new file mode 100644 index 0000000..83ca0fb --- /dev/null +++ b/packages/subgraph/package.json @@ -0,0 +1,39 @@ +{ + "name": "@pwndao/subgraph", + "version": "0.0.1-beta.20", + "type": "module", + "license": "UNLICENSED", + "main": "./dist/index.js", + "module": "./dist/index.js", + "types": "./dist/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js", + "default": "./dist/index.js" + } + }, + "scripts": { + "prepare:mainnet": "mustache config/mainnet.json subgraph.template.yaml > subgraph.yaml", + "prepare:sepolia": "mustache config/sepolia.json subgraph.template.yaml > subgraph.yaml", + "codegen": "nx exec -- graph codegen", + "build": "nx exec -- graph build", + "deploy": "nx exec -- graph deploy pwndao-test-subgraph subgraph.yaml", + "create-local": "nx exec -- graph create --node http://localhost:8020/ pwn-test-proposals", + "remove-local": "nx exec -- graph remove --node http://localhost:8020/ pwn-test-proposals", + "deploy-local": "nx exec -- graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 pwn-test-proposals", + "docker-prepare": "docker build -t matchstick .", + "auth-subgraph-studio": "graph auth", + "test:with-docker": "nx exec -- graph test -d", + "test": "nx exec -- graph test", + "help": "nx exec -- graph test --help" + }, + "dependencies": { + "@graphprotocol/graph-cli": "0.97.1", + "@graphprotocol/graph-ts": "0.38.1", + "mustache": "^3.1.0", + "matchstick-as": "0.6.0" + }, + "files": ["dist", "!**/*.tsbuildinfo"] +} diff --git a/packages/subgraph/project.json b/packages/subgraph/project.json new file mode 100644 index 0000000..6fbecf2 --- /dev/null +++ b/packages/subgraph/project.json @@ -0,0 +1,11 @@ +{ + "name": "@pwndao/subgraph", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "packages/subgraph/src", + "projectType": "library", + "tags": [ + "subgraph" + ], + "targets": { + } +} diff --git a/packages/subgraph/schema.graphql b/packages/subgraph/schema.graphql new file mode 100644 index 0000000..42b5d8a --- /dev/null +++ b/packages/subgraph/schema.graphql @@ -0,0 +1,804 @@ +type Account @entity(immutable: true) { + id: Bytes! # Ethereum address + loansAsBorrower: [Loan!]! @derivedFrom(field: "borrower") + loansAsLender: [Loan!]! @derivedFrom(field: "originalLender") + loansAsLoanOwner: [Loan!]! @derivedFrom(field: "loanOwner") +} + +type AssetCategory @entity(immutable: true) { + id: Bytes! # category id + assets: [AssetContract!]! @derivedFrom(field: "category") +} + +type AssetContract @entity(immutable: true) { + id: Bytes! # asset address + category: AssetCategory + # TODO add also metadata like name / symbol / decimals? +} + +type Asset @entity(immutable: true) { + id: Bytes! # {contract.assetAddress}{assetId} + + contract: AssetContract! + # TODO allow null in case of ERC20s? + tokenId: BigInt! + # TODO use BigInt? + #amount: BigDecimal! + # TODO add also metadata like name / symbol / decimals? +} + +enum LoanStatus { + Active + Repaid + # we do not use defaulted state here as it can't be calculated from the onchain event + # as there is no onchain event when a loan defaults + # Defaulted + Claimed +} + +enum LoanType { + SimpleLoan +} + +type Loan @entity(immutable: false) { + # Combination of chainId and loanId from contract + id: Bytes! # {loanTokenAddress}{loanId} + + # Loan ID from contract event + loanId: BigInt! + + proposal: Proposal + + # Proposal contract address + proposalContract: Bytes! + + loanTokenAddress: Bytes! + + repaidAt: BigInt + claimedAt: BigInt + + contractAddress: Bytes! + + refinancingLoanId: BigInt! + + # Hash of accepted proposal + proposalHash: Bytes! + + borrower: Account! + originalLender: Account! + + loanOwner: Account! + + createdAt: BigInt! + + duration: BigInt! + + defaultDate: BigInt! + + collateral: Asset! + collateralAmount: BigInt! + + credit: Asset! + creditAmount: BigInt! + + status: LoanStatus! + + fixedInterestAmount: BigInt! + accruingInterestAPR: Int! + + lenderSpecHash: Bytes! + borrowerSpecHash: Bytes! + + sourceOfFunds: Bytes! + + extra: Bytes! + + hasDefaulted: Boolean! + + loanType: LoanType! + + # TODO also add Loan contract version? +} + +enum ProposalStatus { + # TODO can we even handle statuses aother than Active? + Active + Revoked + Expired + Accepted +} + +enum ProposalType { + Simple + List + Elastic + ElasticChainlink + UniswapV3LPIndividual + UniswapV3LPSet +} + +# TODO do interface for common proposal base fields??? + +# TODO how can we mark this proposal as revoked when a nonce is revoked? +type Proposal @entity(immutable: true) { + id: Bytes! # proposal hash + proposer: Bytes! # address + createdAt: BigInt! + + # Proposal type discriminator + proposalType: ProposalType! + + # Common fields for all proposal types + credit: Asset! + fixedInterestAmount: BigInt! + accruingInterestAPR: Int! + availableCreditLimit: BigInt! + utilizedCreditId: Bytes! + durationOrDate: BigInt! + expiration: BigInt! + proposerSpecHash: Bytes! + isOffer: Boolean! + refinancingLoanId: BigInt! + nonceSpace: BigInt! + nonce: BigInt! + loanContract: Bytes! + status: ProposalStatus! + blockNumber: BigInt! + transactionHash: Bytes! + loans: [Loan!]! @derivedFrom(field: "proposal") + + # Simple proposal specific fields (ProposalType.Simple) + # - collateral: Asset (active) + # - collateralAmount: BigInt (active) + # - creditAmount: BigInt (active) + # - allowedAcceptor: Bytes (active) + # - checkCollateralStateFingerprint: Boolean (active) + # - collateralStateFingerprint: Bytes (active) + collateral: Asset + collateralAmount: BigInt + creditAmount: BigInt + allowedAcceptor: Bytes + checkCollateralStateFingerprint: Boolean + collateralStateFingerprint: Bytes + + # List proposal specific fields (ProposalType.List) + # - collateral: Asset (shared with Simple) + # - collateralAmount: BigInt (shared with Simple) + # - creditAmount: BigInt (shared with Simple) + # - allowedAcceptor: Bytes (shared with Simple) + # - checkCollateralStateFingerprint: Boolean (shared with Simple) + # - collateralStateFingerprint: Bytes (shared with Simple) + # - collateralIdsWhitelistMerkleRoot: Bytes (active) + collateralIdsWhitelistMerkleRoot: Bytes + + # Elastic proposal specific fields (ProposalType.Elastic) + # - collateral: Asset (shared, but uses collateralId instead of full Asset) + # - checkCollateralStateFingerprint: Boolean (shared) + # - collateralStateFingerprint: Bytes (shared) + # - creditPerCollateralUnit: BigInt (active) + # - minCreditAmount: BigInt (active) + # - allowedAcceptor: Bytes (shared) + creditPerCollateralUnit: BigInt + minCreditAmount: BigInt + + # Elastic Chainlink proposal specific fields (ProposalType.ElasticChainlink) + # - collateral: Asset (shared, but uses collateralId) + # - checkCollateralStateFingerprint: Boolean (shared) + # - collateralStateFingerprint: Bytes (shared) + # - feedIntermediaryDenominations: [Bytes!] (active) + # - feedInvertFlags: [Boolean!] (active) + # - loanToValue: BigInt (active) + # - minCreditAmount: BigInt (shared with Elastic) + # - allowedAcceptor: Bytes (shared) + feedIntermediaryDenominations: [Bytes!] + feedInvertFlags: [Boolean!] + loanToValue: BigInt + + # Uniswap V3 LP Individual proposal specific fields (ProposalType.UniswapV3LPIndividual) + # - collateralId: BigInt (active) + # - token0Denominator: Boolean (active) + # - feedIntermediaryDenominations: [Bytes!] (shared with ElasticChainlink) + # - feedInvertFlags: [Boolean!] (shared with ElasticChainlink) + # - loanToValue: BigInt (shared with ElasticChainlink) + # - minCreditAmount: BigInt (shared) + # - acceptorController: Bytes (active) + # - acceptorControllerData: Bytes (active) + collateralId: BigInt + token0Denominator: Boolean + acceptorController: Bytes + acceptorControllerData: Bytes + + # Uniswap V3 LP Set proposal specific fields (ProposalType.UniswapV3LPSet) + # - tokenAAllowlist: [Bytes!] (active) + # - tokenBAllowlist: [Bytes!] (active) + # - feedIntermediaryDenominations: [Bytes!] (shared with ElasticChainlink) + # - feedInvertFlags: [Boolean!] (shared with ElasticChainlink) + # - loanToValue: BigInt (shared with ElasticChainlink) + # - minCreditAmount: BigInt (shared) + # - acceptorController: Bytes (shared with UniswapV3LPIndividual) + # - acceptorControllerData: Bytes (shared with UniswapV3LPIndividual) + tokenAAllowlist: [Bytes!] + tokenBAllowlist: [Bytes!] + + # Direct reference to the raw event entity for easy function calls + rawEventSimple: SimpleLoanSimpleProposalMade + rawEventList: SimpleLoanListProposalProposalMade + rawEventElastic: SimpleLoanElasticProposalProposalMade + rawEventElasticChainlink: SimpleLoanElasticChainlinkProposalProposalMade + rawEventUniswapV3LPIndividual: SimpleLoanUniswapV3LPIndividualProposalProposalMade + rawEventUniswapV3LPSet: SimpleLoanUniswapV3LPSetProposalProposalMade +} + +# TODO add version + +type SimpleLoanSimpleProposalMade @entity(immutable: true) { + id: Bytes! + proposalHash: Bytes! # bytes32 + proposer: Bytes! # address + + # Reference to the unified Proposal entity + proposal: Proposal! + + # Raw proposal parameters (for easy extraction to function calls) + collateralCategory: Int! # uint8 + collateralAddress: Bytes! # address + collateralId: BigInt! # uint256 + collateralAmount: BigInt! # uint256 + checkCollateralStateFingerprint: Boolean! # bool + collateralStateFingerprint: Bytes! # bytes32 + creditAddress: Bytes! # address + creditAmount: BigInt! # uint256 + availableCreditLimit: BigInt! # uint256 + utilizedCreditId: Bytes! # bytes32 + fixedInterestAmount: BigInt! # uint256 + accruingInterestAPR: Int! # uint24 + durationOrDate: BigInt! # uint32 + expiration: BigInt! # uint40 + allowedAcceptor: Bytes! # address + proposerSpecHash: Bytes! # bytes32 + isOffer: Boolean! # bool + refinancingLoanId: BigInt! # uint256 + nonceSpace: BigInt! # uint256 + nonce: BigInt! # uint256 + loanContract: Bytes! # address + blockNumber: BigInt! + blockTimestamp: BigInt! + transactionHash: Bytes! +} + +type SimpleLoanUniswapV3LPIndividualProposalProposalMade + @entity(immutable: true) { + id: Bytes! + proposalHash: Bytes! # bytes32 + proposer: Bytes! # address + + # Reference to the unified Proposal entity + proposal: Proposal! + + # Raw proposal parameters (for easy extraction to function calls) + collateralId: BigInt! # uint256 + token0Denominator: Boolean! # bool + creditAddress: Bytes! # address + feedIntermediaryDenominations: [Bytes!]! # address[] + feedInvertFlags: [Boolean!]! # bool[] + loanToValue: BigInt! # uint256 + minCreditAmount: BigInt! # uint256 + availableCreditLimit: BigInt! # uint256 + utilizedCreditId: Bytes! # bytes32 + fixedInterestAmount: BigInt! # uint256 + accruingInterestAPR: Int! # uint24 + durationOrDate: BigInt! # uint32 + expiration: BigInt! # uint40 + acceptorController: Bytes! # address + acceptorControllerData: Bytes! # bytes + proposerSpecHash: Bytes! # bytes32 + isOffer: Boolean! # bool + refinancingLoanId: BigInt! # uint256 + nonceSpace: BigInt! # uint256 + nonce: BigInt! # uint256 + loanContract: Bytes! # address + blockNumber: BigInt! + blockTimestamp: BigInt! + transactionHash: Bytes! +} + +type SimpleLoanUniswapV3LPSetProposalProposalMade @entity(immutable: true) { + id: Bytes! + proposalHash: Bytes! # bytes32 + proposer: Bytes! # address + + # Reference to the unified Proposal entity + proposal: Proposal! + + # Raw proposal parameters (for easy extraction to function calls) + tokenAAllowlist: [Bytes!]! # address[] + tokenBAllowlist: [Bytes!]! # address[] + creditAddress: Bytes! # address + feedIntermediaryDenominations: [Bytes!]! # address[] + feedInvertFlags: [Boolean!]! # bool[] + loanToValue: BigInt! # uint256 + minCreditAmount: BigInt! # uint256 + availableCreditLimit: BigInt! # uint256 + utilizedCreditId: Bytes! # bytes32 + fixedInterestAmount: BigInt! # uint256 + accruingInterestAPR: Int! # uint24 + durationOrDate: BigInt! # uint32 + expiration: BigInt! # uint40 + acceptorController: Bytes! # address + acceptorControllerData: Bytes! # bytes + proposerSpecHash: Bytes! # bytes32 + isOffer: Boolean! # bool + refinancingLoanId: BigInt! # uint256 + nonceSpace: BigInt! # uint256 + nonce: BigInt! # uint256 + loanContract: Bytes! # address + blockNumber: BigInt! + blockTimestamp: BigInt! + transactionHash: Bytes! +} + +type SimpleLoanListProposalProposalMade @entity(immutable: true) { + id: Bytes! + proposalHash: Bytes! # bytes32 + proposer: Bytes! # address + + # Reference to the unified Proposal entity + proposal: Proposal! + + # Raw proposal parameters (for easy extraction to function calls) + collateralCategory: Int! # uint8 + collateralAddress: Bytes! # address + collateralIdsWhitelistMerkleRoot: Bytes! # bytes32 + collateralAmount: BigInt! # uint256 + checkCollateralStateFingerprint: Boolean! # bool + collateralStateFingerprint: Bytes! # bytes32 + creditAddress: Bytes! # address + creditAmount: BigInt! # uint256 + availableCreditLimit: BigInt! # uint256 + utilizedCreditId: Bytes! # bytes32 + fixedInterestAmount: BigInt! # uint256 + accruingInterestAPR: Int! # uint24 + durationOrDate: BigInt! # uint32 + expiration: BigInt! # uint40 + allowedAcceptor: Bytes! # address + proposerSpecHash: Bytes! # bytes32 + isOffer: Boolean! # bool + refinancingLoanId: BigInt! # uint256 + nonceSpace: BigInt! # uint256 + nonce: BigInt! # uint256 + loanContract: Bytes! # address + blockNumber: BigInt! + blockTimestamp: BigInt! + transactionHash: Bytes! +} +type SimpleLoanElasticProposalProposalMade @entity(immutable: true) { + id: Bytes! + proposalHash: Bytes! # bytes32 + proposer: Bytes! # address + + # Reference to the unified Proposal entity + proposal: Proposal! + + # Raw proposal parameters (for easy extraction to function calls) + collateralCategory: Int! # uint8 + collateralAddress: Bytes! # address + collateralId: BigInt! # uint256 + checkCollateralStateFingerprint: Boolean! # bool + collateralStateFingerprint: Bytes! # bytes32 + creditAddress: Bytes! # address + creditPerCollateralUnit: BigInt! # uint256 + minCreditAmount: BigInt! # uint256 + availableCreditLimit: BigInt! # uint256 + utilizedCreditId: Bytes! # bytes32 + fixedInterestAmount: BigInt! # uint256 + accruingInterestAPR: Int! # uint24 + durationOrDate: BigInt! # uint32 + expiration: BigInt! # uint40 + allowedAcceptor: Bytes! # address + proposerSpecHash: Bytes! # bytes32 + isOffer: Boolean! # bool + refinancingLoanId: BigInt! # uint256 + nonceSpace: BigInt! # uint256 + nonce: BigInt! # uint256 + loanContract: Bytes! # address + blockNumber: BigInt! + blockTimestamp: BigInt! + transactionHash: Bytes! +} +type SimpleLoanElasticChainlinkProposalProposalMade @entity(immutable: true) { + id: Bytes! + proposalHash: Bytes! # bytes32 + proposer: Bytes! # address + + # Reference to the unified Proposal entity + proposal: Proposal! + + # Raw proposal parameters (for easy extraction to function calls) + collateralCategory: Int! # uint8 + collateralAddress: Bytes! # address + collateralId: BigInt! # uint256 + checkCollateralStateFingerprint: Boolean! # bool + collateralStateFingerprint: Bytes! # bytes32 + creditAddress: Bytes! # address + feedIntermediaryDenominations: [Bytes!]! # address[] + feedInvertFlags: [Boolean!]! # bool[] + loanToValue: BigInt! # uint256 + minCreditAmount: BigInt! # uint256 + availableCreditLimit: BigInt! # uint256 + utilizedCreditId: Bytes! # bytes32 + fixedInterestAmount: BigInt! # uint256 + accruingInterestAPR: Int! # uint24 + durationOrDate: BigInt! # uint32 + expiration: BigInt! # uint40 + allowedAcceptor: Bytes! # address + proposerSpecHash: Bytes! # bytes32 + isOffer: Boolean! # bool + refinancingLoanId: BigInt! # uint256 + nonceSpace: BigInt! # uint256 + nonce: BigInt! # uint256 + loanContract: Bytes! # address + blockNumber: BigInt! + blockTimestamp: BigInt! + transactionHash: Bytes! +} + +type ExtensionProposal @entity(immutable: true) { + id: Bytes! # extensionHash + proposer: Bytes! # address + # TODO shall we allow null values here? + loan: Loan! + + compensationAssetAddress: Bytes! + # compensationAsset: AssetContract! + compensationAmount: BigInt + + durationToExtend: BigInt + proposalExpiration: BigInt + + nonce: BigInt! + nonceSpace: BigInt! + + createdAt: BigInt! +} + +type ChainlinkFeed @entity(immutable: true) { + id: Bytes! + asset: Bytes! # address + denomination: Bytes! # address + aggregator: Bytes! # feed address +} + +type LoanExtendedEvent @entity(immutable: true) { + id: Bytes! + loanId: BigInt! # uint256 + originalDefaultTimestamp: BigInt! # uint40 + extendedDefaultTimestamp: BigInt! # uint40 + blockNumber: BigInt! + blockTimestamp: BigInt! + transactionHash: Bytes! +} + +type LoanTokenTransfer @entity(immutable: true) { + id: Bytes! + contractAddress: Bytes! # address + from: Bytes! # address + to: Bytes! # address + tokenId: BigInt! # uint256 + blockNumber: BigInt! + blockTimestamp: BigInt! + transactionHash: Bytes! +} + +type TagSetEvent @entity(immutable: true) { + id: Bytes! + _address: Bytes! # address + tag: Bytes! # bytes32 + hasTag: Boolean! # bool + blockNumber: BigInt! + blockTimestamp: BigInt! + transactionHash: Bytes! +} + +# ============================== +# TO REMOVE??? +# ============================== + +# type LoanPaidBackEvent @entity(immutable: true) { +# id: Bytes! +# loanId: BigInt! # uint256 +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type LoanClaimedEvent @entity(immutable: true) { +# id: Bytes! +# loanId: BigInt! # uint256 +# defaulted: Boolean! # bool +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type LoanCreatedEvent @entity(immutable: true) { +# id: Bytes! +# loanId: BigInt! # uint256 +# proposalHash: Bytes! # bytes32 +# proposalContract: Bytes! # address +# refinancingLoanId: BigInt! # uint256 +# terms_lender: Bytes! # address +# terms_borrower: Bytes! # address +# terms_duration: BigInt! # uint32 +# terms_collateral_category: Int! # uint8 +# terms_collateral_assetAddress: Bytes! # address +# terms_collateral_id: BigInt! # uint256 +# terms_collateral_amount: BigInt! # uint256 +# terms_credit_category: Int! # uint8 +# terms_credit_assetAddress: Bytes! # address +# terms_credit_id: BigInt! # uint256 +# terms_credit_amount: BigInt! # uint256 +# terms_fixedInterestAmount: BigInt! # uint256 +# terms_accruingInterestAPR: Int! # uint24 +# terms_lenderSpecHash: Bytes! # bytes32 +# terms_borrowerSpecHash: Bytes! # bytes32 +# lenderSpec_sourceOfFunds: Bytes! # address +# extra: Bytes! # bytes +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# =============================== +# UNUSED ENTITIES +# =============================== + +# type DefaultLOANMetadataUriUpdated @entity(immutable: true) { +# id: Bytes! +# newUri: String! # string +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type FeeCollectorUpdated @entity(immutable: true) { +# id: Bytes! +# oldFeeCollector: Bytes! # address +# newFeeCollector: Bytes! # address +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type FeeUpdated @entity(immutable: true) { +# id: Bytes! +# oldFee: Int! # uint16 +# newFee: Int! # uint16 +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type LOANMetadataUriUpdated @entity(immutable: true) { +# id: Bytes! +# loanContract: Bytes! # address +# newUri: String! # string +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } +# type LOANBurned @entity(immutable: true) { +# id: Bytes! +# loanId: BigInt! # uint256 +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type LOANMinted @entity(immutable: true) { +# id: Bytes! +# loanId: BigInt! # uint256 +# loanContract: Bytes! # address +# owner: Bytes! # address +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + + +# type AdminChanged @entity(immutable: true) { +# id: Bytes! +# previousAdmin: Bytes! # address +# newAdmin: Bytes! # address +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type BeaconUpgraded @entity(immutable: true) { +# id: Bytes! +# beacon: Bytes! # address +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type Upgraded @entity(immutable: true) { +# id: Bytes! +# implementation: Bytes! # address +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type Initialized @entity(immutable: true) { +# id: Bytes! +# version: Int! # uint8 +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + + +# type Approval @entity(immutable: true) { +# id: Bytes! +# owner: Bytes! # address +# approved: Bytes! # address +# tokenId: BigInt! # uint256 +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type ApprovalForAll @entity(immutable: true) { +# id: Bytes! +# owner: Bytes! # address +# operator: Bytes! # address +# approved: Boolean! # bool +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type ConfigOwnershipTransferStarted @entity(immutable: true) { +# id: Bytes! +# previousOwner: Bytes! # address +# newOwner: Bytes! # address +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type ConfigOwnershipTransferred @entity(immutable: true) { +# id: Bytes! +# previousOwner: Bytes! # address +# newOwner: Bytes! # address +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type OwnershipTransferStarted @entity(immutable: true) { +# id: Bytes! +# previousOwner: Bytes! # address +# newOwner: Bytes! # address +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type OwnershipTransferred @entity(immutable: true) { +# id: Bytes! +# previousOwner: Bytes! # address +# newOwner: Bytes! # address +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + + +# type FeedConfirmed @entity(immutable: true) { +# id: Bytes! +# asset: Bytes! # address +# denomination: Bytes! # address +# latestAggregator: Bytes! # address +# previousAggregator: Bytes! # address +# nextPhaseId: Int! # uint16 +# sender: Bytes! # address +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type FeedProposed @entity(immutable: true) { +# id: Bytes! +# asset: Bytes! # address +# denomination: Bytes! # address +# proposedAggregator: Bytes! # address +# currentAggregator: Bytes! # address +# sender: Bytes! # address +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type CategoryRegistered @entity(immutable: true) { +# id: Bytes! +# assetAddress: Bytes! # address +# category: Int! # uint8 +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type CategoryUnregistered @entity(immutable: true) { +# id: Bytes! +# assetAddress: Bytes! # address +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type PoolSupply @entity(immutable: true) { +# id: Bytes! +# asset_category: Int! # uint8 +# asset_assetAddress: Bytes! # address +# asset_id: BigInt! # uint256 +# asset_amount: BigInt! # uint256 +# poolAdapter: Bytes! # address +# pool: Bytes! # address +# owner: Bytes! # address +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type PoolWithdraw @entity(immutable: true) { +# id: Bytes! +# asset_category: Int! # uint8 +# asset_assetAddress: Bytes! # address +# asset_id: BigInt! # uint256 +# asset_amount: BigInt! # uint256 +# poolAdapter: Bytes! # address +# pool: Bytes! # address +# owner: Bytes! # address +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type VaultPull @entity(immutable: true) { +# id: Bytes! +# asset_category: Int! # uint8 +# asset_assetAddress: Bytes! # address +# asset_id: BigInt! # uint256 +# asset_amount: BigInt! # uint256 +# origin: Bytes! # address +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type VaultPush @entity(immutable: true) { +# id: Bytes! +# asset_category: Int! # uint8 +# asset_assetAddress: Bytes! # address +# asset_id: BigInt! # uint256 +# asset_amount: BigInt! # uint256 +# beneficiary: Bytes! # address +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } + +# type VaultPushFrom @entity(immutable: true) { +# id: Bytes! +# asset_category: Int! # uint8 +# asset_assetAddress: Bytes! # address +# asset_id: BigInt! # uint256 +# asset_amount: BigInt! # uint256 +# origin: Bytes! # address +# beneficiary: Bytes! # address +# blockNumber: BigInt! +# blockTimestamp: BigInt! +# transactionHash: Bytes! +# } diff --git a/packages/subgraph/src/chainlink-feed-registry.ts b/packages/subgraph/src/chainlink-feed-registry.ts new file mode 100644 index 0000000..1924d5c --- /dev/null +++ b/packages/subgraph/src/chainlink-feed-registry.ts @@ -0,0 +1,58 @@ +import { + FeedConfirmed as FeedConfirmedEvent, +} from "../generated/ChainlinkFeedRegistry/ChainlinkFeedRegistry" +import { + ChainlinkFeed, +} from "../generated/schema" +import { Bytes } from "@graphprotocol/graph-ts" + +function getChainlinkFeedId(event: FeedConfirmedEvent): Bytes { + return event.params.asset.concat(event.params.denomination) +} + +export function handleFeedConfirmed(event: FeedConfirmedEvent): void { + const chainlinkFeedId = getChainlinkFeedId(event) + let chainlinkFeed = ChainlinkFeed.load(chainlinkFeedId) + if (chainlinkFeed == null) { + chainlinkFeed = new ChainlinkFeed(chainlinkFeedId) + } + + chainlinkFeed.asset = event.params.asset + chainlinkFeed.denomination = event.params.denomination + chainlinkFeed.aggregator = event.params.latestAggregator + chainlinkFeed.save() + + // const entity = new FeedConfirmed( + // event.transaction.hash.concatI32(event.logIndex.toI32()), + // ) + // entity.asset = event.params.asset + // entity.denomination = event.params.denomination + // entity.latestAggregator = event.params.latestAggregator + // entity.previousAggregator = event.params.previousAggregator + // entity.nextPhaseId = event.params.nextPhaseId + // entity.sender = event.params.sender + + // entity.blockNumber = event.block.number + // entity.blockTimestamp = event.block.timestamp + // entity.transactionHash = event.transaction.hash + + // entity.save() +} + +// export function handleFeedProposed(event: FeedProposedEvent): void { +// const entity = new FeedProposed( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.asset = event.params.asset +// entity.denomination = event.params.denomination +// entity.proposedAggregator = event.params.proposedAggregator +// entity.currentAggregator = event.params.currentAggregator +// entity.sender = event.params.sender + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } + diff --git a/packages/subgraph/src/config.ts b/packages/subgraph/src/config.ts new file mode 100644 index 0000000..28bec13 --- /dev/null +++ b/packages/subgraph/src/config.ts @@ -0,0 +1,164 @@ +// import { +// AdminChanged as AdminChangedEvent, +// BeaconUpgraded as BeaconUpgradedEvent, +// Upgraded as UpgradedEvent, +// DefaultLOANMetadataUriUpdated as DefaultLOANMetadataUriUpdatedEvent, +// FeeCollectorUpdated as FeeCollectorUpdatedEvent, +// FeeUpdated as FeeUpdatedEvent, +// Initialized as InitializedEvent, +// LOANMetadataUriUpdated as LOANMetadataUriUpdatedEvent, +// OwnershipTransferStarted as OwnershipTransferStartedEvent, +// OwnershipTransferred as OwnershipTransferredEvent, +// } from "../generated/Config/Config" +// import { +// DefaultLOANMetadataUriUpdated, +// FeeCollectorUpdated, +// FeeUpdated, +// LOANMetadataUriUpdated, +// } from "../generated/schema" + +// export function handleAdminChanged(event: AdminChangedEvent): void { +// const entity = new AdminChanged( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.previousAdmin = event.params.previousAdmin +// entity.newAdmin = event.params.newAdmin + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } + +// export function handleBeaconUpgraded(event: BeaconUpgradedEvent): void { +// const entity = new BeaconUpgraded( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.beacon = event.params.beacon + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } + +// export function handleUpgraded(event: UpgradedEvent): void { +// const entity = new Upgraded( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.implementation = event.params.implementation + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } + +// export function handleDefaultLOANMetadataUriUpdated( +// event: DefaultLOANMetadataUriUpdatedEvent, +// ): void { +// const entity = new DefaultLOANMetadataUriUpdated( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.newUri = event.params.newUri + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } + +// export function handleFeeCollectorUpdated( +// event: FeeCollectorUpdatedEvent, +// ): void { +// const entity = new FeeCollectorUpdated( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.oldFeeCollector = event.params.oldFeeCollector +// entity.newFeeCollector = event.params.newFeeCollector + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } + +// export function handleFeeUpdated(event: FeeUpdatedEvent): void { +// const entity = new FeeUpdated( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.oldFee = event.params.oldFee +// entity.newFee = event.params.newFee + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } + +// export function handleInitialized(event: InitializedEvent): void { +// const entity = new Initialized( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.version = event.params.version + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } + +// export function handleLOANMetadataUriUpdated( +// event: LOANMetadataUriUpdatedEvent, +// ): void { +// const entity = new LOANMetadataUriUpdated( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.loanContract = event.params.loanContract +// entity.newUri = event.params.newUri + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } + +// export function handleOwnershipTransferStarted( +// event: OwnershipTransferStartedEvent, +// ): void { +// const entity = new OwnershipTransferStarted( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.previousOwner = event.params.previousOwner +// entity.newOwner = event.params.newOwner + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } + +// export function handleOwnershipTransferred( +// event: OwnershipTransferredEvent, +// ): void { +// const entity = new OwnershipTransferred( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.previousOwner = event.params.previousOwner +// entity.newOwner = event.params.newOwner + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } diff --git a/packages/subgraph/src/entity-helpers/get-or-create.ts b/packages/subgraph/src/entity-helpers/get-or-create.ts new file mode 100644 index 0000000..e69de29 diff --git a/packages/subgraph/src/entity-helpers/ids.ts b/packages/subgraph/src/entity-helpers/ids.ts new file mode 100644 index 0000000..e69de29 diff --git a/packages/subgraph/src/helpers.ts b/packages/subgraph/src/helpers.ts new file mode 100644 index 0000000..2311f20 --- /dev/null +++ b/packages/subgraph/src/helpers.ts @@ -0,0 +1,20 @@ +import { Address, BigInt, Bytes } from "@graphprotocol/graph-ts"; +import { Account } from "../generated/schema"; + +// TODO add logs where applicable +export function getOrCreateAccount(address: Address): Account { + let account = Account.load(address); + if (account == null) { + account = new Account(address); + account.save(); + } + return account; +} + +export function getAssetContractId(assetAddress: Address): Bytes { + return assetAddress; +} + +export function getAssetId(assetAddress: Address, assetId: BigInt): Bytes { + return assetAddress.concat(Bytes.fromByteArray(Bytes.fromBigInt(assetId))); +} diff --git a/packages/subgraph/src/hub.ts b/packages/subgraph/src/hub.ts new file mode 100644 index 0000000..6374ebd --- /dev/null +++ b/packages/subgraph/src/hub.ts @@ -0,0 +1,21 @@ +import { + TagSet as TagSetEvent, +} from "../generated/Hub/Hub" +import { + TagSetEvent as TagSetEventEntity, +} from "../generated/schema" + +export function handleTagSet(event: TagSetEvent): void { + const entity = new TagSetEventEntity( + event.transaction.hash.concatI32(event.logIndex.toI32()), + ) + entity._address = event.params._address + entity.tag = event.params.tag + entity.hasTag = event.params.hasTag + + entity.blockNumber = event.block.number + entity.blockTimestamp = event.block.timestamp + entity.transactionHash = event.transaction.hash + + entity.save() +} diff --git a/packages/subgraph/src/loan-token.ts b/packages/subgraph/src/loan-token.ts new file mode 100644 index 0000000..de27663 --- /dev/null +++ b/packages/subgraph/src/loan-token.ts @@ -0,0 +1,98 @@ +import { + LoanToken, + Transfer as TransferEvent, +} from "../generated/LoanToken/LoanToken" +import { + Loan, + LoanTokenTransfer, +} from "../generated/schema" +import { getOrCreateAccount } from "./helpers" +import { getLoanId } from "./simple-loan" + +export function handleTransfer(event: TransferEvent): void { + const entity = new LoanTokenTransfer( + event.transaction.hash.concatI32(event.logIndex.toI32()), + ) + entity.from = event.params.from + entity.to = event.params.to + entity.tokenId = event.params.tokenId + entity.contractAddress = event.address + + entity.blockNumber = event.block.number + entity.blockTimestamp = event.block.timestamp + entity.transactionHash = event.transaction.hash + + entity.save() + + // also update the loan owner + const loanTokenContract = LoanToken.bind(event.address) + const loanContractAddress = loanTokenContract.loanContract(event.params.tokenId) + + const loan = Loan.load(getLoanId(loanContractAddress, event.params.tokenId)) + + if (!loan) { + return + } + + loan.loanOwner = getOrCreateAccount(event.params.to).id + loan.save() +} + + +// export function handleLOANBurned(event: LOANBurnedEvent): void { +// const entity = new LOANBurned( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.loanId = event.params.loanId + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } + +// export function handleLOANMinted(event: LOANMintedEvent): void { +// const entity = new LOANMinted( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.loanId = event.params.loanId +// entity.loanContract = event.params.loanContract +// entity.owner = event.params.owner + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } + +// export function handleApproval(event: ApprovalEvent): void { +// const entity = new Approval( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.owner = event.params.owner +// entity.approved = event.params.approved +// entity.tokenId = event.params.tokenId + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } + +// export function handleApprovalForAll(event: ApprovalForAllEvent): void { +// const entity = new ApprovalForAll( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.owner = event.params.owner +// entity.operator = event.params.operator +// entity.approved = event.params.approved + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } diff --git a/packages/subgraph/src/multi-token-category-registry.ts b/packages/subgraph/src/multi-token-category-registry.ts new file mode 100644 index 0000000..3ddf713 --- /dev/null +++ b/packages/subgraph/src/multi-token-category-registry.ts @@ -0,0 +1,63 @@ +import { + CategoryRegistered as CategoryRegisteredEvent, + CategoryUnregistered as CategoryUnregisteredEvent, +} from "../generated/MultiTokenCategoryRegistry/MultiTokenCategoryRegistry" +import { + AssetContract, + AssetCategory, +} from "../generated/schema" +import { Bytes } from "@graphprotocol/graph-ts" + +export function handleCategoryRegistered(event: CategoryRegisteredEvent): void { + const categoryId = Bytes.fromI32(event.params.category) + let category = AssetCategory.load(categoryId) + if (category == null) { + category = new AssetCategory(categoryId) + category.save() + } + let assetContract = AssetContract.load(event.params.assetAddress) + if (assetContract == null) { + assetContract = new AssetContract(event.params.assetAddress) + } + + assetContract.category = category.id + assetContract.save() + + // TODO shall we save also the raw event? + // const entity = new CategoryRegistered( + // event.transaction.hash.concatI32(event.logIndex.toI32()), + // ) + // entity.assetAddress = event.params.assetAddress + // entity.category = event.params.category + + // entity.blockNumber = event.block.number + // entity.blockTimestamp = event.block.timestamp + // entity.transactionHash = event.transaction.hash + + // entity.save() +} + +export function handleCategoryUnregistered( + event: CategoryUnregisteredEvent, +): void { + // TODO this does not amek sense probably + const assetInCategory = AssetContract.load(event.params.assetAddress) + if (assetInCategory == null) { + // no need to do anything here + return + } + assetInCategory.category = null + assetInCategory.save() + + // TODO shall we save also the raw event? + // const entity = new CategoryUnregistered( + // event.transaction.hash.concatI32(event.logIndex.toI32()), + // ) + // entity.assetAddress = event.params.assetAddress + + // entity.blockNumber = event.block.number + // entity.blockTimestamp = event.block.timestamp + // entity.transactionHash = event.transaction.hash + + // entity.save() +} diff --git a/packages/subgraph/src/simple-loan-elastic-chainlink-proposal.ts b/packages/subgraph/src/simple-loan-elastic-chainlink-proposal.ts new file mode 100644 index 0000000..9a836df --- /dev/null +++ b/packages/subgraph/src/simple-loan-elastic-chainlink-proposal.ts @@ -0,0 +1,110 @@ +import { ProposalMade as ProposalMadeEvent } from "../generated/SimpleLoanElasticChainlinkProposal/SimpleLoanElasticChainlinkProposal" +import { SimpleLoanElasticChainlinkProposalProposalMade, Proposal } from "../generated/schema" +import { getOrCreateAsset } from "./utils" +import { Bytes, BigInt } from "@graphprotocol/graph-ts" +import { log } from "@graphprotocol/graph-ts" + +export function handleProposalMade(event: ProposalMadeEvent): void { + // Create the specific event entity + const eventEntity = new SimpleLoanElasticChainlinkProposalProposalMade( + event.transaction.hash.concatI32(event.logIndex.toI32()), + ) + eventEntity.proposalHash = event.params.proposalHash + eventEntity.proposer = event.params.proposer + eventEntity.collateralCategory = event.params.proposal.collateralCategory + eventEntity.collateralAddress = event.params.proposal.collateralAddress + eventEntity.collateralId = event.params.proposal.collateralId + eventEntity.checkCollateralStateFingerprint = + event.params.proposal.checkCollateralStateFingerprint + eventEntity.collateralStateFingerprint = + event.params.proposal.collateralStateFingerprint + eventEntity.creditAddress = event.params.proposal.creditAddress + eventEntity.feedIntermediaryDenominations = changetype( + event.params.proposal.feedIntermediaryDenominations, + ) + eventEntity.feedInvertFlags = event.params.proposal.feedInvertFlags + eventEntity.loanToValue = event.params.proposal.loanToValue + eventEntity.minCreditAmount = event.params.proposal.minCreditAmount + eventEntity.availableCreditLimit = + event.params.proposal.availableCreditLimit + eventEntity.utilizedCreditId = event.params.proposal.utilizedCreditId + eventEntity.fixedInterestAmount = + event.params.proposal.fixedInterestAmount + eventEntity.accruingInterestAPR = + event.params.proposal.accruingInterestAPR + eventEntity.durationOrDate = event.params.proposal.durationOrDate + eventEntity.expiration = event.params.proposal.expiration + eventEntity.allowedAcceptor = event.params.proposal.allowedAcceptor + eventEntity.proposer = event.params.proposal.proposer + eventEntity.proposerSpecHash = event.params.proposal.proposerSpecHash + eventEntity.isOffer = event.params.proposal.isOffer + eventEntity.refinancingLoanId = event.params.proposal.refinancingLoanId + eventEntity.nonceSpace = event.params.proposal.nonceSpace + eventEntity.nonce = event.params.proposal.nonce + eventEntity.loanContract = event.params.proposal.loanContract + + eventEntity.blockNumber = event.block.number + eventEntity.blockTimestamp = event.block.timestamp + eventEntity.transactionHash = event.transaction.hash + + // Create or get the unified Proposal entity + let proposal = Proposal.load(event.params.proposalHash) + if (proposal == null) { + proposal = new Proposal(event.params.proposalHash) + + // Set proposal type + proposal.proposalType = "ElasticChainlink" + + // Set common fields + proposal.proposer = event.params.proposer + proposal.createdAt = event.block.timestamp + + // Create Asset entities + const collateralAsset = getOrCreateAsset( + event.params.proposal.collateralAddress, + event.params.proposal.collateralId, + event.params.proposal.collateralCategory + ) + const creditAsset = getOrCreateAsset( + event.params.proposal.creditAddress, + BigInt.fromI32(0), // ERC20 tokens use 0 as token ID + 0 // ERC20 tokens are category 0 + ) + + proposal.credit = creditAsset.id + proposal.fixedInterestAmount = event.params.proposal.fixedInterestAmount + proposal.accruingInterestAPR = event.params.proposal.accruingInterestAPR + proposal.availableCreditLimit = event.params.proposal.availableCreditLimit + proposal.utilizedCreditId = event.params.proposal.utilizedCreditId + proposal.durationOrDate = event.params.proposal.durationOrDate + proposal.expiration = event.params.proposal.expiration + proposal.proposerSpecHash = event.params.proposal.proposerSpecHash + proposal.isOffer = event.params.proposal.isOffer + proposal.refinancingLoanId = event.params.proposal.refinancingLoanId + proposal.nonceSpace = event.params.proposal.nonceSpace + proposal.nonce = event.params.proposal.nonce + proposal.loanContract = event.params.proposal.loanContract + proposal.status = "Active" + proposal.blockNumber = event.block.number + proposal.transactionHash = event.transaction.hash + + // Set ElasticChainlink-specific fields + proposal.collateral = collateralAsset.id + proposal.checkCollateralStateFingerprint = event.params.proposal.checkCollateralStateFingerprint + proposal.collateralStateFingerprint = event.params.proposal.collateralStateFingerprint + proposal.allowedAcceptor = event.params.proposal.allowedAcceptor + proposal.minCreditAmount = event.params.proposal.minCreditAmount + proposal.feedIntermediaryDenominations = changetype(event.params.proposal.feedIntermediaryDenominations) + proposal.feedInvertFlags = event.params.proposal.feedInvertFlags + proposal.loanToValue = event.params.proposal.loanToValue + + // Link to raw event entity + proposal.rawEventElasticChainlink = eventEntity.id + + proposal.save() + } + + // Link the event entity to the unified proposal + eventEntity.proposal = proposal.id + eventEntity.save() +} diff --git a/packages/subgraph/src/simple-loan-elastic-proposal.ts b/packages/subgraph/src/simple-loan-elastic-proposal.ts new file mode 100644 index 0000000..f71b6fa --- /dev/null +++ b/packages/subgraph/src/simple-loan-elastic-proposal.ts @@ -0,0 +1,104 @@ +import { ProposalMade as ProposalMadeEvent } from "../generated/SimpleLoanElasticProposal/SimpleLoanElasticProposal" +import { SimpleLoanElasticProposalProposalMade, Proposal } from "../generated/schema" +import { getOrCreateAsset } from "./utils" +import { BigInt } from "@graphprotocol/graph-ts" + +export function handleProposalMade(event: ProposalMadeEvent): void { + // Create the specific event entity + const eventEntity = new SimpleLoanElasticProposalProposalMade( + event.transaction.hash.concatI32(event.logIndex.toI32()), + ) + eventEntity.proposalHash = event.params.proposalHash + eventEntity.proposer = event.params.proposer + eventEntity.collateralCategory = event.params.proposal.collateralCategory + eventEntity.collateralAddress = event.params.proposal.collateralAddress + eventEntity.collateralId = event.params.proposal.collateralId + eventEntity.checkCollateralStateFingerprint = + event.params.proposal.checkCollateralStateFingerprint + eventEntity.collateralStateFingerprint = + event.params.proposal.collateralStateFingerprint + eventEntity.creditAddress = event.params.proposal.creditAddress + eventEntity.creditPerCollateralUnit = + event.params.proposal.creditPerCollateralUnit + eventEntity.minCreditAmount = event.params.proposal.minCreditAmount + eventEntity.availableCreditLimit = + event.params.proposal.availableCreditLimit + eventEntity.utilizedCreditId = event.params.proposal.utilizedCreditId + eventEntity.fixedInterestAmount = + event.params.proposal.fixedInterestAmount + eventEntity.accruingInterestAPR = + event.params.proposal.accruingInterestAPR + eventEntity.durationOrDate = event.params.proposal.durationOrDate + eventEntity.expiration = event.params.proposal.expiration + eventEntity.allowedAcceptor = event.params.proposal.allowedAcceptor + eventEntity.proposer = event.params.proposal.proposer + eventEntity.proposerSpecHash = event.params.proposal.proposerSpecHash + eventEntity.isOffer = event.params.proposal.isOffer + eventEntity.refinancingLoanId = event.params.proposal.refinancingLoanId + eventEntity.nonceSpace = event.params.proposal.nonceSpace + eventEntity.nonce = event.params.proposal.nonce + eventEntity.loanContract = event.params.proposal.loanContract + + eventEntity.blockNumber = event.block.number + eventEntity.blockTimestamp = event.block.timestamp + eventEntity.transactionHash = event.transaction.hash + + // Create or get the unified Proposal entity + let proposal = Proposal.load(event.params.proposalHash) + if (proposal == null) { + proposal = new Proposal(event.params.proposalHash) + + // Set proposal type + proposal.proposalType = "Elastic" + + // Set common fields + proposal.proposer = event.params.proposer + proposal.createdAt = event.block.timestamp + + // Create Asset entities + const collateralAsset = getOrCreateAsset( + event.params.proposal.collateralAddress, + event.params.proposal.collateralId, + event.params.proposal.collateralCategory + ) + const creditAsset = getOrCreateAsset( + event.params.proposal.creditAddress, + BigInt.fromI32(0), // ERC20 tokens use 0 as token ID + 0 // ERC20 tokens are category 0 + ) + + proposal.credit = creditAsset.id + proposal.fixedInterestAmount = event.params.proposal.fixedInterestAmount + proposal.accruingInterestAPR = event.params.proposal.accruingInterestAPR + proposal.availableCreditLimit = event.params.proposal.availableCreditLimit + proposal.utilizedCreditId = event.params.proposal.utilizedCreditId + proposal.durationOrDate = event.params.proposal.durationOrDate + proposal.expiration = event.params.proposal.expiration + proposal.proposerSpecHash = event.params.proposal.proposerSpecHash + proposal.isOffer = event.params.proposal.isOffer + proposal.refinancingLoanId = event.params.proposal.refinancingLoanId + proposal.nonceSpace = event.params.proposal.nonceSpace + proposal.nonce = event.params.proposal.nonce + proposal.loanContract = event.params.proposal.loanContract + proposal.status = "Active" + proposal.blockNumber = event.block.number + proposal.transactionHash = event.transaction.hash + + // Set Elastic-specific fields + proposal.collateral = collateralAsset.id + proposal.checkCollateralStateFingerprint = event.params.proposal.checkCollateralStateFingerprint + proposal.collateralStateFingerprint = event.params.proposal.collateralStateFingerprint + proposal.allowedAcceptor = event.params.proposal.allowedAcceptor + proposal.creditPerCollateralUnit = event.params.proposal.creditPerCollateralUnit + proposal.minCreditAmount = event.params.proposal.minCreditAmount + + // Link to raw event entity + proposal.rawEventElastic = eventEntity.id + + proposal.save() + } + + // Link the event entity to the unified proposal + eventEntity.proposal = proposal.id + eventEntity.save() +} diff --git a/packages/subgraph/src/simple-loan-list-proposal.ts b/packages/subgraph/src/simple-loan-list-proposal.ts new file mode 100644 index 0000000..24da743 --- /dev/null +++ b/packages/subgraph/src/simple-loan-list-proposal.ts @@ -0,0 +1,104 @@ +import { ProposalMade as ProposalMadeEvent } from "../generated/SimpleLoanListProposal/SimpleLoanListProposal" +import { SimpleLoanListProposalProposalMade, Proposal } from "../generated/schema" +import { getOrCreateAsset } from "./utils" +import { BigInt } from "@graphprotocol/graph-ts" + +export function handleProposalMade(event: ProposalMadeEvent): void { + // Create the specific event entity + const eventEntity = new SimpleLoanListProposalProposalMade( + event.transaction.hash.concatI32(event.logIndex.toI32()), + ) + eventEntity.proposalHash = event.params.proposalHash + eventEntity.proposer = event.params.proposer + eventEntity.collateralCategory = event.params.proposal.collateralCategory + eventEntity.collateralAddress = event.params.proposal.collateralAddress + eventEntity.collateralIdsWhitelistMerkleRoot = + event.params.proposal.collateralIdsWhitelistMerkleRoot + eventEntity.collateralAmount = event.params.proposal.collateralAmount + eventEntity.checkCollateralStateFingerprint = + event.params.proposal.checkCollateralStateFingerprint + eventEntity.collateralStateFingerprint = + event.params.proposal.collateralStateFingerprint + eventEntity.creditAddress = event.params.proposal.creditAddress + eventEntity.creditAmount = event.params.proposal.creditAmount + eventEntity.availableCreditLimit = + event.params.proposal.availableCreditLimit + eventEntity.utilizedCreditId = event.params.proposal.utilizedCreditId + eventEntity.fixedInterestAmount = + event.params.proposal.fixedInterestAmount + eventEntity.accruingInterestAPR = + event.params.proposal.accruingInterestAPR + eventEntity.durationOrDate = event.params.proposal.durationOrDate + eventEntity.expiration = event.params.proposal.expiration + eventEntity.allowedAcceptor = event.params.proposal.allowedAcceptor + eventEntity.proposerSpecHash = event.params.proposal.proposerSpecHash + eventEntity.isOffer = event.params.proposal.isOffer + eventEntity.refinancingLoanId = event.params.proposal.refinancingLoanId + eventEntity.nonceSpace = event.params.proposal.nonceSpace + eventEntity.nonce = event.params.proposal.nonce + eventEntity.loanContract = event.params.proposal.loanContract + + eventEntity.blockNumber = event.block.number + eventEntity.blockTimestamp = event.block.timestamp + eventEntity.transactionHash = event.transaction.hash + + // Create or get the unified Proposal entity + let proposal = Proposal.load(event.params.proposalHash) + if (proposal == null) { + proposal = new Proposal(event.params.proposalHash) + + // Set proposal type + proposal.proposalType = "List" + + // Set common fields + proposal.proposer = event.params.proposer + proposal.createdAt = event.block.timestamp + + // Create Asset entities + const collateralAsset = getOrCreateAsset( + event.params.proposal.collateralAddress, + BigInt.fromI32(0), // List proposals don't have specific token ID, using 0 + event.params.proposal.collateralCategory + ) + const creditAsset = getOrCreateAsset( + event.params.proposal.creditAddress, + BigInt.fromI32(0), // ERC20 tokens use 0 as token ID + 0 // ERC20 tokens are category 0 + ) + + proposal.credit = creditAsset.id + proposal.fixedInterestAmount = event.params.proposal.fixedInterestAmount + proposal.accruingInterestAPR = event.params.proposal.accruingInterestAPR + proposal.availableCreditLimit = event.params.proposal.availableCreditLimit + proposal.utilizedCreditId = event.params.proposal.utilizedCreditId + proposal.durationOrDate = event.params.proposal.durationOrDate + proposal.expiration = event.params.proposal.expiration + proposal.proposerSpecHash = event.params.proposal.proposerSpecHash + proposal.isOffer = event.params.proposal.isOffer + proposal.refinancingLoanId = event.params.proposal.refinancingLoanId + proposal.nonceSpace = event.params.proposal.nonceSpace + proposal.nonce = event.params.proposal.nonce + proposal.loanContract = event.params.proposal.loanContract + proposal.status = "Active" + proposal.blockNumber = event.block.number + proposal.transactionHash = event.transaction.hash + + // Set List-specific fields + proposal.collateral = collateralAsset.id + proposal.collateralAmount = event.params.proposal.collateralAmount + proposal.creditAmount = event.params.proposal.creditAmount + proposal.allowedAcceptor = event.params.proposal.allowedAcceptor + proposal.checkCollateralStateFingerprint = event.params.proposal.checkCollateralStateFingerprint + proposal.collateralStateFingerprint = event.params.proposal.collateralStateFingerprint + proposal.collateralIdsWhitelistMerkleRoot = event.params.proposal.collateralIdsWhitelistMerkleRoot + + // Link to raw event entity + proposal.rawEventList = eventEntity.id + + proposal.save() + } + + // Link the event entity to the unified proposal + eventEntity.proposal = proposal.id + eventEntity.save() +} diff --git a/packages/subgraph/src/simple-loan-simple-proposal.ts b/packages/subgraph/src/simple-loan-simple-proposal.ts new file mode 100644 index 0000000..34a6f88 --- /dev/null +++ b/packages/subgraph/src/simple-loan-simple-proposal.ts @@ -0,0 +1,102 @@ +import { ProposalMade as ProposalMadeEvent } from "../generated/SimpleLoanSimpleProposal/SimpleLoanSimpleProposal" +import { SimpleLoanSimpleProposalMade, Proposal } from "../generated/schema" +import { getOrCreateAsset } from "./utils" +import { BigInt } from "@graphprotocol/graph-ts" + +export function handleProposalMade(event: ProposalMadeEvent): void { + // Create the specific event entity + const eventEntity = new SimpleLoanSimpleProposalMade( + event.transaction.hash.concatI32(event.logIndex.toI32()), + ) + eventEntity.proposalHash = event.params.proposalHash + eventEntity.proposer = event.params.proposer + eventEntity.collateralCategory = event.params.proposal.collateralCategory + eventEntity.collateralAddress = event.params.proposal.collateralAddress + eventEntity.collateralId = event.params.proposal.collateralId + eventEntity.collateralAmount = event.params.proposal.collateralAmount + eventEntity.checkCollateralStateFingerprint = + event.params.proposal.checkCollateralStateFingerprint + eventEntity.collateralStateFingerprint = + event.params.proposal.collateralStateFingerprint + eventEntity.creditAddress = event.params.proposal.creditAddress + eventEntity.creditAmount = event.params.proposal.creditAmount + eventEntity.availableCreditLimit = + event.params.proposal.availableCreditLimit + eventEntity.utilizedCreditId = event.params.proposal.utilizedCreditId + eventEntity.fixedInterestAmount = + event.params.proposal.fixedInterestAmount + eventEntity.accruingInterestAPR = + event.params.proposal.accruingInterestAPR + eventEntity.durationOrDate = event.params.proposal.durationOrDate + eventEntity.expiration = event.params.proposal.expiration + eventEntity.allowedAcceptor = event.params.proposal.allowedAcceptor + eventEntity.proposerSpecHash = event.params.proposal.proposerSpecHash + eventEntity.isOffer = event.params.proposal.isOffer + eventEntity.refinancingLoanId = event.params.proposal.refinancingLoanId + eventEntity.nonceSpace = event.params.proposal.nonceSpace + eventEntity.nonce = event.params.proposal.nonce + eventEntity.loanContract = event.params.proposal.loanContract + + eventEntity.blockNumber = event.block.number + eventEntity.blockTimestamp = event.block.timestamp + eventEntity.transactionHash = event.transaction.hash + + // Create or get the unified Proposal entity + let proposal = Proposal.load(event.params.proposalHash) + if (proposal == null) { + proposal = new Proposal(event.params.proposalHash) + + // Set proposal type + proposal.proposalType = "Simple" + + // Set common fields + proposal.proposer = event.params.proposer + proposal.createdAt = event.block.timestamp + + // Create Asset entities + const collateralAsset = getOrCreateAsset( + event.params.proposal.collateralAddress, + event.params.proposal.collateralId, + event.params.proposal.collateralCategory + ) + const creditAsset = getOrCreateAsset( + event.params.proposal.creditAddress, + BigInt.fromI32(0), // ERC20 tokens use 0 as token ID + 0 // ERC20 tokens are category 0 + ) + + proposal.credit = creditAsset.id + proposal.fixedInterestAmount = event.params.proposal.fixedInterestAmount + proposal.accruingInterestAPR = event.params.proposal.accruingInterestAPR + proposal.availableCreditLimit = event.params.proposal.availableCreditLimit + proposal.utilizedCreditId = event.params.proposal.utilizedCreditId + proposal.durationOrDate = event.params.proposal.durationOrDate + proposal.expiration = event.params.proposal.expiration + proposal.proposerSpecHash = event.params.proposal.proposerSpecHash + proposal.isOffer = event.params.proposal.isOffer + proposal.refinancingLoanId = event.params.proposal.refinancingLoanId + proposal.nonceSpace = event.params.proposal.nonceSpace + proposal.nonce = event.params.proposal.nonce + proposal.loanContract = event.params.proposal.loanContract + proposal.status = "Active" + proposal.blockNumber = event.block.number + proposal.transactionHash = event.transaction.hash + + // Set Simple-specific fields + proposal.collateral = collateralAsset.id + proposal.collateralAmount = event.params.proposal.collateralAmount + proposal.creditAmount = event.params.proposal.creditAmount + proposal.allowedAcceptor = event.params.proposal.allowedAcceptor + proposal.checkCollateralStateFingerprint = event.params.proposal.checkCollateralStateFingerprint + proposal.collateralStateFingerprint = event.params.proposal.collateralStateFingerprint + + // Link to raw event entity + proposal.rawEventSimple = eventEntity.id + + proposal.save() + } + + // Link the event entity to the unified proposal + eventEntity.proposal = proposal.id + eventEntity.save() +} diff --git a/packages/subgraph/src/simple-loan-uniswap-v-3-lp-individual-proposal.ts b/packages/subgraph/src/simple-loan-uniswap-v-3-lp-individual-proposal.ts new file mode 100644 index 0000000..ad51e03 --- /dev/null +++ b/packages/subgraph/src/simple-loan-uniswap-v-3-lp-individual-proposal.ts @@ -0,0 +1,108 @@ +import { ProposalMade as ProposalMadeEvent } from "../generated/SimpleLoanUniswapV3LPIndividualProposal/SimpleLoanUniswapV3LPIndividualProposal" +import { SimpleLoanUniswapV3LPIndividualProposalProposalMade, Proposal } from "../generated/schema" +import { getOrCreateAsset } from "./utils" +import { Bytes, BigInt } from "@graphprotocol/graph-ts" + +export function handleProposalMade(event: ProposalMadeEvent): void { + // Create the specific event entity + const eventEntity = new SimpleLoanUniswapV3LPIndividualProposalProposalMade( + event.transaction.hash.concatI32(event.logIndex.toI32()), + ) + eventEntity.proposalHash = event.params.proposalHash + eventEntity.proposer = event.params.proposer + eventEntity.collateralId = event.params.proposal.collateralId + eventEntity.token0Denominator = event.params.proposal.token0Denominator + eventEntity.creditAddress = event.params.proposal.creditAddress + eventEntity.feedIntermediaryDenominations = changetype( + event.params.proposal.feedIntermediaryDenominations, + ) + eventEntity.feedInvertFlags = event.params.proposal.feedInvertFlags + eventEntity.loanToValue = event.params.proposal.loanToValue + eventEntity.minCreditAmount = event.params.proposal.minCreditAmount + eventEntity.availableCreditLimit = + event.params.proposal.availableCreditLimit + eventEntity.utilizedCreditId = event.params.proposal.utilizedCreditId + eventEntity.fixedInterestAmount = + event.params.proposal.fixedInterestAmount + eventEntity.accruingInterestAPR = + event.params.proposal.accruingInterestAPR + eventEntity.durationOrDate = event.params.proposal.durationOrDate + eventEntity.expiration = event.params.proposal.expiration + eventEntity.acceptorController = event.params.proposal.acceptorController + eventEntity.acceptorControllerData = + event.params.proposal.acceptorControllerData + eventEntity.proposer = event.params.proposal.proposer + eventEntity.proposerSpecHash = event.params.proposal.proposerSpecHash + eventEntity.isOffer = event.params.proposal.isOffer + eventEntity.refinancingLoanId = event.params.proposal.refinancingLoanId + eventEntity.nonceSpace = event.params.proposal.nonceSpace + eventEntity.nonce = event.params.proposal.nonce + eventEntity.loanContract = event.params.proposal.loanContract + + eventEntity.blockNumber = event.block.number + eventEntity.blockTimestamp = event.block.timestamp + eventEntity.transactionHash = event.transaction.hash + + // Create or get the unified Proposal entity + let proposal = Proposal.load(event.params.proposalHash) + if (proposal == null) { + proposal = new Proposal(event.params.proposalHash) + + // Set proposal type + proposal.proposalType = "UniswapV3LPIndividual" + + // Set common fields + proposal.proposer = event.params.proposer + proposal.createdAt = event.block.timestamp + + // Create Asset entities + const collateralAsset = getOrCreateAsset( + // TODO will this differ on chains? this one is uniswap v3 positions manager nft contract for sepolia + Bytes.fromHexString("0x1238536071E1c677A632429e3655c799b22cDA52"), + event.params.proposal.collateralId, + 1 // ERC721 + ) + const creditAsset = getOrCreateAsset( + event.params.proposal.creditAddress, + BigInt.fromI32(0), // ERC20 tokens use 0 as token ID + 0 // ERC20 tokens are category 0 + ) + + proposal.credit = creditAsset.id + proposal.fixedInterestAmount = event.params.proposal.fixedInterestAmount + proposal.accruingInterestAPR = event.params.proposal.accruingInterestAPR + proposal.availableCreditLimit = event.params.proposal.availableCreditLimit + proposal.utilizedCreditId = event.params.proposal.utilizedCreditId + proposal.durationOrDate = event.params.proposal.durationOrDate + proposal.expiration = event.params.proposal.expiration + proposal.proposerSpecHash = event.params.proposal.proposerSpecHash + proposal.isOffer = event.params.proposal.isOffer + proposal.refinancingLoanId = event.params.proposal.refinancingLoanId + proposal.nonceSpace = event.params.proposal.nonceSpace + proposal.nonce = event.params.proposal.nonce + proposal.loanContract = event.params.proposal.loanContract + proposal.status = "Active" + proposal.blockNumber = event.block.number + proposal.transactionHash = event.transaction.hash + + // Set UniswapV3LPIndividual-specific fields + proposal.collateral = collateralAsset.id + proposal.collateralId = event.params.proposal.collateralId + proposal.token0Denominator = event.params.proposal.token0Denominator + proposal.feedIntermediaryDenominations = changetype(event.params.proposal.feedIntermediaryDenominations) + proposal.feedInvertFlags = event.params.proposal.feedInvertFlags + proposal.loanToValue = event.params.proposal.loanToValue + proposal.minCreditAmount = event.params.proposal.minCreditAmount + proposal.acceptorController = event.params.proposal.acceptorController + proposal.acceptorControllerData = event.params.proposal.acceptorControllerData + + // Link to raw event entity + proposal.rawEventUniswapV3LPIndividual = eventEntity.id + + proposal.save() + } + + // Link the event entity to the unified proposal + eventEntity.proposal = proposal.id + eventEntity.save() +} diff --git a/packages/subgraph/src/simple-loan-uniswap-v-3-lp-set-proposal.ts b/packages/subgraph/src/simple-loan-uniswap-v-3-lp-set-proposal.ts new file mode 100644 index 0000000..c19525b --- /dev/null +++ b/packages/subgraph/src/simple-loan-uniswap-v-3-lp-set-proposal.ts @@ -0,0 +1,105 @@ +import { ProposalMade as ProposalMadeEvent } from "../generated/SimpleLoanUniswapV3LPSetProposal/SimpleLoanUniswapV3LPSetProposal" +import { SimpleLoanUniswapV3LPSetProposalProposalMade, Proposal } from "../generated/schema" +import { getOrCreateAsset } from "./utils" +import { Bytes } from "@graphprotocol/graph-ts" +import { BigInt } from "@graphprotocol/graph-ts" + +export function handleProposalMade(event: ProposalMadeEvent): void { + // Create the specific event entity + const eventEntity = new SimpleLoanUniswapV3LPSetProposalProposalMade( + event.transaction.hash.concatI32(event.logIndex.toI32()), + ) + eventEntity.proposalHash = event.params.proposalHash + eventEntity.proposer = event.params.proposer + eventEntity.tokenAAllowlist = changetype( + event.params.proposal.tokenAAllowlist, + ) + eventEntity.tokenBAllowlist = changetype( + event.params.proposal.tokenBAllowlist, + ) + eventEntity.creditAddress = event.params.proposal.creditAddress + eventEntity.feedIntermediaryDenominations = changetype( + event.params.proposal.feedIntermediaryDenominations, + ) + eventEntity.feedInvertFlags = event.params.proposal.feedInvertFlags + eventEntity.loanToValue = event.params.proposal.loanToValue + eventEntity.minCreditAmount = event.params.proposal.minCreditAmount + eventEntity.availableCreditLimit = + event.params.proposal.availableCreditLimit + eventEntity.utilizedCreditId = event.params.proposal.utilizedCreditId + eventEntity.fixedInterestAmount = + event.params.proposal.fixedInterestAmount + eventEntity.accruingInterestAPR = + event.params.proposal.accruingInterestAPR + eventEntity.durationOrDate = event.params.proposal.durationOrDate + eventEntity.expiration = event.params.proposal.expiration + eventEntity.acceptorController = event.params.proposal.acceptorController + eventEntity.acceptorControllerData = + event.params.proposal.acceptorControllerData + eventEntity.proposer = event.params.proposal.proposer + eventEntity.proposerSpecHash = event.params.proposal.proposerSpecHash + eventEntity.isOffer = event.params.proposal.isOffer + eventEntity.refinancingLoanId = event.params.proposal.refinancingLoanId + eventEntity.nonceSpace = event.params.proposal.nonceSpace + eventEntity.nonce = event.params.proposal.nonce + eventEntity.loanContract = event.params.proposal.loanContract + + eventEntity.blockNumber = event.block.number + eventEntity.blockTimestamp = event.block.timestamp + eventEntity.transactionHash = event.transaction.hash + + // Create or get the unified Proposal entity + let proposal = Proposal.load(event.params.proposalHash) + if (proposal == null) { + proposal = new Proposal(event.params.proposalHash) + + // Set proposal type + proposal.proposalType = "UniswapV3LPSet" + + // Set common fields + proposal.proposer = event.params.proposer + proposal.createdAt = event.block.timestamp + + const creditAsset = getOrCreateAsset( + event.params.proposal.creditAddress, + BigInt.fromI32(0), // ERC20 tokens use 0 as token ID + 0 // ERC20 tokens are category 0 + ) + + proposal.credit = creditAsset.id + proposal.fixedInterestAmount = event.params.proposal.fixedInterestAmount + proposal.accruingInterestAPR = event.params.proposal.accruingInterestAPR + proposal.availableCreditLimit = event.params.proposal.availableCreditLimit + proposal.utilizedCreditId = event.params.proposal.utilizedCreditId + proposal.durationOrDate = event.params.proposal.durationOrDate + proposal.expiration = event.params.proposal.expiration + proposal.proposerSpecHash = event.params.proposal.proposerSpecHash + proposal.isOffer = event.params.proposal.isOffer + proposal.refinancingLoanId = event.params.proposal.refinancingLoanId + proposal.nonceSpace = event.params.proposal.nonceSpace + proposal.nonce = event.params.proposal.nonce + proposal.loanContract = event.params.proposal.loanContract + proposal.status = "Active" + proposal.blockNumber = event.block.number + proposal.transactionHash = event.transaction.hash + + // Set UniswapV3LPSet-specific fields + proposal.tokenAAllowlist = changetype(event.params.proposal.tokenAAllowlist) + proposal.tokenBAllowlist = changetype(event.params.proposal.tokenBAllowlist) + proposal.feedIntermediaryDenominations = changetype(event.params.proposal.feedIntermediaryDenominations) + proposal.feedInvertFlags = event.params.proposal.feedInvertFlags + proposal.loanToValue = event.params.proposal.loanToValue + proposal.minCreditAmount = event.params.proposal.minCreditAmount + proposal.acceptorController = event.params.proposal.acceptorController + proposal.acceptorControllerData = event.params.proposal.acceptorControllerData + + // Link to raw event entity + proposal.rawEventUniswapV3LPSet = eventEntity.id + + proposal.save() + } + + // Link the event entity to the unified proposal + eventEntity.proposal = proposal.id + eventEntity.save() +} diff --git a/packages/subgraph/src/simple-loan.ts b/packages/subgraph/src/simple-loan.ts new file mode 100644 index 0000000..bb15155 --- /dev/null +++ b/packages/subgraph/src/simple-loan.ts @@ -0,0 +1,348 @@ +import { Address, BigInt, Bytes } from "@graphprotocol/graph-ts" +import { + ExtensionProposalMade as ExtensionProposalMadeEvent, + LOANClaimed as LOANClaimedEvent, + LOANCreated as LOANCreatedEvent, + LOANExtended as LOANExtendedEvent, + LOANPaidBack as LOANPaidBackEvent, + SimpleLoan, +} from "../generated/SimpleLoan/SimpleLoan" +import { + ExtensionProposal, + LoanExtendedEvent as LoanExtendedEventEntity, + Loan, +} from "../generated/schema" +import { getOrCreateAccount } from "./helpers" +import { getOrCreateAsset } from "./utils" +import { log } from "matchstick-as/assembly/log" + +export function getLoanId(loanContractAddress: Address, loanId: BigInt): Bytes { + return loanContractAddress.concat(Bytes.fromByteArray(Bytes.fromBigInt(loanId))) +} + +export function handleLOANCreated(event: LOANCreatedEvent): void { + const loanId = getLoanId(event.address, event.params.loanId) + const loan = new Loan(loanId) + loan.loanId = event.params.loanId + loan.contractAddress = event.address + loan.proposalHash = event.params.proposalHash + loan.proposalContract = event.params.proposalContract + loan.refinancingLoanId = event.params.refinancingLoanId + loan.originalLender = getOrCreateAccount(event.params.terms.lender).id + loan.loanOwner = getOrCreateAccount(event.params.terms.lender).id + loan.borrower = getOrCreateAccount(event.params.terms.borrower).id + loan.duration = event.params.terms.duration + loan.loanType = "SimpleLoan" + loan.createdAt = event.block.timestamp + loan.collateral = getOrCreateAsset(event.params.terms.collateral.assetAddress, event.params.terms.collateral.id, event.params.terms.collateral.category).id + loan.collateralAmount = event.params.terms.collateral.amount + loan.credit = getOrCreateAsset(event.params.terms.credit.assetAddress, event.params.terms.credit.id, event.params.terms.credit.category).id + loan.creditAmount = event.params.terms.credit.amount + loan.status = "Active" + loan.fixedInterestAmount = event.params.terms.fixedInterestAmount + loan.accruingInterestAPR = event.params.terms.accruingInterestAPR + loan.lenderSpecHash = event.params.terms.lenderSpecHash + loan.borrowerSpecHash = event.params.terms.borrowerSpecHash + loan.sourceOfFunds = event.params.lenderSpec.sourceOfFunds + loan.defaultDate = event.params.terms.duration.plus(loan.createdAt) + loan.extra = event.params.extra + const simpleLoanContract = SimpleLoan.bind(Address.fromBytes(loan.contractAddress)) + loan.loanTokenAddress = simpleLoanContract.loanToken() + loan.hasDefaulted = false + loan.save() +} + +export function handleLOANPaidBack(event: LOANPaidBackEvent): void { + const loanId = getLoanId(event.address, event.params.loanId) + const loan = Loan.load(loanId) + if (!loan) { + // TODO what to do in this case? + return + } + + loan.status = "Repaid" + loan.repaidAt = event.block.timestamp + loan.save() + + // TODO: Update the linked Proposal entity status +} + +export function handleLOANClaimed(event: LOANClaimedEvent): void { + const loanId = getLoanId(event.address, event.params.loanId) + const loan = Loan.load(loanId) + if (!loan) { + // TODO what to do in this case? + return + } + + loan.status = "Claimed" + loan.claimedAt = event.block.timestamp + loan.hasDefaulted = event.params.defaulted + loan.save() + + // TODO: Update the linked Proposal entity status +} + +export function handleLOANExtended(event: LOANExtendedEvent): void { + const loanId = getLoanId(event.address, event.params.loanId) + const loan = Loan.load(loanId) + if (!loan) { + // TODO what to do in this case? + return + } + + const extensionDuration = event.params.extendedDefaultTimestamp.minus(loan.defaultDate); + loan.duration = loan.duration.plus(extensionDuration); + + loan.defaultDate = event.params.extendedDefaultTimestamp + loan.save() + + // save the event as well + const entity = new LoanExtendedEventEntity( + event.transaction.hash.concatI32(event.logIndex.toI32()), + ) + entity.loanId = event.params.loanId + entity.originalDefaultTimestamp = event.params.originalDefaultTimestamp + entity.extendedDefaultTimestamp = event.params.extendedDefaultTimestamp + + entity.blockNumber = event.block.number + entity.blockTimestamp = event.block.timestamp + entity.transactionHash = event.transaction.hash + + entity.save() +} + +export function handleExtensionProposalMade( + event: ExtensionProposalMadeEvent, +): void { + const extensionProposal = new ExtensionProposal(event.params.extensionHash) + extensionProposal.proposer = event.params.proposer + const loanId = getLoanId(event.address, event.params.proposal.loanId) + const loan = Loan.load(loanId) + if (!loan) { + // TODO what to do in this case? + return + } + extensionProposal.loan = loan.id + extensionProposal.compensationAssetAddress = event.params.proposal.compensationAddress + extensionProposal.compensationAmount = event.params.proposal.compensationAmount + extensionProposal.durationToExtend = event.params.proposal.duration + extensionProposal.proposalExpiration = event.params.proposal.expiration + extensionProposal.nonceSpace = event.params.proposal.nonceSpace + extensionProposal.nonce = event.params.proposal.nonce + extensionProposal.createdAt = event.block.timestamp + extensionProposal.save() + + // const entity = new ExtensionProposalMade( + // event.transaction.hash.concatI32(event.logIndex.toI32()), + // ) + // entity.extensionHash = event.params.extensionHash + // entity.proposer = event.params.proposer + // entity.proposal_loanId = event.params.proposal.loanId + // entity.proposal_compensationAddress = + // event.params.proposal.compensationAddress + // entity.proposal_compensationAmount = event.params.proposal.compensationAmount + // entity.proposal_duration = event.params.proposal.duration + // entity.proposal_expiration = event.params.proposal.expiration + // entity.proposal_proposer = event.params.proposal.proposer + // entity.proposal_nonceSpace = event.params.proposal.nonceSpace + // entity.proposal_nonce = event.params.proposal.nonce + + // entity.blockNumber = event.block.number + // entity.blockTimestamp = event.block.timestamp + // entity.transactionHash = event.transaction.hash + + // entity.save() +} + +// ====== UNUSED CODE + +// export function handleLOANClaimed(event: LOANClaimedEvent): void { +// const entity = new LOANClaimed( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.loanId = event.params.loanId +// entity.defaulted = event.params.defaulted + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } + +// export function handleLOANExtended(event: LOANExtendedEvent): void { +// const entity = new LOANExtended( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.loanId = event.params.loanId +// entity.originalDefaultTimestamp = event.params.originalDefaultTimestamp +// entity.extendedDefaultTimestamp = event.params.extendedDefaultTimestamp + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } + +// export function handleExtensionProposalMade( +// event: ExtensionProposalMadeEvent, +// ): void { +// const entity = new ExtensionProposalMade( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.extensionHash = event.params.extensionHash +// entity.proposer = event.params.proposer +// entity.proposal_loanId = event.params.proposal.loanId +// entity.proposal_compensationAddress = +// event.params.proposal.compensationAddress +// entity.proposal_compensationAmount = event.params.proposal.compensationAmount +// entity.proposal_duration = event.params.proposal.duration +// entity.proposal_expiration = event.params.proposal.expiration +// entity.proposal_proposer = event.params.proposal.proposer +// entity.proposal_nonceSpace = event.params.proposal.nonceSpace +// entity.proposal_nonce = event.params.proposal.nonce + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } + +// export function handlePoolSupply(event: PoolSupplyEvent): void { +// const entity = new PoolSupply( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.asset_category = event.params.asset.category +// entity.asset_assetAddress = event.params.asset.assetAddress +// entity.asset_id = event.params.asset.id +// entity.asset_amount = event.params.asset.amount +// entity.poolAdapter = event.params.poolAdapter +// entity.pool = event.params.pool +// entity.owner = event.params.owner + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } + +// export function handlePoolWithdraw(event: PoolWithdrawEvent): void { +// const entity = new PoolWithdraw( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.asset_category = event.params.asset.category +// entity.asset_assetAddress = event.params.asset.assetAddress +// entity.asset_id = event.params.asset.id +// entity.asset_amount = event.params.asset.amount +// entity.poolAdapter = event.params.poolAdapter +// entity.pool = event.params.pool +// entity.owner = event.params.owner + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } + +// export function handleVaultPull(event: VaultPullEvent): void { +// const entity = new VaultPull( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.asset_category = event.params.asset.category +// entity.asset_assetAddress = event.params.asset.assetAddress +// entity.asset_id = event.params.asset.id +// entity.asset_amount = event.params.asset.amount +// entity.origin = event.params.origin + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } + +// export function handleVaultPush(event: VaultPushEvent): void { +// const entity = new VaultPush( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.asset_category = event.params.asset.category +// entity.asset_assetAddress = event.params.asset.assetAddress +// entity.asset_id = event.params.asset.id +// entity.asset_amount = event.params.asset.amount +// entity.beneficiary = event.params.beneficiary + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } + +// export function handleVaultPushFrom(event: VaultPushFromEvent): void { +// const entity = new VaultPushFrom( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.asset_category = event.params.asset.category +// entity.asset_assetAddress = event.params.asset.assetAddress +// entity.asset_id = event.params.asset.id +// entity.asset_amount = event.params.asset.amount +// entity.origin = event.params.origin +// entity.beneficiary = event.params.beneficiary + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } + +// handleLoanClaimed: +// const entity = new LOANCreated( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.loanId = event.params.loanId +// entity.proposalHash = event.params.proposalHash +// entity.proposalContract = event.params.proposalContract +// entity.refinancingLoanId = event.params.refinancingLoanId +// entity.terms_lender = event.params.terms.lender +// entity.terms_borrower = event.params.terms.borrower +// entity.terms_duration = event.params.terms.duration +// entity.terms_collateral_category = event.params.terms.collateral.category +// entity.terms_collateral_assetAddress = +// event.params.terms.collateral.assetAddress +// entity.terms_collateral_id = event.params.terms.collateral.id +// entity.terms_collateral_amount = event.params.terms.collateral.amount +// entity.terms_credit_category = event.params.terms.credit.category +// entity.terms_credit_assetAddress = event.params.terms.credit.assetAddress +// entity.terms_credit_id = event.params.terms.credit.id +// entity.terms_credit_amount = event.params.terms.credit.amount +// entity.terms_fixedInterestAmount = event.params.terms.fixedInterestAmount +// entity.terms_accruingInterestAPR = event.params.terms.accruingInterestAPR +// entity.terms_lenderSpecHash = event.params.terms.lenderSpecHash +// entity.terms_borrowerSpecHash = event.params.terms.borrowerSpecHash +// entity.lenderSpec_sourceOfFunds = event.params.lenderSpec.sourceOfFunds +// entity.extra = event.params.extra + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() + +// export function handleLOANPaidBack(event: LOANPaidBackEvent): void { +// const entity = new LOANPaidBack( +// event.transaction.hash.concatI32(event.logIndex.toI32()), +// ) +// entity.loanId = event.params.loanId + +// entity.blockNumber = event.block.number +// entity.blockTimestamp = event.block.timestamp +// entity.transactionHash = event.transaction.hash + +// entity.save() +// } \ No newline at end of file diff --git a/packages/subgraph/src/utils.ts b/packages/subgraph/src/utils.ts new file mode 100644 index 0000000..8deebe5 --- /dev/null +++ b/packages/subgraph/src/utils.ts @@ -0,0 +1,86 @@ +import { Asset, AssetContract, AssetCategory, Account } from "../generated/schema" +import { Bytes, BigInt, Address } from "@graphprotocol/graph-ts" + +// Helper function to create or get Asset entity +export function getOrCreateAsset(contractAddress: Bytes, tokenId: BigInt, category: i32): Asset { + const assetId = contractAddress.concat(Bytes.fromByteArray(Bytes.fromBigInt(tokenId))) + let asset = Asset.load(assetId) + + if (asset == null) { + let assetContract = AssetContract.load(contractAddress) + if (assetContract == null) { + // Create or get the category + let categoryEntity = AssetCategory.load(Bytes.fromI32(category)) + if (categoryEntity == null) { + categoryEntity = new AssetCategory(Bytes.fromI32(category)) + categoryEntity.save() + } + + assetContract = new AssetContract(contractAddress) + assetContract.category = categoryEntity.id + assetContract.save() + } + + asset = new Asset(assetId) + asset.contract = assetContract.id + asset.tokenId = tokenId + asset.save() + } + + return asset +} + +// Helper function to create or get Account entity +export function getOrCreateAccount(address: Bytes): Account { + let account = Account.load(address) + if (account == null) { + account = new Account(address) + account.save() + } + return account +} + +// Helper function to extract proposal parameters for function calls +// This removes the "proposal_" prefix from field names +export function extractProposalParams(proposalEvent: any): Map { + const params = new Map() + + // Common parameters (available in all proposal types) + if (proposalEvent.proposal_collateralCategory !== undefined) params.set("collateralCategory", proposalEvent.proposal_collateralCategory) + if (proposalEvent.proposal_collateralAddress !== undefined) params.set("collateralAddress", proposalEvent.proposal_collateralAddress) + if (proposalEvent.proposal_collateralId !== undefined) params.set("collateralId", proposalEvent.proposal_collateralId) + if (proposalEvent.proposal_collateralAmount !== undefined) params.set("collateralAmount", proposalEvent.proposal_collateralAmount) + if (proposalEvent.proposal_checkCollateralStateFingerprint !== undefined) params.set("checkCollateralStateFingerprint", proposalEvent.proposal_checkCollateralStateFingerprint) + if (proposalEvent.proposal_collateralStateFingerprint !== undefined) params.set("collateralStateFingerprint", proposalEvent.proposal_collateralStateFingerprint) + if (proposalEvent.proposal_creditAddress !== undefined) params.set("creditAddress", proposalEvent.proposal_creditAddress) + if (proposalEvent.proposal_creditAmount !== undefined) params.set("creditAmount", proposalEvent.proposal_creditAmount) + if (proposalEvent.proposal_availableCreditLimit !== undefined) params.set("availableCreditLimit", proposalEvent.proposal_availableCreditLimit) + if (proposalEvent.proposal_utilizedCreditId !== undefined) params.set("utilizedCreditId", proposalEvent.proposal_utilizedCreditId) + if (proposalEvent.proposal_fixedInterestAmount !== undefined) params.set("fixedInterestAmount", proposalEvent.proposal_fixedInterestAmount) + if (proposalEvent.proposal_accruingInterestAPR !== undefined) params.set("accruingInterestAPR", proposalEvent.proposal_accruingInterestAPR) + if (proposalEvent.proposal_durationOrDate !== undefined) params.set("durationOrDate", proposalEvent.proposal_durationOrDate) + if (proposalEvent.proposal_expiration !== undefined) params.set("expiration", proposalEvent.proposal_expiration) + if (proposalEvent.proposal_allowedAcceptor !== undefined) params.set("allowedAcceptor", proposalEvent.proposal_allowedAcceptor) + if (proposalEvent.proposal_proposer !== undefined) params.set("proposer", proposalEvent.proposal_proposer) + if (proposalEvent.proposal_proposerSpecHash !== undefined) params.set("proposerSpecHash", proposalEvent.proposal_proposerSpecHash) + if (proposalEvent.proposal_isOffer !== undefined) params.set("isOffer", proposalEvent.proposal_isOffer) + if (proposalEvent.proposal_refinancingLoanId !== undefined) params.set("refinancingLoanId", proposalEvent.proposal_refinancingLoanId) + if (proposalEvent.proposal_nonceSpace !== undefined) params.set("nonceSpace", proposalEvent.proposal_nonceSpace) + if (proposalEvent.proposal_nonce !== undefined) params.set("nonce", proposalEvent.proposal_nonce) + if (proposalEvent.proposal_loanContract !== undefined) params.set("loanContract", proposalEvent.proposal_loanContract) + + // Type-specific parameters + if (proposalEvent.proposal_collateralIdsWhitelistMerkleRoot !== undefined) params.set("collateralIdsWhitelistMerkleRoot", proposalEvent.proposal_collateralIdsWhitelistMerkleRoot) + if (proposalEvent.proposal_creditPerCollateralUnit !== undefined) params.set("creditPerCollateralUnit", proposalEvent.proposal_creditPerCollateralUnit) + if (proposalEvent.proposal_minCreditAmount !== undefined) params.set("minCreditAmount", proposalEvent.proposal_minCreditAmount) + if (proposalEvent.proposal_feedIntermediaryDenominations !== undefined) params.set("feedIntermediaryDenominations", proposalEvent.proposal_feedIntermediaryDenominations) + if (proposalEvent.proposal_feedInvertFlags !== undefined) params.set("feedInvertFlags", proposalEvent.proposal_feedInvertFlags) + if (proposalEvent.proposal_loanToValue !== undefined) params.set("loanToValue", proposalEvent.proposal_loanToValue) + if (proposalEvent.proposal_token0Denominator !== undefined) params.set("token0Denominator", proposalEvent.proposal_token0Denominator) + if (proposalEvent.proposal_acceptorController !== undefined) params.set("acceptorController", proposalEvent.proposal_acceptorController) + if (proposalEvent.proposal_acceptorControllerData !== undefined) params.set("acceptorControllerData", proposalEvent.proposal_acceptorControllerData) + if (proposalEvent.proposal_tokenAAllowlist !== undefined) params.set("tokenAAllowlist", proposalEvent.proposal_tokenAAllowlist) + if (proposalEvent.proposal_tokenBAllowlist !== undefined) params.set("tokenBAllowlist", proposalEvent.proposal_tokenBAllowlist) + + return params +} \ No newline at end of file diff --git a/packages/subgraph/subgraph.template.yaml b/packages/subgraph/subgraph.template.yaml new file mode 100644 index 0000000..514711c --- /dev/null +++ b/packages/subgraph/subgraph.template.yaml @@ -0,0 +1,362 @@ +specVersion: 1.2.0 +schema: + file: ./schema.graphql +dataSources: + # TODO should we also include: + # - RevokedNonce ? + # - Config? + # - Hub? + # - SimpleLoanDutchAuction? + + # TODO go over the events here and see what we can remove + - kind: ethereum + name: SimpleLoanSimpleProposal + network: {{network}} + source: + address: "{{SimpleLoanSimpleProposal.address}}" + abi: SimpleLoanSimpleProposal + startBlock: {{SimpleLoanSimpleProposal.startBlock}} + mapping: + kind: ethereum/events + apiVersion: 0.0.9 + language: wasm/assemblyscript + entities: + - ProposalMade + abis: + - name: SimpleLoanSimpleProposal + file: ./abis/SimpleLoanSimpleProposal.json + eventHandlers: + - event: ProposalMade(indexed bytes32,indexed + address,(uint8,address,uint256,uint256,bool,bytes32,address,uint256,uint256,bytes32,uint256,uint24,uint32,uint40,address,address,bytes32,bool,uint256,uint256,uint256,address)) + handler: handleProposalMade + file: ./src/simple-loan-simple-proposal.ts + - kind: ethereum + name: SimpleLoanListProposal + network: {{network}} + source: + address: "{{SimpleLoanListProposal.address}}" + abi: SimpleLoanListProposal + startBlock: {{SimpleLoanListProposal.startBlock}} + mapping: + kind: ethereum/events + apiVersion: 0.0.9 + language: wasm/assemblyscript + entities: + - SimpleLoanListProposalProposalMade + abis: + - name: SimpleLoanListProposal + file: ./abis/SimpleLoanListProposal.json + eventHandlers: + - event: ProposalMade(indexed bytes32,indexed + address,(uint8,address,bytes32,uint256,bool,bytes32,address,uint256,uint256,bytes32,uint256,uint24,uint32,uint40,address,address,bytes32,bool,uint256,uint256,uint256,address)) + handler: handleProposalMade + file: ./src/simple-loan-list-proposal.ts + - kind: ethereum + name: SimpleLoanElasticProposal + network: {{network}} + source: + address: "{{SimpleLoanElasticProposal.address}}" + abi: SimpleLoanElasticProposal + startBlock: {{SimpleLoanElasticProposal.startBlock}} + mapping: + kind: ethereum/events + apiVersion: 0.0.9 + language: wasm/assemblyscript + entities: + - SimpleLoanElasticProposalProposalMade + abis: + - name: SimpleLoanElasticProposal + file: ./abis/SimpleLoanElasticProposal.json + eventHandlers: + - event: ProposalMade(indexed bytes32,indexed + address,(uint8,address,uint256,bool,bytes32,address,uint256,uint256,uint256,bytes32,uint256,uint24,uint32,uint40,address,address,bytes32,bool,uint256,uint256,uint256,address)) + handler: handleProposalMade + file: ./src/simple-loan-elastic-proposal.ts + - kind: ethereum + name: SimpleLoanElasticChainlinkProposal + network: {{network}} + source: + address: "{{SimpleLoanElasticChainlinkProposal.address}}" + abi: SimpleLoanElasticChainlinkProposal + startBlock: {{SimpleLoanElasticChainlinkProposal.startBlock}} + mapping: + kind: ethereum/events + apiVersion: 0.0.9 + language: wasm/assemblyscript + entities: + - SimpleLoanElasticChainlinkProposalProposalMade + abis: + - name: SimpleLoanElasticChainlinkProposal + file: ./abis/SimpleLoanElasticChainlinkProposal.json + eventHandlers: + - event: ProposalMade(indexed bytes32,indexed + address,(uint8,address,uint256,bool,bytes32,address,address[],bool[],uint256,uint256,uint256,bytes32,uint256,uint24,uint32,uint40,address,address,bytes32,bool,uint256,uint256,uint256,address)) + handler: handleProposalMade + file: ./src/simple-loan-elastic-chainlink-proposal.ts + - kind: ethereum + name: SimpleLoan + network: {{network}} + source: + address: "{{SimpleLoan.address}}" + abi: SimpleLoan + startBlock: {{SimpleLoan.startBlock}} + mapping: + kind: ethereum/events + apiVersion: 0.0.9 + language: wasm/assemblyscript + entities: + - ExtensionProposalMade + - LOANClaimed + - LOANCreated + - LoanExtendedEvent + - LOANPaidBack + #- PoolSupply + #- PoolWithdraw + #- VaultPull + #- VaultPush + #- VaultPushFrom + abis: + - name: SimpleLoan + file: ./abis/SimpleLoan.json + eventHandlers: + - event: ExtensionProposalMade(indexed bytes32,indexed + address,(uint256,address,uint256,uint40,uint40,address,uint256,uint256)) + handler: handleExtensionProposalMade + - event: LOANClaimed(indexed uint256,indexed bool) + handler: handleLOANClaimed + - event: LOANCreated(indexed uint256,indexed bytes32,indexed + address,uint256,(address,address,uint32,(uint8,address,uint256,uint256),(uint8,address,uint256,uint256),uint256,uint24,bytes32,bytes32),(address),bytes) + handler: handleLOANCreated + - event: LOANExtended(indexed uint256,uint40,uint40) + handler: handleLOANExtended + - event: LOANPaidBack(indexed uint256) + handler: handleLOANPaidBack + #- event: PoolSupply((uint8,address,uint256,uint256),indexed address,indexed address,indexed + # address) + # handler: handlePoolSupply + #- event: PoolWithdraw((uint8,address,uint256,uint256),indexed address,indexed + # address,indexed address) + # handler: handlePoolWithdraw + #- event: VaultPull((uint8,address,uint256,uint256),indexed address) + # handler: handleVaultPull + #- event: VaultPush((uint8,address,uint256,uint256),indexed address) + # handler: handleVaultPush + #- event: VaultPushFrom((uint8,address,uint256,uint256),indexed address,indexed address) + # handler: handleVaultPushFrom + file: ./src/simple-loan.ts + - kind: ethereum + name: LoanToken + network: {{network}} + source: + address: "{{LoanToken.address}}" + abi: LoanToken + startBlock: {{LoanToken.startBlock}} + mapping: + kind: ethereum/events + apiVersion: 0.0.9 + language: wasm/assemblyscript + entities: + # - Approval + # - ApprovalForAll + #- LOANBurned + #- LOANMinted + - Transfer + abis: + - name: LoanToken + file: ./abis/LoanToken.json + eventHandlers: + # - event: Approval(indexed address,indexed address,indexed uint256) + # handler: handleApproval + # - event: ApprovalForAll(indexed address,indexed address,bool) + # handler: handleApprovalForAll + # note: no need to track LOANBurned and LOANMinted as they happen always + # together with LOANCreated and LOANClaimed + #- event: LOANBurned(indexed uint256) + # handler: handleLOANBurned + #- event: LOANMinted(indexed uint256,indexed address,indexed address) + # handler: handleLOANMinted + - event: Transfer(indexed address,indexed address,indexed uint256) + handler: handleTransfer + file: ./src/loan-token.ts + # TODO update Config abi + # TODO should we also have proxy upgrade events in the config address? + # - kind: ethereum + # name: Config + # network: {{network}} + # source: + # address: "{{Config.address}}" + # abi: Config + # startBlock: {{Config.startBlock}} + # mapping: + # kind: ethereum/events + # apiVersion: 0.0.9 + # language: wasm/assemblyscript + # entities: + # #- AdminChanged + # #- BeaconUpgraded + # #- Upgraded + # - DefaultLOANMetadataUriUpdated + # - FeeCollectorUpdated + # - FeeUpdated + # #- Initialized + # - LOANMetadataUriUpdated + # #- ConfigOwnershipTransferStarted + # #- ConfigOwnershipTransferred + # abis: + # - name: Config + # file: ./abis/Config.json + # eventHandlers: + # #- event: AdminChanged(address,address) + # # handler: handleAdminChanged + # #- event: BeaconUpgraded(indexed address) + # # handler: handleBeaconUpgraded + # #- event: Upgraded(indexed address) + # # handler: handleUpgraded + # - event: DefaultLOANMetadataUriUpdated(string) + # handler: handleDefaultLOANMetadataUriUpdated + # - event: FeeCollectorUpdated(address,address) + # handler: handleFeeCollectorUpdated + # - event: FeeUpdated(uint16,uint16) + # handler: handleFeeUpdated + # #- event: Initialized(uint8) + # # handler: handleInitialized + # - event: LOANMetadataUriUpdated(indexed address,string) + # handler: handleLOANMetadataUriUpdated + # #- event: OwnershipTransferStarted(indexed address,indexed address) + # # handler: handleOwnershipTransferStarted + # #- event: OwnershipTransferred(indexed address,indexed address) + # # handler: handleOwnershipTransferred + # file: ./src/config.ts + - kind: ethereum + name: Hub + network: {{network}} + source: + address: "{{Hub.address}}" + abi: Hub + startBlock: {{Hub.startBlock}} + mapping: + kind: ethereum/events + apiVersion: 0.0.9 + language: wasm/assemblyscript + entities: + #- OwnershipTransferStarted + #- OwnershipTransferred + - TagSetEvent + abis: + - name: Hub + file: ./abis/Hub.json + eventHandlers: + #- event: OwnershipTransferStarted(indexed address,indexed address) + # handler: handleOwnershipTransferStarted + #- event: OwnershipTransferred(indexed address,indexed address) + # handler: handleOwnershipTransferred + - event: TagSet(indexed address,indexed bytes32,bool) + handler: handleTagSet + file: ./src/hub.ts + - kind: ethereum + name: ChainlinkFeedRegistry + network: {{network}} + source: + address: "{{ChainlinkFeedRegistry.address}}" + abi: ChainlinkFeedRegistry + startBlock: {{ChainlinkFeedRegistry.startBlock}} + mapping: + kind: ethereum/events + apiVersion: 0.0.9 + language: wasm/assemblyscript + entities: + #- AccessControllerSet + - ChainlinkFeed + #- FeedConfirmed + #- FeedProposed + #- OwnershipTransferRequested + #- ChainlinkFeedRegistryOwnershipTransferred + abis: + - name: ChainlinkFeedRegistry + file: ./abis/ChainlinkFeedRegistry.json + eventHandlers: + #- event: AccessControllerSet(indexed address,indexed address) + # handler: handleAccessControllerSet + - event: FeedConfirmed(indexed address,indexed address,indexed + address,address,uint16,address) + handler: handleFeedConfirmed + #- event: FeedProposed(indexed address,indexed address,indexed address,address,address) + # handler: handleFeedProposed + #- event: OwnershipTransferRequested(indexed address,indexed address) + # handler: handleOwnershipTransferRequested + #- event: OwnershipTransferred(indexed address,indexed address) + # handler: handleOwnershipTransferred + file: ./src/chainlink-feed-registry.ts + - kind: ethereum + name: MultiTokenCategoryRegistry + network: {{network}} + source: + address: "{{MultiTokenCategoryRegistry.address}}" + abi: MultiTokenCategoryRegistry + startBlock: {{MultiTokenCategoryRegistry.startBlock}} + mapping: + kind: ethereum/events + apiVersion: 0.0.9 + language: wasm/assemblyscript + entities: + - AssetInCategory + - AssetCategory + #- CategoryRegistered + #- CategoryUnregistered + #- MultiTokenCategoryRegistryOwnershipTransferStarted + #- MultiTokenCategoryRegistryOwnershipTransferred + abis: + - name: MultiTokenCategoryRegistry + file: ./abis/MultiTokenCategoryRegistry.json + eventHandlers: + - event: CategoryRegistered(indexed address,indexed uint8) + handler: handleCategoryRegistered + - event: CategoryUnregistered(indexed address) + handler: handleCategoryUnregistered + #- event: OwnershipTransferStarted(indexed address,indexed address) + # handler: handleOwnershipTransferStarted + #- event: OwnershipTransferred(indexed address,indexed address) + # handler: handleOwnershipTransferred + file: ./src/multi-token-category-registry.ts + - kind: ethereum + name: SimpleLoanUniswapV3LPIndividualProposal + network: {{network}} + source: + address: "{{SimpleLoanUniswapV3LPIndividualProposal.address}}" + abi: SimpleLoanUniswapV3LPIndividualProposal + startBlock: {{SimpleLoanUniswapV3LPIndividualProposal.startBlock}} + mapping: + kind: ethereum/events + apiVersion: 0.0.9 + language: wasm/assemblyscript + entities: + - SimpleLoanUniswapV3LPIndividualProposalProposalMade + abis: + - name: SimpleLoanUniswapV3LPIndividualProposal + file: ./abis/SimpleLoanUniswapV3LPIndividualProposal.json + eventHandlers: + - event: ProposalMade(indexed bytes32,indexed + address,(uint256,bool,address,address[],bool[],uint256,uint256,uint256,bytes32,uint256,uint24,uint32,uint40,address,bytes,address,bytes32,bool,uint256,uint256,uint256,address)) + handler: handleProposalMade + file: ./src/simple-loan-uniswap-v-3-lp-individual-proposal.ts + - kind: ethereum + name: SimpleLoanUniswapV3LPSetProposal + network: {{network}} + source: + address: "{{SimpleLoanUniswapV3LPSetProposal.address}}" + abi: SimpleLoanUniswapV3LPSetProposal + startBlock: {{SimpleLoanUniswapV3LPSetProposal.startBlock}} + mapping: + kind: ethereum/events + apiVersion: 0.0.9 + language: wasm/assemblyscript + entities: + - SimpleLoanUniswapV3LPSetProposalProposalMade + abis: + - name: SimpleLoanUniswapV3LPSetProposal + file: ./abis/SimpleLoanUniswapV3LPSetProposal.json + eventHandlers: + - event: ProposalMade(indexed bytes32,indexed + address,(address[],address[],address,address[],bool[],uint256,uint256,uint256,bytes32,uint256,uint24,uint32,uint40,address,bytes,address,bytes32,bool,uint256,uint256,uint256,address)) + handler: handleProposalMade + file: ./src/simple-loan-uniswap-v-3-lp-set-proposal.ts diff --git a/packages/subgraph/tests/.docker/Dockerfile b/packages/subgraph/tests/.docker/Dockerfile new file mode 100644 index 0000000..e13a03c --- /dev/null +++ b/packages/subgraph/tests/.docker/Dockerfile @@ -0,0 +1,22 @@ +FROM --platform=linux/x86_64 ubuntu:22.04 + +ARG DEBIAN_FRONTEND=noninteractive + +ENV ARGS="" + +RUN apt update \ + && apt install -y sudo curl postgresql postgresql-contrib + +RUN curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - \ + && sudo apt-get install -y nodejs + +RUN curl -OL https://github.com/LimeChain/matchstick/releases/download/0.6.0/binary-linux-22 \ + && chmod a+x binary-linux-22 + +RUN mkdir matchstick +WORKDIR /matchstick + +# Commenting out for now as it seems there's no need to copy when using bind mount +# COPY ./ . + +CMD ../binary-linux-22 ${ARGS} diff --git a/packages/subgraph/tests/.latest.json b/packages/subgraph/tests/.latest.json new file mode 100644 index 0000000..ea8250a --- /dev/null +++ b/packages/subgraph/tests/.latest.json @@ -0,0 +1,4 @@ +{ + "version": "0.6.0", + "timestamp": 1749811105822 +} \ No newline at end of file diff --git a/packages/subgraph/tests/chainlink-feed-registry-utils.ts b/packages/subgraph/tests/chainlink-feed-registry-utils.ts new file mode 100644 index 0000000..8369357 --- /dev/null +++ b/packages/subgraph/tests/chainlink-feed-registry-utils.ts @@ -0,0 +1,25 @@ +import { Address, BigInt, ethereum, Bytes } from "@graphprotocol/graph-ts" +import { FeedConfirmed } from "../generated/ChainlinkFeedRegistry/ChainlinkFeedRegistry" +import { assert, test, newMockEvent, dataSourceMock } from 'matchstick-as/assembly/index' + +export function createFeedConfirmedEvent( + asset: Address, + denomination: Address, + latestAggregator: Address +): FeedConfirmed { + let event = changetype(newMockEvent()) + + event.parameters = new Array() + + event.parameters.push( + new ethereum.EventParam("asset", ethereum.Value.fromAddress(asset)) + ) + event.parameters.push( + new ethereum.EventParam("denomination", ethereum.Value.fromAddress(denomination)) + ) + event.parameters.push( + new ethereum.EventParam("latestAggregator", ethereum.Value.fromAddress(latestAggregator)) + ) + + return event +} diff --git a/packages/subgraph/tests/chainlink-feed-registry.test.ts b/packages/subgraph/tests/chainlink-feed-registry.test.ts new file mode 100644 index 0000000..b4ba88a --- /dev/null +++ b/packages/subgraph/tests/chainlink-feed-registry.test.ts @@ -0,0 +1,55 @@ +import { assert, describe, test, clearStore, beforeEach, afterEach } from "matchstick-as/assembly/index" +import { Address, BigInt, ethereum, Bytes } from "@graphprotocol/graph-ts" +import { handleFeedConfirmed } from "../src/chainlink-feed-registry" +import { createFeedConfirmedEvent } from "./chainlink-feed-registry-utils" + +describe("ChainlinkFeedRegistry", () => { + beforeEach(() => { + clearStore() + }) + + afterEach(() => { + clearStore() + }) + + test("handleFeedConfirmed - creates a new ChainlinkFeed entity", () => { + // Create test data + const asset = Address.fromString("0x0000000000000000000000000000000000000001") + const denomination = Address.fromString("0x0000000000000000000000000000000000000002") + const latestAggregator = Address.fromString("0x0000000000000000000000000000000000000003") + + // Create the event + const event = createFeedConfirmedEvent( + asset, + denomination, + latestAggregator + ) + + // Handle the event + handleFeedConfirmed(event) + + // Get the expected ID + const chainlinkFeedId = asset.concat(denomination) + + // Assert the ChainlinkFeed entity was created with correct data + assert.entityCount("ChainlinkFeed", 1) + assert.fieldEquals( + "ChainlinkFeed", + chainlinkFeedId.toHexString(), + "asset", + asset.toHexString() + ) + assert.fieldEquals( + "ChainlinkFeed", + chainlinkFeedId.toHexString(), + "denomination", + denomination.toHexString() + ) + assert.fieldEquals( + "ChainlinkFeed", + chainlinkFeedId.toHexString(), + "aggregator", + latestAggregator.toHexString() + ) + }) +}) \ No newline at end of file diff --git a/packages/subgraph/tests/hub-utils.ts b/packages/subgraph/tests/hub-utils.ts new file mode 100644 index 0000000..1ffcfc7 --- /dev/null +++ b/packages/subgraph/tests/hub-utils.ts @@ -0,0 +1,27 @@ +import { Address, BigInt, Bytes, ethereum } from "@graphprotocol/graph-ts" +import { TagSet } from "../generated/Hub/Hub" +import { assert, test, newMockEvent } from 'matchstick-as/assembly/index' + +export function createTagSetEvent( + contractAddress: Address, + tag: Bytes, + hasTag: boolean +): TagSet { + let event = changetype(newMockEvent()) + + event.parameters = new Array() + + event.parameters.push( + new ethereum.EventParam("_address", ethereum.Value.fromAddress(contractAddress)) + ) + event.parameters.push( + new ethereum.EventParam("tag", ethereum.Value.fromBytes(tag)) + ) + event.parameters.push( + new ethereum.EventParam("hasTag", ethereum.Value.fromBoolean(hasTag)) + ) + + event.address = Address.fromString("0x0000000000000000000000000000000000000001") + + return event +} \ No newline at end of file diff --git a/packages/subgraph/tests/hub.test.ts b/packages/subgraph/tests/hub.test.ts new file mode 100644 index 0000000..23fafd9 --- /dev/null +++ b/packages/subgraph/tests/hub.test.ts @@ -0,0 +1,48 @@ +import { assert, describe, test, clearStore, beforeEach, afterEach } from "matchstick-as/assembly/index" +import { Address, BigInt, ethereum, Bytes } from "@graphprotocol/graph-ts" +import { handleTagSet } from "../src/hub" +import { createTagSetEvent } from "./hub-utils" + +describe("Hub Events", () => { + beforeEach(() => { + // Clear the store before each test + clearStore() + }) + + afterEach(() => { + // Clear the store after each test + clearStore() + }) + + test("handleTagSet - creates a new Tag entity", () => { + let tag = Bytes.fromHexString("0x1234") + let value = true + let contractAddress = Address.fromString("0x0000000000000000000000000000000000000001") + + let event = createTagSetEvent(contractAddress, tag, value) + + handleTagSet(event) + + const tagSetId: Bytes = event.transaction.hash.concatI32(event.logIndex.toI32()) + + assert.entityCount("TagSetEvent", 1) + assert.fieldEquals( + "TagSetEvent", + tagSetId.toHexString(), + "tag", + tag.toHexString() + ) + assert.fieldEquals( + "TagSetEvent", + tagSetId.toHexString(), + "hasTag", + value.toString(), + ) + assert.fieldEquals( + "TagSetEvent", + tagSetId.toHexString(), + "_address", + contractAddress.toHexString() + ) + }) +}) \ No newline at end of file diff --git a/packages/subgraph/tests/loan-token-utils.ts b/packages/subgraph/tests/loan-token-utils.ts new file mode 100644 index 0000000..546fe9c --- /dev/null +++ b/packages/subgraph/tests/loan-token-utils.ts @@ -0,0 +1,28 @@ +import { Address, BigInt, Bytes, ethereum } from "@graphprotocol/graph-ts" +import { Transfer } from "../generated/LoanToken/LoanToken" +import { assert, test, newMockEvent } from 'matchstick-as/assembly/index' + +export function createTransferEvent( + from: Address, + to: Address, + tokenId: BigInt, + loanTokenAddress: Address +): Transfer { + let event = changetype(newMockEvent()) + + event.parameters = new Array() + + event.parameters.push( + new ethereum.EventParam("from", ethereum.Value.fromAddress(from)) + ) + event.parameters.push( + new ethereum.EventParam("to", ethereum.Value.fromAddress(to)) + ) + event.parameters.push( + new ethereum.EventParam("tokenId", ethereum.Value.fromUnsignedBigInt(tokenId)) + ) + + event.address = loanTokenAddress + + return event +} \ No newline at end of file diff --git a/packages/subgraph/tests/loan-token.test.ts b/packages/subgraph/tests/loan-token.test.ts new file mode 100644 index 0000000..e8aa3e4 --- /dev/null +++ b/packages/subgraph/tests/loan-token.test.ts @@ -0,0 +1,76 @@ +import { assert, describe, test, clearStore, beforeEach, afterEach, createMockedFunction } from "matchstick-as/assembly/index" +import { Address, BigInt, Bytes, ethereum } from "@graphprotocol/graph-ts" +import { handleTransfer } from "../src/loan-token" +import { createTransferEvent } from "./loan-token-utils" +import { getLoanId } from "../src/simple-loan" +import { Loan } from "../generated/schema" +import { createTestLoan, TestLoanParams } from "./simple-loan-utils" +import { log } from "matchstick-as/assembly/log" + +describe("LoanToken Events", () => { + beforeEach(() => { + // Clear the store before each test + clearStore() + }) + + afterEach(() => { + // Clear the store after each test + clearStore() + }) + + test("handleTransfer - creates a new Transfer entity", () => { + let from = Address.fromString("0x0000000000000000000000000000000000000001") + let to = Address.fromString("0x0000000000000000000000000000000000000002") + let tokenId = BigInt.fromI32(100) + let loanTokenAddress = Address.fromString("0x0000000000000000000000000000000000000003") + // default address used in mocks in matchstick-as/assembly/defaults.ts + let loanContractAddress = Address.fromString("0xA16081F360e3847006dB660bae1c6d1b2e17eC2A") + + // create mock loan entity + const loanId = getLoanId(loanContractAddress, tokenId) + const loanParams = new TestLoanParams() + loanParams.loanTokenAddress = loanTokenAddress + loanParams.lender = from + loanParams.loanContractAddress = loanContractAddress + + createTestLoan(tokenId, loanParams) + assert.fieldEquals("Loan", loanId.toHexString(), "loanOwner", from.toHexString()) + + let event = createTransferEvent(from, to, tokenId, loanTokenAddress) + const transferEventId = event.transaction.hash.concatI32(event.logIndex.toI32()) + + createMockedFunction(loanTokenAddress, 'loanContract', 'loanContract(uint256):(address)') + .withArgs([ethereum.Value.fromUnsignedBigInt(event.params.tokenId)]) + .returns([ethereum.Value.fromAddress(loanContractAddress)]) + + handleTransfer(event) + + assert.fieldEquals("Loan", loanId.toHexString(), "loanOwner", to.toHexString()) + + assert.entityCount("LoanTokenTransfer", 1) + assert.fieldEquals( + "LoanTokenTransfer", + transferEventId.toHexString(), + "from", + from.toHexString() + ) + assert.fieldEquals( + "LoanTokenTransfer", + transferEventId.toHexString(), + "to", + to.toHexString() + ) + assert.fieldEquals( + "LoanTokenTransfer", + transferEventId.toHexString(), + "tokenId", + tokenId.toString() + ) + assert.fieldEquals( + "LoanTokenTransfer", + transferEventId.toHexString(), + "contractAddress", + loanTokenAddress.toHexString() + ) + }) +}) \ No newline at end of file diff --git a/packages/subgraph/tests/multi-token-category-registry-utils.ts b/packages/subgraph/tests/multi-token-category-registry-utils.ts new file mode 100644 index 0000000..9fd82fd --- /dev/null +++ b/packages/subgraph/tests/multi-token-category-registry-utils.ts @@ -0,0 +1,39 @@ +import { Address, BigInt, Bytes, ethereum } from "@graphprotocol/graph-ts" +import { CategoryRegistered, CategoryUnregistered } from "../generated/MultiTokenCategoryRegistry/MultiTokenCategoryRegistry" +import { assert, test, newMockEvent } from 'matchstick-as/assembly/index' + +export function createCategoryRegisteredEvent( + asset: Address, + category: i32 +): CategoryRegistered { + let event = changetype(newMockEvent()) + + event.parameters = new Array() + + event.parameters.push( + new ethereum.EventParam("assetAddress", ethereum.Value.fromAddress(asset)) + ) + event.parameters.push( + new ethereum.EventParam("category", ethereum.Value.fromI32(category)) + ) + + event.address = Address.fromString("0x0000000000000000000000000000000000000001") + + return event +} + +export function createCategoryUnregisteredEvent( + asset: Address +): CategoryUnregistered { + let event = changetype(newMockEvent()) + + event.parameters = new Array() + + event.parameters.push( + new ethereum.EventParam("assetAddress", ethereum.Value.fromAddress(asset)) + ) + + event.address = Address.fromString("0x0000000000000000000000000000000000000001") + + return event +} \ No newline at end of file diff --git a/packages/subgraph/tests/multi-token-category-registry.test.ts b/packages/subgraph/tests/multi-token-category-registry.test.ts new file mode 100644 index 0000000..f5d3ad0 --- /dev/null +++ b/packages/subgraph/tests/multi-token-category-registry.test.ts @@ -0,0 +1,78 @@ +import { assert, describe, test, clearStore, beforeEach, afterEach } from "matchstick-as/assembly/index" +import { Address, BigInt, ethereum, Bytes } from "@graphprotocol/graph-ts" +import { handleCategoryRegistered, handleCategoryUnregistered } from "../src/multi-token-category-registry" +import { createCategoryRegisteredEvent, createCategoryUnregisteredEvent } from "./multi-token-category-registry-utils" +import { AssetContract } from "../generated/schema" +import { log } from "matchstick-as/assembly/log"; +import { logStore, logEntity } from 'matchstick-as/assembly/store' + +describe("MultiTokenCategoryRegistry Events", () => { + beforeEach(() => { + // Clear the store before each test + clearStore() + }) + + afterEach(() => { + // Clear the store after each test + clearStore() + }) + + test("handleCategoryRegistered - creates a new AssetCategory entity", () => { + let category = Bytes.fromHexString("0x1234").toI32() + let assetAddress = Address.fromString("0x0000000000000000000000000000000000000001") + + let event = createCategoryRegisteredEvent(assetAddress, category) + + handleCategoryRegistered(event) + + let categoryId = Bytes.fromI32(category).toHexString() + + assert.entityCount("AssetCategory", 1) + assert.fieldEquals( + "AssetCategory", + categoryId, + "id", + categoryId + ) + assert.entityCount("AssetContract", 1) + assert.fieldEquals( + "AssetContract", + assetAddress.toHexString(), + "id", + assetAddress.toHexString() + ) + + assert.fieldEquals( + "AssetContract", + assetAddress.toHexString(), + "category", + categoryId + ) + }) + + test("handleCategoryUnregistered - removes the AssetCategory entity", () => { + let category = Bytes.fromHexString("0x1234").toI32() + let registryAddress = Address.fromString("0x0000000000000000000000000000000000000001") + + // First register the category + let registerEvent = createCategoryRegisteredEvent(registryAddress, category) + handleCategoryRegistered(registerEvent) + + // Then unregister it + let unregisterEvent = createCategoryUnregisteredEvent(registryAddress) + handleCategoryUnregistered(unregisterEvent) + + assert.entityCount("AssetCategory", 1) + assert.entityCount("AssetContract", 1) + const assetContract = AssetContract.load(Bytes.fromHexString(registryAddress.toHexString())) + assert.assertNotNull(assetContract) + + if (assetContract != null) { + let assetCategory = assetContract.get("category") + // note: for some reason we can't use assert.assertNull here as here it's stringied "null", + // but this should be good enough for now + assert.fieldEquals("AssetContract", registryAddress.toHexString(), "category", "null") + } + // TODO shall we throw an error if the asset contract is not found? + }) +}) \ No newline at end of file diff --git a/packages/subgraph/tests/proposal-utils.ts b/packages/subgraph/tests/proposal-utils.ts new file mode 100644 index 0000000..37dc0b3 --- /dev/null +++ b/packages/subgraph/tests/proposal-utils.ts @@ -0,0 +1,470 @@ +import { Address, BigInt, ByteArray, Bytes, ethereum } from "@graphprotocol/graph-ts" +import { ProposalMade } from "../generated/SimpleLoanSimpleProposal/SimpleLoanSimpleProposal" +import { ProposalMade as ListProposalMade } from "../generated/SimpleLoanListProposal/SimpleLoanListProposal" +import { ProposalMade as ElasticProposalMade } from "../generated/SimpleLoanElasticProposal/SimpleLoanElasticProposal" +import { ProposalMade as ElasticChainlinkProposalMade } from "../generated/SimpleLoanElasticChainlinkProposal/SimpleLoanElasticChainlinkProposal" +import { ProposalMade as UniswapV3LPIndividualProposalMade } from "../generated/SimpleLoanUniswapV3LPIndividualProposal/SimpleLoanUniswapV3LPIndividualProposal" +import { ProposalMade as UniswapV3LPSetProposalMade } from "../generated/SimpleLoanUniswapV3LPSetProposal/SimpleLoanUniswapV3LPSetProposal" +import { assert, test, newMockEvent, dataSourceMock } from 'matchstick-as/assembly/index' + +export function createSimpleProposalMadeEvent( + proposalHash: Bytes, + proposer: Address, + collateralCategory: i32, + collateralAddress: Address, + collateralId: BigInt, + collateralAmount: BigInt, + checkCollateralStateFingerprint: boolean, + collateralStateFingerprint: Bytes, + creditAddress: Address, + creditAmount: BigInt, + availableCreditLimit: BigInt, + utilizedCreditId: Bytes, + fixedInterestAmount: BigInt, + accruingInterestAPR: i32, + durationOrDate: BigInt, + expiration: BigInt, + allowedAcceptor: Address, + proposerSpecHash: Bytes, + isOffer: boolean, + refinancingLoanId: BigInt, + nonceSpace: BigInt, + nonce: BigInt, + loanContract: Address +): ProposalMade { + let event = changetype(newMockEvent()) + + event.parameters = new Array() + + event.parameters.push( + new ethereum.EventParam("proposalHash", ethereum.Value.fromBytes(proposalHash)) + ) + event.parameters.push( + new ethereum.EventParam("proposer", ethereum.Value.fromAddress(proposer)) + ) + + let proposalTuple = new ethereum.Tuple() + proposalTuple.push(ethereum.Value.fromI32(collateralCategory)) + proposalTuple.push(ethereum.Value.fromAddress(collateralAddress)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(collateralId)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(collateralAmount)) + proposalTuple.push(ethereum.Value.fromBoolean(checkCollateralStateFingerprint)) + proposalTuple.push(ethereum.Value.fromBytes(collateralStateFingerprint)) + proposalTuple.push(ethereum.Value.fromAddress(creditAddress)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(creditAmount)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(availableCreditLimit)) + proposalTuple.push(ethereum.Value.fromBytes(utilizedCreditId)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(fixedInterestAmount)) + proposalTuple.push(ethereum.Value.fromI32(accruingInterestAPR)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(durationOrDate)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(expiration)) + proposalTuple.push(ethereum.Value.fromAddress(allowedAcceptor)) + proposalTuple.push(ethereum.Value.fromAddress(proposer)) + proposalTuple.push(ethereum.Value.fromBytes(proposerSpecHash)) + proposalTuple.push(ethereum.Value.fromBoolean(isOffer)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(refinancingLoanId)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(nonceSpace)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(nonce)) + proposalTuple.push(ethereum.Value.fromAddress(loanContract)) + + event.parameters.push( + new ethereum.EventParam("proposal", ethereum.Value.fromTuple(proposalTuple)) + ) + + event.address = loanContract + + return event +} + +export function createListProposalMadeEvent( + proposalHash: Bytes, + proposer: Address, + collateralCategory: i32, + collateralAddress: Address, + collateralIdsWhitelistMerkleRoot: Bytes, + collateralAmount: BigInt, + checkCollateralStateFingerprint: boolean, + collateralStateFingerprint: Bytes, + creditAddress: Address, + creditAmount: BigInt, + availableCreditLimit: BigInt, + utilizedCreditId: Bytes, + fixedInterestAmount: BigInt, + accruingInterestAPR: i32, + durationOrDate: BigInt, + expiration: BigInt, + allowedAcceptor: Address, + proposerSpecHash: Bytes, + isOffer: boolean, + refinancingLoanId: BigInt, + nonceSpace: BigInt, + nonce: BigInt, + loanContract: Address +): ListProposalMade { + let event = changetype(newMockEvent()) + + event.parameters = new Array() + + event.parameters.push( + new ethereum.EventParam("proposalHash", ethereum.Value.fromBytes(proposalHash)) + ) + event.parameters.push( + new ethereum.EventParam("proposer", ethereum.Value.fromAddress(proposer)) + ) + + let proposalTuple = new ethereum.Tuple() + proposalTuple.push(ethereum.Value.fromI32(collateralCategory)) + proposalTuple.push(ethereum.Value.fromAddress(collateralAddress)) + proposalTuple.push(ethereum.Value.fromBytes(collateralIdsWhitelistMerkleRoot)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(collateralAmount)) + proposalTuple.push(ethereum.Value.fromBoolean(checkCollateralStateFingerprint)) + proposalTuple.push(ethereum.Value.fromBytes(collateralStateFingerprint)) + proposalTuple.push(ethereum.Value.fromAddress(creditAddress)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(creditAmount)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(availableCreditLimit)) + proposalTuple.push(ethereum.Value.fromBytes(utilizedCreditId)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(fixedInterestAmount)) + proposalTuple.push(ethereum.Value.fromI32(accruingInterestAPR)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(durationOrDate)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(expiration)) + proposalTuple.push(ethereum.Value.fromAddress(allowedAcceptor)) + proposalTuple.push(ethereum.Value.fromAddress(proposer)) + proposalTuple.push(ethereum.Value.fromBytes(proposerSpecHash)) + proposalTuple.push(ethereum.Value.fromBoolean(isOffer)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(refinancingLoanId)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(nonceSpace)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(nonce)) + proposalTuple.push(ethereum.Value.fromAddress(loanContract)) + + event.parameters.push( + new ethereum.EventParam("proposal", ethereum.Value.fromTuple(proposalTuple)) + ) + + event.address = loanContract + + return event +} + +export function createElasticProposalMadeEvent( + proposalHash: Bytes, + proposer: Address, + collateralCategory: i32, + collateralAddress: Address, + collateralId: BigInt, + checkCollateralStateFingerprint: boolean, + collateralStateFingerprint: Bytes, + creditAddress: Address, + creditPerCollateralUnit: BigInt, + minCreditAmount: BigInt, + availableCreditLimit: BigInt, + utilizedCreditId: Bytes, + fixedInterestAmount: BigInt, + accruingInterestAPR: i32, + durationOrDate: BigInt, + expiration: BigInt, + allowedAcceptor: Address, + proposerSpecHash: Bytes, + isOffer: boolean, + refinancingLoanId: BigInt, + nonceSpace: BigInt, + nonce: BigInt, + loanContract: Address +): ElasticProposalMade { + let event = changetype(newMockEvent()) + + event.parameters = new Array() + + event.parameters.push( + new ethereum.EventParam("proposalHash", ethereum.Value.fromBytes(proposalHash)) + ) + event.parameters.push( + new ethereum.EventParam("proposer", ethereum.Value.fromAddress(proposer)) + ) + + let proposalTuple = new ethereum.Tuple() + proposalTuple.push(ethereum.Value.fromI32(collateralCategory)) + proposalTuple.push(ethereum.Value.fromAddress(collateralAddress)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(collateralId)) + proposalTuple.push(ethereum.Value.fromBoolean(checkCollateralStateFingerprint)) + proposalTuple.push(ethereum.Value.fromBytes(collateralStateFingerprint)) + proposalTuple.push(ethereum.Value.fromAddress(creditAddress)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(creditPerCollateralUnit)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(minCreditAmount)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(availableCreditLimit)) + proposalTuple.push(ethereum.Value.fromBytes(utilizedCreditId)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(fixedInterestAmount)) + proposalTuple.push(ethereum.Value.fromI32(accruingInterestAPR)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(durationOrDate)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(expiration)) + proposalTuple.push(ethereum.Value.fromAddress(allowedAcceptor)) + proposalTuple.push(ethereum.Value.fromAddress(proposer)) + proposalTuple.push(ethereum.Value.fromBytes(proposerSpecHash)) + proposalTuple.push(ethereum.Value.fromBoolean(isOffer)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(refinancingLoanId)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(nonceSpace)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(nonce)) + proposalTuple.push(ethereum.Value.fromAddress(loanContract)) + + event.parameters.push( + new ethereum.EventParam("proposal", ethereum.Value.fromTuple(proposalTuple)) + ) + + event.address = loanContract + + return event +} + +export function createElasticChainlinkProposalMadeEvent( + proposalHash: Bytes, + proposer: Address, + collateralCategory: i32, + collateralAddress: Address, + collateralId: BigInt, + checkCollateralStateFingerprint: boolean, + collateralStateFingerprint: Bytes, + creditAddress: Address, + feedIntermediaryDenominations: Address[], + feedInvertFlags: boolean[], + loanToValue: BigInt, + minCreditAmount: BigInt, + availableCreditLimit: BigInt, + utilizedCreditId: Bytes, + fixedInterestAmount: BigInt, + accruingInterestAPR: i32, + durationOrDate: BigInt, + expiration: BigInt, + allowedAcceptor: Address, + proposerSpecHash: Bytes, + isOffer: boolean, + refinancingLoanId: BigInt, + nonceSpace: BigInt, + nonce: BigInt, + loanContract: Address +): ElasticChainlinkProposalMade { + let event = changetype(newMockEvent()) + + event.parameters = new Array() + + event.parameters.push( + new ethereum.EventParam("proposalHash", ethereum.Value.fromBytes(proposalHash)) + ) + event.parameters.push( + new ethereum.EventParam("proposer", ethereum.Value.fromAddress(proposer)) + ) + + let proposalTuple = new ethereum.Tuple() + proposalTuple.push(ethereum.Value.fromI32(collateralCategory)) + proposalTuple.push(ethereum.Value.fromAddress(collateralAddress)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(collateralId)) + proposalTuple.push(ethereum.Value.fromBoolean(checkCollateralStateFingerprint)) + proposalTuple.push(ethereum.Value.fromBytes(collateralStateFingerprint)) + proposalTuple.push(ethereum.Value.fromAddress(creditAddress)) + + let feedDenominationsArray = new Array() + for (let i = 0; i < feedIntermediaryDenominations.length; i++) { + feedDenominationsArray.push(ethereum.Value.fromAddress(feedIntermediaryDenominations[i])) + } + proposalTuple.push(ethereum.Value.fromArray(feedDenominationsArray)) + + let feedFlagsArray = new Array() + for (let i = 0; i < feedInvertFlags.length; i++) { + feedFlagsArray.push(ethereum.Value.fromBoolean(feedInvertFlags[i])) + } + proposalTuple.push(ethereum.Value.fromArray(feedFlagsArray)) + + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(loanToValue)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(minCreditAmount)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(availableCreditLimit)) + proposalTuple.push(ethereum.Value.fromBytes(utilizedCreditId)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(fixedInterestAmount)) + proposalTuple.push(ethereum.Value.fromI32(accruingInterestAPR)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(durationOrDate)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(expiration)) + proposalTuple.push(ethereum.Value.fromAddress(allowedAcceptor)) + proposalTuple.push(ethereum.Value.fromAddress(proposer)) + proposalTuple.push(ethereum.Value.fromBytes(proposerSpecHash)) + proposalTuple.push(ethereum.Value.fromBoolean(isOffer)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(refinancingLoanId)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(nonceSpace)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(nonce)) + proposalTuple.push(ethereum.Value.fromAddress(loanContract)) + + event.parameters.push( + new ethereum.EventParam("proposal", ethereum.Value.fromTuple(proposalTuple)) + ) + + event.address = loanContract + + return event +} + +export function createUniswapV3LPIndividualProposalMadeEvent( + proposalHash: Bytes, + proposer: Address, + collateralId: BigInt, + token0Denominator: Address, + creditAddress: Address, + feedIntermediaryDenominations: Address[], + feedInvertFlags: boolean[], + loanToValue: BigInt, + minCreditAmount: BigInt, + availableCreditLimit: BigInt, + utilizedCreditId: Bytes, + fixedInterestAmount: BigInt, + accruingInterestAPR: i32, + durationOrDate: BigInt, + expiration: BigInt, + acceptorController: Address, + acceptorControllerData: Bytes, + proposerSpecHash: Bytes, + isOffer: boolean, + refinancingLoanId: BigInt, + nonceSpace: BigInt, + nonce: BigInt, + loanContract: Address +): UniswapV3LPIndividualProposalMade { + let event = changetype(newMockEvent()) + + event.parameters = new Array() + + event.parameters.push( + new ethereum.EventParam("proposalHash", ethereum.Value.fromBytes(proposalHash)) + ) + event.parameters.push( + new ethereum.EventParam("proposer", ethereum.Value.fromAddress(proposer)) + ) + + let proposalTuple = new ethereum.Tuple() + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(collateralId)) + proposalTuple.push(ethereum.Value.fromBoolean(isOffer)) + proposalTuple.push(ethereum.Value.fromAddress(token0Denominator)) + + let feedDenominationsArray = new Array() + for (let i = 0; i < feedIntermediaryDenominations.length; i++) { + feedDenominationsArray.push(ethereum.Value.fromAddress(feedIntermediaryDenominations[i])) + } + proposalTuple.push(ethereum.Value.fromArray(feedDenominationsArray)) + + let feedFlagsArray = new Array() + for (let i = 0; i < feedInvertFlags.length; i++) { + feedFlagsArray.push(ethereum.Value.fromBoolean(feedInvertFlags[i])) + } + proposalTuple.push(ethereum.Value.fromArray(feedFlagsArray)) + + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(loanToValue)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(minCreditAmount)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(availableCreditLimit)) + proposalTuple.push(ethereum.Value.fromBytes(utilizedCreditId)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(fixedInterestAmount)) + proposalTuple.push(ethereum.Value.fromI32(accruingInterestAPR)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(durationOrDate)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(expiration)) + proposalTuple.push(ethereum.Value.fromAddress(acceptorController)) + proposalTuple.push(ethereum.Value.fromBytes(acceptorControllerData)) + proposalTuple.push(ethereum.Value.fromAddress(proposer)) + proposalTuple.push(ethereum.Value.fromBytes(proposerSpecHash)) + proposalTuple.push(ethereum.Value.fromBoolean(isOffer)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(refinancingLoanId)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(nonceSpace)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(nonce)) + proposalTuple.push(ethereum.Value.fromAddress(loanContract)) + + event.parameters.push( + new ethereum.EventParam("proposal", ethereum.Value.fromTuple(proposalTuple)) + ) + + event.address = loanContract + + return event +} + +export function createUniswapV3LPSetProposalMadeEvent( + proposalHash: Bytes, + proposer: Address, + tokenAAllowlist: Address[], + tokenBAllowlist: Address[], + creditAddress: Address, + feedIntermediaryDenominations: Address[], + feedInvertFlags: boolean[], + loanToValue: BigInt, + minCreditAmount: BigInt, + availableCreditLimit: BigInt, + utilizedCreditId: Bytes, + fixedInterestAmount: BigInt, + accruingInterestAPR: i32, + durationOrDate: BigInt, + expiration: BigInt, + acceptorController: Address, + acceptorControllerData: Bytes, + proposerSpecHash: Bytes, + isOffer: boolean, + refinancingLoanId: BigInt, + nonceSpace: BigInt, + nonce: BigInt, + loanContract: Address +): UniswapV3LPSetProposalMade { + let event = changetype(newMockEvent()) + + event.parameters = new Array() + + event.parameters.push( + new ethereum.EventParam("proposalHash", ethereum.Value.fromBytes(proposalHash)) + ) + event.parameters.push( + new ethereum.EventParam("proposer", ethereum.Value.fromAddress(proposer)) + ) + + let proposalTuple = new ethereum.Tuple() + + let tokenAArray = new Array() + for (let i = 0; i < tokenAAllowlist.length; i++) { + tokenAArray.push(ethereum.Value.fromAddress(tokenAAllowlist[i])) + } + proposalTuple.push(ethereum.Value.fromArray(tokenAArray)) + + let tokenBArray = new Array() + for (let i = 0; i < tokenBAllowlist.length; i++) { + tokenBArray.push(ethereum.Value.fromAddress(tokenBAllowlist[i])) + } + proposalTuple.push(ethereum.Value.fromArray(tokenBArray)) + + proposalTuple.push(ethereum.Value.fromAddress(creditAddress)) + + let feedDenominationsArray = new Array() + for (let i = 0; i < feedIntermediaryDenominations.length; i++) { + feedDenominationsArray.push(ethereum.Value.fromAddress(feedIntermediaryDenominations[i])) + } + proposalTuple.push(ethereum.Value.fromArray(feedDenominationsArray)) + + let feedFlagsArray = new Array() + for (let i = 0; i < feedInvertFlags.length; i++) { + feedFlagsArray.push(ethereum.Value.fromBoolean(feedInvertFlags[i])) + } + proposalTuple.push(ethereum.Value.fromArray(feedFlagsArray)) + + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(loanToValue)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(minCreditAmount)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(availableCreditLimit)) + proposalTuple.push(ethereum.Value.fromBytes(utilizedCreditId)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(fixedInterestAmount)) + proposalTuple.push(ethereum.Value.fromI32(accruingInterestAPR)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(durationOrDate)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(expiration)) + proposalTuple.push(ethereum.Value.fromAddress(acceptorController)) + proposalTuple.push(ethereum.Value.fromBytes(acceptorControllerData)) + proposalTuple.push(ethereum.Value.fromAddress(proposer)) + proposalTuple.push(ethereum.Value.fromBytes(proposerSpecHash)) + proposalTuple.push(ethereum.Value.fromBoolean(isOffer)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(refinancingLoanId)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(nonceSpace)) + proposalTuple.push(ethereum.Value.fromUnsignedBigInt(nonce)) + proposalTuple.push(ethereum.Value.fromAddress(loanContract)) + + event.parameters.push( + new ethereum.EventParam("proposal", ethereum.Value.fromTuple(proposalTuple)) + ) + + event.address = loanContract + + return event +} \ No newline at end of file diff --git a/packages/subgraph/tests/proposal.test.ts b/packages/subgraph/tests/proposal.test.ts new file mode 100644 index 0000000..49d1852 --- /dev/null +++ b/packages/subgraph/tests/proposal.test.ts @@ -0,0 +1,431 @@ +import { assert, describe, test, clearStore, beforeEach, afterEach } from "matchstick-as/assembly/index" +import { Address, BigInt, Bytes } from "@graphprotocol/graph-ts" +import { handleProposalMade as handleSimpleProposalMade } from "../src/simple-loan-simple-proposal" +import { handleProposalMade as handleListProposalMade } from "../src/simple-loan-list-proposal" +import { handleProposalMade as handleElasticProposalMade } from "../src/simple-loan-elastic-proposal" +import { handleProposalMade as handleElasticChainlinkProposalMade } from "../src/simple-loan-elastic-chainlink-proposal" +import { handleProposalMade as handleUniswapV3LPIndividualProposalMade } from "../src/simple-loan-uniswap-v-3-lp-individual-proposal" +import { handleProposalMade as handleUniswapV3LPSetProposalMade } from "../src/simple-loan-uniswap-v-3-lp-set-proposal" +import { createSimpleProposalMadeEvent, createListProposalMadeEvent, createElasticProposalMadeEvent, createElasticChainlinkProposalMadeEvent, createUniswapV3LPIndividualProposalMadeEvent, createUniswapV3LPSetProposalMadeEvent } from "./proposal-utils" + +describe("Proposal Events", () => { + beforeEach(() => { + clearStore() + }) + + afterEach(() => { + clearStore() + }) + + test("handleSimpleProposalMade - creates a new Proposal entity", () => { + const proposalHash = Bytes.fromHexString("0x1234") + const proposer = Address.fromString("0x0000000000000000000000000000000000000001") + const collateralCategory = 1 + const collateralAddress = Address.fromString("0x0000000000000000000000000000000000000002") + const collateralId = BigInt.fromI32(1) + const collateralAmount = BigInt.fromI32(100) + const checkCollateralStateFingerprint = true + const collateralStateFingerprint = Bytes.fromHexString("0x5678") + const creditAddress = Address.fromString("0x0000000000000000000000000000000000000003") + const creditAmount = BigInt.fromI32(1000) + const availableCreditLimit = BigInt.fromI32(2000) + const utilizedCreditId = Bytes.fromHexString("0x9abc") + const fixedInterestAmount = BigInt.fromI32(50) + const accruingInterestAPR = 1000 + const durationOrDate = BigInt.fromI32(30) + const expiration = BigInt.fromI32(1234567890) + const allowedAcceptor = Address.fromString("0x0000000000000000000000000000000000000004") + const proposerSpecHash = Bytes.fromHexString("0xdef0") + const isOffer = true + const refinancingLoanId = BigInt.fromI32(0) + const nonceSpace = BigInt.fromI32(1) + const nonce = BigInt.fromI32(1) + const loanContract = Address.fromString("0x0000000000000000000000000000000000000005") + + const event = createSimpleProposalMadeEvent( + proposalHash, + proposer, + collateralCategory, + collateralAddress, + collateralId, + collateralAmount, + checkCollateralStateFingerprint, + collateralStateFingerprint, + creditAddress, + creditAmount, + availableCreditLimit, + utilizedCreditId, + fixedInterestAmount, + accruingInterestAPR, + durationOrDate, + expiration, + allowedAcceptor, + proposerSpecHash, + isOffer, + refinancingLoanId, + nonceSpace, + nonce, + loanContract + ) + + handleSimpleProposalMade(event) + + // Verify the Proposal entity was created + assert.entityCount("Proposal", 1) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "proposalType", "Simple") + assert.fieldEquals("Proposal", proposalHash.toHexString(), "proposer", proposer.toHexString()) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "collateralAmount", collateralAmount.toString()) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "creditAmount", creditAmount.toString()) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "status", "Active") + + // Verify the SimpleLoanSimpleProposalMade entity was created + assert.entityCount("SimpleLoanSimpleProposalMade", 1) + const eventId = event.transaction.hash.concatI32(event.logIndex.toI32()) + assert.fieldEquals("SimpleLoanSimpleProposalMade", eventId.toHexString(), "proposalHash", proposalHash.toHexString()) + assert.fieldEquals("SimpleLoanSimpleProposalMade", eventId.toHexString(), "proposer", proposer.toHexString()) + }) + + test("handleListProposalMade - creates a new Proposal entity", () => { + const proposalHash = Bytes.fromHexString("0x1234") + const proposer = Address.fromString("0x0000000000000000000000000000000000000001") + const collateralCategory = 1 + const collateralAddress = Address.fromString("0x0000000000000000000000000000000000000002") + const collateralIdsWhitelistMerkleRoot = Bytes.fromHexString("0x5678") + const collateralAmount = BigInt.fromI32(100) + const checkCollateralStateFingerprint = true + const collateralStateFingerprint = Bytes.fromHexString("0x9abc") + const creditAddress = Address.fromString("0x0000000000000000000000000000000000000003") + const creditAmount = BigInt.fromI32(1000) + const availableCreditLimit = BigInt.fromI32(2000) + const utilizedCreditId = Bytes.fromHexString("0xdef0") + const fixedInterestAmount = BigInt.fromI32(50) + const accruingInterestAPR = 1000 + const durationOrDate = BigInt.fromI32(30) + const expiration = BigInt.fromI32(1234567890) + const allowedAcceptor = Address.fromString("0x0000000000000000000000000000000000000004") + const proposerSpecHash = Bytes.fromHexString("0x1234") + const isOffer = true + const refinancingLoanId = BigInt.fromI32(0) + const nonceSpace = BigInt.fromI32(1) + const nonce = BigInt.fromI32(1) + const loanContract = Address.fromString("0x0000000000000000000000000000000000000005") + + const event = createListProposalMadeEvent( + proposalHash, + proposer, + collateralCategory, + collateralAddress, + collateralIdsWhitelistMerkleRoot, + collateralAmount, + checkCollateralStateFingerprint, + collateralStateFingerprint, + creditAddress, + creditAmount, + availableCreditLimit, + utilizedCreditId, + fixedInterestAmount, + accruingInterestAPR, + durationOrDate, + expiration, + allowedAcceptor, + proposerSpecHash, + isOffer, + refinancingLoanId, + nonceSpace, + nonce, + loanContract + ) + + handleListProposalMade(event) + + // Verify the Proposal entity was created + assert.entityCount("Proposal", 1) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "proposalType", "List") + assert.fieldEquals("Proposal", proposalHash.toHexString(), "proposer", proposer.toHexString()) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "collateralAmount", collateralAmount.toString()) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "creditAmount", creditAmount.toString()) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "status", "Active") + + // Verify the SimpleLoanListProposalProposalMade entity was created + assert.entityCount("SimpleLoanListProposalProposalMade", 1) + const eventId = event.transaction.hash.concatI32(event.logIndex.toI32()) + assert.fieldEquals("SimpleLoanListProposalProposalMade", eventId.toHexString(), "proposalHash", proposalHash.toHexString()) + assert.fieldEquals("SimpleLoanListProposalProposalMade", eventId.toHexString(), "proposer", proposer.toHexString()) + }) + + test("handleElasticProposalMade - creates a new Proposal entity", () => { + const proposalHash = Bytes.fromHexString("0x1234") + const proposer = Address.fromString("0x0000000000000000000000000000000000000001") + const collateralCategory = 1 + const collateralAddress = Address.fromString("0x0000000000000000000000000000000000000002") + const collateralId = BigInt.fromI32(1) + const checkCollateralStateFingerprint = true + const collateralStateFingerprint = Bytes.fromHexString("0x5678") + const creditAddress = Address.fromString("0x0000000000000000000000000000000000000003") + const creditPerCollateralUnit = BigInt.fromI32(10) + const minCreditAmount = BigInt.fromI32(100) + const availableCreditLimit = BigInt.fromI32(2000) + const utilizedCreditId = Bytes.fromHexString("0x9abc") + const fixedInterestAmount = BigInt.fromI32(50) + const accruingInterestAPR = 1000 + const durationOrDate = BigInt.fromI32(30) + const expiration = BigInt.fromI32(1234567890) + const allowedAcceptor = Address.fromString("0x0000000000000000000000000000000000000004") + const proposerSpecHash = Bytes.fromHexString("0xdef0") + const isOffer = true + const refinancingLoanId = BigInt.fromI32(0) + const nonceSpace = BigInt.fromI32(1) + const nonce = BigInt.fromI32(1) + const loanContract = Address.fromString("0x0000000000000000000000000000000000000005") + + const event = createElasticProposalMadeEvent( + proposalHash, + proposer, + collateralCategory, + collateralAddress, + collateralId, + checkCollateralStateFingerprint, + collateralStateFingerprint, + creditAddress, + creditPerCollateralUnit, + minCreditAmount, + availableCreditLimit, + utilizedCreditId, + fixedInterestAmount, + accruingInterestAPR, + durationOrDate, + expiration, + allowedAcceptor, + proposerSpecHash, + isOffer, + refinancingLoanId, + nonceSpace, + nonce, + loanContract + ) + + handleElasticProposalMade(event) + + // Verify the Proposal entity was created + assert.entityCount("Proposal", 1) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "proposalType", "Elastic") + assert.fieldEquals("Proposal", proposalHash.toHexString(), "proposer", proposer.toHexString()) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "creditPerCollateralUnit", creditPerCollateralUnit.toString()) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "minCreditAmount", minCreditAmount.toString()) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "status", "Active") + + // Verify the SimpleLoanElasticProposalProposalMade entity was created + assert.entityCount("SimpleLoanElasticProposalProposalMade", 1) + const eventId = event.transaction.hash.concatI32(event.logIndex.toI32()) + assert.fieldEquals("SimpleLoanElasticProposalProposalMade", eventId.toHexString(), "proposalHash", proposalHash.toHexString()) + assert.fieldEquals("SimpleLoanElasticProposalProposalMade", eventId.toHexString(), "proposer", proposer.toHexString()) + }) + + test("handleElasticChainlinkProposalMade - creates a new Proposal entity", () => { + const proposalHash = Bytes.fromHexString("0x1234") + const proposer = Address.fromString("0x0000000000000000000000000000000000000001") + const collateralCategory = 1 + const collateralAddress = Address.fromString("0x0000000000000000000000000000000000000002") + const collateralId = BigInt.fromI32(1) + const checkCollateralStateFingerprint = true + const collateralStateFingerprint = Bytes.fromHexString("0x5678") + const creditAddress = Address.fromString("0x0000000000000000000000000000000000000003") + const feedIntermediaryDenominations = [Address.fromString("0x0000000000000000000000000000000000000023")] + const feedInvertFlags = [true] + const loanToValue = BigInt.fromI32(80) + const minCreditAmount = BigInt.fromI32(100) + const availableCreditLimit = BigInt.fromI32(2000) + const utilizedCreditId = Bytes.fromHexString("0xdef0") + const fixedInterestAmount = BigInt.fromI32(50) + const accruingInterestAPR = 1000 + const durationOrDate = BigInt.fromI32(30) + const expiration = BigInt.fromI32(1234567890) + const allowedAcceptor = Address.fromString("0x0000000000000000000000000000000000000004") + const proposerSpecHash = Bytes.fromHexString("0x1234") + const isOffer = true + const refinancingLoanId = BigInt.fromI32(0) + const nonceSpace = BigInt.fromI32(1) + const nonce = BigInt.fromI32(1) + const loanContract = Address.fromString("0x0000000000000000000000000000000000000005") + + const event = createElasticChainlinkProposalMadeEvent( + proposalHash, + proposer, + collateralCategory, + collateralAddress, + collateralId, + checkCollateralStateFingerprint, + collateralStateFingerprint, + creditAddress, + feedIntermediaryDenominations, + feedInvertFlags, + loanToValue, + minCreditAmount, + availableCreditLimit, + utilizedCreditId, + fixedInterestAmount, + accruingInterestAPR, + durationOrDate, + expiration, + allowedAcceptor, + proposerSpecHash, + isOffer, + refinancingLoanId, + nonceSpace, + nonce, + loanContract + ) + + handleElasticChainlinkProposalMade(event) + + // Verify the Proposal entity was created + assert.entityCount("Proposal", 1) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "proposalType", "ElasticChainlink") + assert.fieldEquals("Proposal", proposalHash.toHexString(), "proposer", proposer.toHexString()) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "loanToValue", loanToValue.toString()) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "minCreditAmount", minCreditAmount.toString()) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "status", "Active") + + // Verify the SimpleLoanElasticChainlinkProposalProposalMade entity was created + assert.entityCount("SimpleLoanElasticChainlinkProposalProposalMade", 1) + const eventId = event.transaction.hash.concatI32(event.logIndex.toI32()) + assert.fieldEquals("SimpleLoanElasticChainlinkProposalProposalMade", eventId.toHexString(), "proposalHash", proposalHash.toHexString()) + assert.fieldEquals("SimpleLoanElasticChainlinkProposalProposalMade", eventId.toHexString(), "proposer", proposer.toHexString()) + }) + + test("handleUniswapV3LPIndividualProposalMade - creates a new Proposal entity", () => { + const proposalHash = Bytes.fromHexString("0x1234") + const proposer = Address.fromString("0x0000000000000000000000000000000000000001") + const collateralId = BigInt.fromI32(1) + const token0Denominator = Address.fromString("0x0000000000000000000000000000000000000002") + const creditAddress = Address.fromString("0x0000000000000000000000000000000000000003") + const feedIntermediaryDenominations = [Address.fromString("0x0000000000000000000000000000000000000023")] + const feedInvertFlags = [true] + const loanToValue = BigInt.fromI32(80) + const minCreditAmount = BigInt.fromI32(100) + const availableCreditLimit = BigInt.fromI32(2000) + const utilizedCreditId = Bytes.fromHexString("0x9abc") + const fixedInterestAmount = BigInt.fromI32(50) + const accruingInterestAPR = 1000 + const durationOrDate = BigInt.fromI32(30) + const expiration = BigInt.fromI32(1234567890) + const acceptorController = Address.fromString("0x0000000000000000000000000000000000000004") + const acceptorControllerData = Bytes.fromHexString("0xdef0") + const proposerSpecHash = Bytes.fromHexString("0x1234") + const isOffer = true + const refinancingLoanId = BigInt.fromI32(0) + const nonceSpace = BigInt.fromI32(1) + const nonce = BigInt.fromI32(1) + const loanContract = Address.fromString("0x0000000000000000000000000000000000000005") + + const event = createUniswapV3LPIndividualProposalMadeEvent( + proposalHash, + proposer, + collateralId, + token0Denominator, + creditAddress, + feedIntermediaryDenominations, + feedInvertFlags, + loanToValue, + minCreditAmount, + availableCreditLimit, + utilizedCreditId, + fixedInterestAmount, + accruingInterestAPR, + durationOrDate, + expiration, + acceptorController, + acceptorControllerData, + proposerSpecHash, + isOffer, + refinancingLoanId, + nonceSpace, + nonce, + loanContract + ) + + handleUniswapV3LPIndividualProposalMade(event) + + // Verify the Proposal entity was created + assert.entityCount("Proposal", 1) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "proposalType", "UniswapV3LPIndividual") + assert.fieldEquals("Proposal", proposalHash.toHexString(), "proposer", proposer.toHexString()) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "loanToValue", loanToValue.toString()) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "minCreditAmount", minCreditAmount.toString()) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "status", "Active") + + // Verify the SimpleLoanUniswapV3LPIndividualProposalProposalMade entity was created + assert.entityCount("SimpleLoanUniswapV3LPIndividualProposalProposalMade", 1) + const eventId = event.transaction.hash.concatI32(event.logIndex.toI32()) + assert.fieldEquals("SimpleLoanUniswapV3LPIndividualProposalProposalMade", eventId.toHexString(), "proposalHash", proposalHash.toHexString()) + assert.fieldEquals("SimpleLoanUniswapV3LPIndividualProposalProposalMade", eventId.toHexString(), "proposer", proposer.toHexString()) + }) + + test("handleUniswapV3LPSetProposalMade - creates a new Proposal entity", () => { + const proposalHash = Bytes.fromHexString("0x1234") + const proposer = Address.fromString("0x0000000000000000000000000000000000000001") + const tokenAAllowlist = [Address.fromString("0x0000000000000000000000000000000000000033")] + const tokenBAllowlist = [Address.fromString("0x0000000000000000000000000000000000000043")] + const creditAddress = Address.fromString("0x0000000000000000000000000000000000000002") + const feedIntermediaryDenominations = [Address.fromString("0x0000000000000000000000000000000000000023")] + const feedInvertFlags = [true] + const loanToValue = BigInt.fromI32(80) + const minCreditAmount = BigInt.fromI32(100) + const availableCreditLimit = BigInt.fromI32(2000) + const utilizedCreditId = Bytes.fromHexString("0x1234") + const fixedInterestAmount = BigInt.fromI32(50) + const accruingInterestAPR = 1000 + const durationOrDate = BigInt.fromI32(30) + const expiration = BigInt.fromI32(1234567890) + const acceptorController = Address.fromString("0x0000000000000000000000000000000000000003") + const acceptorControllerData = Bytes.fromHexString("0x5678") + const proposerSpecHash = Bytes.fromHexString("0x9abc") + const isOffer = true + const refinancingLoanId = BigInt.fromI32(0) + const nonceSpace = BigInt.fromI32(1) + const nonce = BigInt.fromI32(1) + const loanContract = Address.fromString("0x0000000000000000000000000000000000000004") + + const event = createUniswapV3LPSetProposalMadeEvent( + proposalHash, + proposer, + tokenAAllowlist, + tokenBAllowlist, + creditAddress, + feedIntermediaryDenominations, + feedInvertFlags, + loanToValue, + minCreditAmount, + availableCreditLimit, + utilizedCreditId, + fixedInterestAmount, + accruingInterestAPR, + durationOrDate, + expiration, + acceptorController, + acceptorControllerData, + proposerSpecHash, + isOffer, + refinancingLoanId, + nonceSpace, + nonce, + loanContract + ) + + handleUniswapV3LPSetProposalMade(event) + + // Verify the Proposal entity was created + assert.entityCount("Proposal", 1) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "proposalType", "UniswapV3LPSet") + assert.fieldEquals("Proposal", proposalHash.toHexString(), "proposer", proposer.toHexString()) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "loanToValue", loanToValue.toString()) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "minCreditAmount", minCreditAmount.toString()) + assert.fieldEquals("Proposal", proposalHash.toHexString(), "status", "Active") + + // Verify the SimpleLoanUniswapV3LPSetProposalProposalMade entity was created + assert.entityCount("SimpleLoanUniswapV3LPSetProposalProposalMade", 1) + const eventId = event.transaction.hash.concatI32(event.logIndex.toI32()) + assert.fieldEquals("SimpleLoanUniswapV3LPSetProposalProposalMade", eventId.toHexString(), "proposalHash", proposalHash.toHexString()) + assert.fieldEquals("SimpleLoanUniswapV3LPSetProposalProposalMade", eventId.toHexString(), "proposer", proposer.toHexString()) + }) +}) \ No newline at end of file diff --git a/packages/subgraph/tests/simple-loan-utils.ts b/packages/subgraph/tests/simple-loan-utils.ts new file mode 100644 index 0000000..612194c --- /dev/null +++ b/packages/subgraph/tests/simple-loan-utils.ts @@ -0,0 +1,345 @@ +import { Address, BigInt, ethereum, Bytes } from "@graphprotocol/graph-ts" +import { LOANCreated, LOANPaidBack, LOANClaimed, LOANExtended, ExtensionProposalMade } from "../generated/SimpleLoan/SimpleLoan" +import { assert, test, newMockEvent, dataSourceMock, createMockedFunction } from 'matchstick-as/assembly/index' +import { getLoanId, handleLOANCreated } from "../src/simple-loan" +import { Loan } from "../generated/schema"; + +// Define a class to hold the parameters +export class TestLoanParams { + proposalHash: Bytes = Bytes.fromHexString("0x1234"); + proposalContract: Address = Address.fromString("0x0000000000000000000000000000000000000001"); + refinancingLoanId: BigInt = BigInt.fromI32(0); + lender: Address = Address.fromString("0x0000000000000000000000000000000000000002"); + borrower: Address = Address.fromString("0x0000000000000000000000000000000000000003"); + duration: BigInt = BigInt.fromI32(30); + createdAt: BigInt = BigInt.fromI32(1234567890); + collateralAssetAddress: Address = Address.fromString("0x0000000000000000000000000000000000000004"); + collateralId: BigInt = BigInt.fromI32(1); + collateralCategory: i32 = 1; + collateralAmount: BigInt = BigInt.fromI32(100); + creditAssetAddress: Address = Address.fromString("0x0000000000000000000000000000000000000005"); + creditId: BigInt = BigInt.fromI32(0); + creditCategory: i32 = 0; + creditAmount: BigInt = BigInt.fromI32(1000); + fixedInterestAmount: BigInt = BigInt.fromI32(50); + accruingInterestAPR: i32 = 1000; + lenderSpecHash: Bytes = Bytes.fromHexString("0x5678"); + borrowerSpecHash: Bytes = Bytes.fromHexString("0x9abc"); + sourceOfFunds: Address = Address.fromString("0x0000000000000000000000000000000000000003"); + extra: Bytes = Bytes.fromHexString("0x1234"); + loanTokenAddress: Address = Address.fromString("0x0000000000000000000000000000000000000006"); + loanContractAddress: Address = Address.fromString("0x0000000000000000000000000000000000000007"); + loanType: string = "SimpleLoan"; +} + +export function createTestLoan(loanId: BigInt, params: TestLoanParams | null = null): Loan { + // Use default params if none provided + const p = params ? params : new TestLoanParams(); + + const createEvent = createLOANCreatedEvent( + loanId, + p.proposalHash, + p.proposalContract, + p.refinancingLoanId, + p.lender, + p.borrower, + p.duration, + p.createdAt, + p.collateralAssetAddress, + p.collateralId, + p.collateralCategory, + p.collateralAmount, + p.creditAssetAddress, + p.creditId, + p.creditCategory, + p.creditAmount, + p.fixedInterestAmount, + p.accruingInterestAPR, + p.lenderSpecHash, + p.borrowerSpecHash, + p.sourceOfFunds, + p.extra, + p.loanContractAddress, + ); + + createMockedFunction(p.loanContractAddress, 'loanToken', 'loanToken():(address)') + .returns([ethereum.Value.fromAddress(p.loanTokenAddress)]) + + handleLOANCreated(createEvent); + const loan = new Loan(getLoanId(p.loanContractAddress, loanId)); + return loan; +} + +export function createLOANCreatedEvent( + loanId: BigInt, + proposalHash: Bytes, + proposalContract: Address, + refinancingLoanId: BigInt, + lender: Address, + borrower: Address, + duration: BigInt, + createdAt: BigInt, + collateralAssetAddress: Address, + collateralId: BigInt, + collateralCategory: i32, + collateralAmount: BigInt, + creditAssetAddress: Address, + creditId: BigInt, + creditCategory: i32, + creditAmount: BigInt, + fixedInterestAmount: BigInt, + accruingInterestAPR: i32, + lenderSpecHash: Bytes, + borrowerSpecHash: Bytes, + sourceOfFunds: Address, + extra: Bytes, + loanContractAddress: Address +): LOANCreated { + let event = changetype(newMockEvent()) + + event.parameters = new Array() + + event.parameters.push( + new ethereum.EventParam("loanId", ethereum.Value.fromUnsignedBigInt(loanId)) + ) + event.parameters.push( + new ethereum.EventParam("proposalHash", ethereum.Value.fromBytes(proposalHash)) + ) + event.parameters.push( + new ethereum.EventParam("proposalContract", ethereum.Value.fromAddress(proposalContract)) + ) + event.parameters.push( + new ethereum.EventParam("refinancingLoanId", ethereum.Value.fromUnsignedBigInt(refinancingLoanId)) + ) + event.parameters.push( + new ethereum.EventParam("terms", ethereum.Value.fromTuple(createTermsTuple( + lender, + borrower, + duration, + collateralAssetAddress, + collateralId, + collateralCategory, + collateralAmount, + creditAssetAddress, + creditId, + creditCategory, + creditAmount, + fixedInterestAmount, + accruingInterestAPR, + lenderSpecHash, + borrowerSpecHash + ))) + ) + event.parameters.push( + new ethereum.EventParam("lenderSpec", ethereum.Value.fromTuple(createLenderSpecTuple( + sourceOfFunds + ))) + ) + event.parameters.push( + new ethereum.EventParam("extra", ethereum.Value.fromBytes(extra)) + ) + + event.block.timestamp = createdAt + + event.address = loanContractAddress + + return event +} + +function createTermsTuple( + lender: Address, + borrower: Address, + duration: BigInt, + collateralAssetAddress: Address, + collateralId: BigInt, + collateralCategory: i32, + collateralAmount: BigInt, + creditAssetAddress: Address, + creditId: BigInt, + creditCategory: i32, + creditAmount: BigInt, + fixedInterestAmount: BigInt, + accruingInterestAPR: i32, + lenderSpecHash: Bytes, + borrowerSpecHash: Bytes +): ethereum.Tuple { + let tuple = new ethereum.Tuple() + tuple.push(ethereum.Value.fromAddress(lender)) + tuple.push(ethereum.Value.fromAddress(borrower)) + tuple.push(ethereum.Value.fromUnsignedBigInt(duration)) + tuple.push(ethereum.Value.fromTuple(createAssetTuple( + collateralAssetAddress, + collateralId, + collateralCategory, + collateralAmount + ))) + tuple.push(ethereum.Value.fromTuple(createAssetTuple( + creditAssetAddress, + creditId, + creditCategory, + creditAmount + ))) + tuple.push(ethereum.Value.fromUnsignedBigInt(fixedInterestAmount)) + tuple.push(ethereum.Value.fromI32(accruingInterestAPR)) + tuple.push(ethereum.Value.fromBytes(lenderSpecHash)) + tuple.push(ethereum.Value.fromBytes(borrowerSpecHash)) + return tuple +} + +function createAssetTuple( + assetAddress: Address, + id: BigInt, + category: i32, + amount: BigInt +): ethereum.Tuple { + let tuple = new ethereum.Tuple() + tuple.push(ethereum.Value.fromI32(category)) + tuple.push(ethereum.Value.fromAddress(assetAddress)) + tuple.push(ethereum.Value.fromUnsignedBigInt(id)) + tuple.push(ethereum.Value.fromUnsignedBigInt(amount)) + return tuple +} + +function createLenderSpecTuple( + sourceOfFunds: Address +): ethereum.Tuple { + let tuple = new ethereum.Tuple() + tuple.push(ethereum.Value.fromAddress(sourceOfFunds)) + return tuple +} + +export function createLOANClaimedEvent( + loanId: BigInt, + defaulted: boolean, + loanContractAddress: Address +): LOANClaimed { + let event = changetype(newMockEvent()) + + event.parameters = new Array() + + event.parameters.push( + new ethereum.EventParam("loanId", ethereum.Value.fromUnsignedBigInt(loanId)) + ) + event.parameters.push( + new ethereum.EventParam("defaulted", ethereum.Value.fromBoolean(defaulted)) + ) + + // Mock the loanToken() call + event.address = loanContractAddress + + return event +} + +export function createLOANExtendedEvent( + loanId: BigInt, + originalDefaultTimestamp: BigInt, + extendedDefaultTimestamp: BigInt, + loanTokenAddress: Address +): LOANExtended { + let event = changetype(newMockEvent()) + + event.parameters = new Array() + + event.parameters.push( + new ethereum.EventParam("loanId", ethereum.Value.fromUnsignedBigInt(loanId)) + ) + event.parameters.push( + new ethereum.EventParam("originalDefaultTimestamp", ethereum.Value.fromUnsignedBigInt(originalDefaultTimestamp)) + ) + event.parameters.push( + new ethereum.EventParam("extendedDefaultTimestamp", ethereum.Value.fromUnsignedBigInt(extendedDefaultTimestamp)) + ) + + // Mock the loanToken() call + event.address = loanTokenAddress + + return event +} + +export function createExtensionProposalMadeEvent( + extensionHash: Bytes, + proposer: Address, + loanId: BigInt, + compensationAddress: Address, + compensationAmount: BigInt, + duration: BigInt, + expiration: BigInt, + nonceSpace: BigInt, + nonce: BigInt, + loanTokenAddress: Address +): ExtensionProposalMade { + let event = changetype(newMockEvent()) + + event.parameters = new Array() + + event.parameters.push( + new ethereum.EventParam("extensionHash", ethereum.Value.fromBytes(extensionHash)) + ) + event.parameters.push( + new ethereum.EventParam("proposer", ethereum.Value.fromAddress(proposer)) + ) + event.parameters.push( + new ethereum.EventParam("proposal", ethereum.Value.fromTuple(createExtensionProposalTuple( + loanId, + compensationAddress, + compensationAmount, + duration, + expiration, + proposer, + nonceSpace, + nonce + ))) + ) + + // Mock the loanToken() call + event.address = loanTokenAddress + + return event +} + +function createExtensionProposalTuple( + loanId: BigInt, + compensationAddress: Address, + compensationAmount: BigInt, + duration: BigInt, + expiration: BigInt, + proposer: Address, + nonceSpace: BigInt, + nonce: BigInt +): ethereum.Tuple { + let tuple = new ethereum.Tuple() + tuple.push(ethereum.Value.fromUnsignedBigInt(loanId)) + tuple.push(ethereum.Value.fromAddress(compensationAddress)) + tuple.push(ethereum.Value.fromUnsignedBigInt(compensationAmount)) + tuple.push(ethereum.Value.fromUnsignedBigInt(duration)) + tuple.push(ethereum.Value.fromUnsignedBigInt(expiration)) + tuple.push(ethereum.Value.fromAddress(proposer)) + tuple.push(ethereum.Value.fromUnsignedBigInt(nonceSpace)) + tuple.push(ethereum.Value.fromUnsignedBigInt(nonce)) + return tuple +} + + +export function createLOANPaidBackEvent( + loanId: BigInt, + paidBackAt: BigInt, + loanContractAddress: Address + ): LOANPaidBack { + let event = changetype(newMockEvent()) + + event.parameters = new Array() + + event.parameters.push( + new ethereum.EventParam("loanId", ethereum.Value.fromUnsignedBigInt(loanId)) + ) + event.parameters.push( + new ethereum.EventParam("paidBackAt", ethereum.Value.fromUnsignedBigInt(paidBackAt)) + ) + + event.block.timestamp = paidBackAt + + event.address = loanContractAddress + + return event + } + \ No newline at end of file diff --git a/packages/subgraph/tests/simple-loan.test.ts b/packages/subgraph/tests/simple-loan.test.ts new file mode 100644 index 0000000..021baea --- /dev/null +++ b/packages/subgraph/tests/simple-loan.test.ts @@ -0,0 +1,169 @@ +import { assert, describe, test, clearStore, beforeEach, afterEach } from "matchstick-as/assembly/index" +import { Address, BigInt, Bytes } from "@graphprotocol/graph-ts" +import { handleLOANPaidBack, handleLOANClaimed, handleLOANExtended, handleExtensionProposalMade, getLoanId } from "../src/simple-loan" +import { createTestLoan, createLOANPaidBackEvent, createLOANClaimedEvent, createLOANExtendedEvent, createExtensionProposalMadeEvent, TestLoanParams } from "./simple-loan-utils" +import { log } from "matchstick-as/assembly/log" + +describe("SimpleLoan", () => { + beforeEach(() => { + clearStore() + }) + + afterEach(() => { + clearStore() + }) + + test("handleLOANCreated - creates a new Loan entity", () => { + const loanId = BigInt.fromI32(1) + const loanTokenAddress = Address.fromString("0x0000000000000000000000000000000000000006") + const loanContractAddress = Address.fromString("0x0000000000000000000000000000000000000007") + + // Create test parameters with explicit values we want to test + const params = new TestLoanParams() + params.proposalHash = Bytes.fromHexString("0x1234") + params.lender = Address.fromString("0x0000000000000000000000000000000000000002") + params.borrower = Address.fromString("0x0000000000000000000000000000000000000003") + params.duration = BigInt.fromI32(30) + params.createdAt = BigInt.fromI32(1234567890) + params.loanContractAddress = loanContractAddress + params.loanTokenAddress = loanTokenAddress + + const loan = createTestLoan(loanId, params) + + const loanEntityId = getLoanId(loanContractAddress, loanId).toHexString() + assert.entityCount("Loan", 1) + assert.fieldEquals("Loan", loanEntityId, "loanId", loanId.toString()) + assert.fieldEquals("Loan", loanEntityId, "proposalHash", params.proposalHash.toHexString()) + assert.fieldEquals("Loan", loanEntityId, "originalLender", params.lender.toHexString()) + assert.fieldEquals("Loan", loanEntityId, "borrower", params.borrower.toHexString()) + assert.fieldEquals("Loan", loanEntityId, "duration", params.duration.toString()) + assert.fieldEquals("Loan", loanEntityId, "createdAt", params.createdAt.toString()) + assert.fieldEquals("Loan", loanEntityId, "status", "Active") + assert.fieldEquals("Loan", loanEntityId, "loanTokenAddress", loanTokenAddress.toHexString()) + assert.fieldEquals("Loan", loanEntityId, "loanType", "SimpleLoan") + }) + + test("handleLOANPaidBack - updates Loan status to Repaid", () => { + const loanId = BigInt.fromI32(1) + + // Create test parameters with explicit values + const params = new TestLoanParams() + params.createdAt = BigInt.fromI32(1234567890) + + // Create the loan + createTestLoan(loanId, params) + + // Then pay it back + const paidBackAt = BigInt.fromI32(1234567891) + const payBackEvent = createLOANPaidBackEvent(loanId, paidBackAt, params.loanContractAddress) + handleLOANPaidBack(payBackEvent) + + const loanIdBytes = params.loanContractAddress.concat(Bytes.fromByteArray(Bytes.fromBigInt(loanId))) + assert.fieldEquals("Loan", loanIdBytes.toHexString(), "status", "Repaid") + assert.fieldEquals("Loan", loanIdBytes.toHexString(), "repaidAt", paidBackAt.toString()) + }) + + test("handleLOANClaimed - updates Loan status to Claimed", () => { + const loanId = BigInt.fromI32(1) + + // Create test parameters with explicit values + const params = new TestLoanParams() + params.createdAt = BigInt.fromI32(1234567890) + + // Create the loan + createTestLoan(loanId, params) + + // Then claim it + const defaulted = true + const claimEvent = createLOANClaimedEvent(loanId, defaulted, params.loanContractAddress) + handleLOANClaimed(claimEvent) + + const loanEntityId = getLoanId(params.loanContractAddress, loanId).toHexString() + + assert.fieldEquals("Loan", loanEntityId, "status", "Claimed") + assert.fieldEquals("Loan", loanEntityId, "hasDefaulted", defaulted.toString()) + }) + + test("handleLOANExtended - extends loan duration and updates default date", () => { + const loanId = BigInt.fromI32(1) + const loanContractAddress = Address.fromString("0x0000000000000000000000000000000000000006") + + // Create test parameters with explicit values + const params = new TestLoanParams() + params.createdAt = BigInt.fromI32(1234567890) + params.duration = BigInt.fromI32(30) + params.loanContractAddress = loanContractAddress + + // Create the loan + createTestLoan(loanId, params) + + // Then extend it + const originalDefaultTimestamp = params.createdAt.plus(params.duration) // createdAt + duration + const extendedDefaultTimestamp = originalDefaultTimestamp.plus(BigInt.fromI32(30)) // originalDefaultTimestamp + 30 + const extendEvent = createLOANExtendedEvent( + loanId, + originalDefaultTimestamp, + extendedDefaultTimestamp, + loanContractAddress + ) + handleLOANExtended(extendEvent) + + const loanEntityId = getLoanId(loanContractAddress, loanId).toHexString() + assert.fieldEquals("Loan", loanEntityId, "defaultDate", extendedDefaultTimestamp.toString()) + + assert.entityCount("LoanExtendedEvent", 1) + const eventId = extendEvent.transaction.hash.concatI32(extendEvent.logIndex.toI32()) + assert.fieldEquals("LoanExtendedEvent", eventId.toHexString(), "loanId", loanId.toString()) + assert.fieldEquals("LoanExtendedEvent", eventId.toHexString(), "originalDefaultTimestamp", originalDefaultTimestamp.toString()) + assert.fieldEquals("LoanExtendedEvent", eventId.toHexString(), "extendedDefaultTimestamp", extendedDefaultTimestamp.toString()) + }) + + test("handleExtensionProposalMade - creates a new ExtensionProposal entity", () => { + const loanId = BigInt.fromI32(1) + const loanContractAddress = Address.fromString("0x0000000000000000000000000000000000000006") + + // Create test parameters with explicit values + const params = new TestLoanParams() + params.createdAt = BigInt.fromI32(1234567890) + params.loanContractAddress = loanContractAddress + + // Create the loan + createTestLoan(loanId, params) + + // Then create an extension proposal + const extensionHash = Bytes.fromHexString("0xabcd") + const proposer = Address.fromString("0x0000000000000000000000000000000000000008") + const compensationAddress = Address.fromString("0x0000000000000000000000000000000000000009") + const compensationAmount = BigInt.fromI32(100) + const duration = BigInt.fromI32(30) + const expiration = BigInt.fromI32(1234567899) + const nonceSpace = BigInt.fromI32(1) + const nonce = BigInt.fromI32(1) + + const proposalEvent = createExtensionProposalMadeEvent( + extensionHash, + proposer, + loanId, + compensationAddress, + compensationAmount, + duration, + expiration, + nonceSpace, + nonce, + loanContractAddress + ) + handleExtensionProposalMade(proposalEvent) + + const loanEntityId = getLoanId(loanContractAddress, loanId).toHexString() + const proposalId = extensionHash.toHexString() + assert.entityCount("ExtensionProposal", 1) + assert.fieldEquals("ExtensionProposal", proposalId, "loan", loanEntityId) + assert.fieldEquals("ExtensionProposal", proposalId, "proposer", proposer.toHexString()) + assert.fieldEquals("ExtensionProposal", proposalId, "compensationAssetAddress", compensationAddress.toHexString()) + assert.fieldEquals("ExtensionProposal", proposalId, "compensationAmount", compensationAmount.toString()) + assert.fieldEquals("ExtensionProposal", proposalId, "durationToExtend", duration.toString()) + assert.fieldEquals("ExtensionProposal", proposalId, "proposalExpiration", expiration.toString()) + assert.fieldEquals("ExtensionProposal", proposalId, "nonceSpace", nonceSpace.toString()) + assert.fieldEquals("ExtensionProposal", proposalId, "nonce", nonce.toString()) + }) +}) \ No newline at end of file diff --git a/packages/subgraph/tsconfig.json b/packages/subgraph/tsconfig.json new file mode 100644 index 0000000..8aaf8a0 --- /dev/null +++ b/packages/subgraph/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", + "include": ["src", "tests"], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ], + "compilerOptions": { + "module": "esnext", + "moduleResolution": "bundler" + } +} diff --git a/packages/subgraph/tsconfig.lib.json b/packages/subgraph/tsconfig.lib.json new file mode 100644 index 0000000..cb74d04 --- /dev/null +++ b/packages/subgraph/tsconfig.lib.json @@ -0,0 +1,30 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "baseUrl": ".", + "outDir": "dist", + "tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo", + "emitDeclarationOnly": true, + "forceConsistentCasingInFileNames": true, + "allowImportingTsExtensions": true, + "types": ["node", "vite/client"], + "module": "esnext", + "moduleResolution": "bundler" + }, + "include": ["src/**/*.ts", "generated/**/*.ts"], + "references": [], + "exclude": [ + "vite.config.ts", + "vite.config.mts", + "vitest.config.ts", + "vitest.config.mts", + "src/**/*.test.ts", + "src/**/*.spec.ts", + "src/**/*.test.tsx", + "src/**/*.spec.tsx", + "src/**/*.test.js", + "src/**/*.spec.js", + "src/**/*.test.jsx", + "src/**/*.spec.jsx" + ] +} diff --git a/packages/subgraph/tsconfig.spec.json b/packages/subgraph/tsconfig.spec.json new file mode 100644 index 0000000..4b76c95 --- /dev/null +++ b/packages/subgraph/tsconfig.spec.json @@ -0,0 +1,36 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./out-tsc/vitest", + "types": [ + "vitest/globals", + "vitest/importMeta", + "vite/client", + "node", + "vitest" + ], + "forceConsistentCasingInFileNames": true, + "module": "esnext", + "moduleResolution": "bundler" + }, + "include": [ + "vite.config.ts", + "vite.config.mts", + "vitest.config.ts", + "vitest.config.mts", + "src/**/*.test.ts", + "src/**/*.spec.ts", + "src/**/*.test.tsx", + "src/**/*.spec.tsx", + "src/**/*.test.js", + "src/**/*.spec.js", + "src/**/*.test.jsx", + "src/**/*.spec.jsx", + "src/**/*.d.ts" + ], + "references": [ + { + "path": "./tsconfig.lib.json" + } + ] +} diff --git a/packages/v1-core/src/contracts/chain-link-proposal-contract.ts b/packages/v1-core/src/contracts/chain-link-proposal-contract.ts index d88d3c2..9a43265 100644 --- a/packages/v1-core/src/contracts/chain-link-proposal-contract.ts +++ b/packages/v1-core/src/contracts/chain-link-proposal-contract.ts @@ -1,5 +1,5 @@ import { getChainLinkProposalContractAddress } from "@pwndao/sdk-core"; -import { getAccount, readContract } from "@wagmi/core"; +import { getAccount } from "@wagmi/core"; import type { Hex } from "viem"; import type { Address } from "viem"; import type { IServerAPI } from "../factories/types.js"; diff --git a/packages/v1-core/src/contracts/elastic-proposal-contract.ts b/packages/v1-core/src/contracts/elastic-proposal-contract.ts index 8c5ebda..ebebc95 100644 --- a/packages/v1-core/src/contracts/elastic-proposal-contract.ts +++ b/packages/v1-core/src/contracts/elastic-proposal-contract.ts @@ -1,7 +1,5 @@ -import { - getElasticProposalContractAddress, -} from "@pwndao/sdk-core"; -import { getAccount, readContract } from "@wagmi/core"; +import { getElasticProposalContractAddress } from "@pwndao/sdk-core"; +import { getAccount } from "@wagmi/core"; import type { Hex } from "viem"; import type { Address } from "viem"; import {