@drift-labs/vaults-sdk 0.1.0
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/.env.example +2 -0
- package/README.md +58 -0
- package/cli/cli.ts +105 -0
- package/cli/commands/applyProfitShare.ts +48 -0
- package/cli/commands/deposit.ts +35 -0
- package/cli/commands/index.ts +13 -0
- package/cli/commands/initVault.ts +61 -0
- package/cli/commands/initVaultDepositor.ts +43 -0
- package/cli/commands/listDepositorsForVault.ts +33 -0
- package/cli/commands/managerCancelWithdraw.ts +25 -0
- package/cli/commands/managerDeposit.ts +34 -0
- package/cli/commands/managerRequestWithdraw.ts +27 -0
- package/cli/commands/managerUpdateVault.ts +36 -0
- package/cli/commands/managerWithdraw.ts +25 -0
- package/cli/commands/requestWithdraw.ts +29 -0
- package/cli/commands/vaultDeposit.ts +43 -0
- package/cli/commands/vaultWithdraw.ts +43 -0
- package/cli/commands/viewVault.ts +30 -0
- package/cli/commands/viewVaultDepositor.ts +37 -0
- package/cli/commands/withdraw.ts +25 -0
- package/cli/utils.ts +119 -0
- package/lib/accountSubscribers/index.d.ts +2 -0
- package/lib/accountSubscribers/index.js +14 -0
- package/lib/accountSubscribers/pollingVaultDepositorSubscriber.d.ts +7 -0
- package/lib/accountSubscribers/pollingVaultDepositorSubscriber.js +44 -0
- package/lib/accountSubscribers/pollingVaultSubscriber.d.ts +7 -0
- package/lib/accountSubscribers/pollingVaultSubscriber.js +44 -0
- package/lib/accountSubscribers/pollingVaultsProgramAccountSubscriber.d.ts +28 -0
- package/lib/accountSubscribers/pollingVaultsProgramAccountSubscriber.js +68 -0
- package/lib/accounts/index.d.ts +2 -0
- package/lib/accounts/index.js +14 -0
- package/lib/accounts/vaultAccount.d.ts +15 -0
- package/lib/accounts/vaultAccount.js +53 -0
- package/lib/accounts/vaultDepositorAccount.d.ts +18 -0
- package/lib/accounts/vaultDepositorAccount.js +45 -0
- package/lib/accounts/vaultsProgramAccount.d.ts +13 -0
- package/lib/accounts/vaultsProgramAccount.js +25 -0
- package/lib/addresses.d.ts +4 -0
- package/lib/addresses.js +46 -0
- package/lib/constants/index.d.ts +3 -0
- package/lib/constants/index.js +5 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +21 -0
- package/lib/name.d.ts +3 -0
- package/lib/name.js +19 -0
- package/lib/parsers/index.d.ts +1 -0
- package/lib/parsers/index.js +13 -0
- package/lib/parsers/logParser.d.ts +14 -0
- package/lib/parsers/logParser.js +21 -0
- package/lib/types/drift_vaults.d.ts +1475 -0
- package/lib/types/drift_vaults.js +1477 -0
- package/lib/types/types.d.ts +137 -0
- package/lib/types/types.js +20 -0
- package/lib/utils.d.ts +7 -0
- package/lib/utils.js +43 -0
- package/lib/vaultClient.d.ts +100 -0
- package/lib/vaultClient.js +596 -0
- package/package.json +29 -0
- package/src/accountSubscribers/index.ts +2 -0
- package/src/accountSubscribers/pollingVaultDepositorSubscriber.ts +68 -0
- package/src/accountSubscribers/pollingVaultSubscriber.ts +62 -0
- package/src/accountSubscribers/pollingVaultsProgramAccountSubscriber.ts +111 -0
- package/src/accounts/index.ts +2 -0
- package/src/accounts/vaultAccount.ts +86 -0
- package/src/accounts/vaultDepositorAccount.ts +67 -0
- package/src/accounts/vaultsProgramAccount.ts +37 -0
- package/src/addresses.ts +43 -0
- package/src/constants/index.ts +3 -0
- package/src/idl/drift_vaults.json +1547 -0
- package/src/index.ts +9 -0
- package/src/name.ts +18 -0
- package/src/parsers/index.ts +1 -0
- package/src/parsers/logParser.ts +28 -0
- package/src/types/drift_vaults.ts +2949 -0
- package/src/types/types.ts +158 -0
- package/src/utils.ts +33 -0
- package/src/vaultClient.ts +904 -0
- package/tsconfig.json +13 -0
package/lib/addresses.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.getTokenVaultAddressSync = exports.getVaultDepositorAddressSync = exports.getVaultAddressSync = void 0;
|
|
23
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
24
|
+
const anchor = __importStar(require("@coral-xyz/anchor"));
|
|
25
|
+
function getVaultAddressSync(programId, encodedName) {
|
|
26
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
27
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('vault')),
|
|
28
|
+
Buffer.from(encodedName),
|
|
29
|
+
], programId)[0];
|
|
30
|
+
}
|
|
31
|
+
exports.getVaultAddressSync = getVaultAddressSync;
|
|
32
|
+
function getVaultDepositorAddressSync(programId, vault, authority) {
|
|
33
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
34
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('vault_depositor')),
|
|
35
|
+
vault.toBuffer(),
|
|
36
|
+
authority.toBuffer(),
|
|
37
|
+
], programId)[0];
|
|
38
|
+
}
|
|
39
|
+
exports.getVaultDepositorAddressSync = getVaultDepositorAddressSync;
|
|
40
|
+
function getTokenVaultAddressSync(programId, vault) {
|
|
41
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
42
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('vault_token_account')),
|
|
43
|
+
vault.toBuffer(),
|
|
44
|
+
], programId)[0];
|
|
45
|
+
}
|
|
46
|
+
exports.getTokenVaultAddressSync = getTokenVaultAddressSync;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './addresses';
|
|
2
|
+
export * from './name';
|
|
3
|
+
export * from './vaultClient';
|
|
4
|
+
export * from './accounts';
|
|
5
|
+
export * from './accountSubscribers';
|
|
6
|
+
export * from './utils';
|
|
7
|
+
export * from './types/types';
|
|
8
|
+
export * from './constants';
|
|
9
|
+
export * from './parsers';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./addresses"), exports);
|
|
14
|
+
__exportStar(require("./name"), exports);
|
|
15
|
+
__exportStar(require("./vaultClient"), exports);
|
|
16
|
+
__exportStar(require("./accounts"), exports);
|
|
17
|
+
__exportStar(require("./accountSubscribers"), exports);
|
|
18
|
+
__exportStar(require("./utils"), exports);
|
|
19
|
+
__exportStar(require("./types/types"), exports);
|
|
20
|
+
__exportStar(require("./constants"), exports);
|
|
21
|
+
__exportStar(require("./parsers"), exports);
|
package/lib/name.d.ts
ADDED
package/lib/name.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeName = exports.encodeName = exports.MAX_NAME_LENGTH = void 0;
|
|
4
|
+
exports.MAX_NAME_LENGTH = 32;
|
|
5
|
+
function encodeName(name) {
|
|
6
|
+
if (name.length > exports.MAX_NAME_LENGTH) {
|
|
7
|
+
throw Error(`Name (${name}) longer than 32 characters`);
|
|
8
|
+
}
|
|
9
|
+
const buffer = Buffer.alloc(32);
|
|
10
|
+
buffer.fill(name);
|
|
11
|
+
buffer.fill(' ', name.length);
|
|
12
|
+
return Array(...buffer);
|
|
13
|
+
}
|
|
14
|
+
exports.encodeName = encodeName;
|
|
15
|
+
function decodeName(bytes) {
|
|
16
|
+
const buffer = Buffer.from(bytes);
|
|
17
|
+
return buffer.toString('utf8').trim();
|
|
18
|
+
}
|
|
19
|
+
exports.decodeName = decodeName;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './logParser';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./logParser"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Program } from '@coral-xyz/anchor';
|
|
2
|
+
import { TransactionSignature } from '@solana/web3.js';
|
|
3
|
+
import { WrappedEvents } from '../types/types';
|
|
4
|
+
declare type Log = {
|
|
5
|
+
txSig: TransactionSignature;
|
|
6
|
+
slot: number;
|
|
7
|
+
logs: string[];
|
|
8
|
+
};
|
|
9
|
+
export declare class LogParser {
|
|
10
|
+
private program;
|
|
11
|
+
constructor(program: Program);
|
|
12
|
+
parseEventsFromLogs(event: Log): WrappedEvents;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogParser = void 0;
|
|
4
|
+
class LogParser {
|
|
5
|
+
constructor(program) {
|
|
6
|
+
this.program = program;
|
|
7
|
+
}
|
|
8
|
+
parseEventsFromLogs(event) {
|
|
9
|
+
const records = [];
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
const eventGenerator = this.program._events._eventParser.parseLogs(event.logs, false);
|
|
12
|
+
for (const eventLog of eventGenerator) {
|
|
13
|
+
eventLog.data.txSig = event.txSig;
|
|
14
|
+
eventLog.data.slot = event.slot;
|
|
15
|
+
eventLog.data.eventType = eventLog.name;
|
|
16
|
+
records.push(eventLog.data);
|
|
17
|
+
}
|
|
18
|
+
return records;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.LogParser = LogParser;
|