Skip to content

Commit

Permalink
feat: msl v6 repay loan
Browse files Browse the repository at this point in the history
  • Loading branch information
mishuagopian committed Feb 23, 2024
1 parent 3d16093 commit f1312cc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/gondi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -323,7 +324,7 @@ export class Gondi {
nftReceiver?: Address;
}) {
return this.contracts.Msl(loan.contractAddress).repayLoan({
loan,
loan: loanToMslLoan(loan),
nftReceiver,
loanId,
});
Expand Down
27 changes: 27 additions & 0 deletions src/utils/loan.ts
Original file line number Diff line number Diff line change
@@ -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,
};
};
2 changes: 0 additions & 2 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export type Writeable<T> = { -readonly [P in keyof T]: T[P] };

export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;

export const isDefined = <T>(value: T | null | undefined): value is T =>
Expand Down

0 comments on commit f1312cc

Please sign in to comment.