@drift-labs/common 1.0.42 → 1.0.43
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/drift/base/actions/index.d.ts +1 -0
- package/lib/drift/base/actions/index.js +1 -0
- package/lib/drift/base/actions/index.js.map +1 -1
- package/lib/drift/base/actions/swift/create.d.ts +64 -0
- package/lib/drift/base/actions/swift/create.js +71 -0
- package/lib/drift/base/actions/swift/create.js.map +1 -0
- package/lib/drift/base/actions/swift/index.d.ts +1 -0
- package/lib/drift/base/actions/swift/index.js +18 -0
- package/lib/drift/base/actions/swift/index.js.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/drift/base/actions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,0CAAwB;AACxB,yCAAuB;AACvB,yCAAuB;AACvB,4CAA0B","sourcesContent":["export * from './user';\nexport * from './trade';\nexport * from './perp';\nexport * from './spot';\nexport * from './builder';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/drift/base/actions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,0CAAwB;AACxB,yCAAuB;AACvB,yCAAuB;AACvB,4CAA0B;AAC1B,0CAAwB","sourcesContent":["export * from './user';\nexport * from './trade';\nexport * from './perp';\nexport * from './spot';\nexport * from './builder';\nexport * from './swift';\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { DriftClient, PublicKey, TxParams } from '@drift-labs/sdk';
|
|
2
|
+
import { Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
|
|
3
|
+
interface CreateSwiftAccountIxParams {
|
|
4
|
+
driftClient: DriftClient;
|
|
5
|
+
authority: PublicKey;
|
|
6
|
+
numOrders?: number;
|
|
7
|
+
/**
|
|
8
|
+
* Optional external wallet to use as payer. If provided, this wallet will pay
|
|
9
|
+
* for the account creation instead of the default wallet.
|
|
10
|
+
*/
|
|
11
|
+
rentPayerOverride?: PublicKey;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Creates a transaction instruction for initializing a Swift (signed message user orders) account.
|
|
15
|
+
*
|
|
16
|
+
* @param driftClient - The Drift client instance
|
|
17
|
+
* @param authority - The public key of the account authority
|
|
18
|
+
* @param numOrders - The number of order slots to allocate (default: 8)
|
|
19
|
+
* @param rentPayerOverride - Optional wallet to pay for account creation instead of the default wallet
|
|
20
|
+
*
|
|
21
|
+
* @returns The Swift account public key and the initialization instruction
|
|
22
|
+
*/
|
|
23
|
+
export declare const createSwiftAccountIx: ({ driftClient, authority, numOrders, rentPayerOverride, }: CreateSwiftAccountIxParams) => Promise<{
|
|
24
|
+
swiftAccountPublicKey: PublicKey;
|
|
25
|
+
ix: TransactionInstruction;
|
|
26
|
+
}>;
|
|
27
|
+
interface CreateSwiftAccountTxnParams extends CreateSwiftAccountIxParams {
|
|
28
|
+
txParams?: TxParams;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates a complete transaction for initializing a Swift (signed message user orders) account.
|
|
32
|
+
*
|
|
33
|
+
* Wraps {@link createSwiftAccountIx} and builds a transaction ready for signing and submission.
|
|
34
|
+
*
|
|
35
|
+
* @param driftClient - The Drift client instance
|
|
36
|
+
* @param authority - The public key of the account authority
|
|
37
|
+
* @param numOrders - The number of order slots to allocate (default: 8)
|
|
38
|
+
* @param rentPayerOverride - Optional wallet to pay for account creation instead of the default wallet
|
|
39
|
+
* @param txParams - Optional transaction parameters (compute units, priority fees, etc.)
|
|
40
|
+
*
|
|
41
|
+
* @returns The built transaction and the Swift account public key
|
|
42
|
+
*/
|
|
43
|
+
export declare const createSwiftAccountTxn: ({ driftClient, authority, numOrders, rentPayerOverride: externalWallet, txParams, }: CreateSwiftAccountTxnParams) => Promise<{
|
|
44
|
+
transaction: Transaction | VersionedTransaction;
|
|
45
|
+
swiftAccountPublicKey: PublicKey;
|
|
46
|
+
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a Swift account instruction only if one doesn't already exist for the given authority.
|
|
49
|
+
*
|
|
50
|
+
* Always returns the Swift account public key. The `ix` will be `null` if the account
|
|
51
|
+
* is already initialized, indicating no transaction is needed.
|
|
52
|
+
*
|
|
53
|
+
* @param driftClient - The Drift client instance
|
|
54
|
+
* @param authority - The public key of the account authority
|
|
55
|
+
* @param numOrders - The number of order slots to allocate (default: 8)
|
|
56
|
+
* @param rentPayerOverride - Optional wallet to pay for account creation instead of the default wallet
|
|
57
|
+
*
|
|
58
|
+
* @returns The Swift account public key and the initialization instruction (null if already initialized)
|
|
59
|
+
*/
|
|
60
|
+
export declare const createSwiftAccountIxIfNotExists: ({ driftClient, authority, numOrders, rentPayerOverride, }: CreateSwiftAccountIxParams) => Promise<{
|
|
61
|
+
swiftAccountPublicKey: PublicKey;
|
|
62
|
+
ix: TransactionInstruction | null;
|
|
63
|
+
}>;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSwiftAccountIxIfNotExists = exports.createSwiftAccountTxn = exports.createSwiftAccountIx = void 0;
|
|
4
|
+
const sdk_1 = require("@drift-labs/sdk");
|
|
5
|
+
/**
|
|
6
|
+
* Creates a transaction instruction for initializing a Swift (signed message user orders) account.
|
|
7
|
+
*
|
|
8
|
+
* @param driftClient - The Drift client instance
|
|
9
|
+
* @param authority - The public key of the account authority
|
|
10
|
+
* @param numOrders - The number of order slots to allocate (default: 8)
|
|
11
|
+
* @param rentPayerOverride - Optional wallet to pay for account creation instead of the default wallet
|
|
12
|
+
*
|
|
13
|
+
* @returns The Swift account public key and the initialization instruction
|
|
14
|
+
*/
|
|
15
|
+
const createSwiftAccountIx = async ({ driftClient, authority, numOrders = 8, rentPayerOverride, }) => {
|
|
16
|
+
const [swiftAccountPublicKey, ix] = await driftClient.getInitializeSignedMsgUserOrdersAccountIx(authority, numOrders, { externalWallet: rentPayerOverride });
|
|
17
|
+
return { swiftAccountPublicKey, ix };
|
|
18
|
+
};
|
|
19
|
+
exports.createSwiftAccountIx = createSwiftAccountIx;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a complete transaction for initializing a Swift (signed message user orders) account.
|
|
22
|
+
*
|
|
23
|
+
* Wraps {@link createSwiftAccountIx} and builds a transaction ready for signing and submission.
|
|
24
|
+
*
|
|
25
|
+
* @param driftClient - The Drift client instance
|
|
26
|
+
* @param authority - The public key of the account authority
|
|
27
|
+
* @param numOrders - The number of order slots to allocate (default: 8)
|
|
28
|
+
* @param rentPayerOverride - Optional wallet to pay for account creation instead of the default wallet
|
|
29
|
+
* @param txParams - Optional transaction parameters (compute units, priority fees, etc.)
|
|
30
|
+
*
|
|
31
|
+
* @returns The built transaction and the Swift account public key
|
|
32
|
+
*/
|
|
33
|
+
const createSwiftAccountTxn = async ({ driftClient, authority, numOrders, rentPayerOverride: externalWallet, txParams, }) => {
|
|
34
|
+
const { swiftAccountPublicKey, ix } = await (0, exports.createSwiftAccountIx)({
|
|
35
|
+
driftClient,
|
|
36
|
+
authority,
|
|
37
|
+
numOrders,
|
|
38
|
+
rentPayerOverride: externalWallet,
|
|
39
|
+
});
|
|
40
|
+
const transaction = await driftClient.buildTransaction([ix], txParams);
|
|
41
|
+
return { transaction, swiftAccountPublicKey };
|
|
42
|
+
};
|
|
43
|
+
exports.createSwiftAccountTxn = createSwiftAccountTxn;
|
|
44
|
+
/**
|
|
45
|
+
* Creates a Swift account instruction only if one doesn't already exist for the given authority.
|
|
46
|
+
*
|
|
47
|
+
* Always returns the Swift account public key. The `ix` will be `null` if the account
|
|
48
|
+
* is already initialized, indicating no transaction is needed.
|
|
49
|
+
*
|
|
50
|
+
* @param driftClient - The Drift client instance
|
|
51
|
+
* @param authority - The public key of the account authority
|
|
52
|
+
* @param numOrders - The number of order slots to allocate (default: 8)
|
|
53
|
+
* @param rentPayerOverride - Optional wallet to pay for account creation instead of the default wallet
|
|
54
|
+
*
|
|
55
|
+
* @returns The Swift account public key and the initialization instruction (null if already initialized)
|
|
56
|
+
*/
|
|
57
|
+
const createSwiftAccountIxIfNotExists = async ({ driftClient, authority, numOrders = 8, rentPayerOverride, }) => {
|
|
58
|
+
const isInitialized = await driftClient.isSignedMsgUserOrdersAccountInitialized(authority);
|
|
59
|
+
if (isInitialized) {
|
|
60
|
+
const swiftAccountPublicKey = (0, sdk_1.getSignedMsgUserAccountPublicKey)(driftClient.program.programId, authority);
|
|
61
|
+
return { swiftAccountPublicKey, ix: null };
|
|
62
|
+
}
|
|
63
|
+
return await (0, exports.createSwiftAccountIx)({
|
|
64
|
+
driftClient,
|
|
65
|
+
authority,
|
|
66
|
+
numOrders,
|
|
67
|
+
rentPayerOverride,
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
exports.createSwiftAccountIxIfNotExists = createSwiftAccountIxIfNotExists;
|
|
71
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/swift/create.ts"],"names":[],"mappings":";;;AAAA,yCAKyB;AAkBzB;;;;;;;;;GASG;AACI,MAAM,oBAAoB,GAAG,KAAK,EAAE,EAC1C,WAAW,EACX,SAAS,EACT,SAAS,GAAG,CAAC,EACb,iBAAiB,GACW,EAG1B,EAAE;IACJ,MAAM,CAAC,qBAAqB,EAAE,EAAE,CAAC,GAChC,MAAM,WAAW,CAAC,yCAAyC,CAC1D,SAAS,EACT,SAAS,EACT,EAAE,cAAc,EAAE,iBAAiB,EAAE,CACrC,CAAC;IAEH,OAAO,EAAE,qBAAqB,EAAE,EAAE,EAAE,CAAC;AACtC,CAAC,CAAC;AAjBW,QAAA,oBAAoB,wBAiB/B;AAMF;;;;;;;;;;;;GAYG;AACI,MAAM,qBAAqB,GAAG,KAAK,EAAE,EAC3C,WAAW,EACX,SAAS,EACT,SAAS,EACT,iBAAiB,EAAE,cAAc,EACjC,QAAQ,GACqB,EAG3B,EAAE;IACJ,MAAM,EAAE,qBAAqB,EAAE,EAAE,EAAE,GAAG,MAAM,IAAA,4BAAoB,EAAC;QAChE,WAAW;QACX,SAAS;QACT,SAAS;QACT,iBAAiB,EAAE,cAAc;KACjC,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;IAEvE,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,CAAC;AAC/C,CAAC,CAAC;AApBW,QAAA,qBAAqB,yBAoBhC;AAEF;;;;;;;;;;;;GAYG;AACI,MAAM,+BAA+B,GAAG,KAAK,EAAE,EACrD,WAAW,EACX,SAAS,EACT,SAAS,GAAG,CAAC,EACb,iBAAiB,GACW,EAG1B,EAAE;IACJ,MAAM,aAAa,GAClB,MAAM,WAAW,CAAC,uCAAuC,CAAC,SAAS,CAAC,CAAC;IAEtE,IAAI,aAAa,EAAE,CAAC;QACnB,MAAM,qBAAqB,GAAG,IAAA,sCAAgC,EAC7D,WAAW,CAAC,OAAO,CAAC,SAAS,EAC7B,SAAS,CACT,CAAC;QAEF,OAAO,EAAE,qBAAqB,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;IAC5C,CAAC;IAED,OAAO,MAAM,IAAA,4BAAoB,EAAC;QACjC,WAAW;QACX,SAAS;QACT,SAAS;QACT,iBAAiB;KACjB,CAAC,CAAC;AACJ,CAAC,CAAC;AA3BW,QAAA,+BAA+B,mCA2B1C","sourcesContent":["import {\n\tDriftClient,\n\tgetSignedMsgUserAccountPublicKey,\n\tPublicKey,\n\tTxParams,\n} from '@drift-labs/sdk';\nimport {\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n} from '@solana/web3.js';\n\ninterface CreateSwiftAccountIxParams {\n\tdriftClient: DriftClient;\n\tauthority: PublicKey;\n\tnumOrders?: number;\n\t/**\n\t * Optional external wallet to use as payer. If provided, this wallet will pay\n\t * for the account creation instead of the default wallet.\n\t */\n\trentPayerOverride?: PublicKey;\n}\n\n/**\n * Creates a transaction instruction for initializing a Swift (signed message user orders) account.\n *\n * @param driftClient - The Drift client instance\n * @param authority - The public key of the account authority\n * @param numOrders - The number of order slots to allocate (default: 8)\n * @param rentPayerOverride - Optional wallet to pay for account creation instead of the default wallet\n *\n * @returns The Swift account public key and the initialization instruction\n */\nexport const createSwiftAccountIx = async ({\n\tdriftClient,\n\tauthority,\n\tnumOrders = 8,\n\trentPayerOverride,\n}: CreateSwiftAccountIxParams): Promise<{\n\tswiftAccountPublicKey: PublicKey;\n\tix: TransactionInstruction;\n}> => {\n\tconst [swiftAccountPublicKey, ix] =\n\t\tawait driftClient.getInitializeSignedMsgUserOrdersAccountIx(\n\t\t\tauthority,\n\t\t\tnumOrders,\n\t\t\t{ externalWallet: rentPayerOverride }\n\t\t);\n\n\treturn { swiftAccountPublicKey, ix };\n};\n\ninterface CreateSwiftAccountTxnParams extends CreateSwiftAccountIxParams {\n\ttxParams?: TxParams;\n}\n\n/**\n * Creates a complete transaction for initializing a Swift (signed message user orders) account.\n *\n * Wraps {@link createSwiftAccountIx} and builds a transaction ready for signing and submission.\n *\n * @param driftClient - The Drift client instance\n * @param authority - The public key of the account authority\n * @param numOrders - The number of order slots to allocate (default: 8)\n * @param rentPayerOverride - Optional wallet to pay for account creation instead of the default wallet\n * @param txParams - Optional transaction parameters (compute units, priority fees, etc.)\n *\n * @returns The built transaction and the Swift account public key\n */\nexport const createSwiftAccountTxn = async ({\n\tdriftClient,\n\tauthority,\n\tnumOrders,\n\trentPayerOverride: externalWallet,\n\ttxParams,\n}: CreateSwiftAccountTxnParams): Promise<{\n\ttransaction: Transaction | VersionedTransaction;\n\tswiftAccountPublicKey: PublicKey;\n}> => {\n\tconst { swiftAccountPublicKey, ix } = await createSwiftAccountIx({\n\t\tdriftClient,\n\t\tauthority,\n\t\tnumOrders,\n\t\trentPayerOverride: externalWallet,\n\t});\n\n\tconst transaction = await driftClient.buildTransaction([ix], txParams);\n\n\treturn { transaction, swiftAccountPublicKey };\n};\n\n/**\n * Creates a Swift account instruction only if one doesn't already exist for the given authority.\n *\n * Always returns the Swift account public key. The `ix` will be `null` if the account\n * is already initialized, indicating no transaction is needed.\n *\n * @param driftClient - The Drift client instance\n * @param authority - The public key of the account authority\n * @param numOrders - The number of order slots to allocate (default: 8)\n * @param rentPayerOverride - Optional wallet to pay for account creation instead of the default wallet\n *\n * @returns The Swift account public key and the initialization instruction (null if already initialized)\n */\nexport const createSwiftAccountIxIfNotExists = async ({\n\tdriftClient,\n\tauthority,\n\tnumOrders = 8,\n\trentPayerOverride,\n}: CreateSwiftAccountIxParams): Promise<{\n\tswiftAccountPublicKey: PublicKey;\n\tix: TransactionInstruction | null;\n}> => {\n\tconst isInitialized =\n\t\tawait driftClient.isSignedMsgUserOrdersAccountInitialized(authority);\n\n\tif (isInitialized) {\n\t\tconst swiftAccountPublicKey = getSignedMsgUserAccountPublicKey(\n\t\t\tdriftClient.program.programId,\n\t\t\tauthority\n\t\t);\n\n\t\treturn { swiftAccountPublicKey, ix: null };\n\t}\n\n\treturn await createSwiftAccountIx({\n\t\tdriftClient,\n\t\tauthority,\n\t\tnumOrders,\n\t\trentPayerOverride,\n\t});\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './create';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./create"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/swift/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB","sourcesContent":["export * from './create';\n"]}
|