Skip to content

Commit

Permalink
Merge pull request #356 from Cryptorubic/develop
Browse files Browse the repository at this point in the history
xDai bridge
  • Loading branch information
siandreev authored Jun 4, 2021
2 parents 0a1df36 + 09ccf15 commit 52b0dcc
Show file tree
Hide file tree
Showing 46 changed files with 434 additions and 94 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@
"text2locale": "github:juliandavidmr/text2locale",
"ts-node": "~7.0.0",
"tslint": "~6.1.0",
"typescript": "^4.1.5"
"typescript": "~4.1.5"
}
}
24 changes: 23 additions & 1 deletion src/app/core/services/backend/bridge-api/bridge-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { HttpService } from '../../http/http.service';
import { TRADE_STATUS } from './models/TRADE_STATUS';
import { TokensService } from '../tokens-service/tokens.service';
import { BOT_URL } from '../constants/BOT_URL';
import { ethToXDaiDepositWallet } from '../../../../shared/constants/bridge/deposit-wallets';

@Injectable({
providedIn: 'root'
Expand All @@ -20,7 +21,8 @@ export class BridgeApiService {
ETH: BLOCKCHAIN_NAME.ETHEREUM,
BSC: BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN,
POL: BLOCKCHAIN_NAME.POLYGON,
TRX: BLOCKCHAIN_NAME.TRON
TRX: BLOCKCHAIN_NAME.TRON,
XDAI: BLOCKCHAIN_NAME.XDAI
};

constructor(private httpService: HttpService, private tokensService: TokensService) {}
Expand Down Expand Up @@ -176,6 +178,26 @@ export class BridgeApiService {
});
}

public postXDaiTransaction(transactionHash: string): Promise<void> {
const body = {
type: 'xdai',
fromNetwork: BLOCKCHAIN_NAME.ETHEREUM.toLowerCase(),
transaction_id: transactionHash
};

return new Promise<void>((resolve, reject) => {
this.httpService.post('bridges/transactions', body).subscribe(
() => {
resolve();
},
error => {
console.error(error);
reject(error);
}
);
});
}

