Skip to content

Commit

Permalink
refactor: use length to decode relativeBlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhwu committed Sep 19, 2024
1 parent 361f559 commit 0ca5a19
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions sdks/uniswapx-sdk/src/order/V3DutchOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ function parseSerializedOrder(serialized: string): CosignedV3DutchOrderInfo {
token,
startAmount,
curve: {
relativeBlocks: decodeRelativeBlocks(inputRelativeBlocks),
relativeBlocks: decodeRelativeBlocks(inputRelativeBlocks, relativeAmounts.length),
relativeAmounts: relativeAmounts.map((amount: BigNumber) => amount.toBigInt()),
},
maxAmount,
Expand All @@ -546,7 +546,7 @@ function parseSerializedOrder(serialized: string): CosignedV3DutchOrderInfo {
token,
startAmount,
curve: {
relativeBlocks: decodeRelativeBlocks(outputRelativeBlocks),
relativeBlocks: decodeRelativeBlocks(outputRelativeBlocks, relativeAmounts.length),
relativeAmounts: relativeAmounts.map((amount: BigNumber) => amount.toBigInt()),
},
recipient,
Expand All @@ -571,13 +571,11 @@ function encodeRelativeBlocks(relativeBlocks: number[]): BigNumber {
return packedData;
}

function decodeRelativeBlocks(packedData: BigNumber): number[] {
function decodeRelativeBlocks(packedData: BigNumber, relativeAmountsLength: number): number[] {
const relativeBlocks: number[] = [];
for (let i = 0; i < 16; i++) {
for (let i = 0; i < relativeAmountsLength; i++) {
const block = packedData.shr(i * 16).toNumber() & 0xFFFF;
if (block !== 0) {
relativeBlocks.push(block);
}
relativeBlocks.push(block);
}
return relativeBlocks;
}

0 comments on commit 0ca5a19

Please sign in to comment.