@paraswap/dex-lib 3.8.25 → 3.8.26-aave-gsm

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.
Files changed (224) hide show
  1. package/build/abi/Aave_GSM.json +751 -0
  2. package/build/abi/{integral/pool.json → inception/inception-ineth-pool.json} +558 -537
  3. package/build/abi/inception/inception-ineth.json +609 -0
  4. package/build/abi/inception/inception-ratio-feed.json +93 -0
  5. package/build/abi/inception/inception-vault.json +991 -0
  6. package/build/dex/aave-gsm/aave-gsm.d.ts +33 -0
  7. package/build/dex/aave-gsm/aave-gsm.js +278 -0
  8. package/build/dex/aave-gsm/aave-gsm.js.map +1 -0
  9. package/build/dex/aave-gsm/config.d.ts +3 -0
  10. package/build/dex/aave-gsm/config.js +17 -0
  11. package/build/dex/aave-gsm/config.js.map +1 -0
  12. package/build/dex/aave-gsm/types.d.ts +11 -0
  13. package/build/dex/aave-gsm/types.js +3 -0
  14. package/build/dex/aave-gsm/types.js.map +1 -0
  15. package/build/dex/aave-v1/aave-v1.d.ts +2 -1
  16. package/build/dex/aave-v1/aave-v1.js +22 -0
  17. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  18. package/build/dex/generic-rfq/rate-fetcher.js +1 -1
  19. package/build/dex/generic-rfq/rate-fetcher.js.map +1 -1
  20. package/build/dex/idle-dao/idle-dao-pool.d.ts +56 -0
  21. package/build/dex/idle-dao/idle-dao-pool.js +176 -0
  22. package/build/dex/idle-dao/idle-dao-pool.js.map +1 -0
  23. package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +16 -0
  24. package/build/dex/idle-dao/idle-dao-pooling-pool.js +57 -0
  25. package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +1 -0
  26. package/build/dex/idle-dao/scripts.d.ts +9 -0
  27. package/build/dex/idle-dao/scripts.js +552 -0
  28. package/build/dex/idle-dao/scripts.js.map +1 -0
  29. package/build/dex/inception/config.d.ts +5 -0
  30. package/build/dex/inception/config.js +112 -0
  31. package/build/dex/inception/config.js.map +1 -0
  32. package/build/dex/inception/inception-event-pool.d.ts +25 -0
  33. package/build/dex/inception/inception-event-pool.js +57 -0
  34. package/build/dex/inception/inception-event-pool.js.map +1 -0
  35. package/build/dex/{integral/integral.d.ts → inception/inception-native.d.ts} +21 -19
  36. package/build/dex/inception/inception-native.js +131 -0
  37. package/build/dex/inception/inception-native.js.map +1 -0
  38. package/build/dex/inception/inception-pool.d.ts +18 -0
  39. package/build/dex/inception/inception-pool.js +32 -0
  40. package/build/dex/inception/inception-pool.js.map +1 -0
  41. package/build/dex/inception/inception-price-feed.d.ts +19 -0
  42. package/build/dex/inception/inception-price-feed.js +51 -0
  43. package/build/dex/inception/inception-price-feed.js.map +1 -0
  44. package/build/dex/inception/inception.d.ts +44 -0
  45. package/build/dex/inception/inception.js +177 -0
  46. package/build/dex/inception/inception.js.map +1 -0
  47. package/build/dex/inception/tokens.d.ts +9 -0
  48. package/build/dex/inception/tokens.js +28 -0
  49. package/build/dex/inception/tokens.js.map +1 -0
  50. package/build/dex/inception/types.d.ts +22 -0
  51. package/build/dex/inception/types.js +3 -0
  52. package/build/dex/inception/types.js.map +1 -0
  53. package/build/dex/inception/utils.d.ts +7 -0
  54. package/build/dex/inception/utils.js +58 -0
  55. package/build/dex/inception/utils.js.map +1 -0
  56. package/build/dex/index.js +2 -0
  57. package/build/dex/index.js.map +1 -1
  58. package/build/dex/platypus/platypus.d.ts +2 -1
  59. package/build/dex/platypus/platypus.js +31 -0
  60. package/build/dex/platypus/platypus.js.map +1 -1
  61. package/build/dex/swaap-v1/swaap-v1.d.ts +2 -1
  62. package/build/dex/swaap-v1/swaap-v1.js +10 -0
  63. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  64. package/package.json +1 -1
  65. package/src/abi/Aave_GSM.json +751 -0
  66. package/src/dex/aave-gsm/aave-gsm-e2e.test.ts +109 -0
  67. package/src/dex/aave-gsm/aave-gsm-integration.test.ts +318 -0
  68. package/src/dex/aave-gsm/aave-gsm.ts +359 -0
  69. package/src/dex/aave-gsm/config.ts +16 -0
  70. package/src/dex/aave-gsm/types.ts +15 -0
  71. package/src/dex/generic-rfq/rate-fetcher.ts +6 -5
  72. package/src/dex/index.ts +2 -0
  73. package/.vscode/launch.json +0 -16
  74. package/.vscode/settings.json +0 -3
  75. package/build/abi/Uncompressor.json +0 -250
  76. package/build/abi/integral/factory.json +0 -333
  77. package/build/abi/integral/oracle.json +0 -501
  78. package/build/abi/integral/relayer.json +0 -1536
  79. package/build/dex/bProtocol.d.ts +0 -18
  80. package/build/dex/bProtocol.js +0 -39
  81. package/build/dex/bProtocol.js.map +0 -1
  82. package/build/dex/bancor.d.ts +0 -26
  83. package/build/dex/bancor.js +0 -58
  84. package/build/dex/bancor.js.map +0 -1
  85. package/build/dex/compound.d.ts +0 -18
  86. package/build/dex/compound.js +0 -46
  87. package/build/dex/compound.js.map +0 -1
  88. package/build/dex/curve-v2.d.ts +0 -58
  89. package/build/dex/curve-v2.js +0 -180
  90. package/build/dex/curve-v2.js.map +0 -1
  91. package/build/dex/dodo-v1.d.ts +0 -33
  92. package/build/dex/dodo-v1.js +0 -63
  93. package/build/dex/dodo-v1.js.map +0 -1
  94. package/build/dex/etherfi/etherfi.d.ts +0 -26
  95. package/build/dex/etherfi/etherfi.js +0 -96
  96. package/build/dex/etherfi/etherfi.js.map +0 -1
  97. package/build/dex/integral/config.d.ts +0 -4
  98. package/build/dex/integral/config.js +0 -20
  99. package/build/dex/integral/config.js.map +0 -1
  100. package/build/dex/integral/context.d.ts +0 -40
  101. package/build/dex/integral/context.js +0 -158
  102. package/build/dex/integral/context.js.map +0 -1
  103. package/build/dex/integral/helpers.d.ts +0 -17
  104. package/build/dex/integral/helpers.js +0 -157
  105. package/build/dex/integral/helpers.js.map +0 -1
  106. package/build/dex/integral/integral-factory.d.ts +0 -24
  107. package/build/dex/integral/integral-factory.js +0 -95
  108. package/build/dex/integral/integral-factory.js.map +0 -1
  109. package/build/dex/integral/integral-pool.d.ts +0 -50
  110. package/build/dex/integral/integral-pool.js +0 -149
  111. package/build/dex/integral/integral-pool.js.map +0 -1
  112. package/build/dex/integral/integral-pricing.d.ts +0 -18
  113. package/build/dex/integral/integral-pricing.js +0 -114
  114. package/build/dex/integral/integral-pricing.js.map +0 -1
  115. package/build/dex/integral/integral-relayer.d.ts +0 -42
  116. package/build/dex/integral/integral-relayer.js +0 -192
  117. package/build/dex/integral/integral-relayer.js.map +0 -1
  118. package/build/dex/integral/integral-token.d.ts +0 -27
  119. package/build/dex/integral/integral-token.js +0 -59
  120. package/build/dex/integral/integral-token.js.map +0 -1
  121. package/build/dex/integral/integral.js +0 -376
  122. package/build/dex/integral/integral.js.map +0 -1
  123. package/build/dex/integral/types.d.ts +0 -85
  124. package/build/dex/integral/types.js +0 -9
  125. package/build/dex/integral/types.js.map +0 -1
  126. package/build/dex/integral/utils-e2e.d.ts +0 -9
  127. package/build/dex/integral/utils-e2e.js +0 -131
  128. package/build/dex/integral/utils-e2e.js.map +0 -1
  129. package/build/dex/integral/utils.d.ts +0 -17
  130. package/build/dex/integral/utils.js +0 -94
  131. package/build/dex/integral/utils.js.map +0 -1
  132. package/build/dex/lido.d.ts +0 -19
  133. package/build/dex/lido.js +0 -42
  134. package/build/dex/lido.js.map +0 -1
  135. package/build/dex/onebit.d.ts +0 -25
  136. package/build/dex/onebit.js +0 -42
  137. package/build/dex/onebit.js.map +0 -1
  138. package/build/dex/sdai/config.d.ts +0 -11
  139. package/build/dex/sdai/config.js +0 -21
  140. package/build/dex/sdai/config.js.map +0 -1
  141. package/build/dex/sdai/constants.d.ts +0 -2
  142. package/build/dex/sdai/constants.js +0 -6
  143. package/build/dex/sdai/constants.js.map +0 -1
  144. package/build/dex/sdai/scripts/validate-state.d.ts +0 -1
  145. package/build/dex/sdai/scripts/validate-state.js +0 -102
  146. package/build/dex/sdai/scripts/validate-state.js.map +0 -1
  147. package/build/dex/sdai/sdai-pool.d.ts +0 -16
  148. package/build/dex/sdai/sdai-pool.js +0 -85
  149. package/build/dex/sdai/sdai-pool.js.map +0 -1
  150. package/build/dex/sdai/sdai.d.ts +0 -51
  151. package/build/dex/sdai/sdai.js +0 -172
  152. package/build/dex/sdai/sdai.js.map +0 -1
  153. package/build/dex/sdai/types.d.ts +0 -21
  154. package/build/dex/sdai/types.js +0 -11
  155. package/build/dex/sdai/types.js.map +0 -1
  156. package/build/dex/sdai/utils.d.ts +0 -4
  157. package/build/dex/sdai/utils.js +0 -39
  158. package/build/dex/sdai/utils.js.map +0 -1
  159. package/build/dex/smoothy.d.ts +0 -26
  160. package/build/dex/smoothy.js +0 -48
  161. package/build/dex/smoothy.js.map +0 -1
  162. package/build/dex/stable-pool.d.ts +0 -28
  163. package/build/dex/stable-pool.js +0 -62
  164. package/build/dex/stable-pool.js.map +0 -1
  165. package/build/dex/trader-joe-v2.1/optimizer.d.ts +0 -2
  166. package/build/dex/trader-joe-v2.1/optimizer.js +0 -44
  167. package/build/dex/trader-joe-v2.1/optimizer.js.map +0 -1
  168. package/build/dex/trader-joe-v2.1.d.ts +0 -43
  169. package/build/dex/trader-joe-v2.1.js +0 -79
  170. package/build/dex/trader-joe-v2.1.js.map +0 -1
  171. package/build/executor/compressor/Compressor.d.ts +0 -23
  172. package/build/executor/compressor/Compressor.js +0 -144
  173. package/build/executor/compressor/Compressor.js.map +0 -1
  174. package/build/executor/compressor/compress.d.ts +0 -17
  175. package/build/executor/compressor/compress.js +0 -187
  176. package/build/executor/compressor/compress.js.map +0 -1
  177. package/build/executor/compressor/compress_functions/addressSubstitution.d.ts +0 -6
  178. package/build/executor/compressor/compress_functions/addressSubstitution.js +0 -29
  179. package/build/executor/compressor/compress_functions/addressSubstitution.js.map +0 -1
  180. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.d.ts +0 -10
  181. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js +0 -40
  182. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js.map +0 -1
  183. package/build/executor/compressor/compress_functions/byteSubstitution.d.ts +0 -11
  184. package/build/executor/compressor/compress_functions/byteSubstitution.js +0 -64
  185. package/build/executor/compressor/compress_functions/byteSubstitution.js.map +0 -1
  186. package/build/executor/compressor/compress_functions/ffSubstitution.d.ts +0 -7
  187. package/build/executor/compressor/compress_functions/ffSubstitution.js +0 -54
  188. package/build/executor/compressor/compress_functions/ffSubstitution.js.map +0 -1
  189. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.d.ts +0 -8
  190. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js +0 -67
  191. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js.map +0 -1
  192. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.d.ts +0 -8
  193. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js +0 -61
  194. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js.map +0 -1
  195. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.d.ts +0 -6
  196. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js +0 -37
  197. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js.map +0 -1
  198. package/build/executor/compressor/compress_functions/searchUnusedBytes.d.ts +0 -9
  199. package/build/executor/compressor/compress_functions/searchUnusedBytes.js +0 -33
  200. package/build/executor/compressor/compress_functions/searchUnusedBytes.js.map +0 -1
  201. package/build/executor/compressor/fetchSaved.d.ts +0 -0
  202. package/build/executor/compressor/fetchSaved.js +0 -17
  203. package/build/executor/compressor/fetchSaved.js.map +0 -1
  204. package/build/executor/compressor/utils/computeCostL2.d.ts +0 -2
  205. package/build/executor/compressor/utils/computeCostL2.js +0 -14
  206. package/build/executor/compressor/utils/computeCostL2.js.map +0 -1
  207. package/build/executor/compressor/utils/findLongestDuplicatedString.d.ts +0 -2
  208. package/build/executor/compressor/utils/findLongestDuplicatedString.js +0 -30
  209. package/build/executor/compressor/utils/findLongestDuplicatedString.js.map +0 -1
  210. package/build/executor/compressor/utils/getAllIndexes.d.ts +0 -2
  211. package/build/executor/compressor/utils/getAllIndexes.js +0 -12
  212. package/build/executor/compressor/utils/getAllIndexes.js.map +0 -1
  213. package/build/executor/compressor/utils/getByteForAddress.d.ts +0 -2
  214. package/build/executor/compressor/utils/getByteForAddress.js +0 -14
  215. package/build/executor/compressor/utils/getByteForAddress.js.map +0 -1
  216. package/build/executor/compressor/utils/intTo2Bytes.d.ts +0 -2
  217. package/build/executor/compressor/utils/intTo2Bytes.js +0 -14
  218. package/build/executor/compressor/utils/intTo2Bytes.js.map +0 -1
  219. package/build/executor/compressor/utils/intTo3Bytes.d.ts +0 -2
  220. package/build/executor/compressor/utils/intTo3Bytes.js +0 -18
  221. package/build/executor/compressor/utils/intTo3Bytes.js.map +0 -1
  222. package/build/executor/compressor/utils/intToByte.d.ts +0 -2
  223. package/build/executor/compressor/utils/intToByte.js +0 -10
  224. package/build/executor/compressor/utils/intToByte.js.map +0 -1
