Predictoor support (#678)

* first cut, still WIP

* use specific contracts image

* fix missing abi

* more predictoor

* more predictoor

* done predictoor logic

* fix

* update

* merge #682

* update ready logic

* fixes

* lint

* increase timeout

* add oasis-saphire-testnet

* bump to contracts v2.0.0-next.2

* add loop for crappy rpc

* merge template

* fixes 1

* fixes

* fix predictor detection

* Use latest predictoor contracts (#708)

* Update tests.yml

* Update handlers

* Update schema

* Linter

* Update abi and fields

* use latest contracts

* use latest contracts

* expose agg preds in trueval

* fix abi path

* remove unused abis

* fix

---------

Co-authored-by: trizin <25263018+trizin@users.noreply.github.com>

* bump contracts

* Remove floatValue from predictoor trueval handler  (#714)

* Update predictSlot status on trueval submit (#716)

* Update status

* Fix

* Update contracts version

* Use number for predict slot

* Fixes

* Linter

* Fix

* Fix

* tostring

* Fix

* Fix

* Fix

* use contracts v2.0.0-next.11

* use latest graph-cli

* remove --debug flag

* Feature/add predictoor pause event (#723)

* bump contracts

* add pause for predictoorContract

* bump contracts to v2.0.0-13

* bum contracts & add sapphire mainnet

* fix lock

---------

Co-authored-by: trizin <25263018+trizin@users.noreply.github.com>
This commit is contained in:
Alex Coseru 2023-11-21 15:55:49 +02:00 committed by GitHub
parent 87e42fd6ce
commit c6004336ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 31952 additions and 1856 deletions

View File

@ -52,7 +52,7 @@ jobs:
run: |
bash -x start_ocean.sh --with-thegraph --skip-subgraph-deploy --no-dashboard 2>&1 > start_ocean.log &
env:
CONTRACTS_VERSION: v1.1.7
CONTRACTS_VERSION: predictoor3
- run: npm ci
@ -74,6 +74,6 @@ jobs:
env:
ADDRESS_FILE: /home/runner/.ocean/ocean-contracts/artifacts/address.json
BARGE_FOLDER: /home/runner/.ocean/
- name: docker logs
- name: docker logs
run: docker logs ocean_graph-node_1
if: ${{ failure() }}

View File

@ -1,422 +0,0 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "ERC721RolesAddress",
"sourceName": "contracts/utils/ERC721RolesAddress.sol",
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "signer",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "blockNumber",
"type": "uint256"
}
],
"name": "AddedManager",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "signer",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "blockNumber",
"type": "uint256"
}
],
"name": "AddedTo725StoreList",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "signer",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "blockNumber",
"type": "uint256"
}
],
"name": "AddedToCreateERC20List",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "signer",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "blockNumber",
"type": "uint256"
}
],
"name": "AddedToMetadataList",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "signer",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "blockNumber",
"type": "uint256"
}
],
"name": "CleanedPermissions",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "signer",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "blockNumber",
"type": "uint256"
}
],
"name": "RemovedFrom725StoreList",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "signer",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "blockNumber",
"type": "uint256"
}
],
"name": "RemovedFromCreateERC20List",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "signer",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "blockNumber",
"type": "uint256"
}
],
"name": "RemovedFromMetadataList",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "signer",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "blockNumber",
"type": "uint256"
}
],
"name": "RemovedManager",
"type": "event"
},
{
"inputs": [
{
"internalType": "address",
"name": "_allowedAddress",
"type": "address"
}
],
"name": "addTo725StoreList",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_allowedAddress",
"type": "address"
}
],
"name": "addToCreateERC20List",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_allowedAddress",
"type": "address"
}
],
"name": "addToMetadataList",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "auth",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "user",
"type": "address"
}
],
"name": "getPermissions",
"outputs": [
{
"components": [
{
"internalType": "bool",
"name": "manager",
"type": "bool"
},
{
"internalType": "bool",
"name": "deployERC20",
"type": "bool"
},
{
"internalType": "bool",
"name": "updateMetadata",
"type": "bool"
},
{
"internalType": "bool",
"name": "store",
"type": "bool"
}
],
"internalType": "struct ERC721RolesAddress.Roles",
"name": "",
"type": "tuple"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_allowedAddress",
"type": "address"
}
],
"name": "removeFrom725StoreList",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_allowedAddress",
"type": "address"
}
],
"name": "removeFromCreateERC20List",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_allowedAddress",
"type": "address"
}
],
"name": "removeFromMetadataList",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x608060405234801561001057600080fd5b5061090f806100206000396000f3fe608060405234801561001057600080fd5b50600436106100885760003560e01c8063431053ac1161005b578063431053ac1461019f5780634a63740a146101b2578063b0c41ead146101c5578063fe1ec880146101f057600080fd5b806310c558bf1461008d578063160a7925146100a257806319c186e514610179578063273e06b31461018c575b600080fd5b6100a061009b366004610859565b610203565b005b6101356100b0366004610859565b604080516080810182526000808252602082018190529181018290526060810191909152506001600160a01b0316600090815260208181526040918290208251608081018452905460ff808216151583526101008204811615159383019390935262010000810483161515938201939093526301000000909204161515606082015290565b604051610170919081511515815260208083015115159082015260408083015115159082015260609182015115159181019190915260800190565b60405180910390f35b6100a0610187366004610859565b6102f0565b6100a061019a366004610859565b6103ca565b6100a06101ad366004610859565b6104fc565b6100a06101c0366004610859565b61062d565b6101d86101d3366004610889565b610703565b6040516001600160a01b039091168152602001610170565b6100a06101fe366004610859565b61072d565b3360009081526020819052604090205460ff1615156001146102405760405162461bcd60e51b8152600401610237906108a2565b60405180910390fd5b6001600160a01b038116600081815260208190526040808220805462ff000019166201000017815560018054808201825593527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf690920180546001600160a01b0319168417905551909133917fc2a42571a74ce1442c8c44d375ba9442e7d55d94b37afeace261c83c62128fa4906102e49042904390918252602082015260400190565b60405180910390a35050565b3360009081526020819052604090205460ff1615156001146103245760405162461bcd60e51b8152600401610237906108a2565b6001600160a01b038116600081815260208190526040808220805463ff0000001916630100000017815560018054808201825593527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf690920180546001600160a01b0319168417905551909133917feb09276310ed110a7e565d64966d0ff68a47112d2dd5eeb6cbd7451836ce35ee906102e49042904390918252602082015260400190565b3360009081526020819052604090205460ff1615156001148061041b5750336001600160a01b03821614801561041b5750336000908152602081905260409020546301000000900460ff1615156001145b1561047f576001600160a01b03811660008181526020818152604091829020805463ff000000191681558251428152439281019290925292339290917fc929b18b08ffea86a1f95e29384dbe8968f2fcbd70cfd735df3aba1cc548cbf391016102e4565b60405162461bcd60e51b815260206004820152604660248201527f455243373231526f6c6573416464726573733a204e6f7420656e6f756768207060448201527f65726d697373696f6e7320746f2072656d6f76652066726f6d2037323553746f6064820152651c99531a5cdd60d21b608482015260a401610237565b3360009081526020819052604090205460ff1615156001148061054c5750336001600160a01b03821614801561054c57503360009081526020819052604090205462010000900460ff1615156001145b156105af576001600160a01b03811660008181526020818152604091829020805462ff0000191681558251428152439281019290925292339290917f9b41e1311fa819e825bc77fa2568492112e15ea92d173f3f8ee1c8ec3c1c562b91016102e4565b60405162461bcd60e51b815260206004820152604760248201527f455243373231526f6c6573416464726573733a204e6f7420656e6f756768207060448201527f65726d697373696f6e7320746f2072656d6f76652066726f6d206d65746164616064820152661d18481b1a5cdd60ca1b608482015260a401610237565b3360009081526020819052604090205460ff1615156001146106615760405162461bcd60e51b8152600401610237906108a2565b6001600160a01b038116600081815260208190526040808220805461ff00191661010017815560018054808201825593527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf690920180546001600160a01b0319168417905551909133917f0572d56343be407a66810f01449212e8545e14ff5049c479d34be944cdfd0d4f906102e49042904390918252602082015260400190565b6001818154811061071357600080fd5b6000918252602090912001546001600160a01b0316905081565b3360009081526020819052604090205460ff1615156001148061077d5750336001600160a01b03821614801561077d57503360009081526020819052604090205460ff6101009091041615156001145b156107df576001600160a01b03811660008181526020818152604091829020805461ff00191681558251428152439281019290925292339290917f59bd33f4c27cc16a2d74450e1fa43d7896020be9aecea4bee009db9294de899791016102e4565b60405162461bcd60e51b815260206004820152604360248201527f455243373231526f6c6573416464726573733a204e6f7420656e6f756768207060448201527f65726d697373696f6e7320746f2072656d6f76652066726f6d2045524332304c6064820152621a5cdd60ea1b608482015260a401610237565b60006020828403121561086b57600080fd5b81356001600160a01b038116811461088257600080fd5b9392505050565b60006020828403121561089b57600080fd5b5035919050565b6020808252601f908201527f455243373231526f6c6573416464726573733a204e4f54204d414e414745520060408201526060019056fea2646970667358221220cabd9a0cec3e45ffba59a95bb3ddc1d19aa1c82a0724b54aabff16b67c302d2c64736f6c634300080a0033",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100885760003560e01c8063431053ac1161005b578063431053ac1461019f5780634a63740a146101b2578063b0c41ead146101c5578063fe1ec880146101f057600080fd5b806310c558bf1461008d578063160a7925146100a257806319c186e514610179578063273e06b31461018c575b600080fd5b6100a061009b366004610859565b610203565b005b6101356100b0366004610859565b604080516080810182526000808252602082018190529181018290526060810191909152506001600160a01b0316600090815260208181526040918290208251608081018452905460ff808216151583526101008204811615159383019390935262010000810483161515938201939093526301000000909204161515606082015290565b604051610170919081511515815260208083015115159082015260408083015115159082015260609182015115159181019190915260800190565b60405180910390f35b6100a0610187366004610859565b6102f0565b6100a061019a366004610859565b6103ca565b6100a06101ad366004610859565b6104fc565b6100a06101c0366004610859565b61062d565b6101d86101d3366004610889565b610703565b6040516001600160a01b039091168152602001610170565b6100a06101fe366004610859565b61072d565b3360009081526020819052604090205460ff1615156001146102405760405162461bcd60e51b8152600401610237906108a2565b60405180910390fd5b6001600160a01b038116600081815260208190526040808220805462ff000019166201000017815560018054808201825593527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf690920180546001600160a01b0319168417905551909133917fc2a42571a74ce1442c8c44d375ba9442e7d55d94b37afeace261c83c62128fa4906102e49042904390918252602082015260400190565b60405180910390a35050565b3360009081526020819052604090205460ff1615156001146103245760405162461bcd60e51b8152600401610237906108a2565b6001600160a01b038116600081815260208190526040808220805463ff0000001916630100000017815560018054808201825593527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf690920180546001600160a01b0319168417905551909133917feb09276310ed110a7e565d64966d0ff68a47112d2dd5eeb6cbd7451836ce35ee906102e49042904390918252602082015260400190565b3360009081526020819052604090205460ff1615156001148061041b5750336001600160a01b03821614801561041b5750336000908152602081905260409020546301000000900460ff1615156001145b1561047f576001600160a01b03811660008181526020818152604091829020805463ff000000191681558251428152439281019290925292339290917fc929b18b08ffea86a1f95e29384dbe8968f2fcbd70cfd735df3aba1cc548cbf391016102e4565b60405162461bcd60e51b815260206004820152604660248201527f455243373231526f6c6573416464726573733a204e6f7420656e6f756768207060448201527f65726d697373696f6e7320746f2072656d6f76652066726f6d2037323553746f6064820152651c99531a5cdd60d21b608482015260a401610237565b3360009081526020819052604090205460ff1615156001148061054c5750336001600160a01b03821614801561054c57503360009081526020819052604090205462010000900460ff1615156001145b156105af576001600160a01b03811660008181526020818152604091829020805462ff0000191681558251428152439281019290925292339290917f9b41e1311fa819e825bc77fa2568492112e15ea92d173f3f8ee1c8ec3c1c562b91016102e4565b60405162461bcd60e51b815260206004820152604760248201527f455243373231526f6c6573416464726573733a204e6f7420656e6f756768207060448201527f65726d697373696f6e7320746f2072656d6f76652066726f6d206d65746164616064820152661d18481b1a5cdd60ca1b608482015260a401610237565b3360009081526020819052604090205460ff1615156001146106615760405162461bcd60e51b8152600401610237906108a2565b6001600160a01b038116600081815260208190526040808220805461ff00191661010017815560018054808201825593527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf690920180546001600160a01b0319168417905551909133917f0572d56343be407a66810f01449212e8545e14ff5049c479d34be944cdfd0d4f906102e49042904390918252602082015260400190565b6001818154811061071357600080fd5b6000918252602090912001546001600160a01b0316905081565b3360009081526020819052604090205460ff1615156001148061077d5750336001600160a01b03821614801561077d57503360009081526020819052604090205460ff6101009091041615156001145b156107df576001600160a01b03811660008181526020818152604091829020805461ff00191681558251428152439281019290925292339290917f59bd33f4c27cc16a2d74450e1fa43d7896020be9aecea4bee009db9294de899791016102e4565b60405162461bcd60e51b815260206004820152604360248201527f455243373231526f6c6573416464726573733a204e6f7420656e6f756768207060448201527f65726d697373696f6e7320746f2072656d6f76652066726f6d2045524332304c6064820152621a5cdd60ea1b608482015260a401610237565b60006020828403121561086b57600080fd5b81356001600160a01b038116811461088257600080fd5b9392505050565b60006020828403121561089b57600080fd5b5035919050565b6020808252601f908201527f455243373231526f6c6573416464726573733a204e4f54204d414e414745520060408201526060019056fea2646970667358221220cabd9a0cec3e45ffba59a95bb3ddc1d19aa1c82a0724b54aabff16b67c302d2c64736f6c634300080a0033",
"linkReferences": {},
"deployedLinkReferences": {}
}

