Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
292 commits
Select commit Hold shift + click to select a range
2fa9989
wip
fusede Nov 16, 2025
dd205b2
feat: separate protocol fees
fusede Nov 16, 2025
5e48a4e
refactor
fusede Nov 16, 2025
0364f63
chore
fusede Nov 16, 2025
55b5d72
docs
fusede Nov 16, 2025
cc34128
feat: escrow-swap contract
fusede Nov 16, 2025
7a8f7e7
fix: docs
fusede Nov 16, 2025
1af3dda
docs: chore
fusede Nov 16, 2025
d263def
chore
fusede Nov 16, 2025
fea77ae
fix: don't unclude params twice in on_auth
fusede Nov 16, 2025
c4a2136
chore
fusede Nov 16, 2025
be59817
chore
fusede Nov 16, 2025
ce39192
refactor
fusede Nov 17, 2025
1de7349
feat: maker_refunded event
fusede Nov 17, 2025
ff89ee0
fix: docs
fusede Nov 17, 2025
3594146
fix: docs
fusede Nov 17, 2025
38f089a
fix: docs
fusede Nov 17, 2025
cb02d0a
refactor
fusede Nov 17, 2025
1a55ef7
refactor
fusede Nov 17, 2025
3bd2c54
refactor
fusede Nov 17, 2025
16d7578
chore
fusede Nov 17, 2025
0165a51
chore
fusede Nov 17, 2025
412ece9
chore: relax dependencies
fusede Nov 17, 2025
8459995
chore
fusede Nov 17, 2025
4753781
fix(escrow): docs
fusede Nov 18, 2025
b8f7e17
docs: mention embedded lending
fusede Nov 18, 2025
0232eb9
chore
fusede Nov 18, 2025
07893a7
chore
fusede Nov 18, 2025
51c3c4d
chore
fusede Nov 19, 2025
118215a
feat(escrow): taker deadline
mitinarseny Nov 20, 2025
184f5a1
docs: taker's deadline
mitinarseny Nov 20, 2025
3106c67
docs: mention dutch auction
mitinarseny Nov 20, 2025
07a5f6b
Merge branch 'main' into feat/escrow-swap
fusede Nov 24, 2025
8e34bad
format
fusede Nov 24, 2025
c7a89d7
feat: deterministic accounts
mitinarseny Nov 27, 2025
f4b050b
feat: enable deterministic-accounts feature
mitinarseny Nov 27, 2025
ca6e56d
Merge remote-tracking branch 'origin' into feat/deterministic-accounts
mitinarseny Nov 27, 2025
1887cb8
Merge branch 'main' into feat/deterministic-accounts
mitinarseny Nov 27, 2025
f512505
Merge branch 'main' into feat/deterministic-accounts
mitinarseny Nov 27, 2025
654d6df
Merge branch 'main' into feat/escrow-swap
mitinarseny Nov 27, 2025
2132cbc
fix: remove #[serde_as]
mitinarseny Nov 27, 2025
5064d53
feat: state_init in NotifyOnTransfer
mitinarseny Nov 27, 2025
2941039
Merge branch 'feat/state_init_on_transfer' into feat/escrow-swap-nep616
mitinarseny Nov 27, 2025
3ca283d
feat: state_init by verifier, it works!
mitinarseny Nov 27, 2025
e2f6b0f
format
mitinarseny Nov 27, 2025
b8abac3
Merge remote-tracking branch 'origin' into feat/deterministic-accounts
mitinarseny Nov 28, 2025
141a70d
Merge branch 'feat/deterministic-accounts' into feat/state_init_on_tr…
mitinarseny Nov 28, 2025
3e176b9
Merge branch 'feat/state_init_on_transfer' into feat/escrow-swap-nep616
mitinarseny Nov 28, 2025
40c9501
draft
pityjllk Nov 27, 2025
188c3fe
draft impl
pityjllk Nov 27, 2025
f65b773
happy path test
pityjllk Nov 27, 2025
0684199
minor changes
pityjllk Nov 28, 2025
4b42d61
Merge branch 'main' into feat/deterministic-accounts
mitinarseny Nov 28, 2025
019767b
Merge branch 'feat/deterministic-accounts' into feat/state_init_on_tr…
mitinarseny Nov 28, 2025
de9d5e2
Merge branch 'main' into feat/escrow-swap
mitinarseny Nov 28, 2025
77de7e1
Merge branch 'feat/escrow-swap' into feat/escrow-swap-nep616
mitinarseny Nov 28, 2025
6636f90
tmp
pityjllk Nov 28, 2025
7870feb
add missing files
pityjllk Nov 28, 2025
268cca3
Merge remote-tracking branch 'origin/main' into feat/bus-proxy
pityjllk Nov 28, 2025
e987803
escrow params migrated
pityjllk Nov 28, 2025
7d6e7a7
feat: test example
mitinarseny Nov 28, 2025
a3cdda4
Merge branch 'main' into feat/deterministic-accounts
mitinarseny Nov 28, 2025
60254d2
Merge branch 'feat/deterministic-accounts' into feat/state_init_on_tr…
mitinarseny Nov 28, 2025
a7009dd
Merge branch 'main' into feat/escrow-swap
mitinarseny Nov 28, 2025
207af25
Merge branch 'feat/escrow-swap' into feat/escrow-swap-nep616
mitinarseny Nov 28, 2025
fe4e6e6
chore
mitinarseny Nov 28, 2025
1536c7f
Merge branch 'feat/deterministic-accounts' into feat/state_init_on_tr…
mitinarseny Nov 28, 2025
39f0e42
chore
mitinarseny Nov 28, 2025
132330d
chore
mitinarseny Nov 30, 2025
5c7fba8
Merge branch 'feat/escrow-swap' into feat/escrow-swap-nep616
mitinarseny Nov 30, 2025
452a448
migrated escrow params
pityjllk Dec 1, 2025
861cf52
fix: cleanup only after deadline expired
mitinarseny Dec 2, 2025
360abab
fix: docs
mitinarseny Dec 2, 2025
483d45a
Merge branch 'feat/escrow-swap' into feat/escrow-swap-nep616
mitinarseny Dec 2, 2025
e6019ee
progress
pityjllk Dec 3, 2025
a8a12c8
progress
pityjllk Dec 4, 2025
964a821
Merge remote-tracking branch 'origin/main' into feat/bus-proxy
pityjllk Dec 4, 2025
181ab0a
progress
pityjllk Dec 4, 2025
8872782
all tests passing
pityjllk Dec 5, 2025
fa01011
yielded promise parameters works
pityjllk Dec 5, 2025
50a5a50
verify caller
pityjllk Dec 5, 2025
f47287b
align auth-transfer with escrow-proxy
pityjllk Dec 5, 2025
2dbe7f6
Merge branch 'main' into feat/escrow-swap-nep616
mitinarseny Dec 5, 2025
7002751
minor changes
pityjllk Dec 5, 2025
b5cb13c
comipilation fails
pityjllk Dec 5, 2025
6b81442
fix
mitinarseny Dec 5, 2025
5323b44
fix
mitinarseny Dec 5, 2025
3cb1098
chore
mitinarseny Dec 5, 2025
387114c
before contract feature
pityjllk Dec 6, 2025
d1518fe
feat: 'contract' feature for defuse-transfer-auth
pityjllk Dec 6, 2025
510ba53
wip: tests works again
pityjllk Dec 6, 2025
1eb991b
state machine like impl
pityjllk Dec 6, 2025
b6cad79
state machine pass tests
pityjllk Dec 6, 2025
de9b060
ut and error handling
pityjllk Dec 6, 2025
897f683
test failing
pityjllk Dec 7, 2025
009f852
state init works
pityjllk Dec 7, 2025
eaf68c7
sandbox based ut for transfer auth contract
pityjllk Dec 7, 2025
b3b3c0b
simplify
pityjllk Dec 8, 2025
dabba55
Merge branch 'main' into feat/escrow-swap
mitinarseny Dec 8, 2025
987341b
fix: use pub TokenId fields
mitinarseny Dec 8, 2025
772b3ef
chore
mitinarseny Dec 8, 2025
81b24b5
chore
mitinarseny Dec 8, 2025
f6e39cd
tests works
pityjllk Dec 8, 2025
a800c9b
move state machine to dedicated file
pityjllk Dec 8, 2025
9f6fd3a
cleanup
pityjllk Dec 8, 2025
1f85d50
rename
pityjllk Dec 8, 2025
706dac0
current
pityjllk Dec 8, 2025
59358d8
progress
pityjllk Dec 8, 2025
5310ecc
progress
pityjllk Dec 8, 2025
86c7dfc
env removed
pityjllk Dec 8, 2025
f68f2b1
env removed
pityjllk Dec 8, 2025
97375fe
compilesh
pityjllk Dec 8, 2025
49be118
semi works
pityjllk Dec 8, 2025
2cf8db7
cargo make build fixed
pityjllk Dec 8, 2025
7f5c9e1
workarounds
pityjllk Dec 8, 2025
2a619b3
compiles
pityjllk Dec 8, 2025
d3318bc
Merge remote-tracking branch 'origin/main' into feat/bus-proxy
pityjllk Dec 8, 2025
308310c
forward
pityjllk Dec 8, 2025
81889b9
test passes
pityjllk Dec 8, 2025
ac80d47
tests works
pityjllk Dec 8, 2025
0eaa403
fix test
pityjllk Dec 8, 2025
059340f
test works
pityjllk Dec 8, 2025
2737f5c
Merge branch 'main' into feat/escrow-swap
mitinarseny Dec 9, 2025
46f9364
Merge remote-tracking branch 'origin/main' into feat/bus-proxy
pityjllk Dec 9, 2025
94d2d41
Merge remote-tracking branch 'origin/feat/escrow-swap' into feat/bus-…
pityjllk Dec 9, 2025
072a1dd
ext pattern
pityjllk Dec 9, 2025
91c133a
ext trait for escrow proxy
pityjllk Dec 9, 2025
bef2443
test passes
pityjllk Dec 9, 2025
4c0aa10
test passes
pityjllk Dec 9, 2025
3ea8cae
still passsing
pityjllk Dec 9, 2025
9fd9d5f
test passes
pityjllk Dec 9, 2025
622787d
chore: improve test logs
pityjllk Dec 9, 2025
a4c73c6
align escrow proxy
pityjllk Dec 10, 2025
2205d4f
trasnfer auth fixes
pityjllk Dec 10, 2025
e4ef573
cleanup
pityjllk Dec 10, 2025
b1f0914
test passing
pityjllk Dec 10, 2025
8ddb885
another test case
pityjllk Dec 10, 2025
28aecea
tests working
pityjllk Dec 10, 2025
526168d
align tests
pityjllk Dec 10, 2025
480ce55
cleanup
pityjllk Dec 10, 2025
4e7e6ee
cleanup
pityjllk Dec 10, 2025
51d2ec2
cleanup
pityjllk Dec 10, 2025
bd86937
use global account id
pityjllk Dec 10, 2025
22f5a57
serialize msg_hash as hex
pityjllk Dec 10, 2025
35344de
refactor
pityjllk Dec 10, 2025
5d75840
auth call module
pityjllk Dec 10, 2025
3482be2
move to module
pityjllk Dec 10, 2025
5822d06
fix escrow proxy
pityjllk Dec 10, 2025
42c2b86
escrow-proxy refactor
pityjllk Dec 10, 2025
24a62bd
tests for global deployment of multi receiver stub
pityjllk Dec 10, 2025
5cd87eb
work on example
pityjllk Dec 11, 2025
00e5ef8
bump near sdk
pityjllk Dec 11, 2025
48b3231
tmp
pityjllk Dec 11, 2025
2079eea
script progress
pityjllk Dec 11, 2025
d3b9d2b
user setup
pityjllk Dec 11, 2025
97e2984
auth intent
pityjllk Dec 11, 2025
2d16ff8
intents prepared
pityjllk Dec 11, 2025
823ee9a
works fine
pityjllk Dec 11, 2025
2d6ffc0
progressing
pityjllk Dec 11, 2025
b6c253c
fix minor issue
pityjllk Dec 11, 2025
ca907f8
deployment time
pityjllk Dec 11, 2025
926e3fa
failing
pityjllk Dec 11, 2025
e802814
test works
pityjllk Dec 11, 2025
a7bcdd9
demo worked
pityjllk Dec 11, 2025
fecbf8c
all tests for escrow-swap passes
pityjllk Dec 11, 2025
92bbc6f
salt fix for e2e test
pityjllk Dec 11, 2025
f3a8de7
cleanup cargo warnings
pityjllk Dec 11, 2025
091d20a
fix clippy
pityjllk Dec 11, 2025
f4dbbde
fix formatting
pityjllk Dec 11, 2025
afc09c4
chore: workaround for false negative status for global contract deplo…
pityjllk Dec 15, 2025
c52a9f6
Merge remote-tracking branch 'origin/main' into feat/bus-proxy
pityjllk Dec 17, 2025
732f9a8
chore: remove outdated crate
pityjllk Dec 17, 2025
8b968de
chore: revert changes
pityjllk Dec 17, 2025
8758e03
chore: align with promise yield interface
pityjllk Dec 17, 2025
a036d73
chore: remove unnecessary alias
pityjllk Dec 17, 2025
502679b
extract escrow-proxy extensions to common extensions crate
pityjllk Dec 22, 2025
7f217e9
move transfer-auth ext to dedicated crate
pityjllk Dec 22, 2025
efa5a30
cleanup escrow-swap
pityjllk Dec 22, 2025
e233483
remove outdated files
pityjllk Dec 22, 2025
b3879eb
use RC 0.7 of near-api & near-api-types
pityjllk Dec 22, 2025
c1cbb75
move multi-token-receiver ext featues to sandbox-ext
pityjllk Dec 22, 2025
2e472ce
align test with stub
pityjllk Dec 22, 2025
d074f66
move tests to integration tests crate
pityjllk Dec 22, 2025
4e5ed44
simplify
pityjllk Dec 23, 2025
0de89b2
make transfer auth tests into module
pityjllk Dec 23, 2025
1d20d48
simplify
pityjllk Dec 23, 2025
0c10d06
simplified tests
pityjllk Dec 23, 2025
b0de5c3
cleanup
pityjllk Dec 23, 2025
3921024
siplify test
pityjllk Dec 23, 2025
e1d4e54
cleanup
pityjllk Dec 23, 2025
eb11fd0
check authroization status
pityjllk Dec 23, 2025
19d967f
cleanup
pityjllk Dec 23, 2025
a101eea
escrow builder
pityjllk Dec 30, 2025
b1df08d
escrow builder
pityjllk Dec 30, 2025
97407d0
simplify test a lot
pityjllk Dec 30, 2025
6ef841c
simplify test case
pityjllk Jan 5, 2026
c49dc9a
progress
pityjllk Jan 5, 2026
a5f1600
escrow swap ut
pityjllk Jan 5, 2026
67bc096
contract self destruct
pityjllk Jan 5, 2026
6c7b998
check for contract existence in transfer auth tests
pityjllk Jan 5, 2026
351cc5e
TransferAuth -> OneShotCondVar
pityjllk Jan 5, 2026
286a760
rename
pityjllk Jan 6, 2026
77f7536
cleanup
pityjllk Jan 6, 2026
a9f8d76
cleanup
pityjllk Jan 6, 2026
18a8a7e
cleanup
pityjllk Jan 6, 2026
5f0191d
add another ut
pityjllk Jan 6, 2026
3ec5acf
even more tests
pityjllk Jan 6, 2026
1b00796
benchmarks and gas estimation for proxy
pityjllk Jan 7, 2026
2774a8e
move impl to dedicatd modules
pityjllk Jan 7, 2026
fbf2905
organize code
pityjllk Jan 7, 2026
d4ad906
final touches
pityjllk Jan 8, 2026
3fa6895
temporary hardcode cargo near on ci
pityjllk Jan 8, 2026
cdb65da
fix example compilation
pityjllk Jan 8, 2026
b466658
address code rabbit findings
pityjllk Jan 8, 2026
3cbb802
workaround cargo audit
pityjllk Jan 8, 2026
262f45f
fix clippy
pityjllk Jan 8, 2026
301bd83
add comments for patched deps
pityjllk Jan 8, 2026
20c6fd6
rename dummy to zero salt
pityjllk Jan 8, 2026
f32d9c9
address comments
pityjllk Jan 8, 2026
5a8aa9a
fix formatting
pityjllk Jan 8, 2026
20e44f8
workaround cargo audit issue
pityjllk Jan 8, 2026
dfc51ff
address comments
pityjllk Jan 20, 2026
cd27e35
get rid of acl
pityjllk Jan 20, 2026
858774a
dependency to escrow-swap
pityjllk Jan 20, 2026
c8653ab
Merge remote-tracking branch 'origin/main' into feat/bus-proxy
pityjllk Jan 20, 2026
438c76c
cleanup extensions
pityjllk Jan 21, 2026
446d4e2
fix formatting
pityjllk Jan 21, 2026
7cbdf16
cleanup
pityjllk Jan 21, 2026
d8037df
promise utils
pityjllk Jan 21, 2026
61a298d
remove patched dependency
pityjllk Jan 26, 2026
784fa52
use 'deterministic-account-ids' where actually needed
pityjllk Jan 26, 2026
06584e2
use reexported modules
pityjllk Jan 26, 2026
991fbf7
remove outdated test
pityjllk Jan 26, 2026
9b45f05
sort deps
pityjllk Jan 26, 2026
215fde7
use reexported dependency
pityjllk Jan 26, 2026
9f8eeeb
get rid of unnecessary braces
pityjllk Jan 26, 2026
7cd8588
remove serde_json dependency
pityjllk Jan 26, 2026
02c210e
expect empty message
pityjllk Jan 26, 2026
fb3d41b
const messages
pityjllk Jan 26, 2026
00af97f
merge imports
pityjllk Jan 26, 2026
b663e2c
remove init attribute
pityjllk Jan 26, 2026
8584ad0
remove unused fn
pityjllk Jan 26, 2026
3eeb30b
remove callback result from signature
pityjllk Jan 26, 2026
e8299f9
use Result for try_* fns
pityjllk Jan 26, 2026
d8a82c7
remove outdated state transitions and update
pityjllk Jan 26, 2026
6c799e2
add cv_ prefix to view methods
pityjllk Jan 26, 2026
2ac6610
use require
pityjllk Jan 26, 2026
b8f19d0
hardcoded empy json
pityjllk Jan 26, 2026
021fc54
on_auth_signer => notifier_id
pityjllk Jan 26, 2026
740a976
fix formatting
pityjllk Jan 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .cargo/audit.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# cargo-audit configuration
# https://docs.rs/cargo-audit/latest/cargo_audit/config/

