@steerprotocol/sdk 1.30.8-test-algebra-plugins.2 → 1.31.0
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/dist/cjs/base/PoolClient.js +137 -0
- package/dist/cjs/base/PoolClient.js.map +1 -1
- package/dist/cjs/base/VaultClient.js +111 -2
- package/dist/cjs/base/VaultClient.js.map +1 -1
- package/dist/cjs/const/feeManagerContracts.js +25 -0
- package/dist/cjs/const/feeManagerContracts.js.map +1 -0
- package/dist/cjs/const/network.js +7 -0
- package/dist/cjs/const/network.js.map +1 -1
- package/dist/cjs/const/protocol.js +68 -92
- package/dist/cjs/const/protocol.js.map +1 -1
- package/dist/cjs/scripts/processDeployments.js +1 -0
- package/dist/cjs/scripts/processDeployments.js.map +1 -1
- package/dist/esm/base/PoolClient.js +137 -0
- package/dist/esm/base/PoolClient.js.map +1 -1
- package/dist/esm/base/VaultClient.js +111 -2
- package/dist/esm/base/VaultClient.js.map +1 -1
- package/dist/esm/const/feeManagerContracts.js +25 -0
- package/dist/esm/const/feeManagerContracts.js.map +1 -0
- package/dist/esm/const/network.js +7 -0
- package/dist/esm/const/network.js.map +1 -1
- package/dist/esm/const/protocol.js +68 -92
- package/dist/esm/const/protocol.js.map +1 -1
- package/dist/esm/scripts/processDeployments.js +1 -0
- package/dist/esm/scripts/processDeployments.js.map +1 -1
- package/dist/types/base/PoolClient.d.ts +22 -0
- package/dist/types/base/PoolClient.d.ts.map +1 -1
- package/dist/types/base/VaultClient.d.ts +20 -0
- package/dist/types/base/VaultClient.d.ts.map +1 -1
- package/dist/types/const/feeManagerContracts.d.ts +6 -0
- package/dist/types/const/feeManagerContracts.d.ts.map +1 -0
- package/dist/types/const/network.d.ts +1 -0
- package/dist/types/const/network.d.ts.map +1 -1
- package/dist/types/const/protocol.d.ts +4 -19
- package/dist/types/const/protocol.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/__tests__/base/PoolClient.test.ts +355 -104
- package/src/__tests__/base/StakingClient.test.ts +72 -72
- package/src/__tests__/base/VaultClient.protocol-filter.test.ts +64 -137
- package/src/__tests__/base/VaultClient.test.ts +460 -60
- package/src/__tests__/base/vault/single-asset/calculateLimitPrice.test.ts +32 -14
- package/src/__tests__/base/vault/single-asset/calculateSwapAmount.test.ts +7 -4
- package/src/__tests__/base/vault/single-asset/estimateLpTokens.test.ts +105 -570
- package/src/__tests__/base/vault/single-asset/simulateSwap.test.ts +45 -66
- package/src/__tests__/base/vault/single-asset/singleAssetDepositClient.test.ts +178 -381
- package/src/__tests__/const/network.feeManager.test.ts +47 -0
- package/src/__tests__/fixtures/live/single-asset.fixture.json +116 -0
- package/src/__tests__/fixtures/live/staking-pools.fixture.json +353 -0
- package/src/__tests__/fixtures/live/vaults.fixture.json +5392 -0
- package/src/base/PoolClient.ts +200 -1
- package/src/base/VaultClient.ts +169 -2
- package/src/const/feeManagerContracts.ts +28 -0
- package/src/const/network.ts +10 -1
- package/src/const/protocol.ts +18 -39
- package/src/scripts/processDeployments.ts +1 -0
|
@@ -1,39 +1,54 @@
|
|
|
1
|
-
import { createPublicClient, http, parseEther } from 'viem';
|
|
1
|
+
import { createPublicClient, encodeAbiParameters, http, parseEther } from 'viem';
|
|
2
2
|
import { polygon } from 'viem/chains';
|
|
3
3
|
import { determineSwapDirection, simulateSwap, simulateSwapWithSlippage, validateSwapParams } from '../../../../base/vault/single-asset/simulateSwap.js';
|
|
4
4
|
import { AMMType } from '../../../../base/vault/single-asset/types.js';
|
|
5
5
|
|
|
6
6
|
// Mock addresses for testing
|
|
7
|
-
const mockPoolAddress = '
|
|
7
|
+
const mockPoolAddress = '0x45dda9cb7c25131df268515131f647d726f50608' as const;
|
|
8
8
|
const mockRecipientAddress = '0x9876543210987654321098765432109876543210' as const;
|
|
9
|
-
const mockTokenIn = '
|
|
10
|
-
const mockTokenOut = '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619' as const; //
|
|
11
|
-
const mockFee =
|
|
9
|
+
const mockTokenIn = '0x2791bca1f2de4661ed88a30c99a7a9449aa84174' as const; // USDC on Polygon
|
|
10
|
+
const mockTokenOut = '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619' as const; // WETH on Polygon
|
|
11
|
+
const mockFee = 500;
|
|
12
12
|
const mockChainId = 137; // Polygon
|
|
13
|
-
const mockTickSpacing =
|
|
13
|
+
const mockTickSpacing = 10
|
|
14
|
+
const mockSqrtPriceX96After = BigInt('1753087240305394106909115744048138');
|
|
15
|
+
|
|
16
|
+
const encodeQuoteResult = (amountOut: bigint, sqrtPriceX96After: bigint = mockSqrtPriceX96After) =>
|
|
17
|
+
encodeAbiParameters(
|
|
18
|
+
[
|
|
19
|
+
{ name: 'amountOut', type: 'uint256' },
|
|
20
|
+
{ name: 'sqrtPriceX96After', type: 'uint160' },
|
|
21
|
+
{ name: 'initializedTicksCrossed', type: 'uint32' },
|
|
22
|
+
{ name: 'gasEstimate', type: 'uint256' },
|
|
23
|
+
],
|
|
24
|
+
[amountOut, sqrtPriceX96After, 0, 0n],
|
|
25
|
+
);
|
|
14
26
|
|
|
15
27
|
describe('simulateSwap', () => {
|
|
16
28
|
let publicClient: any;
|
|
17
29
|
|
|
18
30
|
beforeEach(() => {
|
|
19
31
|
// Create a mock public client
|
|
20
|
-
publicClient = createPublicClient({
|
|
32
|
+
publicClient = createPublicClient({
|
|
33
|
+
chain: polygon,
|
|
34
|
+
transport: http('https://polygon-bor-rpc.publicnode.com'),
|
|
35
|
+
});
|
|
21
36
|
|
|
22
37
|
// Initialize SteerClient with real clients
|
|
23
38
|
});
|
|
24
39
|
|
|
25
40
|
describe('successful swaps', () => {
|
|
26
41
|
|
|
27
|
-
it
|
|
42
|
+
it('Shoud simulate token0 -> token1 swap', async () => {
|
|
28
43
|
const result = await simulateSwapWithSlippage(
|
|
29
44
|
publicClient,
|
|
30
45
|
{
|
|
31
46
|
poolAddress: mockPoolAddress,
|
|
32
47
|
recipient: mockRecipientAddress,
|
|
33
48
|
zeroForOne: true,
|
|
34
|
-
amountSpecified:
|
|
35
|
-
sqrtPriceLimitX96:
|
|
36
|
-
ammType: AMMType.
|
|
49
|
+
amountSpecified: 1000000n,
|
|
50
|
+
sqrtPriceLimitX96: 1600000000000000000000000000000000n,
|
|
51
|
+
ammType: AMMType.UniswapV3,
|
|
37
52
|
tokenIn: mockTokenIn,
|
|
38
53
|
tokenOut: mockTokenOut,
|
|
39
54
|
fee: mockFee
|
|
@@ -55,8 +70,8 @@ describe('simulateSwap', () => {
|
|
|
55
70
|
pool: mockPoolAddress,
|
|
56
71
|
recipient: mockRecipientAddress,
|
|
57
72
|
zeroForOne: true,
|
|
58
|
-
amountSpecified:
|
|
59
|
-
sqrtPriceLimitX96:
|
|
73
|
+
amountSpecified: 1000000n,
|
|
74
|
+
sqrtPriceLimitX96: 0n,
|
|
60
75
|
ammType: AMMType.UniswapV3,
|
|
61
76
|
tokenIn: mockTokenIn,
|
|
62
77
|
tokenOut: mockTokenOut,
|
|
@@ -73,14 +88,10 @@ describe('simulateSwap', () => {
|
|
|
73
88
|
it('should simulate token1 → token0 swap', async () => {
|
|
74
89
|
const mockAmount0 = parseEther('40'); // Positive means token0 coming in
|
|
75
90
|
const mockAmount1 = -parseEther('20'); // Negative means token1 going out
|
|
76
|
-
const mockEncodedData = '0xabcdef1234567890';
|
|
77
|
-
const mockDecodedResult = [mockAmount0, mockAmount1];
|
|
78
91
|
|
|
79
92
|
publicClient.call = jest.fn().mockResolvedValue({
|
|
80
|
-
data:
|
|
93
|
+
data: encodeQuoteResult(mockAmount0),
|
|
81
94
|
});
|
|
82
|
-
publicClient.encodeFunctionData = jest.fn().mockReturnValue(mockEncodedData);
|
|
83
|
-
publicClient.decodeFunctionResult = jest.fn().mockReturnValue(mockDecodedResult);
|
|
84
95
|
|
|
85
96
|
const result = await simulateSwap(publicClient, {
|
|
86
97
|
pool: mockPoolAddress,
|
|
@@ -96,17 +107,10 @@ describe('simulateSwap', () => {
|
|
|
96
107
|
}, mockChainId);
|
|
97
108
|
|
|
98
109
|
expect(result.success).toBe(true);
|
|
99
|
-
expect(result.data).
|
|
110
|
+
expect(result.data).toMatchObject({
|
|
100
111
|
amount0: mockAmount0,
|
|
101
112
|
amount1: mockAmount1
|
|
102
113
|
});
|
|
103
|
-
|
|
104
|
-
// Verify zeroForOne is false
|
|
105
|
-
expect(publicClient.encodeFunctionData).toHaveBeenCalledWith(
|
|
106
|
-
expect.objectContaining({
|
|
107
|
-
args: expect.arrayContaining([false])
|
|
108
|
-
})
|
|
109
|
-
);
|
|
110
114
|
});
|
|
111
115
|
|
|
112
116
|
it('should handle different amount specifications', async () => {
|
|
@@ -120,13 +124,9 @@ describe('simulateSwap', () => {
|
|
|
120
124
|
for (const amount of amounts) {
|
|
121
125
|
const mockAmount0 = -amount;
|
|
122
126
|
const mockAmount1 = amount * 2n; // 2:1 ratio
|
|
123
|
-
const mockEncodedData = '0x1234567890abcdef';
|
|
124
|
-
|
|
125
127
|
publicClient.call = jest.fn().mockResolvedValue({
|
|
126
|
-
data:
|
|
128
|
+
data: encodeQuoteResult(mockAmount1),
|
|
127
129
|
});
|
|
128
|
-
publicClient.encodeFunctionData = jest.fn().mockReturnValue(mockEncodedData);
|
|
129
|
-
publicClient.decodeFunctionResult = jest.fn().mockReturnValue([mockAmount0, mockAmount1]);
|
|
130
130
|
|
|
131
131
|
const result = await simulateSwap(publicClient, {
|
|
132
132
|
pool: mockPoolAddress,
|
|
@@ -167,15 +167,10 @@ describe('simulateSwap', () => {
|
|
|
167
167
|
];
|
|
168
168
|
|
|
169
169
|
for (const test of priceTests) {
|
|
170
|
-
const
|
|
171
|
-
const mockAmount1 = -parseEther('5');
|
|
172
|
-
const mockEncodedData = '0x1234567890abcdef';
|
|
173
|
-
|
|
170
|
+
const mockAmount1 = parseEther('5');
|
|
174
171
|
publicClient.call = jest.fn().mockResolvedValue({
|
|
175
|
-
data:
|
|
172
|
+
data: encodeQuoteResult(mockAmount1),
|
|
176
173
|
});
|
|
177
|
-
publicClient.encodeFunctionData = jest.fn().mockReturnValue(mockEncodedData);
|
|
178
|
-
publicClient.decodeFunctionResult = jest.fn().mockReturnValue([mockAmount0, mockAmount1]);
|
|
179
174
|
|
|
180
175
|
const result = await simulateSwap(publicClient, {
|
|
181
176
|
pool: mockPoolAddress,
|
|
@@ -191,17 +186,16 @@ describe('simulateSwap', () => {
|
|
|
191
186
|
}, mockChainId);
|
|
192
187
|
|
|
193
188
|
expect(result.success).toBe(true);
|
|
194
|
-
expect(publicClient.encodeFunctionData).toHaveBeenCalledWith(
|
|
195
|
-
expect.objectContaining({
|
|
196
|
-
args: expect.arrayContaining([test.sqrtPriceLimitX96])
|
|
197
|
-
})
|
|
198
|
-
);
|
|
199
189
|
}
|
|
200
190
|
});
|
|
201
191
|
});
|
|
202
192
|
|
|
203
193
|
describe('error handling', () => {
|
|
204
|
-
it('should
|
|
194
|
+
it('should support Algebra AMM via protocol mapping', async () => {
|
|
195
|
+
publicClient.call = jest.fn().mockResolvedValue({
|
|
196
|
+
data: encodeQuoteResult(parseEther('10')),
|
|
197
|
+
});
|
|
198
|
+
|
|
205
199
|
const result = await simulateSwap(publicClient, {
|
|
206
200
|
pool: mockPoolAddress,
|
|
207
201
|
recipient: mockRecipientAddress,
|
|
@@ -215,9 +209,8 @@ describe('simulateSwap', () => {
|
|
|
215
209
|
tickSpacing: mockTickSpacing
|
|
216
210
|
}, mockChainId);
|
|
217
211
|
|
|
218
|
-
expect(result.success).toBe(
|
|
219
|
-
expect(result.status).toBe(
|
|
220
|
-
expect(result.error).toContain('not yet supported');
|
|
212
|
+
expect(result.success).toBe(true);
|
|
213
|
+
expect(result.status).toBe(200);
|
|
221
214
|
});
|
|
222
215
|
|
|
223
216
|
it('should handle call failures', async () => {
|
|
@@ -265,14 +258,8 @@ describe('simulateSwap', () => {
|
|
|
265
258
|
});
|
|
266
259
|
|
|
267
260
|
it('should handle decode errors', async () => {
|
|
268
|
-
const mockEncodedData = '0x1234567890abcdef';
|
|
269
|
-
|
|
270
261
|
publicClient.call = jest.fn().mockResolvedValue({
|
|
271
|
-
data:
|
|
272
|
-
});
|
|
273
|
-
publicClient.encodeFunctionData = jest.fn().mockReturnValue(mockEncodedData);
|
|
274
|
-
publicClient.decodeFunctionResult = jest.fn().mockImplementation(() => {
|
|
275
|
-
throw new Error('Decode failed');
|
|
262
|
+
data: '0x1234567890abcdef',
|
|
276
263
|
});
|
|
277
264
|
|
|
278
265
|
const result = await simulateSwap(publicClient, {
|
|
@@ -290,7 +277,7 @@ describe('simulateSwap', () => {
|
|
|
290
277
|
|
|
291
278
|
expect(result.success).toBe(false);
|
|
292
279
|
expect(result.status).toBe(500);
|
|
293
|
-
expect(result.error).
|
|
280
|
+
expect(result.error).toContain('Data size of');
|
|
294
281
|
});
|
|
295
282
|
});
|
|
296
283
|
|
|
@@ -386,13 +373,9 @@ describe('simulateSwap', () => {
|
|
|
386
373
|
const veryLargeAmount = BigInt('1000000000000000000000000'); // 1M tokens
|
|
387
374
|
const mockAmount0 = -veryLargeAmount;
|
|
388
375
|
const mockAmount1 = veryLargeAmount / 2n;
|
|
389
|
-
const mockEncodedData = '0x1234567890abcdef';
|
|
390
|
-
|
|
391
376
|
publicClient.call = jest.fn().mockResolvedValue({
|
|
392
|
-
data:
|
|
377
|
+
data: encodeQuoteResult(mockAmount1),
|
|
393
378
|
});
|
|
394
|
-
publicClient.encodeFunctionData = jest.fn().mockReturnValue(mockEncodedData);
|
|
395
|
-
publicClient.decodeFunctionResult = jest.fn().mockReturnValue([mockAmount0, mockAmount1]);
|
|
396
379
|
|
|
397
380
|
const result = await simulateSwap(publicClient, {
|
|
398
381
|
pool: mockPoolAddress,
|
|
@@ -416,13 +399,9 @@ describe('simulateSwap', () => {
|
|
|
416
399
|
const verySmallAmount = BigInt('1'); // 1 wei
|
|
417
400
|
const mockAmount0 = -verySmallAmount;
|
|
418
401
|
const mockAmount1 = verySmallAmount;
|
|
419
|
-
const mockEncodedData = '0x1234567890abcdef';
|
|
420
|
-
|
|
421
402
|
publicClient.call = jest.fn().mockResolvedValue({
|
|
422
|
-
data:
|
|
403
|
+
data: encodeQuoteResult(mockAmount1),
|
|
423
404
|
});
|
|
424
|
-
publicClient.encodeFunctionData = jest.fn().mockReturnValue(mockEncodedData);
|
|
425
|
-
publicClient.decodeFunctionResult = jest.fn().mockReturnValue([mockAmount0, mockAmount1]);
|
|
426
405
|
|
|
427
406
|
const result = await simulateSwap(publicClient, {
|
|
428
407
|
pool: mockPoolAddress,
|
|
@@ -464,4 +443,4 @@ describe('validateSwapParams', () => {
|
|
|
464
443
|
ammType: AMMType.UniswapV3
|
|
465
444
|
};
|
|
466
445
|
|
|
467
|
-
});
|
|
446
|
+
});
|