Skip to content
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

feat: mirroring erc-20 contracts #845

Merged
merged 7 commits into from
Oct 11, 2023

Conversation

aleksuss
Copy link
Member

@aleksuss aleksuss commented Oct 4, 2023

Description

The PR adds a possibility to mirror previously deployed ERC-20 contracts on the main Aurora contract. The transaction mirror_erc20_token is allowed in the Silo mode only.

mirror_erc20_token accepts parameters serialised with borsh.
get(set)_erc20_metadata accepts parameters serialised with JSON.

Performance / NEAR gas cost considerations

There are no changes in the performance/gas consumption.

Testing

The corresponding test has been added.

engine/src/contract_methods/connector/mod.rs Outdated Show resolved Hide resolved
engine-types/src/parameters/connector.rs Outdated Show resolved Hide resolved

Ok(result)
})
}

pub fn get_erc20_metadata<I: IO + Copy, E: Env>(mut io: I, env: &E) -> Result<(), ContractError> {
let erc20_address = io.read_input_arr20().map(Address::from_array)?;
let erc20_identifier =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically it is a breaking change, but I think it's okay because we haven't deployed this function yet.

@karim-en
Copy link
Contributor

karim-en commented Oct 9, 2023

@aleksuss Could you please add the details about the added public methods/api with its arguments (json/borsh) in the PR description?

Copy link
Member

@birchmd birchmd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

unsafe fn promise_create_and_combine(&mut self, args: &[PromiseCreateArgs]) -> PromiseId {
args.iter()
.map(|arg| self.promise_create_call(arg))
.last()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation does not have the right semantics. I think the correct implementation would look something like

let id = self.take_id();
self.scheduled_promises.insert(
    id,
    PromiseArgs::Recursive(
        NearPromise::And(
            args.iter().map(|p| NearPromise::Simple(SimpleNearPromise::Create(p.clone()))).collect()
        )
    )
);
PromiseId::new(id)

.try_to_vec()
.map_err(|_| crate::errors::ERR_SERIALIZE)?,
attached_balance: Yocto::new(0),
attached_gas: NearGas::new(5_000_000_000_000),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably makes sense to factor out the gas values as named constants (here and in the other promise).

attached_balance: Yocto::new(0),
attached_gas: NearGas::new(5_000_000_000_000),
};
let promise_id = unsafe {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put a short comment here about the safety of this call. Something along the lines of "these promises are read-only calls to the main engine and this code is only reachable if the transaction is executed by a privileged account".

@aleksuss aleksuss merged commit 27da909 into feat/aleksuss/silo Oct 11, 2023
19 checks passed
@aleksuss aleksuss deleted the feat/aleksuss/erc20_mirroring branch October 11, 2023 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants