@meteora-ag/zap-sdk 1.2.0 → 1.3.1
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/dist/index.d.mts +94 -97
- package/dist/index.d.ts +94 -97
- package/dist/index.js +219 -52
- package/dist/index.mjs +222 -53
- package/package.json +21 -11
package/dist/index.js
CHANGED
|
@@ -114,6 +114,8 @@ __export(index_exports, {
|
|
|
114
114
|
getOrCreateATAInstruction: () => getOrCreateATAInstruction,
|
|
115
115
|
getTokenAccountBalance: () => getTokenAccountBalance,
|
|
116
116
|
getTokenProgramFromMint: () => getTokenProgramFromMint,
|
|
117
|
+
isSingleSidedA: () => isSingleSidedA,
|
|
118
|
+
isSingleSidedB: () => isSingleSidedB,
|
|
117
119
|
toProgramStrategyType: () => toProgramStrategyType,
|
|
118
120
|
unwrapSOLInstruction: () => unwrapSOLInstruction,
|
|
119
121
|
wrapSOLInstruction: () => wrapSOLInstruction
|
|
@@ -660,6 +662,9 @@ var idl_default = {
|
|
|
660
662
|
{
|
|
661
663
|
name: "TransferHookMultiReward",
|
|
662
664
|
fields: ["u8"]
|
|
665
|
+
},
|
|
666
|
+
{
|
|
667
|
+
name: "TransferHookReferral"
|
|
663
668
|
}
|
|
664
669
|
]
|
|
665
670
|
}
|
|
@@ -1792,9 +1797,8 @@ function getJupiterQuote(_0, _1, _2, _3, _4) {
|
|
|
1792
1797
|
dynamicSlippage: dynamicSlippage.toString()
|
|
1793
1798
|
});
|
|
1794
1799
|
const url = `${config.jupiterApiUrl || DEFAULT_JUPITER_API_URL}/swap/v1/quote?${params.toString()}`;
|
|
1795
|
-
let response = null;
|
|
1796
1800
|
try {
|
|
1797
|
-
response = yield fetch(url, {
|
|
1801
|
+
const response = yield fetch(url, {
|
|
1798
1802
|
method: "GET",
|
|
1799
1803
|
headers: __spreadValues({
|
|
1800
1804
|
Accept: "application/json"
|
|
@@ -1803,11 +1807,11 @@ function getJupiterQuote(_0, _1, _2, _3, _4) {
|
|
|
1803
1807
|
if (!response.ok) {
|
|
1804
1808
|
return null;
|
|
1805
1809
|
}
|
|
1810
|
+
const result = yield response.json();
|
|
1811
|
+
return result;
|
|
1806
1812
|
} catch (error) {
|
|
1807
1813
|
return null;
|
|
1808
1814
|
}
|
|
1809
|
-
const result = yield response.json();
|
|
1810
|
-
return result;
|
|
1811
1815
|
});
|
|
1812
1816
|
}
|
|
1813
1817
|
function getJupiterSwapInstruction(_0, _1) {
|
|
@@ -1993,6 +1997,12 @@ function getDammV2RemainingAccounts(_0, _1, _2, _3) {
|
|
|
1993
1997
|
return remainingAccounts;
|
|
1994
1998
|
});
|
|
1995
1999
|
}
|
|
2000
|
+
function isSingleSidedA(poolState) {
|
|
2001
|
+
return poolState.collectFeeMode !== import_cp_amm_sdk.CollectFeeMode.Compounding && poolState.sqrtPrice.eq(poolState.sqrtMinPrice);
|
|
2002
|
+
}
|
|
2003
|
+
function isSingleSidedB(poolState) {
|
|
2004
|
+
return poolState.collectFeeMode !== import_cp_amm_sdk.CollectFeeMode.Compounding && poolState.sqrtPrice.eq(poolState.sqrtMaxPrice);
|
|
2005
|
+
}
|
|
1996
2006
|
function createDammV2SwapPayload(amountIn, minimumSwapAmountOut) {
|
|
1997
2007
|
return Buffer.concat([
|
|
1998
2008
|
Buffer.from(DAMM_V2_SWAP_DISCRIMINATOR),
|
|
@@ -2277,7 +2287,7 @@ function getDlmmRemainingAccounts(connection, lbPair, user, userInputTokenAccoun
|
|
|
2277
2287
|
},
|
|
2278
2288
|
{
|
|
2279
2289
|
isSigner: false,
|
|
2280
|
-
isWritable:
|
|
2290
|
+
isWritable: true,
|
|
2281
2291
|
pubkey: binArrayBitmapExtension
|
|
2282
2292
|
},
|
|
2283
2293
|
{
|
|
@@ -3526,30 +3536,76 @@ var Zap = class {
|
|
|
3526
3536
|
tokenBProgram
|
|
3527
3537
|
);
|
|
3528
3538
|
const inputTokenDecimal = inputTokenMint.equals(tokenAMint) ? tokenADecimal : tokenBDecimal;
|
|
3539
|
+
const collectFeeMode = poolState.collectFeeMode;
|
|
3529
3540
|
const poolBalanceTokenA = (0, import_cp_amm_sdk3.getAmountAFromLiquidityDelta)(
|
|
3530
3541
|
poolState.sqrtPrice,
|
|
3531
3542
|
poolState.sqrtMaxPrice,
|
|
3532
3543
|
poolState.liquidity,
|
|
3533
|
-
import_cp_amm_sdk3.Rounding.Down
|
|
3544
|
+
import_cp_amm_sdk3.Rounding.Down,
|
|
3545
|
+
collectFeeMode,
|
|
3546
|
+
poolState.tokenAAmount,
|
|
3547
|
+
poolState.liquidity
|
|
3534
3548
|
);
|
|
3535
3549
|
const poolBalanceTokenB = (0, import_cp_amm_sdk3.getAmountBFromLiquidityDelta)(
|
|
3536
3550
|
poolState.sqrtMinPrice,
|
|
3537
3551
|
poolState.sqrtPrice,
|
|
3538
3552
|
poolState.liquidity,
|
|
3539
|
-
import_cp_amm_sdk3.Rounding.Down
|
|
3553
|
+
import_cp_amm_sdk3.Rounding.Down,
|
|
3554
|
+
collectFeeMode,
|
|
3555
|
+
poolState.tokenBAmount,
|
|
3556
|
+
poolState.liquidity
|
|
3540
3557
|
);
|
|
3558
|
+
const isInputTokenA = tokenAMint.equals(inputTokenMint);
|
|
3559
|
+
const outputTokenMint = isInputTokenA ? tokenBMint : tokenAMint;
|
|
3560
|
+
const singleSidedA = isSingleSidedA(poolState);
|
|
3561
|
+
const singleSidedB = isSingleSidedB(poolState);
|
|
3541
3562
|
let amount;
|
|
3542
3563
|
let swapTransactions = [];
|
|
3543
3564
|
let maxTransferAmount;
|
|
3544
3565
|
let swapInAmount;
|
|
3545
3566
|
let swapRoute;
|
|
3546
|
-
if (
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3567
|
+
if (singleSidedA && isInputTokenA || singleSidedB && !isInputTokenA) {
|
|
3568
|
+
amount = amountIn;
|
|
3569
|
+
swapInAmount = new import_anchor.BN(0);
|
|
3570
|
+
maxTransferAmount = new import_anchor.BN(0);
|
|
3571
|
+
swapRoute = "dammV2" /* DammV2 */;
|
|
3572
|
+
} else if (singleSidedA && !isInputTokenA || singleSidedB && isInputTokenA) {
|
|
3573
|
+
if (jupiterQuote !== null && (dammV2Quote === null || new import_anchor.BN(jupiterQuote.outAmount).gte(dammV2Quote.swapOutAmount))) {
|
|
3574
|
+
swapInAmount = amountIn;
|
|
3575
|
+
amount = new import_anchor.BN(0);
|
|
3576
|
+
const result = yield buildJupiterSwapTransaction(
|
|
3577
|
+
user,
|
|
3578
|
+
inputTokenMint,
|
|
3579
|
+
outputTokenMint,
|
|
3580
|
+
swapInAmount,
|
|
3581
|
+
maxAccounts,
|
|
3582
|
+
slippageBps,
|
|
3583
|
+
void 0,
|
|
3584
|
+
{
|
|
3585
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
3586
|
+
jupiterApiKey: this.jupiterApiKey
|
|
3587
|
+
}
|
|
3588
|
+
);
|
|
3589
|
+
swapTransactions = [result.transaction];
|
|
3590
|
+
maxTransferAmount = getExtendMaxAmountTransfer(
|
|
3591
|
+
result.quoteResponse.outAmount,
|
|
3592
|
+
maxTransferAmountExtendPercentage
|
|
3593
|
+
);
|
|
3594
|
+
swapRoute = "jupiter" /* Jupiter */;
|
|
3595
|
+
} else if (dammV2Quote !== null) {
|
|
3596
|
+
swapInAmount = new import_anchor.BN(0);
|
|
3597
|
+
amount = amountIn;
|
|
3598
|
+
maxTransferAmount = new import_anchor.BN(0);
|
|
3599
|
+
swapRoute = "dammV2" /* DammV2 */;
|
|
3600
|
+
} else {
|
|
3601
|
+
throw new Error(
|
|
3602
|
+
"No Jupiter or DAMM v2 quote found for single-sided swap, unable to proceed"
|
|
3603
|
+
);
|
|
3604
|
+
}
|
|
3605
|
+
} else if (jupiterQuote !== null && (dammV2Quote === null || new import_anchor.BN(jupiterQuote.outAmount).gte(dammV2Quote.swapOutAmount))) {
|
|
3550
3606
|
const price = convertLamportsToUiAmount(
|
|
3551
3607
|
new import_decimal4.default(jupiterQuote.outAmount),
|
|
3552
|
-
|
|
3608
|
+
isInputTokenA ? tokenBDecimal : tokenADecimal
|
|
3553
3609
|
);
|
|
3554
3610
|
swapInAmount = calculateDirectPoolSwapAmount(
|
|
3555
3611
|
amountIn,
|
|
@@ -3563,13 +3619,13 @@ var Zap = class {
|
|
|
3563
3619
|
new import_decimal4.default(poolBalanceTokenB.toString()),
|
|
3564
3620
|
tokenBDecimal
|
|
3565
3621
|
),
|
|
3566
|
-
|
|
3622
|
+
isInputTokenA
|
|
3567
3623
|
);
|
|
3568
3624
|
amount = amountIn.sub(swapInAmount);
|
|
3569
3625
|
const result = yield buildJupiterSwapTransaction(
|
|
3570
3626
|
user,
|
|
3571
3627
|
inputTokenMint,
|
|
3572
|
-
|
|
3628
|
+
outputTokenMint,
|
|
3573
3629
|
swapInAmount,
|
|
3574
3630
|
maxAccounts,
|
|
3575
3631
|
slippageBps,
|
|
@@ -3585,7 +3641,7 @@ var Zap = class {
|
|
|
3585
3641
|
maxTransferAmountExtendPercentage
|
|
3586
3642
|
);
|
|
3587
3643
|
swapRoute = "jupiter" /* Jupiter */;
|
|
3588
|
-
} else {
|
|
3644
|
+
} else if (dammV2Quote !== null) {
|
|
3589
3645
|
const quote = dammV2Quote;
|
|
3590
3646
|
amount = amountIn;
|
|
3591
3647
|
const price = convertLamportsToUiAmount(
|
|
@@ -3604,13 +3660,15 @@ var Zap = class {
|
|
|
3604
3660
|
new import_decimal4.default(poolBalanceTokenB.toString()),
|
|
3605
3661
|
tokenBDecimal
|
|
3606
3662
|
),
|
|
3607
|
-
|
|
3663
|
+
isInputTokenA
|
|
3608
3664
|
);
|
|
3609
3665
|
maxTransferAmount = getExtendMaxAmountTransfer(
|
|
3610
3666
|
quote.swapOutAmount.toString(),
|
|
3611
3667
|
maxTransferAmountExtendPercentage
|
|
3612
3668
|
);
|
|
3613
3669
|
swapRoute = "dammV2" /* DammV2 */;
|
|
3670
|
+
} else {
|
|
3671
|
+
throw new Error("No Jupiter or DAMM v2 quote found, unable to proceed");
|
|
3614
3672
|
}
|
|
3615
3673
|
const cleanUpInstructions = [];
|
|
3616
3674
|
if (tokenAMint.equals(import_spl_token6.NATIVE_MINT) || tokenBMint.equals(import_spl_token6.NATIVE_MINT)) {
|
|
@@ -3624,7 +3682,7 @@ var Zap = class {
|
|
|
3624
3682
|
position,
|
|
3625
3683
|
positionNftAccount,
|
|
3626
3684
|
isDirectPool: true,
|
|
3627
|
-
isTokenA:
|
|
3685
|
+
isTokenA: isInputTokenA,
|
|
3628
3686
|
tokenAMint,
|
|
3629
3687
|
tokenBMint,
|
|
3630
3688
|
tokenAVault,
|
|
@@ -3735,20 +3793,131 @@ var Zap = class {
|
|
|
3735
3793
|
const closewrapSol = unwrapSOLInstruction(user, user, false);
|
|
3736
3794
|
closewrapSol && cleanUpInstructions.push(closewrapSol);
|
|
3737
3795
|
}
|
|
3796
|
+
const collectFeeMode = poolState.collectFeeMode;
|
|
3738
3797
|
const poolBalanceTokenA = (0, import_cp_amm_sdk3.getAmountAFromLiquidityDelta)(
|
|
3739
3798
|
poolState.sqrtPrice,
|
|
3740
3799
|
poolState.sqrtMaxPrice,
|
|
3741
3800
|
poolState.liquidity,
|
|
3742
|
-
import_cp_amm_sdk3.Rounding.Down
|
|
3801
|
+
import_cp_amm_sdk3.Rounding.Down,
|
|
3802
|
+
collectFeeMode,
|
|
3803
|
+
poolState.tokenAAmount,
|
|
3804
|
+
poolState.liquidity
|
|
3743
3805
|
);
|
|
3744
3806
|
const poolBalanceTokenB = (0, import_cp_amm_sdk3.getAmountBFromLiquidityDelta)(
|
|
3745
3807
|
poolState.sqrtMinPrice,
|
|
3746
3808
|
poolState.sqrtPrice,
|
|
3747
3809
|
poolState.liquidity,
|
|
3748
|
-
import_cp_amm_sdk3.Rounding.Down
|
|
3810
|
+
import_cp_amm_sdk3.Rounding.Down,
|
|
3811
|
+
collectFeeMode,
|
|
3812
|
+
poolState.tokenBAmount,
|
|
3813
|
+
poolState.liquidity
|
|
3749
3814
|
);
|
|
3815
|
+
const singleSidedA = isSingleSidedA(poolState);
|
|
3816
|
+
const singleSidedB = isSingleSidedB(poolState);
|
|
3817
|
+
if (singleSidedA) {
|
|
3818
|
+
if (!jupiterQuoteToA) {
|
|
3819
|
+
throw new Error(
|
|
3820
|
+
"No Jupiter quote for token A found for single-sided pool, unable to proceed"
|
|
3821
|
+
);
|
|
3822
|
+
}
|
|
3823
|
+
const result = yield buildJupiterSwapTransaction(
|
|
3824
|
+
user,
|
|
3825
|
+
inputTokenMint,
|
|
3826
|
+
tokenAMint,
|
|
3827
|
+
amountIn,
|
|
3828
|
+
maxAccounts,
|
|
3829
|
+
slippageBps,
|
|
3830
|
+
void 0,
|
|
3831
|
+
{
|
|
3832
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
3833
|
+
jupiterApiKey: this.jupiterApiKey
|
|
3834
|
+
}
|
|
3835
|
+
);
|
|
3836
|
+
return {
|
|
3837
|
+
user,
|
|
3838
|
+
pool,
|
|
3839
|
+
position,
|
|
3840
|
+
positionNftAccount,
|
|
3841
|
+
maxSqrtPriceChangeBps,
|
|
3842
|
+
amount: new import_anchor.BN(0),
|
|
3843
|
+
isDirectPool: false,
|
|
3844
|
+
tokenAMint,
|
|
3845
|
+
tokenBMint,
|
|
3846
|
+
tokenAVault,
|
|
3847
|
+
tokenBVault,
|
|
3848
|
+
tokenAProgram,
|
|
3849
|
+
tokenBProgram,
|
|
3850
|
+
maxTransferAmountA: getExtendMaxAmountTransfer(
|
|
3851
|
+
result.quoteResponse.outAmount,
|
|
3852
|
+
maxTransferAmountExtendPercentage
|
|
3853
|
+
),
|
|
3854
|
+
swapType: 0 /* swapToA */,
|
|
3855
|
+
maxTransferAmountB: new import_anchor.BN(0),
|
|
3856
|
+
preSqrtPrice: poolState.sqrtPrice,
|
|
3857
|
+
preInstructions,
|
|
3858
|
+
swapTransactions: [result.transaction],
|
|
3859
|
+
cleanUpInstructions,
|
|
3860
|
+
swapInEstimate: {
|
|
3861
|
+
inAmountA: amountIn,
|
|
3862
|
+
inAmountB: new import_anchor.BN(0),
|
|
3863
|
+
routeA: "jupiter" /* Jupiter */,
|
|
3864
|
+
routeB: "dammV2" /* DammV2 */
|
|
3865
|
+
}
|
|
3866
|
+
};
|
|
3867
|
+
}
|
|
3868
|
+
if (singleSidedB) {
|
|
3869
|
+
if (!jupiterQuoteToB) {
|
|
3870
|
+
throw new Error(
|
|
3871
|
+
"No Jupiter quote for token B found for single-sided pool, unable to proceed"
|
|
3872
|
+
);
|
|
3873
|
+
}
|
|
3874
|
+
const result = yield buildJupiterSwapTransaction(
|
|
3875
|
+
user,
|
|
3876
|
+
inputTokenMint,
|
|
3877
|
+
tokenBMint,
|
|
3878
|
+
amountIn,
|
|
3879
|
+
maxAccounts,
|
|
3880
|
+
slippageBps,
|
|
3881
|
+
void 0,
|
|
3882
|
+
{
|
|
3883
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
3884
|
+
jupiterApiKey: this.jupiterApiKey
|
|
3885
|
+
}
|
|
3886
|
+
);
|
|
3887
|
+
return {
|
|
3888
|
+
user,
|
|
3889
|
+
pool,
|
|
3890
|
+
position,
|
|
3891
|
+
positionNftAccount,
|
|
3892
|
+
maxSqrtPriceChangeBps,
|
|
3893
|
+
amount: new import_anchor.BN(0),
|
|
3894
|
+
isDirectPool: false,
|
|
3895
|
+
tokenAMint,
|
|
3896
|
+
tokenBMint,
|
|
3897
|
+
tokenAVault,
|
|
3898
|
+
tokenBVault,
|
|
3899
|
+
tokenAProgram,
|
|
3900
|
+
tokenBProgram,
|
|
3901
|
+
maxTransferAmountA: new import_anchor.BN(0),
|
|
3902
|
+
maxTransferAmountB: getExtendMaxAmountTransfer(
|
|
3903
|
+
result.quoteResponse.outAmount,
|
|
3904
|
+
maxTransferAmountExtendPercentage
|
|
3905
|
+
),
|
|
3906
|
+
swapType: 1 /* swapToB */,
|
|
3907
|
+
preSqrtPrice: poolState.sqrtPrice,
|
|
3908
|
+
preInstructions,
|
|
3909
|
+
swapTransactions: [result.transaction],
|
|
3910
|
+
cleanUpInstructions,
|
|
3911
|
+
swapInEstimate: {
|
|
3912
|
+
inAmountA: new import_anchor.BN(0),
|
|
3913
|
+
inAmountB: amountIn,
|
|
3914
|
+
routeA: "dammV2" /* DammV2 */,
|
|
3915
|
+
routeB: "jupiter" /* Jupiter */
|
|
3916
|
+
}
|
|
3917
|
+
};
|
|
3918
|
+
}
|
|
3750
3919
|
if (jupiterQuoteToA && jupiterQuoteToB === null) {
|
|
3751
|
-
const
|
|
3920
|
+
const result = yield buildJupiterSwapTransaction(
|
|
3752
3921
|
user,
|
|
3753
3922
|
inputTokenMint,
|
|
3754
3923
|
tokenAMint,
|
|
@@ -3776,14 +3945,14 @@ var Zap = class {
|
|
|
3776
3945
|
tokenAProgram,
|
|
3777
3946
|
tokenBProgram,
|
|
3778
3947
|
maxTransferAmountA: getExtendMaxAmountTransfer(
|
|
3779
|
-
|
|
3948
|
+
result.quoteResponse.outAmount,
|
|
3780
3949
|
maxTransferAmountExtendPercentage
|
|
3781
3950
|
),
|
|
3782
3951
|
swapType: 0 /* swapToA */,
|
|
3783
3952
|
maxTransferAmountB: new import_anchor.BN(0),
|
|
3784
3953
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3785
3954
|
preInstructions,
|
|
3786
|
-
swapTransactions: [
|
|
3955
|
+
swapTransactions: [result.transaction],
|
|
3787
3956
|
cleanUpInstructions,
|
|
3788
3957
|
swapInEstimate: {
|
|
3789
3958
|
inAmountA: amountIn,
|
|
@@ -3794,7 +3963,7 @@ var Zap = class {
|
|
|
3794
3963
|
};
|
|
3795
3964
|
}
|
|
3796
3965
|
if (jupiterQuoteToB && jupiterQuoteToA === null) {
|
|
3797
|
-
const
|
|
3966
|
+
const result = yield buildJupiterSwapTransaction(
|
|
3798
3967
|
user,
|
|
3799
3968
|
inputTokenMint,
|
|
3800
3969
|
tokenBMint,
|
|
@@ -3823,13 +3992,13 @@ var Zap = class {
|
|
|
3823
3992
|
tokenBProgram,
|
|
3824
3993
|
maxTransferAmountA: new import_anchor.BN(0),
|
|
3825
3994
|
maxTransferAmountB: getExtendMaxAmountTransfer(
|
|
3826
|
-
|
|
3995
|
+
result.quoteResponse.outAmount,
|
|
3827
3996
|
maxTransferAmountExtendPercentage
|
|
3828
3997
|
),
|
|
3829
3998
|
swapType: 1 /* swapToB */,
|
|
3830
3999
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3831
4000
|
preInstructions,
|
|
3832
|
-
swapTransactions: [
|
|
4001
|
+
swapTransactions: [result.transaction],
|
|
3833
4002
|
cleanUpInstructions,
|
|
3834
4003
|
swapInEstimate: {
|
|
3835
4004
|
inAmountA: new import_anchor.BN(0),
|
|
@@ -3863,6 +4032,24 @@ var Zap = class {
|
|
|
3863
4032
|
)
|
|
3864
4033
|
);
|
|
3865
4034
|
const swapAmountToB = amountIn.sub(swapAmountToA);
|
|
4035
|
+
const baseParams = {
|
|
4036
|
+
user,
|
|
4037
|
+
pool,
|
|
4038
|
+
position,
|
|
4039
|
+
positionNftAccount,
|
|
4040
|
+
maxSqrtPriceChangeBps,
|
|
4041
|
+
amount: new import_anchor.BN(0),
|
|
4042
|
+
isDirectPool: false,
|
|
4043
|
+
tokenAMint,
|
|
4044
|
+
tokenBMint,
|
|
4045
|
+
tokenAVault,
|
|
4046
|
+
tokenBVault,
|
|
4047
|
+
tokenAProgram,
|
|
4048
|
+
tokenBProgram,
|
|
4049
|
+
preInstructions,
|
|
4050
|
+
preSqrtPrice: poolState.sqrtPrice,
|
|
4051
|
+
cleanUpInstructions
|
|
4052
|
+
};
|
|
3866
4053
|
const { transaction: swapToATransaction, quoteResponse: swapToAQuote } = yield buildJupiterSwapTransaction(
|
|
3867
4054
|
user,
|
|
3868
4055
|
inputTokenMint,
|
|
@@ -3889,21 +4076,7 @@ var Zap = class {
|
|
|
3889
4076
|
jupiterApiKey: this.jupiterApiKey
|
|
3890
4077
|
}
|
|
3891
4078
|
);
|
|
3892
|
-
return {
|
|
3893
|
-
user,
|
|
3894
|
-
pool,
|
|
3895
|
-
position,
|
|
3896
|
-
positionNftAccount,
|
|
3897
|
-
maxSqrtPriceChangeBps,
|
|
3898
|
-
amount: new import_anchor.BN(0),
|
|
3899
|
-
isDirectPool: false,
|
|
3900
|
-
tokenAMint,
|
|
3901
|
-
tokenBMint,
|
|
3902
|
-
tokenAVault,
|
|
3903
|
-
tokenBVault,
|
|
3904
|
-
tokenAProgram,
|
|
3905
|
-
tokenBProgram,
|
|
3906
|
-
preInstructions,
|
|
4079
|
+
return __spreadProps(__spreadValues({}, baseParams), {
|
|
3907
4080
|
maxTransferAmountA: getExtendMaxAmountTransfer(
|
|
3908
4081
|
swapToAQuote.outAmount,
|
|
3909
4082
|
maxTransferAmountExtendPercentage
|
|
@@ -3913,16 +4086,14 @@ var Zap = class {
|
|
|
3913
4086
|
maxTransferAmountExtendPercentage
|
|
3914
4087
|
),
|
|
3915
4088
|
swapType: 2 /* swapToBoth */,
|
|
3916
|
-
preSqrtPrice: poolState.sqrtPrice,
|
|
3917
4089
|
swapTransactions: [swapToATransaction, swapToBTransaction],
|
|
3918
|
-
cleanUpInstructions,
|
|
3919
4090
|
swapInEstimate: {
|
|
3920
4091
|
inAmountA: swapAmountToA,
|
|
3921
4092
|
inAmountB: swapAmountToB,
|
|
3922
4093
|
routeA: "jupiter" /* Jupiter */,
|
|
3923
4094
|
routeB: "jupiter" /* Jupiter */
|
|
3924
4095
|
}
|
|
3925
|
-
};
|
|
4096
|
+
});
|
|
3926
4097
|
}
|
|
3927
4098
|
throw new Error(
|
|
3928
4099
|
"No Jupiter quote found for both tokens, unable to proceed"
|
|
@@ -4000,9 +4171,7 @@ var Zap = class {
|
|
|
4000
4171
|
setupTransaction.add(...preInstructions);
|
|
4001
4172
|
}
|
|
4002
4173
|
const ledgerTransaction = new import_web38.Transaction();
|
|
4003
|
-
const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(
|
|
4004
|
-
user
|
|
4005
|
-
);
|
|
4174
|
+
const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(user);
|
|
4006
4175
|
ledgerTransaction.add(resetOrInitializeLedgerTx);
|
|
4007
4176
|
if (isDirectPool) {
|
|
4008
4177
|
const isTokenA = params.isTokenA;
|
|
@@ -4491,9 +4660,7 @@ var Zap = class {
|
|
|
4491
4660
|
setupTransaction.add(...preInstructions);
|
|
4492
4661
|
}
|
|
4493
4662
|
const ledgerTransaction = new import_web38.Transaction();
|
|
4494
|
-
const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(
|
|
4495
|
-
user
|
|
4496
|
-
);
|
|
4663
|
+
const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(user);
|
|
4497
4664
|
ledgerTransaction.add(resetOrInitializeLedgerTx);
|
|
4498
4665
|
if (isDirectRoute) {
|
|
4499
4666
|
const { isTokenX, amount, maxTransferAmount } = params;
|
|
@@ -4796,9 +4963,7 @@ var Zap = class {
|
|
|
4796
4963
|
const tokenXAmountAfterSwap = directSwapEstimate.swapType === 0 /* XToY */ ? tokenXAmount.sub(directSwapEstimate.swapAmount) : directSwapEstimate.swapType === 1 /* YToX */ ? tokenXAmount.add(directSwapEstimate.expectedOutput) : tokenXAmount;
|
|
4797
4964
|
const tokenYAmountAfterSwap = directSwapEstimate.swapType === 0 /* XToY */ ? tokenYAmount.add(directSwapEstimate.expectedOutput) : directSwapEstimate.swapType === 1 /* YToX */ ? tokenYAmount.sub(directSwapEstimate.swapAmount) : tokenYAmount;
|
|
4798
4965
|
const ledgerAddress = deriveLedgerAccount(user);
|
|
4799
|
-
const ledgerAccountInfo = yield this.connection.getAccountInfo(
|
|
4800
|
-
ledgerAddress
|
|
4801
|
-
);
|
|
4966
|
+
const ledgerAccountInfo = yield this.connection.getAccountInfo(ledgerAddress);
|
|
4802
4967
|
const ledgerTransaction = new import_web38.Transaction();
|
|
4803
4968
|
if (!ledgerAccountInfo) {
|
|
4804
4969
|
const initLedgerTx = yield this.initializeLedgerAccount(user, user);
|
|
@@ -5262,6 +5427,8 @@ var Zap = class {
|
|
|
5262
5427
|
getOrCreateATAInstruction,
|
|
5263
5428
|
getTokenAccountBalance,
|
|
5264
5429
|
getTokenProgramFromMint,
|
|
5430
|
+
isSingleSidedA,
|
|
5431
|
+
isSingleSidedB,
|
|
5265
5432
|
toProgramStrategyType,
|
|
5266
5433
|
unwrapSOLInstruction,
|
|
5267
5434
|
wrapSOLInstruction
|