Skip to content

Commit ef0ef80

Browse files
feat: parsing update for v3
1 parent 1c7a5bf commit ef0ef80

2 files changed

Lines changed: 56 additions & 36 deletions

File tree

src/util/src/FToken.ts

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export namespace FToken {
3131
accrualBlockNumber: number;
3232
administrator: string;
3333
balancesMapId: number;
34+
borrowsMapId: number;
3435
supply: {
3536
numSuppliers?: number;
3637
totalSupply: bigInt.BigInteger;
@@ -72,7 +73,11 @@ export namespace FToken {
7273
case TokenStandard.FA12: {
7374
const storageResult = await TezosNodeReader.getContractStorage(server, fTokenAddress);
7475
const balancesMapId = JSONPath({
75-
path: '$.args[0].args[0].args[0].args[2].int',
76+
path: '$.args[0].args[1].args[0].args[2].int',
77+
json: storageResult,
78+
})[0];
79+
const borrowsMapId = JSONPath({
80+
path: '$.args[0].args[0].args[1].args[0].int',
7681
json: storageResult,
7782
})[0];
7883
const adminJsonPrase = JSONPath({ path: '$.args[0].args[1].args[2].prim', json: storageResult })[0];
@@ -93,41 +98,42 @@ export namespace FToken {
9398
json: storageResult,
9499
})[0],
95100
administrator: JSONPath({
96-
path: '$.args[0].args[0].args[0].args[1].string',
101+
path: '$.args[0].args[0].args[0].args[0].args[2].string',
97102
json: storageResult,
98103
})[0],
99104
balancesMapId: balancesMapId,
105+
borrowsMapId: borrowsMapId,
100106
supply: {
101107
totalSupply: bigInt(JSONPath({ path: '$.args[0].args[5].int', json: storageResult })[0]),
102108
supplyRatePerBlock: bigInt(
103109
JSONPath({ path: '$.args[0].args[2].args[2].int', json: storageResult })[0],
104110
),
105111
},
106112
borrow: {
107-
totalBorrows: bigInt(JSONPath({ path: '$.args[0].args[3].int', json: storageResult })[0]),
113+
totalBorrows: bigInt(JSONPath({ path: '$.args[0].args[3].args[1].int', json: storageResult })[0]),
108114
borrowIndex: bigInt(
109-
JSONPath({ path: '$.args[0].args[0].args[0].args[3].int', json: storageResult })[0],
115+
JSONPath({ path: '$.args[0].args[0].args[0].args[1].int', json: storageResult })[0],
110116
),
111117
borrowRateMaxMantissa: bigInt(
112-
JSONPath({ path: '$.args[0].args[0].args[1].args[0].int', json: storageResult })[0],
118+
JSONPath({ path: '$.args[0].args[0].args[0].args[2].int', json: storageResult })[0],
113119
),
114120
borrowRatePerBlock: bigInt(
115-
JSONPath({ path: '$.args[0].args[0].args[1].args[1].int', json: storageResult })[0],
121+
JSONPath({ path: '$.args[0].args[0].args[0].args[3].int', json: storageResult })[0],
116122
),
117123
},
118124
protocolSeizeShareMantissa: bigInt(protocolSeizeShareMantissa),
119125
comptrollerAddress: JSONPath({
120-
path: '$.args[0].args[0].args[1].args[2].string',
126+
path: '$.args[0].args[0].args[1].args[1].string',
121127
json: storageResult,
122128
})[0],
123-
expScale: bigInt(JSONPath({ path: '$.args[0].args[0].args[3].int', json: storageResult })[0]),
129+
expScale: bigInt(JSONPath({ path: '$.args[0].args[0].args[2].int', json: storageResult })[0]),
124130
halfExpScale: bigInt(
125-
JSONPath({ path: '$.args[0].args[1].args[0].args[0].int', json: storageResult })[0],
131+
JSONPath({ path: '$.args[0].args[0].args[4].int', json: storageResult })[0],
126132
),
127133
initialExchangeRateMantissa: bigInt(
128-
JSONPath({ path: '$.args[0].args[1].args[0].args[1].int', json: storageResult })[0],
134+
JSONPath({ path: '$.args[0].args[1].args[0].args[0].int', json: storageResult })[0],
129135
),
130-
interestRateModel: JSONPath({ path: '$.args[0].args[1].args[1].string', json: storageResult })[0],
136+
interestRateModel: JSONPath({ path: '$.args[0].args[1].args[0].args[1].string', json: storageResult })[0],
131137
pendingAdministrator: pendingAdministrator,
132138
reserveFactorMantissa: bigInt(
133139
JSONPath({ path: '$.args[0].args[2].args[0].int', json: storageResult })[0],
@@ -142,7 +148,11 @@ export namespace FToken {
142148
case TokenStandard.FA2: {
143149
const storageResult = await TezosNodeReader.getContractStorage(server, fTokenAddress);
144150
const balancesMapId = JSONPath({
145-
path: '$.args[0].args[0].args[0].args[2].int',
151+
path: '$.args[0].args[1].args[0].args[1].int',
152+
json: storageResult,
153+
})[0];
154+
const borrowsMapId = JSONPath({
155+
path: '$.args[0].args[0].args[1].args[0].int',
146156
json: storageResult,
147157
})[0];
148158
const adminJsonPrase = JSONPath({ path: '$.args[0].args[1].args[1].prim', json: storageResult })[0];
@@ -163,42 +173,43 @@ export namespace FToken {
163173
json: storageResult,
164174
})[0],
165175
administrator: JSONPath({
166-
path: '$.args[0].args[0].args[0].args[1].string',
176+
path: '$.args[0].args[0].args[0].args[0].args[2].string',
167177
json: storageResult,
168178
})[0],
169179
balancesMapId: balancesMapId,
180+
borrowsMapId: borrowsMapId,
170181
supply: {
171182
totalSupply: bigInt(JSONPath({ path: '$.args[0].args[5].int', json: storageResult })[0]),
172183
supplyRatePerBlock: bigInt(
173184
JSONPath({ path: '$.args[0].args[2].args[1].int', json: storageResult })[0],
174185
),
175186
},
176187
borrow: {
177-
totalBorrows: bigInt(JSONPath({ path: '$.args[0].args[3].int', json: storageResult })[0]),
188+
totalBorrows: bigInt(JSONPath({ path: '$.args[0].args[3].args[1].int', json: storageResult })[0]),
178189
borrowIndex: bigInt(
179-
JSONPath({ path: '$.args[0].args[0].args[0].args[3].int', json: storageResult })[0],
190+
JSONPath({ path: '$.args[0].args[0].args[0].args[1].int', json: storageResult })[0],
180191
),
181192
borrowRateMaxMantissa: bigInt(
182-
JSONPath({ path: '$.args[0].args[0].args[1].args[0].int', json: storageResult })[0],
193+
JSONPath({ path: '$.args[0].args[0].args[0].args[2].int', json: storageResult })[0],
183194
),
184195
borrowRatePerBlock: bigInt(
185-
JSONPath({ path: '$.args[0].args[0].args[1].args[1].int', json: storageResult })[0],
196+
JSONPath({ path: '$.args[0].args[0].args[0].args[3].int', json: storageResult })[0],
186197
),
187198
},
188199
protocolSeizeShareMantissa: bigInt(protocolSeizeShareMantissa),
189200
comptrollerAddress: JSONPath({
190-
path: '$.args[0].args[0].args[1].args[2].string',
201+
path: '$.args[0].args[0].args[1].args[1].string',
191202
json: storageResult,
192203
})[0],
193-
expScale: bigInt(JSONPath({ path: '$.args[0].args[0].args[3].int', json: storageResult })[0]),
204+
expScale: bigInt(JSONPath({ path: '$.args[0].args[0].args[2].args[0].int', json: storageResult })[0]),
194205
halfExpScale: bigInt(
195-
JSONPath({ path: '$.args[0].args[1].args[0].args[0].int', json: storageResult })[0],
206+
JSONPath({ path: '$.args[0].args[0].args[3].int', json: storageResult })[0],
196207
),
197208
initialExchangeRateMantissa: bigInt(
198-
JSONPath({ path: '$.args[0].args[1].args[0].args[1].int', json: storageResult })[0],
209+
JSONPath({ path: '$.args[0].args[0].args[4].int', json: storageResult })[0],
199210
),
200211
interestRateModel: JSONPath({
201-
path: '$.args[0].args[1].args[0].args[2].string',
212+
path: '$.args[0].args[1].args[0].args[0].string',
202213
json: storageResult,
203214
})[0],
204215
pendingAdministrator: pendingAdministrator,
@@ -215,7 +226,11 @@ export namespace FToken {
215226
case TokenStandard.XTZ: {
216227
const storageResult = await TezosNodeReader.getContractStorage(server, fTokenAddress);
217228
const balancesMapId = JSONPath({
218-
path: '$.args[0].args[0].args[0].args[2].int',
229+
path: '$.args[0].args[1].args[0].args[1].int',
230+
json: storageResult,
231+
})[0];
232+
const borrowsMapId = JSONPath({
233+
path: '$.args[0].args[0].args[1].args[1].int',
219234
json: storageResult,
220235
})[0];
221236
const adminJsonPrase = JSONPath({ path: '$.args[0].args[1].args[1].prim', json: storageResult })[0];
@@ -241,6 +256,7 @@ export namespace FToken {
241256
json: storageResult,
242257
})[0],
243258
balancesMapId: balancesMapId,
259+
borrowsMapId: borrowsMapId,
244260
supply: {
245261
totalSupply: bigInt(JSONPath({ path: '$.args[0].args[5].int', json: storageResult })[0]),
246262
supplyRatePerBlock: bigInt(
@@ -250,24 +266,24 @@ export namespace FToken {
250266
borrow: {
251267
totalBorrows: bigInt(JSONPath({ path: '$.args[0].args[3].int', json: storageResult })[0]),
252268
borrowIndex: bigInt(
253-
JSONPath({ path: '$.args[0].args[0].args[0].args[3].int', json: storageResult })[0],
269+
JSONPath({ path: '$.args[0].args[0].args[0].args[2].int', json: storageResult })[0],
254270
),
255271
borrowRateMaxMantissa: bigInt(
256-
JSONPath({ path: '$.args[0].args[0].args[1].args[0].int', json: storageResult })[0],
272+
JSONPath({ path: '$.args[0].args[0].args[0].args[3].int', json: storageResult })[0],
257273
),
258274
borrowRatePerBlock: bigInt(
259-
JSONPath({ path: '$.args[0].args[0].args[1].args[1].int', json: storageResult })[0],
275+
JSONPath({ path: '$.args[0].args[0].args[1].args[0].int', json: storageResult })[0],
260276
),
261277
},
262278
protocolSeizeShareMantissa: bigInt(protocolSeizeShareMantissa),
263-
comptrollerAddress: JSONPath({ path: '$.args[0].args[0].args[2].string', json: storageResult })[0],
264-
expScale: bigInt(JSONPath({ path: '$.args[0].args[0].args[3].int', json: storageResult })[0]),
265-
halfExpScale: bigInt(JSONPath({ path: '$.args[0].args[0].args[4].int', json: storageResult })[0]),
279+
comptrollerAddress: JSONPath({ path: '$.args[0].args[0].args[1].args[2].string', json: storageResult })[0],
280+
expScale: bigInt(JSONPath({ path: '$.args[0].args[0].args[2].int', json: storageResult })[0]),
281+
halfExpScale: bigInt(JSONPath({ path: '$.args[0].args[0].args[3].int', json: storageResult })[0]),
266282
initialExchangeRateMantissa: bigInt(
267-
JSONPath({ path: '$.args[0].args[1].args[0].args[0].int', json: storageResult })[0],
283+
JSONPath({ path: '$.args[0].args[0].args[4].int', json: storageResult })[0],
268284
),
269285
interestRateModel: JSONPath({
270-
path: '$.args[0].args[1].args[0].args[1].string',
286+
path: '$.args[0].args[1].args[0].args[0].string',
271287
json: storageResult,
272288
})[0],
273289
pendingAdministrator: pendingAdministrator,
@@ -748,13 +764,15 @@ export namespace FToken {
748764
assetType: AssetType,
749765
currentIndex: bigInt.BigInteger,
750766
balancesMapId: number,
767+
borrowsMapId: number,
751768
server: string,
752769
): Promise<Balance> {
753770
try {
754771
const balanceResult = await queryBalance(account, balancesMapId, server);
755-
return parseBalanceResult(balanceResult, currentIndex, assetType);
772+
const borrowResult = await queryBalance(account, borrowsMapId, server);
773+
return parseBalanceResult(balanceResult, borrowResult, currentIndex, assetType);
756774
} catch (e) {
757-
return parseBalanceResult({}, currentIndex, assetType);
775+
return parseBalanceResult({}, {},currentIndex, assetType);
758776
}
759777
}
760778

@@ -802,12 +820,13 @@ export namespace FToken {
802820
*/
803821
export function parseBalanceResult(
804822
balanceInfo: any,
823+
borrowInfo:any,
805824
currentIndex: bigInt.BigInteger,
806825
assetType: AssetType,
807826
): Balance {
808-
const borrowIndex = JSONPath({ path: '$.args[0].args[0].int', json: balanceInfo })[0] || 0;
809-
const borrowPrincipal = JSONPath({ path: '$.args[0].args[1].int', json: balanceInfo })[0] || 0;
810-
const supplyPrincipal = JSONPath({ path: '$.args[2].int', json: balanceInfo })[0] || 0;
827+
const borrowIndex = JSONPath({ path: '$.args[0].int', json: borrowInfo })[0] || 0;
828+
const borrowPrincipal = JSONPath({ path: '$.args[1].int', json: borrowInfo })[0] || 0;
829+
const supplyPrincipal = JSONPath({ path: '$.args[1].int', json: balanceInfo })[0] || 0;
811830

812831
// TODO: parse approvals
813832
// return 0 balance if uninitialized in contract

src/util/src/TezosLendingPlatform.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ export namespace TezosLendingPlatform {
274274
asset as AssetType,
275275
markets[asset].storage.borrow.borrowIndex,
276276
markets[asset].storage.balancesMapId,
277+
markets[asset].storage.borrowsMapId,
277278
server,
278279
);
279280
console.log('cc2', asset, balances[asset]);

0 commit comments

Comments
 (0)