Skip to content

Commit 790c7b9

Browse files
authored
feat: integratorId check (#33)
1 parent eded2f7 commit 790c7b9

File tree

9 files changed

+47
-16
lines changed

9 files changed

+47
-16
lines changed

.changeset/grumpy-swans-judge.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@across-protocol/integrator-sdk": patch
3+
---
4+
5+
stricter integrator id check

apps/example/app/ethers/components/Bridge.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const chains = [mainnet, arbitrum];
1717
const sdk = AcrossClient.create({
1818
chains,
1919
useTestnet: false,
20-
integratorId: "TEST",
2120
logLevel: "DEBUG",
2221
});
2322

apps/example/lib/across.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export const SUPPORTED_CHAINS = MAINNET_SUPPORTED_CHAINS;
99
const sdk = AcrossClient.create({
1010
chains: [...SUPPORTED_CHAINS],
1111
useTestnet: false,
12-
integratorId: "TEST",
1312
logLevel: "DEBUG",
1413
});
1514

apps/example/scripts/sdk.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ async function main() {
4646
const client = AcrossClient.create({
4747
chains,
4848
useTestnet: false,
49-
integratorId: "TEST",
5049
logLevel: "DEBUG",
5150
walletClient,
5251
tenderly: {

packages/sdk/src/actions/executeQuote.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
Address,
33
Hash,
4+
Hex,
45
parseAbi,
56
SimulateContractReturnType,
67
TransactionReceipt,
@@ -112,7 +113,7 @@ export type ExecuteQuoteParams = {
112113
/**
113114
* An identifier for the integrator.
114115
*/
115-
integratorId: string;
116+
integratorId: Hex;
116117
/**
117118
* The deposit to execute. Should be taken from return value of {@link getQuote}.
118119
*/

packages/sdk/src/actions/simulateDepositTx.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
Hex,
23
PublicClient,
34
SimulateContractReturnType,
45
WalletClient,
@@ -18,7 +19,7 @@ export type SimulateDepositTxParams = {
1819
deposit: Quote["deposit"] & {
1920
fillDeadline?: number;
2021
};
21-
integratorId: string;
22+
integratorId: Hex;
2223
logger?: LoggerT;
2324
};
2425

packages/sdk/src/client.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
Chain,
33
ContractFunctionExecutionError,
44
encodeFunctionData,
5+
Hex,
56
} from "viem";
67
import {
78
getAvailableRoutes,
@@ -43,6 +44,7 @@ import {
4344
getSupportedChains,
4445
simulateTxOnTenderly,
4546
TenderlySimulateTxParams,
47+
assertValidIntegratorId,
4648
} from "./utils";
4749
import {
4850
AcrossApiSimulationError,
@@ -53,12 +55,11 @@ import {
5355
ConfiguredPublicClient,
5456
ConfiguredPublicClientMap,
5557
ConfiguredWalletClient,
56-
Deposit,
5758
} from "./types";
5859

5960
const CLIENT_DEFAULTS = {
6061
pollingInterval: 3_000,
61-
integratorId: "INTEGRATOR_SDK",
62+
integratorId: "0xdead",
6263
logLevel: "ERROR",
6364
} as const;
6465

@@ -67,7 +68,7 @@ export type AcrossClientOptions = {
6768
/**
6869
* An identifier representing the integrator.
6970
*/
70-
integratorId?: string;
71+
integratorId?: Hex;
7172
/**
7273
* The chains to use for the Across API. Should be imported from `viem/chains`.
7374
*/
@@ -135,7 +136,7 @@ export type AcrossClientOptions = {
135136
export class AcrossClient {
136137
private static instance: AcrossClient | null = null;
137138

138-
private integratorId: string;
139+
private integratorId: Hex;
139140
private publicClients: ConfiguredPublicClientMap;
140141
private walletClient?: ConfiguredWalletClient;
141142
private apiUrl: string;
@@ -159,7 +160,10 @@ export class AcrossClient {
159160
}
160161

161162
private constructor(args: AcrossClientOptions) {
162-
this.integratorId = args?.integratorId ?? CLIENT_DEFAULTS.integratorId;
163+
const integratorId = args?.integratorId ?? CLIENT_DEFAULTS.integratorId;
164+
assertValidIntegratorId(integratorId);
165+
166+
this.integratorId = integratorId;
163167
this.walletClient = args?.walletClient;
164168
this.publicClients = configurePublicClients(
165169
args.chains,

packages/sdk/src/utils/hex.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
1-
import { concat, Hex, toHex } from "viem";
1+
import { concat, Hex, isHex } from "viem";
22

33
export const DOMAIN_CALLDATA_DELIMITER = "0x1dc0de";
44

5-
export function tagIntegratorId(integratorId: string, txData: Hex) {
6-
return concat([txData, DOMAIN_CALLDATA_DELIMITER, toHex(integratorId)]);
5+
export function tagIntegratorId(integratorId: Hex, txData: Hex) {
6+
assertValidIntegratorId(integratorId);
7+
8+
return concat([txData, DOMAIN_CALLDATA_DELIMITER, integratorId]);
9+
}
10+
11+
export function getIntegratorDataSuffix(integratorId: Hex) {
12+
assertValidIntegratorId(integratorId);
13+
14+
return concat([DOMAIN_CALLDATA_DELIMITER, integratorId]);
715
}
816

9-
export function getIntegratorDataSuffix(integratorId: string) {
10-
return concat([DOMAIN_CALLDATA_DELIMITER, toHex(integratorId)]);
17+
export function isValidIntegratorId(integratorId: string) {
18+
return (
19+
isHex(integratorId) &&
20+
// "0x" + 2 bytes = 6 hex characters
21+
integratorId.length === 6
22+
);
23+
}
24+
25+
export function assertValidIntegratorId(
26+
integratorId: string,
27+
): integratorId is Hex {
28+
if (!isValidIntegratorId(integratorId)) {
29+
throw new Error(
30+
`Invalid integrator ID: ${integratorId}. Needs to be 2 bytes hex string.`,
31+
);
32+
}
33+
34+
return true;
1135
}

packages/sdk/test/utils/logger.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { hardhat } from "viem/chains";
44

55
const client = AcrossClient.create({
66
useTestnet: true,
7-
integratorId: "TEST_ID",
87
logLevel: "WARN",
98
chains: [hardhat],
109
});

0 commit comments

Comments
 (0)