Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cone sync #2

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 39 additions & 13 deletions abis/pair.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@
"name": "Fees",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "newValue",
"type": "uint256"
}
],
"name": "FeesChanged",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down Expand Up @@ -964,6 +977,19 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "setSwapFee",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -1056,6 +1082,19 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "swapFee",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "symbol",
Expand Down Expand Up @@ -1185,18 +1224,5 @@
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "treasury",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
}
]
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "dystopia-subgraph",
"name": "cone-subgraph",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"codegen": "graph codegen --output-dir src/types/",
"build": "graph build",
"deploy": "graph deploy --node https://api.thegraph.com/deploy/ dystopia-exchange/dystopia",
"deploy-staging": "graph deploy --product hosted-service belbix/dystopia-staging",
"create-local": "graph create --node http://localhost:8020/ dystopia-exchange/dystopia",
"remove-local": "graph remove --node http://localhost:8020/ dystopia-exchange/dystopia",
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 dystopia-exchange/dystopia -l v0.0.1"
"deploy": "graph deploy --node https://api.thegraph.com/deploy/ cone-exchange/cone",
"deploy-staging": "graph deploy --node https://api.thegraph.com/deploy/ belbix/cone-staging",
"create-local": "graph create --node http://localhost:8020/ cone-exchange/cone",
"remove-local": "graph remove --node http://localhost:8020/ cone-exchange/cone",
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 cone-exchange/cone -l v0.0.1"
},
"dependencies": {
"@graphprotocol/graph-cli": "0.31.0",
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Dystopia Subgraph
![TESTS](https://github.com/dystopia-exchange/dystopia-subgraph-v3/actions/workflows/test.yml/badge.svg)
# Cone Subgraph
![TESTS](https://github.com/cone-exchange/cone-subgraph/actions/workflows/test.yml/badge.svg)


## Install
Expand Down
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ type Pair @entity {

gauge: GaugeEntity
gaugebribes: BribeEntity
fee: Int!
}

type PairMap @entity(immutable: true) {
Expand Down
7 changes: 7 additions & 0 deletions src/mappings/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {updatePairDayData, updatePairHourData, updateTokenDayData, updateUniswap
import {findEthPerToken, getEthPriceInUSD, getTrackedLiquidityUSD, getTrackedVolumeUSD} from './pricing'
import {convertTokenToDecimal, createLiquidityPosition, createLiquiditySnapshot, createUser,} from './helpers'
import {ADDRESS_ZERO, BI_18, ONE_BI, ZERO_BD} from './constants';
import {FeesChanged} from "../types/Factory/PairAbi";

// *******************************************************************
// HANDLERS
Expand Down Expand Up @@ -536,6 +537,12 @@ export function handleSwap(event: Swap): void {
token1DayData.save()
}

function handleFeesChanged(event: FeesChanged): void {
const pair = Pair.load(event.address.toHexString()) as Pair
pair.fee = event.params.newValue.toI32();
pair.save();
}

// *******************************************************************
// HELPERS
// *******************************************************************
Expand Down
8 changes: 7 additions & 1 deletion src/mappings/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
fetchTokenTotalSupply,
generatePairMapID,
} from './helpers'
import {ADDRESS_ZERO, ZERO_BD, ZERO_BI} from './constants'
import {ADDRESS_ZERO, DEFAULT_STABLE_FEE, DEFAULT_VOLATILE_FEE, ZERO_BD, ZERO_BI} from './constants'
import {isOnWhitelist} from './pricing'


Expand Down Expand Up @@ -77,6 +77,12 @@ export function handleNewPair(event: PairCreated): void {
pair.token0Price = ZERO_BD
pair.token1Price = ZERO_BD

if(event.params.stable) {
pair.fee = DEFAULT_STABLE_FEE;
} else {
pair.fee = DEFAULT_VOLATILE_FEE;
}

pair.gauge = ADDRESS_ZERO
pair.gaugebribes = ADDRESS_ZERO

Expand Down
6 changes: 5 additions & 1 deletion src/mappings/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ export function findEthPerToken(token: Token): BigDecimal {
// loop through whitelist and check if paired with any
// @ts-ignore
for (let i = 0; i < wl.length; ++i) {

// don't handle price for whitelisted tokens with CONE
// @ts-ignore
if (isOnWhitelist(token.id) && Address.fromString('0xA60205802E1B5C6EC1CAFA3cAcd49dFeECe05AC9').equals(wl[i])) {
continue;
}
// @ts-ignore
const pairMapStable = PairMap.load(generatePairMapID(token.id, wl[i].toHex(), true));
// @ts-ignore
Expand Down
34 changes: 17 additions & 17 deletions src/mappings/ve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export function handleDeposit(event: Deposit): void {
);

// exclude for MERGE
if(event.params.depositType !== 4) {
if (event.params.depositType !== 4) {
ve.totalLocked = ve.totalLocked.minus(veNft.lockedAmount);
}

veNft.lockedAmount = veNft.lockedAmount.plus(formatUnits(event.params.value, BigInt.fromI32(18)))
veNft.lockedEnd = event.params.locktime.toI32()

// exclude for MERGE
if(event.params.depositType !== 4) {
if (event.params.depositType !== 4) {
ve.totalNFTs = ve.totalNFTs + 1;
ve.totalLocked = ve.totalLocked.plus(veNft.lockedAmount);
ve.save();
Expand All @@ -44,23 +44,23 @@ export function handleTransfer(event: Transfer): void {
ve.totalNFTs = ve.totalNFTs - 1;
ve.save();
}
if (!event.params.from.equals(Address.fromString(ADDRESS_ZERO)) && !event.params.to.equals(Address.fromString(ADDRESS_ZERO))) {
const veNft = getOrCreateVeNFT(
event.params.tokenId.toString(),
event.params.from.toHexString(),
event.address.toHexString()
);
veNft.user = event.params.to.toHexString();

let user = User.load(event.params.to.toHexString())
if (!user) {
user = new User(event.params.to.toHexString());
user.usdSwapped = ZERO_BD;
user.save();
}
// if (!event.params.from.equals(Address.fromString(ADDRESS_ZERO)) && !event.params.to.equals(Address.fromString(ADDRESS_ZERO))) {
const veNft = getOrCreateVeNFT(
event.params.tokenId.toString(),
event.params.from.toHexString(),
event.address.toHexString()
);
veNft.user = event.params.to.toHexString();

veNft.save();
let user = User.load(event.params.to.toHexString())
if (!user) {
user = new User(event.params.to.toHexString());
user.usdSwapped = ZERO_BD;
user.save();
}

veNft.save();
// }
}

// ********************************************************
Expand Down
26 changes: 14 additions & 12 deletions subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ schema:
dataSources:
- kind: ethereum/contract
name: Factory
network: matic
network: bsc
source:
address: "0x1d21Db6cde1b18c7E47B0F7F42f4b3F68b9beeC9"
address: "0x0EFc2D2D054383462F2cD72eA2526Ef7687E1016"
abi: FactoryAbi
startBlock: 27986210
startBlock: 19657538
mapping:
kind: ethereum/events
apiVersion: 0.0.5
Expand All @@ -32,11 +32,11 @@ dataSources:

- kind: ethereum/contract
name: Controller
network: matic
network: bsc
source:
address: "0x7377eA6Afb77Ba013B23306154691c231824522a"
address: "0x2d91C960b03F2C39604aE1b644ba508a1366057c"
abi: ControllerAbi
startBlock: 27986210
startBlock: 20403738
mapping:
kind: ethereum/events
apiVersion: 0.0.5
Expand Down Expand Up @@ -65,7 +65,7 @@ dataSources:
templates:
- kind: ethereum/contract
name: PairTemplate
network: matic
network: bsc
source:
abi: PairAbi
mapping:
Expand All @@ -90,10 +90,12 @@ templates:
handler: handleTransfer
- event: Sync(uint256,uint256)
handler: handleSync
- event: FeesChanged(uint256)
handler: handleFeesChanged

- kind: ethereum/contract
name: GaugeTemplate
network: matic
network: bsc
source:
abi: GaugeAbi
mapping:
Expand All @@ -120,7 +122,7 @@ templates:

- kind: ethereum/contract
name: BribeTemplate
network: matic
network: bsc
source:
abi: BribeAbi
mapping:
Expand All @@ -147,7 +149,7 @@ templates:

- kind: ethereum/contract
name: VeTemplate
network: matic
network: bsc
source:
abi: VeAbi
mapping:
Expand All @@ -172,7 +174,7 @@ templates:

- kind: ethereum/contract
name: VoterTemplate
network: matic
network: bsc
source:
abi: VoterAbi
mapping:
Expand Down Expand Up @@ -211,7 +213,7 @@ templates:

- kind: ethereum/contract
name: VeDistTemplate
network: matic
network: bsc
source:
abi: VeDistAbi
mapping:
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1794,9 +1794,9 @@ globby@^11.1.0:
merge2 "^1.4.1"
slash "^3.0.0"

"gluegun@git+https://github.com/edgeandnode/gluegun.git#v4.3.1-pin-colors-dep":
"gluegun@https://github.com/edgeandnode/gluegun#v4.3.1-pin-colors-dep":
version "4.3.1"
resolved "git+https://github.com/edgeandnode/gluegun.git#b34b9003d7bf556836da41b57ef36eb21570620a"
resolved "https://github.com/edgeandnode/gluegun#b34b9003d7bf556836da41b57ef36eb21570620a"
dependencies:
apisauce "^1.0.1"
app-module-path "^2.2.0"
Expand Down