@suilend/sdk 12.7.0 → 13.0.0-next.g803bba0
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/_generated/_dependencies/pyth-2/price-identifier/structs.d.ts +46 -0
- package/_generated/_dependencies/{source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e → pyth-2}/price-identifier/structs.js +45 -25
- package/_generated/_dependencies/std/ascii/structs.d.ts +100 -0
- package/_generated/_dependencies/{source/0x1 → std}/ascii/structs.js +153 -103
- package/_generated/_dependencies/{source/0x1 → std}/option/structs.d.ts +29 -21
- package/_generated/_dependencies/std/option/structs.js +155 -0
- package/_generated/_dependencies/std/type-name/structs.d.ts +65 -0
- package/_generated/_dependencies/{source/0x1 → std}/type-name/structs.js +49 -22
- package/_generated/_dependencies/sui/bag/structs.d.ts +75 -0
- package/_generated/_dependencies/sui/bag/structs.js +154 -0
- package/_generated/_dependencies/{source/0x2 → sui}/balance/structs.d.ts +80 -60
- package/_generated/_dependencies/sui/balance/structs.js +306 -0
- package/_generated/_dependencies/sui/object/structs.d.ts +104 -0
- package/_generated/_dependencies/{source/0x2 → sui}/object/structs.js +98 -46
- package/_generated/_dependencies/{source/0x2 → sui}/object-table/structs.d.ts +37 -30
- package/_generated/_dependencies/sui/object-table/structs.js +164 -0
- package/_generated/_envs/index.d.ts +3 -0
- package/_generated/_envs/index.js +18 -0
- package/_generated/_envs/mainnet.d.ts +2 -0
- package/_generated/_envs/mainnet.js +490 -0
- package/_generated/_framework/env.d.ts +137 -0
- package/_generated/_framework/env.js +261 -0
- package/_generated/_framework/reified.d.ts +68 -36
- package/_generated/_framework/reified.js +110 -98
- package/_generated/_framework/util.d.ts +4 -4
- package/_generated/_framework/util.js +82 -79
- package/_generated/_framework/vector.d.ts +11 -9
- package/_generated/_framework/vector.js +10 -10
- package/_generated/suilend/cell/structs.d.ts +24 -22
- package/_generated/suilend/cell/structs.js +68 -24
- package/_generated/suilend/decimal/structs.d.ts +28 -24
- package/_generated/suilend/decimal/structs.js +45 -24
- package/_generated/suilend/index.d.ts +5 -6
- package/_generated/suilend/index.js +10 -19
- package/_generated/suilend/lending-market/functions.d.ts +1123 -149
- package/_generated/suilend/lending-market/functions.js +1121 -207
- package/_generated/suilend/lending-market/structs.d.ts +985 -1290
- package/_generated/suilend/lending-market/structs.js +2482 -1282
- package/_generated/suilend/lending-market-registry/functions.d.ts +32 -3
- package/_generated/suilend/lending-market-registry/functions.js +30 -6
- package/_generated/suilend/liquidity-mining/structs.d.ts +200 -333
- package/_generated/suilend/liquidity-mining/structs.js +449 -319
- package/_generated/suilend/obligation/structs.d.ts +406 -918
- package/_generated/suilend/obligation/structs.js +786 -596
- package/_generated/suilend/rate-limiter/functions.d.ts +134 -15
- package/_generated/suilend/rate-limiter/functions.js +139 -21
- package/_generated/suilend/rate-limiter/structs.d.ts +72 -80
- package/_generated/suilend/rate-limiter/structs.js +98 -48
- package/_generated/suilend/reserve/structs.d.ts +611 -904
- package/_generated/suilend/reserve/structs.js +1528 -736
- package/_generated/suilend/reserve-config/functions.d.ts +718 -96
- package/_generated/suilend/reserve-config/functions.js +751 -157
- package/_generated/suilend/reserve-config/structs.d.ts +148 -163
- package/_generated/suilend/reserve-config/structs.js +260 -94
- package/client.d.ts +2 -2
- package/client.js +22 -39
- package/lib/initialize.d.ts +76 -76
- package/lib/initialize.js +10 -10
- package/lib/proCompatible.js +5 -5
- package/package.json +1 -1
- package/parsers/lendingMarket.d.ts +9 -9
- package/parsers/obligation.d.ts +14 -14
- package/parsers/obligation.js +4 -4
- package/parsers/rateLimiter.d.ts +1 -1
- package/parsers/reserve.d.ts +12 -12
- package/parsers/reserve.js +2 -2
- package/strategies.d.ts +14 -14
- package/utils/simulate.d.ts +1 -1
- package/utils/simulate.js +5 -5
- package/_generated/_dependencies/source/0x1/ascii/structs.d.ts +0 -84
- package/_generated/_dependencies/source/0x1/index.d.ts +0 -3
- package/_generated/_dependencies/source/0x1/index.js +0 -3
- package/_generated/_dependencies/source/0x1/option/structs.js +0 -110
- package/_generated/_dependencies/source/0x1/type-name/structs.d.ts +0 -47
- package/_generated/_dependencies/source/0x2/bag/structs.d.ts +0 -52
- package/_generated/_dependencies/source/0x2/bag/structs.js +0 -113
- package/_generated/_dependencies/source/0x2/balance/structs.js +0 -210
- package/_generated/_dependencies/source/0x2/index.d.ts +0 -3
- package/_generated/_dependencies/source/0x2/index.js +0 -3
- package/_generated/_dependencies/source/0x2/object/structs.d.ts +0 -82
- package/_generated/_dependencies/source/0x2/object-table/structs.js +0 -115
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/index.d.ts +0 -4
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/index.js +0 -4
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.d.ts +0 -46
|
@@ -1,293 +1,294 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export function isBorrow(type) {
|
|
1
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
2
|
+
import { fromHex, toHex } from '@mysten/sui/utils';
|
|
3
|
+
import { TypeName } from '../../_dependencies/std/type-name/structs.js';
|
|
4
|
+
import { ID, UID } from '../../_dependencies/sui/object/structs.js';
|
|
5
|
+
import { getTypeOrigin } from '../../_envs/index.js';
|
|
6
|
+
import { assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, fieldToJSON, phantom, vector, } from '../../_framework/reified.js';
|
|
7
|
+
import { composeSuiType, compressSuiType, parseTypeName, } from '../../_framework/util.js';
|
|
8
|
+
import { Decimal } from '../decimal/structs.js';
|
|
9
|
+
import { UserRewardManager } from '../liquidity-mining/structs.js';
|
|
10
|
+
/* ============================== Obligation =============================== */
|
|
11
|
+
export function isObligation(type) {
|
|
13
12
|
type = compressSuiType(type);
|
|
14
|
-
return type
|
|
13
|
+
return type.startsWith(`${getTypeOrigin('suilend', 'obligation::Obligation')}::obligation::Obligation` + '<');
|
|
15
14
|
}
|
|
16
|
-
export class
|
|
15
|
+
export class Obligation {
|
|
17
16
|
__StructClass = true;
|
|
18
|
-
static $typeName
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
$
|
|
17
|
+
static get $typeName() {
|
|
18
|
+
return `${getTypeOrigin('suilend', 'obligation::Obligation')}::obligation::Obligation`;
|
|
19
|
+
}
|
|
20
|
+
static $numTypeParams = 1;
|
|
21
|
+
static $isPhantom = [true];
|
|
22
|
+
$typeName = Obligation.$typeName;
|
|
22
23
|
$fullTypeName;
|
|
23
24
|
$typeArgs;
|
|
24
|
-
$isPhantom =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
$isPhantom = Obligation.$isPhantom;
|
|
26
|
+
id;
|
|
27
|
+
lendingMarketId;
|
|
28
|
+
/**
|
|
29
|
+
* all deposits in the obligation. there is at most one deposit per coin type
|
|
30
|
+
* There should never be a deposit object with a zeroed amount
|
|
31
|
+
*/
|
|
32
|
+
deposits;
|
|
33
|
+
/**
|
|
34
|
+
* all borrows in the obligation. there is at most one deposit per coin type
|
|
35
|
+
* There should never be a borrow object with a zeroed amount
|
|
36
|
+
*/
|
|
37
|
+
borrows;
|
|
38
|
+
/** value of all deposits in USD */
|
|
39
|
+
depositedValueUsd;
|
|
40
|
+
/**
|
|
41
|
+
* sum(deposit value * open ltv) for all deposits.
|
|
42
|
+
* if weighted_borrowed_value_usd > allowed_borrow_value_usd,
|
|
43
|
+
* the obligation is not healthy
|
|
44
|
+
*/
|
|
45
|
+
allowedBorrowValueUsd;
|
|
46
|
+
/**
|
|
47
|
+
* sum(deposit value * close ltv) for all deposits
|
|
48
|
+
* if weighted_borrowed_value_usd > unhealthy_borrow_value_usd,
|
|
49
|
+
* the obligation is unhealthy and can be liquidated
|
|
50
|
+
*/
|
|
51
|
+
unhealthyBorrowValueUsd;
|
|
52
|
+
superUnhealthyBorrowValueUsd;
|
|
53
|
+
/** value of all borrows in USD */
|
|
54
|
+
unweightedBorrowedValueUsd;
|
|
55
|
+
/** weighted value of all borrows in USD. used when checking if an obligation is liquidatable */
|
|
56
|
+
weightedBorrowedValueUsd;
|
|
57
|
+
/**
|
|
58
|
+
* weighted value of all borrows in USD, but using the upper bound of the market value
|
|
59
|
+
* used to limit borrows and withdraws
|
|
60
|
+
*/
|
|
61
|
+
weightedBorrowedValueUpperBoundUsd;
|
|
62
|
+
borrowingIsolatedAsset;
|
|
63
|
+
userRewardManagers;
|
|
64
|
+
/** unused */
|
|
65
|
+
badDebtUsd;
|
|
66
|
+
/** unused */
|
|
67
|
+
closable;
|
|
31
68
|
constructor(typeArgs, fields) {
|
|
32
|
-
this.$fullTypeName = composeSuiType(
|
|
69
|
+
this.$fullTypeName = composeSuiType(Obligation.$typeName, ...typeArgs);
|
|
33
70
|
this.$typeArgs = typeArgs;
|
|
34
|
-
this.
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
37
|
-
this.
|
|
38
|
-
this.
|
|
39
|
-
this.
|
|
71
|
+
this.id = fields.id;
|
|
72
|
+
this.lendingMarketId = fields.lendingMarketId;
|
|
73
|
+
this.deposits = fields.deposits;
|
|
74
|
+
this.borrows = fields.borrows;
|
|
75
|
+
this.depositedValueUsd = fields.depositedValueUsd;
|
|
76
|
+
this.allowedBorrowValueUsd = fields.allowedBorrowValueUsd;
|
|
77
|
+
this.unhealthyBorrowValueUsd = fields.unhealthyBorrowValueUsd;
|
|
78
|
+
this.superUnhealthyBorrowValueUsd = fields.superUnhealthyBorrowValueUsd;
|
|
79
|
+
this.unweightedBorrowedValueUsd = fields.unweightedBorrowedValueUsd;
|
|
80
|
+
this.weightedBorrowedValueUsd = fields.weightedBorrowedValueUsd;
|
|
81
|
+
this.weightedBorrowedValueUpperBoundUsd = fields.weightedBorrowedValueUpperBoundUsd;
|
|
82
|
+
this.borrowingIsolatedAsset = fields.borrowingIsolatedAsset;
|
|
83
|
+
this.userRewardManagers = fields.userRewardManagers;
|
|
84
|
+
this.badDebtUsd = fields.badDebtUsd;
|
|
85
|
+
this.closable = fields.closable;
|
|
40
86
|
}
|
|
41
|
-
static reified() {
|
|
87
|
+
static reified(P) {
|
|
88
|
+
const reifiedBcs = Obligation.bcs;
|
|
42
89
|
return {
|
|
43
|
-
typeName
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
90
|
+
get typeName() {
|
|
91
|
+
return Obligation.$typeName;
|
|
92
|
+
},
|
|
93
|
+
get fullTypeName() {
|
|
94
|
+
return composeSuiType(Obligation.$typeName, ...[extractType(P)]);
|
|
95
|
+
},
|
|
96
|
+
get typeArgs() {
|
|
97
|
+
return [extractType(P)];
|
|
98
|
+
},
|
|
99
|
+
isPhantom: Obligation.$isPhantom,
|
|
100
|
+
reifiedTypeArgs: [P],
|
|
101
|
+
fromFields: (fields) => Obligation.fromFields(P, fields),
|
|
102
|
+
fromFieldsWithTypes: (item) => Obligation.fromFieldsWithTypes(P, item),
|
|
103
|
+
fromBcs: (data) => Obligation.fromFields(P, reifiedBcs.parse(data)),
|
|
104
|
+
bcs: reifiedBcs,
|
|
105
|
+
fromJSONField: (field) => Obligation.fromJSONField(P, field),
|
|
106
|
+
fromJSON: (json) => Obligation.fromJSON(P, json),
|
|
107
|
+
fromCoreObject: (obj) => Obligation.fromCoreObject(P, obj),
|
|
108
|
+
fetch: async (client, id) => Obligation.fetch(client, P, id),
|
|
55
109
|
new: (fields) => {
|
|
56
|
-
return new
|
|
110
|
+
return new Obligation([extractType(P)], fields);
|
|
57
111
|
},
|
|
58
|
-
kind:
|
|
112
|
+
kind: 'StructClassReified',
|
|
59
113
|
};
|
|
60
114
|
}
|
|
61
115
|
static get r() {
|
|
62
|
-
return
|
|
116
|
+
return Obligation.reified;
|
|
63
117
|
}
|
|
64
|
-
static phantom() {
|
|
65
|
-
return phantom(
|
|
118
|
+
static phantom(P) {
|
|
119
|
+
return phantom(Obligation.reified(P));
|
|
66
120
|
}
|
|
67
121
|
static get p() {
|
|
68
|
-
return
|
|
122
|
+
return Obligation.phantom;
|
|
69
123
|
}
|
|
70
|
-
static
|
|
71
|
-
return bcs.struct(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
124
|
+
static instantiateBcs() {
|
|
125
|
+
return bcs.struct('Obligation', {
|
|
126
|
+
id: UID.bcs,
|
|
127
|
+
lending_market_id: ID.bcs,
|
|
128
|
+
deposits: bcs.vector(Deposit.bcs),
|
|
129
|
+
borrows: bcs.vector(Borrow.bcs),
|
|
130
|
+
deposited_value_usd: Decimal.bcs,
|
|
131
|
+
allowed_borrow_value_usd: Decimal.bcs,
|
|
132
|
+
unhealthy_borrow_value_usd: Decimal.bcs,
|
|
133
|
+
super_unhealthy_borrow_value_usd: Decimal.bcs,
|
|
134
|
+
unweighted_borrowed_value_usd: Decimal.bcs,
|
|
135
|
+
weighted_borrowed_value_usd: Decimal.bcs,
|
|
136
|
+
weighted_borrowed_value_upper_bound_usd: Decimal.bcs,
|
|
137
|
+
borrowing_isolated_asset: bcs.bool(),
|
|
138
|
+
user_reward_managers: bcs.vector(UserRewardManager.bcs),
|
|
139
|
+
bad_debt_usd: Decimal.bcs,
|
|
140
|
+
closable: bcs.bool(),
|
|
78
141
|
});
|
|
79
142
|
}
|
|
80
|
-
static
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
143
|
+
static cachedBcs = null;
|
|
144
|
+
static get bcs() {
|
|
145
|
+
if (!Obligation.cachedBcs) {
|
|
146
|
+
Obligation.cachedBcs = Obligation.instantiateBcs();
|
|
147
|
+
}
|
|
148
|
+
return Obligation.cachedBcs;
|
|
149
|
+
}
|
|
150
|
+
static fromFields(typeArg, fields) {
|
|
151
|
+
return Obligation.reified(typeArg).new({
|
|
152
|
+
id: decodeFromFields(UID.reified(), fields.id),
|
|
153
|
+
lendingMarketId: decodeFromFields(ID.reified(), fields.lending_market_id),
|
|
154
|
+
deposits: decodeFromFields(vector(Deposit.reified()), fields.deposits),
|
|
155
|
+
borrows: decodeFromFields(vector(Borrow.reified()), fields.borrows),
|
|
156
|
+
depositedValueUsd: decodeFromFields(Decimal.reified(), fields.deposited_value_usd),
|
|
157
|
+
allowedBorrowValueUsd: decodeFromFields(Decimal.reified(), fields.allowed_borrow_value_usd),
|
|
158
|
+
unhealthyBorrowValueUsd: decodeFromFields(Decimal.reified(), fields.unhealthy_borrow_value_usd),
|
|
159
|
+
superUnhealthyBorrowValueUsd: decodeFromFields(Decimal.reified(), fields.super_unhealthy_borrow_value_usd),
|
|
160
|
+
unweightedBorrowedValueUsd: decodeFromFields(Decimal.reified(), fields.unweighted_borrowed_value_usd),
|
|
161
|
+
weightedBorrowedValueUsd: decodeFromFields(Decimal.reified(), fields.weighted_borrowed_value_usd),
|
|
162
|
+
weightedBorrowedValueUpperBoundUsd: decodeFromFields(Decimal.reified(), fields.weighted_borrowed_value_upper_bound_usd),
|
|
163
|
+
borrowingIsolatedAsset: decodeFromFields('bool', fields.borrowing_isolated_asset),
|
|
164
|
+
userRewardManagers: decodeFromFields(vector(UserRewardManager.reified()), fields.user_reward_managers),
|
|
165
|
+
badDebtUsd: decodeFromFields(Decimal.reified(), fields.bad_debt_usd),
|
|
166
|
+
closable: decodeFromFields('bool', fields.closable),
|
|
88
167
|
});
|
|
89
168
|
}
|
|
90
|
-
static fromFieldsWithTypes(item) {
|
|
91
|
-
if (!
|
|
92
|
-
throw new Error(
|
|
169
|
+
static fromFieldsWithTypes(typeArg, item) {
|
|
170
|
+
if (!isObligation(item.type)) {
|
|
171
|
+
throw new Error('not a Obligation type');
|
|
93
172
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
173
|
+
assertFieldsWithTypesArgsMatch(item, [typeArg]);
|
|
174
|
+
return Obligation.reified(typeArg).new({
|
|
175
|
+
id: decodeFromFieldsWithTypes(UID.reified(), item.fields.id),
|
|
176
|
+
lendingMarketId: decodeFromFieldsWithTypes(ID.reified(), item.fields.lending_market_id),
|
|
177
|
+
deposits: decodeFromFieldsWithTypes(vector(Deposit.reified()), item.fields.deposits),
|
|
178
|
+
borrows: decodeFromFieldsWithTypes(vector(Borrow.reified()), item.fields.borrows),
|
|
179
|
+
depositedValueUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.deposited_value_usd),
|
|
180
|
+
allowedBorrowValueUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.allowed_borrow_value_usd),
|
|
181
|
+
unhealthyBorrowValueUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.unhealthy_borrow_value_usd),
|
|
182
|
+
superUnhealthyBorrowValueUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.super_unhealthy_borrow_value_usd),
|
|
183
|
+
unweightedBorrowedValueUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.unweighted_borrowed_value_usd),
|
|
184
|
+
weightedBorrowedValueUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.weighted_borrowed_value_usd),
|
|
185
|
+
weightedBorrowedValueUpperBoundUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.weighted_borrowed_value_upper_bound_usd),
|
|
186
|
+
borrowingIsolatedAsset: decodeFromFieldsWithTypes('bool', item.fields.borrowing_isolated_asset),
|
|
187
|
+
userRewardManagers: decodeFromFieldsWithTypes(vector(UserRewardManager.reified()), item.fields.user_reward_managers),
|
|
188
|
+
badDebtUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.bad_debt_usd),
|
|
189
|
+
closable: decodeFromFieldsWithTypes('bool', item.fields.closable),
|
|
101
190
|
});
|
|
102
191
|
}
|
|
103
|
-
static fromBcs(data) {
|
|
104
|
-
return
|
|
192
|
+
static fromBcs(typeArg, data) {
|
|
193
|
+
return Obligation.fromFields(typeArg, Obligation.bcs.parse(data));
|
|
105
194
|
}
|
|
106
195
|
toJSONField() {
|
|
107
196
|
return {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
197
|
+
id: this.id,
|
|
198
|
+
lendingMarketId: this.lendingMarketId,
|
|
199
|
+
deposits: fieldToJSON(`vector<${Deposit.$typeName}>`, this.deposits),
|
|
200
|
+
borrows: fieldToJSON(`vector<${Borrow.$typeName}>`, this.borrows),
|
|
201
|
+
depositedValueUsd: this.depositedValueUsd.toJSONField(),
|
|
202
|
+
allowedBorrowValueUsd: this.allowedBorrowValueUsd.toJSONField(),
|
|
203
|
+
unhealthyBorrowValueUsd: this.unhealthyBorrowValueUsd.toJSONField(),
|
|
204
|
+
superUnhealthyBorrowValueUsd: this.superUnhealthyBorrowValueUsd.toJSONField(),
|
|
205
|
+
unweightedBorrowedValueUsd: this.unweightedBorrowedValueUsd.toJSONField(),
|
|
206
|
+
weightedBorrowedValueUsd: this.weightedBorrowedValueUsd.toJSONField(),
|
|
207
|
+
weightedBorrowedValueUpperBoundUsd: this.weightedBorrowedValueUpperBoundUsd.toJSONField(),
|
|
208
|
+
borrowingIsolatedAsset: this.borrowingIsolatedAsset,
|
|
209
|
+
userRewardManagers: fieldToJSON(`vector<${UserRewardManager.$typeName}>`, this.userRewardManagers),
|
|
210
|
+
badDebtUsd: this.badDebtUsd.toJSONField(),
|
|
211
|
+
closable: this.closable,
|
|
114
212
|
};
|
|
115
213
|
}
|
|
116
214
|
toJSON() {
|
|
117
|
-
return {
|
|
118
|
-
$typeName: this.$typeName,
|
|
119
|
-
$typeArgs: this.$typeArgs,
|
|
120
|
-
...this.toJSONField(),
|
|
121
|
-
};
|
|
215
|
+
return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
|
|
122
216
|
}
|
|
123
|
-
static fromJSONField(field) {
|
|
124
|
-
return
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
217
|
+
static fromJSONField(typeArg, field) {
|
|
218
|
+
return Obligation.reified(typeArg).new({
|
|
219
|
+
id: decodeFromJSONField(UID.reified(), field.id),
|
|
220
|
+
lendingMarketId: decodeFromJSONField(ID.reified(), field.lendingMarketId),
|
|
221
|
+
deposits: decodeFromJSONField(vector(Deposit.reified()), field.deposits),
|
|
222
|
+
borrows: decodeFromJSONField(vector(Borrow.reified()), field.borrows),
|
|
223
|
+
depositedValueUsd: decodeFromJSONField(Decimal.reified(), field.depositedValueUsd),
|
|
224
|
+
allowedBorrowValueUsd: decodeFromJSONField(Decimal.reified(), field.allowedBorrowValueUsd),
|
|
225
|
+
unhealthyBorrowValueUsd: decodeFromJSONField(Decimal.reified(), field.unhealthyBorrowValueUsd),
|
|
226
|
+
superUnhealthyBorrowValueUsd: decodeFromJSONField(Decimal.reified(), field.superUnhealthyBorrowValueUsd),
|
|
227
|
+
unweightedBorrowedValueUsd: decodeFromJSONField(Decimal.reified(), field.unweightedBorrowedValueUsd),
|
|
228
|
+
weightedBorrowedValueUsd: decodeFromJSONField(Decimal.reified(), field.weightedBorrowedValueUsd),
|
|
229
|
+
weightedBorrowedValueUpperBoundUsd: decodeFromJSONField(Decimal.reified(), field.weightedBorrowedValueUpperBoundUsd),
|
|
230
|
+
borrowingIsolatedAsset: decodeFromJSONField('bool', field.borrowingIsolatedAsset),
|
|
231
|
+
userRewardManagers: decodeFromJSONField(vector(UserRewardManager.reified()), field.userRewardManagers),
|
|
232
|
+
badDebtUsd: decodeFromJSONField(Decimal.reified(), field.badDebtUsd),
|
|
233
|
+
closable: decodeFromJSONField('bool', field.closable),
|
|
131
234
|
});
|
|
132
235
|
}
|
|
133
|
-
static fromJSON(json) {
|
|
134
|
-
if (json.$typeName !==
|
|
135
|
-
throw new Error(
|
|
236
|
+
static fromJSON(typeArg, json) {
|
|
237
|
+
if (json.$typeName !== Obligation.$typeName) {
|
|
238
|
+
throw new Error(`not a Obligation json object: expected '${Obligation.$typeName}' but got '${json.$typeName}'`);
|
|
136
239
|
}
|
|
137
|
-
|
|
240
|
+
assertReifiedTypeArgsMatch(composeSuiType(Obligation.$typeName, ...[extractType(typeArg)]), json.$typeArgs, [typeArg]);
|
|
241
|
+
return Obligation.fromJSONField(typeArg, json);
|
|
138
242
|
}
|
|
139
|
-
static
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
throw new Error(`object at id ${id} is not a Borrow object`);
|
|
243
|
+
static fromCoreObject(typeArg, obj) {
|
|
244
|
+
if (!isObligation(obj.type)) {
|
|
245
|
+
throw new Error(`object at ${obj.objectId} is not a Obligation object`);
|
|
143
246
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
/* ============================== BorrowRecord =============================== */
|
|
148
|
-
export function isBorrowRecord(type) {
|
|
149
|
-
type = compressSuiType(type);
|
|
150
|
-
return type === `${PKG_V1}::obligation::BorrowRecord`;
|
|
151
|
-
}
|
|
152
|
-
export class BorrowRecord {
|
|
153
|
-
__StructClass = true;
|
|
154
|
-
static $typeName = `${PKG_V1}::obligation::BorrowRecord`;
|
|
155
|
-
static $numTypeParams = 0;
|
|
156
|
-
static $isPhantom = [];
|
|
157
|
-
$typeName = BorrowRecord.$typeName;
|
|
158
|
-
$fullTypeName;
|
|
159
|
-
$typeArgs;
|
|
160
|
-
$isPhantom = BorrowRecord.$isPhantom;
|
|
161
|
-
coinType;
|
|
162
|
-
reserveArrayIndex;
|
|
163
|
-
borrowedAmount;
|
|
164
|
-
cumulativeBorrowRate;
|
|
165
|
-
marketValue;
|
|
166
|
-
userRewardManagerIndex;
|
|
167
|
-
constructor(typeArgs, fields) {
|
|
168
|
-
this.$fullTypeName = composeSuiType(BorrowRecord.$typeName, ...typeArgs);
|
|
169
|
-
this.$typeArgs = typeArgs;
|
|
170
|
-
this.coinType = fields.coinType;
|
|
171
|
-
this.reserveArrayIndex = fields.reserveArrayIndex;
|
|
172
|
-
this.borrowedAmount = fields.borrowedAmount;
|
|
173
|
-
this.cumulativeBorrowRate = fields.cumulativeBorrowRate;
|
|
174
|
-
this.marketValue = fields.marketValue;
|
|
175
|
-
this.userRewardManagerIndex = fields.userRewardManagerIndex;
|
|
176
|
-
}
|
|
177
|
-
static reified() {
|
|
178
|
-
return {
|
|
179
|
-
typeName: BorrowRecord.$typeName,
|
|
180
|
-
fullTypeName: composeSuiType(BorrowRecord.$typeName, ...[]),
|
|
181
|
-
typeArgs: [],
|
|
182
|
-
isPhantom: BorrowRecord.$isPhantom,
|
|
183
|
-
reifiedTypeArgs: [],
|
|
184
|
-
fromFields: (fields) => BorrowRecord.fromFields(fields),
|
|
185
|
-
fromFieldsWithTypes: (item) => BorrowRecord.fromFieldsWithTypes(item),
|
|
186
|
-
fromBcs: (data) => BorrowRecord.fromBcs(data),
|
|
187
|
-
bcs: BorrowRecord.bcs,
|
|
188
|
-
fromJSONField: (field) => BorrowRecord.fromJSONField(field),
|
|
189
|
-
fromJSON: (json) => BorrowRecord.fromJSON(json),
|
|
190
|
-
fetch: async (client, id) => BorrowRecord.fetch(client, id),
|
|
191
|
-
new: (fields) => {
|
|
192
|
-
return new BorrowRecord([], fields);
|
|
193
|
-
},
|
|
194
|
-
kind: "StructClassReified",
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
static get r() {
|
|
198
|
-
return BorrowRecord.reified();
|
|
199
|
-
}
|
|
200
|
-
static phantom() {
|
|
201
|
-
return phantom(BorrowRecord.reified());
|
|
202
|
-
}
|
|
203
|
-
static get p() {
|
|
204
|
-
return BorrowRecord.phantom();
|
|
205
|
-
}
|
|
206
|
-
static get bcs() {
|
|
207
|
-
return bcs.struct("BorrowRecord", {
|
|
208
|
-
coin_type: TypeName.bcs,
|
|
209
|
-
reserve_array_index: bcs.u64(),
|
|
210
|
-
borrowed_amount: Decimal.bcs,
|
|
211
|
-
cumulative_borrow_rate: Decimal.bcs,
|
|
212
|
-
market_value: Decimal.bcs,
|
|
213
|
-
user_reward_manager_index: bcs.u64(),
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
static fromFields(fields) {
|
|
217
|
-
return BorrowRecord.reified().new({
|
|
218
|
-
coinType: decodeFromFields(TypeName.reified(), fields.coin_type),
|
|
219
|
-
reserveArrayIndex: decodeFromFields("u64", fields.reserve_array_index),
|
|
220
|
-
borrowedAmount: decodeFromFields(Decimal.reified(), fields.borrowed_amount),
|
|
221
|
-
cumulativeBorrowRate: decodeFromFields(Decimal.reified(), fields.cumulative_borrow_rate),
|
|
222
|
-
marketValue: decodeFromFields(Decimal.reified(), fields.market_value),
|
|
223
|
-
userRewardManagerIndex: decodeFromFields("u64", fields.user_reward_manager_index),
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
static fromFieldsWithTypes(item) {
|
|
227
|
-
if (!isBorrowRecord(item.type)) {
|
|
228
|
-
throw new Error("not a BorrowRecord type");
|
|
247
|
+
const gotTypeArgs = parseTypeName(obj.type).typeArgs;
|
|
248
|
+
if (gotTypeArgs.length !== 1) {
|
|
249
|
+
throw new Error(`type argument mismatch: expected 1 type arguments but got '${gotTypeArgs.length}'`);
|
|
229
250
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
static fromBcs(data) {
|
|
240
|
-
return BorrowRecord.fromFields(BorrowRecord.bcs.parse(data));
|
|
241
|
-
}
|
|
242
|
-
toJSONField() {
|
|
243
|
-
return {
|
|
244
|
-
coinType: this.coinType.toJSONField(),
|
|
245
|
-
reserveArrayIndex: this.reserveArrayIndex.toString(),
|
|
246
|
-
borrowedAmount: this.borrowedAmount.toJSONField(),
|
|
247
|
-
cumulativeBorrowRate: this.cumulativeBorrowRate.toJSONField(),
|
|
248
|
-
marketValue: this.marketValue.toJSONField(),
|
|
249
|
-
userRewardManagerIndex: this.userRewardManagerIndex.toString(),
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
toJSON() {
|
|
253
|
-
return {
|
|
254
|
-
$typeName: this.$typeName,
|
|
255
|
-
$typeArgs: this.$typeArgs,
|
|
256
|
-
...this.toJSONField(),
|
|
257
|
-
};
|
|
251
|
+
for (let i = 0; i < 1; i++) {
|
|
252
|
+
const gotTypeArg = compressSuiType(gotTypeArgs[i]);
|
|
253
|
+
const expectedTypeArg = compressSuiType(extractType([typeArg][i]));
|
|
254
|
+
if (gotTypeArg !== expectedTypeArg) {
|
|
255
|
+
throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return Obligation.fromBcs(typeArg, obj.content);
|
|
258
259
|
}
|
|
259
|
-
static
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
borrowedAmount: decodeFromJSONField(Decimal.reified(), field.borrowedAmount),
|
|
264
|
-
cumulativeBorrowRate: decodeFromJSONField(Decimal.reified(), field.cumulativeBorrowRate),
|
|
265
|
-
marketValue: decodeFromJSONField(Decimal.reified(), field.marketValue),
|
|
266
|
-
userRewardManagerIndex: decodeFromJSONField("u64", field.userRewardManagerIndex),
|
|
260
|
+
static async fetch(client, typeArg, id) {
|
|
261
|
+
const { object } = await client.core.getObject({
|
|
262
|
+
objectId: id,
|
|
263
|
+
include: { content: true },
|
|
267
264
|
});
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
if (json.$typeName !== BorrowRecord.$typeName) {
|
|
271
|
-
throw new Error("not a WithTwoGenerics json object");
|
|
265
|
+
if (!isObligation(object.type)) {
|
|
266
|
+
throw new Error(`object at id ${id} is not a Obligation object`);
|
|
272
267
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const { object } = await client.getObject({ objectId: id, include: { content: true } });
|
|
277
|
-
if (!isBorrowRecord(object.type)) {
|
|
278
|
-
throw new Error(`object at id ${id} is not a BorrowRecord object`);
|
|
268
|
+
const gotTypeArgs = parseTypeName(object.type).typeArgs;
|
|
269
|
+
if (gotTypeArgs.length !== 1) {
|
|
270
|
+
throw new Error(`type argument mismatch: expected 1 type arguments but got '${gotTypeArgs.length}'`);
|
|
279
271
|
}
|
|
280
|
-
|
|
272
|
+
for (let i = 0; i < 1; i++) {
|
|
273
|
+
const gotTypeArg = compressSuiType(gotTypeArgs[i]);
|
|
274
|
+
const expectedTypeArg = compressSuiType(extractType([typeArg][i]));
|
|
275
|
+
if (gotTypeArg !== expectedTypeArg) {
|
|
276
|
+
throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return Obligation.fromBcs(typeArg, object.content);
|
|
281
280
|
}
|
|
282
281
|
}
|
|
283
282
|
/* ============================== Deposit =============================== */
|
|
284
283
|
export function isDeposit(type) {
|
|
285
284
|
type = compressSuiType(type);
|
|
286
|
-
return type === `${
|
|
285
|
+
return type === `${getTypeOrigin('suilend', 'obligation::Deposit')}::obligation::Deposit`;
|
|
287
286
|
}
|
|
288
287
|
export class Deposit {
|
|
289
288
|
__StructClass = true;
|
|
290
|
-
static $typeName
|
|
289
|
+
static get $typeName() {
|
|
290
|
+
return `${getTypeOrigin('suilend', 'obligation::Deposit')}::obligation::Deposit`;
|
|
291
|
+
}
|
|
291
292
|
static $numTypeParams = 0;
|
|
292
293
|
static $isPhantom = [];
|
|
293
294
|
$typeName = Deposit.$typeName;
|
|
@@ -299,6 +300,7 @@ export class Deposit {
|
|
|
299
300
|
depositedCtokenAmount;
|
|
300
301
|
marketValue;
|
|
301
302
|
userRewardManagerIndex;
|
|
303
|
+
/** unused */
|
|
302
304
|
attributedBorrowValue;
|
|
303
305
|
constructor(typeArgs, fields) {
|
|
304
306
|
this.$fullTypeName = composeSuiType(Deposit.$typeName, ...typeArgs);
|
|
@@ -311,23 +313,29 @@ export class Deposit {
|
|
|
311
313
|
this.attributedBorrowValue = fields.attributedBorrowValue;
|
|
312
314
|
}
|
|
313
315
|
static reified() {
|
|
316
|
+
const reifiedBcs = Deposit.bcs;
|
|
314
317
|
return {
|
|
315
|
-
typeName
|
|
316
|
-
|
|
318
|
+
get typeName() {
|
|
319
|
+
return Deposit.$typeName;
|
|
320
|
+
},
|
|
321
|
+
get fullTypeName() {
|
|
322
|
+
return composeSuiType(Deposit.$typeName, ...[]);
|
|
323
|
+
},
|
|
317
324
|
typeArgs: [],
|
|
318
325
|
isPhantom: Deposit.$isPhantom,
|
|
319
326
|
reifiedTypeArgs: [],
|
|
320
327
|
fromFields: (fields) => Deposit.fromFields(fields),
|
|
321
328
|
fromFieldsWithTypes: (item) => Deposit.fromFieldsWithTypes(item),
|
|
322
|
-
fromBcs: (data) => Deposit.
|
|
323
|
-
bcs:
|
|
329
|
+
fromBcs: (data) => Deposit.fromFields(reifiedBcs.parse(data)),
|
|
330
|
+
bcs: reifiedBcs,
|
|
324
331
|
fromJSONField: (field) => Deposit.fromJSONField(field),
|
|
325
332
|
fromJSON: (json) => Deposit.fromJSON(json),
|
|
333
|
+
fromCoreObject: (obj) => Deposit.fromCoreObject(obj),
|
|
326
334
|
fetch: async (client, id) => Deposit.fetch(client, id),
|
|
327
335
|
new: (fields) => {
|
|
328
336
|
return new Deposit([], fields);
|
|
329
337
|
},
|
|
330
|
-
kind:
|
|
338
|
+
kind: 'StructClassReified',
|
|
331
339
|
};
|
|
332
340
|
}
|
|
333
341
|
static get r() {
|
|
@@ -339,8 +347,8 @@ export class Deposit {
|
|
|
339
347
|
static get p() {
|
|
340
348
|
return Deposit.phantom();
|
|
341
349
|
}
|
|
342
|
-
static
|
|
343
|
-
return bcs.struct(
|
|
350
|
+
static instantiateBcs() {
|
|
351
|
+
return bcs.struct('Deposit', {
|
|
344
352
|
coin_type: TypeName.bcs,
|
|
345
353
|
reserve_array_index: bcs.u64(),
|
|
346
354
|
deposited_ctoken_amount: bcs.u64(),
|
|
@@ -349,26 +357,33 @@ export class Deposit {
|
|
|
349
357
|
attributed_borrow_value: Decimal.bcs,
|
|
350
358
|
});
|
|
351
359
|
}
|
|
360
|
+
static cachedBcs = null;
|
|
361
|
+
static get bcs() {
|
|
362
|
+
if (!Deposit.cachedBcs) {
|
|
363
|
+
Deposit.cachedBcs = Deposit.instantiateBcs();
|
|
364
|
+
}
|
|
365
|
+
return Deposit.cachedBcs;
|
|
366
|
+
}
|
|
352
367
|
static fromFields(fields) {
|
|
353
368
|
return Deposit.reified().new({
|
|
354
369
|
coinType: decodeFromFields(TypeName.reified(), fields.coin_type),
|
|
355
|
-
reserveArrayIndex: decodeFromFields(
|
|
356
|
-
depositedCtokenAmount: decodeFromFields(
|
|
370
|
+
reserveArrayIndex: decodeFromFields('u64', fields.reserve_array_index),
|
|
371
|
+
depositedCtokenAmount: decodeFromFields('u64', fields.deposited_ctoken_amount),
|
|
357
372
|
marketValue: decodeFromFields(Decimal.reified(), fields.market_value),
|
|
358
|
-
userRewardManagerIndex: decodeFromFields(
|
|
373
|
+
userRewardManagerIndex: decodeFromFields('u64', fields.user_reward_manager_index),
|
|
359
374
|
attributedBorrowValue: decodeFromFields(Decimal.reified(), fields.attributed_borrow_value),
|
|
360
375
|
});
|
|
361
376
|
}
|
|
362
377
|
static fromFieldsWithTypes(item) {
|
|
363
378
|
if (!isDeposit(item.type)) {
|
|
364
|
-
throw new Error(
|
|
379
|
+
throw new Error('not a Deposit type');
|
|
365
380
|
}
|
|
366
381
|
return Deposit.reified().new({
|
|
367
382
|
coinType: decodeFromFieldsWithTypes(TypeName.reified(), item.fields.coin_type),
|
|
368
|
-
reserveArrayIndex: decodeFromFieldsWithTypes(
|
|
369
|
-
depositedCtokenAmount: decodeFromFieldsWithTypes(
|
|
383
|
+
reserveArrayIndex: decodeFromFieldsWithTypes('u64', item.fields.reserve_array_index),
|
|
384
|
+
depositedCtokenAmount: decodeFromFieldsWithTypes('u64', item.fields.deposited_ctoken_amount),
|
|
370
385
|
marketValue: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.market_value),
|
|
371
|
-
userRewardManagerIndex: decodeFromFieldsWithTypes(
|
|
386
|
+
userRewardManagerIndex: decodeFromFieldsWithTypes('u64', item.fields.user_reward_manager_index),
|
|
372
387
|
attributedBorrowValue: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.attributed_borrow_value),
|
|
373
388
|
});
|
|
374
389
|
}
|
|
@@ -377,7 +392,7 @@ export class Deposit {
|
|
|
377
392
|
}
|
|
378
393
|
toJSONField() {
|
|
379
394
|
return {
|
|
380
|
-
coinType: this.coinType
|
|
395
|
+
coinType: this.coinType,
|
|
381
396
|
reserveArrayIndex: this.reserveArrayIndex.toString(),
|
|
382
397
|
depositedCtokenAmount: this.depositedCtokenAmount.toString(),
|
|
383
398
|
marketValue: this.marketValue.toJSONField(),
|
|
@@ -386,180 +401,208 @@ export class Deposit {
|
|
|
386
401
|
};
|
|
387
402
|
}
|
|
388
403
|
toJSON() {
|
|
389
|
-
return {
|
|
390
|
-
$typeName: this.$typeName,
|
|
391
|
-
$typeArgs: this.$typeArgs,
|
|
392
|
-
...this.toJSONField(),
|
|
393
|
-
};
|
|
404
|
+
return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
|
|
394
405
|
}
|
|
395
406
|
static fromJSONField(field) {
|
|
396
407
|
return Deposit.reified().new({
|
|
397
408
|
coinType: decodeFromJSONField(TypeName.reified(), field.coinType),
|
|
398
|
-
reserveArrayIndex: decodeFromJSONField(
|
|
399
|
-
depositedCtokenAmount: decodeFromJSONField(
|
|
409
|
+
reserveArrayIndex: decodeFromJSONField('u64', field.reserveArrayIndex),
|
|
410
|
+
depositedCtokenAmount: decodeFromJSONField('u64', field.depositedCtokenAmount),
|
|
400
411
|
marketValue: decodeFromJSONField(Decimal.reified(), field.marketValue),
|
|
401
|
-
userRewardManagerIndex: decodeFromJSONField(
|
|
412
|
+
userRewardManagerIndex: decodeFromJSONField('u64', field.userRewardManagerIndex),
|
|
402
413
|
attributedBorrowValue: decodeFromJSONField(Decimal.reified(), field.attributedBorrowValue),
|
|
403
414
|
});
|
|
404
415
|
}
|
|
405
416
|
static fromJSON(json) {
|
|
406
417
|
if (json.$typeName !== Deposit.$typeName) {
|
|
407
|
-
throw new Error(
|
|
418
|
+
throw new Error(`not a Deposit json object: expected '${Deposit.$typeName}' but got '${json.$typeName}'`);
|
|
408
419
|
}
|
|
409
420
|
return Deposit.fromJSONField(json);
|
|
410
421
|
}
|
|
422
|
+
static fromCoreObject(obj) {
|
|
423
|
+
if (!isDeposit(obj.type)) {
|
|
424
|
+
throw new Error(`object at ${obj.objectId} is not a Deposit object`);
|
|
425
|
+
}
|
|
426
|
+
return Deposit.fromBcs(obj.content);
|
|
427
|
+
}
|
|
411
428
|
static async fetch(client, id) {
|
|
412
|
-
const { object } = await client.getObject({
|
|
429
|
+
const { object } = await client.core.getObject({
|
|
430
|
+
objectId: id,
|
|
431
|
+
include: { content: true },
|
|
432
|
+
});
|
|
413
433
|
if (!isDeposit(object.type)) {
|
|
414
434
|
throw new Error(`object at id ${id} is not a Deposit object`);
|
|
415
435
|
}
|
|
416
436
|
return Deposit.fromBcs(object.content);
|
|
417
437
|
}
|
|
418
438
|
}
|
|
419
|
-
/* ==============================
|
|
420
|
-
export function
|
|
439
|
+
/* ============================== Borrow =============================== */
|
|
440
|
+
export function isBorrow(type) {
|
|
421
441
|
type = compressSuiType(type);
|
|
422
|
-
return type === `${
|
|
442
|
+
return type === `${getTypeOrigin('suilend', 'obligation::Borrow')}::obligation::Borrow`;
|
|
423
443
|
}
|
|
424
|
-
export class
|
|
444
|
+
export class Borrow {
|
|
425
445
|
__StructClass = true;
|
|
426
|
-
static $typeName
|
|
446
|
+
static get $typeName() {
|
|
447
|
+
return `${getTypeOrigin('suilend', 'obligation::Borrow')}::obligation::Borrow`;
|
|
448
|
+
}
|
|
427
449
|
static $numTypeParams = 0;
|
|
428
450
|
static $isPhantom = [];
|
|
429
|
-
$typeName =
|
|
451
|
+
$typeName = Borrow.$typeName;
|
|
430
452
|
$fullTypeName;
|
|
431
453
|
$typeArgs;
|
|
432
|
-
$isPhantom =
|
|
454
|
+
$isPhantom = Borrow.$isPhantom;
|
|
433
455
|
coinType;
|
|
434
456
|
reserveArrayIndex;
|
|
435
|
-
|
|
457
|
+
borrowedAmount;
|
|
458
|
+
cumulativeBorrowRate;
|
|
436
459
|
marketValue;
|
|
437
460
|
userRewardManagerIndex;
|
|
438
|
-
attributedBorrowValue;
|
|
439
461
|
constructor(typeArgs, fields) {
|
|
440
|
-
this.$fullTypeName = composeSuiType(
|
|
462
|
+
this.$fullTypeName = composeSuiType(Borrow.$typeName, ...typeArgs);
|
|
441
463
|
this.$typeArgs = typeArgs;
|
|
442
464
|
this.coinType = fields.coinType;
|
|
443
465
|
this.reserveArrayIndex = fields.reserveArrayIndex;
|
|
444
|
-
this.
|
|
466
|
+
this.borrowedAmount = fields.borrowedAmount;
|
|
467
|
+
this.cumulativeBorrowRate = fields.cumulativeBorrowRate;
|
|
445
468
|
this.marketValue = fields.marketValue;
|
|
446
469
|
this.userRewardManagerIndex = fields.userRewardManagerIndex;
|
|
447
|
-
this.attributedBorrowValue = fields.attributedBorrowValue;
|
|
448
470
|
}
|
|
449
471
|
static reified() {
|
|
472
|
+
const reifiedBcs = Borrow.bcs;
|
|
450
473
|
return {
|
|
451
|
-
typeName
|
|
452
|
-
|
|
474
|
+
get typeName() {
|
|
475
|
+
return Borrow.$typeName;
|
|
476
|
+
},
|
|
477
|
+
get fullTypeName() {
|
|
478
|
+
return composeSuiType(Borrow.$typeName, ...[]);
|
|
479
|
+
},
|
|
453
480
|
typeArgs: [],
|
|
454
|
-
isPhantom:
|
|
481
|
+
isPhantom: Borrow.$isPhantom,
|
|
455
482
|
reifiedTypeArgs: [],
|
|
456
|
-
fromFields: (fields) =>
|
|
457
|
-
fromFieldsWithTypes: (item) =>
|
|
458
|
-
fromBcs: (data) =>
|
|
459
|
-
bcs:
|
|
460
|
-
fromJSONField: (field) =>
|
|
461
|
-
fromJSON: (json) =>
|
|
462
|
-
|
|
483
|
+
fromFields: (fields) => Borrow.fromFields(fields),
|
|
484
|
+
fromFieldsWithTypes: (item) => Borrow.fromFieldsWithTypes(item),
|
|
485
|
+
fromBcs: (data) => Borrow.fromFields(reifiedBcs.parse(data)),
|
|
486
|
+
bcs: reifiedBcs,
|
|
487
|
+
fromJSONField: (field) => Borrow.fromJSONField(field),
|
|
488
|
+
fromJSON: (json) => Borrow.fromJSON(json),
|
|
489
|
+
fromCoreObject: (obj) => Borrow.fromCoreObject(obj),
|
|
490
|
+
fetch: async (client, id) => Borrow.fetch(client, id),
|
|
463
491
|
new: (fields) => {
|
|
464
|
-
return new
|
|
492
|
+
return new Borrow([], fields);
|
|
465
493
|
},
|
|
466
|
-
kind:
|
|
494
|
+
kind: 'StructClassReified',
|
|
467
495
|
};
|
|
468
496
|
}
|
|
469
497
|
static get r() {
|
|
470
|
-
return
|
|
498
|
+
return Borrow.reified();
|
|
471
499
|
}
|
|
472
500
|
static phantom() {
|
|
473
|
-
return phantom(
|
|
501
|
+
return phantom(Borrow.reified());
|
|
474
502
|
}
|
|
475
503
|
static get p() {
|
|
476
|
-
return
|
|
504
|
+
return Borrow.phantom();
|
|
477
505
|
}
|
|
478
|
-
static
|
|
479
|
-
return bcs.struct(
|
|
506
|
+
static instantiateBcs() {
|
|
507
|
+
return bcs.struct('Borrow', {
|
|
480
508
|
coin_type: TypeName.bcs,
|
|
481
509
|
reserve_array_index: bcs.u64(),
|
|
482
|
-
|
|
510
|
+
borrowed_amount: Decimal.bcs,
|
|
511
|
+
cumulative_borrow_rate: Decimal.bcs,
|
|
483
512
|
market_value: Decimal.bcs,
|
|
484
513
|
user_reward_manager_index: bcs.u64(),
|
|
485
|
-
attributed_borrow_value: Decimal.bcs,
|
|
486
514
|
});
|
|
487
515
|
}
|
|
516
|
+
static cachedBcs = null;
|
|
517
|
+
static get bcs() {
|
|
518
|
+
if (!Borrow.cachedBcs) {
|
|
519
|
+
Borrow.cachedBcs = Borrow.instantiateBcs();
|
|
520
|
+
}
|
|
521
|
+
return Borrow.cachedBcs;
|
|
522
|
+
}
|
|
488
523
|
static fromFields(fields) {
|
|
489
|
-
return
|
|
524
|
+
return Borrow.reified().new({
|
|
490
525
|
coinType: decodeFromFields(TypeName.reified(), fields.coin_type),
|
|
491
|
-
reserveArrayIndex: decodeFromFields(
|
|
492
|
-
|
|
526
|
+
reserveArrayIndex: decodeFromFields('u64', fields.reserve_array_index),
|
|
527
|
+
borrowedAmount: decodeFromFields(Decimal.reified(), fields.borrowed_amount),
|
|
528
|
+
cumulativeBorrowRate: decodeFromFields(Decimal.reified(), fields.cumulative_borrow_rate),
|
|
493
529
|
marketValue: decodeFromFields(Decimal.reified(), fields.market_value),
|
|
494
|
-
userRewardManagerIndex: decodeFromFields(
|
|
495
|
-
attributedBorrowValue: decodeFromFields(Decimal.reified(), fields.attributed_borrow_value),
|
|
530
|
+
userRewardManagerIndex: decodeFromFields('u64', fields.user_reward_manager_index),
|
|
496
531
|
});
|
|
497
532
|
}
|
|
498
533
|
static fromFieldsWithTypes(item) {
|
|
499
|
-
if (!
|
|
500
|
-
throw new Error(
|
|
534
|
+
if (!isBorrow(item.type)) {
|
|
535
|
+
throw new Error('not a Borrow type');
|
|
501
536
|
}
|
|
502
|
-
return
|
|
537
|
+
return Borrow.reified().new({
|
|
503
538
|
coinType: decodeFromFieldsWithTypes(TypeName.reified(), item.fields.coin_type),
|
|
504
|
-
reserveArrayIndex: decodeFromFieldsWithTypes(
|
|
505
|
-
|
|
539
|
+
reserveArrayIndex: decodeFromFieldsWithTypes('u64', item.fields.reserve_array_index),
|
|
540
|
+
borrowedAmount: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.borrowed_amount),
|
|
541
|
+
cumulativeBorrowRate: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.cumulative_borrow_rate),
|
|
506
542
|
marketValue: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.market_value),
|
|
507
|
-
userRewardManagerIndex: decodeFromFieldsWithTypes(
|
|
508
|
-
attributedBorrowValue: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.attributed_borrow_value),
|
|
543
|
+
userRewardManagerIndex: decodeFromFieldsWithTypes('u64', item.fields.user_reward_manager_index),
|
|
509
544
|
});
|
|
510
545
|
}
|
|
511
546
|
static fromBcs(data) {
|
|
512
|
-
return
|
|
547
|
+
return Borrow.fromFields(Borrow.bcs.parse(data));
|
|
513
548
|
}
|
|
514
549
|
toJSONField() {
|
|
515
550
|
return {
|
|
516
|
-
coinType: this.coinType
|
|
551
|
+
coinType: this.coinType,
|
|
517
552
|
reserveArrayIndex: this.reserveArrayIndex.toString(),
|
|
518
|
-
|
|
553
|
+
borrowedAmount: this.borrowedAmount.toJSONField(),
|
|
554
|
+
cumulativeBorrowRate: this.cumulativeBorrowRate.toJSONField(),
|
|
519
555
|
marketValue: this.marketValue.toJSONField(),
|
|
520
556
|
userRewardManagerIndex: this.userRewardManagerIndex.toString(),
|
|
521
|
-
attributedBorrowValue: this.attributedBorrowValue.toJSONField(),
|
|
522
557
|
};
|
|
523
558
|
}
|
|
524
559
|
toJSON() {
|
|
525
|
-
return {
|
|
526
|
-
$typeName: this.$typeName,
|
|
527
|
-
$typeArgs: this.$typeArgs,
|
|
528
|
-
...this.toJSONField(),
|
|
529
|
-
};
|
|
560
|
+
return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
|
|
530
561
|
}
|
|
531
562
|
static fromJSONField(field) {
|
|
532
|
-
return
|
|
563
|
+
return Borrow.reified().new({
|
|
533
564
|
coinType: decodeFromJSONField(TypeName.reified(), field.coinType),
|
|
534
|
-
reserveArrayIndex: decodeFromJSONField(
|
|
535
|
-
|
|
565
|
+
reserveArrayIndex: decodeFromJSONField('u64', field.reserveArrayIndex),
|
|
566
|
+
borrowedAmount: decodeFromJSONField(Decimal.reified(), field.borrowedAmount),
|
|
567
|
+
cumulativeBorrowRate: decodeFromJSONField(Decimal.reified(), field.cumulativeBorrowRate),
|
|
536
568
|
marketValue: decodeFromJSONField(Decimal.reified(), field.marketValue),
|
|
537
|
-
userRewardManagerIndex: decodeFromJSONField(
|
|
538
|
-
attributedBorrowValue: decodeFromJSONField(Decimal.reified(), field.attributedBorrowValue),
|
|
569
|
+
userRewardManagerIndex: decodeFromJSONField('u64', field.userRewardManagerIndex),
|
|
539
570
|
});
|
|
540
571
|
}
|
|
541
572
|
static fromJSON(json) {
|
|
542
|
-
if (json.$typeName !==
|
|
543
|
-
throw new Error(
|
|
573
|
+
if (json.$typeName !== Borrow.$typeName) {
|
|
574
|
+
throw new Error(`not a Borrow json object: expected '${Borrow.$typeName}' but got '${json.$typeName}'`);
|
|
544
575
|
}
|
|
545
|
-
return
|
|
576
|
+
return Borrow.fromJSONField(json);
|
|
577
|
+
}
|
|
578
|
+
static fromCoreObject(obj) {
|
|
579
|
+
if (!isBorrow(obj.type)) {
|
|
580
|
+
throw new Error(`object at ${obj.objectId} is not a Borrow object`);
|
|
581
|
+
}
|
|
582
|
+
return Borrow.fromBcs(obj.content);
|
|
546
583
|
}
|
|
547
584
|
static async fetch(client, id) {
|
|
548
|
-
const { object } = await client.getObject({
|
|
549
|
-
|
|
550
|
-
|
|
585
|
+
const { object } = await client.core.getObject({
|
|
586
|
+
objectId: id,
|
|
587
|
+
include: { content: true },
|
|
588
|
+
});
|
|
589
|
+
if (!isBorrow(object.type)) {
|
|
590
|
+
throw new Error(`object at id ${id} is not a Borrow object`);
|
|
551
591
|
}
|
|
552
|
-
return
|
|
592
|
+
return Borrow.fromBcs(object.content);
|
|
553
593
|
}
|
|
554
594
|
}
|
|
555
595
|
/* ============================== ExistStaleOracles =============================== */
|
|
556
596
|
export function isExistStaleOracles(type) {
|
|
557
597
|
type = compressSuiType(type);
|
|
558
|
-
return type
|
|
598
|
+
return type
|
|
599
|
+
=== `${getTypeOrigin('suilend', 'obligation::ExistStaleOracles')}::obligation::ExistStaleOracles`;
|
|
559
600
|
}
|
|
560
601
|
export class ExistStaleOracles {
|
|
561
602
|
__StructClass = true;
|
|
562
|
-
static $typeName
|
|
603
|
+
static get $typeName() {
|
|
604
|
+
return `${getTypeOrigin('suilend', 'obligation::ExistStaleOracles')}::obligation::ExistStaleOracles`;
|
|
605
|
+
}
|
|
563
606
|
static $numTypeParams = 0;
|
|
564
607
|
static $isPhantom = [];
|
|
565
608
|
$typeName = ExistStaleOracles.$typeName;
|
|
@@ -573,23 +616,29 @@ export class ExistStaleOracles {
|
|
|
573
616
|
this.dummyField = fields.dummyField;
|
|
574
617
|
}
|
|
575
618
|
static reified() {
|
|
619
|
+
const reifiedBcs = ExistStaleOracles.bcs;
|
|
576
620
|
return {
|
|
577
|
-
typeName
|
|
578
|
-
|
|
621
|
+
get typeName() {
|
|
622
|
+
return ExistStaleOracles.$typeName;
|
|
623
|
+
},
|
|
624
|
+
get fullTypeName() {
|
|
625
|
+
return composeSuiType(ExistStaleOracles.$typeName, ...[]);
|
|
626
|
+
},
|
|
579
627
|
typeArgs: [],
|
|
580
628
|
isPhantom: ExistStaleOracles.$isPhantom,
|
|
581
629
|
reifiedTypeArgs: [],
|
|
582
630
|
fromFields: (fields) => ExistStaleOracles.fromFields(fields),
|
|
583
631
|
fromFieldsWithTypes: (item) => ExistStaleOracles.fromFieldsWithTypes(item),
|
|
584
|
-
fromBcs: (data) => ExistStaleOracles.
|
|
585
|
-
bcs:
|
|
632
|
+
fromBcs: (data) => ExistStaleOracles.fromFields(reifiedBcs.parse(data)),
|
|
633
|
+
bcs: reifiedBcs,
|
|
586
634
|
fromJSONField: (field) => ExistStaleOracles.fromJSONField(field),
|
|
587
635
|
fromJSON: (json) => ExistStaleOracles.fromJSON(json),
|
|
636
|
+
fromCoreObject: (obj) => ExistStaleOracles.fromCoreObject(obj),
|
|
588
637
|
fetch: async (client, id) => ExistStaleOracles.fetch(client, id),
|
|
589
638
|
new: (fields) => {
|
|
590
639
|
return new ExistStaleOracles([], fields);
|
|
591
640
|
},
|
|
592
|
-
kind:
|
|
641
|
+
kind: 'StructClassReified',
|
|
593
642
|
};
|
|
594
643
|
}
|
|
595
644
|
static get r() {
|
|
@@ -601,22 +650,29 @@ export class ExistStaleOracles {
|
|
|
601
650
|
static get p() {
|
|
602
651
|
return ExistStaleOracles.phantom();
|
|
603
652
|
}
|
|
604
|
-
static
|
|
605
|
-
return bcs.struct(
|
|
653
|
+
static instantiateBcs() {
|
|
654
|
+
return bcs.struct('ExistStaleOracles', {
|
|
606
655
|
dummy_field: bcs.bool(),
|
|
607
656
|
});
|
|
608
657
|
}
|
|
658
|
+
static cachedBcs = null;
|
|
659
|
+
static get bcs() {
|
|
660
|
+
if (!ExistStaleOracles.cachedBcs) {
|
|
661
|
+
ExistStaleOracles.cachedBcs = ExistStaleOracles.instantiateBcs();
|
|
662
|
+
}
|
|
663
|
+
return ExistStaleOracles.cachedBcs;
|
|
664
|
+
}
|
|
609
665
|
static fromFields(fields) {
|
|
610
666
|
return ExistStaleOracles.reified().new({
|
|
611
|
-
dummyField: decodeFromFields(
|
|
667
|
+
dummyField: decodeFromFields('bool', fields.dummy_field),
|
|
612
668
|
});
|
|
613
669
|
}
|
|
614
670
|
static fromFieldsWithTypes(item) {
|
|
615
671
|
if (!isExistStaleOracles(item.type)) {
|
|
616
|
-
throw new Error(
|
|
672
|
+
throw new Error('not a ExistStaleOracles type');
|
|
617
673
|
}
|
|
618
674
|
return ExistStaleOracles.reified().new({
|
|
619
|
-
dummyField: decodeFromFieldsWithTypes(
|
|
675
|
+
dummyField: decodeFromFieldsWithTypes('bool', item.fields.dummy_field),
|
|
620
676
|
});
|
|
621
677
|
}
|
|
622
678
|
static fromBcs(data) {
|
|
@@ -628,241 +684,47 @@ export class ExistStaleOracles {
|
|
|
628
684
|
};
|
|
629
685
|
}
|
|
630
686
|
toJSON() {
|
|
631
|
-
return {
|
|
632
|
-
$typeName: this.$typeName,
|
|
633
|
-
$typeArgs: this.$typeArgs,
|
|
634
|
-
...this.toJSONField(),
|
|
635
|
-
};
|
|
687
|
+
return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
|
|
636
688
|
}
|
|
637
689
|
static fromJSONField(field) {
|
|
638
690
|
return ExistStaleOracles.reified().new({
|
|
639
|
-
dummyField: decodeFromJSONField(
|
|
691
|
+
dummyField: decodeFromJSONField('bool', field.dummyField),
|
|
640
692
|
});
|
|
641
693
|
}
|
|
642
694
|
static fromJSON(json) {
|
|
643
695
|
if (json.$typeName !== ExistStaleOracles.$typeName) {
|
|
644
|
-
throw new Error(
|
|
696
|
+
throw new Error(`not a ExistStaleOracles json object: expected '${ExistStaleOracles.$typeName}' but got '${json.$typeName}'`);
|
|
645
697
|
}
|
|
646
698
|
return ExistStaleOracles.fromJSONField(json);
|
|
647
699
|
}
|
|
648
|
-
static
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
throw new Error(`object at id ${id} is not a ExistStaleOracles object`);
|
|
652
|
-
}
|
|
653
|
-
return ExistStaleOracles.fromBcs(object.content);
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
/* ============================== Obligation =============================== */
|
|
657
|
-
export function isObligation(type) {
|
|
658
|
-
type = compressSuiType(type);
|
|
659
|
-
return type.startsWith(`${PKG_V1}::obligation::Obligation` + "<");
|
|
660
|
-
}
|
|
661
|
-
export class Obligation {
|
|
662
|
-
__StructClass = true;
|
|
663
|
-
static $typeName = `${PKG_V1}::obligation::Obligation`;
|
|
664
|
-
static $numTypeParams = 1;
|
|
665
|
-
static $isPhantom = [true];
|
|
666
|
-
$typeName = Obligation.$typeName;
|
|
667
|
-
$fullTypeName;
|
|
668
|
-
$typeArgs;
|
|
669
|
-
$isPhantom = Obligation.$isPhantom;
|
|
670
|
-
id;
|
|
671
|
-
lendingMarketId;
|
|
672
|
-
deposits;
|
|
673
|
-
borrows;
|
|
674
|
-
depositedValueUsd;
|
|
675
|
-
allowedBorrowValueUsd;
|
|
676
|
-
unhealthyBorrowValueUsd;
|
|
677
|
-
superUnhealthyBorrowValueUsd;
|
|
678
|
-
unweightedBorrowedValueUsd;
|
|
679
|
-
weightedBorrowedValueUsd;
|
|
680
|
-
weightedBorrowedValueUpperBoundUsd;
|
|
681
|
-
borrowingIsolatedAsset;
|
|
682
|
-
userRewardManagers;
|
|
683
|
-
badDebtUsd;
|
|
684
|
-
closable;
|
|
685
|
-
constructor(typeArgs, fields) {
|
|
686
|
-
this.$fullTypeName = composeSuiType(Obligation.$typeName, ...typeArgs);
|
|
687
|
-
this.$typeArgs = typeArgs;
|
|
688
|
-
this.id = fields.id;
|
|
689
|
-
this.lendingMarketId = fields.lendingMarketId;
|
|
690
|
-
this.deposits = fields.deposits;
|
|
691
|
-
this.borrows = fields.borrows;
|
|
692
|
-
this.depositedValueUsd = fields.depositedValueUsd;
|
|
693
|
-
this.allowedBorrowValueUsd = fields.allowedBorrowValueUsd;
|
|
694
|
-
this.unhealthyBorrowValueUsd = fields.unhealthyBorrowValueUsd;
|
|
695
|
-
this.superUnhealthyBorrowValueUsd = fields.superUnhealthyBorrowValueUsd;
|
|
696
|
-
this.unweightedBorrowedValueUsd = fields.unweightedBorrowedValueUsd;
|
|
697
|
-
this.weightedBorrowedValueUsd = fields.weightedBorrowedValueUsd;
|
|
698
|
-
this.weightedBorrowedValueUpperBoundUsd =
|
|
699
|
-
fields.weightedBorrowedValueUpperBoundUsd;
|
|
700
|
-
this.borrowingIsolatedAsset = fields.borrowingIsolatedAsset;
|
|
701
|
-
this.userRewardManagers = fields.userRewardManagers;
|
|
702
|
-
this.badDebtUsd = fields.badDebtUsd;
|
|
703
|
-
this.closable = fields.closable;
|
|
704
|
-
}
|
|
705
|
-
static reified(P) {
|
|
706
|
-
return {
|
|
707
|
-
typeName: Obligation.$typeName,
|
|
708
|
-
fullTypeName: composeSuiType(Obligation.$typeName, ...[extractType(P)]),
|
|
709
|
-
typeArgs: [extractType(P)],
|
|
710
|
-
isPhantom: Obligation.$isPhantom,
|
|
711
|
-
reifiedTypeArgs: [P],
|
|
712
|
-
fromFields: (fields) => Obligation.fromFields(P, fields),
|
|
713
|
-
fromFieldsWithTypes: (item) => Obligation.fromFieldsWithTypes(P, item),
|
|
714
|
-
fromBcs: (data) => Obligation.fromBcs(P, data),
|
|
715
|
-
bcs: Obligation.bcs,
|
|
716
|
-
fromJSONField: (field) => Obligation.fromJSONField(P, field),
|
|
717
|
-
fromJSON: (json) => Obligation.fromJSON(P, json),
|
|
718
|
-
fetch: async (client, id) => Obligation.fetch(client, P, id),
|
|
719
|
-
new: (fields) => {
|
|
720
|
-
return new Obligation([extractType(P)], fields);
|
|
721
|
-
},
|
|
722
|
-
kind: "StructClassReified",
|
|
723
|
-
};
|
|
724
|
-
}
|
|
725
|
-
static get r() {
|
|
726
|
-
return Obligation.reified;
|
|
727
|
-
}
|
|
728
|
-
static phantom(P) {
|
|
729
|
-
return phantom(Obligation.reified(P));
|
|
730
|
-
}
|
|
731
|
-
static get p() {
|
|
732
|
-
return Obligation.phantom;
|
|
733
|
-
}
|
|
734
|
-
static get bcs() {
|
|
735
|
-
return bcs.struct("Obligation", {
|
|
736
|
-
id: UID.bcs,
|
|
737
|
-
lending_market_id: ID.bcs,
|
|
738
|
-
deposits: bcs.vector(Deposit.bcs),
|
|
739
|
-
borrows: bcs.vector(Borrow.bcs),
|
|
740
|
-
deposited_value_usd: Decimal.bcs,
|
|
741
|
-
allowed_borrow_value_usd: Decimal.bcs,
|
|
742
|
-
unhealthy_borrow_value_usd: Decimal.bcs,
|
|
743
|
-
super_unhealthy_borrow_value_usd: Decimal.bcs,
|
|
744
|
-
unweighted_borrowed_value_usd: Decimal.bcs,
|
|
745
|
-
weighted_borrowed_value_usd: Decimal.bcs,
|
|
746
|
-
weighted_borrowed_value_upper_bound_usd: Decimal.bcs,
|
|
747
|
-
borrowing_isolated_asset: bcs.bool(),
|
|
748
|
-
user_reward_managers: bcs.vector(UserRewardManager.bcs),
|
|
749
|
-
bad_debt_usd: Decimal.bcs,
|
|
750
|
-
closable: bcs.bool(),
|
|
751
|
-
});
|
|
752
|
-
}
|
|
753
|
-
static fromFields(typeArg, fields) {
|
|
754
|
-
return Obligation.reified(typeArg).new({
|
|
755
|
-
id: decodeFromFields(UID.reified(), fields.id),
|
|
756
|
-
lendingMarketId: decodeFromFields(ID.reified(), fields.lending_market_id),
|
|
757
|
-
deposits: decodeFromFields(reified.vector(Deposit.reified()), fields.deposits),
|
|
758
|
-
borrows: decodeFromFields(reified.vector(Borrow.reified()), fields.borrows),
|
|
759
|
-
depositedValueUsd: decodeFromFields(Decimal.reified(), fields.deposited_value_usd),
|
|
760
|
-
allowedBorrowValueUsd: decodeFromFields(Decimal.reified(), fields.allowed_borrow_value_usd),
|
|
761
|
-
unhealthyBorrowValueUsd: decodeFromFields(Decimal.reified(), fields.unhealthy_borrow_value_usd),
|
|
762
|
-
superUnhealthyBorrowValueUsd: decodeFromFields(Decimal.reified(), fields.super_unhealthy_borrow_value_usd),
|
|
763
|
-
unweightedBorrowedValueUsd: decodeFromFields(Decimal.reified(), fields.unweighted_borrowed_value_usd),
|
|
764
|
-
weightedBorrowedValueUsd: decodeFromFields(Decimal.reified(), fields.weighted_borrowed_value_usd),
|
|
765
|
-
weightedBorrowedValueUpperBoundUsd: decodeFromFields(Decimal.reified(), fields.weighted_borrowed_value_upper_bound_usd),
|
|
766
|
-
borrowingIsolatedAsset: decodeFromFields("bool", fields.borrowing_isolated_asset),
|
|
767
|
-
userRewardManagers: decodeFromFields(reified.vector(UserRewardManager.reified()), fields.user_reward_managers),
|
|
768
|
-
badDebtUsd: decodeFromFields(Decimal.reified(), fields.bad_debt_usd),
|
|
769
|
-
closable: decodeFromFields("bool", fields.closable),
|
|
770
|
-
});
|
|
771
|
-
}
|
|
772
|
-
static fromFieldsWithTypes(typeArg, item) {
|
|
773
|
-
if (!isObligation(item.type)) {
|
|
774
|
-
throw new Error("not a Obligation type");
|
|
775
|
-
}
|
|
776
|
-
assertFieldsWithTypesArgsMatch(item, [typeArg]);
|
|
777
|
-
return Obligation.reified(typeArg).new({
|
|
778
|
-
id: decodeFromFieldsWithTypes(UID.reified(), item.fields.id),
|
|
779
|
-
lendingMarketId: decodeFromFieldsWithTypes(ID.reified(), item.fields.lending_market_id),
|
|
780
|
-
deposits: decodeFromFieldsWithTypes(reified.vector(Deposit.reified()), item.fields.deposits),
|
|
781
|
-
borrows: decodeFromFieldsWithTypes(reified.vector(Borrow.reified()), item.fields.borrows),
|
|
782
|
-
depositedValueUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.deposited_value_usd),
|
|
783
|
-
allowedBorrowValueUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.allowed_borrow_value_usd),
|
|
784
|
-
unhealthyBorrowValueUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.unhealthy_borrow_value_usd),
|
|
785
|
-
superUnhealthyBorrowValueUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.super_unhealthy_borrow_value_usd),
|
|
786
|
-
unweightedBorrowedValueUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.unweighted_borrowed_value_usd),
|
|
787
|
-
weightedBorrowedValueUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.weighted_borrowed_value_usd),
|
|
788
|
-
weightedBorrowedValueUpperBoundUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.weighted_borrowed_value_upper_bound_usd),
|
|
789
|
-
borrowingIsolatedAsset: decodeFromFieldsWithTypes("bool", item.fields.borrowing_isolated_asset),
|
|
790
|
-
userRewardManagers: decodeFromFieldsWithTypes(reified.vector(UserRewardManager.reified()), item.fields.user_reward_managers),
|
|
791
|
-
badDebtUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.bad_debt_usd),
|
|
792
|
-
closable: decodeFromFieldsWithTypes("bool", item.fields.closable),
|
|
793
|
-
});
|
|
794
|
-
}
|
|
795
|
-
static fromBcs(typeArg, data) {
|
|
796
|
-
return Obligation.fromFields(typeArg, Obligation.bcs.parse(data));
|
|
797
|
-
}
|
|
798
|
-
toJSONField() {
|
|
799
|
-
return {
|
|
800
|
-
id: this.id,
|
|
801
|
-
lendingMarketId: this.lendingMarketId,
|
|
802
|
-
deposits: fieldToJSON(`vector<${Deposit.$typeName}>`, this.deposits),
|
|
803
|
-
borrows: fieldToJSON(`vector<${Borrow.$typeName}>`, this.borrows),
|
|
804
|
-
depositedValueUsd: this.depositedValueUsd.toJSONField(),
|
|
805
|
-
allowedBorrowValueUsd: this.allowedBorrowValueUsd.toJSONField(),
|
|
806
|
-
unhealthyBorrowValueUsd: this.unhealthyBorrowValueUsd.toJSONField(),
|
|
807
|
-
superUnhealthyBorrowValueUsd: this.superUnhealthyBorrowValueUsd.toJSONField(),
|
|
808
|
-
unweightedBorrowedValueUsd: this.unweightedBorrowedValueUsd.toJSONField(),
|
|
809
|
-
weightedBorrowedValueUsd: this.weightedBorrowedValueUsd.toJSONField(),
|
|
810
|
-
weightedBorrowedValueUpperBoundUsd: this.weightedBorrowedValueUpperBoundUsd.toJSONField(),
|
|
811
|
-
borrowingIsolatedAsset: this.borrowingIsolatedAsset,
|
|
812
|
-
userRewardManagers: fieldToJSON(`vector<${UserRewardManager.$typeName}>`, this.userRewardManagers),
|
|
813
|
-
badDebtUsd: this.badDebtUsd.toJSONField(),
|
|
814
|
-
closable: this.closable,
|
|
815
|
-
};
|
|
816
|
-
}
|
|
817
|
-
toJSON() {
|
|
818
|
-
return {
|
|
819
|
-
$typeName: this.$typeName,
|
|
820
|
-
$typeArgs: this.$typeArgs,
|
|
821
|
-
...this.toJSONField(),
|
|
822
|
-
};
|
|
823
|
-
}
|
|
824
|
-
static fromJSONField(typeArg, field) {
|
|
825
|
-
return Obligation.reified(typeArg).new({
|
|
826
|
-
id: decodeFromJSONField(UID.reified(), field.id),
|
|
827
|
-
lendingMarketId: decodeFromJSONField(ID.reified(), field.lendingMarketId),
|
|
828
|
-
deposits: decodeFromJSONField(reified.vector(Deposit.reified()), field.deposits),
|
|
829
|
-
borrows: decodeFromJSONField(reified.vector(Borrow.reified()), field.borrows),
|
|
830
|
-
depositedValueUsd: decodeFromJSONField(Decimal.reified(), field.depositedValueUsd),
|
|
831
|
-
allowedBorrowValueUsd: decodeFromJSONField(Decimal.reified(), field.allowedBorrowValueUsd),
|
|
832
|
-
unhealthyBorrowValueUsd: decodeFromJSONField(Decimal.reified(), field.unhealthyBorrowValueUsd),
|
|
833
|
-
superUnhealthyBorrowValueUsd: decodeFromJSONField(Decimal.reified(), field.superUnhealthyBorrowValueUsd),
|
|
834
|
-
unweightedBorrowedValueUsd: decodeFromJSONField(Decimal.reified(), field.unweightedBorrowedValueUsd),
|
|
835
|
-
weightedBorrowedValueUsd: decodeFromJSONField(Decimal.reified(), field.weightedBorrowedValueUsd),
|
|
836
|
-
weightedBorrowedValueUpperBoundUsd: decodeFromJSONField(Decimal.reified(), field.weightedBorrowedValueUpperBoundUsd),
|
|
837
|
-
borrowingIsolatedAsset: decodeFromJSONField("bool", field.borrowingIsolatedAsset),
|
|
838
|
-
userRewardManagers: decodeFromJSONField(reified.vector(UserRewardManager.reified()), field.userRewardManagers),
|
|
839
|
-
badDebtUsd: decodeFromJSONField(Decimal.reified(), field.badDebtUsd),
|
|
840
|
-
closable: decodeFromJSONField("bool", field.closable),
|
|
841
|
-
});
|
|
842
|
-
}
|
|
843
|
-
static fromJSON(typeArg, json) {
|
|
844
|
-
if (json.$typeName !== Obligation.$typeName) {
|
|
845
|
-
throw new Error("not a WithTwoGenerics json object");
|
|
700
|
+
static fromCoreObject(obj) {
|
|
701
|
+
if (!isExistStaleOracles(obj.type)) {
|
|
702
|
+
throw new Error(`object at ${obj.objectId} is not a ExistStaleOracles object`);
|
|
846
703
|
}
|
|
847
|
-
|
|
848
|
-
return Obligation.fromJSONField(typeArg, json);
|
|
704
|
+
return ExistStaleOracles.fromBcs(obj.content);
|
|
849
705
|
}
|
|
850
|
-
static async fetch(client,
|
|
851
|
-
const { object } = await client.getObject({
|
|
852
|
-
|
|
853
|
-
|
|
706
|
+
static async fetch(client, id) {
|
|
707
|
+
const { object } = await client.core.getObject({
|
|
708
|
+
objectId: id,
|
|
709
|
+
include: { content: true },
|
|
710
|
+
});
|
|
711
|
+
if (!isExistStaleOracles(object.type)) {
|
|
712
|
+
throw new Error(`object at id ${id} is not a ExistStaleOracles object`);
|
|
854
713
|
}
|
|
855
|
-
return
|
|
714
|
+
return ExistStaleOracles.fromBcs(object.content);
|
|
856
715
|
}
|
|
857
716
|
}
|
|
858
717
|
/* ============================== ObligationDataEvent =============================== */
|
|
859
718
|
export function isObligationDataEvent(type) {
|
|
860
719
|
type = compressSuiType(type);
|
|
861
|
-
return type
|
|
720
|
+
return type
|
|
721
|
+
=== `${getTypeOrigin('suilend', 'obligation::ObligationDataEvent')}::obligation::ObligationDataEvent`;
|
|
862
722
|
}
|
|
863
723
|
export class ObligationDataEvent {
|
|
864
724
|
__StructClass = true;
|
|
865
|
-
static $typeName
|
|
725
|
+
static get $typeName() {
|
|
726
|
+
return `${getTypeOrigin('suilend', 'obligation::ObligationDataEvent')}::obligation::ObligationDataEvent`;
|
|
727
|
+
}
|
|
866
728
|
static $numTypeParams = 0;
|
|
867
729
|
static $isPhantom = [];
|
|
868
730
|
$typeName = ObligationDataEvent.$typeName;
|
|
@@ -896,30 +758,35 @@ export class ObligationDataEvent {
|
|
|
896
758
|
this.superUnhealthyBorrowValueUsd = fields.superUnhealthyBorrowValueUsd;
|
|
897
759
|
this.unweightedBorrowedValueUsd = fields.unweightedBorrowedValueUsd;
|
|
898
760
|
this.weightedBorrowedValueUsd = fields.weightedBorrowedValueUsd;
|
|
899
|
-
this.weightedBorrowedValueUpperBoundUsd =
|
|
900
|
-
fields.weightedBorrowedValueUpperBoundUsd;
|
|
761
|
+
this.weightedBorrowedValueUpperBoundUsd = fields.weightedBorrowedValueUpperBoundUsd;
|
|
901
762
|
this.borrowingIsolatedAsset = fields.borrowingIsolatedAsset;
|
|
902
763
|
this.badDebtUsd = fields.badDebtUsd;
|
|
903
764
|
this.closable = fields.closable;
|
|
904
765
|
}
|
|
905
766
|
static reified() {
|
|
767
|
+
const reifiedBcs = ObligationDataEvent.bcs;
|
|
906
768
|
return {
|
|
907
|
-
typeName
|
|
908
|
-
|
|
769
|
+
get typeName() {
|
|
770
|
+
return ObligationDataEvent.$typeName;
|
|
771
|
+
},
|
|
772
|
+
get fullTypeName() {
|
|
773
|
+
return composeSuiType(ObligationDataEvent.$typeName, ...[]);
|
|
774
|
+
},
|
|
909
775
|
typeArgs: [],
|
|
910
776
|
isPhantom: ObligationDataEvent.$isPhantom,
|
|
911
777
|
reifiedTypeArgs: [],
|
|
912
778
|
fromFields: (fields) => ObligationDataEvent.fromFields(fields),
|
|
913
779
|
fromFieldsWithTypes: (item) => ObligationDataEvent.fromFieldsWithTypes(item),
|
|
914
|
-
fromBcs: (data) => ObligationDataEvent.
|
|
915
|
-
bcs:
|
|
780
|
+
fromBcs: (data) => ObligationDataEvent.fromFields(reifiedBcs.parse(data)),
|
|
781
|
+
bcs: reifiedBcs,
|
|
916
782
|
fromJSONField: (field) => ObligationDataEvent.fromJSONField(field),
|
|
917
783
|
fromJSON: (json) => ObligationDataEvent.fromJSON(json),
|
|
784
|
+
fromCoreObject: (obj) => ObligationDataEvent.fromCoreObject(obj),
|
|
918
785
|
fetch: async (client, id) => ObligationDataEvent.fetch(client, id),
|
|
919
786
|
new: (fields) => {
|
|
920
787
|
return new ObligationDataEvent([], fields);
|
|
921
788
|
},
|
|
922
|
-
kind:
|
|
789
|
+
kind: 'StructClassReified',
|
|
923
790
|
};
|
|
924
791
|
}
|
|
925
792
|
static get r() {
|
|
@@ -931,17 +798,13 @@ export class ObligationDataEvent {
|
|
|
931
798
|
static get p() {
|
|
932
799
|
return ObligationDataEvent.phantom();
|
|
933
800
|
}
|
|
934
|
-
static
|
|
935
|
-
return bcs.struct(
|
|
936
|
-
lending_market_id: bcs
|
|
937
|
-
.bytes(32)
|
|
938
|
-
.transform({
|
|
801
|
+
static instantiateBcs() {
|
|
802
|
+
return bcs.struct('ObligationDataEvent', {
|
|
803
|
+
lending_market_id: bcs.bytes(32).transform({
|
|
939
804
|
input: (val) => fromHex(val),
|
|
940
805
|
output: (val) => toHex(val),
|
|
941
806
|
}),
|
|
942
|
-
obligation_id: bcs
|
|
943
|
-
.bytes(32)
|
|
944
|
-
.transform({
|
|
807
|
+
obligation_id: bcs.bytes(32).transform({
|
|
945
808
|
input: (val) => fromHex(val),
|
|
946
809
|
output: (val) => toHex(val),
|
|
947
810
|
}),
|
|
@@ -959,12 +822,19 @@ export class ObligationDataEvent {
|
|
|
959
822
|
closable: bcs.bool(),
|
|
960
823
|
});
|
|
961
824
|
}
|
|
825
|
+
static cachedBcs = null;
|
|
826
|
+
static get bcs() {
|
|
827
|
+
if (!ObligationDataEvent.cachedBcs) {
|
|
828
|
+
ObligationDataEvent.cachedBcs = ObligationDataEvent.instantiateBcs();
|
|
829
|
+
}
|
|
830
|
+
return ObligationDataEvent.cachedBcs;
|
|
831
|
+
}
|
|
962
832
|
static fromFields(fields) {
|
|
963
833
|
return ObligationDataEvent.reified().new({
|
|
964
|
-
lendingMarketId: decodeFromFields(
|
|
965
|
-
obligationId: decodeFromFields(
|
|
966
|
-
deposits: decodeFromFields(
|
|
967
|
-
borrows: decodeFromFields(
|
|
834
|
+
lendingMarketId: decodeFromFields('address', fields.lending_market_id),
|
|
835
|
+
obligationId: decodeFromFields('address', fields.obligation_id),
|
|
836
|
+
deposits: decodeFromFields(vector(DepositRecord.reified()), fields.deposits),
|
|
837
|
+
borrows: decodeFromFields(vector(BorrowRecord.reified()), fields.borrows),
|
|
968
838
|
depositedValueUsd: decodeFromFields(Decimal.reified(), fields.deposited_value_usd),
|
|
969
839
|
allowedBorrowValueUsd: decodeFromFields(Decimal.reified(), fields.allowed_borrow_value_usd),
|
|
970
840
|
unhealthyBorrowValueUsd: decodeFromFields(Decimal.reified(), fields.unhealthy_borrow_value_usd),
|
|
@@ -972,20 +842,20 @@ export class ObligationDataEvent {
|
|
|
972
842
|
unweightedBorrowedValueUsd: decodeFromFields(Decimal.reified(), fields.unweighted_borrowed_value_usd),
|
|
973
843
|
weightedBorrowedValueUsd: decodeFromFields(Decimal.reified(), fields.weighted_borrowed_value_usd),
|
|
974
844
|
weightedBorrowedValueUpperBoundUsd: decodeFromFields(Decimal.reified(), fields.weighted_borrowed_value_upper_bound_usd),
|
|
975
|
-
borrowingIsolatedAsset: decodeFromFields(
|
|
845
|
+
borrowingIsolatedAsset: decodeFromFields('bool', fields.borrowing_isolated_asset),
|
|
976
846
|
badDebtUsd: decodeFromFields(Decimal.reified(), fields.bad_debt_usd),
|
|
977
|
-
closable: decodeFromFields(
|
|
847
|
+
closable: decodeFromFields('bool', fields.closable),
|
|
978
848
|
});
|
|
979
849
|
}
|
|
980
850
|
static fromFieldsWithTypes(item) {
|
|
981
851
|
if (!isObligationDataEvent(item.type)) {
|
|
982
|
-
throw new Error(
|
|
852
|
+
throw new Error('not a ObligationDataEvent type');
|
|
983
853
|
}
|
|
984
854
|
return ObligationDataEvent.reified().new({
|
|
985
|
-
lendingMarketId: decodeFromFieldsWithTypes(
|
|
986
|
-
obligationId: decodeFromFieldsWithTypes(
|
|
987
|
-
deposits: decodeFromFieldsWithTypes(
|
|
988
|
-
borrows: decodeFromFieldsWithTypes(
|
|
855
|
+
lendingMarketId: decodeFromFieldsWithTypes('address', item.fields.lending_market_id),
|
|
856
|
+
obligationId: decodeFromFieldsWithTypes('address', item.fields.obligation_id),
|
|
857
|
+
deposits: decodeFromFieldsWithTypes(vector(DepositRecord.reified()), item.fields.deposits),
|
|
858
|
+
borrows: decodeFromFieldsWithTypes(vector(BorrowRecord.reified()), item.fields.borrows),
|
|
989
859
|
depositedValueUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.deposited_value_usd),
|
|
990
860
|
allowedBorrowValueUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.allowed_borrow_value_usd),
|
|
991
861
|
unhealthyBorrowValueUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.unhealthy_borrow_value_usd),
|
|
@@ -993,9 +863,9 @@ export class ObligationDataEvent {
|
|
|
993
863
|
unweightedBorrowedValueUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.unweighted_borrowed_value_usd),
|
|
994
864
|
weightedBorrowedValueUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.weighted_borrowed_value_usd),
|
|
995
865
|
weightedBorrowedValueUpperBoundUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.weighted_borrowed_value_upper_bound_usd),
|
|
996
|
-
borrowingIsolatedAsset: decodeFromFieldsWithTypes(
|
|
866
|
+
borrowingIsolatedAsset: decodeFromFieldsWithTypes('bool', item.fields.borrowing_isolated_asset),
|
|
997
867
|
badDebtUsd: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.bad_debt_usd),
|
|
998
|
-
closable: decodeFromFieldsWithTypes(
|
|
868
|
+
closable: decodeFromFieldsWithTypes('bool', item.fields.closable),
|
|
999
869
|
});
|
|
1000
870
|
}
|
|
1001
871
|
static fromBcs(data) {
|
|
@@ -1020,18 +890,14 @@ export class ObligationDataEvent {
|
|
|
1020
890
|
};
|
|
1021
891
|
}
|
|
1022
892
|
toJSON() {
|
|
1023
|
-
return {
|
|
1024
|
-
$typeName: this.$typeName,
|
|
1025
|
-
$typeArgs: this.$typeArgs,
|
|
1026
|
-
...this.toJSONField(),
|
|
1027
|
-
};
|
|
893
|
+
return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
|
|
1028
894
|
}
|
|
1029
895
|
static fromJSONField(field) {
|
|
1030
896
|
return ObligationDataEvent.reified().new({
|
|
1031
|
-
lendingMarketId: decodeFromJSONField(
|
|
1032
|
-
obligationId: decodeFromJSONField(
|
|
1033
|
-
deposits: decodeFromJSONField(
|
|
1034
|
-
borrows: decodeFromJSONField(
|
|
897
|
+
lendingMarketId: decodeFromJSONField('address', field.lendingMarketId),
|
|
898
|
+
obligationId: decodeFromJSONField('address', field.obligationId),
|
|
899
|
+
deposits: decodeFromJSONField(vector(DepositRecord.reified()), field.deposits),
|
|
900
|
+
borrows: decodeFromJSONField(vector(BorrowRecord.reified()), field.borrows),
|
|
1035
901
|
depositedValueUsd: decodeFromJSONField(Decimal.reified(), field.depositedValueUsd),
|
|
1036
902
|
allowedBorrowValueUsd: decodeFromJSONField(Decimal.reified(), field.allowedBorrowValueUsd),
|
|
1037
903
|
unhealthyBorrowValueUsd: decodeFromJSONField(Decimal.reified(), field.unhealthyBorrowValueUsd),
|
|
@@ -1039,22 +905,346 @@ export class ObligationDataEvent {
|
|
|
1039
905
|
unweightedBorrowedValueUsd: decodeFromJSONField(Decimal.reified(), field.unweightedBorrowedValueUsd),
|
|
1040
906
|
weightedBorrowedValueUsd: decodeFromJSONField(Decimal.reified(), field.weightedBorrowedValueUsd),
|
|
1041
907
|
weightedBorrowedValueUpperBoundUsd: decodeFromJSONField(Decimal.reified(), field.weightedBorrowedValueUpperBoundUsd),
|
|
1042
|
-
borrowingIsolatedAsset: decodeFromJSONField(
|
|
908
|
+
borrowingIsolatedAsset: decodeFromJSONField('bool', field.borrowingIsolatedAsset),
|
|
1043
909
|
badDebtUsd: decodeFromJSONField(Decimal.reified(), field.badDebtUsd),
|
|
1044
|
-
closable: decodeFromJSONField(
|
|
910
|
+
closable: decodeFromJSONField('bool', field.closable),
|
|
1045
911
|
});
|
|
1046
912
|
}
|
|
1047
913
|
static fromJSON(json) {
|
|
1048
914
|
if (json.$typeName !== ObligationDataEvent.$typeName) {
|
|
1049
|
-
throw new Error(
|
|
915
|
+
throw new Error(`not a ObligationDataEvent json object: expected '${ObligationDataEvent.$typeName}' but got '${json.$typeName}'`);
|
|
1050
916
|
}
|
|
1051
917
|
return ObligationDataEvent.fromJSONField(json);
|
|
1052
918
|
}
|
|
919
|
+
static fromCoreObject(obj) {
|
|
920
|
+
if (!isObligationDataEvent(obj.type)) {
|
|
921
|
+
throw new Error(`object at ${obj.objectId} is not a ObligationDataEvent object`);
|
|
922
|
+
}
|
|
923
|
+
return ObligationDataEvent.fromBcs(obj.content);
|
|
924
|
+
}
|
|
1053
925
|
static async fetch(client, id) {
|
|
1054
|
-
const { object } = await client.getObject({
|
|
926
|
+
const { object } = await client.core.getObject({
|
|
927
|
+
objectId: id,
|
|
928
|
+
include: { content: true },
|
|
929
|
+
});
|
|
1055
930
|
if (!isObligationDataEvent(object.type)) {
|
|
1056
931
|
throw new Error(`object at id ${id} is not a ObligationDataEvent object`);
|
|
1057
932
|
}
|
|
1058
933
|
return ObligationDataEvent.fromBcs(object.content);
|
|
1059
934
|
}
|
|
1060
935
|
}
|
|
936
|
+
/* ============================== DepositRecord =============================== */
|
|
937
|
+
export function isDepositRecord(type) {
|
|
938
|
+
type = compressSuiType(type);
|
|
939
|
+
return type
|
|
940
|
+
=== `${getTypeOrigin('suilend', 'obligation::DepositRecord')}::obligation::DepositRecord`;
|
|
941
|
+
}
|
|
942
|
+
export class DepositRecord {
|
|
943
|
+
__StructClass = true;
|
|
944
|
+
static get $typeName() {
|
|
945
|
+
return `${getTypeOrigin('suilend', 'obligation::DepositRecord')}::obligation::DepositRecord`;
|
|
946
|
+
}
|
|
947
|
+
static $numTypeParams = 0;
|
|
948
|
+
static $isPhantom = [];
|
|
949
|
+
$typeName = DepositRecord.$typeName;
|
|
950
|
+
$fullTypeName;
|
|
951
|
+
$typeArgs;
|
|
952
|
+
$isPhantom = DepositRecord.$isPhantom;
|
|
953
|
+
coinType;
|
|
954
|
+
reserveArrayIndex;
|
|
955
|
+
depositedCtokenAmount;
|
|
956
|
+
marketValue;
|
|
957
|
+
userRewardManagerIndex;
|
|
958
|
+
/** unused */
|
|
959
|
+
attributedBorrowValue;
|
|
960
|
+
constructor(typeArgs, fields) {
|
|
961
|
+
this.$fullTypeName = composeSuiType(DepositRecord.$typeName, ...typeArgs);
|
|
962
|
+
this.$typeArgs = typeArgs;
|
|
963
|
+
this.coinType = fields.coinType;
|
|
964
|
+
this.reserveArrayIndex = fields.reserveArrayIndex;
|
|
965
|
+
this.depositedCtokenAmount = fields.depositedCtokenAmount;
|
|
966
|
+
this.marketValue = fields.marketValue;
|
|
967
|
+
this.userRewardManagerIndex = fields.userRewardManagerIndex;
|
|
968
|
+
this.attributedBorrowValue = fields.attributedBorrowValue;
|
|
969
|
+
}
|
|
970
|
+
static reified() {
|
|
971
|
+
const reifiedBcs = DepositRecord.bcs;
|
|
972
|
+
return {
|
|
973
|
+
get typeName() {
|
|
974
|
+
return DepositRecord.$typeName;
|
|
975
|
+
},
|
|
976
|
+
get fullTypeName() {
|
|
977
|
+
return composeSuiType(DepositRecord.$typeName, ...[]);
|
|
978
|
+
},
|
|
979
|
+
typeArgs: [],
|
|
980
|
+
isPhantom: DepositRecord.$isPhantom,
|
|
981
|
+
reifiedTypeArgs: [],
|
|
982
|
+
fromFields: (fields) => DepositRecord.fromFields(fields),
|
|
983
|
+
fromFieldsWithTypes: (item) => DepositRecord.fromFieldsWithTypes(item),
|
|
984
|
+
fromBcs: (data) => DepositRecord.fromFields(reifiedBcs.parse(data)),
|
|
985
|
+
bcs: reifiedBcs,
|
|
986
|
+
fromJSONField: (field) => DepositRecord.fromJSONField(field),
|
|
987
|
+
fromJSON: (json) => DepositRecord.fromJSON(json),
|
|
988
|
+
fromCoreObject: (obj) => DepositRecord.fromCoreObject(obj),
|
|
989
|
+
fetch: async (client, id) => DepositRecord.fetch(client, id),
|
|
990
|
+
new: (fields) => {
|
|
991
|
+
return new DepositRecord([], fields);
|
|
992
|
+
},
|
|
993
|
+
kind: 'StructClassReified',
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
static get r() {
|
|
997
|
+
return DepositRecord.reified();
|
|
998
|
+
}
|
|
999
|
+
static phantom() {
|
|
1000
|
+
return phantom(DepositRecord.reified());
|
|
1001
|
+
}
|
|
1002
|
+
static get p() {
|
|
1003
|
+
return DepositRecord.phantom();
|
|
1004
|
+
}
|
|
1005
|
+
static instantiateBcs() {
|
|
1006
|
+
return bcs.struct('DepositRecord', {
|
|
1007
|
+
coin_type: TypeName.bcs,
|
|
1008
|
+
reserve_array_index: bcs.u64(),
|
|
1009
|
+
deposited_ctoken_amount: bcs.u64(),
|
|
1010
|
+
market_value: Decimal.bcs,
|
|
1011
|
+
user_reward_manager_index: bcs.u64(),
|
|
1012
|
+
attributed_borrow_value: Decimal.bcs,
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
static cachedBcs = null;
|
|
1016
|
+
static get bcs() {
|
|
1017
|
+
if (!DepositRecord.cachedBcs) {
|
|
1018
|
+
DepositRecord.cachedBcs = DepositRecord.instantiateBcs();
|
|
1019
|
+
}
|
|
1020
|
+
return DepositRecord.cachedBcs;
|
|
1021
|
+
}
|
|
1022
|
+
static fromFields(fields) {
|
|
1023
|
+
return DepositRecord.reified().new({
|
|
1024
|
+
coinType: decodeFromFields(TypeName.reified(), fields.coin_type),
|
|
1025
|
+
reserveArrayIndex: decodeFromFields('u64', fields.reserve_array_index),
|
|
1026
|
+
depositedCtokenAmount: decodeFromFields('u64', fields.deposited_ctoken_amount),
|
|
1027
|
+
marketValue: decodeFromFields(Decimal.reified(), fields.market_value),
|
|
1028
|
+
userRewardManagerIndex: decodeFromFields('u64', fields.user_reward_manager_index),
|
|
1029
|
+
attributedBorrowValue: decodeFromFields(Decimal.reified(), fields.attributed_borrow_value),
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
static fromFieldsWithTypes(item) {
|
|
1033
|
+
if (!isDepositRecord(item.type)) {
|
|
1034
|
+
throw new Error('not a DepositRecord type');
|
|
1035
|
+
}
|
|
1036
|
+
return DepositRecord.reified().new({
|
|
1037
|
+
coinType: decodeFromFieldsWithTypes(TypeName.reified(), item.fields.coin_type),
|
|
1038
|
+
reserveArrayIndex: decodeFromFieldsWithTypes('u64', item.fields.reserve_array_index),
|
|
1039
|
+
depositedCtokenAmount: decodeFromFieldsWithTypes('u64', item.fields.deposited_ctoken_amount),
|
|
1040
|
+
marketValue: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.market_value),
|
|
1041
|
+
userRewardManagerIndex: decodeFromFieldsWithTypes('u64', item.fields.user_reward_manager_index),
|
|
1042
|
+
attributedBorrowValue: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.attributed_borrow_value),
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
static fromBcs(data) {
|
|
1046
|
+
return DepositRecord.fromFields(DepositRecord.bcs.parse(data));
|
|
1047
|
+
}
|
|
1048
|
+
toJSONField() {
|
|
1049
|
+
return {
|
|
1050
|
+
coinType: this.coinType,
|
|
1051
|
+
reserveArrayIndex: this.reserveArrayIndex.toString(),
|
|
1052
|
+
depositedCtokenAmount: this.depositedCtokenAmount.toString(),
|
|
1053
|
+
marketValue: this.marketValue.toJSONField(),
|
|
1054
|
+
userRewardManagerIndex: this.userRewardManagerIndex.toString(),
|
|
1055
|
+
attributedBorrowValue: this.attributedBorrowValue.toJSONField(),
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
toJSON() {
|
|
1059
|
+
return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
|
|
1060
|
+
}
|
|
1061
|
+
static fromJSONField(field) {
|
|
1062
|
+
return DepositRecord.reified().new({
|
|
1063
|
+
coinType: decodeFromJSONField(TypeName.reified(), field.coinType),
|
|
1064
|
+
reserveArrayIndex: decodeFromJSONField('u64', field.reserveArrayIndex),
|
|
1065
|
+
depositedCtokenAmount: decodeFromJSONField('u64', field.depositedCtokenAmount),
|
|
1066
|
+
marketValue: decodeFromJSONField(Decimal.reified(), field.marketValue),
|
|
1067
|
+
userRewardManagerIndex: decodeFromJSONField('u64', field.userRewardManagerIndex),
|
|
1068
|
+
attributedBorrowValue: decodeFromJSONField(Decimal.reified(), field.attributedBorrowValue),
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
static fromJSON(json) {
|
|
1072
|
+
if (json.$typeName !== DepositRecord.$typeName) {
|
|
1073
|
+
throw new Error(`not a DepositRecord json object: expected '${DepositRecord.$typeName}' but got '${json.$typeName}'`);
|
|
1074
|
+
}
|
|
1075
|
+
return DepositRecord.fromJSONField(json);
|
|
1076
|
+
}
|
|
1077
|
+
static fromCoreObject(obj) {
|
|
1078
|
+
if (!isDepositRecord(obj.type)) {
|
|
1079
|
+
throw new Error(`object at ${obj.objectId} is not a DepositRecord object`);
|
|
1080
|
+
}
|
|
1081
|
+
return DepositRecord.fromBcs(obj.content);
|
|
1082
|
+
}
|
|
1083
|
+
static async fetch(client, id) {
|
|
1084
|
+
const { object } = await client.core.getObject({
|
|
1085
|
+
objectId: id,
|
|
1086
|
+
include: { content: true },
|
|
1087
|
+
});
|
|
1088
|
+
if (!isDepositRecord(object.type)) {
|
|
1089
|
+
throw new Error(`object at id ${id} is not a DepositRecord object`);
|
|
1090
|
+
}
|
|
1091
|
+
return DepositRecord.fromBcs(object.content);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
/* ============================== BorrowRecord =============================== */
|
|
1095
|
+
export function isBorrowRecord(type) {
|
|
1096
|
+
type = compressSuiType(type);
|
|
1097
|
+
return type
|
|
1098
|
+
=== `${getTypeOrigin('suilend', 'obligation::BorrowRecord')}::obligation::BorrowRecord`;
|
|
1099
|
+
}
|
|
1100
|
+
export class BorrowRecord {
|
|
1101
|
+
__StructClass = true;
|
|
1102
|
+
static get $typeName() {
|
|
1103
|
+
return `${getTypeOrigin('suilend', 'obligation::BorrowRecord')}::obligation::BorrowRecord`;
|
|
1104
|
+
}
|
|
1105
|
+
static $numTypeParams = 0;
|
|
1106
|
+
static $isPhantom = [];
|
|
1107
|
+
$typeName = BorrowRecord.$typeName;
|
|
1108
|
+
$fullTypeName;
|
|
1109
|
+
$typeArgs;
|
|
1110
|
+
$isPhantom = BorrowRecord.$isPhantom;
|
|
1111
|
+
coinType;
|
|
1112
|
+
reserveArrayIndex;
|
|
1113
|
+
borrowedAmount;
|
|
1114
|
+
cumulativeBorrowRate;
|
|
1115
|
+
marketValue;
|
|
1116
|
+
userRewardManagerIndex;
|
|
1117
|
+
constructor(typeArgs, fields) {
|
|
1118
|
+
this.$fullTypeName = composeSuiType(BorrowRecord.$typeName, ...typeArgs);
|
|
1119
|
+
this.$typeArgs = typeArgs;
|
|
1120
|
+
this.coinType = fields.coinType;
|
|
1121
|
+
this.reserveArrayIndex = fields.reserveArrayIndex;
|
|
1122
|
+
this.borrowedAmount = fields.borrowedAmount;
|
|
1123
|
+
this.cumulativeBorrowRate = fields.cumulativeBorrowRate;
|
|
1124
|
+
this.marketValue = fields.marketValue;
|
|
1125
|
+
this.userRewardManagerIndex = fields.userRewardManagerIndex;
|
|
1126
|
+
}
|
|
1127
|
+
static reified() {
|
|
1128
|
+
const reifiedBcs = BorrowRecord.bcs;
|
|
1129
|
+
return {
|
|
1130
|
+
get typeName() {
|
|
1131
|
+
return BorrowRecord.$typeName;
|
|
1132
|
+
},
|
|
1133
|
+
get fullTypeName() {
|
|
1134
|
+
return composeSuiType(BorrowRecord.$typeName, ...[]);
|
|
1135
|
+
},
|
|
1136
|
+
typeArgs: [],
|
|
1137
|
+
isPhantom: BorrowRecord.$isPhantom,
|
|
1138
|
+
reifiedTypeArgs: [],
|
|
1139
|
+
fromFields: (fields) => BorrowRecord.fromFields(fields),
|
|
1140
|
+
fromFieldsWithTypes: (item) => BorrowRecord.fromFieldsWithTypes(item),
|
|
1141
|
+
fromBcs: (data) => BorrowRecord.fromFields(reifiedBcs.parse(data)),
|
|
1142
|
+
bcs: reifiedBcs,
|
|
1143
|
+
fromJSONField: (field) => BorrowRecord.fromJSONField(field),
|
|
1144
|
+
fromJSON: (json) => BorrowRecord.fromJSON(json),
|
|
1145
|
+
fromCoreObject: (obj) => BorrowRecord.fromCoreObject(obj),
|
|
1146
|
+
fetch: async (client, id) => BorrowRecord.fetch(client, id),
|
|
1147
|
+
new: (fields) => {
|
|
1148
|
+
return new BorrowRecord([], fields);
|
|
1149
|
+
},
|
|
1150
|
+
kind: 'StructClassReified',
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
1153
|
+
static get r() {
|
|
1154
|
+
return BorrowRecord.reified();
|
|
1155
|
+
}
|
|
1156
|
+
static phantom() {
|
|
1157
|
+
return phantom(BorrowRecord.reified());
|
|
1158
|
+
}
|
|
1159
|
+
static get p() {
|
|
1160
|
+
return BorrowRecord.phantom();
|
|
1161
|
+
}
|
|
1162
|
+
static instantiateBcs() {
|
|
1163
|
+
return bcs.struct('BorrowRecord', {
|
|
1164
|
+
coin_type: TypeName.bcs,
|
|
1165
|
+
reserve_array_index: bcs.u64(),
|
|
1166
|
+
borrowed_amount: Decimal.bcs,
|
|
1167
|
+
cumulative_borrow_rate: Decimal.bcs,
|
|
1168
|
+
market_value: Decimal.bcs,
|
|
1169
|
+
user_reward_manager_index: bcs.u64(),
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
static cachedBcs = null;
|
|
1173
|
+
static get bcs() {
|
|
1174
|
+
if (!BorrowRecord.cachedBcs) {
|
|
1175
|
+
BorrowRecord.cachedBcs = BorrowRecord.instantiateBcs();
|
|
1176
|
+
}
|
|
1177
|
+
return BorrowRecord.cachedBcs;
|
|
1178
|
+
}
|
|
1179
|
+
static fromFields(fields) {
|
|
1180
|
+
return BorrowRecord.reified().new({
|
|
1181
|
+
coinType: decodeFromFields(TypeName.reified(), fields.coin_type),
|
|
1182
|
+
reserveArrayIndex: decodeFromFields('u64', fields.reserve_array_index),
|
|
1183
|
+
borrowedAmount: decodeFromFields(Decimal.reified(), fields.borrowed_amount),
|
|
1184
|
+
cumulativeBorrowRate: decodeFromFields(Decimal.reified(), fields.cumulative_borrow_rate),
|
|
1185
|
+
marketValue: decodeFromFields(Decimal.reified(), fields.market_value),
|
|
1186
|
+
userRewardManagerIndex: decodeFromFields('u64', fields.user_reward_manager_index),
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
1189
|
+
static fromFieldsWithTypes(item) {
|
|
1190
|
+
if (!isBorrowRecord(item.type)) {
|
|
1191
|
+
throw new Error('not a BorrowRecord type');
|
|
1192
|
+
}
|
|
1193
|
+
return BorrowRecord.reified().new({
|
|
1194
|
+
coinType: decodeFromFieldsWithTypes(TypeName.reified(), item.fields.coin_type),
|
|
1195
|
+
reserveArrayIndex: decodeFromFieldsWithTypes('u64', item.fields.reserve_array_index),
|
|
1196
|
+
borrowedAmount: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.borrowed_amount),
|
|
1197
|
+
cumulativeBorrowRate: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.cumulative_borrow_rate),
|
|
1198
|
+
marketValue: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.market_value),
|
|
1199
|
+
userRewardManagerIndex: decodeFromFieldsWithTypes('u64', item.fields.user_reward_manager_index),
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
static fromBcs(data) {
|
|
1203
|
+
return BorrowRecord.fromFields(BorrowRecord.bcs.parse(data));
|
|
1204
|
+
}
|
|
1205
|
+
toJSONField() {
|
|
1206
|
+
return {
|
|
1207
|
+
coinType: this.coinType,
|
|
1208
|
+
reserveArrayIndex: this.reserveArrayIndex.toString(),
|
|
1209
|
+
borrowedAmount: this.borrowedAmount.toJSONField(),
|
|
1210
|
+
cumulativeBorrowRate: this.cumulativeBorrowRate.toJSONField(),
|
|
1211
|
+
marketValue: this.marketValue.toJSONField(),
|
|
1212
|
+
userRewardManagerIndex: this.userRewardManagerIndex.toString(),
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
toJSON() {
|
|
1216
|
+
return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
|
|
1217
|
+
}
|
|
1218
|
+
static fromJSONField(field) {
|
|
1219
|
+
return BorrowRecord.reified().new({
|
|
1220
|
+
coinType: decodeFromJSONField(TypeName.reified(), field.coinType),
|
|
1221
|
+
reserveArrayIndex: decodeFromJSONField('u64', field.reserveArrayIndex),
|
|
1222
|
+
borrowedAmount: decodeFromJSONField(Decimal.reified(), field.borrowedAmount),
|
|
1223
|
+
cumulativeBorrowRate: decodeFromJSONField(Decimal.reified(), field.cumulativeBorrowRate),
|
|
1224
|
+
marketValue: decodeFromJSONField(Decimal.reified(), field.marketValue),
|
|
1225
|
+
userRewardManagerIndex: decodeFromJSONField('u64', field.userRewardManagerIndex),
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
static fromJSON(json) {
|
|
1229
|
+
if (json.$typeName !== BorrowRecord.$typeName) {
|
|
1230
|
+
throw new Error(`not a BorrowRecord json object: expected '${BorrowRecord.$typeName}' but got '${json.$typeName}'`);
|
|
1231
|
+
}
|
|
1232
|
+
return BorrowRecord.fromJSONField(json);
|
|
1233
|
+
}
|
|
1234
|
+
static fromCoreObject(obj) {
|
|
1235
|
+
if (!isBorrowRecord(obj.type)) {
|
|
1236
|
+
throw new Error(`object at ${obj.objectId} is not a BorrowRecord object`);
|
|
1237
|
+
}
|
|
1238
|
+
return BorrowRecord.fromBcs(obj.content);
|
|
1239
|
+
}
|
|
1240
|
+
static async fetch(client, id) {
|
|
1241
|
+
const { object } = await client.core.getObject({
|
|
1242
|
+
objectId: id,
|
|
1243
|
+
include: { content: true },
|
|
1244
|
+
});
|
|
1245
|
+
if (!isBorrowRecord(object.type)) {
|
|
1246
|
+
throw new Error(`object at id ${id} is not a BorrowRecord object`);
|
|
1247
|
+
}
|
|
1248
|
+
return BorrowRecord.fromBcs(object.content);
|
|
1249
|
+
}
|
|
1250
|
+
}
|