@paraswap/dex-lib 2.42.4-baseswap → 2.42.4-baseswap.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/dex/index.js +0 -2
- package/build/dex/index.js.map +1 -1
- package/build/dex/uniswap-v3/config.js +14 -0
- package/build/dex/uniswap-v3/config.js.map +1 -1
- package/package.json +1 -1
- package/src/dex/index.ts +0 -2
- package/src/dex/uniswap-v3/config.ts +14 -0
- package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +24 -0
- package/src/dex/uniswap-v3/uniswap-v3-integration.test.ts +375 -0
- package/src/dex/baseswap-v3/baseswap-v3-e2e.test.ts +0 -129
- package/src/dex/baseswap-v3/baseswap-v3-events.test.ts +0 -141
- package/src/dex/baseswap-v3/baseswap-v3-factory.ts +0 -73
- package/src/dex/baseswap-v3/baseswap-v3-integration.test.ts +0 -472
- package/src/dex/baseswap-v3/baseswap-v3-pool.ts +0 -519
- package/src/dex/baseswap-v3/baseswap-v3.ts +0 -1243
- package/src/dex/baseswap-v3/config.ts +0 -53
- package/src/dex/baseswap-v3/constants.ts +0 -41
- package/src/dex/baseswap-v3/contract-math/BitMath.ts +0 -90
- package/src/dex/baseswap-v3/contract-math/FixedPoint128.ts +0 -3
- package/src/dex/baseswap-v3/contract-math/FixedPoint96.ts +0 -4
- package/src/dex/baseswap-v3/contract-math/FullMath.ts +0 -30
- package/src/dex/baseswap-v3/contract-math/LiquidityMath.ts +0 -17
- package/src/dex/baseswap-v3/contract-math/Oracle.ts +0 -226
- package/src/dex/baseswap-v3/contract-math/SqrtPriceMath.ts +0 -226
- package/src/dex/baseswap-v3/contract-math/SwapMath.ts +0 -139
- package/src/dex/baseswap-v3/contract-math/Tick.ts +0 -82
- package/src/dex/baseswap-v3/contract-math/TickBitMap.ts +0 -123
- package/src/dex/baseswap-v3/contract-math/TickMath.ts +0 -211
- package/src/dex/baseswap-v3/contract-math/UnsafeMath.ts +0 -5
- package/src/dex/baseswap-v3/contract-math/uniswap-v3-math.ts +0 -666
- package/src/dex/baseswap-v3/contract-math/utils.ts +0 -55
- package/src/dex/baseswap-v3/types.ts +0 -191
- package/src/dex/baseswap-v3/utils.ts +0 -83
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import dotenv from 'dotenv';
|
|
2
|
-
dotenv.config();
|
|
3
|
-
|
|
4
|
-
import { testE2E } from '../../../tests/utils-e2e';
|
|
5
|
-
import {
|
|
6
|
-
Tokens,
|
|
7
|
-
Holders,
|
|
8
|
-
NativeTokenSymbols,
|
|
9
|
-
} from '../../../tests/constants-e2e';
|
|
10
|
-
import { Network, ContractMethod, SwapSide } from '../../constants';
|
|
11
|
-
import { StaticJsonRpcProvider } from '@ethersproject/providers';
|
|
12
|
-
import { generateConfig } from '../../config';
|
|
13
|
-
|
|
14
|
-
function testForNetwork(
|
|
15
|
-
network: Network,
|
|
16
|
-
dexKey: string,
|
|
17
|
-
tokenASymbol: string,
|
|
18
|
-
tokenBSymbol: string,
|
|
19
|
-
tokenAAmount: string,
|
|
20
|
-
tokenBAmount: string,
|
|
21
|
-
nativeTokenAmount: string,
|
|
22
|
-
slippage?: number | undefined,
|
|
23
|
-
) {
|
|
24
|
-
const provider = new StaticJsonRpcProvider(
|
|
25
|
-
generateConfig(network).privateHttpProvider,
|
|
26
|
-
network,
|
|
27
|
-
);
|
|
28
|
-
const tokens = Tokens[network];
|
|
29
|
-
const holders = Holders[network];
|
|
30
|
-
const nativeTokenSymbol = NativeTokenSymbols[network];
|
|
31
|
-
|
|
32
|
-
const sideToContractMethods = new Map([
|
|
33
|
-
[
|
|
34
|
-
SwapSide.SELL,
|
|
35
|
-
[
|
|
36
|
-
ContractMethod.simpleSwap,
|
|
37
|
-
ContractMethod.multiSwap,
|
|
38
|
-
ContractMethod.megaSwap,
|
|
39
|
-
],
|
|
40
|
-
],
|
|
41
|
-
[SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
|
|
42
|
-
]);
|
|
43
|
-
|
|
44
|
-
describe(`${network}`, () => {
|
|
45
|
-
sideToContractMethods.forEach((contractMethods, side) =>
|
|
46
|
-
describe(`${side}`, () => {
|
|
47
|
-
contractMethods.forEach((contractMethod: ContractMethod) => {
|
|
48
|
-
describe(`${contractMethod}`, () => {
|
|
49
|
-
it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => {
|
|
50
|
-
await testE2E(
|
|
51
|
-
tokens[nativeTokenSymbol],
|
|
52
|
-
tokens[tokenASymbol],
|
|
53
|
-
holders[nativeTokenSymbol],
|
|
54
|
-
side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount,
|
|
55
|
-
side,
|
|
56
|
-
dexKey,
|
|
57
|
-
contractMethod,
|
|
58
|
-
network,
|
|
59
|
-
provider,
|
|
60
|
-
undefined,
|
|
61
|
-
undefined,
|
|
62
|
-
undefined,
|
|
63
|
-
slippage,
|
|
64
|
-
);
|
|
65
|
-
});
|
|
66
|
-
it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => {
|
|
67
|
-
await testE2E(
|
|
68
|
-
tokens[tokenASymbol],
|
|
69
|
-
tokens[nativeTokenSymbol],
|
|
70
|
-
holders[tokenASymbol],
|
|
71
|
-
side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount,
|
|
72
|
-
side,
|
|
73
|
-
dexKey,
|
|
74
|
-
contractMethod,
|
|
75
|
-
network,
|
|
76
|
-
provider,
|
|
77
|
-
undefined,
|
|
78
|
-
undefined,
|
|
79
|
-
undefined,
|
|
80
|
-
slippage,
|
|
81
|
-
);
|
|
82
|
-
});
|
|
83
|
-
it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
|
|
84
|
-
await testE2E(
|
|
85
|
-
tokens[tokenASymbol],
|
|
86
|
-
tokens[tokenBSymbol],
|
|
87
|
-
holders[tokenASymbol],
|
|
88
|
-
side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
|
|
89
|
-
side,
|
|
90
|
-
dexKey,
|
|
91
|
-
contractMethod,
|
|
92
|
-
network,
|
|
93
|
-
provider,
|
|
94
|
-
undefined,
|
|
95
|
-
undefined,
|
|
96
|
-
undefined,
|
|
97
|
-
slippage,
|
|
98
|
-
);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
}),
|
|
103
|
-
);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
describe('BaseswapV3 E2E', () => {
|
|
108
|
-
const dexKey = 'BaseswapV3';
|
|
109
|
-
describe('Base', () => {
|
|
110
|
-
const network = Network.BASE;
|
|
111
|
-
|
|
112
|
-
const tokenASymbol: string = 'USDC';
|
|
113
|
-
const tokenBSymbol: string = 'USDbC';
|
|
114
|
-
|
|
115
|
-
const tokenAAmount: string = '1000000';
|
|
116
|
-
const tokenBAmount: string = '1000000';
|
|
117
|
-
const nativeTokenAmount = '1000000000000000000';
|
|
118
|
-
|
|
119
|
-
testForNetwork(
|
|
120
|
-
network,
|
|
121
|
-
dexKey,
|
|
122
|
-
tokenASymbol,
|
|
123
|
-
tokenBSymbol,
|
|
124
|
-
tokenAAmount,
|
|
125
|
-
tokenBAmount,
|
|
126
|
-
nativeTokenAmount,
|
|
127
|
-
);
|
|
128
|
-
});
|
|
129
|
-
});
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import dotenv from 'dotenv';
|
|
3
|
-
dotenv.config();
|
|
4
|
-
|
|
5
|
-
import _ from 'lodash';
|
|
6
|
-
import { BaseswapV3EventPool } from './baseswap-v3-pool';
|
|
7
|
-
import { BaseswapV3Config } from './config';
|
|
8
|
-
import { Network } from '../../constants';
|
|
9
|
-
import { DummyDexHelper } from '../../dex-helper/index';
|
|
10
|
-
import { testEventSubscriber } from '../../../tests/utils-events';
|
|
11
|
-
import { PoolState } from './types';
|
|
12
|
-
import { Interface } from '@ethersproject/abi';
|
|
13
|
-
import ERC20ABI from '../../abi/erc20.json';
|
|
14
|
-
import StateMulticallABI from '../../abi/uniswap-v3/UniswapV3StateMulticall.abi.json';
|
|
15
|
-
import { AbiItem } from 'web3-utils';
|
|
16
|
-
|
|
17
|
-
jest.setTimeout(300 * 1000);
|
|
18
|
-
const dexKey = 'BaseswapV3';
|
|
19
|
-
const network = Network.BASE;
|
|
20
|
-
const config = BaseswapV3Config[dexKey][network];
|
|
21
|
-
|
|
22
|
-
async function fetchPoolStateFromContract(
|
|
23
|
-
baseswapV3Pool: BaseswapV3EventPool,
|
|
24
|
-
blockNumber: number,
|
|
25
|
-
poolAddress: string,
|
|
26
|
-
): Promise<PoolState> {
|
|
27
|
-
const message = `BaseswapV3: ${poolAddress} blockNumber ${blockNumber}`;
|
|
28
|
-
console.log(`Fetching state ${message}`);
|
|
29
|
-
// Be careful to not request state prior to contract deployment
|
|
30
|
-
// Otherwise need to use manual state sourcing from multicall
|
|
31
|
-
// We had that mechanism, but removed it with this commit
|
|
32
|
-
// You can restore it, but better just to find block after state multicall
|
|
33
|
-
// deployment
|
|
34
|
-
const state = baseswapV3Pool.generateState(blockNumber);
|
|
35
|
-
console.log(`Done ${message}`);
|
|
36
|
-
return state;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
describe('BaseswapV3 Event', function () {
|
|
40
|
-
const poolAddress = '0xEf3C164b0feE8Eb073513E88EcEa280A58cC9945';
|
|
41
|
-
const poolFeeCode = 450n;
|
|
42
|
-
const token0 = '0x4200000000000000000000000000000000000006';
|
|
43
|
-
const token1 = '0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA'; // USDbC
|
|
44
|
-
|
|
45
|
-
const blockNumbers: { [eventName: string]: number[] } = {
|
|
46
|
-
['Swap']: [
|
|
47
|
-
5574195, 5574217, 5574296, 5574296, 5574369, 5574404, 5574489, 5574522,
|
|
48
|
-
5574566, 5574579, 5574587, 5574588, 5574611, 5574657, 5574712, 5574737,
|
|
49
|
-
5574761, 5574806, 5574851, 5574896, 5574918, 5574982, 5575086, 5575110,
|
|
50
|
-
5575308, 5575378, 5575490, 5575668,
|
|
51
|
-
],
|
|
52
|
-
['Burn']: [
|
|
53
|
-
5575845, 5609704, 5609704, 5612315, 5612770, 5616727, 5617522, 5617821,
|
|
54
|
-
5620232, 5622253,
|
|
55
|
-
],
|
|
56
|
-
// topic0 - 0x7a53080ba414158be7ec69b987b5fb7d07dee101fe85488f0853ae16239d0bde
|
|
57
|
-
['Mint']: [
|
|
58
|
-
5594704, 5595166, 5606630, 5609854, 5612343, 5612386, 5612959, 5613707,
|
|
59
|
-
5619196, 5620167, 5622035, 5622391, 5644261, 5645562, 5647711, 5649108,
|
|
60
|
-
5649161, 5649377, 5651799, 5652903,
|
|
61
|
-
],
|
|
62
|
-
// topic0 - 0x973d8d92bb299f4af6ce49b52a8adb85ae46b9f214c4c4fc06ac77401237b133
|
|
63
|
-
['SetFeeProtocol']: [],
|
|
64
|
-
// topic0 - 0xac49e518f90a358f652e4400164f05a5d8f7e35e7747279bc3a93dbf584e125a
|
|
65
|
-
// There are some events on blockNumbers: 13125816, 12733621, 12591465
|
|
66
|
-
// But stateMulticall is not deployed at that time. So I just remove that check
|
|
67
|
-
// I think it is not important actually
|
|
68
|
-
['IncreaseObservationCardinalityNext']: [],
|
|
69
|
-
['Collect']: [
|
|
70
|
-
5575845, 5609704, 5612315, 5612770, 5616727, 5617522, 5617821, 5620232,
|
|
71
|
-
5622253, 5642348, 5643915, 5645799, 5646074, 5647176, 5650388, 5650466,
|
|
72
|
-
5653068, 5655334, 5655462, 5656401, 5657882, 5658500, 5659898, 5663603,
|
|
73
|
-
5663999, 5664004, 5670005, 5671343, 5673141,
|
|
74
|
-
],
|
|
75
|
-
['Flash']: [],
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
describe('BaseswapV3EventPool', () => {
|
|
79
|
-
Object.keys(blockNumbers).forEach((event: string) => {
|
|
80
|
-
blockNumbers[event].forEach((blockNumber: number) => {
|
|
81
|
-
it(`${event}:${blockNumber} - should return correct state`, async function () {
|
|
82
|
-
const dexHelper = new DummyDexHelper(network);
|
|
83
|
-
// await dexHelper.init();
|
|
84
|
-
|
|
85
|
-
const logger = dexHelper.getLogger(dexKey);
|
|
86
|
-
|
|
87
|
-
// readonly dexHelper: IDexHelper,
|
|
88
|
-
// parentName: string,
|
|
89
|
-
// readonly stateMultiContract: Contract,
|
|
90
|
-
// readonly decodeStateMultiCallResultWithRelativeBitmaps:
|
|
91
|
-
// | DecodeStateMultiCallFunc
|
|
92
|
-
// | undefined,
|
|
93
|
-
// readonly erc20Interface: Interface,
|
|
94
|
-
// protected readonly factoryAddress: Address,
|
|
95
|
-
// public feeCode: bigint,
|
|
96
|
-
// token0: Address,
|
|
97
|
-
// token1: Address,
|
|
98
|
-
// logger: Logger,
|
|
99
|
-
// mapKey: string = '',
|
|
100
|
-
// readonly poolInitCodeHash: string,
|
|
101
|
-
|
|
102
|
-
const baseswapV3Pool = new BaseswapV3EventPool(
|
|
103
|
-
dexHelper,
|
|
104
|
-
dexKey,
|
|
105
|
-
new dexHelper.web3Provider.eth.Contract(
|
|
106
|
-
StateMulticallABI as AbiItem[],
|
|
107
|
-
config.stateMulticall,
|
|
108
|
-
),
|
|
109
|
-
undefined,
|
|
110
|
-
new Interface(ERC20ABI),
|
|
111
|
-
config.factory,
|
|
112
|
-
poolFeeCode,
|
|
113
|
-
token0,
|
|
114
|
-
token1,
|
|
115
|
-
logger,
|
|
116
|
-
undefined,
|
|
117
|
-
config.initHash,
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
// It is done in generateState. But here have to make it manually
|
|
121
|
-
baseswapV3Pool.poolAddress = poolAddress.toLowerCase();
|
|
122
|
-
baseswapV3Pool.addressesSubscribed[0] = poolAddress;
|
|
123
|
-
|
|
124
|
-
await testEventSubscriber(
|
|
125
|
-
baseswapV3Pool,
|
|
126
|
-
baseswapV3Pool.addressesSubscribed,
|
|
127
|
-
(_blockNumber: number) =>
|
|
128
|
-
fetchPoolStateFromContract(
|
|
129
|
-
baseswapV3Pool,
|
|
130
|
-
_blockNumber,
|
|
131
|
-
poolAddress,
|
|
132
|
-
),
|
|
133
|
-
blockNumber,
|
|
134
|
-
`${dexKey}_${poolAddress}`,
|
|
135
|
-
dexHelper.provider,
|
|
136
|
-
);
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { Interface } from '@ethersproject/abi';
|
|
2
|
-
import { DeepReadonly } from 'ts-essentials';
|
|
3
|
-
import FactoryABI from '../../abi/uniswap-v3/UniswapV3Factory.abi.json';
|
|
4
|
-
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
5
|
-
import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
|
|
6
|
-
import { Address, Log, Logger } from '../../types';
|
|
7
|
-
import { LogDescription } from 'ethers/lib/utils';
|
|
8
|
-
import { FactoryState } from './types';
|
|
9
|
-
|
|
10
|
-
export type OnPoolCreatedCallback = ({
|
|
11
|
-
token0,
|
|
12
|
-
token1,
|
|
13
|
-
fee,
|
|
14
|
-
}: {
|
|
15
|
-
token0: string;
|
|
16
|
-
token1: string;
|
|
17
|
-
fee: bigint;
|
|
18
|
-
}) => Promise<void>;
|
|
19
|
-
|
|
20
|
-
/*
|
|
21
|
-
* "Stateless" event subscriber in order to capture "PoolCreated" event on new pools created.
|
|
22
|
-
* State is present, but it's a placeholder to actually make the events reach handlers (if there's no previous state - `processBlockLogs` is not called)
|
|
23
|
-
*/
|
|
24
|
-
export class BaseswapV3Factory extends StatefulEventSubscriber<FactoryState> {
|
|
25
|
-
handlers: {
|
|
26
|
-
[event: string]: (event: any) => Promise<void>;
|
|
27
|
-
} = {};
|
|
28
|
-
|
|
29
|
-
logDecoder: (log: Log) => any;
|
|
30
|
-
|
|
31
|
-
public readonly factoryIface = new Interface(FactoryABI);
|
|
32
|
-
|
|
33
|
-
constructor(
|
|
34
|
-
readonly dexHelper: IDexHelper,
|
|
35
|
-
parentName: string,
|
|
36
|
-
protected readonly factoryAddress: Address,
|
|
37
|
-
logger: Logger,
|
|
38
|
-
protected readonly onPoolCreated: OnPoolCreatedCallback,
|
|
39
|
-
mapKey: string = '',
|
|
40
|
-
) {
|
|
41
|
-
super(parentName, `${parentName} Factory`, dexHelper, logger, true, mapKey);
|
|
42
|
-
|
|
43
|
-
this.addressesSubscribed = [factoryAddress];
|
|
44
|
-
|
|
45
|
-
this.logDecoder = (log: Log) => this.factoryIface.parseLog(log);
|
|
46
|
-
|
|
47
|
-
this.handlers['PoolCreated'] = this.handleNewPool.bind(this);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
generateState(): FactoryState {
|
|
51
|
-
return {};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
protected async processLog(
|
|
55
|
-
_: DeepReadonly<FactoryState>,
|
|
56
|
-
log: Readonly<Log>,
|
|
57
|
-
): Promise<FactoryState> {
|
|
58
|
-
const event = this.logDecoder(log);
|
|
59
|
-
if (event.name in this.handlers) {
|
|
60
|
-
await this.handlers[event.name](event);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return {};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async handleNewPool(event: LogDescription) {
|
|
67
|
-
const token0 = event.args.token0.toLowerCase();
|
|
68
|
-
const token1 = event.args.token1.toLowerCase();
|
|
69
|
-
const fee = event.args.fee;
|
|
70
|
-
|
|
71
|
-
await this.onPoolCreated({ token0, token1, fee });
|
|
72
|
-
}
|
|
73
|
-
}
|