Skip to content

Commit

Permalink
Accept Solana's WETH as input locked tokens (#13)
Browse files Browse the repository at this point in the history
Co-authored-by: mrlotfi <[email protected]>
  • Loading branch information
mrlotfi and mrlotfi authored Sep 25, 2024
1 parent d3a5a9f commit cf0f661
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/driver/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(
Expand Down
6 changes: 5 additions & 1 deletion src/relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
15 changes: 11 additions & 4 deletions src/utils/fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit cf0f661

Please sign in to comment.