bet-test-sdk 1.0.8 → 1.0.9
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/browser/index.js +12 -15
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/types/curveState.d.ts.map +1 -1
- package/dist/browser/types/util.d.ts +1 -2
- package/dist/browser/types/util.d.ts.map +1 -1
- package/dist/cjs/bet.js +7 -7
- package/dist/cjs/bet.js.map +1 -1
- package/dist/cjs/curveState.d.ts.map +1 -1
- package/dist/cjs/curveState.js +1 -3
- package/dist/cjs/curveState.js.map +1 -1
- package/dist/cjs/util.d.ts +1 -2
- package/dist/cjs/util.d.ts.map +1 -1
- package/dist/cjs/util.js +5 -7
- package/dist/cjs/util.js.map +1 -1
- package/dist/esm/bet.js +8 -8
- package/dist/esm/bet.js.map +1 -1
- package/dist/esm/curveState.d.ts.map +1 -1
- package/dist/esm/curveState.js +1 -3
- package/dist/esm/curveState.js.map +1 -1
- package/dist/esm/util.d.ts +1 -2
- package/dist/esm/util.d.ts.map +1 -1
- package/dist/esm/util.js +3 -4
- package/dist/esm/util.js.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.js
CHANGED
@@ -15885,10 +15885,9 @@ new PublicKey("11111111111111111111111111111111");
|
|
15885
15885
|
|
15886
15886
|
const DEFAULT_COMMITMENT = "finalized";
|
15887
15887
|
const DEFAULT_FINALITY = "finalized";
|
15888
|
-
|
15889
|
-
|
15890
|
-
|
15891
|
-
const calculateWithSlippageSell = (amount, basisPoints) => {
|
15888
|
+
// token amount => token amount
|
15889
|
+
// sol amount => sol amount
|
15890
|
+
const calculateWithSlippage = (amount, basisPoints) => {
|
15892
15891
|
return amount - (amount * basisPoints) / 10000n;
|
15893
15892
|
};
|
15894
15893
|
async function sendTx(connection, tx, payer, signers, priorityFees, commitment = DEFAULT_COMMITMENT, finality = DEFAULT_FINALITY) {
|
@@ -16043,7 +16042,7 @@ class CurveState {
|
|
16043
16042
|
// Calculate the amount of tokens to be purchased
|
16044
16043
|
let s = this.virtualTokenReserves - r;
|
16045
16044
|
// Return the minimum of the calculated tokens and real token reserves
|
16046
|
-
return s < this.
|
16045
|
+
return s < this.realTokenReserves ? s : this.realTokenReserves;
|
16047
16046
|
}
|
16048
16047
|
getSellPrice(amount, feeBasisPoints, isCompted) {
|
16049
16048
|
if (isCompted) {
|
@@ -16054,10 +16053,8 @@ class CurveState {
|
|
16054
16053
|
}
|
16055
16054
|
// Calculate the proportional amount of virtual sol reserves to be received
|
16056
16055
|
let n = (amount * this.virtualSolReserves) / (this.virtualTokenReserves + amount);
|
16057
|
-
console.log("n::::::::::::::", n);
|
16058
16056
|
// Calculate the fee amount in the same units
|
16059
16057
|
let a = (n * feeBasisPoints) / 10000n;
|
16060
|
-
console.log("a::::::::::::::", a);
|
16061
16058
|
// Return the net amount after deducting the fee
|
16062
16059
|
return n - a;
|
16063
16060
|
}
|
@@ -21825,7 +21822,7 @@ class BetSDK {
|
|
21825
21822
|
}
|
21826
21823
|
if (buyAmountSol > 0) {
|
21827
21824
|
const buyTokenAmount = this.getInitialBuyPrice(buyAmountSol); // token amount
|
21828
|
-
const buyTokenAmountWithSlippage =
|
21825
|
+
const buyTokenAmountWithSlippage = calculateWithSlippage(// token amount with slippage
|
21829
21826
|
buyTokenAmount, slippageBasisPoints);
|
21830
21827
|
const buyTx = await this.getBuyInstructions(creator, mintKeyPair.publicKey, buyAmountSol, buyTokenAmountWithSlippage);
|
21831
21828
|
newTx.add(buyTx);
|
@@ -21860,9 +21857,9 @@ class BetSDK {
|
|
21860
21857
|
if (!curveState) {
|
21861
21858
|
throw new Error(`Curve state account not found: ${mint.toBase58()}`);
|
21862
21859
|
}
|
21863
|
-
let
|
21864
|
-
let buyAmountWithSlippage =
|
21865
|
-
return await this.getBuyInstructions(buyer, mint,
|
21860
|
+
let buyTokenAmount = curveState.getBuyPrice(buyAmountSol, betState.isCompted);
|
21861
|
+
let buyAmountWithSlippage = calculateWithSlippage(buyTokenAmount, slippageBasisPoints);
|
21862
|
+
return await this.getBuyInstructions(buyer, mint, buyAmountSol, buyAmountWithSlippage);
|
21866
21863
|
}
|
21867
21864
|
//buy
|
21868
21865
|
async getBuyInstructions(buyer, mint, solAmount, minTokenAmount, commitment = DEFAULT_COMMITMENT) {
|
@@ -21897,7 +21894,7 @@ class BetSDK {
|
|
21897
21894
|
}
|
21898
21895
|
const isComplete = betState.isCompted;
|
21899
21896
|
let minSolOutput = curveState.getSellPrice(sellTokenAmount, FEE_BASIS_POINTS, isComplete);
|
21900
|
-
let minSolOutputWithSlippage =
|
21897
|
+
let minSolOutputWithSlippage = calculateWithSlippage(minSolOutput, slippageBasisPoints);
|
21901
21898
|
return await this.getSellInstructions(seller, mint, sellTokenAmount, minSolOutputWithSlippage);
|
21902
21899
|
}
|
21903
21900
|
async getSellInstructions(seller, mint, sellTokenAmount, minAmountSol) {
|
@@ -22052,9 +22049,9 @@ class BetSDK {
|
|
22052
22049
|
const initRealReservedToken = new BigNumber(DEFAULT_CURVE_INITIALIZE_INIT_RESERVED_TOKEN);
|
22053
22050
|
const buyAmount = amount.toString();
|
22054
22051
|
let n = initVirtualSol.multipliedBy(initVirtualToken); // K
|
22055
|
-
let i = initVirtualSol.plus(buyAmount);
|
22052
|
+
let i = initVirtualSol.plus(buyAmount);
|
22056
22053
|
let r = n.dividedBy(i).plus(1);
|
22057
|
-
let s = initVirtualToken.minus(r);
|
22054
|
+
let s = initVirtualToken.minus(r);
|
22058
22055
|
const compared = s.comparedTo(initRealReservedToken);
|
22059
22056
|
const bigAmount = compared <= 0
|
22060
22057
|
? s
|
@@ -22150,5 +22147,5 @@ class AMM {
|
|
22150
22147
|
}
|
22151
22148
|
}
|
22152
22149
|
|
22153
|
-
export { AMM, APP_CONFIG_SEED, BET_API, BET_STATE_SEED, BetSDK, BetState, CURVE_STATE_SEED, CurveState, DEFAULT_COMMITMENT, DEFAULT_CURVE_INITIALIZE_INIT_RESERVED_TOKEN, DEFAULT_CURVE_INITIALIZE_SUPPLY, DEFAULT_CURVE_INITIALIZE_TOKEN_DEMICAL, DEFAULT_CURVE_INITIALIZE_VITUAL_RESERVED_TOKEN, DEFAULT_CURVE_INITIALIZE_VITUAL_SOL_TOKEN, DEFAULT_DECIMALS, DEFAULT_FINALITY, FEE_BASIS_POINTS, FEE_RECIVED_ACCOUNT_SEED, FEE_STORE_SEED, MigrateDex, MigrateType, POOL_SEED, PROGRAM_ID, REACH_CURVE_SOL_AMOUNT, TOKEN_ACCOUNT_DATA, TOKEN_MINT_AUTHORITY_SEED, buildVersionedTx,
|
22150
|
+
export { AMM, APP_CONFIG_SEED, BET_API, BET_STATE_SEED, BetSDK, BetState, CURVE_STATE_SEED, CurveState, DEFAULT_COMMITMENT, DEFAULT_CURVE_INITIALIZE_INIT_RESERVED_TOKEN, DEFAULT_CURVE_INITIALIZE_SUPPLY, DEFAULT_CURVE_INITIALIZE_TOKEN_DEMICAL, DEFAULT_CURVE_INITIALIZE_VITUAL_RESERVED_TOKEN, DEFAULT_CURVE_INITIALIZE_VITUAL_SOL_TOKEN, DEFAULT_DECIMALS, DEFAULT_FINALITY, FEE_BASIS_POINTS, FEE_RECIVED_ACCOUNT_SEED, FEE_STORE_SEED, MigrateDex, MigrateType, POOL_SEED, PROGRAM_ID, REACH_CURVE_SOL_AMOUNT, TOKEN_ACCOUNT_DATA, TOKEN_MINT_AUTHORITY_SEED, buildVersionedTx, calculateWithSlippage, getTxDetails, sendTx, toCompleteEvent, toCreateEvent, toTradeEvent };
|
22154
22151
|
//# sourceMappingURL=index.js.map
|