@symmetry-hq/sdk 1.0.19 → 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
  }
@@ -356,14 +356,25 @@ function createEditVaultIntentIx(params) {
356
356
  break;
357
357
  case intent_1.TaskType.UpdateWeights: { // 15 - 202
358
358
  const updateWeightsData = editData;
359
- const weights = updateWeightsData.token_weights.slice(0, constants_1.MAX_SUPPORTED_TOKENS_PER_VAULT);
360
- while (weights.length < constants_1.MAX_SUPPORTED_TOKENS_PER_VAULT)
361
- weights.push({ mint: '', weight_bps: 0 });
359
+ const weights = updateWeightsData.token_weights;
362
360
  let tokenMintsHash = (_e = updateWeightsData.token_mints_hash) !== null && _e !== void 0 ? _e : (0, basket_1.computeTokenMintsHash)(vault.composition.slice(0, vault.numTokens)
363
361
  .filter((asset) => asset.active === 1)
364
362
  .map((asset) => asset.mint.toBase58()));
363
+ let tokenWeights = [];
364
+ for (let i = 0; i < constants_1.MAX_SUPPORTED_TOKENS_PER_VAULT; i++) {
365
+ if (i >= vault.numTokens || vault.composition[i].active === 0) {
366
+ tokenWeights.push(0);
367
+ continue;
368
+ }
369
+ let mint = vault.composition[i].mint.toBase58();
370
+ let weight = 0;
371
+ for (let j = 0; j < weights.length; j++)
372
+ if (weights[j].mint === mint)
373
+ weight = weights[j].weight_bps;
374
+ tokenWeights.push(weight);
375
+ }
365
376
  let updateWeights = {
366
- tokenWeights: weights.map((weight) => weight.weight_bps),
377
+ tokenWeights: tokenWeights,
367
378
  tokenMintsHash: tokenMintsHash,
368
379
  };
369
380
  config_1.UpdateWeightsLayout.encode(updateWeights, editDataBuf);
@@ -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.19",
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
  }
@@ -442,16 +442,27 @@ export function createEditVaultIntentIx(params: {
442
442
 
443
443
  case TaskType.UpdateWeights: { // 15 - 202
444
444
  const updateWeightsData = (editData as UpdateWeightsInput);
445
- const weights = updateWeightsData.token_weights.slice(0, MAX_SUPPORTED_TOKENS_PER_VAULT);
446
- while (weights.length < MAX_SUPPORTED_TOKENS_PER_VAULT) weights.push({ mint: '', weight_bps: 0 });
447
-
445
+ const weights = updateWeightsData.token_weights;
448
446
  let tokenMintsHash = updateWeightsData.token_mints_hash ?? computeTokenMintsHash(
449
447
  vault.composition.slice(0, vault.numTokens)
450
448
  .filter((asset) => asset.active === 1)
451
449
  .map((asset) => asset.mint.toBase58())
452
450
  );
451
+ let tokenWeights = [];
452
+ for (let i = 0; i < MAX_SUPPORTED_TOKENS_PER_VAULT; i++) {
453
+ if (i >= vault.numTokens || vault.composition[i].active === 0) {
454
+ tokenWeights.push(0);
455
+ continue;
456
+ }
457
+ let mint = vault.composition[i].mint.toBase58();
458
+ let weight = 0;
459
+ for (let j = 0; j < weights.length; j++)
460
+ if (weights[j].mint === mint)
461
+ weight = weights[j].weight_bps;
462
+ tokenWeights.push(weight);
463
+ }
453
464
  let updateWeights: UpdateWeights = {
454
- tokenWeights: weights.map((weight) => weight.weight_bps),
465
+ tokenWeights: tokenWeights,
455
466
  tokenMintsHash: tokenMintsHash,
456
467
  }
457
468
  UpdateWeightsLayout.encode(updateWeights, editDataBuf);
@@ -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: "XsoCS1TfEyfFhfvj8EtZ528L3CaKBDBRqRapnBbDF2W",
325
+ token_mint: "CLWeikxiw8pC9JEtZt14fqDzYfXF7uVwLuvnJPkrE7av",
326
326
  active: true,
327
327
  min_oracles_thresh: 1,
328
328
  min_conf_bps: 50,
@@ -330,14 +330,14 @@ async function testStates() {
330
330
  conf_multiplier: 1,
331
331
  oracles: [
332
332
  {
333
- oracle_type: "raydium_clmm",
333
+ oracle_type: "raydium_cpmm",
334
334
  account_lut_id: 0,
335
335
  account_lut_index: 0,
336
- account: "6truu3rZuiB9rKQg4VYC3Dt3QwV7DgwGqXrYUcrvnDDE",
336
+ account: "7QBNJCYb6ktWwFsCR2w9SQ1C7ZKog5eGgiirLetSeh9",
337
337
  weight_bps: 5000,
338
338
  is_required: false,
339
- conf_thresh_bps: 200,
340
- volatility_thresh_bps: 200,
339
+ conf_thresh_bps: 100,
340
+ volatility_thresh_bps: 100,
341
341
  max_slippage_bps: 100,
342
342
  min_liquidity: 0,
343
343
  staleness_thresh: 120,
@@ -348,10 +348,10 @@ async function testStates() {
348
348
  quote_token: "wsol",
349
349
  },
350
350
  {
351
- oracle_type: "raydium_clmm",
351
+ oracle_type: "pyth",
352
352
  account_lut_id: 0,
353
353
  account_lut_index: 0,
354
- account: "4pCZCVEiYyT4efNdXUdL2tJF8VGMgiMXrZWq6FiNXhRw",
354
+ account: "AxaxyeDT8JnWERSaTKvFXvPKkEdxnamKSqpWbsSjYg1g",
355
355
  weight_bps: 5000,
356
356
  is_required: false,
357
357
  conf_thresh_bps: 200,
@@ -363,13 +363,13 @@ async function testStates() {
363
363
  token_decimals: 9,
364
364
  twap_seconds_ago: 50,
365
365
  twap_secondary_seconds_ago: 100,
366
- quote_token: "wsol",
366
+ quote_token: "usd",
367
367
  },
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) {
@@ -377,11 +377,24 @@ async function testStates() {
377
377
  token_weights: [
378
378
  {
379
379
  mint: "So11111111111111111111111111111111111111112",
380
- weight_bps: 100,
380
+ weight_bps: 2000,
381
381
  },
382
- ],
383
- token_mints_hash: [
384
- 0, 0, 0, 0,
382
+ {
383
+ mint: "cbbtcf3aa214zXHbiAZQwf4122FBYbraNdFqgw4iMij",
384
+ weight_bps: 2500,
385
+ },
386
+ {
387
+ mint: "XsoCS1TfEyfFhfvj8EtZ528L3CaKBDBRqRapnBbDF2W",
388
+ weight_bps: 2500,
389
+ },
390
+ {
391
+ mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
392
+ weight_bps: 1000,
393
+ },
394
+ {
395
+ mint: "J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn",
396
+ weight_bps: 2000,
397
+ }
385
398
  ],
386
399
  };
387
400
  let tx = await sdk.updateWeightsTx(task_context, update_weights);