We need to ensure that liquidity and accurate pricing is consistently maintained, with LPs providing liquidity and earning fees in return. Various processes occur within a pool such as swapping, fee collection, arbitrage, etc.

Pair retrieval

****pool.getPair() → Retrieves the pair of tokens being traded in the pool.

It accesses the token pair from the environment's process tags. The tokens are identified as "Token-A" and "Token-B".

function pool.getPair()
  -- token A
  local tokenA = ao.env.Process.Tags["Token-A"]

  -- token B
  local tokenB = ao.env.Process.Tags["Token-B"]

  return { tokenA, tokenB }
end

Reserves retrieval

pool.getReserves() → Retrieves the reserves of each token in the pool.

The reserves of each token is returned.

-- Get reserves
function pool.getReserves() return Reserves end

Referring to the getReserves handler:

Handlers.add(
  "getReserves",
  Handlers.utils.hasMatchingTag("Action", "Get-Reserves"),
  function (msg)
    local res = pool.getReserves()
    local pair = pool.getPair()

    ao.send({
      Target = msg.From,
      [pair[1]] = tostring(res[pair[1]]),
      [pair[2]] = tostring(res[pair[2]])
    })
    print(json.encode(res))
  end
)

At the end, we print in JSON string format:

print(json.encode(res))

Expect the following output:

{
"Token-A": <reserveQty>,
"Token-B": <reserveQty>
}