@meteora-ag/zap-sdk 1.2.0 → 1.3.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/dist/index.d.mts +88 -97
- package/dist/index.d.ts +88 -97
- package/dist/index.js +215 -51
- package/dist/index.mjs +218 -52
- package/package.json +23 -14
package/dist/index.mjs
CHANGED
|
@@ -1722,9 +1722,8 @@ function getJupiterQuote(_0, _1, _2, _3, _4) {
|
|
|
1722
1722
|
dynamicSlippage: dynamicSlippage.toString()
|
|
1723
1723
|
});
|
|
1724
1724
|
const url = `${config.jupiterApiUrl || DEFAULT_JUPITER_API_URL}/swap/v1/quote?${params.toString()}`;
|
|
1725
|
-
let response = null;
|
|
1726
1725
|
try {
|
|
1727
|
-
response = yield fetch(url, {
|
|
1726
|
+
const response = yield fetch(url, {
|
|
1728
1727
|
method: "GET",
|
|
1729
1728
|
headers: __spreadValues({
|
|
1730
1729
|
Accept: "application/json"
|
|
@@ -1733,11 +1732,11 @@ function getJupiterQuote(_0, _1, _2, _3, _4) {
|
|
|
1733
1732
|
if (!response.ok) {
|
|
1734
1733
|
return null;
|
|
1735
1734
|
}
|
|
1735
|
+
const result = yield response.json();
|
|
1736
|
+
return result;
|
|
1736
1737
|
} catch (error) {
|
|
1737
1738
|
return null;
|
|
1738
1739
|
}
|
|
1739
|
-
const result = yield response.json();
|
|
1740
|
-
return result;
|
|
1741
1740
|
});
|
|
1742
1741
|
}
|
|
1743
1742
|
function getJupiterSwapInstruction(_0, _1) {
|
|
@@ -1810,7 +1809,11 @@ function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6) {
|
|
|
1810
1809
|
|
|
1811
1810
|
// src/helpers/dammV2.ts
|
|
1812
1811
|
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
|
1813
|
-
import {
|
|
1812
|
+
import {
|
|
1813
|
+
CollectFeeMode,
|
|
1814
|
+
CpAmm,
|
|
1815
|
+
derivePoolAuthority
|
|
1816
|
+
} from "@meteora-ag/cp-amm-sdk";
|
|
1814
1817
|
|
|
1815
1818
|
// src/helpers/pda.ts
|
|
1816
1819
|
import { PublicKey as PublicKey3 } from "@solana/web3.js";
|
|
@@ -1923,6 +1926,12 @@ function getDammV2RemainingAccounts(_0, _1, _2, _3) {
|
|
|
1923
1926
|
return remainingAccounts;
|
|
1924
1927
|
});
|
|
1925
1928
|
}
|
|
1929
|
+
function isSingleSidedA(poolState) {
|
|
1930
|
+
return poolState.collectFeeMode !== CollectFeeMode.Compounding && poolState.sqrtPrice.eq(poolState.sqrtMinPrice);
|
|
1931
|
+
}
|
|
1932
|
+
function isSingleSidedB(poolState) {
|
|
1933
|
+
return poolState.collectFeeMode !== CollectFeeMode.Compounding && poolState.sqrtPrice.eq(poolState.sqrtMaxPrice);
|
|
1934
|
+
}
|
|
1926
1935
|
function createDammV2SwapPayload(amountIn, minimumSwapAmountOut) {
|
|
1927
1936
|
return Buffer.concat([
|
|
1928
1937
|
Buffer.from(DAMM_V2_SWAP_DISCRIMINATOR),
|
|
@@ -3505,30 +3514,76 @@ var Zap = class {
|
|
|
3505
3514
|
tokenBProgram
|
|
3506
3515
|
);
|
|
3507
3516
|
const inputTokenDecimal = inputTokenMint.equals(tokenAMint) ? tokenADecimal : tokenBDecimal;
|
|
3517
|
+
const collectFeeMode = poolState.collectFeeMode;
|
|
3508
3518
|
const poolBalanceTokenA = getAmountAFromLiquidityDelta(
|
|
3509
3519
|
poolState.sqrtPrice,
|
|
3510
3520
|
poolState.sqrtMaxPrice,
|
|
3511
3521
|
poolState.liquidity,
|
|
3512
|
-
Rounding.Down
|
|
3522
|
+
Rounding.Down,
|
|
3523
|
+
collectFeeMode,
|
|
3524
|
+
poolState.tokenAAmount,
|
|
3525
|
+
poolState.liquidity
|
|
3513
3526
|
);
|
|
3514
3527
|
const poolBalanceTokenB = getAmountBFromLiquidityDelta(
|
|
3515
3528
|
poolState.sqrtMinPrice,
|
|
3516
3529
|
poolState.sqrtPrice,
|
|
3517
3530
|
poolState.liquidity,
|
|
3518
|
-
Rounding.Down
|
|
3531
|
+
Rounding.Down,
|
|
3532
|
+
collectFeeMode,
|
|
3533
|
+
poolState.tokenBAmount,
|
|
3534
|
+
poolState.liquidity
|
|
3519
3535
|
);
|
|
3536
|
+
const isInputTokenA = tokenAMint.equals(inputTokenMint);
|
|
3537
|
+
const outputTokenMint = isInputTokenA ? tokenBMint : tokenAMint;
|
|
3538
|
+
const singleSidedA = isSingleSidedA(poolState);
|
|
3539
|
+
const singleSidedB = isSingleSidedB(poolState);
|
|
3520
3540
|
let amount;
|
|
3521
3541
|
let swapTransactions = [];
|
|
3522
3542
|
let maxTransferAmount;
|
|
3523
3543
|
let swapInAmount;
|
|
3524
3544
|
let swapRoute;
|
|
3525
|
-
if (
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3545
|
+
if (singleSidedA && isInputTokenA || singleSidedB && !isInputTokenA) {
|
|
3546
|
+
amount = amountIn;
|
|
3547
|
+
swapInAmount = new BN5(0);
|
|
3548
|
+
maxTransferAmount = new BN5(0);
|
|
3549
|
+
swapRoute = "dammV2" /* DammV2 */;
|
|
3550
|
+
} else if (singleSidedA && !isInputTokenA || singleSidedB && isInputTokenA) {
|
|
3551
|
+
if (jupiterQuote !== null && (dammV2Quote === null || new BN5(jupiterQuote.outAmount).gte(dammV2Quote.swapOutAmount))) {
|
|
3552
|
+
swapInAmount = amountIn;
|
|
3553
|
+
amount = new BN5(0);
|
|
3554
|
+
const result = yield buildJupiterSwapTransaction(
|
|
3555
|
+
user,
|
|
3556
|
+
inputTokenMint,
|
|
3557
|
+
outputTokenMint,
|
|
3558
|
+
swapInAmount,
|
|
3559
|
+
maxAccounts,
|
|
3560
|
+
slippageBps,
|
|
3561
|
+
void 0,
|
|
3562
|
+
{
|
|
3563
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
3564
|
+
jupiterApiKey: this.jupiterApiKey
|
|
3565
|
+
}
|
|
3566
|
+
);
|
|
3567
|
+
swapTransactions = [result.transaction];
|
|
3568
|
+
maxTransferAmount = getExtendMaxAmountTransfer(
|
|
3569
|
+
result.quoteResponse.outAmount,
|
|
3570
|
+
maxTransferAmountExtendPercentage
|
|
3571
|
+
);
|
|
3572
|
+
swapRoute = "jupiter" /* Jupiter */;
|
|
3573
|
+
} else if (dammV2Quote !== null) {
|
|
3574
|
+
swapInAmount = new BN5(0);
|
|
3575
|
+
amount = amountIn;
|
|
3576
|
+
maxTransferAmount = new BN5(0);
|
|
3577
|
+
swapRoute = "dammV2" /* DammV2 */;
|
|
3578
|
+
} else {
|
|
3579
|
+
throw new Error(
|
|
3580
|
+
"No Jupiter or DAMM v2 quote found for single-sided swap, unable to proceed"
|
|
3581
|
+
);
|
|
3582
|
+
}
|
|
3583
|
+
} else if (jupiterQuote !== null && (dammV2Quote === null || new BN5(jupiterQuote.outAmount).gte(dammV2Quote.swapOutAmount))) {
|
|
3529
3584
|
const price = convertLamportsToUiAmount(
|
|
3530
3585
|
new Decimal4(jupiterQuote.outAmount),
|
|
3531
|
-
|
|
3586
|
+
isInputTokenA ? tokenBDecimal : tokenADecimal
|
|
3532
3587
|
);
|
|
3533
3588
|
swapInAmount = calculateDirectPoolSwapAmount(
|
|
3534
3589
|
amountIn,
|
|
@@ -3542,13 +3597,13 @@ var Zap = class {
|
|
|
3542
3597
|
new Decimal4(poolBalanceTokenB.toString()),
|
|
3543
3598
|
tokenBDecimal
|
|
3544
3599
|
),
|
|
3545
|
-
|
|
3600
|
+
isInputTokenA
|
|
3546
3601
|
);
|
|
3547
3602
|
amount = amountIn.sub(swapInAmount);
|
|
3548
3603
|
const result = yield buildJupiterSwapTransaction(
|
|
3549
3604
|
user,
|
|
3550
3605
|
inputTokenMint,
|
|
3551
|
-
|
|
3606
|
+
outputTokenMint,
|
|
3552
3607
|
swapInAmount,
|
|
3553
3608
|
maxAccounts,
|
|
3554
3609
|
slippageBps,
|
|
@@ -3564,7 +3619,7 @@ var Zap = class {
|
|
|
3564
3619
|
maxTransferAmountExtendPercentage
|
|
3565
3620
|
);
|
|
3566
3621
|
swapRoute = "jupiter" /* Jupiter */;
|
|
3567
|
-
} else {
|
|
3622
|
+
} else if (dammV2Quote !== null) {
|
|
3568
3623
|
const quote = dammV2Quote;
|
|
3569
3624
|
amount = amountIn;
|
|
3570
3625
|
const price = convertLamportsToUiAmount(
|
|
@@ -3583,13 +3638,15 @@ var Zap = class {
|
|
|
3583
3638
|
new Decimal4(poolBalanceTokenB.toString()),
|
|
3584
3639
|
tokenBDecimal
|
|
3585
3640
|
),
|
|
3586
|
-
|
|
3641
|
+
isInputTokenA
|
|
3587
3642
|
);
|
|
3588
3643
|
maxTransferAmount = getExtendMaxAmountTransfer(
|
|
3589
3644
|
quote.swapOutAmount.toString(),
|
|
3590
3645
|
maxTransferAmountExtendPercentage
|
|
3591
3646
|
);
|
|
3592
3647
|
swapRoute = "dammV2" /* DammV2 */;
|
|
3648
|
+
} else {
|
|
3649
|
+
throw new Error("No Jupiter or DAMM v2 quote found, unable to proceed");
|
|
3593
3650
|
}
|
|
3594
3651
|
const cleanUpInstructions = [];
|
|
3595
3652
|
if (tokenAMint.equals(NATIVE_MINT3) || tokenBMint.equals(NATIVE_MINT3)) {
|
|
@@ -3603,7 +3660,7 @@ var Zap = class {
|
|
|
3603
3660
|
position,
|
|
3604
3661
|
positionNftAccount,
|
|
3605
3662
|
isDirectPool: true,
|
|
3606
|
-
isTokenA:
|
|
3663
|
+
isTokenA: isInputTokenA,
|
|
3607
3664
|
tokenAMint,
|
|
3608
3665
|
tokenBMint,
|
|
3609
3666
|
tokenAVault,
|
|
@@ -3714,20 +3771,131 @@ var Zap = class {
|
|
|
3714
3771
|
const closewrapSol = unwrapSOLInstruction(user, user, false);
|
|
3715
3772
|
closewrapSol && cleanUpInstructions.push(closewrapSol);
|
|
3716
3773
|
}
|
|
3774
|
+
const collectFeeMode = poolState.collectFeeMode;
|
|
3717
3775
|
const poolBalanceTokenA = getAmountAFromLiquidityDelta(
|
|
3718
3776
|
poolState.sqrtPrice,
|
|
3719
3777
|
poolState.sqrtMaxPrice,
|
|
3720
3778
|
poolState.liquidity,
|
|
3721
|
-
Rounding.Down
|
|
3779
|
+
Rounding.Down,
|
|
3780
|
+
collectFeeMode,
|
|
3781
|
+
poolState.tokenAAmount,
|
|
3782
|
+
poolState.liquidity
|
|
3722
3783
|
);
|
|
3723
3784
|
const poolBalanceTokenB = getAmountBFromLiquidityDelta(
|
|
3724
3785
|
poolState.sqrtMinPrice,
|
|
3725
3786
|
poolState.sqrtPrice,
|
|
3726
3787
|
poolState.liquidity,
|
|
3727
|
-
Rounding.Down
|
|
3788
|
+
Rounding.Down,
|
|
3789
|
+
collectFeeMode,
|
|
3790
|
+
poolState.tokenBAmount,
|
|
3791
|
+
poolState.liquidity
|
|
3728
3792
|
);
|
|
3793
|
+
const singleSidedA = isSingleSidedA(poolState);
|
|
3794
|
+
const singleSidedB = isSingleSidedB(poolState);
|
|
3795
|
+
if (singleSidedA) {
|
|
3796
|
+
if (!jupiterQuoteToA) {
|
|
3797
|
+
throw new Error(
|
|
3798
|
+
"No Jupiter quote for token A found for single-sided pool, unable to proceed"
|
|
3799
|
+
);
|
|
3800
|
+
}
|
|
3801
|
+
const result = yield buildJupiterSwapTransaction(
|
|
3802
|
+
user,
|
|
3803
|
+
inputTokenMint,
|
|
3804
|
+
tokenAMint,
|
|
3805
|
+
amountIn,
|
|
3806
|
+
maxAccounts,
|
|
3807
|
+
slippageBps,
|
|
3808
|
+
void 0,
|
|
3809
|
+
{
|
|
3810
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
3811
|
+
jupiterApiKey: this.jupiterApiKey
|
|
3812
|
+
}
|
|
3813
|
+
);
|
|
3814
|
+
return {
|
|
3815
|
+
user,
|
|
3816
|
+
pool,
|
|
3817
|
+
position,
|
|
3818
|
+
positionNftAccount,
|
|
3819
|
+
maxSqrtPriceChangeBps,
|
|
3820
|
+
amount: new BN5(0),
|
|
3821
|
+
isDirectPool: false,
|
|
3822
|
+
tokenAMint,
|
|
3823
|
+
tokenBMint,
|
|
3824
|
+
tokenAVault,
|
|
3825
|
+
tokenBVault,
|
|
3826
|
+
tokenAProgram,
|
|
3827
|
+
tokenBProgram,
|
|
3828
|
+
maxTransferAmountA: getExtendMaxAmountTransfer(
|
|
3829
|
+
result.quoteResponse.outAmount,
|
|
3830
|
+
maxTransferAmountExtendPercentage
|
|
3831
|
+
),
|
|
3832
|
+
swapType: 0 /* swapToA */,
|
|
3833
|
+
maxTransferAmountB: new BN5(0),
|
|
3834
|
+
preSqrtPrice: poolState.sqrtPrice,
|
|
3835
|
+
preInstructions,
|
|
3836
|
+
swapTransactions: [result.transaction],
|
|
3837
|
+
cleanUpInstructions,
|
|
3838
|
+
swapInEstimate: {
|
|
3839
|
+
inAmountA: amountIn,
|
|
3840
|
+
inAmountB: new BN5(0),
|
|
3841
|
+
routeA: "jupiter" /* Jupiter */,
|
|
3842
|
+
routeB: "dammV2" /* DammV2 */
|
|
3843
|
+
}
|
|
3844
|
+
};
|
|
3845
|
+
}
|
|
3846
|
+
if (singleSidedB) {
|
|
3847
|
+
if (!jupiterQuoteToB) {
|
|
3848
|
+
throw new Error(
|
|
3849
|
+
"No Jupiter quote for token B found for single-sided pool, unable to proceed"
|
|
3850
|
+
);
|
|
3851
|
+
}
|
|
3852
|
+
const result = yield buildJupiterSwapTransaction(
|
|
3853
|
+
user,
|
|
3854
|
+
inputTokenMint,
|
|
3855
|
+
tokenBMint,
|
|
3856
|
+
amountIn,
|
|
3857
|
+
maxAccounts,
|
|
3858
|
+
slippageBps,
|
|
3859
|
+
void 0,
|
|
3860
|
+
{
|
|
3861
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
3862
|
+
jupiterApiKey: this.jupiterApiKey
|
|
3863
|
+
}
|
|
3864
|
+
);
|
|
3865
|
+
return {
|
|
3866
|
+
user,
|
|
3867
|
+
pool,
|
|
3868
|
+
position,
|
|
3869
|
+
positionNftAccount,
|
|
3870
|
+
maxSqrtPriceChangeBps,
|
|
3871
|
+
amount: new BN5(0),
|
|
3872
|
+
isDirectPool: false,
|
|
3873
|
+
tokenAMint,
|
|
3874
|
+
tokenBMint,
|
|
3875
|
+
tokenAVault,
|
|
3876
|
+
tokenBVault,
|
|
3877
|
+
tokenAProgram,
|
|
3878
|
+
tokenBProgram,
|
|
3879
|
+
maxTransferAmountA: new BN5(0),
|
|
3880
|
+
maxTransferAmountB: getExtendMaxAmountTransfer(
|
|
3881
|
+
result.quoteResponse.outAmount,
|
|
3882
|
+
maxTransferAmountExtendPercentage
|
|
3883
|
+
),
|
|
3884
|
+
swapType: 1 /* swapToB */,
|
|
3885
|
+
preSqrtPrice: poolState.sqrtPrice,
|
|
3886
|
+
preInstructions,
|
|
3887
|
+
swapTransactions: [result.transaction],
|
|
3888
|
+
cleanUpInstructions,
|
|
3889
|
+
swapInEstimate: {
|
|
3890
|
+
inAmountA: new BN5(0),
|
|
3891
|
+
inAmountB: amountIn,
|
|
3892
|
+
routeA: "dammV2" /* DammV2 */,
|
|
3893
|
+
routeB: "jupiter" /* Jupiter */
|
|
3894
|
+
}
|
|
3895
|
+
};
|
|
3896
|
+
}
|
|
3729
3897
|
if (jupiterQuoteToA && jupiterQuoteToB === null) {
|
|
3730
|
-
const
|
|
3898
|
+
const result = yield buildJupiterSwapTransaction(
|
|
3731
3899
|
user,
|
|
3732
3900
|
inputTokenMint,
|
|
3733
3901
|
tokenAMint,
|
|
@@ -3755,14 +3923,14 @@ var Zap = class {
|
|
|
3755
3923
|
tokenAProgram,
|
|
3756
3924
|
tokenBProgram,
|
|
3757
3925
|
maxTransferAmountA: getExtendMaxAmountTransfer(
|
|
3758
|
-
|
|
3926
|
+
result.quoteResponse.outAmount,
|
|
3759
3927
|
maxTransferAmountExtendPercentage
|
|
3760
3928
|
),
|
|
3761
3929
|
swapType: 0 /* swapToA */,
|
|
3762
3930
|
maxTransferAmountB: new BN5(0),
|
|
3763
3931
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3764
3932
|
preInstructions,
|
|
3765
|
-
swapTransactions: [
|
|
3933
|
+
swapTransactions: [result.transaction],
|
|
3766
3934
|
cleanUpInstructions,
|
|
3767
3935
|
swapInEstimate: {
|
|
3768
3936
|
inAmountA: amountIn,
|
|
@@ -3773,7 +3941,7 @@ var Zap = class {
|
|
|
3773
3941
|
};
|
|
3774
3942
|
}
|
|
3775
3943
|
if (jupiterQuoteToB && jupiterQuoteToA === null) {
|
|
3776
|
-
const
|
|
3944
|
+
const result = yield buildJupiterSwapTransaction(
|
|
3777
3945
|
user,
|
|
3778
3946
|
inputTokenMint,
|
|
3779
3947
|
tokenBMint,
|
|
@@ -3802,13 +3970,13 @@ var Zap = class {
|
|
|
3802
3970
|
tokenBProgram,
|
|
3803
3971
|
maxTransferAmountA: new BN5(0),
|
|
3804
3972
|
maxTransferAmountB: getExtendMaxAmountTransfer(
|
|
3805
|
-
|
|
3973
|
+
result.quoteResponse.outAmount,
|
|
3806
3974
|
maxTransferAmountExtendPercentage
|
|
3807
3975
|
),
|
|
3808
3976
|
swapType: 1 /* swapToB */,
|
|
3809
3977
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3810
3978
|
preInstructions,
|
|
3811
|
-
swapTransactions: [
|
|
3979
|
+
swapTransactions: [result.transaction],
|
|
3812
3980
|
cleanUpInstructions,
|
|
3813
3981
|
swapInEstimate: {
|
|
3814
3982
|
inAmountA: new BN5(0),
|
|
@@ -3842,6 +4010,24 @@ var Zap = class {
|
|
|
3842
4010
|
)
|
|
3843
4011
|
);
|
|
3844
4012
|
const swapAmountToB = amountIn.sub(swapAmountToA);
|
|
4013
|
+
const baseParams = {
|
|
4014
|
+
user,
|
|
4015
|
+
pool,
|
|
4016
|
+
position,
|
|
4017
|
+
positionNftAccount,
|
|
4018
|
+
maxSqrtPriceChangeBps,
|
|
4019
|
+
amount: new BN5(0),
|
|
4020
|
+
isDirectPool: false,
|
|
4021
|
+
tokenAMint,
|
|
4022
|
+
tokenBMint,
|
|
4023
|
+
tokenAVault,
|
|
4024
|
+
tokenBVault,
|
|
4025
|
+
tokenAProgram,
|
|
4026
|
+
tokenBProgram,
|
|
4027
|
+
preInstructions,
|
|
4028
|
+
preSqrtPrice: poolState.sqrtPrice,
|
|
4029
|
+
cleanUpInstructions
|
|
4030
|
+
};
|
|
3845
4031
|
const { transaction: swapToATransaction, quoteResponse: swapToAQuote } = yield buildJupiterSwapTransaction(
|
|
3846
4032
|
user,
|
|
3847
4033
|
inputTokenMint,
|
|
@@ -3868,21 +4054,7 @@ var Zap = class {
|
|
|
3868
4054
|
jupiterApiKey: this.jupiterApiKey
|
|
3869
4055
|
}
|
|
3870
4056
|
);
|
|
3871
|
-
return {
|
|
3872
|
-
user,
|
|
3873
|
-
pool,
|
|
3874
|
-
position,
|
|
3875
|
-
positionNftAccount,
|
|
3876
|
-
maxSqrtPriceChangeBps,
|
|
3877
|
-
amount: new BN5(0),
|
|
3878
|
-
isDirectPool: false,
|
|
3879
|
-
tokenAMint,
|
|
3880
|
-
tokenBMint,
|
|
3881
|
-
tokenAVault,
|
|
3882
|
-
tokenBVault,
|
|
3883
|
-
tokenAProgram,
|
|
3884
|
-
tokenBProgram,
|
|
3885
|
-
preInstructions,
|
|
4057
|
+
return __spreadProps(__spreadValues({}, baseParams), {
|
|
3886
4058
|
maxTransferAmountA: getExtendMaxAmountTransfer(
|
|
3887
4059
|
swapToAQuote.outAmount,
|
|
3888
4060
|
maxTransferAmountExtendPercentage
|
|
@@ -3892,16 +4064,14 @@ var Zap = class {
|
|
|
3892
4064
|
maxTransferAmountExtendPercentage
|
|
3893
4065
|
),
|
|
3894
4066
|
swapType: 2 /* swapToBoth */,
|
|
3895
|
-
preSqrtPrice: poolState.sqrtPrice,
|
|
3896
4067
|
swapTransactions: [swapToATransaction, swapToBTransaction],
|
|
3897
|
-
cleanUpInstructions,
|
|
3898
4068
|
swapInEstimate: {
|
|
3899
4069
|
inAmountA: swapAmountToA,
|
|
3900
4070
|
inAmountB: swapAmountToB,
|
|
3901
4071
|
routeA: "jupiter" /* Jupiter */,
|
|
3902
4072
|
routeB: "jupiter" /* Jupiter */
|
|
3903
4073
|
}
|
|
3904
|
-
};
|
|
4074
|
+
});
|
|
3905
4075
|
}
|
|
3906
4076
|
throw new Error(
|
|
3907
4077
|
"No Jupiter quote found for both tokens, unable to proceed"
|
|
@@ -3979,9 +4149,7 @@ var Zap = class {
|
|
|
3979
4149
|
setupTransaction.add(...preInstructions);
|
|
3980
4150
|
}
|
|
3981
4151
|
const ledgerTransaction = new Transaction2();
|
|
3982
|
-
const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(
|
|
3983
|
-
user
|
|
3984
|
-
);
|
|
4152
|
+
const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(user);
|
|
3985
4153
|
ledgerTransaction.add(resetOrInitializeLedgerTx);
|
|
3986
4154
|
if (isDirectPool) {
|
|
3987
4155
|
const isTokenA = params.isTokenA;
|
|
@@ -4470,9 +4638,7 @@ var Zap = class {
|
|
|
4470
4638
|
setupTransaction.add(...preInstructions);
|
|
4471
4639
|
}
|
|
4472
4640
|
const ledgerTransaction = new Transaction2();
|
|
4473
|
-
const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(
|
|
4474
|
-
user
|
|
4475
|
-
);
|
|
4641
|
+
const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(user);
|
|
4476
4642
|
ledgerTransaction.add(resetOrInitializeLedgerTx);
|
|
4477
4643
|
if (isDirectRoute) {
|
|
4478
4644
|
const { isTokenX, amount, maxTransferAmount } = params;
|
|
@@ -4775,9 +4941,7 @@ var Zap = class {
|
|
|
4775
4941
|
const tokenXAmountAfterSwap = directSwapEstimate.swapType === 0 /* XToY */ ? tokenXAmount.sub(directSwapEstimate.swapAmount) : directSwapEstimate.swapType === 1 /* YToX */ ? tokenXAmount.add(directSwapEstimate.expectedOutput) : tokenXAmount;
|
|
4776
4942
|
const tokenYAmountAfterSwap = directSwapEstimate.swapType === 0 /* XToY */ ? tokenYAmount.add(directSwapEstimate.expectedOutput) : directSwapEstimate.swapType === 1 /* YToX */ ? tokenYAmount.sub(directSwapEstimate.swapAmount) : tokenYAmount;
|
|
4777
4943
|
const ledgerAddress = deriveLedgerAccount(user);
|
|
4778
|
-
const ledgerAccountInfo = yield this.connection.getAccountInfo(
|
|
4779
|
-
ledgerAddress
|
|
4780
|
-
);
|
|
4944
|
+
const ledgerAccountInfo = yield this.connection.getAccountInfo(ledgerAddress);
|
|
4781
4945
|
const ledgerTransaction = new Transaction2();
|
|
4782
4946
|
if (!ledgerAccountInfo) {
|
|
4783
4947
|
const initLedgerTx = yield this.initializeLedgerAccount(user, user);
|
|
@@ -5240,6 +5404,8 @@ export {
|
|
|
5240
5404
|
getOrCreateATAInstruction,
|
|
5241
5405
|
getTokenAccountBalance,
|
|
5242
5406
|
getTokenProgramFromMint,
|
|
5407
|
+
isSingleSidedA,
|
|
5408
|
+
isSingleSidedB,
|
|
5243
5409
|
toProgramStrategyType,
|
|
5244
5410
|
unwrapSOLInstruction,
|
|
5245
5411
|
wrapSOLInstruction
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meteora-ag/zap-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "A Typescript SDK for interacting with the Zap program on Meteora.",
|
|
5
|
-
"main": "dist/index.
|
|
5
|
+
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"source": "src/index.ts",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
@@ -21,37 +21,46 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"dist/**"
|
|
23
23
|
],
|
|
24
|
-
"scripts": {
|
|
25
|
-
"build": "rm -rf dist && tsup src/index.ts --format esm,cjs --dts",
|
|
26
|
-
"clean": "rm -rf dist && rm -rf node_modules rm -rf pnpm-lock.yaml"
|
|
27
|
-
},
|
|
28
24
|
"exports": {
|
|
29
25
|
".": {
|
|
30
26
|
"types": "./dist/index.d.ts",
|
|
31
27
|
"import": "./dist/index.js",
|
|
32
|
-
"require": "./dist/index.
|
|
28
|
+
"require": "./dist/index.js"
|
|
33
29
|
}
|
|
34
30
|
},
|
|
35
31
|
"devDependencies": {
|
|
36
32
|
"@types/bn.js": "^5.1.0",
|
|
37
|
-
"@types/
|
|
33
|
+
"@types/chai": "^4.3.0",
|
|
38
34
|
"@types/invariant": "^2.2.37",
|
|
39
|
-
"
|
|
40
|
-
"tsx": "^4.20.3",
|
|
35
|
+
"@types/mocha": "^9.0.0",
|
|
41
36
|
"bip39": "^3.1.0",
|
|
42
|
-
"
|
|
37
|
+
"chai": "^4.3.4",
|
|
38
|
+
"ed25519-hd-key": "^1.3.0",
|
|
39
|
+
"litesvm": "^0.6.0",
|
|
40
|
+
"mocha": "^9.0.3",
|
|
41
|
+
"prettier": "^3.8.2",
|
|
42
|
+
"ts-mocha": "^10.0.0",
|
|
43
|
+
"tsup": "^8.5.1",
|
|
44
|
+
"tsx": "^4.20.3"
|
|
43
45
|
},
|
|
44
46
|
"peerDependencies": {
|
|
45
47
|
"typescript": "^5"
|
|
46
48
|
},
|
|
47
49
|
"dependencies": {
|
|
48
50
|
"@coral-xyz/anchor": "^0.31.1",
|
|
49
|
-
"@meteora-ag/cp-amm-sdk": "^1.
|
|
50
|
-
"@meteora-ag/dlmm": "^1.9.
|
|
51
|
+
"@meteora-ag/cp-amm-sdk": "^1.4.0",
|
|
52
|
+
"@meteora-ag/dlmm": "^1.9.7",
|
|
51
53
|
"@solana/spl-token": "^0.4.13",
|
|
52
54
|
"@solana/web3.js": "^1.98.2",
|
|
53
55
|
"bn.js": "^5.2.2",
|
|
54
56
|
"decimal.js": "^10.4.2",
|
|
55
57
|
"invariant": "^2.2.4"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "rm -rf dist && tsup src/index.ts --format esm,cjs --dts",
|
|
61
|
+
"clean": "rm -rf dist && rm -rf node_modules rm -rf pnpm-lock.yaml",
|
|
62
|
+
"typecheck": "tsc",
|
|
63
|
+
"format": "prettier --check .",
|
|
64
|
+
"test": "ts-mocha --no-experimental-strip-types -p ./tsconfig.json -t 1000000 'tests/**/*.test.ts'"
|
|
56
65
|
}
|
|
57
|
-
}
|
|
66
|
+
}
|