@suilend/sdk 1.1.99 → 2.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.
Files changed (91) hide show
  1. package/_generated/_dependencies/source/0x1/ascii/structs.d.ts +7 -7
  2. package/_generated/_dependencies/source/0x1/ascii/structs.js +35 -75
  3. package/_generated/_dependencies/source/0x1/index.js +3 -6
  4. package/_generated/_dependencies/source/0x1/option/structs.d.ts +3 -3
  5. package/_generated/_dependencies/source/0x1/option/structs.js +31 -69
  6. package/_generated/_dependencies/source/0x1/type-name/structs.d.ts +5 -5
  7. package/_generated/_dependencies/source/0x1/type-name/structs.js +20 -25
  8. package/_generated/_dependencies/source/0x2/bag/structs.d.ts +7 -7
  9. package/_generated/_dependencies/source/0x2/bag/structs.js +24 -29
  10. package/_generated/_dependencies/source/0x2/balance/structs.d.ts +7 -7
  11. package/_generated/_dependencies/source/0x2/balance/structs.js +49 -56
  12. package/_generated/_dependencies/source/0x2/index.js +3 -6
  13. package/_generated/_dependencies/source/0x2/object/structs.d.ts +8 -8
  14. package/_generated/_dependencies/source/0x2/object/structs.js +34 -41
  15. package/_generated/_dependencies/source/0x2/object-table/structs.d.ts +7 -7
  16. package/_generated/_dependencies/source/0x2/object-table/structs.js +31 -36
  17. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs.d.ts +5 -5
  18. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs.js +23 -28
  19. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/index.js +4 -7
  20. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs.d.ts +11 -11
  21. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs.js +32 -37
  22. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs.d.ts +23 -23
  23. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs.js +29 -34
  24. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.d.ts +4 -4
  25. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.js +21 -59
  26. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs.d.ts +55 -55
  27. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs.js +46 -53
  28. package/_generated/_framework/reified.d.ts +2 -2
  29. package/_generated/_framework/reified.js +27 -40
  30. package/_generated/_framework/util.js +26 -40
  31. package/_generated/_framework/vector.d.ts +4 -4
  32. package/_generated/_framework/vector.js +16 -21
  33. package/_generated/suilend/cell/structs.d.ts +4 -4
  34. package/_generated/suilend/cell/structs.js +31 -36
  35. package/_generated/suilend/decimal/structs.d.ts +4 -4
  36. package/_generated/suilend/decimal/structs.js +19 -24
  37. package/_generated/suilend/index.js +8 -12
  38. package/_generated/suilend/lending-market/functions.d.ts +1 -0
  39. package/_generated/suilend/lending-market/functions.js +271 -302
  40. package/_generated/suilend/lending-market/structs.d.ts +146 -146
  41. package/_generated/suilend/lending-market/structs.js +549 -617
  42. package/_generated/suilend/lending-market-registry/functions.js +7 -11
  43. package/_generated/suilend/liquidity-mining/structs.d.ts +50 -50
  44. package/_generated/suilend/liquidity-mining/structs.js +159 -205
  45. package/_generated/suilend/obligation/structs.d.ts +106 -106
  46. package/_generated/suilend/obligation/structs.js +313 -363
  47. package/_generated/suilend/rate-limiter/functions.js +23 -31
  48. package/_generated/suilend/rate-limiter/structs.d.ts +15 -15
  49. package/_generated/suilend/rate-limiter/structs.js +49 -56
  50. package/_generated/suilend/reserve/structs.d.ts +139 -139
  51. package/_generated/suilend/reserve/structs.js +397 -451
  52. package/_generated/suilend/reserve-config/functions.js +149 -190
  53. package/_generated/suilend/reserve-config/structs.d.ts +33 -33
  54. package/_generated/suilend/reserve-config/structs.js +109 -149
  55. package/api/events.js +1 -5
  56. package/api/index.js +1 -17
  57. package/client.d.ts +10 -10
  58. package/client.js +118 -128
  59. package/index.js +7 -23
  60. package/lib/constants.js +3 -9
  61. package/lib/index.js +5 -21
  62. package/lib/initialize.d.ts +3 -3
  63. package/lib/initialize.js +103 -140
  64. package/lib/liquidityMining.d.ts +3 -3
  65. package/lib/liquidityMining.js +57 -72
  66. package/lib/pyth.js +9 -14
  67. package/lib/strategyOwnerCap.js +106 -119
  68. package/lib/transactions.js +2 -7
  69. package/lib/types.js +4 -7
  70. package/mmt.js +2 -5
  71. package/package.json +1 -1
  72. package/parsers/apiReserveAssetDataEvent.js +25 -33
  73. package/parsers/index.js +5 -21
  74. package/parsers/lendingMarket.d.ts +1 -1
  75. package/parsers/lendingMarket.js +12 -19
  76. package/parsers/obligation.js +19 -26
  77. package/parsers/rateLimiter.js +11 -19
  78. package/parsers/reserve.d.ts +1 -1
  79. package/parsers/reserve.js +42 -85
  80. package/strategies.d.ts +11 -11
  81. package/strategies.js +547 -586
  82. package/swap/index.js +2 -18
  83. package/swap/quote.js +57 -65
  84. package/swap/transaction.d.ts +2 -2
  85. package/swap/transaction.js +40 -35
  86. package/utils/events.d.ts +3 -3
  87. package/utils/events.js +18 -35
  88. package/utils/index.js +16 -40
  89. package/utils/obligation.d.ts +4 -4
  90. package/utils/obligation.js +17 -60
  91. package/utils/simulate.js +118 -143
