project-serum / serum-ts

Project Serum TypeScript monorepo
https://projectserum.com
Apache License 2.0
270 stars 245 forks source link

"base" and "quote" token accounts confusion #227

Closed ashpoolin closed 2 years ago

ashpoolin commented 2 years ago

Howdy,

For the serum client of this repo, I believe there is some confusion regarding the definitions of "base" and "quote" token accounts. These accounts are for storing unsettled tokens used within serum, and represent available funds to trade. Considering the trading pair RAY/SOL, it is my opinion that the "quote" token is the token you intend to buy, e.g. are "quoting" in a buy order, so in this case, RAY. Similarly, the "base" token should be the base of the pair (SOL), or the token that you sell in exchange for the quoted token during a buy order. It is helpful to remember every tx has both a "buy" and a "sell."

This isn't how serum appears to work, however. I can confirm that, when intending to buy RAY (for example), the payer must be the public key from the quote token account (which oddly accesses an address containing SOL). Conversely, to sell RAY, the RAY tokens will be found in the base token account. This is how I am accessing the base and quote token accounts, and setting up the payer for placing orders:

// 'buy' order (buy RAY / sell SOL) --> use "quote" token account (containing wrapped SOL) as payer 
const quote = await market.findQuoteTokenAccountsForOwner(connection, owner.publicKey, true);
const payer = quote[0].pubkey; 

// 'sell' order (sell RAY / buy SOL) --> use "base" token account (containing RAY) as payer
const base = await market.findBaseTokenAccountsForOwner(connection, owner.publicKey, true);
const payer = base[0].pubkey;

The definitions for the functions findBaseTokenAccountsForOwner(...) and findQuoteTokenAccountsForOwner(...) are found in the market.ts file, but I'm a bit of an idiot so it's not immediately obvious if the mixup takes place there, or if this is just some misunderstanding--on my part--about what a "quote" or "base" account is.

Thanks for looking into this, and please let me know if I can help!

ashpoolin commented 2 years ago

I WAS WRONG. It is a convention for quoting currency pairs that the first currency is the base, and the latter is the quote currency. So in RAY/SOL, as before, RAY is the base token and SOL is the quote token. However unintuitive this may be, it is not a deficiency in the software. I am satisfied, and will be closing this issue.