@sun-protocol/sun-sdk-sunswap-v2 0.1.0-beta.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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/actions.ts","../src/utils.ts","../src/constants.ts","../src/errors.ts","../src/entities/pair.ts","../src/entities/route.ts","../src/entities/trade.ts","../src/reads.ts","../src/router.ts"],"sourcesContent":["export * from './actions.js'\nexport * from './constants.js'\nexport * from './errors.js'\nexport * from './entities/index.js'\nexport * from './reads.js'\nexport * from './router.js'\nexport * from './types.js'\nexport * from './utils.js'\n","import { getContractAddress } from '@sun-protocol/sun-sdk-chains'\nimport {\n createApproveAction,\n createContractCallAction,\n type BigintIsh,\n type ContractCallAction,\n type Network,\n type Token,\n type TronAddress,\n} from '@sun-protocol/sun-sdk-core'\nimport { evmHexToTronAddress } from './utils.js'\n\nexport const V2_ROUTER_SELECTORS = {\n addLiquidity: 'addLiquidity(address,address,uint256,uint256,uint256,uint256,address,uint256)',\n addLiquidityETH: 'addLiquidityETH(address,uint256,uint256,uint256,address,uint256)',\n removeLiquidity: 'removeLiquidity(address,address,uint256,uint256,uint256,address,uint256)',\n removeLiquidityETH: 'removeLiquidityETH(address,uint256,uint256,uint256,address,uint256)',\n swapExactETHForTokens: 'swapExactETHForTokens(uint256,address[],address,uint256)',\n swapETHForExactTokens: 'swapETHForExactTokens(uint256,address[],address,uint256)',\n swapExactTokensForETH: 'swapExactTokensForETH(uint256,uint256,address[],address,uint256)',\n swapExactTokensForTokens: 'swapExactTokensForTokens(uint256,uint256,address[],address,uint256)',\n swapTokensForExactETH: 'swapTokensForExactETH(uint256,uint256,address[],address,uint256)',\n swapTokensForExactTokens: 'swapTokensForExactTokens(uint256,uint256,address[],address,uint256)',\n} as const\n\nexport interface V2ActionOptions {\n readonly network: Network\n readonly router?: TronAddress\n readonly feeLimit?: number\n readonly id?: string\n}\n\nexport interface BuildV2AddLiquidityActionParams extends V2ActionOptions {\n readonly tokenA: Token\n readonly tokenB: Token\n readonly amountADesired: BigintIsh\n readonly amountBDesired: BigintIsh\n readonly amountAMin: BigintIsh\n readonly amountBMin: BigintIsh\n readonly recipient: TronAddress\n readonly deadline: BigintIsh\n}\n\nexport interface BuildV2RemoveLiquidityActionParams extends V2ActionOptions {\n readonly tokenA: Token\n readonly tokenB: Token\n readonly liquidity: BigintIsh\n readonly amountAMin: BigintIsh\n readonly amountBMin: BigintIsh\n readonly recipient: TronAddress\n readonly deadline: BigintIsh\n}\n\nexport interface BuildV2AddLiquidityEthActionParams extends V2ActionOptions {\n readonly token: Token\n readonly amountTokenDesired: BigintIsh\n readonly amountEthDesired: BigintIsh\n readonly amountTokenMin: BigintIsh\n readonly amountEthMin: BigintIsh\n readonly recipient: TronAddress\n readonly deadline: BigintIsh\n}\n\nexport interface BuildV2RemoveLiquidityEthActionParams extends V2ActionOptions {\n readonly token: Token\n readonly liquidity: BigintIsh\n readonly amountTokenMin: BigintIsh\n readonly amountEthMin: BigintIsh\n readonly recipient: TronAddress\n readonly deadline: BigintIsh\n}\n\nexport interface V2SwapActionOptions extends V2ActionOptions {\n readonly path: readonly TronAddress[]\n readonly recipient: TronAddress\n readonly deadline: BigintIsh\n}\n\nexport interface BuildV2SwapExactEthForTokensActionParams extends V2SwapActionOptions {\n readonly amountIn: BigintIsh\n readonly amountOutMin: BigintIsh\n}\n\nexport interface BuildV2SwapEthForExactTokensActionParams extends V2SwapActionOptions {\n readonly amountOut: BigintIsh\n readonly amountInMax: BigintIsh\n}\n\nexport interface BuildV2SwapExactTokensForEthActionParams extends V2SwapActionOptions {\n readonly amountIn: BigintIsh\n readonly amountOutMin: BigintIsh\n}\n\nexport interface BuildV2SwapExactTokensForTokensActionParams extends V2SwapActionOptions {\n readonly amountIn: BigintIsh\n readonly amountOutMin: BigintIsh\n}\n\nexport interface BuildV2SwapTokensForExactEthActionParams extends V2SwapActionOptions {\n readonly amountOut: BigintIsh\n readonly amountInMax: BigintIsh\n}\n\nexport interface BuildV2SwapTokensForExactTokensActionParams extends V2SwapActionOptions {\n readonly amountOut: BigintIsh\n readonly amountInMax: BigintIsh\n}\n\nfunction routerTarget(params: V2ActionOptions): TronAddress {\n return params.router ?? getContractAddress(params.network, 'sunswapV2Router')\n}\n\nfunction valueOf(value: BigintIsh): string {\n return value.toString()\n}\n\nfunction actionId(params: V2ActionOptions, suffix: string): string {\n return params.id ?? `sunswap-v2-${suffix}-${params.network}`\n}\n\nexport function buildV2AddLiquidityAction(params: BuildV2AddLiquidityActionParams): ContractCallAction {\n return createContractCallAction({\n id: actionId(params, 'add-liquidity'),\n target: routerTarget(params),\n functionSelector: V2_ROUTER_SELECTORS.addLiquidity,\n parameters: [\n { type: 'address', value: evmHexToTronAddress(params.tokenA.address, 'tokenA') },\n { type: 'address', value: evmHexToTronAddress(params.tokenB.address, 'tokenB') },\n { type: 'uint256', value: valueOf(params.amountADesired) },\n { type: 'uint256', value: valueOf(params.amountBDesired) },\n { type: 'uint256', value: valueOf(params.amountAMin) },\n { type: 'uint256', value: valueOf(params.amountBMin) },\n { type: 'address', value: params.recipient },\n { type: 'uint256', value: valueOf(params.deadline) },\n ],\n ...(params.feeLimit !== undefined ? { feeLimit: params.feeLimit } : {}),\n })\n}\n\nexport function buildV2RemoveLiquidityAction(params: BuildV2RemoveLiquidityActionParams): ContractCallAction {\n return createContractCallAction({\n id: actionId(params, 'remove-liquidity'),\n target: routerTarget(params),\n functionSelector: V2_ROUTER_SELECTORS.removeLiquidity,\n parameters: [\n { type: 'address', value: evmHexToTronAddress(params.tokenA.address, 'tokenA') },\n { type: 'address', value: evmHexToTronAddress(params.tokenB.address, 'tokenB') },\n { type: 'uint256', value: valueOf(params.liquidity) },\n { type: 'uint256', value: valueOf(params.amountAMin) },\n { type: 'uint256', value: valueOf(params.amountBMin) },\n { type: 'address', value: params.recipient },\n { type: 'uint256', value: valueOf(params.deadline) },\n ],\n ...(params.feeLimit !== undefined ? { feeLimit: params.feeLimit } : {}),\n })\n}\n\nexport function buildV2AddLiquidityEthAction(params: BuildV2AddLiquidityEthActionParams): ContractCallAction {\n return createContractCallAction({\n id: actionId(params, 'add-liquidity-eth'),\n target: routerTarget(params),\n functionSelector: V2_ROUTER_SELECTORS.addLiquidityETH,\n parameters: [\n { type: 'address', value: evmHexToTronAddress(params.token.address, 'token') },\n { type: 'uint256', value: valueOf(params.amountTokenDesired) },\n { type: 'uint256', value: valueOf(params.amountTokenMin) },\n { type: 'uint256', value: valueOf(params.amountEthMin) },\n { type: 'address', value: params.recipient },\n { type: 'uint256', value: valueOf(params.deadline) },\n ],\n callValue: BigInt(valueOf(params.amountEthDesired)),\n ...(params.feeLimit !== undefined ? { feeLimit: params.feeLimit } : {}),\n })\n}\n\nexport function buildV2RemoveLiquidityEthAction(params: BuildV2RemoveLiquidityEthActionParams): ContractCallAction {\n return createContractCallAction({\n id: actionId(params, 'remove-liquidity-eth'),\n target: routerTarget(params),\n functionSelector: V2_ROUTER_SELECTORS.removeLiquidityETH,\n parameters: [\n { type: 'address', value: evmHexToTronAddress(params.token.address, 'token') },\n { type: 'uint256', value: valueOf(params.liquidity) },\n { type: 'uint256', value: valueOf(params.amountTokenMin) },\n { type: 'uint256', value: valueOf(params.amountEthMin) },\n { type: 'address', value: params.recipient },\n { type: 'uint256', value: valueOf(params.deadline) },\n ],\n ...(params.feeLimit !== undefined ? { feeLimit: params.feeLimit } : {}),\n })\n}\n\nexport function buildV2SwapExactEthForTokensAction(\n params: BuildV2SwapExactEthForTokensActionParams,\n): ContractCallAction {\n return createContractCallAction({\n id: actionId(params, 'swap-exact-eth-for-tokens'),\n target: routerTarget(params),\n functionSelector: V2_ROUTER_SELECTORS.swapExactETHForTokens,\n parameters: [\n { type: 'uint256', value: valueOf(params.amountOutMin) },\n { type: 'address[]', value: params.path },\n { type: 'address', value: params.recipient },\n { type: 'uint256', value: valueOf(params.deadline) },\n ],\n callValue: BigInt(valueOf(params.amountIn)),\n ...(params.feeLimit !== undefined ? { feeLimit: params.feeLimit } : {}),\n })\n}\n\nexport function buildV2SwapEthForExactTokensAction(\n params: BuildV2SwapEthForExactTokensActionParams,\n): ContractCallAction {\n return createContractCallAction({\n id: actionId(params, 'swap-eth-for-exact-tokens'),\n target: routerTarget(params),\n functionSelector: V2_ROUTER_SELECTORS.swapETHForExactTokens,\n parameters: [\n { type: 'uint256', value: valueOf(params.amountOut) },\n { type: 'address[]', value: params.path },\n { type: 'address', value: params.recipient },\n { type: 'uint256', value: valueOf(params.deadline) },\n ],\n callValue: BigInt(valueOf(params.amountInMax)),\n ...(params.feeLimit !== undefined ? { feeLimit: params.feeLimit } : {}),\n })\n}\n\nexport function buildV2SwapExactTokensForEthAction(\n params: BuildV2SwapExactTokensForEthActionParams,\n): ContractCallAction {\n return createContractCallAction({\n id: actionId(params, 'swap-exact-tokens-for-eth'),\n target: routerTarget(params),\n functionSelector: V2_ROUTER_SELECTORS.swapExactTokensForETH,\n parameters: [\n { type: 'uint256', value: valueOf(params.amountIn) },\n { type: 'uint256', value: valueOf(params.amountOutMin) },\n { type: 'address[]', value: params.path },\n { type: 'address', value: params.recipient },\n { type: 'uint256', value: valueOf(params.deadline) },\n ],\n ...(params.feeLimit !== undefined ? { feeLimit: params.feeLimit } : {}),\n })\n}\n\nexport function buildV2SwapExactTokensForTokensAction(\n params: BuildV2SwapExactTokensForTokensActionParams,\n): ContractCallAction {\n return createContractCallAction({\n id: actionId(params, 'swap-exact-tokens-for-tokens'),\n target: routerTarget(params),\n functionSelector: V2_ROUTER_SELECTORS.swapExactTokensForTokens,\n parameters: [\n { type: 'uint256', value: valueOf(params.amountIn) },\n { type: 'uint256', value: valueOf(params.amountOutMin) },\n { type: 'address[]', value: params.path },\n { type: 'address', value: params.recipient },\n { type: 'uint256', value: valueOf(params.deadline) },\n ],\n ...(params.feeLimit !== undefined ? { feeLimit: params.feeLimit } : {}),\n })\n}\n\nexport function buildV2SwapTokensForExactEthAction(\n params: BuildV2SwapTokensForExactEthActionParams,\n): ContractCallAction {\n return createContractCallAction({\n id: actionId(params, 'swap-tokens-for-exact-eth'),\n target: routerTarget(params),\n functionSelector: V2_ROUTER_SELECTORS.swapTokensForExactETH,\n parameters: [\n { type: 'uint256', value: valueOf(params.amountOut) },\n { type: 'uint256', value: valueOf(params.amountInMax) },\n { type: 'address[]', value: params.path },\n { type: 'address', value: params.recipient },\n { type: 'uint256', value: valueOf(params.deadline) },\n ],\n ...(params.feeLimit !== undefined ? { feeLimit: params.feeLimit } : {}),\n })\n}\n\nexport function buildV2SwapTokensForExactTokensAction(\n params: BuildV2SwapTokensForExactTokensActionParams,\n): ContractCallAction {\n return createContractCallAction({\n id: actionId(params, 'swap-tokens-for-exact-tokens'),\n target: routerTarget(params),\n functionSelector: V2_ROUTER_SELECTORS.swapTokensForExactTokens,\n parameters: [\n { type: 'uint256', value: valueOf(params.amountOut) },\n { type: 'uint256', value: valueOf(params.amountInMax) },\n { type: 'address[]', value: params.path },\n { type: 'address', value: params.recipient },\n { type: 'uint256', value: valueOf(params.deadline) },\n ],\n ...(params.feeLimit !== undefined ? { feeLimit: params.feeLimit } : {}),\n })\n}\n\nexport function buildV2LpApproveAction(params: {\n readonly pair: TronAddress\n readonly spender: TronAddress\n readonly amount: BigintIsh\n readonly feeLimit?: number\n readonly id?: string\n}): ContractCallAction {\n return createApproveAction({\n id: params.id ?? `sunswap-v2-lp-approve-${params.pair}`,\n target: params.pair,\n spender: params.spender,\n amount: valueOf(params.amount),\n ...(params.feeLimit !== undefined ? { feeLimit: params.feeLimit } : {}),\n })\n}\n","import { getContractAddress, getWrappedNativeAddress } from '@sun-protocol/sun-sdk-chains'\nimport { keccak256 } from '@ethersproject/keccak256'\nimport { sha256 } from '@noble/hashes/sha256'\nimport { Percent, SDK_ERROR_CODES, sdkInvariant, type BigintIsh, type Network, type Token, type TronAddress } from '@sun-protocol/sun-sdk-core'\nimport type { V2PairKey } from './types.js'\n\nexport const V2_INIT_CODE_HASH: Record<Network, `0x${string}`> = {\n mainnet: '0x6d3f89421f83e4b62e628de8fc7ff2b014a79bf8fd8e8b0ea46e4a1d9409b67d',\n nile: '0x9dd9bfc2f6c1103a6c01d9c6a4044e4b8a9361f92df2728cdc3729922d56748e',\n}\n\nexport interface ComputeV2PairAddressParams {\n readonly network: Network\n readonly tokenA: TronAddress | string\n readonly tokenB: TronAddress | string\n readonly factory?: TronAddress | string\n readonly initCodeHash?: string\n readonly wrappedNative?: TronAddress | string\n}\n\nconst BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'\nconst BASE58_ZERO = '1'\nconst HEX_20_BYTES_PATTERN = /^0x[a-fA-F0-9]{40}$/\nconst HEX_20_BYTES_NO_PREFIX_PATTERN = /^[a-fA-F0-9]{40}$/\nconst HEX_32_BYTES_PATTERN = /^(?:0x)?[a-fA-F0-9]{64}$/\nconst TRON_ADDRESS_PAYLOAD_BYTES = 25\nconst TRON_ADDRESS_BYTES = 21\nconst TRON_PREFIX_HEX = '41'\n\nfunction toBigInt(value: BigintIsh): bigint {\n return BigInt(value.toString())\n}\n\nfunction validatePositive(value: bigint, label: string): void {\n sdkInvariant(value > 0n, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, `${label} must be positive`, {\n [label]: value.toString(),\n })\n}\n\nexport function sortV2Tokens(tokenA: Token, tokenB: Token): readonly [Token, Token] {\n return tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA]\n}\n\nfunction decodeBase58(value: string): Uint8Array {\n let decoded = 0n\n\n for (const char of value) {\n const index = BASE58_ALPHABET.indexOf(char)\n sdkInvariant(index >= 0, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, 'Invalid base58 character', { value, char })\n decoded = decoded * 58n + BigInt(index)\n }\n\n const bytes: number[] = []\n while (decoded > 0n) {\n bytes.unshift(Number(decoded & 0xffn))\n decoded >>= 8n\n }\n\n for (const char of value) {\n if (char !== '1') break\n bytes.unshift(0)\n }\n\n return Uint8Array.from(bytes)\n}\n\nfunction encodeBase58(bytes: Uint8Array): string {\n let value = 0n\n for (const byte of bytes) {\n value = (value << 8n) + BigInt(byte)\n }\n\n let encoded = ''\n while (value > 0n) {\n const mod = Number(value % 58n)\n const char = BASE58_ALPHABET[mod]\n sdkInvariant(char !== undefined, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, 'Invalid base58 remainder', { mod })\n encoded = char + encoded\n value /= 58n\n }\n\n for (const byte of bytes) {\n if (byte !== 0) break\n encoded = `${BASE58_ZERO}${encoded}`\n }\n\n return encoded || BASE58_ZERO\n}\n\nfunction bytesToHex(bytes: Uint8Array): string {\n return Array.from(bytes)\n .map((byte) => byte.toString(16).padStart(2, '0'))\n .join('')\n}\n\nfunction hexToBytes(hex: string, label: string): Uint8Array {\n const normalized = hex.startsWith('0x') ? hex.slice(2) : hex\n sdkInvariant(/^[a-fA-F0-9]*$/.test(normalized) && normalized.length % 2 === 0, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, `${label} must be even-length hex`, {\n label,\n value: hex,\n })\n const bytes = new Uint8Array(normalized.length / 2)\n for (let i = 0; i < bytes.length; i += 1) {\n bytes[i] = Number.parseInt(normalized.slice(i * 2, i * 2 + 2), 16)\n }\n return bytes\n}\n\nfunction checksum(payload: Uint8Array): Uint8Array {\n return sha256(sha256(payload)).slice(0, 4)\n}\n\nfunction tronPayloadToBase58(payload: Uint8Array): TronAddress {\n const bytes = new Uint8Array(TRON_ADDRESS_PAYLOAD_BYTES)\n bytes.set(payload, 0)\n bytes.set(checksum(payload), TRON_ADDRESS_BYTES)\n return encodeBase58(bytes) as TronAddress\n}\n\nexport function tronAddressToEvmHex(address: string, label = 'address'): string {\n if (HEX_20_BYTES_PATTERN.test(address)) return address.slice(2).toLowerCase()\n if (HEX_20_BYTES_NO_PREFIX_PATTERN.test(address)) return address.toLowerCase()\n\n const decoded = decodeBase58(address)\n sdkInvariant(\n decoded.length === TRON_ADDRESS_PAYLOAD_BYTES,\n SDK_ERROR_CODES.SDK_INVALID_ARGUMENT,\n `${label} must be a TRON base58 address or 20-byte EVM hex address`,\n { label, value: address },\n )\n const body = decoded.slice(0, TRON_ADDRESS_BYTES)\n const expectedChecksum = checksum(body)\n const actualChecksum = decoded.slice(TRON_ADDRESS_BYTES)\n sdkInvariant(\n bytesToHex(expectedChecksum) === bytesToHex(actualChecksum),\n SDK_ERROR_CODES.SDK_INVALID_ARGUMENT,\n `${label} has invalid TRON base58 checksum`,\n { label, value: address },\n )\n sdkInvariant(body[0] === 0x41, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, `${label} must use TRON 0x41 prefix`, {\n label,\n value: address,\n })\n return bytesToHex(body.slice(1))\n}\n\nexport function evmHexToTronAddress(address: string, label = 'address'): TronAddress {\n sdkInvariant(HEX_20_BYTES_PATTERN.test(address), SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, `${label} must be a 20-byte EVM hex address`, {\n label,\n value: address,\n })\n return tronPayloadToBase58(hexToBytes(`${TRON_PREFIX_HEX}${address.slice(2)}`, label))\n}\n\nexport function tronCreate2Address(params: {\n readonly factoryAddress: string\n readonly salt: string\n readonly initCodeHash: string\n}): TronAddress {\n const factory = tronAddressToEvmHex(params.factoryAddress, 'factory')\n const salt = normalizeV2InitCodeHash(params.salt)\n const initCodeHash = normalizeV2InitCodeHash(params.initCodeHash)\n const hash = keccak256(hexToBytes(`${TRON_PREFIX_HEX}${factory}${salt}${initCodeHash}`, 'CREATE2 input')).slice(2)\n return tronPayloadToBase58(hexToBytes(`${TRON_PREFIX_HEX}${hash.slice(-40)}`, 'contract address'))\n}\n\nfunction normalizeV2InitCodeHash(value: string): string {\n sdkInvariant(HEX_32_BYTES_PATTERN.test(value), SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, 'V2 initCodeHash must be bytes32 hex', {\n value,\n })\n return value.startsWith('0x') ? value.slice(2).toLowerCase() : value.toLowerCase()\n}\n\nfunction normalizeV2TokenAddress(address: string, wrappedNative: string, label: string): string {\n const normalized = address === 'T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb' ? wrappedNative : address\n return tronAddressToEvmHex(normalized, label)\n}\n\nexport function computeV2PairAddress(params: ComputeV2PairAddressParams): TronAddress {\n const wrappedNative = params.wrappedNative ?? getWrappedNativeAddress(params.network)\n const tokenA = normalizeV2TokenAddress(params.tokenA, wrappedNative, 'tokenA')\n const tokenB = normalizeV2TokenAddress(params.tokenB, wrappedNative, 'tokenB')\n sdkInvariant(tokenA !== tokenB, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, 'V2 pair tokens must be different', {\n tokenA: params.tokenA,\n tokenB: params.tokenB,\n })\n\n const [token0, token1] = tokenA < tokenB ? [tokenA, tokenB] : [tokenB, tokenA]\n const factory = tronAddressToEvmHex(params.factory ?? getContractAddress(params.network, 'sunswapV2Factory'), 'factory')\n const tokenHash = keccak256(hexToBytes(`${token0}${token1}`, 'token salt')).slice(2)\n const initCodeHash = normalizeV2InitCodeHash(params.initCodeHash ?? V2_INIT_CODE_HASH[params.network]!)\n return tronCreate2Address({ factoryAddress: factory, salt: tokenHash, initCodeHash })\n}\n\nexport function createV2PairKey(input: { network: V2PairKey['network']; tokenA: Token; tokenB: Token }): V2PairKey {\n const [token0, token1] = sortV2Tokens(input.tokenA, input.tokenB)\n return { network: input.network, token0, token1 }\n}\n\nexport function quoteV2LiquidityAmount(amountA: BigintIsh, reserveA: BigintIsh, reserveB: BigintIsh): string {\n const amount = toBigInt(amountA)\n const reserveIn = toBigInt(reserveA)\n const reserveOut = toBigInt(reserveB)\n validatePositive(amount, 'amountA')\n validatePositive(reserveIn, 'reserveA')\n validatePositive(reserveOut, 'reserveB')\n return ((amount * reserveOut) / reserveIn).toString()\n}\n\nexport function applyV2SlippageMin(amount: BigintIsh, slippageTolerance: Percent): string {\n sdkInvariant(\n !slippageTolerance.lessThan(0),\n SDK_ERROR_CODES.SDK_INVALID_ARGUMENT,\n 'Slippage tolerance cannot be negative',\n { slippageTolerance: slippageTolerance.toSignificant() },\n )\n sdkInvariant(\n !slippageTolerance.greaterThan(1),\n SDK_ERROR_CODES.SDK_INVALID_ARGUMENT,\n 'Slippage tolerance cannot exceed 100%',\n { slippageTolerance: slippageTolerance.toSignificant() },\n )\n return new Percent(1).subtract(slippageTolerance).multiply(amount.toString()).quotient.toString()\n}\n\nexport function getV2AddLiquidityMinimums(\n amounts: { amountA: BigintIsh; amountB: BigintIsh },\n slippageTolerance: Percent,\n): { amountAMin: string; amountBMin: string } {\n return {\n amountAMin: applyV2SlippageMin(amounts.amountA, slippageTolerance),\n amountBMin: applyV2SlippageMin(amounts.amountB, slippageTolerance),\n }\n}\n\nexport function getV2RemoveLiquidityMinimums(\n amounts: { amountA: BigintIsh; amountB: BigintIsh },\n slippageTolerance: Percent,\n): { amountAMin: string; amountBMin: string } {\n return getV2AddLiquidityMinimums(amounts, slippageTolerance)\n}\n","import { Percent } from '@sun-protocol/sun-sdk-core'\nimport JSBI from 'jsbi'\n\nexport const FACTORY_ADDRESS = '0x689abaeeed3f0bb3585773192e23224cac25dd41'\n\nexport const FACTORY_ADDRESS_MAP: { [chainId: number]: string } = {\n 728126428: FACTORY_ADDRESS,\n 3448148188: '0x55f7d5d874a73f21c0851c62d374307985f440fc',\n}\n\nexport const INIT_CODE_HASH = '0x6d3f89421f83e4b62e628de8fc7ff2b014a79bf8fd8e8b0ea46e4a1d9409b67d'\n\nexport const INIT_CODE_HASH_MAP: { [chainId: number]: string } = {\n 728126428: INIT_CODE_HASH,\n 3448148188: '0x9dd9bfc2f6c1103a6c01d9c6a4044e4b8a9361f92df2728cdc3729922d56748e',\n}\n\nexport const MINIMUM_LIQUIDITY = JSBI.BigInt(1000)\n\nexport const ZERO = JSBI.BigInt(0)\nexport const ONE = JSBI.BigInt(1)\nexport const FIVE = JSBI.BigInt(5)\nexport const _997 = JSBI.BigInt(997)\nexport const _1000 = JSBI.BigInt(1000)\nexport const BASIS_POINTS = JSBI.BigInt(10000)\n\nexport const ZERO_PERCENT = new Percent(ZERO)\nexport const ONE_HUNDRED_PERCENT = new Percent(ONE)\n","export class InsufficientReservesError extends Error {\n public readonly isInsufficientReservesError = true as const\n\n public constructor() {\n super('Insufficient reserves')\n this.name = this.constructor.name\n }\n}\n\nexport class InsufficientInputAmountError extends Error {\n public readonly isInsufficientInputAmountError = true as const\n\n public constructor() {\n super('Insufficient input amount')\n this.name = this.constructor.name\n }\n}\n","import { BigNumber } from '@ethersproject/bignumber'\nimport { keccak256, pack } from '@ethersproject/solidity'\nimport { CurrencyAmount, Percent, Price, sqrt, Token, type BigintIsh } from '@sun-protocol/sun-sdk-core'\nimport JSBI from 'jsbi'\nimport invariant from 'tiny-invariant'\nimport {\n _1000,\n _997,\n BASIS_POINTS,\n FACTORY_ADDRESS,\n FACTORY_ADDRESS_MAP,\n FIVE,\n INIT_CODE_HASH,\n INIT_CODE_HASH_MAP,\n MINIMUM_LIQUIDITY,\n ONE,\n ONE_HUNDRED_PERCENT,\n ZERO,\n ZERO_PERCENT,\n} from '../constants.js'\nimport { InsufficientInputAmountError, InsufficientReservesError } from '../errors.js'\nimport { tronAddressToEvmHex, tronCreate2Address } from '../utils.js'\n\nexport const computePairAddress = ({\n factoryAddress,\n tokenA,\n tokenB,\n initCodeHashManualOverride,\n}: {\n factoryAddress: string\n tokenA: Token\n tokenB: Token\n initCodeHashManualOverride?: string\n}): string => {\n const [token0, token1] = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA]\n const salt = keccak256(['bytes'], [pack(['address', 'address'], [token0.address, token1.address])])\n const tronAddress = tronCreate2Address({\n factoryAddress,\n salt,\n initCodeHash: initCodeHashManualOverride ?? INIT_CODE_HASH_MAP[tokenA.chainId] ?? INIT_CODE_HASH,\n })\n return `0x${tronAddressToEvmHex(tronAddress)}`\n}\n\nexport class Pair {\n public readonly liquidityToken: Token\n private readonly tokenAmounts: [CurrencyAmount<Token>, CurrencyAmount<Token>]\n\n public static getAddress(tokenA: Token, tokenB: Token): string {\n const factoryAddress = FACTORY_ADDRESS_MAP[tokenA.chainId] ?? FACTORY_ADDRESS\n return computePairAddress({ factoryAddress, tokenA, tokenB })\n }\n\n public constructor(currencyAmountA: CurrencyAmount<Token>, tokenAmountB: CurrencyAmount<Token>) {\n const tokenAmounts: [CurrencyAmount<Token>, CurrencyAmount<Token>] = currencyAmountA.currency.sortsBefore(tokenAmountB.currency)\n ? [currencyAmountA, tokenAmountB]\n : [tokenAmountB, currencyAmountA]\n this.liquidityToken = new Token(\n tokenAmounts[0].currency.chainId,\n Pair.getAddress(tokenAmounts[0].currency, tokenAmounts[1].currency),\n 18,\n 'UNI-V2',\n 'Uniswap V2',\n )\n this.tokenAmounts = tokenAmounts\n }\n\n public involvesToken(token: Token): boolean {\n return token.equals(this.token0) || token.equals(this.token1)\n }\n\n public get token0Price(): Price<Token, Token> {\n const result = this.tokenAmounts[1].divide(this.tokenAmounts[0])\n return new Price(this.token0, this.token1, result.denominator, result.numerator)\n }\n\n public get token1Price(): Price<Token, Token> {\n const result = this.tokenAmounts[0].divide(this.tokenAmounts[1])\n return new Price(this.token1, this.token0, result.denominator, result.numerator)\n }\n\n public priceOf(token: Token): Price<Token, Token> {\n invariant(this.involvesToken(token), 'TOKEN')\n return token.equals(this.token0) ? this.token0Price : this.token1Price\n }\n\n public get chainId(): number {\n return this.token0.chainId\n }\n\n public get token0(): Token {\n return this.tokenAmounts[0].currency\n }\n\n public get token1(): Token {\n return this.tokenAmounts[1].currency\n }\n\n public get reserve0(): CurrencyAmount<Token> {\n return this.tokenAmounts[0]\n }\n\n public get reserve1(): CurrencyAmount<Token> {\n return this.tokenAmounts[1]\n }\n\n public reserveOf(token: Token): CurrencyAmount<Token> {\n invariant(this.involvesToken(token), 'TOKEN')\n return token.equals(this.token0) ? this.reserve0 : this.reserve1\n }\n\n public getOutputAmount(inputAmount: CurrencyAmount<Token>, calculateFotFees = true): [CurrencyAmount<Token>, Pair] {\n invariant(this.involvesToken(inputAmount.currency), 'TOKEN')\n if (JSBI.equal(this.reserve0.quotient, ZERO) || JSBI.equal(this.reserve1.quotient, ZERO)) {\n throw new InsufficientReservesError()\n }\n\n const inputReserve = this.reserveOf(inputAmount.currency)\n const outputReserve = this.reserveOf(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0)\n const percentAfterSellFees = calculateFotFees ? this.derivePercentAfterSellFees(inputAmount) : ZERO_PERCENT\n const inputAmountAfterTax = percentAfterSellFees.greaterThan(ZERO_PERCENT)\n ? CurrencyAmount.fromRawAmount(inputAmount.currency, percentAfterSellFees.multiply(inputAmount).quotient)\n : inputAmount\n const inputAmountWithFeeAndAfterTax = JSBI.multiply(inputAmountAfterTax.quotient, _997)\n const numerator = JSBI.multiply(inputAmountWithFeeAndAfterTax, outputReserve.quotient)\n const denominator = JSBI.add(JSBI.multiply(inputReserve.quotient, _1000), inputAmountWithFeeAndAfterTax)\n const outputAmount = CurrencyAmount.fromRawAmount(\n inputAmount.currency.equals(this.token0) ? this.token1 : this.token0,\n JSBI.divide(numerator, denominator),\n )\n if (JSBI.equal(outputAmount.quotient, ZERO)) {\n throw new InsufficientInputAmountError()\n }\n\n const percentAfterBuyFees = calculateFotFees ? this.derivePercentAfterBuyFees(outputAmount) : ZERO_PERCENT\n const outputAmountAfterTax = percentAfterBuyFees.greaterThan(ZERO_PERCENT)\n ? CurrencyAmount.fromRawAmount(outputAmount.currency, outputAmount.multiply(percentAfterBuyFees).quotient)\n : outputAmount\n if (JSBI.equal(outputAmountAfterTax.quotient, ZERO)) {\n throw new InsufficientInputAmountError()\n }\n\n return [outputAmountAfterTax, new Pair(inputReserve.add(inputAmountAfterTax), outputReserve.subtract(outputAmountAfterTax))]\n }\n\n public getInputAmount(outputAmount: CurrencyAmount<Token>, calculateFotFees = true): [CurrencyAmount<Token>, Pair] {\n invariant(this.involvesToken(outputAmount.currency), 'TOKEN')\n const percentAfterBuyFees = calculateFotFees ? this.derivePercentAfterBuyFees(outputAmount) : ZERO_PERCENT\n const outputAmountBeforeTax = percentAfterBuyFees.greaterThan(ZERO_PERCENT)\n ? CurrencyAmount.fromRawAmount(outputAmount.currency, JSBI.add(outputAmount.divide(percentAfterBuyFees).quotient, ONE))\n : outputAmount\n if (\n JSBI.equal(this.reserve0.quotient, ZERO) ||\n JSBI.equal(this.reserve1.quotient, ZERO) ||\n JSBI.greaterThanOrEqual(outputAmount.quotient, this.reserveOf(outputAmount.currency).quotient) ||\n JSBI.greaterThanOrEqual(outputAmountBeforeTax.quotient, this.reserveOf(outputAmount.currency).quotient)\n ) {\n throw new InsufficientReservesError()\n }\n\n const outputReserve = this.reserveOf(outputAmount.currency)\n const inputReserve = this.reserveOf(outputAmount.currency.equals(this.token0) ? this.token1 : this.token0)\n const numerator = JSBI.multiply(JSBI.multiply(inputReserve.quotient, outputAmountBeforeTax.quotient), _1000)\n const denominator = JSBI.multiply(JSBI.subtract(outputReserve.quotient, outputAmountBeforeTax.quotient), _997)\n const inputAmount = CurrencyAmount.fromRawAmount(\n outputAmount.currency.equals(this.token0) ? this.token1 : this.token0,\n JSBI.add(JSBI.divide(numerator, denominator), ONE),\n )\n const percentAfterSellFees = calculateFotFees ? this.derivePercentAfterSellFees(inputAmount) : ZERO_PERCENT\n const inputAmountBeforeTax = percentAfterSellFees.greaterThan(ZERO_PERCENT)\n ? CurrencyAmount.fromRawAmount(inputAmount.currency, JSBI.add(inputAmount.divide(percentAfterSellFees).quotient, ONE))\n : inputAmount\n return [inputAmountBeforeTax, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))]\n }\n\n public getLiquidityMinted(\n totalSupply: CurrencyAmount<Token>,\n tokenAmountA: CurrencyAmount<Token>,\n tokenAmountB: CurrencyAmount<Token>,\n ): CurrencyAmount<Token> {\n invariant(totalSupply.currency.equals(this.liquidityToken), 'LIQUIDITY')\n const tokenAmounts: [CurrencyAmount<Token>, CurrencyAmount<Token>] = tokenAmountA.currency.sortsBefore(tokenAmountB.currency)\n ? [tokenAmountA, tokenAmountB]\n : [tokenAmountB, tokenAmountA]\n invariant(tokenAmounts[0].currency.equals(this.token0) && tokenAmounts[1].currency.equals(this.token1), 'TOKEN')\n\n let liquidity: JSBI\n if (JSBI.equal(totalSupply.quotient, ZERO)) {\n liquidity = JSBI.subtract(sqrt(JSBI.multiply(tokenAmounts[0].quotient, tokenAmounts[1].quotient)), MINIMUM_LIQUIDITY)\n } else {\n const amount0 = JSBI.divide(JSBI.multiply(tokenAmounts[0].quotient, totalSupply.quotient), this.reserve0.quotient)\n const amount1 = JSBI.divide(JSBI.multiply(tokenAmounts[1].quotient, totalSupply.quotient), this.reserve1.quotient)\n liquidity = JSBI.lessThanOrEqual(amount0, amount1) ? amount0 : amount1\n }\n if (!JSBI.greaterThan(liquidity, ZERO)) {\n throw new InsufficientInputAmountError()\n }\n return CurrencyAmount.fromRawAmount(this.liquidityToken, liquidity)\n }\n\n public getLiquidityValue(\n token: Token,\n totalSupply: CurrencyAmount<Token>,\n liquidity: CurrencyAmount<Token>,\n feeOn = false,\n kLast?: BigintIsh,\n ): CurrencyAmount<Token> {\n invariant(this.involvesToken(token), 'TOKEN')\n invariant(totalSupply.currency.equals(this.liquidityToken), 'TOTAL_SUPPLY')\n invariant(liquidity.currency.equals(this.liquidityToken), 'LIQUIDITY')\n invariant(JSBI.lessThanOrEqual(liquidity.quotient, totalSupply.quotient), 'LIQUIDITY')\n\n let totalSupplyAdjusted: CurrencyAmount<Token>\n if (!feeOn) {\n totalSupplyAdjusted = totalSupply\n } else {\n invariant(!!kLast, 'K_LAST')\n const kLastParsed = JSBI.BigInt(kLast)\n if (!JSBI.equal(kLastParsed, ZERO)) {\n const rootK = sqrt(JSBI.multiply(this.reserve0.quotient, this.reserve1.quotient))\n const rootKLast = sqrt(kLastParsed)\n if (JSBI.greaterThan(rootK, rootKLast)) {\n const numerator = JSBI.multiply(totalSupply.quotient, JSBI.subtract(rootK, rootKLast))\n const denominator = JSBI.add(JSBI.multiply(rootK, FIVE), rootKLast)\n const feeLiquidity = JSBI.divide(numerator, denominator)\n totalSupplyAdjusted = totalSupply.add(CurrencyAmount.fromRawAmount(this.liquidityToken, feeLiquidity))\n } else {\n totalSupplyAdjusted = totalSupply\n }\n } else {\n totalSupplyAdjusted = totalSupply\n }\n }\n\n return CurrencyAmount.fromRawAmount(\n token,\n JSBI.divide(JSBI.multiply(liquidity.quotient, this.reserveOf(token).quotient), totalSupplyAdjusted.quotient),\n )\n }\n\n private derivePercentAfterSellFees(inputAmount: CurrencyAmount<Token>): Percent {\n const sellFeeBips = this.token0.wrapped.equals(inputAmount.wrapped.currency)\n ? this.token0.wrapped.sellFeeBps\n : this.token1.wrapped.sellFeeBps\n if (sellFeeBips?.gt(BigNumber.from(0))) {\n return ONE_HUNDRED_PERCENT.subtract(new Percent(JSBI.BigInt(sellFeeBips)).divide(BASIS_POINTS))\n }\n return ZERO_PERCENT\n }\n\n private derivePercentAfterBuyFees(outputAmount: CurrencyAmount<Token>): Percent {\n const buyFeeBps = this.token0.wrapped.equals(outputAmount.wrapped.currency)\n ? this.token0.wrapped.buyFeeBps\n : this.token1.wrapped.buyFeeBps\n if (buyFeeBps?.gt(BigNumber.from(0))) {\n return ONE_HUNDRED_PERCENT.subtract(new Percent(JSBI.BigInt(buyFeeBps)).divide(BASIS_POINTS))\n }\n return ZERO_PERCENT\n }\n}\n","import { Price, type Currency, type Token } from '@sun-protocol/sun-sdk-core'\nimport invariant from 'tiny-invariant'\nimport type { Pair } from './pair.js'\n\nexport class Route<TInput extends Currency, TOutput extends Currency> {\n public readonly pairs: Pair[]\n public readonly path: Token[]\n public readonly input: TInput\n public readonly output: TOutput\n\n private _midPrice: Price<TInput, TOutput> | null = null\n\n public constructor(pairs: Pair[], input: TInput, output?: TOutput) {\n invariant(pairs.length > 0, 'PAIRS')\n const firstPair = pairs[0]!\n const chainId = firstPair.chainId\n invariant(pairs.every((pair) => pair.chainId === chainId), 'CHAIN_IDS')\n\n const wrappedInput = input.wrapped\n invariant(firstPair.involvesToken(wrappedInput), 'INPUT')\n invariant(typeof output === 'undefined' || pairs[pairs.length - 1]!.involvesToken(output.wrapped), 'OUTPUT')\n\n const path: Token[] = [wrappedInput]\n for (const [i, pair] of pairs.entries()) {\n const currentInput = path[i]!\n invariant(currentInput.equals(pair.token0) || currentInput.equals(pair.token1), 'PATH')\n const currentOutput = currentInput.equals(pair.token0) ? pair.token1 : pair.token0\n path.push(currentOutput)\n }\n\n this.pairs = pairs\n this.path = path\n this.input = input\n this.output = output ?? (path[path.length - 1] as TOutput)\n }\n\n public get midPrice(): Price<TInput, TOutput> {\n if (this._midPrice !== null) return this._midPrice\n\n const prices: Price<Currency, Currency>[] = []\n for (const [i, pair] of this.pairs.entries()) {\n prices.push(\n this.path[i]!.equals(pair.token0)\n ? new Price(pair.reserve0.currency, pair.reserve1.currency, pair.reserve0.quotient, pair.reserve1.quotient)\n : new Price(pair.reserve1.currency, pair.reserve0.currency, pair.reserve1.quotient, pair.reserve0.quotient),\n )\n }\n\n const reduced = prices.slice(1).reduce((accumulator, currentValue) => accumulator.multiply(currentValue), prices[0]!)\n return (this._midPrice = new Price(this.input, this.output, reduced.denominator, reduced.numerator))\n }\n\n public get chainId(): number {\n return this.pairs[0]!.chainId\n }\n}\n","import type {\n Percent} from '@sun-protocol/sun-sdk-core';\nimport {\n computePriceImpact,\n CurrencyAmount,\n Fraction,\n Price,\n sortedInsert,\n TradeType,\n type Currency,\n} from '@sun-protocol/sun-sdk-core'\nimport JSBI from 'jsbi'\nimport invariant from 'tiny-invariant'\nimport { ONE, ZERO } from '../constants.js'\nimport type { Pair } from './pair.js'\nimport { Route } from './route.js'\n\ninterface InputOutput<TInput extends Currency, TOutput extends Currency> {\n readonly inputAmount: CurrencyAmount<TInput>\n readonly outputAmount: CurrencyAmount<TOutput>\n}\n\nexport function inputOutputComparator<TInput extends Currency, TOutput extends Currency>(\n a: InputOutput<TInput, TOutput>,\n b: InputOutput<TInput, TOutput>,\n): number {\n invariant(a.inputAmount.currency.equals(b.inputAmount.currency), 'INPUT_CURRENCY')\n invariant(a.outputAmount.currency.equals(b.outputAmount.currency), 'OUTPUT_CURRENCY')\n\n if (a.outputAmount.equalTo(b.outputAmount)) {\n if (a.inputAmount.equalTo(b.inputAmount)) return 0\n return a.inputAmount.lessThan(b.inputAmount) ? -1 : 1\n }\n return a.outputAmount.lessThan(b.outputAmount) ? 1 : -1\n}\n\nexport function tradeComparator<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(\n a: Trade<TInput, TOutput, TTradeType>,\n b: Trade<TInput, TOutput, TTradeType>,\n): number {\n const ioComp = inputOutputComparator(a, b)\n if (ioComp !== 0) return ioComp\n if (a.priceImpact.lessThan(b.priceImpact)) return -1\n if (a.priceImpact.greaterThan(b.priceImpact)) return 1\n return a.route.path.length - b.route.path.length\n}\n\nexport interface BestTradeOptions {\n maxNumResults?: number\n maxHops?: number\n}\n\nexport class Trade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType> {\n public readonly route: Route<TInput, TOutput>\n public readonly tradeType: TTradeType\n public readonly inputAmount: CurrencyAmount<TInput>\n public readonly outputAmount: CurrencyAmount<TOutput>\n public readonly executionPrice: Price<TInput, TOutput>\n public readonly priceImpact: Percent\n\n public static exactIn<TInput extends Currency, TOutput extends Currency>(\n route: Route<TInput, TOutput>,\n amountIn: CurrencyAmount<TInput>,\n ): Trade<TInput, TOutput, TradeType.EXACT_INPUT> {\n return new Trade(route, amountIn, TradeType.EXACT_INPUT)\n }\n\n public static exactOut<TInput extends Currency, TOutput extends Currency>(\n route: Route<TInput, TOutput>,\n amountOut: CurrencyAmount<TOutput>,\n ): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT> {\n return new Trade(route, amountOut, TradeType.EXACT_OUTPUT)\n }\n\n public constructor(\n route: Route<TInput, TOutput>,\n amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>,\n tradeType: TTradeType,\n ) {\n this.route = route\n this.tradeType = tradeType\n\n const tokenAmounts = new Array<CurrencyAmount<Currency>>(route.path.length)\n if (tradeType === TradeType.EXACT_INPUT) {\n invariant(amount.currency.equals(route.input), 'INPUT')\n tokenAmounts[0] = amount.wrapped\n for (let i = 0; i < route.path.length - 1; i += 1) {\n const pair = route.pairs[i]!\n const [outputAmount] = pair.getOutputAmount(tokenAmounts[i]!.wrapped)\n tokenAmounts[i + 1] = outputAmount\n }\n this.inputAmount = CurrencyAmount.fromFractionalAmount(route.input, amount.numerator, amount.denominator)\n this.outputAmount = CurrencyAmount.fromFractionalAmount(\n route.output,\n tokenAmounts[tokenAmounts.length - 1]!.numerator,\n tokenAmounts[tokenAmounts.length - 1]!.denominator,\n )\n } else {\n invariant(amount.currency.equals(route.output), 'OUTPUT')\n tokenAmounts[tokenAmounts.length - 1] = amount.wrapped\n for (let i = route.path.length - 1; i > 0; i -= 1) {\n const pair = route.pairs[i - 1]!\n const [inputAmount] = pair.getInputAmount(tokenAmounts[i]!.wrapped)\n tokenAmounts[i - 1] = inputAmount\n }\n this.inputAmount = CurrencyAmount.fromFractionalAmount(route.input, tokenAmounts[0]!.numerator, tokenAmounts[0]!.denominator)\n this.outputAmount = CurrencyAmount.fromFractionalAmount(route.output, amount.numerator, amount.denominator)\n }\n\n this.executionPrice = new Price(this.inputAmount.currency, this.outputAmount.currency, this.inputAmount.quotient, this.outputAmount.quotient)\n this.priceImpact = computePriceImpact(route.midPrice, this.inputAmount, this.outputAmount)\n }\n\n public minimumAmountOut(slippageTolerance: Percent): CurrencyAmount<TOutput> {\n invariant(!slippageTolerance.lessThan(ZERO), 'SLIPPAGE_TOLERANCE')\n if (this.tradeType === TradeType.EXACT_OUTPUT) return this.outputAmount\n\n const slippageAdjustedAmountOut = new Fraction(ONE).subtract(slippageTolerance).multiply(this.outputAmount.quotient).quotient\n const clampedAmount = JSBI.greaterThan(slippageAdjustedAmountOut, JSBI.BigInt(0)) ? slippageAdjustedAmountOut : JSBI.BigInt(0)\n return CurrencyAmount.fromRawAmount(this.outputAmount.currency, clampedAmount)\n }\n\n public maximumAmountIn(slippageTolerance: Percent): CurrencyAmount<TInput> {\n invariant(!slippageTolerance.lessThan(ZERO), 'SLIPPAGE_TOLERANCE')\n if (this.tradeType === TradeType.EXACT_INPUT) return this.inputAmount\n\n const slippageAdjustedAmountIn = new Fraction(ONE).add(slippageTolerance).multiply(this.inputAmount.quotient).quotient\n return CurrencyAmount.fromRawAmount(this.inputAmount.currency, slippageAdjustedAmountIn)\n }\n\n public static bestTradeExactIn<TInput extends Currency, TOutput extends Currency>(\n pairs: Pair[],\n currencyAmountIn: CurrencyAmount<TInput>,\n currencyOut: TOutput,\n { maxNumResults = 3, maxHops = 3 }: BestTradeOptions = {},\n currentPairs: Pair[] = [],\n nextAmountIn: CurrencyAmount<Currency> = currencyAmountIn,\n bestTrades: Trade<TInput, TOutput, TradeType.EXACT_INPUT>[] = [],\n ): Trade<TInput, TOutput, TradeType.EXACT_INPUT>[] {\n invariant(pairs.length > 0, 'PAIRS')\n invariant(maxHops > 0, 'MAX_HOPS')\n invariant(currencyAmountIn === nextAmountIn || currentPairs.length > 0, 'INVALID_RECURSION')\n\n const amountIn = nextAmountIn.wrapped\n const tokenOut = currencyOut.wrapped\n for (let i = 0; i < pairs.length; i += 1) {\n const pair = pairs[i]!\n if (!pair.token0.equals(amountIn.currency) && !pair.token1.equals(amountIn.currency)) continue\n if (pair.reserve0.equalTo(ZERO) || pair.reserve1.equalTo(ZERO)) continue\n\n let amountOut: CurrencyAmount<Currency>\n try {\n ;[amountOut] = pair.getOutputAmount(amountIn)\n } catch (error) {\n if ((error as { readonly isInsufficientInputAmountError?: boolean }).isInsufficientInputAmountError) continue\n throw error\n }\n\n if (amountOut.currency.equals(tokenOut)) {\n sortedInsert(\n bestTrades,\n new Trade(new Route([...currentPairs, pair], currencyAmountIn.currency, currencyOut), currencyAmountIn, TradeType.EXACT_INPUT),\n maxNumResults,\n tradeComparator,\n )\n } else if (maxHops > 1 && pairs.length > 1) {\n const pairsExcludingThisPair = pairs.slice(0, i).concat(pairs.slice(i + 1))\n Trade.bestTradeExactIn(\n pairsExcludingThisPair,\n currencyAmountIn,\n currencyOut,\n { maxNumResults, maxHops: maxHops - 1 },\n [...currentPairs, pair],\n amountOut,\n bestTrades,\n )\n }\n }\n\n return bestTrades\n }\n\n public worstExecutionPrice(slippageTolerance: Percent): Price<TInput, TOutput> {\n return new Price(\n this.inputAmount.currency,\n this.outputAmount.currency,\n this.maximumAmountIn(slippageTolerance).quotient,\n this.minimumAmountOut(slippageTolerance).quotient,\n )\n }\n\n public static bestTradeExactOut<TInput extends Currency, TOutput extends Currency>(\n pairs: Pair[],\n currencyIn: TInput,\n currencyAmountOut: CurrencyAmount<TOutput>,\n { maxNumResults = 3, maxHops = 3 }: BestTradeOptions = {},\n currentPairs: Pair[] = [],\n nextAmountOut: CurrencyAmount<Currency> = currencyAmountOut,\n bestTrades: Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[] = [],\n ): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[] {\n invariant(pairs.length > 0, 'PAIRS')\n invariant(maxHops > 0, 'MAX_HOPS')\n invariant(currencyAmountOut === nextAmountOut || currentPairs.length > 0, 'INVALID_RECURSION')\n\n const amountOut = nextAmountOut.wrapped\n const tokenIn = currencyIn.wrapped\n for (let i = 0; i < pairs.length; i += 1) {\n const pair = pairs[i]!\n if (!pair.token0.equals(amountOut.currency) && !pair.token1.equals(amountOut.currency)) continue\n if (pair.reserve0.equalTo(ZERO) || pair.reserve1.equalTo(ZERO)) continue\n\n let amountIn: CurrencyAmount<Currency>\n try {\n ;[amountIn] = pair.getInputAmount(amountOut)\n } catch (error) {\n if ((error as { readonly isInsufficientReservesError?: boolean }).isInsufficientReservesError) continue\n throw error\n }\n\n if (amountIn.currency.equals(tokenIn)) {\n sortedInsert(\n bestTrades,\n new Trade(new Route([pair, ...currentPairs], currencyIn, currencyAmountOut.currency), currencyAmountOut, TradeType.EXACT_OUTPUT),\n maxNumResults,\n tradeComparator,\n )\n } else if (maxHops > 1 && pairs.length > 1) {\n const pairsExcludingThisPair = pairs.slice(0, i).concat(pairs.slice(i + 1))\n Trade.bestTradeExactOut(\n pairsExcludingThisPair,\n currencyIn,\n currencyAmountOut,\n { maxNumResults, maxHops: maxHops - 1 },\n [pair, ...currentPairs],\n amountIn,\n bestTrades,\n )\n }\n }\n\n return bestTrades\n }\n}\n","import { getContractAddress } from '@sun-protocol/sun-sdk-chains'\nimport type {\n BigintIsh,\n ContractParameter,\n Network,\n TronAddress,\n} from '@sun-protocol/sun-sdk-core'\n\nexport interface V2ContractReadSpec {\n readonly target: TronAddress\n readonly functionSelector: string\n readonly parameters?: readonly ContractParameter[]\n readonly outputs?: readonly { readonly type: string; readonly name?: string }[]\n readonly metadata?: Record<string, unknown>\n}\n\nexport const V2_PAIR_READ_SELECTORS = {\n getReserves: 'getReserves()',\n totalSupply: 'totalSupply()',\n kLast: 'kLast()',\n balanceOf: 'balanceOf(address)',\n allowance: 'allowance(address,address)',\n} as const\n\nexport const V2_FACTORY_READ_SELECTORS = {\n getPair: 'getPair(address,address)',\n feeTo: 'feeTo()',\n} as const\n\nexport const V2_ROUTER_READ_SELECTORS = {\n getAmountsOut: 'getAmountsOut(uint256,address[])',\n getAmountsIn: 'getAmountsIn(uint256,address[])',\n isAllowedTradingPair: 'isAllowedTradingPair(address,address)',\n} as const\n\nexport interface V2RouterReadOptions {\n readonly network: Network\n readonly router?: TronAddress\n}\n\nexport interface V2FactoryReadOptions {\n readonly network: Network\n readonly factory?: TronAddress\n}\n\nexport interface BuildV2FactoryPairReadParams extends V2FactoryReadOptions {\n readonly tokenA: TronAddress\n readonly tokenB: TronAddress\n}\n\nexport interface BuildV2RouterAmountsOutReadParams extends V2RouterReadOptions {\n readonly amountIn: BigintIsh\n readonly path: readonly TronAddress[]\n}\n\nexport interface BuildV2RouterAmountsInReadParams extends V2RouterReadOptions {\n readonly amountOut: BigintIsh\n readonly path: readonly TronAddress[]\n}\n\nexport interface BuildV2RouterAllowedTradingPairReadParams extends V2RouterReadOptions {\n readonly tokenA: TronAddress\n readonly tokenB: TronAddress\n}\n\nfunction valueOf(value: BigintIsh): string {\n return value.toString()\n}\n\nexport function buildV2PairReservesRead(pair: TronAddress): V2ContractReadSpec {\n return {\n target: pair,\n functionSelector: V2_PAIR_READ_SELECTORS.getReserves,\n metadata: { protocol: 'sunswap-v2', contract: 'pair', action: 'get-reserves' },\n }\n}\n\nexport function buildV2PairTotalSupplyRead(pair: TronAddress): V2ContractReadSpec {\n return {\n target: pair,\n functionSelector: V2_PAIR_READ_SELECTORS.totalSupply,\n metadata: { protocol: 'sunswap-v2', contract: 'pair', action: 'total-supply' },\n }\n}\n\nexport function buildV2PairKLastRead(pair: TronAddress): V2ContractReadSpec {\n return {\n target: pair,\n functionSelector: V2_PAIR_READ_SELECTORS.kLast,\n outputs: [{ type: 'uint256', name: 'kLast' }],\n metadata: { protocol: 'sunswap-v2', contract: 'pair', action: 'k-last' },\n }\n}\n\nexport function buildV2PairBalanceRead(pair: TronAddress, owner: TronAddress): V2ContractReadSpec {\n return {\n target: pair,\n functionSelector: V2_PAIR_READ_SELECTORS.balanceOf,\n parameters: [{ type: 'address', value: owner }],\n metadata: { protocol: 'sunswap-v2', contract: 'pair', action: 'balance-of' },\n }\n}\n\nexport function buildV2PairAllowanceRead(pair: TronAddress, owner: TronAddress, spender: TronAddress): V2ContractReadSpec {\n return {\n target: pair,\n functionSelector: V2_PAIR_READ_SELECTORS.allowance,\n parameters: [\n { type: 'address', value: owner },\n { type: 'address', value: spender },\n ],\n metadata: { protocol: 'sunswap-v2', contract: 'pair', action: 'allowance' },\n }\n}\n\nfunction routerTarget(params: V2RouterReadOptions): TronAddress {\n return params.router ?? getContractAddress(params.network, 'sunswapV2Router')\n}\n\nfunction factoryTarget(params: V2FactoryReadOptions): TronAddress {\n return params.factory ?? getContractAddress(params.network, 'sunswapV2Factory')\n}\n\nexport function buildV2FactoryPairRead(params: BuildV2FactoryPairReadParams): V2ContractReadSpec {\n return {\n target: factoryTarget(params),\n functionSelector: V2_FACTORY_READ_SELECTORS.getPair,\n parameters: [\n { type: 'address', value: params.tokenA },\n { type: 'address', value: params.tokenB },\n ],\n outputs: [{ type: 'address', name: 'pair' }],\n metadata: {\n protocol: 'sunswap-v2',\n contract: 'factory',\n action: 'get-pair',\n network: params.network,\n },\n }\n}\n\nexport function buildV2FactoryFeeToRead(params: V2FactoryReadOptions): V2ContractReadSpec {\n return {\n target: factoryTarget(params),\n functionSelector: V2_FACTORY_READ_SELECTORS.feeTo,\n outputs: [{ type: 'address', name: 'feeTo' }],\n metadata: {\n protocol: 'sunswap-v2',\n contract: 'factory',\n action: 'fee-to',\n network: params.network,\n },\n }\n}\n\nexport function buildV2RouterAmountsOutRead(params: BuildV2RouterAmountsOutReadParams): V2ContractReadSpec {\n return {\n target: routerTarget(params),\n functionSelector: V2_ROUTER_READ_SELECTORS.getAmountsOut,\n parameters: [\n { type: 'uint256', value: valueOf(params.amountIn) },\n { type: 'address[]', value: params.path },\n ],\n metadata: {\n protocol: 'sunswap-v2',\n contract: 'router',\n action: 'get-amounts-out',\n network: params.network,\n },\n }\n}\n\nexport function buildV2RouterAmountsInRead(params: BuildV2RouterAmountsInReadParams): V2ContractReadSpec {\n return {\n target: routerTarget(params),\n functionSelector: V2_ROUTER_READ_SELECTORS.getAmountsIn,\n parameters: [\n { type: 'uint256', value: valueOf(params.amountOut) },\n { type: 'address[]', value: params.path },\n ],\n metadata: {\n protocol: 'sunswap-v2',\n contract: 'router',\n action: 'get-amounts-in',\n network: params.network,\n },\n }\n}\n\nexport function buildV2RouterAllowedTradingPairRead(\n params: BuildV2RouterAllowedTradingPairReadParams,\n): V2ContractReadSpec {\n return {\n target: routerTarget(params),\n functionSelector: V2_ROUTER_READ_SELECTORS.isAllowedTradingPair,\n parameters: [\n { type: 'address', value: params.tokenA },\n { type: 'address', value: params.tokenB },\n ],\n metadata: {\n protocol: 'sunswap-v2',\n contract: 'router',\n action: 'is-allowed-trading-pair',\n network: params.network,\n },\n }\n}\n\nexport function normalizeV2ReserveResult(result: readonly unknown[]): { reserve0: string; reserve1: string } {\n return {\n reserve0: valueOf(result[0] as BigintIsh),\n reserve1: valueOf(result[1] as BigintIsh),\n }\n}\n\nexport function normalizeV2AmountsResult(result: unknown): string[] {\n const values = Array.isArray((result as { readonly amounts?: unknown })?.amounts)\n ? (result as { readonly amounts: readonly unknown[] }).amounts\n : Array.isArray(result)\n ? result\n : []\n return values.map((value) => valueOf(value as BigintIsh))\n}\n","import { TradeType, validateAndParseAddress, type Currency, type Percent } from '@sun-protocol/sun-sdk-core'\nimport invariant from 'tiny-invariant'\nimport type { Trade } from './entities/trade.js'\n\nexport interface TradeOptions {\n readonly allowedSlippage: Percent\n readonly ttl: number\n readonly recipient: string\n readonly feeOnTransfer?: boolean\n}\n\nexport interface TradeOptionsDeadline extends Omit<TradeOptions, 'ttl'> {\n readonly deadline: number\n}\n\nexport interface SwapParameters {\n readonly methodName: string\n readonly args: (string | string[])[]\n readonly value: string\n}\n\nfunction toHex(currencyAmount: { readonly quotient: { toString(radix?: number): string } }): string {\n return `0x${currencyAmount.quotient.toString(16)}`\n}\n\nconst ZERO_HEX = '0x0'\n\nexport abstract class Router {\n private constructor() {}\n\n public static swapCallParameters(trade: Trade<Currency, Currency, TradeType>, options: TradeOptions | TradeOptionsDeadline): SwapParameters {\n const etherIn = trade.inputAmount.currency.isNative\n const etherOut = trade.outputAmount.currency.isNative\n invariant(!(etherIn && etherOut), 'ETHER_IN_OUT')\n invariant(!('ttl' in options) || options.ttl > 0, 'TTL')\n\n const to = validateAndParseAddress(options.recipient)\n const amountIn = toHex(trade.maximumAmountIn(options.allowedSlippage))\n const amountOut = toHex(trade.minimumAmountOut(options.allowedSlippage))\n const path = trade.route.path.map((token) => token.address)\n const deadline = 'ttl' in options\n ? `0x${(Math.floor(new Date().getTime() / 1000) + options.ttl).toString(16)}`\n : `0x${options.deadline.toString(16)}`\n const useFeeOnTransfer = Boolean(options.feeOnTransfer)\n\n let methodName = ''\n let args: (string | string[])[] = []\n let value = ZERO_HEX\n\n switch (trade.tradeType) {\n case TradeType.EXACT_INPUT:\n if (etherIn) {\n methodName = useFeeOnTransfer ? 'swapExactETHForTokensSupportingFeeOnTransferTokens' : 'swapExactETHForTokens'\n args = [amountOut, path, to, deadline]\n value = amountIn\n } else if (etherOut) {\n methodName = useFeeOnTransfer ? 'swapExactTokensForETHSupportingFeeOnTransferTokens' : 'swapExactTokensForETH'\n args = [amountIn, amountOut, path, to, deadline]\n value = ZERO_HEX\n } else {\n methodName = useFeeOnTransfer ? 'swapExactTokensForTokensSupportingFeeOnTransferTokens' : 'swapExactTokensForTokens'\n args = [amountIn, amountOut, path, to, deadline]\n value = ZERO_HEX\n }\n break\n case TradeType.EXACT_OUTPUT:\n invariant(!useFeeOnTransfer, 'EXACT_OUT_FOT')\n if (etherIn) {\n methodName = 'swapETHForExactTokens'\n args = [amountOut, path, to, deadline]\n value = amountIn\n } else if (etherOut) {\n methodName = 'swapTokensForExactETH'\n args = [amountOut, amountIn, path, to, deadline]\n value = ZERO_HEX\n } else {\n methodName = 'swapTokensForExactTokens'\n args = [amountOut, amountIn, path, to, deadline]\n value = ZERO_HEX\n }\n break\n }\n\n return { methodName, args, value }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,yBAAmC;AACnC,IAAA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;AACrC,kBAAQ;AAAA,QACV,WAAW,UAAU;AACnB,uBAAa;AACb,iBAAO,CAAC,WAAW,UAAU,MAAM,IAAI,QAAQ;AAC/C,kBAAQ;AAAA,QACV,OAAO;AACL,uBAAa;AACb,iBAAO,CAAC,WAAW,UAAU,MAAM,IAAI,QAAQ;AAC/C,kBAAQ;AAAA,QACV;AACA;AAAA,IACJ;AAEA,WAAO,EAAE,YAAY,MAAM,MAAM;AAAA,EACnC;AACF;","names":["import_sun_sdk_chains","import_sun_sdk_core","import_sun_sdk_core","JSBI","import_sun_sdk_core","import_jsbi","invariant","JSBI","import_sun_sdk_core","import_tiny_invariant","invariant","import_sun_sdk_core","import_jsbi","import_tiny_invariant","invariant","JSBI","import_sun_sdk_chains","valueOf","routerTarget","import_sun_sdk_core","import_tiny_invariant","invariant"]}
@@ -0,0 +1,356 @@
1
+ import { Network, TronAddress, Token, BigintIsh, ContractCallAction, Percent, CurrencyAmount, Price, Currency, TradeType, ContractParameter } from '@sun-protocol/sun-sdk-core';
2
+ import JSBI from 'jsbi';
3
+
4
+ declare const V2_ROUTER_SELECTORS: {
5
+ readonly addLiquidity: "addLiquidity(address,address,uint256,uint256,uint256,uint256,address,uint256)";
6
+ readonly addLiquidityETH: "addLiquidityETH(address,uint256,uint256,uint256,address,uint256)";
7
+ readonly removeLiquidity: "removeLiquidity(address,address,uint256,uint256,uint256,address,uint256)";
8
+ readonly removeLiquidityETH: "removeLiquidityETH(address,uint256,uint256,uint256,address,uint256)";
9
+ readonly swapExactETHForTokens: "swapExactETHForTokens(uint256,address[],address,uint256)";
10
+ readonly swapETHForExactTokens: "swapETHForExactTokens(uint256,address[],address,uint256)";
11
+ readonly swapExactTokensForETH: "swapExactTokensForETH(uint256,uint256,address[],address,uint256)";
12
+ readonly swapExactTokensForTokens: "swapExactTokensForTokens(uint256,uint256,address[],address,uint256)";
13
+ readonly swapTokensForExactETH: "swapTokensForExactETH(uint256,uint256,address[],address,uint256)";
14
+ readonly swapTokensForExactTokens: "swapTokensForExactTokens(uint256,uint256,address[],address,uint256)";
15
+ };
16
+ interface V2ActionOptions {
17
+ readonly network: Network;
18
+ readonly router?: TronAddress;
19
+ readonly feeLimit?: number;
20
+ readonly id?: string;
21
+ }
22
+ interface BuildV2AddLiquidityActionParams extends V2ActionOptions {
23
+ readonly tokenA: Token;
24
+ readonly tokenB: Token;
25
+ readonly amountADesired: BigintIsh;
26
+ readonly amountBDesired: BigintIsh;
27
+ readonly amountAMin: BigintIsh;
28
+ readonly amountBMin: BigintIsh;
29
+ readonly recipient: TronAddress;
30
+ readonly deadline: BigintIsh;
31
+ }
32
+ interface BuildV2RemoveLiquidityActionParams extends V2ActionOptions {
33
+ readonly tokenA: Token;
34
+ readonly tokenB: Token;
35
+ readonly liquidity: BigintIsh;
36
+ readonly amountAMin: BigintIsh;
37
+ readonly amountBMin: BigintIsh;
38
+ readonly recipient: TronAddress;
39
+ readonly deadline: BigintIsh;
40
+ }
41
+ interface BuildV2AddLiquidityEthActionParams extends V2ActionOptions {
42
+ readonly token: Token;
43
+ readonly amountTokenDesired: BigintIsh;
44
+ readonly amountEthDesired: BigintIsh;
45
+ readonly amountTokenMin: BigintIsh;
46
+ readonly amountEthMin: BigintIsh;
47
+ readonly recipient: TronAddress;
48
+ readonly deadline: BigintIsh;
49
+ }
50
+ interface BuildV2RemoveLiquidityEthActionParams extends V2ActionOptions {
51
+ readonly token: Token;
52
+ readonly liquidity: BigintIsh;
53
+ readonly amountTokenMin: BigintIsh;
54
+ readonly amountEthMin: BigintIsh;
55
+ readonly recipient: TronAddress;
56
+ readonly deadline: BigintIsh;
57
+ }
58
+ interface V2SwapActionOptions extends V2ActionOptions {
59
+ readonly path: readonly TronAddress[];
60
+ readonly recipient: TronAddress;
61
+ readonly deadline: BigintIsh;
62
+ }
63
+ interface BuildV2SwapExactEthForTokensActionParams extends V2SwapActionOptions {
64
+ readonly amountIn: BigintIsh;
65
+ readonly amountOutMin: BigintIsh;
66
+ }
67
+ interface BuildV2SwapEthForExactTokensActionParams extends V2SwapActionOptions {
68
+ readonly amountOut: BigintIsh;
69
+ readonly amountInMax: BigintIsh;
70
+ }
71
+ interface BuildV2SwapExactTokensForEthActionParams extends V2SwapActionOptions {
72
+ readonly amountIn: BigintIsh;
73
+ readonly amountOutMin: BigintIsh;
74
+ }
75
+ interface BuildV2SwapExactTokensForTokensActionParams extends V2SwapActionOptions {
76
+ readonly amountIn: BigintIsh;
77
+ readonly amountOutMin: BigintIsh;
78
+ }
79
+ interface BuildV2SwapTokensForExactEthActionParams extends V2SwapActionOptions {
80
+ readonly amountOut: BigintIsh;
81
+ readonly amountInMax: BigintIsh;
82
+ }
83
+ interface BuildV2SwapTokensForExactTokensActionParams extends V2SwapActionOptions {
84
+ readonly amountOut: BigintIsh;
85
+ readonly amountInMax: BigintIsh;
86
+ }
87
+ declare function buildV2AddLiquidityAction(params: BuildV2AddLiquidityActionParams): ContractCallAction;
88
+ declare function buildV2RemoveLiquidityAction(params: BuildV2RemoveLiquidityActionParams): ContractCallAction;
89
+ declare function buildV2AddLiquidityEthAction(params: BuildV2AddLiquidityEthActionParams): ContractCallAction;
90
+ declare function buildV2RemoveLiquidityEthAction(params: BuildV2RemoveLiquidityEthActionParams): ContractCallAction;
91
+ declare function buildV2SwapExactEthForTokensAction(params: BuildV2SwapExactEthForTokensActionParams): ContractCallAction;
92
+ declare function buildV2SwapEthForExactTokensAction(params: BuildV2SwapEthForExactTokensActionParams): ContractCallAction;
93
+ declare function buildV2SwapExactTokensForEthAction(params: BuildV2SwapExactTokensForEthActionParams): ContractCallAction;
94
+ declare function buildV2SwapExactTokensForTokensAction(params: BuildV2SwapExactTokensForTokensActionParams): ContractCallAction;
95
+ declare function buildV2SwapTokensForExactEthAction(params: BuildV2SwapTokensForExactEthActionParams): ContractCallAction;
96
+ declare function buildV2SwapTokensForExactTokensAction(params: BuildV2SwapTokensForExactTokensActionParams): ContractCallAction;
97
+ declare function buildV2LpApproveAction(params: {
98
+ readonly pair: TronAddress;
99
+ readonly spender: TronAddress;
100
+ readonly amount: BigintIsh;
101
+ readonly feeLimit?: number;
102
+ readonly id?: string;
103
+ }): ContractCallAction;
104
+
105
+ declare const FACTORY_ADDRESS = "0x689abaeeed3f0bb3585773192e23224cac25dd41";
106
+ declare const FACTORY_ADDRESS_MAP: {
107
+ [chainId: number]: string;
108
+ };
109
+ declare const INIT_CODE_HASH = "0x6d3f89421f83e4b62e628de8fc7ff2b014a79bf8fd8e8b0ea46e4a1d9409b67d";
110
+ declare const INIT_CODE_HASH_MAP: {
111
+ [chainId: number]: string;
112
+ };
113
+ declare const MINIMUM_LIQUIDITY: JSBI;
114
+ declare const ZERO: JSBI;
115
+ declare const ONE: JSBI;
116
+ declare const FIVE: JSBI;
117
+ declare const _997: JSBI;
118
+ declare const _1000: JSBI;
119
+ declare const BASIS_POINTS: JSBI;
120
+ declare const ZERO_PERCENT: Percent;
121
+ declare const ONE_HUNDRED_PERCENT: Percent;
122
+
123
+ declare class InsufficientReservesError extends Error {
124
+ readonly isInsufficientReservesError: true;
125
+ constructor();
126
+ }
127
+ declare class InsufficientInputAmountError extends Error {
128
+ readonly isInsufficientInputAmountError: true;
129
+ constructor();
130
+ }
131
+
132
+ declare const computePairAddress: ({ factoryAddress, tokenA, tokenB, initCodeHashManualOverride, }: {
133
+ factoryAddress: string;
134
+ tokenA: Token;
135
+ tokenB: Token;
136
+ initCodeHashManualOverride?: string;
137
+ }) => string;
138
+ declare class Pair {
139
+ readonly liquidityToken: Token;
140
+ private readonly tokenAmounts;
141
+ static getAddress(tokenA: Token, tokenB: Token): string;
142
+ constructor(currencyAmountA: CurrencyAmount<Token>, tokenAmountB: CurrencyAmount<Token>);
143
+ involvesToken(token: Token): boolean;
144
+ get token0Price(): Price<Token, Token>;
145
+ get token1Price(): Price<Token, Token>;
146
+ priceOf(token: Token): Price<Token, Token>;
147
+ get chainId(): number;
148
+ get token0(): Token;
149
+ get token1(): Token;
150
+ get reserve0(): CurrencyAmount<Token>;
151
+ get reserve1(): CurrencyAmount<Token>;
152
+ reserveOf(token: Token): CurrencyAmount<Token>;
153
+ getOutputAmount(inputAmount: CurrencyAmount<Token>, calculateFotFees?: boolean): [CurrencyAmount<Token>, Pair];
154
+ getInputAmount(outputAmount: CurrencyAmount<Token>, calculateFotFees?: boolean): [CurrencyAmount<Token>, Pair];
155
+ getLiquidityMinted(totalSupply: CurrencyAmount<Token>, tokenAmountA: CurrencyAmount<Token>, tokenAmountB: CurrencyAmount<Token>): CurrencyAmount<Token>;
156
+ getLiquidityValue(token: Token, totalSupply: CurrencyAmount<Token>, liquidity: CurrencyAmount<Token>, feeOn?: boolean, kLast?: BigintIsh): CurrencyAmount<Token>;
157
+ private derivePercentAfterSellFees;
158
+ private derivePercentAfterBuyFees;
159
+ }
160
+
161
+ declare class Route<TInput extends Currency, TOutput extends Currency> {
162
+ readonly pairs: Pair[];
163
+ readonly path: Token[];
164
+ readonly input: TInput;
165
+ readonly output: TOutput;
166
+ private _midPrice;
167
+ constructor(pairs: Pair[], input: TInput, output?: TOutput);
168
+ get midPrice(): Price<TInput, TOutput>;
169
+ get chainId(): number;
170
+ }
171
+
172
+ interface InputOutput<TInput extends Currency, TOutput extends Currency> {
173
+ readonly inputAmount: CurrencyAmount<TInput>;
174
+ readonly outputAmount: CurrencyAmount<TOutput>;
175
+ }
176
+ declare function inputOutputComparator<TInput extends Currency, TOutput extends Currency>(a: InputOutput<TInput, TOutput>, b: InputOutput<TInput, TOutput>): number;
177
+ declare function tradeComparator<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(a: Trade<TInput, TOutput, TTradeType>, b: Trade<TInput, TOutput, TTradeType>): number;
178
+ interface BestTradeOptions {
179
+ maxNumResults?: number;
180
+ maxHops?: number;
181
+ }
182
+ declare class Trade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType> {
183
+ readonly route: Route<TInput, TOutput>;
184
+ readonly tradeType: TTradeType;
185
+ readonly inputAmount: CurrencyAmount<TInput>;
186
+ readonly outputAmount: CurrencyAmount<TOutput>;
187
+ readonly executionPrice: Price<TInput, TOutput>;
188
+ readonly priceImpact: Percent;
189
+ static exactIn<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountIn: CurrencyAmount<TInput>): Trade<TInput, TOutput, TradeType.EXACT_INPUT>;
190
+ static exactOut<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountOut: CurrencyAmount<TOutput>): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>;
191
+ constructor(route: Route<TInput, TOutput>, amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>, tradeType: TTradeType);
192
+ minimumAmountOut(slippageTolerance: Percent): CurrencyAmount<TOutput>;
193
+ maximumAmountIn(slippageTolerance: Percent): CurrencyAmount<TInput>;
194
+ static bestTradeExactIn<TInput extends Currency, TOutput extends Currency>(pairs: Pair[], currencyAmountIn: CurrencyAmount<TInput>, currencyOut: TOutput, { maxNumResults, maxHops }?: BestTradeOptions, currentPairs?: Pair[], nextAmountIn?: CurrencyAmount<Currency>, bestTrades?: Trade<TInput, TOutput, TradeType.EXACT_INPUT>[]): Trade<TInput, TOutput, TradeType.EXACT_INPUT>[];
195
+ worstExecutionPrice(slippageTolerance: Percent): Price<TInput, TOutput>;
196
+ static bestTradeExactOut<TInput extends Currency, TOutput extends Currency>(pairs: Pair[], currencyIn: TInput, currencyAmountOut: CurrencyAmount<TOutput>, { maxNumResults, maxHops }?: BestTradeOptions, currentPairs?: Pair[], nextAmountOut?: CurrencyAmount<Currency>, bestTrades?: Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[]): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[];
197
+ }
198
+
199
+ interface V2ContractReadSpec {
200
+ readonly target: TronAddress;
201
+ readonly functionSelector: string;
202
+ readonly parameters?: readonly ContractParameter[];
203
+ readonly outputs?: readonly {
204
+ readonly type: string;
205
+ readonly name?: string;
206
+ }[];
207
+ readonly metadata?: Record<string, unknown>;
208
+ }
209
+ declare const V2_PAIR_READ_SELECTORS: {
210
+ readonly getReserves: "getReserves()";
211
+ readonly totalSupply: "totalSupply()";
212
+ readonly kLast: "kLast()";
213
+ readonly balanceOf: "balanceOf(address)";
214
+ readonly allowance: "allowance(address,address)";
215
+ };
216
+ declare const V2_FACTORY_READ_SELECTORS: {
217
+ readonly getPair: "getPair(address,address)";
218
+ readonly feeTo: "feeTo()";
219
+ };
220
+ declare const V2_ROUTER_READ_SELECTORS: {
221
+ readonly getAmountsOut: "getAmountsOut(uint256,address[])";
222
+ readonly getAmountsIn: "getAmountsIn(uint256,address[])";
223
+ readonly isAllowedTradingPair: "isAllowedTradingPair(address,address)";
224
+ };
225
+ interface V2RouterReadOptions {
226
+ readonly network: Network;
227
+ readonly router?: TronAddress;
228
+ }
229
+ interface V2FactoryReadOptions {
230
+ readonly network: Network;
231
+ readonly factory?: TronAddress;
232
+ }
233
+ interface BuildV2FactoryPairReadParams extends V2FactoryReadOptions {
234
+ readonly tokenA: TronAddress;
235
+ readonly tokenB: TronAddress;
236
+ }
237
+ interface BuildV2RouterAmountsOutReadParams extends V2RouterReadOptions {
238
+ readonly amountIn: BigintIsh;
239
+ readonly path: readonly TronAddress[];
240
+ }
241
+ interface BuildV2RouterAmountsInReadParams extends V2RouterReadOptions {
242
+ readonly amountOut: BigintIsh;
243
+ readonly path: readonly TronAddress[];
244
+ }
245
+ interface BuildV2RouterAllowedTradingPairReadParams extends V2RouterReadOptions {
246
+ readonly tokenA: TronAddress;
247
+ readonly tokenB: TronAddress;
248
+ }
249
+ declare function buildV2PairReservesRead(pair: TronAddress): V2ContractReadSpec;
250
+ declare function buildV2PairTotalSupplyRead(pair: TronAddress): V2ContractReadSpec;
251
+ declare function buildV2PairKLastRead(pair: TronAddress): V2ContractReadSpec;
252
+ declare function buildV2PairBalanceRead(pair: TronAddress, owner: TronAddress): V2ContractReadSpec;
253
+ declare function buildV2PairAllowanceRead(pair: TronAddress, owner: TronAddress, spender: TronAddress): V2ContractReadSpec;
254
+ declare function buildV2FactoryPairRead(params: BuildV2FactoryPairReadParams): V2ContractReadSpec;
255
+ declare function buildV2FactoryFeeToRead(params: V2FactoryReadOptions): V2ContractReadSpec;
256
+ declare function buildV2RouterAmountsOutRead(params: BuildV2RouterAmountsOutReadParams): V2ContractReadSpec;
257
+ declare function buildV2RouterAmountsInRead(params: BuildV2RouterAmountsInReadParams): V2ContractReadSpec;
258
+ declare function buildV2RouterAllowedTradingPairRead(params: BuildV2RouterAllowedTradingPairReadParams): V2ContractReadSpec;
259
+ declare function normalizeV2ReserveResult(result: readonly unknown[]): {
260
+ reserve0: string;
261
+ reserve1: string;
262
+ };
263
+ declare function normalizeV2AmountsResult(result: unknown): string[];
264
+
265
+ interface TradeOptions {
266
+ readonly allowedSlippage: Percent;
267
+ readonly ttl: number;
268
+ readonly recipient: string;
269
+ readonly feeOnTransfer?: boolean;
270
+ }
271
+ interface TradeOptionsDeadline extends Omit<TradeOptions, 'ttl'> {
272
+ readonly deadline: number;
273
+ }
274
+ interface SwapParameters {
275
+ readonly methodName: string;
276
+ readonly args: (string | string[])[];
277
+ readonly value: string;
278
+ }
279
+ declare abstract class Router {
280
+ private constructor();
281
+ static swapCallParameters(trade: Trade<Currency, Currency, TradeType>, options: TradeOptions | TradeOptionsDeadline): SwapParameters;
282
+ }
283
+
284
+ interface V2PairKey {
285
+ readonly network: Network;
286
+ readonly token0: Token;
287
+ readonly token1: Token;
288
+ }
289
+ interface V2PairState {
290
+ readonly pair: TronAddress;
291
+ readonly pairKey: V2PairKey;
292
+ readonly reserve0: string;
293
+ readonly reserve1: string;
294
+ readonly totalSupply?: string;
295
+ }
296
+ interface V2LiquidityAmounts {
297
+ readonly amountA: string;
298
+ readonly amountB: string;
299
+ }
300
+ interface V2AddLiquidityAmounts extends V2LiquidityAmounts {
301
+ readonly amountAMin: string;
302
+ readonly amountBMin: string;
303
+ }
304
+ interface V2RemoveLiquidityAmounts {
305
+ readonly liquidity: string;
306
+ readonly amountAMin: string;
307
+ readonly amountBMin: string;
308
+ }
309
+ interface V2TokenPairAmountInput {
310
+ readonly tokenA: Token;
311
+ readonly tokenB: Token;
312
+ readonly amountA: BigintIsh;
313
+ readonly amountB: BigintIsh;
314
+ }
315
+
316
+ declare const V2_INIT_CODE_HASH: Record<Network, `0x${string}`>;
317
+ interface ComputeV2PairAddressParams {
318
+ readonly network: Network;
319
+ readonly tokenA: TronAddress | string;
320
+ readonly tokenB: TronAddress | string;
321
+ readonly factory?: TronAddress | string;
322
+ readonly initCodeHash?: string;
323
+ readonly wrappedNative?: TronAddress | string;
324
+ }
325
+ declare function sortV2Tokens(tokenA: Token, tokenB: Token): readonly [Token, Token];
326
+ declare function tronAddressToEvmHex(address: string, label?: string): string;
327
+ declare function evmHexToTronAddress(address: string, label?: string): TronAddress;
328
+ declare function tronCreate2Address(params: {
329
+ readonly factoryAddress: string;
330
+ readonly salt: string;
331
+ readonly initCodeHash: string;
332
+ }): TronAddress;
333
+ declare function computeV2PairAddress(params: ComputeV2PairAddressParams): TronAddress;
334
+ declare function createV2PairKey(input: {
335
+ network: V2PairKey['network'];
336
+ tokenA: Token;
337
+ tokenB: Token;
338
+ }): V2PairKey;
339
+ declare function quoteV2LiquidityAmount(amountA: BigintIsh, reserveA: BigintIsh, reserveB: BigintIsh): string;
340
+ declare function applyV2SlippageMin(amount: BigintIsh, slippageTolerance: Percent): string;
341
+ declare function getV2AddLiquidityMinimums(amounts: {
342
+ amountA: BigintIsh;
343
+ amountB: BigintIsh;
344
+ }, slippageTolerance: Percent): {
345
+ amountAMin: string;
346
+ amountBMin: string;
347
+ };
348
+ declare function getV2RemoveLiquidityMinimums(amounts: {
349
+ amountA: BigintIsh;
350
+ amountB: BigintIsh;
351
+ }, slippageTolerance: Percent): {
352
+ amountAMin: string;
353
+ amountBMin: string;
354
+ };
355
+
356
+ export { BASIS_POINTS, type BestTradeOptions, type BuildV2AddLiquidityActionParams, type BuildV2AddLiquidityEthActionParams, type BuildV2FactoryPairReadParams, type BuildV2RemoveLiquidityActionParams, type BuildV2RemoveLiquidityEthActionParams, type BuildV2RouterAllowedTradingPairReadParams, type BuildV2RouterAmountsInReadParams, type BuildV2RouterAmountsOutReadParams, type BuildV2SwapEthForExactTokensActionParams, type BuildV2SwapExactEthForTokensActionParams, type BuildV2SwapExactTokensForEthActionParams, type BuildV2SwapExactTokensForTokensActionParams, type BuildV2SwapTokensForExactEthActionParams, type BuildV2SwapTokensForExactTokensActionParams, type ComputeV2PairAddressParams, FACTORY_ADDRESS, FACTORY_ADDRESS_MAP, FIVE, INIT_CODE_HASH, INIT_CODE_HASH_MAP, InsufficientInputAmountError, InsufficientReservesError, MINIMUM_LIQUIDITY, ONE, ONE_HUNDRED_PERCENT, Pair, Route, Router, type SwapParameters, Trade, type TradeOptions, type TradeOptionsDeadline, type V2ActionOptions, type V2AddLiquidityAmounts, type V2ContractReadSpec, type V2FactoryReadOptions, type V2LiquidityAmounts, type V2PairKey, type V2PairState, type V2RemoveLiquidityAmounts, type V2RouterReadOptions, type V2SwapActionOptions, type V2TokenPairAmountInput, V2_FACTORY_READ_SELECTORS, V2_INIT_CODE_HASH, V2_PAIR_READ_SELECTORS, V2_ROUTER_READ_SELECTORS, V2_ROUTER_SELECTORS, ZERO, ZERO_PERCENT, _1000, _997, applyV2SlippageMin, buildV2AddLiquidityAction, buildV2AddLiquidityEthAction, buildV2FactoryFeeToRead, buildV2FactoryPairRead, buildV2LpApproveAction, buildV2PairAllowanceRead, buildV2PairBalanceRead, buildV2PairKLastRead, buildV2PairReservesRead, buildV2PairTotalSupplyRead, buildV2RemoveLiquidityAction, buildV2RemoveLiquidityEthAction, buildV2RouterAllowedTradingPairRead, buildV2RouterAmountsInRead, buildV2RouterAmountsOutRead, buildV2SwapEthForExactTokensAction, buildV2SwapExactEthForTokensAction, buildV2SwapExactTokensForEthAction, buildV2SwapExactTokensForTokensAction, buildV2SwapTokensForExactEthAction, buildV2SwapTokensForExactTokensAction, computePairAddress, computeV2PairAddress, createV2PairKey, evmHexToTronAddress, getV2AddLiquidityMinimums, getV2RemoveLiquidityMinimums, inputOutputComparator, normalizeV2AmountsResult, normalizeV2ReserveResult, quoteV2LiquidityAmount, sortV2Tokens, tradeComparator, tronAddressToEvmHex, tronCreate2Address };