Skip to content

Commit

Permalink
Merge pull request #299 from isreallee82/feat/pancakeswap_mainnet_chain
Browse files Browse the repository at this point in the history
(feat) pancakeswap mainnet
  • Loading branch information
rapcmia authored Apr 15, 2024
2 parents 0fe8449 + e7e3146 commit 343793c
Show file tree
Hide file tree
Showing 9 changed files with 499 additions and 157 deletions.
27 changes: 17 additions & 10 deletions src/chains/ethereum/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { logger } from '../../services/logger';
import { BigNumber, Contract, Transaction, Wallet } from 'ethers';
import { EthereumBase } from './ethereum-base';
import { getEthereumConfig } from './ethereum.config';
import { PancakeSwapConfig } from '../../connectors/pancakeswap/pancakeswap.config';
import { Provider } from '@ethersproject/abstract-provider';
import { ConfigManagerV2 } from '../../services/config-manager-v2';
// import { throttleRetryWrapper } from '../../services/retry';
Expand Down Expand Up @@ -48,7 +49,7 @@ export class Ethereum extends EthereumBase implements Ethereumish {
config.manualGasPrice,
config.gasLimitTransaction,
ConfigManagerV2.getInstance().get('server.nonceDbPath'),
ConfigManagerV2.getInstance().get('server.transactionDbPath')
ConfigManagerV2.getInstance().get('server.transactionDbPath'),
);
this._chain = network;
this._nativeTokenSymbol = config.nativeCurrencySymbol;
Expand All @@ -66,7 +67,7 @@ export class Ethereum extends EthereumBase implements Ethereumish {
this.onDebugMessage(this.requestCounter.bind(this));
this._metricTimer = setInterval(
this.metricLogger.bind(this),
this.metricsLogInterval
this.metricsLogInterval,
);
this.controller = EVMController;
}
Expand Down Expand Up @@ -95,7 +96,7 @@ export class Ethereum extends EthereumBase implements Ethereumish {
this.requestCount +
' request(s) sent in last ' +
this.metricsLogInterval / 1000 +
' seconds.'
' seconds.',
);
this._requestCount = 0; // reset
}
Expand Down Expand Up @@ -146,7 +147,7 @@ export class Ethereum extends EthereumBase implements Ethereumish {

setTimeout(
this.updateGasPrice.bind(this),
this._gasPriceRefreshInterval * 1000
this._gasPriceRefreshInterval * 1000,
);
}

Expand All @@ -159,15 +160,15 @@ export class Ethereum extends EthereumBase implements Ethereumish {
let priorityFee: BigNumber = BigNumber.from('0');
if (this._chain === 'mainnet') {
priorityFee = BigNumber.from(
await this.provider.send('eth_maxPriorityFeePerGas', [])
await this.provider.send('eth_maxPriorityFeePerGas', []),
);
}
return baseFee.add(priorityFee).toNumber() * 1e-9;
}

getContract(
tokenAddress: string,
signerOrProvider?: Wallet | Provider
signerOrProvider?: Wallet | Provider,
): Contract {
return tokenAddress === MKR_ADDRESS
? new Contract(tokenAddress, abi.MKRAbi, signerOrProvider)
Expand All @@ -180,19 +181,25 @@ export class Ethereum extends EthereumBase implements Ethereumish {
let spender: string;
if (reqSpender === 'uniswap') {
spender = UniswapConfig.config.uniswapV3SmartOrderRouterAddress(
this._chain
this._chain,
);
} else if (reqSpender === 'pancakeswap') {
spender = PancakeSwapConfig.config.routerAddress(this._chain);
} else if (reqSpender === 'pancakeswapLP') {
spender = PancakeSwapConfig.config.pancakeswapV3NftManagerAddress(
this._chain,
);
} else if (reqSpender === 'sushiswap') {
spender = SushiswapConfig.config.sushiswapRouterAddress(
this.chainName,
this._chain
this._chain,
);
} else if (reqSpender === 'uniswapLP') {
spender = UniswapConfig.config.uniswapV3NftManagerAddress(this._chain);
} else if (reqSpender === 'carbonamm') {
spender = CarbonConfig.config.carbonContractsConfig(
'ethereum',
this._chain
this._chain,
).carbonControllerAddress;
} else if (reqSpender === 'perp') {
const perp = Perp.getInstance(this._chain, 'optimism');
Expand All @@ -219,7 +226,7 @@ export class Ethereum extends EthereumBase implements Ethereumish {
// cancel transaction
async cancelTx(wallet: Wallet, nonce: number): Promise<Transaction> {
logger.info(
'Canceling any existing transaction(s) with nonce number ' + nonce + '.'
'Canceling any existing transaction(s) with nonce number ' + nonce + '.',
);
return this.cancelTxWithGasPrice(wallet, nonce, this._gasPrice * 2);
}
Expand Down
11 changes: 7 additions & 4 deletions src/connectors/pancakeswap/pancakeswap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ export namespace PancakeSwapConfig {
export const v2Config: V2NetworkConfig = buildConfig(
'pancakeswap',
['AMM'],
[{ chain: 'binance-smart-chain', networks: ['mainnet', 'testnet'] }],
'EVM'
[
{ chain: 'binance-smart-chain', networks: ['mainnet', 'testnet'] },
{ chain: 'ethereum', networks: ['mainnet', 'arbitrum', 'zksync'] },
],
'EVM',
);

export const config: NetworkConfig = {
Expand All @@ -27,11 +30,11 @@ export namespace PancakeSwapConfig {
maximumHops: ConfigManagerV2.getInstance().get(`pancakeswap.maximumHops`),
pancakeswapV3SmartOrderRouterAddress: (network: string) =>
ConfigManagerV2.getInstance().get(
`pancakeswap.contractAddresses.${network}.pancakeswapV3SmartOrderRouterAddress`
`pancakeswap.contractAddresses.${network}.pancakeswapV3SmartOrderRouterAddress`,
),
pancakeswapV3NftManagerAddress: (network: string) =>
ConfigManagerV2.getInstance().get(
`pancakeswap.contractAddresses.${network}.pancakeswapV3NftManagerAddress`
`pancakeswap.contractAddresses.${network}.pancakeswapV3NftManagerAddress`,
),
tradingTypes: (type: string) => {
return type === 'swap' ? ['AMM'] : ['AMM_LP'];
Expand Down
Loading

0 comments on commit 343793c

Please sign in to comment.