Skip to content

Commit

Permalink
Add sonic
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Dec 18, 2024
1 parent 963b04c commit 30836b2
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 30 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@
"@openzeppelin/contracts": "^4.9.3",
"async-lock": "^1.4.0",
"axios": "^1.5.0",
"blockchain-addressbook": "^0.47.98",
"blockchain-addressbook": "^0.47.106",
"dotenv": "^16.3.1",
"lodash": "^4.17.21",
"pg": "^8.11.3",
"pg-connection-string": "^2.6.2",
"pg-format": "^1.0.4",
"pino": "^8.15.1",
"table": "^6.8.1",
"viem": "^2.21.54",
"viem": "^2.21.55",
"yaml": "^2.3.2",
"yargs": "^17.7.2"
},
Expand Down
20 changes: 20 additions & 0 deletions src/lib/addressbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ export function getChainWNativeTokenDecimals(chain: Chain): number {
// if (chain === 'abc') {
// return 18;
// }

if (chain === 'sonic') {
return 18;
}

const tokens = addressbook.addressBook[chain].tokens;
return tokens.WNATIVE.decimals;
}
Expand All @@ -14,6 +19,11 @@ export function getChainWNativeTokenSymbol(chain: Chain): string {
// if (chain === 'abc') {
// return 'ETH';
// }

if (chain === 'sonic') {
return 'S';
}

const tokens = addressbook.addressBook[chain].tokens;
return tokens.WNATIVE.symbol;
}
Expand All @@ -22,6 +32,11 @@ export function getChainWNativeTokenAddress(chain: Chain): Hex {
// if (chain === 'abc') {
// return '0x0000000000000000000000000000000000000000';
// }

if (chain === 'sonic') {
return '0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38';
}

const tokens = addressbook.addressBook[chain].tokens;
return tokens.WNATIVE.address as Hex;
}
Expand All @@ -30,6 +45,11 @@ export function getNetworkId(chain: Chain): number {
// if (chain === 'abc') {
// return 123;
// }

if (chain === 'sonic') {
return 146;
}

const tokens = addressbook.addressBook[chain].tokens;
return tokens.WNATIVE.chainId;
}
4 changes: 2 additions & 2 deletions src/lib/chain.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { addressBook } from 'blockchain-addressbook';

export type Chain = keyof typeof addressBook | 'mode' | 'scroll';
export type Chain = keyof typeof addressBook | 'sonic';

