From f1312cc593d17b3720ce55381492a0a6be8947b6 Mon Sep 17 00:00:00 2001 From: mishuagopian Date: Fri, 23 Feb 2024 13:06:04 -0300 Subject: [PATCH] feat: msl v6 repay loan --- src/gondi.ts | 3 ++- src/utils/loan.ts | 27 +++++++++++++++++++++++++++ src/utils/types.ts | 2 -- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 src/utils/loan.ts diff --git a/src/gondi.ts b/src/gondi.ts index 33ee82e9..e8665f09 100644 --- a/src/gondi.ts +++ b/src/gondi.ts @@ -17,6 +17,7 @@ import { MarketplaceEnum, OffersSortField, Ordering } from '@/generated/graphql' import * as model from '@/model'; import { Reservoir } from '@/reservoir/Reservoir'; import { isNative, SeaportOrder } from '@/reservoir/utils'; +import { loanToMslLoan } from '@/utils/loan'; import { NATIVE_MARKETPLACE } from '@/utils/string'; export class Gondi { @@ -323,7 +324,7 @@ export class Gondi { nftReceiver?: Address; }) { return this.contracts.Msl(loan.contractAddress).repayLoan({ - loan, + loan: loanToMslLoan(loan), nftReceiver, loanId, }); diff --git a/src/utils/loan.ts b/src/utils/loan.ts new file mode 100644 index 00000000..630bab0f --- /dev/null +++ b/src/utils/loan.ts @@ -0,0 +1,27 @@ +import { Loan } from '@/blockchain'; + +export const loanToMslLoan = (loan: Loan) => { + let source; + if ('source' in loan) { + // Filling floor in sources to match types, but it's unused by V1/V2 + source = loan.source.map((s) => ({ + ...s, + floor: 0n, + })); + } else { + source = loan.tranche; + } + + let protocolFee; + if ('protocolFee' in loan) { + protocolFee = loan.protocolFee; + } else { + protocolFee = 0n; + } + return { + ...loan, + source, + tranche: source, + protocolFee, + }; +}; diff --git a/src/utils/types.ts b/src/utils/types.ts index aa12ec05..75fb6c01 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -1,5 +1,3 @@ -export type Writeable = { -readonly [P in keyof T]: T[P] }; - export type Optional = Pick, K> & Omit; export const isDefined = (value: T | null | undefined): value is T =>