@safe-global/protocol-kit 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +9 -9
- package/README.md +1033 -1033
- package/dist/src/Safe.d.ts +51 -1
- package/dist/src/Safe.js +173 -16
- package/dist/src/Safe.js.map +1 -1
- package/dist/src/adapters/ethers/EthersAdapter.js +9 -10
- package/dist/src/adapters/ethers/EthersAdapter.js.map +1 -1
- package/dist/src/adapters/ethers/contracts/SafeProxyFactory/SafeProxyFactoryEthersContract.js +1 -2
- package/dist/src/adapters/ethers/contracts/SafeProxyFactory/SafeProxyFactoryEthersContract.js.map +1 -1
- package/dist/src/adapters/web3/Web3Adapter.js +17 -17
- package/dist/src/adapters/web3/Web3Adapter.js.map +1 -1
- package/dist/src/adapters/web3/contracts/SafeProxyFactory/SafeProxyFactoryWeb3Contract.js +1 -2
- package/dist/src/adapters/web3/contracts/SafeProxyFactory/SafeProxyFactoryWeb3Contract.js.map +1 -1
- package/dist/src/contracts/safeDeploymentContracts.js +16 -16
- package/dist/src/contracts/safeDeploymentContracts.js.map +1 -1
- package/dist/src/contracts/utils.js +25 -1
- package/dist/src/contracts/utils.js.map +1 -1
- package/dist/src/index.d.ts +3 -2
- package/dist/src/index.js +9 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/managers/contractManager.js +19 -14
- package/dist/src/managers/contractManager.js.map +1 -1
- package/dist/src/managers/ownerManager.js +2 -2
- package/dist/src/managers/ownerManager.js.map +1 -1
- package/dist/src/safeFactory/index.js +4 -6
- package/dist/src/safeFactory/index.js.map +1 -1
- package/dist/src/utils/erc-20/index.d.ts +33 -0
- package/dist/src/utils/erc-20/index.js +77 -0
- package/dist/src/utils/erc-20/index.js.map +1 -0
- package/dist/src/utils/signatures/utils.js +1 -1
- package/dist/src/utils/transactions/SafeTransaction.js +2 -2
- package/dist/src/utils/transactions/SafeTransaction.js.map +1 -1
- package/dist/src/utils/transactions/gas.d.ts +48 -1
- package/dist/src/utils/transactions/gas.js +308 -32
- package/dist/src/utils/transactions/gas.js.map +1 -1
- package/dist/src/utils/transactions/utils.js +7 -9
- package/dist/src/utils/transactions/utils.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +98 -96
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/safeFactory/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,0EAAiD;AACjD,uEAAiF;AACjF,yGAGoE;AACpE,qEAMkD;AA2ClD,MAAM,WAAW;IAAjB;QACE,gDAA0C;QAC1C,kDAA6B;QAC7B,2CAA0B;QAC1B,0CAAwB;QACxB,wDAAoD;QACpD,4CAA4B;IAwH9B,CAAC;IAtHC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAClB,UAAU,EACV,WAAW,GAAG,6BAAoB,EAClC,kBAAkB,GAAG,KAAK,EAC1B,gBAAgB,EACE;QAClB,MAAM,cAAc,GAAG,IAAI,WAAW,EAAE,CAAA;QACxC,MAAM,cAAc,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,CAAC,CAAA;QAC5F,OAAO,cAAc,CAAA;IACvB,CAAC;IAEO,KAAK,CAAC,IAAI,CAAC,EACjB,UAAU,EACV,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EACM;QACtB,uBAAA,IAAI,2BAAe,UAAU,MAAA,CAAA;QAC7B,uBAAA,IAAI,4BAAgB,WAAW,MAAA,CAAA;QAC/B,uBAAA,IAAI,mCAAuB,kBAAkB,MAAA,CAAA;QAC7C,uBAAA,IAAI,iCAAqB,gBAAgB,MAAA,CAAA;QACzC,MAAM,OAAO,GAAG,MAAM,uBAAA,IAAI,+BAAY,CAAC,UAAU,EAAE,CAAA;QACnD,MAAM,eAAe,GAAG,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceR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AAE,CAAA;QACvC,MAAM,eAAe,GAAG,uBAAA,IAAI,qCAAkB,EAAE,CAAC,OAAO,CAAC,CAAA;QACzD,MAAM,WAAW,GAAG,MAAM,IAAA,2BAAmB,EAAC;YAC5C,UAAU,EAAE,uBAAA,IAAI,+BAAY;YAC5B,iBAAiB;YACjB,YAAY,EAAE,uBAAA,IAAI,iCAAc;YAChC,eAAe;SAChB,CAAC,CAAA;QAEF,IAAI,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,QAAQ,EAAE;YACrC,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAA;SACnF;QACD,MAAM,WAAW,GAAG,MAAM,uBAAA,IAAI,6CAA0B,CAAC,WAAW,CAAC;YACnE,qBAAqB,EAAE,uBAAA,IAAI,iCAAc,CAAC,UAAU,EAAE;YACtD,WAAW;YACX,SAAS;YACT,OAAO,EAAE;gBACP,IAAI,EAAE,aAAa;gBACnB,GAAG,OAAO;aACX;YACD,QAAQ;SACT,CAAC,CAAA;QACF,MAAM,kBAAkB,GAAG,MAAM,uBAAA,IAAI,+BAAY,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAA;QACjF,IAAI,CAAC,kBAAkB,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAA;SAC7E;QACD,MAAM,IAAI,GAAG,MAAM,cAAI,CAAC,MAAM,CAAC;YAC7B,UAAU,EAAE,uBAAA,IAAI,+BAAY;YAC5B,WAAW;YACX,kBAAkB,EAAE,uBAAA,IAAI,uCAAoB;YAC5C,gBAAgB,EAAE,uBAAA,IAAI,qCAAkB;SACzC,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;CACF;;AAED,kBAAe,WAAW,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import Safe from '../../Safe';
|
|
2
|
+
import { Transaction } from '@safe-global/safe-core-sdk-types';
|
|
3
|
+
/**
|
|
4
|
+
* Returns the number of decimals of a given ERC-20 token.
|
|
5
|
+
*
|
|
6
|
+
* @async
|
|
7
|
+
* @param {string} tokenAddress - The address of the ERC-20 token.
|
|
8
|
+
* @param {Safe} safe - The Safe object.
|
|
9
|
+
* @returns {Promise<number>} The number of decimals that the token uses.
|
|
10
|
+
* @throws "Invalid ERC-20 decimals"
|
|
11
|
+
*/
|
|
12
|
+
export declare function getERC20Decimals(tokenAddress: string, safe: Safe): Promise<number>;
|
|
13
|
+
/**
|
|
14
|
+
* Checks if the given gas token is compatible with the handlePayment function present in the Safe smart contract.
|
|
15
|
+
* A token is considered compatible if it is a native token or a standard ERC-20 token with 18 decimals.
|
|
16
|
+
*
|
|
17
|
+
* @async
|
|
18
|
+
* @export
|
|
19
|
+
* @param {string} gasToken - The address of the gas token.
|
|
20
|
+
* @param {Safe} safe - The Safe object.
|
|
21
|
+
* @returns {Promise<boolean>} Returns true if the gas token is compatible, otherwise false.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isGasTokenCompatibleWithHandlePayment(gasToken: string, safe: Safe): Promise<boolean>;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a transaction object to perform a transfer of a specified amount of ERC-20 tokens to a given address.
|
|
26
|
+
*
|
|
27
|
+
* @export
|
|
28
|
+
* @param {string} tokenAddress - The address of the ERC-20 token.
|
|
29
|
+
* @param {string} toAddress - The address to which the tokens should be transferred.
|
|
30
|
+
* @param {string} amount - The amount of tokens to transfer.
|
|
31
|
+
* @returns {Transaction} Returns a transaction object that represents the transfer.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createERC20TokenTransferTransaction(tokenAddress: string, toAddress: string, amount: string): Transaction;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createERC20TokenTransferTransaction = exports.isGasTokenCompatibleWithHandlePayment = exports.getERC20Decimals = void 0;
|
|
4
|
+
const abi_1 = require("@ethersproject/abi");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const ERC20_ABI = [
|
|
7
|
+
'function transfer(address recipient, uint256 amount) returns (bool)',
|
|
8
|
+
'function decimals() view returns (uint8)'
|
|
9
|
+
];
|
|
10
|
+
/**
|
|
11
|
+
* Returns the number of decimals of a given ERC-20 token.
|
|
12
|
+
*
|
|
13
|
+
* @async
|
|
14
|
+
* @param {string} tokenAddress - The address of the ERC-20 token.
|
|
15
|
+
* @param {Safe} safe - The Safe object.
|
|
16
|
+
* @returns {Promise<number>} The number of decimals that the token uses.
|
|
17
|
+
* @throws "Invalid ERC-20 decimals"
|
|
18
|
+
*/
|
|
19
|
+
async function getERC20Decimals(tokenAddress, safe) {
|
|
20
|
+
const ethAdapter = safe.getEthAdapter();
|
|
21
|
+
const erc20Interface = new abi_1.Interface(ERC20_ABI);
|
|
22
|
+
const getTokenDecimalsTransaction = {
|
|
23
|
+
to: tokenAddress,
|
|
24
|
+
from: tokenAddress,
|
|
25
|
+
value: '0',
|
|
26
|
+
data: erc20Interface.encodeFunctionData('decimals')
|
|
27
|
+
};
|
|
28
|
+
const response = await ethAdapter.call(getTokenDecimalsTransaction);
|
|
29
|
+
const decimals = Number(response);
|
|
30
|
+
if (Number.isNaN(decimals)) {
|
|
31
|
+
throw new Error('Invalid ERC-20 decimals');
|
|
32
|
+
}
|
|
33
|
+
return decimals;
|
|
34
|
+
}
|
|
35
|
+
exports.getERC20Decimals = getERC20Decimals;
|
|
36
|
+
const STANDARD_ERC20_DECIMALS = 18;
|
|
37
|
+
/**
|
|
38
|
+
* Checks if the given gas token is compatible with the handlePayment function present in the Safe smart contract.
|
|
39
|
+
* A token is considered compatible if it is a native token or a standard ERC-20 token with 18 decimals.
|
|
40
|
+
*
|
|
41
|
+
* @async
|
|
42
|
+
* @export
|
|
43
|
+
* @param {string} gasToken - The address of the gas token.
|
|
44
|
+
* @param {Safe} safe - The Safe object.
|
|
45
|
+
* @returns {Promise<boolean>} Returns true if the gas token is compatible, otherwise false.
|
|
46
|
+
*/
|
|
47
|
+
async function isGasTokenCompatibleWithHandlePayment(gasToken, safe) {
|
|
48
|
+
const isNativeToken = gasToken === constants_1.ZERO_ADDRESS;
|
|
49
|
+
if (isNativeToken) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
// Only ERC20 tokens with the standard 18 decimals are compatible
|
|
53
|
+
const gasTokenDecimals = await getERC20Decimals(gasToken, safe);
|
|
54
|
+
const hasTokenStandardERC20Decimals = gasTokenDecimals === STANDARD_ERC20_DECIMALS;
|
|
55
|
+
return hasTokenStandardERC20Decimals;
|
|
56
|
+
}
|
|
57
|
+
exports.isGasTokenCompatibleWithHandlePayment = isGasTokenCompatibleWithHandlePayment;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a transaction object to perform a transfer of a specified amount of ERC-20 tokens to a given address.
|
|
60
|
+
*
|
|
61
|
+
* @export
|
|
62
|
+
* @param {string} tokenAddress - The address of the ERC-20 token.
|
|
63
|
+
* @param {string} toAddress - The address to which the tokens should be transferred.
|
|
64
|
+
* @param {string} amount - The amount of tokens to transfer.
|
|
65
|
+
* @returns {Transaction} Returns a transaction object that represents the transfer.
|
|
66
|
+
*/
|
|
67
|
+
function createERC20TokenTransferTransaction(tokenAddress, toAddress, amount) {
|
|
68
|
+
const erc20Interface = new abi_1.Interface(ERC20_ABI);
|
|
69
|
+
const transferTransaction = {
|
|
70
|
+
to: tokenAddress,
|
|
71
|
+
value: '0',
|
|
72
|
+
data: erc20Interface.encodeFunctionData('transfer', [toAddress, amount])
|
|
73
|
+
};
|
|
74
|
+
return transferTransaction;
|
|
75
|
+
}
|
|
76
|
+
exports.createERC20TokenTransferTransaction = createERC20TokenTransferTransaction;
|
|
77
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/erc-20/index.ts"],"names":[],"mappings":";;;AAAA,4CAA8C;AAI9C,4CAA2C;AAE3C,MAAM,SAAS,GAAG;IAChB,qE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AA;IAE/C,MAAM,mBAAmB,GAAG;QAC1B,EAAE,EAAE,YAAY;QAChB,KAAK,EAAE,GAAG;QACV,IAAI,EAAE,cAAc,CAAC,kBAAkB,CAAC,UAAU,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;KACzE,CAAA;IAED,OAAO,mBAAmB,CAAA;AAC5B,CAAC;AAdD,kFAcC"}
|
|
@@ -47,7 +47,7 @@ const adjustVInSignature = (signingMethod, signature, safeTxHash, signerAddress)
|
|
|
47
47
|
prefix is to check if the signer address is the same as the recovered address.
|
|
48
48
|
|
|
49
49
|
More info:
|
|
50
|
-
https://docs.safe.global/
|
|
50
|
+
https://docs.safe.global/safe-core-protocol/signatures
|
|
51
51
|
*/
|
|
52
52
|
if (signatureV < MIN_VALID_V_VALUE_FOR_SAFE_ECDSA) {
|
|
53
53
|
signatureV += MIN_VALID_V_VALUE_FOR_SAFE_ECDSA;
|
|
@@ -15,8 +15,8 @@ class EthSafeTransaction {
|
|
|
15
15
|
let dynamicParts = '';
|
|
16
16
|
signers.forEach((signerAddress) => {
|
|
17
17
|
const signature = this.signatures.get(signerAddress);
|
|
18
|
-
staticParts += signature
|
|
19
|
-
dynamicParts += signature
|
|
18
|
+
staticParts += signature?.staticPart( /*baseOffset + dynamicParts.length / 2*/).slice(2);
|
|
19
|
+
dynamicParts += signature?.dynamicPart();
|
|
20
20
|
});
|
|
21
21
|
return '0x' + staticParts + dynamicParts;
|
|
22
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SafeTransaction.js","sourceRoot":"","sources":["../../../../src/utils/transactions/SafeTransaction.ts"],"names":[],"mappings":";;AAMA,MAAM,kBAAkB;IAItB,YAAY,IAAyB;QAFrC,eAAU,GAA+B,IAAI,GAAG,EAAE,CAAA;QAGhD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAED,YAAY,CAAC,SAAwB;QACnC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,S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C,aAAa,CAAC,CAAA;YACpD,WAAW,IAAI,SAAS,EAAE,UAAU,EAAC,wCAAwC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;YACvF,YAAY,IAAI,SAAS,EAAE,WAAW,EAAE,CAAA;QAC1C,CAAC,CAAC,CAAA;QACF,OAAO,IAAI,GAAG,WAAW,GAAG,YAAY,CAAA;IAC1C,CAAC;CACF;AAED,kBAAe,kBAAkB,CAAA"}
|
|
@@ -1,4 +1,51 @@
|
|
|
1
|
+
import { EthAdapter, SafeContract, OperationType, SafeVersion, SafeTransaction } from '@safe-global/safe-core-sdk-types';
|
|
2
|
+
import Safe from '../../Safe';
|
|
1
3
|
import { ContractNetworksConfig } from '../../types';
|
|
2
|
-
import { EthAdapter, OperationType, SafeContract, SafeVersion } from '@safe-global/safe-core-sdk-types';
|
|
3
4
|
export declare function estimateGas(safeVersion: SafeVersion, safeContract: SafeContract, ethAdapter: EthAdapter, to: string, valueInWei: string, data: string, operation: OperationType, customContracts?: ContractNetworksConfig): Promise<string>;
|
|
4
5
|
export declare function estimateTxGas(safeContract: SafeContract, ethAdapter: EthAdapter, to: string, valueInWei: string, data: string, operation: OperationType): Promise<string>;
|
|
6
|
+
/**
|
|
7
|
+
* This function estimates the baseGas of a Safe transaction.
|
|
8
|
+
* The baseGas includes costs for:
|
|
9
|
+
* - Generation of the Safe transaction hash (txHash)
|
|
10
|
+
* - Increasing the nonce of the Safe
|
|
11
|
+
* - Verifying the signatures of the Safe transaction
|
|
12
|
+
* - Payment to relayers for executing the transaction
|
|
13
|
+
* - Emitting events ExecutionSuccess or ExecutionFailure
|
|
14
|
+
*
|
|
15
|
+
* Note: it does not include the transaction execution cost (safeTxGas)
|
|
16
|
+
*
|
|
17
|
+
* @async
|
|
18
|
+
* @function estimateTxBaseGas
|
|
19
|
+
* @param {Safe} safe - The Safe instance containing all the information about the safe.
|
|
20
|
+
* @param {SafeTransaction} safeTransaction - The transaction for which the baseGas is to be estimated.
|
|
21
|
+
* @returns {Promise<string>} A Promise that resolves with the estimated baseGas as a string.
|
|
22
|
+
*/
|
|
23
|
+
export declare function estimateTxBaseGas(safe: Safe, safeTransaction: SafeTransaction): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* This function estimates the safeTxGas of a Safe transaction.
|
|
26
|
+
* The safeTxGas value represents the amount of gas required to execute the Safe transaction itself.
|
|
27
|
+
* It does not include costs such as signature verification, transaction hash generation, nonce incrementing, and so on.
|
|
28
|
+
*
|
|
29
|
+
* The estimation method differs based on the version of the Safe:
|
|
30
|
+
* - For versions >= 1.3.0, the simulate function defined in the simulateTxAccessor.sol Contract is used.
|
|
31
|
+
* - For versions < 1.3.0, the deprecated requiredTxGas method defined in the GnosisSafe.sol contract is used.
|
|
32
|
+
*
|
|
33
|
+
* @async
|
|
34
|
+
* @function estimateSafeTxGas
|
|
35
|
+
* @param {Safe} safe - The Safe instance containing all the necessary information about the safe.
|
|
36
|
+
* @param {SafeTransaction} safeTransaction - The transaction for which the safeTxGas is to be estimated.
|
|
37
|
+
* @returns {Promise<string>} A Promise that resolves with the estimated safeTxGas as a string.
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
export declare function estimateSafeTxGas(safe: Safe, safeTransaction: SafeTransaction): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* This function estimates the gas cost of deploying a Safe.
|
|
43
|
+
* It considers also the costs of the Safe setup call.
|
|
44
|
+
* The setup call includes tasks such as setting up initial owners, defining the threshold, and initializing the salt nonce used for address generation.
|
|
45
|
+
*
|
|
46
|
+
* @async
|
|
47
|
+
* @function estimateSafeDeploymentGas
|
|
48
|
+
* @param {Safe} safe - The Safe object containing all necessary information about the safe, including owners, threshold, and saltNonce.
|
|
49
|
+
* @returns {Promise<string>} A Promise that resolves with the estimated gas cost of the safe deployment as a string.
|
|
50
|
+
*/
|
|
51
|
+
export declare function estimateSafeDeploymentGas(safe: Safe): Promise<string>;
|
|
@@ -1,28 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.estimateTxGas = exports.estimateGas = void 0;
|
|
6
|
+
exports.estimateSafeDeploymentGas = exports.estimateSafeTxGas = exports.estimateTxBaseGas = exports.estimateTxGas = exports.estimateGas = void 0;
|
|
4
7
|
const bignumber_1 = require("@ethersproject/bignumber");
|
|
5
8
|
const safe_core_sdk_types_1 = require("@safe-global/safe-core-sdk-types");
|
|
9
|
+
const satisfies_1 = __importDefault(require("semver/functions/satisfies"));
|
|
10
|
+
const constants_1 = require("../constants");
|
|
6
11
|
const safeDeploymentContracts_1 = require("../../contracts/safeDeploymentContracts");
|
|
12
|
+
// Every byte == 00 -> 4 Gas cost
|
|
13
|
+
const CALL_DATA_ZERO_BYTE_GAS_COST = 4;
|
|
14
|
+
// Every byte != 00 -> 16 Gas cost (68 before Istanbul)
|
|
15
|
+
const CALL_DATA_BYTE_GAS_COST = 16;
|
|
16
|
+
// gas cost initialization of a Safe
|
|
17
|
+
const INITIZATION_GAS_COST = 20000;
|
|
18
|
+
// increment nonce gas cost
|
|
19
|
+
const INCREMENT_NONCE_GAS_COST = 5000;
|
|
20
|
+
// Keccak gas cost for the hash of the Safe transaction
|
|
21
|
+
const HASH_GENERATION_GAS_COST = 1500;
|
|
22
|
+
// ecrecover gas cost for ecdsa ~= 4K gas, we use 6K
|
|
23
|
+
const ECRECOVER_GAS_COST = 6000;
|
|
24
|
+
// transfer gas cost
|
|
25
|
+
const TRANSAFER_GAS_COST = 32000;
|
|
26
|
+
// numbers < 256 (0x00(31*2)..ff) are 192 -> 31 * 4 + 1 * CALL_DATA_BYTE_GAS_COST
|
|
27
|
+
// numbers < 65535 (0x(30*2)..ffff) are 256 -> 30 * 4 + 2 * CALL_DATA_BYTE_GAS_COST
|
|
28
|
+
// Calculate gas for signatures
|
|
29
|
+
// (array count (3 -> r, s, v) + ecrecover costs) * signature count
|
|
30
|
+
const GAS_COST_PER_SIGNATURE = 1 * CALL_DATA_BYTE_GAS_COST + 2 * 32 * CALL_DATA_BYTE_GAS_COST + ECRECOVER_GAS_COST;
|
|
7
31
|
function estimateDataGasCosts(data) {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
32
|
+
const bytes = data.match(/.{2}/g);
|
|
33
|
+
return bytes.reduce((gasCost, currentByte) => {
|
|
34
|
+
if (currentByte === '0x') {
|
|
35
|
+
return gasCost + 0;
|
|
11
36
|
}
|
|
12
|
-
if (
|
|
13
|
-
return
|
|
37
|
+
if (currentByte === '00') {
|
|
38
|
+
return gasCost + CALL_DATA_ZERO_BYTE_GAS_COST;
|
|
14
39
|
}
|
|
15
|
-
return
|
|
16
|
-
};
|
|
17
|
-
return data.match(/.{2}/g).reduce(reducer, 0);
|
|
40
|
+
return gasCost + CALL_DATA_BYTE_GAS_COST;
|
|
41
|
+
}, 0);
|
|
18
42
|
}
|
|
19
43
|
async function estimateGas(safeVersion, safeContract, ethAdapter, to, valueInWei, data, operation, customContracts) {
|
|
20
|
-
var _a;
|
|
21
44
|
const chainId = await ethAdapter.getChainId();
|
|
22
45
|
const simulateTxAccessorContract = await (0, safeDeploymentContracts_1.getSimulateTxAccessorContract)({
|
|
23
46
|
ethAdapter,
|
|
24
47
|
safeVersion,
|
|
25
|
-
customContracts: customContracts
|
|
48
|
+
customContracts: customContracts?.[chainId]
|
|
26
49
|
});
|
|
27
50
|
const transactionDataToEstimate = simulateTxAccessorContract.encode('simulate', [
|
|
28
51
|
to,
|
|
@@ -41,32 +64,12 @@ async function estimateGas(safeVersion, safeContract, ethAdapter, to, valueInWei
|
|
|
41
64
|
data: safeFunctionToEstimate,
|
|
42
65
|
from: safeAddress
|
|
43
66
|
};
|
|
44
|
-
// TO-DO: Improve decoding
|
|
45
|
-
/*
|
|
46
|
-
const simulateAndRevertResponse = ethAdapter.decodeParameters(
|
|
47
|
-
['bool', 'bytes'],
|
|
48
|
-
encodedResponse
|
|
49
|
-
)
|
|
50
|
-
const returnedData = ethAdapter.decodeParameters(['uint256', 'bool', 'bytes'], simulateAndRevertResponse[1])
|
|
51
|
-
*/
|
|
52
67
|
try {
|
|
53
68
|
const encodedResponse = await ethAdapter.call(transactionToEstimateGas);
|
|
54
69
|
return Number('0x' + encodedResponse.slice(184).slice(0, 10)).toString();
|
|
55
70
|
}
|
|
56
71
|
catch (error) {
|
|
57
|
-
|
|
58
|
-
if ((_a = error === null || error === void 0 ? void 0 : error.error) === null || _a === void 0 ? void 0 : _a.body) {
|
|
59
|
-
const revertData = JSON.parse(error.error.body).error.data;
|
|
60
|
-
if (revertData && revertData.startsWith('Reverted ')) {
|
|
61
|
-
const [, encodedResponse] = revertData.split('Reverted ');
|
|
62
|
-
const safeTxGas = Number('0x' + encodedResponse.slice(184).slice(0, 10)).toString();
|
|
63
|
-
return safeTxGas;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
// Web3
|
|
67
|
-
const [, encodedResponse] = error.message.split('return data: ');
|
|
68
|
-
const safeTxGas = Number('0x' + encodedResponse.slice(184).slice(0, 10)).toString();
|
|
69
|
-
return safeTxGas;
|
|
72
|
+
return parseSafeTxGasErrorResponse(error);
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
75
|
exports.estimateGas = estimateGas;
|
|
@@ -127,4 +130,277 @@ async function estimateTxGas(safeContract, ethAdapter, to, valueInWei, data, ope
|
|
|
127
130
|
}
|
|
128
131
|
}
|
|
129
132
|
exports.estimateTxGas = estimateTxGas;
|
|
133
|
+
/**
|
|
134
|
+
* This function estimates the baseGas of a Safe transaction.
|
|
135
|
+
* The baseGas includes costs for:
|
|
136
|
+
* - Generation of the Safe transaction hash (txHash)
|
|
137
|
+
* - Increasing the nonce of the Safe
|
|
138
|
+
* - Verifying the signatures of the Safe transaction
|
|
139
|
+
* - Payment to relayers for executing the transaction
|
|
140
|
+
* - Emitting events ExecutionSuccess or ExecutionFailure
|
|
141
|
+
*
|
|
142
|
+
* Note: it does not include the transaction execution cost (safeTxGas)
|
|
143
|
+
*
|
|
144
|
+
* @async
|
|
145
|
+
* @function estimateTxBaseGas
|
|
146
|
+
* @param {Safe} safe - The Safe instance containing all the information about the safe.
|
|
147
|
+
* @param {SafeTransaction} safeTransaction - The transaction for which the baseGas is to be estimated.
|
|
148
|
+
* @returns {Promise<string>} A Promise that resolves with the estimated baseGas as a string.
|
|
149
|
+
*/
|
|
150
|
+
async function estimateTxBaseGas(safe, safeTransaction) {
|
|
151
|
+
const safeTransactionData = safeTransaction.data;
|
|
152
|
+
const { to, value, data, operation, safeTxGas, gasToken, refundReceiver } = safeTransactionData;
|
|
153
|
+
const safeThreshold = await safe.getThreshold();
|
|
154
|
+
const safeNonce = await safe.getNonce();
|
|
155
|
+
const signaturesGasCost = safeThreshold * GAS_COST_PER_SIGNATURE;
|
|
156
|
+
const encodeSafeTxGas = safeTxGas || 0;
|
|
157
|
+
const encodeBaseGas = 0;
|
|
158
|
+
const gasPrice = 1;
|
|
159
|
+
const encodeGasToken = gasToken || constants_1.ZERO_ADDRESS;
|
|
160
|
+
const encodeRefundReceiver = refundReceiver || constants_1.ZERO_ADDRESS;
|
|
161
|
+
const signatures = '0x';
|
|
162
|
+
const safeVersion = await safe.getContractVersion();
|
|
163
|
+
const ethAdapter = safe.getEthAdapter();
|
|
164
|
+
const isL1SafeMasterCopy = safe.getContractManager().isL1SafeMasterCopy;
|
|
165
|
+
const chainId = await safe.getChainId();
|
|
166
|
+
const customContracts = safe.getContractManager().contractNetworks?.[chainId];
|
|
167
|
+
const safeSingletonContract = await (0, safeDeploymentContracts_1.getSafeContract)({
|
|
168
|
+
ethAdapter,
|
|
169
|
+
safeVersion,
|
|
170
|
+
isL1SafeMasterCopy,
|
|
171
|
+
customContracts
|
|
172
|
+
});
|
|
173
|
+
const execTransactionData = safeSingletonContract.encode('execTransaction', [
|
|
174
|
+
to,
|
|
175
|
+
value,
|
|
176
|
+
data,
|
|
177
|
+
operation,
|
|
178
|
+
encodeSafeTxGas,
|
|
179
|
+
encodeBaseGas,
|
|
180
|
+
gasPrice,
|
|
181
|
+
encodeGasToken,
|
|
182
|
+
encodeRefundReceiver,
|
|
183
|
+
signatures
|
|
184
|
+
]);
|
|
185
|
+
// If nonce == 0, nonce storage has to be initialized
|
|
186
|
+
const isSafeInitialized = safeNonce !== 0;
|
|
187
|
+
const incrementNonceGasCost = isSafeInitialized ? INCREMENT_NONCE_GAS_COST : INITIZATION_GAS_COST;
|
|
188
|
+
let baseGas = signaturesGasCost +
|
|
189
|
+
estimateDataGasCosts(execTransactionData) +
|
|
190
|
+
incrementNonceGasCost +
|
|
191
|
+
HASH_GENERATION_GAS_COST;
|
|
192
|
+
// Add additional gas costs
|
|
193
|
+
baseGas > 65536 ? (baseGas += 64) : (baseGas += 128);
|
|
194
|
+
// Base tx costs, transfer costs...
|
|
195
|
+
baseGas += TRANSAFER_GAS_COST;
|
|
196
|
+
return baseGas.toString();
|
|
197
|
+
}
|
|
198
|
+
exports.estimateTxBaseGas = estimateTxBaseGas;
|
|
199
|
+
/**
|
|
200
|
+
* This function estimates the safeTxGas of a Safe transaction.
|
|
201
|
+
* The safeTxGas value represents the amount of gas required to execute the Safe transaction itself.
|
|
202
|
+
* It does not include costs such as signature verification, transaction hash generation, nonce incrementing, and so on.
|
|
203
|
+
*
|
|
204
|
+
* The estimation method differs based on the version of the Safe:
|
|
205
|
+
* - For versions >= 1.3.0, the simulate function defined in the simulateTxAccessor.sol Contract is used.
|
|
206
|
+
* - For versions < 1.3.0, the deprecated requiredTxGas method defined in the GnosisSafe.sol contract is used.
|
|
207
|
+
*
|
|
208
|
+
* @async
|
|
209
|
+
* @function estimateSafeTxGas
|
|
210
|
+
* @param {Safe} safe - The Safe instance containing all the necessary information about the safe.
|
|
211
|
+
* @param {SafeTransaction} safeTransaction - The transaction for which the safeTxGas is to be estimated.
|
|
212
|
+
* @returns {Promise<string>} A Promise that resolves with the estimated safeTxGas as a string.
|
|
213
|
+
*
|
|
214
|
+
*/
|
|
215
|
+
async function estimateSafeTxGas(safe, safeTransaction) {
|
|
216
|
+
const safeVersion = await safe.getContractVersion();
|
|
217
|
+
if ((0, satisfies_1.default)(safeVersion, '>=1.3.0')) {
|
|
218
|
+
const safeTxGas = await estimateSafeTxGasWithSimulate(safe, safeTransaction);
|
|
219
|
+
return addExtraGasForSafety(safeTxGas);
|
|
220
|
+
}
|
|
221
|
+
// deprecated method to estimate the safeTxGas of a Safe transaction
|
|
222
|
+
const safeTxGas = await estimateSafeTxGasWithRequiredTxGas(safe, safeTransaction);
|
|
223
|
+
return addExtraGasForSafety(safeTxGas);
|
|
224
|
+
}
|
|
225
|
+
exports.estimateSafeTxGas = estimateSafeTxGas;
|
|
226
|
+
/**
|
|
227
|
+
* Increase the given safeTxGas gas amount by 5% as a security margin to avoid running out of gas.
|
|
228
|
+
* In some contexts, the safeTxGas might be underestimated, leading to 'out of gas' errors during the Safe transaction execution
|
|
229
|
+
*
|
|
230
|
+
* @param {string} safeTxGas - The original safeTxGas gas amount.
|
|
231
|
+
* @returns {string} The new safeTxGas gas amount, increased by 5% rounded.
|
|
232
|
+
*/
|
|
233
|
+
function addExtraGasForSafety(safeTxGas) {
|
|
234
|
+
const INCREASE_GAS_FACTOR = 1.05; // increase the gas by 5% as a security margin
|
|
235
|
+
return Math.round(Number(safeTxGas) * INCREASE_GAS_FACTOR).toString();
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* This function estimates the safeTxGas of a Safe transaction.
|
|
239
|
+
* Using the deprecated method of requiredTxGas defined in the GnosisSafe contract. This method is meant to be used for Safe versions < 1.3.0.
|
|
240
|
+
* see: https://github.com/safe-global/safe-contracts/blob/v1.2.0/contracts/GnosisSafe.sol#L276
|
|
241
|
+
*
|
|
242
|
+
* @async
|
|
243
|
+
* @function estimateSafeTxGasWithRequiredTxGas
|
|
244
|
+
* @param {Safe} safe - The Safe instance containing all the necessary information about the safe.
|
|
245
|
+
* @param {SafeTransaction} safeTransaction - The transaction for which the safeTxGas is to be estimated.
|
|
246
|
+
* @returns {Promise<string>} A Promise that resolves with the estimated safeTxGas as a string.
|
|
247
|
+
*
|
|
248
|
+
*/
|
|
249
|
+
async function estimateSafeTxGasWithRequiredTxGas(safe, safeTransaction) {
|
|
250
|
+
const isSafeDeployed = await safe.isSafeDeployed();
|
|
251
|
+
const safeAddress = await safe.getAddress();
|
|
252
|
+
const safeVersion = await safe.getContractVersion();
|
|
253
|
+
const ethAdapter = safe.getEthAdapter();
|
|
254
|
+
const isL1SafeMasterCopy = safe.getContractManager().isL1SafeMasterCopy;
|
|
255
|
+
const chainId = await safe.getChainId();
|
|
256
|
+
const customContracts = safe.getContractManager().contractNetworks?.[chainId];
|
|
257
|
+
const safeSingletonContract = await (0, safeDeploymentContracts_1.getSafeContract)({
|
|
258
|
+
ethAdapter,
|
|
259
|
+
safeVersion,
|
|
260
|
+
isL1SafeMasterCopy,
|
|
261
|
+
customContracts
|
|
262
|
+
});
|
|
263
|
+
const transactionDataToEstimate = safeSingletonContract.encode('requiredTxGas', [
|
|
264
|
+
safeTransaction.data.to,
|
|
265
|
+
safeTransaction.data.value,
|
|
266
|
+
safeTransaction.data.data,
|
|
267
|
+
safeTransaction.data.operation
|
|
268
|
+
]);
|
|
269
|
+
const to = isSafeDeployed ? safeAddress : safeSingletonContract.getAddress();
|
|
270
|
+
const transactionToEstimateGas = {
|
|
271
|
+
to,
|
|
272
|
+
value: '0',
|
|
273
|
+
data: transactionDataToEstimate,
|
|
274
|
+
from: safeAddress
|
|
275
|
+
};
|
|
276
|
+
try {
|
|
277
|
+
const encodedResponse = await ethAdapter.call(transactionToEstimateGas);
|
|
278
|
+
const safeTxGas = '0x' + encodedResponse.slice(-32);
|
|
279
|
+
return safeTxGas;
|
|
280
|
+
// if the call throws an error we try to parse the returned value
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
try {
|
|
284
|
+
const revertData = JSON.parse(error.error.body).error.data;
|
|
285
|
+
if (revertData && revertData.startsWith('Reverted ')) {
|
|
286
|
+
const [, safeTxGas] = revertData.split('Reverted ');
|
|
287
|
+
return Number(safeTxGas).toString();
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
catch {
|
|
291
|
+
return '0';
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return '0';
|
|
295
|
+
}
|
|
296
|
+
// TO-DO: Improve decoding
|
|
297
|
+
/*
|
|
298
|
+
const simulateAndRevertResponse = ethAdapter.decodeParameters(
|
|
299
|
+
['bool', 'bytes'],
|
|
300
|
+
encodedResponse
|
|
301
|
+
)
|
|
302
|
+
const returnedData = ethAdapter.decodeParameters(['uint256', 'bool', 'bytes'], simulateAndRevertResponse[1])
|
|
303
|
+
*/
|
|
304
|
+
function decodeSafeTxGas(encodedSafeTxGas) {
|
|
305
|
+
return Number('0x' + encodedSafeTxGas.slice(184).slice(0, 10)).toString();
|
|
306
|
+
}
|
|
307
|
+
function parseSafeTxGasErrorResponse(error) {
|
|
308
|
+
// Ethers
|
|
309
|
+
if (error?.error?.body) {
|
|
310
|
+
const revertData = JSON.parse(error.error.body).error.data;
|
|
311
|
+
if (revertData && revertData.startsWith('Reverted ')) {
|
|
312
|
+
const [, encodedResponse] = revertData.split('Reverted ');
|
|
313
|
+
const safeTxGas = decodeSafeTxGas(encodedResponse);
|
|
314
|
+
return safeTxGas;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
// Web3
|
|
318
|
+
const [, encodedResponse] = error.message.split('return data: ');
|
|
319
|
+
const safeTxGas = decodeSafeTxGas(encodedResponse);
|
|
320
|
+
return safeTxGas;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* This function estimates the safeTxGas of a Safe transaction.
|
|
324
|
+
* It uses the simulate function defined in the SimulateTxAccessor contract. This method is meant to be used for Safe versions >= 1.3.0.
|
|
325
|
+
*
|
|
326
|
+
* @async
|
|
327
|
+
* @function estimateSafeTxGasWithSimulate
|
|
328
|
+
* @param {Safe} safe - The Safe instance containing all the necessary information about the safe.
|
|
329
|
+
* @param {SafeTransaction} safeTransaction - The transaction for which the safeTxGas is to be estimated.
|
|
330
|
+
* @returns {Promise<string>} A Promise that resolves with the estimated safeTxGas as a string.
|
|
331
|
+
*
|
|
332
|
+
*/
|
|
333
|
+
async function estimateSafeTxGasWithSimulate(safe, safeTransaction) {
|
|
334
|
+
const isSafeDeployed = await safe.isSafeDeployed();
|
|
335
|
+
const safeAddress = await safe.getAddress();
|
|
336
|
+
const safeVersion = await safe.getContractVersion();
|
|
337
|
+
const ethAdapter = safe.getEthAdapter();
|
|
338
|
+
const chainId = await safe.getChainId();
|
|
339
|
+
const customContracts = safe.getContractManager().contractNetworks?.[chainId];
|
|
340
|
+
const isL1SafeMasterCopy = safe.getContractManager().isL1SafeMasterCopy;
|
|
341
|
+
const safeSingletonContract = await (0, safeDeploymentContracts_1.getSafeContract)({
|
|
342
|
+
ethAdapter,
|
|
343
|
+
safeVersion,
|
|
344
|
+
isL1SafeMasterCopy,
|
|
345
|
+
customContracts
|
|
346
|
+
});
|
|
347
|
+
// new version of the estimation
|
|
348
|
+
const simulateTxAccessorContract = await (0, safeDeploymentContracts_1.getSimulateTxAccessorContract)({
|
|
349
|
+
ethAdapter,
|
|
350
|
+
safeVersion,
|
|
351
|
+
customContracts
|
|
352
|
+
});
|
|
353
|
+
const transactionDataToEstimate = simulateTxAccessorContract.encode('simulate', [
|
|
354
|
+
safeTransaction.data.to,
|
|
355
|
+
safeTransaction.data.value,
|
|
356
|
+
safeTransaction.data.data,
|
|
357
|
+
safeTransaction.data.operation
|
|
358
|
+
]);
|
|
359
|
+
// if the Safe is not deployed we can use the singleton address to simulate
|
|
360
|
+
const to = isSafeDeployed ? safeAddress : safeSingletonContract.getAddress();
|
|
361
|
+
const safeFunctionToEstimate = safeSingletonContract.encode('simulateAndRevert', [
|
|
362
|
+
await simulateTxAccessorContract.getAddress(),
|
|
363
|
+
transactionDataToEstimate
|
|
364
|
+
]);
|
|
365
|
+
const transactionToEstimateGas = {
|
|
366
|
+
to,
|
|
367
|
+
value: '0',
|
|
368
|
+
data: safeFunctionToEstimate,
|
|
369
|
+
from: safeAddress
|
|
370
|
+
};
|
|
371
|
+
try {
|
|
372
|
+
const encodedResponse = await ethAdapter.call(transactionToEstimateGas);
|
|
373
|
+
const safeTxGas = decodeSafeTxGas(encodedResponse);
|
|
374
|
+
return safeTxGas;
|
|
375
|
+
// if the call throws an error we try to parse the returned value
|
|
376
|
+
}
|
|
377
|
+
catch (error) {
|
|
378
|
+
return parseSafeTxGasErrorResponse(error);
|
|
379
|
+
}
|
|
380
|
+
return '0';
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* This function estimates the gas cost of deploying a Safe.
|
|
384
|
+
* It considers also the costs of the Safe setup call.
|
|
385
|
+
* The setup call includes tasks such as setting up initial owners, defining the threshold, and initializing the salt nonce used for address generation.
|
|
386
|
+
*
|
|
387
|
+
* @async
|
|
388
|
+
* @function estimateSafeDeploymentGas
|
|
389
|
+
* @param {Safe} safe - The Safe object containing all necessary information about the safe, including owners, threshold, and saltNonce.
|
|
390
|
+
* @returns {Promise<string>} A Promise that resolves with the estimated gas cost of the safe deployment as a string.
|
|
391
|
+
*/
|
|
392
|
+
async function estimateSafeDeploymentGas(safe) {
|
|
393
|
+
const isSafeDeployed = await safe.isSafeDeployed();
|
|
394
|
+
if (isSafeDeployed) {
|
|
395
|
+
return '0';
|
|
396
|
+
}
|
|
397
|
+
const ethAdapter = safe.getEthAdapter();
|
|
398
|
+
const safeDeploymentTransaction = await safe.createSafeDeploymentTransaction();
|
|
399
|
+
const estimation = await ethAdapter.estimateGas({
|
|
400
|
+
...safeDeploymentTransaction,
|
|
401
|
+
from: constants_1.ZERO_ADDRESS // if we use the Safe address the estimation always fails due to CREATE2
|
|
402
|
+
});
|
|
403
|
+
return estimation;
|
|
404
|
+
}
|
|
405
|
+
exports.estimateSafeDeploymentGas = estimateSafeDeploymentGas;
|
|
130
406
|
//# sourceMappingURL=gas.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gas.js","sourceRoot":"","sources":["../../../../src/utils/transactions/gas.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gas.js","sourceRoot":"","sources":["../../../../src/utils/transactions/gas.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAoD;AACpD,0EAMyC;AACzC,2EAAwD;AAGxD,4CAA2C;AAC3C,qFAGgD;AAEhD,kCAAkC;AAClC,MAAM,4BAA4B,GAAG,CAAC,CAAA;AAEtC,uDAAuD;AACvD,MAAM,uBAAuB,GAAG,EAAE,CAAA;AAElC,oCAAoC;AACpC,MAAM,oBAAoB,GAAG,KAAM,CAAA;AAEnC,2BAA2B;AAC3B,MAAM,wBAAwB,GAAG,IAAK,CAAA;AAEtC,uDAAuD;AACvD,MAAM,wBAAwB,GAAG,IAAK,CAAA;AAEtC,oDAAoD;AACpD,MAAM,kBAAkB,GAAG,IAAK,CAAA;AAEhC,oBAAoB;AACpB,MAAM,kBAAkB,GAAG,KAAM,CAAA;AAEjC,iFAAiF;AACjF,mFAAmF;AACnF,+BAA+B;AAC/B,mEAAmE;AACnE,MAAM,sBAAsB,GAC1B,CAAC,GAAG,uBAAuB,GAAG,CAAC,GAAG,EAAE,GAAG,uBAAuB,GAAG,kBAAkB,CAAA;AAErF,SAAS,oBAAoB,CAAC,IAAY;IACxC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAa,CAAA;IAE7C,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,OAAe,EAAE,WAAmB,EAAE,EAAE;QAC3D,IAAI,WAAW,KAAK,IAAI,EAAE;YACxB,OAAO,OAAO,GAAG,CAAC,CAAA;SACnB;QAED,IAAI,WAAW,KAAK,IAAI,EAAE;YACxB,OAAO,OAAO,GAAG,4BAA4B,CAAA;SAC9C;QAED,OAAO,OAAO,GAA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