1

I'm developing subgraph for indexing blockchain events, but I get error when defining and object

⠋ Compile subgraphERROR TS2322: Type '<object>' is not assignable to type 'i32'.

 export const FARMS_CONTRACT_NAMES = {
  BALANCER_LIQUIDITY: 'balancerLiquidity',
  GIV_LIQUIDITY: 'givLiquidity',
  GIV_ETH: 'givETH',
  GIV_HNY: 'givHny'
};
                 
Mohammad Ranjbar Z
  • 1,487
  • 1
  • 10
  • 20

2 Answers2

2

If you want to use an object for your config you need to define a class for it, since AS doesn't have implicit objects:

class Config {
  BALANCER_LIQUIDITY: string;
  GIV_LIQUIDITY: string;
  GIV_ETH: string;
  GIV_HNY: string;
}

export const FARMS_CONTRACT_NAMES: Config = {
  BALANCER_LIQUIDITY: 'balancerLiquidity',
  GIV_LIQUIDITY: 'givLiquidity',
  GIV_ETH: 'givETH',
  GIV_HNY: 'givHny'
};

But exporting the values individually has it's benefits, too:

  • Less source code
  • You can import only parts of the config
  • No Class overhead
Sebastian Speitel
  • 7,166
  • 2
  • 19
  • 38
0

After some trial and error changing that in this way solved my problem:

export const BALANCER_LIQUIDITY = 'balancerLM';
export const GIV_LIQUIDITY = 'givLM';
export const GARDEN_POOL = 'gardenPool';
export const GIV_ETH = 'givETH';
export const GIV_HNY = 'givHNYPool';

I think assembly script has problems with defining objects ( in the functions input parameters you cant use object {} )

Mohammad Ranjbar Z
  • 1,487
  • 1
  • 10
  • 20