bet-test-sdk 1.2.8 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +159 -11
- package/dist/browser/index.js +815 -4047
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/types/bet.d.ts +10 -4
- package/dist/browser/types/bet.d.ts.map +1 -1
- package/dist/browser/types/constants.d.ts +5 -5
- package/dist/browser/types/constants.d.ts.map +1 -1
- package/dist/browser/types/curveState.d.ts +8 -12
- package/dist/browser/types/curveState.d.ts.map +1 -1
- package/dist/browser/types/events.d.ts +3 -2
- package/dist/browser/types/events.d.ts.map +1 -1
- package/dist/browser/types/idl/bet.d.ts +605 -993
- package/dist/browser/types/idl/bet.d.ts.map +1 -1
- package/dist/browser/types/index.d.ts +0 -1
- package/dist/browser/types/index.d.ts.map +1 -1
- package/dist/browser/types/types.d.ts +26 -21
- package/dist/browser/types/types.d.ts.map +1 -1
- package/dist/browser/types/util.d.ts +2 -1
- package/dist/browser/types/util.d.ts.map +1 -1
- package/dist/cjs/bet.d.ts +10 -4
- package/dist/cjs/bet.d.ts.map +1 -1
- package/dist/cjs/bet.js +104 -49
- package/dist/cjs/bet.js.map +1 -1
- package/dist/cjs/constants.d.ts +5 -5
- package/dist/cjs/constants.d.ts.map +1 -1
- package/dist/cjs/constants.js +5 -5
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/curveState.d.ts +8 -12
- package/dist/cjs/curveState.d.ts.map +1 -1
- package/dist/cjs/curveState.js +66 -22
- package/dist/cjs/curveState.js.map +1 -1
- package/dist/cjs/events.d.ts +3 -2
- package/dist/cjs/events.d.ts.map +1 -1
- package/dist/cjs/events.js +28 -12
- package/dist/cjs/events.js.map +1 -1
- package/dist/cjs/idl/bet.d.ts +605 -993
- package/dist/cjs/idl/bet.d.ts.map +1 -1
- package/dist/cjs/idl/bet.json +563 -951
- package/dist/cjs/index.d.ts +0 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +0 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types.d.ts +26 -21
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/cjs/util.d.ts +2 -1
- package/dist/cjs/util.d.ts.map +1 -1
- package/dist/cjs/util.js +9 -5
- package/dist/cjs/util.js.map +1 -1
- package/dist/esm/bet.d.ts +10 -4
- package/dist/esm/bet.d.ts.map +1 -1
- package/dist/esm/bet.js +106 -51
- package/dist/esm/bet.js.map +1 -1
- package/dist/esm/constants.d.ts +5 -5
- package/dist/esm/constants.d.ts.map +1 -1
- package/dist/esm/constants.js +5 -5
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/curveState.d.ts +8 -12
- package/dist/esm/curveState.d.ts.map +1 -1
- package/dist/esm/curveState.js +67 -23
- package/dist/esm/curveState.js.map +1 -1
- package/dist/esm/events.d.ts +3 -2
- package/dist/esm/events.d.ts.map +1 -1
- package/dist/esm/events.js +26 -11
- package/dist/esm/events.js.map +1 -1
- package/dist/esm/idl/bet.d.ts +605 -993
- package/dist/esm/idl/bet.d.ts.map +1 -1
- package/dist/esm/idl/bet.json +563 -951
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types.d.ts +26 -21
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/util.d.ts +2 -1
- package/dist/esm/util.d.ts.map +1 -1
- package/dist/esm/util.js +6 -3
- package/dist/esm/util.js.map +1 -1
- package/package.json +1 -1
- package/dist/browser/types/amm.d.ts +0 -24
- package/dist/browser/types/amm.d.ts.map +0 -1
- package/dist/cjs/amm.d.ts +0 -24
- package/dist/cjs/amm.d.ts.map +0 -1
- package/dist/cjs/amm.js +0 -61
- package/dist/cjs/amm.js.map +0 -1
- package/dist/esm/amm.d.ts +0 -24
- package/dist/esm/amm.d.ts.map +0 -1
- package/dist/esm/amm.js +0 -57
- package/dist/esm/amm.js.map +0 -1
package/README.md
CHANGED
@@ -14,7 +14,7 @@ The `BetSDK` is designed to interact with the bet.com decentralized application.
|
|
14
14
|
npm i bet-test-sdk
|
15
15
|
`
|
16
16
|
|
17
|
-
## Notice (for developers)
|
17
|
+
## Notice (for front-end developers)
|
18
18
|
If you encounter an error regarding the `crypto` module when building a front-end project with frameworks such as React, Vue, or Next.js, consider installing a polyfill (for example, the node-polyfills plugin) or adding a crypto-browserify alias to your build configuration.
|
19
19
|
|
20
20
|
For example:
|
@@ -110,6 +110,27 @@ async getBuyInstructionsBySolAmount(
|
|
110
110
|
- `commitment`: Commitment level (default: DEFAULT_COMMITMENT).
|
111
111
|
- **Returns**: A promise that resolves to a `Transaction`.
|
112
112
|
|
113
|
+
#### getBuyInstructionsByTokenAmount
|
114
|
+
|
115
|
+
```typescript
|
116
|
+
async getBuyInstructionsByTokenAmount(
|
117
|
+
buyer: PublicKey,
|
118
|
+
mint: PublicKey,
|
119
|
+
buyAmountToken: bigint,
|
120
|
+
slippageBasisPoints: bigint = 500n,
|
121
|
+
commitment: Commitment = DEFAULT_COMMITMENT
|
122
|
+
): Promise<Transaction>
|
123
|
+
```
|
124
|
+
|
125
|
+
- Buys a specified amount of tokens by token input.
|
126
|
+
- **Parameters**:
|
127
|
+
- `buyer`: The public key of the buyer.
|
128
|
+
- `mint`: The public key of the mint account.
|
129
|
+
- `buyAmountToken`: Amount of token to buy.
|
130
|
+
- `slippageBasisPoints`: Slippage in basis points (default: 500).
|
131
|
+
- `commitment`: Commitment level (default: DEFAULT_COMMITMENT).
|
132
|
+
- **Returns**: A promise that resolves to a `Transaction`.
|
133
|
+
|
113
134
|
#### getSellInstructionsByTokenAmount
|
114
135
|
|
115
136
|
```typescript
|
@@ -129,6 +150,25 @@ async getSellInstructionsByTokenAmount(
|
|
129
150
|
- `slippageBasisPoints`: Slippage in basis points (default: 500)
|
130
151
|
- **Returns**: A promise that resolves to a `Transaction`.
|
131
152
|
|
153
|
+
#### getSellInstructionsBySolAmount
|
154
|
+
|
155
|
+
```typescript
|
156
|
+
async getSellInstructionsBySolAmount(
|
157
|
+
seller: PublicKey,
|
158
|
+
mint: PublicKey,
|
159
|
+
solAmountOut: bigint,
|
160
|
+
slippageBasisPoints: bigint = 500n,
|
161
|
+
): Promise<Transaction>
|
162
|
+
```
|
163
|
+
|
164
|
+
- Sells a specified amount of tokens.
|
165
|
+
- **Parameters**:
|
166
|
+
- `seller`: The public key of the seller.
|
167
|
+
- `mint`: The public key of the mint account.
|
168
|
+
- `solAmountOut`: Amount of sol to sell.
|
169
|
+
- `slippageBasisPoints`: Slippage in basis points (default: 500)
|
170
|
+
- **Returns**: A promise that resolves to a `Transaction`.
|
171
|
+
|
132
172
|
### Some preview methods for calculations
|
133
173
|
|
134
174
|
```typescript
|
@@ -235,7 +275,7 @@ const createAndBuyToken = async (sdk, testAccount) => {
|
|
235
275
|
}
|
236
276
|
};
|
237
277
|
|
238
|
-
const
|
278
|
+
const buyTokensWithSolAmount = async (sdk, testAccount, mint) => {
|
239
279
|
const curveStateAccount = await sdk.getCurveStateAccount(mint)
|
240
280
|
if (curveStateAccount) {
|
241
281
|
console.log(
|
@@ -244,7 +284,7 @@ const buyTokens = async (sdk, testAccount, mint) => {
|
|
244
284
|
);
|
245
285
|
return;
|
246
286
|
}
|
247
|
-
const buyResults = await sdk.
|
287
|
+
const buyResults = await sdk.buyWithSolAmount(
|
248
288
|
testAccount,
|
249
289
|
mint,
|
250
290
|
BigInt(0.001 * LAMPORTS_PER_SOL),
|
@@ -263,7 +303,35 @@ const buyTokens = async (sdk, testAccount, mint) => {
|
|
263
303
|
}
|
264
304
|
};
|
265
305
|
|
266
|
-
const
|
306
|
+
const buyTokensWithTokenAmount = async (sdk, testAccount, mint) => {
|
307
|
+
const curveStateAccount = await sdk.getCurveStateAccount(mint)
|
308
|
+
if (curveStateAccount) {
|
309
|
+
console.log(
|
310
|
+
"mint does not exist",
|
311
|
+
mint.toBase58()
|
312
|
+
);
|
313
|
+
return;
|
314
|
+
}
|
315
|
+
const buyResults = await sdk.buyWithTokenAmount(
|
316
|
+
testAccount,
|
317
|
+
mint,
|
318
|
+
BigInt(10000 * Math.pow(10, DEFAULT_DECIMALS)),
|
319
|
+
SLIPPAGE_BASIS_POINTS,
|
320
|
+
{
|
321
|
+
unitLimit: 500000,
|
322
|
+
unitPrice: 250000,
|
323
|
+
},
|
324
|
+
);
|
325
|
+
|
326
|
+
if (buyResults.success) {
|
327
|
+
printSPLBalance(sdk.connection, mint, testAccount.publicKey);
|
328
|
+
console.log("Curve state after buy", await sdk.getCurveStateAccount(mint));
|
329
|
+
} else {
|
330
|
+
console.log("Buy failed");
|
331
|
+
}
|
332
|
+
};
|
333
|
+
|
334
|
+
const sellTokensWithTokenAmount = async (sdk, testAccount, mint) => {
|
267
335
|
const currentSPLBalance = await getSPLBalance(
|
268
336
|
sdk.connection,
|
269
337
|
mint,
|
@@ -272,7 +340,7 @@ const sellTokens = async (sdk, testAccount, mint) => {
|
|
272
340
|
console.log("currentSPLBalance", currentSPLBalance);
|
273
341
|
|
274
342
|
if (currentSPLBalance) {
|
275
|
-
const sellResults = await sdk.
|
343
|
+
const sellResults = await sdk.sellWithTokenAmount(
|
276
344
|
testAccount,
|
277
345
|
mint,
|
278
346
|
BigInt(currentSPLBalance * Math.pow(10, DEFAULT_DECIMALS)),
|
@@ -293,6 +361,36 @@ const sellTokens = async (sdk, testAccount, mint) => {
|
|
293
361
|
}
|
294
362
|
};
|
295
363
|
|
364
|
+
const sellTokensWithSolAmount = async (sdk, testAccount, mint) => {
|
365
|
+
const currentSPLBalance = await getSPLBalance(
|
366
|
+
sdk.connection,
|
367
|
+
mint,
|
368
|
+
testAccount.publicKey
|
369
|
+
);
|
370
|
+
console.log("currentSPLBalance", currentSPLBalance);
|
371
|
+
|
372
|
+
if (currentSPLBalance) {
|
373
|
+
const sellResults = await sdk.sellWithSolAmount(
|
374
|
+
testAccount,
|
375
|
+
mint,
|
376
|
+
BigInt(0.001 * LAMPORTS_PER_SOL),
|
377
|
+
SLIPPAGE_BASIS_POINTS,
|
378
|
+
{
|
379
|
+
unitLimit: 500000,
|
380
|
+
unitPrice: 250000,
|
381
|
+
}
|
382
|
+
);
|
383
|
+
|
384
|
+
if (sellResults.success) {
|
385
|
+
await printSOLBalance(sdk.connection, testAccount.publicKey, "Test Account keypair");
|
386
|
+
printSPLBalance(sdk.connection, mint, testAccount.publicKey, "After SPL sell all");
|
387
|
+
console.log("Bet curve after sell", await sdk.getCurveStateAccount(mint));
|
388
|
+
} else {
|
389
|
+
console.log("Sell failed");
|
390
|
+
}
|
391
|
+
}
|
392
|
+
};
|
393
|
+
|
296
394
|
const main = async () => {
|
297
395
|
try {
|
298
396
|
const provider = getProvider();
|
@@ -318,8 +416,8 @@ const main = async () => {
|
|
318
416
|
}
|
319
417
|
|
320
418
|
if (curveStateAccount) {
|
321
|
-
await
|
322
|
-
await
|
419
|
+
await buyTokensWithSolAmount(sdk, testAccount, mint);
|
420
|
+
await sellTokensWithTokenAmount(sdk, testAccount, mint);
|
323
421
|
}
|
324
422
|
} catch (error) {
|
325
423
|
console.error("An error occurred:", error);
|
@@ -360,10 +458,10 @@ async createAndBuy(
|
|
360
458
|
- `finality`: Finality level (default: DEFAULT_FINALITY).
|
361
459
|
- **Returns**: A promise that resolves to a `TransactionResult`.
|
362
460
|
|
363
|
-
####
|
461
|
+
#### buyWithSolAmount
|
364
462
|
|
365
463
|
```typescript
|
366
|
-
async
|
464
|
+
async buyWithSolAmount(
|
367
465
|
buyer: Keypair,
|
368
466
|
mint: PublicKey,
|
369
467
|
buyAmountSol: bigint,
|
@@ -385,10 +483,35 @@ async buy(
|
|
385
483
|
- `finality`: Finality level (default: DEFAULT_FINALITY).
|
386
484
|
- **Returns**: A promise that resolves to a `TransactionResult`.
|
387
485
|
|
388
|
-
####
|
486
|
+
#### buyWithTokenAmount
|
487
|
+
|
488
|
+
```typescript
|
489
|
+
async buyWithTokenAmount(
|
490
|
+
buyer: Keypair,
|
491
|
+
mint: PublicKey,
|
492
|
+
buyAmountToken: bigint,
|
493
|
+
slippageBasisPoints: bigint = 500n,
|
494
|
+
priorityFees?: PriorityFee,
|
495
|
+
commitment: Commitment = DEFAULT_COMMITMENT,
|
496
|
+
finality: Finality = DEFAULT_FINALITY
|
497
|
+
): Promise<TransactionResult>
|
498
|
+
```
|
499
|
+
|
500
|
+
- Buys a specified amount of sols.
|
501
|
+
- **Parameters**:
|
502
|
+
- `buyer`: The keypair of the buyer.
|
503
|
+
- `mint`: The public key of the mint account.
|
504
|
+
- `buyAmountToken`: Amount of token to buy.
|
505
|
+
- `slippageBasisPoints`: Slippage in basis points (default: 500).
|
506
|
+
- `priorityFees`: Priority fees (optional).
|
507
|
+
- `commitment`: Commitment level (default: DEFAULT_COMMITMENT).
|
508
|
+
- `finality`: Finality level (default: DEFAULT_FINALITY).
|
509
|
+
- **Returns**: A promise that resolves to a `TransactionResult`.
|
510
|
+
|
511
|
+
#### sellWithTokenAmount
|
389
512
|
|
390
513
|
```typescript
|
391
|
-
async
|
514
|
+
async sellWithTokenAmount(
|
392
515
|
seller: Keypair,
|
393
516
|
mint: PublicKey,
|
394
517
|
sellTokenAmount: bigint,
|
@@ -410,6 +533,31 @@ async sell(
|
|
410
533
|
- `finality`: Finality level (default: DEFAULT_FINALITY).
|
411
534
|
- **Returns**: A promise that resolves to a `TransactionResult`.
|
412
535
|
|
536
|
+
#### sellWithSolAmount
|
537
|
+
|
538
|
+
```typescript
|
539
|
+
async sellWithSolAmount(
|
540
|
+
seller: Keypair,
|
541
|
+
mint: PublicKey,
|
542
|
+
sellSolAmount: bigint,
|
543
|
+
slippageBasisPoints: bigint = 500n,
|
544
|
+
priorityFees?: PriorityFee,
|
545
|
+
commitment: Commitment = DEFAULT_COMMITMENT,
|
546
|
+
finality: Finality = DEFAULT_FINALITY
|
547
|
+
): Promise<TransactionResult>
|
548
|
+
```
|
549
|
+
|
550
|
+
- Sells a specified amount of tokens.
|
551
|
+
- **Parameters**:
|
552
|
+
- `seller`: The keypair of the seller.
|
553
|
+
- `mint`: The public key of the mint account.
|
554
|
+
- `sellSolAmount`: Amount of sols to sell.
|
555
|
+
- `slippageBasisPoints`: Slippage in basis points (default: 500).
|
556
|
+
- `priorityFees`: Priority fees (optional).
|
557
|
+
- `commitment`: Commitment level (default: DEFAULT_COMMITMENT).
|
558
|
+
- `finality`: Finality level (default: DEFAULT_FINALITY).
|
559
|
+
- **Returns**: A promise that resolves to a `TransactionResult`.
|
560
|
+
|
413
561
|
#### addEventListener
|
414
562
|
|
415
563
|
```typescript
|