@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,316 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.addFieldsToIntent = addFieldsToIntent;
|
|
16
|
+
exports.fetchIntent = fetchIntent;
|
|
17
|
+
exports.fetchIntentsMultiple = fetchIntentsMultiple;
|
|
18
|
+
exports.fetchIntents = fetchIntents;
|
|
19
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
20
|
+
const constants_1 = require("../../constants");
|
|
21
|
+
const intent_1 = require("../../layouts/intents/intent");
|
|
22
|
+
const txUtils_1 = require("../../txUtils");
|
|
23
|
+
const config_1 = require("../../layouts/config");
|
|
24
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
25
|
+
const oracle_1 = require("../../layouts/oracle");
|
|
26
|
+
const fraction_1 = require("../../layouts/fraction");
|
|
27
|
+
function decodeTaskDataForType(intent) {
|
|
28
|
+
let taskType = (0, intent_1.taskTypeFromU8)(intent.taskType);
|
|
29
|
+
let taskData = intent.taskData;
|
|
30
|
+
switch (taskType) {
|
|
31
|
+
case intent_1.TaskType.EditCreator:
|
|
32
|
+
let editCreator = config_1.EditCreatorLayout.decode(Buffer.from(taskData.slice(0, config_1.EditCreatorLayout.getSpan())));
|
|
33
|
+
let creator_settings = {
|
|
34
|
+
creator: editCreator.creator.toBase58(),
|
|
35
|
+
};
|
|
36
|
+
return creator_settings;
|
|
37
|
+
case intent_1.TaskType.EditManagerSettings:
|
|
38
|
+
let managerSettings = config_1.ManagerSettingsLayout.decode(Buffer.from(taskData.slice(0, config_1.ManagerSettingsLayout.getSpan())));
|
|
39
|
+
let authorityBitmasks = config_1.AuthorityBitmasksLayout.decode(Buffer.from(taskData.slice(config_1.ManagerSettingsLayout.getSpan(), config_1.ManagerSettingsLayout.getSpan() + config_1.AuthorityBitmasksLayout.getSpan())));
|
|
40
|
+
let totalManagers = constants_1.MAX_MANAGERS_PER_BASKET;
|
|
41
|
+
while (totalManagers > 0 && managerSettings.managers[totalManagers - 1].equals(web3_js_1.PublicKey.default)) {
|
|
42
|
+
totalManagers--;
|
|
43
|
+
}
|
|
44
|
+
managerSettings.managers = managerSettings.managers.slice(0, totalManagers);
|
|
45
|
+
managerSettings.managersWeightBps = managerSettings.managersWeightBps.slice(0, totalManagers);
|
|
46
|
+
let manager_settings = {
|
|
47
|
+
managers: managerSettings.managers.map((manager, i) => ({
|
|
48
|
+
pubkey: manager.toBase58(),
|
|
49
|
+
fee_split_weight_bps: managerSettings.managersWeightBps[i],
|
|
50
|
+
authorities: {
|
|
51
|
+
managers: (((2 ** i) & authorityBitmasks.managersAuthorityBitmask) != 0),
|
|
52
|
+
fees: (((2 ** i) & authorityBitmasks.feesAuthorityBitmask) != 0),
|
|
53
|
+
schedule: (((2 ** i) & authorityBitmasks.scheduleAuthorityBitmask) != 0),
|
|
54
|
+
automation: (((2 ** i) & authorityBitmasks.automationAuthorityBitmask) != 0),
|
|
55
|
+
lp: (((2 ** i) & authorityBitmasks.lpAuthorityBitmask) != 0),
|
|
56
|
+
metadata: (((2 ** i) & authorityBitmasks.metadataAuthorityBitmask) != 0),
|
|
57
|
+
deposits: (((2 ** i) & authorityBitmasks.depositsAuthorityBitmask) != 0),
|
|
58
|
+
force_rebalance: (((2 ** i) & authorityBitmasks.forceRebalanceAuthorityBitmask) != 0),
|
|
59
|
+
custom_rebalance: (((2 ** i) & authorityBitmasks.customRebalanceAuthorityBitmask) != 0),
|
|
60
|
+
add_token: (((2 ** i) & authorityBitmasks.addTokenIntentAuthorityBitmask) != 0),
|
|
61
|
+
update_weights: (((2 ** i) & authorityBitmasks.updateWeightsIntentAuthorityBitmask) != 0),
|
|
62
|
+
make_direct_swap: (((2 ** i) & authorityBitmasks.makeDirectSwapIntentAuthorityBitmask) != 0),
|
|
63
|
+
},
|
|
64
|
+
})),
|
|
65
|
+
modification_delay: parseInt(managerSettings.modificationDelay.toString()),
|
|
66
|
+
};
|
|
67
|
+
return manager_settings;
|
|
68
|
+
case intent_1.TaskType.EditFeeSettings:
|
|
69
|
+
let editFeeSettings = config_1.FeeSettingsLayout.decode(Buffer.from(taskData.slice(0, config_1.FeeSettingsLayout.getSpan())));
|
|
70
|
+
let fee_settings = {
|
|
71
|
+
creator_deposit_fee_bps: editFeeSettings.creatorDepositFeeBps,
|
|
72
|
+
creator_withdraw_fee_bps: editFeeSettings.creatorWithdrawFeeBps,
|
|
73
|
+
creator_management_fee_bps: editFeeSettings.creatorManagementFeeBps,
|
|
74
|
+
creator_performance_fee_bps: editFeeSettings.creatorPerformanceFeeBps,
|
|
75
|
+
managers_deposit_fee_bps: editFeeSettings.managersDepositFeeBps,
|
|
76
|
+
managers_withdraw_fee_bps: editFeeSettings.managersWithdrawFeeBps,
|
|
77
|
+
managers_management_fee_bps: editFeeSettings.managersManagementFeeBps,
|
|
78
|
+
managers_performance_fee_bps: editFeeSettings.managersPerformanceFeeBps,
|
|
79
|
+
basket_deposit_fee_bps: editFeeSettings.basketDepositFeeBps,
|
|
80
|
+
basket_withdraw_fee_bps: editFeeSettings.basketWithdrawFeeBps,
|
|
81
|
+
modification_delay: parseInt(editFeeSettings.modificationDelay.toString()),
|
|
82
|
+
};
|
|
83
|
+
return fee_settings;
|
|
84
|
+
case intent_1.TaskType.EditScheduleSettings:
|
|
85
|
+
let editScheduleSettings = config_1.ScheduleSettingsLayout.decode(Buffer.from(taskData.slice(0, config_1.ScheduleSettingsLayout.getSpan())));
|
|
86
|
+
let schedule_settings = {
|
|
87
|
+
cycle_start_time: parseInt(editScheduleSettings.cycleStartTime.toString()),
|
|
88
|
+
cycle_duration: parseInt(editScheduleSettings.cycleDuration.toString()),
|
|
89
|
+
deposits_start: parseInt(editScheduleSettings.depositsStart.toString()),
|
|
90
|
+
deposits_end: parseInt(editScheduleSettings.depositsEnd.toString()),
|
|
91
|
+
automation_start: parseInt(editScheduleSettings.automationStart.toString()),
|
|
92
|
+
automation_end: parseInt(editScheduleSettings.automationEnd.toString()),
|
|
93
|
+
management_start: parseInt(editScheduleSettings.managementStart.toString()),
|
|
94
|
+
management_end: parseInt(editScheduleSettings.managementEnd.toString()),
|
|
95
|
+
modification_delay: parseInt(editScheduleSettings.modificationDelay.toString()),
|
|
96
|
+
};
|
|
97
|
+
return schedule_settings;
|
|
98
|
+
case intent_1.TaskType.EditAutomationSettings:
|
|
99
|
+
let editAutomationSettings = config_1.AutomationSettingsLayout.decode(Buffer.from(taskData.slice(0, config_1.AutomationSettingsLayout.getSpan())));
|
|
100
|
+
let automation_settings = {
|
|
101
|
+
enabled: editAutomationSettings.allowAutomation == 1 ? true : false,
|
|
102
|
+
rebalance_slippage_threshold_bps: editAutomationSettings.rebalanceSlippageThresholdBps,
|
|
103
|
+
per_trade_rebalance_slippage_threshold_bps: editAutomationSettings.perTradeRebalanceSlippageThresholdBps,
|
|
104
|
+
rebalance_activation_threshold_abs_bps: editAutomationSettings.rebalanceActivationThresholdAbsBps,
|
|
105
|
+
rebalance_activation_threshold_rel_bps: editAutomationSettings.rebalanceActivationThresholdRelBps,
|
|
106
|
+
rebalance_activation_cooldown: parseInt(editAutomationSettings.rebalanceActivationCooldown.toString()),
|
|
107
|
+
modification_delay: parseInt(editAutomationSettings.modificationDelay.toString()),
|
|
108
|
+
};
|
|
109
|
+
return automation_settings;
|
|
110
|
+
case intent_1.TaskType.EditLpSettings:
|
|
111
|
+
let editLpSettings = config_1.LpSettingsLayout.decode(Buffer.from(taskData.slice(0, config_1.LpSettingsLayout.getSpan())));
|
|
112
|
+
let lp_settings = {
|
|
113
|
+
enabled: editLpSettings.allowLp == 1 ? true : false,
|
|
114
|
+
lp_threshold_bps: editLpSettings.lpThresholdBps,
|
|
115
|
+
modification_delay: parseInt(editLpSettings.modificationDelay.toString()),
|
|
116
|
+
};
|
|
117
|
+
return lp_settings;
|
|
118
|
+
case intent_1.TaskType.EditMetadataSettings:
|
|
119
|
+
let editMetadataSettings = config_1.MetadataSettingsLayout.decode(Buffer.from(taskData.slice(0, config_1.MetadataSettingsLayout.getSpan())));
|
|
120
|
+
let metadata = {
|
|
121
|
+
symbol: Buffer.from(editMetadataSettings.symbol.slice(0, editMetadataSettings.symbolLength)).toString(),
|
|
122
|
+
name: Buffer.from(editMetadataSettings.name.slice(0, editMetadataSettings.nameLength)).toString(),
|
|
123
|
+
uri: Buffer.from(editMetadataSettings.uri.slice(0, editMetadataSettings.uriLength)).toString()
|
|
124
|
+
};
|
|
125
|
+
let metadata_settings = {
|
|
126
|
+
symbol: metadata.symbol,
|
|
127
|
+
name: metadata.name,
|
|
128
|
+
uri: metadata.uri,
|
|
129
|
+
modification_delay: parseInt(editMetadataSettings.modificationDelay.toString()),
|
|
130
|
+
};
|
|
131
|
+
return metadata_settings;
|
|
132
|
+
case intent_1.TaskType.EditDepositsSettings:
|
|
133
|
+
let deposits_settings = {
|
|
134
|
+
enabled: taskData[0] == 1 ? true : false,
|
|
135
|
+
};
|
|
136
|
+
return deposits_settings;
|
|
137
|
+
case intent_1.TaskType.EditForceRebalanceSettings:
|
|
138
|
+
let force_rebalance_settings = {
|
|
139
|
+
enabled: taskData[0] == 1 ? true : false,
|
|
140
|
+
modification_delay: parseInt(new bn_js_1.default(Buffer.from(taskData.slice(1, 9)), "le").toString()),
|
|
141
|
+
};
|
|
142
|
+
return force_rebalance_settings;
|
|
143
|
+
case intent_1.TaskType.EditCustomRebalanceSettings:
|
|
144
|
+
let custom_rebalance_settings = {
|
|
145
|
+
enabled: taskData[0] == 1 ? true : false,
|
|
146
|
+
modification_delay: parseInt(new bn_js_1.default(Buffer.from(taskData.slice(1, 9)), "le").toString()),
|
|
147
|
+
};
|
|
148
|
+
return custom_rebalance_settings;
|
|
149
|
+
case intent_1.TaskType.EditAddTokenDelay:
|
|
150
|
+
let editAddTokenDelay = config_1.EditAddTokenDelayLayout.decode(Buffer.from(taskData.slice(0, config_1.EditAddTokenDelayLayout.getSpan())));
|
|
151
|
+
let add_token_settings = {
|
|
152
|
+
modification_delay: parseInt(editAddTokenDelay.modificationDelay.toString()),
|
|
153
|
+
};
|
|
154
|
+
return add_token_settings;
|
|
155
|
+
case intent_1.TaskType.EditUpdateWeightsDelay:
|
|
156
|
+
let editUpdateWeightsDelay = config_1.EditUpdateWeightsDelayLayout.decode(Buffer.from(taskData.slice(0, config_1.EditUpdateWeightsDelayLayout.getSpan())));
|
|
157
|
+
let update_weights_settings = {
|
|
158
|
+
modification_delay: parseInt(editUpdateWeightsDelay.modificationDelay.toString()),
|
|
159
|
+
};
|
|
160
|
+
return update_weights_settings;
|
|
161
|
+
case intent_1.TaskType.EditMakeDirectSwapDelay:
|
|
162
|
+
let editMakeDirectSwapDelay = config_1.EditMakeDirectSwapDelayLayout.decode(Buffer.from(taskData.slice(0, config_1.EditMakeDirectSwapDelayLayout.getSpan())));
|
|
163
|
+
let make_direct_swap_settings = {
|
|
164
|
+
modification_delay: parseInt(editMakeDirectSwapDelay.modificationDelay.toString()),
|
|
165
|
+
};
|
|
166
|
+
return make_direct_swap_settings;
|
|
167
|
+
case intent_1.TaskType.AddToken:
|
|
168
|
+
let oracleAggregator = oracle_1.OracleAggregatorLayout.decode(Buffer.from(taskData.slice(0, oracle_1.OracleAggregatorLayout.getSpan())));
|
|
169
|
+
let active = taskData[oracle_1.OracleAggregatorLayout.getSpan()] == 1 ? true : false;
|
|
170
|
+
let token_mint = new web3_js_1.PublicKey(taskData.slice(oracle_1.OracleAggregatorLayout.getSpan() + 1, oracle_1.OracleAggregatorLayout.getSpan() + 33));
|
|
171
|
+
let add_token_input = {
|
|
172
|
+
token_mint: token_mint.toBase58(),
|
|
173
|
+
active: active,
|
|
174
|
+
min_oracles_thresh: oracleAggregator.minOraclesThresh,
|
|
175
|
+
min_conf_bps: oracleAggregator.minConfBps,
|
|
176
|
+
conf_thresh_bps: oracleAggregator.confThreshBps,
|
|
177
|
+
conf_multiplier: (0, fraction_1.fractionToDecimal)(oracleAggregator.confMultiplier).toNumber(),
|
|
178
|
+
oracles: oracleAggregator.oracles.slice(0, oracleAggregator.numOracles).map(oracle => {
|
|
179
|
+
var _a;
|
|
180
|
+
return ({
|
|
181
|
+
oracle_type: (_a = oracle_1.ORACLE_TYPES_STRINGS.get(oracle.oracleSettings.oracleType)) !== null && _a !== void 0 ? _a : "example",
|
|
182
|
+
account_lut_id: oracle.accountsToLoadLutIds[0],
|
|
183
|
+
account_lut_index: oracle.accountsToLoadLutIndices[0],
|
|
184
|
+
account: "",
|
|
185
|
+
num_required_accounts: oracle.oracleSettings.numRequiredAccounts,
|
|
186
|
+
weight: oracle.oracleSettings.weight,
|
|
187
|
+
is_required: oracle.oracleSettings.isRequired == 1 ? true : false,
|
|
188
|
+
conf_thresh_bps: oracle.oracleSettings.confThreshBps,
|
|
189
|
+
volatility_thresh_bps: oracle.oracleSettings.volatilityThreshBps,
|
|
190
|
+
max_slippage_bps: oracle.oracleSettings.maxSlippageBps,
|
|
191
|
+
min_liquidity: parseInt(oracle.oracleSettings.minLiquidity.toString()),
|
|
192
|
+
staleness_thresh: parseInt(oracle.oracleSettings.stalenessThresh.toString()),
|
|
193
|
+
staleness_conf_rate_bps: oracle.oracleSettings.stalenessConfRateBps,
|
|
194
|
+
token_decimals: oracle.oracleSettings.tokenDecimals,
|
|
195
|
+
twap_seconds_ago: parseInt(oracle.oracleSettings.twapSecondsAgo.toString()),
|
|
196
|
+
twap_secondary_seconds_ago: parseInt(oracle.oracleSettings.twapSecondarySecondsAgo.toString()),
|
|
197
|
+
});
|
|
198
|
+
}),
|
|
199
|
+
};
|
|
200
|
+
return add_token_input;
|
|
201
|
+
case intent_1.TaskType.UpdateWeights:
|
|
202
|
+
let updateWeights = config_1.UpdateWeightsLayout.decode(Buffer.from(taskData.slice(0, config_1.UpdateWeightsLayout.getSpan())));
|
|
203
|
+
let update_weights_input = {
|
|
204
|
+
token_weights: updateWeights.tokenWeights.map(weight => ({
|
|
205
|
+
mint: "",
|
|
206
|
+
weight_bps: weight,
|
|
207
|
+
})),
|
|
208
|
+
token_mints_hash: updateWeights.tokenMintsHash,
|
|
209
|
+
};
|
|
210
|
+
return update_weights_input;
|
|
211
|
+
case intent_1.TaskType.MakeDirectSwap:
|
|
212
|
+
let makeDirectSwap = config_1.MakeDirectSwapLayout.decode(Buffer.from(taskData.slice(0, config_1.MakeDirectSwapLayout.getSpan())));
|
|
213
|
+
let make_direct_swap_input = {
|
|
214
|
+
from_token_mint: makeDirectSwap.fromTokenMint.toBase58(),
|
|
215
|
+
to_token_mint: makeDirectSwap.toTokenMint.toBase58(),
|
|
216
|
+
amount_from: parseInt(makeDirectSwap.amountFrom.toString()),
|
|
217
|
+
amount_to: parseInt(makeDirectSwap.amountTo.toString()),
|
|
218
|
+
};
|
|
219
|
+
return make_direct_swap_input;
|
|
220
|
+
default:
|
|
221
|
+
throw new Error(`Unknown task type: ${taskType}`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
;
|
|
225
|
+
function addFieldsToIntent(intent) {
|
|
226
|
+
var _a, _b;
|
|
227
|
+
let formatted = {
|
|
228
|
+
pubkey: intent.ownAddress.toBase58(),
|
|
229
|
+
manager: intent.manager.toBase58(),
|
|
230
|
+
status: (_a = intent_1.INTENT_STATUS_STRINGS.get(intent.status)) !== null && _a !== void 0 ? _a : "not_active",
|
|
231
|
+
activation_timestamp: parseInt(intent.activationTimestamp.toString()),
|
|
232
|
+
expiration_timestamp: parseInt(intent.expirationTimestamp.toString()),
|
|
233
|
+
basket: intent.basket.toBase58(),
|
|
234
|
+
bounty: {
|
|
235
|
+
bounty_depositor: intent.bounty.bountyDepositor.toBase58(),
|
|
236
|
+
bounty_mint: intent.bounty.bountyMint.toBase58(),
|
|
237
|
+
bounty_per_price_update_task: {
|
|
238
|
+
min_bounty: parseInt(intent.bounty.bountyPerPriceUpdateTask.minBounty.toString()),
|
|
239
|
+
max_bounty: parseInt(intent.bounty.bountyPerPriceUpdateTask.maxBounty.toString()),
|
|
240
|
+
min_bounty_until: parseInt(intent.bounty.bountyPerPriceUpdateTask.minBountyUntil.toString()),
|
|
241
|
+
max_bounty_after: parseInt(intent.bounty.bountyPerPriceUpdateTask.maxBountyAfter.toString()),
|
|
242
|
+
},
|
|
243
|
+
bounty_per_task: {
|
|
244
|
+
min_bounty: parseInt(intent.bounty.bountyPerTask.minBounty.toString()),
|
|
245
|
+
max_bounty: parseInt(intent.bounty.bountyPerTask.maxBounty.toString()),
|
|
246
|
+
min_bounty_until: parseInt(intent.bounty.bountyPerTask.minBountyUntil.toString()),
|
|
247
|
+
max_bounty_after: parseInt(intent.bounty.bountyPerTask.maxBountyAfter.toString()),
|
|
248
|
+
},
|
|
249
|
+
bounty_total: parseInt(intent.bounty.bountyTotal.toString()),
|
|
250
|
+
bounty_left: parseInt(intent.bounty.bountyLeft.toString()),
|
|
251
|
+
},
|
|
252
|
+
task_type: (_b = intent_1.TASK_TYPE_STRINGS.get(intent.taskType)) !== null && _b !== void 0 ? _b : "unknown",
|
|
253
|
+
task_data: decodeTaskDataForType(intent),
|
|
254
|
+
};
|
|
255
|
+
intent.formatted = formatted;
|
|
256
|
+
return intent;
|
|
257
|
+
}
|
|
258
|
+
function fetchIntent(connection, intentAddress) {
|
|
259
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
260
|
+
const intentAi = yield connection.getAccountInfo(intentAddress);
|
|
261
|
+
if (!intentAi)
|
|
262
|
+
throw new Error('Basket intent not found');
|
|
263
|
+
let intent = intent_1.IntentLayout.decode(intentAi.data.slice(8));
|
|
264
|
+
intent.ownAddress = intentAddress;
|
|
265
|
+
intent = addFieldsToIntent(intent);
|
|
266
|
+
return intent;
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
function fetchIntentsMultiple(connection, intentAddresses) {
|
|
270
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
+
let multipleAccountsInfo = yield (0, txUtils_1.getMultipleAccountsInfoBatched)(connection, intentAddresses);
|
|
272
|
+
let intents = intentAddresses.map(address => {
|
|
273
|
+
let ai = multipleAccountsInfo.get(address.toBase58());
|
|
274
|
+
if (!ai)
|
|
275
|
+
return null;
|
|
276
|
+
return Object.assign(Object.assign({}, intent_1.IntentLayout.decode(ai.data.slice(8))), { ownAddress: address });
|
|
277
|
+
}).filter(intent => intent !== null);
|
|
278
|
+
intents = intents.map(intent => addFieldsToIntent(intent));
|
|
279
|
+
let intentsMap = new Map();
|
|
280
|
+
for (let intent of intents)
|
|
281
|
+
intentsMap.set(intent.ownAddress.toBase58(), intent);
|
|
282
|
+
return intentsMap;
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
function fetchIntents(connection, filter) {
|
|
286
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
287
|
+
let accountFilters = [
|
|
288
|
+
{ dataSize: 8 + intent_1.IntentLayout.getSpan() },
|
|
289
|
+
];
|
|
290
|
+
if ((filter === null || filter === void 0 ? void 0 : filter.type) === "basket") {
|
|
291
|
+
accountFilters.push({ memcmp: {
|
|
292
|
+
offset: 8 + 32 + 1 + 8 + 8,
|
|
293
|
+
bytes: filter.pubkey
|
|
294
|
+
} });
|
|
295
|
+
}
|
|
296
|
+
else if ((filter === null || filter === void 0 ? void 0 : filter.type) === "manager") {
|
|
297
|
+
accountFilters.push({ memcmp: {
|
|
298
|
+
offset: 8,
|
|
299
|
+
bytes: filter.pubkey
|
|
300
|
+
} });
|
|
301
|
+
}
|
|
302
|
+
const accounts = yield connection
|
|
303
|
+
.getProgramAccounts(constants_1.BASKETS_V3_PROGRAM_ID, {
|
|
304
|
+
commitment: "confirmed",
|
|
305
|
+
filters: accountFilters,
|
|
306
|
+
encoding: 'base64'
|
|
307
|
+
});
|
|
308
|
+
let intents = accounts.map(account => {
|
|
309
|
+
let intent = intent_1.IntentLayout.decode(account.account.data.slice(8));
|
|
310
|
+
intent.ownAddress = account.pubkey;
|
|
311
|
+
return intent;
|
|
312
|
+
});
|
|
313
|
+
intents = intents.map(intent => addFieldsToIntent(intent));
|
|
314
|
+
return intents;
|
|
315
|
+
});
|
|
316
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { RebalanceIntent, RebalanceType, UIRebalanceIntent } from "../../layouts/intents/rebalanceIntent";
|
|
3
|
+
import { Basket, FormattedBasket } from "../../layouts/basket";
|
|
4
|
+
export declare function computeRebalanceIntentBountyAmount(rebalance_type: RebalanceType, num_tokens: number, bounty_bond: number, bounty_per_task: number, bounty_per_price_update_task_max: number): number;
|
|
5
|
+
export declare function formatRebalanceIntent(rebalanceIntent: RebalanceIntent, basket?: FormattedBasket): UIRebalanceIntent;
|
|
6
|
+
export declare function fetchRebalanceIntent(connection: Connection, rebalanceIntentAddress: PublicKey): Promise<UIRebalanceIntent>;
|
|
7
|
+
export declare function fetchRebalanceIntentsMultiple(connection: Connection, rebalanceIntentAddresses: PublicKey[]): Promise<Map<string, UIRebalanceIntent>>;
|
|
8
|
+
export interface RebalanceIntentFilter {
|
|
9
|
+
type: "basket" | "owner";
|
|
10
|
+
pubkey: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function fetchRebalanceIntents(connection: Connection, filter?: RebalanceIntentFilter): Promise<UIRebalanceIntent[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Returns all valid swap pairs available during the rebalance auction phase.
|
|
15
|
+
*
|
|
16
|
+
* **Swap direction (basket perspective):**
|
|
17
|
+
* - `inMint` / `inAmount`: what the basket is supposed to **receive**.
|
|
18
|
+
* - `outMint` / `outAmount`: what the basket wants to **swap** (give away).
|
|
19
|
+
* So each pair describes an **outMint → inMint** swap. When generating swap
|
|
20
|
+
* transactions, use this direction: swap `outMint` → `inMint` (sell outAmount of
|
|
21
|
+
* outMint, receive inAmount of inMint).
|
|
22
|
+
*
|
|
23
|
+
* Only runs when the rebalance is in Auction action and the current time falls
|
|
24
|
+
* within one of the three auction windows. For the active auction, target amounts
|
|
25
|
+
* are refreshed if they haven't been updated since the auction started.
|
|
26
|
+
*
|
|
27
|
+
* Iterates over completed price-update tokens to compute exchange rates via
|
|
28
|
+
* getSwapAmounts (using time-since-start and auction duration). Pairs with
|
|
29
|
+
* positive in/out amounts are collected and sorted by value descending
|
|
30
|
+
* (highest value first).
|
|
31
|
+
*
|
|
32
|
+
* @param rebalanceIntent - The rebalance intent state
|
|
33
|
+
* @param basket - The basket (used to update target amounts when needed)
|
|
34
|
+
* @returns Array of swap pairs, or empty array when not in auction or outside auction windows
|
|
35
|
+
*/
|
|
36
|
+
export declare function getSwapPairs(rebalanceIntent: RebalanceIntent, basket: Basket): {
|
|
37
|
+
inMint: string;
|
|
38
|
+
outMint: string;
|
|
39
|
+
inAmount: number;
|
|
40
|
+
outAmount: number;
|
|
41
|
+
value: number;
|
|
42
|
+
}[];
|