@@ -0,0 +1,359 @@
1
+ import {
2
+ Token,
3
+ Address,
4
+ ExchangePrices,
5
+ PoolPrices,
6
+ AdapterExchangeParam,
7
+ PoolLiquidity,
8
+ Logger,
9
+ NumberAsString,
10
+ DexExchangeParam,
11
+ } from '../../types';
12
+ import { SwapSide, Network } from '../../constants';
13
+ import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
14
+ import { getDexKeysWithNetwork } from '../../utils';
15
+ import { IDex } from '../../dex/idex';
16
+ import { IDexHelper } from '../../dex-helper/idex-helper';
17
+ import { AaveGsmData, DexParams } from './types';
18
+ import { SimpleExchange } from '../simple-exchange';
19
+ import { AaveGsmConfig } from './config';
20
+
21
+ import GSM_ABI from '../../abi/Aave_GSM.json';
22
+ import { Interface } from '@ethersproject/abi';
23
+ import { MultiResult } from '../../lib/multi-wrapper';
24
+ import { BytesLike } from 'ethers';
25
+ import { generalDecoder } from '../../lib/decoders';
26
+ import { parseUnits } from 'ethers/lib/utils';
27
+
28
+ export class AaveGsm extends SimpleExchange implements IDex<AaveGsmData> {
29
+ static readonly gsmInterface = new Interface(GSM_ABI);
30
+
31
+ protected config: DexParams;
32
+
33
+ readonly hasConstantPriceLargeAmounts = false;
34
+ readonly needWrapNative = false;
35
+
36
+ readonly isFeeOnTransferSupported = false;
37
+
38
+ public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
39
+ getDexKeysWithNetwork(AaveGsmConfig);
40
+
41
+ logger: Logger;
42
+
43
+ constructor(
44
+ readonly network: Network,
45
+ readonly dexKey: string,
46
+ readonly dexHelper: IDexHelper,
47
+ ) {
48
+ super(dexHelper, dexKey);
49
+ const config = AaveGsmConfig[dexKey][network];
50
+ this.config = {
51
+ GSM_USDT: config.GSM_USDT.toLowerCase(),
52
+ GSM_USDC: config.GSM_USDC.toLowerCase(),
53
+ USDT: config.USDT.toLowerCase(),
54
+ USDC: config.USDC.toLowerCase(),
55
+ GHO: config.GHO.toLowerCase(),
56
+ };
57
+
58
+ this.logger = dexHelper.getLogger(dexKey);
59
+ }
60
+
61
+ getAdapters(side: SwapSide): { name: string; index: number }[] | null {
62
+ return null;
63
+ }
64
+
65
+ async getPoolIdentifiers(
66
+ srcToken: Token,
67
+ destToken: Token,
68
+ side: SwapSide,
69
+ blockNumber: number,
70
+ ): Promise<string[]> {
71
+ const srcTokenAddress = srcToken.address.toLowerCase();
72
+ const destTokenAddress = destToken.address.toLowerCase();
73
+
74
+ if (
75
+ (srcTokenAddress === this.config.GHO &&
76
+ destTokenAddress === this.config.USDT) ||
77
+ (srcTokenAddress === this.config.USDT &&
78
+ destTokenAddress === this.config.GHO)
79
+ ) {
80
+ return [`${this.dexKey}_${this.config.GSM_USDT}`];
81
+ } else if (
82
+ (srcTokenAddress === this.config.GHO &&
83
+ destTokenAddress === this.config.USDC) ||
84
+ (srcTokenAddress === this.config.USDC &&
85
+ destTokenAddress === this.config.GHO)
86
+ ) {
87
+ return [`${this.dexKey}_${this.config.GSM_USDC}`];
88
+ } else {
89
+ return [];
90
+ }
91
+ }
92
+
93
+ // Returns pool prices for amounts.
94
+ // If limitPools is defined only pools in limitPools
95
+ // should be used. If limitPools is undefined then
96
+ // any pools can be used.
97
+ async getPricesVolume(
98
+ srcToken: Token,
99
+ destToken: Token,
100
+ amounts: bigint[],
101
+ side: SwapSide,
102
+ blockNumber: number,
103
+ limitPools?: string[],
104
+ ): Promise<null | ExchangePrices<AaveGsmData>> {
105
+ const srcTokenAddress = srcToken.address.toLowerCase();
106
+ const destTokenAddress = destToken.address.toLowerCase();
107
+
108
+ if (
109
+ !(
110
+ (srcTokenAddress == this.config.GHO &&
111
+ (destTokenAddress == this.config.USDC ||
112
+ destTokenAddress == this.config.USDT)) ||
113
+ (destTokenAddress == this.config.GHO &&
114
+ (srcTokenAddress == this.config.USDC ||
115
+ srcTokenAddress == this.config.USDT))
116
+ )
117
+ ) {
118
+ return null;
119
+ }
120
+
121
+ let endpoint: string;
122
+ let target: string;
123
+ let resultIsGho: boolean;
124
+ if (srcTokenAddress == this.config.GHO && side == SwapSide.BUY) {
125
+ endpoint = 'getGhoAmountForBuyAsset';
126
+ resultIsGho = true;
127
+ } else if (srcTokenAddress == this.config.GHO && side == SwapSide.SELL) {
128
+ endpoint = 'getAssetAmountForBuyAsset';
129
+ resultIsGho = false;
130
+ } else if (destTokenAddress == this.config.GHO && side == SwapSide.SELL) {
131
+ endpoint = 'getGhoAmountForSellAsset';
132
+ resultIsGho = true;
133
+ } else {
134
+ endpoint = 'getAssetAmountForSellAsset';
135
+ resultIsGho = false;
136
+ }
137
+
138
+ if (
139
+ srcTokenAddress == this.config.USDT ||
140
+ destTokenAddress == this.config.USDT
141
+ ) {
142
+ target = this.config.GSM_USDT;
143
+ } else {
144
+ target = this.config.GSM_USDC;
145
+ }
146
+
147
+ const unit = parseUnits(
148
+ '1',
149
+ side == SwapSide.SELL ? srcToken.decimals : destToken.decimals,
150
+ ).toBigInt();
151
+
152
+ const amountsWithUnit = [...amounts, unit];
153
+
154
+ const calls = amountsWithUnit.map(amount => ({
155
+ target,
156
+ callData: AaveGsm.gsmInterface.encodeFunctionData(endpoint, [amount]),
157
+ decodeFunction: (
158
+ result: MultiResult<BytesLike> | BytesLike,
159
+ ): { underlying: bigint; gho: bigint } => {
160
+ return generalDecoder(
161
+ result,
162
+ ['uint256', 'uint256', 'uint256', 'uint256'],
163
+ {
164
+ underlying: 0n,
165
+ gho: 0n,
166
+ },
167
+ value => ({
168
+ underlying: value[0].toBigInt(),
169
+ gho: value[1].toBigInt(),
170
+ }),
171
+ );
172
+ },
173
+ }));
174
+
175
+ let results = await this.dexHelper.multiWrapper.tryAggregate<{
176
+ underlying: bigint;
177
+ gho: bigint;
178
+ }>(true, calls, blockNumber);
179
+
180
+ const unitPriceResult = results.pop()!;
181
+
182
+ return [
183
+ {
184
+ unit: resultIsGho
185
+ ? unitPriceResult.returnData.gho
186
+ : unitPriceResult.returnData.underlying,
187
+ prices: results.map(result =>
188
+ resultIsGho ? result.returnData.gho : result.returnData.underlying,
189
+ ),
190
+ data: {
191
+ exchange: this.dexKey,
192
+ },
193
+ poolAddresses: [target],
194
+ exchange: this.dexKey,
195
+ gasCost: endpoint.indexOf('BuyAsset') > 0 ? 80000 : 74000,
196
+ poolIdentifier: `${this.dexKey}_${target}`,
197
+ },
198
+ ];
199
+ }
200
+
201
+ // Returns estimated gas cost of calldata for this DEX in multiSwap
202
+ getCalldataGasCost(poolPrices: PoolPrices<AaveGsmData>): number | number[] {
203
+ return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
204
+ }
205
+
206
+ getAdapterParam(
207
+ srcToken: string,
208
+ destToken: string,
209
+ srcAmount: string,
210
+ destAmount: string,
211
+ data: AaveGsmData,
212
+ side: SwapSide,
213
+ ): AdapterExchangeParam {
214
+ const { exchange } = data;
215
+
216
+ const payload = '';
217
+
218
+ return {
219
+ targetExchange: exchange,
220
+ payload,
221
+ networkFee: '0',
222
+ };
223
+ }
224
+
225
+ async getDexParam(
226
+ srcToken: Address,
227
+ destToken: Address,
228
+ srcAmount: NumberAsString,
229
+ destAmount: NumberAsString,
230
+ recipient: Address,
231
+ data: AaveGsmData,
232
+ side: SwapSide,
233
+ ): Promise<DexExchangeParam> {
234
+ const isSrcGho = srcToken.toLowerCase() === this.config.GHO;
235
+ const swapFunction = isSrcGho ? 'buyAsset' : 'sellAsset';
236
+ const ghoAmount = isSrcGho ? srcAmount : destAmount;
237
+ let assetAmount = isSrcGho ? destAmount : srcAmount;
238
+ const targetExchange =
239
+ srcToken.toLowerCase() === this.config.USDT ||
240
+ destToken.toLowerCase() === this.config.USDT
241
+ ? this.config.GSM_USDT
242
+ : this.config.GSM_USDC;
243
+
244
+ if (BigInt(assetAmount) == 1n) {
245
+ const endpoint = isSrcGho
246
+ ? 'getAssetAmountForBuyAsset'
247
+ : 'getAssetAmountForSellAsset';
248
+
249
+ const calldata = {
250
+ target: targetExchange,
251
+ callData: AaveGsm.gsmInterface.encodeFunctionData(endpoint, [
252
+ ghoAmount,
253
+ ]),
254
+ decodeFunction: (
255
+ result: MultiResult<BytesLike> | BytesLike,
256
+ ): { underlying: bigint; gho: bigint } => {
257
+ return generalDecoder(
258
+ result,
259
+ ['uint256', 'uint256', 'uint256', 'uint256'],
260
+ {
261
+ underlying: 0n,
262
+ gho: 0n,
263
+ },
264
+ value => ({
265
+ underlying: value[0].toBigInt(),
266
+ gho: value[1].toBigInt(),
267
+ }),
268
+ );
269
+ },
270
+ };
271
+
272
+ const result = await this.dexHelper.multiWrapper.tryAggregate<{
273
+ underlying: bigint;
274
+ gho: bigint;
275
+ }>(true, [calldata]);
276
+
277
+ assetAmount = result[0].returnData.underlying.toString();
278
+ }
279
+
280
+ const exchangeData = AaveGsm.gsmInterface.encodeFunctionData(swapFunction, [
281
+ assetAmount,
282
+ recipient,
283
+ ]);
284
+
285
+ return {
286
+ needWrapNative: this.needWrapNative,
287
+ dexFuncHasRecipient: true,
288
+ exchangeData,
289
+ targetExchange,
290
+ returnAmountPos: isSrcGho ? 1 : 0,
291
+ };
292
+ }
293
+
294
+ // Returns list of top pools based on liquidity. Max
295
+ // limit number pools should be returned.
296
+ async getTopPoolsForToken(
297
+ tokenAddress: Address,
298
+ limit: number,
299
+ ): Promise<PoolLiquidity[]> {
300
+ tokenAddress = tokenAddress.toLowerCase();
301
+
302
+ if (tokenAddress == this.config.GHO) {
303
+ return [
304
+ {
305
+ exchange: this.dexKey,
306
+ address: this.config.GSM_USDC,
307
+ connectorTokens: [
308
+ {
309
+ decimals: 6,
310
+ address: this.config.USDC,
311
+ },
312
+ ],
313
+ liquidityUSD: 1000000000, // Just returning a big number so this DEX will be preferred
314
+ },
315
+ {
316
+ exchange: this.dexKey,
317
+ address: this.config.GSM_USDT,
318
+ connectorTokens: [
319
+ {
320
+ decimals: 6,
321
+ address: this.config.USDT,
322
+ },
323
+ ],
324
+ liquidityUSD: 1000000000, // Just returning a big number so this DEX will be preferred
325
+ },
326
+ ];
327
+ } else if (tokenAddress == this.config.USDC) {
328
+ return [
329
+ {
330
+ exchange: this.dexKey,
331
+ address: this.config.GSM_USDC,
332
+ connectorTokens: [
333
+ {
334
+ decimals: 18,
335
+ address: this.config.GHO,
336
+ },
337
+ ],
338
+ liquidityUSD: 1000000000, // Just returning a big number so this DEX will be preferred
339
+ },
340
+ ];
341
+ } else if (tokenAddress == this.config.USDT) {
342
+ return [
343
+ {
344
+ exchange: this.dexKey,
345
+ address: this.config.GSM_USDT,
346
+ connectorTokens: [
347
+ {
348
+ decimals: 18,
349
+ address: this.config.GHO,
350
+ },
351
+ ],
352
+ liquidityUSD: 1000000000, // Just returning a big number so this DEX will be preferred
353
+ },
354
+ ];
355
+ } else {
356
+ return [];
357
+ }
358
+ }
359
+ }
@@ -0,0 +1,16 @@
1
+ import { DexParams } from './types';
2
+ import { DexConfigMap, AdapterMappings } from '../../types';
3
+ import { Network, SwapSide } from '../../constants';
4
+ import { AaveV3Ethereum, MiscEthereum } from '@bgd-labs/aave-address-book';
5
+
6
+ export const AaveGsmConfig: DexConfigMap<DexParams> = {
7
+ AaveGsm: {
8
+ [Network.MAINNET]: {
9
+ GSM_USDT: MiscEthereum.GSM_USDT,
10
+ GSM_USDC: MiscEthereum.GSM_USDC,
11
+ USDT: AaveV3Ethereum.ASSETS.USDT.UNDERLYING,
12
+ USDC: AaveV3Ethereum.ASSETS.USDC.UNDERLYING,
13
+ GHO: AaveV3Ethereum.ASSETS.GHO.UNDERLYING,
14
+ },
15
+ },
16
+ };
@@ -0,0 +1,15 @@
1
+ import { Address } from '../../types';
2
+
3
+ export type AaveGsmData = {
4
+ // returned by the API that can be used for
5
+ // tx building. The data structure should be minimal.
6
+ exchange: Address;
7
+ };
8
+
9
+ export type DexParams = {
10
+ GSM_USDT: string;
11
+ GSM_USDC: string;
12
+ USDT: string;
13
+ USDC: string;
14
+ GHO: string;
15
+ };
@@ -1,5 +1,5 @@
1
1
  import BigNumber from 'bignumber.js';
