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 9 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 28.50% 28.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/algebra/v1 16.40% 17.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/ambient 11.80% 11.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/balancer-v1 29.60% 32.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/balancer-v2/composable-stable 36.50% 38.30% ✔️
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 21.20% 24.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/balancer-v2/weighted 28.90% 32.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/bancor-v21 25.10% 25.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/bancor-v3 34.90% 37.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/bebop 21.90% 21.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/bedrock/unieth 6.00% 6.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/clipper 23.60% 23.60% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/curve/plain 21.00% 21.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/curve/stable-meta-ng 9.00% 10.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/curve/stable-ng 11.40% 12.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/curve/tricrypto-ng 23.60% 24.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/curve/twocrypto-ng 22.90% 23.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/dai-usds 10.50% 17.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/deltaswap-v1 36.20% 36.20% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/dexalot 29.80% 29.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/dodo/classical 25.50% 28.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/dodo/dpp 10.80% 14.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/dodo/dsp 11.20% 14.60% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/dodo/dvm 11.70% 15.20% ✔️
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 9.10% 9.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/ether-vista 2.00% 2.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/etherfi/eeth 7.70% 7.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/etherfi/vampire 4.50% 4.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/etherfi/weeth 6.20% 6.20% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/fluid/dex-t1 53.10% 53.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/fluid/vault-t1 9.40% 9.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/frax/sfrxeth 9.00% 9.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/frax/sfrxeth-convertor 17.00% 17.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/generic-simple-rate 17.30% 21.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/gyroscope/2clp 30.30% 30.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/gyroscope/3clp 32.60% 32.60% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/gyroscope/eclp 50.10% 50.10% ✔️
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 43.90% 43.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/integral 21.90% 26.60% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/kelp/rseth 6.90% 6.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/kyber-pmm 0.00% 43.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/lo1inch 48.10% 48.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/mantle/meth 14.20% 14.20% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/mkr-sky 14.30% 21.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/mx-trading 35.00% 35.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/native-v1 31.00% 31.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/nomiswap/nomiswapstable 6.60% 7.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/ondo-usdy 13.60% 13.60% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/puffer/pufeth 10.70% 10.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/renzo/ezeth 5.70% 5.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/ringswap 11.00% 12.60% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/rocketpool/reth 10.40% 10.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/staderethx 15.50% 15.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/swaap-v2 19.90% 26.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/swell/rsweth 4.30% 4.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/swell/sweth 4.30% 4.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/syncswapv2/aqua 18.00% 20.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/syncswapv2/classic 15.40% 19.20% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/syncswapv2/stable 20.70% 24.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/uniswap-v1 8.60% 12.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/uniswap-v2 7.60% 9.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/usd0pp 13.70% 13.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/velocore-v2/cpmm 40.40% 42.60% ✔️
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 19.10% 23.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/velodrome-v1 26.40% 29.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/velodrome-v2 28.50% 31.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/virtual-fun 28.00% 28.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/woofi-v2 37.40% 41.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/woofi-v21 36.40% 39.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/algebrav1 16.40% 17.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/balancer-composable-stable 40.00% 42.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/balancer/stable 29.50% 33.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/balancer/weighted 29.60% 32.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/camelot 27.50% 31.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/curve/aave 19.00% 20.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/curve/base 11.80% 13.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/curve/compound 11.30% 12.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/curve/meta 19.10% 20.20% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/curve/plain-oracle 10.00% 11.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/curve/tricrypto 25.00% 26.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/curve/two 11.10% 12.20% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/dmm 19.40% 24.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/dodo 28.50% 31.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/equalizer 18.00% 22.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/fraxswap 13.40% 18.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/fulcrom 22.70% 26.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/fxdx 17.60% 19.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/gmx 22.90% 24.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/gmx-glp 22.70% 23.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/iziswap 19.40% 23.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/kokonut-crypto 19.90% 21.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/kyber-pmm 29.10% 32.60% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/lido 15.60% 21.60% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/lido-steth 12.70% 18.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/limitorder 29.90% 32.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/liquiditybookv20 24.90% 27.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/liquiditybookv21 33.10% 35.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/madmex 21.70% 23.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/makerpsm 23.30% 28.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/mantisswap 32.90% 36.20% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/maverickv1 48.30% 49.60% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/metavault 24.00% 25.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/nuriv2 14.50% 17.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pancakev3 30.30% 32.60% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/platypus 18.70% 21.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pol-matic 7.70% 15.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/quickperps 19.90% 21.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/ramsesv2 14.40% 17.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/saddle 46.70% 49.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/slipstream 14.00% 14.00% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/smardex 29.90% 34.10% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/solidly-v3 16.70% 19.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/swapbased-perp 26.60% 28.30% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/syncswap/syncswapclassic 20.10% 24.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/syncswap/syncswapstable 28.60% 32.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/synthetix 31.10% 32.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/traderjoev20 2.60% 2.60% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/traderjoev21 2.60% 2.60% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/uniswap 15.50% 16.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/uniswapv3 29.70% 31.90% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/usdfi 28.60% 33.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/velocimeter 29.80% 34.80% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/velodrome 29.40% 34.20% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/velodromev2 29.40% 34.40% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/vooi 22.00% 26.70% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/wombat/wombatlsd 20.20% 23.20% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/wombat/wombatmain 20.40% 23.50% ✔️
github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/woofiv2 36.10% 40.20% ✔️
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