77 lines
2.3 KiB
JavaScript
77 lines
2.3 KiB
JavaScript
|
|
import { createPublicClient, http, getAddress } from 'viem'
|
||
|
|
import { arbitrumSepolia } from 'viem/chains'
|
||
|
|
|
||
|
|
const client = createPublicClient({
|
||
|
|
chain: arbitrumSepolia,
|
||
|
|
transport: http('https://api.zan.top/node/v1/arb/sepolia/baf84c429d284bb5b676cb8c9ca21c07')
|
||
|
|
})
|
||
|
|
|
||
|
|
const LENDING_PROXY = getAddress('0xCb4E7B1069F6C26A1c27523ce4c8dfD884552d1D')
|
||
|
|
const USER = getAddress('0xa013422A5918CD099C63c8CC35283EACa99a705d')
|
||
|
|
|
||
|
|
const SUPPLY_COLLATERAL_EVENT = {
|
||
|
|
type: 'event',
|
||
|
|
name: 'SupplyCollateral',
|
||
|
|
inputs: [
|
||
|
|
{ indexed: true, name: 'from', type: 'address' },
|
||
|
|
{ indexed: true, name: 'dst', type: 'address' },
|
||
|
|
{ indexed: true, name: 'asset', type: 'address' },
|
||
|
|
{ indexed: false, name: 'amount', type: 'uint256' }
|
||
|
|
]
|
||
|
|
}
|
||
|
|
|
||
|
|
async function main() {
|
||
|
|
console.log('\n检查最近的 SupplyCollateral 事件...\n')
|
||
|
|
|
||
|
|
const latestBlock = await client.getBlockNumber()
|
||
|
|
console.log('最新区块:', latestBlock)
|
||
|
|
console.log('查询范围: 最近 1000 个区块\n')
|
||
|
|
|
||
|
|
try {
|
||
|
|
const logs = await client.getLogs({
|
||
|
|
address: LENDING_PROXY,
|
||
|
|
event: SUPPLY_COLLATERAL_EVENT,
|
||
|
|
fromBlock: latestBlock - 1000n,
|
||
|
|
toBlock: latestBlock
|
||
|
|
})
|
||
|
|
|
||
|
|
if (logs.length === 0) {
|
||
|
|
console.log('未找到任何 SupplyCollateral 事件')
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
console.log('找到', logs.length, '个事件:\n')
|
||
|
|
|
||
|
|
logs.forEach((log, i) => {
|
||
|
|
const { from, dst, asset, amount } = log.args
|
||
|
|
const isCurrentUser = from.toLowerCase() === USER.toLowerCase()
|
||
|
|
|
||
|
|
console.log((i + 1) + '. 区块', log.blockNumber)
|
||
|
|
console.log(' 交易:', log.transactionHash)
|
||
|
|
console.log(' From:', from, isCurrentUser ? '<- 你的地址' : '')
|
||
|
|
console.log(' To:', dst)
|
||
|
|
console.log(' Asset:', asset)
|
||
|
|
console.log(' Amount:', Number(amount) / 1e18)
|
||
|
|
console.log()
|
||
|
|
})
|
||
|
|
|
||
|
|
const userLogs = logs.filter(log =>
|
||
|
|
log.args.from.toLowerCase() === USER.toLowerCase()
|
||
|
|
)
|
||
|
|
|
||
|
|
if (userLogs.length > 0) {
|
||
|
|
console.log('\n找到你的', userLogs.length, '笔存入记录!')
|
||
|
|
console.log('最近一笔:')
|
||
|
|
const latest = userLogs[userLogs.length - 1]
|
||
|
|
console.log(' 交易哈希:', latest.transactionHash)
|
||
|
|
console.log(' 数量:', Number(latest.args.amount) / 1e18, 'YT-A')
|
||
|
|
console.log(' 区块:', latest.blockNumber)
|
||
|
|
}
|
||
|
|
|
||
|
|
} catch (error) {
|
||
|
|
console.error('查询失败:', error.message)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
main()
|