@symmetry-hq/sdk 1.0.1

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 (121) hide show
  1. package/dist/src/constants.d.ts +23 -0
  2. package/dist/src/constants.js +38 -0
  3. package/dist/src/index.d.ts +804 -0
  4. package/dist/src/index.js +2097 -0
  5. package/dist/src/instructions/automation/auction.d.ts +6 -0
  6. package/dist/src/instructions/automation/auction.js +40 -0
  7. package/dist/src/instructions/automation/claimBounty.d.ts +12 -0
  8. package/dist/src/instructions/automation/claimBounty.js +44 -0
  9. package/dist/src/instructions/automation/flashSwap.d.ts +21 -0
  10. package/dist/src/instructions/automation/flashSwap.js +74 -0
  11. package/dist/src/instructions/automation/priceUpdate.d.ts +19 -0
  12. package/dist/src/instructions/automation/priceUpdate.js +89 -0
  13. package/dist/src/instructions/automation/rebalanceIntent.d.ts +32 -0
  14. package/dist/src/instructions/automation/rebalanceIntent.js +117 -0
  15. package/dist/src/instructions/automation/rebalanceSwap.d.ts +11 -0
  16. package/dist/src/instructions/automation/rebalanceSwap.js +42 -0
  17. package/dist/src/instructions/management/addBounty.d.ts +7 -0
  18. package/dist/src/instructions/management/addBounty.js +41 -0
  19. package/dist/src/instructions/management/admin.d.ts +9 -0
  20. package/dist/src/instructions/management/admin.js +53 -0
  21. package/dist/src/instructions/management/claimFees.d.ts +15 -0
  22. package/dist/src/instructions/management/claimFees.js +95 -0
  23. package/dist/src/instructions/management/createBasket.d.ts +21 -0
  24. package/dist/src/instructions/management/createBasket.js +98 -0
  25. package/dist/src/instructions/management/edit.d.ts +51 -0
  26. package/dist/src/instructions/management/edit.js +477 -0
  27. package/dist/src/instructions/management/luts.d.ts +30 -0
  28. package/dist/src/instructions/management/luts.js +99 -0
  29. package/dist/src/instructions/pda.d.ts +25 -0
  30. package/dist/src/instructions/pda.js +128 -0
  31. package/dist/src/instructions/user/deposit.d.ts +20 -0
  32. package/dist/src/instructions/user/deposit.js +100 -0
  33. package/dist/src/instructions/user/withdraw.d.ts +8 -0
  34. package/dist/src/instructions/user/withdraw.js +36 -0
  35. package/dist/src/jup.d.ts +49 -0
  36. package/dist/src/jup.js +80 -0
  37. package/dist/src/keeperMonitor.d.ts +52 -0
  38. package/dist/src/keeperMonitor.js +624 -0
  39. package/dist/src/layouts/basket.d.ts +191 -0
  40. package/dist/src/layouts/basket.js +51 -0
  41. package/dist/src/layouts/config.d.ts +281 -0
  42. package/dist/src/layouts/config.js +237 -0
  43. package/dist/src/layouts/fraction.d.ts +20 -0
  44. package/dist/src/layouts/fraction.js +164 -0
  45. package/dist/src/layouts/intents/bounty.d.ts +18 -0
  46. package/dist/src/layouts/intents/bounty.js +19 -0
  47. package/dist/src/layouts/intents/intent.d.ts +209 -0
  48. package/dist/src/layouts/intents/intent.js +97 -0
  49. package/dist/src/layouts/intents/rebalanceIntent.d.ts +212 -0
  50. package/dist/src/layouts/intents/rebalanceIntent.js +94 -0
  51. package/dist/src/layouts/lookupTable.d.ts +7 -0
  52. package/dist/src/layouts/lookupTable.js +10 -0
  53. package/dist/src/layouts/oracle.d.ts +63 -0
  54. package/dist/src/layouts/oracle.js +96 -0
  55. package/dist/src/states/basket.d.ts +14 -0
  56. package/dist/src/states/basket.js +479 -0
  57. package/dist/src/states/config.d.ts +3 -0
  58. package/dist/src/states/config.js +71 -0
  59. package/dist/src/states/intents/intent.d.ts +10 -0
  60. package/dist/src/states/intents/intent.js +316 -0
  61. package/dist/src/states/intents/rebalanceIntent.d.ts +42 -0
  62. package/dist/src/states/intents/rebalanceIntent.js +680 -0
  63. package/dist/src/states/oracles/constants.d.ts +9 -0
  64. package/dist/src/states/oracles/constants.js +15 -0
  65. package/dist/src/states/oracles/oracle.d.ts +24 -0
  66. package/dist/src/states/oracles/oracle.js +168 -0
  67. package/dist/src/states/oracles/pythOracle.d.ts +132 -0
  68. package/dist/src/states/oracles/pythOracle.js +609 -0
  69. package/dist/src/states/oracles/raydiumClmmOracle.d.ts +184 -0
  70. package/dist/src/states/oracles/raydiumClmmOracle.js +843 -0
  71. package/dist/src/states/oracles/raydiumCpmmOracle.d.ts +120 -0
  72. package/dist/src/states/oracles/raydiumCpmmOracle.js +540 -0
  73. package/dist/src/states/oracles/switchboardOracle.d.ts +0 -0
  74. package/dist/src/states/oracles/switchboardOracle.js +1 -0
  75. package/dist/src/states/withdrawBasketFees.d.ts +10 -0
  76. package/dist/src/states/withdrawBasketFees.js +154 -0
  77. package/dist/src/txUtils.d.ts +65 -0
  78. package/dist/src/txUtils.js +306 -0
  79. package/dist/test.d.ts +1 -0
  80. package/dist/test.js +561 -0
  81. package/package.json +31 -0
  82. package/src/constants.ts +40 -0
  83. package/src/index.ts +2431 -0
  84. package/src/instructions/automation/auction.ts +55 -0
  85. package/src/instructions/automation/claimBounty.ts +69 -0
  86. package/src/instructions/automation/flashSwap.ts +104 -0
  87. package/src/instructions/automation/priceUpdate.ts +117 -0
  88. package/src/instructions/automation/rebalanceIntent.ts +181 -0
  89. package/src/instructions/management/addBounty.ts +55 -0
  90. package/src/instructions/management/admin.ts +72 -0
  91. package/src/instructions/management/claimFees.ts +129 -0
  92. package/src/instructions/management/createBasket.ts +138 -0
  93. package/src/instructions/management/edit.ts +602 -0
  94. package/src/instructions/management/luts.ts +157 -0
  95. package/src/instructions/pda.ts +151 -0
  96. package/src/instructions/user/deposit.ts +143 -0
  97. package/src/instructions/user/withdraw.ts +53 -0
  98. package/src/jup.ts +113 -0
  99. package/src/keeperMonitor.ts +585 -0
  100. package/src/layouts/basket.ts +233 -0
  101. package/src/layouts/config.ts +576 -0
  102. package/src/layouts/fraction.ts +164 -0
  103. package/src/layouts/intents/bounty.ts +35 -0
  104. package/src/layouts/intents/intent.ts +324 -0
  105. package/src/layouts/intents/rebalanceIntent.ts +306 -0
  106. package/src/layouts/lookupTable.ts +14 -0
  107. package/src/layouts/oracle.ts +157 -0
  108. package/src/states/basket.ts +527 -0
  109. package/src/states/config.ts +62 -0
  110. package/src/states/intents/intent.ts +311 -0
  111. package/src/states/intents/rebalanceIntent.ts +751 -0
  112. package/src/states/oracles/constants.ts +13 -0
  113. package/src/states/oracles/oracle.ts +212 -0
  114. package/src/states/oracles/pythOracle.ts +874 -0
  115. package/src/states/oracles/raydiumClmmOracle.ts +1193 -0
  116. package/src/states/oracles/raydiumCpmmOracle.ts +784 -0
  117. package/src/states/oracles/switchboardOracle.ts +0 -0
  118. package/src/states/withdrawBasketFees.ts +160 -0
  119. package/src/txUtils.ts +424 -0
  120. package/test.ts +609 -0
  121. package/tsconfig.json +101 -0
