Skip to content

Commit

Permalink
Merge branch 'master' into id-802-150
Browse files Browse the repository at this point in the history
  • Loading branch information
IDIDOS authored Dec 28, 2024
2 parents f577430 + b18d273 commit 9ad79a1
Show file tree
Hide file tree
Showing 176 changed files with 2,006 additions and 2,428 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
"analyze": "webpack --profile --json > stats.json && webpack-bundle-analyzer stats.json",
"docs": "yarn create-index && typedoc && yarn delete-index",
"publish": "yarn publish --access public",
"publish:alpha": "yarn publish --access public --tag alpha"
"publish:alpha": "yarn publish --access public --tag alpha",
"test:file": "jest -- __tests__/unit-tests/dedust"
},
"dependencies": {
"@1inch/limit-order-protocol-utils": "3.0.1",
Expand Down
14 changes: 14 additions & 0 deletions src/common/tokens/constants/native-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ const testnetNativeTokens: Record<TestnetEvmBlockchain, Token> = {
name: 'Ether',
symbol: 'ETH',
decimals: 18
}),
[BLOCKCHAIN_NAME.UNICHAIN_SEPOLIA_TESTNET]: new Token({
blockchain: BLOCKCHAIN_NAME.UNICHAIN_SEPOLIA_TESTNET,
address: EvmWeb3Pure.nativeTokenAddress,
name: 'Ether',
symbol: 'ETH',
decimals: 18
})
};

Expand Down Expand Up @@ -692,5 +699,12 @@ export const nativeTokensList: Record<BlockchainName, Token> = {
name: 'ZIL',
symbol: 'ZIL',
decimals: 18
}),
[BLOCKCHAIN_NAME.SONIC]: new Token({
blockchain: BLOCKCHAIN_NAME.SONIC,
address: EvmWeb3Pure.nativeTokenAddress,
name: 'SONIC',
symbol: 'S',
decimals: 18
})
};
4 changes: 3 additions & 1 deletion src/common/tokens/constants/wrapped-addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const wrappedAddress: Partial<Record<EvmBlockchainName, string>> = {
[BLOCKCHAIN_NAME.BAHAMUT]: '0x4084ab20f8ffca76c19aaf854fb5fe9de6217fbb',
[BLOCKCHAIN_NAME.GRAVITY]: '0xBB859E225ac8Fb6BE1C7e38D87b767e95Fef0EbD',
[BLOCKCHAIN_NAME.FLARE]: '0x1d80c49bbbcd1c0911346656b529df9e5c2f783d',
[BLOCKCHAIN_NAME.SONIC]: '0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38',
// Testnet
[BLOCKCHAIN_NAME.GOERLI]: '0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6',
[BLOCKCHAIN_NAME.SCROLL_SEPOLIA]: '0x5300000000000000000000000000000000000004',
Expand All @@ -62,5 +63,6 @@ export const wrappedAddress: Partial<Record<EvmBlockchainName, string>> = {
[BLOCKCHAIN_NAME.BERACHAIN]: '0x7507c1dc16935B82698e4C63f2746A2fCf994dF8',
[BLOCKCHAIN_NAME.BLAST_TESTNET]: '0x4200000000000000000000000000000000000023',
[BLOCKCHAIN_NAME.HOLESKY]: '',
[BLOCKCHAIN_NAME.BITLAYER]: '0xff204e2681a6fa0e2c3fade68a1b28fb90e4fc5f'
[BLOCKCHAIN_NAME.BITLAYER]: '0xff204e2681a6fa0e2c3fade68a1b28fb90e4fc5f',
[BLOCKCHAIN_NAME.UNICHAIN_SEPOLIA_TESTNET]: '0x4200000000000000000000000000000000000006'
};
14 changes: 14 additions & 0 deletions src/common/tokens/constants/wrapped-native-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,5 +478,19 @@ export const wrappedNativeTokensList: Partial<Record<EvmBlockchainName, Token>>
name: 'Wrapped Gravity',
symbol: 'WG',
decimals: 18
}),
[BLOCKCHAIN_NAME.UNICHAIN_SEPOLIA_TESTNET]: new Token({
blockchain: BLOCKCHAIN_NAME.UNICHAIN_SEPOLIA_TESTNET,
address: '0x4200000000000000000000000000000000000006',
name: 'Wrapped Ether',
symbol: 'WETH',
decimals: 18
}),
[BLOCKCHAIN_NAME.SONIC]: new Token({
blockchain: BLOCKCHAIN_NAME.SONIC,
address: '0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38',
name: 'Wrapped Sonic',
symbol: 'WS',
decimals: 18
})
};
4 changes: 3 additions & 1 deletion src/core/blockchain/models/backend-blockchains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ const BLOCKCHAINS_MAPPING = {
[BLOCKCHAIN_NAME.CORE]: 'core',
[BLOCKCHAIN_NAME.BAHAMUT]: 'bahamut',
[BLOCKCHAIN_NAME.BITLAYER]: 'bitlayer',
[BLOCKCHAIN_NAME.GRAVITY]: 'gravity'
[BLOCKCHAIN_NAME.GRAVITY]: 'gravity',
[BLOCKCHAIN_NAME.UNICHAIN_SEPOLIA_TESTNET]: 'unichain-sepolia-testnet',
[BLOCKCHAIN_NAME.SONIC]: 'sonic'
} as const;

