@drift-labs/sdk 2.30.0-beta.1 → 2.31.0-beta.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/lib/accounts/pollingTokenAccountSubscriber.d.ts +3 -3
- package/lib/accounts/pollingTokenAccountSubscriber.js +5 -2
- package/lib/accounts/types.d.ts +3 -3
- package/lib/adminClient.d.ts +1 -0
- package/lib/adminClient.js +9 -0
- package/lib/constants/spotMarkets.js +10 -0
- package/lib/dlob/DLOB.d.ts +20 -1
- package/lib/dlob/DLOB.js +39 -0
- package/lib/driftClient.d.ts +13 -8
- package/lib/driftClient.js +32 -27
- package/lib/examples/makeTradeExample.js +1 -1
- package/lib/idl/drift.json +106 -15
- package/lib/jupiter/jupiterClient.d.ts +1 -1
- package/lib/jupiter/jupiterClient.js +7 -2
- package/lib/math/spotBalance.d.ts +41 -0
- package/lib/math/spotBalance.js +41 -0
- package/lib/token/index.d.ts +3 -2
- package/lib/token/index.js +9 -32
- package/lib/tokenFaucet.d.ts +3 -3
- package/lib/tokenFaucet.js +4 -9
- package/lib/tx/retryTxSender.js +3 -0
- package/lib/types.d.ts +22 -2
- package/lib/types.js +12 -1
- package/lib/wallet.d.ts +5 -3
- package/lib/wallet.js +19 -7
- package/package.json +2 -2
- package/src/accounts/pollingTokenAccountSubscriber.ts +8 -5
- package/src/accounts/types.ts +3 -3
- package/src/adminClient.ts +19 -0
- package/src/constants/spotMarkets.ts +11 -0
- package/src/dlob/DLOB.ts +75 -0
- package/src/driftClient.ts +57 -53
- package/src/examples/makeTradeExample.ts +2 -4
- package/src/idl/drift.json +106 -15
- package/src/jupiter/jupiterClient.ts +10 -2
- package/src/math/spotBalance.ts +41 -0
- package/src/token/index.ts +12 -36
- package/src/tokenFaucet.ts +15 -34
- package/src/tx/retryTxSender.ts +4 -0
- package/src/types.ts +23 -2
- package/src/wallet.ts +34 -12
- package/tests/dlob/helpers.ts +1 -0
- package/tests/dlob/test.ts +218 -40
- package/lib/util/getTokenAddress.d.ts +0 -2
- package/lib/util/getTokenAddress.js +0 -9
- package/src/util/getTokenAddress.ts +0 -18
package/src/idl/drift.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
2
|
+
"version": "2.31.0-beta.0",
|
|
3
3
|
"name": "drift",
|
|
4
4
|
"instructions": [
|
|
5
5
|
{
|
|
@@ -863,6 +863,14 @@
|
|
|
863
863
|
"type": {
|
|
864
864
|
"option": "u64"
|
|
865
865
|
}
|
|
866
|
+
},
|
|
867
|
+
{
|
|
868
|
+
"name": "reduceOnly",
|
|
869
|
+
"type": {
|
|
870
|
+
"option": {
|
|
871
|
+
"defined": "SwapReduceOnly"
|
|
872
|
+
}
|
|
873
|
+
}
|
|
866
874
|
}
|
|
867
875
|
]
|
|
868
876
|
},
|
|
@@ -3636,6 +3644,32 @@
|
|
|
3636
3644
|
}
|
|
3637
3645
|
]
|
|
3638
3646
|
},
|
|
3647
|
+
{
|
|
3648
|
+
"name": "updatePerpMarketTargetBaseAssetAmountPerLp",
|
|
3649
|
+
"accounts": [
|
|
3650
|
+
{
|
|
3651
|
+
"name": "admin",
|
|
3652
|
+
"isMut": false,
|
|
3653
|
+
"isSigner": true
|
|
3654
|
+
},
|
|
3655
|
+
{
|
|
3656
|
+
"name": "state",
|
|
3657
|
+
"isMut": false,
|
|
3658
|
+
"isSigner": false
|
|
3659
|
+
},
|
|
3660
|
+
{
|
|
3661
|
+
"name": "perpMarket",
|
|
3662
|
+
"isMut": true,
|
|
3663
|
+
"isSigner": false
|
|
3664
|
+
}
|
|
3665
|
+
],
|
|
3666
|
+
"args": [
|
|
3667
|
+
{
|
|
3668
|
+
"name": "targetBaseAssetAmountPerLp",
|
|
3669
|
+
"type": "i32"
|
|
3670
|
+
}
|
|
3671
|
+
]
|
|
3672
|
+
},
|
|
3639
3673
|
{
|
|
3640
3674
|
"name": "updateLpCooldownTime",
|
|
3641
3675
|
"accounts": [
|
|
@@ -6441,7 +6475,8 @@
|
|
|
6441
6475
|
{
|
|
6442
6476
|
"name": "lastOracleNormalisedPrice",
|
|
6443
6477
|
"docs": [
|
|
6444
|
-
"the last seen oracle price partially shrunk toward the amm reserve price"
|
|
6478
|
+
"the last seen oracle price partially shrunk toward the amm reserve price",
|
|
6479
|
+
"precision: PRICE_PRECISION"
|
|
6445
6480
|
],
|
|
6446
6481
|
"type": "i64"
|
|
6447
6482
|
},
|
|
@@ -6455,21 +6490,24 @@
|
|
|
6455
6490
|
{
|
|
6456
6491
|
"name": "lastBidPriceTwap",
|
|
6457
6492
|
"docs": [
|
|
6458
|
-
"average estimate of bid price over funding_period"
|
|
6493
|
+
"average estimate of bid price over funding_period",
|
|
6494
|
+
"precision: PRICE_PRECISION"
|
|
6459
6495
|
],
|
|
6460
6496
|
"type": "u64"
|
|
6461
6497
|
},
|
|
6462
6498
|
{
|
|
6463
6499
|
"name": "lastAskPriceTwap",
|
|
6464
6500
|
"docs": [
|
|
6465
|
-
"average estimate of ask price over funding_period"
|
|
6501
|
+
"average estimate of ask price over funding_period",
|
|
6502
|
+
"precision: PRICE_PRECISION"
|
|
6466
6503
|
],
|
|
6467
6504
|
"type": "u64"
|
|
6468
6505
|
},
|
|
6469
6506
|
{
|
|
6470
6507
|
"name": "lastMarkPriceTwap",
|
|
6471
6508
|
"docs": [
|
|
6472
|
-
"average estimate of (bid+ask)/2 price over funding_period"
|
|
6509
|
+
"average estimate of (bid+ask)/2 price over funding_period",
|
|
6510
|
+
"precision: PRICE_PRECISION"
|
|
6473
6511
|
],
|
|
6474
6512
|
"type": "u64"
|
|
6475
6513
|
},
|
|
@@ -6491,14 +6529,15 @@
|
|
|
6491
6529
|
"name": "lastOracleConfPct",
|
|
6492
6530
|
"docs": [
|
|
6493
6531
|
"the pct size of the oracle confidence interval",
|
|
6494
|
-
"PERCENTAGE_PRECISION"
|
|
6532
|
+
"precision: PERCENTAGE_PRECISION"
|
|
6495
6533
|
],
|
|
6496
6534
|
"type": "u64"
|
|
6497
6535
|
},
|
|
6498
6536
|
{
|
|
6499
6537
|
"name": "netRevenueSinceLastFunding",
|
|
6500
6538
|
"docs": [
|
|
6501
|
-
"the total_fee_minus_distribution change since the last funding update"
|
|
6539
|
+
"the total_fee_minus_distribution change since the last funding update",
|
|
6540
|
+
"precision: QUOTE_PRECISION"
|
|
6502
6541
|
],
|
|
6503
6542
|
"type": "i64"
|
|
6504
6543
|
},
|
|
@@ -6519,28 +6558,32 @@
|
|
|
6519
6558
|
{
|
|
6520
6559
|
"name": "orderStepSize",
|
|
6521
6560
|
"docs": [
|
|
6522
|
-
"the base step size (increment) of orders"
|
|
6561
|
+
"the base step size (increment) of orders",
|
|
6562
|
+
"precision: BASE_PRECISION"
|
|
6523
6563
|
],
|
|
6524
6564
|
"type": "u64"
|
|
6525
6565
|
},
|
|
6526
6566
|
{
|
|
6527
6567
|
"name": "orderTickSize",
|
|
6528
6568
|
"docs": [
|
|
6529
|
-
"the price tick size of orders"
|
|
6569
|
+
"the price tick size of orders",
|
|
6570
|
+
"precision: PRICE_PRECISION"
|
|
6530
6571
|
],
|
|
6531
6572
|
"type": "u64"
|
|
6532
6573
|
},
|
|
6533
6574
|
{
|
|
6534
6575
|
"name": "minOrderSize",
|
|
6535
6576
|
"docs": [
|
|
6536
|
-
"the minimum base size of an order"
|
|
6577
|
+
"the minimum base size of an order",
|
|
6578
|
+
"precision: BASE_PRECISION"
|
|
6537
6579
|
],
|
|
6538
6580
|
"type": "u64"
|
|
6539
6581
|
},
|
|
6540
6582
|
{
|
|
6541
6583
|
"name": "maxPositionSize",
|
|
6542
6584
|
"docs": [
|
|
6543
|
-
"the max base size a single user can have"
|
|
6585
|
+
"the max base size a single user can have",
|
|
6586
|
+
"precision: BASE_PRECISION"
|
|
6544
6587
|
],
|
|
6545
6588
|
"type": "u64"
|
|
6546
6589
|
},
|
|
@@ -6576,14 +6619,16 @@
|
|
|
6576
6619
|
{
|
|
6577
6620
|
"name": "markStd",
|
|
6578
6621
|
"docs": [
|
|
6579
|
-
"estimate of standard deviation of the fill (mark) prices"
|
|
6622
|
+
"estimate of standard deviation of the fill (mark) prices",
|
|
6623
|
+
"precision: PRICE_PRECISION"
|
|
6580
6624
|
],
|
|
6581
6625
|
"type": "u64"
|
|
6582
6626
|
},
|
|
6583
6627
|
{
|
|
6584
6628
|
"name": "oracleStd",
|
|
6585
6629
|
"docs": [
|
|
6586
|
-
"estimate of standard deviation of the oracle price at each update"
|
|
6630
|
+
"estimate of standard deviation of the oracle price at each update",
|
|
6631
|
+
"precision: PRICE_PRECISION"
|
|
6587
6632
|
],
|
|
6588
6633
|
"type": "u64"
|
|
6589
6634
|
},
|
|
@@ -6660,7 +6705,8 @@
|
|
|
6660
6705
|
{
|
|
6661
6706
|
"name": "ammJitIntensity",
|
|
6662
6707
|
"docs": [
|
|
6663
|
-
"the jit intensity of AMM. larger intensity means larger participation in jit. 0 means no jit participation."
|
|
6708
|
+
"the jit intensity of AMM. larger intensity means larger participation in jit. 0 means no jit participation.",
|
|
6709
|
+
"(0, 100] is intensity for protocol-owned AMM. (100, 200] is intensity for user LP-owned AMM."
|
|
6664
6710
|
],
|
|
6665
6711
|
"type": "u8"
|
|
6666
6712
|
},
|
|
@@ -6680,12 +6726,20 @@
|
|
|
6680
6726
|
],
|
|
6681
6727
|
"type": "bool"
|
|
6682
6728
|
},
|
|
6729
|
+
{
|
|
6730
|
+
"name": "targetBaseAssetAmountPerLp",
|
|
6731
|
+
"docs": [
|
|
6732
|
+
"the target value for `base_asset_amount_per_lp`, used during AMM JIT with LP split",
|
|
6733
|
+
"precision: BASE_PRECISION"
|
|
6734
|
+
],
|
|
6735
|
+
"type": "i32"
|
|
6736
|
+
},
|
|
6683
6737
|
{
|
|
6684
6738
|
"name": "padding",
|
|
6685
6739
|
"type": {
|
|
6686
6740
|
"array": [
|
|
6687
6741
|
"u8",
|
|
6688
|
-
|
|
6742
|
+
44
|
|
6689
6743
|
]
|
|
6690
6744
|
}
|
|
6691
6745
|
}
|
|
@@ -7449,6 +7503,20 @@
|
|
|
7449
7503
|
]
|
|
7450
7504
|
}
|
|
7451
7505
|
},
|
|
7506
|
+
{
|
|
7507
|
+
"name": "SwapReduceOnly",
|
|
7508
|
+
"type": {
|
|
7509
|
+
"kind": "enum",
|
|
7510
|
+
"variants": [
|
|
7511
|
+
{
|
|
7512
|
+
"name": "In"
|
|
7513
|
+
},
|
|
7514
|
+
{
|
|
7515
|
+
"name": "Out"
|
|
7516
|
+
}
|
|
7517
|
+
]
|
|
7518
|
+
}
|
|
7519
|
+
},
|
|
7452
7520
|
{
|
|
7453
7521
|
"name": "TwapPeriod",
|
|
7454
7522
|
"type": {
|
|
@@ -7681,6 +7749,12 @@
|
|
|
7681
7749
|
},
|
|
7682
7750
|
{
|
|
7683
7751
|
"name": "OrderFillWithPhoenix"
|
|
7752
|
+
},
|
|
7753
|
+
{
|
|
7754
|
+
"name": "OrderFilledWithAMMJitLPSplit"
|
|
7755
|
+
},
|
|
7756
|
+
{
|
|
7757
|
+
"name": "OrderFilledWithLPJit"
|
|
7684
7758
|
}
|
|
7685
7759
|
]
|
|
7686
7760
|
}
|
|
@@ -7897,6 +7971,23 @@
|
|
|
7897
7971
|
]
|
|
7898
7972
|
}
|
|
7899
7973
|
},
|
|
7974
|
+
{
|
|
7975
|
+
"name": "AMMLiquiditySplit",
|
|
7976
|
+
"type": {
|
|
7977
|
+
"kind": "enum",
|
|
7978
|
+
"variants": [
|
|
7979
|
+
{
|
|
7980
|
+
"name": "ProtocolOwned"
|
|
7981
|
+
},
|
|
7982
|
+
{
|
|
7983
|
+
"name": "LPOwned"
|
|
7984
|
+
},
|
|
7985
|
+
{
|
|
7986
|
+
"name": "Shared"
|
|
7987
|
+
}
|
|
7988
|
+
]
|
|
7989
|
+
}
|
|
7990
|
+
},
|
|
7900
7991
|
{
|
|
7901
7992
|
"name": "SpotBalanceType",
|
|
7902
7993
|
"type": {
|
|
@@ -89,7 +89,7 @@ export class JupiterClient {
|
|
|
89
89
|
/**
|
|
90
90
|
* Get a swap transaction for a route
|
|
91
91
|
* @param route the route to perform swap
|
|
92
|
-
* @param userPublicKey the
|
|
92
|
+
* @param userPublicKey the signer's wallet public key
|
|
93
93
|
* @param slippageBps the slippage tolerance in basis points
|
|
94
94
|
*/
|
|
95
95
|
public async getSwapTransaction({
|
|
@@ -143,7 +143,9 @@ export class JupiterClient {
|
|
|
143
143
|
)
|
|
144
144
|
).filter((lookup) => lookup);
|
|
145
145
|
|
|
146
|
-
const transactionMessage = TransactionMessage.decompile(message
|
|
146
|
+
const transactionMessage = TransactionMessage.decompile(message, {
|
|
147
|
+
addressLookupTableAccounts: lookupTables,
|
|
148
|
+
});
|
|
147
149
|
return {
|
|
148
150
|
transactionMessage,
|
|
149
151
|
lookupTables,
|
|
@@ -190,6 +192,12 @@ export class JupiterClient {
|
|
|
190
192
|
return false;
|
|
191
193
|
}
|
|
192
194
|
|
|
195
|
+
if (
|
|
196
|
+
instruction.programId.toString() === '11111111111111111111111111111111'
|
|
197
|
+
) {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
|
|
193
201
|
if (
|
|
194
202
|
instruction.programId.toString() ===
|
|
195
203
|
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'
|
package/src/math/spotBalance.ts
CHANGED
|
@@ -23,6 +23,15 @@ import { OraclePriceData } from '../oracles/types';
|
|
|
23
23
|
import { PERCENTAGE_PRECISION } from '../constants/numericConstants';
|
|
24
24
|
import { divCeil } from './utils';
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Calculates the balance of a given token amount including any accumulated interest. This
|
|
28
|
+
* is the same as `SpotPosition.scaledBalance`.
|
|
29
|
+
*
|
|
30
|
+
* @param {BN} tokenAmount - the amount of tokens
|
|
31
|
+
* @param {SpotMarketAccount} spotMarket - the spot market account
|
|
32
|
+
* @param {SpotBalanceType} balanceType - the balance type ('deposit' or 'borrow')
|
|
33
|
+
* @return {BN} the calculated balance, scaled by `SPOT_MARKET_BALANCE_PRECISION`
|
|
34
|
+
*/
|
|
26
35
|
export function getBalance(
|
|
27
36
|
tokenAmount: BN,
|
|
28
37
|
spotMarket: SpotMarketAccount,
|
|
@@ -43,6 +52,14 @@ export function getBalance(
|
|
|
43
52
|
return balance;
|
|
44
53
|
}
|
|
45
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Calculates the spot token amount including any accumulated interest.
|
|
57
|
+
*
|
|
58
|
+
* @param {BN} balanceAmount - The balance amount, typically from `SpotPosition.scaledBalance`
|
|
59
|
+
* @param {SpotMarketAccount} spotMarket - The spot market account details
|
|
60
|
+
* @param {SpotBalanceType} balanceType - The balance type to be used for calculation
|
|
61
|
+
* @returns {BN} The calculated token amount, scaled by `SpotMarketConfig.precision`
|
|
62
|
+
*/
|
|
46
63
|
export function getTokenAmount(
|
|
47
64
|
balanceAmount: BN,
|
|
48
65
|
spotMarket: SpotMarketAccount,
|
|
@@ -62,6 +79,13 @@ export function getTokenAmount(
|
|
|
62
79
|
}
|
|
63
80
|
}
|
|
64
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Returns the signed (positive for deposit,negative for borrow) token amount based on the balance type.
|
|
84
|
+
*
|
|
85
|
+
* @param {BN} tokenAmount - The token amount to convert (from `getTokenAmount`)
|
|
86
|
+
* @param {SpotBalanceType} balanceType - The balance type to determine the sign of the token amount.
|
|
87
|
+
* @returns {BN} - The signed token amount, scaled by `SpotMarketConfig.precision`
|
|
88
|
+
*/
|
|
65
89
|
export function getSignedTokenAmount(
|
|
66
90
|
tokenAmount: BN,
|
|
67
91
|
balanceType: SpotBalanceType
|
|
@@ -73,6 +97,15 @@ export function getSignedTokenAmount(
|
|
|
73
97
|
}
|
|
74
98
|
}
|
|
75
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Calculates the value of a given token amount using the worst of the provided oracle price and its TWAP.
|
|
102
|
+
*
|
|
103
|
+
* @param {BN} tokenAmount - The amount of tokens to calculate the value for (from `getTokenAmount`)
|
|
104
|
+
* @param {number} spotDecimals - The number of decimals in the token.
|
|
105
|
+
* @param {OraclePriceData} oraclePriceData - The oracle price data (typically a token/USD oracle).
|
|
106
|
+
* @param {BN} oraclePriceTwap - The Time-Weighted Average Price of the oracle.
|
|
107
|
+
* @return {BN} The calculated value of the given token amount, scaled by `PRICE_PRECISION`
|
|
108
|
+
*/
|
|
76
109
|
export function getStrictTokenValue(
|
|
77
110
|
tokenAmount: BN,
|
|
78
111
|
spotDecimals: number,
|
|
@@ -95,6 +128,14 @@ export function getStrictTokenValue(
|
|
|
95
128
|
return tokenAmount.mul(price).div(precisionDecrease);
|
|
96
129
|
}
|
|
97
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Calculates the value of a given token amount in relation to an oracle price data
|
|
133
|
+
*
|
|
134
|
+
* @param {BN} tokenAmount - The amount of tokens to calculate the value for (from `getTokenAmount`)
|
|
135
|
+
* @param {number} spotDecimals - The number of decimal places of the token.
|
|
136
|
+
* @param {OraclePriceData} oraclePriceData - The oracle price data (typically a token/USD oracle).
|
|
137
|
+
* @return {BN} The value of the token based on the oracle, scaled by `PRICE_PRECISION`
|
|
138
|
+
*/
|
|
98
139
|
export function getTokenValue(
|
|
99
140
|
tokenAmount: BN,
|
|
100
141
|
spotDecimals: number,
|
package/src/token/index.ts
CHANGED
|
@@ -1,37 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PublicKey } from '@solana/web3.js';
|
|
3
|
-
|
|
4
|
-
export function parseTokenAccount(data: Buffer):
|
|
5
|
-
|
|
6
|
-
accountInfo
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
accountInfo.delegatedAmount = u64.fromBuffer(Buffer.from('0'));
|
|
14
|
-
} else {
|
|
15
|
-
accountInfo.delegate = new PublicKey(accountInfo.delegate);
|
|
16
|
-
accountInfo.delegatedAmount = u64.fromBuffer(accountInfo.delegatedAmount);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
accountInfo.isInitialized = accountInfo.state !== 0;
|
|
20
|
-
accountInfo.isFrozen = accountInfo.state === 2;
|
|
21
|
-
|
|
22
|
-
if (accountInfo.isNativeOption === 1) {
|
|
23
|
-
accountInfo.rentExemptReserve = u64.fromBuffer(accountInfo.isNative);
|
|
24
|
-
accountInfo.isNative = true;
|
|
25
|
-
} else {
|
|
26
|
-
accountInfo.rentExemptReserve = null;
|
|
27
|
-
accountInfo.isNative = false;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (accountInfo.closeAuthorityOption === 0) {
|
|
31
|
-
accountInfo.closeAuthority = null;
|
|
32
|
-
} else {
|
|
33
|
-
accountInfo.closeAuthority = new PublicKey(accountInfo.closeAuthority);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return accountInfo;
|
|
1
|
+
import { Account, TOKEN_PROGRAM_ID, unpackAccount } from '@solana/spl-token';
|
|
2
|
+
import { PublicKey, AccountInfo } from '@solana/web3.js';
|
|
3
|
+
|
|
4
|
+
export function parseTokenAccount(data: Buffer, pubkey: PublicKey): Account {
|
|
5
|
+
// mock AccountInfo so unpackAccount can be used
|
|
6
|
+
const accountInfo: AccountInfo<Buffer> = {
|
|
7
|
+
data,
|
|
8
|
+
owner: TOKEN_PROGRAM_ID,
|
|
9
|
+
executable: false,
|
|
10
|
+
lamports: 0,
|
|
11
|
+
};
|
|
12
|
+
return unpackAccount(pubkey, accountInfo, TOKEN_PROGRAM_ID);
|
|
37
13
|
}
|
package/src/tokenFaucet.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as anchor from '@coral-xyz/anchor';
|
|
2
2
|
import { AnchorProvider, Idl, Program } from '@coral-xyz/anchor';
|
|
3
3
|
import {
|
|
4
|
-
AccountInfo,
|
|
5
|
-
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
6
|
-
Token,
|
|
7
4
|
TOKEN_PROGRAM_ID,
|
|
5
|
+
getAccount,
|
|
6
|
+
Account,
|
|
7
|
+
createAssociatedTokenAccountInstruction,
|
|
8
|
+
getAssociatedTokenAddress,
|
|
8
9
|
} from '@solana/spl-token';
|
|
9
10
|
import {
|
|
10
11
|
ConfirmOptions,
|
|
@@ -174,15 +175,12 @@ export class TokenFaucet {
|
|
|
174
175
|
{ userPubKey: userPublicKey }
|
|
175
176
|
);
|
|
176
177
|
|
|
177
|
-
const createAssociatedAccountIx =
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
userPublicKey,
|
|
184
|
-
this.wallet.publicKey
|
|
185
|
-
);
|
|
178
|
+
const createAssociatedAccountIx = createAssociatedTokenAccountInstruction(
|
|
179
|
+
this.wallet.publicKey,
|
|
180
|
+
associateTokenPublicKey,
|
|
181
|
+
userPublicKey,
|
|
182
|
+
state.mint
|
|
183
|
+
);
|
|
186
184
|
|
|
187
185
|
const mintToIx = await this.mintToUserIx(associateTokenPublicKey, amount);
|
|
188
186
|
|
|
@@ -194,36 +192,19 @@ export class TokenFaucet {
|
|
|
194
192
|
}): Promise<anchor.web3.PublicKey> {
|
|
195
193
|
const state: any = await this.fetchState();
|
|
196
194
|
|
|
197
|
-
return
|
|
198
|
-
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
199
|
-
TOKEN_PROGRAM_ID,
|
|
200
|
-
state.mint,
|
|
201
|
-
props.userPubKey
|
|
202
|
-
);
|
|
195
|
+
return getAssociatedTokenAddress(state.mint, props.userPubKey);
|
|
203
196
|
}
|
|
204
197
|
|
|
205
198
|
public async getTokenAccountInfo(props: {
|
|
206
199
|
userPubKey: PublicKey;
|
|
207
|
-
}): Promise<
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
const state: any = await this.fetchState();
|
|
211
|
-
|
|
212
|
-
const token = new Token(
|
|
213
|
-
this.connection,
|
|
214
|
-
state.mint,
|
|
215
|
-
TOKEN_PROGRAM_ID,
|
|
216
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
217
|
-
// @ts-ignore
|
|
218
|
-
this.provider.payer
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
return await token.getAccountInfo(assosciatedKey);
|
|
200
|
+
}): Promise<Account> {
|
|
201
|
+
const associatedKey = await this.getAssosciatedMockUSDMintAddress(props);
|
|
202
|
+
return await getAccount(this.connection, associatedKey);
|
|
222
203
|
}
|
|
223
204
|
|
|
224
205
|
public async subscribeToTokenAccount(props: {
|
|
225
206
|
userPubKey: PublicKey;
|
|
226
|
-
callback: (accountInfo:
|
|
207
|
+
callback: (accountInfo: Account) => void;
|
|
227
208
|
}): Promise<boolean> {
|
|
228
209
|
try {
|
|
229
210
|
const tokenAccountKey = await this.getAssosciatedMockUSDMintAddress(
|
package/src/tx/retryTxSender.ts
CHANGED
|
@@ -122,6 +122,10 @@ export class RetryTxSender implements TxSender {
|
|
|
122
122
|
// @ts-ignore
|
|
123
123
|
tx.sign((additionalSigners ?? []).concat(this.provider.wallet.payer));
|
|
124
124
|
|
|
125
|
+
if (opts === undefined) {
|
|
126
|
+
opts = this.provider.opts;
|
|
127
|
+
}
|
|
128
|
+
|
|
125
129
|
return this.sendRawTransaction(tx.serialize(), opts);
|
|
126
130
|
}
|
|
127
131
|
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PublicKey, Transaction } from '@solana/web3.js';
|
|
1
|
+
import { PublicKey, Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
2
2
|
import { BN, ZERO } from '.';
|
|
3
3
|
|
|
4
4
|
// # Utility Types / Enums / Constants
|
|
@@ -133,6 +133,12 @@ export class OrderActionExplanation {
|
|
|
133
133
|
static readonly ORDER_FILLED_WITH_AMM_JIT = {
|
|
134
134
|
orderFilledWithAmmJit: {},
|
|
135
135
|
};
|
|
136
|
+
static readonly ORDER_FILLED_WITH_AMM_JIT_LP_SPLIT = {
|
|
137
|
+
orderFilledWithAmmJitLpSplit: {},
|
|
138
|
+
};
|
|
139
|
+
static readonly ORDER_FILLED_WITH_LP_JIT = {
|
|
140
|
+
orderFilledWithAmmJitLpSplit: {},
|
|
141
|
+
};
|
|
136
142
|
static readonly ORDER_FILLED_WITH_MATCH = {
|
|
137
143
|
orderFilledWithMatch: {},
|
|
138
144
|
};
|
|
@@ -506,7 +512,7 @@ export type OrderActionRecord = {
|
|
|
506
512
|
};
|
|
507
513
|
|
|
508
514
|
export type SwapRecord = {
|
|
509
|
-
ts:
|
|
515
|
+
ts: BN;
|
|
510
516
|
user: PublicKey;
|
|
511
517
|
amountOut: BN;
|
|
512
518
|
amountIn: BN;
|
|
@@ -730,6 +736,7 @@ export type AMM = {
|
|
|
730
736
|
|
|
731
737
|
baseAssetAmountPerLp: BN;
|
|
732
738
|
quoteAssetAmountPerLp: BN;
|
|
739
|
+
targetBaseAssetAmountPerLp: number;
|
|
733
740
|
|
|
734
741
|
ammJitIntensity: number;
|
|
735
742
|
maxOpenInterest: BN;
|
|
@@ -951,12 +958,26 @@ export type TxParams = {
|
|
|
951
958
|
computeUnitsPrice?: number;
|
|
952
959
|
};
|
|
953
960
|
|
|
961
|
+
export class SwapReduceOnly {
|
|
962
|
+
static readonly In = { in: {} };
|
|
963
|
+
static readonly Out = { out: {} };
|
|
964
|
+
}
|
|
965
|
+
|
|
954
966
|
// # Misc Types
|
|
955
967
|
export interface IWallet {
|
|
956
968
|
signTransaction(tx: Transaction): Promise<Transaction>;
|
|
957
969
|
signAllTransactions(txs: Transaction[]): Promise<Transaction[]>;
|
|
958
970
|
publicKey: PublicKey;
|
|
959
971
|
}
|
|
972
|
+
export interface IVersionedWallet {
|
|
973
|
+
signVersionedTransaction(
|
|
974
|
+
tx: VersionedTransaction
|
|
975
|
+
): Promise<VersionedTransaction>;
|
|
976
|
+
signAllVersionedTransactions(
|
|
977
|
+
txs: VersionedTransaction[]
|
|
978
|
+
): Promise<VersionedTransaction[]>;
|
|
979
|
+
publicKey: PublicKey;
|
|
980
|
+
}
|
|
960
981
|
|
|
961
982
|
export type FeeStructure = {
|
|
962
983
|
feeTiers: FeeTier[];
|
package/src/wallet.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
Keypair,
|
|
3
|
+
PublicKey,
|
|
4
|
+
Transaction,
|
|
5
|
+
VersionedTransaction,
|
|
6
|
+
} from '@solana/web3.js';
|
|
7
|
+
import { IWallet, IVersionedWallet } from './types';
|
|
3
8
|
import fs from 'fs';
|
|
4
9
|
import bs58 from 'bs58';
|
|
5
10
|
|
|
6
|
-
export class Wallet implements IWallet {
|
|
11
|
+
export class Wallet implements IWallet, IVersionedWallet {
|
|
7
12
|
constructor(readonly payer: Keypair) {}
|
|
8
13
|
|
|
9
14
|
async signTransaction(tx: Transaction): Promise<Transaction> {
|
|
@@ -11,6 +16,13 @@ export class Wallet implements IWallet {
|
|
|
11
16
|
return tx;
|
|
12
17
|
}
|
|
13
18
|
|
|
19
|
+
async signVersionedTransaction(
|
|
20
|
+
tx: VersionedTransaction
|
|
21
|
+
): Promise<VersionedTransaction> {
|
|
22
|
+
tx.sign([this.payer]);
|
|
23
|
+
return tx;
|
|
24
|
+
}
|
|
25
|
+
|
|
14
26
|
async signAllTransactions(txs: Transaction[]): Promise<Transaction[]> {
|
|
15
27
|
return txs.map((t) => {
|
|
16
28
|
t.partialSign(this.payer);
|
|
@@ -18,6 +30,15 @@ export class Wallet implements IWallet {
|
|
|
18
30
|
});
|
|
19
31
|
}
|
|
20
32
|
|
|
33
|
+
async signAllVersionedTransactions(
|
|
34
|
+
txs: VersionedTransaction[]
|
|
35
|
+
): Promise<VersionedTransaction[]> {
|
|
36
|
+
return txs.map((t) => {
|
|
37
|
+
t.sign([this.payer]);
|
|
38
|
+
return t;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
21
42
|
get publicKey(): PublicKey {
|
|
22
43
|
return this.payer.publicKey;
|
|
23
44
|
}
|
|
@@ -27,17 +48,18 @@ export function loadKeypair(privateKey: string): Keypair {
|
|
|
27
48
|
// try to load privateKey as a filepath
|
|
28
49
|
let loadedKey: Uint8Array;
|
|
29
50
|
if (fs.existsSync(privateKey)) {
|
|
30
|
-
|
|
31
|
-
|
|
51
|
+
privateKey = fs.readFileSync(privateKey).toString();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (privateKey.includes('[') && privateKey.includes(']')) {
|
|
55
|
+
loadedKey = Uint8Array.from(JSON.parse(privateKey));
|
|
56
|
+
} else if (privateKey.includes(',')) {
|
|
57
|
+
loadedKey = Uint8Array.from(
|
|
58
|
+
privateKey.split(',').map((val) => Number(val))
|
|
32
59
|
);
|
|
33
60
|
} else {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
privateKey.split(',').map((val) => Number(val))
|
|
37
|
-
);
|
|
38
|
-
} else {
|
|
39
|
-
loadedKey = new Uint8Array(bs58.decode(privateKey));
|
|
40
|
-
}
|
|
61
|
+
privateKey = privateKey.replace(/\s/g, '');
|
|
62
|
+
loadedKey = new Uint8Array(bs58.decode(privateKey));
|
|
41
63
|
}
|
|
42
64
|
|
|
43
65
|
return Keypair.fromSecretKey(Uint8Array.from(loadedKey));
|
package/tests/dlob/helpers.ts
CHANGED
|
@@ -114,6 +114,7 @@ export const mockAMM: AMM = {
|
|
|
114
114
|
totalSocialLoss: new BN(0),
|
|
115
115
|
baseAssetAmountPerLp: new BN(0),
|
|
116
116
|
quoteAssetAmountPerLp: new BN(0),
|
|
117
|
+
targetBaseAssetAmountPerLp: 0,
|
|
117
118
|
|
|
118
119
|
quoteBreakEvenAmountLong: new BN(0),
|
|
119
120
|
quoteBreakEvenAmountShort: new BN(0),
|