From aa9efd472dc76c6b434ecb87d95a8347573c65d8 Mon Sep 17 00:00:00 2001 From: Benjamin Patch Date: Thu, 20 Jul 2023 10:27:35 +1000 Subject: [PATCH] initial secondary fees config addition --- packages/internal/dex/sdk/src/config/index.ts | 8 ++++++-- .../internal/dex/sdk/src/errors/exchangeError.ts | 6 ++++++ packages/internal/dex/sdk/src/types/index.ts | 12 ++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/internal/dex/sdk/src/config/index.ts b/packages/internal/dex/sdk/src/config/index.ts index 35b62dcee0..6c0d586ddf 100644 --- a/packages/internal/dex/sdk/src/config/index.ts +++ b/packages/internal/dex/sdk/src/config/index.ts @@ -2,7 +2,7 @@ import { Environment, ImmutableConfiguration } from '@imtbl/config'; import { IMMUTABLE_TESTNET_COMMON_ROUTING_TOKENS, TIMX_IMMUTABLE_TESTNET } from 'constants/tokens'; import { ChainNotSupportedError, InvalidConfigurationError } from 'errors'; import { IMMUTABLE_TESTNET_CHAIN_ID, IMMUTABLE_TESTNET_RPC_URL } from 'constants/chains'; -import { isValidNonZeroAddress } from 'lib'; +import { SecondaryFees, isValidNonZeroAddress } from 'lib'; import { Chain, ExchangeModuleConfiguration, ExchangeOverrides } from '../types'; export type ExchangeContracts = { @@ -40,7 +40,7 @@ export const SUPPORTED_CHAIN_IDS_FOR_ENVIRONMENT: Record { - if (!value) { + if (!value && key !== 'secondaryFees') { throw new InvalidConfigurationError(`Missing override: ${key}`); } }); @@ -62,6 +62,8 @@ export class ExchangeConfiguration { public chain: Chain; + public secondaryFees?: SecondaryFees; + constructor({ chainId, baseConfig, overrides }: ExchangeModuleConfiguration) { this.baseConfig = baseConfig; @@ -75,6 +77,8 @@ export class ExchangeConfiguration { nativeToken: overrides.nativeToken, }; + this.secondaryFees = overrides.secondaryFees; + return; } diff --git a/packages/internal/dex/sdk/src/errors/exchangeError.ts b/packages/internal/dex/sdk/src/errors/exchangeError.ts index ade0587ca7..fc9e7dbd75 100644 --- a/packages/internal/dex/sdk/src/errors/exchangeError.ts +++ b/packages/internal/dex/sdk/src/errors/exchangeError.ts @@ -56,6 +56,12 @@ export class ChainNotSupportedError extends ExchangeError { } } +export class InvalidFeePrcntError extends ExchangeError { + constructor(feedPrcnt: number) { + super(`invalid fee percent: ${feedPrcnt}`, ExchangeErrorCode.INVALID_SLIPPAGE); + } +} + export class InvalidSlippageError extends ExchangeError { constructor(message: string) { super(message, ExchangeErrorCode.INVALID_SLIPPAGE); diff --git a/packages/internal/dex/sdk/src/types/index.ts b/packages/internal/dex/sdk/src/types/index.ts index 7bede060c9..db99bd8b03 100644 --- a/packages/internal/dex/sdk/src/types/index.ts +++ b/packages/internal/dex/sdk/src/types/index.ts @@ -18,6 +18,17 @@ export type Chain = { nativeToken: TokenInfo; }; +/** + * Interface representing the secondary fees for a swap + * @property {string[]} feeRecipients - The fee recipient addresses + * @property {ethers.BigNumber[]} feePrcntsInBasisPoints - The fee percentages in basis points + * @example [100, 200, 300] would represent 1%, 2%, and 3% respectively + */ +export type SecondaryFees = { + feeRecipients: string[]; + feePrcntsInBasisPoints: ethers.BigNumber[]; +}; + /** * Interface representing an amount with the token information * @property {TokenInfo} token - The token information @@ -83,6 +94,7 @@ export interface ExchangeOverrides { exchangeContracts: ExchangeContracts; commonRoutingTokens: TokenInfo[]; nativeToken: TokenInfo; + secondaryFees?: SecondaryFees; } export interface ExchangeModuleConfiguration