-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update to pricelib v1.3.1 but add ignorelist config, and change oracl…
…e count, slowing down the syncing but improving accuracy
- Loading branch information
Showing
27 changed files
with
1,596 additions
and
513 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 22 additions & 12 deletions
34
subgraphs/polygon-bridge/src/prices/calculations/CalculationsSushiswap.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,47 @@ | ||
import * as utils from "../common/utils"; | ||
import * as constants from "../common/constants"; | ||
import { CustomPriceType } from "../common/types"; | ||
import { Address, BigDecimal, BigInt } from "@graphprotocol/graph-ts"; | ||
import { CustomPriceType, OracleContract } from "../common/types"; | ||
import { Address, BigDecimal, BigInt, ethereum } from "@graphprotocol/graph-ts"; | ||
import { CalculationsSushiSwap as CalculationsSushiContract } from "../../../generated/FxERC20Events/CalculationsSushiSwap"; | ||
|
||
export function getSushiSwapContract( | ||
contractAddress: Address | ||
contract: OracleContract, | ||
block: ethereum.Block | null = null | ||
): CalculationsSushiContract | null { | ||
if (utils.isNullAddress(contractAddress)) return null; | ||
if ( | ||
(block && contract.startBlock.gt(block.number)) || | ||
utils.isNullAddress(contract.address) | ||
) | ||
return null; | ||
|
||
return CalculationsSushiContract.bind(contractAddress); | ||
return CalculationsSushiContract.bind(contract.address); | ||
} | ||
|
||
export function getTokenPriceUSDC(tokenAddr: Address): CustomPriceType { | ||
export function getTokenPriceUSDC( | ||
tokenAddr: Address, | ||
block: ethereum.Block | null = null | ||
): CustomPriceType { | ||
const config = utils.getConfig(); | ||
|
||
if (!config || config.sushiCalculationsBlacklist().includes(tokenAddr)) | ||
return new CustomPriceType(); | ||
|
||
const sushiContract = getSushiSwapContract(config.sushiCalculations()); | ||
if (!sushiContract) { | ||
return new CustomPriceType(); | ||
} | ||
const calculationSushiContract = getSushiSwapContract( | ||
config.sushiCalculations(), | ||
block | ||
); | ||
if (!calculationSushiContract) return new CustomPriceType(); | ||
|
||
const tokenPrice: BigDecimal = utils | ||
.readValue<BigInt>( | ||
sushiContract.try_getPriceUsdc(tokenAddr), | ||
calculationSushiContract.try_getPriceUsdc(tokenAddr), | ||
constants.BIGINT_ZERO | ||
) | ||
.toBigDecimal(); | ||
|
||
return CustomPriceType.initialize( | ||
tokenPrice, | ||
constants.DEFAULT_USDC_DECIMALS | ||
constants.DEFAULT_USDC_DECIMALS, | ||
constants.OracleType.SUSHI_CALCULATIONS | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.