Skip to content

Commit

Permalink
feat : add DefaultGas for Iziswap (#580)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunspirit99 authored Nov 11, 2024
1 parent 3549700 commit 383da40
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/source/iziswap/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ const (
SIMULATOR_PT_RANGE = 2000
)

var zeroBI = big.NewInt(0)

var (
DefaultGas = Gas{Swap: 210000}
zeroBI = big.NewInt(0)
)
var pointDeltas = map[int]int{
100: 1,
400: 8,
Expand Down
5 changes: 5 additions & 0 deletions pkg/source/iziswap/pool_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
type PoolSimulator struct {
pool.Pool
PoolInfo swap.PoolInfo
gas Gas
}

func NewPoolSimulator(entityPool entity.Pool) (*PoolSimulator, error) {
Expand Down Expand Up @@ -107,6 +108,7 @@ func (p *PoolSimulator) CalcAmountOut(param pool.CalcAmountOutParams) (*pool.Cal
Token: tokenAmountIn.Token,
Amount: nil,
},
Gas: p.gas.Swap,
SwapInfo: iZiSwapInfo{
nextPoint: ret.CurrentPoint,
nextLiquidity: new(big.Int).Set(ret.Liquidity),
Expand Down Expand Up @@ -134,6 +136,7 @@ func (p *PoolSimulator) CalcAmountOut(param pool.CalcAmountOutParams) (*pool.Cal
Token: tokenAmountIn.Token,
Amount: nil,
},
Gas: p.gas.Swap,
SwapInfo: iZiSwapInfo{
nextPoint: ret.CurrentPoint,
nextLiquidity: new(big.Int).Set(ret.Liquidity),
Expand Down Expand Up @@ -200,6 +203,7 @@ func (p *PoolSimulator) CalcAmountIn(param pool.CalcAmountInParams) (*pool.CalcA
Token: tokenAmountOut.Token,
Amount: nil,
},
Gas: p.gas.Swap,
SwapInfo: swapInfo,
}, nil
} else {
Expand Down Expand Up @@ -230,6 +234,7 @@ func (p *PoolSimulator) CalcAmountIn(param pool.CalcAmountInParams) (*pool.CalcA
Token: tokenAmountOut.Token,
Amount: nil,
},
Gas: p.gas.Swap,
SwapInfo: iZiSwapInfo{
nextPoint: ret.CurrentPoint,
nextLiquidity: new(big.Int).Set(ret.Liquidity),
Expand Down
4 changes: 4 additions & 0 deletions pkg/source/iziswap/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ type Metadata struct {
type Meta struct {
LimitPoint int `json:"limitPoint"`
}

type Gas struct {
Swap int64
}

0 comments on commit 383da40

Please sign in to comment.