@unlink-xyz/react 0.1.5 → 0.1.7-canary.252b8ea
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/index.d.ts +152 -49
- package/dist/index.js +965 -430
- package/dist/index.js.map +1 -1
- package/dist/multisig/index.d.ts +106 -0
- package/dist/multisig/index.js +31353 -0
- package/dist/multisig/index.js.map +1 -0
- package/package.json +12 -2
package/dist/index.js
CHANGED
|
@@ -9042,9 +9042,9 @@ function genBech32(encoding) {
|
|
|
9042
9042
|
}
|
|
9043
9043
|
var bech32m = /* @__PURE__ */ genBech32("bech32m");
|
|
9044
9044
|
var VERSION = 1;
|
|
9045
|
-
var LIMIT =
|
|
9045
|
+
var LIMIT = 130;
|
|
9046
9046
|
var ALL_CHAINS = "ffffffffffffffff";
|
|
9047
|
-
var PREFIX = "
|
|
9047
|
+
var PREFIX = "unlink";
|
|
9048
9048
|
var SALT = new TextEncoder().encode("unlink");
|
|
9049
9049
|
function xorWithSalt(hex2) {
|
|
9050
9050
|
const bytes2 = Hex.toBytes(hex2);
|
|
@@ -9162,7 +9162,7 @@ function parseZkAddress(value) {
|
|
|
9162
9162
|
};
|
|
9163
9163
|
} catch (err) {
|
|
9164
9164
|
throw new ValidationError(
|
|
9165
|
-
`Invalid ZK address (expected
|
|
9165
|
+
`Invalid ZK address (expected unlink1... format): ${err instanceof Error ? err.message : "unknown error"}`
|
|
9166
9166
|
);
|
|
9167
9167
|
}
|
|
9168
9168
|
}
|
|
@@ -28352,8 +28352,8 @@ var ContractUnknownEventPayload = class extends EventPayload {
|
|
|
28352
28352
|
/**
|
|
28353
28353
|
* @_event:
|
|
28354
28354
|
*/
|
|
28355
|
-
constructor(
|
|
28356
|
-
super(
|
|
28355
|
+
constructor(contract2, listener, filter, log) {
|
|
28356
|
+
super(contract2, listener, filter);
|
|
28357
28357
|
defineProperties(this, { log });
|
|
28358
28358
|
}
|
|
28359
28359
|
/**
|
|
@@ -28379,9 +28379,9 @@ var ContractEventPayload = class extends ContractUnknownEventPayload {
|
|
|
28379
28379
|
/**
|
|
28380
28380
|
* @_ignore:
|
|
28381
28381
|
*/
|
|
28382
|
-
constructor(
|
|
28383
|
-
super(
|
|
28384
|
-
const args =
|
|
28382
|
+
constructor(contract2, listener, filter, fragment, _log) {
|
|
28383
|
+
super(contract2, listener, filter, new EventLog(_log, contract2.interface, fragment));
|
|
28384
|
+
const args = contract2.interface.decodeEventLog(fragment, this.log.data, this.log.topics);
|
|
28385
28385
|
defineProperties(this, { args, fragment });
|
|
28386
28386
|
}
|
|
28387
28387
|
/**
|
|
@@ -28424,12 +28424,12 @@ function getResolver(value) {
|
|
|
28424
28424
|
var PreparedTopicFilter = class {
|
|
28425
28425
|
#filter;
|
|
28426
28426
|
fragment;
|
|
28427
|
-
constructor(
|
|
28427
|
+
constructor(contract2, fragment, args) {
|
|
28428
28428
|
defineProperties(this, { fragment });
|
|
28429
28429
|
if (fragment.inputs.length < args.length) {
|
|
28430
28430
|
throw new Error("too many arguments");
|
|
28431
28431
|
}
|
|
28432
|
-
const runner = getRunner(
|
|
28432
|
+
const runner = getRunner(contract2.runner, "resolveName");
|
|
28433
28433
|
const resolver = canResolve(runner) ? runner : null;
|
|
28434
28434
|
this.#filter = (async function() {
|
|
28435
28435
|
const resolvedArgs = await Promise.all(fragment.inputs.map((param, index) => {
|
|
@@ -28447,7 +28447,7 @@ var PreparedTopicFilter = class {
|
|
|
28447
28447
|
return value;
|
|
28448
28448
|
});
|
|
28449
28449
|
}));
|
|
28450
|
-
return
|
|
28450
|
+
return contract2.interface.encodeFilterTopics(fragment, resolvedArgs);
|
|
28451
28451
|
})();
|
|
28452
28452
|
}
|
|
28453
28453
|
getTopicFilter() {
|
|
@@ -28496,14 +28496,14 @@ async function resolveArgs(_runner, inputs, args) {
|
|
|
28496
28496
|
});
|
|
28497
28497
|
}));
|
|
28498
28498
|
}
|
|
28499
|
-
function buildWrappedFallback(
|
|
28499
|
+
function buildWrappedFallback(contract2) {
|
|
28500
28500
|
const populateTransaction = async function(overrides) {
|
|
28501
28501
|
const tx = await copyOverrides(overrides, ["data"]);
|
|
28502
|
-
tx.to = await
|
|
28502
|
+
tx.to = await contract2.getAddress();
|
|
28503
28503
|
if (tx.from) {
|
|
28504
|
-
tx.from = await resolveAddress(tx.from, getResolver(
|
|
28504
|
+
tx.from = await resolveAddress(tx.from, getResolver(contract2.runner));
|
|
28505
28505
|
}
|
|
28506
|
-
const iface =
|
|
28506
|
+
const iface = contract2.interface;
|
|
28507
28507
|
const noValue = getBigInt(tx.value || BN_09, "overrides.value") === BN_09;
|
|
28508
28508
|
const noData = (tx.data || "0x") === "0x";
|
|
28509
28509
|
if (iface.fallback && !iface.fallback.payable && iface.receive && !noData && !noValue) {
|
|
@@ -28516,27 +28516,27 @@ function buildWrappedFallback(contract) {
|
|
|
28516
28516
|
return tx;
|
|
28517
28517
|
};
|
|
28518
28518
|
const staticCall = async function(overrides) {
|
|
28519
|
-
const runner = getRunner(
|
|
28519
|
+
const runner = getRunner(contract2.runner, "call");
|
|
28520
28520
|
assert(canCall(runner), "contract runner does not support calling", "UNSUPPORTED_OPERATION", { operation: "call" });
|
|
28521
28521
|
const tx = await populateTransaction(overrides);
|
|
28522
28522
|
try {
|
|
28523
28523
|
return await runner.call(tx);
|
|
28524
28524
|
} catch (error) {
|
|
28525
28525
|
if (isCallException(error) && error.data) {
|
|
28526
|
-
throw
|
|
28526
|
+
throw contract2.interface.makeError(error.data, tx);
|
|
28527
28527
|
}
|
|
28528
28528
|
throw error;
|
|
28529
28529
|
}
|
|
28530
28530
|
};
|
|
28531
28531
|
const send = async function(overrides) {
|
|
28532
|
-
const runner =
|
|
28532
|
+
const runner = contract2.runner;
|
|
28533
28533
|
assert(canSend(runner), "contract runner does not support sending transactions", "UNSUPPORTED_OPERATION", { operation: "sendTransaction" });
|
|
28534
28534
|
const tx = await runner.sendTransaction(await populateTransaction(overrides));
|
|
28535
|
-
const provider = getProvider(
|
|
28536
|
-
return new ContractTransactionResponse(
|
|
28535
|
+
const provider = getProvider(contract2.runner);
|
|
28536
|
+
return new ContractTransactionResponse(contract2.interface, provider, tx);
|
|
28537
28537
|
};
|
|
28538
28538
|
const estimateGas = async function(overrides) {
|
|
28539
|
-
const runner = getRunner(
|
|
28539
|
+
const runner = getRunner(contract2.runner, "estimateGas");
|
|
28540
28540
|
assert(canEstimate(runner), "contract runner does not support gas estimation", "UNSUPPORTED_OPERATION", { operation: "estimateGas" });
|
|
28541
28541
|
return await runner.estimateGas(await populateTransaction(overrides));
|
|
28542
28542
|
};
|
|
@@ -28544,7 +28544,7 @@ function buildWrappedFallback(contract) {
|
|
|
28544
28544
|
return await send(overrides);
|
|
28545
28545
|
};
|
|
28546
28546
|
defineProperties(method, {
|
|
28547
|
-
_contract:
|
|
28547
|
+
_contract: contract2,
|
|
28548
28548
|
estimateGas,
|
|
28549
28549
|
populateTransaction,
|
|
28550
28550
|
send,
|
|
@@ -28552,9 +28552,9 @@ function buildWrappedFallback(contract) {
|
|
|
28552
28552
|
});
|
|
28553
28553
|
return method;
|
|
28554
28554
|
}
|
|
28555
|
-
function buildWrappedMethod(
|
|
28555
|
+
function buildWrappedMethod(contract2, key) {
|
|
28556
28556
|
const getFragment = function(...args) {
|
|
28557
|
-
const fragment =
|
|
28557
|
+
const fragment = contract2.interface.getFunction(key, args);
|
|
28558
28558
|
assert(fragment, "no matching fragment", "UNSUPPORTED_OPERATION", {
|
|
28559
28559
|
operation: "fragment",
|
|
28560
28560
|
info: { key, args }
|
|
@@ -28567,16 +28567,16 @@ function buildWrappedMethod(contract, key) {
|
|
|
28567
28567
|
if (fragment.inputs.length + 1 === args.length) {
|
|
28568
28568
|
overrides = await copyOverrides(args.pop());
|
|
28569
28569
|
if (overrides.from) {
|
|
28570
|
-
overrides.from = await resolveAddress(overrides.from, getResolver(
|
|
28570
|
+
overrides.from = await resolveAddress(overrides.from, getResolver(contract2.runner));
|
|
28571
28571
|
}
|
|
28572
28572
|
}
|
|
28573
28573
|
if (fragment.inputs.length !== args.length) {
|
|
28574
28574
|
throw new Error("internal error: fragment inputs doesn't match arguments; should not happen");
|
|
28575
28575
|
}
|
|
28576
|
-
const resolvedArgs = await resolveArgs(
|
|
28576
|
+
const resolvedArgs = await resolveArgs(contract2.runner, fragment.inputs, args);
|
|
28577
28577
|
return Object.assign({}, overrides, await resolveProperties({
|
|
28578
|
-
to:
|
|
28579
|
-
data:
|
|
28578
|
+
to: contract2.getAddress(),
|
|
28579
|
+
data: contract2.interface.encodeFunctionData(fragment, resolvedArgs)
|
|
28580
28580
|
}));
|
|
28581
28581
|
};
|
|
28582
28582
|
const staticCall = async function(...args) {
|
|
@@ -28587,19 +28587,19 @@ function buildWrappedMethod(contract, key) {
|
|
|
28587
28587
|
return result;
|
|
28588
28588
|
};
|
|
28589
28589
|
const send = async function(...args) {
|
|
28590
|
-
const runner =
|
|
28590
|
+
const runner = contract2.runner;
|
|
28591
28591
|
assert(canSend(runner), "contract runner does not support sending transactions", "UNSUPPORTED_OPERATION", { operation: "sendTransaction" });
|
|
28592
28592
|
const tx = await runner.sendTransaction(await populateTransaction(...args));
|
|
28593
|
-
const provider = getProvider(
|
|
28594
|
-
return new ContractTransactionResponse(
|
|
28593
|
+
const provider = getProvider(contract2.runner);
|
|
28594
|
+
return new ContractTransactionResponse(contract2.interface, provider, tx);
|
|
28595
28595
|
};
|
|
28596
28596
|
const estimateGas = async function(...args) {
|
|
28597
|
-
const runner = getRunner(
|
|
28597
|
+
const runner = getRunner(contract2.runner, "estimateGas");
|
|
28598
28598
|
assert(canEstimate(runner), "contract runner does not support gas estimation", "UNSUPPORTED_OPERATION", { operation: "estimateGas" });
|
|
28599
28599
|
return await runner.estimateGas(await populateTransaction(...args));
|
|
28600
28600
|
};
|
|
28601
28601
|
const staticCallResult = async function(...args) {
|
|
28602
|
-
const runner = getRunner(
|
|
28602
|
+
const runner = getRunner(contract2.runner, "call");
|
|
28603
28603
|
assert(canCall(runner), "contract runner does not support calling", "UNSUPPORTED_OPERATION", { operation: "call" });
|
|
28604
28604
|
const tx = await populateTransaction(...args);
|
|
28605
28605
|
let result = "0x";
|
|
@@ -28607,12 +28607,12 @@ function buildWrappedMethod(contract, key) {
|
|
|
28607
28607
|
result = await runner.call(tx);
|
|
28608
28608
|
} catch (error) {
|
|
28609
28609
|
if (isCallException(error) && error.data) {
|
|
28610
|
-
throw
|
|
28610
|
+
throw contract2.interface.makeError(error.data, tx);
|
|
28611
28611
|
}
|
|
28612
28612
|
throw error;
|
|
28613
28613
|
}
|
|
28614
28614
|
const fragment = getFragment(...args);
|
|
28615
|
-
return
|
|
28615
|
+
return contract2.interface.decodeFunctionResult(fragment, result);
|
|
28616
28616
|
};
|
|
28617
28617
|
const method = async (...args) => {
|
|
28618
28618
|
const fragment = getFragment(...args);
|
|
@@ -28622,8 +28622,8 @@ function buildWrappedMethod(contract, key) {
|
|
|
28622
28622
|
return await send(...args);
|
|
28623
28623
|
};
|
|
28624
28624
|
defineProperties(method, {
|
|
28625
|
-
name:
|
|
28626
|
-
_contract:
|
|
28625
|
+
name: contract2.interface.getFunctionName(key),
|
|
28626
|
+
_contract: contract2,
|
|
28627
28627
|
_key: key,
|
|
28628
28628
|
getFragment,
|
|
28629
28629
|
estimateGas,
|
|
@@ -28636,7 +28636,7 @@ function buildWrappedMethod(contract, key) {
|
|
|
28636
28636
|
configurable: false,
|
|
28637
28637
|
enumerable: true,
|
|
28638
28638
|
get: () => {
|
|
28639
|
-
const fragment =
|
|
28639
|
+
const fragment = contract2.interface.getFunction(key);
|
|
28640
28640
|
assert(fragment, "no matching fragment", "UNSUPPORTED_OPERATION", {
|
|
28641
28641
|
operation: "fragment",
|
|
28642
28642
|
info: { key }
|
|
@@ -28646,9 +28646,9 @@ function buildWrappedMethod(contract, key) {
|
|
|
28646
28646
|
});
|
|
28647
28647
|
return method;
|
|
28648
28648
|
}
|
|
28649
|
-
function buildWrappedEvent(
|
|
28649
|
+
function buildWrappedEvent(contract2, key) {
|
|
28650
28650
|
const getFragment = function(...args) {
|
|
28651
|
-
const fragment =
|
|
28651
|
+
const fragment = contract2.interface.getEvent(key, args);
|
|
28652
28652
|
assert(fragment, "no matching fragment", "UNSUPPORTED_OPERATION", {
|
|
28653
28653
|
operation: "fragment",
|
|
28654
28654
|
info: { key, args }
|
|
@@ -28656,11 +28656,11 @@ function buildWrappedEvent(contract, key) {
|
|
|
28656
28656
|
return fragment;
|
|
28657
28657
|
};
|
|
28658
28658
|
const method = function(...args) {
|
|
28659
|
-
return new PreparedTopicFilter(
|
|
28659
|
+
return new PreparedTopicFilter(contract2, getFragment(...args), args);
|
|
28660
28660
|
};
|
|
28661
28661
|
defineProperties(method, {
|
|
28662
|
-
name:
|
|
28663
|
-
_contract:
|
|
28662
|
+
name: contract2.interface.getEventName(key),
|
|
28663
|
+
_contract: contract2,
|
|
28664
28664
|
_key: key,
|
|
28665
28665
|
getFragment
|
|
28666
28666
|
});
|
|
@@ -28668,7 +28668,7 @@ function buildWrappedEvent(contract, key) {
|
|
|
28668
28668
|
configurable: false,
|
|
28669
28669
|
enumerable: true,
|
|
28670
28670
|
get: () => {
|
|
28671
|
-
const fragment =
|
|
28671
|
+
const fragment = contract2.interface.getEvent(key);
|
|
28672
28672
|
assert(fragment, "no matching fragment", "UNSUPPORTED_OPERATION", {
|
|
28673
28673
|
operation: "fragment",
|
|
28674
28674
|
info: { key }
|
|
@@ -28680,16 +28680,16 @@ function buildWrappedEvent(contract, key) {
|
|
|
28680
28680
|
}
|
|
28681
28681
|
var internal2 = /* @__PURE__ */ Symbol.for("_ethersInternal_contract");
|
|
28682
28682
|
var internalValues = /* @__PURE__ */ new WeakMap();
|
|
28683
|
-
function setInternal(
|
|
28684
|
-
internalValues.set(
|
|
28683
|
+
function setInternal(contract2, values) {
|
|
28684
|
+
internalValues.set(contract2[internal2], values);
|
|
28685
28685
|
}
|
|
28686
|
-
function getInternal(
|
|
28687
|
-
return internalValues.get(
|
|
28686
|
+
function getInternal(contract2) {
|
|
28687
|
+
return internalValues.get(contract2[internal2]);
|
|
28688
28688
|
}
|
|
28689
28689
|
function isDeferred(value) {
|
|
28690
28690
|
return value && typeof value === "object" && "getTopicFilter" in value && typeof value.getTopicFilter === "function" && value.fragment;
|
|
28691
28691
|
}
|
|
28692
|
-
async function getSubInfo(
|
|
28692
|
+
async function getSubInfo(contract2, event) {
|
|
28693
28693
|
let topics;
|
|
28694
28694
|
let fragment = null;
|
|
28695
28695
|
if (Array.isArray(event)) {
|
|
@@ -28697,7 +28697,7 @@ async function getSubInfo(contract, event) {
|
|
|
28697
28697
|
if (isHexString(name, 32)) {
|
|
28698
28698
|
return name;
|
|
28699
28699
|
}
|
|
28700
|
-
const fragment2 =
|
|
28700
|
+
const fragment2 = contract2.interface.getEvent(name);
|
|
28701
28701
|
assertArgument(fragment2, "unknown fragment", "name", name);
|
|
28702
28702
|
return fragment2.topicHash;
|
|
28703
28703
|
};
|
|
@@ -28716,7 +28716,7 @@ async function getSubInfo(contract, event) {
|
|
|
28716
28716
|
if (isHexString(event, 32)) {
|
|
28717
28717
|
topics = [event];
|
|
28718
28718
|
} else {
|
|
28719
|
-
fragment =
|
|
28719
|
+
fragment = contract2.interface.getEvent(event);
|
|
28720
28720
|
assertArgument(fragment, "unknown fragment", "event", event);
|
|
28721
28721
|
topics = [fragment.topicHash];
|
|
28722
28722
|
}
|
|
@@ -28753,36 +28753,36 @@ async function getSubInfo(contract, event) {
|
|
|
28753
28753
|
}).join("&");
|
|
28754
28754
|
return { fragment, tag, topics };
|
|
28755
28755
|
}
|
|
28756
|
-
async function hasSub(
|
|
28757
|
-
const { subs } = getInternal(
|
|
28758
|
-
return subs.get((await getSubInfo(
|
|
28756
|
+
async function hasSub(contract2, event) {
|
|
28757
|
+
const { subs } = getInternal(contract2);
|
|
28758
|
+
return subs.get((await getSubInfo(contract2, event)).tag) || null;
|
|
28759
28759
|
}
|
|
28760
|
-
async function getSub(
|
|
28761
|
-
const provider = getProvider(
|
|
28760
|
+
async function getSub(contract2, operation, event) {
|
|
28761
|
+
const provider = getProvider(contract2.runner);
|
|
28762
28762
|
assert(provider, "contract runner does not support subscribing", "UNSUPPORTED_OPERATION", { operation });
|
|
28763
|
-
const { fragment, tag, topics } = await getSubInfo(
|
|
28764
|
-
const { addr, subs } = getInternal(
|
|
28763
|
+
const { fragment, tag, topics } = await getSubInfo(contract2, event);
|
|
28764
|
+
const { addr, subs } = getInternal(contract2);
|
|
28765
28765
|
let sub2 = subs.get(tag);
|
|
28766
28766
|
if (!sub2) {
|
|
28767
|
-
const address = addr ? addr :
|
|
28767
|
+
const address = addr ? addr : contract2;
|
|
28768
28768
|
const filter = { address, topics };
|
|
28769
28769
|
const listener = (log) => {
|
|
28770
28770
|
let foundFragment = fragment;
|
|
28771
28771
|
if (foundFragment == null) {
|
|
28772
28772
|
try {
|
|
28773
|
-
foundFragment =
|
|
28773
|
+
foundFragment = contract2.interface.getEvent(log.topics[0]);
|
|
28774
28774
|
} catch (error) {
|
|
28775
28775
|
}
|
|
28776
28776
|
}
|
|
28777
28777
|
if (foundFragment) {
|
|
28778
28778
|
const _foundFragment = foundFragment;
|
|
28779
|
-
const args = fragment ?
|
|
28780
|
-
emit22(
|
|
28781
|
-
return new ContractEventPayload(
|
|
28779
|
+
const args = fragment ? contract2.interface.decodeEventLog(fragment, log.data, log.topics) : [];
|
|
28780
|
+
emit22(contract2, event, args, (listener2) => {
|
|
28781
|
+
return new ContractEventPayload(contract2, listener2, event, _foundFragment, log);
|
|
28782
28782
|
});
|
|
28783
28783
|
} else {
|
|
28784
|
-
emit22(
|
|
28785
|
-
return new ContractUnknownEventPayload(
|
|
28784
|
+
emit22(contract2, event, [], (listener2) => {
|
|
28785
|
+
return new ContractUnknownEventPayload(contract2, listener2, event, log);
|
|
28786
28786
|
});
|
|
28787
28787
|
}
|
|
28788
28788
|
};
|
|
@@ -28808,9 +28808,9 @@ async function getSub(contract, operation, event) {
|
|
|
28808
28808
|
return sub2;
|
|
28809
28809
|
}
|
|
28810
28810
|
var lastEmit = Promise.resolve();
|
|
28811
|
-
async function _emit(
|
|
28811
|
+
async function _emit(contract2, event, args, payloadFunc) {
|
|
28812
28812
|
await lastEmit;
|
|
28813
|
-
const sub2 = await hasSub(
|
|
28813
|
+
const sub2 = await hasSub(contract2, event);
|
|
28814
28814
|
if (!sub2) {
|
|
28815
28815
|
return false;
|
|
28816
28816
|
}
|
|
@@ -28821,23 +28821,23 @@ async function _emit(contract, event, args, payloadFunc) {
|
|
|
28821
28821
|
passArgs.push(payloadFunc(once22 ? null : listener));
|
|
28822
28822
|
}
|
|
28823
28823
|
try {
|
|
28824
|
-
listener.call(
|
|
28824
|
+
listener.call(contract2, ...passArgs);
|
|
28825
28825
|
} catch (error) {
|
|
28826
28826
|
}
|
|
28827
28827
|
return !once22;
|
|
28828
28828
|
});
|
|
28829
28829
|
if (sub2.listeners.length === 0) {
|
|
28830
28830
|
sub2.stop();
|
|
28831
|
-
getInternal(
|
|
28831
|
+
getInternal(contract2).subs.delete(sub2.tag);
|
|
28832
28832
|
}
|
|
28833
28833
|
return count > 0;
|
|
28834
28834
|
}
|
|
28835
|
-
async function emit22(
|
|
28835
|
+
async function emit22(contract2, event, args, payloadFunc) {
|
|
28836
28836
|
try {
|
|
28837
28837
|
await lastEmit;
|
|
28838
28838
|
} catch (error) {
|
|
28839
28839
|
}
|
|
28840
|
-
const resultPromise = _emit(
|
|
28840
|
+
const resultPromise = _emit(contract2, event, args, payloadFunc);
|
|
28841
28841
|
lastEmit = resultPromise;
|
|
28842
28842
|
return await resultPromise;
|
|
28843
28843
|
}
|
|
@@ -29263,8 +29263,8 @@ var BaseContract = class _BaseContract {
|
|
|
29263
29263
|
if (runner == null) {
|
|
29264
29264
|
runner = null;
|
|
29265
29265
|
}
|
|
29266
|
-
const
|
|
29267
|
-
return
|
|
29266
|
+
const contract2 = new this(target, abi, runner);
|
|
29267
|
+
return contract2;
|
|
29268
29268
|
}
|
|
29269
29269
|
};
|
|
29270
29270
|
function _ContractBase() {
|
|
@@ -29559,7 +29559,7 @@ var EnsResolver = class _EnsResolver {
|
|
|
29559
29559
|
return { url: null, linkage };
|
|
29560
29560
|
}
|
|
29561
29561
|
const tokenId = comps[1];
|
|
29562
|
-
const
|
|
29562
|
+
const contract2 = new Contract(comps[0], [
|
|
29563
29563
|
// ERC-721
|
|
29564
29564
|
"function tokenURI(uint) view returns (string)",
|
|
29565
29565
|
"function ownerOf(uint) view returns (address)",
|
|
@@ -29568,21 +29568,21 @@ var EnsResolver = class _EnsResolver {
|
|
|
29568
29568
|
"function balanceOf(address, uint256) view returns (uint)"
|
|
29569
29569
|
], this.provider);
|
|
29570
29570
|
if (scheme === "erc721") {
|
|
29571
|
-
const tokenOwner = await
|
|
29571
|
+
const tokenOwner = await contract2.ownerOf(tokenId);
|
|
29572
29572
|
if (owner !== tokenOwner) {
|
|
29573
29573
|
linkage.push({ type: "!owner", value: tokenOwner });
|
|
29574
29574
|
return { url: null, linkage };
|
|
29575
29575
|
}
|
|
29576
29576
|
linkage.push({ type: "owner", value: tokenOwner });
|
|
29577
29577
|
} else if (scheme === "erc1155") {
|
|
29578
|
-
const balance = await
|
|
29578
|
+
const balance = await contract2.balanceOf(owner, tokenId);
|
|
29579
29579
|
if (!balance) {
|
|
29580
29580
|
linkage.push({ type: "!balance", value: "0" });
|
|
29581
29581
|
return { url: null, linkage };
|
|
29582
29582
|
}
|
|
29583
29583
|
linkage.push({ type: "balance", value: balance.toString() });
|
|
29584
29584
|
}
|
|
29585
|
-
let metadataUrl = await
|
|
29585
|
+
let metadataUrl = await contract2[selector](tokenId);
|
|
29586
29586
|
if (metadataUrl == null || metadataUrl === "0x") {
|
|
29587
29587
|
linkage.push({ type: "!metadata-url", value: "" });
|
|
29588
29588
|
return { url: null, linkage };
|
|
@@ -29654,10 +29654,10 @@ var EnsResolver = class _EnsResolver {
|
|
|
29654
29654
|
static async #getResolver(provider, name) {
|
|
29655
29655
|
const ensAddr = await _EnsResolver.getEnsAddress(provider);
|
|
29656
29656
|
try {
|
|
29657
|
-
const
|
|
29657
|
+
const contract2 = new Contract(ensAddr, [
|
|
29658
29658
|
"function resolver(bytes32) view returns (address)"
|
|
29659
29659
|
], provider);
|
|
29660
|
-
const addr = await
|
|
29660
|
+
const addr = await contract2.resolver(namehash(name), {
|
|
29661
29661
|
enableCcipRead: true
|
|
29662
29662
|
});
|
|
29663
29663
|
if (addr === ZeroAddress) {
|
|
@@ -35647,29 +35647,41 @@ function createJsonHttpClient(baseUrl, deps) {
|
|
|
35647
35647
|
fetch: fetchImpl,
|
|
35648
35648
|
// Disable ky's automatic error throwing to prevent browser DevTools
|
|
35649
35649
|
// from logging expected 404s as network errors
|
|
35650
|
-
throwHttpErrors: false
|
|
35650
|
+
throwHttpErrors: false,
|
|
35651
|
+
retry: 0
|
|
35651
35652
|
});
|
|
35653
|
+
const RETRYABLE_STATUSES = [502, 503, 504];
|
|
35654
|
+
const MAX_RETRIES = 3;
|
|
35655
|
+
const BASE_DELAY_MS = 500;
|
|
35652
35656
|
return {
|
|
35653
35657
|
async request(opts) {
|
|
35654
35658
|
let res;
|
|
35655
|
-
|
|
35656
|
-
|
|
35657
|
-
|
|
35658
|
-
|
|
35659
|
-
|
|
35660
|
-
|
|
35661
|
-
|
|
35662
|
-
|
|
35663
|
-
|
|
35664
|
-
|
|
35665
|
-
|
|
35666
|
-
|
|
35659
|
+
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
35660
|
+
try {
|
|
35661
|
+
res = await api(opts.path.replace(/^\//, ""), {
|
|
35662
|
+
method: opts.method,
|
|
35663
|
+
searchParams: opts.query,
|
|
35664
|
+
json: opts.json,
|
|
35665
|
+
body: opts.body,
|
|
35666
|
+
headers: opts.headers,
|
|
35667
|
+
signal: opts.signal
|
|
35668
|
+
});
|
|
35669
|
+
} catch (err) {
|
|
35670
|
+
if (err instanceof TimeoutError) {
|
|
35671
|
+
throw new HttpError("HTTP timeout", 408, null);
|
|
35672
|
+
}
|
|
35673
|
+
throw new HttpError(
|
|
35674
|
+
err instanceof Error ? err.message : "Network error",
|
|
35675
|
+
0,
|
|
35676
|
+
null
|
|
35677
|
+
);
|
|
35667
35678
|
}
|
|
35668
|
-
|
|
35669
|
-
|
|
35670
|
-
|
|
35671
|
-
|
|
35672
|
-
|
|
35679
|
+
if (RETRYABLE_STATUSES.includes(res.status) && attempt < MAX_RETRIES) {
|
|
35680
|
+
const delay2 = BASE_DELAY_MS * 2 ** attempt + Math.random() * 200;
|
|
35681
|
+
await new Promise((r2) => setTimeout(r2, delay2));
|
|
35682
|
+
continue;
|
|
35683
|
+
}
|
|
35684
|
+
break;
|
|
35673
35685
|
}
|
|
35674
35686
|
if (!res.ok) {
|
|
35675
35687
|
const body = await readErrorBodySafe(res);
|
|
@@ -35871,63 +35883,110 @@ var Runtime = {
|
|
|
35871
35883
|
}
|
|
35872
35884
|
};
|
|
35873
35885
|
var CONFIG_URL = "https://config.unlink.xyz/networks.json";
|
|
35874
|
-
function parseRequiredString(
|
|
35886
|
+
function parseRequiredString(chain2, field, value) {
|
|
35875
35887
|
if (typeof value !== "string" || value.trim().length === 0) {
|
|
35876
35888
|
throw new InitializationError(
|
|
35877
|
-
`Invalid SDK config for ${
|
|
35889
|
+
`Invalid SDK config for ${chain2}: ${field} must be a non-empty string`
|
|
35878
35890
|
);
|
|
35879
35891
|
}
|
|
35880
35892
|
return value.trim();
|
|
35881
35893
|
}
|
|
35882
|
-
function parseOptionalString(
|
|
35894
|
+
function parseOptionalString(chain2, field, value) {
|
|
35883
35895
|
if (value === void 0) return void 0;
|
|
35884
35896
|
if (typeof value !== "string" || value.trim().length === 0) {
|
|
35885
35897
|
throw new InitializationError(
|
|
35886
|
-
`Invalid SDK config for ${
|
|
35898
|
+
`Invalid SDK config for ${chain2}: ${field} must be a non-empty string when provided`
|
|
35887
35899
|
);
|
|
35888
35900
|
}
|
|
35889
35901
|
return value.trim();
|
|
35890
35902
|
}
|
|
35891
|
-
function
|
|
35903
|
+
function parseRequiredChainId(chain2, value) {
|
|
35904
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) {
|
|
35905
|
+
throw new InitializationError(
|
|
35906
|
+
`Invalid SDK config for ${chain2}: chainId must be a positive integer`
|
|
35907
|
+
);
|
|
35908
|
+
}
|
|
35909
|
+
return value;
|
|
35910
|
+
}
|
|
35911
|
+
function parseChainConfig(chain2, value) {
|
|
35892
35912
|
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
35893
35913
|
throw new InitializationError(
|
|
35894
|
-
`Invalid SDK config for ${
|
|
35914
|
+
`Invalid SDK config for ${chain2}: expected object`
|
|
35895
35915
|
);
|
|
35896
35916
|
}
|
|
35897
35917
|
const raw = value;
|
|
35918
|
+
const chainId = parseRequiredChainId(chain2, raw.chainId);
|
|
35898
35919
|
const gatewayUrl = parseRequiredString(
|
|
35899
|
-
|
|
35920
|
+
chain2,
|
|
35900
35921
|
"gatewayUrl",
|
|
35901
35922
|
raw.gatewayUrl
|
|
35902
35923
|
).replace(/\/+$/, "");
|
|
35903
|
-
const poolAddress = parseRequiredString(
|
|
35924
|
+
const poolAddress = parseRequiredString(
|
|
35925
|
+
chain2,
|
|
35926
|
+
"poolAddress",
|
|
35927
|
+
raw.poolAddress
|
|
35928
|
+
);
|
|
35904
35929
|
const artifactVersion = parseRequiredString(
|
|
35905
|
-
|
|
35930
|
+
chain2,
|
|
35906
35931
|
"artifactVersion",
|
|
35907
35932
|
raw.artifactVersion
|
|
35908
35933
|
).replace(/^\/+|\/+$/g, "");
|
|
35934
|
+
const adapterAddress = parseOptionalString(
|
|
35935
|
+
chain2,
|
|
35936
|
+
"adapterAddress",
|
|
35937
|
+
raw.adapterAddress
|
|
35938
|
+
);
|
|
35939
|
+
const frostUrl = parseOptionalString(
|
|
35940
|
+
chain2,
|
|
35941
|
+
"frostUrl",
|
|
35942
|
+
raw.frostUrl
|
|
35943
|
+
)?.replace(/\/+$/, "");
|
|
35909
35944
|
const artifactBaseUrl = parseOptionalString(
|
|
35910
|
-
|
|
35945
|
+
chain2,
|
|
35911
35946
|
"artifactBaseUrl",
|
|
35912
35947
|
raw.artifactBaseUrl
|
|
35913
35948
|
)?.replace(/\/+$/, "");
|
|
35949
|
+
let tokenAddresses;
|
|
35950
|
+
if (raw.tokenAddresses !== void 0) {
|
|
35951
|
+
if (raw.tokenAddresses === null || typeof raw.tokenAddresses !== "object" || Array.isArray(raw.tokenAddresses)) {
|
|
35952
|
+
throw new InitializationError(
|
|
35953
|
+
`Invalid SDK config for ${chain2}: tokenAddresses must be an object`
|
|
35954
|
+
);
|
|
35955
|
+
}
|
|
35956
|
+
tokenAddresses = {};
|
|
35957
|
+
for (const [name, addr] of Object.entries(
|
|
35958
|
+
raw.tokenAddresses
|
|
35959
|
+
)) {
|
|
35960
|
+
tokenAddresses[name] = parseRequiredString(
|
|
35961
|
+
chain2,
|
|
35962
|
+
`tokenAddresses.${name}`,
|
|
35963
|
+
addr
|
|
35964
|
+
);
|
|
35965
|
+
}
|
|
35966
|
+
}
|
|
35914
35967
|
return {
|
|
35968
|
+
chainId,
|
|
35915
35969
|
gatewayUrl,
|
|
35970
|
+
...frostUrl !== void 0 ? { frostUrl } : {},
|
|
35916
35971
|
poolAddress,
|
|
35972
|
+
...adapterAddress !== void 0 ? { adapterAddress } : {},
|
|
35917
35973
|
artifactVersion,
|
|
35918
|
-
...artifactBaseUrl !== void 0 ? { artifactBaseUrl } : { artifactBaseUrl: DEFAULT_ARTIFACT_BASE_URL }
|
|
35974
|
+
...artifactBaseUrl !== void 0 ? { artifactBaseUrl } : { artifactBaseUrl: DEFAULT_ARTIFACT_BASE_URL },
|
|
35975
|
+
...tokenAddresses !== void 0 ? { tokenAddresses } : {}
|
|
35919
35976
|
};
|
|
35920
35977
|
}
|
|
35921
|
-
async function
|
|
35978
|
+
async function fetchChainConfig(chain2) {
|
|
35922
35979
|
const res = await fetch(CONFIG_URL);
|
|
35923
35980
|
if (!res.ok) {
|
|
35924
35981
|
throw new InitializationError(`Failed to fetch SDK config: ${res.status}`);
|
|
35925
35982
|
}
|
|
35926
35983
|
const config22 = await res.json();
|
|
35927
|
-
if (!config22[
|
|
35928
|
-
throw new InitializationError(
|
|
35984
|
+
if (!config22[chain2]) {
|
|
35985
|
+
throw new InitializationError(
|
|
35986
|
+
`Unknown chain: "${chain2}". Supported chains: ${Object.keys(config22).join(", ")}`
|
|
35987
|
+
);
|
|
35929
35988
|
}
|
|
35930
|
-
return
|
|
35989
|
+
return parseChainConfig(chain2, config22[chain2]);
|
|
35931
35990
|
}
|
|
35932
35991
|
function createServiceConfig(gatewayUrl) {
|
|
35933
35992
|
const baseUrl = gatewayUrl.replace(/\/+$/, "");
|
|
@@ -53316,6 +53375,114 @@ var circuits_default = {
|
|
|
53316
53375
|
template: "JoinSplit",
|
|
53317
53376
|
pubs: ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
53318
53377
|
params: [5, 2, 16]
|
|
53378
|
+
},
|
|
53379
|
+
joinsplit_1x3_16: {
|
|
53380
|
+
file: "joinsplit",
|
|
53381
|
+
template: "JoinSplit",
|
|
53382
|
+
pubs: ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
53383
|
+
params: [1, 3, 16]
|
|
53384
|
+
},
|
|
53385
|
+
joinsplit_4x3_16: {
|
|
53386
|
+
file: "joinsplit",
|
|
53387
|
+
template: "JoinSplit",
|
|
53388
|
+
pubs: ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
53389
|
+
params: [4, 3, 16]
|
|
53390
|
+
},
|
|
53391
|
+
joinsplit_5x3_16: {
|
|
53392
|
+
file: "joinsplit",
|
|
53393
|
+
template: "JoinSplit",
|
|
53394
|
+
pubs: ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
53395
|
+
params: [5, 3, 16]
|
|
53396
|
+
},
|
|
53397
|
+
joinsplit_6x1_16: {
|
|
53398
|
+
file: "joinsplit",
|
|
53399
|
+
template: "JoinSplit",
|
|
53400
|
+
pubs: ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
53401
|
+
params: [6, 1, 16]
|
|
53402
|
+
},
|
|
53403
|
+
joinsplit_6x2_16: {
|
|
53404
|
+
file: "joinsplit",
|
|
53405
|
+
template: "JoinSplit",
|
|
53406
|
+
pubs: ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
53407
|
+
params: [6, 2, 16]
|
|
53408
|
+
},
|
|
53409
|
+
joinsplit_6x3_16: {
|
|
53410
|
+
file: "joinsplit",
|
|
53411
|
+
template: "JoinSplit",
|
|
53412
|
+
pubs: ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
53413
|
+
params: [6, 3, 16]
|
|
53414
|
+
},
|
|
53415
|
+
joinsplit_7x1_16: {
|
|
53416
|
+
file: "joinsplit",
|
|
53417
|
+
template: "JoinSplit",
|
|
53418
|
+
pubs: ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
53419
|
+
params: [7, 1, 16]
|
|
53420
|
+
},
|
|
53421
|
+
joinsplit_7x2_16: {
|
|
53422
|
+
file: "joinsplit",
|
|
53423
|
+
template: "JoinSplit",
|
|
53424
|
+
pubs: ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
53425
|
+
params: [7, 2, 16]
|
|
53426
|
+
},
|
|
53427
|
+
joinsplit_7x3_16: {
|
|
53428
|
+
file: "joinsplit",
|
|
53429
|
+
template: "JoinSplit",
|
|
53430
|
+
pubs: ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
53431
|
+
params: [7, 3, 16]
|
|
53432
|
+
},
|
|
53433
|
+
joinsplit_8x1_16: {
|
|
53434
|
+
file: "joinsplit",
|
|
53435
|
+
template: "JoinSplit",
|
|
53436
|
+
pubs: ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
53437
|
+
params: [8, 1, 16]
|
|
53438
|
+
},
|
|
53439
|
+
joinsplit_8x2_16: {
|
|
53440
|
+
file: "joinsplit",
|
|
53441
|
+
template: "JoinSplit",
|
|
53442
|
+
pubs: ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
53443
|
+
params: [8, 2, 16]
|
|
53444
|
+
},
|
|
53445
|
+
joinsplit_8x3_16: {
|
|
53446
|
+
file: "joinsplit",
|
|
53447
|
+
template: "JoinSplit",
|
|
53448
|
+
pubs: ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
53449
|
+
params: [8, 3, 16]
|
|
53450
|
+
},
|
|
53451
|
+
joinsplit_9x1_16: {
|
|
53452
|
+
file: "joinsplit",
|
|
53453
|
+
template: "JoinSplit",
|
|
53454
|
+
pubs: ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
53455
|
+
params: [9, 1, 16]
|
|
53456
|
+
},
|
|
53457
|
+
joinsplit_9x2_16: {
|
|
53458
|
+
file: "joinsplit",
|
|
53459
|
+
template: "JoinSplit",
|
|
53460
|
+
pubs: ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
53461
|
+
params: [9, 2, 16]
|
|
53462
|
+
},
|
|
53463
|
+
joinsplit_9x3_16: {
|
|
53464
|
+
file: "joinsplit",
|
|
53465
|
+
template: "JoinSplit",
|
|
53466
|
+
pubs: ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
53467
|
+
params: [9, 3, 16]
|
|
53468
|
+
},
|
|
53469
|
+
joinsplit_10x1_16: {
|
|
53470
|
+
file: "joinsplit",
|
|
53471
|
+
template: "JoinSplit",
|
|
53472
|
+
pubs: ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
53473
|
+
params: [10, 1, 16]
|
|
53474
|
+
},
|
|
53475
|
+
joinsplit_10x2_16: {
|
|
53476
|
+
file: "joinsplit",
|
|
53477
|
+
template: "JoinSplit",
|
|
53478
|
+
pubs: ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
53479
|
+
params: [10, 2, 16]
|
|
53480
|
+
},
|
|
53481
|
+
joinsplit_10x3_16: {
|
|
53482
|
+
file: "joinsplit",
|
|
53483
|
+
template: "JoinSplit",
|
|
53484
|
+
pubs: ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
53485
|
+
params: [10, 3, 16]
|
|
53319
53486
|
}
|
|
53320
53487
|
};
|
|
53321
53488
|
var registry = {};
|
|
@@ -53331,7 +53498,7 @@ var SUPPORTED_CIRCUITS = Object.keys(CIRCUIT_REGISTRY);
|
|
|
53331
53498
|
function getCircuitConfig(inputs, outputs) {
|
|
53332
53499
|
return CIRCUIT_REGISTRY[`${inputs}x${outputs}`];
|
|
53333
53500
|
}
|
|
53334
|
-
var MAX_ARTIFACT_CACHE_ENTRIES =
|
|
53501
|
+
var MAX_ARTIFACT_CACHE_ENTRIES = 16;
|
|
53335
53502
|
var artifactCache = /* @__PURE__ */ new Map();
|
|
53336
53503
|
function selectCircuit(inputs, outputs) {
|
|
53337
53504
|
const config22 = getCircuitConfig(inputs, outputs);
|
|
@@ -54166,6 +54333,58 @@ function normalizeReshield(reshield, index) {
|
|
|
54166
54333
|
);
|
|
54167
54334
|
return { npk, random, token, minAmount };
|
|
54168
54335
|
}
|
|
54336
|
+
function approve(token, spender, amount) {
|
|
54337
|
+
const normalizedToken = ensureAddress("token", token);
|
|
54338
|
+
const normalizedSpender = ensureAddress("spender", spender);
|
|
54339
|
+
const normalizedAmount = ensureNonNegative("amount", amount);
|
|
54340
|
+
const data = approveInterface.encodeFunctionData("approve", [
|
|
54341
|
+
normalizedSpender,
|
|
54342
|
+
normalizedAmount
|
|
54343
|
+
]);
|
|
54344
|
+
return {
|
|
54345
|
+
to: normalizedToken,
|
|
54346
|
+
data,
|
|
54347
|
+
value: 0n
|
|
54348
|
+
};
|
|
54349
|
+
}
|
|
54350
|
+
function toCall(tx) {
|
|
54351
|
+
if (tx.to == null) {
|
|
54352
|
+
throw new AdapterError("tx.to is required");
|
|
54353
|
+
}
|
|
54354
|
+
const to = ensureAddress("tx.to", tx.to);
|
|
54355
|
+
if (tx.data == null) {
|
|
54356
|
+
throw new AdapterError("tx.data is required");
|
|
54357
|
+
}
|
|
54358
|
+
const data = ensureHexData("tx.data", tx.data);
|
|
54359
|
+
let value;
|
|
54360
|
+
if (tx.value == null) {
|
|
54361
|
+
value = 0n;
|
|
54362
|
+
} else {
|
|
54363
|
+
try {
|
|
54364
|
+
value = BigInt(tx.value);
|
|
54365
|
+
} catch {
|
|
54366
|
+
throw new AdapterError(
|
|
54367
|
+
`tx.value must be convertible to bigint, received: ${String(tx.value)}`
|
|
54368
|
+
);
|
|
54369
|
+
}
|
|
54370
|
+
}
|
|
54371
|
+
return { to, data, value: ensureNonNegative("tx.value", value) };
|
|
54372
|
+
}
|
|
54373
|
+
function contract(address, abi) {
|
|
54374
|
+
const to = ensureAddress("contract.address", address);
|
|
54375
|
+
const iface = new Interface(abi);
|
|
54376
|
+
return new Proxy(
|
|
54377
|
+
{},
|
|
54378
|
+
{
|
|
54379
|
+
get(_, method) {
|
|
54380
|
+
return (...args) => {
|
|
54381
|
+
const data = iface.encodeFunctionData(method, args);
|
|
54382
|
+
return { to, data, value: 0n };
|
|
54383
|
+
};
|
|
54384
|
+
}
|
|
54385
|
+
}
|
|
54386
|
+
);
|
|
54387
|
+
}
|
|
54169
54388
|
function encodeAdapterExecute(params) {
|
|
54170
54389
|
const transactCalldata = ensureHexData(
|
|
54171
54390
|
"transactCalldata",
|
|
@@ -54189,6 +54408,7 @@ function encodeAdapterExecute(params) {
|
|
|
54189
54408
|
deadline
|
|
54190
54409
|
]);
|
|
54191
54410
|
}
|
|
54411
|
+
var buildApproveCall = approve;
|
|
54192
54412
|
init_process();
|
|
54193
54413
|
init_buffer();
|
|
54194
54414
|
init_process();
|
|
@@ -55575,26 +55795,34 @@ function normalizeCall2(call, index) {
|
|
|
55575
55795
|
value: call.value
|
|
55576
55796
|
};
|
|
55577
55797
|
}
|
|
55578
|
-
function
|
|
55579
|
-
const token = ensureAddress(`
|
|
55798
|
+
function normalizeSpendInput(input, index) {
|
|
55799
|
+
const token = ensureAddress(`spend[${index}].token`, input.token);
|
|
55800
|
+
if (token.toLowerCase() === ETH_TOKEN.toLowerCase()) {
|
|
55801
|
+
throw new AdapterError(
|
|
55802
|
+
`spend[${index}].token: native ETH is not supported in adapter execution`
|
|
55803
|
+
);
|
|
55804
|
+
}
|
|
55580
55805
|
if (input.amount <= 0n) {
|
|
55581
|
-
throw new AdapterError(`
|
|
55806
|
+
throw new AdapterError(`spend[${index}].amount must be greater than zero`);
|
|
55582
55807
|
}
|
|
55583
55808
|
return {
|
|
55584
55809
|
token,
|
|
55585
55810
|
amount: input.amount
|
|
55586
55811
|
};
|
|
55587
55812
|
}
|
|
55588
|
-
function
|
|
55589
|
-
const token = ensureAddress(`
|
|
55590
|
-
if (
|
|
55813
|
+
function normalizeReceiveInput(receive, index) {
|
|
55814
|
+
const token = ensureAddress(`receive[${index}].token`, receive.token);
|
|
55815
|
+
if (token.toLowerCase() === ETH_TOKEN.toLowerCase()) {
|
|
55591
55816
|
throw new AdapterError(
|
|
55592
|
-
`
|
|
55817
|
+
`receive[${index}].token: native ETH is not supported in adapter execution`
|
|
55593
55818
|
);
|
|
55594
55819
|
}
|
|
55820
|
+
if (receive.minAmount < 0n) {
|
|
55821
|
+
throw new AdapterError(`receive[${index}].minAmount must be non-negative`);
|
|
55822
|
+
}
|
|
55595
55823
|
return {
|
|
55596
55824
|
token,
|
|
55597
|
-
minAmount:
|
|
55825
|
+
minAmount: receive.minAmount
|
|
55598
55826
|
};
|
|
55599
55827
|
}
|
|
55600
55828
|
function randomFieldElement(randomBigintFn) {
|
|
@@ -55614,32 +55842,42 @@ function createAdapterService(deps) {
|
|
|
55614
55842
|
"adapterAddress",
|
|
55615
55843
|
params.adapterAddress
|
|
55616
55844
|
);
|
|
55617
|
-
if (!params.
|
|
55618
|
-
throw new AdapterError("at least one
|
|
55845
|
+
if (!params.spend.length) {
|
|
55846
|
+
throw new AdapterError("at least one spend token is required");
|
|
55619
55847
|
}
|
|
55620
55848
|
if (!params.calls.length) {
|
|
55621
55849
|
throw new AdapterError("at least one adapter call is required");
|
|
55622
55850
|
}
|
|
55623
|
-
if (!params.
|
|
55624
|
-
throw new AdapterError("at least one
|
|
55851
|
+
if (!params.receive.length) {
|
|
55852
|
+
throw new AdapterError("at least one receive output is required");
|
|
55625
55853
|
}
|
|
55626
|
-
const
|
|
55627
|
-
(input, i) =>
|
|
55854
|
+
const spendInputs = params.spend.map(
|
|
55855
|
+
(input, i) => normalizeSpendInput(input, i)
|
|
55628
55856
|
);
|
|
55629
55857
|
const seenTokens = /* @__PURE__ */ new Set();
|
|
55630
|
-
for (const input of
|
|
55858
|
+
for (const input of spendInputs) {
|
|
55631
55859
|
const lower = input.token.toLowerCase();
|
|
55632
55860
|
if (seenTokens.has(lower)) {
|
|
55633
55861
|
throw new AdapterError(
|
|
55634
|
-
`duplicate
|
|
55862
|
+
`duplicate spend token ${input.token}; combine amounts per token instead`
|
|
55635
55863
|
);
|
|
55636
55864
|
}
|
|
55637
55865
|
seenTokens.add(lower);
|
|
55638
55866
|
}
|
|
55639
55867
|
const calls = params.calls.map((call, i) => normalizeCall2(call, i));
|
|
55640
|
-
const
|
|
55641
|
-
(
|
|
55868
|
+
const receiveSpecs = params.receive.map(
|
|
55869
|
+
(receive, i) => normalizeReceiveInput(receive, i)
|
|
55642
55870
|
);
|
|
55871
|
+
const seenReceiveTokens = /* @__PURE__ */ new Set();
|
|
55872
|
+
for (const r2 of receiveSpecs) {
|
|
55873
|
+
const lower = r2.token.toLowerCase();
|
|
55874
|
+
if (seenReceiveTokens.has(lower)) {
|
|
55875
|
+
throw new AdapterError(
|
|
55876
|
+
`duplicate receive token ${r2.token}; each receive must target a unique token`
|
|
55877
|
+
);
|
|
55878
|
+
}
|
|
55879
|
+
seenReceiveTokens.add(lower);
|
|
55880
|
+
}
|
|
55643
55881
|
const account = overrides?.account ?? await deps.requireActiveAccount();
|
|
55644
55882
|
const signer = overrides?.signer ?? deps.requireSigner(account);
|
|
55645
55883
|
const nowSeconds = BigInt(Math.floor(nowImpl() / 1e3));
|
|
@@ -55648,19 +55886,19 @@ function createAdapterService(deps) {
|
|
|
55648
55886
|
throw new AdapterError("deadline must be in the future");
|
|
55649
55887
|
}
|
|
55650
55888
|
const executionCalls = calls;
|
|
55651
|
-
const reshields =
|
|
55652
|
-
(
|
|
55889
|
+
const reshields = receiveSpecs.map(
|
|
55890
|
+
(receive) => {
|
|
55653
55891
|
const random = randomFieldElement(randomBigintImpl);
|
|
55654
55892
|
const npk = poseidon([account.masterPublicKey, random]);
|
|
55655
55893
|
return {
|
|
55656
55894
|
npk,
|
|
55657
55895
|
random,
|
|
55658
|
-
token:
|
|
55659
|
-
minAmount:
|
|
55896
|
+
token: receive.token,
|
|
55897
|
+
minAmount: receive.minAmount
|
|
55660
55898
|
};
|
|
55661
55899
|
}
|
|
55662
55900
|
);
|
|
55663
|
-
const inputTokens =
|
|
55901
|
+
const inputTokens = spendInputs.map((input) => input.token);
|
|
55664
55902
|
const nonce = randomFieldElement(randomBigintImpl);
|
|
55665
55903
|
const adapterDataHash = computeAdapterDataHash({
|
|
55666
55904
|
calls: executionCalls,
|
|
@@ -55677,7 +55915,7 @@ function createAdapterService(deps) {
|
|
|
55677
55915
|
});
|
|
55678
55916
|
const withdrawalPlans = planWithdrawalsImpl(
|
|
55679
55917
|
notes,
|
|
55680
|
-
|
|
55918
|
+
spendInputs.map((input) => ({
|
|
55681
55919
|
token: input.token,
|
|
55682
55920
|
amount: input.amount,
|
|
55683
55921
|
recipient: adapterAddress
|
|
@@ -55760,7 +55998,7 @@ function createAdapterService(deps) {
|
|
|
55760
55998
|
adapterCalldata,
|
|
55761
55999
|
historyPreview: {
|
|
55762
56000
|
kind: "Withdraw",
|
|
55763
|
-
amounts:
|
|
56001
|
+
amounts: spendInputs.map((input) => ({
|
|
55764
56002
|
token: input.token,
|
|
55765
56003
|
delta: (-input.amount).toString()
|
|
55766
56004
|
}))
|
|
@@ -55780,6 +56018,9 @@ init_process();
|
|
|
55780
56018
|
init_buffer();
|
|
55781
56019
|
var BIP44_ETH_PREFIX = "m/44'/60'/0'/0";
|
|
55782
56020
|
var ERC20_BALANCE_OF = "function balanceOf(address) view returns (uint256)";
|
|
56021
|
+
function isNativeToken(token) {
|
|
56022
|
+
return token.toLowerCase() === ETH_TOKEN.toLowerCase();
|
|
56023
|
+
}
|
|
55783
56024
|
function createBurnerService(deps) {
|
|
55784
56025
|
const { chainRpcUrl, getMasterSeed, withdrawToAddress, requestDeposit } = deps;
|
|
55785
56026
|
const provider = new JsonRpcProvider(chainRpcUrl);
|
|
@@ -55827,8 +56068,8 @@ function createBurnerService(deps) {
|
|
|
55827
56068
|
}
|
|
55828
56069
|
async function getTokenBalance(address, token) {
|
|
55829
56070
|
const iface = new Interface([ERC20_BALANCE_OF]);
|
|
55830
|
-
const
|
|
55831
|
-
const bal = await
|
|
56071
|
+
const contract2 = new Contract(token, iface, provider);
|
|
56072
|
+
const bal = await contract2.getFunction("balanceOf")(address);
|
|
55832
56073
|
return BigInt(bal ?? 0);
|
|
55833
56074
|
}
|
|
55834
56075
|
async function getBalance(address) {
|
|
@@ -55847,6 +56088,12 @@ function createBurnerService(deps) {
|
|
|
55847
56088
|
}
|
|
55848
56089
|
async function sweepToPool(index, params) {
|
|
55849
56090
|
const { address } = await addressOf(index);
|
|
56091
|
+
const native = isNativeToken(params.token);
|
|
56092
|
+
if (native && params.amount == null) {
|
|
56093
|
+
throw new Error(
|
|
56094
|
+
"amount is required for native ETH sweeps (needed to reserve gas)"
|
|
56095
|
+
);
|
|
56096
|
+
}
|
|
55850
56097
|
const amount = params.amount ?? await getTokenBalance(address, params.token);
|
|
55851
56098
|
if (amount === 0n) {
|
|
55852
56099
|
throw new Error("No token balance to sweep");
|
|
@@ -55857,17 +56104,20 @@ function createBurnerService(deps) {
|
|
|
55857
56104
|
depositor: address,
|
|
55858
56105
|
deposits: [{ token: params.token, amount }]
|
|
55859
56106
|
});
|
|
55860
|
-
|
|
55861
|
-
|
|
55862
|
-
|
|
55863
|
-
|
|
55864
|
-
|
|
55865
|
-
|
|
55866
|
-
|
|
55867
|
-
|
|
56107
|
+
if (!native) {
|
|
56108
|
+
const erc20Iface = new Interface([
|
|
56109
|
+
"function approve(address spender, uint256 amount)"
|
|
56110
|
+
]);
|
|
56111
|
+
const approveData = erc20Iface.encodeFunctionData("approve", [
|
|
56112
|
+
params.poolAddress,
|
|
56113
|
+
amount
|
|
56114
|
+
]);
|
|
56115
|
+
await send(index, { to: params.token, data: approveData });
|
|
56116
|
+
}
|
|
55868
56117
|
const { txHash } = await send(index, {
|
|
55869
56118
|
to: depositResult.to,
|
|
55870
|
-
data: depositResult.calldata
|
|
56119
|
+
data: depositResult.calldata,
|
|
56120
|
+
value: depositResult.value
|
|
55871
56121
|
});
|
|
55872
56122
|
return { txHash };
|
|
55873
56123
|
}
|
|
@@ -56520,50 +56770,62 @@ function createWalletSDK(deps, options) {
|
|
|
56520
56770
|
};
|
|
56521
56771
|
return sdk;
|
|
56522
56772
|
}
|
|
56523
|
-
var
|
|
56773
|
+
var Unlink = class _Unlink {
|
|
56524
56774
|
/** @internal */
|
|
56525
56775
|
sdk;
|
|
56526
56776
|
/** Chain ID this wallet operates on. */
|
|
56527
56777
|
chainId;
|
|
56528
56778
|
/** Pool contract address this wallet transacts with. */
|
|
56529
56779
|
poolAddress;
|
|
56530
|
-
|
|
56780
|
+
/** Adapter contract address for DeFi operations. */
|
|
56781
|
+
adapterAddress;
|
|
56782
|
+
constructor(sdk, chainId, poolAddress, adapterAddress) {
|
|
56531
56783
|
this.sdk = sdk;
|
|
56532
56784
|
this.chainId = chainId;
|
|
56533
56785
|
this.poolAddress = poolAddress;
|
|
56786
|
+
this.adapterAddress = adapterAddress;
|
|
56787
|
+
this.adapter = {
|
|
56788
|
+
address: adapterAddress
|
|
56789
|
+
};
|
|
56534
56790
|
}
|
|
56535
56791
|
/**
|
|
56536
|
-
* Create a new
|
|
56792
|
+
* Create a new Unlink instance.
|
|
56537
56793
|
*
|
|
56538
56794
|
* Handles all initialization internally:
|
|
56539
|
-
* - Resolves
|
|
56795
|
+
* - Resolves chain config (if using `chain` instead of explicit URLs)
|
|
56540
56796
|
* - Auto-detects storage (IndexedDB in browser) and rng (crypto.getRandomValues)
|
|
56541
56797
|
* - Runs schema migration via `initCore()`
|
|
56542
56798
|
* - Creates the internal SDK
|
|
56543
56799
|
*/
|
|
56544
56800
|
static async create(config22) {
|
|
56801
|
+
let chainId;
|
|
56545
56802
|
let gatewayUrl;
|
|
56546
56803
|
let poolAddress;
|
|
56804
|
+
let adapterAddress;
|
|
56547
56805
|
let proverConfig = config22.prover;
|
|
56548
|
-
if ("
|
|
56806
|
+
if ("chain" in config22) {
|
|
56807
|
+
const chainConfig = await fetchChainConfig(config22.chain);
|
|
56808
|
+
chainId = chainConfig.chainId;
|
|
56809
|
+
gatewayUrl = chainConfig.gatewayUrl;
|
|
56810
|
+
poolAddress = config22.poolAddress ?? chainConfig.poolAddress;
|
|
56811
|
+
adapterAddress = config22.adapterAddress ?? chainConfig.adapterAddress;
|
|
56812
|
+
proverConfig = {
|
|
56813
|
+
artifactSource: {
|
|
56814
|
+
baseUrl: config22.prover?.artifactSource?.baseUrl ?? chainConfig.artifactBaseUrl,
|
|
56815
|
+
version: config22.prover?.artifactSource?.version ?? chainConfig.artifactVersion,
|
|
56816
|
+
preferLocalFiles: config22.prover?.artifactSource?.preferLocalFiles
|
|
56817
|
+
}
|
|
56818
|
+
};
|
|
56819
|
+
} else {
|
|
56820
|
+
chainId = config22.chainId;
|
|
56549
56821
|
gatewayUrl = config22.gatewayUrl;
|
|
56550
56822
|
poolAddress = config22.poolAddress;
|
|
56823
|
+
adapterAddress = config22.adapterAddress;
|
|
56551
56824
|
if (typeof window !== "undefined" && !config22.prover?.artifactSource?.version) {
|
|
56552
56825
|
throw new InitializationError(
|
|
56553
|
-
"prover.artifactSource.version is required in browser when using explicit gatewayUrl mode. Use
|
|
56826
|
+
"prover.artifactSource.version is required in browser when using explicit gatewayUrl mode. Use chain mode or provide a pinned artifact version."
|
|
56554
56827
|
);
|
|
56555
56828
|
}
|
|
56556
|
-
} else {
|
|
56557
|
-
const envConfig = await fetchEnvironmentConfig(config22.environment);
|
|
56558
|
-
gatewayUrl = envConfig.gatewayUrl;
|
|
56559
|
-
poolAddress = config22.poolAddress ?? envConfig.poolAddress;
|
|
56560
|
-
proverConfig = {
|
|
56561
|
-
artifactSource: {
|
|
56562
|
-
baseUrl: config22.prover?.artifactSource?.baseUrl ?? envConfig.artifactBaseUrl,
|
|
56563
|
-
version: config22.prover?.artifactSource?.version ?? envConfig.artifactVersion,
|
|
56564
|
-
preferLocalFiles: config22.prover?.artifactSource?.preferLocalFiles
|
|
56565
|
-
}
|
|
56566
|
-
};
|
|
56567
56829
|
}
|
|
56568
56830
|
const storage = config22.storage ?? detectStorage();
|
|
56569
56831
|
const rng = config22.rng ?? defaultRng;
|
|
@@ -56572,14 +56834,14 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
56572
56834
|
const sdk = createWalletSDK(
|
|
56573
56835
|
{ core, fetch: fetchImpl },
|
|
56574
56836
|
{
|
|
56575
|
-
chainId
|
|
56837
|
+
chainId,
|
|
56576
56838
|
gatewayUrl,
|
|
56577
56839
|
chainRpcUrl: config22.chainRpcUrl,
|
|
56578
56840
|
prover: proverConfig,
|
|
56579
56841
|
autoSync: config22.autoSync
|
|
56580
56842
|
}
|
|
56581
56843
|
);
|
|
56582
|
-
return new
|
|
56844
|
+
return new _Unlink(sdk, chainId, poolAddress, adapterAddress ?? "");
|
|
56583
56845
|
}
|
|
56584
56846
|
// ===== Seed Lifecycle =====
|
|
56585
56847
|
/** Seed management (create, import, export, delete mnemonic). */
|
|
@@ -56610,10 +56872,10 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
56610
56872
|
return this.sdk.deposit.reconcile(relayId);
|
|
56611
56873
|
}
|
|
56612
56874
|
/**
|
|
56613
|
-
*
|
|
56875
|
+
* Send a private transfer (1 or more recipients).
|
|
56614
56876
|
* Handles note selection, circuit selection, and proof generation automatically.
|
|
56615
56877
|
*/
|
|
56616
|
-
async
|
|
56878
|
+
async send(params, overrides) {
|
|
56617
56879
|
return this.sdk.transfer.send(
|
|
56618
56880
|
{
|
|
56619
56881
|
chainId: this.chainId,
|
|
@@ -56624,9 +56886,9 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
56624
56886
|
);
|
|
56625
56887
|
}
|
|
56626
56888
|
/**
|
|
56627
|
-
* Get a
|
|
56889
|
+
* Get a send plan without executing (for preview/confirmation UIs).
|
|
56628
56890
|
*/
|
|
56629
|
-
async
|
|
56891
|
+
async planSend(params, account) {
|
|
56630
56892
|
return this.sdk.transfer.plan(
|
|
56631
56893
|
{
|
|
56632
56894
|
chainId: this.chainId,
|
|
@@ -56636,8 +56898,8 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
56636
56898
|
account
|
|
56637
56899
|
);
|
|
56638
56900
|
}
|
|
56639
|
-
/** Execute a pre-built
|
|
56640
|
-
async
|
|
56901
|
+
/** Execute a pre-built send plan. */
|
|
56902
|
+
async executeSend(plans, overrides) {
|
|
56641
56903
|
return this.sdk.transfer.execute(
|
|
56642
56904
|
plans,
|
|
56643
56905
|
{ chainId: this.chainId, poolAddress: this.poolAddress },
|
|
@@ -56786,31 +57048,31 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
56786
57048
|
return this.sdk.burner.getBalance(address);
|
|
56787
57049
|
}
|
|
56788
57050
|
};
|
|
56789
|
-
// =====
|
|
57051
|
+
// ===== Interact (Private DeFi) =====
|
|
56790
57052
|
/**
|
|
56791
|
-
*
|
|
56792
|
-
*
|
|
57053
|
+
* Adapter contract address (resolved from config).
|
|
57054
|
+
* Use for building DeFi calls that reference the adapter.
|
|
56793
57055
|
*/
|
|
56794
|
-
adapter
|
|
56795
|
-
|
|
56796
|
-
|
|
56797
|
-
|
|
56798
|
-
|
|
56799
|
-
|
|
56800
|
-
|
|
56801
|
-
|
|
56802
|
-
|
|
56803
|
-
|
|
56804
|
-
|
|
56805
|
-
|
|
56806
|
-
|
|
56807
|
-
|
|
56808
|
-
|
|
56809
|
-
|
|
56810
|
-
|
|
56811
|
-
|
|
56812
|
-
|
|
56813
|
-
}
|
|
57056
|
+
adapter;
|
|
57057
|
+
/**
|
|
57058
|
+
* Execute an atomic unshield -> DeFi call(s) -> reshield flow through an adapter.
|
|
57059
|
+
* chainId/poolAddress/adapterAddress are injected automatically.
|
|
57060
|
+
*/
|
|
57061
|
+
async interact(params, opts, overrides) {
|
|
57062
|
+
return this.sdk.adapter.execute(
|
|
57063
|
+
{
|
|
57064
|
+
chainId: this.chainId,
|
|
57065
|
+
poolAddress: this.poolAddress,
|
|
57066
|
+
adapterAddress: this.adapterAddress,
|
|
57067
|
+
spend: params.spend,
|
|
57068
|
+
calls: params.calls,
|
|
57069
|
+
receive: params.receive,
|
|
57070
|
+
deadline: params.deadline
|
|
57071
|
+
},
|
|
57072
|
+
opts,
|
|
57073
|
+
overrides
|
|
57074
|
+
);
|
|
57075
|
+
}
|
|
56814
57076
|
// ===== Advanced =====
|
|
56815
57077
|
/**
|
|
56816
57078
|
* Advanced escape hatch for raw JoinSplit transaction building.
|
|
@@ -56930,15 +57192,17 @@ function createUnlinkError(err, operation) {
|
|
|
56930
57192
|
};
|
|
56931
57193
|
}
|
|
56932
57194
|
var initialState = {
|
|
56933
|
-
|
|
57195
|
+
unlink: null,
|
|
56934
57196
|
walletExists: false,
|
|
56935
57197
|
accounts: [],
|
|
56936
57198
|
activeAccount: null,
|
|
56937
57199
|
activeAccountIndex: null,
|
|
57200
|
+
chainId: null,
|
|
56938
57201
|
notes: [],
|
|
56939
57202
|
balances: {},
|
|
57203
|
+
burners: [],
|
|
56940
57204
|
pendingDeposits: [],
|
|
56941
|
-
|
|
57205
|
+
pendingSends: [],
|
|
56942
57206
|
pendingWithdrawals: [],
|
|
56943
57207
|
ready: false,
|
|
56944
57208
|
busy: false,
|
|
@@ -56954,22 +57218,23 @@ function convertNotes(noteRecords) {
|
|
|
56954
57218
|
}
|
|
56955
57219
|
function UnlinkProvider({
|
|
56956
57220
|
children,
|
|
56957
|
-
chainId,
|
|
56958
57221
|
poolAddress,
|
|
56959
57222
|
syncInterval = 5e3,
|
|
56960
57223
|
autoSync = true,
|
|
56961
|
-
|
|
56962
|
-
|
|
56963
|
-
prover
|
|
57224
|
+
prover,
|
|
57225
|
+
...configProps
|
|
56964
57226
|
}) {
|
|
57227
|
+
const chain2 = "chain" in configProps ? configProps.chain : void 0;
|
|
57228
|
+
const chainId = "chainId" in configProps ? configProps.chainId : void 0;
|
|
57229
|
+
const gatewayUrl = "gatewayUrl" in configProps ? configProps.gatewayUrl : void 0;
|
|
56965
57230
|
const [state, setState] = useState(initialState);
|
|
56966
|
-
const
|
|
57231
|
+
const unlinkRef = useRef(null);
|
|
56967
57232
|
const proverKey = JSON.stringify(prover ?? null);
|
|
56968
|
-
const refreshAccounts = useCallback(async (
|
|
57233
|
+
const refreshAccounts = useCallback(async (unlink) => {
|
|
56969
57234
|
try {
|
|
56970
|
-
const accounts = await
|
|
56971
|
-
const activeAccount = await
|
|
56972
|
-
const activeAccountIndex = await
|
|
57235
|
+
const accounts = await unlink.accounts.list();
|
|
57236
|
+
const activeAccount = await unlink.accounts.getActive();
|
|
57237
|
+
const activeAccountIndex = await unlink.accounts.getActiveIndex();
|
|
56973
57238
|
setState((prev2) => ({
|
|
56974
57239
|
...prev2,
|
|
56975
57240
|
accounts,
|
|
@@ -56980,24 +57245,24 @@ function UnlinkProvider({
|
|
|
56980
57245
|
console.error("[UnlinkProvider] refreshAccounts error", err);
|
|
56981
57246
|
}
|
|
56982
57247
|
}, []);
|
|
56983
|
-
const refreshState = useCallback(async (
|
|
57248
|
+
const refreshState = useCallback(async (unlink) => {
|
|
56984
57249
|
try {
|
|
56985
|
-
const noteRecords = await
|
|
57250
|
+
const noteRecords = await unlink.getNotes();
|
|
56986
57251
|
const notes = convertNotes(noteRecords);
|
|
56987
|
-
const balances = await
|
|
57252
|
+
const balances = await unlink.getBalances();
|
|
56988
57253
|
setState((prev2) => ({ ...prev2, notes, balances }));
|
|
56989
57254
|
} catch (err) {
|
|
56990
57255
|
console.error("[UnlinkProvider] refresh error", err);
|
|
56991
57256
|
}
|
|
56992
57257
|
}, []);
|
|
56993
57258
|
useEffect(() => {
|
|
56994
|
-
if (!
|
|
57259
|
+
if (!chain2 && !gatewayUrl) {
|
|
56995
57260
|
const configError = new ValidationError(
|
|
56996
|
-
"Either
|
|
57261
|
+
"Either chain or gatewayUrl is required"
|
|
56997
57262
|
);
|
|
56998
57263
|
setState((prev2) => ({
|
|
56999
57264
|
...prev2,
|
|
57000
|
-
status: "Error: Either
|
|
57265
|
+
status: "Error: Either chain or gatewayUrl is required",
|
|
57001
57266
|
error: createUnlinkError(configError, "init")
|
|
57002
57267
|
}));
|
|
57003
57268
|
return;
|
|
@@ -57010,22 +57275,21 @@ function UnlinkProvider({
|
|
|
57010
57275
|
...prev2,
|
|
57011
57276
|
status: "Initializing SDK..."
|
|
57012
57277
|
}));
|
|
57013
|
-
const
|
|
57014
|
-
|
|
57015
|
-
|
|
57016
|
-
gatewayUrl,
|
|
57278
|
+
const unlink = await Unlink.create(
|
|
57279
|
+
chain2 ? {
|
|
57280
|
+
chain: chain2,
|
|
57017
57281
|
poolAddress,
|
|
57018
57282
|
...prover ? { prover } : {}
|
|
57019
57283
|
} : {
|
|
57020
57284
|
chainId,
|
|
57021
|
-
|
|
57285
|
+
gatewayUrl,
|
|
57022
57286
|
poolAddress,
|
|
57023
57287
|
...prover ? { prover } : {}
|
|
57024
57288
|
}
|
|
57025
57289
|
);
|
|
57026
57290
|
if (cancelled) return;
|
|
57027
|
-
|
|
57028
|
-
const walletExists = await
|
|
57291
|
+
unlinkRef.current = unlink;
|
|
57292
|
+
const walletExists = await unlink.seed.exists();
|
|
57029
57293
|
if (cancelled) return;
|
|
57030
57294
|
let accounts = [];
|
|
57031
57295
|
let activeAccount = null;
|
|
@@ -57033,32 +57297,33 @@ function UnlinkProvider({
|
|
|
57033
57297
|
let notes = [];
|
|
57034
57298
|
let balances = {};
|
|
57035
57299
|
if (walletExists) {
|
|
57036
|
-
accounts = await
|
|
57300
|
+
accounts = await unlink.accounts.list();
|
|
57037
57301
|
if (accounts.length === 0) {
|
|
57038
|
-
await
|
|
57039
|
-
accounts = await
|
|
57302
|
+
await unlink.accounts.create();
|
|
57303
|
+
accounts = await unlink.accounts.list();
|
|
57040
57304
|
}
|
|
57041
|
-
activeAccount = await
|
|
57042
|
-
activeAccountIndex = await
|
|
57305
|
+
activeAccount = await unlink.accounts.getActive();
|
|
57306
|
+
activeAccountIndex = await unlink.accounts.getActiveIndex();
|
|
57043
57307
|
if (accounts.length > 0 && !activeAccount) {
|
|
57044
|
-
await
|
|
57045
|
-
activeAccount = await
|
|
57046
|
-
activeAccountIndex = await
|
|
57308
|
+
await unlink.accounts.setActive(accounts[0].index);
|
|
57309
|
+
activeAccount = await unlink.accounts.getActive();
|
|
57310
|
+
activeAccountIndex = await unlink.accounts.getActiveIndex();
|
|
57047
57311
|
}
|
|
57048
57312
|
if (activeAccount) {
|
|
57049
|
-
const noteRecords = await
|
|
57313
|
+
const noteRecords = await unlink.getNotes();
|
|
57050
57314
|
notes = convertNotes(noteRecords);
|
|
57051
|
-
balances = await
|
|
57315
|
+
balances = await unlink.getBalances();
|
|
57052
57316
|
}
|
|
57053
57317
|
}
|
|
57054
57318
|
const statusMessage = !walletExists ? "No wallet - create or import one" : !activeAccount ? "No account - create one to get started" : "Ready";
|
|
57055
57319
|
setState((prev2) => ({
|
|
57056
57320
|
...prev2,
|
|
57057
|
-
|
|
57321
|
+
unlink,
|
|
57058
57322
|
walletExists,
|
|
57059
57323
|
accounts,
|
|
57060
57324
|
activeAccount,
|
|
57061
57325
|
activeAccountIndex,
|
|
57326
|
+
chainId: unlink.chainId,
|
|
57062
57327
|
notes,
|
|
57063
57328
|
balances,
|
|
57064
57329
|
ready: true,
|
|
@@ -57066,12 +57331,12 @@ function UnlinkProvider({
|
|
|
57066
57331
|
error: null
|
|
57067
57332
|
}));
|
|
57068
57333
|
if (autoSync && walletExists && activeAccount) {
|
|
57069
|
-
|
|
57334
|
+
unlink.startAutoSync(syncInterval);
|
|
57070
57335
|
}
|
|
57071
|
-
unsubscribe =
|
|
57072
|
-
if (event.type === "notes-updated" && event.chainId === chainId) {
|
|
57336
|
+
unsubscribe = unlink.on((event) => {
|
|
57337
|
+
if (event.type === "notes-updated" && event.chainId === unlink.chainId) {
|
|
57073
57338
|
setState((prev2) => ({ ...prev2, syncError: null }));
|
|
57074
|
-
void refreshState(
|
|
57339
|
+
void refreshState(unlink);
|
|
57075
57340
|
}
|
|
57076
57341
|
if (event.type === "sync-error") {
|
|
57077
57342
|
setState((prev2) => ({ ...prev2, syncError: event.error }));
|
|
@@ -57080,9 +57345,9 @@ function UnlinkProvider({
|
|
|
57080
57345
|
setState((prev2) => ({ ...prev2, walletExists: true }));
|
|
57081
57346
|
}
|
|
57082
57347
|
if (event.type === "account-created" || event.type === "account-switched") {
|
|
57083
|
-
void refreshAccounts(
|
|
57348
|
+
void refreshAccounts(unlink);
|
|
57084
57349
|
if (event.type === "account-switched") {
|
|
57085
|
-
void refreshState(
|
|
57350
|
+
void refreshState(unlink);
|
|
57086
57351
|
}
|
|
57087
57352
|
}
|
|
57088
57353
|
});
|
|
@@ -57100,25 +57365,25 @@ function UnlinkProvider({
|
|
|
57100
57365
|
return () => {
|
|
57101
57366
|
cancelled = true;
|
|
57102
57367
|
unsubscribe?.();
|
|
57103
|
-
|
|
57368
|
+
unlinkRef.current?.stopAutoSync();
|
|
57104
57369
|
};
|
|
57105
57370
|
}, [
|
|
57371
|
+
chain2,
|
|
57106
57372
|
chainId,
|
|
57107
57373
|
autoSync,
|
|
57108
57374
|
syncInterval,
|
|
57109
57375
|
refreshState,
|
|
57110
57376
|
refreshAccounts,
|
|
57111
57377
|
gatewayUrl,
|
|
57112
|
-
environment,
|
|
57113
57378
|
poolAddress,
|
|
57114
57379
|
proverKey
|
|
57115
57380
|
]);
|
|
57116
57381
|
const createWallet = useCallback(async () => {
|
|
57117
|
-
const
|
|
57118
|
-
if (!
|
|
57382
|
+
const unlink = unlinkRef.current;
|
|
57383
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57119
57384
|
setState((prev2) => ({ ...prev2, busy: true, status: "Creating wallet..." }));
|
|
57120
57385
|
try {
|
|
57121
|
-
const result = await
|
|
57386
|
+
const result = await unlink.seed.create();
|
|
57122
57387
|
setState((prev2) => ({
|
|
57123
57388
|
...prev2,
|
|
57124
57389
|
walletExists: true,
|
|
@@ -57139,24 +57404,25 @@ function UnlinkProvider({
|
|
|
57139
57404
|
}
|
|
57140
57405
|
}, []);
|
|
57141
57406
|
const importWallet = useCallback(async (mnemonic) => {
|
|
57142
|
-
const
|
|
57143
|
-
if (!
|
|
57407
|
+
const unlink = unlinkRef.current;
|
|
57408
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57144
57409
|
setState((prev2) => ({
|
|
57145
57410
|
...prev2,
|
|
57146
57411
|
busy: true,
|
|
57147
57412
|
status: "Importing wallet..."
|
|
57148
57413
|
}));
|
|
57149
57414
|
try {
|
|
57150
|
-
await
|
|
57151
|
-
const accounts = await
|
|
57152
|
-
const activeAccount = await
|
|
57153
|
-
const activeAccountIndex = await
|
|
57415
|
+
await unlink.seed.importMnemonic(mnemonic);
|
|
57416
|
+
const accounts = await unlink.accounts.list();
|
|
57417
|
+
const activeAccount = await unlink.accounts.getActive();
|
|
57418
|
+
const activeAccountIndex = await unlink.accounts.getActiveIndex();
|
|
57154
57419
|
setState((prev2) => ({
|
|
57155
57420
|
...prev2,
|
|
57156
57421
|
walletExists: true,
|
|
57157
57422
|
accounts,
|
|
57158
57423
|
activeAccount,
|
|
57159
57424
|
activeAccountIndex,
|
|
57425
|
+
burners: [],
|
|
57160
57426
|
busy: false,
|
|
57161
57427
|
status: accounts.length > 0 ? "Wallet imported" : "Wallet imported - create an account",
|
|
57162
57428
|
syncError: null,
|
|
@@ -57173,16 +57439,16 @@ function UnlinkProvider({
|
|
|
57173
57439
|
}
|
|
57174
57440
|
}, []);
|
|
57175
57441
|
const exportMnemonic = useCallback(async () => {
|
|
57176
|
-
const
|
|
57177
|
-
if (!
|
|
57178
|
-
return
|
|
57442
|
+
const unlink = unlinkRef.current;
|
|
57443
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57444
|
+
return unlink.seed.exportMnemonic();
|
|
57179
57445
|
}, []);
|
|
57180
57446
|
const clearWallet = useCallback(async () => {
|
|
57181
|
-
const
|
|
57182
|
-
if (!
|
|
57447
|
+
const unlink = unlinkRef.current;
|
|
57448
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57183
57449
|
setState((prev2) => ({ ...prev2, busy: true, status: "Clearing wallet..." }));
|
|
57184
57450
|
try {
|
|
57185
|
-
await
|
|
57451
|
+
await unlink.seed.delete();
|
|
57186
57452
|
setState((prev2) => ({
|
|
57187
57453
|
...prev2,
|
|
57188
57454
|
walletExists: false,
|
|
@@ -57191,6 +57457,7 @@ function UnlinkProvider({
|
|
|
57191
57457
|
activeAccountIndex: null,
|
|
57192
57458
|
notes: [],
|
|
57193
57459
|
balances: {},
|
|
57460
|
+
burners: [],
|
|
57194
57461
|
busy: false,
|
|
57195
57462
|
status: "Wallet cleared",
|
|
57196
57463
|
syncError: null,
|
|
@@ -57208,18 +57475,18 @@ function UnlinkProvider({
|
|
|
57208
57475
|
}, []);
|
|
57209
57476
|
const createAccount = useCallback(
|
|
57210
57477
|
async (index) => {
|
|
57211
|
-
const
|
|
57212
|
-
if (!
|
|
57478
|
+
const unlink = unlinkRef.current;
|
|
57479
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57213
57480
|
setState((prev2) => ({
|
|
57214
57481
|
...prev2,
|
|
57215
57482
|
busy: true,
|
|
57216
57483
|
status: "Creating account..."
|
|
57217
57484
|
}));
|
|
57218
57485
|
try {
|
|
57219
|
-
const account = await
|
|
57220
|
-
const accounts = await
|
|
57221
|
-
const activeAccount = await
|
|
57222
|
-
const activeAccountIndex = await
|
|
57486
|
+
const account = await unlink.accounts.create(index);
|
|
57487
|
+
const accounts = await unlink.accounts.list();
|
|
57488
|
+
const activeAccount = await unlink.accounts.getActive();
|
|
57489
|
+
const activeAccountIndex = await unlink.accounts.getActiveIndex();
|
|
57223
57490
|
setState((prev2) => ({
|
|
57224
57491
|
...prev2,
|
|
57225
57492
|
accounts,
|
|
@@ -57230,7 +57497,7 @@ function UnlinkProvider({
|
|
|
57230
57497
|
error: null
|
|
57231
57498
|
}));
|
|
57232
57499
|
if (autoSync && accounts.length === 1) {
|
|
57233
|
-
|
|
57500
|
+
unlink.startAutoSync(syncInterval);
|
|
57234
57501
|
}
|
|
57235
57502
|
return account;
|
|
57236
57503
|
} catch (err) {
|
|
@@ -57246,22 +57513,22 @@ function UnlinkProvider({
|
|
|
57246
57513
|
[autoSync, syncInterval]
|
|
57247
57514
|
);
|
|
57248
57515
|
const switchAccount = useCallback(async (index) => {
|
|
57249
|
-
const
|
|
57250
|
-
if (!
|
|
57516
|
+
const unlink = unlinkRef.current;
|
|
57517
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57251
57518
|
setState((prev2) => ({
|
|
57252
57519
|
...prev2,
|
|
57253
57520
|
busy: true,
|
|
57254
57521
|
status: "Switching account..."
|
|
57255
57522
|
}));
|
|
57256
57523
|
try {
|
|
57257
|
-
await
|
|
57258
|
-
const activeAccount = await
|
|
57524
|
+
await unlink.accounts.setActive(index);
|
|
57525
|
+
const activeAccount = await unlink.accounts.getActive();
|
|
57259
57526
|
let notes = [];
|
|
57260
57527
|
let balances = {};
|
|
57261
57528
|
if (activeAccount) {
|
|
57262
|
-
const noteRecords = await
|
|
57529
|
+
const noteRecords = await unlink.getNotes();
|
|
57263
57530
|
notes = convertNotes(noteRecords);
|
|
57264
|
-
balances = await
|
|
57531
|
+
balances = await unlink.getBalances();
|
|
57265
57532
|
}
|
|
57266
57533
|
setState((prev2) => ({
|
|
57267
57534
|
...prev2,
|
|
@@ -57283,58 +57550,64 @@ function UnlinkProvider({
|
|
|
57283
57550
|
throw err;
|
|
57284
57551
|
}
|
|
57285
57552
|
}, []);
|
|
57286
|
-
const send = useCallback(
|
|
57287
|
-
|
|
57288
|
-
|
|
57289
|
-
|
|
57290
|
-
|
|
57291
|
-
|
|
57292
|
-
|
|
57293
|
-
...prev2,
|
|
57294
|
-
busy: true,
|
|
57295
|
-
status: params.length > 1 ? `Sending (${params.length} transfers)...` : "Sending..."
|
|
57296
|
-
}));
|
|
57297
|
-
try {
|
|
57298
|
-
const result = await wallet.transfer({
|
|
57299
|
-
transfers: params.map((t) => ({
|
|
57300
|
-
token: t.token,
|
|
57301
|
-
recipient: t.recipient,
|
|
57302
|
-
amount: t.amount
|
|
57303
|
-
}))
|
|
57304
|
-
});
|
|
57305
|
-
setState((prev2) => ({
|
|
57306
|
-
...prev2,
|
|
57307
|
-
busy: false,
|
|
57308
|
-
status: params.length > 1 ? `Transfer submitted (${params.length} transfers)` : "Transfer submitted",
|
|
57309
|
-
pendingTransfers: [
|
|
57310
|
-
...prev2.pendingTransfers,
|
|
57311
|
-
...params.map((t, i) => ({
|
|
57312
|
-
txId: `${result.relayId}-${i}`,
|
|
57313
|
-
status: "pending",
|
|
57314
|
-
chainId: wallet.chainId,
|
|
57315
|
-
token: t.token,
|
|
57316
|
-
amount: t.amount,
|
|
57317
|
-
recipient: t.recipient,
|
|
57318
|
-
startedAt: Date.now()
|
|
57319
|
-
}))
|
|
57320
|
-
],
|
|
57321
|
-
error: null
|
|
57322
|
-
}));
|
|
57323
|
-
return result;
|
|
57324
|
-
} catch (err) {
|
|
57553
|
+
const send = useCallback(
|
|
57554
|
+
async (params, overrides) => {
|
|
57555
|
+
const unlink = unlinkRef.current;
|
|
57556
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57557
|
+
if (params.length === 0) {
|
|
57558
|
+
throw new Error("At least one transfer is required");
|
|
57559
|
+
}
|
|
57325
57560
|
setState((prev2) => ({
|
|
57326
57561
|
...prev2,
|
|
57327
|
-
busy:
|
|
57328
|
-
status:
|
|
57329
|
-
error: createUnlinkError(err, "send")
|
|
57562
|
+
busy: true,
|
|
57563
|
+
status: params.length > 1 ? `Sending (${params.length} transfers)...` : "Sending..."
|
|
57330
57564
|
}));
|
|
57331
|
-
|
|
57332
|
-
|
|
57333
|
-
|
|
57334
|
-
|
|
57335
|
-
|
|
57336
|
-
|
|
57337
|
-
|
|
57565
|
+
try {
|
|
57566
|
+
const result = await unlink.send(
|
|
57567
|
+
{
|
|
57568
|
+
transfers: params.map((t) => ({
|
|
57569
|
+
token: t.token,
|
|
57570
|
+
recipient: t.recipient,
|
|
57571
|
+
amount: t.amount
|
|
57572
|
+
}))
|
|
57573
|
+
},
|
|
57574
|
+
overrides
|
|
57575
|
+
);
|
|
57576
|
+
setState((prev2) => ({
|
|
57577
|
+
...prev2,
|
|
57578
|
+
busy: false,
|
|
57579
|
+
status: params.length > 1 ? `Transfer submitted (${params.length} transfers)` : "Transfer submitted",
|
|
57580
|
+
pendingSends: [
|
|
57581
|
+
...prev2.pendingSends,
|
|
57582
|
+
...params.map((t, i) => ({
|
|
57583
|
+
txId: `${result.relayId}-${i}`,
|
|
57584
|
+
status: "pending",
|
|
57585
|
+
chainId: unlink.chainId,
|
|
57586
|
+
token: t.token,
|
|
57587
|
+
amount: t.amount,
|
|
57588
|
+
recipient: t.recipient,
|
|
57589
|
+
startedAt: Date.now()
|
|
57590
|
+
}))
|
|
57591
|
+
],
|
|
57592
|
+
error: null
|
|
57593
|
+
}));
|
|
57594
|
+
return result;
|
|
57595
|
+
} catch (err) {
|
|
57596
|
+
setState((prev2) => ({
|
|
57597
|
+
...prev2,
|
|
57598
|
+
busy: false,
|
|
57599
|
+
status: `Error: ${err instanceof Error ? err.message : "Unknown"}`,
|
|
57600
|
+
error: createUnlinkError(err, "send")
|
|
57601
|
+
}));
|
|
57602
|
+
throw err;
|
|
57603
|
+
}
|
|
57604
|
+
},
|
|
57605
|
+
[]
|
|
57606
|
+
);
|
|
57607
|
+
const planSend = useCallback(async (params) => {
|
|
57608
|
+
const unlink = unlinkRef.current;
|
|
57609
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57610
|
+
return unlink.planSend({
|
|
57338
57611
|
transfers: params.map((t) => ({
|
|
57339
57612
|
token: t.token,
|
|
57340
57613
|
recipient: t.recipient,
|
|
@@ -57342,37 +57615,40 @@ function UnlinkProvider({
|
|
|
57342
57615
|
}))
|
|
57343
57616
|
});
|
|
57344
57617
|
}, []);
|
|
57345
|
-
const
|
|
57346
|
-
|
|
57347
|
-
|
|
57348
|
-
|
|
57349
|
-
...prev2,
|
|
57350
|
-
busy: true,
|
|
57351
|
-
status: "Executing transfer..."
|
|
57352
|
-
}));
|
|
57353
|
-
try {
|
|
57354
|
-
const result = await wallet.executeTransfer(plans);
|
|
57618
|
+
const executeSend = useCallback(
|
|
57619
|
+
async (plans, overrides) => {
|
|
57620
|
+
const unlink = unlinkRef.current;
|
|
57621
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57355
57622
|
setState((prev2) => ({
|
|
57356
57623
|
...prev2,
|
|
57357
|
-
busy:
|
|
57358
|
-
status: "
|
|
57359
|
-
error: null
|
|
57360
|
-
}));
|
|
57361
|
-
return result;
|
|
57362
|
-
} catch (err) {
|
|
57363
|
-
setState((prev2) => ({
|
|
57364
|
-
...prev2,
|
|
57365
|
-
busy: false,
|
|
57366
|
-
status: `Error: ${err instanceof Error ? err.message : "Unknown"}`,
|
|
57367
|
-
error: createUnlinkError(err, "executeTransfer")
|
|
57624
|
+
busy: true,
|
|
57625
|
+
status: "Executing send..."
|
|
57368
57626
|
}));
|
|
57369
|
-
|
|
57370
|
-
|
|
57371
|
-
|
|
57372
|
-
|
|
57627
|
+
try {
|
|
57628
|
+
const result = await unlink.executeSend(plans, overrides);
|
|
57629
|
+
setState((prev2) => ({
|
|
57630
|
+
...prev2,
|
|
57631
|
+
busy: false,
|
|
57632
|
+
status: "Send executed",
|
|
57633
|
+
error: null
|
|
57634
|
+
}));
|
|
57635
|
+
return result;
|
|
57636
|
+
} catch (err) {
|
|
57637
|
+
setState((prev2) => ({
|
|
57638
|
+
...prev2,
|
|
57639
|
+
busy: false,
|
|
57640
|
+
status: `Error: ${err instanceof Error ? err.message : "Unknown"}`,
|
|
57641
|
+
error: createUnlinkError(err, "executeSend")
|
|
57642
|
+
}));
|
|
57643
|
+
throw err;
|
|
57644
|
+
}
|
|
57645
|
+
},
|
|
57646
|
+
[]
|
|
57647
|
+
);
|
|
57648
|
+
const deposit2 = useCallback(
|
|
57373
57649
|
async (params) => {
|
|
57374
|
-
const
|
|
57375
|
-
if (!
|
|
57650
|
+
const unlink = unlinkRef.current;
|
|
57651
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57376
57652
|
if (params.length === 0) {
|
|
57377
57653
|
throw new Error("At least one deposit is required");
|
|
57378
57654
|
}
|
|
@@ -57386,7 +57662,7 @@ function UnlinkProvider({
|
|
|
57386
57662
|
status: params.length > 1 ? `Preparing deposit (${params.length} tokens)...` : "Preparing deposit..."
|
|
57387
57663
|
}));
|
|
57388
57664
|
try {
|
|
57389
|
-
const result = await
|
|
57665
|
+
const result = await unlink.deposit({
|
|
57390
57666
|
depositor,
|
|
57391
57667
|
deposits: params.map((d2) => ({
|
|
57392
57668
|
token: d2.token,
|
|
@@ -57404,7 +57680,7 @@ function UnlinkProvider({
|
|
|
57404
57680
|
status: "pending",
|
|
57405
57681
|
token: c.token,
|
|
57406
57682
|
amount: c.amount,
|
|
57407
|
-
chainId:
|
|
57683
|
+
chainId: unlink.chainId,
|
|
57408
57684
|
commitment: c.commitment,
|
|
57409
57685
|
startedAt: Date.now()
|
|
57410
57686
|
}))
|
|
@@ -57417,17 +57693,17 @@ function UnlinkProvider({
|
|
|
57417
57693
|
...prev2,
|
|
57418
57694
|
busy: false,
|
|
57419
57695
|
status: `Error: ${err instanceof Error ? err.message : "Unknown"}`,
|
|
57420
|
-
error: createUnlinkError(err, "
|
|
57696
|
+
error: createUnlinkError(err, "deposit")
|
|
57421
57697
|
}));
|
|
57422
57698
|
throw err;
|
|
57423
57699
|
}
|
|
57424
57700
|
},
|
|
57425
57701
|
[]
|
|
57426
57702
|
);
|
|
57427
|
-
const
|
|
57428
|
-
async (params) => {
|
|
57429
|
-
const
|
|
57430
|
-
if (!
|
|
57703
|
+
const withdraw = useCallback(
|
|
57704
|
+
async (params, overrides) => {
|
|
57705
|
+
const unlink = unlinkRef.current;
|
|
57706
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57431
57707
|
if (params.length === 0) {
|
|
57432
57708
|
throw new Error("At least one withdrawal is required");
|
|
57433
57709
|
}
|
|
@@ -57437,13 +57713,16 @@ function UnlinkProvider({
|
|
|
57437
57713
|
status: params.length > 1 ? `Processing withdrawal (${params.length} tokens)...` : "Withdrawing..."
|
|
57438
57714
|
}));
|
|
57439
57715
|
try {
|
|
57440
|
-
const result = await
|
|
57441
|
-
|
|
57442
|
-
|
|
57443
|
-
|
|
57444
|
-
|
|
57445
|
-
|
|
57446
|
-
|
|
57716
|
+
const result = await unlink.withdraw(
|
|
57717
|
+
{
|
|
57718
|
+
withdrawals: params.map((w) => ({
|
|
57719
|
+
token: w.token,
|
|
57720
|
+
amount: w.amount,
|
|
57721
|
+
recipient: w.recipient
|
|
57722
|
+
}))
|
|
57723
|
+
},
|
|
57724
|
+
overrides
|
|
57725
|
+
);
|
|
57447
57726
|
setState((prev2) => ({
|
|
57448
57727
|
...prev2,
|
|
57449
57728
|
busy: false,
|
|
@@ -57453,7 +57732,7 @@ function UnlinkProvider({
|
|
|
57453
57732
|
...params.map((w, i) => ({
|
|
57454
57733
|
txId: `${result.relayId}-${i}`,
|
|
57455
57734
|
status: "pending",
|
|
57456
|
-
chainId:
|
|
57735
|
+
chainId: unlink.chainId,
|
|
57457
57736
|
token: w.token,
|
|
57458
57737
|
amount: w.amount,
|
|
57459
57738
|
recipient: w.recipient,
|
|
@@ -57468,7 +57747,37 @@ function UnlinkProvider({
|
|
|
57468
57747
|
...prev2,
|
|
57469
57748
|
busy: false,
|
|
57470
57749
|
status: `Error: ${err instanceof Error ? err.message : "Unknown"}`,
|
|
57471
|
-
error: createUnlinkError(err, "
|
|
57750
|
+
error: createUnlinkError(err, "withdraw")
|
|
57751
|
+
}));
|
|
57752
|
+
throw err;
|
|
57753
|
+
}
|
|
57754
|
+
},
|
|
57755
|
+
[]
|
|
57756
|
+
);
|
|
57757
|
+
const interact = useCallback(
|
|
57758
|
+
async (params) => {
|
|
57759
|
+
const unlink = unlinkRef.current;
|
|
57760
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57761
|
+
setState((prev2) => ({
|
|
57762
|
+
...prev2,
|
|
57763
|
+
busy: true,
|
|
57764
|
+
status: "Executing interaction..."
|
|
57765
|
+
}));
|
|
57766
|
+
try {
|
|
57767
|
+
const result = await unlink.interact(params);
|
|
57768
|
+
setState((prev2) => ({
|
|
57769
|
+
...prev2,
|
|
57770
|
+
busy: false,
|
|
57771
|
+
status: "Interaction submitted",
|
|
57772
|
+
error: null
|
|
57773
|
+
}));
|
|
57774
|
+
return result;
|
|
57775
|
+
} catch (err) {
|
|
57776
|
+
setState((prev2) => ({
|
|
57777
|
+
...prev2,
|
|
57778
|
+
busy: false,
|
|
57779
|
+
status: `Error: ${err instanceof Error ? err.message : "Unknown"}`,
|
|
57780
|
+
error: createUnlinkError(err, "interact")
|
|
57472
57781
|
}));
|
|
57473
57782
|
throw err;
|
|
57474
57783
|
}
|
|
@@ -57477,9 +57786,9 @@ function UnlinkProvider({
|
|
|
57477
57786
|
);
|
|
57478
57787
|
const planWithdraw = useCallback(
|
|
57479
57788
|
async (params) => {
|
|
57480
|
-
const
|
|
57481
|
-
if (!
|
|
57482
|
-
return
|
|
57789
|
+
const unlink = unlinkRef.current;
|
|
57790
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57791
|
+
return unlink.planWithdraw({
|
|
57483
57792
|
withdrawals: params.map((w) => ({
|
|
57484
57793
|
token: w.token,
|
|
57485
57794
|
amount: w.amount,
|
|
@@ -57489,37 +57798,183 @@ function UnlinkProvider({
|
|
|
57489
57798
|
},
|
|
57490
57799
|
[]
|
|
57491
57800
|
);
|
|
57492
|
-
const executeWithdraw = useCallback(
|
|
57493
|
-
|
|
57494
|
-
|
|
57801
|
+
const executeWithdraw = useCallback(
|
|
57802
|
+
async (plans, overrides) => {
|
|
57803
|
+
const unlink = unlinkRef.current;
|
|
57804
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57805
|
+
setState((prev2) => ({
|
|
57806
|
+
...prev2,
|
|
57807
|
+
busy: true,
|
|
57808
|
+
status: plans.length > 1 ? `Executing withdrawal (${plans.length} tokens)...` : "Executing withdrawal..."
|
|
57809
|
+
}));
|
|
57810
|
+
try {
|
|
57811
|
+
const result = await unlink.executeWithdraw(plans, overrides);
|
|
57812
|
+
setState((prev2) => ({
|
|
57813
|
+
...prev2,
|
|
57814
|
+
busy: false,
|
|
57815
|
+
status: plans.length > 1 ? `Withdrawal executed (${plans.length} tokens)` : "Withdrawal executed",
|
|
57816
|
+
error: null
|
|
57817
|
+
}));
|
|
57818
|
+
return result;
|
|
57819
|
+
} catch (err) {
|
|
57820
|
+
setState((prev2) => ({
|
|
57821
|
+
...prev2,
|
|
57822
|
+
busy: false,
|
|
57823
|
+
status: `Error: ${err instanceof Error ? err.message : "Unknown"}`,
|
|
57824
|
+
error: createUnlinkError(err, "executeWithdraw")
|
|
57825
|
+
}));
|
|
57826
|
+
throw err;
|
|
57827
|
+
}
|
|
57828
|
+
},
|
|
57829
|
+
[]
|
|
57830
|
+
);
|
|
57831
|
+
const createBurner = useCallback(async (index) => {
|
|
57832
|
+
const unlink = unlinkRef.current;
|
|
57833
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57495
57834
|
setState((prev2) => ({
|
|
57496
57835
|
...prev2,
|
|
57497
57836
|
busy: true,
|
|
57498
|
-
status:
|
|
57837
|
+
status: `Creating burner ${index}...`
|
|
57499
57838
|
}));
|
|
57500
57839
|
try {
|
|
57501
|
-
const
|
|
57840
|
+
const burner = await unlink.burner.addressOf(index);
|
|
57502
57841
|
setState((prev2) => ({
|
|
57503
57842
|
...prev2,
|
|
57843
|
+
burners: [
|
|
57844
|
+
...prev2.burners.filter((existing) => existing.index !== burner.index),
|
|
57845
|
+
burner
|
|
57846
|
+
],
|
|
57504
57847
|
busy: false,
|
|
57505
|
-
status:
|
|
57848
|
+
status: `Burner ${index} ready`,
|
|
57506
57849
|
error: null
|
|
57507
57850
|
}));
|
|
57508
|
-
return
|
|
57851
|
+
return burner;
|
|
57509
57852
|
} catch (err) {
|
|
57510
57853
|
setState((prev2) => ({
|
|
57511
57854
|
...prev2,
|
|
57512
57855
|
busy: false,
|
|
57513
57856
|
status: `Error: ${err instanceof Error ? err.message : "Unknown"}`,
|
|
57514
|
-
error: createUnlinkError(err, "
|
|
57857
|
+
error: createUnlinkError(err, "createBurner")
|
|
57515
57858
|
}));
|
|
57516
57859
|
throw err;
|
|
57517
57860
|
}
|
|
57518
57861
|
}, []);
|
|
57862
|
+
const removeBurner = useCallback((index) => {
|
|
57863
|
+
setState((prev2) => ({
|
|
57864
|
+
...prev2,
|
|
57865
|
+
burners: prev2.burners.filter((burner) => burner.index !== index)
|
|
57866
|
+
}));
|
|
57867
|
+
}, []);
|
|
57868
|
+
const burnerSend = useCallback(
|
|
57869
|
+
async (index, tx) => {
|
|
57870
|
+
const unlink = unlinkRef.current;
|
|
57871
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57872
|
+
setState((prev2) => ({
|
|
57873
|
+
...prev2,
|
|
57874
|
+
busy: true,
|
|
57875
|
+
status: "Sending burner transaction..."
|
|
57876
|
+
}));
|
|
57877
|
+
try {
|
|
57878
|
+
const result = await unlink.burner.send(index, tx);
|
|
57879
|
+
setState((prev2) => ({
|
|
57880
|
+
...prev2,
|
|
57881
|
+
busy: false,
|
|
57882
|
+
status: "Burner transaction sent",
|
|
57883
|
+
error: null
|
|
57884
|
+
}));
|
|
57885
|
+
return result;
|
|
57886
|
+
} catch (err) {
|
|
57887
|
+
setState((prev2) => ({
|
|
57888
|
+
...prev2,
|
|
57889
|
+
busy: false,
|
|
57890
|
+
status: `Error: ${err instanceof Error ? err.message : "Unknown"}`,
|
|
57891
|
+
error: createUnlinkError(err, "burnerSend")
|
|
57892
|
+
}));
|
|
57893
|
+
throw err;
|
|
57894
|
+
}
|
|
57895
|
+
},
|
|
57896
|
+
[]
|
|
57897
|
+
);
|
|
57898
|
+
const burnerFund = useCallback(
|
|
57899
|
+
async (index, params) => {
|
|
57900
|
+
const unlink = unlinkRef.current;
|
|
57901
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57902
|
+
setState((prev2) => ({
|
|
57903
|
+
...prev2,
|
|
57904
|
+
busy: true,
|
|
57905
|
+
status: "Funding burner..."
|
|
57906
|
+
}));
|
|
57907
|
+
try {
|
|
57908
|
+
const result = await unlink.burner.fund(index, params);
|
|
57909
|
+
setState((prev2) => ({
|
|
57910
|
+
...prev2,
|
|
57911
|
+
busy: false,
|
|
57912
|
+
status: "Burner funded",
|
|
57913
|
+
error: null
|
|
57914
|
+
}));
|
|
57915
|
+
return result;
|
|
57916
|
+
} catch (err) {
|
|
57917
|
+
setState((prev2) => ({
|
|
57918
|
+
...prev2,
|
|
57919
|
+
busy: false,
|
|
57920
|
+
status: `Error: ${err instanceof Error ? err.message : "Unknown"}`,
|
|
57921
|
+
error: createUnlinkError(err, "burnerFund")
|
|
57922
|
+
}));
|
|
57923
|
+
throw err;
|
|
57924
|
+
}
|
|
57925
|
+
},
|
|
57926
|
+
[]
|
|
57927
|
+
);
|
|
57928
|
+
const burnerSweepToPool = useCallback(
|
|
57929
|
+
async (index, params) => {
|
|
57930
|
+
const unlink = unlinkRef.current;
|
|
57931
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57932
|
+
setState((prev2) => ({
|
|
57933
|
+
...prev2,
|
|
57934
|
+
busy: true,
|
|
57935
|
+
status: "Sweeping burner to pool..."
|
|
57936
|
+
}));
|
|
57937
|
+
try {
|
|
57938
|
+
const result = await unlink.burner.sweepToPool(index, params);
|
|
57939
|
+
setState((prev2) => ({
|
|
57940
|
+
...prev2,
|
|
57941
|
+
busy: false,
|
|
57942
|
+
status: "Burner sweep submitted",
|
|
57943
|
+
error: null
|
|
57944
|
+
}));
|
|
57945
|
+
return result;
|
|
57946
|
+
} catch (err) {
|
|
57947
|
+
setState((prev2) => ({
|
|
57948
|
+
...prev2,
|
|
57949
|
+
busy: false,
|
|
57950
|
+
status: `Error: ${err instanceof Error ? err.message : "Unknown"}`,
|
|
57951
|
+
error: createUnlinkError(err, "burnerSweepToPool")
|
|
57952
|
+
}));
|
|
57953
|
+
throw err;
|
|
57954
|
+
}
|
|
57955
|
+
},
|
|
57956
|
+
[]
|
|
57957
|
+
);
|
|
57958
|
+
const burnerGetTokenBalance = useCallback(
|
|
57959
|
+
async (address, token) => {
|
|
57960
|
+
const unlink = unlinkRef.current;
|
|
57961
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57962
|
+
return unlink.burner.getTokenBalance(address, token);
|
|
57963
|
+
},
|
|
57964
|
+
[]
|
|
57965
|
+
);
|
|
57966
|
+
const burnerGetBalance = useCallback(
|
|
57967
|
+
async (address) => {
|
|
57968
|
+
const unlink = unlinkRef.current;
|
|
57969
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57970
|
+
return unlink.burner.getBalance(address);
|
|
57971
|
+
},
|
|
57972
|
+
[]
|
|
57973
|
+
);
|
|
57519
57974
|
const refresh = useCallback(async () => {
|
|
57520
|
-
const
|
|
57521
|
-
if (!
|
|
57522
|
-
const activeAccount = await
|
|
57975
|
+
const unlink = unlinkRef.current;
|
|
57976
|
+
if (!unlink) return;
|
|
57977
|
+
const activeAccount = await unlink.accounts.getActive();
|
|
57523
57978
|
if (!activeAccount) return;
|
|
57524
57979
|
setState((prev2) => ({
|
|
57525
57980
|
...prev2,
|
|
@@ -57527,8 +57982,8 @@ function UnlinkProvider({
|
|
|
57527
57982
|
status: "Syncing..."
|
|
57528
57983
|
}));
|
|
57529
57984
|
try {
|
|
57530
|
-
await
|
|
57531
|
-
await refreshState(
|
|
57985
|
+
await unlink.sync();
|
|
57986
|
+
await refreshState(unlink);
|
|
57532
57987
|
setState((prev2) => ({
|
|
57533
57988
|
...prev2,
|
|
57534
57989
|
busy: false,
|
|
@@ -57545,9 +58000,9 @@ function UnlinkProvider({
|
|
|
57545
58000
|
}
|
|
57546
58001
|
}, [refreshState]);
|
|
57547
58002
|
const forceResync = useCallback(async () => {
|
|
57548
|
-
const
|
|
57549
|
-
if (!
|
|
57550
|
-
const activeAccount = await
|
|
58003
|
+
const unlink = unlinkRef.current;
|
|
58004
|
+
if (!unlink) return;
|
|
58005
|
+
const activeAccount = await unlink.accounts.getActive();
|
|
57551
58006
|
if (!activeAccount) return;
|
|
57552
58007
|
setState((prev2) => ({
|
|
57553
58008
|
...prev2,
|
|
@@ -57555,8 +58010,8 @@ function UnlinkProvider({
|
|
|
57555
58010
|
status: "Resyncing..."
|
|
57556
58011
|
}));
|
|
57557
58012
|
try {
|
|
57558
|
-
await
|
|
57559
|
-
await refreshState(
|
|
58013
|
+
await unlink.sync({ forceFullResync: true });
|
|
58014
|
+
await refreshState(unlink);
|
|
57560
58015
|
setState((prev2) => ({
|
|
57561
58016
|
...prev2,
|
|
57562
58017
|
busy: false,
|
|
@@ -57576,9 +58031,9 @@ function UnlinkProvider({
|
|
|
57576
58031
|
setState((prev2) => ({ ...prev2, error: null }));
|
|
57577
58032
|
}, []);
|
|
57578
58033
|
const getTxStatus = useCallback(async (txId) => {
|
|
57579
|
-
const
|
|
57580
|
-
if (!
|
|
57581
|
-
const response = await
|
|
58034
|
+
const unlink = unlinkRef.current;
|
|
58035
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
58036
|
+
const response = await unlink.getTxStatus(txId);
|
|
57582
58037
|
return {
|
|
57583
58038
|
txId: response.id,
|
|
57584
58039
|
state: response.state,
|
|
@@ -57589,8 +58044,8 @@ function UnlinkProvider({
|
|
|
57589
58044
|
}, []);
|
|
57590
58045
|
const waitForConfirmation = useCallback(
|
|
57591
58046
|
async (txId, options) => {
|
|
57592
|
-
const
|
|
57593
|
-
if (!
|
|
58047
|
+
const unlink = unlinkRef.current;
|
|
58048
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57594
58049
|
const timeout2 = options?.timeout ?? DEFAULT_CONFIRMATION_TIMEOUT_MS;
|
|
57595
58050
|
const startTime3 = Date.now();
|
|
57596
58051
|
let delay2 = CONFIRMATION_POLL_INTERVAL_MS;
|
|
@@ -57631,7 +58086,6 @@ function UnlinkProvider({
|
|
|
57631
58086
|
const value = useMemo(
|
|
57632
58087
|
() => ({
|
|
57633
58088
|
...state,
|
|
57634
|
-
chainId,
|
|
57635
58089
|
// Wallet actions
|
|
57636
58090
|
createWallet,
|
|
57637
58091
|
importWallet,
|
|
@@ -57640,16 +58094,26 @@ function UnlinkProvider({
|
|
|
57640
58094
|
// Account actions
|
|
57641
58095
|
createAccount,
|
|
57642
58096
|
switchAccount,
|
|
57643
|
-
//
|
|
58097
|
+
// Send actions
|
|
57644
58098
|
send,
|
|
57645
|
-
|
|
57646
|
-
|
|
58099
|
+
planSend,
|
|
58100
|
+
executeSend,
|
|
57647
58101
|
// Deposit actions
|
|
57648
|
-
|
|
58102
|
+
deposit: deposit2,
|
|
57649
58103
|
// Withdraw actions
|
|
57650
|
-
|
|
58104
|
+
withdraw,
|
|
58105
|
+
// Interact actions
|
|
58106
|
+
interact,
|
|
57651
58107
|
planWithdraw,
|
|
57652
58108
|
executeWithdraw,
|
|
58109
|
+
// Burner actions
|
|
58110
|
+
createBurner,
|
|
58111
|
+
removeBurner,
|
|
58112
|
+
burnerSend,
|
|
58113
|
+
burnerFund,
|
|
58114
|
+
burnerSweepToPool,
|
|
58115
|
+
burnerGetTokenBalance,
|
|
58116
|
+
burnerGetBalance,
|
|
57653
58117
|
// Sync actions
|
|
57654
58118
|
refresh,
|
|
57655
58119
|
forceResync,
|
|
@@ -57661,7 +58125,6 @@ function UnlinkProvider({
|
|
|
57661
58125
|
}),
|
|
57662
58126
|
[
|
|
57663
58127
|
state,
|
|
57664
|
-
chainId,
|
|
57665
58128
|
createWallet,
|
|
57666
58129
|
importWallet,
|
|
57667
58130
|
exportMnemonic,
|
|
@@ -57669,12 +58132,20 @@ function UnlinkProvider({
|
|
|
57669
58132
|
createAccount,
|
|
57670
58133
|
switchAccount,
|
|
57671
58134
|
send,
|
|
57672
|
-
|
|
57673
|
-
|
|
57674
|
-
|
|
57675
|
-
|
|
58135
|
+
planSend,
|
|
58136
|
+
executeSend,
|
|
58137
|
+
deposit2,
|
|
58138
|
+
withdraw,
|
|
58139
|
+
interact,
|
|
57676
58140
|
planWithdraw,
|
|
57677
58141
|
executeWithdraw,
|
|
58142
|
+
createBurner,
|
|
58143
|
+
removeBurner,
|
|
58144
|
+
burnerSend,
|
|
58145
|
+
burnerFund,
|
|
58146
|
+
burnerSweepToPool,
|
|
58147
|
+
burnerGetTokenBalance,
|
|
58148
|
+
burnerGetBalance,
|
|
57678
58149
|
refresh,
|
|
57679
58150
|
forceResync,
|
|
57680
58151
|
clearError,
|
|
@@ -57698,20 +58169,20 @@ function useUnlink() {
|
|
|
57698
58169
|
// src/useUnlinkHistory.ts
|
|
57699
58170
|
import { useCallback as useCallback2, useEffect as useEffect2, useState as useState2 } from "react";
|
|
57700
58171
|
function useUnlinkHistory(options) {
|
|
57701
|
-
const {
|
|
58172
|
+
const { unlink, activeAccount } = useUnlink();
|
|
57702
58173
|
const includeSelfSends = options?.includeSelfSends;
|
|
57703
58174
|
const [history, setHistory] = useState2([]);
|
|
57704
58175
|
const [loading, setLoading] = useState2(true);
|
|
57705
58176
|
const [error, setError] = useState2(null);
|
|
57706
58177
|
const fetchHistory = useCallback2(async () => {
|
|
57707
|
-
if (!
|
|
58178
|
+
if (!unlink || !activeAccount) {
|
|
57708
58179
|
setHistory([]);
|
|
57709
58180
|
setLoading(false);
|
|
57710
58181
|
return;
|
|
57711
58182
|
}
|
|
57712
58183
|
try {
|
|
57713
58184
|
setLoading(true);
|
|
57714
|
-
const entries = await
|
|
58185
|
+
const entries = await unlink.getHistory({
|
|
57715
58186
|
includeSelfSends
|
|
57716
58187
|
});
|
|
57717
58188
|
setHistory(entries);
|
|
@@ -57721,19 +58192,19 @@ function useUnlinkHistory(options) {
|
|
|
57721
58192
|
} finally {
|
|
57722
58193
|
setLoading(false);
|
|
57723
58194
|
}
|
|
57724
|
-
}, [
|
|
58195
|
+
}, [unlink, activeAccount, includeSelfSends]);
|
|
57725
58196
|
useEffect2(() => {
|
|
57726
58197
|
void fetchHistory();
|
|
57727
58198
|
}, [fetchHistory]);
|
|
57728
58199
|
useEffect2(() => {
|
|
57729
|
-
if (!
|
|
57730
|
-
const unsubscribe =
|
|
58200
|
+
if (!unlink) return;
|
|
58201
|
+
const unsubscribe = unlink.on((event) => {
|
|
57731
58202
|
if (event.type === "notes-updated") {
|
|
57732
58203
|
void fetchHistory();
|
|
57733
58204
|
}
|
|
57734
58205
|
});
|
|
57735
58206
|
return unsubscribe;
|
|
57736
|
-
}, [
|
|
58207
|
+
}, [unlink, fetchHistory]);
|
|
57737
58208
|
const refresh = useCallback2(async () => {
|
|
57738
58209
|
await fetchHistory();
|
|
57739
58210
|
}, [fetchHistory]);
|
|
@@ -57766,7 +58237,7 @@ function useUnlinkBalances() {
|
|
|
57766
58237
|
// src/useTxStatus.ts
|
|
57767
58238
|
import { useCallback as useCallback3, useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
|
|
57768
58239
|
function useTxStatus(txId) {
|
|
57769
|
-
const { getTxStatus,
|
|
58240
|
+
const { getTxStatus, unlink } = useUnlink();
|
|
57770
58241
|
const [state, setState] = useState3(null);
|
|
57771
58242
|
const [txHash, setTxHash] = useState3(null);
|
|
57772
58243
|
const [blockNumber, setBlockNumber] = useState3(null);
|
|
@@ -57776,7 +58247,7 @@ function useTxStatus(txId) {
|
|
|
57776
58247
|
currentTxIdRef.current = txId;
|
|
57777
58248
|
const refresh = useCallback3(async () => {
|
|
57778
58249
|
const targetTxId = currentTxIdRef.current;
|
|
57779
|
-
if (!targetTxId || !
|
|
58250
|
+
if (!targetTxId || !unlink) return;
|
|
57780
58251
|
setIsLoading(true);
|
|
57781
58252
|
try {
|
|
57782
58253
|
const status = await getTxStatus(targetTxId);
|
|
@@ -57793,13 +58264,13 @@ function useTxStatus(txId) {
|
|
|
57793
58264
|
setIsLoading(false);
|
|
57794
58265
|
}
|
|
57795
58266
|
}
|
|
57796
|
-
}, [
|
|
58267
|
+
}, [unlink, getTxStatus]);
|
|
57797
58268
|
useEffect3(() => {
|
|
57798
|
-
if (txId &&
|
|
57799
|
-
|
|
58269
|
+
if (txId && unlink) {
|
|
58270
|
+
unlink.trackTx(txId);
|
|
57800
58271
|
void refresh();
|
|
57801
58272
|
return () => {
|
|
57802
|
-
|
|
58273
|
+
unlink.untrackTx(txId);
|
|
57803
58274
|
};
|
|
57804
58275
|
} else {
|
|
57805
58276
|
setState(null);
|
|
@@ -57807,10 +58278,10 @@ function useTxStatus(txId) {
|
|
|
57807
58278
|
setBlockNumber(null);
|
|
57808
58279
|
setError(null);
|
|
57809
58280
|
}
|
|
57810
|
-
}, [txId,
|
|
58281
|
+
}, [txId, unlink, refresh]);
|
|
57811
58282
|
useEffect3(() => {
|
|
57812
|
-
if (!
|
|
57813
|
-
const unsubscribe =
|
|
58283
|
+
if (!unlink || !txId) return;
|
|
58284
|
+
const unsubscribe = unlink.on((event) => {
|
|
57814
58285
|
if (event.type === "tx-status-changed" && event.txId === txId) {
|
|
57815
58286
|
setState(event.state);
|
|
57816
58287
|
setTxHash(event.txHash ?? null);
|
|
@@ -57819,7 +58290,7 @@ function useTxStatus(txId) {
|
|
|
57819
58290
|
}
|
|
57820
58291
|
});
|
|
57821
58292
|
return unsubscribe;
|
|
57822
|
-
}, [
|
|
58293
|
+
}, [unlink, txId]);
|
|
57823
58294
|
return { state, txHash, blockNumber, error, isLoading, refresh };
|
|
57824
58295
|
}
|
|
57825
58296
|
|
|
@@ -57836,7 +58307,7 @@ function useOperationMutation(operation) {
|
|
|
57836
58307
|
const [isError2, setIsError] = useState4(false);
|
|
57837
58308
|
const pendingRef = useRef3(false);
|
|
57838
58309
|
const generationRef = useRef3(0);
|
|
57839
|
-
const
|
|
58310
|
+
const execute = useCallback4(
|
|
57840
58311
|
async (input) => {
|
|
57841
58312
|
if (pendingRef.current) {
|
|
57842
58313
|
throw new Error("Operation already in progress");
|
|
@@ -57879,36 +58350,94 @@ function useOperationMutation(operation) {
|
|
|
57879
58350
|
setIsSuccess(false);
|
|
57880
58351
|
setIsError(false);
|
|
57881
58352
|
}, []);
|
|
57882
|
-
return {
|
|
58353
|
+
return { execute, data, isPending, isSuccess, isError: isError2, error, reset };
|
|
57883
58354
|
}
|
|
57884
58355
|
|
|
57885
58356
|
// src/useDeposit.ts
|
|
57886
58357
|
function useDeposit() {
|
|
57887
|
-
const {
|
|
58358
|
+
const { deposit: deposit2 } = useUnlink();
|
|
57888
58359
|
const op = useCallback5(
|
|
57889
|
-
(params) =>
|
|
57890
|
-
[
|
|
58360
|
+
(params) => deposit2(params),
|
|
58361
|
+
[deposit2]
|
|
57891
58362
|
);
|
|
57892
|
-
|
|
58363
|
+
const { execute, ...rest } = useOperationMutation(op);
|
|
58364
|
+
return { deposit: execute, ...rest };
|
|
57893
58365
|
}
|
|
57894
58366
|
|
|
57895
|
-
// src/
|
|
58367
|
+
// src/useSend.ts
|
|
57896
58368
|
import { useCallback as useCallback6 } from "react";
|
|
57897
|
-
function
|
|
58369
|
+
function useSend(overrides) {
|
|
57898
58370
|
const { send } = useUnlink();
|
|
57899
|
-
const op = useCallback6(
|
|
57900
|
-
|
|
58371
|
+
const op = useCallback6(
|
|
58372
|
+
(params) => send(params, overrides),
|
|
58373
|
+
[send, overrides]
|
|
58374
|
+
);
|
|
58375
|
+
const { execute, ...rest } = useOperationMutation(op);
|
|
58376
|
+
return { send: execute, ...rest };
|
|
57901
58377
|
}
|
|
57902
58378
|
|
|
57903
58379
|
// src/useWithdraw.ts
|
|
57904
58380
|
import { useCallback as useCallback7 } from "react";
|
|
57905
|
-
function useWithdraw() {
|
|
57906
|
-
const {
|
|
58381
|
+
function useWithdraw(overrides) {
|
|
58382
|
+
const { withdraw } = useUnlink();
|
|
57907
58383
|
const op = useCallback7(
|
|
57908
|
-
(params) =>
|
|
57909
|
-
[
|
|
58384
|
+
(params) => withdraw(params, overrides),
|
|
58385
|
+
[withdraw, overrides]
|
|
58386
|
+
);
|
|
58387
|
+
const { execute, ...rest } = useOperationMutation(op);
|
|
58388
|
+
return { withdraw: execute, ...rest };
|
|
58389
|
+
}
|
|
58390
|
+
|
|
58391
|
+
// src/useInteract.ts
|
|
58392
|
+
import { useCallback as useCallback8 } from "react";
|
|
58393
|
+
function useInteract() {
|
|
58394
|
+
const { interact } = useUnlink();
|
|
58395
|
+
const op = useCallback8(
|
|
58396
|
+
(params) => interact(params),
|
|
58397
|
+
[interact]
|
|
58398
|
+
);
|
|
58399
|
+
const { execute, ...rest } = useOperationMutation(op);
|
|
58400
|
+
return { interact: execute, ...rest };
|
|
58401
|
+
}
|
|
58402
|
+
|
|
58403
|
+
// src/useBurner.ts
|
|
58404
|
+
import { useCallback as useCallback9 } from "react";
|
|
58405
|
+
function useBurner() {
|
|
58406
|
+
const {
|
|
58407
|
+
burners,
|
|
58408
|
+
createBurner,
|
|
58409
|
+
removeBurner,
|
|
58410
|
+
burnerSend,
|
|
58411
|
+
burnerFund,
|
|
58412
|
+
burnerSweepToPool,
|
|
58413
|
+
burnerGetTokenBalance,
|
|
58414
|
+
burnerGetBalance
|
|
58415
|
+
} = useUnlink();
|
|
58416
|
+
const sendOp = useCallback9(
|
|
58417
|
+
(input) => burnerSend(input.index, input.tx),
|
|
58418
|
+
[burnerSend]
|
|
57910
58419
|
);
|
|
57911
|
-
|
|
58420
|
+
const fundOp = useCallback9(
|
|
58421
|
+
(input) => burnerFund(input.index, input.params),
|
|
58422
|
+
[burnerFund]
|
|
58423
|
+
);
|
|
58424
|
+
const sweepOp = useCallback9(
|
|
58425
|
+
(input) => burnerSweepToPool(input.index, input.params),
|
|
58426
|
+
[burnerSweepToPool]
|
|
58427
|
+
);
|
|
58428
|
+
const send = useOperationMutation(sendOp);
|
|
58429
|
+
const fund = useOperationMutation(fundOp);
|
|
58430
|
+
const sweepToPool = useOperationMutation(sweepOp);
|
|
58431
|
+
return {
|
|
58432
|
+
burners,
|
|
58433
|
+
createBurner,
|
|
58434
|
+
removeBurner,
|
|
58435
|
+
send,
|
|
58436
|
+
fund,
|
|
58437
|
+
sweepToPool,
|
|
58438
|
+
getTokenBalance: burnerGetTokenBalance,
|
|
58439
|
+
getBalance: burnerGetBalance
|
|
58440
|
+
};
|
|
57912
58441
|
}
|
|
57913
58442
|
export {
|
|
57914
58443
|
CONFIRMATION_POLL_INTERVAL_MS,
|
|
@@ -57917,7 +58446,10 @@ export {
|
|
|
57917
58446
|
TimeoutError2 as TimeoutError,
|
|
57918
58447
|
TransactionFailedError,
|
|
57919
58448
|
UnlinkProvider,
|
|
58449
|
+
approve,
|
|
58450
|
+
buildApproveCall,
|
|
57920
58451
|
computeBalances,
|
|
58452
|
+
contract,
|
|
57921
58453
|
decodeAddress,
|
|
57922
58454
|
encodeAddress,
|
|
57923
58455
|
formatAmount,
|
|
@@ -57926,9 +58458,12 @@ export {
|
|
|
57926
58458
|
parseZkAddress,
|
|
57927
58459
|
randomHex,
|
|
57928
58460
|
shortenHex,
|
|
58461
|
+
toCall,
|
|
58462
|
+
useBurner,
|
|
57929
58463
|
useDeposit,
|
|
58464
|
+
useInteract,
|
|
57930
58465
|
useOperationMutation,
|
|
57931
|
-
|
|
58466
|
+
useSend,
|
|
57932
58467
|
useTxStatus,
|
|
57933
58468
|
useUnlink,
|
|
57934
58469
|
useUnlinkBalance,
|