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

Adding an option for apps to 'forecall' callContractWithToken to hasten resolution of calls. #102

Merged
merged 26 commits into from
Jun 7, 2022

Conversation

Foivos
Copy link
Contributor

@Foivos Foivos commented May 24, 2022

Add a different version of the executable that can have executeWithToken front-run by the application (and have the tokens provided to it) to hasten execution.

@Foivos Foivos changed the title Feat/fortell feat/fortell May 25, 2022
@Foivos Foivos changed the title feat/fortell Adding an option for apps to 'fortell' callContractWithToken to hasten resolution of calls. May 25, 2022
@fish-sammy
Copy link
Contributor

I need more information about what is this PR doing and what are we trying to achieve before I can review it.

test/Util.js Outdated

const UtilTest = require('../build/UtilTest.json');

const { it } = require('mocha');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const { it } = require('mocha');

import { IAxelarGateway } from './IAxelarGateway.sol';
import { IERC20 } from './IERC20.sol';

abstract contract IAxelarExecutableForetellable {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
abstract contract IAxelarExecutableForetellable {
abstract contract AxelarExecutableForetellable {

I is for interface and this isn't but an abstract contract.

Copy link
Contributor

Choose a reason for hiding this comment

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

@sammy1991106 we already used that pattern for the IAxelarExecutable. It has some logic in it and also is an abstract contract. Do you think it's worth renaming it? Also should it be moved out of interfaces folder?

Copy link
Contributor

Choose a reason for hiding this comment

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

ok nvm then if it's already done elsewhere.

error NotAuthorizedToForetell();

IAxelarGateway public gateway;
mapping(string => mapping(string => mapping(bytes => mapping(string => mapping(uint256 => address)))))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
mapping(string => mapping(string => mapping(bytes => mapping(string => mapping(uint256 => address)))))
mapping(bytes32 => address) public foretellers;

and key becomes keccak256(sourceChain, sourceAddress, payload, tokenSymbol, amount). Fewer hashing happening and therefore cheaper gas cost, no?

string memory tokenSymbolA,
uint256 amount
) internal override {
(string memory tokenSymbolB, string memory recipient) = abi.decode(payload, (string, string));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
(string memory tokenSymbolB, string memory recipient) = abi.decode(payload, (string, string));
(bytes32 nonce, string memory tokenSymbolB, string memory recipient) = abi.decode(payload, (string, string));

Without a nonce, only one of the multiple swapping attempts with the exact same parameters can be foretold until executed.

_execute(sourceChain, sourceAddress, payload);
}

function foretell(
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see why foretell can only work with executeWithToken but not execute?

@re1ro
Copy link
Contributor

re1ro commented Jun 6, 2022

Please rebase your branch onto the latest main 💯

} else {
_execute(sourceChain, sourceAddress, payload);
}
_execute(sourceChain, sourceAddress, payload);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this _execute duplicated here?


abstract contract IAxelarExecutableForetellable {
error NotApprovedByGateway();
error AlreadyFortold();
Copy link
Contributor

Choose a reason for hiding this comment

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

Foretold 😸 ?

address foreteller
) external {
address token = gateway.tokenAddresses(tokenSymbol);
IERC20(token).transferFrom(msg.sender, address(this), amount);
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to use safe transfer here
Example

if (foreteller != address(0)) {
foretellers[keccak256(abi.encode(sourceChain, sourceAddress, payload, tokenSymbol, amount))] = address(0);
address token = gateway.tokenAddresses(tokenSymbol);
IERC20(token).transfer(foreteller, amount);
Copy link
Contributor

Choose a reason for hiding this comment

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

@re1ro re1ro changed the title Adding an option for apps to 'fortell' callContractWithToken to hasten resolution of calls. Adding an option for apps to 'forecall' callContractWithToken to hasten resolution of calls. Jun 7, 2022
@re1ro re1ro dismissed fish-sammy’s stale review June 7, 2022 19:29

The feedback was addressed

@re1ro re1ro merged commit e30c983 into main Jun 7, 2022
@re1ro re1ro deleted the feat/fortell branch June 7, 2022 19:29
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.

3 participants