@elmntl/vaults-v2 1.3.4 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,10 +33,36 @@ import {
33
33
  } from "../types";
34
34
  import idl from "../generated/idl/elemental_vault_v2.json";
35
35
 
36
+ /**
37
+ * The DEFAULT program this SDK targets: ELE6 — the original deployment and
38
+ * the contract every consumer was published against (locked by tests/sdk.test.ts).
39
+ *
40
+ * ELE6 and ELE7 run byte-identical code since 2026-08-18 (both solana-verify
41
+ * builds of ele-vault-v2 @ 65e7b7f; they differ only in declare_id), so one
42
+ * embedded IDL serves both. Select the deployment explicitly:
43
+ * new ElementalV2Context(provider, ELE7_PROGRAM_ID)
44
+ * The embedded IDL's `address` field is never trusted — the constructor always
45
+ * stamps the chosen program id onto it, so the default stays what this constant
46
+ * says regardless of which program the IDL was generated against.
47
+ *
48
+ * Only ELE7 is a migration TARGET (it holds the MigrationConfig accounts);
49
+ * ELE5/ELE6 are sources whose migrate_out CPIs into it.
50
+ */
36
51
  export const VAULT_PROGRAM_ID = new PublicKey(
37
52
  "ELE6rYCZUaegWxVhWM4ef9pXZBAgGUVaVKkTbDvX6BMU",
38
53
  );
39
54
 
