Skip to content

Commit b764aec

Browse files
authored
depositId as uint256 in speedup typed data (#179)
* depositId as uint256 in speedup typed data * add changeset * fix * impersonate exclusive relayer in tests * fix
1 parent cc40c74 commit b764aec

File tree

6 files changed

+75
-13
lines changed

6 files changed

+75
-13
lines changed

.changeset/funny-toys-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@across-protocol/app-sdk": patch
3+
---
4+
5+
Fix for speed up typed data

packages/sdk/src/actions/signUpdateDeposit.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { Address, Hex, WalletClient } from "viem";
2-
import { getUpdateDepositTypedDataV3_5 } from "../utils/index.js";
2+
import {
3+
getUpdateDepositTypedData,
4+
getUpdateDepositTypedDataV3_5,
5+
} from "../utils/index.js";
36

47
export type SignUpdateDepositTypedDataParams = {
58
walletClient: WalletClient;
@@ -35,6 +38,45 @@ export async function signUpdateDepositTypedData(
3538
throw new Error("Wallet account has to be set");
3639
}
3740

41+
const signature = await walletClient.signTypedData(
42+
getUpdateDepositTypedData({
43+
signerAddress: account.address,
44+
originChainId,
45+
depositId,
46+
updatedMessage,
47+
updatedOutputAmount,
48+
updatedRecipient,
49+
}),
50+
);
51+
52+
return signature;
53+
}
54+
55+
/**
56+
* Creates a signature that allows signer to update a deposit. Can be used with
57+
* `SpokePool` contract's `speedUpDeposit` method. Is used internally by
58+
* {@link simulateUpdateDepositTx}
59+
* @param params See {@link SignUpdateDepositTypedDataParams}
60+
* @returns Hex-encoded signature
61+
*/
62+
export async function signUpdateDepositTypedDataV3_5(
63+
params: SignUpdateDepositTypedDataParams,
64+
) {
65+
const {
66+
walletClient,
67+
depositId,
68+
originChainId,
69+
updatedMessage,
70+
updatedOutputAmount,
71+
updatedRecipient,
72+
} = params;
73+
74+
const account = walletClient.account;
75+
76+
if (!account) {
77+
throw new Error("Wallet account has to be set");
78+
}
79+
3880
const signature = await walletClient.signTypedData(
3981
getUpdateDepositTypedDataV3_5({
4082
signerAddress: account.address,

packages/sdk/src/utils/typedData.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { Address, Hex } from "viem";
22
import { addressToBytes32 } from "./hex.js";
33

4-
/**
5-
* @deprecated Use `getUpdateDepositTypedDataV3_5` instead.
6-
*/
74
export function getUpdateDepositTypedData({
85
signerAddress,
96
originChainId,
@@ -13,7 +10,7 @@ export function getUpdateDepositTypedData({
1310
updatedRecipient,
1411
}: {
1512
signerAddress: Address;
16-
originChainId: number;
13+
originChainId: bigint | number;
1714
depositId: bigint | number;
1815
updatedOutputAmount: bigint;
1916
updatedRecipient: Address;
@@ -24,11 +21,11 @@ export function getUpdateDepositTypedData({
2421
domain: {
2522
name: "ACROSS-V2",
2623
version: "1.0.0",
27-
chainId: originChainId,
24+
chainId: Number(originChainId),
2825
},
2926
types: {
3027
UpdateDepositDetails: [
31-
{ name: "depositId", type: "uint32" },
28+
{ name: "depositId", type: "uint256" },
3229
{ name: "originChainId", type: "uint256" },
3330
{ name: "updatedOutputAmount", type: "uint256" },
3431
{ name: "updatedRecipient", type: "address" },
@@ -37,7 +34,7 @@ export function getUpdateDepositTypedData({
3734
},
3835
primaryType: "UpdateDepositDetails",
3936
message: {
40-
depositId: Number(depositId),
37+
depositId: BigInt(depositId),
4138
originChainId: BigInt(originChainId),
4239
updatedOutputAmount,
4340
updatedRecipient,

packages/sdk/test/common/relayer.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Address, TransactionReceipt } from "viem";
1+
import { type Address, type TransactionReceipt } from "viem";
22
import {
33
getDepositFromLogs,
44
type AcrossClient,
@@ -7,6 +7,7 @@ import {
77
import type { ChainClient } from "./anvil.js";
88
import { spokePoolAbiV3 } from "../../src/abis/SpokePool/index.js";
99
import { spokePoolAbiV3_5 } from "../../dist/abis/SpokePool/v3_5.js";
10+
import { isAddressDefined } from "./utils.js";
1011

1112
type RelayerParams = {
1213
depositReceipt: TransactionReceipt;
@@ -15,6 +16,7 @@ type RelayerParams = {
1516
destinationPublicClient: ConfiguredPublicClient;
1617
chainClient: ChainClient;
1718
spokePoolAddress?: Address;
19+
exclusiveRelayer?: Address;
1820
};
1921

2022
// ACROSS RELAYER MOCK
@@ -26,11 +28,18 @@ export async function waitForDepositAndFillV3_5({
2628
destinationPublicClient,
2729
chainClient,
2830
spokePoolAddress,
31+
exclusiveRelayer,
2932
}: RelayerParams) {
3033
const destinationSpokepoolAddress =
3134
spokePoolAddress ??
3235
(await acrossClient.getSpokePoolAddress(destinationPublicClient.chain.id));
3336

37+
if (isAddressDefined(exclusiveRelayer)) {
38+
await chainClient.impersonateAccount({
39+
address: exclusiveRelayer,
40+
});
41+
}
42+
3443
const deposit = getDepositFromLogs({
3544
originChainId: originPublicClient.chain.id,
3645
receipt: depositReceipt,
@@ -52,7 +61,9 @@ export async function waitForDepositAndFillV3_5({
5261
},
5362
BigInt(destinationPublicClient.chain.id),
5463
],
55-
account: chainClient.account.address,
64+
account: isAddressDefined(exclusiveRelayer)
65+
? exclusiveRelayer
66+
: chainClient.account.address,
5667
});
5768

5869
return await chainClient.writeContract(request);

packages/sdk/test/common/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import {
22
parseEther,
33
WalletClient,
4+
zeroAddress,
45
type Address,
56
type PublicClient,
67
} from "viem";
78
import { USDC_MAINNET, USDC_WHALE } from "./constants.js";
89
import { type ChainClient } from "./anvil.js";
910
import { UpgradeTestEnvironment } from "./upgrade.2025.js";
1011

12+
export function isAddressDefined(address?: Address): address is Address {
13+
return address && address !== "0x" && address !== zeroAddress ? true : false;
14+
}
15+
1116
export function sleep(ms: number) {
1217
return new Promise((resolve) => {
1318
setTimeout(() => resolve(true), ms);

packages/sdk/test/e2e/executeQuote.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
BLOCK_NUMBER_MAINNET,
2727
} from "../common/constants.js";
2828
import { fundUsdc } from "../common/utils.js";
29-
import { waitForDepositAndFillV3 } from "../common/relayer.js";
29+
import { waitForDepositAndFillV3_5 } from "../common/relayer.js";
3030
import { spokePoolAbiV3 } from "../../src/abis/SpokePool/index.js";
3131

3232
const inputToken = {
@@ -64,6 +64,7 @@ describe("executeQuote", async () => {
6464
const [_route] = await testClient.getAvailableRoutes(testRoute);
6565
assert(_route !== undefined, "route is not defined");
6666
assertType<Route>(_route);
67+
console.log(_route);
6768
route = _route;
6869
});
6970

@@ -75,6 +76,7 @@ describe("executeQuote", async () => {
7576

7677
assert(_quote, "No quote for route");
7778
assertType<Quote>(_quote);
79+
console.log(_quote);
7880
quote = _quote;
7981
});
8082

@@ -108,7 +110,6 @@ describe("executeQuote", async () => {
108110
value: parseEther("1"),
109111
}),
110112
]);
111-
112113
// fund test wallet clients with 1000 USDC
113114
await fundUsdc(chainClientMainnet, testWalletMainnet.account.address);
114115

@@ -152,12 +153,13 @@ describe("executeQuote", async () => {
152153
if (progress.status === "txSuccess") {
153154
depositTxSuccess = true;
154155
const { txReceipt } = progress;
155-
const _fillHash = await waitForDepositAndFillV3({
156+
const _fillHash = await waitForDepositAndFillV3_5({
156157
depositReceipt: txReceipt,
157158
acrossClient: testClient,
158159
originPublicClient: publicClientMainnet,
159160
destinationPublicClient: publicClientArbitrum,
160161
chainClient: chainClientArbitrum,
162+
exclusiveRelayer: deposit.exclusiveRelayer,
161163
});
162164

163165
fillHash = _fillHash;

0 commit comments

Comments
 (0)