@1stdex/first-sdk 1.0.69 → 1.0.71
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/batch/index.js +4 -3
- package/dist/cjs/calls/batch/index.js.map +1 -1
- package/dist/cjs/calls/batch/prepare-withdraw.js +128 -0
- package/dist/cjs/calls/batch/prepare-withdraw.js.map +1 -0
- package/dist/cjs/calls/index.js +3 -2
- package/dist/cjs/calls/index.js.map +1 -1
- package/dist/esm/calls/batch/index.js +1 -1
- package/dist/esm/calls/batch/index.js.map +1 -1
- package/dist/esm/calls/batch/prepare-withdraw.js +160 -0
- package/dist/esm/calls/batch/prepare-withdraw.js.map +1 -0
- package/dist/esm/calls/index.js +1 -1
- package/dist/esm/calls/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/calls/batch/index.d.ts +1 -1
- package/dist/types/calls/batch/index.d.ts.map +1 -1
- package/dist/types/calls/batch/prepare-withdraw.d.ts +49 -0
- package/dist/types/calls/batch/prepare-withdraw.d.ts.map +1 -0
- package/dist/types/calls/index.d.ts +1 -1
- package/dist/types/calls/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/calls/batch/prepare-withdraw-from-vault.js +0 -58
- package/dist/cjs/calls/batch/prepare-withdraw-from-vault.js.map +0 -1
- package/dist/esm/calls/batch/prepare-withdraw-from-vault.js +0 -85
- package/dist/esm/calls/batch/prepare-withdraw-from-vault.js.map +0 -1
- package/dist/types/calls/batch/prepare-withdraw-from-vault.d.ts +0 -37
- package/dist/types/calls/batch/prepare-withdraw-from-vault.d.ts.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { prepareLimitOrderWithSetup } from './prepare-limit-order-with-setup';
|
|
2
2
|
export { prepareMarketOrderWithSetup } from './prepare-market-order-with-setup';
|
|
3
|
-
export {
|
|
3
|
+
export { prepareWithdraw, NotEnoughFundsError } from './prepare-withdraw';
|
|
4
4
|
export type { BatchCall } from './prepare-limit-order-with-setup';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/calls/batch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,EAAE,2BAA2B,EAAE,MAAM,mCAAmC,CAAC;AAChF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/calls/batch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,EAAE,2BAA2B,EAAE,MAAM,mCAAmC,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,YAAY,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { CHAIN_IDS } from '../../constants/chain-configs/chain';
|
|
2
|
+
import { DefaultWriteContractOptions } from '../../types';
|
|
3
|
+
import { BatchCall } from './prepare-limit-order-with-setup';
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when there are insufficient funds in wallet and vault combined.
|
|
6
|
+
*/
|
|
7
|
+
export declare class NotEnoughFundsError extends Error {
|
|
8
|
+
readonly required: bigint;
|
|
9
|
+
readonly available: bigint;
|
|
10
|
+
constructor(message: string, required: bigint, available: bigint);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Prepares transactions to withdraw tokens optimally from wallet and/or vault to a recipient.
|
|
14
|
+
* If wallet has sufficient balance, transfers directly. Otherwise, withdraws the shortfall from
|
|
15
|
+
* vault to wallet (with approval if needed), then transfers the full amount to recipient.
|
|
16
|
+
* Throws NotEnoughFundsError if combined wallet + vault balance is insufficient.
|
|
17
|
+
*
|
|
18
|
+
* @param chainId The chain ID.
|
|
19
|
+
* @param userAddress The user address (wallet and vault owner).
|
|
20
|
+
* @param toAddress The recipient address.
|
|
21
|
+
* @param currency The currency/token address.
|
|
22
|
+
* @param amount The amount to send (decimal-adjusted string, e.g., '100.5' for 100.5 tokens).
|
|
23
|
+
* @param options Optional parameters.
|
|
24
|
+
* @returns Promise resolving to array of batch calls.
|
|
25
|
+
* @example
|
|
26
|
+
* import { prepareWithdraw } from '@1stdex/first-sdk'
|
|
27
|
+
* import { useSmartWallets } from '@privy-io/react-auth/smart-wallets'
|
|
28
|
+
*
|
|
29
|
+
* const calls = await prepareWithdraw({
|
|
30
|
+
* chainId: 421614,
|
|
31
|
+
* userAddress: '0xF8c1869Ecd4df136693C45EcE1b67f85B6bDaE69',
|
|
32
|
+
* toAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
|
|
33
|
+
* currency: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
34
|
+
* amount: '100.5' // 100.5 tokens
|
|
35
|
+
* })
|
|
36
|
+
*
|
|
37
|
+
* // Send all calls in one batched transaction
|
|
38
|
+
* const { client } = useSmartWallets()
|
|
39
|
+
* const txHash = await client.sendUserOperation({ calls })
|
|
40
|
+
*/
|
|
41
|
+
export declare const prepareWithdraw: ({ chainId, userAddress, toAddress, currency, amount, options, }: {
|
|
42
|
+
chainId: CHAIN_IDS;
|
|
43
|
+
userAddress: `0x${string}`;
|
|
44
|
+
toAddress: `0x${string}`;
|
|
45
|
+
currency: `0x${string}`;
|
|
46
|
+
amount: string;
|
|
47
|
+
options?: DefaultWriteContractOptions;
|
|
48
|
+
}) => Promise<BatchCall[]>;
|
|
49
|
+
//# sourceMappingURL=prepare-withdraw.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepare-withdraw.d.ts","sourceRoot":"","sources":["../../../../src/calls/batch/prepare-withdraw.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,SAAS,EAAa,MAAM,qCAAqC,CAAC;AAK3E,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAG1D,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAE7D;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;aAG1B,QAAQ,EAAE,MAAM;aAChB,SAAS,EAAE,MAAM;gBAFjC,OAAO,EAAE,MAAM,EACC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM;CAMpC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,eAAe,oEAOzB;IACD,OAAO,EAAE,SAAS,CAAC;IACnB,WAAW,EAAE,KAAK,MAAM,EAAE,CAAC;IAC3B,SAAS,EAAE,KAAK,MAAM,EAAE,CAAC;IACzB,QAAQ,EAAE,KAAK,MAAM,EAAE,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,2BAA2B,CAAC;CACvC,KAAG,QAAQ,SAAS,EAAE,CAsHtB,CAAC"}
|
|
@@ -8,6 +8,6 @@ export { setApprovalOfOpenOrdersForAll } from './approval/open-order';
|
|
|
8
8
|
export { setTokenAllowances } from './approval/token';
|
|
9
9
|
export { approveAllForMarket } from './approval/market';
|
|
10
10
|
export { setVault, removeVault, depositToVault, withdrawFromVault, } from './vault';
|
|
11
|
-
export { prepareLimitOrderWithSetup, prepareMarketOrderWithSetup,
|
|
11
|
+
export { prepareLimitOrderWithSetup, prepareMarketOrderWithSetup, prepareWithdraw, NotEnoughFundsError, } from './batch';
|
|
12
12
|
export type { BatchCall } from './batch';
|
|
13
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/calls/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAA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B,OAAO,EACL,0BAA0B,EAC1B,2BAA2B,EAC3B,eAAe,EACf,mBAAmB,GACpB,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.prepareWithdrawFromVault = void 0;
|
|
4
|
-
const viem_1 = require("viem");
|
|
5
|
-
const chain_1 = require("../../constants/chain-configs/chain");
|
|
6
|
-
const addresses_1 = require("../../constants/chain-configs/addresses");
|
|
7
|
-
const vault_1 = require("../../views/vault");
|
|
8
|
-
const withdraw_from_vault_1 = require("../vault/withdraw-from-vault");
|
|
9
|
-
const prepareWithdrawFromVault = async ({ chainId, userAddress, currency, amount, options, }) => {
|
|
10
|
-
const controllerAddress = addresses_1.CONTRACT_ADDRESSES[chainId].Controller;
|
|
11
|
-
const publicClient = (0, viem_1.createPublicClient)({
|
|
12
|
-
chain: chain_1.CHAIN_MAP[chainId],
|
|
13
|
-
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
14
|
-
});
|
|
15
|
-
const calls = [];
|
|
16
|
-
const vault = await (0, vault_1.getVault)({
|
|
17
|
-
chainId,
|
|
18
|
-
tokenAddress: currency,
|
|
19
|
-
...(options?.rpcUrl && { options: { rpcUrl: options.rpcUrl } }),
|
|
20
|
-
});
|
|
21
|
-
const allowance = await publicClient.readContract({
|
|
22
|
-
address: vault.address,
|
|
23
|
-
abi: viem_1.erc20Abi,
|
|
24
|
-
functionName: 'allowance',
|
|
25
|
-
args: [userAddress, controllerAddress],
|
|
26
|
-
});
|
|
27
|
-
const maxValue = 2n ** 256n - 1n;
|
|
28
|
-
if (allowance < amount) {
|
|
29
|
-
calls.push({
|
|
30
|
-
to: vault.address,
|
|
31
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
32
|
-
abi: viem_1.erc20Abi,
|
|
33
|
-
functionName: 'approve',
|
|
34
|
-
args: [controllerAddress, maxValue],
|
|
35
|
-
}),
|
|
36
|
-
value: 0n,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
const hasApprovalCall = calls.length > 0;
|
|
40
|
-
const withdrawTx = await (0, withdraw_from_vault_1.withdrawFromVault)({
|
|
41
|
-
chainId,
|
|
42
|
-
userAddress,
|
|
43
|
-
currency,
|
|
44
|
-
amount,
|
|
45
|
-
options: {
|
|
46
|
-
...options,
|
|
47
|
-
skipGasEstimation: hasApprovalCall,
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
calls.push({
|
|
51
|
-
to: withdrawTx.to,
|
|
52
|
-
data: withdrawTx.data,
|
|
53
|
-
value: withdrawTx.value,
|
|
54
|
-
});
|
|
55
|
-
return calls;
|
|
56
|
-
};
|
|
57
|
-
exports.prepareWithdrawFromVault = prepareWithdrawFromVault;
|
|
58
|
-
//# sourceMappingURL=prepare-withdraw-from-vault.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prepare-withdraw-from-vault.js","sourceRoot":"","sources":["../../../../src/calls/batch/prepare-withdraw-from-vault.ts"],"names":[],"mappings":";;;AAAA,+BAA8E;AAE9E,+DAA2E;AAC3E,uEAA6E;AAC7E,6CAA6C;AAC7C,sEAAiE;AA+B1D,MAAM,wBAAwB,GAAG,KAAK,EAAE,EAC7C,OAAO,EACP,WAAW,EACX,QAAQ,EACR,MAAM,EACN,OAAO,GAOR,EAAwB,EAAE;IACzB,MAAM,iBAAiB,GAAG,8BAAkB,CAAC,OAAO,CAAE,CAAC,UAAU,CAAC;IAElE,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,CAA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EAAE,UAAU,CAAC,KAAK;KACxB,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AA1EW,QAAA,wBAAwB,4BA0EnC"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { createPublicClient, encodeFunctionData, erc20Abi, http } from 'viem';
|
|
2
|
-
import { CHAIN_MAP } from '../../constants/chain-configs/chain';
|
|
3
|
-
import { CONTRACT_ADDRESSES } from '../../constants/chain-configs/addresses';
|
|
4
|
-
import { getVault } from '../../views/vault';
|
|
5
|
-
import { withdrawFromVault } from '../vault/withdraw-from-vault';
|
|
6
|
-
/**
|
|
7
|
-
* Prepares all necessary transactions for withdrawing from a vault, including approval if needed.
|
|
8
|
-
* Checks if controller has allowance on vault and includes approval call if needed.
|
|
9
|
-
* Returns array of calls that can be batched in a single smart wallet transaction.
|
|
10
|
-
*
|
|
11
|
-
* @param chainId The chain ID.
|
|
12
|
-
* @param userAddress The user address.
|
|
13
|
-
* @param currency The currency/token address to withdraw.
|
|
14
|
-
* @param amount The amount to withdraw (in wei).
|
|
15
|
-
* @param options Optional parameters.
|
|
16
|
-
* @returns Promise resolving to array of batch calls (1 or 2 calls).
|
|
17
|
-
* @example
|
|
18
|
-
* import { prepareWithdrawFromVault } from '@1stdex/first-sdk'
|
|
19
|
-
* import { useSmartWallets } from '@privy-io/react-auth/smart-wallets'
|
|
20
|
-
*
|
|
21
|
-
* const calls = await prepareWithdrawFromVault({
|
|
22
|
-
* chainId: 421614,
|
|
23
|
-
* userAddress: '0xF8c1869Ecd4df136693C45EcE1b67f85B6bDaE69',
|
|
24
|
-
* currency: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
25
|
-
* amount: 1000000000000000000n // 1 token (18 decimals)
|
|
26
|
-
* })
|
|
27
|
-
*
|
|
28
|
-
* // Send all calls in one batched transaction
|
|
29
|
-
* const { client } = useSmartWallets()
|
|
30
|
-
* const txHash = await client.sendUserOperation({ calls })
|
|
31
|
-
*/
|
|
32
|
-
export const prepareWithdrawFromVault = async ({ chainId, userAddress, currency, amount, options, }) => {
|
|
33
|
-
const controllerAddress = CONTRACT_ADDRESSES[chainId].Controller;
|
|
34
|
-
const publicClient = createPublicClient({
|
|
35
|
-
chain: CHAIN_MAP[chainId],
|
|
36
|
-
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
|
|
37
|
-
});
|
|
38
|
-
const calls = [];
|
|
39
|
-
// Get vault address for the currency
|
|
40
|
-
const vault = await getVault({
|
|
41
|
-
chainId,
|
|
42
|
-
tokenAddress: currency,
|
|
43
|
-
...(options?.rpcUrl && { options: { rpcUrl: options.rpcUrl } }),
|
|
44
|
-
});
|
|
45
|
-
// Check if user has approved vault token to controller
|
|
46
|
-
const allowance = await publicClient.readContract({
|
|
47
|
-
address: vault.address,
|
|
48
|
-
abi: erc20Abi,
|
|
49
|
-
functionName: 'allowance',
|
|
50
|
-
args: [userAddress, controllerAddress],
|
|
51
|
-
});
|
|
52
|
-
const maxValue = 2n ** 256n - 1n;
|
|
53
|
-
// Add approval call if allowance is insufficient
|
|
54
|
-
if (allowance < amount) {
|
|
55
|
-
calls.push({
|
|
56
|
-
to: vault.address,
|
|
57
|
-
data: encodeFunctionData({
|
|
58
|
-
abi: erc20Abi,
|
|
59
|
-
functionName: 'approve',
|
|
60
|
-
args: [controllerAddress, maxValue],
|
|
61
|
-
}),
|
|
62
|
-
value: 0n,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
// Build withdraw transaction
|
|
66
|
-
// Skip gas estimation if we have approval call (batch scenario)
|
|
67
|
-
const hasApprovalCall = calls.length > 0;
|
|
68
|
-
const withdrawTx = await withdrawFromVault({
|
|
69
|
-
chainId,
|
|
70
|
-
userAddress,
|
|
71
|
-
currency,
|
|
72
|
-
amount,
|
|
73
|
-
options: {
|
|
74
|
-
...options,
|
|
75
|
-
skipGasEstimation: hasApprovalCall,
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
calls.push({
|
|
79
|
-
to: withdrawTx.to,
|
|
80
|
-
data: withdrawTx.data,
|
|
81
|
-
value: withdrawTx.value,
|
|
82
|
-
});
|
|
83
|
-
return calls;
|
|
84
|
-
};
|
|
85
|
-
//# sourceMappingURL=prepare-withdraw-from-vault.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prepare-withdraw-from-vault.js","sourceRoot":"","sources":["../../../../src/calls/batch/prepare-withdraw-from-vault.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE9E,OAAO,EAAa,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAKjE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,EAAE,EAC7C,OAAO,EACP,WAAW,EACX,QAAQ,EACR,MAAM,EACN,OAAO,GAOR,EAAwB,EAAE;IACzB,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,OAAO,CAAE,CAAC,UAAU,CAAC;IAElE,MAAM,YAAY,GAAG,kBAAkB,CAAC;QACtC,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC;QACzB,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;KAC3D,CAAC,CAAC;IAEH,MAAM,KAAK,GAAgB,EAAE,CAAC;IAE9B,qCAAqC;IACrC,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC;QAC3B,OAAO;QACP,YAAY,EAAE,QAAQ;QACtB,GAAG,CAAC,OAAO,EAAE,MA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s/chain';
|
|
2
|
-
import { DefaultWriteContractOptions } from '../../types';
|
|
3
|
-
import { BatchCall } from './prepare-limit-order-with-setup';
|
|
4
|
-
/**
|
|
5
|
-
* Prepares all necessary transactions for withdrawing from a vault, including approval if needed.
|
|
6
|
-
* Checks if controller has allowance on vault and includes approval call if needed.
|
|
7
|
-
* Returns array of calls that can be batched in a single smart wallet transaction.
|
|
8
|
-
*
|
|
9
|
-
* @param chainId The chain ID.
|
|
10
|
-
* @param userAddress The user address.
|
|
11
|
-
* @param currency The currency/token address to withdraw.
|
|
12
|
-
* @param amount The amount to withdraw (in wei).
|
|
13
|
-
* @param options Optional parameters.
|
|
14
|
-
* @returns Promise resolving to array of batch calls (1 or 2 calls).
|
|
15
|
-
* @example
|
|
16
|
-
* import { prepareWithdrawFromVault } from '@1stdex/first-sdk'
|
|
17
|
-
* import { useSmartWallets } from '@privy-io/react-auth/smart-wallets'
|
|
18
|
-
*
|
|
19
|
-
* const calls = await prepareWithdrawFromVault({
|
|
20
|
-
* chainId: 421614,
|
|
21
|
-
* userAddress: '0xF8c1869Ecd4df136693C45EcE1b67f85B6bDaE69',
|
|
22
|
-
* currency: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
23
|
-
* amount: 1000000000000000000n // 1 token (18 decimals)
|
|
24
|
-
* })
|
|
25
|
-
*
|
|
26
|
-
* // Send all calls in one batched transaction
|
|
27
|
-
* const { client } = useSmartWallets()
|
|
28
|
-
* const txHash = await client.sendUserOperation({ calls })
|
|
29
|
-
*/
|
|
30
|
-
export declare const prepareWithdrawFromVault: ({ chainId, userAddress, currency, amount, options, }: {
|
|
31
|
-
chainId: CHAIN_IDS;
|
|
32
|
-
userAddress: `0x${string}`;
|
|
33
|
-
currency: `0x${string}`;
|
|
34
|
-
amount: bigint;
|
|
35
|
-
options?: DefaultWriteContractOptions;
|
|
36
|
-
}) => Promise<BatchCall[]>;
|
|
37
|
-
//# sourceMappingURL=prepare-withdraw-from-vault.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prepare-withdraw-from-vault.d.ts","sourceRoot":"","sources":["../../../../src/calls/batch/prepare-withdraw-from-vault.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAa,MAAM,qCAAqC,CAAC;AAI3E,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,wBAAwB,yDAMlC;IACD,OAAO,EAAE,SAAS,CAAC;IACnB,WAAW,EAAE,KAAK,MAAM,EAAE,CAAC;IAC3B,QAAQ,EAAE,KAAK,MAAM,EAAE,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,2BAA2B,CAAC;CACvC,KAAG,QAAQ,SAAS,EAAE,CA8DtB,CAAC"}
|