Skip to content

Commit

Permalink
Merge branch 'master' into leverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Macket authored Apr 26, 2024
2 parents 8c3f7a6 + 2998781 commit 9c96da8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/external-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const _getAllPoolsFromApi = async (network: INetworkName): Promise<IExten
_getPoolsFromApi(network, "factory"),
_getPoolsFromApi(network, "factory-crvusd"),
_getPoolsFromApi(network, "factory-crypto"),
_getPoolsFromApi(network, "factory-twocrypto"),
_getPoolsFromApi(network, "factory-tricrypto"),
_getPoolsFromApi(network, "factory-stable-ng"),
]);
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ensureAllowance,
getUsdRate,
getGasPriceFromL2,
getGasInfoForL2,
} from "./utils.js";


Expand Down Expand Up @@ -42,6 +43,7 @@ const lending = {
ensureAllowance,
getUsdRate,
getGasPriceFromL2,
getGasInfoForL2,
oneWayfactory: {
fetchMarkets: _lending.fetchOneWayMarkets,
getMarketList: _lending.getOneWayMarketList,
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface IDict<T> {

export type INetworkName = "ethereum" | "bsc" | "optimism" | "xdai" | "polygon" | "fantom" | "zksync" | "moonbeam" | "kava" | "base" | "arbitrum" | "celo" | "avalanche" | "aurora";
export type IChainId = 1 | 10 | 56 | 100 | 137 | 250 | 324 | 1284 | 2222 | 8453 | 42161 | 42220 | 43114 | 1313161554;
export type IPoolFactory = "main" | "crypto" | "factory" | "factory-crvusd" | "factory-crypto" | "factory-tricrypto" | "factory-stable-ng";
export type IPoolFactory = "main" | "crypto" | "factory" | "factory-crvusd" | "factory-crypto" | "factory-twocrypto" | "factory-tricrypto" | "factory-stable-ng";
export interface ICurveContract {
contract: Contract,
multicallContract: MulticallContract,
Expand Down
4 changes: 2 additions & 2 deletions src/markets/OneWayMarketTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,10 +758,10 @@ export class OneWayMarketTemplate {
}
const tokenInfo = await lending.multicallProvider.all(tokenInfoCalls);
for (let i = 0; i < tokens.length; i++) {
lending.constants.DECIMALS[tokens[i]] = tokenInfo[(i * 2) + 1] as number;
lending.constants.DECIMALS[tokens[i]] = Number(tokenInfo[(i * 2) + 1]);
}

return tokens.map((token, i) => ({ token, symbol: tokenInfo[i * 2] as string, decimals: tokenInfo[(i * 2) + 1] as number }));
return tokens.map((token, i) => ({ token, symbol: tokenInfo[i * 2] as string, decimals: Number(tokenInfo[(i * 2) + 1]) }));
},
{
promise: true,
Expand Down
34 changes: 31 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,38 @@ export const getUsdRate = async (coin: string): Promise<number> => {
return await _getUsdRate(coinAddress);
}

export const getGasPriceFromL2 = (): number => {
export const getBaseFeeByLastBlock = async () => {
const provider = lending.provider;

try {
const block = await provider.getBlock('latest');
if(!block) {
return 0.01
}

return Number(block.baseFeePerGas) / (10**9);
} catch (error: any) {
throw new Error(error)
}
}

export const getGasPriceFromL2 = async (): Promise<number> => {
if(lending.chainId === 42161) {
return 0.01 * 1e9; // constant 0.1 gwei
return await getBaseFeeByLastBlock()
} else {
throw Error("This method exists only for ARBITRUM network");
}
}

export const getGasInfoForL2 = async (): Promise<Record<string, number>> => {
if(lending.chainId === 42161) {
const baseFee = await getBaseFeeByLastBlock()

return {
maxFeePerGas: Number(((baseFee * 1.1) + 0.01).toFixed(2)),
maxPriorityFeePerGas: 0.01,
}
} else {
throw Error("This method exists only for L2 networks");
throw Error("This method exists only for ARBITRUM network");
}
}

0 comments on commit 9c96da8

Please sign in to comment.