thirdweb 5.65.1 → 5.65.2
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/chains/utils.js +14 -6
- package/dist/cjs/chains/utils.js.map +1 -1
- package/dist/cjs/extensions/erc20/write/transferBatch.js +65 -18
- package/dist/cjs/extensions/erc20/write/transferBatch.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/chains/utils.js +8 -2
- package/dist/esm/chains/utils.js.map +1 -1
- package/dist/esm/extensions/erc20/write/transferBatch.js +64 -18
- package/dist/esm/extensions/erc20/write/transferBatch.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/chains/utils.d.ts +10 -0
- package/dist/types/chains/utils.d.ts.map +1 -1
- package/dist/types/extensions/erc20/write/transferBatch.d.ts +31 -0
- package/dist/types/extensions/erc20/write/transferBatch.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/chains/utils.test.ts +123 -0
- package/src/chains/utils.ts +8 -2
- package/src/extensions/erc20/write/transferBatch.test.ts +102 -10
- package/src/extensions/erc20/write/transferBatch.ts +79 -25
- package/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx +2 -1
- package/src/version.ts +1 -1
@@ -53,34 +53,88 @@ export function transferBatch(
|
|
53
53
|
return multicall({
|
54
54
|
contract: options.contract,
|
55
55
|
asyncParams: async () => {
|
56
|
+
const content = await optimizeTransferContent(options);
|
56
57
|
return {
|
57
|
-
data:
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
const d = await decimals(options).catch(() => 18);
|
66
|
-
// turn ether into gwei
|
67
|
-
amount = toUnits(transfer.amount.toString(), d);
|
68
|
-
} else {
|
69
|
-
amount = transfer.amountWei;
|
70
|
-
}
|
71
|
-
return encodeTransfer({
|
72
|
-
to: transfer.to,
|
73
|
-
value: amount,
|
74
|
-
overrides: {
|
75
|
-
erc20Value: {
|
76
|
-
amountWei: amount,
|
77
|
-
tokenAddress: options.contract.address,
|
78
|
-
},
|
58
|
+
data: content.map((item) => {
|
59
|
+
return encodeTransfer({
|
60
|
+
to: item.to,
|
61
|
+
value: item.amountWei,
|
62
|
+
overrides: {
|
63
|
+
erc20Value: {
|
64
|
+
amountWei: item.amountWei,
|
65
|
+
tokenAddress: options.contract.address,
|
79
66
|
},
|
80
|
-
}
|
81
|
-
})
|
82
|
-
),
|
67
|
+
},
|
68
|
+
});
|
69
|
+
}),
|
83
70
|
};
|
84
71
|
},
|
85
72
|
});
|
86
73
|
}
|
74
|
+
|
75
|
+
/**
|
76
|
+
* Records with the same recipient (`to`) can be packed into one transaction
|
77
|
+
* For example, the data below:
|
78
|
+
* ```ts
|
79
|
+
* [
|
80
|
+
* {
|
81
|
+
* to: "wallet-a",
|
82
|
+
* amount: 1,
|
83
|
+
* },
|
84
|
+
* {
|
85
|
+
* to: "wallet-A",
|
86
|
+
* amountWei: 1000000000000000000n,
|
87
|
+
* },
|
88
|
+
* ]
|
89
|
+
* ```
|
90
|
+
*
|
91
|
+
* can be packed to:
|
92
|
+
* ```ts
|
93
|
+
* [
|
94
|
+
* {
|
95
|
+
* to: "wallet-a",
|
96
|
+
* amountWei: 2000000000000000000n,
|
97
|
+
* },
|
98
|
+
* ]
|
99
|
+
* ```
|
100
|
+
* @internal
|
101
|
+
*/
|
102
|
+
export async function optimizeTransferContent(
|
103
|
+
options: BaseTransactionOptions<TransferBatchParams>,
|
104
|
+
): Promise<Array<{ to: string; amountWei: bigint }>> {
|
105
|
+
const groupedRecords = await options.batch.reduce(
|
106
|
+
async (accPromise, record) => {
|
107
|
+
const acc = await accPromise;
|
108
|
+
let amountInWei: bigint;
|
109
|
+
if ("amount" in record) {
|
110
|
+
// it's OK to call this multiple times because the call is cached
|
111
|
+
const { decimals } = await import("../read/decimals.js");
|
112
|
+
// if this fails we fall back to `18` decimals
|
113
|
+
const d = await decimals(options).catch(() => undefined);
|
114
|
+
if (d === undefined) {
|
115
|
+
throw new Error(
|
116
|
+
`Failed to get the decimals for contract: ${options.contract.address}`,
|
117
|
+
);
|
118
|
+
}
|
119
|
+
amountInWei = toUnits(record.amount.toString(), d);
|
120
|
+
} else {
|
121
|
+
amountInWei = record.amountWei;
|
122
|
+
}
|
123
|
+
const existingRecord = acc.find(
|
124
|
+
(r) => r.to.toLowerCase() === record.to.toLowerCase(),
|
125
|
+
);
|
126
|
+
if (existingRecord) {
|
127
|
+
existingRecord.amountWei = existingRecord.amountWei + amountInWei;
|
128
|
+
} else {
|
129
|
+
acc.push({
|
130
|
+
to: record.to,
|
131
|
+
amountWei: amountInWei,
|
132
|
+
});
|
133
|
+
}
|
134
|
+
|
135
|
+
return acc;
|
136
|
+
},
|
137
|
+
Promise.resolve([] as { to: string; amountWei: bigint }[]),
|
138
|
+
);
|
139
|
+
return groupedRecords;
|
140
|
+
}
|
@@ -984,7 +984,8 @@ function SwapScreenContent(props: {
|
|
984
984
|
|
985
985
|
const disableContinue =
|
986
986
|
(swapRequired && !quoteQuery.data) || isNotEnoughBalance;
|
987
|
-
const switchChainRequired =
|
987
|
+
const switchChainRequired =
|
988
|
+
props.payer.wallet.getChain()?.id !== fromChain.id;
|
988
989
|
|
989
990
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
990
991
|
function getErrorMessage(err: any) {
|
package/src/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = "5.65.
|
1
|
+
export const version = "5.65.2";
|