Skip to content

Commit

Permalink
Merge pull request #13 from mangrovedao/fix/maxence/price
Browse files Browse the repository at this point in the history
feat: add addresses
  • Loading branch information
maxencerb authored May 3, 2024
2 parents 0ff5c99 + 365d0a4 commit 9c6e775
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-tips-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@mangrovedao/mgv": minor
---

Added addresses book in /addresses
19 changes: 19 additions & 0 deletions src/addresses/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export type {
Token,
BuildTokenParms,
} from './tokens/index.js'

export { blastMarkets } from './markets/index.js'

// --- tokens ---

export {
blastWETH,
blastUSDB,
blastMetaStreetWETHPUNKS20,
blastMetaStreetWETHPUNKS40,
} from './tokens/index.js'

// --- mangrove ---

export { blastMangrove } from './mangrove/index.js'
7 changes: 7 additions & 0 deletions src/addresses/mangrove/blast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { MangroveActionsDefaultParams } from '../../types/index.js'

export const blastMangrove = {
mgv: '0xb1a49C54192Ea59B233200eA38aB56650Dfb448C',
mgvOrder: '0x83251E7F36a51c5238C9aa0c6Bb7cc209b32d80e',
mgvReader: '0x26fD9643Baf1f8A44b752B28f0D90AEBd04AB3F8',
} as const satisfies MangroveActionsDefaultParams
1 change: 1 addition & 0 deletions src/addresses/mangrove/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { blastMangrove } from './blast.js'
25 changes: 25 additions & 0 deletions src/addresses/markets/blast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { MarketParams } from '../../types/index.js'
import {
blastMetaStreetWETHPUNKS20,
blastMetaStreetWETHPUNKS40,
blastUSDB,
blastWETH,
} from '../tokens/blast.js'

export const blastMarkets = [
{
base: blastWETH,
quote: blastUSDB,
tickSpacing: 1n,
},
{
base: blastMetaStreetWETHPUNKS20,
quote: blastWETH,
tickSpacing: 1n,
},
{
base: blastMetaStreetWETHPUNKS40,
quote: blastWETH,
tickSpacing: 1n,
},
] as const satisfies MarketParams[]
1 change: 1 addition & 0 deletions src/addresses/markets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { blastMarkets } from './blast.js'
23 changes: 23 additions & 0 deletions src/addresses/tokens/blast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { buildToken } from './utils.js'

export const blastWETH = buildToken({
address: '0x4300000000000000000000000000000000000004',
symbol: 'WETH',
})

export const blastUSDB = buildToken({
address: '0x4300000000000000000000000000000000000002',
symbol: 'USDB',
displayDecimals: 2,
priceDisplayDecimals: 2,
})

export const blastMetaStreetWETHPUNKS20 = buildToken({
address: '0x9a50953716ba58e3d6719ea5c437452ac578705f',
symbol: 'mwstETH-WPUNKS:20',
})

export const blastMetaStreetWETHPUNKS40 = buildToken({
address: '0x999f220296b5843b2909cc5f8b4204aaca5341d8',
symbol: 'mwstETH-WPUNKS:40',
})
13 changes: 13 additions & 0 deletions src/addresses/tokens/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export {
blastWETH,
blastUSDB,
blastMetaStreetWETHPUNKS20,
blastMetaStreetWETHPUNKS40,
} from './blast.js'

export type {
Token,
BuildTokenParms,
} from './utils.js'

export { buildToken } from './utils.js'
81 changes: 81 additions & 0 deletions src/addresses/tokens/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import type { Address } from 'viem'

export const DEFAULT_DISPLAY_DECIMALS = 3 as const
export const DEFAULT_PRICE_DISPLAY_DECIMALS = 6 as const
export const DEFAULT_DECIMALS = 18 as const

