Conversation
| else 0L | ||
|
|
||
| val feeCharged = rewardTokens * feePerToken | ||
| val isValidReward = (SELF.value.toBigInt - feeCharged) <= rewardTokens * price |
There was a problem hiding this comment.
Shouldn't this be >= instead? As we need enough ERGs to pay for the tokens.
There was a problem hiding this comment.
This contract only ensures a user gets at least (SELF.value.toBigInt - feeCharged) / price rewardTokens.
There was a problem hiding this comment.
For a newbie this is very confusing as the condition looks like tokensUserCanAffordToPayFor <= tokensToBuy which is like saying "ensure that user buys at least as many tokens as he can afford to buy" but maybe there can be more INPUTS 🤷
Remove reference to UniSwap 1.0
Remove reference to UniSwap 1.0
Add N2T contracts
|
|
||
| - Depositing. An amount of LP tokens taken from LP reserves is proportional to an amount of underlying assets deposited. `LP = min(X_deposited * LP_supply / X_reserved, Y_deposited * LP_supply / Y_reserved)` | ||
| - Redemption. Amounts of underlying assets redeemed are proportional to an amount of LP tokens returned. `X_redeemed = LP_returned * X_reserved / LP_supply`, `Y_redeemed = LP_returned * Y_reserved / LP_supply` | ||
| - Swap. Tokens are exchanged at a price corresponding to a relation of a pair’s reserve balances while preserving constant product constraint (`CP = X_reserved * Y_reserved`). Correct amount of protocol fees is paid (0.03% currently). `X_output = X_reserved * Y_input * 997 / (Y_reserved * 1000 + Y_input * 997)` |
eip-0014.md
Outdated
| tokens[1] | LP token reserves | ||
| tokens[2] | Asset X | ||
| tokens[3] | Asset Y | ||
| R4[Long] | Fee multiplier numerator (e.g. 0.003% fee -> 997 fee_num) |
eip-0014.md
Outdated
| ##### Contract parameters: | ||
| Constant | Type | Description | ||
| --------------------|------------|--------------- | ||
| Pk | ProveDLog | User PublicKey |
eip-0014.md
Outdated
| ##### Contract parameters: | ||
| Constant | Type | Description | ||
| ---------------|------------|--------------- | ||
| Pk | ProveDLog | User PublicKey |
eip-0014.md
Outdated
| ##### Contract parameters: | ||
| Constant | Type | Description | ||
| ---------------|------------|--------------- | ||
| Pk | ProveDLog | User PublicKey |
eip-0014.md
Outdated
| ###### Contract parameters | ||
| Constant | Type | Description | ||
| --------------------|------------|--------------- | ||
| Pk | ProveDLog | User PublicKey |
eip-0014.md
Outdated
| ###### Contract parameters: | ||
| Constant | Type | Description | ||
| --------------------|------------|--------------- | ||
| Pk | ProveDLog | User PublicKey |
| } | ||
| ``` | ||
|
|
||
| #### Swap proxy-contract |
There was a problem hiding this comment.
Please describe why proxy contracts are needed, how are they used.
| val quoteAsset = rewardBox.tokens(0) | ||
| val quoteAmount = quoteAsset._2.toBigInt | ||
| val fairDexFee = rewardBox.value >= SELF.value - quoteAmount * DexFeePerTokenNum / DexFeePerTokenDenom | ||
| val relaxedOutput = quoteAmount + 1L // handle rounding loss |
There was a problem hiding this comment.
We can imagine the case when there are no much tokens in the pool at all (maybe not so many issued), then this relaxation becomes significant?
|
|
||
| val validDeposit = | ||
| if (INPUTS.size == 2 && poolIn.tokens.size == 4) { | ||
| val validPoolIn = poolIn.tokens(0) == (PoolNFT, 1L) |
There was a problem hiding this comment.
No need to check that NFT is in quantity 1, we can save a bit of space.
|
|
||
| val validRedeem = | ||
| if (INPUTS.size == 2 && poolIn.tokens.size == 4) { | ||
| val validPoolIn = poolIn.tokens(0) == (PoolNFT, 1L) |
There was a problem hiding this comment.
Like before, avoid checking that NFT is in quantity 1
1. The check of "returnOut.value >= SELF.value - DexFee" is not needed, hence removed 2. Fix author list
Motivation
Act of exchange without trusted parties is a most basic primitive for decentralized finance on top of blockchains. Thus contracts for that were introduced early, and basic single-chain swap contract was introduced early in the ErgoScript whitepaper. Then a lot of other order contracts appeared: with partial filling, buyback guarantee and so on. What is good for traders in decentralized worlds, such contracts are usually composable.
While swap order contracts allows for orderbook-based decentralized exchanges (DEXes), now popular AMM-based DEXes (where AMM stands for Automated Market Maker) also possible on Ergo.
Interestingly, unlike other known blockchains, thanks to the extended UTXO model, liquidity pool contracts for AMM-based DEXes can be combined with order contracts (for orderbook-based DEXes). This gives unique possibility to have shared liquidity among different types of exchanges on top of the Ergo blockchain.
This PR provides known DEX contracts for both orderbook-based and AMM-based DEXes, and also provides info on their composability.