@symmetry-hq/sdk 1.0.14 → 1.0.16

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.
Files changed (41) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +121 -31
  3. package/dist/instructions/automation/flashSwap.d.ts +4 -0
  4. package/dist/instructions/automation/flashSwap.js +8 -8
  5. package/dist/instructions/management/claimFees.d.ts +2 -1
  6. package/dist/instructions/management/claimFees.js +5 -3
  7. package/dist/instructions/management/edit.d.ts +1 -0
  8. package/dist/instructions/management/edit.js +17 -0
  9. package/dist/instructions/user/deposit.d.ts +1 -0
  10. package/dist/instructions/user/deposit.js +2 -2
  11. package/dist/instructions/user/withdraw.d.ts +1 -0
  12. package/dist/instructions/user/withdraw.js +4 -4
  13. package/dist/src/instructions/pda.js +2 -2
  14. package/dist/src/keeperRebalaneHandler.d.ts +32 -0
  15. package/dist/src/keeperRebalaneHandler.js +278 -0
  16. package/dist/src/states/basket.js +3 -7
  17. package/dist/src/states/oracles/pythOracle.d.ts +2 -10
  18. package/dist/src/states/oracles/pythOracle.js +2 -43
  19. package/dist/src/txUtils.js +12 -22
  20. package/dist/states/basket.js +1 -1
  21. package/dist/states/oracles/oracle.js +3 -3
  22. package/dist/states/oracles/raydiumClmmOracle.d.ts +11 -11
  23. package/dist/states/oracles/raydiumClmmOracle.js +97 -84
  24. package/dist/states/oracles/raydiumCpmmOracle.d.ts +5 -5
  25. package/dist/states/oracles/raydiumCpmmOracle.js +41 -55
  26. package/package.json +7 -2
  27. package/src/index.ts +139 -34
  28. package/src/instructions/automation/flashSwap.ts +12 -8
  29. package/src/instructions/management/claimFees.ts +6 -2
  30. package/src/instructions/management/edit.ts +21 -1
  31. package/src/instructions/user/deposit.ts +3 -3
  32. package/src/instructions/user/withdraw.ts +7 -4
  33. package/src/states/basket.ts +2 -2
  34. package/src/states/oracles/oracle.ts +4 -3
  35. package/src/states/oracles/raydiumClmmOracle.ts +54 -54
  36. package/src/states/oracles/raydiumCpmmOracle.ts +47 -62
  37. package/test.ts +80 -19
  38. package/dist/src/instructions/automation/rebalanceSwap.d.ts +0 -11
  39. package/dist/src/instructions/automation/rebalanceSwap.js +0 -42
  40. package/dist/src/runtime/crypto.d.ts +0 -1
  41. package/dist/src/runtime/crypto.js +0 -14
package/dist/index.d.ts CHANGED
@@ -391,7 +391,7 @@ export declare class SymmetryCore {
391
391
  keeper: string;
392
392
  intent: string;
393
393
  jup_token_ledger_ix?: TransactionInstruction;
394
- jup_swap_ix: TransactionInstruction;
394
+ jup_swap_ix?: TransactionInstruction;
395
395
  jup_address_lookup_table_addresses?: PublicKey[];
396
396
  }): Promise<TxPayloadBatchSequence>;