export const allChainIds: Chain[] = [...Object.keys(addressBook), 'mode', 'scroll'] as Chain[];
export const allChainIds: Chain[] = [...Object.keys(addressBook), 'sonic'] as Chain[];
29 changes: 29 additions & 0 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,28 @@ export const RPC_CONFIG: Record<Chain, RpcConfig> = {
enabled: true, // not yet supported
},
},
sonic: {
...defaultConfig,
url: RPC_FORCE_URL || process.env.SONIC_RPC_URL || 'https://rpc.soniclabs.com',
contracts: {
...defaultContracts,
harvestLens: '0x507c863E3d2FDca55054b90966f1fbA107CEb318',
},
transaction: {
...defaultTransactionConfig,
type: 'legacy',
maxNativePerTransactionWei: bigintMultiplyFloat(ONE_ETHER, 0.01),
},
unwrap: {
...defaultUnwrapConfig,
minAmountOfWNativeWei: bigintMultiplyFloat(ONE_ETHER, 0.005),
maxAmountOfNativeWei: bigintMultiplyFloat(ONE_ETHER, 0.02),
},
revenueBridgeHarvest: {
...defaultRevenueBridgeHarvestConfig,
enabled: false,
},
},
zkevm: {
...defaultConfig,
url: RPC_FORCE_URL || process.env.ZKEVM_RPC_URL || 'https://rpc.ankr.com/polygon_zkevm',
Expand Down Expand Up @@ -1135,6 +1157,13 @@ export const EXPLORER_CONFIG: Record<Chain, ExplorerConfig> = {
apiKey: process.env.SEI_EXPLORER_API_KEY || '',
type: 'etherscan',
},
sonic: {
addressLinkTemplate: 'https://sonicscan.org/address/${address}',
transactionLinkTemplate: 'https://sonicscan.org/tx/${hash}',
apiUrl: process.env.SONIC_EXPLORER_API_URL || 'https://api.sonicscan.org/api',
apiKey: process.env.SONIC_EXPLORER_API_KEY || '',
type: 'etherscan',
},
zkevm: {
addressLinkTemplate: 'https://zkevm.polygonscan.com/address/${address}',
transactionLinkTemplate: 'https://zkevm.polygonscan.com/tx/${hash}',
Expand Down
2 changes: 2 additions & 0 deletions src/lib/rpc-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
rootstock,
scroll,
sei,
sonic,
zkSync,
} from 'viem/chains';
import type { Chain } from './chain';
Expand Down Expand Up @@ -89,6 +90,7 @@ const VIEM_CHAINS: Record<Chain, ViemChain | null> = {
rootstock: applyConfig('rootstock', rootstock),
scroll: applyConfig('scroll', scroll),
sei: applyConfig('sei', sei),
sonic: applyConfig('sonic', sonic),
zkevm: applyConfig('zkevm', polygonZkEvm),
zksync: applyConfig('zksync', zkSync),
};
Expand Down
52 changes: 26 additions & 26 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

"@adraffy/ens-normalize@^1.10.1":
version "1.11.0"
resolved "https://registry.yarnpkg.com/@adraffy/ens-normalize/-/ens-normalize-1.11.0.tgz#42cc67c5baa407ac25059fcd7d405cc5ecdb0c33"
resolved "https://registry.npmjs.org/@adraffy/ens-normalize/-/ens-normalize-1.11.0.tgz"
integrity sha512-/3DDPKHqqIqxUULp8yP4zODUY1i+2xvVWsv8A79xGWdCAG+8sb0hRh0Rk2QyOJUnnbyPUAZYcpBuRe3nS2OIUg==

"@ampproject/remapping@^2.2.0":
Expand Down Expand Up @@ -304,7 +304,7 @@

"@biomejs/biome@1.8.2":
version "1.8.2"
resolved "https://registry.yarnpkg.com/@biomejs/biome/-/biome-1.8.2.tgz#a2c93113409b863eb043095e1aa85f11bf31af04"
resolved "https://registry.npmjs.org/@biomejs/biome/-/biome-1.8.2.tgz"
integrity sha512-XafCzLgs0xbH0bCjYKxQ63ig2V86fZQMq1jiy5pyLToWk9aHxA8GAUxyBtklPHtPYZPGEPOYglQHj4jyfUp+Iw==
optionalDependencies:
"@biomejs/cli-darwin-arm64" "1.8.2"
Expand All @@ -318,12 +318,12 @@

"@biomejs/cli-darwin-arm64@1.8.2":
version "1.8.2"
resolved "https://registry.yarnpkg.com/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-1.8.2.tgz#9e1b3c480d7c62d3272a3b6d1e3e8e7143830a94"
resolved "https://registry.npmjs.org/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-1.8.2.tgz"
integrity sha512-l9msLsTcSIAPqMsPIhodQmb50sEfaXPLQ0YW4cdj6INmd8iaOh/V9NceQb2366vACTJgcWDQ2RzlvURek1T68g==

"@biomejs/cli-darwin-x64@1.8.2":
version "1.8.2"
resolved "https://registry.npmjs.org/@biomejs/cli-darwin-x64/-/cli-darwin-x64-1.8.2.tgz"
resolved "https://registry.yarnpkg.com/@biomejs/cli-darwin-x64/-/cli-darwin-x64-1.8.2.tgz#9d30a25bccbbbd577146642cfbcfb9a96c661708"
integrity sha512-Fc4y/FuIxRSiB3TJ+y27vFDE/HJt4QgBuymktsIKEcBZvnKfsRjxvzVDunccRn4xbKgepnp+fn6BoS+ZIg/I3Q==

"@biomejs/cli-linux-arm64-musl@1.8.2":
Expand Down Expand Up @@ -630,31 +630,31 @@

"@noble/curves@1.7.0", "@noble/curves@^1.6.0", "@noble/curves@~1.7.0":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.7.0.tgz#0512360622439256df892f21d25b388f52505e45"
resolved "https://registry.npmjs.org/@noble/curves/-/curves-1.7.0.tgz"
integrity sha512-UTMhXK9SeDhFJVrHeUJ5uZlI6ajXg10O6Ddocf9S6GjbSBVZsJo88HzKwXznNfGpMTRDyJkqMjNDPYgf0qFWnw==
dependencies:
"@noble/hashes" "1.6.0"

"@noble/curves@^1.4.0":
version "1.4.2"
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.4.2.tgz#40309198c76ed71bc6dbf7ba24e81ceb4d0d1fe9"
resolved "https://registry.npmjs.org/@noble/curves/-/curves-1.4.2.tgz"
integrity sha512-TavHr8qycMChk8UwMld0ZDRvatedkzWfH8IiaeGCfymOP5i0hSCozz9vHOL0nkwk7HRMlFnAiKpS2jrUmSybcw==
dependencies:
"@noble/hashes" "1.4.0"

"@noble/hashes@1.4.0", "@noble/hashes@^1.4.0":
version "1.4.0"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.4.0.tgz#45814aa329f30e4fe0ba49426f49dfccdd066426"
resolved "https://registry.npmjs.org/@noble/hashes/-/hashes-1.4.0.tgz"
integrity sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg==

"@noble/hashes@1.6.0":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.6.0.tgz#d4bfb516ad6e7b5111c216a5cc7075f4cf19e6c5"
resolved "https://registry.npmjs.org/@noble/hashes/-/hashes-1.6.0.tgz"
integrity sha512-YUULf0Uk4/mAA89w+k3+yUYh6NrEvxZa5T6SY3wlMvE2chHkxFUUIDI8/XW1QSC357iA5pSnqt7XEhvFOqmDyQ==

"@noble/hashes@1.6.1", "@noble/hashes@^1.5.0", "@noble/hashes@~1.6.0":
version "1.6.1"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.6.1.tgz#df6e5943edcea504bac61395926d6fd67869a0d5"
resolved "https://registry.npmjs.org/@noble/hashes/-/hashes-1.6.1.tgz"
integrity sha512-pq5D8h10hHBjyqX+cfBm0i8JUXJ0UhczFc4r74zbuT9XgewFo2E3J1cOaGtdZynILNmQ685YWGzGE1Zv6io50w==

"@nodelib/fs.scandir@2.1.5":
Expand Down Expand Up @@ -763,12 +763,12 @@

"@scure/base@~1.2.1":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.2.1.tgz#dd0b2a533063ca612c17aa9ad26424a2ff5aa865"
resolved "https://registry.npmjs.org/@scure/base/-/base-1.2.1.tgz"
integrity sha512-DGmGtC8Tt63J5GfHgfl5CuAXh96VF/LD8K9Hr/Gv0J2lAoRGlPOMpqMpMbCTOoOJMZCk2Xt+DskdDyn6dEFdzQ==

"@scure/bip32@1.6.0", "@scure/bip32@^1.5.0":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@scure/bip32/-/bip32-1.6.0.tgz#6dbc6b4af7c9101b351f41231a879d8da47e0891"
resolved "https://registry.npmjs.org/@scure/bip32/-/bip32-1.6.0.tgz"
integrity sha512-82q1QfklrUUdXJzjuRU7iG7D7XiFx5PHYVS0+oeNKhyDLT7WPqs6pBcM2W5ZdwOwKCwoE1Vy1se+DHjcXwCYnA==
dependencies:
"@noble/curves" "~1.7.0"
Expand All @@ -777,7 +777,7 @@

"@scure/bip39@1.5.0", "@scure/bip39@^1.4.0":
version "1.5.0"
resolved "https://registry.yarnpkg.com/@scure/bip39/-/bip39-1.5.0.tgz#c8f9533dbd787641b047984356531d84485f19be"
resolved "https://registry.npmjs.org/@scure/bip39/-/bip39-1.5.0.tgz"
integrity sha512-Dop+ASYhnrwm9+HA/HwXg7j2ZqM6yk2fyLWb5znexjctFY3+E+eU8cIWI0Pql0Qx4hPZCijlGq4OL71g+Uz30A==
dependencies:
"@noble/hashes" "~1.6.0"
Expand Down Expand Up @@ -1004,7 +1004,7 @@ abbrev@^1.0.0:

abitype@1.0.7, abitype@^1.0.6:
version "1.0.7"
resolved "https://registry.yarnpkg.com/abitype/-/abitype-1.0.7.tgz#876a0005d211e1c9132825d45bcee7b46416b284"
resolved "https://registry.npmjs.org/abitype/-/abitype-1.0.7.tgz"
integrity sha512-ZfYYSktDQUwc2eduYu8C4wOs+RDPmnRYMh7zNfzeMtGGgb0U+6tLGjixUic6mXf5xKKCcgT5Qp6cv39tOARVFw==

abort-controller@^3.0.0:
Expand Down Expand Up @@ -1253,10 +1253,10 @@ base64-js@^1.3.1:
resolved "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz"
integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==

blockchain-addressbook@^0.47.98:
version "0.47.98"
resolved "https://registry.yarnpkg.com/blockchain-addressbook/-/blockchain-addressbook-0.47.98.tgz#d42cddd3b7e6add7cc78f7c81044f9147ccbccec"
integrity sha512-U4FbqU3pb3ZN+/tC+NlL+6V5KUnliOcHnmYbq7Ft3+VuuJaqLoMeC/w1GnfzJvBnd7fSv3FdFTFS3o7nVyYHJA==
blockchain-addressbook@^0.47.106:
version "0.47.106"
resolved "https://registry.npmjs.org/blockchain-addressbook/-/blockchain-addressbook-0.47.106.tgz"
integrity sha512-zOUBYl4G4yc552jeSDyg+Zl9AhYV5vk/W2TnmppL4OJ2dADRmhyw5EC/KFtjkvNkN+P7zXMkH2Wl836ePeCr5Q==

boxen@^7.0.0:
version "7.1.1"
Expand Down Expand Up @@ -1794,7 +1794,7 @@ event-target-shim@^5.0.0:

eventemitter3@5.0.1, eventemitter3@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-5.0.1.tgz#53f5ffd0a492ac800721bb42c66b841de96423c4"
resolved "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz"
integrity sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==

events@^3.3.0:
Expand Down Expand Up @@ -2415,7 +2415,7 @@ isexe@^2.0.0:

isows@1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/isows/-/isows-1.0.6.tgz#0da29d706fa51551c663c627ace42769850f86e7"
resolved "https://registry.npmjs.org/isows/-/isows-1.0.6.tgz"
integrity sha512-lPHCayd40oW98/I0uvgaHKWCSvkzY27LjWLbtzOm64yQ+G3Q5npjjbdppU65iZXkK1Zt+kH9pfegli0AYfwYYw==

istanbul-lib-coverage@^3.0.0, istanbul-lib-coverage@^3.2.0:
Expand Down Expand Up @@ -3479,7 +3479,7 @@ onetime@^6.0.0:

ox@0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/ox/-/ox-0.1.2.tgz#0f791be2ccabeaf4928e6d423498fe1c8094e560"
resolved "https://registry.npmjs.org/ox/-/ox-0.1.2.tgz"
integrity sha512-ak/8K0Rtphg9vnRJlbOdaX9R7cmxD2MiSthjWGaQdMk3D7hrAlDoM+6Lxn7hN52Za3vrXfZ7enfke/5WjolDww==
dependencies:
"@adraffy/ens-normalize" "^1.10.1"
Expand Down Expand Up @@ -4721,10 +4721,10 @@ validate-npm-package-name@^5.0.0:
dependencies:
builtins "^5.0.0"

viem@^2.21.54:
version "2.21.54"
resolved "https://registry.yarnpkg.com/viem/-/viem-2.21.54.tgz#76d6f86ab8809078f1ac140ac1a2beadbc86b9f6"
integrity sha512-G9mmtbua3UtnVY9BqAtWdNp+3AO+oWhD0B9KaEsZb6gcrOWgmA4rz02yqEMg+qW9m6KgKGie7q3zcHqJIw6AqA==
viem@^2.21.55:
version "2.21.55"
resolved "https://registry.npmjs.org/viem/-/viem-2.21.55.tgz"
integrity sha512-PgXew7C11cAuEtOSgRyQx2kJxEOPUwIwZA9dMglRByqJuFVA7wSGZZOOo/93iylAA8E15bEdqy9xulU3oKZ70Q==
dependencies:
"@noble/curves" "1.7.0"
"@noble/hashes" "1.6.1"
Expand All @@ -4745,7 +4745,7 @@ walker@^1.0.8:

webauthn-p256@0.0.10:
version "0.0.10"
resolved "https://registry.yarnpkg.com/webauthn-p256/-/webauthn-p256-0.0.10.tgz#877e75abe8348d3e14485932968edf3325fd2fdd"
resolved "https://registry.npmjs.org/webauthn-p256/-/webauthn-p256-0.0.10.tgz"
integrity sha512-EeYD+gmIT80YkSIDb2iWq0lq2zbHo1CxHlQTeJ+KkCILWpVy3zASH3ByD4bopzfk0uCwXxLqKGLqp2W4O28VFA==
dependencies:
"@noble/curves" "^1.4.0"
Expand Down Expand Up @@ -4831,7 +4831,7 @@ write-file-atomic@^4.0.2:

ws@8.18.0:
version "8.18.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.18.0.tgz#0d7505a6eafe2b0e712d232b42279f53bc289bbc"
resolved "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz"
integrity sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==

xdg-basedir@^5.0.1, xdg-basedir@^5.1.0:
Expand Down

0 comments on commit 30836b2

Please sign in to comment.