Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add new cn networks #419

Merged
merged 12 commits into from
Aug 1, 2023
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];
Loading