@drift-labs/sdk
Version:
SDK for Drift Protocol
139 lines (138 loc) • 6.07 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DriftCore = void 0;
const pdas = __importStar(require("../addresses/pda"));
const constants = __importStar(require("../constants"));
const user_1 = require("../decode/user");
const customCoder_1 = require("../decode/customCoder");
const drift_json_1 = __importDefault(require("../idl/drift.json"));
const fetch_1 = require("../accounts/fetch");
const deposit_1 = require("./instructions/deposit");
const withdraw_1 = require("./instructions/withdraw");
const orders_1 = require("./instructions/orders");
const fill_1 = require("./instructions/fill");
const trigger_1 = require("./instructions/trigger");
const settlement_1 = require("./instructions/settlement");
const liquidation_1 = require("./instructions/liquidation");
const funding_1 = require("./instructions/funding");
const perpOrders_1 = require("./instructions/perpOrders");
const remainingAccounts = __importStar(require("./remainingAccounts"));
const signedMsg = __importStar(require("./signedMsg"));
/**
* DriftCore is the minimal, core SDK surface:
* - No subscriptions / polling / websockets.
* - Pure helpers for PDAs, decoding, constants, and instruction building.
*
* Transaction/instruction builders will be progressively moved here from `DriftClient`.
*/
class DriftCore {
static defaultIdl() {
return drift_json_1.default;
}
static coder(idl = DriftCore.defaultIdl()) {
return new customCoder_1.CustomBorshCoder(idl);
}
/** Decode a Drift `User` account buffer without creating a Program. */
static decodeUserAccount(buffer) {
return (0, user_1.decodeUser)(buffer);
}
/** Fetch and decode a Drift `User` account. */
static async fetchUserAccount(connection, userAccountPublicKey) {
const data = await (0, fetch_1.fetchAccount)(connection, userAccountPublicKey);
return data ? DriftCore.decodeUserAccount(data) : null;
}
static async buildDepositInstruction(args) {
return await (0, deposit_1.buildDepositInstruction)(args);
}
static async buildWithdrawInstruction(args) {
return await (0, withdraw_1.buildWithdrawInstruction)(args);
}
static async buildPlaceOrdersInstruction(args) {
return await (0, orders_1.buildPlaceOrdersInstruction)(args);
}
static async buildCancelOrdersInstruction(args) {
return await (0, orders_1.buildCancelOrdersInstruction)(args);
}
static async buildFillPerpOrderInstruction(args) {
return await (0, fill_1.buildFillPerpOrderInstruction)(args);
}
static async buildTriggerOrderInstruction(args) {
return await (0, trigger_1.buildTriggerOrderInstruction)(args);
}
static async buildSettlePnlInstruction(args) {
return await (0, settlement_1.buildSettlePnlInstruction)(args);
}
static async buildLiquidatePerpInstruction(args) {
return await (0, liquidation_1.buildLiquidatePerpInstruction)(args);
}
static async buildPlacePerpOrderInstruction(args) {
return await (0, perpOrders_1.buildPlacePerpOrderInstruction)(args);
}
static async buildPlaceAndTakePerpOrderInstruction(args) {
return await (0, perpOrders_1.buildPlaceAndTakePerpOrderInstruction)(args);
}
static async buildPlaceAndMakePerpOrderInstruction(args) {
return await (0, perpOrders_1.buildPlaceAndMakePerpOrderInstruction)(args);
}
static async buildCancelOrderInstruction(args) {
return await (0, perpOrders_1.buildCancelOrderInstruction)(args);
}
static async buildCancelOrderByUserIdInstruction(args) {
return await (0, perpOrders_1.buildCancelOrderByUserIdInstruction)(args);
}
static async buildCancelOrdersByIdsInstruction(args) {
return await (0, perpOrders_1.buildCancelOrdersByIdsInstruction)(args);
}
static async buildModifyOrderInstruction(args) {
return await (0, perpOrders_1.buildModifyOrderInstruction)(args);
}
static async buildModifyOrderByUserIdInstruction(args) {
return await (0, perpOrders_1.buildModifyOrderByUserIdInstruction)(args);
}
static async buildUpdateFundingRateInstruction(args) {
return await (0, funding_1.buildUpdateFundingRateInstruction)(args);
}
/**
* Placeholder for instruction builders.
*
* In follow-up refactors, DriftClient methods like `getDepositInstruction`,
* `getPlaceOrdersIx`, etc. will be moved here as pure builders.
*/
static buildInstructions(_ctx) {
return [];
}
}
exports.DriftCore = DriftCore;
/** Re-export PDA helpers (pure). */
DriftCore.pdas = pdas;
/** Re-export SDK constants (market configs, numeric constants, etc). */
DriftCore.constants = constants;
/** Re-export remaining-accounts logic (pure). */
DriftCore.remainingAccounts = remainingAccounts;
DriftCore.signedMsg = signedMsg;