-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Leaving dust when sending transaction (#7412)
* fix: remove balance check from validateSendConfirmation * fix: dont allow leaving dust on the address * fix: required storage deposit for minimal basic output * chore: rename typo * chore: add comments * fix: conditions for leaving dust * chore: improve variable naming & error message --------- Co-authored-by: Begoña Álvarez de la Cruz <[email protected]>
- Loading branch information
1 parent
ab1adc6
commit d168f57
Showing
4 changed files
with
62 additions
and
3 deletions.
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
41 changes: 41 additions & 0 deletions
41
...es/shared/lib/core/wallet/utils/outputs/getRequiredStorageDepositForMinimalBasicOutput.ts
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,41 @@ | ||
import { getClient } from '@core/profile-manager/api/getClient' | ||
import { EMPTY_HEX_ID } from '@core/wallet' | ||
import { | ||
AddressType, | ||
AddressUnlockCondition, | ||
BasicOutputBuilderParams, | ||
Ed25519Address, | ||
UnlockConditionType, | ||
} from '@iota/sdk/out/types' | ||
import { plainToInstance } from 'class-transformer' | ||
|
||
const MOCK_BASIC_OUTPUT_AMOUNT = '10' | ||
|
||
/** | ||
* Calculate minimum storage deposit required for the most minimal basic output with a single address unlock condition. | ||
* @returns The minimum storage deposit. | ||
*/ | ||
export async function getRequiredStorageDepositForMinimalBasicOutput(): Promise<number> { | ||
const address = { | ||
type: AddressType.Ed25519, | ||
pubKeyHash: EMPTY_HEX_ID, | ||
} | ||
const ed25519Address = plainToInstance(Ed25519Address, address) | ||
|
||
const unlockCondition = { | ||
type: UnlockConditionType.Address, | ||
address: ed25519Address, | ||
} | ||
const addressUnlockCondition = plainToInstance(AddressUnlockCondition, unlockCondition) | ||
|
||
const params: BasicOutputBuilderParams = { | ||
amount: MOCK_BASIC_OUTPUT_AMOUNT, | ||
unlockConditions: [addressUnlockCondition], | ||
} | ||
|
||
const client = await getClient() | ||
const basicOutput = await client.buildBasicOutput(params) | ||
const minimumRequiredStorageDeposit = await client.minimumRequiredStorageDeposit(basicOutput) | ||
|
||
return minimumRequiredStorageDeposit | ||
} |
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