@symmetry-hq/sdk 1.0.20 → 1.0.21

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/dist/index.js CHANGED
@@ -695,6 +695,16 @@ class SymmetryCore {
695
695
  let expirationTimestamp = new bn_js_1.default((_b = params.context.expiration_timestamp) !== null && _b !== void 0 ? _b : 0);
696
696
  let editType = params.type;
697
697
  let editData = params.settings;
698
+ let poolInfos = [];
699
+ if (params.type === intent_1.TaskType.AddToken) {
700
+ let allAccounts = [];
701
+ let addTokenData = editData;
702
+ for (let i = 0; i < addTokenData.oracles.length; i++)
703
+ allAccounts.push(new web3_js_1.PublicKey(addTokenData.oracles[i].account));
704
+ let infos = yield (0, txUtils_1.getMultipleAccountsInfoBatched)(this.sdkParams.connection, allAccounts);
705
+ for (let i = 0; i < allAccounts.length; i++)
706
+ poolInfos[i] = infos.get(allAccounts[i].toBase58());
707
+ }
698
708
  let modificationDelay = (() => {
699
709
  switch (editType) {
700
710
  case intent_1.TaskType.EditCreator: return new bn_js_1.default(0);
@@ -760,6 +770,9 @@ class SymmetryCore {
760
770
  if (oracle.oracle_type == "pyth")
761
771
  continue;
762
772
  if (oracle.oracle_type == "raydium_cpmm") {
773
+ let parsedPool = raydiumCpmmOracle_1.RaydiumCpmmPoolState.decode(poolInfos[i].data, 8);
774
+ additionalOracleAccounts.push(parsedPool.token0Vault);
775
+ additionalOracleAccounts.push(parsedPool.token1Vault);
763
776
  let observationKey = raydiumCpmmOracle_1.RaydiumCPMMOracle.deriveObservationKey(oracleAccount, this.sdkParams.network);
764
777
  additionalOracleAccounts.push(observationKey[0]);
765
778
  }
@@ -92,6 +92,7 @@ export declare class RaydiumCpmmPoolState {
92
92
  static decode(data: Buffer, offset?: number): RaydiumCpmmPoolState;
93
93
  }
94
94
  export declare class RaydiumCPMMOracle {
95
+ static deriveVaultAta(poolId: PublicKey, tokenMint: PublicKey, network: "mainnet" | "devnet"): [PublicKey, number];
95
96
  static deriveObservationKey(poolId: PublicKey, network: "mainnet" | "devnet"): [PublicKey, number];
96
97
  static getObservationAtIndex(observations: Observation[], index: number): Observation;
97
98
  static getObservationAtTimestamp(timestamp: BN, observations: Observation[], startIndex: number): Observation;
@@ -278,6 +278,14 @@ class RaydiumCPMMOracle {
278
278
  // this.vault0 = cpmmParams.vault0;
279
279
  // this.vault1 = cpmmParams.vault1;
280
280
  // }
281
+ static deriveVaultAta(poolId, tokenMint, network) {
282
+ const seeds = [
283
+ Buffer.from("pool_vault"),
284
+ poolId.toBuffer(),
285
+ tokenMint.toBuffer(),
286
+ ];
287
+ return web3_js_1.PublicKey.findProgramAddressSync(seeds, network === "mainnet" ? CPMM_PROGRAM_ID : DEV_CPMM_PROGRAM_ID);
288
+ }
281
289
  static deriveObservationKey(poolId, network) {
282
290
  const seeds = [
283
291
  Buffer.from("observation"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symmetry-hq/sdk",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "Symmetry V3 SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -91,7 +91,7 @@ import {
91
91
  getMultipleAccountsInfoBatched
92
92
  } from './txUtils';
93
93
  import { RaydiumCLMMOracle } from './states/oracles/raydiumClmmOracle';
94
- import { RaydiumCPMMOracle } from './states/oracles/raydiumCpmmOracle';
94
+ import { RaydiumCPMMOracle, RaydiumCpmmPoolState } from './states/oracles/raydiumCpmmOracle';
95
95
 
96
96
  export class SymmetryCore {
97
97
 
@@ -728,6 +728,16 @@ export class SymmetryCore {
728
728
  let expirationTimestamp = new BN(params.context.expiration_timestamp ?? 0);
729
729
  let editType = params.type;
730
730
  let editData = params.settings;
731
+ let poolInfos = [];
732
+ if (params.type === TaskType.AddToken) {
733
+ let allAccounts = [];
734
+ let addTokenData = (editData as AddOrEditTokenInput);
735
+ for (let i = 0; i < addTokenData.oracles.length; i++)
736
+ allAccounts.push(new PublicKey(addTokenData.oracles[i].account));
737
+ let infos = await getMultipleAccountsInfoBatched(this.sdkParams.connection, allAccounts);
738
+ for (let i = 0; i < allAccounts.length; i++)
739
+ poolInfos[i] = infos.get(allAccounts[i].toBase58());
740
+ }
731
741
  let modificationDelay = (() => {
732
742
  switch(editType) {
733
743
  case TaskType.EditCreator: return new BN(0);
@@ -801,6 +811,9 @@ export class SymmetryCore {
801
811
  if (oracle.oracle_type == "example") continue;
802
812
  if (oracle.oracle_type == "pyth") continue;
803
813
  if (oracle.oracle_type == "raydium_cpmm") {
814
+ let parsedPool = RaydiumCpmmPoolState.decode(poolInfos[i]!.data, 8);
815
+ additionalOracleAccounts.push(parsedPool.token0Vault);
816
+ additionalOracleAccounts.push(parsedPool.token1Vault);
804
817
  let observationKey = RaydiumCPMMOracle.deriveObservationKey(oracleAccount, this.sdkParams.network);
805
818
  additionalOracleAccounts.push(observationKey[0]);
806
819
  }
@@ -429,6 +429,15 @@ export class RaydiumCPMMOracle {
429
429
 
430
430
  // }
431
431
 
432
+ static deriveVaultAta(poolId: PublicKey, tokenMint: PublicKey, network: "mainnet" | "devnet"): [PublicKey, number] {
433
+ const seeds = [
434
+ Buffer.from("pool_vault"),
435
+ poolId.toBuffer(),
436
+ tokenMint.toBuffer(),
437
+ ];
438
+ return PublicKey.findProgramAddressSync(seeds, network === "mainnet" ? CPMM_PROGRAM_ID : DEV_CPMM_PROGRAM_ID);
439
+ }
440
+
432
441
  static deriveObservationKey(poolId: PublicKey, network: "mainnet" | "devnet"): [PublicKey, number] {
433
442
  const seeds = [
434
443
  Buffer.from("observation"),
package/test.ts CHANGED
@@ -322,7 +322,7 @@ async function testStates() {
322
322
 
323
323
  if (tests.addOrEditToken) {
324
324
  let add_token: AddOrEditTokenInput = {
325
- token_mint: "J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn",
325
+ token_mint: "CLWeikxiw8pC9JEtZt14fqDzYfXF7uVwLuvnJPkrE7av",
326
326
  active: true,
327
327
  min_oracles_thresh: 1,
328
328
  min_conf_bps: 50,
@@ -330,10 +330,10 @@ async function testStates() {
330
330
  conf_multiplier: 1,
331
331
  oracles: [
332
332
  {
333
- oracle_type: "lst",
333
+ oracle_type: "raydium_cpmm",
334
334
  account_lut_id: 0,
335
335
  account_lut_index: 0,
336
- account: "Jito4APyf642JPZPx3hGc6WWJ8zPKtRbRs4P815Awbb",
336
+ account: "7QBNJCYb6ktWwFsCR2w9SQ1C7ZKog5eGgiirLetSeh9",
337
337
  weight_bps: 5000,
338
338
  is_required: false,
339
339
  conf_thresh_bps: 100,
@@ -368,8 +368,8 @@ async function testStates() {
368
368
  ],
369
369
  };
370
370
  let tx = await sdk.addOrEditTokenTx(task_context, add_token);
371
- let res = await sdk.signAndSendTxPayloadBatchSequence({txPayloadBatchSequence: tx, wallet});
372
- console.log(res);
371
+ // let res = await sdk.signAndSendTxPayloadBatchSequence({txPayloadBatchSequence: tx, wallet});
372
+ // console.log(res);
373
373
  }
374
374
 
375
375
  if (tests.updateWeights) {