@crypticdot/defituna-client 3.1.16 → 3.1.18
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 +11 -17
- package/dist/index.mjs +11 -17
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -10323,10 +10323,10 @@ function getIncreaseSpotPositionQuote(args) {
|
|
|
10323
10323
|
let nextSqrtPrice = fusionPool.sqrtPrice;
|
|
10324
10324
|
if (positionToken != collateralToken) {
|
|
10325
10325
|
const price = (0, import_fusionamm_core4.sqrtPriceToPrice)(fusionPool.sqrtPrice, 1, 1);
|
|
10326
|
-
borrow = BigInt(Math.
|
|
10327
|
-
|
|
10328
|
-
collateral = reverseApplyTunaProtocolFee(increaseAmount - borrowWithFeesApplied, protocolFeeRateOnCollateral);
|
|
10326
|
+
borrow = BigInt(Math.ceil(Number(increaseAmount) * (leverage - 1) / leverage));
|
|
10327
|
+
collateral = increaseAmount - (0, import_fusionamm_core4.tryApplySwapFee)(applyTunaProtocolFee(borrow, protocolFeeRate), fusionPool.feeRate);
|
|
10329
10328
|
collateral = (0, import_fusionamm_core4.tryReverseApplySwapFee)(collateral, fusionPool.feeRate);
|
|
10329
|
+
collateral = reverseApplyTunaProtocolFee(collateral, protocolFeeRateOnCollateral);
|
|
10330
10330
|
swapInputAmount = increaseAmount;
|
|
10331
10331
|
estimatedAmount = BigInt(
|
|
10332
10332
|
Math.round(collateralToken == 0 /* A */ ? Number(increaseAmount) * price : Number(increaseAmount) / price)
|
|
@@ -10334,16 +10334,14 @@ function getIncreaseSpotPositionQuote(args) {
|
|
|
10334
10334
|
} else {
|
|
10335
10335
|
const price = (0, import_fusionamm_core4.sqrtPriceToPrice)(fusionPool.sqrtPrice, 1, 1);
|
|
10336
10336
|
const positionToBorrowedTokenPrice = collateralToken == 0 /* A */ ? price : 1 / price;
|
|
10337
|
-
const borrowInPositionToken = Number(increaseAmount) * (leverage - 1) / leverage;
|
|
10338
|
-
borrow = BigInt(Math.
|
|
10337
|
+
const borrowInPositionToken = Math.ceil(Number(increaseAmount) * (leverage - 1) / leverage);
|
|
10338
|
+
borrow = BigInt(Math.ceil(borrowInPositionToken * positionToBorrowedTokenPrice));
|
|
10339
10339
|
const borrowInPositionTokenWithFeesApplied = (0, import_fusionamm_core4.tryApplySwapFee)(
|
|
10340
10340
|
applyTunaProtocolFee(BigInt(Math.floor(borrowInPositionToken)), protocolFeeRate),
|
|
10341
10341
|
fusionPool.feeRate
|
|
10342
10342
|
);
|
|
10343
|
-
collateral =
|
|
10344
|
-
|
|
10345
|
-
protocolFeeRateOnCollateral
|
|
10346
|
-
);
|
|
10343
|
+
collateral = increaseAmount - borrowInPositionTokenWithFeesApplied;
|
|
10344
|
+
collateral = reverseApplyTunaProtocolFee(collateral, protocolFeeRateOnCollateral);
|
|
10347
10345
|
swapInputAmount = applyTunaProtocolFee(borrow, protocolFeeRate);
|
|
10348
10346
|
estimatedAmount = increaseAmount;
|
|
10349
10347
|
}
|
|
@@ -10499,16 +10497,12 @@ function getTradableAmount(args) {
|
|
|
10499
10497
|
let availableToTrade = 0n;
|
|
10500
10498
|
const addLeverage = (collateral) => {
|
|
10501
10499
|
collateral = applyTunaProtocolFee(collateral, protocolFeeRateOnCollateral);
|
|
10502
|
-
const feeMultiplier = (1 - protocolFeeRate / HUNDRED_PERCENT) * (1 - fusionPool.feeRate / 1e6);
|
|
10503
|
-
let borrow = BigInt(
|
|
10504
|
-
Math.round(Number(collateral) * (leverage - 1) / (leverage + feeMultiplier * (1 - leverage)))
|
|
10505
|
-
);
|
|
10506
|
-
borrow = applyTunaProtocolFee(borrow, protocolFeeRate);
|
|
10507
|
-
borrow = (0, import_fusionamm_core4.tryApplySwapFee)(borrow, fusionPool.feeRate);
|
|
10508
10500
|
if (collateralToken != newPositionToken) {
|
|
10509
10501
|
collateral = (0, import_fusionamm_core4.tryApplySwapFee)(collateral, fusionPool.feeRate);
|
|
10510
10502
|
}
|
|
10511
|
-
|
|
10503
|
+
const feeMultiplier = (1 - protocolFeeRate / HUNDRED_PERCENT) * (1 - fusionPool.feeRate / 1e6);
|
|
10504
|
+
const total = Number(collateral) / (1 - feeMultiplier * (leverage - 1) / leverage);
|
|
10505
|
+
return BigInt(Math.floor(total));
|
|
10512
10506
|
};
|
|
10513
10507
|
if (newPositionToken == positionToken) {
|
|
10514
10508
|
availableToTrade = addLeverage(availableBalance);
|
|
@@ -10523,7 +10517,7 @@ function getTradableAmount(args) {
|
|
|
10523
10517
|
}
|
|
10524
10518
|
} else {
|
|
10525
10519
|
const positionAmountInCollateralToken = collateralToken == positionToken ? positionAmount : BigInt(Math.round(Number(positionAmount) * positionToOppositeTokenPrice));
|
|
10526
|
-
let positionCollateral = collateralToken == positionToken ? positionAmount - (0, import_fusionamm_core4.swapQuoteByOutputToken)(positionDebt, positionToken == 1 /* B */, 0, fusionPool, tickArrays).tokenEstIn : (0, import_fusionamm_core4.swapQuoteByInputToken)(positionAmount, positionToken == 0 /* A */, 0, fusionPool, tickArrays).tokenEstOut - positionDebt;
|
|
10520
|
+
let positionCollateral = collateralToken == positionToken ? positionAmount - (positionDebt > 0n ? (0, import_fusionamm_core4.swapQuoteByOutputToken)(positionDebt, positionToken == 1 /* B */, 0, fusionPool, tickArrays).tokenEstIn : 0n) : positionAmount > 0n ? (0, import_fusionamm_core4.swapQuoteByInputToken)(positionAmount, positionToken == 0 /* A */, 0, fusionPool, tickArrays).tokenEstOut - positionDebt : 0n;
|
|
10527
10521
|
if (positionCollateral < 0n) positionCollateral = 0n;
|
|
10528
10522
|
availableToTrade = positionAmountInCollateralToken + addLeverage(availableBalance + positionCollateral);
|
|
10529
10523
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -10493,10 +10493,10 @@ function getIncreaseSpotPositionQuote(args) {
|
|
|
10493
10493
|
let nextSqrtPrice = fusionPool.sqrtPrice;
|
|
10494
10494
|
if (positionToken != collateralToken) {
|
|
10495
10495
|
const price = sqrtPriceToPrice(fusionPool.sqrtPrice, 1, 1);
|
|
10496
|
-
borrow = BigInt(Math.
|
|
10497
|
-
|
|
10498
|
-
collateral = reverseApplyTunaProtocolFee(increaseAmount - borrowWithFeesApplied, protocolFeeRateOnCollateral);
|
|
10496
|
+
borrow = BigInt(Math.ceil(Number(increaseAmount) * (leverage - 1) / leverage));
|
|
10497
|
+
collateral = increaseAmount - tryApplySwapFee2(applyTunaProtocolFee(borrow, protocolFeeRate), fusionPool.feeRate);
|
|
10499
10498
|
collateral = tryReverseApplySwapFee(collateral, fusionPool.feeRate);
|
|
10499
|
+
collateral = reverseApplyTunaProtocolFee(collateral, protocolFeeRateOnCollateral);
|
|
10500
10500
|
swapInputAmount = increaseAmount;
|
|
10501
10501
|
estimatedAmount = BigInt(
|
|
10502
10502
|
Math.round(collateralToken == 0 /* A */ ? Number(increaseAmount) * price : Number(increaseAmount) / price)
|
|
@@ -10504,16 +10504,14 @@ function getIncreaseSpotPositionQuote(args) {
|
|
|
10504
10504
|
} else {
|
|
10505
10505
|
const price = sqrtPriceToPrice(fusionPool.sqrtPrice, 1, 1);
|
|
10506
10506
|
const positionToBorrowedTokenPrice = collateralToken == 0 /* A */ ? price : 1 / price;
|
|
10507
|
-
const borrowInPositionToken = Number(increaseAmount) * (leverage - 1) / leverage;
|
|
10508
|
-
borrow = BigInt(Math.
|
|
10507
|
+
const borrowInPositionToken = Math.ceil(Number(increaseAmount) * (leverage - 1) / leverage);
|
|
10508
|
+
borrow = BigInt(Math.ceil(borrowInPositionToken * positionToBorrowedTokenPrice));
|
|
10509
10509
|
const borrowInPositionTokenWithFeesApplied = tryApplySwapFee2(
|
|
10510
10510
|
applyTunaProtocolFee(BigInt(Math.floor(borrowInPositionToken)), protocolFeeRate),
|
|
10511
10511
|
fusionPool.feeRate
|
|
10512
10512
|
);
|
|
10513
|
-
collateral =
|
|
10514
|
-
|
|
10515
|
-
protocolFeeRateOnCollateral
|
|
10516
|
-
);
|
|
10513
|
+
collateral = increaseAmount - borrowInPositionTokenWithFeesApplied;
|
|
10514
|
+
collateral = reverseApplyTunaProtocolFee(collateral, protocolFeeRateOnCollateral);
|
|
10517
10515
|
swapInputAmount = applyTunaProtocolFee(borrow, protocolFeeRate);
|
|
10518
10516
|
estimatedAmount = increaseAmount;
|
|
10519
10517
|
}
|
|
@@ -10669,16 +10667,12 @@ function getTradableAmount(args) {
|
|
|
10669
10667
|
let availableToTrade = 0n;
|
|
10670
10668
|
const addLeverage = (collateral) => {
|
|
10671
10669
|
collateral = applyTunaProtocolFee(collateral, protocolFeeRateOnCollateral);
|
|
10672
|
-
const feeMultiplier = (1 - protocolFeeRate / HUNDRED_PERCENT) * (1 - fusionPool.feeRate / 1e6);
|
|
10673
|
-
let borrow = BigInt(
|
|
10674
|
-
Math.round(Number(collateral) * (leverage - 1) / (leverage + feeMultiplier * (1 - leverage)))
|
|
10675
|
-
);
|
|
10676
|
-
borrow = applyTunaProtocolFee(borrow, protocolFeeRate);
|
|
10677
|
-
borrow = tryApplySwapFee2(borrow, fusionPool.feeRate);
|
|
10678
10670
|
if (collateralToken != newPositionToken) {
|
|
10679
10671
|
collateral = tryApplySwapFee2(collateral, fusionPool.feeRate);
|
|
10680
10672
|
}
|
|
10681
|
-
|
|
10673
|
+
const feeMultiplier = (1 - protocolFeeRate / HUNDRED_PERCENT) * (1 - fusionPool.feeRate / 1e6);
|
|
10674
|
+
const total = Number(collateral) / (1 - feeMultiplier * (leverage - 1) / leverage);
|
|
10675
|
+
return BigInt(Math.floor(total));
|
|
10682
10676
|
};
|
|
10683
10677
|
if (newPositionToken == positionToken) {
|
|
10684
10678
|
availableToTrade = addLeverage(availableBalance);
|
|
@@ -10693,7 +10687,7 @@ function getTradableAmount(args) {
|
|
|
10693
10687
|
}
|
|
10694
10688
|
} else {
|
|
10695
10689
|
const positionAmountInCollateralToken = collateralToken == positionToken ? positionAmount : BigInt(Math.round(Number(positionAmount) * positionToOppositeTokenPrice));
|
|
10696
|
-
let positionCollateral = collateralToken == positionToken ? positionAmount - swapQuoteByOutputToken(positionDebt, positionToken == 1 /* B */, 0, fusionPool, tickArrays).tokenEstIn : swapQuoteByInputToken(positionAmount, positionToken == 0 /* A */, 0, fusionPool, tickArrays).tokenEstOut - positionDebt;
|
|
10690
|
+
let positionCollateral = collateralToken == positionToken ? positionAmount - (positionDebt > 0n ? swapQuoteByOutputToken(positionDebt, positionToken == 1 /* B */, 0, fusionPool, tickArrays).tokenEstIn : 0n) : positionAmount > 0n ? swapQuoteByInputToken(positionAmount, positionToken == 0 /* A */, 0, fusionPool, tickArrays).tokenEstOut - positionDebt : 0n;
|
|
10697
10691
|
if (positionCollateral < 0n) positionCollateral = 0n;
|
|
10698
10692
|
availableToTrade = positionAmountInCollateralToken + addLeverage(availableBalance + positionCollateral);
|
|
10699
10693
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crypticdot/defituna-client",
|
|
3
3
|
"description": "Typescript client to interact with DefiTuna's on-chain program.",
|
|
4
|
-
"version": "3.1.
|
|
4
|
+
"version": "3.1.18",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"@orca-so/whirlpools-core": "^2.0.0",
|
|
20
20
|
"@orca-so/whirlpools-client": "^4.0.1",
|
|
21
21
|
"@orca-so/whirlpools": "^4.0.0",
|
|
22
|
-
"@crypticdot/fusionamm-core": "^1.0.
|
|
23
|
-
"@crypticdot/fusionamm-client": "^1.0.
|
|
24
|
-
"@crypticdot/fusionamm-sdk": "^1.0.
|
|
22
|
+
"@crypticdot/fusionamm-core": "^1.0.67",
|
|
23
|
+
"@crypticdot/fusionamm-client": "^1.0.67",
|
|
24
|
+
"@crypticdot/fusionamm-sdk": "^1.0.67",
|
|
25
25
|
"@solana/kit": "^2.1.0",
|
|
26
26
|
"@solana/sysvars": "^2.1.0",
|
|
27
27
|
"@solana-program/compute-budget": "^0.7.0",
|
|
@@ -51,11 +51,11 @@
|
|
|
51
51
|
"rimraf": "^6.0.1",
|
|
52
52
|
"vitest": "^3.1.1",
|
|
53
53
|
"solana-bankrun": "^0.4.0",
|
|
54
|
-
"@crypticdot/defituna-program": "3.1.
|
|
54
|
+
"@crypticdot/defituna-program": "3.1.4"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"build": "node ./codama.mjs && tsup src/index.ts --format cjs,esm --dts",
|
|
58
|
-
"test": "vitest run tests --no-cache",
|
|
58
|
+
"test": "RUST_LOG=error vitest run tests --no-cache",
|
|
59
59
|
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
60
60
|
"eslint": "eslint \"src/**/*.ts\"",
|
|
61
61
|
"eslint:fix": "eslint \"src/**/*.ts\" --fix",
|