@suilend/sdk 3.0.3 → 3.0.5

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 (68) hide show
  1. package/_generated/_dependencies/source/0x1/ascii/structs.js +4 -4
  2. package/_generated/_dependencies/source/0x1/option/structs.js +4 -4
  3. package/_generated/_dependencies/source/0x1/type-name/structs.js +4 -4
  4. package/_generated/_dependencies/source/0x2/bag/structs.js +4 -4
  5. package/_generated/_dependencies/source/0x2/balance/structs.js +3 -3
  6. package/_generated/_dependencies/source/0x2/object/structs.js +3 -3
  7. package/_generated/_dependencies/source/0x2/object-table/structs.js +4 -4
  8. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs.js +3 -3
  9. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs.js +4 -4
  10. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs.js +5 -5
  11. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.js +4 -4
  12. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs.js +5 -5
  13. package/_generated/_framework/reified.js +2 -2
  14. package/_generated/_framework/vector.js +2 -2
  15. package/_generated/suilend/cell/structs.js +4 -4
  16. package/_generated/suilend/decimal/structs.js +3 -3
  17. package/_generated/suilend/lending-market/functions.js +4 -4
  18. package/_generated/suilend/lending-market/structs.js +11 -11
  19. package/_generated/suilend/lending-market-registry/functions.js +2 -2
  20. package/_generated/suilend/liquidity-mining/structs.js +9 -9
  21. package/_generated/suilend/obligation/structs.js +8 -8
  22. package/_generated/suilend/rate-limiter/functions.js +2 -2
  23. package/_generated/suilend/rate-limiter/structs.js +4 -4
  24. package/_generated/suilend/reserve/structs.js +12 -12
  25. package/_generated/suilend/reserve-config/functions.js +2 -2
  26. package/_generated/suilend/reserve-config/structs.js +5 -5
  27. package/api/index.js +1 -1
  28. package/client.js +32 -50
  29. package/index.js +7 -7
  30. package/lib/index.js +5 -5
  31. package/lib/initialize.js +8 -8
  32. package/lib/liquidityMining.js +3 -3
  33. package/lib/pythAdapter.d.ts +1 -2
  34. package/lib/pythAdapter.js +96 -17
  35. package/lib/strategyOwnerCap.js +2 -2
  36. package/margin/margin/admin_cap.d.ts +1 -4
  37. package/margin/margin/admin_cap.js +15 -9
  38. package/margin/margin/deps/std/type_name.d.ts +9 -10
  39. package/margin/margin/deps/std/type_name.js +17 -14
  40. package/margin/margin/deps/sui/vec_set.d.ts +3 -5
  41. package/margin/margin/deps/sui/vec_set.js +9 -6
  42. package/margin/margin/deps/suilend/lending_market.d.ts +1 -4
  43. package/margin/margin/deps/suilend/lending_market.js +9 -6
  44. package/margin/margin/market.d.ts +22 -67
  45. package/margin/margin/market.js +86 -108
  46. package/margin/margin/permissions.d.ts +9 -16
  47. package/margin/margin/permissions.js +29 -29
  48. package/margin/margin/position.d.ts +12 -35
  49. package/margin/margin/position.js +84 -67
  50. package/margin/margin/router.d.ts +10 -50
  51. package/margin/margin/router.js +102 -71
  52. package/margin/margin/version.d.ts +1 -4
  53. package/margin/margin/version.js +7 -4
  54. package/margin/utils/index.d.ts +9 -9
  55. package/margin/utils/index.js +32 -29
  56. package/package.json +1 -1
  57. package/parsers/apiReserveAssetDataEvent.js +1 -1
  58. package/parsers/index.js +5 -5
  59. package/parsers/lendingMarket.js +2 -2
  60. package/parsers/obligation.js +1 -1
  61. package/parsers/rateLimiter.js +1 -1
  62. package/parsers/reserve.js +3 -3
  63. package/strategies.js +101 -42
  64. package/swap/index.js +2 -2
  65. package/swap/transaction.js +5 -14
  66. package/utils/index.js +3 -3
  67. package/utils/obligation.js +39 -30
  68. package/utils/simulate.js +4 -4
@@ -7,11 +7,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { normalizeSuiAddress } from "@mysten/sui/utils";
10
11
  import { BigNumber } from "bignumber.js";
11
12
  import pLimit from "p-limit";
