-
Notifications
You must be signed in to change notification settings - Fork 2
Aptos: add to pool (WIP) #460
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 all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
343fa35
feat(core): Add PoolState interface to core
nicomiicro a4d8dae
feat(core): Add getPoolState to client interface
nicomiicro cf1e61d
feat(aptos): implement client.getPoolState
nicomiicro bcb6fcd
feat(ui): add aptos pool state queries
nicomiicro 634b35e
fix(aptos): use proper resource type in getTokenBalance
nicomiicro eedbc49
Merge branch 'aptos/contracts' into aptos/add-to-pool
nicomiicro dfcba14
refactor(ui): define local AptosPoolState
nicomiicro cdf1422
refactor(aptos): remove AptosPoolState
nicomiicro 8b3c262
refactor(aptos): tidy up utils and types
nicomiicro 9d0af66
Merge branch 'aptos/contracts' into aptos/add-to-pool
nicomiicro 4f3fd60
refactor(aptos): rename const to constants
nicomiicro c7156f1
refactor(aptos): rename getBalances to getPoolBalances
nicomiicro 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
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
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
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,3 @@ | ||
| // From https://github.com/pontem-network/liquidswap/blob/b89aed9adb96c0b083134765f75be814418be670/sources/swap/liquidity_pool.move#L70-L74 | ||
| export const FEE_DECIMALS = 4; | ||
| export const DAO_FEE_DECIMALS = 2; |
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,3 @@ | ||
| export * from "./constants"; | ||
| export * from "./types"; | ||
| export * from "./utils"; |
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,20 @@ | ||
| import type { Types } from "aptos"; | ||
|
|
||
| export interface PoolResource { | ||
| readonly data: { | ||
| readonly coin_x_reserve: { | ||
| readonly value: string; | ||
| }; | ||
| readonly coin_y_reserve: { | ||
| readonly value: string; | ||
| }; | ||
| readonly dao_fee: string; | ||
| readonly fee: string; | ||
| readonly last_block_timestamp: string; | ||
| readonly last_price_x_cumulative: string; | ||
| readonly last_price_y_cumulative: string; | ||
| readonly x_scale: string; | ||
| readonly y_scale: string; | ||
| }; | ||
| readonly type: Types.MoveStructTag; | ||
| } |
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,24 @@ | ||
| import { isSortedSymbols } from "@pontem/liquidswap-sdk/dist/tsc/utils/contracts.js"; | ||
| import type { PoolState, TokenDetails } from "@swim-io/core"; | ||
| import { atomicToHuman } from "@swim-io/utils"; | ||
| import { Decimal } from "decimal.js"; | ||
|
|
||
| import type { PoolResource } from "./types"; | ||
|
|
||
| export const getPoolBalances = ( | ||
| pool: PoolResource, | ||
| tokens: readonly [TokenDetails, TokenDetails], | ||
| ): PoolState["balances"] => { | ||
| const reserves = [ | ||
| pool.data.coin_x_reserve.value, | ||
| pool.data.coin_y_reserve.value, | ||
| ]; | ||
| const atomicBalances = isSortedSymbols(tokens[0].address, tokens[1].address) | ||
| ? reserves | ||
| : [...reserves].reverse(); | ||
|
|
||
| return [ | ||
| atomicToHuman(new Decimal(atomicBalances[0]), tokens[0].decimals), | ||
| atomicToHuman(new Decimal(atomicBalances[1]), tokens[1].decimals), | ||
| ]; | ||
| }; |
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.