@0xtorch/core 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/import/accounts/index.d.ts +2 -0
- package/dist/import/accounts/index.d.ts.map +1 -0
- package/dist/import/accounts/types/account.d.ts +6 -0
- package/dist/import/accounts/types/account.d.ts.map +1 -0
- package/dist/import/accounts/types/index.d.ts +2 -0
- package/dist/import/accounts/types/index.d.ts.map +1 -0
- package/dist/import/actions/index.d.ts +2 -0
- package/dist/import/actions/index.d.ts.map +1 -0
- package/dist/import/actions/types/addLiquidity.d.ts +7 -0
- package/dist/import/actions/types/addLiquidity.d.ts.map +1 -0
- package/dist/import/actions/types/atomicArbitrage.d.ts +5 -0
- package/dist/import/actions/types/atomicArbitrage.d.ts.map +1 -0
- package/dist/import/actions/types/bridgeFrom.d.ts +6 -0
- package/dist/import/actions/types/bridgeFrom.d.ts.map +1 -0
- package/dist/import/actions/types/bridgeTo.d.ts +6 -0
- package/dist/import/actions/types/bridgeTo.d.ts.map +1 -0
- package/dist/import/actions/types/buyNft.d.ts +7 -0
- package/dist/import/actions/types/buyNft.d.ts.map +1 -0
- package/dist/import/actions/types/common.d.ts +50 -0
- package/dist/import/actions/types/common.d.ts.map +1 -0
- package/dist/import/actions/types/deposit.d.ts +6 -0
- package/dist/import/actions/types/deposit.d.ts.map +1 -0
- package/dist/import/actions/types/depositWithBond.d.ts +7 -0
- package/dist/import/actions/types/depositWithBond.d.ts.map +1 -0
- package/dist/import/actions/types/freeMintNft.d.ts +8 -0
- package/dist/import/actions/types/freeMintNft.d.ts.map +1 -0
- package/dist/import/actions/types/income.d.ts +5 -0
- package/dist/import/actions/types/income.d.ts.map +1 -0
- package/dist/import/actions/types/index.d.ts +24 -0
- package/dist/import/actions/types/index.d.ts.map +1 -0
- package/dist/import/actions/types/move.d.ts +5 -0
- package/dist/import/actions/types/move.d.ts.map +1 -0
- package/dist/import/actions/types/nftRoyalty.d.ts +7 -0
- package/dist/import/actions/types/nftRoyalty.d.ts.map +1 -0
- package/dist/import/actions/types/removeLiquidity.d.ts +7 -0
- package/dist/import/actions/types/removeLiquidity.d.ts.map +1 -0
- package/dist/import/actions/types/sellNft.d.ts +6 -0
- package/dist/import/actions/types/sellNft.d.ts.map +1 -0
- package/dist/import/actions/types/spam.d.ts +6 -0
- package/dist/import/actions/types/spam.d.ts.map +1 -0
- package/dist/import/actions/types/swapIncome.d.ts +4 -0
- package/dist/import/actions/types/swapIncome.d.ts.map +1 -0
- package/dist/import/actions/types/swapNft.d.ts +6 -0
- package/dist/import/actions/types/swapNft.d.ts.map +1 -0
- package/dist/import/actions/types/swapTransfer.d.ts +4 -0
- package/dist/import/actions/types/swapTransfer.d.ts.map +1 -0
- package/dist/import/actions/types/trade.d.ts +7 -0
- package/dist/import/actions/types/trade.d.ts.map +1 -0
- package/dist/import/actions/types/transactionFee.d.ts +7 -0
- package/dist/import/actions/types/transactionFee.d.ts.map +1 -0
- package/dist/import/actions/types/transfer.d.ts +8 -0
- package/dist/import/actions/types/transfer.d.ts.map +1 -0
- package/dist/import/actions/types/withdraw.d.ts +7 -0
- package/dist/import/actions/types/withdraw.d.ts.map +1 -0
- package/dist/import/actions/types/withdrawWithBond.d.ts +7 -0
- package/dist/import/actions/types/withdrawWithBond.d.ts.map +1 -0
- package/dist/import/apps/index.d.ts +3 -0
- package/dist/import/apps/index.d.ts.map +1 -0
- package/dist/import/apps/types.d.ts +11 -0
- package/dist/import/apps/types.d.ts.map +1 -0
- package/dist/import/assets/constants.d.ts +2 -0
- package/dist/import/assets/constants.d.ts.map +1 -0
- package/dist/import/assets/creates/createCryptoCurrency.d.ts +3 -0
- package/dist/import/assets/creates/createCryptoCurrency.d.ts.map +1 -0
- package/dist/import/assets/creates/createFiatCurrency.d.ts +3 -0
- package/dist/import/assets/creates/createFiatCurrency.d.ts.map +1 -0
- package/dist/import/assets/creates/index.d.ts +3 -0
- package/dist/import/assets/creates/index.d.ts.map +1 -0
- package/dist/import/assets/definitions/astar.d.ts +13 -0
- package/dist/import/assets/definitions/astar.d.ts.map +1 -0
- package/dist/import/assets/definitions/avalanche.d.ts +13 -0
- package/dist/import/assets/definitions/avalanche.d.ts.map +1 -0
- package/dist/import/assets/definitions/bnb.d.ts +13 -0
- package/dist/import/assets/definitions/bnb.d.ts.map +1 -0
- package/dist/import/assets/definitions/coingeckoCryptoCurrencyDataSource.d.ts +18 -0
- package/dist/import/assets/definitions/coingeckoCryptoCurrencyDataSource.d.ts.map +1 -0
- package/dist/import/assets/definitions/ethereum.d.ts +13 -0
- package/dist/import/assets/definitions/ethereum.d.ts.map +1 -0
- package/dist/import/assets/definitions/eur.d.ts +8 -0
- package/dist/import/assets/definitions/eur.d.ts.map +1 -0
- package/dist/import/assets/definitions/fantom.d.ts +13 -0
- package/dist/import/assets/definitions/fantom.d.ts.map +1 -0
- package/dist/import/assets/definitions/index.d.ts +17 -0
- package/dist/import/assets/definitions/index.d.ts.map +1 -0
- package/dist/import/assets/definitions/jpy.d.ts +8 -0
- package/dist/import/assets/definitions/jpy.d.ts.map +1 -0
- package/dist/import/assets/definitions/kava.d.ts +13 -0
- package/dist/import/assets/definitions/kava.d.ts.map +1 -0
- package/dist/import/assets/definitions/mantle.d.ts +13 -0
- package/dist/import/assets/definitions/mantle.d.ts.map +1 -0
- package/dist/import/assets/definitions/maticNetwork.d.ts +13 -0
- package/dist/import/assets/definitions/maticNetwork.d.ts.map +1 -0
- package/dist/import/assets/definitions/metis.d.ts +13 -0
- package/dist/import/assets/definitions/metis.d.ts.map +1 -0
- package/dist/import/assets/definitions/moonbeam.d.ts +13 -0
- package/dist/import/assets/definitions/moonbeam.d.ts.map +1 -0
- package/dist/import/assets/definitions/moonriver.d.ts +13 -0
- package/dist/import/assets/definitions/moonriver.d.ts.map +1 -0
- package/dist/import/assets/definitions/ronin.d.ts +13 -0
- package/dist/import/assets/definitions/ronin.d.ts.map +1 -0
- package/dist/import/assets/definitions/usd.d.ts +8 -0
- package/dist/import/assets/definitions/usd.d.ts.map +1 -0
- package/dist/import/assets/externals/coingecko/constants.d.ts +2 -0
- package/dist/import/assets/externals/coingecko/constants.d.ts.map +1 -0
- package/dist/import/assets/externals/coingecko/getAutoRetry.d.ts +4 -0
- package/dist/import/assets/externals/coingecko/getAutoRetry.d.ts.map +1 -0
- package/dist/import/assets/externals/coingecko/getCoinMarketChartRange.d.ts +49 -0
- package/dist/import/assets/externals/coingecko/getCoinMarketChartRange.d.ts.map +1 -0
- package/dist/import/assets/externals/coingecko/getCoinsMarkets.d.ts +58 -0
- package/dist/import/assets/externals/coingecko/getCoinsMarkets.d.ts.map +1 -0
- package/dist/import/assets/externals/coingecko/index.d.ts +3 -0
- package/dist/import/assets/externals/coingecko/index.d.ts.map +1 -0
- package/dist/import/assets/externals/index.d.ts +2 -0
- package/dist/import/assets/externals/index.d.ts.map +1 -0
- package/dist/import/assets/index.d.ts +5 -0
- package/dist/import/assets/index.d.ts.map +1 -0
- package/dist/import/assets/types/cryptoCurrency.d.ts +17 -0
- package/dist/import/assets/types/cryptoCurrency.d.ts.map +1 -0
- package/dist/import/assets/types/cryptoCurrencyPrice.d.ts +10 -0
- package/dist/import/assets/types/cryptoCurrencyPrice.d.ts.map +1 -0
- package/dist/import/assets/types/dataSource.d.ts +18 -0
- package/dist/import/assets/types/dataSource.d.ts.map +1 -0
- package/dist/import/assets/types/fiatCurrency.d.ts +12 -0
- package/dist/import/assets/types/fiatCurrency.d.ts.map +1 -0
- package/dist/import/assets/types/index.d.ts +6 -0
- package/dist/import/assets/types/index.d.ts.map +1 -0
- package/dist/import/assets/types/nft.d.ts +5 -0
- package/dist/import/assets/types/nft.d.ts.map +1 -0
- package/dist/import/index.d.mts +12 -0
- package/dist/import/index.d.mts.map +1 -0
- package/dist/import/index.mjs +2 -0
- package/dist/import/portfolios/createPortfolio.d.ts +2 -0
- package/dist/import/portfolios/createPortfolio.d.ts.map +1 -0
- package/dist/import/portfolios/index.d.ts +3 -0
- package/dist/import/portfolios/index.d.ts.map +1 -0
- package/dist/import/portfolios/type.d.ts +4 -0
- package/dist/import/portfolios/type.d.ts.map +1 -0
- package/dist/import/types.d.ts +11 -0
- package/dist/import/types.d.ts.map +1 -0
- package/dist/import/utils/errors.d.ts +48 -0
- package/dist/import/utils/errors.d.ts.map +1 -0
- package/dist/import/utils/index.d.ts +5 -0
- package/dist/import/utils/index.d.ts.map +1 -0
- package/dist/import/utils/rest.d.ts +14 -0
- package/dist/import/utils/rest.d.ts.map +1 -0
- package/dist/import/utils/stringify.d.ts +2 -0
- package/dist/import/utils/stringify.d.ts.map +1 -0
- package/dist/import/utils/types.d.ts +12 -0
- package/dist/import/utils/types.d.ts.map +1 -0
- package/dist/require/index.cjs +2 -0
- package/dist/require/index.d.cts +2 -0
- package/dist/require/index.d.cts.map +1 -0
- package/package.json +79 -0
- package/src/accounts/index.ts +1 -0
- package/src/accounts/types/account.ts +5 -0
- package/src/accounts/types/index.ts +1 -0
- package/src/actions/index.ts +44 -0
- package/src/actions/schemas/constants.ts +16 -0
- package/src/actions/schemas/swap.ts +7 -0
- package/src/actions/types/addLiquidity.ts +23 -0
- package/src/actions/types/atomicArbitrage.ts +30 -0
- package/src/actions/types/bridgeFrom.ts +23 -0
- package/src/actions/types/bridgeTo.ts +23 -0
- package/src/actions/types/buyNft.ts +34 -0
- package/src/actions/types/common.ts +142 -0
- package/src/actions/types/deposit.ts +23 -0
- package/src/actions/types/depositWithBond.ts +23 -0
- package/src/actions/types/freeMintNft.ts +20 -0
- package/src/actions/types/income.ts +21 -0
- package/src/actions/types/index.ts +53 -0
- package/src/actions/types/move.ts +21 -0
- package/src/actions/types/nftRoyalty.ts +19 -0
- package/src/actions/types/removeLiquidity.ts +23 -0
- package/src/actions/types/sellNft.ts +22 -0
- package/src/actions/types/spam.ts +23 -0
- package/src/actions/types/swapIncome.ts +12 -0
- package/src/actions/types/swapNft.ts +12 -0
- package/src/actions/types/swapTransfer.ts +12 -0
- package/src/actions/types/trade.ts +34 -0
- package/src/actions/types/transactionFee.ts +19 -0
- package/src/actions/types/transfer.ts +36 -0
- package/src/actions/types/withdraw.ts +23 -0
- package/src/actions/types/withdrawWithBond.ts +23 -0
- package/src/apps/index.ts +2 -0
- package/src/apps/types.ts +20 -0
- package/src/assets/constants.ts +1 -0
- package/src/assets/creates/createCryptoCurrency.ts +7 -0
- package/src/assets/creates/createFiatCurrency.ts +10 -0
- package/src/assets/creates/index.ts +2 -0
- package/src/assets/definitions/astar.ts +14 -0
- package/src/assets/definitions/avalanche.ts +14 -0
- package/src/assets/definitions/bnb.ts +14 -0
- package/src/assets/definitions/coingeckoCryptoCurrencyDataSource.test.ts +53 -0
- package/src/assets/definitions/coingeckoCryptoCurrencyDataSource.ts +169 -0
- package/src/assets/definitions/ethereum.ts +14 -0
- package/src/assets/definitions/eur.ts +9 -0
- package/src/assets/definitions/fantom.ts +14 -0
- package/src/assets/definitions/index.ts +16 -0
- package/src/assets/definitions/jpy.ts +9 -0
- package/src/assets/definitions/kava.ts +14 -0
- package/src/assets/definitions/mantle.ts +14 -0
- package/src/assets/definitions/maticNetwork.ts +14 -0
- package/src/assets/definitions/metis.ts +14 -0
- package/src/assets/definitions/moonbeam.ts +14 -0
- package/src/assets/definitions/moonriver.ts +14 -0
- package/src/assets/definitions/ronin.ts +14 -0
- package/src/assets/definitions/usd.ts +9 -0
- package/src/assets/externals/coingecko/constants.ts +1 -0
- package/src/assets/externals/coingecko/getAutoRetry.ts +35 -0
- package/src/assets/externals/coingecko/getCoinMarketChartRange.test.ts +28 -0
- package/src/assets/externals/coingecko/getCoinMarketChartRange.ts +88 -0
- package/src/assets/externals/coingecko/getCoinsMarkets.test.ts +11 -0
- package/src/assets/externals/coingecko/getCoinsMarkets.ts +106 -0
- package/src/assets/externals/coingecko/index.ts +2 -0
- package/src/assets/externals/index.ts +1 -0
- package/src/assets/index.ts +27 -0
- package/src/assets/types/cryptoCurrency.ts +17 -0
- package/src/assets/types/cryptoCurrencyPrice.ts +14 -0
- package/src/assets/types/dataSource.ts +26 -0
- package/src/assets/types/fiatCurrency.ts +21 -0
- package/src/assets/types/index.ts +9 -0
- package/src/assets/types/nft.ts +5 -0
- package/src/index.cts +1 -0
- package/src/index.mts +79 -0
- package/src/portfolios/createPortfolio.test.ts +7 -0
- package/src/portfolios/createPortfolio.ts +3 -0
- package/src/portfolios/index.ts +2 -0
- package/src/portfolios/type.ts +3 -0
- package/src/tests/constants.ts +1 -0
- package/src/tests/index.ts +2 -0
- package/src/tests/utils.ts +26 -0
- package/src/types.ts +11 -0
- package/src/utils/errors.ts +130 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/rest.test.ts +19 -0
- package/src/utils/rest.ts +138 -0
- package/src/utils/stringify.test.ts +24 -0
- package/src/utils/stringify.ts +11 -0
- package/src/utils/types.ts +12 -0
- package/tsconfig.json +28 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CryptoCurrency,
|
|
3
|
+
CryptoCurrencyPrice,
|
|
4
|
+
FiatCurrency,
|
|
5
|
+
Nft,
|
|
6
|
+
} from '../../assets'
|
|
7
|
+
import type { AccountAction, NormalAction } from './common'
|
|
8
|
+
|
|
9
|
+
type Action = 'trade'
|
|
10
|
+
|
|
11
|
+
export type NormalActionTrade<
|
|
12
|
+
Account = unknown,
|
|
13
|
+
// TODO crypto 以外の価格にも対応させる
|
|
14
|
+
Price extends CryptoCurrencyPrice | undefined =
|
|
15
|
+
| CryptoCurrencyPrice
|
|
16
|
+
| undefined,
|
|
17
|
+
Asset extends CryptoCurrency | FiatCurrency | Nft =
|
|
18
|
+
| CryptoCurrency
|
|
19
|
+
| FiatCurrency
|
|
20
|
+
| Nft,
|
|
21
|
+
> = NormalAction<Action, Account, Price, Asset, 'in' | 'out'>
|
|
22
|
+
|
|
23
|
+
export type AccountActionTrade<
|
|
24
|
+
Account = unknown,
|
|
25
|
+
Source extends string = string,
|
|
26
|
+
// TODO crypto 以外の価格にも対応させる
|
|
27
|
+
Price extends CryptoCurrencyPrice | undefined =
|
|
28
|
+
| CryptoCurrencyPrice
|
|
29
|
+
| undefined,
|
|
30
|
+
Asset extends CryptoCurrency | FiatCurrency | Nft =
|
|
31
|
+
| CryptoCurrency
|
|
32
|
+
| FiatCurrency
|
|
33
|
+
| Nft,
|
|
34
|
+
> = AccountAction<Action, Source, Account, Price, Asset, 'in' | 'out'>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CryptoCurrency, CryptoCurrencyPrice } from '../../assets'
|
|
2
|
+
import type { AccountAction, NormalAction } from './common'
|
|
3
|
+
|
|
4
|
+
type Action = 'transaction-fee'
|
|
5
|
+
|
|
6
|
+
export type NormalActionTransactionFee<
|
|
7
|
+
Account = unknown,
|
|
8
|
+
Price extends CryptoCurrencyPrice | undefined =
|
|
9
|
+
| CryptoCurrencyPrice
|
|
10
|
+
| undefined,
|
|
11
|
+
> = NormalAction<Action, Account, Price, CryptoCurrency, 'out'>
|
|
12
|
+
|
|
13
|
+
export type AccountActionTransactionFee<
|
|
14
|
+
Account = unknown,
|
|
15
|
+
Source extends string = string,
|
|
16
|
+
Price extends CryptoCurrencyPrice | undefined =
|
|
17
|
+
| CryptoCurrencyPrice
|
|
18
|
+
| undefined,
|
|
19
|
+
> = AccountAction<Action, Source, Account, Price, CryptoCurrency, 'out'>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CryptoCurrency,
|
|
3
|
+
CryptoCurrencyPrice,
|
|
4
|
+
FiatCurrency,
|
|
5
|
+
Nft,
|
|
6
|
+
} from '../../assets'
|
|
7
|
+
import type { AccountAction, NormalAction } from './common'
|
|
8
|
+
|
|
9
|
+
export type Action = 'transfer'
|
|
10
|
+
|
|
11
|
+
/** asset transfer */
|
|
12
|
+
export type NormalActionTransfer<
|
|
13
|
+
Account = unknown,
|
|
14
|
+
// TODO crypto 以外の価格にも対応させる
|
|
15
|
+
Price extends CryptoCurrencyPrice | undefined =
|
|
16
|
+
| CryptoCurrencyPrice
|
|
17
|
+
| undefined,
|
|
18
|
+
Asset extends CryptoCurrency | FiatCurrency | Nft =
|
|
19
|
+
| CryptoCurrency
|
|
20
|
+
| FiatCurrency
|
|
21
|
+
| Nft,
|
|
22
|
+
> = NormalAction<Action, Account, Price, Asset, 'none'>
|
|
23
|
+
|
|
24
|
+
/** transfer from account to others */
|
|
25
|
+
export type AccountActionTransfer<
|
|
26
|
+
Account = unknown,
|
|
27
|
+
Source extends string = string,
|
|
28
|
+
// TODO crypto 以外の価格にも対応させる
|
|
29
|
+
Price extends CryptoCurrencyPrice | undefined =
|
|
30
|
+
| CryptoCurrencyPrice
|
|
31
|
+
| undefined,
|
|
32
|
+
Asset extends CryptoCurrency | FiatCurrency | Nft =
|
|
33
|
+
| CryptoCurrency
|
|
34
|
+
| FiatCurrency
|
|
35
|
+
| Nft,
|
|
36
|
+
> = AccountAction<Action, Source, Account, Price, Asset, 'out'>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CryptoCurrency, CryptoCurrencyPrice, Nft } from '../../assets'
|
|
2
|
+
import type { AccountAction, NormalAction } from './common'
|
|
3
|
+
|
|
4
|
+
type Action = 'withdraw'
|
|
5
|
+
|
|
6
|
+
export type NormalActionWithdraw<
|
|
7
|
+
Account = unknown,
|
|
8
|
+
// TODO crypto 以外の価格にも対応させる
|
|
9
|
+
Price extends CryptoCurrencyPrice | undefined =
|
|
10
|
+
| CryptoCurrencyPrice
|
|
11
|
+
| undefined,
|
|
12
|
+
Asset extends CryptoCurrency | Nft = CryptoCurrency | Nft,
|
|
13
|
+
> = NormalAction<Action, Account, Price, Asset, 'in'>
|
|
14
|
+
|
|
15
|
+
export type AccountActionWithdraw<
|
|
16
|
+
Account = unknown,
|
|
17
|
+
Source extends string = string,
|
|
18
|
+
// TODO crypto 以外の価格にも対応させる
|
|
19
|
+
Price extends CryptoCurrencyPrice | undefined =
|
|
20
|
+
| CryptoCurrencyPrice
|
|
21
|
+
| undefined,
|
|
22
|
+
Asset extends CryptoCurrency | Nft = CryptoCurrency | Nft,
|
|
23
|
+
> = AccountAction<Action, Source, Account, Price, Asset, 'in'>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CryptoCurrency, CryptoCurrencyPrice, Nft } from '../../assets'
|
|
2
|
+
import type { AccountAction, NormalAction } from './common'
|
|
3
|
+
|
|
4
|
+
type Action = 'withdraw-with-bond'
|
|
5
|
+
|
|
6
|
+
export type NormalActionWithdrawWithBond<
|
|
7
|
+
Account = unknown,
|
|
8
|
+
// TODO crypto 以外の価格にも対応させる
|
|
9
|
+
Price extends CryptoCurrencyPrice | undefined =
|
|
10
|
+
| CryptoCurrencyPrice
|
|
11
|
+
| undefined,
|
|
12
|
+
Asset extends CryptoCurrency | Nft = CryptoCurrency | Nft,
|
|
13
|
+
> = NormalAction<Action, Account, Price, Asset, 'in' | 'out'>
|
|
14
|
+
|
|
15
|
+
export type AccountActionWithdrawWithBond<
|
|
16
|
+
Account = unknown,
|
|
17
|
+
Source extends string = string,
|
|
18
|
+
// TODO crypto 以外の価格にも対応させる
|
|
19
|
+
Price extends CryptoCurrencyPrice | undefined =
|
|
20
|
+
| CryptoCurrencyPrice
|
|
21
|
+
| undefined,
|
|
22
|
+
Asset extends CryptoCurrency | Nft = CryptoCurrency | Nft,
|
|
23
|
+
> = AccountAction<Action, Source, Account, Price, Asset, 'in' | 'out'>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type App = {
|
|
2
|
+
readonly id: string
|
|
3
|
+
readonly categories: AppCategory[]
|
|
4
|
+
readonly name: string
|
|
5
|
+
readonly description: string | undefined
|
|
6
|
+
readonly website: string | undefined
|
|
7
|
+
readonly icon: string | undefined
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const appCategories = [
|
|
11
|
+
'bridge',
|
|
12
|
+
'cex',
|
|
13
|
+
'cross-chain',
|
|
14
|
+
'dex',
|
|
15
|
+
'gaming',
|
|
16
|
+
'lending',
|
|
17
|
+
'nft-marketplace',
|
|
18
|
+
'other',
|
|
19
|
+
] as const
|
|
20
|
+
export type AppCategory = (typeof appCategories)[number]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const fiatCurrencyDecimals = 6
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createCryptoCurrency } from '../creates'
|
|
2
|
+
|
|
3
|
+
export const astar = createCryptoCurrency({
|
|
4
|
+
type: 'CryptoCurrency',
|
|
5
|
+
id: 'astar',
|
|
6
|
+
name: 'Astar',
|
|
7
|
+
symbol: 'ASTR',
|
|
8
|
+
icon: undefined,
|
|
9
|
+
market: {
|
|
10
|
+
coingeckoId: 'astar',
|
|
11
|
+
marketCapUsd: undefined,
|
|
12
|
+
},
|
|
13
|
+
updatedAt: Date.now(),
|
|
14
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createCryptoCurrency } from '../creates'
|
|
2
|
+
|
|
3
|
+
export const avalanche = createCryptoCurrency({
|
|
4
|
+
type: 'CryptoCurrency',
|
|
5
|
+
id: 'avalanche-2',
|
|
6
|
+
name: 'Avalanche',
|
|
7
|
+
symbol: 'AVAX',
|
|
8
|
+
icon: undefined,
|
|
9
|
+
market: {
|
|
10
|
+
coingeckoId: 'avalanche-2',
|
|
11
|
+
marketCapUsd: undefined,
|
|
12
|
+
},
|
|
13
|
+
updatedAt: Date.now(),
|
|
14
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createCryptoCurrency } from '../creates'
|
|
2
|
+
|
|
3
|
+
export const bnb = createCryptoCurrency({
|
|
4
|
+
type: 'CryptoCurrency',
|
|
5
|
+
id: 'binancecoin',
|
|
6
|
+
name: 'BNB',
|
|
7
|
+
symbol: 'BNB',
|
|
8
|
+
icon: undefined,
|
|
9
|
+
market: {
|
|
10
|
+
coingeckoId: 'binancecoin',
|
|
11
|
+
marketCapUsd: undefined,
|
|
12
|
+
},
|
|
13
|
+
updatedAt: Date.now(),
|
|
14
|
+
})
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test'
|
|
2
|
+
import { isIntegrationTest } from '../../tests'
|
|
3
|
+
import { bnb } from './bnb'
|
|
4
|
+
import {
|
|
5
|
+
coingeckoCryptoCurrencyDataSource,
|
|
6
|
+
splitFromToBy90DaysSeconds,
|
|
7
|
+
} from './coingeckoCryptoCurrencyDataSource'
|
|
8
|
+
import { ethereum } from './ethereum'
|
|
9
|
+
import { usd } from './usd'
|
|
10
|
+
|
|
11
|
+
describe.if(isIntegrationTest)('coingeckoCryptoCurrencyDataSource', () => {
|
|
12
|
+
it('should get current price', async () => {
|
|
13
|
+
const prices = await coingeckoCryptoCurrencyDataSource.getCurrentPrice({
|
|
14
|
+
targetCurrencies: [ethereum, bnb],
|
|
15
|
+
vsCurrency: usd,
|
|
16
|
+
})
|
|
17
|
+
expect(prices).toHaveLength(2)
|
|
18
|
+
expect(prices[0].crypto.id).toBe(ethereum.id)
|
|
19
|
+
expect(prices[1].crypto.id).toBe(bnb.id)
|
|
20
|
+
})
|
|
21
|
+
it('should get historical prices', async () => {
|
|
22
|
+
const prices = await coingeckoCryptoCurrencyDataSource.getHistoricalPrices({
|
|
23
|
+
targetCurrencies: [ethereum],
|
|
24
|
+
vsCurrency: usd,
|
|
25
|
+
from: new Date('2021-01-01').getTime(),
|
|
26
|
+
to: new Date('2021-04-30').getTime(),
|
|
27
|
+
})
|
|
28
|
+
expect(prices.length).toBeGreaterThan(1000)
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
describe('splitFromToBy90DaysSeconds', () => {
|
|
33
|
+
it('should split the range into 90 day intervals', () => {
|
|
34
|
+
const from = 0
|
|
35
|
+
const to = 60 * 60 * 24 * 90 * 3 // 270 days in seconds
|
|
36
|
+
const result = splitFromToBy90DaysSeconds(from, to)
|
|
37
|
+
expect(result).toEqual([
|
|
38
|
+
{ from: 0, to: 60 * 60 * 24 * 90 },
|
|
39
|
+
{ from: 60 * 60 * 24 * 90, to: 60 * 60 * 24 * 90 * 2 },
|
|
40
|
+
{ from: 60 * 60 * 24 * 90 * 2, to: 60 * 60 * 24 * 90 * 3 },
|
|
41
|
+
])
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('should handle ranges that are not exact multiples of 90 days', () => {
|
|
45
|
+
const from = 0
|
|
46
|
+
const to = 60 * 60 * 24 * 95 // 95 days in seconds
|
|
47
|
+
const result = splitFromToBy90DaysSeconds(from, to)
|
|
48
|
+
expect(result).toEqual([
|
|
49
|
+
{ from: 0, to: 60 * 60 * 24 * 90 },
|
|
50
|
+
{ from: 60 * 60 * 24 * 90, to: 60 * 60 * 24 * 95 },
|
|
51
|
+
])
|
|
52
|
+
})
|
|
53
|
+
})
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { createBigDecimal } from '@0xtorch/big-decimal'
|
|
2
|
+
|
|
3
|
+
import type { Config } from '../../types'
|
|
4
|
+
import { fiatCurrencyDecimals } from '../constants'
|
|
5
|
+
import { getCoinMarketChartRange, getCoinsMarkets } from '../externals'
|
|
6
|
+
import type {
|
|
7
|
+
CryptoCurrency,
|
|
8
|
+
CryptoCurrencyDataSource,
|
|
9
|
+
CryptoCurrencyPrice,
|
|
10
|
+
FiatCurrency,
|
|
11
|
+
} from '../types'
|
|
12
|
+
|
|
13
|
+
const createCryptoCurrencyDataSource = <
|
|
14
|
+
const dataSource extends CryptoCurrencyDataSource,
|
|
15
|
+
>(
|
|
16
|
+
dataSource: dataSource,
|
|
17
|
+
): dataSource => ({
|
|
18
|
+
...dataSource,
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
export const coingeckoCryptoCurrencyDataSource = createCryptoCurrencyDataSource(
|
|
22
|
+
{
|
|
23
|
+
getCurrentPrice: async (
|
|
24
|
+
{ targetCurrencies, vsCurrency },
|
|
25
|
+
config?: Config,
|
|
26
|
+
) => {
|
|
27
|
+
if (
|
|
28
|
+
targetCurrencies.some(
|
|
29
|
+
(currency) => currency.market.coingeckoId === undefined,
|
|
30
|
+
)
|
|
31
|
+
) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
'require parameters.targetCurrencies.market.coingeckoId',
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
const coingeckoIds = targetCurrencies.map(
|
|
37
|
+
(currency) => currency.market.coingeckoId!,
|
|
38
|
+
)
|
|
39
|
+
const coins = await getCoinsMarkets(
|
|
40
|
+
{
|
|
41
|
+
vs_currency: vsCurrency.id,
|
|
42
|
+
ids: coingeckoIds,
|
|
43
|
+
},
|
|
44
|
+
config,
|
|
45
|
+
)
|
|
46
|
+
if (coins.length !== targetCurrencies.length) {
|
|
47
|
+
throw new Error('invalid response')
|
|
48
|
+
}
|
|
49
|
+
return targetCurrencies.map((currency) => {
|
|
50
|
+
const targetCoin = coins.find(
|
|
51
|
+
(coin) => coin.id === currency.market.coingeckoId,
|
|
52
|
+
)
|
|
53
|
+
if (targetCoin === undefined) {
|
|
54
|
+
throw new Error('invalid response')
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
cryptoCurrencyId: currency.id,
|
|
58
|
+
crypto: currency,
|
|
59
|
+
fiatCurrencyId: vsCurrency.id,
|
|
60
|
+
price: createBigDecimal(
|
|
61
|
+
targetCoin.current_price.toFixed(fiatCurrencyDecimals),
|
|
62
|
+
fiatCurrencyDecimals,
|
|
63
|
+
),
|
|
64
|
+
timestamp: new Date(targetCoin.last_updated).getTime(),
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
},
|
|
68
|
+
getHistoricalPrices: async (
|
|
69
|
+
{ targetCurrencies, vsCurrency, from, to },
|
|
70
|
+
config?: Config,
|
|
71
|
+
) => {
|
|
72
|
+
const timeoutTimestamp =
|
|
73
|
+
Date.now() + (config?.timeout === undefined ? 60_000 : config.timeout)
|
|
74
|
+
if (
|
|
75
|
+
targetCurrencies.some(
|
|
76
|
+
(currency) => currency.market.coingeckoId === undefined,
|
|
77
|
+
)
|
|
78
|
+
) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
'require parameters.targetCurrencies.market.coingeckoId',
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// from,to を seconds に変換する
|
|
85
|
+
const fromSeconds = Math.floor(from / 1000)
|
|
86
|
+
const toSeconds = Math.ceil(to / 1000)
|
|
87
|
+
|
|
88
|
+
// from, to を 90 日間毎に分割する
|
|
89
|
+
const ranges = splitFromToBy90DaysSeconds(fromSeconds, toSeconds)
|
|
90
|
+
|
|
91
|
+
// 通貨毎に価格を取得する
|
|
92
|
+
const mut_prices: CryptoCurrencyPrice[] = []
|
|
93
|
+
for (const currency of targetCurrencies) {
|
|
94
|
+
const prices = await getCryptoCurrencyPrices(
|
|
95
|
+
currency,
|
|
96
|
+
vsCurrency,
|
|
97
|
+
ranges,
|
|
98
|
+
{
|
|
99
|
+
timeout: timeoutTimestamp - Date.now(),
|
|
100
|
+
logger: config?.logger,
|
|
101
|
+
},
|
|
102
|
+
)
|
|
103
|
+
mut_prices.push(...prices)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return mut_prices
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
const getCryptoCurrencyPrices = async (
|
|
112
|
+
cryptoCurrency: CryptoCurrency,
|
|
113
|
+
vsCurrency: FiatCurrency,
|
|
114
|
+
ranges: readonly { readonly from: number; readonly to: number }[],
|
|
115
|
+
config?: Config,
|
|
116
|
+
): Promise<readonly CryptoCurrencyPrice[]> => {
|
|
117
|
+
const timeoutTimestamp =
|
|
118
|
+
Date.now() + (config?.timeout === undefined ? 60_000 : config.timeout)
|
|
119
|
+
|
|
120
|
+
if (cryptoCurrency.market.coingeckoId === undefined) {
|
|
121
|
+
throw new Error('invalid cryptoCurrency')
|
|
122
|
+
}
|
|
123
|
+
const mut_prices: CryptoCurrencyPrice[] = []
|
|
124
|
+
for (const { from, to } of ranges) {
|
|
125
|
+
const { prices } = await getCoinMarketChartRange(
|
|
126
|
+
{
|
|
127
|
+
id: cryptoCurrency.market.coingeckoId,
|
|
128
|
+
vs_currency: vsCurrency.id,
|
|
129
|
+
from,
|
|
130
|
+
to,
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
timeout: timeoutTimestamp - Date.now(),
|
|
134
|
+
logger: config?.logger,
|
|
135
|
+
},
|
|
136
|
+
)
|
|
137
|
+
mut_prices.push(
|
|
138
|
+
...prices.map(([timestamp, price]) => ({
|
|
139
|
+
cryptoCurrencyId: cryptoCurrency.id,
|
|
140
|
+
crypto: cryptoCurrency,
|
|
141
|
+
fiatCurrencyId: vsCurrency.id,
|
|
142
|
+
timestamp,
|
|
143
|
+
price: createBigDecimal(
|
|
144
|
+
price.toFixed(fiatCurrencyDecimals),
|
|
145
|
+
fiatCurrencyDecimals,
|
|
146
|
+
),
|
|
147
|
+
})),
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
return mut_prices
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** 90日間の秒数 */
|
|
154
|
+
const DAYS_90_SECONDS = 60 * 60 * 24 * 90
|
|
155
|
+
|
|
156
|
+
/** from, to を 90 日間毎に分割する */
|
|
157
|
+
export const splitFromToBy90DaysSeconds = (
|
|
158
|
+
from: number,
|
|
159
|
+
to: number,
|
|
160
|
+
): { readonly from: number; readonly to: number }[] => {
|
|
161
|
+
const diffSeconds = to - from
|
|
162
|
+
const count = Math.ceil(diffSeconds / DAYS_90_SECONDS)
|
|
163
|
+
|
|
164
|
+
return Array.from({ length: count }, (_, index) => {
|
|
165
|
+
const currentFrom = from + DAYS_90_SECONDS * index
|
|
166
|
+
const currentTo = Math.min(to, from + DAYS_90_SECONDS * (index + 1))
|
|
167
|
+
return { from: currentFrom, to: currentTo }
|
|
168
|
+
})
|
|
169
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createCryptoCurrency } from '../creates'
|
|
2
|
+
|
|
3
|
+
export const ethereum = createCryptoCurrency({
|
|
4
|
+
type: 'CryptoCurrency',
|
|
5
|
+
id: 'ethereum',
|
|
6
|
+
name: 'Ethereum',
|
|
7
|
+
symbol: 'ETH',
|
|
8
|
+
icon: undefined,
|
|
9
|
+
market: {
|
|
10
|
+
coingeckoId: 'ethereum',
|
|
11
|
+
marketCapUsd: undefined,
|
|
12
|
+
},
|
|
13
|
+
updatedAt: Date.now(),
|
|
14
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createCryptoCurrency } from '../creates'
|
|
2
|
+
|
|
3
|
+
export const fantom = createCryptoCurrency({
|
|
4
|
+
type: 'CryptoCurrency',
|
|
5
|
+
id: 'fantom',
|
|
6
|
+
name: 'Fantom',
|
|
7
|
+
symbol: 'FTM',
|
|
8
|
+
icon: undefined,
|
|
9
|
+
market: {
|
|
10
|
+
coingeckoId: 'fantom',
|
|
11
|
+
marketCapUsd: undefined,
|
|
12
|
+
},
|
|
13
|
+
updatedAt: Date.now(),
|
|
14
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { astar } from './astar'
|
|
2
|
+
export { avalanche } from './avalanche'
|
|
3
|
+
export { bnb } from './bnb'
|
|
4
|
+
export { coingeckoCryptoCurrencyDataSource } from './coingeckoCryptoCurrencyDataSource'
|
|
5
|
+
export { ethereum } from './ethereum'
|
|
6
|
+
export { eur } from './eur'
|
|
7
|
+
export { fantom } from './fantom'
|
|
8
|
+
export { jpy } from './jpy'
|
|
9
|
+
export { kava } from './kava'
|
|
10
|
+
export { mantle } from './mantle'
|
|
11
|
+
export { maticNetwork } from './maticNetwork'
|
|
12
|
+
export { metis } from './metis'
|
|
13
|
+
export { moonbeam } from './moonbeam'
|
|
14
|
+
export { moonriver } from './moonriver'
|
|
15
|
+
export { ronin } from './ronin'
|
|
16
|
+
export { usd } from './usd'
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createCryptoCurrency } from '../creates'
|
|
2
|
+
|
|
3
|
+
export const kava = createCryptoCurrency({
|
|
4
|
+
type: 'CryptoCurrency',
|
|
5
|
+
id: 'kava',
|
|
6
|
+
name: 'Kava',
|
|
7
|
+
symbol: 'KAVA',
|
|
8
|
+
icon: undefined,
|
|
9
|
+
market: {
|
|
10
|
+
coingeckoId: 'kava',
|
|
11
|
+
marketCapUsd: undefined,
|
|
12
|
+
},
|
|
13
|
+
updatedAt: Date.now(),
|
|
14
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createCryptoCurrency } from '../creates'
|
|
2
|
+
|
|
3
|
+
export const mantle = createCryptoCurrency({
|
|
4
|
+
type: 'CryptoCurrency',
|
|
5
|
+
id: 'mantle',
|
|
6
|
+
name: 'Mantle',
|
|
7
|
+
symbol: 'MNT',
|
|
8
|
+
icon: undefined,
|
|
9
|
+
market: {
|
|
10
|
+
coingeckoId: 'mantle',
|
|
11
|
+
marketCapUsd: undefined,
|
|
12
|
+
},
|
|
13
|
+
updatedAt: Date.now(),
|
|
14
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createCryptoCurrency } from '../creates'
|
|
2
|
+
|
|
3
|
+
export const maticNetwork = createCryptoCurrency({
|
|
4
|
+
type: 'CryptoCurrency',
|
|
5
|
+
id: 'matic-network',
|
|
6
|
+
name: 'Polygon',
|
|
7
|
+
symbol: 'MATIC',
|
|
8
|
+
icon: undefined,
|
|
9
|
+
market: {
|
|
10
|
+
coingeckoId: 'matic-network',
|
|
11
|
+
marketCapUsd: undefined,
|
|
12
|
+
},
|
|
13
|
+
updatedAt: Date.now(),
|
|
14
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createCryptoCurrency } from '../creates'
|
|
2
|
+
|
|
3
|
+
export const metis = createCryptoCurrency({
|
|
4
|
+
type: 'CryptoCurrency',
|
|
5
|
+
id: 'metis-token',
|
|
6
|
+
name: 'Metis',
|
|
7
|
+
symbol: 'METIS',
|
|
8
|
+
icon: undefined,
|
|
9
|
+
market: {
|
|
10
|
+
coingeckoId: 'metis-token',
|
|
11
|
+
marketCapUsd: undefined,
|
|
12
|
+
},
|
|
13
|
+
updatedAt: Date.now(),
|
|
14
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createCryptoCurrency } from '../creates'
|
|
2
|
+
|
|
3
|
+
export const moonbeam = createCryptoCurrency({
|
|
4
|
+
type: 'CryptoCurrency',
|
|
5
|
+
id: 'moonbeam',
|
|
6
|
+
name: 'Moonbeam',
|
|
7
|
+
symbol: 'GLMR',
|
|
8
|
+
icon: undefined,
|
|
9
|
+
market: {
|
|
10
|
+
coingeckoId: 'moonbeam',
|
|
11
|
+
marketCapUsd: undefined,
|
|
12
|
+
},
|
|
13
|
+
updatedAt: Date.now(),
|
|
14
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createCryptoCurrency } from '../creates'
|
|
2
|
+
|
|
3
|
+
export const moonriver = createCryptoCurrency({
|
|
4
|
+
type: 'CryptoCurrency',
|
|
5
|
+
id: 'moonriver',
|
|
6
|
+
name: 'Moonriver',
|
|
7
|
+
symbol: 'MOVR',
|
|
8
|
+
icon: undefined,
|
|
9
|
+
market: {
|
|
10
|
+
coingeckoId: 'moonriver',
|
|
11
|
+
marketCapUsd: undefined,
|
|
12
|
+
},
|
|
13
|
+
updatedAt: Date.now(),
|
|
14
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createCryptoCurrency } from '../creates'
|
|
2
|
+
|
|
3
|
+
export const ronin = createCryptoCurrency({
|
|
4
|
+
type: 'CryptoCurrency',
|
|
5
|
+
id: 'ronin',
|
|
6
|
+
name: 'Ronin',
|
|
7
|
+
symbol: 'RON',
|
|
8
|
+
icon: undefined,
|
|
9
|
+
market: {
|
|
10
|
+
coingeckoId: 'ronin',
|
|
11
|
+
marketCapUsd: undefined,
|
|
12
|
+
},
|
|
13
|
+
updatedAt: Date.now(),
|
|
14
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const rootUrl = 'https://api.coingecko.com/api/v3'
|