@mmt-finance/amm-sui-sdk 0.0.1-beta

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/.eslintrc.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "env": {
3
+ "browser": true,
4
+ "es2021": true,
5
+ "node": true
6
+ },
7
+ "extends": [
8
+ "eslint:recommended",
9
+ "plugin:@typescript-eslint/recommended",
10
+ "prettier"
11
+ ],
12
+ "parser": "@typescript-eslint/parser",
13
+ "parserOptions": {
14
+ "ecmaVersion": "latest",
15
+ "sourceType": "module"
16
+ },
17
+ "plugins": ["@typescript-eslint"],
18
+ "rules": {
19
+ "@typescript-eslint/no-explicit-any": "warn",
20
+ "@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }]
21
+ }
22
+ }
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env sh
2
+ . "$(dirname -- "$0")/_/husky.sh"
3
+
4
+ npx --no -- commitlint --edit ${1}
package/.prettierrc ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "semi": true,
3
+ "trailingComma": "all",
4
+ "singleQuote": true,
5
+ "printWidth": 100,
6
+ "tabWidth": 2
7
+ }
package/README.md ADDED
@@ -0,0 +1,206 @@
1
+ # AMM Sui SDK
2
+
3
+ The Momentum SDK provides access to the Momentum DeFi protocols suite on Sui.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @mmt-finance/amm-sui-sdk
9
+ # or
10
+ bun add @mmt-finance/amm-sui-sdk
11
+ ```
12
+
13
+ ### Initialization
14
+
15
+ Initialize the SDK with your RPC endpoint and preferred network ('mainnet' | 'testnet').
16
+
17
+ ```typescript
18
+ import { MmtAmmSdk } from '@mmt-finance/amm-sui-sdk';
19
+
20
+ // Initialize for Mainnet
21
+ const sdk = new MmtAmmSdk({
22
+ network: 'mainnet',
23
+ rpcEndpoint: 'https://fullnode.mainnet.sui.io:443',
24
+ });
25
+
26
+ // Or Initialize for Testnet
27
+ const testnetSdk = new MmtAmmSdk({
28
+ network: 'testnet',
29
+ rpcEndpoint: 'https://fullnode.testnet.sui.io:443',
30
+ });
31
+
32
+ // Legacy initialization (defaults to mainnet) is also supported:
33
+ // const sdk = new MmtAmmSdk('https://fullnode.mainnet.sui.io:443');
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ ### 1. Create Pool
39
+
40
+ Create a new Liquidity Pool.
41
+
42
+ ```typescript
43
+ const txb = new Transaction();
44
+
45
+ sdk.createPool({
46
+ isStable: false, // true for stable pool, false for uncorrelated
47
+ decimalsX: 9, // Decimals for Token X
48
+ decimalsY: 6, // Decimals for Token Y
49
+ txb,
50
+ typeX: '0x...::coin::X',
51
+ typeY: '0x...::coin::Y',
52
+ });
53
+
54
+ // Sign and execute `txb`
55
+ ```
56
+
57
+ ### 2. Create Pool and Add Liquidity (Single Transaction)
58
+
59
+ Create a pool and add initial liquidity in the same transaction block.
60
+
61
+ ```typescript
62
+ const txb = new Transaction();
63
+
64
+ sdk.createPoolAndAddLiquidity({
65
+ isStable: false,
66
+ decimalsX: 9,
67
+ decimalsY: 6,
68
+ txb,
69
+ typeX: '0x...::coin::X',
70
+ typeY: '0x...::coin::Y',
71
+ // Liquidity Parameters
72
+ minAddAmountX: 90000000n, // Min amount of X to add (slippage)
73
+ minAddAmountY: 90000000n, // Min amount of Y to add (slippage)
74
+ coinX: '0x...' | TransactionArgument, // Coin Object ID or Argument (Full balance used)
75
+ coinY: '0x...' | TransactionArgument, // Coin Object ID or Argument (Full balance used)
76
+ // Optional: transferToAddress is supported in addLiquidity but strictly speaking createPoolAndAddLiquidity returns void/shares to sender in current SDK impl unless wrapper handles it.
77
+ // Checking SDK impl: returns undefined. Transfers to sender.
78
+ // SDK code removed transferToAddress from options in step 305?
79
+ // Let's check step 305 diff. Yes, transferToAddress was removed from interface.
80
+ // So I should remove it from README too.
81
+ });
82
+ ```
83
+
84
+ ### 3. Basic Swap
85
+
86
+ Perform a swap between two tokens in a specific pool.
87
+
88
+ ```typescript
89
+ const txb = new Transaction();
90
+
91
+ sdk.swap({
92
+ pool, // Pool object
93
+ inputCoinType: '0x...::coin::X',
94
+ inputCoinAmount: 1000000n,
95
+ inputCoin: txb.gas, // or other coin object
96
+ minReceived: 0n,
97
+ txb,
98
+ transferToAddress: '0x...',
99
+ });
100
+ ```
101
+
102
+ ### 4. Swap with Route
103
+
104
+ Perform a multi-hop swap across multiple pools.
105
+
106
+ ```typescript
107
+ const txb = new Transaction();
108
+
109
+ sdk.swapWithRoute({
110
+ pools: [pool1, pool2], // Array of Pool objects forming the route
111
+ inputCoinType: '0x...::coin::X',
112
+ inputCoinAmount: 1000000n,
113
+ inputCoin: txb.gas,
114
+ minReceived: 0n,
115
+ txb,
116
+ transferToAddress: '0x...',
117
+ });
118
+ ```
119
+
120
+ ### 5. Add Liquidity
121
+
122
+ Add liquidity to a pool (requires both tokens).
123
+
124
+ ```typescript
125
+ const txb = new Transaction();
126
+
127
+ sdk.addLiquidity({
128
+ pool,
129
+ amountX: 1000000n,
130
+ amountY: 2000000n,
131
+ minAddAmountX: 900000n,
132
+ minAddAmountY: 1800000n,
133
+ coinX: coinXObject,
134
+ coinY: coinYObject,
135
+ txb,
136
+ transferToAddress: '0x...',
137
+ });
138
+ ```
139
+
140
+ ### 6. Single Sided Add Liquidity
141
+
142
+ Add liquidity using only one type of token. The SDK will automatically swap the necessary amount to match the pool ratio.
143
+
144
+ ```typescript
145
+ const txb = new Transaction();
146
+
147
+ await sdk.addLiquiditySingleSided({
148
+ pool,
149
+ inputCoinType: '0x...::coin::X',
150
+ inputCoinAmount: 1000000n,
151
+ inputCoin: coinXObject,
152
+ tokenInDecimals: 9,
153
+ tokenOutDecimals: 6,
154
+ swapSlippageTolerance: 0.05, // 5%
155
+ txb,
156
+ transferToAddress: '0x...',
157
+ });
158
+ ```
159
+
160
+ ### 7. Remove Liquidity
161
+
162
+ Remove liquidity from a pool by burning LP tokens.
163
+
164
+ ```typescript
165
+ const txb = new Transaction();
166
+
167
+ sdk.removeLiquidity({
168
+ pool,
169
+ amount: 500000n,
170
+ mmtLpToken: lpTokenObject,
171
+ txb,
172
+ transferToAddress: '0x...',
173
+ });
174
+ ```
175
+
176
+ ### 8. Helper: Get User LP Positions
177
+
178
+ Fetch all LP positions for a specific user and pool.
179
+
180
+ ```typescript
181
+ const positions = await sdk.getUserLpPositions({
182
+ pool,
183
+ userAddress: '0x...',
184
+ });
185
+ ```
186
+
187
+ ## Types
188
+
189
+ Key interfaces used in the SDK:
190
+
191
+ - **Pool**: Represents an AMM pool state.
192
+ - **CreatePoolOptions**: Options for creating a pool.
193
+ - **CreatePoolAndAddLiquidityOptions**: Options for creating a pool with initial liquidity.
194
+ - **SwapOptions / SwapWithRouteOptions**: Options for swapping.
195
+ - **AddLiquidityOptions / RemoveLiquidityOptions**: Options for liquidity management.
196
+
197
+ Import them from:
198
+
199
+ ```typescript
200
+ import {
201
+ Pool,
202
+ CreatePoolOptions,
203
+ CreatePoolAndAddLiquidityOptions,
204
+ SwapOptions,
205
+ } from '@mmt-finance/amm-sui-sdk';
206
+ ```