@liquidium/client 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +263 -205
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -9
- package/dist/index.d.ts +45 -9
- package/dist/index.js +263 -205
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -262,6 +262,7 @@ var idlFactory = ({ IDL }) => {
|
|
|
262
262
|
const Chains = IDL.Variant({
|
|
263
263
|
"BTC": IDL.Null,
|
|
264
264
|
"ETH": IDL.Null,
|
|
265
|
+
"ICP": IDL.Null,
|
|
265
266
|
"SOL": IDL.Null
|
|
266
267
|
});
|
|
267
268
|
const WalletType = IDL.Variant({ "Wallet": Chains });
|
|
@@ -319,8 +320,14 @@ var idlFactory = ({ IDL }) => {
|
|
|
319
320
|
"InsufficientFunds": IDL.Null
|
|
320
321
|
});
|
|
321
322
|
const Result = IDL.Variant({ "Ok": IDL.Null, "Err": ProtocolError });
|
|
323
|
+
const IcrcAccount = IDL.Record({
|
|
324
|
+
"owner": IDL.Principal,
|
|
325
|
+
"subaccount": IDL.Opt(IDL.Vec(IDL.Nat8))
|
|
326
|
+
});
|
|
322
327
|
const AccountType = IDL.Variant({
|
|
328
|
+
"Icrc": IcrcAccount,
|
|
323
329
|
"Native": IDL.Principal,
|
|
330
|
+
"AccountIdentifier": IDL.Text,
|
|
324
331
|
"External": IDL.Text
|
|
325
332
|
});
|
|
326
333
|
const BorrowAssetRequest = IDL.Record({
|
|
@@ -357,6 +364,7 @@ var idlFactory = ({ IDL }) => {
|
|
|
357
364
|
});
|
|
358
365
|
const Assets = IDL.Variant({
|
|
359
366
|
"BTC": IDL.Null,
|
|
367
|
+
"ICP": IDL.Null,
|
|
360
368
|
"SOL": IDL.Null,
|
|
361
369
|
"USDC": IDL.Null,
|
|
362
370
|
"USDT": IDL.Null
|
|
@@ -1387,8 +1395,14 @@ function extractVariantTag(variant, knownTags) {
|
|
|
1387
1395
|
|
|
1388
1396
|
// src/core/canisters/instant-loans/flexible-actor.ts
|
|
1389
1397
|
var flexibleInstantLoansIdlFactory = ({ IDL }) => {
|
|
1398
|
+
const IcrcAccount = IDL.Record({
|
|
1399
|
+
owner: IDL.Principal,
|
|
1400
|
+
subaccount: IDL.Opt(IDL.Vec(IDL.Nat8))
|
|
1401
|
+
});
|
|
1390
1402
|
const AccountType = IDL.Variant({
|
|
1403
|
+
Icrc: IcrcAccount,
|
|
1391
1404
|
Native: IDL.Principal,
|
|
1405
|
+
AccountIdentifier: IDL.Text,
|
|
1392
1406
|
External: IDL.Text
|
|
1393
1407
|
});
|
|
1394
1408
|
const SignatureVerificationError = IDL.Variant({
|
|
@@ -3037,6 +3051,189 @@ function createDepositAccountsActor(canisterContext) {
|
|
|
3037
3051
|
canisterId
|
|
3038
3052
|
});
|
|
3039
3053
|
}
|
|
3054
|
+
var flexibleLendingIdlFactory = ({ IDL }) => {
|
|
3055
|
+
const PoolRecord = IDL.Record({
|
|
3056
|
+
principal: IDL.Principal,
|
|
3057
|
+
asset: IDL.Unknown,
|
|
3058
|
+
chain: IDL.Unknown,
|
|
3059
|
+
total_supply_at_last_sync: IDL.Nat,
|
|
3060
|
+
total_debt_at_last_sync: IDL.Nat,
|
|
3061
|
+
supply_cap: IDL.Opt(IDL.Nat),
|
|
3062
|
+
borrow_cap: IDL.Opt(IDL.Nat),
|
|
3063
|
+
max_ltv: IDL.Nat64,
|
|
3064
|
+
liquidation_threshold: IDL.Nat64,
|
|
3065
|
+
liquidation_bonus: IDL.Nat64,
|
|
3066
|
+
protocol_liquidation_fee: IDL.Nat64,
|
|
3067
|
+
reserve_factor: IDL.Nat64,
|
|
3068
|
+
base_rate: IDL.Nat,
|
|
3069
|
+
optimal_utilization_rate: IDL.Nat,
|
|
3070
|
+
rate_slope_before: IDL.Nat,
|
|
3071
|
+
rate_slope_after: IDL.Nat,
|
|
3072
|
+
lending_index: IDL.Nat,
|
|
3073
|
+
borrow_index: IDL.Nat,
|
|
3074
|
+
same_asset_borrowing: IDL.Opt(IDL.Bool),
|
|
3075
|
+
frozen: IDL.Bool,
|
|
3076
|
+
last_updated: IDL.Opt(IDL.Nat64)
|
|
3077
|
+
});
|
|
3078
|
+
const BorrowingPowerRecord = IDL.Record({
|
|
3079
|
+
max_borrowable_usd: IDL.Nat,
|
|
3080
|
+
weighted_max_ltv: IDL.Nat
|
|
3081
|
+
});
|
|
3082
|
+
const PositionRecord = IDL.Record({
|
|
3083
|
+
asset: IDL.Unknown,
|
|
3084
|
+
total_debt_interest: IDL.Nat,
|
|
3085
|
+
borrow_index_snapshot: IDL.Nat,
|
|
3086
|
+
lending_index_snapshot: IDL.Nat,
|
|
3087
|
+
debt_scaled: IDL.Nat,
|
|
3088
|
+
total_earned_interest: IDL.Nat,
|
|
3089
|
+
deposit_scaled: IDL.Nat,
|
|
3090
|
+
pool_id: IDL.Principal,
|
|
3091
|
+
unpaid_debt_interest: IDL.Nat,
|
|
3092
|
+
last_update: IDL.Nat64,
|
|
3093
|
+
user_profile: IDL.Principal
|
|
3094
|
+
});
|
|
3095
|
+
const UserStatsRecord = IDL.Record({
|
|
3096
|
+
debt: IDL.Nat,
|
|
3097
|
+
collateral: IDL.Nat,
|
|
3098
|
+
acumulated_interest: IDL.Nat,
|
|
3099
|
+
borrowing_power: BorrowingPowerRecord,
|
|
3100
|
+
positions: IDL.Vec(PositionRecord),
|
|
3101
|
+
weighted_liquidation_threshold: IDL.Nat
|
|
3102
|
+
});
|
|
3103
|
+
const PositionViewRecord = IDL.Record({
|
|
3104
|
+
lending_index_now: IDL.Nat,
|
|
3105
|
+
interest_since_snapshot: IDL.Nat,
|
|
3106
|
+
asset: IDL.Unknown,
|
|
3107
|
+
total_debt_interest: IDL.Nat,
|
|
3108
|
+
borrow_index_snapshot: IDL.Nat,
|
|
3109
|
+
debt_native_now: IDL.Nat,
|
|
3110
|
+
borrow_index_now: IDL.Nat,
|
|
3111
|
+
lending_index_snapshot: IDL.Nat,
|
|
3112
|
+
debt_scaled: IDL.Nat,
|
|
3113
|
+
total_earned_interest: IDL.Nat,
|
|
3114
|
+
deposit_scaled: IDL.Nat,
|
|
3115
|
+
earned_since_snapshot: IDL.Nat,
|
|
3116
|
+
deposited_native_now: IDL.Nat,
|
|
3117
|
+
pool_id: IDL.Principal,
|
|
3118
|
+
last_update: IDL.Nat64,
|
|
3119
|
+
user_profile: IDL.Principal
|
|
3120
|
+
});
|
|
3121
|
+
return IDL.Service({
|
|
3122
|
+
list_pools: IDL.Func([], [IDL.Vec(PoolRecord)], ["query"]),
|
|
3123
|
+
get_pool_rate: IDL.Func(
|
|
3124
|
+
[IDL.Principal],
|
|
3125
|
+
[IDL.Opt(IDL.Tuple(IDL.Nat, IDL.Nat, IDL.Nat))],
|
|
3126
|
+
["query"]
|
|
3127
|
+
),
|
|
3128
|
+
get_health_factor: IDL.Func(
|
|
3129
|
+
[IDL.Principal],
|
|
3130
|
+
[IDL.Nat, UserStatsRecord],
|
|
3131
|
+
["query"]
|
|
3132
|
+
),
|
|
3133
|
+
get_profile_stats: IDL.Func([IDL.Principal], [UserStatsRecord], ["query"]),
|
|
3134
|
+
get_position: IDL.Func(
|
|
3135
|
+
[IDL.Principal, IDL.Principal],
|
|
3136
|
+
[IDL.Opt(PositionViewRecord)],
|
|
3137
|
+
["query"]
|
|
3138
|
+
)
|
|
3139
|
+
});
|
|
3140
|
+
};
|
|
3141
|
+
function createFlexibleLendingActor(canisterContext) {
|
|
3142
|
+
const canisterId = canisterContext.canisterIds.lending;
|
|
3143
|
+
if (!canisterId) {
|
|
3144
|
+
throw new LiquidiumError(
|
|
3145
|
+
LiquidiumErrorCode.SERVICE_UNAVAILABLE,
|
|
3146
|
+
"Lending canister ID is not configured"
|
|
3147
|
+
);
|
|
3148
|
+
}
|
|
3149
|
+
return agent.Actor.createActor(flexibleLendingIdlFactory, {
|
|
3150
|
+
agent: canisterContext.agent,
|
|
3151
|
+
canisterId
|
|
3152
|
+
});
|
|
3153
|
+
}
|
|
3154
|
+
function decodeFlexiblePool(pool) {
|
|
3155
|
+
const asset = extractVariantTag(pool.asset, KNOWN_ASSET_TAGS);
|
|
3156
|
+
const chain = extractVariantTag(pool.chain, KNOWN_CHAIN_TAGS);
|
|
3157
|
+
if (!asset || !chain) {
|
|
3158
|
+
return null;
|
|
3159
|
+
}
|
|
3160
|
+
return {
|
|
3161
|
+
principal: pool.principal,
|
|
3162
|
+
asset,
|
|
3163
|
+
chain,
|
|
3164
|
+
total_supply_at_last_sync: pool.total_supply_at_last_sync,
|
|
3165
|
+
total_debt_at_last_sync: pool.total_debt_at_last_sync,
|
|
3166
|
+
supply_cap: pool.supply_cap,
|
|
3167
|
+
borrow_cap: pool.borrow_cap,
|
|
3168
|
+
max_ltv: pool.max_ltv,
|
|
3169
|
+
liquidation_threshold: pool.liquidation_threshold,
|
|
3170
|
+
liquidation_bonus: pool.liquidation_bonus,
|
|
3171
|
+
protocol_liquidation_fee: pool.protocol_liquidation_fee,
|
|
3172
|
+
reserve_factor: pool.reserve_factor,
|
|
3173
|
+
base_rate: pool.base_rate,
|
|
3174
|
+
optimal_utilization_rate: pool.optimal_utilization_rate,
|
|
3175
|
+
rate_slope_before: pool.rate_slope_before,
|
|
3176
|
+
rate_slope_after: pool.rate_slope_after,
|
|
3177
|
+
lending_index: pool.lending_index,
|
|
3178
|
+
borrow_index: pool.borrow_index,
|
|
3179
|
+
same_asset_borrowing: pool.same_asset_borrowing,
|
|
3180
|
+
frozen: pool.frozen,
|
|
3181
|
+
last_updated: pool.last_updated
|
|
3182
|
+
};
|
|
3183
|
+
}
|
|
3184
|
+
function decodeFlexiblePosition(position) {
|
|
3185
|
+
const asset = extractVariantTag(position.asset, KNOWN_ASSET_TAGS);
|
|
3186
|
+
if (!asset) {
|
|
3187
|
+
return null;
|
|
3188
|
+
}
|
|
3189
|
+
return {
|
|
3190
|
+
asset,
|
|
3191
|
+
total_debt_interest: position.total_debt_interest,
|
|
3192
|
+
borrow_index_snapshot: position.borrow_index_snapshot,
|
|
3193
|
+
lending_index_snapshot: position.lending_index_snapshot,
|
|
3194
|
+
debt_scaled: position.debt_scaled,
|
|
3195
|
+
total_earned_interest: position.total_earned_interest,
|
|
3196
|
+
deposit_scaled: position.deposit_scaled,
|
|
3197
|
+
pool_id: position.pool_id,
|
|
3198
|
+
unpaid_debt_interest: position.unpaid_debt_interest,
|
|
3199
|
+
last_update: position.last_update,
|
|
3200
|
+
user_profile: position.user_profile
|
|
3201
|
+
};
|
|
3202
|
+
}
|
|
3203
|
+
function decodeFlexiblePositionView(view) {
|
|
3204
|
+
const asset = extractVariantTag(view.asset, KNOWN_ASSET_TAGS);
|
|
3205
|
+
if (!asset) {
|
|
3206
|
+
return null;
|
|
3207
|
+
}
|
|
3208
|
+
return {
|
|
3209
|
+
lending_index_now: view.lending_index_now,
|
|
3210
|
+
interest_since_snapshot: view.interest_since_snapshot,
|
|
3211
|
+
asset,
|
|
3212
|
+
total_debt_interest: view.total_debt_interest,
|
|
3213
|
+
borrow_index_snapshot: view.borrow_index_snapshot,
|
|
3214
|
+
debt_native_now: view.debt_native_now,
|
|
3215
|
+
borrow_index_now: view.borrow_index_now,
|
|
3216
|
+
lending_index_snapshot: view.lending_index_snapshot,
|
|
3217
|
+
debt_scaled: view.debt_scaled,
|
|
3218
|
+
total_earned_interest: view.total_earned_interest,
|
|
3219
|
+
deposit_scaled: view.deposit_scaled,
|
|
3220
|
+
earned_since_snapshot: view.earned_since_snapshot,
|
|
3221
|
+
deposited_native_now: view.deposited_native_now,
|
|
3222
|
+
pool_id: view.pool_id,
|
|
3223
|
+
last_update: view.last_update,
|
|
3224
|
+
user_profile: view.user_profile
|
|
3225
|
+
};
|
|
3226
|
+
}
|
|
3227
|
+
function decodeFlexibleUserStats(stats) {
|
|
3228
|
+
return {
|
|
3229
|
+
debt: stats.debt,
|
|
3230
|
+
collateral: stats.collateral,
|
|
3231
|
+
acumulated_interest: stats.acumulated_interest,
|
|
3232
|
+
borrowing_power: stats.borrowing_power,
|
|
3233
|
+
positions: stats.positions.map(decodeFlexiblePosition).filter((position) => position !== null),
|
|
3234
|
+
weighted_liquidation_threshold: stats.weighted_liquidation_threshold
|
|
3235
|
+
};
|
|
3236
|
+
}
|
|
3040
3237
|
|
|
3041
3238
|
// src/core/utils/inflow-subaccount.ts
|
|
3042
3239
|
var INFLOW_DEPOSIT_PREFIX = 1;
|
|
@@ -3074,8 +3271,8 @@ var EvmSupplyApprovalStrategy = {
|
|
|
3074
3271
|
// src/modules/lending/_internal/supply-targets.ts
|
|
3075
3272
|
async function resolveSupplyTarget(canisterContext, request) {
|
|
3076
3273
|
const selectedPool = await getPoolById(canisterContext, request.poolId);
|
|
3077
|
-
const asset =
|
|
3078
|
-
const chain =
|
|
3274
|
+
const asset = selectedPool.asset;
|
|
3275
|
+
const chain = selectedPool.chain;
|
|
3079
3276
|
const mechanism = resolveSupplyMechanism({
|
|
3080
3277
|
asset,
|
|
3081
3278
|
chain,
|
|
@@ -3181,15 +3378,16 @@ function mapDepositAccountErrorToLiquidiumError(error) {
|
|
|
3181
3378
|
);
|
|
3182
3379
|
}
|
|
3183
3380
|
async function getPoolById(canisterContext, poolId) {
|
|
3184
|
-
const pools = await
|
|
3381
|
+
const pools = await createFlexibleLendingActor(canisterContext).list_pools();
|
|
3185
3382
|
const selectedPool = pools.find((pool) => pool.principal.toText() === poolId);
|
|
3186
|
-
|
|
3383
|
+
const decodedPool = selectedPool ? decodeFlexiblePool(selectedPool) : null;
|
|
3384
|
+
if (!decodedPool) {
|
|
3187
3385
|
throw new LiquidiumError(
|
|
3188
3386
|
LiquidiumErrorCode.POOL_NOT_FOUND,
|
|
3189
3387
|
`Pool not found: ${poolId}`
|
|
3190
3388
|
);
|
|
3191
3389
|
}
|
|
3192
|
-
return
|
|
3390
|
+
return decodedPool;
|
|
3193
3391
|
}
|
|
3194
3392
|
async function getNativeAddressSupplyTarget(canisterContext, profileId, request) {
|
|
3195
3393
|
assertSupportsNativeAddressInflowTarget(request.asset, request.chain);
|
|
@@ -4336,8 +4534,32 @@ function accountFromCanister(account) {
|
|
|
4336
4534
|
if ("Native" in account) {
|
|
4337
4535
|
return { type: "Native", principal: account.Native.toText() };
|
|
4338
4536
|
}
|
|
4537
|
+
if ("AccountIdentifier" in account) {
|
|
4538
|
+
return {
|
|
4539
|
+
type: "AccountIdentifier",
|
|
4540
|
+
address: account.AccountIdentifier
|
|
4541
|
+
};
|
|
4542
|
+
}
|
|
4543
|
+
if ("Icrc" in account) {
|
|
4544
|
+
const subaccount = normalizeOptionalSubaccount(account.Icrc.subaccount[0]);
|
|
4545
|
+
return {
|
|
4546
|
+
type: "Icrc",
|
|
4547
|
+
owner: account.Icrc.owner.toText(),
|
|
4548
|
+
subaccount,
|
|
4549
|
+
address: icrc.encodeIcrcAccount({
|
|
4550
|
+
owner: account.Icrc.owner,
|
|
4551
|
+
subaccount
|
|
4552
|
+
})
|
|
4553
|
+
};
|
|
4554
|
+
}
|
|
4339
4555
|
return { type: "External", address: account.External };
|
|
4340
4556
|
}
|
|
4557
|
+
function normalizeOptionalSubaccount(subaccount) {
|
|
4558
|
+
if (!subaccount) {
|
|
4559
|
+
return void 0;
|
|
4560
|
+
}
|
|
4561
|
+
return subaccount instanceof Uint8Array ? subaccount : Uint8Array.from(subaccount);
|
|
4562
|
+
}
|
|
4341
4563
|
function mapInstantLoanEvent(event) {
|
|
4342
4564
|
return {
|
|
4343
4565
|
id: event.id,
|
|
@@ -4779,8 +5001,6 @@ function roundInflowFeeEstimate(request, totalFee) {
|
|
|
4779
5001
|
function roundUpToNearest(amount, roundingUnit) {
|
|
4780
5002
|
return ceilDivBigint(amount, roundingUnit) * roundingUnit;
|
|
4781
5003
|
}
|
|
4782
|
-
|
|
4783
|
-
// src/modules/lending/mappers.ts
|
|
4784
5004
|
function mapCanisterOutflowDetails(outflow) {
|
|
4785
5005
|
const rawOutflowType = getVariantKey(outflow.outflow_type);
|
|
4786
5006
|
return {
|
|
@@ -4799,11 +5019,35 @@ function mapCanisterAccountType(receiver) {
|
|
|
4799
5019
|
account: receiver.Native.toText()
|
|
4800
5020
|
};
|
|
4801
5021
|
}
|
|
5022
|
+
if ("AccountIdentifier" in receiver) {
|
|
5023
|
+
return {
|
|
5024
|
+
type: "AccountIdentifier",
|
|
5025
|
+
account: receiver.AccountIdentifier
|
|
5026
|
+
};
|
|
5027
|
+
}
|
|
5028
|
+
if ("Icrc" in receiver) {
|
|
5029
|
+
const subaccount = normalizeOptionalSubaccount2(receiver.Icrc.subaccount[0]);
|
|
5030
|
+
return {
|
|
5031
|
+
type: "Icrc",
|
|
5032
|
+
owner: receiver.Icrc.owner.toText(),
|
|
5033
|
+
subaccount,
|
|
5034
|
+
account: icrc.encodeIcrcAccount({
|
|
5035
|
+
owner: receiver.Icrc.owner,
|
|
5036
|
+
subaccount
|
|
5037
|
+
})
|
|
5038
|
+
};
|
|
5039
|
+
}
|
|
4802
5040
|
return {
|
|
4803
5041
|
type: "External",
|
|
4804
5042
|
account: receiver.External
|
|
4805
5043
|
};
|
|
4806
5044
|
}
|
|
5045
|
+
function normalizeOptionalSubaccount2(subaccount) {
|
|
5046
|
+
if (!subaccount) {
|
|
5047
|
+
return void 0;
|
|
5048
|
+
}
|
|
5049
|
+
return subaccount instanceof Uint8Array ? subaccount : Uint8Array.from(subaccount);
|
|
5050
|
+
}
|
|
4807
5051
|
function normalizeOutflowType(rawOutflowType) {
|
|
4808
5052
|
switch (rawOutflowType) {
|
|
4809
5053
|
case "Withdraw":
|
|
@@ -4997,7 +5241,7 @@ var LendingModule = class {
|
|
|
4997
5241
|
);
|
|
4998
5242
|
}
|
|
4999
5243
|
const selectedPool = await this.getPoolById(request.poolId);
|
|
5000
|
-
const selectedAsset =
|
|
5244
|
+
const selectedAsset = selectedPool.asset;
|
|
5001
5245
|
const minimumBorrowAmountError = getBorrowAmountMinimumValidationError({
|
|
5002
5246
|
amount: request.amount,
|
|
5003
5247
|
asset: selectedAsset
|
|
@@ -5011,7 +5255,7 @@ var LendingModule = class {
|
|
|
5011
5255
|
const receiverAddress = normalizeExternalAddress({
|
|
5012
5256
|
address: destinationAccount,
|
|
5013
5257
|
asset: selectedAsset,
|
|
5014
|
-
chain:
|
|
5258
|
+
chain: selectedPool.chain
|
|
5015
5259
|
});
|
|
5016
5260
|
const lendingActor = createLendingActor(this.canisterContext);
|
|
5017
5261
|
try {
|
|
@@ -5186,8 +5430,8 @@ var LendingModule = class {
|
|
|
5186
5430
|
const selectedPool = await this.getPoolById(request.poolId);
|
|
5187
5431
|
return await this.getEvmSupplyContextForPool({
|
|
5188
5432
|
request,
|
|
5189
|
-
asset:
|
|
5190
|
-
chain:
|
|
5433
|
+
asset: selectedPool.asset,
|
|
5434
|
+
chain: selectedPool.chain
|
|
5191
5435
|
});
|
|
5192
5436
|
}
|
|
5193
5437
|
async getEvmSupplyContextForPool(params) {
|
|
@@ -5602,24 +5846,27 @@ var LendingModule = class {
|
|
|
5602
5846
|
return this.evmReadClient;
|
|
5603
5847
|
}
|
|
5604
5848
|
async getPoolById(poolId) {
|
|
5605
|
-
const pools = await
|
|
5849
|
+
const pools = await createFlexibleLendingActor(
|
|
5850
|
+
this.canisterContext
|
|
5851
|
+
).list_pools();
|
|
5606
5852
|
const selectedPool = pools.find(
|
|
5607
5853
|
(pool) => pool.principal.toText() === poolId
|
|
5608
5854
|
);
|
|
5609
|
-
|
|
5855
|
+
const decodedPool = selectedPool ? decodeFlexiblePool(selectedPool) : null;
|
|
5856
|
+
if (!decodedPool) {
|
|
5610
5857
|
throw new LiquidiumError(
|
|
5611
5858
|
LiquidiumErrorCode.POOL_NOT_FOUND,
|
|
5612
5859
|
`Pool not found: ${poolId}`
|
|
5613
5860
|
);
|
|
5614
5861
|
}
|
|
5615
|
-
return
|
|
5862
|
+
return decodedPool;
|
|
5616
5863
|
}
|
|
5617
5864
|
async normalizeOutflowReceiverAddress(params) {
|
|
5618
5865
|
const selectedPool = await this.getPoolById(params.poolId);
|
|
5619
5866
|
return normalizeExternalAddress({
|
|
5620
5867
|
address: params.receiverAddress,
|
|
5621
|
-
asset:
|
|
5622
|
-
chain:
|
|
5868
|
+
asset: selectedPool.asset,
|
|
5869
|
+
chain: selectedPool.chain
|
|
5623
5870
|
});
|
|
5624
5871
|
}
|
|
5625
5872
|
async sendEthContractTransaction(walletAdapter, walletAddress, request, actionType) {
|
|
@@ -5703,12 +5950,6 @@ function mapExpectedOutflowDetails(details, expectedOutflowType, operation) {
|
|
|
5703
5950
|
`${operation} returned unexpected outflow type ${details.outflowType}`
|
|
5704
5951
|
);
|
|
5705
5952
|
}
|
|
5706
|
-
if (details.receiver.type !== "External") {
|
|
5707
|
-
throw new LiquidiumError(
|
|
5708
|
-
LiquidiumErrorCode.INTERNAL,
|
|
5709
|
-
`${operation} returned unexpected receiver type ${details.receiver.type}`
|
|
5710
|
-
);
|
|
5711
|
-
}
|
|
5712
5953
|
return details;
|
|
5713
5954
|
}
|
|
5714
5955
|
async function delay(timeoutMs) {
|
|
@@ -5744,189 +5985,6 @@ function shouldSubmitInflow(params) {
|
|
|
5744
5985
|
}
|
|
5745
5986
|
return !isEthStablecoin(params.instruction.asset, params.instruction.chain);
|
|
5746
5987
|
}
|
|
5747
|
-
var flexibleLendingIdlFactory = ({ IDL }) => {
|
|
5748
|
-
const PoolRecord = IDL.Record({
|
|
5749
|
-
principal: IDL.Principal,
|
|
5750
|
-
asset: IDL.Unknown,
|
|
5751
|
-
chain: IDL.Unknown,
|
|
5752
|
-
total_supply_at_last_sync: IDL.Nat,
|
|
5753
|
-
total_debt_at_last_sync: IDL.Nat,
|
|
5754
|
-
supply_cap: IDL.Opt(IDL.Nat),
|
|
5755
|
-
borrow_cap: IDL.Opt(IDL.Nat),
|
|
5756
|
-
max_ltv: IDL.Nat64,
|
|
5757
|
-
liquidation_threshold: IDL.Nat64,
|
|
5758
|
-
liquidation_bonus: IDL.Nat64,
|
|
5759
|
-
protocol_liquidation_fee: IDL.Nat64,
|
|
5760
|
-
reserve_factor: IDL.Nat64,
|
|
5761
|
-
base_rate: IDL.Nat,
|
|
5762
|
-
optimal_utilization_rate: IDL.Nat,
|
|
5763
|
-
rate_slope_before: IDL.Nat,
|
|
5764
|
-
rate_slope_after: IDL.Nat,
|
|
5765
|
-
lending_index: IDL.Nat,
|
|
5766
|
-
borrow_index: IDL.Nat,
|
|
5767
|
-
same_asset_borrowing: IDL.Opt(IDL.Bool),
|
|
5768
|
-
frozen: IDL.Bool,
|
|
5769
|
-
last_updated: IDL.Opt(IDL.Nat64)
|
|
5770
|
-
});
|
|
5771
|
-
const BorrowingPowerRecord = IDL.Record({
|
|
5772
|
-
max_borrowable_usd: IDL.Nat,
|
|
5773
|
-
weighted_max_ltv: IDL.Nat
|
|
5774
|
-
});
|
|
5775
|
-
const PositionRecord = IDL.Record({
|
|
5776
|
-
asset: IDL.Unknown,
|
|
5777
|
-
total_debt_interest: IDL.Nat,
|
|
5778
|
-
borrow_index_snapshot: IDL.Nat,
|
|
5779
|
-
lending_index_snapshot: IDL.Nat,
|
|
5780
|
-
debt_scaled: IDL.Nat,
|
|
5781
|
-
total_earned_interest: IDL.Nat,
|
|
5782
|
-
deposit_scaled: IDL.Nat,
|
|
5783
|
-
pool_id: IDL.Principal,
|
|
5784
|
-
unpaid_debt_interest: IDL.Nat,
|
|
5785
|
-
last_update: IDL.Nat64,
|
|
5786
|
-
user_profile: IDL.Principal
|
|
5787
|
-
});
|
|
5788
|
-
const UserStatsRecord = IDL.Record({
|
|
5789
|
-
debt: IDL.Nat,
|
|
5790
|
-
collateral: IDL.Nat,
|
|
5791
|
-
acumulated_interest: IDL.Nat,
|
|
5792
|
-
borrowing_power: BorrowingPowerRecord,
|
|
5793
|
-
positions: IDL.Vec(PositionRecord),
|
|
5794
|
-
weighted_liquidation_threshold: IDL.Nat
|
|
5795
|
-
});
|
|
5796
|
-
const PositionViewRecord = IDL.Record({
|
|
5797
|
-
lending_index_now: IDL.Nat,
|
|
5798
|
-
interest_since_snapshot: IDL.Nat,
|
|
5799
|
-
asset: IDL.Unknown,
|
|
5800
|
-
total_debt_interest: IDL.Nat,
|
|
5801
|
-
borrow_index_snapshot: IDL.Nat,
|
|
5802
|
-
debt_native_now: IDL.Nat,
|
|
5803
|
-
borrow_index_now: IDL.Nat,
|
|
5804
|
-
lending_index_snapshot: IDL.Nat,
|
|
5805
|
-
debt_scaled: IDL.Nat,
|
|
5806
|
-
total_earned_interest: IDL.Nat,
|
|
5807
|
-
deposit_scaled: IDL.Nat,
|
|
5808
|
-
earned_since_snapshot: IDL.Nat,
|
|
5809
|
-
deposited_native_now: IDL.Nat,
|
|
5810
|
-
pool_id: IDL.Principal,
|
|
5811
|
-
last_update: IDL.Nat64,
|
|
5812
|
-
user_profile: IDL.Principal
|
|
5813
|
-
});
|
|
5814
|
-
return IDL.Service({
|
|
5815
|
-
list_pools: IDL.Func([], [IDL.Vec(PoolRecord)], ["query"]),
|
|
5816
|
-
get_pool_rate: IDL.Func(
|
|
5817
|
-
[IDL.Principal],
|
|
5818
|
-
[IDL.Opt(IDL.Tuple(IDL.Nat, IDL.Nat, IDL.Nat))],
|
|
5819
|
-
["query"]
|
|
5820
|
-
),
|
|
5821
|
-
get_health_factor: IDL.Func(
|
|
5822
|
-
[IDL.Principal],
|
|
5823
|
-
[IDL.Nat, UserStatsRecord],
|
|
5824
|
-
["query"]
|
|
5825
|
-
),
|
|
5826
|
-
get_profile_stats: IDL.Func([IDL.Principal], [UserStatsRecord], ["query"]),
|
|
5827
|
-
get_position: IDL.Func(
|
|
5828
|
-
[IDL.Principal, IDL.Principal],
|
|
5829
|
-
[IDL.Opt(PositionViewRecord)],
|
|
5830
|
-
["query"]
|
|
5831
|
-
)
|
|
5832
|
-
});
|
|
5833
|
-
};
|
|
5834
|
-
function createFlexibleLendingActor(canisterContext) {
|
|
5835
|
-
const canisterId = canisterContext.canisterIds.lending;
|
|
5836
|
-
if (!canisterId) {
|
|
5837
|
-
throw new LiquidiumError(
|
|
5838
|
-
LiquidiumErrorCode.SERVICE_UNAVAILABLE,
|
|
5839
|
-
"Lending canister ID is not configured"
|
|
5840
|
-
);
|
|
5841
|
-
}
|
|
5842
|
-
return agent.Actor.createActor(flexibleLendingIdlFactory, {
|
|
5843
|
-
agent: canisterContext.agent,
|
|
5844
|
-
canisterId
|
|
5845
|
-
});
|
|
5846
|
-
}
|
|
5847
|
-
function decodeFlexiblePool(pool) {
|
|
5848
|
-
const asset = extractVariantTag(pool.asset, KNOWN_ASSET_TAGS);
|
|
5849
|
-
const chain = extractVariantTag(pool.chain, KNOWN_CHAIN_TAGS);
|
|
5850
|
-
if (!asset || !chain) {
|
|
5851
|
-
return null;
|
|
5852
|
-
}
|
|
5853
|
-
return {
|
|
5854
|
-
principal: pool.principal,
|
|
5855
|
-
asset,
|
|
5856
|
-
chain,
|
|
5857
|
-
total_supply_at_last_sync: pool.total_supply_at_last_sync,
|
|
5858
|
-
total_debt_at_last_sync: pool.total_debt_at_last_sync,
|
|
5859
|
-
supply_cap: pool.supply_cap,
|
|
5860
|
-
borrow_cap: pool.borrow_cap,
|
|
5861
|
-
max_ltv: pool.max_ltv,
|
|
5862
|
-
liquidation_threshold: pool.liquidation_threshold,
|
|
5863
|
-
liquidation_bonus: pool.liquidation_bonus,
|
|
5864
|
-
protocol_liquidation_fee: pool.protocol_liquidation_fee,
|
|
5865
|
-
reserve_factor: pool.reserve_factor,
|
|
5866
|
-
base_rate: pool.base_rate,
|
|
5867
|
-
optimal_utilization_rate: pool.optimal_utilization_rate,
|
|
5868
|
-
rate_slope_before: pool.rate_slope_before,
|
|
5869
|
-
rate_slope_after: pool.rate_slope_after,
|
|
5870
|
-
lending_index: pool.lending_index,
|
|
5871
|
-
borrow_index: pool.borrow_index,
|
|
5872
|
-
same_asset_borrowing: pool.same_asset_borrowing,
|
|
5873
|
-
frozen: pool.frozen,
|
|
5874
|
-
last_updated: pool.last_updated
|
|
5875
|
-
};
|
|
5876
|
-
}
|
|
5877
|
-
function decodeFlexiblePosition(position) {
|
|
5878
|
-
const asset = extractVariantTag(position.asset, KNOWN_ASSET_TAGS);
|
|
5879
|
-
if (!asset) {
|
|
5880
|
-
return null;
|
|
5881
|
-
}
|
|
5882
|
-
return {
|
|
5883
|
-
asset,
|
|
5884
|
-
total_debt_interest: position.total_debt_interest,
|
|
5885
|
-
borrow_index_snapshot: position.borrow_index_snapshot,
|
|
5886
|
-
lending_index_snapshot: position.lending_index_snapshot,
|
|
5887
|
-
debt_scaled: position.debt_scaled,
|
|
5888
|
-
total_earned_interest: position.total_earned_interest,
|
|
5889
|
-
deposit_scaled: position.deposit_scaled,
|
|
5890
|
-
pool_id: position.pool_id,
|
|
5891
|
-
unpaid_debt_interest: position.unpaid_debt_interest,
|
|
5892
|
-
last_update: position.last_update,
|
|
5893
|
-
user_profile: position.user_profile
|
|
5894
|
-
};
|
|
5895
|
-
}
|
|
5896
|
-
function decodeFlexiblePositionView(view) {
|
|
5897
|
-
const asset = extractVariantTag(view.asset, KNOWN_ASSET_TAGS);
|
|
5898
|
-
if (!asset) {
|
|
5899
|
-
return null;
|
|
5900
|
-
}
|
|
5901
|
-
return {
|
|
5902
|
-
lending_index_now: view.lending_index_now,
|
|
5903
|
-
interest_since_snapshot: view.interest_since_snapshot,
|
|
5904
|
-
asset,
|
|
5905
|
-
total_debt_interest: view.total_debt_interest,
|
|
5906
|
-
borrow_index_snapshot: view.borrow_index_snapshot,
|
|
5907
|
-
debt_native_now: view.debt_native_now,
|
|
5908
|
-
borrow_index_now: view.borrow_index_now,
|
|
5909
|
-
lending_index_snapshot: view.lending_index_snapshot,
|
|
5910
|
-
debt_scaled: view.debt_scaled,
|
|
5911
|
-
total_earned_interest: view.total_earned_interest,
|
|
5912
|
-
deposit_scaled: view.deposit_scaled,
|
|
5913
|
-
earned_since_snapshot: view.earned_since_snapshot,
|
|
5914
|
-
deposited_native_now: view.deposited_native_now,
|
|
5915
|
-
pool_id: view.pool_id,
|
|
5916
|
-
last_update: view.last_update,
|
|
5917
|
-
user_profile: view.user_profile
|
|
5918
|
-
};
|
|
5919
|
-
}
|
|
5920
|
-
function decodeFlexibleUserStats(stats) {
|
|
5921
|
-
return {
|
|
5922
|
-
debt: stats.debt,
|
|
5923
|
-
collateral: stats.collateral,
|
|
5924
|
-
acumulated_interest: stats.acumulated_interest,
|
|
5925
|
-
borrowing_power: stats.borrowing_power,
|
|
5926
|
-
positions: stats.positions.map(decodeFlexiblePosition).filter((position) => position !== null),
|
|
5927
|
-
weighted_liquidation_threshold: stats.weighted_liquidation_threshold
|
|
5928
|
-
};
|
|
5929
|
-
}
|
|
5930
5988
|
|
|
5931
5989
|
// src/modules/market/mappers.ts
|
|
5932
5990
|
var DECIMAL_BASE = 10;
|