Skip to content

Commit

Permalink
logs for back testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mishuagopian committed Mar 25, 2024
1 parent 51f3970 commit aeeb42a
Show file tree
Hide file tree
Showing 2 changed files with 330 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
329 changes: 329 additions & 0 deletions src/contracts/MslV6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,98 @@ export class MslV6 extends BaseContract<typeof multiSourceLoanAbiV6> {
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}`,
Expand Down Expand Up @@ -290,6 +382,34 @@ export class MslV6 extends BaseContract<typeof multiSourceLoanAbiV6> {
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 };
},
};
Expand Down Expand Up @@ -332,6 +452,99 @@ export class MslV6 extends BaseContract<typeof multiSourceLoanAbiV6> {
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}`,
Expand Down Expand Up @@ -360,6 +573,96 @@ export class MslV6 extends BaseContract<typeof multiSourceLoanAbiV6> {
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}`,
Expand Down Expand Up @@ -492,6 +795,32 @@ export class MslV6 extends BaseContract<typeof multiSourceLoanAbiV6> {
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,
Expand Down

0 comments on commit aeeb42a

Please sign in to comment.