@polymarket/relayer-client 1.0.11 → 1.0.13

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.
Files changed (127) hide show
  1. package/dist/examples/deploySafe.d.ts +1 -0
  2. package/dist/examples/deploySafe.js +30 -0
  3. package/dist/examples/deploySafe.js.map +1 -0
  4. package/dist/examples/getAddress.d.ts +1 -0
  5. package/dist/examples/getAddress.js +23 -0
  6. package/dist/examples/getAddress.js.map +1 -0
  7. package/dist/examples/getNonce.d.ts +1 -0
  8. package/dist/examples/getNonce.js +27 -0
  9. package/dist/examples/getNonce.js.map +1 -0
  10. package/dist/examples/getRelayPayload.d.ts +1 -0
  11. package/dist/examples/getRelayPayload.js +27 -0
  12. package/dist/examples/getRelayPayload.js.map +1 -0
  13. package/dist/examples/getTransaction.d.ts +1 -0
  14. package/dist/examples/getTransaction.js +23 -0
  15. package/dist/examples/getTransaction.js.map +1 -0
  16. package/dist/examples/getTransactions.d.ts +1 -0
  17. package/dist/examples/getTransactions.js +23 -0
  18. package/dist/examples/getTransactions.js.map +1 -0
  19. package/dist/examples/poll.d.ts +1 -0
  20. package/dist/examples/poll.js +26 -0
  21. package/dist/examples/poll.js.map +1 -0
  22. package/dist/examples/proxyExecute.d.ts +1 -0
  23. package/dist/examples/proxyExecute.js +45 -0
  24. package/dist/examples/proxyExecute.js.map +1 -0
  25. package/dist/examples/safeExecute.d.ts +1 -0
  26. package/dist/examples/safeExecute.js +45 -0
  27. package/dist/examples/safeExecute.js.map +1 -0
  28. package/dist/examples/safeExecuteFail.d.ts +1 -0
  29. package/dist/examples/safeExecuteFail.js +55 -0
  30. package/dist/examples/safeExecuteFail.js.map +1 -0
  31. package/dist/examples/safeExecuteManual.d.ts +1 -0
  32. package/dist/examples/safeExecuteManual.js +45 -0
  33. package/dist/examples/safeExecuteManual.js.map +1 -0
  34. package/dist/src/abis/erc20Abi.d.ts +38 -0
  35. package/dist/src/abis/erc20Abi.js +226 -0
  36. package/dist/src/abis/erc20Abi.js.map +1 -0
  37. package/dist/src/abis/index.d.ts +5 -0
  38. package/dist/src/abis/index.js +9 -0
  39. package/dist/src/abis/index.js.map +1 -0
  40. package/dist/src/abis/multisend.d.ts +13 -0
  41. package/dist/src/abis/multisend.js +21 -0
  42. package/dist/src/abis/multisend.js.map +1 -0
  43. package/dist/src/abis/proxyFactory.d.ts +66 -0
  44. package/dist/src/abis/proxyFactory.js +323 -0
  45. package/dist/src/abis/proxyFactory.js.map +1 -0
  46. package/dist/src/abis/safe.d.ts +35 -0
  47. package/dist/src/abis/safe.js +1142 -0
  48. package/dist/src/abis/safe.js.map +1 -0
  49. package/dist/src/abis/safeFactory.d.ts +60 -0
  50. package/dist/src/abis/safeFactory.js +228 -0
  51. package/dist/src/abis/safeFactory.js.map +1 -0
  52. package/dist/src/auth/handler.d.ts +15 -0
  53. package/dist/src/auth/handler.js +50 -0
  54. package/dist/src/auth/handler.js.map +1 -0
  55. package/dist/src/auth/index.d.ts +1 -0
  56. package/dist/src/auth/index.js +5 -0
  57. package/dist/src/auth/index.js.map +1 -0
  58. package/dist/src/builder/create.d.ts +3 -0
  59. package/dist/src/builder/create.js +56 -0
  60. package/dist/src/builder/create.js.map +1 -0
  61. package/dist/src/builder/index.d.ts +4 -0
  62. package/dist/src/builder/index.js +8 -0
  63. package/dist/src/builder/index.js.map +1 -0
  64. package/dist/src/builder/proxy.d.ts +3 -0
  65. package/dist/src/builder/proxy.js +94 -0
  66. package/dist/src/builder/proxy.js.map +1 -0
  67. package/dist/src/builder/safe.d.ts +4 -0
  68. package/dist/src/builder/safe.js +131 -0
  69. package/dist/src/builder/safe.js.map +1 -0
  70. package/dist/src/builder/utils.d.ts +2 -0
  71. package/dist/src/builder/utils.js +14 -0
  72. package/dist/src/builder/utils.js.map +1 -0
  73. package/dist/src/client.d.ts +37 -0
  74. package/dist/src/client.js +187 -0
  75. package/dist/src/client.js.map +1 -0
  76. package/dist/src/constants/index.d.ts +7 -0
  77. package/dist/src/constants/index.js +11 -0
  78. package/dist/src/constants/index.js.map +1 -0
  79. package/dist/src/encode/index.d.ts +3 -0
  80. package/dist/src/encode/index.js +7 -0
  81. package/dist/src/encode/index.js.map +1 -0
  82. package/dist/src/encode/proxy.d.ts +2 -0
  83. package/dist/src/encode/proxy.js +11 -0
  84. package/dist/src/encode/proxy.js.map +1 -0
  85. package/dist/src/encode/safe.d.ts +2 -0
  86. package/dist/src/encode/safe.js +22 -0
  87. package/dist/src/encode/safe.js.map +1 -0
  88. package/dist/src/encode/utils.d.ts +6 -0
  89. package/dist/src/encode/utils.js +48 -0
  90. package/dist/src/encode/utils.js.map +1 -0
  91. package/dist/src/endpoints.d.ts +5 -0
  92. package/dist/src/endpoints.js +9 -0
  93. package/dist/src/endpoints.js.map +1 -0
  94. package/dist/src/http-helpers/index.d.ts +10 -0
  95. package/dist/src/http-helpers/index.js +54 -0
  96. package/dist/src/http-helpers/index.js.map +1 -0
  97. package/dist/src/index.d.ts +2 -0
  98. package/dist/src/index.js +6 -0
  99. package/dist/src/index.js.map +1 -0
  100. package/dist/src/manual/index.d.ts +5 -0
  101. package/dist/src/manual/index.js +33 -0
  102. package/dist/src/manual/index.js.map +1 -0
  103. package/dist/src/response/index.d.ts +2 -0
  104. package/dist/src/response/index.js +6 -0
  105. package/dist/src/response/index.js.map +1 -0
  106. package/dist/src/response/relayer.d.ts +12 -0
  107. package/dist/src/response/relayer.js +29 -0
  108. package/dist/src/response/relayer.js.map +1 -0
  109. package/dist/src/response/viem.d.ts +8 -0
  110. package/dist/src/response/viem.js +20 -0
  111. package/dist/src/response/viem.js.map +1 -0
  112. package/dist/src/signeradapter/adapter.d.ts +20 -0
  113. package/dist/src/signeradapter/adapter.js +176 -0
  114. package/dist/src/signeradapter/adapter.js.map +1 -0
  115. package/dist/src/signeradapter/index.d.ts +2 -0
  116. package/dist/src/signeradapter/index.js +6 -0
  117. package/dist/src/signeradapter/index.js.map +1 -0
  118. package/dist/src/signeradapter/interfaces.d.ts +8 -0
  119. package/dist/src/signeradapter/interfaces.js +3 -0
  120. package/dist/src/signeradapter/interfaces.js.map +1 -0
  121. package/dist/src/types.d.ts +127 -0
  122. package/dist/src/types.js +32 -0
  123. package/dist/src/types.js.map +1 -0
  124. package/dist/src/utils/index.d.ts +1 -0
  125. package/dist/src/utils/index.js +8 -0
  126. package/dist/src/utils/index.js.map +1 -0
  127. package/package.json +4 -3
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildSafeTransactionRequest = exports.aggregateTransaction = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const types_1 = require("../types");
6
+ const utils_1 = require("./utils");
7
+ const ethers_1 = require("ethers");
8
+ const utils_2 = require("ethers/lib/utils");
9
+ const safe_1 = require("../encode/safe");
10
+ const utils_3 = require("../encode/utils");
11
+ function createSafeSignature(signer, structHash) {
12
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
13
+ return signer.signMessage(structHash);
14
+ });
15
+ }
16
+ function splitSignature(sig) {
17
+ let sigV = parseInt(sig.slice(-2), 16);
18
+ switch (sigV) {
19
+ case 0:
20
+ case 1:
21
+ sigV += 31;
22
+ break;
23
+ case 27:
24
+ case 28:
25
+ sigV += 4;
26
+ break;
27
+ default:
28
+ throw new Error("Invalid signature");
29
+ }
30
+ sig = sig.slice(0, -2) + sigV.toString(16);
31
+ return {
32
+ r: ethers_1.BigNumber.from("0x" + sig.slice(2, 66)).toString(),
33
+ s: ethers_1.BigNumber.from("0x" + sig.slice(66, 130)).toString(),
34
+ v: ethers_1.BigNumber.from("0x" + sig.slice(130, 132)).toString(),
35
+ };
36
+ }
37
+ function createStructHash(chainId, safe, to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, nonce) {
38
+ const domain = {
39
+ chainId: chainId,
40
+ verifyingContract: safe,
41
+ };
42
+ const types = {
43
+ // keccak256(
44
+ // "SafeTx(address to,uint256 value,bytes data,uint8 operation,uint256 safeTxGas,uint256 baseGas,uint256 gasPrice,address gasToken,address refundReceiver,uint256 nonce)"
45
+ // );
46
+ SafeTx: [
47
+ { name: 'to', type: 'address' },
48
+ { name: 'value', type: 'uint256' },
49
+ { name: 'data', type: 'bytes' },
50
+ { name: 'operation', type: 'uint8' },
51
+ { name: 'safeTxGas', type: 'uint256' },
52
+ { name: 'baseGas', type: 'uint256' },
53
+ { name: 'gasPrice', type: 'uint256' },
54
+ { name: 'gasToken', type: 'address' },
55
+ { name: 'refundReceiver', type: 'address' },
56
+ { name: 'nonce', type: 'uint256' },
57
+ ],
58
+ };
59
+ const values = {
60
+ to: to,
61
+ value: value,
62
+ data: data,
63
+ operation: operation,
64
+ safeTxGas: safeTxGas,
65
+ baseGas: baseGas,
66
+ gasPrice: gasPrice,
67
+ gasToken: gasToken,
68
+ refundReceiver: refundReceiver,
69
+ nonce: nonce,
70
+ };
71
+ const structHash = utils_2._TypedDataEncoder.hash(domain, types, values);
72
+ // console.log(`Safe Struct Hash: ${structHash}`);
73
+ return structHash;
74
+ }
75
+ function aggregateTransaction(txns) {
76
+ let transaction;
77
+ if (txns.length == 1) {
78
+ transaction = txns[0];
79
+ }
80
+ else {
81
+ transaction = safe_1.createSafeMultisendTransaction(txns);
82
+ }
83
+ return transaction;
84
+ }
85
+ exports.aggregateTransaction = aggregateTransaction;
86
+ function buildSafeTransactionRequest(signer, args, metadata) {
87
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
88
+ const transaction = aggregateTransaction(args.transactions);
89
+ const safeTxnGas = "0";
90
+ const baseGas = "0";
91
+ const gasPrice = "0";
92
+ const gasToken = ethers_1.ethers.constants.AddressZero;
93
+ const refundReceiver = ethers_1.ethers.constants.AddressZero;
94
+ const safeAddress = utils_1.deriveSafe(args.from);
95
+ // Generate the struct hash
96
+ // NOTE: this includes a client side optimization over the current relayers
97
+ // Generates struct hash locally instead of going across the network using the RPC call
98
+ const structHash = createStructHash(args.chainId, safeAddress, transaction.to, transaction.value, transaction.data, transaction.operation, safeTxnGas, baseGas, gasPrice, gasToken, refundReceiver, args.nonce);
99
+ const sig = yield createSafeSignature(signer, structHash);
100
+ // Split the sig then pack it into Gnosis accepted rsv format
101
+ const splitSig = splitSignature(sig);
102
+ const packedSig = utils_3.abiEncodePacked({ type: "uint256", value: splitSig.r }, { type: "uint256", value: splitSig.s }, { type: "uint8", value: splitSig.v });
103
+ const sigParams = {
104
+ gasPrice,
105
+ operation: `${transaction.operation}`,
106
+ safeTxnGas,
107
+ baseGas,
108
+ gasToken,
109
+ refundReceiver,
110
+ };
111
+ if (metadata == undefined) {
112
+ metadata = "";
113
+ }
114
+ const req = {
115
+ from: args.from,
116
+ to: transaction.to,
117
+ proxyWallet: safeAddress,
118
+ data: transaction.data,
119
+ nonce: args.nonce,
120
+ signature: packedSig,
121
+ signatureParams: sigParams,
122
+ type: types_1.TransactionType.SAFE,
123
+ metadata: metadata,
124
+ };
125
+ console.log(`Created Safe Transaction Request: `);
126
+ console.log(req);
127
+ return req;
128
+ });
129
+ }
130
+ exports.buildSafeTransactionRequest = buildSafeTransactionRequest;
131
+ //# sourceMappingURL=safe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safe.js","sourceRoot":"","sources":["../../../src/builder/safe.ts"],"names":[],"mappings":";;;;AAAA,oCAOkB;AAClB,mCAAqC;AACrC,mCAA2C;AAC3C,4CAAqD;AACrD,yCAAgE;AAChE,2CAAkD;AASlD,SAAe,mBAAmB,CAAC,MAAqB,EAAE,UAAkB;;QACxE,OAAO,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAC1C,CAAC;CAAA;AAED,SAAS,cAAc,CAAC,GAAW;IAC/B,IAAI,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACvC,QAAQ,IAAI,EAAE;QACV,KAAK,CAAC,CAAC;QACP,KAAK,CAAC;YACF,IAAI,IAAI,EAAE,CAAC;YACX,MA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;QAED,MAAM,GAAG,GAAI;YACT,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,EAAE,EAAE,WAAW,CAAC,EAAE;YAClB,WAAW,EAAE,WAAW;YACxB,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,SAAS,EAAE,SAAS;YACpB,eAAe,EAAE,SAAS;YAC1B,IAAI,EAAE,uBAAe,CAAC,IAAI;YAC1B,QAAQ,EAAE,QAAQ;SACrB,CAAA;QAED,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;QAClD,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjB,OAAO,GAAG,CAAC;IACf,CAAC;CAAA;AAtED,kEAsEC"}
@@ -0,0 +1,2 @@
1
+ export declare const deriveProxyWallet: (address: string) => string;
2
+ export declare const deriveSafe: (address: string) => string;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deriveSafe = exports.deriveProxyWallet = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const constants_1 = require("../constants");
6
+ const deriveProxyWallet = (address) => {
7
+ return ethers_1.ethers.utils.getCreate2Address(constants_1.PROXY_WALLET_FACTORY_ADDRESS, ethers_1.ethers.utils.solidityKeccak256(["address"], [address]), constants_1.PROXY_INIT_CODE_HASH);
8
+ };
9
+ exports.deriveProxyWallet = deriveProxyWallet;
10
+ const deriveSafe = (address) => {
11
+ return ethers_1.ethers.utils.getCreate2Address(constants_1.SAFE_FACTORY_ADDRESS, ethers_1.ethers.utils.keccak256(ethers_1.ethers.utils.defaultAbiCoder.encode(["address"], [address])), constants_1.SAFE_INIT_CODE_HASH);
12
+ };
13
+ exports.deriveSafe = deriveSafe;
14
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/builder/utils.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAChC,4CAA6H;AAEtH,MAAM,iBAAiB,GAAG,CAAC,OAAe,EAAU,EAAE;IACzD,OAAO,eAAM,CAAC,KAAK,CAAC,iBAAiB,CACjC,wCAA4B,EAC5B,eAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,EACtD,gCAAoB,CACvB,CAAC;AACN,CAAC,CAAA;AANY,QAAA,iBAAiB,qBAM7B;AAGM,MAAM,UAAU,GAAG,CAAC,OAAe,EAAW,EAAE;IACnD,OAAO,eAAM,CAAC,KAAK,CAAC,iBAAiB,CACjC,gCAAoB,EACpB,eAAM,CAAC,KAAK,CAAC,SAAS,CAClB,eAAM,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAC9D,EACD,+BAAmB,CACtB,CAAC;AACN,CAAC,CAAA;AARY,QAAA,UAAU,cAQtB"}
@@ -0,0 +1,37 @@
1
+ import { Provider, TransactionResponse } from "@ethersproject/providers";
2
+ import { HttpClient } from "./http-helpers";
3
+ import { AddressPayload, AuthArgs, ManualOverrides, NoncePayload, ProxyTransaction, RelayerTransaction, RelayerTransactionResponse, RelayPayload, SafeTransaction } from "./types";
4
+ import { AuthHandler } from "./auth";
5
+ import { ViemTransactionResponse } from "./response";
6
+ import { SignerAdapter } from "./signeradapter";
7
+ export declare class RelayClient {
8
+ readonly relayerUrl: string;
9
+ readonly chainId: number;
10
+ readonly httpClient: HttpClient;
11
+ readonly signer?: SignerAdapter;
12
+ readonly provider?: Provider;
13
+ readonly authHandler?: AuthHandler;
14
+ constructor(relayerUrl: string, chainId: number, signer?: SignerAdapter, authArgs?: AuthArgs);
15
+ getRelayAddress(): Promise<AddressPayload>;
16
+ getNonce(signerAddress: string, signerType: string): Promise<NoncePayload>;
17
+ getRelayPayload(signerAddress: string, signerType: string): Promise<RelayPayload>;
18
+ getTransaction(transactionId: string): Promise<RelayerTransaction[]>;
19
+ getTransactions(): Promise<RelayerTransaction[]>;
20
+ executeProxyTransactions(txns: ProxyTransaction[], metadata?: string): Promise<RelayerTransactionResponse>;
21
+ executeSafeTransactions(txns: SafeTransaction[], metadata?: string): Promise<RelayerTransactionResponse>;
22
+ executeManualTransactions(txns: SafeTransaction[], overrides?: ManualOverrides): Promise<TransactionResponse | ViemTransactionResponse>;
23
+ deploySafe(): Promise<RelayerTransactionResponse>;
24
+ /**
25
+ * Periodically polls the transaction id until it reaches a desired state
26
+ * Returns the relayer transaction if it does each the desired state
27
+ * Times out after maxPolls is reached
28
+ * @param transactionId
29
+ * @param states
30
+ * @param maxPolls
31
+ * @param pollFrequency
32
+ * @returns
33
+ */
34
+ pollUntilState(transactionId: string, states: string[], maxPolls?: number, pollFrequency?: number): Promise<RelayerTransaction | undefined>;
35
+ private submitTransaction;
36
+ private send;
37
+ }
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RelayClient = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const ethers_1 = require("ethers");
6
+ const browser_or_node_1 = tslib_1.__importDefault(require("browser-or-node"));
7
+ const http_helpers_1 = require("./http-helpers");
8
+ const types_1 = require("./types");
9
+ const endpoints_1 = require("./endpoints");
10
+ const builder_1 = require("./builder");
11
+ const encode_1 = require("./encode");
12
+ const auth_1 = require("./auth");
13
+ const utils_1 = require("./utils");
14
+ const manual_1 = require("./manual");
15
+ const response_1 = require("./response");
16
+ class RelayClient {
17
+ constructor(relayerUrl, chainId, signer, authArgs) {
18
+ this.relayerUrl = relayerUrl.endsWith("/") ? relayerUrl.slice(0, -1) : relayerUrl;
19
+ this.chainId = chainId;
20
+ this.httpClient = new http_helpers_1.HttpClient();
21
+ if (signer != undefined) {
22
+ this.signer = signer;
23
+ }
24
+ if (authArgs !== undefined) {
25
+ this.authHandler = new auth_1.AuthHandler(this.httpClient, authArgs);
26
+ }
27
+ }
28
+ getRelayAddress() {
29
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
30
+ return this.send(`${this.relayerUrl}${endpoints_1.GET_ADDRESS}`, http_helpers_1.GET);
31
+ });
32
+ }
33
+ getNonce(signerAddress, signerType) {
34
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
35
+ return this.send(`${this.relayerUrl}${endpoints_1.GET_NONCE}?address=${signerAddress}&type=${signerType}`, http_helpers_1.GET);
36
+ });
37
+ }
38
+ getRelayPayload(signerAddress, signerType) {
39
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
40
+ return this.send(`${this.relayerUrl}${endpoints_1.GET_RELAY_PAYLOAD}?address=${signerAddress}&type=${signerType}`, http_helpers_1.GET);
41
+ });
42
+ }
43
+ getTransaction(transactionId) {
44
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
45
+ return this.send(`${this.relayerUrl}${endpoints_1.GET_TRANSACTION}?id=${transactionId}`, http_helpers_1.GET);
46
+ });
47
+ }
48
+ getTransactions() {
49
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
50
+ return this.send(`${this.relayerUrl}${endpoints_1.GET_TRANSACTION}s`, http_helpers_1.GET);
51
+ });
52
+ }
53
+ executeProxyTransactions(txns, metadata) {
54
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
55
+ if (this.signer == undefined) {
56
+ throw new Error("missing signer");
57
+ }
58
+ const start = Date.now();
59
+ const from = yield this.signer.getAddress();
60
+ const rp = yield this.getRelayPayload(from, types_1.TransactionType.PROXY);
61
+ const args = {
62
+ from: from,
63
+ gasPrice: "0",
64
+ data: encode_1.encodeProxyTransactionData(txns),
65
+ relay: rp.address,
66
+ nonce: rp.nonce,
67
+ };
68
+ const request = yield builder_1.buildProxyTransactionRequest(this.signer, args, metadata);
69
+ console.log(`Client side proxy request creation took: ${(Date.now() - start) / 1000} seconds`);
70
+ const resp = yield this.submitTransaction(request);
71
+ return new response_1.ClientRelayerTransactionResponse(resp.transactionID, resp.state, resp.transactionHash, this);
72
+ });
73
+ }
74
+ executeSafeTransactions(txns, metadata) {
75
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
76
+ if (this.signer == undefined) {
77
+ throw new Error("missing signer");
78
+ }
79
+ const start = Date.now();
80
+ const from = yield this.signer.getAddress();
81
+ // Note: goes over the network
82
+ const noncePayload = yield this.getNonce(from, types_1.TransactionType.SAFE);
83
+ const args = {
84
+ transactions: txns,
85
+ from,
86
+ nonce: noncePayload.nonce,
87
+ chainId: this.chainId,
88
+ };
89
+ const request = yield builder_1.buildSafeTransactionRequest(this.signer, args, metadata);
90
+ console.log(`Client side safe request creation took: ${(Date.now() - start) / 1000} seconds`);
91
+ const resp = yield this.submitTransaction(request);
92
+ return new response_1.ClientRelayerTransactionResponse(resp.transactionID, resp.state, resp.transactionHash, this);
93
+ });
94
+ }
95
+ executeManualTransactions(txns, overrides) {
96
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
97
+ if (overrides == undefined) {
98
+ overrides = {};
99
+ }
100
+ if (this.signer == undefined) {
101
+ throw new Error("missing signer");
102
+ }
103
+ return manual_1.executeManualTransactions(this.signer, txns, overrides);
104
+ });
105
+ }
106
+ deploySafe() {
107
+ var _a;
108
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
109
+ if (this.signer == undefined) {
110
+ throw new Error("missing signer");
111
+ }
112
+ const start = Date.now();
113
+ const from = yield ((_a = this.signer) === null || _a === void 0 ? void 0 : _a.getAddress());
114
+ const args = {
115
+ from: from,
116
+ chainId: this.chainId,
117
+ paymentToken: ethers_1.ethers.constants.AddressZero,
118
+ payment: "0",
119
+ paymentReceiver: ethers_1.ethers.constants.AddressZero,
120
+ };
121
+ const request = yield builder_1.buildSafeCreateTransactionRequest(this.signer, args);
122
+ console.log(`Client side deploy request creation took: ${(Date.now() - start) / 1000} seconds`);
123
+ const resp = yield this.submitTransaction(request);
124
+ return new response_1.ClientRelayerTransactionResponse(resp.transactionID, resp.state, resp.transactionHash, this);
125
+ });
126
+ }
127
+ /**
128
+ * Periodically polls the transaction id until it reaches a desired state
129
+ * Returns the relayer transaction if it does each the desired state
130
+ * Times out after maxPolls is reached
131
+ * @param transactionId
132
+ * @param states
133
+ * @param maxPolls
134
+ * @param pollFrequency
135
+ * @returns
136
+ */
137
+ pollUntilState(transactionId, states, maxPolls, pollFrequency) {
138
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
139
+ console.log(`Waiting for transaction ${transactionId} matching states: ${states}...`);
140
+ const maxPollCount = maxPolls != undefined ? maxPolls : 10;
141
+ let pollFreq = 2000; // Default to polling every 2 seconds
142
+ if (pollFrequency != undefined) {
143
+ if (pollFrequency >= 1000) {
144
+ pollFreq = pollFrequency;
145
+ }
146
+ }
147
+ let pollCount = 0;
148
+ while (pollCount < maxPollCount) {
149
+ const txns = yield this.getTransaction(transactionId);
150
+ if (txns.length > 0) {
151
+ const txn = txns[0];
152
+ if (states.includes(txn.state)) {
153
+ return txn;
154
+ }
155
+ }
156
+ pollCount++;
157
+ yield utils_1.sleep(pollFreq);
158
+ }
159
+ console.log(`Transaction not found or not in given states, timing out`);
160
+ });
161
+ }
162
+ submitTransaction(req) {
163
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
164
+ return this.send(`${this.relayerUrl}${endpoints_1.SUBMIT_TRANSACTION}`, http_helpers_1.POST, undefined, req);
165
+ });
166
+ }
167
+ send(endpoint, method, headers, data, params) {
168
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
169
+ // Explicitly inject the polymarket session cookies
170
+ // In prod environments, this will be unnecessary as the browser will have the needed cookies
171
+ // Needed only for local testing
172
+ if (!browser_or_node_1.default && this.authHandler !== undefined) {
173
+ const cookie = yield this.authHandler.getPolymarketCookies();
174
+ if (headers != undefined) {
175
+ headers["Cookie"] = cookie;
176
+ }
177
+ else {
178
+ headers = { "Cookie": cookie };
179
+ }
180
+ }
181
+ const resp = yield this.httpClient.send(endpoint, method, headers, data, params);
182
+ return resp.data;
183
+ });
184
+ }
185
+ }
186
+ exports.RelayClient = RelayClient;
187
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;;AACA,mCAAgC;AAChC,8EAAwC;AAExC,iDAIwB;AACxB,mCAciB;AACjB,2CAMqB;AACrB,uCAImB;AACnB,qCAAsD;AACtD,iCAAqC;AAErC,mCAAgC;AAChC,qCAAqD;AACrD,yCAAuF;AAIvF,MAAa,WAAW;IAapB,YACI,UAAkB,EAClB,OAAe,EACf,MAAsB,EACtB,QAAmB;QAEnB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;QAClF,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,IAAI,yBAAU,EAAE,CAAC;QAEnC,IAAI,MAAM,IAAI,SAAS,EAAE;YACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;SACxB;QAED,IAAI,QAAQ,KAAK,SAAS,EAAE;YACxB,IAAI,CAAC,WAAW,GAAG,IAAI,kBAAW,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;SACjE;IACL,CAAC;IAEY,eAAe;;YACxB,OAAO,IAAI,CAAC,IAAI,CACZ,GAAG,IAAI,CAAC,UAAU,GAAG,uBAAW,EAAE,EAClC,kBAAG,CACN,CAAC;QACN,CAAC;KAAA;IAEY,QAAQ,CAAC,aAAqB,EAAE,UAAkB;;YAC3D,OAAO,IAAI,CAAC,IAAI,CACZ,GAAG,IAAI,CAAC,UAAU,GAAG,qBAAS,YAAY,aAAa,SAAS,UAAU,EAAE,EAC5E,kBAAG,CACN,CAAC;QACN,CAAC;KAAA;IAEY,eAAe,CAAC,aAAqB,EAAE,UAAkB;;YAClE,OAAO,IAAI,CAAC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,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,oBAAoB,EAAE,CAAC;gBAC7D,IAAG,OAAO,IAAI,SAAS,EAAE;oBACrB,OAAO,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC;iBAC9B;qBAAM;oBACH,OAAO,GAAG,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC;iBAChC;aACJ;YACD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;YACjF,OAAO,IAAI,CAAC,IAAI,CAAC;QACrB,CAAC;KAAA;CACJ;AA5ND,kCA4NC"}
@@ -0,0 +1,7 @@
1
+ export declare const RELAY_HUB_ADDRESS = "0xD216153c06E857cD7f72665E0aF1d7D82172F494";
2
+ export declare const PROXY_WALLET_FACTORY_ADDRESS = "0xaB45c5A4B0c941a2F231C04C3f49182e1A254052";
3
+ export declare const SAFE_FACTORY_ADDRESS = "0xaacFeEa03eb1561C4e67d661e40682Bd20E3541b";
4
+ export declare const SAFE_MULTISEND_ADDRESS = "0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761";
5
+ export declare const PROXY_INIT_CODE_HASH = "0xd21df8dc65880a8606f09fe0ce3df9b8869287ab0b058be05aa9e8af6330a00b";
6
+ export declare const SAFE_INIT_CODE_HASH = "0x2bce2127ff07fb632d16c8347c4ebf501f4841168bed00d9e6ef715ddb6fcecf";
7
+ export declare const SAFE_FACTORY_NAME = "Polymarket Contract Proxy Factory";
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SAFE_FACTORY_NAME = exports.SAFE_INIT_CODE_HASH = exports.PROXY_INIT_CODE_HASH = exports.SAFE_MULTISEND_ADDRESS = exports.SAFE_FACTORY_ADDRESS = exports.PROXY_WALLET_FACTORY_ADDRESS = exports.RELAY_HUB_ADDRESS = void 0;
4
+ exports.RELAY_HUB_ADDRESS = "0xD216153c06E857cD7f72665E0aF1d7D82172F494";
5
+ exports.PROXY_WALLET_FACTORY_ADDRESS = "0xaB45c5A4B0c941a2F231C04C3f49182e1A254052";
6
+ exports.SAFE_FACTORY_ADDRESS = "0xaacFeEa03eb1561C4e67d661e40682Bd20E3541b";
7
+ exports.SAFE_MULTISEND_ADDRESS = "0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761";
8
+ exports.PROXY_INIT_CODE_HASH = "0xd21df8dc65880a8606f09fe0ce3df9b8869287ab0b058be05aa9e8af6330a00b";
9
+ exports.SAFE_INIT_CODE_HASH = "0x2bce2127ff07fb632d16c8347c4ebf501f4841168bed00d9e6ef715ddb6fcecf";
10
+ exports.SAFE_FACTORY_NAME = "Polymarket Contract Proxy Factory";
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/constants/index.ts"],"names":[],"mappings":";;;AAAa,QAAA,iBAAiB,GAAG,4CAA4C,CAAC;AAEjE,QAAA,4BAA4B,GAAG,4CAA4C,CAAC;AAE5E,QAAA,oBAAoB,GAAG,4CAA4C,CAAC;AAEpE,QAAA,sBAAsB,GAAG,4CAA4C,CAAC;AAEtE,QAAA,oBAAoB,GAAG,oEAAoE,CAAC;AAE5F,QAAA,mBAAmB,GAAG,oEAAoE,CAAC;AAE3F,QAAA,iBAAiB,GAAG,mCAAmC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./proxy";
2
+ export * from "./safe";
3
+ export * from "./utils";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./proxy"), exports);
5
+ tslib_1.__exportStar(require("./safe"), exports);
6
+ tslib_1.__exportStar(require("./utils"), exports);
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/encode/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB;AACxB,iDAAuB;AACvB,kDAAwB"}
@@ -0,0 +1,2 @@
1
+ import { ProxyTransaction } from "../types";
2
+ export declare const encodeProxyTransactionData: (txns: ProxyTransaction[]) => string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encodeProxyTransactionData = void 0;
4
+ const utils_1 = require("ethers/lib/utils");
5
+ const abis_1 = require("../abis");
6
+ const factoryInterface = new utils_1.Interface(abis_1.proxyWalletFactory);
7
+ const encodeProxyTransactionData = (txns) => {
8
+ return factoryInterface.encodeFunctionData("proxy((uint8,address,uint256,bytes)[])", [txns]);
9
+ };
10
+ exports.encodeProxyTransactionData = encodeProxyTransactionData;
11
+ //# sourceMappingURL=proxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../src/encode/proxy.ts"],"names":[],"mappings":";;;AAAA,4CAA6C;AAC7C,kCAA6C;AAG7C,MAAM,gBAAgB,GAAG,IAAI,iBAAS,CAAC,yBAAkB,CAAC,CAAC;AAEpD,MAAM,0BAA0B,GAAG,CAAC,IAAwB,EAAW,EAAE;IAC5E,OAAO,gBAAgB,CAAC,kBAAkB,CACtC,wCAAwC,EACxC,CAAC,IAAI,CAAC,CACT,CAAC;AACN,CAAC,CAAA;AALY,QAAA,0BAA0B,8BAKtC"}
@@ -0,0 +1,2 @@
1
+ import { SafeTransaction } from "../types";
2
+ export declare const createSafeMultisendTransaction: (txns: SafeTransaction[]) => SafeTransaction;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSafeMultisendTransaction = void 0;
4
+ const utils_1 = require("ethers/lib/utils");
5
+ const constants_1 = require("../constants");
6
+ const abis_1 = require("../abis");
7
+ const types_1 = require("../types");
8
+ const utils_2 = require("./utils");
9
+ const multisendInterface = new utils_1.Interface(abis_1.multisendAbi);
10
+ const createSafeMultisendTransaction = (txns) => {
11
+ const data = multisendInterface.encodeFunctionData("multiSend", [
12
+ utils_2.joinHexData(txns.map(tx => utils_2.abiEncodePacked({ type: "uint8", value: tx.operation }, { type: "address", value: tx.to }, { type: "uint256", value: tx.value }, { type: "uint256", value: utils_2.getHexDataLength(tx.data) }, { type: "bytes", value: tx.data }))),
13
+ ]);
14
+ return {
15
+ to: constants_1.SAFE_MULTISEND_ADDRESS,
16
+ value: "0",
17
+ data: data,
18
+ operation: types_1.OperationType.DelegateCall,
19
+ };
20
+ };
21
+ exports.createSafeMultisendTransaction = createSafeMultisendTransaction;
22
+ //# sourceMappingURL=safe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safe.js","sourceRoot":"","sources":["../../../src/encode/safe.ts"],"names":[],"mappings":";;;AAAA,4CAA6C;AAC7C,4CAAsD;AACtD,kCAAuC;AACvC,oCAA0D;AAC1D,mCAAyE;AAEzE,MAAM,kBAAkB,GAAG,IAAI,iBAAS,CAAC,mBAAY,CAAC,CAAC;AAEhD,MAAM,8BAA8B,GAAG,CAAC,IAAuB,EAAmB,EAAE;IACvF,MAAM,IAAI,GAAG,kBAAkB,CAAC,kBAAkB,CAAC,WAAW,EAAE;QAC5D,mBAAW,CACP,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CACV,uBAAe,CACX,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,SAAS,EAAE,EACtC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE,EACjC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,EACpC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,wBAAgB,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,EACrD,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,EAAE,CACpC,CACJ,CACJ;KACJ,CAAC,CAAC;IAEH,OAAO;QACH,EAAE,EAAE,kCAAsB;QAC1B,KAAK,EAAE,GAAG;QACV,IAAI,EAAE,IAAI;QACV,SAAS,EAAE,qBAAa,CAAC,YAAY;KACxC,CAAA;AACL,CAAC,CAAA;AArBY,QAAA,8BAA8B,kCAqB1C"}
@@ -0,0 +1,6 @@
1
+ export declare function joinHexData(hexData: string[]): string;
2
+ export declare function abiEncodePacked(...params: {
3
+ type: string;
4
+ value: any;
5
+ }[]): string;
6
+ export declare function getHexDataLength(hexData: string): number;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHexDataLength = exports.abiEncodePacked = exports.joinHexData = void 0;
4
+ const abi_1 = require("@ethersproject/abi");
5
+ function joinHexData(hexData) {
6
+ return `0x${hexData
7
+ .map((hex) => {
8
+ const stripped = hex.replace(/^0x/, '');
9
+ return stripped.length % 2 === 0 ? stripped : '0' + stripped;
10
+ })
11
+ .join('')}`;
12
+ }
13
+ exports.joinHexData = joinHexData;
14
+ function abiEncodePacked(...params) {
15
+ return joinHexData(params.map(({ type, value }) => {
16
+ const encoded = abi_1.defaultAbiCoder.encode([type], [value]);
17
+ if (type === 'bytes' || type === 'string') {
18
+ const bytesLength = parseInt(encoded.slice(66, 130), 16);
19
+ return encoded.slice(130, 130 + 2 * bytesLength);
20
+ }
21
+ let typeMatch = type.match(/^(?:u?int\d*|bytes\d+|address)\[\]$/);
22
+ if (typeMatch) {
23
+ return encoded.slice(130);
24
+ }
25
+ if (type.startsWith('bytes')) {
26
+ const bytesLength = parseInt(type.slice(5));
27
+ return encoded.slice(2, 2 + 2 * bytesLength);
28
+ }
29
+ typeMatch = type.match(/^u?int(\d*)$/);
30
+ if (typeMatch) {
31
+ if (typeMatch[1] !== '') {
32
+ const bytesLength = parseInt(typeMatch[1]) / 8;
33
+ return encoded.slice(-2 * bytesLength);
34
+ }
35
+ return encoded.slice(-64);
36
+ }
37
+ if (type === 'address') {
38
+ return encoded.slice(-40);
39
+ }
40
+ throw new Error(`unsupported type ${type}`);
41
+ }));
42
+ }
43
+ exports.abiEncodePacked = abiEncodePacked;
44
+ function getHexDataLength(hexData) {
45
+ return Math.ceil((hexData.startsWith("0x") ? hexData.length - 2 : hexData.length) / 2);
46
+ }
47
+ exports.getHexDataLength = getHexDataLength;
48
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/encode/utils.ts"],"names":[],"mappings":";;;AAAA,4CAAoD;AAGpD,SAAgB,WAAW,CAAC,OAAiB;IACzC,OAAO,KAAK,OAAO;SAChB,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QACX,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;QACvC,OAAO,QAAQ,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,GAAG,QAAQ,CAAA;IAC9D,CAAC,CAAC;SACD,IAAI,CAAC,EAAE,CAAC,EAAE,CAAA;AACjB,CAAC;AAPD,kCAOC;AAED,SAAgB,eAAe,CAAC,GAAG,MAAsC;IACrE,OAAO,WAAW,CAChB,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE;QAC7B,MAAM,OAAO,GAAG,qBAAe,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;QAEvD,IAAI,IAAI,KAAK,OAAO,IAAI,IAAI,KAAK,QAAQ,EAAE;YACzC,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAA;YACxD,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,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C,CAAC,CAAC;AAC3F,CAAC;AAFD,4CAEC"}
@@ -0,0 +1,5 @@
1
+ export declare const GET_ADDRESS = "/address";
2
+ export declare const GET_NONCE = "/nonce";
3
+ export declare const GET_RELAY_PAYLOAD = "/relay-payload";
4
+ export declare const GET_TRANSACTION = "/transaction";
5
+ export declare const SUBMIT_TRANSACTION = "/submit";
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SUBMIT_TRANSACTION = exports.GET_TRANSACTION = exports.GET_RELAY_PAYLOAD = exports.GET_NONCE = exports.GET_ADDRESS = void 0;
4
+ exports.GET_ADDRESS = "/address";
5
+ exports.GET_NONCE = "/nonce";
6
+ exports.GET_RELAY_PAYLOAD = "/relay-payload";
7
+ exports.GET_TRANSACTION = "/transaction";
8
+ exports.SUBMIT_TRANSACTION = "/submit";
9
+ //# sourceMappingURL=endpoints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoints.js","sourceRoot":"","sources":["../../src/endpoints.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,UAAU,CAAC;AACzB,QAAA,SAAS,GAAG,QAAQ,CAAC;AACrB,QAAA,iBAAiB,GAAG,gBAAgB,CAAA;AACpC,QAAA,eAAe,GAAG,cAAc,CAAA;AAEhC,QAAA,kBAAkB,GAAG,SAAS,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { AxiosInstance, AxiosResponse, Method } from "axios";
2
+ export declare const GET = "GET";
3
+ export declare const POST = "POST";
4
+ export declare const DELETE = "DELETE";
5
+ export declare const PUT = "PUT";
6
+ export declare class HttpClient {
7
+ readonly instance: AxiosInstance;
8
+ constructor();
9
+ send(endpoint: string, method: Method, headers?: any, data?: any, params?: any): Promise<AxiosResponse>;
10
+ }