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 Feb 27, 2024
1 parent cd8cf81 commit 6df2008
Show file tree
Hide file tree
Showing 3 changed files with 315 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,
};

const approveToken = async (user: Gondi, to: Address) => {
Expand Down
204 changes: 204 additions & 0 deletions src/contracts/MslV5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,91 @@ export class MslV5 extends BaseContract<typeof multiSourceLoanABIV5> {
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(
{
"borrower": "${args.loan.borrower}",
"fee": ${args.fee},
"lender": "${args.loan.source[0].lender}",
"offerId": ${args.offerId},
"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},
"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},
}
)
],
}
),
}
),
"event": "LoanEmitted",
"logIndex": 2,
"transactionIndex": ${receipt.transactionIndex},
"transactionHash": HexBytes(
"${receipt.transactionHash}"
),
"address": MSL_ADDRESS_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": MSL_ADDRESS_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.loanId}`,
Expand Down Expand Up @@ -288,6 +373,31 @@ export class MslV5 extends BaseContract<typeof multiSourceLoanABIV5> {
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": "LoanRefinanced",
"logIndex": 2,
"transactionIndex": ${receipt.transactionIndex},
"transactionHash": HexBytes(
"${receipt.transactionHash}"
),
"address": MSL_ADDRESS_V5,
"blockHash": HexBytes(
"${receipt.blockHash}"
),
"blockNumber": ${receipt.blockNumber},
}
)
`);
return { ...events[0].args, ...receipt };
},
};
Expand Down Expand Up @@ -357,6 +467,100 @@ export class MslV5 extends BaseContract<typeof multiSourceLoanABIV5> {
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": MSL_ADDRESS_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": MSL_ADDRESS_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}`,
Expand Down
110 changes: 110 additions & 0 deletions src/contracts/MslV6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,91 @@ 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},
"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": [
AttributeDict(
{
"accruedInterest": ${args.loan.tranche[0].accruedInterest},
"aprBps": ${args.loan.tranche[0].aprBps},
"floor": "${args.loan.tranche[0].floor}",
"lender": "${args.loan.tranche[0].lender}",
"loanId": ${args.loan.tranche[0].loanId},
"principalAmount": ${args.loan.tranche[0].principalAmount},
"startTime": ${args.loan.tranche[0].startTime},
}
)
],
}
),
}
),
"event": "LoanEmitted",
"logIndex": 2,
"transactionIndex": ${receipt.transactionIndex},
"transactionHash": HexBytes(
"${receipt.transactionHash}"
),
"address": MSL_ADDRESS_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": MSL_ADDRESS_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 @@ -302,6 +387,31 @@ 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": AttributeDict(
{
"loanId": ${args.loanId},
"totalRepayment": ${args.totalRepayment},
"fee": ${args.fee},
}
),
"event": "LoanRefinanced",
"logIndex": 2,
"transactionIndex": ${receipt.transactionIndex},
"transactionHash": HexBytes(
"${receipt.transactionHash}"
),
"address": MSL_ADDRESS_V5,
"blockHash": HexBytes(
"${receipt.blockHash}"
),
"blockNumber": ${receipt.blockNumber},
}
)
`);
return { ...events[0].args, ...receipt };
},
};
Expand Down

0 comments on commit 6df2008

Please sign in to comment.