diff --git a/.env b/.env index 96575047..56cb7ea8 100644 --- a/.env +++ b/.env @@ -1,10 +1,11 @@ -NODE_MODE=developement +NODE_MODE=deployed DATABASE_URL_LOCAL=mongodb://localhost:27017/V2-graphQL DATABASE_URL_ONLINE=mongodb+srv://admin:scytalelabs@cluster0-9yop5.mongodb.net/V2-graphQL?retryWrites=true&w=majority -FACTORY_ADDRESS=157ece984b5ee7c58ae95299b4b7afa890bddb1d9f710fe2384a9e589f9b1bb8 -token0=ebd3469763c597ef971782ea6a164531183c2251cac023cabf84b7c6bb521136 -token1=d595a82535e34b87ee37b5cc094241304e28b0904f70ff83ffbc9f71bc9b5410 -pair=5d7922b0281a1074663be274d0e0e8bd14aae748aa28d3b552aef8d0a5a7963b +FACTORY_CONTRACT=157ece984b5ee7c58ae95299b4b7afa890bddb1d9f710fe2384a9e589f9b1bb8 +PAIR_CONTRACT=5d7922b0281a1074663be274d0e0e8bd14aae748aa28d3b552aef8d0a5a7963b +CALLEE_CONTRACT=fbfeda8b97f056f526f20c2fc2b486d9bdbfb3e46b9a164527e57c0c86e68612 +TOKEN0_CONTRACT=ebd3469763c597ef971782ea6a164531183c2251cac023cabf84b7c6bb521136 +TOKEN1_CONTRACT=d595a82535e34b87ee37b5cc094241304e28b0904f70ff83ffbc9f71bc9b5410 GRAPHQL=http://localhost:3000/graphql CHAIN_NAME=casper-test @@ -67,9 +68,3 @@ SET_TREASURY_FEE_PERCENT_PAYMENT_AMOUNT=5000000000 SET_FEE_TO_PAYMENT_AMOUNT=5000000000 SET_FEE_TO_SETTER_PAYMENT_AMOUNT=5000000000 CREATE_PAIR_PAYMENT_AMOUNT=5000000000 - -FACTORY_CONTRACT=157ece984b5ee7c58ae95299b4b7afa890bddb1d9f710fe2384a9e589f9b1bb8 -PAIR_CONTRACT=5d7922b0281a1074663be274d0e0e8bd14aae748aa28d3b552aef8d0a5a7963b -CALLEE_CONTRACT=fbfeda8b97f056f526f20c2fc2b486d9bdbfb3e46b9a164527e57c0c86e68612 -TOKEN0_CONTRACT=ebd3469763c597ef971782ea6a164531183c2251cac023cabf84b7c6bb521136 -TOKEN1_CONTRACT=d595a82535e34b87ee37b5cc094241304e28b0904f70ff83ffbc9f71bc9b5410 \ No newline at end of file diff --git a/graphql/dayUpdates.js b/graphql/dayUpdates.js index ef9f0fd1..9023a33a 100644 --- a/graphql/dayUpdates.js +++ b/graphql/dayUpdates.js @@ -19,7 +19,7 @@ async function updateUniswapDayData (timeStamp) { try { let uniswap = await UniswapFactory.findOne({ - id: process.env.FACTORY_ADDRESS, + id: process.env.FACTORY_CONTRACT, }); let timestamp = timeStamp; diff --git a/graphql/mutations.js b/graphql/mutations.js index ff09a9ae..c9b41e76 100644 --- a/graphql/mutations.js +++ b/graphql/mutations.js @@ -77,11 +77,11 @@ const handleNewPair = { // load factory (create if first exchange) let factory = await UniswapFactory.findOne({ - id: process.env.FACTORY_ADDRESS, + id: process.env.FACTORY_CONTRACT, }); if (factory === null) { factory = new UniswapFactory({ - id: process.env.FACTORY_ADDRESS, + id: process.env.FACTORY_CONTRACT, pairCount: 0, totalVolumeETH: ZERO_BD, totalLiquidityETH: ZERO_BD, @@ -239,7 +239,7 @@ const handleTransfer = { } let factory = await UniswapFactory.findOne({ - id: process.env.FACTORY_ADDRESS, + id: process.env.FACTORY_CONTRACT, }); let transactionHash = args.deployHash; @@ -449,7 +449,7 @@ const handleSync = { let token0 = await Token.findOne({ id: pair.token0 }); let token1 = await Token.findOne({ id: pair.token1 }); let uniswap = await UniswapFactory.findOne({ - id: process.env.FACTORY_ADDRESS, + id: process.env.FACTORY_CONTRACT, }); // reset factory liquidity by subtracting onluy tarcked liquidity @@ -565,7 +565,7 @@ const handleMint = { let pair = await Pair.findOne({ id: args.pairAddress }); let uniswap = await UniswapFactory.findOne({ - id: process.env.FACTORY_ADDRESS, + id: process.env.FACTORY_CONTRACT, }); let token0 = await Token.findOne({ id: pair.token0 }); @@ -672,7 +672,7 @@ const handleBurn = { let pair = await Pair.findOne({ id: args.pairAaddress }); let uniswap = await UniswapFactory.findOne({ - id: process.env.FACTORY_ADDRESS, + id: process.env.FACTORY_CONTRACT, }); //update token info @@ -828,7 +828,7 @@ const handleSwap = { // update global values, only used tracked amounts for volume let uniswap = await UniswapFactory.findOne({ - id: process.env.FACTORY_ADDRESS, + id: process.env.FACTORY_CONTRACT, }); uniswap.totalVolumeUSD = uniswap.totalVolumeUSD + trackedAmountUSD; uniswap.totalVolumeETH = uniswap.totalVolumeETH + trackedAmountETH; diff --git a/graphql/pricing.js b/graphql/pricing.js index fddcd0a7..4a78057d 100644 --- a/graphql/pricing.js +++ b/graphql/pricing.js @@ -90,7 +90,7 @@ async function findEthPerToken(token) { } // loop through whitelist and check if paired with any for (let i = 0; i < WHITELIST.length; ++i) { - //let pairAddress = await factory.getPair(process.env.FACTORY_ADDRESS,token.id, WHITELIST[i]); + //let pairAddress = await factory.getPair(process.env.FACTORY_CONTRACT,token.id, WHITELIST[i]); let pairAddress = "hash-0000000000000000000000000000000000000000000000000000000000000000"; diff --git a/package.json b/package.json index c8c80a33..e596514c 100644 --- a/package.json +++ b/package.json @@ -3,13 +3,7 @@ "version": "0.0.0", "private": true, "scripts": { - "start": "ts-node ./bin/www", - "test:erc20install": "ts-node JsClients/ERC20/test/install.ts", - "test:erc20installed": "ts-node JsClients/ERC20/test/installed.ts", - "test:pairinstall": "ts-node JsClients/PAIR/test/install.ts", - "test:pairinstalled": "ts-node JsClients/PAIR/test/installed.ts", - "test:factoryinstall": "ts-node JsClients/FACTORY/test/install.ts", - "test:factoryinstalled": "ts-node JsClients/FACTORY/test/installed.ts" + "start": "ts-node ./bin/www" }, "dependencies": { "casper-js-sdk": "2.4.1", diff --git a/readme.md b/readme.md new file mode 100644 index 00000000..9cd6285f --- /dev/null +++ b/readme.md @@ -0,0 +1,58 @@ +# Casper_Uniswap_V2 GraphQL + +Casper Uniswap is a decentralized protocol for automated token exchange on Casper. + +This graphql dynamically tracks any pair created by the casper uniswap factory. It tracks of the current state of casper Uniswap contracts, and contains derived stats for things like historical data and USD prices. + +- aggregated data across pairs and tokens, +- data on individual pairs and tokens, +- data on transactions +- data on liquidity providers +- historical data on Uniswap, pairs or tokens, aggregated by day + +## Running Locally + +npm install to install the require packages +npm start to start the server + +## Queries + +Below are a few ways to show how to query the casper-uniswap-graphql for data. The queries show most of the information that is queryable, but there are many other filtering options that can be used, just check out the [querying api](https://thegraph.com/docs/graphql-api). These queries can be used locally or in The Graph Explorer playground. + +## Key Entity Overviews + +#### Casper UniswapFactory + +Contains data across all of Casper Uniswap V2. This entity tracks important things like total liquidity (in CSPR and USD, see below), all time volume, transaction count, number of pairs and more. + +#### Token + +Contains data on a specific token. This token specific data is aggregated across all pairs, and is updated whenever there is a transaction involving that token. + +#### Pair + +Contains data on a specific pair. + +#### Transaction + +Every transaction on Uniswap is stored. Each transaction contains an array of mints, burns, and swaps that occured within it. + +#### Mint, Burn, Swap + +These contain specifc information about a transaction. Things like which pair triggered the transaction, amounts, sender, recipient, and more. Each is linked to a parent Transaction entity. + +## Example Queries + +### Querying Aggregated Casper Uniswap Data + +This query fetches aggredated data from all Casper uniswap pairs and tokens, to give a view into how much activity is happening within the whole protocol. + +```graphql +{ + uniswapFactories(first: 1) { + pairCount + totalVolumeUSD + totalLiquidityUSD + } +} +``` diff --git a/test.js b/test.js index 82853fc3..e69de29b 100644 --- a/test.js +++ b/test.js @@ -1,94 +0,0 @@ -// var mongoose = require('mongoose'); -// require('mongoose-bigdecimal'); -// var Schema = mongoose.Schema; -// var BigDecimal = require('big.js'); - -// //define your schema -// var ProductSchema = new Schema({ -// price: { -// type: Schema.Types.BigDecimal, -// required: true, -// index:true -// }, -// discounts:[{ -// type: Schema.Types.BigDecimal -// }] -// }); -// Product = mongoose.model('Product', ProductSchema); - -// //use it -// var book = new Product(); -// book.price = new BigDecimal(12); -// book.save(done); -// var data=[ -// [ -// { data: 'contract_package_hash' }, -// { -// data: '0024dc4c2ea77a01a0da90893c3283cfa602d78acf198aaa67e61e9bc9b44c93' -// } -// ], -// [ { data: 'event_type' }, { data: 'transfer' } ], -// [ -// { data: 'from' }, -// { -// data: 'Key::Account(0000000000000000000000000000000000000000000000000000000000000000)' -// } -// ], -// [ -// { data: 'to' }, -// { -// data: 'Key::Account(e56a24ed039010d56c2f47aad13fb740b94f3253889500129421054ebb38d917)' -// } -// ], -// [ { data: 'value' }, { data: '50' } ] -// ]; - -// console.log("data: ",data[0][1].data); - -const { request } = require('graphql-request'); - -// request('http://localhost:3000/graphql', -// `mutation handleTransfer( $pairAddress: String!, $from: String!, $to: String!, $value: Int!, $deployHash: String!, $timeStamp: Int!, $blockHash: String!){ -// handleTransfer( pairAddress: $pairAddress, from: $from, to: $to, value: $value, deployHash: $deployHash, timeStamp: $timeStamp, blockHash: $blockHash) { -// id -// } - -// }`, -// {pairAddress:'11f6e1b2d9566ab6d796f026b1d4bd36b71664c4ee8805fbc9cdca406607cd59', from: '0000000000000000000000000000000000000000000000000000000000000000', to: '0000000000000000000000000000000000000000000000000000000000000111', value: 5, pairAddress:'11f6e1b2d9566ab6d796f026b1d4bd36b71664c4ee8805fbc9cdca406607cd59', deployHash:'0000000000000000000000000000000000000000000000000000000000000000', timeStamp:1000, blockHash:'0000000000000000000000000000000000000000000000000000000000000000'}) -// .then(data => console.log(data)) -// .catch(error => console.error(error)); - -// request('http://localhost:3000/graphql', -// `mutation handleNewPair( $token0: String!, $token1: String!, $pair: String!, $all_pairs_length: Int!, $timeStamp: Int!, $blockHash: String!){ -// handleNewPair( token0: $token0, token1: $token1, pair: $pair, all_pairs_length: $all_pairs_length, timeStamp: $timeStamp, blockHash: $blockHash) { -// id -// } - -// }`, -// {token0:'51254d70d183f4b1e59ee5d5b0c76d3c3a81d0366278beecc05b546d49a9835c', token1: '96b0431770a34f5b651a43c830f3c8537e7c44f2cb8191d7efbcca2379785cda', pair: '11f6e1b2d9566ab6d796f026b1d4bd36b71664c4ee8805fbc9cdca406607cd59', all_pairs_length: 5, timeStamp:1000, blockHash:'0000000000000000000000000000000000000000000000000000000000000000'}) -// .then(data => console.log(data)) -// .catch(error => console.error(error)); - - -// var data="Key::hash(45d8a07febaf15b0b0c5ace02533c9d278fd2b6e31b84e7a7abd0c7478e57ea2)"; -// var from=data.split('('); -// var from1=from[1].split(')'); -// console.log("from: ", from1[0]); -// var data1="1"; - -// console.log("from: ", parseInt(data1)); - -// var int=1635977242919; -// console.log("int: ",int.toString()); - - -request('http://localhost:3000/graphql', - `mutation handleSync( $reserve0: Int!, $reserve1: Int!, $pairAddress: String!){ - handleSync( reserve0: $reserve0, reserve1: $reserve1, pairAddress: $pairAddress) { - result - } - - }`, - {reserve0:0, reserve1: 0, pairAddress: "c22c075df6da91e5c803ebc8914b12a215261c9d0cf28f637a9ce83b96f9842b"}) - .then(data => console.log(data)) - .catch(error => console.error(error)); \ No newline at end of file