Skip to content

Commit c29e90f

Browse files
authored
feat: lens testnet support (#824)
1 parent 547fcf1 commit c29e90f

File tree

10 files changed

+89
-87
lines changed

10 files changed

+89
-87
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@across-protocol/sdk",
33
"author": "UMA Team",
4-
"version": "3.4.8",
4+
"version": "3.4.9",
55
"license": "AGPL-3.0",
66
"homepage": "https://docs.across.to/reference/sdk",
77
"files": [
@@ -99,8 +99,8 @@
9999
},
100100
"dependencies": {
101101
"@across-protocol/across-token": "^1.0.0",
102-
"@across-protocol/constants": "^3.1.25",
103-
"@across-protocol/contracts": "^3.0.19",
102+
"@across-protocol/constants": "^3.1.27",
103+
"@across-protocol/contracts": "^3.0.20",
104104
"@eth-optimism/sdk": "^3.3.1",
105105
"@ethersproject/bignumber": "^5.7.0",
106106
"@pinata/sdk": "^2.1.0",

src/constants.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { constants as ethersConstants } from "ethers";
2-
import { TOKEN_SYMBOLS_MAP } from "@across-protocol/constants";
2+
import { CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "@across-protocol/constants";
33

44
export {
55
ChainFamily,
@@ -60,3 +60,12 @@ export const BRIDGED_USDC_SYMBOLS = [
6060
TOKEN_SYMBOLS_MAP.USDbC.symbol,
6161
TOKEN_SYMBOLS_MAP.USDzC.symbol,
6262
];
63+
64+
export const CUSTOM_GAS_TOKENS = {
65+
[CHAIN_IDs.POLYGON]: "MATIC",
66+
[CHAIN_IDs.POLYGON_AMOY]: "MATIC",
67+
[CHAIN_IDs.ALEPH_ZERO]: "AZERO",
68+
// FIXME: Replace with GRASS price once listed on Coingecko.
69+
// For testing purposes, we use ETH price instead.
70+
[CHAIN_IDs.LENS_SEPOLIA]: "ETH",
71+
};

src/relayFeeCalculator/chain-queries/alephZero.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { CHAIN_IDs } from "../../constants";
2+
import { Coingecko } from "../../coingecko/Coingecko";
3+
import { QueryBase } from "./baseQuery";
4+
5+
type QueryBaseArgs = ConstructorParameters<typeof QueryBase>;
6+
7+
export class CustomGasTokenQueries extends QueryBase {
8+
readonly customGasTokenSymbol: string;
9+
10+
constructor(args: { queryBaseArgs: QueryBaseArgs; customGasTokenSymbol: string }) {
11+
super(...args.queryBaseArgs);
12+
this.customGasTokenSymbol = args.customGasTokenSymbol;
13+
}
14+
15+
override async getTokenPrice(tokenSymbol: string): Promise<number> {
16+
if (!this.symbolMapping[tokenSymbol]) throw new Error(`${tokenSymbol} does not exist in mapping`);
17+
const coingeckoInstance = Coingecko.get(this.logger, this.coingeckoProApiKey);
18+
const [, tokenPrice] = await coingeckoInstance.getCurrentPriceByContract(
19+
this.symbolMapping[tokenSymbol].addresses[CHAIN_IDs.MAINNET],
20+
"usd"
21+
);
22+
23+
const [, customGasTokenPrice] = await coingeckoInstance.getCurrentPriceByContract(
24+
this.symbolMapping[this.customGasTokenSymbol].addresses[CHAIN_IDs.MAINNET],
25+
"usd"
26+
);
27+
return Number((tokenPrice / customGasTokenPrice).toFixed(this.symbolMapping[this.customGasTokenSymbol].decimals));
28+
}
29+
}

src/relayFeeCalculator/chain-queries/factory.ts

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ import { CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "@across-protocol/constants";
33
import { getDeployedAddress } from "@across-protocol/contracts";
44
import { asL2Provider } from "@eth-optimism/sdk";
55
import { providers } from "ethers";
6-
import { DEFAULT_SIMULATED_RELAYER_ADDRESS } from "../../constants";
7-
import { chainIsAlephZero, chainIsMatic, chainIsOPStack, isDefined } from "../../utils";
6+
import { DEFAULT_SIMULATED_RELAYER_ADDRESS, CUSTOM_GAS_TOKENS } from "../../constants";
7+
import { chainIsOPStack, isDefined } from "../../utils";
88
import { QueryBase } from "./baseQuery";
9-
import { PolygonQueries } from "./polygon";
109
import { DEFAULT_LOGGER, Logger } from "../relayFeeCalculator";
11-
import { AlephZeroQueries } from "./alephZero";
10+
import { CustomGasTokenQueries } from "./customGasToken";
1211

1312
/**
1413
* Some chains have a fixed gas price that is applied to the gas estimates. We should override
@@ -31,30 +30,21 @@ export class QueryBase__factory {
3130
): QueryBase {
3231
assert(isDefined(spokePoolAddress));
3332

34-
if (chainIsMatic(chainId)) {
35-
return new PolygonQueries(
36-
provider,
37-
symbolMapping,
38-
spokePoolAddress,
39-
simulatedRelayerAddress,
40-
logger,
41-
coingeckoProApiKey,
42-
fixedGasPrice[chainId],
43-
"usd"
44-
);
45-
}
46-
47-
if (chainIsAlephZero(chainId)) {
48-
return new AlephZeroQueries(
49-
provider,
50-
symbolMapping,
51-
spokePoolAddress,
52-
simulatedRelayerAddress,
53-
logger,
54-
coingeckoProApiKey,
55-
fixedGasPrice[chainId],
56-
"usd"
57-
);
33+
const customGasTokenSymbol = CUSTOM_GAS_TOKENS[chainId];
34+
if (customGasTokenSymbol) {
35+
return new CustomGasTokenQueries({
36+
queryBaseArgs: [
37+
provider,
38+
symbolMapping,
39+
spokePoolAddress,
40+
simulatedRelayerAddress,
41+
logger,
42+
coingeckoProApiKey,
43+
fixedGasPrice[chainId],
44+
"usd",
45+
],
46+
customGasTokenSymbol,
47+
});
5848
}
5949

6050
// For OPStack chains, we need to wrap the provider in an L2Provider
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from "./baseQuery";
2-
export * from "./polygon";
32
export * from "./factory";
3+
export * from "./customGasToken";

src/relayFeeCalculator/chain-queries/polygon.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/utils/Multicall.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const DETERMINISTIC_MULTICALL_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976C
1919

2020
const NON_DETERMINISTIC_MULTICALL_ADDRESSES = {
2121
[CHAIN_IDs.ZK_SYNC]: "0xF9cda624FBC7e059355ce98a31693d299FACd963",
22+
[CHAIN_IDs.LENS_SEPOLIA]: "0x8A44EDE8a6843a997bC0Cc4659e4dB1Da8f91116",
2223
};
2324

2425
// @notice Multicall3 is an OP stack preinstall, so don't specify it here.

src/utils/NetworkUtils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ export function chainIsOPStack(chainId: number): boolean {
6060
return PUBLIC_NETWORKS[chainId]?.family === ChainFamily.OP_STACK;
6161
}
6262

63+
/**
64+
* Determines whether a chain ID is a ZkStack implementation.
65+
* @param chainId Chain ID to evaluate.
66+
* @returns True if chainId is a ZkStack chain, otherwise false.
67+
*/
68+
export function chainIsZkStack(chainId: number): boolean {
69+
return PUBLIC_NETWORKS[chainId]?.family === ChainFamily.ZK_STACK;
70+
}
71+
6372
/**
6473
* Determines whether a chain ID is an Arbitrum Orbit implementation.
6574
* @param chainId Chain ID to evaluate.
@@ -87,6 +96,15 @@ export function chainIsAlephZero(chainId: number): boolean {
8796
return [CHAIN_IDs.ALEPH_ZERO].includes(chainId);
8897
}
8998

99+
/**
100+
* Determines whether a chain ID is a Lens implementation
101+
* @param chainId Chain ID to evaluate
102+
* @returns True if chainId is a Lens chain, otherwise false.
103+
*/
104+
export function chainIsLens(chainId: number): boolean {
105+
return [CHAIN_IDs.LENS_SEPOLIA].includes(chainId);
106+
}
107+
90108
/**
91109
* Determines whether a chain ID is a Linea implementation.
92110
* @param chainId Chain ID to evaluate.

yarn.lock

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,10 @@
1616
"@uma/common" "^2.17.0"
1717
hardhat "^2.9.3"
1818

19-
"@across-protocol/constants@^3.1.24":
20-
version "3.1.24"
21-
resolved "https://registry.yarnpkg.com/@across-protocol/constants/-/constants-3.1.24.tgz#01fe49330bb467dd01813387ddbac741bc74a035"
22-
integrity sha512-guKtvIbif//vsmSZbwGubTWVtfkWiyWenr2sVyo63U/68GOW89ceJRLu4efLjeLVGiSrNAJtFUCv9dTwrrosWA==
23-
24-
"@across-protocol/constants@^3.1.25":
25-
version "3.1.25"
26-
resolved "https://registry.yarnpkg.com/@across-protocol/constants/-/constants-3.1.25.tgz#60d6d9814582ff91faf2b6d9f51d6dccb447b4ce"
27-
integrity sha512-GpZoYn7hETYL2BPMM2GqXAer6+l/xuhder+pvpb00HJcb/sqCjF7vaaeKxjKJ3jKtyeulYmdu0NDkeNm5KbNWA==
19+
"@across-protocol/constants@^3.1.27":
20+
version "3.1.27"
21+
resolved "https://registry.yarnpkg.com/@across-protocol/constants/-/constants-3.1.27.tgz#6c7b2b277d83ae1024c1de6faf474192391af0bd"
22+
integrity sha512-3YEK2ERB2FVdDdrkFk5YeuRu/oIAHTIeu6YfT39SfZjIPyltP0ReFlDfZQ8c+rFiHurwyK39kjZF70VxRRREYw==
2823

2924
"@across-protocol/contracts@^0.1.4":
3025
version "0.1.4"
@@ -35,12 +30,12 @@
3530
"@openzeppelin/contracts" "4.1.0"
3631
"@uma/core" "^2.18.0"
3732

38-
"@across-protocol/contracts@^3.0.19":
39-
version "3.0.19"
40-
resolved "https://registry.yarnpkg.com/@across-protocol/contracts/-/contracts-3.0.19.tgz#3756504bb3f5f625f9ca403045a79050e675602f"
41-
integrity sha512-9GjKKF8SHGKP9FGhawHzLZ8sfBVFUICd+Bn1pn3SFuh0p+ndQIayG+QEYRKGFUXVPV6+XXLve750PQ1Hu7dIEg==
33+
"@across-protocol/contracts@^3.0.20":
34+
version "3.0.20"
35+
resolved "https://registry.yarnpkg.com/@across-protocol/contracts/-/contracts-3.0.20.tgz#5a70782093d21a96b2e955b7ed725bea7af6e804"
36+
integrity sha512-ufyO+MrbY7+0TDm/1cDl9iAeR4P8jt0AM1F9wiCBHVIYtj1wMD4eNm7G5Am3u8p1ruMjRhi6dJEVQcRF2O+LUg==
4237
dependencies:
43-
"@across-protocol/constants" "^3.1.24"
38+
"@across-protocol/constants" "^3.1.27"
4439
"@coral-xyz/anchor" "^0.30.1"
4540
"@defi-wonderland/smock" "^2.3.4"
4641
"@eth-optimism/contracts" "^0.5.40"

0 commit comments

Comments
 (0)