Skip to content

Commit 0b7e206

Browse files
authored
Everclear Adapter (#368)
* creation of documents and adding everclear to general adapter index.ts * added everclear contract addresses * confirmed contractAddresses + chains * demo 1 * added everclear to bridgeNetworkData * code fix * deleted comments * fixed event signature and abi format * deleted unsupported chains * added new chains * implemented depositIntent and withdrawalIntent events
1 parent c5c5697 commit 0b7e206

File tree

6 files changed

+167
-8
lines changed

6 files changed

+167
-8
lines changed

package-lock.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"build": "vite build",
1515
"start": "node ./dist/index.js",
1616
"start:dev": "node ./dist/index.js",
17-
1817
"start:cron": "node ./dist/startCron.js"
1918
},
2019
"devDependencies": {
@@ -38,7 +37,7 @@
3837
"@aws-sdk/client-s3": "^3.749.0",
3938
"@aws-sdk/client-sts": "^3.749.0",
4039
"@aws-sdk/credential-providers": "^3.749.0",
41-
"@defillama/sdk": "^5.0.119",
40+
"@defillama/sdk": "^5.0.137",
4241
"@fastify/cors": "^9.0.1",
4342
"@graphql-typed-document-node/core": "^3.2.0",
4443
"@solana/web3.js": "^1.87.3",

src/adapters/everclear/index.ts

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import { BridgeAdapter, PartialContractEventParams } from "../../helpers/bridgeAdapter.type";
2+
import { Chain } from "@defillama/sdk/build/general";
3+
import { getTxDataFromEVMEventLogs } from "../../helpers/processTransactions";
4+
import { ethers } from "ethers";
5+
6+
const contractAddresses = {
7+
//EverclearSpoke contract addresses for each chain
8+
ethereum: ["0xa05A3380889115bf313f1Db9d5f335157Be4D816"],
9+
optimism: ["0xa05A3380889115bf313f1Db9d5f335157Be4D816"],
10+
bsc: ["0xa05A3380889115bf313f1Db9d5f335157Be4D816"],
11+
unichain: ["0xa05A3380889115bf313f1Db9d5f335157Be4D816"],
12+
polygon: ["0x7189C59e245135696bFd2906b56607755F84F3fD"],
13+
zksync: ["0x7F5e085981C93C579c865554B9b723B058AaE4D3"],
14+
ronin: ["0xdCA40903E271Cc76AECd62dF8D6c19f3Ac873E64"],
15+
base: ["0xa05A3380889115bf313f1Db9d5f335157Be4D816"],
16+
apechain: ["0xa05A3380889115bf313f1Db9d5f335157Be4D816"],
17+
mode: ["0xeFa6Ac3F931620fD0449eC8c619f2A14A0A78E99"],
18+
arbitrum: ["0xa05A3380889115bf313f1Db9d5f335157Be4D816"],
19+
avalanche: ["0x9aA2Ecad5C77dfcB4f34893993f313ec4a370460"],
20+
zircuit: ["0xD0E86F280D26Be67A672d1bFC9bB70500adA76fe"],
21+
linea: ["0xc24dC29774fD2c1c0c5FA31325Bb9cbC11D8b751"],
22+
blast: ["0x9ADA72CCbAfe94248aFaDE6B604D1bEAacc899A7"],
23+
scroll: ["0xa05A3380889115bf313f1Db9d5f335157Be4D816"],
24+
taiko: ["0x9ADA72CCbAfe94248aFaDE6B604D1bEAacc899A7"],
25+
sonic: ["0xa05A3380889115bf313f1Db9d5f335157Be4D816"],
26+
berachain: ["0xa05A3380889115bf313f1Db9d5f335157Be4D816"],
27+
mantle: ["0xe0F010e465f15dcD42098dF9b99F1038c11B3056"],
28+
ink: ["0xa05A3380889115bf313f1Db9d5f335157Be4D816"],
29+
} as const;
30+
31+
// Helper function to convert bytes32 to address
32+
function bytes32ToAddress(bytes32: string) {
33+
return ethers.utils.getAddress('0x' + bytes32.slice(26));
34+
}
35+
36+
// Deposit event (IntentAdded)
37+
const depositIntent: PartialContractEventParams = {
38+
target: "",
39+
topic: "IntentAdded(bytes32,bytes32,(bytes32,bytes32,bytes32,bytes32,uint24,uint32,uint64,uint48,uint48,uint256,uint32[],bytes))",
40+
abi: [
41+
"event IntentAdded(bytes32 indexed _intentId, bytes32 indexed _queueId, tuple(bytes32 initiator, bytes32 receiver, bytes32 inputAsset, bytes32 outputAsset, uint24 maxFee, uint32 origin, uint64 nonce, uint48 timestamp, uint48 ttl, uint256 amount, uint32[] destinations, bytes data) _intent)",
42+
],
43+
logKeys: {
44+
blockNumber: "blockNumber",
45+
txHash: "transactionHash",
46+
},
47+
argKeys: {
48+
amount: "_intent.amount",
49+
from: "_intent.initiator",
50+
token: "_intent.inputAsset",
51+
},
52+
argGetters: {
53+
from: (logArgs: any) => bytes32ToAddress(logArgs._intent.initiator),
54+
token: (logArgs: any) => bytes32ToAddress(logArgs._intent.inputAsset)
55+
},
56+
isDeposit: true,
57+
};
58+
59+
// Withdrawal event (Settled)
60+
const withdrawalIntent: PartialContractEventParams = {
61+
target: "",
62+
topic: "Settled(bytes32,address,address,uint256)",
63+
abi: [
64+
"event Settled(bytes32 indexed _intentId, address _account, address _asset, uint256 _amount)",
65+
],
66+
logKeys: {
67+
blockNumber: "blockNumber",
68+
txHash: "transactionHash",
69+
},
70+
argKeys: {
71+
amount: "_amount",
72+
to: "_account",
73+
from: "_account",
74+
token: "_asset",
75+
},
76+
isDeposit: false,
77+
};
78+
79+
const constructParams = (chain: Chain) => {
80+
const chainConfig = contractAddresses[chain as keyof typeof contractAddresses];
81+
82+
// Create event params for both deposit and withdrawal events for each contract address
83+
const eventParams: PartialContractEventParams[] = [];
84+
85+
// Add deposit (IntentAdded) events
86+
chainConfig.forEach(address => {
87+
eventParams.push({...depositIntent, target: address});
88+
});
89+
90+
// Add withdrawal (Settled) events
91+
chainConfig.forEach(address => {
92+
eventParams.push({...withdrawalIntent, target: address});
93+
});
94+
95+
return async (fromBlock: number, toBlock: number) => {
96+
console.log("Fetching Everclear bridge volume from block:", fromBlock, "to block:", toBlock)
97+
return getTxDataFromEVMEventLogs("everclear", chain, fromBlock, toBlock, eventParams);
98+
};
99+
};
100+
101+
const adapter: BridgeAdapter = {
102+
ethereum: constructParams("ethereum"),
103+
optimism: constructParams("optimism"),
104+
bsc: constructParams("bsc"),
105+
unichain: constructParams("unichain"),
106+
polygon: constructParams("polygon"),
107+
zksync: constructParams("zksync"),
108+
ronin: constructParams("ronin"),
109+
base: constructParams("base"),
110+
apechain: constructParams("apechain"),
111+
mode: constructParams("mode"),
112+
arbitrum: constructParams("arbitrum"),
113+
avalanche: constructParams("avalanche"),
114+
zircuit: constructParams("zircuit"),
115+
linea: constructParams("linea"),
116+
blast: constructParams("blast"),
117+
scroll: constructParams("scroll"),
118+
taiko: constructParams("taiko"),
119+
sonic: constructParams("sonic"),
120+
berachain: constructParams("berachain"),
121+
mantle: constructParams("mantle"),
122+
ink: constructParams("ink"),
123+
};
124+
125+
export default adapter;

src/adapters/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { BridgeAdapter, AsyncBridgeAdapter } from "../helpers/bridgeAdapter.type";
2+
import everclear from "./everclear";
23
import polygon from "./polygon";
34
import synapse from "./synapse";
45
import hop from "./hop";
@@ -172,6 +173,7 @@ export default {
172173
train,
173174
assetchainbridge,
174175
fuel,
176+
everclear,
175177
lighter,
176178
movement,
177179
intersoon,

src/data/bridgeNetworkData.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2107,7 +2107,8 @@ export default [
21072107
url: "https://bridge.movementnetwork.xyz/",
21082108
chains: ["Ethereum", "Movement"],
21092109
destinationChain: "Movement",
2110-
}, {
2110+
},
2111+
{
21112112
id: 89,
21122113
displayName: "Asset Chain Bridge",
21132114
bridgeDbName: "assetchainbridge",
@@ -2126,4 +2127,35 @@ export default [
21262127
url: "https://intersoon.soo.network",
21272128
chains: ["Solana", "Ton"],
21282129
},
2130+
{
2131+
id: 91,
2132+
displayName: "Everclear",
2133+
bridgeDbName: "everclear",
2134+
iconLink: "icons:everclear",
2135+
largeTxThreshold: 10000,
2136+
url:"https://explorer.everclear.org/",
2137+
chains: [
2138+
"Ethereum",
2139+
"Optimism",
2140+
"BSC",
2141+
"Unichain",
2142+
"Polygon",
2143+
"ZKsync Era",
2144+
"Ronin",
2145+
"Base",
2146+
"ApeChain",
2147+
"Mode",
2148+
"Arbitrum",
2149+
"Avalanche",
2150+
"Zircuit",
2151+
"Linea",
2152+
"Blast",
2153+
"Scroll",
2154+
"Taiko",
2155+
"Sonic",
2156+
"Berachain",
2157+
"Mantle",
2158+
"Ink",
2159+
],
2160+
},
21292161
] as BridgeNetwork[];

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"noImplicitThis": false,
2121
"noUnusedLocals": false,
2222
"noUnusedParameters": true,
23-
"lib": ["ES2019"],
23+
"lib": ["ES2019", "DOM"],
2424
"outDir": ".webpack",
2525
"rootDir": "./src",
2626
"sourceMap": true

0 commit comments

Comments
 (0)