bet-test-sdk 1.1.1 → 1.1.2

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.
@@ -22043,6 +22043,79 @@ class BetSDK {
22043
22043
  : initRealReservedToken;
22044
22044
  return BigInt(bigAmount.toString().split(".")[0]);
22045
22045
  }
22046
+ // Buy: Fixed sol amount in, estimated token amount out
22047
+ async getTokenAmountOut(mint, solAmountIn, slippageBasisPoints) {
22048
+ const curveStateAccount = await this.getValidCurveState(mint);
22049
+ if (!curveStateAccount) {
22050
+ return 0n;
22051
+ }
22052
+ let shouldOutTokens = curveStateAccount.getBuyPrice(solAmountIn, false);
22053
+ if (slippageBasisPoints) {
22054
+ shouldOutTokens -= (shouldOutTokens * slippageBasisPoints) / 10000n;
22055
+ }
22056
+ return shouldOutTokens;
22057
+ }
22058
+ // Buy: Fixed token amount out, estimated sol amount in
22059
+ async getMinSolAmountIn(mint, tokenAmountOut, slippageBasisPoints) {
22060
+ const curveStateAccount = await this.getValidCurveState(mint);
22061
+ if (!curveStateAccount) {
22062
+ return 0n;
22063
+ }
22064
+ let shouldOutTokens = tokenAmountOut > curveStateAccount.virtualTokenReserves - curveStateAccount.realTokenReserves
22065
+ ? curveStateAccount.virtualTokenReserves - curveStateAccount.realTokenReserves
22066
+ : tokenAmountOut;
22067
+ let minSolAmountIn = (shouldOutTokens * curveStateAccount.virtualSolReserves) /
22068
+ (curveStateAccount.virtualTokenReserves - shouldOutTokens) +
22069
+ 1n;
22070
+ if (slippageBasisPoints) {
22071
+ minSolAmountIn += (minSolAmountIn * slippageBasisPoints) / 10000n;
22072
+ }
22073
+ let fee = (minSolAmountIn * FEE_BASIS_POINTS) / 10000n;
22074
+ return minSolAmountIn + fee;
22075
+ }
22076
+ // Sell: Fixed token amount in, estimated sol amount out
22077
+ async getSolAmountOut(mint, tokenAmountIn, slippageBasisPoints) {
22078
+ const curveStateAccount = await this.getValidCurveState(mint);
22079
+ if (!curveStateAccount) {
22080
+ return 0n;
22081
+ }
22082
+ let shouldOutTokens = curveStateAccount.getSellPrice(tokenAmountIn, FEE_BASIS_POINTS, false);
22083
+ if (slippageBasisPoints) {
22084
+ shouldOutTokens -= (shouldOutTokens * slippageBasisPoints) / 10000n;
22085
+ }
22086
+ return shouldOutTokens;
22087
+ }
22088
+ // Sell: Fixed sol amount out, estimated token amount in
22089
+ async getMinTokenAmountIn(mint, solAmountOut, slippageBasisPoints) {
22090
+ const curveStateAccount = await this.getValidCurveState(mint);
22091
+ if (!curveStateAccount) {
22092
+ return 0n;
22093
+ }
22094
+ let shouldOutSols = solAmountOut > curveStateAccount.virtualSolReserves - curveStateAccount.realSolReserves
22095
+ ? curveStateAccount.virtualSolReserves - curveStateAccount.realSolReserves
22096
+ : solAmountOut;
22097
+ let minTokenAmountIn = (shouldOutSols * curveStateAccount.virtualTokenReserves) /
22098
+ (curveStateAccount.virtualSolReserves - shouldOutSols) +
22099
+ 1n;
22100
+ if (slippageBasisPoints) {
22101
+ minTokenAmountIn += (minTokenAmountIn * slippageBasisPoints) / 10000n;
22102
+ }
22103
+ let fee = (minTokenAmountIn * FEE_BASIS_POINTS) / 10000n;
22104
+ return minTokenAmountIn + fee;
22105
+ }
22106
+ async getValidCurveState(mint) {
22107
+ const curveStateAccount = await this.getCurveStateAccount(mint);
22108
+ const betStateAccount = await this.getBetStateAccount(mint);
22109
+ if (!curveStateAccount || !betStateAccount) {
22110
+ console.error("Mint does not exist");
22111
+ return null;
22112
+ }
22113
+ if (betStateAccount.isCompted) {
22114
+ console.error("Compted");
22115
+ return null;
22116
+ }
22117
+ return curveStateAccount;
22118
+ }
22046
22119
  //EVENTS
22047
22120
  addEventListener(eventType, callback) {
22048
22121
  return this.program.addEventListener(eventType, (event, slot, signature) => {