Skip to content

Commit

Permalink
fix _reference_ subgraph lint
Browse files Browse the repository at this point in the history
  • Loading branch information
melotik committed Oct 26, 2023
1 parent e88e11c commit 7263916
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 42 deletions.
49 changes: 24 additions & 25 deletions subgraphs/_reference_/src/common/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable prefer-const */
import { ERC20 } from "../../generated/UniswapV2Factory/ERC20";
import { ERC20SymbolBytes } from "../../generated/UniswapV2Factory/ERC20SymbolBytes";
import { ERC20NameBytes } from "../../generated/UniswapV2Factory/ERC20NameBytes";
Expand All @@ -9,25 +8,25 @@ export const INVALID_TOKEN_DECIMALS = 0;
export const UNKNOWN_TOKEN_VALUE = "unknown";

export function fetchTokenSymbol(tokenAddress: Address): string {
let contract = ERC20.bind(tokenAddress);
let contractSymbolBytes = ERC20SymbolBytes.bind(tokenAddress);
const contract = ERC20.bind(tokenAddress);
const contractSymbolBytes = ERC20SymbolBytes.bind(tokenAddress);

// try types string and bytes32 for symbol
let symbolValue = UNKNOWN_TOKEN_VALUE;
let symbolResult = contract.try_symbol();
const symbolResult = contract.try_symbol();
if (!symbolResult.reverted) {
return symbolResult.value;
}

// non-standard ERC20 implementation
let symbolResultBytes = contractSymbolBytes.try_symbol();
const symbolResultBytes = contractSymbolBytes.try_symbol();
if (!symbolResultBytes.reverted) {
// for broken pairs that have no symbol function exposed
if (!isNullEthValue(symbolResultBytes.value.toHexString())) {
symbolValue = symbolResultBytes.value.toString();
} else {
// try with the static definition
let staticTokenDefinition =
const staticTokenDefinition =
StaticTokenDefinition.fromAddress(tokenAddress);
if (staticTokenDefinition != null) {
symbolValue = staticTokenDefinition.symbol;
Expand All @@ -39,25 +38,25 @@ export function fetchTokenSymbol(tokenAddress: Address): string {
}

export function fetchTokenName(tokenAddress: Address): string {
let contract = ERC20.bind(tokenAddress);
let contractNameBytes = ERC20NameBytes.bind(tokenAddress);
const contract = ERC20.bind(tokenAddress);
const contractNameBytes = ERC20NameBytes.bind(tokenAddress);

// try types string and bytes32 for name
let nameValue = UNKNOWN_TOKEN_VALUE;
let nameResult = contract.try_name();
const nameResult = contract.try_name();
if (!nameResult.reverted) {
return nameResult.value;
}

// non-standard ERC20 implementation
let nameResultBytes = contractNameBytes.try_name();
const nameResultBytes = contractNameBytes.try_name();
if (!nameResultBytes.reverted) {
// for broken exchanges that have no name function exposed
if (!isNullEthValue(nameResultBytes.value.toHexString())) {
nameValue = nameResultBytes.value.toString();
} else {
// try with the static definition
let staticTokenDefinition =
const staticTokenDefinition =
StaticTokenDefinition.fromAddress(tokenAddress);
if (staticTokenDefinition != null) {
nameValue = staticTokenDefinition.name;
Expand All @@ -69,17 +68,17 @@ export function fetchTokenName(tokenAddress: Address): string {
}

export function fetchTokenDecimals(tokenAddress: Address): i32 {
let contract = ERC20.bind(tokenAddress);
const contract = ERC20.bind(tokenAddress);

// try types uint8 for decimals
let decimalResult = contract.try_decimals();
const decimalResult = contract.try_decimals();
if (!decimalResult.reverted) {
let decimalValue = decimalResult.value;
const decimalValue = decimalResult.value;
return decimalValue.toI32();
}

// try with the static definition
let staticTokenDefinition = StaticTokenDefinition.fromAddress(tokenAddress);
const staticTokenDefinition = StaticTokenDefinition.fromAddress(tokenAddress);
if (staticTokenDefinition != null) {
return staticTokenDefinition.decimals as i32;
} else {
Expand Down Expand Up @@ -111,10 +110,10 @@ class StaticTokenDefinition {

// Get all tokens with a static defintion
static getStaticDefinitions(): Array<StaticTokenDefinition> {
let staticDefinitions = new Array<StaticTokenDefinition>(INT_SIX);
const staticDefinitions = new Array<StaticTokenDefinition>(INT_SIX);

// Add DGD
let tokenDGD = new StaticTokenDefinition(
const tokenDGD = new StaticTokenDefinition(
Address.fromString("0xe0b7927c4af23765cb51314a0e0521a9645f0e2a"),
"DGD",
"DGD",
Expand All @@ -123,7 +122,7 @@ class StaticTokenDefinition {
staticDefinitions.push(tokenDGD);

// Add AAVE
let tokenAAVE = new StaticTokenDefinition(
const tokenAAVE = new StaticTokenDefinition(
Address.fromString("0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9"),
"AAVE",
"Aave Token",
Expand All @@ -132,7 +131,7 @@ class StaticTokenDefinition {
staticDefinitions.push(tokenAAVE);

// Add LIF
let tokenLIF = new StaticTokenDefinition(
const tokenLIF = new StaticTokenDefinition(
Address.fromString("0xeb9951021698b42e4399f9cbb6267aa35f82d59d"),
"LIF",
"Lif",
Expand All @@ -141,7 +140,7 @@ class StaticTokenDefinition {
staticDefinitions.push(tokenLIF);

// Add SVD
let tokenSVD = new StaticTokenDefinition(
const tokenSVD = new StaticTokenDefinition(
Address.fromString("0xbdeb4b83251fb146687fa19d1c660f99411eefe3"),
"SVD",
"savedroid",
Expand All @@ -150,7 +149,7 @@ class StaticTokenDefinition {
staticDefinitions.push(tokenSVD);

// Add TheDAO
let tokenTheDAO = new StaticTokenDefinition(
const tokenTheDAO = new StaticTokenDefinition(
Address.fromString("0xbb9bc244d798123fde783fcc1c72d3bb8c189413"),
"TheDAO",
"TheDAO",
Expand All @@ -159,7 +158,7 @@ class StaticTokenDefinition {
staticDefinitions.push(tokenTheDAO);

// Add HPB
let tokenHPB = new StaticTokenDefinition(
const tokenHPB = new StaticTokenDefinition(
Address.fromString("0x38c6a68304cdefb9bec48bbfaaba5c5b47818bb2"),
"HPB",
"HPBCoin",
Expand All @@ -172,12 +171,12 @@ class StaticTokenDefinition {

// Helper for hardcoded tokens
static fromAddress(tokenAddress: Address): StaticTokenDefinition | null {
let staticDefinitions = this.getStaticDefinitions();
let tokenAddressHex = tokenAddress.toHexString();
const staticDefinitions = this.getStaticDefinitions();
const tokenAddressHex = tokenAddress.toHexString();

// Search the definition using the address
for (let i = 0; i < staticDefinitions.length; i++) {
let staticDefinition = staticDefinitions[i];
const staticDefinition = staticDefinitions[i];
if (staticDefinition.address.toHexString() == tokenAddressHex) {
return staticDefinition;
}
Expand Down
1 change: 0 additions & 1 deletion subgraphs/_reference_/src/common/utils/datetime.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-magic-numbers */
import { BigInt } from "@graphprotocol/graph-ts";
import { SECONDS_PER_DAY } from "../constants";

Expand Down
2 changes: 1 addition & 1 deletion subgraphs/_reference_/src/prices/config/arbitrum.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
import * as constants from "../common/constants";
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts";
import { Configurations, OracleConfig, OracleContract } from "../common/types";
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/_reference_/src/prices/config/aurora.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
import * as constants from "../common/constants";
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts";
import { Configurations, OracleConfig, OracleContract } from "../common/types";
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/_reference_/src/prices/config/avalanche.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
import * as constants from "../common/constants";
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts";
import { Configurations, OracleConfig, OracleContract } from "../common/types";
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/_reference_/src/prices/config/bsc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
import * as constants from "../common/constants";
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts";
import { Configurations, OracleConfig, OracleContract } from "../common/types";
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/_reference_/src/prices/config/celo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
import * as constants from "../common/constants";
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts";
import { Configurations, OracleConfig, OracleContract } from "../common/types";
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/_reference_/src/prices/config/cronos.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
import * as constants from "../common/constants";
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts";
import { Configurations, OracleConfig, OracleContract } from "../common/types";
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/_reference_/src/prices/config/fantom.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
import * as constants from "../common/constants";
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts";
import { Configurations, OracleConfig, OracleContract } from "../common/types";
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/_reference_/src/prices/config/fuse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
import * as constants from "../common/constants";
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts";
import { Configurations, OracleConfig, OracleContract } from "../common/types";
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/_reference_/src/prices/config/gnosis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
import * as constants from "../common/constants";
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts";
import { Configurations, OracleConfig, OracleContract } from "../common/types";
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/_reference_/src/prices/config/harmony.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
import * as constants from "../common/constants";
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts";
import { Configurations, OracleConfig, OracleContract } from "../common/types";
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/_reference_/src/prices/config/moonbeam.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
import * as constants from "../common/constants";
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts";
import { Configurations, OracleConfig, OracleContract } from "../common/types";
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/_reference_/src/prices/config/optimism.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
import * as constants from "../common/constants";
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts";
import { Configurations, OracleConfig, OracleContract } from "../common/types";
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/_reference_/src/prices/config/polygon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
import * as constants from "../common/constants";
import { BigInt, Address, ethereum } from "@graphprotocol/graph-ts";
import { Configurations, OracleConfig, OracleContract } from "../common/types";
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/_reference_/src/prices/config/template.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
import * as constants from "../common/constants";
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts";
import { Configurations, OracleConfig, OracleContract } from "../common/types";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-magic-numbers */
import * as utils from "../common/utils";
import * as constants from "../common/constants";
import { CustomPriceType } from "../common/types";
Expand Down
1 change: 0 additions & 1 deletion subgraphs/_reference_/src/sdk/protocols/bridge/chainIds.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-magic-numbers */
import { BigInt, TypedMap } from "@graphprotocol/graph-ts";
import { Network } from "../../util/constants";

Expand Down

0 comments on commit 7263916

Please sign in to comment.