397
397
  /**
package/dist/index.js CHANGED
@@ -47,6 +47,8 @@ Object.defineProperty(exports, "isRebalanceRequired", { enumerable: true, get: f
47
47
  const pythOracle_1 = require("./states/oracles/pythOracle");
48
48
  const withdrawBasketFees_1 = require("./states/withdrawBasketFees");
49
49
  const txUtils_1 = require("./txUtils");
50
+ const raydiumClmmOracle_1 = require("./states/oracles/raydiumClmmOracle");
51
+ const raydiumCpmmOracle_1 = require("./states/oracles/raydiumCpmmOracle");
50
52
  class SymmetryCore {
51
53
  /**
52
54
  * Initializes the SymmetryCore SDK.
@@ -747,6 +749,26 @@ class SymmetryCore {
747
749
  }
748
750
  }
749
751
  let intent = (0, pda_1.getIntentPda)(vault.ownAddress, intentSeedArray, editType);
752
+ let additionalOracleAccounts = [];
753
+ if (editType === intent_1.TaskType.AddToken) {
754
+ let addTokenData = editData;
755
+ for (let i = 0; i < addTokenData.oracles.length; i++) {
756
+ let oracle = addTokenData.oracles[i];
757
+ let oracleAccount = new web3_js_1.PublicKey(oracle.account);
758
+ if (oracle.oracle_type == "example")
759
+ continue;
760
+ if (oracle.oracle_type == "pyth")
761
+ continue;
762
+ if (oracle.oracle_type == "raydium_cpmm") {
763
+ let observationKey = raydiumCpmmOracle_1.RaydiumCPMMOracle.deriveObservationKey(oracleAccount, this.sdkParams.network);
764
+ additionalOracleAccounts.push(observationKey[0]);
765
+ }
766
+ if (oracle.oracle_type == "raydium_clmm") {
767
+ let observationKey = raydiumClmmOracle_1.RaydiumCLMMOracle.deriveObservationKey(oracleAccount, this.sdkParams.network);
768
+ additionalOracleAccounts.push(observationKey[0]);
769
+ }
770
+ }
771
+ }
750
772
  let openVaultIntentIx = (0, edit_1.createEditVaultIntentIx)({
751
773
  manager: manager,
752
774
  vault: vault,
@@ -759,6 +781,7 @@ class SymmetryCore {
759
781
  minBounty: minBounty,
760
782
  maxBounty: maxBounty,
761
783
  tokenProgram: tokenProgram,
784
+ additionalOracleAccounts: additionalOracleAccounts,
762
785
  });
763
786
  let txBatchData = { batches: [[{
764
787
  payer: manager,
@@ -768,7 +791,7 @@ class SymmetryCore {
768
791
  web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
769
792
  web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
770
793
  ],
771
- lookupTables: [],
794
+ lookupTables: [vault.lookupTables.active[0]],
772
795
  }]] };
773
796
  // Only execute in the same transaction when there is no delay and no scheduled activation.
774
797
  if (modificationDelay.eq(new bn_js_1.default(0)) && activationTimestamp.eq(new bn_js_1.default(0))) {
@@ -781,32 +804,44 @@ class SymmetryCore {
781
804
  keeper: manager,
782
805
  vaultMint: vault.mint,
783
806
  });
784
- if (editType == intent_1.TaskType.MakeDirectSwap && params.jup_swap_ix) {
807
+ if (editType == intent_1.TaskType.MakeDirectSwap) {
808
+ let mintIn = new web3_js_1.PublicKey(editData.from_token_mint);
809
+ let mintOut = new web3_js_1.PublicKey(editData.to_token_mint);
810
+ let mintInInfo = yield this.sdkParams.connection.getAccountInfo(mintIn);
811
+ let mintOutInfo = yield this.sdkParams.connection.getAccountInfo(mintOut);
812
+ let mintInProgram = mintInInfo.owner;
813
+ let mintOutProgram = mintOutInfo.owner;
785
814
  let flashParams = {
786
815
  keeper: manager,
787
816
  vault: vault.ownAddress,
788
817
  rebalanceIntent: undefined,
789
818
  intent: intent,
790
- mintIn: new web3_js_1.PublicKey(editData.from_token_mint),
791
- mintOut: new web3_js_1.PublicKey(editData.to_token_mint),
819
+ mintIn: mintIn,
820
+ mintOut: mintOut,
792
821
  amountIn: new bn_js_1.default(editData.amount_from),
793
822
  amountOut: new bn_js_1.default(editData.amount_to),
823
+ mintInProgram: mintInProgram,
824
+ mintOutProgram: mintOutProgram,
794
825
  mode: undefined,
795
826
  };
796
827
  let ixWithdraw = (0, flashSwap_1.flashWithdrawIx)(flashParams);
797
828
  let ixDeposit = (0, flashSwap_1.flashDepositIx)(flashParams);
829
+ let managerFromATA = (0, pda_1.getAta)(manager, flashParams.mintIn, mintInProgram);
830
+ let managerToATA = (0, pda_1.getAta)(manager, flashParams.mintOut, mintOutProgram);
831
+ let ixs = [
832
+ (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(manager, managerFromATA, manager, flashParams.mintIn, mintInProgram),
833
+ (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(manager, managerToATA, manager, flashParams.mintOut, mintOutProgram),
834
+ ixWithdraw,
835
+ ];
836
+ if (params.jup_swap_ix)
837
+ ixs.push(params.jup_swap_ix);
838
+ ixs.push(ixDeposit);
839
+ ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }));
840
+ ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }));
798
841
  txBatchData.batches.push([{
799
842
  payer: manager,
800
- instructions: [
801
- (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(manager, (0, pda_1.getAta)(manager, flashParams.mintIn), manager, flashParams.mintIn),
802
- (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(manager, (0, pda_1.getAta)(manager, flashParams.mintOut), manager, flashParams.mintOut),
803
- ixWithdraw,
804
- params.jup_swap_ix,
805
- ixDeposit,
806
- web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
807
- web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
808
- ],
809
- lookupTables: [],
843
+ instructions: ixs, // TODO: use jup lookup tables
844
+ lookupTables: [vault.lookupTables.active[0]],
810
845
  }]);
811
846
  txBatchData.batches.push([{
812
847
  payer: manager,
@@ -815,16 +850,30 @@ class SymmetryCore {
815
850
  web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
816
851
  web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
817
852
  ],
818
- lookupTables: [],
853
+ lookupTables: [vault.lookupTables.active[0]],
819
854
  }]);
820
855
  }
821
856
  else {
822
- txBatchData.batches[0][0].instructions = [
823
- ...wsolIxs,
824
- openVaultIntentIx,
825
- executeVaultIntentIx,
826
- web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
827
- web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
857
+ txBatchData.batches = [
858
+ [{
859
+ payer: manager,
860
+ instructions: [
861
+ ...wsolIxs,
862
+ openVaultIntentIx,
863
+ web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
864
+ web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
865
+ ],
866
+ lookupTables: [vault.lookupTables.active[0]],
867
+ }],
868
+ [{
869
+ payer: manager,
870
+ instructions: [
871
+ executeVaultIntentIx,
872
+ web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
873
+ web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
874
+ ],
875
+ lookupTables: [vault.lookupTables.active[0]],
876
+ }]
828
877
  ];
829
878
  }
830
879
  }
@@ -889,6 +938,12 @@ class SymmetryCore {
889
938
  if (!taskData) {
890
939
  throw new Error('Make direct swap intent is missing decoded task data');
891
940
  }
941
+ let mintIn = new web3_js_1.PublicKey(taskData.from_token_mint);
942
+ let mintOut = new web3_js_1.PublicKey(taskData.to_token_mint);
943
+ let mintInInfo = yield this.sdkParams.connection.getAccountInfo(mintIn);
944
+ let mintOutInfo = yield this.sdkParams.connection.getAccountInfo(mintOut);
945
+ let mintInProgram = mintInInfo.owner;
946
+ let mintOutProgram = mintOutInfo.owner;
892
947
  const flashParams = {
893
948
  keeper,
894
949
  vault: intent.vault,
@@ -899,6 +954,8 @@ class SymmetryCore {
899
954
  amountIn: new bn_js_1.default(taskData.amount_from),
900
955
  amountOut: new bn_js_1.default(taskData.amount_to),
901
956
  mode: undefined,
957
+ mintInProgram: mintInProgram,
958
+ mintOutProgram: mintOutProgram,
902
959
  };
903
960
  const ixWithdraw = (0, flashSwap_1.flashWithdrawIx)(flashParams);
904
961
  const ixDeposit = (0, flashSwap_1.flashDepositIx)(flashParams);
@@ -911,14 +968,19 @@ class SymmetryCore {
911
968
  keeper,
912
969
  vaultMint: undefined,
913
970
  });
971
+ let keeperFromATA = (0, pda_1.getAta)(keeper, flashParams.mintIn, mintInProgram);
972
+ let keeperToATA = (0, pda_1.getAta)(keeper, flashParams.mintOut, mintOutProgram);
914
973
  const flashInstructions = [
915
- (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(keeper, (0, pda_1.getAta)(keeper, flashParams.mintIn), keeper, flashParams.mintIn),
916
- (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(keeper, (0, pda_1.getAta)(keeper, flashParams.mintOut), keeper, flashParams.mintOut),
974
+ (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(keeper, keeperFromATA, keeper, mintIn, mintInProgram),
975
+ (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(keeper, keeperToATA, keeper, mintOut, mintOutProgram),
917
976
  ];
918
977
  if (params.jup_token_ledger_ix) {
919
978
  flashInstructions.push(params.jup_token_ledger_ix);
920
979
  }
921
- flashInstructions.push(ixWithdraw, params.jup_swap_ix, ixDeposit, web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }), web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }));
980
+ flashInstructions.push(ixWithdraw);
981
+ if (params.jup_swap_ix)
982
+ flashInstructions.push(params.jup_swap_ix);
983
+ flashInstructions.push(ixDeposit, web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }), web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }));
922
984
  const txBatchData = { batches: [
923
985
  [{
924
986
  payer: keeper,
@@ -1071,6 +1133,8 @@ class SymmetryCore {
1071
1133
  // vault: vault.ownAddress,
1072
1134
  // })
1073
1135
  // ];
1136
+ let tokenMintInfos = yield (0, txUtils_1.getMultipleAccountsInfoBatched)(this.sdkParams.connection, contributions.map(contribution => contribution.mint));
1137
+ let tokenPrograms = contributions.map(contribution => tokenMintInfos.get(contribution.mint.toBase58()).owner);
1074
1138
  let txBatchData = { batches: [
1075
1139
  [{
1076
1140
  payer: buyer,
@@ -1105,7 +1169,11 @@ class SymmetryCore {
1105
1169
  (0, deposit_1.depositTokensIx)({
1106
1170
  owner: buyer,
1107
1171
  vault: vault.ownAddress,
1108
- contributions: contributions,
1172
+ contributions: contributions.map((contribution, index) => ({
1173
+ mint: contribution.mint,
1174
+ amount: contribution.amount,
1175
+ tokenProgram: tokenPrograms[index],
1176
+ })),
1109
1177
  }).map(ix => {
1110
1178
  return {
1111
1179
  payer: buyer,
@@ -1181,10 +1249,16 @@ class SymmetryCore {
1181
1249
  lookupTables: [],
1182
1250
  }]);
1183
1251
  }
1252
+ let tokenMintInfos = yield (0, txUtils_1.getMultipleAccountsInfoBatched)(this.sdkParams.connection, contributions.map(contribution => contribution.mint));
1253
+ let tokenPrograms = contributions.map(contribution => tokenMintInfos.get(contribution.mint.toBase58()).owner);
1184
1254
  txBatchData.batches.push((0, deposit_1.depositTokensIx)({
1185
1255
  owner: buyer,
1186
1256
  vault: rebalanceIntentState.vault,
1187
- contributions: contributions,
1257
+ contributions: contributions.map((contribution, index) => ({
1258
+ mint: contribution.mint,
1259
+ amount: contribution.amount,
1260
+ tokenProgram: tokenPrograms[index],
1261
+ })),
1188
1262
  }).map(ix => ({
1189
1263
  payer: buyer,
1190
1264
  instructions: [
@@ -1710,6 +1784,10 @@ class SymmetryCore {
1710
1784
  let amountIn = new bn_js_1.default(params.amount_in);
1711
1785
  let amountOut = new bn_js_1.default(params.amount_out);
1712
1786
  let mode = params.mode ? params.mode : 0;
1787
+ let mintInInfo = yield this.sdkParams.connection.getAccountInfo(mintIn);
1788
+ let mintOutInfo = yield this.sdkParams.connection.getAccountInfo(mintOut);
1789
+ let mintInProgram = mintInInfo.owner;
1790
+ let mintOutProgram = mintOutInfo.owner;
1713
1791
  let flashParams = {
1714
1792
  keeper: keeper,
1715
1793
  vault: vault,
@@ -1720,13 +1798,17 @@ class SymmetryCore {
1720
1798
  amountIn: amountIn,
1721
1799
  amountOut: amountOut,
1722
1800
  mode: mode,
1801
+ mintInProgram: mintInProgram,
1802
+ mintOutProgram: mintOutProgram,
1723
1803
  };
1724
1804
  let ixWithdraw = (0, flashSwap_1.flashWithdrawIx)(flashParams);
1725
1805
  let ixDeposit = (0, flashSwap_1.flashDepositIx)(flashParams);
1726
1806
  let ixs = [];
1807
+ let keeperFromATA = (0, pda_1.getAta)(keeper, mintIn, mintInProgram);
1808
+ let keeperToATA = (0, pda_1.getAta)(keeper, mintOut, mintOutProgram);
1727
1809
  ixs = ixs.concat([
1728
- (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(keeper, (0, pda_1.getAta)(keeper, mintIn), keeper, mintIn),
1729
- (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(keeper, (0, pda_1.getAta)(keeper, mintOut), keeper, mintOut),
1810
+ (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(keeper, keeperFromATA, keeper, mintIn, mintInProgram),
1811
+ (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(keeper, keeperToATA, keeper, mintOut, mintOutProgram),
1730
1812
  ]);
1731
1813
  if (params.jup_token_ledger_ix) {
1732
1814
  ixs.push(params.jup_token_ledger_ix);
@@ -1765,7 +1847,7 @@ class SymmetryCore {
1765
1847
  let keeper = new web3_js_1.PublicKey(params.keeper);
1766
1848
  let rebalanceIntent = (yield this.fetchRebalanceIntent(params.rebalance_intent)).chain_data;
1767
1849
  let vault = yield this.fetchVault(rebalanceIntent.vault.toBase58());
1768
- let vaultRebalanceIntent = (0, pda_1.getRebalanceIntentPda)(vault.ownAddress, rebalanceIntent.owner);
1850
+ let vaultRebalanceIntent = (0, pda_1.getRebalanceIntentPda)(vault.ownAddress, vault.ownAddress);
1769
1851
  let ix = (0, deposit_1.mintVaultIx)({
1770
1852
  keeper: keeper,
1771
1853
  vault: vault.ownAddress,
@@ -1834,14 +1916,18 @@ class SymmetryCore {
1834
1916
  }
1835
1917
  let batchSize = 7;
1836
1918
  let ixs = [];
1919
+ let tokenMintInfos = yield (0, txUtils_1.getMultipleAccountsInfoBatched)(this.sdkParams.connection, redeemableTokenMints);
1920
+ let allTokenPrograms = redeemableTokenMints.map(mint => tokenMintInfos.get(mint.toBase58()).owner);
1837
1921
  for (let batchStart = 0; batchStart < redeemableTokenMints.length; batchStart += batchSize) {
1838
1922
  let tokenMints = redeemableTokenMints.slice(batchStart, batchStart + batchSize);
1923
+ let tokenPrograms = allTokenPrograms.slice(batchStart, batchStart + batchSize);
1839
1924
  if (tokenMints.length > 0) {
1840
1925
  ixs.push((0, withdraw_1.redeemTokensIx)({
1841
1926
  keeper: keeper,
1842
1927
  vault: rebalanceIntent.vault,
1843
1928
  owner: rebalanceIntent.owner,
1844
1929
  tokenMints: tokenMints,
1930
+ tokenPrograms: tokenPrograms,
1845
1931
  }));
1846
1932
  }
1847
1933
  }
@@ -2015,13 +2101,15 @@ class SymmetryCore {
2015
2101
  }
2016
2102
  let withdrawFeesIxs = [];
2017
2103
  let claimTokenFeesFromVaultIxs = [];
2104
+ let tokenMintInfos = yield (0, txUtils_1.getMultipleAccountsInfoBatched)(this.sdkParams.connection, vault.composition.map(composition => composition.mint));
2105
+ let tokenPrograms = vault.composition.map(composition => tokenMintInfos.get(composition.mint.toBase58()).owner);
2018
2106
  claimableFeeTypes.forEach((feeType, index) => {
2019
2107
  withdrawFeesIxs.push((0, claimFees_1.withdrawFeesIx)({
2020
2108
  claimer,
2021
2109
  vaultTokenMint: vault.mint,
2022
2110
  feeType: feeType,
2023
2111
  }));
2024
- claimTokenFeesFromVaultIxs.push(...(0, claimFees_1.claimFeeTokensFromVaultIxs)(claimer, vault.ownAddress, (0, pda_1.getWithdrawVaultFeesPda)(vault.ownAddress, feeType), claimer, owners[index], vault.composition.map(composition => composition.mint)));
2112
+ claimTokenFeesFromVaultIxs.push(...(0, claimFees_1.claimFeeTokensFromVaultIxs)(claimer, vault.ownAddress, (0, pda_1.getWithdrawVaultFeesPda)(vault.ownAddress, feeType), claimer, owners[index], vault.composition.map(composition => composition.mint), tokenPrograms));
2025
2113
  });
2026
2114
  let txBatchData = { batches: [
2027
2115
  withdrawFeesIxs.map(ix => ({
@@ -2066,7 +2154,9 @@ class SymmetryCore {
2066
2154
  return __awaiter(this, void 0, void 0, function* () {
2067
2155
  let claimer = new web3_js_1.PublicKey(params.claimer);
2068
2156
  let withdrawVaultFees = yield this.fetchWithdrawVaultFees(params.withdrawVaultFees);
2069
- let claimTokenFeesFromVaultIxs = (0, claimFees_1.claimFeeTokensFromVaultIxs)(claimer, withdrawVaultFees.vault, withdrawVaultFees.ownAddress, withdrawVaultFees.rentPayer, withdrawVaultFees.owners, withdrawVaultFees.accumulatedTokens);
2157
+ let tokenMintInfos = yield (0, txUtils_1.getMultipleAccountsInfoBatched)(this.sdkParams.connection, withdrawVaultFees.accumulatedTokens);
2158
+ let tokenPrograms = withdrawVaultFees.accumulatedTokens.map(token => tokenMintInfos.get(token.toBase58()).owner);
2159
+ let claimTokenFeesFromVaultIxs = (0, claimFees_1.claimFeeTokensFromVaultIxs)(claimer, withdrawVaultFees.vault, withdrawVaultFees.ownAddress, withdrawVaultFees.rentPayer, withdrawVaultFees.owners, withdrawVaultFees.accumulatedTokens, tokenPrograms);
2070
2160
  // Create batches: all claim instructions can run in parallel
2071
2161
  let txBatchData = { batches: [
2072
2162
  claimTokenFeesFromVaultIxs.map(ix => ({
@@ -9,6 +9,8 @@ export declare function flashWithdrawIx(params: {
9
9
  mintOut: PublicKey;
10
10
  amountIn: BN;
11
11
  amountOut: BN;
12
+ mintInProgram: PublicKey;
13
+ mintOutProgram: PublicKey;
12
14
  mode?: number;
13
15
  }): TransactionInstruction;
14
16
  export declare function flashDepositIx(params: {
@@ -18,4 +20,6 @@ export declare function flashDepositIx(params: {
18
20
  intent?: PublicKey;
19
21
  mintIn: PublicKey;
20
22
  mintOut: PublicKey;
23
+ mintInProgram: PublicKey;
24
+ mintOutProgram: PublicKey;
21
25
  }): TransactionInstruction;
@@ -11,10 +11,10 @@ const FLASH_DEPOSIT_DISCRIMINATOR = Buffer.from([21, 4, 89, 84, 131, 84, 128, 21
11
11
  function flashWithdrawIx(params) {
12
12
  var _a, _b;
13
13
  const { keeper, vault, mintIn, mintOut, amountIn, amountOut, mode } = params;
14
- let keeperFromATA = (0, pda_1.getAta)(keeper, mintIn);
15
- let keeperToATA = (0, pda_1.getAta)(keeper, mintOut);
16
- let vaultInATA = (0, pda_1.getAta)(vault, mintIn);
17
- let vaultOutATA = (0, pda_1.getAta)(vault, mintOut);
14
+ let keeperFromATA = (0, pda_1.getAta)(keeper, mintIn, params.mintInProgram);
15
+ let keeperToATA = (0, pda_1.getAta)(keeper, mintOut, params.mintOutProgram);
16
+ let vaultInATA = (0, pda_1.getAta)(vault, mintIn, params.mintInProgram);
17
+ let vaultOutATA = (0, pda_1.getAta)(vault, mintOut, params.mintOutProgram);
18
18
  const keys = [
19
19
  { pubkey: params.keeper, isWritable: true, isSigner: true },
20
20
  { pubkey: params.vault, isWritable: true, isSigner: false },
@@ -44,10 +44,10 @@ function flashWithdrawIx(params) {
44
44
  }
45
45
  function flashDepositIx(params) {
46
46
  const { keeper, vault, mintIn, mintOut } = params;
47
- let keeperFromATA = (0, pda_1.getAta)(keeper, mintIn);
48
- let keeperToATA = (0, pda_1.getAta)(keeper, mintOut);
49
- let vaultInATA = (0, pda_1.getAta)(vault, mintIn);
50
- let vaultOutATA = (0, pda_1.getAta)(vault, mintOut);
47
+ let keeperFromATA = (0, pda_1.getAta)(keeper, mintIn, params.mintInProgram);
48
+ let keeperToATA = (0, pda_1.getAta)(keeper, mintOut, params.mintOutProgram);
49
+ let vaultInATA = (0, pda_1.getAta)(vault, mintIn, params.mintInProgram);
50
+ let vaultOutATA = (0, pda_1.getAta)(vault, mintOut, params.mintOutProgram);
51
51
  const keys = [
52
52
  { pubkey: params.keeper, isWritable: true, isSigner: true },
53
53
  { pubkey: params.vault, isWritable: true, isSigner: false },
@@ -11,5 +11,6 @@ export declare function claimFeeTokensFromVaultIx(params: {
11
11
  rentPayer: PublicKey;
12
12
  owners: PublicKey[];
13
13
  tokenMints: PublicKey[];
14
+ tokenPrograms: PublicKey[];
14
15
  }): TransactionInstruction;
15
- export declare function claimFeeTokensFromVaultIxs(signer: PublicKey, vault: PublicKey, withdrawVaultFees: PublicKey, rentPayer: PublicKey, owners: PublicKey[], tokenMints: PublicKey[]): TransactionInstruction[];
16
+ export declare function claimFeeTokensFromVaultIxs(signer: PublicKey, vault: PublicKey, withdrawVaultFees: PublicKey, rentPayer: PublicKey, owners: PublicKey[], tokenMints: PublicKey[], tokenPrograms: PublicKey[]): TransactionInstruction[];
@@ -56,8 +56,8 @@ function claimFeeTokensFromVaultIx(params) {
56
56
  // Remaining accounts: for each token: (mint, vaultAta, claimer1Ata, claimer2Ata, ...)
57
57
  for (let i = 0; i < tokenMints.length; i++) {
58
58
  const mint = tokenMints[i];
59
- const vaultAta = (0, pda_1.getAta)(vault, mint);
60
- const claimerATAs = owners.map(owner => (0, pda_1.getAta)(owner, mint));
59
+ const vaultAta = (0, pda_1.getAta)(vault, mint, params.tokenPrograms[i]);
60
+ const claimerATAs = owners.map(owner => (0, pda_1.getAta)(owner, mint, params.tokenPrograms[i]));
61
61
  keys.push({ pubkey: mint, isWritable: false, isSigner: false });
62
62
  keys.push({ pubkey: vaultAta, isWritable: true, isSigner: false });
63
63
  for (let j = 0; j < numOwners; j++) {
@@ -70,7 +70,7 @@ function claimFeeTokensFromVaultIx(params) {
70
70
  data,
71
71
  });
72
72
  }
73
- function claimFeeTokensFromVaultIxs(signer, vault, withdrawVaultFees, rentPayer, owners, tokenMints) {
73
+ function claimFeeTokensFromVaultIxs(signer, vault, withdrawVaultFees, rentPayer, owners, tokenMints, tokenPrograms) {
74
74
  if (owners.length === 0 || tokenMints.length === 0)
75
75
  return [];
76
76
  // Account limit: 8 fixed accounts + (owners + 2) * number_of_mints <= 30
@@ -82,6 +82,7 @@ function claimFeeTokensFromVaultIxs(signer, vault, withdrawVaultFees, rentPayer,
82
82
  let ixs = [];
83
83
  for (let i = 0; i < tokenMints.length; i += maxTokensPerTx) {
84
84
  const batchTokenMints = tokenMints.slice(i, i + maxTokensPerTx);
85
+ const batchTokenPrograms = tokenPrograms.slice(i, i + maxTokensPerTx);
85
86
  ixs.push(claimFeeTokensFromVaultIx({
86
87
  signer: signer,
87
88
  vault: vault,
@@ -89,6 +90,7 @@ function claimFeeTokensFromVaultIxs(signer, vault, withdrawVaultFees, rentPayer,
89
90
  rentPayer: rentPayer,
90
91
  owners: owners,
91
92
  tokenMints: batchTokenMints,
93
+ tokenPrograms: batchTokenPrograms,
92
94
  }));
93
95
  }
94
96
  return ixs;
@@ -31,6 +31,7 @@ export declare function createEditVaultIntentIx(params: {
31
31
  minBounty: BN;
32
32
  maxBounty: BN;
33
33
  tokenProgram?: PublicKey;
34
+ additionalOracleAccounts?: PublicKey[];
34
35
  }): TransactionInstruction;
35
36
  export declare function executeEditVaultIntentIx(params: {
36
37
  keeper: PublicKey;
@@ -324,6 +324,16 @@ function createEditVaultIntentIx(params) {
324
324
  isWritable: true,
325
325
  isSigner: false
326
326
  });
327
+ additionalAccounts.push({
328
+ pubkey: constants_1.PYTHNET_CUSTODY_PRICE_WSOL_ACCOUNT,
329
+ isWritable: true,
330
+ isSigner: false
331
+ });
332
+ additionalAccounts.push({
333
+ pubkey: constants_1.PYTHNET_CUSTODY_PRICE_USDC_ACCOUNT,
334
+ isWritable: true,
335
+ isSigner: false
336
+ });
327
337
  for (let i = 0; i < addTokenData.oracles.length; i++) {
328
338
  additionalAccounts.push({
329
339
  pubkey: new web3_js_1.PublicKey(addTokenData.oracles[i].account),
@@ -331,6 +341,13 @@ function createEditVaultIntentIx(params) {
331
341
  isSigner: false
332
342
  });
333
343
  }
344
+ if (params.additionalOracleAccounts)
345
+ for (let i = 0; i < params.additionalOracleAccounts.length; i++)
346
+ additionalAccounts.push({
347
+ pubkey: params.additionalOracleAccounts[i],
348
+ isWritable: true,
349
+ isSigner: false
350
+ });
334
351
  additionalAccounts.push({
335
352
  pubkey: constants_1.ADDRESS_LOOKUP_TABLE_PROGRAM_ID,
336
353
  isWritable: false,
@@ -5,6 +5,7 @@ export declare function depositTokensIx(params: {
5
5
  contributions: {
6
6
  mint: PublicKey;
7
7
  amount: number;
8
+ tokenProgram: PublicKey;
8
9
  }[];
9
10
  }): TransactionInstruction[];
10
11
  export declare function lockDepositsIx(params: {
@@ -39,8 +39,8 @@ function depositTokensIx(params) {
39
39
  // remaining accounts
40
40
  batch_contributions.forEach((contribution) => {
41
41
  let mint = contribution.mint;
42
- let ownerAta = (0, pda_1.getAta)(owner, mint);
43
- let vaultAta = (0, pda_1.getAta)(vault, mint);
42
+ let ownerAta = (0, pda_1.getAta)(owner, mint, contribution.tokenProgram);
43
+ let vaultAta = (0, pda_1.getAta)(vault, mint, contribution.tokenProgram);
44
44
  keys.push({ pubkey: mint, isSigner: false, isWritable: false });
45
45
  keys.push({ pubkey: ownerAta, isSigner: false, isWritable: true });
46
46
  keys.push({ pubkey: vaultAta, isSigner: false, isWritable: true });
@@ -5,4 +5,5 @@ export declare function redeemTokensIx(params: {
5
5
  vault: PublicKey;
6
6
  owner: PublicKey;
7
7
  tokenMints: PublicKey[];
8
+ tokenPrograms: PublicKey[];
8
9
  }): TransactionInstruction;
@@ -8,7 +8,7 @@ const web3_js_1 = require("@solana/web3.js");
8
8
  const web3_js_2 = require("@solana/web3.js");
9
9
  const REDEEM_TOKENS_DISCRIMINATOR = Buffer.from([83, 49, 112, 2, 105, 193, 106, 126]);
10
10
  function redeemTokensIx(params) {
11
- const { keeper, vault, owner, } = params;
11
+ const { keeper, vault, owner, tokenMints, tokenPrograms, } = params;
12
12
  let rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(vault, owner);
13
13
  const keys = [
14
14
  { pubkey: keeper, isSigner: true, isWritable: true },
@@ -21,10 +21,10 @@ function redeemTokensIx(params) {
21
21
  { pubkey: web3_js_2.SystemProgram.programId, isSigner: false, isWritable: false },
22
22
  ];
23
23
  // remaining accounts
24
- params.tokenMints.forEach((mint) => {
24
+ tokenMints.forEach((mint, index) => {
25
25
  keys.push({ pubkey: mint, isWritable: false, isSigner: false });
26
- keys.push({ pubkey: (0, pda_1.getAta)(owner, mint), isWritable: true, isSigner: false });
27
- keys.push({ pubkey: (0, pda_1.getAta)(vault, mint), isWritable: true, isSigner: false });
26
+ keys.push({ pubkey: (0, pda_1.getAta)(owner, mint, tokenPrograms[index]), isWritable: true, isSigner: false });
27
+ keys.push({ pubkey: (0, pda_1.getAta)(vault, mint, tokenPrograms[index]), isWritable: true, isSigner: false });
28
28
  });
29
29
  const discriminator = REDEEM_TOKENS_DISCRIMINATOR;
30
30
  const data = discriminator;
@@ -19,11 +19,11 @@ exports.getMetadataAccount = getMetadataAccount;
19
19
  exports.getLookupTableAccount = getLookupTableAccount;
20
20
  exports.getLookupTableInfoAccount = getLookupTableInfoAccount;
21
21
  exports.getAta = getAta;
22
+ const crypto_1 = require("crypto");
22
23
  const bn_js_1 = __importDefault(require("bn.js"));
23
24
  const spl_token_1 = require("@solana/spl-token");
24
25
  const web3_js_1 = require("@solana/web3.js");
25
26
  const constants_1 = require("../constants");
26
- const crypto_1 = require("../runtime/crypto");
27
27
  exports.GLOBAL_CONFIG_SEED = Buffer.from("global_config");
28
28
  exports.VAULT_FEES_SEED = Buffer.from("basket_fees");
29
29
  exports.WITHDRAW_VAULT_FEES_SEED = Buffer.from("withdraw_basket_fees");
@@ -47,7 +47,7 @@ function serializeString(input) {
47
47
  return out;
48
48
  }
49
49
  function getRandomSeed() {
50
- return Array.from((0, crypto_1.getSecureRandomBytes)(16));
50
+ return Array.from((0, crypto_1.randomBytes)(16));
51
51
  }
52
52
  function getVaultTokenMintPda(vaultId) {
53
53
  return web3_js_1.PublicKey.findProgramAddressSync([
@@ -0,0 +1,32 @@
1
+ import { Connection, PublicKey } from "@solana/web3.js";
2
+ import { Wallet } from "./txUtils";
3
+ import { Basket, UIRebalanceIntent } from ".";
4
+ export declare class RebalanceHandler {
5
+ private params;
6
+ private intent;
7
+ private basket;
8
+ constructor(params: {
9
+ intent: UIRebalanceIntent;
10
+ basket: Basket;
11
+ wallet: Wallet;
12
+ connection: Connection;
13
+ network: "devnet" | "mainnet";
14
+ jupiterApiKey: string;
15
+ maxAllowedAccounts: number;
16
+ priorityFee?: number;
17
+ simulateTransactions?: boolean;
18
+ });
19
+ delay: (ms: number) => Promise<unknown>;
20
+ refresh(): Promise<void>;
21
+ static run(params: {
22
+ intentPubkey: PublicKey;
23
+ wallet: Wallet;
24
+ connection: Connection;
25
+ network: "devnet" | "mainnet";
26
+ jupiterApiKey: string;
27
+ maxAllowedAccounts: number;
28
+ priorityFee?: number;
29
+ simulateTransactions?: boolean;
30
+ }): Promise<void>;
31
+ private execute;
32
+ }