@unlink-xyz/react 0.1.3-canary.01ac52d → 0.1.3-canary.05ae89f
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 +58 -44
- package/dist/index.js +700 -441
- 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
|
@@ -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);
|
|
@@ -35919,17 +35931,48 @@ function parseChainConfig(chain2, value) {
|
|
|
35919
35931
|
"artifactVersion",
|
|
35920
35932
|
raw.artifactVersion
|
|
35921
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(/\/+$/, "");
|
|
35922
35944
|
const artifactBaseUrl = parseOptionalString(
|
|
35923
35945
|
chain2,
|
|
35924
35946
|
"artifactBaseUrl",
|
|
35925
35947
|
raw.artifactBaseUrl
|
|
35926
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
|
+
}
|
|
35927
35967
|
return {
|
|
35928
35968
|
chainId,
|
|
35929
35969
|
gatewayUrl,
|
|
35970
|
+
...frostUrl !== void 0 ? { frostUrl } : {},
|
|
35930
35971
|
poolAddress,
|
|
35972
|
+
...adapterAddress !== void 0 ? { adapterAddress } : {},
|
|
35931
35973
|
artifactVersion,
|
|
35932
|
-
...artifactBaseUrl !== void 0 ? { artifactBaseUrl } : { artifactBaseUrl: DEFAULT_ARTIFACT_BASE_URL }
|
|
35974
|
+
...artifactBaseUrl !== void 0 ? { artifactBaseUrl } : { artifactBaseUrl: DEFAULT_ARTIFACT_BASE_URL },
|
|
35975
|
+
...tokenAddresses !== void 0 ? { tokenAddresses } : {}
|
|
35933
35976
|
};
|
|
35934
35977
|
}
|
|
35935
35978
|
async function fetchChainConfig(chain2) {
|
|
@@ -53332,6 +53375,114 @@ var circuits_default = {
|
|
|
53332
53375
|
template: "JoinSplit",
|
|
53333
53376
|
pubs: ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
|
|
53334
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]
|
|
53335
53486
|
}
|
|
53336
53487
|
};
|
|
53337
53488
|
var registry = {};
|
|
@@ -53347,7 +53498,7 @@ var SUPPORTED_CIRCUITS = Object.keys(CIRCUIT_REGISTRY);
|
|
|
53347
53498
|
function getCircuitConfig(inputs, outputs) {
|
|
53348
53499
|
return CIRCUIT_REGISTRY[`${inputs}x${outputs}`];
|
|
53349
53500
|
}
|
|
53350
|
-
var MAX_ARTIFACT_CACHE_ENTRIES =
|
|
53501
|
+
var MAX_ARTIFACT_CACHE_ENTRIES = 16;
|
|
53351
53502
|
var artifactCache = /* @__PURE__ */ new Map();
|
|
53352
53503
|
function selectCircuit(inputs, outputs) {
|
|
53353
53504
|
const config22 = getCircuitConfig(inputs, outputs);
|
|
@@ -54182,6 +54333,58 @@ function normalizeReshield(reshield, index) {
|
|
|
54182
54333
|
);
|
|
54183
54334
|
return { npk, random, token, minAmount };
|
|
54184
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
|
+
}
|
|
54185
54388
|
function encodeAdapterExecute(params) {
|
|
54186
54389
|
const transactCalldata = ensureHexData(
|
|
54187
54390
|
"transactCalldata",
|
|
@@ -54205,6 +54408,7 @@ function encodeAdapterExecute(params) {
|
|
|
54205
54408
|
deadline
|
|
54206
54409
|
]);
|
|
54207
54410
|
}
|
|
54411
|
+
var buildApproveCall = approve;
|
|
54208
54412
|
init_process();
|
|
54209
54413
|
init_buffer();
|
|
54210
54414
|
init_process();
|
|
@@ -55591,26 +55795,34 @@ function normalizeCall2(call, index) {
|
|
|
55591
55795
|
value: call.value
|
|
55592
55796
|
};
|
|
55593
55797
|
}
|
|
55594
|
-
function
|
|
55595
|
-
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
|
+
}
|
|
55596
55805
|
if (input.amount <= 0n) {
|
|
55597
|
-
throw new AdapterError(`
|
|
55806
|
+
throw new AdapterError(`spend[${index}].amount must be greater than zero`);
|
|
55598
55807
|
}
|
|
55599
55808
|
return {
|
|
55600
55809
|
token,
|
|
55601
55810
|
amount: input.amount
|
|
55602
55811
|
};
|
|
55603
55812
|
}
|
|
55604
|
-
function
|
|
55605
|
-
const token = ensureAddress(`
|
|
55606
|
-
if (
|
|
55813
|
+
function normalizeReceiveInput(receive, index) {
|
|
55814
|
+
const token = ensureAddress(`receive[${index}].token`, receive.token);
|
|
55815
|
+
if (token.toLowerCase() === ETH_TOKEN.toLowerCase()) {
|
|
55607
55816
|
throw new AdapterError(
|
|
55608
|
-
`
|
|
55817
|
+
`receive[${index}].token: native ETH is not supported in adapter execution`
|
|
55609
55818
|
);
|
|
55610
55819
|
}
|
|
55820
|
+
if (receive.minAmount < 0n) {
|
|
55821
|
+
throw new AdapterError(`receive[${index}].minAmount must be non-negative`);
|
|
55822
|
+
}
|
|
55611
55823
|
return {
|
|
55612
55824
|
token,
|
|
55613
|
-
minAmount:
|
|
55825
|
+
minAmount: receive.minAmount
|
|
55614
55826
|
};
|
|
55615
55827
|
}
|
|
55616
55828
|
function randomFieldElement(randomBigintFn) {
|
|
@@ -55630,41 +55842,41 @@ function createAdapterService(deps) {
|
|
|
55630
55842
|
"adapterAddress",
|
|
55631
55843
|
params.adapterAddress
|
|
55632
55844
|
);
|
|
55633
|
-
if (!params.
|
|
55634
|
-
throw new AdapterError("at least one
|
|
55845
|
+
if (!params.spend.length) {
|
|
55846
|
+
throw new AdapterError("at least one spend token is required");
|
|
55635
55847
|
}
|
|
55636
55848
|
if (!params.calls.length) {
|
|
55637
55849
|
throw new AdapterError("at least one adapter call is required");
|
|
55638
55850
|
}
|
|
55639
|
-
if (!params.
|
|
55640
|
-
throw new AdapterError("at least one
|
|
55851
|
+
if (!params.receive.length) {
|
|
55852
|
+
throw new AdapterError("at least one receive output is required");
|
|
55641
55853
|
}
|
|
55642
|
-
const
|
|
55643
|
-
(input, i) =>
|
|
55854
|
+
const spendInputs = params.spend.map(
|
|
55855
|
+
(input, i) => normalizeSpendInput(input, i)
|
|
55644
55856
|
);
|
|
55645
55857
|
const seenTokens = /* @__PURE__ */ new Set();
|
|
55646
|
-
for (const input of
|
|
55858
|
+
for (const input of spendInputs) {
|
|
55647
55859
|
const lower = input.token.toLowerCase();
|
|
55648
55860
|
if (seenTokens.has(lower)) {
|
|
55649
55861
|
throw new AdapterError(
|
|
55650
|
-
`duplicate
|
|
55862
|
+
`duplicate spend token ${input.token}; combine amounts per token instead`
|
|
55651
55863
|
);
|
|
55652
55864
|
}
|
|
55653
55865
|
seenTokens.add(lower);
|
|
55654
55866
|
}
|
|
55655
55867
|
const calls = params.calls.map((call, i) => normalizeCall2(call, i));
|
|
55656
|
-
const
|
|
55657
|
-
(
|
|
55868
|
+
const receiveSpecs = params.receive.map(
|
|
55869
|
+
(receive, i) => normalizeReceiveInput(receive, i)
|
|
55658
55870
|
);
|
|
55659
|
-
const
|
|
55660
|
-
for (const r2 of
|
|
55871
|
+
const seenReceiveTokens = /* @__PURE__ */ new Set();
|
|
55872
|
+
for (const r2 of receiveSpecs) {
|
|
55661
55873
|
const lower = r2.token.toLowerCase();
|
|
55662
|
-
if (
|
|
55874
|
+
if (seenReceiveTokens.has(lower)) {
|
|
55663
55875
|
throw new AdapterError(
|
|
55664
|
-
`duplicate
|
|
55876
|
+
`duplicate receive token ${r2.token}; each receive must target a unique token`
|
|
55665
55877
|
);
|
|
55666
55878
|
}
|
|
55667
|
-
|
|
55879
|
+
seenReceiveTokens.add(lower);
|
|
55668
55880
|
}
|
|
55669
55881
|
const account = overrides?.account ?? await deps.requireActiveAccount();
|
|
55670
55882
|
const signer = overrides?.signer ?? deps.requireSigner(account);
|
|
@@ -55674,19 +55886,19 @@ function createAdapterService(deps) {
|
|
|
55674
55886
|
throw new AdapterError("deadline must be in the future");
|
|
55675
55887
|
}
|
|
55676
55888
|
const executionCalls = calls;
|
|
55677
|
-
const reshields =
|
|
55678
|
-
(
|
|
55889
|
+
const reshields = receiveSpecs.map(
|
|
55890
|
+
(receive) => {
|
|
55679
55891
|
const random = randomFieldElement(randomBigintImpl);
|
|
55680
55892
|
const npk = poseidon([account.masterPublicKey, random]);
|
|
55681
55893
|
return {
|
|
55682
55894
|
npk,
|
|
55683
55895
|
random,
|
|
55684
|
-
token:
|
|
55685
|
-
minAmount:
|
|
55896
|
+
token: receive.token,
|
|
55897
|
+
minAmount: receive.minAmount
|
|
55686
55898
|
};
|
|
55687
55899
|
}
|
|
55688
55900
|
);
|
|
55689
|
-
const inputTokens =
|
|
55901
|
+
const inputTokens = spendInputs.map((input) => input.token);
|
|
55690
55902
|
const nonce = randomFieldElement(randomBigintImpl);
|
|
55691
55903
|
const adapterDataHash = computeAdapterDataHash({
|
|
55692
55904
|
calls: executionCalls,
|
|
@@ -55703,7 +55915,7 @@ function createAdapterService(deps) {
|
|
|
55703
55915
|
});
|
|
55704
55916
|
const withdrawalPlans = planWithdrawalsImpl(
|
|
55705
55917
|
notes,
|
|
55706
|
-
|
|
55918
|
+
spendInputs.map((input) => ({
|
|
55707
55919
|
token: input.token,
|
|
55708
55920
|
amount: input.amount,
|
|
55709
55921
|
recipient: adapterAddress
|
|
@@ -55786,7 +55998,7 @@ function createAdapterService(deps) {
|
|
|
55786
55998
|
adapterCalldata,
|
|
55787
55999
|
historyPreview: {
|
|
55788
56000
|
kind: "Withdraw",
|
|
55789
|
-
amounts:
|
|
56001
|
+
amounts: spendInputs.map((input) => ({
|
|
55790
56002
|
token: input.token,
|
|
55791
56003
|
delta: (-input.amount).toString()
|
|
55792
56004
|
}))
|
|
@@ -55806,6 +56018,9 @@ init_process();
|
|
|
55806
56018
|
init_buffer();
|
|
55807
56019
|
var BIP44_ETH_PREFIX = "m/44'/60'/0'/0";
|
|
55808
56020
|
var ERC20_BALANCE_OF = "function balanceOf(address) view returns (uint256)";
|
|
56021
|
+
function isNativeToken(token) {
|
|
56022
|
+
return token.toLowerCase() === ETH_TOKEN.toLowerCase();
|
|
56023
|
+
}
|
|
55809
56024
|
function createBurnerService(deps) {
|
|
55810
56025
|
const { chainRpcUrl, getMasterSeed, withdrawToAddress, requestDeposit } = deps;
|
|
55811
56026
|
const provider = new JsonRpcProvider(chainRpcUrl);
|
|
@@ -55853,8 +56068,8 @@ function createBurnerService(deps) {
|
|
|
55853
56068
|
}
|
|
55854
56069
|
async function getTokenBalance(address, token) {
|
|
55855
56070
|
const iface = new Interface([ERC20_BALANCE_OF]);
|
|
55856
|
-
const
|
|
55857
|
-
const bal = await
|
|
56071
|
+
const contract2 = new Contract(token, iface, provider);
|
|
56072
|
+
const bal = await contract2.getFunction("balanceOf")(address);
|
|
55858
56073
|
return BigInt(bal ?? 0);
|
|
55859
56074
|
}
|
|
55860
56075
|
async function getBalance(address) {
|
|
@@ -55873,6 +56088,12 @@ function createBurnerService(deps) {
|
|
|
55873
56088
|
}
|
|
55874
56089
|
async function sweepToPool(index, params) {
|
|
55875
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
|
+
}
|
|
55876
56097
|
const amount = params.amount ?? await getTokenBalance(address, params.token);
|
|
55877
56098
|
if (amount === 0n) {
|
|
55878
56099
|
throw new Error("No token balance to sweep");
|
|
@@ -55883,17 +56104,20 @@ function createBurnerService(deps) {
|
|
|
55883
56104
|
depositor: address,
|
|
55884
56105
|
deposits: [{ token: params.token, amount }]
|
|
55885
56106
|
});
|
|
55886
|
-
|
|
55887
|
-
|
|
55888
|
-
|
|
55889
|
-
|
|
55890
|
-
|
|
55891
|
-
|
|
55892
|
-
|
|
55893
|
-
|
|
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
|
+
}
|
|
55894
56117
|
const { txHash } = await send(index, {
|
|
55895
56118
|
to: depositResult.to,
|
|
55896
|
-
data: depositResult.calldata
|
|
56119
|
+
data: depositResult.calldata,
|
|
56120
|
+
value: depositResult.value
|
|
55897
56121
|
});
|
|
55898
56122
|
return { txHash };
|
|
55899
56123
|
}
|
|
@@ -56546,20 +56770,26 @@ function createWalletSDK(deps, options) {
|
|
|
56546
56770
|
};
|
|
56547
56771
|
return sdk;
|
|
56548
56772
|
}
|
|
56549
|
-
var
|
|
56773
|
+
var Unlink = class _Unlink {
|
|
56550
56774
|
/** @internal */
|
|
56551
56775
|
sdk;
|
|
56552
56776
|
/** Chain ID this wallet operates on. */
|
|
56553
56777
|
chainId;
|
|
56554
56778
|
/** Pool contract address this wallet transacts with. */
|
|
56555
56779
|
poolAddress;
|
|
56556
|
-
|
|
56780
|
+
/** Adapter contract address for DeFi operations. */
|
|
56781
|
+
adapterAddress;
|
|
56782
|
+
constructor(sdk, chainId, poolAddress, adapterAddress) {
|
|
56557
56783
|
this.sdk = sdk;
|
|
56558
56784
|
this.chainId = chainId;
|
|
56559
56785
|
this.poolAddress = poolAddress;
|
|
56786
|
+
this.adapterAddress = adapterAddress;
|
|
56787
|
+
this.adapter = {
|
|
56788
|
+
address: adapterAddress
|
|
56789
|
+
};
|
|
56560
56790
|
}
|
|
56561
56791
|
/**
|
|
56562
|
-
* Create a new
|
|
56792
|
+
* Create a new Unlink instance.
|
|
56563
56793
|
*
|
|
56564
56794
|
* Handles all initialization internally:
|
|
56565
56795
|
* - Resolves chain config (if using `chain` instead of explicit URLs)
|
|
@@ -56571,12 +56801,14 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
56571
56801
|
let chainId;
|
|
56572
56802
|
let gatewayUrl;
|
|
56573
56803
|
let poolAddress;
|
|
56804
|
+
let adapterAddress;
|
|
56574
56805
|
let proverConfig = config22.prover;
|
|
56575
56806
|
if ("chain" in config22) {
|
|
56576
56807
|
const chainConfig = await fetchChainConfig(config22.chain);
|
|
56577
56808
|
chainId = chainConfig.chainId;
|
|
56578
56809
|
gatewayUrl = chainConfig.gatewayUrl;
|
|
56579
56810
|
poolAddress = config22.poolAddress ?? chainConfig.poolAddress;
|
|
56811
|
+
adapterAddress = config22.adapterAddress ?? chainConfig.adapterAddress;
|
|
56580
56812
|
proverConfig = {
|
|
56581
56813
|
artifactSource: {
|
|
56582
56814
|
baseUrl: config22.prover?.artifactSource?.baseUrl ?? chainConfig.artifactBaseUrl,
|
|
@@ -56588,6 +56820,7 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
56588
56820
|
chainId = config22.chainId;
|
|
56589
56821
|
gatewayUrl = config22.gatewayUrl;
|
|
56590
56822
|
poolAddress = config22.poolAddress;
|
|
56823
|
+
adapterAddress = config22.adapterAddress;
|
|
56591
56824
|
if (typeof window !== "undefined" && !config22.prover?.artifactSource?.version) {
|
|
56592
56825
|
throw new InitializationError(
|
|
56593
56826
|
"prover.artifactSource.version is required in browser when using explicit gatewayUrl mode. Use chain mode or provide a pinned artifact version."
|
|
@@ -56608,7 +56841,7 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
56608
56841
|
autoSync: config22.autoSync
|
|
56609
56842
|
}
|
|
56610
56843
|
);
|
|
56611
|
-
return new
|
|
56844
|
+
return new _Unlink(sdk, chainId, poolAddress, adapterAddress ?? "");
|
|
56612
56845
|
}
|
|
56613
56846
|
// ===== Seed Lifecycle =====
|
|
56614
56847
|
/** Seed management (create, import, export, delete mnemonic). */
|
|
@@ -56639,10 +56872,10 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
56639
56872
|
return this.sdk.deposit.reconcile(relayId);
|
|
56640
56873
|
}
|
|
56641
56874
|
/**
|
|
56642
|
-
*
|
|
56875
|
+
* Send a private transfer (1 or more recipients).
|
|
56643
56876
|
* Handles note selection, circuit selection, and proof generation automatically.
|
|
56644
56877
|
*/
|
|
56645
|
-
async
|
|
56878
|
+
async send(params, overrides) {
|
|
56646
56879
|
return this.sdk.transfer.send(
|
|
56647
56880
|
{
|
|
56648
56881
|
chainId: this.chainId,
|
|
@@ -56653,9 +56886,9 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
56653
56886
|
);
|
|
56654
56887
|
}
|
|
56655
56888
|
/**
|
|
56656
|
-
* Get a
|
|
56889
|
+
* Get a send plan without executing (for preview/confirmation UIs).
|
|
56657
56890
|
*/
|
|
56658
|
-
async
|
|
56891
|
+
async planSend(params, account) {
|
|
56659
56892
|
return this.sdk.transfer.plan(
|
|
56660
56893
|
{
|
|
56661
56894
|
chainId: this.chainId,
|
|
@@ -56665,8 +56898,8 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
56665
56898
|
account
|
|
56666
56899
|
);
|
|
56667
56900
|
}
|
|
56668
|
-
/** Execute a pre-built
|
|
56669
|
-
async
|
|
56901
|
+
/** Execute a pre-built send plan. */
|
|
56902
|
+
async executeSend(plans, overrides) {
|
|
56670
56903
|
return this.sdk.transfer.execute(
|
|
56671
56904
|
plans,
|
|
56672
56905
|
{ chainId: this.chainId, poolAddress: this.poolAddress },
|
|
@@ -56815,31 +57048,31 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
56815
57048
|
return this.sdk.burner.getBalance(address);
|
|
56816
57049
|
}
|
|
56817
57050
|
};
|
|
56818
|
-
// =====
|
|
57051
|
+
// ===== Interact (Private DeFi) =====
|
|
56819
57052
|
/**
|
|
56820
|
-
*
|
|
56821
|
-
*
|
|
57053
|
+
* Adapter contract address (resolved from config).
|
|
57054
|
+
* Use for building DeFi calls that reference the adapter.
|
|
56822
57055
|
*/
|
|
56823
|
-
adapter
|
|
56824
|
-
|
|
56825
|
-
|
|
56826
|
-
|
|
56827
|
-
|
|
56828
|
-
|
|
56829
|
-
|
|
56830
|
-
|
|
56831
|
-
|
|
56832
|
-
|
|
56833
|
-
|
|
56834
|
-
|
|
56835
|
-
|
|
56836
|
-
|
|
56837
|
-
|
|
56838
|
-
|
|
56839
|
-
|
|
56840
|
-
|
|
56841
|
-
|
|
56842
|
-
}
|
|
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
|
+
}
|
|
56843
57076
|
// ===== Advanced =====
|
|
56844
57077
|
/**
|
|
56845
57078
|
* Advanced escape hatch for raw JoinSplit transaction building.
|
|
@@ -56959,7 +57192,7 @@ function createUnlinkError(err, operation) {
|
|
|
56959
57192
|
};
|
|
56960
57193
|
}
|
|
56961
57194
|
var initialState = {
|
|
56962
|
-
|
|
57195
|
+
unlink: null,
|
|
56963
57196
|
walletExists: false,
|
|
56964
57197
|
accounts: [],
|
|
56965
57198
|
activeAccount: null,
|
|
@@ -56969,7 +57202,7 @@ var initialState = {
|
|
|
56969
57202
|
balances: {},
|
|
56970
57203
|
burners: [],
|
|
56971
57204
|
pendingDeposits: [],
|
|
56972
|
-
|
|
57205
|
+
pendingSends: [],
|
|
56973
57206
|
pendingWithdrawals: [],
|
|
56974
57207
|
ready: false,
|
|
56975
57208
|
busy: false,
|
|
@@ -56995,13 +57228,13 @@ function UnlinkProvider({
|
|
|
56995
57228
|
const chainId = "chainId" in configProps ? configProps.chainId : void 0;
|
|
56996
57229
|
const gatewayUrl = "gatewayUrl" in configProps ? configProps.gatewayUrl : void 0;
|
|
56997
57230
|
const [state, setState] = useState(initialState);
|
|
56998
|
-
const
|
|
57231
|
+
const unlinkRef = useRef(null);
|
|
56999
57232
|
const proverKey = JSON.stringify(prover ?? null);
|
|
57000
|
-
const refreshAccounts = useCallback(async (
|
|
57233
|
+
const refreshAccounts = useCallback(async (unlink) => {
|
|
57001
57234
|
try {
|
|
57002
|
-
const accounts = await
|
|
57003
|
-
const activeAccount = await
|
|
57004
|
-
const activeAccountIndex = await
|
|
57235
|
+
const accounts = await unlink.accounts.list();
|
|
57236
|
+
const activeAccount = await unlink.accounts.getActive();
|
|
57237
|
+
const activeAccountIndex = await unlink.accounts.getActiveIndex();
|
|
57005
57238
|
setState((prev2) => ({
|
|
57006
57239
|
...prev2,
|
|
57007
57240
|
accounts,
|
|
@@ -57012,11 +57245,11 @@ function UnlinkProvider({
|
|
|
57012
57245
|
console.error("[UnlinkProvider] refreshAccounts error", err);
|
|
57013
57246
|
}
|
|
57014
57247
|
}, []);
|
|
57015
|
-
const refreshState = useCallback(async (
|
|
57248
|
+
const refreshState = useCallback(async (unlink) => {
|
|
57016
57249
|
try {
|
|
57017
|
-
const noteRecords = await
|
|
57250
|
+
const noteRecords = await unlink.getNotes();
|
|
57018
57251
|
const notes = convertNotes(noteRecords);
|
|
57019
|
-
const balances = await
|
|
57252
|
+
const balances = await unlink.getBalances();
|
|
57020
57253
|
setState((prev2) => ({ ...prev2, notes, balances }));
|
|
57021
57254
|
} catch (err) {
|
|
57022
57255
|
console.error("[UnlinkProvider] refresh error", err);
|
|
@@ -57042,7 +57275,7 @@ function UnlinkProvider({
|
|
|
57042
57275
|
...prev2,
|
|
57043
57276
|
status: "Initializing SDK..."
|
|
57044
57277
|
}));
|
|
57045
|
-
const
|
|
57278
|
+
const unlink = await Unlink.create(
|
|
57046
57279
|
chain2 ? {
|
|
57047
57280
|
chain: chain2,
|
|
57048
57281
|
poolAddress,
|
|
@@ -57055,8 +57288,8 @@ function UnlinkProvider({
|
|
|
57055
57288
|
}
|
|
57056
57289
|
);
|
|
57057
57290
|
if (cancelled) return;
|
|
57058
|
-
|
|
57059
|
-
const walletExists = await
|
|
57291
|
+
unlinkRef.current = unlink;
|
|
57292
|
+
const walletExists = await unlink.seed.exists();
|
|
57060
57293
|
if (cancelled) return;
|
|
57061
57294
|
let accounts = [];
|
|
57062
57295
|
let activeAccount = null;
|
|
@@ -57064,33 +57297,33 @@ function UnlinkProvider({
|
|
|
57064
57297
|
let notes = [];
|
|
57065
57298
|
let balances = {};
|
|
57066
57299
|
if (walletExists) {
|
|
57067
|
-
accounts = await
|
|
57300
|
+
accounts = await unlink.accounts.list();
|
|
57068
57301
|
if (accounts.length === 0) {
|
|
57069
|
-
await
|
|
57070
|
-
accounts = await
|
|
57302
|
+
await unlink.accounts.create();
|
|
57303
|
+
accounts = await unlink.accounts.list();
|
|
57071
57304
|
}
|
|
57072
|
-
activeAccount = await
|
|
57073
|
-
activeAccountIndex = await
|
|
57305
|
+
activeAccount = await unlink.accounts.getActive();
|
|
57306
|
+
activeAccountIndex = await unlink.accounts.getActiveIndex();
|
|
57074
57307
|
if (accounts.length > 0 && !activeAccount) {
|
|
57075
|
-
await
|
|
57076
|
-
activeAccount = await
|
|
57077
|
-
activeAccountIndex = await
|
|
57308
|
+
await unlink.accounts.setActive(accounts[0].index);
|
|
57309
|
+
activeAccount = await unlink.accounts.getActive();
|
|
57310
|
+
activeAccountIndex = await unlink.accounts.getActiveIndex();
|
|
57078
57311
|
}
|
|
57079
57312
|
if (activeAccount) {
|
|
57080
|
-
const noteRecords = await
|
|
57313
|
+
const noteRecords = await unlink.getNotes();
|
|
57081
57314
|
notes = convertNotes(noteRecords);
|
|
57082
|
-
balances = await
|
|
57315
|
+
balances = await unlink.getBalances();
|
|
57083
57316
|
}
|
|
57084
57317
|
}
|
|
57085
57318
|
const statusMessage = !walletExists ? "No wallet - create or import one" : !activeAccount ? "No account - create one to get started" : "Ready";
|
|
57086
57319
|
setState((prev2) => ({
|
|
57087
57320
|
...prev2,
|
|
57088
|
-
|
|
57321
|
+
unlink,
|
|
57089
57322
|
walletExists,
|
|
57090
57323
|
accounts,
|
|
57091
57324
|
activeAccount,
|
|
57092
57325
|
activeAccountIndex,
|
|
57093
|
-
chainId:
|
|
57326
|
+
chainId: unlink.chainId,
|
|
57094
57327
|
notes,
|
|
57095
57328
|
balances,
|
|
57096
57329
|
ready: true,
|
|
@@ -57098,12 +57331,12 @@ function UnlinkProvider({
|
|
|
57098
57331
|
error: null
|
|
57099
57332
|
}));
|
|
57100
57333
|
if (autoSync && walletExists && activeAccount) {
|
|
57101
|
-
|
|
57334
|
+
unlink.startAutoSync(syncInterval);
|
|
57102
57335
|
}
|
|
57103
|
-
unsubscribe =
|
|
57104
|
-
if (event.type === "notes-updated" && event.chainId ===
|
|
57336
|
+
unsubscribe = unlink.on((event) => {
|
|
57337
|
+
if (event.type === "notes-updated" && event.chainId === unlink.chainId) {
|
|
57105
57338
|
setState((prev2) => ({ ...prev2, syncError: null }));
|
|
57106
|
-
void refreshState(
|
|
57339
|
+
void refreshState(unlink);
|
|
57107
57340
|
}
|
|
57108
57341
|
if (event.type === "sync-error") {
|
|
57109
57342
|
setState((prev2) => ({ ...prev2, syncError: event.error }));
|
|
@@ -57112,9 +57345,9 @@ function UnlinkProvider({
|
|
|
57112
57345
|
setState((prev2) => ({ ...prev2, walletExists: true }));
|
|
57113
57346
|
}
|
|
57114
57347
|
if (event.type === "account-created" || event.type === "account-switched") {
|
|
57115
|
-
void refreshAccounts(
|
|
57348
|
+
void refreshAccounts(unlink);
|
|
57116
57349
|
if (event.type === "account-switched") {
|
|
57117
|
-
void refreshState(
|
|
57350
|
+
void refreshState(unlink);
|
|
57118
57351
|
}
|
|
57119
57352
|
}
|
|
57120
57353
|
});
|
|
@@ -57132,7 +57365,7 @@ function UnlinkProvider({
|
|
|
57132
57365
|
return () => {
|
|
57133
57366
|
cancelled = true;
|
|
57134
57367
|
unsubscribe?.();
|
|
57135
|
-
|
|
57368
|
+
unlinkRef.current?.stopAutoSync();
|
|
57136
57369
|
};
|
|
57137
57370
|
}, [
|
|
57138
57371
|
chain2,
|
|
@@ -57146,11 +57379,11 @@ function UnlinkProvider({
|
|
|
57146
57379
|
proverKey
|
|
57147
57380
|
]);
|
|
57148
57381
|
const createWallet = useCallback(async () => {
|
|
57149
|
-
const
|
|
57150
|
-
if (!
|
|
57382
|
+
const unlink = unlinkRef.current;
|
|
57383
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57151
57384
|
setState((prev2) => ({ ...prev2, busy: true, status: "Creating wallet..." }));
|
|
57152
57385
|
try {
|
|
57153
|
-
const result = await
|
|
57386
|
+
const result = await unlink.seed.create();
|
|
57154
57387
|
setState((prev2) => ({
|
|
57155
57388
|
...prev2,
|
|
57156
57389
|
walletExists: true,
|
|
@@ -57171,18 +57404,18 @@ function UnlinkProvider({
|
|
|
57171
57404
|
}
|
|
57172
57405
|
}, []);
|
|
57173
57406
|
const importWallet = useCallback(async (mnemonic) => {
|
|
57174
|
-
const
|
|
57175
|
-
if (!
|
|
57407
|
+
const unlink = unlinkRef.current;
|
|
57408
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57176
57409
|
setState((prev2) => ({
|
|
57177
57410
|
...prev2,
|
|
57178
57411
|
busy: true,
|
|
57179
57412
|
status: "Importing wallet..."
|
|
57180
57413
|
}));
|
|
57181
57414
|
try {
|
|
57182
|
-
await
|
|
57183
|
-
const accounts = await
|
|
57184
|
-
const activeAccount = await
|
|
57185
|
-
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();
|
|
57186
57419
|
setState((prev2) => ({
|
|
57187
57420
|
...prev2,
|
|
57188
57421
|
walletExists: true,
|
|
@@ -57206,16 +57439,16 @@ function UnlinkProvider({
|
|
|
57206
57439
|
}
|
|
57207
57440
|
}, []);
|
|
57208
57441
|
const exportMnemonic = useCallback(async () => {
|
|
57209
|
-
const
|
|
57210
|
-
if (!
|
|
57211
|
-
return
|
|
57442
|
+
const unlink = unlinkRef.current;
|
|
57443
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57444
|
+
return unlink.seed.exportMnemonic();
|
|
57212
57445
|
}, []);
|
|
57213
57446
|
const clearWallet = useCallback(async () => {
|
|
57214
|
-
const
|
|
57215
|
-
if (!
|
|
57447
|
+
const unlink = unlinkRef.current;
|
|
57448
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57216
57449
|
setState((prev2) => ({ ...prev2, busy: true, status: "Clearing wallet..." }));
|
|
57217
57450
|
try {
|
|
57218
|
-
await
|
|
57451
|
+
await unlink.seed.delete();
|
|
57219
57452
|
setState((prev2) => ({
|
|
57220
57453
|
...prev2,
|
|
57221
57454
|
walletExists: false,
|
|
@@ -57242,18 +57475,18 @@ function UnlinkProvider({
|
|
|
57242
57475
|
}, []);
|
|
57243
57476
|
const createAccount = useCallback(
|
|
57244
57477
|
async (index) => {
|
|
57245
|
-
const
|
|
57246
|
-
if (!
|
|
57478
|
+
const unlink = unlinkRef.current;
|
|
57479
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57247
57480
|
setState((prev2) => ({
|
|
57248
57481
|
...prev2,
|
|
57249
57482
|
busy: true,
|
|
57250
57483
|
status: "Creating account..."
|
|
57251
57484
|
}));
|
|
57252
57485
|
try {
|
|
57253
|
-
const account = await
|
|
57254
|
-
const accounts = await
|
|
57255
|
-
const activeAccount = await
|
|
57256
|
-
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();
|
|
57257
57490
|
setState((prev2) => ({
|
|
57258
57491
|
...prev2,
|
|
57259
57492
|
accounts,
|
|
@@ -57264,7 +57497,7 @@ function UnlinkProvider({
|
|
|
57264
57497
|
error: null
|
|
57265
57498
|
}));
|
|
57266
57499
|
if (autoSync && accounts.length === 1) {
|
|
57267
|
-
|
|
57500
|
+
unlink.startAutoSync(syncInterval);
|
|
57268
57501
|
}
|
|
57269
57502
|
return account;
|
|
57270
57503
|
} catch (err) {
|
|
@@ -57280,22 +57513,22 @@ function UnlinkProvider({
|
|
|
57280
57513
|
[autoSync, syncInterval]
|
|
57281
57514
|
);
|
|
57282
57515
|
const switchAccount = useCallback(async (index) => {
|
|
57283
|
-
const
|
|
57284
|
-
if (!
|
|
57516
|
+
const unlink = unlinkRef.current;
|
|
57517
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57285
57518
|
setState((prev2) => ({
|
|
57286
57519
|
...prev2,
|
|
57287
57520
|
busy: true,
|
|
57288
57521
|
status: "Switching account..."
|
|
57289
57522
|
}));
|
|
57290
57523
|
try {
|
|
57291
|
-
await
|
|
57292
|
-
const activeAccount = await
|
|
57524
|
+
await unlink.accounts.setActive(index);
|
|
57525
|
+
const activeAccount = await unlink.accounts.getActive();
|
|
57293
57526
|
let notes = [];
|
|
57294
57527
|
let balances = {};
|
|
57295
57528
|
if (activeAccount) {
|
|
57296
|
-
const noteRecords = await
|
|
57529
|
+
const noteRecords = await unlink.getNotes();
|
|
57297
57530
|
notes = convertNotes(noteRecords);
|
|
57298
|
-
balances = await
|
|
57531
|
+
balances = await unlink.getBalances();
|
|
57299
57532
|
}
|
|
57300
57533
|
setState((prev2) => ({
|
|
57301
57534
|
...prev2,
|
|
@@ -57317,58 +57550,64 @@ function UnlinkProvider({
|
|
|
57317
57550
|
throw err;
|
|
57318
57551
|
}
|
|
57319
57552
|
}, []);
|
|
57320
|
-
const send = useCallback(
|
|
57321
|
-
|
|
57322
|
-
|
|
57323
|
-
|
|
57324
|
-
|
|
57325
|
-
|
|
57326
|
-
|
|
57327
|
-
...prev2,
|
|
57328
|
-
busy: true,
|
|
57329
|
-
status: params.length > 1 ? `Sending (${params.length} transfers)...` : "Sending..."
|
|
57330
|
-
}));
|
|
57331
|
-
try {
|
|
57332
|
-
const result = await wallet.transfer({
|
|
57333
|
-
transfers: params.map((t) => ({
|
|
57334
|
-
token: t.token,
|
|
57335
|
-
recipient: t.recipient,
|
|
57336
|
-
amount: t.amount
|
|
57337
|
-
}))
|
|
57338
|
-
});
|
|
57339
|
-
setState((prev2) => ({
|
|
57340
|
-
...prev2,
|
|
57341
|
-
busy: false,
|
|
57342
|
-
status: params.length > 1 ? `Transfer submitted (${params.length} transfers)` : "Transfer submitted",
|
|
57343
|
-
pendingTransfers: [
|
|
57344
|
-
...prev2.pendingTransfers,
|
|
57345
|
-
...params.map((t, i) => ({
|
|
57346
|
-
txId: `${result.relayId}-${i}`,
|
|
57347
|
-
status: "pending",
|
|
57348
|
-
chainId: wallet.chainId,
|
|
57349
|
-
token: t.token,
|
|
57350
|
-
amount: t.amount,
|
|
57351
|
-
recipient: t.recipient,
|
|
57352
|
-
startedAt: Date.now()
|
|
57353
|
-
}))
|
|
57354
|
-
],
|
|
57355
|
-
error: null
|
|
57356
|
-
}));
|
|
57357
|
-
return result;
|
|
57358
|
-
} 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
|
+
}
|
|
57359
57560
|
setState((prev2) => ({
|
|
57360
57561
|
...prev2,
|
|
57361
|
-
busy:
|
|
57362
|
-
status:
|
|
57363
|
-
error: createUnlinkError(err, "send")
|
|
57562
|
+
busy: true,
|
|
57563
|
+
status: params.length > 1 ? `Sending (${params.length} transfers)...` : "Sending..."
|
|
57364
57564
|
}));
|
|
57365
|
-
|
|
57366
|
-
|
|
57367
|
-
|
|
57368
|
-
|
|
57369
|
-
|
|
57370
|
-
|
|
57371
|
-
|
|
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({
|
|
57372
57611
|
transfers: params.map((t) => ({
|
|
57373
57612
|
token: t.token,
|
|
57374
57613
|
recipient: t.recipient,
|
|
@@ -57376,37 +57615,40 @@ function UnlinkProvider({
|
|
|
57376
57615
|
}))
|
|
57377
57616
|
});
|
|
57378
57617
|
}, []);
|
|
57379
|
-
const
|
|
57380
|
-
|
|
57381
|
-
|
|
57382
|
-
|
|
57383
|
-
...prev2,
|
|
57384
|
-
busy: true,
|
|
57385
|
-
status: "Executing transfer..."
|
|
57386
|
-
}));
|
|
57387
|
-
try {
|
|
57388
|
-
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");
|
|
57389
57622
|
setState((prev2) => ({
|
|
57390
57623
|
...prev2,
|
|
57391
|
-
busy:
|
|
57392
|
-
status: "
|
|
57393
|
-
error: null
|
|
57394
|
-
}));
|
|
57395
|
-
return result;
|
|
57396
|
-
} catch (err) {
|
|
57397
|
-
setState((prev2) => ({
|
|
57398
|
-
...prev2,
|
|
57399
|
-
busy: false,
|
|
57400
|
-
status: `Error: ${err instanceof Error ? err.message : "Unknown"}`,
|
|
57401
|
-
error: createUnlinkError(err, "executeTransfer")
|
|
57624
|
+
busy: true,
|
|
57625
|
+
status: "Executing send..."
|
|
57402
57626
|
}));
|
|
57403
|
-
|
|
57404
|
-
|
|
57405
|
-
|
|
57406
|
-
|
|
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(
|
|
57407
57649
|
async (params) => {
|
|
57408
|
-
const
|
|
57409
|
-
if (!
|
|
57650
|
+
const unlink = unlinkRef.current;
|
|
57651
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57410
57652
|
if (params.length === 0) {
|
|
57411
57653
|
throw new Error("At least one deposit is required");
|
|
57412
57654
|
}
|
|
@@ -57420,7 +57662,7 @@ function UnlinkProvider({
|
|
|
57420
57662
|
status: params.length > 1 ? `Preparing deposit (${params.length} tokens)...` : "Preparing deposit..."
|
|
57421
57663
|
}));
|
|
57422
57664
|
try {
|
|
57423
|
-
const result = await
|
|
57665
|
+
const result = await unlink.deposit({
|
|
57424
57666
|
depositor,
|
|
57425
57667
|
deposits: params.map((d2) => ({
|
|
57426
57668
|
token: d2.token,
|
|
@@ -57438,7 +57680,7 @@ function UnlinkProvider({
|
|
|
57438
57680
|
status: "pending",
|
|
57439
57681
|
token: c.token,
|
|
57440
57682
|
amount: c.amount,
|
|
57441
|
-
chainId:
|
|
57683
|
+
chainId: unlink.chainId,
|
|
57442
57684
|
commitment: c.commitment,
|
|
57443
57685
|
startedAt: Date.now()
|
|
57444
57686
|
}))
|
|
@@ -57451,17 +57693,17 @@ function UnlinkProvider({
|
|
|
57451
57693
|
...prev2,
|
|
57452
57694
|
busy: false,
|
|
57453
57695
|
status: `Error: ${err instanceof Error ? err.message : "Unknown"}`,
|
|
57454
|
-
error: createUnlinkError(err, "
|
|
57696
|
+
error: createUnlinkError(err, "deposit")
|
|
57455
57697
|
}));
|
|
57456
57698
|
throw err;
|
|
57457
57699
|
}
|
|
57458
57700
|
},
|
|
57459
57701
|
[]
|
|
57460
57702
|
);
|
|
57461
|
-
const
|
|
57462
|
-
async (params) => {
|
|
57463
|
-
const
|
|
57464
|
-
if (!
|
|
57703
|
+
const withdraw = useCallback(
|
|
57704
|
+
async (params, overrides) => {
|
|
57705
|
+
const unlink = unlinkRef.current;
|
|
57706
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57465
57707
|
if (params.length === 0) {
|
|
57466
57708
|
throw new Error("At least one withdrawal is required");
|
|
57467
57709
|
}
|
|
@@ -57471,13 +57713,16 @@ function UnlinkProvider({
|
|
|
57471
57713
|
status: params.length > 1 ? `Processing withdrawal (${params.length} tokens)...` : "Withdrawing..."
|
|
57472
57714
|
}));
|
|
57473
57715
|
try {
|
|
57474
|
-
const result = await
|
|
57475
|
-
|
|
57476
|
-
|
|
57477
|
-
|
|
57478
|
-
|
|
57479
|
-
|
|
57480
|
-
|
|
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
|
+
);
|
|
57481
57726
|
setState((prev2) => ({
|
|
57482
57727
|
...prev2,
|
|
57483
57728
|
busy: false,
|
|
@@ -57487,7 +57732,7 @@ function UnlinkProvider({
|
|
|
57487
57732
|
...params.map((w, i) => ({
|
|
57488
57733
|
txId: `${result.relayId}-${i}`,
|
|
57489
57734
|
status: "pending",
|
|
57490
|
-
chainId:
|
|
57735
|
+
chainId: unlink.chainId,
|
|
57491
57736
|
token: w.token,
|
|
57492
57737
|
amount: w.amount,
|
|
57493
57738
|
recipient: w.recipient,
|
|
@@ -57502,28 +57747,28 @@ function UnlinkProvider({
|
|
|
57502
57747
|
...prev2,
|
|
57503
57748
|
busy: false,
|
|
57504
57749
|
status: `Error: ${err instanceof Error ? err.message : "Unknown"}`,
|
|
57505
|
-
error: createUnlinkError(err, "
|
|
57750
|
+
error: createUnlinkError(err, "withdraw")
|
|
57506
57751
|
}));
|
|
57507
57752
|
throw err;
|
|
57508
57753
|
}
|
|
57509
57754
|
},
|
|
57510
57755
|
[]
|
|
57511
57756
|
);
|
|
57512
|
-
const
|
|
57757
|
+
const interact = useCallback(
|
|
57513
57758
|
async (params) => {
|
|
57514
|
-
const
|
|
57515
|
-
if (!
|
|
57759
|
+
const unlink = unlinkRef.current;
|
|
57760
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57516
57761
|
setState((prev2) => ({
|
|
57517
57762
|
...prev2,
|
|
57518
57763
|
busy: true,
|
|
57519
|
-
status: "Executing
|
|
57764
|
+
status: "Executing interaction..."
|
|
57520
57765
|
}));
|
|
57521
57766
|
try {
|
|
57522
|
-
const result = await
|
|
57767
|
+
const result = await unlink.interact(params);
|
|
57523
57768
|
setState((prev2) => ({
|
|
57524
57769
|
...prev2,
|
|
57525
57770
|
busy: false,
|
|
57526
|
-
status: "
|
|
57771
|
+
status: "Interaction submitted",
|
|
57527
57772
|
error: null
|
|
57528
57773
|
}));
|
|
57529
57774
|
return result;
|
|
@@ -57532,7 +57777,7 @@ function UnlinkProvider({
|
|
|
57532
57777
|
...prev2,
|
|
57533
57778
|
busy: false,
|
|
57534
57779
|
status: `Error: ${err instanceof Error ? err.message : "Unknown"}`,
|
|
57535
|
-
error: createUnlinkError(err, "
|
|
57780
|
+
error: createUnlinkError(err, "interact")
|
|
57536
57781
|
}));
|
|
57537
57782
|
throw err;
|
|
57538
57783
|
}
|
|
@@ -57541,9 +57786,9 @@ function UnlinkProvider({
|
|
|
57541
57786
|
);
|
|
57542
57787
|
const planWithdraw = useCallback(
|
|
57543
57788
|
async (params) => {
|
|
57544
|
-
const
|
|
57545
|
-
if (!
|
|
57546
|
-
return
|
|
57789
|
+
const unlink = unlinkRef.current;
|
|
57790
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57791
|
+
return unlink.planWithdraw({
|
|
57547
57792
|
withdrawals: params.map((w) => ({
|
|
57548
57793
|
token: w.token,
|
|
57549
57794
|
amount: w.amount,
|
|
@@ -57553,43 +57798,46 @@ function UnlinkProvider({
|
|
|
57553
57798
|
},
|
|
57554
57799
|
[]
|
|
57555
57800
|
);
|
|
57556
|
-
const executeWithdraw = useCallback(
|
|
57557
|
-
|
|
57558
|
-
|
|
57559
|
-
|
|
57560
|
-
...prev2,
|
|
57561
|
-
busy: true,
|
|
57562
|
-
status: plans.length > 1 ? `Executing withdrawal (${plans.length} tokens)...` : "Executing withdrawal..."
|
|
57563
|
-
}));
|
|
57564
|
-
try {
|
|
57565
|
-
const result = await wallet.executeWithdraw(plans);
|
|
57566
|
-
setState((prev2) => ({
|
|
57567
|
-
...prev2,
|
|
57568
|
-
busy: false,
|
|
57569
|
-
status: plans.length > 1 ? `Withdrawal executed (${plans.length} tokens)` : "Withdrawal executed",
|
|
57570
|
-
error: null
|
|
57571
|
-
}));
|
|
57572
|
-
return result;
|
|
57573
|
-
} catch (err) {
|
|
57801
|
+
const executeWithdraw = useCallback(
|
|
57802
|
+
async (plans, overrides) => {
|
|
57803
|
+
const unlink = unlinkRef.current;
|
|
57804
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57574
57805
|
setState((prev2) => ({
|
|
57575
57806
|
...prev2,
|
|
57576
|
-
busy:
|
|
57577
|
-
status:
|
|
57578
|
-
error: createUnlinkError(err, "executeWithdraw")
|
|
57807
|
+
busy: true,
|
|
57808
|
+
status: plans.length > 1 ? `Executing withdrawal (${plans.length} tokens)...` : "Executing withdrawal..."
|
|
57579
57809
|
}));
|
|
57580
|
-
|
|
57581
|
-
|
|
57582
|
-
|
|
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
|
+
);
|
|
57583
57831
|
const createBurner = useCallback(async (index) => {
|
|
57584
|
-
const
|
|
57585
|
-
if (!
|
|
57832
|
+
const unlink = unlinkRef.current;
|
|
57833
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57586
57834
|
setState((prev2) => ({
|
|
57587
57835
|
...prev2,
|
|
57588
57836
|
busy: true,
|
|
57589
57837
|
status: `Creating burner ${index}...`
|
|
57590
57838
|
}));
|
|
57591
57839
|
try {
|
|
57592
|
-
const burner = await
|
|
57840
|
+
const burner = await unlink.burner.addressOf(index);
|
|
57593
57841
|
setState((prev2) => ({
|
|
57594
57842
|
...prev2,
|
|
57595
57843
|
burners: [
|
|
@@ -57619,15 +57867,15 @@ function UnlinkProvider({
|
|
|
57619
57867
|
}, []);
|
|
57620
57868
|
const burnerSend = useCallback(
|
|
57621
57869
|
async (index, tx) => {
|
|
57622
|
-
const
|
|
57623
|
-
if (!
|
|
57870
|
+
const unlink = unlinkRef.current;
|
|
57871
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57624
57872
|
setState((prev2) => ({
|
|
57625
57873
|
...prev2,
|
|
57626
57874
|
busy: true,
|
|
57627
57875
|
status: "Sending burner transaction..."
|
|
57628
57876
|
}));
|
|
57629
57877
|
try {
|
|
57630
|
-
const result = await
|
|
57878
|
+
const result = await unlink.burner.send(index, tx);
|
|
57631
57879
|
setState((prev2) => ({
|
|
57632
57880
|
...prev2,
|
|
57633
57881
|
busy: false,
|
|
@@ -57649,15 +57897,15 @@ function UnlinkProvider({
|
|
|
57649
57897
|
);
|
|
57650
57898
|
const burnerFund = useCallback(
|
|
57651
57899
|
async (index, params) => {
|
|
57652
|
-
const
|
|
57653
|
-
if (!
|
|
57900
|
+
const unlink = unlinkRef.current;
|
|
57901
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57654
57902
|
setState((prev2) => ({
|
|
57655
57903
|
...prev2,
|
|
57656
57904
|
busy: true,
|
|
57657
57905
|
status: "Funding burner..."
|
|
57658
57906
|
}));
|
|
57659
57907
|
try {
|
|
57660
|
-
const result = await
|
|
57908
|
+
const result = await unlink.burner.fund(index, params);
|
|
57661
57909
|
setState((prev2) => ({
|
|
57662
57910
|
...prev2,
|
|
57663
57911
|
busy: false,
|
|
@@ -57679,15 +57927,15 @@ function UnlinkProvider({
|
|
|
57679
57927
|
);
|
|
57680
57928
|
const burnerSweepToPool = useCallback(
|
|
57681
57929
|
async (index, params) => {
|
|
57682
|
-
const
|
|
57683
|
-
if (!
|
|
57930
|
+
const unlink = unlinkRef.current;
|
|
57931
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57684
57932
|
setState((prev2) => ({
|
|
57685
57933
|
...prev2,
|
|
57686
57934
|
busy: true,
|
|
57687
57935
|
status: "Sweeping burner to pool..."
|
|
57688
57936
|
}));
|
|
57689
57937
|
try {
|
|
57690
|
-
const result = await
|
|
57938
|
+
const result = await unlink.burner.sweepToPool(index, params);
|
|
57691
57939
|
setState((prev2) => ({
|
|
57692
57940
|
...prev2,
|
|
57693
57941
|
busy: false,
|
|
@@ -57709,24 +57957,24 @@ function UnlinkProvider({
|
|
|
57709
57957
|
);
|
|
57710
57958
|
const burnerGetTokenBalance = useCallback(
|
|
57711
57959
|
async (address, token) => {
|
|
57712
|
-
const
|
|
57713
|
-
if (!
|
|
57714
|
-
return
|
|
57960
|
+
const unlink = unlinkRef.current;
|
|
57961
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57962
|
+
return unlink.burner.getTokenBalance(address, token);
|
|
57715
57963
|
},
|
|
57716
57964
|
[]
|
|
57717
57965
|
);
|
|
57718
57966
|
const burnerGetBalance = useCallback(
|
|
57719
57967
|
async (address) => {
|
|
57720
|
-
const
|
|
57721
|
-
if (!
|
|
57722
|
-
return
|
|
57968
|
+
const unlink = unlinkRef.current;
|
|
57969
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57970
|
+
return unlink.burner.getBalance(address);
|
|
57723
57971
|
},
|
|
57724
57972
|
[]
|
|
57725
57973
|
);
|
|
57726
57974
|
const refresh = useCallback(async () => {
|
|
57727
|
-
const
|
|
57728
|
-
if (!
|
|
57729
|
-
const activeAccount = await
|
|
57975
|
+
const unlink = unlinkRef.current;
|
|
57976
|
+
if (!unlink) return;
|
|
57977
|
+
const activeAccount = await unlink.accounts.getActive();
|
|
57730
57978
|
if (!activeAccount) return;
|
|
57731
57979
|
setState((prev2) => ({
|
|
57732
57980
|
...prev2,
|
|
@@ -57734,8 +57982,8 @@ function UnlinkProvider({
|
|
|
57734
57982
|
status: "Syncing..."
|
|
57735
57983
|
}));
|
|
57736
57984
|
try {
|
|
57737
|
-
await
|
|
57738
|
-
await refreshState(
|
|
57985
|
+
await unlink.sync();
|
|
57986
|
+
await refreshState(unlink);
|
|
57739
57987
|
setState((prev2) => ({
|
|
57740
57988
|
...prev2,
|
|
57741
57989
|
busy: false,
|
|
@@ -57752,9 +58000,9 @@ function UnlinkProvider({
|
|
|
57752
58000
|
}
|
|
57753
58001
|
}, [refreshState]);
|
|
57754
58002
|
const forceResync = useCallback(async () => {
|
|
57755
|
-
const
|
|
57756
|
-
if (!
|
|
57757
|
-
const activeAccount = await
|
|
58003
|
+
const unlink = unlinkRef.current;
|
|
58004
|
+
if (!unlink) return;
|
|
58005
|
+
const activeAccount = await unlink.accounts.getActive();
|
|
57758
58006
|
if (!activeAccount) return;
|
|
57759
58007
|
setState((prev2) => ({
|
|
57760
58008
|
...prev2,
|
|
@@ -57762,8 +58010,8 @@ function UnlinkProvider({
|
|
|
57762
58010
|
status: "Resyncing..."
|
|
57763
58011
|
}));
|
|
57764
58012
|
try {
|
|
57765
|
-
await
|
|
57766
|
-
await refreshState(
|
|
58013
|
+
await unlink.sync({ forceFullResync: true });
|
|
58014
|
+
await refreshState(unlink);
|
|
57767
58015
|
setState((prev2) => ({
|
|
57768
58016
|
...prev2,
|
|
57769
58017
|
busy: false,
|
|
@@ -57783,9 +58031,9 @@ function UnlinkProvider({
|
|
|
57783
58031
|
setState((prev2) => ({ ...prev2, error: null }));
|
|
57784
58032
|
}, []);
|
|
57785
58033
|
const getTxStatus = useCallback(async (txId) => {
|
|
57786
|
-
const
|
|
57787
|
-
if (!
|
|
57788
|
-
const response = await
|
|
58034
|
+
const unlink = unlinkRef.current;
|
|
58035
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
58036
|
+
const response = await unlink.getTxStatus(txId);
|
|
57789
58037
|
return {
|
|
57790
58038
|
txId: response.id,
|
|
57791
58039
|
state: response.state,
|
|
@@ -57796,8 +58044,8 @@ function UnlinkProvider({
|
|
|
57796
58044
|
}, []);
|
|
57797
58045
|
const waitForConfirmation = useCallback(
|
|
57798
58046
|
async (txId, options) => {
|
|
57799
|
-
const
|
|
57800
|
-
if (!
|
|
58047
|
+
const unlink = unlinkRef.current;
|
|
58048
|
+
if (!unlink) throw new Error("SDK not initialized");
|
|
57801
58049
|
const timeout2 = options?.timeout ?? DEFAULT_CONFIRMATION_TIMEOUT_MS;
|
|
57802
58050
|
const startTime3 = Date.now();
|
|
57803
58051
|
let delay2 = CONFIRMATION_POLL_INTERVAL_MS;
|
|
@@ -57846,16 +58094,16 @@ function UnlinkProvider({
|
|
|
57846
58094
|
// Account actions
|
|
57847
58095
|
createAccount,
|
|
57848
58096
|
switchAccount,
|
|
57849
|
-
//
|
|
58097
|
+
// Send actions
|
|
57850
58098
|
send,
|
|
57851
|
-
|
|
57852
|
-
|
|
58099
|
+
planSend,
|
|
58100
|
+
executeSend,
|
|
57853
58101
|
// Deposit actions
|
|
57854
|
-
|
|
58102
|
+
deposit: deposit2,
|
|
57855
58103
|
// Withdraw actions
|
|
57856
|
-
|
|
57857
|
-
//
|
|
57858
|
-
|
|
58104
|
+
withdraw,
|
|
58105
|
+
// Interact actions
|
|
58106
|
+
interact,
|
|
57859
58107
|
planWithdraw,
|
|
57860
58108
|
executeWithdraw,
|
|
57861
58109
|
// Burner actions
|
|
@@ -57884,11 +58132,11 @@ function UnlinkProvider({
|
|
|
57884
58132
|
createAccount,
|
|
57885
58133
|
switchAccount,
|
|
57886
58134
|
send,
|
|
57887
|
-
|
|
57888
|
-
|
|
57889
|
-
|
|
57890
|
-
|
|
57891
|
-
|
|
58135
|
+
planSend,
|
|
58136
|
+
executeSend,
|
|
58137
|
+
deposit2,
|
|
58138
|
+
withdraw,
|
|
58139
|
+
interact,
|
|
57892
58140
|
planWithdraw,
|
|
57893
58141
|
executeWithdraw,
|
|
57894
58142
|
createBurner,
|
|
@@ -57921,20 +58169,20 @@ function useUnlink() {
|
|
|
57921
58169
|
// src/useUnlinkHistory.ts
|
|
57922
58170
|
import { useCallback as useCallback2, useEffect as useEffect2, useState as useState2 } from "react";
|
|
57923
58171
|
function useUnlinkHistory(options) {
|
|
57924
|
-
const {
|
|
58172
|
+
const { unlink, activeAccount } = useUnlink();
|
|
57925
58173
|
const includeSelfSends = options?.includeSelfSends;
|
|
57926
58174
|
const [history, setHistory] = useState2([]);
|
|
57927
58175
|
const [loading, setLoading] = useState2(true);
|
|
57928
58176
|
const [error, setError] = useState2(null);
|
|
57929
58177
|
const fetchHistory = useCallback2(async () => {
|
|
57930
|
-
if (!
|
|
58178
|
+
if (!unlink || !activeAccount) {
|
|
57931
58179
|
setHistory([]);
|
|
57932
58180
|
setLoading(false);
|
|
57933
58181
|
return;
|
|
57934
58182
|
}
|
|
57935
58183
|
try {
|
|
57936
58184
|
setLoading(true);
|
|
57937
|
-
const entries = await
|
|
58185
|
+
const entries = await unlink.getHistory({
|
|
57938
58186
|
includeSelfSends
|
|
57939
58187
|
});
|
|
57940
58188
|
setHistory(entries);
|
|
@@ -57944,19 +58192,19 @@ function useUnlinkHistory(options) {
|
|
|
57944
58192
|
} finally {
|
|
57945
58193
|
setLoading(false);
|
|
57946
58194
|
}
|
|
57947
|
-
}, [
|
|
58195
|
+
}, [unlink, activeAccount, includeSelfSends]);
|
|
57948
58196
|
useEffect2(() => {
|
|
57949
58197
|
void fetchHistory();
|
|
57950
58198
|
}, [fetchHistory]);
|
|
57951
58199
|
useEffect2(() => {
|
|
57952
|
-
if (!
|
|
57953
|
-
const unsubscribe =
|
|
58200
|
+
if (!unlink) return;
|
|
58201
|
+
const unsubscribe = unlink.on((event) => {
|
|
57954
58202
|
if (event.type === "notes-updated") {
|
|
57955
58203
|
void fetchHistory();
|
|
57956
58204
|
}
|
|
57957
58205
|
});
|
|
57958
58206
|
return unsubscribe;
|
|
57959
|
-
}, [
|
|
58207
|
+
}, [unlink, fetchHistory]);
|
|
57960
58208
|
const refresh = useCallback2(async () => {
|
|
57961
58209
|
await fetchHistory();
|
|
57962
58210
|
}, [fetchHistory]);
|
|
@@ -57989,7 +58237,7 @@ function useUnlinkBalances() {
|
|
|
57989
58237
|
// src/useTxStatus.ts
|
|
57990
58238
|
import { useCallback as useCallback3, useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
|
|
57991
58239
|
function useTxStatus(txId) {
|
|
57992
|
-
const { getTxStatus,
|
|
58240
|
+
const { getTxStatus, unlink } = useUnlink();
|
|
57993
58241
|
const [state, setState] = useState3(null);
|
|
57994
58242
|
const [txHash, setTxHash] = useState3(null);
|
|
57995
58243
|
const [blockNumber, setBlockNumber] = useState3(null);
|
|
@@ -57999,7 +58247,7 @@ function useTxStatus(txId) {
|
|
|
57999
58247
|
currentTxIdRef.current = txId;
|
|
58000
58248
|
const refresh = useCallback3(async () => {
|
|
58001
58249
|
const targetTxId = currentTxIdRef.current;
|
|
58002
|
-
if (!targetTxId || !
|
|
58250
|
+
if (!targetTxId || !unlink) return;
|
|
58003
58251
|
setIsLoading(true);
|
|
58004
58252
|
try {
|
|
58005
58253
|
const status = await getTxStatus(targetTxId);
|
|
@@ -58016,13 +58264,13 @@ function useTxStatus(txId) {
|
|
|
58016
58264
|
setIsLoading(false);
|
|
58017
58265
|
}
|
|
58018
58266
|
}
|
|
58019
|
-
}, [
|
|
58267
|
+
}, [unlink, getTxStatus]);
|
|
58020
58268
|
useEffect3(() => {
|
|
58021
|
-
if (txId &&
|
|
58022
|
-
|
|
58269
|
+
if (txId && unlink) {
|
|
58270
|
+
unlink.trackTx(txId);
|
|
58023
58271
|
void refresh();
|
|
58024
58272
|
return () => {
|
|
58025
|
-
|
|
58273
|
+
unlink.untrackTx(txId);
|
|
58026
58274
|
};
|
|
58027
58275
|
} else {
|
|
58028
58276
|
setState(null);
|
|
@@ -58030,10 +58278,10 @@ function useTxStatus(txId) {
|
|
|
58030
58278
|
setBlockNumber(null);
|
|
58031
58279
|
setError(null);
|
|
58032
58280
|
}
|
|
58033
|
-
}, [txId,
|
|
58281
|
+
}, [txId, unlink, refresh]);
|
|
58034
58282
|
useEffect3(() => {
|
|
58035
|
-
if (!
|
|
58036
|
-
const unsubscribe =
|
|
58283
|
+
if (!unlink || !txId) return;
|
|
58284
|
+
const unsubscribe = unlink.on((event) => {
|
|
58037
58285
|
if (event.type === "tx-status-changed" && event.txId === txId) {
|
|
58038
58286
|
setState(event.state);
|
|
58039
58287
|
setTxHash(event.txHash ?? null);
|
|
@@ -58042,7 +58290,7 @@ function useTxStatus(txId) {
|
|
|
58042
58290
|
}
|
|
58043
58291
|
});
|
|
58044
58292
|
return unsubscribe;
|
|
58045
|
-
}, [
|
|
58293
|
+
}, [unlink, txId]);
|
|
58046
58294
|
return { state, txHash, blockNumber, error, isLoading, refresh };
|
|
58047
58295
|
}
|
|
58048
58296
|
|
|
@@ -58059,7 +58307,7 @@ function useOperationMutation(operation) {
|
|
|
58059
58307
|
const [isError2, setIsError] = useState4(false);
|
|
58060
58308
|
const pendingRef = useRef3(false);
|
|
58061
58309
|
const generationRef = useRef3(0);
|
|
58062
|
-
const
|
|
58310
|
+
const execute = useCallback4(
|
|
58063
58311
|
async (input) => {
|
|
58064
58312
|
if (pendingRef.current) {
|
|
58065
58313
|
throw new Error("Operation already in progress");
|
|
@@ -58102,47 +58350,54 @@ function useOperationMutation(operation) {
|
|
|
58102
58350
|
setIsSuccess(false);
|
|
58103
58351
|
setIsError(false);
|
|
58104
58352
|
}, []);
|
|
58105
|
-
return {
|
|
58353
|
+
return { execute, data, isPending, isSuccess, isError: isError2, error, reset };
|
|
58106
58354
|
}
|
|
58107
58355
|
|
|
58108
58356
|
// src/useDeposit.ts
|
|
58109
58357
|
function useDeposit() {
|
|
58110
|
-
const {
|
|
58358
|
+
const { deposit: deposit2 } = useUnlink();
|
|
58111
58359
|
const op = useCallback5(
|
|
58112
|
-
(params) =>
|
|
58113
|
-
[
|
|
58360
|
+
(params) => deposit2(params),
|
|
58361
|
+
[deposit2]
|
|
58114
58362
|
);
|
|
58115
|
-
|
|
58363
|
+
const { execute, ...rest } = useOperationMutation(op);
|
|
58364
|
+
return { deposit: execute, ...rest };
|
|
58116
58365
|
}
|
|
58117
58366
|
|
|
58118
|
-
// src/
|
|
58367
|
+
// src/useSend.ts
|
|
58119
58368
|
import { useCallback as useCallback6 } from "react";
|
|
58120
|
-
function
|
|
58369
|
+
function useSend(overrides) {
|
|
58121
58370
|
const { send } = useUnlink();
|
|
58122
|
-
const op = useCallback6(
|
|
58123
|
-
|
|
58371
|
+
const op = useCallback6(
|
|
58372
|
+
(params) => send(params, overrides),
|
|
58373
|
+
[send, overrides]
|
|
58374
|
+
);
|
|
58375
|
+
const { execute, ...rest } = useOperationMutation(op);
|
|
58376
|
+
return { send: execute, ...rest };
|
|
58124
58377
|
}
|
|
58125
58378
|
|
|
58126
58379
|
// src/useWithdraw.ts
|
|
58127
58380
|
import { useCallback as useCallback7 } from "react";
|
|
58128
|
-
function useWithdraw() {
|
|
58129
|
-
const {
|
|
58381
|
+
function useWithdraw(overrides) {
|
|
58382
|
+
const { withdraw } = useUnlink();
|
|
58130
58383
|
const op = useCallback7(
|
|
58131
|
-
(params) =>
|
|
58132
|
-
[
|
|
58384
|
+
(params) => withdraw(params, overrides),
|
|
58385
|
+
[withdraw, overrides]
|
|
58133
58386
|
);
|
|
58134
|
-
|
|
58387
|
+
const { execute, ...rest } = useOperationMutation(op);
|
|
58388
|
+
return { withdraw: execute, ...rest };
|
|
58135
58389
|
}
|
|
58136
58390
|
|
|
58137
|
-
// src/
|
|
58391
|
+
// src/useInteract.ts
|
|
58138
58392
|
import { useCallback as useCallback8 } from "react";
|
|
58139
|
-
function
|
|
58140
|
-
const {
|
|
58393
|
+
function useInteract() {
|
|
58394
|
+
const { interact } = useUnlink();
|
|
58141
58395
|
const op = useCallback8(
|
|
58142
|
-
(params) =>
|
|
58143
|
-
[
|
|
58396
|
+
(params) => interact(params),
|
|
58397
|
+
[interact]
|
|
58144
58398
|
);
|
|
58145
|
-
|
|
58399
|
+
const { execute, ...rest } = useOperationMutation(op);
|
|
58400
|
+
return { interact: execute, ...rest };
|
|
58146
58401
|
}
|
|
58147
58402
|
|
|
58148
58403
|
// src/useBurner.ts
|
|
@@ -58191,7 +58446,10 @@ export {
|
|
|
58191
58446
|
TimeoutError2 as TimeoutError,
|
|
58192
58447
|
TransactionFailedError,
|
|
58193
58448
|
UnlinkProvider,
|
|
58449
|
+
approve,
|
|
58450
|
+
buildApproveCall,
|
|
58194
58451
|
computeBalances,
|
|
58452
|
+
contract,
|
|
58195
58453
|
decodeAddress,
|
|
58196
58454
|
encodeAddress,
|
|
58197
58455
|
formatAmount,
|
|
@@ -58200,11 +58458,12 @@ export {
|
|
|
58200
58458
|
parseZkAddress,
|
|
58201
58459
|
randomHex,
|
|
58202
58460
|
shortenHex,
|
|
58203
|
-
|
|
58461
|
+
toCall,
|
|
58204
58462
|
useBurner,
|
|
58205
58463
|
useDeposit,
|
|
58464
|
+
useInteract,
|
|
58206
58465
|
useOperationMutation,
|
|
58207
|
-
|
|
58466
|
+
useSend,
|
|
58208
58467
|
useTxStatus,
|
|
58209
58468
|
useUnlink,
|
|
58210
58469
|
useUnlinkBalance,
|