Skip to content

Commit

Permalink
feat(smart-wallet): TxRelayInfo - add smartWalletAddress, add tenderl…
Browse files Browse the repository at this point in the history
…y link
  • Loading branch information
shrpne committed Mar 1, 2023
1 parent 7a6465f commit bc0335a
Show file tree
Hide file tree
Showing 7 changed files with 19,759 additions and 25,361 deletions.
1 change: 1 addition & 0 deletions assets/abi-smartwallet-bin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const HUB_MINTER_MULTISIG_ADDRESS = process.env.APP_HUB_MINTER_MULTISIG_A
export const SMART_WALLET_RELAY_MINTER_ADDRESS = "Mxc9b1b39f4c94b1bcbf68c1beba97ab84f7763cf0";
export const SMART_WALLET_FACTORY_CONTRACT_ADDRESS = "0x324718b3cE9906fcf5cE140342146Eb16970d889";
export const SMART_WALLET_FACTORY_LEGACY_BSC_CONTRACT_ADDRESS = "0x7F3C8d5363B44875001Fa2A63A7dB6FCb8BEE989";
export const SMART_WALLET_RELAY_BROADCASTER_ADDRESS = '0x64e51D5930CDBbf99f3cB27654A03b18f7060C5E';
export const SMART_WALLET_RELAY_API_URL = process.env.APP_HUB_API_URL + 'smart-wallet-relay/';
export const HUB_API_URL = process.env.APP_HUB_API_URL;
export const FARM_API_URL = process.env.APP_FARM_API_URL;
Expand Down
49 changes: 47 additions & 2 deletions components/TxRelayInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@ import web3Utils from 'web3-utils';
import web3Abi from 'web3-eth-abi';
import {getRelayTxStatus, SMART_WALLET_RELAY_TX_STATUS} from '~/api/smart-wallet-relay.js';
import {prettyExact, shortHashFilter, getEvmTxUrl, getEvmAddressUrl, getEvmBlockUrl} from "~/assets/utils.js";
import {SMART_WALLET_RELAY_MINTER_ADDRESS, SMART_WALLET_FACTORY_CONTRACT_ADDRESS, SMART_WALLET_FACTORY_LEGACY_BSC_CONTRACT_ADDRESS, HUB_CHAIN_DATA} from "~/assets/variables.js";
import {
SMART_WALLET_RELAY_MINTER_ADDRESS,
SMART_WALLET_FACTORY_CONTRACT_ADDRESS,
SMART_WALLET_FACTORY_LEGACY_BSC_CONTRACT_ADDRESS,
SMART_WALLET_RELAY_BROADCASTER_ADDRESS,
HUB_CHAIN_DATA,
HUB_NETWORK_SLUG,
} from "~/assets/variables.js";
import smartWalletABI from '~/assets/abi-smartwallet.js';
import smartWalletFactoryABI from '~/assets/abi-smartwallet-factory.js';
import smartWalletFactoryABILegacy from '~/assets/abi-smartwallet-factory-legacy.js';
import {getSmartWalletAddress} from '~/composables/use-web3-smartwallet.js';
export default {
SMART_WALLET_RELAY_TX_STATUS,
SMART_WALLET_RELAY_BROADCASTER_ADDRESS,
props: {
tx: {
type: Object,
Expand Down Expand Up @@ -81,6 +90,14 @@ export default {
return '';
}
},
smartWalletAddress() {
if (this.callDestination === SMART_WALLET_FACTORY_CONTRACT_ADDRESS && this.callPayloadDecoded?._owner && this.callPayloadDecoded?._nonce) {
return getSmartWalletAddress(this.callPayloadDecoded._owner, {
walletIndex: this.callPayloadDecoded._nonce,
});
}
return '';
},
txList() {
return this.callPayloadDecoded._logicContractAddress.map((to, index) => {
return {
Expand All @@ -105,7 +122,9 @@ export default {
const networkName = this.payloadParsed.type.replace('send_to_', '');
return HUB_CHAIN_DATA[networkName];
},
tenderlyNetworkSlug() {
return this.hubNetworkData?.hubNetworkSlug === HUB_NETWORK_SLUG.ETHEREUM ? 'mainnet' : this.hubNetworkData?.hubNetworkSlug;
},
},
methods: {
prettyExact,
Expand Down Expand Up @@ -169,6 +188,16 @@ export default {
Owner:
<a class="link--default" :href="getAddressUrl(callPayloadDecoded._owner)" target="_blank">{{ callPayloadDecoded._owner }}</a>
</template>
<template v-if="callPayloadDecoded._nonce">
<br>
Smart-wallet index:
{{ callPayloadDecoded._nonce }}
</template>
<template v-if="smartWalletAddress">
<br>
Smart-wallet:
<a class="link--default" :href="getAddressUrl(smartWalletAddress)" target="_blank">{{ smartWalletAddress }}</a>
</template>
<br>
Timeout block:
Expand Down Expand Up @@ -207,6 +236,22 @@ export default {
<br><br>
Base64:
{{ relayTxParams.d }}
<br><br>
<a
class="link--default" target="_blank"
v-if="relayTxStatus?.txHash"
:href="`https://dashboard.tenderly.co/tx/${tenderlyNetworkSlug}/${relayTxStatus?.txHash}`"
>
Tenderly inspect
</a>
<a
class="link--default" target="_blank"
v-else
:href="`https://dashboard.tenderly.co/simulator/new?contractAddress=${callDestination}&rawFunctionInput=${callPayload}&block=${callPayloadDecoded._timeout - 10}&from=${$options.SMART_WALLET_RELAY_BROADCASTER_ADDRESS}&gas=${gasLimit}&gasPrice=${relayTxParams.gp}&value=0&network=${hubNetworkData?.chainId}`"
>
Tenderly simulate
</a>
</details>
</template>
</dd>
Expand Down
56 changes: 56 additions & 0 deletions composables/use-web3-smartwallet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import web3Utils from 'web3-utils';
import web3Abi from 'web3-eth-abi';
import smartWalletBin from '~/assets/abi-smartwallet-bin.js';
import {SMART_WALLET_FACTORY_CONTRACT_ADDRESS, SMART_WALLET_FACTORY_LEGACY_BSC_CONTRACT_ADDRESS} from '~/assets/variables.js';




// index to derive wallet
const SMART_WALLET_INDEX = 0;

/**
* @pure
* @nosideeffects
* @param {string} evmAccountAddress
* @param {object} [options]
* @param {boolean} [options.isLegacy]
* @param {number} [options.walletIndex]
* @return {string}
*/
// @ts-expect-error @TODO https://github.com/microsoft/TypeScript/issues/50286
export function getSmartWalletAddress(evmAccountAddress, {isLegacy, walletIndex = SMART_WALLET_INDEX} = {}) {
if (!evmAccountAddress) {
return '';
}
const factoryContractAddress = isLegacy ? SMART_WALLET_FACTORY_LEGACY_BSC_CONTRACT_ADDRESS : SMART_WALLET_FACTORY_CONTRACT_ADDRESS;
const salt = web3Utils.keccak256(web3Abi.encodeParameters(["address", "uint256"], [evmAccountAddress, walletIndex]));
const byteCode = smartWalletBin + web3Abi.encodeParameter('address', evmAccountAddress).slice(2);
return buildCreate2Address(factoryContractAddress, salt, byteCode);

/**
* @param {string} creatorAddress
* @param {string} saltHex
* @param {string} byteCode
* @return {string}
*/
function buildCreate2Address(creatorAddress, saltHex, byteCode) {
const parts = [
'ff',
creatorAddress.slice(2),
saltHex.slice(2),
web3Utils.keccak256(byteCode).slice(2),
];

const partsHash = web3Utils.keccak256(`0x${parts.join('')}`);
return `0x${partsHash.slice(-40)}`.toLowerCase();
}
}

/**
* @typedef {object} SmartWalletTxParams
* @property {string} to
* @property {string} data
* @property {string} value
*/

10 changes: 5 additions & 5 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ module.exports = {
plugins: [
new webpack.ContextReplacementPlugin(/moment[/]locale$/, /^\.\/(en|ru)$/),
],
babel: {
presets: ['@nuxt/babel-preset-app'],
// prevent @babel/plugin-transform-runtime from inserting `import` statement into commonjs files (bc. it breaks webpack)
sourceType: 'unambiguous',
},
// babel: {
// presets: ['@nuxt/babel-preset-app'],
// // prevent @babel/plugin-transform-runtime from inserting `import` statement into commonjs files (bc. it breaks webpack)
// sourceType: 'unambiguous',
// },
transpile: [
/es6-promise|\.(?!(?:js|json)$).{1,5}$/i,
'/base-x/',
Expand Down
Loading

0 comments on commit bc0335a

Please sign in to comment.