@equilab/marginly-sdk
Advanced tools
Comparing version 1.0.19 to 1.0.20
/** @module MarginlyPoolExecute generates `execute` parameters for desired actions */ | ||
import { BigNumber } from 'ethers'; | ||
import { MarginlyPosition } from '.'; | ||
/** | ||
@@ -151,2 +152,3 @@ * Enum with all calls performed via Marginly `execute` method | ||
}; | ||
export declare function castParamsToBigInt({ methodName, args: [ct, bn1, bn2, bn3, b, s, bn4], value, }: ExecuteParams): ExecuteParamsBigInt; | ||
export declare function getActionArgs(props: ({ | ||
@@ -159,2 +161,3 @@ type: 'depositAndOpenPosition'; | ||
} & CommonParams)): ExecuteParamsBigInt | undefined; | ||
export declare function getWithdrawAllArgs(pos: MarginlyPosition | undefined, isBaseNative: boolean, isQuoteNative: boolean): ExecuteParamsBigInt | undefined; | ||
export {}; |
"use strict"; | ||
/** @module MarginlyPoolExecute generates `execute` parameters for desired actions */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getActionArgs = exports.getCalldata = exports.getEmergencyWithdrawArgs = exports.getReceivePositionArgs = exports.getReinitWithBalanceSyncArgs = exports.getReinitArgs = exports.getClosePositionArgs = exports.getDepositQuoteAndShortArgs = exports.getShortArgs = exports.getDepositBaseAndLongArgs = exports.getLongArgs = exports.getWithdrawQuoteAllArgs = exports.getWithdrawQuoteArgs = exports.getWithdrawBaseAllArgs = exports.getWithdrawBaseArgs = exports.getDepositQuoteArgs = exports.getDepositBaseArgs = exports.EXECUTE_ARGS_ABI_DEFINITION = exports.CallType = void 0; | ||
exports.getWithdrawAllArgs = exports.getActionArgs = exports.castParamsToBigInt = exports.getCalldata = exports.getEmergencyWithdrawArgs = exports.getReceivePositionArgs = exports.getReinitWithBalanceSyncArgs = exports.getReinitArgs = exports.getClosePositionArgs = exports.getDepositQuoteAndShortArgs = exports.getShortArgs = exports.getDepositBaseAndLongArgs = exports.getLongArgs = exports.getWithdrawQuoteAllArgs = exports.getWithdrawQuoteArgs = exports.getWithdrawBaseAllArgs = exports.getWithdrawBaseArgs = exports.getDepositQuoteArgs = exports.getDepositBaseArgs = exports.EXECUTE_ARGS_ABI_DEFINITION = exports.CallType = void 0; | ||
const ethers_1 = require("ethers"); | ||
@@ -9,2 +9,3 @@ const utils_1 = require("ethers/lib/utils"); | ||
const marginlyPoolMath_1 = require("./marginlyPoolMath"); | ||
const _1 = require("."); | ||
/** | ||
@@ -329,2 +330,10 @@ * Enum with all calls performed via Marginly `execute` method | ||
const getLeveragedAmount = (amount, direction, leverage, basePrice) => direction === 'long' ? +amount * (leverage - 1) : (+amount * (leverage - 1)) / basePrice; | ||
function castParamsToBigInt({ methodName, args: [ct, bn1, bn2, bn3, b, s, bn4], value, }) { | ||
return { | ||
methodName, | ||
args: [ct, bn1.toBigInt(), bn2.toBigInt(), bn3.toBigInt(), b, s, bn4.toBigInt()], | ||
value: value.toBigInt(), | ||
}; | ||
} | ||
exports.castParamsToBigInt = castParamsToBigInt; | ||
function getActionArgs(props) { | ||
@@ -350,11 +359,15 @@ const { type, direction, slippageTolerancePercentage, basePriceX96, baseDecimals, quoteDecimals, isDepositingNativeToken, swapCalldata, } = props; | ||
const limitPriceX96 = (0, marginlyPoolMath_1.convertPriceStringToX96)(limitPrice.toString(), ethers_1.BigNumber.from(baseDecimals), ethers_1.BigNumber.from(quoteDecimals)); | ||
const { methodName, args: [ct, bn1, bn2, bn3, b, s, bn4], value, } = type === 'depositAndOpenPosition' && amountBn && leveragedAmountBn | ||
const params = type === 'depositAndOpenPosition' && amountBn && leveragedAmountBn | ||
? openMethod(amountBn, leveragedAmountBn, limitPriceX96, ethers_1.BigNumber.from(swapCalldata), isDepositingNativeToken) | ||
: getClosePositionArgs(limitPriceX96, ethers_1.BigNumber.from(swapCalldata), isDepositingNativeToken); | ||
return { | ||
methodName, | ||
args: [ct, bn1.toBigInt(), bn2.toBigInt(), bn3.toBigInt(), b, s, bn4.toBigInt()], | ||
value: value.toBigInt(), | ||
}; | ||
return castParamsToBigInt(params); | ||
} | ||
exports.getActionArgs = getActionArgs; | ||
function getWithdrawAllArgs(pos, isBaseNative, isQuoteNative) { | ||
if (!pos || pos.type !== _1.PositionType.Lend) | ||
return undefined; | ||
const isWithdrawingBase = pos.baseAmount.gt(0); | ||
const params = isWithdrawingBase ? getWithdrawBaseAllArgs(isBaseNative) : getWithdrawQuoteAllArgs(isQuoteNative); | ||
return castParamsToBigInt(params); | ||
} | ||
exports.getWithdrawAllArgs = getWithdrawAllArgs; |
{ | ||
"name": "@equilab/marginly-sdk", | ||
"version": "1.0.19", | ||
"version": "1.0.20", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
320007
4967