-
Notifications
You must be signed in to change notification settings - Fork 57
Implement genesis liquidity protocol #545
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
Merged
Merged
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
c1bcb0f
add genesis liquidity implementation
da51543
Merge branch 'develop' of https://github.com/serai-dex/serai into emi…
b9df73e
add missing deposit event
2b32fe9
fix CI issues
207f2bd
minor fixes
c320402
make math safer
8be0538
fix fmt
df774d1
Merge branch 'develop' of https://github.com/serai-dex/serai into emi…
7041dbe
make remove liquidity an authorized call
826f998
implement setting initial values for coins
926ddd0
add genesis liquidity test & misc fixes
7ecbfde
Merge branch 'develop' of https://github.com/serai-dex/serai into emi…
20cf4c9
updato develop latest
90a5232
Merge branch 'develop' of https://github.com/serai-dex/serai into emi…
04fcb2b
fix rotation test
929d0bf
Merge branch 'develop' of https://github.com/akildemir/serai into emi…
ad70bce
Merge branch 'develop' into HEAD
kayabaNerve 28edc66
Finish merging develop
kayabaNerve f75fe67
Remove accidentally committed ETH files
kayabaNerve c14923f
fix pr comments
ef70384
further bug fixes
1eee0a4
fix last pr comments
9d50fe7
tidy up
4104650
Merge branch 'develop' into HEAD
kayabaNerve b040dce
Misc
kayabaNerve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
pub use serai_genesis_liquidity_primitives as primitives; | ||
|
||
use serai_primitives::*; | ||
use primitives::*; | ||
|
||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)] | ||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
pub enum Call { | ||
remove_coin_liquidity { balance: Balance }, | ||
oraclize_values { prices: Prices, signature: Signature }, | ||
} | ||
|
||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)] | ||
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))] | ||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
pub enum Event { | ||
GenesisLiquidityAdded { by: SeraiAddress, balance: Balance }, | ||
GenesisLiquidityRemoved { by: SeraiAddress, balance: Balance }, | ||
GenesisLiquidityAddedToPool { coin1: Balance, coin2: Balance }, | ||
EconomicSecurityReached { network: NetworkId }, | ||
akildemir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use serai_primitives::{Balance, SeraiAddress}; | ||
akildemir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)] | ||
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))] | ||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
pub enum Call { | ||
burn { balance: Balance }, | ||
transfer { to: SeraiAddress, balance: Balance }, | ||
} | ||
|
||
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)] | ||
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))] | ||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
pub enum Event { | ||
Mint { to: SeraiAddress, balance: Balance }, | ||
Burn { from: SeraiAddress, balance: Balance }, | ||
Transfer { from: SeraiAddress, to: SeraiAddress, balance: Balance }, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
pub use serai_abi::genesis_liquidity::primitives; | ||
use primitives::Prices; | ||
|
||
use serai_abi::primitives::*; | ||
|
||
use sp_core::sr25519::Signature; | ||
|
||
use scale::Encode; | ||
|
||
use crate::{Serai, SeraiError, TemporalSerai, Transaction}; | ||
|
||
pub type GenesisLiquidityEvent = serai_abi::genesis_liquidity::Event; | ||
|
||
const PALLET: &str = "GenesisLiquidity"; | ||
|
||
#[derive(Clone, Copy)] | ||
pub struct SeraiGenesisLiquidity<'a>(pub(crate) &'a TemporalSerai<'a>); | ||
impl<'a> SeraiGenesisLiquidity<'a> { | ||
pub async fn events(&self) -> Result<Vec<GenesisLiquidityEvent>, SeraiError> { | ||
self | ||
.0 | ||
.events(|event| { | ||
if let serai_abi::Event::GenesisLiquidity(event) = event { | ||
Some(event.clone()) | ||
} else { | ||
None | ||
} | ||
}) | ||
.await | ||
} | ||
|
||
pub fn oraclize_values(prices: Prices, signature: Signature) -> Transaction { | ||
Serai::unsigned(serai_abi::Call::GenesisLiquidity( | ||
serai_abi::genesis_liquidity::Call::oraclize_values { prices, signature }, | ||
)) | ||
} | ||
|
||
pub fn remove_coin_liquidity(balance: Balance) -> serai_abi::Call { | ||
serai_abi::Call::GenesisLiquidity(serai_abi::genesis_liquidity::Call::remove_coin_liquidity { | ||
balance, | ||
}) | ||
} | ||
|
||
pub async fn liquidity( | ||
&self, | ||
address: &SeraiAddress, | ||
coin: Coin, | ||
) -> Result<(Amount, Amount), SeraiError> { | ||
Ok( | ||
self | ||
.0 | ||
.storage( | ||
PALLET, | ||
"Liquidity", | ||
(coin, sp_core::hashing::blake2_128(&address.encode()), &address.0), | ||
) | ||
.await? | ||
.unwrap_or((Amount(0), Amount(0))), | ||
) | ||
} | ||
|
||
pub async fn supply(&self, coin: Coin) -> Result<(Amount, Amount), SeraiError> { | ||
Ok(self.0.storage(PALLET, "Supply", coin).await?.unwrap_or((Amount(0), Amount(0)))) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use scale::Encode; | ||
|
||
use serai_abi::primitives::{SeraiAddress, Amount, Coin, Balance}; | ||
|
||
use crate::{TemporalSerai, SeraiError}; | ||
|
||
const PALLET: &str = "LiquidityTokens"; | ||
|
||
#[derive(Clone, Copy)] | ||
pub struct SeraiLiquidityTokens<'a>(pub(crate) &'a TemporalSerai<'a>); | ||
impl<'a> SeraiLiquidityTokens<'a> { | ||
pub async fn token_supply(&self, coin: Coin) -> Result<Amount, SeraiError> { | ||
Ok(self.0.storage(PALLET, "Supply", coin).await?.unwrap_or(Amount(0))) | ||
} | ||
|
||
pub async fn token_balance( | ||
&self, | ||
coin: Coin, | ||
address: SeraiAddress, | ||
) -> Result<Amount, SeraiError> { | ||
Ok( | ||
self | ||
.0 | ||
.storage( | ||
PALLET, | ||
"Balances", | ||
(sp_core::hashing::blake2_128(&address.encode()), &address.0, coin), | ||
) | ||
.await? | ||
.unwrap_or(Amount(0)), | ||
) | ||
} | ||
|
||
pub fn transfer(to: SeraiAddress, balance: Balance) -> serai_abi::Call { | ||
serai_abi::Call::LiquidityTokens(serai_abi::liquidity_tokens::Call::transfer { to, balance }) | ||
} | ||
|
||
pub fn burn(balance: Balance) -> serai_abi::Call { | ||
serai_abi::Call::LiquidityTokens(serai_abi::liquidity_tokens::Call::burn { balance }) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.