@symmetry-hq/temp-v3-sdk 0.0.3 → 0.0.4

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 (43) hide show
  1. package/dist/src/index.d.ts +2 -1
  2. package/dist/src/index.js +3 -3
  3. package/dist/src/instructions/management/createBasket.js +2 -2
  4. package/dist/src/layouts/basket.d.ts +11 -5
  5. package/dist/src/layouts/basket.js +2 -2
  6. package/dist/src/layouts/config.d.ts +0 -1
  7. package/dist/src/layouts/config.js +3 -6
  8. package/dist/src/layouts/fraction.d.ts +2 -2
  9. package/dist/src/layouts/fraction.js +2 -2
  10. package/dist/src/layouts/intents/bounty.d.ts +2 -2
  11. package/dist/src/layouts/intents/bounty.js +2 -2
  12. package/dist/src/layouts/intents/intent.d.ts +2 -9
  13. package/dist/src/layouts/intents/intent.js +0 -1
  14. package/dist/src/layouts/intents/rebalanceIntent.d.ts +3 -2
  15. package/dist/src/layouts/oracle.d.ts +18 -4
  16. package/dist/src/layouts/oracle.js +21 -1
  17. package/dist/src/states/basket.d.ts +2 -2
  18. package/dist/src/states/basket.js +9 -2
  19. package/dist/src/states/intents/intent.d.ts +2 -7
  20. package/dist/src/states/intents/intent.js +12 -16
  21. package/dist/src/states/intents/rebalanceIntent.d.ts +1 -0
  22. package/dist/src/states/intents/rebalanceIntent.js +14 -2
  23. package/dist/src/states/oracles/oracle.d.ts +3 -3
  24. package/dist/src/states/oracles/oracle.js +11 -5
  25. package/dist/src/states/oracles/raydiumCpmmOracle.d.ts +4 -2
  26. package/dist/src/states/oracles/raydiumCpmmOracle.js +10 -3
  27. package/dist/test.js +16 -3
  28. package/package.json +1 -1
  29. package/src/index.ts +11 -1
  30. package/src/instructions/management/createBasket.ts +2 -2
  31. package/src/layouts/basket.ts +13 -5
  32. package/src/layouts/config.ts +2 -6
  33. package/src/layouts/fraction.ts +4 -4
  34. package/src/layouts/intents/bounty.ts +4 -4
  35. package/src/layouts/intents/intent.ts +2 -10
  36. package/src/layouts/intents/rebalanceIntent.ts +4 -3
  37. package/src/layouts/oracle.ts +22 -5
  38. package/src/states/basket.ts +14 -5
  39. package/src/states/intents/intent.ts +12 -20
  40. package/src/states/intents/rebalanceIntent.ts +15 -3
  41. package/src/states/oracles/oracle.ts +13 -9
  42. package/src/states/oracles/raydiumCpmmOracle.ts +11 -2
  43. package/test.ts +19 -6
@@ -12,7 +12,7 @@ export declare const COMPUTE_UNITS = 1000000;
12
12
  export declare const PRIORITY_FEE = 100000;
13
13
  export declare const JUPITER_API_KEY = "https://quote-api.jup.ag/v6/";
14
14
  export declare const MAX_JUPITER_ACCOUNTS = 35;
