Skip to content

Commit 697d843

Browse files
authored
Sync updates to escrow protection for aptos (#1428)
1 parent d24cc34 commit 697d843

File tree

6 files changed

+46
-90
lines changed

6 files changed

+46
-90
lines changed

examples/oft-adapter-aptos-move/sources/oft_implementation/oft_adapter_fa.move

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
module oft::oft_adapter_fa {
1010
use std::coin::Coin;
1111
use std::fungible_asset::{Self, FungibleAsset, Metadata};
12+
use std::object::ObjectCore;
1213
use std::object::{Self, address_to_object, ExtendRef, Object, object_exists};
1314
use std::option::{Self, Option};
1415
use std::primary_fungible_store;
@@ -298,8 +299,8 @@ module oft::oft_adapter_fa {
298299
let constructor_ref = &object::create_named_object(account, b"fa_escrow");
299300
let escrow_extend_ref = object::generate_extend_ref(constructor_ref);
300301

301-
// Disable the transfer of the escrow object
302-
object::disable_ungated_transfer(&object::generate_transfer_ref(constructor_ref));
302+
// Disown the escrow object to prevent withdrawal by transient owner
303+
object::transfer(account, object::object_from_constructor_ref<ObjectCore>(constructor_ref), @0x0);
303304

304305
// Initialize the storage and save the ExtendRef for future signer generation
305306
move_to(move account, OftImpl {

examples/oft-adapter-aptos-move/sources/shared_oapp/oapp_compose.move

Lines changed: 0 additions & 82 deletions
This file was deleted.

examples/oft-adapter-aptos-move/sources/shared_oapp/oapp_store.move

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ module oft::oapp_store {
1111

1212
friend oft::oapp_core;
1313
friend oft::oapp_receive;
14-
friend oft::oapp_compose;
1514
friend oft::oft;
1615

1716
// ************************************************* CONFIGURATION *************************************************

examples/oft-adapter-aptos-move/sources/shared_oft/oft.move

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ module oft::oft {
3636
use oft_common::oft_limit::OftLimit;
3737

3838
friend oft::oapp_receive;
39-
friend oft::oapp_compose;
4039

4140
// ======================================== For FungibleAsset Enabled OFTs ========================================
4241

examples/oft-adapter-aptos-move/tests/implementations/oft_adapter_fa_tests.move

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
module oft::oft_adapter_fa_tests {
55
use std::account::{create_account_for_test, create_signer_for_test};
66
use std::event::was_event_emitted;
7-
use std::fungible_asset::{Self, Metadata};
8-
use std::fungible_asset::{mint, MintRef};
7+
use std::fungible_asset::{Self, FungibleStore, Metadata, mint, MintRef};
98
use std::object::address_to_object;
109
use std::option;
1110
use std::primary_fungible_store;
11+
use std::primary_fungible_store::ensure_primary_store_exists;
1212
use std::timestamp;
1313
use std::vector;
1414

@@ -91,6 +91,47 @@ module oft::oft_adapter_fa_tests {
9191
assert!(balance == 123456700, 0);
9292
}
9393

94+
#[test]
95+
#[expected_failure(abort_code = 0x50008 /*ENOT_STORE_OWNER*/, location = std::fungible_asset)]
96+
fun test_transfer_escrow_fails() {
97+
let mint_ref = setup();
98+
99+
let dst_eid = 2u32;
100+
// This configuration function (debit) is not resposible for handling dust, therefore the tested amount excludes
101+
// the dust amount (last two digits)
102+
let amount_ld = 123456700;
103+
let min_amount_ld = 0u64;
104+
105+
let fa = mint(&mint_ref, amount_ld);
106+
let (sent, received) = oft_adapter_fa::debit_fungible_asset(
107+
@444,
108+
&mut fa,
109+
min_amount_ld,
110+
dst_eid,
111+
);
112+
113+
// amount sent and received should reflect the amount debited
114+
assert!(sent == 123456700, 0);
115+
assert!(received == 123456700, 0);
116+
117+
// no remaining balance in debited account
118+
let remaining_balance = fungible_asset::amount(&fa);
119+
assert!(remaining_balance == 00, 0);
120+
burn_token_for_test(fa);
121+
122+
// escrow balance should increase to match
123+
let balance = primary_fungible_store::balance(escrow_address(), oft_adapter_fa::metadata());
124+
assert!(balance == 123456700, 0);
125+
126+
// transfer from escrow should fail
127+
fungible_asset::transfer<FungibleStore>(
128+
&create_signer_for_test(@oft),
129+
ensure_primary_store_exists<Metadata>(escrow_address(), oft_adapter_fa::metadata()),
130+
ensure_primary_store_exists<Metadata>(@555, oft_adapter_fa::metadata()),
131+
1000,
132+
);
133+
}
134+
94135
#[test]
95136
fun test_credit() {
96137
let mint_ref = setup();
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
#[test_only]
22
module oft::oapp_test_helper {
3-
use oft::oapp_compose;
43
use oft::oapp_receive;
54
use oft::oapp_store;
65

76
public fun init_oapp() {
87
oapp_store::init_module_for_test();
98
oapp_receive::init_module_for_test();
10-
oapp_compose::init_module_for_test();
119
}
1210
}

0 commit comments

Comments
 (0)