Skip to content

Commit

Permalink
initial secondary fees config addition
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjimmutable committed Jul 20, 2023
1 parent b2a516b commit aa9efd4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/internal/dex/sdk/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -40,7 +40,7 @@ export const SUPPORTED_CHAIN_IDS_FOR_ENVIRONMENT: Record<Environment, Record<num

function validateOverrides(overrides: ExchangeOverrides) {
Object.entries(overrides).forEach(([key, value]) => {
if (!value) {
if (!value && key !== 'secondaryFees') {
throw new InvalidConfigurationError(`Missing override: ${key}`);
}
});
Expand All @@ -62,6 +62,8 @@ export class ExchangeConfiguration {

public chain: Chain;

public secondaryFees?: SecondaryFees;

constructor({ chainId, baseConfig, overrides }: ExchangeModuleConfiguration) {
this.baseConfig = baseConfig;

Expand All @@ -75,6 +77,8 @@ export class ExchangeConfiguration {
nativeToken: overrides.nativeToken,
};

this.secondaryFees = overrides.secondaryFees;

return;
}

Expand Down
6 changes: 6 additions & 0 deletions packages/internal/dex/sdk/src/errors/exchangeError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions packages/internal/dex/sdk/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -83,6 +94,7 @@ export interface ExchangeOverrides {
exchangeContracts: ExchangeContracts;
commonRoutingTokens: TokenInfo[];
nativeToken: TokenInfo;
secondaryFees?: SecondaryFees;
}

export interface ExchangeModuleConfiguration
Expand Down

0 comments on commit aa9efd4

Please sign in to comment.