@n1xyz/nord-ts 0.0.17 → 0.0.18-8121ed05.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/dist/gen/nord.js +1 -1
- package/dist/nord/client/NordUser.js +2 -1
- package/dist/utils.d.ts +0 -9
- package/dist/utils.js +0 -19
- package/package.json +5 -6
- package/src/nord/client/NordUser.ts +2 -3
- package/src/utils.ts +0 -21
package/dist/gen/nord.js
CHANGED
|
@@ -39,6 +39,7 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
39
39
|
const ed = __importStar(require("@noble/ed25519"));
|
|
40
40
|
const sha512_1 = require("@noble/hashes/sha512");
|
|
41
41
|
ed.etc.sha512Sync = sha512_1.sha512;
|
|
42
|
+
const proton_1 = require("@n1xyz/proton");
|
|
42
43
|
const utils_1 = require("../../utils");
|
|
43
44
|
const actions_1 = require("../api/actions");
|
|
44
45
|
const NordError_1 = require("../utils/NordError");
|
|
@@ -244,7 +245,7 @@ class NordUser {
|
|
|
244
245
|
// Get the user's token account
|
|
245
246
|
const fromAccount = await this.getAssociatedTokenAccount(mint);
|
|
246
247
|
// Convert amount to BN with proper decimals
|
|
247
|
-
const amountBN = (0,
|
|
248
|
+
const amountBN = (0, proton_1.floatToBn)(amount, tokenInfo.precision);
|
|
248
249
|
// Create deposit parameters
|
|
249
250
|
const depositParams = {
|
|
250
251
|
amount: amountBN,
|
package/dist/utils.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { KeyType, type Market, type Token } from "./types";
|
|
|
3
3
|
import * as proto from "./gen/nord";
|
|
4
4
|
import { ethers } from "ethers";
|
|
5
5
|
import { RequestInfo, RequestInit, Response } from "node-fetch";
|
|
6
|
-
import { BN } from "@coral-xyz/anchor";
|
|
7
6
|
import { Keypair } from "@solana/web3.js";
|
|
8
7
|
export declare const SESSION_TTL: bigint;
|
|
9
8
|
export declare const ZERO_DECIMAL: Decimal;
|
|
@@ -114,12 +113,4 @@ export declare function decodeLengthDelimited<T, M extends proto.MessageFns<T>>(
|
|
|
114
113
|
export declare function checkPubKeyLength(keyType: KeyType, len: number): void;
|
|
115
114
|
export declare function findMarket(markets: Market[], marketId: number): Market;
|
|
116
115
|
export declare function findToken(tokens: Token[], tokenId: number): Token;
|
|
117
|
-
/**
|
|
118
|
-
* Convert a number to a BN with the specified number of decimals
|
|
119
|
-
*
|
|
120
|
-
* @param amount Amount as a number
|
|
121
|
-
* @param decimals Number of decimal places
|
|
122
|
-
* @returns Amount as a BN
|
|
123
|
-
*/
|
|
124
|
-
export declare function toBN(amount: number, decimals: number): BN;
|
|
125
116
|
export declare function keypairFromPrivateKey(privateKey: string | Uint8Array): Keypair;
|
package/dist/utils.js
CHANGED
|
@@ -18,7 +18,6 @@ exports.decodeLengthDelimited = decodeLengthDelimited;
|
|
|
18
18
|
exports.checkPubKeyLength = checkPubKeyLength;
|
|
19
19
|
exports.findMarket = findMarket;
|
|
20
20
|
exports.findToken = findToken;
|
|
21
|
-
exports.toBN = toBN;
|
|
22
21
|
exports.keypairFromPrivateKey = keypairFromPrivateKey;
|
|
23
22
|
const decimal_js_1 = require("decimal.js");
|
|
24
23
|
const ed25519_1 = require("@noble/curves/ed25519");
|
|
@@ -29,7 +28,6 @@ const types_1 = require("./types");
|
|
|
29
28
|
const wire_1 = require("@bufbuild/protobuf/wire");
|
|
30
29
|
const ethers_1 = require("ethers");
|
|
31
30
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
32
|
-
const anchor_1 = require("@coral-xyz/anchor");
|
|
33
31
|
const web3_js_1 = require("@solana/web3.js");
|
|
34
32
|
const bs58_1 = __importDefault(require("bs58"));
|
|
35
33
|
exports.SESSION_TTL = 60n * 60n * 24n * 30n;
|
|
@@ -260,23 +258,6 @@ function findToken(tokens, tokenId) {
|
|
|
260
258
|
}
|
|
261
259
|
return tokens[tokenId];
|
|
262
260
|
}
|
|
263
|
-
/**
|
|
264
|
-
* Convert a number to a BN with the specified number of decimals
|
|
265
|
-
*
|
|
266
|
-
* @param amount Amount as a number
|
|
267
|
-
* @param decimals Number of decimal places
|
|
268
|
-
* @returns Amount as a BN
|
|
269
|
-
*/
|
|
270
|
-
function toBN(amount, decimals) {
|
|
271
|
-
const amountString = amount.toFixed(decimals);
|
|
272
|
-
const [whole, fraction] = amountString.split(".");
|
|
273
|
-
// Convert to smallest units (no decimals)
|
|
274
|
-
const wholeBN = new anchor_1.BN(whole).mul(new anchor_1.BN(10).pow(new anchor_1.BN(decimals)));
|
|
275
|
-
const fractionBN = fraction
|
|
276
|
-
? new anchor_1.BN(fraction.padEnd(decimals, "0").slice(0, decimals))
|
|
277
|
-
: new anchor_1.BN(0);
|
|
278
|
-
return wholeBN.add(fractionBN);
|
|
279
|
-
}
|
|
280
261
|
function keypairFromPrivateKey(privateKey) {
|
|
281
262
|
if (typeof privateKey === "string") {
|
|
282
263
|
if (!privateKey.startsWith("0x")) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n1xyz/nord-ts",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18-8121ed05.0",
|
|
4
4
|
"description": "Typescript for Nord",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@jest/types": "^29.6.3",
|
|
17
17
|
"@types/google-protobuf": "^3.15.10",
|
|
18
18
|
"@types/jest": "^29.5.12",
|
|
19
|
-
"@types/node": "^
|
|
19
|
+
"@types/node": "^22.15.29",
|
|
20
20
|
"@types/node-fetch": "^2.6.9",
|
|
21
21
|
"@types/ws": "^8.5.10",
|
|
22
22
|
"@typescript-eslint/eslint-plugin": "^8.26.1",
|
|
@@ -33,19 +33,18 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@bufbuild/protobuf": "^2.0.0",
|
|
36
|
-
"@coral-xyz/anchor": "0.30.1",
|
|
37
36
|
"@noble/curves": "^1.3.0",
|
|
38
37
|
"@noble/ed25519": "^2.2.3",
|
|
39
38
|
"@noble/hashes": "^1.3.2",
|
|
40
|
-
"@solana/spl-token": "^0.4.
|
|
41
|
-
"@solana/web3.js": "1.
|
|
39
|
+
"@solana/spl-token": "^0.4.13",
|
|
40
|
+
"@solana/web3.js": "^1.98.2",
|
|
42
41
|
"bs58": "^6.0.0",
|
|
43
42
|
"decimal.js": "^10.4.3",
|
|
44
43
|
"ethers": "^6.11.1",
|
|
45
44
|
"node-fetch": "2.6.13",
|
|
46
45
|
"tweetnacl": "^1.0.3",
|
|
47
46
|
"ws": "^8.16.0",
|
|
48
|
-
"@n1xyz/proton": "0.0.0"
|
|
47
|
+
"@n1xyz/proton": "0.0.1-8121ed05.0"
|
|
49
48
|
},
|
|
50
49
|
"scripts": {
|
|
51
50
|
"dev": "nodemon --exec npx tsc",
|
|
@@ -9,7 +9,7 @@ import Decimal from "decimal.js";
|
|
|
9
9
|
import * as ed from "@noble/ed25519";
|
|
10
10
|
import { sha512 } from "@noble/hashes/sha512";
|
|
11
11
|
ed.etc.sha512Sync = sha512;
|
|
12
|
-
import { SPLTokenInfo, DepositSplParams } from "@n1xyz/proton";
|
|
12
|
+
import { SPLTokenInfo, DepositSplParams, floatToBn } from "@n1xyz/proton";
|
|
13
13
|
import { FillMode, Order, Side } from "../../types";
|
|
14
14
|
import {
|
|
15
15
|
BigIntValue,
|
|
@@ -17,7 +17,6 @@ import {
|
|
|
17
17
|
findMarket,
|
|
18
18
|
findToken,
|
|
19
19
|
optExpect,
|
|
20
|
-
toBN as utilsToBN,
|
|
21
20
|
keypairFromPrivateKey,
|
|
22
21
|
} from "../../utils";
|
|
23
22
|
import {
|
|
@@ -433,7 +432,7 @@ export class NordUser {
|
|
|
433
432
|
const fromAccount = await this.getAssociatedTokenAccount(mint);
|
|
434
433
|
|
|
435
434
|
// Convert amount to BN with proper decimals
|
|
436
|
-
const amountBN =
|
|
435
|
+
const amountBN = floatToBn(amount, tokenInfo.precision);
|
|
437
436
|
|
|
438
437
|
// Create deposit parameters
|
|
439
438
|
const depositParams: DepositSplParams = {
|
package/src/utils.ts
CHANGED
|
@@ -9,7 +9,6 @@ import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
|
|
|
9
9
|
import { ethers } from "ethers";
|
|
10
10
|
import fetch from "node-fetch";
|
|
11
11
|
import { RequestInfo, RequestInit, Response } from "node-fetch";
|
|
12
|
-
import { BN } from "@coral-xyz/anchor";
|
|
13
12
|
import { Keypair } from "@solana/web3.js";
|
|
14
13
|
import bs58 from "bs58";
|
|
15
14
|
|
|
@@ -302,26 +301,6 @@ export function findToken(tokens: Token[], tokenId: number): Token {
|
|
|
302
301
|
return tokens[tokenId];
|
|
303
302
|
}
|
|
304
303
|
|
|
305
|
-
/**
|
|
306
|
-
* Convert a number to a BN with the specified number of decimals
|
|
307
|
-
*
|
|
308
|
-
* @param amount Amount as a number
|
|
309
|
-
* @param decimals Number of decimal places
|
|
310
|
-
* @returns Amount as a BN
|
|
311
|
-
*/
|
|
312
|
-
export function toBN(amount: number, decimals: number): BN {
|
|
313
|
-
const amountString = amount.toFixed(decimals);
|
|
314
|
-
const [whole, fraction] = amountString.split(".");
|
|
315
|
-
|
|
316
|
-
// Convert to smallest units (no decimals)
|
|
317
|
-
const wholeBN = new BN(whole).mul(new BN(10).pow(new BN(decimals)));
|
|
318
|
-
const fractionBN = fraction
|
|
319
|
-
? new BN(fraction.padEnd(decimals, "0").slice(0, decimals))
|
|
320
|
-
: new BN(0);
|
|
321
|
-
|
|
322
|
-
return wholeBN.add(fractionBN);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
304
|
export function keypairFromPrivateKey(
|
|
326
305
|
privateKey: string | Uint8Array,
|
|
327
306
|
): Keypair {
|