Skip to content

Commit a879f66

Browse files
authored
feat: misc solana fixes (#1049)
1 parent a2771cd commit a879f66

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@across-protocol/sdk",
33
"author": "UMA Team",
4-
"version": "4.2.0",
4+
"version": "4.2.1",
55
"license": "AGPL-3.0",
66
"homepage": "https://docs.across.to/reference/sdk",
77
"files": [

src/coingecko/Coingecko.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@ export class Coingecko {
7070
private platformIdMap = new Map<number, string>(); // chainId => platform_id (137 => "polygon-pos")
7171
private tokenIdMap: Record<string, Record<string, string>> = {}; // coinGeckoId => { platform_id : "tokenAddress":}
7272

73-
public static get(logger: Logger, apiKey?: string) {
73+
public static get(logger: Logger, apiKey?: string, customPlatformIdMap?: Record<number, string>) {
7474
if (!this.instance)
7575
this.instance = new Coingecko(
7676
"https://api.coingecko.com/api/v3",
7777
"https://pro-api.coingecko.com/api/v3",
7878
logger,
79-
apiKey
79+
apiKey,
80+
customPlatformIdMap
8081
);
8182
return this.instance;
8283
}
@@ -98,7 +99,8 @@ export class Coingecko {
9899
private readonly host: string,
99100
private readonly proHost: string,
100101
private readonly logger: Logger,
101-
private readonly apiKey?: string
102+
private readonly apiKey?: string,
103+
private readonly customPlatformIdMap?: Record<number, string>
102104
) {
103105
this.prices = {};
104106
}
@@ -115,6 +117,13 @@ export class Coingecko {
115117
platforms.filter((chain) => Boolean(chain.chain_identifier)).map((chain) => [chain.chain_identifier, chain.id])
116118
);
117119

120+
// Extend the platformIdMap with any custom platform ids
121+
if (this.customPlatformIdMap) {
122+
Object.entries(this.customPlatformIdMap).forEach(([chainId, platformId]) => {
123+
this.platformIdMap.set(Number(chainId), platformId);
124+
});
125+
}
126+
118127
id = this.platformIdMap.get(chainId);
119128
if (!id) {
120129
this.logger.error({

src/gasPriceOracle/adapters/solana.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ export async function messageFee(provider: SVMProvider, opts: GasPriceEstimateOp
3434

3535
// Optionally impose a minimum priority fee, denoted in microLamports/computeUnit.
3636
const flooredPriorityFeePerGas = parseUnits(process.env[`MIN_PRIORITY_FEE_PER_GAS_${opts.chainId}`] || "0", 6);
37-
let microLamportsPerComputeUnit = toBN(totalPrioritizationFees / BigInt(nonzeroPrioritizationFees.length));
37+
let microLamportsPerComputeUnit = toBN(
38+
totalPrioritizationFees / BigInt(Math.max(nonzeroPrioritizationFees.length, 1))
39+
);
3840
if (microLamportsPerComputeUnit.lt(flooredPriorityFeePerGas)) {
3941
microLamportsPerComputeUnit = flooredPriorityFeePerGas;
4042
}

src/utils/TokenUtils.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import * as constants from "../constants";
44
import { L1Token } from "../interfaces";
55
import { ERC20__factory } from "../typechain";
66
import { BigNumber } from "./BigNumberUtils";
7-
import { getNetworkName, chainIsL1, chainIsProd } from "./NetworkUtils";
7+
import { getNetworkName, chainIsL1, chainIsProd, chainIsSvm } from "./NetworkUtils";
88
import { isDefined } from "./TypeGuards";
9-
import { compareAddressesSimple } from "./AddressUtils";
9+
import { compareAddressesSimple, toAddressType } from "./AddressUtils";
1010
const { TOKEN_SYMBOLS_MAP, CHAIN_IDs, TOKEN_EQUIVALENCE_REMAPPING } = constants;
1111

1212
type SignerOrProvider = providers.Provider | Signer;
@@ -112,9 +112,12 @@ export function isStablecoin(tokenSymbol: string): boolean {
112112
* @returns
113113
*/
114114
export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMapping = TOKEN_SYMBOLS_MAP): L1Token {
115+
const parsedAddress = chainIsSvm(chainId)
116+
? toAddressType(l2TokenAddress).toBase58()
117+
: toAddressType(l2TokenAddress).toEvmAddress();
115118
// @dev This might give false positives if tokens on different networks have the same address. I'm not sure how
116119
// to get around this...
117-
let tokenObject = Object.values(tokenMapping).find(({ addresses }) => addresses[chainId] === l2TokenAddress);
120+
let tokenObject = Object.values(tokenMapping).find(({ addresses }) => addresses[chainId] === parsedAddress);
118121
if (!tokenObject) {
119122
throw new Error(
120123
`TokenUtils#getTokenInfo: Unable to resolve token in TOKEN_SYMBOLS_MAP for ${l2TokenAddress} on chain ${chainId}`

0 commit comments

Comments
 (0)