export type Token<
TAddress extends Address = Address,
TSymbol extends string = string,
TDecimals extends number = number,
TDisplayDecimals extends number = number,
TPriceDisplayDecimals extends number = number,
> = {
address: TAddress
symbol: TSymbol
decimals: TDecimals
displayDecimals: TDisplayDecimals
priceDisplayDecimals: TPriceDisplayDecimals
}

export type BuildTokenParms<
TAddress extends Address = Address,
TSymbol extends string = string,
TDecimals extends number | undefined = number | undefined,
TDisplayDecimals extends number | undefined = number | undefined,
TPriceDisplayDecimals extends number | undefined = number | undefined,
> = {
address: TAddress
symbol: TSymbol
decimals?: TDecimals
displayDecimals?: TDisplayDecimals
priceDisplayDecimals?: TPriceDisplayDecimals
}

export function buildToken<
TAddress extends Address = Address,
TSymbol extends string = string,
TDecimals extends number | undefined = undefined,
TDisplayDecimals extends number | undefined = undefined,
TPriceDisplayDecimals extends number | undefined = undefined,
>({
address,
symbol,
decimals = DEFAULT_DECIMALS,
displayDecimals = DEFAULT_DISPLAY_DECIMALS,
priceDisplayDecimals = DEFAULT_PRICE_DISPLAY_DECIMALS,
}: BuildTokenParms<
TAddress,
TSymbol,
TDecimals,
TDisplayDecimals,
TPriceDisplayDecimals
>): Token<
TAddress,
TSymbol,
TDecimals extends number ? TDecimals : typeof DEFAULT_DECIMALS,
TDisplayDecimals extends number
? TDisplayDecimals
: typeof DEFAULT_DISPLAY_DECIMALS,
TPriceDisplayDecimals extends number
? TPriceDisplayDecimals
: typeof DEFAULT_PRICE_DISPLAY_DECIMALS
> {
return {
address,
symbol,
decimals,
displayDecimals,
priceDisplayDecimals,
} as Token<
TAddress,
TSymbol,
TDecimals extends number ? TDecimals : typeof DEFAULT_DECIMALS,
TDisplayDecimals extends number
? TDisplayDecimals
: typeof DEFAULT_DISPLAY_DECIMALS,
TPriceDisplayDecimals extends number
? TPriceDisplayDecimals
: typeof DEFAULT_PRICE_DISPLAY_DECIMALS
>
}
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export {

export type {
MangroveActionsDefaultParams,
Token,
MarketParams,
BuiltArgs,
BuiltArgsWithValue,
Expand Down Expand Up @@ -63,3 +62,10 @@ export type {
// --- bundles ---

export { publicMarketActions } from './bundle/index.js'

// --- addresses ---

export type {
Token,
BuildTokenParms,
} from './addresses/index.js'
5 changes: 5 additions & 0 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
"import": "./_esm/actions/index.js",
"default": "./_cjs/actions/index.js"
},
"./addresses": {
"types": "./_types/addresses/index.d.ts",
"import": "./_esm/addresses/index.js",
"default": "./_cjs/addresses/index.js"
},
"./builder": {
"types": "./_types/builder/index.d.ts",
"import": "./_esm/builder/index.js",
Expand Down
11 changes: 1 addition & 10 deletions src/types/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Address } from 'viem'
import type { Token } from '../../addresses/tokens/utils.js'

/**
* The parameters for the Mangrove actions.
Expand All @@ -12,16 +13,6 @@ export type MangroveActionsDefaultParams = {
mgvOrder: Address
}

/**
* The parameters for a token.
* @param address The address of the token.
* @param decimals The number of decimals of the token.
*/
export type Token = {
address: Address
decimals: number
}

/**
*
* The parameters for a given market market
Expand Down
1 change: 0 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export type {
MangroveActionsDefaultParams,
Token,
MarketParams,
BuiltArgs,
BuiltArgsWithValue,
Expand Down

0 comments on commit 9c6e775

Please sign in to comment.