Skip to content

Commit

Permalink
Merge pull request #2 from valentinmatter/add-avalanche
Browse files Browse the repository at this point in the history
Add Avalanche & Fantom and fix indentation
  • Loading branch information
YoavBZ authored Nov 6, 2022
2 parents ab3911a + 913b24c commit 20a881a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
58 changes: 30 additions & 28 deletions src/bridge/base-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ export const CHAIN_TO_ASSET_ID: {[key: string]: string } = {
[Chain.POLYGON]: 'MATIC_POLYGON',
[Chain.MUMBAI]: 'MATIC_POLYGON_MUMBAI',
[Chain.RINKEBY]: 'ETH_TEST4',
[Chain.ARBITRUM]: 'ETH-AETH'
}
[Chain.ARBITRUM]: 'ETH-AETH',
[Chain.FANTOM]: "FTM_FANTOM",
[Chain.AVALANCHE]: "AVAX",
};

export const CHAIN_IDS = {
[Chain.MAINNET]: 1,
Expand All @@ -26,8 +28,9 @@ export const CHAIN_IDS = {
[Chain.POLYGON]: 137,
[Chain.ARBITRUM]: 42161,
[Chain.MUMBAI]: 80001,
}

[Chain.FANTOM]: 250,
[Chain.AVALANCHE]: 43114,
};

export abstract class BaseBridge {
readonly assetId: string;
Expand All @@ -36,29 +39,29 @@ export abstract class BaseBridge {
TransactionStatus.FAILED,
TransactionStatus.CANCELLED,
TransactionStatus.BLOCKED,
TransactionStatus.REJECTED
TransactionStatus.REJECTED,
];

constructor(readonly params: BridgeParams) {
const chain = params.chain || Chain.MAINNET;
this.assetId = CHAIN_TO_ASSET_ID[chain];
}

async getDepositAddress(): Promise<string> {
const depositAddresses = await this.params.fireblocksApiClient.getDepositAddresses(this.params.vaultAccountId, this.assetId);
return depositAddresses[0].address;
}
constructor(readonly params: BridgeParams) {
const chain = params.chain || Chain.MAINNET;
this.assetId = CHAIN_TO_ASSET_ID[chain];
}

getChainId(): number {
return CHAIN_IDS[this.params.chain];
}
async getDepositAddress(): Promise<string> {
const depositAddresses = await this.params.fireblocksApiClient.getDepositAddresses(this.params.vaultAccountId, this.assetId);
return depositAddresses[0].address;
}

async waitForTxHash(txId: string, timeoutMs?: number): Promise<string> {
return Promise.race([
(async () => {
getChainId(): number {
return CHAIN_IDS[this.params.chain];
}

async waitForTxHash(txId: string, timeoutMs?: number): Promise<string> {
return Promise.race([
(async () => {
let status: TransactionStatus;
let txInfo: TransactionResponse;
while(!BaseBridge.finalTransactionStates.includes(status)) {
while (!BaseBridge.finalTransactionStates.includes(status)) {
try {
txInfo = await this.params.fireblocksApiClient.getTransactionById(txId);
status = txInfo.status;
Expand All @@ -69,19 +72,18 @@ export abstract class BaseBridge {
return txInfo.txHash;
}
await new Promise(r => setTimeout(r, 1000));
};

if(status != TransactionStatus.COMPLETED)
{
}

if (status != TransactionStatus.COMPLETED) {
throw `Transaction was not completed successfully. Final Status: ${status}`;
}
return txInfo.txHash;
})(),
new Promise<string>((resolve, reject) => {
if(timeoutMs) {
setTimeout(() => reject(`waitForTxCompletion() for txId ${txId} timed out`), timeoutMs)
if (timeoutMs) {
setTimeout(() => reject(`waitForTxCompletion() for txId ${txId} timed out`), timeoutMs);
}
})
]);
}
}
}
4 changes: 3 additions & 1 deletion src/interfaces/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ export enum Chain {
MUMBAI = "polygon_test",
RINKEBY = "rinkeby",
ARBITRUM = "arbitrum",
}
AVALANCHE = "avalanche",
FANTOM = "fantom",
}

0 comments on commit 20a881a

Please sign in to comment.