@fairblock/stabletrust 1.0.15 → 1.0.17
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/README.md +6 -6
- package/examples/complete-flow.js +3 -10
- package/package.json +1 -1
- package/src/client.js +18 -8
- package/src/constants.js +6 -6
- package/src/crypto.js +5 -5
package/README.md
CHANGED
|
@@ -38,12 +38,12 @@ The following contract addresses are available for confidential transfers on tes
|
|
|
38
38
|
|
|
39
39
|
| Network(Testnet) | Chain ID | Contract Address |
|
|
40
40
|
| :--------------- | :------- | :------------------------------------------- |
|
|
41
|
-
| Stable | 2201 | `
|
|
42
|
-
| Arc | 1244 | `
|
|
43
|
-
| Base | 84532 | `
|
|
44
|
-
| Ethereum | 11155111 | `
|
|
45
|
-
| Arbitrum | 421614 | `
|
|
46
|
-
| Tempo | 42431 | `
|
|
41
|
+
| Stable | 2201 | `0xB96aa42b246a956B170fE426A72fB610E4976f9E` |
|
|
42
|
+
| Arc | 1244 | `0xb20aB54e1c6AE55B0DD11FEB7FFf3fF1E9631f19` |
|
|
43
|
+
| Base | 84532 | `0x962a8A7CD28BfFBb17C4F6Ec388782cca3ffd618` |
|
|
44
|
+
| Ethereum | 11155111 | `0x2E48F3D9b8F4aCA9E6AF0630eaB2ceB7A3f5eEd1` |
|
|
45
|
+
| Arbitrum | 421614 | `0x14Afd604971bee5b5fac52df2d56CaE421519Cc5` |
|
|
46
|
+
| Tempo | 42431 | `0x08B6563C95dfe3a4F5533CAA6F7D55a74FCb4F6c` |
|
|
47
47
|
|
|
48
48
|
## Usage
|
|
49
49
|
|
|
@@ -11,9 +11,6 @@ dotenv.config();
|
|
|
11
11
|
* https://docs.fairblock.network/docs/confidential_transfers/technical_overview
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
// Optional override for custom confidential contract deployments.
|
|
15
|
-
const CONTRACT_ADDRESS =
|
|
16
|
-
process.env.CONTRACT_ADDRESS || "0xb0b461aFA69b715d842c7fAb602f50D4cef83fe5";
|
|
17
14
|
// Standard ERC20 token contract. Any ERC20 on this chain ID can be used.
|
|
18
15
|
const TOKEN_ADDRESS =
|
|
19
16
|
process.env.TOKEN_ADDRESS || "0x78Cf24370174180738C5B8E352B6D14c83a6c9A9";
|
|
@@ -42,11 +39,7 @@ async function trackPerformance(actionName, action) {
|
|
|
42
39
|
async function main() {
|
|
43
40
|
console.log("=== Starting Confidential Flow Performance Test ===\n");
|
|
44
41
|
|
|
45
|
-
const client = new ConfidentialTransferClient(
|
|
46
|
-
RPC_URL,
|
|
47
|
-
CONTRACT_ADDRESS,
|
|
48
|
-
Number(CHAIN_ID),
|
|
49
|
-
);
|
|
42
|
+
const client = new ConfidentialTransferClient(RPC_URL, Number(CHAIN_ID));
|
|
50
43
|
|
|
51
44
|
const provider = new ethers.JsonRpcProvider(RPC_URL);
|
|
52
45
|
const sender = new ethers.Wallet(process.env.SENDER_PRIVATE_KEY, provider);
|
|
@@ -170,9 +163,9 @@ async function main() {
|
|
|
170
163
|
);
|
|
171
164
|
|
|
172
165
|
// 3. WITHDRAW PHASE
|
|
173
|
-
const withdrawAmount = ethers.parseUnits("0.
|
|
166
|
+
const withdrawAmount = ethers.parseUnits("0.025", tokenDecimals);
|
|
174
167
|
console.log(
|
|
175
|
-
"Withdrawing 0.
|
|
168
|
+
"Withdrawing 0.025 tokens from confidential contract to recipient's public balance...",
|
|
176
169
|
);
|
|
177
170
|
let recipientConfidentialBalanceBeforeWithdraw =
|
|
178
171
|
await client.getConfidentialBalance(
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -778,18 +778,28 @@ export class ConfidentialTransferClient {
|
|
|
778
778
|
}
|
|
779
779
|
|
|
780
780
|
const address = await wallet.getAddress();
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
derivedKeys.privateKey,
|
|
784
|
-
tokenAddress,
|
|
785
|
-
"withdraw",
|
|
786
|
-
);
|
|
787
|
-
|
|
788
|
-
const balanceSummary = await this.getConfidentialBalance(
|
|
781
|
+
// Fetch balance first — only apply pending if available is insufficient
|
|
782
|
+
let balanceSummary = await this.getConfidentialBalance(
|
|
789
783
|
address,
|
|
790
784
|
derivedKeys.privateKey,
|
|
791
785
|
tokenAddress,
|
|
792
786
|
);
|
|
787
|
+
|
|
788
|
+
if (balanceSummary.available.amount < BigInt(amount)) {
|
|
789
|
+
await this._applyPendingIfNeeded(
|
|
790
|
+
wallet,
|
|
791
|
+
derivedKeys.privateKey,
|
|
792
|
+
tokenAddress,
|
|
793
|
+
"withdraw",
|
|
794
|
+
);
|
|
795
|
+
// Re-fetch after applying pending
|
|
796
|
+
balanceSummary = await this.getConfidentialBalance(
|
|
797
|
+
address,
|
|
798
|
+
derivedKeys.privateKey,
|
|
799
|
+
tokenAddress,
|
|
800
|
+
);
|
|
801
|
+
}
|
|
802
|
+
|
|
793
803
|
const currentBalanceCiphertext = balanceSummary.available.ciphertext;
|
|
794
804
|
const currentBalance = balanceSummary.available.amount;
|
|
795
805
|
|
package/src/constants.js
CHANGED
|
@@ -25,12 +25,12 @@ export const TEMPO_FEE_TOKEN_ADDRESS =
|
|
|
25
25
|
"0x20c0000000000000000000000000000000000000";
|
|
26
26
|
|
|
27
27
|
export const STABLETRUST_CONTRACTS_BY_CHAIN_ID = Object.freeze({
|
|
28
|
-
2201: "
|
|
29
|
-
1244: "
|
|
30
|
-
84532: "
|
|
31
|
-
11155111: "
|
|
32
|
-
421614: "
|
|
33
|
-
42431: "
|
|
28
|
+
2201: "0xB96aa42b246a956B170fE426A72fB610E4976f9E", //Stable
|
|
29
|
+
1244: "0xb20aB54e1c6AE55B0DD11FEB7FFf3fF1E9631f19", //Arc
|
|
30
|
+
84532: "0x962a8A7CD28BfFBb17C4F6Ec388782cca3ffd618", //Base
|
|
31
|
+
11155111: "0x2E48F3D9b8F4aCA9E6AF0630eaB2ceB7A3f5eEd1", //Ethereum
|
|
32
|
+
421614: "0x14Afd604971bee5b5fac52df2d56CaE421519Cc5", //Arbitrum
|
|
33
|
+
42431: "0x08B6563C95dfe3a4F5533CAA6F7D55a74FCb4F6c", //Tempo
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
export function getStableTrustContractAddress(chainId) {
|
package/src/crypto.js
CHANGED
|
@@ -11,7 +11,7 @@ import { ethers } from "ethers";
|
|
|
11
11
|
*/
|
|
12
12
|
export async function deriveKeys(wallet, config, generateKeypair) {
|
|
13
13
|
const domain = {
|
|
14
|
-
name: "
|
|
14
|
+
name: "ConfidentialTokens",
|
|
15
15
|
version: "1",
|
|
16
16
|
chainId: config.chainId,
|
|
17
17
|
verifyingContract: config.contractAddress,
|
|
@@ -26,15 +26,15 @@ export async function deriveKeys(wallet, config, generateKeypair) {
|
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
const contextHash = ethers.keccak256(
|
|
29
|
-
ethers.
|
|
29
|
+
ethers.AbiCoder.defaultAbiCoder().encode(
|
|
30
30
|
["uint256", "address", "address", "string"],
|
|
31
31
|
[config.chainId, config.contractAddress, ethers.ZeroAddress, "main"],
|
|
32
32
|
),
|
|
33
33
|
);
|
|
34
|
-
|
|
34
|
+
const userAddress = wallet.address.toLowerCase();
|
|
35
35
|
const message = {
|
|
36
36
|
purpose: "homomorphic-key-derive-v1",
|
|
37
|
-
user:
|
|
37
|
+
user: userAddress,
|
|
38
38
|
context: contextHash,
|
|
39
39
|
};
|
|
40
40
|
|
|
@@ -42,7 +42,7 @@ export async function deriveKeys(wallet, config, generateKeypair) {
|
|
|
42
42
|
const domainContext = JSON.stringify({
|
|
43
43
|
chainId: config.chainId.toString(),
|
|
44
44
|
verifyingContract: config.contractAddress,
|
|
45
|
-
user:
|
|
45
|
+
user: userAddress,
|
|
46
46
|
purpose: "homomorphic-key-derive-v1",
|
|
47
47
|
version: "1",
|
|
48
48
|
});
|