@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,55 @@
1
+ import {
2
+ ASSOCIATED_TOKEN_PROGRAM_ID,
3
+ TOKEN_2022_PROGRAM_ID,
4
+ TOKEN_PROGRAM_ID
5
+ } from '@solana/spl-token';
6
+ import { PublicKey, TransactionInstruction } from '@solana/web3.js';
7
+ import { BASKETS_V3_PROGRAM_ID } from '../../constants';
8
+ import { SystemProgram } from '@solana/web3.js';
9
+ import { getAta, getBountyVaultPda, getGlobalConfigPda, getRebalanceIntentPda, getRentPayerPda } from '../pda';
10
+
11
+
12
+ const CREATE_AUCTION_DISCRIMINATOR = Buffer.from([50, 37, 7, 103, 80, 100, 162, 13]);
13
+
14
+ export function createAuctionIx(params: {
15
+ keeper: PublicKey,
16
+ basket: PublicKey,
17
+ bountyMint: PublicKey,
18
+ }): TransactionInstruction {
19
+ const { keeper, basket, bountyMint } = params;
20
+ let bountyVault = getBountyVaultPda();
21
+
22
+ let bountyVaultAta = getAta(bountyMint, bountyVault);
23
+ let rebalanceIntent = getRebalanceIntentPda(basket, basket);
24
+
25
+ let rentPayerPda = getRentPayerPda();
26
+
27
+ let globalConfig = getGlobalConfigPda();
28
+
29
+ let keeperBountyATA = getAta(keeper, bountyMint);
30
+
31
+ const data = CREATE_AUCTION_DISCRIMINATOR;
32
+
33
+ const keys = [
34
+ { pubkey: keeper, isWritable: true, isSigner: true },
35
+ { pubkey: basket, isWritable: true, isSigner: false },
36
+ { pubkey: rebalanceIntent, isWritable: true, isSigner: false },
37
+ { pubkey: rentPayerPda, isWritable: true, isSigner: false },
38
+ { pubkey: globalConfig, isWritable: false, isSigner: false },
39
+ { pubkey: bountyMint, isWritable: false, isSigner: false },
40
+ { pubkey: keeperBountyATA, isWritable: true, isSigner: false },
41
+ { pubkey: bountyVault, isWritable: true, isSigner: false },
42
+ { pubkey: bountyVaultAta, isWritable: true, isSigner: false },
43
+ { pubkey: SystemProgram.programId, isWritable: false, isSigner: false },
44
+ { pubkey: TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
45
+ { pubkey: TOKEN_2022_PROGRAM_ID, isWritable: false, isSigner: false },
46
+ { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
47
+ { pubkey: rebalanceIntent, isWritable: true, isSigner: false }
48
+ ];
49
+
50
+ return new TransactionInstruction({
51
+ keys,
52
+ programId: BASKETS_V3_PROGRAM_ID,
53
+ data,
54
+ });
55
+ }
@@ -0,0 +1,69 @@
1
+ import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
2
+ import { SystemProgram, TransactionInstruction } from "@solana/web3.js";
3
+ import { PublicKey } from "@solana/web3.js";
4
+ import { getAta, getBountyVaultPda, getGlobalConfigPda } from "../pda";
5
+ import { BASKETS_V3_PROGRAM_ID } from "../../constants";
6
+
7
+
8
+ export const CLAIM_BOUNTY_HANDLER_DISCRIMINATOR = Buffer.from([13, 252, 98, 119, 169, 40, 250, 254]);
9
+
10
+ export function claimBountyIx(params: {
11
+ keeper: PublicKey;
12
+ basket: PublicKey;
13
+ intent: PublicKey;
14
+ bountyMint: PublicKey;
15
+ bountyDepositor: PublicKey;
16
+ rentPayer: PublicKey;
17
+ keepers: PublicKey[];
18
+ }): TransactionInstruction {
19
+ const {
20
+ keeper,
21
+ basket,
22
+ intent,
23
+ bountyMint,
24
+ bountyDepositor,
25
+ rentPayer,
26
+ keepers
27
+ } = params;
28
+
29
+
30
+ let bountyVault = getBountyVaultPda();
31
+
32
+ let globalConfig = getGlobalConfigPda();
33
+
34
+ let keeperBountyAta = getAta(keeper, bountyMint);
35
+ let basketBountyAta = getAta(basket, bountyMint);
36
+
37
+ let bountyVaultAta = getAta(bountyVault, bountyMint);
38
+ let bountyDepositorAta = getAta(bountyDepositor, bountyMint);
39
+
40
+ const data = CLAIM_BOUNTY_HANDLER_DISCRIMINATOR;
41
+
42
+ const keys = [
43
+ { pubkey: keeper, isSigner: true, isWritable: true },
44
+ { pubkey: basket, isSigner: false, isWritable: true },
45
+ { pubkey: intent, isSigner: false, isWritable: true },
46
+ { pubkey: bountyMint, isSigner: false, isWritable: false },
47
+ { pubkey: keeperBountyAta, isSigner: false, isWritable: true },
48
+ { pubkey: basketBountyAta, isSigner: false, isWritable: true },
49
+ { pubkey: bountyVault, isSigner: false, isWritable: true },
50
+ { pubkey: bountyVaultAta, isSigner: false, isWritable: true },
51
+ { pubkey: bountyDepositorAta, isSigner: false, isWritable: true },
52
+ { pubkey: rentPayer, isSigner: false, isWritable: true },
53
+ { pubkey: globalConfig, isSigner: false, isWritable: false },
54
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
55
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
56
+ ];
57
+
58
+ keepers.forEach((keeperPubkey) => {
59
+ keys.push({ pubkey: keeperPubkey, isWritable: true, isSigner: false });
60
+ const remKeeperATA = getAta(keeperPubkey, bountyMint);
61
+ keys.push({ pubkey: remKeeperATA, isWritable: true, isSigner: false });
62
+ });
63
+
64
+ return new TransactionInstruction({
65
+ keys,
66
+ programId: BASKETS_V3_PROGRAM_ID,
67
+ data,
68
+ });
69
+ }
@@ -0,0 +1,104 @@
1
+ import BN from 'bn.js';
2
+ import { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token';
3
+ import { PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY, TransactionInstruction } from '@solana/web3.js';
4
+
5
+ import { BASKETS_V3_PROGRAM_ID } from '../../constants';
6
+ import { getAta, getGlobalConfigPda } from '../pda';
7
+
8
+ const FLASH_WITHDRAW_DISCRIMINATOR = Buffer.from([164, 84, 46, 132, 94, 220, 214, 156]);
9
+ const FLASH_DEPOSIT_DISCRIMINATOR = Buffer.from([21, 4, 89, 84, 131, 84, 128, 21]);
10
+
11
+ export function flashWithdrawIx(params: {
12
+ keeper: PublicKey;
13
+ basket: PublicKey;
14
+ rebalanceIntent?: PublicKey;
15
+ intent?: PublicKey;
16
+ mintIn: PublicKey;
17
+ mintOut: PublicKey;
18
+ amountIn: BN;
19
+ amountOut: BN;
20
+ mode?: number;
21
+ }): TransactionInstruction {
22
+
23
+ const { keeper, basket, mintIn, mintOut, amountIn, amountOut, mode } = params;
24
+
25
+ let keeperFromATA = getAta(keeper, mintIn);
26
+ let keeperToATA = getAta(keeper, mintOut);
27
+ let basketInATA = getAta(basket, mintIn);
28
+ let basketOutATA = getAta(basket, mintOut);
29
+
30
+ const keys = [
31
+ { pubkey: params.keeper, isWritable: true, isSigner: true },
32
+ { pubkey: params.basket, isWritable: true, isSigner: false },
33
+ { pubkey: params.rebalanceIntent ?? BASKETS_V3_PROGRAM_ID, isWritable: params.rebalanceIntent ? true : false, isSigner: false },
34
+ { pubkey: params.intent ?? BASKETS_V3_PROGRAM_ID, isWritable: params.intent ? true : false, isSigner: false },
35
+ { pubkey: params.mintIn, isWritable: false, isSigner: false },
36
+ { pubkey: params.mintOut, isWritable: false, isSigner: false },
37
+ { pubkey: keeperFromATA, isWritable: true, isSigner: false },
38
+ { pubkey: keeperToATA, isWritable: true, isSigner: false },
39
+ { pubkey: basketInATA, isWritable: true, isSigner: false },
40
+ { pubkey: basketOutATA, isWritable: true, isSigner: false },
41
+ { pubkey: getGlobalConfigPda(), isWritable: false, isSigner: false },
42
+ { pubkey: SYSVAR_INSTRUCTIONS_PUBKEY, isWritable: false, isSigner: false },
43
+ { pubkey: TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
44
+ { pubkey: TOKEN_2022_PROGRAM_ID, isWritable: false, isSigner: false },
45
+ ];
46
+
47
+ const discriminator = FLASH_WITHDRAW_DISCRIMINATOR;
48
+
49
+ const amountInBuffer = Buffer.from(amountIn.toArray("le", 8));
50
+ const amountOutBuffer = Buffer.from(amountOut.toArray("le", 8));
51
+ const modeBuffer = Buffer.from([mode ?? 0]);
52
+
53
+ const data = Buffer.concat([discriminator, amountInBuffer, amountOutBuffer, modeBuffer]);
54
+
55
+ return new TransactionInstruction({
56
+ keys,
57
+ programId: BASKETS_V3_PROGRAM_ID,
58
+ data,
59
+ });
60
+ }
61
+
62
+ export function flashDepositIx(params: {
63
+ keeper: PublicKey;
64
+ basket: PublicKey;
65
+ rebalanceIntent?: PublicKey;
66
+ intent?: PublicKey;
67
+ mintIn: PublicKey;
68
+ mintOut: PublicKey;
69
+ }): TransactionInstruction {
70
+ const { keeper, basket, mintIn, mintOut } = params;
71
+
72
+ let keeperFromATA = getAta(keeper, mintIn);
73
+ let keeperToATA = getAta(keeper, mintOut);
74
+ let basketInATA = getAta(basket, mintIn);
75
+ let basketOutATA = getAta(basket, mintOut);
76
+
77
+ const keys = [
78
+ { pubkey: params.keeper, isWritable: true, isSigner: true },
79
+ { pubkey: params.basket, isWritable: true, isSigner: false },
80
+ { pubkey: params.rebalanceIntent ? params.rebalanceIntent : BASKETS_V3_PROGRAM_ID, isWritable: params.rebalanceIntent ? true : false, isSigner: false },
81
+ { pubkey: params.intent ? params.intent : BASKETS_V3_PROGRAM_ID, isWritable: params.intent ? true : false, isSigner: false },
82
+ { pubkey: params.mintIn, isWritable: false, isSigner: false },
83
+ { pubkey: params.mintOut, isWritable: false, isSigner: false },
84
+ { pubkey: keeperFromATA, isWritable: true, isSigner: false },
85
+ { pubkey: keeperToATA, isWritable: true, isSigner: false },
86
+ { pubkey: basketInATA, isWritable: true, isSigner: false },
87
+ { pubkey: basketOutATA, isWritable: true, isSigner: false },
88
+ { pubkey: getGlobalConfigPda(), isWritable: false, isSigner: false },
89
+ { pubkey: SYSVAR_INSTRUCTIONS_PUBKEY, isWritable: false, isSigner: false },
90
+ { pubkey: TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
91
+ { pubkey: TOKEN_2022_PROGRAM_ID, isWritable: false, isSigner: false },
92
+ ];
93
+
94
+ const discriminator = FLASH_DEPOSIT_DISCRIMINATOR;
95
+
96
+
97
+ const data = Buffer.concat([discriminator]);
98
+
99
+ return new TransactionInstruction({
100
+ keys,
101
+ programId: BASKETS_V3_PROGRAM_ID,
102
+ data,
103
+ });
104
+ }
@@ -0,0 +1,117 @@
1
+ import { PublicKey, TransactionInstruction } from '@solana/web3.js';
2
+
3
+ import {
4
+ BASKETS_V3_PROGRAM_ID, PYTHNET_CUSTODY_PRICE_USDC_ACCOUNT, PYTHNET_CUSTODY_PRICE_WSOL_ACCOUNT
5
+ } from '../../constants';
6
+ import { OraclePriceLayout, OraclePriceOnChain } from '../../layouts/oracle';
7
+ import { getAta, getBasketFeesPda, getGlobalConfigPda, getRebalanceIntentPda } from '../pda';
8
+ import BN from 'bn.js';
9
+ import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
10
+
11
+ const UPDATE_TOKEN_PRICES_DISCRIMINATOR = Buffer.from([147, 87, 140, 33, 214, 189, 181, 242]);
12
+ const UPDATE_TOKEN_PRICES_CUSTOM_DISCRIMINATOR = Buffer.from([71, 100, 35, 136, 116, 239, 54, 126]);
13
+
14
+
15
+ export function updateTokenPricesIx(params: {
16
+ keeper: PublicKey,
17
+ basket: PublicKey,
18
+ rebalanceIntent: PublicKey,
19
+ basketRebalanceIntent?: PublicKey,
20
+ lookupTable0: PublicKey,
21
+ lookupTable1: PublicKey,
22
+ tokenIndices: number[], // length 20
23
+ additionalOracleAccounts: PublicKey[],
24
+ basketMint?: PublicKey,
25
+ }): TransactionInstruction {
26
+
27
+
28
+ let globalConfig = getGlobalConfigPda();
29
+
30
+ const tokenIndices = params.tokenIndices.slice(0, 20);
31
+ while (tokenIndices.length < 20) {
32
+ tokenIndices.push(0);
33
+ }
34
+
35
+ const data = Buffer.concat([
36
+ Buffer.from(UPDATE_TOKEN_PRICES_DISCRIMINATOR), // 8 bytes
37
+ Buffer.from(tokenIndices)
38
+ ]);
39
+
40
+ const keys = [
41
+ { pubkey: params.keeper, isSigner: true, isWritable: true },
42
+ { pubkey: params.basket, isSigner: false, isWritable: true },
43
+ { pubkey: params.rebalanceIntent, isSigner: false, isWritable: true },
44
+ { pubkey: globalConfig, isSigner: false, isWritable: false },
45
+ { pubkey: PYTHNET_CUSTODY_PRICE_WSOL_ACCOUNT, isSigner: false, isWritable: true },
46
+ { pubkey: PYTHNET_CUSTODY_PRICE_USDC_ACCOUNT, isSigner: false, isWritable: true },
47
+ { pubkey: params.lookupTable0, isSigner: false, isWritable: true },
48
+ { pubkey: params.lookupTable1, isSigner: false, isWritable: true },
49
+ { pubkey: params.basketRebalanceIntent ?? BASKETS_V3_PROGRAM_ID, isSigner: false, isWritable: params.basketRebalanceIntent ? true : false },
50
+ ];
51
+
52
+ // remaining accounts
53
+
54
+ keys.push(...params.additionalOracleAccounts.map((pubkey) => ({ pubkey, isSigner: false, isWritable: false })));
55
+
56
+ if (params.basketMint) {
57
+ let basketFeesWallet = getBasketFeesPda(params.basket);
58
+ let basketFeesTokenAccount = getAta(basketFeesWallet, params.basketMint);
59
+ keys.push({ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false });
60
+ keys.push({ pubkey: params.basketMint, isSigner: false, isWritable: true });
61
+ keys.push({ pubkey: basketFeesTokenAccount, isSigner: false, isWritable: true });
62
+ }
63
+
64
+ return new TransactionInstruction({
65
+ keys,
66
+ programId: BASKETS_V3_PROGRAM_ID,
67
+ data
68
+ });
69
+ }
70
+
71
+ export function updateTokenPricesCustomIx(params: {
72
+ manager: PublicKey,
73
+ basket: PublicKey,
74
+ tokenIndices: number[], // length 10
75
+ tokenPrices: OraclePriceOnChain[] // length 10
76
+ }): TransactionInstruction {
77
+ const { manager, basket } = params;
78
+ const globalConfig = getGlobalConfigPda();
79
+ const rebalanceIntent = getRebalanceIntentPda(basket, manager);
80
+
81
+ const tokenIndices = params.tokenIndices.slice(0, 10);
82
+ while (tokenIndices.length < 10) tokenIndices.push(0);
83
+
84
+ const tokenPrices = params.tokenPrices.slice(0, 10);
85
+ while (tokenPrices.length < 10) {
86
+ tokenPrices.push({
87
+ price: { high: new BN(0), low: new BN(0) },
88
+ conf: { high: new BN(0), low: new BN(0) },
89
+ updateTime: new BN(0),
90
+ });
91
+ }
92
+
93
+ const pricesBufs = tokenPrices.map((p) => {
94
+ const buf = Buffer.alloc(OraclePriceLayout.span);
95
+ OraclePriceLayout.encode(p, buf);
96
+ return buf;
97
+ });
98
+
99
+ const data = Buffer.concat([
100
+ Buffer.from(UPDATE_TOKEN_PRICES_CUSTOM_DISCRIMINATOR),
101
+ Buffer.from(tokenIndices),
102
+ ...pricesBufs,
103
+ ]);
104
+
105
+ const keys = [
106
+ { pubkey: manager, isSigner: true, isWritable: true },
107
+ { pubkey: basket, isSigner: false, isWritable: true },
108
+ { pubkey: rebalanceIntent, isSigner: false, isWritable: true },
109
+ { pubkey: globalConfig, isSigner: false, isWritable: false },
110
+ ];
111
+
112
+ return new TransactionInstruction({
113
+ keys,
114
+ programId: BASKETS_V3_PROGRAM_ID,
115
+ data,
116
+ });
117
+ }
@@ -0,0 +1,181 @@
1
+ import BN from 'bn.js';
2
+ import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token';
3
+ import {
4
+ PublicKey, SystemProgram, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RENT_PUBKEY, TransactionInstruction
5
+ } from '@solana/web3.js';
6
+
7
+ import { BASKETS_V3_PROGRAM_ID } from '../../constants';
8
+ import {
9
+ getAta, getBasketFeesPda, getBountyVaultPda, getGlobalConfigPda, getRebalanceIntentPda,
10
+ getRentPayerPda
11
+ } from '../pda';
12
+
13
+ const CREATE_REBALANCE_INTENT_DISCRIMINATOR = Buffer.from([120, 80, 245, 123, 212, 149, 163, 47]);
14
+ const RESIZE_REBALANCE_INTENT_HANDLER = Buffer.from([71, 204, 243, 183, 209, 118, 111, 94]);
15
+ const INIT_REBALANCE_INTENT_DISCRIMINATOR = Buffer.from([127, 215, 41, 110, 244, 179, 131, 7]);
16
+ const CANCEL_REBALANCE_DISCRIMINATOR = Buffer.from([51, 236, 71, 57, 141, 130, 39, 151]);
17
+
18
+
19
+ export function createRebalanceIntentIx(params: {
20
+ signer: PublicKey;
21
+ owner: PublicKey;
22
+ basket: PublicKey;
23
+ }): TransactionInstruction {
24
+ const { signer, owner, basket } = params;
25
+
26
+ const rebalanceIntent = getRebalanceIntentPda(basket, owner);
27
+ const rentPayerPda = getRentPayerPda();
28
+ const globalConfig = getGlobalConfigPda();
29
+
30
+ const keys = [
31
+ { pubkey: signer, isSigner: true, isWritable: true },
32
+ { pubkey: owner, isSigner: false, isWritable: true },
33
+ { pubkey: basket, isSigner: false, isWritable: true },
34
+ { pubkey: rebalanceIntent, isSigner: false, isWritable: true },
35
+ { pubkey: rentPayerPda, isSigner: false, isWritable: true },
36
+ { pubkey: globalConfig, isSigner: false, isWritable: false },
37
+ { pubkey: SYSVAR_INSTRUCTIONS_PUBKEY, isSigner: false, isWritable: false },
38
+ { pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false },
39
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
40
+ ];
41
+
42
+ return new TransactionInstruction({
43
+ keys,
44
+ programId: BASKETS_V3_PROGRAM_ID,
45
+ data: CREATE_REBALANCE_INTENT_DISCRIMINATOR,
46
+ });
47
+ }
48
+
49
+ export function resizeRebalanceIntentIx(
50
+ rebalanceIntent: PublicKey
51
+ ): TransactionInstruction {
52
+
53
+ const data = RESIZE_REBALANCE_INTENT_HANDLER;
54
+
55
+ const keys = [
56
+ { pubkey: rebalanceIntent, isSigner: false, isWritable: true}
57
+ ];
58
+
59
+ return new TransactionInstruction({
60
+ keys,
61
+ programId: BASKETS_V3_PROGRAM_ID,
62
+ data
63
+ });
64
+ }
65
+
66
+
67
+ export function initRebalanceIntentIx(params: {
68
+ signer: PublicKey,
69
+ owner: PublicKey,
70
+ basket: PublicKey,
71
+ basketTokenMint: PublicKey,
72
+ rebalanceIntentRentPayer: PublicKey,
73
+ bountyMint: PublicKey,
74
+ rebalanceType: number, // u8
75
+ basketRebalanceIntent: PublicKey | undefined,
76
+ rebalanceSlippageBps: number, // u16
77
+ perTradeRebalanceSlippageBps: number, // u16
78
+ executionStartTime: number, // u64
79
+ minBountyAmount: number, // u64
80
+ maxBountyAmount: number, // u64
81
+ withdrawParamsBurnAmount?: number, // u64
82
+ withdrawParamsTokenMintsHash?: number[], // length 32
83
+ withdrawParamsKeepTokensBitmask?: BN, // u128
84
+ withdrawParamsKeepAllTokens?: number, // u8
85
+ }): TransactionInstruction {
86
+ const {
87
+ signer,
88
+ owner,
89
+ basket,
90
+ basketTokenMint,
91
+ rebalanceIntentRentPayer,
92
+ bountyMint,
93
+ rebalanceType,
94
+ rebalanceSlippageBps,
95
+ perTradeRebalanceSlippageBps,
96
+ executionStartTime,
97
+ minBountyAmount,
98
+ maxBountyAmount,
99
+ withdrawParamsBurnAmount = 0,
100
+ withdrawParamsTokenMintsHash = new Array(32).fill(0),
101
+ withdrawParamsKeepTokensBitmask = new BN(0),
102
+ withdrawParamsKeepAllTokens = 0,
103
+ basketRebalanceIntent,
104
+ } = params;
105
+
106
+ const rebalanceIntent = getRebalanceIntentPda(basket, owner);
107
+ const rentPayerPda = getRentPayerPda();
108
+ const globalConfig = getGlobalConfigPda();
109
+ const bountyVault = getBountyVaultPda();
110
+ const basketFeesPda = getBasketFeesPda(basket);
111
+
112
+ const signerBasketAta = getAta(signer, basketTokenMint);
113
+ const signerBountyAta = getAta(signer, bountyMint);
114
+ const bountyVaultAta = getAta(bountyVault, bountyMint);
115
+ const basketFeesAta = getAta(basketFeesPda, basketTokenMint);
116
+
117
+ const data = Buffer.concat([
118
+ INIT_REBALANCE_INTENT_DISCRIMINATOR,
119
+ rebalanceIntentRentPayer.toBuffer(),
120
+ Buffer.from([rebalanceType]),
121
+ Buffer.from(new BN(rebalanceSlippageBps).toArray("le", 2)),
122
+ Buffer.from(new BN(perTradeRebalanceSlippageBps).toArray("le", 2)),
123
+ Buffer.from(new BN(executionStartTime).toArray("le", 8)),
124
+ Buffer.from(new BN(minBountyAmount).toArray("le", 8)),
125
+ Buffer.from(new BN(maxBountyAmount).toArray("le", 8)),
126
+ Buffer.from(new BN(withdrawParamsBurnAmount).toArray("le", 8)),
127
+ Buffer.from(withdrawParamsTokenMintsHash),
128
+ Buffer.from(withdrawParamsKeepTokensBitmask.toArray("le", 16)),
129
+ Buffer.from([withdrawParamsKeepAllTokens]),
130
+ ]);
131
+
132
+ const keys = [
133
+ { pubkey: signer, isSigner: true, isWritable: true },
134
+ { pubkey: owner, isSigner: false, isWritable: true },
135
+ { pubkey: basket, isSigner: false, isWritable: true },
136
+ { pubkey: rebalanceIntent, isSigner: false, isWritable: true },
137
+ { pubkey: rentPayerPda, isSigner: false, isWritable: true },
138
+ { pubkey: basketTokenMint, isSigner: false, isWritable: true },
139
+ { pubkey: signerBasketAta, isSigner: false, isWritable: true },
140
+ { pubkey: globalConfig, isSigner: false, isWritable: false },
141
+ { pubkey: bountyMint, isSigner: false, isWritable: false },
142
+ { pubkey: signerBountyAta, isSigner: false, isWritable: true },
143
+ { pubkey: bountyVault, isSigner: false, isWritable: true },
144
+ { pubkey: bountyVaultAta, isSigner: false, isWritable: true },
145
+ { pubkey: basketFeesPda, isSigner: false, isWritable: true },
146
+ { pubkey: basketFeesAta, isSigner: false, isWritable: true },
147
+ { pubkey: basketRebalanceIntent ? basketRebalanceIntent : BASKETS_V3_PROGRAM_ID, isSigner: false, isWritable: basketRebalanceIntent ? true : false },
148
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
149
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
150
+ { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
151
+ ];
152
+
153
+ return new TransactionInstruction({
154
+ keys,
155
+ programId: BASKETS_V3_PROGRAM_ID,
156
+ data,
157
+ });
158
+ }
159
+
160
+ export function cancelRebalanceIx(params: {
161
+ keeper: PublicKey,
162
+ basket: PublicKey,
163
+ rebalanceIntent: PublicKey,
164
+ }): TransactionInstruction {
165
+ const { keeper, basket, rebalanceIntent } = params;
166
+
167
+ const globalConfig = getGlobalConfigPda();
168
+
169
+ const keys = [
170
+ { pubkey: keeper, isSigner: true, isWritable: true },
171
+ { pubkey: basket, isSigner: false, isWritable: true },
172
+ { pubkey: rebalanceIntent, isSigner: false, isWritable: true },
173
+ { pubkey: globalConfig, isSigner: false, isWritable: false },
174
+ ];
175
+
176
+ return new TransactionInstruction({
177
+ keys,
178
+ programId: BASKETS_V3_PROGRAM_ID,
179
+ data: CANCEL_REBALANCE_DISCRIMINATOR,
180
+ });
181
+ }
@@ -0,0 +1,55 @@
1
+ import BN from 'bn.js';
2
+ import {
3
+ ASSOCIATED_TOKEN_PROGRAM_ID,
4
+ TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID
5
+ } from '@solana/spl-token';
6
+ import { PublicKey, SystemProgram, TransactionInstruction } from '@solana/web3.js';
7
+ import { BASKETS_V3_PROGRAM_ID } from '../../constants';
8
+ import { getAta, getBountyVaultPda, getGlobalConfigPda } from '../pda';
9
+
10
+ const ADD_BOUNTY_DISCRIMINATOR = Buffer.from([84, 56, 167, 193, 17, 91, 42, 143,]);
11
+
12
+
13
+ export function addBountyIx(params: {
14
+ keeper: PublicKey;
15
+ basket: PublicKey;
16
+ bountyMint: PublicKey;
17
+ amount: number;
18
+ }): TransactionInstruction {
19
+ const {
20
+ keeper,
21
+ basket,
22
+ bountyMint,
23
+ amount,
24
+ } = params;
25
+
26
+ let bountyVault = getBountyVaultPda();
27
+ let globalConfig = getGlobalConfigPda();
28
+ let keeperBountyAta = getAta(keeper, bountyMint);
29
+ let bountyVaultAta = getAta(bountyVault, bountyMint);
30
+
31
+ const data = Buffer.concat([
32
+ ADD_BOUNTY_DISCRIMINATOR,
33
+ Buffer.from(new BN(amount).toArray("le", 8)), // u64 LE
34
+ ]);
35
+
36
+ const keys = [
37
+ { pubkey: keeper, isSigner: true, isWritable: true },
38
+ { pubkey: basket, isSigner: false, isWritable: true },
39
+ { pubkey: bountyMint, isSigner: false, isWritable: false },
40
+ { pubkey: keeperBountyAta, isSigner: false, isWritable: true },
41
+ { pubkey: bountyVault, isSigner: false, isWritable: true },
42
+ { pubkey: bountyVaultAta, isSigner: false, isWritable: true },
43
+ { pubkey: globalConfig, isSigner: false, isWritable: false },
44
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
45
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
46
+ { pubkey: TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },
47
+ { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
48
+ ];
49
+
50
+ return new TransactionInstruction({
51
+ keys,
52
+ programId: BASKETS_V3_PROGRAM_ID,
53
+ data,
54
+ });
55
+ }
@@ -0,0 +1,72 @@
1
+ import {
2
+ PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY, TransactionInstruction
3
+ } from '@solana/web3.js';
4
+ import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token';
5
+ import { BASKETS_V3_PROGRAM_ID } from '../../constants';
6
+ import { GlobalConfig, GlobalConfigLayout } from '../../layouts/config';
7
+ import { getAta, getBountyVaultPda, getGlobalConfigPda } from '../pda';
8
+
9
+
10
+ const CREATE_GLOBAL_CONFIG_DISCRIMINATOR = Buffer.from([62, 50, 47, 241, 153, 49, 252, 239]);
11
+ const EDIT_GLOBAL_CONFIG_DISCRIMINATOR = Buffer.from([209, 246, 241, 219, 204, 153, 103, 175]);
12
+
13
+
14
+ export function createGlobalConfigIx(params: {
15
+ admin: PublicKey;
16
+ }): TransactionInstruction {
17
+ const { admin } = params;
18
+
19
+ let globalConfig = getGlobalConfigPda();
20
+
21
+ const data = CREATE_GLOBAL_CONFIG_DISCRIMINATOR;
22
+
23
+ const keys = [
24
+ { pubkey: admin, isSigner: true, isWritable: true },
25
+ { pubkey: globalConfig, isSigner: false, isWritable: true },
26
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
27
+ { pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false },
28
+ ];
29
+
30
+ return new TransactionInstruction({
31
+ keys,
32
+ programId: BASKETS_V3_PROGRAM_ID,
33
+ data,
34
+ });
35
+ }
36
+
37
+
38
+ export function editGlobalConfigIx( params: {
39
+ signer: PublicKey;
40
+ config: GlobalConfig;
41
+ }): TransactionInstruction {
42
+
43
+ const discriminator = EDIT_GLOBAL_CONFIG_DISCRIMINATOR;
44
+
45
+ let globalConfig = getGlobalConfigPda();
46
+
47
+ const buffer = Buffer.alloc(GlobalConfigLayout.span);
48
+ const len = GlobalConfigLayout.encode(params.config, buffer);
49
+ const data = Buffer.concat([discriminator, buffer.slice(0, len)]);
50
+
51
+ let bountyMint = params.config.bountyMint;
52
+ let bountyVault = getBountyVaultPda();
53
+ let bountyVaultAta = getAta(bountyVault, bountyMint);
54
+
55
+ const keys = [
56
+ { pubkey: params.signer, isSigner: true, isWritable: true },
57
+ { pubkey: globalConfig, isSigner: false, isWritable: true },
58
+ { pubkey: bountyMint, isSigner: false, isWritable: false },
59
+ { pubkey: bountyVault, isSigner: false, isWritable: false },
60
+ { pubkey: bountyVaultAta, isSigner: false, isWritable: true },
61
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
62
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
63
+ { pubkey: TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },
64
+ { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
65
+ ];
66
+
67
+ return new TransactionInstruction({
68
+ keys,
69
+ programId: BASKETS_V3_PROGRAM_ID,
70
+ data,
71
+ });
72
+ }