@deriverse/kit 1.0.38 → 1.0.41
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/dist/auto_buffer.d.ts +0 -2
- package/dist/auto_data.d.ts +0 -2
- package/dist/constants.d.ts +12 -0
- package/dist/constants.js +26 -0
- package/dist/engine/account-helpers.d.ts +59 -0
- package/dist/engine/account-helpers.js +177 -0
- package/dist/engine/account-helpers.test.d.ts +1 -0
- package/dist/engine/account-helpers.test.js +199 -0
- package/dist/engine/client-queries.d.ts +36 -0
- package/dist/engine/client-queries.js +498 -0
- package/dist/engine/client-queries.test.d.ts +1 -0
- package/dist/engine/client-queries.test.js +341 -0
- package/dist/engine/context-builders.d.ts +16 -0
- package/dist/engine/context-builders.js +158 -0
- package/dist/engine/context-builders.test.d.ts +1 -0
- package/dist/engine/context-builders.test.js +156 -0
- package/dist/engine/index.d.ts +101 -0
- package/dist/engine/index.js +745 -0
- package/dist/engine/index.test.d.ts +1 -0
- package/dist/engine/index.test.js +663 -0
- package/dist/engine/logs-decoder.d.ts +18 -0
- package/dist/engine/logs-decoder.js +414 -0
- package/dist/engine/logs-decoder.test.d.ts +1 -0
- package/dist/engine/logs-decoder.test.js +836 -0
- package/dist/engine/perp-instructions.d.ts +68 -0
- package/dist/engine/perp-instructions.js +478 -0
- package/dist/engine/perp-instructions.test.d.ts +1 -0
- package/dist/engine/perp-instructions.test.js +296 -0
- package/dist/engine/spot-instructions.d.ts +52 -0
- package/dist/engine/spot-instructions.js +376 -0
- package/dist/engine/spot-instructions.test.d.ts +1 -0
- package/dist/engine/spot-instructions.test.js +221 -0
- package/dist/engine/utils.d.ts +23 -0
- package/dist/engine/utils.js +329 -0
- package/dist/engine/utils.test.d.ts +1 -0
- package/dist/engine/utils.test.js +120 -0
- package/dist/index.d.ts +6 -247
- package/dist/index.js +14 -2925
- package/dist/instruction_models.d.ts +0 -2
- package/dist/instruction_models.js +39 -40
- package/dist/logs_models.d.ts +0 -2
- package/dist/types/engine-args.d.ts +32 -0
- package/dist/types/engine-args.js +2 -0
- package/dist/types/enums.d.ts +43 -0
- package/dist/{types.js → types/enums.js} +3 -5
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.js +38 -0
- package/dist/types/log-message.d.ts +2 -0
- package/dist/types/log-message.js +2 -0
- package/dist/types/responses.d.ts +248 -0
- package/dist/types/responses.js +2 -0
- package/dist/types/schemas.d.ts +165 -0
- package/dist/types/schemas.js +254 -0
- package/dist/types/schemas.test.d.ts +1 -0
- package/dist/types/schemas.test.js +94 -0
- package/dist/utils.d.ts +0 -0
- package/dist/utils.js +1 -0
- package/package.json +26 -6
- package/dist/types.d.ts +0 -565
package/dist/auto_buffer.d.ts
CHANGED
package/dist/auto_data.d.ts
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const VERSION = 1;
|
|
2
|
+
export declare const PROGRAM_ID: import("@solana/kit").Address<"DRVSpZ2YUYYKgZP8XtLhAGtT1zYSCKzeHfb4DgRnrgqD">;
|
|
3
|
+
export declare const MARKET_DEPTH = 20;
|
|
4
|
+
export declare const ADDRESS_LOOKUP_TABLE_PROGRAM_ID: import("@solana/kit").Address<"AddressLookupTab1e1111111111111111111111111">;
|
|
5
|
+
export declare const SYSTEM_PROGRAM_ID: import("@solana/kit").Address<"11111111111111111111111111111111">;
|
|
6
|
+
export declare const TOKEN_PROGRAM_ID: import("@solana/kit").Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
7
|
+
export declare const TOKEN_2022_PROGRAM_ID: import("@solana/kit").Address<"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb">;
|
|
8
|
+
export declare const ASSOCIATED_TOKEN_PROGRAM_ID: import("@solana/kit").Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">;
|
|
9
|
+
export declare let dec: number;
|
|
10
|
+
export declare let lpDec: number;
|
|
11
|
+
export declare const nullOrder = 65535;
|
|
12
|
+
export declare function setDecimals(uiNumbers: boolean): void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nullOrder = exports.lpDec = exports.dec = exports.ASSOCIATED_TOKEN_PROGRAM_ID = exports.TOKEN_2022_PROGRAM_ID = exports.TOKEN_PROGRAM_ID = exports.SYSTEM_PROGRAM_ID = exports.ADDRESS_LOOKUP_TABLE_PROGRAM_ID = exports.MARKET_DEPTH = exports.PROGRAM_ID = exports.VERSION = void 0;
|
|
4
|
+
exports.setDecimals = setDecimals;
|
|
5
|
+
const kit_1 = require("@solana/kit");
|
|
6
|
+
exports.VERSION = 1;
|
|
7
|
+
exports.PROGRAM_ID = (0, kit_1.address)('DRVSpZ2YUYYKgZP8XtLhAGtT1zYSCKzeHfb4DgRnrgqD');
|
|
8
|
+
exports.MARKET_DEPTH = 20;
|
|
9
|
+
exports.ADDRESS_LOOKUP_TABLE_PROGRAM_ID = (0, kit_1.address)('AddressLookupTab1e1111111111111111111111111');
|
|
10
|
+
exports.SYSTEM_PROGRAM_ID = (0, kit_1.address)('11111111111111111111111111111111');
|
|
11
|
+
exports.TOKEN_PROGRAM_ID = (0, kit_1.address)('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA');
|
|
12
|
+
exports.TOKEN_2022_PROGRAM_ID = (0, kit_1.address)('TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb');
|
|
13
|
+
exports.ASSOCIATED_TOKEN_PROGRAM_ID = (0, kit_1.address)('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL');
|
|
14
|
+
exports.dec = 1000000000;
|
|
15
|
+
exports.lpDec = 10000;
|
|
16
|
+
exports.nullOrder = 0xffff;
|
|
17
|
+
function setDecimals(uiNumbers) {
|
|
18
|
+
if (!uiNumbers) {
|
|
19
|
+
exports.dec = 1;
|
|
20
|
+
exports.lpDec = 1;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
exports.dec = 1000000000;
|
|
24
|
+
exports.lpDec = 10000;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Address, Rpc, DataSlice, Commitment, SolanaRpcApiDevnet, SolanaRpcApiMainnet } from '@solana/kit';
|
|
2
|
+
import { getInstrAccountByTagArgs } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Context needed for account helper functions
|
|
5
|
+
*/
|
|
6
|
+
export interface AccountHelperContext {
|
|
7
|
+
rpc: Rpc<SolanaRpcApiDevnet> | Rpc<SolanaRpcApiMainnet>;
|
|
8
|
+
programId: Address;
|
|
9
|
+
version: number;
|
|
10
|
+
commitment: Commitment;
|
|
11
|
+
drvsAuthority: Address;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get program-derived account address by tag
|
|
15
|
+
*/
|
|
16
|
+
declare function getAccountByTag(ctx: AccountHelperContext, tag: number): Promise<Address>;
|
|
17
|
+
/**
|
|
18
|
+
* Get instrument account address by tag and token IDs
|
|
19
|
+
*/
|
|
20
|
+
declare function getInstrAccountByTag(ctx: AccountHelperContext, args: getInstrAccountByTagArgs): Promise<Address>;
|
|
21
|
+
/**
|
|
22
|
+
* Get token account address for a mint
|
|
23
|
+
*/
|
|
24
|
+
declare function getTokenAccount(ctx: AccountHelperContext, mint: Address): Promise<Address>;
|
|
25
|
+
/**
|
|
26
|
+
* Get Token ID from mint public key if this token registered on Deriverse
|
|
27
|
+
*/
|
|
28
|
+
declare function getTokenId(ctx: AccountHelperContext, mint: Address): Promise<number | null>;
|
|
29
|
+
/**
|
|
30
|
+
* Get instrument ID if this instrument registered on Deriverse
|
|
31
|
+
*/
|
|
32
|
+
declare function getInstrId(ctx: AccountHelperContext, args: {
|
|
33
|
+
assetTokenId: number;
|
|
34
|
+
crncyTokenId: number;
|
|
35
|
+
}): Promise<number | null>;
|
|
36
|
+
/**
|
|
37
|
+
* Find accounts by tag (used during initialization)
|
|
38
|
+
*/
|
|
39
|
+
declare function findAccountsByTag(ctx: AccountHelperContext, tag: number, dataSlice?: DataSlice): Promise<Readonly<{
|
|
40
|
+
account: Readonly<{
|
|
41
|
+
executable: boolean;
|
|
42
|
+
lamports: import("@solana/kit").Lamports;
|
|
43
|
+
owner: Address;
|
|
44
|
+
rentEpoch: bigint;
|
|
45
|
+
space: bigint;
|
|
46
|
+
}> & Readonly<{
|
|
47
|
+
data: import("@solana/kit").Base64EncodedDataResponse;
|
|
48
|
+
}>;
|
|
49
|
+
pubkey: Address;
|
|
50
|
+
}>[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Find client primary account PDA
|
|
53
|
+
*/
|
|
54
|
+
declare function findClientPrimaryAccount(ctx: Pick<AccountHelperContext, 'programId' | 'version'>, signer: Address): Promise<Address>;
|
|
55
|
+
/**
|
|
56
|
+
* Find client community account PDA
|
|
57
|
+
*/
|
|
58
|
+
declare function findClientCommunityAccount(ctx: Pick<AccountHelperContext, 'programId' | 'version'>, signer: Address): Promise<Address>;
|
|
59
|
+
export { getAccountByTag, getInstrAccountByTag, getTokenAccount, getTokenId, getInstrId, findAccountsByTag, findClientPrimaryAccount, findClientCommunityAccount, };
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getAccountByTag = getAccountByTag;
|
|
16
|
+
exports.getInstrAccountByTag = getInstrAccountByTag;
|
|
17
|
+
exports.getTokenAccount = getTokenAccount;
|
|
18
|
+
exports.getTokenId = getTokenId;
|
|
19
|
+
exports.getInstrId = getInstrId;
|
|
20
|
+
exports.findAccountsByTag = findAccountsByTag;
|
|
21
|
+
exports.findClientPrimaryAccount = findClientPrimaryAccount;
|
|
22
|
+
exports.findClientCommunityAccount = findClientCommunityAccount;
|
|
23
|
+
const kit_1 = require("@solana/kit");
|
|
24
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
25
|
+
const buffer_1 = require("buffer");
|
|
26
|
+
const enums_1 = require("../types/enums");
|
|
27
|
+
const structure_models_1 = require("../structure_models");
|
|
28
|
+
/**
|
|
29
|
+
* Get program-derived account address by tag
|
|
30
|
+
*/
|
|
31
|
+
function getAccountByTag(ctx, tag) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
let buf = buffer_1.Buffer.alloc(8);
|
|
34
|
+
buf.writeInt32LE(ctx.version, 0);
|
|
35
|
+
buf.writeInt32LE(tag, 4);
|
|
36
|
+
const address = (yield (0, kit_1.getProgramDerivedAddress)({
|
|
37
|
+
programAddress: ctx.programId,
|
|
38
|
+
seeds: [buf, (0, kit_1.getAddressEncoder)().encode(ctx.drvsAuthority)],
|
|
39
|
+
}))[0];
|
|
40
|
+
return address;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get instrument account address by tag and token IDs
|
|
45
|
+
*/
|
|
46
|
+
function getInstrAccountByTag(ctx, args) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
let buf = buffer_1.Buffer.alloc(16);
|
|
49
|
+
buf.writeInt32LE(ctx.version, 0);
|
|
50
|
+
buf.writeInt32LE(args.tag, 4);
|
|
51
|
+
buf.writeInt32LE(args.assetTokenId, 8);
|
|
52
|
+
buf.writeInt32LE(args.crncyTokenId, 12);
|
|
53
|
+
const address = (yield (0, kit_1.getProgramDerivedAddress)({
|
|
54
|
+
programAddress: ctx.programId,
|
|
55
|
+
seeds: [buf, (0, kit_1.getAddressEncoder)().encode(ctx.drvsAuthority)],
|
|
56
|
+
}))[0];
|
|
57
|
+
return address;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get token account address for a mint
|
|
62
|
+
*/
|
|
63
|
+
function getTokenAccount(ctx, mint) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
let buf = buffer_1.Buffer.from((0, kit_1.getAddressEncoder)().encode(mint).buffer);
|
|
66
|
+
buf.writeInt32LE(ctx.version, 28);
|
|
67
|
+
const address = (yield (0, kit_1.getProgramDerivedAddress)({
|
|
68
|
+
programAddress: ctx.programId,
|
|
69
|
+
seeds: [buf, (0, kit_1.getAddressEncoder)().encode(ctx.drvsAuthority)],
|
|
70
|
+
}))[0];
|
|
71
|
+
return address;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get Token ID from mint public key if this token registered on Deriverse
|
|
76
|
+
*/
|
|
77
|
+
function getTokenId(ctx, mint) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
const tokenAddress = yield getTokenAccount(ctx, mint);
|
|
80
|
+
let info = yield ctx.rpc
|
|
81
|
+
.getAccountInfo(tokenAddress, {
|
|
82
|
+
commitment: ctx.commitment,
|
|
83
|
+
encoding: 'base64',
|
|
84
|
+
dataSlice: { offset: structure_models_1.TokenStateModel.OFFSET_ID, length: 4 },
|
|
85
|
+
})
|
|
86
|
+
.send();
|
|
87
|
+
if (!info.value) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
const data = buffer_1.Buffer.from((0, kit_1.getBase64Encoder)().encode(info.value.data[0]));
|
|
92
|
+
return data.readUInt32LE(0);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get instrument ID if this instrument registered on Deriverse
|
|
98
|
+
*/
|
|
99
|
+
function getInstrId(ctx, args) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
const instrAddress = yield getInstrAccountByTag(ctx, {
|
|
102
|
+
assetTokenId: args.assetTokenId,
|
|
103
|
+
crncyTokenId: args.crncyTokenId,
|
|
104
|
+
tag: enums_1.AccountType.INSTR,
|
|
105
|
+
});
|
|
106
|
+
let info = yield ctx.rpc
|
|
107
|
+
.getAccountInfo(instrAddress, {
|
|
108
|
+
commitment: ctx.commitment,
|
|
109
|
+
encoding: 'base64',
|
|
110
|
+
dataSlice: { offset: structure_models_1.InstrAccountHeaderModel.OFFSET_INSTR_ID, length: 4 },
|
|
111
|
+
})
|
|
112
|
+
.send();
|
|
113
|
+
if (info.value == null) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
const data = buffer_1.Buffer.from((0, kit_1.getBase64Encoder)().encode(info.value.data[0]));
|
|
118
|
+
return data.readUInt32LE(0);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Find accounts by tag (used during initialization)
|
|
124
|
+
*/
|
|
125
|
+
function findAccountsByTag(ctx, tag, dataSlice) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
let tagBuf = buffer_1.Buffer.alloc(8);
|
|
128
|
+
tagBuf.writeUInt32LE(tag, 0);
|
|
129
|
+
tagBuf.writeUInt32LE(ctx.version, 4);
|
|
130
|
+
let accounts = yield ctx.rpc
|
|
131
|
+
.getProgramAccounts(ctx.programId, {
|
|
132
|
+
encoding: 'base64',
|
|
133
|
+
dataSlice: dataSlice,
|
|
134
|
+
filters: [
|
|
135
|
+
{
|
|
136
|
+
memcmp: {
|
|
137
|
+
offset: BigInt(0),
|
|
138
|
+
encoding: 'base58',
|
|
139
|
+
bytes: bs58_1.default.encode(tagBuf),
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
})
|
|
144
|
+
.send();
|
|
145
|
+
return accounts;
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Find client primary account PDA
|
|
150
|
+
*/
|
|
151
|
+
function findClientPrimaryAccount(ctx, signer) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
let tagBuf = buffer_1.Buffer.alloc(8);
|
|
154
|
+
tagBuf.writeUint32LE(ctx.version, 0);
|
|
155
|
+
tagBuf.writeUint32LE(enums_1.AccountType.CLIENT_PRIMARY, 4);
|
|
156
|
+
const address = (yield (0, kit_1.getProgramDerivedAddress)({
|
|
157
|
+
programAddress: ctx.programId,
|
|
158
|
+
seeds: [tagBuf, (0, kit_1.getAddressEncoder)().encode(signer)],
|
|
159
|
+
}))[0];
|
|
160
|
+
return address;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Find client community account PDA
|
|
165
|
+
*/
|
|
166
|
+
function findClientCommunityAccount(ctx, signer) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
let tagBuf = buffer_1.Buffer.alloc(8);
|
|
169
|
+
tagBuf.writeUint32LE(ctx.version, 0);
|
|
170
|
+
tagBuf.writeUint32LE(enums_1.AccountType.CLIENT_COMMUNITY, 4);
|
|
171
|
+
const address = (yield (0, kit_1.getProgramDerivedAddress)({
|
|
172
|
+
programAddress: ctx.programId,
|
|
173
|
+
seeds: [tagBuf, (0, kit_1.getAddressEncoder)().encode(signer)],
|
|
174
|
+
}))[0];
|
|
175
|
+
return address;
|
|
176
|
+
});
|
|
177
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const vitest_1 = require("vitest");
|
|
13
|
+
const account_helpers_1 = require("./account-helpers");
|
|
14
|
+
const enums_1 = require("../types/enums");
|
|
15
|
+
// Mock context for testing PDA derivation
|
|
16
|
+
function createMockContext(overrides = {}) {
|
|
17
|
+
return Object.assign({ rpc: {}, programId: 'DRVSvY68xD69Zwwgj9N8hRBu2eXvEzy8eejiVLNYGLti', version: 1, commitment: 'confirmed', drvsAuthority: 'DRVStQsAKhF8gpz1xLzWyk2Q1HKKF3g21tknXtHpVLab' }, overrides);
|
|
18
|
+
}
|
|
19
|
+
(0, vitest_1.describe)('account-helpers', () => {
|
|
20
|
+
(0, vitest_1.describe)('getAccountByTag', () => {
|
|
21
|
+
(0, vitest_1.it)('returns a valid address', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
const ctx = createMockContext();
|
|
23
|
+
const address = yield (0, account_helpers_1.getAccountByTag)(ctx, enums_1.AccountType.ROOT);
|
|
24
|
+
(0, vitest_1.expect)(address).toBeDefined();
|
|
25
|
+
(0, vitest_1.expect)(typeof address).toBe('string');
|
|
26
|
+
(0, vitest_1.expect)(address.length).toBeGreaterThan(30);
|
|
27
|
+
}));
|
|
28
|
+
(0, vitest_1.it)('returns consistent addresses for same inputs', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
const ctx = createMockContext();
|
|
30
|
+
const address1 = yield (0, account_helpers_1.getAccountByTag)(ctx, enums_1.AccountType.ROOT);
|
|
31
|
+
const address2 = yield (0, account_helpers_1.getAccountByTag)(ctx, enums_1.AccountType.ROOT);
|
|
32
|
+
(0, vitest_1.expect)(address1).toBe(address2);
|
|
33
|
+
}));
|
|
34
|
+
(0, vitest_1.it)('returns different addresses for different tags', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
const ctx = createMockContext();
|
|
36
|
+
const addressRoot = yield (0, account_helpers_1.getAccountByTag)(ctx, enums_1.AccountType.ROOT);
|
|
37
|
+
const addressCommunity = yield (0, account_helpers_1.getAccountByTag)(ctx, enums_1.AccountType.COMMUNITY);
|
|
38
|
+
(0, vitest_1.expect)(addressRoot).not.toBe(addressCommunity);
|
|
39
|
+
}));
|
|
40
|
+
(0, vitest_1.it)('returns different addresses for different versions', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
const ctx1 = createMockContext({ version: 1 });
|
|
42
|
+
const ctx2 = createMockContext({ version: 2 });
|
|
43
|
+
const address1 = yield (0, account_helpers_1.getAccountByTag)(ctx1, enums_1.AccountType.ROOT);
|
|
44
|
+
const address2 = yield (0, account_helpers_1.getAccountByTag)(ctx2, enums_1.AccountType.ROOT);
|
|
45
|
+
(0, vitest_1.expect)(address1).not.toBe(address2);
|
|
46
|
+
}));
|
|
47
|
+
(0, vitest_1.it)('returns different addresses for different drvsAuthority', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
+
const ctx1 = createMockContext({
|
|
49
|
+
drvsAuthority: 'DRVStQsAKhF8gpz1xLzWyk2Q1HKKF3g21tknXtHpVLab',
|
|
50
|
+
});
|
|
51
|
+
const ctx2 = createMockContext({
|
|
52
|
+
drvsAuthority: '11111111111111111111111111111111',
|
|
53
|
+
});
|
|
54
|
+
const address1 = yield (0, account_helpers_1.getAccountByTag)(ctx1, enums_1.AccountType.ROOT);
|
|
55
|
+
const address2 = yield (0, account_helpers_1.getAccountByTag)(ctx2, enums_1.AccountType.ROOT);
|
|
56
|
+
(0, vitest_1.expect)(address1).not.toBe(address2);
|
|
57
|
+
}));
|
|
58
|
+
});
|
|
59
|
+
(0, vitest_1.describe)('getInstrAccountByTag', () => {
|
|
60
|
+
(0, vitest_1.it)('returns a valid address', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
+
const ctx = createMockContext();
|
|
62
|
+
const address = yield (0, account_helpers_1.getInstrAccountByTag)(ctx, {
|
|
63
|
+
tag: enums_1.AccountType.INSTR,
|
|
64
|
+
assetTokenId: 1,
|
|
65
|
+
crncyTokenId: 0,
|
|
66
|
+
});
|
|
67
|
+
(0, vitest_1.expect)(address).toBeDefined();
|
|
68
|
+
(0, vitest_1.expect)(typeof address).toBe('string');
|
|
69
|
+
(0, vitest_1.expect)(address.length).toBeGreaterThan(30);
|
|
70
|
+
}));
|
|
71
|
+
(0, vitest_1.it)('returns consistent addresses for same inputs', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
|
+
const ctx = createMockContext();
|
|
73
|
+
const args = { tag: enums_1.AccountType.INSTR, assetTokenId: 1, crncyTokenId: 0 };
|
|
74
|
+
const address1 = yield (0, account_helpers_1.getInstrAccountByTag)(ctx, args);
|
|
75
|
+
const address2 = yield (0, account_helpers_1.getInstrAccountByTag)(ctx, args);
|
|
76
|
+
(0, vitest_1.expect)(address1).toBe(address2);
|
|
77
|
+
}));
|
|
78
|
+
(0, vitest_1.it)('returns different addresses for different token pairs', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
+
const ctx = createMockContext();
|
|
80
|
+
const address1 = yield (0, account_helpers_1.getInstrAccountByTag)(ctx, {
|
|
81
|
+
tag: enums_1.AccountType.INSTR,
|
|
82
|
+
assetTokenId: 1,
|
|
83
|
+
crncyTokenId: 0,
|
|
84
|
+
});
|
|
85
|
+
const address2 = yield (0, account_helpers_1.getInstrAccountByTag)(ctx, {
|
|
86
|
+
tag: enums_1.AccountType.INSTR,
|
|
87
|
+
assetTokenId: 2,
|
|
88
|
+
crncyTokenId: 0,
|
|
89
|
+
});
|
|
90
|
+
(0, vitest_1.expect)(address1).not.toBe(address2);
|
|
91
|
+
}));
|
|
92
|
+
(0, vitest_1.it)('returns different addresses for different tags', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
93
|
+
const ctx = createMockContext();
|
|
94
|
+
const address1 = yield (0, account_helpers_1.getInstrAccountByTag)(ctx, {
|
|
95
|
+
tag: enums_1.AccountType.INSTR,
|
|
96
|
+
assetTokenId: 1,
|
|
97
|
+
crncyTokenId: 0,
|
|
98
|
+
});
|
|
99
|
+
const address2 = yield (0, account_helpers_1.getInstrAccountByTag)(ctx, {
|
|
100
|
+
tag: enums_1.AccountType.SPOT_BIDS_TREE,
|
|
101
|
+
assetTokenId: 1,
|
|
102
|
+
crncyTokenId: 0,
|
|
103
|
+
});
|
|
104
|
+
(0, vitest_1.expect)(address1).not.toBe(address2);
|
|
105
|
+
}));
|
|
106
|
+
});
|
|
107
|
+
(0, vitest_1.describe)('getTokenAccount', () => {
|
|
108
|
+
(0, vitest_1.it)('returns a valid address', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
109
|
+
const ctx = createMockContext();
|
|
110
|
+
const mint = 'So11111111111111111111111111111111111111112';
|
|
111
|
+
const address = yield (0, account_helpers_1.getTokenAccount)(ctx, mint);
|
|
112
|
+
(0, vitest_1.expect)(address).toBeDefined();
|
|
113
|
+
(0, vitest_1.expect)(typeof address).toBe('string');
|
|
114
|
+
(0, vitest_1.expect)(address.length).toBeGreaterThan(30);
|
|
115
|
+
}));
|
|
116
|
+
(0, vitest_1.it)('returns consistent addresses for same mint', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
+
const ctx = createMockContext();
|
|
118
|
+
const mint = 'So11111111111111111111111111111111111111112';
|
|
119
|
+
const address1 = yield (0, account_helpers_1.getTokenAccount)(ctx, mint);
|
|
120
|
+
const address2 = yield (0, account_helpers_1.getTokenAccount)(ctx, mint);
|
|
121
|
+
(0, vitest_1.expect)(address1).toBe(address2);
|
|
122
|
+
}));
|
|
123
|
+
(0, vitest_1.it)('returns different addresses for different mints', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
124
|
+
const ctx = createMockContext();
|
|
125
|
+
const mint1 = 'So11111111111111111111111111111111111111112';
|
|
126
|
+
const mint2 = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';
|
|
127
|
+
const address1 = yield (0, account_helpers_1.getTokenAccount)(ctx, mint1);
|
|
128
|
+
const address2 = yield (0, account_helpers_1.getTokenAccount)(ctx, mint2);
|
|
129
|
+
(0, vitest_1.expect)(address1).not.toBe(address2);
|
|
130
|
+
}));
|
|
131
|
+
});
|
|
132
|
+
(0, vitest_1.describe)('findClientPrimaryAccount', () => {
|
|
133
|
+
(0, vitest_1.it)('returns a valid address', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
134
|
+
const ctx = createMockContext();
|
|
135
|
+
const signer = 'DRVStQsAKhF8gpz1xLzWyk2Q1HKKF3g21tknXtHpVLab';
|
|
136
|
+
const address = yield (0, account_helpers_1.findClientPrimaryAccount)(ctx, signer);
|
|
137
|
+
(0, vitest_1.expect)(address).toBeDefined();
|
|
138
|
+
(0, vitest_1.expect)(typeof address).toBe('string');
|
|
139
|
+
(0, vitest_1.expect)(address.length).toBeGreaterThan(30);
|
|
140
|
+
}));
|
|
141
|
+
(0, vitest_1.it)('returns consistent addresses for same signer', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
142
|
+
const ctx = createMockContext();
|
|
143
|
+
const signer = 'DRVStQsAKhF8gpz1xLzWyk2Q1HKKF3g21tknXtHpVLab';
|
|
144
|
+
const address1 = yield (0, account_helpers_1.findClientPrimaryAccount)(ctx, signer);
|
|
145
|
+
const address2 = yield (0, account_helpers_1.findClientPrimaryAccount)(ctx, signer);
|
|
146
|
+
(0, vitest_1.expect)(address1).toBe(address2);
|
|
147
|
+
}));
|
|
148
|
+
(0, vitest_1.it)('returns different addresses for different signers', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
149
|
+
const ctx = createMockContext();
|
|
150
|
+
const signer1 = 'DRVStQsAKhF8gpz1xLzWyk2Q1HKKF3g21tknXtHpVLab';
|
|
151
|
+
const signer2 = '11111111111111111111111111111111';
|
|
152
|
+
const address1 = yield (0, account_helpers_1.findClientPrimaryAccount)(ctx, signer1);
|
|
153
|
+
const address2 = yield (0, account_helpers_1.findClientPrimaryAccount)(ctx, signer2);
|
|
154
|
+
(0, vitest_1.expect)(address1).not.toBe(address2);
|
|
155
|
+
}));
|
|
156
|
+
(0, vitest_1.it)('only requires programId and version from context', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
157
|
+
// findClientPrimaryAccount uses Pick<AccountHelperContext, 'programId' | 'version'>
|
|
158
|
+
const minimalCtx = {
|
|
159
|
+
programId: 'DRVSvY68xD69Zwwgj9N8hRBu2eXvEzy8eejiVLNYGLti',
|
|
160
|
+
version: 1,
|
|
161
|
+
};
|
|
162
|
+
const signer = 'DRVStQsAKhF8gpz1xLzWyk2Q1HKKF3g21tknXtHpVLab';
|
|
163
|
+
const address = yield (0, account_helpers_1.findClientPrimaryAccount)(minimalCtx, signer);
|
|
164
|
+
(0, vitest_1.expect)(address).toBeDefined();
|
|
165
|
+
}));
|
|
166
|
+
});
|
|
167
|
+
(0, vitest_1.describe)('findClientCommunityAccount', () => {
|
|
168
|
+
(0, vitest_1.it)('returns a valid address', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
169
|
+
const ctx = createMockContext();
|
|
170
|
+
const signer = 'DRVStQsAKhF8gpz1xLzWyk2Q1HKKF3g21tknXtHpVLab';
|
|
171
|
+
const address = yield (0, account_helpers_1.findClientCommunityAccount)(ctx, signer);
|
|
172
|
+
(0, vitest_1.expect)(address).toBeDefined();
|
|
173
|
+
(0, vitest_1.expect)(typeof address).toBe('string');
|
|
174
|
+
(0, vitest_1.expect)(address.length).toBeGreaterThan(30);
|
|
175
|
+
}));
|
|
176
|
+
(0, vitest_1.it)('returns consistent addresses for same signer', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
177
|
+
const ctx = createMockContext();
|
|
178
|
+
const signer = 'DRVStQsAKhF8gpz1xLzWyk2Q1HKKF3g21tknXtHpVLab';
|
|
179
|
+
const address1 = yield (0, account_helpers_1.findClientCommunityAccount)(ctx, signer);
|
|
180
|
+
const address2 = yield (0, account_helpers_1.findClientCommunityAccount)(ctx, signer);
|
|
181
|
+
(0, vitest_1.expect)(address1).toBe(address2);
|
|
182
|
+
}));
|
|
183
|
+
(0, vitest_1.it)('returns different addresses for different signers', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
184
|
+
const ctx = createMockContext();
|
|
185
|
+
const signer1 = 'DRVStQsAKhF8gpz1xLzWyk2Q1HKKF3g21tknXtHpVLab';
|
|
186
|
+
const signer2 = '11111111111111111111111111111111';
|
|
187
|
+
const address1 = yield (0, account_helpers_1.findClientCommunityAccount)(ctx, signer1);
|
|
188
|
+
const address2 = yield (0, account_helpers_1.findClientCommunityAccount)(ctx, signer2);
|
|
189
|
+
(0, vitest_1.expect)(address1).not.toBe(address2);
|
|
190
|
+
}));
|
|
191
|
+
(0, vitest_1.it)('returns different address than findClientPrimaryAccount for same signer', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
192
|
+
const ctx = createMockContext();
|
|
193
|
+
const signer = 'DRVStQsAKhF8gpz1xLzWyk2Q1HKKF3g21tknXtHpVLab';
|
|
194
|
+
const primaryAddress = yield (0, account_helpers_1.findClientPrimaryAccount)(ctx, signer);
|
|
195
|
+
const communityAddress = yield (0, account_helpers_1.findClientCommunityAccount)(ctx, signer);
|
|
196
|
+
(0, vitest_1.expect)(primaryAddress).not.toBe(communityAddress);
|
|
197
|
+
}));
|
|
198
|
+
});
|
|
199
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Address } from '@solana/kit';
|
|
2
|
+
import { Instrument, GetClientSpotOrdersInfoResponse, GetClientSpotOrdersArgs, GetClientSpotOrdersResponse, GetClientPerpOrdersInfoResponse, GetClientPerpOrdersArgs, GetClientPerpOrdersResponse, GetClientDataResponse, GetClientSpotOrdersInfoArgs, GetClientPerpOrdersInfoArgs } from '../types';
|
|
3
|
+
import { TokenStateModel } from '../structure_models';
|
|
4
|
+
import { AccountHelperContext } from './account-helpers';
|
|
5
|
+
/**
|
|
6
|
+
* Context needed for client query functions
|
|
7
|
+
*/
|
|
8
|
+
export interface ClientQueryContext extends AccountHelperContext {
|
|
9
|
+
instruments: Map<number, Instrument>;
|
|
10
|
+
tokens: Map<number, TokenStateModel>;
|
|
11
|
+
uiNumbers: boolean;
|
|
12
|
+
clientPrimaryAccount: Address | null;
|
|
13
|
+
clientCommunityAccount: Address | null;
|
|
14
|
+
originalClientId: number | null;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Unpack client accounts
|
|
18
|
+
*/
|
|
19
|
+
declare function getClientData(ctx: ClientQueryContext): Promise<GetClientDataResponse>;
|
|
20
|
+
/**
|
|
21
|
+
* Get general information about open orders in particular instrument (spot)
|
|
22
|
+
*/
|
|
23
|
+
declare function getClientSpotOrdersInfo(ctx: ClientQueryContext, args: GetClientSpotOrdersInfoArgs): Promise<GetClientSpotOrdersInfoResponse>;
|
|
24
|
+
/**
|
|
25
|
+
* Get general information about open orders in particular instrument (perp)
|
|
26
|
+
*/
|
|
27
|
+
declare function getClientPerpOrdersInfo(ctx: ClientQueryContext, args: GetClientPerpOrdersInfoArgs): Promise<GetClientPerpOrdersInfoResponse>;
|
|
28
|
+
/**
|
|
29
|
+
* Get list of open orders (spot) in particular instrument
|
|
30
|
+
*/
|
|
31
|
+
declare function getClientSpotOrders(ctx: ClientQueryContext, args: GetClientSpotOrdersArgs): Promise<GetClientSpotOrdersResponse>;
|
|
32
|
+
/**
|
|
33
|
+
* Get list of open orders (perp) in particular instrument
|
|
34
|
+
*/
|
|
35
|
+
declare function getClientPerpOrders(ctx: ClientQueryContext, args: GetClientPerpOrdersArgs): Promise<GetClientPerpOrdersResponse>;
|
|
36
|
+
export { getClientData, getClientSpotOrdersInfo, getClientPerpOrdersInfo, getClientSpotOrders, getClientPerpOrders };
|