-
Notifications
You must be signed in to change notification settings - Fork 19
feat: imt_mint/imt_burn intents
#193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 28 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
142726e
pubkey account synchronizer added
hlgltvnnk 475e5a7
test fixed
hlgltvnnk 00dc35b
mint tokens method added
hlgltvnnk 8f56a19
mint tokens fn call added
hlgltvnnk 47cb36c
burn intent added
hlgltvnnk 552904f
burn intent added
hlgltvnnk b940a6f
naming upd
hlgltvnnk 60524fd
mint + burn intents changes
hlgltvnnk 1e277ae
tests updated
hlgltvnnk 3347af8
minor edits
hlgltvnnk fdf1353
mint intent updated
hlgltvnnk 6ba4a39
fix
hlgltvnnk e5c3096
fix
hlgltvnnk 3e6ca0b
review changes
hlgltvnnk a82384f
fix
hlgltvnnk 99e38ee
burn intent removed
hlgltvnnk 8146632
notification added to mt_mint intent
hlgltvnnk 974ab4f
dip5 standart added
hlgltvnnk 6602cee
burn intents added + tests updated
hlgltvnnk 2aa54eb
burn tests added
hlgltvnnk 174654e
typo fix
hlgltvnnk 416ad99
naming updated
hlgltvnnk 18f4268
simulate burn intent test added
hlgltvnnk b2b2e13
refactoring
hlgltvnnk 1f0037c
Merge branch 'main' into feat/far-acc-management
hlgltvnnk a1e0f37
imt feature added
hlgltvnnk e5f8b68
notification min gas upd
hlgltvnnk 38344f4
mint intent updated
hlgltvnnk a352ecd
minor edit
hlgltvnnk 709aeac
refactoring
hlgltvnnk deeace5
minter added to burn intent + notification static gas limits updated
hlgltvnnk 6cac2b2
doc fix
hlgltvnnk d75da27
fix
hlgltvnnk 37a1953
fix
hlgltvnnk bf617a7
refactorign
hlgltvnnk ea03a31
fix
hlgltvnnk 60c1c4b
fix
hlgltvnnk 6a3b585
fix
hlgltvnnk 9cc44df
chore
mitinarseny f54ae8b
fix: allocate more gas for implicit Near account_id transfer
mitinarseny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -162,7 +162,7 @@ jobs: | |
| with: | ||
| cache: false | ||
| - name: Install cargo-audit | ||
| run: cargo install cargo-audit --version "^0.21" --locked | ||
| run: cargo install cargo-audit --version "^0.22" --locked | ||
| - uses: rustsec/[email protected] | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
@@ -188,7 +188,8 @@ jobs: | |
| - name: Install Cargo Plugins | ||
| run: cargo install cargo-audit --locked | ||
| - name: Run security audit | ||
| run: cargo audit --deny unsound --deny yanked | ||
| # TODO: ignoring lru vulnerability in near-sdk, remove when fixed | ||
| run: cargo audit --deny unsound --deny yanked --ignore RUSTSEC-2026-0002 | ||
| # run: cargo audit --deny warnings # Warnings include: unmaintained, unsound and yanked | ||
|
|
||
| contract_analysis: | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
hlgltvnnk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or 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,142 @@ | ||
| use std::{borrow::Cow, collections::BTreeMap}; | ||
|
|
||
| use defuse_token_id::TokenId; | ||
| use near_sdk::{AccountId, AccountIdRef, CryptoHash, near}; | ||
| use serde_with::{DisplayFromStr, serde_as}; | ||
|
|
||
| use crate::{ | ||
| DefuseError, Result, | ||
| accounts::AccountEvent, | ||
| amounts::Amounts, | ||
| engine::{Engine, Inspector, State}, | ||
| events::DefuseEvent, | ||
| intents::tokens::NotifyOnTransfer, | ||
| }; | ||
|
|
||
| use super::{ExecutableIntent, IntentEvent}; | ||
|
|
||
| #[near(serializers = [borsh, json])] | ||
| #[derive(Debug, Clone)] | ||
| /// Mint a set of tokens from the signer to a specified account id, within the intents contract. | ||
| pub struct ImtMint { | ||
| pub receiver_id: AccountId, | ||
|
|
||
| // The tokens transferred in this call will be wrapped | ||
| // in such a way as to bind the token ID to the minter authority. | ||
| // The final string representation of the token | ||
| // will be as follows: `imt:<minter_id>:<token_id>` | ||
| #[serde_as(as = "Amounts<BTreeMap<_, DisplayFromStr>>")] | ||
| pub tokens: ImtTokens, | ||
|
|
||
| #[serde(default, skip_serializing_if = "Option::is_none")] | ||
| pub memo: Option<String>, | ||
|
|
||
| /// Optionally notify receiver_id via `mt_on_transfer()` | ||
| /// | ||
| /// NOTE: `min_gas` is adjusted with following values: | ||
| /// * default: 30TGas | ||
| /// * minimum: 5TGas | ||
| #[serde(flatten, default, skip_serializing_if = "Option::is_none")] | ||
| pub notification: Option<NotifyOnTransfer>, | ||
| } | ||
|
|
||
| impl ExecutableIntent for ImtMint { | ||
| #[inline] | ||
| fn execute_intent<S, I>( | ||
| self, | ||
| signer_id: &AccountIdRef, | ||
| engine: &mut Engine<S, I>, | ||
| intent_hash: CryptoHash, | ||
| ) -> Result<()> | ||
| where | ||
| S: State, | ||
| I: Inspector, | ||
| { | ||
| engine | ||
| .inspector | ||
| .on_event(DefuseEvent::ImtMint(Cow::Borrowed( | ||
| [IntentEvent::new( | ||
| AccountEvent::new(signer_id, Cow::Borrowed(&self)), | ||
| intent_hash, | ||
| )] | ||
| .as_slice(), | ||
| ))); | ||
|
|
||
| let tokens = self.tokens.into_generic_tokens(signer_id); | ||
hlgltvnnk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| engine | ||
| .state | ||
| .mt_mint(self.receiver_id.clone(), tokens.clone(), self.memo)?; | ||
|
|
||
| if let Some(notification) = self.notification { | ||
| engine | ||
| .state | ||
| .notify_on_transfer(signer_id, self.receiver_id, tokens, notification); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| #[near(serializers = [borsh, json])] | ||
| #[derive(Debug, Clone)] | ||
| /// Burn a set of tokens minted by signer, within the intents contract. | ||
hlgltvnnk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pub struct ImtBurn { | ||
| // The tokens burned in this call should be wrapped | ||
| // as Imt tokens bounded to the minter authority | ||
| // as follows: `imt:<minter_id>:<token_id>` | ||
| #[serde_as(as = "Amounts<BTreeMap<_, DisplayFromStr>>")] | ||
| pub tokens: Amounts, | ||
|
|
||
| #[serde(default, skip_serializing_if = "Option::is_none")] | ||
| pub memo: Option<String>, | ||
| } | ||
|
|
||
| impl ExecutableIntent for ImtBurn { | ||
| #[inline] | ||
| fn execute_intent<S, I>( | ||
| self, | ||
| signer_id: &AccountIdRef, | ||
| engine: &mut Engine<S, I>, | ||
| intent_hash: CryptoHash, | ||
| ) -> Result<()> | ||
| where | ||
| S: State, | ||
| I: Inspector, | ||
| { | ||
| engine | ||
| .inspector | ||
| .on_event(DefuseEvent::ImtBurn(Cow::Borrowed( | ||
| [IntentEvent::new( | ||
| AccountEvent::new(signer_id, Cow::Borrowed(&self)), | ||
| intent_hash, | ||
| )] | ||
| .as_slice(), | ||
| ))); | ||
|
|
||
| self.tokens | ||
| .iter() | ||
| .all(|(token, _)| matches!(token, TokenId::Imt(_))) | ||
| .then_some(()) | ||
| .ok_or(DefuseError::OnlyImtTokensCanBeBurned)?; | ||
hlgltvnnk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| engine.state.mt_burn(signer_id, self.tokens, self.memo) | ||
| } | ||
hlgltvnnk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| pub type ImtTokens = Amounts<BTreeMap<defuse_nep245::TokenId, u128>>; | ||
hlgltvnnk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| impl ImtTokens { | ||
| fn into_generic_tokens(self, minter_id: &AccountIdRef) -> Amounts<BTreeMap<TokenId, u128>> { | ||
| Amounts::new( | ||
| self.iter() | ||
hlgltvnnk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .map(|(token_id, amount)| { | ||
| let token = | ||
| defuse_token_id::imt::ImtTokenId::new(minter_id, token_id.to_string()) | ||
| .into(); | ||
| (token, *amount) | ||
| }) | ||
| .collect(), | ||
| ) | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -51,7 +51,7 @@ container_build_command = [ | |
| "build", | ||
| "non-reproducible-wasm", | ||
| "--locked", | ||
| "--features=abi,contract", | ||
| "--features=abi,contract,imt", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldnt we make it default feature instead?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now, this feature will only be available on FAR, so we are not making it the default |
||
| "--no-embed-abi", | ||
| ] | ||
|
|
||
|
|
@@ -72,6 +72,7 @@ sandbox = [ | |
| "dep:defuse-sandbox", | ||
| "dep:defuse-test-utils", | ||
| ] | ||
| imt = ["defuse-core/imt"] | ||
|
|
||
| [dev-dependencies] | ||
| defuse-core = { workspace = true, features = ["arbitrary"] } | ||
|
|
||
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.