109 lines
3.5 KiB
JavaScript
109 lines
3.5 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 YT_A = getAddress('0x97204190B35D9895a7a47aa7BaC61ac08De3cF05')
|
||
|
|
const LENDING_PROXY = getAddress('0xCb4E7B1069F6C26A1c27523ce4c8dfD884552d1D')
|
||
|
|
const USER = getAddress('0xa013422A5918CD099C63c8CC35283EACa99a705d')
|
||
|
|
|
||
|
|
const TRANSFER_EVENT = {
|
||
|
|
type: 'event',
|
||
|
|
name: 'Transfer',
|
||
|
|
inputs: [
|
||
|
|
{ indexed: true, name: 'from', type: 'address' },
|
||
|
|
{ indexed: true, name: 'to', type: 'address' },
|
||
|
|
{ indexed: false, name: 'value', type: 'uint256' }
|
||
|
|
]
|
||
|
|
}
|
||
|
|
|
||
|
|
async function main() {
|
||
|
|
console.log('\n检查 YT-A 代币转账... \n')
|
||
|
|
|
||
|
|
const latestBlock = await client.getBlockNumber()
|
||
|
|
console.log('最新区块:', latestBlock)
|
||
|
|
console.log('查询范围: 最近 1000 个区块\n')
|
||
|
|
|
||
|
|
try {
|
||
|
|
// 检查转入 Lending 合约的 Transfer
|
||
|
|
console.log('--- 1. 查找转入 Lending 合约的转账 ---')
|
||
|
|
const logsTo = await client.getLogs({
|
||
|
|
address: YT_A,
|
||
|
|
event: TRANSFER_EVENT,
|
||
|
|
args: {
|
||
|
|
to: LENDING_PROXY
|
||
|
|
},
|
||
|
|
fromBlock: latestBlock - 1000n,
|
||
|
|
toBlock: latestBlock
|
||
|
|
})
|
||
|
|
|
||
|
|
if (logsTo.length === 0) {
|
||
|
|
console.log('✗ 未找到任何转入 Lending 合约的转账\n')
|
||
|
|
} else {
|
||
|
|
console.log('✓ 找到', logsTo.length, '笔转入记录:\n')
|
||
|
|
logsTo.forEach((log, i) => {
|
||
|
|
const { from, to, value } = log.args
|
||
|
|
const isFromUser = from.toLowerCase() === USER.toLowerCase()
|
||
|
|
console.log((i + 1) + '. 区块', log.blockNumber)
|
||
|
|
console.log(' 交易:', log.transactionHash)
|
||
|
|
console.log(' From:', from, isFromUser ? '<- 你的地址' : '')
|
||
|
|
console.log(' To:', to)
|
||
|
|
console.log(' Amount:', Number(value) / 1e18, 'YT-A')
|
||
|
|
console.log()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// 检查从用户发出的 Transfer
|
||
|
|
console.log('--- 2. 查找从你的地址发出的转账 ---')
|
||
|
|
const logsFrom = await client.getLogs({
|
||
|
|
address: YT_A,
|
||
|
|
event: TRANSFER_EVENT,
|
||
|
|
args: {
|
||
|
|
from: USER
|
||
|
|
},
|
||
|
|
fromBlock: latestBlock - 1000n,
|
||
|
|
toBlock: latestBlock
|
||
|
|
})
|
||
|
|
|
||
|
|
if (logsFrom.length === 0) {
|
||
|
|
console.log('✗ 未找到任何从你地址发出的转账\n')
|
||
|
|
} else {
|
||
|
|
console.log('✓ 找到', logsFrom.length, '笔转出记录:\n')
|
||
|
|
logsFrom.forEach((log, i) => {
|
||
|
|
const { from, to, value } = log.args
|
||
|
|
const isToLending = to.toLowerCase() === LENDING_PROXY.toLowerCase()
|
||
|
|
console.log((i + 1) + '. 区块', log.blockNumber)
|
||
|
|
console.log(' 交易:', log.transactionHash)
|
||
|
|
console.log(' From:', from)
|
||
|
|
console.log(' To:', to, isToLending ? '<- Lending 合约' : '')
|
||
|
|
console.log(' Amount:', Number(value) / 1e18, 'YT-A')
|
||
|
|
console.log()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// 检查用户的 YT-A 余额
|
||
|
|
console.log('--- 3. 检查当前 YT-A 余额 ---')
|
||
|
|
const balance = await client.readContract({
|
||
|
|
address: YT_A,
|
||
|
|
abi: [{
|
||
|
|
inputs: [{ internalType: 'address', name: 'account', type: 'address' }],
|
||
|
|
name: 'balanceOf',
|
||
|
|
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||
|
|
stateMutability: 'view',
|
||
|
|
type: 'function'
|
||
|
|
}],
|
||
|
|
functionName: 'balanceOf',
|
||
|
|
args: [USER]
|
||
|
|
})
|
||
|
|
console.log('你的 YT-A 余额:', Number(balance) / 1e18, '\n')
|
||
|
|
|
||
|
|
} catch (error) {
|
||
|
|
console.error('查询失败:', error.message)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
main()
|