Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update logic lo #643

Merged
merged 11 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ require (
github.com/ethereum/go-ethereum v1.14.12
github.com/go-resty/resty/v2 v2.14.0
github.com/goccy/go-json v0.10.3
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.6.0
github.com/holiman/uint256 v1.3.1
github.com/klauspost/compress v1.17.8
Expand All @@ -31,6 +30,7 @@ require (
github.com/orcaman/concurrent-map v1.0.0
github.com/pkg/errors v0.9.1
github.com/samber/lo v1.38.1
github.com/shopspring/decimal v1.4.0
github.com/sirupsen/logrus v1.9.3
github.com/sourcegraph/conc v0.3.0
github.com/stretchr/testify v1.9.0
Expand Down Expand Up @@ -63,7 +63,6 @@ require (
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/supranational/blst v0.3.13 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect
Expand Down
10 changes: 0 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo=
github.com/golang/glog v1.1.2/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/rLQ=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
Expand Down Expand Up @@ -231,7 +229,6 @@ github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAh
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
Expand All @@ -244,7 +241,6 @@ go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN8
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
Expand All @@ -255,7 +251,6 @@ golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
Expand All @@ -269,7 +264,6 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
Expand Down Expand Up @@ -300,8 +294,6 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down Expand Up @@ -341,15 +333,13 @@ golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE=
golang.org/x/tools v0.25.0/go.mod h1:/vtpO8WL1N9cQC3FN5zPqb//fRXskFHbLKk4OW1Q7rg=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
39 changes: 21 additions & 18 deletions pkg/source/limitorder/http_client_dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type (
Permit string `json:"permit"`
Interaction string `json:"interaction"`
ExpiredAt int64 `json:"expiredAt"`
IsTakerAssetFee bool `json:"isTakerAssetFee"`

AvailableMakingAmount string `json:"availableMakingAmount"`
MakerBalanceAllowance string `json:"makerBalanceAllowance"`
Expand Down Expand Up @@ -112,6 +113,7 @@ type (
Permit string `json:"permit"`
Interaction string `json:"interaction"`
ExpiredAt int64 `json:"expiredAt"`
IsTakerAssetFee bool `json:"isTakerAssetFee"`

AvailableMakingAmount *big.Int `json:"availableMakingAmount"`

Expand All @@ -132,24 +134,25 @@ func toOrder(ordersData []*orderData) ([]*order, error) {
result := make([]*order, len(ordersData))
for i, o := range ordersData {
result[i] = &order{
ID: o.ID,
Salt: o.Salt,
ChainID: o.ChainID,
Signature: o.Signature,
MakerAsset: o.MakerAsset,
TakerAsset: o.TakerAsset,
Maker: o.Maker,
Receiver: o.Receiver,
AllowedSenders: o.AllowedSenders,
FeeRecipient: o.FeeRecipient,
MakerAssetData: o.MakerAssetData,
TakerAssetData: o.TakerAssetData,
GetMakerAmount: o.GetMakerAmount,
GetTakerAmount: o.GetTakerAmount,
Predicate: o.Predicate,
Permit: o.Permit,
Interaction: o.Interaction,
ExpiredAt: o.ExpiredAt,
ID: o.ID,
Salt: o.Salt,
ChainID: o.ChainID,
Signature: o.Signature,
MakerAsset: o.MakerAsset,
TakerAsset: o.TakerAsset,
Maker: o.Maker,
Receiver: o.Receiver,
AllowedSenders: o.AllowedSenders,
FeeRecipient: o.FeeRecipient,
MakerAssetData: o.MakerAssetData,
TakerAssetData: o.TakerAssetData,
GetMakerAmount: o.GetMakerAmount,
GetTakerAmount: o.GetTakerAmount,
Predicate: o.Predicate,
Permit: o.Permit,
Interaction: o.Interaction,
ExpiredAt: o.ExpiredAt,
IsTakerAssetFee: o.IsTakerAssetFee,
}
makerTokenFeePercent, err := strconv.ParseInt(o.MakerTokenFeePercent, 10, 32)
if err != nil {
Expand Down
38 changes: 30 additions & 8 deletions pkg/source/limitorder/pool_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,18 @@ func (p *PoolSimulator) calcAmountWithSwapInfo(swapSide SwapSide, tokenAmountIn
continue
}

feeAmountWeiByOrder := p.calcFeeAmountPerOrder(order, filledMakingAmountWei)
totalFeeAmountWei = new(big.Int).Add(totalFeeAmountWei, feeAmountWeiByOrder)
actualAmountOut := new(big.Int).Sub(filledMakingAmountWei, feeAmountWeiByOrder)
var feeAmountWeiByOrder *big.Int
var actualAmountOut *big.Int
if order.IsTakerAssetFee {
// Calculate fee in taker asset
feeAmountWeiByOrder = p.calcFeeAmountPerOrder(order, remainingTakingAmountWei)
actualAmountOut = new(big.Int).Sub(remainingTakingAmountWei, feeAmountWeiByOrder)
Copy link
Member

@hieuvo hieuvo Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please double check the logic of this line, it doesn't look right to me 🤔

} else {
feeAmountWeiByOrder = p.calcFeeAmountPerOrder(order, filledMakingAmountWei)
actualAmountOut = new(big.Int).Sub(filledMakingAmountWei, feeAmountWeiByOrder)
}
totalAmountOutWei = new(big.Int).Add(totalAmountOutWei, actualAmountOut)
totalFeeAmountWei = new(big.Int).Add(totalFeeAmountWei, feeAmountWeiByOrder)
filledOrderInfo := newFilledOrderInfo(order, filledTakingAmountWei.String(), filledMakingAmountWei.String(), feeAmountWeiByOrder.String())
swapInfo.FilledOrders = append(swapInfo.FilledOrders, filledOrderInfo)
isFulfillAmountIn = true
Expand Down Expand Up @@ -305,9 +313,19 @@ func (p *PoolSimulator) calcAmountWithSwapInfo(swapSide SwapSide, tokenAmountIn
}
break
}

totalAmountIn = new(big.Int).Sub(totalAmountIn, remainingTakingAmountWei)
feeAmountWeiByOrder := p.calcFeeAmountPerOrder(order, remainingMakingAmountWei)
actualAmountOut := new(big.Int).Sub(remainingMakingAmountWei, feeAmountWeiByOrder)

var feeAmountWeiByOrder *big.Int
var actualAmountOut *big.Int
if order.IsTakerAssetFee {
// Calculate fee in taker asset
feeAmountWeiByOrder = p.calcFeeAmountPerOrder(order, remainingTakingAmountWei)
actualAmountOut = new(big.Int).Sub(remainingTakingAmountWei, feeAmountWeiByOrder)
} else {
feeAmountWeiByOrder = p.calcFeeAmountPerOrder(order, remainingMakingAmountWei)
actualAmountOut = new(big.Int).Sub(remainingMakingAmountWei, feeAmountWeiByOrder)
}
totalAmountOutWei = new(big.Int).Add(totalAmountOutWei, actualAmountOut)
totalFeeAmountWei = new(big.Int).Add(totalFeeAmountWei, feeAmountWeiByOrder)
filledOrderInfo := newFilledOrderInfo(order, remainingTakingAmountWei.String(), remainingMakingAmountWei.String(), feeAmountWeiByOrder.String())
Expand All @@ -320,12 +338,16 @@ func (p *PoolSimulator) calcAmountWithSwapInfo(swapSide SwapSide, tokenAmountIn
return totalAmountOutWei, swapInfo, totalFeeAmountWei, nil
}

// feeAmount = (params.makingAmount * params.order.makerTokenFeePercent + BPS - 1) / BPS
func (p *PoolSimulator) calcFeeAmountPerOrder(order *order, filledMakingAmount *big.Int) *big.Int {
// calcFeeAmountPerOrder calculates the fee amount for a filled order
// feeAmount = (filledAmount * order.makerTokenFeePercent + BPS - 1) / BPS
// where filledAmount is:
// - filledTakingAmount if order.IsTakerAssetFee is true
// - filledMakingAmount if order.IsTakerAssetFee is false
func (p *PoolSimulator) calcFeeAmountPerOrder(order *order, filledAmount *big.Int) *big.Int {
if order.MakerTokenFeePercent == 0 {
return constant.ZeroBI
}
amount := new(big.Int).Mul(filledMakingAmount, big.NewInt(int64(order.MakerTokenFeePercent)))
amount := new(big.Int).Mul(filledAmount, big.NewInt(int64(order.MakerTokenFeePercent)))
return new(big.Int).Div(new(big.Int).Sub(new(big.Int).Add(amount, valueobject.BasisPoint), constant.One), valueobject.BasisPoint)
}

Expand Down
115 changes: 115 additions & 0 deletions pkg/source/limitorder/pool_simulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,121 @@ func TestPool_CalcAmountOut(t *testing.T) {
want *pool.CalcAmountOutResult
err error
}{
{
name: "Should return correct CalcAmountOutResult when IsTakerAssetFee=true",
poolEntity: entity.Pool{
Address: "pool_limit_order_",
ReserveUsd: 1000000000,
AmplifiedTvl: 0,
SwapFee: 0,
Exchange: "kyberswap_limit-order",
Type: "limit-order",
Timestamp: 0,
Reserves: []string{"10000000000000000000", "10000000000000000000"},
Tokens: []*entity.PoolToken{
{
Address: "0x4200000000000000000000000000000000000006",
Name: "WETH",
Symbol: "WETH",
Decimals: 18,
Swappable: true,
},
{
Address: "0x1dd2d631c92b1acdfcdd51a0f7145a50130050c4",
Name: "ALB",
Symbol: "ALB",
Decimals: 18,
Swappable: true,
},
},
Extra: marshalPoolExtra(&Extra{
SellOrders: []*order{
{
ID: 1383,
ChainID: "5",
Salt: "154002081474686290844625688130661839166",
Signature: "signature1",
TakerAsset: "0x1dd2d631c92b1acdfcdd51a0f7145a50130050c4",
MakerAsset: "0x4200000000000000000000000000000000000006",
Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590",
Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590",
AllowedSenders: "0x0000000000000000000000000000000000000000",
TakingAmount: parseBigInt("10094237807104621"),
MakingAmount: parseBigInt("1000000000000"),
FeeConfig: parseBigInt("6277103196897319986124780282469434185881440815774577556840"),
FeeRecipient: "0x0000000000000000000000000000000000000000",
FilledMakingAmount: parseBigInt("0"),
FilledTakingAmount: parseBigInt("0"),
MakerTokenFeePercent: 100,
MakerAssetData: "",
TakerAssetData: "",
GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000000000000e8d4a510000000000000000000000000000000000000000000000000000023dca7e2c5526d",
GetTakerAmount: "296637bf000000000000000000000000000000000000000000000000000000e8d4a510000000000000000000000000000000000000000000000000000023dca7e2c5526d",
Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000008869bd40f0fe077f8857ad27e7cecdcafd4e52550000000000000000000000008869bd40f0fe077f8857ad27e7cecdcafd4e52550000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e30000000000000000000000002b9b20295b6f1bea547271982f62432f526706e9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b00000000000000000000000000000000000000000000000000000001235001cd00000000000000000000000000000000000000000000000000000000",
Permit: "",
Interaction: "",
ExpiredAt: 0,
IsTakerAssetFee: true,
},
},
BuyOrders: []*order{},
}),
TotalSupply: "",
},
args: args{
tokenAmountIn: pool.TokenAmount{
Token: "0x4200000000000000000000000000000000000006",
Amount: parseBigInt("1000000000000"),
AmountUsd: 0,
},
tokenOut: "0x1dd2d631c92b1acdfcdd51a0f7145a50130050c4",
},
want: &pool.CalcAmountOutResult{
TokenAmountOut: &pool.TokenAmount{
Token: "0x1dd2d631c92b1acdfcdd51a0f7145a50130050c4",
Amount: parseBigInt("9993295429033574"),
AmountUsd: 0,
},
Fee: &pool.TokenAmount{
Token: "0x4200000000000000000000000000000000000006",
Amount: parseBigInt("100942378071047"),
AmountUsd: 0,
},
Gas: 113308,
SwapInfo: SwapInfo{
AmountIn: "1000000000000",
SwapSide: Sell,
FilledOrders: []*FilledOrderInfo{
{
OrderID: 1383,
FilledTakingAmount: "1000000000000",
FilledMakingAmount: "99066419",
TakingAmount: "10094237807104621",
MakingAmount: "1000000000000",
Salt: "154002081474686290844625688130661839166",
TakerAsset: "0x1dd2d631c92b1acdfcdd51a0f7145a50130050c4",
MakerAsset: "0x4200000000000000000000000000000000000006",
Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590",
Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590",
AllowedSenders: "0x0000000000000000000000000000000000000000",
GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000000000000e8d4a510000000000000000000000000000000000000000000000000000023dca7e2c5526d",
GetTakerAmount: "296637bf000000000000000000000000000000000000000000000000000000e8d4a510000000000000000000000000000000000000000000000000000023dca7e2c5526d",
FeeConfig: "6277103196897319986124780282469434185881440815774577556840",
FeeRecipient: "0x0000000000000000000000000000000000000000",
MakerTokenFeePercent: 100,
MakerAssetData: "",
TakerAssetData: "",
Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000008869bd40f0fe077f8857ad27e7cecdcafd4e52550000000000000000000000008869bd40f0fe077f8857ad27e7cecdcafd4e52550000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e30000000000000000000000002b9b20295b6f1bea547271982f62432f526706e9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b00000000000000000000000000000000000000000000000000000001235001cd00000000000000000000000000000000000000000000000000000000",
Permit: "",
Interaction: "",
Signature: "signature1",
FeeAmount: "100942378071047",
},
},
},
},
err: nil,
},
{
name: "Should return correct CalcAmountOutResult when swapSide is BUY(strings.ToLower(tokeIn) <= strings.ToLower(TokenOut))",
poolEntity: entity.Pool{
Expand Down
Loading