@paraswap/dex-lib 3.8.36 → 3.8.38
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/cables/CablesMainnetRFQ.json +1073 -0
- package/build/abi/sdai/SavingsUSDS.abi.json +720 -0
- package/build/dex/cables/cables.d.ts +64 -0
- package/build/dex/cables/cables.js +445 -0
- package/build/dex/cables/cables.js.map +1 -0
- package/build/dex/cables/config.d.ts +4 -0
- package/build/dex/cables/config.js +15 -0
- package/build/dex/cables/config.js.map +1 -0
- package/build/dex/cables/constants.d.ts +19 -0
- package/build/dex/cables/constants.js +26 -0
- package/build/dex/cables/constants.js.map +1 -0
- package/build/dex/cables/rate-fetcher.d.ts +34 -0
- package/build/dex/cables/rate-fetcher.js +117 -0
- package/build/dex/cables/rate-fetcher.js.map +1 -0
- package/build/dex/cables/types.d.ts +106 -0
- package/build/dex/cables/types.js +12 -0
- package/build/dex/cables/types.js.map +1 -0
- package/build/dex/cables/validators.d.ts +5 -0
- package/build/dex/cables/validators.js +49 -0
- package/build/dex/cables/validators.js.map +1 -0
- package/build/dex/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/spark/config.js +25 -0
- package/build/dex/spark/config.js.map +1 -1
- package/build/dex/spark/scripts/validate-state.js +1 -1
- package/build/dex/spark/scripts/validate-state.js.map +1 -1
- package/build/dex/spark/spark-sdai-pool.d.ts +7 -3
- package/build/dex/spark/spark-sdai-pool.js +24 -28
- package/build/dex/spark/spark-sdai-pool.js.map +1 -1
- package/build/dex/spark/spark.d.ts +10 -5
- package/build/dex/spark/spark.js +46 -31
- package/build/dex/spark/spark.js.map +1 -1
- package/build/dex/spark/types.d.ts +6 -0
- package/build/dex/spark/types.js.map +1 -1
- package/build/dex/spark/utils.d.ts +3 -1
- package/build/dex/spark/utils.js +43 -7
- package/build/dex/spark/utils.js.map +1 -1
- package/build/dex/usual-bond/usual-bond.js +7 -9
- package/build/dex/usual-bond/usual-bond.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/sdai/SavingsUSDS.abi.json +720 -0
- package/src/abi/usual-bond/usd0pp.abi.json +867 -0
- package/src/dex/index.ts +2 -0
- package/src/dex/spark/config.ts +24 -0
- package/src/dex/spark/scripts/validate-state.ts +1 -0
- package/src/dex/spark/spark-e2e.test.ts +25 -21
- package/src/dex/spark/spark-events.test.ts +77 -62
- package/src/dex/spark/spark-integration.test.ts +290 -7
- package/src/dex/spark/spark-sdai-pool.ts +22 -19
- package/src/dex/spark/spark.ts +62 -36
- package/src/dex/spark/types.ts +6 -0
- package/src/dex/spark/utils.ts +83 -19
- package/src/dex/usual-bond/config.ts +12 -0
- package/src/dex/usual-bond/types.ts +10 -0
- package/src/dex/usual-bond/usual-bond-e2e.test.ts +80 -0
- package/src/dex/usual-bond/usual-bond-integration.test.ts +144 -0
- package/src/dex/usual-bond/usual-bond.ts +208 -0
- package/tests/constants-e2e.ts +17 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Token,
|
|
3
|
+
Address,
|
|
4
|
+
ExchangePrices,
|
|
5
|
+
PoolPrices,
|
|
6
|
+
AdapterExchangeParam,
|
|
7
|
+
Logger,
|
|
8
|
+
NumberAsString,
|
|
9
|
+
DexExchangeParam,
|
|
10
|
+
PoolLiquidity,
|
|
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 '../idex';
|
|
16
|
+
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
17
|
+
import { UsualBondData, DexParams } from './types';
|
|
18
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
19
|
+
import { UsualBondConfig } from './config';
|
|
20
|
+
import { Interface, JsonFragment } from '@ethersproject/abi';
|
|
21
|
+
import USD0PP_ABI from '../../abi/usual-bond/usd0pp.abi.json';
|
|
22
|
+
import { BI_POWS } from '../../bigint-constants';
|
|
23
|
+
|
|
24
|
+
export class UsualBond extends SimpleExchange implements IDex<UsualBondData> {
|
|
25
|
+
protected config: DexParams;
|
|
26
|
+
|
|
27
|
+
readonly hasConstantPriceLargeAmounts = true;
|
|
28
|
+
readonly needWrapNative = false;
|
|
29
|
+
readonly isFeeOnTransferSupported = false;
|
|
30
|
+
|
|
31
|
+
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
|
|
32
|
+
getDexKeysWithNetwork(UsualBondConfig);
|
|
33
|
+
|
|
34
|
+
usd0ppIface: Interface;
|
|
35
|
+
logger: Logger;
|
|
36
|
+
|
|
37
|
+
constructor(
|
|
38
|
+
readonly network: Network,
|
|
39
|
+
readonly dexKey: string,
|
|
40
|
+
readonly dexHelper: IDexHelper,
|
|
41
|
+
) {
|
|
42
|
+
super(dexHelper, dexKey);
|
|
43
|
+
const config = UsualBondConfig[dexKey][network];
|
|
44
|
+
this.usd0ppIface = new Interface(USD0PP_ABI as JsonFragment[]);
|
|
45
|
+
this.config = {
|
|
46
|
+
usd0Address: config.usd0Address.toLowerCase(),
|
|
47
|
+
usd0ppAddress: config.usd0ppAddress.toLowerCase(),
|
|
48
|
+
};
|
|
49
|
+
this.logger = dexHelper.getLogger(dexKey);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async initializePricing(blockNumber: number) {
|
|
53
|
+
// No initialization needed for constant price
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getConfig() {
|
|
57
|
+
return this.config;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
is_usd0(token: string) {
|
|
61
|
+
return token.toLowerCase() === this.config.usd0Address.toLowerCase();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
is_usd0pp(token: string) {
|
|
65
|
+
return token.toLowerCase() === this.config.usd0ppAddress.toLowerCase();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
is_usd0_swap_token(srcToken: string, destToken: string) {
|
|
69
|
+
return this.is_usd0(srcToken) && this.is_usd0pp(destToken);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getAdapters() {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async getPoolIdentifiers(
|
|
77
|
+
srcToken: Token,
|
|
78
|
+
destToken: Token,
|
|
79
|
+
side: SwapSide,
|
|
80
|
+
blockNumber: number,
|
|
81
|
+
): Promise<string[]> {
|
|
82
|
+
if (!srcToken || !destToken) {
|
|
83
|
+
this.logger.error('Source or destination token is undefined');
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const srcTokenAddress = srcToken.address?.toLowerCase();
|
|
88
|
+
const destTokenAddress = destToken.address?.toLowerCase();
|
|
89
|
+
|
|
90
|
+
if (!srcTokenAddress || !destTokenAddress) {
|
|
91
|
+
this.logger.error('Source or destination token address is undefined');
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (this.is_usd0_swap_token(srcTokenAddress, destTokenAddress)) {
|
|
96
|
+
return [`${this.dexKey}_${this.config.usd0ppAddress}`];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async getPricesVolume(
|
|
103
|
+
srcToken: Token,
|
|
104
|
+
destToken: Token,
|
|
105
|
+
amounts: bigint[],
|
|
106
|
+
side: SwapSide,
|
|
107
|
+
blockNumber: number,
|
|
108
|
+
limitPools?: string[],
|
|
109
|
+
): Promise<null | ExchangePrices<UsualBondData>> {
|
|
110
|
+
if (side === SwapSide.BUY) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const isUSD0SwapToken = this.is_usd0_swap_token(
|
|
115
|
+
srcToken.address,
|
|
116
|
+
destToken.address,
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
if (!isUSD0SwapToken) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const unitOut = BI_POWS[18]; // 1:1 swap
|
|
124
|
+
const amountsOut = amounts; // 1:1 swap, so output amounts are the same as input
|
|
125
|
+
|
|
126
|
+
return [
|
|
127
|
+
{
|
|
128
|
+
unit: unitOut,
|
|
129
|
+
prices: amountsOut,
|
|
130
|
+
data: {},
|
|
131
|
+
poolAddresses: [this.config.usd0ppAddress],
|
|
132
|
+
exchange: this.dexKey,
|
|
133
|
+
gasCost: 70000,
|
|
134
|
+
poolIdentifier: this.dexKey,
|
|
135
|
+
},
|
|
136
|
+
];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
getCalldataGasCost(poolPrices: PoolPrices<UsualBondData>): number | number[] {
|
|
140
|
+
return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
getAdapterParam(
|
|
144
|
+
srcToken: string,
|
|
145
|
+
destToken: string,
|
|
146
|
+
srcAmount: string,
|
|
147
|
+
destAmount: string,
|
|
148
|
+
data: UsualBondData,
|
|
149
|
+
side: SwapSide,
|
|
150
|
+
): AdapterExchangeParam {
|
|
151
|
+
const payload = '0x';
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
targetExchange: this.config.usd0ppAddress,
|
|
155
|
+
payload,
|
|
156
|
+
networkFee: '0',
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async getDexParam(
|
|
161
|
+
srcToken: Address,
|
|
162
|
+
destToken: Address,
|
|
163
|
+
srcAmount: NumberAsString,
|
|
164
|
+
destAmount: NumberAsString,
|
|
165
|
+
recipient: Address,
|
|
166
|
+
data: UsualBondData,
|
|
167
|
+
side: SwapSide,
|
|
168
|
+
): Promise<DexExchangeParam> {
|
|
169
|
+
if (this.is_usd0(srcToken) && this.is_usd0pp(destToken)) {
|
|
170
|
+
const exchangeData = this.usd0ppIface.encodeFunctionData('mint', [
|
|
171
|
+
srcAmount,
|
|
172
|
+
]);
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
needWrapNative: false,
|
|
176
|
+
dexFuncHasRecipient: false,
|
|
177
|
+
exchangeData,
|
|
178
|
+
targetExchange: this.config.usd0ppAddress,
|
|
179
|
+
returnAmountPos: undefined,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
throw new Error('LOGIC ERROR');
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async getTopPoolsForToken(
|
|
186
|
+
tokenAddress: Address,
|
|
187
|
+
limit: number,
|
|
188
|
+
): Promise<PoolLiquidity[]> {
|
|
189
|
+
const isUsd0 = this.is_usd0(tokenAddress);
|
|
190
|
+
if (!isUsd0 && !this.is_usd0pp(tokenAddress)) return [];
|
|
191
|
+
|
|
192
|
+
return [
|
|
193
|
+
{
|
|
194
|
+
exchange: this.dexKey,
|
|
195
|
+
address: this.config.usd0ppAddress,
|
|
196
|
+
connectorTokens: [
|
|
197
|
+
{
|
|
198
|
+
decimals: 18,
|
|
199
|
+
address: isUsd0
|
|
200
|
+
? this.config.usd0ppAddress
|
|
201
|
+
: this.config.usd0Address,
|
|
202
|
+
},
|
|
203
|
+
],
|
|
204
|
+
liquidityUSD: 1000000000, // Just returning a big number so this DEX will be preferred
|
|
205
|
+
},
|
|
206
|
+
];
|
|
207
|
+
}
|
|
208
|
+
}
|
package/tests/constants-e2e.ts
CHANGED
|
@@ -19,6 +19,10 @@ export const Tokens: {
|
|
|
19
19
|
[network: number]: { [symbol: string]: SmartTokenParams };
|
|
20
20
|
} = {
|
|
21
21
|
[Network.MAINNET]: {
|
|
22
|
+
sUSDS: {
|
|
23
|
+
address: '0xa3931d71877C0E7a3148CB7Eb4463524FEc27fbD',
|
|
24
|
+
decimals: 18,
|
|
25
|
+
},
|
|
22
26
|
USDS: {
|
|
23
27
|
address: '0xdC035D45d973E3EC169d2276DDab16f1e407384F',
|
|
24
28
|
decimals: 18,
|
|
@@ -523,6 +527,16 @@ export const Tokens: {
|
|
|
523
527
|
address: '0x07D1718fF05a8C53C8F05aDAEd57C0d672945f9a',
|
|
524
528
|
decimals: 18,
|
|
525
529
|
},
|
|
530
|
+
USD0: {
|
|
531
|
+
address: '0x73A15FeD60Bf67631dC6cd7Bc5B6e8da8190aCF5',
|
|
532
|
+
decimals: 18,
|
|
533
|
+
symbol: 'USD0',
|
|
534
|
+
},
|
|
535
|
+
'USD0++': {
|
|
536
|
+
address: '0x35D8949372D46B7a3D5A56006AE77B215fc69bC0',
|
|
537
|
+
decimals: 18,
|
|
538
|
+
symbol: 'USD0++',
|
|
539
|
+
},
|
|
526
540
|
},
|
|
527
541
|
[Network.POLYGON]: {
|
|
528
542
|
jGBP: {
|
|
@@ -1501,6 +1515,7 @@ export const Holders: {
|
|
|
1501
1515
|
} = {
|
|
1502
1516
|
[Network.MAINNET]: {
|
|
1503
1517
|
USDS: '0xB1796E8f1eEcF23027c1E3C00fE303629A189d10',
|
|
1518
|
+
sUSDS: '0xd564B3aE673CAa49D054Bf185bD72a6853763eE7',
|
|
1504
1519
|
SKY: '0x0ddda327A6614130CCb20bc0097313A282176A01',
|
|
1505
1520
|
MKR: '0xe9aAA7A9DDc0877626C1779AbC29993aD89A6c1f',
|
|
1506
1521
|
// Idle tokens
|
|
@@ -1606,6 +1621,8 @@ export const Holders: {
|
|
|
1606
1621
|
weETH: '0x267ed5f71EE47D3E45Bb1569Aa37889a2d10f91e',
|
|
1607
1622
|
rUSD: '0xEC2eda1C4F981E468ABF62424a10B69B738b498E',
|
|
1608
1623
|
arUSD: '0xeFc24206053a452e2299BF3b8f964512b041Db4C',
|
|
1624
|
+
USD0: '0x6A5d5Af0E266a24648a9d7E8D388EAEc7AbD8433',
|
|
1625
|
+
'USD0++': '0x2227b6806339906707b43F36a1f07B52FF7Fa776',
|
|
1609
1626
|
},
|
|
1610
1627
|
[Network.POLYGON]: {
|
|
1611
1628
|
jGBP: '0x02aa0B826c7BA6386DdBE04C0a8715A1c0A16B24',
|