Skip to content

Commit

Permalink
Merge pull request #378 from hummingbot/fix/solana-fees
Browse files Browse the repository at this point in the history
(fix) jupiter fees
  • Loading branch information
fengtality authored Dec 26, 2024
2 parents 033a0ed + 47d6fa6 commit a392323
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
10 changes: 5 additions & 5 deletions src/chains/solana/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ export class Solana implements Solanaish {
unsafeMax: Math.max(Math.min(unsafeMax, maxPriorityFee), minPriorityFee),
};

console.debug('[PRIORITY FEES] Calculated priority fees:', result);
console.log('[PRIORITY FEES] Calculated priority fees:', result);

return result;
} catch (error: any) {
Expand Down Expand Up @@ -985,22 +985,22 @@ export class Solana implements Solanaish {
}

private increasePriorityFeeMultiplier(): void {
priorityFeeMultiplier += 3;
console.debug(`[PRIORITY FEE] Increased priorityFeeMultiplier to: ${priorityFeeMultiplier}`);
priorityFeeMultiplier += 1;
console.log(`[PRIORITY FEE] Increased priorityFeeMultiplier to: ${priorityFeeMultiplier}`);
}

private decreasePriorityFeeMultiplier(): void {
if (priorityFeeMultiplier <= 1) {
priorityFeeMultiplier = 1;
console.debug(
console.log(
`[PRIORITY FEE] Set priorityFeeMultiplier to minimum value: ${priorityFeeMultiplier}`,
);
return;
}

if (priorityFeeMultiplier > 1) {
priorityFeeMultiplier -= 1;
console.debug(`[PRIORITY FEE] Decreased priorityFeeMultiplier to: ${priorityFeeMultiplier}`);
console.log(`[PRIORITY FEE] Decreased priorityFeeMultiplier to: ${priorityFeeMultiplier}`);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/connectors/jupiter/jupiter.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ export namespace JupiterConfig {
tradingTypes: Array<string>;
chainType: string;
availableNetworks: Array<AvailableNetworks>;
gasLimitEstimate: number;
gasCost: number;
}

export const config: NetworkConfig = {
allowedSlippage: ConfigManagerV2.getInstance().get(
'jupiter.allowedSlippage',
),
gasLimitEstimate: ConfigManagerV2.getInstance().get(
'jupiter.gasLimitEstimate',
gasCost: ConfigManagerV2.getInstance().get(
'jupiter.gasCost',
),
tradingTypes: ['AMM'],
chainType: 'SOLANA',
Expand Down
9 changes: 3 additions & 6 deletions src/connectors/jupiter/jupiter.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,12 @@ export async function estimateGas(
jupiter: Jupiter,
): Promise<EstimateGasResponse> {
// TODO: get gas price from the network
const gasPrice: number = 0.00001
const gasLimit: number = jupiter.gasLimit;
const gasCost: string = (gasPrice * gasLimit).toString()
return {
network: solanaish.network,
timestamp: Date.now(),
gasPrice,
gasPrice: 0,
gasPriceToken: solanaish.nativeTokenSymbol,
gasLimit: gasLimit,
gasCost: gasCost,
gasLimit: 0,
gasCost: jupiter.gasCost.toString(),
};
}
6 changes: 3 additions & 3 deletions src/connectors/jupiter/jupiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export class Jupiter {
private _ready: boolean = false;
private _config: JupiterConfig.NetworkConfig;
protected jupiterQuoteApi!: ReturnType<typeof createJupiterApiClient>;
public gasLimit: number = 0;
public gasCost: number = 0;

private constructor(network: string) {
this._config = JupiterConfig.config;
this.chain = Solana.getInstance(network);
this.gasLimit = JupiterConfig.config.gasLimitEstimate;
this.gasCost = JupiterConfig.config.gasCost;
this.loadJupiter();
}

Expand Down Expand Up @@ -123,7 +123,7 @@ export class Jupiter {
userPublicKey: wallet.publicKey.toBase58(),
dynamicComputeUnitLimit: true,
prioritizationFeeLamports: {
autoMultiplier: Math.max(priorityFeeMultiplier, 3),
autoMultiplier: Math.min(priorityFeeMultiplier, 3),
},
},
});
Expand Down
4 changes: 2 additions & 2 deletions src/services/schema/jupiter-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"type": "object",
"properties": {
"allowedSlippage": { "type": "string" },
"gasLimitEstimate": { "type": "integer" }
"gasCost": { "type": "number" }
},
"additionalProperties": false,
"required": ["allowedSlippage", "gasLimitEstimate"]
"required": ["allowedSlippage", "gasCost"]
}
4 changes: 2 additions & 2 deletions src/templates/jupiter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# execution price. It uses a rational number for precision.
allowedSlippage: '5/100'

# the transaction gas amount used to estimate gasCost for a jupiter trade.
gasLimitEstimate: 1
# the default transaction gasCost in SOL for a jupiter trade.
gasCost: 0.0005

0 comments on commit a392323

Please sign in to comment.