@meteora-ag/dlmm 1.3.15 → 1.3.17-rc.0
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/index.d.ts +7 -1
- package/dist/index.js +68 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -6,9 +6,11 @@ import {
|
|
|
6
6
|
MintLayout,
|
|
7
7
|
NATIVE_MINT as NATIVE_MINT2,
|
|
8
8
|
TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID2,
|
|
9
|
+
createAssociatedTokenAccountIdempotentInstruction as createAssociatedTokenAccountIdempotentInstruction2,
|
|
9
10
|
createAssociatedTokenAccountInstruction as createAssociatedTokenAccountInstruction2,
|
|
10
11
|
createTransferInstruction,
|
|
11
|
-
getAssociatedTokenAddressSync as getAssociatedTokenAddressSync2
|
|
12
|
+
getAssociatedTokenAddressSync as getAssociatedTokenAddressSync2,
|
|
13
|
+
unpackAccount
|
|
12
14
|
} from "@solana/spl-token";
|
|
13
15
|
import {
|
|
14
16
|
ComputeBudgetProgram as ComputeBudgetProgram3,
|
|
@@ -5477,6 +5479,7 @@ var CONSTANTS = Object.entries(IDL.constants);
|
|
|
5477
5479
|
var MAX_BIN_ARRAY_SIZE = new BN(
|
|
5478
5480
|
CONSTANTS.find(([k, v]) => v.name == "MAX_BIN_PER_ARRAY")?.[1].value ?? 0
|
|
5479
5481
|
);
|
|
5482
|
+
console.log("CONSTANTS", CONSTANTS);
|
|
5480
5483
|
var MAX_BIN_PER_POSITION = new BN(
|
|
5481
5484
|
CONSTANTS.find(([k, v]) => v.name == "MAX_BIN_PER_POSITION")?.[1].value ?? 0
|
|
5482
5485
|
);
|
|
@@ -6641,7 +6644,7 @@ function derivePosition(lbPair, base, lowerBinId, width, programId) {
|
|
|
6641
6644
|
lbPair.toBuffer(),
|
|
6642
6645
|
base.toBuffer(),
|
|
6643
6646
|
lowerBinIdBytes,
|
|
6644
|
-
new Uint8Array(width.
|
|
6647
|
+
new Uint8Array(width.toArrayLike(Buffer, "le", 4))
|
|
6645
6648
|
],
|
|
6646
6649
|
programId
|
|
6647
6650
|
);
|
|
@@ -11042,9 +11045,14 @@ var DLMM = class {
|
|
|
11042
11045
|
* - `minPrice`: Start price in UI format
|
|
11043
11046
|
* - `maxPrice`: End price in UI format
|
|
11044
11047
|
* - `base`: Base key
|
|
11048
|
+
* - `txPayer`: Account rental fee payer
|
|
11049
|
+
* - `feeOwner`: Fee owner key. Default to position owner
|
|
11050
|
+
* - `operator`: Operator key
|
|
11051
|
+
* - `lockReleasePoint`: Timelock. Point (slot/timestamp) the position can withdraw the liquidity,
|
|
11052
|
+
* - `shouldSeedPositionOwner` (optional): Whether to send 1 lamport amount of token X to the position owner to prove ownership.
|
|
11045
11053
|
* @returns {Promise<SeedLiquidityResponse>}
|
|
11046
11054
|
*/
|
|
11047
|
-
async seedLiquidity(owner, seedAmount, curvature, minPrice, maxPrice, base) {
|
|
11055
|
+
async seedLiquidity(owner, seedAmount, curvature, minPrice, maxPrice, base, payer, feeOwner, operator, lockReleasePoint, shouldSeedPositionOwner = false) {
|
|
11048
11056
|
const toLamportMultiplier = new Decimal5(
|
|
11049
11057
|
10 ** (this.tokenY.decimal - this.tokenX.decimal)
|
|
11050
11058
|
);
|
|
@@ -11089,13 +11097,56 @@ var DLMM = class {
|
|
|
11089
11097
|
);
|
|
11090
11098
|
const positionCount = getPositionCount(minBinId, maxBinId.sub(new BN10(1)));
|
|
11091
11099
|
const seederTokenX = getAssociatedTokenAddressSync2(
|
|
11100
|
+
this.lbPair.tokenXMint,
|
|
11101
|
+
operator,
|
|
11102
|
+
false
|
|
11103
|
+
);
|
|
11104
|
+
const seederTokenY = getAssociatedTokenAddressSync2(
|
|
11105
|
+
this.lbPair.tokenYMint,
|
|
11106
|
+
operator,
|
|
11107
|
+
false
|
|
11108
|
+
);
|
|
11109
|
+
const ownerTokenX = getAssociatedTokenAddressSync2(
|
|
11092
11110
|
this.lbPair.tokenXMint,
|
|
11093
11111
|
owner,
|
|
11094
11112
|
false
|
|
11095
11113
|
);
|
|
11114
|
+
const sendPositionOwnerTokenProveIxs = [];
|
|
11096
11115
|
const initializeBinArraysAndPositionIxs = [];
|
|
11097
11116
|
const addLiquidityIxs = [];
|
|
11098
11117
|
const appendedInitBinArrayIx = /* @__PURE__ */ new Set();
|
|
11118
|
+
if (shouldSeedPositionOwner) {
|
|
11119
|
+
const positionOwnerTokenX = await this.program.provider.connection.getAccountInfo(ownerTokenX);
|
|
11120
|
+
let requireTokenProve = false;
|
|
11121
|
+
if (positionOwnerTokenX) {
|
|
11122
|
+
const ownerTokenXState = unpackAccount(
|
|
11123
|
+
ownerTokenX,
|
|
11124
|
+
positionOwnerTokenX,
|
|
11125
|
+
TOKEN_PROGRAM_ID2
|
|
11126
|
+
);
|
|
11127
|
+
requireTokenProve = ownerTokenXState.amount == 0n;
|
|
11128
|
+
} else {
|
|
11129
|
+
requireTokenProve = true;
|
|
11130
|
+
}
|
|
11131
|
+
if (requireTokenProve) {
|
|
11132
|
+
const initPositionOwnerTokenX = createAssociatedTokenAccountIdempotentInstruction2(
|
|
11133
|
+
payer,
|
|
11134
|
+
ownerTokenX,
|
|
11135
|
+
owner,
|
|
11136
|
+
this.lbPair.tokenXMint,
|
|
11137
|
+
TOKEN_PROGRAM_ID2
|
|
11138
|
+
);
|
|
11139
|
+
sendPositionOwnerTokenProveIxs.push(initPositionOwnerTokenX);
|
|
11140
|
+
sendPositionOwnerTokenProveIxs.push(
|
|
11141
|
+
createTransferInstruction(
|
|
11142
|
+
seederTokenX,
|
|
11143
|
+
ownerTokenX,
|
|
11144
|
+
operator,
|
|
11145
|
+
1n
|
|
11146
|
+
)
|
|
11147
|
+
);
|
|
11148
|
+
}
|
|
11149
|
+
}
|
|
11099
11150
|
for (let i = 0; i < positionCount.toNumber(); i++) {
|
|
11100
11151
|
const lowerBinId = minBinId.add(MAX_BIN_PER_POSITION.mul(new BN10(i)));
|
|
11101
11152
|
const upperBinId = lowerBinId.add(MAX_BIN_PER_POSITION).sub(new BN10(1));
|
|
@@ -11130,7 +11181,7 @@ var DLMM = class {
|
|
|
11130
11181
|
await this.program.methods.initializeBinArray(lowerBinArrayIndex).accounts({
|
|
11131
11182
|
lbPair: this.pubkey,
|
|
11132
11183
|
binArray: lowerBinArray,
|
|
11133
|
-
funder:
|
|
11184
|
+
funder: payer
|
|
11134
11185
|
}).instruction()
|
|
11135
11186
|
);
|
|
11136
11187
|
appendedInitBinArrayIx.add(lowerBinArray.toBase58());
|
|
@@ -11141,7 +11192,7 @@ var DLMM = class {
|
|
|
11141
11192
|
await this.program.methods.initializeBinArray(upperBinArrayIndex).accounts({
|
|
11142
11193
|
lbPair: this.pubkey,
|
|
11143
11194
|
binArray: upperBinArray,
|
|
11144
|
-
funder:
|
|
11195
|
+
funder: payer
|
|
11145
11196
|
}).instruction()
|
|
11146
11197
|
);
|
|
11147
11198
|
appendedInitBinArrayIx.add(upperBinArray.toBase58());
|
|
@@ -11149,26 +11200,25 @@ var DLMM = class {
|
|
|
11149
11200
|
const positionAccount = accounts[2];
|
|
11150
11201
|
if (!positionAccount) {
|
|
11151
11202
|
instructions.push(
|
|
11152
|
-
await this.program.methods.
|
|
11203
|
+
await this.program.methods.initializePositionByOperator(
|
|
11153
11204
|
lowerBinId.toNumber(),
|
|
11154
|
-
MAX_BIN_PER_POSITION.toNumber()
|
|
11205
|
+
MAX_BIN_PER_POSITION.toNumber(),
|
|
11206
|
+
feeOwner,
|
|
11207
|
+
lockReleasePoint
|
|
11155
11208
|
).accounts({
|
|
11156
11209
|
lbPair: this.pubkey,
|
|
11157
11210
|
position: positionPda,
|
|
11158
11211
|
base,
|
|
11159
11212
|
owner,
|
|
11160
|
-
payer
|
|
11213
|
+
payer,
|
|
11214
|
+
operator,
|
|
11215
|
+
operatorTokenX: seederTokenX,
|
|
11216
|
+
ownerTokenX,
|
|
11217
|
+
systemProgram: SystemProgram2.programId
|
|
11161
11218
|
}).instruction()
|
|
11162
11219
|
);
|
|
11163
11220
|
}
|
|
11164
11221
|
if (instructions.length > 1) {
|
|
11165
|
-
instructions.push(
|
|
11166
|
-
await getEstimatedComputeUnitIxWithBuffer(
|
|
11167
|
-
this.program.provider.connection,
|
|
11168
|
-
instructions,
|
|
11169
|
-
owner
|
|
11170
|
-
)
|
|
11171
|
-
);
|
|
11172
11222
|
initializeBinArraysAndPositionIxs.push(instructions);
|
|
11173
11223
|
instructions = [];
|
|
11174
11224
|
}
|
|
@@ -11198,7 +11248,7 @@ var DLMM = class {
|
|
|
11198
11248
|
tokenMint: this.lbPair.tokenXMint,
|
|
11199
11249
|
binArrayLower: lowerBinArray,
|
|
11200
11250
|
binArrayUpper: upperBinArray,
|
|
11201
|
-
sender:
|
|
11251
|
+
sender: operator
|
|
11202
11252
|
}).instruction()
|
|
11203
11253
|
);
|
|
11204
11254
|
if (i + 1 >= positionCount.toNumber() && !finalLoss.isZero()) {
|
|
@@ -11222,7 +11272,7 @@ var DLMM = class {
|
|
|
11222
11272
|
tokenMint: this.lbPair.tokenXMint,
|
|
11223
11273
|
binArrayLower: lowerBinArray,
|
|
11224
11274
|
binArrayUpper: upperBinArray,
|
|
11225
|
-
sender:
|
|
11275
|
+
sender: operator
|
|
11226
11276
|
}).instruction()
|
|
11227
11277
|
);
|
|
11228
11278
|
}
|
|
@@ -11234,7 +11284,9 @@ var DLMM = class {
|
|
|
11234
11284
|
]);
|
|
11235
11285
|
}
|
|
11236
11286
|
}
|
|
11287
|
+
console.log("let return");
|
|
11237
11288
|
return {
|
|
11289
|
+
sendPositionOwnerTokenProveIxs,
|
|
11238
11290
|
initializeBinArraysAndPositionIxs,
|
|
11239
11291
|
addLiquidityIxs
|
|
11240
11292
|
};
|