@galaxy-kj/core-stellar-sdk 2.0.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.
- package/LICENSE +21 -0
- package/README.md +576 -0
- package/dist/claimable-balances/claimable-balance-manager.d.ts +99 -0
- package/dist/claimable-balances/claimable-balance-manager.d.ts.map +1 -0
- package/dist/claimable-balances/claimable-balance-manager.js +352 -0
- package/dist/claimable-balances/claimable-balance-manager.js.map +1 -0
- package/dist/claimable-balances/helpers.d.ts +66 -0
- package/dist/claimable-balances/helpers.d.ts.map +1 -0
- package/dist/claimable-balances/helpers.js +179 -0
- package/dist/claimable-balances/helpers.js.map +1 -0
- package/dist/claimable-balances/index.d.ts +12 -0
- package/dist/claimable-balances/index.d.ts.map +1 -0
- package/dist/claimable-balances/index.js +14 -0
- package/dist/claimable-balances/index.js.map +1 -0
- package/dist/claimable-balances/predicate-builder.d.ts +66 -0
- package/dist/claimable-balances/predicate-builder.d.ts.map +1 -0
- package/dist/claimable-balances/predicate-builder.js +169 -0
- package/dist/claimable-balances/predicate-builder.js.map +1 -0
- package/dist/claimable-balances/types.d.ts +123 -0
- package/dist/claimable-balances/types.d.ts.map +1 -0
- package/dist/claimable-balances/types.js +9 -0
- package/dist/claimable-balances/types.js.map +1 -0
- package/dist/hooks/use-stellar.d.ts +48 -0
- package/dist/hooks/use-stellar.d.ts.map +1 -0
- package/dist/hooks/use-stellar.js +510 -0
- package/dist/hooks/use-stellar.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/liquidity-pools/calculations.d.ts +113 -0
- package/dist/liquidity-pools/calculations.d.ts.map +1 -0
- package/dist/liquidity-pools/calculations.js +291 -0
- package/dist/liquidity-pools/calculations.js.map +1 -0
- package/dist/liquidity-pools/helpers.d.ts +102 -0
- package/dist/liquidity-pools/helpers.d.ts.map +1 -0
- package/dist/liquidity-pools/helpers.js +219 -0
- package/dist/liquidity-pools/helpers.js.map +1 -0
- package/dist/liquidity-pools/index.d.ts +13 -0
- package/dist/liquidity-pools/index.d.ts.map +1 -0
- package/dist/liquidity-pools/index.js +18 -0
- package/dist/liquidity-pools/index.js.map +1 -0
- package/dist/liquidity-pools/liquidity-pool-manager.d.ts +106 -0
- package/dist/liquidity-pools/liquidity-pool-manager.d.ts.map +1 -0
- package/dist/liquidity-pools/liquidity-pool-manager.js +387 -0
- package/dist/liquidity-pools/liquidity-pool-manager.js.map +1 -0
- package/dist/liquidity-pools/types.d.ts +135 -0
- package/dist/liquidity-pools/types.d.ts.map +1 -0
- package/dist/liquidity-pools/types.js +6 -0
- package/dist/liquidity-pools/types.js.map +1 -0
- package/dist/liquidity-pools/validation.d.ts +75 -0
- package/dist/liquidity-pools/validation.d.ts.map +1 -0
- package/dist/liquidity-pools/validation.js +218 -0
- package/dist/liquidity-pools/validation.js.map +1 -0
- package/dist/services/stellar-service.d.ts +231 -0
- package/dist/services/stellar-service.d.ts.map +1 -0
- package/dist/services/stellar-service.js +674 -0
- package/dist/services/stellar-service.js.map +1 -0
- package/dist/soroban/helpers/contract-factory.d.ts +45 -0
- package/dist/soroban/helpers/contract-factory.d.ts.map +1 -0
- package/dist/soroban/helpers/contract-factory.js +84 -0
- package/dist/soroban/helpers/contract-factory.js.map +1 -0
- package/dist/soroban/helpers/token-contract-wrapper.d.ts +104 -0
- package/dist/soroban/helpers/token-contract-wrapper.d.ts.map +1 -0
- package/dist/soroban/helpers/token-contract-wrapper.js +286 -0
- package/dist/soroban/helpers/token-contract-wrapper.js.map +1 -0
- package/dist/soroban/index.d.ts +19 -0
- package/dist/soroban/index.d.ts.map +1 -0
- package/dist/soroban/index.js +19 -0
- package/dist/soroban/index.js.map +1 -0
- package/dist/soroban/soroban-contract-manager.d.ts +71 -0
- package/dist/soroban/soroban-contract-manager.d.ts.map +1 -0
- package/dist/soroban/soroban-contract-manager.js +376 -0
- package/dist/soroban/soroban-contract-manager.js.map +1 -0
- package/dist/soroban/types/contract-types.d.ts +156 -0
- package/dist/soroban/types/contract-types.d.ts.map +1 -0
- package/dist/soroban/types/contract-types.js +3 -0
- package/dist/soroban/types/contract-types.js.map +1 -0
- package/dist/soroban/utils/abi-parser.d.ts +90 -0
- package/dist/soroban/utils/abi-parser.d.ts.map +1 -0
- package/dist/soroban/utils/abi-parser.js +308 -0
- package/dist/soroban/utils/abi-parser.js.map +1 -0
- package/dist/soroban/utils/error-parser.d.ts +70 -0
- package/dist/soroban/utils/error-parser.d.ts.map +1 -0
- package/dist/soroban/utils/error-parser.js +302 -0
- package/dist/soroban/utils/error-parser.js.map +1 -0
- package/dist/soroban/utils/event-decoder.d.ts +91 -0
- package/dist/soroban/utils/event-decoder.d.ts.map +1 -0
- package/dist/soroban/utils/event-decoder.js +307 -0
- package/dist/soroban/utils/event-decoder.js.map +1 -0
- package/dist/soroban/utils/event-monitor.d.ts +93 -0
- package/dist/soroban/utils/event-monitor.d.ts.map +1 -0
- package/dist/soroban/utils/event-monitor.js +282 -0
- package/dist/soroban/utils/event-monitor.js.map +1 -0
- package/dist/soroban/utils/function-signature-builder.d.ts +98 -0
- package/dist/soroban/utils/function-signature-builder.d.ts.map +1 -0
- package/dist/soroban/utils/function-signature-builder.js +272 -0
- package/dist/soroban/utils/function-signature-builder.js.map +1 -0
- package/dist/soroban/utils/scval-converter.d.ts +48 -0
- package/dist/soroban/utils/scval-converter.d.ts.map +1 -0
- package/dist/soroban/utils/scval-converter.js +320 -0
- package/dist/soroban/utils/scval-converter.js.map +1 -0
- package/dist/sponsored-reserves/builders/sponsored-account-builder.d.ts +58 -0
- package/dist/sponsored-reserves/builders/sponsored-account-builder.d.ts.map +1 -0
- package/dist/sponsored-reserves/builders/sponsored-account-builder.js +159 -0
- package/dist/sponsored-reserves/builders/sponsored-account-builder.js.map +1 -0
- package/dist/sponsored-reserves/builders/sponsored-claimable-balance-builder.d.ts +104 -0
- package/dist/sponsored-reserves/builders/sponsored-claimable-balance-builder.d.ts.map +1 -0
- package/dist/sponsored-reserves/builders/sponsored-claimable-balance-builder.js +258 -0
- package/dist/sponsored-reserves/builders/sponsored-claimable-balance-builder.js.map +1 -0
- package/dist/sponsored-reserves/builders/sponsored-data-entry-builder.d.ts +96 -0
- package/dist/sponsored-reserves/builders/sponsored-data-entry-builder.d.ts.map +1 -0
- package/dist/sponsored-reserves/builders/sponsored-data-entry-builder.js +320 -0
- package/dist/sponsored-reserves/builders/sponsored-data-entry-builder.js.map +1 -0
- package/dist/sponsored-reserves/builders/sponsored-signer-builder.d.ts +100 -0
- package/dist/sponsored-reserves/builders/sponsored-signer-builder.d.ts.map +1 -0
- package/dist/sponsored-reserves/builders/sponsored-signer-builder.js +271 -0
- package/dist/sponsored-reserves/builders/sponsored-signer-builder.js.map +1 -0
- package/dist/sponsored-reserves/builders/sponsored-trustline-builder.d.ts +87 -0
- package/dist/sponsored-reserves/builders/sponsored-trustline-builder.d.ts.map +1 -0
- package/dist/sponsored-reserves/builders/sponsored-trustline-builder.js +281 -0
- package/dist/sponsored-reserves/builders/sponsored-trustline-builder.js.map +1 -0
- package/dist/sponsored-reserves/index.d.ts +20 -0
- package/dist/sponsored-reserves/index.d.ts.map +1 -0
- package/dist/sponsored-reserves/index.js +24 -0
- package/dist/sponsored-reserves/index.js.map +1 -0
- package/dist/sponsored-reserves/services/sponsored-reserves-manager.d.ts +144 -0
- package/dist/sponsored-reserves/services/sponsored-reserves-manager.d.ts.map +1 -0
- package/dist/sponsored-reserves/services/sponsored-reserves-manager.js +536 -0
- package/dist/sponsored-reserves/services/sponsored-reserves-manager.js.map +1 -0
- package/dist/sponsored-reserves/templates/claimable-balance-template.d.ts +96 -0
- package/dist/sponsored-reserves/templates/claimable-balance-template.d.ts.map +1 -0
- package/dist/sponsored-reserves/templates/claimable-balance-template.js +306 -0
- package/dist/sponsored-reserves/templates/claimable-balance-template.js.map +1 -0
- package/dist/sponsored-reserves/templates/multi-operation-template.d.ts +99 -0
- package/dist/sponsored-reserves/templates/multi-operation-template.d.ts.map +1 -0
- package/dist/sponsored-reserves/templates/multi-operation-template.js +313 -0
- package/dist/sponsored-reserves/templates/multi-operation-template.js.map +1 -0
- package/dist/sponsored-reserves/templates/user-onboarding-template.d.ts +79 -0
- package/dist/sponsored-reserves/templates/user-onboarding-template.d.ts.map +1 -0
- package/dist/sponsored-reserves/templates/user-onboarding-template.js +262 -0
- package/dist/sponsored-reserves/templates/user-onboarding-template.js.map +1 -0
- package/dist/sponsored-reserves/types/sponsored-reserves-types.d.ts +364 -0
- package/dist/sponsored-reserves/types/sponsored-reserves-types.d.ts.map +1 -0
- package/dist/sponsored-reserves/types/sponsored-reserves-types.js +9 -0
- package/dist/sponsored-reserves/types/sponsored-reserves-types.js.map +1 -0
- package/dist/sponsored-reserves/utils/cost-calculator.d.ts +98 -0
- package/dist/sponsored-reserves/utils/cost-calculator.d.ts.map +1 -0
- package/dist/sponsored-reserves/utils/cost-calculator.js +238 -0
- package/dist/sponsored-reserves/utils/cost-calculator.js.map +1 -0
- package/dist/sponsored-reserves/utils/sponsorship-validation.d.ts +112 -0
- package/dist/sponsored-reserves/utils/sponsorship-validation.d.ts.map +1 -0
- package/dist/sponsored-reserves/utils/sponsorship-validation.js +394 -0
- package/dist/sponsored-reserves/utils/sponsorship-validation.js.map +1 -0
- package/dist/types/stellar-sdk-compat.d.ts +25 -0
- package/dist/types/stellar-sdk-compat.d.ts.map +1 -0
- package/dist/types/stellar-sdk-compat.js +44 -0
- package/dist/types/stellar-sdk-compat.js.map +1 -0
- package/dist/types/stellar-types.d.ts +160 -0
- package/dist/types/stellar-types.d.ts.map +1 -0
- package/dist/types/stellar-types.js +9 -0
- package/dist/types/stellar-types.js.map +1 -0
- package/dist/utils/encryption.utils.d.ts +9 -0
- package/dist/utils/encryption.utils.d.ts.map +1 -0
- package/dist/utils/encryption.utils.js +44 -0
- package/dist/utils/encryption.utils.js.map +1 -0
- package/dist/utils/network-utils.d.ts +138 -0
- package/dist/utils/network-utils.d.ts.map +1 -0
- package/dist/utils/network-utils.js +240 -0
- package/dist/utils/network-utils.js.map +1 -0
- package/dist/utils/stellar-utils.d.ts +114 -0
- package/dist/utils/stellar-utils.d.ts.map +1 -0
- package/dist/utils/stellar-utils.js +186 -0
- package/dist/utils/stellar-utils.js.map +1 -0
- package/dist/utils/supabase-client.d.ts +2 -0
- package/dist/utils/supabase-client.d.ts.map +1 -0
- package/dist/utils/supabase-client.js +9 -0
- package/dist/utils/supabase-client.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Helper functions for liquidity pool operations
|
|
3
|
+
* @description Utility functions for common liquidity pool patterns
|
|
4
|
+
* @author Galaxy DevKit Team
|
|
5
|
+
* @version 1.0.0
|
|
6
|
+
* @since 2024-01-22
|
|
7
|
+
*/
|
|
8
|
+
import BigNumber from 'bignumber.js';
|
|
9
|
+
import { calculateMinimumAmounts } from './calculations';
|
|
10
|
+
/**
|
|
11
|
+
* Calculates optimal deposit amounts maintaining pool ratio
|
|
12
|
+
* @param maxAmountA - Maximum amount of asset A user wants to deposit
|
|
13
|
+
* @param maxAmountB - Maximum amount of asset B user wants to deposit
|
|
14
|
+
* @param pool - Current pool state
|
|
15
|
+
* @param slippage - Slippage tolerance (default: 0.01 for 1%)
|
|
16
|
+
* @returns Optimal deposit amounts
|
|
17
|
+
*/
|
|
18
|
+
export function calculateOptimalDeposit(maxAmountA, maxAmountB, pool, slippage = '0.01') {
|
|
19
|
+
const maxA = new BigNumber(maxAmountA);
|
|
20
|
+
const maxB = new BigNumber(maxAmountB);
|
|
21
|
+
const reserveA = new BigNumber(pool.reserveA);
|
|
22
|
+
const reserveB = new BigNumber(pool.reserveB);
|
|
23
|
+
// Calculate pool ratio
|
|
24
|
+
const poolRatio = reserveB.dividedBy(reserveA);
|
|
25
|
+
// Calculate how much B is needed for maxA
|
|
26
|
+
const neededB = maxA.multipliedBy(poolRatio);
|
|
27
|
+
// Calculate how much A is needed for maxB
|
|
28
|
+
const neededA = maxB.dividedBy(poolRatio);
|
|
29
|
+
let optimalA;
|
|
30
|
+
let optimalB;
|
|
31
|
+
// Use the constraining amount
|
|
32
|
+
if (neededB.isLessThanOrEqualTo(maxB)) {
|
|
33
|
+
// A is the limiting factor
|
|
34
|
+
optimalA = maxA.toFixed(7);
|
|
35
|
+
optimalB = neededB.toFixed(7);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
// B is the limiting factor
|
|
39
|
+
optimalA = neededA.toFixed(7);
|
|
40
|
+
optimalB = maxB.toFixed(7);
|
|
41
|
+
}
|
|
42
|
+
// Calculate minimum amounts with slippage protection
|
|
43
|
+
const { minAmountA, minAmountB } = calculateMinimumAmounts(optimalA, optimalB, slippage);
|
|
44
|
+
return {
|
|
45
|
+
amountA: optimalA,
|
|
46
|
+
amountB: optimalB,
|
|
47
|
+
minAmountA,
|
|
48
|
+
minAmountB,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Formats pool assets as a readable string
|
|
53
|
+
* @param pool - Liquidity pool
|
|
54
|
+
* @returns Formatted string "ASSET_A/ASSET_B"
|
|
55
|
+
*/
|
|
56
|
+
export function formatPoolAssets(pool) {
|
|
57
|
+
const assetACode = pool.assetA.isNative() ? 'XLM' : pool.assetA.getCode();
|
|
58
|
+
const assetBCode = pool.assetB.isNative() ? 'XLM' : pool.assetB.getCode();
|
|
59
|
+
return `${assetACode}/${assetBCode}`;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Calculates the value of user's shares in the pool
|
|
63
|
+
* @param shares - User's share amount
|
|
64
|
+
* @param pool - Pool state
|
|
65
|
+
* @returns Value in terms of each asset
|
|
66
|
+
*/
|
|
67
|
+
export function calculateShareValue(shares, pool) {
|
|
68
|
+
const userShares = new BigNumber(shares);
|
|
69
|
+
const totalShares = new BigNumber(pool.totalShares);
|
|
70
|
+
if (totalShares.isZero()) {
|
|
71
|
+
return { valueA: '0', valueB: '0' };
|
|
72
|
+
}
|
|
73
|
+
const shareRatio = userShares.dividedBy(totalShares);
|
|
74
|
+
const valueA = shareRatio.multipliedBy(pool.reserveA).toFixed(7);
|
|
75
|
+
const valueB = shareRatio.multipliedBy(pool.reserveB).toFixed(7);
|
|
76
|
+
return { valueA, valueB };
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Checks if a deposit would significantly impact pool price
|
|
80
|
+
* @param amountA - Amount of asset A to deposit
|
|
81
|
+
* @param amountB - Amount of asset B to deposit
|
|
82
|
+
* @param pool - Current pool state
|
|
83
|
+
* @param threshold - Price impact threshold (default: 0.01 for 1%)
|
|
84
|
+
* @returns True if price impact exceeds threshold
|
|
85
|
+
*/
|
|
86
|
+
export function wouldImpactPrice(amountA, amountB, pool, threshold = '0.01') {
|
|
87
|
+
const depositA = new BigNumber(amountA);
|
|
88
|
+
const depositB = new BigNumber(amountB);
|
|
89
|
+
const reserveA = new BigNumber(pool.reserveA);
|
|
90
|
+
const reserveB = new BigNumber(pool.reserveB);
|
|
91
|
+
// Calculate current ratio
|
|
92
|
+
const currentRatio = reserveB.dividedBy(reserveA);
|
|
93
|
+
// Calculate new ratio after deposit
|
|
94
|
+
const newReserveA = reserveA.plus(depositA);
|
|
95
|
+
const newReserveB = reserveB.plus(depositB);
|
|
96
|
+
const newRatio = newReserveB.dividedBy(newReserveA);
|
|
97
|
+
// Calculate price change
|
|
98
|
+
const priceChange = newRatio.minus(currentRatio).abs().dividedBy(currentRatio);
|
|
99
|
+
return priceChange.isGreaterThan(threshold);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Calculates the break-even price for a liquidity position
|
|
103
|
+
* Useful for understanding when to exit a position
|
|
104
|
+
* @param initialAmountA - Initial deposit of asset A
|
|
105
|
+
* @param initialAmountB - Initial deposit of asset B
|
|
106
|
+
* @param currentReserveA - Current pool reserve A
|
|
107
|
+
* @param currentReserveB - Current pool reserve B
|
|
108
|
+
* @returns Break-even price ratio
|
|
109
|
+
*/
|
|
110
|
+
export function calculateBreakEvenPrice(initialAmountA, initialAmountB, currentReserveA, currentReserveB) {
|
|
111
|
+
const initA = new BigNumber(initialAmountA);
|
|
112
|
+
const initB = new BigNumber(initialAmountB);
|
|
113
|
+
// Initial average price
|
|
114
|
+
const initialPrice = initB.dividedBy(initA);
|
|
115
|
+
return initialPrice.toFixed(7);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Estimates impermanent loss for a liquidity position
|
|
119
|
+
* @param initialPrice - Price when position was opened
|
|
120
|
+
* @param currentPrice - Current price
|
|
121
|
+
* @returns Impermanent loss as percentage
|
|
122
|
+
*/
|
|
123
|
+
export function calculateImpermanentLoss(initialPrice, currentPrice) {
|
|
124
|
+
const p0 = new BigNumber(initialPrice);
|
|
125
|
+
const p1 = new BigNumber(currentPrice);
|
|
126
|
+
// IL formula: 2 * sqrt(priceRatio) / (1 + priceRatio) - 1
|
|
127
|
+
const priceRatio = p1.dividedBy(p0);
|
|
128
|
+
const sqrtRatio = priceRatio.sqrt();
|
|
129
|
+
const il = new BigNumber(2)
|
|
130
|
+
.multipliedBy(sqrtRatio)
|
|
131
|
+
.dividedBy(new BigNumber(1).plus(priceRatio))
|
|
132
|
+
.minus(1)
|
|
133
|
+
.abs();
|
|
134
|
+
return il.multipliedBy(100).toFixed(2);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Checks if pool has sufficient liquidity for an operation
|
|
138
|
+
* @param requiredAmountA - Required amount of asset A
|
|
139
|
+
* @param requiredAmountB - Required amount of asset B
|
|
140
|
+
* @param pool - Pool state
|
|
141
|
+
* @param safetyMargin - Safety margin as percentage (default: 0.01 for 1%)
|
|
142
|
+
* @returns True if pool has sufficient liquidity
|
|
143
|
+
*/
|
|
144
|
+
export function hasSufficientLiquidity(requiredAmountA, requiredAmountB, pool, safetyMargin = '0.01') {
|
|
145
|
+
const reqA = new BigNumber(requiredAmountA);
|
|
146
|
+
const reqB = new BigNumber(requiredAmountB);
|
|
147
|
+
const resA = new BigNumber(pool.reserveA);
|
|
148
|
+
const resB = new BigNumber(pool.reserveB);
|
|
149
|
+
// Apply safety margin
|
|
150
|
+
const margin = new BigNumber(1).minus(safetyMargin);
|
|
151
|
+
const availableA = resA.multipliedBy(margin);
|
|
152
|
+
const availableB = resB.multipliedBy(margin);
|
|
153
|
+
return reqA.isLessThanOrEqualTo(availableA) && reqB.isLessThanOrEqualTo(availableB);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Calculates annual percentage rate (APR) from fees
|
|
157
|
+
* @param dailyFees - Daily fees earned
|
|
158
|
+
* @param totalLiquidity - Total liquidity in pool
|
|
159
|
+
* @returns APR as percentage
|
|
160
|
+
*/
|
|
161
|
+
export function calculateAPRFromFees(dailyFees, totalLiquidity) {
|
|
162
|
+
const fees = new BigNumber(dailyFees);
|
|
163
|
+
const liquidity = new BigNumber(totalLiquidity);
|
|
164
|
+
if (liquidity.isZero()) {
|
|
165
|
+
return '0.00';
|
|
166
|
+
}
|
|
167
|
+
// APR = (dailyFees / totalLiquidity) * 365 * 100
|
|
168
|
+
const apr = fees.dividedBy(liquidity).multipliedBy(365).multipliedBy(100);
|
|
169
|
+
return apr.toFixed(2);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Formats an amount to Stellar's 7 decimal precision
|
|
173
|
+
* @param amount - Amount to format
|
|
174
|
+
* @returns Formatted amount
|
|
175
|
+
*/
|
|
176
|
+
export function toStellarPrecision(amount) {
|
|
177
|
+
return new BigNumber(amount).toFixed(7, BigNumber.ROUND_DOWN);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Checks if two assets match (useful for finding pools)
|
|
181
|
+
* @param asset1 - First asset
|
|
182
|
+
* @param asset2 - Second asset
|
|
183
|
+
* @returns True if assets are the same
|
|
184
|
+
*/
|
|
185
|
+
export function assetsEqual(asset1, asset2) {
|
|
186
|
+
if (asset1.isNative() && asset2.isNative()) {
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
if (asset1.isNative() || asset2.isNative()) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
return (asset1.getCode() === asset2.getCode() &&
|
|
193
|
+
asset1.getIssuer() === asset2.getIssuer());
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Sorts two assets lexicographically (required for pool ID generation)
|
|
197
|
+
* @param assetA - First asset
|
|
198
|
+
* @param assetB - Second asset
|
|
199
|
+
* @returns Sorted assets [first, second]
|
|
200
|
+
*/
|
|
201
|
+
export function sortAssets(assetA, assetB) {
|
|
202
|
+
const codeA = assetA.isNative() ? 'XLM' : assetA.getCode();
|
|
203
|
+
const codeB = assetB.isNative() ? 'XLM' : assetB.getCode();
|
|
204
|
+
// Sort by code first
|
|
205
|
+
if (codeA < codeB) {
|
|
206
|
+
return [assetA, assetB];
|
|
207
|
+
}
|
|
208
|
+
else if (codeA > codeB) {
|
|
209
|
+
return [assetB, assetA];
|
|
210
|
+
}
|
|
211
|
+
// If codes are the same, sort by issuer
|
|
212
|
+
if (!assetA.isNative() && !assetB.isNative()) {
|
|
213
|
+
const issuerA = assetA.getIssuer();
|
|
214
|
+
const issuerB = assetB.getIssuer();
|
|
215
|
+
return issuerA < issuerB ? [assetA, assetB] : [assetB, assetA];
|
|
216
|
+
}
|
|
217
|
+
return [assetA, assetB];
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/liquidity-pools/helpers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,SAAS,MAAM,cAAc,CAAC;AAGrC,OAAO,EAAE,uBAAuB,EAAwB,MAAM,gBAAgB,CAAC;AAE/E;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CACrC,UAAkB,EAClB,UAAkB,EAClB,IAAmB,EACnB,WA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AAM,CAAC,OAAO,EAAE,CAAC;IAC3D,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IAE3D,qBAAqB;IACrB,IAAI,KAAK,GAAG,KAAK,EAAE,CAAC;QAClB,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1B,CAAC;SAAM,IAAI,KAAK,GAAG,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1B,CAAC;IAED,wCAAwC;IACxC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;QAC7C,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;QACnC,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;QAEnC,OAAO,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjE,CAAC;IAED,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Liquidity Pools module exports
|
|
3
|
+
* @description Public API exports for liquidity pool operations
|
|
4
|
+
* @author Galaxy DevKit Team
|
|
5
|
+
* @version 1.0.0
|
|
6
|
+
* @since 2024-01-22
|
|
7
|
+
*/
|
|
8
|
+
export type { LiquidityPool, LiquidityPoolDeposit, LiquidityPoolWithdraw, QueryPoolsParams, LiquidityPoolResult, PoolAnalytics, PriceImpact, DepositEstimate, WithdrawEstimate, PoolShare, PoolTrade, } from './types';
|
|
9
|
+
export { LiquidityPoolManager } from './liquidity-pool-manager';
|
|
10
|
+
export { calculateConstantProduct, calculateSpotPrice, calculateDepositShares, calculateWithdrawAmounts, calculatePriceImpact, calculateSwapOutput, estimateDeposit, estimateWithdraw, calculateMinimumAmounts, calculatePriceBounds, } from './calculations';
|
|
11
|
+
export { validatePoolId, validateAmount, validateSlippage, validatePrice, validatePublicKey, validateDepositParams, validateWithdrawParams, validateSufficientShares, validateMinimumLiquidity, } from './validation';
|
|
12
|
+
export { calculateOptimalDeposit, formatPoolAssets, calculateShareValue, wouldImpactPrice, calculateBreakEvenPrice, calculateImpermanentLoss, hasSufficientLiquidity, calculateAPRFromFees, toStellarPrecision, assetsEqual, sortAssets, } from './helpers';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/liquidity-pools/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,YAAY,EACV,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EACrB,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,SAAS,EACT,SAAS,GACV,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAGhE,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,sBAAsB,EACtB,wBAAwB,EACxB,oBAAoB,EACpB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,EACvB,wBAAwB,EACxB,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,EAClB,WAAW,EACX,UAAU,GACX,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Liquidity Pools module exports
|
|
3
|
+
* @description Public API exports for liquidity pool operations
|
|
4
|
+
* @author Galaxy DevKit Team
|
|
5
|
+
* @version 1.0.0
|
|
6
|
+
* @since 2024-01-22
|
|
7
|
+
*/
|
|
8
|
+
// Export manager
|
|
9
|
+
export { LiquidityPoolManager } from './liquidity-pool-manager';
|
|
10
|
+
// Export calculation functions
|
|
11
|
+
export { calculateConstantProduct, calculateSpotPrice, calculateDepositShares, calculateWithdrawAmounts, calculatePriceImpact, calculateSwapOutput, estimateDeposit, estimateWithdraw, calculateMinimumAmounts, calculatePriceBounds, } from './calculations';
|
|
12
|
+
// Export validation functions
|
|
13
|
+
export { validatePoolId, validateAmount, validateSlippage, validatePrice, validatePublicKey, validateDepositParams, validateWithdrawParams, validateSufficientShares, validateMinimumLiquidity, } from './validation';
|
|
14
|
+
// Export helper functions
|
|
15
|
+
export { calculateOptimalDeposit, formatPoolAssets, calculateShareValue, wouldImpactPrice, calculateBreakEvenPrice, calculateImpermanentLoss, hasSufficientLiquidity, calculateAPRFromFees, toStellarPrecision, assetsEqual, sortAssets, } from './helpers';
|
|
16
|
+
// Note: Pool IDs are generated by the Stellar network and retrieved via Horizon API.
|
|
17
|
+
// Use LiquidityPoolManager.queryPools() or getPoolsForAssets() to find pools for specific assets.
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/liquidity-pools/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAiBH,iBAAiB;AACjB,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,+BAA+B;AAC/B,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,sBAAsB,EACtB,wBAAwB,EACxB,oBAAoB,EACpB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AAExB,8BAA8B;AAC9B,OAAO,EACL,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,cAAc,CAAC;AAEtB,0BAA0B;AAC1B,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,EACvB,wBAAwB,EACxB,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,EAClB,WAAW,EACX,UAAU,GACX,MAAM,WAAW,CAAC;AAEnB,qFAAqF;AACrF,kGAAkG"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Liquidity Pool Manager
|
|
3
|
+
* @description Manages liquidity pool operations on Stellar network
|
|
4
|
+
* @author Galaxy DevKit Team
|
|
5
|
+
* @version 1.0.0
|
|
6
|
+
* @since 2024-01-22
|
|
7
|
+
*/
|
|
8
|
+
import { Asset, Horizon } from '@stellar/stellar-sdk';
|
|
9
|
+
import { LiquidityPool, LiquidityPoolDeposit, LiquidityPoolWithdraw, LiquidityPoolResult, QueryPoolsParams, PoolAnalytics, DepositEstimate, WithdrawEstimate, PoolShare } from './types';
|
|
10
|
+
import { Wallet } from '../types/stellar-types';
|
|
11
|
+
/**
|
|
12
|
+
* Liquidity Pool Manager class
|
|
13
|
+
* @class LiquidityPoolManager
|
|
14
|
+
* @description Handles all liquidity pool operations
|
|
15
|
+
*/
|
|
16
|
+
export declare class LiquidityPoolManager {
|
|
17
|
+
private server;
|
|
18
|
+
private networkPassphrase;
|
|
19
|
+
constructor(server: Horizon.Server, networkPassphrase: string);
|
|
20
|
+
/**
|
|
21
|
+
* Deposits liquidity to a pool
|
|
22
|
+
* @param wallet - Source wallet
|
|
23
|
+
* @param params - Deposit parameters
|
|
24
|
+
* @param password - Wallet password for decryption
|
|
25
|
+
* @returns Promise<LiquidityPoolResult>
|
|
26
|
+
* @throws {Error} If validation fails or transaction fails
|
|
27
|
+
*/
|
|
28
|
+
depositLiquidity(wallet: Wallet, params: LiquidityPoolDeposit, password: string): Promise<LiquidityPoolResult>;
|
|
29
|
+
/**
|
|
30
|
+
* Withdraws liquidity from a pool
|
|
31
|
+
* @param wallet - Source wallet
|
|
32
|
+
* @param params - Withdrawal parameters
|
|
33
|
+
* @param password - Wallet password for decryption
|
|
34
|
+
* @returns Promise<LiquidityPoolResult>
|
|
35
|
+
* @throws {Error} If validation fails or transaction fails
|
|
36
|
+
*/
|
|
37
|
+
withdrawLiquidity(wallet: Wallet, params: LiquidityPoolWithdraw, password: string): Promise<LiquidityPoolResult>;
|
|
38
|
+
/**
|
|
39
|
+
* Gets liquidity pool details by ID
|
|
40
|
+
* @param poolId - Pool ID
|
|
41
|
+
* @returns Promise<LiquidityPool>
|
|
42
|
+
* @throws {Error} If pool not found or fetch fails
|
|
43
|
+
*/
|
|
44
|
+
getPoolDetails(poolId: string): Promise<LiquidityPool>;
|
|
45
|
+
/**
|
|
46
|
+
* Queries liquidity pools
|
|
47
|
+
* @param params - Query parameters
|
|
48
|
+
* @returns Promise<LiquidityPool[]>
|
|
49
|
+
*/
|
|
50
|
+
queryPools(params?: QueryPoolsParams): Promise<LiquidityPool[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Gets user's share balance for a specific pool
|
|
53
|
+
* @param publicKey - User's public key
|
|
54
|
+
* @param poolId - Pool ID
|
|
55
|
+
* @returns Promise<string> - Share balance
|
|
56
|
+
*/
|
|
57
|
+
getUserShares(publicKey: string, poolId: string): Promise<string>;
|
|
58
|
+
/**
|
|
59
|
+
* Gets all pool shares for a user
|
|
60
|
+
* @param publicKey - User's public key
|
|
61
|
+
* @returns Promise<PoolShare[]>
|
|
62
|
+
*/
|
|
63
|
+
getUserPoolShares(publicKey: string): Promise<PoolShare[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Gets pool analytics with on-chain data (TVL and share price)
|
|
66
|
+
* Note: volume24h, fees24h, and apy require historical data from external analytics services
|
|
67
|
+
* @param poolId - Pool ID
|
|
68
|
+
* @returns Promise<PoolAnalytics>
|
|
69
|
+
*/
|
|
70
|
+
getPoolAnalytics(poolId: string): Promise<PoolAnalytics>;
|
|
71
|
+
/**
|
|
72
|
+
* Estimates deposit operation
|
|
73
|
+
* @param poolId - Pool ID
|
|
74
|
+
* @param amountA - Amount of asset A
|
|
75
|
+
* @param amountB - Amount of asset B
|
|
76
|
+
* @returns Promise<DepositEstimate>
|
|
77
|
+
*/
|
|
78
|
+
estimatePoolDeposit(poolId: string, amountA: string, amountB: string): Promise<DepositEstimate>;
|
|
79
|
+
/**
|
|
80
|
+
* Estimates withdrawal operation
|
|
81
|
+
* @param poolId - Pool ID
|
|
82
|
+
* @param shares - Shares to withdraw
|
|
83
|
+
* @returns Promise<WithdrawEstimate>
|
|
84
|
+
*/
|
|
85
|
+
estimatePoolWithdraw(poolId: string, shares: string): Promise<WithdrawEstimate>;
|
|
86
|
+
/**
|
|
87
|
+
* Gets liquidity pools for specific assets
|
|
88
|
+
* @param assetA - First asset
|
|
89
|
+
* @param assetB - Second asset
|
|
90
|
+
* @param limit - Number of results to return
|
|
91
|
+
* @returns Promise<LiquidityPool[]>
|
|
92
|
+
*/
|
|
93
|
+
getPoolsForAssets(assetA: Asset, assetB: Asset, limit?: number): Promise<LiquidityPool[]>;
|
|
94
|
+
/**
|
|
95
|
+
* Maps Horizon API pool to our LiquidityPool type
|
|
96
|
+
* @param horizonPool - Horizon API pool
|
|
97
|
+
* @returns LiquidityPool
|
|
98
|
+
*/
|
|
99
|
+
private mapHorizonPoolToLiquidityPool;
|
|
100
|
+
/**
|
|
101
|
+
* Estimates transaction fee
|
|
102
|
+
* @returns Promise<string>
|
|
103
|
+
*/
|
|
104
|
+
private estimateFee;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=liquidity-pool-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liquidity-pool-manager.d.ts","sourceRoot":"","sources":["../../src/liquidity-pools/liquidity-pool-manager.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAEL,KAAK,EAGL,OAAO,EAGR,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,SAAS,EACV,MAAM,SAAS,CAAC;AAajB,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAGhD;;;;GAIG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,iBAAiB,CAAS;gBAEtB,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,iBAAiB,EAAE,MAAM;IAK7D;;;;;;;OAOG;IACG,gBAAgB,CACpB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,oBAAoB,EAC5B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,mBAAmB,CAAC;IA4E/B;;;;;;;OAOG;IACG,iBAAiB,CACrB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,qBAAqB,EAC7B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,mBAAmB,CAAC;IAyE/B;;;;;OAKG;IACG,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAoB5D;;;;OAIG;IACG,UAAU,CAAC,MAAM,GAAE,gBAAqB,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAkCzE;;;;;OAKG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAwBvE;;;;OAIG;IACG,iBAAiB,CAAC,SAA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