[advisories]
# Ignore the lru unsound advisory - it comes from near-vm-runner which is
# locked to lru ^0.12.3 and cannot be updated to the fixed 0.16.3 version.
# The advisory relates to IterMut's Stacked Borrows violation, which does
# not affect our usage as we don't use IterMut directly.
# Tracked: https://github.com/near/nearcore/issues/XXXXX (upstream)
ignore = ["RUSTSEC-2026-0002"]
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ jobs:
with:
cache: false
- name: Install cargo-audit
run: cargo install cargo-audit --version "^0.21" --locked
# Require 0.22+ for CVSS 4.0 support (advisory-db now contains CVSS 4.0 entries)
run: cargo install cargo-audit --version "^0.22" --locked
- uses: rustsec/audit-check@v2.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
90 changes: 81 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"defuse",
"erc191",
"escrow-swap",
"escrow-proxy",
"fees",
"io-utils",
"map-utils",
Expand All @@ -33,6 +34,7 @@ members = [
"tip191",
"token-id",
"ton-connect",
"oneshot-condvar",
"wnear",
]
default-members = ["defuse"]
Expand All @@ -56,6 +58,7 @@ defuse-deadline.path = "deadline"
defuse-decimal.path = "decimal"
defuse-erc191.path = "erc191"
defuse-escrow-swap.path = "escrow-swap"
defuse-escrow-proxy.path = "escrow-proxy"
defuse-fees.path = "fees"
defuse-io-utils.path = "io-utils"
defuse-map-utils.path = "map-utils"
Expand All @@ -70,6 +73,7 @@ defuse-poa-token.path = "poa-token"
defuse-sandbox.path = "sandbox"
defuse-sep53.path = "sep53"
defuse-serde-utils.path = "serde-utils"
defuse-oneshot-condvar.path = "oneshot-condvar"
defuse-tip191.path = "tip191"
defuse-token-id = { path = "token-id", default-features = false }
defuse-ton-connect = { path = "ton-connect", default-features = false, features = [
Expand All @@ -82,8 +86,9 @@ defuse-test-utils.path = "test-utils"

cargo-near-build = "0.9.0"
near-account-id = "2.4.0"
near-api = "0.8.2"
near-api-types = "0.8.2"
near-api = "0.8.3"
near-api-types = "0.8.3"
near-openapi-client = "0.7"
near-openapi-types = "0.6.0"
near-contract-standards = "5.24"
near-crypto = "0.34.1"
Expand Down
42 changes: 42 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ POA_TOKEN_WASM_NO_REGISTRATION_WASM = "${POA_TOKEN_WITH_NO_REGISTRATION_DIR}/def
MT_RECEIVER_STUB_DIR = "${TARGET_DIR}/multi-token-receiver-stub"
MT_RECEIVER_STUB_WASM = "${MT_RECEIVER_STUB_DIR}/multi_token_receiver_stub.wasm"

ESCROW_PROXY_DIR = "${TARGET_DIR}/"
ESCROW_PROXY_WASM = "${ESCROW_PROXY_DIR}/defuse_escrow_proxy.wasm"

ONESHOT_CONDVAR_DIR = "${TARGET_DIR}/"
ONESHOT_CONDVAR_WASM = "${ONESHOT_CONDVAR_DIR}/defuse_oneshot_condvar.wasm"

[tasks.default]
alias = "build"

Expand All @@ -25,6 +31,8 @@ dependencies = [
"build-escrow-swap",
"build-poa-factory",
"build-poa-token-no-registration",
"build-escrow-proxy",
"build-oneshot-condvar",
"contract-stats",
"build-multi-token-receiver-stub",
]
Expand Down Expand Up @@ -114,6 +122,40 @@ args = [
"--no-embed-abi",
]

[tasks.build-escrow-proxy]
dependencies = ["add-cache-dir-tag"]
command = "cargo"
args = [
"near",
"build",
"non-reproducible-wasm",
"--locked",
"--manifest-path",
"./escrow-proxy/Cargo.toml",
"--features",
"abi,contract,escrow-swap",
"--out-dir",
"${ESCROW_PROXY_DIR}",
"--no-embed-abi",
]

[tasks.build-oneshot-condvar]
dependencies = ["add-cache-dir-tag"]
command = "cargo"
args = [
"near",
"build",
"non-reproducible-wasm",
"--locked",
"--manifest-path",
"./oneshot-condvar/Cargo.toml",
"--features",
"abi,contract,auth-call",
"--out-dir",
"${ONESHOT_CONDVAR_DIR}",
"--no-abi",
]

# ============================================================================
# Build reproducible tasks
# ============================================================================
Expand Down
1 change: 1 addition & 0 deletions defuse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ contract = [

sandbox = [
"arbitrary",
"contract",
"dep:defuse-sandbox",
"dep:defuse-test-utils",
]
Expand Down
14 changes: 2 additions & 12 deletions defuse/src/contract/tokens/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod nep245;

use super::Contract;
use defuse_core::{DefuseError, Result, token_id::TokenId};
use defuse_near_utils::{Lock, UnwrapOrPanic};
use defuse_near_utils::{Lock, UnwrapOrPanic, max_list_u128_json_len};
use defuse_nep245::{MtBurnEvent, MtEvent, MtMintEvent};
use itertools::{Either, Itertools};
use near_sdk::{AccountId, AccountIdRef, Gas, env, json_types::U128, serde_json};
Expand Down Expand Up @@ -152,7 +152,7 @@ impl Contract {
let tokens_count = tokens_iter.len();

let requested_refunds =
env::promise_result_checked(0, Self::mt_on_transfer_max_result_len(tokens_count))
env::promise_result_checked(0, max_list_u128_json_len(tokens_count))
.ok()
.and_then(|value| serde_json::from_slice::<Vec<U128>>(&value).ok())
.filter(|refunds| refunds.len() == tokens_count);
Expand Down Expand Up @@ -211,16 +211,6 @@ impl Contract {
MtEvent::MtBurn([burn_event].as_slice().into()).emit();
}
}

const fn mt_on_transfer_max_result_len(amounts_count: usize) -> usize {
// we allow at most one newline char and up to 8 spaces/tabs if the JSON was prettified
const MAX_LEN_PER_AMOUNT: usize =
" \"+340282366920938463463374607431768211455\",\n".len(); // u128::MAX

amounts_count
.saturating_mul(MAX_LEN_PER_AMOUNT)
.saturating_add("[\n]".len())
}
}

const MAX_TOKEN_ID_LEN: usize = 127;
Expand Down
13 changes: 6 additions & 7 deletions defuse/src/contract/tokens/nep245/resolver.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Cow;

use defuse_near_utils::{Lock, UnwrapOrPanic, UnwrapOrPanicError};
use defuse_near_utils::{Lock, UnwrapOrPanic, UnwrapOrPanicError, max_list_u128_json_len};
use defuse_nep245::{
ClearedApproval, MtEventEmit, MtTransferEvent, TokenId, resolver::MultiTokenResolver,
};
Expand All @@ -27,12 +27,11 @@ impl MultiTokenResolver for Contract {
"invalid args"
);

let mut refunds =
env::promise_result_checked(0, Self::mt_on_transfer_max_result_len(amounts.len()))
.ok()
.and_then(|value| serde_json::from_slice::<Vec<U128>>(&value).ok())
.filter(|refund| refund.len() == amounts.len())
.unwrap_or_else(|| amounts.clone());
let mut refunds = env::promise_result_checked(0, max_list_u128_json_len(amounts.len()))
.ok()
.and_then(|value| serde_json::from_slice::<Vec<U128>>(&value).ok())
.filter(|refund| refund.len() == amounts.len())
.unwrap_or_else(|| amounts.clone());

let sender_id = previous_owner_ids.first().cloned().unwrap_or_panic();

Expand Down
Loading
Loading