@meteora-ag/cp-amm-sdk 1.0.1-rc.24 → 1.0.1-rc.26
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.mts +158 -2
- package/dist/index.d.ts +158 -2
- package/dist/index.js +580 -258
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +580 -258
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6352,6 +6352,7 @@ var cp_amm_default = {
|
|
|
6352
6352
|
// src/CpAmm.ts
|
|
6353
6353
|
|
|
6354
6354
|
|
|
6355
|
+
|
|
6355
6356
|
var _web3js = require('@solana/web3.js');
|
|
6356
6357
|
|
|
6357
6358
|
// src/constants.ts
|
|
@@ -7210,6 +7211,46 @@ var CpAmm = class {
|
|
|
7210
7211
|
};
|
|
7211
7212
|
});
|
|
7212
7213
|
}
|
|
7214
|
+
/**
|
|
7215
|
+
* Prepares token accounts for a transaction by retrieving or creating associated token accounts.
|
|
7216
|
+
* @private
|
|
7217
|
+
* @param {PublicKey} owner - The owner of the token accounts
|
|
7218
|
+
* @param {PublicKey} tokenAMint - Mint address of token A
|
|
7219
|
+
* @param {PublicKey} tokenBMint - Mint address of token B
|
|
7220
|
+
* @param {PublicKey} tokenAProgram - Program ID for token A (Token or Token2022)
|
|
7221
|
+
* @param {PublicKey} tokenBProgram - Program ID for token B (Token or Token2022)
|
|
7222
|
+
* @returns {Promise<{tokenAAta: PublicKey, tokenBAta: PublicKey, instructions: TransactionInstruction[]}>}
|
|
7223
|
+
* The token account addresses and any instructions needed to create them
|
|
7224
|
+
*/
|
|
7225
|
+
prepareTokenAccounts(owner, tokenAMint, tokenBMint, tokenAProgram, tokenBProgram) {
|
|
7226
|
+
return __async(this, null, function* () {
|
|
7227
|
+
const instructions = [];
|
|
7228
|
+
const [
|
|
7229
|
+
{ ataPubkey: tokenAAta, ix: createInputTokenAccountIx },
|
|
7230
|
+
{ ataPubkey: tokenBAta, ix: createOutputTokenAccountIx }
|
|
7231
|
+
] = yield Promise.all([
|
|
7232
|
+
getOrCreateATAInstruction(
|
|
7233
|
+
this._program.provider.connection,
|
|
7234
|
+
tokenAMint,
|
|
7235
|
+
owner,
|
|
7236
|
+
owner,
|
|
7237
|
+
true,
|
|
7238
|
+
tokenAProgram
|
|
7239
|
+
),
|
|
7240
|
+
getOrCreateATAInstruction(
|
|
7241
|
+
this._program.provider.connection,
|
|
7242
|
+
tokenBMint,
|
|
7243
|
+
owner,
|
|
7244
|
+
owner,
|
|
7245
|
+
true,
|
|
7246
|
+
tokenBProgram
|
|
7247
|
+
)
|
|
7248
|
+
]);
|
|
7249
|
+
createInputTokenAccountIx && instructions.push(createInputTokenAccountIx);
|
|
7250
|
+
createOutputTokenAccountIx && instructions.push(createOutputTokenAccountIx);
|
|
7251
|
+
return { tokenAAta, tokenBAta, instructions };
|
|
7252
|
+
});
|
|
7253
|
+
}
|
|
7213
7254
|
/**
|
|
7214
7255
|
* Derives token badge account metadata
|
|
7215
7256
|
* @param tokenAMint - Public key of token A mint
|
|
@@ -7230,6 +7271,161 @@ var CpAmm = class {
|
|
|
7230
7271
|
}
|
|
7231
7272
|
];
|
|
7232
7273
|
}
|
|
7274
|
+
/**
|
|
7275
|
+
* Builds an instruction to add liquidity to a position.
|
|
7276
|
+
* @private
|
|
7277
|
+
* @param {BuildAddLiquidityParams} params - Parameters for adding liquidity
|
|
7278
|
+
* @returns {Promise<TransactionInstruction>} Instruction to add liquidity
|
|
7279
|
+
*/
|
|
7280
|
+
buildAddLiquidityInstruction(params) {
|
|
7281
|
+
return __async(this, null, function* () {
|
|
7282
|
+
const {
|
|
7283
|
+
pool,
|
|
7284
|
+
position,
|
|
7285
|
+
positionNftAccount,
|
|
7286
|
+
owner,
|
|
7287
|
+
tokenAAccount,
|
|
7288
|
+
tokenBAccount,
|
|
7289
|
+
tokenAMint,
|
|
7290
|
+
tokenBMint,
|
|
7291
|
+
tokenAVault,
|
|
7292
|
+
tokenBVault,
|
|
7293
|
+
tokenAProgram,
|
|
7294
|
+
tokenBProgram,
|
|
7295
|
+
liquidityDelta,
|
|
7296
|
+
tokenAAmountThreshold,
|
|
7297
|
+
tokenBAmountThreshold
|
|
7298
|
+
} = params;
|
|
7299
|
+
return yield this._program.methods.addLiquidity({
|
|
7300
|
+
liquidityDelta,
|
|
7301
|
+
tokenAAmountThreshold,
|
|
7302
|
+
tokenBAmountThreshold
|
|
7303
|
+
}).accountsPartial({
|
|
7304
|
+
pool,
|
|
7305
|
+
position,
|
|
7306
|
+
positionNftAccount,
|
|
7307
|
+
owner,
|
|
7308
|
+
tokenAAccount,
|
|
7309
|
+
tokenBAccount,
|
|
7310
|
+
tokenAMint,
|
|
7311
|
+
tokenBMint,
|
|
7312
|
+
tokenAVault,
|
|
7313
|
+
tokenBVault,
|
|
7314
|
+
tokenAProgram,
|
|
7315
|
+
tokenBProgram
|
|
7316
|
+
}).instruction();
|
|
7317
|
+
});
|
|
7318
|
+
}
|
|
7319
|
+
/**
|
|
7320
|
+
* Builds an instruction to remove all liquidity from a position.
|
|
7321
|
+
* @private
|
|
7322
|
+
* @param {BuildRemoveAllLiquidityInstructionParams} params - Parameters for removing all liquidity
|
|
7323
|
+
* @returns {Promise<TransactionInstruction>} Instruction to remove all liquidity
|
|
7324
|
+
*/
|
|
7325
|
+
buildRemoveAllLiquidityInstruction(params) {
|
|
7326
|
+
return __async(this, null, function* () {
|
|
7327
|
+
const {
|
|
7328
|
+
poolAuthority,
|
|
7329
|
+
owner,
|
|
7330
|
+
pool,
|
|
7331
|
+
position,
|
|
7332
|
+
positionNftAccount,
|
|
7333
|
+
tokenAAccount,
|
|
7334
|
+
tokenBAccount,
|
|
7335
|
+
tokenAAmountThreshold,
|
|
7336
|
+
tokenBAmountThreshold,
|
|
7337
|
+
tokenAMint,
|
|
7338
|
+
tokenBMint,
|
|
7339
|
+
tokenAVault,
|
|
7340
|
+
tokenBVault,
|
|
7341
|
+
tokenAProgram,
|
|
7342
|
+
tokenBProgram
|
|
7343
|
+
} = params;
|
|
7344
|
+
return yield this._program.methods.removeAllLiquidity(tokenAAmountThreshold, tokenBAmountThreshold).accountsPartial({
|
|
7345
|
+
poolAuthority,
|
|
7346
|
+
pool,
|
|
7347
|
+
position,
|
|
7348
|
+
positionNftAccount,
|
|
7349
|
+
owner,
|
|
7350
|
+
tokenAAccount,
|
|
7351
|
+
tokenBAccount,
|
|
7352
|
+
tokenAMint,
|
|
7353
|
+
tokenBMint,
|
|
7354
|
+
tokenAVault,
|
|
7355
|
+
tokenBVault,
|
|
7356
|
+
tokenAProgram,
|
|
7357
|
+
tokenBProgram
|
|
7358
|
+
}).instruction();
|
|
7359
|
+
});
|
|
7360
|
+
}
|
|
7361
|
+
/**
|
|
7362
|
+
* Builds an instruction to claim fees accumulated by a position.
|
|
7363
|
+
* @private
|
|
7364
|
+
* @param {ClaimPositionFeeInstructionParams} params - Parameters for claiming position fees
|
|
7365
|
+
* @returns {Promise<TransactionInstruction>} Instruction to claim position fees
|
|
7366
|
+
*/
|
|
7367
|
+
buildClaimPositionFeeInstruction(params) {
|
|
7368
|
+
return __async(this, null, function* () {
|
|
7369
|
+
const {
|
|
7370
|
+
owner,
|
|
7371
|
+
poolAuthority,
|
|
7372
|
+
pool,
|
|
7373
|
+
position,
|
|
7374
|
+
positionNftAccount,
|
|
7375
|
+
tokenAAccount,
|
|
7376
|
+
tokenBAccount,
|
|
7377
|
+
tokenAVault,
|
|
7378
|
+
tokenBVault,
|
|
7379
|
+
tokenAMint,
|
|
7380
|
+
tokenBMint,
|
|
7381
|
+
tokenAProgram,
|
|
7382
|
+
tokenBProgram
|
|
7383
|
+
} = params;
|
|
7384
|
+
return yield this._program.methods.claimPositionFee().accountsPartial({
|
|
7385
|
+
poolAuthority,
|
|
7386
|
+
owner,
|
|
7387
|
+
pool,
|
|
7388
|
+
position,
|
|
7389
|
+
positionNftAccount,
|
|
7390
|
+
tokenAAccount,
|
|
7391
|
+
tokenBAccount,
|
|
7392
|
+
tokenAVault,
|
|
7393
|
+
tokenBVault,
|
|
7394
|
+
tokenAMint,
|
|
7395
|
+
tokenBMint,
|
|
7396
|
+
tokenAProgram,
|
|
7397
|
+
tokenBProgram
|
|
7398
|
+
}).instruction();
|
|
7399
|
+
});
|
|
7400
|
+
}
|
|
7401
|
+
/**
|
|
7402
|
+
* Builds an instruction to close a position.
|
|
7403
|
+
* @private
|
|
7404
|
+
* @param {ClosePositionInstructionParams} params - Parameters for closing a position
|
|
7405
|
+
* @returns {Promise<TransactionInstruction>} Instruction to close the position
|
|
7406
|
+
*/
|
|
7407
|
+
buildClosePositionInstruction(params) {
|
|
7408
|
+
return __async(this, null, function* () {
|
|
7409
|
+
const {
|
|
7410
|
+
owner,
|
|
7411
|
+
poolAuthority,
|
|
7412
|
+
pool,
|
|
7413
|
+
position,
|
|
7414
|
+
positionNftAccount,
|
|
7415
|
+
positionNftMint
|
|
7416
|
+
} = params;
|
|
7417
|
+
return yield this._program.methods.closePosition().accountsPartial({
|
|
7418
|
+
positionNftMint,
|
|
7419
|
+
positionNftAccount,
|
|
7420
|
+
pool,
|
|
7421
|
+
position,
|
|
7422
|
+
poolAuthority,
|
|
7423
|
+
rentReceiver: owner,
|
|
7424
|
+
owner,
|
|
7425
|
+
tokenProgram: _spltoken.TOKEN_2022_PROGRAM_ID
|
|
7426
|
+
}).instruction();
|
|
7427
|
+
});
|
|
7428
|
+
}
|
|
7233
7429
|
/**
|
|
7234
7430
|
* Fetches the Config state of the program.
|
|
7235
7431
|
* @param config - Public key of the config account.
|
|
@@ -7359,6 +7555,18 @@ var CpAmm = class {
|
|
|
7359
7555
|
return vestings;
|
|
7360
7556
|
});
|
|
7361
7557
|
}
|
|
7558
|
+
isLockedPosition(position) {
|
|
7559
|
+
const totalLockedLiquidity = position.vestedLiquidity.add(
|
|
7560
|
+
position.permanentLockedLiquidity
|
|
7561
|
+
);
|
|
7562
|
+
return totalLockedLiquidity.gtn(0);
|
|
7563
|
+
}
|
|
7564
|
+
isPoolExist(pool) {
|
|
7565
|
+
return __async(this, null, function* () {
|
|
7566
|
+
const poolState = yield this._program.account.pool.fetchNullable(pool);
|
|
7567
|
+
return poolState !== null;
|
|
7568
|
+
});
|
|
7569
|
+
}
|
|
7362
7570
|
/**
|
|
7363
7571
|
* Calculates swap quote based on input amount and pool state.
|
|
7364
7572
|
* @param params - Swap parameters including input amount, pool state, slippage, etc.
|
|
@@ -7549,30 +7757,17 @@ var CpAmm = class {
|
|
|
7549
7757
|
pool,
|
|
7550
7758
|
this._program.programId
|
|
7551
7759
|
);
|
|
7552
|
-
const
|
|
7553
|
-
|
|
7554
|
-
|
|
7555
|
-
|
|
7556
|
-
|
|
7557
|
-
|
|
7558
|
-
|
|
7559
|
-
|
|
7560
|
-
|
|
7561
|
-
|
|
7562
|
-
|
|
7563
|
-
tokenAProgram
|
|
7564
|
-
),
|
|
7565
|
-
getOrCreateATAInstruction(
|
|
7566
|
-
this._program.provider.connection,
|
|
7567
|
-
tokenBMint,
|
|
7568
|
-
payer,
|
|
7569
|
-
payer,
|
|
7570
|
-
true,
|
|
7571
|
-
tokenBProgram
|
|
7572
|
-
)
|
|
7573
|
-
]);
|
|
7574
|
-
createTokenATokenAccountIx && preInstructions.push(createTokenATokenAccountIx);
|
|
7575
|
-
createTokenBTokenAccountIx && preInstructions.push(createTokenBTokenAccountIx);
|
|
7760
|
+
const {
|
|
7761
|
+
tokenAAta: payerTokenA,
|
|
7762
|
+
tokenBAta: payerTokenB,
|
|
7763
|
+
instructions: preInstructions
|
|
7764
|
+
} = yield this.prepareTokenAccounts(
|
|
7765
|
+
payer,
|
|
7766
|
+
tokenAMint,
|
|
7767
|
+
tokenBMint,
|
|
7768
|
+
tokenAProgram,
|
|
7769
|
+
tokenBProgram
|
|
7770
|
+
);
|
|
7576
7771
|
if (tokenAMint.equals(_spltoken.NATIVE_MINT)) {
|
|
7577
7772
|
const wrapSOLIx = wrapSOLInstruction(
|
|
7578
7773
|
payer,
|
|
@@ -7681,30 +7876,17 @@ var CpAmm = class {
|
|
|
7681
7876
|
pool,
|
|
7682
7877
|
this._program.programId
|
|
7683
7878
|
);
|
|
7684
|
-
const
|
|
7685
|
-
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
|
|
7690
|
-
|
|
7691
|
-
|
|
7692
|
-
|
|
7693
|
-
|
|
7694
|
-
|
|
7695
|
-
tokenAProgram
|
|
7696
|
-
),
|
|
7697
|
-
getOrCreateATAInstruction(
|
|
7698
|
-
this._program.provider.connection,
|
|
7699
|
-
tokenBMint,
|
|
7700
|
-
payer,
|
|
7701
|
-
payer,
|
|
7702
|
-
true,
|
|
7703
|
-
tokenBProgram
|
|
7704
|
-
)
|
|
7705
|
-
]);
|
|
7706
|
-
createTokenATokenAccountIx && preInstructions.push(createTokenATokenAccountIx);
|
|
7707
|
-
createTokenBTokenAccountIx && preInstructions.push(createTokenBTokenAccountIx);
|
|
7879
|
+
const {
|
|
7880
|
+
tokenAAta: payerTokenA,
|
|
7881
|
+
tokenBAta: payerTokenB,
|
|
7882
|
+
instructions: preInstructions
|
|
7883
|
+
} = yield this.prepareTokenAccounts(
|
|
7884
|
+
payer,
|
|
7885
|
+
tokenAMint,
|
|
7886
|
+
tokenBMint,
|
|
7887
|
+
tokenAProgram,
|
|
7888
|
+
tokenBProgram
|
|
7889
|
+
);
|
|
7708
7890
|
if (tokenAMint.equals(_spltoken.NATIVE_MINT)) {
|
|
7709
7891
|
const wrapSOLIx = wrapSOLInstruction(
|
|
7710
7892
|
payer,
|
|
@@ -7774,7 +7956,7 @@ var CpAmm = class {
|
|
|
7774
7956
|
positionNft,
|
|
7775
7957
|
this._program.programId
|
|
7776
7958
|
);
|
|
7777
|
-
return yield this._program.methods.createPosition().
|
|
7959
|
+
return yield this._program.methods.createPosition().accountsPartial({
|
|
7778
7960
|
owner,
|
|
7779
7961
|
positionNftMint: positionNft,
|
|
7780
7962
|
poolAuthority,
|
|
@@ -7783,9 +7965,7 @@ var CpAmm = class {
|
|
|
7783
7965
|
pool,
|
|
7784
7966
|
position,
|
|
7785
7967
|
tokenProgram: _spltoken.TOKEN_2022_PROGRAM_ID,
|
|
7786
|
-
systemProgram: _web3js.SystemProgram.programId
|
|
7787
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
7788
|
-
program: this._program.programId
|
|
7968
|
+
systemProgram: _web3js.SystemProgram.programId
|
|
7789
7969
|
}).transaction();
|
|
7790
7970
|
});
|
|
7791
7971
|
}
|
|
@@ -7817,30 +7997,17 @@ var CpAmm = class {
|
|
|
7817
7997
|
positionNftMint,
|
|
7818
7998
|
this._program.programId
|
|
7819
7999
|
);
|
|
7820
|
-
const
|
|
7821
|
-
|
|
7822
|
-
|
|
7823
|
-
|
|
7824
|
-
|
|
7825
|
-
|
|
7826
|
-
|
|
7827
|
-
|
|
7828
|
-
|
|
7829
|
-
|
|
7830
|
-
|
|
7831
|
-
tokenAProgram
|
|
7832
|
-
),
|
|
7833
|
-
getOrCreateATAInstruction(
|
|
7834
|
-
this._program.provider.connection,
|
|
7835
|
-
tokenBMint,
|
|
7836
|
-
owner,
|
|
7837
|
-
owner,
|
|
7838
|
-
true,
|
|
7839
|
-
tokenBProgram
|
|
7840
|
-
)
|
|
7841
|
-
]);
|
|
7842
|
-
createTokenATokenAccountIx && preInstructions.push(createTokenATokenAccountIx);
|
|
7843
|
-
createTokenBTokenAccountIx && preInstructions.push(createTokenBTokenAccountIx);
|
|
8000
|
+
const {
|
|
8001
|
+
tokenAAta: tokenAAccount,
|
|
8002
|
+
tokenBAta: tokenBAccount,
|
|
8003
|
+
instructions: preInstructions
|
|
8004
|
+
} = yield this.prepareTokenAccounts(
|
|
8005
|
+
owner,
|
|
8006
|
+
tokenAMint,
|
|
8007
|
+
tokenBMint,
|
|
8008
|
+
tokenAProgram,
|
|
8009
|
+
tokenBProgram
|
|
8010
|
+
);
|
|
7844
8011
|
if (tokenAMint.equals(_spltoken.NATIVE_MINT)) {
|
|
7845
8012
|
const wrapSOLIx = wrapSOLInstruction(
|
|
7846
8013
|
owner,
|
|
@@ -7864,11 +8031,7 @@ var CpAmm = class {
|
|
|
7864
8031
|
const closeWrappedSOLIx = yield unwrapSOLInstruction(owner);
|
|
7865
8032
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
7866
8033
|
}
|
|
7867
|
-
|
|
7868
|
-
liquidityDelta: liquidityDeltaQ64,
|
|
7869
|
-
tokenAAmountThreshold,
|
|
7870
|
-
tokenBAmountThreshold
|
|
7871
|
-
}).accountsStrict({
|
|
8034
|
+
const addLiquidityInstruction = yield this.buildAddLiquidityInstruction({
|
|
7872
8035
|
pool,
|
|
7873
8036
|
position,
|
|
7874
8037
|
positionNftAccount,
|
|
@@ -7881,9 +8044,15 @@ var CpAmm = class {
|
|
|
7881
8044
|
tokenBVault,
|
|
7882
8045
|
tokenAProgram,
|
|
7883
8046
|
tokenBProgram,
|
|
7884
|
-
|
|
7885
|
-
|
|
7886
|
-
|
|
8047
|
+
liquidityDelta: liquidityDeltaQ64,
|
|
8048
|
+
tokenAAmountThreshold,
|
|
8049
|
+
tokenBAmountThreshold
|
|
8050
|
+
});
|
|
8051
|
+
const transaction = new (0, _web3js.Transaction)();
|
|
8052
|
+
transaction.add(...preInstructions);
|
|
8053
|
+
transaction.add(addLiquidityInstruction);
|
|
8054
|
+
transaction.add(...postInstructions);
|
|
8055
|
+
return transaction;
|
|
7887
8056
|
});
|
|
7888
8057
|
}
|
|
7889
8058
|
/**
|
|
@@ -7913,30 +8082,17 @@ var CpAmm = class {
|
|
|
7913
8082
|
this._program.programId
|
|
7914
8083
|
);
|
|
7915
8084
|
const poolAuthority = derivePoolAuthority(this._program.programId);
|
|
7916
|
-
const
|
|
7917
|
-
|
|
7918
|
-
|
|
7919
|
-
|
|
7920
|
-
|
|
7921
|
-
|
|
7922
|
-
|
|
7923
|
-
|
|
7924
|
-
|
|
7925
|
-
|
|
7926
|
-
|
|
7927
|
-
tokenAProgram
|
|
7928
|
-
),
|
|
7929
|
-
getOrCreateATAInstruction(
|
|
7930
|
-
this._program.provider.connection,
|
|
7931
|
-
tokenBMint,
|
|
7932
|
-
owner,
|
|
7933
|
-
owner,
|
|
7934
|
-
true,
|
|
7935
|
-
tokenBProgram
|
|
7936
|
-
)
|
|
7937
|
-
]);
|
|
7938
|
-
createTokenAAccountIx && preInstructions.push(createTokenAAccountIx);
|
|
7939
|
-
createTokenBAccountIx && preInstructions.push(createTokenBAccountIx);
|
|
8085
|
+
const {
|
|
8086
|
+
tokenAAta: tokenAAccount,
|
|
8087
|
+
tokenBAta: tokenBAccount,
|
|
8088
|
+
instructions: preInstructions
|
|
8089
|
+
} = yield this.prepareTokenAccounts(
|
|
8090
|
+
owner,
|
|
8091
|
+
tokenAMint,
|
|
8092
|
+
tokenBMint,
|
|
8093
|
+
tokenAProgram,
|
|
8094
|
+
tokenBProgram
|
|
8095
|
+
);
|
|
7940
8096
|
const postInstructions = [];
|
|
7941
8097
|
if ([tokenAMint.toBase58(), tokenBMint.toBase58()].includes(
|
|
7942
8098
|
_spltoken.NATIVE_MINT.toBase58()
|
|
@@ -7948,7 +8104,7 @@ var CpAmm = class {
|
|
|
7948
8104
|
liquidityDelta: liquidityDeltaQ64,
|
|
7949
8105
|
tokenAAmountThreshold,
|
|
7950
8106
|
tokenBAmountThreshold
|
|
7951
|
-
}).
|
|
8107
|
+
}).accountsPartial({
|
|
7952
8108
|
poolAuthority,
|
|
7953
8109
|
pool,
|
|
7954
8110
|
position,
|
|
@@ -7961,9 +8117,7 @@ var CpAmm = class {
|
|
|
7961
8117
|
tokenAVault,
|
|
7962
8118
|
tokenBVault,
|
|
7963
8119
|
tokenAProgram,
|
|
7964
|
-
tokenBProgram
|
|
7965
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
7966
|
-
program: this._program.programId
|
|
8120
|
+
tokenBProgram
|
|
7967
8121
|
}).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
7968
8122
|
});
|
|
7969
8123
|
}
|
|
@@ -7993,30 +8147,17 @@ var CpAmm = class {
|
|
|
7993
8147
|
this._program.programId
|
|
7994
8148
|
);
|
|
7995
8149
|
const poolAuthority = derivePoolAuthority(this._program.programId);
|
|
7996
|
-
const
|
|
7997
|
-
|
|
7998
|
-
|
|
7999
|
-
|
|
8000
|
-
|
|
8001
|
-
|
|
8002
|
-
|
|
8003
|
-
|
|
8004
|
-
|
|
8005
|
-
|
|
8006
|
-
|
|
8007
|
-
tokenAProgram
|
|
8008
|
-
),
|
|
8009
|
-
getOrCreateATAInstruction(
|
|
8010
|
-
this._program.provider.connection,
|
|
8011
|
-
tokenBMint,
|
|
8012
|
-
owner,
|
|
8013
|
-
owner,
|
|
8014
|
-
true,
|
|
8015
|
-
tokenBProgram
|
|
8016
|
-
)
|
|
8017
|
-
]);
|
|
8018
|
-
createTokenAAccountIx && preInstructions.push(createTokenAAccountIx);
|
|
8019
|
-
createTokenBAccountIx && preInstructions.push(createTokenBAccountIx);
|
|
8150
|
+
const {
|
|
8151
|
+
tokenAAta: tokenAAccount,
|
|
8152
|
+
tokenBAta: tokenBAccount,
|
|
8153
|
+
instructions: preInstructions
|
|
8154
|
+
} = yield this.prepareTokenAccounts(
|
|
8155
|
+
owner,
|
|
8156
|
+
tokenAMint,
|
|
8157
|
+
tokenBMint,
|
|
8158
|
+
tokenAProgram,
|
|
8159
|
+
tokenBProgram
|
|
8160
|
+
);
|
|
8020
8161
|
const postInstructions = [];
|
|
8021
8162
|
if ([tokenAMint.toBase58(), tokenBMint.toBase58()].includes(
|
|
8022
8163
|
_spltoken.NATIVE_MINT.toBase58()
|
|
@@ -8024,21 +8165,28 @@ var CpAmm = class {
|
|
|
8024
8165
|
const closeWrappedSOLIx = yield unwrapSOLInstruction(owner);
|
|
8025
8166
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
8026
8167
|
}
|
|
8027
|
-
|
|
8168
|
+
const removeAllLiquidityInstruction = yield this.buildRemoveAllLiquidityInstruction({
|
|
8028
8169
|
poolAuthority,
|
|
8170
|
+
owner,
|
|
8029
8171
|
pool,
|
|
8030
8172
|
position,
|
|
8031
8173
|
positionNftAccount,
|
|
8032
|
-
owner,
|
|
8033
8174
|
tokenAAccount,
|
|
8034
8175
|
tokenBAccount,
|
|
8176
|
+
tokenAAmountThreshold,
|
|
8177
|
+
tokenBAmountThreshold,
|
|
8035
8178
|
tokenAMint,
|
|
8036
8179
|
tokenBMint,
|
|
8037
8180
|
tokenAVault,
|
|
8038
8181
|
tokenBVault,
|
|
8039
8182
|
tokenAProgram,
|
|
8040
8183
|
tokenBProgram
|
|
8041
|
-
})
|
|
8184
|
+
});
|
|
8185
|
+
const transaction = new (0, _web3js.Transaction)();
|
|
8186
|
+
transaction.add(...preInstructions);
|
|
8187
|
+
transaction.add(removeAllLiquidityInstruction);
|
|
8188
|
+
transaction.add(...postInstructions);
|
|
8189
|
+
return transaction;
|
|
8042
8190
|
});
|
|
8043
8191
|
}
|
|
8044
8192
|
/**
|
|
@@ -8064,30 +8212,20 @@ var CpAmm = class {
|
|
|
8064
8212
|
referralTokenAccount
|
|
8065
8213
|
} = params;
|
|
8066
8214
|
const poolAuthority = derivePoolAuthority(this._program.programId);
|
|
8067
|
-
const
|
|
8068
|
-
|
|
8069
|
-
|
|
8070
|
-
|
|
8071
|
-
|
|
8072
|
-
|
|
8073
|
-
|
|
8074
|
-
|
|
8075
|
-
|
|
8076
|
-
|
|
8077
|
-
|
|
8078
|
-
|
|
8079
|
-
|
|
8080
|
-
|
|
8081
|
-
this._program.provider.connection,
|
|
8082
|
-
outputTokenMint,
|
|
8083
|
-
payer,
|
|
8084
|
-
payer,
|
|
8085
|
-
true,
|
|
8086
|
-
tokenBProgram
|
|
8087
|
-
)
|
|
8088
|
-
]);
|
|
8089
|
-
createInputTokenAccountIx && preInstructions.push(createInputTokenAccountIx);
|
|
8090
|
-
createOutputTokenAccountIx && preInstructions.push(createOutputTokenAccountIx);
|
|
8215
|
+
const [inputTokenProgram, outputTokenProgram] = inputTokenMint.equals(
|
|
8216
|
+
tokenAMint
|
|
8217
|
+
) ? [tokenAProgram, tokenBProgram] : [tokenBProgram, tokenAProgram];
|
|
8218
|
+
const {
|
|
8219
|
+
tokenAAta: inputTokenAccount,
|
|
8220
|
+
tokenBAta: outputTokenAccount,
|
|
8221
|
+
instructions: preInstructions
|
|
8222
|
+
} = yield this.prepareTokenAccounts(
|
|
8223
|
+
payer,
|
|
8224
|
+
inputTokenMint,
|
|
8225
|
+
outputTokenMint,
|
|
8226
|
+
inputTokenProgram,
|
|
8227
|
+
outputTokenProgram
|
|
8228
|
+
);
|
|
8091
8229
|
if (inputTokenMint.equals(_spltoken.NATIVE_MINT)) {
|
|
8092
8230
|
const wrapSOLIx = wrapSOLInstruction(
|
|
8093
8231
|
payer,
|
|
@@ -8106,7 +8244,7 @@ var CpAmm = class {
|
|
|
8106
8244
|
return yield this._program.methods.swap({
|
|
8107
8245
|
amountIn,
|
|
8108
8246
|
minimumAmountOut
|
|
8109
|
-
}).
|
|
8247
|
+
}).accountsPartial({
|
|
8110
8248
|
poolAuthority,
|
|
8111
8249
|
pool,
|
|
8112
8250
|
payer,
|
|
@@ -8118,9 +8256,7 @@ var CpAmm = class {
|
|
|
8118
8256
|
tokenBMint,
|
|
8119
8257
|
tokenAProgram,
|
|
8120
8258
|
tokenBProgram,
|
|
8121
|
-
referralTokenAccount
|
|
8122
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
8123
|
-
program: this._program.programId
|
|
8259
|
+
referralTokenAccount
|
|
8124
8260
|
}).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
8125
8261
|
});
|
|
8126
8262
|
}
|
|
@@ -8155,16 +8291,14 @@ var CpAmm = class {
|
|
|
8155
8291
|
liquidityPerPeriod,
|
|
8156
8292
|
numberOfPeriod
|
|
8157
8293
|
};
|
|
8158
|
-
return yield this._program.methods.lockPosition(lockPositionParams).
|
|
8294
|
+
return yield this._program.methods.lockPosition(lockPositionParams).accountsPartial({
|
|
8159
8295
|
position,
|
|
8160
8296
|
positionNftAccount,
|
|
8161
8297
|
vesting: vestingAccount,
|
|
8162
8298
|
pool,
|
|
8163
8299
|
owner,
|
|
8164
8300
|
payer,
|
|
8165
|
-
systemProgram: _web3js.SystemProgram.programId
|
|
8166
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
8167
|
-
program: this._program.programId
|
|
8301
|
+
systemProgram: _web3js.SystemProgram.programId
|
|
8168
8302
|
}).transaction();
|
|
8169
8303
|
});
|
|
8170
8304
|
}
|
|
@@ -8180,13 +8314,11 @@ var CpAmm = class {
|
|
|
8180
8314
|
positionNftMint,
|
|
8181
8315
|
this._program.programId
|
|
8182
8316
|
);
|
|
8183
|
-
return yield this._program.methods.permanentLockPosition(unlockedLiquidity).
|
|
8317
|
+
return yield this._program.methods.permanentLockPosition(unlockedLiquidity).accountsPartial({
|
|
8184
8318
|
position,
|
|
8185
8319
|
positionNftAccount,
|
|
8186
8320
|
pool,
|
|
8187
|
-
owner
|
|
8188
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
8189
|
-
program: this._program.programId
|
|
8321
|
+
owner
|
|
8190
8322
|
}).transaction();
|
|
8191
8323
|
});
|
|
8192
8324
|
}
|
|
@@ -8202,7 +8334,7 @@ var CpAmm = class {
|
|
|
8202
8334
|
positionNftMint,
|
|
8203
8335
|
this._program.programId
|
|
8204
8336
|
);
|
|
8205
|
-
return yield this._program.methods.refreshVesting().
|
|
8337
|
+
return yield this._program.methods.refreshVesting().accountsPartial({
|
|
8206
8338
|
position,
|
|
8207
8339
|
positionNftAccount,
|
|
8208
8340
|
pool,
|
|
@@ -8242,30 +8374,17 @@ var CpAmm = class {
|
|
|
8242
8374
|
this._program.programId
|
|
8243
8375
|
);
|
|
8244
8376
|
const poolAuthority = derivePoolAuthority(this._program.programId);
|
|
8245
|
-
const
|
|
8246
|
-
|
|
8247
|
-
|
|
8248
|
-
|
|
8249
|
-
|
|
8250
|
-
|
|
8251
|
-
|
|
8252
|
-
|
|
8253
|
-
|
|
8254
|
-
|
|
8255
|
-
|
|
8256
|
-
tokenAProgram
|
|
8257
|
-
),
|
|
8258
|
-
getOrCreateATAInstruction(
|
|
8259
|
-
this._program.provider.connection,
|
|
8260
|
-
tokenBMint,
|
|
8261
|
-
owner,
|
|
8262
|
-
owner,
|
|
8263
|
-
true,
|
|
8264
|
-
tokenBProgram
|
|
8265
|
-
)
|
|
8266
|
-
]);
|
|
8267
|
-
createTokenAAccountIx && preInstructions.push(createTokenAAccountIx);
|
|
8268
|
-
createTokenBAccountIx && preInstructions.push(createTokenBAccountIx);
|
|
8377
|
+
const {
|
|
8378
|
+
tokenAAta: tokenAAccount,
|
|
8379
|
+
tokenBAta: tokenBAccount,
|
|
8380
|
+
instructions: preInstructions
|
|
8381
|
+
} = yield this.prepareTokenAccounts(
|
|
8382
|
+
owner,
|
|
8383
|
+
tokenAMint,
|
|
8384
|
+
tokenBMint,
|
|
8385
|
+
tokenAProgram,
|
|
8386
|
+
tokenBProgram
|
|
8387
|
+
);
|
|
8269
8388
|
const postInstructions = [];
|
|
8270
8389
|
if ([tokenAMint.toBase58(), tokenBMint.toBase58()].includes(
|
|
8271
8390
|
_spltoken.NATIVE_MINT.toBase58()
|
|
@@ -8273,9 +8392,9 @@ var CpAmm = class {
|
|
|
8273
8392
|
const closeWrappedSOLIx = yield unwrapSOLInstruction(owner);
|
|
8274
8393
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
8275
8394
|
}
|
|
8276
|
-
|
|
8277
|
-
poolAuthority,
|
|
8395
|
+
const claimPositionFeeInstruction = yield this.buildClaimPositionFeeInstruction({
|
|
8278
8396
|
owner,
|
|
8397
|
+
poolAuthority,
|
|
8279
8398
|
pool,
|
|
8280
8399
|
position,
|
|
8281
8400
|
positionNftAccount,
|
|
@@ -8286,10 +8405,13 @@ var CpAmm = class {
|
|
|
8286
8405
|
tokenAMint,
|
|
8287
8406
|
tokenBMint,
|
|
8288
8407
|
tokenAProgram,
|
|
8289
|
-
tokenBProgram
|
|
8290
|
-
|
|
8291
|
-
|
|
8292
|
-
|
|
8408
|
+
tokenBProgram
|
|
8409
|
+
});
|
|
8410
|
+
const transaction = new (0, _web3js.Transaction)();
|
|
8411
|
+
transaction.add(...preInstructions);
|
|
8412
|
+
transaction.add(claimPositionFeeInstruction);
|
|
8413
|
+
transaction.add(...postInstructions);
|
|
8414
|
+
return transaction;
|
|
8293
8415
|
});
|
|
8294
8416
|
}
|
|
8295
8417
|
closePosition(params) {
|
|
@@ -8300,16 +8422,241 @@ var CpAmm = class {
|
|
|
8300
8422
|
positionNftMint,
|
|
8301
8423
|
this._program.programId
|
|
8302
8424
|
);
|
|
8303
|
-
|
|
8425
|
+
const instruction = yield this.buildClosePositionInstruction({
|
|
8426
|
+
owner,
|
|
8427
|
+
poolAuthority,
|
|
8428
|
+
pool,
|
|
8429
|
+
position,
|
|
8304
8430
|
positionNftMint,
|
|
8431
|
+
positionNftAccount
|
|
8432
|
+
});
|
|
8433
|
+
return new (0, _web3js.Transaction)().add(instruction);
|
|
8434
|
+
});
|
|
8435
|
+
}
|
|
8436
|
+
/**
|
|
8437
|
+
* Builds a transaction to remove all liquidity from a position and close it.
|
|
8438
|
+
* This combines several operations in a single transaction:
|
|
8439
|
+
* 1. Claims any accumulated fees
|
|
8440
|
+
* 2. Removes all liquidity
|
|
8441
|
+
* 3. Closes the position
|
|
8442
|
+
*
|
|
8443
|
+
* @param {RemoveAllLiquidityAndClosePositionParams} params - Combined parameters
|
|
8444
|
+
* @returns {TxBuilder} Transaction builder with all required instructions
|
|
8445
|
+
* @throws {Error} If the position is locked or cannot be closed
|
|
8446
|
+
*/
|
|
8447
|
+
removeAllLiquidityAndClosePosition(params) {
|
|
8448
|
+
return __async(this, null, function* () {
|
|
8449
|
+
const {
|
|
8450
|
+
owner,
|
|
8451
|
+
position,
|
|
8452
|
+
positionState,
|
|
8453
|
+
poolState,
|
|
8454
|
+
tokenAAmountThreshold,
|
|
8455
|
+
tokenBAmountThreshold
|
|
8456
|
+
} = params;
|
|
8457
|
+
const { nftMint: positionNftMint, pool } = positionState;
|
|
8458
|
+
const { tokenAMint, tokenBMint, tokenAVault, tokenBVault } = poolState;
|
|
8459
|
+
const isLockedPosition = this.isLockedPosition(positionState);
|
|
8460
|
+
if (isLockedPosition) {
|
|
8461
|
+
throw Error("position must be unlocked");
|
|
8462
|
+
}
|
|
8463
|
+
const positionNftAccount = derivePositionNftAccount(
|
|
8464
|
+
positionNftMint,
|
|
8465
|
+
this._program.programId
|
|
8466
|
+
);
|
|
8467
|
+
const poolAuthority = derivePoolAuthority(this._program.programId);
|
|
8468
|
+
const tokenAProgram = getTokenProgram(poolState.tokenAFlag);
|
|
8469
|
+
const tokenBProgram = getTokenProgram(poolState.tokenBFlag);
|
|
8470
|
+
const {
|
|
8471
|
+
tokenAAta: tokenAAccount,
|
|
8472
|
+
tokenBAta: tokenBAccount,
|
|
8473
|
+
instructions: preInstructions
|
|
8474
|
+
} = yield this.prepareTokenAccounts(
|
|
8475
|
+
owner,
|
|
8476
|
+
tokenAMint,
|
|
8477
|
+
tokenBMint,
|
|
8478
|
+
tokenAProgram,
|
|
8479
|
+
tokenBProgram
|
|
8480
|
+
);
|
|
8481
|
+
const postInstructions = [];
|
|
8482
|
+
if ([tokenAMint.toBase58(), tokenBMint.toBase58()].includes(
|
|
8483
|
+
_spltoken.NATIVE_MINT.toBase58()
|
|
8484
|
+
)) {
|
|
8485
|
+
const closeWrappedSOLIx = yield unwrapSOLInstruction(owner);
|
|
8486
|
+
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
8487
|
+
}
|
|
8488
|
+
const transaction = new (0, _web3js.Transaction)();
|
|
8489
|
+
transaction.add(...preInstructions);
|
|
8490
|
+
const claimPositionFeeInstruction = yield this.buildClaimPositionFeeInstruction({
|
|
8491
|
+
owner,
|
|
8492
|
+
poolAuthority,
|
|
8493
|
+
pool,
|
|
8494
|
+
position,
|
|
8305
8495
|
positionNftAccount,
|
|
8496
|
+
tokenAAccount,
|
|
8497
|
+
tokenBAccount,
|
|
8498
|
+
tokenAVault,
|
|
8499
|
+
tokenBVault,
|
|
8500
|
+
tokenAMint,
|
|
8501
|
+
tokenBMint,
|
|
8502
|
+
tokenAProgram,
|
|
8503
|
+
tokenBProgram
|
|
8504
|
+
});
|
|
8505
|
+
transaction.add(claimPositionFeeInstruction);
|
|
8506
|
+
const removeAllLiquidityInstruction = yield this.buildRemoveAllLiquidityInstruction({
|
|
8507
|
+
poolAuthority,
|
|
8508
|
+
owner,
|
|
8306
8509
|
pool,
|
|
8307
8510
|
position,
|
|
8511
|
+
positionNftAccount,
|
|
8512
|
+
tokenAAccount,
|
|
8513
|
+
tokenBAccount,
|
|
8514
|
+
tokenAAmountThreshold,
|
|
8515
|
+
tokenBAmountThreshold,
|
|
8516
|
+
tokenAMint,
|
|
8517
|
+
tokenBMint,
|
|
8518
|
+
tokenAVault,
|
|
8519
|
+
tokenBVault,
|
|
8520
|
+
tokenAProgram,
|
|
8521
|
+
tokenBProgram
|
|
8522
|
+
});
|
|
8523
|
+
transaction.add(removeAllLiquidityInstruction);
|
|
8524
|
+
const closePositionInstruction = yield this.buildClosePositionInstruction({
|
|
8525
|
+
owner,
|
|
8308
8526
|
poolAuthority,
|
|
8309
|
-
|
|
8527
|
+
pool,
|
|
8528
|
+
position,
|
|
8529
|
+
positionNftMint,
|
|
8530
|
+
positionNftAccount
|
|
8531
|
+
});
|
|
8532
|
+
transaction.add(closePositionInstruction);
|
|
8533
|
+
return transaction;
|
|
8534
|
+
});
|
|
8535
|
+
}
|
|
8536
|
+
/**
|
|
8537
|
+
* Builds a transaction to merge liquidity from one position into another.
|
|
8538
|
+
* This process:
|
|
8539
|
+
* 1. Claims fees from the source position
|
|
8540
|
+
* 2. Removes all liquidity from the source position
|
|
8541
|
+
* 3. Adds that liquidity to the target position
|
|
8542
|
+
* 4. Closes the source position
|
|
8543
|
+
*
|
|
8544
|
+
* @param {MergePositionParams} params - Parameters for merging positions
|
|
8545
|
+
* @returns {TxBuilder} Transaction builder with all required instructions
|
|
8546
|
+
* @throws {Error} If either position is locked or incompatible
|
|
8547
|
+
*/
|
|
8548
|
+
mergePosition(params) {
|
|
8549
|
+
return __async(this, null, function* () {
|
|
8550
|
+
const {
|
|
8310
8551
|
owner,
|
|
8311
|
-
|
|
8312
|
-
|
|
8552
|
+
positionA,
|
|
8553
|
+
positionB,
|
|
8554
|
+
positionBState,
|
|
8555
|
+
positionAState,
|
|
8556
|
+
poolState,
|
|
8557
|
+
tokenAAmountThreshold,
|
|
8558
|
+
tokenBAmountThreshold
|
|
8559
|
+
} = params;
|
|
8560
|
+
const isLockedPosition = this.isLockedPosition(positionBState);
|
|
8561
|
+
if (isLockedPosition) {
|
|
8562
|
+
throw Error("position must be unlocked");
|
|
8563
|
+
}
|
|
8564
|
+
const postionBLiquidityDelta = positionBState.unlockedLiquidity;
|
|
8565
|
+
const pool = positionBState.pool;
|
|
8566
|
+
const { tokenAMint, tokenBMint, tokenAVault, tokenBVault } = poolState;
|
|
8567
|
+
const positionBNftAccount = derivePositionNftAccount(
|
|
8568
|
+
positionBState.nftMint,
|
|
8569
|
+
this._program.programId
|
|
8570
|
+
);
|
|
8571
|
+
const positionANftAccount = derivePositionNftAccount(
|
|
8572
|
+
positionAState.nftMint,
|
|
8573
|
+
this._program.programId
|
|
8574
|
+
);
|
|
8575
|
+
const poolAuthority = derivePoolAuthority(this._program.programId);
|
|
8576
|
+
const tokenAProgram = getTokenProgram(poolState.tokenAFlag);
|
|
8577
|
+
const tokenBProgram = getTokenProgram(poolState.tokenBFlag);
|
|
8578
|
+
const {
|
|
8579
|
+
tokenAAta: tokenAAccount,
|
|
8580
|
+
tokenBAta: tokenBAccount,
|
|
8581
|
+
instructions: preInstructions
|
|
8582
|
+
} = yield this.prepareTokenAccounts(
|
|
8583
|
+
owner,
|
|
8584
|
+
tokenAMint,
|
|
8585
|
+
tokenBMint,
|
|
8586
|
+
tokenAProgram,
|
|
8587
|
+
tokenBProgram
|
|
8588
|
+
);
|
|
8589
|
+
const postInstructions = [];
|
|
8590
|
+
if ([tokenAMint.toBase58(), tokenBMint.toBase58()].includes(
|
|
8591
|
+
_spltoken.NATIVE_MINT.toBase58()
|
|
8592
|
+
)) {
|
|
8593
|
+
const closeWrappedSOLIx = yield unwrapSOLInstruction(owner);
|
|
8594
|
+
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
8595
|
+
}
|
|
8596
|
+
const transaction = new (0, _web3js.Transaction)();
|
|
8597
|
+
transaction.add(...preInstructions);
|
|
8598
|
+
const claimPositionFeeInstruction = yield this.buildClaimPositionFeeInstruction({
|
|
8599
|
+
owner,
|
|
8600
|
+
poolAuthority,
|
|
8601
|
+
pool,
|
|
8602
|
+
position: positionB,
|
|
8603
|
+
positionNftAccount: positionBNftAccount,
|
|
8604
|
+
tokenAAccount,
|
|
8605
|
+
tokenBAccount,
|
|
8606
|
+
tokenAVault,
|
|
8607
|
+
tokenBVault,
|
|
8608
|
+
tokenAMint,
|
|
8609
|
+
tokenBMint,
|
|
8610
|
+
tokenAProgram,
|
|
8611
|
+
tokenBProgram
|
|
8612
|
+
});
|
|
8613
|
+
transaction.add(claimPositionFeeInstruction);
|
|
8614
|
+
const removeAllLiquidityInstruction = yield this.buildRemoveAllLiquidityInstruction({
|
|
8615
|
+
poolAuthority,
|
|
8616
|
+
owner,
|
|
8617
|
+
pool,
|
|
8618
|
+
position: positionB,
|
|
8619
|
+
positionNftAccount: positionBNftAccount,
|
|
8620
|
+
tokenAAccount,
|
|
8621
|
+
tokenBAccount,
|
|
8622
|
+
tokenAAmountThreshold,
|
|
8623
|
+
tokenBAmountThreshold,
|
|
8624
|
+
tokenAMint,
|
|
8625
|
+
tokenBMint,
|
|
8626
|
+
tokenAVault,
|
|
8627
|
+
tokenBVault,
|
|
8628
|
+
tokenAProgram,
|
|
8629
|
+
tokenBProgram
|
|
8630
|
+
});
|
|
8631
|
+
transaction.add(removeAllLiquidityInstruction);
|
|
8632
|
+
const addLiquidityInstruction = yield this.buildAddLiquidityInstruction({
|
|
8633
|
+
pool,
|
|
8634
|
+
position: positionA,
|
|
8635
|
+
positionNftAccount: positionANftAccount,
|
|
8636
|
+
owner,
|
|
8637
|
+
tokenAAccount,
|
|
8638
|
+
tokenBAccount,
|
|
8639
|
+
tokenAMint,
|
|
8640
|
+
tokenBMint,
|
|
8641
|
+
tokenAVault,
|
|
8642
|
+
tokenBVault,
|
|
8643
|
+
tokenAProgram,
|
|
8644
|
+
tokenBProgram,
|
|
8645
|
+
liquidityDelta: postionBLiquidityDelta,
|
|
8646
|
+
tokenAAmountThreshold,
|
|
8647
|
+
tokenBAmountThreshold
|
|
8648
|
+
});
|
|
8649
|
+
transaction.add(addLiquidityInstruction);
|
|
8650
|
+
const closePositionInstruction = yield this.buildClosePositionInstruction({
|
|
8651
|
+
owner,
|
|
8652
|
+
poolAuthority,
|
|
8653
|
+
pool: positionBState.pool,
|
|
8654
|
+
position: positionB,
|
|
8655
|
+
positionNftMint: positionBState.nftMint,
|
|
8656
|
+
positionNftAccount: positionBNftAccount
|
|
8657
|
+
});
|
|
8658
|
+
transaction.add(closePositionInstruction);
|
|
8659
|
+
return transaction;
|
|
8313
8660
|
});
|
|
8314
8661
|
}
|
|
8315
8662
|
/**
|
|
@@ -8320,11 +8667,9 @@ var CpAmm = class {
|
|
|
8320
8667
|
updateRewardDuration(params) {
|
|
8321
8668
|
return __async(this, null, function* () {
|
|
8322
8669
|
const { pool, admin, rewardIndex, newDuration } = params;
|
|
8323
|
-
return yield this._program.methods.updateRewardDuration(rewardIndex, newDuration).
|
|
8670
|
+
return yield this._program.methods.updateRewardDuration(rewardIndex, newDuration).accountsPartial({
|
|
8324
8671
|
pool,
|
|
8325
|
-
admin
|
|
8326
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
8327
|
-
program: this._program.programId
|
|
8672
|
+
admin
|
|
8328
8673
|
}).transaction();
|
|
8329
8674
|
});
|
|
8330
8675
|
}
|
|
@@ -8336,11 +8681,9 @@ var CpAmm = class {
|
|
|
8336
8681
|
updateRewardFunder(params) {
|
|
8337
8682
|
return __async(this, null, function* () {
|
|
8338
8683
|
const { pool, admin, rewardIndex, newFunder } = params;
|
|
8339
|
-
return yield this._program.methods.updateRewardFunder(rewardIndex, newFunder).
|
|
8684
|
+
return yield this._program.methods.updateRewardFunder(rewardIndex, newFunder).accountsPartial({
|
|
8340
8685
|
pool,
|
|
8341
|
-
admin
|
|
8342
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
8343
|
-
program: this._program.programId
|
|
8686
|
+
admin
|
|
8344
8687
|
}).transaction();
|
|
8345
8688
|
});
|
|
8346
8689
|
}
|
|
@@ -8374,15 +8717,13 @@ var CpAmm = class {
|
|
|
8374
8717
|
);
|
|
8375
8718
|
preInstructions.push(...wrapSOLIx);
|
|
8376
8719
|
}
|
|
8377
|
-
return yield this._program.methods.fundReward(rewardIndex, amount, carryForward).
|
|
8720
|
+
return yield this._program.methods.fundReward(rewardIndex, amount, carryForward).accountsPartial({
|
|
8378
8721
|
pool,
|
|
8379
8722
|
rewardVault: vault,
|
|
8380
8723
|
rewardMint: mint,
|
|
8381
8724
|
funderTokenAccount,
|
|
8382
8725
|
funder,
|
|
8383
|
-
tokenProgram
|
|
8384
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
8385
|
-
program: this._program.programId
|
|
8726
|
+
tokenProgram
|
|
8386
8727
|
}).transaction();
|
|
8387
8728
|
});
|
|
8388
8729
|
}
|
|
@@ -8414,16 +8755,14 @@ var CpAmm = class {
|
|
|
8414
8755
|
const closeWrappedSOLIx = yield unwrapSOLInstruction(funder);
|
|
8415
8756
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
8416
8757
|
}
|
|
8417
|
-
return yield this._program.methods.withdrawIneligibleReward(rewardIndex).
|
|
8758
|
+
return yield this._program.methods.withdrawIneligibleReward(rewardIndex).accountsPartial({
|
|
8418
8759
|
pool,
|
|
8419
8760
|
rewardVault: vault,
|
|
8420
8761
|
rewardMint: mint,
|
|
8421
8762
|
poolAuthority,
|
|
8422
8763
|
funderTokenAccount,
|
|
8423
8764
|
funder,
|
|
8424
|
-
tokenProgram
|
|
8425
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
8426
|
-
program: this._program.programId
|
|
8765
|
+
tokenProgram
|
|
8427
8766
|
}).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
8428
8767
|
});
|
|
8429
8768
|
}
|
|
@@ -8447,30 +8786,17 @@ var CpAmm = class {
|
|
|
8447
8786
|
const poolAuthority = derivePoolAuthority(this._program.programId);
|
|
8448
8787
|
const tokenAProgram = getTokenProgram(tokenAFlag);
|
|
8449
8788
|
const tokenBProgram = getTokenProgram(tokenBFlag);
|
|
8450
|
-
const
|
|
8451
|
-
|
|
8452
|
-
|
|
8453
|
-
|
|
8454
|
-
|
|
8455
|
-
|
|
8456
|
-
|
|
8457
|
-
|
|
8458
|
-
|
|
8459
|
-
|
|
8460
|
-
|
|
8461
|
-
tokenAProgram
|
|
8462
|
-
),
|
|
8463
|
-
getOrCreateATAInstruction(
|
|
8464
|
-
this._program.provider.connection,
|
|
8465
|
-
poolState.tokenBMint,
|
|
8466
|
-
partner,
|
|
8467
|
-
partner,
|
|
8468
|
-
true,
|
|
8469
|
-
tokenBProgram
|
|
8470
|
-
)
|
|
8471
|
-
]);
|
|
8472
|
-
createTokenAAccountIx && preInstructions.push(createTokenAAccountIx);
|
|
8473
|
-
createTokenBAccountIx && preInstructions.push(createTokenBAccountIx);
|
|
8789
|
+
const {
|
|
8790
|
+
tokenAAta: tokenAAccount,
|
|
8791
|
+
tokenBAta: tokenBAccount,
|
|
8792
|
+
instructions: preInstructions
|
|
8793
|
+
} = yield this.prepareTokenAccounts(
|
|
8794
|
+
partner,
|
|
8795
|
+
tokenAMint,
|
|
8796
|
+
tokenBMint,
|
|
8797
|
+
tokenAProgram,
|
|
8798
|
+
tokenBProgram
|
|
8799
|
+
);
|
|
8474
8800
|
const postInstructions = [];
|
|
8475
8801
|
if ([
|
|
8476
8802
|
poolState.tokenAMint.toBase58(),
|
|
@@ -8479,7 +8805,7 @@ var CpAmm = class {
|
|
|
8479
8805
|
const closeWrappedSOLIx = yield unwrapSOLInstruction(partner);
|
|
8480
8806
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
8481
8807
|
}
|
|
8482
|
-
return yield this._program.methods.claimPartnerFee(maxAmountA, maxAmountB).
|
|
8808
|
+
return yield this._program.methods.claimPartnerFee(maxAmountA, maxAmountB).accountsPartial({
|
|
8483
8809
|
poolAuthority,
|
|
8484
8810
|
pool,
|
|
8485
8811
|
tokenAAccount,
|
|
@@ -8490,9 +8816,7 @@ var CpAmm = class {
|
|
|
8490
8816
|
tokenBMint,
|
|
8491
8817
|
partner,
|
|
8492
8818
|
tokenAProgram,
|
|
8493
|
-
tokenBProgram
|
|
8494
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
8495
|
-
program: this._program.programId
|
|
8819
|
+
tokenBProgram
|
|
8496
8820
|
}).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
8497
8821
|
});
|
|
8498
8822
|
}
|
|
@@ -8528,7 +8852,7 @@ var CpAmm = class {
|
|
|
8528
8852
|
const closeWrappedSOLIx = yield unwrapSOLInstruction(user);
|
|
8529
8853
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
8530
8854
|
}
|
|
8531
|
-
return yield this._program.methods.claimReward(rewardIndex).
|
|
8855
|
+
return yield this._program.methods.claimReward(rewardIndex).accountsPartial({
|
|
8532
8856
|
pool: positionState.pool,
|
|
8533
8857
|
positionNftAccount,
|
|
8534
8858
|
rewardVault: rewardInfo.vault,
|
|
@@ -8537,9 +8861,7 @@ var CpAmm = class {
|
|
|
8537
8861
|
position,
|
|
8538
8862
|
userTokenAccount,
|
|
8539
8863
|
owner: user,
|
|
8540
|
-
tokenProgram
|
|
8541
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
8542
|
-
program: this._program.programId
|
|
8864
|
+
tokenProgram
|
|
8543
8865
|
}).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
8544
8866
|
});
|
|
8545
8867
|
}
|