@meteora-ag/cp-amm-sdk 1.0.1-rc.3 → 1.0.1-rc.30
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 +45 -200
- package/dist/index.d.mts +3149 -3417
- package/dist/index.d.ts +3149 -3417
- package/dist/index.js +1812 -684
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1856 -728
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __pow = Math.pow;
|
|
2
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
3
|
return new Promise((resolve, reject) => {
|
|
3
4
|
var fulfilled = (value) => {
|
|
4
5
|
try {
|
|
@@ -21,13 +22,8 @@
|
|
|
21
22
|
|
|
22
23
|
// src/CpAmm.ts
|
|
23
24
|
var _anchor = require('@coral-xyz/anchor');
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
25
|
var _spltoken = require('@solana/spl-token');
|
|
29
26
|
var _invariant = require('invariant'); var _invariant2 = _interopRequireDefault(_invariant);
|
|
30
|
-
var _decimaljs = require('decimal.js'); var _decimaljs2 = _interopRequireDefault(_decimaljs);
|
|
31
27
|
|
|
32
28
|
// src/idl/cp_amm.json
|
|
33
29
|
var cp_amm_default = {
|
|
@@ -1074,6 +1070,123 @@ var cp_amm_default = {
|
|
|
1074
1070
|
],
|
|
1075
1071
|
args: []
|
|
1076
1072
|
},
|
|
1073
|
+
{
|
|
1074
|
+
name: "close_position",
|
|
1075
|
+
discriminator: [
|
|
1076
|
+
123,
|
|
1077
|
+
134,
|
|
1078
|
+
81,
|
|
1079
|
+
0,
|
|
1080
|
+
49,
|
|
1081
|
+
68,
|
|
1082
|
+
98,
|
|
1083
|
+
98
|
|
1084
|
+
],
|
|
1085
|
+
accounts: [
|
|
1086
|
+
{
|
|
1087
|
+
name: "position_nft_mint",
|
|
1088
|
+
docs: [
|
|
1089
|
+
"position_nft_mint"
|
|
1090
|
+
],
|
|
1091
|
+
writable: true
|
|
1092
|
+
},
|
|
1093
|
+
{
|
|
1094
|
+
name: "position_nft_account",
|
|
1095
|
+
docs: [
|
|
1096
|
+
"The token account for nft"
|
|
1097
|
+
],
|
|
1098
|
+
writable: true
|
|
1099
|
+
},
|
|
1100
|
+
{
|
|
1101
|
+
name: "pool",
|
|
1102
|
+
writable: true,
|
|
1103
|
+
relations: [
|
|
1104
|
+
"position"
|
|
1105
|
+
]
|
|
1106
|
+
},
|
|
1107
|
+
{
|
|
1108
|
+
name: "position",
|
|
1109
|
+
writable: true
|
|
1110
|
+
},
|
|
1111
|
+
{
|
|
1112
|
+
name: "pool_authority",
|
|
1113
|
+
pda: {
|
|
1114
|
+
seeds: [
|
|
1115
|
+
{
|
|
1116
|
+
kind: "const",
|
|
1117
|
+
value: [
|
|
1118
|
+
112,
|
|
1119
|
+
111,
|
|
1120
|
+
111,
|
|
1121
|
+
108,
|
|
1122
|
+
95,
|
|
1123
|
+
97,
|
|
1124
|
+
117,
|
|
1125
|
+
116,
|
|
1126
|
+
104,
|
|
1127
|
+
111,
|
|
1128
|
+
114,
|
|
1129
|
+
105,
|
|
1130
|
+
116,
|
|
1131
|
+
121
|
|
1132
|
+
]
|
|
1133
|
+
}
|
|
1134
|
+
]
|
|
1135
|
+
}
|
|
1136
|
+
},
|
|
1137
|
+
{
|
|
1138
|
+
name: "rent_receiver",
|
|
1139
|
+
writable: true
|
|
1140
|
+
},
|
|
1141
|
+
{
|
|
1142
|
+
name: "owner",
|
|
1143
|
+
docs: [
|
|
1144
|
+
"Owner of position"
|
|
1145
|
+
],
|
|
1146
|
+
signer: true
|
|
1147
|
+
},
|
|
1148
|
+
{
|
|
1149
|
+
name: "token_program",
|
|
1150
|
+
docs: [
|
|
1151
|
+
"Program to create NFT mint/token account and transfer for token22 account"
|
|
1152
|
+
],
|
|
1153
|
+
address: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
|
|
1154
|
+
},
|
|
1155
|
+
{
|
|
1156
|
+
name: "event_authority",
|
|
1157
|
+
pda: {
|
|
1158
|
+
seeds: [
|
|
1159
|
+
{
|
|
1160
|
+
kind: "const",
|
|
1161
|
+
value: [
|
|
1162
|
+
95,
|
|
1163
|
+
95,
|
|
1164
|
+
101,
|
|
1165
|
+
118,
|
|
1166
|
+
101,
|
|
1167
|
+
110,
|
|
1168
|
+
116,
|
|
1169
|
+
95,
|
|
1170
|
+
97,
|
|
1171
|
+
117,
|
|
1172
|
+
116,
|
|
1173
|
+
104,
|
|
1174
|
+
111,
|
|
1175
|
+
114,
|
|
1176
|
+
105,
|
|
1177
|
+
116,
|
|
1178
|
+
121
|
|
1179
|
+
]
|
|
1180
|
+
}
|
|
1181
|
+
]
|
|
1182
|
+
}
|
|
1183
|
+
},
|
|
1184
|
+
{
|
|
1185
|
+
name: "program"
|
|
1186
|
+
}
|
|
1187
|
+
],
|
|
1188
|
+
args: []
|
|
1189
|
+
},
|
|
1077
1190
|
{
|
|
1078
1191
|
name: "create_claim_fee_operator",
|
|
1079
1192
|
discriminator: [
|
|
@@ -1165,7 +1278,7 @@ var cp_amm_default = {
|
|
|
1165
1278
|
{
|
|
1166
1279
|
name: "create_config",
|
|
1167
1280
|
docs: [
|
|
1168
|
-
"ADMIN FUNCTIONS
|
|
1281
|
+
"ADMIN FUNCTIONS /////"
|
|
1169
1282
|
],
|
|
1170
1283
|
discriminator: [
|
|
1171
1284
|
201,
|
|
@@ -3508,6 +3621,19 @@ var cp_amm_default = {
|
|
|
3508
3621
|
5
|
|
3509
3622
|
]
|
|
3510
3623
|
},
|
|
3624
|
+
{
|
|
3625
|
+
name: "EvtClosePosition",
|
|
3626
|
+
discriminator: [
|
|
3627
|
+
20,
|
|
3628
|
+
145,
|
|
3629
|
+
144,
|
|
3630
|
+
68,
|
|
3631
|
+
143,
|
|
3632
|
+
142,
|
|
3633
|
+
214,
|
|
3634
|
+
178
|
|
3635
|
+
]
|
|
3636
|
+
},
|
|
3511
3637
|
{
|
|
3512
3638
|
name: "EvtCreateClaimFeeOperator",
|
|
3513
3639
|
discriminator: [
|
|
@@ -3899,6 +4025,11 @@ var cp_amm_default = {
|
|
|
3899
4025
|
code: 6038,
|
|
3900
4026
|
name: "FeeInverseIsIncorrect",
|
|
3901
4027
|
msg: "Fee inverse is incorrect"
|
|
4028
|
+
},
|
|
4029
|
+
{
|
|
4030
|
+
code: 6039,
|
|
4031
|
+
name: "PositionIsNotEmpty",
|
|
4032
|
+
msg: "Position is not empty"
|
|
3902
4033
|
}
|
|
3903
4034
|
],
|
|
3904
4035
|
types: [
|
|
@@ -4412,6 +4543,14 @@ var cp_amm_default = {
|
|
|
4412
4543
|
}
|
|
4413
4544
|
}
|
|
4414
4545
|
},
|
|
4546
|
+
{
|
|
4547
|
+
name: "token_a_amount",
|
|
4548
|
+
type: "u64"
|
|
4549
|
+
},
|
|
4550
|
+
{
|
|
4551
|
+
name: "token_b_amount",
|
|
4552
|
+
type: "u64"
|
|
4553
|
+
},
|
|
4415
4554
|
{
|
|
4416
4555
|
name: "total_amount_a",
|
|
4417
4556
|
type: "u64"
|
|
@@ -4567,6 +4706,30 @@ var cp_amm_default = {
|
|
|
4567
4706
|
]
|
|
4568
4707
|
}
|
|
4569
4708
|
},
|
|
4709
|
+
{
|
|
4710
|
+
name: "EvtClosePosition",
|
|
4711
|
+
type: {
|
|
4712
|
+
kind: "struct",
|
|
4713
|
+
fields: [
|
|
4714
|
+
{
|
|
4715
|
+
name: "pool",
|
|
4716
|
+
type: "pubkey"
|
|
4717
|
+
},
|
|
4718
|
+
{
|
|
4719
|
+
name: "owner",
|
|
4720
|
+
type: "pubkey"
|
|
4721
|
+
},
|
|
4722
|
+
{
|
|
4723
|
+
name: "position",
|
|
4724
|
+
type: "pubkey"
|
|
4725
|
+
},
|
|
4726
|
+
{
|
|
4727
|
+
name: "position_nft_mint",
|
|
4728
|
+
type: "pubkey"
|
|
4729
|
+
}
|
|
4730
|
+
]
|
|
4731
|
+
}
|
|
4732
|
+
},
|
|
4570
4733
|
{
|
|
4571
4734
|
name: "EvtCreateClaimFeeOperator",
|
|
4572
4735
|
docs: [
|
|
@@ -4709,6 +4872,10 @@ var cp_amm_default = {
|
|
|
4709
4872
|
type: {
|
|
4710
4873
|
kind: "struct",
|
|
4711
4874
|
fields: [
|
|
4875
|
+
{
|
|
4876
|
+
name: "pool",
|
|
4877
|
+
type: "pubkey"
|
|
4878
|
+
},
|
|
4712
4879
|
{
|
|
4713
4880
|
name: "token_a_mint",
|
|
4714
4881
|
type: "pubkey"
|
|
@@ -4773,6 +4940,14 @@ var cp_amm_default = {
|
|
|
4773
4940
|
name: "token_b_flag",
|
|
4774
4941
|
type: "u8"
|
|
4775
4942
|
},
|
|
4943
|
+
{
|
|
4944
|
+
name: "token_a_amount",
|
|
4945
|
+
type: "u64"
|
|
4946
|
+
},
|
|
4947
|
+
{
|
|
4948
|
+
name: "token_b_amount",
|
|
4949
|
+
type: "u64"
|
|
4950
|
+
},
|
|
4776
4951
|
{
|
|
4777
4952
|
name: "total_amount_a",
|
|
4778
4953
|
type: "u64"
|
|
@@ -4874,11 +5049,11 @@ var cp_amm_default = {
|
|
|
4874
5049
|
type: "pubkey"
|
|
4875
5050
|
},
|
|
4876
5051
|
{
|
|
4877
|
-
name: "
|
|
5052
|
+
name: "lock_liquidity_amount",
|
|
4878
5053
|
type: "u128"
|
|
4879
5054
|
},
|
|
4880
5055
|
{
|
|
4881
|
-
name: "
|
|
5056
|
+
name: "total_permanent_locked_liquidity",
|
|
4882
5057
|
type: "u128"
|
|
4883
5058
|
}
|
|
4884
5059
|
]
|
|
@@ -4910,11 +5085,11 @@ var cp_amm_default = {
|
|
|
4910
5085
|
}
|
|
4911
5086
|
},
|
|
4912
5087
|
{
|
|
4913
|
-
name: "
|
|
5088
|
+
name: "token_a_amount",
|
|
4914
5089
|
type: "u64"
|
|
4915
5090
|
},
|
|
4916
5091
|
{
|
|
4917
|
-
name: "
|
|
5092
|
+
name: "token_b_amount",
|
|
4918
5093
|
type: "u64"
|
|
4919
5094
|
}
|
|
4920
5095
|
]
|
|
@@ -4950,7 +5125,7 @@ var cp_amm_default = {
|
|
|
4950
5125
|
type: "u8"
|
|
4951
5126
|
},
|
|
4952
5127
|
{
|
|
4953
|
-
name: "
|
|
5128
|
+
name: "has_referral",
|
|
4954
5129
|
type: "bool"
|
|
4955
5130
|
},
|
|
4956
5131
|
{
|
|
@@ -4970,7 +5145,7 @@ var cp_amm_default = {
|
|
|
4970
5145
|
}
|
|
4971
5146
|
},
|
|
4972
5147
|
{
|
|
4973
|
-
name: "
|
|
5148
|
+
name: "actual_amount_in",
|
|
4974
5149
|
type: "u64"
|
|
4975
5150
|
},
|
|
4976
5151
|
{
|
|
@@ -6177,25 +6352,62 @@ var cp_amm_default = {
|
|
|
6177
6352
|
// src/CpAmm.ts
|
|
6178
6353
|
|
|
6179
6354
|
|
|
6355
|
+
|
|
6180
6356
|
var _web3js = require('@solana/web3.js');
|
|
6181
6357
|
|
|
6358
|
+
// src/types.ts
|
|
6359
|
+
var Rounding = /* @__PURE__ */ ((Rounding2) => {
|
|
6360
|
+
Rounding2[Rounding2["Up"] = 0] = "Up";
|
|
6361
|
+
Rounding2[Rounding2["Down"] = 1] = "Down";
|
|
6362
|
+
return Rounding2;
|
|
6363
|
+
})(Rounding || {});
|
|
6364
|
+
var ActivationPoint = /* @__PURE__ */ ((ActivationPoint2) => {
|
|
6365
|
+
ActivationPoint2[ActivationPoint2["Timestamp"] = 0] = "Timestamp";
|
|
6366
|
+
ActivationPoint2[ActivationPoint2["Slot"] = 1] = "Slot";
|
|
6367
|
+
return ActivationPoint2;
|
|
6368
|
+
})(ActivationPoint || {});
|
|
6369
|
+
var FeeSchedulerMode = /* @__PURE__ */ ((FeeSchedulerMode2) => {
|
|
6370
|
+
FeeSchedulerMode2[FeeSchedulerMode2["Linear"] = 0] = "Linear";
|
|
6371
|
+
FeeSchedulerMode2[FeeSchedulerMode2["Exponential"] = 1] = "Exponential";
|
|
6372
|
+
return FeeSchedulerMode2;
|
|
6373
|
+
})(FeeSchedulerMode || {});
|
|
6374
|
+
var CollectFeeMode = /* @__PURE__ */ ((CollectFeeMode3) => {
|
|
6375
|
+
CollectFeeMode3[CollectFeeMode3["BothToken"] = 0] = "BothToken";
|
|
6376
|
+
CollectFeeMode3[CollectFeeMode3["OnlyB"] = 1] = "OnlyB";
|
|
6377
|
+
return CollectFeeMode3;
|
|
6378
|
+
})(CollectFeeMode || {});
|
|
6379
|
+
var TradeDirection = /* @__PURE__ */ ((TradeDirection2) => {
|
|
6380
|
+
TradeDirection2[TradeDirection2["AtoB"] = 0] = "AtoB";
|
|
6381
|
+
TradeDirection2[TradeDirection2["BtoA"] = 1] = "BtoA";
|
|
6382
|
+
return TradeDirection2;
|
|
6383
|
+
})(TradeDirection || {});
|
|
6384
|
+
var ActivationType = /* @__PURE__ */ ((ActivationType2) => {
|
|
6385
|
+
ActivationType2[ActivationType2["Slot"] = 0] = "Slot";
|
|
6386
|
+
ActivationType2[ActivationType2["Timestamp"] = 1] = "Timestamp";
|
|
6387
|
+
return ActivationType2;
|
|
6388
|
+
})(ActivationType || {});
|
|
6389
|
+
|
|
6390
|
+
// src/pda.ts
|
|
6391
|
+
|
|
6392
|
+
|
|
6182
6393
|
// src/constants.ts
|
|
6183
6394
|
|
|
6184
6395
|
|
|
6185
6396
|
var CP_AMM_PROGRAM_ID = new (0, _web3js.PublicKey)(
|
|
6186
6397
|
"cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG"
|
|
6187
6398
|
);
|
|
6399
|
+
var LIQUIDITY_SCALE = 128;
|
|
6188
6400
|
var SCALE_OFFSET = 64;
|
|
6189
6401
|
var BASIS_POINT_MAX = 1e4;
|
|
6190
6402
|
var MAX_FEE_NUMERATOR = 5e8;
|
|
6191
6403
|
var FEE_DENOMINATOR = 1e9;
|
|
6404
|
+
var PRECISION = 1e6;
|
|
6192
6405
|
var MIN_SQRT_PRICE = new (0, _anchor.BN)("4295048016");
|
|
6193
6406
|
var MAX_SQRT_PRICE = new (0, _anchor.BN)("79226673521066979257578248091");
|
|
6194
6407
|
var MIN_CU_BUFFER = 5e4;
|
|
6195
6408
|
var MAX_CU_BUFFER = 2e5;
|
|
6196
6409
|
|
|
6197
6410
|
// src/pda.ts
|
|
6198
|
-
|
|
6199
6411
|
function getFirstKey(key1, key2) {
|
|
6200
6412
|
const buf1 = key1.toBuffer();
|
|
6201
6413
|
const buf2 = key2.toBuffer();
|
|
@@ -6212,19 +6424,19 @@ function getSecondKey(key1, key2) {
|
|
|
6212
6424
|
}
|
|
6213
6425
|
return buf1;
|
|
6214
6426
|
}
|
|
6215
|
-
function derivePoolAuthority(
|
|
6427
|
+
function derivePoolAuthority() {
|
|
6216
6428
|
return _web3js.PublicKey.findProgramAddressSync(
|
|
6217
6429
|
[Buffer.from("pool_authority")],
|
|
6218
|
-
|
|
6430
|
+
CP_AMM_PROGRAM_ID
|
|
6219
6431
|
)[0];
|
|
6220
6432
|
}
|
|
6221
|
-
function deriveConfigAddress(index
|
|
6433
|
+
function deriveConfigAddress(index) {
|
|
6222
6434
|
return _web3js.PublicKey.findProgramAddressSync(
|
|
6223
6435
|
[Buffer.from("config"), index.toArrayLike(Buffer, "le", 8)],
|
|
6224
|
-
|
|
6436
|
+
CP_AMM_PROGRAM_ID
|
|
6225
6437
|
)[0];
|
|
6226
6438
|
}
|
|
6227
|
-
function derivePoolAddress(config, tokenAMint, tokenBMint
|
|
6439
|
+
function derivePoolAddress(config, tokenAMint, tokenBMint) {
|
|
6228
6440
|
return _web3js.PublicKey.findProgramAddressSync(
|
|
6229
6441
|
[
|
|
6230
6442
|
Buffer.from("pool"),
|
|
@@ -6232,124 +6444,67 @@ function derivePoolAddress(config, tokenAMint, tokenBMint, programId) {
|
|
|
6232
6444
|
getFirstKey(tokenAMint, tokenBMint),
|
|
6233
6445
|
getSecondKey(tokenAMint, tokenBMint)
|
|
6234
6446
|
],
|
|
6235
|
-
|
|
6447
|
+
CP_AMM_PROGRAM_ID
|
|
6236
6448
|
)[0];
|
|
6237
6449
|
}
|
|
6238
|
-
function derivePositionAddress(positionNft
|
|
6450
|
+
function derivePositionAddress(positionNft) {
|
|
6239
6451
|
return _web3js.PublicKey.findProgramAddressSync(
|
|
6240
6452
|
[Buffer.from("position"), positionNft.toBuffer()],
|
|
6241
|
-
|
|
6453
|
+
CP_AMM_PROGRAM_ID
|
|
6242
6454
|
)[0];
|
|
6243
6455
|
}
|
|
6244
|
-
function deriveTokenVaultAddress(tokenMint, pool
|
|
6456
|
+
function deriveTokenVaultAddress(tokenMint, pool) {
|
|
6245
6457
|
return _web3js.PublicKey.findProgramAddressSync(
|
|
6246
6458
|
[Buffer.from("token_vault"), tokenMint.toBuffer(), pool.toBuffer()],
|
|
6247
|
-
|
|
6459
|
+
CP_AMM_PROGRAM_ID
|
|
6248
6460
|
)[0];
|
|
6249
6461
|
}
|
|
6250
|
-
function deriveRewardVaultAddress(pool, rewardIndex
|
|
6462
|
+
function deriveRewardVaultAddress(pool, rewardIndex) {
|
|
6251
6463
|
return _web3js.PublicKey.findProgramAddressSync(
|
|
6252
6464
|
[Buffer.from("reward_vault"), pool.toBuffer(), Buffer.from([rewardIndex])],
|
|
6253
|
-
|
|
6465
|
+
CP_AMM_PROGRAM_ID
|
|
6254
6466
|
)[0];
|
|
6255
6467
|
}
|
|
6256
|
-
function deriveCustomizablePoolAddress(tokenAMint, tokenBMint
|
|
6468
|
+
function deriveCustomizablePoolAddress(tokenAMint, tokenBMint) {
|
|
6257
6469
|
return _web3js.PublicKey.findProgramAddressSync(
|
|
6258
6470
|
[
|
|
6259
6471
|
Buffer.from("cpool"),
|
|
6260
6472
|
getFirstKey(tokenAMint, tokenBMint),
|
|
6261
6473
|
getSecondKey(tokenAMint, tokenBMint)
|
|
6262
6474
|
],
|
|
6263
|
-
|
|
6475
|
+
CP_AMM_PROGRAM_ID
|
|
6264
6476
|
)[0];
|
|
6265
6477
|
}
|
|
6266
|
-
function deriveTokenBadgeAddress(tokenMint
|
|
6478
|
+
function deriveTokenBadgeAddress(tokenMint) {
|
|
6267
6479
|
return _web3js.PublicKey.findProgramAddressSync(
|
|
6268
6480
|
[Buffer.from("token_badge"), tokenMint.toBuffer()],
|
|
6269
|
-
|
|
6481
|
+
CP_AMM_PROGRAM_ID
|
|
6270
6482
|
)[0];
|
|
6271
6483
|
}
|
|
6272
|
-
function deriveClaimFeeOperatorAddress(operator
|
|
6484
|
+
function deriveClaimFeeOperatorAddress(operator) {
|
|
6273
6485
|
return _web3js.PublicKey.findProgramAddressSync(
|
|
6274
6486
|
[Buffer.from("cf_operator"), operator.toBuffer()],
|
|
6275
|
-
|
|
6487
|
+
CP_AMM_PROGRAM_ID
|
|
6276
6488
|
)[0];
|
|
6277
6489
|
}
|
|
6278
|
-
function derivePositionNftAccount(positionNftMint
|
|
6490
|
+
function derivePositionNftAccount(positionNftMint) {
|
|
6279
6491
|
return _web3js.PublicKey.findProgramAddressSync(
|
|
6280
6492
|
[Buffer.from("position_nft_account"), positionNftMint.toBuffer()],
|
|
6281
|
-
|
|
6493
|
+
CP_AMM_PROGRAM_ID
|
|
6282
6494
|
)[0];
|
|
6283
6495
|
}
|
|
6284
|
-
function
|
|
6496
|
+
function deriveTokenBadge(tokenMint) {
|
|
6285
6497
|
return _web3js.PublicKey.findProgramAddressSync(
|
|
6286
|
-
[Buffer.from("
|
|
6287
|
-
|
|
6288
|
-
);
|
|
6498
|
+
[Buffer.from("token_badge"), tokenMint.toBuffer()],
|
|
6499
|
+
CP_AMM_PROGRAM_ID
|
|
6500
|
+
)[0];
|
|
6289
6501
|
}
|
|
6290
6502
|
|
|
6291
|
-
// src/
|
|
6503
|
+
// src/helpers/token.ts
|
|
6504
|
+
var _bytes = require('@coral-xyz/anchor/dist/cjs/utils/bytes');
|
|
6292
6505
|
|
|
6293
6506
|
|
|
6294
6507
|
|
|
6295
|
-
// src/types.ts
|
|
6296
|
-
var Rounding = /* @__PURE__ */ ((Rounding2) => {
|
|
6297
|
-
Rounding2[Rounding2["Up"] = 0] = "Up";
|
|
6298
|
-
Rounding2[Rounding2["Down"] = 1] = "Down";
|
|
6299
|
-
return Rounding2;
|
|
6300
|
-
})(Rounding || {});
|
|
6301
|
-
var ActivationPoint = /* @__PURE__ */ ((ActivationPoint2) => {
|
|
6302
|
-
ActivationPoint2[ActivationPoint2["Timestamp"] = 0] = "Timestamp";
|
|
6303
|
-
ActivationPoint2[ActivationPoint2["Slot"] = 1] = "Slot";
|
|
6304
|
-
return ActivationPoint2;
|
|
6305
|
-
})(ActivationPoint || {});
|
|
6306
|
-
var FeeSchedulerMode = /* @__PURE__ */ ((FeeSchedulerMode2) => {
|
|
6307
|
-
FeeSchedulerMode2[FeeSchedulerMode2["Linear"] = 0] = "Linear";
|
|
6308
|
-
FeeSchedulerMode2[FeeSchedulerMode2["Exponential"] = 1] = "Exponential";
|
|
6309
|
-
return FeeSchedulerMode2;
|
|
6310
|
-
})(FeeSchedulerMode || {});
|
|
6311
|
-
var CollectFeeMode = /* @__PURE__ */ ((CollectFeeMode2) => {
|
|
6312
|
-
CollectFeeMode2[CollectFeeMode2["BothToken"] = 0] = "BothToken";
|
|
6313
|
-
CollectFeeMode2[CollectFeeMode2["OnlyB"] = 1] = "OnlyB";
|
|
6314
|
-
return CollectFeeMode2;
|
|
6315
|
-
})(CollectFeeMode || {});
|
|
6316
|
-
var TradeDirection = /* @__PURE__ */ ((TradeDirection2) => {
|
|
6317
|
-
TradeDirection2[TradeDirection2["AtoB"] = 0] = "AtoB";
|
|
6318
|
-
TradeDirection2[TradeDirection2["BtoA"] = 1] = "BtoA";
|
|
6319
|
-
return TradeDirection2;
|
|
6320
|
-
})(TradeDirection || {});
|
|
6321
|
-
var ActivationType = /* @__PURE__ */ ((ActivationType2) => {
|
|
6322
|
-
ActivationType2[ActivationType2["Slot"] = 0] = "Slot";
|
|
6323
|
-
ActivationType2[ActivationType2["Timestamp"] = 1] = "Timestamp";
|
|
6324
|
-
return ActivationType2;
|
|
6325
|
-
})(ActivationType || {});
|
|
6326
|
-
|
|
6327
|
-
// src/math/index.ts
|
|
6328
|
-
function mulDiv(x, y, denominator, rounding) {
|
|
6329
|
-
const { div, mod } = x.mul(y).divmod(denominator);
|
|
6330
|
-
if (rounding == 0 /* Up */ && !mod.isZero()) {
|
|
6331
|
-
return div.add(new (0, _anchor.BN)(1));
|
|
6332
|
-
}
|
|
6333
|
-
return div;
|
|
6334
|
-
}
|
|
6335
|
-
function divCeil(a, b) {
|
|
6336
|
-
if (a.isZero()) {
|
|
6337
|
-
return new (0, _anchor.BN)(0);
|
|
6338
|
-
}
|
|
6339
|
-
return a.add(b.sub(new (0, _anchor.BN)(1))).div(b);
|
|
6340
|
-
}
|
|
6341
|
-
function decimalToQ64(num) {
|
|
6342
|
-
return new (0, _anchor.BN)(num.mul(_decimaljs2.default.pow(2, 64)).floor().toFixed());
|
|
6343
|
-
}
|
|
6344
|
-
function priceToSqrtPrice(initPrice, tokenADecimal, tokenBDecimal) {
|
|
6345
|
-
const sqrtPriceQ64 = decimalToQ64(
|
|
6346
|
-
initPrice.mul(_decimaljs2.default.pow(10, tokenBDecimal - tokenADecimal)).sqrt()
|
|
6347
|
-
);
|
|
6348
|
-
return sqrtPriceQ64;
|
|
6349
|
-
}
|
|
6350
|
-
|
|
6351
|
-
// src/utils/token.ts
|
|
6352
|
-
|
|
6353
6508
|
|
|
6354
6509
|
|
|
6355
6510
|
|
|
@@ -6435,8 +6590,52 @@ var unwrapSOLInstruction = (owner, allowOwnerOffCurve = true) => __async(void 0,
|
|
|
6435
6590
|
}
|
|
6436
6591
|
return null;
|
|
6437
6592
|
});
|
|
6593
|
+
function getNftOwner(connection, nftMint) {
|
|
6594
|
+
return __async(this, null, function* () {
|
|
6595
|
+
const largesTokenAccount = yield connection.getTokenLargestAccounts(nftMint);
|
|
6596
|
+
const accountInfo = yield connection.getParsedAccountInfo(
|
|
6597
|
+
largesTokenAccount.value[0].address
|
|
6598
|
+
);
|
|
6599
|
+
const owner = new (0, _web3js.PublicKey)(accountInfo.value.data.parsed.info.owner);
|
|
6600
|
+
return new (0, _web3js.PublicKey)(owner);
|
|
6601
|
+
});
|
|
6602
|
+
}
|
|
6603
|
+
function getAllUserPositionNftAccount(connection, user) {
|
|
6604
|
+
return __async(this, null, function* () {
|
|
6605
|
+
const filters = [
|
|
6606
|
+
{
|
|
6607
|
+
memcmp: {
|
|
6608
|
+
offset: 32,
|
|
6609
|
+
bytes: user.toBase58()
|
|
6610
|
+
}
|
|
6611
|
+
},
|
|
6612
|
+
{
|
|
6613
|
+
memcmp: {
|
|
6614
|
+
offset: 64,
|
|
6615
|
+
bytes: _bytes.bs58.encode(Buffer.from([1, 0, 0, 0, 0, 0, 0, 0]))
|
|
6616
|
+
// 1
|
|
6617
|
+
}
|
|
6618
|
+
}
|
|
6619
|
+
];
|
|
6620
|
+
const tokenAccountsRaw = yield connection.getProgramAccounts(
|
|
6621
|
+
_spltoken.TOKEN_2022_PROGRAM_ID,
|
|
6622
|
+
{
|
|
6623
|
+
filters
|
|
6624
|
+
}
|
|
6625
|
+
);
|
|
6626
|
+
const userPositionNftAccount = [];
|
|
6627
|
+
for (const { account, pubkey } of tokenAccountsRaw) {
|
|
6628
|
+
const tokenAccountData = _spltoken.AccountLayout.decode(account.data);
|
|
6629
|
+
userPositionNftAccount.push({
|
|
6630
|
+
positionNft: tokenAccountData.mint,
|
|
6631
|
+
positionNftAccount: pubkey
|
|
6632
|
+
});
|
|
6633
|
+
}
|
|
6634
|
+
return userPositionNftAccount;
|
|
6635
|
+
});
|
|
6636
|
+
}
|
|
6438
6637
|
|
|
6439
|
-
// src/
|
|
6638
|
+
// src/helpers/fee.ts
|
|
6440
6639
|
|
|
6441
6640
|
|
|
6442
6641
|
// src/math/feeMath.ts
|
|
@@ -6543,7 +6742,111 @@ function pow(base, exp) {
|
|
|
6543
6742
|
return result;
|
|
6544
6743
|
}
|
|
6545
6744
|
|
|
6546
|
-
// src/
|
|
6745
|
+
// src/math/mathUtils.ts
|
|
6746
|
+
|
|
6747
|
+
var _decimaljs = require('decimal.js'); var _decimaljs2 = _interopRequireDefault(_decimaljs);
|
|
6748
|
+
function mulShr(x, y, offset, rounding) {
|
|
6749
|
+
const denominator = new (0, _anchor.BN)(1).shln(offset);
|
|
6750
|
+
return mulDiv(x, y, denominator, rounding);
|
|
6751
|
+
}
|
|
6752
|
+
function shlDiv(x, y, offset, rounding) {
|
|
6753
|
+
const scale = new (0, _anchor.BN)(1).shln(offset);
|
|
6754
|
+
return mulDiv(x, scale, y, rounding);
|
|
6755
|
+
}
|
|
6756
|
+
function mulDiv(x, y, denominator, rounding) {
|
|
6757
|
+
const { div, mod } = x.mul(y).divmod(denominator);
|
|
6758
|
+
if (rounding == 0 /* Up */ && !mod.isZero()) {
|
|
6759
|
+
return div.add(new (0, _anchor.BN)(1));
|
|
6760
|
+
}
|
|
6761
|
+
return div;
|
|
6762
|
+
}
|
|
6763
|
+
function divCeil(a, b) {
|
|
6764
|
+
if (a.isZero()) {
|
|
6765
|
+
return new (0, _anchor.BN)(0);
|
|
6766
|
+
}
|
|
6767
|
+
return a.add(b.sub(new (0, _anchor.BN)(1))).div(b);
|
|
6768
|
+
}
|
|
6769
|
+
function q64ToDecimal(num, decimalPlaces) {
|
|
6770
|
+
return new (0, _decimaljs2.default)(num.toString()).div(_decimaljs2.default.pow(2, 64)).toDecimalPlaces(decimalPlaces);
|
|
6771
|
+
}
|
|
6772
|
+
function decimalToQ64(num) {
|
|
6773
|
+
return new (0, _anchor.BN)(num.mul(_decimaljs2.default.pow(2, 64)).floor().toFixed());
|
|
6774
|
+
}
|
|
6775
|
+
|
|
6776
|
+
// src/helpers/curve.ts
|
|
6777
|
+
|
|
6778
|
+
|
|
6779
|
+
function getNextSqrtPrice(amount, sqrtPrice, liquidity, aToB) {
|
|
6780
|
+
let result;
|
|
6781
|
+
if (aToB) {
|
|
6782
|
+
const product = amount.mul(sqrtPrice);
|
|
6783
|
+
const denominator = liquidity.add(product);
|
|
6784
|
+
result = mulDiv(liquidity, sqrtPrice, denominator, 0 /* Up */);
|
|
6785
|
+
} else {
|
|
6786
|
+
const quotient = amount.shln(SCALE_OFFSET * 2).div(liquidity);
|
|
6787
|
+
result = sqrtPrice.add(quotient);
|
|
6788
|
+
}
|
|
6789
|
+
return result;
|
|
6790
|
+
}
|
|
6791
|
+
function getDeltaAmountA(lowerSqrtPrice, upperSqrtPrice, liquidity, rounding) {
|
|
6792
|
+
const deltaSqrtPrice = upperSqrtPrice.sub(lowerSqrtPrice);
|
|
6793
|
+
const prod = liquidity.mul(deltaSqrtPrice);
|
|
6794
|
+
const denominator = lowerSqrtPrice.mul(upperSqrtPrice);
|
|
6795
|
+
const result = shlDiv(prod, denominator, SCALE_OFFSET, rounding);
|
|
6796
|
+
return result.shrn(SCALE_OFFSET);
|
|
6797
|
+
}
|
|
6798
|
+
function getDeltaAmountB(lowerSqrtPrice, upperSqrtPrice, liquidity, rounding) {
|
|
6799
|
+
const deltaSqrtPrice = upperSqrtPrice.sub(lowerSqrtPrice);
|
|
6800
|
+
const prod = liquidity.mul(deltaSqrtPrice);
|
|
6801
|
+
let result;
|
|
6802
|
+
if (rounding == 0 /* Up */) {
|
|
6803
|
+
const denominator = new (0, _anchor.BN)(1).shln(SCALE_OFFSET * 2);
|
|
6804
|
+
result = divCeil(prod, denominator);
|
|
6805
|
+
} else {
|
|
6806
|
+
result = prod.shrn(SCALE_OFFSET * 2);
|
|
6807
|
+
}
|
|
6808
|
+
return result;
|
|
6809
|
+
}
|
|
6810
|
+
function getLiquidityDeltaFromAmountA(maxAmountA, lowerSqrtPrice, upperSqrtPrice) {
|
|
6811
|
+
const prod = new (0, _decimaljs2.default)(
|
|
6812
|
+
maxAmountA.mul(upperSqrtPrice.mul(lowerSqrtPrice)).toString()
|
|
6813
|
+
);
|
|
6814
|
+
const delta = new (0, _decimaljs2.default)(upperSqrtPrice.sub(lowerSqrtPrice).toString());
|
|
6815
|
+
return new (0, _anchor.BN)(prod.div(delta).floor().toFixed());
|
|
6816
|
+
}
|
|
6817
|
+
function getLiquidityDeltaFromAmountB(maxAmountB, lowerSqrtPrice, upperSqrtPrice) {
|
|
6818
|
+
const denominator = new (0, _decimaljs2.default)(
|
|
6819
|
+
upperSqrtPrice.sub(lowerSqrtPrice).toString()
|
|
6820
|
+
);
|
|
6821
|
+
const prod = new (0, _decimaljs2.default)(maxAmountB.toString()).mul(
|
|
6822
|
+
_decimaljs2.default.pow(2, SCALE_OFFSET * 2)
|
|
6823
|
+
);
|
|
6824
|
+
return new (0, _anchor.BN)(prod.div(denominator).floor().toFixed());
|
|
6825
|
+
}
|
|
6826
|
+
function getAmountAFromLiquidityDelta(liquidity, currentSqrtPrice, maxSqrtPrice, rounding) {
|
|
6827
|
+
const prod = new (0, _decimaljs2.default)(liquidity.toString()).mul(
|
|
6828
|
+
new (0, _decimaljs2.default)(maxSqrtPrice.sub(currentSqrtPrice).toString())
|
|
6829
|
+
);
|
|
6830
|
+
const denominator = currentSqrtPrice.mul(maxSqrtPrice);
|
|
6831
|
+
const result = prod.mul(_decimaljs2.default.pow(2, 64)).div(new (0, _decimaljs2.default)(denominator.toString()));
|
|
6832
|
+
if (rounding == 0 /* Up */) {
|
|
6833
|
+
return result.div(_decimaljs2.default.pow(2, 64)).ceil().toFixed();
|
|
6834
|
+
}
|
|
6835
|
+
return result.div(_decimaljs2.default.pow(2, 64)).floor().toFixed();
|
|
6836
|
+
}
|
|
6837
|
+
function getAmountBFromLiquidityDelta(liquidity, currentSqrtPrice, minSqrtPrice, rounding) {
|
|
6838
|
+
const delta = currentSqrtPrice.sub(minSqrtPrice);
|
|
6839
|
+
const prod = new (0, _decimaljs2.default)(liquidity.toString()).mul(
|
|
6840
|
+
new (0, _decimaljs2.default)(delta.toString())
|
|
6841
|
+
);
|
|
6842
|
+
if (rounding == 0 /* Up */) {
|
|
6843
|
+
return prod.div(_decimaljs2.default.pow(2, 128)).ceil().toFixed();
|
|
6844
|
+
}
|
|
6845
|
+
return prod.div(_decimaljs2.default.pow(2, 128)).floor().toFixed();
|
|
6846
|
+
}
|
|
6847
|
+
|
|
6848
|
+
// src/helpers/fee.ts
|
|
6849
|
+
|
|
6547
6850
|
function getBaseFeeNumerator(feeSchedulerMode, cliffFeeNumerator, period, reductionFactor) {
|
|
6548
6851
|
let feeNumerator;
|
|
6549
6852
|
if (feeSchedulerMode == 0 /* Linear */) {
|
|
@@ -6557,9 +6860,14 @@ function getBaseFeeNumerator(feeSchedulerMode, cliffFeeNumerator, period, reduct
|
|
|
6557
6860
|
return feeNumerator;
|
|
6558
6861
|
}
|
|
6559
6862
|
function getDynamicFeeNumerator(volatilityAccumulator, binStep, variableFeeControl) {
|
|
6560
|
-
const
|
|
6561
|
-
|
|
6562
|
-
|
|
6863
|
+
const volatilityAccumulatorDecimal = new (0, _decimaljs2.default)(
|
|
6864
|
+
volatilityAccumulator.toString()
|
|
6865
|
+
).div(_decimaljs2.default.pow(2, 64));
|
|
6866
|
+
const squareVfaBin = volatilityAccumulatorDecimal.mul(new (0, _decimaljs2.default)(binStep.toString())).pow(2);
|
|
6867
|
+
const vFee = squareVfaBin.mul(new (0, _decimaljs2.default)(variableFeeControl.toString()));
|
|
6868
|
+
return new (0, _anchor.BN)(
|
|
6869
|
+
vFee.add(99999999999).div(1e11).floor().toFixed()
|
|
6870
|
+
);
|
|
6563
6871
|
}
|
|
6564
6872
|
function getFeeNumerator(currentPoint, activationPoint, numberOfPeriod, periodFrequency, feeSchedulerMode, cliffFeeNumerator, reductionFactor, dynamicFeeParams) {
|
|
6565
6873
|
if (Number(periodFrequency) == 0) {
|
|
@@ -6586,136 +6894,46 @@ function getFeeNumerator(currentPoint, activationPoint, numberOfPeriod, periodFr
|
|
|
6586
6894
|
}
|
|
6587
6895
|
return feeNumerator.gt(new (0, _anchor.BN)(MAX_FEE_NUMERATOR)) ? new (0, _anchor.BN)(MAX_FEE_NUMERATOR) : feeNumerator;
|
|
6588
6896
|
}
|
|
6589
|
-
|
|
6590
|
-
|
|
6591
|
-
|
|
6592
|
-
|
|
6593
|
-
|
|
6594
|
-
|
|
6595
|
-
|
|
6596
|
-
const denominator = liquidity.add(product);
|
|
6597
|
-
result = mulDiv(liquidity, sqrtPrice, denominator, 0 /* Up */);
|
|
6598
|
-
} else {
|
|
6599
|
-
const quotient = amount.shln(SCALE_OFFSET * 2).div(liquidity);
|
|
6600
|
-
result = sqrtPrice.add(quotient);
|
|
6601
|
-
}
|
|
6602
|
-
return result;
|
|
6603
|
-
}
|
|
6604
|
-
function getDeltaAmountA(lowerSqrtPrice, upperSqrtPrice, liquidity, rounding) {
|
|
6605
|
-
const deltaSqrtPrice = upperSqrtPrice.sub(lowerSqrtPrice);
|
|
6606
|
-
const denominator = lowerSqrtPrice.mul(upperSqrtPrice);
|
|
6607
|
-
return mulDiv(liquidity, deltaSqrtPrice, denominator, rounding);
|
|
6897
|
+
function getFeeMode(collectFeeMode, btoA) {
|
|
6898
|
+
const feeOnInput = btoA && collectFeeMode === 1 /* OnlyB */;
|
|
6899
|
+
const feesOnTokenA = btoA && collectFeeMode === 0 /* BothToken */;
|
|
6900
|
+
return {
|
|
6901
|
+
feeOnInput,
|
|
6902
|
+
feesOnTokenA
|
|
6903
|
+
};
|
|
6608
6904
|
}
|
|
6609
|
-
function
|
|
6610
|
-
|
|
6611
|
-
|
|
6612
|
-
|
|
6613
|
-
|
|
6614
|
-
|
|
6615
|
-
|
|
6616
|
-
} else {
|
|
6617
|
-
result = prod.shrn(SCALE_OFFSET * 2);
|
|
6618
|
-
}
|
|
6619
|
-
return result;
|
|
6905
|
+
function getTotalFeeOnAmount(amount, tradeFeeNumerator) {
|
|
6906
|
+
return mulDiv(
|
|
6907
|
+
amount,
|
|
6908
|
+
tradeFeeNumerator,
|
|
6909
|
+
new (0, _anchor.BN)(FEE_DENOMINATOR),
|
|
6910
|
+
0 /* Up */
|
|
6911
|
+
);
|
|
6620
6912
|
}
|
|
6621
|
-
function
|
|
6622
|
-
let
|
|
6623
|
-
let
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
sqrtPrice,
|
|
6629
|
-
liquidity,
|
|
6630
|
-
true
|
|
6631
|
-
);
|
|
6632
|
-
outAmount = getDeltaAmountB(
|
|
6633
|
-
nextSqrtPrice,
|
|
6634
|
-
sqrtPrice,
|
|
6635
|
-
liquidity,
|
|
6636
|
-
1 /* Down */
|
|
6637
|
-
);
|
|
6638
|
-
lpFee = mulDiv(
|
|
6639
|
-
outAmount,
|
|
6640
|
-
tradeFeeNumerator,
|
|
6641
|
-
new (0, _anchor.BN)(FEE_DENOMINATOR),
|
|
6642
|
-
1 /* Down */
|
|
6643
|
-
);
|
|
6644
|
-
} else {
|
|
6645
|
-
const nextSqrtPrice = getNextSqrtPrice(
|
|
6646
|
-
inAmount,
|
|
6647
|
-
sqrtPrice,
|
|
6648
|
-
liquidity,
|
|
6649
|
-
false
|
|
6650
|
-
);
|
|
6651
|
-
outAmount = getDeltaAmountA(
|
|
6652
|
-
sqrtPrice,
|
|
6653
|
-
nextSqrtPrice,
|
|
6654
|
-
liquidity,
|
|
6655
|
-
1 /* Down */
|
|
6656
|
-
);
|
|
6657
|
-
lpFee = mulDiv(
|
|
6658
|
-
outAmount,
|
|
6659
|
-
tradeFeeNumerator,
|
|
6660
|
-
new (0, _anchor.BN)(new (0, _anchor.BN)(FEE_DENOMINATOR)),
|
|
6661
|
-
1 /* Down */
|
|
6662
|
-
);
|
|
6663
|
-
}
|
|
6664
|
-
} else {
|
|
6665
|
-
const nextSqrtPrice = getNextSqrtPrice(
|
|
6666
|
-
inAmount,
|
|
6667
|
-
sqrtPrice,
|
|
6668
|
-
liquidity,
|
|
6669
|
-
true
|
|
6670
|
-
);
|
|
6671
|
-
outAmount = getDeltaAmountB(
|
|
6672
|
-
nextSqrtPrice,
|
|
6673
|
-
sqrtPrice,
|
|
6674
|
-
liquidity,
|
|
6675
|
-
1 /* Down */
|
|
6676
|
-
);
|
|
6677
|
-
lpFee = mulDiv(
|
|
6678
|
-
outAmount,
|
|
6679
|
-
tradeFeeNumerator,
|
|
6680
|
-
new (0, _anchor.BN)(FEE_DENOMINATOR),
|
|
6681
|
-
1 /* Down */
|
|
6682
|
-
);
|
|
6683
|
-
if (aToB) {
|
|
6684
|
-
} else {
|
|
6685
|
-
lpFee = mulDiv(
|
|
6686
|
-
inAmount,
|
|
6687
|
-
tradeFeeNumerator,
|
|
6688
|
-
new (0, _anchor.BN)(FEE_DENOMINATOR),
|
|
6689
|
-
1 /* Down */
|
|
6690
|
-
);
|
|
6691
|
-
const nextSqrtPrice2 = getNextSqrtPrice(
|
|
6692
|
-
inAmount.sub(lpFee),
|
|
6693
|
-
sqrtPrice,
|
|
6694
|
-
liquidity,
|
|
6695
|
-
false
|
|
6696
|
-
);
|
|
6697
|
-
outAmount = getDeltaAmountA(
|
|
6698
|
-
sqrtPrice,
|
|
6699
|
-
nextSqrtPrice2,
|
|
6700
|
-
liquidity,
|
|
6701
|
-
1 /* Down */
|
|
6702
|
-
);
|
|
6703
|
-
}
|
|
6913
|
+
function getSwapAmount(inAmount, sqrtPrice, liquidity, tradeFeeNumerator, aToB, collectFeeMode) {
|
|
6914
|
+
let feeMode = getFeeMode(collectFeeMode, !aToB);
|
|
6915
|
+
let actualInAmount = inAmount;
|
|
6916
|
+
let totalFee = new (0, _anchor.BN)(0);
|
|
6917
|
+
if (feeMode.feeOnInput) {
|
|
6918
|
+
totalFee = getTotalFeeOnAmount(inAmount, tradeFeeNumerator);
|
|
6919
|
+
actualInAmount = inAmount.sub(totalFee);
|
|
6704
6920
|
}
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
|
|
6715
|
-
|
|
6921
|
+
const outAmount = aToB ? getDeltaAmountB(
|
|
6922
|
+
getNextSqrtPrice(actualInAmount, sqrtPrice, liquidity, true),
|
|
6923
|
+
sqrtPrice,
|
|
6924
|
+
liquidity,
|
|
6925
|
+
1 /* Down */
|
|
6926
|
+
) : getDeltaAmountA(
|
|
6927
|
+
sqrtPrice,
|
|
6928
|
+
getNextSqrtPrice(actualInAmount, sqrtPrice, liquidity, false),
|
|
6929
|
+
liquidity,
|
|
6930
|
+
1 /* Down */
|
|
6931
|
+
);
|
|
6932
|
+
const amountOut = feeMode.feeOnInput ? outAmount : (totalFee = getTotalFeeOnAmount(outAmount, tradeFeeNumerator), outAmount.sub(totalFee));
|
|
6933
|
+
return { amountOut, totalFee };
|
|
6716
6934
|
}
|
|
6717
6935
|
|
|
6718
|
-
// src/
|
|
6936
|
+
// src/helpers/computeUnits.ts
|
|
6719
6937
|
|
|
6720
6938
|
|
|
6721
6939
|
|
|
@@ -6790,87 +7008,442 @@ var getEstimatedComputeUnitIxWithBuffer = (connection, instructions, feePayer, b
|
|
|
6790
7008
|
return _web3js.ComputeBudgetProgram.setComputeUnitLimit({ units });
|
|
6791
7009
|
});
|
|
6792
7010
|
|
|
6793
|
-
// src/
|
|
7011
|
+
// src/helpers/utils.ts
|
|
6794
7012
|
|
|
6795
7013
|
|
|
6796
|
-
var
|
|
6797
|
-
const slippage = (100
|
|
7014
|
+
var getMaxAmountWithSlippage = (amount, rate) => {
|
|
7015
|
+
const slippage = (100 + rate) / 100 * BASIS_POINT_MAX;
|
|
6798
7016
|
return amount.mul(new (0, _anchor.BN)(slippage)).div(new (0, _anchor.BN)(BASIS_POINT_MAX));
|
|
6799
7017
|
};
|
|
6800
|
-
var
|
|
6801
|
-
const
|
|
6802
|
-
return new (0,
|
|
7018
|
+
var getMinAmountWithSlippage = (amount, rate) => {
|
|
7019
|
+
const slippage = (100 - rate) / 100 * BASIS_POINT_MAX;
|
|
7020
|
+
return amount.mul(new (0, _anchor.BN)(slippage)).div(new (0, _anchor.BN)(BASIS_POINT_MAX));
|
|
7021
|
+
};
|
|
7022
|
+
var getPriceImpact = (actualAmount, idealAmount) => {
|
|
7023
|
+
const diff = idealAmount.sub(actualAmount);
|
|
7024
|
+
return new (0, _decimaljs2.default)(diff.toString()).div(new (0, _decimaljs2.default)(idealAmount.toString())).mul(100).toNumber();
|
|
7025
|
+
};
|
|
7026
|
+
var getPriceFromSqrtPrice = (sqrtPrice, tokenADecimal, tokenBDecimal) => {
|
|
7027
|
+
const decimalSqrtPrice = new (0, _decimaljs2.default)(sqrtPrice.toString());
|
|
7028
|
+
const price = decimalSqrtPrice.mul(decimalSqrtPrice).mul(new (0, _decimaljs2.default)(__pow(10, tokenADecimal - tokenBDecimal))).div(_decimaljs2.default.pow(2, 128)).toString();
|
|
7029
|
+
return price;
|
|
7030
|
+
};
|
|
7031
|
+
var getSqrtPriceFromPrice = (price, tokenADecimal, tokenBDecimal) => {
|
|
7032
|
+
const decimalPrice = new (0, _decimaljs2.default)(price);
|
|
7033
|
+
const adjustedByDecimals = decimalPrice.div(
|
|
7034
|
+
new (0, _decimaljs2.default)(__pow(10, tokenADecimal - tokenBDecimal))
|
|
7035
|
+
);
|
|
7036
|
+
const sqrtValue = _decimaljs2.default.sqrt(adjustedByDecimals);
|
|
7037
|
+
const sqrtValueQ64 = sqrtValue.mul(_decimaljs2.default.pow(2, 64));
|
|
7038
|
+
return new (0, _anchor.BN)(sqrtValueQ64.floor().toFixed());
|
|
7039
|
+
};
|
|
7040
|
+
var getUnClaimReward = (poolState, positionState) => {
|
|
7041
|
+
const totalPositionLiquidity = positionState.unlockedLiquidity.add(positionState.vestedLiquidity).add(positionState.permanentLockedLiquidity);
|
|
7042
|
+
const feeAPerTokenStored = new (0, _anchor.BN)(
|
|
7043
|
+
Buffer.from(poolState.feeAPerLiquidity).reverse()
|
|
7044
|
+
).sub(new (0, _anchor.BN)(Buffer.from(positionState.feeAPerTokenCheckpoint).reverse()));
|
|
7045
|
+
const feeBPerTokenStored = new (0, _anchor.BN)(
|
|
7046
|
+
Buffer.from(poolState.feeBPerLiquidity).reverse()
|
|
7047
|
+
).sub(new (0, _anchor.BN)(Buffer.from(positionState.feeBPerTokenCheckpoint).reverse()));
|
|
7048
|
+
const feeA = totalPositionLiquidity.mul(feeAPerTokenStored).shrn(LIQUIDITY_SCALE);
|
|
7049
|
+
const feeB = totalPositionLiquidity.mul(feeBPerTokenStored).shrn(LIQUIDITY_SCALE);
|
|
7050
|
+
return {
|
|
7051
|
+
feeTokenA: positionState.feeAPending.add(feeA),
|
|
7052
|
+
feeTokenB: positionState.feeBPending.add(feeB),
|
|
7053
|
+
rewards: positionState.rewardInfos.length > 0 ? positionState.rewardInfos.map((item) => item.rewardPendings) : []
|
|
7054
|
+
};
|
|
7055
|
+
};
|
|
7056
|
+
|
|
7057
|
+
// src/helpers/accountFilters.ts
|
|
7058
|
+
var positionByPoolFilter = (pool) => {
|
|
7059
|
+
return {
|
|
7060
|
+
memcmp: {
|
|
7061
|
+
bytes: pool.toBase58(),
|
|
7062
|
+
offset: 8
|
|
7063
|
+
}
|
|
7064
|
+
};
|
|
7065
|
+
};
|
|
7066
|
+
var vestingByPositionFilter = (position) => {
|
|
7067
|
+
return {
|
|
7068
|
+
memcmp: {
|
|
7069
|
+
bytes: position.toBase58(),
|
|
7070
|
+
offset: 8
|
|
7071
|
+
}
|
|
7072
|
+
};
|
|
6803
7073
|
};
|
|
6804
7074
|
|
|
7075
|
+
// src/helpers/priceMath.ts
|
|
7076
|
+
|
|
7077
|
+
|
|
7078
|
+
function calculateInitSqrtPrice(tokenAAmount, tokenBAmount, minSqrtPrice, maxSqrtPrice) {
|
|
7079
|
+
if (tokenAAmount.isZero() || tokenBAmount.isZero()) {
|
|
7080
|
+
throw new Error("Amount cannot be zero");
|
|
7081
|
+
}
|
|
7082
|
+
const amountADecimal = new (0, _decimaljs2.default)(tokenAAmount.toString());
|
|
7083
|
+
const amountBDecimal = new (0, _decimaljs2.default)(tokenBAmount.toString());
|
|
7084
|
+
const minSqrtPriceDecimal = new (0, _decimaljs2.default)(minSqrtPrice.toString()).div(
|
|
7085
|
+
_decimaljs2.default.pow(2, 64)
|
|
7086
|
+
);
|
|
7087
|
+
const maxSqrtPriceDecimal = new (0, _decimaljs2.default)(maxSqrtPrice.toString()).div(
|
|
7088
|
+
_decimaljs2.default.pow(2, 64)
|
|
7089
|
+
);
|
|
7090
|
+
const x = new (0, _decimaljs2.default)(1).div(maxSqrtPriceDecimal);
|
|
7091
|
+
const y = amountBDecimal.div(amountADecimal);
|
|
7092
|
+
const xy = x.mul(y);
|
|
7093
|
+
const paMinusXY = minSqrtPriceDecimal.sub(xy);
|
|
7094
|
+
const xyMinusPa = xy.sub(minSqrtPriceDecimal);
|
|
7095
|
+
const fourY = new (0, _decimaljs2.default)(4).mul(y);
|
|
7096
|
+
const discriminant = xyMinusPa.mul(xyMinusPa).add(fourY);
|
|
7097
|
+
const sqrtDiscriminant = discriminant.sqrt();
|
|
7098
|
+
const result = paMinusXY.add(sqrtDiscriminant).div(new (0, _decimaljs2.default)(2)).mul(_decimaljs2.default.pow(2, 64));
|
|
7099
|
+
return new (0, _anchor.BN)(result.floor().toFixed());
|
|
7100
|
+
}
|
|
7101
|
+
|
|
7102
|
+
// src/helpers/token2022.ts
|
|
7103
|
+
|
|
7104
|
+
|
|
7105
|
+
|
|
7106
|
+
|
|
7107
|
+
|
|
7108
|
+
|
|
7109
|
+
|
|
7110
|
+
function calculatePreFeeAmount(transferFee, postFeeAmount) {
|
|
7111
|
+
if (postFeeAmount.isZero()) {
|
|
7112
|
+
return new (0, _anchor.BN)(0);
|
|
7113
|
+
}
|
|
7114
|
+
if (transferFee.transferFeeBasisPoints === 0) {
|
|
7115
|
+
return postFeeAmount;
|
|
7116
|
+
}
|
|
7117
|
+
const maximumFee = new (0, _anchor.BN)(transferFee.maximumFee.toString());
|
|
7118
|
+
if (transferFee.transferFeeBasisPoints === _spltoken.MAX_FEE_BASIS_POINTS) {
|
|
7119
|
+
return postFeeAmount.add(maximumFee);
|
|
7120
|
+
}
|
|
7121
|
+
const ONE_IN_BASIS_POINTS = new (0, _anchor.BN)(_spltoken.MAX_FEE_BASIS_POINTS);
|
|
7122
|
+
const numerator = postFeeAmount.mul(ONE_IN_BASIS_POINTS);
|
|
7123
|
+
const denominator = ONE_IN_BASIS_POINTS.sub(
|
|
7124
|
+
new (0, _anchor.BN)(transferFee.transferFeeBasisPoints)
|
|
7125
|
+
);
|
|
7126
|
+
const rawPreFeeAmount = numerator.add(denominator).sub(new (0, _anchor.BN)(1)).div(denominator);
|
|
7127
|
+
if (rawPreFeeAmount.sub(postFeeAmount).gte(maximumFee)) {
|
|
7128
|
+
return postFeeAmount.add(maximumFee);
|
|
7129
|
+
}
|
|
7130
|
+
return rawPreFeeAmount;
|
|
7131
|
+
}
|
|
7132
|
+
function calculateInverseFee(transferFee, postFeeAmount) {
|
|
7133
|
+
const preFeeAmount = calculatePreFeeAmount(transferFee, postFeeAmount);
|
|
7134
|
+
return new (0, _anchor.BN)(
|
|
7135
|
+
_spltoken.calculateFee.call(void 0, transferFee, BigInt(preFeeAmount.toString())).toString()
|
|
7136
|
+
);
|
|
7137
|
+
}
|
|
7138
|
+
function calculateTransferFeeIncludedAmount(transferFeeExcludedAmount, mint, currentEpoch) {
|
|
7139
|
+
if (transferFeeExcludedAmount.isZero()) {
|
|
7140
|
+
return {
|
|
7141
|
+
amount: new (0, _anchor.BN)(0),
|
|
7142
|
+
transferFee: new (0, _anchor.BN)(0)
|
|
7143
|
+
};
|
|
7144
|
+
}
|
|
7145
|
+
const transferFeeConfig = _spltoken.getTransferFeeConfig.call(void 0, mint);
|
|
7146
|
+
if (transferFeeConfig === null) {
|
|
7147
|
+
return {
|
|
7148
|
+
amount: transferFeeExcludedAmount,
|
|
7149
|
+
transferFee: new (0, _anchor.BN)(0)
|
|
7150
|
+
};
|
|
7151
|
+
}
|
|
7152
|
+
const epochFee = _spltoken.getEpochFee.call(void 0, transferFeeConfig, BigInt(currentEpoch));
|
|
7153
|
+
const transferFee = epochFee.transferFeeBasisPoints == _spltoken.MAX_FEE_BASIS_POINTS ? new (0, _anchor.BN)(epochFee.maximumFee.toString()) : calculateInverseFee(epochFee, transferFeeExcludedAmount);
|
|
7154
|
+
const transferFeeIncludedAmount = transferFeeExcludedAmount.add(transferFee);
|
|
7155
|
+
return {
|
|
7156
|
+
amount: transferFeeIncludedAmount,
|
|
7157
|
+
transferFee
|
|
7158
|
+
};
|
|
7159
|
+
}
|
|
7160
|
+
function calculateTransferFeeExcludedAmount(transferFeeIncludedAmount, mint, currentEpoch) {
|
|
7161
|
+
const transferFeeConfig = _spltoken.getTransferFeeConfig.call(void 0, mint);
|
|
7162
|
+
if (transferFeeConfig === null) {
|
|
7163
|
+
return {
|
|
7164
|
+
amount: transferFeeIncludedAmount,
|
|
7165
|
+
transferFee: new (0, _anchor.BN)(0)
|
|
7166
|
+
};
|
|
7167
|
+
}
|
|
7168
|
+
const transferFeeIncludedAmountN = BigInt(
|
|
7169
|
+
transferFeeIncludedAmount.toString()
|
|
7170
|
+
);
|
|
7171
|
+
const transferFee = _spltoken.calculateFee.call(void 0,
|
|
7172
|
+
_spltoken.getEpochFee.call(void 0, transferFeeConfig, BigInt(currentEpoch)),
|
|
7173
|
+
transferFeeIncludedAmountN
|
|
7174
|
+
);
|
|
7175
|
+
const transferFeeExcludedAmount = new (0, _anchor.BN)(
|
|
7176
|
+
(transferFeeIncludedAmountN - transferFee).toString()
|
|
7177
|
+
);
|
|
7178
|
+
return {
|
|
7179
|
+
amount: transferFeeExcludedAmount,
|
|
7180
|
+
transferFee: new (0, _anchor.BN)(transferFee.toString())
|
|
7181
|
+
};
|
|
7182
|
+
}
|
|
7183
|
+
|
|
6805
7184
|
// src/CpAmm.ts
|
|
7185
|
+
var _bnjs = require('bn.js');
|
|
6806
7186
|
var CpAmm = class {
|
|
6807
7187
|
constructor(connection) {
|
|
6808
7188
|
this._program = new (0, _anchor.Program)(cp_amm_default, {
|
|
6809
7189
|
connection
|
|
6810
7190
|
});
|
|
7191
|
+
this.poolAuthority = derivePoolAuthority();
|
|
6811
7192
|
}
|
|
7193
|
+
/**
|
|
7194
|
+
* Returns the Anchor program instance.
|
|
7195
|
+
* @returns The AmmProgram instance.
|
|
7196
|
+
*/
|
|
6812
7197
|
getProgram() {
|
|
6813
7198
|
return this._program;
|
|
6814
7199
|
}
|
|
6815
7200
|
/**
|
|
6816
|
-
|
|
6817
|
-
|
|
6818
|
-
|
|
6819
|
-
|
|
6820
|
-
|
|
6821
|
-
|
|
6822
|
-
|
|
6823
|
-
|
|
6824
|
-
|
|
6825
|
-
|
|
7201
|
+
* Prepares token accounts for a transaction by retrieving or creating associated token accounts.
|
|
7202
|
+
* @private
|
|
7203
|
+
* @param {PublicKey} owner - The owner of the token accounts
|
|
7204
|
+
* @param {PublicKey} tokenAMint - Mint address of token A
|
|
7205
|
+
* @param {PublicKey} tokenBMint - Mint address of token B
|
|
7206
|
+
* @param {PublicKey} tokenAProgram - Program ID for token A (Token or Token2022)
|
|
7207
|
+
* @param {PublicKey} tokenBProgram - Program ID for token B (Token or Token2022)
|
|
7208
|
+
* @returns {Promise<{tokenAAta: PublicKey, tokenBAta: PublicKey, instructions: TransactionInstruction[]}>}
|
|
7209
|
+
* The token account addresses and any instructions needed to create them
|
|
7210
|
+
*/
|
|
7211
|
+
prepareTokenAccounts(owner, tokenAMint, tokenBMint, tokenAProgram, tokenBProgram) {
|
|
6826
7212
|
return __async(this, null, function* () {
|
|
6827
|
-
const
|
|
6828
|
-
const
|
|
6829
|
-
|
|
6830
|
-
|
|
6831
|
-
|
|
6832
|
-
|
|
6833
|
-
|
|
6834
|
-
|
|
6835
|
-
|
|
6836
|
-
|
|
6837
|
-
|
|
6838
|
-
|
|
6839
|
-
|
|
6840
|
-
|
|
6841
|
-
|
|
6842
|
-
|
|
6843
|
-
|
|
6844
|
-
|
|
6845
|
-
|
|
6846
|
-
|
|
6847
|
-
|
|
6848
|
-
|
|
6849
|
-
|
|
6850
|
-
|
|
6851
|
-
|
|
6852
|
-
liquidityQ64
|
|
6853
|
-
};
|
|
7213
|
+
const instructions = [];
|
|
7214
|
+
const [
|
|
7215
|
+
{ ataPubkey: tokenAAta, ix: createInputTokenAccountIx },
|
|
7216
|
+
{ ataPubkey: tokenBAta, ix: createOutputTokenAccountIx }
|
|
7217
|
+
] = yield Promise.all([
|
|
7218
|
+
getOrCreateATAInstruction(
|
|
7219
|
+
this._program.provider.connection,
|
|
7220
|
+
tokenAMint,
|
|
7221
|
+
owner,
|
|
7222
|
+
owner,
|
|
7223
|
+
true,
|
|
7224
|
+
tokenAProgram
|
|
7225
|
+
),
|
|
7226
|
+
getOrCreateATAInstruction(
|
|
7227
|
+
this._program.provider.connection,
|
|
7228
|
+
tokenBMint,
|
|
7229
|
+
owner,
|
|
7230
|
+
owner,
|
|
7231
|
+
true,
|
|
7232
|
+
tokenBProgram
|
|
7233
|
+
)
|
|
7234
|
+
]);
|
|
7235
|
+
createInputTokenAccountIx && instructions.push(createInputTokenAccountIx);
|
|
7236
|
+
createOutputTokenAccountIx && instructions.push(createOutputTokenAccountIx);
|
|
7237
|
+
return { tokenAAta, tokenBAta, instructions };
|
|
6854
7238
|
});
|
|
6855
7239
|
}
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
6860
|
-
|
|
6861
|
-
|
|
6862
|
-
|
|
6863
|
-
|
|
6864
|
-
|
|
7240
|
+
/**
|
|
7241
|
+
* Derives token badge account metadata
|
|
7242
|
+
* @param tokenAMint - Public key of token A mint
|
|
7243
|
+
* @param tokenBMint - Public key of token B mint
|
|
7244
|
+
* @returns Array of account metadata for token badges
|
|
7245
|
+
*/
|
|
7246
|
+
getTokenBadgeAccounts(tokenAMint, tokenBMint) {
|
|
7247
|
+
return [
|
|
7248
|
+
{
|
|
7249
|
+
pubkey: deriveTokenBadge(tokenAMint),
|
|
7250
|
+
isWritable: false,
|
|
7251
|
+
isSigner: false
|
|
7252
|
+
},
|
|
7253
|
+
{
|
|
7254
|
+
pubkey: deriveTokenBadge(tokenBMint),
|
|
7255
|
+
isWritable: false,
|
|
7256
|
+
isSigner: false
|
|
7257
|
+
}
|
|
7258
|
+
];
|
|
6865
7259
|
}
|
|
6866
|
-
|
|
7260
|
+
/**
|
|
7261
|
+
* Builds an instruction to add liquidity to a position.
|
|
7262
|
+
* @private
|
|
7263
|
+
* @param {BuildAddLiquidityParams} params - Parameters for adding liquidity
|
|
7264
|
+
* @returns {Promise<TransactionInstruction>} Instruction to add liquidity
|
|
7265
|
+
*/
|
|
7266
|
+
buildAddLiquidityInstruction(params) {
|
|
6867
7267
|
return __async(this, null, function* () {
|
|
6868
|
-
const
|
|
6869
|
-
|
|
6870
|
-
|
|
6871
|
-
|
|
6872
|
-
|
|
6873
|
-
|
|
7268
|
+
const {
|
|
7269
|
+
pool,
|
|
7270
|
+
position,
|
|
7271
|
+
positionNftAccount,
|
|
7272
|
+
owner,
|
|
7273
|
+
tokenAAccount,
|
|
7274
|
+
tokenBAccount,
|
|
7275
|
+
tokenAMint,
|
|
7276
|
+
tokenBMint,
|
|
7277
|
+
tokenAVault,
|
|
7278
|
+
tokenBVault,
|
|
7279
|
+
tokenAProgram,
|
|
7280
|
+
tokenBProgram,
|
|
7281
|
+
liquidityDelta,
|
|
7282
|
+
tokenAAmountThreshold,
|
|
7283
|
+
tokenBAmountThreshold
|
|
7284
|
+
} = params;
|
|
7285
|
+
return yield this._program.methods.addLiquidity({
|
|
7286
|
+
liquidityDelta,
|
|
7287
|
+
tokenAAmountThreshold,
|
|
7288
|
+
tokenBAmountThreshold
|
|
7289
|
+
}).accountsPartial({
|
|
7290
|
+
pool,
|
|
7291
|
+
position,
|
|
7292
|
+
positionNftAccount,
|
|
7293
|
+
owner,
|
|
7294
|
+
tokenAAccount,
|
|
7295
|
+
tokenBAccount,
|
|
7296
|
+
tokenAMint,
|
|
7297
|
+
tokenBMint,
|
|
7298
|
+
tokenAVault,
|
|
7299
|
+
tokenBVault,
|
|
7300
|
+
tokenAProgram,
|
|
7301
|
+
tokenBProgram
|
|
7302
|
+
}).instruction();
|
|
7303
|
+
});
|
|
7304
|
+
}
|
|
7305
|
+
/**
|
|
7306
|
+
* Builds an instruction to remove all liquidity from a position.
|
|
7307
|
+
* @private
|
|
7308
|
+
* @param {BuildRemoveAllLiquidityInstructionParams} params - Parameters for removing all liquidity
|
|
7309
|
+
* @returns {Promise<TransactionInstruction>} Instruction to remove all liquidity
|
|
7310
|
+
*/
|
|
7311
|
+
buildRemoveAllLiquidityInstruction(params) {
|
|
7312
|
+
return __async(this, null, function* () {
|
|
7313
|
+
const {
|
|
7314
|
+
poolAuthority,
|
|
7315
|
+
owner,
|
|
7316
|
+
pool,
|
|
7317
|
+
position,
|
|
7318
|
+
positionNftAccount,
|
|
7319
|
+
tokenAAccount,
|
|
7320
|
+
tokenBAccount,
|
|
7321
|
+
tokenAAmountThreshold,
|
|
7322
|
+
tokenBAmountThreshold,
|
|
7323
|
+
tokenAMint,
|
|
7324
|
+
tokenBMint,
|
|
7325
|
+
tokenAVault,
|
|
7326
|
+
tokenBVault,
|
|
7327
|
+
tokenAProgram,
|
|
7328
|
+
tokenBProgram
|
|
7329
|
+
} = params;
|
|
7330
|
+
return yield this._program.methods.removeAllLiquidity(tokenAAmountThreshold, tokenBAmountThreshold).accountsPartial({
|
|
7331
|
+
poolAuthority,
|
|
7332
|
+
pool,
|
|
7333
|
+
position,
|
|
7334
|
+
positionNftAccount,
|
|
7335
|
+
owner,
|
|
7336
|
+
tokenAAccount,
|
|
7337
|
+
tokenBAccount,
|
|
7338
|
+
tokenAMint,
|
|
7339
|
+
tokenBMint,
|
|
7340
|
+
tokenAVault,
|
|
7341
|
+
tokenBVault,
|
|
7342
|
+
tokenAProgram,
|
|
7343
|
+
tokenBProgram
|
|
7344
|
+
}).instruction();
|
|
7345
|
+
});
|
|
7346
|
+
}
|
|
7347
|
+
/**
|
|
7348
|
+
* Builds an instruction to claim fees accumulated by a position.
|
|
7349
|
+
* @private
|
|
7350
|
+
* @param {ClaimPositionFeeInstructionParams} params - Parameters for claiming position fees
|
|
7351
|
+
* @returns {Promise<TransactionInstruction>} Instruction to claim position fees
|
|
7352
|
+
*/
|
|
7353
|
+
buildClaimPositionFeeInstruction(params) {
|
|
7354
|
+
return __async(this, null, function* () {
|
|
7355
|
+
const {
|
|
7356
|
+
owner,
|
|
7357
|
+
poolAuthority,
|
|
7358
|
+
pool,
|
|
7359
|
+
position,
|
|
7360
|
+
positionNftAccount,
|
|
7361
|
+
tokenAAccount,
|
|
7362
|
+
tokenBAccount,
|
|
7363
|
+
tokenAVault,
|
|
7364
|
+
tokenBVault,
|
|
7365
|
+
tokenAMint,
|
|
7366
|
+
tokenBMint,
|
|
7367
|
+
tokenAProgram,
|
|
7368
|
+
tokenBProgram
|
|
7369
|
+
} = params;
|
|
7370
|
+
return yield this._program.methods.claimPositionFee().accountsPartial({
|
|
7371
|
+
poolAuthority,
|
|
7372
|
+
owner,
|
|
7373
|
+
pool,
|
|
7374
|
+
position,
|
|
7375
|
+
positionNftAccount,
|
|
7376
|
+
tokenAAccount,
|
|
7377
|
+
tokenBAccount,
|
|
7378
|
+
tokenAVault,
|
|
7379
|
+
tokenBVault,
|
|
7380
|
+
tokenAMint,
|
|
7381
|
+
tokenBMint,
|
|
7382
|
+
tokenAProgram,
|
|
7383
|
+
tokenBProgram
|
|
7384
|
+
}).instruction();
|
|
7385
|
+
});
|
|
7386
|
+
}
|
|
7387
|
+
/**
|
|
7388
|
+
* Builds an instruction to close a position.
|
|
7389
|
+
* @private
|
|
7390
|
+
* @param {ClosePositionInstructionParams} params - Parameters for closing a position
|
|
7391
|
+
* @returns {Promise<TransactionInstruction>} Instruction to close the position
|
|
7392
|
+
*/
|
|
7393
|
+
buildClosePositionInstruction(params) {
|
|
7394
|
+
return __async(this, null, function* () {
|
|
7395
|
+
const {
|
|
7396
|
+
owner,
|
|
7397
|
+
poolAuthority,
|
|
7398
|
+
pool,
|
|
7399
|
+
position,
|
|
7400
|
+
positionNftAccount,
|
|
7401
|
+
positionNftMint
|
|
7402
|
+
} = params;
|
|
7403
|
+
return yield this._program.methods.closePosition().accountsPartial({
|
|
7404
|
+
positionNftMint,
|
|
7405
|
+
positionNftAccount,
|
|
7406
|
+
pool,
|
|
7407
|
+
position,
|
|
7408
|
+
poolAuthority,
|
|
7409
|
+
rentReceiver: owner,
|
|
7410
|
+
owner,
|
|
7411
|
+
tokenProgram: _spltoken.TOKEN_2022_PROGRAM_ID
|
|
7412
|
+
}).instruction();
|
|
7413
|
+
});
|
|
7414
|
+
}
|
|
7415
|
+
/**
|
|
7416
|
+
* Fetches the Config state of the program.
|
|
7417
|
+
* @param config - Public key of the config account.
|
|
7418
|
+
* @returns Parsed ConfigState.
|
|
7419
|
+
*/
|
|
7420
|
+
fetchConfigState(config) {
|
|
7421
|
+
return __async(this, null, function* () {
|
|
7422
|
+
const configState = yield this._program.account.config.fetchNullable(
|
|
7423
|
+
config
|
|
7424
|
+
);
|
|
7425
|
+
_invariant2.default.call(void 0, configState, `Config account: ${config} not found`);
|
|
7426
|
+
return configState;
|
|
7427
|
+
});
|
|
7428
|
+
}
|
|
7429
|
+
/**
|
|
7430
|
+
* Fetches the Pool state.
|
|
7431
|
+
* @param pool - Public key of the pool.
|
|
7432
|
+
* @returns Parsed PoolState.
|
|
7433
|
+
*/
|
|
7434
|
+
fetchPoolState(pool) {
|
|
7435
|
+
return __async(this, null, function* () {
|
|
7436
|
+
const poolState = yield this._program.account.pool.fetchNullable(pool);
|
|
7437
|
+
_invariant2.default.call(void 0, poolState, `Pool account: ${pool} not found`);
|
|
7438
|
+
return poolState;
|
|
7439
|
+
});
|
|
7440
|
+
}
|
|
7441
|
+
/**
|
|
7442
|
+
* Fetches the Position state.
|
|
7443
|
+
* @param position - Public key of the position.
|
|
7444
|
+
* @returns Parsed PositionState.
|
|
7445
|
+
*/
|
|
7446
|
+
fetchPositionState(position) {
|
|
6874
7447
|
return __async(this, null, function* () {
|
|
6875
7448
|
const positionState = yield this._program.account.position.fetchNullable(
|
|
6876
7449
|
position
|
|
@@ -6879,10 +7452,136 @@ var CpAmm = class {
|
|
|
6879
7452
|
return positionState;
|
|
6880
7453
|
});
|
|
6881
7454
|
}
|
|
7455
|
+
/**
|
|
7456
|
+
* Retrieves all config accounts.
|
|
7457
|
+
* @returns Array of config public keys and their states.
|
|
7458
|
+
*/
|
|
7459
|
+
getAllConfigs() {
|
|
7460
|
+
return __async(this, null, function* () {
|
|
7461
|
+
const configAccounts = yield this._program.account.config.all();
|
|
7462
|
+
return configAccounts;
|
|
7463
|
+
});
|
|
7464
|
+
}
|
|
7465
|
+
/**
|
|
7466
|
+
* Retrieves all pool accounts.
|
|
7467
|
+
* @returns Array of pool public keys and their states.
|
|
7468
|
+
*/
|
|
7469
|
+
getAllPools() {
|
|
7470
|
+
return __async(this, null, function* () {
|
|
7471
|
+
const poolAccounts = yield this._program.account.pool.all();
|
|
7472
|
+
return poolAccounts;
|
|
7473
|
+
});
|
|
7474
|
+
}
|
|
7475
|
+
/**
|
|
7476
|
+
* Retrieves all position accounts.
|
|
7477
|
+
* @returns Array of position public keys and their states.
|
|
7478
|
+
*/
|
|
7479
|
+
getAllPositions() {
|
|
7480
|
+
return __async(this, null, function* () {
|
|
7481
|
+
const poolAccounts = yield this._program.account.position.all();
|
|
7482
|
+
return poolAccounts;
|
|
7483
|
+
});
|
|
7484
|
+
}
|
|
7485
|
+
/**
|
|
7486
|
+
* Gets all positions a specific pool.
|
|
7487
|
+
* @param pool - Public key of the pool.
|
|
7488
|
+
* @returns List of user positions for the pool.
|
|
7489
|
+
*/
|
|
7490
|
+
getAllPositionsByPool(pool) {
|
|
7491
|
+
return __async(this, null, function* () {
|
|
7492
|
+
return yield this._program.account.position.all([
|
|
7493
|
+
positionByPoolFilter(pool)
|
|
7494
|
+
]);
|
|
7495
|
+
});
|
|
7496
|
+
}
|
|
7497
|
+
/**
|
|
7498
|
+
* Gets all positions of a user for a specific pool.
|
|
7499
|
+
* @param pool - Public key of the pool.
|
|
7500
|
+
* @param user - Public key of the user.
|
|
7501
|
+
* @returns List of user positions for the pool.
|
|
7502
|
+
*/
|
|
7503
|
+
getUserPositionByPool(pool, user) {
|
|
7504
|
+
return __async(this, null, function* () {
|
|
7505
|
+
const allUserPositions = yield this.getPositionsByUser(user);
|
|
7506
|
+
return allUserPositions.filter(
|
|
7507
|
+
(position) => position.positionState.pool.equals(pool)
|
|
7508
|
+
);
|
|
7509
|
+
});
|
|
7510
|
+
}
|
|
7511
|
+
/**
|
|
7512
|
+
* Gets all positions of a user across all pools.
|
|
7513
|
+
* @param user - Public key of the user.
|
|
7514
|
+
* @returns Array of user positions already sorted by liquidity
|
|
7515
|
+
*/
|
|
7516
|
+
getPositionsByUser(user) {
|
|
7517
|
+
return __async(this, null, function* () {
|
|
7518
|
+
const userPositionAccounts = yield getAllUserPositionNftAccount(
|
|
7519
|
+
this._program.provider.connection,
|
|
7520
|
+
user
|
|
7521
|
+
);
|
|
7522
|
+
if (userPositionAccounts.length === 0) {
|
|
7523
|
+
return [];
|
|
7524
|
+
}
|
|
7525
|
+
const positionAddresses = userPositionAccounts.map(
|
|
7526
|
+
(account) => derivePositionAddress(account.positionNft)
|
|
7527
|
+
);
|
|
7528
|
+
const positionStates = yield this._program.account.position.fetchMultiple(
|
|
7529
|
+
positionAddresses
|
|
7530
|
+
);
|
|
7531
|
+
const positionResult = userPositionAccounts.map((account, index) => {
|
|
7532
|
+
const positionState = positionStates[index];
|
|
7533
|
+
if (!positionState) return null;
|
|
7534
|
+
return {
|
|
7535
|
+
positionNftAccount: account.positionNftAccount,
|
|
7536
|
+
position: positionAddresses[index],
|
|
7537
|
+
positionState
|
|
7538
|
+
};
|
|
7539
|
+
}).filter(Boolean);
|
|
7540
|
+
positionResult.sort((a, b) => {
|
|
7541
|
+
const totalLiquidityA = a.positionState.vestedLiquidity.add(a.positionState.permanentLockedLiquidity).add(a.positionState.unlockedLiquidity);
|
|
7542
|
+
const totalLiquidityB = b.positionState.vestedLiquidity.add(b.positionState.permanentLockedLiquidity).add(b.positionState.unlockedLiquidity);
|
|
7543
|
+
return totalLiquidityB.cmp(totalLiquidityA);
|
|
7544
|
+
});
|
|
7545
|
+
return positionResult;
|
|
7546
|
+
});
|
|
7547
|
+
}
|
|
7548
|
+
getAllVestingsByPosition(position) {
|
|
7549
|
+
return __async(this, null, function* () {
|
|
7550
|
+
const vestings = yield this._program.account.vesting.all([
|
|
7551
|
+
vestingByPositionFilter(position)
|
|
7552
|
+
]);
|
|
7553
|
+
return vestings;
|
|
7554
|
+
});
|
|
7555
|
+
}
|
|
7556
|
+
isLockedPosition(position) {
|
|
7557
|
+
const totalLockedLiquidity = position.vestedLiquidity.add(
|
|
7558
|
+
position.permanentLockedLiquidity
|
|
7559
|
+
);
|
|
7560
|
+
return totalLockedLiquidity.gtn(0);
|
|
7561
|
+
}
|
|
7562
|
+
isPoolExist(pool) {
|
|
7563
|
+
return __async(this, null, function* () {
|
|
7564
|
+
const poolState = yield this._program.account.pool.fetchNullable(pool);
|
|
7565
|
+
return poolState !== null;
|
|
7566
|
+
});
|
|
7567
|
+
}
|
|
7568
|
+
/**
|
|
7569
|
+
* Calculates swap quote based on input amount and pool state.
|
|
7570
|
+
* @param params - Swap parameters including input amount, pool state, slippage, etc.
|
|
7571
|
+
* @returns Swap quote including expected output amount, fee, and price impact.
|
|
7572
|
+
*/
|
|
6882
7573
|
getQuote(params) {
|
|
6883
7574
|
return __async(this, null, function* () {
|
|
6884
|
-
|
|
6885
|
-
|
|
7575
|
+
const {
|
|
7576
|
+
inAmount,
|
|
7577
|
+
inputTokenMint,
|
|
7578
|
+
slippage,
|
|
7579
|
+
poolState,
|
|
7580
|
+
currentTime,
|
|
7581
|
+
currentSlot,
|
|
7582
|
+
inputTokenInfo,
|
|
7583
|
+
outputTokenInfo
|
|
7584
|
+
} = params;
|
|
6886
7585
|
const {
|
|
6887
7586
|
sqrtPrice: sqrtPriceQ64,
|
|
6888
7587
|
liquidity: liquidityQ64,
|
|
@@ -6899,13 +7598,16 @@ var CpAmm = class {
|
|
|
6899
7598
|
periodFrequency
|
|
6900
7599
|
} = poolFees.baseFee;
|
|
6901
7600
|
const dynamicFee = poolFees.dynamicFee;
|
|
7601
|
+
let actualAmountIn = inAmount;
|
|
7602
|
+
if (inputTokenInfo) {
|
|
7603
|
+
actualAmountIn = calculateTransferFeeExcludedAmount(
|
|
7604
|
+
inAmount,
|
|
7605
|
+
inputTokenInfo.mint,
|
|
7606
|
+
inputTokenInfo.currentEpoch
|
|
7607
|
+
).amount;
|
|
7608
|
+
}
|
|
6902
7609
|
const aToB = poolState.tokenAMint.equals(inputTokenMint);
|
|
6903
|
-
const
|
|
6904
|
-
const blockInfo = yield this._program.provider.connection.getBlock(slot, {
|
|
6905
|
-
maxSupportedTransactionVersion: 0
|
|
6906
|
-
});
|
|
6907
|
-
const currentTime = (_a = blockInfo == null ? void 0 : blockInfo.blockTime) != null ? _a : Math.floor(Date.now() / 1e3);
|
|
6908
|
-
const currentPoint = activationType ? currentTime : slot;
|
|
7610
|
+
const currentPoint = activationType ? currentTime : currentSlot;
|
|
6909
7611
|
let dynamicFeeParams;
|
|
6910
7612
|
if (dynamicFee.initialized) {
|
|
6911
7613
|
const { volatilityAccumulator, binStep, variableFeeControl } = dynamicFee;
|
|
@@ -6921,64 +7623,245 @@ var CpAmm = class {
|
|
|
6921
7623
|
reductionFactor,
|
|
6922
7624
|
dynamicFeeParams
|
|
6923
7625
|
);
|
|
6924
|
-
const {
|
|
6925
|
-
|
|
7626
|
+
const { amountOut, totalFee } = getSwapAmount(
|
|
7627
|
+
actualAmountIn,
|
|
6926
7628
|
sqrtPriceQ64,
|
|
6927
7629
|
liquidityQ64,
|
|
6928
7630
|
tradeFeeNumerator,
|
|
6929
7631
|
aToB,
|
|
6930
7632
|
collectFeeMode
|
|
6931
7633
|
);
|
|
6932
|
-
|
|
6933
|
-
|
|
6934
|
-
|
|
6935
|
-
|
|
7634
|
+
let actualAmoutOut = amountOut;
|
|
7635
|
+
if (outputTokenInfo) {
|
|
7636
|
+
actualAmoutOut = calculateTransferFeeExcludedAmount(
|
|
7637
|
+
amountOut,
|
|
7638
|
+
outputTokenInfo.mint,
|
|
7639
|
+
outputTokenInfo.currentEpoch
|
|
7640
|
+
).amount;
|
|
7641
|
+
}
|
|
7642
|
+
const minSwapOutAmount = getMinAmountWithSlippage(actualAmoutOut, slippage);
|
|
6936
7643
|
return {
|
|
6937
7644
|
swapInAmount: inAmount,
|
|
6938
|
-
|
|
7645
|
+
consumedInAmount: actualAmountIn,
|
|
7646
|
+
swapOutAmount: actualAmoutOut,
|
|
6939
7647
|
minSwapOutAmount,
|
|
6940
|
-
totalFee
|
|
6941
|
-
priceImpact: getPriceImpact(minSwapOutAmount,
|
|
7648
|
+
totalFee,
|
|
7649
|
+
priceImpact: getPriceImpact(minSwapOutAmount, actualAmoutOut)
|
|
6942
7650
|
};
|
|
6943
7651
|
});
|
|
6944
7652
|
}
|
|
6945
7653
|
/**
|
|
6946
|
-
*
|
|
7654
|
+
* Calculates the deposit quote for liquidity pool.
|
|
6947
7655
|
*
|
|
6948
|
-
* @param {
|
|
6949
|
-
* - tokenX: The mint address of token X.
|
|
6950
|
-
* - tokenY: The mint address of token Y.
|
|
6951
|
-
* - maxAmountX: The maximum amount of token X available.
|
|
6952
|
-
* - maxAmountY: The maximum amount of token Y available.
|
|
6953
|
-
* - pool: The address of the liquidity pool.
|
|
7656
|
+
* @param {GetDepositQuoteParams} params - The parameters for calculating the deposit quote.
|
|
6954
7657
|
*
|
|
6955
|
-
* @returns {Promise<
|
|
7658
|
+
* @returns {Promise<Object>} Deposit quote results
|
|
7659
|
+
* @returns {BN} returns.actualInputAmount - The actual amount used as input (after deducting transfer fees).
|
|
7660
|
+
* @returns {BN} returns.outputAmount - The calculated corresponding amount of the other token.
|
|
7661
|
+
* @returns {BN} returns.liquidityDelta - The amount of liquidity that will be added to the pool.
|
|
6956
7662
|
*/
|
|
6957
|
-
|
|
7663
|
+
getDepositQuote(params) {
|
|
6958
7664
|
return __async(this, null, function* () {
|
|
6959
7665
|
const {
|
|
6960
|
-
|
|
6961
|
-
|
|
6962
|
-
|
|
6963
|
-
|
|
7666
|
+
inAmount,
|
|
7667
|
+
isTokenA,
|
|
7668
|
+
inputTokenInfo,
|
|
7669
|
+
outputTokenInfo,
|
|
7670
|
+
minSqrtPrice,
|
|
7671
|
+
maxSqrtPrice,
|
|
6964
7672
|
sqrtPrice
|
|
6965
7673
|
} = params;
|
|
6966
|
-
const
|
|
6967
|
-
|
|
7674
|
+
const actualAmountIn = inputTokenInfo ? inAmount.sub(
|
|
7675
|
+
calculateTransferFeeIncludedAmount(
|
|
7676
|
+
inAmount,
|
|
7677
|
+
inputTokenInfo.mint,
|
|
7678
|
+
inputTokenInfo.currentEpoch
|
|
7679
|
+
).transferFee
|
|
7680
|
+
) : inAmount;
|
|
7681
|
+
const { liquidityDelta, rawAmount } = isTokenA ? {
|
|
7682
|
+
liquidityDelta: getLiquidityDeltaFromAmountA(
|
|
7683
|
+
actualAmountIn,
|
|
7684
|
+
sqrtPrice,
|
|
7685
|
+
maxSqrtPrice
|
|
7686
|
+
),
|
|
7687
|
+
rawAmount: (delta) => getAmountBFromLiquidityDelta(
|
|
7688
|
+
delta,
|
|
7689
|
+
sqrtPrice,
|
|
7690
|
+
minSqrtPrice,
|
|
7691
|
+
0 /* Up */
|
|
7692
|
+
)
|
|
7693
|
+
} : {
|
|
7694
|
+
liquidityDelta: getLiquidityDeltaFromAmountB(
|
|
7695
|
+
actualAmountIn,
|
|
7696
|
+
minSqrtPrice,
|
|
7697
|
+
sqrtPrice
|
|
7698
|
+
),
|
|
7699
|
+
rawAmount: (delta) => getAmountAFromLiquidityDelta(
|
|
7700
|
+
delta,
|
|
7701
|
+
sqrtPrice,
|
|
7702
|
+
maxSqrtPrice,
|
|
7703
|
+
0 /* Up */
|
|
7704
|
+
)
|
|
7705
|
+
};
|
|
7706
|
+
const rawOutputAmount = new (0, _anchor.BN)(rawAmount(liquidityDelta));
|
|
7707
|
+
const outputAmount = outputTokenInfo ? calculateTransferFeeIncludedAmount(
|
|
7708
|
+
rawOutputAmount,
|
|
7709
|
+
outputTokenInfo.mint,
|
|
7710
|
+
outputTokenInfo.currentEpoch
|
|
7711
|
+
).amount : rawOutputAmount;
|
|
7712
|
+
return {
|
|
7713
|
+
actualInputAmount: actualAmountIn,
|
|
7714
|
+
consumedInputAmount: inAmount,
|
|
7715
|
+
liquidityDelta,
|
|
7716
|
+
outputAmount
|
|
7717
|
+
};
|
|
7718
|
+
});
|
|
7719
|
+
}
|
|
7720
|
+
/**
|
|
7721
|
+
* Calculates the withdrawal quote for removing liquidity from a concentrated liquidity pool.
|
|
7722
|
+
*
|
|
7723
|
+
* @param {GetWithdrawQuoteParams} params - The parameters for calculating the withdraw quote
|
|
7724
|
+
*
|
|
7725
|
+
* @param {Object|null} params.tokenATokenInfo - must provide if token a is token2022
|
|
7726
|
+
* @param {Object|null} params.tokenBTokenInfo - must provide if token b is token2022
|
|
7727
|
+
*
|
|
7728
|
+
* @returns {Promise<Object>} Withdrawal quote results
|
|
7729
|
+
* @returns {BN} returns.liquidityDelta - The amount of liquidity that will be removed from the pool
|
|
7730
|
+
* @returns {BN} returns.outAmountA - The calculated amount of token A to be received (after deducting transfer fees)
|
|
7731
|
+
* @returns {BN} returns.outAmountB - The calculated amount of token B to be received (after deducting transfer fees)
|
|
7732
|
+
*/
|
|
7733
|
+
getWithdrawQuote(params) {
|
|
7734
|
+
return __async(this, null, function* () {
|
|
7735
|
+
const {
|
|
7736
|
+
liquidityDelta,
|
|
7737
|
+
sqrtPrice,
|
|
7738
|
+
maxSqrtPrice,
|
|
7739
|
+
minSqrtPrice,
|
|
7740
|
+
tokenATokenInfo,
|
|
7741
|
+
tokenBTokenInfo
|
|
7742
|
+
} = params;
|
|
7743
|
+
const amountA = getAmountAFromLiquidityDelta(
|
|
7744
|
+
liquidityDelta,
|
|
6968
7745
|
sqrtPrice,
|
|
6969
|
-
|
|
7746
|
+
maxSqrtPrice,
|
|
7747
|
+
1 /* Down */
|
|
6970
7748
|
);
|
|
6971
|
-
const
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
|
|
7749
|
+
const amountB = getAmountBFromLiquidityDelta(
|
|
7750
|
+
liquidityDelta,
|
|
7751
|
+
sqrtPrice,
|
|
7752
|
+
minSqrtPrice,
|
|
7753
|
+
1 /* Down */
|
|
6975
7754
|
);
|
|
6976
|
-
return
|
|
7755
|
+
return {
|
|
7756
|
+
liquidityDelta,
|
|
7757
|
+
outAmountA: tokenATokenInfo ? calculateTransferFeeExcludedAmount(
|
|
7758
|
+
new (0, _anchor.BN)(amountA),
|
|
7759
|
+
tokenATokenInfo.mint,
|
|
7760
|
+
tokenATokenInfo.currentEpoch
|
|
7761
|
+
).amount : new (0, _anchor.BN)(amountA),
|
|
7762
|
+
outAmountB: tokenBTokenInfo ? calculateTransferFeeExcludedAmount(
|
|
7763
|
+
new (0, _anchor.BN)(amountB),
|
|
7764
|
+
tokenBTokenInfo.mint,
|
|
7765
|
+
tokenBTokenInfo.currentEpoch
|
|
7766
|
+
).amount : new (0, _anchor.BN)(amountB)
|
|
7767
|
+
};
|
|
6977
7768
|
});
|
|
6978
7769
|
}
|
|
7770
|
+
/**
|
|
7771
|
+
* Calculates liquidity and corresponding token amounts for token A single-sided pool creation
|
|
7772
|
+
* Only supports initialization where initial price equals min sqrt price
|
|
7773
|
+
* @param params Parameters for single-sided pool creation
|
|
7774
|
+
* @returns Calculated liquidity delta
|
|
7775
|
+
*/
|
|
7776
|
+
preparePoolCreationSingleSide(params) {
|
|
7777
|
+
const {
|
|
7778
|
+
tokenAAmount,
|
|
7779
|
+
initSqrtPrice,
|
|
7780
|
+
minSqrtPrice,
|
|
7781
|
+
maxSqrtPrice,
|
|
7782
|
+
tokenAInfo
|
|
7783
|
+
} = params;
|
|
7784
|
+
if (!initSqrtPrice.eq(minSqrtPrice)) {
|
|
7785
|
+
throw new Error("Only support single side for base token.");
|
|
7786
|
+
}
|
|
7787
|
+
const actualAmountIn = tokenAInfo ? tokenAAmount.sub(
|
|
7788
|
+
calculateTransferFeeIncludedAmount(
|
|
7789
|
+
tokenAAmount,
|
|
7790
|
+
tokenAInfo.mint,
|
|
7791
|
+
tokenAInfo.currentEpoch
|
|
7792
|
+
).transferFee
|
|
7793
|
+
) : tokenAAmount;
|
|
7794
|
+
const liquidityDelta = getLiquidityDeltaFromAmountA(
|
|
7795
|
+
actualAmountIn,
|
|
7796
|
+
initSqrtPrice,
|
|
7797
|
+
maxSqrtPrice
|
|
7798
|
+
);
|
|
7799
|
+
return liquidityDelta;
|
|
7800
|
+
}
|
|
7801
|
+
/**
|
|
7802
|
+
* Prepares parameters required for pool creation, including initial sqrt price and liquidity.
|
|
7803
|
+
* @private
|
|
7804
|
+
* @param {PreparePoolCreationParams} params - Initial token amounts for pool creation.
|
|
7805
|
+
* @returns init sqrt price and liquidity in Q64 format.
|
|
7806
|
+
*/
|
|
7807
|
+
preparePoolCreationParams(params) {
|
|
7808
|
+
const {
|
|
7809
|
+
tokenAAmount,
|
|
7810
|
+
tokenBAmount,
|
|
7811
|
+
minSqrtPrice,
|
|
7812
|
+
maxSqrtPrice,
|
|
7813
|
+
tokenAInfo,
|
|
7814
|
+
tokenBInfo
|
|
7815
|
+
} = params;
|
|
7816
|
+
if (tokenAAmount.eq(new (0, _anchor.BN)(0)) && tokenBAmount.eq(new (0, _anchor.BN)(0))) {
|
|
7817
|
+
throw new Error("Invalid input amount");
|
|
7818
|
+
}
|
|
7819
|
+
const actualAmountAIn = tokenAInfo ? tokenAAmount.sub(
|
|
7820
|
+
calculateTransferFeeIncludedAmount(
|
|
7821
|
+
tokenAAmount,
|
|
7822
|
+
tokenAInfo.mint,
|
|
7823
|
+
tokenAInfo.currentEpoch
|
|
7824
|
+
).transferFee
|
|
7825
|
+
) : tokenAAmount;
|
|
7826
|
+
const actualAmountBIn = tokenBInfo ? tokenAAmount.sub(
|
|
7827
|
+
calculateTransferFeeIncludedAmount(
|
|
7828
|
+
tokenBAmount,
|
|
7829
|
+
tokenBInfo.mint,
|
|
7830
|
+
tokenBInfo.currentEpoch
|
|
7831
|
+
).transferFee
|
|
7832
|
+
) : tokenAAmount;
|
|
7833
|
+
const initSqrtPrice = calculateInitSqrtPrice(
|
|
7834
|
+
tokenAAmount,
|
|
7835
|
+
tokenBAmount,
|
|
7836
|
+
minSqrtPrice,
|
|
7837
|
+
maxSqrtPrice
|
|
7838
|
+
);
|
|
7839
|
+
const liquidityDeltaFromAmountA = getLiquidityDeltaFromAmountA(
|
|
7840
|
+
actualAmountAIn,
|
|
7841
|
+
initSqrtPrice,
|
|
7842
|
+
maxSqrtPrice
|
|
7843
|
+
);
|
|
7844
|
+
const liquidityDeltaFromAmountB = getLiquidityDeltaFromAmountB(
|
|
7845
|
+
actualAmountBIn,
|
|
7846
|
+
minSqrtPrice,
|
|
7847
|
+
initSqrtPrice
|
|
7848
|
+
);
|
|
7849
|
+
const liquidityDelta = _bnjs.min.call(void 0,
|
|
7850
|
+
liquidityDeltaFromAmountA,
|
|
7851
|
+
liquidityDeltaFromAmountB
|
|
7852
|
+
);
|
|
7853
|
+
return {
|
|
7854
|
+
initSqrtPrice,
|
|
7855
|
+
liquidityDelta
|
|
7856
|
+
};
|
|
7857
|
+
}
|
|
7858
|
+
/**
|
|
7859
|
+
* Builds a transaction to create a permissionless pool.
|
|
7860
|
+
* @param params - Parameters for pool creation.
|
|
7861
|
+
* @returns Transaction builder.
|
|
7862
|
+
*/
|
|
6979
7863
|
createPool(params) {
|
|
6980
7864
|
return __async(this, null, function* () {
|
|
6981
|
-
var _a, _b, _c, _d;
|
|
6982
7865
|
const {
|
|
6983
7866
|
payer,
|
|
6984
7867
|
creator,
|
|
@@ -6986,70 +7869,61 @@ var CpAmm = class {
|
|
|
6986
7869
|
positionNft,
|
|
6987
7870
|
tokenAMint,
|
|
6988
7871
|
tokenBMint,
|
|
7872
|
+
initSqrtPrice,
|
|
7873
|
+
liquidityDelta,
|
|
6989
7874
|
activationPoint,
|
|
6990
7875
|
tokenAAmount,
|
|
6991
7876
|
tokenBAmount,
|
|
6992
|
-
|
|
6993
|
-
|
|
7877
|
+
tokenAProgram,
|
|
7878
|
+
tokenBProgram
|
|
6994
7879
|
} = params;
|
|
6995
|
-
const
|
|
6996
|
-
|
|
6997
|
-
|
|
6998
|
-
|
|
6999
|
-
|
|
7000
|
-
|
|
7001
|
-
|
|
7002
|
-
|
|
7003
|
-
|
|
7004
|
-
|
|
7005
|
-
config,
|
|
7006
|
-
tokenAMint,
|
|
7007
|
-
tokenBMint,
|
|
7008
|
-
this._program.programId
|
|
7009
|
-
);
|
|
7010
|
-
const position = derivePositionAddress(
|
|
7011
|
-
positionNft,
|
|
7012
|
-
this._program.programId
|
|
7013
|
-
);
|
|
7014
|
-
const positionNftAccount = derivePositionNftAccount(
|
|
7015
|
-
positionNft,
|
|
7016
|
-
this._program.programId
|
|
7017
|
-
);
|
|
7018
|
-
const tokenAProgram = (_b = (_a = yield this._program.provider.connection.getParsedAccountInfo(tokenAMint)) == null ? void 0 : _a.value) == null ? void 0 : _b.owner;
|
|
7019
|
-
const tokenBProgram = (_d = (_c = yield this._program.provider.connection.getParsedAccountInfo(tokenBMint)) == null ? void 0 : _c.value) == null ? void 0 : _d.owner;
|
|
7020
|
-
const payerTokenA = _spltoken.getAssociatedTokenAddressSync.call(void 0,
|
|
7021
|
-
tokenAMint,
|
|
7880
|
+
const pool = derivePoolAddress(config, tokenAMint, tokenBMint);
|
|
7881
|
+
const position = derivePositionAddress(positionNft);
|
|
7882
|
+
const positionNftAccount = derivePositionNftAccount(positionNft);
|
|
7883
|
+
const tokenAVault = deriveTokenVaultAddress(tokenAMint, pool);
|
|
7884
|
+
const tokenBVault = deriveTokenVaultAddress(tokenBMint, pool);
|
|
7885
|
+
const {
|
|
7886
|
+
tokenAAta: payerTokenA,
|
|
7887
|
+
tokenBAta: payerTokenB,
|
|
7888
|
+
instructions: preInstructions
|
|
7889
|
+
} = yield this.prepareTokenAccounts(
|
|
7022
7890
|
payer,
|
|
7023
|
-
|
|
7024
|
-
tokenAProgram
|
|
7025
|
-
);
|
|
7026
|
-
const payerTokenB = _spltoken.getAssociatedTokenAddressSync.call(void 0,
|
|
7891
|
+
tokenAMint,
|
|
7027
7892
|
tokenBMint,
|
|
7028
|
-
|
|
7029
|
-
true,
|
|
7893
|
+
tokenAProgram,
|
|
7030
7894
|
tokenBProgram
|
|
7031
7895
|
);
|
|
7032
|
-
|
|
7896
|
+
if (tokenAMint.equals(_spltoken.NATIVE_MINT)) {
|
|
7897
|
+
const wrapSOLIx = wrapSOLInstruction(
|
|
7898
|
+
payer,
|
|
7899
|
+
payerTokenA,
|
|
7900
|
+
BigInt(tokenAAmount.toString())
|
|
7901
|
+
);
|
|
7902
|
+
preInstructions.push(...wrapSOLIx);
|
|
7903
|
+
}
|
|
7904
|
+
if (tokenBMint.equals(_spltoken.NATIVE_MINT)) {
|
|
7905
|
+
const wrapSOLIx = wrapSOLInstruction(
|
|
7906
|
+
payer,
|
|
7907
|
+
payerTokenB,
|
|
7908
|
+
BigInt(tokenBAmount.toString())
|
|
7909
|
+
);
|
|
7910
|
+
preInstructions.push(...wrapSOLIx);
|
|
7911
|
+
}
|
|
7912
|
+
const tokenBadgeAccounts = this.getTokenBadgeAccounts(
|
|
7033
7913
|
tokenAMint,
|
|
7034
|
-
|
|
7035
|
-
this._program.programId
|
|
7036
|
-
);
|
|
7037
|
-
const tokenBVault = deriveTokenVaultAddress(
|
|
7038
|
-
tokenBMint,
|
|
7039
|
-
pool,
|
|
7040
|
-
this._program.programId
|
|
7914
|
+
tokenBMint
|
|
7041
7915
|
);
|
|
7042
7916
|
const tx = yield this._program.methods.initializePool({
|
|
7043
|
-
liquidity:
|
|
7044
|
-
sqrtPrice:
|
|
7917
|
+
liquidity: liquidityDelta,
|
|
7918
|
+
sqrtPrice: initSqrtPrice,
|
|
7045
7919
|
activationPoint
|
|
7046
|
-
}).
|
|
7920
|
+
}).accountsPartial({
|
|
7047
7921
|
creator,
|
|
7048
7922
|
positionNftAccount,
|
|
7049
7923
|
positionNftMint: positionNft,
|
|
7050
7924
|
payer,
|
|
7051
7925
|
config,
|
|
7052
|
-
poolAuthority,
|
|
7926
|
+
poolAuthority: this.poolAuthority,
|
|
7053
7927
|
pool,
|
|
7054
7928
|
position,
|
|
7055
7929
|
tokenAMint,
|
|
@@ -7061,13 +7935,16 @@ var CpAmm = class {
|
|
|
7061
7935
|
token2022Program: _spltoken.TOKEN_2022_PROGRAM_ID,
|
|
7062
7936
|
tokenAProgram,
|
|
7063
7937
|
tokenBProgram,
|
|
7064
|
-
systemProgram: _web3js.SystemProgram.programId
|
|
7065
|
-
|
|
7066
|
-
program: this._program.programId
|
|
7067
|
-
}).transaction();
|
|
7938
|
+
systemProgram: _web3js.SystemProgram.programId
|
|
7939
|
+
}).preInstructions(preInstructions).remainingAccounts(tokenBadgeAccounts).transaction();
|
|
7068
7940
|
return tx;
|
|
7069
7941
|
});
|
|
7070
7942
|
}
|
|
7943
|
+
/**
|
|
7944
|
+
* Builds a transaction to create a customizable pool.
|
|
7945
|
+
* @param params - Parameters for customizable pool creation.
|
|
7946
|
+
* @returns Transaction and related addresses.
|
|
7947
|
+
*/
|
|
7071
7948
|
createCustomPool(params) {
|
|
7072
7949
|
return __async(this, null, function* () {
|
|
7073
7950
|
const {
|
|
@@ -7075,8 +7952,10 @@ var CpAmm = class {
|
|
|
7075
7952
|
tokenBMint,
|
|
7076
7953
|
tokenAAmount,
|
|
7077
7954
|
tokenBAmount,
|
|
7078
|
-
|
|
7079
|
-
|
|
7955
|
+
sqrtMinPrice,
|
|
7956
|
+
sqrtMaxPrice,
|
|
7957
|
+
liquidityDelta,
|
|
7958
|
+
initSqrtPrice,
|
|
7080
7959
|
payer,
|
|
7081
7960
|
creator,
|
|
7082
7961
|
positionNft,
|
|
@@ -7088,62 +7967,22 @@ var CpAmm = class {
|
|
|
7088
7967
|
tokenAProgram,
|
|
7089
7968
|
tokenBProgram
|
|
7090
7969
|
} = params;
|
|
7091
|
-
const
|
|
7092
|
-
|
|
7093
|
-
|
|
7094
|
-
|
|
7095
|
-
|
|
7096
|
-
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
|
|
7100
|
-
|
|
7101
|
-
|
|
7102
|
-
tokenBMint,
|
|
7103
|
-
this._program.programId
|
|
7104
|
-
);
|
|
7105
|
-
const position = derivePositionAddress(
|
|
7106
|
-
positionNft,
|
|
7107
|
-
this._program.programId
|
|
7108
|
-
);
|
|
7109
|
-
const positionNftAccount = derivePositionNftAccount(
|
|
7110
|
-
positionNft,
|
|
7111
|
-
this._program.programId
|
|
7112
|
-
);
|
|
7113
|
-
const tokenAVault = deriveTokenVaultAddress(
|
|
7970
|
+
const pool = deriveCustomizablePoolAddress(tokenAMint, tokenBMint);
|
|
7971
|
+
const position = derivePositionAddress(positionNft);
|
|
7972
|
+
const positionNftAccount = derivePositionNftAccount(positionNft);
|
|
7973
|
+
const tokenAVault = deriveTokenVaultAddress(tokenAMint, pool);
|
|
7974
|
+
const tokenBVault = deriveTokenVaultAddress(tokenBMint, pool);
|
|
7975
|
+
const {
|
|
7976
|
+
tokenAAta: payerTokenA,
|
|
7977
|
+
tokenBAta: payerTokenB,
|
|
7978
|
+
instructions: preInstructions
|
|
7979
|
+
} = yield this.prepareTokenAccounts(
|
|
7980
|
+
payer,
|
|
7114
7981
|
tokenAMint,
|
|
7115
|
-
pool,
|
|
7116
|
-
this._program.programId
|
|
7117
|
-
);
|
|
7118
|
-
const tokenBVault = deriveTokenVaultAddress(
|
|
7119
7982
|
tokenBMint,
|
|
7120
|
-
|
|
7121
|
-
|
|
7983
|
+
tokenAProgram,
|
|
7984
|
+
tokenBProgram
|
|
7122
7985
|
);
|
|
7123
|
-
const preInstructions = [];
|
|
7124
|
-
const [
|
|
7125
|
-
{ ataPubkey: payerTokenA, ix: createTokenATokenAccountIx },
|
|
7126
|
-
{ ataPubkey: payerTokenB, ix: createTokenBTokenAccountIx }
|
|
7127
|
-
] = yield Promise.all([
|
|
7128
|
-
getOrCreateATAInstruction(
|
|
7129
|
-
this._program.provider.connection,
|
|
7130
|
-
tokenAMint,
|
|
7131
|
-
payer,
|
|
7132
|
-
payer,
|
|
7133
|
-
true,
|
|
7134
|
-
tokenAProgram
|
|
7135
|
-
),
|
|
7136
|
-
getOrCreateATAInstruction(
|
|
7137
|
-
this._program.provider.connection,
|
|
7138
|
-
tokenBMint,
|
|
7139
|
-
payer,
|
|
7140
|
-
payer,
|
|
7141
|
-
true,
|
|
7142
|
-
tokenBProgram
|
|
7143
|
-
)
|
|
7144
|
-
]);
|
|
7145
|
-
createTokenATokenAccountIx && preInstructions.push(createTokenATokenAccountIx);
|
|
7146
|
-
createTokenBTokenAccountIx && preInstructions.push(createTokenBTokenAccountIx);
|
|
7147
7986
|
if (tokenAMint.equals(_spltoken.NATIVE_MINT)) {
|
|
7148
7987
|
const wrapSOLIx = wrapSOLInstruction(
|
|
7149
7988
|
payer,
|
|
@@ -7160,22 +7999,26 @@ var CpAmm = class {
|
|
|
7160
7999
|
);
|
|
7161
8000
|
preInstructions.push(...wrapSOLIx);
|
|
7162
8001
|
}
|
|
8002
|
+
const tokenBadgeAccounts = this.getTokenBadgeAccounts(
|
|
8003
|
+
tokenAMint,
|
|
8004
|
+
tokenBMint
|
|
8005
|
+
);
|
|
7163
8006
|
const transaction = yield this._program.methods.initializeCustomizablePool({
|
|
7164
8007
|
poolFees,
|
|
7165
|
-
sqrtMinPrice
|
|
7166
|
-
sqrtMaxPrice
|
|
8008
|
+
sqrtMinPrice,
|
|
8009
|
+
sqrtMaxPrice,
|
|
7167
8010
|
hasAlphaVault,
|
|
7168
|
-
liquidity:
|
|
7169
|
-
sqrtPrice:
|
|
8011
|
+
liquidity: liquidityDelta,
|
|
8012
|
+
sqrtPrice: initSqrtPrice,
|
|
7170
8013
|
activationType,
|
|
7171
8014
|
collectFeeMode,
|
|
7172
8015
|
activationPoint
|
|
7173
|
-
}).
|
|
8016
|
+
}).accountsPartial({
|
|
7174
8017
|
creator,
|
|
7175
8018
|
positionNftAccount,
|
|
7176
8019
|
positionNftMint: positionNft,
|
|
7177
8020
|
payer,
|
|
7178
|
-
poolAuthority,
|
|
8021
|
+
poolAuthority: this.poolAuthority,
|
|
7179
8022
|
pool,
|
|
7180
8023
|
position,
|
|
7181
8024
|
tokenAMint,
|
|
@@ -7185,50 +8028,49 @@ var CpAmm = class {
|
|
|
7185
8028
|
payerTokenA,
|
|
7186
8029
|
payerTokenB,
|
|
7187
8030
|
token2022Program: _spltoken.TOKEN_2022_PROGRAM_ID,
|
|
7188
|
-
tokenAProgram
|
|
7189
|
-
tokenBProgram
|
|
7190
|
-
systemProgram: _web3js.SystemProgram.programId
|
|
7191
|
-
|
|
7192
|
-
program: this._program.programId
|
|
7193
|
-
}).preInstructions(preInstructions).transaction();
|
|
8031
|
+
tokenAProgram,
|
|
8032
|
+
tokenBProgram,
|
|
8033
|
+
systemProgram: _web3js.SystemProgram.programId
|
|
8034
|
+
}).preInstructions(preInstructions).remainingAccounts(tokenBadgeAccounts).transaction();
|
|
7194
8035
|
return { tx: transaction, pool, position };
|
|
7195
8036
|
});
|
|
7196
8037
|
}
|
|
8038
|
+
/**
|
|
8039
|
+
* Builds a transaction to create a position.
|
|
8040
|
+
* @param {CreatePositionParams} params - Parameters for position creation.
|
|
8041
|
+
* @returns Transaction builder.
|
|
8042
|
+
*/
|
|
7197
8043
|
createPosition(params) {
|
|
7198
8044
|
return __async(this, null, function* () {
|
|
7199
8045
|
const { owner, payer, pool, positionNft } = params;
|
|
7200
|
-
const
|
|
7201
|
-
const
|
|
7202
|
-
|
|
7203
|
-
this._program.programId
|
|
7204
|
-
);
|
|
7205
|
-
const positionNftAccount = derivePositionNftAccount(
|
|
7206
|
-
positionNft,
|
|
7207
|
-
this._program.programId
|
|
7208
|
-
);
|
|
7209
|
-
return yield this._program.methods.createPosition().accountsStrict({
|
|
8046
|
+
const position = derivePositionAddress(positionNft);
|
|
8047
|
+
const positionNftAccount = derivePositionNftAccount(positionNft);
|
|
8048
|
+
return yield this._program.methods.createPosition().accountsPartial({
|
|
7210
8049
|
owner,
|
|
7211
8050
|
positionNftMint: positionNft,
|
|
7212
|
-
poolAuthority,
|
|
8051
|
+
poolAuthority: this.poolAuthority,
|
|
7213
8052
|
positionNftAccount,
|
|
7214
8053
|
payer,
|
|
7215
8054
|
pool,
|
|
7216
8055
|
position,
|
|
7217
8056
|
tokenProgram: _spltoken.TOKEN_2022_PROGRAM_ID,
|
|
7218
|
-
systemProgram: _web3js.SystemProgram.programId
|
|
7219
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
7220
|
-
program: this._program.programId
|
|
8057
|
+
systemProgram: _web3js.SystemProgram.programId
|
|
7221
8058
|
}).transaction();
|
|
7222
8059
|
});
|
|
7223
8060
|
}
|
|
8061
|
+
/**
|
|
8062
|
+
* Builds a transaction to add liquidity to an existing position.
|
|
8063
|
+
* @param {AddLiquidityParams} params - Parameters for adding liquidity.
|
|
8064
|
+
* @returns Transaction builder.
|
|
8065
|
+
*/
|
|
7224
8066
|
addLiquidity(params) {
|
|
7225
8067
|
return __async(this, null, function* () {
|
|
7226
8068
|
const {
|
|
7227
8069
|
owner,
|
|
7228
8070
|
pool,
|
|
7229
8071
|
position,
|
|
7230
|
-
|
|
7231
|
-
|
|
8072
|
+
positionNftAccount,
|
|
8073
|
+
liquidityDelta,
|
|
7232
8074
|
maxAmountTokenA,
|
|
7233
8075
|
maxAmountTokenB,
|
|
7234
8076
|
tokenAAmountThreshold,
|
|
@@ -7240,34 +8082,17 @@ var CpAmm = class {
|
|
|
7240
8082
|
tokenAProgram,
|
|
7241
8083
|
tokenBProgram
|
|
7242
8084
|
} = params;
|
|
7243
|
-
const
|
|
7244
|
-
|
|
7245
|
-
|
|
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
|
|
7246
8095
|
);
|
|
7247
|
-
const preInstructions = [];
|
|
7248
|
-
const [
|
|
7249
|
-
{ ataPubkey: tokenAAccount, ix: createTokenATokenAccountIx },
|
|
7250
|
-
{ ataPubkey: tokenBAccount, ix: createTokenBTokenAccountIx }
|
|
7251
|
-
] = yield Promise.all([
|
|
7252
|
-
getOrCreateATAInstruction(
|
|
7253
|
-
this._program.provider.connection,
|
|
7254
|
-
tokenAMint,
|
|
7255
|
-
owner,
|
|
7256
|
-
owner,
|
|
7257
|
-
true,
|
|
7258
|
-
tokenAProgram
|
|
7259
|
-
),
|
|
7260
|
-
getOrCreateATAInstruction(
|
|
7261
|
-
this._program.provider.connection,
|
|
7262
|
-
tokenBMint,
|
|
7263
|
-
owner,
|
|
7264
|
-
owner,
|
|
7265
|
-
true,
|
|
7266
|
-
tokenBProgram
|
|
7267
|
-
)
|
|
7268
|
-
]);
|
|
7269
|
-
createTokenATokenAccountIx && preInstructions.push(createTokenATokenAccountIx);
|
|
7270
|
-
createTokenBTokenAccountIx && preInstructions.push(createTokenBTokenAccountIx);
|
|
7271
8096
|
if (tokenAMint.equals(_spltoken.NATIVE_MINT)) {
|
|
7272
8097
|
const wrapSOLIx = wrapSOLInstruction(
|
|
7273
8098
|
owner,
|
|
@@ -7291,11 +8116,7 @@ var CpAmm = class {
|
|
|
7291
8116
|
const closeWrappedSOLIx = yield unwrapSOLInstruction(owner);
|
|
7292
8117
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
7293
8118
|
}
|
|
7294
|
-
|
|
7295
|
-
liquidityDelta: liquidityDeltaQ64,
|
|
7296
|
-
tokenAAmountThreshold,
|
|
7297
|
-
tokenBAmountThreshold
|
|
7298
|
-
}).accountsStrict({
|
|
8119
|
+
const addLiquidityInstruction = yield this.buildAddLiquidityInstruction({
|
|
7299
8120
|
pool,
|
|
7300
8121
|
position,
|
|
7301
8122
|
positionNftAccount,
|
|
@@ -7308,19 +8129,32 @@ var CpAmm = class {
|
|
|
7308
8129
|
tokenBVault,
|
|
7309
8130
|
tokenAProgram,
|
|
7310
8131
|
tokenBProgram,
|
|
7311
|
-
|
|
7312
|
-
|
|
7313
|
-
|
|
8132
|
+
liquidityDelta,
|
|
8133
|
+
tokenAAmountThreshold,
|
|
8134
|
+
tokenBAmountThreshold
|
|
8135
|
+
});
|
|
8136
|
+
const transaction = new (0, _web3js.Transaction)();
|
|
8137
|
+
transaction.add(
|
|
8138
|
+
...preInstructions.length > 0 ? preInstructions : [],
|
|
8139
|
+
addLiquidityInstruction,
|
|
8140
|
+
...postInstructions.length > 0 ? postInstructions : []
|
|
8141
|
+
);
|
|
8142
|
+
return transaction;
|
|
7314
8143
|
});
|
|
7315
8144
|
}
|
|
8145
|
+
/**
|
|
8146
|
+
* Builds a transaction to remove liquidity from a position.
|
|
8147
|
+
* @param {RemoveLiquidityParams} params - Parameters for removing liquidity.
|
|
8148
|
+
* @returns Transaction builder.
|
|
8149
|
+
*/
|
|
7316
8150
|
removeLiquidity(params) {
|
|
7317
8151
|
return __async(this, null, function* () {
|
|
7318
8152
|
const {
|
|
7319
8153
|
owner,
|
|
7320
8154
|
pool,
|
|
7321
8155
|
position,
|
|
7322
|
-
|
|
7323
|
-
|
|
8156
|
+
positionNftAccount,
|
|
8157
|
+
liquidityDelta,
|
|
7324
8158
|
tokenAAmountThreshold,
|
|
7325
8159
|
tokenBAmountThreshold,
|
|
7326
8160
|
tokenAMint,
|
|
@@ -7330,35 +8164,17 @@ var CpAmm = class {
|
|
|
7330
8164
|
tokenAProgram,
|
|
7331
8165
|
tokenBProgram
|
|
7332
8166
|
} = params;
|
|
7333
|
-
const
|
|
7334
|
-
|
|
7335
|
-
|
|
8167
|
+
const {
|
|
8168
|
+
tokenAAta: tokenAAccount,
|
|
8169
|
+
tokenBAta: tokenBAccount,
|
|
8170
|
+
instructions: preInstructions
|
|
8171
|
+
} = yield this.prepareTokenAccounts(
|
|
8172
|
+
owner,
|
|
8173
|
+
tokenAMint,
|
|
8174
|
+
tokenBMint,
|
|
8175
|
+
tokenAProgram,
|
|
8176
|
+
tokenBProgram
|
|
7336
8177
|
);
|
|
7337
|
-
const poolAuthority = derivePoolAuthority(this._program.programId);
|
|
7338
|
-
const preInstructions = [];
|
|
7339
|
-
const [
|
|
7340
|
-
{ ataPubkey: tokenAAccount, ix: createTokenAAccountIx },
|
|
7341
|
-
{ ataPubkey: tokenBAccount, ix: createTokenBAccountIx }
|
|
7342
|
-
] = yield Promise.all([
|
|
7343
|
-
getOrCreateATAInstruction(
|
|
7344
|
-
this._program.provider.connection,
|
|
7345
|
-
tokenAMint,
|
|
7346
|
-
owner,
|
|
7347
|
-
owner,
|
|
7348
|
-
true,
|
|
7349
|
-
tokenAProgram
|
|
7350
|
-
),
|
|
7351
|
-
getOrCreateATAInstruction(
|
|
7352
|
-
this._program.provider.connection,
|
|
7353
|
-
tokenBMint,
|
|
7354
|
-
owner,
|
|
7355
|
-
owner,
|
|
7356
|
-
true,
|
|
7357
|
-
tokenBProgram
|
|
7358
|
-
)
|
|
7359
|
-
]);
|
|
7360
|
-
createTokenAAccountIx && preInstructions.push(createTokenAAccountIx);
|
|
7361
|
-
createTokenBAccountIx && preInstructions.push(createTokenBAccountIx);
|
|
7362
8178
|
const postInstructions = [];
|
|
7363
8179
|
if ([tokenAMint.toBase58(), tokenBMint.toBase58()].includes(
|
|
7364
8180
|
_spltoken.NATIVE_MINT.toBase58()
|
|
@@ -7367,11 +8183,11 @@ var CpAmm = class {
|
|
|
7367
8183
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
7368
8184
|
}
|
|
7369
8185
|
return yield this._program.methods.removeLiquidity({
|
|
7370
|
-
liquidityDelta
|
|
8186
|
+
liquidityDelta,
|
|
7371
8187
|
tokenAAmountThreshold,
|
|
7372
8188
|
tokenBAmountThreshold
|
|
7373
|
-
}).
|
|
7374
|
-
poolAuthority,
|
|
8189
|
+
}).accountsPartial({
|
|
8190
|
+
poolAuthority: this.poolAuthority,
|
|
7375
8191
|
pool,
|
|
7376
8192
|
position,
|
|
7377
8193
|
positionNftAccount,
|
|
@@ -7383,12 +8199,80 @@ var CpAmm = class {
|
|
|
7383
8199
|
tokenAVault,
|
|
7384
8200
|
tokenBVault,
|
|
7385
8201
|
tokenAProgram,
|
|
7386
|
-
tokenBProgram
|
|
7387
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
7388
|
-
program: this._program.programId
|
|
8202
|
+
tokenBProgram
|
|
7389
8203
|
}).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
7390
8204
|
});
|
|
7391
8205
|
}
|
|
8206
|
+
/**
|
|
8207
|
+
* Builds a transaction to remove liquidity from a position.
|
|
8208
|
+
* @param {RemoveLiquidityParams} params - Parameters for removing liquidity.
|
|
8209
|
+
* @returns Transaction builder.
|
|
8210
|
+
*/
|
|
8211
|
+
removeAllLiquidity(params) {
|
|
8212
|
+
return __async(this, null, function* () {
|
|
8213
|
+
const {
|
|
8214
|
+
owner,
|
|
8215
|
+
pool,
|
|
8216
|
+
position,
|
|
8217
|
+
positionNftAccount,
|
|
8218
|
+
tokenAAmountThreshold,
|
|
8219
|
+
tokenBAmountThreshold,
|
|
8220
|
+
tokenAMint,
|
|
8221
|
+
tokenBMint,
|
|
8222
|
+
tokenAVault,
|
|
8223
|
+
tokenBVault,
|
|
8224
|
+
tokenAProgram,
|
|
8225
|
+
tokenBProgram
|
|
8226
|
+
} = params;
|
|
8227
|
+
const {
|
|
8228
|
+
tokenAAta: tokenAAccount,
|
|
8229
|
+
tokenBAta: tokenBAccount,
|
|
8230
|
+
instructions: preInstructions
|
|
8231
|
+
} = yield this.prepareTokenAccounts(
|
|
8232
|
+
owner,
|
|
8233
|
+
tokenAMint,
|
|
8234
|
+
tokenBMint,
|
|
8235
|
+
tokenAProgram,
|
|
8236
|
+
tokenBProgram
|
|
8237
|
+
);
|
|
8238
|
+
const postInstructions = [];
|
|
8239
|
+
if ([tokenAMint.toBase58(), tokenBMint.toBase58()].includes(
|
|
8240
|
+
_spltoken.NATIVE_MINT.toBase58()
|
|
8241
|
+
)) {
|
|
8242
|
+
const closeWrappedSOLIx = yield unwrapSOLInstruction(owner);
|
|
8243
|
+
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
8244
|
+
}
|
|
8245
|
+
const removeAllLiquidityInstruction = yield this.buildRemoveAllLiquidityInstruction({
|
|
8246
|
+
poolAuthority: this.poolAuthority,
|
|
8247
|
+
owner,
|
|
8248
|
+
pool,
|
|
8249
|
+
position,
|
|
8250
|
+
positionNftAccount,
|
|
8251
|
+
tokenAAccount,
|
|
8252
|
+
tokenBAccount,
|
|
8253
|
+
tokenAAmountThreshold,
|
|
8254
|
+
tokenBAmountThreshold,
|
|
8255
|
+
tokenAMint,
|
|
8256
|
+
tokenBMint,
|
|
8257
|
+
tokenAVault,
|
|
8258
|
+
tokenBVault,
|
|
8259
|
+
tokenAProgram,
|
|
8260
|
+
tokenBProgram
|
|
8261
|
+
});
|
|
8262
|
+
const transaction = new (0, _web3js.Transaction)();
|
|
8263
|
+
transaction.add(
|
|
8264
|
+
...preInstructions.length > 0 ? preInstructions : [],
|
|
8265
|
+
removeAllLiquidityInstruction,
|
|
8266
|
+
...postInstructions.length > 0 ? postInstructions : []
|
|
8267
|
+
);
|
|
8268
|
+
return transaction;
|
|
8269
|
+
});
|
|
8270
|
+
}
|
|
8271
|
+
/**
|
|
8272
|
+
* Builds a transaction to perform a swap in the pool.
|
|
8273
|
+
* @param {SwapParams} params - Parameters for swapping tokens.
|
|
8274
|
+
* @returns Transaction builder.
|
|
8275
|
+
*/
|
|
7392
8276
|
swap(params) {
|
|
7393
8277
|
return __async(this, null, function* () {
|
|
7394
8278
|
const {
|
|
@@ -7406,31 +8290,20 @@ var CpAmm = class {
|
|
|
7406
8290
|
tokenBProgram,
|
|
7407
8291
|
referralTokenAccount
|
|
7408
8292
|
} = params;
|
|
7409
|
-
const
|
|
7410
|
-
|
|
7411
|
-
|
|
7412
|
-
|
|
7413
|
-
|
|
7414
|
-
|
|
7415
|
-
|
|
7416
|
-
|
|
7417
|
-
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
|
|
7421
|
-
|
|
7422
|
-
|
|
7423
|
-
getOrCreateATAInstruction(
|
|
7424
|
-
this._program.provider.connection,
|
|
7425
|
-
outputTokenMint,
|
|
7426
|
-
payer,
|
|
7427
|
-
payer,
|
|
7428
|
-
true,
|
|
7429
|
-
tokenBProgram
|
|
7430
|
-
)
|
|
7431
|
-
]);
|
|
7432
|
-
createInputTokenAccountIx && preInstructions.push(createInputTokenAccountIx);
|
|
7433
|
-
createOutputTokenAccountIx && preInstructions.push(createOutputTokenAccountIx);
|
|
8293
|
+
const [inputTokenProgram, outputTokenProgram] = inputTokenMint.equals(
|
|
8294
|
+
tokenAMint
|
|
8295
|
+
) ? [tokenAProgram, tokenBProgram] : [tokenBProgram, tokenAProgram];
|
|
8296
|
+
const {
|
|
8297
|
+
tokenAAta: inputTokenAccount,
|
|
8298
|
+
tokenBAta: outputTokenAccount,
|
|
8299
|
+
instructions: preInstructions
|
|
8300
|
+
} = yield this.prepareTokenAccounts(
|
|
8301
|
+
payer,
|
|
8302
|
+
inputTokenMint,
|
|
8303
|
+
outputTokenMint,
|
|
8304
|
+
inputTokenProgram,
|
|
8305
|
+
outputTokenProgram
|
|
8306
|
+
);
|
|
7434
8307
|
if (inputTokenMint.equals(_spltoken.NATIVE_MINT)) {
|
|
7435
8308
|
const wrapSOLIx = wrapSOLInstruction(
|
|
7436
8309
|
payer,
|
|
@@ -7449,8 +8322,8 @@ var CpAmm = class {
|
|
|
7449
8322
|
return yield this._program.methods.swap({
|
|
7450
8323
|
amountIn,
|
|
7451
8324
|
minimumAmountOut
|
|
7452
|
-
}).
|
|
7453
|
-
poolAuthority,
|
|
8325
|
+
}).accountsPartial({
|
|
8326
|
+
poolAuthority: this.poolAuthority,
|
|
7454
8327
|
pool,
|
|
7455
8328
|
payer,
|
|
7456
8329
|
inputTokenAccount,
|
|
@@ -7461,12 +8334,15 @@ var CpAmm = class {
|
|
|
7461
8334
|
tokenBMint,
|
|
7462
8335
|
tokenAProgram,
|
|
7463
8336
|
tokenBProgram,
|
|
7464
|
-
referralTokenAccount
|
|
7465
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
7466
|
-
program: this._program.programId
|
|
8337
|
+
referralTokenAccount
|
|
7467
8338
|
}).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
7468
8339
|
});
|
|
7469
8340
|
}
|
|
8341
|
+
/**
|
|
8342
|
+
* Builds a transaction to lock a position with vesting schedule.
|
|
8343
|
+
* @param {LockPositionParams} params - Locking parameters.
|
|
8344
|
+
* @returns Transaction builder.
|
|
8345
|
+
*/
|
|
7470
8346
|
lockPosition(params) {
|
|
7471
8347
|
return __async(this, null, function* () {
|
|
7472
8348
|
const {
|
|
@@ -7475,64 +8351,56 @@ var CpAmm = class {
|
|
|
7475
8351
|
payer,
|
|
7476
8352
|
vestingAccount,
|
|
7477
8353
|
position,
|
|
7478
|
-
|
|
8354
|
+
positionNftAccount,
|
|
7479
8355
|
cliffPoint,
|
|
7480
8356
|
periodFrequency,
|
|
7481
8357
|
cliffUnlockLiquidity,
|
|
7482
8358
|
liquidityPerPeriod,
|
|
7483
|
-
numberOfPeriod
|
|
7484
|
-
vestings
|
|
8359
|
+
numberOfPeriod
|
|
7485
8360
|
} = params;
|
|
7486
|
-
const positionNftAccount = derivePositionNftAccount(
|
|
7487
|
-
positionNftMint,
|
|
7488
|
-
this._program.programId
|
|
7489
|
-
);
|
|
7490
8361
|
const lockPositionParams = {
|
|
7491
8362
|
cliffPoint,
|
|
7492
8363
|
periodFrequency,
|
|
7493
8364
|
cliffUnlockLiquidity,
|
|
7494
8365
|
liquidityPerPeriod,
|
|
7495
|
-
numberOfPeriod
|
|
7496
|
-
index: vestings.length
|
|
8366
|
+
numberOfPeriod
|
|
7497
8367
|
};
|
|
7498
|
-
return yield this._program.methods.lockPosition(lockPositionParams).
|
|
8368
|
+
return yield this._program.methods.lockPosition(lockPositionParams).accountsPartial({
|
|
7499
8369
|
position,
|
|
7500
8370
|
positionNftAccount,
|
|
7501
8371
|
vesting: vestingAccount,
|
|
7502
8372
|
pool,
|
|
7503
8373
|
owner,
|
|
7504
8374
|
payer,
|
|
7505
|
-
systemProgram: _web3js.SystemProgram.programId
|
|
7506
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
7507
|
-
program: this._program.programId
|
|
8375
|
+
systemProgram: _web3js.SystemProgram.programId
|
|
7508
8376
|
}).transaction();
|
|
7509
8377
|
});
|
|
7510
8378
|
}
|
|
8379
|
+
/**
|
|
8380
|
+
* Builds a transaction to permanently lock a position.
|
|
8381
|
+
* @param {PermanentLockParams} params - Parameters for permanent locking.
|
|
8382
|
+
* @returns Transaction builder.
|
|
8383
|
+
*/
|
|
7511
8384
|
permanentLockPosition(params) {
|
|
7512
8385
|
return __async(this, null, function* () {
|
|
7513
|
-
const { owner, position,
|
|
7514
|
-
|
|
7515
|
-
positionNftMint,
|
|
7516
|
-
this._program.programId
|
|
7517
|
-
);
|
|
7518
|
-
return yield this._program.methods.permanentLockPosition(unlockedLiquidity).accountsStrict({
|
|
8386
|
+
const { owner, position, positionNftAccount, pool, unlockedLiquidity } = params;
|
|
8387
|
+
return yield this._program.methods.permanentLockPosition(unlockedLiquidity).accountsPartial({
|
|
7519
8388
|
position,
|
|
7520
8389
|
positionNftAccount,
|
|
7521
8390
|
pool,
|
|
7522
|
-
owner
|
|
7523
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
7524
|
-
program: this._program.programId
|
|
8391
|
+
owner
|
|
7525
8392
|
}).transaction();
|
|
7526
8393
|
});
|
|
7527
8394
|
}
|
|
8395
|
+
/**
|
|
8396
|
+
* Builds a transaction to refresh vesting status of a position.
|
|
8397
|
+
* @param {RefreshVestingParams} params - Refresh vesting parameters.
|
|
8398
|
+
* @returns Transaction builder.
|
|
8399
|
+
*/
|
|
7528
8400
|
refreshVesting(params) {
|
|
7529
8401
|
return __async(this, null, function* () {
|
|
7530
|
-
const { owner, position,
|
|
7531
|
-
|
|
7532
|
-
positionNftMint,
|
|
7533
|
-
this._program.programId
|
|
7534
|
-
);
|
|
7535
|
-
return yield this._program.methods.refreshVesting().accountsStrict({
|
|
8402
|
+
const { owner, position, positionNftAccount, pool, vestings } = params;
|
|
8403
|
+
return yield this._program.methods.refreshVesting().accountsPartial({
|
|
7536
8404
|
position,
|
|
7537
8405
|
positionNftAccount,
|
|
7538
8406
|
pool,
|
|
@@ -7548,13 +8416,18 @@ var CpAmm = class {
|
|
|
7548
8416
|
).transaction();
|
|
7549
8417
|
});
|
|
7550
8418
|
}
|
|
8419
|
+
/**
|
|
8420
|
+
* Builds a transaction to claim position fee rewards.
|
|
8421
|
+
* @param {ClaimPositionFeeParams} params - Parameters for claiming position fee.
|
|
8422
|
+
* @returns Transaction builder.
|
|
8423
|
+
*/
|
|
7551
8424
|
claimPositionFee(params) {
|
|
7552
8425
|
return __async(this, null, function* () {
|
|
7553
8426
|
const {
|
|
7554
8427
|
owner,
|
|
7555
8428
|
pool,
|
|
7556
8429
|
position,
|
|
7557
|
-
|
|
8430
|
+
positionNftAccount,
|
|
7558
8431
|
tokenAVault,
|
|
7559
8432
|
tokenBVault,
|
|
7560
8433
|
tokenAMint,
|
|
@@ -7562,35 +8435,17 @@ var CpAmm = class {
|
|
|
7562
8435
|
tokenAProgram,
|
|
7563
8436
|
tokenBProgram
|
|
7564
8437
|
} = params;
|
|
7565
|
-
const
|
|
7566
|
-
|
|
7567
|
-
|
|
8438
|
+
const {
|
|
8439
|
+
tokenAAta: tokenAAccount,
|
|
8440
|
+
tokenBAta: tokenBAccount,
|
|
8441
|
+
instructions: preInstructions
|
|
8442
|
+
} = yield this.prepareTokenAccounts(
|
|
8443
|
+
owner,
|
|
8444
|
+
tokenAMint,
|
|
8445
|
+
tokenBMint,
|
|
8446
|
+
tokenAProgram,
|
|
8447
|
+
tokenBProgram
|
|
7568
8448
|
);
|
|
7569
|
-
const poolAuthority = derivePoolAuthority(this._program.programId);
|
|
7570
|
-
const preInstructions = [];
|
|
7571
|
-
const [
|
|
7572
|
-
{ ataPubkey: tokenAAccount, ix: createTokenAAccountIx },
|
|
7573
|
-
{ ataPubkey: tokenBAccount, ix: createTokenBAccountIx }
|
|
7574
|
-
] = yield Promise.all([
|
|
7575
|
-
getOrCreateATAInstruction(
|
|
7576
|
-
this._program.provider.connection,
|
|
7577
|
-
tokenAMint,
|
|
7578
|
-
owner,
|
|
7579
|
-
owner,
|
|
7580
|
-
true,
|
|
7581
|
-
tokenAProgram
|
|
7582
|
-
),
|
|
7583
|
-
getOrCreateATAInstruction(
|
|
7584
|
-
this._program.provider.connection,
|
|
7585
|
-
tokenBMint,
|
|
7586
|
-
owner,
|
|
7587
|
-
owner,
|
|
7588
|
-
true,
|
|
7589
|
-
tokenBProgram
|
|
7590
|
-
)
|
|
7591
|
-
]);
|
|
7592
|
-
createTokenAAccountIx && preInstructions.push(createTokenAAccountIx);
|
|
7593
|
-
createTokenBAccountIx && preInstructions.push(createTokenBAccountIx);
|
|
7594
8449
|
const postInstructions = [];
|
|
7595
8450
|
if ([tokenAMint.toBase58(), tokenBMint.toBase58()].includes(
|
|
7596
8451
|
_spltoken.NATIVE_MINT.toBase58()
|
|
@@ -7598,47 +8453,303 @@ var CpAmm = class {
|
|
|
7598
8453
|
const closeWrappedSOLIx = yield unwrapSOLInstruction(owner);
|
|
7599
8454
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
7600
8455
|
}
|
|
7601
|
-
|
|
7602
|
-
|
|
8456
|
+
const claimPositionFeeInstruction = yield this.buildClaimPositionFeeInstruction({
|
|
8457
|
+
owner,
|
|
8458
|
+
poolAuthority: this.poolAuthority,
|
|
8459
|
+
pool,
|
|
8460
|
+
position,
|
|
8461
|
+
positionNftAccount,
|
|
8462
|
+
tokenAAccount,
|
|
8463
|
+
tokenBAccount,
|
|
8464
|
+
tokenAVault,
|
|
8465
|
+
tokenBVault,
|
|
8466
|
+
tokenAMint,
|
|
8467
|
+
tokenBMint,
|
|
8468
|
+
tokenAProgram,
|
|
8469
|
+
tokenBProgram
|
|
8470
|
+
});
|
|
8471
|
+
const transaction = new (0, _web3js.Transaction)();
|
|
8472
|
+
transaction.add(
|
|
8473
|
+
...preInstructions.length > 0 ? preInstructions : [],
|
|
8474
|
+
claimPositionFeeInstruction,
|
|
8475
|
+
...postInstructions.length > 0 ? postInstructions : []
|
|
8476
|
+
);
|
|
8477
|
+
return transaction;
|
|
8478
|
+
});
|
|
8479
|
+
}
|
|
8480
|
+
closePosition(params) {
|
|
8481
|
+
return __async(this, null, function* () {
|
|
8482
|
+
const { owner, pool, position, positionNftMint, positionNftAccount } = params;
|
|
8483
|
+
const instruction = yield this.buildClosePositionInstruction({
|
|
8484
|
+
owner,
|
|
8485
|
+
poolAuthority: this.poolAuthority,
|
|
8486
|
+
pool,
|
|
8487
|
+
position,
|
|
8488
|
+
positionNftMint,
|
|
8489
|
+
positionNftAccount
|
|
8490
|
+
});
|
|
8491
|
+
return new (0, _web3js.Transaction)().add(instruction);
|
|
8492
|
+
});
|
|
8493
|
+
}
|
|
8494
|
+
/**
|
|
8495
|
+
* Builds a transaction to remove all liquidity from a position and close it.
|
|
8496
|
+
* This combines several operations in a single transaction:
|
|
8497
|
+
* 1. Claims any accumulated fees
|
|
8498
|
+
* 2. Removes all liquidity
|
|
8499
|
+
* 3. Closes the position
|
|
8500
|
+
*
|
|
8501
|
+
* @param {RemoveAllLiquidityAndClosePositionParams} params - Combined parameters
|
|
8502
|
+
* @returns {TxBuilder} Transaction builder with all required instructions
|
|
8503
|
+
* @throws {Error} If the position is locked or cannot be closed
|
|
8504
|
+
*/
|
|
8505
|
+
removeAllLiquidityAndClosePosition(params) {
|
|
8506
|
+
return __async(this, null, function* () {
|
|
8507
|
+
const {
|
|
8508
|
+
owner,
|
|
8509
|
+
position,
|
|
8510
|
+
positionNftAccount,
|
|
8511
|
+
positionState,
|
|
8512
|
+
poolState,
|
|
8513
|
+
tokenAAmountThreshold,
|
|
8514
|
+
tokenBAmountThreshold
|
|
8515
|
+
} = params;
|
|
8516
|
+
const { nftMint: positionNftMint, pool } = positionState;
|
|
8517
|
+
const { tokenAMint, tokenBMint, tokenAVault, tokenBVault } = poolState;
|
|
8518
|
+
const isLockedPosition = this.isLockedPosition(positionState);
|
|
8519
|
+
if (isLockedPosition) {
|
|
8520
|
+
throw Error("position must be unlocked");
|
|
8521
|
+
}
|
|
8522
|
+
const tokenAProgram = getTokenProgram(poolState.tokenAFlag);
|
|
8523
|
+
const tokenBProgram = getTokenProgram(poolState.tokenBFlag);
|
|
8524
|
+
const {
|
|
8525
|
+
tokenAAta: tokenAAccount,
|
|
8526
|
+
tokenBAta: tokenBAccount,
|
|
8527
|
+
instructions: preInstructions
|
|
8528
|
+
} = yield this.prepareTokenAccounts(
|
|
8529
|
+
owner,
|
|
8530
|
+
tokenAMint,
|
|
8531
|
+
tokenBMint,
|
|
8532
|
+
tokenAProgram,
|
|
8533
|
+
tokenBProgram
|
|
8534
|
+
);
|
|
8535
|
+
const postInstructions = [];
|
|
8536
|
+
if ([tokenAMint.toBase58(), tokenBMint.toBase58()].includes(
|
|
8537
|
+
_spltoken.NATIVE_MINT.toBase58()
|
|
8538
|
+
)) {
|
|
8539
|
+
const closeWrappedSOLIx = yield unwrapSOLInstruction(owner);
|
|
8540
|
+
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
8541
|
+
}
|
|
8542
|
+
const transaction = new (0, _web3js.Transaction)();
|
|
8543
|
+
if (preInstructions.length > 0) {
|
|
8544
|
+
transaction.add(...preInstructions);
|
|
8545
|
+
}
|
|
8546
|
+
const claimPositionFeeInstruction = yield this.buildClaimPositionFeeInstruction({
|
|
8547
|
+
owner,
|
|
8548
|
+
poolAuthority: this.poolAuthority,
|
|
8549
|
+
pool,
|
|
8550
|
+
position,
|
|
8551
|
+
positionNftAccount,
|
|
8552
|
+
tokenAAccount,
|
|
8553
|
+
tokenBAccount,
|
|
8554
|
+
tokenAVault,
|
|
8555
|
+
tokenBVault,
|
|
8556
|
+
tokenAMint,
|
|
8557
|
+
tokenBMint,
|
|
8558
|
+
tokenAProgram,
|
|
8559
|
+
tokenBProgram
|
|
8560
|
+
});
|
|
8561
|
+
transaction.add(claimPositionFeeInstruction);
|
|
8562
|
+
const removeAllLiquidityInstruction = yield this.buildRemoveAllLiquidityInstruction({
|
|
8563
|
+
poolAuthority: this.poolAuthority,
|
|
7603
8564
|
owner,
|
|
7604
8565
|
pool,
|
|
7605
8566
|
position,
|
|
7606
8567
|
positionNftAccount,
|
|
7607
8568
|
tokenAAccount,
|
|
7608
8569
|
tokenBAccount,
|
|
8570
|
+
tokenAAmountThreshold,
|
|
8571
|
+
tokenBAmountThreshold,
|
|
8572
|
+
tokenAMint,
|
|
8573
|
+
tokenBMint,
|
|
8574
|
+
tokenAVault,
|
|
8575
|
+
tokenBVault,
|
|
8576
|
+
tokenAProgram,
|
|
8577
|
+
tokenBProgram
|
|
8578
|
+
});
|
|
8579
|
+
transaction.add(removeAllLiquidityInstruction);
|
|
8580
|
+
const closePositionInstruction = yield this.buildClosePositionInstruction({
|
|
8581
|
+
owner,
|
|
8582
|
+
poolAuthority: this.poolAuthority,
|
|
8583
|
+
pool,
|
|
8584
|
+
position,
|
|
8585
|
+
positionNftMint,
|
|
8586
|
+
positionNftAccount
|
|
8587
|
+
});
|
|
8588
|
+
transaction.add(closePositionInstruction);
|
|
8589
|
+
if (postInstructions.length > 0) {
|
|
8590
|
+
transaction.add(...postInstructions);
|
|
8591
|
+
}
|
|
8592
|
+
return transaction;
|
|
8593
|
+
});
|
|
8594
|
+
}
|
|
8595
|
+
/**
|
|
8596
|
+
* Builds a transaction to merge liquidity from one position into another.
|
|
8597
|
+
* This process:
|
|
8598
|
+
* 1. Claims fees from the source position
|
|
8599
|
+
* 2. Removes all liquidity from the source position
|
|
8600
|
+
* 3. Adds that liquidity to the target position
|
|
8601
|
+
* 4. Closes the source position
|
|
8602
|
+
*
|
|
8603
|
+
* @param {MergePositionParams} params - Parameters for merging positions
|
|
8604
|
+
* @returns {TxBuilder} Transaction builder with all required instructions
|
|
8605
|
+
* @throws {Error} If either position is locked or incompatible
|
|
8606
|
+
*/
|
|
8607
|
+
mergePosition(params) {
|
|
8608
|
+
return __async(this, null, function* () {
|
|
8609
|
+
const {
|
|
8610
|
+
owner,
|
|
8611
|
+
positionA,
|
|
8612
|
+
positionB,
|
|
8613
|
+
positionBState,
|
|
8614
|
+
poolState,
|
|
8615
|
+
positionBNftAccount,
|
|
8616
|
+
positionANftAccount,
|
|
8617
|
+
tokenAAmountAddLiquidityThreshold,
|
|
8618
|
+
tokenBAmountAddLiquidityThreshold,
|
|
8619
|
+
tokenAAmountRemoveLiquidityThreshold,
|
|
8620
|
+
tokenBAmountRemoveLiquidityThreshold
|
|
8621
|
+
} = params;
|
|
8622
|
+
const isLockedPosition = this.isLockedPosition(positionBState);
|
|
8623
|
+
if (isLockedPosition) {
|
|
8624
|
+
throw Error("position must be unlocked");
|
|
8625
|
+
}
|
|
8626
|
+
const postionBLiquidityDelta = positionBState.unlockedLiquidity;
|
|
8627
|
+
const pool = positionBState.pool;
|
|
8628
|
+
const { tokenAMint, tokenBMint, tokenAVault, tokenBVault } = poolState;
|
|
8629
|
+
const tokenAProgram = getTokenProgram(poolState.tokenAFlag);
|
|
8630
|
+
const tokenBProgram = getTokenProgram(poolState.tokenBFlag);
|
|
8631
|
+
const {
|
|
8632
|
+
tokenAAta: tokenAAccount,
|
|
8633
|
+
tokenBAta: tokenBAccount,
|
|
8634
|
+
instructions: preInstructions
|
|
8635
|
+
} = yield this.prepareTokenAccounts(
|
|
8636
|
+
owner,
|
|
8637
|
+
tokenAMint,
|
|
8638
|
+
tokenBMint,
|
|
8639
|
+
tokenAProgram,
|
|
8640
|
+
tokenBProgram
|
|
8641
|
+
);
|
|
8642
|
+
const postInstructions = [];
|
|
8643
|
+
if ([tokenAMint.toBase58(), tokenBMint.toBase58()].includes(
|
|
8644
|
+
_spltoken.NATIVE_MINT.toBase58()
|
|
8645
|
+
)) {
|
|
8646
|
+
const closeWrappedSOLIx = yield unwrapSOLInstruction(owner);
|
|
8647
|
+
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
8648
|
+
}
|
|
8649
|
+
const transaction = new (0, _web3js.Transaction)();
|
|
8650
|
+
if (preInstructions.length > 0) {
|
|
8651
|
+
transaction.add(...preInstructions);
|
|
8652
|
+
}
|
|
8653
|
+
const claimPositionFeeInstruction = yield this.buildClaimPositionFeeInstruction({
|
|
8654
|
+
owner,
|
|
8655
|
+
poolAuthority: this.poolAuthority,
|
|
8656
|
+
pool,
|
|
8657
|
+
position: positionB,
|
|
8658
|
+
positionNftAccount: positionBNftAccount,
|
|
8659
|
+
tokenAAccount,
|
|
8660
|
+
tokenBAccount,
|
|
8661
|
+
tokenAVault,
|
|
8662
|
+
tokenBVault,
|
|
8663
|
+
tokenAMint,
|
|
8664
|
+
tokenBMint,
|
|
8665
|
+
tokenAProgram,
|
|
8666
|
+
tokenBProgram
|
|
8667
|
+
});
|
|
8668
|
+
transaction.add(claimPositionFeeInstruction);
|
|
8669
|
+
const removeAllLiquidityInstruction = yield this.buildRemoveAllLiquidityInstruction({
|
|
8670
|
+
poolAuthority: this.poolAuthority,
|
|
8671
|
+
owner,
|
|
8672
|
+
pool,
|
|
8673
|
+
position: positionB,
|
|
8674
|
+
positionNftAccount: positionBNftAccount,
|
|
8675
|
+
tokenAAccount,
|
|
8676
|
+
tokenBAccount,
|
|
8677
|
+
tokenAAmountThreshold: tokenAAmountRemoveLiquidityThreshold,
|
|
8678
|
+
tokenBAmountThreshold: tokenBAmountRemoveLiquidityThreshold,
|
|
8679
|
+
tokenAMint,
|
|
8680
|
+
tokenBMint,
|
|
7609
8681
|
tokenAVault,
|
|
7610
8682
|
tokenBVault,
|
|
8683
|
+
tokenAProgram,
|
|
8684
|
+
tokenBProgram
|
|
8685
|
+
});
|
|
8686
|
+
transaction.add(removeAllLiquidityInstruction);
|
|
8687
|
+
const addLiquidityInstruction = yield this.buildAddLiquidityInstruction({
|
|
8688
|
+
pool,
|
|
8689
|
+
position: positionA,
|
|
8690
|
+
positionNftAccount: positionANftAccount,
|
|
8691
|
+
owner,
|
|
8692
|
+
tokenAAccount,
|
|
8693
|
+
tokenBAccount,
|
|
7611
8694
|
tokenAMint,
|
|
7612
8695
|
tokenBMint,
|
|
8696
|
+
tokenAVault,
|
|
8697
|
+
tokenBVault,
|
|
7613
8698
|
tokenAProgram,
|
|
7614
8699
|
tokenBProgram,
|
|
7615
|
-
|
|
7616
|
-
|
|
7617
|
-
|
|
8700
|
+
liquidityDelta: postionBLiquidityDelta,
|
|
8701
|
+
tokenAAmountThreshold: tokenAAmountAddLiquidityThreshold,
|
|
8702
|
+
tokenBAmountThreshold: tokenBAmountAddLiquidityThreshold
|
|
8703
|
+
});
|
|
8704
|
+
transaction.add(addLiquidityInstruction);
|
|
8705
|
+
const closePositionInstruction = yield this.buildClosePositionInstruction({
|
|
8706
|
+
owner,
|
|
8707
|
+
poolAuthority: this.poolAuthority,
|
|
8708
|
+
pool: positionBState.pool,
|
|
8709
|
+
position: positionB,
|
|
8710
|
+
positionNftMint: positionBState.nftMint,
|
|
8711
|
+
positionNftAccount: positionBNftAccount
|
|
8712
|
+
});
|
|
8713
|
+
transaction.add(closePositionInstruction);
|
|
8714
|
+
if (postInstructions.length > 0) {
|
|
8715
|
+
transaction.add(...postInstructions);
|
|
8716
|
+
}
|
|
8717
|
+
return transaction;
|
|
7618
8718
|
});
|
|
7619
8719
|
}
|
|
8720
|
+
/**
|
|
8721
|
+
* Builds a transaction to update reward duration.
|
|
8722
|
+
* @param {UpdateRewardDurationParams} params - Parameters including pool and new duration.
|
|
8723
|
+
* @returns Transaction builder.
|
|
8724
|
+
*/
|
|
7620
8725
|
updateRewardDuration(params) {
|
|
7621
8726
|
return __async(this, null, function* () {
|
|
7622
8727
|
const { pool, admin, rewardIndex, newDuration } = params;
|
|
7623
|
-
return yield this._program.methods.updateRewardDuration(rewardIndex, newDuration).
|
|
8728
|
+
return yield this._program.methods.updateRewardDuration(rewardIndex, newDuration).accountsPartial({
|
|
7624
8729
|
pool,
|
|
7625
|
-
admin
|
|
7626
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
7627
|
-
program: this._program.programId
|
|
8730
|
+
admin
|
|
7628
8731
|
}).transaction();
|
|
7629
8732
|
});
|
|
7630
8733
|
}
|
|
8734
|
+
/**
|
|
8735
|
+
* Builds a transaction to update reward funder address.
|
|
8736
|
+
* @param {UpdateRewardFunderParams} params - Parameters including pool and new funder address.
|
|
8737
|
+
* @returns Transaction builder.
|
|
8738
|
+
*/
|
|
7631
8739
|
updateRewardFunder(params) {
|
|
7632
8740
|
return __async(this, null, function* () {
|
|
7633
8741
|
const { pool, admin, rewardIndex, newFunder } = params;
|
|
7634
|
-
return yield this._program.methods.updateRewardFunder(rewardIndex, newFunder).
|
|
8742
|
+
return yield this._program.methods.updateRewardFunder(rewardIndex, newFunder).accountsPartial({
|
|
7635
8743
|
pool,
|
|
7636
|
-
admin
|
|
7637
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
7638
|
-
program: this._program.programId
|
|
8744
|
+
admin
|
|
7639
8745
|
}).transaction();
|
|
7640
8746
|
});
|
|
7641
8747
|
}
|
|
8748
|
+
/**
|
|
8749
|
+
* Builds a transaction to fund rewards in a pool.
|
|
8750
|
+
* @param {FundRewardParams} params - Funding parameters.
|
|
8751
|
+
* @returns Transaction builder.
|
|
8752
|
+
*/
|
|
7642
8753
|
fundReward(params) {
|
|
7643
8754
|
return __async(this, null, function* () {
|
|
7644
8755
|
const { rewardIndex, carryForward, pool, funder, amount } = params;
|
|
@@ -7664,22 +8775,24 @@ var CpAmm = class {
|
|
|
7664
8775
|
);
|
|
7665
8776
|
preInstructions.push(...wrapSOLIx);
|
|
7666
8777
|
}
|
|
7667
|
-
return yield this._program.methods.fundReward(rewardIndex, amount, carryForward).
|
|
8778
|
+
return yield this._program.methods.fundReward(rewardIndex, amount, carryForward).accountsPartial({
|
|
7668
8779
|
pool,
|
|
7669
8780
|
rewardVault: vault,
|
|
7670
8781
|
rewardMint: mint,
|
|
7671
8782
|
funderTokenAccount,
|
|
7672
8783
|
funder,
|
|
7673
|
-
tokenProgram
|
|
7674
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
7675
|
-
program: this._program.programId
|
|
8784
|
+
tokenProgram
|
|
7676
8785
|
}).transaction();
|
|
7677
8786
|
});
|
|
7678
8787
|
}
|
|
8788
|
+
/**
|
|
8789
|
+
* Builds a transaction to withdraw ineligible rewards from a pool.
|
|
8790
|
+
* @param {WithdrawIneligibleRewardParams} params - Parameters for withdrawal.
|
|
8791
|
+
* @returns Transaction builder.
|
|
8792
|
+
*/
|
|
7679
8793
|
withdrawIneligibleReward(params) {
|
|
7680
8794
|
return __async(this, null, function* () {
|
|
7681
8795
|
const { rewardIndex, pool, funder } = params;
|
|
7682
|
-
const poolAuthority = derivePoolAuthority(this._program.programId);
|
|
7683
8796
|
const poolState = yield this.fetchPoolState(pool);
|
|
7684
8797
|
const rewardInfo = poolState.rewardInfos[rewardIndex];
|
|
7685
8798
|
const { mint, vault, rewardTokenFlag } = rewardInfo;
|
|
@@ -7699,19 +8812,22 @@ var CpAmm = class {
|
|
|
7699
8812
|
const closeWrappedSOLIx = yield unwrapSOLInstruction(funder);
|
|
7700
8813
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
7701
8814
|
}
|
|
7702
|
-
return yield this._program.methods.withdrawIneligibleReward(rewardIndex).
|
|
8815
|
+
return yield this._program.methods.withdrawIneligibleReward(rewardIndex).accountsPartial({
|
|
7703
8816
|
pool,
|
|
7704
8817
|
rewardVault: vault,
|
|
7705
8818
|
rewardMint: mint,
|
|
7706
|
-
poolAuthority,
|
|
8819
|
+
poolAuthority: this.poolAuthority,
|
|
7707
8820
|
funderTokenAccount,
|
|
7708
8821
|
funder,
|
|
7709
|
-
tokenProgram
|
|
7710
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
7711
|
-
program: this._program.programId
|
|
8822
|
+
tokenProgram
|
|
7712
8823
|
}).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
7713
8824
|
});
|
|
7714
8825
|
}
|
|
8826
|
+
/**
|
|
8827
|
+
* Builds a transaction to claim partner fee rewards.
|
|
8828
|
+
* @param {ClaimPartnerFeeParams} params - Claim parameters including amounts and partner address.
|
|
8829
|
+
* @returns Transaction builder.
|
|
8830
|
+
*/
|
|
7715
8831
|
claimPartnerFee(params) {
|
|
7716
8832
|
return __async(this, null, function* () {
|
|
7717
8833
|
const { partner, pool, maxAmountA, maxAmountB } = params;
|
|
@@ -7724,33 +8840,19 @@ var CpAmm = class {
|
|
|
7724
8840
|
tokenAFlag,
|
|
7725
8841
|
tokenBFlag
|
|
7726
8842
|
} = poolState;
|
|
7727
|
-
const poolAuthority = derivePoolAuthority(this._program.programId);
|
|
7728
8843
|
const tokenAProgram = getTokenProgram(tokenAFlag);
|
|
7729
8844
|
const tokenBProgram = getTokenProgram(tokenBFlag);
|
|
7730
|
-
const
|
|
7731
|
-
|
|
7732
|
-
|
|
7733
|
-
|
|
7734
|
-
|
|
7735
|
-
|
|
7736
|
-
|
|
7737
|
-
|
|
7738
|
-
|
|
7739
|
-
|
|
7740
|
-
|
|
7741
|
-
tokenAProgram
|
|
7742
|
-
),
|
|
7743
|
-
getOrCreateATAInstruction(
|
|
7744
|
-
this._program.provider.connection,
|
|
7745
|
-
poolState.tokenBMint,
|
|
7746
|
-
partner,
|
|
7747
|
-
partner,
|
|
7748
|
-
true,
|
|
7749
|
-
tokenBProgram
|
|
7750
|
-
)
|
|
7751
|
-
]);
|
|
7752
|
-
createTokenAAccountIx && preInstructions.push(createTokenAAccountIx);
|
|
7753
|
-
createTokenBAccountIx && preInstructions.push(createTokenBAccountIx);
|
|
8845
|
+
const {
|
|
8846
|
+
tokenAAta: tokenAAccount,
|
|
8847
|
+
tokenBAta: tokenBAccount,
|
|
8848
|
+
instructions: preInstructions
|
|
8849
|
+
} = yield this.prepareTokenAccounts(
|
|
8850
|
+
partner,
|
|
8851
|
+
tokenAMint,
|
|
8852
|
+
tokenBMint,
|
|
8853
|
+
tokenAProgram,
|
|
8854
|
+
tokenBProgram
|
|
8855
|
+
);
|
|
7754
8856
|
const postInstructions = [];
|
|
7755
8857
|
if ([
|
|
7756
8858
|
poolState.tokenAMint.toBase58(),
|
|
@@ -7759,8 +8861,8 @@ var CpAmm = class {
|
|
|
7759
8861
|
const closeWrappedSOLIx = yield unwrapSOLInstruction(partner);
|
|
7760
8862
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
7761
8863
|
}
|
|
7762
|
-
return yield this._program.methods.claimPartnerFee(maxAmountA, maxAmountB).
|
|
7763
|
-
poolAuthority,
|
|
8864
|
+
return yield this._program.methods.claimPartnerFee(maxAmountA, maxAmountB).accountsPartial({
|
|
8865
|
+
poolAuthority: this.poolAuthority,
|
|
7764
8866
|
pool,
|
|
7765
8867
|
tokenAAccount,
|
|
7766
8868
|
tokenBAccount,
|
|
@@ -7770,22 +8872,25 @@ var CpAmm = class {
|
|
|
7770
8872
|
tokenBMint,
|
|
7771
8873
|
partner,
|
|
7772
8874
|
tokenAProgram,
|
|
7773
|
-
tokenBProgram
|
|
7774
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
7775
|
-
program: this._program.programId
|
|
8875
|
+
tokenBProgram
|
|
7776
8876
|
}).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
7777
8877
|
});
|
|
7778
8878
|
}
|
|
8879
|
+
/**
|
|
8880
|
+
* Builds a transaction to claim reward from a position.
|
|
8881
|
+
* @param {ClaimRewardParams} params - Parameters for claiming reward.
|
|
8882
|
+
* @returns Transaction builder.
|
|
8883
|
+
*/
|
|
7779
8884
|
claimReward(params) {
|
|
7780
8885
|
return __async(this, null, function* () {
|
|
7781
|
-
const {
|
|
7782
|
-
|
|
7783
|
-
|
|
7784
|
-
|
|
7785
|
-
|
|
7786
|
-
|
|
7787
|
-
|
|
7788
|
-
|
|
8886
|
+
const {
|
|
8887
|
+
user,
|
|
8888
|
+
position,
|
|
8889
|
+
positionNftAccount,
|
|
8890
|
+
rewardIndex,
|
|
8891
|
+
poolState,
|
|
8892
|
+
positionState
|
|
8893
|
+
} = params;
|
|
7789
8894
|
const rewardInfo = poolState.rewardInfos[rewardIndex];
|
|
7790
8895
|
const tokenProgram = getTokenProgram(rewardInfo.rewardTokenFlag);
|
|
7791
8896
|
const preInstructions = [];
|
|
@@ -7803,18 +8908,16 @@ var CpAmm = class {
|
|
|
7803
8908
|
const closeWrappedSOLIx = yield unwrapSOLInstruction(user);
|
|
7804
8909
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
7805
8910
|
}
|
|
7806
|
-
return yield this._program.methods.claimReward(rewardIndex).
|
|
8911
|
+
return yield this._program.methods.claimReward(rewardIndex).accountsPartial({
|
|
7807
8912
|
pool: positionState.pool,
|
|
7808
8913
|
positionNftAccount,
|
|
7809
8914
|
rewardVault: rewardInfo.vault,
|
|
7810
8915
|
rewardMint: rewardInfo.mint,
|
|
7811
|
-
poolAuthority,
|
|
8916
|
+
poolAuthority: this.poolAuthority,
|
|
7812
8917
|
position,
|
|
7813
8918
|
userTokenAccount,
|
|
7814
8919
|
owner: user,
|
|
7815
|
-
tokenProgram
|
|
7816
|
-
eventAuthority: deriveEventAuthority(this._program.programId)[0],
|
|
7817
|
-
program: this._program.programId
|
|
8920
|
+
tokenProgram
|
|
7818
8921
|
}).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
|
|
7819
8922
|
});
|
|
7820
8923
|
}
|
|
@@ -7870,5 +8973,30 @@ var index_default = cp_amm_default;
|
|
|
7870
8973
|
|
|
7871
8974
|
|
|
7872
8975
|
|
|
7873
|
-
|
|
8976
|
+
|
|
8977
|
+
|
|
8978
|
+
|
|
8979
|
+
|
|
8980
|
+
|
|
8981
|
+
|
|
8982
|
+
|
|
8983
|
+
|
|
8984
|
+
|
|
8985
|
+
|
|
8986
|
+
|
|
8987
|
+
|
|
8988
|
+
|
|
8989
|
+
|
|
8990
|
+
|
|
8991
|
+
|
|
8992
|
+
|
|
8993
|
+
|
|
8994
|
+
|
|
8995
|
+
|
|
8996
|
+
|
|
8997
|
+
|
|
8998
|
+
|
|
8999
|
+
|
|
9000
|
+
|
|
9001
|
+
exports.ActivationPoint = ActivationPoint; exports.ActivationType = ActivationType; exports.BASIS_POINT_MAX = BASIS_POINT_MAX; exports.CP_AMM_PROGRAM_ID = CP_AMM_PROGRAM_ID; exports.CollectFeeMode = CollectFeeMode; exports.CpAmm = CpAmm; exports.FEE_DENOMINATOR = FEE_DENOMINATOR; exports.FeeSchedulerMode = FeeSchedulerMode; exports.LIQUIDITY_SCALE = LIQUIDITY_SCALE; exports.MAX_CU_BUFFER = MAX_CU_BUFFER; exports.MAX_FEE_NUMERATOR = MAX_FEE_NUMERATOR; exports.MAX_SQRT_PRICE = MAX_SQRT_PRICE; exports.MIN_CU_BUFFER = MIN_CU_BUFFER; exports.MIN_SQRT_PRICE = MIN_SQRT_PRICE; exports.ONE = ONE; exports.PRECISION = PRECISION; exports.Rounding = Rounding; exports.SCALE_OFFSET = SCALE_OFFSET; exports.TradeDirection = TradeDirection; exports.calculateInitSqrtPrice = calculateInitSqrtPrice; exports.calculateTransferFeeExcludedAmount = calculateTransferFeeExcludedAmount; exports.calculateTransferFeeIncludedAmount = calculateTransferFeeIncludedAmount; exports.decimalToQ64 = decimalToQ64; exports.default = index_default; exports.deriveClaimFeeOperatorAddress = deriveClaimFeeOperatorAddress; exports.deriveConfigAddress = deriveConfigAddress; exports.deriveCustomizablePoolAddress = deriveCustomizablePoolAddress; exports.derivePoolAddress = derivePoolAddress; exports.derivePoolAuthority = derivePoolAuthority; exports.derivePositionAddress = derivePositionAddress; exports.derivePositionNftAccount = derivePositionNftAccount; exports.deriveRewardVaultAddress = deriveRewardVaultAddress; exports.deriveTokenBadge = deriveTokenBadge; exports.deriveTokenBadgeAddress = deriveTokenBadgeAddress; exports.deriveTokenVaultAddress = deriveTokenVaultAddress; exports.divCeil = divCeil; exports.getAllUserPositionNftAccount = getAllUserPositionNftAccount; exports.getAmountAFromLiquidityDelta = getAmountAFromLiquidityDelta; exports.getAmountBFromLiquidityDelta = getAmountBFromLiquidityDelta; exports.getBaseFeeNumerator = getBaseFeeNumerator; exports.getDeltaAmountA = getDeltaAmountA; exports.getDeltaAmountB = getDeltaAmountB; exports.getDynamicFeeNumerator = getDynamicFeeNumerator; exports.getEstimatedComputeUnitIxWithBuffer = getEstimatedComputeUnitIxWithBuffer; exports.getEstimatedComputeUnitUsageWithBuffer = getEstimatedComputeUnitUsageWithBuffer; exports.getFeeNumerator = getFeeNumerator; exports.getFirstKey = getFirstKey; exports.getLiquidityDeltaFromAmountA = getLiquidityDeltaFromAmountA; exports.getLiquidityDeltaFromAmountB = getLiquidityDeltaFromAmountB; exports.getMaxAmountWithSlippage = getMaxAmountWithSlippage; exports.getMinAmountWithSlippage = getMinAmountWithSlippage; exports.getNextSqrtPrice = getNextSqrtPrice; exports.getNftOwner = getNftOwner; exports.getOrCreateATAInstruction = getOrCreateATAInstruction; exports.getPriceFromSqrtPrice = getPriceFromSqrtPrice; exports.getPriceImpact = getPriceImpact; exports.getSecondKey = getSecondKey; exports.getSimulationComputeUnits = getSimulationComputeUnits; exports.getSqrtPriceFromPrice = getSqrtPriceFromPrice; exports.getSwapAmount = getSwapAmount; exports.getTokenDecimals = getTokenDecimals; exports.getTokenProgram = getTokenProgram; exports.getUnClaimReward = getUnClaimReward; exports.mulDiv = mulDiv; exports.mulShr = mulShr; exports.positionByPoolFilter = positionByPoolFilter; exports.pow = pow; exports.q64ToDecimal = q64ToDecimal; exports.shlDiv = shlDiv; exports.unwrapSOLInstruction = unwrapSOLInstruction; exports.vestingByPositionFilter = vestingByPositionFilter; exports.wrapSOLInstruction = wrapSOLInstruction;
|
|
7874
9002
|
//# sourceMappingURL=index.js.map
|