@paraswap/dex-lib 2.37.2 → 2.37.3
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/abi/pancakeswap-v3/PancakeswapV3Factory.abi.json +300 -0
- package/build/abi/uniswap-v3/UniswapV3Factory.abi.json +148 -0
- package/build/dex/algebra/algebra-factory.d.ts +25 -0
- package/build/dex/algebra/algebra-factory.js +43 -0
- package/build/dex/algebra/algebra-factory.js.map +1 -0
- package/build/dex/algebra/algebra.d.ts +3 -0
- package/build/dex/algebra/algebra.js +27 -5
- package/build/dex/algebra/algebra.js.map +1 -1
- package/build/dex/algebra/config.js +0 -1
- package/build/dex/algebra/config.js.map +1 -1
- package/build/dex/algebra/types.d.ts +1 -1
- package/build/dex/{woo-fi → hello}/config.d.ts +1 -1
- package/build/dex/{test-dex → hello}/config.js +3 -3
- package/build/dex/hello/config.js.map +1 -0
- package/build/dex/{test-dex/test-dex-pool.d.ts → hello/hello-pool.d.ts} +4 -4
- package/build/dex/{test-dex/test-dex-pool.js → hello/hello-pool.js} +9 -8
- package/build/dex/hello/hello-pool.js.map +1 -0
- package/build/dex/{test-dex/test-dex.d.ts → hello/hello.d.ts} +8 -8
- package/build/dex/{test-dex/test-dex.js → hello/hello.js} +7 -7
- package/build/dex/hello/hello.js.map +1 -0
- package/build/dex/{test-dex → hello}/types.d.ts +1 -1
- package/build/dex/{woo-fi → hello}/types.js.map +1 -1
- package/build/dex/{test-dex → my-test-dex}/config.d.ts +1 -1
- package/build/dex/my-test-dex/config.js +15 -0
- package/build/dex/my-test-dex/config.js.map +1 -0
- package/build/dex/my-test-dex/my-test-dex-pool.d.ts +39 -0
- package/build/dex/my-test-dex/my-test-dex-pool.js +64 -0
- package/build/dex/my-test-dex/my-test-dex-pool.js.map +1 -0
- package/build/dex/my-test-dex/my-test-dex.d.ts +37 -0
- package/build/dex/my-test-dex/my-test-dex.js +126 -0
- package/build/dex/my-test-dex/my-test-dex.js.map +1 -0
- package/build/dex/my-test-dex/types.d.ts +6 -0
- package/build/dex/{test-dex → my-test-dex}/types.js.map +1 -1
- package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.d.ts +26 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.js +44 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.js.map +1 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +3 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3.js +26 -2
- package/build/dex/pancakeswap-v3/pancakeswap-v3.js.map +1 -1
- package/build/dex/uniswap-v3/types.d.ts +1 -0
- package/build/dex/uniswap-v3/types.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3-factory.d.ts +26 -0
- package/build/dex/uniswap-v3/uniswap-v3-factory.js +44 -0
- package/build/dex/uniswap-v3/uniswap-v3-factory.js.map +1 -0
- package/build/dex/uniswap-v3/uniswap-v3.d.ts +3 -0
- package/build/dex/uniswap-v3/uniswap-v3.js +26 -2
- package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
- package/build/dex-helper/dummy-dex-helper.js +3 -0
- package/build/dex-helper/dummy-dex-helper.js.map +1 -1
- package/build/dex-helper/icache.d.ts +1 -0
- package/package.json +1 -1
- package/src/abi/pancakeswap-v3/PancakeswapV3Factory.abi.json +300 -0
- package/src/dex/algebra/algebra-factory.ts +70 -0
- package/src/dex/algebra/algebra.ts +47 -6
- package/src/dex/algebra/config.ts +0 -1
- package/src/dex/algebra/types.ts +2 -1
- package/src/dex/pancakeswap-v3/pancakeswap-v3-factory.ts +73 -0
- package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +50 -2
- package/src/dex/uniswap-v3/types.ts +2 -0
- package/src/dex/uniswap-v3/uniswap-v3-factory.ts +73 -0
- package/src/dex/uniswap-v3/uniswap-v3.ts +47 -2
- package/src/dex-helper/dummy-dex-helper.ts +4 -0
- package/src/dex-helper/icache.ts +2 -0
- package/build/abi/quickPerps/fast-price-events.json +0 -70
- package/build/abi/quickPerps/fast-price-feed.json +0 -748
- package/build/abi/quickPerps/reader.json +0 -313
- package/build/abi/quickPerps/vault-price-feed.json +0 -477
- package/build/abi/quickPerps/vault.json +0 -1953
- package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
- package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +0 -285
- package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +0 -583
- package/build/abi/woo-fi/WooFeeManager.abi.json +0 -318
- package/build/abi/woo-fi/WooPP.abi.json +0 -548
- package/build/abi/woo-fi/Wooracle.abi.json +0 -260
- package/build/dex/aave-v3/tokens/arbitrum.json +0 -50
- package/build/dex/aave-v3/tokens/avalanche.json +0 -74
- package/build/dex/aave-v3/tokens/fantom.json +0 -62
- package/build/dex/aave-v3/tokens/optimism.json +0 -50
- package/build/dex/aave-v3/tokens/polygon.json +0 -116
- package/build/dex/balancer-v2/LinearMath.d.ts +0 -19
- package/build/dex/balancer-v2/LinearMath.js +0 -179
- package/build/dex/balancer-v2/LinearMath.js.map +0 -1
- package/build/dex/balancer-v2/LinearPool.d.ts +0 -47
- package/build/dex/balancer-v2/LinearPool.js +0 -324
- package/build/dex/balancer-v2/LinearPool.js.map +0 -1
- package/build/dex/balancer-v2/PhantomStablePool.d.ts +0 -47
- package/build/dex/balancer-v2/PhantomStablePool.js +0 -294
- package/build/dex/balancer-v2/PhantomStablePool.js.map +0 -1
- package/build/dex/balancer-v2/StableMath.d.ts +0 -9
- package/build/dex/balancer-v2/StableMath.js +0 -272
- package/build/dex/balancer-v2/StableMath.js.map +0 -1
- package/build/dex/balancer-v2/balancer-v2-pool.d.ts +0 -75
- package/build/dex/balancer-v2/balancer-v2-pool.js +0 -417
- package/build/dex/balancer-v2/balancer-v2-pool.js.map +0 -1
- package/build/dex/maverick-v1/scripts/event-sequence.d.ts +0 -1
- package/build/dex/maverick-v1/scripts/event-sequence.js +0 -110
- package/build/dex/maverick-v1/scripts/event-sequence.js.map +0 -1
- package/build/dex/quickswap/camelot-v3.d.ts +0 -6
- package/build/dex/quickswap/camelot-v3.js +0 -19
- package/build/dex/quickswap/camelot-v3.js.map +0 -1
- package/build/dex/quickswap/zyberswap-v3.d.ts +0 -6
- package/build/dex/quickswap/zyberswap-v3.js +0 -19
- package/build/dex/quickswap/zyberswap-v3.js.map +0 -1
- package/build/dex/quickswap-v3.d.ts +0 -21
- package/build/dex/quickswap-v3.js +0 -40
- package/build/dex/quickswap-v3.js.map +0 -1
- package/build/dex/test-dex/config.js.map +0 -1
- package/build/dex/test-dex/test-dex-pool.js.map +0 -1
- package/build/dex/test-dex/test-dex.js.map +0 -1
- package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +0 -12
- package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +0 -23
- package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +0 -1
- package/build/dex/woo-fi/config.js +0 -141
- package/build/dex/woo-fi/config.js.map +0 -1
- package/build/dex/woo-fi/constants.d.ts +0 -5
- package/build/dex/woo-fi/constants.js +0 -20
- package/build/dex/woo-fi/constants.js.map +0 -1
- package/build/dex/woo-fi/types.d.ts +0 -48
- package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +0 -14
- package/build/dex/woo-fi/woo-fi-decimal-math.js +0 -42
- package/build/dex/woo-fi/woo-fi-decimal-math.js.map +0 -1
- package/build/dex/woo-fi/woo-fi-math.d.ts +0 -31
- package/build/dex/woo-fi/woo-fi-math.js +0 -300
- package/build/dex/woo-fi/woo-fi-math.js.map +0 -1
- package/build/dex/woo-fi/woo-fi.d.ts +0 -65
- package/build/dex/woo-fi/woo-fi.js +0 -480
- package/build/dex/woo-fi/woo-fi.js.map +0 -1
- package/build/dex/woo-fi-v2/woo-fi-math.d.ts +0 -16
- package/build/dex/woo-fi-v2/woo-fi-math.js +0 -137
- package/build/dex/woo-fi-v2/woo-fi-math.js.map +0 -1
- package/build/workers.d.ts +0 -0
- package/build/workers.js +0 -2
- package/build/workers.js.map +0 -1
- /package/build/dex/{test-dex → hello}/types.js +0 -0
- /package/build/dex/{woo-fi → my-test-dex}/types.js +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dummy-dex-helper.js","sourceRoot":"","sources":["../../src/dex-helper/dummy-dex-helper.ts"],"names":[],"mappings":";;;;;;AAOA,kDAA0B;AAE1B,uDAAuD;AACvD,wDAA2E;AAC3E,yEAA8C;AAC9C,oDAA4B;AAC5B,0CAA0C;AAC1C,gDAAwB;AAExB,sCAAyD;AACzD,wDAAoD;AAGpD,gEAA4D;AAE5D,MAAM,MAAM,GAAG,IAAA,kBAAS,EAAC,gBAAgB,CAAC,CAAC;AAE3C,6CAA6C;AAC7C,MAAM,UAAU;IAAhB;QACU,YAAO,GAA2B,EAAE,CAAC;QAErC,WAAM,GAAgC,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"dummy-dex-helper.js","sourceRoot":"","sources":["../../src/dex-helper/dummy-dex-helper.ts"],"names":[],"mappings":";;;;;;AAOA,kDAA0B;AAE1B,uDAAuD;AACvD,wDAA2E;AAC3E,yEAA8C;AAC9C,oDAA4B;AAC5B,0CAA0C;AAC1C,gDAAwB;AAExB,sCAAyD;AACzD,wDAAoD;AAGpD,gEAA4D;AAE5D,MAAM,MAAM,GAAG,IAAA,kBAAS,EAAC,gBAAgB,CAAC,CAAC;AAE3C,6CAA6C;AAC7C,MAAM,UAAU;IAAhB;QACU,YAAO,GAA2B,EAAE,CAAC;QAErC,WAAM,GAAgC,EAAE,CAAC;IA8InD,CAAC;IA5IC,KAAK,CAAC,GAAG,CACP,MAAc,EACd,OAAe,EACf,QAAgB;QAEhB,MAAM,GAAG,GAAG,GAAG,OAAO,IAAI,MAAM,IAAI,QAAQ,EAAE,CAAC,WAAW,EAAE,CAAC;QAC7D,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;Y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,CAAC;YACvB,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC;QACF,oEAAoE;QACpE,IAAI,CAAC,gBAAgB,GAAG,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,CAC9C,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;QAChD,IAAI,CAAC,YAAY,GAAG,IAAI,4BAAY,CAClC,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,SAAS,CAAC,gBAAgB,OAAO,EAAE,CAAC,CAC1C,CAAC;QAEF,IAAI,CAAC,gBAAgB,GAAG,IAAI,oCAAgB,CAC1C,GAAG,EACH,CAAC,EACD,IAAI,CAAC,SAAS,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAC9C,CAAC;IACJ,CAAC;IAED,sBAAsB,CAAC,MAAc;QACnC,IAAI,CAAC,QAAQ,GAAG,IAAI,iCAAqB,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9E,CAAC;CACF;AApDD,wCAoDC"}
|
|
@@ -10,6 +10,7 @@ export interface ICache {
|
|
|
10
10
|
sadd(setKey: string, key: string): Promise<void>;
|
|
11
11
|
zadd(key: string, bulkItemsToAdd: (number | string)[], option?: 'NX'): Promise<number>;
|
|
12
12
|
zremrangebyscore(key: string, min: number, max: number): Promise<number>;
|
|
13
|
+
zrem(key: string, membersKeys: string[]): Promise<number>;
|
|
13
14
|
zscore(setKey: string, key: string): Promise<string | null>;
|
|
14
15
|
sismember(setKey: string, key: string): Promise<boolean>;
|
|
15
16
|
hset(mapKey: string, key: string, value: string): Promise<void>;
|
package/package.json
CHANGED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"inputs": [
|
|
4
|
+
{ "internalType": "address", "name": "_poolDeployer", "type": "address" }
|
|
5
|
+
],
|
|
6
|
+
"stateMutability": "nonpayable",
|
|
7
|
+
"type": "constructor"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"anonymous": false,
|
|
11
|
+
"inputs": [
|
|
12
|
+
{
|
|
13
|
+
"indexed": true,
|
|
14
|
+
"internalType": "uint24",
|
|
15
|
+
"name": "fee",
|
|
16
|
+
"type": "uint24"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"indexed": true,
|
|
20
|
+
"internalType": "int24",
|
|
21
|
+
"name": "tickSpacing",
|
|
22
|
+
"type": "int24"
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"name": "FeeAmountEnabled",
|
|
26
|
+
"type": "event"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"anonymous": false,
|
|
30
|
+
"inputs": [
|
|
31
|
+
{
|
|
32
|
+
"indexed": true,
|
|
33
|
+
"internalType": "uint24",
|
|
34
|
+
"name": "fee",
|
|
35
|
+
"type": "uint24"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"indexed": false,
|
|
39
|
+
"internalType": "bool",
|
|
40
|
+
"name": "whitelistRequested",
|
|
41
|
+
"type": "bool"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"indexed": false,
|
|
45
|
+
"internalType": "bool",
|
|
46
|
+
"name": "enabled",
|
|
47
|
+
"type": "bool"
|
|
48
|
+
}
|
|
49
|
+
],
|
|
50
|
+
"name": "FeeAmountExtraInfoUpdated",
|
|
51
|
+
"type": "event"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"anonymous": false,
|
|
55
|
+
"inputs": [
|
|
56
|
+
{
|
|
57
|
+
"indexed": true,
|
|
58
|
+
"internalType": "address",
|
|
59
|
+
"name": "oldOwner",
|
|
60
|
+
"type": "address"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"indexed": true,
|
|
64
|
+
"internalType": "address",
|
|
65
|
+
"name": "newOwner",
|
|
66
|
+
"type": "address"
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
"name": "OwnerChanged",
|
|
70
|
+
"type": "event"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"anonymous": false,
|
|
74
|
+
"inputs": [
|
|
75
|
+
{
|
|
76
|
+
"indexed": true,
|
|
77
|
+
"internalType": "address",
|
|
78
|
+
"name": "token0",
|
|
79
|
+
"type": "address"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"indexed": true,
|
|
83
|
+
"internalType": "address",
|
|
84
|
+
"name": "token1",
|
|
85
|
+
"type": "address"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"indexed": true,
|
|
89
|
+
"internalType": "uint24",
|
|
90
|
+
"name": "fee",
|
|
91
|
+
"type": "uint24"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"indexed": false,
|
|
95
|
+
"internalType": "int24",
|
|
96
|
+
"name": "tickSpacing",
|
|
97
|
+
"type": "int24"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"indexed": false,
|
|
101
|
+
"internalType": "address",
|
|
102
|
+
"name": "pool",
|
|
103
|
+
"type": "address"
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
"name": "PoolCreated",
|
|
107
|
+
"type": "event"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"anonymous": false,
|
|
111
|
+
"inputs": [
|
|
112
|
+
{
|
|
113
|
+
"indexed": true,
|
|
114
|
+
"internalType": "address",
|
|
115
|
+
"name": "lmPoolDeployer",
|
|
116
|
+
"type": "address"
|
|
117
|
+
}
|
|
118
|
+
],
|
|
119
|
+
"name": "SetLmPoolDeployer",
|
|
120
|
+
"type": "event"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"anonymous": false,
|
|
124
|
+
"inputs": [
|
|
125
|
+
{
|
|
126
|
+
"indexed": true,
|
|
127
|
+
"internalType": "address",
|
|
128
|
+
"name": "user",
|
|
129
|
+
"type": "address"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"indexed": false,
|
|
133
|
+
"internalType": "bool",
|
|
134
|
+
"name": "verified",
|
|
135
|
+
"type": "bool"
|
|
136
|
+
}
|
|
137
|
+
],
|
|
138
|
+
"name": "WhiteListAdded",
|
|
139
|
+
"type": "event"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"inputs": [
|
|
143
|
+
{ "internalType": "address", "name": "pool", "type": "address" },
|
|
144
|
+
{ "internalType": "address", "name": "recipient", "type": "address" },
|
|
145
|
+
{
|
|
146
|
+
"internalType": "uint128",
|
|
147
|
+
"name": "amount0Requested",
|
|
148
|
+
"type": "uint128"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"internalType": "uint128",
|
|
152
|
+
"name": "amount1Requested",
|
|
153
|
+
"type": "uint128"
|
|
154
|
+
}
|
|
155
|
+
],
|
|
156
|
+
"name": "collectProtocol",
|
|
157
|
+
"outputs": [
|
|
158
|
+
{ "internalType": "uint128", "name": "amount0", "type": "uint128" },
|
|
159
|
+
{ "internalType": "uint128", "name": "amount1", "type": "uint128" }
|
|
160
|
+
],
|
|
161
|
+
"stateMutability": "nonpayable",
|
|
162
|
+
"type": "function"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"inputs": [
|
|
166
|
+
{ "internalType": "address", "name": "tokenA", "type": "address" },
|
|
167
|
+
{ "internalType": "address", "name": "tokenB", "type": "address" },
|
|
168
|
+
{ "internalType": "uint24", "name": "fee", "type": "uint24" }
|
|
169
|
+
],
|
|
170
|
+
"name": "createPool",
|
|
171
|
+
"outputs": [
|
|
172
|
+
{ "internalType": "address", "name": "pool", "type": "address" }
|
|
173
|
+
],
|
|
174
|
+
"stateMutability": "nonpayable",
|
|
175
|
+
"type": "function"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
"inputs": [
|
|
179
|
+
{ "internalType": "uint24", "name": "fee", "type": "uint24" },
|
|
180
|
+
{ "internalType": "int24", "name": "tickSpacing", "type": "int24" }
|
|
181
|
+
],
|
|
182
|
+
"name": "enableFeeAmount",
|
|
183
|
+
"outputs": [],
|
|
184
|
+
"stateMutability": "nonpayable",
|
|
185
|
+
"type": "function"
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
"inputs": [{ "internalType": "uint24", "name": "", "type": "uint24" }],
|
|
189
|
+
"name": "feeAmountTickSpacing",
|
|
190
|
+
"outputs": [{ "internalType": "int24", "name": "", "type": "int24" }],
|
|
191
|
+
"stateMutability": "view",
|
|
192
|
+
"type": "function"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"inputs": [{ "internalType": "uint24", "name": "", "type": "uint24" }],
|
|
196
|
+
"name": "feeAmountTickSpacingExtraInfo",
|
|
197
|
+
"outputs": [
|
|
198
|
+
{ "internalType": "bool", "name": "whitelistRequested", "type": "bool" },
|
|
199
|
+
{ "internalType": "bool", "name": "enabled", "type": "bool" }
|
|
200
|
+
],
|
|
201
|
+
"stateMutability": "view",
|
|
202
|
+
"type": "function"
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
"inputs": [
|
|
206
|
+
{ "internalType": "address", "name": "", "type": "address" },
|
|
207
|
+
{ "internalType": "address", "name": "", "type": "address" },
|
|
208
|
+
{ "internalType": "uint24", "name": "", "type": "uint24" }
|
|
209
|
+
],
|
|
210
|
+
"name": "getPool",
|
|
211
|
+
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
|
|
212
|
+
"stateMutability": "view",
|
|
213
|
+
"type": "function"
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
"inputs": [],
|
|
217
|
+
"name": "lmPoolDeployer",
|
|
218
|
+
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
|
|
219
|
+
"stateMutability": "view",
|
|
220
|
+
"type": "function"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
"inputs": [],
|
|
224
|
+
"name": "owner",
|
|
225
|
+
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
|
|
226
|
+
"stateMutability": "view",
|
|
227
|
+
"type": "function"
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
"inputs": [],
|
|
231
|
+
"name": "poolDeployer",
|
|
232
|
+
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
|
|
233
|
+
"stateMutability": "view",
|
|
234
|
+
"type": "function"
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
"inputs": [
|
|
238
|
+
{ "internalType": "uint24", "name": "fee", "type": "uint24" },
|
|
239
|
+
{ "internalType": "bool", "name": "whitelistRequested", "type": "bool" },
|
|
240
|
+
{ "internalType": "bool", "name": "enabled", "type": "bool" }
|
|
241
|
+
],
|
|
242
|
+
"name": "setFeeAmountExtraInfo",
|
|
243
|
+
"outputs": [],
|
|
244
|
+
"stateMutability": "nonpayable",
|
|
245
|
+
"type": "function"
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
"inputs": [
|
|
249
|
+
{ "internalType": "address", "name": "pool", "type": "address" },
|
|
250
|
+
{ "internalType": "uint32", "name": "feeProtocol0", "type": "uint32" },
|
|
251
|
+
{ "internalType": "uint32", "name": "feeProtocol1", "type": "uint32" }
|
|
252
|
+
],
|
|
253
|
+
"name": "setFeeProtocol",
|
|
254
|
+
"outputs": [],
|
|
255
|
+
"stateMutability": "nonpayable",
|
|
256
|
+
"type": "function"
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
"inputs": [
|
|
260
|
+
{ "internalType": "address", "name": "pool", "type": "address" },
|
|
261
|
+
{ "internalType": "address", "name": "lmPool", "type": "address" }
|
|
262
|
+
],
|
|
263
|
+
"name": "setLmPool",
|
|
264
|
+
"outputs": [],
|
|
265
|
+
"stateMutability": "nonpayable",
|
|
266
|
+
"type": "function"
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
"inputs": [
|
|
270
|
+
{
|
|
271
|
+
"internalType": "address",
|
|
272
|
+
"name": "_lmPoolDeployer",
|
|
273
|
+
"type": "address"
|
|
274
|
+
}
|
|
275
|
+
],
|
|
276
|
+
"name": "setLmPoolDeployer",
|
|
277
|
+
"outputs": [],
|
|
278
|
+
"stateMutability": "nonpayable",
|
|
279
|
+
"type": "function"
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
"inputs": [
|
|
283
|
+
{ "internalType": "address", "name": "_owner", "type": "address" }
|
|
284
|
+
],
|
|
285
|
+
"name": "setOwner",
|
|
286
|
+
"outputs": [],
|
|
287
|
+
"stateMutability": "nonpayable",
|
|
288
|
+
"type": "function"
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
"inputs": [
|
|
292
|
+
{ "internalType": "address", "name": "user", "type": "address" },
|
|
293
|
+
{ "internalType": "bool", "name": "verified", "type": "bool" }
|
|
294
|
+
],
|
|
295
|
+
"name": "setWhiteListAddress",
|
|
296
|
+
"outputs": [],
|
|
297
|
+
"stateMutability": "nonpayable",
|
|
298
|
+
"type": "function"
|
|
299
|
+
}
|
|
300
|
+
]
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { DeepReadonly } from 'ts-essentials';
|
|
3
|
+
import FactoryABI from '../../abi/algebra/AlgebraFactory-v1_1.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
|
+
}: {
|
|
14
|
+
token0: string;
|
|
15
|
+
token1: string;
|
|
16
|
+
}) => Promise<void>;
|
|
17
|
+
|
|
18
|
+
/*
|
|
19
|
+
* "Stateless" event subscriber in order to capture "PoolCreated" event on new pools created.
|
|
20
|
+
* 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)
|
|
21
|
+
*/
|
|
22
|
+
export class AlgebraFactory extends StatefulEventSubscriber<FactoryState> {
|
|
23
|
+
handlers: {
|
|
24
|
+
[event: string]: (event: any) => Promise<void>;
|
|
25
|
+
} = {};
|
|
26
|
+
|
|
27
|
+
logDecoder: (log: Log) => any;
|
|
28
|
+
|
|
29
|
+
public readonly factoryIface = new Interface(FactoryABI);
|
|
30
|
+
|
|
31
|
+
constructor(
|
|
32
|
+
readonly dexHelper: IDexHelper,
|
|
33
|
+
parentName: string,
|
|
34
|
+
protected readonly factoryAddress: Address,
|
|
35
|
+
logger: Logger,
|
|
36
|
+
protected readonly onPoolCreated: OnPoolCreatedCallback,
|
|
37
|
+
mapKey: string = '',
|
|
38
|
+
) {
|
|
39
|
+
super(parentName, `${parentName} Factory`, dexHelper, logger, true, mapKey);
|
|
40
|
+
|
|
41
|
+
this.addressesSubscribed = [factoryAddress];
|
|
42
|
+
|
|
43
|
+
this.logDecoder = (log: Log) => this.factoryIface.parseLog(log);
|
|
44
|
+
|
|
45
|
+
this.handlers['Pool'] = this.handleNewPool.bind(this);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
generateState(): FactoryState {
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
protected async processLog(
|
|
53
|
+
_: DeepReadonly<FactoryState>,
|
|
54
|
+
log: Readonly<Log>,
|
|
55
|
+
): Promise<FactoryState> {
|
|
56
|
+
const event = this.logDecoder(log);
|
|
57
|
+
if (event.name in this.handlers) {
|
|
58
|
+
await this.handlers[event.name](event);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async handleNewPool(event: LogDescription) {
|
|
65
|
+
const token0 = event.args.token0;
|
|
66
|
+
const token1 = event.args.token1;
|
|
67
|
+
|
|
68
|
+
await this.onPoolCreated({ token0, token1 });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -38,14 +38,15 @@ import {
|
|
|
38
38
|
import { AlgebraMath } from './lib/AlgebraMath';
|
|
39
39
|
import { AlgebraEventPoolV1_1 } from './algebra-pool-v1_1';
|
|
40
40
|
import { AlgebraEventPoolV1_9 } from './algebra-pool-v1_9';
|
|
41
|
+
import { AlgebraFactory, OnPoolCreatedCallback } from './algebra-factory';
|
|
41
42
|
|
|
42
43
|
type PoolPairsInfo = {
|
|
43
44
|
token0: Address;
|
|
44
45
|
token1: Address;
|
|
45
46
|
};
|
|
46
47
|
|
|
47
|
-
const ALGEBRA_CLEAN_NOT_EXISTING_POOL_TTL_MS = 3 * 60 * 60 * 1000; // 3
|
|
48
|
-
const ALGEBRA_CLEAN_NOT_EXISTING_POOL_INTERVAL_MS =
|
|
48
|
+
const ALGEBRA_CLEAN_NOT_EXISTING_POOL_TTL_MS = 3 * 24 * 60 * 60 * 1000; // 3 days
|
|
49
|
+
const ALGEBRA_CLEAN_NOT_EXISTING_POOL_INTERVAL_MS = 24 * 60 * 60 * 1000; // Once in a day
|
|
49
50
|
const ALGEBRA_EFFICIENCY_FACTOR = 3;
|
|
50
51
|
const ALGEBRA_TICK_GAS_COST = 24_000; // Ceiled
|
|
51
52
|
const ALGEBRA_TICK_BASE_OVERHEAD = 75_000;
|
|
@@ -59,6 +60,7 @@ const MAX_STALE_STATE_BLOCK_AGE = {
|
|
|
59
60
|
type IAlgebraEventPool = AlgebraEventPoolV1_1 | AlgebraEventPoolV1_9;
|
|
60
61
|
|
|
61
62
|
export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
|
|
63
|
+
private readonly factory: AlgebraFactory;
|
|
62
64
|
readonly isFeeOnTransferSupported: boolean = false;
|
|
63
65
|
protected eventPools: Record<string, IAlgebraEventPool | null> = {};
|
|
64
66
|
|
|
@@ -114,6 +116,14 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
|
|
|
114
116
|
|
|
115
117
|
this.AlgebraPoolImplem =
|
|
116
118
|
config.version === 'v1.1' ? AlgebraEventPoolV1_1 : AlgebraEventPoolV1_9;
|
|
119
|
+
|
|
120
|
+
this.factory = new AlgebraFactory(
|
|
121
|
+
dexHelper,
|
|
122
|
+
dexKey,
|
|
123
|
+
this.config.factory,
|
|
124
|
+
this.logger,
|
|
125
|
+
this.onPoolCreatedDeleteFromNonExistingSet,
|
|
126
|
+
);
|
|
117
127
|
}
|
|
118
128
|
|
|
119
129
|
getAdapters(side: SwapSide): { name: string; index: number }[] | null {
|
|
@@ -126,13 +136,13 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
|
|
|
126
136
|
}
|
|
127
137
|
|
|
128
138
|
async initializePricing(blockNumber: number) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
ALGEBRA_CLEAN_NOT_EXISTING_POOL_TTL_MS;
|
|
139
|
+
// Init listening to new pools creation
|
|
140
|
+
await this.factory.initialize(blockNumber);
|
|
132
141
|
|
|
133
142
|
if (!this.dexHelper.config.isSlave) {
|
|
134
143
|
const cleanExpiredNotExistingPoolsKeys = async () => {
|
|
135
|
-
const maxTimestamp =
|
|
144
|
+
const maxTimestamp =
|
|
145
|
+
Date.now() - ALGEBRA_CLEAN_NOT_EXISTING_POOL_TTL_MS;
|
|
136
146
|
await this.dexHelper.cache.zremrangebyscore(
|
|
137
147
|
this.notExistingPoolSetKey,
|
|
138
148
|
0,
|
|
@@ -147,6 +157,37 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
|
|
|
147
157
|
}
|
|
148
158
|
}
|
|
149
159
|
|
|
160
|
+
/*
|
|
161
|
+
* When a non existing pool is queried, it's blacklisted for an arbitrary long period in order to prevent issuing too many rpc calls
|
|
162
|
+
* Once the pool is created, it gets immediately flagged
|
|
163
|
+
*/
|
|
164
|
+
onPoolCreatedDeleteFromNonExistingSet: OnPoolCreatedCallback = async ({
|
|
165
|
+
token0,
|
|
166
|
+
token1,
|
|
167
|
+
}) => {
|
|
168
|
+
const logPrefix = '[Algebra.onPoolCreatedDeleteFromNonExistingSet]';
|
|
169
|
+
const [_token0, _token1] = this._sortTokens(token0, token1);
|
|
170
|
+
const poolKey = `${token0}_${token1}`.toLowerCase();
|
|
171
|
+
|
|
172
|
+
// consider doing it only from master pool for less calls to distant cache
|
|
173
|
+
|
|
174
|
+
// delete entry locally to let local instance discover the pool
|
|
175
|
+
delete this.eventPools[this.getPoolIdentifier(_token0, _token1)];
|
|
176
|
+
|
|
177
|
+
try {
|
|
178
|
+
this.logger.info(
|
|
179
|
+
`${logPrefix} delete pool from not existing set: ${poolKey}`,
|
|
180
|
+
);
|
|
181
|
+
// delete pool record from set
|
|
182
|
+
await this.dexHelper.cache.zrem(this.notExistingPoolSetKey, [poolKey]);
|
|
183
|
+
} catch (error) {
|
|
184
|
+
this.logger.error(
|
|
185
|
+
`${logPrefix} failed to delete pool from set: ${poolKey}`,
|
|
186
|
+
error,
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
150
191
|
async getPool(
|
|
151
192
|
srcAddress: Address,
|
|
152
193
|
destAddress: Address,
|
|
@@ -83,7 +83,6 @@ export const AlgebraConfig: DexConfigMap<DexParams> = {
|
|
|
83
83
|
uniswapMulticall: '0x1F98415757620B543A52E61c46B32eB19261F984',
|
|
84
84
|
deployer: '0x6dd3fb9653b10e806650f107c3b5a0a6ff974f65',
|
|
85
85
|
version: 'v1.9',
|
|
86
|
-
cleanExistingPoolTTLMs: 20 * 60 * 1000,
|
|
87
86
|
},
|
|
88
87
|
},
|
|
89
88
|
};
|
package/src/dex/algebra/types.ts
CHANGED
|
@@ -51,6 +51,8 @@ export type PoolState_v1_9 = {
|
|
|
51
51
|
areTicksCompressed: boolean;
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
+
export type FactoryState = Record<string, never>;
|
|
55
|
+
|
|
54
56
|
export type AlgebraData = {
|
|
55
57
|
path: {
|
|
56
58
|
tokenIn: Address;
|
|
@@ -73,7 +75,6 @@ export type DexParams = {
|
|
|
73
75
|
version: 'v1.1' | 'v1.9';
|
|
74
76
|
forceRPC?: boolean;
|
|
75
77
|
forceManualStateGenerate?: boolean;
|
|
76
|
-
cleanExistingPoolTTLMs?: number;
|
|
77
78
|
};
|
|
78
79
|
|
|
79
80
|
export type IAlgebraPoolState = PoolStateV1_1 | PoolState_v1_9;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { DeepReadonly } from 'ts-essentials';
|
|
3
|
+
import FactoryABI from '../../abi/pancakeswap-v3/PancakeswapV3Factory.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 '../uniswap-v3/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 PancakeswapV3Factory 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;
|
|
68
|
+
const token1 = event.args.token1;
|
|
69
|
+
const fee = event.args.fee;
|
|
70
|
+
|
|
71
|
+
await this.onPoolCreated({ token0, token1, fee });
|
|
72
|
+
}
|
|
73
|
+
}
|