2
- import { isEmpty } from 'lodash';
2
+ import { isEmpty, omit } from 'lodash';
3
3
  import { SwapSide } from '@paraswap/core';
4
4
  import { BN_1 } from '../../bignumber-constants';
5
5
  import { IDexHelper } from '../../dex-helper';
@@ -433,14 +433,15 @@ export class RateFetcher {
433
433
  timeout: GET_FIRM_RATE_TIMEOUT_MS,
434
434
  };
435
435
 
436
+ this.logger.info(
437
+ 'FirmRate Request:',
438
+ JSON.stringify(omit(payload, 'secret')).replace(/(?:\r\n|\r|\n)/g, ' '),
439
+ );
440
+
436
441
  if (this.firmRateAuth) {
437
442
  this.firmRateAuth(payload);
438
443
  delete payload.secret;
439
444
  }
440
- this.logger.info(
441
- 'FirmRate Request:',
442
- JSON.stringify(payload).replace(/(?:\r\n|\r|\n)/g, ' '),
443
- );
444
445
  const { data } = await this.dexHelper.httpRequest.request<unknown>(
445
446
  payload,
446
447
  );
package/src/dex/index.ts CHANGED
@@ -86,6 +86,7 @@ import { AaveV3Stata } from './aave-v3-stata/aave-v3-stata';
86
86
  import { OSwap } from './oswap/oswap';
