Conversation
projects/amped/src/constants.ts
Outdated
| [NETWORKS.BASE]: 8453 | ||
| } as const; | ||
|
|
||
| export const RPC_URLS = { |
There was a problem hiding this comment.
do not need do this. Check venus project and how we get provider
projects/amped/src/constants.ts
Outdated
| export const BASIS_POINTS_DIVISOR = 10000; | ||
|
|
||
| // Supported chains | ||
| export const supportedChains = [146, 8453] as const; |
There was a problem hiding this comment.
too much redundant variables. Check venus project
projects/amped/src/constants.ts
Outdated
| NATIVE_TOKEN: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE' as Address, | ||
| WRAPPED_NATIVE_TOKEN: '0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38' as Address, | ||
| WETH: '0x50c42deacd8fc9773493ed674b675be577f2634b' as Address, | ||
| USDC: '0x29219dd400f2bf60e5a23d13be72b486d4038894' as Address, |
There was a problem hiding this comment.
No need create your own token list of USDC, WETH, etc...
projects/amped/src/constants.ts
Outdated
| decimals: 18, | ||
| }, | ||
| rpcUrls: { | ||
| default: { |
There was a problem hiding this comment.
No need do this. We have proper way to get provider. Check venus project
projects/amped/src/constants.ts
Outdated
| export type SupportedNetwork = typeof NETWORKS[keyof typeof NETWORKS]; | ||
|
|
||
| // Explicit lowercase chain name type for standardization | ||
| export type LowercaseChainName = 'sonic' | 'base'; |
There was a problem hiding this comment.
what for this? If you want create enum with supported chains - do it.
| * @param props.walletClient - Optional Viem Wallet Client for interacting with the blockchain | ||
| * @param options - System tools (notify) | ||
| * @returns Transaction result with liquidity addition details | ||
| */ |
There was a problem hiding this comment.
Why you have 2 addLiquidity functions? slippageTolerance - not use anywhere.
| import { SupportedToken, getTokenAddress, getChainFromName } from '../../utils.js'; | ||
| import type { PublicClient, WalletClient } from 'viem'; | ||
| import { encodeFunctionData, Address } from 'viem'; | ||
| import { Router } from '../../abis/Router.js'; |
There was a problem hiding this comment.
this imports not use in code. We have strict rules in our project, it will not even compile with such imports and functions.
| await notify(`Adding liquidity with ${tokenSymbol} on ${networkName}...`); | ||
|
|
||
| // Get user token balances | ||
| const userBalanceResult = await getUserTokenBalances({ |
There was a problem hiding this comment.
why if user want work with one token we must fetch his balances for all supported tokens?
| tokenSymbol: TokenSymbol; | ||
| amount: string; | ||
| slippageTolerance?: number; | ||
| percentOfBalance?: number; |
There was a problem hiding this comment.
percentOfBalance?: number; - it can't be undefined. Check venus project and how we treat optional parametrs
| if (allowance < amountInWei) { | ||
| await notify(`Allowance is ${formatUnits(allowance, tokenDecimals)}, needs ${formatUnits(amountInWei, tokenDecimals)}. Requesting approval for GlpManager...`); | ||
| try { | ||
| // Send approval with viem walletClient | ||
| const MAX_UINT256 = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); | ||
| await notify(`Setting unlimited approval (MAX_UINT256) for ${tokenSymbol} for GlpManager`); | ||
|
|
||
| await notify('Sending approval transaction with viem...'); | ||
| approvalHash = await walletClient.writeContract({ | ||
| address: tokenInAddress as `0x${string}`, | ||
| abi: ERC20, | ||
| functionName: 'approve', | ||
| args: [glpManagerAddressTyped, MAX_UINT256], | ||
| account: walletClient.account, | ||
| chain: walletClient.chain, | ||
| }); | ||
|
|
||
| await notify(`Approval transaction sent: ${approvalHash}. Waiting for confirmation...`); | ||
| // Wait for receipt with viem publicClient | ||
| const receipt = await publicClient.waitForTransactionReceipt({ hash: approvalHash }); | ||
|
|
||
| if (receipt.status === 'success') { | ||
| await notify('Approval confirmed.'); | ||
| // Verify allowance after approval | ||
| const newAllowance = await publicClient.readContract({ | ||
| address: tokenInAddress as `0x${string}`, | ||
| abi: ERC20, | ||
| functionName: 'allowance', | ||
| args: [account, glpManagerAddressTyped], | ||
| }); | ||
| await notify(`New allowance for GlpManager: ${formatUnits(newAllowance, tokenDecimals)} ${tokenSymbol}`); | ||
| if (newAllowance < amountInWei) { | ||
| return toResult(`Approval transaction successful but allowance for GlpManager is still insufficient. Required: ${formatUnits(amountInWei, tokenDecimals)}, Granted: ${formatUnits(newAllowance, tokenDecimals)}`, true); |
| * @returns APR information including base APR and reward rates | ||
| */ | ||
| export async function getALPAPR( | ||
| { chainName, account, tokenAddress, publicClient }: Props, |
| const rewardTokenPriceFormatted = Number(formatUnits(rewardTokenPrice, 30)).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 6 }); | ||
| const rewardTokenSymbol = networkName === NETWORKS.SONIC ? 'wS' : 'WETH'; // Get symbol for logging | ||
|
|
||
| await options.notify('APR calculation completed'); |
There was a problem hiding this comment.
we have 1-3 notify in execute functions
You have -
marketSwap.ts: 8 occurrences
getSwapsLiquidity.ts: 14 occurrences
getPerpsLiquidity.ts: 14 occurrences
closePosition.ts: 12 occurrences
getPerpsLiquidity.ts (leverage folder): 14 occurrences
getAllOpenPositions.ts: 18 occurrences
getPosition.ts: 17 occurrences
claimRewards.ts: 3 occurrences
There was a problem hiding this comment.
Here maybe it's correct, because all info which goes in toResult - going through AI and it can be cut or modified, but in notify you can convey immutable data to user. But no need such notify quantity in execution functions.
| } | ||
|
|
||
| // Define the specific ABI for the functions we need | ||
| const GLP_TOKEN_ABI = [ |
| displaySymbol = 'ETH'; // Ensure display symbol is native | ||
| } | ||
|
|
||
| if (addressForVaultCall && addressForVaultCall !== '0x0000000000000000000000000000000000000000') { |
| } | ||
|
|
||
| // Explicitly get contracts for the network to satisfy linter potentially | ||
| const currentNetworkContracts = CONTRACT_ADDRESSES[networkName]; |
There was a problem hiding this comment.
you already check chain. currentNetworkContracts can't be undefined. You have a lot such redundant checks throughout all project.
| let receipt: TransactionReceipt | null = null; | ||
| let attempts = 0; | ||
| const maxAttempts = 5; | ||
| const retryDelayMs = 3000; | ||
|
|
||
| while (attempts < maxAttempts) { | ||
| try { | ||
| receipt = await publicClient.getTransactionReceipt({ hash: txHash }); | ||
| if (receipt) { | ||
| break; // Exit loop if receipt is found | ||
| } | ||
| } catch (e) { | ||
| // Log error during attempts, but continue retrying | ||
| await notify(`Attempt ${attempts + 1} to get receipt failed: ${(e as Error).message}`); | ||
| } | ||
| attempts++; | ||
| if (attempts < maxAttempts) { | ||
| await notify(`Retrying in ${retryDelayMs / 1000}s... (${attempts}/${maxAttempts})`); | ||
| await new Promise(resolve => setTimeout(resolve, retryDelayMs)); | ||
| } |
| return toResult(`Transaction ${txHash} failed with status: ${receipt.status}`, true); | ||
| } | ||
|
|
||
| const removeLiquidityEvents = receipt.logs.filter(log => { |
There was a problem hiding this comment.
too hard logic. Check venus project and way how parse events with viem
| * @param options - System tools for blockchain interactions | ||
| * @returns Detailed information about the position including size, collateral, PnL, etc. | ||
| */ | ||
| export async function getPosition({ chainName, account, indexToken, collateralToken, isLong }: Props, { notify, getProvider }: FunctionOptions): Promise<FunctionReturn> { |
There was a problem hiding this comment.
we need proper names for args for AI. indexToken - > tokenSymbol, collateralToken -> collateralTokenSymbol
projects/amped/src/tools.ts
Outdated
| }, | ||
| ], | ||
| required: ['chainName', 'account', 'tokenSymbol'], | ||
| parameters: { |
There was a problem hiding this comment.
we don't have parameters in examples.
projects/amped/src/tools.ts
Outdated
| }, | ||
| tokenSymbol: { | ||
| type: 'string', | ||
| description: `Symbol of the token to provide as liquidity. Sonic: ${sonicTokenSymbols}, Base: ${baseTokenSymbols}`, |
There was a problem hiding this comment.
If you want use enum - do it. Description is not proper place for supported token list
projects/amped/src/tools.ts
Outdated
| }, | ||
| minUsdg: { | ||
| type: 'string', | ||
| description: 'Minimum USDG to receive in decimal format (e.g., "1.5" for 1.5 USDG). Uses 18 decimals. Defaults to "0" if not specified.', |
There was a problem hiding this comment.
Uses 18 decimals. Defaults to "0" if not specified. - what for? Use must specify token amount and inside functions you must handle decimals. Do not leave this for AI
| * Maps from token symbol to token data for each supported chain | ||
| * Using Partial<Record> to allow for partial token support on each chain | ||
| */ | ||
| const TOKEN_MAP: Record<string, Partial<Record<TokenSymbol, TokenData>>> = { |
There was a problem hiding this comment.
do not do this. If you need specific tokens - it's ok. But not reassign WS, USDC, Anon. We already have our token list https://github.com/RealWagmi/heyanon-tokenlist
Amped Finance Integration
Description
Implementation of Amped Finance perpetual swaps and AMM exchange integration:
Core Features
✅ Liquidity Operations
✅ Leveraged Trading
✅ Information Services
✅ Risk Management
Technical Improvements
Enhanced error handling with contextual messages
Robust input validation for financial operations
Type-safe implementations for core operations
Gas-optimized transaction building
Comprehensive response formatting
Supported Networks
Sonic (Mainnet)
Test Results
All core test suites passing (6/6):
Implementation Details
Modular architecture with separated concerns:
Features
Next Steps
References
Amped Finance
Protocol Type: Decentralized Perpetual Exchange
Twitter: @AmpedFinance
Documentation: https://amped.gitbook.io/amped/