@1stdex/first-sdk 1.0.4 → 1.0.6
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/cjs/calls/approval/order.js +17 -26
- package/dist/cjs/calls/approval/order.js.map +1 -1
- package/dist/cjs/calls/approval/token.js +34 -121
- package/dist/cjs/calls/approval/token.js.map +1 -1
- package/dist/esm/calls/approval/order.js +33 -55
- package/dist/esm/calls/approval/order.js.map +1 -1
- package/dist/esm/calls/approval/token.js +47 -146
- package/dist/esm/calls/approval/token.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/calls/approval/order.d.ts +23 -36
- package/dist/types/calls/approval/order.d.ts.map +1 -1
- package/dist/types/calls/approval/token.d.ts +16 -18
- package/dist/types/calls/approval/token.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -4,31 +4,26 @@ exports.approveControllerAsOrderOperator = exports.setOrderOperatorApproval = vo
|
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
5
|
const chain_1 = require("../../constants/chain-configs/chain");
|
|
6
6
|
const addresses_1 = require("../../constants/chain-configs/addresses");
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
7
|
+
const build_transaction_1 = require("../../utils/build-transaction");
|
|
8
|
+
const operator_1 = require("../../entities/open-order/apis/operator");
|
|
9
|
+
const setOrderOperatorApproval = async ({ chainId, userAddress, operator, approved, options, }) => {
|
|
11
10
|
const publicClient = (0, viem_1.createPublicClient)({
|
|
12
11
|
chain: chain_1.CHAIN_MAP[chainId],
|
|
13
12
|
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
14
13
|
});
|
|
15
|
-
const
|
|
16
|
-
|
|
14
|
+
const isOrderOperator = await (0, operator_1.fetchIsOrderOperator)(publicClient, chainId, userAddress);
|
|
15
|
+
if (!isOrderOperator) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
return (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
17
19
|
chain: chain_1.CHAIN_MAP[chainId],
|
|
20
|
+
account: userAddress,
|
|
18
21
|
address: addresses_1.CONTRACT_ADDRESSES[chainId].BookManager,
|
|
19
22
|
abi: [
|
|
20
23
|
{
|
|
21
24
|
inputs: [
|
|
22
|
-
{
|
|
23
|
-
|
|
24
|
-
name: 'operator',
|
|
25
|
-
type: 'address',
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
internalType: 'bool',
|
|
29
|
-
name: 'approved',
|
|
30
|
-
type: 'bool',
|
|
31
|
-
},
|
|
25
|
+
{ internalType: 'address', name: 'operator', type: 'address' },
|
|
26
|
+
{ internalType: 'bool', name: 'approved', type: 'bool' },
|
|
32
27
|
],
|
|
33
28
|
name: 'setOrderOperator',
|
|
34
29
|
outputs: [],
|
|
@@ -38,21 +33,17 @@ const setOrderOperatorApproval = async ({ chainId, walletClient, operator, appro
|
|
|
38
33
|
],
|
|
39
34
|
functionName: 'setOrderOperator',
|
|
40
35
|
args: [operator, approved],
|
|
41
|
-
});
|
|
42
|
-
return walletClient.writeContract(request);
|
|
36
|
+
}, options?.gasLimit);
|
|
43
37
|
};
|
|
44
38
|
exports.setOrderOperatorApproval = setOrderOperatorApproval;
|
|
45
|
-
const approveControllerAsOrderOperator = async ({ chainId,
|
|
46
|
-
|
|
39
|
+
const approveControllerAsOrderOperator = async ({ chainId, userAddress, options, }) => {
|
|
40
|
+
return (0, exports.setOrderOperatorApproval)({
|
|
47
41
|
chainId,
|
|
48
|
-
|
|
42
|
+
userAddress,
|
|
49
43
|
operator: addresses_1.CONTRACT_ADDRESSES[chainId].Controller,
|
|
50
44
|
approved: true,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
params.options = options;
|
|
54
|
-
}
|
|
55
|
-
return (0, exports.setOrderOperatorApproval)(params);
|
|
45
|
+
...(options && { options }),
|
|
46
|
+
});
|
|
56
47
|
};
|
|
57
48
|
exports.approveControllerAsOrderOperator = approveControllerAsOrderOperator;
|
|
58
49
|
//# sourceMappingURL=order.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order.js","sourceRoot":"","sources":["../../../../src/calls/approval/order.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"order.js","sourceRoot":"","sources":["../../../../src/calls/approval/order.ts"],"names":[],"mappings":";;;AAAA,+BAAgD;AAEhD,+DAA2E;AAE3E,uEAA6E;AAC7E,qEAAiE;AACjE,sEAA+E;AAwBxE,MAAM,wBAAwB,GAAG,KAAK,EAAE,EAC7C,OAAO,EACP,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,OAAO,GAOR,EAAoC,EAAE;IACrC,MAAM,YAAY,GAAG,IAAA,yBAAkB,EAAC;QACtC,KAAK,EAAE,iBAAS,CAAC,OAAO,CAAC;QACzB,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,IAAA,WAAI,EAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAA,WAAI,GAAE;KAC3D,CAAC,CAAC;IAEH,MAAM,eAAe,GAAG,MAAM,IAAA,+BAAoB,EAChD,YAAY,EACZ,OAAO,EACP,WAAW,CACZ,CAAC;IACF,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,IAAA,oCAAgB,EACrB,YAAY,EACZ;QACE,KAAK,EAAE,iBAAS,CAAC,OAAO,CAAC;QACzB,OAAO,EAAE,WAAW;QACpB,OAAO,EAAE,8BAAkB,CAAC,OAAO,CAAE,CAAC,WAAW;QACjD,GAAG,EAAE;YACH;gBACE,MAAM,EAAE;oBACN,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE;oBAC9D,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE;iBACzD;gBACD,IAAI,EAAE,kBAAkB;gBACxB,OAAO,EAAE,EAAE;gBACX,eAAe,EAAE,YAAY;gBAC7B,IAAI,EAAE,UAAU;aACjB;SACO;QACV,YAAY,EAAE,kBAAkB;QAChC,IAAI,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;KAC3B,EACD,OAAO,EAAE,QAAQ,CAClB,CAAC;AACJ,CAAC,CAAC;AAlDW,QAAA,wBAAwB,4BAkDnC;AAqBK,MAAM,gCAAgC,GAAG,KAAK,EAAE,EACrD,OAAO,EACP,WAAW,EACX,OAAO,GAKR,EAAoC,EAAE;IACrC,OAAO,IAAA,gCAAwB,EAAC;QAC9B,OAAO;QACP,WAAW;QACX,QAAQ,EAAE,8BAAkB,CAAC,OAAO,CAAE,CAAC,UAAU;QACjD,QAAQ,EAAE,IAAI;QACd,GAAG,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,CAAC;KAC5B,CAAC,CAAC;AACL,CAAC,CAAC;AAhBW,QAAA,gCAAgC,oCAgB3C"}
|
|
@@ -7,10 +7,8 @@ const apis_1 = require("../../entities/currency/apis");
|
|
|
7
7
|
const allowance_1 = require("../../entities/currency/apis/allowance");
|
|
8
8
|
const addresses_1 = require("../../constants/chain-configs/addresses");
|
|
9
9
|
const vault_1 = require("../../views/vault");
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
throw new Error('Account is not found');
|
|
13
|
-
}
|
|
10
|
+
const build_transaction_1 = require("../../utils/build-transaction");
|
|
11
|
+
const setTokenAllowances = async ({ chainId, userAddress, tokenAddress, options, }) => {
|
|
14
12
|
const publicClient = (0, viem_1.createPublicClient)({
|
|
15
13
|
chain: chain_1.CHAIN_MAP[chainId],
|
|
16
14
|
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
@@ -29,139 +27,54 @@ const setTokenAllowances = async ({ chainId, walletClient, tokenAddress, options
|
|
|
29
27
|
const oneMillionTokens = 10n ** BigInt(currency.decimals) * 1000000n;
|
|
30
28
|
const threshold = maxValue - oneMillionTokens;
|
|
31
29
|
const [tokenToControllerAllowance, vaultToControllerAllowance, vaultToBookManagerAllowance,] = await Promise.all([
|
|
32
|
-
(0, allowance_1.fetchAllowance)(publicClient, tokenAddress,
|
|
33
|
-
(0, allowance_1.fetchAllowance)(publicClient, vault.address,
|
|
34
|
-
(0, allowance_1.fetchAllowance)(publicClient, vault.address,
|
|
30
|
+
(0, allowance_1.fetchAllowance)(publicClient, tokenAddress, userAddress, controllerAddress),
|
|
31
|
+
(0, allowance_1.fetchAllowance)(publicClient, vault.address, userAddress, controllerAddress),
|
|
32
|
+
(0, allowance_1.fetchAllowance)(publicClient, vault.address, userAddress, bookManagerAddress),
|
|
35
33
|
]);
|
|
36
34
|
const approvalAbi = [
|
|
37
35
|
{
|
|
38
36
|
inputs: [
|
|
39
|
-
{
|
|
40
|
-
|
|
41
|
-
name: 'spender',
|
|
42
|
-
type: 'address',
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
internalType: 'uint256',
|
|
46
|
-
name: 'value',
|
|
47
|
-
type: 'uint256',
|
|
48
|
-
},
|
|
37
|
+
{ internalType: 'address', name: 'spender', type: 'address' },
|
|
38
|
+
{ internalType: 'uint256', name: 'value', type: 'uint256' },
|
|
49
39
|
],
|
|
50
40
|
name: 'approve',
|
|
51
|
-
outputs: [
|
|
52
|
-
{
|
|
53
|
-
internalType: 'bool',
|
|
54
|
-
name: '',
|
|
55
|
-
type: 'bool',
|
|
56
|
-
},
|
|
57
|
-
],
|
|
41
|
+
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
|
|
58
42
|
stateMutability: 'nonpayable',
|
|
59
43
|
type: 'function',
|
|
60
44
|
},
|
|
61
45
|
];
|
|
62
|
-
const
|
|
46
|
+
const transactions = [];
|
|
63
47
|
if (tokenToControllerAllowance < threshold) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
args: [controllerAddress, maxValue],
|
|
73
|
-
});
|
|
74
|
-
hash = await walletClient.writeContract(request);
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
if (error.message?.includes('Nonce provided for the transaction is lower than the current nonce')) {
|
|
78
|
-
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
79
|
-
const { request } = await publicClient.simulateContract({
|
|
80
|
-
account: walletClient.account,
|
|
81
|
-
chain: chain_1.CHAIN_MAP[chainId],
|
|
82
|
-
address: tokenAddress,
|
|
83
|
-
abi: approvalAbi,
|
|
84
|
-
functionName: 'approve',
|
|
85
|
-
args: [controllerAddress, maxValue],
|
|
86
|
-
});
|
|
87
|
-
hash = await walletClient.writeContract(request);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
throw error;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
transactionHashes.push(hash);
|
|
94
|
-
await publicClient.waitForTransactionReceipt({ hash });
|
|
95
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
48
|
+
transactions.push(await (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
49
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
50
|
+
account: userAddress,
|
|
51
|
+
address: tokenAddress,
|
|
52
|
+
abi: approvalAbi,
|
|
53
|
+
functionName: 'approve',
|
|
54
|
+
args: [controllerAddress, maxValue],
|
|
55
|
+
}, options?.gasLimit));
|
|
96
56
|
}
|
|
97
57
|
if (vaultToControllerAllowance < threshold) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
args: [controllerAddress, maxValue],
|
|
107
|
-
});
|
|
108
|
-
hash = await walletClient.writeContract(request);
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
if (error.message?.includes('Nonce provided for the transaction is lower than the current nonce')) {
|
|
112
|
-
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
113
|
-
const { request } = await publicClient.simulateContract({
|
|
114
|
-
account: walletClient.account,
|
|
115
|
-
chain: chain_1.CHAIN_MAP[chainId],
|
|
116
|
-
address: vault.address,
|
|
117
|
-
abi: approvalAbi,
|
|
118
|
-
functionName: 'approve',
|
|
119
|
-
args: [controllerAddress, maxValue],
|
|
120
|
-
});
|
|
121
|
-
hash = await walletClient.writeContract(request);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
throw error;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
transactionHashes.push(hash);
|
|
128
|
-
await publicClient.waitForTransactionReceipt({ hash });
|
|
129
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
58
|
+
transactions.push(await (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
59
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
60
|
+
account: userAddress,
|
|
61
|
+
address: vault.address,
|
|
62
|
+
abi: approvalAbi,
|
|
63
|
+
functionName: 'approve',
|
|
64
|
+
args: [controllerAddress, maxValue],
|
|
65
|
+
}, options?.gasLimit));
|
|
130
66
|
}
|
|
131
67
|
if (vaultToBookManagerAllowance < threshold) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
args: [bookManagerAddress, maxValue],
|
|
141
|
-
});
|
|
142
|
-
hash = await walletClient.writeContract(request);
|
|
143
|
-
}
|
|
144
|
-
catch (error) {
|
|
145
|
-
if (error.message?.includes('Nonce provided for the transaction is lower than the current nonce')) {
|
|
146
|
-
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
147
|
-
const { request } = await publicClient.simulateContract({
|
|
148
|
-
account: walletClient.account,
|
|
149
|
-
chain: chain_1.CHAIN_MAP[chainId],
|
|
150
|
-
address: vault.address,
|
|
151
|
-
abi: approvalAbi,
|
|
152
|
-
functionName: 'approve',
|
|
153
|
-
args: [bookManagerAddress, maxValue],
|
|
154
|
-
});
|
|
155
|
-
hash = await walletClient.writeContract(request);
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
throw error;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
transactionHashes.push(hash);
|
|
162
|
-
await publicClient.waitForTransactionReceipt({ hash });
|
|
68
|
+
transactions.push(await (0, build_transaction_1.buildTransaction)(publicClient, {
|
|
69
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
70
|
+
account: userAddress,
|
|
71
|
+
address: vault.address,
|
|
72
|
+
abi: approvalAbi,
|
|
73
|
+
functionName: 'approve',
|
|
74
|
+
args: [bookManagerAddress, maxValue],
|
|
75
|
+
}, options?.gasLimit));
|
|
163
76
|
}
|
|
164
|
-
return
|
|
77
|
+
return transactions;
|
|
165
78
|
};
|
|
166
79
|
exports.setTokenAllowances = setTokenAllowances;
|
|
167
80
|
//# sourceMappingURL=token.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../../../src/calls/approval/token.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../../../src/calls/approval/token.ts"],"names":[],"mappings":";;;AAAA,+BAAgD;AAEhD,+DAA2E;AAE3E,uDAA6D;AAC7D,sEAAwE;AACxE,uEAA6E;AAC7E,6CAA6C;AAC7C,qEAAiE;AAgC1D,MAAM,kBAAkB,GAAG,KAAK,EAAE,EACvC,OAAO,EACP,WAAW,EACX,YAAY,EACZ,OAAO,GAMR,EAA0B,EAAE;IAC3B,MAAM,YAAY,GAAG,IAAA,yBAAkB,EAAC;QACtC,KAAK,EAAE,iBAAS,CAAC,OAAO,CAAC;QACzB,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,IAAA,WAAI,EAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAA,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ACpB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,GAAG,EAAE,WAAW;YAChB,YAAY,EAAE,SAAS;YACvB,IAAI,EAAE,CAAC,kBAAkB,EAAE,QAAQ,CAAC;SACrC,EACD,OAAO,EAAE,QAAQ,CAClB,CACF,CAAC;IACJ,CAAC;IAGD,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAzHW,QAAA,kBAAkB,sBAyH7B"}
|
|
@@ -1,60 +1,48 @@
|
|
|
1
1
|
import { createPublicClient, http } from 'viem';
|
|
2
2
|
import { CHAIN_MAP } from '../../constants/chain-configs/chain';
|
|
3
3
|
import { CONTRACT_ADDRESSES } from '../../constants/chain-configs/addresses';
|
|
4
|
+
import { buildTransaction } from '../../utils/build-transaction';
|
|
5
|
+
import { fetchIsOrderOperator } from '../../entities/open-order/apis/operator';
|
|
4
6
|
/**
|
|
5
|
-
*
|
|
6
|
-
* Sets the order operator approval for the specified operator address on the given chain.
|
|
7
|
+
* Prepares a transaction to set the order operator approval for the specified operator address on the given chain.
|
|
7
8
|
*
|
|
8
9
|
* @param {CHAIN_IDS} chainId The chain ID.
|
|
9
|
-
* @param {
|
|
10
|
+
* @param {`0x${string}`} userAddress The user address.
|
|
10
11
|
* @param {`0x${string}`} operator The operator address to approve or revoke.
|
|
11
12
|
* @param {boolean} approved Whether to approve or revoke the operator.
|
|
12
13
|
* @param {Object} [options] Optional parameters for setting approval.
|
|
13
|
-
* @param {string} options.rpcUrl The RPC URL to use for
|
|
14
|
-
* @returns {Promise
|
|
14
|
+
* @param {string} options.rpcUrl The RPC URL to use for building the transaction.
|
|
15
|
+
* @returns {Promise<Transaction>} Promise resolving to the transaction object.
|
|
15
16
|
* @example
|
|
16
17
|
* import { setOrderOperatorApproval } from '@clober/v2-sdk'
|
|
17
|
-
* import { mnemonicToAccount } from 'viem/accounts'
|
|
18
18
|
*
|
|
19
|
-
* const
|
|
20
|
-
* chain: arbitrumSepolia,
|
|
21
|
-
* account: mnemonicToAccount('legal ...'),
|
|
22
|
-
* transport: http(),
|
|
23
|
-
* })
|
|
24
|
-
*
|
|
25
|
-
* const hash = await setOrderOperatorApproval({
|
|
19
|
+
* const transaction = await setOrderOperatorApproval({
|
|
26
20
|
* chainId: 421614,
|
|
27
|
-
*
|
|
21
|
+
* userAddress: '0xF8c1869Ecd4df136693C45EcE1b67f85B6bDaE69',
|
|
28
22
|
* operator: '0x1234567890123456789012345678901234567890',
|
|
29
23
|
* approved: true
|
|
30
24
|
* })
|
|
25
|
+
*
|
|
26
|
+
* const hash = await walletClient.sendTransaction(transaction)
|
|
31
27
|
*/
|
|
32
|
-
export const setOrderOperatorApproval = async ({ chainId,
|
|
33
|
-
if (!walletClient.account) {
|
|
34
|
-
throw new Error('Account is not found');
|
|
35
|
-
}
|
|
28
|
+
export const setOrderOperatorApproval = async ({ chainId, userAddress, operator, approved, options, }) => {
|
|
36
29
|
const publicClient = createPublicClient({
|
|
37
30
|
chain: CHAIN_MAP[chainId],
|
|
38
31
|
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
39
32
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
const isOrderOperator = await fetchIsOrderOperator(publicClient, chainId, userAddress);
|
|
34
|
+
if (!isOrderOperator) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
return buildTransaction(publicClient, {
|
|
43
38
|
chain: CHAIN_MAP[chainId],
|
|
39
|
+
account: userAddress,
|
|
44
40
|
address: CONTRACT_ADDRESSES[chainId].BookManager,
|
|
45
41
|
abi: [
|
|
46
42
|
{
|
|
47
43
|
inputs: [
|
|
48
|
-
{
|
|
49
|
-
|
|
50
|
-
name: 'operator',
|
|
51
|
-
type: 'address',
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
internalType: 'bool',
|
|
55
|
-
name: 'approved',
|
|
56
|
-
type: 'bool',
|
|
57
|
-
},
|
|
44
|
+
{ internalType: 'address', name: 'operator', type: 'address' },
|
|
45
|
+
{ internalType: 'bool', name: 'approved', type: 'bool' },
|
|
58
46
|
],
|
|
59
47
|
name: 'setOrderOperator',
|
|
60
48
|
outputs: [],
|
|
@@ -64,44 +52,34 @@ export const setOrderOperatorApproval = async ({ chainId, walletClient, operator
|
|
|
64
52
|
],
|
|
65
53
|
functionName: 'setOrderOperator',
|
|
66
54
|
args: [operator, approved],
|
|
67
|
-
});
|
|
68
|
-
return walletClient.writeContract(request);
|
|
55
|
+
}, options?.gasLimit);
|
|
69
56
|
};
|
|
70
57
|
/**
|
|
71
|
-
*
|
|
72
|
-
* Approves the controller as an order operator for the specified chain.
|
|
58
|
+
* Prepares a transaction to approve the controller as an order operator for the specified chain.
|
|
73
59
|
* This is a convenience function that delegates to `setOrderOperatorApproval`.
|
|
74
60
|
*
|
|
75
61
|
* @param {CHAIN_IDS} chainId The chain ID.
|
|
76
|
-
* @param {
|
|
62
|
+
* @param {`0x${string}`} userAddress The user address.
|
|
77
63
|
* @param {Object} [options] Optional parameters for setting approval.
|
|
78
|
-
* @param {string} options.rpcUrl The RPC URL to use for
|
|
79
|
-
* @returns {Promise
|
|
64
|
+
* @param {string} options.rpcUrl The RPC URL to use for building the transaction.
|
|
65
|
+
* @returns {Promise<Transaction>} Promise resolving to the transaction object.
|
|
80
66
|
* @example
|
|
81
67
|
* import { approveControllerAsOrderOperator } from '@clober/v2-sdk'
|
|
82
|
-
* import { mnemonicToAccount } from 'viem/accounts'
|
|
83
68
|
*
|
|
84
|
-
* const
|
|
85
|
-
* chain: arbitrumSepolia,
|
|
86
|
-
* account: mnemonicToAccount('legal ...'),
|
|
87
|
-
* transport: http(),
|
|
88
|
-
* })
|
|
89
|
-
*
|
|
90
|
-
* const hash = await approveControllerAsOrderOperator({
|
|
69
|
+
* const transaction = await approveControllerAsOrderOperator({
|
|
91
70
|
* chainId: 421614,
|
|
92
|
-
*
|
|
71
|
+
* userAddress: '0xF8c1869Ecd4df136693C45EcE1b67f85B6bDaE69'
|
|
93
72
|
* })
|
|
73
|
+
*
|
|
74
|
+
* const hash = await walletClient.sendTransaction(transaction)
|
|
94
75
|
*/
|
|
95
|
-
export const approveControllerAsOrderOperator = async ({ chainId,
|
|
96
|
-
|
|
76
|
+
export const approveControllerAsOrderOperator = async ({ chainId, userAddress, options, }) => {
|
|
77
|
+
return setOrderOperatorApproval({
|
|
97
78
|
chainId,
|
|
98
|
-
|
|
79
|
+
userAddress,
|
|
99
80
|
operator: CONTRACT_ADDRESSES[chainId].Controller,
|
|
100
81
|
approved: true,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
params.options = options;
|
|
104
|
-
}
|
|
105
|
-
return setOrderOperatorApproval(params);
|
|
82
|
+
...(options && { options }),
|
|
83
|
+
});
|
|
106
84
|
};
|
|
107
85
|
//# sourceMappingURL=order.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order.js","sourceRoot":"","sources":["../../../../src/calls/approval/order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"order.js","sourceRoot":"","sources":["../../../../src/calls/approval/order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAEhD,OAAO,EAAa,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAE3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAE/E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,EAAE,EAC7C,OAAO,EACP,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,OAAO,GAOR,EAAoC,EAAE;IACrC,MAAM,YAAY,GAAG,kBAAkB,CAAC;QACtC,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC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