public notifyBridgeBot(
bridgeTrade: BridgeTrade,
transactionHash: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { ReceiveButtonComponent } from './components/bridge-table/deposit-button
import { EthereumTronBridgeProviderService } from './services/blockchains-bridge-provider/ethereum-tron-bridge-provider/ethereum-tron-bridge-provider.service';
import { BinanceTronBridgeProviderService } from './services/blockchains-bridge-provider/binance-tron-bridge-provider/binance-tron-bridge-provider.service';
import { PanamaBridgeProviderService } from './services/blockchains-bridge-provider/common/panama-bridge-provider/panama-bridge-provider.service';
import { EthereumXdaiBridgeProviderService } from './services/blockchains-bridge-provider/ethereum-xdai-bridge-provider/ethereum-xdai-bridge-provider.service';

@NgModule({
declarations: [
Expand Down Expand Up @@ -61,6 +62,7 @@ import { PanamaBridgeProviderService } from './services/blockchains-bridge-provi
EthereumBinanceRubicBridgeProviderService,
EthereumPolygonBridgeProviderService,
EthereumTronBridgeProviderService,
EthereumXdaiBridgeProviderService,
BinanceTronBridgeProviderService
]
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export class BridgeTableComponent implements OnInit, OnDestroy {
[BLOCKCHAIN_NAME.TRON]: {
label: 'TRON',
img: 'tron.svg'
},
[BLOCKCHAIN_NAME.XDAI]: {
label: 'XDAI',
img: 'xdai.svg'
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
<button
class="swap-section__revert-button revert-button"
type="button"
*ngIf="toBlockchain.key !== BLOCKCHAIN_NAME.TRON"
*ngIf="toBlockchain.key !== BLOCKCHAIN_NAME.TRON && toBlockchain.key !== BLOCKCHAIN_NAME.XDAI"
(click)="revertBlockchains()"
>
<img src="assets/images/icons/revert.svg" alt="Revert" width="21" height="24" />
Expand Down Expand Up @@ -189,24 +189,11 @@

<a
class="swap-box__blockchain-link"
[href]="
isBlockchainSelected(BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN)
? 'https://www.binance.org/'
: isBlockchainSelected(BLOCKCHAIN_NAME.POLYGON)
? 'https://polygon.technology/'
: 'https://tron.network/'
"
[href]="BLOCKCHAIN_DATA[toBlockchain.key]?.link"
target="_blank"
>
{{ 'bridgePage.whatIs' | translate }}
{{
isBlockchainSelected(BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN)
? 'Binance Smart Chain'
: isBlockchainSelected(BLOCKCHAIN_NAME.POLYGON)
? 'Polygon'
: 'TRON'
}}
{{ 'bridgePage.whatIsAfter' | translate }}?
{{ BLOCKCHAIN_DATA[toBlockchain.key]?.caption }}{{ 'bridgePage.whatIsAfter' | translate }}?
</a>
</div>
</div>
Expand All @@ -228,30 +215,17 @@
</app-primary-button>

<a
[href]="
isBlockchainSelected(BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN) ||
isBlockchainSelected(BLOCKCHAIN_NAME.TRON)
? 'https://www.binance.org/'
: 'https://polygon.technology/'
"
*ngIf="providerData.img"
[href]="providerData.href"
target="_blank"
class="confirm-section__blockchain-link"
[ngClass]="{
'cross-chain-form__confirm-info_hidden':
selectedToken?.blockchainToken[BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN]?.address ===
this.BRBC_ADDRESS,
'cross-chain-form__confirm-info_polygon': isBlockchainSelected(BLOCKCHAIN_NAME.POLYGON)
'confirm-section__blockchain-link_opacity': providerData.img === 'Polygon' || providerData.img === 'XDai'
}"
>
<span>{{ 'bridgePage.assistanceOf' | translate }}</span>
<img
[src]="
'assets/images/icons/collaborations/' +
(isBlockchainSelected(BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN) ||
isBlockchainSelected(BLOCKCHAIN_NAME.TRON)
? 'Binance.svg'
: 'Polygon.svg')
"
[src]="'assets/images/icons/collaborations/' + providerData.img + '.svg'"
width="99"
height="24"
alt="blockchain"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
visibility: hidden;
}

&_polygon {
&_opacity {
&:hover {
img {
opacity: 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import InputToken from 'src/app/shared/models/tokens/InputToken';
import { BLOCKCHAINS } from 'src/app/features/cross-chain-swaps-page/common/constants/BLOCKCHAINS';
import ADDRESS_TYPE from 'src/app/shared/models/blockchain/ADDRESS_TYPE';
import { ErrorsService } from 'src/app/core/services/errors/errors.service';

import { TransactionReceipt } from 'web3-eth';
import { BridgeToken } from '../../models/BridgeToken';
import { BridgeBlockchain } from '../../models/BridgeBlockchain';
import { BridgeTrade } from '../../models/BridgeTrade';
import { BridgeService } from '../../services/bridge.service';
import { BRIDGE_PROVIDER_TYPE } from '../../models/ProviderType';

@Component({
selector: 'app-bridge-form',
Expand All @@ -33,7 +36,7 @@ export class BridgeFormComponent implements OnInit, OnDestroy {
public ADDRESS_TYPE = ADDRESS_TYPE;

public fromBlockchainsList: BridgeBlockchain[] = Object.values(BLOCKCHAINS).filter(
b => b.key !== BLOCKCHAIN_NAME.TRON
b => b.key !== BLOCKCHAIN_NAME.TRON && b.key !== BLOCKCHAIN_NAME.XDAI
);

public toBlockchainsList: BridgeBlockchain[] = Object.values(BLOCKCHAINS);
Expand Down Expand Up @@ -68,6 +71,56 @@ export class BridgeFormComponent implements OnInit, OnDestroy {

public toWalletAddress: string;

public BLOCKCHAIN_DATA = {
[BLOCKCHAIN_NAME.ETHEREUM]: {
link: 'https://ethereum.org/en/',
caption: 'Ethereum'
},
[BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN]: {
link: 'https://www.binance.org/',
caption: 'Binance Smart Chain',
providerImg: 'Binance'
},
[BLOCKCHAIN_NAME.POLYGON]: {
link: 'https://polygon.technology/',
caption: 'Polygon',
providerImg: 'Polygon'
},
[BLOCKCHAIN_NAME.TRON]: {
link: 'https://tron.network/',
caption: 'TRON',
providerImg: 'Binance'
},
[BLOCKCHAIN_NAME.XDAI]: {
link: 'https://www.xdaichain.com/',
caption: 'xDai',
providerImg: 'XDai'
}
};

public PROVIDERS_DATA = {
[BRIDGE_PROVIDER_TYPE.PANAMA]: {
img: 'Binance',
href: 'https://www.binance.org/'
},
[BRIDGE_PROVIDER_TYPE.RUBIC]: {
img: '',
href: ''
},
[BRIDGE_PROVIDER_TYPE.POLYGON]: {
img: 'Polygon',
href: 'https://polygon.technology/'
},
[BRIDGE_PROVIDER_TYPE.XDAI]: {
img: 'XDai',
href: 'https://www.xdaichain.com/'
},
[BRIDGE_PROVIDER_TYPE.EVO]: {
img: 'Evo',
href: ''
}
};

private tokensSubscription$: Subscription;

private addressSubscription$: Subscription;
Expand Down Expand Up @@ -229,6 +282,11 @@ export class BridgeFormComponent implements OnInit, OnDestroy {
}
}

get providerData(): { img: string; href: string } {
const providerType = this.bridgeService.getProviderType(this.selectedToken);
return this.PROVIDERS_DATA[providerType];
}

constructor(
private bridgeService: BridgeService,
private dialog: MatDialog,
Expand Down Expand Up @@ -436,8 +494,8 @@ export class BridgeFormComponent implements OnInit, OnDestroy {
.createTrade(bridgeTrade)
.pipe(first())
.subscribe(
(res: string) => {
this.tradeSuccessId = res;
(res: TransactionReceipt) => {
this.tradeSuccessId = res.transactionHash;
this.tradeInProgress = false;
this.buttonAnimation = false;
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum BRIDGE_PROVIDER_TYPE {
PANAMA = 'PANAMA',
POLYGON = 'POLYGON',
RUBIC = 'RUBIC',
XDAI = 'XDAI',
EVO = 'EVO'
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@ import {
BridgeToken
} from 'src/app/features/cross-chain-swaps-page/bridge-page/models/BridgeToken';
import { BridgeTrade } from 'src/app/features/cross-chain-swaps-page/bridge-page/models/BridgeTrade';
import { TransactionReceipt } from 'web3-eth';
import { BlockchainsBridgeProvider } from '../blockchains-bridge-provider';
import { PanamaBridgeProviderService } from '../common/panama-bridge-provider/panama-bridge-provider.service';
import { PanamaToken } from '../common/panama-bridge-provider/models/PanamaToken';
import { BRIDGE_PROVIDER_TYPE } from '../../../models/ProviderType';

@Injectable()
export class BinanceTronBridgeProviderService extends BlockchainsBridgeProvider {
constructor(private commonPanamaBridgeProviderService: PanamaBridgeProviderService) {
super();
}

getProviderType(): BRIDGE_PROVIDER_TYPE {
return BRIDGE_PROVIDER_TYPE.PANAMA;
}

private static parseUSDTPanamaToken(token: PanamaToken): BridgeToken {
return {
symbol: token.symbol,
Expand Down Expand Up @@ -64,7 +70,7 @@ export class BinanceTronBridgeProviderService extends BlockchainsBridgeProvider
createTrade(
bridgeTrade: BridgeTrade,
updateTransactionsList: () => Promise<void>
): Observable<string> {
): Observable<TransactionReceipt> {
return this.commonPanamaBridgeProviderService.createTrade(bridgeTrade, updateTransactionsList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,38 @@ import { BridgeTrade } from 'src/app/features/cross-chain-swaps-page/bridge-page
import { BridgeToken } from 'src/app/features/cross-chain-swaps-page/bridge-page/models/BridgeToken';
import SwapToken from 'src/app/shared/models/tokens/SwapToken';
import { BLOCKCHAIN_NAME } from 'src/app/shared/models/blockchain/BLOCKCHAIN_NAME';
import { TransactionReceipt } from 'web3-eth';
import { BRIDGE_PROVIDER_TYPE } from '../../models/ProviderType';

export abstract class BlockchainsBridgeProvider {
/**
* @description get type of provider
*/
public abstract getProviderType?(token?: BridgeToken): BRIDGE_PROVIDER_TYPE;

/**
* @description get transformed list of bridge tokens from usually tokens
* @param swapTokens swap list tokens
* @return observable bridge list tokens
*/
public abstract getTokensList(swapTokens: List<SwapToken>): Observable<List<BridgeToken>>;

/**
* @description get price blockchain provider's fee
* @param token bridge token
* @param toBlockchain destination blockchain
* @return observable number fee price
*/
public abstract getFee(token: BridgeToken, toBlockchain: BLOCKCHAIN_NAME): Observable<number>;

/**
* @description create trade between different networks
* @param bridgeTrade object with data for trade
* @param updateTransactionsList callback function for update list of bridge trades
* @return observable transaction receipt object
*/
public abstract createTrade(
bridgeTrade: BridgeTrade,
updateTransactionsList: () => Promise<void>
): Observable<string>;
): Observable<TransactionReceipt>;
}
Loading

0 comments on commit 52b0dcc

Please sign in to comment.