raydium-io / raydium-sdk-V2-demo

Open-source Typescript SDK demos
48 stars 31 forks source link

Input token account not found - no way to generate associated account during swap #62

Closed gladwinput closed 2 months ago

gladwinput commented 2 months ago

Error: [\"input token account not found\"]

await raydium.liquidity.swap({
  poolInfo,
  poolKeys,
  amountIn: new BN(amountIn),
  amountOut: out.minAmountOut,
  fixedSide: 'in',
  inputMint: mintIn.address,
  txVersion: txVersion,
  config: {
    inputUseSolBalance: true,
    outputUseSolBalance: true,
    associatedOnly: false,
  },
});

If you try to fire off a swap there's 1) no way to put a custom instruction to create the token and 2) if you try to create it to get the instruction to put it into a new transaction you setup with the custom instruction first it'll fail its check on swap anyway.

Possible to just get a flag to set up an associated token?

cruzshia commented 2 months ago

input token account not found means you don't have the token account you want to input, what's your wallet address and swap mint address? that means if you want to swap usdc -> sol, you must have usdc token accounts in your wallet or swap will fail even you add create a new token account in this tx (because your balance is zero).

gladwinput commented 2 months ago

Okay however if I am setting up a transaction under the understanding that later I when I execute the transaction the tokens will be there (due to transaction execution order) then I’d like to have the swap instructions ready to build the swap when it’s time. And at the moment I can’t do it because of the rejection. I’d have to explicitly wait for funds to come in then do the transaction instruction then trigger it which takes away some valuable time when I could pre-instruction and build the transaction to send when the time comes

cruzshia commented 2 months ago

const { execute, transaction, builder } = await raydium.liquidity.swap return transaction and all instructions in builder builder.allInstructions, you can build your own tx by combine these data, just ensure you have input mint balance(token account) before swap

gladwinput commented 2 months ago

Is there any way to suppress the errors though? because it throws them no matter what so you can't get the variables back

cruzshia commented 2 months ago

as I said previously, sent a small input mint amount to your wallet, it will create token account for you. you can't make swap tx without input mint token account.

gladwinput commented 2 months ago

but that's the problem - I need the instruction ready so that when the amount comes to the wallet I can create the swap (very time sensitive in my use case so every ms counts which is why I can't just wait until it arrives then create it). But I need to use this swap() to create the instruction. I would have to buy the input amount in another transaction with sol to get the token to then create this transaction to sell it, doesn't make sense

cruzshia commented 2 months ago

maybe you should fork our sdk and customize by yourself. validation code is here: https://github.com/raydium-io/raydium-sdk-V2/blob/master/src/raydium/liquidity/liquidity.ts#L870 we can't skip this check just for special cases.

gladwinput commented 2 months ago

Appreciated, will do that - quick question I see you compress it into an index.js, how do you compile this once amended? Haha a bit new to me

cruzshia commented 2 months ago

modify name/version in package.json and run yarn push will push sdk to npm regiestry, and of course you need to register a npm account (https://www.npmjs.com/), then you can run yarn install to get your customized package. if you just want to build, just run yarn build and you can find compressed index.js in dist directory

gladwinput commented 2 months ago

Appreciate you going out of your way to respond so helpfully