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

improve explanations of parameters for execute Relay Call guide #662

Merged
merged 4 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 77 additions & 28 deletions docs/guides/key-manager/execute-relay-transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ import KeyManagerContract from '@lukso/lsp-smart-contracts/artifacts/LSP6KeyMana
import { EIP191Signer } from '@lukso/eip191-signer.js';
import Web3 from 'web3';

// This is the version relative to the LSP6 standard, defined as the number 6.
import { LSP6_VERSION } from '@lukso/lsp-smart-contracts/constants';
// This is the version relative to the LSP25 standard, defined as the number 25.
import { LSP25_VERSION } from '@lukso/lsp-smart-contracts/constants';

const web3 = new Web3('https://rpc.testnet.lukso.network');
const universalProfileAddress = '0x...';
const msgValue = 0; // Amount of native tokens to be sent
const recipientAddress = '0x...';

// setup the Universal Profile controller account
Expand All @@ -89,14 +88,13 @@ import KeyManagerContract from '@lukso/lsp-smart-contracts/artifacts/LSP6KeyMana
import { EIP191Signer } from '@lukso/eip191-signer.js';
import { ethers } from 'ethers';

// This is the version relative to the LSP6 standard, defined as the number 6.
import { LSP6_VERSION } from '@lukso/lsp-smart-contracts/constants';
// This is the version relative to the LSP25 standard, defined as the number 25.
import { LSP25_VERSION } from '@lukso/lsp-smart-contracts/constants';

const provider = new ethers.providers.JsonRpcProvider(
'https://rpc.testnet.lukso.network',
);
const universalProfileAddress = '0x...';
const msgValue = 0; // Amount of native tokens to be sent
const recipientAddress = '0x...';

// setup the Universal Profile controller account
Expand Down Expand Up @@ -189,12 +187,13 @@ const channelId = 0;
const nonce = await keyManager.methods.getNonce(controllerAccount.address, channelId).call();

const validityTimestamps = 0; // no validity timestamp set
const msgValue = 0; // Amount of native tokens to fund the UP with while calling

const abiPayload = universalProfile.methods
.execute(
0, // Operation type: CALL
recipientAddress,
msgValue,
web3.utils.toWei(3), // transfer 3 LYX to recipient
'0x', // Data
)
.encodeABI();
Expand All @@ -211,11 +210,12 @@ const channelId = 0;
const nonce = await keyManager.getNonce(controllerAccount.address, channelId);

const validityTimestamps = 0; // no validity timestamp set
const msgValue = 0; // Amount of native tokens to fund the UP with while calling

const abiPayload = universalProfile.interface.encodeFunctionData('execute', [
0, // Operation type: CALL
recipientAddress,
msgValue,
ethers.utils.parseEther('3'), // transfer 3 LYX to recipient
'0x', // Data
]);
```
Expand Down Expand Up @@ -249,13 +249,22 @@ For more information check: [**How to sign relay transactions?**](../../standard
```typescript title="Sign the transaction"
const chainId = await web3.eth.getChainId();

// prettier-ignore
let encodedMessage = web3.utils.encodePacked(
{ value: LSP6_VERSION, type: 'uint256' },
{ value: chainId, type: 'uint256' },
{ value: nonce, type: 'uint256' },
{ value: validityTimestamps, type: 'uint256' },
{ value: msgValue, type: 'uint256' },
{ value: abiPayload, type: 'bytes' },
// MUST be number `25`
{ value: LSP25_VERSION, type: 'uint256' }, // `0x0000000000000000000000000000000000000000000000000000000000000019`
// e.g: `4201` for LUKSO Testnet
{ value: chainId, type: 'uint256' }, // `0x0000000000000000000000000000000000000000000000000000000000001069`
// e.g: nonce nb 5
CJ42 marked this conversation as resolved.
Show resolved Hide resolved
{ value: nonce, type: 'uint256' }, // `0x0000000000000000000000000000000000000000000000000000000000000005`
// e.g: valid until 1st January 2025 at midnight (GMT).
// Timestamp = 1735689600
CJ42 marked this conversation as resolved.
Show resolved Hide resolved
{ value: validityTimestamps, type: 'uint256' }, // `0x0000000000000000000000000000000000000000000000000000000067748580`
// e.g: not funding the contract with any LYX (0)
{ value: msgValue, type: 'uint256' }, // `0x0000000000000000000000000000000000000000000000000000000000000000`
// e.g: execute(uint256,address,uint256,bytes)
// send 3 LYX to address `0xcafecafecafecafeafecafecafecafeafecafecafecafeafecafecafecafe`
{ value: abiPayload, type: 'bytes' }, // `0x44c028fe0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cafecafecafecafecafecafecafecafecafecafe00000000000000000000000000000000000000000000000029a2241af62c000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000`
);

