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

Snip 9 - Outside Execution #1202

Merged
merged 3 commits into from
Aug 26, 2024
Merged

Snip 9 - Outside Execution #1202

merged 3 commits into from
Aug 26, 2024

Conversation

PhilippeR26
Copy link
Collaborator

Motivation and Resolution

Solves issue #948 and replace stuck PR #1111 .
Implantation of the concept of execution of a transaction signed by an other account, standardized in SNIP-9.

Usage related changes

Most usages are explained in a dedicated guide, and detailed usage is explained in JSDoc.
2 main functions :
Creation of an outside transaction object with Account.getOutsideTransaction()

const call1: Call = {
  contractAddress: erc20Address,
  entrypoint: 'transfer',
  calldata: {
    recipient: recipientAddress,
    amount: cairo.uint256(3n * 10n ** 16n),
  },
};

const callOptions: OutsideExecutionOptions = {
  caller: executorAccount.address,
  execute_after: Math.floor(Date.now() / 1000) - 3600, // 1 hour ago
  execute_before: Math.floor(Date.now() / 1000) + 3600, // 1 hour from now
};

const outsideTransaction1: OutsideTransaction = await signerAccount.getOutsideTransaction(
  callOptions,
  call1
);

call1 can be an array of Call.

Execution from an other account with Account.executeFromOutside()

const response = await executorAccount.executeFromOutside(outsideTransaction1);
await provider.waitForTransaction(response.transaction_hash);

outsideTransaction1 can be an array of OutsideTransaction

Development related changes

  • The Account interface has not been modified, to not impact the users of this interface(ArgentX, Braavos, ...).
  • Due to excessive duration, tests are only using a SNIP-9 V2 account. Nevertheless separated tests have been performed with all cases (V1, V2, ERC165 compatible but SNIP-9 unsupported, no ERC165 support), and with mix of possibilities (multi OutsideTransaction including multicall, with several signer accounts (using several SNIP-9 versions).

NOTE
I don't know what is the current policy about enums, but an enum has been created in :
https://github.com/PhilippeR26/starknet.js/blob/b85379d05f8eb44a6cc49b583e1b6e406428ba0f/src/types/outsideExecution.ts#L77C1-L81C2

Checklist:

  • Performed a self-review of the code
  • Rebased to the last commit of the target branch (or merged it into my branch)
  • Linked the issues which this PR resolves
  • Documented the changes in code (API docs will be generated automatically)
  • Updated the tests
  • All tests are passing

Copy link
Collaborator

@ivpavici ivpavici left a comment

Choose a reason for hiding this comment

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

mostly some grammar stuff and couple of questions from my side!

__tests__/account.outsideExecution.test.ts Outdated Show resolved Hide resolved
src/utils/src5.ts Show resolved Hide resolved
src/types/outsideExecution.ts Outdated Show resolved Hide resolved
www/docs/guides/outsideExecution.md Outdated Show resolved Hide resolved
www/docs/guides/outsideExecution.md Outdated Show resolved Hide resolved
src/utils/outsideExecution.ts Outdated Show resolved Hide resolved
src/utils/outsideExecution.ts Outdated Show resolved Hide resolved
src/utils/outsideExecution.ts Outdated Show resolved Hide resolved
src/account/default.ts Outdated Show resolved Hide resolved
src/account/default.ts Outdated Show resolved Hide resolved
@ivpavici ivpavici requested a review from penovicp August 19, 2024 12:40
@penovicp penovicp changed the base branch from develop to snip-9 August 26, 2024 06:58
Copy link
Collaborator

@penovicp penovicp left a comment

Choose a reason for hiding this comment

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

lgtm

Note: I did a restructuring and rebase to PR #1111 so Konstantin can also be tracked by GitHub as a contributor.

src/utils/src5.ts Show resolved Hide resolved
src/utils/src5.ts Show resolved Hide resolved
[call1],
OutsideExecutionVersion.V2
);
expect(message).toEqual({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't change anything now but just wanted to mention that in the future when dealing with large objects as the expected result of tests using snapshots might be simpler.

@penovicp penovicp mentioned this pull request Aug 26, 2024
@ivpavici ivpavici merged commit edeade8 into starknet-io:snip-9 Aug 26, 2024
penovicp added a commit that referenced this pull request Aug 27, 2024
* feat: draft SNIP-9 implementation  (#1111)

* feat: finalize SNIP-9 outside execution implementation (#1202)

---------

Co-authored-by: Konstantin Fastov <[email protected]>
Co-authored-by: Philippe ROSTAN <[email protected]>
github-actions bot pushed a commit that referenced this pull request Aug 27, 2024
# [6.13.0](v6.12.1...v6.13.0) (2024-08-27)

### Bug Fixes

* repair enum type lookup for typed data hashing ([36f8c3c](36f8c3c))
* sync cryptographic dependencies ([da20310](da20310))

### Features

* implement SNIP-9 outside execution functionality ([#1208](#1208)) ([e3c80c5](e3c80c5)), closes [#1111](#1111) [#1202](#1202)
* improve message verification utilities ([#1198](#1198)) ([bdad9a5](bdad9a5))
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