diff --git a/examples/common.ts b/examples/common.ts index 92974899..ed563f4b 100644 --- a/examples/common.ts +++ b/examples/common.ts @@ -101,6 +101,7 @@ export const testCollectionOfferInput = { export const testSingleNftOfferInput = { ...offerInput, nftId: testNftId, + principalAmount: offerInput.principalAmount / 2n, }; export const approveToken = async (user: Gondi, to: Address) => { diff --git a/src/contracts/MslV6.ts b/src/contracts/MslV6.ts index 010974a6..fc333646 100644 --- a/src/contracts/MslV6.ts +++ b/src/contracts/MslV6.ts @@ -187,6 +187,98 @@ export class MslV6 extends BaseContract { const events = filterLogs(receipt, filter); if (events.length === 0) throw new Error('Loan not emitted'); const args = events[0].args; + const tx = await this.bcClient.getTransaction({ hash: txHash }); + console.log('tx', tx.hash); + console.log(`SAMPLE + MutableAttributeDict( + { + "args": AttributeDict( + { + "fee": ${args.fee}, + "offerId": [${args.offerId.join(',')}], + "loanId": ${args.loanId}, + "loan": AttributeDict( + { + "borrower": "${args.loan.borrower}", + "duration": ${args.loan.duration}, + "nftCollateralAddress": "${args.loan.nftCollateralAddress}", + "nftCollateralTokenId": ${args.loan.nftCollateralTokenId}, + "principalAddress": Currencies.WETH.value.address, + "principalAmount": ${args.loan.principalAmount}, + "protocolFee": ${args.loan.protocolFee}, + "startTime": ${args.loan.startTime}, + "tranche": [${args.loan.tranche + .map( + (tranche) => ` + AttributeDict( + { + "accruedInterest": ${tranche.accruedInterest}, + "aprBps": ${tranche.aprBps}, + "floor": ${tranche.floor}, + "lender": "${tranche.lender}", + "loanId": ${tranche.loanId}, + "principalAmount": ${tranche.principalAmount}, + "startTime": ${tranche.startTime}, + } + )`, + ) + .join(',')} + ], + } + ), + } + ), + "event": "LoanEmitted", + "logIndex": 2, + "transactionIndex": ${receipt.transactionIndex}, + "transactionHash": HexBytes( + "${receipt.transactionHash}" + ), + "address": MULTI_SOURCE_LOAN_CONTRACT_V6, + "blockHash": HexBytes( + "${receipt.blockHash}" + ), + "blockNumber": ${receipt.blockNumber}, + "topics": [ + ${events[0].topics?.map((topic) => `HexBytes("${topic}")`).join(',')}, + ], + } + ) + `); + console.log(`SAMPLE_TX + MutableAttributeDict( + { + "hash": HexBytes( + "${receipt.transactionHash}" + ), + "nonce": ${tx.nonce}, + "blockHash": HexBytes( + "${receipt.blockHash}" + ), + "blockNumber": ${receipt.blockNumber}, + "transactionIndex": ${receipt.transactionIndex}, + "from": "${tx.from}", + "to": MULTI_SOURCE_LOAN_CONTRACT_V6, + "value": ${tx.value}, + "gasPrice": ${tx.gasPrice}, + "gas": ${tx.gas}, + "input": "ASD", + "v": ${tx.v}, + "r": HexBytes( + "${tx.r}" + ), + "s": HexBytes( + "${tx.s}" + ), + "type": 2, + "accessList": [], + "maxPriorityFeePerGas": ${tx.maxPriorityFeePerGas}, + "maxFeePerGas": ${tx.maxFeePerGas}, + "chainId": ${tx.chainId}, + } + ) + `); + console.log(tx.input); return { loan: { id: `${this.contract.address.toLowerCase()}.${args.loanId}`, @@ -290,6 +382,34 @@ export class MslV6 extends BaseContract { const filter = await this.contract.createEventFilter.LoanRepaid(); const events = filterLogs(receipt, filter); if (events.length === 0) throw new Error('Loan not repaid'); + const args = events[0].args; + console.log(`SAMPLE + MutableAttributeDict( + { + "args": MutableAttributeDict( + { + "loanId": ${args.loanId}, + "totalRepayment": ${args.totalRepayment}, + "fee": ${args.fee}, + } + ), + "event": "LoanRepaid", + "logIndex": 2, + "transactionIndex": ${receipt.transactionIndex}, + "transactionHash": HexBytes( + "${receipt.transactionHash}" + ), + "address": MULTI_SOURCE_LOAN_CONTRACT_V6, + "blockHash": HexBytes( + "${receipt.blockHash}" + ), + "blockNumber": ${receipt.blockNumber}, + "topics": [ + ${events[0].topics?.map((topic) => `HexBytes("${topic}")`).join(',')}, + ], + } + ) + `); return { ...events[0].args, ...receipt }; }, }; @@ -332,6 +452,99 @@ export class MslV6 extends BaseContract { const events = filterLogs(receipt, filter); if (events.length === 0) throw new Error('Loan not refinanced'); const args = events[0].args; + const tx = await this.bcClient.getTransaction({ hash: txHash }); + console.log('tx', tx.hash); + console.log(`SAMPLE + MutableAttributeDict( + { + "args": AttributeDict( + { + "oldLoanId": ${args.oldLoanId}, + "newLoanId": ${args.newLoanId}, + "renegotiationId": ${args.renegotiationId}, + "fee": ${args.fee}, + "loan": AttributeDict( + { + "borrower": "${args.loan.borrower}", + "duration": ${args.loan.duration}, + "nftCollateralAddress": "${args.loan.nftCollateralAddress}", + "nftCollateralTokenId": ${args.loan.nftCollateralTokenId}, + "principalAddress": Currencies.WETH.value.address, + "principalAmount": ${args.loan.principalAmount}, + "startTime": ${args.loan.startTime}, + "protocolFee": ${args.loan.protocolFee}, + "tranche": [${args.loan.tranche + .map( + (tranche) => ` + AttributeDict( + { + "accruedInterest": ${tranche.accruedInterest}, + "aprBps": ${tranche.aprBps}, + "floor": ${tranche.floor}, + "lender": "${tranche.lender}", + "loanId": ${tranche.loanId}, + "principalAmount": ${tranche.principalAmount}, + "startTime": ${tranche.startTime}, + } + )`, + ) + .join(',')} + ], + } + ), + } + ), + "event": "LoanRefinanced", + "logIndex": 2, + "transactionIndex": ${receipt.transactionIndex}, + "transactionHash": HexBytes( + "${receipt.transactionHash}" + ), + "address": MULTI_SOURCE_LOAN_CONTRACT_V6, + "blockHash": HexBytes( + "${receipt.blockHash}" + ), + "blockNumber": ${receipt.blockNumber}, + "topics": [ + ${events[0].topics?.map((topic) => `HexBytes("${topic}")`).join(',')}, + ], + } + ) + `); + console.log(`SAMPLE_TX + MutableAttributeDict( + { + "hash": HexBytes( + "${receipt.transactionHash}" + ), + "nonce": ${tx.nonce}, + "blockHash": HexBytes( + "${receipt.blockHash}" + ), + "blockNumber": ${receipt.blockNumber}, + "transactionIndex": ${receipt.transactionIndex}, + "from": "${tx.from}", + "to": MULTI_SOURCE_LOAN_CONTRACT_V6, + "value": ${tx.value}, + "gasPrice": ${tx.gasPrice}, + "gas": ${tx.gas}, + "input": "ASD", + "v": ${tx.v}, + "r": HexBytes( + "${tx.r}" + ), + "s": HexBytes( + "${tx.s}" + ), + "type": 2, + "accessList": [], + "maxPriorityFeePerGas": ${tx.maxPriorityFeePerGas}, + "maxFeePerGas": ${tx.maxFeePerGas}, + "chainId": ${tx.chainId}, + } + ) + `); + console.log(tx.input); return { loan: { id: `${this.contract.address.toLowerCase()}.${args.newLoanId}`, @@ -360,6 +573,96 @@ export class MslV6 extends BaseContract { const events = filterLogs(receipt, filter); if (events.length === 0) throw new Error('Loan not refinanced'); const args = events[0].args; + const tx = await this.bcClient.getTransaction({ hash: txHash }); + console.log('tx', tx.hash); + console.log(`SAMPLE + MutableAttributeDict( + { + "args": AttributeDict( + { + "oldLoanId": ${args.oldLoanId}, + "newLoanId": ${args.newLoanId}, + "renegotiationId": ${args.renegotiationId}, + "fee": ${args.fee}, + "loan": AttributeDict( + { + "borrower": "${args.loan.borrower}", + "duration": ${args.loan.duration}, + "nftCollateralAddress": "${args.loan.nftCollateralAddress}", + "nftCollateralTokenId": ${args.loan.nftCollateralTokenId}, + "principalAddress": Currencies.WETH.value.address, + "principalAmount": ${args.loan.principalAmount}, + "startTime": ${args.loan.startTime}, + "protocolFee": ${args.loan.protocolFee}, + "tranche": [${args.loan.tranche + .map( + (tranche) => ` + AttributeDict( + { + "accruedInterest": ${tranche.accruedInterest}, + "aprBps": ${tranche.aprBps}, + "floor": ${tranche.floor}, + "lender": "${tranche.lender}", + "loanId": ${tranche.loanId}, + "principalAmount": ${tranche.principalAmount}, + "startTime": ${tranche.startTime}, + } + )`, + ) + .join(',')} + ], + } + ), + } + ), + "event": "LoanRefinanced", + "logIndex": 2, + "transactionIndex": ${receipt.transactionIndex}, + "transactionHash": HexBytes( + "${receipt.transactionHash}" + ), + "address": MULTI_SOURCE_LOAN_CONTRACT_V6, + "blockHash": HexBytes( + "${receipt.blockHash}" + ), + "blockNumber": ${receipt.blockNumber}, + } + ) + `); + console.log(`SAMPLE_TX + MutableAttributeDict( + { + "hash": HexBytes( + "${receipt.transactionHash}" + ), + "nonce": ${tx.nonce}, + "blockHash": HexBytes( + "${receipt.blockHash}" + ), + "blockNumber": ${receipt.blockNumber}, + "transactionIndex": ${receipt.transactionIndex}, + "from": "${tx.from}", + "to": MULTI_SOURCE_LOAN_CONTRACT_V6, + "value": ${tx.value}, + "gasPrice": ${tx.gasPrice}, + "gas": ${tx.gas}, + "input": "ASD", + "v": ${tx.v}, + "r": HexBytes( + "${tx.r}" + ), + "s": HexBytes( + "${tx.s}" + ), + "type": 2, + "accessList": [], + "maxPriorityFeePerGas": ${tx.maxPriorityFeePerGas}, + "maxFeePerGas": ${tx.maxFeePerGas}, + "chainId": ${tx.chainId}, + } + ) + `); + console.log(tx.input); return { loan: { id: `${this.contract.address.toLowerCase()}.${args.newLoanId}`, @@ -492,6 +795,32 @@ export class MslV6 extends BaseContract { const sentToLiquidatorEvents = filterLogs(receipt, filterSentToLiquidator); if (foreclosedEvents.length === 0 && sentToLiquidatorEvents.length === 0) throw new Error('Loan not liquidated'); + const args = foreclosedEvents?.[0]?.args ?? {}; + console.log(`SAMPLE + MutableAttributeDict( + { + "args": AttributeDict({ + "loanId": ${args.loanId}, + // liquidator only for "LoanSentToLiquidator" event + "liquidator": AUCTION_LOAN_LIQUIDATOR_CONTRACT_V6, + }) + "event": "LoanForeclosed" or "LoanSentToLiquidator", + "logIndex": 1, + "transactionIndex": ${receipt.transactionIndex}, + "transactionHash": HexBytes( + "${receipt.transactionHash}" + ), + "address": MULTI_SOURCE_LOAN_CONTRACT_V6, + "blockHash": HexBytes( + "${receipt.blockHash}" + ), + "blockNumber": ${receipt.blockNumber}, + "topics": [ + ${foreclosedEvents[0].topics?.map((topic) => `HexBytes("${topic}")`).join(',')}, + ], + } + ) + `); return { ...(foreclosedEvents?.[0]?.args ?? sentToLiquidatorEvents?.[0]?.args), ...receipt,