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

refactor(subgraphs/exchange): fix build:fuse execution errors #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@
"prettier": "^2.0.0",
"typescript": "^4.0.0"
},
"dependencies": {}
"dependencies": {
"@voltage-finance/core": "^1.0.1"
}
}
2 changes: 1 addition & 1 deletion packages/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const JOE_MAKER_V2_ADDRESS = Address.fromString('0xC98C3C547DDbcc0029F38E

// PRICING
export const VOLTAGE_WFUSE_USDC_PAIR_ADDRESS = Address.fromString('0xc79983b0754ac688bf54939add59bdf75916fda2')
export const VOLT_USDC_PAIR_ADDRESS = Address.fromString('0xa01c9a5401fabfefe71cacd7ec70b92cfc180bf8')
export const VOLT_FUSD_PAIR_ADDRESS = Address.fromString('0x4e6b54f8dee787b16d8cdba4f759342b19239c2c')

export const WFUSE_ADDRESS = Address.fromString('0x0be9e53fd7edac9f859882afdda116645287c629')
export const USDT_ADDRESS = Address.fromString('0xfadbbf8ce7d5b7041be672561bba99f79c532e10')
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/exchange/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

"deploy:avax": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ traderjoe-xyz/exchange exchange.avax.yaml",
"deploy:rinkeby": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ traderjoe-xyz/exchange-rinkeby-ii exchange.rinkeby.yaml",
"deploy:fuse": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ voltfinance/voltage-exchange exchange.fuse.yaml",
"deploy:fuse": "graph deploy --access-token $GRAPH_TOKEN --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ diegofigs/voltfinance-exchange exchange.fuse.yaml",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REMINDER: this should be changed back before merge


"create-local": "graph create --node http://localhost:8020/ traderjoe-xyz/exchange",
"remove-local": "graph remove --node http://localhost:8020/ traderjoe-xyz/exchange",
Expand Down
56 changes: 28 additions & 28 deletions subgraphs/exchange/src/exchange/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
BIG_DECIMAL_ZERO,
FACTORY_ADDRESS,
WHITELIST,
JOE_USDT_PAIR_ADDRESS,
VOLT_FUSD_PAIR_ADDRESS,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opted on using this pair since its the most liquid, regardless I think this reference is not used

WFUSE_STABLE_PAIRS,
WFUSE_ADDRESS,
USDT_ADDRESS,
Expand All @@ -30,43 +30,43 @@ export function getJoePrice(block: ethereum.Block = null): BigDecimal {
}

/*
* JOE price is the weighted average of JOE/AVAX * AVAX and JOE/USDT.
* VOLT price is the weighted average of VOLT/WFUSE * WFUSE and VOLT/USDC.
*
*/
export function getWavgJoePrice(block: ethereum.Block = null): BigDecimal {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function was changed because build:fuse command failed reading a reference here; think this method is not called regardless.

// get JOE/USDT
const usdt_pair = Pair.load(JOE_USDT_PAIR_ADDRESS.toString())
const usdt_price = usdt_pair
? usdt_pair.token0 == VOLT_TOKEN_ADDRESS.toHexString()
? usdt_pair.token1Price
: usdt_pair.token0Price
// get VOLT/USDC
const fusdPair = Pair.load(VOLT_FUSD_PAIR_ADDRESS.toString())
const fusdPrice = fusdPair
? fusdPair.token0 == VOLT_TOKEN_ADDRESS.toHexString()
? fusdPair.token1Price
: fusdPair.token0Price
: BIG_DECIMAL_ZERO
const usdt_weight = usdt_pair
? usdt_pair.token0 == VOLT_TOKEN_ADDRESS.toHexString()
? usdt_pair.reserve0
: usdt_pair.reserve1
const fusdWeight = fusdPair
? fusdPair.token0 == VOLT_TOKEN_ADDRESS.toHexString()
? fusdPair.reserve0
: fusdPair.reserve1
: BIG_DECIMAL_ZERO

// get JOE/AVAX
const joe_wavax_address = factoryContract.getPair(VOLT_TOKEN_ADDRESS, WFUSE_ADDRESS)
const avax_pair = Pair.load(joe_wavax_address.toString())
const avax_rate = avax_pair
? avax_pair.token0 == VOLT_TOKEN_ADDRESS.toHexString()
? avax_pair.token1Price
: avax_pair.token0Price
// get VOLT/WFUSE
const voltWfuseAddress = factoryContract.getPair(VOLT_TOKEN_ADDRESS, WFUSE_ADDRESS)
const wfusePair = Pair.load(voltWfuseAddress.toString())
const wfuseRate = wfusePair
? wfusePair.token0 == VOLT_TOKEN_ADDRESS.toHexString()
? wfusePair.token1Price
: wfusePair.token0Price
: BIG_DECIMAL_ZERO
const avax_weight = avax_pair
? avax_pair.token0 == VOLT_TOKEN_ADDRESS.toHexString()
? avax_pair.reserve0
: avax_pair.reserve1
const wfuseWeight = wfusePair
? wfusePair.token0 == VOLT_TOKEN_ADDRESS.toHexString()
? wfusePair.reserve0
: wfusePair.reserve1
: BIG_DECIMAL_ZERO
const avax_price = avax_rate.times(getAvaxPrice())
const wfusePrice = wfuseRate.times(getAvaxPrice())

// weighted avg
const sumprod = usdt_price.times(usdt_weight).plus(avax_price.times(avax_weight))
const sumweights = usdt_weight.plus(avax_weight)
const wavg = sumprod.div(sumweights)
return wavg
const sumprod = fusdPrice.times(fusdWeight).plus(wfusePrice.times(wfuseWeight))
const sumweights = fusdWeight.plus(wfuseWeight)
const weightedAverage = sumprod.div(sumweights)
return weightedAverage
}

/*
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@
"@typescript-eslint/types" "4.27.0"
eslint-visitor-keys "^2.0.0"

"@voltage-finance/core@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@voltage-finance/core/-/core-1.0.1.tgz#c345e0030c61994128181623762fd02354ea2018"
integrity sha512-C51OVjoi7SLqkeowmxhqkw/wCcFpzk2j7Mi1kd5QkovjUhpo4TK1FEWEOz3h+r+UmefYjRxhzAFhraQkUABiPg==

[email protected]:
version "1.3.2"
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.2.tgz#c102371b6ec3a7cf3b847ca00c20bb0fce4c6dea"
Expand Down