@paraswap/dex-lib 3.8.31 → 3.8.32-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.
- package/build/abi/inception/inception-ratio-feed.json +239 -3
- package/build/dex/aave-gsm/aave-gsm-pool.d.ts +3 -0
- package/build/dex/aave-gsm/aave-gsm-pool.js +30 -0
- package/build/dex/aave-gsm/aave-gsm-pool.js.map +1 -1
- package/build/dex/aave-gsm/aave-gsm.d.ts +2 -0
- package/build/dex/aave-gsm/aave-gsm.js +29 -9
- package/build/dex/aave-gsm/aave-gsm.js.map +1 -1
- package/build/dex/aave-gsm/types.d.ts +1 -0
- package/build/dex/inception/config.d.ts +1 -2
- package/build/dex/inception/config.js +1 -4
- package/build/dex/inception/config.js.map +1 -1
- package/build/dex/inception/inception-event-pool.d.ts +4 -13
- package/build/dex/inception/inception-event-pool.js +9 -15
- package/build/dex/inception/inception-event-pool.js.map +1 -1
- package/build/dex/inception/inception.d.ts +6 -7
- package/build/dex/inception/inception.js +36 -17
- package/build/dex/inception/inception.js.map +1 -1
- package/build/dex/inception/tokens.d.ts +1 -1
- package/build/dex/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/stkgho/stkgho-pool.js +1 -1
- package/build/dex/stkgho/stkgho-pool.js.map +1 -1
- package/build/dex/stkgho/stkgho.js +5 -1
- package/build/dex/stkgho/stkgho.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/stkGHO.json +1131 -0
- package/src/dex/aave-gsm/aave-gsm-e2e.test.ts +2 -1
- package/src/dex/aave-gsm/aave-gsm-events.test.ts +3 -0
- package/src/dex/aave-gsm/aave-gsm-pool.ts +47 -0
- package/src/dex/aave-gsm/aave-gsm.ts +36 -10
- package/src/dex/aave-gsm/types.ts +1 -0
- package/src/dex/index.ts +2 -0
- package/src/dex/stkgho/config.ts +14 -0
- package/src/dex/stkgho/stkgho-e2e.test.ts +77 -0
- package/src/dex/stkgho/stkgho-events.test.ts +79 -0
- package/src/dex/stkgho/stkgho-integration.test.ts +226 -0
- package/src/dex/stkgho/stkgho-pool.ts +111 -0
- package/src/dex/stkgho/stkgho.ts +221 -0
- package/src/dex/stkgho/types.ts +14 -0
- package/tests/constants-e2e.ts +4 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { DeepReadonly } from 'ts-essentials';
|
|
3
|
+
import { Log, Logger } from '../../types';
|
|
4
|
+
import { catchParseLogError } from '../../utils';
|
|
5
|
+
import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
|
|
6
|
+
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
7
|
+
import { PoolState } from './types';
|
|
8
|
+
import StkGHO_ABI from '../../abi/stkGHO.json';
|
|
9
|
+
import { StkGHOConfig } from './config';
|
|
10
|
+
import { uint256ToBigInt } from '../../lib/decoders';
|
|
11
|
+
|
|
12
|
+
export class StkGHOEventPool extends StatefulEventSubscriber<PoolState> {
|
|
13
|
+
handlers: {
|
|
14
|
+
[event: string]: (
|
|
15
|
+
event: any,
|
|
16
|
+
state: DeepReadonly<PoolState>,
|
|
17
|
+
log: Readonly<Log>,
|
|
18
|
+
) => DeepReadonly<PoolState> | null;
|
|
19
|
+
} = {};
|
|
20
|
+
|
|
21
|
+
logDecoder: (log: Log) => any;
|
|
22
|
+
|
|
23
|
+
addressesSubscribed: string[];
|
|
24
|
+
|
|
25
|
+
constructor(
|
|
26
|
+
readonly poolName: string,
|
|
27
|
+
readonly parentName: string,
|
|
28
|
+
protected network: number,
|
|
29
|
+
protected dexHelper: IDexHelper,
|
|
30
|
+
logger: Logger,
|
|
31
|
+
protected stkGHOIface = new Interface(StkGHO_ABI),
|
|
32
|
+
) {
|
|
33
|
+
super(parentName, poolName, dexHelper, logger);
|
|
34
|
+
|
|
35
|
+
this.logDecoder = (log: Log) => this.stkGHOIface.parseLog(log);
|
|
36
|
+
this.addressesSubscribed = [StkGHOConfig[parentName][network].stkGHO];
|
|
37
|
+
|
|
38
|
+
this.handlers['ExchangeRateChanged'] =
|
|
39
|
+
this.handleExchangeRateChanged.bind(this);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
getIdentifier(): string {
|
|
43
|
+
return `${this.parentName}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The function is called every time any of the subscribed
|
|
48
|
+
* addresses release log. The function accepts the current
|
|
49
|
+
* state, updates the state according to the log, and returns
|
|
50
|
+
* the updated state.
|
|
51
|
+
* @param state - Current state of event subscriber
|
|
52
|
+
* @param log - Log released by one of the subscribed addresses
|
|
53
|
+
* @returns Updates state of the event subscriber after the log
|
|
54
|
+
*/
|
|
55
|
+
protected processLog(
|
|
56
|
+
state: DeepReadonly<PoolState>,
|
|
57
|
+
log: Readonly<Log>,
|
|
58
|
+
): DeepReadonly<PoolState> | null {
|
|
59
|
+
try {
|
|
60
|
+
const event = this.logDecoder(log);
|
|
61
|
+
if (event.name in this.handlers) {
|
|
62
|
+
return this.handlers[event.name](event, state, log);
|
|
63
|
+
}
|
|
64
|
+
} catch (e) {
|
|
65
|
+
catchParseLogError(e, this.logger);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The function generates state using on-chain calls. This
|
|
73
|
+
* function is called to regenerate state if the event based
|
|
74
|
+
* system fails to fetch events and the local state is no
|
|
75
|
+
* more correct.
|
|
76
|
+
* @param blockNumber - Blocknumber for which the state should
|
|
77
|
+
* should be generated
|
|
78
|
+
* @returns state of the event subscriber at blocknumber
|
|
79
|
+
*/
|
|
80
|
+
async generateState(blockNumber: number): Promise<DeepReadonly<PoolState>> {
|
|
81
|
+
const callData = [
|
|
82
|
+
{
|
|
83
|
+
target: this.addressesSubscribed[0],
|
|
84
|
+
callData: this.stkGHOIface.encodeFunctionData('getExchangeRate', []),
|
|
85
|
+
decodeFunction: uint256ToBigInt,
|
|
86
|
+
},
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
const res = await this.dexHelper.multiWrapper.tryAggregate<bigint>(
|
|
90
|
+
true,
|
|
91
|
+
callData,
|
|
92
|
+
blockNumber,
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const result = {
|
|
96
|
+
exchangeRate: res[0].returnData,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
handleExchangeRateChanged(
|
|
103
|
+
event: any,
|
|
104
|
+
state: DeepReadonly<PoolState>,
|
|
105
|
+
log: Readonly<Log>,
|
|
106
|
+
): DeepReadonly<PoolState> | null {
|
|
107
|
+
return {
|
|
108
|
+
exchangeRate: BigInt(event.args.exchangeRate),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -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
|
+
}
|
package/tests/constants-e2e.ts
CHANGED
|
@@ -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,
|