From 0da166316837a7fc27d773372e6a83ca7604e55a Mon Sep 17 00:00:00 2001 From: sakulstra Date: Wed, 24 Jul 2024 11:40:05 +0200 Subject: [PATCH] fix: transform to number first --- src/govv3/generatePayloadReport.spec.ts | 4 ++-- .../reserveConfigurationInterpreter.spec.ts | 24 +++++++++++++++++++ .../utils/reserveConfigurationInterpreter.ts | 4 ++-- 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 src/govv3/utils/reserveConfigurationInterpreter.spec.ts diff --git a/src/govv3/generatePayloadReport.spec.ts b/src/govv3/generatePayloadReport.spec.ts index 0db0892..0b5569d 100644 --- a/src/govv3/generatePayloadReport.spec.ts +++ b/src/govv3/generatePayloadReport.spec.ts @@ -55,7 +55,7 @@ describe('generatePayloadReport', () => { async () => { const report = await generateReport({ ...(MOCK_PAYLOAD as any), - client: CHAIN_ID_CLIENT_MAP[MOCK_PAYLOAD.simulation.transaction.network_id], + client: CHAIN_ID_CLIENT_MAP[Number(MOCK_PAYLOAD.simulation.transaction.network_id)], }); expect(report).toMatchSnapshot(); }, @@ -67,7 +67,7 @@ describe('generatePayloadReport', () => { async () => { const report = await generateReport({ ...(STREAM_PAYLOAD as any), - client: CHAIN_ID_CLIENT_MAP[MOCK_PAYLOAD.simulation.transaction.network_id], + client: CHAIN_ID_CLIENT_MAP[Number(MOCK_PAYLOAD.simulation.transaction.network_id)], }); expect(report).toMatchSnapshot(); }, diff --git a/src/govv3/utils/reserveConfigurationInterpreter.spec.ts b/src/govv3/utils/reserveConfigurationInterpreter.spec.ts new file mode 100644 index 0000000..69afd73 --- /dev/null +++ b/src/govv3/utils/reserveConfigurationInterpreter.spec.ts @@ -0,0 +1,24 @@ +// 7239967485535440384849065513280590734864674587685562855040293771882277901892 +import {CHAIN_ID_CLIENT_MAP} from '@bgd-labs/js-utils'; +import {describe, expect, it} from 'vitest'; +import {decodeReserveDataV3} from './reserveConfigurationInterpreter'; +import {toHex} from 'viem'; + +describe('reserveConfigurationInterpreter', () => { + it( + 'should detect a change in virtualBalanceActivated', + () => { + const decodedDataBefore = decodeReserveDataV3( + BigInt('2961908203178170875878950237596494035300546083027602574194771387707299396'), + ); + expect(decodedDataBefore.virtualAccountingEnabled).toBe(false); + + const decodedDataAfter = decodeReserveDataV3( + BigInt('7239967485535440384849065513280590734864674587685562855040293771882277901892'), + ); + expect(decodedDataAfter.virtualAccountingEnabled).toBe(true); + expect({...decodedDataBefore, virtualAccountingEnabled: true}).toEqual(decodedDataAfter); + }, + {timeout: 30000}, + ); +}); diff --git a/src/govv3/utils/reserveConfigurationInterpreter.ts b/src/govv3/utils/reserveConfigurationInterpreter.ts index 70685a2..74182d0 100644 --- a/src/govv3/utils/reserveConfigurationInterpreter.ts +++ b/src/govv3/utils/reserveConfigurationInterpreter.ts @@ -40,7 +40,7 @@ function decodeReserveDataV2(data: bigint) { }; } -function decodeReserveDataV3(data: bigint) { +export function decodeReserveDataV3(data: bigint) { const ltv = getBits(data, 0n, 15n); const liquidationThreshold = getBits(data, 16n, 31n); const liquidationBonus = getBits(data, 32n, 47n); @@ -60,7 +60,7 @@ function decodeReserveDataV3(data: bigint) { const eModeCategory = getBits(data, 168n, 175n); const unbackedMintCap = getBits(data, 176n, 211n); const debtCeiling = getBits(data, 212n, 251n); - const virtualAccountingEnabled = getBits(data, 252n, 252n); + const virtualAccountingEnabled = Number(getBits(data, 252n, 252n)); return { ltv,