@@ -0,0 +1,129 @@
1
+ import {
2
+ ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID
3
+ } from '@solana/spl-token';
4
+ import { PublicKey, SystemProgram, TransactionInstruction } from '@solana/web3.js';
5
+
6
+ import { BASKETS_V3_PROGRAM_ID } from '../../constants';
7
+ import {
8
+ getAta, getBasketFeesPda, getBasketState, getGlobalConfigPda, getWithdrawBasketFeesPda
9
+ } from '../pda';
10
+
11
+ const WITHDRAW_FEES_DISCRIMINATOR = Buffer.from([159, 222, 146, 66, 254, 108, 55, 51]);
12
+
13
+ const CLAIM_FEE_TOKENS_FROM_BASKET_DISCRIMINATOR = Buffer.from([53, 109, 220, 141, 193, 193, 13, 32]);
14
+
15
+ export function withdrawFeesIx(params: {
16
+ claimer: PublicKey,
17
+ basketTokenMint: PublicKey,
18
+ feeType: number,
19
+ }): TransactionInstruction {
20
+ let { claimer, basketTokenMint, feeType } = params;
21
+ let basket = getBasketState(basketTokenMint);
22
+ let withdrawBasketFees = getWithdrawBasketFeesPda(basket, feeType);
23
+ let basketFeesWallet = getBasketFeesPda(basket);
24
+ let basketFeesTokenAccount = getAta(basketFeesWallet, basketTokenMint);
25
+ let globalConfig = getGlobalConfigPda();
26
+
27
+ const discriminator = WITHDRAW_FEES_DISCRIMINATOR;
28
+ const args = Buffer.from([feeType]);
29
+ const data = Buffer.concat([discriminator, args]);
30
+
31
+ const keys = [
32
+ { pubkey: claimer, isWritable: true, isSigner: true },
33
+ { pubkey: basket, isWritable: true, isSigner: false },
34
+ { pubkey: withdrawBasketFees, isWritable: true, isSigner: false },
35
+ { pubkey: basketTokenMint, isWritable: true, isSigner: false },
36
+ { pubkey: basketFeesWallet, isWritable: true, isSigner: false },
37
+ { pubkey: basketFeesTokenAccount, isWritable: true, isSigner: false },
38
+ { pubkey: globalConfig, isWritable: false, isSigner: false },
39
+ { pubkey: SystemProgram.programId, isWritable: false, isSigner: false },
40
+ { pubkey: TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
41
+ { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
42
+ ];
43
+
44
+ return new TransactionInstruction({
45
+ keys,
46
+ programId: BASKETS_V3_PROGRAM_ID,
47
+ data,
48
+ });
49
+ }
50
+
51
+ export function claimFeeTokensFromBasketIx(params: {
52
+ signer: PublicKey,
53
+ basket: PublicKey,
54
+ withdrawBasketFees: PublicKey,
55
+ rentPayer: PublicKey,
56
+ owners: PublicKey[],
57
+ tokenMints: PublicKey[],
58
+ }): TransactionInstruction {
59
+ let { signer, basket, withdrawBasketFees, rentPayer, owners, tokenMints } = params;
60
+ let numOwners = owners.length;
61
+
62
+ const discriminator = CLAIM_FEE_TOKENS_FROM_BASKET_DISCRIMINATOR;
63
+ const args = Buffer.from([numOwners]);
64
+ const data = Buffer.concat([discriminator, args]);
65
+
66
+ const keys = [
67
+ { pubkey: signer, isWritable: true, isSigner: true },
68
+ { pubkey: basket, isWritable: true, isSigner: false },
69
+ { pubkey: withdrawBasketFees, isWritable: true, isSigner: false },
70
+ { pubkey: rentPayer, isWritable: true, isSigner: false },
71
+ { pubkey: SystemProgram.programId, isWritable: false, isSigner: false },
72
+ { pubkey: TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
73
+ { pubkey: TOKEN_2022_PROGRAM_ID, isWritable: false, isSigner: false },
74
+ { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
75
+ ];
76
+
77
+ // Remaining accounts: for each token: (mint, basketAta, claimer1Ata, claimer2Ata, ...)
78
+ for (let i = 0; i < tokenMints.length; i++) {
79
+ const mint = tokenMints[i];
80
+ const basketAta = getAta(basket, mint);
81
+ const claimerATAs = owners.map(owner => getAta(owner, mint));
82
+ keys.push({ pubkey: mint, isWritable: false, isSigner: false });
83
+ keys.push({ pubkey: basketAta, isWritable: true, isSigner: false });
84
+
85
+ for (let j = 0; j < numOwners; j++) {
86
+ keys.push({ pubkey: claimerATAs[j], isWritable: true, isSigner: false });
87
+ }
88
+ }
89
+
90
+ return new TransactionInstruction({
91
+ keys,
92
+ programId: BASKETS_V3_PROGRAM_ID,
93
+ data,
94
+ });
95
+ }
96
+
97
+ export function claimFeeTokensFromBasketIxs(
98
+ signer: PublicKey,
99
+ basket: PublicKey,
100
+ withdrawBasketFees: PublicKey,
101
+ rentPayer: PublicKey,
102
+ owners: PublicKey[],
103
+ tokenMints: PublicKey[],
104
+ ): TransactionInstruction[] {
105
+ if (owners.length === 0 || tokenMints.length === 0) return [];
106
+
107
+ // Account limit: 8 fixed accounts + (owners + 2) * number_of_mints <= 30
108
+ // So: (owners + 2) * number_of_mints <= 24
109
+ // Max tokens per tx: Math.floor(24 / (owners.length + 2))
110
+ const accountsPerToken = owners.length + 2; // mint, basketAta, and one account per owner
111
+ const maxRemainingAccounts = 24; // 30 - 8 fixed accounts
112
+ const maxTokensPerTx = Math.floor(maxRemainingAccounts / accountsPerToken);
113
+
114
+ let ixs: TransactionInstruction[] = [];
115
+
116
+ for (let i = 0; i < tokenMints.length; i += maxTokensPerTx) {
117
+ const batchTokenMints = tokenMints.slice(i, i + maxTokensPerTx);
118
+ ixs.push(claimFeeTokensFromBasketIx({
119
+ signer: signer,
120
+ basket: basket,
121
+ withdrawBasketFees: withdrawBasketFees,
122
+ rentPayer: rentPayer,
123
+ owners: owners,
124
+ tokenMints: batchTokenMints,
125
+ }));
126
+ }
127
+
128
+ return ixs;
129
+ }
@@ -0,0 +1,138 @@
1
+ import BN from 'bn.js';
2
+ import {
3
+ ASSOCIATED_TOKEN_PROGRAM_ID,
4
+ TOKEN_PROGRAM_ID
5
+ } from '@solana/spl-token';
6
+ import {
7
+ PublicKey, SYSVAR_RENT_PUBKEY, TransactionInstruction, SystemProgram
8
+ } from '@solana/web3.js';
9
+
10
+ import {
11
+ ADDRESS_LOOKUP_TABLE_PROGRAM_ID,
12
+ BASKETS_V3_PROGRAM_ID,
13
+ METADATA_PROGRAM_ID,
14
+ MINTS,
15
+ PYTHNET_CUSTODY_PRICE_USDC_ACCOUNT,
16
+ PYTHNET_CUSTODY_PRICE_WSOL_ACCOUNT,
17
+ } from '../../constants';
18
+ import { Fraction } from '../../layouts/fraction';
19
+ import { getAta, getGlobalConfigPda, getLookupTableAccount, getMetadataAccount, getRentPayerPda, serializeString } from '../pda';
20
+ import { HostFees, HostFeesLayout, MetadataParams } from '../../layouts/config';
21
+
22
+
23
+ const CREATE_BASKET_STATE_ACCOUNT_DISCRIMINATOR = Buffer.from([119, 105, 241, 40, 193, 2, 32, 12]);
24
+ const RESIZE_BASKET_STATE_DISCRIMINATOR = Uint8Array.from([103, 216, 111, 212, 45, 172, 125, 84]);
25
+ const CREATE_BASKET_DISCRIMINATOR = Buffer.from([175, 138, 181, 18, 46, 58, 146, 159]);
26
+
27
+
28
+ export function createBasketStateAccountIx(params: {
29
+ creator: PublicKey;
30
+ basket: PublicKey;
31
+ }): TransactionInstruction {
32
+
33
+ let { creator, basket } = params;
34
+ let rentPayerPda = getRentPayerPda();
35
+
36
+ const data = Buffer.concat([
37
+ CREATE_BASKET_STATE_ACCOUNT_DISCRIMINATOR,
38
+ ]);
39
+
40
+ const keys = [
41
+ { pubkey: creator, isSigner: true, isWritable: true },
42
+ { pubkey: basket, isSigner: false, isWritable: true },
43
+ { pubkey: rentPayerPda, isSigner: false, isWritable: true },
44
+ { pubkey: getGlobalConfigPda(), isSigner: false, isWritable: false },
45
+ { pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false },
46
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
47
+ ];
48
+
49
+ return new TransactionInstruction({
50
+ keys,
51
+ programId: BASKETS_V3_PROGRAM_ID,
52
+ data,
53
+ });
54
+ }
55
+
56
+ export function resizeBasketStateIx(params: {
57
+ basket: PublicKey;
58
+ }): TransactionInstruction {
59
+ let { basket } = params;
60
+ const data = Buffer.concat([
61
+ RESIZE_BASKET_STATE_DISCRIMINATOR,
62
+ ]);
63
+
64
+ const keys = [
65
+ { pubkey: basket, isSigner: false, isWritable: true },
66
+ ];
67
+
68
+ return new TransactionInstruction({
69
+ keys,
70
+ programId: BASKETS_V3_PROGRAM_ID,
71
+ data,
72
+ });
73
+ }
74
+
75
+ export function createBasketIx(params: {
76
+ basket: PublicKey,
77
+ mint: PublicKey,
78
+ slot: number,
79
+ creator: PublicKey,
80
+ host: PublicKey,
81
+ startPrice: Fraction,
82
+ hostFees: HostFees, // [u16; 4]
83
+ metadataParams: MetadataParams,
84
+ network: "devnet" | "mainnet",
85
+ }): TransactionInstruction {
86
+ let { basket, mint, slot, creator, host, startPrice, hostFees, metadataParams } = params;
87
+
88
+ let metadataAccount = getMetadataAccount(mint);
89
+
90
+ let lookupTable0 = getLookupTableAccount(basket, slot);
91
+ let lookupTable1 = getLookupTableAccount(basket, slot - 1);
92
+
93
+ let wsolBasketTokenAccount = getAta(basket, MINTS[params.network].WSOL);
94
+ let usdcBasketTokenAccount = getAta(basket, MINTS[params.network].USDC);
95
+
96
+ const hostFeesBuffer = Buffer.alloc(HostFeesLayout.span);
97
+ HostFeesLayout.encode(hostFees, hostFeesBuffer);
98
+
99
+ const data = Buffer.concat([
100
+ CREATE_BASKET_DISCRIMINATOR,
101
+ Buffer.from(new BN(slot).toArray("le", 8)),
102
+ host.toBuffer(),
103
+ Buffer.from(startPrice.high.toArray("le", 8)),
104
+ Buffer.from(startPrice.low.toArray("le", 8)),
105
+ hostFeesBuffer,
106
+ serializeString(metadataParams.name),
107
+ serializeString(metadataParams.symbol),
108
+ serializeString(metadataParams.uri),
109
+ ]);
110
+
111
+ const keys = [
112
+ { pubkey: creator, isSigner: true, isWritable: true },
113
+ { pubkey: basket, isSigner: false, isWritable: true },
114
+ { pubkey: mint, isSigner: false, isWritable: true },
115
+ { pubkey: metadataAccount, isSigner: false, isWritable: true },
116
+ { pubkey: lookupTable0, isSigner: false, isWritable: true },
117
+ { pubkey: lookupTable1, isSigner: false, isWritable: true },
118
+ { pubkey: wsolBasketTokenAccount, isSigner: false, isWritable: true },
119
+ { pubkey: MINTS[params.network].WSOL, isSigner: false, isWritable: true },
120
+ { pubkey: PYTHNET_CUSTODY_PRICE_WSOL_ACCOUNT, isSigner: false, isWritable: true },
121
+ { pubkey: usdcBasketTokenAccount, isSigner: false, isWritable: true },
122
+ { pubkey: MINTS[params.network].USDC, isSigner: false, isWritable: true },
123
+ { pubkey: PYTHNET_CUSTODY_PRICE_USDC_ACCOUNT, isSigner: false, isWritable: true },
124
+ { pubkey: getGlobalConfigPda(), isSigner: false, isWritable: true },
125
+ { pubkey: ADDRESS_LOOKUP_TABLE_PROGRAM_ID, isSigner: false, isWritable: false },
126
+ { pubkey: METADATA_PROGRAM_ID, isSigner: false, isWritable: false },
127
+ { pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false },
128
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
129
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
130
+ { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
131
+ ];
132
+
133
+ return new TransactionInstruction({
134
+ keys,
135
+ programId: BASKETS_V3_PROGRAM_ID,
136
+ data,
137
+ });
138
+ }