@aboutcircles/sdk-transfers 0.1.5 → 0.1.7
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/TransferBuilder.d.ts +59 -13
- package/dist/TransferBuilder.d.ts.map +1 -1
- package/dist/TransferBuilder.js +397 -112
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/index.js +4 -8974
- package/package.json +3 -4
|
@@ -1,13 +1,33 @@
|
|
|
1
|
-
import type { Address, AdvancedTransferOptions } from '@aboutcircles/sdk-types';
|
|
2
|
-
import type { Core } from '@aboutcircles/sdk-core';
|
|
1
|
+
import type { Address, AdvancedTransferOptions, PathfindingResult, CirclesConfig } from '@aboutcircles/sdk-types';
|
|
3
2
|
/**
|
|
4
3
|
* TransferBuilder constructs transfer transactions without executing them
|
|
5
4
|
* Handles pathfinding, wrapped token unwrapping/wrapping, and flow matrix construction
|
|
6
5
|
*/
|
|
7
6
|
export declare class TransferBuilder {
|
|
8
|
-
private
|
|
9
|
-
private
|
|
10
|
-
|
|
7
|
+
private config;
|
|
8
|
+
private hubV2;
|
|
9
|
+
private liftERC20;
|
|
10
|
+
private rpcClient;
|
|
11
|
+
private pathfinder;
|
|
12
|
+
private balance;
|
|
13
|
+
private group;
|
|
14
|
+
constructor(config: CirclesConfig);
|
|
15
|
+
/**
|
|
16
|
+
* Build flow matrix transaction from a pre-computed path
|
|
17
|
+
* This is a lower-level function useful when you already have a path and want to build transactions
|
|
18
|
+
*
|
|
19
|
+
* @param from Sender address
|
|
20
|
+
* @param to Recipient address
|
|
21
|
+
* @param path Pathfinding result with transfers
|
|
22
|
+
* @param options Advanced transfer options
|
|
23
|
+
* @param aggregate Whether to aggregate tokens at destination
|
|
24
|
+
* @returns Array of transactions to execute in order
|
|
25
|
+
*/
|
|
26
|
+
buildFlowMatrixTx(from: Address, to: Address, path: PathfindingResult, options?: AdvancedTransferOptions, aggregate?: boolean): Promise<Array<{
|
|
27
|
+
to: Address;
|
|
28
|
+
data: `0x${string}`;
|
|
29
|
+
value: bigint;
|
|
30
|
+
}>>;
|
|
11
31
|
/**
|
|
12
32
|
* Construct an advanced transfer transaction
|
|
13
33
|
* Returns the list of transactions to execute without executing them
|
|
@@ -18,21 +38,47 @@ export declare class TransferBuilder {
|
|
|
18
38
|
* @param options Advanced transfer options
|
|
19
39
|
* @returns Array of transactions to execute in order
|
|
20
40
|
*/
|
|
21
|
-
constructAdvancedTransfer(from: Address, to: Address, amount: number | bigint, options?: AdvancedTransferOptions): Promise<Array<{
|
|
41
|
+
constructAdvancedTransfer(from: Address, to: Address, amount: number | bigint, options?: AdvancedTransferOptions, aggregate?: boolean): Promise<Array<{
|
|
22
42
|
to: Address;
|
|
23
43
|
data: `0x${string}`;
|
|
24
44
|
value: bigint;
|
|
25
45
|
}>>;
|
|
26
46
|
/**
|
|
27
|
-
* Construct a replenish transaction to
|
|
28
|
-
*
|
|
29
|
-
*
|
|
47
|
+
* Construct a replenish transaction to acquire a specific token in unwrapped form
|
|
48
|
+
*
|
|
49
|
+
* This function tops up your unwrapped balance to reach the target amount (not adding on top).
|
|
50
|
+
*
|
|
51
|
+
* Process:
|
|
52
|
+
* 1. Checks current balance of the target token (unwrapped and wrapped)
|
|
53
|
+
* 2. If sufficient wrapped tokens exist, unwraps only what's needed
|
|
54
|
+
* 3. If insufficient, uses pathfinding with trust simulation to acquire tokens
|
|
55
|
+
* 4. Temporarily trusts the token owner if needed for the transfer
|
|
56
|
+
* 5. Untrusts after the transfer completes
|
|
57
|
+
*
|
|
58
|
+
* Note on Precision:
|
|
59
|
+
* - Pathfinding uses 6-decimal precision (last 12 decimals are truncated)
|
|
60
|
+
* - The function rounds UP to the next 6-decimal boundary to ensure you get at least the target
|
|
61
|
+
* - Final balance will be AT or SLIGHTLY ABOVE target (e.g., 1900.000001 instead of exactly 1900.000000)
|
|
62
|
+
* - The excess is always less than 0.000001 CRC and ensures you never fall short of the target
|
|
63
|
+
*
|
|
64
|
+
* @param from The account address that needs tokens
|
|
65
|
+
* @param tokenId The token ID to replenish (avatar address whose tokens we want)
|
|
66
|
+
* @param amount Target unwrapped balance in atto-circles (will top up to this amount)
|
|
67
|
+
* @param receiver Optional receiver address (defaults to 'from')
|
|
68
|
+
* @returns Array of transactions to execute in order
|
|
30
69
|
*
|
|
31
|
-
* @
|
|
32
|
-
*
|
|
33
|
-
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* // If you have 100 CRC unwrapped and call replenish(1000 CRC),
|
|
73
|
+
* // it will acquire 900 CRC to reach a total of 1000 CRC
|
|
74
|
+
* const txs = await transferBuilder.constructReplenish(
|
|
75
|
+
* myAddress,
|
|
76
|
+
* tokenAddress,
|
|
77
|
+
* 1000n * 10n**18n // 1000 CRC
|
|
78
|
+
* );
|
|
79
|
+
* ```
|
|
34
80
|
*/
|
|
35
|
-
constructReplenish(
|
|
81
|
+
constructReplenish(from: Address, tokenId: Address, amount: bigint, receiver?: Address): Promise<Array<{
|
|
36
82
|
to: Address;
|
|
37
83
|
data: `0x${string}`;
|
|
38
84
|
value: bigint;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransferBuilder.d.ts","sourceRoot":"","sources":["../src/TransferBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,uBAAuB,
|
|
1
|
+
{"version":3,"file":"TransferBuilder.d.ts","sourceRoot":"","sources":["../src/TransferBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAoBlH;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,SAAS,CAA2B;IAC5C,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,C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