Skip to content

Commit 8e8f427

Browse files
authored
Solana withdrawals migration (#96)
* chore: start migrating to new allocator * chore: start migrating to new allocator * chore: start migrating to new allocator * chore: start migrating to new allocator * chore: start migrating to new allocator * chore: start migrating to new allocator * fix: onchain allocator cache * fix: onchain allocator cache * fix: onchain allocator cache * chore: migrate to new allocator * chore: migrate to new allocator * chore: migrate to new allocator * chore: migrate to new allocator * chore: migrate to new allocator * chore: migrate to new allocator * chore: migrate to new allocator * chore: upgrade sdk * feat: prepare for solana withdrawals migration * fix: build
1 parent c57dafb commit 8e8f427

File tree

5 files changed

+20
-30
lines changed

5 files changed

+20
-30
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"@fastify/swagger-ui": "^5.2.3",
2020
"@fastify/type-provider-typebox": "^5.1.0",
2121
"@near-js/providers": "^2.3.1",
22-
"@reservoir0x/relay-protocol-sdk": "^0.0.50",
22+
"@reservoir0x/relay-protocol-sdk": "^0.0.59",
2323
"@sinclair/typebox": "^0.34.14",
2424
"@solana/web3.js": "^1.98.2",
2525
"asn1.js": "^5.4.1",

src/api/queries/chains/v1.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const Schema = {
2727
Type.Literal("sui-vm"),
2828
Type.Literal("ton-vm"),
2929
Type.Literal("tron-vm"),
30+
Type.Literal("lighter-vm"),
3031
],
3132
{
3233
description: "The vm type of the chain",

src/services/request-handler/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
getDecodedWithdrawalId,
55
getVmTypeNativeCurrency,
66
} from "@reservoir0x/relay-protocol-sdk";
7-
import { PublicKey, Keypair } from "@solana/web3.js";
7+
import { PublicKey, Keypair, SystemProgram } from "@solana/web3.js";
88
import * as bitcoin from "bitcoinjs-lib";
99
import bs58 from "bs58";
1010
import { randomBytes } from "crypto";
@@ -20,6 +20,7 @@ import {
2020
parseAbi,
2121
zeroAddress,
2222
encodeAbiParameters,
23+
zeroHash,
2324
} from "viem";
2425
import { privateKeyToAccount } from "viem/accounts";
2526
import TronWeb from "tronweb";
@@ -299,6 +300,9 @@ export class RequestHandlerService {
299300
amount: request.amount,
300301
nonce: BigInt("0x" + randomBytes(8).toString("hex")).toString(),
301302
expiration,
303+
// TODO: Use correct values fetched from the depository
304+
domain: zeroHash,
305+
vaultAddress: SystemProgram.programId.toBase58(),
302306
};
303307

304308
id = getDecodedWithdrawalId({

src/utils/onchain-allocator.ts

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,8 @@ const getPayloadBuilder = async (address: string) => {
8585
};
8686
};
8787

88-
export const getOnchainAllocator = async (chainId: string) => {
89-
let allocator = config.onchainAllocator;
90-
if (
91-
process.env.SERVICE === "relay-protocol-hub-dev" &&
92-
[
93-
"ethereum",
94-
"optimism",
95-
"polygon",
96-
"abstract",
97-
"base",
98-
"arbitrum",
99-
"solana",
100-
"hyperliquid",
101-
].includes(chainId)
102-
) {
103-
allocator = "0x45348c213bf7ddb8e45f34ca4f333307a78ecb9a";
104-
}
105-
88+
export const getOnchainAllocator = async (_chainId: string) => {
89+
const allocator = config.onchainAllocator;
10690
if (!allocator) {
10791
throw externalError("Onchain allocator not configured");
10892
}
@@ -190,11 +174,12 @@ const extractEddsaSignature = (rawNearSignature: string): string => {
190174

191175
let _getSignerCache = new Map<string, string>();
192176
export const getSigner = async (chainId: string) => {
193-
const vmType = await getChain(chainId).then((c) => c.vmType);
194-
if (_getSignerCache.has(vmType)) {
195-
return _getSignerCache.get(vmType)!;
177+
if (_getSignerCache.has(chainId)) {
178+
return _getSignerCache.get(chainId)!;
196179
}
197180

181+
const vmType = await getChain(chainId).then((c) => c.vmType);
182+
198183
let domainId: number | undefined;
199184
switch (vmType) {
200185
case "ethereum-vm":
@@ -235,7 +220,7 @@ export const getSigner = async (chainId: string) => {
235220
case "ethereum-vm":
236221
case "hyperliquid-vm": {
237222
_getSignerCache.set(
238-
vmType,
223+
chainId,
239224
publicKeyToAddress(
240225
`0x04${Buffer.from(bs58.decode(publicKey)).toString("hex")}`
241226
).toLowerCase()
@@ -245,7 +230,7 @@ export const getSigner = async (chainId: string) => {
245230
}
246231

247232
case "solana-vm": {
248-
_getSignerCache.set(vmType, publicKey);
233+
_getSignerCache.set(chainId, publicKey);
249234

250235
break;
251236
}
@@ -255,7 +240,7 @@ export const getSigner = async (chainId: string) => {
255240
}
256241
}
257242

258-
return _getSignerCache.get(vmType)!;
243+
return _getSignerCache.get(chainId)!;
259244
};
260245

261246
export const getSignature = async (id: string) => {

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,10 +1463,10 @@
14631463
resolved "https://registry.yarnpkg.com/@protobuf-ts/runtime/-/runtime-2.11.1.tgz#ee2bf2fac6e2d8deac0ca63471a77481548e5553"
14641464
integrity sha512-KuDaT1IfHkugM2pyz+FwiY80ejWrkH1pAtOBOZFuR6SXEFTsnb/jiQWQ1rCIrcKx2BtyxnxW6BWwsVSA/Ie+WQ==
14651465

1466-
"@reservoir0x/relay-protocol-sdk@^0.0.50":
1467-
version "0.0.50"
1468-
resolved "https://registry.yarnpkg.com/@reservoir0x/relay-protocol-sdk/-/relay-protocol-sdk-0.0.50.tgz#0a5b42e9f52aa8143ed13e6bf389e19274cd8f92"
1469-
integrity sha512-2WcysR1rb2r5yqUxbSXDEvIvUk6lcDfG/pb7GUGr4Ub4AA9TNofCu2fgkB1Yu2HySfDADYWZ420wm7P26SGZQg==
1466+
"@reservoir0x/relay-protocol-sdk@^0.0.59":
1467+
version "0.0.59"
1468+
resolved "https://registry.yarnpkg.com/@reservoir0x/relay-protocol-sdk/-/relay-protocol-sdk-0.0.59.tgz#ee6edcfd54d3bb58aa835f79471797474f55bb97"
1469+
integrity sha512-T0nxQiGCclvDdsfsaXI+oydjRHmSY9xvVqNCZHRj+QOYmG/hl3wj+f/+uqacPI/ht+AGnvrx5FtKJIm36c78Yw==
14701470
dependencies:
14711471
"@coral-xyz/anchor" "^0.31.1"
14721472
"@mysten/sui" "^1.24.0"

0 commit comments

Comments
 (0)