@gainsnetwork/sdk 0.0.25 → 0.0.26

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.
@@ -8,6 +8,10 @@ export type GetBorrowingFeeContext = {
8
8
  openInterest: OpenInterest;
9
9
  };
10
10
  export declare const getBorrowingFee: (posDai: number, pairIndex: number, long: boolean, initialAccFees: BorrowingFee.InitialAccFees, context: GetBorrowingFeeContext) => number;
11
+ export declare const withinMaxGroupOi: (pairIndex: number, long: boolean, positionSizeDai: number, context: {
12
+ groups: BorrowingFee.Group[];
13
+ pairs: BorrowingFee.Pair[];
14
+ }) => boolean;
11
15
  export declare const borrowingFeeUtils: {
12
16
  getPairGroupAccFeesDeltas: (i: number, pairGroups: BorrowingFee.PairGroup[], initialFees: BorrowingFee.InitialAccFees, pairIndex: number, long: boolean, context: GetBorrowingFeeContext) => {
13
17
  deltaGroup: number;
@@ -49,5 +53,8 @@ export declare const borrowingFeeUtils: {
49
53
  getActiveGroupFeePerBlock: (group: BorrowingFee.Group, accBlockWeightedMarketCap: number, currentBlock: number) => number;
50
54
  getActiveFeePerBlock: (pair: BorrowingFee.Pair, group: BorrowingFee.Group | undefined, pairOpenInterest: OpenInterest, accBlockWeightedMarketCap: number, currentBlock: number) => number;
51
55
  getWeightedVaultMarketCap: (accBlockWeightedMarketCap: number, lastAccBlockWeightedMarketCap: number, blockDelta: number) => number;
56
+ getPairGroupIndex: (pairIndex: number, context: {
57
+ pairs: BorrowingFee.Pair[];
58
+ }) => number;
52
59
  };
53
60
  export * as BorrowingFee from "./types";
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.BorrowingFee = exports.borrowingFeeUtils = exports.getBorrowingFee = void 0;
26
+ exports.BorrowingFee = exports.borrowingFeeUtils = exports.withinMaxGroupOi = exports.getBorrowingFee = void 0;
27
27
  const getBorrowingFee = (posDai, pairIndex, long, initialAccFees, context) => {
28
28
  if (!context.groups ||
29
29
  !context.pairs ||
@@ -53,6 +53,23 @@ const getBorrowingFee = (posDai, pairIndex, long, initialAccFees, context) => {
53
53
  return (posDai * fee) / 100;
54
54
  };
55
55
  exports.getBorrowingFee = getBorrowingFee;
56
+ const withinMaxGroupOi = (pairIndex, long, positionSizeDai, context) => {
57
+ const { groups, pairs } = context;
58
+ if (!groups || !pairs) {
59
+ return false;
60
+ }
61
+ const g = groups[getPairGroupIndex(pairIndex, { pairs })];
62
+ return (g.maxOi == 0 || (long ? g.oiLong : g.oiShort) + positionSizeDai <= g.maxOi);
63
+ };
64
+ exports.withinMaxGroupOi = withinMaxGroupOi;
65
+ const getPairGroupIndex = (pairIndex, context) => {
66
+ const { pairs } = context;
67
+ if (!pairs[pairIndex]) {
68
+ return 0;
69
+ }
70
+ const pairGroups = pairs[pairIndex].groups;
71
+ return pairGroups.length == 0 ? 0 : pairGroups[0].groupIndex;
72
+ };
56
73
  const getPairPendingAccFees = (pairIndex, currentBlock, context) => {
57
74
  const { pairs, openInterest: { long, short }, accBlockWeightedMarketCap, } = context;
58
75
  const pair = pairs[pairIndex];
@@ -152,5 +169,6 @@ exports.borrowingFeeUtils = {
152
169
  getActiveGroupFeePerBlock,
153
170
  getActiveFeePerBlock,
154
171
  getWeightedVaultMarketCap,
172
+ getPairGroupIndex,
155
173
  };
156
174
  exports.BorrowingFee = __importStar(require("./types"));
@@ -23,6 +23,7 @@ export type Group = {
23
23
  accFeeLong: number;
24
24
  accFeeShort: number;
25
25
  accLastUpdatedBlock: number;
26
+ maxOi: number;
26
27
  lastAccBlockWeightedMarketCap: number;
27
28
  };
28
29
  export type InitialAccFees = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gainsnetwork/sdk",
3
- "version": "0.0.25",
3
+ "version": "0.0.26",
4
4
  "description": "Gains Network SDK",
5
5
  "main": "./lib/index.js",
6
6
  "files": [