How I could obtain the current earnings of a farm from Maiar Exchange via Elrond REST API? For example, for the LKMEX farm I want to determine the current earnings (My Earned MEX) in MEX and/or USDT since the latest harverst or 'reinvest'. Thanks!
How I could obtain the current earnings of a farm from Maiar Exchange via Elrond REST API? For example, for the LKMEX farm I want to determine the current earnings (My Earned MEX) in MEX and/or USDT since the latest harverst or 'reinvest'. Thanks!
You have two options here:
Straightforward and low level way would be to ask the calculateRewardsForGivenPosition view function via vm query for the desired farm contract. This can be done via POST request through https://gateway.elrond.com/vm-values/query.
Check out https://docs.elrond.com/sdk-and-tools/rest-api/virtual-machine/ for vm-queries via REST API details and https://github.com/ElrondNetwork/sc-dex-rs/blob/main/dex/farm/src/lib.rs#L372 for the aforementioned view function's expected parameters.
Basically, you'll have to ask the farm contract for your latest rewards using just the Farm Token quantity and the attributes field of your Farm Token which you can find them out using the https://api.elrond.com/nfts/[token] route.
A concrete example for this case:
erd1qqqqqqqqqqqqqpgq7qhsw8kffad85jtt79t9ym0a4ycvan9a2jps0zkpenMEXFARML-28d646-360d8b via https://api.elrond.com/nfts/MEXFARML-28d646-360d8b : supply 2863539312887406729205021282 (we have to convert this to hex from decimal); attributes AAAABYENv6kdAAAAAAAAAg8AAAAAAAAC8QAAAAwGP0dX61aTZ298cosAAAAMAwFisUg/gGvN0gfWAAAADAlAqgkzlhPTPU56Yg== (we'll have to convert this from base64 to hex); For conversion, you can use this nifty tool: http://207.244.241.38/elrond-converters/The resulting VMQuery request looks like this:
POST https://gateway.elrond.com/vm-values/query HTTP/1.1
Content-Type: application/json
{
"scAddress": "erd1qqqqqqqqqqqqqpgq7qhsw8kffad85jtt79t9ym0a4ycvan9a2jps0zkpen",
"funcName": "calculateRewardsForGivenPosition",
"args": ["0940aa09339613d33d4e7a62", "00000005810dbfa91d000000000000020f00000000000002f10000000c063f4757eb5693676f7c728b0000000c030162b1483f806bcdd207d60000000c0940aa09339613d33d4e7a62"]
}
You'll then have to convert the response from base64 to decimal to get your rewards amount.
GraphQL Maiar DEX service requests: You'll have to get your hands dirty for this since the service repo is not public, so you'll have to reverse engineer your way into figuring our the requests you have to make and hope that the needed routes are not authenticated. This can be much easier to use, in theory, but requires some investigation work beforehand, as I was saying. One way to start into this is to just open up Maiar Exchange and investigate the network requests done by the site via the browser's developer console.