@cetusprotocol/aggregator-sdk 1.1.4 โ 1.1.5
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/.github/workflows/test.yml +152 -0
- package/.vscode/settings.json +8 -0
- package/CLAUDE.md +101 -0
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +24 -44
- package/dist/index.mjs +24 -44
- package/docs/Cetus_Aggregator_V3_/346/216/245/345/217/243/346/226/207/346/241/243.md +706 -0
- package/docs/REFACTOR.md +24 -0
- package/docs//350/267/257/345/276/204/346/213/223/346/211/221/346/216/222/345/272/217.md +208 -0
- package/package.json +2 -2
- package/script/copy-to-sui-aggregator.sh +85 -0
- package/test.json +267 -0
- package/.claude/settings.local.json +0 -41
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
name: Automated Testing with Success Rate
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main, develop, refactor-v3 ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main, develop, refactor-v3 ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
|
|
13
|
+
steps:
|
|
14
|
+
- name: Checkout code
|
|
15
|
+
uses: actions/checkout@v4
|
|
16
|
+
|
|
17
|
+
- name: Setup Bun
|
|
18
|
+
uses: oven-sh/setup-bun@v1
|
|
19
|
+
with:
|
|
20
|
+
bun-version: latest
|
|
21
|
+
|
|
22
|
+
- name: Install dependencies
|
|
23
|
+
run: bun install
|
|
24
|
+
|
|
25
|
+
- name: Run tests with coverage and statistics
|
|
26
|
+
run: |
|
|
27
|
+
echo "๐งช Running all tests..."
|
|
28
|
+
|
|
29
|
+
# Run tests with JSON output for parsing
|
|
30
|
+
bun test --json --outputFile=test-results.json --coverage || true
|
|
31
|
+
|
|
32
|
+
# Also run regular test output for display
|
|
33
|
+
echo "๐ Test Results:"
|
|
34
|
+
bun test --verbose || TEST_EXIT_CODE=$?
|
|
35
|
+
|
|
36
|
+
# Parse test results and calculate success rate
|
|
37
|
+
echo "๐ Calculating test success rate..."
|
|
38
|
+
|
|
39
|
+
# Create a simple Node.js script to parse JSON results
|
|
40
|
+
cat > calculate-stats.js << 'EOF'
|
|
41
|
+
const fs = require('fs');
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
// Try to read the JSON results file
|
|
45
|
+
let results;
|
|
46
|
+
if (fs.existsSync('test-results.json')) {
|
|
47
|
+
const data = fs.readFileSync('test-results.json', 'utf8');
|
|
48
|
+
results = JSON.parse(data);
|
|
49
|
+
} else {
|
|
50
|
+
console.log('โ ๏ธ JSON results file not found, using alternative method');
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Calculate statistics
|
|
55
|
+
const totalTests = results.numTotalTests || 0;
|
|
56
|
+
const passedTests = results.numPassedTests || 0;
|
|
57
|
+
const failedTests = results.numFailedTests || 0;
|
|
58
|
+
const successRate = totalTests > 0 ? ((passedTests / totalTests) * 100).toFixed(2) : 0;
|
|
59
|
+
|
|
60
|
+
console.log('\n๐ =================================');
|
|
61
|
+
console.log('๐ TEST EXECUTION SUMMARY');
|
|
62
|
+
console.log('๐ =================================');
|
|
63
|
+
console.log(`๐ Total Tests: ${totalTests}`);
|
|
64
|
+
console.log(`โ
Passed Tests: ${passedTests}`);
|
|
65
|
+
console.log(`โ Failed Tests: ${failedTests}`);
|
|
66
|
+
console.log(`๐ Success Rate: ${successRate}%`);
|
|
67
|
+
console.log('๐ =================================\n');
|
|
68
|
+
|
|
69
|
+
// Set environment variables for GitHub Actions
|
|
70
|
+
console.log(`::set-output name=total_tests::${totalTests}`);
|
|
71
|
+
console.log(`::set-output name=passed_tests::${passedTests}`);
|
|
72
|
+
console.log(`::set-output name=failed_tests::${failedTests}`);
|
|
73
|
+
console.log(`::set-output name=success_rate::${successRate}`);
|
|
74
|
+
|
|
75
|
+
// Exit with non-zero code if tests failed
|
|
76
|
+
if (failedTests > 0) {
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error('Error parsing test results:', error);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
EOF
|
|
85
|
+
|
|
86
|
+
# Run the statistics calculation
|
|
87
|
+
node calculate-stats.js || {
|
|
88
|
+
echo "โ ๏ธ Falling back to alternative statistics calculation..."
|
|
89
|
+
|
|
90
|
+
# Alternative method using grep on test output
|
|
91
|
+
echo "๐ ================================="
|
|
92
|
+
echo "๐ TEST EXECUTION SUMMARY"
|
|
93
|
+
echo "๐ ================================="
|
|
94
|
+
|
|
95
|
+
# Count test files
|
|
96
|
+
TEST_FILES=$(find tests -name "*.test.ts" | wc -l)
|
|
97
|
+
echo "๐ Total Test Files: $TEST_FILES"
|
|
98
|
+
|
|
99
|
+
# Try to get basic stats from bun test output
|
|
100
|
+
echo "๐ Running tests again for statistics..."
|
|
101
|
+
bun test 2>&1 | tee test-output.log
|
|
102
|
+
|
|
103
|
+
# Parse the output for basic statistics
|
|
104
|
+
if grep -q "Tests:" test-output.log; then
|
|
105
|
+
STATS=$(grep "Tests:" test-output.log | tail -1)
|
|
106
|
+
echo "๐ $STATS"
|
|
107
|
+
fi
|
|
108
|
+
|
|
109
|
+
echo "๐ ================================="
|
|
110
|
+
|
|
111
|
+
# Clean up
|
|
112
|
+
rm -f test-output.log
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
# Clean up
|
|
116
|
+
rm -f calculate-stats.js test-results.json
|
|
117
|
+
|
|
118
|
+
# Exit with the original test exit code
|
|
119
|
+
exit ${TEST_EXIT_CODE:-0}
|
|
120
|
+
|
|
121
|
+
- name: Upload test results
|
|
122
|
+
uses: actions/upload-artifact@v3
|
|
123
|
+
if: always()
|
|
124
|
+
with:
|
|
125
|
+
name: test-results
|
|
126
|
+
path: |
|
|
127
|
+
coverage/
|
|
128
|
+
test-results.json
|
|
129
|
+
retention-days: 30
|
|
130
|
+
|
|
131
|
+
- name: Comment PR with test results
|
|
132
|
+
uses: actions/github-script@v6
|
|
133
|
+
if: github.event_name == 'pull_request'
|
|
134
|
+
with:
|
|
135
|
+
script: |
|
|
136
|
+
const output = `## ๐งช Test Results
|
|
137
|
+
|
|
138
|
+
**Test Execution Summary:**
|
|
139
|
+
- Total Tests: \${{ steps.test.outputs.total_tests || 'N/A' }}
|
|
140
|
+
- Passed Tests: \${{ steps.test.outputs.passed_tests || 'N/A' }}
|
|
141
|
+
- Failed Tests: \${{ steps.test.outputs.failed_tests || 'N/A' }}
|
|
142
|
+
- Success Rate: \${{ steps.test.outputs.success_rate || 'N/A' }}%
|
|
143
|
+
|
|
144
|
+
\${{ steps.test.outputs.failed_tests > 0 && 'โ Some tests failed. Please review the test output above.' || 'โ
All tests passed!' }}
|
|
145
|
+
`;
|
|
146
|
+
|
|
147
|
+
github.rest.issues.createComment({
|
|
148
|
+
issue_number: context.issue.number,
|
|
149
|
+
owner: context.repo.owner,
|
|
150
|
+
repo: context.repo.repo,
|
|
151
|
+
body: output
|
|
152
|
+
});
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
The **Cetus Aggregator SDK** is a TypeScript library for the Sui blockchain ecosystem that provides swap aggregation across 25+ decentralized exchanges (DEXs). The SDK finds optimal trading routes, best prices, and lowest slippage by integrating multiple DEXs including Cetus, DeepBook, Kriya, FlowX, Turbos, Aftermath, and many others.
|
|
8
|
+
|
|
9
|
+
## Development Commands
|
|
10
|
+
|
|
11
|
+
### Build and Development
|
|
12
|
+
|
|
13
|
+
- `bun run build` - Compile TypeScript to CommonJS/ESM with type definitions using tsup
|
|
14
|
+
- `bun run dev` - Development mode with file watching
|
|
15
|
+
- `bun run clean` - Remove build artifacts and dependencies
|
|
16
|
+
- `bun run publish:test` - Publish experimental version to bun
|
|
17
|
+
|
|
18
|
+
### Testing
|
|
19
|
+
|
|
20
|
+
- `bun test` - Run Jest test suite with ESM support
|
|
21
|
+
- Tests are organized by aggregator versions (v2/v3) in `/tests/` directory
|
|
22
|
+
- Individual DEX tests located in `/tests/aggregatorv2/router/`
|
|
23
|
+
- Mathematical function tests in `/tests/math.test.ts`
|
|
24
|
+
|
|
25
|
+
## Architecture
|
|
26
|
+
|
|
27
|
+
### Core Components
|
|
28
|
+
|
|
29
|
+
**Main Entry Points:**
|
|
30
|
+
|
|
31
|
+
- `src/index.ts` - Main export barrel
|
|
32
|
+
- `src/client.ts` - Aggregator v2 client implementation
|
|
33
|
+
- `src/clientv3.ts` - Aggregator v3 client implementation
|
|
34
|
+
|
|
35
|
+
**Key Directories:**
|
|
36
|
+
|
|
37
|
+
- `src/transaction/` - DEX-specific swap implementations (25+ integrations)
|
|
38
|
+
- `src/utils/` - Utility functions for coins, transactions, API calls
|
|
39
|
+
- `src/types/` - TypeScript type definitions
|
|
40
|
+
- `src/movecall/` - Move contract interaction helpers
|
|
41
|
+
- `src/api/` - API interaction layer
|
|
42
|
+
- `src/math/` - Mathematical calculations for trading
|
|
43
|
+
|
|
44
|
+
### DEX Integration Pattern
|
|
45
|
+
|
|
46
|
+
Each DEX has its own transaction module in `src/transaction/` following a consistent pattern:
|
|
47
|
+
|
|
48
|
+
- Import from main client class (AggregatorClient/AggregatorClient)
|
|
49
|
+
- Implement DEX-specific swap logic
|
|
50
|
+
- Handle transaction building and execution
|
|
51
|
+
- Support both amount-in and amount-out calculations
|
|
52
|
+
|
|
53
|
+
### TypeScript Configuration
|
|
54
|
+
|
|
55
|
+
- Uses path mapping: `~/*` maps to `src/*`
|
|
56
|
+
- Jest configured with same path mapping
|
|
57
|
+
- Targets ES6 with CommonJS modules
|
|
58
|
+
- Strict TypeScript enabled
|
|
59
|
+
|
|
60
|
+
### Key Dependencies
|
|
61
|
+
|
|
62
|
+
- `@mysten/sui@^1.6.0` - Official Sui SDK for blockchain interactions
|
|
63
|
+
- `@pythnetwork/pyth-sui-js@^2.1.0` - Pyth oracle integration for price feeds
|
|
64
|
+
- `bn.js@^5.2.1` - Big number handling for precise calculations
|
|
65
|
+
- `decimal.js@^10.4.3` - Decimal arithmetic for financial calculations
|
|
66
|
+
|
|
67
|
+
### Multi-Version Support
|
|
68
|
+
|
|
69
|
+
The SDK supports both Aggregator v2 and v3 APIs:
|
|
70
|
+
|
|
71
|
+
- v2: Legacy aggregator with extensive DEX support
|
|
72
|
+
- v3: Newer aggregator with enhanced features and performance
|
|
73
|
+
|
|
74
|
+
### Testing Strategy
|
|
75
|
+
|
|
76
|
+
- Unit tests for mathematical functions (`tests/math.test.ts`)
|
|
77
|
+
- Integration tests for each DEX in `tests/aggregatorv2/router/`
|
|
78
|
+
- Router functionality tests (`tests/aggregatorv2/router.test.ts`)
|
|
79
|
+
- Wallet interaction tests (`tests/wallet.test.ts`)
|
|
80
|
+
|
|
81
|
+
### Build Process
|
|
82
|
+
|
|
83
|
+
Uses `tsup` for bundling with:
|
|
84
|
+
|
|
85
|
+
- Multiple output formats (CJS, ESM, TypeScript declarations)
|
|
86
|
+
- Tree shaking enabled
|
|
87
|
+
- Code splitting support
|
|
88
|
+
- Development watch mode
|
|
89
|
+
|
|
90
|
+
### Contract Addresses
|
|
91
|
+
|
|
92
|
+
The SDK works with multiple contract versions on Sui mainnet:
|
|
93
|
+
|
|
94
|
+
- CetusAggregatorV2: `0x3864c7c59a4889fec05d1aae4bc9dba5a0e0940594b424fbed44cb3f6ac4c032`
|
|
95
|
+
- CetusAggregatorV2ExtendV1: `0x39402d188b7231036e52266ebafad14413b4bf3daea4ac17115989444e6cd516`
|
|
96
|
+
- CetusAggregatorV2ExtendV2: `0x368d13376443a8051b22b42a9125f6a3bc836422bb2d9c4a53984b8d6624c326`
|
|
97
|
+
- CetusAggregatorSimple: `0x594d67abc0778023ac852800578271dd7e18698ad06e6298034858c77612333d`
|
|
98
|
+
|
|
99
|
+
### Environment Setup
|
|
100
|
+
|
|
101
|
+
The SDK works with Sui mainnet and testnet environments via the `Env` enum. Configure clients with appropriate RPC endpoints and package configurations for the target network.
|
package/dist/index.d.mts
CHANGED
|
@@ -627,7 +627,7 @@ declare const SuiZeroCoinFn = "0x2::coin::zero";
|
|
|
627
627
|
declare const DEEPBOOK_PACKAGE_ID = "0x000000000000000000000000000000000000000000000000000000000000dee9";
|
|
628
628
|
declare const DEEPBOOK_PUBLISHED_AT = "0x000000000000000000000000000000000000000000000000000000000000dee9";
|
|
629
629
|
declare const CETUS_PUBLISHED_AT = "0x70968826ad1b4ba895753f634b0aea68d0672908ca1075a2abdf0fc9e0b2fc6a";
|
|
630
|
-
declare const CETUS_V3_PUBLISHED_AT = "
|
|
630
|
+
declare const CETUS_V3_PUBLISHED_AT = "0xb1e11ceaf3e7cd3031ef5e24804478ec3441c5aecdace910bdaca317a0c1c535";
|
|
631
631
|
declare const MAINNET_CETUS_GLOBAL_CONFIG_ID = "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f";
|
|
632
632
|
declare const TESTNET_CETUS_GLOBAL_CONFIG_ID = "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a";
|
|
633
633
|
declare const MAINNET_FLOWX_AMM_CONTAINER_ID = "0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511";
|
|
@@ -679,9 +679,9 @@ declare const DEEPBOOK_V3_DEEP_FEE_TYPES: {
|
|
|
679
679
|
declare const CLIENT_CONFIG: {
|
|
680
680
|
readonly DEFAULT_PYTH_URL: "https://hermes.pyth.network";
|
|
681
681
|
readonly PYTH_TIMEOUT: 3000;
|
|
682
|
-
readonly
|
|
682
|
+
readonly MAX_OVERLAY_FEE_RATE: 0.1;
|
|
683
|
+
readonly MAX_OVERLAY_FEE_RATE_NUMERATOR: 100000;
|
|
683
684
|
readonly FEE_RATE_MULTIPLIER: 1000000;
|
|
684
|
-
readonly MAX_FEE_RATE: 100000;
|
|
685
685
|
readonly DEFAULT_OVERLAY_FEE_RECEIVER: "0x0";
|
|
686
686
|
readonly ERRORS: {
|
|
687
687
|
readonly SIGNER_REQUIRED: "Signer is required, but not provided.";
|
|
@@ -702,7 +702,7 @@ declare const AGGREGATOR_V3_CONFIG: {
|
|
|
702
702
|
readonly MAX_FEE_RATE: 100000;
|
|
703
703
|
readonly MAX_AMOUNT_IN: "18446744073709551615";
|
|
704
704
|
readonly DEFAULT_PUBLISHED_AT: {
|
|
705
|
-
readonly Mainnet: "
|
|
705
|
+
readonly Mainnet: "0x33ec64e9bb369bf045ddc198c81adbf2acab424da37465d95296ee02045d2b17";
|
|
706
706
|
readonly Testnet: "0x0";
|
|
707
707
|
};
|
|
708
708
|
};
|
|
@@ -794,7 +794,7 @@ declare const GAS_TYPE_ARG = "0x2::sui::SUI";
|
|
|
794
794
|
declare const GAS_TYPE_ARG_LONG = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
|
|
795
795
|
declare const GAS_SYMBOL = "SUI";
|
|
796
796
|
declare const DEFAULT_NFT_TRANSFER_GAS_FEE = 450;
|
|
797
|
-
declare const SUI_SYSTEM_STATE_OBJECT_ID = "
|
|
797
|
+
declare const SUI_SYSTEM_STATE_OBJECT_ID = "0x0000000000000000000000000000000000000005";
|
|
798
798
|
/**
|
|
799
799
|
* This class provides helper methods for working with coins.
|
|
800
800
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -627,7 +627,7 @@ declare const SuiZeroCoinFn = "0x2::coin::zero";
|
|
|
627
627
|
declare const DEEPBOOK_PACKAGE_ID = "0x000000000000000000000000000000000000000000000000000000000000dee9";
|
|
628
628
|
declare const DEEPBOOK_PUBLISHED_AT = "0x000000000000000000000000000000000000000000000000000000000000dee9";
|
|
629
629
|
declare const CETUS_PUBLISHED_AT = "0x70968826ad1b4ba895753f634b0aea68d0672908ca1075a2abdf0fc9e0b2fc6a";
|
|
630
|
-
declare const CETUS_V3_PUBLISHED_AT = "
|
|
630
|
+
declare const CETUS_V3_PUBLISHED_AT = "0xb1e11ceaf3e7cd3031ef5e24804478ec3441c5aecdace910bdaca317a0c1c535";
|
|
631
631
|
declare const MAINNET_CETUS_GLOBAL_CONFIG_ID = "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f";
|
|
632
632
|
declare const TESTNET_CETUS_GLOBAL_CONFIG_ID = "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a";
|
|
633
633
|
declare const MAINNET_FLOWX_AMM_CONTAINER_ID = "0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511";
|
|
@@ -679,9 +679,9 @@ declare const DEEPBOOK_V3_DEEP_FEE_TYPES: {
|
|
|
679
679
|
declare const CLIENT_CONFIG: {
|
|
680
680
|
readonly DEFAULT_PYTH_URL: "https://hermes.pyth.network";
|
|
681
681
|
readonly PYTH_TIMEOUT: 3000;
|
|
682
|
-
readonly
|
|
682
|
+
readonly MAX_OVERLAY_FEE_RATE: 0.1;
|
|
683
|
+
readonly MAX_OVERLAY_FEE_RATE_NUMERATOR: 100000;
|
|
683
684
|
readonly FEE_RATE_MULTIPLIER: 1000000;
|
|
684
|
-
readonly MAX_FEE_RATE: 100000;
|
|
685
685
|
readonly DEFAULT_OVERLAY_FEE_RECEIVER: "0x0";
|
|
686
686
|
readonly ERRORS: {
|
|
687
687
|
readonly SIGNER_REQUIRED: "Signer is required, but not provided.";
|
|
@@ -702,7 +702,7 @@ declare const AGGREGATOR_V3_CONFIG: {
|
|
|
702
702
|
readonly MAX_FEE_RATE: 100000;
|
|
703
703
|
readonly MAX_AMOUNT_IN: "18446744073709551615";
|
|
704
704
|
readonly DEFAULT_PUBLISHED_AT: {
|
|
705
|
-
readonly Mainnet: "
|
|
705
|
+
readonly Mainnet: "0x33ec64e9bb369bf045ddc198c81adbf2acab424da37465d95296ee02045d2b17";
|
|
706
706
|
readonly Testnet: "0x0";
|
|
707
707
|
};
|
|
708
708
|
};
|
|
@@ -794,7 +794,7 @@ declare const GAS_TYPE_ARG = "0x2::sui::SUI";
|
|
|
794
794
|
declare const GAS_TYPE_ARG_LONG = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
|
|
795
795
|
declare const GAS_SYMBOL = "SUI";
|
|
796
796
|
declare const DEFAULT_NFT_TRANSFER_GAS_FEE = 450;
|
|
797
|
-
declare const SUI_SYSTEM_STATE_OBJECT_ID = "
|
|
797
|
+
declare const SUI_SYSTEM_STATE_OBJECT_ID = "0x0000000000000000000000000000000000000005";
|
|
798
798
|
/**
|
|
799
799
|
* This class provides helper methods for working with coins.
|
|
800
800
|
*/
|
package/dist/index.js
CHANGED
|
@@ -2999,7 +2999,7 @@ var GAS_TYPE_ARG = "0x2::sui::SUI";
|
|
|
2999
2999
|
var GAS_TYPE_ARG_LONG = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
|
|
3000
3000
|
var GAS_SYMBOL = "SUI";
|
|
3001
3001
|
var DEFAULT_NFT_TRANSFER_GAS_FEE = 450;
|
|
3002
|
-
var SUI_SYSTEM_STATE_OBJECT_ID = "
|
|
3002
|
+
var SUI_SYSTEM_STATE_OBJECT_ID = "0x0000000000000000000000000000000000000005";
|
|
3003
3003
|
var CoinUtils = class _CoinUtils {
|
|
3004
3004
|
/**
|
|
3005
3005
|
* Get the coin type argument from a SuiMoveObject.
|
|
@@ -3107,18 +3107,10 @@ var CoinUtils = class _CoinUtils {
|
|
|
3107
3107
|
* @returns The CoinAsset objects that have a balance greater than or equal to the given amount.
|
|
3108
3108
|
*/
|
|
3109
3109
|
static selectCoinObjectIdGreaterThanOrEqual(coins, amount, exclude = []) {
|
|
3110
|
-
const selectedResult = _CoinUtils.selectCoinAssetGreaterThanOrEqual(
|
|
3111
|
-
|
|
3112
|
-
amount,
|
|
3113
|
-
exclude
|
|
3114
|
-
);
|
|
3115
|
-
const objectArray = selectedResult.selectedCoins.map(
|
|
3116
|
-
(item) => item.coinObjectId
|
|
3117
|
-
);
|
|
3110
|
+
const selectedResult = _CoinUtils.selectCoinAssetGreaterThanOrEqual(coins, amount, exclude);
|
|
3111
|
+
const objectArray = selectedResult.selectedCoins.map((item) => item.coinObjectId);
|
|
3118
3112
|
const remainCoins = selectedResult.remainingCoins;
|
|
3119
|
-
const amountArray = selectedResult.selectedCoins.map(
|
|
3120
|
-
(item) => item.balance.toString()
|
|
3121
|
-
);
|
|
3113
|
+
const amountArray = selectedResult.selectedCoins.map((item) => item.balance.toString());
|
|
3122
3114
|
return { objectArray, remainCoins, amountArray };
|
|
3123
3115
|
}
|
|
3124
3116
|
/**
|
|
@@ -3130,9 +3122,7 @@ var CoinUtils = class _CoinUtils {
|
|
|
3130
3122
|
* @returns The CoinAsset objects that have a balance greater than or equal to the given amount.
|
|
3131
3123
|
*/
|
|
3132
3124
|
static selectCoinAssetGreaterThanOrEqual(coins, amount, exclude = []) {
|
|
3133
|
-
const sortedCoins = _CoinUtils.sortByBalance(
|
|
3134
|
-
coins.filter((c) => !exclude.includes(c.coinObjectId))
|
|
3135
|
-
);
|
|
3125
|
+
const sortedCoins = _CoinUtils.sortByBalance(coins.filter((c) => !exclude.includes(c.coinObjectId)));
|
|
3136
3126
|
const total = _CoinUtils.calculateTotalBalance(sortedCoins);
|
|
3137
3127
|
if (total < amount) {
|
|
3138
3128
|
return { selectedCoins: [], remainingCoins: sortedCoins };
|
|
@@ -3145,13 +3135,9 @@ var CoinUtils = class _CoinUtils {
|
|
|
3145
3135
|
const remainingCoins = [...sortedCoins];
|
|
3146
3136
|
while (sum2 < total) {
|
|
3147
3137
|
const target = amount - sum2;
|
|
3148
|
-
const coinWithSmallestSufficientBalanceIndex = remainingCoins.findIndex(
|
|
3149
|
-
(c) => c.balance >= target
|
|
3150
|
-
);
|
|
3138
|
+
const coinWithSmallestSufficientBalanceIndex = remainingCoins.findIndex((c) => c.balance >= target);
|
|
3151
3139
|
if (coinWithSmallestSufficientBalanceIndex !== -1) {
|
|
3152
|
-
selectedCoins.push(
|
|
3153
|
-
remainingCoins[coinWithSmallestSufficientBalanceIndex]
|
|
3154
|
-
);
|
|
3140
|
+
selectedCoins.push(remainingCoins[coinWithSmallestSufficientBalanceIndex]);
|
|
3155
3141
|
remainingCoins.splice(coinWithSmallestSufficientBalanceIndex, 1);
|
|
3156
3142
|
break;
|
|
3157
3143
|
}
|
|
@@ -3161,10 +3147,7 @@ var CoinUtils = class _CoinUtils {
|
|
|
3161
3147
|
sum2 += coinWithLargestBalance.balance;
|
|
3162
3148
|
}
|
|
3163
3149
|
}
|
|
3164
|
-
return {
|
|
3165
|
-
selectedCoins: _CoinUtils.sortByBalance(selectedCoins),
|
|
3166
|
-
remainingCoins: _CoinUtils.sortByBalance(remainingCoins)
|
|
3167
|
-
};
|
|
3150
|
+
return { selectedCoins: _CoinUtils.sortByBalance(selectedCoins), remainingCoins: _CoinUtils.sortByBalance(remainingCoins) };
|
|
3168
3151
|
}
|
|
3169
3152
|
/**
|
|
3170
3153
|
* Sort the CoinAsset objects by their balance.
|
|
@@ -3173,14 +3156,10 @@ var CoinUtils = class _CoinUtils {
|
|
|
3173
3156
|
* @returns The sorted CoinAsset objects.
|
|
3174
3157
|
*/
|
|
3175
3158
|
static sortByBalance(coins) {
|
|
3176
|
-
return coins.sort(
|
|
3177
|
-
(a, b) => a.balance < b.balance ? -1 : a.balance > b.balance ? 1 : 0
|
|
3178
|
-
);
|
|
3159
|
+
return coins.sort((a, b) => a.balance < b.balance ? -1 : a.balance > b.balance ? 1 : 0);
|
|
3179
3160
|
}
|
|
3180
3161
|
static sortByBalanceDes(coins) {
|
|
3181
|
-
return coins.sort(
|
|
3182
|
-
(a, b) => a.balance > b.balance ? -1 : a.balance < b.balance ? 0 : 1
|
|
3183
|
-
);
|
|
3162
|
+
return coins.sort((a, b) => a.balance > b.balance ? -1 : a.balance < b.balance ? 0 : 1);
|
|
3184
3163
|
}
|
|
3185
3164
|
/**
|
|
3186
3165
|
* Calculate the total balance of a list of CoinAsset objects.
|
|
@@ -3361,7 +3340,7 @@ var SuiZeroCoinFn = "0x2::coin::zero";
|
|
|
3361
3340
|
var DEEPBOOK_PACKAGE_ID = "0x000000000000000000000000000000000000000000000000000000000000dee9";
|
|
3362
3341
|
var DEEPBOOK_PUBLISHED_AT = "0x000000000000000000000000000000000000000000000000000000000000dee9";
|
|
3363
3342
|
var CETUS_PUBLISHED_AT = "0x70968826ad1b4ba895753f634b0aea68d0672908ca1075a2abdf0fc9e0b2fc6a";
|
|
3364
|
-
var CETUS_V3_PUBLISHED_AT = "
|
|
3343
|
+
var CETUS_V3_PUBLISHED_AT = "0xb1e11ceaf3e7cd3031ef5e24804478ec3441c5aecdace910bdaca317a0c1c535";
|
|
3365
3344
|
var MAINNET_CETUS_GLOBAL_CONFIG_ID = "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f";
|
|
3366
3345
|
var TESTNET_CETUS_GLOBAL_CONFIG_ID = "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a";
|
|
3367
3346
|
var MAINNET_FLOWX_AMM_CONTAINER_ID = "0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511";
|
|
@@ -3418,9 +3397,9 @@ var DEEPBOOK_V3_DEEP_FEE_TYPES = {
|
|
|
3418
3397
|
var CLIENT_CONFIG = {
|
|
3419
3398
|
DEFAULT_PYTH_URL: "https://hermes.pyth.network",
|
|
3420
3399
|
PYTH_TIMEOUT: 3e3,
|
|
3421
|
-
|
|
3400
|
+
MAX_OVERLAY_FEE_RATE: 0.1,
|
|
3401
|
+
MAX_OVERLAY_FEE_RATE_NUMERATOR: 1e5,
|
|
3422
3402
|
FEE_RATE_MULTIPLIER: 1e6,
|
|
3423
|
-
MAX_FEE_RATE: 1e5,
|
|
3424
3403
|
DEFAULT_OVERLAY_FEE_RECEIVER: "0x0",
|
|
3425
3404
|
// Error Messages
|
|
3426
3405
|
ERRORS: {
|
|
@@ -3443,13 +3422,13 @@ var AGGREGATOR_V3_CONFIG = {
|
|
|
3443
3422
|
// 10%
|
|
3444
3423
|
MAX_AMOUNT_IN: U64_MAX,
|
|
3445
3424
|
DEFAULT_PUBLISHED_AT: {
|
|
3446
|
-
Mainnet: "
|
|
3425
|
+
Mainnet: "0x33ec64e9bb369bf045ddc198c81adbf2acab424da37465d95296ee02045d2b17",
|
|
3447
3426
|
Testnet: "0x0"
|
|
3448
3427
|
}
|
|
3449
3428
|
};
|
|
3450
3429
|
|
|
3451
3430
|
// src/api.ts
|
|
3452
|
-
var SDK_VERSION =
|
|
3431
|
+
var SDK_VERSION = 1010105;
|
|
3453
3432
|
function parseRouterResponse(data, byAmountIn) {
|
|
3454
3433
|
let packages = /* @__PURE__ */ new Map();
|
|
3455
3434
|
if (data.packages) {
|
|
@@ -3612,7 +3591,6 @@ function getRouter(endpoint, apiKey, params) {
|
|
|
3612
3591
|
url += `&apiKey=${apiKey}`;
|
|
3613
3592
|
}
|
|
3614
3593
|
url += `&v=${SDK_VERSION}`;
|
|
3615
|
-
console.log("url", url);
|
|
3616
3594
|
const response = yield fetch(url);
|
|
3617
3595
|
return response;
|
|
3618
3596
|
} catch (error) {
|
|
@@ -3703,7 +3681,6 @@ function processFlattenRoutes(routerData) {
|
|
|
3703
3681
|
flattenedPaths[i].isLastUseOfIntermediateToken = true;
|
|
3704
3682
|
}
|
|
3705
3683
|
}
|
|
3706
|
-
console.log("flattenedPaths", flattenedPaths);
|
|
3707
3684
|
return {
|
|
3708
3685
|
quoteID: routerData.quoteID || "",
|
|
3709
3686
|
amountIn: routerData.amountIn,
|
|
@@ -6719,7 +6696,7 @@ var SpringsuiRouter = class {
|
|
|
6719
6696
|
const args = [
|
|
6720
6697
|
swapContext,
|
|
6721
6698
|
txb.object(swapData.poolId),
|
|
6722
|
-
txb.object(
|
|
6699
|
+
txb.object("0x5"),
|
|
6723
6700
|
txb.pure.u64(swapData.amountIn),
|
|
6724
6701
|
txb.pure.bool(swapData.direction)
|
|
6725
6702
|
];
|
|
@@ -7401,7 +7378,8 @@ var VoloRouter = class {
|
|
|
7401
7378
|
swapContext,
|
|
7402
7379
|
txb.object(this.stakePool),
|
|
7403
7380
|
txb.object(this.metadata),
|
|
7404
|
-
txb.object(
|
|
7381
|
+
txb.object("0x5"),
|
|
7382
|
+
// SuiSystemState
|
|
7405
7383
|
txb.pure.bool(swapData.direction),
|
|
7406
7384
|
txb.pure.u64(swapData.amountIn)
|
|
7407
7385
|
];
|
|
@@ -7452,7 +7430,8 @@ var AfsuiRouter = class {
|
|
|
7452
7430
|
swapContext,
|
|
7453
7431
|
txb.object(this.stakedSuiVault),
|
|
7454
7432
|
txb.object(this.safe),
|
|
7455
|
-
txb.object(
|
|
7433
|
+
txb.object("0x5"),
|
|
7434
|
+
// SuiSystemState
|
|
7456
7435
|
txb.object(this.referVault),
|
|
7457
7436
|
txb.object(this.validator),
|
|
7458
7437
|
txb.pure.bool(swapData.direction),
|
|
@@ -7497,7 +7476,8 @@ var HaedalRouter = class {
|
|
|
7497
7476
|
const args = [
|
|
7498
7477
|
swapContext,
|
|
7499
7478
|
txb.object(swapData.poolId),
|
|
7500
|
-
txb.object(
|
|
7479
|
+
txb.object("0x5"),
|
|
7480
|
+
// SuiSystemState
|
|
7501
7481
|
txb.pure.bool(swapData.direction),
|
|
7502
7482
|
txb.pure.u64(swapData.amountIn)
|
|
7503
7483
|
];
|
|
@@ -8256,7 +8236,7 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8256
8236
|
this.apiKey = params.apiKey || "";
|
|
8257
8237
|
this.partner = params.partner;
|
|
8258
8238
|
if (params.overlayFeeRate) {
|
|
8259
|
-
if (params.overlayFeeRate > 0 && params.overlayFeeRate <= CLIENT_CONFIG.
|
|
8239
|
+
if (params.overlayFeeRate > 0 && params.overlayFeeRate <= CLIENT_CONFIG.MAX_OVERLAY_FEE_RATE) {
|
|
8260
8240
|
this.overlayFeeRate = params.overlayFeeRate * AGGREGATOR_V3_CONFIG.FEE_DENOMINATOR;
|
|
8261
8241
|
if (this.overlayFeeRate > AGGREGATOR_V3_CONFIG.MAX_FEE_RATE) {
|
|
8262
8242
|
throw new Error(
|
|
@@ -8897,7 +8877,7 @@ function recordFirstCoinIndex(paths) {
|
|
|
8897
8877
|
return newCoinRecord;
|
|
8898
8878
|
}
|
|
8899
8879
|
function checkOverlayFeeConfig(overlayFeeRate, overlayFeeReceiver) {
|
|
8900
|
-
if (overlayFeeRate > CLIENT_CONFIG.
|
|
8880
|
+
if (overlayFeeRate > CLIENT_CONFIG.MAX_OVERLAY_FEE_RATE_NUMERATOR) {
|
|
8901
8881
|
throw new Error(CLIENT_CONFIG.ERRORS.INVALID_OVERLAY_FEE_RATE);
|
|
8902
8882
|
}
|
|
8903
8883
|
if (overlayFeeReceiver === "0x0" && overlayFeeRate > 0) {
|