Skip to content

Commit 4f8efbe

Browse files
committed
switch token fetch to debridge api for debridge provider
1 parent 2abe7de commit 4f8efbe

File tree

12 files changed

+181
-93
lines changed

12 files changed

+181
-93
lines changed

dist/index.d.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,36 @@ import { Chain } from 'viem/chains';
44
import { N as Network } from './adapter-06DuPPG-.js';
55
import 'zod';
66

7+
declare const ChainById: {
8+
abstract: number;
9+
arbitrum: number;
10+
avalanche: number;
11+
base: number;
12+
berachain: number;
13+
bitrock: number;
14+
bsc: number;
15+
cronos: number;
16+
cronoszkEVM: number;
17+
crossFi: number;
18+
ethereum: number;
19+
fantom: number;
20+
gnosis: number;
21+
heco: number;
22+
hyperEVM: number;
23+
linea: number;
24+
metis: number;
25+
neon: number;
26+
opBNB: number;
27+
optimism: number;
28+
polygon: number;
29+
polygonzkEVM: number;
30+
sei: number;
31+
sonic: number;
32+
story: number;
33+
tron: number;
34+
};
35+
declare const getChainMap: (chainId: number) => string | undefined;
36+
737
/**
838
* Get a chain from the viem chains object
939
*
@@ -19,4 +49,4 @@ declare const getChain: (id: string) => Chain;
1949
*/
2050
declare const getNetworkInfo: (chain: Chain) => Network;
2151

22-
export { Network, getChain, getNetworkInfo };
52+
export { ChainById, Network, getChain, getChainMap, getNetworkInfo };

dist/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {
2+
ChainById,
23
getChain,
4+
getChainMap,
35
getNetworkInfo
4-
} from "./chunk-QYWLTMWP.js";
6+
} from "./chunk-DO5TJVOX.js";
57
import {
68
__name,
79
__publicField
@@ -45,7 +47,9 @@ var _DexAi = class _DexAi {
4547
__name(_DexAi, "DexAi");
4648
var DexAi = _DexAi;
4749
export {
50+
ChainById,
4851
DexAi,
4952
getChain,
53+
getChainMap,
5054
getNetworkInfo
5155
};

src/adapters/providers/coingecko/constants.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,4 @@ export const CoingeckoPlatformId = {
5454
[Chain.SONIC]: "sonic",
5555
[Chain.STORY]: "story",
5656
[Chain.TRON]: "tron",
57-
};
58-
59-
60-
// bridge 1 LINK from bsc to USDT on sonic
61-
// 0x691889F5944126906F0051c5ca087e975BADABb3
57+
};

src/adapters/providers/debridge/constants.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Chain } from "../../../networks/constant";
1+
import { Chain, getChainMap } from "../../../networks/constant";
22

