diff --git a/src/token.js b/src/token.js index 85352b24..97478d94 100644 --- a/src/token.js +++ b/src/token.js @@ -1,9 +1,10 @@ -import { ZERO_ADDRESS } from '~/common/constants'; +import { SAFE_LAST_VERSION, ZERO_ADDRESS } from '~/common/constants'; import CoreError, { TransferError, ErrorCodes } from '~/common/error'; import checkAccount from '~/common/checkAccount'; import checkOptions from '~/common/checkOptions'; import { getTokenContract } from '~/common/getContracts'; +import { getVersion } from '~/safe'; /* Due to block gas limit of 12.500.000 a transitive transaction can have a * limited number of steps. The limit below gives a 50% buffer between the @@ -225,11 +226,14 @@ export default function createTokenModule(web3, contracts, utils) { const txData = await hub.methods.signup().encodeABI(); + const safeVersion = await getVersion(web3, options.safeAddress); + // Call method and return result return await utils.executeSafeTx(account, { safeAddress: options.safeAddress, to: hub.options.address, txData, + isCRCVersion: safeVersion != SAFE_LAST_VERSION, }); }, diff --git a/src/utils.js b/src/utils.js index 39e6e3df..de26ed7e 100644 --- a/src/utils.js +++ b/src/utils.js @@ -910,6 +910,8 @@ export default function createUtilsModule(web3, contracts, globalOptions) { * @param {string} userOptions.gasToken - address of ERC20 token * @param {Object} userOptions.txData - encoded transaction data * @param {number} userOptions.value - value in Wei + * @param {boolean} userOptions.isCRCVersion - is the Safe v1.1.1+Cirlces, false by default + * * @return {string} - transaction hash */ @@ -935,9 +937,14 @@ export default function createUtilsModule(web3, contracts, globalOptions) { type: 'number', default: 0, }, + isCRCVersion: { + type: 'boolean', + default: false, + }, }); - const { to, gasToken, txData, value, safeAddress } = options; + const { to, gasToken, txData, value, safeAddress, isCRCVersion } = + options; const operation = CALL_OP; const refundReceiver = ZERO_ADDRESS; @@ -982,24 +989,42 @@ export default function createUtilsModule(web3, contracts, globalOptions) { // Request nonce for Safe const nonce = await requestNonce(web3, relayServiceEndpoint, safeAddress); - // Get the chainId from the network - const chainId = await web3.eth.getChainId(); - // Prepare EIP712 transaction data and sign it - const typedData = formatTypedData( - to, - value, - txData, - operation, - safeTxGas, - dataGas, - gasPrice, - gasToken, - refundReceiver, - nonce, - chainId, - safeAddress, - ); + let typedData; + if (isCRCVersion == true) { + // Prepare EIP712 transaction data and sign it + typedData = formatTypedDataCRCVersion( + to, + value, + txData, + operation, + safeTxGas, + dataGas, + gasPrice, + gasToken, + refundReceiver, + nonce, + safeAddress, + ); + } else { + // Get the chainId from the network + const chainId = await web3.eth.getChainId(); + // Prepare EIP712 transaction data and sign it + typedData = formatTypedData( + to, + value, + txData, + operation, + safeTxGas, + dataGas, + gasPrice, + gasToken, + refundReceiver, + nonce, + chainId, + safeAddress, + ); + } const signature = signTypedData(web3, account.privateKey, typedData); diff --git a/test/safe.test.js b/test/safe.test.js index 53e676af..fe4b9c16 100644 --- a/test/safe.test.js +++ b/test/safe.test.js @@ -7,15 +7,10 @@ import { deploySafeAndToken, fundSafe, deployCRCVersionSafe, - deployCRCVersionToken, + deployToken, } from './helpers/transactions'; -import { - SAFE_LAST_VERSION, - SAFE_CRC_VERSION, - ZERO_ADDRESS, -} from '~/common/constants'; -import getContracts from '~/common/getContracts'; +import { SAFE_LAST_VERSION, SAFE_CRC_VERSION } from '~/common/constants'; describe('Safe', () => { let core; @@ -247,33 +242,20 @@ describe('Safe', () => { let ownerCRCVersion; let CRCVersionSafeAddress; let CRCVersionSafeInstance; - let contracts; beforeAll(async () => { // Deploy new version (v1.3.0) const result = await deploySafeAndToken(core, accounts[0]); safeAddress = result.safeAddress; - // Get the hub - const hubAddress = core.options.hubAddress; - contracts = await getContracts(web3, { - hubAddress: hubAddress, - proxyFactoryAddress: ZERO_ADDRESS, - safeMasterAddress: ZERO_ADDRESS, - }); - const { hub } = contracts; - // Deploy a Safe with the CRC version (v1.1.1+Circles) ownerCRCVersion = getAccount(8); CRCVersionSafeInstance = await deployCRCVersionSafe(ownerCRCVersion); CRCVersionSafeAddress = CRCVersionSafeInstance.options.address; await fundSafe(accounts[0], CRCVersionSafeAddress); - await deployCRCVersionToken( - web3, - ownerCRCVersion, - CRCVersionSafeInstance, - hub, - ); + await deployToken(core, ownerCRCVersion, { + safeAddress: CRCVersionSafeAddress, + }); }); it('I should get the last version by default', async () => {