-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Constants fully moved to the core and frontend uses the core's constants. - Safety utils are now used from the core - useMemecoin hook now uses the useMemecoin hook from the hooks package - useQuoteToken, useQuoteTokenPrice hooks are imported from the hooks package - Deploy, Launch, Collect Fees, Extend Liquidty Lock actions are now uses the core's Factory methods closes #227 --------- Co-authored-by: 0xChqrles <clanier.dev@gmail.com>
- Loading branch information
Showing
74 changed files
with
619 additions
and
3,301 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './ekubo' | ||
export * from './marketCap' | ||
export * from './price' | ||
export * from './safety' |
This file contains 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,30 @@ | ||
import { constants, RpcProvider } from 'starknet' | ||
import { expect, test } from 'vitest' | ||
|
||
import * as TestData from '../../test/TestData' | ||
import { Factory } from '../factory/default' | ||
import { getStartingMarketCap } from './marketCap' | ||
import { getPairPrice } from './price' | ||
|
||
const provider = new RpcProvider({ | ||
nodeUrl: 'https://starknet-mainnet.public.blastapi.io', | ||
}) | ||
|
||
const factory = new Factory({ provider, chainId: constants.StarknetChainId.SN_MAIN }) | ||
|
||
test('Starting Market Cap', async () => { | ||
const memecoin = await factory.getMemecoin(TestData.launched.address) | ||
|
||
expect(memecoin).toBeDefined() | ||
expect(memecoin?.isLaunched).toBe(true) | ||
if (!memecoin || !memecoin.isLaunched) return | ||
|
||
const quoteTokenPrice = await getPairPrice( | ||
factory.config.provider, | ||
memecoin.quoteToken?.usdcPair, | ||
memecoin.launch.blockNumber - 1, | ||
) | ||
const startingMarketCap = getStartingMarketCap(memecoin, quoteTokenPrice) | ||
|
||
expect(startingMarketCap?.toFixed(0)).toBe('4972') | ||
}) |
This file contains 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,36 @@ | ||
import { Fraction } from '@uniswap/sdk-core' | ||
|
||
import { DECIMALS, LiquidityType } from '../constants' | ||
import { Memecoin } from '../types' | ||
import { getInitialPrice } from './ekubo' | ||
import { decimalsScale } from './helpers' | ||
|
||
// eslint-disable-next-line import/no-unused-modules | ||
export function getStartingMarketCap(memecoin: Memecoin, quoteTokenPriceAtLaunch?: Fraction): Fraction | undefined { | ||
if (!memecoin.isLaunched || !quoteTokenPriceAtLaunch || !memecoin.quoteToken) return undefined | ||
|
||
switch (memecoin.liquidity.type) { | ||
case LiquidityType.STARKDEFI_ERC20: | ||
case LiquidityType.JEDISWAP_ERC20: { | ||
// starting mcap = quote amount in liq * (team allocation % + 100) * quote token price at launch | ||
return new Fraction(memecoin.liquidity.quoteAmount) | ||
.multiply(new Fraction(memecoin.launch.teamAllocation, memecoin.totalSupply).add(1)) | ||
.divide(decimalsScale(memecoin.quoteToken.decimals)) | ||
.multiply(quoteTokenPriceAtLaunch) | ||
} | ||
|
||
case LiquidityType.EKUBO_NFT: { | ||
// get starting price from starting tick | ||
const initialPrice = getInitialPrice(memecoin.liquidity.startingTick) | ||
|
||
// starting mcap = initial price * quote token price at launch * total supply | ||
return new Fraction( | ||
initialPrice.toFixed(DECIMALS).replace(/\./, '').replace(/^0+/, ''), // from 0.000[...]0001 to "1" | ||
decimalsScale(DECIMALS), | ||
) | ||
.multiply(quoteTokenPriceAtLaunch) | ||
.multiply(memecoin.totalSupply) | ||
.divide(decimalsScale(DECIMALS)) | ||
} | ||
} | ||
} |
This file contains 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,23 @@ | ||
import { constants, RpcProvider } from 'starknet' | ||
import { describe, expect, test } from 'vitest' | ||
|
||
import { Ether } from '../constants' | ||
import { getPairPrice } from './price' | ||
|
||
const provider = new RpcProvider({ | ||
nodeUrl: 'https://starknet-mainnet.public.blastapi.io', | ||
}) | ||
|
||
describe('Price', () => { | ||
test('No pair', async () => { | ||
const price = await getPairPrice(provider) | ||
|
||
expect(price.toFixed(0)).toBe('1') | ||
}) | ||
|
||
test('USDC Pair', async () => { | ||
const price = await getPairPrice(provider, Ether[constants.StarknetChainId.SN_MAIN].usdcPair, 500_000) | ||
|
||
expect(price.toFixed(0)).toBe('2309') | ||
}) | ||
}) |
This file contains 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.