@quartz-labs/sdk 0.0.1 → 0.0.3
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/dist/client.d.ts +19 -0
- package/dist/client.js +60 -0
- package/dist/config/constants.d.ts +9 -0
- package/{src/config/constants.ts → dist/config/constants.js} +3 -4
- package/dist/idl/quartz.json +646 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/model/driftUser.d.ts +36 -0
- package/dist/model/driftUser.js +574 -0
- package/dist/services/driftClientService.d.ts +9 -0
- package/dist/services/driftClientService.js +28 -0
- package/dist/types/quartz.d.ts +647 -0
- package/dist/types/quartz.js +646 -0
- package/dist/user.d.ts +25 -0
- package/dist/user.js +158 -0
- package/dist/utils/helpers.d.ts +12 -0
- package/dist/utils/helpers.js +39 -0
- package/dist/utils/jupiter.d.ts +7 -0
- package/dist/utils/jupiter.js +48 -0
- package/package.json +13 -4
- package/src/client.ts +0 -117
- package/src/helpers.ts +0 -33
- package/src/idl/quartz.json +0 -646
- package/src/index.ts +0 -4
- package/src/model/driftUser.ts +0 -1056
- package/src/types/quartz.ts +0 -1293
- package/src/user.ts +0 -85
- package/tsconfig.json +0 -17
package/README.md
CHANGED
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DriftClient } from "@drift-labs/sdk";
|
|
2
|
+
import { Quartz } from "./types/quartz.js";
|
|
3
|
+
import { Program, Wallet } from "@coral-xyz/anchor";
|
|
4
|
+
import { Connection, AddressLookupTableAccount } from "@solana/web3.js";
|
|
5
|
+
import { PublicKey } from "@solana/web3.js";
|
|
6
|
+
import { QuartzUser } from "./user";
|
|
7
|
+
export declare class QuartzClient {
|
|
8
|
+
private connection;
|
|
9
|
+
private wallet;
|
|
10
|
+
private program;
|
|
11
|
+
private quartzLookupTable;
|
|
12
|
+
private driftClient;
|
|
13
|
+
private oracles;
|
|
14
|
+
constructor(connection: Connection, wallet: Wallet, program: Program<Quartz>, quartzAddressTable: AddressLookupTableAccount, driftClient: DriftClient, oracles: Map<string, PublicKey>);
|
|
15
|
+
static initialize(connection: Connection, wallet: Wallet): Promise<QuartzClient>;
|
|
16
|
+
getAllQuartzAccountPubkeys(): Promise<PublicKey[]>;
|
|
17
|
+
getQuartzAccount(vault: PublicKey): Promise<QuartzUser>;
|
|
18
|
+
getMultipleQuartzAccounts(vaults: PublicKey[]): Promise<(QuartzUser | null)[]>;
|
|
19
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { fetchUserAccountsUsingKeys as fetchDriftAccountsUsingKeys } from "@drift-labs/sdk";
|
|
2
|
+
import { QUARTZ_ADDRESS_TABLE, QUARTZ_PROGRAM_ID } from "./config/constants";
|
|
3
|
+
import quartzIdl from "./idl/quartz.json";
|
|
4
|
+
import { AnchorProvider, Program, setProvider } from "@coral-xyz/anchor";
|
|
5
|
+
import { PythSolanaReceiver } from "@pythnetwork/pyth-solana-receiver";
|
|
6
|
+
import { QuartzUser } from "./user";
|
|
7
|
+
import { getDriftUserPublicKey } from "./utils/helpers";
|
|
8
|
+
import { DriftClientService } from "./services/driftClientService";
|
|
9
|
+
export class QuartzClient {
|
|
10
|
+
constructor(connection, wallet, program, quartzAddressTable, driftClient, oracles) {
|
|
11
|
+
this.connection = connection;
|
|
12
|
+
this.wallet = wallet;
|
|
13
|
+
this.program = program;
|
|
14
|
+
this.quartzLookupTable = quartzAddressTable;
|
|
15
|
+
this.driftClient = driftClient;
|
|
16
|
+
this.oracles = oracles;
|
|
17
|
+
}
|
|
18
|
+
static async initialize(connection, wallet) {
|
|
19
|
+
const provider = new AnchorProvider(connection, wallet, { commitment: "confirmed" });
|
|
20
|
+
setProvider(provider);
|
|
21
|
+
const program = new Program(quartzIdl, QUARTZ_PROGRAM_ID, provider);
|
|
22
|
+
const quartzLookupTable = await connection.getAddressLookupTable(QUARTZ_ADDRESS_TABLE).then((res) => res.value);
|
|
23
|
+
if (!quartzLookupTable)
|
|
24
|
+
throw Error("Address Lookup Table account not found");
|
|
25
|
+
const driftClient = await DriftClientService.getDriftClient(connection);
|
|
26
|
+
const pythSolanaReceiver = new PythSolanaReceiver({ connection, wallet });
|
|
27
|
+
const oracles = new Map([
|
|
28
|
+
["SOL/USD", pythSolanaReceiver.getPriceFeedAccountAddress(0, "0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d")],
|
|
29
|
+
["USDC/USD", pythSolanaReceiver.getPriceFeedAccountAddress(0, "0xeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a")]
|
|
30
|
+
]);
|
|
31
|
+
return new QuartzClient(connection, wallet, program, quartzLookupTable, driftClient, oracles);
|
|
32
|
+
}
|
|
33
|
+
async getAllQuartzAccountPubkeys() {
|
|
34
|
+
return (await this.program.account.vault.all()).map((vault) => vault.publicKey);
|
|
35
|
+
}
|
|
36
|
+
async getQuartzAccount(vault) {
|
|
37
|
+
await this.program.account.vault.fetch(vault); // Check account exists
|
|
38
|
+
return new QuartzUser(vault, this.connection, this.program, this.quartzLookupTable, this.oracles, this.driftClient);
|
|
39
|
+
}
|
|
40
|
+
async getMultipleQuartzAccounts(vaults) {
|
|
41
|
+
if (vaults.length === 0)
|
|
42
|
+
return [];
|
|
43
|
+
const accounts = await this.program.account.vault.fetchMultiple(vaults);
|
|
44
|
+
accounts.forEach((account, index) => {
|
|
45
|
+
if (account === null)
|
|
46
|
+
throw Error(`Account not found for pubkey: ${vaults[index].toBase58()}`);
|
|
47
|
+
});
|
|
48
|
+
const driftUsers = await fetchDriftAccountsUsingKeys(this.connection, this.driftClient.program, vaults.map((vault) => getDriftUserPublicKey(vault)));
|
|
49
|
+
// TODO: Uncomment once Drift accounts are guaranteed
|
|
50
|
+
// const undefinedIndex = driftUsers.findIndex(user => !user);
|
|
51
|
+
// if (undefinedIndex !== -1) {
|
|
52
|
+
// throw new Error(`[${this.wallet?.publicKey}] Failed to fetch drift user for vault ${vaults[undefinedIndex].toBase58()}`);
|
|
53
|
+
// }
|
|
54
|
+
return driftUsers.map((driftUser, index) => {
|
|
55
|
+
if (driftUser === undefined)
|
|
56
|
+
return null;
|
|
57
|
+
return new QuartzUser(vaults[index], this.connection, this.program, this.quartzLookupTable, this.oracles, this.driftClient);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
export declare const QUARTZ_PROGRAM_ID: PublicKey;
|
|
3
|
+
export declare const QUARTZ_ADDRESS_TABLE: PublicKey;
|
|
4
|
+
export declare const QUARTZ_HEALTH_BUFFER = 0.1;
|
|
5
|
+
export declare const USDC_MINT: PublicKey;
|
|
6
|
+
export declare const WSOL_MINT: PublicKey;
|
|
7
|
+
export declare const DRIFT_MARKET_INDEX_USDC = 0;
|
|
8
|
+
export declare const DRIFT_MARKET_INDEX_SOL = 1;
|
|
9
|
+
export declare const SUPPORTED_DRIFT_MARKETS: number[];
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
|
2
|
-
|
|
3
2
|
export const QUARTZ_PROGRAM_ID = new PublicKey("6JjHXLheGSNvvexgzMthEcgjkcirDrGduc3HAKB2P1v2");
|
|
4
3
|
export const QUARTZ_ADDRESS_TABLE = new PublicKey("96BmeKKVGX3LKYSKo3FCEom1YpNY11kCnGscKq6ouxLx");
|
|
5
|
-
|
|
6
4
|
export const QUARTZ_HEALTH_BUFFER = 0.1;
|
|
7
|
-
|
|
5
|
+
export const USDC_MINT = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
|
|
6
|
+
export const WSOL_MINT = new PublicKey("So11111111111111111111111111111111111111112");
|
|
8
7
|
export const DRIFT_MARKET_INDEX_USDC = 0;
|
|
9
8
|
export const DRIFT_MARKET_INDEX_SOL = 1;
|
|
10
|
-
export const SUPPORTED_DRIFT_MARKETS = [DRIFT_MARKET_INDEX_USDC, DRIFT_MARKET_INDEX_SOL];
|
|
9
|
+
export const SUPPORTED_DRIFT_MARKETS = [DRIFT_MARKET_INDEX_USDC, DRIFT_MARKET_INDEX_SOL];
|