55
+ /** ELE6 — same as the default; exported for explicitness at call sites. */
56
+ export const ELE6_PROGRAM_ID = VAULT_PROGRAM_ID;
57
+
58
+ /** ELE7 — newer deployment; all ELE7-era pools (USDT, ONyc V2, USDC_J/K/RWA, E1, SOL_X1). */
59
+ export const ELE7_PROGRAM_ID = new PublicKey(
60
+ "ELE7vRKKCzWT5SEt1eey2Snn3z6pWmBuv5AjDq3BeS1Y",
61
+ );
62
+
63
+ /** Migrations always land in ELE7 — it is the only program holding MigrationConfigs. */
64
+ export const MIGRATION_TARGET_PROGRAM_ID = ELE7_PROGRAM_ID;
65
+
40
66
  export class ElementalV2Context {
41
67
  public readonly provider: AnchorProvider;
42
68
  public readonly program: Program;
@@ -44,12 +70,12 @@ export class ElementalV2Context {
44
70
 
45
71
  constructor(provider: AnchorProvider, programId?: PublicKey) {
46
72
  this.provider = provider;
47
- if (programId) {
48
- const customIdl = { ...idl, address: programId.toBase58() };
49
- this.program = new Program(customIdl as Idl, provider);
50
- } else {
51
- this.program = new Program(idl as Idl, provider);
52
- }
73
+ // Always stamp the selected deployment onto the IDL: the generated file's
74
+ // `address` reflects whichever program it was generated against, and must
75
+ // never decide the default.
76
+ const target = programId ?? VAULT_PROGRAM_ID;
77
+ const customIdl = { ...idl, address: target.toBase58() };
78
+ this.program = new Program(customIdl as Idl, provider);
53
79
  }
54
80
 
55
81
  get connection(): Connection {
@@ -605,6 +631,69 @@ export class ElementalV2Context {
605
631
  return [ix];
606
632
  }
607
633
 
634
+
635
+ /**
636
+ * Move this position into an ELE7 pool — principal AND all unclaimed rewards
637
+ * — in ONE instruction, skipping the 2-epoch cooldown.
638
+ *
639
+ * NO TOKENS MOVE. migrate_out settles the position, closes it (rent back to
640
+ * the owner) and CPIs into ELE7's migrate_in, which credits the whole settled
641
+ * total as PRINCIPAL of the target position. Yield earned in the old vault
642
+ * stops being yield and starts earning the target pool's rate next epoch.
643
+ * Because it is a ledger transfer between programs, every balance-delta
644
+ * parser reads zero for it: consumers must read MigrateOutEvent /
645
+ * MigratedInEvent, never wallet deltas.
646
+ *
647
+ * migrate_in is deliberately NOT exposed. ELE7 only accepts it from a CPI
648
+ * signed by a source pool_authority PDA, so a client-built one can never
649
+ * succeed; offering a builder would only invite the attempt.
650
+ *
651
+ * The caller must ensure the TARGET position exists (create_position on ELE7
652
+ * is permissionless — prepend it when getAccountInfo shows nothing there).
653
+ * The account order below is the IDL's, verified against it field by field;
654
+ * every PDA seed here was confirmed against mainnet by deriving a
655
+ * MigrationConfig that exists on chain.
656
+ *
657
+ * Fails when no MigrationConfig exists for (targetPool, this pool's
658
+ * authority), when the assets differ, when the cap is short, mid-cooldown,
659
+ * in the deposit epoch, or when the target is at capacity — see the gate
660
+ * table in elemental_v3/docs/MIGRATION.md.
661
+ */
662
+ async migrateOutInstructions(
663
+ position: Position,
664
+ targetPool: PublicKey,
665
+ targetProgram: PublicKey = MIGRATION_TARGET_PROGRAM_ID,
666
+ ): Promise<TransactionInstruction[]> {
667
+ const poolAuthority = this.findPoolAuthority(position.pool.address);
668
+ const owner = this.walletAddress;
669
+
670
+ // Both PDAs live on the TARGET program, not this one.
671
+ const [targetConfig] = PublicKey.findProgramAddressSync(
672
+ [Buffer.from("migration"), targetPool.toBuffer(), poolAuthority.toBuffer()],
673
+ targetProgram,
674
+ );
675
+ const [targetPosition] = PublicKey.findProgramAddressSync(
676
+ [Buffer.from("position"), owner.toBuffer(), targetPool.toBuffer()],
677
+ targetProgram,
678
+ );
679
+
680
+ const ix = await (this.program.methods as any)
681
+ .migrateOut()
682
+ .accounts({
683
+ owner,
684
+ position: position.address,
685
+ pool: position.pool.address,
686
+ poolAuthority,
687
+ targetProgram,
688
+ targetConfig,
689
+ targetPool,
690
+ targetPosition,
691
+ })
692
+ .instruction();
693
+
694
+ return [ix];
695
+ }
696
+
608
697
  async claimInstructions(
609
698
  position: Position,
610
699
  ): Promise<TransactionInstruction[]> {
@@ -1 +1,7 @@
1
- export { ElementalV2Context, VAULT_PROGRAM_ID } from "./elemental";
1
+ export {
2
+ ElementalV2Context,
3
+ VAULT_PROGRAM_ID,
4
+ ELE6_PROGRAM_ID,
5
+ ELE7_PROGRAM_ID,
6
+ MIGRATION_TARGET_PROGRAM_ID,
7
+ } from "./elemental";
package/src/types.ts CHANGED
@@ -99,4 +99,6 @@ export const POOL_FAUCET_CONFIG: Record<string, string> = {
99
99
  "2PZPsRYvLb95iHLeDJz5HUpDvtWaDrij8Q5iZTB9XrWW": "EZUYntxRKvCWsoHDKaW1C3XjwJVrJwSLVTkuynQemKEE",
100
100
  // USDC pool #2 (ELE7, 11% APR) - separate faucet for withdrawals (created 2026-05-17)
101
101
  "E1khywt2EpTs4eD7QbaVvBvNjQbiJ83AfayHkfFyBBCX": "9VPdN1zkwv5vi29NAbpr91ej6ac27N2EVW9UFwM62Y5P",
102
+ // USDC RWA pool (ELE7, 14% APR) - separate faucet for withdrawals (created 2026-06-17)
103
+ "997LaZC7HTYcgAPMaxjCqe4kp8qq3QJVgZfSnqCT5KpQ": "FMH99QmevidUCxM74vvxzxeeoQaDDLRXTLHtLpMaDUqF",
102
104
  };