Skip to content

Commit

Permalink
Fix Spark DEX v3.1 (5.45.6)
Browse files Browse the repository at this point in the history
  • Loading branch information
axtezy authored Nov 25, 2024
2 parents 6985b5e + d2c5424 commit df46749
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rubic-sdk",
"version": "5.45.5",
"version": "5.45.6",
"description": "Simplify dApp creation",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ export class EvmWeb3Public extends Web3Public {
private allowMultipleRequests(err: unknown): boolean {
return (
(err instanceof Error && err.message.includes('unsigned transaction')) ||
this.blockchainName === BLOCKCHAIN_NAME.ZETACHAIN
this.blockchainName === BLOCKCHAIN_NAME.ZETACHAIN ||
(err instanceof Error && err.message.includes('out of gas'))
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import BigNumber from 'bignumber.js';
import { RubicSdkError } from 'src/common/errors';
import { Token } from 'src/common/tokens';
import { compareAddresses } from 'src/common/utils/blockchain';
import { notNull } from 'src/common/utils/object';
import { EvmBlockchainName } from 'src/core/blockchain/models/blockchain-name';
import { MethodData } from 'src/core/blockchain/web3-public-service/web3-public/models/method-data';
import { Exact } from 'src/features/on-chain/calculation-manager/providers/common/on-chain-trade/evm-on-chain-trade/models/exact';
import { UniswapV3Route } from 'src/features/on-chain/calculation-manager/providers/dexes/common/uniswap-v3-abstract/models/uniswap-v3-route';
import { AbiItem } from 'web3-utils';

import { UniswapV3RouterConfiguration } from '../../models/uniswap-v3-router-configuration';
import { LiquidityPool } from './models/liquidity-pool';
import { FeeAmount, LiquidityPool } from './models/liquidity-pool';
import { UniswapV3QuoterController } from './uniswap-v3-quoter-controller';

interface GetQuoterMethodsDataOptions {
Expand All @@ -27,6 +31,8 @@ interface QuoteExactInputSingleParams {
}

export class SparkDexV3QuoterController extends UniswapV3QuoterController {
protected readonly feeAmounts: FeeAmount[] = [100, 500, 3000];

constructor(
blockchain: EvmBlockchainName,
routerConfiguration: UniswapV3RouterConfiguration<string>,
Expand Down Expand Up @@ -136,4 +142,62 @@ export class SparkDexV3QuoterController extends UniswapV3QuoterController {
})
.flat();
}

public async getAllRoutes(
from: Token,
to: Token,
exact: Exact,
weiAmount: string,
routeMaxTransitTokens: number
): Promise<UniswapV3Route[]> {
const routesLiquidityPools = await this.getAllLiquidityPools(from, to);
const options: Omit<GetQuoterMethodsDataOptions, 'maxTransitTokens'> = {
routesLiquidityPools,
from,
to,
exact,
weiAmount
};
const quoterMethodsData = [...Array(routeMaxTransitTokens + 1)]
.map((_, maxTransitTokens) =>
this.getQuoterMethodsData(
{
...options,
maxTransitTokens
},
[],
from.address
)
)
.flat();

const results = await this.web3Public.multicallContractMethods<
string | { amountOut: string }
>(
this.quoterContractAddress,
this.quoterContractABI,
quoterMethodsData.map(quoterMethodData => quoterMethodData.methodData)
);

return results
.map((result, index) => {
const pool = quoterMethodsData?.[index];
if (!pool) {
throw new RubicSdkError('Pool has to be defined');
}
if (result.success) {
return {
outputAbsoluteAmount: new BigNumber(
result?.output! instanceof Object
? result?.output?.amountOut
: result.output!
),
poolsPath: pool.poolsPath,
initialTokenAddress: from.address
};
}
return null;
})
.filter(notNull);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbiItem } from 'web3-utils';

export const SPARK_DEX_V3_FLARE_SWAP_ROUTER_CONTRACT = '0xCb70f9bA912a99849d19FC24Ccb7925ED307b877';
export const SPARK_DEX_V3_FLARE_SWAP_ROUTER_CONTRACT = '0x8a1E35F5c98C4E85B36B7B253222eE17773b2781';

export const SPARK_DEX_V3_FLARE_SWAP_ROUTER_ABI: AbiItem[] = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AbiItem } from 'web3-utils';

export const SPARK_DEX_V3_FLARE_QUOTER_CONTRACT_ADDRESS =
'0x2DcABbB3a5Fe9DBb1F43edf48449aA7254Ef3a80';
'0x5B5513c55fd06e2658010c121c37b07fC8e8B705';

export const SPARK_DEX_V3_FLARE_QUOTER_CONTRACT_ABI: AbiItem[] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { compareAddresses } from 'src/common/utils/blockchain';
import { BLOCKCHAIN_NAME } from 'src/core/blockchain/models/blockchain-name';
import { EvmWeb3Pure } from 'src/core/blockchain/web3-pure/typed-web3-pure/evm-web3-pure/evm-web3-pure';
import { createTokenNativeAddressProxyInPathStartAndEnd } from 'src/features/common/utils/token-native-address-proxy';
import { UNI_SWAP_V3_SPARK_DEX_FLARE_ROUTER_CONFIGURATION } from 'src/features/on-chain/calculation-manager/providers/dexes/flare/spark-dex-flare/spark-dex-v3-flare/constants/spark-dex-v3-flare-router-config';

import {
ON_CHAIN_TRADE_TYPE,
Expand All @@ -22,7 +23,6 @@ import {
SPARK_DEX_V3_FLARE_QUOTER_CONTRACT_ABI,
SPARK_DEX_V3_FLARE_QUOTER_CONTRACT_ADDRESS
} from './constants/spark-dex-v3-flare-quoter-data';
import { UNI_SWAP_V3_SPARK_DEX_FLARE_ROUTER_CONFIGURATION } from './constants/uniswap-v3-spark-dex-flare-router-config';
import { SparkDexV3FlareTrade } from './spark-dex-v3-flare-trade';

export class SparkDexV3FlareProvider extends UniswapV3AlgebraAbstractProvider<SparkDexV3FlareTrade> {
Expand All @@ -47,7 +47,7 @@ export class SparkDexV3FlareProvider extends UniswapV3AlgebraAbstractProvider<Sp
this.routerConfiguration,
SPARK_DEX_V3_FLARE_QUOTER_CONTRACT_ADDRESS,
SPARK_DEX_V3_FLARE_QUOTER_CONTRACT_ABI,
'0xb3fB4f96175f6f9D716c17744e5A6d4BA9da8176'
'0x8A2578d23d4C532cC9A98FaD91C0523f5efDE652'
);

protected createTradeInstance(
Expand Down

0 comments on commit df46749

Please sign in to comment.