Skip to content

Commit

Permalink
Feature/add new cn networks (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
Doctor-Cyclone authored Aug 1, 2023
2 parents 2815f33 + c3d7bb2 commit 53fe4a0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rubic-sdk",
"version": "4.13.3",
"version": "4.14.0",
"description": "Simplify dApp creation",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import {
changenowApiBlockchain,
ChangenowCrossChainSupportedBlockchain
} from 'src/features/cross-chain/calculation-manager/providers/changenow-provider/constants/changenow-api-blockchain';
import {
ChangenowProxySupportedBlockchain,
changenowProxySupportedBlockchains
} from 'src/features/cross-chain/calculation-manager/providers/changenow-provider/constants/changenow-proxy-supported-blockchains';
import { nativeTokensData } from 'src/features/cross-chain/calculation-manager/providers/changenow-provider/constants/native-addresses';
import {
ChangenowCurrenciesResponse,
Expand All @@ -47,6 +51,14 @@ export class ChangenowCrossChainProvider extends CrossChainProvider {
return Object.keys(changenowApiBlockchain).includes(blockchain);
}

public isSupportedProxyBlockchain(
blockchain: BlockchainName
): blockchain is ChangenowProxySupportedBlockchain {
return changenowProxySupportedBlockchains.some(
supportedBlockchain => supportedBlockchain === blockchain
);
}

// eslint-disable-next-line complexity
public async calculate(
from: PriceTokenAmount,
Expand All @@ -55,11 +67,10 @@ export class ChangenowCrossChainProvider extends CrossChainProvider {
): Promise<CalculationResult> {
const fromBlockchain = from.blockchain;
const toBlockchain = toToken.blockchain;
// let useProxy = options?.useProxy?.[this.type] ?? true;

const useProxy =
(options?.useProxy?.[this.type] &&
fromBlockchain === BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN) ||
false;
this.isSupportedProxyBlockchain(fromBlockchain) &&
(options?.useProxy?.[this.type] || false);

if (
!this.areSupportedBlockchains(fromBlockchain, toBlockchain) ||
Expand Down Expand Up @@ -144,7 +155,7 @@ export class ChangenowCrossChainProvider extends CrossChainProvider {
const changenowTrade: ChangenowTrade = {
from: from as PriceTokenAmount<ChangenowCrossChainSupportedBlockchain>,
to,
toTokenAmountMin: transitMinAmount,
toTokenAmountMin: toAmount,
fromCurrency: transit,
toCurrency,
feeInfo,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { BLOCKCHAIN_NAME } from 'src/core/blockchain/models/blockchain-name';

export const changenowProxySupportedBlockchains = [
BLOCKCHAIN_NAME.ETHEREUM,
BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN,
BLOCKCHAIN_NAME.POLYGON,
BLOCKCHAIN_NAME.ARBITRUM,
BLOCKCHAIN_NAME.AVALANCHE,
BLOCKCHAIN_NAME.OPTIMISM,
BLOCKCHAIN_NAME.FANTOM,
BLOCKCHAIN_NAME.PULSECHAIN
] as const;

export type ChangenowProxySupportedBlockchain = (typeof changenowProxySupportedBlockchains)[number];

0 comments on commit 53fe4a0

Please sign in to comment.