@gainsnetwork/sdk 0.2.56-rc2 → 0.2.56-rc4
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.js +2 -3
- package/lib/contracts/types/generated/GNSMultiCollatDiamond.d.ts +192 -7
- package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.js +322 -2
- package/lib/contracts/utils/borrowingFees.js +3 -1
- package/lib/trade/fees/borrowing/converter.d.ts +5 -3
- package/lib/trade/fees/borrowing/converter.js +8 -3
- package/lib/trade/fees/borrowing/index.d.ts +9 -4
- package/lib/trade/fees/borrowing/index.js +53 -11
- package/lib/trade/fees/borrowing/types.d.ts +5 -0
- package/package.json +1 -1
|
@@ -10969,6 +10969,26 @@ const _abi = [
|
|
|
10969
10969
|
name: "BorrowingZeroGroup",
|
|
10970
10970
|
type: "error",
|
|
10971
10971
|
},
|
|
10972
|
+
{
|
|
10973
|
+
anonymous: false,
|
|
10974
|
+
inputs: [
|
|
10975
|
+
{
|
|
10976
|
+
indexed: false,
|
|
10977
|
+
internalType: "uint32",
|
|
10978
|
+
name: "minP",
|
|
10979
|
+
type: "uint32",
|
|
10980
|
+
},
|
|
10981
|
+
{
|
|
10982
|
+
indexed: false,
|
|
10983
|
+
internalType: "uint32",
|
|
10984
|
+
name: "maxP",
|
|
10985
|
+
type: "uint32",
|
|
10986
|
+
},
|
|
10987
|
+
],
|
|
10988
|
+
name: "BorrowingFeePerBlockCapUpdated",
|
|
10989
|
+
type: "event",
|
|
10990
|
+
signature: "0xca38800286190b44d87a61aaf551868afbd46f1f76ed5b145e4e975e446a2964",
|
|
10991
|
+
},
|
|
10972
10992
|
{
|
|
10973
10993
|
anonymous: false,
|
|
10974
10994
|
inputs: [
|
|
@@ -11183,6 +11203,38 @@ const _abi = [
|
|
|
11183
11203
|
type: "event",
|
|
11184
11204
|
signature: "0x12515cf8712ede0f0e48dd7513c14f22f116a6b3f95bd493da7511cf7dcbadd7",
|
|
11185
11205
|
},
|
|
11206
|
+
{
|
|
11207
|
+
anonymous: false,
|
|
11208
|
+
inputs: [
|
|
11209
|
+
{
|
|
11210
|
+
indexed: true,
|
|
11211
|
+
internalType: "uint8",
|
|
11212
|
+
name: "collateralIndex",
|
|
11213
|
+
type: "uint8",
|
|
11214
|
+
},
|
|
11215
|
+
{
|
|
11216
|
+
indexed: true,
|
|
11217
|
+
internalType: "uint16",
|
|
11218
|
+
name: "pairIndex",
|
|
11219
|
+
type: "uint16",
|
|
11220
|
+
},
|
|
11221
|
+
{
|
|
11222
|
+
indexed: false,
|
|
11223
|
+
internalType: "uint32",
|
|
11224
|
+
name: "minP",
|
|
11225
|
+
type: "uint32",
|
|
11226
|
+
},
|
|
11227
|
+
{
|
|
11228
|
+
indexed: false,
|
|
11229
|
+
internalType: "uint32",
|
|
11230
|
+
name: "maxP",
|
|
11231
|
+
type: "uint32",
|
|
11232
|
+
},
|
|
11233
|
+
],
|
|
11234
|
+
name: "BorrowingPairFeePerBlockCapUpdated",
|
|
11235
|
+
type: "event",
|
|
11236
|
+
signature: "0xf5413841beaa3a78d74ab0e0e7528e0f5d357a193b9f600eb87c8746475109f6",
|
|
11237
|
+
},
|
|
11186
11238
|
{
|
|
11187
11239
|
anonymous: false,
|
|
11188
11240
|
inputs: [
|
|
@@ -11485,6 +11537,32 @@ const _abi = [
|
|
|
11485
11537
|
type: "function",
|
|
11486
11538
|
signature: "0x48da5b38",
|
|
11487
11539
|
},
|
|
11540
|
+
{
|
|
11541
|
+
inputs: [],
|
|
11542
|
+
name: "getBorrowingFeePerBlockCap",
|
|
11543
|
+
outputs: [
|
|
11544
|
+
{
|
|
11545
|
+
components: [
|
|
11546
|
+
{
|
|
11547
|
+
internalType: "uint32",
|
|
11548
|
+
name: "minP",
|
|
11549
|
+
type: "uint32",
|
|
11550
|
+
},
|
|
11551
|
+
{
|
|
11552
|
+
internalType: "uint32",
|
|
11553
|
+
name: "maxP",
|
|
11554
|
+
type: "uint32",
|
|
11555
|
+
},
|
|
11556
|
+
],
|
|
11557
|
+
internalType: "struct IBorrowingFees.BorrowingFeePerBlockCap",
|
|
11558
|
+
name: "",
|
|
11559
|
+
type: "tuple",
|
|
11560
|
+
},
|
|
11561
|
+
],
|
|
11562
|
+
stateMutability: "view",
|
|
11563
|
+
type: "function",
|
|
11564
|
+
signature: "0x06c01bef",
|
|
11565
|
+
},
|
|
11488
11566
|
{
|
|
11489
11567
|
inputs: [
|
|
11490
11568
|
{
|
|
@@ -11616,7 +11694,12 @@ const _abi = [
|
|
|
11616
11694
|
},
|
|
11617
11695
|
{
|
|
11618
11696
|
internalType: "uint64",
|
|
11619
|
-
name: "
|
|
11697
|
+
name: "groupAccFeeLongDelta",
|
|
11698
|
+
type: "uint64",
|
|
11699
|
+
},
|
|
11700
|
+
{
|
|
11701
|
+
internalType: "uint64",
|
|
11702
|
+
name: "groupAccFeeShortDelta",
|
|
11620
11703
|
type: "uint64",
|
|
11621
11704
|
},
|
|
11622
11705
|
],
|
|
@@ -11807,6 +11890,80 @@ const _abi = [
|
|
|
11807
11890
|
type: "function",
|
|
11808
11891
|
signature: "0x5d5bf24d",
|
|
11809
11892
|
},
|
|
11893
|
+
{
|
|
11894
|
+
inputs: [
|
|
11895
|
+
{
|
|
11896
|
+
internalType: "uint8",
|
|
11897
|
+
name: "_collateralIndex",
|
|
11898
|
+
type: "uint8",
|
|
11899
|
+
},
|
|
11900
|
+
{
|
|
11901
|
+
internalType: "uint16",
|
|
11902
|
+
name: "_pairIndex",
|
|
11903
|
+
type: "uint16",
|
|
11904
|
+
},
|
|
11905
|
+
],
|
|
11906
|
+
name: "getBorrowingPairFeePerBlockCap",
|
|
11907
|
+
outputs: [
|
|
11908
|
+
{
|
|
11909
|
+
components: [
|
|
11910
|
+
{
|
|
11911
|
+
internalType: "uint32",
|
|
11912
|
+
name: "minP",
|
|
11913
|
+
type: "uint32",
|
|
11914
|
+
},
|
|
11915
|
+
{
|
|
11916
|
+
internalType: "uint32",
|
|
11917
|
+
name: "maxP",
|
|
11918
|
+
type: "uint32",
|
|
11919
|
+
},
|
|
11920
|
+
],
|
|
11921
|
+
internalType: "struct IBorrowingFees.BorrowingFeePerBlockCap",
|
|
11922
|
+
name: "",
|
|
11923
|
+
type: "tuple",
|
|
11924
|
+
},
|
|
11925
|
+
],
|
|
11926
|
+
stateMutability: "view",
|
|
11927
|
+
type: "function",
|
|
11928
|
+
signature: "0x7bdbfe5a",
|
|
11929
|
+
},
|
|
11930
|
+
{
|
|
11931
|
+
inputs: [
|
|
11932
|
+
{
|
|
11933
|
+
internalType: "uint8",
|
|
11934
|
+
name: "_collateralIndex",
|
|
11935
|
+
type: "uint8",
|
|
11936
|
+
},
|
|
11937
|
+
{
|
|
11938
|
+
internalType: "uint16[]",
|
|
11939
|
+
name: "_indices",
|
|
11940
|
+
type: "uint16[]",
|
|
11941
|
+
},
|
|
11942
|
+
],
|
|
11943
|
+
name: "getBorrowingPairFeePerBlockCaps",
|
|
11944
|
+
outputs: [
|
|
11945
|
+
{
|
|
11946
|
+
components: [
|
|
11947
|
+
{
|
|
11948
|
+
internalType: "uint32",
|
|
11949
|
+
name: "minP",
|
|
11950
|
+
type: "uint32",
|
|
11951
|
+
},
|
|
11952
|
+
{
|
|
11953
|
+
internalType: "uint32",
|
|
11954
|
+
name: "maxP",
|
|
11955
|
+
type: "uint32",
|
|
11956
|
+
},
|
|
11957
|
+
],
|
|
11958
|
+
internalType: "struct IBorrowingFees.BorrowingFeePerBlockCap[]",
|
|
11959
|
+
name: "",
|
|
11960
|
+
type: "tuple[]",
|
|
11961
|
+
},
|
|
11962
|
+
],
|
|
11963
|
+
stateMutability: "view",
|
|
11964
|
+
type: "function",
|
|
11965
|
+
signature: "0x0a67b9a3",
|
|
11966
|
+
},
|
|
11810
11967
|
{
|
|
11811
11968
|
inputs: [
|
|
11812
11969
|
{
|
|
@@ -11983,7 +12140,12 @@ const _abi = [
|
|
|
11983
12140
|
},
|
|
11984
12141
|
{
|
|
11985
12142
|
internalType: "uint64",
|
|
11986
|
-
name: "
|
|
12143
|
+
name: "pairAccFeeLongDelta",
|
|
12144
|
+
type: "uint64",
|
|
12145
|
+
},
|
|
12146
|
+
{
|
|
12147
|
+
internalType: "uint64",
|
|
12148
|
+
name: "pairAccFeeShortDelta",
|
|
11987
12149
|
type: "uint64",
|
|
11988
12150
|
},
|
|
11989
12151
|
],
|
|
@@ -12301,6 +12463,32 @@ const _abi = [
|
|
|
12301
12463
|
type: "function",
|
|
12302
12464
|
signature: "0xfc79e929",
|
|
12303
12465
|
},
|
|
12466
|
+
{
|
|
12467
|
+
inputs: [
|
|
12468
|
+
{
|
|
12469
|
+
components: [
|
|
12470
|
+
{
|
|
12471
|
+
internalType: "uint32",
|
|
12472
|
+
name: "minP",
|
|
12473
|
+
type: "uint32",
|
|
12474
|
+
},
|
|
12475
|
+
{
|
|
12476
|
+
internalType: "uint32",
|
|
12477
|
+
name: "maxP",
|
|
12478
|
+
type: "uint32",
|
|
12479
|
+
},
|
|
12480
|
+
],
|
|
12481
|
+
internalType: "struct IBorrowingFees.BorrowingFeePerBlockCap",
|
|
12482
|
+
name: "_feePerBlockCap",
|
|
12483
|
+
type: "tuple",
|
|
12484
|
+
},
|
|
12485
|
+
],
|
|
12486
|
+
name: "initializeBorrowingFeePerBlockCap",
|
|
12487
|
+
outputs: [],
|
|
12488
|
+
stateMutability: "nonpayable",
|
|
12489
|
+
type: "function",
|
|
12490
|
+
signature: "0x1a733ea0",
|
|
12491
|
+
},
|
|
12304
12492
|
{
|
|
12305
12493
|
inputs: [
|
|
12306
12494
|
{
|
|
@@ -12335,6 +12523,32 @@ const _abi = [
|
|
|
12335
12523
|
type: "function",
|
|
12336
12524
|
signature: "0x4fa72788",
|
|
12337
12525
|
},
|
|
12526
|
+
{
|
|
12527
|
+
inputs: [
|
|
12528
|
+
{
|
|
12529
|
+
components: [
|
|
12530
|
+
{
|
|
12531
|
+
internalType: "uint32",
|
|
12532
|
+
name: "minP",
|
|
12533
|
+
type: "uint32",
|
|
12534
|
+
},
|
|
12535
|
+
{
|
|
12536
|
+
internalType: "uint32",
|
|
12537
|
+
name: "maxP",
|
|
12538
|
+
type: "uint32",
|
|
12539
|
+
},
|
|
12540
|
+
],
|
|
12541
|
+
internalType: "struct IBorrowingFees.BorrowingFeePerBlockCap",
|
|
12542
|
+
name: "_feePerBlockCap",
|
|
12543
|
+
type: "tuple",
|
|
12544
|
+
},
|
|
12545
|
+
],
|
|
12546
|
+
name: "setBorrowingFeePerBlockCap",
|
|
12547
|
+
outputs: [],
|
|
12548
|
+
stateMutability: "nonpayable",
|
|
12549
|
+
type: "function",
|
|
12550
|
+
signature: "0x197b65a5",
|
|
12551
|
+
},
|
|
12338
12552
|
{
|
|
12339
12553
|
inputs: [
|
|
12340
12554
|
{
|
|
@@ -12417,6 +12631,42 @@ const _abi = [
|
|
|
12417
12631
|
type: "function",
|
|
12418
12632
|
signature: "0x02c4e7c1",
|
|
12419
12633
|
},
|
|
12634
|
+
{
|
|
12635
|
+
inputs: [
|
|
12636
|
+
{
|
|
12637
|
+
internalType: "uint8",
|
|
12638
|
+
name: "_collateralIndex",
|
|
12639
|
+
type: "uint8",
|
|
12640
|
+
},
|
|
12641
|
+
{
|
|
12642
|
+
internalType: "uint16[]",
|
|
12643
|
+
name: "_indices",
|
|
12644
|
+
type: "uint16[]",
|
|
12645
|
+
},
|
|
12646
|
+
{
|
|
12647
|
+
components: [
|
|
12648
|
+
{
|
|
12649
|
+
internalType: "uint32",
|
|
12650
|
+
name: "minP",
|
|
12651
|
+
type: "uint32",
|
|
12652
|
+
},
|
|
12653
|
+
{
|
|
12654
|
+
internalType: "uint32",
|
|
12655
|
+
name: "maxP",
|
|
12656
|
+
type: "uint32",
|
|
12657
|
+
},
|
|
12658
|
+
],
|
|
12659
|
+
internalType: "struct IBorrowingFees.BorrowingFeePerBlockCap[]",
|
|
12660
|
+
name: "_values",
|
|
12661
|
+
type: "tuple[]",
|
|
12662
|
+
},
|
|
12663
|
+
],
|
|
12664
|
+
name: "setBorrowingPairFeePerBlockCapArray",
|
|
12665
|
+
outputs: [],
|
|
12666
|
+
stateMutability: "nonpayable",
|
|
12667
|
+
type: "function",
|
|
12668
|
+
signature: "0x92748a7d",
|
|
12669
|
+
},
|
|
12420
12670
|
{
|
|
12421
12671
|
inputs: [
|
|
12422
12672
|
{
|
|
@@ -12661,6 +12911,20 @@ const _abi = [
|
|
|
12661
12911
|
type: "event",
|
|
12662
12912
|
signature: "0x764c19c693af0da42ec6c6bed68a2dd1a2fa93d24785fcfce58ffa29ae313606",
|
|
12663
12913
|
},
|
|
12914
|
+
{
|
|
12915
|
+
anonymous: false,
|
|
12916
|
+
inputs: [
|
|
12917
|
+
{
|
|
12918
|
+
indexed: false,
|
|
12919
|
+
internalType: "uint8",
|
|
12920
|
+
name: "limitJobCount",
|
|
12921
|
+
type: "uint8",
|
|
12922
|
+
},
|
|
12923
|
+
],
|
|
12924
|
+
name: "LimitJobCountUpdated",
|
|
12925
|
+
type: "event",
|
|
12926
|
+
signature: "0xe3fd233ab0f657acfa4eec07f6b1d79a510c3eef274d27d305c7fc47695a1e7f",
|
|
12927
|
+
},
|
|
12664
12928
|
{
|
|
12665
12929
|
anonymous: false,
|
|
12666
12930
|
inputs: [
|
|
@@ -13270,6 +13534,20 @@ const _abi = [
|
|
|
13270
13534
|
type: "function",
|
|
13271
13535
|
signature: "0x891e656c",
|
|
13272
13536
|
},
|
|
13537
|
+
{
|
|
13538
|
+
inputs: [],
|
|
13539
|
+
name: "getLimitJobCount",
|
|
13540
|
+
outputs: [
|
|
13541
|
+
{
|
|
13542
|
+
internalType: "uint8",
|
|
13543
|
+
name: "",
|
|
13544
|
+
type: "uint8",
|
|
13545
|
+
},
|
|
13546
|
+
],
|
|
13547
|
+
stateMutability: "view",
|
|
13548
|
+
type: "function",
|
|
13549
|
+
signature: "0x75d097a7",
|
|
13550
|
+
},
|
|
13273
13551
|
{
|
|
13274
13552
|
inputs: [],
|
|
13275
13553
|
name: "getLimitJobId",
|
|
@@ -13284,6 +13562,20 @@ const _abi = [
|
|
|
13284
13562
|
type: "function",
|
|
13285
13563
|
signature: "0xf4b0664d",
|
|
13286
13564
|
},
|
|
13565
|
+
{
|
|
13566
|
+
inputs: [],
|
|
13567
|
+
name: "getLimitJobIndex",
|
|
13568
|
+
outputs: [
|
|
13569
|
+
{
|
|
13570
|
+
internalType: "uint88",
|
|
13571
|
+
name: "",
|
|
13572
|
+
type: "uint88",
|
|
13573
|
+
},
|
|
13574
|
+
],
|
|
13575
|
+
stateMutability: "view",
|
|
13576
|
+
type: "function",
|
|
13577
|
+
signature: "0xdb461060",
|
|
13578
|
+
},
|
|
13287
13579
|
{
|
|
13288
13580
|
inputs: [
|
|
13289
13581
|
{
|
|
@@ -13642,6 +13934,20 @@ const _abi = [
|
|
|
13642
13934
|
type: "function",
|
|
13643
13935
|
signature: "0xbbad411a",
|
|
13644
13936
|
},
|
|
13937
|
+
{
|
|
13938
|
+
inputs: [
|
|
13939
|
+
{
|
|
13940
|
+
internalType: "uint8",
|
|
13941
|
+
name: "_limitJobCount",
|
|
13942
|
+
type: "uint8",
|
|
13943
|
+
},
|
|
13944
|
+
],
|
|
13945
|
+
name: "initializeLimitJobCount",
|
|
13946
|
+
outputs: [],
|
|
13947
|
+
stateMutability: "nonpayable",
|
|
13948
|
+
type: "function",
|
|
13949
|
+
signature: "0xc386f31b",
|
|
13950
|
+
},
|
|
13645
13951
|
{
|
|
13646
13952
|
inputs: [
|
|
13647
13953
|
{
|
|
@@ -13741,6 +14047,20 @@ const _abi = [
|
|
|
13741
14047
|
type: "function",
|
|
13742
14048
|
signature: "0x25e589cd",
|
|
13743
14049
|
},
|
|
14050
|
+
{
|
|
14051
|
+
inputs: [
|
|
14052
|
+
{
|
|
14053
|
+
internalType: "uint8",
|
|
14054
|
+
name: "_limitJobCount",
|
|
14055
|
+
type: "uint8",
|
|
14056
|
+
},
|
|
14057
|
+
],
|
|
14058
|
+
name: "setLimitJobCount",
|
|
14059
|
+
outputs: [],
|
|
14060
|
+
stateMutability: "nonpayable",
|
|
14061
|
+
type: "function",
|
|
14062
|
+
signature: "0x19a891e4",
|
|
14063
|
+
},
|
|
13744
14064
|
{
|
|
13745
14065
|
inputs: [
|
|
13746
14066
|
{
|
|
@@ -32,7 +32,9 @@ const getBorrowingGroupName = (groupIndex) => {
|
|
|
32
32
|
};
|
|
33
33
|
exports.getBorrowingGroupName = getBorrowingGroupName;
|
|
34
34
|
const fetchAllPairBorrowingFees = (contract, collateralIndex) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
-
|
|
35
|
+
const [pairs, pairOi, pairGroups] = yield contract.getAllBorrowingPairs(collateralIndex);
|
|
36
|
+
const feeCaps = yield contract.getBorrowingPairFeePerBlockCaps(collateralIndex, [...Array(pairs.length).keys()]);
|
|
37
|
+
return (0, trade_1.convertPairBorrowingFees)([pairs, pairOi, pairGroups, feeCaps]);
|
|
36
38
|
});
|
|
37
39
|
exports.fetchAllPairBorrowingFees = fetchAllPairBorrowingFees;
|
|
38
40
|
const fetchGroupBorrowingFees = (contract, collateralIndex, groupIxs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { IBorrowingFees } from "../../../contracts/types/generated/GNSMultiCollatDiamond";
|
|
2
2
|
import { BorrowingFee } from ".";
|
|
3
3
|
export declare const convertPairGroupBorrowingFee: (pairGroup: IBorrowingFees.BorrowingPairGroupStructOutput) => BorrowingFee.PairGroup;
|
|
4
|
-
export declare const convertPairBorrowingFee: (pair: IBorrowingFees.BorrowingDataStructOutput, pairOi: IBorrowingFees.OpenInterestStructOutput, pairGroup: IBorrowingFees.BorrowingPairGroupStructOutput[]) => BorrowingFee.Pair;
|
|
5
|
-
export declare const convertPairBorrowingFees: ([pairs, pairOi, pairGroups]: [
|
|
4
|
+
export declare const convertPairBorrowingFee: (pair: IBorrowingFees.BorrowingDataStructOutput, pairOi: IBorrowingFees.OpenInterestStructOutput, pairGroup: IBorrowingFees.BorrowingPairGroupStructOutput[], feeCap: IBorrowingFees.BorrowingFeePerBlockCapStructOutput) => BorrowingFee.Pair;
|
|
5
|
+
export declare const convertPairBorrowingFees: ([pairs, pairOi, pairGroups, feeCaps]: [
|
|
6
6
|
IBorrowingFees.BorrowingDataStructOutput[],
|
|
7
7
|
IBorrowingFees.OpenInterestStructOutput[],
|
|
8
|
-
IBorrowingFees.BorrowingPairGroupStructOutput[][]
|
|
8
|
+
IBorrowingFees.BorrowingPairGroupStructOutput[][],
|
|
9
|
+
IBorrowingFees.BorrowingFeePerBlockCapStructOutput[]
|
|
9
10
|
]) => BorrowingFee.Pair[];
|
|
10
11
|
export declare const convertGroupBorrowingFee: (group: IBorrowingFees.BorrowingDataStructOutput, groupOi: IBorrowingFees.OpenInterestStructOutput) => BorrowingFee.Group;
|
|
11
12
|
export declare const convertGroupBorrowingData: (obj: IBorrowingFees.BorrowingDataStructOutput, oi: IBorrowingFees.OpenInterestStructOutput) => BorrowingFee.BorrowingData & BorrowingFee.BorrowingOi;
|
|
@@ -13,3 +14,4 @@ export declare const convertGroupBorrowingFees: ([groups, groupOis]: [
|
|
|
13
14
|
IBorrowingFees.BorrowingDataStructOutput[],
|
|
14
15
|
IBorrowingFees.OpenInterestStructOutput[]
|
|
15
16
|
]) => BorrowingFee.Group[];
|
|
17
|
+
export declare const convertFeePerBlockCap: (feeCap: IBorrowingFees.BorrowingFeePerBlockCapStructOutput) => BorrowingFee.BorrowingFeePerBlockCap;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertGroupBorrowingFees = exports.convertGroupBorrowingData = exports.convertGroupBorrowingFee = exports.convertPairBorrowingFees = exports.convertPairBorrowingFee = exports.convertPairGroupBorrowingFee = void 0;
|
|
3
|
+
exports.convertFeePerBlockCap = exports.convertGroupBorrowingFees = exports.convertGroupBorrowingData = exports.convertGroupBorrowingFee = exports.convertPairBorrowingFees = exports.convertPairBorrowingFee = exports.convertPairGroupBorrowingFee = void 0;
|
|
4
4
|
const borrowingFees_1 = require("../../../contracts/utils/borrowingFees");
|
|
5
5
|
const convertPairGroupBorrowingFee = (pairGroup) => ({
|
|
6
6
|
groupIndex: pairGroup.groupIndex,
|
|
@@ -14,9 +14,9 @@ const convertPairGroupBorrowingFee = (pairGroup) => ({
|
|
|
14
14
|
block: pairGroup.block,
|
|
15
15
|
});
|
|
16
16
|
exports.convertPairGroupBorrowingFee = convertPairGroupBorrowingFee;
|
|
17
|
-
const convertPairBorrowingFee = (pair, pairOi, pairGroup) => (Object.assign(Object.assign({}, (0, exports.convertGroupBorrowingData)(pair, pairOi)), { groups: pairGroup.map(value => (0, exports.convertPairGroupBorrowingFee)(value)) }));
|
|
17
|
+
const convertPairBorrowingFee = (pair, pairOi, pairGroup, feeCap) => (Object.assign(Object.assign({}, (0, exports.convertGroupBorrowingData)(pair, pairOi)), { groups: pairGroup.map(value => (0, exports.convertPairGroupBorrowingFee)(value)), feePerBlockCap: (0, exports.convertFeePerBlockCap)(feeCap) }));
|
|
18
18
|
exports.convertPairBorrowingFee = convertPairBorrowingFee;
|
|
19
|
-
const convertPairBorrowingFees = ([pairs, pairOi, pairGroups]) => pairs.map((value, ix) => (0, exports.convertPairBorrowingFee)(value, pairOi[ix], pairGroups[ix]));
|
|
19
|
+
const convertPairBorrowingFees = ([pairs, pairOi, pairGroups, feeCaps]) => pairs.map((value, ix) => (0, exports.convertPairBorrowingFee)(value, pairOi[ix], pairGroups[ix], feeCaps[ix]));
|
|
20
20
|
exports.convertPairBorrowingFees = convertPairBorrowingFees;
|
|
21
21
|
const convertGroupBorrowingFee = (group, groupOi) => (0, exports.convertGroupBorrowingData)(group, groupOi);
|
|
22
22
|
exports.convertGroupBorrowingFee = convertGroupBorrowingFee;
|
|
@@ -35,3 +35,8 @@ const convertGroupBorrowingData = (obj, oi) => ({
|
|
|
35
35
|
exports.convertGroupBorrowingData = convertGroupBorrowingData;
|
|
36
36
|
const convertGroupBorrowingFees = ([groups, groupOis]) => groups.map((value, ix) => (0, exports.convertGroupBorrowingFee)(value, groupOis[ix]));
|
|
37
37
|
exports.convertGroupBorrowingFees = convertGroupBorrowingFees;
|
|
38
|
+
const convertFeePerBlockCap = (feeCap) => ({
|
|
39
|
+
minP: feeCap.minP ? parseFloat(feeCap.minP.toString()) / 1e3 / 100 : 0,
|
|
40
|
+
maxP: feeCap.maxP ? parseFloat(feeCap.maxP.toString()) / 1e3 / 100 : 1,
|
|
41
|
+
});
|
|
42
|
+
exports.convertFeePerBlockCap = convertFeePerBlockCap;
|
|
@@ -22,7 +22,8 @@ export declare const borrowingFeeUtils: {
|
|
|
22
22
|
}) => {
|
|
23
23
|
accFeeLong: number;
|
|
24
24
|
accFeeShort: number;
|
|
25
|
-
|
|
25
|
+
deltaLong: number;
|
|
26
|
+
deltaShort: number;
|
|
26
27
|
};
|
|
27
28
|
getPairPendingAccFee: (pairIndex: PairIndex, currentBlock: number, long: boolean, context: {
|
|
28
29
|
pairs: BorrowingFee.Pair[];
|
|
@@ -33,21 +34,25 @@ export declare const borrowingFeeUtils: {
|
|
|
33
34
|
}) => {
|
|
34
35
|
accFeeLong: number;
|
|
35
36
|
accFeeShort: number;
|
|
36
|
-
|
|
37
|
+
deltaLong: number;
|
|
38
|
+
deltaShort: number;
|
|
37
39
|
};
|
|
38
40
|
getGroupPendingAccFee: (groupIndex: number, currentBlock: number, long: boolean, context: {
|
|
39
41
|
groups: BorrowingFee.Group[];
|
|
40
42
|
}) => number;
|
|
41
|
-
getPendingAccFees: (accFeeLong: number, accFeeShort: number, oiLong: number, oiShort: number, feePerBlock: number, currentBlock: number, accLastUpdatedBlock: number, maxOi: number, feeExponent: number) => {
|
|
43
|
+
getPendingAccFees: (accFeeLong: number, accFeeShort: number, oiLong: number, oiShort: number, feePerBlock: number, currentBlock: number, accLastUpdatedBlock: number, maxOi: number, feeExponent: number, feeCaps?: BorrowingFee.BorrowingFeePerBlockCap) => {
|
|
42
44
|
accFeeLong: number;
|
|
43
45
|
accFeeShort: number;
|
|
44
|
-
|
|
46
|
+
deltaLong: number;
|
|
47
|
+
deltaShort: number;
|
|
45
48
|
};
|
|
46
49
|
getActiveFeePerBlock: (pair: BorrowingFee.Pair, group: BorrowingFee.Group | undefined) => number;
|
|
47
50
|
getBorrowingDataActiveFeePerBlock: (val: BorrowingFee.Pair | BorrowingFee.Group) => number;
|
|
48
51
|
getPairGroupIndex: (pairIndex: PairIndex, context: {
|
|
49
52
|
pairs: BorrowingFee.Pair[];
|
|
50
53
|
}) => number;
|
|
54
|
+
getPendingAccFeesDelta: (blockDistance: number, feePerBlock: number, netOi: number, maxOi: number, feeExponent: number) => number;
|
|
55
|
+
getFeePerBlockCaps: (cap?: BorrowingFee.BorrowingFeePerBlockCap) => BorrowingFee.BorrowingFeePerBlockCap;
|
|
51
56
|
};
|
|
52
57
|
export * as BorrowingFee from "./types";
|
|
53
58
|
export * from "./converter";
|
|
@@ -77,7 +77,7 @@ const getPairGroupIndex = (pairIndex, context) => {
|
|
|
77
77
|
const getPairPendingAccFees = (pairIndex, currentBlock, context) => {
|
|
78
78
|
const { pairs, openInterest: { long, short }, } = context;
|
|
79
79
|
const pair = pairs[pairIndex];
|
|
80
|
-
return getPendingAccFees(pair.accFeeLong, pair.accFeeShort, long, short, pair.feePerBlock, currentBlock, pair.accLastUpdatedBlock, pair.oi.max, pair.feeExponent);
|
|
80
|
+
return getPendingAccFees(pair.accFeeLong, pair.accFeeShort, long, short, pair.feePerBlock, currentBlock, pair.accLastUpdatedBlock, pair.oi.max, pair.feeExponent, pair.feePerBlockCap);
|
|
81
81
|
};
|
|
82
82
|
const getPairPendingAccFee = (pairIndex, currentBlock, long, context) => {
|
|
83
83
|
const { accFeeLong, accFeeShort } = getPairPendingAccFees(pairIndex, currentBlock, context);
|
|
@@ -127,22 +127,62 @@ const getPairGroupAccFeesDeltas = (i, pairGroups, initialFees, pairIndex, long,
|
|
|
127
127
|
}
|
|
128
128
|
return { deltaGroup, deltaPair, beforeTradeOpen };
|
|
129
129
|
};
|
|
130
|
-
const getPendingAccFees = (accFeeLong, accFeeShort, oiLong, oiShort, feePerBlock, currentBlock, accLastUpdatedBlock, maxOi, feeExponent
|
|
130
|
+
const getPendingAccFees = (accFeeLong, accFeeShort, oiLong, oiShort, feePerBlock, currentBlock, accLastUpdatedBlock, maxOi, feeExponent, feeCaps // as percentage: eg minP: 0.1 = 10%, maxP: 0.5 = 50%
|
|
131
|
+
) => {
|
|
131
132
|
const moreShorts = oiLong < oiShort;
|
|
133
|
+
const blockDistance = currentBlock > accLastUpdatedBlock ? currentBlock - accLastUpdatedBlock : 0;
|
|
134
|
+
// If block distance is zero nothing changes
|
|
135
|
+
if (blockDistance === 0) {
|
|
136
|
+
return {
|
|
137
|
+
accFeeLong,
|
|
138
|
+
accFeeShort,
|
|
139
|
+
deltaLong: 0,
|
|
140
|
+
deltaShort: 0,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
132
143
|
const netOi = Math.abs(oiLong - oiShort);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
144
|
+
// Calculate minimum and maximum effective oi
|
|
145
|
+
const { minP, maxP } = getFeePerBlockCaps(feeCaps);
|
|
146
|
+
const minNetOi = maxOi * minP;
|
|
147
|
+
const maxNetOi = maxOi * maxP;
|
|
148
|
+
// Calculate the minimum acc fee delta (applies to both sides)
|
|
149
|
+
const minDelta = minNetOi > 0
|
|
150
|
+
? getPendingAccFeesDelta(blockDistance, feePerBlock, netOi, maxOi, feeExponent)
|
|
151
|
+
: 0;
|
|
152
|
+
// Calculate the actual acc fee (using capped oi of 100% or less)
|
|
153
|
+
const delta = netOi > minNetOi
|
|
154
|
+
? getPendingAccFeesDelta(blockDistance, feePerBlock, Math.min(netOi, maxNetOi), // if netOi > cap, use cap
|
|
155
|
+
maxOi, feeExponent)
|
|
156
|
+
: minDelta;
|
|
157
|
+
const [deltaLong, deltaShort] = moreShorts
|
|
158
|
+
? [minDelta, delta]
|
|
159
|
+
: [delta, minDelta];
|
|
160
|
+
return {
|
|
161
|
+
accFeeLong: accFeeLong + deltaLong,
|
|
162
|
+
accFeeShort: accFeeShort + deltaShort,
|
|
163
|
+
deltaLong,
|
|
164
|
+
deltaShort,
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
const getPendingAccFeesDelta = (blockDistance, feePerBlock, netOi, maxOi, feeExponent) => {
|
|
168
|
+
return maxOi > 0 && feeExponent > 0
|
|
169
|
+
? feePerBlock * blockDistance * Math.pow((netOi / maxOi), feeExponent)
|
|
137
170
|
: 0;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return {
|
|
171
|
+
};
|
|
172
|
+
const getFeePerBlockCaps = (cap) => {
|
|
173
|
+
return {
|
|
174
|
+
minP: (cap === null || cap === void 0 ? void 0 : cap.minP) || 0,
|
|
175
|
+
maxP: (cap === null || cap === void 0 ? void 0 : cap.maxP) && cap.maxP > 0 ? cap.maxP : 1,
|
|
176
|
+
};
|
|
141
177
|
};
|
|
142
178
|
const getBorrowingDataActiveFeePerBlock = (val) => {
|
|
143
179
|
const { long, short, max } = val.oi;
|
|
144
|
-
const
|
|
145
|
-
|
|
180
|
+
const { minP, maxP } = getFeePerBlockCaps("feePerBlockCap" in val ? val.feePerBlockCap : undefined);
|
|
181
|
+
// Calculate the effective open interest
|
|
182
|
+
// If minP > 0 then netOi has to be at least minP * maxOi
|
|
183
|
+
// If maxP > 0 then netOi cannot be more than maxP * maxOi
|
|
184
|
+
const effectiveOi = Math.min(Math.max(Math.abs(long - short), max * minP), max * maxP);
|
|
185
|
+
return val.feePerBlock * Math.pow((effectiveOi / max), val.feeExponent);
|
|
146
186
|
};
|
|
147
187
|
const getActiveFeePerBlock = (pair, group) => {
|
|
148
188
|
const pairFeePerBlock = getBorrowingDataActiveFeePerBlock(pair);
|
|
@@ -162,6 +202,8 @@ exports.borrowingFeeUtils = {
|
|
|
162
202
|
getActiveFeePerBlock,
|
|
163
203
|
getBorrowingDataActiveFeePerBlock,
|
|
164
204
|
getPairGroupIndex,
|
|
205
|
+
getPendingAccFeesDelta,
|
|
206
|
+
getFeePerBlockCaps,
|
|
165
207
|
};
|
|
166
208
|
exports.BorrowingFee = __importStar(require("./types"));
|
|
167
209
|
__exportStar(require("./converter"), exports);
|
|
@@ -20,8 +20,13 @@ export type PairGroup = {
|
|
|
20
20
|
export type BorrowingOi = {
|
|
21
21
|
oi: OpenInterest;
|
|
22
22
|
};
|
|
23
|
+
export type BorrowingFeePerBlockCap = {
|
|
24
|
+
minP: number;
|
|
25
|
+
maxP: number;
|
|
26
|
+
};
|
|
23
27
|
export type Pair = BorrowingData & BorrowingOi & {
|
|
24
28
|
groups: PairGroup[];
|
|
29
|
+
feePerBlockCap?: BorrowingFeePerBlockCap;
|
|
25
30
|
};
|
|
26
31
|
export type Group = BorrowingData & BorrowingOi;
|
|
27
32
|
export type InitialAccFees = {
|