Folks router error

Hi, i am trying to make folks router work, however it throws error.

    const quote = await folksRouterClient.fetchSwapQuote(
      0,
      452399768,
      BigInt(amount),
      SwapMode.FIXED_INPUT,
    );
    console.log("Quote",quote)
    if(quote.quoteAmount < BigInt(5_300_000)){
      console.log("Not swapping. Bad price",quote.quoteAmount,"<",BigInt(5_300_000))
      return;
    }
    const base64txns = await folksRouterClient.prepareSwapTransactions(sender, BigInt(0), quote);
    const unsignedTxns = base64txns.map(txn => decodeUnsignedTransaction(Buffer.from(txn, "base64")));
    const signedTxns = unsignedTxns.map(txn => txn.signTxn(acc.sk));
    let tx = await client.sendRawTransaction(signedTxns).do();
    console.log("tx",tx)

Error is:

{"message":"TransactionPool.Remember: transaction 4L4XR5SA7PBOFDBXGDERSLCYETXUWCOHOCF5PSAH6VL45V5BRUJQ: logic eval error: receiver error: must optin, asset 452399768 missing from AVBX7ME2FLXP6RA7FPI5C6Y6JJJ5JTNWKEFAOVRBCVJ3M4A66P3AQ427BE. Details: pc=1563, opcodes=frame_dig -3; callsub label21; itxn_submit"}

My next question is …

I have noted in the folks router client in fetchSwapQuote method

referrer?: string

How can I become the referrer?

(I think the first question is related as the generic referrer is probably not opted into the votecoin?)

1 Like

I found out this page Referral Program

I was not able to optin using prepareReferrerOptIntoAsset method, so i wrote my own


    const lsig = getReferrerLogicSig(referrerAddr);
    console.log("lsig address",lsig.lsig.address())
    const app = await  client.disassemble(lsig.lsig.logic).do()
    console.log("app",app)
    const txFund = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
       amount: 100_000,
       from: referrerAddr,
       to: lsig.lsig.address(),
       suggestedParams: {...params, fee: 2000, flatFee:true}
    })
    const txOptin = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({
       amount: 0,
       assetIndex: 452399768,
       from: lsig.lsig.address(),
       to: lsig.lsig.address(),
       suggestedParams: {...params, fee: 0, flatFee:true},
    })
    var toSignGrouped = algosdk.assignGroupID([txFund,txOptin]);
    console.log("toSignGrouped",toSignGrouped)
    signed.push(toSignGrouped[0].signTxn(refacc.sk));
    signed.push(algosdk.signLogicSigTransactionObject(toSignGrouped[1], lsig).blob)

    console.log("signed",signed)
    let tx = await client.sendRawTransaction(signed).do();
    console.log("tx",tx)

these seems to fund the referal escrow account

however this does not work either

no matter what i put in the referer, i get the error that account AVBX7ME2FLXP6RA7FPI5C6Y6JJJ5JTNWKEFAOVRBCVJ3M4A66P3AQ427BE is not opted in into the vote coin

can somebody please opt in the vote coin to the account Algorand Account ? Thanks

The Vote Coin is currently ranked Top #6 project token in algorand ecosystem.

Was also discussed in the folks forum Vote Coin as borrowable asset at Folks Finance

1 Like

Hi @Scholtz , I have opted in the referrer for the Folks Router Treasury account Q5Q5FC5PTYQIUX5PGNTEW22UJHJHVVUEMMWV2LSG6MGT33YQ54ST7FEIGA - group txn Algorand Group

1 Like

Thanks. i am getting now error at pc=1880… any idea how to continue?

{"message":"TransactionPool.Remember: transaction 6ENQFPGDQFYDOATDNCKODD5YQ6G7INS5NNBQRONJYEBF764EBT4Q: logic eval error: assert failed pc=1880. Details: pc=1880, opcodes=frame_dig -3; \\u003e=; assert"}

my code is now