package/utils/index.js CHANGED
@@ -1,32 +1,11 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.bisectionMethod = exports.linearlyInterpolate = exports.reserveSort = exports.toHexString = void 0;
21
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
22
- __exportStar(require("./events"), exports);
23
- __exportStar(require("./obligation"), exports);
24
- __exportStar(require("./simulate"), exports);
25
- const toHexString = (bytes) => Array.from(bytes, function (byte) {
1
+ import BigNumber from "bignumber.js";
2
+ export * from "./events";
3
+ export * from "./obligation";
4
+ export * from "./simulate";
5
+ export const toHexString = (bytes) => Array.from(bytes, function (byte) {
26
6
  return ("0" + (byte & 0xff).toString(16)).slice(-2);
27
7
  }).join("");
28
- exports.toHexString = toHexString;
29
- const reserveSort = (reserves, aCoinType, bCoinType) => {
8
+ export const reserveSort = (reserves, aCoinType, bCoinType) => {
30
9
  const aReserveIndex = reserves.findIndex((r) => r.coinType === aCoinType);
31
10
  const bReserveIndex = reserves.findIndex((r) => r.coinType === bCoinType);
32
11
  if (aReserveIndex > -1 && bReserveIndex > -1)
@@ -36,25 +15,23 @@ const reserveSort = (reserves, aCoinType, bCoinType) => {
36
15
  else
37
16
  return aReserveIndex > -1 ? -1 : 1;
38
17
  };
39
- exports.reserveSort = reserveSort;
40
- const linearlyInterpolate = (array, xKey, yKey, _xValue) => {
18
+ export const linearlyInterpolate = (array, xKey, yKey, _xValue) => {
41
19
  let i = 1;
42
20
  while (i < array.length) {
43
- const leftXValue = new bignumber_js_1.default(array[i - 1][xKey]);
44
- const leftYValue = new bignumber_js_1.default(array[i - 1][yKey]);
45
- const xValue = new bignumber_js_1.default(_xValue);
46
- const rightXValue = new bignumber_js_1.default(array[i][xKey]);
47
- const rightYValue = new bignumber_js_1.default(array[i][yKey]);
21
+ const leftXValue = new BigNumber(array[i - 1][xKey]);
22
+ const leftYValue = new BigNumber(array[i - 1][yKey]);
23
+ const xValue = new BigNumber(_xValue);
24
+ const rightXValue = new BigNumber(array[i][xKey]);
25
+ const rightYValue = new BigNumber(array[i][yKey]);
48
26
  if (xValue.gte(leftXValue) && xValue.lte(rightXValue)) {
49
- const weight = new bignumber_js_1.default(xValue.minus(leftXValue)).div(rightXValue.minus(leftXValue));
27
+ const weight = new BigNumber(xValue.minus(leftXValue)).div(rightXValue.minus(leftXValue));
50
28
  return leftYValue.plus(weight.times(rightYValue.minus(leftYValue)));
51
29
  }
52
30
  i = i + 1;
53
31
  }
54
32
  // Should never reach here
55
- return new bignumber_js_1.default(0);
33
+ return new BigNumber(0);
56
34
  };
57
- exports.linearlyInterpolate = linearlyInterpolate;
58
35
  /**
59
36
  * Bisection method to find the optimal value that satisfies a condition
60
37
  * @param left - Left boundary of the search range
@@ -64,10 +41,10 @@ exports.linearlyInterpolate = linearlyInterpolate;
64
41
  * @param tolerance - Convergence tolerance (default: 0.000001)
65
42
  * @returns The optimal value that satisfies the condition
66
43
  */
67
- const bisectionMethod = (left, right, condition, maxIterations = 50, tolerance = new bignumber_js_1.default(0.000001)) => {
44
+ export const bisectionMethod = (left, right, condition, maxIterations = 50, tolerance = new BigNumber(0.000001)) => {
68
45
  let currentLeft = left;
69
46
  let currentRight = right;
70
- let bestValue = new bignumber_js_1.default(0);
47
+ let bestValue = new BigNumber(0);
71
48
  for (let i = 0; i < maxIterations; i++) {
72
49
  const mid = currentLeft.plus(currentRight).div(2);
73
50
  if (mid.eq(currentLeft) && mid.eq(currentRight)) {
@@ -87,4 +64,3 @@ const bisectionMethod = (left, right, condition, maxIterations = 50, tolerance =
87
64
  }
88
65
  return bestValue;
89
66
  };
90
- exports.bisectionMethod = bisectionMethod;
@@ -1,8 +1,8 @@
1
- import { SuiClient } from "@mysten/sui/client";
1
+ import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
2
2
  import { Obligation } from "../_generated/suilend/obligation/structs";
3
3
  import { ParsedObligation } from "../parsers";
4
- export declare function fetchAllObligationsForMarketWithHandler(client: SuiClient, lendingMarketId: string, lendingMarketType: string, chunkHandler: (obligations: Obligation<string>[]) => Promise<void>): Promise<void>;
5
- export declare function fetchAllObligationsForMarket(client: SuiClient, lendingMarketId: string, lendingMarketType: string): Promise<Obligation<string>[]>;
4
+ export declare function fetchAllObligationsForMarketWithHandler(client: SuiJsonRpcClient, lendingMarketId: string, lendingMarketType: string, chunkHandler: (obligations: Obligation<string>[]) => Promise<void>): Promise<void>;
5
+ export declare function fetchAllObligationsForMarket(client: SuiJsonRpcClient, lendingMarketId: string, lendingMarketType: string): Promise<Obligation<string>[]>;
6
6
  export type FormattedObligationHistory = NonLiquidationHistoryEvent | LiquidationHistoryEvent;
7
7
  export type NonLiquidationHistoryEvent = {
8
8
  reserveId: string;
@@ -20,7 +20,7 @@ export type LiquidationHistoryEvent = {
20
20
  timestampMs: number;
21
21
  digest: string;
22
22
  };
23
- export declare function getObligationHistoryPage(client: SuiClient, obligationId: string, maxQuantity: number, cursor: string | null): Promise<{
23
+ export declare function getObligationHistoryPage(client: SuiJsonRpcClient, obligationId: string, maxQuantity: number, cursor: string | null): Promise<{
24
24
  cursor: string | null | undefined;
25
25
  history: FormattedObligationHistory[];
26
26
  }>;
@@ -1,37 +1,3 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -41,25 +7,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
41
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
42
8
  });
43
9
  };
44
- var __importDefault = (this && this.__importDefault) || function (mod) {
45
- return (mod && mod.__esModule) ? mod : { "default": mod };
46
- };
47
- Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.getWeightedBorrowsUsd = void 0;
49
- exports.fetchAllObligationsForMarketWithHandler = fetchAllObligationsForMarketWithHandler;
50
- exports.fetchAllObligationsForMarket = fetchAllObligationsForMarket;
51
- exports.getObligationHistoryPage = getObligationHistoryPage;
52
- const utils_1 = require("@mysten/sui/utils");
53
- const bignumber_js_1 = require("bignumber.js");
54
- const p_limit_1 = __importDefault(require("p-limit"));
55
- const reified_1 = require("../_generated/_framework/reified");
56
- const suilend_1 = require("../_generated/suilend");
57
- const structs_1 = require("../_generated/suilend/obligation/structs");
58
- const parsed = __importStar(require("./events"));
59
- function fetchAllObligationsForMarketWithHandler(client, lendingMarketId, lendingMarketType, chunkHandler) {
10
+ import { fromBase64 } from "@mysten/sui/utils";
11
+ import { BigNumber } from "bignumber.js";
12
+ import pLimit from "p-limit";
13
+ import { phantom } from "../_generated/_framework/reified";
14
+ import { PACKAGE_ID } from "../_generated/suilend";
15
+ import { Obligation } from "../_generated/suilend/obligation/structs";
16
+ import * as parsed from "./events";
17
+ export function fetchAllObligationsForMarketWithHandler(client, lendingMarketId, lendingMarketType, chunkHandler) {
60
18
  return __awaiter(this, void 0, void 0, function* () {
61
19
  var _a;
62
- const limit = (0, p_limit_1.default)(30);
20
+ const limit = pLimit(30);
63
21
  const rawLendingMarket = yield client.getObject({
64
22
  id: lendingMarketId,
65
23
  options: {
@@ -87,7 +45,7 @@ function fetchAllObligationsForMarketWithHandler(client, lendingMarketId, lendin
87
45
  const obligationObjects = yield chunkedMultiGet(client, response.data.map((x) => x.objectId));
88
46
  const obligations = [];
89
47
  for (const rawObligation of obligationObjects) {
90
- obligations.push(structs_1.Obligation.fromBcs((0, reified_1.phantom)(lendingMarketType), (0, utils_1.fromBase64)(((_a = rawObligation.data) === null || _a === void 0 ? void 0 : _a.bcs).bcsBytes)));
48
+ obligations.push(Obligation.fromBcs(phantom(lendingMarketType), fromBase64(((_a = rawObligation.data) === null || _a === void 0 ? void 0 : _a.bcs).bcsBytes)));
91
49
  }
92
50
  yield chunkHandler(obligations);
93
51
  })));
@@ -95,7 +53,7 @@ function fetchAllObligationsForMarketWithHandler(client, lendingMarketId, lendin
95
53
  yield Promise.all(promises);
96
54
  });
97
55
  }
98
- function fetchAllObligationsForMarket(client, lendingMarketId, lendingMarketType) {
56
+ export function fetchAllObligationsForMarket(client, lendingMarketId, lendingMarketType) {
99
57
  return __awaiter(this, void 0, void 0, function* () {
100
58
  var _a, _b;
101
59
  const rawLendingMarket = yield client.getObject({
@@ -125,14 +83,14 @@ function fetchAllObligationsForMarket(client, lendingMarketId, lendingMarketType
125
83
  const obligationObjects = yield chunkedMultiGet(client, fields.map((x) => x.objectId));
126
84
  const obligations = [];
127
85
  for (const rawObligation of obligationObjects) {
128
- obligations.push(structs_1.Obligation.fromBcs((0, reified_1.phantom)(lendingMarketType), (0, utils_1.fromBase64)(((_b = rawObligation.data) === null || _b === void 0 ? void 0 : _b.bcs).bcsBytes)));
86
+ obligations.push(Obligation.fromBcs(phantom(lendingMarketType), fromBase64(((_b = rawObligation.data) === null || _b === void 0 ? void 0 : _b.bcs).bcsBytes)));
129
87
  }
130
88
  return obligations;
131
89
  });
132
90
  }
133
91
  function chunkedMultiGet(client, objectIds) {
134
92
  return __awaiter(this, void 0, void 0, function* () {
135
- const limit = (0, p_limit_1.default)(30);
93
+ const limit = pLimit(30);
136
94
  const results = [];
137
95
  const chunks = splitIntoChunks(objectIds, 50);
138
96
  const promises = [];
@@ -163,7 +121,7 @@ function splitIntoChunks(arr, chunkSize) {
163
121
  }
164
122
  return result;
165
123
  }
166
- function getObligationHistoryPage(client, obligationId, maxQuantity, cursor) {
124
+ export function getObligationHistoryPage(client, obligationId, maxQuantity, cursor) {
167
125
  return __awaiter(this, void 0, void 0, function* () {
168
126
  var _a;
169
127
  if (maxQuantity > 50 || maxQuantity < 1) {
@@ -183,7 +141,7 @@ function getObligationHistoryPage(client, obligationId, maxQuantity, cursor) {
183
141
  });
184
142
  let formattedEvents = [];
185
143
  for (const data of payload.data) {
186
- const events = ((_a = data.events) === null || _a === void 0 ? void 0 : _a.filter((e) => e.packageId === suilend_1.PACKAGE_ID)) || [];
144
+ const events = ((_a = data.events) === null || _a === void 0 ? void 0 : _a.filter((e) => e.packageId === PACKAGE_ID)) || [];
187
145
  formattedEvents = formattedEvents.concat(formatEventsToHistory(obligationId, data, events));
188
146
  }
189
147
  if (payload.hasNextPage) {
@@ -307,9 +265,8 @@ function formatEventsToHistory(obligationId, data, events) {
307
265
  }
308
266
  return formattedEvents;
309
267
  }
310
- const getWeightedBorrowsUsd = (obligation) => {
268
+ export const getWeightedBorrowsUsd = (obligation) => {
311
269
  return obligation.maxPriceWeightedBorrowsUsd.gt(obligation.minPriceBorrowLimitUsd)
312
- ? bignumber_js_1.BigNumber.max(obligation.weightedBorrowsUsd, obligation.minPriceBorrowLimitUsd)
270
+ ? BigNumber.max(obligation.weightedBorrowsUsd, obligation.minPriceBorrowLimitUsd)
313
271
  : obligation.maxPriceWeightedBorrowsUsd;
314
272
  };
315
- exports.getWeightedBorrowsUsd = getWeightedBorrowsUsd;