@paraswap/dex-lib 3.8.35 → 3.8.36-usual.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/build/abi/lite-psm/usdsPsm.json +163 -0
- package/build/dex/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/lite-psm/config.js +5 -1
- package/build/dex/lite-psm/config.js.map +1 -1
- package/build/dex/lite-psm/lite-psm.d.ts +4 -2
- package/build/dex/lite-psm/lite-psm.js +39 -26
- package/build/dex/lite-psm/lite-psm.js.map +1 -1
- package/build/dex/lite-psm/types.d.ts +2 -2
- package/build/dex/usual-bond/usual-bond.js +5 -11
- package/build/dex/usual-bond/usual-bond.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/lite-psm/usdsPsm.json +163 -0
- package/src/abi/usual-bond/usd0pp.abi.json +867 -0
- package/src/dex/index.ts +2 -0
- package/src/dex/lite-psm/config.ts +5 -1
- package/src/dex/lite-psm/lite-psm-e2e.test.ts +68 -1
- package/src/dex/lite-psm/lite-psm.ts +52 -31
- package/src/dex/lite-psm/types.ts +3 -2
- 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 +81 -0
- package/src/dex/usual-bond/usual-bond-integration.test.ts +144 -0
- package/src/dex/usual-bond/usual-bond.ts +204 -0
- package/tests/constants-e2e.ts +13 -1
|
@@ -0,0 +1,204 @@
|
|
|
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
|
+
const isUSD0SwapToken = this.is_usd0_swap_token(
|
|
111
|
+
srcToken.address,
|
|
112
|
+
destToken.address,
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
if (!isUSD0SwapToken) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const unitOut = BI_POWS[18]; // 1:1 swap
|
|
120
|
+
const amountsOut = amounts; // 1:1 swap, so output amounts are the same as input
|
|
121
|
+
|
|
122
|
+
return [
|
|
123
|
+
{
|
|
124
|
+
unit: unitOut,
|
|
125
|
+
prices: amountsOut,
|
|
126
|
+
data: {},
|
|
127
|
+
poolAddresses: [this.config.usd0ppAddress],
|
|
128
|
+
exchange: this.dexKey,
|
|
129
|
+
gasCost: 70000,
|
|
130
|
+
poolIdentifier: this.dexKey,
|
|
131
|
+
},
|
|
132
|
+
];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
getCalldataGasCost(poolPrices: PoolPrices<UsualBondData>): number | number[] {
|
|
136
|
+
return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
getAdapterParam(
|
|
140
|
+
srcToken: string,
|
|
141
|
+
destToken: string,
|
|
142
|
+
srcAmount: string,
|
|
143
|
+
destAmount: string,
|
|
144
|
+
data: UsualBondData,
|
|
145
|
+
side: SwapSide,
|
|
146
|
+
): AdapterExchangeParam {
|
|
147
|
+
const payload = '0x';
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
targetExchange: this.config.usd0ppAddress,
|
|
151
|
+
payload,
|
|
152
|
+
networkFee: '0',
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async getDexParam(
|
|
157
|
+
srcToken: Address,
|
|
158
|
+
destToken: Address,
|
|
159
|
+
srcAmount: NumberAsString,
|
|
160
|
+
destAmount: NumberAsString,
|
|
161
|
+
recipient: Address,
|
|
162
|
+
data: UsualBondData,
|
|
163
|
+
side: SwapSide,
|
|
164
|
+
): Promise<DexExchangeParam> {
|
|
165
|
+
if (this.is_usd0(srcToken) && this.is_usd0pp(destToken)) {
|
|
166
|
+
const exchangeData = this.usd0ppIface.encodeFunctionData('mint', [
|
|
167
|
+
srcAmount,
|
|
168
|
+
]);
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
needWrapNative: false,
|
|
172
|
+
dexFuncHasRecipient: false,
|
|
173
|
+
exchangeData,
|
|
174
|
+
targetExchange: this.config.usd0ppAddress,
|
|
175
|
+
returnAmountPos: undefined,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
throw new Error('LOGIC ERROR');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async getTopPoolsForToken(
|
|
182
|
+
tokenAddress: Address,
|
|
183
|
+
limit: number,
|
|
184
|
+
): Promise<PoolLiquidity[]> {
|
|
185
|
+
const isUsd0 = this.is_usd0(tokenAddress);
|
|
186
|
+
if (!isUsd0 && !this.is_usd0pp(tokenAddress)) return [];
|
|
187
|
+
|
|
188
|
+
return [
|
|
189
|
+
{
|
|
190
|
+
exchange: this.dexKey,
|
|
191
|
+
address: this.config.usd0ppAddress,
|
|
192
|
+
connectorTokens: [
|
|
193
|
+
{
|
|
194
|
+
decimals: 18,
|
|
195
|
+
address: isUsd0
|
|
196
|
+
? this.config.usd0ppAddress
|
|
197
|
+
: this.config.usd0Address,
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
liquidityUSD: 1000000000, // Just returning a big number so this DEX will be preferred
|
|
201
|
+
},
|
|
202
|
+
];
|
|
203
|
+
}
|
|
204
|
+
}
|
package/tests/constants-e2e.ts
CHANGED
|
@@ -523,6 +523,16 @@ export const Tokens: {
|
|
|
523
523
|
address: '0x07D1718fF05a8C53C8F05aDAEd57C0d672945f9a',
|
|
524
524
|
decimals: 18,
|
|
525
525
|
},
|
|
526
|
+
USD0: {
|
|
527
|
+
address: '0x73A15FeD60Bf67631dC6cd7Bc5B6e8da8190aCF5',
|
|
528
|
+
decimals: 18,
|
|
529
|
+
symbol: 'USD0',
|
|
530
|
+
},
|
|
531
|
+
'USD0++': {
|
|
532
|
+
address: '0x35D8949372D46B7a3D5A56006AE77B215fc69bC0',
|
|
533
|
+
decimals: 18,
|
|
534
|
+
symbol: 'USD0++',
|
|
535
|
+
},
|
|
526
536
|
},
|
|
527
537
|
[Network.POLYGON]: {
|
|
528
538
|
jGBP: {
|
|
@@ -1500,7 +1510,7 @@ export const Holders: {
|
|
|
1500
1510
|
[network: number]: { [tokenAddress: string]: Address };
|
|
1501
1511
|
} = {
|
|
1502
1512
|
[Network.MAINNET]: {
|
|
1503
|
-
USDS: '
|
|
1513
|
+
USDS: '0xB1796E8f1eEcF23027c1E3C00fE303629A189d10',
|
|
1504
1514
|
SKY: '0x0ddda327A6614130CCb20bc0097313A282176A01',
|
|
1505
1515
|
MKR: '0xe9aAA7A9DDc0877626C1779AbC29993aD89A6c1f',
|
|
1506
1516
|
// Idle tokens
|
|
@@ -1606,6 +1616,8 @@ export const Holders: {
|
|
|
1606
1616
|
weETH: '0x267ed5f71EE47D3E45Bb1569Aa37889a2d10f91e',
|
|
1607
1617
|
rUSD: '0xEC2eda1C4F981E468ABF62424a10B69B738b498E',
|
|
1608
1618
|
arUSD: '0xeFc24206053a452e2299BF3b8f964512b041Db4C',
|
|
1619
|
+
USD0: '0x6A5d5Af0E266a24648a9d7E8D388EAEc7AbD8433',
|
|
1620
|
+
'USD0++': '0x2227b6806339906707b43F36a1f07B52FF7Fa776',
|
|
1609
1621
|
},
|
|
1610
1622
|
[Network.POLYGON]: {
|
|
1611
1623
|
jGBP: '0x02aa0B826c7BA6386DdBE04C0a8715A1c0A16B24',
|