-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LayerZero bridge for ALGB token (#561)
- Loading branch information
Showing
11 changed files
with
485 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...ss-chain/calculation-manager/providers/layerzero-bridge/constants/algb-token-addresses.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { BLOCKCHAIN_NAME } from 'src/core/blockchain/models/blockchain-name'; | ||
|
||
import { LayerZeroBridgeSupportedBlockchain } from '../models/layerzero-bridge-supported-blockchains'; | ||
|
||
export const ALGB_TOKEN: Record<LayerZeroBridgeSupportedBlockchain, string> = { | ||
[BLOCKCHAIN_NAME.ARBITRUM]: '0x9f018bda8f6b507a0c9e6f290b2f7c49c2f8daf8', | ||
[BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN]: '0xe374116f490b461764e2438f98eab3fff383367b', | ||
[BLOCKCHAIN_NAME.POLYGON]: '0x0169ec1f8f639b32eec6d923e24c2a2ff45b9dd6' | ||
}; |
10 changes: 10 additions & 0 deletions
10
...hain/calculation-manager/providers/layerzero-bridge/constants/layerzero-bridge-address.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { BLOCKCHAIN_NAME } from 'src/core/blockchain/models/blockchain-name'; | ||
|
||
import { LayerZeroBridgeSupportedBlockchain } from '../models/layerzero-bridge-supported-blockchains'; | ||
import { ALGB_TOKEN } from './algb-token-addresses'; | ||
|
||
export const layerZeroProxyOFT: Record<LayerZeroBridgeSupportedBlockchain, string> = { | ||
[BLOCKCHAIN_NAME.ARBITRUM]: ALGB_TOKEN.ARBITRUM, | ||
[BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN]: ALGB_TOKEN.BSC, | ||
[BLOCKCHAIN_NAME.POLYGON]: '0xDef87c507ef911Fd99c118c53171510Eb7967738' | ||
}; |
9 changes: 9 additions & 0 deletions
9
...ss-chain/calculation-manager/providers/layerzero-bridge/constants/layzerzero-chain-ids.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { BLOCKCHAIN_NAME } from 'src/core/blockchain/models/blockchain-name'; | ||
|
||
import { LayerZeroBridgeSupportedBlockchain } from '../models/layerzero-bridge-supported-blockchains'; | ||
|
||
export const layerZeroChainIds: Record<LayerZeroBridgeSupportedBlockchain, string> = { | ||
[BLOCKCHAIN_NAME.ARBITRUM]: '110', | ||
[BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN]: '102', | ||
[BLOCKCHAIN_NAME.POLYGON]: '109' | ||
}; |
94 changes: 94 additions & 0 deletions
94
...s/cross-chain/calculation-manager/providers/layerzero-bridge/layerzero-bridge-provider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { NotSupportedTokensError } from 'src/common/errors'; | ||
import { PriceToken, PriceTokenAmount } from 'src/common/tokens'; | ||
import { BlockchainName, EvmBlockchainName } from 'src/core/blockchain/models/blockchain-name'; | ||
import { RequiredCrossChainOptions } from 'src/features/cross-chain/calculation-manager/models/cross-chain-options'; | ||
import { CROSS_CHAIN_TRADE_TYPE } from 'src/features/cross-chain/calculation-manager/models/cross-chain-trade-type'; | ||
import { CbridgeCrossChainSupportedBlockchain } from 'src/features/cross-chain/calculation-manager/providers/cbridge/constants/cbridge-supported-blockchains'; | ||
import { CrossChainProvider } from 'src/features/cross-chain/calculation-manager/providers/common/cross-chain-provider'; | ||
import { CalculationResult } from 'src/features/cross-chain/calculation-manager/providers/common/models/calculation-result'; | ||
import { FeeInfo } from 'src/features/cross-chain/calculation-manager/providers/common/models/fee-info'; | ||
import { RubicStep } from 'src/features/cross-chain/calculation-manager/providers/common/models/rubicStep'; | ||
|
||
import { LayerZeroBridgeTrade } from './layerzero-bridge-trade'; | ||
import { | ||
LayerZeroBridgeSupportedBlockchain, | ||
layerZeroBridgeSupportedBlockchains | ||
} from './models/layerzero-bridge-supported-blockchains'; | ||
|
||
export class LayerZeroBridgeProvider extends CrossChainProvider { | ||
public readonly type = CROSS_CHAIN_TRADE_TYPE.LAYERZERO; | ||
|
||
public isSupportedBlockchain( | ||
blockchain: BlockchainName | ||
): blockchain is LayerZeroBridgeSupportedBlockchain { | ||
return layerZeroBridgeSupportedBlockchains.some( | ||
supportedBlockchain => supportedBlockchain === blockchain | ||
); | ||
} | ||
|
||
public async calculate( | ||
fromToken: PriceTokenAmount<EvmBlockchainName>, | ||
toToken: PriceToken<EvmBlockchainName>, | ||
options: RequiredCrossChainOptions | ||
): Promise<CalculationResult> { | ||
const fromBlockchain = fromToken.blockchain as LayerZeroBridgeSupportedBlockchain; | ||
const toBlockchain = toToken.blockchain as LayerZeroBridgeSupportedBlockchain; | ||
|
||
if (!this.areSupportedBlockchains(fromBlockchain, toBlockchain)) { | ||
return { | ||
trade: null, | ||
error: new NotSupportedTokensError(), | ||
tradeType: this.type | ||
}; | ||
} | ||
|
||
try { | ||
const to = new PriceTokenAmount({ | ||
...toToken.asStruct, | ||
tokenAmount: fromToken.tokenAmount | ||
}); | ||
|
||
const gasData = | ||
options.gasCalculation === 'enabled' | ||
? await LayerZeroBridgeTrade.getGasData(fromToken, to, options) | ||
: null; | ||
|
||
return { | ||
trade: new LayerZeroBridgeTrade( | ||
{ | ||
from: fromToken, | ||
to, | ||
gasData | ||
}, | ||
options.providerAddress, | ||
await this.getRoutePath(fromToken, to) | ||
), | ||
tradeType: this.type | ||
}; | ||
} catch (err) { | ||
const rubicSdkError = CrossChainProvider.parseError(err); | ||
|
||
return { | ||
trade: null, | ||
error: rubicSdkError, | ||
tradeType: this.type | ||
}; | ||
} | ||
} | ||
|
||
protected async getFeeInfo( | ||
_fromBlockchain: CbridgeCrossChainSupportedBlockchain, | ||
_providerAddress: string, | ||
_percentFeeToken: PriceTokenAmount, | ||
_useProxy: boolean | ||
): Promise<FeeInfo> { | ||
return {}; | ||
} | ||
|
||
protected async getRoutePath( | ||
fromToken: PriceTokenAmount<EvmBlockchainName>, | ||
toToken: PriceTokenAmount<EvmBlockchainName> | ||
): Promise<RubicStep[]> { | ||
return [{ type: 'cross-chain', provider: this.type, path: [fromToken, toToken] }]; | ||
} | ||
} |
Oops, something went wrong.