12
- import { phantom } from "../_generated/_framework/reified";
13
- import { PACKAGE_ID } from "../_generated/suilend";
14
- import { Obligation } from "../_generated/suilend/obligation/structs";
13
+ import { phantom } from "../_generated/_framework/reified.js";
14
+ import { PACKAGE_ID } from "../_generated/suilend/index.js";
15
+ import { Obligation } from "../_generated/suilend/obligation/structs.js";
16
+ const NORMALIZED_PACKAGE_ID = normalizeSuiAddress(PACKAGE_ID);
15
17
  export function fetchAllObligationsForMarketWithHandler(suiGrpcClient, lendingMarketId, lendingMarketType, chunkHandler) {
16
18
  return __awaiter(this, void 0, void 0, function* () {
17
19
  const limit = pLimit(30);
@@ -20,7 +22,7 @@ export function fetchAllObligationsForMarketWithHandler(suiGrpcClient, lendingMa
20
22
  include: { json: true },
21
23
  });
22
24
  const obligationField = rawLendingMarket.json.obligations;
23
- const obligationOwnerID = obligationField.id.id;
25
+ const obligationOwnerID = obligationField.id;
24
26
  let hasNextPage = true;
25
27
  let cursor = null;
26
28
  const promises = [];
@@ -32,7 +34,9 @@ export function fetchAllObligationsForMarketWithHandler(suiGrpcClient, lendingMa
32
34
  hasNextPage = response.hasNextPage;
33
35
  cursor = response.cursor;
34
36
  promises.push(limit(() => __awaiter(this, void 0, void 0, function* () {
35
- const obligationObjects = yield chunkedMultiGet(suiGrpcClient, response.dynamicFields.map((x) => x.fieldId));
37
+ const obligationObjects = yield chunkedMultiGet(suiGrpcClient, response.dynamicFields
38
+ .filter((x) => x.$kind === "DynamicObject")
39
+ .map((x) => x.childId));
36
40
  const obligations = [];
37
41
  for (const rawObligation of obligationObjects) {
38
42
  if (rawObligation instanceof Error)
@@ -52,7 +56,7 @@ export function fetchAllObligationsForMarket(suiGrpcClient, lendingMarketId, len
52
56
  include: { json: true },
53
57
  });
54
58
  const obligationField = rawLendingMarket.json.obligations;
55
- const obligationOwnerID = obligationField.id.id;
59
+ const obligationOwnerID = obligationField.id;
56
60
  let hasNextPage = true;
57
61
  let cursor = null;
58
62
  let fields = [];
@@ -65,7 +69,7 @@ export function fetchAllObligationsForMarket(suiGrpcClient, lendingMarketId, len
65
69
  hasNextPage = response.hasNextPage;
66
70
  cursor = response.cursor;
67
71
  }
68
- const obligationObjects = yield chunkedMultiGet(suiGrpcClient, fields.map((x) => x.fieldId));
72
+ const obligationObjects = yield chunkedMultiGet(suiGrpcClient, fields.filter((x) => x.$kind === "DynamicObject").map((x) => x.childId));
69
73
  const obligations = [];
70
74
  for (const rawObligation of obligationObjects) {
71
75
  if (rawObligation instanceof Error)
@@ -112,10 +116,10 @@ export function getObligationHistoryPage(suiGraphQLClient, obligationId, maxQuan
112
116
  const result = yield suiGraphQLClient.query({
113
117
  query: `
114
118
  query QueryObligationTransactions($objectId: SuiAddress!, $first: Int, $after: String) {
115
- transactionBlocks(
119
+ transactions(
116
120
  first: $first
117
121
  after: $after
118
- filter: { changedObject: $objectId }
122
+ filter: { affectedObject: $objectId }
119
123
  ) {
120
124
  pageInfo {
121
125
  hasNextPage
@@ -127,12 +131,14 @@ export function getObligationHistoryPage(suiGraphQLClient, obligationId, maxQuan
127
131
  timestamp
128
132
  events(first: 50) {
129
133
  nodes {
130
- sendingModule {
134
+ transactionModule {
131
135
  package { address }
132
136
  name
133
137
  }
134
- type { repr }
135
- json
138
+ contents {
139
+ type { repr }
140
+ json
141
+ }
136
142
  }
137
143
  }
138
144
  }
@@ -146,13 +152,17 @@ export function getObligationHistoryPage(suiGraphQLClient, obligationId, maxQuan
146
152
  after: cursor,
147
153
  },
148
154
  });
149
- const payload = (_a = result.data) === null || _a === void 0 ? void 0 : _a.transactionBlocks;
155
+ const payload = (_a = result.data) === null || _a === void 0 ? void 0 : _a.transactions;
150
156
  if (!payload) {
151
157
  return { cursor: null, history: [] };
152
158
  }
153
159
  let formattedEvents = [];
154
160
  for (const txNode of payload.nodes) {
155
- const events = txNode.effects.events.nodes.filter((e) => { var _a, _b; return ((_b = (_a = e.sendingModule) === null || _a === void 0 ? void 0 : _a.package) === null || _b === void 0 ? void 0 : _b.address) === PACKAGE_ID; });
161
+ const events = txNode.effects.events.nodes.filter((e) => {
162
+ var _a, _b;
163
+ return ((_a = e.contents) === null || _a === void 0 ? void 0 : _a.type.repr.startsWith(`${PACKAGE_ID}::`)) ||
164
+ ((_b = e.contents) === null || _b === void 0 ? void 0 : _b.type.repr.startsWith(`${NORMALIZED_PACKAGE_ID}::`));
165
+ });
156
166
  formattedEvents = formattedEvents.concat(formatEventsToHistory(obligationId, txNode, events));
157
167
  }
158
168
  return {
@@ -168,25 +178,25 @@ function formatEventsToHistory(obligationId, txNode, events) {
168
178
  ? new Date(txNode.effects.timestamp).getTime()
169
179
  : 0;
170
180
  for (const event of events) {
171
- const eventType = (_a = event.type.repr.split("::").pop()) !== null && _a !== void 0 ? _a : "";
172
- const params = event.json;
181
+ if (!event.contents)
182
+ continue;
183
+ const eventType = (_a = event.contents.type.repr.split("::").pop()) !== null && _a !== void 0 ? _a : "";
184
+ const params = event.contents.json;
173
185
  if (eventType === "DepositEvent") {
174
186
  if ((params === null || params === void 0 ? void 0 : params.obligation_id) !== obligationId) {
175
187
  continue;
176
188
  }
177
- // Find the corresponding mint event
178
189
  const matchingEvent = events.find((e) => {
179
- var _a;
180
- return (e.type.repr.includes("MintEvent") &&
181
- ((_a = e.json) === null || _a === void 0 ? void 0 : _a.ctoken_amount) === params.ctoken_amount);
190
+ var _a, _b, _c;
191
+ return (((_a = e.contents) === null || _a === void 0 ? void 0 : _a.type.repr.includes("MintEvent")) &&
192
+ ((_c = (_b = e.contents) === null || _b === void 0 ? void 0 : _b.json) === null || _c === void 0 ? void 0 : _c.ctoken_amount) === params.ctoken_amount);
182
193
  });
183
- if (!matchingEvent) {
184
- // TODO: Handle case with solo Mint or solo Deposit
194
+ if (!(matchingEvent === null || matchingEvent === void 0 ? void 0 : matchingEvent.contents)) {
185
195
  continue;
186
196
  }
187
197
  formattedEvents.push({
188
198
  reserveId: params.reserve_id,
189
- quantity: parseInt(matchingEvent.json.liquidity_amount),
199
+ quantity: parseInt(matchingEvent.contents.json.liquidity_amount),
190
200
  action: "Deposit",
191
201
  timestampMs,
192
202
  digest: txNode.digest,
@@ -196,18 +206,17 @@ function formatEventsToHistory(obligationId, txNode, events) {
196
206
  if ((params === null || params === void 0 ? void 0 : params.obligation_id) !== obligationId) {
197
207
  continue;
198
208
  }
199
- // Find the corresponding mint event
200
209
  const matchingEvent = events.find((e) => {
201
- var _a;
202
- return (e.type.repr.includes("RedeemEvent") &&
203
- ((_a = e.json) === null || _a === void 0 ? void 0 : _a.ctoken_amount) === params.ctoken_amount);
210
+ var _a, _b, _c;
211
+ return (((_a = e.contents) === null || _a === void 0 ? void 0 : _a.type.repr.includes("RedeemEvent")) &&
212
+ ((_c = (_b = e.contents) === null || _b === void 0 ? void 0 : _b.json) === null || _c === void 0 ? void 0 : _c.ctoken_amount) === params.ctoken_amount);
204
213
  });
205
- if (!matchingEvent) {
214
+ if (!(matchingEvent === null || matchingEvent === void 0 ? void 0 : matchingEvent.contents)) {
206
215
  continue;
207
216
  }
208
217
  formattedEvents.push({
209
- reserveId: matchingEvent.json.reserve_id,
210
- quantity: parseInt(matchingEvent.json.liquidity_amount),
218
+ reserveId: matchingEvent.contents.json.reserve_id,
219
+ quantity: parseInt(matchingEvent.contents.json.liquidity_amount),
211
220
  action: "Withdraw",
212
221
  timestampMs,
213
222
  digest: txNode.digest,
package/utils/simulate.js CHANGED
@@ -11,10 +11,10 @@ import { bcs } from "@mysten/sui/bcs";
11
11
  import { toHex } from "@mysten/sui/utils";
12
12
  import BigNumber from "bignumber.js";
13
13
  import { v4 as uuidv4 } from "uuid";
14
- import { Decimal } from "../_generated/suilend/decimal/structs";
15
- import { UserReward, } from "../_generated/suilend/liquidity-mining/structs";
16
- import { WAD } from "../lib/constants";
17
- import { linearlyInterpolate } from "../utils";
14
+ import { Decimal } from "../_generated/suilend/decimal/structs.js";
15
+ import { UserReward, } from "../_generated/suilend/liquidity-mining/structs.js";
16
+ import { WAD } from "../lib/constants.js";
17
+ import { linearlyInterpolate } from "../utils/index.js";
18
18
  /**
19
19
  * @deprecated since version 1.0.8. Use `calculateUtilizationPercent` instead.
20
20
  */