Skip to content

Commit

Permalink
fix(#minor); yearn v2; fix log index (#2269)
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh9200 authored Jul 23, 2023
1 parent 6c10078 commit dbf5550
Show file tree
Hide file tree
Showing 23 changed files with 2,184 additions and 2,177 deletions.
6 changes: 3 additions & 3 deletions deployment/deployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -5346,7 +5346,7 @@
"status": "prod",
"versions": {
"schema": "1.3.0",
"subgraph": "1.2.3",
"subgraph": "1.2.4",
"methodology": "1.0.0"
},
"files": {
Expand All @@ -5372,7 +5372,7 @@
"status": "prod",
"versions": {
"schema": "1.3.0",
"subgraph": "1.2.3",
"subgraph": "1.2.4",
"methodology": "1.0.0"
},
"files": {
Expand All @@ -5398,7 +5398,7 @@
"status": "dev",
"versions": {
"schema": "1.3.0",
"subgraph": "1.2.3",
"subgraph": "1.2.4",
"methodology": "1.0.0"
},
"files": {
Expand Down
67 changes: 34 additions & 33 deletions subgraphs/yearn-v2/src/Prices/calculations/CalculationsCurve.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
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 { CalculationsCurve as CalculationsCurveContract } from "../../../generated/templates/Vault/CalculationsCurve";

export function getCalculationsCurveContract(
network: string
): CalculationsCurveContract {
return CalculationsCurveContract.bind(
constants.CURVE_CALCULATIONS_ADDRESS_MAP.get(network)!
);
}

export function getTokenPriceFromCalculationCurve(
tokenAddr: Address,
network: string
): CustomPriceType {
const calculationCurveContract = getCalculationsCurveContract(network);

if (!calculationCurveContract) {
return new CustomPriceType();
}

let tokenPrice: BigDecimal = utils
.readValue<BigInt>(
calculationCurveContract.try_getCurvePriceUsdc(tokenAddr),
constants.BIGINT_ZERO
)
.toBigDecimal();

return CustomPriceType.initialize(tokenPrice, 6);
}
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 { CalculationsCurve as CalculationsCurveContract } from "../../../generated/templates/Vault/CalculationsCurve";

export function getCalculationsCurveContract(
network: string
): CalculationsCurveContract {
return CalculationsCurveContract.bind(
constants.CURVE_CALCULATIONS_ADDRESS_MAP.get(network)!
);
}

export function getTokenPriceFromCalculationCurve(
tokenAddr: Address,
network: string
): CustomPriceType {
const calculationCurveContract = getCalculationsCurveContract(network);

if (!calculationCurveContract) {
return new CustomPriceType();
}

const tokenPrice: BigDecimal = utils
.readValue<BigInt>(
calculationCurveContract.try_getCurvePriceUsdc(tokenAddr),
constants.BIGINT_ZERO
)
.toBigDecimal();

// eslint-disable-next-line @typescript-eslint/no-magic-numbers
return CustomPriceType.initialize(tokenPrice, 6);
}
65 changes: 33 additions & 32 deletions subgraphs/yearn-v2/src/Prices/calculations/CalculationsSushiswap.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
import * as utils from "../common/utils";
import * as constants from "../common/constants";
import { CustomPriceType } from "../common/types";
import { Address, BigDecimal, BigInt, log } from "@graphprotocol/graph-ts";
import { CalculationsSushiSwap as CalculationsSushiContract } from "../../../generated/templates/Vault/CalculationsSushiSwap";

export function getSushiSwapContract(
network: string
): CalculationsSushiContract {
return CalculationsSushiContract.bind(
constants.SUSHISWAP_CALCULATIONS_ADDRESS_MAP.get(network)!
);
}

export function getTokenPriceFromSushiSwap(
tokenAddr: Address,
network: string
): CustomPriceType {
const curveContract = getSushiSwapContract(network);
if (!curveContract) {
return new CustomPriceType();
}

let tokenPrice: BigDecimal = utils
.readValue<BigInt>(
curveContract.try_getPriceUsdc(tokenAddr),
constants.BIGINT_ZERO
)
.toBigDecimal();

return CustomPriceType.initialize(tokenPrice, 6);
}
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 { CalculationsSushiSwap as CalculationsSushiContract } from "../../../generated/templates/Vault/CalculationsSushiSwap";

export function getSushiSwapContract(
network: string
): CalculationsSushiContract {
return CalculationsSushiContract.bind(
constants.SUSHISWAP_CALCULATIONS_ADDRESS_MAP.get(network)!
);
}

export function getTokenPriceFromSushiSwap(
tokenAddr: Address,
network: string
): CustomPriceType {
const curveContract = getSushiSwapContract(network);
if (!curveContract) {
return new CustomPriceType();
}

const tokenPrice: BigDecimal = utils
.readValue<BigInt>(
curveContract.try_getPriceUsdc(tokenAddr),
constants.BIGINT_ZERO
)
.toBigDecimal();

// eslint-disable-next-line @typescript-eslint/no-magic-numbers
return CustomPriceType.initialize(tokenPrice, 6);
}
Loading

0 comments on commit dbf5550

Please sign in to comment.