33
export const supportedChains = [
44
Chain.ARBITRUM,
@@ -88,3 +88,13 @@ export const DLNInternalId = {
8888
[Chain.SONIC]: 100000014,
8989
[Chain.STORY]: 100000013,
9090
};
91+
92+
/**
93+
* Retrieve DLN internal ID by passing a chainId
94+
* @param chainId
95+
* @returns
96+
*/
97+
export const getDLNByChainId = (chainId: number) => {
98+
const chain = getChainMap(chainId);
99+
if (chain) return DLNInternalId[chain];
100+
};

src/adapters/providers/debridge/dln.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import { dlnSourceAbi } from "./abis/dlnSource";
1010
import { DLN, evmDLNContracts } from "./constants";
1111
import { getChain } from "dexai";
1212
import { Chain, ChainById } from "../../../networks/constant";
13-
import { PrepareTxResponse, ValidateChainResponse } from "./type";
13+
import { DeBridgeTokens, PrepareTxResponse, ValidateChainResponse } from "./type";
14+
import { toResult } from "@heyanon/sdk";
1415

1516
// Define bridge step types for better type safety
1617
type BridgeStep = "initial" | "confirmation" | "execution";
@@ -20,7 +21,7 @@ type BridgeStep = "initial" | "confirmation" | "execution";
2021
* This provider provides the ability for user to bridge token from one chain to another.
2122
*/
2223
export class DeBridgeLiquidityAdapterProvider extends AdapterProvider<BaseAccount> {
23-
private tokensCache: LRUCache<string, Token[]>;
24+
private tokensCache: LRUCache<string, DeBridgeTokens[]>;
2425
private bridgeStep: BridgeStep;
2526
private transactionTimeout: NodeJS.Timeout | null = null;
2627
private lastPreparedTransaction: any = null;
@@ -42,6 +43,9 @@ export class DeBridgeLiquidityAdapterProvider extends AdapterProvider<BaseAccoun
4243
name: "bridge_token",
4344
description: `
4445
Bridge a token from one network chain to another network chain or token
46+
47+
Inputs:
48+
-
4549
4650
Strict Rules:
4751
- Do not respond without querying bridge_token function
@@ -55,10 +59,7 @@ export class DeBridgeLiquidityAdapterProvider extends AdapterProvider<BaseAccoun
5559
// Handle transaction cancellation
5660
if (this.bridgeStep === "execution" && !args.isConfirmed) {
5761
this.resetBridgeState(args);
58-
return {
59-
success: true,
60-
data: "Transaction has been cancled successfully",
61-
};
62+
return toResult("Transaction has been cancled successfully", false);
6263
}
6364

6465
// Reset confirmation if not in execution step
@@ -73,10 +74,7 @@ export class DeBridgeLiquidityAdapterProvider extends AdapterProvider<BaseAccoun
7374

7475
const validatedChains = validateDLNInputs(args);
7576
if (!validatedChains.success || !validatedChains.data)
76-
return {
77-
success: validatedChains.success,
78-
data: validatedChains.errorMessage,
79-
};
77+
return toResult(validatedChains.errorMessage, true);
8078

8179
const { fromChain, toChain } = validatedChains.data;
8280

@@ -99,10 +97,10 @@ export class DeBridgeLiquidityAdapterProvider extends AdapterProvider<BaseAccoun
9997

10098
if (!prepareTx.success) {
10199
this.resetBridgeState();
102-
return {
103-
success: false,
104-
data: "errorMessage" in prepareTx ? prepareTx.errorMessage : "Unknown error occurred",
105-
};
100+
return toResult(
101+
"errorMessage" in prepareTx ? prepareTx.errorMessage : "Unknown error occurred",
102+
true,
103+
);
106104
}
107105

108106
// Handle confirmation step
@@ -286,14 +284,15 @@ export class DeBridgeLiquidityAdapterProvider extends AdapterProvider<BaseAccoun
286284

287285
// Format token lists for display
288286
const sourceTokens = srcTokens
289-
?.map((t: Token, i) => `${i + 1}. ${t.symbol.toUpperCase()} - ${t.address}`)
287+
?.map((t: DeBridgeTokens, i) => `${i + 1}. ${t.symbol.toUpperCase()} - ${t.address}`)
290288
.join("\n");
291289

292290
const destinationTokens = destTokens
293-
?.map((t: Token, i) => `${i + 1}. ${t.symbol.toUpperCase()} - ${t.address}`)
291+
?.map((t: DeBridgeTokens, i) => `${i + 1}. ${t.symbol.toUpperCase()} - ${t.address}`)
294292
.join("\n");
295293

296-
return `
294+
return toResult(
295+
`
297296
Stricly display below token data for user to select source and destination tokens
298297
from the list below which they want to bridge.
299298
@@ -304,7 +303,9 @@ export class DeBridgeLiquidityAdapterProvider extends AdapterProvider<BaseAccoun
304303
${destinationTokens}
305304
306305
If the token you want to bridge to isn't on the list, kindly paste the token address.
307-
`;
306+
`,
307+
false,
308+
);
308309
}
309310

310311
/**
@@ -319,8 +320,8 @@ export class DeBridgeLiquidityAdapterProvider extends AdapterProvider<BaseAccoun
319320
? "⚠️ Your previous transaction has expired. Please review and confirm the updated transaction details."
320321
: "Note: This transaction will expire in 30 seconds if not confirmed.";
321322

322-
return {
323-
message: `
323+
return toResult(
324+
`
324325
Strictly display this entire confirmation message to user:
325326
326327
${wasExpired ? expiryMessage : ""}
@@ -344,7 +345,8 @@ export class DeBridgeLiquidityAdapterProvider extends AdapterProvider<BaseAccoun
344345
345346
${!wasExpired ? expiryMessage : ""}
346347
`,
347-
};
348+
false,
349+
);
348350
}
349351

350352
/**
@@ -419,7 +421,7 @@ export class DeBridgeLiquidityAdapterProvider extends AdapterProvider<BaseAccoun
419421

420422
// Reset bridge state after successful transaction
421423
this.resetBridgeState(args);
422-
return { success: true, data: "Bridge transaction submitted successfully" };
424+
return toResult("Bridge transaction submitted successfully", false);
423425
}
424426

425427
/**
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
export { dlnAdapterProvider } from "./dln";
2+
export {
3+
DLNInternalId,
4+
deBridgeGates,
5+
evmDLNContracts,
6+
DLN,
7+
svmDLNContracts,
8+
getDLNByChainId,
9+
} from "./constants";

src/adapters/providers/debridge/schemas/bridge.schema.ts

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,34 @@ import { z } from "zod";
22
import { supportedChains } from "../constants";
33
import { zeroAddress } from "viem";
44

5+
// Please select the source and destination tokens from the list below for the bridging process:
6+
7+
// ### Source Tokens:
8+
// 1. **ETH** - `0x0000000000000000000000000000000000000000`
9+
// 2. **USDT** - `0xdac17f958d2ee523a2206206994597c13d831ec7`
10+
// 3. **BNB** - `0x418d75f65a02b3d53b2418fb8e1fe493759c7605`
11+
// 4. **USDC** - `0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48`
12+
// 5. **STETH** - `0xae7ab96520de3a18e5e111b5eaab095312d7fe84`
13+
// 6. **WBTC** - `0x2260fac5e5542a773aa44fbcfedf7c193bc2c599`
14+
// 7. **LINK** - `0x514910771af9ca656af840dff83e8264ecf986ca`
15+
// 8. **WSTETH** - `0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0`
16+
// 9. **LEO** - `0x2af5d2ad76741191d15dfe7bf6ac92d4bd912ca3`
17+
// 10. **SHIB** - `0xfcaf0e4498e78d65526a507360f755178b804ba8`
18+
19+
// ### Destination Tokens:
20+
// 1. **BNB** - `0x0000000000000000000000000000000000000000`
21+
// 2. **LINK** - `0xf8a0bf9cf54bb92f17374d9e9a321e6a111a51bd`
22+
// 3. **TON** - `0x76a797a59ba2c17726896976b7b3747bfd1d220f`
23+
// 4. **OM** - `0xf78d2e7936f5fe18308a3b2951a93b6c4a41f5e2`
24+
// 5. **UNI** - `0xbf5140a22578168fd562dccf235e5d43a02ce9b1`
25+
// 6. **PEPE** - `0xef00278d7eadf3b2c05267a2f185e468ad7eab7d`
26+
// 7. **AAVE** - `0xfb6115445bff7b52feb98650c87f44907e58f802`
27+
// 8. **ATOM** - `0x0eb3a705fc54725037cc9e008bdede697f62f335`
28+
// 9. **FDUSD** - `0xc5f0f7b66764f6ec8c8dff7ba683102295e16409`
29+
// 10. **FET** - `0x031b41e504677879370e9dbcf937283a8691fa7f`
30+
31+
// If the token you want to bridge to isn't on the list, kindly provide the token address.
32+
533
/**
634
* Input schema for bridging tokens on deBridge
735
*/
@@ -13,19 +41,25 @@ export const bridgeTokenSchema = z.object({
1341
.string()
1442
.default(zeroAddress)
1543
.optional()
16-
.describe("The token address that will be bridged."),
44+
.describe("The token address that will be bridged. use default address if not provided"),
1745
destinationChain: z
1846
.enum(supportedChains.map(sc => sc) as [string, ...string[]])
1947
.describe("Chain name to where the source chain sends transaction"),
2048
destinationTokenAddress: z
2149
.string()
2250
.default(zeroAddress)
2351
.optional()
24-
.describe("The token address that will be recieved after the bridge"),
25-
to: z.string().optional().default(zeroAddress).describe(`The address of the receiver`),
52+
.describe(
53+
"The token address that will be recieved after the bridge. use default address if not provided",
54+
),
55+
to: z
56+
.string()
57+
.optional()
58+
.default(zeroAddress)
59+
.describe(`The address of the receiver. use default address if not provided.`),
2660
amount: z.string().describe("Amount of tokens in decimal format"),
2761
isConfirmed: z
2862
.boolean()
2963
.default(false)
30-
.describe("this is the last step before transaction is done"),
64+
.describe("Never ask for confirmation except if I ask you to"),
3165
});

src/adapters/providers/debridge/type.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,23 @@ export type PrepareTxResponse = {
3333
amountInUsd: number;
3434
estTakeValueInUsd: number;
3535
takeAmountInUint: number;
36-
destToken: Token;
37-
sourceToken: Token;
36+
destToken: DeBridgeTokens;
37+
sourceToken: DeBridgeTokens;
3838
affiliateFee: Hex;
3939
permitEnvelope: Hex;
4040
};
41+
42+
export interface DeBridgeTokenResponse {
43+
tokens: {
44+
[key: string]: DeBridgeTokens;
45+
};
46+
}
47+
export interface DeBridgeTokens {
48+
symbol: string;
49+
name: string;
50+
decimals: number;
51+
address: string;
52+
logoURI: string;
53+
tags?: [{ Name: string }];
54+
eip2612?: boolean;
55+
}

0 commit comments

Comments
 (0)