@paraswap/dex-lib 2.28.11 → 2.28.12-ramses.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/.idea/aws.xml +17 -0
- package/.idea/codeStyles/Project.xml +19 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/paraswap-dex-lib.iml +9 -0
- package/.idea/vcs.xml +6 -0
- package/build/abi/RamsesV2StateMulticall.abi.json +891 -0
- package/build/abi/algebra/AlgebraPool.abi.json +727 -0
- package/build/abi/curve-v1/StableSwapFRXETH.json +889 -0
- package/build/abi/curve-v1/StableSwapWBETH.json +1223 -0
- package/build/abi/wBETH.json +1527 -0
- package/build/dex/algebra/algebra-pool.d.ts +46 -0
- package/build/dex/algebra/algebra-pool.js +336 -0
- package/build/dex/algebra/algebra-pool.js.map +1 -0
- package/build/dex/curve-v1/pools/frxETHpool.d.ts +7 -0
- package/build/dex/curve-v1/pools/frxETHpool.js +27 -0
- package/build/dex/curve-v1/pools/frxETHpool.js.map +1 -0
- package/build/dex/curve-v1/pools/wbETHpool.d.ts +29 -0
- package/build/dex/curve-v1/pools/wbETHpool.js +408 -0
- package/build/dex/curve-v1/pools/wbETHpool.js.map +1 -0
- package/build/dex/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/pancakeswap-v3/types.d.ts +14 -0
- package/build/dex/{test-dex → pancakeswap-v3}/types.js.map +1 -1
- package/build/dex/{test-dex → ramses-v2}/config.d.ts +1 -1
- package/build/dex/ramses-v2/config.js +28 -0
- package/build/dex/ramses-v2/config.js.map +1 -0
- package/build/dex/ramses-v2/constants.d.ts +28 -0
- package/build/dex/ramses-v2/constants.js +35 -0
- package/build/dex/ramses-v2/constants.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/BitMath.d.ts +4 -0
- package/build/dex/ramses-v2/contract-math/BitMath.js +93 -0
- package/build/dex/ramses-v2/contract-math/BitMath.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/FixedPoint128.d.ts +3 -0
- package/build/dex/ramses-v2/contract-math/FixedPoint128.js +8 -0
- package/build/dex/ramses-v2/contract-math/FixedPoint128.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/FixedPoint96.d.ts +4 -0
- package/build/dex/ramses-v2/contract-math/FixedPoint96.js +9 -0
- package/build/dex/ramses-v2/contract-math/FixedPoint96.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/FullMath.d.ts +4 -0
- package/build/dex/ramses-v2/contract-math/FullMath.js +19 -0
- package/build/dex/ramses-v2/contract-math/FullMath.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/LiquidityMath.d.ts +3 -0
- package/build/dex/ramses-v2/contract-math/LiquidityMath.js +22 -0
- package/build/dex/ramses-v2/contract-math/LiquidityMath.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/Oracle.d.ts +10 -0
- package/build/dex/ramses-v2/contract-math/Oracle.js +133 -0
- package/build/dex/ramses-v2/contract-math/Oracle.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/SqrtPriceMath.d.ts +10 -0
- package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js +91 -0
- package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/SwapMath.d.ts +8 -0
- package/build/dex/ramses-v2/contract-math/SwapMath.js +70 -0
- package/build/dex/ramses-v2/contract-math/SwapMath.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/Tick.d.ts +7 -0
- package/build/dex/ramses-v2/contract-math/Tick.js +45 -0
- package/build/dex/ramses-v2/contract-math/Tick.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/TickBitMap.d.ts +8 -0
- package/build/dex/ramses-v2/contract-math/TickBitMap.js +87 -0
- package/build/dex/ramses-v2/contract-math/TickBitMap.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/TickMath.d.ts +8 -0
- package/build/dex/ramses-v2/contract-math/TickMath.js +162 -0
- package/build/dex/ramses-v2/contract-math/TickMath.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/UnsafeMath.d.ts +3 -0
- package/build/dex/ramses-v2/contract-math/UnsafeMath.js +10 -0
- package/build/dex/ramses-v2/contract-math/UnsafeMath.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/uniswap-v3-math.d.ts +18 -0
- package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js +392 -0
- package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/utils.d.ts +3 -0
- package/build/dex/ramses-v2/contract-math/utils.js +16 -0
- package/build/dex/ramses-v2/contract-math/utils.js.map +1 -0
- package/build/dex/ramses-v2/ramses-v2-pool.d.ts +42 -0
- package/build/dex/ramses-v2/ramses-v2-pool.js +307 -0
- package/build/dex/ramses-v2/ramses-v2-pool.js.map +1 -0
- package/build/dex/ramses-v2/ramses-v2.d.ts +61 -0
- package/build/dex/ramses-v2/ramses-v2.js +690 -0
- package/build/dex/ramses-v2/ramses-v2.js.map +1 -0
- package/build/dex/ramses-v2/types.d.ts +154 -0
- package/build/dex/ramses-v2/types.js +9 -0
- package/build/dex/ramses-v2/types.js.map +1 -0
- package/build/dex/ramses-v2/utils.d.ts +6 -0
- package/build/dex/ramses-v2/utils.js +71 -0
- package/build/dex/ramses-v2/utils.js.map +1 -0
- package/build/dex/solidly/config.js +11 -1
- package/build/dex/solidly/config.js.map +1 -1
- package/build/dex/solidly/forks-override/ramses.d.ts +44 -0
- package/build/dex/solidly/forks-override/ramses.js +132 -0
- package/build/dex/solidly/forks-override/ramses.js.map +1 -0
- package/build/dex/solidly/solidly.js +1 -0
- package/build/dex/solidly/solidly.js.map +1 -1
- package/build/dex/uniswap-v3/forks/ramses-v2/utils.d.ts +4 -0
- package/build/dex/uniswap-v3/forks/ramses-v2/utils.js +63 -0
- package/build/dex/uniswap-v3/forks/ramses-v2/utils.js.map +1 -0
- package/package.json +1 -1
- package/src/dex/index.ts +2 -0
- package/src/dex/solidly/config.ts +13 -1
- package/src/dex/solidly/forks-override/ramses.ts +224 -0
- package/src/dex/solidly/solidly-e2e.test.ts +95 -0
- package/src/dex/solidly/solidly-integration.test.ts +141 -1
- package/src/dex/solidly/solidly.ts +2 -0
- package/build/dex/test-dex/config.js +0 -15
- package/build/dex/test-dex/config.js.map +0 -1
- package/build/dex/test-dex/test-dex-pool.d.ts +0 -39
- package/build/dex/test-dex/test-dex-pool.js +0 -63
- package/build/dex/test-dex/test-dex-pool.js.map +0 -1
- package/build/dex/test-dex/test-dex.d.ts +0 -37
- package/build/dex/test-dex/test-dex.js +0 -126
- package/build/dex/test-dex/test-dex.js.map +0 -1
- package/build/dex/test-dex/types.d.ts +0 -6
- 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/dex/{test-dex → pancakeswap-v3}/types.js +0 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeStateMultiCallResultWithRelativeBitmaps = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const decoders_1 = require("../../../../lib/decoders");
|
|
6
|
+
const ts_essentials_1 = require("ts-essentials");
|
|
7
|
+
function decodeStateMultiCallResultWithRelativeBitmaps(result) {
|
|
8
|
+
const [isSuccess, toDecode] = (0, decoders_1.extractSuccessAndValue)(result);
|
|
9
|
+
(0, ts_essentials_1.assert)(isSuccess && toDecode !== '0x', `decodeStateMultiCallResultWithRelativeBitmaps failed to get decodable result: ${result}`);
|
|
10
|
+
const decoded = ethers_1.ethers.utils.defaultAbiCoder.decode([
|
|
11
|
+
// I don't want to pass here any interface, so I just use it in ethers format
|
|
12
|
+
`
|
|
13
|
+
tuple(
|
|
14
|
+
address pool,
|
|
15
|
+
uint256 blockTimestamp,
|
|
16
|
+
tuple(
|
|
17
|
+
uint160 sqrtPriceX96,
|
|
18
|
+
int24 tick,
|
|
19
|
+
uint16 observationIndex,
|
|
20
|
+
uint16 observationCardinality,
|
|
21
|
+
uint16 observationCardinalityNext,
|
|
22
|
+
uint8 feeProtocol,
|
|
23
|
+
bool unlocked,
|
|
24
|
+
) slot0,
|
|
25
|
+
uint128 liquidity,
|
|
26
|
+
int24 tickSpacing,
|
|
27
|
+
uint128 maxLiquidityPerTick,
|
|
28
|
+
tuple(
|
|
29
|
+
uint32 blockTimestamp,
|
|
30
|
+
int56 tickCumulative,
|
|
31
|
+
uint160 secondsPerLiquidityCumulativeX128,
|
|
32
|
+
bool initialized,
|
|
33
|
+
uint160 secondsPerBoostedLiquidityPeriodX128,
|
|
34
|
+
uint32 boostedInRange,
|
|
35
|
+
) observation,
|
|
36
|
+
tuple(
|
|
37
|
+
int16 index,
|
|
38
|
+
uint256 value
|
|
39
|
+
)[] tickBitmap,
|
|
40
|
+
tuple(
|
|
41
|
+
int24 index,
|
|
42
|
+
tuple(
|
|
43
|
+
uint128 liquidityGross,
|
|
44
|
+
int128 liquidityNet,
|
|
45
|
+
uint128 cleanUnusedSlot,
|
|
46
|
+
uint128 cleanUnusedSlot2,
|
|
47
|
+
uint256 feeGrowthOutside0X128,
|
|
48
|
+
uint256 feeGrowthOutside1X128,
|
|
49
|
+
int56 tickCumulativeOutside,
|
|
50
|
+
uint160 secondsPerLiquidityOutsideX128,
|
|
51
|
+
uint32 secondsOutside,
|
|
52
|
+
bool initialized,
|
|
53
|
+
) value,
|
|
54
|
+
)[] ticks
|
|
55
|
+
)
|
|
56
|
+
`,
|
|
57
|
+
], toDecode)[0];
|
|
58
|
+
// This conversion is not precise, because when we decode, we have more values
|
|
59
|
+
// But I typed only the ones that are used later
|
|
60
|
+
return decoded;
|
|
61
|
+
}
|
|
62
|
+
exports.decodeStateMultiCallResultWithRelativeBitmaps = decodeStateMultiCallResultWithRelativeBitmaps;
|
|
63
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../src/dex/uniswap-v3/forks/ramses-v2/utils.ts"],"names":[],"mappings":";;;AACA,mCAA2C;AAE3C,uDAAkE;AAClE,iDAAuC;AAEvC,SAAgB,6CAA6C,CAC3D,MAA0C;IAE1C,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,GAAG,IAAA,iCAAsB,EAAC,MAAM,CAAC,CAAC;IAE7D,IAAA,sBAAM,EACJ,SAAS,IAAI,QAAQ,KAAK,IAAI,EAC9B,iFAAiF,MAAM,EAAE,CAC1F,CAAC;IAEF,MAAM,OAAO,GAAG,eAAM,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,CACjD;QACE,6EAA6E;QAC7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4CD;KACA,EACD,QAAQ,CACT,CAAC,CAAC,CAAC,CAAC;IAEL,8EAA8E;IAC9E,gDAAgD;IAChD,OAAO,OAAyD,CAAC;AACnE,CAAC;AAjED,sGAiEC"}
|
package/package.json
CHANGED
package/src/dex/index.ts
CHANGED
|
@@ -42,6 +42,7 @@ import { WooFiV2 } from './woo-fi-v2/woo-fi-v2';
|
|
|
42
42
|
import { ParaSwapLimitOrders } from './paraswap-limit-orders/paraswap-limit-orders';
|
|
43
43
|
import { AugustusRFQOrder } from './augustus-rfq';
|
|
44
44
|
import { Solidly } from './solidly/solidly';
|
|
45
|
+
import { Ramses } from './solidly/forks-override/ramses';
|
|
45
46
|
import { Thena } from './solidly/forks-override/thena';
|
|
46
47
|
import { Chronos } from './solidly/forks-override/chronos';
|
|
47
48
|
import { Velodrome } from './solidly/forks-override/velodrome';
|
|
@@ -124,6 +125,7 @@ const Dexes = [
|
|
|
124
125
|
Solidly,
|
|
125
126
|
SolidlyEthereum,
|
|
126
127
|
SpiritSwapV2,
|
|
128
|
+
Ramses,
|
|
127
129
|
Thena,
|
|
128
130
|
Chronos,
|
|
129
131
|
Velodrome,
|
|
@@ -125,6 +125,18 @@ export const SolidlyConfig: DexConfigMap<DexParams> = {
|
|
|
125
125
|
feeCode: 0,
|
|
126
126
|
},
|
|
127
127
|
},
|
|
128
|
+
Ramses: {
|
|
129
|
+
[Network.ARBITRUM]: {
|
|
130
|
+
subgraphURL:
|
|
131
|
+
'https://api.thegraph.com/subgraphs/name/ramsesexchange/api-subgraph',
|
|
132
|
+
factoryAddress: '0xAAA20D08e59F6561f242b08513D36266C5A29415',
|
|
133
|
+
router: '0xb2634B3CBc1E401AB3C2743DB44d459C5c9aA662',
|
|
134
|
+
initCode:
|
|
135
|
+
'0x1565b129f2d1790f12d45301b9b084335626f0c92410bc43130763b69971135d',
|
|
136
|
+
poolGasCost: 180 * 1000,
|
|
137
|
+
feeCode: 0,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
128
140
|
};
|
|
129
141
|
|
|
130
142
|
export const Adapters: Record<number, AdapterMappings> = {
|
|
@@ -147,6 +159,6 @@ export const Adapters: Record<number, AdapterMappings> = {
|
|
|
147
159
|
[SwapSide.SELL]: [{ name: 'AvalancheAdapter02', index: 3 }], // solisnek
|
|
148
160
|
},
|
|
149
161
|
[Network.ARBITRUM]: {
|
|
150
|
-
[SwapSide.SELL]: [{ name: 'ArbitrumAdapter02', index: 1 }], // chronos
|
|
162
|
+
[SwapSide.SELL]: [{ name: 'ArbitrumAdapter02', index: 1 }], // chronos, ramses
|
|
151
163
|
},
|
|
152
164
|
};
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { Network, SUBGRAPH_TIMEOUT } from '../../../constants';
|
|
2
|
+
import { getDexKeysWithNetwork } from '../../../utils';
|
|
3
|
+
import { SolidlyConfig } from '../config';
|
|
4
|
+
import _ from 'lodash';
|
|
5
|
+
import { Address, PoolLiquidity } from '../../../types';
|
|
6
|
+
import BigNumber from 'bignumber.js';
|
|
7
|
+
import { Solidly } from '../solidly';
|
|
8
|
+
import { IDexHelper } from '../../../dex-helper';
|
|
9
|
+
import { SolidlyPair } from '../types';
|
|
10
|
+
import { Interface } from '@ethersproject/abi';
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
const RamsesFactoryABI = [
|
|
14
|
+
{
|
|
15
|
+
inputs: [{internalType: 'address', name: '', type: 'address'}],
|
|
16
|
+
name: 'pairFee',
|
|
17
|
+
outputs: [{internalType: 'uint256', 'name': '', type: 'uint256'}],
|
|
18
|
+
stateMutability: 'view',
|
|
19
|
+
type: 'function',
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const ramsesFactoryIface = new Interface(RamsesFactoryABI);
|
|
24
|
+
|
|
25
|
+
export type RamsesSubgraphPool = {
|
|
26
|
+
id: string;
|
|
27
|
+
isStable: boolean;
|
|
28
|
+
token0: string;
|
|
29
|
+
reserve0: string;
|
|
30
|
+
reserve1: string;
|
|
31
|
+
token1: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type RamsesSubgraphToken = {
|
|
35
|
+
id: string;
|
|
36
|
+
decimals: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class Ramses extends Solidly {
|
|
40
|
+
|
|
41
|
+
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
|
|
42
|
+
getDexKeysWithNetwork(_.pick(SolidlyConfig, ['Ramses']));
|
|
43
|
+
|
|
44
|
+
constructor(
|
|
45
|
+
protected network: Network,
|
|
46
|
+
dexKey: string,
|
|
47
|
+
protected dexHelper: IDexHelper,
|
|
48
|
+
) {
|
|
49
|
+
super(
|
|
50
|
+
network,
|
|
51
|
+
dexKey,
|
|
52
|
+
dexHelper,
|
|
53
|
+
true, // dynamic fees
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
protected getFeesMultiCallData(pair: SolidlyPair) {
|
|
58
|
+
const callEntry = {
|
|
59
|
+
target: this.factoryAddress,
|
|
60
|
+
callData: ramsesFactoryIface.encodeFunctionData('pairFee', [pair.exchange]),
|
|
61
|
+
};
|
|
62
|
+
const callDecoder = (values: any[]) =>
|
|
63
|
+
parseInt(
|
|
64
|
+
ramsesFactoryIface
|
|
65
|
+
.decodeFunctionResult('pairFee', values)[0]
|
|
66
|
+
.toString(),
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
callEntry,
|
|
71
|
+
callDecoder,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async getTopPoolsForToken(
|
|
76
|
+
tokenAddress: Address,
|
|
77
|
+
count: number,
|
|
78
|
+
): Promise<PoolLiquidity[]> {
|
|
79
|
+
if (!this.subgraphURL) return [];
|
|
80
|
+
|
|
81
|
+
const query = `query ($token: Bytes!, $count: Int) {
|
|
82
|
+
pools0: pairs(first: $count, orderBy: reserve0, orderDirection: desc, where: {token0: $token, reserve0_gt: 1, reserve1_gt: 1}) {
|
|
83
|
+
id
|
|
84
|
+
isStable
|
|
85
|
+
token0
|
|
86
|
+
token1
|
|
87
|
+
reserve0,
|
|
88
|
+
reserve1,
|
|
89
|
+
}
|
|
90
|
+
pools1: pairs(first: $count, orderBy: reserve1, orderDirection: desc, where: {token1: $token, reserve0_gt: 1, reserve1_gt: 1}) {
|
|
91
|
+
id
|
|
92
|
+
isStable
|
|
93
|
+
token0
|
|
94
|
+
token1
|
|
95
|
+
reserve0,
|
|
96
|
+
reserve1,
|
|
97
|
+
}
|
|
98
|
+
}`;
|
|
99
|
+
|
|
100
|
+
const { data } = await this.dexHelper.httpRequest.post(
|
|
101
|
+
this.subgraphURL,
|
|
102
|
+
{
|
|
103
|
+
query,
|
|
104
|
+
variables: { token: tokenAddress.toLowerCase(), count },
|
|
105
|
+
},
|
|
106
|
+
SUBGRAPH_TIMEOUT,
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
if (!(data && data.pools0 && data.pools1))
|
|
110
|
+
throw new Error("Couldn't fetch the pools from the subgraph");
|
|
111
|
+
|
|
112
|
+
const tokenIds = _.uniq([].concat(data.pools0, data.pools1).map(
|
|
113
|
+
(pool: RamsesSubgraphPool) => [ pool.token0, pool.token1]).flat(),
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const tokensQuery = `
|
|
117
|
+
query ($tokenIds: [String!]) {
|
|
118
|
+
tokens(where: {id_in: $tokenIds}) {
|
|
119
|
+
id
|
|
120
|
+
decimals
|
|
121
|
+
}
|
|
122
|
+
}`;
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
const { data: tokensData } = await this.dexHelper.httpRequest.post(
|
|
126
|
+
this.subgraphURL,
|
|
127
|
+
{
|
|
128
|
+
query: tokensQuery,
|
|
129
|
+
variables: { tokenIds },
|
|
130
|
+
},
|
|
131
|
+
SUBGRAPH_TIMEOUT,
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
const pools0 = await this.prepareSubgraphPools(tokensData.tokens, data.pools0, (pool,{
|
|
135
|
+
address1, decimals1, liquidityUSDToken0, liquidityUSDToken1,
|
|
136
|
+
}) => ({
|
|
137
|
+
exchange: this.dexKey,
|
|
138
|
+
stable: pool.isStable,
|
|
139
|
+
address: pool.id.toLowerCase(),
|
|
140
|
+
connectorTokens: [
|
|
141
|
+
{
|
|
142
|
+
address: address1,
|
|
143
|
+
decimals: decimals1,
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
liquidityUSD: liquidityUSDToken0 + liquidityUSDToken1,
|
|
147
|
+
}));
|
|
148
|
+
|
|
149
|
+
const pools1 = await this.prepareSubgraphPools(tokensData.tokens, data.pools1, (pool,{
|
|
150
|
+
address0, decimals0, liquidityUSDToken0, liquidityUSDToken1,
|
|
151
|
+
}) => ({
|
|
152
|
+
exchange: this.dexKey,
|
|
153
|
+
stable: pool.isStable,
|
|
154
|
+
address: pool.id.toLowerCase(),
|
|
155
|
+
connectorTokens: [
|
|
156
|
+
{
|
|
157
|
+
address: address0,
|
|
158
|
+
decimals: decimals0,
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
liquidityUSD: liquidityUSDToken0 + liquidityUSDToken1,
|
|
162
|
+
}));
|
|
163
|
+
|
|
164
|
+
return _.slice(
|
|
165
|
+
_.sortBy(_.concat(pools0, pools1), [pool => -1 * pool.liquidityUSD]),
|
|
166
|
+
0,
|
|
167
|
+
count,
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
protected async prepareSubgraphPools(
|
|
172
|
+
tokens: RamsesSubgraphToken[],
|
|
173
|
+
pools: RamsesSubgraphPool[],
|
|
174
|
+
iterator: (
|
|
175
|
+
pool: RamsesSubgraphPool, {
|
|
176
|
+
address0,
|
|
177
|
+
address1,
|
|
178
|
+
decimals0,
|
|
179
|
+
decimals1,
|
|
180
|
+
reserve0,
|
|
181
|
+
reserve1,
|
|
182
|
+
liquidityUSDToken0,
|
|
183
|
+
liquidityUSDToken1,
|
|
184
|
+
}: {
|
|
185
|
+
address0: string,
|
|
186
|
+
address1: string,
|
|
187
|
+
decimals0: number,
|
|
188
|
+
decimals1: number,
|
|
189
|
+
reserve0: bigint,
|
|
190
|
+
reserve1: bigint,
|
|
191
|
+
liquidityUSDToken0: number,
|
|
192
|
+
liquidityUSDToken1: number,
|
|
193
|
+
}) => PoolLiquidity
|
|
194
|
+
): Promise<PoolLiquidity[]> {
|
|
195
|
+
return Promise.all(pools.map(async (
|
|
196
|
+
pool: RamsesSubgraphPool,
|
|
197
|
+
) => {
|
|
198
|
+
const address0 = pool.token0.toLowerCase();
|
|
199
|
+
const address1 = pool.token1.toLowerCase();
|
|
200
|
+
|
|
201
|
+
const decimals0 = parseInt(tokens.find((t) => t.id === address0)!.decimals);
|
|
202
|
+
const decimals1 = parseInt(tokens.find((t) => t.id === address1)!.decimals);
|
|
203
|
+
|
|
204
|
+
const reserve0 = BigInt(new BigNumber(pool.reserve0).multipliedBy(10 ** decimals0).toFixed());
|
|
205
|
+
const reserve1 = BigInt(new BigNumber(pool.reserve1).multipliedBy(10 ** decimals1).toFixed());
|
|
206
|
+
|
|
207
|
+
const liquidityUSDToken0 = await this.dexHelper.getTokenUSDPrice({
|
|
208
|
+
address: address0,
|
|
209
|
+
decimals: decimals0,
|
|
210
|
+
}, reserve0);
|
|
211
|
+
|
|
212
|
+
const liquidityUSDToken1 = await this.dexHelper.getTokenUSDPrice({
|
|
213
|
+
address: address1,
|
|
214
|
+
decimals: decimals1,
|
|
215
|
+
}, reserve1);
|
|
216
|
+
|
|
217
|
+
return iterator(
|
|
218
|
+
pool, {
|
|
219
|
+
address0, address1, decimals0, decimals1, reserve0, reserve1, liquidityUSDToken0, liquidityUSDToken1,
|
|
220
|
+
},
|
|
221
|
+
);
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
}
|
|
@@ -1179,5 +1179,100 @@ describe('Solidly E2E', () => {
|
|
|
1179
1179
|
}),
|
|
1180
1180
|
);
|
|
1181
1181
|
});
|
|
1182
|
+
|
|
1183
|
+
describe('Ramses', () => {
|
|
1184
|
+
const dexKey = 'Ramses';
|
|
1185
|
+
|
|
1186
|
+
const sideToContractMethods = new Map([
|
|
1187
|
+
[
|
|
1188
|
+
SwapSide.SELL,
|
|
1189
|
+
[
|
|
1190
|
+
ContractMethod.simpleSwap,
|
|
1191
|
+
ContractMethod.multiSwap,
|
|
1192
|
+
ContractMethod.megaSwap,
|
|
1193
|
+
],
|
|
1194
|
+
],
|
|
1195
|
+
]);
|
|
1196
|
+
|
|
1197
|
+
const pairs: { name: string; sellAmount: string }[][] = [
|
|
1198
|
+
[
|
|
1199
|
+
{
|
|
1200
|
+
name: 'ETH',
|
|
1201
|
+
sellAmount: '1000000000000000000',
|
|
1202
|
+
},
|
|
1203
|
+
{
|
|
1204
|
+
name: 'USDCe',
|
|
1205
|
+
sellAmount: '100000000',
|
|
1206
|
+
},
|
|
1207
|
+
],
|
|
1208
|
+
[
|
|
1209
|
+
{
|
|
1210
|
+
name: 'WETH',
|
|
1211
|
+
sellAmount: '1000000000000000000',
|
|
1212
|
+
},
|
|
1213
|
+
{
|
|
1214
|
+
name: 'USDCe',
|
|
1215
|
+
sellAmount: '100000000',
|
|
1216
|
+
},
|
|
1217
|
+
],
|
|
1218
|
+
[
|
|
1219
|
+
{
|
|
1220
|
+
name: 'USDT',
|
|
1221
|
+
sellAmount: '100000000',
|
|
1222
|
+
},
|
|
1223
|
+
{
|
|
1224
|
+
name: 'USDCe',
|
|
1225
|
+
sellAmount: '100000000',
|
|
1226
|
+
},
|
|
1227
|
+
],
|
|
1228
|
+
[
|
|
1229
|
+
{
|
|
1230
|
+
name: 'USDCe',
|
|
1231
|
+
sellAmount: '100000000',
|
|
1232
|
+
},
|
|
1233
|
+
{
|
|
1234
|
+
name: 'DAI',
|
|
1235
|
+
sellAmount: '100000000000000000000',
|
|
1236
|
+
},
|
|
1237
|
+
],
|
|
1238
|
+
];
|
|
1239
|
+
|
|
1240
|
+
sideToContractMethods.forEach((contractMethods, side) =>
|
|
1241
|
+
describe(`${side}`, () => {
|
|
1242
|
+
contractMethods.forEach((contractMethod: ContractMethod) => {
|
|
1243
|
+
pairs.forEach(pair => {
|
|
1244
|
+
describe(`${contractMethod}`, () => {
|
|
1245
|
+
it(`${pair[0].name} -> ${pair[1].name}`, async () => {
|
|
1246
|
+
await testE2E(
|
|
1247
|
+
tokens[pair[0].name],
|
|
1248
|
+
tokens[pair[1].name],
|
|
1249
|
+
holders[pair[0].name],
|
|
1250
|
+
pair[0].sellAmount,
|
|
1251
|
+
side,
|
|
1252
|
+
dexKey,
|
|
1253
|
+
contractMethod,
|
|
1254
|
+
network,
|
|
1255
|
+
provider,
|
|
1256
|
+
);
|
|
1257
|
+
});
|
|
1258
|
+
it(`${pair[1].name} -> ${pair[0].name}`, async () => {
|
|
1259
|
+
await testE2E(
|
|
1260
|
+
tokens[pair[1].name],
|
|
1261
|
+
tokens[pair[0].name],
|
|
1262
|
+
holders[pair[1].name],
|
|
1263
|
+
pair[1].sellAmount,
|
|
1264
|
+
side,
|
|
1265
|
+
dexKey,
|
|
1266
|
+
contractMethod,
|
|
1267
|
+
network,
|
|
1268
|
+
provider,
|
|
1269
|
+
);
|
|
1270
|
+
});
|
|
1271
|
+
});
|
|
1272
|
+
});
|
|
1273
|
+
});
|
|
1274
|
+
}),
|
|
1275
|
+
);
|
|
1276
|
+
});
|
|
1182
1277
|
});
|
|
1183
1278
|
});
|
|
@@ -12,6 +12,8 @@ import solidlyPairABI from '../../abi/solidly/SolidlyPair.json';
|
|
|
12
12
|
import { SpiritSwapV2 } from './forks-override/spiritSwapV2';
|
|
13
13
|
import { Cone } from './forks-override/cone';
|
|
14
14
|
import { Chronos } from './forks-override/chronos';
|
|
15
|
+
import { Ramses } from './forks-override/ramses';
|
|
16
|
+
import * as util from 'util';
|
|
15
17
|
|
|
16
18
|
const amounts18 = [0n, BI_POWS[18], 2000000000000000000n];
|
|
17
19
|
const amounts6 = [0n, BI_POWS[6], 2000000n];
|
|
@@ -60,7 +62,7 @@ const constructCheckOnChainPricing =
|
|
|
60
62
|
funcName,
|
|
61
63
|
tokenIn,
|
|
62
64
|
);
|
|
63
|
-
|
|
65
|
+
|
|
64
66
|
const readerResult = (
|
|
65
67
|
await dexHelper.multiContract.methods
|
|
66
68
|
.aggregate(readerCallData)
|
|
@@ -70,6 +72,8 @@ const constructCheckOnChainPricing =
|
|
|
70
72
|
decodeReaderResult(readerResult, readerIface, funcName),
|
|
71
73
|
);
|
|
72
74
|
|
|
75
|
+
console.log('ON-CHAIN PRICES: ', expectedPrices);
|
|
76
|
+
|
|
73
77
|
expect(prices.map(p => p.toString())).toEqual(
|
|
74
78
|
expectedPrices.map(p => p.toString()),
|
|
75
79
|
);
|
|
@@ -768,5 +772,141 @@ describe('Solidly integration tests', () => {
|
|
|
768
772
|
});
|
|
769
773
|
});
|
|
770
774
|
});
|
|
775
|
+
|
|
776
|
+
describe('Ramses', function () {
|
|
777
|
+
const dexKey = 'Ramses';
|
|
778
|
+
const ramses = new Ramses(network, dexKey, dexHelper);
|
|
779
|
+
|
|
780
|
+
describe('UniswapV2 like pool', function () {
|
|
781
|
+
const TokenASymbol = 'USDCe';
|
|
782
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
783
|
+
const TokenBSymbol = 'WETH';
|
|
784
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
785
|
+
|
|
786
|
+
const amounts = amounts18;
|
|
787
|
+
|
|
788
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
789
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
790
|
+
const pools = await ramses.getPoolIdentifiers(
|
|
791
|
+
tokenA,
|
|
792
|
+
tokenB,
|
|
793
|
+
SwapSide.SELL,
|
|
794
|
+
blocknumber,
|
|
795
|
+
);
|
|
796
|
+
console.log(
|
|
797
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
798
|
+
pools,
|
|
799
|
+
);
|
|
800
|
+
|
|
801
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
802
|
+
|
|
803
|
+
console.log('AMOUNTS: ', amounts);
|
|
804
|
+
|
|
805
|
+
const poolPrices = await ramses.getPricesVolume(
|
|
806
|
+
tokenA,
|
|
807
|
+
tokenB,
|
|
808
|
+
amounts,
|
|
809
|
+
SwapSide.SELL,
|
|
810
|
+
blocknumber,
|
|
811
|
+
pools,
|
|
812
|
+
);
|
|
813
|
+
console.log(
|
|
814
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
815
|
+
util.inspect(poolPrices, false, null, true),
|
|
816
|
+
);
|
|
817
|
+
|
|
818
|
+
expect(poolPrices).not.toBeNull();
|
|
819
|
+
// checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
820
|
+
|
|
821
|
+
// Check if onchain pricing equals to calculated ones
|
|
822
|
+
|
|
823
|
+
for (const i in poolPrices || []) {
|
|
824
|
+
await checkOnChainPricing(
|
|
825
|
+
ramses,
|
|
826
|
+
'getAmountOut',
|
|
827
|
+
blocknumber,
|
|
828
|
+
poolPrices![i].prices,
|
|
829
|
+
poolPrices![i].poolAddresses![0],
|
|
830
|
+
tokenA.address,
|
|
831
|
+
amounts,
|
|
832
|
+
);
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
|
|
836
|
+
it('getTopPoolsForToken', async function () {
|
|
837
|
+
const poolLiquidity = await ramses.getTopPoolsForToken(
|
|
838
|
+
tokenA.address,
|
|
839
|
+
10,
|
|
840
|
+
);
|
|
841
|
+
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
842
|
+
|
|
843
|
+
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
844
|
+
});
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
describe('Curve like stable pool', function () {
|
|
848
|
+
const TokenASymbol = 'USDT';
|
|
849
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
850
|
+
const TokenBSymbol = 'USDCe';
|
|
851
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
852
|
+
|
|
853
|
+
const amounts = amounts6;
|
|
854
|
+
|
|
855
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
856
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
857
|
+
const pools = await ramses.getPoolIdentifiers(
|
|
858
|
+
tokenA,
|
|
859
|
+
tokenB,
|
|
860
|
+
SwapSide.SELL,
|
|
861
|
+
blocknumber,
|
|
862
|
+
);
|
|
863
|
+
console.log(
|
|
864
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
865
|
+
pools,
|
|
866
|
+
);
|
|
867
|
+
|
|
868
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
869
|
+
|
|
870
|
+
const poolPrices = await ramses.getPricesVolume(
|
|
871
|
+
tokenA,
|
|
872
|
+
tokenB,
|
|
873
|
+
amounts,
|
|
874
|
+
SwapSide.SELL,
|
|
875
|
+
blocknumber,
|
|
876
|
+
pools,
|
|
877
|
+
);
|
|
878
|
+
console.log(
|
|
879
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
880
|
+
poolPrices,
|
|
881
|
+
);
|
|
882
|
+
|
|
883
|
+
expect(poolPrices).not.toBeNull();
|
|
884
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
885
|
+
|
|
886
|
+
// Check if onchain pricing equals to calculated ones
|
|
887
|
+
for (const i in poolPrices || []) {
|
|
888
|
+
await checkOnChainPricing(
|
|
889
|
+
ramses,
|
|
890
|
+
'getAmountOut',
|
|
891
|
+
blocknumber,
|
|
892
|
+
poolPrices![i].prices,
|
|
893
|
+
poolPrices![i].poolAddresses![0],
|
|
894
|
+
tokenA.address,
|
|
895
|
+
amounts,
|
|
896
|
+
);
|
|
897
|
+
}
|
|
898
|
+
});
|
|
899
|
+
|
|
900
|
+
it('getTopPoolsForToken', async function () {
|
|
901
|
+
const poolLiquidity = await ramses.getTopPoolsForToken(
|
|
902
|
+
tokenA.address,
|
|
903
|
+
10,
|
|
904
|
+
);
|
|
905
|
+
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
906
|
+
|
|
907
|
+
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
908
|
+
});
|
|
909
|
+
});
|
|
910
|
+
});
|
|
771
911
|
});
|
|
772
912
|
});
|
|
@@ -72,6 +72,7 @@ export class Solidly extends UniswapV2 {
|
|
|
72
72
|
'Thena',
|
|
73
73
|
'SoliSnek',
|
|
74
74
|
'Chronos',
|
|
75
|
+
'Ramses'
|
|
75
76
|
]),
|
|
76
77
|
);
|
|
77
78
|
|
|
@@ -520,6 +521,7 @@ export class Solidly extends UniswapV2 {
|
|
|
520
521
|
const pair = await this.findSolidlyPair(from, to, stable);
|
|
521
522
|
if (!(pair && pair.pool && pair.exchange)) return null;
|
|
522
523
|
const pairState = pair.pool.getState(blockNumber);
|
|
524
|
+
|
|
523
525
|
if (!pairState) {
|
|
524
526
|
this.logger.error(
|
|
525
527
|
`Error_orderPairParams expected reserves, got none (maybe the pool doesn't exist) ${
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Adapters = exports.TestDexConfig = void 0;
|
|
4
|
-
const constants_1 = require("../../constants");
|
|
5
|
-
exports.TestDexConfig = {
|
|
6
|
-
TestDex: {
|
|
7
|
-
// TODO: complete me!
|
|
8
|
-
},
|
|
9
|
-
};
|
|
10
|
-
exports.Adapters = {
|
|
11
|
-
// TODO: add adapters for each chain
|
|
12
|
-
// This is an example to copy
|
|
13
|
-
[constants_1.Network.MAINNET]: { [constants_1.SwapSide.SELL]: [{ name: '', index: 0 }] },
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=config.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/dex/test-dex/config.ts"],"names":[],"mappings":";;;AAEA,+CAAoD;AAEvC,QAAA,aAAa,GAA4B;IACpD,OAAO,EAAE;IACP,qBAAqB;KACtB;CACF,CAAC;AAEW,QAAA,QAAQ,GAAoC;IACvD,oCAAoC;IACpC,6BAA6B;IAC7B,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,oBAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE;CACjE,CAAC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Interface } from '@ethersproject/abi';
|
|
2
|
-
import { DeepReadonly } from 'ts-essentials';
|
|
3
|
-
import { Log, Logger } from '../../types';
|
|
4
|
-
import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
|
|
5
|
-
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
6
|
-
import { PoolState } from './types';
|
|
7
|
-
export declare class TestDexEventPool extends StatefulEventSubscriber<PoolState> {
|
|
8
|
-
protected parentName: string;
|
|
9
|
-
protected network: number;
|
|
10
|
-
protected dexHelper: IDexHelper;
|
|
11
|
-
protected testDexIface: Interface;
|
|
12
|
-
handlers: {
|
|
13
|
-
[event: string]: (event: any, state: DeepReadonly<PoolState>, log: Readonly<Log>) => DeepReadonly<PoolState> | null;
|
|
14
|
-
};
|
|
15
|
-
logDecoder: (log: Log) => any;
|
|
16
|
-
addressesSubscribed: string[];
|
|
17
|
-
constructor(parentName: string, network: number, dexHelper: IDexHelper, logger: Logger, testDexIface?: Interface);
|
|
18
|
-
/**
|
|
19
|
-
* The function is called every time any of the subscribed
|
|
20
|
-
* addresses release log. The function accepts the current
|
|
21
|
-
* state, updates the state according to the log, and returns
|
|
22
|
-
* the updated state.
|
|
23
|
-
* @param state - Current state of event subscriber
|
|
24
|
-
* @param log - Log released by one of the subscribed addresses
|
|
25
|
-
* @returns Updates state of the event subscriber after the log
|
|
26
|
-
*/
|
|
27
|
-
protected processLog(state: DeepReadonly<PoolState>, log: Readonly<Log>): DeepReadonly<PoolState> | null;
|
|
28
|
-
/**
|
|
29
|
-
* The function generates state using on-chain calls. This
|
|
30
|
-
* function is called to regenerate state if the event based
|
|
31
|
-
* system fails to fetch events and the local state is no
|
|
32
|
-
* more correct.
|
|
33
|
-
* @param blockNumber - Blocknumber for which the state should
|
|
34
|
-
* should be generated
|
|
35
|
-
* @returns state of the event subscriber at blocknumber
|
|
36
|
-
*/
|
|
37
|
-
generateState(blockNumber: number): Promise<DeepReadonly<PoolState>>;
|
|
38
|
-
handleMyEvent(event: any, state: DeepReadonly<PoolState>, log: Readonly<Log>): DeepReadonly<PoolState> | null;
|
|
39
|
-
}
|