@drift-labs/sdk 2.85.0-beta.0 → 2.85.0-beta.10
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/VERSION +1 -1
- package/bun.lockb +0 -0
- package/lib/accounts/bulkAccountLoader.d.ts +3 -3
- package/lib/accounts/pollingDriftClientAccountSubscriber.js +10 -2
- package/lib/accounts/pollingUserAccountSubscriber.d.ts +4 -3
- package/lib/accounts/pollingUserAccountSubscriber.js +7 -6
- package/lib/accounts/testBulkAccountLoader.d.ts +4 -0
- package/lib/accounts/testBulkAccountLoader.js +45 -0
- package/lib/bankrun/bankrunConnection.d.ts +71 -0
- package/lib/bankrun/bankrunConnection.js +285 -0
- package/lib/blockhashSubscriber/BlockhashSubscriber.js +22 -15
- package/lib/constants/perpMarkets.js +10 -0
- package/lib/constants/spotMarkets.js +10 -0
- package/lib/driftClient.d.ts +2 -2
- package/lib/driftClient.js +14 -13
- package/lib/events/eventSubscriber.js +12 -4
- package/lib/idl/drift.json +28 -8
- package/lib/testClient.js +1 -2
- package/lib/tokenFaucet.d.ts +3 -1
- package/lib/tokenFaucet.js +41 -8
- package/lib/tx/txParamProcessor.d.ts +2 -1
- package/lib/tx/txParamProcessor.js +7 -3
- package/lib/types.d.ts +1 -0
- package/lib/user.js +1 -1
- package/package.json +3 -1
- package/src/accounts/bulkAccountLoader.ts +3 -2
- package/src/accounts/pollingDriftClientAccountSubscriber.ts +16 -3
- package/src/accounts/pollingUserAccountSubscriber.ts +13 -12
- package/src/accounts/testBulkAccountLoader.ts +53 -0
- package/src/bankrun/bankrunConnection.ts +466 -0
- package/src/blockhashSubscriber/BlockhashSubscriber.ts +24 -19
- package/src/constants/perpMarkets.ts +10 -0
- package/src/constants/spotMarkets.ts +10 -0
- package/src/driftClient.ts +21 -15
- package/src/events/eventSubscriber.ts +5 -0
- package/src/idl/drift.json +28 -8
- package/src/testClient.ts +1 -2
- package/src/tokenFaucet.ts +49 -12
- package/src/tx/txParamProcessor.ts +11 -2
- package/src/types.ts +1 -0
- package/src/user.ts +5 -2
package/src/idl/drift.json
CHANGED
|
@@ -3934,6 +3934,12 @@
|
|
|
3934
3934
|
{
|
|
3935
3935
|
"name": "maxBorrowRate",
|
|
3936
3936
|
"type": "u32"
|
|
3937
|
+
},
|
|
3938
|
+
{
|
|
3939
|
+
"name": "minBorrowRate",
|
|
3940
|
+
"type": {
|
|
3941
|
+
"option": "u8"
|
|
3942
|
+
}
|
|
3937
3943
|
}
|
|
3938
3944
|
]
|
|
3939
3945
|
},
|
|
@@ -6198,13 +6204,13 @@
|
|
|
6198
6204
|
"type": "i16"
|
|
6199
6205
|
},
|
|
6200
6206
|
{
|
|
6201
|
-
"name": "
|
|
6202
|
-
"
|
|
6203
|
-
"
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
|
|
6207
|
-
|
|
6207
|
+
"name": "maxTokenBorrowsFraction",
|
|
6208
|
+
"docs": [
|
|
6209
|
+
"What fraction of max_token_deposits",
|
|
6210
|
+
"disabled when 0, 1 => 1/10000 => .01% of max_token_deposits",
|
|
6211
|
+
"precision: X/10000"
|
|
6212
|
+
],
|
|
6213
|
+
"type": "u16"
|
|
6208
6214
|
},
|
|
6209
6215
|
{
|
|
6210
6216
|
"name": "flashLoanAmount",
|
|
@@ -6240,12 +6246,21 @@
|
|
|
6240
6246
|
],
|
|
6241
6247
|
"type": "u64"
|
|
6242
6248
|
},
|
|
6249
|
+
{
|
|
6250
|
+
"name": "minBorrowRate",
|
|
6251
|
+
"docs": [
|
|
6252
|
+
"The min borrow rate for this market when the market regardless of utilization",
|
|
6253
|
+
"1 => 1/200 => .5%",
|
|
6254
|
+
"precision: X/200"
|
|
6255
|
+
],
|
|
6256
|
+
"type": "u8"
|
|
6257
|
+
},
|
|
6243
6258
|
{
|
|
6244
6259
|
"name": "padding",
|
|
6245
6260
|
"type": {
|
|
6246
6261
|
"array": [
|
|
6247
6262
|
"u8",
|
|
6248
|
-
|
|
6263
|
+
47
|
|
6249
6264
|
]
|
|
6250
6265
|
}
|
|
6251
6266
|
}
|
|
@@ -12009,6 +12024,11 @@
|
|
|
12009
12024
|
"code": 6267,
|
|
12010
12025
|
"name": "UnableToParsePullOracleMessage",
|
|
12011
12026
|
"msg": "Unable to parse pull oracle message"
|
|
12027
|
+
},
|
|
12028
|
+
{
|
|
12029
|
+
"code": 6268,
|
|
12030
|
+
"name": "MaxBorrows",
|
|
12031
|
+
"msg": "Can not borow more than max borrows"
|
|
12012
12032
|
}
|
|
12013
12033
|
]
|
|
12014
12034
|
}
|
package/src/testClient.ts
CHANGED
|
@@ -10,8 +10,6 @@ export class TestClient extends AdminClient {
|
|
|
10
10
|
throw new Error('Test client must be polling');
|
|
11
11
|
}
|
|
12
12
|
super(config);
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
this.txHandler.blockhashCommitment = 'recent';
|
|
15
13
|
}
|
|
16
14
|
|
|
17
15
|
async sendTransaction(
|
|
@@ -30,6 +28,7 @@ export class TestClient extends AdminClient {
|
|
|
30
28
|
let lastFetchedSlot = (
|
|
31
29
|
this.accountSubscriber as PollingDriftClientAccountSubscriber
|
|
32
30
|
).accountLoader.mostRecentSlot;
|
|
31
|
+
await this.fetchAccounts();
|
|
33
32
|
while (lastFetchedSlot < slot) {
|
|
34
33
|
await this.fetchAccounts();
|
|
35
34
|
lastFetchedSlot = (
|
package/src/tokenFaucet.ts
CHANGED
|
@@ -2,10 +2,10 @@ import * as anchor from '@coral-xyz/anchor';
|
|
|
2
2
|
import { AnchorProvider, Idl, Program } from '@coral-xyz/anchor';
|
|
3
3
|
import {
|
|
4
4
|
TOKEN_PROGRAM_ID,
|
|
5
|
-
getAccount,
|
|
6
5
|
Account,
|
|
7
6
|
createAssociatedTokenAccountInstruction,
|
|
8
7
|
getAssociatedTokenAddress,
|
|
8
|
+
getAccount,
|
|
9
9
|
} from '@solana/spl-token';
|
|
10
10
|
import {
|
|
11
11
|
ConfirmOptions,
|
|
@@ -19,8 +19,10 @@ import {
|
|
|
19
19
|
import { BN } from '.';
|
|
20
20
|
import tokenFaucet from './idl/token_faucet.json';
|
|
21
21
|
import { IWallet } from './types';
|
|
22
|
+
import { BankrunContextWrapper } from './bankrun/bankrunConnection';
|
|
22
23
|
|
|
23
24
|
export class TokenFaucet {
|
|
25
|
+
context?: BankrunContextWrapper;
|
|
24
26
|
connection: Connection;
|
|
25
27
|
wallet: IWallet;
|
|
26
28
|
public program: Program;
|
|
@@ -33,13 +35,20 @@ export class TokenFaucet {
|
|
|
33
35
|
wallet: IWallet,
|
|
34
36
|
programId: PublicKey,
|
|
35
37
|
mint: PublicKey,
|
|
36
|
-
opts?: ConfirmOptions
|
|
38
|
+
opts?: ConfirmOptions,
|
|
39
|
+
context?: BankrunContextWrapper
|
|
37
40
|
) {
|
|
38
41
|
this.connection = connection;
|
|
42
|
+
this.context = context;
|
|
39
43
|
this.wallet = wallet;
|
|
40
44
|
this.opts = opts || AnchorProvider.defaultOptions();
|
|
41
45
|
// @ts-ignore
|
|
42
|
-
const provider = new AnchorProvider(
|
|
46
|
+
const provider = new AnchorProvider(
|
|
47
|
+
context ? context.connection.toConnection() : this.connection,
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
wallet,
|
|
50
|
+
this.opts
|
|
51
|
+
);
|
|
43
52
|
this.provider = provider;
|
|
44
53
|
this.program = new Program(tokenFaucet as Idl, programId, provider);
|
|
45
54
|
this.mint = mint;
|
|
@@ -76,7 +85,7 @@ export class TokenFaucet {
|
|
|
76
85
|
public async initialize(): Promise<TransactionSignature> {
|
|
77
86
|
const [faucetConfigPublicKey] =
|
|
78
87
|
await this.getFaucetConfigPublicKeyAndNonce();
|
|
79
|
-
|
|
88
|
+
const ix = this.program.instruction.initialize({
|
|
80
89
|
accounts: {
|
|
81
90
|
faucetConfig: faucetConfigPublicKey,
|
|
82
91
|
admin: this.wallet.publicKey,
|
|
@@ -86,6 +95,9 @@ export class TokenFaucet {
|
|
|
86
95
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
87
96
|
},
|
|
88
97
|
});
|
|
98
|
+
const tx = new Transaction().add(ix);
|
|
99
|
+
const txSig = await this.context.sendTransaction(tx);
|
|
100
|
+
return txSig;
|
|
89
101
|
}
|
|
90
102
|
|
|
91
103
|
public async fetchState(): Promise<any> {
|
|
@@ -114,12 +126,29 @@ export class TokenFaucet {
|
|
|
114
126
|
|
|
115
127
|
const tx = new Transaction().add(mintIx);
|
|
116
128
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
129
|
+
if (this.context) {
|
|
130
|
+
return await this.context.sendTransaction(tx);
|
|
131
|
+
} else {
|
|
132
|
+
return await this.program.provider.sendAndConfirm(tx, [], this.opts);
|
|
133
|
+
}
|
|
120
134
|
}
|
|
121
135
|
|
|
122
136
|
public async transferMintAuthority(): Promise<TransactionSignature> {
|
|
137
|
+
if (this.context) {
|
|
138
|
+
const ix = this.program.instruction.transferMintAuthority({
|
|
139
|
+
accounts: {
|
|
140
|
+
faucetConfig: await this.getFaucetConfigPublicKey(),
|
|
141
|
+
mintAccount: this.mint,
|
|
142
|
+
mintAuthority: await this.getMintAuthority(),
|
|
143
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
144
|
+
admin: this.wallet.publicKey,
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
const tx = new Transaction().add(ix);
|
|
148
|
+
const txSig = await this.context.sendTransaction(tx);
|
|
149
|
+
return txSig;
|
|
150
|
+
}
|
|
151
|
+
|
|
123
152
|
return await this.program.rpc.transferMintAuthority({
|
|
124
153
|
accounts: {
|
|
125
154
|
faucetConfig: await this.getFaucetConfigPublicKey(),
|
|
@@ -146,9 +175,8 @@ export class TokenFaucet {
|
|
|
146
175
|
let associatedTokenAccountExists = false;
|
|
147
176
|
|
|
148
177
|
try {
|
|
149
|
-
const assosciatedTokenAccount =
|
|
150
|
-
associatedTokenPublicKey
|
|
151
|
-
);
|
|
178
|
+
const assosciatedTokenAccount =
|
|
179
|
+
await this.context.connection.getAccountInfo(associatedTokenPublicKey);
|
|
152
180
|
|
|
153
181
|
associatedTokenAccountExists = !!assosciatedTokenAccount;
|
|
154
182
|
} catch (e) {
|
|
@@ -162,7 +190,13 @@ export class TokenFaucet {
|
|
|
162
190
|
|
|
163
191
|
tx.add(mintToTx);
|
|
164
192
|
|
|
165
|
-
|
|
193
|
+
let txSig;
|
|
194
|
+
if (this.context) {
|
|
195
|
+
txSig = await this.context.sendTransaction(tx);
|
|
196
|
+
} else {
|
|
197
|
+
txSig = await this.program.provider.sendAndConfirm(tx, [], this.opts);
|
|
198
|
+
}
|
|
199
|
+
|
|
166
200
|
return [associatedTokenPublicKey, txSig];
|
|
167
201
|
}
|
|
168
202
|
|
|
@@ -200,6 +234,9 @@ export class TokenFaucet {
|
|
|
200
234
|
userPubKey: PublicKey;
|
|
201
235
|
}): Promise<Account> {
|
|
202
236
|
const associatedKey = await this.getAssosciatedMockUSDMintAddress(props);
|
|
237
|
+
if (this.context) {
|
|
238
|
+
return await this.context.connection.getTokenAccount(associatedKey);
|
|
239
|
+
}
|
|
203
240
|
return await getAccount(this.connection, associatedKey);
|
|
204
241
|
}
|
|
205
242
|
|
|
@@ -215,7 +252,7 @@ export class TokenFaucet {
|
|
|
215
252
|
props.callback(await this.getTokenAccountInfo(props));
|
|
216
253
|
|
|
217
254
|
// Couldn't find a way to do it using anchor framework subscription, someone on serum discord recommended this way
|
|
218
|
-
this.connection.onAccountChange(
|
|
255
|
+
this.context.connection.onAccountChange(
|
|
219
256
|
tokenAccountKey,
|
|
220
257
|
async (
|
|
221
258
|
_accountInfo /* accountInfo is a buffer which we don't know how to deserialize */
|
|
@@ -32,7 +32,8 @@ export class TransactionParamProcessor {
|
|
|
32
32
|
public static async getTxSimComputeUnits(
|
|
33
33
|
tx: VersionedTransaction,
|
|
34
34
|
connection: Connection,
|
|
35
|
-
bufferMultiplier: number // Making this a mandatory param to force the user to remember that simulated CU's can be inaccurate and a buffer should be applied
|
|
35
|
+
bufferMultiplier: number, // Making this a mandatory param to force the user to remember that simulated CU's can be inaccurate and a buffer should be applied
|
|
36
|
+
lowerBoundCu?: number
|
|
36
37
|
): Promise<{ success: boolean; computeUnits: number }> {
|
|
37
38
|
try {
|
|
38
39
|
if (TEST_SIMS_ALWAYS_FAIL)
|
|
@@ -49,10 +50,18 @@ export class TransactionParamProcessor {
|
|
|
49
50
|
const computeUnits = await this.getComputeUnitsFromSim(simTxResult);
|
|
50
51
|
|
|
51
52
|
// Apply the buffer, but round down to the MAX_COMPUTE_UNITS, and round up to the nearest whole number
|
|
52
|
-
|
|
53
|
+
let bufferedComputeUnits = Math.ceil(
|
|
53
54
|
Math.min(computeUnits * bufferMultiplier, MAX_COMPUTE_UNITS)
|
|
54
55
|
);
|
|
55
56
|
|
|
57
|
+
// If a lower bound CU is passed then enforce it
|
|
58
|
+
if (lowerBoundCu) {
|
|
59
|
+
bufferedComputeUnits = Math.max(
|
|
60
|
+
bufferedComputeUnits,
|
|
61
|
+
Math.min(lowerBoundCu, MAX_COMPUTE_UNITS)
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
56
65
|
return {
|
|
57
66
|
success: true,
|
|
58
67
|
computeUnits: bufferedComputeUnits,
|
package/src/types.ts
CHANGED
|
@@ -1042,6 +1042,7 @@ export type ProcessingTxParams = {
|
|
|
1042
1042
|
computeUnitsBufferMultiplier?: number;
|
|
1043
1043
|
useSimulatedComputeUnitsForCUPriceCalculation?: boolean;
|
|
1044
1044
|
getCUPriceFromComputeUnits?: (computeUnits: number) => number;
|
|
1045
|
+
lowerBoundCu?: number;
|
|
1045
1046
|
};
|
|
1046
1047
|
|
|
1047
1048
|
export type TxParams = BaseTxParams & ProcessingTxParams;
|
package/src/user.ts
CHANGED
|
@@ -108,9 +108,12 @@ export class User {
|
|
|
108
108
|
this.userAccountPublicKey = config.userAccountPublicKey;
|
|
109
109
|
if (config.accountSubscription?.type === 'polling') {
|
|
110
110
|
this.accountSubscriber = new PollingUserAccountSubscriber(
|
|
111
|
-
config.driftClient.
|
|
111
|
+
config.driftClient.connection,
|
|
112
112
|
config.userAccountPublicKey,
|
|
113
|
-
config.accountSubscription.accountLoader
|
|
113
|
+
config.accountSubscription.accountLoader,
|
|
114
|
+
this.driftClient.program.account.user.coder.accounts.decodeUnchecked.bind(
|
|
115
|
+
this.driftClient.program.account.user.coder.accounts
|
|
116
|
+
)
|
|
114
117
|
);
|
|
115
118
|
} else if (config.accountSubscription?.type === 'custom') {
|
|
116
119
|
this.accountSubscriber = config.accountSubscription.userAccountSubscriber;
|