Skip to content

Commit

Permalink
Add testnets and providers (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
axtezy authored Aug 28, 2023
2 parents aae70d0 + 15922a3 commit bfe0374
Show file tree
Hide file tree
Showing 74 changed files with 1,757 additions and 462 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.18.0",
"version": "4.19.0",
"description": "Simplify dApp creation",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
45 changes: 44 additions & 1 deletion src/common/tokens/constants/native-tokens.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,59 @@
import { Token } from 'src/common/tokens/token';
import { BLOCKCHAIN_NAME, BlockchainName } from 'src/core/blockchain/models/blockchain-name';
import {
BLOCKCHAIN_NAME,
BlockchainName,
TestnetEvmBlockchain
} from 'src/core/blockchain/models/blockchain-name';
import { BitcoinWeb3Pure } from 'src/core/blockchain/web3-pure/typed-web3-pure/bitcoin-web3-pure';
import { EvmWeb3Pure } from 'src/core/blockchain/web3-pure/typed-web3-pure/evm-web3-pure/evm-web3-pure';
import { IcpWeb3Pure } from 'src/core/blockchain/web3-pure/typed-web3-pure/icp-web3-pure';
import { KavaCosmosWeb3Pure } from 'src/core/blockchain/web3-pure/typed-web3-pure/non-evm-web3-pure/kava-cosmos-web3-pure';
import { TronWeb3Pure } from 'src/core/blockchain/web3-pure/typed-web3-pure/tron-web3-pure/tron-web3-pure';

const testnetNativeTokens: Record<TestnetEvmBlockchain, Token> = {
[BLOCKCHAIN_NAME.FUJI]: new Token({
blockchain: BLOCKCHAIN_NAME.FUJI,
address: EvmWeb3Pure.nativeTokenAddress,
name: 'AVAX',
symbol: 'AVAX',
decimals: 18
}),
[BLOCKCHAIN_NAME.MUMBAI]: new Token({
blockchain: BLOCKCHAIN_NAME.MUMBAI,
address: EvmWeb3Pure.nativeTokenAddress,
name: 'Matic Network',
symbol: 'MATIC',
decimals: 18
}),
[BLOCKCHAIN_NAME.GOERLI]: new Token({
blockchain: BLOCKCHAIN_NAME.GOERLI,
address: EvmWeb3Pure.nativeTokenAddress,
name: 'Ethereum',
symbol: 'ETH',
decimals: 18
}),
[BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN_TESTNET]: new Token({
blockchain: BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN_TESTNET,
address: EvmWeb3Pure.nativeTokenAddress,
name: 'Test Binance Coin',
symbol: 'tBNB',
decimals: 18
}),
[BLOCKCHAIN_NAME.SCROLL_SEPOLIA]: new Token({
blockchain: BLOCKCHAIN_NAME.SCROLL_SEPOLIA,
address: EvmWeb3Pure.nativeTokenAddress,
name: 'ETH',
symbol: 'ETH',
decimals: 18
})
};

export const nativeTokensList: Record<BlockchainName, Token> = {
...Object.values(BLOCKCHAIN_NAME).reduce(
(acc, blockchain) => ({ ...acc, [blockchain]: blockchain }),
{} as Record<BlockchainName, Token>
),
...testnetNativeTokens,
[BLOCKCHAIN_NAME.ETHEREUM]: new Token({
blockchain: BLOCKCHAIN_NAME.ETHEREUM,
address: EvmWeb3Pure.nativeTokenAddress,
Expand Down
5 changes: 4 additions & 1 deletion src/common/tokens/constants/wrapped-addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ export const wrappedAddress: Partial<Record<EvmBlockchainName, string>> = {
[BLOCKCHAIN_NAME.PULSECHAIN]: '0xa1077a294dde1b09bb078844df40758a5d0f9a27',
[BLOCKCHAIN_NAME.LINEA]: '0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f',
[BLOCKCHAIN_NAME.BASE]: '0x4200000000000000000000000000000000000006',
[BLOCKCHAIN_NAME.MANTLE]: '0x78c1b0C915c4FAA5FffA6CAbf0219DA63d7f4cb8'
[BLOCKCHAIN_NAME.MANTLE]: '0x78c1b0C915c4FAA5FffA6CAbf0219DA63d7f4cb8',
// Testnet
[BLOCKCHAIN_NAME.GOERLI]: '0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6',
[BLOCKCHAIN_NAME.SCROLL_SEPOLIA]: '0x5300000000000000000000000000000000000004'
};
70 changes: 70 additions & 0 deletions src/common/tokens/constants/wrapped-native-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,5 +254,75 @@ export const wrappedNativeTokensList: Partial<Record<EvmBlockchainName, Token>>
name: 'Wrapped Mantle',
symbol: 'WMNT',
decimals: 18
}),
[BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN_TESTNET]: new Token({
blockchain: BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN_TESTNET,
address: '0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6',
name: 'Wrapped Ether',
symbol: 'WETH',
decimals: 18
}),
[BLOCKCHAIN_NAME.MUMBAI]: new Token({
blockchain: BLOCKCHAIN_NAME.MUMBAI,
address: '0x9c3c9283d3e44854697cd22d3faa240cfb032889',
name: 'Wrapped Matic',
symbol: 'WMATIC',
decimals: 18
}),
[BLOCKCHAIN_NAME.FUJI]: new Token({
blockchain: BLOCKCHAIN_NAME.FUJI,
address: '0x1d308089a2d1ced3f1ce36b1fcaf815b07217be3',
name: 'Wrapped Avax',
symbol: 'WAVAX',
decimals: 18
}),
[BLOCKCHAIN_NAME.GOERLI]: new Token({
blockchain: BLOCKCHAIN_NAME.GOERLI,
address: '0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6',
name: 'Wrapped Ether',
symbol: 'WETH',
decimals: 18
}),
[BLOCKCHAIN_NAME.SCROLL_SEPOLIA]: new Token({
blockchain: BLOCKCHAIN_NAME.SCROLL_SEPOLIA,
address: '0x5300000000000000000000000000000000000004',
name: 'Wrapped Ether',
symbol: 'WETH',
decimals: 18
}),
[BLOCKCHAIN_NAME.ETHEREUM_CLASSIC]: new Token({
blockchain: BLOCKCHAIN_NAME.ETHEREUM_CLASSIC,
address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
name: 'Wrapped Ether',
symbol: 'WETH',
decimals: 18
}),
[BLOCKCHAIN_NAME.FLARE]: new Token({
blockchain: BLOCKCHAIN_NAME.FLARE,
address: '0x1D80c49BbBCd1C0911346656B529DF9E5c2F783d',
name: 'Wrapper Flare',
symbol: 'WFLR',
decimals: 18
}),
[BLOCKCHAIN_NAME.IOTEX]: new Token({
blockchain: BLOCKCHAIN_NAME.IOTEX,
address: '0xa00744882684c3e4747faefd68d283ea44099d03',
name: 'Wrapped IoTeX',
symbol: 'WIOTX',
decimals: 18
}),
[BLOCKCHAIN_NAME.THETA]: new Token({
blockchain: BLOCKCHAIN_NAME.THETA,
address: '0xaf537fb7e4c77c97403de94ce141b7edb9f7fcf0',
name: 'Wrapped Theta',
symbol: 'wTHETA',
decimals: 18
}),
[BLOCKCHAIN_NAME.BITCOIN_CASH]: new Token({
blockchain: BLOCKCHAIN_NAME.BITCOIN_CASH,
address: '0x3743eC0673453E5009310C727Ba4eaF7b3a1cc04',
name: 'Wrapped BCH',
symbol: 'WBCH',
decimals: 18
})
};
11 changes: 11 additions & 0 deletions src/core/blockchain/models/blockchain-name.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
export const TEST_EVM_BLOCKCHAIN_NAME = {
MUMBAI: 'MUMBAI',
BINANCE_SMART_CHAIN_TESTNET: 'BSCT',
GOERLI: 'GOERLI',
FUJI: 'FUJI',
SCROLL_SEPOLIA: 'SCROLL_SEPOLIA'
} as const;

export const EVM_BLOCKCHAIN_NAME = {
...TEST_EVM_BLOCKCHAIN_NAME,
ETHEREUM: 'ETH',
BINANCE_SMART_CHAIN: 'BSC',
POLYGON: 'POLYGON',
Expand Down Expand Up @@ -124,6 +133,8 @@ export const BLOCKCHAIN_NAME = {

export type BlockchainName = (typeof BLOCKCHAIN_NAME)[keyof typeof BLOCKCHAIN_NAME];

export type TestnetEvmBlockchain =
(typeof TEST_EVM_BLOCKCHAIN_NAME)[keyof typeof TEST_EVM_BLOCKCHAIN_NAME];
export type EvmBlockchainName = (typeof EVM_BLOCKCHAIN_NAME)[keyof typeof EVM_BLOCKCHAIN_NAME];
export type SolanaBlockchainName = typeof BLOCKCHAIN_NAME.SOLANA;
export type NearBlockchainName = typeof BLOCKCHAIN_NAME.NEAR;
Expand Down
10 changes: 10 additions & 0 deletions src/core/blockchain/utils/blockchains-info/blockchains-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
BlockchainName,
EVM_BLOCKCHAIN_NAME,
EvmBlockchainName,
TEST_EVM_BLOCKCHAIN_NAME,
TestnetEvmBlockchain,
TronBlockchainName
} from 'src/core/blockchain/models/blockchain-name';
import { ChainType } from 'src/core/blockchain/models/chain-type';
Expand Down Expand Up @@ -47,6 +49,14 @@ export class BlockchainsInfo {
);
}

public static isTestBlockchainName(
blockchainName: BlockchainName
): blockchainName is TestnetEvmBlockchain {
return Object.values(TEST_EVM_BLOCKCHAIN_NAME).some(
testBlockchainName => testBlockchainName === blockchainName
);
}

public static isBitcoinBlockchainName(
blockchainName: BlockchainName
): blockchainName is BitcoinBlockchainName {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ export const blockchainId: Record<BlockchainName, number> = {
[BLOCKCHAIN_NAME.LINEA]: 59144,
[BLOCKCHAIN_NAME.BASE]: 8453,
[BLOCKCHAIN_NAME.MANTLE]: 5000,
// Tesnents
[BLOCKCHAIN_NAME.GOERLI]: 5,
[BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN_TESTNET]: 87,
[BLOCKCHAIN_NAME.MUMBAI]: 80001,
[BLOCKCHAIN_NAME.FUJI]: 43113,
[BLOCKCHAIN_NAME.SCROLL_SEPOLIA]: 534351,
// Non EVN blockchains
[BLOCKCHAIN_NAME.BITCOIN]: 5555,
[BLOCKCHAIN_NAME.FILECOIN]: 314
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@ export const MULTICALL_ADDRESSES: Record<Web3PublicSupportedBlockchain, string>
[BLOCKCHAIN_NAME.POLYGON_ZKEVM]: '0xca11bde05977b3631167028862be2a173976ca11',
[BLOCKCHAIN_NAME.LINEA]: '0xcA11bde05977b3631167028862bE2a173976CA11',
[BLOCKCHAIN_NAME.BASE]: '0xcA11bde05977b3631167028862bE2a173976CA11',
[BLOCKCHAIN_NAME.MANTLE]: '0xcA11bde05977b3631167028862bE2a173976CA11'
[BLOCKCHAIN_NAME.MANTLE]: '0xcA11bde05977b3631167028862bE2a173976CA11',
[BLOCKCHAIN_NAME.SCROLL_SEPOLIA]: '0xcA11bde05977b3631167028862bE2a173976CA11',
[BLOCKCHAIN_NAME.GOERLI]: '0x5ba1e12693dc8f9c48aad8770482f4739beed696'
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CbridgeCrossChainProvider } from 'src/features/cross-chain/calculation-
import { ChangenowCrossChainProvider } from 'src/features/cross-chain/calculation-manager/providers/changenow-provider/changenow-cross-chain-provider';
import { DebridgeCrossChainProvider } from 'src/features/cross-chain/calculation-manager/providers/debridge-provider/debridge-cross-chain-provider';
import { LifiCrossChainProvider } from 'src/features/cross-chain/calculation-manager/providers/lifi-provider/lifi-cross-chain-provider';
import { ScrollBridgeProvider } from 'src/features/cross-chain/calculation-manager/providers/scroll-bridge/scroll-bridge-provider';
import { SquidrouterCrossChainProvider } from 'src/features/cross-chain/calculation-manager/providers/squidrouter-provider/squidrouter-cross-chain-provider';
import { SymbiosisCrossChainProvider } from 'src/features/cross-chain/calculation-manager/providers/symbiosis-provider/symbiosis-cross-chain-provider';
import { XyCrossChainProvider } from 'src/features/cross-chain/calculation-manager/providers/xy-provider/xy-cross-chain-provider';
Expand All @@ -23,7 +24,8 @@ const nonProxyProviders = [
DebridgeCrossChainProvider,
BridgersCrossChainProvider,
ChangenowCrossChainProvider,
ArbitrumRbcBridgeProvider
ArbitrumRbcBridgeProvider,
ScrollBridgeProvider
] as const;

export const CrossChainProviders = [...proxyProviders, ...nonProxyProviders] as const;
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export const defaultCrossChainCalculationOptions: Omit<
timeout: 25_000,
slippageTolerance: 0.04,
deadline: 20,
changenowFullyEnabled: false
changenowFullyEnabled: false,
enableTestnets: false
};
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ export interface CrossChainOptions {
changenowFullyEnabled?: boolean;

useProxy?: Record<CrossChainTradeType, boolean>;

/**
* True if test networks are enabled.
*/
enableTestnets?: boolean;
}

export type RequiredCrossChainOptions = MarkRequired<
Expand All @@ -72,4 +77,5 @@ export type RequiredCrossChainOptions = MarkRequired<
| 'providerAddress'
| 'timeout'
| 'changenowFullyEnabled'
| 'enableTestnets'
>;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export const CROSS_CHAIN_TRADE_TYPE = {
CHANGENOW: 'changenow',
STARGATE: 'stargate',
ARBITRUM: 'arbitrum',
SQUIDROUTER: 'squidrouter'
SQUIDROUTER: 'squidrouter',
SCROLL_BRIDGE: 'scroll_bridge'
} as const;

export type CrossChainTradeType =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,64 @@
// @ts-ignore
import { getRequestOptions } from 'cbridge-revert-manager';
import { Injector } from 'src/core/injector/injector';
import { CbridgeEstimateAmountRequest } from 'src/features/cross-chain/calculation-manager/providers/cbridge/models/cbridge-estimate-amount-request';
import { CbridgeEstimateAmountResponse } from 'src/features/cross-chain/calculation-manager/providers/cbridge/models/cbridge-estimate-amount-response';
import { CbridgeStatusResponse } from 'src/features/cross-chain/calculation-manager/providers/cbridge/models/cbridge-status-response';
import { CbridgeTransferConfigsResponse } from 'src/features/cross-chain/calculation-manager/providers/cbridge/models/cbridge-transfer-configs-response';

export class CbridgeCrossChainApiService {
public static readonly apiEndpoint = 'https://cbridge-prod2.celer.app/v2/';
private static readonly apiEndpoint = 'https://cbridge-prod2.celer.app/v2/';

public static async getTransferConfigs(): Promise<CbridgeTransferConfigsResponse> {
private static readonly testnetApiEndpoint = 'https://cbridge-v2-test.celer.network/v2/';

public static async getTransferConfigs(options: {
useTestnet: boolean;
}): Promise<CbridgeTransferConfigsResponse> {
const apiUrl = options.useTestnet
? CbridgeCrossChainApiService.testnetApiEndpoint
: CbridgeCrossChainApiService.apiEndpoint;
return Injector.httpClient.get<CbridgeTransferConfigsResponse>(
`${CbridgeCrossChainApiService.apiEndpoint}getTransferConfigs`
`${apiUrl}getTransferConfigs`
);
}

public static async fetchEstimateAmount(
requestParams: CbridgeEstimateAmountRequest
requestParams: CbridgeEstimateAmountRequest,
options: { useTestnet: boolean }
): Promise<CbridgeEstimateAmountResponse> {
return Injector.httpClient.get<CbridgeEstimateAmountResponse>(
`${CbridgeCrossChainApiService.apiEndpoint}estimateAmt`,
{ params: { ...requestParams } }
);
const apiUrl = options.useTestnet
? CbridgeCrossChainApiService.testnetApiEndpoint
: CbridgeCrossChainApiService.apiEndpoint;
return Injector.httpClient.get<CbridgeEstimateAmountResponse>(`${apiUrl}estimateAmt`, {
params: { ...requestParams }
});
}

public static async fetchTradeStatus(transferId: string): Promise<CbridgeStatusResponse> {
return Injector.httpClient.post<CbridgeStatusResponse>(
`${CbridgeCrossChainApiService.apiEndpoint}getTransferStatus`,
{ transfer_id: transferId }
);
public static async fetchTradeStatus(
transferId: string,
options: {
useTestnet: boolean;
}
): Promise<CbridgeStatusResponse> {
const apiUrl = options.useTestnet
? CbridgeCrossChainApiService.testnetApiEndpoint
: CbridgeCrossChainApiService.apiEndpoint;
return Injector.httpClient.post<CbridgeStatusResponse>(`${apiUrl}getTransferStatus`, {
transfer_id: transferId
});
}

public static async withdrawLiquidity(
transferId: string,
estimatedReceivedAmt: string,
options: {
useTestnet: boolean;
}
): Promise<void> {
const apiUrl = options.useTestnet
? CbridgeCrossChainApiService.testnetApiEndpoint
: CbridgeCrossChainApiService.apiEndpoint;
const body: object = await getRequestOptions(transferId, estimatedReceivedAmt);
return Injector.httpClient.post(`${apiUrl}withdrawLiquidity`, body);
}
}
Loading

0 comments on commit bfe0374

Please sign in to comment.