const amount = 1_000_000;
const folksRouterClient = new FolksRouterClient(Network.MAINNET);
    const quote = await folksRouterClient.fetchSwapQuote(
      0,
      452399768,
      BigInt(amount),
      SwapMode.FIXED_INPUT,
      15,
      10,
      "AWALLETCPHQPJGCZ6AHLIFPHWBHUEHQ7VBYJVVGQRRY4MEIGWUBKCQYP4Y"
    );
    console.log("Quote",quote)
    if(quote.quoteAmount < BigInt(5_300_000)){
      console.log("Not swapping. Bad price",quote.quoteAmount,"<",BigInt(5_300_000))
      return;
    }
    const base64txns = await folksRouterClient.prepareSwapTransactions(sender, BigInt(0), quote);
    const unsignedTxns = base64txns.map(txn => decodeUnsignedTransaction(Buffer.from(txn, "base64")));
    const signedTxns = unsignedTxns.map(txn => txn.signTxn(acc.sk));
    let tx = await client.sendRawTransaction(signedTxns).do();
    console.log("tx",tx)

Btw its failing also with

    const quote = await folksRouterClient.fetchSwapQuote(
      0,
      452399768,
      BigInt(amount),
      SwapMode.FIXED_INPUT
    );
1 Like

You should increase the slippage and try again. There can be some rounding issues which mean 0 slippage doesn’t go through even if there are no changes. Also we are investigating reports from users who are experiencing the issue even with higher slippages.

1 Like

also with slipage at 10 it fails at the same place

with 50 it works

with 49 i get error

TransactionPool.Remember: transaction HIXJGAYADRCWM2WNUFOKEL33MAMEI2WGRRUGB5HSYDBC34GJHTHQ: logic eval error: underflow on subtracting 26936 from sender amount 26935. Details: pc=1587, opcodes=frame_dig -3; callsub label21; itxn_submit

with 30 i get error (pc=1880)

TransactionPool.Remember: transaction B7CRXYWD2JF5EHSESYYARE44BI4PST3YHFDUNH5NJI2TK32NOAJA: logic eval error: assert failed pc=1880. Details: pc=1880, opcodes=frame_dig -3; \\u003e=; assert

Now i received also with 50 error (pc=1587)

TransactionPool.Remember: transaction 63GBNZK64YQZW4S4OGYP6SP3YGGBWRBA3QGIZI7XX4LFPPCBYMEA: logic eval error: underflow on subtracting 26926 from sender amount 26925. Details: pc=1587, opcodes=frame_dig -3; callsub label21; itxn_submit

Looks like some rounding issue at some mid swap or when fees are deducted

I would say there might be also some error in quote calculation. With quote 53.968744 i have received the 53.738493 vote, 15 minutes later i have received the same quote 53.968744 and received 53.732695.

Interesting thing is that the vote has been traded beween 16:17:28 and 16:30:52 and it produces the same output. (but perhaps its just because i am swapping only 10 algos)

When tried to swap 1 algo to $vote, i get dynamic cost budget exceeded. (pc=544)

TransactionPool.Remember: transaction HDZZOXNA6FY6KGVI4KEMAWMV6ZGV7JJN26IXQKO54KRPJGPZLMAQ: logic eval error: pc=544 dynamic cost budget exceeded, executing frame_dig: local program cost was 354. Details: pc=544, opcodes=frame_bury 8; frame_dig 8; frame_dig -1
1 Like

Hi, i decided to implement folks router also in the AWallet, and I am getting the CORS error.

Can you allow on your server CORS for

https://www.a-wallet.net
https://main.h3.a-wallet.net
https://ww2.a-wallet.net
https://vercel.a-wallet.net
https://awallet.vercel.app
http://localhost:8080

Please?

I have integrated the folks router to AWallet, but i am not able to finish it properly until the cors issue is resolved… Any idea how to continue? To setup dummy proxy just to enable cors headers seems like waste of time, so i will wait a bit for response…

1 Like

Hey thanks for reporting, we think we have now resolved the issues with incorrect quotes. There might still be some slight rounding issues which I described above but otherwise should be good.

1 Like

Please try again and let us know if the integration works

1 Like

Hi, integration now works, however i am still getting the pc=1587 error on every tx i try.

I tried with different amounts…

