Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,13 @@ export async function loadConfiguration(): Promise<MarkConfiguration> {
solana: {
privateKey: configJson.solana?.privateKey ?? (await fromEnv('SOLANA_PRIVATE_KEY', true)) ?? undefined,
rpcUrl: configJson.solana?.rpcUrl ?? (await fromEnv('SOLANA_RPC_URL', true)) ?? undefined,
ptUsdeThreshold:
configJson.solana?.ptUsdeThreshold ?? (await fromEnv('PTUSDE_SOLANA_THRESHOLD', true)) ?? undefined,
ptUsdeTarget: configJson.solana?.ptUsdeTarget ?? (await fromEnv('PTUSDE_SOLANA_TARGET', true)) ?? undefined,
ptUsdeMaxRebalanceAmount:
configJson.solana?.ptUsdeMaxRebalanceAmount ??
(await fromEnv('PTUSDE_SOLANA_MAX_REBALANCE_AMOUNT', true)) ??
undefined,
},
tacRebalance: {
enabled:
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ export interface MarkConfiguration extends RebalanceConfig {
solana?: {
privateKey?: string; // Solana wallet private key (base58 encoded)
rpcUrl?: string; // Solana RPC endpoint (defaults to mainnet-beta)
ptUsdeThreshold?: string; // ptUSDe threshold for rebalancing (9 decimals)
ptUsdeTarget?: string; // ptUSDe target for rebalancing (9 decimals)
ptUsdeMaxRebalanceAmount?: string; // max usdc rebalance amount for rebalancing (6 decimals)
};
tacRebalance?: TokenRebalanceConfig;
methRebalance?: TokenRebalanceConfig;
Expand Down
43 changes: 18 additions & 25 deletions packages/poller/src/rebalance/solanaUsdc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,6 @@ const MIN_REBALANCING_AMOUNT = 1_000_000n; // 1 USDC
// Default operation timeout: 24 hours (in minutes)
const DEFAULT_OPERATION_TTL_MINUTES = 24 * 60;

// ============================================================================
// TESTING DEFAULTS - TODO: Update these values for production
// ============================================================================
// For testing, we use low thresholds (5 tokens) to trigger rebalancing easily.
// Production values should be significantly higher based on expected volumes.
//
// Environment variables to override:
// - PTUSDE_SOLANA_THRESHOLD: Minimum ptUSDe balance before rebalancing (9 decimals)
// - PTUSDE_SOLANA_TARGET: Target ptUSDe balance after rebalancing (9 decimals)
// - SOLANA_USDC_MAX_REBALANCE_AMOUNT: Maximum USDC per rebalance operation (6 decimals)
//
// ============================================================================
const DEFAULT_PTUSDE_THRESHOLD = 5n * BigInt(10 ** PTUSDE_SOLANA_DECIMALS); // 5 ptUSDe for testing
const DEFAULT_PTUSDE_TARGET = 10n * BigInt(10 ** PTUSDE_SOLANA_DECIMALS); // 10 ptUSDe for testing
const DEFAULT_MAX_REBALANCE_AMOUNT = 10n * BigInt(10 ** USDC_SOLANA_DECIMALS); // 10 USDC for testing

/**
* Check if an operation has exceeded its TTL (time-to-live).
* Operations stuck in PENDING or AWAITING_CALLBACK for too long should be marked as failed.
Expand Down Expand Up @@ -313,21 +297,30 @@ export async function rebalanceSolanaUsdc(context: ProcessingContext): Promise<R
}

// Values should be in native units (9 decimals for ptUSDe, 6 decimals for USDC)
const ptUsdeThresholdEnv = process.env['PTUSDE_SOLANA_THRESHOLD'];
const ptUsdeTargetEnv = process.env['PTUSDE_SOLANA_TARGET'];
const maxRebalanceAmountEnv = process.env['SOLANA_USDC_MAX_REBALANCE_AMOUNT'];
const ptUsdeThresholdEnv = config.solana?.ptUsdeThreshold;
const ptUsdeTargetEnv = config.solana?.ptUsdeTarget;
const ptUsdeMaxRebalanceAmountEnv = config.solana?.ptUsdeMaxRebalanceAmount;

if (!ptUsdeThresholdEnv || !ptUsdeTargetEnv || !ptUsdeMaxRebalanceAmountEnv) {
logger.error('Missing Solana USDC rebalancing configuration', {
requestId,
missingConfig: {
ptUsdeThresholdEnv,
ptUsdeTargetEnv,
ptUsdeMaxRebalanceAmountEnv,
},
});
return rebalanceOperations;
}

// TODO: Update defaults for production - current values are for testing
// Threshold: minimum ptUSDe balance that triggers rebalancing (in 9 decimals for Solana ptUSDe)
const ptUsdeThreshold = ptUsdeThresholdEnv ? safeParseBigInt(ptUsdeThresholdEnv) : DEFAULT_PTUSDE_THRESHOLD;
const ptUsdeThreshold = safeParseBigInt(ptUsdeThresholdEnv);

// Target: desired ptUSDe balance after rebalancing (in 9 decimals for Solana ptUSDe)
const ptUsdeTarget = ptUsdeTargetEnv ? safeParseBigInt(ptUsdeTargetEnv) : DEFAULT_PTUSDE_TARGET;
const ptUsdeTarget = safeParseBigInt(ptUsdeTargetEnv);

// Max rebalance amount per operation (in 6 decimals for USDC)
const maxRebalanceAmount = maxRebalanceAmountEnv
? safeParseBigInt(maxRebalanceAmountEnv)
: DEFAULT_MAX_REBALANCE_AMOUNT;
const maxRebalanceAmount = safeParseBigInt(ptUsdeMaxRebalanceAmountEnv);

logger.info('Checking ptUSDe balance threshold for rebalancing decision', {
requestId,
Expand Down