@suilend/sdk 3.0.3 → 3.0.4
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/client.js +19 -37
- package/lib/initialize.js +2 -2
- package/lib/pythAdapter.d.ts +1 -2
- package/lib/pythAdapter.js +72 -16
- package/margin/margin/admin_cap.d.ts +1 -4
- package/margin/margin/admin_cap.js +15 -9
- package/margin/margin/deps/std/type_name.d.ts +9 -10
- package/margin/margin/deps/std/type_name.js +17 -14
- package/margin/margin/deps/sui/vec_set.d.ts +3 -5
- package/margin/margin/deps/sui/vec_set.js +9 -6
- package/margin/margin/deps/suilend/lending_market.d.ts +1 -4
- package/margin/margin/deps/suilend/lending_market.js +9 -6
- package/margin/margin/market.d.ts +22 -67
- package/margin/margin/market.js +86 -108
- package/margin/margin/permissions.d.ts +9 -16
- package/margin/margin/permissions.js +29 -29
- package/margin/margin/position.d.ts +12 -35
- package/margin/margin/position.js +84 -67
- package/margin/margin/router.d.ts +10 -50
- package/margin/margin/router.js +102 -71
- package/margin/margin/version.d.ts +1 -4
- package/margin/margin/version.js +7 -4
- package/margin/utils/index.d.ts +9 -9
- package/margin/utils/index.js +32 -29
- package/package.json +1 -1
- package/strategies.js +95 -36
- package/swap/transaction.js +4 -13
- package/utils/obligation.js +36 -27
package/utils/obligation.js
CHANGED
|
@@ -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
13
|
import { phantom } from "../_generated/_framework/reified";
|
|
13
14
|
import { PACKAGE_ID } from "../_generated/suilend";
|
|
14
15
|
import { Obligation } from "../_generated/suilend/obligation/structs";
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
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
|
-
|
|
119
|
+
transactions(
|
|
116
120
|
first: $first
|
|
117
121
|
after: $after
|
|
118
|
-
filter: {
|
|
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
|
-
|
|
134
|
+
transactionModule {
|
|
131
135
|
package { address }
|
|
132
136
|
name
|
|
133
137
|
}
|
|
134
|
-
|
|
135
|
-
|
|
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.
|
|
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) => {
|
|
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
|
-
|
|
172
|
-
|
|
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
|
-
((
|
|
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
|
-
((
|
|
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,
|