Network request error. Received status 400 (): TransactionPool.Remember: transaction IAIEKIL7MPLXZS2GKY2D2OHGRRV5XCG64II47AI5UF63TON2WSYA: logic eval error: underflow on subtracting 2690 from sender amount 2689. Details: pc=1587, opcodes=frame_dig -3; callsub label21; itxn_submit
Network request error. Received status 400 (): TransactionPool.Remember: transaction WHRAJ2E2TSNX3WUIE7N5ZCDWFFMEY6MBMMRXZ24FKVDSQQ7362UA: logic eval error: underflow on subtracting 5376 from sender amount 5375. Details: pc=1587, opcodes=frame_dig -3; callsub label21; itxn_submit
Network request error. Received status 400 (): TransactionPool.Remember: transaction J6DS66UODDFJTWZWAU25VKAHEK5SXPZJ4JW2TIGWDZQBOFTMIOEA: logic eval error: underflow on subtracting 8065 from sender amount 8064. Details: pc=1587, opcodes=frame_dig -3; callsub label21; itxn_submit
Network request error. Received status 400 (): TransactionPool.Remember: transaction AN5A7W45USQANCOM5SCVR4BLR6WXZG5SYAJH5IXOW4BVD6CGDWMA: logic eval error: underflow on subtracting 10750 from sender amount 10749. Details: pc=1587, opcodes=frame_dig -3; callsub label21; itxn_submit
Network request error. Received status 400 (): TransactionPool.Remember: transaction 44JFU5RNU3HFC6INEQJYFS7AJIHODVUZ7DPPD4I2O53TXKYQ3YKQ: logic eval error: underflow on subtracting 13437 from sender amount 13436. Details: pc=1587, opcodes=frame_dig -3; callsub label21; itxn_submit

I noticed also the price impact result is strange… With only 1 algo to be swapped the price impact is calculated at 0.12% (TVL of main pool is over $50k), price impact of 10 algos is 0.18%, of 100 algos 0.21%, and 1000 algos 0.51%

I dont think that swapping only one algo to vote (at 0.02% lp pool) will move whole market 0,12%

Or the price impact is the real return what user will receive? (0,1% fee + 0,02% LP ) … Perhaps it would be better if api would return “minimumReceived” attribute and “minimumReceivedWithWorstSlippage”…

1 Like

We will look into the error

The price impact includes the fees charged. It is the absolute value of (actual - current) / current where actual is the quotation price (including all fees) and current is the DEX price excluding all fees.

1 Like

Great, thx.

So i can be sure that if i set slipage to zero, i will receive at least the quote amount… Right?

1 Like

Yes in the case of fixed input. When it is fixed output, the slippage controls how much of the asset is being sent from your account.

2 Likes

Are the logic eval error: underflow on subtracting errors coming from fixed input or fixed output swap? Also what slippage did you use?

1 Like

Input

1 Like

Hi @Scholtz, we deployed a new version of the folks router smart contract which should fix the issues you reported. Appreciate your help with identifying these! Let us know if it works for you

1 Like

works great. havent had any issue since the last fixes…

it is already deployed in AWallet in all environments

2 Likes

Hi @gidon , can I ask for favor?

In regards a build a bull hackathon I am working on ASA - Real gold | Buidls | DoraHacks

At the moment we fetch on testnet quotes for pairs
USDC-GOLD
ALGO-GOLD
BTC-GOLD

Can you please approve assets in folks router on testnet?

    gold: 450822081
    usdc: 37074699
    btc: 67396528

I have added enough liquidity to the testnet.pact.fi pools and also some to testnet.tinyman.org

When I try to swap from these assets to algo it returns 404 with info that route not found, however there are routes there… Or what can i do to enable it?

1 Like

Hey @Scholtz, in testnet the pools are hardcoded, so we need to add them manually, I added: 450869691 (USDC-GoldGram) and 450828268 ( ALGO-GoldGram) from Pact and JPJSYDZQSFREFJE3RJNPXBOHQAMJ66O7CINJVCS6O5BYTO6UGTTBJALZC4 (GoldGram-ALGO) from Tinyman.

2 Likes

Hi @palace22, @gidon,

can you please whitelist assets 1241944285 (Gold) and 1241945177 (GoldDAO) in the mainnet folks router please?

Thank you

1 Like