Skip to content

Commit

Permalink
Kamino sdk small fixes (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
alittlezz authored Oct 16, 2023
1 parent 1012375 commit 1e11aec
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/kamino-sdk/src/rebalance_methods/driftRebalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export function readDriftRebalanceParamsFromStrategy(rebalanceRaw: RebalanceRaw)
params['startMidTick'] = new Decimal(paramsBuffer.readInt32LE(0));
params['ticksBelowMid'] = new Decimal(paramsBuffer.readInt32LE(4));
params['ticksAboveMid'] = new Decimal(paramsBuffer.readInt32LE(8));
params['secondsPerTick'] = new Decimal(paramsBuffer.readBigUint64LE(12).toString());
params['secondsPerTick'] = new Decimal(paramsBuffer.readBigUInt64LE(12).toString());
params['direction'] = new Decimal(paramsBuffer.readUint8(20));

return params;
Expand All @@ -172,7 +172,7 @@ export function readRawDriftRebalanceStateFromStrategy(rebalanceRaw: RebalanceRa
let state: RebalanceFieldsDict = {};

state['step'] = new Decimal(stateBuffer.readUInt8(0));
state['lastDriftTimestamp'] = new Decimal(stateBuffer.readBigUint64LE(1).toString());
state['lastDriftTimestamp'] = new Decimal(stateBuffer.readBigUInt64LE(1).toString());
state['lastMidTick'] = new Decimal(stateBuffer.readInt32LE(9));

return state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function readPeriodicRebalanceRebalanceParamsFromStrategy(rebalanceRaw: R
let paramsBuffer = Buffer.from(rebalanceRaw.params);
let params: RebalanceFieldsDict = {};

params['period'] = new Decimal(paramsBuffer.readBigUint64LE(0).toString());
params['period'] = new Decimal(paramsBuffer.readBigUInt64LE(0).toString());
params['lowerRangeBps'] = new Decimal(paramsBuffer.readUInt16LE(8));
params['upperRangeBps'] = new Decimal(paramsBuffer.readUInt16LE(10));

Expand All @@ -100,7 +100,7 @@ export function readPeriodicRebalanceRebalanceStateFromStrategy(rebalanceRaw: Re
let stateBuffer = Buffer.from(rebalanceRaw.state);
let state: RebalanceFieldsDict = {};

state['lastRebalanceTimestamp'] = new Decimal(stateBuffer.readBigUint64LE(0).toString());
state['lastRebalanceTimestamp'] = new Decimal(stateBuffer.readBigUInt64LE(0).toString());

return state;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ export function readPricePercentageRebalanceStateFromStrategy(
): RebalanceFieldInfo[] {
let stateBuffer = Buffer.from(rebalanceRaw.state);

let lowerSqrtPriceX64 = new Decimal(readBigUint128LE(stateBuffer, 0).toString());
let upperSqrtPriceX64 = new Decimal(readBigUint128LE(stateBuffer, 16).toString());
let lowerSqrtPriceX64 = readBigUint128LE(stateBuffer, 0).toString();
let upperSqrtPriceX64 = readBigUint128LE(stateBuffer, 16).toString();
let lowerPrice: Decimal, upperPrice: Decimal;

if (dex == 'ORCA') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ export function readPricePercentageWithResetRebalanceStateFromStrategy(
let resetLowerRangeBps = new Decimal(params.find((param) => param.label == 'resetLowerRangeBps')?.value.toString()!);
let resetUpperRangeBps = new Decimal(params.find((param) => param.label == 'resetUpperRangeBps')?.value!.toString()!);

let lowerResetSqrtPriceX64 = new Decimal(readBigUint128LE(stateBuffer, 0).toString());
let upperResetSqrtPriceX64 = new Decimal(readBigUint128LE(stateBuffer, 16).toString());
let lowerResetSqrtPriceX64 = readBigUint128LE(stateBuffer, 0).toString();
let upperResetSqrtPriceX64 = readBigUint128LE(stateBuffer, 16).toString();

let lowerResetPrice: Decimal, upperResetPrice: Decimal;

Expand Down
2 changes: 1 addition & 1 deletion packages/kamino-sdk/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export function lamportsToNumberDecimal(amount: Decimal.Value, decimals: number)
}

export function readBigUint128LE(buffer: Buffer, offset: number): bigint {
return buffer.readBigUint64LE(offset) + (buffer.readBigUint64LE(offset + 8) << BigInt(64));
return buffer.readBigUInt64LE(offset) + (buffer.readBigUInt64LE(offset + 8) << BigInt(64));
}

function writeBNUint64LE(buffer: Buffer, value: BN, offset: number) {
Expand Down

0 comments on commit 1e11aec

Please sign in to comment.