View File

@ -6,6 +6,7 @@ echo "deploy subgraph is ${DEPLOY_SUBGRAPH}"
if [ "${DEPLOY_SUBGRAPH}" = "true" ]
then
rm -f /ocean-subgraph/ready
echo "Waiting for contracts to be deployed"
while [ ! -f "/ocean-contracts/artifacts/ready" ]; do
sleep 2
@ -13,5 +14,7 @@ then
export ADDRESS_FILE="/ocean-contracts/artifacts/address.json"
cd /usr/src/app/
npm run quickstart:barge
sleep 3
touch /ocean-subgraph/ready
fi
tail -f /dev/null

View File

@ -17,8 +17,9 @@ services:
postgres_pass: let-me-in
postgres_db: graph-node
ipfs: 'ipfs:5001'
ethereum: 'goerli:https://goerli.infura.io/v3/${INFURA_PROJECT_ID}'
RUST_LOG: info
ethereum: 'oasis_saphire_testnet:http://192.168.136.129:8080'
RUST_LOG: warning
GRAPH_ETHEREUM_MAX_BLOCK_RANGE_SIZE: 100
ipfs:
image: ipfs/go-ipfs:v0.4.23
ports:

32855
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -17,14 +17,16 @@
"quickstart:sepolia": "node ./scripts/generatenetworkssubgraphs.js sepolia && npm run codegen && npm run create:local && npm run deploy:local",
"quickstart:gen-x-testnet": "node ./scripts/generatenetworkssubgraphs.js gen-x-testnet && npm run codegen && npm run create:local && npm run deploy:local",
"quickstart:bsc": "node ./scripts/generatenetworkssubgraphs.js bsc && npm run codegen && npm run create:local && npm run deploy:local",
"quickstart:oasis_saphire_testnet": "node ./scripts/generatenetworkssubgraphs.js oasis_saphire_testnet && npm run codegen && npm run create:local && npm run deploy:local",
"quickstart:oasis_saphire": "node ./scripts/generatenetworkssubgraphs.js oasis_saphire && npm run codegen && npm run create:local && npm run deploy:local",
"create:thegraph": "graph create oceanprotocol/ocean-subgraph --node https://api.thegraph.com/deploy/",
"create:local": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
"create:local-barge": "graph create oceanprotocol/ocean-subgraph --node http://172.15.0.15:8020",
"codegen": "graph codegen --output-dir src/@types",
"build": "graph build",
"deploy:thegraph": "graph deploy oceanprotocol/ocean-subgraph -l $npm_package_version --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/",
"deploy:local": "graph deploy oceanprotocol/ocean-subgraph subgraph.yaml -l $npm_package_version --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020",
"deploy:local-barge": "graph deploy oceanprotocol/ocean-subgraph subgraph.yaml -l $npm_package_version --ipfs http://172.15.0.16:5001 --node http://172.15.0.15:8020",
"deploy:local": "graph deploy oceanprotocol/ocean-subgraph subgraph.yaml -l $npm_package_version --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020",
"deploy:local-barge": "graph deploy oceanprotocol/ocean-subgraph subgraph.yaml -l $npm_package_version --ipfs http://172.15.0.16:5001 --node http://172.15.0.15:8020",
"test": "npm run codegen && npm run lint && npm run type-check",
"test-integration": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/**/*.test.ts'",
"test-dispenser": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/Dispenser.test.ts'",
@ -46,7 +48,8 @@
"changelog": "auto-changelog -p"
},
"devDependencies": {
"@oceanprotocol/lib": "^2.7.0",
"@graphprotocol/graph-cli": "^0.56.0",
"@graphprotocol/graph-ts": "^0.30.0",
"@types/chai": "^4.3.5",
"@types/chai-spies": "^1.0.3",
"@types/mocha": "^10.0.2",
@ -76,9 +79,10 @@
"typescript": "^5.2.2"
},
"dependencies": {
"@graphprotocol/graph-cli": "^0.56.0",
"@graphprotocol/graph-ts": "^0.30.0",
"@oceanprotocol/contracts": "^1.1.14"
"@oceanprotocol/contracts": "^2.0.2",
"@oceanprotocol/lib": "^2.7.0",
"cross-fetch": "^3.1.6",
"ethereumjs-util": "^7.1.5"
},
"repository": {
"type": "git",

View File

@ -30,7 +30,7 @@ type Token @entity {
publishMarketFeeAmount: BigDecimal
"template ID of the datatoken"
templateId: BigInt
templateId: BigInt!
"number of addresses holding a balance of datatoken , TODO: can we actually calculate this? what happens when users trade the dts"
holderCount: BigInt!
@ -98,6 +98,9 @@ type Nft @entity{
"template address"
template: String!
"template ID of the datatoken"
templateId: Int
"set if NFT is transferable"
transferable: Boolean!
@ -644,3 +647,131 @@ type Erc20Template @entity {
}
type PredictSubscription @entity{
"id = {contract address}-{txid}-{eventIndex}"
id: ID!
predictContract: PredictContract!
user: User!
expireTime: BigInt!
"txId"
txId: String
eventIndex:Int!
timestamp: Int!
block: Int!
}
enum PredictSlotStatus {
Pending,
Paying,
Canceled
}
type PredictPayout @entity{
"id = {contract address}-{slot}-{user}"
id: ID!
prediction: PredictPrediction!
payout: BigDecimal!
predictedValue: Boolean!
trueValue: Boolean!
aggregatedPredictedValue: BigDecimal!
"txId"
txId: String
eventIndex:Int!
timestamp: Int!
block: Int!
}
type PredictPrediction @entity{
"id = {contract address}-{slot}-{user}"
id: ID!
slot: PredictSlot!
user: User!
stake: BigDecimal!
payout: PredictPayout
"txId"
txId: String
eventIndex:Int!
timestamp: Int!
block: Int!
}
type PredictTrueVal @entity{
"id = {contract address}-{slot}"
id: ID!
slot: PredictSlot!
trueValue: Boolean!
"txId"
txId: String
eventIndex:Int!
timestamp: Int!
block: Int!
}
type PredictionRevenue @entity{
"id = {contract address}-{slot}-{txid}-{eventIndex}"
id: ID!
slot: PredictSlot!
amount: BigDecimal!
"txId"
txId: String
eventIndex:Int!
timestamp: Int!
block: Int!
}
type PredictSlot @entity{
"id = {contract address}-{slot}"
id: ID!
predictContract: PredictContract!
slot: Int!
predictions:[PredictPrediction!] @derivedFrom(field: "slot")
trueValues: [PredictTrueVal!] @derivedFrom(field: "slot")
revenue: BigDecimal!
revenues: [PredictionRevenue!] @derivedFrom(field: "slot")
status: PredictSlotStatus!
roundSumStakesUp: BigDecimal!
roundSumStakes: BigDecimal!
}
type PredictSettingUpdate @entity{
"id = {contract address}-{txId}-{eventIndex}"
id: ID!
predictContract: PredictContract!
secondsPerEpoch: BigInt!
secondsPerSubscription: BigInt!
truevalSubmitTimeout: BigInt!
stakeToken: Token
"txId"
txId: String
eventIndex:Int!
timestamp: Int!
block: Int!
}
type PredictContract @entity{
"id = {contract address}"
id: ID!
token: Token!
paused: Boolean!
slots: [PredictSlot!] @derivedFrom(field: "predictContract")
settingUpdates: [PredictSettingUpdate!] @derivedFrom(field: "predictContract")
subscriptions: [PredictSubscription!] @derivedFrom(field: "predictContract")
secondsPerEpoch: BigInt!
secondsPerSubscription: BigInt!
truevalSubmitTimeout: BigInt!
stakeToken: Token
"creation txId"
txId: String
"timestamp of creation tx"
timestamp: Int!
"block of creation tx"
block: Int!
eventIndex: Int!
}

View File

@ -0,0 +1,269 @@
import {
PredictSubscription,
PredictPayout,
PredictPrediction,
PredictTrueVal,
PredictSlot,
PredictSettingUpdate,
PredictionRevenue
} from '../@types/schema'
import { BigInt, BigDecimal, Address } from '@graphprotocol/graph-ts'
import {
PredictionSubmitted,
PredictionPayout,
NewSubscription,
TruevalSubmitted,
SettingChanged,
RevenueAdded,
Paused
} from '../@types/templates/ERC20Template3/ERC20Template3'
import { weiToDecimal } from './utils/generic'
import { getPredictContract, getToken } from './utils/tokenUtils'
import { getUser } from './utils/userUtils'
function getPredictSlot(
predictContractAddress: string,
slot: i32
): PredictSlot {
const id = predictContractAddress + '-' + slot.toString()
let newPredictSlot = PredictSlot.load(id)
if (newPredictSlot === null) {
newPredictSlot = new PredictSlot(id)
newPredictSlot.predictContract = predictContractAddress
newPredictSlot.slot = slot
newPredictSlot.revenue = BigDecimal.zero()
newPredictSlot.roundSumStakesUp = BigDecimal.zero()
newPredictSlot.roundSumStakes = BigDecimal.zero()
newPredictSlot.status = 'Pending'
newPredictSlot.save()
}
return newPredictSlot
}
export function handlePredictionSubmitted(event: PredictionSubmitted): void {
const predictSlot = getPredictSlot(
event.address.toHexString(),
event.params.slot.toI32()
)
const user = getUser(event.params.predictoor.toHex())
const id =
event.address.toHexString() +
'-' +
event.params.slot.toString() +
'-' +
user.id
const predictPrediction = new PredictPrediction(id)
predictPrediction.slot = predictSlot.id
predictPrediction.user = user.id
const predictContract = getPredictContract(event.address)
let decimals = 18
if (predictContract.stakeToken) {
const stakeToken = getToken(
Address.fromString(predictContract.stakeToken!),
false
)
decimals = stakeToken.decimals
}
predictPrediction.stake = weiToDecimal(
event.params.stake.toBigDecimal(),
BigInt.fromI32(decimals).toI32()
)
predictPrediction.payout = null
predictPrediction.block = event.block.number.toI32()
predictPrediction.txId = event.transaction.hash.toHexString()
predictPrediction.eventIndex = event.logIndex.toI32()
predictPrediction.timestamp = event.block.timestamp.toI32()
predictPrediction.save()
}
export function handlePredictionPayout(event: PredictionPayout): void {
const user = getUser(event.params.predictoor.toHex())
const predictionId =
event.address.toHexString() +
'-' +
event.params.slot.toString() +
'-' +
user.id
const predictPrediction = PredictPrediction.load(predictionId)
if (!predictPrediction) return
const predictionPayout = new PredictPayout(predictionId)
predictionPayout.prediction = predictPrediction.id
let decimals = 18
const predictContract = getPredictContract(event.address)
if (predictContract.stakeToken) {
const stakeToken = getToken(
Address.fromString(predictContract.stakeToken!),
false
)
decimals = stakeToken.decimals
}
predictionPayout.payout = weiToDecimal(
event.params.payout.toBigDecimal(),
BigInt.fromI32(decimals).toI32()
)
predictionPayout.predictedValue = event.params.predictedValue
predictionPayout.trueValue = event.params.trueValue
predictionPayout.aggregatedPredictedValue = weiToDecimal(
event.params.aggregatedPredictedValue.toBigDecimal(),
18
)
predictionPayout.block = event.block.number.toI32()
predictionPayout.txId = event.transaction.hash.toHexString()
predictionPayout.eventIndex = event.logIndex.toI32()
predictionPayout.timestamp = event.block.timestamp.toI32()
predictionPayout.save()
predictPrediction.payout = predictionPayout.id
predictPrediction.save()
}
export function handleNewSubscription(event: NewSubscription): void {
const id =
event.address.toHexString() +
'-' +
event.transaction.hash.toHexString() +
'-' +
event.logIndex.toString()
const newSubscription = new PredictSubscription(id)
const predictContract = getPredictContract(event.address)
newSubscription.predictContract = predictContract.id
const user = getUser(event.params.user.toHex())
newSubscription.user = user.id
newSubscription.expireTime = event.params.expires
newSubscription.block = event.block.number.toI32()
newSubscription.txId = event.transaction.hash.toHexString()
newSubscription.eventIndex = event.logIndex.toI32()
newSubscription.timestamp = event.block.timestamp.toI32()
newSubscription.save()
}
export function handleTruevalSubmitted(event: TruevalSubmitted): void {
const predictSlot = getPredictSlot(
event.address.toHexString(),
event.params.slot.toI32()
)
const id = event.address.toHexString() + '-' + event.params.slot.toString()
const newPredictTrueVals = new PredictTrueVal(id) // they share the same id
newPredictTrueVals.slot = predictSlot.id
newPredictTrueVals.trueValue = event.params.trueValue
newPredictTrueVals.block = event.block.number.toI32()
newPredictTrueVals.txId = event.transaction.hash.toHexString()
newPredictTrueVals.eventIndex = event.logIndex.toI32()
newPredictTrueVals.timestamp = event.block.timestamp.toI32()
newPredictTrueVals.save()
let decimals = 18
const predictContract = getPredictContract(event.address)
if (predictContract.stakeToken) {
const stakeToken = getToken(
Address.fromString(predictContract.stakeToken!),
false
)
decimals = stakeToken.decimals
}
predictSlot.roundSumStakesUp = weiToDecimal(
event.params.roundSumStakesUp.toBigDecimal(),
BigInt.fromI32(decimals).toI32()
)
predictSlot.roundSumStakes = weiToDecimal(
event.params.roundSumStakes.toBigDecimal(),
BigInt.fromI32(decimals).toI32()
)
if (event.params.status == 1) {
predictSlot.status = 'Paying'
}
if (event.params.status == 2) {
predictSlot.status = 'Canceled'
}
predictSlot.save()
}
export function handleSettingChanged(event: SettingChanged): void {
const predictContract = getPredictContract(event.address)
predictContract.secondsPerEpoch = event.params.secondsPerEpoch
predictContract.secondsPerSubscription = event.params.secondsPerSubscription
predictContract.truevalSubmitTimeout = event.params.trueValueSubmitTimeout
const stakeToken = getToken(event.params.stakeToken, false)
predictContract.stakeToken = stakeToken.id
predictContract.save()
const predictSettingsUpdate = new PredictSettingUpdate(
event.address.toHexString() +
'- ' +
event.transaction.hash.toHexString() +
'-' +
event.logIndex.toHexString()
)
predictSettingsUpdate.block = event.block.number.toI32()
predictSettingsUpdate.txId = event.transaction.hash.toHexString()
predictSettingsUpdate.eventIndex = event.logIndex.toI32()
predictSettingsUpdate.timestamp = event.block.timestamp.toI32()
predictSettingsUpdate.predictContract = predictContract.id
predictSettingsUpdate.secondsPerEpoch = event.params.secondsPerEpoch
predictSettingsUpdate.secondsPerSubscription =
event.params.secondsPerSubscription
predictSettingsUpdate.truevalSubmitTimeout =
event.params.trueValueSubmitTimeout
predictSettingsUpdate.stakeToken = stakeToken.id
predictSettingsUpdate.save()
}
export function handlePaused(event: Paused): void {
const predictContract = getPredictContract(event.address)
predictContract.paused = event.params.paused
predictContract.save()
}
export function handleRevenueAdded(event: RevenueAdded): void {
/*
for (uint256 i = 0; i < num_epochs; i++) {
subscriptionRevenueAtBlock[
slot + secondsPerEpoch * (i)
] += amt_per_epoch;
}
emit RevenueAdded(amount,slot,amt_per_epoch,num_epochs,secondsPerEpoch);
*/
const numEpochs = event.params.numEpochs
const secondsPerEpoch = event.params.secondsPerEpoch
let decimals = 18
const predictContract = getPredictContract(event.address)
if (predictContract.stakeToken) {
const stakeToken = getToken(
Address.fromString(predictContract.stakeToken!),
false
)
decimals = stakeToken.decimals
}
const amountPerEpoch = weiToDecimal(
event.params.amountPerEpoch.toBigDecimal(),
BigInt.fromI32(decimals).toI32()
)
const slot = event.params.slot
for (let i = BigInt.zero(); i.lt(numEpochs); i = i.plus(BigInt.fromI32(1))) {
const targetSlot = slot.plus(secondsPerEpoch.times(i))
const predictSlot = getPredictSlot(
event.address.toHexString(),
targetSlot.toI32()
)
predictSlot.revenue = predictSlot.revenue.plus(amountPerEpoch)
predictSlot.save()
const revenueId =
event.address.toHexString() +
'-' +
targetSlot.toString() +
'-' +
event.transaction.hash.toHexString() +
'-' +
event.logIndex.toHexString()
const predictRevenue = new PredictionRevenue(revenueId)
predictRevenue.slot = predictSlot.id
predictRevenue.amount = amountPerEpoch
predictRevenue.block = event.block.number.toI32()
predictRevenue.txId = event.transaction.hash.toHexString()
predictRevenue.eventIndex = event.logIndex.toI32()
predictRevenue.timestamp = event.block.timestamp.toI32()
predictRevenue.save()
}
}

View File

@ -7,9 +7,17 @@ import {
import { Erc721Template, Erc20Template } from '../@types/schema'
import { decimal } from './utils/constants'
import { weiToDecimal } from './utils/generic'
import {
ERC20Template as factoryERC20Template,
ERC20Template3 as factoryERC20Template3
} from '../@types/templates'
import { getUser } from './utils/userUtils'
import { getToken, getNftToken, getErc20TemplateId } from './utils/tokenUtils'
import {
getToken,
getNftToken,
getErc20TemplateId,
getPredictContract
} from './utils/tokenUtils'
import { addDatatoken } from './utils/globalUtils'
export function handleNftCreated(event: NFTCreated): void {
@ -29,7 +37,6 @@ export function handleNftCreated(event: NFTCreated): void {
nft.eventIndex = event.logIndex.toI32()
nft.transferable = event.params.transferable
nft.template = event.params.templateAddress.toHexString()
nft.save()
}
@ -54,6 +61,16 @@ export function handleNewToken(event: TokenCreated): void {
token.templateId = getErc20TemplateId(event.params.templateAddress)
token.save()
addDatatoken()
if (token.templateId.toString() == '3') {
factoryERC20Template3.create(event.params.newTokenAddress)
const predictContract = getPredictContract(event.params.newTokenAddress)
predictContract.timestamp = event.block.timestamp.toI32()
predictContract.txId = event.transaction.hash.toHex()
predictContract.block = event.block.number.toI32()
predictContract.eventIndex = event.logIndex.toI32()
predictContract.save()
}
factoryERC20Template.create(event.params.newTokenAddress)
}
export function handleNew721Template(event: Template721Added): void {

View File

@ -1,15 +1,18 @@
import { Address, log, BigDecimal, BigInt } from '@graphprotocol/graph-ts'
import { Nft, Token, Erc721Template, Erc20Template } from '../../@types/schema'
import {
Nft,
Token,
PredictContract,
Erc721Template,
Erc20Template
} from '../../@types/schema'
import { ERC20 } from '../../@types/templates/ERC20Template/ERC20'
import { ERC20Template, ERC721Template } from '../../@types/templates'
import { ERC721Template } from '../../@types/templates'
import { addNft } from './globalUtils'
import { ZERO_ADDRESS } from './constants'
export function createToken(address: Address, isDatatoken: boolean): Token {
log.debug('started creating token with address: {}', [address.toHexString()])
if (isDatatoken) {
ERC20Template.create(address)
}
const token = new Token(address.toHexString())
const contract = ERC20.bind(address)
const name = contract.try_name()
@ -31,6 +34,7 @@ export function createToken(address: Address, isDatatoken: boolean): Token {
token.block = 0
token.tx = ''
token.eventIndex = 0
token.templateId = BigInt.zero()
token.save()
return token
}
@ -125,3 +129,28 @@ export function getErc20TemplateId(address: Address): BigInt {
}
return BigInt.zero()
}
export function createPredictContract(address: Address): PredictContract {
const predictContract = new PredictContract(address.toHexString())
const token = getToken(address, true)
predictContract.token = token.id
predictContract.secondsPerEpoch = BigInt.zero()
predictContract.secondsPerSubscription = BigInt.zero()
predictContract.truevalSubmitTimeout = BigInt.zero()
predictContract.stakeToken = null
predictContract.txId = ''
predictContract.timestamp = 0
predictContract.block = 0
predictContract.eventIndex = 0
predictContract.paused = false
predictContract.save()
return predictContract
}
export function getPredictContract(address: Address): PredictContract {
let newPredictContract = PredictContract.load(address.toHexString())
if (newPredictContract === null) {
newPredictContract = createPredictContract(address)
}
return newPredictContract
}

View File

@ -54,6 +54,41 @@ templates:
handler: handleProviderFee
receipt: true
- name: ERC20Template3
kind: ethereum/contract
network: __NETWORK__
source:
abi: ERC20Template3
mapping:
kind: ethereum/events
apiVersion: 0.0.7
language: wasm/assemblyscript
file: ./src/mappings/erc20Template3.ts
entities:
- ERC20Template3
abis:
- name: ERC20Template3
file: ./node_modules/@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template3.sol/ERC20Template3.json
- name: ERC20
file: ./abis/ERC20.json
- name: ERC20Roles
file: ./node_modules/@oceanprotocol/contracts/artifacts/contracts/utils/ERC20Roles.sol/ERC20Roles.json
eventHandlers:
- event: PredictionSubmitted(indexed address,indexed uint256,uint256)
handler: handlePredictionSubmitted
- event: PredictionPayout(indexed address,indexed uint256,uint256,uint256,bool,bool,uint256,uint8)
handler: handlePredictionPayout
- event: NewSubscription(indexed address,uint256,uint256)
handler: handleNewSubscription
- event: TruevalSubmitted(indexed uint256,bool,uint8,uint256,uint256)
handler: handleTruevalSubmitted
- event: SettingChanged(uint256,uint256,uint256,address)
handler: handleSettingChanged
- event: RevenueAdded(uint256,uint256,uint256,uint256,uint256)
handler: handleRevenueAdded
- event: Paused(bool)
handler: handlePaused
- name: ERC721Template
kind: ethereum/contract
network: __NETWORK__
@ -189,6 +224,10 @@ dataSources:
entities:
- ERC721Factory
abis:
- name: ERC721Template
file: ./node_modules/@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json
- name: ERC20Template
file: ./node_modules/@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json
- name: ERC721Factory
file: ./node_modules/@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json
- name: ERC20