export const TO_BACKEND_BLOCKCHAINS: Record<BlockchainName, BackendBlockchain> = {
Expand Down
6 changes: 4 additions & 2 deletions src/core/blockchain/models/blockchain-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export const TEST_EVM_BLOCKCHAIN_NAME = {
SEPOLIA: 'SEPOLIA',
BERACHAIN: 'BERACHAIN',
BLAST_TESTNET: 'BLAST_TESTNET',
HOLESKY: 'HOLESKY'
HOLESKY: 'HOLESKY',
UNICHAIN_SEPOLIA_TESTNET: 'UNICHAIN_SEPOLIA_TESTNET'
} as const;

export const EVM_BLOCKCHAIN_NAME = {
Expand Down Expand Up @@ -71,7 +72,8 @@ export const EVM_BLOCKCHAIN_NAME = {
CORE: 'CORE',
BAHAMUT: 'BAHAMUT',
BITLAYER: 'BITLAYER',
GRAVITY: 'GRAVITY'
GRAVITY: 'GRAVITY',
SONIC: 'SONIC'
} as const;

export const BLOCKCHAIN_NAME = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const blockchainId: Record<BlockchainName, number> = {
[BLOCKCHAIN_NAME.BAHAMUT]: 5165,
[BLOCKCHAIN_NAME.BITLAYER]: 200901,
[BLOCKCHAIN_NAME.GRAVITY]: 1625,
[BLOCKCHAIN_NAME.SONIC]: 146,
// Tesnents
[BLOCKCHAIN_NAME.GOERLI]: 5,
[BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN_TESTNET]: 87,
Expand All @@ -81,6 +82,7 @@ export const blockchainId: Record<BlockchainName, number> = {
[BLOCKCHAIN_NAME.BERACHAIN]: 80084,
[BLOCKCHAIN_NAME.BLAST_TESTNET]: 168587773,
[BLOCKCHAIN_NAME.HOLESKY]: 17000,
[BLOCKCHAIN_NAME.UNICHAIN_SEPOLIA_TESTNET]: 1301,
// 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 @@ -3,7 +3,8 @@ import { BLOCKCHAIN_NAME, EVM_BLOCKCHAIN_NAME } from 'src/core/blockchain/models
export const web3PrivateSupportedBlockchain = [
...Object.values(EVM_BLOCKCHAIN_NAME),
BLOCKCHAIN_NAME.TRON,
BLOCKCHAIN_NAME.SOLANA
BLOCKCHAIN_NAME.SOLANA,
BLOCKCHAIN_NAME.BITCOIN
] as const;

export type Web3PrivateSupportedBlockchain = (typeof web3PrivateSupportedBlockchain)[number];
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export const web3PrivateSupportedChainTypes = [
CHAIN_TYPE.EVM,
CHAIN_TYPE.TRON,
CHAIN_TYPE.SOLANA,
CHAIN_TYPE.TON
CHAIN_TYPE.TON,
CHAIN_TYPE.BITCOIN
] as const;

export type Web3PrivateSupportedChainType = (typeof web3PrivateSupportedChainTypes)[number];
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CHAIN_TYPE } from 'src/core/blockchain/models/chain-type';
import { Web3PrivateSupportedChainType } from 'src/core/blockchain/web3-private-service/models/web-private-supported-chain-type';
import { BitcoinWeb3Private } from 'src/core/blockchain/web3-private-service/web3-private/bitcoin-web3-private/bitcoin-web3-private';
import { EvmWeb3Private } from 'src/core/blockchain/web3-private-service/web3-private/evm-web3-private/evm-web3-private';
import { SolanaWeb3Private } from 'src/core/blockchain/web3-private-service/web3-private/solana-web3-private/solana-web3-private';
import { TronWeb3Private } from 'src/core/blockchain/web3-private-service/web3-private/tron-web3-private/tron-web3-private';
Expand All @@ -12,4 +13,5 @@ export type Web3PrivateStorage = Record<Web3PrivateSupportedChainType, Web3Priva
[CHAIN_TYPE.TRON]: TronWeb3Private | undefined;
[CHAIN_TYPE.SOLANA]: SolanaWeb3Private | undefined;
[CHAIN_TYPE.TON]: TonWeb3Private | undefined;
[CHAIN_TYPE.BITCOIN]: BitcoinWeb3Private | undefined;
};
12 changes: 11 additions & 1 deletion src/core/blockchain/web3-private-service/web3-private-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RubicSdkError } from 'src/common/errors';
import {
BitcoinBlockchainName,
BlockchainName,
EvmBlockchainName,
SolanaBlockchainName,
Expand All @@ -15,12 +16,14 @@ import {
web3PrivateSupportedChainTypes
} from 'src/core/blockchain/web3-private-service/models/web-private-supported-chain-type';
import { Web3PrivateStorage } from 'src/core/blockchain/web3-private-service/models/web3-private-storage';
import { BitcoinWeb3Private } from 'src/core/blockchain/web3-private-service/web3-private/bitcoin-web3-private/bitcoin-web3-private';
import { EmptyWeb3Private } from 'src/core/blockchain/web3-private-service/web3-private/empty-web3-private';
import { EvmWeb3Private } from 'src/core/blockchain/web3-private-service/web3-private/evm-web3-private/evm-web3-private';
import { SolanaWeb3Private } from 'src/core/blockchain/web3-private-service/web3-private/solana-web3-private/solana-web3-private';
import { TronWeb3Private } from 'src/core/blockchain/web3-private-service/web3-private/tron-web3-private/tron-web3-private';
import { Web3Private } from 'src/core/blockchain/web3-private-service/web3-private/web3-private';
import {
BitcoinWalletProviderCore,
EvmWalletProviderCore,
SolanaWalletProviderCore,
TonWalletProviderCore,
Expand All @@ -47,7 +50,8 @@ export class Web3PrivateService {
[CHAIN_TYPE.EVM]: this.createEvmWeb3Private.bind(this),
[CHAIN_TYPE.TRON]: this.createTronWeb3Private.bind(this),
[CHAIN_TYPE.SOLANA]: this.createSolanaWeb3Private.bind(this),
[CHAIN_TYPE.TON]: this.createTonWeb3Private.bind(this)
[CHAIN_TYPE.TON]: this.createTonWeb3Private.bind(this),
[CHAIN_TYPE.BITCOIN]: this.createBitcoinWeb3Private.bind(this)
};

constructor(walletProvider: WalletProvider) {
Expand All @@ -58,6 +62,7 @@ export class Web3PrivateService {
public getWeb3Private(chainType: 'TRON'): TronWeb3Private;
public getWeb3Private(chainType: 'SOLANA'): SolanaWeb3Private;
public getWeb3Private(chainType: 'TON'): TonWeb3Private;
public getWeb3Private(chainType: 'BITCOIN'): BitcoinWeb3Private;
public getWeb3Private(chainType: ChainType): never;
public getWeb3Private(chainType: ChainType) {
if (!Web3PrivateService.isSupportedChainType(chainType)) {
Expand All @@ -75,6 +80,7 @@ export class Web3PrivateService {
public getWeb3PrivateByBlockchain(blockchain: SolanaBlockchainName): SolanaWeb3Private;
public getWeb3PrivateByBlockchain(blockchain: TronBlockchainName): TronWeb3Private;
public getWeb3PrivateByBlockchain(blockchain: TonBlockchainName): TonWeb3Private;
public getWeb3PrivateByBlockchain(blockchain: BitcoinBlockchainName): BitcoinWeb3Private;
public getWeb3PrivateByBlockchain(blockchain: Web3PrivateSupportedBlockchain): Web3Private;
public getWeb3PrivateByBlockchain(blockchain: BlockchainName): never;
public getWeb3PrivateByBlockchain(blockchain: BlockchainName) {
Expand Down Expand Up @@ -131,6 +137,10 @@ export class Web3PrivateService {
return new TonWeb3Private(tonProviderCore);
}

private createBitcoinWeb3Private(providerCore: BitcoinWalletProviderCore): BitcoinWeb3Private {
return new BitcoinWeb3Private(providerCore);
}

public updateWeb3PrivateStorage(walletProvider: WalletProvider) {
this.web3PrivateStorage = this.createWeb3PrivateStorage(walletProvider);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { BLOCKCHAIN_NAME, BlockchainName } from 'src/core/blockchain/models/blockchain-name';
import { BasicTransactionOptions } from 'src/core/blockchain/web3-private-service/web3-private/models/basic-transaction-options';
import { BitcoinWeb3Pure } from 'src/core/blockchain/web3-pure/typed-web3-pure/bitcoin-web3-pure';
import { BitcoinWalletProviderCore } from 'src/core/sdk/models/wallet-provider';
import { OnChainStatusManager } from 'src/features/on-chain/status-manager/on-chain-status-manager';

import { Web3Private } from '../web3-private';

export class BitcoinWeb3Private extends Web3Private {
protected readonly Web3Pure = BitcoinWeb3Pure;

public getBlockchainName(): Promise<BlockchainName> {
return Promise.resolve(BLOCKCHAIN_NAME.BITCOIN);
}

public async transfer(
recipient: string,
amount: string,
memo?: string,
options?: BasicTransactionOptions
): Promise<string> {
const hashPromise = new Promise<string>((resolve, reject) => {
this.wallet.core.request(
{
method: 'transfer',
params: [
{
feeRate: 10,
from: this.wallet.address,
recipient,
amount: {
amount,
decimals: 8
},
...(memo && { memo })
}
]
},
(error, txHash) => {
if (error) {
reject(error);
} else {
options?.onTransactionHash?.(txHash);
resolve(txHash);
}
}
);
});
try {
const hash = await hashPromise;
if (typeof hash === 'string') {
const statusData = await OnChainStatusManager.getBitcoinTransaction(hash);
return statusData.hash!;
}
throw new Error();
} catch {
throw new Error('Failed to transfer funds');
}
}

constructor(private readonly wallet: BitcoinWalletProviderCore) {
super(wallet.address);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface BitcoinEncodedConfig {
data?: string;
to: string;
value: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class TonWeb3Private extends Web3Private {
options.onTransactionHash?.(txHash);
const isCompleted = await this.waitForTransactionReceipt(txHash);
if (!isCompleted) {
throw new RubicSdkError('[TonWeb3Private] TON transaction timeout expired!');
throw new RubicSdkError('[BitcoinWeb3Private] TON transaction timeout expired!');
}

return boc;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Any } from 'src/common/utils/types';
import {
BitcoinBlockchainName,
EvmBlockchainName,
SolanaBlockchainName,
TronBlockchainName
} from 'src/core/blockchain/models/blockchain-name';
import { Web3PublicSupportedBlockchain } from 'src/core/blockchain/web3-public-service/models/web3-public-storage';
import { BitcoinWeb3Public } from 'src/core/blockchain/web3-public-service/web3-public/bitcoin-web3-public/bitcoin-web3-public';
import { EvmWeb3Public } from 'src/core/blockchain/web3-public-service/web3-public/evm-web3-public/evm-web3-public';
import { SolanaWeb3Public } from 'src/core/blockchain/web3-public-service/web3-public/solana-web3-public/solana-web3-public';
import { TronWeb3Public } from 'src/core/blockchain/web3-public-service/web3-public/tron-web3-public/tron-web3-public';
Expand All @@ -16,4 +18,5 @@ export type CreateWeb3Public = Record<
> &
Record<EvmBlockchainName, (blockchainName: EvmBlockchainName) => EvmWeb3Public> &
Record<TronBlockchainName, () => TronWeb3Public> &
Record<SolanaBlockchainName, () => SolanaWeb3Public>;
Record<SolanaBlockchainName, () => SolanaWeb3Public> &
Record<BitcoinBlockchainName, () => BitcoinWeb3Public>;
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {
BitcoinBlockchainName,
BLOCKCHAIN_NAME,
EVM_BLOCKCHAIN_NAME,
EvmBlockchainName,
SolanaBlockchainName,
TonBlockchainName,
TronBlockchainName
} from 'src/core/blockchain/models/blockchain-name';
import { BitcoinWeb3Public } from 'src/core/blockchain/web3-public-service/web3-public/bitcoin-web3-public/bitcoin-web3-public';
import { EvmWeb3Public } from 'src/core/blockchain/web3-public-service/web3-public/evm-web3-public/evm-web3-public';
import { SolanaWeb3Public } from 'src/core/blockchain/web3-public-service/web3-public/solana-web3-public/solana-web3-public';
import { TronWeb3Public } from 'src/core/blockchain/web3-public-service/web3-public/tron-web3-public/tron-web3-public';
Expand All @@ -16,12 +18,14 @@ export const web3PublicSupportedBlockchains = [
...Object.values(EVM_BLOCKCHAIN_NAME),
BLOCKCHAIN_NAME.TRON,
BLOCKCHAIN_NAME.SOLANA,
BLOCKCHAIN_NAME.TON
BLOCKCHAIN_NAME.TON,
BLOCKCHAIN_NAME.BITCOIN
] as const;

export type Web3PublicSupportedBlockchain = (typeof web3PublicSupportedBlockchains)[number];

export type Web3PublicStorage = Record<EvmBlockchainName, EvmWeb3Public> &
Record<TronBlockchainName, TronWeb3Public> &
Record<SolanaBlockchainName, SolanaWeb3Public> &
Record<TonBlockchainName, TonWeb3Public>;
Record<TonBlockchainName, TonWeb3Public> &
Record<BitcoinBlockchainName, BitcoinWeb3Public>;
10 changes: 9 additions & 1 deletion src/core/blockchain/web3-public-service/web3-public-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { HealthcheckError, RubicSdkError, TimeoutError } from 'src/common/errors
import pTimeout from 'src/common/utils/p-timeout';
import { TronWeb } from 'src/core/blockchain/constants/tron/tron-web';
import {
BitcoinBlockchainName,
BLOCKCHAIN_NAME,
BlockchainName,
EVM_BLOCKCHAIN_NAME,
Expand All @@ -19,6 +20,7 @@ import {
Web3PublicSupportedBlockchain,
web3PublicSupportedBlockchains
} from 'src/core/blockchain/web3-public-service/models/web3-public-storage';
import { BitcoinWeb3Public } from 'src/core/blockchain/web3-public-service/web3-public/bitcoin-web3-public/bitcoin-web3-public';
import { EvmWeb3Public } from 'src/core/blockchain/web3-public-service/web3-public/evm-web3-public/evm-web3-public';
import { SolanaWeb3Public } from 'src/core/blockchain/web3-public-service/web3-public/solana-web3-public/solana-web3-public';
import { TronWeb3Public } from 'src/core/blockchain/web3-public-service/web3-public/tron-web3-public/tron-web3-public';
Expand Down Expand Up @@ -53,6 +55,7 @@ export class Web3PublicService {
public getWeb3Public(blockchainName: TronBlockchainName): TronWeb3Public;
public getWeb3Public(blockchainName: SolanaBlockchainName): SolanaWeb3Public;
public getWeb3Public(blockchainName: TonBlockchainName): TonWeb3Public;
public getWeb3Public(blockchainName: BitcoinBlockchainName): BitcoinWeb3Public;
public getWeb3Public(blockchainName: Web3PublicSupportedBlockchain): Web3Public;
public getWeb3Public(blockchainName: BlockchainName): never;
public getWeb3Public(blockchainName: BlockchainName) {
Expand Down Expand Up @@ -85,7 +88,8 @@ export class Web3PublicService {
),
[BLOCKCHAIN_NAME.TRON]: this.createTronWeb3PublicProxy.bind(this),
[BLOCKCHAIN_NAME.SOLANA]: this.createSolanaWeb3PublicProxy.bind(this),
[BLOCKCHAIN_NAME.TON]: this.createTonWeb3Public.bind(this)
[BLOCKCHAIN_NAME.TON]: this.createTonWeb3Public.bind(this),
[BLOCKCHAIN_NAME.BITCOIN]: this.createBitcoinWeb3Public.bind(this)
};
}

Expand Down Expand Up @@ -130,6 +134,10 @@ export class Web3PublicService {
return tonWeb3Public;
}

private createBitcoinWeb3Public(): BitcoinWeb3Public {
return new BitcoinWeb3Public();
}

private createWeb3PublicProxy<T extends Web3Public = Web3Public>(
blockchainName: Web3PublicSupportedBlockchain,
web3Public: T
Expand Down
Loading

0 comments on commit 9ad79a1

Please sign in to comment.