@clober/v2-sdk 0.0.25-dev → 0.0.26
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/approval.js +72 -22
- package/dist/cjs/approval.js.map +1 -1
- package/dist/cjs/utils/allowance.js +40 -0
- package/dist/cjs/utils/allowance.js.map +1 -0
- package/dist/esm/approval.js +98 -21
- package/dist/esm/approval.js.map +1 -1
- package/dist/esm/utils/allowance.js +36 -0
- package/dist/esm/utils/allowance.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/approval.d.ts +34 -0
- package/dist/types/approval.d.ts.map +1 -1
- package/dist/types/utils/allowance.d.ts +3 -0
- package/dist/types/utils/allowance.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/cjs/approval.js
CHANGED
|
@@ -1,30 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setApprovalOfOpenOrdersForAll = void 0;
|
|
3
|
+
exports.approveERC20 = exports.setApprovalOfOpenOrdersForAll = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
4
5
|
const chain_1 = require("./constants/chain");
|
|
5
6
|
const addresses_1 = require("./constants/addresses");
|
|
6
7
|
const approval_1 = require("./utils/approval");
|
|
7
8
|
const decorator_1 = require("./utils/decorator");
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
inputs: [
|
|
11
|
-
{
|
|
12
|
-
internalType: 'address',
|
|
13
|
-
name: 'operator',
|
|
14
|
-
type: 'address',
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
internalType: 'bool',
|
|
18
|
-
name: 'approved',
|
|
19
|
-
type: 'bool',
|
|
20
|
-
},
|
|
21
|
-
],
|
|
22
|
-
name: 'setApprovalForAll',
|
|
23
|
-
outputs: [],
|
|
24
|
-
stateMutability: 'nonpayable',
|
|
25
|
-
type: 'function',
|
|
26
|
-
},
|
|
27
|
-
];
|
|
9
|
+
const allowance_1 = require("./utils/allowance");
|
|
10
|
+
const currency_1 = require("./utils/currency");
|
|
28
11
|
exports.setApprovalOfOpenOrdersForAll = (0, decorator_1.decorator)(async ({ chainId, walletClient, }) => {
|
|
29
12
|
if (!walletClient.account) {
|
|
30
13
|
throw new Error('Account is not found');
|
|
@@ -37,9 +20,76 @@ exports.setApprovalOfOpenOrdersForAll = (0, decorator_1.decorator)(async ({ chai
|
|
|
37
20
|
account: walletClient.account,
|
|
38
21
|
chain: chain_1.CHAIN_MAP[chainId],
|
|
39
22
|
address: addresses_1.CONTRACT_ADDRESSES[chainId].BookManager,
|
|
40
|
-
abi:
|
|
23
|
+
abi: [
|
|
24
|
+
{
|
|
25
|
+
inputs: [
|
|
26
|
+
{
|
|
27
|
+
internalType: 'address',
|
|
28
|
+
name: 'operator',
|
|
29
|
+
type: 'address',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
internalType: 'bool',
|
|
33
|
+
name: 'approved',
|
|
34
|
+
type: 'bool',
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
name: 'setApprovalForAll',
|
|
38
|
+
outputs: [],
|
|
39
|
+
stateMutability: 'nonpayable',
|
|
40
|
+
type: 'function',
|
|
41
|
+
},
|
|
42
|
+
],
|
|
41
43
|
functionName: 'setApprovalForAll',
|
|
42
44
|
args: [addresses_1.CONTRACT_ADDRESSES[chainId].Controller, true],
|
|
43
45
|
});
|
|
44
46
|
});
|
|
47
|
+
exports.approveERC20 = (0, decorator_1.decorator)(async ({ chainId, walletClient, token, amount, }) => {
|
|
48
|
+
if (!walletClient.account) {
|
|
49
|
+
throw new Error('Account is not found');
|
|
50
|
+
}
|
|
51
|
+
const [currency, allowance] = await Promise.all([
|
|
52
|
+
(0, currency_1.fetchCurrency)(chainId, token),
|
|
53
|
+
(0, allowance_1.fetchAllowance)(chainId, token, walletClient.account.address, addresses_1.CONTRACT_ADDRESSES[chainId].Controller),
|
|
54
|
+
]);
|
|
55
|
+
if (allowance >= (0, viem_1.parseUnits)(amount, currency.decimals)) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
return walletClient.writeContract({
|
|
59
|
+
account: walletClient.account,
|
|
60
|
+
chain: chain_1.CHAIN_MAP[chainId],
|
|
61
|
+
address: token,
|
|
62
|
+
abi: [
|
|
63
|
+
{
|
|
64
|
+
inputs: [
|
|
65
|
+
{
|
|
66
|
+
internalType: 'address',
|
|
67
|
+
name: 'spender',
|
|
68
|
+
type: 'address',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
internalType: 'uint256',
|
|
72
|
+
name: 'value',
|
|
73
|
+
type: 'uint256',
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
name: 'approve',
|
|
77
|
+
outputs: [
|
|
78
|
+
{
|
|
79
|
+
internalType: 'bool',
|
|
80
|
+
name: '',
|
|
81
|
+
type: 'bool',
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
stateMutability: 'nonpayable',
|
|
85
|
+
type: 'function',
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
functionName: 'approve',
|
|
89
|
+
args: [
|
|
90
|
+
addresses_1.CONTRACT_ADDRESSES[chainId].Controller,
|
|
91
|
+
(0, viem_1.parseUnits)(amount, currency.decimals),
|
|
92
|
+
],
|
|
93
|
+
});
|
|
94
|
+
});
|
|
45
95
|
//# sourceMappingURL=approval.js.map
|
package/dist/cjs/approval.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval.js","sourceRoot":"","sources":["../../src/approval.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"approval.js","sourceRoot":"","sources":["../../src/approval.ts"],"names":[],"mappings":";;;AAAA,+BAA+C;AAE/C,6CAAwD;AACxD,qDAA0D;AAC1D,+CAAwD;AACxD,iDAA6C;AAE7C,iDAAkD;AAClD,+CAAgD;AA0BnC,QAAA,6BAA6B,GAAG,IAAA,qB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esModule", { value: true });
|
|
3
|
+
exports.fetchAllowance = void 0;
|
|
4
|
+
const client_1 = require("../constants/client");
|
|
5
|
+
const _abi = [
|
|
6
|
+
{
|
|
7
|
+
inputs: [
|
|
8
|
+
{
|
|
9
|
+
internalType: 'address',
|
|
10
|
+
name: 'owner',
|
|
11
|
+
type: 'address',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
internalType: 'address',
|
|
15
|
+
name: 'spender',
|
|
16
|
+
type: 'address',
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
name: 'allowance',
|
|
20
|
+
outputs: [
|
|
21
|
+
{
|
|
22
|
+
internalType: 'uint256',
|
|
23
|
+
name: '',
|
|
24
|
+
type: 'uint256',
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
stateMutability: 'view',
|
|
28
|
+
type: 'function',
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
async function fetchAllowance(chainId, token, userAddress, spenderAddress) {
|
|
32
|
+
return client_1.cachedPublicClients[chainId].readContract({
|
|
33
|
+
address: token,
|
|
34
|
+
abi: _abi,
|
|
35
|
+
functionName: 'allowance',
|
|
36
|
+
args: [userAddress, spenderAddress],
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
exports.fetchAllowance = fetchAllowance;
|
|
40
|
+
//# sourceMappingURL=allowance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allowance.js","sourceRoot":"","sources":["../../../src/utils/allowance.ts"],"names":[],"mappings":";;;AAAA,gDAAyD;AAGzD,MAAM,IAAI,GAAG;IACX;QACE,MAAM,EAAE;YACN;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,SAAS;aAChB;YACD;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,SAAS;aAChB;SACF;QACD,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE;YACP;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,SAAS;aAChB;SACF;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;CACO,CAAA;AAEH,KAAK,UAAU,cAAc,CAClC,OAAkB,EAClB,KAAoB,EACpB,WAA0B,EAC1B,cAA6B;IAE7B,OAAO,4BAAmB,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC;QAC/C,OAAO,EAAE,KAAK;QACd,GAAG,EAAE,IAAI;QACT,YAAY,EAAE,WAAW;QACzB,IAAI,EAAE,CAAC,WAAW,EAAE,cAAc,CAAC;KACpC,CAAC,CAAA;AACJ,CAAC;AAZD,wCAYC"}
|
package/dist/esm/approval.js
CHANGED
|
@@ -1,27 +1,10 @@
|
|
|
1
|
+
import { parseUnits } from 'viem';
|
|
1
2
|
import { CHAIN_MAP } from './constants/chain';
|
|
2
3
|
import { CONTRACT_ADDRESSES } from './constants/addresses';
|
|
3
4
|
import { fetchIsApprovedForAll } from './utils/approval';
|
|
4
5
|
import { decorator } from './utils/decorator';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
inputs: [
|
|
8
|
-
{
|
|
9
|
-
internalType: 'address',
|
|
10
|
-
name: 'operator',
|
|
11
|
-
type: 'address',
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
internalType: 'bool',
|
|
15
|
-
name: 'approved',
|
|
16
|
-
type: 'bool',
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
name: 'setApprovalForAll',
|
|
20
|
-
outputs: [],
|
|
21
|
-
stateMutability: 'nonpayable',
|
|
22
|
-
type: 'function',
|
|
23
|
-
},
|
|
24
|
-
];
|
|
6
|
+
import { fetchAllowance } from './utils/allowance';
|
|
7
|
+
import { fetchCurrency } from './utils/currency';
|
|
25
8
|
/**
|
|
26
9
|
* @dev This function relates with `viem` dependency
|
|
27
10
|
* Sets approval of all open orders for the specified account on the given chain.
|
|
@@ -58,9 +41,103 @@ export const setApprovalOfOpenOrdersForAll = decorator(async ({ chainId, walletC
|
|
|
58
41
|
account: walletClient.account,
|
|
59
42
|
chain: CHAIN_MAP[chainId],
|
|
60
43
|
address: CONTRACT_ADDRESSES[chainId].BookManager,
|
|
61
|
-
abi:
|
|
44
|
+
abi: [
|
|
45
|
+
{
|
|
46
|
+
inputs: [
|
|
47
|
+
{
|
|
48
|
+
internalType: 'address',
|
|
49
|
+
name: 'operator',
|
|
50
|
+
type: 'address',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
internalType: 'bool',
|
|
54
|
+
name: 'approved',
|
|
55
|
+
type: 'bool',
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
name: 'setApprovalForAll',
|
|
59
|
+
outputs: [],
|
|
60
|
+
stateMutability: 'nonpayable',
|
|
61
|
+
type: 'function',
|
|
62
|
+
},
|
|
63
|
+
],
|
|
62
64
|
functionName: 'setApprovalForAll',
|
|
63
65
|
args: [CONTRACT_ADDRESSES[chainId].Controller, true],
|
|
64
66
|
});
|
|
65
67
|
});
|
|
68
|
+
/**
|
|
69
|
+
* @dev This function relates with `viem` dependency
|
|
70
|
+
* Approves the specified amount of tokens for the given account on the specified chain.
|
|
71
|
+
*
|
|
72
|
+
* @param {CHAIN_IDS} chainId The chain ID.
|
|
73
|
+
* @param {WalletClient} walletClient The wallet client.
|
|
74
|
+
* @param {`0x${string}`} token The ERC20 token address.
|
|
75
|
+
* @param {string} amount The amount of tokens to permit.
|
|
76
|
+
* @param options
|
|
77
|
+
* @param options.rpcUrl The RPC URL of the blockchain.
|
|
78
|
+
* @returns {Promise<`0x${string}` | undefined>} Promise resolving to the transaction hash. If the account is already approved, the promise resolves to `undefined`.
|
|
79
|
+
* @example
|
|
80
|
+
* import { approveERC20 } from '@clober/v2-sdk'
|
|
81
|
+
*
|
|
82
|
+
* const walletClient = createWalletClient({
|
|
83
|
+
* chain: arbitrumSepolia,
|
|
84
|
+
* account: mnemonicToAccount('legal ...'),
|
|
85
|
+
* transport: http(),
|
|
86
|
+
* })
|
|
87
|
+
*
|
|
88
|
+
* const hash = await approveERC20({
|
|
89
|
+
* chainId: 421614,
|
|
90
|
+
* walletClient
|
|
91
|
+
* token: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
92
|
+
* amount: '1000.123', // approve 1000.123 USDC
|
|
93
|
+
* })
|
|
94
|
+
*/
|
|
95
|
+
export const approveERC20 = decorator(async ({ chainId, walletClient, token, amount, }) => {
|
|
96
|
+
if (!walletClient.account) {
|
|
97
|
+
throw new Error('Account is not found');
|
|
98
|
+
}
|
|
99
|
+
const [currency, allowance] = await Promise.all([
|
|
100
|
+
fetchCurrency(chainId, token),
|
|
101
|
+
fetchAllowance(chainId, token, walletClient.account.address, CONTRACT_ADDRESSES[chainId].Controller),
|
|
102
|
+
]);
|
|
103
|
+
if (allowance >= parseUnits(amount, currency.decimals)) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
return walletClient.writeContract({
|
|
107
|
+
account: walletClient.account,
|
|
108
|
+
chain: CHAIN_MAP[chainId],
|
|
109
|
+
address: token,
|
|
110
|
+
abi: [
|
|
111
|
+
{
|
|
112
|
+
inputs: [
|
|
113
|
+
{
|
|
114
|
+
internalType: 'address',
|
|
115
|
+
name: 'spender',
|
|
116
|
+
type: 'address',
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
internalType: 'uint256',
|
|
120
|
+
name: 'value',
|
|
121
|
+
type: 'uint256',
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
name: 'approve',
|
|
125
|
+
outputs: [
|
|
126
|
+
{
|
|
127
|
+
internalType: 'bool',
|
|
128
|
+
name: '',
|
|
129
|
+
type: 'bool',
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
stateMutability: 'nonpayable',
|
|
133
|
+
type: 'function',
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
functionName: 'approve',
|
|
137
|
+
args: [
|
|
138
|
+
CONTRACT_ADDRESSES[chainId].Controller,
|
|
139
|
+
parseUnits(amount, currency.decimals),
|
|
140
|
+
],
|
|
141
|
+
});
|
|
142
|
+
});
|
|
66
143
|
//# sourceMappingURL=approval.js.map
|
package/dist/esm/approval.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval.js","sourceRoot":"","sources":["../../src/approval.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"approval.js","sourceRoot":"","sources":["../../src/approval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAgB,MAAM,MAAM,CAAA;AAE/C,OAAO,EAAa,SAAS,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAE7C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEhD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,SAAS,CACpD,KAAK,EAAE,EACL,OAAO,EACP,YAAY,GAKb,EAAsC,EAAE;IACvC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;IACzC,CAAC;IACD,MAAM,gBAAgB,GAAG,MAAM,qBAAqB,CAClD,OAAO,EACP,YAAY,CAAC,OAAO,CAAC,OAAO,CAC7B,CAAA;IACD,IAAI,gBAAgB,EAAE,CAAC;QACrB,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,OAAO,YAAY,CAAC,aAAa,CAAC;QAChC,OAAO,EAAE,YAAY,CAAC,OAAO;QAC7B,KAAK,EAAE,SAAS,CAAC,OAAO,CA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AC;QAChC,OAAO,EAAE,YAAY,CAAC,OAAO;QAC7B,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC;QACzB,OAAO,EAAE,KAAK;QACd,GAAG,EAAE;YACH;gBACE,MAAM,EAAE;oBACN;wBACE,YAAY,EAAE,SAAS;wBACvB,IAAI,EAAE,SAAS;wBACf,IAAI,EAAE,SAAS;qBAChB;oBACD;wBACE,YAAY,EAAE,SAAS;wBACvB,IAAI,EAAE,OAAO;wBACb,IAAI,EAAE,SAAS;qBAChB;iBACF;gBACD,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE;oBACP;wBACE,YAAY,EAAE,MAAM;wBACpB,IAAI,EAAE,EAAE;wBACR,IAAI,EAAE,MAAM;qBACb;iBACF;gBACD,eAAe,EAAE,YAAY;gBAC7B,IAAI,EAAE,UAAU;aACjB;SACO;QACV,YAAY,EAAE,SAAS;QACvB,IAAI,EAAE;YACJ,kBAAkB,CAAC,OAAO,CAAE,CAAC,UAAU;YACvC,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC;SACtC;KACF,CAAC,CAAA;AACJ,CAAC,CACF,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { cachedPublicClients } from '../constants/client';
|
|
2
|
+
const _abi = [
|
|
3
|
+
{
|
|
4
|
+
inputs: [
|
|
5
|
+
{
|
|
6
|
+
internalType: 'address',
|
|
7
|
+
name: 'owner',
|
|
8
|
+
type: 'address',
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
internalType: 'address',
|
|
12
|
+
name: 'spender',
|
|
13
|
+
type: 'address',
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
name: 'allowance',
|
|
17
|
+
outputs: [
|
|
18
|
+
{
|
|
19
|
+
internalType: 'uint256',
|
|
20
|
+
name: '',
|
|
21
|
+
type: 'uint256',
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
stateMutability: 'view',
|
|
25
|
+
type: 'function',
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
export async function fetchAllowance(chainId, token, userAddress, spenderAddress) {
|
|
29
|
+
return cachedPublicClients[chainId].readContract({
|
|
30
|
+
address: token,
|
|
31
|
+
abi: _abi,
|
|
32
|
+
functionName: 'allowance',
|
|
33
|
+
args: [userAddress, spenderAddress],
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=allowance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allowance.js","sourceRoot":"","sources":["../../../src/utils/allowance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAGzD,MAAM,IAAI,GAAG;IACX;QACE,MAAM,EAAE;YACN;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,SAAS;aAChB;YACD;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,SAAS;aAChB;SACF;QACD,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE;YACP;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,SAAS;aAChB;SACF;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;CACO,CAAA;AAEV,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAAkB,EAClB,KAAoB,EACpB,WAA0B,EAC1B,cAA6B;IAE7B,OAAO,mBAAmB,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC;QAC/C,OAAO,EAAE,KAAK;QACd,GAAG,EAAE,IAAI;QACT,YAAY,EAAE,WAAW;QACzB,IAAI,EAAE,CAAC,WAAW,EAAE,cAAc,CAAC;KACpC,CAAC,CAAA;AACJ,CAAC"}
|