Skip to content

Commit

Permalink
updated base fee to use EIP1559 by default and osmosis config for it.…
Browse files Browse the repository at this point in the history
… changed reduceLiquidity() to return array of amount/base/symbol instead of static # of coins (for pools with >2 token types). also changed swap fees to use sim() by default.
  • Loading branch information
chasevoorhees committed Nov 25, 2023
1 parent 455fd64 commit 7bca960
Show file tree
Hide file tree
Showing 12 changed files with 471 additions and 242 deletions.
27 changes: 15 additions & 12 deletions docs/swagger/definitions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1008,10 +1008,7 @@ definitions:
- 'gasUsed'
- 'gasWanted'
- 'txHash'
- 'token0'
- 'token1'
- 'amount0'
- 'amount1'
- 'balances'
properties:
network:
type: 'string'
Expand All @@ -1031,14 +1028,20 @@ definitions:
type: 'string'
txHash:
type: 'string'
token0:
type: 'string'
token1:
type: 'string'
amount0:
type: 'string'
amount1:
type: 'string'
balances:
type: 'array'
items: 'object'
required:
- 'amount'
- 'denom'
- 'symbol'
properties:
amount:
type: 'string'
denom:
type: 'string'
symbol:
type: 'string'

LiquidityCollectRequest:
type: 'object'
Expand Down
7 changes: 2 additions & 5 deletions src/amm/amm.requests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SerializableExtendedPool as CosmosSerializableExtendedPool } from '../chains/osmosis/osmosis.types';
import { CoinAndSymbol, SerializableExtendedPool as CosmosSerializableExtendedPool } from '../chains/osmosis/osmosis.types';
import { PerpPosition } from '../connectors/perp/perp';
import {
NetworkSelectionRequest,
Expand Down Expand Up @@ -247,10 +247,7 @@ export interface CosmosRemoveLiquidityResponse {
gasUsed: string;
gasWanted: string;
txHash: string;
token0: string;
token1: string;
amount0: string;
amount1: string;
balances: CoinAndSymbol[];
}

export interface PositionRequest extends NetworkSelectionRequest {
Expand Down
30 changes: 29 additions & 1 deletion src/chains/cosmos/cosmos-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const { toBase64, fromBase64, fromHex } = require('@cosmjs/encoding');
const crypto = require('crypto').webcrypto;

import { osmosis } from 'osmojs';
import { getEIP1559DynamicBaseFee } from '../osmosis/osmosis.prices';
const { createRPCQueryClient } = osmosis.ClientFactory;

export class CosmosAsset implements Asset {
Expand Down Expand Up @@ -157,19 +158,29 @@ export class CosmosBase {
public tokenListType: TokenListType;
public cache: NodeCache;

public manualGasPrice: string;
public rpcAddressDynamicBaseFee: string;
public useEIP1559DynamicBaseFeeInsteadOfManualGasPrice: boolean;

constructor(
chainName: string,
rpcUrl: string,
tokenListSource: string,
tokenListType: TokenListType,
gasPriceConstant: number
gasPriceConstant: number, // adjustment
useEIP1559DynamicBaseFeeInsteadOfManualGasPrice?: boolean,
rpcAddressDynamicBaseFee?: string,
manualGasPrice?: string
) {
this.manualGasPrice = manualGasPrice!;
this.chainName = chainName;
this.rpcUrl = rpcUrl;
this.gasPriceConstant = gasPriceConstant;
this.tokenListSource = tokenListSource;
this.tokenListType = tokenListType;
this.cache = new NodeCache({ stdTTL: 3600 }); // set default cache ttl to 1hr
this.useEIP1559DynamicBaseFeeInsteadOfManualGasPrice = useEIP1559DynamicBaseFeeInsteadOfManualGasPrice!
this.rpcAddressDynamicBaseFee = rpcAddressDynamicBaseFee!
}

ready(): boolean {
Expand All @@ -185,6 +196,14 @@ export class CosmosBase {
if (!this.ready()) {
if (this.chainName == 'osmosis'){
this._provider = await createRPCQueryClient({rpcEndpoint: this.rpcUrl});

if (this.useEIP1559DynamicBaseFeeInsteadOfManualGasPrice){
const eipPrice = await getEIP1559DynamicBaseFee(this.rpcAddressDynamicBaseFee);
if (eipPrice != ''){
this.manualGasPrice = eipPrice;
}
}

}else{
this._provider = StargateClient.connect(this.rpcUrl);
}
Expand All @@ -203,6 +222,15 @@ export class CosmosBase {
return;
}

async getLatestBasePrice(): Promise<string> {
var eipPrice = this.manualGasPrice;
if (this.useEIP1559DynamicBaseFeeInsteadOfManualGasPrice){
eipPrice = await getEIP1559DynamicBaseFee(this.rpcAddressDynamicBaseFee);
}
this.manualGasPrice = eipPrice;
return this.manualGasPrice
}

async loadTokens(
tokenListSource: string,
tokenListType: TokenListType
Expand Down
2 changes: 1 addition & 1 deletion src/chains/cosmos/cosmos.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const toCosmosBalances = (
tokenSymbols.forEach((symbol) => {
let balance = '0.0';

if (balances[symbol]) {
if (balances[symbol]) {// && !balances[symbol].value.eq(0)) { // is check necessary here or filtered in client?
balance = tokenValueToString(balances[symbol]);
}

Expand Down
4 changes: 4 additions & 0 deletions src/chains/osmosis/osmosis.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export namespace OsmosisConfig {
gasLimitTransaction: string;
manualGasPrice: string;
allowedSlippage: string;
rpcAddressDynamicBaseFee: string;
useEIP1559DynamicBaseFeeInsteadOfManualGasPrice: boolean;
}

export const config: NetworkConfig = {
Expand Down Expand Up @@ -49,5 +51,7 @@ export namespace OsmosisConfig {
gasAdjustment: ConfigManagerV2.getInstance().get(`osmosis.gasAdjustment`),
allowedSlippage: ConfigManagerV2.getInstance().get(`osmosis.allowedSlippage`),
feeTier: ConfigManagerV2.getInstance().get(`osmosis.feeTier`),
useEIP1559DynamicBaseFeeInsteadOfManualGasPrice: ConfigManagerV2.getInstance().get(`osmosis.useEIP1559DynamicBaseFeeInsteadOfManualGasPrice`),
rpcAddressDynamicBaseFee: ConfigManagerV2.getInstance().get(`osmosis.rpcAddressDynamicBaseFee`),
};
}
Loading

0 comments on commit 7bca960

Please sign in to comment.