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

feat: ✨ liq-src: kyber-pmm #624

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

thanhpp
Copy link
Member

@thanhpp thanhpp commented Nov 29, 2024

Why did we need it?

  • more liq for ks and avoid megadump

Related Issue

Release Note

How Has This Been Tested?

Screenshots (if appropriate):

@kyber-ci-bot
Copy link

kyber-ci-bot commented Nov 29, 2024

Test coverage changes:
Package Before After Diff
github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity 26.30% 26.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/algebra/integral 32.60% 32.60% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/algebra/v1 17.80% 17.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/ambient 17.90% 17.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/balancer-v1 42.80% 42.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/balancer-v2/composable-stable 48.70% 48.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/balancer-v2/math 49.00% 49.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/balancer-v2/stable 33.80% 33.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/balancer-v2/weighted 44.90% 44.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/bancor-v21 31.70% 31.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/bancor-v3 51.20% 51.20% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/bebop 26.40% 26.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/bedrock/unieth 16.90% 16.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/beets-ss 25.50% 25.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/clipper 50.00% 50.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/curve/plain 59.30% 59.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/curve/stable-meta-ng 41.40% 41.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/curve/stable-ng 37.70% 37.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/curve/tricrypto-ng 62.30% 62.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/curve/twocrypto-ng 61.10% 61.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/dai-usds 21.90% 21.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/deltaswap-v1 46.50% 46.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/dexalot 45.10% 45.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/dodo/classical 59.10% 59.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/dodo/dpp 38.50% 38.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/dodo/dsp 41.00% 41.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/dodo/dvm 49.50% 49.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/dodo/libv1 73.30% 73.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/dodo/libv2 37.60% 37.60% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/ethena/susde 27.10% 27.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/ether-vista 2.30% 2.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/etherfi/eeth 16.00% 16.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/etherfi/vampire 27.10% 27.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/etherfi/weeth 12.30% 12.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/fluid/dex-t1 72.50% 72.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/fluid/vault-t1 17.70% 17.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/frax/sfrxeth 18.00% 18.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/frax/sfrxeth-convertor 37.50% 37.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/generic-simple-rate 32.90% 32.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/gyroscope/2clp 42.30% 42.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/gyroscope/3clp 43.90% 43.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/gyroscope/eclp 58.80% 58.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/gyroscope/math 14.30% 14.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/hashflow-v3 74.30% 74.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/integral 35.70% 35.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/kelp/rseth 11.80% 11.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/kyber-pmm 0.00% 75.60% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/lo1inch 84.10% 84.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/mantle/meth 28.10% 28.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/mkr-sky 29.70% 29.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/mx-trading 72.00% 72.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/native-v1 69.20% 69.20% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/nomiswap/nomiswapstable 83.10% 83.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/ondo-usdy 23.90% 23.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/puffer/pufeth 22.80% 22.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/renzo/ezeth 9.40% 9.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/ringswap 10.70% 10.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/rocketpool/reth 26.10% 26.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/solidly-v2 39.90% 39.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/staderethx 28.00% 28.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/swaap-v2 56.40% 56.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/swell/rsweth 6.20% 6.20% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/swell/sweth 6.20% 6.20% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/syncswapv2/aqua 22.60% 22.60% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/syncswapv2/classic 32.30% 32.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/syncswapv2/stable 40.50% 40.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/uniswap-v1 14.10% 14.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/uniswap-v2 8.30% 8.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/usd0pp 27.30% 27.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/velocore-v2/cpmm 54.50% 54.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/velocore-v2/math 16.80% 16.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/velocore-v2/math/sd59x18 51.90% 51.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/velocore-v2/wombat-stable 30.40% 30.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/velodrome-v1 35.30% 35.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/velodrome-v2 40.30% 40.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/virtual-fun 39.10% 39.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/woofi-v2 55.20% 55.20% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/woofi-v21 57.50% 57.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/algebrav1 17.80% 17.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/balancer-composable-stable 55.40% 55.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/balancer/stable 78.10% 78.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/balancer/weighted 56.60% 56.60% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/camelot 38.70% 38.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/curve/aave 70.70% 70.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/curve/base 43.50% 43.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/curve/compound 75.40% 75.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/curve/meta 87.00% 87.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/curve/plain-oracle 38.50% 38.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/curve/tricrypto 70.30% 70.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/curve/two 29.20% 29.20% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/dmm 33.30% 33.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/dodo 36.40% 36.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/equalizer 28.80% 28.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/fraxswap 23.90% 23.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/fulcrom 31.40% 31.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/fxdx 20.90% 20.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/gmx 27.60% 27.60% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/gmx-glp 26.30% 26.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/iziswap 25.20% 25.20% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/kokonut-crypto 55.50% 55.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/kyber-pmm 38.50% 38.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/lido 22.80% 22.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/lido-steth 33.30% 33.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/limitorder 51.80% 51.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/liquiditybookv20 38.60% 38.60% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/liquiditybookv21 48.30% 48.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/madmex 25.10% 25.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/makerpsm 37.30% 37.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/mantisswap 53.10% 53.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/maverickv1 70.90% 70.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/metavault 28.40% 28.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/nuriv2 22.40% 22.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pancakev3 47.40% 47.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/platypus 25.90% 25.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pol-matic 18.90% 18.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/quickperps 23.90% 23.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/ramsesv2 22.00% 22.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/saddle 64.00% 64.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/slipstream 21.10% 21.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/smardex 46.20% 46.20% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/solidly-v3 28.40% 28.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/swapbased-perp 31.40% 31.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/syncswap/syncswapclassic 68.30% 68.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/syncswap/syncswapstable 82.50% 82.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/synthetix 38.00% 38.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/traderjoev20 12.80% 12.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/traderjoev21 12.20% 12.20% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/uniswap 17.00% 17.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/uniswapv3 45.00% 45.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/usdfi 44.10% 44.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/velocimeter 46.60% 46.60% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/velodrome 44.90% 44.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/velodromev2 45.60% 45.60% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/vooi 36.90% 36.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/wombat/wombatlsd 55.30% 55.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/wombat/wombatmain 56.50% 56.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/woofiv2 54.70% 54.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/util 4.50% 4.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/abi 75.00% 75.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/bignumber 14.80% 14.80% ✔️