15
- export declare class BasketsSdk {
15
+ export declare class SymmetryCore {
16
16
  private sdkParams;
17
17
  constructor(params: {
18
18
  connection: Connection;
@@ -54,3 +54,4 @@ export declare class BasketsSdk {
54
54
  wallet: Wallet;
55
55
  }): Promise<TransactionSignature[]>;
56
56
  }
57
+ export { Basket, BasketFilter, Intent, IntentFilter, RebalanceIntent, RebalanceIntentFilter };
package/dist/src/index.js CHANGED
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.BasketsSdk = exports.MAX_JUPITER_ACCOUNTS = exports.JUPITER_API_KEY = exports.PRIORITY_FEE = exports.COMPUTE_UNITS = void 0;
12
+ exports.SymmetryCore = exports.MAX_JUPITER_ACCOUNTS = exports.JUPITER_API_KEY = exports.PRIORITY_FEE = exports.COMPUTE_UNITS = void 0;
13
13
  const anchor_1 = require("@coral-xyz/anchor");
14
14
  const web3_js_1 = require("@solana/web3.js");
15
15
  const constants_1 = require("./constants");
@@ -24,7 +24,7 @@ exports.COMPUTE_UNITS = 1000000;
24
24
  exports.PRIORITY_FEE = 100000;
25
25
  exports.JUPITER_API_KEY = "https://quote-api.jup.ag/v6/";
26
26
  exports.MAX_JUPITER_ACCOUNTS = 35;
27
- class BasketsSdk {
27
+ class SymmetryCore {
28
28
  constructor(params) {
29
29
  var _a, _b, _c, _d;
30
30
  this.sdkParams = {
@@ -196,4 +196,4 @@ class BasketsSdk {
196
196
  });
197
197
  }
198
198
  }
199
- exports.BasketsSdk = BasketsSdk;
199
+ exports.SymmetryCore = SymmetryCore;
@@ -63,8 +63,8 @@ function createBasketIx(params) {
63
63
  Buffer.from(seed),
64
64
  Buffer.from(new anchor_1.BN(slot).toArray("le", 8)),
65
65
  host.toBuffer(),
66
- Buffer.from(startPrice.numerator.toArray("le", 8)),
67
- Buffer.from(startPrice.exponent.toArray("le", 8)),
66
+ Buffer.from(startPrice.high.toArray("le", 8)),
67
+ Buffer.from(startPrice.low.toArray("le", 8)),
68
68
  hostFeesBuffer,
69
69
  (0, pda_1.serializeString)(metadataParams.name),
70
70
  (0, pda_1.serializeString)(metadataParams.symbol),
@@ -1,8 +1,8 @@
1
- import { BN } from "@coral-xyz/anchor";
2
- import { PublicKey } from "@solana/web3.js";
3
- import { OracleAggregator } from "./oracle";
4
- import { Fraction } from "./fraction";
5
- import { BasketSettings } from "./config";
1
+ import { BN } from '@coral-xyz/anchor';
2
+ import { PublicKey } from '@solana/web3.js';
3
+ import { BasketSettings } from './config';
4
+ import { Fraction } from './fraction';
5
+ import { OracleAggregator } from './oracle';
6
6
  export declare const MAX_SUPPORTED_TOKENS_PER_BASKET: number;
7
7
  export interface BasketFees {
8
8
  symmetryFees: BN;
@@ -23,6 +23,11 @@ export interface Asset {
23
23
  oracleAggregator: OracleAggregator;
24
24
  }
25
25
  export declare const AssetLayout: any;
26
+ export interface Metadata {
27
+ symbol: string;
28
+ name: string;
29
+ uri: string;
30
+ }
26
31
  export interface Basket {
27
32
  version: number;
28
33
  seedArray: number[];
@@ -37,5 +42,6 @@ export interface Basket {
37
42
  writeVersion: BN;
38
43
  numTokens: number;
39
44
  composition: Asset[];
45
+ metadata?: Metadata;
40
46
  }
41
47
  export declare const BasketLayout: any;
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BasketLayout = exports.AssetLayout = exports.LookupTablesLayout = exports.BasketFeesLayout = exports.MAX_SUPPORTED_TOKENS_PER_BASKET = void 0;
4
4
  const borsh_1 = require("@coral-xyz/borsh");
5
- const oracle_1 = require("./oracle");
6
- const fraction_1 = require("./fraction");
7
5
  const config_1 = require("./config");
6
+ const fraction_1 = require("./fraction");
7
+ const oracle_1 = require("./oracle");
8
8
  exports.MAX_SUPPORTED_TOKENS_PER_BASKET = 100;
9
9
  ;
10
10
  exports.BasketFeesLayout = (0, borsh_1.struct)([
@@ -10,7 +10,6 @@ export declare enum BasketType {
10
10
  Private = 0,
11
11
  Public = 1
12
12
  }
13
- export declare const BasketTypeLayout: any;
14
13
  export interface ScheduleSettings {
15
14
  cycleDuration: BN;
16
15
  depositsStart: BN;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GlobalConfigLayout = exports.BasketSettingsLayout = exports.MetadataSettingsLayout = exports.LpSettingsLayout = exports.AutomationSettingsLayout = exports.ManagerSettingsLayout = exports.FeeSettingsLayout = exports.ScheduleSettingsLayout = exports.BasketTypeLayout = exports.BasketType = exports.MAX_URI_LENGTH = exports.MAX_NAME_LENGTH = exports.MAX_SYMBOL_LENGTH = exports.MAX_MANAGERS_PER_BASKET = void 0;
3
+ exports.GlobalConfigLayout = exports.BasketSettingsLayout = exports.MetadataSettingsLayout = exports.LpSettingsLayout = exports.AutomationSettingsLayout = exports.ManagerSettingsLayout = exports.FeeSettingsLayout = exports.ScheduleSettingsLayout = exports.BasketType = exports.MAX_URI_LENGTH = exports.MAX_NAME_LENGTH = exports.MAX_SYMBOL_LENGTH = exports.MAX_MANAGERS_PER_BASKET = void 0;
4
4
  const borsh_1 = require("@coral-xyz/borsh");
5
5
  const fraction_1 = require("./fraction");
6
6
  const bounty_1 = require("./intents/bounty");
@@ -14,9 +14,6 @@ var BasketType;
14
14
  BasketType[BasketType["Public"] = 1] = "Public";
15
15
  })(BasketType || (exports.BasketType = BasketType = {}));
16
16
  ;
17
- exports.BasketTypeLayout = (0, borsh_1.struct)([
18
- (0, borsh_1.u8)('basketType'),
19
- ]);
20
17
  ;
21
18
  exports.ScheduleSettingsLayout = (0, borsh_1.struct)([
22
19
  (0, borsh_1.u64)('cycleDuration'),
@@ -30,6 +27,7 @@ exports.ScheduleSettingsLayout = (0, borsh_1.struct)([
30
27
  ]);
31
28
  ;
32
29
  exports.FeeSettingsLayout = (0, borsh_1.struct)([
30
+ (0, borsh_1.u64)('modificationDelay'),
33
31
  (0, borsh_1.u16)('hostDepositFeeBps'),
34
32
  (0, borsh_1.u16)('hostManagementFeeBps'),
35
33
  (0, borsh_1.u16)('hostPerformanceFeeBps'),
@@ -41,7 +39,6 @@ exports.FeeSettingsLayout = (0, borsh_1.struct)([
41
39
  (0, borsh_1.u16)('managersPerformanceFeeBps'),
42
40
  (0, borsh_1.u16)('basketDepositFeeBps'),
43
41
  (0, borsh_1.u16)('basketWithdrawFeeBps'),
44
- (0, borsh_1.u64)('modificationDelay'),
45
42
  ]);
46
43
  exports.ManagerSettingsLayout = (0, borsh_1.struct)([
47
44
  (0, borsh_1.array)((0, borsh_1.publicKey)(), exports.MAX_MANAGERS_PER_BASKET, 'managers'),
@@ -76,7 +73,7 @@ exports.MetadataSettingsLayout = (0, borsh_1.struct)([
76
73
  exports.BasketSettingsLayout = (0, borsh_1.struct)([
77
74
  (0, borsh_1.publicKey)('creator'),
78
75
  (0, borsh_1.publicKey)('host'),
79
- exports.BasketTypeLayout.replicate('basketType'),
76
+ (0, borsh_1.u8)('basketType'),
80
77
  fraction_1.FractionLayout.replicate('startPrice'),
81
78
  (0, borsh_1.u64)('activeRebalance'),
82
79
  (0, borsh_1.u64)('activeDeposits'),
@@ -1,6 +1,6 @@
1
1
  import { BN } from "@coral-xyz/anchor";
2
2
  export interface Fraction {
3
- numerator: BN;
4
- exponent: BN;
3
+ high: BN;
4
+ low: BN;
5
5
  }
6
6
  export declare const FractionLayout: any;
@@ -4,6 +4,6 @@ exports.FractionLayout = void 0;
4
4
  const borsh_1 = require("@coral-xyz/borsh");
5
5
  ;
6
6
  exports.FractionLayout = (0, borsh_1.struct)([
7
- (0, borsh_1.u64)('numerator'),
8
- (0, borsh_1.u64)('exponent'),
7
+ (0, borsh_1.u64)('high'),
8
+ (0, borsh_1.u64)('low'),
9
9
  ]);
@@ -10,9 +10,9 @@ export declare const BountyScheduleLayout: any;
10
10
  export interface Bounty {
11
11
  bountyDepositor: PublicKey;
12
12
  bountyMint: PublicKey;
13
- bountyTotal: BN;
14
- bountyLeft: BN;
15
13
  bountyPerPriceUpdateTask: BountySchedule;
16
14
  bountyPerTask: BountySchedule;
15
+ bountyTotal: BN;
16
+ bountyLeft: BN;
17
17
  }
18
18
  export declare const BountyLayout: any;
@@ -12,8 +12,8 @@ exports.BountyScheduleLayout = (0, borsh_1.struct)([
12
12
  exports.BountyLayout = (0, borsh_1.struct)([
13
13
  (0, borsh_1.publicKey)('bountyDepositor'),
14
14
  (0, borsh_1.publicKey)('bountyMint'),
15
+ exports.BountyScheduleLayout.replicate('bountyPerPriceUpdateTask'),
16
+ exports.BountyScheduleLayout.replicate('bountyPerTask'),
15
17
  (0, borsh_1.u64)('bountyTotal'),
16
18
  (0, borsh_1.u64)('bountyLeft'),
17
- exports.BountyScheduleLayout.replicate('bountyPerPriceUpdateTask'),
18
- exports.BountyScheduleLayout.replicate('bountyPerTask')
19
19
  ]);
@@ -10,15 +10,6 @@ export declare enum IntentStatus {
10
10
  Reverted = 2,
11
11
  Completed = 3
12
12
  }
13
- export interface ParsedIntent {
14
- manager: PublicKey;
15
- status: IntentStatus;
16
- activationTimestamp: BN;
17
- basket: PublicKey;
18
- bounty: Bounty;
19
- taskType: TaskType;
20
- taskData: EditData;
21
- }
22
13
  export interface Intent {
23
14
  manager: PublicKey;
24
15
  status: IntentStatus;
@@ -27,6 +18,8 @@ export interface Intent {
27
18
  bounty: Bounty;
28
19
  taskType: TaskType;
29
20
  taskData: number[];
21
+ parsedTaskData?: EditData;
22
+ ownAddress?: PublicKey;
30
23
  }
31
24
  export declare const IntentLayout: any;
32
25
  export interface HostFees {
@@ -16,7 +16,6 @@ var IntentStatus;
16
16
  })(IntentStatus || (exports.IntentStatus = IntentStatus = {}));
17
17
  ;
18
18
  ;
19
- ;
20
19
  exports.IntentLayout = (0, borsh_1.struct)([
21
20
  (0, borsh_1.publicKey)('manager'),
22
21
  (0, borsh_1.u8)('status'),
@@ -2,7 +2,7 @@ import { BN } from "@coral-xyz/anchor";
2
2
  import { PublicKey } from "@solana/web3.js";
3
3
  import { Fraction } from "../fraction";
4
4
  import { Bounty } from "./bounty";
5
- import { OraclePrice } from "../../states/oracles/oracle";
5
+ import { OraclePriceOnChain } from "../oracle";
6
6
  export declare enum RebalanceType {
7
7
  Deposit = 0,
8
8
  Withdraw = 1,
@@ -23,7 +23,7 @@ export interface TokenAuction {
23
23
  mint: PublicKey;
24
24
  amount: BN;
25
25
  targetAmount: BN;
26
- price: OraclePrice;
26
+ price: OraclePriceOnChain;
27
27
  keepToken: number;
28
28
  }
29
29
  export declare const TokenAuctionLayout: any;
@@ -52,5 +52,6 @@ export interface RebalanceIntent {
52
52
  finishPriceUpdateTask: TaskCompletion;
53
53
  mintBasketTask: TaskCompletion;
54
54
  tokenSettlementTasks: TaskCompletion[];
55
+ ownAddress?: PublicKey;
55
56
  }
56
57
  export declare const RebalanceIntentLayout: any;
@@ -2,14 +2,28 @@ import { BN } from "@coral-xyz/anchor";
2
2
  import { Fraction } from "./fraction";
3
3
  export declare const MAX_ORACLES_PER_TOKEN = 4;
4
4
  export declare const MAX_ACCOUNTS_PER_ORACLE = 4;
5
- export interface OraclePrice {
5
+ export interface OraclePriceOnChain {
6
6
  price: Fraction;
7
7
  conf: Fraction;
8
8
  updateTime: BN;
9
9
  }
10
10
  export declare const OraclePriceLayout: any;
11
+ export declare enum OracleType {
12
+ Example = 0,
13
+ Pyth = 1,
14
+ RaydiumCllm = 2,
15
+ RaydiumCpmm = 3
16
+ }
17
+ export declare enum Quote {
18
+ Usdc = 0,
19
+ Wsol = 1
20
+ }
21
+ export declare enum Side {
22
+ Base = 0,
23
+ Quote = 1
24
+ }
11
25
  export interface OracleSettings {
12
- oracleType: number;
26
+ oracleType: OracleType;
13
27
  numRequiredAccounts: number;
14
28
  weight: number;
15
29
  isRequired: number;
@@ -21,8 +35,8 @@ export interface OracleSettings {
21
35
  tokenDecimals: number;
22
36
  twapSecondsAgo: BN;
23
37
  twapSecondarySecondsAgo: BN;
24
- quote: number;
25
- side: number;
38
+ quote: Quote;
39
+ side: Side;
26
40
  }
27
41
  export declare const OracleSettingsLayout: any;
28
42
  export interface OracleData {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OracleAggregatorLayout = exports.OracleDataLayout = exports.OracleSettingsLayout = exports.OraclePriceLayout = exports.MAX_ACCOUNTS_PER_ORACLE = exports.MAX_ORACLES_PER_TOKEN = void 0;
3
+ exports.OracleAggregatorLayout = exports.OracleDataLayout = exports.OracleSettingsLayout = exports.Side = exports.Quote = exports.OracleType = exports.OraclePriceLayout = exports.MAX_ACCOUNTS_PER_ORACLE = exports.MAX_ORACLES_PER_TOKEN = void 0;
4
4
  const borsh_1 = require("@coral-xyz/borsh");
5
5
  const fraction_1 = require("./fraction");
6
6
  exports.MAX_ORACLES_PER_TOKEN = 4;
@@ -11,6 +11,26 @@ exports.OraclePriceLayout = (0, borsh_1.struct)([
11
11
  fraction_1.FractionLayout.replicate('conf'),
12
12
  (0, borsh_1.u64)('updateTime'),
13
13
  ]);
14
+ var OracleType;
15
+ (function (OracleType) {
16
+ OracleType[OracleType["Example"] = 0] = "Example";
17
+ OracleType[OracleType["Pyth"] = 1] = "Pyth";
18
+ OracleType[OracleType["RaydiumCllm"] = 2] = "RaydiumCllm";
19
+ OracleType[OracleType["RaydiumCpmm"] = 3] = "RaydiumCpmm";
20
+ })(OracleType || (exports.OracleType = OracleType = {}));
21
+ ;
22
+ var Quote;
23
+ (function (Quote) {
24
+ Quote[Quote["Usdc"] = 0] = "Usdc";
25
+ Quote[Quote["Wsol"] = 1] = "Wsol";
26
+ })(Quote || (exports.Quote = Quote = {}));
27
+ ;
28
+ var Side;
29
+ (function (Side) {
30
+ Side[Side["Base"] = 0] = "Base";
31
+ Side[Side["Quote"] = 1] = "Quote";
32
+ })(Side || (exports.Side = Side = {}));
33
+ ;
14
34
  exports.OracleSettingsLayout = (0, borsh_1.struct)([
15
35
  (0, borsh_1.u8)('oracleType'),
16
36
  (0, borsh_1.u8)('numRequiredAccounts'),
@@ -1,5 +1,5 @@
1
- import { Connection, PublicKey } from "@solana/web3.js";
2
- import { Basket } from "../layouts/basket";
1
+ import { Connection, PublicKey } from '@solana/web3.js';
2
+ import { Basket } from '../layouts/basket';
3
3
  export declare function decodeBasket(dataWithoutDiscriminator: Buffer): Basket;
4
4
  export declare function fetchBasket(connection: Connection, basketAddress: PublicKey): Promise<Basket>;
5
5
  export interface BasketFilter {
@@ -12,11 +12,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.decodeBasket = decodeBasket;
13
13
  exports.fetchBasket = fetchBasket;
14
14
  exports.fetchBaskets = fetchBaskets;
15
- const basket_1 = require("../layouts/basket");
16
15
  const constants_1 = require("../constants");
16
+ const basket_1 = require("../layouts/basket");
17
17
  function decodeBasket(dataWithoutDiscriminator) {
18
18
  let basket = basket_1.BasketLayout.decode(dataWithoutDiscriminator);
19
- return basket;
19
+ let metadataSettings = basket.settings.metadataSettings;
20
+ let metadata = {
21
+ symbol: Buffer.from(metadataSettings.symbol.slice(0, metadataSettings.symbolLength)).toString(),
22
+ name: Buffer.from(metadataSettings.name.slice(0, metadataSettings.nameLength)).toString(),
23
+ uri: Buffer.from(metadataSettings.uri.slice(0, metadataSettings.uriLength)).toString()
24
+ };
25
+ basket.composition = basket.composition.slice(0, basket.numTokens);
26
+ return Object.assign(Object.assign({}, basket), { metadata: metadata });
20
27
  }
21
28
  function fetchBasket(connection, basketAddress) {
22
29
  return __awaiter(this, void 0, void 0, function* () {
@@ -1,12 +1,7 @@
1
1
  import { Connection, PublicKey } from '@solana/web3.js';
2
- import { Intent, ParsedIntent } from '../../layouts/intents/intent';
3
- /**
4
- * Decode an Intent account buffer.
5
- * Returns ParsedIntent.
6
- */
7
- export declare function decodeIntent(intent: Intent): ParsedIntent;
2
+ import { Intent } from '../../layouts/intents/intent';
3
+ export declare function decodeIntent(dataWithoutDiscriminator: Buffer, ownAddress?: PublicKey): Intent;
8
4
  export declare function fetchIntent(connection: Connection, intent: PublicKey): Promise<Intent>;
9
- export declare function fetchParsedIntent(connection: Connection, intent: PublicKey): Promise<ParsedIntent>;
10
5
  export interface IntentFilter {
11
6
  filterType: "basket" | "owner";
12
7
  filterValue: PublicKey;
@@ -11,7 +11,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.decodeIntent = decodeIntent;
13
13
  exports.fetchIntent = fetchIntent;
14
- exports.fetchParsedIntent = fetchParsedIntent;
15
14
  exports.fetchIntents = fetchIntents;
16
15
  const constants_1 = require("../../constants");
17
16
  const intent_1 = require("../../layouts/intents/intent");
@@ -33,29 +32,26 @@ const taskLayoutMap = new Map([
33
32
  // Decode taskData buffer for a given task type; returns decoded object or raw Buffer on failure
34
33
  function decodeTaskDataForType(taskType, taskData) {
35
34
  const layout = taskLayoutMap.get(taskType);
35
+ console.log(layout);
36
36
  return layout.decode(taskData);
37
37
  }
38
38
  ;
39
- /**
40
- * Decode an Intent account buffer.
41
- * Returns ParsedIntent.
42
- */
43
- function decodeIntent(intent) {
44
- let parsedTaskData = decodeTaskDataForType(intent.taskType, intent.taskData);
45
- return Object.assign(Object.assign({}, intent), { taskData: parsedTaskData });
39
+ function decodeIntent(dataWithoutDiscriminator, ownAddress) {
40
+ let intent = intent_1.IntentLayout.decode(dataWithoutDiscriminator);
41
+ console.log(intent.taskData);
42
+ console.log(intent.taskType);
43
+ // let parsedTaskData = decodeTaskDataForType(intent.taskType, intent.taskData);
44
+ // console.log(parsedTaskData);
45
+ return Object.assign(Object.assign({}, intent), {
46
+ // parsedTaskData: parsedTaskData,
47
+ ownAddress: ownAddress });
46
48
  }
47
49
  function fetchIntent(connection, intent) {
48
50
  return __awaiter(this, void 0, void 0, function* () {
49
51
  const intentAi = yield connection.getAccountInfo(intent);
50
52
  if (!intentAi)
51
53
  throw new Error('Basket intent not found');
52
- return intent_1.IntentLayout.decode(intentAi.data.slice(8));
53
- });
54
- }
55
- function fetchParsedIntent(connection, intent) {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- const intentState = yield fetchIntent(connection, intent);
58
- return decodeIntent(intentState);
54
+ return decodeIntent(intentAi.data.slice(8), intent);
59
55
  });
60
56
  }
61
57
  function fetchIntents(connection, filters) {
@@ -84,7 +80,7 @@ function fetchIntents(connection, filters) {
84
80
  filters: accountFilters,
85
81
  encoding: 'base64'
86
82
  });
87
- const rebalanceIntents = accounts.map(account => intent_1.IntentLayout.decode(account.account.data.slice(8)));
83
+ const rebalanceIntents = accounts.map(account => decodeIntent(account.account.data.slice(8), account.pubkey));
88
84
  return rebalanceIntents;
89
85
  });
90
86
  }
@@ -1,5 +1,6 @@
1
1
  import { Connection, PublicKey } from "@solana/web3.js";
2
2
  import { RebalanceIntent } from "../../layouts/intents/rebalanceIntent";
3
+ export declare function decodeRebalanceIntent(dataWithoutDiscriminator: Buffer, ownAddress?: PublicKey): RebalanceIntent;
3
4
  export declare function fetchRebalanceIntent(connection: Connection, rebalanceIntent: PublicKey): Promise<RebalanceIntent>;
4
5
  export interface RebalanceIntentFilter {
5
6
  filterType: "basket" | "owner";
@@ -9,17 +9,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.decodeRebalanceIntent = decodeRebalanceIntent;
12
13
  exports.fetchRebalanceIntent = fetchRebalanceIntent;
13
14
  exports.fetchRebalanceIntents = fetchRebalanceIntents;
15
+ const web3_js_1 = require("@solana/web3.js");
14
16
  const rebalanceIntent_1 = require("../../layouts/intents/rebalanceIntent");
15
17
  const constants_1 = require("../../constants");
18
+ function decodeRebalanceIntent(dataWithoutDiscriminator, ownAddress) {
19
+ let rebalanceIntent = rebalanceIntent_1.RebalanceIntentLayout.decode(dataWithoutDiscriminator);
20
+ let numTokens = constants_1.MAX_SUPPORTED_TOKENS_PER_BASKET - 1;
21
+ while (rebalanceIntent.tokens[numTokens].mint.equals(web3_js_1.PublicKey.default))
22
+ numTokens--;
23
+ rebalanceIntent.tokens = rebalanceIntent.tokens.slice(0, numTokens + 1);
24
+ rebalanceIntent.priceUpdateTasks = rebalanceIntent.priceUpdateTasks.slice(0, numTokens + 1);
25
+ rebalanceIntent.tokenSettlementTasks = rebalanceIntent.tokenSettlementTasks.slice(0, numTokens + 1);
26
+ return Object.assign(Object.assign({}, rebalanceIntent), { ownAddress: ownAddress });
27
+ }
16
28
  function fetchRebalanceIntent(connection, rebalanceIntent) {
17
29
  return __awaiter(this, void 0, void 0, function* () {
18
30
  const rebalanceIntentAi = yield connection.getAccountInfo(rebalanceIntent);
19
31
  if (!rebalanceIntentAi) {
20
32
  throw new Error("Rebalance intent not found");
21
33
  }
22
- return rebalanceIntent_1.RebalanceIntentLayout.decode(rebalanceIntentAi.data.slice(8));
34
+ return decodeRebalanceIntent(rebalanceIntentAi.data.slice(8), rebalanceIntent);
23
35
  });
24
36
  }
25
37
  function fetchRebalanceIntents(connection, filters) {
@@ -48,7 +60,7 @@ function fetchRebalanceIntents(connection, filters) {
48
60
  filters: accountFilters,
49
61
  encoding: 'base64'
50
62
  });
51
- const rebalanceIntents = accounts.map(account => rebalanceIntent_1.RebalanceIntentLayout.decode(account.account.data.slice(8)));
63
+ const rebalanceIntents = accounts.map(account => decodeRebalanceIntent(account.account.data.slice(8), account.pubkey));
52
64
  return rebalanceIntents;
53
65
  });
54
66
  }
@@ -28,10 +28,10 @@ export declare class OraclePrice {
28
28
  price: Decimal;
29
29
  conf: Decimal;
30
30
  updateTime: BN;
31
- mid: Decimal;
32
- low: Decimal;
33
- high: Decimal;
34
31
  constructor(price: Decimal, conf: Decimal, updateTime: BN);
32
+ getMid(): Decimal;
33
+ getLow(): Decimal;
34
+ getHigh(): Decimal;
35
35
  }
36
36
  export declare class OracleResult {
37
37
  price: OraclePrice | null;
@@ -53,9 +53,6 @@ class OraclePrice {
53
53
  this.price = new decimal_js_1.default(price);
54
54
  this.conf = new decimal_js_1.default(conf);
55
55
  this.updateTime = updateTime;
56
- this.mid = this.price;
57
- this.low = this.price.sub(this.conf);
58
- this.high = this.price.add(this.conf);
59
56
  let zero_Decimal = new decimal_js_1.default(0);
60
57
  if (this.price.lte(zero_Decimal))
61
58
  throw new Error("price should be more than 0");
@@ -64,6 +61,15 @@ class OraclePrice {
64
61
  if (this.updateTime.lte(0))
65
62
  throw new Error("update time should be more than 0");
66
63
  }
64
+ getMid() {
65
+ return this.price;
66
+ }
67
+ getLow() {
68
+ return this.price.sub(this.conf);
69
+ }
70
+ getHigh() {
71
+ return this.price.add(this.conf);
72
+ }
67
73
  }
68
74
  exports.OraclePrice = OraclePrice;
69
75
  class OracleResult {
@@ -133,7 +139,7 @@ class OracleAggregator {
133
139
  for (let i = 0; i < this.oracles.length; i++) {
134
140
  try {
135
141
  let result = yield this.oracles[i].fetch();
136
- if (result.ok()) {
142
+ if (result.ok() && result.price !== null) {
137
143
  prices.push(result.price);
138
144
  weights.push(new decimal_js_1.default(this.oracles[i].weight));
139
145
  }
@@ -154,7 +160,7 @@ class OracleAggregator {
154
160
  let frac3 = new decimal_js_1.default(3);
155
161
  prices.map((price, i) => {
156
162
  var _a, _b, _c;
157
- allPrices.push((_a = price === null || price === void 0 ? void 0 : price.mid) !== null && _a !== void 0 ? _a : null, (_b = price === null || price === void 0 ? void 0 : price.low) !== null && _b !== void 0 ? _b : null, (_c = price === null || price === void 0 ? void 0 : price.high) !== null && _c !== void 0 ? _c : null);
163
+ allPrices.push((_a = price === null || price === void 0 ? void 0 : price.getMid()) !== null && _a !== void 0 ? _a : null, (_b = price === null || price === void 0 ? void 0 : price.getLow()) !== null && _b !== void 0 ? _b : null, (_c = price === null || price === void 0 ? void 0 : price.getHigh()) !== null && _c !== void 0 ? _c : null);
158
164
  let w = weights[i].div(frac3);
159
165
  allWeights.push(w, w, w);
160
166
  });
@@ -2,14 +2,16 @@ import Decimal from 'decimal.js';
2
2
  import { BN } from '@coral-xyz/anchor';
3
3
  import { Connection, PublicKey } from '@solana/web3.js';
4
4
  import { Oracle, OracleResult } from './oracle';
5
- declare enum Side {
5
+ export declare enum Side {
6
6
  Base = 0,
7
7
  Quote = 1
8
8
  }
9
- declare enum Quote {
9
+ export declare const SideLayout: any;
10
+ export declare enum Quote {
10
11
  Usdc = 0,
11
12
  Wsol = 1
12
13
  }
14
+ export declare const QuoteLayout: any;
13
15
  declare class Observation {
14
16
  timestamp: BN;
15
17
  cumT0Price: BN;
@@ -12,23 +12,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.RaydiumCPMMOracle = void 0;
15
+ exports.RaydiumCPMMOracle = exports.QuoteLayout = exports.Quote = exports.SideLayout = exports.Side = void 0;
16
16
  const decimal_js_1 = __importDefault(require("decimal.js"));
17
17
  const anchor_1 = require("@coral-xyz/anchor");
18
18
  const web3_js_1 = require("@solana/web3.js");
19
19
  const oracle_1 = require("./oracle");
20
+ const borsh_1 = require("@coral-xyz/borsh");
20
21
  const CPMM_PROGRAM_ID = new web3_js_1.PublicKey("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C");
21
22
  const DEV_CPMM_PROGRAM_ID = new web3_js_1.PublicKey("DRaycpLY18LhpbydsBWbVJtxpNv9oXPgjRSfpF2bWpYb");
22
23
  var Side;
23
24
  (function (Side) {
24
25
  Side[Side["Base"] = 0] = "Base";
25
26
  Side[Side["Quote"] = 1] = "Quote";
26
- })(Side || (Side = {}));
27
+ })(Side || (exports.Side = Side = {}));
28
+ exports.SideLayout = (0, borsh_1.struct)([
29
+ (0, borsh_1.u8)('side'),
30
+ ]);
27
31
  var Quote;
28
32
  (function (Quote) {
29
33
  Quote[Quote["Usdc"] = 0] = "Usdc";
30
34
  Quote[Quote["Wsol"] = 1] = "Wsol";
31
- })(Quote || (Quote = {}));
35
+ })(Quote || (exports.Quote = Quote = {}));
36
+ exports.QuoteLayout = (0, borsh_1.struct)([
37
+ (0, borsh_1.u8)('quote'),
38
+ ]);
32
39
  class Observation {
33
40
  constructor(params) {
34
41
  this.timestamp = params.timestamp;
package/dist/test.js CHANGED
@@ -15,14 +15,14 @@ const anchor_1 = require("@coral-xyz/anchor");
15
15
  let connection = new web3_js_1.Connection("https://api.devnet.solana.com");
16
16
  function testStates() {
17
17
  return __awaiter(this, void 0, void 0, function* () {
18
- let sdk = new src_1.BasketsSdk({
18
+ let sdk = new src_1.SymmetryCore({
19
19
  connection: connection,
20
20
  });
21
21
  console.log("SDK created");
22
22
  let x = yield sdk.createBasketTx({
23
23
  creator: web3_js_1.PublicKey.default,
24
24
  host: web3_js_1.PublicKey.default,
25
- startPrice: { exponent: new anchor_1.BN(1), numerator: new anchor_1.BN(1) },
25
+ startPrice: { high: new anchor_1.BN(0), low: new anchor_1.BN(Math.floor((1 << 64) / 10)) },
26
26
  hostFees: { hostDepositFeeBps: 0, hostManagementFeeBps: 0, hostPerformanceFeeBps: 0 },
27
27
  metadataParams: { name: "Test Basket", symbol: "TB", uri: "https://test.com" },
28
28
  metadataModificationDelay: new anchor_1.BN(0),
@@ -33,7 +33,20 @@ function testStates() {
33
33
  let intents = yield sdk.fetchAllIntents([]);
34
34
  console.log(intents.map(intent => intent.manager.toBase58()));
35
35
  let rebalanceIntents = yield sdk.fetchAllRebalanceIntents([]);
36
- console.log(rebalanceIntents.map(rebalanceIntent => rebalanceIntent.owner.toBase58()));
36
+ console.log(rebalanceIntents.map(rebalanceIntent => {
37
+ var _a;
38
+ return {
39
+ owner: rebalanceIntent.owner.toBase58(),
40
+ basket: rebalanceIntent.basket.toBase58(),
41
+ ownAddress: (_a = rebalanceIntent.ownAddress) === null || _a === void 0 ? void 0 : _a.toBase58(),
42
+ };
43
+ }));
44
+ rebalanceIntents.forEach(rebalanceIntent => {
45
+ console.log("--------------------------------");
46
+ console.log(rebalanceIntent.tokens[0].price, rebalanceIntent.tokens[0].price);
47
+ });
48
+ // console.log(baskets[0]);
49
+ // console.log(baskets[0].composition[0].oracleAggregator.oracles[0].oracleSettings);
37
50
  });
38
51
  }
39
52
  testStates();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symmetry-hq/temp-v3-sdk",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Symmetry Baskets V3 SDK",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
package/src/index.ts CHANGED
@@ -25,7 +25,7 @@ export const JUPITER_API_KEY = "https://quote-api.jup.ag/v6/";
25
25
  export const MAX_JUPITER_ACCOUNTS = 35;
26
26
 
27
27
 
28
- export class BasketsSdk {
28
+ export class SymmetryCore {
29
29
 
30
30
  private sdkParams: {
31
31
  payer: PublicKey,
@@ -264,3 +264,13 @@ export class BasketsSdk {
264
264
  }
265
265
 
266
266
  }
267
+
268
+
269
+ export {
270
+ Basket,
271
+ BasketFilter,
272
+ Intent,
273
+ IntentFilter,
274
+ RebalanceIntent,
275
+ RebalanceIntentFilter
276
+ }
@@ -108,8 +108,8 @@ export function createBasketIx(params: {
108
108
  Buffer.from(seed),
109
109
  Buffer.from(new BN(slot).toArray("le", 8)),
110
110
  host.toBuffer(),
111
- Buffer.from(startPrice.numerator.toArray("le", 8)),
112
- Buffer.from(startPrice.exponent.toArray("le", 8)),
111
+ Buffer.from(startPrice.high.toArray("le", 8)),
112
+ Buffer.from(startPrice.low.toArray("le", 8)),
113
113
  hostFeesBuffer,
114
114
  serializeString(metadataParams.name),
115
115
  serializeString(metadataParams.symbol),
@@ -1,10 +1,11 @@
1
1
 
2
- import { BN } from "@coral-xyz/anchor";
3
- import { PublicKey } from "@solana/web3.js";
2
+ import { BN } from '@coral-xyz/anchor';
4
3
  import { array, publicKey, str, struct, u128, u16, u64, u8 } from '@coral-xyz/borsh';
5
- import { OracleAggregator, OracleAggregatorLayout } from "./oracle";
6
- import { Fraction, FractionLayout } from "./fraction";
7
- import { BasketSettings, BasketSettingsLayout } from "./config";
4
+ import { PublicKey } from '@solana/web3.js';
5
+
6
+ import { BasketSettings, BasketSettingsLayout } from './config';
7
+ import { Fraction, FractionLayout } from './fraction';
8
+ import { OracleAggregator, OracleAggregatorLayout } from './oracle';
8
9
 
9
10
  export const MAX_SUPPORTED_TOKENS_PER_BASKET: number = 100;
10
11
 
@@ -46,6 +47,12 @@ export const AssetLayout = struct<Asset>([
46
47
  OracleAggregatorLayout.replicate('oracleAggregator'),
47
48
  ]);
48
49
 
50
+ export interface Metadata {
51
+ symbol: string,
52
+ name: string,
53
+ uri: string
54
+ }
55
+
49
56
  export interface Basket {
50
57
  version: number; // u8
51
58
  seedArray: number[]; // length 16
@@ -63,6 +70,7 @@ export interface Basket {
63
70
  writeVersion: BN; // u64
64
71
  numTokens: number; // u8
65
72
  composition: Asset[]; // length MAX_SUPPORTED_TOKENS_PER_BASKET
73
+ metadata?: Metadata
66
74
  };
67
75
 
68
76
  export const BasketLayout = struct<Basket>([
@@ -14,10 +14,6 @@ export enum BasketType {
14
14
  Public = 1,
15
15
  };
16
16
 
17
- export const BasketTypeLayout = struct<BasketType>([
18
- u8('basketType'),
19
- ]);
20
-
21
17
  export interface ScheduleSettings {
22
18
  cycleDuration: BN; // u64
23
19
  depositsStart: BN; // u64
@@ -56,6 +52,7 @@ export interface FeeSettings {
56
52
  };
57
53
 
58
54
  export const FeeSettingsLayout = struct<FeeSettings>([
55
+ u64('modificationDelay'),
59
56
  u16('hostDepositFeeBps'),
60
57
  u16('hostManagementFeeBps'),
61
58
  u16('hostPerformanceFeeBps'),
@@ -67,7 +64,6 @@ export const FeeSettingsLayout = struct<FeeSettings>([
67
64
  u16('managersPerformanceFeeBps'),
68
65
  u16('basketDepositFeeBps'),
69
66
  u16('basketWithdrawFeeBps'),
70
- u64('modificationDelay'),
71
67
  ]);
72
68
 
73
69
  export interface ManagerSettings {
@@ -175,7 +171,7 @@ export const BasketSettingsLayout = struct<BasketSettings>([
175
171
  publicKey('creator'),
176
172
  publicKey('host'),
177
173
 
178
- BasketTypeLayout.replicate('basketType'),
174
+ u8('basketType'),
179
175
  FractionLayout.replicate('startPrice'),
180
176
 
181
177
  u64('activeRebalance'),
@@ -2,11 +2,11 @@ import { BN } from "@coral-xyz/anchor";
2
2
  import { array, publicKey, str, struct, u128, u16, u64, u8 } from '@coral-xyz/borsh';
3
3
 
4
4
  export interface Fraction {
5
- numerator: BN; // u64 -> BN
6
- exponent: BN; // u64 -> BN
5
+ high: BN; // u64 -> BN
6
+ low: BN; // u64 -> BN
7
7
  };
8
8
 
9
9
  export const FractionLayout = struct<Fraction>([
10
- u64('numerator'),
11
- u64('exponent'),
10
+ u64('high'),
11
+ u64('low'),
12
12
  ]);
@@ -19,17 +19,17 @@ export const BountyScheduleLayout = struct<BountySchedule>([
19
19
  export interface Bounty {
20
20
  bountyDepositor: PublicKey;
21
21
  bountyMint: PublicKey;
22
- bountyTotal: BN; // u64
23
- bountyLeft: BN; // u64
24
22
  bountyPerPriceUpdateTask: BountySchedule;
25
23
  bountyPerTask: BountySchedule;
24
+ bountyTotal: BN; // u64
25
+ bountyLeft: BN; // u64
26
26
  }
27
27
 
28
28
  export const BountyLayout = struct<Bounty>([
29
29
  publicKey('bountyDepositor'),
30
30
  publicKey('bountyMint'),
31
+ BountyScheduleLayout.replicate('bountyPerPriceUpdateTask'),
32
+ BountyScheduleLayout.replicate('bountyPerTask'),
31
33
  u64('bountyTotal'),
32
34
  u64('bountyLeft'),
33
- BountyScheduleLayout.replicate('bountyPerPriceUpdateTask'),
34
- BountyScheduleLayout.replicate('bountyPerTask')
35
35
  ]);
@@ -15,16 +15,6 @@ export enum IntentStatus {
15
15
  Completed,
16
16
  };
17
17
 
18
- export interface ParsedIntent {
19
- manager: PublicKey;
20
- status : IntentStatus;
21
- activationTimestamp: BN; // u64
22
- basket: PublicKey;
23
- bounty: Bounty;
24
- taskType: TaskType;
25
- taskData: EditData;
26
- };
27
-
28
18
  export interface Intent {
29
19
  manager: PublicKey;
30
20
  status : IntentStatus;
@@ -33,6 +23,8 @@ export interface Intent {
33
23
  bounty: Bounty;
34
24
  taskType: TaskType;
35
25
  taskData: number[]; // length of 600
26
+ parsedTaskData?: EditData;
27
+ ownAddress?: PublicKey;
36
28
  };
37
29
 
38
30
  export const IntentLayout = struct<Intent>([
@@ -3,8 +3,7 @@ import { PublicKey } from "@solana/web3.js";
3
3
  import { array, publicKey, str, struct, u128, u16, u64, u8 } from '@coral-xyz/borsh';
4
4
  import { Fraction, FractionLayout } from "../fraction";
5
5
  import { Bounty, BountyLayout } from "./bounty";
6
- import { OraclePrice } from "../../states/oracles/oracle";
7
- import { OraclePriceLayout } from "../oracle";
6
+ import { OraclePriceLayout, OraclePriceOnChain } from "../oracle";
8
7
  import { MAX_SUPPORTED_TOKENS_PER_BASKET } from "../basket";
9
8
 
10
9
  export enum RebalanceType {
@@ -34,7 +33,7 @@ export interface TokenAuction {
34
33
  mint: PublicKey;
35
34
  amount: BN; // u64
36
35
  targetAmount: BN; // u64
37
- price: OraclePrice;
36
+ price: OraclePriceOnChain;
38
37
  keepToken: number; // u8
39
38
  };
40
39
 
@@ -82,6 +81,8 @@ export interface RebalanceIntent {
82
81
  mintBasketTask: TaskCompletion;
83
82
 
84
83
  tokenSettlementTasks: TaskCompletion[]; // MAX_SUPPORTED_TOKENS_PER_BASKET
84
+
85
+ ownAddress?: PublicKey;
85
86
  };
86
87
 
87
88
 
@@ -5,22 +5,39 @@ import { Fraction, FractionLayout } from "./fraction";
5
5
  export const MAX_ORACLES_PER_TOKEN = 4;
6
6
  export const MAX_ACCOUNTS_PER_ORACLE = 4;
7
7
 
8
- export interface OraclePrice {
8
+ export interface OraclePriceOnChain {
9
9
  price: Fraction;
10
10
  conf: Fraction;
11
11
  updateTime: BN; // u64
12
12
  };
13
13
 
14
- export const OraclePriceLayout = struct<OraclePrice>([
14
+ export const OraclePriceLayout = struct<OraclePriceOnChain>([
15
15
  FractionLayout.replicate('price'),
16
16
  FractionLayout.replicate('conf'),
17
17
  u64('updateTime'),
18
18
  ]);
19
19
 
20
20
 
21
+ export enum OracleType {
22
+ Example = 0,
23
+ Pyth = 1,
24
+ RaydiumCllm = 2,
25
+ RaydiumCpmm = 3,
26
+ };
27
+
28
+ export enum Quote {
29
+ Usdc = 0,
30
+ Wsol = 1,
31
+ };
32
+
33
+ export enum Side {
34
+ Base = 0,
35
+ Quote = 1,
36
+ };
37
+
21
38
  export interface OracleSettings {
22
39
  // type of the oracle (Pyth, CP swap, ...)
23
- oracleType: number; // u8
40
+ oracleType: OracleType; // u8
24
41
  numRequiredAccounts: number; // u8
25
42
  // weight used in aggregation
26
43
  weight: number; // u16
@@ -40,8 +57,8 @@ export interface OracleSettings {
40
57
  // Special parameters specific to Raydium
41
58
  twapSecondsAgo: BN; // u64, primary twap window in seconds
42
59
  twapSecondarySecondsAgo: BN; // u64, secondary twap window - to check volatility
43
- quote: number; // u8, 1 = USDC, 2 = WSOL
44
- side: number; // 0 = base, 1 = quote
60
+ quote: Quote; // u8, 1 = USDC, 2 = WSOL
61
+ side: Side; // 0 = base, 1 = quote
45
62
  }
46
63
 
47
64
  export const OracleSettingsLayout = struct<OracleSettings>([
@@ -1,11 +1,20 @@
1
- import { Connection, GetProgramAccountsFilter, GetProgramAccountsResponse, PublicKey } from "@solana/web3.js";
2
- import { AssetLayout, Basket, BasketLayout, LookupTablesLayout } from "../layouts/basket";
3
- import { BASKETS_V3_PROGRAM_ID } from "../constants";
1
+ import {
2
+ Connection, GetProgramAccountsFilter, GetProgramAccountsResponse, PublicKey
3
+ } from '@solana/web3.js';
4
4
 
5
+ import { BASKETS_V3_PROGRAM_ID } from '../constants';
6
+ import { AssetLayout, Basket, BasketLayout, LookupTablesLayout } from '../layouts/basket';
5
7
 
6
8
  export function decodeBasket(dataWithoutDiscriminator: Buffer): Basket {
7
- let basket = BasketLayout.decode(dataWithoutDiscriminator);
8
- return basket;
9
+ let basket: Basket = BasketLayout.decode(dataWithoutDiscriminator);
10
+ let metadataSettings = basket.settings.metadataSettings;
11
+ let metadata = {
12
+ symbol: Buffer.from(metadataSettings.symbol.slice(0, metadataSettings.symbolLength)).toString(),
13
+ name: Buffer.from(metadataSettings.name.slice(0, metadataSettings.nameLength)).toString(),
14
+ uri: Buffer.from(metadataSettings.uri.slice(0, metadataSettings.uriLength)).toString()
15
+ }
16
+ basket.composition = basket.composition.slice(0, basket.numTokens);
17
+ return {...basket, metadata: metadata};
9
18
  }
10
19
 
11
20
  export async function fetchBasket(
@@ -1,9 +1,7 @@
1
- import { BN } from '@coral-xyz/anchor';
2
- import { array, publicKey, struct, u16, u32, u64, u8 } from '@coral-xyz/borsh';
3
1
  import { Connection, PublicKey } from '@solana/web3.js';
4
2
 
5
3
  import { BASKETS_V3_PROGRAM_ID } from '../../constants';
6
- import { AddTokenDelayLayout, AddTokenLayout, Intent, IntentLayout, IntentStatus, ManagerSettingsWithAuthorityBitmasksLayout, ParsedIntent, SwapLayout, TaskType, UpdateWeightsDelayLayout, UpdateWeightsLayout } from '../../layouts/intents/intent';
4
+ import { AddTokenDelayLayout, AddTokenLayout, Intent, IntentLayout, ManagerSettingsWithAuthorityBitmasksLayout, SwapLayout, TaskType, UpdateWeightsDelayLayout, UpdateWeightsLayout } from '../../layouts/intents/intent';
7
5
  import { MetadataSettingsLayout, AutomationSettingsLayout, FeeSettingsLayout, LpSettingsLayout, ScheduleSettingsLayout } from '../../layouts/config';
8
6
  import { GetProgramAccountsFilter } from '@solana/web3.js';
9
7
  import { GetProgramAccountsResponse } from '@solana/web3.js';
@@ -30,19 +28,21 @@ function decodeTaskDataForType(
30
28
  taskData: number[]
31
29
  ): any {
32
30
  const layout = taskLayoutMap.get(taskType);
31
+ console.log(layout);
33
32
  return layout.decode(taskData);
34
33
  };
35
34
 
36
35
 
37
- /**
38
- * Decode an Intent account buffer.
39
- * Returns ParsedIntent.
40
- */
41
- export function decodeIntent(intent: Intent): ParsedIntent {
42
- let parsedTaskData = decodeTaskDataForType(intent.taskType, intent.taskData);
36
+ export function decodeIntent(dataWithoutDiscriminator: Buffer, ownAddress?: PublicKey): Intent {
37
+ let intent: Intent = IntentLayout.decode(dataWithoutDiscriminator);
38
+ console.log(intent.taskData);
39
+ console.log(intent.taskType);
40
+ // let parsedTaskData = decodeTaskDataForType(intent.taskType, intent.taskData);
41
+ // console.log(parsedTaskData);
43
42
  return {
44
43
  ...intent,
45
- taskData: parsedTaskData,
44
+ // parsedTaskData: parsedTaskData,
45
+ ownAddress: ownAddress,
46
46
  };
47
47
  }
48
48
 
@@ -54,15 +54,7 @@ export async function fetchIntent(
54
54
  intent
55
55
  );
56
56
  if (!intentAi) throw new Error('Basket intent not found');
57
- return IntentLayout.decode(intentAi.data.slice(8));
58
- }
59
-
60
- export async function fetchParsedIntent(
61
- connection: Connection,
62
- intent: PublicKey,
63
- ): Promise<ParsedIntent>{
64
- const intentState: Intent = await fetchIntent(connection, intent);
65
- return decodeIntent(intentState);
57
+ return decodeIntent(intentAi.data.slice(8), intent);
66
58
  }
67
59
 
68
60
  export interface IntentFilter {
@@ -101,7 +93,7 @@ export async function fetchIntents(
101
93
  }
102
94
  );
103
95
  const rebalanceIntents: Intent[] = accounts.map(account =>
104
- IntentLayout.decode(account.account.data.slice(8))
96
+ decodeIntent(account.account.data.slice(8), account.pubkey)
105
97
  );
106
98
  return rebalanceIntents;
107
99
  }
@@ -1,9 +1,21 @@
1
1
  import { Connection, GetProgramAccountsResponse, PublicKey } from "@solana/web3.js";
2
2
  import { RebalanceIntent, RebalanceIntentLayout } from "../../layouts/intents/rebalanceIntent";
3
3
  import { GetProgramAccountsFilter } from "@solana/web3.js";
4
- import { BASKETS_V3_PROGRAM_ID } from "../../constants";
4
+ import { BASKETS_V3_PROGRAM_ID, MAX_SUPPORTED_TOKENS_PER_BASKET } from "../../constants";
5
5
 
6
6
 
7
+ export function decodeRebalanceIntent(dataWithoutDiscriminator: Buffer, ownAddress?: PublicKey): RebalanceIntent {
8
+ let rebalanceIntent: RebalanceIntent = RebalanceIntentLayout.decode(dataWithoutDiscriminator);
9
+
10
+ let numTokens = MAX_SUPPORTED_TOKENS_PER_BASKET - 1;
11
+ while (rebalanceIntent.tokens[numTokens].mint.equals(PublicKey.default))
12
+ numTokens--;
13
+ rebalanceIntent.tokens = rebalanceIntent.tokens.slice(0, numTokens + 1);
14
+ rebalanceIntent.priceUpdateTasks = rebalanceIntent.priceUpdateTasks.slice(0, numTokens + 1);
15
+ rebalanceIntent.tokenSettlementTasks = rebalanceIntent.tokenSettlementTasks.slice(0, numTokens + 1);
16
+ return {...rebalanceIntent, ownAddress: ownAddress};
17
+ }
18
+
7
19
  export async function fetchRebalanceIntent(
8
20
  connection: Connection,
9
21
  rebalanceIntent: PublicKey,
@@ -12,7 +24,7 @@ export async function fetchRebalanceIntent(
12
24
  if (!rebalanceIntentAi) {
13
25
  throw new Error("Rebalance intent not found");
14
26
  }
15
- return RebalanceIntentLayout.decode(rebalanceIntentAi.data.slice(8));
27
+ return decodeRebalanceIntent(rebalanceIntentAi.data.slice(8), rebalanceIntent);
16
28
  }
17
29
 
18
30
  export interface RebalanceIntentFilter {
@@ -51,7 +63,7 @@ export async function fetchRebalanceIntents(
51
63
  }
52
64
  );
53
65
  const rebalanceIntents: RebalanceIntent[] = accounts.map(account =>
54
- RebalanceIntentLayout.decode(account.account.data.slice(8))
66
+ decodeRebalanceIntent(account.account.data.slice(8), account.pubkey)
55
67
  );
56
68
  return rebalanceIntents;
57
69
  }
@@ -43,23 +43,27 @@ export class OraclePrice {
43
43
  price: Decimal;
44
44
  conf: Decimal;
45
45
  updateTime: BN;
46
- mid: Decimal;
47
- low: Decimal;
48
- high: Decimal;
49
46
 
50
47
  constructor(price: Decimal, conf: Decimal, updateTime: BN){
51
48
  this.price = new Decimal(price);
52
49
  this.conf = new Decimal(conf);
53
50
  this.updateTime = updateTime;
54
- this.mid = this.price;
55
- this.low = this.price.sub(this.conf);
56
- this.high = this.price.add(this.conf);
57
51
 
58
52
  let zero_Decimal = new Decimal(0);
59
53
  if(this.price.lte(zero_Decimal)) throw new Error("price should be more than 0");
60
54
  if(this.conf.lt(zero_Decimal)) throw new Error("confidence can't be negative");
61
55
  if(this.updateTime.lte(0)) throw new Error("update time should be more than 0");
62
56
  }
57
+
58
+ getMid(): Decimal {
59
+ return this.price;
60
+ }
61
+ getLow(): Decimal {
62
+ return this.price.sub(this.conf);
63
+ }
64
+ getHigh(): Decimal {
65
+ return this.price.add(this.conf);
66
+ }
63
67
  }
64
68
 
65
69
  export class OracleResult {
@@ -136,13 +140,13 @@ export class OracleAggregator{
136
140
  }
137
141
  async fetch(): Promise<OracleResult> {
138
142
  console.log("Fetching price from oracle aggregator");
139
- let prices: (OraclePrice | null)[] = Array(0);
143
+ let prices: OraclePrice[] = Array(0);
140
144
  let weights: Decimal[] = Array(0);
141
145
 
142
146
  for(let i = 0; i< this.oracles.length; i++){
143
147
  try {
144
148
  let result = await this.oracles[i].fetch();
145
- if(result.ok()){
149
+ if(result.ok() && result.price !== null){
146
150
  prices.push(result.price);
147
151
  weights.push(new Decimal(this.oracles[i].weight));
148
152
  }
@@ -163,7 +167,7 @@ export class OracleAggregator{
163
167
  let allWeights: Decimal[] = Array(0);
164
168
  let frac3: Decimal = new Decimal(3);
165
169
  prices.map((price, i) => {
166
- allPrices.push(price?.mid ?? null , price?.low ?? null , price?.high ?? null);
170
+ allPrices.push(price?.getMid() ?? null , price?.getLow() ?? null , price?.getHigh() ?? null);
167
171
  let w = weights[i].div(frac3);
168
172
  allWeights.push(w,w,w);
169
173
  });
@@ -4,20 +4,29 @@ import { BN } from '@coral-xyz/anchor';
4
4
  import { Connection, PublicKey } from '@solana/web3.js';
5
5
 
6
6
  import { ErrorCode, Oracle, OracleErrors, OraclePrice, OracleResult } from './oracle';
7
+ import { struct, u8 } from '@coral-xyz/borsh';
7
8
 
8
9
  const CPMM_PROGRAM_ID = new PublicKey("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C");
9
10
  const DEV_CPMM_PROGRAM_ID = new PublicKey("DRaycpLY18LhpbydsBWbVJtxpNv9oXPgjRSfpF2bWpYb");
10
11
 
11
- enum Side {
12
+ export enum Side {
12
13
  Base,
13
14
  Quote,
14
15
  }
15
16
 
16
- enum Quote {
17
+ export const SideLayout = struct<Side>([
18
+ u8('side'),
19
+ ]);
20
+
21
+ export enum Quote {
17
22
  Usdc,
18
23
  Wsol,
19
24
  }
20
25
 
26
+ export const QuoteLayout = struct<Quote>([
27
+ u8('quote'),
28
+ ]);
29
+
21
30
  class Observation {
22
31
  timestamp: BN; // u64
23
32
  cumT0Price: BN; // u128
package/test.ts CHANGED
@@ -1,30 +1,43 @@
1
1
  import { Connection, PublicKey } from "@solana/web3.js";
2
- import { BasketsSdk } from "./src";
2
+ import { SymmetryCore, Basket, } from "./src";
3
3
  import { BN } from "@coral-xyz/anchor";
4
4
 
5
5
 
6
6
  let connection = new Connection("https://api.devnet.solana.com");
7
7
 
8
8
  async function testStates() {
9
- let sdk = new BasketsSdk({
9
+ let sdk = new SymmetryCore({
10
10
  connection: connection as any,
11
11
  });
12
12
  console.log("SDK created");
13
13
  let x = await sdk.createBasketTx({
14
14
  creator: PublicKey.default,
15
15
  host: PublicKey.default,
16
- startPrice: {exponent: new BN(1), numerator: new BN(1)},
16
+ startPrice: {high: new BN(0), low: new BN(Math.floor((1 << 64) / 10))},
17
17
  hostFees: {hostDepositFeeBps: 0, hostManagementFeeBps: 0, hostPerformanceFeeBps: 0},
18
18
  metadataParams: { name: "Test Basket", symbol: "TB", uri: "https://test.com" },
19
19
  metadataModificationDelay: new BN(0),
20
20
  });
21
21
  console.log(x);
22
- let baskets = await sdk.fetchAllBaskets([]);
22
+ let baskets: Basket[] = await sdk.fetchAllBaskets([]);
23
23
  console.log(baskets.map(basket => basket.ownAddress.toBase58()));
24
24
  let intents = await sdk.fetchAllIntents([]);
25
25
  console.log(intents.map(intent => intent.manager.toBase58()));
26
- let rebalanceIntents = await sdk.fetchAllRebalanceIntents([]);
27
- console.log(rebalanceIntents.map(rebalanceIntent => rebalanceIntent.owner.toBase58()));
26
+ let rebalanceIntents = await sdk.fetchAllRebalanceIntents([
27
+ ]);
28
+ console.log(rebalanceIntents.map(rebalanceIntent => {
29
+ return {
30
+ owner: rebalanceIntent.owner.toBase58(),
31
+ basket: rebalanceIntent.basket.toBase58(),
32
+ ownAddress: rebalanceIntent.ownAddress?.toBase58(),
33
+ };
34
+ }));
35
+ rebalanceIntents.forEach(rebalanceIntent => {
36
+ console.log("--------------------------------");
37
+ console.log(rebalanceIntent.tokens[0].price, rebalanceIntent.tokens[0].price);
38
+ });
39
+ // console.log(baskets[0]);
40
+ // console.log(baskets[0].composition[0].oracleAggregator.oracles[0].oracleSettings);
28
41
  }
29
42
 
30
43
  testStates();