30 justlend(compound fork)如何查看token的collateral factor

先说说我是怎么查到compound的ctoken的抵押率的
比如cDAI
cDAI的合约里面,可以找到comptroller合约,顺藤摸瓜找到proxy合约
浏览器里面直接读取代理合约,注意martkets函数,输入ctoken的地址,就可以查到对应的抵押率
这里输入cDAI的地址0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643,可得抵押率是82.5%
这里参考了compound官方文档中关于抵押率的描述

但是在justlend同样操作就报错了
比如通过jUSDC合约,可以查到comptroller合约
但是这个comptroller合约却没有显示有代理合约
不过通过读取合约,可以进一步查找到comptrollerImplementation合约
问题来了,直接通过comptrollerImplementation合约直接调用markets函数是不行的,我想是不是应该通过proxy来调用

于是我尝试了以下方法,创建tron合约,修改合约的abi地址
也就是以下代码

jUSDC = "TNSBA6KvSvMoTqQcEgpVK7VhHT3z7wifxy"
mystr = "xxxx"  # 函数的abi str,此处省略
comptroller = client.get_contract("TGjYzgCyPobsNS9n6WcbdLVR9dH7mWqFx7")
comptroller.abi=json.loads(mystr)
comptroller.functions.markets(jUSDC)

结果报错了,提示合约没有此函数

然后我又尝试通过Contract类创建合约,代码类似

jUSDC = "TNSBA6KvSvMoTqQcEgpVK7VhHT3z7wifxy"
mystr = "xxxx"  # 函数的abi str,此处省略
comptroller = Contract(addr="TGjYzgCyPobsNS9n6WcbdLVR9dH7mWqFx7", abi=json.loads(mystr))
comptroller.functions.markets(jUSDC)

结果还是一样的错误提示,不包含此函数
tron合约部分参考的是tronpy官方文档

那要怎么才能读取到这个抵押率值呢?不限制一定要python,因为web3的python和js大概都能互相参考了

请先 登录 后评论

1 个回答

七哥 - 独立开发者
  擅长:Defi

这是因为你没有将合约和网络绑定或者ABI使用错误。正确代码如下:

from tronpy import Tron,Contract
import json

client = Tron()
cntr = client.get_contract('TGjYzgCyPobsNS9n6WcbdLVR9dH7mWqFx7')
cntr.abi=json.loads(mystr)
jUSDC = "TNSBA6KvSvMoTqQcEgpVK7VhHT3z7wifxy"
print(cntr.functions.markets(jUSDC))

mystr='''
[ 
	{
		"constant": true,
		"inputs": [
			{
				"internalType": "address",
				"name": "",
				"type": "address"
			}
		],
		"name": "markets",
		"outputs": [
			{
				"internalType": "bool",
				"name": "isListed",
				"type": "bool"
			},
			{
				"internalType": "uint256",
				"name": "collateralFactorMantissa",
				"type": "uint256"
			},
			{
				"internalType": "bool",
				"name": "isComped",
				"type": "bool"
			}
		],
		"payable": false,
		"stateMutability": "view",
		"type": "function"
	}
]
'''
请先 登录 后评论
  • 1 关注
  • 0 收藏,2905 浏览
  • ETH_IS_OK 提出于 2022-06-27 05:21