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'
};
                 

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 {} )

4

2 回答 2

1

如果你想为你的配置使用一个对象,你需要为它定义一个类,因为 AS 没有隐式对象:

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'
};

但是单独导出值也有好处:

  • 更少的源代码
  • 您只能导入部分配置
  • 没有类开销
于 2021-12-02T13:33:31.933 回答
1

经过一些试验和错误以这种方式改变它解决了我的问题:

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';

我认为汇编脚本在定义对象时存在问题(在函数输入参数中你不能使用 object {})

于 2021-12-02T05:01:17.950 回答