Skip to content

Commit

Permalink
feat: implement tracing url resolver (#46)
Browse files Browse the repository at this point in the history
closes #44
  • Loading branch information
BeroBurny authored Sep 23, 2024
1 parent f01bddf commit efd1be3
Show file tree
Hide file tree
Showing 6 changed files with 279 additions and 5 deletions.
3 changes: 3 additions & 0 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"eslint": "^8.57.0",
"typescript": "^5.0.3"
},
"dependencies": {
"viem": "^2.21.9"
},
"volta": {
"node": "20.17.0",
"yarn": "4.3.1"
Expand Down
87 changes: 87 additions & 0 deletions packages/sdk/src/helpers/acrossV3.abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
export const acrossV3Abi = [
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "inputToken",
type: "address",
},
{
indexed: false,
internalType: "address",
name: "outputToken",
type: "address",
},
{
indexed: false,
internalType: "uint256",
name: "inputAmount",
type: "uint256",
},
{
indexed: false,
internalType: "uint256",
name: "outputAmount",
type: "uint256",
},
{
indexed: true,
internalType: "uint256",
name: "destinationChainId",
type: "uint256",
},
{
indexed: true,
internalType: "uint32",
name: "depositId",
type: "uint32",
},
{
indexed: false,
internalType: "uint32",
name: "quoteTimestamp",
type: "uint32",
},
{
indexed: false,
internalType: "uint32",
name: "fillDeadline",
type: "uint32",
},
{
indexed: false,
internalType: "uint32",
name: "exclusivityDeadline",
type: "uint32",
},
{
indexed: true,
internalType: "address",
name: "depositor",
type: "address",
},
{
indexed: false,
internalType: "address",
name: "recipient",
type: "address",
},
{
indexed: false,
internalType: "address",
name: "exclusiveRelayer",
type: "address",
},
{
indexed: false,
internalType: "bytes",
name: "message",
type: "bytes",
},
],
name: "V3FundsDeposited",
type: "event",
},
] as const;
60 changes: 60 additions & 0 deletions packages/sdk/src/helpers/getTrackingUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { createPublicClient, http, parseEventLogs } from "viem";

import type { Address, Chain, Tool } from "../types";

import { acrossV3Abi } from "./acrossV3.abi";

export async function experimental_getTrackingUrl(
transactionHash: string,
chain: Chain,
tool: Tool,
): Promise<string> {
switch (tool.name) {
case "LiFi": {
const url = new URL("v1/status", "https://li.quest/");
url.searchParams.set("txHash", transactionHash);
return url.toString();
}
case "Sygma": {
const url = new URL(
`api/transfers/txHash/${transactionHash}`,
"https://api.buildwithsygma.com/",
);
return url.toString();
}
case "Sygma-Testnet": {
const url = new URL(
`api/transfers/txHash/${transactionHash}`,
"https://api.test.buildwithsygma.com/",
);
return url.toString();
}
case "Across": {
const rpcUrl =
chain.rpcURLs[Math.floor(Math.random() * chain.rpcURLs.length)];

const client = createPublicClient({
transport: http(rpcUrl),
});
const transactionReceipt = await client.getTransactionReceipt({
hash: transactionHash as Address,
});
const logs = parseEventLogs({
abi: acrossV3Abi,
eventName: "V3FundsDeposited",
logs: transactionReceipt.logs,
});
if (logs.length === 0) {
return "Transaction not found";
}

const url = new URL("api/deposit/status", "https://app.across.to/");
url.searchParams.set("originChainId", String(chain.chainID));
url.searchParams.set("depositId", String(logs[0].args.depositId));

return url.toString();
}
default:
return "Tool not recognized.";
}
}
1 change: 1 addition & 0 deletions packages/sdk/src/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { experimental_getTrackingUrl } from "./getTrackingUrl";
12 changes: 7 additions & 5 deletions packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface Chain {
chainType: ChainType;
name: string;
logoURI: string;
rpcurls: string[];
rpcURLs: string[];
}

