@paraswap/dex-lib 3.8.31 → 3.8.32

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.
@@ -0,0 +1,221 @@
1
+ import { AsyncOrSync } from 'ts-essentials';
2
+ import {
3
+ Token,
4
+ Address,
5
+ ExchangePrices,
6
+ PoolPrices,
7
+ AdapterExchangeParam,
8
+ SimpleExchangeParam,
9
+ PoolLiquidity,
10
+ Logger,
11
+ NumberAsString,
12
+ DexExchangeParam,
13
+ } from '../../types';
14
+ import { SwapSide, Network } from '../../constants';
15
+ import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
16
+ import { getDexKeysWithNetwork } from '../../utils';
17
+ import { IDex } from '../../dex/idex';
18
+ import { IDexHelper } from '../../dex-helper/idex-helper';
19
+ import { DexParams, PoolState, StkGHOData } from './types';
20
+ import { SimpleExchange } from '../simple-exchange';
21
+ import { StkGHOConfig } from './config';
22
+ import { StkGHOEventPool } from './stkgho-pool';
23
+ import { Interface } from '@ethersproject/abi';
24
+ import StkGHO_ABI from '../../abi/stkGHO.json';
25
+
26
+ export class StkGHO extends SimpleExchange implements IDex<StkGHOData> {
27
+ static readonly stkGHOInterface = new Interface(StkGHO_ABI);
28
+ protected eventPool: StkGHOEventPool;
29
+
30
+ readonly hasConstantPriceLargeAmounts = false;
31
+ readonly needWrapNative = true;
32
+
33
+ protected config: DexParams;
34
+
35
+ readonly isFeeOnTransferSupported = false;
36
+ readonly exchangeRateUnit = 1_000_000_000_000_000_000n;
37
+
38
+ public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
39
+ getDexKeysWithNetwork(StkGHOConfig);
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
+ this.logger = dexHelper.getLogger(dexKey);
50
+ this.eventPool = new StkGHOEventPool(
51
+ dexKey,
52
+ dexKey,
53
+ network,
54
+ dexHelper,
55
+ this.logger,
56
+ );
57
+
58
+ const config = StkGHOConfig[dexKey][network];
59
+ this.config = {
60
+ stkGHO: config.stkGHO.toLowerCase(),
61
+ GHO: config.GHO.toLowerCase(),
62
+ };
63
+ }
64
+
65
+ async initializePricing(blockNumber: number) {
66
+ const state = await this.eventPool.generateState(blockNumber);
67
+
68
+ this.eventPool.initialize(blockNumber, {
69
+ state,
70
+ });
71
+ }
72
+
73
+ getAdapters(side: SwapSide): { name: string; index: number }[] | null {
74
+ return null;
75
+ }
76
+
77
+ async getPoolIdentifiers(
78
+ srcToken: Token,
79
+ destToken: Token,
80
+ side: SwapSide,
81
+ blockNumber: number,
82
+ ): Promise<string[]> {
83
+ const srcTokenAddress = srcToken.address.toLowerCase();
84
+ const destTokenAddress = destToken.address.toLowerCase();
85
+
86
+ if (
87
+ srcTokenAddress === this.config.GHO &&
88
+ destTokenAddress === this.config.stkGHO
89
+ ) {
90
+ return [`${this.dexKey}`];
91
+ } else {
92
+ return [];
93
+ }
94
+ }
95
+
96
+ async getPoolState(blockNumber: number): Promise<PoolState> {
97
+ const eventState = this.eventPool.getState(blockNumber);
98
+ if (eventState) return eventState;
99
+ const onChainState = await this.eventPool.generateState(blockNumber);
100
+ this.eventPool.setState(onChainState, blockNumber);
101
+ return onChainState;
102
+ }
103
+
104
+ async getPricesVolume(
105
+ srcToken: Token,
106
+ destToken: Token,
107
+ amounts: bigint[],
108
+ side: SwapSide,
109
+ blockNumber: number,
110
+ limitPools?: string[],
111
+ ): Promise<null | ExchangePrices<StkGHOData>> {
112
+ if (side === SwapSide.BUY) {
113
+ return null;
114
+ }
115
+
116
+ const srcTokenAddress = srcToken.address.toLowerCase();
117
+ const destTokenAddress = destToken.address.toLowerCase();
118
+
119
+ if (
120
+ srcTokenAddress != this.config.GHO ||
121
+ destTokenAddress != this.config.stkGHO
122
+ ) {
123
+ return null;
124
+ }
125
+
126
+ const state = await this.getPoolState(blockNumber);
127
+
128
+ return [
129
+ {
130
+ unit: state.exchangeRate,
131
+ prices: amounts.map(
132
+ amount => (state.exchangeRate * amount) / this.exchangeRateUnit,
133
+ ),
134
+ data: {
135
+ exchange: this.dexKey,
136
+ },
137
+ poolAddresses: [this.config.stkGHO],
138
+ exchange: this.dexKey,
139
+ gasCost: 100_000,
140
+ poolIdentifier: `${this.dexKey}`,
141
+ },
142
+ ];
143
+ }
144
+
145
+ getCalldataGasCost(poolPrices: PoolPrices<StkGHOData>): number | number[] {
146
+ return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
147
+ }
148
+
149
+ getAdapterParam(
150
+ srcToken: string,
151
+ destToken: string,
152
+ srcAmount: string,
153
+ destAmount: string,
154
+ data: StkGHOData,
155
+ side: SwapSide,
156
+ ): AdapterExchangeParam {
157
+ const { exchange } = data;
158
+
159
+ const payload = '';
160
+
161
+ return {
162
+ targetExchange: exchange,
163
+ payload,
164
+ networkFee: '0',
165
+ };
166
+ }
167
+
168
+ async updatePoolState(): Promise<void> {}
169
+
170
+ async getDexParam(
171
+ srcToken: Address,
172
+ destToken: Address,
173
+ srcAmount: NumberAsString,
174
+ destAmount: NumberAsString,
175
+ recipient: Address,
176
+ data: StkGHOData,
177
+ side: SwapSide,
178
+ ): Promise<DexExchangeParam> {
179
+ const exchangeData = StkGHO.stkGHOInterface.encodeFunctionData('stake', [
180
+ recipient,
181
+ srcAmount,
182
+ ]);
183
+
184
+ return {
185
+ needWrapNative: this.needWrapNative,
186
+ dexFuncHasRecipient: true,
187
+ exchangeData,
188
+ targetExchange: this.config.stkGHO,
189
+ returnAmountPos: undefined,
190
+ };
191
+ }
192
+
193
+ async getTopPoolsForToken(
194
+ tokenAddress: Address,
195
+ limit: number,
196
+ ): Promise<PoolLiquidity[]> {
197
+ tokenAddress = tokenAddress.toLowerCase();
198
+
199
+ if (tokenAddress == this.config.GHO) {
200
+ return [
201
+ {
202
+ exchange: this.dexKey,
203
+ address: this.config.stkGHO,
204
+ connectorTokens: [
205
+ {
206
+ decimals: 18,
207
+ address: this.config.stkGHO,
208
+ },
209
+ ],
210
+ liquidityUSD: 1_000_000_000_000, // GHO to stkGHO supply is unlimited
211
+ },
212
+ ];
213
+ } else {
214
+ return [];
215
+ }
216
+ }
217
+
218
+ // This is optional function in case if your implementation has acquired any resources
219
+ // you need to release for graceful shutdown. For example, it may be any interval timer
220
+ releaseResources(): AsyncOrSync<void> {}
221
+ }
@@ -0,0 +1,14 @@
1
+ import { Address } from '../../types';
2
+
3
+ export type PoolState = {
4
+ exchangeRate: bigint;
5
+ };
6
+
7
+ export type StkGHOData = {
8
+ exchange: Address;
9
+ };
10
+
11
+ export type DexParams = {
12
+ stkGHO: Address;
13
+ GHO: Address;
14
+ };
@@ -455,6 +455,10 @@ export const Tokens: {
455
455
  address: '0x40d16fc0246ad3160ccc09b8d0d3a2cd28ae6c2f',
456
456
  decimals: 18,
457
457
  },
458
+ stkGHO: {
459
+ address: '0x1a88Df1cFe15Af22B3c4c783D4e6F7F9e0C1885d',
460
+ decimals: 18,
461
+ },
458
462
  USDe: {
459
463
  address: '0x4c9EDD5852cd905f086C759E8383e09bff1E68B3',
460
464
  decimals: 18,