@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.cjs.js CHANGED
@@ -27146,116 +27146,6 @@ var instructions$9 = [
27146
27146
  ],
27147
27147
  args: []
27148
27148
  },
27149
- {
27150
- name: "initialize_permissioned_bundle_depositor",
27151
- docs: [
27152
- "Initialize a permissioned Neutral user bundle account for the GLAM vault.",
27153
- "",
27154
- "- Permission: `InitializePermissionedBundleDepositor`.",
27155
- "- Policy: `bundle_account` must be present in `NeutralPolicy::bundles_allowlist`."
27156
- ],
27157
- discriminator: [
27158
- 157,
27159
- 162,
27160
- 213,
27161
- 42,
27162
- 205,
27163
- 201,
27164
- 37,
27165
- 255
27166
- ],
27167
- accounts: [
27168
- {
27169
- name: "glam_state",
27170
- writable: true
27171
- },
27172
- {
27173
- name: "glam_vault",
27174
- writable: true,
27175
- pda: {
27176
- seeds: [
27177
- {
27178
- kind: "const",
27179
- value: [
27180
- 118,
27181
- 97,
27182
- 117,
27183
- 108,
27184
- 116
27185
- ]
27186
- },
27187
- {
27188
- kind: "account",
27189
- path: "glam_state"
27190
- }
27191
- ],
27192
- program: {
27193
- kind: "account",
27194
- path: "glam_protocol_program"
27195
- }
27196
- }
27197
- },
27198
- {
27199
- name: "glam_signer",
27200
- writable: true,
27201
- signer: true
27202
- },
27203
- {
27204
- name: "integration_authority",
27205
- pda: {
27206
- seeds: [
27207
- {
27208
- kind: "const",
27209
- value: [
27210
- 105,
27211
- 110,
27212
- 116,
27213
- 101,
27214
- 103,
27215
- 114,
27216
- 97,
27217
- 116,
27218
- 105,
27219
- 111,
27220
- 110,
27221
- 45,
27222
- 97,
27223
- 117,
27224
- 116,
27225
- 104,
27226
- 111,
27227
- 114,
27228
- 105,
27229
- 116,
27230
- 121
27231
- ]
27232
- }
27233
- ]
27234
- }
27235
- },
27236
- {
27237
- name: "cpi_program",
27238
- address: "BUNDDh4P5XviMm1f3gCvnq2qKx6TGosAGnoUK12e7cXU"
27239
- },
27240
- {
27241
- name: "glam_protocol_program",
27242
- address: "GLAMpaME8wdTEzxtiYEAa5yD8fZbxZiz2hNtV58RZiEz"
27243
- },
27244
- {
27245
- name: "system_program",
27246
- address: "11111111111111111111111111111111"
27247
- },
27248
- {
27249
- name: "bundle_account",
27250
- writable: true
27251
- },
27252
- {
27253
- name: "user_bundle_account",
27254
- writable: true
27255
- }
27256
- ],
27257
- args: []
27258
- },
27259
27149
  {
27260
27150
  name: "request_deposit",
27261
27151
  docs: [
@@ -27392,8 +27282,7 @@ var instructions$9 = [
27392
27282
  writable: true
27393
27283
  },
27394
27284
  {
27395
- name: "token_program",
27396
- address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
27285
+ name: "token_program"
27397
27286
  }
27398
27287
  ],
27399
27288
  args: [
@@ -28674,27 +28563,22 @@ var constants$9 = [
28674
28563
  {
28675
28564
  name: "PROTO_NEUTRAL_PERM_CLOSE_USER_BUNDLE_ACCOUNT",
28676
28565
  type: "u64",
28677
- value: "16"
28566
+ value: "8"
28678
28567
  },
28679
28568
  {
28680
28569
  name: "PROTO_NEUTRAL_PERM_INITIALIZE_BUNDLE_DEPOSITOR",
28681
28570
  type: "u64",
28682
28571
  value: "1"
28683
28572
  },
28684
- {
28685
- name: "PROTO_NEUTRAL_PERM_INITIALIZE_PERMISSIONED_BUNDLE_DEPOSITOR",
28686
- type: "u64",
28687
- value: "2"
28688
- },
28689
28573
  {
28690
28574
  name: "PROTO_NEUTRAL_PERM_REQUEST_DEPOSIT",
28691
28575
  type: "u64",
28692
- value: "4"
28576
+ value: "2"
28693
28577
  },
28694
28578
  {
28695
28579
  name: "PROTO_NEUTRAL_PERM_REQUEST_WITHDRAWAL",
28696
28580
  type: "u64",
28697
- value: "8"
28581
+ value: "4"
28698
28582
  }
28699
28583
  ];
28700
28584
  var ExtNeutralIdlJson = {
@@ -36145,19 +36029,26 @@ var instructions$7 = [
36145
36029
  args: []
36146
36030
  },
36147
36031
  {
36148
- name: "price_single_asset_vault",
36032
+ name: "price_neutral_bundle_depositors",
36149
36033
  docs: [
36150
- "Prices a single asset vault."
36034
+ "Price neutral bundle depositors",
36035
+ "",
36036
+ "Remaining accounts:",
36037
+ "- 4 * N neutral bundle depositor account tuples:",
36038
+ "1. User bundle account",
36039
+ "2. Bundle account",
36040
+ "3. Bundle oracle data account",
36041
+ "4. Bundle asset oracle account"
36151
36042
  ],
36152
36043
  discriminator: [
36044
+ 202,
36153
36045
  93,
36154
- 213,
36155
- 219,
36156
- 25,
36157
- 38,
36158
- 74,
36159
- 9,
36160
- 167
36046
+ 205,
36047
+ 29,
36048
+ 37,
36049
+ 180,
36050
+ 127,
36051
+ 102
36161
36052
  ],
36162
36053
  accounts: [
36163
36054
  {
@@ -36228,7 +36119,10 @@ var instructions$7 = [
36228
36119
  signer: true
36229
36120
  },
36230
36121
  {
36231
- name: "base_asset_ata"
36122
+ name: "sol_usd_oracle"
36123
+ },
36124
+ {
36125
+ name: "base_asset_oracle"
36232
36126
  },
36233
36127
  {
36234
36128
  name: "integration_authority",
@@ -36263,6 +36157,68 @@ var instructions$7 = [
36263
36157
  ]
36264
36158
  }
36265
36159
  },
36160
+ {
36161
+ name: "glam_config",
36162
+ pda: {
36163
+ seeds: [
36164
+ {
36165
+ kind: "const",
36166
+ value: [
36167
+ 103,
36168
+ 108,
36169
+ 111,
36170
+ 98,
36171
+ 97,
36172
+ 108,
36173
+ 45,
36174
+ 99,
36175
+ 111,
36176
+ 110,
36177
+ 102,
36178
+ 105,
36179
+ 103
36180
+ ]
36181
+ }
36182
+ ],
36183
+ program: {
36184
+ kind: "const",
36185
+ value: [
36186
+ 10,
36187
+ 11,
36188
+ 0,
36189
+ 83,
36190
+ 72,
36191
+ 16,
36192
+ 46,
36193
+ 144,
36194
+ 46,
36195
+ 42,
36196
+ 79,
36197
+ 22,
36198
+ 157,
36199
+ 123,
36200
+ 21,
36201
+ 242,
36202
+ 192,
36203
+ 146,
36204
+ 1,
36205
+ 78,
36206
+ 88,
36207
+ 59,
36208
+ 102,
36209
+ 9,
36210
+ 190,
36211
+ 226,
36212
+ 92,
36213
+ 189,
36214
+ 187,
36215
+ 232,
36216
+ 83,
36217
+ 220
36218
+ ]
36219
+ }
36220
+ }
36221
+ },
36266
36222
  {
36267
36223
  name: "glam_protocol",
36268
36224
  address: "gstgptmbgJVi5f8ZmSRVZjZkDQwqKa3xWuUtD5WmJHz"
@@ -36306,16 +36262,19 @@ var instructions$7 = [
36306
36262
  args: []
36307
36263
  },
36308
36264
  {
36309
- name: "price_stake_accounts",
36265
+ name: "price_single_asset_vault",
36266
+ docs: [
36267
+ "Prices a single asset vault."
36268
+ ],
36310
36269
  discriminator: [
36311
- 119,
36312
- 137,
36270
+ 93,
36271
+ 213,
36272
+ 219,
36273
+ 25,
36274
+ 38,
36275
+ 74,
36313
36276
  9,
36314
- 15,
36315
- 196,
36316
- 73,
36317
- 30,
36318
- 27
36277
+ 167
36319
36278
  ],
36320
36279
  accounts: [
36321
36280
  {
@@ -36386,10 +36345,7 @@ var instructions$7 = [
36386
36345
  signer: true
36387
36346
  },
36388
36347
  {
36389
- name: "sol_usd_oracle"
36390
- },
36391
- {
36392
- name: "base_asset_oracle"
36348
+ name: "base_asset_ata"
36393
36349
  },
36394
36350
  {
36395
36351
  name: "integration_authority",
@@ -36424,68 +36380,229 @@ var instructions$7 = [
36424
36380
  ]
36425
36381
  }
36426
36382
  },
36427
- {
36428
- name: "glam_config",
36429
- pda: {
36430
- seeds: [
36431
- {
36432
- kind: "const",
36433
- value: [
36434
- 103,
36435
- 108,
36436
- 111,
36437
- 98,
36438
- 97,
36439
- 108,
36440
- 45,
36441
- 99,
36442
- 111,
36443
- 110,
36444
- 102,
36445
- 105,
36446
- 103
36447
- ]
36448
- }
36449
- ],
36450
- program: {
36451
- kind: "const",
36452
- value: [
36453
- 10,
36454
- 11,
36455
- 0,
36456
- 83,
36457
- 72,
36458
- 16,
36459
- 46,
36460
- 144,
36461
- 46,
36462
- 42,
36463
- 79,
36464
- 22,
36465
- 157,
36466
- 123,
36467
- 21,
36468
- 242,
36469
- 192,
36470
- 146,
36471
- 1,
36472
- 78,
36473
- 88,
36474
- 59,
36475
- 102,
36476
- 9,
36477
- 190,
36478
- 226,
36479
- 92,
36480
- 189,
36481
- 187,
36482
- 232,
36483
- 83,
36484
- 220
36485
- ]
36486
- }
36487
- }
36488
- },
36383
+ {
36384
+ name: "glam_protocol",
36385
+ address: "gstgptmbgJVi5f8ZmSRVZjZkDQwqKa3xWuUtD5WmJHz"
36386
+ },
36387
+ {
36388
+ name: "event_authority",
36389
+ optional: true,
36390
+ pda: {
36391
+ seeds: [
36392
+ {
36393
+ kind: "const",
36394
+ value: [
36395
+ 95,
36396
+ 95,
36397
+ 101,
36398
+ 118,
36399
+ 101,
36400
+ 110,
36401
+ 116,
36402
+ 95,
36403
+ 97,
36404
+ 117,
36405
+ 116,
36406
+ 104,
36407
+ 111,
36408
+ 114,
36409
+ 105,
36410
+ 116,
36411
+ 121
36412
+ ]
36413
+ }
36414
+ ]
36415
+ }
36416
+ },
36417
+ {
36418
+ name: "event_program",
36419
+ optional: true,
36420
+ address: "gstgm1M39mhgnvgyScGUDRwNn5kNVSd97hTtyow1Et5"
36421
+ }
36422
+ ],
36423
+ args: []
36424
+ },
36425
+ {
36426
+ name: "price_stake_accounts",
36427
+ discriminator: [
36428
+ 119,
36429
+ 137,
36430
+ 9,
36431
+ 15,
36432
+ 196,
36433
+ 73,
36434
+ 30,
36435
+ 27
36436
+ ],
36437
+ accounts: [
36438
+ {
36439
+ name: "glam_state",
36440
+ writable: true
36441
+ },
36442
+ {
36443
+ name: "glam_vault",
36444
+ pda: {
36445
+ seeds: [
36446
+ {
36447
+ kind: "const",
36448
+ value: [
36449
+ 118,
36450
+ 97,
36451
+ 117,
36452
+ 108,
36453
+ 116
36454
+ ]
36455
+ },
36456
+ {
36457
+ kind: "account",
36458
+ path: "glam_state"
36459
+ }
36460
+ ],
36461
+ program: {
36462
+ kind: "const",
36463
+ value: [
36464
+ 10,
36465
+ 55,
36466
+ 49,
36467
+ 193,
36468
+ 142,
36469
+ 247,
36470
+ 75,
36471
+ 193,
36472
+ 33,
36473
+ 61,
36474
+ 5,
36475
+ 218,
36476
+ 254,
36477
+ 219,
36478
+ 143,
36479
+ 206,
36480
+ 156,
36481
+ 138,
36482
+ 14,
36483
+ 32,
36484
+ 89,
36485
+ 232,
36486
+ 248,
36487
+ 173,
36488
+ 46,
36489
+ 77,
36490
+ 46,
36491
+ 206,
36492
+ 189,
36493
+ 171,
36494
+ 68,
36495
+ 237
36496
+ ]
36497
+ }
36498
+ }
36499
+ },
36500
+ {
36501
+ name: "signer",
36502
+ writable: true,
36503
+ signer: true
36504
+ },
36505
+ {
36506
+ name: "sol_usd_oracle"
36507
+ },
36508
+ {
36509
+ name: "base_asset_oracle"
36510
+ },
36511
+ {
36512
+ name: "integration_authority",
36513
+ pda: {
36514
+ seeds: [
36515
+ {
36516
+ kind: "const",
36517
+ value: [
36518
+ 105,
36519
+ 110,
36520
+ 116,
36521
+ 101,
36522
+ 103,
36523
+ 114,
36524
+ 97,
36525
+ 116,
36526
+ 105,
36527
+ 111,
36528
+ 110,
36529
+ 45,
36530
+ 97,
36531
+ 117,
36532
+ 116,
36533
+ 104,
36534
+ 111,
36535
+ 114,
36536
+ 105,
36537
+ 116,
36538
+ 121
36539
+ ]
36540
+ }
36541
+ ]
36542
+ }
36543
+ },
36544
+ {
36545
+ name: "glam_config",
36546
+ pda: {
36547
+ seeds: [
36548
+ {
36549
+ kind: "const",
36550
+ value: [
36551
+ 103,
36552
+ 108,
36553
+ 111,
36554
+ 98,
36555
+ 97,
36556
+ 108,
36557
+ 45,
36558
+ 99,
36559
+ 111,
36560
+ 110,
36561
+ 102,
36562
+ 105,
36563
+ 103
36564
+ ]
36565
+ }
36566
+ ],
36567
+ program: {
36568
+ kind: "const",
36569
+ value: [
36570
+ 10,
36571
+ 11,
36572
+ 0,
36573
+ 83,
36574
+ 72,
36575
+ 16,
36576
+ 46,
36577
+ 144,
36578
+ 46,
36579
+ 42,
36580
+ 79,
36581
+ 22,
36582
+ 157,
36583
+ 123,
36584
+ 21,
36585
+ 242,
36586
+ 192,
36587
+ 146,
36588
+ 1,
36589
+ 78,
36590
+ 88,
36591
+ 59,
36592
+ 102,
36593
+ 9,
36594
+ 190,
36595
+ 226,
36596
+ 92,
36597
+ 189,
36598
+ 187,
36599
+ 232,
36600
+ 83,
36601
+ 220
36602
+ ]
36603
+ }
36604
+ }
36605
+ },
36489
36606
  {
36490
36607
  name: "glam_protocol",
36491
36608
  address: "gstgptmbgJVi5f8ZmSRVZjZkDQwqKa3xWuUtD5WmJHz"
@@ -53736,116 +53853,6 @@ var instructions = [
53736
53853
  ],
53737
53854
  args: []
53738
53855
  },
53739
- {
53740
- name: "initialize_permissioned_bundle_depositor",
53741
- docs: [
53742
- "Initialize a permissioned Neutral user bundle account for the GLAM vault.",
53743
- "",
53744
- "- Permission: `InitializePermissionedBundleDepositor`.",
53745
- "- Policy: `bundle_account` must be present in `NeutralPolicy::bundles_allowlist`."
53746
- ],
53747
- discriminator: [
53748
- 157,
53749
- 162,
53750
- 213,
53751
- 42,
53752
- 205,
53753
- 201,
53754
- 37,
53755
- 255
53756
- ],
53757
- accounts: [
53758
- {
53759
- name: "glam_state",
53760
- writable: true
53761
- },
53762
- {
53763
- name: "glam_vault",
53764
- writable: true,
53765
- pda: {
53766
- seeds: [
53767
- {
53768
- kind: "const",
53769
- value: [
53770
- 118,
53771
- 97,
53772
- 117,
53773
- 108,
53774
- 116
53775
- ]
53776
- },
53777
- {
53778
- kind: "account",
53779
- path: "glam_state"
53780
- }
53781
- ],
53782
- program: {
53783
- kind: "account",
53784
- path: "glam_protocol_program"
53785
- }
53786
- }
53787
- },
53788
- {
53789
- name: "glam_signer",
53790
- writable: true,
53791
- signer: true
53792
- },
53793
- {
53794
- name: "integration_authority",
53795
- pda: {
53796
- seeds: [
53797
- {
53798
- kind: "const",
53799
- value: [
53800
- 105,
53801
- 110,
53802
- 116,
53803
- 101,
53804
- 103,
53805
- 114,
53806
- 97,
53807
- 116,
53808
- 105,
53809
- 111,
53810
- 110,
53811
- 45,
53812
- 97,
53813
- 117,
53814
- 116,
53815
- 104,
53816
- 111,
53817
- 114,
53818
- 105,
53819
- 116,
53820
- 121
53821
- ]
53822
- }
53823
- ]
53824
- }
53825
- },
53826
- {
53827
- name: "cpi_program",
53828
- address: "BUNDDh4P5XviMm1f3gCvnq2qKx6TGosAGnoUK12e7cXU"
53829
- },
53830
- {
53831
- name: "glam_protocol_program",
53832
- address: "gstgptmbgJVi5f8ZmSRVZjZkDQwqKa3xWuUtD5WmJHz"
53833
- },
53834
- {
53835
- name: "system_program",
53836
- address: "11111111111111111111111111111111"
53837
- },
53838
- {
53839
- name: "bundle_account",
53840
- writable: true
53841
- },
53842
- {
53843
- name: "user_bundle_account",
53844
- writable: true
53845
- }
53846
- ],
53847
- args: []
53848
- },
53849
53856
  {
53850
53857
  name: "request_deposit",
53851
53858
  docs: [
@@ -53982,8 +53989,7 @@ var instructions = [
53982
53989
  writable: true
53983
53990
  },
53984
53991
  {
53985
- name: "token_program",
53986
- address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
53992
+ name: "token_program"
53987
53993
  }
53988
53994
  ],
53989
53995
  args: [
@@ -55264,27 +55270,22 @@ var constants = [
55264
55270
  {
55265
55271
  name: "PROTO_NEUTRAL_PERM_CLOSE_USER_BUNDLE_ACCOUNT",
55266
55272
  type: "u64",
55267
- value: "16"
55273
+ value: "8"
55268
55274
  },
55269
55275
  {
55270
55276
  name: "PROTO_NEUTRAL_PERM_INITIALIZE_BUNDLE_DEPOSITOR",
55271
55277
  type: "u64",
55272
55278
  value: "1"
55273
55279
  },
55274
- {
55275
- name: "PROTO_NEUTRAL_PERM_INITIALIZE_PERMISSIONED_BUNDLE_DEPOSITOR",
55276
- type: "u64",
55277
- value: "2"
55278
- },
55279
55280
  {
55280
55281
  name: "PROTO_NEUTRAL_PERM_REQUEST_DEPOSIT",
55281
55282
  type: "u64",
55282
- value: "4"
55283
+ value: "2"
55283
55284
  },
55284
55285
  {
55285
55286
  name: "PROTO_NEUTRAL_PERM_REQUEST_WITHDRAWAL",
55286
55287
  type: "u64",
55287
- value: "8"
55288
+ value: "4"
55288
55289
  }
55289
55290
  ];
55290
55291
  var ExtNeutralIdlJsonStaging = {
@@ -63536,6 +63537,244 @@ class BridgeClient {
63536
63537
  }
63537
63538
  }
63538
63539
 
63540
+ const NEUTRAL_PROTOCOL = 0b1;
63541
+ const NEUTRAL_BUNDLE_DISCRIMINATOR = Buffer.from([
63542
+ 15,
63543
+ 82,
63544
+ 167,
63545
+ 230,
63546
+ 37,
63547
+ 214,
63548
+ 82,
63549
+ 80
63550
+ ]);
63551
+ class NeutralBundleAccount {
63552
+ static decode(address, buffer) {
63553
+ const data = NeutralBundleAccount._layout.decode(buffer);
63554
+ if (!Buffer.from(data.discriminator).equals(NEUTRAL_BUNDLE_DISCRIMINATOR)) {
63555
+ throw new Error("Account is not a Neutral Bundle account");
63556
+ }
63557
+ const account = new NeutralBundleAccount();
63558
+ Object.assign(account, {
63559
+ _address: address,
63560
+ ...data
63561
+ });
63562
+ return account;
63563
+ }
63564
+ getAddress() {
63565
+ return this._address;
63566
+ }
63567
+ get permissioned() {
63568
+ return this.permissionned;
63569
+ }
63570
+ toView() {
63571
+ return {
63572
+ treasuryAccount: this.treasuryAccount,
63573
+ assetAddress: this.assetAddress,
63574
+ assetDecimals: this.assetDecimals,
63575
+ permissioned: this.permissioned
63576
+ };
63577
+ }
63578
+ }
63579
+ NeutralBundleAccount._layout = borsh.struct([
63580
+ borsh.array(borsh.u8(), 8, "discriminator"),
63581
+ borsh.array(borsh.u8(), 32, "name"),
63582
+ borsh.publicKey("manager"),
63583
+ borsh.publicKey("keeper"),
63584
+ borsh.publicKey("treasuryAccount"),
63585
+ borsh.vec(borsh.publicKey(), "allocatedReceivers"),
63586
+ borsh.u64("bundleUnderlyingBalance"),
63587
+ borsh.u64("maxDepositAmount"),
63588
+ borsh.u64("withdrawalDelay"),
63589
+ borsh.u32("performanceFee"),
63590
+ borsh.u32("managementFeeBps"),
63591
+ borsh.u32("depositFee"),
63592
+ borsh.u32("withdrawalFee"),
63593
+ borsh.u128("managerPfeeShares"),
63594
+ borsh.u32("currentAllocationBps"),
63595
+ borsh.u64("oracleBuffer"),
63596
+ borsh.u128("totalShares"),
63597
+ borsh.u64("assetPrecision"),
63598
+ borsh.publicKey("assetAddress"),
63599
+ borsh.u8("assetDecimals"),
63600
+ borsh.i64("withdrawalTMin"),
63601
+ borsh.i64("withdrawalTMax"),
63602
+ borsh.f32("withdrawalCurve"),
63603
+ borsh.bool("permissionned"),
63604
+ borsh.u128("managerMfeeShares"),
63605
+ borsh.u64("minDepositAmount"),
63606
+ borsh.i64("oracleUpdateTimeLimit"),
63607
+ borsh.i64("oracleMaxAge"),
63608
+ borsh.i64("withdrawalRedemptionRequestCutoffTs"),
63609
+ borsh.i64("withdrawalRedemptionUnlockCurrentCycleTs"),
63610
+ borsh.i64("withdrawalRedemptionUnlockNextCycleTs"),
63611
+ borsh.array(borsh.u8(), 207, "padding")
63612
+ ]);
63613
+ function toBn$1(value) {
63614
+ if (anchor.BN.isBN(value)) {
63615
+ return value;
63616
+ }
63617
+ return new anchor.BN(value.toString());
63618
+ }
63619
+ function getNeutralUserBundlePda(authority, bundle) {
63620
+ return web3_js.PublicKey.findProgramAddressSync([
63621
+ Buffer.from("USER_BUNDLE"),
63622
+ authority.toBuffer(),
63623
+ bundle.toBuffer()
63624
+ ], NTBUNDLE_PROGRAM_ID)[0];
63625
+ }
63626
+ function getNeutralOracleDataPda(bundle) {
63627
+ return web3_js.PublicKey.findProgramAddressSync([
63628
+ Buffer.from("ORACLE"),
63629
+ bundle.toBuffer()
63630
+ ], NTBUNDLE_PROGRAM_ID)[0];
63631
+ }
63632
+ function getNeutralBundleTempDataPda(bundle) {
63633
+ return web3_js.PublicKey.findProgramAddressSync([
63634
+ Buffer.from("BUNDLE_TEMP_DATA"),
63635
+ bundle.toBuffer()
63636
+ ], NTBUNDLE_PROGRAM_ID)[0];
63637
+ }
63638
+ function getNeutralPendingBundleAssetAuthorityPda(bundle) {
63639
+ return web3_js.PublicKey.findProgramAddressSync([
63640
+ Buffer.from("PENDING_BUNDLE_ASSET_AUTHORITY"),
63641
+ bundle.toBuffer()
63642
+ ], NTBUNDLE_PROGRAM_ID)[0];
63643
+ }
63644
+ function getNeutralPendingDepositTokenAccountPda(pendingBundleAssetAuthority, assetAddress) {
63645
+ return splToken.getAssociatedTokenAddressSync(assetAddress, pendingBundleAssetAuthority, true, splToken.TOKEN_PROGRAM_ID);
63646
+ }
63647
+ let TxBuilder$8 = class TxBuilder extends BaseTxBuilder {
63648
+ async setNeutralPolicyIx(policy, signer) {
63649
+ return await this.client.base.extNeutralProgram.methods.setNeutralPolicy(policy).accountsPartial({
63650
+ glamState: this.client.base.statePda,
63651
+ glamSigner: signer || this.client.base.signer,
63652
+ glamProtocolProgram: this.client.base.protocolProgram.programId
63653
+ }).instruction();
63654
+ }
63655
+ async setNeutralPolicyTx(policy, txOptions = {}) {
63656
+ const ix = await this.setNeutralPolicyIx(policy, txOptions.signer);
63657
+ return await this.buildVersionedTx([
63658
+ ix
63659
+ ], txOptions);
63660
+ }
63661
+ async initializeBundleDepositorIx(accounts, signer) {
63662
+ const bundle = await this.client.fetchBundle(accounts.bundle);
63663
+ if (bundle.permissioned) {
63664
+ throw new Error("Bundle is permissioned. Use initializePermissionedBundleDepositor instead.");
63665
+ }
63666
+ return await this.client.base.extNeutralProgram.methods.initializeBundleDepositor().accountsPartial({
63667
+ ...this.client.baseAccounts(signer),
63668
+ bundleAccount: accounts.bundle,
63669
+ userBundleAccount: accounts.userBundleAccount || this.client.getUserBundlePda(accounts.bundle)
63670
+ }).instruction();
63671
+ }
63672
+ async initializeBundleDepositorTx(accounts, txOptions = {}) {
63673
+ const ix = await this.initializeBundleDepositorIx(accounts, txOptions.signer);
63674
+ return await this.buildVersionedTx([
63675
+ ix
63676
+ ], txOptions);
63677
+ }
63678
+ async requestDepositIx(accounts, amount, signer) {
63679
+ const bundle = await this.client.fetchBundle(accounts.bundle);
63680
+ const tokenProgram = accounts.tokenProgram || splToken.TOKEN_PROGRAM_ID;
63681
+ const assetAddress = accounts.assetAddress || bundle.assetAddress;
63682
+ const pendingBundleAssetAuthority = accounts.pendingBundleAssetAuthority || this.client.getPendingBundleAssetAuthorityPda(accounts.bundle);
63683
+ return await this.client.base.extNeutralProgram.methods.requestDeposit(toBn$1(amount)).accountsPartial({
63684
+ ...this.client.baseAccounts(signer),
63685
+ userTokenAccount: accounts.userTokenAccount || this.client.base.getVaultAta(assetAddress, tokenProgram),
63686
+ pendingDepositTokenAccount: accounts.pendingDepositTokenAccount || getNeutralPendingDepositTokenAccountPda(pendingBundleAssetAuthority, assetAddress),
63687
+ treasuryAccount: accounts.treasuryAccount || bundle.treasuryAccount,
63688
+ userBundleAccount: accounts.userBundleAccount || this.client.getUserBundlePda(accounts.bundle),
63689
+ assetAddress,
63690
+ oracleData: accounts.oracleData || this.client.getOracleDataPda(accounts.bundle),
63691
+ bundleTempData: accounts.bundleTempData || this.client.getBundleTempDataPda(accounts.bundle),
63692
+ bundleAccount: accounts.bundle,
63693
+ pendingBundleAssetAuthority,
63694
+ tokenProgram
63695
+ }).instruction();
63696
+ }
63697
+ async requestDepositTx(accounts, amount, txOptions = {}) {
63698
+ const ix = await this.requestDepositIx(accounts, amount, txOptions.signer);
63699
+ return await this.buildVersionedTx([
63700
+ ix
63701
+ ], txOptions);
63702
+ }
63703
+ };
63704
+ class NeutralClient {
63705
+ baseAccounts(signer) {
63706
+ return {
63707
+ glamState: this.base.statePda,
63708
+ glamVault: this.base.vaultPda,
63709
+ glamSigner: signer || this.base.signer,
63710
+ integrationAuthority: this.getIntegrationAuthorityPda(),
63711
+ cpiProgram: NTBUNDLE_PROGRAM_ID,
63712
+ glamProtocolProgram: this.base.protocolProgram.programId,
63713
+ systemProgram: web3_js.SystemProgram.programId
63714
+ };
63715
+ }
63716
+ getIntegrationAuthorityPda() {
63717
+ return getIntegrationAuthorityPda(this.base.extNeutralProgram.programId);
63718
+ }
63719
+ getUserBundlePda(bundle) {
63720
+ return getNeutralUserBundlePda(this.base.vaultPda, bundle);
63721
+ }
63722
+ getOracleDataPda(bundle) {
63723
+ return getNeutralOracleDataPda(bundle);
63724
+ }
63725
+ getBundleTempDataPda(bundle) {
63726
+ return getNeutralBundleTempDataPda(bundle);
63727
+ }
63728
+ getPendingBundleAssetAuthorityPda(bundle) {
63729
+ return getNeutralPendingBundleAssetAuthorityPda(bundle);
63730
+ }
63731
+ async fetchBundle(bundle) {
63732
+ const account = await this.base.connection.getAccountInfo(bundle);
63733
+ if (!account) {
63734
+ throw new Error(`Neutral bundle account not found: ${bundle}`);
63735
+ }
63736
+ if (!account.owner.equals(NTBUNDLE_PROGRAM_ID)) {
63737
+ throw new Error(`Neutral bundle ${bundle} is owned by ${account.owner}, expected ${NTBUNDLE_PROGRAM_ID}`);
63738
+ }
63739
+ return NeutralBundleAccount.decode(bundle, account.data);
63740
+ }
63741
+ async fetchPolicy() {
63742
+ return await this.base.fetchProtocolPolicy(this.base.extNeutralProgram.programId, NEUTRAL_PROTOCOL, NeutralPolicy);
63743
+ }
63744
+ async setPolicy(policy, txOptions = {}) {
63745
+ const tx = await this.txBuilder.setNeutralPolicyTx(policy, txOptions);
63746
+ return await this.base.sendAndConfirm(tx);
63747
+ }
63748
+ async allowlistBundle(bundle, txOptions = {}) {
63749
+ const policy = await this.fetchPolicy() ?? new NeutralPolicy([]);
63750
+ if (policy.bundlesAllowlist.find((b)=>b.equals(bundle))) {
63751
+ throw new Error(`Neutral bundle ${bundle} is already in the allowlist`);
63752
+ }
63753
+ policy.bundlesAllowlist.push(bundle);
63754
+ return await this.setPolicy(policy, txOptions);
63755
+ }
63756
+ async initializeBundleDepositor(bundle, txOptions = {}) {
63757
+ const tx = await this.txBuilder.initializeBundleDepositorTx({
63758
+ bundle
63759
+ }, txOptions);
63760
+ return await this.base.sendAndConfirm(tx);
63761
+ }
63762
+ async requestDeposit(bundle, amount, txOptions = {}) {
63763
+ const tx = await this.txBuilder.requestDepositTx({
63764
+ bundle
63765
+ }, amount, txOptions);
63766
+ return await this.base.sendAndConfirm(tx);
63767
+ }
63768
+ async requestDepositUiAmount(bundle, amount, txOptions = {}) {
63769
+ const bundleAccount = await this.fetchBundle(bundle);
63770
+ return await this.requestDeposit(bundle, fromUiAmount(amount, bundleAccount.assetDecimals), txOptions);
63771
+ }
63772
+ constructor(base){
63773
+ this.base = base;
63774
+ this.txBuilder = new TxBuilder$8(this);
63775
+ }
63776
+ }
63777
+
63539
63778
  /**
63540
63779
  * Represents a single asset holding within a vault.
63541
63780
  *
@@ -64170,6 +64409,76 @@ class PriceClient {
64170
64409
  kaminoReserves: Array.from(kaminoReserves)
64171
64410
  };
64172
64411
  }
64412
+ async priceNeutralBundleDepositorsIx() {
64413
+ const stateModel = this.cachedStateModel ?? await this.base.fetchStateModel();
64414
+ const externalPositions = new PkSet(stateModel.externalPositions ?? []);
64415
+ const policy = await this.base.fetchProtocolPolicy(this.base.extNeutralProgram.programId, NEUTRAL_PROTOCOL, NeutralPolicy);
64416
+ if (!policy || policy.bundlesAllowlist.length === 0) {
64417
+ return {
64418
+ ixs: [],
64419
+ kaminoReserves: []
64420
+ };
64421
+ }
64422
+ const positions = policy.bundlesAllowlist.map((bundle)=>({
64423
+ bundle,
64424
+ userBundle: getNeutralUserBundlePda(this.base.vaultPda, bundle)
64425
+ })).filter(({ userBundle })=>externalPositions.has(userBundle));
64426
+ if (positions.length === 0) {
64427
+ return {
64428
+ ixs: [],
64429
+ kaminoReserves: []
64430
+ };
64431
+ }
64432
+ const bundleInfos = await this.base.connection.getMultipleAccountsInfo(positions.map(({ bundle })=>bundle), "confirmed");
64433
+ const [solUsdOracle, baseAssetOracle, baseAssetMeta] = await Promise.all([
64434
+ this.base.getSolOracle(),
64435
+ this.getBaseAssetOracle(),
64436
+ this.base.getAssetMeta(stateModel.baseAssetMint)
64437
+ ]);
64438
+ const kaminoReserves = new PkSet();
64439
+ if (baseAssetMeta.oracleSource === "KaminoReserve") {
64440
+ kaminoReserves.add(baseAssetMeta.oracle);
64441
+ }
64442
+ const remainingAccounts = [];
64443
+ for(let i = 0; i < positions.length; i++){
64444
+ const { bundle, userBundle } = positions[i];
64445
+ const bundleInfo = bundleInfos[i];
64446
+ if (!bundleInfo) {
64447
+ throw new Error(`Neutral bundle account not found: ${bundle}`);
64448
+ }
64449
+ if (!bundleInfo.owner.equals(NTBUNDLE_PROGRAM_ID)) {
64450
+ throw new Error(`Neutral bundle ${bundle} is owned by ${bundleInfo.owner}, expected ${NTBUNDLE_PROGRAM_ID}`);
64451
+ }
64452
+ const bundleAccount = NeutralBundleAccount.decode(bundle, bundleInfo.data);
64453
+ const bundleAssetMeta = await this.base.getAssetMeta(bundleAccount.assetAddress);
64454
+ if (bundleAssetMeta.oracleSource === "KaminoReserve") {
64455
+ kaminoReserves.add(bundleAssetMeta.oracle);
64456
+ }
64457
+ [
64458
+ userBundle,
64459
+ bundle,
64460
+ getNeutralOracleDataPda(bundle),
64461
+ bundleAssetMeta.oracle
64462
+ ].forEach((pubkey)=>{
64463
+ remainingAccounts.push({
64464
+ pubkey,
64465
+ isSigner: false,
64466
+ isWritable: false
64467
+ });
64468
+ });
64469
+ }
64470
+ const ix = await this.base.mintProgram.methods.priceNeutralBundleDepositors().accounts({
64471
+ glamState: this.base.statePda,
64472
+ solUsdOracle,
64473
+ baseAssetOracle
64474
+ }).remainingAccounts(remainingAccounts).instruction();
64475
+ return {
64476
+ ixs: [
64477
+ ix
64478
+ ],
64479
+ kaminoReserves: Array.from(kaminoReserves)
64480
+ };
64481
+ }
64173
64482
  async priceEpiValidatedPositionsIx() {
64174
64483
  const observationState = await this.epi.fetchObservationState();
64175
64484
  if (!observationState) {
@@ -64241,6 +64550,10 @@ class PriceClient {
64241
64550
  if (bridgeIntegrationAcl) {
64242
64551
  chunks.push(await this.priceManagedTransfersIxs());
64243
64552
  }
64553
+ const neutralIntegrationAcl = integrationAcls.find((acl)=>acl.integrationProgram.equals(this.base.extNeutralProgram.programId) && (acl.protocolsBitmask & NEUTRAL_PROTOCOL) !== 0);
64554
+ if (neutralIntegrationAcl) {
64555
+ chunks.push(await this.priceNeutralBundleDepositorsIx());
64556
+ }
64244
64557
  }
64245
64558
  // Coalesce all kamino reserve refreshes into a single front-loaded ix.
64246
64559
  const allReserves = new PkSet();
@@ -64311,7 +64624,7 @@ class PriceClient {
64311
64624
  }
64312
64625
  }
64313
64626
 
64314
- let TxBuilder$8 = class TxBuilder extends BaseTxBuilder {
64627
+ let TxBuilder$7 = class TxBuilder extends BaseTxBuilder {
64315
64628
  async crystallizeFeesIxs(glamSigner) {
64316
64629
  const glamState = this.client.base.statePda;
64317
64630
  const glamMint = this.client.base.mintPda;
@@ -64469,11 +64782,11 @@ class FeesClient {
64469
64782
  constructor(base, price){
64470
64783
  this.base = base;
64471
64784
  this.price = price;
64472
- this.txBuilder = new TxBuilder$8(this);
64785
+ this.txBuilder = new TxBuilder$7(this);
64473
64786
  }
64474
64787
  }
64475
64788
 
64476
- let TxBuilder$7 = class TxBuilder extends BaseTxBuilder {
64789
+ let TxBuilder$6 = class TxBuilder extends BaseTxBuilder {
64477
64790
  async emergencyAccessUpdateIx(args, signer) {
64478
64791
  return await this.client.base.protocolProgram.methods.emergencyAccessUpdate(new EmergencyAccessUpdateArgs(args)).accounts({
64479
64792
  glamState: this.client.base.statePda,
@@ -64638,11 +64951,11 @@ class AccessClient {
64638
64951
  }
64639
64952
  constructor(base){
64640
64953
  this.base = base;
64641
- this.txBuilder = new TxBuilder$7(this);
64954
+ this.txBuilder = new TxBuilder$6(this);
64642
64955
  }
64643
64956
  }
64644
64957
 
64645
- let TxBuilder$6 = class TxBuilder extends BaseTxBuilder {
64958
+ let TxBuilder$5 = class TxBuilder extends BaseTxBuilder {
64646
64959
  async applyStateTimelockIx(glamSigner) {
64647
64960
  return await this.client.base.protocolProgram.methods.updateStateApplyTimelock().accounts({
64648
64961
  glamState: this.client.base.statePda,
@@ -64720,11 +65033,11 @@ class TimelockClient {
64720
65033
  constructor(base, stateClient){
64721
65034
  this.base = base;
64722
65035
  this.stateClient = stateClient;
64723
- this.txBuilder = new TxBuilder$6(this);
65036
+ this.txBuilder = new TxBuilder$5(this);
64724
65037
  }
64725
65038
  }
64726
65039
 
64727
- let TxBuilder$5 = class TxBuilder extends BaseTxBuilder {
65040
+ let TxBuilder$4 = class TxBuilder extends BaseTxBuilder {
64728
65041
  async initializeAndDelegateStakeIxs(vote, amount, glamSigner) {
64729
65042
  const [stakeAccount, createStakeAccountIx] = await this.client.createStakeAccount(glamSigner);
64730
65043
  const glamState = this.client.base.statePda;
@@ -64937,11 +65250,11 @@ class StakeClient {
64937
65250
  }
64938
65251
  constructor(base){
64939
65252
  this.base = base;
64940
- this.txBuilder = new TxBuilder$5(this);
65253
+ this.txBuilder = new TxBuilder$4(this);
64941
65254
  }
64942
65255
  }
64943
65256
 
64944
- let TxBuilder$4 = class TxBuilder extends BaseTxBuilder {
65257
+ let TxBuilder$3 = class TxBuilder extends BaseTxBuilder {
64945
65258
  async depositSolIxs(stakePool, lamports, glamSigner) {
64946
65259
  const { programId: stakePoolProgram, poolMint, withdrawAuthority, feeAccount, tokenProgramId: tokenProgram, reserveStake } = await this.client.getStakePoolAccountData(stakePool);
64947
65260
  const glamVault = this.client.base.vaultPda;
@@ -65139,7 +65452,7 @@ class StakePoolClient {
65139
65452
  this.base = base;
65140
65453
  this.stake = stake;
65141
65454
  this.marinade = marinade;
65142
- this.txBuilder = new TxBuilder$4(this);
65455
+ this.txBuilder = new TxBuilder$3(this);
65143
65456
  }
65144
65457
  }
65145
65458
 
@@ -65189,7 +65502,7 @@ class CctpBridgeEvent {
65189
65502
  this.uiAmount = toUiAmount(this.amount, 6);
65190
65503
  }
65191
65504
  }
65192
- let TxBuilder$3 = class TxBuilder extends BaseTxBuilder {
65505
+ let TxBuilder$2 = class TxBuilder extends BaseTxBuilder {
65193
65506
  /**
65194
65507
  * Returns a transaction that calls CCTP's `depositForBurn` instruction that bridges USDC to another chain.
65195
65508
  * A keypair is generated for the message sent event account, which must be included as a transaction signer.
@@ -65720,7 +66033,7 @@ class CctpClient {
65720
66033
  }
65721
66034
  constructor(base){
65722
66035
  this.base = base;
65723
- this.txBuilder = new TxBuilder$3(this);
66036
+ this.txBuilder = new TxBuilder$2(this);
65724
66037
  }
65725
66038
  }
65726
66039
 
@@ -65738,7 +66051,7 @@ function toReservedBytes(value) {
65738
66051
  }
65739
66052
  return bytes;
65740
66053
  }
65741
- let TxBuilder$2 = class TxBuilder extends BaseTxBuilder {
66054
+ let TxBuilder$1 = class TxBuilder extends BaseTxBuilder {
65742
66055
  async upsertExternalPositionIx(params, signer) {
65743
66056
  return await this.client.base.extEpiProgram.methods.upsertExternalPosition({
65744
66057
  positionId: toFixedArray32(params.positionId, "positionId"),
@@ -65847,12 +66160,12 @@ class EpiClient {
65847
66160
  }
65848
66161
  constructor(base){
65849
66162
  this.base = base;
65850
- this.txBuilder = new TxBuilder$2(this);
66163
+ this.txBuilder = new TxBuilder$1(this);
65851
66164
  }
65852
66165
  }
65853
66166
 
65854
66167
  const LOOPSCALE_BS_AUTH = new web3_js.PublicKey("CyNKPfqsSLAejjZtEeNG3pR4SkPhSPHXdGhuNTyudrNs");
65855
- function toBn$1(value) {
66168
+ function toBn(value) {
65856
66169
  if (anchor.BN.isBN(value)) {
65857
66170
  return value;
65858
66171
  }
@@ -65866,10 +66179,10 @@ function getLoopscaleEventAuthorityPda(programId = LOOPSCALE_PROGRAM_ID) {
65866
66179
  function getLoopscaleLoanPda(borrower, nonce, programId = LOOPSCALE_PROGRAM_ID) {
65867
66180
  return web3_js.PublicKey.findProgramAddressSync([
65868
66181
  borrower.toBuffer(),
65869
- toBn$1(nonce).toArrayLike(Buffer, "le", 8)
66182
+ toBn(nonce).toArrayLike(Buffer, "le", 8)
65870
66183
  ], programId)[0];
65871
66184
  }
65872
- let TxBuilder$1 = class TxBuilder extends BaseTxBuilder {
66185
+ let TxBuilder = class TxBuilder extends BaseTxBuilder {
65873
66186
  async createLoanIx(params, accounts, signer) {
65874
66187
  return await this.client.base.extLoopscaleProgram.methods.createLoan({
65875
66188
  nonce: params.nonce
@@ -66022,267 +66335,6 @@ class LoopscaleClient {
66022
66335
  const tx = await this.txBuilder.borrowPrincipalTx(params, accounts, txOptions);
66023
66336
  return await this.base.sendAndConfirm(tx);
66024
66337
  }
66025
- constructor(base){
66026
- this.base = base;
66027
- this.txBuilder = new TxBuilder$1(this);
66028
- }
66029
- }
66030
-
66031
- const NEUTRAL_PROTOCOL = 0b1;
66032
- const NEUTRAL_BUNDLE_DISCRIMINATOR = Buffer.from([
66033
- 15,
66034
- 82,
66035
- 167,
66036
- 230,
66037
- 37,
66038
- 214,
66039
- 82,
66040
- 80
66041
- ]);
66042
- class NeutralBundleAccount {
66043
- static decode(address, buffer) {
66044
- const data = NeutralBundleAccount._layout.decode(buffer);
66045
- if (!Buffer.from(data.discriminator).equals(NEUTRAL_BUNDLE_DISCRIMINATOR)) {
66046
- throw new Error("Account is not a Neutral Bundle account");
66047
- }
66048
- const account = new NeutralBundleAccount();
66049
- Object.assign(account, {
66050
- _address: address,
66051
- ...data
66052
- });
66053
- return account;
66054
- }
66055
- getAddress() {
66056
- return this._address;
66057
- }
66058
- get permissioned() {
66059
- return this.permissionned;
66060
- }
66061
- toView() {
66062
- return {
66063
- treasuryAccount: this.treasuryAccount,
66064
- assetAddress: this.assetAddress,
66065
- assetDecimals: this.assetDecimals,
66066
- permissioned: this.permissioned
66067
- };
66068
- }
66069
- }
66070
- NeutralBundleAccount._layout = borsh.struct([
66071
- borsh.array(borsh.u8(), 8, "discriminator"),
66072
- borsh.array(borsh.u8(), 32, "name"),
66073
- borsh.publicKey("manager"),
66074
- borsh.publicKey("keeper"),
66075
- borsh.publicKey("treasuryAccount"),
66076
- borsh.vec(borsh.publicKey(), "allocatedReceivers"),
66077
- borsh.u64("bundleUnderlyingBalance"),
66078
- borsh.u64("maxDepositAmount"),
66079
- borsh.u64("withdrawalDelay"),
66080
- borsh.u32("performanceFee"),
66081
- borsh.u32("managementFeeBps"),
66082
- borsh.u32("depositFee"),
66083
- borsh.u32("withdrawalFee"),
66084
- borsh.u128("managerPfeeShares"),
66085
- borsh.u32("currentAllocationBps"),
66086
- borsh.u64("oracleBuffer"),
66087
- borsh.u128("totalShares"),
66088
- borsh.u64("assetPrecision"),
66089
- borsh.publicKey("assetAddress"),
66090
- borsh.u8("assetDecimals"),
66091
- borsh.i64("withdrawalTMin"),
66092
- borsh.i64("withdrawalTMax"),
66093
- borsh.f32("withdrawalCurve"),
66094
- borsh.bool("permissionned"),
66095
- borsh.u128("managerMfeeShares"),
66096
- borsh.u64("minDepositAmount"),
66097
- borsh.i64("oracleUpdateTimeLimit"),
66098
- borsh.i64("oracleMaxAge"),
66099
- borsh.i64("withdrawalRedemptionRequestCutoffTs"),
66100
- borsh.i64("withdrawalRedemptionUnlockCurrentCycleTs"),
66101
- borsh.i64("withdrawalRedemptionUnlockNextCycleTs"),
66102
- borsh.array(borsh.u8(), 207, "padding")
66103
- ]);
66104
- function toBn(value) {
66105
- if (anchor.BN.isBN(value)) {
66106
- return value;
66107
- }
66108
- return new anchor.BN(value.toString());
66109
- }
66110
- function getNeutralUserBundlePda(authority, bundle) {
66111
- return web3_js.PublicKey.findProgramAddressSync([
66112
- Buffer.from("USER_BUNDLE"),
66113
- authority.toBuffer(),
66114
- bundle.toBuffer()
66115
- ], NTBUNDLE_PROGRAM_ID)[0];
66116
- }
66117
- function getNeutralOracleDataPda(bundle) {
66118
- return web3_js.PublicKey.findProgramAddressSync([
66119
- Buffer.from("ORACLE"),
66120
- bundle.toBuffer()
66121
- ], NTBUNDLE_PROGRAM_ID)[0];
66122
- }
66123
- function getNeutralBundleTempDataPda(bundle) {
66124
- return web3_js.PublicKey.findProgramAddressSync([
66125
- Buffer.from("BUNDLE_TEMP_DATA"),
66126
- bundle.toBuffer()
66127
- ], NTBUNDLE_PROGRAM_ID)[0];
66128
- }
66129
- function getNeutralPendingBundleAssetAuthorityPda(bundle) {
66130
- return web3_js.PublicKey.findProgramAddressSync([
66131
- Buffer.from("PENDING_BUNDLE_ASSET_AUTHORITY"),
66132
- bundle.toBuffer()
66133
- ], NTBUNDLE_PROGRAM_ID)[0];
66134
- }
66135
- function getNeutralPendingDepositTokenAccountPda(pendingBundleAssetAuthority, assetAddress) {
66136
- return splToken.getAssociatedTokenAddressSync(assetAddress, pendingBundleAssetAuthority, true, splToken.TOKEN_PROGRAM_ID);
66137
- }
66138
- let TxBuilder = class TxBuilder extends BaseTxBuilder {
66139
- async setNeutralPolicyIx(policy, signer) {
66140
- return await this.client.base.extNeutralProgram.methods.setNeutralPolicy(policy).accountsPartial({
66141
- glamState: this.client.base.statePda,
66142
- glamSigner: signer || this.client.base.signer,
66143
- glamProtocolProgram: this.client.base.protocolProgram.programId
66144
- }).instruction();
66145
- }
66146
- async setNeutralPolicyTx(policy, txOptions = {}) {
66147
- const ix = await this.setNeutralPolicyIx(policy, txOptions.signer);
66148
- return await this.buildVersionedTx([
66149
- ix
66150
- ], txOptions);
66151
- }
66152
- async initializeBundleDepositorIx(accounts, signer) {
66153
- const bundle = await this.client.fetchBundle(accounts.bundle);
66154
- if (bundle.permissioned) {
66155
- throw new Error("Bundle is permissioned. Use initializePermissionedBundleDepositor instead.");
66156
- }
66157
- return await this.client.base.extNeutralProgram.methods.initializeBundleDepositor().accountsPartial({
66158
- ...this.client.baseAccounts(signer),
66159
- bundleAccount: accounts.bundle,
66160
- userBundleAccount: accounts.userBundleAccount || this.client.getUserBundlePda(accounts.bundle)
66161
- }).instruction();
66162
- }
66163
- async initializeBundleDepositorTx(accounts, txOptions = {}) {
66164
- const ix = await this.initializeBundleDepositorIx(accounts, txOptions.signer);
66165
- return await this.buildVersionedTx([
66166
- ix
66167
- ], txOptions);
66168
- }
66169
- async initializePermissionedBundleDepositorIx(accounts, signer) {
66170
- const bundle = await this.client.fetchBundle(accounts.bundle);
66171
- if (!bundle.permissioned) {
66172
- throw new Error("Bundle is not permissioned. Use initializeBundleDepositor instead.");
66173
- }
66174
- return await this.client.base.extNeutralProgram.methods.initializePermissionedBundleDepositor().accountsPartial({
66175
- ...this.client.baseAccounts(signer),
66176
- bundleAccount: accounts.bundle,
66177
- userBundleAccount: accounts.userBundleAccount || this.client.getUserBundlePda(accounts.bundle)
66178
- }).instruction();
66179
- }
66180
- async initializePermissionedBundleDepositorTx(accounts, txOptions = {}) {
66181
- const ix = await this.initializePermissionedBundleDepositorIx(accounts, txOptions.signer);
66182
- return await this.buildVersionedTx([
66183
- ix
66184
- ], txOptions);
66185
- }
66186
- async requestDepositIx(accounts, amount, signer) {
66187
- const bundle = await this.client.fetchBundle(accounts.bundle);
66188
- const tokenProgram = accounts.tokenProgram || splToken.TOKEN_PROGRAM_ID;
66189
- const assetAddress = accounts.assetAddress || bundle.assetAddress;
66190
- const pendingBundleAssetAuthority = accounts.pendingBundleAssetAuthority || this.client.getPendingBundleAssetAuthorityPda(accounts.bundle);
66191
- return await this.client.base.extNeutralProgram.methods.requestDeposit(toBn(amount)).accountsPartial({
66192
- ...this.client.baseAccounts(signer),
66193
- userTokenAccount: accounts.userTokenAccount || this.client.base.getVaultAta(assetAddress, tokenProgram),
66194
- pendingDepositTokenAccount: accounts.pendingDepositTokenAccount || getNeutralPendingDepositTokenAccountPda(pendingBundleAssetAuthority, assetAddress),
66195
- treasuryAccount: accounts.treasuryAccount || bundle.treasuryAccount,
66196
- userBundleAccount: accounts.userBundleAccount || this.client.getUserBundlePda(accounts.bundle),
66197
- assetAddress,
66198
- oracleData: accounts.oracleData || this.client.getOracleDataPda(accounts.bundle),
66199
- bundleTempData: accounts.bundleTempData || this.client.getBundleTempDataPda(accounts.bundle),
66200
- bundleAccount: accounts.bundle,
66201
- pendingBundleAssetAuthority,
66202
- tokenProgram
66203
- }).instruction();
66204
- }
66205
- async requestDepositTx(accounts, amount, txOptions = {}) {
66206
- const ix = await this.requestDepositIx(accounts, amount, txOptions.signer);
66207
- return await this.buildVersionedTx([
66208
- ix
66209
- ], txOptions);
66210
- }
66211
- };
66212
- class NeutralClient {
66213
- baseAccounts(signer) {
66214
- return {
66215
- glamState: this.base.statePda,
66216
- glamVault: this.base.vaultPda,
66217
- glamSigner: signer || this.base.signer,
66218
- integrationAuthority: this.getIntegrationAuthorityPda(),
66219
- cpiProgram: NTBUNDLE_PROGRAM_ID,
66220
- glamProtocolProgram: this.base.protocolProgram.programId,
66221
- systemProgram: web3_js.SystemProgram.programId
66222
- };
66223
- }
66224
- getIntegrationAuthorityPda() {
66225
- return getIntegrationAuthorityPda(this.base.extNeutralProgram.programId);
66226
- }
66227
- getUserBundlePda(bundle) {
66228
- return getNeutralUserBundlePda(this.base.vaultPda, bundle);
66229
- }
66230
- getOracleDataPda(bundle) {
66231
- return getNeutralOracleDataPda(bundle);
66232
- }
66233
- getBundleTempDataPda(bundle) {
66234
- return getNeutralBundleTempDataPda(bundle);
66235
- }
66236
- getPendingBundleAssetAuthorityPda(bundle) {
66237
- return getNeutralPendingBundleAssetAuthorityPda(bundle);
66238
- }
66239
- async fetchBundle(bundle) {
66240
- const account = await this.base.connection.getAccountInfo(bundle);
66241
- if (!account) {
66242
- throw new Error(`Neutral bundle account not found: ${bundle}`);
66243
- }
66244
- if (!account.owner.equals(NTBUNDLE_PROGRAM_ID)) {
66245
- throw new Error(`Neutral bundle ${bundle} is owned by ${account.owner}, expected ${NTBUNDLE_PROGRAM_ID}`);
66246
- }
66247
- return NeutralBundleAccount.decode(bundle, account.data);
66248
- }
66249
- async fetchPolicy() {
66250
- return await this.base.fetchProtocolPolicy(this.base.extNeutralProgram.programId, NEUTRAL_PROTOCOL, NeutralPolicy);
66251
- }
66252
- async setPolicy(policy, txOptions = {}) {
66253
- const tx = await this.txBuilder.setNeutralPolicyTx(policy, txOptions);
66254
- return await this.base.sendAndConfirm(tx);
66255
- }
66256
- async allowlistBundle(bundle, txOptions = {}) {
66257
- const policy = await this.fetchPolicy() ?? new NeutralPolicy([]);
66258
- if (policy.bundlesAllowlist.find((b)=>b.equals(bundle))) {
66259
- throw new Error(`Neutral bundle ${bundle} is already in the allowlist`);
66260
- }
66261
- policy.bundlesAllowlist.push(bundle);
66262
- return await this.setPolicy(policy, txOptions);
66263
- }
66264
- async initializeBundleDepositor(bundle, txOptions = {}) {
66265
- const tx = await this.txBuilder.initializeBundleDepositorTx({
66266
- bundle
66267
- }, txOptions);
66268
- return await this.base.sendAndConfirm(tx);
66269
- }
66270
- async initializePermissionedBundleDepositor(bundle, txOptions = {}) {
66271
- const tx = await this.txBuilder.initializePermissionedBundleDepositorTx({
66272
- bundle
66273
- }, txOptions);
66274
- return await this.base.sendAndConfirm(tx);
66275
- }
66276
- async requestDeposit(bundle, amount, txOptions = {}) {
66277
- const tx = await this.txBuilder.requestDepositTx({
66278
- bundle
66279
- }, amount, txOptions);
66280
- return await this.base.sendAndConfirm(tx);
66281
- }
66282
- async requestDepositUiAmount(bundle, amount, txOptions = {}) {
66283
- const bundleAccount = await this.fetchBundle(bundle);
66284
- return await this.requestDeposit(bundle, fromUiAmount(amount, bundleAccount.assetDecimals), txOptions);
66285
- }
66286
66338
  constructor(base){
66287
66339
  this.base = base;
66288
66340
  this.txBuilder = new TxBuilder(this);