@gainsnetwork/sdk 0.2.69 → 0.2.70-rc1
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/constants.d.ts +13 -0
- package/lib/constants.js +16 -2
- package/lib/contracts/utils/pairs.js +13 -0
- package/lib/trade/types.d.ts +14 -1
- package/lib/trade/types.js +13 -0
- package/package.json +1 -1
- package/lib/contracts/fetch/fees/borrowingFeesV2.d.ts +0 -76
- package/lib/contracts/fetch/fees/borrowingFeesV2.js +0 -193
- package/lib/contracts/fetch/fees/fundingFees.d.ts +0 -66
- package/lib/contracts/fetch/fees/fundingFees.js +0 -150
- package/lib/contracts/fetch/priceImpact/skew.d.ts +0 -63
- package/lib/contracts/fetch/priceImpact/skew.js +0 -168
- package/lib/trade/fees/borrowingV2/converter.d.ts +0 -66
- package/lib/trade/fees/borrowingV2/converter.js +0 -121
- package/lib/trade/fees/borrowingV2/index.d.ts +0 -59
- package/lib/trade/fees/borrowingV2/index.js +0 -139
- package/lib/trade/fees/borrowingV2/types.d.ts +0 -79
- package/lib/trade/fees/borrowingV2/types.js +0 -5
- package/lib/trade/fees/fundingFees/converter.d.ts +0 -102
- package/lib/trade/fees/fundingFees/converter.js +0 -196
- package/lib/trade/fees/fundingFees/index.d.ts +0 -135
- package/lib/trade/fees/fundingFees/index.js +0 -322
- package/lib/trade/fees/fundingFees/types.d.ts +0 -77
- package/lib/trade/fees/fundingFees/types.js +0 -5
- package/lib/trade/fees/trading/converter.d.ts +0 -30
- package/lib/trade/fees/trading/converter.js +0 -43
- package/lib/trade/fees/trading/index.d.ts +0 -34
- package/lib/trade/fees/trading/index.js +0 -104
- package/lib/trade/fees/trading/types.d.ts +0 -39
- package/lib/trade/fees/trading/types.js +0 -5
- package/lib/trade/priceImpact/index.d.ts +0 -8
- package/lib/trade/priceImpact/index.js +0 -32
- package/lib/trade/priceImpact/skew/converter.d.ts +0 -77
- package/lib/trade/priceImpact/skew/converter.js +0 -171
- package/lib/trade/priceImpact/skew/index.d.ts +0 -57
- package/lib/trade/priceImpact/skew/index.js +0 -175
- package/lib/trade/priceImpact/skew/types.d.ts +0 -55
- package/lib/trade/priceImpact/skew/types.js +0 -5
- package/lib/trade/utils.d.ts +0 -18
- package/lib/trade/utils.js +0 -30
package/lib/constants.d.ts
CHANGED
|
@@ -386,6 +386,19 @@ export declare const pairs: {
|
|
|
386
386
|
"BVIV/USD": string;
|
|
387
387
|
"EVIV/USD": string;
|
|
388
388
|
"CRCL/USD": string;
|
|
389
|
+
"RESOLV/USD": string;
|
|
390
|
+
"SQD/USD": string;
|
|
391
|
+
"TAIKO/USD": string;
|
|
392
|
+
"HOME/USD": string;
|
|
393
|
+
"B/USD": string;
|
|
394
|
+
"HUMA/USD": string;
|
|
395
|
+
"SBET/USD": string;
|
|
396
|
+
"MTPLF/USD": string;
|
|
397
|
+
"PLTR/USD": string;
|
|
398
|
+
"BIDU/USD": string;
|
|
399
|
+
"ROKU/USD": string;
|
|
400
|
+
"EXOD/USD": string;
|
|
401
|
+
"CHYME/USD": string;
|
|
389
402
|
};
|
|
390
403
|
export declare const syntheticPairs: Set<string>;
|
|
391
404
|
export declare const parentToSyntheticPairMap: Map<string, string>;
|
package/lib/constants.js
CHANGED
|
@@ -394,6 +394,19 @@ exports.pairs = {
|
|
|
394
394
|
"BVIV/USD": CRYPTO,
|
|
395
395
|
"EVIV/USD": CRYPTO,
|
|
396
396
|
"CRCL/USD": STOCKS,
|
|
397
|
+
"RESOLV/USD": CRYPTO,
|
|
398
|
+
"SQD/USD": CRYPTO,
|
|
399
|
+
"TAIKO/USD": CRYPTO,
|
|
400
|
+
"HOME/USD": CRYPTO,
|
|
401
|
+
"B/USD": CRYPTO,
|
|
402
|
+
"HUMA/USD": CRYPTO,
|
|
403
|
+
"SBET/USD": STOCKS,
|
|
404
|
+
"MTPLF/USD": STOCKS,
|
|
405
|
+
"PLTR/USD": STOCKS,
|
|
406
|
+
"BIDU/USD": STOCKS,
|
|
407
|
+
"ROKU/USD": STOCKS,
|
|
408
|
+
"EXOD/USD": STOCKS,
|
|
409
|
+
"CHYME/USD": STOCKS,
|
|
397
410
|
};
|
|
398
411
|
exports.syntheticPairs = new Set([
|
|
399
412
|
"BTCDEGEN/USD",
|
|
@@ -442,11 +455,12 @@ exports.stockSplits = {
|
|
|
442
455
|
};
|
|
443
456
|
exports.delistedPairIxs = new Set([
|
|
444
457
|
4, 6, 15, 24, 25, 27, 28, 30, 31, 36, 48, 51, 52, 53, 54, 56, 59, 60, 61, 63,
|
|
445
|
-
66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 95, 96, 97, 98,
|
|
446
|
-
|
|
458
|
+
66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 95, 96, 97, 98, 99,
|
|
459
|
+
101, 106, 111, 113, 114, 116, 118, 120, 122, 123, 125, 127, 130, 147, 152,
|
|
447
460
|
160, 163, 170, 179, 182, 183, 187, 188, 189, 190, 208, 209, 225, 229, 230,
|
|
448
461
|
231, 238, 239, 241, 250, 253, 254, 258, 270, 275, 276, 278, 279, 282, 285,
|
|
449
462
|
290, 294, 296, 305, 330, 349, 352, 353, 354, 355, 357, 365, 366, 384, 385,
|
|
463
|
+
387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399,
|
|
450
464
|
]);
|
|
451
465
|
exports.delistedGroupsIxs = new Set([]);
|
|
452
466
|
exports.DEFAULT_PROTECTION_CLOSE_FACTOR = 1;
|
|
@@ -492,4 +492,17 @@ const PAIR_INDEX_TO_DESCRIPTION = {
|
|
|
492
492
|
[types_1.PairIndex.BVIVUSD]: "Bitcoin Volmex Implied Volatility 30 Day Index to US Dollar",
|
|
493
493
|
[types_1.PairIndex.EVIVUSD]: "Ethereum Volmex Implied Volatility 30 Day Index to US Dollar",
|
|
494
494
|
[types_1.PairIndex.CRCLUSD]: "Circle Internet Group to US Dollar",
|
|
495
|
+
[types_1.PairIndex.RESOLVUSD]: "Resolv to US Dollar",
|
|
496
|
+
[types_1.PairIndex.SQDUSD]: "Subsquid to US Dollar",
|
|
497
|
+
[types_1.PairIndex.TAIKOUSD]: "Taiko to US Dollar",
|
|
498
|
+
[types_1.PairIndex.HOMEUSD]: "Defi App to US Dollar",
|
|
499
|
+
[types_1.PairIndex.BUSD]: "BUILDon to US Dollar",
|
|
500
|
+
[types_1.PairIndex.HUMAUSD]: "Huma Finance to US Dollar",
|
|
501
|
+
[types_1.PairIndex.SBETUSD]: "Sharplink Gaming Inc to US Dollar",
|
|
502
|
+
[types_1.PairIndex.MTPLFUSD]: "Metaplanet to US Dollar",
|
|
503
|
+
[types_1.PairIndex.PLTRUSD]: "Palantir Technologies to US Dollar",
|
|
504
|
+
[types_1.PairIndex.BIDUUSD]: "Baidu to US Dollar",
|
|
505
|
+
[types_1.PairIndex.ROKUUSD]: "Roku to US Dollar",
|
|
506
|
+
[types_1.PairIndex.EXODUSD]: "Exodus Movement Inc to US Dollar",
|
|
507
|
+
[types_1.PairIndex.CHYMEUSD]: "Chime Financial Inc to US Dollar",
|
|
495
508
|
};
|
package/lib/trade/types.d.ts
CHANGED
|
@@ -609,5 +609,18 @@ export declare enum PairIndex {
|
|
|
609
609
|
LPTUSD = 383,
|
|
610
610
|
BVIVUSD = 384,
|
|
611
611
|
EVIVUSD = 385,
|
|
612
|
-
CRCLUSD = 386
|
|
612
|
+
CRCLUSD = 386,
|
|
613
|
+
RESOLVUSD = 387,
|
|
614
|
+
SQDUSD = 388,
|
|
615
|
+
TAIKOUSD = 389,
|
|
616
|
+
HOMEUSD = 390,
|
|
617
|
+
BUSD = 391,
|
|
618
|
+
HUMAUSD = 392,
|
|
619
|
+
SBETUSD = 393,
|
|
620
|
+
MTPLFUSD = 394,
|
|
621
|
+
PLTRUSD = 395,
|
|
622
|
+
BIDUUSD = 396,
|
|
623
|
+
ROKUUSD = 397,
|
|
624
|
+
EXODUSD = 398,
|
|
625
|
+
CHYMEUSD = 399
|
|
613
626
|
}
|
package/lib/trade/types.js
CHANGED
|
@@ -416,4 +416,17 @@ var PairIndex;
|
|
|
416
416
|
PairIndex[PairIndex["BVIVUSD"] = 384] = "BVIVUSD";
|
|
417
417
|
PairIndex[PairIndex["EVIVUSD"] = 385] = "EVIVUSD";
|
|
418
418
|
PairIndex[PairIndex["CRCLUSD"] = 386] = "CRCLUSD";
|
|
419
|
+
PairIndex[PairIndex["RESOLVUSD"] = 387] = "RESOLVUSD";
|
|
420
|
+
PairIndex[PairIndex["SQDUSD"] = 388] = "SQDUSD";
|
|
421
|
+
PairIndex[PairIndex["TAIKOUSD"] = 389] = "TAIKOUSD";
|
|
422
|
+
PairIndex[PairIndex["HOMEUSD"] = 390] = "HOMEUSD";
|
|
423
|
+
PairIndex[PairIndex["BUSD"] = 391] = "BUSD";
|
|
424
|
+
PairIndex[PairIndex["HUMAUSD"] = 392] = "HUMAUSD";
|
|
425
|
+
PairIndex[PairIndex["SBETUSD"] = 393] = "SBETUSD";
|
|
426
|
+
PairIndex[PairIndex["MTPLFUSD"] = 394] = "MTPLFUSD";
|
|
427
|
+
PairIndex[PairIndex["PLTRUSD"] = 395] = "PLTRUSD";
|
|
428
|
+
PairIndex[PairIndex["BIDUUSD"] = 396] = "BIDUUSD";
|
|
429
|
+
PairIndex[PairIndex["ROKUUSD"] = 397] = "ROKUUSD";
|
|
430
|
+
PairIndex[PairIndex["EXODUSD"] = 398] = "EXODUSD";
|
|
431
|
+
PairIndex[PairIndex["CHYMEUSD"] = 399] = "CHYMEUSD";
|
|
419
432
|
})(PairIndex = exports.PairIndex || (exports.PairIndex = {}));
|
package/package.json
CHANGED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/// <reference types="mocha" />
|
|
2
|
-
import type { GNSMultiCollatDiamond } from "../../types/generated";
|
|
3
|
-
import { BorrowingFeeV2 } from "../../../trade/fees/borrowingV2";
|
|
4
|
-
/**
|
|
5
|
-
* @dev Fetches borrowing fee parameters v2 for specific pairs
|
|
6
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
7
|
-
* @param collateralIndices Array of collateral indices
|
|
8
|
-
* @param pairIndices Array of pair indices
|
|
9
|
-
* @returns Promise resolving to array of borrowing fee parameters
|
|
10
|
-
*/
|
|
11
|
-
export declare const fetchBorrowingFeeParamsV2: (contract: GNSMultiCollatDiamond, collateralIndices: number[], pairIndices: number[]) => Promise<BorrowingFeeV2.BorrowingFeeParams[]>;
|
|
12
|
-
/**
|
|
13
|
-
* @dev Fetches pair borrowing fee data v2 for specific pairs
|
|
14
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
15
|
-
* @param collateralIndices Array of collateral indices
|
|
16
|
-
* @param pairIndices Array of pair indices
|
|
17
|
-
* @returns Promise resolving to array of pair borrowing fee data
|
|
18
|
-
*/
|
|
19
|
-
export declare const fetchPairBorrowingFeeDataV2: (contract: GNSMultiCollatDiamond, collateralIndices: number[], pairIndices: number[]) => Promise<BorrowingFeeV2.PairBorrowingFeeData[]>;
|
|
20
|
-
/**
|
|
21
|
-
* @dev Fetches borrowing fees in collateral tokens for a specific trade
|
|
22
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
23
|
-
* @param trader Address of the trader
|
|
24
|
-
* @param index Trade index
|
|
25
|
-
* @param currentPairPrice Current price of the trading pair (1e6 precision)
|
|
26
|
-
* @returns Promise resolving to borrowing fees in collateral tokens
|
|
27
|
-
*/
|
|
28
|
-
export declare const fetchTradeBorrowingFeesCollateralV2: (contract: GNSMultiCollatDiamond, trader: string, index: number, currentPairPrice: number) => Promise<number>;
|
|
29
|
-
/**
|
|
30
|
-
* @dev Fetches pending accumulated borrowing fees for a specific pair
|
|
31
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
32
|
-
* @param collateralIndex Index of the collateral
|
|
33
|
-
* @param pairIndex Index of the trading pair
|
|
34
|
-
* @param currentPairPrice Current price of the trading pair (1e6 precision)
|
|
35
|
-
* @returns Promise resolving to pending accumulated borrowing fee
|
|
36
|
-
*/
|
|
37
|
-
export declare const fetchPairPendingAccBorrowingFeesV2: (contract: GNSMultiCollatDiamond, collateralIndex: number, pairIndex: number, currentPairPrice: number) => Promise<number>;
|
|
38
|
-
/**
|
|
39
|
-
* @dev Convenience function to fetch all borrowing v2 data for specific pairs
|
|
40
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
41
|
-
* @param collateralIndex Index of the collateral
|
|
42
|
-
* @param pairIndices Array of pair indices
|
|
43
|
-
* @returns Promise resolving to complete borrowing v2 data set
|
|
44
|
-
*/
|
|
45
|
-
export declare const fetchAllBorrowingV2Data: (contract: GNSMultiCollatDiamond, collateralIndex: number, pairIndices: number[]) => Promise<{
|
|
46
|
-
params: BorrowingFeeV2.BorrowingFeeParams[];
|
|
47
|
-
data: BorrowingFeeV2.PairBorrowingFeeData[];
|
|
48
|
-
context: BorrowingFeeV2.GetBorrowingFeeV2Context;
|
|
49
|
-
}>;
|
|
50
|
-
/**
|
|
51
|
-
* @dev Creates a complete borrowing v2 context from contract data
|
|
52
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
53
|
-
* @param collateralIndex Index of the collateral
|
|
54
|
-
* @param pairIndices Array of pair indices
|
|
55
|
-
* @param currentTimestamp Optional current timestamp for calculations
|
|
56
|
-
* @returns Promise resolving to complete borrowing v2 context
|
|
57
|
-
*/
|
|
58
|
-
export declare const createBorrowingV2ContextFromContract: (contract: GNSMultiCollatDiamond, collateralIndex: number, pairIndices: number[], currentTimestamp?: number) => Promise<BorrowingFeeV2.GetBorrowingFeeV2Context>;
|
|
59
|
-
/**
|
|
60
|
-
* @dev Helper function to create context from already fetched arrays
|
|
61
|
-
* @param collateralIndices Array of collateral indices
|
|
62
|
-
* @param pairIndices Array of pair indices
|
|
63
|
-
* @param params Array of borrowing fee parameters
|
|
64
|
-
* @param data Array of pair borrowing fee data
|
|
65
|
-
* @param currentTimestamp Optional current timestamp
|
|
66
|
-
* @returns Complete borrowing v2 context
|
|
67
|
-
*/
|
|
68
|
-
export declare const createBorrowingV2ContextFromArrays: (collateralIndices: number[], pairIndices: number[], params: BorrowingFeeV2.BorrowingFeeParams[], data: BorrowingFeeV2.PairBorrowingFeeData[], currentTimestamp?: number) => BorrowingFeeV2.GetBorrowingFeeV2Context;
|
|
69
|
-
/**
|
|
70
|
-
* @dev Fetches borrowing v2 data for multiple collateral/pair combinations
|
|
71
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
72
|
-
* @param collateralIndices Array of collateral indices
|
|
73
|
-
* @param pairIndices Array of pair indices (must match collateralIndices length)
|
|
74
|
-
* @returns Promise resolving to complete borrowing v2 context
|
|
75
|
-
*/
|
|
76
|
-
export declare const fetchBorrowingV2DataForPairs: (contract: GNSMultiCollatDiamond, collateralIndices: number[], pairIndices: number[]) => Promise<BorrowingFeeV2.GetBorrowingFeeV2Context>;
|
|
@@ -1,193 +0,0 @@
|
|
|
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
|
-
exports.fetchBorrowingV2DataForPairs = exports.createBorrowingV2ContextFromArrays = exports.createBorrowingV2ContextFromContract = exports.fetchAllBorrowingV2Data = exports.fetchPairPendingAccBorrowingFeesV2 = exports.fetchTradeBorrowingFeesCollateralV2 = exports.fetchPairBorrowingFeeDataV2 = exports.fetchBorrowingFeeParamsV2 = void 0;
|
|
13
|
-
const converter_1 = require("../../../trade/fees/borrowingV2/converter");
|
|
14
|
-
/**
|
|
15
|
-
* @dev Fetches borrowing fee parameters v2 for specific pairs
|
|
16
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
17
|
-
* @param collateralIndices Array of collateral indices
|
|
18
|
-
* @param pairIndices Array of pair indices
|
|
19
|
-
* @returns Promise resolving to array of borrowing fee parameters
|
|
20
|
-
*/
|
|
21
|
-
const fetchBorrowingFeeParamsV2 = (contract, collateralIndices, pairIndices) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
-
if (collateralIndices.length !== pairIndices.length) {
|
|
23
|
-
throw new Error("Collateral indices and pair indices arrays must have the same length");
|
|
24
|
-
}
|
|
25
|
-
try {
|
|
26
|
-
const contractParams = yield contract.getPairBorrowingFeeParams(collateralIndices, pairIndices);
|
|
27
|
-
return (0, converter_1.convertBorrowingFeeParamsArray)(contractParams);
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
console.error("Error fetching borrowing fee params v2:", error);
|
|
31
|
-
throw error;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
exports.fetchBorrowingFeeParamsV2 = fetchBorrowingFeeParamsV2;
|
|
35
|
-
/**
|
|
36
|
-
* @dev Fetches pair borrowing fee data v2 for specific pairs
|
|
37
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
38
|
-
* @param collateralIndices Array of collateral indices
|
|
39
|
-
* @param pairIndices Array of pair indices
|
|
40
|
-
* @returns Promise resolving to array of pair borrowing fee data
|
|
41
|
-
*/
|
|
42
|
-
const fetchPairBorrowingFeeDataV2 = (contract, collateralIndices, pairIndices) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
-
if (collateralIndices.length !== pairIndices.length) {
|
|
44
|
-
throw new Error("Collateral indices and pair indices arrays must have the same length");
|
|
45
|
-
}
|
|
46
|
-
try {
|
|
47
|
-
const contractData = yield contract.getPairBorrowingFeeData(collateralIndices, pairIndices);
|
|
48
|
-
return (0, converter_1.convertPairBorrowingFeeDataArray)(contractData);
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
console.error("Error fetching pair borrowing fee data v2:", error);
|
|
52
|
-
throw error;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
exports.fetchPairBorrowingFeeDataV2 = fetchPairBorrowingFeeDataV2;
|
|
56
|
-
/**
|
|
57
|
-
* @dev Fetches borrowing fees in collateral tokens for a specific trade
|
|
58
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
59
|
-
* @param trader Address of the trader
|
|
60
|
-
* @param index Trade index
|
|
61
|
-
* @param currentPairPrice Current price of the trading pair (1e6 precision)
|
|
62
|
-
* @returns Promise resolving to borrowing fees in collateral tokens
|
|
63
|
-
*/
|
|
64
|
-
const fetchTradeBorrowingFeesCollateralV2 = (contract, trader, index, currentPairPrice) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
-
try {
|
|
66
|
-
const feesCollateral = yield contract.getTradeBorrowingFeesCollateral(trader, index, currentPairPrice);
|
|
67
|
-
// Convert BigNumber to normalized float
|
|
68
|
-
// Note: Collateral precision varies by chain, but contract returns proper precision
|
|
69
|
-
return parseFloat(feesCollateral.toString());
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
console.error("Error fetching trade borrowing fees collateral v2:", error);
|
|
73
|
-
throw error;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
exports.fetchTradeBorrowingFeesCollateralV2 = fetchTradeBorrowingFeesCollateralV2;
|
|
77
|
-
/**
|
|
78
|
-
* @dev Fetches pending accumulated borrowing fees for a specific pair
|
|
79
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
80
|
-
* @param collateralIndex Index of the collateral
|
|
81
|
-
* @param pairIndex Index of the trading pair
|
|
82
|
-
* @param currentPairPrice Current price of the trading pair (1e6 precision)
|
|
83
|
-
* @returns Promise resolving to pending accumulated borrowing fee
|
|
84
|
-
*/
|
|
85
|
-
const fetchPairPendingAccBorrowingFeesV2 = (contract, collateralIndex, pairIndex, currentPairPrice) => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
|
-
try {
|
|
87
|
-
const accBorrowingFeeP = yield contract.getPairPendingAccBorrowingFees(collateralIndex, pairIndex, currentPairPrice);
|
|
88
|
-
// Convert BigNumber to normalized float
|
|
89
|
-
return parseFloat(accBorrowingFeeP.toString()) / 1e20;
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
console.error("Error fetching pair pending acc borrowing fees v2:", error);
|
|
93
|
-
throw error;
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
exports.fetchPairPendingAccBorrowingFeesV2 = fetchPairPendingAccBorrowingFeesV2;
|
|
97
|
-
/**
|
|
98
|
-
* @dev Convenience function to fetch all borrowing v2 data for specific pairs
|
|
99
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
100
|
-
* @param collateralIndex Index of the collateral
|
|
101
|
-
* @param pairIndices Array of pair indices
|
|
102
|
-
* @returns Promise resolving to complete borrowing v2 data set
|
|
103
|
-
*/
|
|
104
|
-
const fetchAllBorrowingV2Data = (contract, collateralIndex, pairIndices) => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
|
-
const collateralIndices = new Array(pairIndices.length).fill(collateralIndex);
|
|
106
|
-
try {
|
|
107
|
-
// Fetch both parameters and data in parallel
|
|
108
|
-
const [params, data] = yield Promise.all([
|
|
109
|
-
(0, exports.fetchBorrowingFeeParamsV2)(contract, collateralIndices, pairIndices),
|
|
110
|
-
(0, exports.fetchPairBorrowingFeeDataV2)(contract, collateralIndices, pairIndices),
|
|
111
|
-
]);
|
|
112
|
-
// Create context from fetched data
|
|
113
|
-
const context = (0, exports.createBorrowingV2ContextFromArrays)(collateralIndices, pairIndices, params, data);
|
|
114
|
-
return { params, data, context };
|
|
115
|
-
}
|
|
116
|
-
catch (error) {
|
|
117
|
-
console.error("Error fetching all borrowing v2 data:", error);
|
|
118
|
-
throw error;
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
exports.fetchAllBorrowingV2Data = fetchAllBorrowingV2Data;
|
|
122
|
-
/**
|
|
123
|
-
* @dev Creates a complete borrowing v2 context from contract data
|
|
124
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
125
|
-
* @param collateralIndex Index of the collateral
|
|
126
|
-
* @param pairIndices Array of pair indices
|
|
127
|
-
* @param currentTimestamp Optional current timestamp for calculations
|
|
128
|
-
* @returns Promise resolving to complete borrowing v2 context
|
|
129
|
-
*/
|
|
130
|
-
const createBorrowingV2ContextFromContract = (contract, collateralIndex, pairIndices, currentTimestamp) => __awaiter(void 0, void 0, void 0, function* () {
|
|
131
|
-
const { context } = yield (0, exports.fetchAllBorrowingV2Data)(contract, collateralIndex, pairIndices);
|
|
132
|
-
return Object.assign(Object.assign({}, context), { currentTimestamp: currentTimestamp !== null && currentTimestamp !== void 0 ? currentTimestamp : Math.floor(Date.now() / 1000) });
|
|
133
|
-
});
|
|
134
|
-
exports.createBorrowingV2ContextFromContract = createBorrowingV2ContextFromContract;
|
|
135
|
-
/**
|
|
136
|
-
* @dev Helper function to create context from already fetched arrays
|
|
137
|
-
* @param collateralIndices Array of collateral indices
|
|
138
|
-
* @param pairIndices Array of pair indices
|
|
139
|
-
* @param params Array of borrowing fee parameters
|
|
140
|
-
* @param data Array of pair borrowing fee data
|
|
141
|
-
* @param currentTimestamp Optional current timestamp
|
|
142
|
-
* @returns Complete borrowing v2 context
|
|
143
|
-
*/
|
|
144
|
-
const createBorrowingV2ContextFromArrays = (collateralIndices, pairIndices, params, data, currentTimestamp) => {
|
|
145
|
-
const context = {
|
|
146
|
-
currentTimestamp: currentTimestamp !== null && currentTimestamp !== void 0 ? currentTimestamp : Math.floor(Date.now() / 1000),
|
|
147
|
-
borrowingParams: {},
|
|
148
|
-
borrowingData: {},
|
|
149
|
-
};
|
|
150
|
-
// Build nested objects indexed by collateralIndex and pairIndex
|
|
151
|
-
for (let i = 0; i < collateralIndices.length; i++) {
|
|
152
|
-
const collateralIndex = collateralIndices[i];
|
|
153
|
-
const pairIndex = pairIndices[i];
|
|
154
|
-
// Initialize collateral index objects if they don't exist
|
|
155
|
-
if (!context.borrowingParams[collateralIndex]) {
|
|
156
|
-
context.borrowingParams[collateralIndex] = {};
|
|
157
|
-
}
|
|
158
|
-
if (!context.borrowingData[collateralIndex]) {
|
|
159
|
-
context.borrowingData[collateralIndex] = {};
|
|
160
|
-
}
|
|
161
|
-
// Store data
|
|
162
|
-
context.borrowingParams[collateralIndex][pairIndex] = params[i];
|
|
163
|
-
context.borrowingData[collateralIndex][pairIndex] = data[i];
|
|
164
|
-
}
|
|
165
|
-
return context;
|
|
166
|
-
};
|
|
167
|
-
exports.createBorrowingV2ContextFromArrays = createBorrowingV2ContextFromArrays;
|
|
168
|
-
/**
|
|
169
|
-
* @dev Fetches borrowing v2 data for multiple collateral/pair combinations
|
|
170
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
171
|
-
* @param collateralIndices Array of collateral indices
|
|
172
|
-
* @param pairIndices Array of pair indices (must match collateralIndices length)
|
|
173
|
-
* @returns Promise resolving to complete borrowing v2 context
|
|
174
|
-
*/
|
|
175
|
-
const fetchBorrowingV2DataForPairs = (contract, collateralIndices, pairIndices) => __awaiter(void 0, void 0, void 0, function* () {
|
|
176
|
-
if (collateralIndices.length !== pairIndices.length) {
|
|
177
|
-
throw new Error("Collateral indices and pair indices arrays must have the same length");
|
|
178
|
-
}
|
|
179
|
-
try {
|
|
180
|
-
// Fetch both parameters and data in parallel
|
|
181
|
-
const [params, data] = yield Promise.all([
|
|
182
|
-
(0, exports.fetchBorrowingFeeParamsV2)(contract, collateralIndices, pairIndices),
|
|
183
|
-
(0, exports.fetchPairBorrowingFeeDataV2)(contract, collateralIndices, pairIndices),
|
|
184
|
-
]);
|
|
185
|
-
// Create and return context
|
|
186
|
-
return (0, exports.createBorrowingV2ContextFromArrays)(collateralIndices, pairIndices, params, data);
|
|
187
|
-
}
|
|
188
|
-
catch (error) {
|
|
189
|
-
console.error("Error fetching borrowing v2 data for pairs:", error);
|
|
190
|
-
throw error;
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
exports.fetchBorrowingV2DataForPairs = fetchBorrowingV2DataForPairs;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import type { GNSMultiCollatDiamond } from "../../types/generated";
|
|
2
|
-
import type { TradeInitialAccFees } from "../../../trade/fees/fundingFees";
|
|
3
|
-
/**
|
|
4
|
-
* @dev Fetches pending accumulated funding fees for a specific pair
|
|
5
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
6
|
-
* @param collateralIndex Collateral index
|
|
7
|
-
* @param pairIndex Pair index
|
|
8
|
-
* @param currentPairPrice Current pair price (1e10)
|
|
9
|
-
* @returns Promise resolving to accumulated funding fees and current rate
|
|
10
|
-
*/
|
|
11
|
-
export declare const fetchPairPendingAccFundingFees: (contract: GNSMultiCollatDiamond, collateralIndex: number, pairIndex: number, currentPairPrice: bigint) => Promise<{
|
|
12
|
-
accFundingFeeLongP: number;
|
|
13
|
-
accFundingFeeShortP: number;
|
|
14
|
-
currentFundingRatePerSecondP: number;
|
|
15
|
-
}>;
|
|
16
|
-
/**
|
|
17
|
-
* @dev Fetches funding fees for a specific trade in collateral tokens
|
|
18
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
19
|
-
* @param trader Trader address
|
|
20
|
-
* @param index Trade index
|
|
21
|
-
* @param currentPairPrice Current pair price (1e10)
|
|
22
|
-
* @returns Promise resolving to funding fee in collateral tokens
|
|
23
|
-
*/
|
|
24
|
-
export declare const fetchTradeFundingFeesCollateral: (contract: GNSMultiCollatDiamond, trader: string, index: number, currentPairPrice: bigint) => Promise<number>;
|
|
25
|
-
/**
|
|
26
|
-
* @dev Fetches trade fees data for a specific trade
|
|
27
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
28
|
-
* @param trader Trader address
|
|
29
|
-
* @param index Trade index
|
|
30
|
-
* @returns Promise resolving to trade fees data
|
|
31
|
-
*/
|
|
32
|
-
export declare const fetchTradeFeesData: (contract: GNSMultiCollatDiamond, trader: string, index: number) => Promise<TradeInitialAccFees>;
|
|
33
|
-
/**
|
|
34
|
-
* @dev Fetches trade fees data for multiple trades
|
|
35
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
36
|
-
* @param traders Array of trader addresses
|
|
37
|
-
* @param indices Array of trade indices
|
|
38
|
-
* @returns Promise resolving to array of trade fees data
|
|
39
|
-
*/
|
|
40
|
-
export declare const fetchTradeFeesDataBatch: (contract: GNSMultiCollatDiamond, traders: string[], indices: number[]) => Promise<TradeInitialAccFees[]>;
|
|
41
|
-
/**
|
|
42
|
-
* @dev Fetches pending accumulated funding fees for multiple pairs
|
|
43
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
44
|
-
* @param collateralIndices Array of collateral indices
|
|
45
|
-
* @param pairIndices Array of pair indices
|
|
46
|
-
* @param currentPairPrices Array of current pair prices (1e10)
|
|
47
|
-
* @returns Promise resolving to array of accumulated funding fees
|
|
48
|
-
*/
|
|
49
|
-
export declare const fetchPairPendingAccFundingFeesBatch: (contract: GNSMultiCollatDiamond, collateralIndices: number[], pairIndices: number[], currentPairPrices: bigint[]) => Promise<Array<{
|
|
50
|
-
accFundingFeeLongP: number;
|
|
51
|
-
accFundingFeeShortP: number;
|
|
52
|
-
currentFundingRatePerSecondP: number;
|
|
53
|
-
}>>;
|
|
54
|
-
/**
|
|
55
|
-
* @dev Helper to convert price from number to contract format
|
|
56
|
-
* @param price Price as number
|
|
57
|
-
* @returns Price in contract format (1e10)
|
|
58
|
-
*/
|
|
59
|
-
export declare const priceToContractFormat: (price: number) => bigint;
|
|
60
|
-
/**
|
|
61
|
-
* @dev Helper to convert collateral amount to contract format
|
|
62
|
-
* @param amount Amount as number
|
|
63
|
-
* @param decimals Collateral decimals (6 for USDC, 18 for others)
|
|
64
|
-
* @returns Amount in contract format
|
|
65
|
-
*/
|
|
66
|
-
export declare const collateralToContractFormat: (amount: number, decimals: number) => bigint;
|
|
@@ -1,150 +0,0 @@
|
|
|
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
|
-
exports.collateralToContractFormat = exports.priceToContractFormat = exports.fetchPairPendingAccFundingFeesBatch = exports.fetchTradeFeesDataBatch = exports.fetchTradeFeesData = exports.fetchTradeFundingFeesCollateral = exports.fetchPairPendingAccFundingFees = void 0;
|
|
13
|
-
/**
|
|
14
|
-
* @dev Fetches pending accumulated funding fees for a specific pair
|
|
15
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
16
|
-
* @param collateralIndex Collateral index
|
|
17
|
-
* @param pairIndex Pair index
|
|
18
|
-
* @param currentPairPrice Current pair price (1e10)
|
|
19
|
-
* @returns Promise resolving to accumulated funding fees and current rate
|
|
20
|
-
*/
|
|
21
|
-
const fetchPairPendingAccFundingFees = (contract, collateralIndex, pairIndex, currentPairPrice) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
-
try {
|
|
23
|
-
const result = yield contract.getPairPendingAccFundingFees(collateralIndex, pairIndex, currentPairPrice);
|
|
24
|
-
return {
|
|
25
|
-
accFundingFeeLongP: Number(result.accFundingFeeLongP) / 1e20,
|
|
26
|
-
accFundingFeeShortP: Number(result.accFundingFeeShortP) / 1e20,
|
|
27
|
-
currentFundingRatePerSecondP: Number(result.currentFundingRatePerSecondP) / 1e18, // FUNDING_RATE_PER_SECOND_P precision
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
console.error("Error fetching pair pending acc funding fees:", error);
|
|
32
|
-
throw error;
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
exports.fetchPairPendingAccFundingFees = fetchPairPendingAccFundingFees;
|
|
36
|
-
/**
|
|
37
|
-
* @dev Fetches funding fees for a specific trade in collateral tokens
|
|
38
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
39
|
-
* @param trader Trader address
|
|
40
|
-
* @param index Trade index
|
|
41
|
-
* @param currentPairPrice Current pair price (1e10)
|
|
42
|
-
* @returns Promise resolving to funding fee in collateral tokens
|
|
43
|
-
*/
|
|
44
|
-
const fetchTradeFundingFeesCollateral = (contract, trader, index, currentPairPrice) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
-
try {
|
|
46
|
-
const fundingFeeCollateral = yield contract.getTradeFundingFeesCollateral(trader, index, currentPairPrice);
|
|
47
|
-
// Convert from BigNumber to number (collateral precision already applied)
|
|
48
|
-
return Number(fundingFeeCollateral);
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
console.error("Error fetching trade funding fees:", error);
|
|
52
|
-
throw error;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
exports.fetchTradeFundingFeesCollateral = fetchTradeFundingFeesCollateral;
|
|
56
|
-
/**
|
|
57
|
-
* @dev Fetches trade fees data for a specific trade
|
|
58
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
59
|
-
* @param trader Trader address
|
|
60
|
-
* @param index Trade index
|
|
61
|
-
* @returns Promise resolving to trade fees data
|
|
62
|
-
*/
|
|
63
|
-
const fetchTradeFeesData = (contract, trader, index) => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
-
try {
|
|
65
|
-
const feesData = yield contract.getTradeFeesData(trader, index);
|
|
66
|
-
return {
|
|
67
|
-
accPerOiLong: Number(feesData.initialAccFundingFeeP) / 1e20,
|
|
68
|
-
accPerOiShort: Number(feesData.initialAccFundingFeeP) / 1e20,
|
|
69
|
-
openBlock: 0, // Not available in this struct
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
console.error("Error fetching trade fees data:", error);
|
|
74
|
-
throw error;
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
exports.fetchTradeFeesData = fetchTradeFeesData;
|
|
78
|
-
/**
|
|
79
|
-
* @dev Fetches trade fees data for multiple trades
|
|
80
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
81
|
-
* @param traders Array of trader addresses
|
|
82
|
-
* @param indices Array of trade indices
|
|
83
|
-
* @returns Promise resolving to array of trade fees data
|
|
84
|
-
*/
|
|
85
|
-
const fetchTradeFeesDataBatch = (contract, traders, indices) => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
|
-
if (traders.length !== indices.length) {
|
|
87
|
-
throw new Error("Traders and indices arrays must have the same length");
|
|
88
|
-
}
|
|
89
|
-
try {
|
|
90
|
-
const feesDatas = yield contract.getTradeFeesDataArray(traders, indices);
|
|
91
|
-
return feesDatas.map(feesData => ({
|
|
92
|
-
accPerOiLong: Number(feesData.initialAccFundingFeeP) / 1e20,
|
|
93
|
-
accPerOiShort: Number(feesData.initialAccFundingFeeP) / 1e20,
|
|
94
|
-
openBlock: 0,
|
|
95
|
-
}));
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
console.error("Error fetching trade fees data batch:", error);
|
|
99
|
-
throw error;
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
exports.fetchTradeFeesDataBatch = fetchTradeFeesDataBatch;
|
|
103
|
-
/**
|
|
104
|
-
* @dev Fetches pending accumulated funding fees for multiple pairs
|
|
105
|
-
* @param contract GNSMultiCollatDiamond contract instance
|
|
106
|
-
* @param collateralIndices Array of collateral indices
|
|
107
|
-
* @param pairIndices Array of pair indices
|
|
108
|
-
* @param currentPairPrices Array of current pair prices (1e10)
|
|
109
|
-
* @returns Promise resolving to array of accumulated funding fees
|
|
110
|
-
*/
|
|
111
|
-
const fetchPairPendingAccFundingFeesBatch = (contract, collateralIndices, pairIndices, currentPairPrices) => __awaiter(void 0, void 0, void 0, function* () {
|
|
112
|
-
if (collateralIndices.length !== pairIndices.length ||
|
|
113
|
-
pairIndices.length !== currentPairPrices.length) {
|
|
114
|
-
throw new Error("All input arrays must have the same length");
|
|
115
|
-
}
|
|
116
|
-
try {
|
|
117
|
-
// Fetch all in parallel
|
|
118
|
-
const promises = collateralIndices.map((collateralIndex, i) => contract.getPairPendingAccFundingFees(collateralIndex, pairIndices[i], currentPairPrices[i]));
|
|
119
|
-
const results = yield Promise.all(promises);
|
|
120
|
-
return results.map(result => ({
|
|
121
|
-
accFundingFeeLongP: Number(result.accFundingFeeLongP) / 1e20,
|
|
122
|
-
accFundingFeeShortP: Number(result.accFundingFeeShortP) / 1e20,
|
|
123
|
-
currentFundingRatePerSecondP: Number(result.currentFundingRatePerSecondP) / 1e18,
|
|
124
|
-
}));
|
|
125
|
-
}
|
|
126
|
-
catch (error) {
|
|
127
|
-
console.error("Error fetching pair pending acc funding fees batch:", error);
|
|
128
|
-
throw error;
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
exports.fetchPairPendingAccFundingFeesBatch = fetchPairPendingAccFundingFeesBatch;
|
|
132
|
-
/**
|
|
133
|
-
* @dev Helper to convert price from number to contract format
|
|
134
|
-
* @param price Price as number
|
|
135
|
-
* @returns Price in contract format (1e10)
|
|
136
|
-
*/
|
|
137
|
-
const priceToContractFormat = (price) => {
|
|
138
|
-
return BigInt(Math.round(price * 1e10));
|
|
139
|
-
};
|
|
140
|
-
exports.priceToContractFormat = priceToContractFormat;
|
|
141
|
-
/**
|
|
142
|
-
* @dev Helper to convert collateral amount to contract format
|
|
143
|
-
* @param amount Amount as number
|
|
144
|
-
* @param decimals Collateral decimals (6 for USDC, 18 for others)
|
|
145
|
-
* @returns Amount in contract format
|
|
146
|
-
*/
|
|
147
|
-
const collateralToContractFormat = (amount, decimals) => {
|
|
148
|
-
return BigInt(Math.round(amount * Math.pow(10, decimals)));
|
|
149
|
-
};
|
|
150
|
-
exports.collateralToContractFormat = collateralToContractFormat;
|