let eip191Signer = new EIP191Signer();
Expand All @@ -274,9 +283,24 @@ let { signature } = await eip191Signer.signDataWithIntendedValidator(
```typescript title="Sign the transaction"
const { chainId } = await provider.getNetwork();

// prettier-ignore
let encodedMessage = ethers.utils.solidityPack(
['uint256', 'uint256', 'uint256', 'uint256', 'uint256', 'bytes'],
[LSP6_VERSION, chainId, nonce, validityTimestamps, msgValue, abiPayload],
[
// MUST be number `25`
LSP25_VERSION, // `0x0000000000000000000000000000000000000000000000000000000000000019`
// e.g: `4201` for LUKSO Testnet
chainId, // `0x0000000000000000000000000000000000000000000000000000000000001069`
// e.g: nonce nb 5
nonce, // `0x0000000000000000000000000000000000000000000000000000000000000005`
// e.g: valid until 1st January 2025 at midnight (GMT).
// Timestamp = 1735689600
validityTimestamps, // `0x0000000000000000000000000000000000000000000000000000000067748580`
// e.g: not funding the contract with any LYX (0)
msgValue, // `0x0000000000000000000000000000000000000000000000000000000000000000`
// e.g: execute(uint256,address,uint256,bytes) -> send 3 LYX to address `0xcafecafecafecafeafecafecafecafeafecafecafecafeafecafecafecafe`
abiPayload, // `0x44c028fe0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cafecafecafecafecafecafecafecafecafecafe00000000000000000000000000000000000000000000000029a2241af62c000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000`
],
);

let eip191Signer = new EIP191Signer();
Expand Down Expand Up @@ -367,12 +391,11 @@ import KeyManagerContract from '@lukso/lsp-smart-contracts/artifacts/LSP6KeyMana
import { EIP191Signer } from '@lukso/eip191-signer.js';
import Web3 from 'web3';

// This is the version relative to the LSP6 standard, defined as the number 6.
import { LSP6_VERSION } from '@lukso/lsp-smart-contracts/constants';
// This is the version relative to the LSP25 standard, defined as the number 25.
import { LSP25_VERSION } from '@lukso/lsp-smart-contracts/constants';

const web3 = new Web3('https://rpc.testnet.lukso.network');
const universalProfileAddress = '0x...';
const msgValue = 0; // Amount of native tokens to be sent
const recipientAddress = '0x...';

// setup the Universal Profile controller account
Expand All @@ -396,25 +419,36 @@ const nonce = await keyManager.methods
.call();

const validityTimestamps = 0; // no validity timestamp set
const msgValue = 0; // Amount of native tokens to fund the UP with while calling

// send 3 LYX to recipient
const abiPayload = universalProfile.methods
.execute(
0, // Operation type: CALL
recipientAddress,
msgValue,
web3.utils.toWei(3), // transfer 3 LYX to recipient
'0x', // Data
)
.encodeABI();

const chainId = await web3.eth.getChainId();

// prettier-ignore
let encodedMessage = web3.utils.encodePacked(
{ value: LSP6_VERSION, type: 'uint256' },
{ value: chainId, type: 'uint256' },
{ value: nonce, type: 'uint256' },
{ value: validityTimestamps, type: 'uint256' },
{ value: msgValue, type: 'uint256' },
{ value: abiPayload, type: 'bytes' },
// MUST be number `25`
{ value: LSP25_VERSION, type: 'uint256' }, // `0x0000000000000000000000000000000000000000000000000000000000000019`
// e.g: `4201` for LUKSO Testnet
{ value: chainId, type: 'uint256' }, // `0x0000000000000000000000000000000000000000000000000000000000001069`
// e.g: nonce nb 5
{ value: nonce, type: 'uint256' }, // `0x0000000000000000000000000000000000000000000000000000000000000005`
// e.g: valid until 1st January 2025 at midnight (GMT).
// Timestamp = 1735689600
{ value: validityTimestamps, type: 'uint256' }, // `0x0000000000000000000000000000000000000000000000000000000067748580`
// e.g: not funding the contract with any LYX (0)
{ value: msgValue, type: 'uint256' }, // `0x0000000000000000000000000000000000000000000000000000000000000000`
// e.g: execute(uint256,address,uint256,bytes)
// send 3 LYX to address `0xcafecafecafecafeafecafecafecafeafecafecafecafeafecafecafecafe`
{ value: abiPayload, type: 'bytes' }, // `0x44c028fe0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cafecafecafecafecafecafecafecafecafecafe00000000000000000000000000000000000000000000000029a2241af62c000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000`
);

let eip191Signer = new EIP191Signer();
Expand Down Expand Up @@ -443,8 +477,8 @@ import KeyManagerContract from '@lukso/lsp-smart-contracts/artifacts/LSP6KeyMana
import { EIP191Signer } from '@lukso/eip191-signer.js';
import { ethers } from 'ethers';

// This is the version relative to the LSP6 standard, defined as the number 6.
import { LSP6_VERSION } from '@lukso/lsp-smart-contracts/constants';
// This is the version relative to the LSP25 standard, defined as the number 25.
import { LSP25_VERSION } from '@lukso/lsp-smart-contracts/constants';

const provider = new ethers.providers.JsonRpcProvider(
'https://rpc.testnet.lukso.network',
Expand Down Expand Up @@ -486,9 +520,24 @@ const abiPayload = universalProfile.interface.encodeFunctionData('execute', [

const { chainId } = await provider.getNetwork();

// prettier-ignore
let encodedMessage = ethers.utils.solidityPack(
['uint256', 'uint256', 'uint256', 'uint256', 'uint256', 'bytes'],
[LSP6_VERSION, chainId, nonce, validityTimestamps, msgValue, abiPayload],
[
// MUST be number `25`
LSP25_VERSION, // `0x0000000000000000000000000000000000000000000000000000000000000019`
// e.g: `4201` for LUKSO Testnet
chainId, // `0x0000000000000000000000000000000000000000000000000000000000001069`
// e.g: nonce nb 5
nonce, // `0x0000000000000000000000000000000000000000000000000000000000000005`
// e.g: valid until 1st January 2025 at midnight (GMT).
// Timestamp = 1735689600
validityTimestamps, // `0x0000000000000000000000000000000000000000000000000000000067748580`
// e.g: not funding the contract with any LYX (0)
msgValue, // `0x0000000000000000000000000000000000000000000000000000000000000000`
// e.g: execute(uint256,address,uint256,bytes) -> send 3 LYX to address `0xcafecafecafecafeafecafecafecafeafecafecafecafeafecafecafecafe`
abiPayload, // `0x44c028fe0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cafecafecafecafecafecafecafecafecafecafe00000000000000000000000000000000000000000000000029a2241af62c000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000`
],
);

let eip191Signer = new EIP191Signer();
Expand Down
8 changes: 4 additions & 4 deletions docs/standards/universal-profile/lsp6-key-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -851,8 +851,8 @@ To obtain a valid signature that can be used by anyone to execute a relayed tran
- 1. the **payload** (an abi-encoded function call) to be executed on the linked account.
- 2. the **chain id** of the blockchain where the `payload` will be executed.
- 3. the address of the [`LSP6KeyManager`](../../contracts/contracts/LSP6KeyManager/LSP6KeyManager.md) smart contract where the **payload** will be executed.
d. the Key Manager **nonce** of the controller.
- 4. the `validityTimestamps`, composed of 2 x `uint128` concatenated together, where:
- 4. the Key Manager **nonce** of the controller.
- 5. the `validityTimestamps`, composed of 2 x `uint128` concatenated together, where:

4.1. the left-side `uint128` corresponds to the timestamp from which the relay call is valid from.

Expand All @@ -869,15 +869,15 @@ To obtain a valid signature that can be used by anyone to execute a relayed tran
The relay transactions are signed using the [**version 0 of EIP191**](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-191.md#version-0x00). The relay call data that you want to sign **MUST** be the _keccak256 hash digest_ of the following elements _(bytes values)_ concatenated together.

```javascript
0x19 <0x00> <KeyManager address> <LSP6_VERSION> <chainId> <nonce> <validityTimestamps> <value> <payload>
0x19 <0x00> <KeyManager address> <LSP25_VERSION> <chainId> <nonce> <validityTimestamps> <value> <payload>
```

| Message elements | Details |
| :------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `0x19` | Byte used to ensure that the _relay call signed data_ is not a valid RLP. |
| `0x00` | The [**version 0 of EIP191**](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-191.md#version-0x00). |
| `KeyManager address` | The address of the Key Manager that will execute the relay call. |
| `LSP6_VERSION` | The version of the Key Manager that will execute the relay call, as a `uint256`. (Current version of LSP6 Key Manager is **6**) |
| `LSP25_VERSION` | The `uint256` number **25** that defines the current version of the LSP25 Execute Relay Call standard. |
| `chainId` | The chain id of the blockchain where the Key Manager is deployed, as `uint256`. |
| `nonce` | The unique [**nonce**](https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-6-KeyManager.md#getnonce) for the payload. |
| `validityTimestamps` | Two `uint128` timestamps concatenated, the first timestamp determines from when the payload can be executed, the second timestamp delimits the end of the validity of the payload. If `validityTimestamps` is 0, the checks of the timestamps are skipped |
Expand Down