ston-fi / sdk

SDK for building applications on STON.fi protocol

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swap Example

unsphere opened this issue · comments

I am not able to get a swap working. The transaction will be sent successfully, but there is no exchange. Is there an error in my code?

const { publicKey, secretKey } = await mnemonicToWalletKey(
    mnemonic.split(' ')
  );

  const provider = new TonWeb.HttpProvider(
    'https://toncenter.com/api/v2/jsonRPC',
    {
      apiKey:
        '...',
    }
  );
  const tonweb = new TonWeb(provider);

  const Wallet = tonweb.wallet.all.v4R2;
  const wallet = new Wallet(provider, {
    publicKey,
  });
  const address = await wallet.getAddress();
  const nonBouncableAddress = address.toString(true, true, false);
  const seqno = (await wallet.methods.seqno().call()) || 0;

  const stonfiRouter = new Router(provider, {
    revision: ROUTER_REVISION.V1,
    address: ROUTER_REVISION_ADDRESS.V1,
  });

  const tonToJettonTxParams = await stonfiRouter.buildSwapProxyTonTxParams({
    userWalletAddress: nonBouncableAddress,
    proxyTonAddress: 'EQCM3B12QK1e4yZSf8GtBRT0aLMNyEsBc_DhVfRRtOEffLez',
    offerAmount: new TonWeb.utils.BN('100000000'),
    askJettonAddress: 'EQA2kCVNwVsil2EM2mB0SkXytxCqQjS4mttjDpnXmwG9T6bO', //STON
    minAskAmount: new TonWeb.utils.BN(1),
    queryId: 12345,
    referralAddress: undefined,
  });

  const result = await wallet.methods
    .transfer({
      secretKey,
      toAddress: ROUTER_REVISION_ADDRESS.V1,
      amount: tonToJettonTxParams.gasAmount,
      seqno: seqno,
      payload: tonToJettonTxParams.payload,
    })
    .send();

console.log(result);

/*
{
  "@type": "ok",
  "@extra": "1714167550.242306:8:0.9612518955091519",
}
*/

So the result looks okay to me, but I get TON sent back by the router:
Screenshot 2024-04-26 at 23 39 14

Any idea?

Fixed: Forgot to use sendMode