"github.com/KyberNetwork/logger"
"github.com/dgraph-io/ristretto"

kyberpmm "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/kyber-pmm"
Copy link
Member

Choose a reason for hiding this comment

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

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/kyber-pmm"

Copy link
Member Author

Choose a reason for hiding this comment

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

updated in 3df5a23

@@ -0,0 +1,21 @@
package client
Copy link
Member

@lehainam-dev lehainam-dev Dec 4, 2024

Choose a reason for hiding this comment

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

Minor: I don't see any major changes in client pkg. Can we re-use the client pkg in source/kyber-pmm?

If eventually, we remove the source/kyber-pmm, then it's ok to add client here.

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm, i think we should move to a new pkg and remove the old one

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm, i think we should move to a new pkg and remove the old one

inventoryLimitIn = limit.GetLimit(param.TokenAmountIn.Token)
)
if param.TokenAmountIn.Amount.Cmp(inventoryLimitIn) > 0 {
return nil, errors.New("not enough inventory in")
Copy link
Member

Choose a reason for hiding this comment

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

We can move the error into error.go (same as CalcAmountIn PR)

Copy link
Member Author

Choose a reason for hiding this comment

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

updated in 3df5a23

Comment on lines 72 to 76
if slices.ContainsFunc(staticExtra.QuoteTokenAddresses, func(s string) bool {
return strings.EqualFold(s, entityPool.Tokens[i].Address)
}) {
quoteTokens = append(quoteTokens, *entityPool.Tokens[i])
}
Copy link
Member

Choose a reason for hiding this comment

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

Minor: Can we create a map first to check if the token exists?

Copy link
Member Author

Choose a reason for hiding this comment

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

updated in 3df5a23

timestamp: entityPool.Timestamp,
}, nil
}

Copy link
Member

@lehainam-dev lehainam-dev Dec 4, 2024

Choose a reason for hiding this comment

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

We need to write custom CanSwapFrom(baseToken) and CanSwapTo(quoteToken) functions here.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated in 3df5a23

return result
}

return []string{p.baseToken.Address}
Copy link
Member

Choose a reason for hiding this comment

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

You should check if the input address is in quoteTokens, then return the baseToken, otherwise, this should return nil.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated in 25bf1f3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants