Skip to content

Commit

Permalink
Integrate solidly-v2 (#671)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunspirit99 committed Dec 31, 2024
1 parent 30b872c commit 26eb4c6
Show file tree
Hide file tree
Showing 28 changed files with 3,126 additions and 100 deletions.
8 changes: 6 additions & 2 deletions pkg/liquidity-source/curve/stable-ng/math.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package stableng

import (
"fmt"
"math"
"time"

Expand Down Expand Up @@ -315,8 +316,11 @@ func (t *PoolSimulator) GetDx(
) (err error) {
defer func() {
if r := recover(); r != nil {
err = errors.Wrapf(ErrExecutionReverted, "recovered error: %v", r.(error))
return
if recoveredError, ok := r.(error); ok {
err = errors.Wrapf(ErrExecutionReverted, "recovered error: %v", recoveredError)
} else {
err = fmt.Errorf("unexpected panic: %v", r)
}
}
}()

Expand Down
7 changes: 6 additions & 1 deletion pkg/liquidity-source/deltaswap-v1/pool_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package deltaswapv1

import (
"errors"
"fmt"
"math/big"

"github.com/KyberNetwork/blockchain-toolkit/integer"
Expand Down Expand Up @@ -260,7 +261,11 @@ func (s *PoolSimulator) getAmountOut(amountIn, reserveIn, reserveOut, fee *uint2
func (s *PoolSimulator) getAmountIn(amountOut, reserveIn, reserveOut, fee *uint256.Int) (amountIn *uint256.Int, err error) {
defer func() {
if r := recover(); r != nil {
err = r.(error)
if recoveredError, ok := r.(error); ok {
err = recoveredError
} else {
err = fmt.Errorf("unexpected panic: %v", r)
}
}
}()

Expand Down
8 changes: 7 additions & 1 deletion pkg/liquidity-source/dodo/classical/sell_helper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package classical

import (
"fmt"

"github.com/holiman/uint256"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/dodo/libv1"
Expand All @@ -23,7 +25,11 @@ func (p *PoolSimulator) querySellQuoteToken(amount *uint256.Int) (
) {
defer func() {
if r := recover(); r != nil {
err = r.(error)
if recoveredError, ok := r.(error); ok {
err = recoveredError
} else {
err = fmt.Errorf("unexpected panic: %v", r)
}
}
}()

Expand Down
14 changes: 12 additions & 2 deletions pkg/liquidity-source/dodo/classical/trader.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package classical

import (
"fmt"

"github.com/holiman/uint256"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/dodo/libv1"
Expand All @@ -18,7 +20,11 @@ func (p *PoolSimulator) _querySellBaseToken(amount *uint256.Int) (
) {
defer func() {
if r := recover(); r != nil {
err = r.(error)
if recoveredError, ok := r.(error); ok {
err = recoveredError
} else {
err = fmt.Errorf("unexpected panic: %v", r)
}
}
}()

Expand Down Expand Up @@ -75,7 +81,11 @@ func (p *PoolSimulator) _queryBuyBaseToken(amount *uint256.Int) (
) {
defer func() {
if r := recover(); r != nil {
err = r.(error)
if recoveredError, ok := r.(error); ok {
err = recoveredError
} else {
err = fmt.Errorf("unexpected panic: %v", r)
}
}
}()

Expand Down
14 changes: 12 additions & 2 deletions pkg/liquidity-source/dodo/dpp/trader.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dpp

import (
"fmt"

"github.com/holiman/uint256"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/dodo/libv2"
Expand All @@ -15,7 +17,11 @@ func (p *PoolSimulator) querySellBase(payBaseAmount *uint256.Int) (
) {
defer func() {
if r := recover(); r != nil {
err = r.(error)
if recoveredError, ok := r.(error); ok {
err = recoveredError
} else {
err = fmt.Errorf("unexpected panic: %v", r)
}
}
}()

Expand All @@ -42,7 +48,11 @@ func (p *PoolSimulator) querySellQuote(payQuoteAmount *uint256.Int) (
) {
defer func() {
if r := recover(); r != nil {
err = r.(error)
if recoveredError, ok := r.(error); ok {
err = recoveredError
} else {
err = fmt.Errorf("unexpected panic: %v", r)
}
}
}()

Expand Down
14 changes: 12 additions & 2 deletions pkg/liquidity-source/dodo/dsp/trader.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dsp

import (
"fmt"

"github.com/holiman/uint256"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/dodo/libv2"
Expand All @@ -15,7 +17,11 @@ func (p *PoolSimulator) querySellBase(payBaseAmount *uint256.Int) (
) {
defer func() {
if r := recover(); r != nil {
err = r.(error)
if recoveredError, ok := r.(error); ok {
err = recoveredError
} else {
err = fmt.Errorf("unexpected panic: %v", r)
}
}
}()

Expand All @@ -42,7 +48,11 @@ func (p *PoolSimulator) querySellQuote(payQuoteAmount *uint256.Int) (
) {
defer func() {
if r := recover(); r != nil {
err = r.(error)
if recoveredError, ok := r.(error); ok {
err = recoveredError
} else {
err = fmt.Errorf("unexpected panic: %v", r)
}
}
}()

Expand Down
14 changes: 12 additions & 2 deletions pkg/liquidity-source/dodo/dvm/trader.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dvm

import (
"fmt"

"github.com/holiman/uint256"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/dodo/libv2"
Expand All @@ -15,7 +17,11 @@ func (p *PoolSimulator) querySellBase(payBaseAmount *uint256.Int) (
) {
defer func() {
if r := recover(); r != nil {
err = r.(error)
if recoveredError, ok := r.(error); ok {
err = recoveredError
} else {
err = fmt.Errorf("unexpected panic: %v", r)
}
}
}()

Expand All @@ -42,7 +48,11 @@ func (p *PoolSimulator) querySellQuote(payQuoteAmount *uint256.Int) (
) {
defer func() {
if r := recover(); r != nil {
err = r.(error)
if recoveredError, ok := r.(error); ok {
err = recoveredError
} else {
err = fmt.Errorf("unexpected panic: %v", r)
}
}
}()

Expand Down
7 changes: 6 additions & 1 deletion pkg/liquidity-source/ringswap/pool_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ringswap

import (
"errors"
"fmt"
"math/big"

"github.com/KyberNetwork/blockchain-toolkit/integer"
Expand Down Expand Up @@ -295,7 +296,11 @@ func (s *PoolSimulator) getAmountOut(amountIn, reserveIn, reserveOut *uint256.In
func (s *PoolSimulator) getAmountIn(amountOut, reserveIn, reserveOut *uint256.Int) (amountIn *uint256.Int, err error) {
defer func() {
if r := recover(); r != nil {
err = r.(error)
if recoveredError, ok := r.(error); ok {
err = recoveredError
} else {
err = fmt.Errorf("unexpected panic: %v", r)
}
}
}()

Expand Down
34 changes: 34 additions & 0 deletions pkg/liquidity-source/solidly-v2/abis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package solidlyv2

import (
"bytes"

"github.com/ethereum/go-ethereum/accounts/abi"
)

var (
poolABI abi.ABI
factoryABI abi.ABI
)

func init() {
builder := []struct {
ABI *abi.ABI
data []byte
}{
{
&poolABI, poolABIJson,
},
{
&factoryABI, factoryABIJson,
},
}

for _, b := range builder {
var err error
*b.ABI, err = abi.JSON(bytes.NewReader(b.data))
if err != nil {
panic(err)
}
}
}
Loading

0 comments on commit 26eb4c6

Please sign in to comment.