@safe-global/relay-kit 1.3.0 → 2.0.0-alpha.1
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/dist/src/RelayKitBasePack.d.ts +33 -0
- package/dist/src/RelayKitBasePack.js +15 -0
- package/dist/src/RelayKitBasePack.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/packs/gelato/GelatoRelayPack.d.ts +13 -14
- package/dist/src/packs/gelato/GelatoRelayPack.js +42 -43
- package/dist/src/packs/gelato/GelatoRelayPack.js.map +1 -1
- package/dist/src/packs/gelato/GelatoRelayPack.test.js +25 -28
- package/dist/src/packs/gelato/GelatoRelayPack.test.js.map +1 -1
- package/dist/src/packs/gelato/types.d.ts +5 -0
- package/dist/src/packs/gelato/types.js +3 -0
- package/dist/src/packs/gelato/types.js.map +1 -0
- package/dist/src/types.d.ts +2 -13
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -5
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import Safe from '@safe-global/protocol-kit';
|
|
2
|
+
import { MetaTransactionOptions, SafeTransaction } from '@safe-global/safe-core-sdk-types';
|
|
3
|
+
import { RelayKitTransaction } from './types';
|
|
4
|
+
export declare abstract class RelayKitBasePack {
|
|
5
|
+
protocolKit: Safe;
|
|
6
|
+
/**
|
|
7
|
+
* The packs implemented using our SDK should extend this class and therefore provide a Safe SDK instance
|
|
8
|
+
* @constructor
|
|
9
|
+
* @param protocolKit The Safe SDK instance
|
|
10
|
+
*/
|
|
11
|
+
constructor(protocolKit: Safe);
|
|
12
|
+
/**
|
|
13
|
+
* Get an estimation of the fee that will be paid for a transaction
|
|
14
|
+
* @param chainId The chain id
|
|
15
|
+
* @param gasLimit Max amount of gas willing to consume
|
|
16
|
+
* @param gasToken Token address (or 0 if ETH) that is used for the payment
|
|
17
|
+
*/
|
|
18
|
+
abstract getEstimateFee(chainId: bigint, gasLimit: string, gasToken?: string): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a Safe transaction designed to be executed using the relayer.
|
|
21
|
+
* @param {RelayKitTransaction} RelayKitTransaction - Properties required to create the transaction.
|
|
22
|
+
* @returns {Promise<SafeTransaction>} - Returns a Promise that resolves with a SafeTransaction object.
|
|
23
|
+
*/
|
|
24
|
+
abstract createRelayedTransaction({ transactions, options, onlyCalls }: RelayKitTransaction): Promise<SafeTransaction>;
|
|
25
|
+
/**
|
|
26
|
+
* Sends the Safe transaction to the relayer for execution.
|
|
27
|
+
* If the Safe is not deployed, it creates a batch of transactions including the Safe deployment transaction.
|
|
28
|
+
* @param {SafeTransaction} safeTransaction - The Safe transaction to be executed
|
|
29
|
+
* @param {MetaTransactionOptions} options - The transaction options
|
|
30
|
+
* @returns {Promise<RelayResponse>} Returns a Promise that resolves with a RelayResponse object.
|
|
31
|
+
*/
|
|
32
|
+
abstract executeRelayTransaction(safeTransaction: SafeTransaction, options?: MetaTransactionOptions): Promise<unknown>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelayKitBasePack = void 0;
|
|
4
|
+
class RelayKitBasePack {
|
|
5
|
+
/**
|
|
6
|
+
* The packs implemented using our SDK should extend this class and therefore provide a Safe SDK instance
|
|
7
|
+
* @constructor
|
|
8
|
+
* @param protocolKit The Safe SDK instance
|
|
9
|
+
*/
|
|
10
|
+
constructor(protocolKit) {
|
|
11
|
+
this.protocolKit = protocolKit;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.RelayKitBasePack = RelayKitBasePack;
|
|
15
|
+
//# sourceMappingURL=RelayKitBasePack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RelayKitBasePack.js","sourceRoot":"","sources":["../../src/RelayKitBasePack.ts"],"names":[],"mappings":";;;AAKA,MAAsB,gBAAgB;IAGpC;;;;OAIG;IACH,YAAY,WAAiB;QAC3B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IAChC,CAAC;CAgCF;AA1CD,4CA0CC"}
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -15,5 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./packs/gelato/GelatoRelayPack"), exports);
|
|
18
|
+
__exportStar(require("./packs/gelato/types"), exports);
|
|
19
|
+
__exportStar(require("./RelayKitBasePack"), exports);
|
|
18
20
|
__exportStar(require("./types"), exports);
|
|
19
21
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iEAA8C;AAC9C,0CAAuB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iEAA8C;AAC9C,uDAAoC;AAEpC,qDAAkC;AAClC,0CAAuB"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { RelayResponse, TransactionStatusResponse } from '@gelatonetwork/relay-sdk';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import { RelayKitBasePack } from '../../RelayKitBasePack';
|
|
3
|
+
import { RelayKitTransaction } from '../../types';
|
|
4
4
|
import { MetaTransactionOptions, RelayTransaction, SafeTransaction } from '@safe-global/safe-core-sdk-types';
|
|
5
|
-
|
|
5
|
+
import { GelatoOptions } from './types';
|
|
6
|
+
export declare class GelatoRelayPack extends RelayKitBasePack {
|
|
6
7
|
#private;
|
|
7
|
-
constructor(apiKey
|
|
8
|
+
constructor({ apiKey, protocolKit }: GelatoOptions);
|
|
8
9
|
private _getFeeToken;
|
|
9
10
|
getFeeCollector(): string;
|
|
10
|
-
getEstimateFee(chainId:
|
|
11
|
+
getEstimateFee(chainId: bigint, gasLimit: string, gasToken?: string): Promise<string>;
|
|
11
12
|
getTaskStatus(taskId: string): Promise<TransactionStatusResponse | undefined>;
|
|
12
13
|
/**
|
|
13
14
|
* Creates a payment transaction to Gelato
|
|
@@ -15,7 +16,6 @@ export declare class GelatoRelayPack implements RelayPack {
|
|
|
15
16
|
* @private
|
|
16
17
|
* @async
|
|
17
18
|
* @function
|
|
18
|
-
* @param {Safe} safe - The Safe object
|
|
19
19
|
* @param {string} gas - The gas amount for the payment.
|
|
20
20
|
* @param {MetaTransactionOptions} options - Options for the meta transaction.
|
|
21
21
|
* @returns {Promise<Transaction>} Promise object representing the created payment transaction.
|
|
@@ -25,10 +25,10 @@ export declare class GelatoRelayPack implements RelayPack {
|
|
|
25
25
|
/**
|
|
26
26
|
* Creates a Safe transaction designed to be executed using the Gelato Relayer.
|
|
27
27
|
*
|
|
28
|
-
* @param {
|
|
28
|
+
* @param {RelayKitTransaction} RelayKitTransaction - Properties required to create the transaction.
|
|
29
29
|
* @returns {Promise<SafeTransaction>} Returns a Promise that resolves with a SafeTransaction object.
|
|
30
30
|
*/
|
|
31
|
-
createRelayedTransaction({
|
|
31
|
+
createRelayedTransaction({ transactions, onlyCalls, options }: RelayKitTransaction): Promise<SafeTransaction>;
|
|
32
32
|
/**
|
|
33
33
|
* Creates a Safe transaction designed to be executed using the Gelato Relayer and
|
|
34
34
|
* uses the handlePayment function defined in the Safe contract to pay the fees
|
|
@@ -36,7 +36,7 @@ export declare class GelatoRelayPack implements RelayPack {
|
|
|
36
36
|
*
|
|
37
37
|
* @async
|
|
38
38
|
* @function createTransactionWithHandlePayment
|
|
39
|
-
* @param {
|
|
39
|
+
* @param {RelayKitTransaction} RelayKitTransaction - Properties needed to create the transaction.
|
|
40
40
|
* @returns {Promise<SafeTransaction>} Returns a promise that resolves to the created SafeTransaction.
|
|
41
41
|
* @private
|
|
42
42
|
*/
|
|
@@ -47,21 +47,20 @@ export declare class GelatoRelayPack implements RelayPack {
|
|
|
47
47
|
*
|
|
48
48
|
* @async
|
|
49
49
|
* @function createTransactionWithTransfer
|
|
50
|
-
* @param {
|
|
50
|
+
* @param {RelayKitTransaction} RelayKitTransaction - Properties needed to create the transaction.
|
|
51
51
|
* @returns {Promise<SafeTransaction>} Returns a promise that resolves to the created SafeTransaction.
|
|
52
52
|
* @private
|
|
53
53
|
*/
|
|
54
54
|
private createTransactionWithTransfer;
|
|
55
|
-
sendSponsorTransaction(target: string, encodedTransaction: string, chainId:
|
|
56
|
-
sendSyncTransaction(target: string, encodedTransaction: string, chainId:
|
|
55
|
+
sendSponsorTransaction(target: string, encodedTransaction: string, chainId: bigint): Promise<RelayResponse>;
|
|
56
|
+
sendSyncTransaction(target: string, encodedTransaction: string, chainId: bigint, options: MetaTransactionOptions): Promise<RelayResponse>;
|
|
57
57
|
relayTransaction({ target, encodedTransaction, chainId, options }: RelayTransaction): Promise<RelayResponse>;
|
|
58
58
|
/**
|
|
59
59
|
* Sends the Safe transaction to the Gelato Relayer for execution.
|
|
60
60
|
* If the Safe is not deployed, it creates a batch of transactions including the Safe deployment transaction.
|
|
61
61
|
*
|
|
62
62
|
* @param {SafeTransaction} safeTransaction - The Safe transaction to be executed.
|
|
63
|
-
* @param {Safe} safe - The Safe object related to the transaction.
|
|
64
63
|
* @returns {Promise<RelayResponse>} Returns a Promise that resolves with a RelayResponse object.
|
|
65
64
|
*/
|
|
66
|
-
executeRelayTransaction(safeTransaction: SafeTransaction,
|
|
65
|
+
executeRelayTransaction(safeTransaction: SafeTransaction, options?: MetaTransactionOptions): Promise<RelayResponse>;
|
|
67
66
|
}
|
|
@@ -13,12 +13,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
13
13
|
var _GelatoRelayPack_gelatoRelay, _GelatoRelayPack_apiKey;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.GelatoRelayPack = void 0;
|
|
16
|
-
const bignumber_1 = require("@ethersproject/bignumber");
|
|
17
16
|
const relay_sdk_1 = require("@gelatonetwork/relay-sdk");
|
|
18
17
|
const protocol_kit_1 = require("@safe-global/protocol-kit");
|
|
18
|
+
const RelayKitBasePack_1 = require("../../RelayKitBasePack");
|
|
19
19
|
const constants_1 = require("../../constants");
|
|
20
|
-
class GelatoRelayPack {
|
|
21
|
-
constructor(apiKey) {
|
|
20
|
+
class GelatoRelayPack extends RelayKitBasePack_1.RelayKitBasePack {
|
|
21
|
+
constructor({ apiKey, protocolKit }) {
|
|
22
|
+
super(protocolKit);
|
|
22
23
|
_GelatoRelayPack_gelatoRelay.set(this, void 0);
|
|
23
24
|
_GelatoRelayPack_apiKey.set(this, void 0);
|
|
24
25
|
__classPrivateFieldSet(this, _GelatoRelayPack_gelatoRelay, new relay_sdk_1.GelatoRelay(), "f");
|
|
@@ -32,7 +33,7 @@ class GelatoRelayPack {
|
|
|
32
33
|
}
|
|
33
34
|
async getEstimateFee(chainId, gasLimit, gasToken) {
|
|
34
35
|
const feeToken = this._getFeeToken(gasToken);
|
|
35
|
-
const estimation = await __classPrivateFieldGet(this, _GelatoRelayPack_gelatoRelay, "f").getEstimatedFee(chainId, feeToken,
|
|
36
|
+
const estimation = await __classPrivateFieldGet(this, _GelatoRelayPack_gelatoRelay, "f").getEstimatedFee(chainId, feeToken, BigInt(gasLimit), false);
|
|
36
37
|
return estimation.toString();
|
|
37
38
|
}
|
|
38
39
|
async getTaskStatus(taskId) {
|
|
@@ -44,14 +45,13 @@ class GelatoRelayPack {
|
|
|
44
45
|
* @private
|
|
45
46
|
* @async
|
|
46
47
|
* @function
|
|
47
|
-
* @param {Safe} safe - The Safe object
|
|
48
48
|
* @param {string} gas - The gas amount for the payment.
|
|
49
49
|
* @param {MetaTransactionOptions} options - Options for the meta transaction.
|
|
50
50
|
* @returns {Promise<Transaction>} Promise object representing the created payment transaction.
|
|
51
51
|
*
|
|
52
52
|
*/
|
|
53
|
-
async createPaymentToGelato(
|
|
54
|
-
const chainId = await
|
|
53
|
+
async createPaymentToGelato(gas, options) {
|
|
54
|
+
const chainId = await this.protocolKit.getChainId();
|
|
55
55
|
const gelatoAddress = this.getFeeCollector();
|
|
56
56
|
const gasToken = options.gasToken ?? constants_1.ZERO_ADDRESS;
|
|
57
57
|
const paymentToGelato = await this.getEstimateFee(chainId, gas, gasToken);
|
|
@@ -62,14 +62,14 @@ class GelatoRelayPack {
|
|
|
62
62
|
/**
|
|
63
63
|
* Creates a Safe transaction designed to be executed using the Gelato Relayer.
|
|
64
64
|
*
|
|
65
|
-
* @param {
|
|
65
|
+
* @param {RelayKitTransaction} RelayKitTransaction - Properties required to create the transaction.
|
|
66
66
|
* @returns {Promise<SafeTransaction>} Returns a Promise that resolves with a SafeTransaction object.
|
|
67
67
|
*/
|
|
68
|
-
async createRelayedTransaction({
|
|
68
|
+
async createRelayedTransaction({ transactions, onlyCalls = false, options = {} }) {
|
|
69
69
|
const { isSponsored = false } = options;
|
|
70
70
|
if (isSponsored) {
|
|
71
|
-
const nonce = await
|
|
72
|
-
const sponsoredTransaction = await
|
|
71
|
+
const nonce = await this.protocolKit.getNonce();
|
|
72
|
+
const sponsoredTransaction = await this.protocolKit.createTransaction({
|
|
73
73
|
safeTransactionData: transactions,
|
|
74
74
|
onlyCalls,
|
|
75
75
|
options: {
|
|
@@ -80,13 +80,13 @@ class GelatoRelayPack {
|
|
|
80
80
|
}
|
|
81
81
|
// If the ERC20 gas token does not follow the standard 18 decimals, we cannot use handlePayment to pay Gelato fees.
|
|
82
82
|
const gasToken = options.gasToken ?? constants_1.ZERO_ADDRESS;
|
|
83
|
-
const isGasTokenCompatible = await (0, protocol_kit_1.isGasTokenCompatibleWithHandlePayment)(gasToken,
|
|
83
|
+
const isGasTokenCompatible = await (0, protocol_kit_1.isGasTokenCompatibleWithHandlePayment)(gasToken, this.protocolKit);
|
|
84
84
|
if (!isGasTokenCompatible) {
|
|
85
85
|
// if the ERC20 gas token is not compatible (less than 18 decimals like USDC), a separate transfer is required to pay Gelato fees.
|
|
86
|
-
return this.createTransactionWithTransfer({
|
|
86
|
+
return this.createTransactionWithTransfer({ transactions, onlyCalls, options });
|
|
87
87
|
}
|
|
88
88
|
// If the gas token is compatible (Native token or standard ERC20), we use handlePayment function present in the Safe contract to pay Gelato fees
|
|
89
|
-
return this.createTransactionWithHandlePayment({
|
|
89
|
+
return this.createTransactionWithHandlePayment({ transactions, onlyCalls, options });
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
92
|
* Creates a Safe transaction designed to be executed using the Gelato Relayer and
|
|
@@ -95,15 +95,15 @@ class GelatoRelayPack {
|
|
|
95
95
|
*
|
|
96
96
|
* @async
|
|
97
97
|
* @function createTransactionWithHandlePayment
|
|
98
|
-
* @param {
|
|
98
|
+
* @param {RelayKitTransaction} RelayKitTransaction - Properties needed to create the transaction.
|
|
99
99
|
* @returns {Promise<SafeTransaction>} Returns a promise that resolves to the created SafeTransaction.
|
|
100
100
|
* @private
|
|
101
101
|
*/
|
|
102
|
-
async createTransactionWithHandlePayment({
|
|
102
|
+
async createTransactionWithHandlePayment({ transactions, onlyCalls = false, options = {} }) {
|
|
103
103
|
const { gasLimit } = options;
|
|
104
|
-
const nonce = await
|
|
104
|
+
const nonce = await this.protocolKit.getNonce();
|
|
105
105
|
// this transaction is only used for gas estimations
|
|
106
|
-
const transactionToEstimateGas = await
|
|
106
|
+
const transactionToEstimateGas = await this.protocolKit.createTransaction({
|
|
107
107
|
safeTransactionData: transactions,
|
|
108
108
|
onlyCalls,
|
|
109
109
|
options: {
|
|
@@ -112,14 +112,14 @@ class GelatoRelayPack {
|
|
|
112
112
|
});
|
|
113
113
|
// as we set gasPrice to 1, safeTxGas is set to a non-zero value to prevent transaction failure due to out-of-gas errors. value see: https://github.com/safe-global/safe-contracts/blob/main/contracts/Safe.sol#L203
|
|
114
114
|
const gasPrice = '1';
|
|
115
|
-
const safeTxGas = await (0, protocol_kit_1.estimateSafeTxGas)(
|
|
115
|
+
const safeTxGas = await (0, protocol_kit_1.estimateSafeTxGas)(this.protocolKit, transactionToEstimateGas);
|
|
116
116
|
const gasToken = options.gasToken ?? constants_1.ZERO_ADDRESS;
|
|
117
117
|
const refundReceiver = this.getFeeCollector();
|
|
118
|
-
const chainId = await
|
|
118
|
+
const chainId = await this.protocolKit.getChainId();
|
|
119
119
|
// if a custom gasLimit is provided, we do not need to estimate the gas cost
|
|
120
120
|
if (gasLimit) {
|
|
121
121
|
const paymentToGelato = await this.getEstimateFee(chainId, gasLimit, gasToken);
|
|
122
|
-
const syncTransaction = await
|
|
122
|
+
const syncTransaction = await this.protocolKit.createTransaction({
|
|
123
123
|
safeTransactionData: transactions,
|
|
124
124
|
onlyCalls,
|
|
125
125
|
options: {
|
|
@@ -134,14 +134,14 @@ class GelatoRelayPack {
|
|
|
134
134
|
return syncTransaction;
|
|
135
135
|
}
|
|
136
136
|
// If gasLimit is not provided, we need to estimate the gas cost.
|
|
137
|
-
const baseGas = await (0, protocol_kit_1.estimateTxBaseGas)(
|
|
138
|
-
const safeDeploymentGasCost = await (0, protocol_kit_1.estimateSafeDeploymentGas)(
|
|
137
|
+
const baseGas = await (0, protocol_kit_1.estimateTxBaseGas)(this.protocolKit, transactionToEstimateGas);
|
|
138
|
+
const safeDeploymentGasCost = await (0, protocol_kit_1.estimateSafeDeploymentGas)(this.protocolKit);
|
|
139
139
|
const totalGas = Number(baseGas) + // baseGas
|
|
140
140
|
Number(safeTxGas) + // safeTxGas
|
|
141
141
|
Number(safeDeploymentGasCost) + // Safe deploymet gas cost if it is required
|
|
142
142
|
constants_1.GELATO_GAS_EXECUTION_OVERHEAD; // Gelato execution overhead
|
|
143
143
|
const paymentToGelato = await this.getEstimateFee(chainId, String(totalGas), gasToken);
|
|
144
|
-
const syncTransaction = await
|
|
144
|
+
const syncTransaction = await this.protocolKit.createTransaction({
|
|
145
145
|
safeTransactionData: transactions,
|
|
146
146
|
onlyCalls,
|
|
147
147
|
options: {
|
|
@@ -161,18 +161,18 @@ class GelatoRelayPack {
|
|
|
161
161
|
*
|
|
162
162
|
* @async
|
|
163
163
|
* @function createTransactionWithTransfer
|
|
164
|
-
* @param {
|
|
164
|
+
* @param {RelayKitTransaction} RelayKitTransaction - Properties needed to create the transaction.
|
|
165
165
|
* @returns {Promise<SafeTransaction>} Returns a promise that resolves to the created SafeTransaction.
|
|
166
166
|
* @private
|
|
167
167
|
*/
|
|
168
|
-
async createTransactionWithTransfer({
|
|
168
|
+
async createTransactionWithTransfer({ transactions, onlyCalls = false, options = {} }) {
|
|
169
169
|
const { gasLimit } = options;
|
|
170
|
-
const nonce = await
|
|
170
|
+
const nonce = await this.protocolKit.getNonce();
|
|
171
171
|
const gasToken = options.gasToken ?? constants_1.ZERO_ADDRESS;
|
|
172
172
|
// if a custom gasLimit is provided, we do not need to estimate the gas cost
|
|
173
173
|
if (gasLimit) {
|
|
174
|
-
const transferToGelato = await this.createPaymentToGelato(
|
|
175
|
-
const syncTransaction = await
|
|
174
|
+
const transferToGelato = await this.createPaymentToGelato(gasLimit, options);
|
|
175
|
+
const syncTransaction = await this.protocolKit.createTransaction({
|
|
176
176
|
safeTransactionData: [...transactions, transferToGelato],
|
|
177
177
|
onlyCalls,
|
|
178
178
|
options: {
|
|
@@ -184,23 +184,23 @@ class GelatoRelayPack {
|
|
|
184
184
|
}
|
|
185
185
|
// If gasLimit is not provided, we need to estimate the gas cost.
|
|
186
186
|
// this transaction is only used for gas estimations
|
|
187
|
-
const transactionToEstimateGas = await
|
|
187
|
+
const transactionToEstimateGas = await this.protocolKit.createTransaction({
|
|
188
188
|
safeTransactionData: transactions,
|
|
189
189
|
onlyCalls,
|
|
190
190
|
options: {
|
|
191
191
|
nonce
|
|
192
192
|
}
|
|
193
193
|
});
|
|
194
|
-
const safeTxGas = await (0, protocol_kit_1.estimateSafeTxGas)(
|
|
195
|
-
const baseGas = await (0, protocol_kit_1.estimateTxBaseGas)(
|
|
196
|
-
const safeDeploymentGasCost = await (0, protocol_kit_1.estimateSafeDeploymentGas)(
|
|
194
|
+
const safeTxGas = await (0, protocol_kit_1.estimateSafeTxGas)(this.protocolKit, transactionToEstimateGas);
|
|
195
|
+
const baseGas = await (0, protocol_kit_1.estimateTxBaseGas)(this.protocolKit, transactionToEstimateGas);
|
|
196
|
+
const safeDeploymentGasCost = await (0, protocol_kit_1.estimateSafeDeploymentGas)(this.protocolKit);
|
|
197
197
|
const totalGas = Number(baseGas) + // baseGas
|
|
198
198
|
Number(safeTxGas) + // safeTxGas without Gelato payment transfer
|
|
199
199
|
Number(safeDeploymentGasCost) + // Safe deploymet gas cost if it is required
|
|
200
200
|
constants_1.GELATO_TRANSFER_GAS_COST + // Gelato payment transfer
|
|
201
201
|
constants_1.GELATO_GAS_EXECUTION_OVERHEAD; // Gelato execution overhead
|
|
202
|
-
const transferToGelato = await this.createPaymentToGelato(
|
|
203
|
-
const syncTransaction = await
|
|
202
|
+
const transferToGelato = await this.createPaymentToGelato(String(totalGas), options);
|
|
203
|
+
const syncTransaction = await this.protocolKit.createTransaction({
|
|
204
204
|
safeTransactionData: [...transactions, transferToGelato],
|
|
205
205
|
onlyCalls,
|
|
206
206
|
options: {
|
|
@@ -233,7 +233,7 @@ class GelatoRelayPack {
|
|
|
233
233
|
isRelayContext: false
|
|
234
234
|
};
|
|
235
235
|
const relayRequestOptions = {
|
|
236
|
-
gasLimit
|
|
236
|
+
gasLimit: gasLimit ? BigInt(gasLimit) : undefined
|
|
237
237
|
};
|
|
238
238
|
const response = await __classPrivateFieldGet(this, _GelatoRelayPack_gelatoRelay, "f").callWithSyncFee(request, relayRequestOptions);
|
|
239
239
|
return response;
|
|
@@ -249,14 +249,13 @@ class GelatoRelayPack {
|
|
|
249
249
|
* If the Safe is not deployed, it creates a batch of transactions including the Safe deployment transaction.
|
|
250
250
|
*
|
|
251
251
|
* @param {SafeTransaction} safeTransaction - The Safe transaction to be executed.
|
|
252
|
-
* @param {Safe} safe - The Safe object related to the transaction.
|
|
253
252
|
* @returns {Promise<RelayResponse>} Returns a Promise that resolves with a RelayResponse object.
|
|
254
253
|
*/
|
|
255
|
-
async executeRelayTransaction(safeTransaction,
|
|
256
|
-
const isSafeDeployed = await
|
|
257
|
-
const chainId = await
|
|
258
|
-
const safeAddress = await
|
|
259
|
-
const safeTransactionEncodedData = await
|
|
254
|
+
async executeRelayTransaction(safeTransaction, options) {
|
|
255
|
+
const isSafeDeployed = await this.protocolKit.isSafeDeployed();
|
|
256
|
+
const chainId = await this.protocolKit.getChainId();
|
|
257
|
+
const safeAddress = await this.protocolKit.getAddress();
|
|
258
|
+
const safeTransactionEncodedData = await this.protocolKit.getEncodedTransaction(safeTransaction);
|
|
260
259
|
const gasToken = options?.gasToken || safeTransaction.data.gasToken;
|
|
261
260
|
if (isSafeDeployed) {
|
|
262
261
|
const relayTransaction = {
|
|
@@ -271,7 +270,7 @@ class GelatoRelayPack {
|
|
|
271
270
|
return this.relayTransaction(relayTransaction);
|
|
272
271
|
}
|
|
273
272
|
// if the Safe is not deployed we create a batch with the Safe deployment transaction and the provided Safe transaction
|
|
274
|
-
const safeDeploymentBatch = await
|
|
273
|
+
const safeDeploymentBatch = await this.protocolKit.wrapSafeTransactionIntoDeploymentBatch(safeTransaction);
|
|
275
274
|
const relayTransaction = {
|
|
276
275
|
target: safeDeploymentBatch.to,
|
|
277
276
|
encodedTransaction: safeDeploymentBatch.data,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GelatoRelayPack.js","sourceRoot":"","sources":["../../../../src/packs/gelato/GelatoRelayPack.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"GelatoRelayPack.js","sourceRoot":"","sources":["../../../../src/packs/gelato/GelatoRelayPack.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,wDAOiC;AACjC,4DAMkC;AAClC,8EAA0E;AAC1E,g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,eAAgC,EAChC,OAAgC;QAEhC,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,cAAc,EAAE,CAAA;QAC9D,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,CAAA;QACnD,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,CAAA;QACvD,MAAM,0BAA0B,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,qBAAqB,CAAC,eAAe,CAAC,CAAA;QAEhG,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAA;QAEnE,IAAI,cAAc,EAAE;YAClB,MAAM,gBAAgB,GAAqB;gBACzC,MAAM,EAAE,WAAW;gBACnB,kBAAkB,EAAE,0BAA0B;gBAC9C,OAAO;gBACP,OAAO,EAAE;oBACP,GAAG,OAAO;oBACV,QAAQ;iBACT;aACF,CAAA;YAED,OAAO,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAA;SAC/C;QAED,uHAAuH;QACvH,MAAM,mBAAmB,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,sCAAsC,CACvF,eAAe,CAChB,CAAA;QAED,MAAM,gBAAgB,GAAqB;YACzC,MAAM,EAAE,mBAAmB,CAAC,EAAE;YAC9B,kBAAkB,EAAE,mBAAmB,CAAC,IAAI;YAC5C,OAAO;YACP,OAAO,EAAE;gBACP,GAAG,OAAO;gBACV,QAAQ;aACT;SACF,CAAA;QAED,OAAO,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAA;IAChD,CAAC;CACF;AA7WD,0CA6WC"}
|
|
@@ -23,7 +23,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const bignumber_1 = require("@ethersproject/bignumber");
|
|
27
26
|
const protocol_kit_1 = __importStar(require("@safe-global/protocol-kit"));
|
|
28
27
|
const safe_core_sdk_types_1 = require("@safe-global/safe-core-sdk-types");
|
|
29
28
|
const constants_1 = require("../../constants");
|
|
@@ -32,18 +31,18 @@ var TaskState;
|
|
|
32
31
|
(function (TaskState) {
|
|
33
32
|
TaskState["CheckPending"] = "CheckPending";
|
|
34
33
|
})(TaskState || (TaskState = {}));
|
|
35
|
-
const CHAIN_ID =
|
|
34
|
+
const CHAIN_ID = 1n;
|
|
36
35
|
const ADDRESS = '0x...address';
|
|
37
36
|
const GAS_TOKEN = '0x...gasToken';
|
|
38
37
|
const SAFE_ADDRESS = '0x...safe-address';
|
|
39
38
|
const API_KEY = 'api-key';
|
|
40
|
-
const FEE_ESTIMATION =
|
|
39
|
+
const FEE_ESTIMATION = BigInt(100000);
|
|
41
40
|
const BASEGAS_ESTIMATION = '20000';
|
|
42
41
|
const SAFETXGAS_ESTIMATION = '10000';
|
|
43
42
|
const SAFE_DEPLOYMENT_GAS_ESTIMATION = '30000';
|
|
44
43
|
const TASK_ID = 'task-id';
|
|
45
44
|
const TASK_STATUS = {
|
|
46
|
-
chainId: CHAIN_ID,
|
|
45
|
+
chainId: Number(CHAIN_ID),
|
|
47
46
|
taskState: TaskState.CheckPending,
|
|
48
47
|
taskId: TASK_ID,
|
|
49
48
|
creationDate: Date.now().toString()
|
|
@@ -96,7 +95,8 @@ jest.doMock('@safe-global/protocol-kit', () => ({
|
|
|
96
95
|
createERC20TokenTransferTransaction: mockCreateERC20TokenTransferTransaction,
|
|
97
96
|
isGasTokenCompatibleWithHandlePayment: mockedIsGasTokenCompatibleWithHandlePayment
|
|
98
97
|
}));
|
|
99
|
-
const
|
|
98
|
+
const safe = new protocol_kit_1.default();
|
|
99
|
+
const gelatoRelayPack = new GelatoRelayPack_1.GelatoRelayPack({ apiKey: API_KEY, protocolKit: safe });
|
|
100
100
|
describe('GelatoRelayPack', () => {
|
|
101
101
|
beforeEach(() => {
|
|
102
102
|
jest.clearAllMocks();
|
|
@@ -105,13 +105,13 @@ describe('GelatoRelayPack', () => {
|
|
|
105
105
|
mockEstimateSafeDeploymentGas.mockResolvedValue(Promise.resolve(SAFE_DEPLOYMENT_GAS_ESTIMATION));
|
|
106
106
|
});
|
|
107
107
|
it('should allow to get a fee estimation', async () => {
|
|
108
|
-
const chainId =
|
|
108
|
+
const chainId = 1n;
|
|
109
109
|
const gasLimit = '100000';
|
|
110
110
|
const gasToken = '0x0000000000000000000000000000000000000000';
|
|
111
111
|
const estimation = await gelatoRelayPack.getEstimateFee(chainId, gasLimit, gasToken);
|
|
112
112
|
expect(estimation).toBe(FEE_ESTIMATION.toString());
|
|
113
|
-
expect(mockGetEstimateFee).toHaveBeenCalledWith(chainId, constants_1.GELATO_NATIVE_TOKEN_ADDRESS,
|
|
114
|
-
expect(
|
|
113
|
+
expect(mockGetEstimateFee).toHaveBeenCalledWith(chainId, constants_1.GELATO_NATIVE_TOKEN_ADDRESS, BigInt(gasLimit), false);
|
|
114
|
+
expect(BigInt(estimation) > 0).toBe(true);
|
|
115
115
|
});
|
|
116
116
|
it('should allow to check the task status', async () => {
|
|
117
117
|
const taskId = 'task-id';
|
|
@@ -129,13 +129,12 @@ describe('GelatoRelayPack', () => {
|
|
|
129
129
|
}, API_KEY);
|
|
130
130
|
});
|
|
131
131
|
it('should throw an error when trying to do a sponsored transaction without an api key', async () => {
|
|
132
|
-
const relayPack = new GelatoRelayPack_1.GelatoRelayPack();
|
|
132
|
+
const relayPack = new GelatoRelayPack_1.GelatoRelayPack({ protocolKit: safe });
|
|
133
133
|
await expect(relayPack.sendSponsorTransaction(SAFE_ADDRESS, '0x', CHAIN_ID)).rejects.toThrowError('API key not defined');
|
|
134
134
|
});
|
|
135
135
|
describe('when creating a relayed transaction', () => {
|
|
136
136
|
describe('When gas limit is manually defined', () => {
|
|
137
137
|
let relayPack;
|
|
138
|
-
const safe = new protocol_kit_1.default();
|
|
139
138
|
const transactions = [
|
|
140
139
|
{
|
|
141
140
|
to: ADDRESS,
|
|
@@ -149,14 +148,15 @@ describe('GelatoRelayPack', () => {
|
|
|
149
148
|
};
|
|
150
149
|
beforeEach(() => {
|
|
151
150
|
jest.clearAllMocks();
|
|
152
|
-
relayPack = new GelatoRelayPack_1.GelatoRelayPack();
|
|
151
|
+
relayPack = new GelatoRelayPack_1.GelatoRelayPack({ protocolKit: safe });
|
|
153
152
|
safe.getNonce = jest.fn().mockResolvedValue(0);
|
|
153
|
+
safe.getChainId = jest.fn().mockResolvedValue(0);
|
|
154
154
|
safe.getContractManager = jest.fn().mockReturnValue({ safeContract: {} });
|
|
155
155
|
safe.createTransaction = jest.fn().mockResolvedValue(SAFE_TRANSACTION);
|
|
156
156
|
mockedIsGasTokenCompatibleWithHandlePayment.mockResolvedValue(Promise.resolve(true));
|
|
157
157
|
});
|
|
158
158
|
it('should allow you to create a sponsored one', async () => {
|
|
159
|
-
await relayPack.createRelayedTransaction({
|
|
159
|
+
await relayPack.createRelayedTransaction({ transactions, options });
|
|
160
160
|
expect(safe.createTransaction).toHaveBeenCalledWith({
|
|
161
161
|
safeTransactionData: transactions,
|
|
162
162
|
onlyCalls: false,
|
|
@@ -167,7 +167,6 @@ describe('GelatoRelayPack', () => {
|
|
|
167
167
|
});
|
|
168
168
|
it('should allow to create a sync fee one', async () => {
|
|
169
169
|
await relayPack.createRelayedTransaction({
|
|
170
|
-
safe,
|
|
171
170
|
transactions,
|
|
172
171
|
options: { ...options, isSponsored: false }
|
|
173
172
|
});
|
|
@@ -186,7 +185,6 @@ describe('GelatoRelayPack', () => {
|
|
|
186
185
|
});
|
|
187
186
|
it('should return the correct gasToken when being sent through the options', async () => {
|
|
188
187
|
await relayPack.createRelayedTransaction({
|
|
189
|
-
safe,
|
|
190
188
|
transactions,
|
|
191
189
|
options: { ...options, isSponsored: false, gasToken: GAS_TOKEN }
|
|
192
190
|
});
|
|
@@ -217,7 +215,7 @@ describe('GelatoRelayPack', () => {
|
|
|
217
215
|
data: '0x'
|
|
218
216
|
};
|
|
219
217
|
mockCreateERC20TokenTransferTransaction.mockReturnValue(transferToGelato);
|
|
220
|
-
await relayPack.createRelayedTransaction({
|
|
218
|
+
await relayPack.createRelayedTransaction({ transactions, options });
|
|
221
219
|
expect(safe.createTransaction).toHaveBeenCalledWith({
|
|
222
220
|
safeTransactionData: [...transactions, transferToGelato],
|
|
223
221
|
onlyCalls: false,
|
|
@@ -230,7 +228,6 @@ describe('GelatoRelayPack', () => {
|
|
|
230
228
|
});
|
|
231
229
|
describe('When gas limit is automatically estimate', () => {
|
|
232
230
|
let relayPack;
|
|
233
|
-
const safe = new protocol_kit_1.default();
|
|
234
231
|
const mockTransferTransacton = {
|
|
235
232
|
to: ADDRESS,
|
|
236
233
|
data: '0x',
|
|
@@ -239,8 +236,9 @@ describe('GelatoRelayPack', () => {
|
|
|
239
236
|
const transactions = [mockTransferTransacton];
|
|
240
237
|
beforeEach(() => {
|
|
241
238
|
jest.clearAllMocks();
|
|
242
|
-
relayPack = new GelatoRelayPack_1.GelatoRelayPack();
|
|
239
|
+
relayPack = new GelatoRelayPack_1.GelatoRelayPack({ protocolKit: safe });
|
|
243
240
|
safe.getNonce = jest.fn().mockResolvedValue(0);
|
|
241
|
+
safe.getChainId = jest.fn().mockResolvedValue(0);
|
|
244
242
|
safe.getContractManager = jest.fn().mockReturnValue({ safeContract: {} });
|
|
245
243
|
safe.createTransaction = jest.fn().mockResolvedValue(SAFE_TRANSACTION);
|
|
246
244
|
mockedIsGasTokenCompatibleWithHandlePayment.mockResolvedValue(Promise.resolve(true));
|
|
@@ -249,7 +247,7 @@ describe('GelatoRelayPack', () => {
|
|
|
249
247
|
const options = {
|
|
250
248
|
isSponsored: true
|
|
251
249
|
};
|
|
252
|
-
await relayPack.createRelayedTransaction({
|
|
250
|
+
await relayPack.createRelayedTransaction({ transactions, options });
|
|
253
251
|
expect(safe.createTransaction).toHaveBeenCalledWith({
|
|
254
252
|
safeTransactionData: transactions,
|
|
255
253
|
onlyCalls: false,
|
|
@@ -264,7 +262,7 @@ describe('GelatoRelayPack', () => {
|
|
|
264
262
|
mockedIsGasTokenCompatibleWithHandlePayment.mockResolvedValue(Promise.resolve(true));
|
|
265
263
|
});
|
|
266
264
|
it('should allow you to create relay transaction using the native token to pay Gelato fees', async () => {
|
|
267
|
-
await relayPack.createRelayedTransaction({
|
|
265
|
+
await relayPack.createRelayedTransaction({ transactions });
|
|
268
266
|
expect(safe.createTransaction).toHaveBeenCalledWith({
|
|
269
267
|
safeTransactionData: transactions,
|
|
270
268
|
onlyCalls: false,
|
|
@@ -282,7 +280,7 @@ describe('GelatoRelayPack', () => {
|
|
|
282
280
|
const options = {
|
|
283
281
|
gasToken: GAS_TOKEN
|
|
284
282
|
};
|
|
285
|
-
await relayPack.createRelayedTransaction({
|
|
283
|
+
await relayPack.createRelayedTransaction({ transactions, options });
|
|
286
284
|
expect(safe.createTransaction).toHaveBeenCalledWith({
|
|
287
285
|
safeTransactionData: transactions,
|
|
288
286
|
onlyCalls: false,
|
|
@@ -312,7 +310,7 @@ describe('GelatoRelayPack', () => {
|
|
|
312
310
|
data: '0x'
|
|
313
311
|
};
|
|
314
312
|
mockCreateERC20TokenTransferTransaction.mockReturnValue(transferToGelato);
|
|
315
|
-
await relayPack.createRelayedTransaction({
|
|
313
|
+
await relayPack.createRelayedTransaction({ transactions, options });
|
|
316
314
|
expect(safe.createTransaction).toHaveBeenCalledWith({
|
|
317
315
|
safeTransactionData: [...transactions, transferToGelato],
|
|
318
316
|
onlyCalls: false,
|
|
@@ -337,7 +335,7 @@ describe('GelatoRelayPack', () => {
|
|
|
337
335
|
feeToken: constants_1.GELATO_NATIVE_TOKEN_ADDRESS,
|
|
338
336
|
isRelayContext: false
|
|
339
337
|
}, {
|
|
340
|
-
gasLimit:
|
|
338
|
+
gasLimit: BigInt(100000)
|
|
341
339
|
});
|
|
342
340
|
});
|
|
343
341
|
it('should expose a relayTransaction doing a sponsored or sync fee transaction depending on an optional parameter', async () => {
|
|
@@ -373,14 +371,13 @@ describe('GelatoRelayPack', () => {
|
|
|
373
371
|
feeToken: constants_1.GELATO_NATIVE_TOKEN_ADDRESS,
|
|
374
372
|
isRelayContext: false
|
|
375
373
|
}, {
|
|
376
|
-
gasLimit:
|
|
374
|
+
gasLimit: BigInt(100000)
|
|
377
375
|
});
|
|
378
376
|
});
|
|
379
377
|
it('should allow to retrieve the fee collector address', () => {
|
|
380
378
|
expect(gelatoRelayPack.getFeeCollector()).toBe(constants_1.GELATO_FEE_COLLECTOR);
|
|
381
379
|
});
|
|
382
380
|
describe('executeRelayTransaction', () => {
|
|
383
|
-
const safe = new protocol_kit_1.default();
|
|
384
381
|
const ENCODED_TRANSACTION_DATA = '0x...txData';
|
|
385
382
|
const MULTISEND_ADDRESS = '0x...multiSendAddress';
|
|
386
383
|
const SAFE_DEPLOYMENT_BATCH = {
|
|
@@ -411,7 +408,7 @@ describe('GelatoRelayPack', () => {
|
|
|
411
408
|
data: '0x'
|
|
412
409
|
}
|
|
413
410
|
};
|
|
414
|
-
const gelatoResponse = await gelatoRelayPack.executeRelayTransaction(relayTransaction,
|
|
411
|
+
const gelatoResponse = await gelatoRelayPack.executeRelayTransaction(relayTransaction, options);
|
|
415
412
|
expect(gelatoResponse).toBe(RELAY_RESPONSE);
|
|
416
413
|
expect(mockSponsoredCall).toHaveBeenCalledWith({
|
|
417
414
|
chainId: CHAIN_ID,
|
|
@@ -436,7 +433,7 @@ describe('GelatoRelayPack', () => {
|
|
|
436
433
|
data: '0x'
|
|
437
434
|
}
|
|
438
435
|
};
|
|
439
|
-
const gelatoResponse = await gelatoRelayPack.executeRelayTransaction(relayTransaction
|
|
436
|
+
const gelatoResponse = await gelatoRelayPack.executeRelayTransaction(relayTransaction);
|
|
440
437
|
expect(gelatoResponse).toBe(RELAY_RESPONSE);
|
|
441
438
|
expect(mockCallWithSyncFee).toHaveBeenCalledWith({
|
|
442
439
|
chainId: CHAIN_ID,
|
|
@@ -464,7 +461,7 @@ describe('GelatoRelayPack', () => {
|
|
|
464
461
|
data: '0x'
|
|
465
462
|
}
|
|
466
463
|
};
|
|
467
|
-
const gelatoResponse = await gelatoRelayPack.executeRelayTransaction(relayTransaction,
|
|
464
|
+
const gelatoResponse = await gelatoRelayPack.executeRelayTransaction(relayTransaction, options);
|
|
468
465
|
expect(gelatoResponse).toBe(RELAY_RESPONSE);
|
|
469
466
|
expect(mockSponsoredCall).toHaveBeenCalledWith({
|
|
470
467
|
chainId: CHAIN_ID,
|
|
@@ -491,7 +488,7 @@ describe('GelatoRelayPack', () => {
|
|
|
491
488
|
data: '0x'
|
|
492
489
|
}
|
|
493
490
|
};
|
|
494
|
-
const gelatoResponse = await gelatoRelayPack.executeRelayTransaction(relayTransaction
|
|
491
|
+
const gelatoResponse = await gelatoRelayPack.executeRelayTransaction(relayTransaction);
|
|
495
492
|
expect(gelatoResponse).toBe(RELAY_RESPONSE);
|
|
496
493
|
expect(mockCallWithSyncFee).toHaveBeenCalledWith({
|
|
497
494
|
chainId: CHAIN_ID,
|