diff --git a/examples/common.ts b/examples/common.ts index f2375754..2122d441 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, }; const approveToken = async (user: Gondi, to: Address) => { diff --git a/src/contracts/MslV5.ts b/src/contracts/MslV5.ts index 5ebb4e53..c1d36e9c 100644 --- a/src/contracts/MslV5.ts +++ b/src/contracts/MslV5.ts @@ -358,6 +358,100 @@ export class MslV5 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}, + "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}, + "source": [ + AttributeDict( + { + "aprBps": ${args.loan.source[0].aprBps}, + "accruedInterest": ${args.loan.source[0].accruedInterest}, + "lender": "${args.loan.source[0].lender}", + "loanId": ${args.loan.source[0].loanId}, + "principalAmount": ${args.loan.source[0].principalAmount}, + "startTime": ${args.loan.source[0].startTime}, + } + ), + AttributeDict( + { + "aprBps": ${args.loan.source[1].aprBps}, + "accruedInterest": ${args.loan.source[1].accruedInterest}, + "lender": "${args.loan.source[1].lender}", + "loanId": ${args.loan.source[1].loanId}, + "principalAmount": ${args.loan.source[1].principalAmount}, + "startTime": ${args.loan.source[1].startTime}, + } + ) + ], + } + ), + "fee": ${args.fee}, + } + ), + "event": "LoanRefinanced", + "logIndex": 2, + "transactionIndex": ${receipt.transactionIndex}, + "transactionHash": HexBytes( + "${receipt.transactionHash}" + ), + "address": MULTI_SOURCE_LOAN_CONTRACT_V5, + "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_V5, + "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}`, diff --git a/src/contracts/MslV6.ts b/src/contracts/MslV6.ts index dcf6d0ff..7e4ceabc 100644 --- a/src/contracts/MslV6.ts +++ b/src/contracts/MslV6.ts @@ -199,6 +199,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}`, @@ -302,6 +394,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": AttributeDict( + { + "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 }; }, };