export interface TokenBalance {
Expand Down Expand Up @@ -65,6 +65,11 @@ export interface FailedSolution {
error: string;
}

export interface Tool {
logoURI: string;
name: string;
}

export interface Solution {
destinationChain: ChainID;
destinationTokenAddress: Address;
Expand All @@ -75,10 +80,7 @@ export interface Solution {
sourceChain: ChainID;
sourceTokenAddress: Address;
amount: string;
tool: {
logoURI: string;
name: string;
};
tool: Tool;
transaction: Transaction;
approvals?: Transaction[];
}
Expand Down
121 changes: 121 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ __metadata:
version: 8
cacheKey: 10c0

"@adraffy/ens-normalize@npm:1.10.0":
version: 1.10.0
resolution: "@adraffy/ens-normalize@npm:1.10.0"
checksum: 10c0/78ae700847a2516d5a0ae12c4e23d09392a40c67e73b137eb7189f51afb1601c8d18784aeda2ed288a278997824dc924d1f398852c21d41ee2c4c564f2fb4d26
languageName: node
linkType: hard

"@adraffy/ens-normalize@npm:^1.8.8":
version: 1.10.1
resolution: "@adraffy/ens-normalize@npm:1.10.1"
Expand Down Expand Up @@ -1792,6 +1799,7 @@ __metadata:
"@types/node": "npm:18.19.42"
eslint: "npm:^8.57.0"
typescript: "npm:^5.0.3"
viem: "npm:^2.21.9"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -3086,6 +3094,15 @@ __metadata:
languageName: node
linkType: hard

"@noble/curves@npm:1.4.0":
version: 1.4.0
resolution: "@noble/curves@npm:1.4.0"
dependencies:
"@noble/hashes": "npm:1.4.0"
checksum: 10c0/31fbc370df91bcc5a920ca3f2ce69c8cf26dc94775a36124ed8a5a3faf0453badafd2ee4337061ffea1b43c623a90ee8b286a5a81604aaf9563bdad7ff795d18
languageName: node
linkType: hard

"@noble/curves@npm:1.4.2, @noble/curves@npm:~1.4.0":
version: 1.4.2
resolution: "@noble/curves@npm:1.4.2"
Expand All @@ -3095,13 +3112,29 @@ __metadata:
languageName: node
linkType: hard

"@noble/curves@npm:^1.4.0":
version: 1.6.0
resolution: "@noble/curves@npm:1.6.0"
dependencies:
"@noble/hashes": "npm:1.5.0"
checksum: 10c0/f3262aa4d39148e627cd82b5ac1c93f88c5bb46dd2566b5e8e52ffac3a0fc381ad30c2111656fd2bd3b0d37d43d540543e0d93a5ff96a6cb184bc3bfe10d1cd9
languageName: node
linkType: hard

"@noble/hashes@npm:1.4.0, @noble/hashes@npm:~1.4.0":
version: 1.4.0
resolution: "@noble/hashes@npm:1.4.0"
checksum: 10c0/8c3f005ee72e7b8f9cff756dfae1241485187254e3f743873e22073d63906863df5d4f13d441b7530ea614b7a093f0d889309f28b59850f33b66cb26a779a4a5
languageName: node
linkType: hard

"@noble/hashes@npm:1.5.0, @noble/hashes@npm:^1.4.0, @noble/hashes@npm:~1.5.0":
version: 1.5.0
resolution: "@noble/hashes@npm:1.5.0"
checksum: 10c0/1b46539695fbfe4477c0822d90c881a04d4fa2921c08c552375b444a48cac9930cb1ee68de0a3c7859e676554d0f3771999716606dc4d8f826e414c11692cdd9
languageName: node
linkType: hard

"@nodelib/fs.scandir@npm:2.1.5":
version: 2.1.5
resolution: "@nodelib/fs.scandir@npm:2.1.5"
Expand Down Expand Up @@ -3662,6 +3695,13 @@ __metadata:
languageName: node
linkType: hard

"@scure/base@npm:~1.1.8":
version: 1.1.9
resolution: "@scure/base@npm:1.1.9"
checksum: 10c0/77a06b9a2db8144d22d9bf198338893d77367c51b58c72b99df990c0a11f7cadd066d4102abb15e3ca6798d1529e3765f55c4355742465e49aed7a0c01fe76e8
languageName: node
linkType: hard

"@scure/bip32@npm:1.4.0":
version: 1.4.0
resolution: "@scure/bip32@npm:1.4.0"
Expand All @@ -3683,6 +3723,16 @@ __metadata:
languageName: node
linkType: hard

"@scure/bip39@npm:1.4.0":
version: 1.4.0
resolution: "@scure/bip39@npm:1.4.0"
dependencies:
"@noble/hashes": "npm:~1.5.0"
"@scure/base": "npm:~1.1.8"
checksum: 10c0/dcdceeac348ed9c0f545c1a7ef8854ef62d6eb4e7b7aaafa4e2ef27f7e1c5744b0cd26292afd04e1ee59ae035b19abdd65174a444b8db8c238ccc662f6b90eac
languageName: node
linkType: hard

"@sentry-internal/browser-utils@npm:8.25.0":
version: 8.25.0
resolution: "@sentry-internal/browser-utils@npm:8.25.0"
Expand Down Expand Up @@ -5667,6 +5717,21 @@ __metadata:
languageName: node
linkType: hard

"abitype@npm:1.0.5":
version: 1.0.5
resolution: "abitype@npm:1.0.5"
peerDependencies:
typescript: ">=5.0.4"
zod: ^3 >=3.22.0
peerDependenciesMeta:
typescript:
optional: true
zod:
optional: true
checksum: 10c0/dc954877fba19e2b7a70f1025807d69fa5aabec8bd58ce94e68d1a5ec1697fff3fe5214b4392508db7191762150f19a2396cf66ffb1d3ba8c1f37a89fd25e598
languageName: node
linkType: hard

"accepts@npm:~1.3.4, accepts@npm:~1.3.5, accepts@npm:~1.3.8":
version: 1.3.8
resolution: "accepts@npm:1.3.8"
Expand Down Expand Up @@ -11409,6 +11474,15 @@ __metadata:
languageName: node
linkType: hard

"isows@npm:1.0.4":
version: 1.0.4
resolution: "isows@npm:1.0.4"
peerDependencies:
ws: "*"
checksum: 10c0/46f43b07edcf148acba735ddfc6ed985e1e124446043ea32b71023e67671e46619c8818eda8c34a9ac91cb37c475af12a3aeeee676a88a0aceb5d67a3082313f
languageName: node
linkType: hard

"iterator.prototype@npm:^1.1.2":
version: 1.1.2
resolution: "iterator.prototype@npm:1.1.2"
Expand Down Expand Up @@ -17725,6 +17799,28 @@ __metadata:
languageName: node
linkType: hard

"viem@npm:^2.21.9":
version: 2.21.9
resolution: "viem@npm:2.21.9"
dependencies:
"@adraffy/ens-normalize": "npm:1.10.0"
"@noble/curves": "npm:1.4.0"
"@noble/hashes": "npm:1.4.0"
"@scure/bip32": "npm:1.4.0"
"@scure/bip39": "npm:1.4.0"
abitype: "npm:1.0.5"
isows: "npm:1.0.4"
webauthn-p256: "npm:0.0.5"
ws: "npm:8.17.1"
peerDependencies:
typescript: ">=5.0.4"
peerDependenciesMeta:
typescript:
optional: true
checksum: 10c0/342d85595bd1a646bc51b222dbfc046501ffacd7c5b7da28c4bc936248063a0dc26256187a5d2ea048be05785f2e9daf8af27faea315a425e5cb6105a7d1d2d2
languageName: node
linkType: hard

"vite-node@npm:1.6.0":
version: 1.6.0
resolution: "vite-node@npm:1.6.0"
Expand Down Expand Up @@ -18196,6 +18292,16 @@ __metadata:
languageName: unknown
linkType: soft

"webauthn-p256@npm:0.0.5":
version: 0.0.5
resolution: "webauthn-p256@npm:0.0.5"
dependencies:
"@noble/curves": "npm:^1.4.0"
"@noble/hashes": "npm:^1.4.0"
checksum: 10c0/8a445dddaf0e699363a0a7bca51742f672dbbec427c1a97618465bfc418df0eff10d3f1cf5e43bcd0cd0dc5abcdaad7914916c06c84107eaf226f5a1d0690c13
languageName: node
linkType: hard

"webidl-conversions@npm:^3.0.0":
version: 3.0.1
resolution: "webidl-conversions@npm:3.0.1"
Expand Down Expand Up @@ -18632,6 +18738,21 @@ __metadata:
languageName: node
linkType: hard

"ws@npm:8.17.1":
version: 8.17.1
resolution: "ws@npm:8.17.1"
peerDependencies:
bufferutil: ^4.0.1
utf-8-validate: ">=5.0.2"
peerDependenciesMeta:
bufferutil:
optional: true
utf-8-validate:
optional: true
checksum: 10c0/f4a49064afae4500be772abdc2211c8518f39e1c959640457dcee15d4488628620625c783902a52af2dd02f68558da2868fd06e6fd0e67ebcd09e6881b1b5bfe
languageName: node
linkType: hard

"ws@npm:^7.3.1":
version: 7.5.10
resolution: "ws@npm:7.5.10"
Expand Down

0 comments on commit efd1be3

Please sign in to comment.