@suilend/sdk 1.1.7 → 1.1.8
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/{mainnet/_generated → _generated}/_dependencies/source/0x1/ascii/structs.js +3 -3
- package/{mainnet/_generated → _generated}/_dependencies/source/0x1/option/structs.d.ts +1 -1
- package/{mainnet/_generated → _generated}/_dependencies/source/0x1/option/structs.js +2 -2
- package/{mainnet/_generated → _generated}/_dependencies/source/0x1/type-name/structs.js +2 -2
- package/{mainnet/_generated → _generated}/_dependencies/source/0x2/bag/structs.js +2 -2
- package/{mainnet/_generated → _generated}/_dependencies/source/0x2/balance/structs.js +3 -3
- package/{mainnet/_generated → _generated}/_dependencies/source/0x2/object/structs.js +3 -3
- package/{mainnet/_generated → _generated}/_dependencies/source/0x2/object-table/structs.js +2 -2
- package/{mainnet/_generated → _generated}/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.js +2 -2
- package/{mainnet/_generated → _generated}/_framework/reified.js +10 -10
- package/{mainnet/_generated → _generated}/_framework/util.d.ts +5 -11
- package/{mainnet/_generated → _generated}/_framework/util.js +12 -13
- package/{mainnet/_generated → _generated}/_framework/vector.d.ts +1 -1
- package/{mainnet/_generated → _generated}/_framework/vector.js +2 -2
- package/{mainnet/_generated → _generated}/suilend/cell/structs.d.ts +1 -1
- package/{mainnet/_generated → _generated}/suilend/cell/structs.js +2 -2
- package/{mainnet/_generated → _generated}/suilend/decimal/structs.js +2 -2
- package/{mainnet/_generated → _generated}/suilend/index.d.ts +2 -1
- package/{mainnet/_generated → _generated}/suilend/index.js +4 -0
- package/{mainnet/_generated → _generated}/suilend/lending-market/functions.js +32 -33
- package/{mainnet/_generated → _generated}/suilend/lending-market/structs.js +15 -15
- package/{mainnet/_generated → _generated}/suilend/lending-market-registry/functions.js +2 -3
- package/{mainnet/_generated → _generated}/suilend/liquidity-mining/structs.js +6 -6
- package/{mainnet/_generated → _generated}/suilend/obligation/structs.js +7 -7
- package/{mainnet/_generated → _generated}/suilend/rate-limiter/functions.js +6 -7
- package/{mainnet/_generated → _generated}/suilend/rate-limiter/structs.js +3 -3
- package/{mainnet/_generated → _generated}/suilend/reserve/structs.js +7 -7
- package/{mainnet/_generated → _generated}/suilend/reserve-config/functions.js +39 -40
- package/{mainnet/_generated → _generated}/suilend/reserve-config/structs.js +3 -3
- package/api/index.d.ts +1 -0
- package/{mainnet/utils.js → api/index.js} +1 -1
- package/client.d.ts +65 -0
- package/{core/client.js → client.js} +176 -178
- package/{core/constants.d.ts → constants.d.ts} +0 -4
- package/{core/constants.js → constants.js} +1 -6
- package/index.d.ts +7 -1
- package/index.js +7 -1
- package/package.json +1 -1
- package/{mainnet/parsers → parsers}/index.d.ts +1 -0
- package/{mainnet/parsers → parsers}/index.js +1 -0
- package/{core/parsers → parsers}/lendingMarket.d.ts +38 -37
- package/{core/parsers → parsers}/lendingMarket.js +15 -4
- package/{core/parsers → parsers}/obligation.d.ts +60 -60
- package/{core/parsers → parsers}/obligation.js +5 -3
- package/{mainnet/parsers → parsers}/rateLimiter.d.ts +10 -9
- package/{core/parsers → parsers}/rateLimiter.js +3 -3
- package/{core/parsers → parsers}/reserve.d.ts +47 -46
- package/{core/parsers → parsers}/reserve.js +32 -8
- package/types.d.ts +200 -0
- package/types.js +15 -0
- package/{core/utils → utils}/events.js +3 -3
- package/{mainnet/utils → utils}/obligation.js +5 -6
- package/utils/simulate.js +316 -0
- package/core/client.d.ts +0 -117
- package/core/parsers/deps.d.ts +0 -15
- package/core/parsers/deps.js +0 -2
- package/core/parsers/rateLimiter.d.ts +0 -19
- package/core/types.d.ts +0 -882
- package/core/types.js +0 -132
- package/core/utils/simulate.d.ts +0 -56
- package/core/utils/simulate.js +0 -312
- package/mainnet/api/events.d.ts +0 -1
- package/mainnet/api/events.js +0 -17
- package/mainnet/client.d.ts +0 -18
- package/mainnet/client.js +0 -110
- package/mainnet/constants.d.ts +0 -3
- package/mainnet/constants.js +0 -20
- package/mainnet/index.d.ts +0 -6
- package/mainnet/index.js +0 -22
- package/mainnet/parsers/apiReserveAssetDataEvent.d.ts +0 -1
- package/mainnet/parsers/apiReserveAssetDataEvent.js +0 -17
- package/mainnet/parsers/lendingMarket.d.ts +0 -127
- package/mainnet/parsers/lendingMarket.js +0 -41
- package/mainnet/parsers/obligation.d.ts +0 -10
- package/mainnet/parsers/obligation.js +0 -30
- package/mainnet/parsers/rateLimiter.js +0 -32
- package/mainnet/parsers/reserve.d.ts +0 -166
- package/mainnet/parsers/reserve.js +0 -38
- package/mainnet/types.d.ts +0 -1
- package/mainnet/types.js +0 -17
- package/mainnet/utils/events.d.ts +0 -1
- package/mainnet/utils/events.js +0 -17
- package/mainnet/utils/simulate.js +0 -78
- package/mainnet/utils.d.ts +0 -1
- /package/{mainnet/_generated → _generated}/_dependencies/source/0x1/ascii/structs.d.ts +0 -0
- /package/{mainnet/_generated → _generated}/_dependencies/source/0x1/index.d.ts +0 -0
- /package/{mainnet/_generated → _generated}/_dependencies/source/0x1/index.js +0 -0
- /package/{mainnet/_generated → _generated}/_dependencies/source/0x1/type-name/structs.d.ts +0 -0
- /package/{mainnet/_generated → _generated}/_dependencies/source/0x2/bag/structs.d.ts +0 -0
- /package/{mainnet/_generated → _generated}/_dependencies/source/0x2/balance/structs.d.ts +0 -0
- /package/{mainnet/_generated → _generated}/_dependencies/source/0x2/index.d.ts +0 -0
- /package/{mainnet/_generated → _generated}/_dependencies/source/0x2/index.js +0 -0
- /package/{mainnet/_generated → _generated}/_dependencies/source/0x2/object/structs.d.ts +0 -0
- /package/{mainnet/_generated → _generated}/_dependencies/source/0x2/object-table/structs.d.ts +0 -0
- /package/{mainnet/_generated → _generated}/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/index.d.ts +0 -0
- /package/{mainnet/_generated → _generated}/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/index.js +0 -0
- /package/{mainnet/_generated → _generated}/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.d.ts +0 -0
- /package/{mainnet/_generated → _generated}/_framework/reified.d.ts +0 -0
- /package/{mainnet/_generated → _generated}/suilend/decimal/structs.d.ts +0 -0
- /package/{mainnet/_generated → _generated}/suilend/lending-market/functions.d.ts +0 -0
- /package/{mainnet/_generated → _generated}/suilend/lending-market/structs.d.ts +0 -0
- /package/{mainnet/_generated → _generated}/suilend/lending-market-registry/functions.d.ts +0 -0
- /package/{mainnet/_generated → _generated}/suilend/liquidity-mining/structs.d.ts +0 -0
- /package/{mainnet/_generated → _generated}/suilend/obligation/structs.d.ts +0 -0
- /package/{mainnet/_generated → _generated}/suilend/rate-limiter/functions.d.ts +0 -0
- /package/{mainnet/_generated → _generated}/suilend/rate-limiter/structs.d.ts +0 -0
- /package/{mainnet/_generated → _generated}/suilend/reserve/structs.d.ts +0 -0
- /package/{mainnet/_generated → _generated}/suilend/reserve-config/functions.d.ts +0 -0
- /package/{mainnet/_generated → _generated}/suilend/reserve-config/structs.d.ts +0 -0
- /package/{core/api → api}/events.d.ts +0 -0
- /package/{core/api → api}/events.js +0 -0
- /package/{core/parsers → parsers}/apiReserveAssetDataEvent.d.ts +0 -0
- /package/{core/parsers → parsers}/apiReserveAssetDataEvent.js +0 -0
- /package/{core/utils → utils}/events.d.ts +0 -0
- /package/{mainnet/utils → utils}/index.d.ts +0 -0
- /package/{mainnet/utils → utils}/index.js +0 -0
- /package/{mainnet/utils → utils}/obligation.d.ts +0 -0
- /package/{mainnet/utils → utils}/simulate.d.ts +0 -0
- /package/{core/utils.d.ts → utils.d.ts} +0 -0
- /package/{core/utils.js → utils.js} +0 -0
|
@@ -9,61 +9,59 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.SuilendClient = void 0;
|
|
13
|
-
const transactions_1 = require("@mysten/sui/transactions");
|
|
12
|
+
exports.SuilendClient = exports.LENDING_MARKET_TYPE = exports.LENDING_MARKET_ID = void 0;
|
|
14
13
|
const utils_1 = require("@mysten/sui/utils");
|
|
15
14
|
const pyth_sui_js_1 = require("@pythnetwork/pyth-sui-js");
|
|
15
|
+
const reified_1 = require("./_generated/_framework/reified");
|
|
16
|
+
const suilend_1 = require("./_generated/suilend");
|
|
17
|
+
const suilend_2 = require("./_generated/suilend");
|
|
18
|
+
const functions_1 = require("./_generated/suilend/lending-market/functions");
|
|
19
|
+
const structs_1 = require("./_generated/suilend/lending-market/structs");
|
|
20
|
+
const functions_2 = require("./_generated/suilend/lending-market-registry/functions");
|
|
21
|
+
const structs_2 = require("./_generated/suilend/obligation/structs");
|
|
22
|
+
const functions_3 = require("./_generated/suilend/rate-limiter/functions");
|
|
23
|
+
const functions_4 = require("./_generated/suilend/reserve-config/functions");
|
|
16
24
|
const types_1 = require("./types");
|
|
17
25
|
const utils_2 = require("./utils");
|
|
18
26
|
const WORMHOLE_STATE_ID = "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c";
|
|
19
27
|
const PYTH_STATE_ID = "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8";
|
|
28
|
+
const SUILEND_UPGRADE_CAP_ID = "0x3d4ef1859c3ee9fc72858f588b56a09da5466e64f8cc4e90a7b3b909fba8a7ae";
|
|
29
|
+
function getLatestPackageId(client, upgradeCapId) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
var _a;
|
|
32
|
+
const object = yield client.getObject({
|
|
33
|
+
id: upgradeCapId,
|
|
34
|
+
options: {
|
|
35
|
+
showContent: true,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
return ((_a = object.data) === null || _a === void 0 ? void 0 : _a.content).fields.package;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
20
41
|
const SUI_COINTYPE = "0x2::sui::SUI";
|
|
42
|
+
exports.LENDING_MARKET_ID = "0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1";
|
|
43
|
+
exports.LENDING_MARKET_TYPE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL";
|
|
21
44
|
class SuilendClient {
|
|
22
|
-
constructor(lendingMarket, client
|
|
45
|
+
constructor(lendingMarket, client) {
|
|
23
46
|
this.lendingMarket = lendingMarket;
|
|
24
47
|
this.client = client;
|
|
25
48
|
this.pythClient = new pyth_sui_js_1.SuiPythClient(client, PYTH_STATE_ID, WORMHOLE_STATE_ID);
|
|
26
49
|
this.pythConnection = new pyth_sui_js_1.SuiPriceServiceConnection("https://hermes.pyth.network");
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.PUBLISHED_AT = PUBLISHED_AT;
|
|
30
|
-
this.LendingMarket = LendingMarket;
|
|
31
|
-
this.Obligation = Obligation;
|
|
32
|
-
this.ObligationOwnerCap = ObligationOwnerCap;
|
|
33
|
-
this.createLendingMarketFunction = createLendingMarket;
|
|
34
|
-
this.createReserveConfigFunction = createReserveConfig;
|
|
35
|
-
this.updateReserveConfigFunction = updateReserveConfig;
|
|
36
|
-
this.addReserveFunction = addReserve;
|
|
37
|
-
this.addPoolRewardFunction = addPoolReward;
|
|
38
|
-
this.cancelPoolRewardFunction = cancelPoolReward;
|
|
39
|
-
this.closePoolRewardFunction = closePoolReward;
|
|
40
|
-
this.claimRewardsFunction = claimRewards;
|
|
41
|
-
this.claimRewardsAndDepositFunction = claimRewardsAndDeposit;
|
|
42
|
-
this.createRateLimiterConfigFunction = createRateLimiterConfig;
|
|
43
|
-
this.updateRateLimiterConfigFunction = updateRateLimiterConfig;
|
|
44
|
-
this.refreshReservePriceFunction = refreshReservePrice;
|
|
45
|
-
this.depositLiquidityAndMintCtokensFunction =
|
|
46
|
-
depositLiquidityAndMintCtokens;
|
|
47
|
-
this.depositCtokensIntoObligationFunction = depositCtokensIntoObligation;
|
|
48
|
-
this.withdrawCtokensFunction = withdrawCtokens;
|
|
49
|
-
this.borrowFunction = borrow;
|
|
50
|
-
this.repayFunction = repay;
|
|
51
|
-
this.liquidateFunction = liquidate;
|
|
52
|
-
this.migrateFunction = migrate;
|
|
53
|
-
this.claimFeesFunction = claimFees;
|
|
54
|
-
this.redeemCtokensAndWithdrawLiquidityFunction =
|
|
55
|
-
redeemCtokensAndWithdrawLiquidity;
|
|
56
|
-
this.changeReservePriceFeedFunction = changeReservePriceFeed;
|
|
57
|
-
}
|
|
58
|
-
static initialize(lendingMarketId, lendingMarketType, client, deps) {
|
|
50
|
+
}
|
|
51
|
+
static initialize(lendingMarketId, lendingMarketType, client) {
|
|
59
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
const lendingMarket = yield
|
|
61
|
-
|
|
53
|
+
const lendingMarket = yield structs_1.LendingMarket.fetch(client, (0, reified_1.phantom)(lendingMarketType), lendingMarketId);
|
|
54
|
+
const latestPackageId = yield getLatestPackageId(client, SUILEND_UPGRADE_CAP_ID);
|
|
55
|
+
console.log("latestPackageId", latestPackageId);
|
|
56
|
+
(0, suilend_1.setPublishedAt)(latestPackageId);
|
|
57
|
+
return new SuilendClient(lendingMarket, client);
|
|
62
58
|
});
|
|
63
59
|
}
|
|
64
|
-
static initializeWithLendingMarket(lendingMarket, client
|
|
60
|
+
static initializeWithLendingMarket(lendingMarket, client) {
|
|
65
61
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
|
|
62
|
+
const latestPackageId = yield getLatestPackageId(client, SUILEND_UPGRADE_CAP_ID);
|
|
63
|
+
(0, suilend_1.setPublishedAt)(latestPackageId);
|
|
64
|
+
return new SuilendClient(lendingMarket, client);
|
|
67
65
|
});
|
|
68
66
|
}
|
|
69
67
|
static hasBetaPass(ownerId, client) {
|
|
@@ -77,23 +75,23 @@ class SuilendClient {
|
|
|
77
75
|
return objs.data.length > 0;
|
|
78
76
|
});
|
|
79
77
|
}
|
|
80
|
-
static createNewLendingMarket(
|
|
81
|
-
return __awaiter(this,
|
|
82
|
-
const [ownerCap, lendingMarket] = createLendingMarket(transaction, lendingMarketType, transaction.object(registryId));
|
|
78
|
+
static createNewLendingMarket(registryId, lendingMarketType, transaction) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const [ownerCap, lendingMarket] = (0, functions_2.createLendingMarket)(transaction, lendingMarketType, transaction.object(registryId));
|
|
83
81
|
transaction.moveCall({
|
|
84
82
|
target: `0x2::transfer::public_share_object`,
|
|
85
|
-
typeArguments: [`${LendingMarket.$typeName}<${lendingMarketType}>}`],
|
|
83
|
+
typeArguments: [`${structs_1.LendingMarket.$typeName}<${lendingMarketType}>}`],
|
|
86
84
|
arguments: [lendingMarket],
|
|
87
85
|
});
|
|
88
86
|
return ownerCap;
|
|
89
87
|
});
|
|
90
88
|
}
|
|
91
|
-
static getObligationOwnerCaps(
|
|
92
|
-
return __awaiter(this,
|
|
89
|
+
static getObligationOwnerCaps(ownerId, lendingMarketTypeArgs, client) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
91
|
const objs = yield client.getOwnedObjects({
|
|
94
92
|
owner: ownerId,
|
|
95
93
|
filter: {
|
|
96
|
-
StructType: `${PACKAGE_ID}::lending_market::ObligationOwnerCap<${lendingMarketTypeArgs[0]}>`,
|
|
94
|
+
StructType: `${suilend_2.PACKAGE_ID}::lending_market::ObligationOwnerCap<${lendingMarketTypeArgs[0]}>`,
|
|
97
95
|
},
|
|
98
96
|
});
|
|
99
97
|
if (objs.data.length > 0) {
|
|
@@ -109,7 +107,7 @@ class SuilendClient {
|
|
|
109
107
|
var _a, _b, _c, _d;
|
|
110
108
|
if (((_b = (_a = obj.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject")
|
|
111
109
|
throw new Error("Error: invalid data type");
|
|
112
|
-
obligationOwnerCaps.push(ObligationOwnerCap.fromBcs(phantom(lendingMarketTypeArgs[0]), (0, utils_1.fromBase64)((_d = (_c = obj.data) === null || _c === void 0 ? void 0 : _c.bcs) === null || _d === void 0 ? void 0 : _d.bcsBytes)));
|
|
110
|
+
obligationOwnerCaps.push(structs_1.ObligationOwnerCap.fromBcs((0, reified_1.phantom)(lendingMarketTypeArgs[0]), (0, utils_1.fromBase64)((_d = (_c = obj.data) === null || _c === void 0 ? void 0 : _c.bcs) === null || _d === void 0 ? void 0 : _d.bcsBytes)));
|
|
113
111
|
});
|
|
114
112
|
return obligationOwnerCaps;
|
|
115
113
|
}
|
|
@@ -118,46 +116,46 @@ class SuilendClient {
|
|
|
118
116
|
}
|
|
119
117
|
});
|
|
120
118
|
}
|
|
121
|
-
static getObligation(
|
|
122
|
-
return __awaiter(this,
|
|
123
|
-
var
|
|
119
|
+
static getObligation(obligationId, lendingMarketTypeArgs, client) {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
var _a, _b;
|
|
124
122
|
const obligationData = yield client.getObject({
|
|
125
123
|
id: obligationId,
|
|
126
124
|
options: { showBcs: true },
|
|
127
125
|
});
|
|
128
|
-
if (((
|
|
126
|
+
if (((_b = (_a = obligationData.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject") {
|
|
129
127
|
throw new Error("Error: invalid data type");
|
|
130
128
|
}
|
|
131
|
-
const obligation = Obligation.fromBcs(phantom(lendingMarketTypeArgs[0]), (0, utils_1.fromBase64)(obligationData.data.bcs.bcsBytes));
|
|
129
|
+
const obligation = structs_2.Obligation.fromBcs((0, reified_1.phantom)(lendingMarketTypeArgs[0]), (0, utils_1.fromBase64)(obligationData.data.bcs.bcsBytes));
|
|
132
130
|
return obligation;
|
|
133
131
|
});
|
|
134
132
|
}
|
|
135
133
|
getObligation(obligationId) {
|
|
136
|
-
return SuilendClient.getObligation(obligationId, this.lendingMarket.$typeArgs, this.client
|
|
134
|
+
return SuilendClient.getObligation(obligationId, this.lendingMarket.$typeArgs, this.client);
|
|
137
135
|
}
|
|
138
|
-
static getLendingMarketOwnerCapId(
|
|
139
|
-
return __awaiter(this,
|
|
140
|
-
var
|
|
136
|
+
static getLendingMarketOwnerCapId(ownerId, lendingMarketTypeArgs, client) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
var _a;
|
|
141
139
|
const objs = yield client.getOwnedObjects({
|
|
142
140
|
owner: ownerId,
|
|
143
141
|
filter: {
|
|
144
|
-
StructType: `${PACKAGE_ID}::lending_market::LendingMarketOwnerCap<${lendingMarketTypeArgs[0]}>`,
|
|
142
|
+
StructType: `${suilend_2.PACKAGE_ID}::lending_market::LendingMarketOwnerCap<${lendingMarketTypeArgs[0]}>`,
|
|
145
143
|
},
|
|
146
144
|
});
|
|
147
145
|
if (objs.data.length > 0)
|
|
148
|
-
return (
|
|
146
|
+
return (_a = objs.data[0].data) === null || _a === void 0 ? void 0 : _a.objectId;
|
|
149
147
|
else
|
|
150
148
|
return null;
|
|
151
149
|
});
|
|
152
150
|
}
|
|
153
151
|
getLendingMarketOwnerCapId(ownerId) {
|
|
154
152
|
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
-
return SuilendClient.getLendingMarketOwnerCapId(ownerId, this.lendingMarket.$typeArgs, this.client
|
|
153
|
+
return SuilendClient.getLendingMarketOwnerCapId(ownerId, this.lendingMarket.$typeArgs, this.client);
|
|
156
154
|
});
|
|
157
155
|
}
|
|
158
156
|
createReserve(lendingMarketOwnerCapId, transaction, pythPriceId, coinType, createReserveConfigArgs) {
|
|
159
157
|
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
-
const [config] =
|
|
158
|
+
const [config] = (0, functions_4.createReserveConfig)(transaction, createReserveConfigArgs);
|
|
161
159
|
const priceUpdateData = yield this.pythConnection.getPriceFeedsUpdateData([
|
|
162
160
|
pythPriceId,
|
|
163
161
|
]);
|
|
@@ -168,13 +166,13 @@ class SuilendClient {
|
|
|
168
166
|
if (coin_metadata === null) {
|
|
169
167
|
throw new Error("Error: coin metadata not found");
|
|
170
168
|
}
|
|
171
|
-
return
|
|
172
|
-
lendingMarketOwnerCap: lendingMarketOwnerCapId,
|
|
173
|
-
lendingMarket: this.lendingMarket.id,
|
|
174
|
-
priceInfo: priceInfoObjectIds[0],
|
|
175
|
-
config,
|
|
176
|
-
coinMetadata: coin_metadata.id,
|
|
177
|
-
clock: utils_1.SUI_CLOCK_OBJECT_ID,
|
|
169
|
+
return (0, functions_1.addReserve)(transaction, [this.lendingMarket.$typeArgs[0], coinType], {
|
|
170
|
+
lendingMarketOwnerCap: transaction.object(lendingMarketOwnerCapId),
|
|
171
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
172
|
+
priceInfo: transaction.object(priceInfoObjectIds[0]),
|
|
173
|
+
config: transaction.object(config),
|
|
174
|
+
coinMetadata: transaction.object(coin_metadata.id),
|
|
175
|
+
clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
178
176
|
});
|
|
179
177
|
});
|
|
180
178
|
}
|
|
@@ -190,57 +188,57 @@ class SuilendClient {
|
|
|
190
188
|
transaction.mergeCoins(transaction.object(mergeCoin.coinObjectId), coins.map((c) => transaction.object(c.coinObjectId)).slice(1));
|
|
191
189
|
}
|
|
192
190
|
const [rewardCoin] = transaction.splitCoins(isSui ? transaction.gas : transaction.object(mergeCoin.coinObjectId), [rewardValue]);
|
|
193
|
-
return
|
|
194
|
-
lendingMarketOwnerCap: lendingMarketOwnerCapId,
|
|
195
|
-
lendingMarket: this.lendingMarket.id,
|
|
196
|
-
reserveArrayIndex,
|
|
197
|
-
isDepositReward,
|
|
198
|
-
rewards: rewardCoin,
|
|
199
|
-
startTimeMs,
|
|
200
|
-
endTimeMs,
|
|
201
|
-
clock: utils_1.SUI_CLOCK_OBJECT_ID,
|
|
191
|
+
return (0, functions_1.addPoolReward)(transaction, [this.lendingMarket.$typeArgs[0], rewardCoinType], {
|
|
192
|
+
lendingMarketOwnerCap: transaction.object(lendingMarketOwnerCapId),
|
|
193
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
194
|
+
reserveArrayIndex: transaction.pure.u64(reserveArrayIndex),
|
|
195
|
+
isDepositReward: transaction.pure.bool(isDepositReward),
|
|
196
|
+
rewards: transaction.object(rewardCoin),
|
|
197
|
+
startTimeMs: transaction.pure.u64(startTimeMs),
|
|
198
|
+
endTimeMs: transaction.pure.u64(endTimeMs),
|
|
199
|
+
clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
202
200
|
});
|
|
203
201
|
});
|
|
204
202
|
}
|
|
205
203
|
cancelReward(lendingMarketOwnerCapId, reserveArrayIndex, isDepositReward, rewardIndex, rewardCoinType, transaction) {
|
|
206
|
-
return
|
|
207
|
-
lendingMarketOwnerCap: lendingMarketOwnerCapId,
|
|
208
|
-
lendingMarket: this.lendingMarket.id,
|
|
209
|
-
reserveArrayIndex,
|
|
210
|
-
isDepositReward,
|
|
204
|
+
return (0, functions_1.cancelPoolReward)(transaction, [this.lendingMarket.$typeArgs[0], rewardCoinType], {
|
|
205
|
+
lendingMarketOwnerCap: transaction.object(lendingMarketOwnerCapId),
|
|
206
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
207
|
+
reserveArrayIndex: transaction.pure.u64(reserveArrayIndex),
|
|
208
|
+
isDepositReward: transaction.pure.bool(isDepositReward),
|
|
211
209
|
rewardIndex,
|
|
212
|
-
clock: utils_1.SUI_CLOCK_OBJECT_ID,
|
|
210
|
+
clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
213
211
|
});
|
|
214
212
|
}
|
|
215
213
|
closeReward(lendingMarketOwnerCapId, reserveArrayIndex, isDepositReward, rewardIndex, rewardCoinType, transaction) {
|
|
216
|
-
return
|
|
217
|
-
lendingMarketOwnerCap: lendingMarketOwnerCapId,
|
|
218
|
-
lendingMarket: this.lendingMarket.id,
|
|
219
|
-
reserveArrayIndex,
|
|
220
|
-
isDepositReward,
|
|
214
|
+
return (0, functions_1.closePoolReward)(transaction, [this.lendingMarket.$typeArgs[0], rewardCoinType], {
|
|
215
|
+
lendingMarketOwnerCap: transaction.object(lendingMarketOwnerCapId),
|
|
216
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
217
|
+
reserveArrayIndex: transaction.pure.u64(reserveArrayIndex),
|
|
218
|
+
isDepositReward: transaction.pure.bool(isDepositReward),
|
|
221
219
|
rewardIndex,
|
|
222
|
-
clock: utils_1.SUI_CLOCK_OBJECT_ID,
|
|
220
|
+
clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
223
221
|
});
|
|
224
222
|
}
|
|
225
223
|
claimReward(obligationOwnerCapId, reserveArrayIndex, rewardIndex, rewardType, side, transaction) {
|
|
226
|
-
return
|
|
224
|
+
return (0, functions_1.claimRewards)(transaction, [this.lendingMarket.$typeArgs[0], rewardType], {
|
|
227
225
|
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
228
226
|
cap: transaction.object(obligationOwnerCapId),
|
|
229
|
-
clock: utils_1.SUI_CLOCK_OBJECT_ID,
|
|
230
|
-
reserveId: reserveArrayIndex,
|
|
227
|
+
clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
228
|
+
reserveId: transaction.pure.u64(reserveArrayIndex),
|
|
231
229
|
rewardIndex,
|
|
232
|
-
isDepositReward: side === types_1.Side.DEPOSIT,
|
|
230
|
+
isDepositReward: transaction.pure.bool(side === types_1.Side.DEPOSIT),
|
|
233
231
|
});
|
|
234
232
|
}
|
|
235
233
|
claimRewardsAndDeposit(obligationId, rewardReserveArrayIndex, rewardIndex, rewardType, side, depositReserveArrayIndex, transaction) {
|
|
236
|
-
return
|
|
234
|
+
return (0, functions_1.claimRewardsAndDeposit)(transaction, [this.lendingMarket.$typeArgs[0], rewardType], {
|
|
237
235
|
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
238
236
|
obligationId,
|
|
239
237
|
clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
240
|
-
rewardReserveId: rewardReserveArrayIndex,
|
|
241
|
-
rewardIndex,
|
|
242
|
-
isDepositReward: side === types_1.Side.DEPOSIT,
|
|
243
|
-
depositReserveId: depositReserveArrayIndex,
|
|
238
|
+
rewardReserveId: transaction.pure.u64(rewardReserveArrayIndex),
|
|
239
|
+
rewardIndex: transaction.pure.u64(rewardIndex),
|
|
240
|
+
isDepositReward: transaction.pure.bool(side === types_1.Side.DEPOSIT),
|
|
241
|
+
depositReserveId: transaction.pure.u64(depositReserveArrayIndex),
|
|
244
242
|
});
|
|
245
243
|
}
|
|
246
244
|
claimRewardsToObligation(ownerId, rewards, transaction) {
|
|
@@ -268,23 +266,33 @@ class SuilendClient {
|
|
|
268
266
|
}
|
|
269
267
|
updateReserveConfig(ownerId, lendingMarketOwnerCapId, transaction, coinType, createReserveConfigArgs) {
|
|
270
268
|
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
-
const [config] =
|
|
272
|
-
return
|
|
273
|
-
lendingMarketOwnerCap: lendingMarketOwnerCapId,
|
|
274
|
-
lendingMarket: this.lendingMarket.id,
|
|
275
|
-
reserveArrayIndex: this.findReserveArrayIndex(coinType),
|
|
276
|
-
config,
|
|
269
|
+
const [config] = (0, functions_4.createReserveConfig)(transaction, createReserveConfigArgs);
|
|
270
|
+
return (0, functions_1.updateReserveConfig)(transaction, [...this.lendingMarket.$typeArgs, coinType], {
|
|
271
|
+
lendingMarketOwnerCap: transaction.object(lendingMarketOwnerCapId),
|
|
272
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
273
|
+
reserveArrayIndex: transaction.pure.u64(this.findReserveArrayIndex(coinType)),
|
|
274
|
+
config: transaction.object(config),
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
newObligationOwnerCap(transaction, lendingMarketOwnerCapId, destinationAddress, obligationId) {
|
|
279
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
280
|
+
const [obligationOwnerCap] = (0, functions_1.newObligationOwnerCap)(transaction, this.lendingMarket.$typeArgs[0], {
|
|
281
|
+
lendingMarketOwnerCap: transaction.object(lendingMarketOwnerCapId),
|
|
282
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
283
|
+
obligationId,
|
|
277
284
|
});
|
|
285
|
+
transaction.transferObjects([obligationOwnerCap], transaction.pure.address(destinationAddress));
|
|
278
286
|
});
|
|
279
287
|
}
|
|
280
288
|
updateRateLimiterConfig(lendingMarketOwnerCapId, transaction, newRateLimiterConfigArgs) {
|
|
281
289
|
return __awaiter(this, void 0, void 0, function* () {
|
|
282
|
-
const [config] =
|
|
283
|
-
return
|
|
284
|
-
lendingMarketOwnerCap: lendingMarketOwnerCapId,
|
|
285
|
-
lendingMarket: this.lendingMarket.id,
|
|
286
|
-
clock: utils_1.SUI_CLOCK_OBJECT_ID,
|
|
287
|
-
config,
|
|
290
|
+
const [config] = (0, functions_3.newConfig)(transaction, newRateLimiterConfigArgs);
|
|
291
|
+
return (0, functions_1.updateRateLimiterConfig)(transaction, this.lendingMarket.$typeArgs[0], {
|
|
292
|
+
lendingMarketOwnerCap: transaction.object(lendingMarketOwnerCapId),
|
|
293
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
294
|
+
clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
295
|
+
config: transaction.object(config),
|
|
288
296
|
});
|
|
289
297
|
});
|
|
290
298
|
}
|
|
@@ -294,18 +302,18 @@ class SuilendClient {
|
|
|
294
302
|
pythPriceId,
|
|
295
303
|
]);
|
|
296
304
|
const priceInfoObjectIds = yield this.pythClient.updatePriceFeeds(transaction, priceUpdateData, [pythPriceId]);
|
|
297
|
-
return
|
|
298
|
-
lendingMarketOwnerCap: lendingMarketOwnerCapId,
|
|
299
|
-
lendingMarket: this.lendingMarket.id,
|
|
300
|
-
reserveArrayIndex: this.findReserveArrayIndex(coinType),
|
|
301
|
-
priceInfoObj: priceInfoObjectIds[0],
|
|
302
|
-
clock: utils_1.SUI_CLOCK_OBJECT_ID,
|
|
305
|
+
return (0, functions_1.changeReservePriceFeed)(transaction, [this.lendingMarket.$typeArgs[0], coinType], {
|
|
306
|
+
lendingMarketOwnerCap: transaction.object(lendingMarketOwnerCapId),
|
|
307
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
308
|
+
reserveArrayIndex: transaction.pure.u64(this.findReserveArrayIndex(coinType)),
|
|
309
|
+
priceInfoObj: transaction.object(priceInfoObjectIds[0]),
|
|
310
|
+
clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
303
311
|
});
|
|
304
312
|
});
|
|
305
313
|
}
|
|
306
314
|
createObligation(transaction) {
|
|
307
315
|
return transaction.moveCall({
|
|
308
|
-
target: `${
|
|
316
|
+
target: `${suilend_2.PUBLISHED_AT}::lending_market::create_obligation`,
|
|
309
317
|
arguments: [transaction.object(this.lendingMarket.id)],
|
|
310
318
|
typeArguments: this.lendingMarket.$typeArgs,
|
|
311
319
|
});
|
|
@@ -314,33 +322,23 @@ class SuilendClient {
|
|
|
314
322
|
return __awaiter(this, void 0, void 0, function* () {
|
|
315
323
|
const reserveArrayIndexToPriceId = new Map();
|
|
316
324
|
obligation.deposits.forEach((deposit) => {
|
|
317
|
-
const reserve = this.lendingMarket.reserves[deposit.reserveArrayIndex];
|
|
325
|
+
const reserve = this.lendingMarket.reserves[Number(deposit.reserveArrayIndex)];
|
|
318
326
|
reserveArrayIndexToPriceId.set(deposit.reserveArrayIndex, (0, utils_1.toHex)(new Uint8Array(reserve.priceIdentifier.bytes)));
|
|
319
327
|
});
|
|
320
328
|
obligation.borrows.forEach((borrow) => {
|
|
321
|
-
const reserve = this.lendingMarket.reserves[borrow.reserveArrayIndex];
|
|
329
|
+
const reserve = this.lendingMarket.reserves[Number(borrow.reserveArrayIndex)];
|
|
322
330
|
reserveArrayIndexToPriceId.set(borrow.reserveArrayIndex, (0, utils_1.toHex)(new Uint8Array(reserve.priceIdentifier.bytes)));
|
|
323
331
|
});
|
|
324
332
|
if (extraReserveArrayIndex != undefined &&
|
|
325
333
|
extraReserveArrayIndex >= 0 &&
|
|
326
334
|
extraReserveArrayIndex < this.lendingMarket.reserves.length) {
|
|
327
|
-
const reserve = this.lendingMarket.reserves[extraReserveArrayIndex];
|
|
335
|
+
const reserve = this.lendingMarket.reserves[Number(extraReserveArrayIndex)];
|
|
328
336
|
reserveArrayIndexToPriceId.set(extraReserveArrayIndex, (0, utils_1.toHex)(new Uint8Array(reserve.priceIdentifier.bytes)));
|
|
329
337
|
}
|
|
330
338
|
const tuples = Array.from(reserveArrayIndexToPriceId.entries()).sort();
|
|
331
339
|
const priceIds = Array.from(tuples.map((tuple) => tuple[1]));
|
|
332
340
|
const priceUpdateData = yield this.pythConnection.getPriceFeedsUpdateData(priceIds);
|
|
333
|
-
const
|
|
334
|
-
obligation.borrows.length +
|
|
335
|
-
(extraReserveArrayIndex != null ? 1 : 0);
|
|
336
|
-
let priceInfoObjectIds = [];
|
|
337
|
-
if (numUniqueAssets >= 3) {
|
|
338
|
-
const tx = new transactions_1.Transaction(); // hack
|
|
339
|
-
priceInfoObjectIds = yield this.pythClient.updatePriceFeeds(tx, priceUpdateData, priceIds);
|
|
340
|
-
}
|
|
341
|
-
else {
|
|
342
|
-
priceInfoObjectIds = yield this.pythClient.updatePriceFeeds(transaction, priceUpdateData, priceIds);
|
|
343
|
-
}
|
|
341
|
+
const priceInfoObjectIds = yield this.pythClient.updatePriceFeeds(transaction, priceUpdateData, priceIds);
|
|
344
342
|
for (let i = 0; i < tuples.length; i++) {
|
|
345
343
|
this.refreshReservePrices(transaction, priceInfoObjectIds[i], tuples[i][0]);
|
|
346
344
|
}
|
|
@@ -351,27 +349,27 @@ class SuilendClient {
|
|
|
351
349
|
if (priceInfoObjectId == null) {
|
|
352
350
|
return;
|
|
353
351
|
}
|
|
354
|
-
|
|
355
|
-
lendingMarket: this.lendingMarket.id,
|
|
356
|
-
reserveArrayIndex,
|
|
357
|
-
clock: utils_1.SUI_CLOCK_OBJECT_ID,
|
|
358
|
-
priceInfo: priceInfoObjectId,
|
|
352
|
+
(0, functions_1.refreshReservePrice)(transaction, this.lendingMarket.$typeArgs[0], {
|
|
353
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
354
|
+
reserveArrayIndex: transaction.pure.u64(reserveArrayIndex),
|
|
355
|
+
clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
356
|
+
priceInfo: transaction.object(priceInfoObjectId),
|
|
359
357
|
});
|
|
360
358
|
});
|
|
361
359
|
}
|
|
362
360
|
deposit(sendCoin, coinType, obligationOwnerCap, transaction) {
|
|
363
361
|
return __awaiter(this, void 0, void 0, function* () {
|
|
364
|
-
const [ctokens] =
|
|
365
|
-
lendingMarket: this.lendingMarket.id,
|
|
366
|
-
reserveArrayIndex: this.findReserveArrayIndex(coinType),
|
|
367
|
-
clock: utils_1.SUI_CLOCK_OBJECT_ID,
|
|
362
|
+
const [ctokens] = (0, functions_1.depositLiquidityAndMintCtokens)(transaction, [this.lendingMarket.$typeArgs[0], coinType], {
|
|
363
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
364
|
+
reserveArrayIndex: transaction.pure.u64(this.findReserveArrayIndex(coinType)),
|
|
365
|
+
clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
368
366
|
deposit: sendCoin,
|
|
369
367
|
});
|
|
370
|
-
|
|
371
|
-
lendingMarket: this.lendingMarket.id,
|
|
372
|
-
reserveArrayIndex: this.findReserveArrayIndex(coinType),
|
|
368
|
+
(0, functions_1.depositCtokensIntoObligation)(transaction, [this.lendingMarket.$typeArgs[0], coinType], {
|
|
369
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
370
|
+
reserveArrayIndex: transaction.pure.u64(this.findReserveArrayIndex(coinType)),
|
|
373
371
|
obligationOwnerCap,
|
|
374
|
-
clock: utils_1.SUI_CLOCK_OBJECT_ID,
|
|
372
|
+
clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
375
373
|
deposit: ctokens,
|
|
376
374
|
});
|
|
377
375
|
});
|
|
@@ -415,10 +413,10 @@ class SuilendClient {
|
|
|
415
413
|
transaction.mergeCoins(transaction.object(mergeCoin.coinObjectId), coins.map((c) => transaction.object(c.coinObjectId)).slice(1));
|
|
416
414
|
}
|
|
417
415
|
const [sendCoin] = transaction.splitCoins(isSui ? transaction.gas : transaction.object(mergeCoin.coinObjectId), [value]);
|
|
418
|
-
const [ctokens] =
|
|
419
|
-
lendingMarket: this.lendingMarket.id,
|
|
420
|
-
reserveArrayIndex: this.findReserveArrayIndex(coinType),
|
|
421
|
-
clock: utils_1.SUI_CLOCK_OBJECT_ID,
|
|
416
|
+
const [ctokens] = (0, functions_1.depositLiquidityAndMintCtokens)(transaction, [this.lendingMarket.$typeArgs[0], coinType], {
|
|
417
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
418
|
+
reserveArrayIndex: transaction.pure.u64(this.findReserveArrayIndex(coinType)),
|
|
419
|
+
clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
422
420
|
deposit: sendCoin,
|
|
423
421
|
});
|
|
424
422
|
transaction.transferObjects([ctokens], transaction.pure.address(ownerId));
|
|
@@ -430,22 +428,22 @@ class SuilendClient {
|
|
|
430
428
|
if (!obligation)
|
|
431
429
|
throw new Error("Error: no obligation");
|
|
432
430
|
yield this.refreshAll(transaction, obligation);
|
|
433
|
-
const [ctokens] =
|
|
434
|
-
lendingMarket: this.lendingMarket.id,
|
|
435
|
-
reserveArrayIndex: this.findReserveArrayIndex(coinType),
|
|
431
|
+
const [ctokens] = (0, functions_1.withdrawCtokens)(transaction, [this.lendingMarket.$typeArgs[0], coinType], {
|
|
432
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
433
|
+
reserveArrayIndex: transaction.pure.u64(this.findReserveArrayIndex(coinType)),
|
|
436
434
|
obligationOwnerCap: obligationOwnerCapId,
|
|
437
|
-
clock: utils_1.SUI_CLOCK_OBJECT_ID,
|
|
435
|
+
clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
438
436
|
amount: BigInt(value),
|
|
439
437
|
});
|
|
440
438
|
const [exemption] = transaction.moveCall({
|
|
441
439
|
target: `0x1::option::none`,
|
|
442
440
|
typeArguments: [
|
|
443
|
-
`${
|
|
441
|
+
`${suilend_2.PACKAGE_ID}::lending_market::RateLimiterExemption<${this.lendingMarket.$typeArgs[0]}, ${coinType}>`,
|
|
444
442
|
],
|
|
445
443
|
arguments: [],
|
|
446
444
|
});
|
|
447
445
|
return transaction.moveCall({
|
|
448
|
-
target: `${
|
|
446
|
+
target: `${suilend_2.PUBLISHED_AT}::lending_market::redeem_ctokens_and_withdraw_liquidity`,
|
|
449
447
|
typeArguments: [this.lendingMarket.$typeArgs[0], coinType],
|
|
450
448
|
arguments: [
|
|
451
449
|
transaction.object(this.lendingMarket.id),
|
|
@@ -469,11 +467,11 @@ class SuilendClient {
|
|
|
469
467
|
if (!obligation)
|
|
470
468
|
throw new Error("Error: no obligation");
|
|
471
469
|
yield this.refreshAll(transaction, obligation, this.findReserveArrayIndex(coinType));
|
|
472
|
-
const result =
|
|
473
|
-
lendingMarket: this.lendingMarket.id,
|
|
474
|
-
reserveArrayIndex: this.findReserveArrayIndex(coinType),
|
|
470
|
+
const result = (0, functions_1.borrow)(transaction, [this.lendingMarket.$typeArgs[0], coinType], {
|
|
471
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
472
|
+
reserveArrayIndex: transaction.pure.u64(this.findReserveArrayIndex(coinType)),
|
|
475
473
|
obligationOwnerCap: obligationOwnerCapId,
|
|
476
|
-
clock: utils_1.SUI_CLOCK_OBJECT_ID,
|
|
474
|
+
clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
477
475
|
amount: BigInt(value),
|
|
478
476
|
});
|
|
479
477
|
return result;
|
|
@@ -486,11 +484,11 @@ class SuilendClient {
|
|
|
486
484
|
});
|
|
487
485
|
}
|
|
488
486
|
repay(obligationId, coinType, coin, transaction) {
|
|
489
|
-
return
|
|
490
|
-
lendingMarket: this.lendingMarket.id,
|
|
491
|
-
reserveArrayIndex: this.findReserveArrayIndex(coinType),
|
|
487
|
+
return (0, functions_1.repay)(transaction, [this.lendingMarket.$typeArgs[0], coinType], {
|
|
488
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
489
|
+
reserveArrayIndex: transaction.pure.u64(this.findReserveArrayIndex(coinType)),
|
|
492
490
|
obligationId: obligationId,
|
|
493
|
-
clock: utils_1.SUI_CLOCK_OBJECT_ID,
|
|
491
|
+
clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
494
492
|
maxRepayCoins: coin,
|
|
495
493
|
});
|
|
496
494
|
}
|
|
@@ -517,12 +515,12 @@ class SuilendClient {
|
|
|
517
515
|
const [optionalExemption] = transaction.moveCall({
|
|
518
516
|
target: `0x1::option::some`,
|
|
519
517
|
typeArguments: [
|
|
520
|
-
`${
|
|
518
|
+
`${suilend_2.PUBLISHED_AT}::lending_market::RateLimiterExemption<${this.lendingMarket.$typeArgs[0]}, ${withdrawCoinType}>`,
|
|
521
519
|
],
|
|
522
520
|
arguments: [exemption],
|
|
523
521
|
});
|
|
524
522
|
return transaction.moveCall({
|
|
525
|
-
target: `${
|
|
523
|
+
target: `${suilend_2.PUBLISHED_AT}::lending_market::redeem_ctokens_and_withdraw_liquidity`,
|
|
526
524
|
typeArguments: [this.lendingMarket.$typeArgs[0], withdrawCoinType],
|
|
527
525
|
arguments: [
|
|
528
526
|
transaction.object(this.lendingMarket.id),
|
|
@@ -537,26 +535,26 @@ class SuilendClient {
|
|
|
537
535
|
liquidate(transaction, obligation, repayCoinType, withdrawCoinType, repayCoinId) {
|
|
538
536
|
return __awaiter(this, void 0, void 0, function* () {
|
|
539
537
|
yield this.refreshAll(transaction, obligation);
|
|
540
|
-
return
|
|
541
|
-
lendingMarket: this.lendingMarket.id,
|
|
538
|
+
return (0, functions_1.liquidate)(transaction, [this.lendingMarket.$typeArgs[0], repayCoinType, withdrawCoinType], {
|
|
539
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
542
540
|
obligationId: obligation.id,
|
|
543
|
-
repayReserveArrayIndex: this.findReserveArrayIndex(repayCoinType),
|
|
544
|
-
withdrawReserveArrayIndex: this.findReserveArrayIndex(withdrawCoinType),
|
|
545
|
-
clock: utils_1.SUI_CLOCK_OBJECT_ID,
|
|
541
|
+
repayReserveArrayIndex: transaction.pure.u64(this.findReserveArrayIndex(repayCoinType)),
|
|
542
|
+
withdrawReserveArrayIndex: transaction.pure.u64(this.findReserveArrayIndex(withdrawCoinType)),
|
|
543
|
+
clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
546
544
|
repayCoins: repayCoinId,
|
|
547
545
|
});
|
|
548
546
|
});
|
|
549
547
|
}
|
|
550
548
|
migrate(transaction, lendingMarketOwnerCapId) {
|
|
551
|
-
return
|
|
552
|
-
lendingMarketOwnerCap: lendingMarketOwnerCapId,
|
|
553
|
-
lendingMarket: this.lendingMarket.id,
|
|
549
|
+
return (0, functions_1.migrate)(transaction, this.lendingMarket.$typeArgs[0], {
|
|
550
|
+
lendingMarketOwnerCap: transaction.object(lendingMarketOwnerCapId),
|
|
551
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
554
552
|
});
|
|
555
553
|
}
|
|
556
554
|
claimFees(transaction, coinType) {
|
|
557
|
-
return
|
|
558
|
-
lendingMarket: this.lendingMarket.id,
|
|
559
|
-
reserveArrayIndex: this.findReserveArrayIndex(coinType),
|
|
555
|
+
return (0, functions_1.claimFees)(transaction, [this.lendingMarket.$typeArgs[0], coinType], {
|
|
556
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
557
|
+
reserveArrayIndex: transaction.pure.u64(this.findReserveArrayIndex(coinType)),
|
|
560
558
|
});
|
|
561
559
|
}
|
|
562
560
|
redeemCtokensAndWithdrawLiquidity(ownerId, ctokenCoinTypes, transaction) {
|
|
@@ -579,10 +577,10 @@ class SuilendClient {
|
|
|
579
577
|
transaction.mergeCoins(transaction.object(mergeCoin.coinObjectId), mergeCoins.map((mc) => transaction.object(mc.coinObjectId)).slice(1));
|
|
580
578
|
}
|
|
581
579
|
const coinType = (0, utils_2.extractCTokenCoinType)(ctokenCoinType);
|
|
582
|
-
const [redeemCoin] =
|
|
583
|
-
lendingMarket: this.lendingMarket.id,
|
|
584
|
-
reserveArrayIndex: this.findReserveArrayIndex(coinType),
|
|
585
|
-
clock: utils_1.SUI_CLOCK_OBJECT_ID,
|
|
580
|
+
const [redeemCoin] = (0, functions_1.redeemCtokensAndWithdrawLiquidity)(transaction, [this.lendingMarket.$typeArgs[0], coinType], {
|
|
581
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
582
|
+
reserveArrayIndex: transaction.pure.u64(this.findReserveArrayIndex(coinType)),
|
|
583
|
+
clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
586
584
|
ctokens: transaction.object(mergeCoin.coinObjectId),
|
|
587
585
|
rateLimiterExemption: null,
|
|
588
586
|
});
|
|
@@ -3,12 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.WAD = exports.maxU64 = void 0;
|
|
7
7
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
8
|
exports.maxU64 = new bignumber_js_1.default(2).pow(64).minus(1);
|
|
9
9
|
exports.WAD = new bignumber_js_1.default(10).pow(18);
|
|
10
|
-
var SdkEnv;
|
|
11
|
-
(function (SdkEnv) {
|
|
12
|
-
SdkEnv["BETA"] = "beta";
|
|
13
|
-
SdkEnv["MAINNET"] = "mainnet";
|
|
14
|
-
})(SdkEnv || (exports.SdkEnv = SdkEnv = {}));
|