@exodus/solana-plugin 1.23.2 → 1.24.0
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/CHANGELOG.md +10 -0
- package/package.json +4 -2
- package/src/create-asset.js +2 -0
- package/src/send-validations.js +126 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.24.0](https://github.com/ExodusMovement/assets/compare/@exodus/solana-plugin@1.23.2...@exodus/solana-plugin@1.24.0) (2025-07-16)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
* feat: move send validation to each asset plugin (#6076)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
6
16
|
## [1.23.2](https://github.com/ExodusMovement/assets/compare/@exodus/solana-plugin@1.23.1...@exodus/solana-plugin@1.23.2) (2025-06-25)
|
|
7
17
|
|
|
8
18
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/solana-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.24.0",
|
|
4
4
|
"description": "Solana plugin for Exodus SDK powered wallets.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@exodus/assets": "^11.0.0",
|
|
25
25
|
"@exodus/bip44-constants": "^195.0.0",
|
|
26
|
+
"@exodus/i18n-dummy": "^1.0.0",
|
|
27
|
+
"@exodus/send-validation-model": "^1.0.0",
|
|
26
28
|
"@exodus/solana-api": "^3.20.3",
|
|
27
29
|
"@exodus/solana-lib": "^3.11.2",
|
|
28
30
|
"@exodus/solana-meta": "^2.3.1",
|
|
@@ -40,5 +42,5 @@
|
|
|
40
42
|
"type": "git",
|
|
41
43
|
"url": "git+https://github.com/ExodusMovement/assets.git"
|
|
42
44
|
},
|
|
43
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "c12ad495a49f457bc0941e6b568b608e2a6a4250"
|
|
44
46
|
}
|
package/src/create-asset.js
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
import ms from 'ms'
|
|
25
25
|
|
|
26
26
|
import { createGetBalanceForAddress } from './get-balance-for-address.js'
|
|
27
|
+
import sendValidations from './send-validations.js'
|
|
27
28
|
import { createWeb3API } from './web3/index.js'
|
|
28
29
|
|
|
29
30
|
const DEFAULT_ACCOUNT_RESERVE = 0
|
|
@@ -180,6 +181,7 @@ export const createSolanaAssetFactory =
|
|
|
180
181
|
getFeeData: () => feeData,
|
|
181
182
|
getSupportedPurposes: () => [44],
|
|
182
183
|
getKeyIdentifier: createGetKeyIdentifier({ bip44, assetName: base.name }),
|
|
184
|
+
getSendValidations: () => sendValidations,
|
|
183
185
|
getTokens: () =>
|
|
184
186
|
Object.values(assets)
|
|
185
187
|
.filter((asset) => asset.name !== base.name)
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { t } from '@exodus/i18n-dummy'
|
|
2
|
+
import sendValidationModel from '@exodus/send-validation-model'
|
|
3
|
+
|
|
4
|
+
const { createValidator, FIELDS, PRIORITY_LEVELS, VALIDATION_TYPES } = sendValidationModel
|
|
5
|
+
|
|
6
|
+
// cannot send SOL to token Address
|
|
7
|
+
const solanaAddressTypeValidator = createValidator({
|
|
8
|
+
id: 'WRONG_ADDRESS_TYPE',
|
|
9
|
+
type: VALIDATION_TYPES.ERROR,
|
|
10
|
+
field: FIELDS.ADDRESS,
|
|
11
|
+
|
|
12
|
+
isValid: ({ addressDetails }) => addressDetails && addressDetails.addressType !== 'token',
|
|
13
|
+
|
|
14
|
+
priority: PRIORITY_LEVELS.BASE,
|
|
15
|
+
|
|
16
|
+
shouldValidate: ({ asset }) => ['solana'].includes(asset.name),
|
|
17
|
+
getMessage: () => t('Destination address is for a different token type.'),
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
// cannot send token X to a different target account address (token Y)
|
|
21
|
+
const solanaMintAddressValidator = createValidator({
|
|
22
|
+
id: 'ADDRESS_MINT_MISMATCH',
|
|
23
|
+
type: VALIDATION_TYPES.ERROR,
|
|
24
|
+
shouldValidate: ({ asset }) => ['SOLANA_TOKEN'].includes(asset.assetType),
|
|
25
|
+
|
|
26
|
+
isValid: async ({ asset, addressDetails }) =>
|
|
27
|
+
!addressDetails.targetMint || asset.mintAddress === addressDetails.targetMint,
|
|
28
|
+
priority: PRIORITY_LEVELS.MIDDLE,
|
|
29
|
+
getMessage: ({ asset }) =>
|
|
30
|
+
t(`Destination Wallet is not a ${asset.baseAsset.displayName} ${asset.displayTicker} address.`),
|
|
31
|
+
field: FIELDS.ADDRESS,
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const solanaAddressValidator = createValidator({
|
|
35
|
+
id: 'SOLANA_ADDRESS',
|
|
36
|
+
type: VALIDATION_TYPES.ERROR,
|
|
37
|
+
shouldValidate: ({ asset }) => asset.name === 'solana',
|
|
38
|
+
isValid: async ({ addressDetails }) => {
|
|
39
|
+
return addressDetails.addressType !== 'token'
|
|
40
|
+
},
|
|
41
|
+
priority: PRIORITY_LEVELS.MIDDLE,
|
|
42
|
+
getMessage: () => t(`The Solana network doesn't allow sending SOL to a Token Account address.`),
|
|
43
|
+
field: FIELDS.ADDRESS,
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
const solanaRentExemptAmountValidator = createValidator({
|
|
47
|
+
id: 'SOL_RENT_EXEMPT_AMOUNT',
|
|
48
|
+
type: VALIDATION_TYPES.ERROR,
|
|
49
|
+
shouldValidate: ({ asset, sendAmount }) =>
|
|
50
|
+
sendAmount && (asset.assetType === 'SOLANA_TOKEN' || asset.name === 'solana'),
|
|
51
|
+
isValid: async ({ asset, destinationAddress, sendAmount, baseAssetBalance, feeAmount }) => {
|
|
52
|
+
if (!destinationAddress || !sendAmount || sendAmount.isZero) {
|
|
53
|
+
return true
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const serverApi = asset.baseAsset.serverApi
|
|
57
|
+
const rentExemptValue = await serverApi.getRentExemptionMinAmount(destinationAddress)
|
|
58
|
+
const rentExemptAmount = asset.baseAsset.currency.baseUnit(rentExemptValue)
|
|
59
|
+
|
|
60
|
+
// differentiate between SOL and Solana token
|
|
61
|
+
let isEnoughForRent
|
|
62
|
+
if (asset.name === asset.baseAsset.name) {
|
|
63
|
+
// sending SOL
|
|
64
|
+
isEnoughForRent = sendAmount.gte(rentExemptAmount)
|
|
65
|
+
} else {
|
|
66
|
+
// sending token
|
|
67
|
+
isEnoughForRent = baseAssetBalance
|
|
68
|
+
.sub(feeAmount || asset.feeAsset.currency.ZERO)
|
|
69
|
+
.gte(rentExemptAmount)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return isEnoughForRent
|
|
73
|
+
},
|
|
74
|
+
priority: PRIORITY_LEVELS.MIDDLE,
|
|
75
|
+
|
|
76
|
+
getMessage: () => t(`Amount too low. Send at least 0.002 SOL to cover network fees.`), // hardcoded rent exempt amount, will be refactored once we have a better solution to return async calls
|
|
77
|
+
|
|
78
|
+
field: FIELDS.ADDRESS,
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
const solanaRentExemptAmountSenderValidator = {
|
|
82
|
+
id: 'SOL_RENT_EXEMPT_AMOUNT_SENDER',
|
|
83
|
+
type: VALIDATION_TYPES.ERROR,
|
|
84
|
+
priority: PRIORITY_LEVELS.MIDDLE,
|
|
85
|
+
field: FIELDS.ADDRESS,
|
|
86
|
+
shouldValidate: ({ asset, sendAmount, fees, spendableBalance, accountState }) =>
|
|
87
|
+
sendAmount &&
|
|
88
|
+
asset.name === 'solana' &&
|
|
89
|
+
fees &&
|
|
90
|
+
accountState?.rentExemptAmount &&
|
|
91
|
+
spendableBalance,
|
|
92
|
+
|
|
93
|
+
isValid: ({ accountState, asset, fromAddress, sendAmount, spendableBalance, fees }) => {
|
|
94
|
+
const rentExemptAmount = accountState.rentExemptAmount
|
|
95
|
+
const remaining = spendableBalance.sub(fees.fee).sub(sendAmount)
|
|
96
|
+
return remaining.isZero || remaining.gte(rentExemptAmount)
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
getMessage: ({ accountState, asset }) =>
|
|
100
|
+
t(
|
|
101
|
+
`You can either leave a zero balance, which will close your SOL account, or maintain a minimum balance of ${accountState.rentExemptAmount.toDefaultString()} ${asset.displayTicker} to keep it active.`
|
|
102
|
+
),
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const solanaPayValidator = createValidator({
|
|
106
|
+
id: 'SOLANA_PAY',
|
|
107
|
+
type: VALIDATION_TYPES.ERROR,
|
|
108
|
+
shouldValidate: ({ solanaPayInfo }) => {
|
|
109
|
+
return !!(solanaPayInfo?.recipient || solanaPayInfo?.link)
|
|
110
|
+
},
|
|
111
|
+
isValid: async ({ solanaPayInfo }) => {
|
|
112
|
+
return !(solanaPayInfo.recipient || solanaPayInfo.link)
|
|
113
|
+
},
|
|
114
|
+
priority: PRIORITY_LEVELS.MIDDLE,
|
|
115
|
+
getMessage: () => t(`Please use Solana Pay feature to scan this QRCode.`),
|
|
116
|
+
field: FIELDS.ADDRESS,
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
export default [
|
|
120
|
+
solanaAddressTypeValidator,
|
|
121
|
+
solanaAddressValidator,
|
|
122
|
+
solanaMintAddressValidator,
|
|
123
|
+
solanaRentExemptAmountValidator,
|
|
124
|
+
solanaPayValidator,
|
|
125
|
+
solanaRentExemptAmountSenderValidator,
|
|
126
|
+
]
|