project-serum / serum-ts Goto Github PK
View Code? Open in Web Editor NEWProject Serum TypeScript monorepo
Home Page: https://projectserum.com
License: Apache License 2.0
Project Serum TypeScript monorepo
Home Page: https://projectserum.com
License: Apache License 2.0
Merge https://github.com/project-serum/serum-js with this repo
If a user places a non-sol account (e.g., a token account) into the beneficiary field, the user bricks the lockup, since it won't be able to sign with the address.
I'm using Phantom wallet which gives me a 88 character long private key. Adding this key to New Account gives me the error that the size of the private key is wrong.
We should disable the staking UI if a user has staking rewards available. This will help prevent a user from forgetting to collect the reward and therefore missing it once staking again.
This is a stopgap until we have either 1) separate event queues for each staker (which will make it safe to stake when a reward is outstanding) or 2) reward collection cranks to auto collect rewards.
If a token account is created after the app has been loaded, the OwnedTokenAccountsSelector
won't pickup the new account. This is because we do a fetch on initially loading the react app. Instead, we should open a websocket connection and stream updates.
How to reproduce:
Observed Error:
Uncaught (in promise) TypeError: exports.POOL_STATE_TAG.toBuffer is not a function
at Object.isPoolState (schema.js?b2c4:48)
at loadPoolInfo (index.js?4485:36)
Requested in Discord. https://discord.com/channels/739225212658122886/749297859807019209/783609499332116491
I'd be happy to provide a PR for this, but first I want to know if there's interest. From what I see, the Dex UI ends up accessing the _decoded.asks
and _decoded.bids
and then set up a listener using connection.onAccountChange()
on the public key of the ask/bid accounts.
market._decoded.asks
and not market. asksAddress
? The latter seems cleaner.onBidsChange
and onAsksChange
?serum-ts/packages/swap/src/index.ts
Line 733 in 3e6545c
serum-ts/packages/swap/src/index.ts
Line 734 in 3e6545c
serum-ts/packages/borsh/src/index.ts
Line 112 in b7e821e
export const MintLayout: typeof BufferLayout.Structure = BufferLayout.struct([
BufferLayout.u32('mintAuthorityOption'),
Layout.publicKey('mintAuthority'),
Layout.uint64('supply'),
BufferLayout.u8('decimals'),
BufferLayout.u8('isInitialized'),
BufferLayout.u32('freezeAuthorityOption'),
Layout.publicKey('freezeAuthority'),
]);
Currently, the Lockup page's unlock button allows a user to withdraw/unlock all tokens from a single vesting account. We should add an additional button that does this for all available vesting accounts, automatically, instead of requiring the user to go through each vesting account one by one.
Was just wondering if the JS example for interfacing with a Serum market needs updating. I've tried running it and run into the same error that the Market.load()
expects a programId
, otherwise it tries to do equality operations on an undefined argument. I imagine perhaps the API has changed in the meantime?
https://github.com/project-serum/serum-ts/blob/master/packages/serum/README.md
import { Account, Connection, PublicKey } from '@solana/web3.js';
import { Market } from '@project-serum/serum';
let connection = new Connection('https://testnet.solana.com');
let marketAddress = new PublicKey('...');
let market = await Market.load(connection, marketAddress);
Which throws the following error as described above:
return this._bn.eq(publicKey._bn);
^
TypeError: Cannot read property '_bn' of undefined
Managed to get around it simply by passing in the programId of the Serum v3 program:
let programId = new PublicKey('9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin'); // Serum program v3
let market = await Market.load(connection, marketAddress, {}, programId);
Loading market method described in packages/serum/readme is out of date. Can't run readme example.
let market = await Market.load(connection, marketAddress);
I am adding a fee wallet in the .env file and the settle gives me an error, when I remove it, the settle works correctly.
coin_mint
from smart contract becomes baseMint
in the typescript SDK, pc_mint
becomes quoteMint
and so on.
This can confuse those who are unfamiliar with market maker terminology. How about using similar variable names everywhere? It will be easier to make changes in the typescript SDK. Breaking change.
maxQuoteQuantity
is being calculated as price*quantity
, which fails to take fees into account when the order is a bid that matches against a resting offer. Instead, maxQuoteQuantity
should be set to price*quantity*(1+fee_rate)
, unless the order is post-only.
We are using many packages that are old versions. So I think we need to install Dependabot to resolve this problem radically. I'm not an expert on Dependabot, so we need more discussions :)
This is for DEX V3, RAY/USDC market, 2xiv8A5xrJ7RnGdxXB42uFEkYHJjszEhaJyKKt4WaLep
๐ Settling funds...
Transaction simulation failed: Error processing Instruction 0: custom program error: 0x100076b
Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin invoke [1]
Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin consumed 4284 of 200000 compute units
Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin failed: custom program error: 0x100076b
2021-03-12T21:32:09.174Z ๐ Error:
Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x100076b
at Connection.sendEncodedTransaction (/home/zenpoet/goldorak/node_modules/@solana/web3.js/lib/index.cjs.js:3556:13)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Connection.sendRawTransaction (/home/zenpoet/goldorak/node_modules/@solana/web3.js/lib/index.cjs.js:3517:20)
at async Connection.sendTransaction (/home/zenpoet/goldorak/node_modules/@solana/web3.js/lib/index.cjs.js:3507:12)
at async Market._sendTransaction (/home/zenpoet/goldorak/node_modules/@project-serum/serum/lib/market.js:446:27)
at async Market.settleFunds (/home/zenpoet/goldorak/node_modules/@project-serum/serum/lib/market.js:530:16)
at async main (/home/zenpoet/goldorak/settle.js:18:4)
My suggestion is to make the process of getting free and total balances as seamless as using a CEX API.
This can be done with a getBalances method that'd return a JSON with the free and total balances for each currency.
This is the only missing part to make the trading example entirely functional, since it's an essential part of any trading algorithm.
I had a real fun error where the MarketProxy wasn't even making it to the Serum DEX. Turns out it was caused by a Mint decimal change during a refactor and the lot size became larger than the mint's decimals. So everything was failing silently. The market initialized fine, but posting orders failed to proxy because the instruction data got mangled.
A simple fix would be on initialize market & new order instruction creation, validate the lots against the mint decimals.
the function market.findOpenOrdersAccountsForOwner() seems to be unreliable as it some times does not include all the accounts. For example the below code gave the following result:
async function getOpenOrderAccounts() {
let openOrderAccounts = await market.findOpenOrdersAccountsForOwner(
connection,
owner.publicKey,
)
console.log(openOrderAccounts.length)
for (let index = 0; index < openOrderAccounts.length; index++) {
const element = openOrderAccounts[index];
//console.log(element.address.toString())
if (element.address.toString() == openOrdersAccountAddress){
console.log('found our account')
for (let index2 = 0; index2 < element.orders.length; index2++) {
const element2 = element.orders[index2];
if (element2.toString() !== '0') {console.log(element2.toString())}
}
}
}
}
$ node test.js
95
found our account
5755384150997379837575
5755384150997379837573
5755384150997379837572
5755384150997379837571
$ node test.js
94
$ % node test.js
94
$ % node test.js
94
$ % node test.js
94
$ % node test.js
95
found our account
5755384150997379837575
5755384150997379837573
5755384150997379837572
5755384150997379837571
There have been some useful releases lately and @project-serum/serum
is not compatible with the latest version.
https://github.com/solana-labs/solana-web3.js/releases?after=v0.91.0
I think the NPM package is old. For example, it doesn't expose swapMarkets
, and has no estimate
method. Please publish the latest code?
for bundling purposes, I am trying to get it work for cloudflare worker. To enable tree shake, we should implement es6 module.
For easier setup, we can check out https://github.com/egoist/tsup for zero config configuration.
Let me know if I should create the PR for this
Currently, the claim button allows a user to claim a single reward from the event queue. We should either add a new button, or replace the existing button, with one that claims all the available rewards.
I started working on a candle batcher for the serum dex, based on the loadFills method in the serum-ts repo. From inspecting the output I figured that the eventQueue always contains both the taker & maker side of the trade. I started working on a bit of logic to match those and filter out duplicates, basically recover the actual matching in order to be able to record actual trades.
During testing I observed this scenario which doesn't really make sense to me, so I was wondering if anyone knows how to interpret this output: https://gist.github.com/mschneider/8a9a10b9bf7b7b37de43db6fc231c739
From what I understand we see here an order that got filled at two price levels:
For the first price level a corresponding maker order can be found. For the second it seems to be MIA.
I looked more into the matching engine to find if there is a case in which only a single Fill gets emitted, and it seems to be possible for multiple maker orders that collectively add up to a single larger taker fill to be emitted at once. The above scenario with more taker fills than maker fills seems not possible. ๐คท๐ปโโ๏ธ Any thoughts on what happened to the maker fill in that case?
makePlaceOrderTransaction
accepts as argument the payer public key that in this case is the SPL Token Account.
For some reason, many users has duplicate accounts with same token address. When order is executed, we don't have the ability to set the Token Metadata of the token to sell, so in many times we get transactions errors due this issue, the Serum Market Program tries to debit to a random account without check the balance.
Do we have a way to avoid duplicated accounts from same token address? or maybe better, do we have a way to merge duplicate accounts using json rpc?
Since v1.10.0
at @solana/web3.js
, Account
was deprecated. So we should update @solana/web3.js
package and replace Account
with KeyPair
.
Hi, not sure if it's an issue or it's how it should be but OXY/USDT market is included twice in markets.json
(both not depreciated), should this one be removed perhaps?
serum-ts/packages/serum/src/markets.json
Line 1197 in 9f581f0
Currently @project-serum/serum
only targets commonjs. We should provide a module as well.
Add missing markets such as COPE/USDC
Sometimes new order fails with the following:
Transaction simulation failed: Error processing Instruction 0: custom program error: 0x22
Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin invoke [1]
Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin consumed 8970 of 200000 compute units
Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin failed: custom program error: 0x22
/Users/borkur/Desktop/Coding/server-sunny/node_modules/@solana/web3.js/lib/index.cjs.js:4882
throw new SendTransactionError('failed to send transaction: ' + res.error.message, logs);
^
SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x22
at Connection.sendEncodedTransaction (/Users/borkur/Desktop/Coding/server-sunny/node_modules/@solana/web3.js/lib/index.cjs.js:4882:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Connection.sendRawTransaction (/Users/borkur/Desktop/Coding/server-sunny/node_modules/@solana/web3.js/lib/index.cjs.js:4840:20)
at async Connection.sendTransaction (/Users/borkur/Desktop/Coding/server-sunny/node_modules/@solana/web3.js/lib/index.cjs.js:4830:12)
at async Market._sendTransaction (/Users/borkur/Desktop/Coding/server-sunny/node_modules/@project-serum/serum/lib/market.js:504:27)
at async Market.placeOrder (/Users/borkur/Desktop/Coding/server-sunny/node_modules/@project-serum/serum/lib/market.js:249:16)
at async Timeout.startServer [as _onTimeout] (file:///Users/borkur/Desktop/Coding/server-sunny/server-sunny.js:215:5) {
logs: [
'Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin invoke [1]',
'Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin consumed 8970 of 200000 compute units',
'Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin failed: custom program error: 0x22'
]
}
Sometimes I get wrong balance. I'm fetching "unsettled" balance with the code below. Sometimes however I'm getting a result back that does not match with the gui. (The gui is correct.) If I settle the coins into my wallet and then resubmit them to the dex this usually fixes itself but then the problem reappears.
// Get balances
let openOrders = await market.findOpenOrdersAccountsForOwner(
connection,
owner.publicKey
);
baseTokenBalance = Math.floor(
openOrders[0].baseTokenFree.toNumber() / 1000000
);
quoteTokenBalance = Math.floor(
openOrders[0].quoteTokenFree.toNumber() / 1000000
);
console.log("--------------------------------------");
console.log("baseTokenBalanceFreeRAW: " + openOrders[0].baseTokenFree.toNumber());
console.log("quoteTokenBalanceFreeRAW: " + openOrders[0].quoteTokenFree.toNumber());
console.log("baseTokenBalanceFree: " + baseTokenBalance);
console.log("quoteTokenBalanceFree: " + quoteTokenBalance);
console.log("--------------------------------------");
I am using anchor 0.16.2, and following typescript packages
"@project-serum/anchor": "^0.16.2",
"@solana/spl-token": "^0.1.8",
"dotenv": "^10.0.0",
"yargs": "^16.2.0"
I set my solana config to the following variables
$ solana config get
Config File: /Users/raven/.config/solana/cli/config.yml
RPC URL: https://api.devnet.solana.com
WebSocket URL: wss://api.devnet.solana.com/ (computed)
Keypair Path: /Users/raven/.config/solana/id.json
Commitment: confirmed
and am invoking the following code
ANCHOR_PROVIDER_URL="https://api.devnet.solana.com" ANCHOR_WALLET=/Users/raven/.config/solana/id.json npm run serve
to run an expressJS server (typescript).
whenever I make an API call through the following code
const provider = anchor.getProvider()
const poolSigner = _poolSigner;
const currentBid = await getTokenAccount(provider, userRedeemable)
await exchangeUsdcForRedeemableRpc(
poolAccount,
poolSigner,
provider.wallet.publicKey,
userUsdc,
account.redeemableMint,
userRedeemable,
account.poolUsdc,
depositAmount,
);
I get an error
Error making the bidding request!
{}
Error: failed to get info about account AfQRhis7aZg6NmPpjrFN1KpZviMEp6H1VnKBzHkBxckK: FetchError: request to http://localhost:8899/ failed, reason: connect ECONNREFUSED 127.0.0.1:8899
at Connection.getAccountInfo (/Users/raven/imo-launchpad/example-server/node_modules/@solana/web3.js/src/connection.ts:2443:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async AccountClient.fetchNullable (/Users/raven/imo-launchpad/example-server/node_modules/@project-serum/anchor/src/program/namespace/account.ts:128:25)
at async AccountClient.fetch (/Users/raven/imo-launchpad/example-server/node_modules/@project-serum/anchor/src/program/namespace/account.ts:152:18)
In short: The request is made to the local testnet, instead of to devnet / the development cluster.
I find this weird, as in all instances that I could do, I have made sure to set the Solana cluster to https://api.devnet.solana.com
.
When I control-F the entire project, I only see the following code-snippet to include localhost:8899
as the link
static local(url?: string, opts?: ConfirmOptions): Provider {
opts = opts ?? Provider.defaultOptions();
const connection = new Connection(
url ?? "http://localhost:8899",
opts.preflightCommitment
);
const wallet = NodeWallet.local();
return new Provider(connection, wallet, opts);
}
manualy changing this in the node_modules
did not resolve this, however.
Is there anything wrong that I do, or anything I'm missing? The request is made to the local testnet, instead of to devnet / the development cluster.
Any help would be greatly appreciated, this is the last bug that stands between me and devnet.
This is for the ignition hackathon in 2 days, so I would appreciate any help a lot! :)
We should run these tests in CI against a localnetwork https://github.com/project-serum/serum-ts/blob/master/packages/registry/test/integration/e2e.spec.ts#L41, either here or in the serum-dex repo (where we already have the setup for integration tests against a localnet).
I am trying to decode serum order info directly from the blockchain history (rpc results) this issue will document the process of figuring out how, and offer a PR to improve the internal documentation.
Now, markets.json provide address of market only.
Could you please add Coin Vault, PC vault of market as well ?
https://solanabeach.io/transaction/DDJ9ugTdwbrn3JojTKkkgCwk3GnE9CW4qpG8KCv6ktjFy7CTLLouvBQzL1yWrwgbPnMdUjTk9BFZh5nhr4ghW67
Thank you !
Currently the error is meaningless to a user
Error creating srm pool: Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x1
Im using @solana/wallet-adapter, phantom adapter works fine with the integration, but coin98 or sollet, after signing the transactions, shows WalletSendTransactionError: Signature verification failed
I dont know if this is regarding the signTransaction implementation or something that I need to change in the integration itself
Currently, when transferring locked funds to the registry program, the "available for withdrawal" UI shows zero, which is correct. However, we should show an additional row representing the amount available for withdrawal if the funds were back in the lockup program, i.e., the amount vested.
Currently the lockup UI only shows SRM + MSRM. We should allow users to lockup arbitrary tokens (the backend program already allows it).
const connection = new Connection('...');
const marketAddress = new PublicKey('...');
const programAccount = new PublicKey("...");
let market = await Market.load(connection, marketAddress, { skipPreflight: false, confirmations: 0 }, programAccount);
const owner = new Account(...)
const payer = new PublicKey(...)
const openOrders = await market.findOpenOrdersAccountsForOwner(connection, payer)
for (const openOrder of openOrders) {
console.log(openOrder)
await market.cancelOrderByClientId(connection, owner, openOrder, 0)
}
And it's telling me:
(node:10605) UnhandledPromiseRejectionWarning: TypeError: src.toArrayLike is not a function
at BNLayout.encode (/home/wangge/serum_exp/node_modules/@project-serum/serum/lib/layout.js:44:33)
at Structure.encode (/home/wangge/serum_exp/node_modules/buffer-layout/lib/Layout.js:1272:26)
at VariantLayout.encode (/home/wangge/serum_exp/node_modules/buffer-layout/lib/Layout.js:1914:19)
at Union.encode (/home/wangge/serum_exp/node_modules/buffer-layout/lib/Layout.js:1730:16)
at VersionedLayout.encode (/home/wangge/serum_exp/node_modules/@project-serum/serum/lib/layout.js:94:31)
at encodeInstruction (/home/wangge/serum_exp/node_modules/@project-serum/serum/lib/instructions.js:41:50)
at Function.cancelOrderByClientId (/home/wangge/serum_exp/node_modules/@project-serum/serum/lib/instructions.js:156:19)
at Market.makeCancelOrderByClientIdTransaction (/home/wangge/serum_exp/node_modules/@project-serum/serum/lib/market.js:412:56)
at Market.cancelOrderByClientId (/home/wangge/serum_exp/node_modules/@project-serum/serum/lib/market.js:407:40)
at main (file:///home/wangge/serum_exp/index.js:24:22)
(node:10605) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:10605) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
If it's due to the error on my side, it will be really appreciated if someone can provide a working example. Many thanks~
Added any
here https://github.com/project-serum/serum-ts/blob/master/types/buffer-layout/index.d.ts#L2, so that @solana/spl-token
would compile for the swap
package. We should remove this any.
Current error without the any:
$ tsc -b && rollup -c rollup/rollup.config.ts
../../node_modules/@solana/spl-token/lib/index.d.ts(25,28): error TS2314: Generic type 'Layout<T>' requires 1 type argument(s).
../../node_modules/@solana/spl-token/lib/index.d.ts(34,31): error TS2314: Generic type 'Layout<T>' requires 1 type argument(s).
../../node_modules/@solana/spl-token-swap/lib/index.d.ts(29,33): error TS2314: Generic type 'Layout<T>' requires 1 type argument(s).
The given example here is out of date. The Market.load
function requires additional parameters including MarketOptions
as well as programId. For example the following is a valid invocation of Market.load
await Market.load(
provider.connection,
new anchor.web3.PublicKey("JCFHBoAxpFrKi9kShQdZCDUWjwCe1W25EvVza8DL8xwz"),
{},
new anchor.web3.PublicKey("DESVgJVGajEgKGXhb6XmqDHGz3VjdgP7rEVESBgxmroY"),
);
Getting this error when try to run this example https://github.com/project-serum/serum-ts/blob/master/packages/swap/examples/swap.js from swap package:
Error: 410 Gone: {"jsonrpc":"2.0","error":{"code": 410, "message":"The RPC call or parameters have been disabled."}, "id": "3b56fc88-1bd6-4b12-86b1-42482f87a777" }
at ClientBrowser.callServer (/home/aven/WebstormProjects/serum-ts/packages/swap/node_modules/@solana/web3.js/lib/index.cjs.js:4423:18)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
What is wrong?
Hello , I've got problem with 'placeOrder / side : buy'
but side : 'sell' is perfectly worked.
How to fix this problem ?
** This is my errors of side : 'buy' **
Desktop/serum/node_modules/@project-serum/serum/lib/market.js:409
throw new Error('Invalid payer account');
Error: Invalid payer account
at Market.makePlaceOrderTransaction (/Users/chain/Desktop/serum/node_modules/@project-serum/serum/lib/market.js:409:23)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Market.placeOrder (/Desktop/serum/node_modules/@project-serum/serum/lib/market.js:236:42)
at async file:///Desktop/serum/old.js:62:1
This is my config
PAIR : SOL/USDT
let marketAddress = new PublicKey('HWHvQhFmJB3NUcu1aihKmrKegfVxBEHzwVX6yZCKEsi1');
let programAddress = new PublicKey("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin");
โ await market.placeOrder(connection, {owner,payer,side: 'buy',price: 10,size: 0.1,orderType: 'limit',});
โ
await market.placeOrder(connection, {owner,payer,side: 'sell',price: 50,size: 0.1,orderType: 'limit',});
Thank You
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.