Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NOJIRA] incorrect max secondary fee basis points #1012

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/internal/dex/sdk/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"parserOptions": {
"project": "./tsconfig.json",
"tsconfigRootDir": "."
},
"rules": {
"implicit-arrow-linebreak": "off"
}
}
141 changes: 81 additions & 60 deletions packages/internal/dex/sdk/src/config/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { Environment, ImmutableConfiguration } from '@imtbl/config';
import { ChainNotSupportedError, InvalidConfigurationError } from 'errors';
import * as test from 'test/utils';
import { ExchangeModuleConfiguration, ExchangeOverrides, TokenInfo } from '../types';
import { ExchangeModuleConfiguration, ExchangeOverrides, ERC20 } from '../types';
import { ExchangeConfiguration, ExchangeContracts } from './index';
import { IMMUTABLE_TESTNET_CHAIN_ID } from '../constants/chains';

describe('ExchangeConfiguration', () => {
const chainId = 999999999;
// This list can be updated with any Tokens that are deployed to the chain being configured
// These tokens will be used to find available pools for a swap
const commonRoutingTokensSingle: TokenInfo[] = [
const commonRoutingTokensSingle: ERC20[] = [
{
type: 'erc20',
chainId,
address: '0x12958b06abdf2701ace6ceb3ce0b8b1ce11e0851',
decimals: 18,
Expand Down Expand Up @@ -71,22 +72,25 @@ describe('ExchangeConfiguration', () => {

// This list can be updated with any Tokens that are deployed to the chain being configured
// These tokens will be used to find available pools for a swap
const commonRoutingTokens: TokenInfo[] = [
const commonRoutingTokens: ERC20[] = [
{
type: 'erc20',
chainId,
address: '0x12958b06abdf2701ace6ceb3ce0b8b1ce11e0851',
decimals: 18,
symbol: 'FUN',
name: 'The Fungibles Token',
},
{
type: 'erc20',
chainId,
address: '0x22958b06abdf2701ace6ceb3ce0b8b1ce11e0851',
decimals: 18,
symbol: 'USDC',
name: 'US Dollar Coin',
},
{
type: 'erc20',
chainId,
address: '0x32958b06abdf2701ace6ceb3ce0b8b1ce11e0851',
decimals: 18,
Expand Down Expand Up @@ -126,24 +130,25 @@ describe('ExchangeConfiguration', () => {
expect(config.chain.contracts.peripheryRouter).toBe(contractOverrides.peripheryRouter);
expect(config.chain.contracts.quoterV2).toBe(contractOverrides.quoterV2);
// tokens
expect(config.chain.commonRoutingTokens[0].address.toLocaleLowerCase())
.toEqual(commonRoutingTokens[0].address.toLocaleLowerCase());
expect(config.chain.commonRoutingTokens[0].address.toLocaleLowerCase()).toEqual(
commonRoutingTokens[0].address.toLocaleLowerCase(),
);

expect(config.chain.commonRoutingTokens[1].address.toLowerCase())
.toEqual(commonRoutingTokens[1].address.toLowerCase());
expect(config.chain.commonRoutingTokens[1].address.toLowerCase()).toEqual(
commonRoutingTokens[1].address.toLowerCase(),
);

expect(config.chain.commonRoutingTokens[2].address.toLowerCase())
.toEqual(commonRoutingTokens[2].address.toLowerCase());
expect(config.chain.commonRoutingTokens[2].address.toLowerCase()).toEqual(
commonRoutingTokens[2].address.toLowerCase(),
);

expect(config.secondaryFees).toBeDefined();
if (!config.secondaryFees) {
// This should never happen
throw new Error('Secondary fees should be defined');
}
expect(config.secondaryFees[0].recipient.toLowerCase())
.toEqual(dummyFeeRecipient.toLowerCase());
expect(config.secondaryFees[0].basisPoints.toString())
.toEqual(secondaryFees[0].basisPoints.toString());
expect(config.secondaryFees[0].recipient.toLowerCase()).toEqual(dummyFeeRecipient.toLowerCase());
expect(config.secondaryFees[0].basisPoints.toString()).toEqual(secondaryFees[0].basisPoints.toString());
});

it('should throw when missing configuration', () => {
Expand All @@ -167,11 +172,14 @@ describe('ExchangeConfiguration', () => {
nativeToken: test.IMX_TEST_TOKEN,
};

expect(() => new ExchangeConfiguration({
chainId,
baseConfig: immutableConfig,
overrides,
})).toThrow(new InvalidConfigurationError('Invalid exchange contract address for multicall'));
expect(
() =>
new ExchangeConfiguration({
chainId,
baseConfig: immutableConfig,
overrides,
}),
).toThrow(new InvalidConfigurationError('Invalid exchange contract address for multicall'));
});

it('show throw when given an invalid RPC URL', () => {
Expand All @@ -187,11 +195,14 @@ describe('ExchangeConfiguration', () => {
nativeToken: test.IMX_TEST_TOKEN,
};

expect(() => new ExchangeConfiguration({
chainId,
baseConfig: immutableConfig,
overrides,
})).toThrow(new InvalidConfigurationError('Missing override: rpcURL'));
expect(
() =>
new ExchangeConfiguration({
chainId,
baseConfig: immutableConfig,
overrides,
}),
).toThrow(new InvalidConfigurationError('Missing override: rpcURL'));
});

it('should throw when given an invalid secondary fee recipient address', () => {
Expand All @@ -216,14 +227,17 @@ describe('ExchangeConfiguration', () => {
nativeToken: test.IMX_TEST_TOKEN,
};

expect(() => new ExchangeConfiguration({
baseConfig: immutableConfig,
chainId,
secondaryFees,
overrides,
})).toThrow(new InvalidConfigurationError(
`Invalid secondary fee recipient address: ${secondaryFees[0].recipient}`,
));
expect(
() =>
new ExchangeConfiguration({
baseConfig: immutableConfig,
chainId,
secondaryFees,
overrides,
}),
).toThrow(
new InvalidConfigurationError(`Invalid secondary fee recipient address: ${secondaryFees[0].recipient}`),
);
});

it('should throw when given invalid secondary fee basis points', () => {
Expand All @@ -236,22 +250,22 @@ describe('ExchangeConfiguration', () => {
const secondaryFeesOneRecipient = [
{
recipient: dummyFeeRecipient,
basisPoints: 10001,
basisPoints: 1001,
},
];

const secondaryFeesMultipleRecipients = [
{
recipient: dummyFeeRecipient,
basisPoints: 5000,
basisPoints: 500,
},
{
recipient: dummyFeeRecipient,
basisPoints: 5000,
basisPoints: 500,
},
{
recipient: dummyFeeRecipient,
basisPoints: 1000,
basisPoints: 100,
},
];

Expand All @@ -270,32 +284,39 @@ describe('ExchangeConfiguration', () => {
nativeToken: test.IMX_TEST_TOKEN,
};

expect(() => new ExchangeConfiguration({
baseConfig: immutableConfig,
chainId,
secondaryFees: secondaryFeesOneRecipient,
overrides,
})).toThrow(new InvalidConfigurationError(
`Invalid secondary fee basis points: ${secondaryFeesOneRecipient[0].basisPoints}`,
));

expect(() => new ExchangeConfiguration({
baseConfig: immutableConfig,
chainId,
secondaryFees: secondaryFeesMultipleRecipients,
overrides,
})).toThrow(new InvalidConfigurationError(
'Invalid total secondary fee basis points: 11000',
));
expect(
() =>
new ExchangeConfiguration({
baseConfig: immutableConfig,
chainId,
secondaryFees: secondaryFeesOneRecipient,
overrides,
}),
).toThrow(
new InvalidConfigurationError(
`Invalid secondary fee basis points: ${secondaryFeesOneRecipient[0].basisPoints}`,
),
);

expect(() => new ExchangeConfiguration({
baseConfig: immutableConfig,
chainId,
secondaryFees: secondaryFeesWithZeroBasisPoints,
overrides,
})).toThrow(new InvalidConfigurationError(
'Invalid secondary fee basis points: 0',
));
expect(
() =>
new ExchangeConfiguration({
baseConfig: immutableConfig,
chainId,
secondaryFees: secondaryFeesMultipleRecipients,
overrides,
}),
).toThrow(new InvalidConfigurationError('Invalid total secondary fee basis points: 1100'));

expect(
() =>
new ExchangeConfiguration({
baseConfig: immutableConfig,
chainId,
secondaryFees: secondaryFeesWithZeroBasisPoints,
overrides,
}),
).toThrow(new InvalidConfigurationError('Invalid secondary fee basis points: 0'));
});

it('should not set secondary fees when not given', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/dex/sdk/src/constants/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ export const MIN_MAX_HOPS: number = 1;
export const BASIS_POINT_PRECISION = 10_000;

// 10% maximum secondary fee
export const MAX_SECONDARY_FEE_BASIS_POINTS = 10000;
export const MAX_SECONDARY_FEE_BASIS_POINTS = 1000;