@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.
- package/dist/src/constants.d.ts +23 -0
- package/dist/src/constants.js +38 -0
- package/dist/src/index.d.ts +804 -0
- package/dist/src/index.js +2097 -0
- package/dist/src/instructions/automation/auction.d.ts +6 -0
- package/dist/src/instructions/automation/auction.js +40 -0
- package/dist/src/instructions/automation/claimBounty.d.ts +12 -0
- package/dist/src/instructions/automation/claimBounty.js +44 -0
- package/dist/src/instructions/automation/flashSwap.d.ts +21 -0
- package/dist/src/instructions/automation/flashSwap.js +74 -0
- package/dist/src/instructions/automation/priceUpdate.d.ts +19 -0
- package/dist/src/instructions/automation/priceUpdate.js +89 -0
- package/dist/src/instructions/automation/rebalanceIntent.d.ts +32 -0
- package/dist/src/instructions/automation/rebalanceIntent.js +117 -0
- package/dist/src/instructions/automation/rebalanceSwap.d.ts +11 -0
- package/dist/src/instructions/automation/rebalanceSwap.js +42 -0
- package/dist/src/instructions/management/addBounty.d.ts +7 -0
- package/dist/src/instructions/management/addBounty.js +41 -0
- package/dist/src/instructions/management/admin.d.ts +9 -0
- package/dist/src/instructions/management/admin.js +53 -0
- package/dist/src/instructions/management/claimFees.d.ts +15 -0
- package/dist/src/instructions/management/claimFees.js +95 -0
- package/dist/src/instructions/management/createBasket.d.ts +21 -0
- package/dist/src/instructions/management/createBasket.js +98 -0
- package/dist/src/instructions/management/edit.d.ts +51 -0
- package/dist/src/instructions/management/edit.js +477 -0
- package/dist/src/instructions/management/luts.d.ts +30 -0
- package/dist/src/instructions/management/luts.js +99 -0
- package/dist/src/instructions/pda.d.ts +25 -0
- package/dist/src/instructions/pda.js +128 -0
- package/dist/src/instructions/user/deposit.d.ts +20 -0
- package/dist/src/instructions/user/deposit.js +100 -0
- package/dist/src/instructions/user/withdraw.d.ts +8 -0
- package/dist/src/instructions/user/withdraw.js +36 -0
- package/dist/src/jup.d.ts +49 -0
- package/dist/src/jup.js +80 -0
- package/dist/src/keeperMonitor.d.ts +52 -0
- package/dist/src/keeperMonitor.js +624 -0
- package/dist/src/layouts/basket.d.ts +191 -0
- package/dist/src/layouts/basket.js +51 -0
- package/dist/src/layouts/config.d.ts +281 -0
- package/dist/src/layouts/config.js +237 -0
- package/dist/src/layouts/fraction.d.ts +20 -0
- package/dist/src/layouts/fraction.js +164 -0
- package/dist/src/layouts/intents/bounty.d.ts +18 -0
- package/dist/src/layouts/intents/bounty.js +19 -0
- package/dist/src/layouts/intents/intent.d.ts +209 -0
- package/dist/src/layouts/intents/intent.js +97 -0
- package/dist/src/layouts/intents/rebalanceIntent.d.ts +212 -0
- package/dist/src/layouts/intents/rebalanceIntent.js +94 -0
- package/dist/src/layouts/lookupTable.d.ts +7 -0
- package/dist/src/layouts/lookupTable.js +10 -0
- package/dist/src/layouts/oracle.d.ts +63 -0
- package/dist/src/layouts/oracle.js +96 -0
- package/dist/src/states/basket.d.ts +14 -0
- package/dist/src/states/basket.js +479 -0
- package/dist/src/states/config.d.ts +3 -0
- package/dist/src/states/config.js +71 -0
- package/dist/src/states/intents/intent.d.ts +10 -0
- package/dist/src/states/intents/intent.js +316 -0
- package/dist/src/states/intents/rebalanceIntent.d.ts +42 -0
- package/dist/src/states/intents/rebalanceIntent.js +680 -0
- package/dist/src/states/oracles/constants.d.ts +9 -0
- package/dist/src/states/oracles/constants.js +15 -0
- package/dist/src/states/oracles/oracle.d.ts +24 -0
- package/dist/src/states/oracles/oracle.js +168 -0
- package/dist/src/states/oracles/pythOracle.d.ts +132 -0
- package/dist/src/states/oracles/pythOracle.js +609 -0
- package/dist/src/states/oracles/raydiumClmmOracle.d.ts +184 -0
- package/dist/src/states/oracles/raydiumClmmOracle.js +843 -0
- package/dist/src/states/oracles/raydiumCpmmOracle.d.ts +120 -0
- package/dist/src/states/oracles/raydiumCpmmOracle.js +540 -0
- package/dist/src/states/oracles/switchboardOracle.d.ts +0 -0
- package/dist/src/states/oracles/switchboardOracle.js +1 -0
- package/dist/src/states/withdrawBasketFees.d.ts +10 -0
- package/dist/src/states/withdrawBasketFees.js +154 -0
- package/dist/src/txUtils.d.ts +65 -0
- package/dist/src/txUtils.js +306 -0
- package/dist/test.d.ts +1 -0
- package/dist/test.js +561 -0
- package/package.json +31 -0
- package/src/constants.ts +40 -0
- package/src/index.ts +2431 -0
- package/src/instructions/automation/auction.ts +55 -0
- package/src/instructions/automation/claimBounty.ts +69 -0
- package/src/instructions/automation/flashSwap.ts +104 -0
- package/src/instructions/automation/priceUpdate.ts +117 -0
- package/src/instructions/automation/rebalanceIntent.ts +181 -0
- package/src/instructions/management/addBounty.ts +55 -0
- package/src/instructions/management/admin.ts +72 -0
- package/src/instructions/management/claimFees.ts +129 -0
- package/src/instructions/management/createBasket.ts +138 -0
- package/src/instructions/management/edit.ts +602 -0
- package/src/instructions/management/luts.ts +157 -0
- package/src/instructions/pda.ts +151 -0
- package/src/instructions/user/deposit.ts +143 -0
- package/src/instructions/user/withdraw.ts +53 -0
- package/src/jup.ts +113 -0
- package/src/keeperMonitor.ts +585 -0
- package/src/layouts/basket.ts +233 -0
- package/src/layouts/config.ts +576 -0
- package/src/layouts/fraction.ts +164 -0
- package/src/layouts/intents/bounty.ts +35 -0
- package/src/layouts/intents/intent.ts +324 -0
- package/src/layouts/intents/rebalanceIntent.ts +306 -0
- package/src/layouts/lookupTable.ts +14 -0
- package/src/layouts/oracle.ts +157 -0
- package/src/states/basket.ts +527 -0
- package/src/states/config.ts +62 -0
- package/src/states/intents/intent.ts +311 -0
- package/src/states/intents/rebalanceIntent.ts +751 -0
- package/src/states/oracles/constants.ts +13 -0
- package/src/states/oracles/oracle.ts +212 -0
- package/src/states/oracles/pythOracle.ts +874 -0
- package/src/states/oracles/raydiumClmmOracle.ts +1193 -0
- package/src/states/oracles/raydiumCpmmOracle.ts +784 -0
- package/src/states/oracles/switchboardOracle.ts +0 -0
- package/src/states/withdrawBasketFees.ts +160 -0
- package/src/txUtils.ts +424 -0
- package/test.ts +609 -0
- package/tsconfig.json +101 -0
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Connection,
|
|
3
|
+
PublicKey,
|
|
4
|
+
GetProgramAccountsFilter,
|
|
5
|
+
GetProgramAccountsResponse
|
|
6
|
+
} from '@solana/web3.js';
|
|
7
|
+
|
|
8
|
+
import { BASKETS_V3_PROGRAM_ID, MAX_MANAGERS_PER_BASKET } from '../../constants';
|
|
9
|
+
import { AddOrEditTokenInput, EditAddTokenSettings, EditAutomationSettings, EditCreatorSettings, EditCustomRebalanceSettings, EditDepositsSettings, EditFeeSettings, EditForceRebalanceSettings, EditLpSettings, EditMakeDirectSwapSettings, EditManagerSettings, EditMetadataSettings, EditScheduleSettings, EditUpdateWeightsSettings, FormattedIntent, Intent, INTENT_STATUS_STRINGS, IntentLayout, IntentStatus, MakeDirectSwapInput, Settings, TASK_TYPE_STRINGS, TaskType, taskTypeFromU8, UpdateWeightsInput } from '../../layouts/intents/intent';
|
|
10
|
+
import { getMultipleAccountsInfoBatched } from '../../txUtils';
|
|
11
|
+
import { AuthorityBitmasks, AuthorityBitmasksLayout, AutomationSettings, AutomationSettingsLayout, EditAddTokenDelay, EditAddTokenDelayLayout, EditCreator, EditCreatorLayout, EditMakeDirectSwapDelay, EditMakeDirectSwapDelayLayout, EditUpdateWeightsDelay, EditUpdateWeightsDelayLayout, FeeSettings, FeeSettingsLayout, LpSettings, LpSettingsLayout, MakeDirectSwap, MakeDirectSwapLayout, ManagerSettings, ManagerSettingsLayout, MetadataSettings, MetadataSettingsLayout, ScheduleSettings, ScheduleSettingsLayout, UpdateWeights, UpdateWeightsLayout } from '../../layouts/config';
|
|
12
|
+
import BN from 'bn.js';
|
|
13
|
+
import { ORACLE_TYPES_STRINGS, OracleAggregator, OracleAggregatorLayout } from '../../layouts/oracle';
|
|
14
|
+
import { fractionToDecimal } from '../../layouts/fraction';
|
|
15
|
+
|
|
16
|
+
function decodeTaskDataForType(intent: Intent): Settings {
|
|
17
|
+
let taskType = taskTypeFromU8(intent.taskType);
|
|
18
|
+
let taskData = intent.taskData;
|
|
19
|
+
switch (taskType) {
|
|
20
|
+
case TaskType.EditCreator:
|
|
21
|
+
let editCreator: EditCreator = EditCreatorLayout.decode(Buffer.from(taskData.slice(0, EditCreatorLayout.getSpan())));
|
|
22
|
+
let creator_settings: EditCreatorSettings = {
|
|
23
|
+
creator: editCreator.creator.toBase58(),
|
|
24
|
+
}
|
|
25
|
+
return creator_settings;
|
|
26
|
+
case TaskType.EditManagerSettings:
|
|
27
|
+
let managerSettings: ManagerSettings = ManagerSettingsLayout.decode(Buffer.from(taskData.slice(0, ManagerSettingsLayout.getSpan())));
|
|
28
|
+
let authorityBitmasks: AuthorityBitmasks = AuthorityBitmasksLayout.decode(Buffer.from(taskData.slice(ManagerSettingsLayout.getSpan(), ManagerSettingsLayout.getSpan() + AuthorityBitmasksLayout.getSpan())));
|
|
29
|
+
let totalManagers = MAX_MANAGERS_PER_BASKET;
|
|
30
|
+
while (totalManagers > 0 && managerSettings.managers[totalManagers - 1].equals(PublicKey.default)) {
|
|
31
|
+
totalManagers--;
|
|
32
|
+
}
|
|
33
|
+
managerSettings.managers = managerSettings.managers.slice(0, totalManagers);
|
|
34
|
+
managerSettings.managersWeightBps = managerSettings.managersWeightBps.slice(0, totalManagers);
|
|
35
|
+
let manager_settings: EditManagerSettings = {
|
|
36
|
+
managers: managerSettings.managers.map((manager, i) => ({
|
|
37
|
+
pubkey: manager.toBase58(),
|
|
38
|
+
fee_split_weight_bps: managerSettings.managersWeightBps[i],
|
|
39
|
+
authorities: {
|
|
40
|
+
managers: (((2 ** i) & authorityBitmasks.managersAuthorityBitmask) != 0),
|
|
41
|
+
fees: (((2 ** i) & authorityBitmasks.feesAuthorityBitmask) != 0),
|
|
42
|
+
schedule: (((2 ** i) & authorityBitmasks.scheduleAuthorityBitmask) != 0),
|
|
43
|
+
automation: (((2 ** i) & authorityBitmasks.automationAuthorityBitmask) != 0),
|
|
44
|
+
lp: (((2 ** i) & authorityBitmasks.lpAuthorityBitmask) != 0),
|
|
45
|
+
metadata: (((2 ** i) & authorityBitmasks.metadataAuthorityBitmask) != 0),
|
|
46
|
+
deposits: (((2 ** i) & authorityBitmasks.depositsAuthorityBitmask) != 0),
|
|
47
|
+
force_rebalance: (((2 ** i) & authorityBitmasks.forceRebalanceAuthorityBitmask) != 0),
|
|
48
|
+
custom_rebalance: (((2 ** i) & authorityBitmasks.customRebalanceAuthorityBitmask) != 0),
|
|
49
|
+
add_token: (((2 ** i) & authorityBitmasks.addTokenIntentAuthorityBitmask) != 0),
|
|
50
|
+
update_weights: (((2 ** i) & authorityBitmasks.updateWeightsIntentAuthorityBitmask) != 0),
|
|
51
|
+
make_direct_swap: (((2 ** i) & authorityBitmasks.makeDirectSwapIntentAuthorityBitmask) != 0),
|
|
52
|
+
},
|
|
53
|
+
})),
|
|
54
|
+
modification_delay: parseInt(managerSettings.modificationDelay.toString()),
|
|
55
|
+
}
|
|
56
|
+
return manager_settings;
|
|
57
|
+
case TaskType.EditFeeSettings:
|
|
58
|
+
let editFeeSettings: FeeSettings = FeeSettingsLayout.decode(Buffer.from(taskData.slice(0, FeeSettingsLayout.getSpan())));
|
|
59
|
+
let fee_settings: EditFeeSettings = {
|
|
60
|
+
creator_deposit_fee_bps: editFeeSettings.creatorDepositFeeBps,
|
|
61
|
+
creator_withdraw_fee_bps: editFeeSettings.creatorWithdrawFeeBps,
|
|
62
|
+
creator_management_fee_bps: editFeeSettings.creatorManagementFeeBps,
|
|
63
|
+
creator_performance_fee_bps: editFeeSettings.creatorPerformanceFeeBps,
|
|
64
|
+
managers_deposit_fee_bps: editFeeSettings.managersDepositFeeBps,
|
|
65
|
+
managers_withdraw_fee_bps: editFeeSettings.managersWithdrawFeeBps,
|
|
66
|
+
managers_management_fee_bps: editFeeSettings.managersManagementFeeBps,
|
|
67
|
+
managers_performance_fee_bps: editFeeSettings.managersPerformanceFeeBps,
|
|
68
|
+
basket_deposit_fee_bps: editFeeSettings.basketDepositFeeBps,
|
|
69
|
+
basket_withdraw_fee_bps: editFeeSettings.basketWithdrawFeeBps,
|
|
70
|
+
modification_delay: parseInt(editFeeSettings.modificationDelay.toString()),
|
|
71
|
+
}
|
|
72
|
+
return fee_settings;
|
|
73
|
+
case TaskType.EditScheduleSettings:
|
|
74
|
+
let editScheduleSettings: ScheduleSettings = ScheduleSettingsLayout.decode(Buffer.from(taskData.slice(0, ScheduleSettingsLayout.getSpan())));
|
|
75
|
+
let schedule_settings: EditScheduleSettings = {
|
|
76
|
+
cycle_start_time: parseInt(editScheduleSettings.cycleStartTime.toString()),
|
|
77
|
+
cycle_duration: parseInt(editScheduleSettings.cycleDuration.toString()),
|
|
78
|
+
deposits_start: parseInt(editScheduleSettings.depositsStart.toString()),
|
|
79
|
+
deposits_end: parseInt(editScheduleSettings.depositsEnd.toString()),
|
|
80
|
+
automation_start: parseInt(editScheduleSettings.automationStart.toString()),
|
|
81
|
+
automation_end: parseInt(editScheduleSettings.automationEnd.toString()),
|
|
82
|
+
management_start: parseInt(editScheduleSettings.managementStart.toString()),
|
|
83
|
+
management_end: parseInt(editScheduleSettings.managementEnd.toString()),
|
|
84
|
+
modification_delay: parseInt(editScheduleSettings.modificationDelay.toString()),
|
|
85
|
+
}
|
|
86
|
+
return schedule_settings;
|
|
87
|
+
case TaskType.EditAutomationSettings:
|
|
88
|
+
let editAutomationSettings: AutomationSettings = AutomationSettingsLayout.decode(Buffer.from(taskData.slice(0, AutomationSettingsLayout.getSpan())));
|
|
89
|
+
let automation_settings: EditAutomationSettings = {
|
|
90
|
+
enabled: editAutomationSettings.allowAutomation == 1 ? true : false,
|
|
91
|
+
rebalance_slippage_threshold_bps: editAutomationSettings.rebalanceSlippageThresholdBps,
|
|
92
|
+
per_trade_rebalance_slippage_threshold_bps: editAutomationSettings.perTradeRebalanceSlippageThresholdBps,
|
|
93
|
+
rebalance_activation_threshold_abs_bps: editAutomationSettings.rebalanceActivationThresholdAbsBps,
|
|
94
|
+
rebalance_activation_threshold_rel_bps: editAutomationSettings.rebalanceActivationThresholdRelBps,
|
|
95
|
+
rebalance_activation_cooldown: parseInt(editAutomationSettings.rebalanceActivationCooldown.toString()),
|
|
96
|
+
modification_delay: parseInt(editAutomationSettings.modificationDelay.toString()),
|
|
97
|
+
}
|
|
98
|
+
return automation_settings;
|
|
99
|
+
case TaskType.EditLpSettings:
|
|
100
|
+
let editLpSettings: LpSettings = LpSettingsLayout.decode(Buffer.from(taskData.slice(0, LpSettingsLayout.getSpan())));
|
|
101
|
+
let lp_settings: EditLpSettings = {
|
|
102
|
+
enabled: editLpSettings.allowLp == 1 ? true : false,
|
|
103
|
+
lp_threshold_bps: editLpSettings.lpThresholdBps,
|
|
104
|
+
modification_delay: parseInt(editLpSettings.modificationDelay.toString()),
|
|
105
|
+
}
|
|
106
|
+
return lp_settings;
|
|
107
|
+
case TaskType.EditMetadataSettings:
|
|
108
|
+
let editMetadataSettings: MetadataSettings = MetadataSettingsLayout.decode(Buffer.from(taskData.slice(0, MetadataSettingsLayout.getSpan())));
|
|
109
|
+
let metadata = {
|
|
110
|
+
symbol: Buffer.from(editMetadataSettings.symbol.slice(0, editMetadataSettings.symbolLength)).toString(),
|
|
111
|
+
name: Buffer.from(editMetadataSettings.name.slice(0, editMetadataSettings.nameLength)).toString(),
|
|
112
|
+
uri: Buffer.from(editMetadataSettings.uri.slice(0, editMetadataSettings.uriLength)).toString()
|
|
113
|
+
}
|
|
114
|
+
let metadata_settings: EditMetadataSettings = {
|
|
115
|
+
symbol: metadata.symbol,
|
|
116
|
+
name: metadata.name,
|
|
117
|
+
uri: metadata.uri,
|
|
118
|
+
modification_delay: parseInt(editMetadataSettings.modificationDelay.toString()),
|
|
119
|
+
}
|
|
120
|
+
return metadata_settings;
|
|
121
|
+
case TaskType.EditDepositsSettings:
|
|
122
|
+
let deposits_settings: EditDepositsSettings = {
|
|
123
|
+
enabled: taskData[0] == 1 ? true : false,
|
|
124
|
+
}
|
|
125
|
+
return deposits_settings;
|
|
126
|
+
case TaskType.EditForceRebalanceSettings:
|
|
127
|
+
let force_rebalance_settings: EditForceRebalanceSettings = {
|
|
128
|
+
enabled: taskData[0] == 1 ? true : false,
|
|
129
|
+
modification_delay: parseInt(new BN(Buffer.from(taskData.slice(1, 9)), "le").toString()),
|
|
130
|
+
}
|
|
131
|
+
return force_rebalance_settings;
|
|
132
|
+
case TaskType.EditCustomRebalanceSettings:
|
|
133
|
+
let custom_rebalance_settings: EditCustomRebalanceSettings = {
|
|
134
|
+
enabled: taskData[0] == 1 ? true : false,
|
|
135
|
+
modification_delay: parseInt(new BN(Buffer.from(taskData.slice(1, 9)), "le").toString()),
|
|
136
|
+
}
|
|
137
|
+
return custom_rebalance_settings;
|
|
138
|
+
case TaskType.EditAddTokenDelay:
|
|
139
|
+
let editAddTokenDelay: EditAddTokenDelay = EditAddTokenDelayLayout.decode(Buffer.from(taskData.slice(0, EditAddTokenDelayLayout.getSpan())));
|
|
140
|
+
let add_token_settings: EditAddTokenSettings = {
|
|
141
|
+
modification_delay: parseInt(editAddTokenDelay.modificationDelay.toString()),
|
|
142
|
+
}
|
|
143
|
+
return add_token_settings;
|
|
144
|
+
case TaskType.EditUpdateWeightsDelay:
|
|
145
|
+
let editUpdateWeightsDelay: EditUpdateWeightsDelay = EditUpdateWeightsDelayLayout.decode(Buffer.from(taskData.slice(0, EditUpdateWeightsDelayLayout.getSpan())));
|
|
146
|
+
let update_weights_settings: EditUpdateWeightsSettings = {
|
|
147
|
+
modification_delay: parseInt(editUpdateWeightsDelay.modificationDelay.toString()),
|
|
148
|
+
}
|
|
149
|
+
return update_weights_settings;
|
|
150
|
+
case TaskType.EditMakeDirectSwapDelay:
|
|
151
|
+
let editMakeDirectSwapDelay: EditMakeDirectSwapDelay = EditMakeDirectSwapDelayLayout.decode(Buffer.from(taskData.slice(0, EditMakeDirectSwapDelayLayout.getSpan())));
|
|
152
|
+
let make_direct_swap_settings: EditMakeDirectSwapSettings = {
|
|
153
|
+
modification_delay: parseInt(editMakeDirectSwapDelay.modificationDelay.toString()),
|
|
154
|
+
}
|
|
155
|
+
return make_direct_swap_settings;
|
|
156
|
+
case TaskType.AddToken:
|
|
157
|
+
let oracleAggregator: OracleAggregator = OracleAggregatorLayout.decode(Buffer.from(taskData.slice(0, OracleAggregatorLayout.getSpan())));
|
|
158
|
+
let active = taskData[OracleAggregatorLayout.getSpan()] == 1 ? true : false;
|
|
159
|
+
let token_mint = new PublicKey(taskData.slice(OracleAggregatorLayout.getSpan() + 1, OracleAggregatorLayout.getSpan() + 33));
|
|
160
|
+
let add_token_input: AddOrEditTokenInput = {
|
|
161
|
+
token_mint: token_mint.toBase58(),
|
|
162
|
+
active: active,
|
|
163
|
+
min_oracles_thresh: oracleAggregator.minOraclesThresh,
|
|
164
|
+
min_conf_bps: oracleAggregator.minConfBps,
|
|
165
|
+
conf_thresh_bps: oracleAggregator.confThreshBps,
|
|
166
|
+
conf_multiplier: fractionToDecimal(oracleAggregator.confMultiplier).toNumber(),
|
|
167
|
+
oracles: oracleAggregator.oracles.slice(0, oracleAggregator.numOracles).map(oracle => ({
|
|
168
|
+
oracle_type: ORACLE_TYPES_STRINGS.get(oracle.oracleSettings.oracleType) ?? "example",
|
|
169
|
+
account_lut_id: oracle.accountsToLoadLutIds[0],
|
|
170
|
+
account_lut_index: oracle.accountsToLoadLutIndices[0],
|
|
171
|
+
account: "",
|
|
172
|
+
num_required_accounts: oracle.oracleSettings.numRequiredAccounts,
|
|
173
|
+
weight: oracle.oracleSettings.weight,
|
|
174
|
+
is_required: oracle.oracleSettings.isRequired == 1 ? true : false,
|
|
175
|
+
conf_thresh_bps: oracle.oracleSettings.confThreshBps,
|
|
176
|
+
volatility_thresh_bps: oracle.oracleSettings.volatilityThreshBps,
|
|
177
|
+
max_slippage_bps: oracle.oracleSettings.maxSlippageBps,
|
|
178
|
+
min_liquidity: parseInt(oracle.oracleSettings.minLiquidity.toString()),
|
|
179
|
+
staleness_thresh: parseInt(oracle.oracleSettings.stalenessThresh.toString()),
|
|
180
|
+
staleness_conf_rate_bps: oracle.oracleSettings.stalenessConfRateBps,
|
|
181
|
+
token_decimals: oracle.oracleSettings.tokenDecimals,
|
|
182
|
+
twap_seconds_ago: parseInt(oracle.oracleSettings.twapSecondsAgo.toString()),
|
|
183
|
+
twap_secondary_seconds_ago: parseInt(oracle.oracleSettings.twapSecondarySecondsAgo.toString()),
|
|
184
|
+
})),
|
|
185
|
+
}
|
|
186
|
+
return add_token_input;
|
|
187
|
+
case TaskType.UpdateWeights:
|
|
188
|
+
let updateWeights: UpdateWeights = UpdateWeightsLayout.decode(Buffer.from(taskData.slice(0, UpdateWeightsLayout.getSpan())));
|
|
189
|
+
let update_weights_input: UpdateWeightsInput = {
|
|
190
|
+
token_weights: updateWeights.tokenWeights.map(weight => ({
|
|
191
|
+
mint: "",
|
|
192
|
+
weight_bps: weight,
|
|
193
|
+
})),
|
|
194
|
+
token_mints_hash: updateWeights.tokenMintsHash,
|
|
195
|
+
}
|
|
196
|
+
return update_weights_input;
|
|
197
|
+
case TaskType.MakeDirectSwap:
|
|
198
|
+
let makeDirectSwap: MakeDirectSwap = MakeDirectSwapLayout.decode(Buffer.from(taskData.slice(0, MakeDirectSwapLayout.getSpan())));
|
|
199
|
+
let make_direct_swap_input: MakeDirectSwapInput = {
|
|
200
|
+
from_token_mint: makeDirectSwap.fromTokenMint.toBase58(),
|
|
201
|
+
to_token_mint: makeDirectSwap.toTokenMint.toBase58(),
|
|
202
|
+
amount_from: parseInt(makeDirectSwap.amountFrom.toString()),
|
|
203
|
+
amount_to: parseInt(makeDirectSwap.amountTo.toString()),
|
|
204
|
+
}
|
|
205
|
+
return make_direct_swap_input;
|
|
206
|
+
default:
|
|
207
|
+
throw new Error(`Unknown task type: ${taskType}`);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
export function addFieldsToIntent(intent: Intent): Intent {
|
|
213
|
+
let formatted: FormattedIntent = {
|
|
214
|
+
pubkey: intent.ownAddress!.toBase58(),
|
|
215
|
+
manager: intent.manager.toBase58(),
|
|
216
|
+
status: INTENT_STATUS_STRINGS.get(intent.status) ?? "not_active",
|
|
217
|
+
activation_timestamp: parseInt(intent.activationTimestamp.toString()),
|
|
218
|
+
expiration_timestamp: parseInt(intent.expirationTimestamp.toString()),
|
|
219
|
+
basket: intent.basket.toBase58(),
|
|
220
|
+
bounty: {
|
|
221
|
+
bounty_depositor: intent.bounty.bountyDepositor.toBase58(),
|
|
222
|
+
bounty_mint: intent.bounty.bountyMint.toBase58(),
|
|
223
|
+
bounty_per_price_update_task: {
|
|
224
|
+
min_bounty: parseInt(intent.bounty.bountyPerPriceUpdateTask.minBounty.toString()),
|
|
225
|
+
max_bounty: parseInt(intent.bounty.bountyPerPriceUpdateTask.maxBounty.toString()),
|
|
226
|
+
min_bounty_until: parseInt(intent.bounty.bountyPerPriceUpdateTask.minBountyUntil.toString()),
|
|
227
|
+
max_bounty_after: parseInt(intent.bounty.bountyPerPriceUpdateTask.maxBountyAfter.toString()),
|
|
228
|
+
},
|
|
229
|
+
bounty_per_task: {
|
|
230
|
+
min_bounty: parseInt(intent.bounty.bountyPerTask.minBounty.toString()),
|
|
231
|
+
max_bounty: parseInt(intent.bounty.bountyPerTask.maxBounty.toString()),
|
|
232
|
+
min_bounty_until: parseInt(intent.bounty.bountyPerTask.minBountyUntil.toString()),
|
|
233
|
+
max_bounty_after: parseInt(intent.bounty.bountyPerTask.maxBountyAfter.toString()),
|
|
234
|
+
},
|
|
235
|
+
bounty_total: parseInt(intent.bounty.bountyTotal.toString()),
|
|
236
|
+
bounty_left: parseInt(intent.bounty.bountyLeft.toString()),
|
|
237
|
+
},
|
|
238
|
+
task_type: TASK_TYPE_STRINGS.get(intent.taskType) ?? "unknown",
|
|
239
|
+
task_data: decodeTaskDataForType(intent),
|
|
240
|
+
}
|
|
241
|
+
intent.formatted = formatted;
|
|
242
|
+
return intent;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export async function fetchIntent(
|
|
246
|
+
connection: Connection,
|
|
247
|
+
intentAddress: PublicKey,
|
|
248
|
+
): Promise<Intent>{
|
|
249
|
+
const intentAi = await connection.getAccountInfo(intentAddress);
|
|
250
|
+
if (!intentAi) throw new Error('Basket intent not found');
|
|
251
|
+
let intent = IntentLayout.decode(intentAi.data.slice(8));
|
|
252
|
+
intent.ownAddress = intentAddress;
|
|
253
|
+
intent = addFieldsToIntent(intent);
|
|
254
|
+
return intent;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export async function fetchIntentsMultiple(
|
|
258
|
+
connection: Connection,
|
|
259
|
+
intentAddresses: PublicKey[],
|
|
260
|
+
): Promise<Map<string, Intent>> {
|
|
261
|
+
let multipleAccountsInfo = await getMultipleAccountsInfoBatched(connection, intentAddresses);
|
|
262
|
+
let intents: Intent[] = intentAddresses.map(address => {
|
|
263
|
+
let ai = multipleAccountsInfo.get(address.toBase58());
|
|
264
|
+
if (!ai) return null;
|
|
265
|
+
return { ...IntentLayout.decode(ai.data.slice(8)), ownAddress: address }
|
|
266
|
+
}).filter(intent => intent !== null);
|
|
267
|
+
intents = intents.map(intent => addFieldsToIntent(intent));
|
|
268
|
+
let intentsMap: Map<string, Intent> = new Map();
|
|
269
|
+
for (let intent of intents) intentsMap.set(intent.ownAddress!.toBase58(), intent);
|
|
270
|
+
return intentsMap;
|
|
271
|
+
}
|
|
272
|
+
export interface IntentFilter {
|
|
273
|
+
type: "basket" | "manager";
|
|
274
|
+
pubkey: string;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export async function fetchIntents(
|
|
278
|
+
connection: Connection,
|
|
279
|
+
filter?: IntentFilter,
|
|
280
|
+
): Promise<Intent[]> {
|
|
281
|
+
let accountFilters: GetProgramAccountsFilter[] = [
|
|
282
|
+
{ dataSize: 8 + IntentLayout.getSpan() },
|
|
283
|
+
];
|
|
284
|
+
if (filter?.type === "basket") {
|
|
285
|
+
accountFilters.push({ memcmp: {
|
|
286
|
+
offset: 8 + 32 + 1 + 8 + 8,
|
|
287
|
+
bytes: filter.pubkey
|
|
288
|
+
} });
|
|
289
|
+
} else if (filter?.type === "manager") {
|
|
290
|
+
accountFilters.push({ memcmp: {
|
|
291
|
+
offset: 8,
|
|
292
|
+
bytes: filter.pubkey
|
|
293
|
+
} });
|
|
294
|
+
}
|
|
295
|
+
const accounts: GetProgramAccountsResponse = await connection
|
|
296
|
+
.getProgramAccounts(
|
|
297
|
+
BASKETS_V3_PROGRAM_ID,
|
|
298
|
+
{
|
|
299
|
+
commitment: "confirmed",
|
|
300
|
+
filters: accountFilters,
|
|
301
|
+
encoding: 'base64'
|
|
302
|
+
}
|
|
303
|
+
);
|
|
304
|
+
let intents: Intent[] = accounts.map(account => {
|
|
305
|
+
let intent = IntentLayout.decode(account.account.data.slice(8));
|
|
306
|
+
intent.ownAddress = account.pubkey;
|
|
307
|
+
return intent;
|
|
308
|
+
});
|
|
309
|
+
intents = intents.map(intent => addFieldsToIntent(intent));
|
|
310
|
+
return intents;
|
|
311
|
+
}
|