bet-test-sdk 1.1.6 → 1.1.7
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/README.md +4 -3
- package/dist/browser/index.js +34 -22
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/types/bet.d.ts.map +1 -1
- package/dist/browser/types/constants.d.ts +1 -0
- package/dist/browser/types/constants.d.ts.map +1 -1
- package/dist/browser/types/curveState.d.ts +2 -2
- package/dist/browser/types/curveState.d.ts.map +1 -1
- package/dist/browser/types/util.d.ts.map +1 -1
- package/dist/cjs/bet.d.ts.map +1 -1
- package/dist/cjs/bet.js +21 -11
- package/dist/cjs/bet.js.map +1 -1
- package/dist/cjs/constants.d.ts +1 -0
- package/dist/cjs/constants.d.ts.map +1 -1
- package/dist/cjs/constants.js +2 -1
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/curveState.d.ts +2 -2
- package/dist/cjs/curveState.d.ts.map +1 -1
- package/dist/cjs/curveState.js +11 -9
- package/dist/cjs/curveState.js.map +1 -1
- package/dist/cjs/util.d.ts.map +1 -1
- package/dist/cjs/util.js +2 -1
- package/dist/cjs/util.js.map +1 -1
- package/dist/esm/bet.d.ts.map +1 -1
- package/dist/esm/bet.js +22 -12
- package/dist/esm/bet.js.map +1 -1
- package/dist/esm/constants.d.ts +1 -0
- package/dist/esm/constants.d.ts.map +1 -1
- package/dist/esm/constants.js +1 -0
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/curveState.d.ts +2 -2
- package/dist/esm/curveState.d.ts.map +1 -1
- package/dist/esm/curveState.js +11 -9
- package/dist/esm/curveState.js.map +1 -1
- package/dist/esm/util.d.ts.map +1 -1
- package/dist/esm/util.js +2 -1
- package/dist/esm/util.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
@@ -61,6 +61,7 @@ const createAndBuyToken = async (sdk, testAccount) => {
|
|
61
61
|
file: await fs.openAsBlob("example/basic/test.jpg"),
|
62
62
|
migrateDex: MigrateDex.Meteora,
|
63
63
|
twitter: "https://example.x.com",
|
64
|
+
createdOn: "https://test.bet.com",
|
64
65
|
telegram: "https://example.t.me",
|
65
66
|
discord: "https://example.discord.com",
|
66
67
|
website: "https://www.example.com",
|
@@ -72,7 +73,7 @@ const createAndBuyToken = async (sdk, testAccount) => {
|
|
72
73
|
BigInt(0.0001 * LAMPORTS_PER_SOL),
|
73
74
|
SLIPPAGE_BASIS_POINTS,
|
74
75
|
{
|
75
|
-
unitLimit:
|
76
|
+
unitLimit: 500000,
|
76
77
|
unitPrice: 250000,
|
77
78
|
}
|
78
79
|
);
|
@@ -99,7 +100,7 @@ const buyTokens = async (sdk, testAccount, mint) => {
|
|
99
100
|
BigInt(0.001 * LAMPORTS_PER_SOL),
|
100
101
|
SLIPPAGE_BASIS_POINTS,
|
101
102
|
{
|
102
|
-
unitLimit:
|
103
|
+
unitLimit: 500000,
|
103
104
|
unitPrice: 250000,
|
104
105
|
},
|
105
106
|
);
|
@@ -127,7 +128,7 @@ const sellTokens = async (sdk, testAccount, mint) => {
|
|
127
128
|
BigInt(currentSPLBalance * Math.pow(10, DEFAULT_DECIMALS)),
|
128
129
|
SLIPPAGE_BASIS_POINTS,
|
129
130
|
{
|
130
|
-
unitLimit:
|
131
|
+
unitLimit: 500000,
|
131
132
|
unitPrice: 250000,
|
132
133
|
}
|
133
134
|
);
|
package/dist/browser/index.js
CHANGED
@@ -20,6 +20,7 @@ const DEFAULT_CURVE_INITIALIZE_SUPPLY = 1_000_000_000_000_000;
|
|
20
20
|
const REACH_CURVE_SOL_AMOUNT = 85_000_000_000;
|
21
21
|
const DEFAULT_DECIMALS = 6;
|
22
22
|
const FEE_BASIS_POINTS = 100n;
|
23
|
+
const DENOMINATOR = 10000n;
|
23
24
|
|
24
25
|
var commonjsGlobal$1 = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
25
26
|
|
@@ -15888,7 +15889,7 @@ const DEFAULT_FINALITY = "finalized";
|
|
15888
15889
|
// token amount => token amount
|
15889
15890
|
// sol amount => sol amount
|
15890
15891
|
const calculateWithSlippage = (amount, basisPoints) => {
|
15891
|
-
return amount - (amount * basisPoints) /
|
15892
|
+
return amount - (amount * basisPoints) / DENOMINATOR;
|
15892
15893
|
};
|
15893
15894
|
async function sendTx(connection, tx, payer, signers, priorityFees, commitment = DEFAULT_COMMITMENT, finality = DEFAULT_FINALITY) {
|
15894
15895
|
let newTx = new Transaction();
|
@@ -16026,13 +16027,14 @@ class CurveState {
|
|
16026
16027
|
this.realSolReserves = realSolReserves;
|
16027
16028
|
this.realTokenReserves = realTokenReserves;
|
16028
16029
|
}
|
16029
|
-
getBuyPrice(amount,
|
16030
|
-
if (
|
16031
|
-
throw new Error("Curve is
|
16030
|
+
getBuyPrice(amount, isCompleted) {
|
16031
|
+
if (isCompleted) {
|
16032
|
+
throw new Error("Curve is completed");
|
16032
16033
|
}
|
16033
16034
|
if (amount <= 0n) {
|
16034
16035
|
return 0n;
|
16035
16036
|
}
|
16037
|
+
amount = amount * (DENOMINATOR - FEE_BASIS_POINTS) / DENOMINATOR;
|
16036
16038
|
// Calculate the product of virtual reserves
|
16037
16039
|
let n = this.virtualSolReserves * this.virtualTokenReserves;
|
16038
16040
|
// Calculate the new virtual sol reserves after the purchase
|
@@ -16044,8 +16046,8 @@ class CurveState {
|
|
16044
16046
|
// Return the minimum of the calculated tokens and real token reserves
|
16045
16047
|
return s < this.realTokenReserves ? s : this.realTokenReserves;
|
16046
16048
|
}
|
16047
|
-
getSellPrice(amount, feeBasisPoints,
|
16048
|
-
if (
|
16049
|
+
getSellPrice(amount, feeBasisPoints, isCompleted) {
|
16050
|
+
if (isCompleted) {
|
16049
16051
|
throw new Error("Curve is complete");
|
16050
16052
|
}
|
16051
16053
|
if (amount <= 0n) {
|
@@ -16054,7 +16056,7 @@ class CurveState {
|
|
16054
16056
|
// Calculate the proportional amount of virtual sol reserves to be received
|
16055
16057
|
let n = (amount * this.virtualSolReserves) / (this.virtualTokenReserves + amount);
|
16056
16058
|
// Calculate the fee amount in the same units
|
16057
|
-
let a = (n * feeBasisPoints) /
|
16059
|
+
let a = (n * feeBasisPoints) / DENOMINATOR;
|
16058
16060
|
// Return the net amount after deducting the fee
|
16059
16061
|
return n - a;
|
16060
16062
|
}
|
@@ -16079,7 +16081,7 @@ class CurveState {
|
|
16079
16081
|
let totalSellValue = (solTokens * this.virtualSolReserves) /
|
16080
16082
|
(this.virtualTokenReserves - solTokens) +
|
16081
16083
|
1n;
|
16082
|
-
let fee = (totalSellValue * feeBasisPoints) /
|
16084
|
+
let fee = (totalSellValue * feeBasisPoints) / DENOMINATOR;
|
16083
16085
|
return totalSellValue + fee;
|
16084
16086
|
}
|
16085
16087
|
static fromBuffer(buffer) {
|
@@ -16087,13 +16089,13 @@ class CurveState {
|
|
16087
16089
|
u64$1("discriminator"),
|
16088
16090
|
u64$1("initReservedToken"),
|
16089
16091
|
u64$1("supply"),
|
16090
|
-
u64$1("virtualTokenReserves"),
|
16091
16092
|
u64$1("virtualSolReserves"),
|
16093
|
+
u64$1("virtualTokenReserves"),
|
16092
16094
|
u64$1("realSolReserves"),
|
16093
16095
|
u64$1("realTokenReserves"),
|
16094
16096
|
]);
|
16095
16097
|
let value = structure.decode(buffer);
|
16096
|
-
return new CurveState(BigInt(value.discriminator), BigInt(value.initReservedToken), BigInt(value.supply), BigInt(value.
|
16098
|
+
return new CurveState(BigInt(value.discriminator), BigInt(value.initReservedToken), BigInt(value.supply), BigInt(value.virtualSolReserves), BigInt(value.virtualTokenReserves), BigInt(value.realSolReserves), BigInt(value.realTokenReserves));
|
16097
16099
|
}
|
16098
16100
|
}
|
16099
16101
|
|
@@ -21876,8 +21878,8 @@ class BetSDK {
|
|
21876
21878
|
if (!curveState) {
|
21877
21879
|
throw new Error(`Curve state account not found: ${mint.toBase58()}`);
|
21878
21880
|
}
|
21879
|
-
const
|
21880
|
-
let minSolOutput = curveState.getSellPrice(sellTokenAmount, FEE_BASIS_POINTS,
|
21881
|
+
const isCompleted = betState.isCompted;
|
21882
|
+
let minSolOutput = curveState.getSellPrice(sellTokenAmount, FEE_BASIS_POINTS, isCompleted);
|
21881
21883
|
let minSolOutputWithSlippage = calculateWithSlippage(minSolOutput, slippageBasisPoints);
|
21882
21884
|
return await this.getSellInstructions(seller, mint, sellTokenAmount, minSolOutputWithSlippage);
|
21883
21885
|
}
|
@@ -22030,6 +22032,7 @@ class BetSDK {
|
|
22030
22032
|
if (amount <= 0n) {
|
22031
22033
|
return 0n;
|
22032
22034
|
}
|
22035
|
+
amount = amount * (DENOMINATOR - FEE_BASIS_POINTS) / DENOMINATOR;
|
22033
22036
|
const initVirtualSol = new BigNumber(DEFAULT_CURVE_INITIALIZE_VITUAL_SOL_TOKEN);
|
22034
22037
|
const initVirtualToken = new BigNumber(DEFAULT_CURVE_INITIALIZE_VITUAL_RESERVED_TOKEN);
|
22035
22038
|
const initRealReservedToken = new BigNumber(DEFAULT_CURVE_INITIALIZE_INIT_RESERVED_TOKEN);
|
@@ -22052,46 +22055,56 @@ class BetSDK {
|
|
22052
22055
|
}
|
22053
22056
|
let shouldOutTokens = curveStateAccount.getBuyPrice(solAmountIn, false);
|
22054
22057
|
if (slippageBasisPoints) {
|
22055
|
-
shouldOutTokens -= (shouldOutTokens * slippageBasisPoints) /
|
22058
|
+
shouldOutTokens -= (shouldOutTokens * slippageBasisPoints) / DENOMINATOR;
|
22056
22059
|
}
|
22057
22060
|
return shouldOutTokens;
|
22058
22061
|
}
|
22059
22062
|
// Buy: Fixed token amount out, estimated sol amount in
|
22060
22063
|
async getMinSolAmountIn(mint, tokenAmountOut, slippageBasisPoints) {
|
22064
|
+
if (tokenAmountOut <= 0) {
|
22065
|
+
return 0n;
|
22066
|
+
}
|
22061
22067
|
const curveStateAccount = await this.getValidCurveState(mint);
|
22062
22068
|
if (!curveStateAccount) {
|
22063
22069
|
return 0n;
|
22064
22070
|
}
|
22065
|
-
let shouldOutTokens = tokenAmountOut > curveStateAccount.
|
22066
|
-
? curveStateAccount.
|
22071
|
+
let shouldOutTokens = tokenAmountOut > curveStateAccount.realTokenReserves
|
22072
|
+
? curveStateAccount.realTokenReserves
|
22067
22073
|
: tokenAmountOut;
|
22068
22074
|
let minSolAmountIn = (shouldOutTokens * curveStateAccount.virtualSolReserves) /
|
22069
22075
|
(curveStateAccount.virtualTokenReserves - shouldOutTokens) +
|
22070
22076
|
1n;
|
22077
|
+
let fee = (minSolAmountIn * FEE_BASIS_POINTS) / DENOMINATOR;
|
22071
22078
|
if (slippageBasisPoints) {
|
22072
|
-
minSolAmountIn += (minSolAmountIn * slippageBasisPoints) /
|
22079
|
+
minSolAmountIn += (minSolAmountIn * slippageBasisPoints) / DENOMINATOR;
|
22073
22080
|
}
|
22074
|
-
let fee = (minSolAmountIn * FEE_BASIS_POINTS) / 10000n;
|
22075
22081
|
return minSolAmountIn + fee;
|
22076
22082
|
}
|
22077
22083
|
// Sell: Fixed token amount in, estimated sol amount out
|
22078
22084
|
async getSolAmountOut(mint, tokenAmountIn, slippageBasisPoints) {
|
22085
|
+
if (tokenAmountIn <= 0) {
|
22086
|
+
return 0n;
|
22087
|
+
}
|
22079
22088
|
const curveStateAccount = await this.getValidCurveState(mint);
|
22080
22089
|
if (!curveStateAccount) {
|
22081
22090
|
return 0n;
|
22082
22091
|
}
|
22083
22092
|
let shouldOutTokens = curveStateAccount.getSellPrice(tokenAmountIn, FEE_BASIS_POINTS, false);
|
22084
22093
|
if (slippageBasisPoints) {
|
22085
|
-
shouldOutTokens -= (shouldOutTokens * slippageBasisPoints) /
|
22094
|
+
shouldOutTokens -= (shouldOutTokens * slippageBasisPoints) / DENOMINATOR;
|
22086
22095
|
}
|
22087
22096
|
return shouldOutTokens;
|
22088
22097
|
}
|
22089
22098
|
// Sell: Fixed sol amount out, estimated token amount in
|
22090
22099
|
async getMinTokenAmountIn(mint, solAmountOut, slippageBasisPoints) {
|
22100
|
+
if (solAmountOut <= 0) {
|
22101
|
+
return 0n;
|
22102
|
+
}
|
22091
22103
|
const curveStateAccount = await this.getValidCurveState(mint);
|
22092
22104
|
if (!curveStateAccount) {
|
22093
22105
|
return 0n;
|
22094
22106
|
}
|
22107
|
+
solAmountOut = solAmountOut * (DENOMINATOR - FEE_BASIS_POINTS) / DENOMINATOR;
|
22095
22108
|
let shouldOutSols = solAmountOut > curveStateAccount.virtualSolReserves - curveStateAccount.realSolReserves
|
22096
22109
|
? curveStateAccount.virtualSolReserves - curveStateAccount.realSolReserves
|
22097
22110
|
: solAmountOut;
|
@@ -22099,10 +22112,9 @@ class BetSDK {
|
|
22099
22112
|
(curveStateAccount.virtualSolReserves - shouldOutSols) +
|
22100
22113
|
1n;
|
22101
22114
|
if (slippageBasisPoints) {
|
22102
|
-
minTokenAmountIn += (minTokenAmountIn * slippageBasisPoints) /
|
22115
|
+
minTokenAmountIn += (minTokenAmountIn * slippageBasisPoints) / DENOMINATOR;
|
22103
22116
|
}
|
22104
|
-
|
22105
|
-
return minTokenAmountIn + fee;
|
22117
|
+
return minTokenAmountIn;
|
22106
22118
|
}
|
22107
22119
|
async getValidCurveState(mint) {
|
22108
22120
|
const curveStateAccount = await this.getCurveStateAccount(mint);
|
@@ -22206,5 +22218,5 @@ class AMM {
|
|
22206
22218
|
}
|
22207
22219
|
}
|
22208
22220
|
|
22209
|
-
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 };
|
22221
|
+
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, DENOMINATOR, 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 };
|
22210
22222
|
//# sourceMappingURL=index.js.map
|