@meteora-ag/zap-sdk 1.2.0-rc.3 → 1.2.0-rc.4
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 +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +154 -39
- package/dist/index.mjs +154 -39
- package/package.json +7 -6
package/dist/index.d.mts
CHANGED
|
@@ -2019,6 +2019,8 @@ declare class Zap {
|
|
|
2019
2019
|
private updateLedgerBalanceAfterSwap;
|
|
2020
2020
|
private zapInDammV2;
|
|
2021
2021
|
private resetOrInitializeLedgerAccount;
|
|
2022
|
+
private isJupiterQuoteableAmount;
|
|
2023
|
+
private findMinimumJupiterQuoteableAmount;
|
|
2022
2024
|
private zapInDlmmForInitializedPosition;
|
|
2023
2025
|
private zapInDlmmForUninitializedPosition;
|
|
2024
2026
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -2019,6 +2019,8 @@ declare class Zap {
|
|
|
2019
2019
|
private updateLedgerBalanceAfterSwap;
|
|
2020
2020
|
private zapInDammV2;
|
|
2021
2021
|
private resetOrInitializeLedgerAccount;
|
|
2022
|
+
private isJupiterQuoteableAmount;
|
|
2023
|
+
private findMinimumJupiterQuoteableAmount;
|
|
2022
2024
|
private zapInDlmmForInitializedPosition;
|
|
2023
2025
|
private zapInDlmmForUninitializedPosition;
|
|
2024
2026
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1863,37 +1863,18 @@ 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
|
-
|
|
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 };
|
|
1866
|
+
const instruction = new import_web32.TransactionInstruction({
|
|
1867
|
+
keys: swapInstructionResponse.swapInstruction.accounts.map((item) => {
|
|
1868
|
+
return {
|
|
1869
|
+
pubkey: new import_web32.PublicKey(item.pubkey),
|
|
1870
|
+
isSigner: item.isSigner,
|
|
1871
|
+
isWritable: item.isWritable
|
|
1872
|
+
};
|
|
1873
|
+
}),
|
|
1874
|
+
programId: new import_web32.PublicKey(swapInstructionResponse.swapInstruction.programId),
|
|
1875
|
+
data: Buffer.from(swapInstructionResponse.swapInstruction.data, "base64")
|
|
1876
|
+
});
|
|
1877
|
+
return { transaction: new import_web32.Transaction().add(instruction), quoteResponse };
|
|
1897
1878
|
});
|
|
1898
1879
|
}
|
|
1899
1880
|
|
|
@@ -3224,6 +3205,26 @@ function calculateIndirectPoolSwapAmount(amount, amountDecimals, price1, price2,
|
|
|
3224
3205
|
convertUiAmountToLamports(swapAmountDecimal, amountDecimals).floor().toString()
|
|
3225
3206
|
);
|
|
3226
3207
|
}
|
|
3208
|
+
function splitIndirectSwapAmounts(amountIn, swapAmountToA) {
|
|
3209
|
+
if (swapAmountToA.isNeg()) {
|
|
3210
|
+
throw new Error("Calculated swap amount to token A cannot be negative");
|
|
3211
|
+
}
|
|
3212
|
+
if (swapAmountToA.gt(amountIn)) {
|
|
3213
|
+
throw new Error(
|
|
3214
|
+
"Calculated swap amount to token A exceeds total input amount"
|
|
3215
|
+
);
|
|
3216
|
+
}
|
|
3217
|
+
const swapAmountToB = amountIn.sub(swapAmountToA);
|
|
3218
|
+
if (swapAmountToB.isNeg()) {
|
|
3219
|
+
throw new Error("Calculated swap amount to token B cannot be negative");
|
|
3220
|
+
}
|
|
3221
|
+
return {
|
|
3222
|
+
swapAmountToA,
|
|
3223
|
+
swapAmountToB,
|
|
3224
|
+
hasSwapToA: !swapAmountToA.isZero(),
|
|
3225
|
+
hasSwapToB: !swapAmountToB.isZero()
|
|
3226
|
+
};
|
|
3227
|
+
}
|
|
3227
3228
|
function getExtendMaxAmountTransfer(amount, percentage) {
|
|
3228
3229
|
const extendAmount = new import_decimal3.default(amount).mul(percentage).div(100).floor().toString();
|
|
3229
3230
|
return new import_bn4.default(amount).add(new import_bn4.default(extendAmount));
|
|
@@ -3331,6 +3332,65 @@ var Zap = class {
|
|
|
3331
3332
|
return yield this.initializeLedgerAccount(user, user);
|
|
3332
3333
|
});
|
|
3333
3334
|
}
|
|
3335
|
+
isJupiterQuoteableAmount(inputMint, outputMint, amount, maxAccounts, slippageBps) {
|
|
3336
|
+
return __async(this, null, function* () {
|
|
3337
|
+
if (amount.isZero()) {
|
|
3338
|
+
return true;
|
|
3339
|
+
}
|
|
3340
|
+
const quote = yield getJupiterQuote(
|
|
3341
|
+
inputMint,
|
|
3342
|
+
outputMint,
|
|
3343
|
+
amount,
|
|
3344
|
+
maxAccounts,
|
|
3345
|
+
slippageBps,
|
|
3346
|
+
false,
|
|
3347
|
+
true,
|
|
3348
|
+
true,
|
|
3349
|
+
{
|
|
3350
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
3351
|
+
jupiterApiKey: this.jupiterApiKey
|
|
3352
|
+
}
|
|
3353
|
+
);
|
|
3354
|
+
return quote !== null;
|
|
3355
|
+
});
|
|
3356
|
+
}
|
|
3357
|
+
findMinimumJupiterQuoteableAmount(inputMint, outputMint, maxAmount, maxAccounts, slippageBps) {
|
|
3358
|
+
return __async(this, null, function* () {
|
|
3359
|
+
if (maxAmount.isZero()) {
|
|
3360
|
+
return null;
|
|
3361
|
+
}
|
|
3362
|
+
const maxAmountQuoteable = yield this.isJupiterQuoteableAmount(
|
|
3363
|
+
inputMint,
|
|
3364
|
+
outputMint,
|
|
3365
|
+
maxAmount,
|
|
3366
|
+
maxAccounts,
|
|
3367
|
+
slippageBps
|
|
3368
|
+
);
|
|
3369
|
+
if (!maxAmountQuoteable) {
|
|
3370
|
+
return null;
|
|
3371
|
+
}
|
|
3372
|
+
let left = new import_anchor.BN(1);
|
|
3373
|
+
let right = maxAmount;
|
|
3374
|
+
let best = maxAmount;
|
|
3375
|
+
while (left.lte(right)) {
|
|
3376
|
+
const mid = left.add(right).div(new import_anchor.BN(2));
|
|
3377
|
+
const isQuoteable = yield this.isJupiterQuoteableAmount(
|
|
3378
|
+
inputMint,
|
|
3379
|
+
outputMint,
|
|
3380
|
+
mid,
|
|
3381
|
+
maxAccounts,
|
|
3382
|
+
slippageBps
|
|
3383
|
+
);
|
|
3384
|
+
if (isQuoteable) {
|
|
3385
|
+
best = mid;
|
|
3386
|
+
right = mid.sub(new import_anchor.BN(1));
|
|
3387
|
+
} else {
|
|
3388
|
+
left = mid.add(new import_anchor.BN(1));
|
|
3389
|
+
}
|
|
3390
|
+
}
|
|
3391
|
+
return best;
|
|
3392
|
+
});
|
|
3393
|
+
}
|
|
3334
3394
|
zapInDlmmForInitializedPosition(params) {
|
|
3335
3395
|
return __async(this, null, function* () {
|
|
3336
3396
|
const {
|
|
@@ -3881,8 +3941,63 @@ var Zap = class {
|
|
|
3881
3941
|
tokenBDecimal
|
|
3882
3942
|
)
|
|
3883
3943
|
);
|
|
3884
|
-
|
|
3885
|
-
|
|
3944
|
+
let { swapAmountToA: adjustedSwapAmountToA, swapAmountToB } = splitIndirectSwapAmounts(amountIn, swapAmountToA);
|
|
3945
|
+
const quoteableA = yield this.isJupiterQuoteableAmount(
|
|
3946
|
+
inputTokenMint,
|
|
3947
|
+
tokenAMint,
|
|
3948
|
+
adjustedSwapAmountToA,
|
|
3949
|
+
maxAccounts,
|
|
3950
|
+
slippageBps
|
|
3951
|
+
);
|
|
3952
|
+
if (!quoteableA && !adjustedSwapAmountToA.isZero()) {
|
|
3953
|
+
const minQuoteableToA = yield this.findMinimumJupiterQuoteableAmount(
|
|
3954
|
+
inputTokenMint,
|
|
3955
|
+
tokenAMint,
|
|
3956
|
+
amountIn,
|
|
3957
|
+
maxAccounts,
|
|
3958
|
+
slippageBps
|
|
3959
|
+
);
|
|
3960
|
+
if (minQuoteableToA !== null) {
|
|
3961
|
+
adjustedSwapAmountToA = minQuoteableToA;
|
|
3962
|
+
swapAmountToB = amountIn.sub(adjustedSwapAmountToA);
|
|
3963
|
+
} else {
|
|
3964
|
+
adjustedSwapAmountToA = new import_anchor.BN(0);
|
|
3965
|
+
swapAmountToB = amountIn;
|
|
3966
|
+
}
|
|
3967
|
+
}
|
|
3968
|
+
const quoteableB = yield this.isJupiterQuoteableAmount(
|
|
3969
|
+
inputTokenMint,
|
|
3970
|
+
tokenBMint,
|
|
3971
|
+
swapAmountToB,
|
|
3972
|
+
maxAccounts,
|
|
3973
|
+
slippageBps
|
|
3974
|
+
);
|
|
3975
|
+
if (!quoteableB && !swapAmountToB.isZero()) {
|
|
3976
|
+
const minQuoteableToB = yield this.findMinimumJupiterQuoteableAmount(
|
|
3977
|
+
inputTokenMint,
|
|
3978
|
+
tokenBMint,
|
|
3979
|
+
amountIn,
|
|
3980
|
+
maxAccounts,
|
|
3981
|
+
slippageBps
|
|
3982
|
+
);
|
|
3983
|
+
if (minQuoteableToB !== null) {
|
|
3984
|
+
swapAmountToB = minQuoteableToB;
|
|
3985
|
+
adjustedSwapAmountToA = amountIn.sub(swapAmountToB);
|
|
3986
|
+
} else {
|
|
3987
|
+
swapAmountToB = new import_anchor.BN(0);
|
|
3988
|
+
adjustedSwapAmountToA = amountIn;
|
|
3989
|
+
}
|
|
3990
|
+
}
|
|
3991
|
+
const { hasSwapToA, hasSwapToB } = splitIndirectSwapAmounts(
|
|
3992
|
+
amountIn,
|
|
3993
|
+
adjustedSwapAmountToA
|
|
3994
|
+
);
|
|
3995
|
+
if (!hasSwapToA && !hasSwapToB) {
|
|
3996
|
+
throw new Error(
|
|
3997
|
+
"Calculated zero swap amount for both token routes, unable to proceed"
|
|
3998
|
+
);
|
|
3999
|
+
}
|
|
4000
|
+
if (!hasSwapToA) {
|
|
3886
4001
|
const { transaction: swapToBTransaction2, quoteResponse: swapToBQuote2 } = yield buildJupiterSwapTransaction(
|
|
3887
4002
|
user,
|
|
3888
4003
|
inputTokenMint,
|
|
@@ -3928,12 +4043,12 @@ var Zap = class {
|
|
|
3928
4043
|
}
|
|
3929
4044
|
};
|
|
3930
4045
|
}
|
|
3931
|
-
if (
|
|
4046
|
+
if (!hasSwapToB) {
|
|
3932
4047
|
const { transaction: swapToATransaction2, quoteResponse: swapToAQuote2 } = yield buildJupiterSwapTransaction(
|
|
3933
4048
|
user,
|
|
3934
4049
|
inputTokenMint,
|
|
3935
4050
|
tokenAMint,
|
|
3936
|
-
|
|
4051
|
+
adjustedSwapAmountToA,
|
|
3937
4052
|
maxAccounts,
|
|
3938
4053
|
slippageBps,
|
|
3939
4054
|
void 0,
|
|
@@ -3960,14 +4075,14 @@ var Zap = class {
|
|
|
3960
4075
|
swapToAQuote2.outAmount,
|
|
3961
4076
|
maxTransferAmountExtendPercentage
|
|
3962
4077
|
),
|
|
3963
|
-
maxTransferAmountB: new import_anchor.BN(0),
|
|
3964
4078
|
swapType: 0 /* swapToA */,
|
|
4079
|
+
maxTransferAmountB: new import_anchor.BN(0),
|
|
3965
4080
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3966
4081
|
preInstructions,
|
|
3967
4082
|
swapTransactions: [swapToATransaction2],
|
|
3968
4083
|
cleanUpInstructions,
|
|
3969
4084
|
swapInEstimate: {
|
|
3970
|
-
inAmountA:
|
|
4085
|
+
inAmountA: adjustedSwapAmountToA,
|
|
3971
4086
|
inAmountB: new import_anchor.BN(0),
|
|
3972
4087
|
routeA: "jupiter" /* Jupiter */,
|
|
3973
4088
|
routeB: "dammV2" /* DammV2 */
|
|
@@ -3978,7 +4093,7 @@ var Zap = class {
|
|
|
3978
4093
|
user,
|
|
3979
4094
|
inputTokenMint,
|
|
3980
4095
|
tokenAMint,
|
|
3981
|
-
|
|
4096
|
+
adjustedSwapAmountToA,
|
|
3982
4097
|
maxAccounts,
|
|
3983
4098
|
slippageBps,
|
|
3984
4099
|
void 0,
|
|
@@ -4028,7 +4143,7 @@ var Zap = class {
|
|
|
4028
4143
|
swapTransactions: [swapToATransaction, swapToBTransaction],
|
|
4029
4144
|
cleanUpInstructions,
|
|
4030
4145
|
swapInEstimate: {
|
|
4031
|
-
inAmountA:
|
|
4146
|
+
inAmountA: adjustedSwapAmountToA,
|
|
4032
4147
|
inAmountB: swapAmountToB,
|
|
4033
4148
|
routeA: "jupiter" /* Jupiter */,
|
|
4034
4149
|
routeB: "jupiter" /* Jupiter */
|
package/dist/index.mjs
CHANGED
|
@@ -1793,37 +1793,18 @@ 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
|
-
|
|
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 };
|
|
1796
|
+
const instruction = new TransactionInstruction({
|
|
1797
|
+
keys: swapInstructionResponse.swapInstruction.accounts.map((item) => {
|
|
1798
|
+
return {
|
|
1799
|
+
pubkey: new PublicKey2(item.pubkey),
|
|
1800
|
+
isSigner: item.isSigner,
|
|
1801
|
+
isWritable: item.isWritable
|
|
1802
|
+
};
|
|
1803
|
+
}),
|
|
1804
|
+
programId: new PublicKey2(swapInstructionResponse.swapInstruction.programId),
|
|
1805
|
+
data: Buffer.from(swapInstructionResponse.swapInstruction.data, "base64")
|
|
1806
|
+
});
|
|
1807
|
+
return { transaction: new Transaction().add(instruction), quoteResponse };
|
|
1827
1808
|
});
|
|
1828
1809
|
}
|
|
1829
1810
|
|
|
@@ -3203,6 +3184,26 @@ function calculateIndirectPoolSwapAmount(amount, amountDecimals, price1, price2,
|
|
|
3203
3184
|
convertUiAmountToLamports(swapAmountDecimal, amountDecimals).floor().toString()
|
|
3204
3185
|
);
|
|
3205
3186
|
}
|
|
3187
|
+
function splitIndirectSwapAmounts(amountIn, swapAmountToA) {
|
|
3188
|
+
if (swapAmountToA.isNeg()) {
|
|
3189
|
+
throw new Error("Calculated swap amount to token A cannot be negative");
|
|
3190
|
+
}
|
|
3191
|
+
if (swapAmountToA.gt(amountIn)) {
|
|
3192
|
+
throw new Error(
|
|
3193
|
+
"Calculated swap amount to token A exceeds total input amount"
|
|
3194
|
+
);
|
|
3195
|
+
}
|
|
3196
|
+
const swapAmountToB = amountIn.sub(swapAmountToA);
|
|
3197
|
+
if (swapAmountToB.isNeg()) {
|
|
3198
|
+
throw new Error("Calculated swap amount to token B cannot be negative");
|
|
3199
|
+
}
|
|
3200
|
+
return {
|
|
3201
|
+
swapAmountToA,
|
|
3202
|
+
swapAmountToB,
|
|
3203
|
+
hasSwapToA: !swapAmountToA.isZero(),
|
|
3204
|
+
hasSwapToB: !swapAmountToB.isZero()
|
|
3205
|
+
};
|
|
3206
|
+
}
|
|
3206
3207
|
function getExtendMaxAmountTransfer(amount, percentage) {
|
|
3207
3208
|
const extendAmount = new Decimal3(amount).mul(percentage).div(100).floor().toString();
|
|
3208
3209
|
return new BN4(amount).add(new BN4(extendAmount));
|
|
@@ -3310,6 +3311,65 @@ var Zap = class {
|
|
|
3310
3311
|
return yield this.initializeLedgerAccount(user, user);
|
|
3311
3312
|
});
|
|
3312
3313
|
}
|
|
3314
|
+
isJupiterQuoteableAmount(inputMint, outputMint, amount, maxAccounts, slippageBps) {
|
|
3315
|
+
return __async(this, null, function* () {
|
|
3316
|
+
if (amount.isZero()) {
|
|
3317
|
+
return true;
|
|
3318
|
+
}
|
|
3319
|
+
const quote = yield getJupiterQuote(
|
|
3320
|
+
inputMint,
|
|
3321
|
+
outputMint,
|
|
3322
|
+
amount,
|
|
3323
|
+
maxAccounts,
|
|
3324
|
+
slippageBps,
|
|
3325
|
+
false,
|
|
3326
|
+
true,
|
|
3327
|
+
true,
|
|
3328
|
+
{
|
|
3329
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
3330
|
+
jupiterApiKey: this.jupiterApiKey
|
|
3331
|
+
}
|
|
3332
|
+
);
|
|
3333
|
+
return quote !== null;
|
|
3334
|
+
});
|
|
3335
|
+
}
|
|
3336
|
+
findMinimumJupiterQuoteableAmount(inputMint, outputMint, maxAmount, maxAccounts, slippageBps) {
|
|
3337
|
+
return __async(this, null, function* () {
|
|
3338
|
+
if (maxAmount.isZero()) {
|
|
3339
|
+
return null;
|
|
3340
|
+
}
|
|
3341
|
+
const maxAmountQuoteable = yield this.isJupiterQuoteableAmount(
|
|
3342
|
+
inputMint,
|
|
3343
|
+
outputMint,
|
|
3344
|
+
maxAmount,
|
|
3345
|
+
maxAccounts,
|
|
3346
|
+
slippageBps
|
|
3347
|
+
);
|
|
3348
|
+
if (!maxAmountQuoteable) {
|
|
3349
|
+
return null;
|
|
3350
|
+
}
|
|
3351
|
+
let left = new BN5(1);
|
|
3352
|
+
let right = maxAmount;
|
|
3353
|
+
let best = maxAmount;
|
|
3354
|
+
while (left.lte(right)) {
|
|
3355
|
+
const mid = left.add(right).div(new BN5(2));
|
|
3356
|
+
const isQuoteable = yield this.isJupiterQuoteableAmount(
|
|
3357
|
+
inputMint,
|
|
3358
|
+
outputMint,
|
|
3359
|
+
mid,
|
|
3360
|
+
maxAccounts,
|
|
3361
|
+
slippageBps
|
|
3362
|
+
);
|
|
3363
|
+
if (isQuoteable) {
|
|
3364
|
+
best = mid;
|
|
3365
|
+
right = mid.sub(new BN5(1));
|
|
3366
|
+
} else {
|
|
3367
|
+
left = mid.add(new BN5(1));
|
|
3368
|
+
}
|
|
3369
|
+
}
|
|
3370
|
+
return best;
|
|
3371
|
+
});
|
|
3372
|
+
}
|
|
3313
3373
|
zapInDlmmForInitializedPosition(params) {
|
|
3314
3374
|
return __async(this, null, function* () {
|
|
3315
3375
|
const {
|
|
@@ -3860,8 +3920,63 @@ var Zap = class {
|
|
|
3860
3920
|
tokenBDecimal
|
|
3861
3921
|
)
|
|
3862
3922
|
);
|
|
3863
|
-
|
|
3864
|
-
|
|
3923
|
+
let { swapAmountToA: adjustedSwapAmountToA, swapAmountToB } = splitIndirectSwapAmounts(amountIn, swapAmountToA);
|
|
3924
|
+
const quoteableA = yield this.isJupiterQuoteableAmount(
|
|
3925
|
+
inputTokenMint,
|
|
3926
|
+
tokenAMint,
|
|
3927
|
+
adjustedSwapAmountToA,
|
|
3928
|
+
maxAccounts,
|
|
3929
|
+
slippageBps
|
|
3930
|
+
);
|
|
3931
|
+
if (!quoteableA && !adjustedSwapAmountToA.isZero()) {
|
|
3932
|
+
const minQuoteableToA = yield this.findMinimumJupiterQuoteableAmount(
|
|
3933
|
+
inputTokenMint,
|
|
3934
|
+
tokenAMint,
|
|
3935
|
+
amountIn,
|
|
3936
|
+
maxAccounts,
|
|
3937
|
+
slippageBps
|
|
3938
|
+
);
|
|
3939
|
+
if (minQuoteableToA !== null) {
|
|
3940
|
+
adjustedSwapAmountToA = minQuoteableToA;
|
|
3941
|
+
swapAmountToB = amountIn.sub(adjustedSwapAmountToA);
|
|
3942
|
+
} else {
|
|
3943
|
+
adjustedSwapAmountToA = new BN5(0);
|
|
3944
|
+
swapAmountToB = amountIn;
|
|
3945
|
+
}
|
|
3946
|
+
}
|
|
3947
|
+
const quoteableB = yield this.isJupiterQuoteableAmount(
|
|
3948
|
+
inputTokenMint,
|
|
3949
|
+
tokenBMint,
|
|
3950
|
+
swapAmountToB,
|
|
3951
|
+
maxAccounts,
|
|
3952
|
+
slippageBps
|
|
3953
|
+
);
|
|
3954
|
+
if (!quoteableB && !swapAmountToB.isZero()) {
|
|
3955
|
+
const minQuoteableToB = yield this.findMinimumJupiterQuoteableAmount(
|
|
3956
|
+
inputTokenMint,
|
|
3957
|
+
tokenBMint,
|
|
3958
|
+
amountIn,
|
|
3959
|
+
maxAccounts,
|
|
3960
|
+
slippageBps
|
|
3961
|
+
);
|
|
3962
|
+
if (minQuoteableToB !== null) {
|
|
3963
|
+
swapAmountToB = minQuoteableToB;
|
|
3964
|
+
adjustedSwapAmountToA = amountIn.sub(swapAmountToB);
|
|
3965
|
+
} else {
|
|
3966
|
+
swapAmountToB = new BN5(0);
|
|
3967
|
+
adjustedSwapAmountToA = amountIn;
|
|
3968
|
+
}
|
|
3969
|
+
}
|
|
3970
|
+
const { hasSwapToA, hasSwapToB } = splitIndirectSwapAmounts(
|
|
3971
|
+
amountIn,
|
|
3972
|
+
adjustedSwapAmountToA
|
|
3973
|
+
);
|
|
3974
|
+
if (!hasSwapToA && !hasSwapToB) {
|
|
3975
|
+
throw new Error(
|
|
3976
|
+
"Calculated zero swap amount for both token routes, unable to proceed"
|
|
3977
|
+
);
|
|
3978
|
+
}
|
|
3979
|
+
if (!hasSwapToA) {
|
|
3865
3980
|
const { transaction: swapToBTransaction2, quoteResponse: swapToBQuote2 } = yield buildJupiterSwapTransaction(
|
|
3866
3981
|
user,
|
|
3867
3982
|
inputTokenMint,
|
|
@@ -3907,12 +4022,12 @@ var Zap = class {
|
|
|
3907
4022
|
}
|
|
3908
4023
|
};
|
|
3909
4024
|
}
|
|
3910
|
-
if (
|
|
4025
|
+
if (!hasSwapToB) {
|
|
3911
4026
|
const { transaction: swapToATransaction2, quoteResponse: swapToAQuote2 } = yield buildJupiterSwapTransaction(
|
|
3912
4027
|
user,
|
|
3913
4028
|
inputTokenMint,
|
|
3914
4029
|
tokenAMint,
|
|
3915
|
-
|
|
4030
|
+
adjustedSwapAmountToA,
|
|
3916
4031
|
maxAccounts,
|
|
3917
4032
|
slippageBps,
|
|
3918
4033
|
void 0,
|
|
@@ -3939,14 +4054,14 @@ var Zap = class {
|
|
|
3939
4054
|
swapToAQuote2.outAmount,
|
|
3940
4055
|
maxTransferAmountExtendPercentage
|
|
3941
4056
|
),
|
|
3942
|
-
maxTransferAmountB: new BN5(0),
|
|
3943
4057
|
swapType: 0 /* swapToA */,
|
|
4058
|
+
maxTransferAmountB: new BN5(0),
|
|
3944
4059
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3945
4060
|
preInstructions,
|
|
3946
4061
|
swapTransactions: [swapToATransaction2],
|
|
3947
4062
|
cleanUpInstructions,
|
|
3948
4063
|
swapInEstimate: {
|
|
3949
|
-
inAmountA:
|
|
4064
|
+
inAmountA: adjustedSwapAmountToA,
|
|
3950
4065
|
inAmountB: new BN5(0),
|
|
3951
4066
|
routeA: "jupiter" /* Jupiter */,
|
|
3952
4067
|
routeB: "dammV2" /* DammV2 */
|
|
@@ -3957,7 +4072,7 @@ var Zap = class {
|
|
|
3957
4072
|
user,
|
|
3958
4073
|
inputTokenMint,
|
|
3959
4074
|
tokenAMint,
|
|
3960
|
-
|
|
4075
|
+
adjustedSwapAmountToA,
|
|
3961
4076
|
maxAccounts,
|
|
3962
4077
|
slippageBps,
|
|
3963
4078
|
void 0,
|
|
@@ -4007,7 +4122,7 @@ var Zap = class {
|
|
|
4007
4122
|
swapTransactions: [swapToATransaction, swapToBTransaction],
|
|
4008
4123
|
cleanUpInstructions,
|
|
4009
4124
|
swapInEstimate: {
|
|
4010
|
-
inAmountA:
|
|
4125
|
+
inAmountA: adjustedSwapAmountToA,
|
|
4011
4126
|
inAmountB: swapAmountToB,
|
|
4012
4127
|
routeA: "jupiter" /* Jupiter */,
|
|
4013
4128
|
routeB: "jupiter" /* Jupiter */
|
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.4",
|
|
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
|
-
"tsup": "^8.4.0",
|
|
36
|
-
"tsx": "^4.20.3",
|
|
37
35
|
"bip39": "^3.1.0",
|
|
38
|
-
"ed25519-hd-key": "^1.3.0"
|
|
36
|
+
"ed25519-hd-key": "^1.3.0",
|
|
37
|
+
"tsup": "^8.4.0",
|
|
38
|
+
"tsx": "^4.20.3"
|
|
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.
|
|
45
|
+
"@meteora-ag/cp-amm-sdk": "^1.3.6",
|
|
46
46
|
"@meteora-ag/dlmm": "^1.9.0",
|
|
47
47
|
"@solana/spl-token": "^0.4.13",
|
|
48
48
|
"@solana/web3.js": "^1.98.2",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"build": "rm -rf dist && tsup src/index.ts --format esm,cjs --dts",
|
|
55
|
-
"clean": "rm -rf dist && rm -rf node_modules rm -rf pnpm-lock.yaml"
|
|
55
|
+
"clean": "rm -rf dist && rm -rf node_modules rm -rf pnpm-lock.yaml",
|
|
56
|
+
"test": "node --import tsx --test tests/**/*.test.ts"
|
|
56
57
|
}
|
|
57
58
|
}
|