-
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.
add router cross chain provider (#675)
- Loading branch information
Showing
16 changed files
with
883 additions
and
7 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
41 changes: 41 additions & 0 deletions
41
src/features/common/providers/router/models/router-quote-response-config.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,41 @@ | ||
type RouterFlowType = 'trustless' | 'mint-burn' | 'circle' | 'gateway' | 'none'; | ||
|
||
interface RouterAsset { | ||
decimals: number; | ||
symbol: string; | ||
name: string; | ||
chainId: string; | ||
address: string; | ||
resourceID: string; | ||
isMintable: boolean; | ||
isWrappedAsset: boolean; | ||
} | ||
|
||
interface RouterSwapTokenInfo { | ||
chainId: string; | ||
asset: RouterAsset; | ||
stableReserveAsset: RouterAsset; | ||
tokenAmount: string; | ||
stableReserveAmount: string; | ||
path: string[]; | ||
flags: string[]; | ||
priceImpact: string; | ||
tokenPath: string; | ||
dataTx: string[]; | ||
} | ||
|
||
export interface RouterQuoteResponseConfig { | ||
flowType: RouterFlowType; | ||
isTransfer: boolean; | ||
isWrappedToken: boolean; | ||
allowanceTo: string; | ||
fromTokenAddress: string; | ||
toTokenAddress: string; | ||
source: RouterSwapTokenInfo & { | ||
bridgeFeeAmount: string; | ||
}; | ||
destination: RouterSwapTokenInfo; | ||
partnerId: number; | ||
estimatedTime: number; | ||
slippageTolerance: number; | ||
} |
8 changes: 8 additions & 0 deletions
8
src/features/common/providers/router/models/router-quote-send-params.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,8 @@ | ||
export interface RouterQuoteSendParams { | ||
amount: string; | ||
fromTokenAddress: string; | ||
fromTokenChainId: string; | ||
toTokenAddress: string; | ||
toTokenChainId: string; | ||
slippageTolerance?: number; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/features/common/providers/router/models/router-send-transaction-params.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,23 @@ | ||
import { RouterQuoteResponseConfig } from './router-quote-response-config'; | ||
|
||
export interface RouterSendTransactionParams extends RouterQuoteResponseConfig { | ||
senderAddress: string; | ||
receiverAddress: string; | ||
refundAddress: string; | ||
} | ||
|
||
export interface RouterSendTransactionResponse extends RouterSendTransactionParams { | ||
txn: { | ||
from: string; | ||
value: string; | ||
to: string; | ||
data: string; | ||
gasPrice: string; | ||
gasLimit: string; | ||
}; | ||
} | ||
|
||
export interface RouterTxStatusResponse { | ||
status: 'completed' | 'pending'; | ||
dest_tx_hash: string; | ||
} |
57 changes: 57 additions & 0 deletions
57
src/features/common/providers/router/services/router-api-service.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,57 @@ | ||
import { TX_STATUS } from 'src/core/blockchain/web3-public-service/web3-public/models/tx-status'; | ||
import { Injector } from 'src/core/injector/injector'; | ||
import { TxStatusData } from 'src/features/common/status-manager/models/tx-status-data'; | ||
import { CrossChainTradeData } from 'src/features/cross-chain/status-manager/models/cross-chain-trade-data'; | ||
|
||
import { RouterQuoteResponseConfig } from '../models/router-quote-response-config'; | ||
import { RouterQuoteSendParams } from '../models/router-quote-send-params'; | ||
import { | ||
RouterSendTransactionParams, | ||
RouterSendTransactionResponse, | ||
RouterTxStatusResponse | ||
} from '../models/router-send-transaction-params'; | ||
|
||
export class RouterApiService { | ||
private static readonly ROUTER_ENDPOINT = | ||
'https://api-beta.pathfinder.routerprotocol.com/api/v2'; | ||
|
||
private static readonly partnerId = 159; | ||
|
||
public static async getQuote( | ||
params: RouterQuoteSendParams | ||
): Promise<RouterQuoteResponseConfig> { | ||
return Injector.httpClient.get<RouterQuoteResponseConfig>(`${this.ROUTER_ENDPOINT}/quote`, { | ||
params: { ...params, partnerId: this.partnerId } | ||
}); | ||
} | ||
|
||
public static async getSwapTx( | ||
params: RouterSendTransactionParams | ||
): Promise<RouterSendTransactionResponse> { | ||
return Injector.httpClient.post<RouterSendTransactionResponse>( | ||
`${this.ROUTER_ENDPOINT}/transaction`, | ||
params | ||
); | ||
} | ||
|
||
public static async getTxStatus(data: CrossChainTradeData): Promise<TxStatusData> { | ||
const txData = await Injector.httpClient.get<RouterTxStatusResponse>( | ||
`${this.ROUTER_ENDPOINT}/status`, | ||
{ | ||
params: { | ||
srcTxHash: data.srcTxHash | ||
} | ||
} | ||
); | ||
if (txData.status === 'completed') { | ||
return { | ||
hash: txData.dest_tx_hash, | ||
status: TX_STATUS.SUCCESS | ||
}; | ||
} | ||
return { | ||
hash: null, | ||
status: TX_STATUS.PENDING | ||
}; | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
...lation-manager/providers/router-provider/constants/router-cross-chain-supported-chains.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,30 @@ | ||
import { BLOCKCHAIN_NAME } from 'src/core/blockchain/models/blockchain-name'; | ||
|
||
export const routerCrossChainSupportedChains = [ | ||
BLOCKCHAIN_NAME.ETHEREUM, | ||
BLOCKCHAIN_NAME.OPTIMISM, | ||
BLOCKCHAIN_NAME.ROOTSTOCK, | ||
BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN, | ||
BLOCKCHAIN_NAME.POLYGON, | ||
BLOCKCHAIN_NAME.MANTA_PACIFIC, | ||
BLOCKCHAIN_NAME.XLAYER, | ||
BLOCKCHAIN_NAME.FANTOM, | ||
BLOCKCHAIN_NAME.BOBA, | ||
BLOCKCHAIN_NAME.ZK_SYNC, | ||
BLOCKCHAIN_NAME.METIS, | ||
BLOCKCHAIN_NAME.POLYGON_ZKEVM, | ||
BLOCKCHAIN_NAME.MANTLE, | ||
BLOCKCHAIN_NAME.BASE, | ||
BLOCKCHAIN_NAME.MODE, | ||
BLOCKCHAIN_NAME.ARBITRUM, | ||
BLOCKCHAIN_NAME.AVALANCHE, | ||
BLOCKCHAIN_NAME.LINEA, | ||
BLOCKCHAIN_NAME.BLAST, | ||
BLOCKCHAIN_NAME.TAIKO, | ||
BLOCKCHAIN_NAME.SCROLL, | ||
BLOCKCHAIN_NAME.TRON, | ||
BLOCKCHAIN_NAME.AURORA | ||
// BLOCKCHAIN_NAME.SOLANA | ||
]; | ||
|
||
export type RouterCrossChainSupportedBlockchains = (typeof routerCrossChainSupportedChains)[number]; |
Oops, something went wrong.