From 7884316bc6cf62b805e16ee10b6cd75c1a77a3d6 Mon Sep 17 00:00:00 2001 From: Chien Nguyen Date: Wed, 18 Dec 2024 11:54:16 +0700 Subject: [PATCH] Reduce the length of new tests Reduce the length of tests 2 Reduce the length of tests 3 --- .../pool_simulator_calc_amount_in_test.go | 1290 +++-------------- 1 file changed, 226 insertions(+), 1064 deletions(-) diff --git a/pkg/source/limitorder/pool_simulator_calc_amount_in_test.go b/pkg/source/limitorder/pool_simulator_calc_amount_in_test.go index 63a207ace..b810506d2 100644 --- a/pkg/source/limitorder/pool_simulator_calc_amount_in_test.go +++ b/pkg/source/limitorder/pool_simulator_calc_amount_in_test.go @@ -2,6 +2,7 @@ package limitorder import ( "math/big" + "strconv" "testing" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" @@ -31,91 +32,10 @@ func TestPool_CalcAmountIn(t *testing.T) { }{ { name: "Should return correct CalcAmountInResult when swapSide is BUY(strings.ToLower(tokeIn) <= strings.ToLower(TokenOut))", - 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: tokenUSDT, - Name: "USDT", - Symbol: "USDT", - Decimals: 6, - Swappable: true, - }, - { - Address: tokenUSDC, - Name: "USDC", - Symbol: "USDC", - Decimals: 6, - Swappable: true, - }, - }, - Extra: marshalPoolExtra(&Extra{ - BuyOrders: []*order{ - { - ID: 1383, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature1", - TakerAsset: tokenUSDT, - MakerAsset: tokenUSDC, - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("200"), - MakingAmount: parseBigInt("400"), - FeeConfig: parseBigInt("100"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - }, - { - ID: 1382, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature2", - TakerAsset: tokenUSDT, - MakerAsset: tokenUSDC, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("300"), - MakingAmount: parseBigInt("300"), - FeeConfig: parseBigInt("100"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - IsTakerAssetFee: true, - }, - }, - SellOrders: []*order{}, - }), - TotalSupply: "", - }, + poolEntity: newExamplePool(t, nil, []*order{ + newExampleOrder(t, 1, tokenUSDT, big.NewInt(200), big.NewInt(0), tokenUSDC, big.NewInt(400), big.NewInt(0), 0, false), + newExampleOrder(t, 2, tokenUSDT, big.NewInt(300), big.NewInt(0), tokenUSDC, big.NewInt(300), big.NewInt(0), 0, true), + }), args: args{ tokenAmountOut: pool.TokenAmount{ Token: tokenUSDT, @@ -140,55 +60,20 @@ func TestPool_CalcAmountIn(t *testing.T) { AmountIn: "300", SwapSide: Buy, FilledOrders: []*FilledOrderInfo{ - { - OrderID: 1383, - FilledTakingAmount: "200", - FilledMakingAmount: "400", - TakingAmount: "200", - MakingAmount: "400", - Salt: "185786982651412687203851465093295409688", - TakerAsset: tokenUSDT, - MakerAsset: tokenUSDC, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - FeeConfig: "100", - FeeRecipient: "0x0000000000000000000000000000000000000000", - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - Signature: "signature1", - FeeAmount: "0", - }, - { - OrderID: 1382, - FilledTakingAmount: "100", - FilledMakingAmount: "100", - TakingAmount: "300", - MakingAmount: "300", - Salt: "185786982651412687203851465093295409688", - Signature: "signature2", - TakerAsset: tokenUSDT, - MakerAsset: tokenUSDC, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - FeeConfig: "100", - FeeRecipient: "0x0000000000000000000000000000000000000000", - AllowedSenders: "0x0000000000000000000000000000000000000000", - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - FeeAmount: "0", - }, + newExampleFilledOrderInfo( + t, + 1, + tokenUSDT, big.NewInt(200), big.NewInt(200), + tokenUSDC, big.NewInt(400), big.NewInt(400), + big.NewInt(0), 0, + ), + newExampleFilledOrderInfo( + t, + 2, + tokenUSDT, big.NewInt(300), big.NewInt(100), + tokenUSDC, big.NewInt(300), big.NewInt(100), + big.NewInt(0), 0, + ), }, }, }, @@ -196,88 +81,10 @@ func TestPool_CalcAmountIn(t *testing.T) { }, { name: "Should return correct CalcAmountInResult when swapSide is SELL(strings.ToLower(tokeIn) > strings.ToLower(TokenOut))", - 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: tokenUSDT, - Name: "USDT", - Symbol: "USDT", - Decimals: 6, - Swappable: true, - }, - { - Address: tokenUSDC, - Name: "USDC", - Symbol: "USDC", - Decimals: 6, - Swappable: true, - }, - }, - Extra: marshalPoolExtra(&Extra{ - SellOrders: []*order{ - { - ID: 1383, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature1", - TakerAsset: tokenUSDC, - MakerAsset: tokenUSDT, - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("992000"), - MakingAmount: parseBigInt("1000000"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - }, - { - ID: 1382, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature2", - TakerAsset: tokenUSDC, - MakerAsset: tokenUSDT, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("1010000"), - MakingAmount: parseBigInt("1000000"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - }, - }, - BuyOrders: []*order{}, - }), - TotalSupply: "", - }, + poolEntity: newExamplePool(t, []*order{ + newExampleOrder(t, 1, tokenUSDC, big.NewInt(992_000), big.NewInt(0), tokenUSDT, big.NewInt(1_000_000), big.NewInt(0), 0, false), + newExampleOrder(t, 2, tokenUSDC, big.NewInt(1_010_000), big.NewInt(0), tokenUSDT, big.NewInt(1_000_000), big.NewInt(0), 0, false), + }, nil), args: args{ tokenAmountOut: pool.TokenAmount{ Token: tokenUSDC, @@ -302,53 +109,20 @@ func TestPool_CalcAmountIn(t *testing.T) { AmountIn: "1210000", SwapSide: Sell, FilledOrders: []*FilledOrderInfo{ - { - OrderID: 1383, - FilledTakingAmount: "992000", - FilledMakingAmount: "1000000", - TakingAmount: "992000", - MakingAmount: "1000000", - Salt: "185786982651412687203851465093295409688", - TakerAsset: tokenUSDC, - MakerAsset: tokenUSDT, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - FeeRecipient: "0x0000000000000000000000000000000000000000", - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - Signature: "signature1", - FeeAmount: "0", - }, - { - OrderID: 1382, - FilledTakingAmount: "218000", - FilledMakingAmount: "215841", - TakingAmount: "1010000", - MakingAmount: "1000000", - Salt: "185786982651412687203851465093295409688", - Signature: "signature2", - TakerAsset: tokenUSDC, - MakerAsset: tokenUSDT, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - FeeRecipient: "0x0000000000000000000000000000000000000000", - AllowedSenders: "0x0000000000000000000000000000000000000000", - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - FeeAmount: "0", - }, + newExampleFilledOrderInfo( + t, + 1, + tokenUSDC, big.NewInt(992_000), big.NewInt(992_000), + tokenUSDT, big.NewInt(1_000_000), big.NewInt(1_000_000), + big.NewInt(0), 0, + ), + newExampleFilledOrderInfo( + t, + 2, + tokenUSDC, big.NewInt(1_010_000), big.NewInt(218_000), + tokenUSDT, big.NewInt(1_000_000), big.NewInt(215_841), + big.NewInt(0), 0, + ), }, }, }, @@ -356,90 +130,10 @@ func TestPool_CalcAmountIn(t *testing.T) { }, { name: "Should return correct CalcAmountInResult when swapSide is BUY(strings.ToLower(tokeIn) <= strings.ToLower(TokenOut)) and orders has MakerTokenFeePercent", - 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: tokenUSDT, - Name: "USDT", - Symbol: "USDT", - Decimals: 6, - Swappable: true, - }, - { - Address: tokenUSDC, - Name: "USDC", - Symbol: "USDC", - Decimals: 6, - Swappable: true, - }, - }, - Extra: marshalPoolExtra(&Extra{ - BuyOrders: []*order{ - { - ID: 1383, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature1", - TakerAsset: tokenUSDT, - MakerAsset: tokenUSDC, - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("200"), - MakingAmount: parseBigInt("400"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 100, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - IsTakerAssetFee: true, - }, - { - ID: 1382, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature2", - TakerAsset: tokenUSDT, - MakerAsset: tokenUSDC, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("300"), - MakingAmount: parseBigInt("300"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - IsTakerAssetFee: true, - }, - }, - SellOrders: []*order{}, - }), - TotalSupply: "", - }, + poolEntity: newExamplePool(t, nil, []*order{ + newExampleOrder(t, 1383, tokenUSDT, big.NewInt(200), big.NewInt(0), tokenUSDC, big.NewInt(400), big.NewInt(0), 100, true), + newExampleOrder(t, 1382, tokenUSDT, big.NewInt(300), big.NewInt(0), tokenUSDC, big.NewInt(300), big.NewInt(0), 0, true), + }), args: args{ tokenAmountOut: pool.TokenAmount{ Token: tokenUSDT, @@ -464,53 +158,18 @@ func TestPool_CalcAmountIn(t *testing.T) { AmountIn: "300", SwapSide: Buy, FilledOrders: []*FilledOrderInfo{ - { - OrderID: 1383, - FilledTakingAmount: "200", - FilledMakingAmount: "400", - TakingAmount: "200", - MakingAmount: "400", - Salt: "185786982651412687203851465093295409688", - TakerAsset: tokenUSDT, - MakerAsset: tokenUSDC, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - FeeRecipient: "0x0000000000000000000000000000000000000000", - MakerTokenFeePercent: 100, - MakerAssetData: "", - TakerAssetData: "", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - Signature: "signature1", - FeeAmount: "2", - }, - { - OrderID: 1382, - FilledTakingAmount: "100", - FilledMakingAmount: "100", - TakingAmount: "300", - MakingAmount: "300", - Salt: "185786982651412687203851465093295409688", - Signature: "signature2", - TakerAsset: tokenUSDT, - MakerAsset: tokenUSDC, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - FeeRecipient: "0x0000000000000000000000000000000000000000", - AllowedSenders: "0x0000000000000000000000000000000000000000", - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - FeeAmount: "0", - }, + newExampleFilledOrderInfo(t, + 1383, + tokenUSDT, big.NewInt(200), big.NewInt(200), + tokenUSDC, big.NewInt(400), big.NewInt(400), + big.NewInt(2), 100, + ), + newExampleFilledOrderInfo(t, + 1382, + tokenUSDT, big.NewInt(300), big.NewInt(100), + tokenUSDC, big.NewInt(300), big.NewInt(100), + big.NewInt(0), 0, + ), }, }, }, @@ -518,138 +177,12 @@ func TestPool_CalcAmountIn(t *testing.T) { }, { name: "Should return correct CalcAmountInResult and list orders(include fallback orders) when swapSide is SELL(strings.ToLower(tokeIn) > strings.ToLower(TokenOut))", - 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: tokenUSDT, - Name: "USDT", - Symbol: "USDT", - Decimals: 6, - Swappable: true, - }, - { - Address: tokenUSDC, - Name: "USDC", - Symbol: "USDC", - Decimals: 6, - Swappable: true, - }, - }, - Extra: marshalPoolExtra(&Extra{ - SellOrders: []*order{ - { - ID: 1383, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature1", - TakerAsset: tokenUSDC, - MakerAsset: tokenUSDT, - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("700"), - MakingAmount: parseBigInt("1400"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - }, - { - ID: 1382, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature2", - TakerAsset: tokenUSDC, - MakerAsset: tokenUSDT, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("240"), - MakingAmount: parseBigInt("250"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - }, - { - ID: 1385, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature4", - TakerAsset: tokenUSDC, - MakerAsset: tokenUSDT, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("200"), - MakingAmount: parseBigInt("300"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - }, - { - ID: 1389, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature5", - TakerAsset: tokenUSDC, - MakerAsset: tokenUSDT, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("100"), - MakingAmount: parseBigInt("100"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - }, - }, - BuyOrders: []*order{}, - }), - TotalSupply: "", - }, + poolEntity: newExamplePool(t, []*order{ + newExampleOrder(t, 1383, tokenUSDC, big.NewInt(700), big.NewInt(0), tokenUSDT, big.NewInt(1400), big.NewInt(0), 0, false), + newExampleOrder(t, 1382, tokenUSDC, big.NewInt(240), big.NewInt(0), tokenUSDT, big.NewInt(250), big.NewInt(0), 0, false), + newExampleOrder(t, 1385, tokenUSDC, big.NewInt(200), big.NewInt(0), tokenUSDT, big.NewInt(300), big.NewInt(0), 0, false), + newExampleOrder(t, 1389, tokenUSDC, big.NewInt(100), big.NewInt(0), tokenUSDT, big.NewInt(100), big.NewInt(0), 0, false), + }, nil), args: args{ tokenAmountOut: pool.TokenAmount{ Token: tokenUSDC, @@ -674,79 +207,24 @@ func TestPool_CalcAmountIn(t *testing.T) { AmountIn: "700", SwapSide: Sell, FilledOrders: []*FilledOrderInfo{ - { - OrderID: 1383, - FilledTakingAmount: "700", - FilledMakingAmount: "1400", - TakingAmount: "700", - MakingAmount: "1400", - Salt: "185786982651412687203851465093295409688", - TakerAsset: tokenUSDC, - MakerAsset: tokenUSDT, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - FeeRecipient: "0x0000000000000000000000000000000000000000", - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - Signature: "signature1", - FeeAmount: "0", - }, - { - OrderID: 1382, - FilledTakingAmount: "0", - FilledMakingAmount: "0", - TakingAmount: "240", - MakingAmount: "250", - Salt: "185786982651412687203851465093295409688", - Signature: "signature2", - TakerAsset: tokenUSDC, - MakerAsset: tokenUSDT, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - FeeRecipient: "0x0000000000000000000000000000000000000000", - AllowedSenders: "0x0000000000000000000000000000000000000000", - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - FeeAmount: "0", - IsFallBack: true, - }, - { - OrderID: 1385, - Salt: "185786982651412687203851465093295409688", - Signature: "signature4", - TakerAsset: tokenUSDC, - MakerAsset: tokenUSDT, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: "200", - MakingAmount: "300", - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: "0", - FilledTakingAmount: "0", - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - IsFallBack: true, - FeeAmount: "0", - }, + newExampleFilledOrderInfo(t, + 1383, + tokenUSDC, big.NewInt(700), big.NewInt(700), + tokenUSDT, big.NewInt(1400), big.NewInt(1400), + big.NewInt(0), 0, + ), + newExampleFallBackOrderInfo(t, + 1382, + tokenUSDC, big.NewInt(240), + tokenUSDT, big.NewInt(250), + 0, + ), + newExampleFallBackOrderInfo(t, + 1385, + tokenUSDC, big.NewInt(200), + tokenUSDT, big.NewInt(300), + 0, + ), }, }, }, @@ -754,88 +232,10 @@ func TestPool_CalcAmountIn(t *testing.T) { }, { name: "Should return correct error(ErrCannotFulfillAmountIn) when cannot fulfill amountIn buy the orders", - 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: tokenUSDT, - Name: "USDT", - Symbol: "USDT", - Decimals: 6, - Swappable: true, - }, - { - Address: tokenUSDC, - Name: "USDC", - Symbol: "USDC", - Decimals: 6, - Swappable: true, - }, - }, - Extra: marshalPoolExtra(&Extra{ - SellOrders: []*order{ - { - ID: 1383, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature1", - TakerAsset: tokenUSDC, - MakerAsset: tokenUSDT, - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("992000"), - MakingAmount: parseBigInt("1000000"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - }, - { - ID: 1382, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature2", - TakerAsset: tokenUSDC, - MakerAsset: tokenUSDT, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("1010000"), - MakingAmount: parseBigInt("1000000"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - }, - }, - BuyOrders: []*order{}, - }), - TotalSupply: "", - }, + poolEntity: newExamplePool(t, []*order{ + newExampleOrder(t, 1383, tokenUSDC, big.NewInt(992_000), big.NewInt(0), tokenUSDT, big.NewInt(1_000_000), big.NewInt(0), 0, false), + newExampleOrder(t, 1382, tokenUSDC, big.NewInt(1_010_000), big.NewInt(0), tokenUSDT, big.NewInt(1_000_000), big.NewInt(0), 0, false), + }, nil), args: args{ tokenAmountOut: pool.TokenAmount{ Token: tokenUSDC, @@ -883,91 +283,10 @@ func TestPool_CalcAmountOut_CalcAmountIn(t *testing.T) { }{ { name: "Should return correct CalcAmountInResult and CalcAmountOutResult when swapSide is BUY(strings.ToLower(tokeIn) <= strings.ToLower(TokenOut))", - 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: tokenUSDT, - Name: "USDT", - Symbol: "USDT", - Decimals: 6, - Swappable: true, - }, - { - Address: tokenUSDC, - Name: "USDC", - Symbol: "USDC", - Decimals: 6, - Swappable: true, - }, - }, - Extra: marshalPoolExtra(&Extra{ - BuyOrders: []*order{ - { - ID: 1383, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature1", - TakerAsset: tokenUSDT, - MakerAsset: tokenUSDC, - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("200"), - MakingAmount: parseBigInt("400"), - FeeConfig: parseBigInt("100"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - }, - { - ID: 1382, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature2", - TakerAsset: tokenUSDT, - MakerAsset: tokenUSDC, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("300"), - MakingAmount: parseBigInt("300"), - FeeConfig: parseBigInt("100"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - IsTakerAssetFee: true, - }, - }, - SellOrders: []*order{}, - }), - TotalSupply: "", - }, + poolEntity: newExamplePool(t, nil, []*order{ + newExampleOrder(t, 1, tokenUSDT, big.NewInt(200), big.NewInt(0), tokenUSDC, big.NewInt(400), big.NewInt(0), 0, false), + newExampleOrder(t, 2, tokenUSDT, big.NewInt(300), big.NewInt(0), tokenUSDC, big.NewInt(300), big.NewInt(0), 0, true), + }), args: args{ tokenIn: tokenUSDC, amountIn: parseBigInt("300"), @@ -978,88 +297,10 @@ func TestPool_CalcAmountOut_CalcAmountIn(t *testing.T) { }, { name: "Should return correct CalcAmountInResult and CalcAmountOutResult when swapSide is SELL(strings.ToLower(tokeIn) > strings.ToLower(TokenOut))", - 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: tokenUSDT, - Name: "USDT", - Symbol: "USDT", - Decimals: 6, - Swappable: true, - }, - { - Address: tokenUSDC, - Name: "USDC", - Symbol: "USDC", - Decimals: 6, - Swappable: true, - }, - }, - Extra: marshalPoolExtra(&Extra{ - SellOrders: []*order{ - { - ID: 1383, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature1", - TakerAsset: tokenUSDC, - MakerAsset: tokenUSDT, - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("992000"), - MakingAmount: parseBigInt("1000000"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - }, - { - ID: 1382, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature2", - TakerAsset: tokenUSDC, - MakerAsset: tokenUSDT, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("1010000"), - MakingAmount: parseBigInt("1000000"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - }, - }, - BuyOrders: []*order{}, - }), - TotalSupply: "", - }, + poolEntity: newExamplePool(t, []*order{ + newExampleOrder(t, 1, tokenUSDC, big.NewInt(992_000), big.NewInt(0), tokenUSDT, big.NewInt(1_000_000), big.NewInt(0), 0, false), + newExampleOrder(t, 2, tokenUSDC, big.NewInt(1_010_000), big.NewInt(0), tokenUSDT, big.NewInt(1_000_000), big.NewInt(0), 0, false), + }, nil), args: args{ tokenIn: tokenUSDT, @@ -1071,90 +312,10 @@ func TestPool_CalcAmountOut_CalcAmountIn(t *testing.T) { }, { name: "Should return correct CalcAmountInResult and CalcAmountOutResult when swapSide is BUY(strings.ToLower(tokeIn) <= strings.ToLower(TokenOut)) and orders has MakerTokenFeePercent", - 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: tokenUSDT, - Name: "USDT", - Symbol: "USDT", - Decimals: 6, - Swappable: true, - }, - { - Address: tokenUSDC, - Name: "USDC", - Symbol: "USDC", - Decimals: 6, - Swappable: true, - }, - }, - Extra: marshalPoolExtra(&Extra{ - BuyOrders: []*order{ - { - ID: 1383, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature1", - TakerAsset: tokenUSDT, - MakerAsset: tokenUSDC, - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("200"), - MakingAmount: parseBigInt("400"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 100, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - IsTakerAssetFee: true, - }, - { - ID: 1382, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature2", - TakerAsset: tokenUSDT, - MakerAsset: tokenUSDC, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("300"), - MakingAmount: parseBigInt("300"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - IsTakerAssetFee: true, - }, - }, - SellOrders: []*order{}, - }), - TotalSupply: "", - }, + poolEntity: newExamplePool(t, nil, []*order{ + newExampleOrder(t, 1383, tokenUSDT, big.NewInt(200), big.NewInt(0), tokenUSDC, big.NewInt(400), big.NewInt(0), 100, true), + newExampleOrder(t, 1382, tokenUSDT, big.NewInt(300), big.NewInt(0), tokenUSDC, big.NewInt(300), big.NewInt(0), 0, true), + }), args: args{ tokenIn: tokenUSDC, amountIn: parseBigInt("302"), @@ -1165,138 +326,12 @@ func TestPool_CalcAmountOut_CalcAmountIn(t *testing.T) { }, { name: "Should return correct CalcAmountInResult and CalcAmountOutResult and list orders(include fallback orders) when swapSide is SELL(strings.ToLower(tokeIn) > strings.ToLower(TokenOut))", - 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: tokenUSDT, - Name: "USDT", - Symbol: "USDT", - Decimals: 6, - Swappable: true, - }, - { - Address: tokenUSDC, - Name: "USDC", - Symbol: "USDC", - Decimals: 6, - Swappable: true, - }, - }, - Extra: marshalPoolExtra(&Extra{ - SellOrders: []*order{ - { - ID: 1383, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature1", - TakerAsset: tokenUSDC, - MakerAsset: tokenUSDT, - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("700"), - MakingAmount: parseBigInt("1400"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - }, - { - ID: 1382, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature2", - TakerAsset: tokenUSDC, - MakerAsset: tokenUSDT, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("240"), - MakingAmount: parseBigInt("250"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - }, - { - ID: 1385, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature4", - TakerAsset: tokenUSDC, - MakerAsset: tokenUSDT, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("200"), - MakingAmount: parseBigInt("300"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - }, - { - ID: 1389, - ChainID: "5", - Salt: "185786982651412687203851465093295409688", - Signature: "signature5", - TakerAsset: tokenUSDC, - MakerAsset: tokenUSDT, - Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", - AllowedSenders: "0x0000000000000000000000000000000000000000", - TakingAmount: parseBigInt("100"), - MakingAmount: parseBigInt("100"), - FeeRecipient: "0x0000000000000000000000000000000000000000", - FilledMakingAmount: parseBigInt("0"), - FilledTakingAmount: parseBigInt("0"), - MakerTokenFeePercent: 0, - MakerAssetData: "", - TakerAssetData: "", - GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", - Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", - Permit: "", - Interaction: "", - ExpiredAt: 0, - }, - }, - BuyOrders: []*order{}, - }), - TotalSupply: "", - }, + poolEntity: newExamplePool(t, []*order{ + newExampleOrder(t, 1383, tokenUSDC, big.NewInt(700), big.NewInt(0), tokenUSDT, big.NewInt(1400), big.NewInt(0), 0, false), + newExampleOrder(t, 1382, tokenUSDC, big.NewInt(240), big.NewInt(0), tokenUSDT, big.NewInt(250), big.NewInt(0), 0, false), + newExampleOrder(t, 1385, tokenUSDC, big.NewInt(200), big.NewInt(0), tokenUSDT, big.NewInt(300), big.NewInt(0), 0, false), + newExampleOrder(t, 1389, tokenUSDC, big.NewInt(100), big.NewInt(0), tokenUSDT, big.NewInt(100), big.NewInt(0), 0, false), + }, nil), args: args{ tokenIn: tokenUSDT, amountIn: parseBigInt("700"), @@ -1344,5 +379,132 @@ func TestPool_CalcAmountOut_CalcAmountIn(t *testing.T) { assert.Equal(t, tt.args.amountIn, calcAmountInResult.TokenAmountIn.Amount) }) } +} + +func newExamplePool(t *testing.T, sellOrders, buyOrders []*order) entity.Pool { + t.Helper() + return 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: tokenUSDT, + Name: "USDT", + Symbol: "USDT", + Decimals: 6, + Swappable: true, + }, + { + Address: tokenUSDC, + Name: "USDC", + Symbol: "USDC", + Decimals: 6, + Swappable: true, + }, + }, + Extra: marshalPoolExtra(&Extra{ + BuyOrders: buyOrders, + SellOrders: sellOrders, + }), + TotalSupply: "", + } +} + +func newExampleOrder( + t *testing.T, + id int64, + takerAsset string, takingAmount, filledTakingAmount *big.Int, + makerAsset string, makingAmount, filledMakingAmount *big.Int, + makerTokenFeePercent uint32, IsTakerAssetFee bool, +) *order { + t.Helper() + + return &order{ + ID: id, + ChainID: "5", + Salt: "185786982651412687203851465093295409688", + Signature: "signature" + strconv.Itoa(int(id)), + TakerAsset: takerAsset, + MakerAsset: makerAsset, + Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", + Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", + AllowedSenders: "0x0000000000000000000000000000000000000000", + TakingAmount: takingAmount, + MakingAmount: makingAmount, + FeeConfig: parseBigInt("100"), + FeeRecipient: "0x0000000000000000000000000000000000000000", + FilledMakingAmount: filledMakingAmount, + FilledTakingAmount: filledTakingAmount, + MakerTokenFeePercent: makerTokenFeePercent, + MakerAssetData: "", + TakerAssetData: "", + GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", + GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", + Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", + Permit: "", + Interaction: "", + ExpiredAt: 0, + IsTakerAssetFee: IsTakerAssetFee, + } +} + +func newExampleFallBackOrderInfo( + t *testing.T, + orderID int64, + takerAsset string, takingAmount *big.Int, + makerAsset string, makingAmount *big.Int, + makerTokenFeePercent uint32, +) *FilledOrderInfo { + t.Helper() + o := newExampleFilledOrderInfo( + t, orderID, + takerAsset, takingAmount, big.NewInt(0), + makerAsset, makingAmount, big.NewInt(0), + big.NewInt(0), makerTokenFeePercent, + ) + o.IsFallBack = true + return o +} + +func newExampleFilledOrderInfo( + t *testing.T, + orderID int64, + takerAsset string, takingAmount, filledTakingAmount *big.Int, + makerAsset string, makingAmount, filledMakingAmount *big.Int, + feeAmount *big.Int, makerTokenFeePercent uint32, +) *FilledOrderInfo { + t.Helper() + + return &FilledOrderInfo{ + OrderID: orderID, + FilledTakingAmount: filledTakingAmount.String(), + FilledMakingAmount: filledMakingAmount.String(), + TakingAmount: takingAmount.String(), + MakingAmount: makingAmount.String(), + Salt: "185786982651412687203851465093295409688", + TakerAsset: takerAsset, + MakerAsset: makerAsset, + Maker: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", + Receiver: "0xa246ec8bf7f2e54cc2f7bfdd869302ae4a08a590", + AllowedSenders: "0x0000000000000000000000000000000000000000", + GetMakerAmount: "f4a215c3000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", + GetTakerAmount: "296637bf000000000000000000000000000000000000000000000001d7d843dc3b4800000000000000000000000000000000000000000000000000000de0b6b3a7640000", + FeeConfig: "100", + FeeRecipient: "0x0000000000000000000000000000000000000000", + MakerTokenFeePercent: makerTokenFeePercent, + MakerAssetData: "", + TakerAssetData: "", + Predicate: "961d5b1e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000002892e28b58ab329741f27fd1ea56dca0192a38840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044cf6fc6e3000000000000000000000000a246ec8bf7f2e54cc2f7bfdd869302ae4a08a590000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002463592c2b0000000000000000000000000000000000000000000000000000000063c1169800000000000000000000000000000000000000000000000000000000", + Permit: "", + Interaction: "", + Signature: "signature" + strconv.Itoa(int(orderID)), + FeeAmount: feeAmount.String(), + } }