I'm trying to calculate the price of some tokens in an AMM (we're on Moonbeam so getting the price in USDC by routing it through GLMR-quoted pools)
export function tokenPrice(token: string): BigInt {
switch(token){
case DOT:
let glmrDot = GlmrDotContract.bind(Address.fromString(GLMR_DOT));
let glmrBalance = glmrDot.try_balanceOf(Address.fromString(WGLMR)).value;
let tokenBalance = glmrDot.try_balanceOf(Address.fromString(DOT)).value;
return tokenBalance.div(glmrBalance).div(priceOfGlmr())
case USDC:
const glmrUsdc = USDCGlmrContract.bind(Address.fromString(GLMR_USDC));
glmrBalance = glmrUsdc.try_balanceOf(Address.fromString(WGLMR)).value;
tokenBalance = glmrUsdc.try_balanceOf(Address.fromString(USDC)).value;
return glmrBalance.div(tokenBalance)
}
return BigInt.zero()
}
When I run my test in matchstick, I get
Could not find a mocked function for function with address: 0x555b…10d1, name: balanceOf, signature balanceOf(address):(uint256), params: [Address(0x0e358838ce72d5e61e0018a2ffac4bec5f4c88d2)]
Ideally, I'd have some way to stage tokens into that address, balanceOf would just work normally, reporting back the number of tokens in those pools so that my code could run.
Is there any way to do that? Or do have have to mock the call?