unisWAPV2PAIR,薄荷功能,如何创建流动性与添加的流动性的比例

发布于 2025-01-31 11:51:21 字数 260 浏览 6 评论 0 原文

function mint(address to) external lock returns (uint liquidity) {
   
}

以上功能的实现使流动性被添加到要解决的地址中,但是流动性只是根据储备金的差异和代币的差异而铸造的,它将如何根据发件人添加的流动性成比例地创建流动性,

我是否缺少某些东西,是否丢失了某些东西,如果用户始终调用薄荷功能,他将不会在地址中添加免费的LP代币,因为我们可以看到薄荷功能是外部的,而不是内部

function mint(address to) external lock returns (uint liquidity) {
   
}

The function above is implemented such that liquidity is added to the to address, however the liquidity is just minted depending on the difference of reserves and balance of token how will it create the liquidity in proportion to liquidity added by sender,

Am i missing something, what if a user always calls the mint function will he not get free LP token added to the address as we can see that the mint function is external not internal

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

葬花如无物 2025-02-07 11:51:21

我错过了一些东西,如果用户总是称呼薄荷功能,他将不会在地址中添加免费的LP令牌,因为我们可以看到薄荷功能是外部的,而不是内部

您缺少功能主体和所有逻辑并在内部进行检查它。

Am i missing something, what if a user always calls the mint function will he not get free LP token added to the address as we can see that the mint function is external not internal

You are missing the function body and all the logic and checks inside it.

无言温柔 2025-02-07 11:51:21

如果用户始终调用薄荷功能,该怎么办,他不会在地址中添加免费的LP令牌

mint()函数本身只有薄荷lp令牌可以弥补实际LP平衡和预期LP平衡之间的差异。如果实际和预期余额之间没有区别,则没有LP令牌。

一种常见的做法是使用路由器函数将令牌发送到配对合同,然后调用 mint()函数 - 这两者都是一项交易的一部分,因此无法完成此操作。

如果有基本令牌发送到该配对合同的情况下,而无需调用 mint()函数,那么任何人都可以自由调用该函数以代表此差异的LP令牌。但是,只有一次,作为LP薄荷零,差异。

what if a user always calls the mint function will he not get free LP token added to the address

The mint() function itself only mints LP tokens to make up for a difference between actual LP balance and expected LP balance. If there's no difference between the actual and expected balances, no LP tokens are minted.

A common practice is to use the router function addLiquidity() which sends tokens to the Pair contract, and then invokes the mint() function - both as part of one transaction, so there's no way to frontrun this action.

If there were underlying tokens sent to the Pair contract without invoking the mint() function, then anyone could invoke this function freely claiming LP tokens representing this difference. However only once, as the LP mint zeros up the difference.

完美的未来在梦里 2025-02-07 11:51:21

如果用户总是调用薄荷功能,该怎么办
添加到地址的令牌,因为我们可以看到薄荷功能是
外部而不是内部

当用户添加流动性时,

mint()被调用。

但是,流动性只是根据
代币的储备和平衡将如何创造流动性
与发件人添加的流动性比例,

因为主要方程是基于增加的流动性与LP令牌股票的增加成正比。这是有道理的,因为增加流动性对价格没有影响,因此,如果您增加了更多的流动性,则应该收到与收到的LP代币成正比的,例如,

假设您拥有T股,并且希望将流动性从L0提高到L1。还会为您造成多少股?

L1 / L0 = (T + mintAmount)/T

我们需要查找 mintamount

(L1/L0) * T = T + mintAmount // leave mintAmount alone

((L1/L0)*T) - T = mintAmount // multiply T with L0/L0

((L1/L0)*T) - (T*L0)/L0 = mintAmount

最后

mintAmount = ((L1-L0)/L0) * T

what if a user always calls the mint function will he not get free LP
token added to the address as we can see that the mint function is
external not internal

mint() is called when a user added liquidity.

however the liquidity is just minted depending on the difference of
reserves and balance of token how will it create the liquidity in
proportion to liquidity added by sender,

Because the main equation is based on increasing liquidity is proportional to an increase in LP token shares. This makes sense because adding liquidity has no effect on price, so if you add more liquidity, you should receive LP tokens proportional to what you have received before

Let's say you have T shares and you want to increase liquidity from L0 to L1. How many more shares will be minted for you?

L1 / L0 = (T + mintAmount)/T

We need to find mintAmount.

(L1/L0) * T = T + mintAmount // leave mintAmount alone

((L1/L0)*T) - T = mintAmount // multiply T with L0/L0

((L1/L0)*T) - (T*L0)/L0 = mintAmount

Finally

mintAmount = ((L1-L0)/L0) * T
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文