Skip to content

Hotfix: fix ui fee receiver format #1778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion sdk/src/utils/__tests__/uiFeeReceiver.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isAddress } from "viem";
import { describe, it, expect } from "vitest";

import { createTwapUiFeeReceiver, decodeTwapUiFeeReceiver } from "utils/twap/uiFeeReceiver";
import { createTwapUiFeeReceiver, decodeTwapUiFeeReceiver, setUiFeeReceiverIsExpress } from "utils/twap/uiFeeReceiver";

describe("uiFeeReceiver", () => {
describe("decodeTwapUiFeeReceiver", () => {
Expand Down Expand Up @@ -64,3 +64,23 @@ describe("uiFeeReceiver", () => {
});
});
});

describe("setUiFeeReceiverIsExpress", () => {
it("should correctly set isExpress for simple uiFeeReceiver", () => {
expect(setUiFeeReceiverIsExpress("0xff00000000000000000000000000000000000001", true)).toEqual(
"0xff00000000000000000000000000000100000001"
);
expect(setUiFeeReceiverIsExpress("0xff00000000000000000000000000000000000001", false)).toEqual(
"0xff00000000000000000000000000000000000001"
);
});

it("should correctly set isExpress for twap uiFeeReceiver", () => {
expect(setUiFeeReceiverIsExpress("0xff0000000000000000000000000000000a123401", true)).toEqual(
"0xff0000000000000000000000000000010a123401"
);
expect(setUiFeeReceiverIsExpress("0xff0000000000000000000000000000000a123401", false)).toEqual(
"0xff0000000000000000000000000000000a123401"
);
});
});
19 changes: 9 additions & 10 deletions sdk/src/utils/twap/uiFeeReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ const PREFIX = "0xff0000";

/**
* Ui fee receiver structure:
* 0..3 bytes (0..7 chars) - PREFIX
* 4..16 bytes (8..27 chars) - 12 bytes buffer
* 17 byte (27..29 chars) - isExpress flag
* 18 byte (30..32 chars) - numberOfParts (hex encoded)
* 19..20 bytes (34..38 chars) - twapId
* 20 byte (38..40 chars) - VERSION
* 0-3 (4) bytes (0-7 chars) - PREFIX
* 4-15 (12) bytes (8-32 chars) - 12 bytes buffer
* 16 (1) byte (33-34 chars) - isExpress flag
* 17 (1) byte (35-36 chars) - numberOfParts (hex encoded)
* 18-19 (2) bytes (37-40 chars) - twapId
* 20 (1) byte (41-42 chars) - VERSION
*
* Total: 20 bytes (40 hex characters)
* Total: 0x + 20 bytes (41 hex characters)
*/

export function generateTwapId() {
return Math.floor(Math.random() * 256 * 256)
.toString(16)
Expand All @@ -25,9 +24,9 @@ export function createTwapUiFeeReceiver({ numberOfParts }: { numberOfParts: numb
const twapId = generateTwapId();

const numberOfPartsInHex = numberOfParts.toString(16).padStart(2, "0");
const isExpressHex = "00";

const buffer = "00".repeat(12);
const isExpressHex = "00";

return `${PREFIX}${buffer}${isExpressHex}${numberOfPartsInHex}${twapId}${VERSION}`;
}
Expand Down Expand Up @@ -55,5 +54,5 @@ export function isValidTwapUiFeeReceiver(address: string) {
export function setUiFeeReceiverIsExpress(uiFeeReceiver: string, isExpress: boolean): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add test for this function

const isExpressInHex = isExpress ? "01" : "00";

return `${uiFeeReceiver.slice(0, 27)}${isExpressInHex}${uiFeeReceiver.slice(29)}`;
return `${uiFeeReceiver.slice(0, 16 * 2)}${isExpressInHex}${uiFeeReceiver.slice(17 * 2)}`;
}
5 changes: 4 additions & 1 deletion src/context/SyntheticsEvents/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { OrderMetricId, sendTxnErrorMetric } from "lib/metrics";

import type {

Check warning on line 3 in src/context/SyntheticsEvents/utils.ts

View workflow job for this annotation

GitHub Actions / Run Tests

There should be at least one empty line between import groups

Check warning on line 3 in src/context/SyntheticsEvents/utils.ts

View workflow job for this annotation

GitHub Actions / Run Tests

There should be at least one empty line between import groups
GelatoTaskStatus,
PendingDepositData,
PendingOrderData,
PendingShiftData,
PendingWithdrawalData,
} from "./types";
import { extendError } from "lib/errors";

Check warning on line 10 in src/context/SyntheticsEvents/utils.ts

View workflow job for this annotation

GitHub Actions / Run Tests

`lib/errors` import should occur before import of `lib/metrics`

Check warning on line 10 in src/context/SyntheticsEvents/utils.ts

View workflow job for this annotation

GitHub Actions / Run Tests

`lib/errors` import should occur before import of `lib/metrics`

export function getPendingOrderKey(
data: Omit<PendingOrderData, "txnType" | "triggerPrice" | "acceptablePrice" | "autoCancel">
Expand Down Expand Up @@ -89,7 +90,9 @@

if (bytecodeMatch) {
const bytecode = bytecodeMatch[0];
const error = new Error(`data="${bytecode}"`);
const error = extendError(new Error(`data="${bytecode}"`), {
data: { taskId: gelatoTaskStatus.taskId },
});
sendTxnErrorMetric(metricId, error, "relayer");
return;
}
Expand Down