-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: prevent implicit asset burn (#3540)
* feat: added test for feature * feat: added guards against illicit asset burns * chore: docs * chore: changeset * chore: removed test.only * chore: finalize the PR * chore: refactored the burnable assets to a helper * chore: use `autoCost` * chore: breaking change * docs: added docs on asset burn * speeling * chore: changeset * lintfix * chore: allow asset burn via `sendTransaction` options * Update apps/docs/src/guide/transactions/transaction-request.md Co-authored-by: Nedim Salkić <[email protected]> * chore: added asset burn validation to wallet * chore: update wallet-unlocked tx example to be valid * chore: update test assertions Co-authored-by: Nedim Salkić <[email protected]> * chore: added asset burn validation for `MessageCoin` * chore: update validation check Co-authored-by: Sérgio Torres <[email protected]> * chore: use transactionRequest for helpers --------- Co-authored-by: Nedim Salkić <[email protected]> Co-authored-by: Anderson Arboleya <[email protected]> Co-authored-by: Sérgio Torres <[email protected]> Co-authored-by: Daniel Bate <[email protected]>
- Loading branch information
1 parent
0f138cd
commit 08a31d8
Showing
13 changed files
with
584 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@fuel-ts/account": minor | ||
"@fuel-ts/errors": patch | ||
--- | ||
|
||
feat!: prevent implicit asset burn |
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
39 changes: 39 additions & 0 deletions
39
apps/docs/src/guide/transactions/snippets/transaction-request/asset-burn.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,39 @@ | ||
import { InputType, Provider, ScriptTransactionRequest, Wallet } from 'fuels'; | ||
import { ASSET_A } from 'fuels/test-utils'; | ||
|
||
import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; | ||
|
||
const provider = new Provider(LOCAL_NETWORK_URL); | ||
const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); | ||
|
||
// #region asset-burn | ||
const transactionRequest = new ScriptTransactionRequest(); | ||
|
||
const { | ||
coins: [coin], | ||
} = await sender.getCoins(ASSET_A); | ||
|
||
// Add the coin as an input, without a change output | ||
transactionRequest.inputs.push({ | ||
id: coin.id, | ||
type: InputType.Coin, | ||
owner: coin.owner.toB256(), | ||
amount: coin.amount, | ||
assetId: coin.assetId, | ||
txPointer: '0x00000000000000000000000000000000', | ||
witnessIndex: | ||
transactionRequest.getCoinInputWitnessIndexByOwner(coin.owner) ?? | ||
transactionRequest.addEmptyWitness(), | ||
}); | ||
|
||
// Fund the transaction | ||
await transactionRequest.autoCost(sender); | ||
|
||
// Send the transaction with asset burn enabled | ||
const tx = await sender.sendTransaction(transactionRequest, { | ||
enableAssetBurn: true, | ||
}); | ||
// #endregion asset-burn | ||
|
||
const { isStatusSuccess } = await tx.waitForResult(); | ||
console.log('Transaction should have been successful', isStatusSuccess); |
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
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
Oops, something went wrong.