@n1xyz/nord-ts 0.0.1
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/.eslintignore +1 -0
- package/.eslintrc.js +20 -0
- package/.prettierignore +1 -0
- package/README.md +110 -0
- package/dist/abis/ERC20_ABI.d.ts +39 -0
- package/dist/abis/ERC20_ABI.js +313 -0
- package/dist/abis/NORD_GETTERS_FACET_ABI.d.ts +34 -0
- package/dist/abis/NORD_GETTERS_FACET_ABI.js +195 -0
- package/dist/abis/NORD_RAMP_FACET_ABI.d.ts +35 -0
- package/dist/abis/NORD_RAMP_FACET_ABI.js +144 -0
- package/dist/abis/index.d.ts +3 -0
- package/dist/abis/index.js +9 -0
- package/dist/const.d.ts +11 -0
- package/dist/const.js +34 -0
- package/dist/gen/common.d.ts +63 -0
- package/dist/gen/common.js +205 -0
- package/dist/gen/nord.d.ts +705 -0
- package/dist/gen/nord.js +4784 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +21 -0
- package/dist/nord/Nord.d.ts +76 -0
- package/dist/nord/Nord.js +376 -0
- package/dist/nord/NordImpl.d.ts +7 -0
- package/dist/nord/NordImpl.js +6 -0
- package/dist/nord/NordUser.d.ts +77 -0
- package/dist/nord/NordUser.js +249 -0
- package/dist/nord/actions.d.ts +101 -0
- package/dist/nord/actions.js +254 -0
- package/dist/nord/index.d.ts +2 -0
- package/dist/nord/index.js +9 -0
- package/dist/types.d.ts +343 -0
- package/dist/types.js +92 -0
- package/dist/utils.d.ts +114 -0
- package/dist/utils.js +257 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +92 -0
- package/docs/assets/icons.js +15 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +59 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1415 -0
- package/docs/classes/Nord.html +44 -0
- package/docs/classes/NordUser.html +35 -0
- package/docs/classes/Subscriber.html +6 -0
- package/docs/enums/FillMode.html +5 -0
- package/docs/enums/KeyType.html +4 -0
- package/docs/enums/PeakTpsPeriodUnit.html +15 -0
- package/docs/enums/Side.html +3 -0
- package/docs/functions/assert.html +1 -0
- package/docs/functions/bigIntToProtoU128.html +4 -0
- package/docs/functions/checkPubKeyLength.html +1 -0
- package/docs/functions/checkedFetch.html +6 -0
- package/docs/functions/createWebSocketSubscription.html +12 -0
- package/docs/functions/decodeLengthDelimited.html +10 -0
- package/docs/functions/encodeLengthDelimited.html +6 -0
- package/docs/functions/fillModeToProtoFillMode.html +5 -0
- package/docs/functions/findMarket.html +1 -0
- package/docs/functions/findToken.html +1 -0
- package/docs/functions/makeWalletSignFn.html +6 -0
- package/docs/functions/optExpect.html +5 -0
- package/docs/functions/optMap.html +5 -0
- package/docs/functions/optUnwrap.html +2 -0
- package/docs/functions/panic.html +1 -0
- package/docs/functions/signAction.html +6 -0
- package/docs/functions/toScaledU128.html +8 -0
- package/docs/functions/toScaledU64.html +8 -0
- package/docs/index.html +21 -0
- package/docs/interfaces/Account.html +8 -0
- package/docs/interfaces/ActionInfo.html +8 -0
- package/docs/interfaces/ActionQuery.html +4 -0
- package/docs/interfaces/ActionResponse.html +8 -0
- package/docs/interfaces/ActionsExtendedInfo.html +10 -0
- package/docs/interfaces/ActionsQuery.html +5 -0
- package/docs/interfaces/ActionsResponse.html +6 -0
- package/docs/interfaces/AggregateMetrics.html +12 -0
- package/docs/interfaces/BlockQuery.html +6 -0
- package/docs/interfaces/BlockResponse.html +6 -0
- package/docs/interfaces/BlockSummary.html +8 -0
- package/docs/interfaces/BlockSummaryResponse.html +6 -0
- package/docs/interfaces/DeltaEvent.html +6 -0
- package/docs/interfaces/ERC20TokenInfo.html +5 -0
- package/docs/interfaces/Info.html +3 -0
- package/docs/interfaces/Market.html +6 -0
- package/docs/interfaces/MarketStats.html +7 -0
- package/docs/interfaces/MarketsStatsResponse.html +2 -0
- package/docs/interfaces/NordConfig.html +5 -0
- package/docs/interfaces/Order.html +6 -0
- package/docs/interfaces/OrderInfo.html +6 -0
- package/docs/interfaces/OrderbookOrder.html +6 -0
- package/docs/interfaces/OrderbookResponse.html +10 -0
- package/docs/interfaces/PerpMarketStats.html +5 -0
- package/docs/interfaces/RollmanActionExtendedInfo.html +4 -0
- package/docs/interfaces/RollmanActionInfo.html +4 -0
- package/docs/interfaces/RollmanActionResponse.html +4 -0
- package/docs/interfaces/RollmanActionsResponse.html +2 -0
- package/docs/interfaces/RollmanBlockResponse.html +3 -0
- package/docs/interfaces/SubscriberConfig.html +3 -0
- package/docs/interfaces/Token.html +5 -0
- package/docs/interfaces/Trade.html +5 -0
- package/docs/interfaces/TradeInfo.html +20 -0
- package/docs/interfaces/Trades.html +5 -0
- package/docs/interfaces/TradesQueryParams.html +10 -0
- package/docs/interfaces/TradesResponse.html +12 -0
- package/docs/modules.html +77 -0
- package/docs/types/BigIntValue.html +2 -0
- package/docs/variables/DEBUG_KEYS.html +1 -0
- package/docs/variables/DEFAULT_FUNDING_AMOUNTS.html +1 -0
- package/docs/variables/DEV_CONTRACT_ADDRESS.html +1 -0
- package/docs/variables/DEV_TOKEN_INFOS.html +1 -0
- package/docs/variables/DEV_URL.html +1 -0
- package/docs/variables/ERC20_ABI.html +1 -0
- package/docs/variables/EVM_DEV_URL.html +1 -0
- package/docs/variables/FAUCET_PRIVATE_ADDRESS.html +1 -0
- package/docs/variables/MAX_BUFFER_LEN.html +1 -0
- package/docs/variables/NORD_GETTERS_FACET_ABI.html +1 -0
- package/docs/variables/NORD_RAMP_FACET_ABI.html +1 -0
- package/docs/variables/SESSION_TTL.html +1 -0
- package/docs/variables/WEBSERVER_DEV_URL.html +1 -0
- package/docs/variables/ZERO_DECIMAL.html +1 -0
- package/jest.config.ts +9 -0
- package/nodemon.json +4 -0
- package/package.json +61 -0
- package/protoc-generate.sh +23 -0
- package/src/abis/ERC20_ABI.ts +310 -0
- package/src/abis/NORD_GETTERS_FACET_ABI.ts +192 -0
- package/src/abis/NORD_RAMP_FACET_ABI.ts +141 -0
- package/src/abis/index.ts +3 -0
- package/src/const.ts +39 -0
- package/src/gen/common.ts +280 -0
- package/src/gen/nord.ts +5666 -0
- package/src/index.ts +5 -0
- package/src/nord/Nord.ts +504 -0
- package/src/nord/NordImpl.ts +8 -0
- package/src/nord/NordUser.ts +469 -0
- package/src/nord/actions.ts +484 -0
- package/src/nord/index.ts +2 -0
- package/src/types.ts +393 -0
- package/src/utils.ts +300 -0
- package/tests/utils.spec.ts +154 -0
- package/tsconfig.json +24 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { describe, it, expect } from "@jest/globals";
|
|
2
|
+
import {
|
|
3
|
+
bigIntToProtoU128,
|
|
4
|
+
toScaledU64,
|
|
5
|
+
toScaledU128,
|
|
6
|
+
encodeLengthDelimited,
|
|
7
|
+
decodeLengthDelimited,
|
|
8
|
+
} from "../src/utils";
|
|
9
|
+
import Decimal from "decimal.js";
|
|
10
|
+
import * as proto from "../src/gen/nord";
|
|
11
|
+
|
|
12
|
+
describe("toScaledU64", () => {
|
|
13
|
+
// Used as scaling medium
|
|
14
|
+
const D64 = Decimal.clone({
|
|
15
|
+
precision: 20,
|
|
16
|
+
toExpPos: 20,
|
|
17
|
+
toExpNeg: -20,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const MaxDec = new D64(2).pow(64).sub(1);
|
|
21
|
+
const MaxUint = BigInt(MaxDec.toString());
|
|
22
|
+
|
|
23
|
+
const success: Array<[Decimal.Value, number, bigint]> = [
|
|
24
|
+
[0, 0, 0n],
|
|
25
|
+
[1, 0, 1n],
|
|
26
|
+
[123.45, 3, 123450n],
|
|
27
|
+
[MaxDec, 0, MaxUint],
|
|
28
|
+
[MaxDec.div(1000), 3, MaxUint],
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
success.forEach((sample) => {
|
|
32
|
+
it(`Convert decimal ${sample[0]}*10^${sample[1]} to bignum ${sample[2]} should succeed`, () => {
|
|
33
|
+
expect(toScaledU64(sample[0], sample[1])).toEqual(sample[2]);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const failure: Array<[Decimal.Value, number, string]> = [
|
|
38
|
+
[-1, 0, "Number is negative"],
|
|
39
|
+
[-1000, 2, "Number is negative"],
|
|
40
|
+
[0.1, 0, "Precision loss"],
|
|
41
|
+
[0.0001, 3, "Precision loss"],
|
|
42
|
+
[MaxDec.add(1), 0, "Integer is out of range"],
|
|
43
|
+
[MaxDec.add(1).div(1000), 3, "Integer is out of range"],
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
failure.forEach((sample) => {
|
|
47
|
+
it(`Convert decimal ${sample[0]}/10^${sample[1]} to bignum should fail with ${sample[2]} `, () => {
|
|
48
|
+
expect(() => toScaledU64(sample[0], sample[1])).toThrow(sample[2]);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe("toScaledU128", () => {
|
|
54
|
+
// Used as scaling medium
|
|
55
|
+
const D128 = Decimal.clone({
|
|
56
|
+
precision: 40,
|
|
57
|
+
toExpPos: 40,
|
|
58
|
+
toExpNeg: -40,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const MaxDec = new D128(2).pow(128).sub(1);
|
|
62
|
+
const MaxUint = BigInt(MaxDec.toString());
|
|
63
|
+
|
|
64
|
+
const success: Array<[Decimal.Value, number, bigint]> = [
|
|
65
|
+
[0, 0, 0n],
|
|
66
|
+
[1, 0, 1n],
|
|
67
|
+
[123.45, 3, 123450n],
|
|
68
|
+
[MaxDec, 0, MaxUint],
|
|
69
|
+
[MaxDec.div(1000), 3, MaxUint],
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
success.forEach((sample) => {
|
|
73
|
+
it(`Convert decimal ${sample[0]}*10^${sample[1]} to bignum ${sample[2]} should succeed`, () => {
|
|
74
|
+
expect(toScaledU128(sample[0], sample[1])).toEqual(sample[2]);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const failure: Array<[Decimal.Value, number, string]> = [
|
|
79
|
+
[-1, 0, "Number is negative"],
|
|
80
|
+
[-1000, 2, "Number is negative"],
|
|
81
|
+
[0.1, 0, "Precision loss"],
|
|
82
|
+
[0.0001, 3, "Precision loss"],
|
|
83
|
+
[MaxDec.add(1), 0, "Integer is out of range"],
|
|
84
|
+
[MaxDec.add(1).div(1000), 3, "Integer is out of range"],
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
failure.forEach((sample) => {
|
|
88
|
+
it(`Convert decimal ${sample[0]}/10^${sample[1]} to bignum should fail with ${sample[2]} `, () => {
|
|
89
|
+
expect(() => toScaledU128(sample[0], sample[1])).toThrow(sample[2]);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const U64_MAX = (1n << 64n) - 1n;
|
|
95
|
+
const U128_MAX = (1n << 128n) - 1n;
|
|
96
|
+
|
|
97
|
+
describe("bigIntToProtoU128", () => {
|
|
98
|
+
const success: Array<[bigint, { lo: bigint; hi: bigint }]> = [
|
|
99
|
+
[0n, { lo: 0n, hi: 0n }],
|
|
100
|
+
[1n, { lo: 1n, hi: 0n }],
|
|
101
|
+
[U64_MAX - 1n, { lo: U64_MAX - 1n, hi: 0n }],
|
|
102
|
+
[U64_MAX, { lo: U64_MAX, hi: 0n }],
|
|
103
|
+
[U64_MAX + 1n, { lo: 0n, hi: 1n }],
|
|
104
|
+
[U128_MAX - 1n, { lo: U64_MAX - 1n, hi: U64_MAX }],
|
|
105
|
+
[U128_MAX, { lo: U64_MAX, hi: U64_MAX }],
|
|
106
|
+
];
|
|
107
|
+
|
|
108
|
+
success.forEach((sample, index) => {
|
|
109
|
+
it(`Conversion to Protobuf's U128 should succeed: case ${index}`, () => {
|
|
110
|
+
expect(bigIntToProtoU128(sample[0])).toEqual(sample[1]);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const failure: Array<[bigint, string]> = [
|
|
115
|
+
[-1n, "Negative number"],
|
|
116
|
+
[U128_MAX + 1n, "U128 overflow"],
|
|
117
|
+
];
|
|
118
|
+
|
|
119
|
+
failure.forEach((sample, index) => {
|
|
120
|
+
it(`Conversion to Protobuf's U128 should fail: case ${index}`, () => {
|
|
121
|
+
expect(() => bigIntToProtoU128(sample[0])).toThrow(sample[1]);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe("proto.Action encode-decode loop", () => {
|
|
127
|
+
const action: proto.Action = {
|
|
128
|
+
currentTimestamp: 0n,
|
|
129
|
+
nonce: 0,
|
|
130
|
+
kind: {
|
|
131
|
+
$case: "placeOrder",
|
|
132
|
+
value: {
|
|
133
|
+
sessionId: 42n,
|
|
134
|
+
marketId: 9,
|
|
135
|
+
fillMode: proto.FillMode.LIMIT,
|
|
136
|
+
side: proto.Side.ASK,
|
|
137
|
+
isReduceOnly: false,
|
|
138
|
+
price: 12n,
|
|
139
|
+
size: 39n,
|
|
140
|
+
quoteSize: { lo: 54n, hi: 55n },
|
|
141
|
+
senderAccountId: undefined,
|
|
142
|
+
delegatorAccountId: undefined,
|
|
143
|
+
clientOrderId: 350n,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
it("action encode-decode roundabout should succeed", () => {
|
|
149
|
+
const encoded = encodeLengthDelimited(action, proto.Action);
|
|
150
|
+
const decoded: proto.Action = decodeLengthDelimited(encoded, proto.Action);
|
|
151
|
+
|
|
152
|
+
expect(decoded).toEqual(action);
|
|
153
|
+
});
|
|
154
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"declaration": true,
|
|
4
|
+
"target": "es2020",
|
|
5
|
+
"lib": ["es2020"],
|
|
6
|
+
"module": "commonjs",
|
|
7
|
+
"rootDir": "./src",
|
|
8
|
+
"moduleResolution": "Node",
|
|
9
|
+
"outDir": "./dist",
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"resolveJsonModule": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
},
|
|
16
|
+
"typeAcquisition": {
|
|
17
|
+
"include": [
|
|
18
|
+
"jest",
|
|
19
|
+
"@types/jest"
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
"exclude": ["dist", "**/node_modules/**/*"],
|
|
23
|
+
"include": ["./src/**/*"]
|
|
24
|
+
}
|