@meteora-ag/zap-sdk 1.2.0-rc.1 → 1.2.0-rc.3
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.js +126 -25
- package/dist/index.mjs +126 -25
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1863,18 +1863,37 @@ function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6) {
|
|
|
1863
1863
|
quoteResponse,
|
|
1864
1864
|
config
|
|
1865
1865
|
);
|
|
1866
|
-
const
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1866
|
+
const toTxInstruction = (instruction) => {
|
|
1867
|
+
if (!instruction) return null;
|
|
1868
|
+
return new import_web32.TransactionInstruction({
|
|
1869
|
+
keys: instruction.accounts.map((item) => {
|
|
1870
|
+
return {
|
|
1871
|
+
pubkey: new import_web32.PublicKey(item.pubkey),
|
|
1872
|
+
isSigner: item.isSigner,
|
|
1873
|
+
isWritable: item.isWritable
|
|
1874
|
+
};
|
|
1875
|
+
}),
|
|
1876
|
+
programId: new import_web32.PublicKey(instruction.programId),
|
|
1877
|
+
data: Buffer.from(instruction.data, "base64")
|
|
1878
|
+
});
|
|
1879
|
+
};
|
|
1880
|
+
const transaction = new import_web32.Transaction();
|
|
1881
|
+
const tokenLedgerInstruction = toTxInstruction(
|
|
1882
|
+
swapInstructionResponse.tokenLedgerInstruction
|
|
1883
|
+
);
|
|
1884
|
+
if (tokenLedgerInstruction) {
|
|
1885
|
+
transaction.add(tokenLedgerInstruction);
|
|
1886
|
+
}
|
|
1887
|
+
for (const setupInstruction of swapInstructionResponse.setupInstructions) {
|
|
1888
|
+
const txInstruction = toTxInstruction(setupInstruction);
|
|
1889
|
+
if (txInstruction) transaction.add(txInstruction);
|
|
1890
|
+
}
|
|
1891
|
+
const swapInstruction = toTxInstruction(swapInstructionResponse.swapInstruction);
|
|
1892
|
+
if (!swapInstruction) {
|
|
1893
|
+
throw new Error("Missing Jupiter swap instruction");
|
|
1894
|
+
}
|
|
1895
|
+
transaction.add(swapInstruction);
|
|
1896
|
+
return { transaction, quoteResponse };
|
|
1878
1897
|
});
|
|
1879
1898
|
}
|
|
1880
1899
|
|
|
@@ -3863,21 +3882,103 @@ var Zap = class {
|
|
|
3863
3882
|
)
|
|
3864
3883
|
);
|
|
3865
3884
|
const swapAmountToB = amountIn.sub(swapAmountToA);
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3885
|
+
if (swapAmountToA.isZero()) {
|
|
3886
|
+
const { transaction: swapToBTransaction2, quoteResponse: swapToBQuote2 } = yield buildJupiterSwapTransaction(
|
|
3887
|
+
user,
|
|
3888
|
+
inputTokenMint,
|
|
3889
|
+
tokenBMint,
|
|
3890
|
+
swapAmountToB,
|
|
3891
|
+
maxAccounts,
|
|
3892
|
+
slippageBps,
|
|
3893
|
+
void 0,
|
|
3894
|
+
{
|
|
3895
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
3896
|
+
jupiterApiKey: this.jupiterApiKey
|
|
3897
|
+
}
|
|
3898
|
+
);
|
|
3899
|
+
return {
|
|
3900
|
+
user,
|
|
3901
|
+
pool,
|
|
3902
|
+
position,
|
|
3903
|
+
positionNftAccount,
|
|
3904
|
+
maxSqrtPriceChangeBps,
|
|
3905
|
+
amount: new import_anchor.BN(0),
|
|
3906
|
+
isDirectPool: false,
|
|
3907
|
+
tokenAMint,
|
|
3908
|
+
tokenBMint,
|
|
3909
|
+
tokenAVault,
|
|
3910
|
+
tokenBVault,
|
|
3911
|
+
tokenAProgram,
|
|
3912
|
+
tokenBProgram,
|
|
3913
|
+
maxTransferAmountA: new import_anchor.BN(0),
|
|
3914
|
+
maxTransferAmountB: getExtendMaxAmountTransfer(
|
|
3915
|
+
swapToBQuote2.outAmount,
|
|
3916
|
+
maxTransferAmountExtendPercentage
|
|
3917
|
+
),
|
|
3918
|
+
swapType: 1 /* swapToB */,
|
|
3919
|
+
preSqrtPrice: poolState.sqrtPrice,
|
|
3920
|
+
preInstructions,
|
|
3921
|
+
swapTransactions: [swapToBTransaction2],
|
|
3922
|
+
cleanUpInstructions,
|
|
3923
|
+
swapInEstimate: {
|
|
3924
|
+
inAmountA: new import_anchor.BN(0),
|
|
3925
|
+
inAmountB: swapAmountToB,
|
|
3926
|
+
routeA: "dammV2" /* DammV2 */,
|
|
3927
|
+
routeB: "jupiter" /* Jupiter */
|
|
3928
|
+
}
|
|
3929
|
+
};
|
|
3930
|
+
}
|
|
3931
|
+
if (swapAmountToB.isZero()) {
|
|
3932
|
+
const { transaction: swapToATransaction2, quoteResponse: swapToAQuote2 } = yield buildJupiterSwapTransaction(
|
|
3933
|
+
user,
|
|
3934
|
+
inputTokenMint,
|
|
3935
|
+
tokenAMint,
|
|
3936
|
+
swapAmountToA,
|
|
3937
|
+
maxAccounts,
|
|
3938
|
+
slippageBps,
|
|
3939
|
+
void 0,
|
|
3940
|
+
{
|
|
3941
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
3942
|
+
jupiterApiKey: this.jupiterApiKey
|
|
3943
|
+
}
|
|
3944
|
+
);
|
|
3945
|
+
return {
|
|
3946
|
+
user,
|
|
3947
|
+
pool,
|
|
3948
|
+
position,
|
|
3949
|
+
positionNftAccount,
|
|
3950
|
+
maxSqrtPriceChangeBps,
|
|
3951
|
+
amount: new import_anchor.BN(0),
|
|
3952
|
+
isDirectPool: false,
|
|
3953
|
+
tokenAMint,
|
|
3954
|
+
tokenBMint,
|
|
3955
|
+
tokenAVault,
|
|
3956
|
+
tokenBVault,
|
|
3957
|
+
tokenAProgram,
|
|
3958
|
+
tokenBProgram,
|
|
3959
|
+
maxTransferAmountA: getExtendMaxAmountTransfer(
|
|
3960
|
+
swapToAQuote2.outAmount,
|
|
3961
|
+
maxTransferAmountExtendPercentage
|
|
3962
|
+
),
|
|
3963
|
+
maxTransferAmountB: new import_anchor.BN(0),
|
|
3964
|
+
swapType: 0 /* swapToA */,
|
|
3965
|
+
preSqrtPrice: poolState.sqrtPrice,
|
|
3966
|
+
preInstructions,
|
|
3967
|
+
swapTransactions: [swapToATransaction2],
|
|
3968
|
+
cleanUpInstructions,
|
|
3969
|
+
swapInEstimate: {
|
|
3970
|
+
inAmountA: swapAmountToA,
|
|
3971
|
+
inAmountB: new import_anchor.BN(0),
|
|
3972
|
+
routeA: "jupiter" /* Jupiter */,
|
|
3973
|
+
routeB: "dammV2" /* DammV2 */
|
|
3974
|
+
}
|
|
3975
|
+
};
|
|
3875
3976
|
}
|
|
3876
3977
|
const { transaction: swapToATransaction, quoteResponse: swapToAQuote } = yield buildJupiterSwapTransaction(
|
|
3877
3978
|
user,
|
|
3878
3979
|
inputTokenMint,
|
|
3879
3980
|
tokenAMint,
|
|
3880
|
-
|
|
3981
|
+
swapAmountToA,
|
|
3881
3982
|
maxAccounts,
|
|
3882
3983
|
slippageBps,
|
|
3883
3984
|
void 0,
|
|
@@ -3890,7 +3991,7 @@ var Zap = class {
|
|
|
3890
3991
|
user,
|
|
3891
3992
|
inputTokenMint,
|
|
3892
3993
|
tokenBMint,
|
|
3893
|
-
|
|
3994
|
+
swapAmountToB,
|
|
3894
3995
|
maxAccounts,
|
|
3895
3996
|
slippageBps,
|
|
3896
3997
|
void 0,
|
|
@@ -3927,8 +4028,8 @@ var Zap = class {
|
|
|
3927
4028
|
swapTransactions: [swapToATransaction, swapToBTransaction],
|
|
3928
4029
|
cleanUpInstructions,
|
|
3929
4030
|
swapInEstimate: {
|
|
3930
|
-
inAmountA:
|
|
3931
|
-
inAmountB:
|
|
4031
|
+
inAmountA: swapAmountToA,
|
|
4032
|
+
inAmountB: swapAmountToB,
|
|
3932
4033
|
routeA: "jupiter" /* Jupiter */,
|
|
3933
4034
|
routeB: "jupiter" /* Jupiter */
|
|
3934
4035
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1793,18 +1793,37 @@ function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6) {
|
|
|
1793
1793
|
quoteResponse,
|
|
1794
1794
|
config
|
|
1795
1795
|
);
|
|
1796
|
-
const
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1796
|
+
const toTxInstruction = (instruction) => {
|
|
1797
|
+
if (!instruction) return null;
|
|
1798
|
+
return new TransactionInstruction({
|
|
1799
|
+
keys: instruction.accounts.map((item) => {
|
|
1800
|
+
return {
|
|
1801
|
+
pubkey: new PublicKey2(item.pubkey),
|
|
1802
|
+
isSigner: item.isSigner,
|
|
1803
|
+
isWritable: item.isWritable
|
|
1804
|
+
};
|
|
1805
|
+
}),
|
|
1806
|
+
programId: new PublicKey2(instruction.programId),
|
|
1807
|
+
data: Buffer.from(instruction.data, "base64")
|
|
1808
|
+
});
|
|
1809
|
+
};
|
|
1810
|
+
const transaction = new Transaction();
|
|
1811
|
+
const tokenLedgerInstruction = toTxInstruction(
|
|
1812
|
+
swapInstructionResponse.tokenLedgerInstruction
|
|
1813
|
+
);
|
|
1814
|
+
if (tokenLedgerInstruction) {
|
|
1815
|
+
transaction.add(tokenLedgerInstruction);
|
|
1816
|
+
}
|
|
1817
|
+
for (const setupInstruction of swapInstructionResponse.setupInstructions) {
|
|
1818
|
+
const txInstruction = toTxInstruction(setupInstruction);
|
|
1819
|
+
if (txInstruction) transaction.add(txInstruction);
|
|
1820
|
+
}
|
|
1821
|
+
const swapInstruction = toTxInstruction(swapInstructionResponse.swapInstruction);
|
|
1822
|
+
if (!swapInstruction) {
|
|
1823
|
+
throw new Error("Missing Jupiter swap instruction");
|
|
1824
|
+
}
|
|
1825
|
+
transaction.add(swapInstruction);
|
|
1826
|
+
return { transaction, quoteResponse };
|
|
1808
1827
|
});
|
|
1809
1828
|
}
|
|
1810
1829
|
|
|
@@ -3842,21 +3861,103 @@ var Zap = class {
|
|
|
3842
3861
|
)
|
|
3843
3862
|
);
|
|
3844
3863
|
const swapAmountToB = amountIn.sub(swapAmountToA);
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3864
|
+
if (swapAmountToA.isZero()) {
|
|
3865
|
+
const { transaction: swapToBTransaction2, quoteResponse: swapToBQuote2 } = yield buildJupiterSwapTransaction(
|
|
3866
|
+
user,
|
|
3867
|
+
inputTokenMint,
|
|
3868
|
+
tokenBMint,
|
|
3869
|
+
swapAmountToB,
|
|
3870
|
+
maxAccounts,
|
|
3871
|
+
slippageBps,
|
|
3872
|
+
void 0,
|
|
3873
|
+
{
|
|
3874
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
3875
|
+
jupiterApiKey: this.jupiterApiKey
|
|
3876
|
+
}
|
|
3877
|
+
);
|
|
3878
|
+
return {
|
|
3879
|
+
user,
|
|
3880
|
+
pool,
|
|
3881
|
+
position,
|
|
3882
|
+
positionNftAccount,
|
|
3883
|
+
maxSqrtPriceChangeBps,
|
|
3884
|
+
amount: new BN5(0),
|
|
3885
|
+
isDirectPool: false,
|
|
3886
|
+
tokenAMint,
|
|
3887
|
+
tokenBMint,
|
|
3888
|
+
tokenAVault,
|
|
3889
|
+
tokenBVault,
|
|
3890
|
+
tokenAProgram,
|
|
3891
|
+
tokenBProgram,
|
|
3892
|
+
maxTransferAmountA: new BN5(0),
|
|
3893
|
+
maxTransferAmountB: getExtendMaxAmountTransfer(
|
|
3894
|
+
swapToBQuote2.outAmount,
|
|
3895
|
+
maxTransferAmountExtendPercentage
|
|
3896
|
+
),
|
|
3897
|
+
swapType: 1 /* swapToB */,
|
|
3898
|
+
preSqrtPrice: poolState.sqrtPrice,
|
|
3899
|
+
preInstructions,
|
|
3900
|
+
swapTransactions: [swapToBTransaction2],
|
|
3901
|
+
cleanUpInstructions,
|
|
3902
|
+
swapInEstimate: {
|
|
3903
|
+
inAmountA: new BN5(0),
|
|
3904
|
+
inAmountB: swapAmountToB,
|
|
3905
|
+
routeA: "dammV2" /* DammV2 */,
|
|
3906
|
+
routeB: "jupiter" /* Jupiter */
|
|
3907
|
+
}
|
|
3908
|
+
};
|
|
3909
|
+
}
|
|
3910
|
+
if (swapAmountToB.isZero()) {
|
|
3911
|
+
const { transaction: swapToATransaction2, quoteResponse: swapToAQuote2 } = yield buildJupiterSwapTransaction(
|
|
3912
|
+
user,
|
|
3913
|
+
inputTokenMint,
|
|
3914
|
+
tokenAMint,
|
|
3915
|
+
swapAmountToA,
|
|
3916
|
+
maxAccounts,
|
|
3917
|
+
slippageBps,
|
|
3918
|
+
void 0,
|
|
3919
|
+
{
|
|
3920
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
3921
|
+
jupiterApiKey: this.jupiterApiKey
|
|
3922
|
+
}
|
|
3923
|
+
);
|
|
3924
|
+
return {
|
|
3925
|
+
user,
|
|
3926
|
+
pool,
|
|
3927
|
+
position,
|
|
3928
|
+
positionNftAccount,
|
|
3929
|
+
maxSqrtPriceChangeBps,
|
|
3930
|
+
amount: new BN5(0),
|
|
3931
|
+
isDirectPool: false,
|
|
3932
|
+
tokenAMint,
|
|
3933
|
+
tokenBMint,
|
|
3934
|
+
tokenAVault,
|
|
3935
|
+
tokenBVault,
|
|
3936
|
+
tokenAProgram,
|
|
3937
|
+
tokenBProgram,
|
|
3938
|
+
maxTransferAmountA: getExtendMaxAmountTransfer(
|
|
3939
|
+
swapToAQuote2.outAmount,
|
|
3940
|
+
maxTransferAmountExtendPercentage
|
|
3941
|
+
),
|
|
3942
|
+
maxTransferAmountB: new BN5(0),
|
|
3943
|
+
swapType: 0 /* swapToA */,
|
|
3944
|
+
preSqrtPrice: poolState.sqrtPrice,
|
|
3945
|
+
preInstructions,
|
|
3946
|
+
swapTransactions: [swapToATransaction2],
|
|
3947
|
+
cleanUpInstructions,
|
|
3948
|
+
swapInEstimate: {
|
|
3949
|
+
inAmountA: swapAmountToA,
|
|
3950
|
+
inAmountB: new BN5(0),
|
|
3951
|
+
routeA: "jupiter" /* Jupiter */,
|
|
3952
|
+
routeB: "dammV2" /* DammV2 */
|
|
3953
|
+
}
|
|
3954
|
+
};
|
|
3854
3955
|
}
|
|
3855
3956
|
const { transaction: swapToATransaction, quoteResponse: swapToAQuote } = yield buildJupiterSwapTransaction(
|
|
3856
3957
|
user,
|
|
3857
3958
|
inputTokenMint,
|
|
3858
3959
|
tokenAMint,
|
|
3859
|
-
|
|
3960
|
+
swapAmountToA,
|
|
3860
3961
|
maxAccounts,
|
|
3861
3962
|
slippageBps,
|
|
3862
3963
|
void 0,
|
|
@@ -3869,7 +3970,7 @@ var Zap = class {
|
|
|
3869
3970
|
user,
|
|
3870
3971
|
inputTokenMint,
|
|
3871
3972
|
tokenBMint,
|
|
3872
|
-
|
|
3973
|
+
swapAmountToB,
|
|
3873
3974
|
maxAccounts,
|
|
3874
3975
|
slippageBps,
|
|
3875
3976
|
void 0,
|
|
@@ -3906,8 +4007,8 @@ var Zap = class {
|
|
|
3906
4007
|
swapTransactions: [swapToATransaction, swapToBTransaction],
|
|
3907
4008
|
cleanUpInstructions,
|
|
3908
4009
|
swapInEstimate: {
|
|
3909
|
-
inAmountA:
|
|
3910
|
-
inAmountB:
|
|
4010
|
+
inAmountA: swapAmountToA,
|
|
4011
|
+
inAmountB: swapAmountToB,
|
|
3911
4012
|
routeA: "jupiter" /* Jupiter */,
|
|
3912
4013
|
routeB: "jupiter" /* Jupiter */
|
|
3913
4014
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meteora-ag/zap-sdk",
|
|
3
|
-
"version": "1.2.0-rc.
|
|
3
|
+
"version": "1.2.0-rc.3",
|
|
4
4
|
"description": "A Typescript SDK for interacting with the Zap program on Meteora.",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -32,17 +32,17 @@
|
|
|
32
32
|
"@types/bn.js": "^5.1.0",
|
|
33
33
|
"@types/bun": "latest",
|
|
34
34
|
"@types/invariant": "^2.2.37",
|
|
35
|
-
"bip39": "^3.1.0",
|
|
36
|
-
"ed25519-hd-key": "^1.3.0",
|
|
37
35
|
"tsup": "^8.4.0",
|
|
38
|
-
"tsx": "^4.20.3"
|
|
36
|
+
"tsx": "^4.20.3",
|
|
37
|
+
"bip39": "^3.1.0",
|
|
38
|
+
"ed25519-hd-key": "^1.3.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"typescript": "^5"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@coral-xyz/anchor": "^0.31.1",
|
|
45
|
-
"@meteora-ag/cp-amm-sdk": "^1.3
|
|
45
|
+
"@meteora-ag/cp-amm-sdk": "^1.2.3",
|
|
46
46
|
"@meteora-ag/dlmm": "^1.9.0",
|
|
47
47
|
"@solana/spl-token": "^0.4.13",
|
|
48
48
|
"@solana/web3.js": "^1.98.2",
|