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

Error in Running the subgraph locally #836

Open
expandboard opened this issue Feb 12, 2025 · 5 comments
Open

Error in Running the subgraph locally #836

expandboard opened this issue Feb 12, 2025 · 5 comments

Comments

@expandboard
Copy link

expandboard commented Feb 12, 2025

This error be arisen when the subgraph is ran locally

1. Run anvil

anvil --host 0.0.0.0 --gas-limit 100000000000 --base-fee 1

2. Deploy the contracts

cd contracts
./deploy local

3. Run the graph node

cd subgraph
./start-graph

4. Deploy the subgraph

cd subgraph
./deploy-subgraph local --version v1 --create

Hardware

OS Ubuntu 24.10
RAM 16GB
:~/liquity/bold/subgraph$ sudo ./deploy-subgraph local --version v1 --create

Deploying subgraph:

  NAME:               liquity2/liquity2
  VERSION:            v1
  GRAPH NODE:         http://localhost:8020/
  IPFS NODE:          http://localhost:5001/
  CREATE:             yes
  DEBUG:              no


- Update sources network
  Reading networks config
- Update sources network
  Skip 'BoldToken': No changes to network configuration
- Update sources network
  Skip 'Governance': No changes to network configuration
- Update sources network
✔ Update sources network
- Apply migrations
  Skip migration: Bump mapping apiVersion from 0.0.1 to 0.0.2
- Apply migrations
  Skip migration: Bump mapping apiVersion from 0.0.2 to 0.0.3
- Apply migrations
  Skip migration: Bump mapping apiVersion from 0.0.3 to 0.0.4
- Apply migrations
  Skip migration: Bump mapping apiVersion from 0.0.4 to 0.0.5
- Apply migrations
  Skip migration: Bump mapping apiVersion from 0.0.5 to 0.0.6
- Apply migrations
  Skip migration: Bump manifest specVersion from 0.0.1 to 0.0.2
- Apply migrations
-   Skip migration: Bump manifest specVersion from 0.0.2 to 0.0.4
- Apply migrations
✔ Apply migrations
- Load subgraph from subgraph.yaml
✔ Load subgraph from subgraph.yaml
- Compile subgraph
  Compile data source: BoldToken => build/BoldToken/BoldToken.wasm
- Compile subgraph
✖ Failed to compile subgraph: Failed to compile data source mapping: 7 parse error(s)
Error: EEXIT: 1
    at Object.exit (/home/ubuntu/liquity/bold/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@oclif/core/lib/errors/index.js:21:11)
    at BuildCommand.exit (/home/ubuntu/liquity/bold/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@oclif/core/lib/command.js:131:23)
    at BuildCommand.run (/home/ubuntu/liquity/bold/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]/node_modules/@graphprotocol/graph-cli/dist/commands/build.js:76:22)
    at async BuildCommand._run (/home/ubuntu/liquity/bold/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@oclif/core/lib/command.js:117:22)
    at async Config.runCommand (/home/ubuntu/liquity/bold/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@oclif/core/lib/config/config.js:329:25)
    at async Object.run (/home/ubuntu/liquity/bold/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@oclif/core/lib/main.js:89:16)
Error: The AssemblyScript compiler crashed when compiling this file: 'src/BoldToken.mapping.ts'
Suggestion: try to comment the whole file and uncomment it little by little while re-running the graph-cli until you isolate the line where the problem happens.
Also, please contact us so we can make the CLI better by handling errors like this. You can reach out in any of these links:
- Discord channel: https://discord.gg/eM8CA6WA9r
- Github issues: https://github.com/graphprotocol/graph-tooling/issues/new/choose
    at process.<anonymous> (/home/ubuntu/liquity/bold/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]/node_modules/@graphprotocol/graph-cli/dist/compiler/asc.js:29:11)
    at process.emit (node:events:536:35)
    at process.exit (node:internal/process/per_thread:182:15)
    at Object.handle (/home/ubuntu/liquity/bold/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@oclif/core/lib/errors/handle.js:33:21)
    at module.exports (/home/ubuntu/liquity/bold/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@oclif/core/handle.js:1:58)

  Error: - Update sources network

  Reading networks config
- Update sources network
  Skip 'BoldToken': No changes to network configuration
- Update sources network
  Skip 'Governance': No changes to network configuration
