From cf0f6615c3fe422a53ebc2e6abdeca9178513d49 Mon Sep 17 00:00:00 2001 From: Mohammad Reza Lotfi Date: Wed, 25 Sep 2024 10:00:58 +0330 Subject: [PATCH] Accept Solana's WETH as input locked tokens (#13) Co-authored-by: mrlotfi --- src/driver/driver.ts | 3 ++- src/relayer.ts | 6 +++++- src/utils/fees.ts | 15 +++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/driver/driver.ts b/src/driver/driver.ts index 34098f8..587b179 100644 --- a/src/driver/driver.ts +++ b/src/driver/driver.ts @@ -178,6 +178,7 @@ export class DriverService { const fromNativeUSDT = this.tokenList.getNativeUsdt(srcChain); const fromNativeUSDC = this.tokenList.getNativeUsdc(srcChain); const fromEth = this.tokenList.getEth(srcChain); + const fromSolWeth = srcChain === CHAIN_ID_SOLANA ? this.tokenList.getWethSol() : null; if (fromToken.contract === fromNativeUSDC?.contract || fromToken.contract === fromNativeUSDT?.contract) { const destUsdc = this.tokenList.getNativeUsdc(destChain); @@ -187,7 +188,7 @@ export class DriverService { } return (destUsdc || destUsdt)!; - } else if (fromToken.contract === fromEth?.contract) { + } else if (fromToken.contract === fromEth?.contract || fromToken.contract === fromSolWeth?.contract) { return this.tokenList.getEth(destChain)!; } else { throw new Error( diff --git a/src/relayer.ts b/src/relayer.ts index cff4e4b..f6f9fe7 100644 --- a/src/relayer.ts +++ b/src/relayer.ts @@ -496,7 +496,11 @@ export class Relayer { private isInputTokenAcceptable(swap: Swap) { // We only accept ETH and USDC as input tokens (except for bsc) in our quote API so we are ignoring anything - let acceptedTokens = [this.tokenList.getEth(swap.sourceChain), this.tokenList.getNativeUsdc(swap.sourceChain)]; + let acceptedTokens = [ + this.tokenList.getEth(swap.sourceChain), + this.tokenList.getNativeUsdc(swap.sourceChain), + this.tokenList.getWethSol(), + ]; if (swap.sourceChain === CHAIN_ID_BSC) { acceptedTokens.push(this.tokenList.getNativeUsdt(swap.sourceChain)); } diff --git a/src/utils/fees.ts b/src/utils/fees.ts index ed63f10..21213bc 100644 --- a/src/utils/fees.ts +++ b/src/utils/fees.ts @@ -3,6 +3,7 @@ import * as mathjs from 'mathjs'; import { CHAIN_ID_ARBITRUM, CHAIN_ID_BASE, + CHAIN_ID_BSC, CHAIN_ID_ETH, CHAIN_ID_OPTIMISM, CHAIN_ID_POLYGON, @@ -45,6 +46,7 @@ export class FeeService { const sourceUsdt = this.tokenList.getNativeUsdt(qr.fromChainId); const sourceUsdc = this.tokenList.getNativeUsdc(qr.fromChainId); const sourceEth = this.tokenList.getEth(qr.fromChainId); + const sourceSolEth = qr.fromChainId === CHAIN_ID_SOLANA ? this.tokenList.getWethSol() : null; const destUsdt = this.tokenList.getNativeUsdt(qr.toChainId); const destUsdc = this.tokenList.getNativeUsdc(qr.toChainId); const destEth = this.tokenList.getEth(qr.toChainId); @@ -68,7 +70,7 @@ export class FeeService { let baseFulfillGasWithBatch = this.gConf.feeParams.baseFulfillGasWithBatchEth; let baseFulfillGasWithOutBatch = this.gConf.feeParams.baseFulfillGasWithOutBatchEth; - if (qr.fromToken.contract !== sourceEth?.contract) { + if (qr.fromToken.contract !== sourceEth?.contract && qr.fromToken.contract !== sourceSolEth?.contract) { // when source is not eth, usdc (or other erc20) must be used at dest to fulfill and more gas overhead baseFulfillGasWithOutBatch += this.gConf.feeParams.erc20GasOverHead; baseFulfillGasWithBatch += this.gConf.feeParams.erc20GasOverHead; @@ -89,10 +91,15 @@ export class FeeService { let hasDestSwap = true; if ( - (sourceUsdc?.contract === qr.fromToken.contract && destUsdt?.contract === qr.toToken.contract) || - (sourceUsdt?.contract === qr.fromToken.contract && destUsdc?.contract === qr.toToken.contract) || + (sourceUsdc?.contract === qr.fromToken.contract && + destUsdt?.contract === qr.toToken.contract && + qr.toChainId === CHAIN_ID_BSC) || + (sourceUsdt?.contract === qr.fromToken.contract && + qr.fromChainId === CHAIN_ID_BSC && + destUsdc?.contract === qr.toToken.contract) || (sourceUsdc?.contract === qr.fromToken.contract && destUsdc?.contract === qr.toToken.contract) || - (sourceEth?.contract === qr.fromToken.contract && destEth?.contract === qr.toToken.contract) + (sourceEth?.contract === qr.fromToken.contract && destEth?.contract === qr.toToken.contract) || + (sourceSolEth?.contract === qr.fromToken.contract && destEth?.contract === qr.toToken.contract) ) { hasDestSwap = false; }