Skip to content

Commit 28e5a31

Browse files
committed
fix lints
1 parent 15c1bb6 commit 28e5a31

File tree

4 files changed

+286
-29
lines changed

4 files changed

+286
-29
lines changed

packages/sui-agent/src/@types/interface.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,10 @@ export const NETWORK_CONFIG: NetworkConfigs = {
205205
faucet: 'https://faucet.testnet.sui.io/gas',
206206
},
207207
};
208+
209+
interface Liquidation {
210+
user: string;
211+
liquidation_sender: string;
212+
[key: string]: unknown; // Uses unknown instead of any
213+
}
214+
export type { Liquidation };

packages/sui-agent/src/protocols/navi/index.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { NAVISDKClient } from 'navi-sdk';
22
import { handleError } from '../../utils';
33
import sentioApi from '../../config/sentio';
4+
import { Liquidation } from '../../@types/interface';
45
// Initialize NAVI SDK client
56
let naviClient: NAVISDKClient | null = null;
67

@@ -14,7 +15,7 @@ let naviClient: NAVISDKClient | null = null;
1415
export async function initializeNaviClient(
1516
...args: (string | number | bigint | boolean)[]
1617
): Promise<string> {
17-
let [mnemonic, networkType, numberOfAccounts] = args as [
18+
const [mnemonic, networkType, numberOfAccounts] = args as [
1819
string,
1920
string,
2021
number,
@@ -26,7 +27,7 @@ export async function initializeNaviClient(
2627
networkType,
2728
numberOfAccounts: numberOfAccounts || 5,
2829
});
29-
let account = naviClient.accounts[0];
30+
const account = naviClient.accounts[0];
3031
return JSON.stringify([
3132
{
3233
reasoning: 'Successfully initialized NAVI SDK client',
@@ -127,9 +128,11 @@ async function checkUserLiquidations(address: string) {
127128
const liquidations = response.data;
128129
console.log(liquidations.result.rows, 'liquidations');
129130
return {
130-
asUser: liquidations.result.rows.filter((l: any) => l.user === address),
131+
asUser: liquidations.result.rows.filter(
132+
(l: Liquidation) => l.user === address,
133+
),
131134
asLiquidator: liquidations.result.rows.filter(
132-
(l: any) => l.liquidation_sender === address,
135+
(l: Liquidation) => l.liquidation_sender === address,
133136
),
134137
totalLiquidations: liquidations.length,
135138
};
@@ -148,8 +151,16 @@ async function checkUserLiquidations(address: string) {
148151
}
149152
export async function checkUserLiquidationStatusTool(
150153
...args: (string | number | bigint | boolean)[]
151-
): Promise<any> {
154+
): Promise<string> {
152155
const [walletAddress] = args as [string];
153-
return checkUserLiquidations(walletAddress);
156+
const result = await checkUserLiquidations(walletAddress);
157+
return JSON.stringify([
158+
{
159+
reasoning: 'Successfully retrieved liquidation status',
160+
response: JSON.stringify(result),
161+
status: 'success',
162+
query: `Check liquidation status for ${walletAddress}`,
163+
errors: [],
164+
},
165+
]);
154166
}
155-
// Add more NAVI-specific functions here...

packages/sui-agent/src/utils/tools.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,3 @@ class Tools {
8787
}
8888

8989
export default Tools;
90-
91-
// tools.registerTool("Tool 1", "Description of Tool 1", () => {
92-
// return "Tool 1 has been processed successfully.";
93-
// });
94-
// tools.registerTool("Tool 2", "Description of Tool 2", () => {
95-
// return "Tool 2 has been processed successfully.";
96-
// });
97-
// tools.registerTool("Tool 3", "Description of Tool 3", () => {
98-
// return "Tool 3 has been processed successfully.";
99-
// });
100-
101-
// // Selecting a tool based on query
102-
// const query = "Tool 1";
103-
// const selectedTool = tools.selectAppropriateTool(query);
104-
105-
// if (selectedTool) {
106-
// console.log(`Selected Tool: ${selectedTool.name}`);
107-
// const result = selectedTool.process(); // Running the tool's process method
108-
// console.log(result); // Output similar format for all tools
109-
// } else {
110-
// console.log("No tool found for the query.");
111-
// }

pool.md

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
Pools
2+
AMM pools for both stable and uncorrelated assets of variable weights with up to 8 assets per pool.
3+
4+
A comprehensive system for managing liquidity pools, trades, and LP tokens in the Aftermath Finance protocol.
5+
6+
Initialization
7+
Copy
8+
const afSdk = new Aftermath("MAINNET");
9+
await afSdk.init(); // initialize provider
10+
11+
const pools = afSdk.Pools();
12+
Constants
13+
Copy
14+
Pools.constants = {
15+
feePercentages: {
16+
totalProtocol: 0.00005, // 0.005%
17+
treasury: 0.5, // 50% of protocol fees
18+
insuranceFund: 0.3, // 30% of protocol fees
19+
devWallet: 0.2, // 20% of protocol fees
20+
},
21+
referralPercentages: {
22+
discount: 0.05, // 5% of treasury fees
23+
rebate: 0.05, // 5% of treasury fees
24+
},
25+
bounds: {
26+
maxCoinsInPool: 8,
27+
maxTradePercentageOfPoolBalance: 0.3, // 30%
28+
maxWithdrawPercentageOfPoolBalance: 0.3, // 30%
29+
minSwapFee: 0.0001, // 0.01%
30+
maxSwapFee: 0.1, // 10%
31+
minWeight: 0.01, // 1%
32+
maxWeight: 0.99, // 99%
33+
minDaoFee: 0, // 0%
34+
maxDaoFee: 1, // 100%
35+
},
36+
defaults: {
37+
lpCoinDecimals: 9,
38+
},
39+
};
40+
Pool Management Methods
41+
Getting Pool Information
42+
Copy
43+
// Get a single pool
44+
const pool = await pools.getPool({
45+
objectId: "0x...",
46+
});
47+
48+
// Get multiple pools
49+
const somePools = await pools.getPools({
50+
objectIds: ["0x...", "0x..."],
51+
});
52+
53+
// Get all pools
54+
const allPools = await pools.getAllPools();
55+
56+
// Get owned LP coins
57+
const lpCoins = await pools.getOwnedLpCoins({
58+
walletAddress: "0x...",
59+
});
60+
Pool Creation and Publishing
61+
Copy
62+
// Publish new LP coin
63+
const publishTx = await pools.getPublishLpCoinTransaction({
64+
walletAddress: "0x...",
65+
lpCoinDecimals: 9,
66+
});
67+
68+
// Create new pool
69+
const createPoolTx = await pools.getCreatePoolTransaction({
70+
walletAddress: "0x...",
71+
lpCoinType: "0x...",
72+
lpCoinMetadata: {
73+
name: "My Pool LP",
74+
symbol: "MLP",
75+
},
76+
coinsInfo: [
77+
{
78+
coinType: "0x...",
79+
weight: 0.5,
80+
decimals: 9,
81+
tradeFeeIn: 0.003,
82+
initialDeposit: BigInt("1000000000"),
83+
},
84+
],
85+
poolName: "My Pool",
86+
poolFlatness: 0,
87+
createPoolCapId: "0x...",
88+
respectDecimals: true,
89+
});
90+
Pool Information Queries
91+
Copy
92+
// Get pool object ID from LP coin type
93+
const poolId = await pools.getPoolObjectIdForLpCoinType({
94+
lpCoinType: "0x...",
95+
});
96+
97+
// Check if coin type is LP token
98+
const isLp = await pools.isLpCoinType({
99+
lpCoinType: "0x...",
100+
});
101+
102+
// Get 24h volume
103+
const volume = await pools.getTotalVolume24hrs();
104+
105+
// Get pool statistics
106+
const stats = await pools.getPoolsStats({
107+
poolIds: ["0x..."],
108+
});
109+
Pool Class Methods
110+
The Pool class provides methods for interacting with individual pools.
111+
112+
Trading and Liquidity Operations
113+
Copy
114+
const pool = new Pool(poolObject);
115+
116+
// Trade
117+
const tradeTx = await pool.getTradeTransaction({
118+
walletAddress: "0x...",
119+
coinInType: "0x...",
120+
coinInAmount: BigInt("1000000"),
121+
coinOutType: "0x...",
122+
slippage: 0.01,
123+
});
124+
125+
// Deposit
126+
const depositTx = await pool.getDepositTransaction({
127+
walletAddress: "0x...",
128+
amountsIn: {
129+
"0x...": BigInt("1000000"),
130+
},
131+
slippage: 0.01,
132+
});
133+
134+
// Withdraw
135+
const withdrawTx = await pool.getWithdrawTransaction({
136+
walletAddress: "0x...",
137+
amountsOutDirection: {
138+
"0x...": BigInt("1000000"),
139+
},
140+
lpCoinAmount: BigInt("1000000"),
141+
slippage: 0.01,
142+
});
143+
144+
// Multi-coin withdraw
145+
const multiWithdrawTx = await pool.getAllCoinWithdrawTransaction({
146+
walletAddress: "0x...",
147+
lpCoinAmount: BigInt("1000000"),
148+
});
149+
Price and Amount Calculations
150+
Copy
151+
// Get spot price
152+
const spotPrice = pool.getSpotPrice({
153+
coinInType: "0x...",
154+
coinOutType: "0x...",
155+
withFees: true,
156+
});
157+
158+
// Calculate trade output amount
159+
const amountOut = pool.getTradeAmountOut({
160+
coinInType: "0x...",
161+
coinInAmount: BigInt("1000000"),
162+
coinOutType: "0x...",
163+
referral: false,
164+
});
165+
166+
// Calculate trade input amount
167+
const amountIn = pool.getTradeAmountIn({
168+
coinInType: "0x...",
169+
coinOutAmount: BigInt("1000000"),
170+
coinOutType: "0x...",
171+
referral: false,
172+
});
173+
174+
// Calculate LP tokens for deposit
175+
const lpInfo = pool.getDepositLpAmountOut({
176+
amountsIn: {
177+
"0x...": BigInt("1000000"),
178+
},
179+
referral: false,
180+
});
181+
Pool Analytics
182+
Copy
183+
// Get pool statistics
184+
const stats = await pool.getStats();
185+
186+
// Get volume data
187+
const volumeData = await pool.getVolumeData({
188+
timeframe: "1D", // "1D" | "1W" | "1M" | "3M" | "6M" | "1Y"
189+
});
190+
191+
// Get fee data
192+
const feeData = await pool.getFeeData({
193+
timeframe: "1D",
194+
});
195+
196+
// Get 24h volume
197+
const volume24h = await pool.getVolume24hrs();
198+
Types
199+
Pool Types
200+
Copy
201+
interface PoolObject {
202+
name: string;
203+
creator: string;
204+
lpCoinType: string;
205+
lpCoinSupply: bigint;
206+
illiquidLpCoinSupply: bigint;
207+
flatness: bigint;
208+
coins: Record<string, PoolCoin>;
209+
lpCoinDecimals: number;
210+
daoFeePoolObject?: DaoFeePoolObject;
211+
}
212+
213+
interface PoolCoin {
214+
weight: bigint;
215+
balance: bigint;
216+
tradeFeeIn: bigint;
217+
tradeFeeOut: bigint;
218+
depositFee: bigint;
219+
withdrawFee: bigint;
220+
decimalsScalar: bigint;
221+
normalizedBalance: bigint;
222+
decimals?: number;
223+
}
224+
225+
interface PoolStats {
226+
volume: number;
227+
tvl: number;
228+
supplyPerLps: number[];
229+
lpPrice: number;
230+
fees: number;
231+
apr: number;
232+
}
233+
Example Usage
234+
Copy
235+
const afSdk = new Aftermath("MAINNET");
236+
await afSdk.init();
237+
const pools = afSdk.Pools();
238+
239+
// Get a pool
240+
const pool = await pools.getPool({
241+
objectId: "0x...",
242+
});
243+
244+
// Calculate trade output
245+
const amountOut = pool.getTradeAmountOut({
246+
coinInType: "0x2::sui::SUI",
247+
coinOutType:
248+
"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",
249+
coinInAmount: BigInt("1000000000"),
250+
referral: true,
251+
});
252+
253+
// Execute trade
254+
const tradeTx = await pool.getTradeTransaction({
255+
walletAddress: "0x...",
256+
coinInType: "0x2::sui::SUI",
257+
coinInAmount: BigInt("1000000000"),
258+
coinOutType:
259+
"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",
260+
slippage: 0.01,
261+
});

0 commit comments

Comments
 (0)