- Update sources network
✔ Update sources network
- Apply migrations
  Skip migration: Bump mapping apiVersion from 0.0.1 to 0.0.2
- Apply migrations
  Skip migration: Bump mapping apiVersion from 0.0.2 to 0.0.3
- Apply migrations
  Skip migration: Bump mapping apiVersion from 0.0.3 to 0.0.4
- Apply migrations
  Skip migration: Bump mapping apiVersion from 0.0.4 to 0.0.5
- Apply migrations
  Skip migration: Bump mapping apiVersion from 0.0.5 to 0.0.6
- Apply migrations
  Skip migration: Bump manifest specVersion from 0.0.1 to 0.0.2
- Apply migrations
  Skip migration: Bump manifest specVersion from 0.0.2 to 0.0.4
- Apply migrations
✔ Apply migrations
- Load subgraph from subgraph.yaml
✔ Load subgraph from subgraph.yaml
- Compile subgraph
  Compile data source: BoldToken => build/BoldToken/BoldToken.wasm
- Compile subgraph
✖ Failed to compile subgraph: Failed to compile data source mapping: 7 parse error(s)
Error: EEXIT: 1

    at Object.exit (/home/ubuntu/liquity/bold/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@oclif/core/lib/errors/index.js:21:11)
    at BuildCommand.exit (/home/ubuntu/liquity/bold/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@oclif/core/lib/command.js:131:23)
    at BuildCommand.run (/home/ubuntu/liquity/bold/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]/node_modules/@graphprotocol/graph-cli/dist/commands/build.js:76:22)
    at async BuildCommand._run (/home/ubuntu/liquity/bold/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@oclif/core/lib/command.js:117:22)
    at async Config.runCommand (/home/ubuntu/liquity/bold/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@oclif/core/lib/config/config.js:329:25)
    at async Object.run (/home/ubuntu/liquity/bold/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@oclif/core/lib/main.js:89:16)
Error: The AssemblyScript compiler crashed when compiling this file: 'src/BoldToken.mapping.ts'
Suggestion: try to comment the whole file and uncomment it little by little while re-running the graph-cli until you isolate the line where the problem happens.
Also, please contact us so we can make the CLI better by handling errors like this. You can reach out in any of these links:
- Discord channel: https://discord.gg/eM8CA6WA9r
- Github issues: https://github.com/graphprotocol/graph-tooling/issues/new/choose
    at process.<anonymous> (/home/ubuntu/liquity/bold/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]/node_modules/@graphprotocol/graph-cli/dist/compiler/asc.js:29:11)
    at process.emit (node:events:536:35)
    at process.exit (node:internal/process/per_thread:182:15)
    at Object.handle (/home/ubuntu/liquity/bold/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@oclif/core/lib/errors/handle.js:33:21)
    at module.exports (/home/ubuntu/liquity/bold/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@oclif/core/handle.js:1:58)
    at Object.main (/home/ubuntu/liquity/bold/subgraph/cli/deploy-subgraph.ts:157:9)
    exit code: 1

@expandboard expandboard changed the title Error in Run the subgraph locally Error in Running the subgraph locally Feb 13, 2025
@bpierre
Copy link
Contributor

bpierre commented Feb 18, 2025

@expandboard do you get any error when running this command?

cd subgraph
pnpm asc src/BoldToken.mapping.ts

@expandboard
Copy link
Author

expandboard commented Feb 19, 2025

Thanks @bpierre . i ran and got this:

$ pnpm asc src/BoldToken.mapping.ts
 ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL  Command "asc" not found

do you use Mac or Linux?

@bpierre
Copy link
Contributor

bpierre commented Feb 21, 2025

@expandboard I am using Linux. This is weird, asc (assemblyscript package) should come from both @graphprotocol/graph-ts and @graphprotocol/graph-cli 🤔

Could you please paste your src/BoldToken.mapping.ts file? Also did you run pnpm install the last time you updated your branch? And do you have any change in the local files?

@expandboard
Copy link
Author

@bpierre the new run is same error. I tried to run pnpm install in root, contract and subgraph directories. asc package can not be find too. i used a new linux image.

