-
Notifications
You must be signed in to change notification settings - Fork 18
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
Switch to FT-141 for BridgeToken #39
Conversation
Filled the bug found in near-sdk-rs: near/near-sdk-rs#306 |
Fixes #39 |
This PR fixes #21. |
Leverage rust enum types for better interface of ResultType Formatting
Right now mint always require attached a NEAR deposit, but there are several options:
If in addition there is a view function that allows UI to know in advance whether the user is registered or not we can improve UX for options 2 and 3. However they still need to first sign tx to register with FullAccessKey, and then add extra key to call non-payable mint function. |
bridge-token-factory/src/lib.rs
Outdated
.try_to_vec() | ||
.unwrap(), | ||
); | ||
PromiseOrValue::Value(amount) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be 0
given that we are locking all those tokens on this contract?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, should be 0
Is payable actually requires that at least 1 yN gets attached?
There is a pure storage registration function already in the token, but it's more of a question if user or relayer needs to call it or can just call mint once. |
The 10x growth is really weird - that means there is something that should
be no be compiled in there.
Did you try to rebuild wasm file?
Also it's weird that cost on testnet is still 10e20, it should be 10e19 now.
…On Fri, Mar 5, 2021 at 4:17 AM Marcelo Fornet ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In bridge-token-factory/src/lib.rs
<#39 (comment)>
:
> @@ -31,8 +27,6 @@ const BRIDGE_TOKEN_NEW: Gas = 10_000_000_000_000;
/// Initial balance for the BridgeToken contract to cover storage and related.
const BRIDGE_TOKEN_INIT_BALANCE: Balance = 30_000_000_000_000_000_000_000_000; // 3e25yN, 30N
According to my experiment calculations it should be increased 🤔
cost per byte on testnet is: 100000000000000000000 (is the cost already
decreased in testnet?)
contract size in bytes is: 3769047 (Notice that it is growing in this PR
from 481014 to 3769047 almost 10x)
BRIDGE_TOKEN_INIT_BALANCE = 30000000000000000000000000
MINIMUM_EXPECTED = 376904700000000000000000000
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#39 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABK27V7F5I6Z37DBS5YUU3TCDDUBANCNFSM4YTKHVAQ>
.
--
Best regards,
Illia Polosukhin
|
Cost is reduced by 10x:
```
$ near state dev-1614947681178-6795333 7.3s Fri
Mar 5 04:36:19 2021
Account dev-1614947681178-6795333
{
amount: '9999561724097628400000000',
locked: '0',
code_hash: 'G9KxxEMn6woPq7npJVCbf2s976ptXm6dnH3AMDqVCzCR',
storage_usage: 246824,
storage_paid_at: 0,
block_height: 38933125,
block_hash: 'FHTUCmdKLXS9Zf3dGPtV6wk2Vk17MchwfX5ZjEJX1xrz',
formattedAmount: '9.9995617240976284'
}
```
Here, 9N is enough to cover 246kb.
On Fri, Mar 5, 2021 at 4:20 AM Illia Polosukhin <[email protected]>
wrote:
… The 10x growth is really weird - that means there is something that should
be no be compiled in there.
Did you try to rebuild wasm file?
Also it's weird that cost on testnet is still 10e20, it should be 10e19
now.
On Fri, Mar 5, 2021 at 4:17 AM Marcelo Fornet ***@***.***>
wrote:
> ***@***.**** commented on this pull request.
> ------------------------------
>
> In bridge-token-factory/src/lib.rs
> <#39 (comment)>
> :
>
> > @@ -31,8 +27,6 @@ const BRIDGE_TOKEN_NEW: Gas = 10_000_000_000_000;
>
> /// Initial balance for the BridgeToken contract to cover storage and related.
>
> const BRIDGE_TOKEN_INIT_BALANCE: Balance = 30_000_000_000_000_000_000_000_000; // 3e25yN, 30N
>
>
> According to my experiment calculations it should be increased 🤔
>
> cost per byte on testnet is: 100000000000000000000 (is the cost already
> decreased in testnet?)
> contract size in bytes is: 3769047 (Notice that it is growing in this PR
> from 481014 to 3769047 almost 10x)
>
> BRIDGE_TOKEN_INIT_BALANCE = 30000000000000000000000000
>
> MINIMUM_EXPECTED = 376904700000000000000000000
>
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#39 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AABK27V7F5I6Z37DBS5YUU3TCDDUBANCNFSM4YTKHVAQ>
> .
>
--
Best regards,
Illia Polosukhin
--
Best regards,
Illia Polosukhin
|
@ilblackdragon what contract did you deployed, because in this repository I got this:
This contract is |
Have you rebuilt it?
The one checked in this repo has link symbols and wasn't compiled with all
the flags because I was compiling for testing purposes.
…On Fri, Mar 5, 2021 at 5:16 AM Marcelo Fornet ***@***.***> wrote:
@ilblackdragon <https://github.com/ilblackdragon> what contract did you
deployed, because in this repository I got this:
❯ ls -l res/bridge_token_factory.wasm
-rwxr-xr-x 1 marcelo staff 3769047 Mar 5 14:14 res/bridge_token_factory.wasm
This contract is 3769047 bytes long.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#39 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABK27TFUQG2JDX3M24PTZDTCDKRNANCNFSM4YTKHVAQ>
.
--
Best regards,
Illia Polosukhin
|
Please update to the new interface of Storage Manger: https://github.com/near/near-sdk-rs/blob/master/near-contract-standards/src/storage_manager/mod.rs @mikedotexe, the current version of the vanilla token implementation still uses AR instead of a storage manger. Is this something that is going to continue? We need the interface for the storage interaction for CC: @mfornet |
Closes #21 |
This is much more complicated problem due to the fact of async execution of the contracts, as was mentioned by @abacabadabacaba. Scenario when the asserts are not working :
As a result, the proof was consumed, while the transfer was not finished. Recording the proof consumption after the minting function execution is not working, since then one proof can be used multiple times. One of the possible option is to add a rollback procedure for the proof recordings. In this case the proof should be forwarded to |
@djsatok my understanding from how the runtime works, is that if a promise fails, the full transaction is reverted, so the call to
Bridge factory doesn't check this, this is checked on the BridgeToken once the |
After reading this SO answer I see the whole transaction is not reverted. One possible solution is to record the proof on the |
Discussed the above mentioned issue with reverting the Perhaps in future we should implement the reverting mechanism, though it would still have some places to shoot in a leg, like attaching enough gas to pay for the reverting receipt. |
Compile contracts
Shouldn't we call |
Disregard previous comment, I read attached deposit instead of attached gas. |
The drawback of the second approach, is that right now we currently don't require the recipient to even exist, and that won't be the case anymore. |
Why not just call |
Also, I see that this PR removes |
@@ -11,7 +11,7 @@ docker run \ | |||
-w /host/bridge-token-factory \ | |||
-e RUSTFLAGS='-C link-arg=-s' \ | |||
nearprotocol/contract-builder \ | |||
cargo +stable build --target wasm32-unknown-unknown --release | |||
/bin/bash -c "rustup target add wasm32-unknown-unknown; cargo build --target wasm32-unknown-unknown --release" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wasm32-unknown-unknown
is not installed in the current docker image for the latest toolchain. Notice it haven't been updated for 8 months. The Dockerfile is correct but we need to publish the new image. Filed issue at near/near-sdk-rs#310
The error I'm getting right now:
Compiling bridge-token-factory v0.1.0 (/host/bridge-token-factory)
error[E0463]: can't find crate for `std`
|
= note: the `wasm32-unknown-unknown` target may not be installed
error: aborting due to previous error
For more information about this error, try `rustc --explain E0463`.
error: could not compile `bridge-token-factory`.
|
||
const NO_DEPOSIT: Balance = 0; | ||
|
||
#[near_bindgen] | ||
#[derive(BorshDeserialize, BorshSerialize)] | ||
#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add PanicOnDefault
to BridgeTokenFactory
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done: 48eeea8
bridge-token/src/lib.rs
Outdated
decimals: Option<u8>, | ||
) { | ||
// Only owner can change the metadata | ||
assert_eq!(env::current_account_id(), env::signer_account_id()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't using signer_account_id
have the same problems as using tx.origin
in Solidity? Please change to predecessor_account_id
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solved in 7482c5d
Moreover same issue existed with current implementation of AdminControlled
which is fixed here: Near-One/rainbow-bridge#524. It is already fixed, and added PR to use respective version: dbc227b
bridge-token/src/lib.rs
Outdated
recipient, | ||
&self.controller, | ||
NO_DEPOSIT, | ||
env::prepaid_gas() / 2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may run out of gas, in which case the tokens will be destroyed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done d0b92af
Together with fixed gas to schedule finish_withdraw
/ finish_deposit
/ mint
) | ||
}; | ||
} | ||
|
||
#[test] | ||
fn test_eth_token_transfer() { | ||
let (user, factory) = setup_token_factory(); | ||
let root = "root".to_string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable is redundant and is not used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solved in 3bd8556
This prevent loosing funds, by calling finish_withdraw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Implements basics of FT-141.
Sim tests are still not finished and everything should be looked over again to see if there are better flows (like react on receiving to
factory_id
for withdrawing tokens)