87
87
  import { ConcentratorArusd } from './concentrator-arusd/concentrator-arusd';
88
88
  import { FxProtocolRusd } from './fx-protocol-rusd/fx-protocol-rusd';
89
+ import { AaveGsm } from './aave-gsm/aave-gsm';
89
90
  import { LitePsm } from './lite-psm/lite-psm';
90
91
 
91
92
  const LegacyDexes = [
@@ -168,6 +169,7 @@ const Dexes = [
168
169
  OSwap,
169
170
  ConcentratorArusd,
170
171
  FxProtocolRusd,
172
+ AaveGsm,
171
173
  LitePsm,
172
174
  ];
173
175
 
@@ -1,16 +0,0 @@
1
- {
2
- "version": "0.2.0",
3
- "configurations": [
4
- {
5
- "args": [
6
- "${workspaceFolder}/src/dex/maverick-v2/maverick-v2-integration.test.ts"
7
- ],
8
- "internalConsoleOptions": "openOnSessionStart",
9
- "name": "Dex-lib",
10
- "program": "${workspaceFolder}/node_modules/jest/bin/jest",
11
- "request": "launch",
12
- "skipFiles": ["<node_internals>/**"],
13
- "type": "node"
14
- }
15
- ]
16
- }
@@ -1,3 +0,0 @@
1
- {
2
- "typescript.tsdk": "node_modules/typescript/lib"
3
- }