import { Address, BigInt, DataSourceContext } from "@graphprotocol/graph-ts";
import {
  CollateralRegistryAddressChanged as CollateralRegistryAddressChangedEvent,
} from "../generated/BoldToken/BoldToken";
import { BorrowerOperations as BorrowerOperationsContract } from "../generated/BoldToken/BorrowerOperations";
import { CollateralRegistry as CollateralRegistryContract } from "../generated/BoldToken/CollateralRegistry";
import { ERC20 as ERC20Contract } from "../generated/BoldToken/ERC20";
import { TroveManager as TroveManagerContract } from "../generated/BoldToken/TroveManager";
import { Collateral, CollateralAddresses, StabilityPoolEpochScale, Token } from "../generated/schema";
import {
  StabilityPool as StabilityPoolTemplate,
  TroveManager as TroveManagerTemplate,
  TroveNFT as TroveNFTTemplate,
} from "../generated/templates";

function addCollateral(
  collIndex: i32,
  totalCollaterals: i32,
  tokenAddress: Address,
  troveManagerAddress: Address,
): void {
  let collId = collIndex.toString();

  let collateral = new Collateral(collId);
  collateral.collIndex = collIndex;
  collateral.token = collId;

  let token = new Token(collId);
  let tokenContract = ERC20Contract.bind(tokenAddress);
  token.collateral = collId;
  token.name = tokenContract.name();
  token.symbol = tokenContract.symbol();
  token.decimals = tokenContract.decimals();

  let troveManagerContract = TroveManagerContract.bind(troveManagerAddress);

  let addresses = new CollateralAddresses(collId);
  addresses.collateral = collId;
  addresses.borrowerOperations = troveManagerContract.borrowerOperations();
  addresses.sortedTroves = troveManagerContract.sortedTroves();
  addresses.stabilityPool = troveManagerContract.stabilityPool();
  addresses.token = tokenAddress;
  addresses.troveManager = troveManagerAddress;
  addresses.troveNft = troveManagerContract.troveNFT();

  collateral.minCollRatio = BorrowerOperationsContract.bind(
    Address.fromBytes(addresses.borrowerOperations),
  ).MCR();

  // initial collId + epoch + scale => S
  let spEpochScale = new StabilityPoolEpochScale(collId + ":0:0");
  spEpochScale.B = BigInt.fromI32(0);
  spEpochScale.S = BigInt.fromI32(0);

  collateral.save();
  token.save();
  addresses.save();
  spEpochScale.save();

  let context = new DataSourceContext();
  context.setBytes("address:borrowerOperations", addresses.borrowerOperations);
  context.setBytes("address:sortedTroves", addresses.sortedTroves);
  context.setBytes("address:stabilityPool", addresses.stabilityPool);
  context.setBytes("address:token", addresses.token);
  context.setBytes("address:troveManager", addresses.troveManager);
  context.setBytes("address:troveNft", addresses.troveNft);
  context.setString("collId", collId);
  context.setI32("collIndex", collIndex);
  context.setI32("totalCollaterals", totalCollaterals);

  TroveManagerTemplate.createWithContext(troveManagerAddress, context);
  TroveNFTTemplate.createWithContext(Address.fromBytes(addresses.troveNft), context);
  StabilityPoolTemplate.createWithContext(Address.fromBytes(addresses.stabilityPool), context);
}

export function handleCollateralRegistryAddressChanged(event: CollateralRegistryAddressChangedEvent): void {
  let registry = CollateralRegistryContract.bind(event.params._newCollateralRegistryAddress);
  let totalCollaterals = registry.totalCollaterals().toI32();

  for (let index = 0; index < totalCollaterals; index++) {
    let tokenAddress = Address.fromBytes(registry.getToken(BigInt.fromI32(index)));
    let troveManagerAddress = Address.fromBytes(registry.getTroveManager(BigInt.fromI32(index)));

    if (tokenAddress.toHex() === Address.zero().toHex() || troveManagerAddress.toHex() === Address.zero().toHex()) {
      break;
    }

    // we use the token address as the id for the collateral
    if (!Collateral.load(tokenAddress.toHexString())) {
      addCollateral(
        index,
        totalCollaterals,
        tokenAddress,
        troveManagerAddress,
      );
    }
  }
}

@bpierre
Copy link
Contributor

bpierre commented Feb 28, 2025

@expandboard asc should be there, as it comes from assemblyscript which is required by The Graph packages.

Could you please try to run this in the subgraph/ directory?

pnpm why assemblyscript --long

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants