-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathrelayer.ts
More file actions
64 lines (61 loc) · 1.53 KB
/
relayer.ts
File metadata and controls
64 lines (61 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { BigNumber, BigNumberish } from "ethers";
import { getRelayAPIKEY, getRelayUrl } from "./utils";
import { axiosGet, axiosPost } from "@socket.tech/dl-common";
import { mode } from "../config/config";
import { ChainSlugToId } from "../../../src";
interface RequestObj {
to: string;
data: string;
chainSlug: number;
value?: string | BigNumber;
gasPrice?: BigNumberish;
gasLimit?: BigNumberish;
type?: number;
}
export const relayTx = async (params: RequestObj) => {
try {
let { to, data, chainSlug, gasPrice, value, type, gasLimit } = params;
let config = {
headers: {
"x-api-key": getRelayAPIKEY(mode),
},
};
let body = {
to,
data,
value,
chainId: ChainSlugToId[chainSlug],
gasLimit,
gasPrice,
type,
sequential: false,
source: "LoadTester",
};
let response = await axiosPost(
`${await getRelayUrl(mode)}/relay`,
body,
config
);
if (response?.success) return response?.data;
else {
console.log("error in relaying tx", response);
return { hash: "" };
}
} catch (error) {
console.log("uncaught error", error);
}
};
export const getStatus = async (txId: string) => {
try {
const response = await axiosGet(
`${await getRelayUrl(mode)}/status?txId=${txId}`
);
if (response?.success) return response?.data;
else {
console.log("error in relaying tx", response);
return { hash: "" };
}
} catch (error) {
console.log("uncaught error", error);
}
};