Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/util/src/Comptroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export namespace Comptroller {
export async function GetStorage(address: string, protocolAddresses: ProtocolAddresses, server: string): Promise<Storage> {
const storageResult = await TezosNodeReader.getContractStorage(server, address);
// get marketsMapId
const marketsMapId = JSONPath({ path: '$.args[0].args[1].args[2].int', json: storageResult })[0];
const marketsMapId = JSONPath({ path: '$.args[0].args[1].args[1].int', json: storageResult })[0];
// get all market values for fTokens from protocolAddresses
const markets: MarketMap = {};

Expand All @@ -73,14 +73,14 @@ export namespace Comptroller {
// parse results
try {
return {
accountLiquidityMapId: JSONPath({ path: '$.args[0].args[0].args[0].args[0].int', json: storageResult })[0],
collateralsMapId: JSONPath({ path: '$.args[0].args[0].args[1].args[1].int', json: storageResult })[0],
loansMapId: JSONPath({ path: '$.args[0].args[1].args[0].args[1].int', json: storageResult })[0],
administrator: JSONPath({ path: '$.args[0].args[0].args[0].args[2].string', json: storageResult })[0],
closeFactorMantissa: JSONPath({ path: '$.args[0].args[0].args[1].args[0].int', json: storageResult })[0],
expScale: JSONPath({ path: '$.args[0].args[0].args[2].int', json: storageResult })[0],
halfExpScale: JSONPath({ path: '$.args[0].args[0].args[3].int', json: storageResult })[0],
liquidationIncentiveMantissa: JSONPath({ path: '$.args[0].args[1].args[0].args[0].int', json: storageResult })[0],
accountLiquidityMapId: JSONPath({ path: '$.args[0].args[0].args[0].args[0].args[0].int', json: storageResult })[0],
collateralsMapId: JSONPath({ path: '$.args[0].args[0].args[1].args[0].int', json: storageResult })[0],
loansMapId: JSONPath({ path: '$.args[0].args[1].args[0].args[0].int', json: storageResult })[0],
administrator: JSONPath({ path: '$.args[0].args[0].args[0].args[1].string', json: storageResult })[0],
closeFactorMantissa: JSONPath({ path: '$.args[0].args[0].args[0].args[2].int', json: storageResult })[0],
expScale: JSONPath({ path: '$.args[0].args[0].args[1].args[1].int', json: storageResult })[0],
halfExpScale: JSONPath({ path: '$.args[0].args[0].args[2].int', json: storageResult })[0],
liquidationIncentiveMantissa: JSONPath({ path: '$.args[0].args[0].args[3].int', json: storageResult })[0],
marketsMapId: marketsMapId,
oracleAddress: JSONPath({ path: '$.args[0].args[2].args[1].string', json: storageResult })[0],
pendingAdministrator: JSONPath({ path: '$.args[0].args[3].prim', json: storageResult })[0],
Expand Down
91 changes: 55 additions & 36 deletions src/util/src/FToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export namespace FToken {
accrualBlockNumber: number;
administrator: string;
balancesMapId: number;
borrowsMapId: number;
supply: {
numSuppliers?: number;
totalSupply: bigInt.BigInteger;
Expand Down Expand Up @@ -72,7 +73,11 @@ export namespace FToken {
case TokenStandard.FA12: {
const storageResult = await TezosNodeReader.getContractStorage(server, fTokenAddress);
const balancesMapId = JSONPath({
path: '$.args[0].args[0].args[0].args[2].int',
path: '$.args[0].args[1].args[0].args[2].int',
json: storageResult,
})[0];
const borrowsMapId = JSONPath({
path: '$.args[0].args[0].args[1].args[0].int',
json: storageResult,
})[0];
const adminJsonPrase = JSONPath({ path: '$.args[0].args[1].args[2].prim', json: storageResult })[0];
Expand All @@ -93,41 +98,42 @@ export namespace FToken {
json: storageResult,
})[0],
administrator: JSONPath({
path: '$.args[0].args[0].args[0].args[1].string',
path: '$.args[0].args[0].args[0].args[0].args[2].string',
json: storageResult,
})[0],
balancesMapId: balancesMapId,
borrowsMapId: borrowsMapId,
supply: {
totalSupply: bigInt(JSONPath({ path: '$.args[0].args[5].int', json: storageResult })[0]),
supplyRatePerBlock: bigInt(
JSONPath({ path: '$.args[0].args[2].args[2].int', json: storageResult })[0],
),
},
borrow: {
totalBorrows: bigInt(JSONPath({ path: '$.args[0].args[3].int', json: storageResult })[0]),
totalBorrows: bigInt(JSONPath({ path: '$.args[0].args[3].args[1].int', json: storageResult })[0]),
borrowIndex: bigInt(
JSONPath({ path: '$.args[0].args[0].args[0].args[3].int', json: storageResult })[0],
JSONPath({ path: '$.args[0].args[0].args[0].args[1].int', json: storageResult })[0],
),
borrowRateMaxMantissa: bigInt(
JSONPath({ path: '$.args[0].args[0].args[1].args[0].int', json: storageResult })[0],
JSONPath({ path: '$.args[0].args[0].args[0].args[2].int', json: storageResult })[0],
),
borrowRatePerBlock: bigInt(
JSONPath({ path: '$.args[0].args[0].args[1].args[1].int', json: storageResult })[0],
JSONPath({ path: '$.args[0].args[0].args[0].args[3].int', json: storageResult })[0],
),
},
protocolSeizeShareMantissa: bigInt(protocolSeizeShareMantissa),
comptrollerAddress: JSONPath({
path: '$.args[0].args[0].args[1].args[2].string',
path: '$.args[0].args[0].args[1].args[1].string',
json: storageResult,
})[0],
expScale: bigInt(JSONPath({ path: '$.args[0].args[0].args[3].int', json: storageResult })[0]),
expScale: bigInt(JSONPath({ path: '$.args[0].args[0].args[2].int', json: storageResult })[0]),
halfExpScale: bigInt(
JSONPath({ path: '$.args[0].args[1].args[0].args[0].int', json: storageResult })[0],
JSONPath({ path: '$.args[0].args[0].args[4].int', json: storageResult })[0],
),
initialExchangeRateMantissa: bigInt(
JSONPath({ path: '$.args[0].args[1].args[0].args[1].int', json: storageResult })[0],
JSONPath({ path: '$.args[0].args[1].args[0].args[0].int', json: storageResult })[0],
),
interestRateModel: JSONPath({ path: '$.args[0].args[1].args[1].string', json: storageResult })[0],
interestRateModel: JSONPath({ path: '$.args[0].args[1].args[0].args[1].string', json: storageResult })[0],
pendingAdministrator: pendingAdministrator,
reserveFactorMantissa: bigInt(
JSONPath({ path: '$.args[0].args[2].args[0].int', json: storageResult })[0],
Expand All @@ -142,7 +148,11 @@ export namespace FToken {
case TokenStandard.FA2: {
const storageResult = await TezosNodeReader.getContractStorage(server, fTokenAddress);
const balancesMapId = JSONPath({
path: '$.args[0].args[0].args[0].args[2].int',
path: '$.args[0].args[1].args[0].args[1].int',
json: storageResult,
})[0];
const borrowsMapId = JSONPath({
path: '$.args[0].args[0].args[1].args[0].int',
json: storageResult,
})[0];
const adminJsonPrase = JSONPath({ path: '$.args[0].args[1].args[1].prim', json: storageResult })[0];
Expand All @@ -163,42 +173,43 @@ export namespace FToken {
json: storageResult,
})[0],
administrator: JSONPath({
path: '$.args[0].args[0].args[0].args[1].string',
path: '$.args[0].args[0].args[0].args[0].args[2].string',
json: storageResult,
})[0],
balancesMapId: balancesMapId,
borrowsMapId: borrowsMapId,
supply: {
totalSupply: bigInt(JSONPath({ path: '$.args[0].args[5].int', json: storageResult })[0]),
supplyRatePerBlock: bigInt(
JSONPath({ path: '$.args[0].args[2].args[1].int', json: storageResult })[0],
),
},
borrow: {
totalBorrows: bigInt(JSONPath({ path: '$.args[0].args[3].int', json: storageResult })[0]),
totalBorrows: bigInt(JSONPath({ path: '$.args[0].args[3].args[1].int', json: storageResult })[0]),
borrowIndex: bigInt(
JSONPath({ path: '$.args[0].args[0].args[0].args[3].int', json: storageResult })[0],
JSONPath({ path: '$.args[0].args[0].args[0].args[1].int', json: storageResult })[0],
),
borrowRateMaxMantissa: bigInt(
JSONPath({ path: '$.args[0].args[0].args[1].args[0].int', json: storageResult })[0],
JSONPath({ path: '$.args[0].args[0].args[0].args[2].int', json: storageResult })[0],
),
borrowRatePerBlock: bigInt(
JSONPath({ path: '$.args[0].args[0].args[1].args[1].int', json: storageResult })[0],
JSONPath({ path: '$.args[0].args[0].args[0].args[3].int', json: storageResult })[0],
),
},
protocolSeizeShareMantissa: bigInt(protocolSeizeShareMantissa),
comptrollerAddress: JSONPath({
path: '$.args[0].args[0].args[1].args[2].string',
path: '$.args[0].args[0].args[1].args[1].string',
json: storageResult,
})[0],
expScale: bigInt(JSONPath({ path: '$.args[0].args[0].args[3].int', json: storageResult })[0]),
expScale: bigInt(JSONPath({ path: '$.args[0].args[0].args[2].args[0].int', json: storageResult })[0]),
halfExpScale: bigInt(
JSONPath({ path: '$.args[0].args[1].args[0].args[0].int', json: storageResult })[0],
JSONPath({ path: '$.args[0].args[0].args[3].int', json: storageResult })[0],
),
initialExchangeRateMantissa: bigInt(
JSONPath({ path: '$.args[0].args[1].args[0].args[1].int', json: storageResult })[0],
JSONPath({ path: '$.args[0].args[0].args[4].int', json: storageResult })[0],
),
interestRateModel: JSONPath({
path: '$.args[0].args[1].args[0].args[2].string',
path: '$.args[0].args[1].args[0].args[0].string',
json: storageResult,
})[0],
pendingAdministrator: pendingAdministrator,
Expand All @@ -215,7 +226,11 @@ export namespace FToken {
case TokenStandard.XTZ: {
const storageResult = await TezosNodeReader.getContractStorage(server, fTokenAddress);
const balancesMapId = JSONPath({
path: '$.args[0].args[0].args[0].args[2].int',
path: '$.args[0].args[1].args[0].args[1].int',
json: storageResult,
})[0];
const borrowsMapId = JSONPath({
path: '$.args[0].args[0].args[1].args[1].int',
json: storageResult,
})[0];
const adminJsonPrase = JSONPath({ path: '$.args[0].args[1].args[1].prim', json: storageResult })[0];
Expand All @@ -241,6 +256,7 @@ export namespace FToken {
json: storageResult,
})[0],
balancesMapId: balancesMapId,
borrowsMapId: borrowsMapId,
supply: {
totalSupply: bigInt(JSONPath({ path: '$.args[0].args[5].int', json: storageResult })[0]),
supplyRatePerBlock: bigInt(
Expand All @@ -250,24 +266,24 @@ export namespace FToken {
borrow: {
totalBorrows: bigInt(JSONPath({ path: '$.args[0].args[3].int', json: storageResult })[0]),
borrowIndex: bigInt(
JSONPath({ path: '$.args[0].args[0].args[0].args[3].int', json: storageResult })[0],
JSONPath({ path: '$.args[0].args[0].args[0].args[2].int', json: storageResult })[0],
),
borrowRateMaxMantissa: bigInt(
JSONPath({ path: '$.args[0].args[0].args[1].args[0].int', json: storageResult })[0],
JSONPath({ path: '$.args[0].args[0].args[0].args[3].int', json: storageResult })[0],
),
borrowRatePerBlock: bigInt(
JSONPath({ path: '$.args[0].args[0].args[1].args[1].int', json: storageResult })[0],
JSONPath({ path: '$.args[0].args[0].args[1].args[0].int', json: storageResult })[0],
),
},
protocolSeizeShareMantissa: bigInt(protocolSeizeShareMantissa),
comptrollerAddress: JSONPath({ path: '$.args[0].args[0].args[2].string', json: storageResult })[0],
expScale: bigInt(JSONPath({ path: '$.args[0].args[0].args[3].int', json: storageResult })[0]),
halfExpScale: bigInt(JSONPath({ path: '$.args[0].args[0].args[4].int', json: storageResult })[0]),
comptrollerAddress: JSONPath({ path: '$.args[0].args[0].args[1].args[2].string', json: storageResult })[0],
expScale: bigInt(JSONPath({ path: '$.args[0].args[0].args[2].int', json: storageResult })[0]),
halfExpScale: bigInt(JSONPath({ path: '$.args[0].args[0].args[3].int', json: storageResult })[0]),
initialExchangeRateMantissa: bigInt(
JSONPath({ path: '$.args[0].args[1].args[0].args[0].int', json: storageResult })[0],
JSONPath({ path: '$.args[0].args[0].args[4].int', json: storageResult })[0],
),
interestRateModel: JSONPath({
path: '$.args[0].args[1].args[0].args[1].string',
path: '$.args[0].args[1].args[0].args[0].string',
json: storageResult,
})[0],
pendingAdministrator: pendingAdministrator,
Expand Down Expand Up @@ -748,13 +764,15 @@ export namespace FToken {
assetType: AssetType,
currentIndex: bigInt.BigInteger,
balancesMapId: number,
borrowsMapId: number,
server: string,
): Promise<Balance> {
try {
const balanceResult = await queryBalance(account, balancesMapId, server);
return parseBalanceResult(balanceResult, currentIndex, assetType);
const borrowResult = await queryBalance(account, borrowsMapId, server);
return parseBalanceResult(balanceResult, borrowResult, currentIndex, assetType);
} catch (e) {
return parseBalanceResult({}, currentIndex, assetType);
return parseBalanceResult({}, {},currentIndex, assetType);
}
}

Expand Down Expand Up @@ -802,12 +820,13 @@ export namespace FToken {
*/
export function parseBalanceResult(
balanceInfo: any,
borrowInfo:any,
currentIndex: bigInt.BigInteger,
assetType: AssetType,
): Balance {
const borrowIndex = JSONPath({ path: '$.args[0].args[0].int', json: balanceInfo })[0] || 0;
const borrowPrincipal = JSONPath({ path: '$.args[0].args[1].int', json: balanceInfo })[0] || 0;
const supplyPrincipal = JSONPath({ path: '$.args[2].int', json: balanceInfo })[0] || 0;
const borrowIndex = JSONPath({ path: '$.args[0].int', json: borrowInfo })[0] || 0;
const borrowPrincipal = JSONPath({ path: '$.args[1].int', json: borrowInfo })[0] || 0;
const supplyPrincipal = JSONPath({ path: '$.args[1].int', json: balanceInfo })[0] || 0;

// TODO: parse approvals
// return 0 balance if uninitialized in contract
Expand Down
1 change: 1 addition & 0 deletions src/util/src/TezosLendingPlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ export namespace TezosLendingPlatform {
asset as AssetType,
markets[asset].storage.borrow.borrowIndex,
markets[asset].storage.balancesMapId,
markets[asset].storage.borrowsMapId,
server,
);
console.log('cc2', asset, balances[asset]);
Expand Down