bet-test-sdk 1.1.0 → 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.
- package/dist/browser/index.js +86 -29
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/types/bet.d.ts +5 -0
- package/dist/browser/types/bet.d.ts.map +1 -1
- package/dist/browser/types/betState.d.ts.map +1 -1
- package/dist/browser/types/types.d.ts +4 -4
- package/dist/cjs/bet.d.ts +5 -0
- package/dist/cjs/bet.d.ts.map +1 -1
- package/dist/cjs/bet.js +75 -2
- package/dist/cjs/bet.js.map +1 -1
- package/dist/cjs/betState.d.ts.map +1 -1
- package/dist/cjs/betState.js +8 -23
- package/dist/cjs/betState.js.map +1 -1
- package/dist/cjs/types.d.ts +4 -4
- package/dist/cjs/types.js +4 -4
- package/dist/esm/bet.d.ts +5 -0
- package/dist/esm/bet.d.ts.map +1 -1
- package/dist/esm/bet.js +75 -2
- package/dist/esm/bet.js.map +1 -1
- package/dist/esm/betState.d.ts.map +1 -1
- package/dist/esm/betState.js +8 -23
- package/dist/esm/betState.js.map +1 -1
- package/dist/esm/types.d.ts +4 -4
- package/dist/esm/types.js +4 -4
- package/package.json +1 -1
package/dist/browser/index.js
CHANGED
@@ -15962,13 +15962,13 @@ const getTxDetails = async (connection, sig, commitment = DEFAULT_COMMITMENT, fi
|
|
15962
15962
|
|
15963
15963
|
var MigrateType;
|
15964
15964
|
(function (MigrateType) {
|
15965
|
-
MigrateType[MigrateType["
|
15966
|
-
MigrateType[MigrateType["
|
15965
|
+
MigrateType[MigrateType["RAYDIUM"] = 0] = "RAYDIUM";
|
15966
|
+
MigrateType[MigrateType["METEORA"] = 1] = "METEORA";
|
15967
15967
|
})(MigrateType || (MigrateType = {}));
|
15968
15968
|
var MigrateDex;
|
15969
15969
|
(function (MigrateDex) {
|
15970
|
-
MigrateDex["
|
15971
|
-
MigrateDex["
|
15970
|
+
MigrateDex["RAYDIUM"] = "raydium";
|
15971
|
+
MigrateDex["METEORA"] = "meteora";
|
15972
15972
|
})(MigrateDex || (MigrateDex = {}));
|
15973
15973
|
|
15974
15974
|
function toCreateEvent(event) {
|
@@ -16097,6 +16097,8 @@ class CurveState {
|
|
16097
16097
|
}
|
16098
16098
|
}
|
16099
16099
|
|
16100
|
+
const u128 = (property) => struct$1([u64$1("low"), u64$1("high")], property);
|
16101
|
+
const toBigInt = ({ low, high }) => (BigInt(high.toString()) << 64n) + BigInt(low.toString());
|
16100
16102
|
// "discriminator": [143,61,238,62,232,157,101,185]
|
16101
16103
|
class BetState {
|
16102
16104
|
discriminator;
|
@@ -16135,34 +16137,16 @@ class BetState {
|
|
16135
16137
|
publicKey$3("mint"),
|
16136
16138
|
publicKey$3("poolOfSol"),
|
16137
16139
|
publicKey$3("poolOfToken"),
|
16138
|
-
|
16139
|
-
|
16140
|
-
|
16141
|
-
|
16142
|
-
publicKey$3('totalSolInAndTotalTokenOut'),
|
16143
|
-
publicKey$3('totalSolOutAndtotalTokenIn'),
|
16140
|
+
u128("totalSolIn"),
|
16141
|
+
u128("totalTokenOut"),
|
16142
|
+
u128("totalSolOut"),
|
16143
|
+
u128("totalTokenIn"),
|
16144
16144
|
u8$1("migrateType"),
|
16145
16145
|
bool("isWithdrawed"),
|
16146
16146
|
bool("isCompted"),
|
16147
16147
|
]);
|
16148
16148
|
let value = structure.decode(buffer);
|
16149
|
-
|
16150
|
-
return value;
|
16151
|
-
// return new BetState(
|
16152
|
-
// BigInt(value.discriminator),
|
16153
|
-
// new PublicKey(value.creator),
|
16154
|
-
// new PublicKey(value.curveState),
|
16155
|
-
// new PublicKey(value.mint),
|
16156
|
-
// new PublicKey(value.poolOfSol),
|
16157
|
-
// new PublicKey(value.poolOfToken),
|
16158
|
-
// BigInt(value.totalSolIn),
|
16159
|
-
// BigInt(value.totalTokenOut),
|
16160
|
-
// BigInt(value.totalSolOut),
|
16161
|
-
// BigInt(value.totalTokenIn),
|
16162
|
-
// value.migrateType,
|
16163
|
-
// value.isWithdrawed,
|
16164
|
-
// value.isCompted
|
16165
|
-
// );
|
16149
|
+
return new BetState(BigInt(value.discriminator), new PublicKey(value.creator), new PublicKey(value.curveState), new PublicKey(value.mint), new PublicKey(value.poolOfSol), new PublicKey(value.poolOfToken), toBigInt(value.totalSolIn), toBigInt(value.totalTokenOut), toBigInt(value.totalSolOut), toBigInt(value.totalTokenIn), value.migrateType, value.isWithdrawed, value.isCompted);
|
16166
16150
|
}
|
16167
16151
|
}
|
16168
16152
|
|
@@ -21813,7 +21797,7 @@ class BetSDK {
|
|
21813
21797
|
async getCreateAndBuyInstructions(creator, createTokenMetadata, buyAmountSol, slippageBasisPoints = 500n, commitment = DEFAULT_COMMITMENT) {
|
21814
21798
|
let mintKeyPair = await this.createMint();
|
21815
21799
|
let tokenMetadata = await this.createTokenMetadata(createTokenMetadata);
|
21816
|
-
const migrateType = createTokenMetadata.migrateDex == MigrateDex.
|
21800
|
+
const migrateType = createTokenMetadata.migrateDex == MigrateDex.METEORA ? MigrateType.METEORA : MigrateType.RAYDIUM;
|
21817
21801
|
let createTx = await this.getCreateInstructions(creator, createTokenMetadata.name, createTokenMetadata.symbol, tokenMetadata.data, migrateType, mintKeyPair);
|
21818
21802
|
let newTx = new Transaction().add(createTx);
|
21819
21803
|
const curveStateAccount = await this.getCurveStateAccount(mintKeyPair.publicKey, commitment);
|
@@ -21836,7 +21820,7 @@ class BetSDK {
|
|
21836
21820
|
async getCreateInstructions(creator, name, symbol, uri, migrateType, mintKeyPair) {
|
21837
21821
|
return this.program.methods
|
21838
21822
|
.createToken({
|
21839
|
-
migrateType: migrateType == MigrateType.
|
21823
|
+
migrateType: migrateType == MigrateType.RAYDIUM ? { raydium: {} } : { meteora: {} },
|
21840
21824
|
name: name,
|
21841
21825
|
symbol: symbol,
|
21842
21826
|
uri: uri
|
@@ -22059,6 +22043,79 @@ class BetSDK {
|
|
22059
22043
|
: initRealReservedToken;
|
22060
22044
|
return BigInt(bigAmount.toString().split(".")[0]);
|
22061
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
|
+
}
|
22062
22119
|
//EVENTS
|
22063
22120
|
addEventListener(eventType, callback) {
|
22064
22121
|
return this.program.addEventListener(eventType, (event, slot, signature) => {
|