Skip to content

Commit

Permalink
fix: transform to number first
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Jul 24, 2024
1 parent c0961ac commit 0da1663
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/govv3/generatePayloadReport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
Expand All @@ -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();
},
Expand Down
24 changes: 24 additions & 0 deletions src/govv3/utils/reserveConfigurationInterpreter.spec.ts
Original file line number Diff line number Diff line change
@@ -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},
);
});
4 changes: 2 additions & 2 deletions src/govv3/utils/reserveConfigurationInterpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down

0 comments on commit 0da1663

Please sign in to comment.