Skip to content

Commit

Permalink
(feat) openocean add bsc,cronos,arbitrum and optimism chains
Browse files Browse the repository at this point in the history
  • Loading branch information
kanghoulin committed Mar 27, 2023
1 parent 54e4871 commit 842a1ca
Show file tree
Hide file tree
Showing 8 changed files with 1,448 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/chains/binance-smart-chain/binance-smart-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Ethereumish } from '../../services/common-interfaces';
import { PancakeSwapConfig } from '../../connectors/pancakeswap/pancakeswap.config';
import { SushiswapConfig } from '../../connectors/sushiswap/sushiswap.config';
import { ConfigManagerV2 } from '../../services/config-manager-v2';
import { OpenoceanConfig } from '../../connectors/openocean/openocean.config';

export class BinanceSmartChain extends EthereumBase implements Ethereumish {
private static _instances: { [name: string]: BinanceSmartChain };
Expand Down Expand Up @@ -100,6 +101,8 @@ export class BinanceSmartChain extends EthereumBase implements Ethereumish {
'binance-smart-chain',
this._chain
);
} else if (reqSpender === 'openocean') {
spender = OpenoceanConfig.config.routerAddress('binance-smart-chain', this._chain);
} else {
spender = reqSpender;
}
Expand Down
3 changes: 3 additions & 0 deletions src/chains/cronos/cronos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Ethereumish } from '../../services/common-interfaces';
import { MadMeerkatConfig } from '../../connectors/mad_meerkat/mad_meerkat.config';
import { VVSConfig } from '../../connectors/vvs/vvs.config';
import { ConfigManagerV2 } from '../../services/config-manager-v2';
import { OpenoceanConfig } from '../../connectors/openocean/openocean.config';

export class Cronos extends EthereumBase implements Ethereumish {
private static _instances: { [name: string]: Cronos };
Expand Down Expand Up @@ -98,6 +99,8 @@ export class Cronos extends EthereumBase implements Ethereumish {
spender = MadMeerkatConfig.config.routerAddress(this._chain);
} else if (reqSpender == 'vvs') {
spender = VVSConfig.config.routerAddress(this._chain);
} else if (reqSpender === 'openocean') {
spender = OpenoceanConfig.config.routerAddress('cronos', this._chain);
} else {
spender = reqSpender;
}
Expand Down
4 changes: 3 additions & 1 deletion src/connectors/openocean/openocean.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ export namespace OpenoceanConfig {
tradingTypes: ['EVM_AMM'],
availableNetworks: [
{ chain: 'avalanche', networks: ['avalanche'] },
{ chain: 'ethereum', networks: ['mainnet'] },
{ chain: 'ethereum', networks: ['mainnet', 'arbitrum_one', 'optimism'] },
{ chain: 'polygon', networks: ['mainnet'] },
{ chain: 'harmony', networks: ['mainnet'] },
{ chain: 'binance-smart-chain', networks: ['mainnet'] },
{ chain: 'cronos', networks: ['mainnet'] },
],
};
}
27 changes: 22 additions & 5 deletions src/connectors/openocean/openocean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { Avalanche } from '../../chains/avalanche/avalanche';
import { Ethereum } from '../../chains/ethereum/ethereum';
import { Polygon } from '../../chains/polygon/polygon';
import { Harmony } from '../../chains/harmony/harmony';
import { BinanceSmartChain } from '../../chains/binance-smart-chain/binance-smart-chain';
import { Cronos } from '../../chains/cronos/cronos';
import { ExpectedTrade, Uniswapish } from '../../services/common-interfaces';
import {
HttpException,
Expand Down Expand Up @@ -53,6 +55,7 @@ export class Openocean implements Uniswapish {
private static _instances: { [name: string]: Openocean };
private chainInstance;
private _chain: string;
private _network: string;
private _router: string;
private _gasLimitEstimate: number;
private _ttl: number;
Expand All @@ -62,6 +65,7 @@ export class Openocean implements Uniswapish {

private constructor(chain: string, network: string) {
this._chain = chain;
this._network = network;
const config = OpenoceanConfig.config;
this.chainInstance = this.getChainInstance(network);
this.chainId = this.chainInstance.chainId;
Expand Down Expand Up @@ -90,6 +94,10 @@ export class Openocean implements Uniswapish {
return Polygon.getInstance(network);
} else if (this._chain === 'harmony') {
return Harmony.getInstance(network);
} else if (this._chain === 'binance-smart-chain') {
return BinanceSmartChain.getInstance(network);
} else if (this._chain === 'cronos') {
return Cronos.getInstance(network);
} else {
throw new Error('unsupported chain');
}
Expand Down Expand Up @@ -154,15 +162,24 @@ export class Openocean implements Uniswapish {
}

public get chainName(): string {
if (this._chain === 'ethereum') {
if (this._chain === 'ethereum' && this._network === 'mainnet') {
return 'eth';
} else if (this._chain === 'ethereum' && this._network === 'arbitrum_one') {
return 'arbitrum';
} else if (this._chain === 'ethereum' && this._network === 'optimism') {
return 'optimism';
} else if (this._chain === 'avalanche') {
return 'avax';
} else if (this._chain === 'polygon') {
return 'polygon';
} else if (this._chain === 'harmony') {
return 'harmony';
} else if (this._chain === 'binance-smart-chain') {
return 'bsc';
}
// else if (this._chain === 'polygon') {
// return 'polygon';
// } else if (this._chain === 'harmony') {
// return 'harmony';
// } else if (this._chain === 'cronos') {
// return 'cronos';
// }
return this._chain;
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/schema/openocean-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"contractAddresses": {
"type": "object",
"patternProperties": {
"^\\w+$": {
"[\\w-]+$": {
"type": "object",
"patternProperties": {
"^\\w+$": {
Expand Down
6 changes: 6 additions & 0 deletions src/templates/openocean.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ contractAddresses:
harmony:
mainnet:
routerAddress: '0x6352a56caadC4F1E25CD6c75970Fa768A3304e64'
binance-smart-chain:
mainnet:
routerAddress: '0x6352a56caadC4F1E25CD6c75970Fa768A3304e64'
cronos:
mainnet:
routerAddress: '0x6352a56caadC4F1E25CD6c75970Fa768A3304e64'
Loading

0 comments on commit 842a1ca

Please sign in to comment.