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