-
Notifications
You must be signed in to change notification settings - Fork 10
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
Feat/flat curve #20
Open
ibrica
wants to merge
18
commits into
main
Choose a base branch
from
feat/flat-curve
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feat/flat curve #20
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5323246
feat: new contract and anchor version
ibrica 436f779
feat: new curve adapters
ibrica 9e1b1be
feat: update curve account
ibrica ce39d4a
fix: anchor mismatch
ibrica 6bf85da
feat: publish new version
ibrica cc4c7c3
fix: remove fs so it works in the browser
ibrica 24f7300
v4.1.0-alpha-0.0.2
ibrica c8900a9
v4.1.0-alpha-0.0.4
ibrica 1a347bc
v4.1.0-alpha-0.0.5
ibrica 601fa21
v4.1.0-alpha-0.0.6
ibrica 33c7127
v4.1.0-alpha-0.0.7
ibrica 4e1c695
feat: curve types
ibrica 946e8a9
feat: add flat collateral and price inc to token
ibrica f3ad99e
v4.1.0-alpha-0.0.8
ibrica e810033
v4.1.0-alpha-0.0.9
ibrica 30c30bb
v4.1.0-alpha-0.0.10
ibrica 929d28d
feat: conditional import
ibrica 23e3033
Merge branch 'main' into feat/flat-curve
ibrica 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 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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { | ||
GetCollateralPriceOptions, | ||
GetCollateralAmountOptions, | ||
GetTokenAmountOptions, | ||
} from '../token'; | ||
import { GetTokenAmountSyncOptions } from '../token/GetTokenAmountSyncOptions'; | ||
import { AbstractCurveAdapter } from './AbstractCurveAdapter'; | ||
import { ConstantProductCurveV2 } from '@heliofi/launchpad-common'; | ||
import { GetCollateralAmountSyncOptions } from '../token/GetCollateralAmountSyncOptions'; | ||
|
||
export class ConstantProductCurveV2Adapter extends AbstractCurveAdapter { | ||
private readonly platformFeeBps: number = 100; | ||
|
||
private readonly curve = new ConstantProductCurveV2(); | ||
|
||
getCollateralPrice(options: GetCollateralPriceOptions): Promise<bigint> { | ||
return this.getCollateralAmountByTokens({ | ||
tokenAmount: options.tokenAmount, | ||
tradeDirection: 'BUY', | ||
curvePosition: options.curvePosition, | ||
}); | ||
} | ||
|
||
async getCollateralAmountByTokens( | ||
options: GetCollateralAmountOptions, | ||
): Promise<bigint> { | ||
const curvePosition = | ||
options.curvePosition ?? (await this.getCurvePosition()); | ||
|
||
return this.curve.getCollateralAmountFromTokens({ | ||
amount: options.tokenAmount, | ||
curvePosition, | ||
platformFeeBps: this.platformFeeBps, | ||
tradeDirection: options.tradeDirection, | ||
}); | ||
} | ||
|
||
getCollateralAmountByTokensSync( | ||
options: GetCollateralAmountSyncOptions, | ||
): bigint { | ||
const curvePosition = options.curvePosition; | ||
|
||
return this.curve.getCollateralAmountFromTokens({ | ||
amount: options.tokenAmount, | ||
curvePosition, | ||
platformFeeBps: this.platformFeeBps, | ||
tradeDirection: options.tradeDirection, | ||
}); | ||
} | ||
|
||
async getTokenAmountByCollateral( | ||
options: GetTokenAmountOptions, | ||
): Promise<bigint> { | ||
const curvePosition = | ||
options.curvePosition ?? (await this.getCurvePosition()); | ||
|
||
return this.curve.getTokensAmountFromCollateral({ | ||
amount: options.collateralAmount, | ||
curvePosition, | ||
platformFeeBps: this.platformFeeBps, | ||
tradeDirection: options.tradeDirection, | ||
}); | ||
} | ||
|
||
getTokenAmountByCollateralSync(options: GetTokenAmountSyncOptions): bigint { | ||
const curvePosition = options.curvePosition; | ||
|
||
return this.curve.getTokensAmountFromCollateral({ | ||
amount: options.collateralAmount, | ||
curvePosition, | ||
platformFeeBps: this.platformFeeBps, | ||
tradeDirection: options.tradeDirection, | ||
}); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { | ||
GetCollateralPriceOptions, | ||
GetCollateralAmountOptions, | ||
GetTokenAmountOptions, | ||
} from '../token'; | ||
import { GetTokenAmountSyncOptions } from '../token/GetTokenAmountSyncOptions'; | ||
import { AbstractCurveAdapter } from './AbstractCurveAdapter'; | ||
import { FlatCurveV1 } from '@heliofi/launchpad-common'; | ||
import { GetCollateralAmountSyncOptions } from '../token/GetCollateralAmountSyncOptions'; | ||
import { TokenLaunchpadIdl } from '../../../solana'; | ||
import { BaseAnchorProvider } from '../../../solana'; | ||
|
||
export class FlatCurveV1Adapter extends AbstractCurveAdapter { | ||
private readonly platformFeeBps: number = 100; | ||
|
||
private readonly curve: FlatCurveV1; | ||
|
||
constructor( | ||
moonshotProgram: BaseAnchorProvider<TokenLaunchpadIdl>, | ||
mintAddress: string, | ||
collateralCollected: bigint, | ||
priceIncrease?: number, | ||
) { | ||
super(moonshotProgram, mintAddress); | ||
this.curve = new FlatCurveV1(collateralCollected, priceIncrease); | ||
} | ||
|
||
getCollateralPrice(options: GetCollateralPriceOptions): Promise<bigint> { | ||
return this.getCollateralAmountByTokens({ | ||
tokenAmount: options.tokenAmount, | ||
tradeDirection: 'BUY', | ||
curvePosition: options.curvePosition, | ||
}); | ||
} | ||
|
||
async getCollateralAmountByTokens( | ||
options: GetCollateralAmountOptions, | ||
): Promise<bigint> { | ||
const curvePosition = | ||
options.curvePosition ?? (await this.getCurvePosition()); | ||
|
||
return this.curve.getCollateralAmountFromTokens({ | ||
amount: options.tokenAmount, | ||
curvePosition, | ||
platformFeeBps: this.platformFeeBps, | ||
tradeDirection: options.tradeDirection, | ||
}); | ||
} | ||
|
||
getCollateralAmountByTokensSync( | ||
options: GetCollateralAmountSyncOptions, | ||
): bigint { | ||
const curvePosition = options.curvePosition; | ||
|
||
return this.curve.getCollateralAmountFromTokens({ | ||
amount: options.tokenAmount, | ||
curvePosition, | ||
platformFeeBps: this.platformFeeBps, | ||
tradeDirection: options.tradeDirection, | ||
}); | ||
} | ||
|
||
async getTokenAmountByCollateral( | ||
options: GetTokenAmountOptions, | ||
): Promise<bigint> { | ||
const curvePosition = | ||
options.curvePosition ?? (await this.getCurvePosition()); | ||
|
||
return this.curve.getTokensAmountFromCollateral({ | ||
amount: options.collateralAmount, | ||
curvePosition, | ||
platformFeeBps: this.platformFeeBps, | ||
tradeDirection: options.tradeDirection, | ||
}); | ||
} | ||
|
||
getTokenAmountByCollateralSync(options: GetTokenAmountSyncOptions): bigint { | ||
const curvePosition = options.curvePosition; | ||
|
||
return this.curve.getTokensAmountFromCollateral({ | ||
amount: options.collateralAmount, | ||
curvePosition, | ||
platformFeeBps: this.platformFeeBps, | ||
tradeDirection: options.tradeDirection, | ||
}); | ||
} | ||
} |
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,4 +1,6 @@ | ||
export * from './CurveAccount'; | ||
export * from './LinearCurveV1Adapter'; | ||
export * from './ConstantProductCurveV1Adapter'; | ||
export * from './ConstantProductCurveV2Adapter'; | ||
export * from './FlatCurveV1Adapter'; | ||
export * from './getCurveAdapter'; |
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,7 +1,3 @@ | ||
import { readFileSync } from 'fs'; | ||
|
||
export const imagePathToBase64 = (filePath: string): string => { | ||
const imageBuffer = readFileSync(filePath); | ||
|
||
return imageBuffer.toString('base64'); | ||
export const imagePathToBase64 = (input: string): string => { | ||
return Buffer.from(input).toString('base64'); // TODO: check how to do file without fs so it is browser compatible | ||
}; |
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,12 +1,8 @@ | ||
import { Idl } from '@coral-xyz/anchor'; | ||
import { PublicKey } from '@solana/web3.js'; | ||
import idl from './tokenLaunchpadIdlV1'; | ||
import idl from './tokenLaunchpadIdlV4'; | ||
|
||
export const programId = new PublicKey(idl.metadata.address); | ||
export const tokenLaunchpadIdlV1 = idl as TokenLaunchpadIdl; | ||
export const programId = new PublicKey(idl.address); | ||
export const tokenLaunchpadIdlV4 = idl as TokenLaunchpadIdl; | ||
|
||
export type TokenLaunchpadIdl = Idl & { | ||
metadata: { | ||
address: string; | ||
}; | ||
}; | ||
export type TokenLaunchpadIdl = Idl; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martin, here the fs was used for uploading image so it doesn't work in the browser, we have to sync about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, missed that we can think of a solution for nodejs and browser envs