@quartz-labs/sdk 0.0.1 → 0.0.2
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 +1 -1
- package/build/client.d.ts +19 -0
- package/build/client.js +60 -0
- package/build/config/constants.d.ts +7 -0
- package/build/config/constants.js +7 -0
- package/build/helpers.d.ts +12 -0
- package/build/helpers.js +39 -0
- package/build/idl/quartz.json +646 -0
- package/build/index.d.ts +4 -0
- package/build/index.js +4 -0
- package/build/model/driftUser.d.ts +33 -0
- package/build/model/driftUser.js +567 -0
- package/build/services/driftClientService.d.ts +9 -0
- package/build/services/driftClientService.js +28 -0
- package/build/types/quartz.d.ts +647 -0
- package/build/types/quartz.js +646 -0
- package/build/user.d.ts +16 -0
- package/build/user.js +47 -0
- package/jest.config.js +4 -0
- package/package.json +10 -4
- package/src/client.ts +36 -34
- package/src/config/constants.ts +3 -0
- package/src/index.ts +2 -1
- package/src/model/driftUser.ts +12 -2
- package/src/services/driftClientService.ts +37 -0
- package/src/tests/helpers.test.ts +48 -0
- package/src/user.ts +147 -5
- package/src/utils/helpers.ts +68 -0
- package/src/utils/jupiter.ts +73 -0
- package/src/helpers.ts +0 -33
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { PublicKey, Connection, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
import { QuoteResponse } from "@jup-ag/api";
|
|
3
|
+
import { AddressLookupTableAccount } from "@solana/web3.js";
|
|
4
|
+
|
|
5
|
+
export async function getJupiterSwapIx(
|
|
6
|
+
walletPubkey: PublicKey,
|
|
7
|
+
connection: Connection,
|
|
8
|
+
quoteResponse: QuoteResponse
|
|
9
|
+
): Promise<{
|
|
10
|
+
ix_jupiterSwap: TransactionInstruction,
|
|
11
|
+
jupiterLookupTables: AddressLookupTableAccount[]
|
|
12
|
+
}> {
|
|
13
|
+
const instructions = await (
|
|
14
|
+
await fetch('https://quote-api.jup.ag/v6/swap-instructions', {
|
|
15
|
+
method: 'POST',
|
|
16
|
+
headers: {
|
|
17
|
+
'Content-Type': 'application/json'
|
|
18
|
+
},
|
|
19
|
+
body: JSON.stringify({
|
|
20
|
+
quoteResponse,
|
|
21
|
+
userPublicKey: walletPubkey.toBase58(),
|
|
22
|
+
useCompression: true,
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
).json();
|
|
26
|
+
|
|
27
|
+
if (instructions.error) {
|
|
28
|
+
throw new Error("Failed to get swap instructions: " + instructions.error);
|
|
29
|
+
}
|
|
30
|
+
const { swapInstruction, addressLookupTableAddresses } = instructions;
|
|
31
|
+
|
|
32
|
+
const getAddressLookupTableAccounts = async (
|
|
33
|
+
keys: string[]
|
|
34
|
+
): Promise<AddressLookupTableAccount[]> => {
|
|
35
|
+
const addressLookupTableAccountInfos =
|
|
36
|
+
await connection.getMultipleAccountsInfo(
|
|
37
|
+
keys.map((key) => new PublicKey(key))
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return addressLookupTableAccountInfos.reduce((acc: any, accountInfo: any, index: any) => {
|
|
41
|
+
const addressLookupTableAddress = keys[index];
|
|
42
|
+
if (accountInfo) {
|
|
43
|
+
const addressLookupTableAccount = new AddressLookupTableAccount({
|
|
44
|
+
key: new PublicKey(addressLookupTableAddress),
|
|
45
|
+
state: AddressLookupTableAccount.deserialize(accountInfo.data),
|
|
46
|
+
});
|
|
47
|
+
acc.push(addressLookupTableAccount);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return acc;
|
|
51
|
+
}, new Array<AddressLookupTableAccount>());
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const addressLookupTableAccounts: AddressLookupTableAccount[] = [];
|
|
55
|
+
addressLookupTableAccounts.push(
|
|
56
|
+
...(await getAddressLookupTableAccounts(addressLookupTableAddresses))
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const ix_jupiterSwap = new TransactionInstruction({
|
|
60
|
+
programId: new PublicKey(swapInstruction.programId),
|
|
61
|
+
keys: swapInstruction.accounts.map((key: any) => ({
|
|
62
|
+
pubkey: new PublicKey(key.pubkey),
|
|
63
|
+
isSigner: key.isSigner,
|
|
64
|
+
isWritable: key.isWritable,
|
|
65
|
+
})),
|
|
66
|
+
data: Buffer.from(swapInstruction.data, "base64"),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
ix_jupiterSwap,
|
|
71
|
+
jupiterLookupTables: addressLookupTableAccounts,
|
|
72
|
+
};
|
|
73
|
+
}
|
package/src/helpers.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { PublicKey } from "@solana/web3.js";
|
|
2
|
-
import { QUARTZ_PROGRAM_ID } from "./config/constants";
|
|
3
|
-
import { BN } from "@coral-xyz/anchor";
|
|
4
|
-
import { DRIFT_PROGRAM_ID } from "@drift-labs/sdk";
|
|
5
|
-
|
|
6
|
-
export const getVaultPubkey = (owner: PublicKey) => {
|
|
7
|
-
const [vaultPda] = PublicKey.findProgramAddressSync(
|
|
8
|
-
[Buffer.from("vault"), owner.toBuffer()],
|
|
9
|
-
QUARTZ_PROGRAM_ID
|
|
10
|
-
)
|
|
11
|
-
return vaultPda;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const getVaultSplPubkey = (owner: PublicKey, mint: PublicKey) => {
|
|
15
|
-
const vaultPda = getVaultPubkey(owner);
|
|
16
|
-
const [vaultSplPda] = PublicKey.findProgramAddressSync(
|
|
17
|
-
[vaultPda.toBuffer(), mint.toBuffer()],
|
|
18
|
-
QUARTZ_PROGRAM_ID
|
|
19
|
-
);
|
|
20
|
-
return vaultSplPda;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const getDriftUser = (vaultPda: PublicKey) => {
|
|
24
|
-
const [userPda] = PublicKey.findProgramAddressSync(
|
|
25
|
-
[
|
|
26
|
-
Buffer.from("user"),
|
|
27
|
-
vaultPda.toBuffer(),
|
|
28
|
-
new BN(0).toArrayLike(Buffer, 'le', 2),
|
|
29
|
-
],
|
|
30
|
-
new PublicKey(DRIFT_PROGRAM_ID)
|
|
31
|
-
);
|
|
32
|
-
return userPda;
|
|
33
|
-
}
|