@drift-labs/common 1.0.17 → 1.0.18
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/EnvironmentConstants.js +2 -2
- package/lib/EnvironmentConstants.js.map +1 -1
- package/lib/clients/redisClient.d.ts +0 -1
- package/lib/clients/swiftClient.d.ts +1 -1
- package/lib/clients/swiftClient.js +60 -20
- package/lib/clients/swiftClient.js.map +1 -1
- package/lib/clients/tvFeed.d.ts +2 -1
- package/lib/clients/tvFeed.js +4 -3
- package/lib/clients/tvFeed.js.map +1 -1
- package/lib/common-ui-utils/commonUiUtils.d.ts +0 -1
- package/lib/constants/autogenerated/driftErrors.json +5 -1
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.d.ts +1 -1
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.js +14 -5
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.js.map +1 -1
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/types.d.ts +8 -1
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/types.js.map +1 -1
- package/lib/drift/Drift/clients/AuthorityDrift/index.d.ts +1 -1
- package/lib/drift/Drift/clients/AuthorityDrift/index.js.map +1 -1
- package/lib/drift/Drift/clients/CentralServerDrift/index.d.ts +2 -2
- package/lib/drift/Drift/clients/CentralServerDrift/index.js +4 -4
- package/lib/drift/Drift/clients/CentralServerDrift/index.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.d.ts +4 -2
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js +9 -2
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js +3 -5
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.d.ts +9 -1
- package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.js +7 -5
- package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/positionMaxLeverage.d.ts +2 -2
- package/lib/drift/base/actions/trade/openPerpOrder/positionMaxLeverage.js +6 -2
- package/lib/drift/base/actions/trade/openPerpOrder/positionMaxLeverage.js.map +1 -1
- package/lib/drift/base/actions/trade/swap.d.ts +6 -13
- package/lib/drift/base/actions/trade/swap.js +11 -36
- package/lib/drift/base/actions/trade/swap.js.map +1 -1
- package/lib/drift/base/actions/user/create.js +6 -1
- package/lib/drift/base/actions/user/create.js.map +1 -1
- package/lib/serializableTypes.d.ts +1 -0
- package/lib/serializableTypes.js +4 -0
- package/lib/serializableTypes.js.map +1 -1
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/token.d.ts +2 -1
- package/lib/utils/token.js +3 -2
- package/lib/utils/token.js.map +1 -1
- package/package.json +14 -2
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
2
|
import { BN, Event, OrderActionRecord, OrderRecord, PublicKey, BigNum, MarketType, DriftClient, SpotMarketConfig } from '@drift-labs/sdk';
|
|
4
3
|
import { UIMatchedOrderRecordAndAction, UISerializableOrderActionRecord } from '../serializableTypes';
|
|
5
4
|
import { AccountInfo, Connection } from '@solana/web3.js';
|
package/lib/utils/token.d.ts
CHANGED
|
@@ -6,9 +6,10 @@ export declare const getTokenAddress: (mintAddress: string, userPubKey: string)
|
|
|
6
6
|
* This should be used for spot token movement in and out of the user's wallet.
|
|
7
7
|
* @param mintAddress - The mint address
|
|
8
8
|
* @param authorityPubKey - The authority's public key
|
|
9
|
+
* @param tokenProgram - The token program ID (defaults to TOKEN_PROGRAM_ID, use TOKEN_2022_PROGRAM_ID for Token-2022 tokens)
|
|
9
10
|
* @returns The associated token address
|
|
10
11
|
*/
|
|
11
|
-
export declare const getTokenAddressForDepositAndWithdraw: (mintAddress: PublicKey, authorityPubKey: PublicKey) => Promise<PublicKey>;
|
|
12
|
+
export declare const getTokenAddressForDepositAndWithdraw: (mintAddress: PublicKey, authorityPubKey: PublicKey, tokenProgram?: PublicKey) => Promise<PublicKey>;
|
|
12
13
|
export declare const getTokenAccount: (connection: Connection, mintAddress: string, userPubKey: string) => Promise<{
|
|
13
14
|
pubkey: PublicKey;
|
|
14
15
|
account: import('@solana/web3.js').AccountInfo<import('@solana/web3.js').ParsedAccountData>;
|
package/lib/utils/token.js
CHANGED
|
@@ -16,13 +16,14 @@ exports.getTokenAddress = getTokenAddress;
|
|
|
16
16
|
* This should be used for spot token movement in and out of the user's wallet.
|
|
17
17
|
* @param mintAddress - The mint address
|
|
18
18
|
* @param authorityPubKey - The authority's public key
|
|
19
|
+
* @param tokenProgram - The token program ID (defaults to TOKEN_PROGRAM_ID, use TOKEN_2022_PROGRAM_ID for Token-2022 tokens)
|
|
19
20
|
* @returns The associated token address
|
|
20
21
|
*/
|
|
21
|
-
const getTokenAddressForDepositAndWithdraw = async (mintAddress, authorityPubKey) => {
|
|
22
|
+
const getTokenAddressForDepositAndWithdraw = async (mintAddress, authorityPubKey, tokenProgram = spl_token_1.TOKEN_PROGRAM_ID) => {
|
|
22
23
|
const isSol = mintAddress.equals(sdk_1.WRAPPED_SOL_MINT);
|
|
23
24
|
if (isSol)
|
|
24
25
|
return authorityPubKey;
|
|
25
|
-
return (0, spl_token_1.getAssociatedTokenAddress)(mintAddress, authorityPubKey, true);
|
|
26
|
+
return (0, spl_token_1.getAssociatedTokenAddress)(mintAddress, authorityPubKey, true, tokenProgram);
|
|
26
27
|
};
|
|
27
28
|
exports.getTokenAddressForDepositAndWithdraw = getTokenAddressForDepositAndWithdraw;
|
|
28
29
|
const getTokenAccount = async (connection, mintAddress, userPubKey) => {
|
package/lib/utils/token.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../src/utils/token.ts"],"names":[],"mappings":";;;AAAA,yCAAmD;AACnD,
|
|
1
|
+
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../src/utils/token.ts"],"names":[],"mappings":";;;AAAA,yCAAmD;AACnD,iDAI2B;AAC3B,6CAAgF;AAEhF,+CAG2B;AAF1B,6GAAA,gBAAgB,OAAA;AAChB,6HAAA,gCAAgC,OAAA;AAG1B,MAAM,eAAe,GAAG,CAC9B,WAAmB,EACnB,UAAkB,EACG,EAAE;IACvB,OAAO,IAAA,qCAAyB,EAC/B,IAAI,mBAAS,CAAC,WAAW,CAAC,EAC1B,IAAI,mBAAS,CAAC,UAAU,CAAC,EACzB,IAAI,CACJ,CAAC;AACH,CAAC,CAAC;AATW,QAAA,eAAe,mBAS1B;AAEF;;;;;;;GAOG;AACI,MAAM,oCAAoC,GAAG,KAAK,EACxD,WAAsB,EACtB,eAA0B,EAC1B,eAA0B,4BAAgB,EACrB,EAAE;IACvB,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,sBAAgB,CAAC,CAAC;IAEnD,IAAI,KAAK;QAAE,OAAO,eAAe,CAAC;IAElC,OAAO,IAAA,qCAAyB,EAC/B,WAAW,EACX,eAAe,EACf,IAAI,EACJ,YAAY,CACZ,CAAC;AACH,CAAC,CAAC;AAfW,QAAA,oCAAoC,wCAe/C;AAEK,MAAM,eAAe,GAAG,KAAK,EACnC,UAAsB,EACtB,WAAmB,EACnB,UAAkB,EAMhB,EAAE;IACJ,MAAM,aAAa,GAAG,MAAM,UAAU,CAAC,6BAA6B,CACnE,IAAI,mBAAS,CAAC,UAAU,CAAC,EACzB,EAAE,IAAI,EAAE,IAAI,mBAAS,CAAC,WAAW,CAAC,EAAE,CACpC,CAAC;IAEF,MAAM,iBAAiB,GAAG,MAAM,IAAA,qCAAyB,EACxD,IAAI,mBAAS,CAAC,WAAW,CAAC,EAC1B,IAAI,mBAAS,CAAC,UAAU,CAAC,EACzB,IAAI,CACJ,CAAC;IAEF,MAAM,aAAa,GAClB,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CACtC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CACxC,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAEhC,OAAO,aAAa,CAAC;AACtB,CAAC,CAAC;AA3BW,QAAA,eAAe,mBA2B1B;AAEK,MAAM,oBAAoB,GAAG,KAAK,EACxC,KAAgB,EAChB,WAAsB,EACtB,KAAiB,EACiB,EAAE;IACpC,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,KAAK,GAAG,KAAK,CAAC;IACf,CAAC;IAED,MAAM,iBAAiB,GAAG,MAAM,IAAA,qCAAyB,EACxD,WAAW,EACX,KAAK,EACL,IAAI,CACJ,CAAC;IAEF,MAAM,WAAW,GAAG,MAAM,IAAA,mDAAuC,EAChE,KAAK,EACL,iBAAiB,EACjB,KAAK,EACL,WAAW,CACX,CAAC;IAEF,OAAO,WAAW,CAAC;AACpB,CAAC,CAAC;AAvBW,QAAA,oBAAoB,wBAuB/B","sourcesContent":["import { WRAPPED_SOL_MINT } from '@drift-labs/sdk';\nimport {\n\tcreateAssociatedTokenAccountInstruction,\n\tgetAssociatedTokenAddress,\n\tTOKEN_PROGRAM_ID,\n} from '@solana/spl-token';\nimport { Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';\n\nexport {\n\tTOKEN_PROGRAM_ID,\n\tcreateTransferCheckedInstruction,\n} from '@solana/spl-token';\n\nexport const getTokenAddress = (\n\tmintAddress: string,\n\tuserPubKey: string\n): Promise<PublicKey> => {\n\treturn getAssociatedTokenAddress(\n\t\tnew PublicKey(mintAddress),\n\t\tnew PublicKey(userPubKey),\n\t\ttrue\n\t);\n};\n\n/**\n * Get the associated token address for the given mint and user public key. If the mint is SOL, return the user public key.\n * This should be used for spot token movement in and out of the user's wallet.\n * @param mintAddress - The mint address\n * @param authorityPubKey - The authority's public key\n * @param tokenProgram - The token program ID (defaults to TOKEN_PROGRAM_ID, use TOKEN_2022_PROGRAM_ID for Token-2022 tokens)\n * @returns The associated token address\n */\nexport const getTokenAddressForDepositAndWithdraw = async (\n\tmintAddress: PublicKey,\n\tauthorityPubKey: PublicKey,\n\ttokenProgram: PublicKey = TOKEN_PROGRAM_ID\n): Promise<PublicKey> => {\n\tconst isSol = mintAddress.equals(WRAPPED_SOL_MINT);\n\n\tif (isSol) return authorityPubKey;\n\n\treturn getAssociatedTokenAddress(\n\t\tmintAddress,\n\t\tauthorityPubKey,\n\t\ttrue,\n\t\ttokenProgram\n\t);\n};\n\nexport const getTokenAccount = async (\n\tconnection: Connection,\n\tmintAddress: string,\n\tuserPubKey: string\n): Promise<{\n\tpubkey: PublicKey;\n\taccount: import('@solana/web3.js').AccountInfo<\n\t\timport('@solana/web3.js').ParsedAccountData\n\t>;\n}> => {\n\tconst tokenAccounts = await connection.getParsedTokenAccountsByOwner(\n\t\tnew PublicKey(userPubKey),\n\t\t{ mint: new PublicKey(mintAddress) }\n\t);\n\n\tconst associatedAddress = await getAssociatedTokenAddress(\n\t\tnew PublicKey(mintAddress),\n\t\tnew PublicKey(userPubKey),\n\t\ttrue\n\t);\n\n\tconst targetAccount =\n\t\ttokenAccounts.value.filter((account) =>\n\t\t\taccount.pubkey.equals(associatedAddress)\n\t\t)[0] || tokenAccounts.value[0];\n\n\treturn targetAccount;\n};\n\nexport const createTokenAccountIx = async (\n\towner: PublicKey,\n\tmintAddress: PublicKey,\n\tpayer?: PublicKey\n): Promise<TransactionInstruction> => {\n\tif (!payer) {\n\t\tpayer = owner;\n\t}\n\n\tconst associatedAddress = await getAssociatedTokenAddress(\n\t\tmintAddress,\n\t\towner,\n\t\ttrue\n\t);\n\n\tconst createAtaIx = await createAssociatedTokenAccountInstruction(\n\t\tpayer,\n\t\tassociatedAddress,\n\t\towner,\n\t\tmintAddress\n\t);\n\n\treturn createAtaIx;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drift-labs/common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.18",
|
|
4
4
|
"description": "Common functions for Drift",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"author": "Drift Labs",
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"@drift-labs/sdk": "^2.136.0",
|
|
20
21
|
"@slack/web-api": "6.4.0",
|
|
21
22
|
"@solana/spl-token": "0.3.8",
|
|
22
23
|
"@solana/web3.js": "1.98.0",
|
|
@@ -39,6 +40,9 @@
|
|
|
39
40
|
},
|
|
40
41
|
"scripts": {
|
|
41
42
|
"build": "yarn clean && tsc",
|
|
43
|
+
"build:minify": "node build-browser.js && node build-node.js",
|
|
44
|
+
"build:minify:browser": "node build-browser.js",
|
|
45
|
+
"build:minify:node": "node build-node.js",
|
|
42
46
|
"prepublishOnly": "yarn build",
|
|
43
47
|
"watch": "yarn clean && tsc --watch",
|
|
44
48
|
"build-dual": "yarn clean && tsup",
|
|
@@ -71,14 +75,22 @@
|
|
|
71
75
|
"@jest/globals": "29.3.1",
|
|
72
76
|
"@types/mocha": "10.0.4",
|
|
73
77
|
"@types/sinon": "^17.0.4",
|
|
78
|
+
"buffer": "^6.0.3",
|
|
74
79
|
"chai": "4.3.10",
|
|
80
|
+
"crypto-browserify": "^3.12.1",
|
|
75
81
|
"encoding": "0.1.13",
|
|
82
|
+
"esbuild": "^0.27.1",
|
|
76
83
|
"jest": "29.7.0",
|
|
77
84
|
"madge": "^8.0.0",
|
|
78
85
|
"mocha": "10.2.0",
|
|
86
|
+
"os-browserify": "^0.3.0",
|
|
87
|
+
"path-browserify": "^1.0.1",
|
|
88
|
+
"process": "^0.11.10",
|
|
79
89
|
"sinon": "^21.0.0",
|
|
90
|
+
"stream-browserify": "^3.0.0",
|
|
80
91
|
"ts-node": "10.9.1",
|
|
81
|
-
"typescript": "5.4.5"
|
|
92
|
+
"typescript": "5.4.5",
|
|
93
|
+
"vm-browserify": "^1.1.2"
|
|
82
94
|
},
|
|
83
95
|
"publishConfig": {
|
|
84
96
|
"access": "public"
|