-
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.
2690, add Lifi on-chain/cross-chain provider for Solana (#689)
- Loading branch information
Showing
29 changed files
with
785 additions
and
134 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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/* used for passing fromAddress in swap/quote requests with disabled wallet */ | ||
export const FAKE_WALLET_ADDRESS = '0xe388Ed184958062a2ea29B7fD049ca21244AE02e'; | ||
export const FAKE_SOLANA_WALLET_ADDRESS = '7cwWhuCJUHc27Dq4nQRhggwgeuVHEeS3NWv7BY6yY9Bk'; |
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,53 @@ | ||
import { BLOCKCHAIN_NAME, BlockchainName } from 'src/core/blockchain/models/blockchain-name'; | ||
import { blockchainId } from 'src/core/blockchain/utils/blockchains-info/constants/blockchain-id'; | ||
import { | ||
FAKE_SOLANA_WALLET_ADDRESS, | ||
FAKE_WALLET_ADDRESS | ||
} from 'src/features/common/constants/fake-wallet-address'; | ||
|
||
import { LifiCrossChainSupportedBlockchain } from '../../../cross-chain/calculation-manager/providers/lifi-provider/constants/lifi-cross-chain-supported-blockchain'; | ||
|
||
export class LifiUtilsService { | ||
private static readonly SOLANA_CHAIN_ID = 'SOL'; | ||
|
||
private static readonly SOLANA_NATIVE_TOKEN_ADDRESS = '11111111111111111111111111111111'; | ||
|
||
public static getLifiReceiverAddress( | ||
fromBlockchain: LifiCrossChainSupportedBlockchain, | ||
toBlockchain: LifiCrossChainSupportedBlockchain, | ||
fromAddress: string, | ||
receiverAddress: string | undefined | ||
): string { | ||
if (receiverAddress) { | ||
return receiverAddress; | ||
} | ||
|
||
if (fromBlockchain === BLOCKCHAIN_NAME.SOLANA) { | ||
return FAKE_WALLET_ADDRESS; | ||
} | ||
if (toBlockchain === BLOCKCHAIN_NAME.SOLANA) { | ||
return FAKE_SOLANA_WALLET_ADDRESS; | ||
} | ||
|
||
return fromAddress; | ||
} | ||
|
||
public static getLifiChainId(blockchain: BlockchainName): number | string { | ||
if (blockchain === BLOCKCHAIN_NAME.SOLANA) { | ||
return this.SOLANA_CHAIN_ID; | ||
} | ||
return blockchainId[blockchain]; | ||
} | ||
|
||
public static getLifiTokenAddress( | ||
blockchain: BlockchainName, | ||
isNative: boolean, | ||
tokenAddress: string | ||
): string { | ||
if (blockchain === BLOCKCHAIN_NAME.SOLANA && isNative) { | ||
return this.SOLANA_NATIVE_TOKEN_ADDRESS; | ||
} | ||
|
||
return tokenAddress; | ||
} | ||
} |
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,17 @@ | ||
import { PriceTokenAmount } from 'src/common/tokens'; | ||
|
||
const DEFAULT_FEE_PERCENT = 0.02; | ||
|
||
export function getSolanaFee(from: PriceTokenAmount): number { | ||
if (!from.price) { | ||
return DEFAULT_FEE_PERCENT; | ||
} | ||
|
||
const usdTokenAmount = from.tokenAmount.multipliedBy(from.price); | ||
|
||
if (usdTokenAmount.gt(100)) { | ||
return DEFAULT_FEE_PERCENT; | ||
} | ||
|
||
return 0; | ||
} |
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
Oops, something went wrong.