@trusset/sdk 0.1.0 → 0.5.0
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/README.md +175 -171
- package/dist/base-BYEauvBZ.d.mts +111 -0
- package/dist/base-zODt0Kf5.d.ts +111 -0
- package/dist/chunk-2KHUPARH.js +2260 -0
- package/dist/chunk-3YF42MHV.mjs +678 -0
- package/dist/chunk-4MNJZAXE.mjs +2260 -0
- package/dist/chunk-7HFMHYRA.js +107 -0
- package/dist/chunk-ACXAKW5E.js +916 -0
- package/dist/chunk-AI4ZNJLR.js +678 -0
- package/dist/chunk-C7CANC53.mjs +208 -0
- package/dist/chunk-DQCX2GYT.mjs +107 -0
- package/dist/chunk-GWMT6UU7.js +208 -0
- package/dist/chunk-OQG3PEF3.mjs +916 -0
- package/dist/flow-Cz8A09rn.d.mts +171 -0
- package/dist/flow-Cz8A09rn.d.ts +171 -0
- package/dist/index-DKUSzkBN.d.ts +956 -0
- package/dist/index-Dl4U8vUM.d.mts +956 -0
- package/dist/index.d.mts +39 -448
- package/dist/index.d.ts +39 -448
- package/dist/index.js +264 -534
- package/dist/index.mjs +249 -483
- package/dist/modules/customers/index.d.mts +2 -0
- package/dist/modules/customers/index.d.ts +2 -0
- package/dist/modules/customers/index.js +17 -0
- package/dist/modules/customers/index.mjs +17 -0
- package/dist/modules/lending/index.d.mts +6768 -0
- package/dist/modules/lending/index.d.ts +6768 -0
- package/dist/modules/lending/index.js +44 -0
- package/dist/modules/lending/index.mjs +44 -0
- package/dist/modules/tokens/index.d.mts +476 -0
- package/dist/modules/tokens/index.d.ts +476 -0
- package/dist/modules/tokens/index.js +8 -0
- package/dist/modules/tokens/index.mjs +8 -0
- package/package.json +71 -35
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _chunkAI4ZNJLRjs = require('./chunk-AI4ZNJLR.js');
|
|
16
|
+
|
|
17
|
+
// src/modules/lending/base.ts
|
|
18
|
+
var LENDING_BASE = "/lending-external-securities-v2/api";
|
|
19
|
+
var WRITE_TIMEOUT_MS = 6e4;
|
|
20
|
+
var DOCUMENT_TIMEOUT_MS = 12e4;
|
|
21
|
+
var BUILD = { timeoutMs: WRITE_TIMEOUT_MS };
|
|
22
|
+
var CONFIRM = { timeoutMs: WRITE_TIMEOUT_MS, retry: "confirm" };
|
|
23
|
+
var CONFIRM_ONCE = { timeoutMs: WRITE_TIMEOUT_MS, retry: "write" };
|
|
24
|
+
var LendingContext = class extends _chunkAI4ZNJLRjs.InstanceChain {
|
|
25
|
+
};
|
|
26
|
+
var LendingArea = class {
|
|
27
|
+
constructor(ctx) {
|
|
28
|
+
this.ctx = ctx;
|
|
29
|
+
}
|
|
30
|
+
get http() {
|
|
31
|
+
return this.ctx.http;
|
|
32
|
+
}
|
|
33
|
+
async twoLeg(options, spec) {
|
|
34
|
+
if (options === void 0) return spec.build();
|
|
35
|
+
if (_chunkAI4ZNJLRjs.isConfirmOptions.call(void 0, options)) return spec.confirm(_chunkAI4ZNJLRjs.confirmHashOf.call(void 0, options), null);
|
|
36
|
+
if (!_chunkAI4ZNJLRjs.isSignOptions.call(void 0, options)) {
|
|
37
|
+
throw new (0, _chunkAI4ZNJLRjs.ValidationError)("Pass { signer } to sign and confirm, or { txHash } to confirm a transaction you broadcast yourself");
|
|
38
|
+
}
|
|
39
|
+
await _chunkAI4ZNJLRjs.preflightChain.call(void 0, this.ctx, options);
|
|
40
|
+
const prepared = await spec.build();
|
|
41
|
+
const plan = _chunkAI4ZNJLRjs.planOf.call(void 0, prepared, spec.plan);
|
|
42
|
+
if (!plan) return _chunkAI4ZNJLRjs.attachTransactions.call(void 0, prepared, []);
|
|
43
|
+
if (spec.check) await spec.check(prepared, await _chunkAI4ZNJLRjs.signerAddress.call(void 0, _chunkAI4ZNJLRjs.requireSigner.call(void 0, options.signer)));
|
|
44
|
+
const executed = await _chunkAI4ZNJLRjs.execute.call(void 0, this.ctx, plan, options);
|
|
45
|
+
return _chunkAI4ZNJLRjs.confirmExecuted.call(void 0, executed, (hash) => spec.confirm(hash, prepared));
|
|
46
|
+
}
|
|
47
|
+
async oneLeg(options, build, plan) {
|
|
48
|
+
if (options === void 0) return build();
|
|
49
|
+
if (_chunkAI4ZNJLRjs.isConfirmOptions.call(void 0, options)) {
|
|
50
|
+
throw new (0, _chunkAI4ZNJLRjs.ValidationError)("This route has no confirm leg: the chain state it changes is read back from the chain on the next read");
|
|
51
|
+
}
|
|
52
|
+
if (!_chunkAI4ZNJLRjs.isSignOptions.call(void 0, options)) {
|
|
53
|
+
throw new (0, _chunkAI4ZNJLRjs.ValidationError)("Pass { signer } to sign, or no options to get the unsigned transaction");
|
|
54
|
+
}
|
|
55
|
+
await _chunkAI4ZNJLRjs.preflightChain.call(void 0, this.ctx, options);
|
|
56
|
+
const prepared = await build();
|
|
57
|
+
const resolved = _chunkAI4ZNJLRjs.planOf.call(void 0, prepared, { ...plan, confirmIndex: null });
|
|
58
|
+
if (!resolved) return { transactions: [] };
|
|
59
|
+
const executed = await _chunkAI4ZNJLRjs.execute.call(void 0, this.ctx, resolved, options);
|
|
60
|
+
return { transactions: executed.transactions };
|
|
61
|
+
}
|
|
62
|
+
async assertSignerRoles(marketId, address, roles) {
|
|
63
|
+
for (const role of roles) {
|
|
64
|
+
const status = await this.http.get(`${LENDING_BASE}/markets/${enc(marketId)}/access-role/${address}`, { role });
|
|
65
|
+
if (status.failed || typeof status.granted !== "boolean") {
|
|
66
|
+
throw new (0, _chunkAI4ZNJLRjs.TrussetError)(`Whether ${address} holds ${role} on this market could not be read just now, so nothing was signed. Retry shortly`, "ROLE_UNREADABLE", 503);
|
|
67
|
+
}
|
|
68
|
+
if (!status.granted) {
|
|
69
|
+
throw new (0, _chunkAI4ZNJLRjs.ValidationError)(`${address} does not hold ${role} on this market, and a step of this plan needs it. Prepare without a signer and sign that step from the wallet that holds ${role}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async assertSignerHoldsAny(marketId, address, roles) {
|
|
74
|
+
let unreadable = false;
|
|
75
|
+
for (const role of roles) {
|
|
76
|
+
const status = await this.http.get(`${LENDING_BASE}/markets/${enc(marketId)}/access-role/${address}`, { role });
|
|
77
|
+
if (status.granted === true) return;
|
|
78
|
+
if (status.failed || typeof status.granted !== "boolean") unreadable = true;
|
|
79
|
+
}
|
|
80
|
+
if (unreadable) {
|
|
81
|
+
throw new (0, _chunkAI4ZNJLRjs.TrussetError)(`Whether ${address} holds ${roles.join(" or ")} on this market could not be read just now, so nothing was signed. Retry shortly`, "ROLE_UNREADABLE", 503);
|
|
82
|
+
}
|
|
83
|
+
throw new (0, _chunkAI4ZNJLRjs.ValidationError)(`${address} holds none of ${roles.join(", ")} on this market, and this transaction needs one. Prepare without a signer and sign from the wallet that holds it`);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
function enc(value) {
|
|
87
|
+
return encodeURIComponent(value);
|
|
88
|
+
}
|
|
89
|
+
function compact(body) {
|
|
90
|
+
const out = {};
|
|
91
|
+
for (const [k, v] of Object.entries(body)) {
|
|
92
|
+
if (v !== void 0) out[k] = v;
|
|
93
|
+
}
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
exports.LENDING_BASE = LENDING_BASE; exports.DOCUMENT_TIMEOUT_MS = DOCUMENT_TIMEOUT_MS; exports.BUILD = BUILD; exports.CONFIRM = CONFIRM; exports.CONFIRM_ONCE = CONFIRM_ONCE; exports.LendingContext = LendingContext; exports.LendingArea = LendingArea; exports.enc = enc; exports.compact = compact;
|