@exodus/solana-plugin 1.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/package.json +34 -0
- package/src/index.js +126 -0
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@exodus/solana-plugin",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Exodus internal Solana asset plugin",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"src",
|
|
8
|
+
"!src/**/__tests__"
|
|
9
|
+
],
|
|
10
|
+
"author": "Exodus Movement, Inc.",
|
|
11
|
+
"license": "UNLICENSED",
|
|
12
|
+
"homepage": "https://github.com/ExodusMovement/assets",
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "restricted"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"pretest": "yarn lint",
|
|
18
|
+
"test": "jest",
|
|
19
|
+
"lint": "eslint ./src",
|
|
20
|
+
"lint:fix": "yarn lint --fix"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@exodus/assets": "^9.0.1",
|
|
24
|
+
"@exodus/bip44-constants": "^195.0.0",
|
|
25
|
+
"@exodus/solana-api": "^2.5.23",
|
|
26
|
+
"@exodus/solana-lib": "^1.6.7",
|
|
27
|
+
"@exodus/solana-meta": "^1.0.4",
|
|
28
|
+
"minimalistic-assert": "^1.0.1"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@exodus/assets-testing": "file:../../../__testing__"
|
|
32
|
+
},
|
|
33
|
+
"gitHead": "9e502c63fb13a0d98349cb953f10b24467fff617"
|
|
34
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { connectAssetsList } from '@exodus/assets'
|
|
2
|
+
import bip44Constants from '@exodus/bip44-constants/by-ticker'
|
|
3
|
+
import {
|
|
4
|
+
createGetKeyIdentifier,
|
|
5
|
+
getAddressFromPublicKey,
|
|
6
|
+
getEncodedSecretKey,
|
|
7
|
+
isValidAddress,
|
|
8
|
+
parseUnsignedTx,
|
|
9
|
+
signUnsignedTx,
|
|
10
|
+
} from '@exodus/solana-lib'
|
|
11
|
+
import { solana as feeData } from '@exodus/solana-lib/src/fee-data'
|
|
12
|
+
import assetList from '@exodus/solana-meta'
|
|
13
|
+
import ms from 'ms'
|
|
14
|
+
import serverApi, {
|
|
15
|
+
getBalancesFactory,
|
|
16
|
+
getUnstakingFee,
|
|
17
|
+
SolanaMonitor,
|
|
18
|
+
SolanaFeeMonitor,
|
|
19
|
+
SolanaAccountState,
|
|
20
|
+
createAndBroadcastTXFactory,
|
|
21
|
+
} from '@exodus/solana-api'
|
|
22
|
+
|
|
23
|
+
const createAsset = ({
|
|
24
|
+
config: {
|
|
25
|
+
stakingFeatureAvailable = true,
|
|
26
|
+
includeUnparsed = false,
|
|
27
|
+
monitorInterval = ms('30s'),
|
|
28
|
+
} = {},
|
|
29
|
+
overrideCallback = ({ asset }) => asset,
|
|
30
|
+
} = {}) => {
|
|
31
|
+
const assets = connectAssetsList(assetList)
|
|
32
|
+
const base = assets.solana
|
|
33
|
+
|
|
34
|
+
const accountReserve = base.currency.SOL(0.01)
|
|
35
|
+
const lowBalance = base.currency.SOL(0.01)
|
|
36
|
+
const MIN_STAKING_BALANCE = base.currency.SOL(0.01)
|
|
37
|
+
|
|
38
|
+
const address = {
|
|
39
|
+
validate: isValidAddress,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const bip44 = bip44Constants[base.ticker]
|
|
43
|
+
|
|
44
|
+
const keys = {
|
|
45
|
+
encodePrivate: getEncodedSecretKey,
|
|
46
|
+
encodePublic: getAddressFromPublicKey,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const getBalances = getBalancesFactory({ stakingFeatureAvailable })
|
|
50
|
+
|
|
51
|
+
const sendTx = createAndBroadcastTXFactory(serverApi)
|
|
52
|
+
|
|
53
|
+
const createToken = ({ mintAddress, name, ...tokenDef }) => ({
|
|
54
|
+
...tokenDef,
|
|
55
|
+
address,
|
|
56
|
+
assetId: mintAddress,
|
|
57
|
+
bip44,
|
|
58
|
+
keys,
|
|
59
|
+
mintAddress,
|
|
60
|
+
name,
|
|
61
|
+
api: {
|
|
62
|
+
features: {},
|
|
63
|
+
getBalances,
|
|
64
|
+
},
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
const createCustomToken = ({ assetId, assetName, ...rest }) =>
|
|
68
|
+
createToken({ ...rest, name: assetName, mintAddress: assetId })
|
|
69
|
+
|
|
70
|
+
const features = {
|
|
71
|
+
accountState: true,
|
|
72
|
+
customTokens: true,
|
|
73
|
+
feeMonitor: true,
|
|
74
|
+
feesApi: true,
|
|
75
|
+
nfts: true,
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const api = {
|
|
79
|
+
addressHasHistory: (...args) => serverApi.getAccountInfo(...args).then((acc) => !!acc),
|
|
80
|
+
broadcastTx: (...args) => serverApi.broadcastTransaction(...args),
|
|
81
|
+
createAccountState: () => SolanaAccountState,
|
|
82
|
+
createFeeMonitor: (args) => new SolanaFeeMonitor({ ...args, api: serverApi }),
|
|
83
|
+
createHistoryMonitor: (args) =>
|
|
84
|
+
new SolanaMonitor({ interval: monitorInterval, includeUnparsed, api: serverApi, ...args }),
|
|
85
|
+
createToken: (tokenDef) =>
|
|
86
|
+
tokenDef.isBuiltIn ? createToken(tokenDef) : createCustomToken(tokenDef),
|
|
87
|
+
defaultAddressPath: 'm/0/0',
|
|
88
|
+
features,
|
|
89
|
+
getBalances,
|
|
90
|
+
getFee: () => feeData.fee,
|
|
91
|
+
getFeeAsync: async () => feeData.fee,
|
|
92
|
+
getFeeData: () => feeData,
|
|
93
|
+
getKeyIdentifier: createGetKeyIdentifier({
|
|
94
|
+
bip44,
|
|
95
|
+
assetName: base.name,
|
|
96
|
+
keyType: 'nacl',
|
|
97
|
+
}),
|
|
98
|
+
getTokens: () =>
|
|
99
|
+
Object.values(assets)
|
|
100
|
+
.filter((asset) => asset.name !== base.name)
|
|
101
|
+
.map(createToken),
|
|
102
|
+
getUnstakingFee,
|
|
103
|
+
hasFeature: (feature) => !!features[feature], // @deprecated use api.features instead
|
|
104
|
+
parseUnsignedTx,
|
|
105
|
+
parseTx: ({ unsignedTx }) => parseUnsignedTx(unsignedTx),
|
|
106
|
+
sendTx,
|
|
107
|
+
signTx: ({ unsignedTx, privateKey }) => signUnsignedTx(unsignedTx, privateKey),
|
|
108
|
+
signUnsignedTx,
|
|
109
|
+
validateAssetId: isValidAddress,
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const fullAsset = {
|
|
113
|
+
...base,
|
|
114
|
+
address,
|
|
115
|
+
keys,
|
|
116
|
+
api,
|
|
117
|
+
bip44,
|
|
118
|
+
accountReserve,
|
|
119
|
+
lowBalance,
|
|
120
|
+
MIN_STAKING_BALANCE,
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return overrideCallback({ asset: fullAsset })
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export default { createAsset }
|