@glamsystems/glam-sdk 1.1.0-alpha.0 → 1.1.0-alpha.1

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/index.esm.js CHANGED
@@ -27126,116 +27126,6 @@ var instructions$9 = [
27126
27126
  ],
27127
27127
  args: []
27128
27128
  },
27129
- {
27130
- name: "initialize_permissioned_bundle_depositor",
27131
- docs: [
27132
- "Initialize a permissioned Neutral user bundle account for the GLAM vault.",
27133
- "",
27134
- "- Permission: `InitializePermissionedBundleDepositor`.",
27135
- "- Policy: `bundle_account` must be present in `NeutralPolicy::bundles_allowlist`."
27136
- ],
27137
- discriminator: [
27138
- 157,
27139
- 162,
27140
- 213,
27141
- 42,
27142
- 205,
27143
- 201,
27144
- 37,
27145
- 255
27146
- ],
27147
- accounts: [
27148
- {
27149
- name: "glam_state",
27150
- writable: true
27151
- },
27152
- {
27153
- name: "glam_vault",
27154
- writable: true,
27155
- pda: {
27156
- seeds: [
27157
- {
27158
- kind: "const",
27159
- value: [
27160
- 118,
27161
- 97,
27162
- 117,
27163
- 108,
27164
- 116
27165
- ]
27166
- },
27167
- {
27168
- kind: "account",
27169
- path: "glam_state"
27170
- }
27171
- ],
27172
- program: {
27173
- kind: "account",
27174
- path: "glam_protocol_program"
27175
- }
27176
- }
27177
- },
27178
- {
27179
- name: "glam_signer",
27180
- writable: true,
27181
- signer: true
27182
- },
27183
- {
27184
- name: "integration_authority",
27185
- pda: {
27186
- seeds: [
27187
- {
27188
- kind: "const",
27189
- value: [
27190
- 105,
27191
- 110,
27192
- 116,
27193
- 101,
27194
- 103,
27195
- 114,
27196
- 97,
27197
- 116,
27198
- 105,
27199
- 111,
27200
- 110,
27201
- 45,
27202
- 97,
27203
- 117,
27204
- 116,
27205
- 104,
27206
- 111,
27207
- 114,
27208
- 105,
27209
- 116,
27210
- 121
27211
- ]
27212
- }
27213
- ]
27214
- }
27215
- },
27216
- {
27217
- name: "cpi_program",
27218
- address: "BUNDDh4P5XviMm1f3gCvnq2qKx6TGosAGnoUK12e7cXU"
27219
- },
27220
- {
27221
- name: "glam_protocol_program",
27222
- address: "GLAMpaME8wdTEzxtiYEAa5yD8fZbxZiz2hNtV58RZiEz"
27223
- },
27224
- {
27225
- name: "system_program",
27226
- address: "11111111111111111111111111111111"
27227
- },
27228
- {
27229
- name: "bundle_account",
27230
- writable: true
27231
- },
27232
- {
27233
- name: "user_bundle_account",
27234
- writable: true
27235
- }
27236
- ],
27237
- args: []
27238
- },
27239
27129
  {
27240
27130
  name: "request_deposit",
27241
27131
  docs: [
@@ -27372,8 +27262,7 @@ var instructions$9 = [
27372
27262
  writable: true
27373
27263
  },
27374
27264
  {
27375
- name: "token_program",
27376
- address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
27265
+ name: "token_program"
27377
27266
  }
27378
27267
  ],
27379
27268
  args: [
@@ -28654,27 +28543,22 @@ var constants$9 = [
28654
28543
  {
28655
28544
  name: "PROTO_NEUTRAL_PERM_CLOSE_USER_BUNDLE_ACCOUNT",
28656
28545
  type: "u64",
28657
- value: "16"
28546
+ value: "8"
28658
28547
  },
28659
28548
  {
28660
28549
  name: "PROTO_NEUTRAL_PERM_INITIALIZE_BUNDLE_DEPOSITOR",
28661
28550
  type: "u64",
28662
28551
  value: "1"
28663
28552
  },
28664
- {
28665
- name: "PROTO_NEUTRAL_PERM_INITIALIZE_PERMISSIONED_BUNDLE_DEPOSITOR",
28666
- type: "u64",
28667
- value: "2"
28668
- },
28669
28553
  {
28670
28554
  name: "PROTO_NEUTRAL_PERM_REQUEST_DEPOSIT",
28671
28555
  type: "u64",
28672
- value: "4"
28556
+ value: "2"
28673
28557
  },
28674
28558
  {
28675
28559
  name: "PROTO_NEUTRAL_PERM_REQUEST_WITHDRAWAL",
28676
28560
  type: "u64",
28677
- value: "8"
28561
+ value: "4"
28678
28562
  }
28679
28563
  ];
28680
28564
  var ExtNeutralIdlJson = {
@@ -36125,19 +36009,26 @@ var instructions$7 = [
36125
36009
  args: []
36126
36010
  },
36127
36011
  {
36128
- name: "price_single_asset_vault",
36012
+ name: "price_neutral_bundle_depositors",
36129
36013
  docs: [
36130
- "Prices a single asset vault."
36014
+ "Price neutral bundle depositors",
36015
+ "",
36016
+ "Remaining accounts:",
36017
+ "- 4 * N neutral bundle depositor account tuples:",
36018
+ "1. User bundle account",
36019
+ "2. Bundle account",
36020
+ "3. Bundle oracle data account",
36021
+ "4. Bundle asset oracle account"
36131
36022
  ],
36132
36023
  discriminator: [
36024
+ 202,
36133
36025
  93,
36134
- 213,
36135
- 219,
36136
- 25,
36137
- 38,
36138
- 74,
36139
- 9,
36140
- 167
36026
+ 205,
36027
+ 29,
36028
+ 37,
36029
+ 180,
36030
+ 127,
36031
+ 102
36141
36032
  ],
36142
36033
  accounts: [
36143
36034
  {
@@ -36208,7 +36099,10 @@ var instructions$7 = [
36208
36099
  signer: true
36209
36100
  },
36210
36101
  {
36211
- name: "base_asset_ata"
36102
+ name: "sol_usd_oracle"
36103
+ },
36104
+ {
36105
+ name: "base_asset_oracle"
36212
36106
  },
36213
36107
  {
36214
36108
  name: "integration_authority",
@@ -36243,6 +36137,68 @@ var instructions$7 = [
36243
36137
  ]
36244
36138
  }
36245
36139
  },
36140
+ {
36141
+ name: "glam_config",
36142
+ pda: {
36143
+ seeds: [
36144
+ {
36145
+ kind: "const",
36146
+ value: [
36147
+ 103,
36148
+ 108,
36149
+ 111,
36150
+ 98,
36151
+ 97,
36152
+ 108,
36153
+ 45,
36154
+ 99,
36155
+ 111,
36156
+ 110,
36157
+ 102,
36158
+ 105,
36159
+ 103
36160
+ ]
36161
+ }
36162
+ ],
36163
+ program: {
36164
+ kind: "const",
36165
+ value: [
36166
+ 10,
36167
+ 11,
36168
+ 0,
36169
+ 83,
36170
+ 72,
36171
+ 16,
36172
+ 46,
36173
+ 144,
36174
+ 46,
36175
+ 42,
36176
+ 79,
36177
+ 22,
36178
+ 157,
36179
+ 123,
36180
+ 21,
36181
+ 242,
36182
+ 192,
36183
+ 146,
36184
+ 1,
36185
+ 78,
36186
+ 88,
36187
+ 59,
36188
+ 102,
36189
+ 9,
36190
+ 190,
36191
+ 226,
36192
+ 92,
36193
+ 189,
36194
+ 187,
36195
+ 232,
36196
+ 83,
36197
+ 220
36198
+ ]
36199
+ }
36200
+ }
36201
+ },
36246
36202
  {
36247
36203
  name: "glam_protocol",
36248
36204
  address: "gstgptmbgJVi5f8ZmSRVZjZkDQwqKa3xWuUtD5WmJHz"
@@ -36286,16 +36242,19 @@ var instructions$7 = [
36286
36242
  args: []
36287
36243
  },
36288
36244
  {
36289
- name: "price_stake_accounts",
36245
+ name: "price_single_asset_vault",
36246
+ docs: [
36247
+ "Prices a single asset vault."
36248
+ ],
36290
36249
  discriminator: [
36291
- 119,
36292
- 137,
36250
+ 93,
36251
+ 213,
36252
+ 219,
36253
+ 25,
36254
+ 38,
36255
+ 74,
36293
36256
  9,
36294
- 15,
36295
- 196,
36296
- 73,
36297
- 30,
36298
- 27
36257
+ 167
36299
36258
  ],
36300
36259
  accounts: [
36301
36260
  {
@@ -36366,10 +36325,7 @@ var instructions$7 = [
36366
36325
  signer: true
36367
36326
  },
36368
36327
  {
36369
- name: "sol_usd_oracle"
36370
- },
36371
- {
36372
- name: "base_asset_oracle"
36328
+ name: "base_asset_ata"
36373
36329
  },
36374
36330
  {
36375
36331
  name: "integration_authority",
@@ -36404,68 +36360,229 @@ var instructions$7 = [
36404
36360
  ]
36405
36361
  }
36406
36362
  },
36407
- {
36408
- name: "glam_config",
36409
- pda: {
36410
- seeds: [
36411
- {
36412
- kind: "const",
36413
- value: [
36414
- 103,
36415
- 108,
36416
- 111,
36417
- 98,
36418
- 97,
36419
- 108,
36420
- 45,
36421
- 99,
36422
- 111,
36423
- 110,
36424
- 102,
36425
- 105,
36426
- 103
36427
- ]
36428
- }
36429
- ],
36430
- program: {
36431
- kind: "const",
36432
- value: [
36433
- 10,
36434
- 11,
36435
- 0,
36436
- 83,
36437
- 72,
36438
- 16,
36439
- 46,
36440
- 144,
36441
- 46,
36442
- 42,
36443
- 79,
36444
- 22,
36445
- 157,
36446
- 123,
36447
- 21,
36448
- 242,
36449
- 192,
36450
- 146,
36451
- 1,
36452
- 78,
36453
- 88,
36454
- 59,
36455
- 102,
36456
- 9,
36457
- 190,
36458
- 226,
36459
- 92,
36460
- 189,
36461
- 187,
36462
- 232,
36463
- 83,
36464
- 220
36465
- ]
36466
- }
36467
- }
36468
- },
36363
+ {
36364
+ name: "glam_protocol",
36365
+ address: "gstgptmbgJVi5f8ZmSRVZjZkDQwqKa3xWuUtD5WmJHz"
36366
+ },
36367
+ {
36368
+ name: "event_authority",
36369
+ optional: true,
36370
+ pda: {
36371
+ seeds: [
36372
+ {
36373
+ kind: "const",
36374
+ value: [
36375
+ 95,
36376
+ 95,
36377
+ 101,
36378
+ 118,
36379
+ 101,
36380
+ 110,
36381
+ 116,
36382
+ 95,
36383
+ 97,
36384
+ 117,
36385
+ 116,
36386
+ 104,
36387
+ 111,
36388
+ 114,
36389
+ 105,
36390
+ 116,
36391
+ 121
36392
+ ]
36393
+ }
36394
+ ]
36395
+ }
36396
+ },
36397
+ {
36398
+ name: "event_program",
36399
+ optional: true,
36400
+ address: "gstgm1M39mhgnvgyScGUDRwNn5kNVSd97hTtyow1Et5"
36401
+ }
36402
+ ],
36403
+ args: []
36404
+ },
36405
+ {
36406
+ name: "price_stake_accounts",
36407
+ discriminator: [
36408
+ 119,
36409
+ 137,
36410
+ 9,
36411
+ 15,
36412
+ 196,
36413
+ 73,
36414
+ 30,
36415
+ 27
36416
+ ],
36417
+ accounts: [
36418
+ {
36419
+ name: "glam_state",
36420
+ writable: true
36421
+ },
36422
+ {
36423
+ name: "glam_vault",
36424
+ pda: {
36425
+ seeds: [
36426
+ {
36427
+ kind: "const",
36428
+ value: [
36429
+ 118,
36430
+ 97,
36431
+ 117,
36432
+ 108,
36433
+ 116
36434
+ ]
36435
+ },
36436
+ {
36437
+ kind: "account",
36438
+ path: "glam_state"
36439
+ }
36440
+ ],
36441
+ program: {
36442
+ kind: "const",
36443
+ value: [
36444
+ 10,
36445
+ 55,
36446
+ 49,
36447
+ 193,
36448
+ 142,
36449
+ 247,
36450
+ 75,
36451
+ 193,
36452
+ 33,
36453
+ 61,
36454
+ 5,
36455
+ 218,
36456
+ 254,
36457
+ 219,
36458
+ 143,
36459
+ 206,
36460
+ 156,
36461
+ 138,
36462
+ 14,
36463
+ 32,
36464
+ 89,
36465
+ 232,
36466
+ 248,
36467
+ 173,
36468
+ 46,
36469
+ 77,
36470
+ 46,
36471
+ 206,
36472
+ 189,
36473
+ 171,
36474
+ 68,
36475
+ 237
36476
+ ]
36477
+ }
36478
+ }
36479
+ },
36480
+ {
36481
+ name: "signer",
36482
+ writable: true,
36483
+ signer: true
36484
+ },
36485
+ {
36486
+ name: "sol_usd_oracle"
36487
+ },
36488
+ {
36489
+ name: "base_asset_oracle"
36490
+ },
36491
+ {
36492
+ name: "integration_authority",
36493
+ pda: {
36494
+ seeds: [
36495
+ {
36496
+ kind: "const",
36497
+ value: [
36498
+ 105,
36499
+ 110,
36500
+ 116,
36501
+ 101,
36502
+ 103,
36503
+ 114,
36504
+ 97,
36505
+ 116,
36506
+ 105,
36507
+ 111,
36508
+ 110,
36509
+ 45,
36510
+ 97,
36511
+ 117,
36512
+ 116,
36513
+ 104,
36514
+ 111,
36515
+ 114,
36516
+ 105,
36517
+ 116,
36518
+ 121
36519
+ ]
36520
+ }
36521
+ ]
36522
+ }
36523
+ },
36524
+ {
36525
+ name: "glam_config",
36526
+ pda: {
36527
+ seeds: [
36528
+ {
36529
+ kind: "const",
36530
+ value: [
36531
+ 103,
36532
+ 108,
36533
+ 111,
36534
+ 98,
36535
+ 97,
36536
+ 108,
36537
+ 45,
36538
+ 99,
36539
+ 111,
36540
+ 110,
36541
+ 102,
36542
+ 105,
36543
+ 103
36544
+ ]
36545
+ }
36546
+ ],
36547
+ program: {
36548
+ kind: "const",
36549
+ value: [
36550
+ 10,
36551
+ 11,
36552
+ 0,
36553
+ 83,
36554
+ 72,
36555
+ 16,
36556
+ 46,
36557
+ 144,
36558
+ 46,
36559
+ 42,
36560
+ 79,
36561
+ 22,
36562
+ 157,
36563
+ 123,
36564
+ 21,
36565
+ 242,
36566
+ 192,
36567
+ 146,
36568
+ 1,
36569
+ 78,
36570
+ 88,
36571
+ 59,
36572
+ 102,
36573
+ 9,
36574
+ 190,
36575
+ 226,
36576
+ 92,
36577
+ 189,
36578
+ 187,
36579
+ 232,
36580
+ 83,
36581
+ 220
36582
+ ]
36583
+ }
36584
+ }
36585
+ },
36469
36586
  {
36470
36587
  name: "glam_protocol",
36471
36588
  address: "gstgptmbgJVi5f8ZmSRVZjZkDQwqKa3xWuUtD5WmJHz"
@@ -53716,116 +53833,6 @@ var instructions = [
53716
53833
  ],
53717
53834
  args: []
53718
53835
  },
53719
- {
53720
- name: "initialize_permissioned_bundle_depositor",
53721
- docs: [
53722
- "Initialize a permissioned Neutral user bundle account for the GLAM vault.",
53723
- "",
53724
- "- Permission: `InitializePermissionedBundleDepositor`.",
53725
- "- Policy: `bundle_account` must be present in `NeutralPolicy::bundles_allowlist`."
53726
- ],
53727
- discriminator: [
53728
- 157,
53729
- 162,
53730
- 213,
53731
- 42,
53732
- 205,
53733
- 201,
53734
- 37,
53735
- 255
53736
- ],
53737
- accounts: [
53738
- {
53739
- name: "glam_state",
53740
- writable: true
53741
- },
53742
- {
53743
- name: "glam_vault",
53744
- writable: true,
53745
- pda: {
53746
- seeds: [
53747
- {
53748
- kind: "const",
53749
- value: [
53750
- 118,
53751
- 97,
53752
- 117,
53753
- 108,
53754
- 116
53755
- ]
53756
- },
53757
- {
53758
- kind: "account",
53759
- path: "glam_state"
53760
- }
53761
- ],
53762
- program: {
53763
- kind: "account",
53764
- path: "glam_protocol_program"
53765
- }
53766
- }
53767
- },
53768
- {
53769
- name: "glam_signer",
53770
- writable: true,
53771
- signer: true
53772
- },
53773
- {
53774
- name: "integration_authority",
53775
- pda: {
53776
- seeds: [
53777
- {
53778
- kind: "const",
53779
- value: [
53780
- 105,
53781
- 110,
53782
- 116,
53783
- 101,
53784
- 103,
53785
- 114,
53786
- 97,
53787
- 116,
53788
- 105,
53789
- 111,
53790
- 110,
53791
- 45,
53792
- 97,
53793
- 117,
53794
- 116,
53795
- 104,
53796
- 111,
53797
- 114,
53798
- 105,
53799
- 116,
53800
- 121
53801
- ]
53802
- }
53803
- ]
53804
- }
53805
- },
53806
- {
53807
- name: "cpi_program",
53808
- address: "BUNDDh4P5XviMm1f3gCvnq2qKx6TGosAGnoUK12e7cXU"
53809
- },
53810
- {
53811
- name: "glam_protocol_program",
53812
- address: "gstgptmbgJVi5f8ZmSRVZjZkDQwqKa3xWuUtD5WmJHz"
53813
- },
53814
- {
53815
- name: "system_program",
53816
- address: "11111111111111111111111111111111"
53817
- },
53818
- {
53819
- name: "bundle_account",
53820
- writable: true
53821
- },
53822
- {
53823
- name: "user_bundle_account",
53824
- writable: true
53825
- }
53826
- ],
53827
- args: []
53828
- },
53829
53836
  {
53830
53837
  name: "request_deposit",
53831
53838
  docs: [
@@ -53962,8 +53969,7 @@ var instructions = [
53962
53969
  writable: true
53963
53970
  },
53964
53971
  {
53965
- name: "token_program",
53966
- address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
53972
+ name: "token_program"
53967
53973
  }
53968
53974
  ],
53969
53975
  args: [
@@ -55244,27 +55250,22 @@ var constants = [
55244
55250
  {
55245
55251
  name: "PROTO_NEUTRAL_PERM_CLOSE_USER_BUNDLE_ACCOUNT",
55246
55252
  type: "u64",
55247
- value: "16"
55253
+ value: "8"
55248
55254
  },
55249
55255
  {
55250
55256
  name: "PROTO_NEUTRAL_PERM_INITIALIZE_BUNDLE_DEPOSITOR",
55251
55257
  type: "u64",
55252
55258
  value: "1"
55253
55259
  },
55254
- {
55255
- name: "PROTO_NEUTRAL_PERM_INITIALIZE_PERMISSIONED_BUNDLE_DEPOSITOR",
55256
- type: "u64",
55257
- value: "2"
55258
- },
55259
55260
  {
55260
55261
  name: "PROTO_NEUTRAL_PERM_REQUEST_DEPOSIT",
55261
55262
  type: "u64",
55262
- value: "4"
55263
+ value: "2"
55263
55264
  },
55264
55265
  {
55265
55266
  name: "PROTO_NEUTRAL_PERM_REQUEST_WITHDRAWAL",
55266
55267
  type: "u64",
55267
- value: "8"
55268
+ value: "4"
55268
55269
  }
55269
55270
  ];
55270
55271
  var ExtNeutralIdlJsonStaging = {
@@ -63516,6 +63517,244 @@ class BridgeClient {
63516
63517
  }
63517
63518
  }
63518
63519
 
63520
+ const NEUTRAL_PROTOCOL = 0b1;
63521
+ const NEUTRAL_BUNDLE_DISCRIMINATOR = Buffer.from([
63522
+ 15,
63523
+ 82,
63524
+ 167,
63525
+ 230,
63526
+ 37,
63527
+ 214,
63528
+ 82,
63529
+ 80
63530
+ ]);
63531
+ class NeutralBundleAccount {
63532
+ static decode(address, buffer) {
63533
+ const data = NeutralBundleAccount._layout.decode(buffer);
63534
+ if (!Buffer.from(data.discriminator).equals(NEUTRAL_BUNDLE_DISCRIMINATOR)) {
63535
+ throw new Error("Account is not a Neutral Bundle account");
63536
+ }
63537
+ const account = new NeutralBundleAccount();
63538
+ Object.assign(account, {
63539
+ _address: address,
63540
+ ...data
63541
+ });
63542
+ return account;
63543
+ }
63544
+ getAddress() {
63545
+ return this._address;
63546
+ }
63547
+ get permissioned() {
63548
+ return this.permissionned;
63549
+ }
63550
+ toView() {
63551
+ return {
63552
+ treasuryAccount: this.treasuryAccount,
63553
+ assetAddress: this.assetAddress,
63554
+ assetDecimals: this.assetDecimals,
63555
+ permissioned: this.permissioned
63556
+ };
63557
+ }
63558
+ }
63559
+ NeutralBundleAccount._layout = struct([
63560
+ array(u8(), 8, "discriminator"),
63561
+ array(u8(), 32, "name"),
63562
+ publicKey("manager"),
63563
+ publicKey("keeper"),
63564
+ publicKey("treasuryAccount"),
63565
+ vec(publicKey(), "allocatedReceivers"),
63566
+ u64("bundleUnderlyingBalance"),
63567
+ u64("maxDepositAmount"),
63568
+ u64("withdrawalDelay"),
63569
+ u32("performanceFee"),
63570
+ u32("managementFeeBps"),
63571
+ u32("depositFee"),
63572
+ u32("withdrawalFee"),
63573
+ u128("managerPfeeShares"),
63574
+ u32("currentAllocationBps"),
63575
+ u64("oracleBuffer"),
63576
+ u128("totalShares"),
63577
+ u64("assetPrecision"),
63578
+ publicKey("assetAddress"),
63579
+ u8("assetDecimals"),
63580
+ i64("withdrawalTMin"),
63581
+ i64("withdrawalTMax"),
63582
+ f32("withdrawalCurve"),
63583
+ bool("permissionned"),
63584
+ u128("managerMfeeShares"),
63585
+ u64("minDepositAmount"),
63586
+ i64("oracleUpdateTimeLimit"),
63587
+ i64("oracleMaxAge"),
63588
+ i64("withdrawalRedemptionRequestCutoffTs"),
63589
+ i64("withdrawalRedemptionUnlockCurrentCycleTs"),
63590
+ i64("withdrawalRedemptionUnlockNextCycleTs"),
63591
+ array(u8(), 207, "padding")
63592
+ ]);
63593
+ function toBn$1(value) {
63594
+ if (BN.isBN(value)) {
63595
+ return value;
63596
+ }
63597
+ return new BN(value.toString());
63598
+ }
63599
+ function getNeutralUserBundlePda(authority, bundle) {
63600
+ return PublicKey.findProgramAddressSync([
63601
+ Buffer.from("USER_BUNDLE"),
63602
+ authority.toBuffer(),
63603
+ bundle.toBuffer()
63604
+ ], NTBUNDLE_PROGRAM_ID)[0];
63605
+ }
63606
+ function getNeutralOracleDataPda(bundle) {
63607
+ return PublicKey.findProgramAddressSync([
63608
+ Buffer.from("ORACLE"),
63609
+ bundle.toBuffer()
63610
+ ], NTBUNDLE_PROGRAM_ID)[0];
63611
+ }
63612
+ function getNeutralBundleTempDataPda(bundle) {
63613
+ return PublicKey.findProgramAddressSync([
63614
+ Buffer.from("BUNDLE_TEMP_DATA"),
63615
+ bundle.toBuffer()
63616
+ ], NTBUNDLE_PROGRAM_ID)[0];
63617
+ }
63618
+ function getNeutralPendingBundleAssetAuthorityPda(bundle) {
63619
+ return PublicKey.findProgramAddressSync([
63620
+ Buffer.from("PENDING_BUNDLE_ASSET_AUTHORITY"),
63621
+ bundle.toBuffer()
63622
+ ], NTBUNDLE_PROGRAM_ID)[0];
63623
+ }
63624
+ function getNeutralPendingDepositTokenAccountPda(pendingBundleAssetAuthority, assetAddress) {
63625
+ return getAssociatedTokenAddressSync(assetAddress, pendingBundleAssetAuthority, true, TOKEN_PROGRAM_ID);
63626
+ }
63627
+ let TxBuilder$8 = class TxBuilder extends BaseTxBuilder {
63628
+ async setNeutralPolicyIx(policy, signer) {
63629
+ return await this.client.base.extNeutralProgram.methods.setNeutralPolicy(policy).accountsPartial({
63630
+ glamState: this.client.base.statePda,
63631
+ glamSigner: signer || this.client.base.signer,
63632
+ glamProtocolProgram: this.client.base.protocolProgram.programId
63633
+ }).instruction();
63634
+ }
63635
+ async setNeutralPolicyTx(policy, txOptions = {}) {
63636
+ const ix = await this.setNeutralPolicyIx(policy, txOptions.signer);
63637
+ return await this.buildVersionedTx([
63638
+ ix
63639
+ ], txOptions);
63640
+ }
63641
+ async initializeBundleDepositorIx(accounts, signer) {
63642
+ const bundle = await this.client.fetchBundle(accounts.bundle);
63643
+ if (bundle.permissioned) {
63644
+ throw new Error("Bundle is permissioned. Use initializePermissionedBundleDepositor instead.");
63645
+ }
63646
+ return await this.client.base.extNeutralProgram.methods.initializeBundleDepositor().accountsPartial({
63647
+ ...this.client.baseAccounts(signer),
63648
+ bundleAccount: accounts.bundle,
63649
+ userBundleAccount: accounts.userBundleAccount || this.client.getUserBundlePda(accounts.bundle)
63650
+ }).instruction();
63651
+ }
63652
+ async initializeBundleDepositorTx(accounts, txOptions = {}) {
63653
+ const ix = await this.initializeBundleDepositorIx(accounts, txOptions.signer);
63654
+ return await this.buildVersionedTx([
63655
+ ix
63656
+ ], txOptions);
63657
+ }
63658
+ async requestDepositIx(accounts, amount, signer) {
63659
+ const bundle = await this.client.fetchBundle(accounts.bundle);
63660
+ const tokenProgram = accounts.tokenProgram || TOKEN_PROGRAM_ID;
63661
+ const assetAddress = accounts.assetAddress || bundle.assetAddress;
63662
+ const pendingBundleAssetAuthority = accounts.pendingBundleAssetAuthority || this.client.getPendingBundleAssetAuthorityPda(accounts.bundle);
63663
+ return await this.client.base.extNeutralProgram.methods.requestDeposit(toBn$1(amount)).accountsPartial({
63664
+ ...this.client.baseAccounts(signer),
63665
+ userTokenAccount: accounts.userTokenAccount || this.client.base.getVaultAta(assetAddress, tokenProgram),
63666
+ pendingDepositTokenAccount: accounts.pendingDepositTokenAccount || getNeutralPendingDepositTokenAccountPda(pendingBundleAssetAuthority, assetAddress),
63667
+ treasuryAccount: accounts.treasuryAccount || bundle.treasuryAccount,
63668
+ userBundleAccount: accounts.userBundleAccount || this.client.getUserBundlePda(accounts.bundle),
63669
+ assetAddress,
63670
+ oracleData: accounts.oracleData || this.client.getOracleDataPda(accounts.bundle),
63671
+ bundleTempData: accounts.bundleTempData || this.client.getBundleTempDataPda(accounts.bundle),
63672
+ bundleAccount: accounts.bundle,
63673
+ pendingBundleAssetAuthority,
63674
+ tokenProgram
63675
+ }).instruction();
63676
+ }
63677
+ async requestDepositTx(accounts, amount, txOptions = {}) {
63678
+ const ix = await this.requestDepositIx(accounts, amount, txOptions.signer);
63679
+ return await this.buildVersionedTx([
63680
+ ix
63681
+ ], txOptions);
63682
+ }
63683
+ };
63684
+ class NeutralClient {
63685
+ baseAccounts(signer) {
63686
+ return {
63687
+ glamState: this.base.statePda,
63688
+ glamVault: this.base.vaultPda,
63689
+ glamSigner: signer || this.base.signer,
63690
+ integrationAuthority: this.getIntegrationAuthorityPda(),
63691
+ cpiProgram: NTBUNDLE_PROGRAM_ID,
63692
+ glamProtocolProgram: this.base.protocolProgram.programId,
63693
+ systemProgram: SystemProgram.programId
63694
+ };
63695
+ }
63696
+ getIntegrationAuthorityPda() {
63697
+ return getIntegrationAuthorityPda(this.base.extNeutralProgram.programId);
63698
+ }
63699
+ getUserBundlePda(bundle) {
63700
+ return getNeutralUserBundlePda(this.base.vaultPda, bundle);
63701
+ }
63702
+ getOracleDataPda(bundle) {
63703
+ return getNeutralOracleDataPda(bundle);
63704
+ }
63705
+ getBundleTempDataPda(bundle) {
63706
+ return getNeutralBundleTempDataPda(bundle);
63707
+ }
63708
+ getPendingBundleAssetAuthorityPda(bundle) {
63709
+ return getNeutralPendingBundleAssetAuthorityPda(bundle);
63710
+ }
63711
+ async fetchBundle(bundle) {
63712
+ const account = await this.base.connection.getAccountInfo(bundle);
63713
+ if (!account) {
63714
+ throw new Error(`Neutral bundle account not found: ${bundle}`);
63715
+ }
63716
+ if (!account.owner.equals(NTBUNDLE_PROGRAM_ID)) {
63717
+ throw new Error(`Neutral bundle ${bundle} is owned by ${account.owner}, expected ${NTBUNDLE_PROGRAM_ID}`);
63718
+ }
63719
+ return NeutralBundleAccount.decode(bundle, account.data);
63720
+ }
63721
+ async fetchPolicy() {
63722
+ return await this.base.fetchProtocolPolicy(this.base.extNeutralProgram.programId, NEUTRAL_PROTOCOL, NeutralPolicy);
63723
+ }
63724
+ async setPolicy(policy, txOptions = {}) {
63725
+ const tx = await this.txBuilder.setNeutralPolicyTx(policy, txOptions);
63726
+ return await this.base.sendAndConfirm(tx);
63727
+ }
63728
+ async allowlistBundle(bundle, txOptions = {}) {
63729
+ const policy = await this.fetchPolicy() ?? new NeutralPolicy([]);
63730
+ if (policy.bundlesAllowlist.find((b)=>b.equals(bundle))) {
63731
+ throw new Error(`Neutral bundle ${bundle} is already in the allowlist`);
63732
+ }
63733
+ policy.bundlesAllowlist.push(bundle);
63734
+ return await this.setPolicy(policy, txOptions);
63735
+ }
63736
+ async initializeBundleDepositor(bundle, txOptions = {}) {
63737
+ const tx = await this.txBuilder.initializeBundleDepositorTx({
63738
+ bundle
63739
+ }, txOptions);
63740
+ return await this.base.sendAndConfirm(tx);
63741
+ }
63742
+ async requestDeposit(bundle, amount, txOptions = {}) {
63743
+ const tx = await this.txBuilder.requestDepositTx({
63744
+ bundle
63745
+ }, amount, txOptions);
63746
+ return await this.base.sendAndConfirm(tx);
63747
+ }
63748
+ async requestDepositUiAmount(bundle, amount, txOptions = {}) {
63749
+ const bundleAccount = await this.fetchBundle(bundle);
63750
+ return await this.requestDeposit(bundle, fromUiAmount(amount, bundleAccount.assetDecimals), txOptions);
63751
+ }
63752
+ constructor(base){
63753
+ this.base = base;
63754
+ this.txBuilder = new TxBuilder$8(this);
63755
+ }
63756
+ }
63757
+
63519
63758
  /**
63520
63759
  * Represents a single asset holding within a vault.
63521
63760
  *
@@ -64150,6 +64389,76 @@ class PriceClient {
64150
64389
  kaminoReserves: Array.from(kaminoReserves)
64151
64390
  };
64152
64391
  }
64392
+ async priceNeutralBundleDepositorsIx() {
64393
+ const stateModel = this.cachedStateModel ?? await this.base.fetchStateModel();
64394
+ const externalPositions = new PkSet(stateModel.externalPositions ?? []);
64395
+ const policy = await this.base.fetchProtocolPolicy(this.base.extNeutralProgram.programId, NEUTRAL_PROTOCOL, NeutralPolicy);
64396
+ if (!policy || policy.bundlesAllowlist.length === 0) {
64397
+ return {
64398
+ ixs: [],
64399
+ kaminoReserves: []
64400
+ };
64401
+ }
64402
+ const positions = policy.bundlesAllowlist.map((bundle)=>({
64403
+ bundle,
64404
+ userBundle: getNeutralUserBundlePda(this.base.vaultPda, bundle)
64405
+ })).filter(({ userBundle })=>externalPositions.has(userBundle));
64406
+ if (positions.length === 0) {
64407
+ return {
64408
+ ixs: [],
64409
+ kaminoReserves: []
64410
+ };
64411
+ }
64412
+ const bundleInfos = await this.base.connection.getMultipleAccountsInfo(positions.map(({ bundle })=>bundle), "confirmed");
64413
+ const [solUsdOracle, baseAssetOracle, baseAssetMeta] = await Promise.all([
64414
+ this.base.getSolOracle(),
64415
+ this.getBaseAssetOracle(),
64416
+ this.base.getAssetMeta(stateModel.baseAssetMint)
64417
+ ]);
64418
+ const kaminoReserves = new PkSet();
64419
+ if (baseAssetMeta.oracleSource === "KaminoReserve") {
64420
+ kaminoReserves.add(baseAssetMeta.oracle);
64421
+ }
64422
+ const remainingAccounts = [];
64423
+ for(let i = 0; i < positions.length; i++){
64424
+ const { bundle, userBundle } = positions[i];
64425
+ const bundleInfo = bundleInfos[i];
64426
+ if (!bundleInfo) {
64427
+ throw new Error(`Neutral bundle account not found: ${bundle}`);
64428
+ }
64429
+ if (!bundleInfo.owner.equals(NTBUNDLE_PROGRAM_ID)) {
64430
+ throw new Error(`Neutral bundle ${bundle} is owned by ${bundleInfo.owner}, expected ${NTBUNDLE_PROGRAM_ID}`);
64431
+ }
64432
+ const bundleAccount = NeutralBundleAccount.decode(bundle, bundleInfo.data);
64433
+ const bundleAssetMeta = await this.base.getAssetMeta(bundleAccount.assetAddress);
64434
+ if (bundleAssetMeta.oracleSource === "KaminoReserve") {
64435
+ kaminoReserves.add(bundleAssetMeta.oracle);
64436
+ }
64437
+ [
64438
+ userBundle,
64439
+ bundle,
64440
+ getNeutralOracleDataPda(bundle),
64441
+ bundleAssetMeta.oracle
64442
+ ].forEach((pubkey)=>{
64443
+ remainingAccounts.push({
64444
+ pubkey,
64445
+ isSigner: false,
64446
+ isWritable: false
64447
+ });
64448
+ });
64449
+ }
64450
+ const ix = await this.base.mintProgram.methods.priceNeutralBundleDepositors().accounts({
64451
+ glamState: this.base.statePda,
64452
+ solUsdOracle,
64453
+ baseAssetOracle
64454
+ }).remainingAccounts(remainingAccounts).instruction();
64455
+ return {
64456
+ ixs: [
64457
+ ix
64458
+ ],
64459
+ kaminoReserves: Array.from(kaminoReserves)
64460
+ };
64461
+ }
64153
64462
  async priceEpiValidatedPositionsIx() {
64154
64463
  const observationState = await this.epi.fetchObservationState();
64155
64464
  if (!observationState) {
@@ -64221,6 +64530,10 @@ class PriceClient {
64221
64530
  if (bridgeIntegrationAcl) {
64222
64531
  chunks.push(await this.priceManagedTransfersIxs());
64223
64532
  }
64533
+ const neutralIntegrationAcl = integrationAcls.find((acl)=>acl.integrationProgram.equals(this.base.extNeutralProgram.programId) && (acl.protocolsBitmask & NEUTRAL_PROTOCOL) !== 0);
64534
+ if (neutralIntegrationAcl) {
64535
+ chunks.push(await this.priceNeutralBundleDepositorsIx());
64536
+ }
64224
64537
  }
64225
64538
  // Coalesce all kamino reserve refreshes into a single front-loaded ix.
64226
64539
  const allReserves = new PkSet();
@@ -64291,7 +64604,7 @@ class PriceClient {
64291
64604
  }
64292
64605
  }
64293
64606
 
64294
- let TxBuilder$8 = class TxBuilder extends BaseTxBuilder {
64607
+ let TxBuilder$7 = class TxBuilder extends BaseTxBuilder {
64295
64608
  async crystallizeFeesIxs(glamSigner) {
64296
64609
  const glamState = this.client.base.statePda;
64297
64610
  const glamMint = this.client.base.mintPda;
@@ -64449,11 +64762,11 @@ class FeesClient {
64449
64762
  constructor(base, price){
64450
64763
  this.base = base;
64451
64764
  this.price = price;
64452
- this.txBuilder = new TxBuilder$8(this);
64765
+ this.txBuilder = new TxBuilder$7(this);
64453
64766
  }
64454
64767
  }
64455
64768
 
64456
- let TxBuilder$7 = class TxBuilder extends BaseTxBuilder {
64769
+ let TxBuilder$6 = class TxBuilder extends BaseTxBuilder {
64457
64770
  async emergencyAccessUpdateIx(args, signer) {
64458
64771
  return await this.client.base.protocolProgram.methods.emergencyAccessUpdate(new EmergencyAccessUpdateArgs(args)).accounts({
64459
64772
  glamState: this.client.base.statePda,
@@ -64618,11 +64931,11 @@ class AccessClient {
64618
64931
  }
64619
64932
  constructor(base){
64620
64933
  this.base = base;
64621
- this.txBuilder = new TxBuilder$7(this);
64934
+ this.txBuilder = new TxBuilder$6(this);
64622
64935
  }
64623
64936
  }
64624
64937
 
64625
- let TxBuilder$6 = class TxBuilder extends BaseTxBuilder {
64938
+ let TxBuilder$5 = class TxBuilder extends BaseTxBuilder {
64626
64939
  async applyStateTimelockIx(glamSigner) {
64627
64940
  return await this.client.base.protocolProgram.methods.updateStateApplyTimelock().accounts({
64628
64941
  glamState: this.client.base.statePda,
@@ -64700,11 +65013,11 @@ class TimelockClient {
64700
65013
  constructor(base, stateClient){
64701
65014
  this.base = base;
64702
65015
  this.stateClient = stateClient;
64703
- this.txBuilder = new TxBuilder$6(this);
65016
+ this.txBuilder = new TxBuilder$5(this);
64704
65017
  }
64705
65018
  }
64706
65019
 
64707
- let TxBuilder$5 = class TxBuilder extends BaseTxBuilder {
65020
+ let TxBuilder$4 = class TxBuilder extends BaseTxBuilder {
64708
65021
  async initializeAndDelegateStakeIxs(vote, amount, glamSigner) {
64709
65022
  const [stakeAccount, createStakeAccountIx] = await this.client.createStakeAccount(glamSigner);
64710
65023
  const glamState = this.client.base.statePda;
@@ -64917,11 +65230,11 @@ class StakeClient {
64917
65230
  }
64918
65231
  constructor(base){
64919
65232
  this.base = base;
64920
- this.txBuilder = new TxBuilder$5(this);
65233
+ this.txBuilder = new TxBuilder$4(this);
64921
65234
  }
64922
65235
  }
64923
65236
 
64924
- let TxBuilder$4 = class TxBuilder extends BaseTxBuilder {
65237
+ let TxBuilder$3 = class TxBuilder extends BaseTxBuilder {
64925
65238
  async depositSolIxs(stakePool, lamports, glamSigner) {
64926
65239
  const { programId: stakePoolProgram, poolMint, withdrawAuthority, feeAccount, tokenProgramId: tokenProgram, reserveStake } = await this.client.getStakePoolAccountData(stakePool);
64927
65240
  const glamVault = this.client.base.vaultPda;
@@ -65119,7 +65432,7 @@ class StakePoolClient {
65119
65432
  this.base = base;
65120
65433
  this.stake = stake;
65121
65434
  this.marinade = marinade;
65122
- this.txBuilder = new TxBuilder$4(this);
65435
+ this.txBuilder = new TxBuilder$3(this);
65123
65436
  }
65124
65437
  }
65125
65438
 
@@ -65169,7 +65482,7 @@ class CctpBridgeEvent {
65169
65482
  this.uiAmount = toUiAmount(this.amount, 6);
65170
65483
  }
65171
65484
  }
65172
- let TxBuilder$3 = class TxBuilder extends BaseTxBuilder {
65485
+ let TxBuilder$2 = class TxBuilder extends BaseTxBuilder {
65173
65486
  /**
65174
65487
  * Returns a transaction that calls CCTP's `depositForBurn` instruction that bridges USDC to another chain.
65175
65488
  * A keypair is generated for the message sent event account, which must be included as a transaction signer.
@@ -65700,7 +66013,7 @@ class CctpClient {
65700
66013
  }
65701
66014
  constructor(base){
65702
66015
  this.base = base;
65703
- this.txBuilder = new TxBuilder$3(this);
66016
+ this.txBuilder = new TxBuilder$2(this);
65704
66017
  }
65705
66018
  }
65706
66019
 
@@ -65718,7 +66031,7 @@ function toReservedBytes(value) {
65718
66031
  }
65719
66032
  return bytes;
65720
66033
  }
65721
- let TxBuilder$2 = class TxBuilder extends BaseTxBuilder {
66034
+ let TxBuilder$1 = class TxBuilder extends BaseTxBuilder {
65722
66035
  async upsertExternalPositionIx(params, signer) {
65723
66036
  return await this.client.base.extEpiProgram.methods.upsertExternalPosition({
65724
66037
  positionId: toFixedArray32(params.positionId, "positionId"),
@@ -65827,12 +66140,12 @@ class EpiClient {
65827
66140
  }
65828
66141
  constructor(base){
65829
66142
  this.base = base;
65830
- this.txBuilder = new TxBuilder$2(this);
66143
+ this.txBuilder = new TxBuilder$1(this);
65831
66144
  }
65832
66145
  }
65833
66146
 
65834
66147
  const LOOPSCALE_BS_AUTH = new PublicKey("CyNKPfqsSLAejjZtEeNG3pR4SkPhSPHXdGhuNTyudrNs");
65835
- function toBn$1(value) {
66148
+ function toBn(value) {
65836
66149
  if (BN.isBN(value)) {
65837
66150
  return value;
65838
66151
  }
@@ -65846,10 +66159,10 @@ function getLoopscaleEventAuthorityPda(programId = LOOPSCALE_PROGRAM_ID) {
65846
66159
  function getLoopscaleLoanPda(borrower, nonce, programId = LOOPSCALE_PROGRAM_ID) {
65847
66160
  return PublicKey.findProgramAddressSync([
65848
66161
  borrower.toBuffer(),
65849
- toBn$1(nonce).toArrayLike(Buffer, "le", 8)
66162
+ toBn(nonce).toArrayLike(Buffer, "le", 8)
65850
66163
  ], programId)[0];
65851
66164
  }
65852
- let TxBuilder$1 = class TxBuilder extends BaseTxBuilder {
66165
+ let TxBuilder = class TxBuilder extends BaseTxBuilder {
65853
66166
  async createLoanIx(params, accounts, signer) {
65854
66167
  return await this.client.base.extLoopscaleProgram.methods.createLoan({
65855
66168
  nonce: params.nonce
@@ -66002,267 +66315,6 @@ class LoopscaleClient {
66002
66315
  const tx = await this.txBuilder.borrowPrincipalTx(params, accounts, txOptions);
66003
66316
  return await this.base.sendAndConfirm(tx);
66004
66317
  }
66005
- constructor(base){
66006
- this.base = base;
66007
- this.txBuilder = new TxBuilder$1(this);
66008
- }
66009
- }
66010
-
66011
- const NEUTRAL_PROTOCOL = 0b1;
66012
- const NEUTRAL_BUNDLE_DISCRIMINATOR = Buffer.from([
66013
- 15,
66014
- 82,
66015
- 167,
66016
- 230,
66017
- 37,
66018
- 214,
66019
- 82,
66020
- 80
66021
- ]);
66022
- class NeutralBundleAccount {
66023
- static decode(address, buffer) {
66024
- const data = NeutralBundleAccount._layout.decode(buffer);
66025
- if (!Buffer.from(data.discriminator).equals(NEUTRAL_BUNDLE_DISCRIMINATOR)) {
66026
- throw new Error("Account is not a Neutral Bundle account");
66027
- }
66028
- const account = new NeutralBundleAccount();
66029
- Object.assign(account, {
66030
- _address: address,
66031
- ...data
66032
- });
66033
- return account;
66034
- }
66035
- getAddress() {
66036
- return this._address;
66037
- }
66038
- get permissioned() {
66039
- return this.permissionned;
66040
- }
66041
- toView() {
66042
- return {
66043
- treasuryAccount: this.treasuryAccount,
66044
- assetAddress: this.assetAddress,
66045
- assetDecimals: this.assetDecimals,
66046
- permissioned: this.permissioned
66047
- };
66048
- }
66049
- }
66050
- NeutralBundleAccount._layout = struct([
66051
- array(u8(), 8, "discriminator"),
66052
- array(u8(), 32, "name"),
66053
- publicKey("manager"),
66054
- publicKey("keeper"),
66055
- publicKey("treasuryAccount"),
66056
- vec(publicKey(), "allocatedReceivers"),
66057
- u64("bundleUnderlyingBalance"),
66058
- u64("maxDepositAmount"),
66059
- u64("withdrawalDelay"),
66060
- u32("performanceFee"),
66061
- u32("managementFeeBps"),
66062
- u32("depositFee"),
66063
- u32("withdrawalFee"),
66064
- u128("managerPfeeShares"),
66065
- u32("currentAllocationBps"),
66066
- u64("oracleBuffer"),
66067
- u128("totalShares"),
66068
- u64("assetPrecision"),
66069
- publicKey("assetAddress"),
66070
- u8("assetDecimals"),
66071
- i64("withdrawalTMin"),
66072
- i64("withdrawalTMax"),
66073
- f32("withdrawalCurve"),
66074
- bool("permissionned"),
66075
- u128("managerMfeeShares"),
66076
- u64("minDepositAmount"),
66077
- i64("oracleUpdateTimeLimit"),
66078
- i64("oracleMaxAge"),
66079
- i64("withdrawalRedemptionRequestCutoffTs"),
66080
- i64("withdrawalRedemptionUnlockCurrentCycleTs"),
66081
- i64("withdrawalRedemptionUnlockNextCycleTs"),
66082
- array(u8(), 207, "padding")
66083
- ]);
66084
- function toBn(value) {
66085
- if (BN.isBN(value)) {
66086
- return value;
66087
- }
66088
- return new BN(value.toString());
66089
- }
66090
- function getNeutralUserBundlePda(authority, bundle) {
66091
- return PublicKey.findProgramAddressSync([
66092
- Buffer.from("USER_BUNDLE"),
66093
- authority.toBuffer(),
66094
- bundle.toBuffer()
66095
- ], NTBUNDLE_PROGRAM_ID)[0];
66096
- }
66097
- function getNeutralOracleDataPda(bundle) {
66098
- return PublicKey.findProgramAddressSync([
66099
- Buffer.from("ORACLE"),
66100
- bundle.toBuffer()
66101
- ], NTBUNDLE_PROGRAM_ID)[0];
66102
- }
66103
- function getNeutralBundleTempDataPda(bundle) {
66104
- return PublicKey.findProgramAddressSync([
66105
- Buffer.from("BUNDLE_TEMP_DATA"),
66106
- bundle.toBuffer()
66107
- ], NTBUNDLE_PROGRAM_ID)[0];
66108
- }
66109
- function getNeutralPendingBundleAssetAuthorityPda(bundle) {
66110
- return PublicKey.findProgramAddressSync([
66111
- Buffer.from("PENDING_BUNDLE_ASSET_AUTHORITY"),
66112
- bundle.toBuffer()
66113
- ], NTBUNDLE_PROGRAM_ID)[0];
66114
- }
66115
- function getNeutralPendingDepositTokenAccountPda(pendingBundleAssetAuthority, assetAddress) {
66116
- return getAssociatedTokenAddressSync(assetAddress, pendingBundleAssetAuthority, true, TOKEN_PROGRAM_ID);
66117
- }
66118
- let TxBuilder = class TxBuilder extends BaseTxBuilder {
66119
- async setNeutralPolicyIx(policy, signer) {
66120
- return await this.client.base.extNeutralProgram.methods.setNeutralPolicy(policy).accountsPartial({
66121
- glamState: this.client.base.statePda,
66122
- glamSigner: signer || this.client.base.signer,
66123
- glamProtocolProgram: this.client.base.protocolProgram.programId
66124
- }).instruction();
66125
- }
66126
- async setNeutralPolicyTx(policy, txOptions = {}) {
66127
- const ix = await this.setNeutralPolicyIx(policy, txOptions.signer);
66128
- return await this.buildVersionedTx([
66129
- ix
66130
- ], txOptions);
66131
- }
66132
- async initializeBundleDepositorIx(accounts, signer) {
66133
- const bundle = await this.client.fetchBundle(accounts.bundle);
66134
- if (bundle.permissioned) {
66135
- throw new Error("Bundle is permissioned. Use initializePermissionedBundleDepositor instead.");
66136
- }
66137
- return await this.client.base.extNeutralProgram.methods.initializeBundleDepositor().accountsPartial({
66138
- ...this.client.baseAccounts(signer),
66139
- bundleAccount: accounts.bundle,
66140
- userBundleAccount: accounts.userBundleAccount || this.client.getUserBundlePda(accounts.bundle)
66141
- }).instruction();
66142
- }
66143
- async initializeBundleDepositorTx(accounts, txOptions = {}) {
66144
- const ix = await this.initializeBundleDepositorIx(accounts, txOptions.signer);
66145
- return await this.buildVersionedTx([
66146
- ix
66147
- ], txOptions);
66148
- }
66149
- async initializePermissionedBundleDepositorIx(accounts, signer) {
66150
- const bundle = await this.client.fetchBundle(accounts.bundle);
66151
- if (!bundle.permissioned) {
66152
- throw new Error("Bundle is not permissioned. Use initializeBundleDepositor instead.");
66153
- }
66154
- return await this.client.base.extNeutralProgram.methods.initializePermissionedBundleDepositor().accountsPartial({
66155
- ...this.client.baseAccounts(signer),
66156
- bundleAccount: accounts.bundle,
66157
- userBundleAccount: accounts.userBundleAccount || this.client.getUserBundlePda(accounts.bundle)
66158
- }).instruction();
66159
- }
66160
- async initializePermissionedBundleDepositorTx(accounts, txOptions = {}) {
66161
- const ix = await this.initializePermissionedBundleDepositorIx(accounts, txOptions.signer);
66162
- return await this.buildVersionedTx([
66163
- ix
66164
- ], txOptions);
66165
- }
66166
- async requestDepositIx(accounts, amount, signer) {
66167
- const bundle = await this.client.fetchBundle(accounts.bundle);
66168
- const tokenProgram = accounts.tokenProgram || TOKEN_PROGRAM_ID;
66169
- const assetAddress = accounts.assetAddress || bundle.assetAddress;
66170
- const pendingBundleAssetAuthority = accounts.pendingBundleAssetAuthority || this.client.getPendingBundleAssetAuthorityPda(accounts.bundle);
66171
- return await this.client.base.extNeutralProgram.methods.requestDeposit(toBn(amount)).accountsPartial({
66172
- ...this.client.baseAccounts(signer),
66173
- userTokenAccount: accounts.userTokenAccount || this.client.base.getVaultAta(assetAddress, tokenProgram),
66174
- pendingDepositTokenAccount: accounts.pendingDepositTokenAccount || getNeutralPendingDepositTokenAccountPda(pendingBundleAssetAuthority, assetAddress),
66175
- treasuryAccount: accounts.treasuryAccount || bundle.treasuryAccount,
66176
- userBundleAccount: accounts.userBundleAccount || this.client.getUserBundlePda(accounts.bundle),
66177
- assetAddress,
66178
- oracleData: accounts.oracleData || this.client.getOracleDataPda(accounts.bundle),
66179
- bundleTempData: accounts.bundleTempData || this.client.getBundleTempDataPda(accounts.bundle),
66180
- bundleAccount: accounts.bundle,
66181
- pendingBundleAssetAuthority,
66182
- tokenProgram
66183
- }).instruction();
66184
- }
66185
- async requestDepositTx(accounts, amount, txOptions = {}) {
66186
- const ix = await this.requestDepositIx(accounts, amount, txOptions.signer);
66187
- return await this.buildVersionedTx([
66188
- ix
66189
- ], txOptions);
66190
- }
66191
- };
66192
- class NeutralClient {
66193
- baseAccounts(signer) {
66194
- return {
66195
- glamState: this.base.statePda,
66196
- glamVault: this.base.vaultPda,
66197
- glamSigner: signer || this.base.signer,
66198
- integrationAuthority: this.getIntegrationAuthorityPda(),
66199
- cpiProgram: NTBUNDLE_PROGRAM_ID,
66200
- glamProtocolProgram: this.base.protocolProgram.programId,
66201
- systemProgram: SystemProgram.programId
66202
- };
66203
- }
66204
- getIntegrationAuthorityPda() {
66205
- return getIntegrationAuthorityPda(this.base.extNeutralProgram.programId);
66206
- }
66207
- getUserBundlePda(bundle) {
66208
- return getNeutralUserBundlePda(this.base.vaultPda, bundle);
66209
- }
66210
- getOracleDataPda(bundle) {
66211
- return getNeutralOracleDataPda(bundle);
66212
- }
66213
- getBundleTempDataPda(bundle) {
66214
- return getNeutralBundleTempDataPda(bundle);
66215
- }
66216
- getPendingBundleAssetAuthorityPda(bundle) {
66217
- return getNeutralPendingBundleAssetAuthorityPda(bundle);
66218
- }
66219
- async fetchBundle(bundle) {
66220
- const account = await this.base.connection.getAccountInfo(bundle);
66221
- if (!account) {
66222
- throw new Error(`Neutral bundle account not found: ${bundle}`);
66223
- }
66224
- if (!account.owner.equals(NTBUNDLE_PROGRAM_ID)) {
66225
- throw new Error(`Neutral bundle ${bundle} is owned by ${account.owner}, expected ${NTBUNDLE_PROGRAM_ID}`);
66226
- }
66227
- return NeutralBundleAccount.decode(bundle, account.data);
66228
- }
66229
- async fetchPolicy() {
66230
- return await this.base.fetchProtocolPolicy(this.base.extNeutralProgram.programId, NEUTRAL_PROTOCOL, NeutralPolicy);
66231
- }
66232
- async setPolicy(policy, txOptions = {}) {
66233
- const tx = await this.txBuilder.setNeutralPolicyTx(policy, txOptions);
66234
- return await this.base.sendAndConfirm(tx);
66235
- }
66236
- async allowlistBundle(bundle, txOptions = {}) {
66237
- const policy = await this.fetchPolicy() ?? new NeutralPolicy([]);
66238
- if (policy.bundlesAllowlist.find((b)=>b.equals(bundle))) {
66239
- throw new Error(`Neutral bundle ${bundle} is already in the allowlist`);
66240
- }
66241
- policy.bundlesAllowlist.push(bundle);
66242
- return await this.setPolicy(policy, txOptions);
66243
- }
66244
- async initializeBundleDepositor(bundle, txOptions = {}) {
66245
- const tx = await this.txBuilder.initializeBundleDepositorTx({
66246
- bundle
66247
- }, txOptions);
66248
- return await this.base.sendAndConfirm(tx);
66249
- }
66250
- async initializePermissionedBundleDepositor(bundle, txOptions = {}) {
66251
- const tx = await this.txBuilder.initializePermissionedBundleDepositorTx({
66252
- bundle
66253
- }, txOptions);
66254
- return await this.base.sendAndConfirm(tx);
66255
- }
66256
- async requestDeposit(bundle, amount, txOptions = {}) {
66257
- const tx = await this.txBuilder.requestDepositTx({
66258
- bundle
66259
- }, amount, txOptions);
66260
- return await this.base.sendAndConfirm(tx);
66261
- }
66262
- async requestDepositUiAmount(bundle, amount, txOptions = {}) {
66263
- const bundleAccount = await this.fetchBundle(bundle);
66264
- return await this.requestDeposit(bundle, fromUiAmount(amount, bundleAccount.assetDecimals), txOptions);
66265
- }
66266
66318
  constructor(base){
66267
66319
  this.base = base;
66268
66320
  this.txBuilder = new TxBuilder(this);