@strkfarm/sdk 2.0.0-dev.24 → 2.0.0-dev.25
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.browser.global.js +19 -15
- package/dist/index.browser.mjs +19 -15
- package/dist/index.js +19 -15
- package/dist/index.mjs +19 -15
- package/package.json +1 -1
- package/src/strategies/vesu-extended-strategy/utils/helper.ts +12 -13
- package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +22 -8
|
@@ -92648,21 +92648,17 @@ spurious results.`);
|
|
|
92648
92648
|
};
|
|
92649
92649
|
var calculatePositionToCloseToWithdrawAmount = async (extendedBalance, extendedPositions, amountToWithdraw) => {
|
|
92650
92650
|
try {
|
|
92651
|
+
const extendedLeverage = calculateExtendedLevergae();
|
|
92651
92652
|
const extendedPosition = extendedPositions.value;
|
|
92652
|
-
const
|
|
92653
|
-
|
|
92654
|
-
|
|
92655
|
-
);
|
|
92656
|
-
const availableForWithdrawal = new Web3Number(
|
|
92657
|
-
extendedBalance.availableForWithdrawal,
|
|
92658
|
-
USDC_TOKEN_DECIMALS
|
|
92659
|
-
);
|
|
92660
|
-
const netAmount = amountToWithdraw.minus(availableForWithdrawal);
|
|
92653
|
+
const marginRequired = new Web3Number(extendedBalance.initialMargin, USDC_TOKEN_DECIMALS);
|
|
92654
|
+
const unrealisedPnl = new Web3Number(extendedBalance.unrealisedPnl, USDC_TOKEN_DECIMALS);
|
|
92655
|
+
const availableForWithdrawal = new Web3Number(extendedBalance.availableForWithdrawal, USDC_TOKEN_DECIMALS);
|
|
92661
92656
|
const upnlPercent = unrealisedPnl.dividedBy(extendedPosition);
|
|
92662
92657
|
console.log(`upnlPercent: ${upnlPercent}`);
|
|
92663
|
-
const
|
|
92664
|
-
const
|
|
92665
|
-
|
|
92658
|
+
const walletBalance = new Web3Number(extendedBalance.balance, USDC_TOKEN_DECIMALS);
|
|
92659
|
+
const term1 = marginRequired.minus(walletBalance).minus(availableForWithdrawal).plus(amountToWithdraw).multipliedBy(extendedLeverage);
|
|
92660
|
+
const denominator = upnlPercent.multipliedBy(extendedLeverage).plus(1);
|
|
92661
|
+
return new Web3Number(Math.ceil(term1.dividedBy(denominator).dividedBy(extendedLeverage).toNumber()), USDC_TOKEN_DECIMALS);
|
|
92666
92662
|
} catch (err2) {
|
|
92667
92663
|
logger2.error(
|
|
92668
92664
|
`error calculating position to close to withdraw amount: ${err2}`
|
|
@@ -99260,7 +99256,9 @@ spurious results.`);
|
|
|
99260
99256
|
);
|
|
99261
99257
|
const extendedPositions = await extendedAdapter.getAllOpenPositions();
|
|
99262
99258
|
if (!extendedPositions) {
|
|
99263
|
-
logger2.error(
|
|
99259
|
+
logger2.error(
|
|
99260
|
+
`error getting extended positions: ${extendedPositions} while moving assets from extended to vault`
|
|
99261
|
+
);
|
|
99264
99262
|
return this.createTransactionResult(
|
|
99265
99263
|
[],
|
|
99266
99264
|
false,
|
|
@@ -99276,8 +99274,14 @@ spurious results.`);
|
|
|
99276
99274
|
),
|
|
99277
99275
|
USDC_TOKEN_DECIMALS
|
|
99278
99276
|
);
|
|
99279
|
-
const positionAmountToClose = await calculatePositionToCloseToWithdrawAmount(
|
|
99280
|
-
|
|
99277
|
+
const positionAmountToClose = await calculatePositionToCloseToWithdrawAmount(
|
|
99278
|
+
extendedHoldings,
|
|
99279
|
+
extendedPositions[0],
|
|
99280
|
+
params.amount
|
|
99281
|
+
);
|
|
99282
|
+
logger2.info(
|
|
99283
|
+
`positionAmountToClose: ${positionAmountToClose} this is without leverage`
|
|
99284
|
+
);
|
|
99281
99285
|
logger2.info(
|
|
99282
99286
|
`${_VesuExtendedMultiplierStrategy.name}::moveAssets leftAmountAfterWithdrawalAmountInAccount: ${leftAmountAfterWithdrawalAmountInAccount.toNumber()}`
|
|
99283
99287
|
);
|
package/dist/index.browser.mjs
CHANGED
|
@@ -28603,21 +28603,17 @@ var calculateDeltaDebtAmount = (maxLtv = MAX_LTV_BTC_USDC, existingVesuCollatera
|
|
|
28603
28603
|
};
|
|
28604
28604
|
var calculatePositionToCloseToWithdrawAmount = async (extendedBalance, extendedPositions, amountToWithdraw) => {
|
|
28605
28605
|
try {
|
|
28606
|
+
const extendedLeverage = calculateExtendedLevergae();
|
|
28606
28607
|
const extendedPosition = extendedPositions.value;
|
|
28607
|
-
const
|
|
28608
|
-
|
|
28609
|
-
|
|
28610
|
-
);
|
|
28611
|
-
const availableForWithdrawal = new Web3Number(
|
|
28612
|
-
extendedBalance.availableForWithdrawal,
|
|
28613
|
-
USDC_TOKEN_DECIMALS
|
|
28614
|
-
);
|
|
28615
|
-
const netAmount = amountToWithdraw.minus(availableForWithdrawal);
|
|
28608
|
+
const marginRequired = new Web3Number(extendedBalance.initialMargin, USDC_TOKEN_DECIMALS);
|
|
28609
|
+
const unrealisedPnl = new Web3Number(extendedBalance.unrealisedPnl, USDC_TOKEN_DECIMALS);
|
|
28610
|
+
const availableForWithdrawal = new Web3Number(extendedBalance.availableForWithdrawal, USDC_TOKEN_DECIMALS);
|
|
28616
28611
|
const upnlPercent = unrealisedPnl.dividedBy(extendedPosition);
|
|
28617
28612
|
console.log(`upnlPercent: ${upnlPercent}`);
|
|
28618
|
-
const
|
|
28619
|
-
const
|
|
28620
|
-
|
|
28613
|
+
const walletBalance = new Web3Number(extendedBalance.balance, USDC_TOKEN_DECIMALS);
|
|
28614
|
+
const term1 = marginRequired.minus(walletBalance).minus(availableForWithdrawal).plus(amountToWithdraw).multipliedBy(extendedLeverage);
|
|
28615
|
+
const denominator = upnlPercent.multipliedBy(extendedLeverage).plus(1);
|
|
28616
|
+
return new Web3Number(Math.ceil(term1.dividedBy(denominator).dividedBy(extendedLeverage).toNumber()), USDC_TOKEN_DECIMALS);
|
|
28621
28617
|
} catch (err) {
|
|
28622
28618
|
logger.error(
|
|
28623
28619
|
`error calculating position to close to withdraw amount: ${err}`
|
|
@@ -35222,7 +35218,9 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
35222
35218
|
);
|
|
35223
35219
|
const extendedPositions = await extendedAdapter.getAllOpenPositions();
|
|
35224
35220
|
if (!extendedPositions) {
|
|
35225
|
-
logger.error(
|
|
35221
|
+
logger.error(
|
|
35222
|
+
`error getting extended positions: ${extendedPositions} while moving assets from extended to vault`
|
|
35223
|
+
);
|
|
35226
35224
|
return this.createTransactionResult(
|
|
35227
35225
|
[],
|
|
35228
35226
|
false,
|
|
@@ -35238,8 +35236,14 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
35238
35236
|
),
|
|
35239
35237
|
USDC_TOKEN_DECIMALS
|
|
35240
35238
|
);
|
|
35241
|
-
const positionAmountToClose = await calculatePositionToCloseToWithdrawAmount(
|
|
35242
|
-
|
|
35239
|
+
const positionAmountToClose = await calculatePositionToCloseToWithdrawAmount(
|
|
35240
|
+
extendedHoldings,
|
|
35241
|
+
extendedPositions[0],
|
|
35242
|
+
params.amount
|
|
35243
|
+
);
|
|
35244
|
+
logger.info(
|
|
35245
|
+
`positionAmountToClose: ${positionAmountToClose} this is without leverage`
|
|
35246
|
+
);
|
|
35243
35247
|
logger.info(
|
|
35244
35248
|
`${_VesuExtendedMultiplierStrategy.name}::moveAssets leftAmountAfterWithdrawalAmountInAccount: ${leftAmountAfterWithdrawalAmountInAccount.toNumber()}`
|
|
35245
35249
|
);
|
package/dist/index.js
CHANGED
|
@@ -28407,21 +28407,17 @@ var calculateDeltaDebtAmount = (maxLtv = MAX_LTV_BTC_USDC, existingVesuCollatera
|
|
|
28407
28407
|
};
|
|
28408
28408
|
var calculatePositionToCloseToWithdrawAmount = async (extendedBalance, extendedPositions, amountToWithdraw) => {
|
|
28409
28409
|
try {
|
|
28410
|
+
const extendedLeverage = calculateExtendedLevergae();
|
|
28410
28411
|
const extendedPosition = extendedPositions.value;
|
|
28411
|
-
const
|
|
28412
|
-
|
|
28413
|
-
|
|
28414
|
-
);
|
|
28415
|
-
const availableForWithdrawal = new Web3Number(
|
|
28416
|
-
extendedBalance.availableForWithdrawal,
|
|
28417
|
-
USDC_TOKEN_DECIMALS
|
|
28418
|
-
);
|
|
28419
|
-
const netAmount = amountToWithdraw.minus(availableForWithdrawal);
|
|
28412
|
+
const marginRequired = new Web3Number(extendedBalance.initialMargin, USDC_TOKEN_DECIMALS);
|
|
28413
|
+
const unrealisedPnl = new Web3Number(extendedBalance.unrealisedPnl, USDC_TOKEN_DECIMALS);
|
|
28414
|
+
const availableForWithdrawal = new Web3Number(extendedBalance.availableForWithdrawal, USDC_TOKEN_DECIMALS);
|
|
28420
28415
|
const upnlPercent = unrealisedPnl.dividedBy(extendedPosition);
|
|
28421
28416
|
console.log(`upnlPercent: ${upnlPercent}`);
|
|
28422
|
-
const
|
|
28423
|
-
const
|
|
28424
|
-
|
|
28417
|
+
const walletBalance = new Web3Number(extendedBalance.balance, USDC_TOKEN_DECIMALS);
|
|
28418
|
+
const term1 = marginRequired.minus(walletBalance).minus(availableForWithdrawal).plus(amountToWithdraw).multipliedBy(extendedLeverage);
|
|
28419
|
+
const denominator = upnlPercent.multipliedBy(extendedLeverage).plus(1);
|
|
28420
|
+
return new Web3Number(Math.ceil(term1.dividedBy(denominator).dividedBy(extendedLeverage).toNumber()), USDC_TOKEN_DECIMALS);
|
|
28425
28421
|
} catch (err) {
|
|
28426
28422
|
logger.error(
|
|
28427
28423
|
`error calculating position to close to withdraw amount: ${err}`
|
|
@@ -35381,7 +35377,9 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
35381
35377
|
);
|
|
35382
35378
|
const extendedPositions = await extendedAdapter.getAllOpenPositions();
|
|
35383
35379
|
if (!extendedPositions) {
|
|
35384
|
-
logger.error(
|
|
35380
|
+
logger.error(
|
|
35381
|
+
`error getting extended positions: ${extendedPositions} while moving assets from extended to vault`
|
|
35382
|
+
);
|
|
35385
35383
|
return this.createTransactionResult(
|
|
35386
35384
|
[],
|
|
35387
35385
|
false,
|
|
@@ -35397,8 +35395,14 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
35397
35395
|
),
|
|
35398
35396
|
USDC_TOKEN_DECIMALS
|
|
35399
35397
|
);
|
|
35400
|
-
const positionAmountToClose = await calculatePositionToCloseToWithdrawAmount(
|
|
35401
|
-
|
|
35398
|
+
const positionAmountToClose = await calculatePositionToCloseToWithdrawAmount(
|
|
35399
|
+
extendedHoldings,
|
|
35400
|
+
extendedPositions[0],
|
|
35401
|
+
params.amount
|
|
35402
|
+
);
|
|
35403
|
+
logger.info(
|
|
35404
|
+
`positionAmountToClose: ${positionAmountToClose} this is without leverage`
|
|
35405
|
+
);
|
|
35402
35406
|
logger.info(
|
|
35403
35407
|
`${_VesuExtendedMultiplierStrategy.name}::moveAssets leftAmountAfterWithdrawalAmountInAccount: ${leftAmountAfterWithdrawalAmountInAccount.toNumber()}`
|
|
35404
35408
|
);
|
package/dist/index.mjs
CHANGED
|
@@ -28259,21 +28259,17 @@ var calculateDeltaDebtAmount = (maxLtv = MAX_LTV_BTC_USDC, existingVesuCollatera
|
|
|
28259
28259
|
};
|
|
28260
28260
|
var calculatePositionToCloseToWithdrawAmount = async (extendedBalance, extendedPositions, amountToWithdraw) => {
|
|
28261
28261
|
try {
|
|
28262
|
+
const extendedLeverage = calculateExtendedLevergae();
|
|
28262
28263
|
const extendedPosition = extendedPositions.value;
|
|
28263
|
-
const
|
|
28264
|
-
|
|
28265
|
-
|
|
28266
|
-
);
|
|
28267
|
-
const availableForWithdrawal = new Web3Number(
|
|
28268
|
-
extendedBalance.availableForWithdrawal,
|
|
28269
|
-
USDC_TOKEN_DECIMALS
|
|
28270
|
-
);
|
|
28271
|
-
const netAmount = amountToWithdraw.minus(availableForWithdrawal);
|
|
28264
|
+
const marginRequired = new Web3Number(extendedBalance.initialMargin, USDC_TOKEN_DECIMALS);
|
|
28265
|
+
const unrealisedPnl = new Web3Number(extendedBalance.unrealisedPnl, USDC_TOKEN_DECIMALS);
|
|
28266
|
+
const availableForWithdrawal = new Web3Number(extendedBalance.availableForWithdrawal, USDC_TOKEN_DECIMALS);
|
|
28272
28267
|
const upnlPercent = unrealisedPnl.dividedBy(extendedPosition);
|
|
28273
28268
|
console.log(`upnlPercent: ${upnlPercent}`);
|
|
28274
|
-
const
|
|
28275
|
-
const
|
|
28276
|
-
|
|
28269
|
+
const walletBalance = new Web3Number(extendedBalance.balance, USDC_TOKEN_DECIMALS);
|
|
28270
|
+
const term1 = marginRequired.minus(walletBalance).minus(availableForWithdrawal).plus(amountToWithdraw).multipliedBy(extendedLeverage);
|
|
28271
|
+
const denominator = upnlPercent.multipliedBy(extendedLeverage).plus(1);
|
|
28272
|
+
return new Web3Number(Math.ceil(term1.dividedBy(denominator).dividedBy(extendedLeverage).toNumber()), USDC_TOKEN_DECIMALS);
|
|
28277
28273
|
} catch (err) {
|
|
28278
28274
|
logger.error(
|
|
28279
28275
|
`error calculating position to close to withdraw amount: ${err}`
|
|
@@ -35233,7 +35229,9 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
35233
35229
|
);
|
|
35234
35230
|
const extendedPositions = await extendedAdapter.getAllOpenPositions();
|
|
35235
35231
|
if (!extendedPositions) {
|
|
35236
|
-
logger.error(
|
|
35232
|
+
logger.error(
|
|
35233
|
+
`error getting extended positions: ${extendedPositions} while moving assets from extended to vault`
|
|
35234
|
+
);
|
|
35237
35235
|
return this.createTransactionResult(
|
|
35238
35236
|
[],
|
|
35239
35237
|
false,
|
|
@@ -35249,8 +35247,14 @@ var VesuExtendedMultiplierStrategy = class _VesuExtendedMultiplierStrategy exten
|
|
|
35249
35247
|
),
|
|
35250
35248
|
USDC_TOKEN_DECIMALS
|
|
35251
35249
|
);
|
|
35252
|
-
const positionAmountToClose = await calculatePositionToCloseToWithdrawAmount(
|
|
35253
|
-
|
|
35250
|
+
const positionAmountToClose = await calculatePositionToCloseToWithdrawAmount(
|
|
35251
|
+
extendedHoldings,
|
|
35252
|
+
extendedPositions[0],
|
|
35253
|
+
params.amount
|
|
35254
|
+
);
|
|
35255
|
+
logger.info(
|
|
35256
|
+
`positionAmountToClose: ${positionAmountToClose} this is without leverage`
|
|
35257
|
+
);
|
|
35254
35258
|
logger.info(
|
|
35255
35259
|
`${_VesuExtendedMultiplierStrategy.name}::moveAssets leftAmountAfterWithdrawalAmountInAccount: ${leftAmountAfterWithdrawalAmountInAccount.toNumber()}`
|
|
35256
35260
|
);
|
package/package.json
CHANGED
|
@@ -471,21 +471,20 @@ export const calculatePositionToCloseToWithdrawAmount = async (
|
|
|
471
471
|
amountToWithdraw: Web3Number
|
|
472
472
|
) => {
|
|
473
473
|
try {
|
|
474
|
+
const extendedLeverage = calculateExtendedLevergae();
|
|
474
475
|
const extendedPosition = extendedPositions.value;
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
)
|
|
479
|
-
const availableForWithdrawal = new Web3Number(
|
|
480
|
-
extendedBalance.availableForWithdrawal,
|
|
481
|
-
USDC_TOKEN_DECIMALS
|
|
482
|
-
);
|
|
483
|
-
const netAmount = amountToWithdraw.minus(availableForWithdrawal);
|
|
484
|
-
const upnlPercent = unrealisedPnl.dividedBy(extendedPosition);
|
|
476
|
+
const marginRequired = new Web3Number(extendedBalance.initialMargin , USDC_TOKEN_DECIMALS);
|
|
477
|
+
const unrealisedPnl = new Web3Number(extendedBalance.unrealisedPnl, USDC_TOKEN_DECIMALS);
|
|
478
|
+
const availableForWithdrawal = new Web3Number(extendedBalance.availableForWithdrawal, USDC_TOKEN_DECIMALS);
|
|
479
|
+
const upnlPercent = unrealisedPnl.dividedBy(extendedPosition)
|
|
485
480
|
console.log(`upnlPercent: ${upnlPercent}`);
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
481
|
+
/**
|
|
482
|
+
* New Formula
|
|
483
|
+
*/
|
|
484
|
+
const walletBalance = new Web3Number(extendedBalance.balance, USDC_TOKEN_DECIMALS);
|
|
485
|
+
const term1 = marginRequired.minus(walletBalance).minus(availableForWithdrawal).plus(amountToWithdraw).multipliedBy(extendedLeverage);
|
|
486
|
+
const denominator = upnlPercent.multipliedBy(extendedLeverage).plus(1);
|
|
487
|
+
return new Web3Number(Math.ceil(term1.dividedBy(denominator).dividedBy(extendedLeverage).toNumber()), USDC_TOKEN_DECIMALS);
|
|
489
488
|
} catch (err) {
|
|
490
489
|
logger.error(
|
|
491
490
|
`error calculating position to close to withdraw amount: ${err}`
|
|
@@ -8,7 +8,12 @@ import {
|
|
|
8
8
|
UNIVERSAL_MANAGE_IDS,
|
|
9
9
|
UniversalStrategySettings,
|
|
10
10
|
} from "../universal-strategy";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
calculateDebtAmount,
|
|
13
|
+
calculateDeltaDebtAmount,
|
|
14
|
+
calculateExtendedLevergae,
|
|
15
|
+
calculatePositionToCloseToWithdrawAmount,
|
|
16
|
+
} from "./utils/helper";
|
|
12
17
|
import { logger } from "@/utils";
|
|
13
18
|
import { AUDIT_URL } from "../universal-lst-muliplier-strategy";
|
|
14
19
|
import { getNoRiskTags } from "@/interfaces";
|
|
@@ -410,7 +415,7 @@ export class VesuExtendedMultiplierStrategy<
|
|
|
410
415
|
logger.info(
|
|
411
416
|
`${VesuExtendedMultiplierStrategy.name}::shouldInvest amountToInvest: ${amountToInvestNumber}`
|
|
412
417
|
);
|
|
413
|
-
|
|
418
|
+
|
|
414
419
|
if (amountToInvest.lessThan(LIMIT_BALANCE_VALUE)) {
|
|
415
420
|
return {
|
|
416
421
|
shouldInvest: false,
|
|
@@ -498,7 +503,8 @@ export class VesuExtendedMultiplierStrategy<
|
|
|
498
503
|
debtAmountToBeRepaid: new Web3Number(0, 0),
|
|
499
504
|
};
|
|
500
505
|
}
|
|
501
|
-
const amountToInvestAfterRepayingDebt =
|
|
506
|
+
const amountToInvestAfterRepayingDebt =
|
|
507
|
+
amountToInvest.minus(debtAmountToBeRepaid);
|
|
502
508
|
const { vesu_amount, extended_amount, extended_leverage, vesu_leverage } =
|
|
503
509
|
await calculateAmountDistribution(
|
|
504
510
|
amountToInvestAfterRepayingDebt.toNumber(),
|
|
@@ -1144,7 +1150,9 @@ export class VesuExtendedMultiplierStrategy<
|
|
|
1144
1150
|
);
|
|
1145
1151
|
const extendedPositions = await extendedAdapter.getAllOpenPositions();
|
|
1146
1152
|
if (!extendedPositions) {
|
|
1147
|
-
logger.error(
|
|
1153
|
+
logger.error(
|
|
1154
|
+
`error getting extended positions: ${extendedPositions} while moving assets from extended to vault`
|
|
1155
|
+
);
|
|
1148
1156
|
return this.createTransactionResult(
|
|
1149
1157
|
[],
|
|
1150
1158
|
false,
|
|
@@ -1160,8 +1168,15 @@ export class VesuExtendedMultiplierStrategy<
|
|
|
1160
1168
|
),
|
|
1161
1169
|
USDC_TOKEN_DECIMALS
|
|
1162
1170
|
);
|
|
1163
|
-
const positionAmountToClose =
|
|
1164
|
-
|
|
1171
|
+
const positionAmountToClose =
|
|
1172
|
+
await calculatePositionToCloseToWithdrawAmount(
|
|
1173
|
+
extendedHoldings,
|
|
1174
|
+
extendedPositions[0],
|
|
1175
|
+
params.amount
|
|
1176
|
+
);
|
|
1177
|
+
logger.info(
|
|
1178
|
+
`positionAmountToClose: ${positionAmountToClose} this is without leverage`
|
|
1179
|
+
);
|
|
1165
1180
|
logger.info(
|
|
1166
1181
|
`${
|
|
1167
1182
|
VesuExtendedMultiplierStrategy.name
|
|
@@ -1177,8 +1192,7 @@ export class VesuExtendedMultiplierStrategy<
|
|
|
1177
1192
|
logger.error(`error fetching order book btc usdc: ${status}`);
|
|
1178
1193
|
priceOfBTC = collateralPrice.price;
|
|
1179
1194
|
}
|
|
1180
|
-
const btcAmount =
|
|
1181
|
-
positionAmountToClose.dividedBy(priceOfBTC);
|
|
1195
|
+
const btcAmount = positionAmountToClose.dividedBy(priceOfBTC);
|
|
1182
1196
|
/**
|
|
1183
1197
|
* If amount for withdrawal is greater than the amount in extended available for withdrawal,
|
|
1184
1198
|
* then we need to open a long position depending on the difference between the two
|