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