@epicentral/sos-sdk 0.9.0-beta → 0.9.1-beta
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/accounts/fetchers.ts +1 -28
- package/index.ts +6 -0
- package/package.json +1 -1
- package/short/preflight.ts +4 -83
package/accounts/fetchers.ts
CHANGED
|
@@ -43,34 +43,7 @@ async function decodeAccount<T>(
|
|
|
43
43
|
): Promise<T | null> {
|
|
44
44
|
const data = await fetchRawAccount(rpc, address);
|
|
45
45
|
if (!data) return null;
|
|
46
|
-
|
|
47
|
-
return decoder.decode(data);
|
|
48
|
-
} catch (e) {
|
|
49
|
-
// #region agent log
|
|
50
|
-
try {
|
|
51
|
-
fetch("http://127.0.0.1:7586/ingest/4a07cb33-954d-4b27-b1a3-08f1423b9d05", {
|
|
52
|
-
method: "POST",
|
|
53
|
-
headers: { "Content-Type": "application/json", "X-Debug-Session-Id": "af65cf" },
|
|
54
|
-
body: JSON.stringify({
|
|
55
|
-
sessionId: "af65cf",
|
|
56
|
-
location: "sos-sdk/accounts/fetchers.ts:decodeAccount",
|
|
57
|
-
message: "decode_throw",
|
|
58
|
-
data: {
|
|
59
|
-
address: String(address),
|
|
60
|
-
dataLen: data.length,
|
|
61
|
-
firstDiscHex: Array.from(data.slice(0, 8))
|
|
62
|
-
.map((b) => b.toString(16).padStart(2, "0"))
|
|
63
|
-
.join(""),
|
|
64
|
-
err: (e as Error)?.message ?? String(e),
|
|
65
|
-
},
|
|
66
|
-
timestamp: Date.now(),
|
|
67
|
-
hypothesisId: "H2-i64-account-size-mismatch",
|
|
68
|
-
}),
|
|
69
|
-
}).catch(() => {});
|
|
70
|
-
} catch {}
|
|
71
|
-
// #endregion
|
|
72
|
-
throw e;
|
|
73
|
-
}
|
|
46
|
+
return decoder.decode(data);
|
|
74
47
|
}
|
|
75
48
|
|
|
76
49
|
export async function fetchOptionAccount(
|
package/index.ts
CHANGED
|
@@ -3,6 +3,12 @@ export * from "./client/types";
|
|
|
3
3
|
export * from "./client/lookup-table";
|
|
4
4
|
export { OptionType } from "./generated/types";
|
|
5
5
|
|
|
6
|
+
export type { OptionAccount } from "./generated/accounts/optionAccount";
|
|
7
|
+
export {
|
|
8
|
+
OptionProgramInstruction,
|
|
9
|
+
parseOptionProgramInstruction,
|
|
10
|
+
} from "./generated/programs/optionProgram";
|
|
11
|
+
|
|
6
12
|
export * from "./accounts/pdas";
|
|
7
13
|
export * from "./accounts/fetchers";
|
|
8
14
|
export * from "./accounts/list";
|
package/package.json
CHANGED
package/short/preflight.ts
CHANGED
|
@@ -266,82 +266,15 @@ export async function preflightUnwindWriterUnsold(
|
|
|
266
266
|
params.programId
|
|
267
267
|
);
|
|
268
268
|
|
|
269
|
-
// #region agent log
|
|
270
|
-
const __debugIngest = (stage: string, data: Record<string, unknown>) => {
|
|
271
|
-
try {
|
|
272
|
-
fetch("http://127.0.0.1:7586/ingest/4a07cb33-954d-4b27-b1a3-08f1423b9d05", {
|
|
273
|
-
method: "POST",
|
|
274
|
-
headers: { "Content-Type": "application/json", "X-Debug-Session-Id": "af65cf" },
|
|
275
|
-
body: JSON.stringify({
|
|
276
|
-
sessionId: "af65cf",
|
|
277
|
-
location: "sos-sdk/short/preflight.ts:preflightUnwindWriterUnsold",
|
|
278
|
-
message: stage,
|
|
279
|
-
data,
|
|
280
|
-
timestamp: Date.now(),
|
|
281
|
-
hypothesisId: "H2-i64-writerPosition-or-poolLoan-size",
|
|
282
|
-
}),
|
|
283
|
-
}).catch(() => {});
|
|
284
|
-
} catch {}
|
|
285
|
-
};
|
|
286
|
-
// #endregion
|
|
287
|
-
// #region agent log
|
|
288
|
-
__debugIngest("before_account_fetch", {
|
|
289
|
-
writerPositionAddress: String(writerPositionAddress),
|
|
290
|
-
collateralPool: String(resolved.collateralPool),
|
|
291
|
-
vaultPda: String(vaultPda),
|
|
292
|
-
writer: String(params.writer),
|
|
293
|
-
});
|
|
294
|
-
// #endregion
|
|
295
|
-
|
|
296
269
|
let writerPosition: Awaited<ReturnType<typeof fetchWriterPosition>> | null = null;
|
|
297
270
|
let collateralPool: Awaited<ReturnType<typeof fetchCollateralPool>> | null = null;
|
|
298
271
|
let vault: Awaited<ReturnType<typeof fetchVault>> | null = null;
|
|
299
272
|
let loans: Awaited<ReturnType<typeof fetchPoolLoansByMaker>> = [];
|
|
300
273
|
let currentSlot: bigint | number = 0n;
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
// #endregion
|
|
306
|
-
} catch (e) {
|
|
307
|
-
// #region agent log
|
|
308
|
-
__debugIngest("fetchWriterPosition_throw", {
|
|
309
|
-
err: (e as Error)?.message ?? String(e),
|
|
310
|
-
stack: String((e as Error)?.stack ?? "").slice(0, 600),
|
|
311
|
-
});
|
|
312
|
-
// #endregion
|
|
313
|
-
throw e;
|
|
314
|
-
}
|
|
315
|
-
try {
|
|
316
|
-
collateralPool = await fetchCollateralPool(params.rpc, resolved.collateralPool);
|
|
317
|
-
} catch (e) {
|
|
318
|
-
// #region agent log
|
|
319
|
-
__debugIngest("fetchCollateralPool_throw", { err: (e as Error)?.message ?? String(e) });
|
|
320
|
-
// #endregion
|
|
321
|
-
throw e;
|
|
322
|
-
}
|
|
323
|
-
try {
|
|
324
|
-
vault = await fetchVault(params.rpc, vaultPda);
|
|
325
|
-
} catch (e) {
|
|
326
|
-
// #region agent log
|
|
327
|
-
__debugIngest("fetchVault_throw", { err: (e as Error)?.message ?? String(e) });
|
|
328
|
-
// #endregion
|
|
329
|
-
throw e;
|
|
330
|
-
}
|
|
331
|
-
try {
|
|
332
|
-
loans = await fetchPoolLoansByMaker(params.rpc, params.writer);
|
|
333
|
-
// #region agent log
|
|
334
|
-
__debugIngest("fetchPoolLoansByMaker_ok", { count: loans.length });
|
|
335
|
-
// #endregion
|
|
336
|
-
} catch (e) {
|
|
337
|
-
// #region agent log
|
|
338
|
-
__debugIngest("fetchPoolLoansByMaker_throw", {
|
|
339
|
-
err: (e as Error)?.message ?? String(e),
|
|
340
|
-
stack: String((e as Error)?.stack ?? "").slice(0, 600),
|
|
341
|
-
});
|
|
342
|
-
// #endregion
|
|
343
|
-
throw e;
|
|
344
|
-
}
|
|
274
|
+
writerPosition = await fetchWriterPosition(params.rpc, writerPositionAddress);
|
|
275
|
+
collateralPool = await fetchCollateralPool(params.rpc, resolved.collateralPool);
|
|
276
|
+
vault = await fetchVault(params.rpc, vaultPda);
|
|
277
|
+
loans = await fetchPoolLoansByMaker(params.rpc, params.writer);
|
|
345
278
|
currentSlot = await params.rpc.getSlot().send();
|
|
346
279
|
|
|
347
280
|
invariant(!!writerPosition, "Writer position is required for unwind preflight.");
|
|
@@ -434,18 +367,6 @@ export async function preflightUnwindWriterUnsold(
|
|
|
434
367
|
: [];
|
|
435
368
|
|
|
436
369
|
if (includePoolLoansForRepay) {
|
|
437
|
-
// #region agent log
|
|
438
|
-
__debugIngest("loan_selection", {
|
|
439
|
-
activeLoanCount: writerPosition.activeLoanCount,
|
|
440
|
-
matchingLoansFound: matchingLoans.length,
|
|
441
|
-
selectedCount: positionLoans.length,
|
|
442
|
-
selectedNonces: positionLoans.map((l) => Number(l.data.nonce)),
|
|
443
|
-
selectedPrincipalSum: positionLoans
|
|
444
|
-
.reduce((s, l) => s + toBigInt(l.data.principal), 0n)
|
|
445
|
-
.toString(),
|
|
446
|
-
writerBorrowedPrincipal: toBigInt(writerPosition.borrowedPrincipal).toString(),
|
|
447
|
-
});
|
|
448
|
-
// #endregion
|
|
449
370
|
if (positionLoans.length !== writerPosition.activeLoanCount) {
|
|
450
371
|
return baseResult(
|
|
451
372
|
false,
|