@unlink-xyz/core 0.1.6 → 0.1.8
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/browser/index.js +257 -154
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/wallet/index.js +209 -153
- package/dist/browser/wallet/index.js.map +1 -1
- package/dist/config.d.ts +6 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +180 -77
- package/dist/index.js.map +1 -1
- package/dist/transactions/adapter.d.ts +34 -1
- package/dist/transactions/adapter.d.ts.map +1 -1
- package/dist/transactions/index.d.ts +1 -1
- package/dist/transactions/index.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/wallet/adapter.d.ts +2 -2
- package/dist/wallet/adapter.d.ts.map +1 -1
- package/dist/wallet/burner/service.d.ts +1 -0
- package/dist/wallet/burner/service.d.ts.map +1 -1
- package/dist/wallet/burner/types.d.ts +2 -2
- package/dist/wallet/burner/types.d.ts.map +1 -1
- package/dist/wallet/index.d.ts +2 -2
- package/dist/wallet/index.d.ts.map +1 -1
- package/dist/wallet/index.js +132 -76
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/sdk.d.ts +2 -2
- package/dist/wallet/types.d.ts +49 -38
- package/dist/wallet/types.d.ts.map +1 -1
- package/dist/wallet/{unlink-wallet.d.ts → unlink.d.ts} +38 -31
- package/dist/wallet/unlink.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/wallet/unlink-wallet.d.ts.map +0 -1
package/dist/wallet/adapter.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { createBroadcasterClient } from "../clients/broadcaster.js";
|
|
|
3
3
|
import { transact } from "../transactions/transact.js";
|
|
4
4
|
import type { ServiceOptions, TransactStateStore } from "../transactions/types/index.js";
|
|
5
5
|
import { planWithdrawals } from "../transactions/withdrawal-planner.js";
|
|
6
|
-
import type {
|
|
6
|
+
import type { WalletInteractAPI } from "./types.js";
|
|
7
7
|
type BroadcasterClient = Pick<ReturnType<typeof createBroadcasterClient>, "submitRelay">;
|
|
8
8
|
export type AdapterServiceDeps = {
|
|
9
9
|
stateStore: TransactStateStore;
|
|
@@ -16,6 +16,6 @@ export type AdapterServiceDeps = {
|
|
|
16
16
|
randomBigintFn?: () => bigint;
|
|
17
17
|
nowFn?: () => number;
|
|
18
18
|
};
|
|
19
|
-
export declare function createAdapterService(deps: AdapterServiceDeps):
|
|
19
|
+
export declare function createAdapterService(deps: AdapterServiceDeps): WalletInteractAPI;
|
|
20
20
|
export {};
|
|
21
21
|
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../wallet/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE1E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../wallet/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE1E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAMzE,OAAO,EAEL,QAAQ,EAGT,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EACV,cAAc,EAEd,kBAAkB,EACnB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAOxE,OAAO,KAAK,EAKV,iBAAiB,EAElB,MAAM,YAAY,CAAC;AAKpB,KAAK,iBAAiB,GAAG,IAAI,CAC3B,UAAU,CAAC,OAAO,uBAAuB,CAAC,EAC1C,aAAa,CACd,CAAC;AAOF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,EAAE,kBAAkB,CAAC;IAC/B,MAAM,EAAE,cAAc,CAAC;IACvB,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,oBAAoB,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7C,aAAa,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,MAAM,CAAC;IAChD,iBAAiB,CAAC,EAAE,OAAO,eAAe,CAAC;IAC3C,UAAU,CAAC,EAAE,OAAO,QAAQ,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,MAAM,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC;CACtB,CAAC;AA2EF,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,kBAAkB,GACvB,iBAAiB,CAkNnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../wallet/burner/service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../wallet/burner/service.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAEV,SAAS,EAIV,MAAM,YAAY,CAAC;AAKpB,MAAM,MAAM,iBAAiB,GAAG;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IACzC,2DAA2D;IAC3D,iBAAiB,EAAE,CAAC,MAAM,EAAE;QAC1B,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,KAAK,CAAC;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KAC1E,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IAC9B,kEAAkE;IAClE,cAAc,EAAE,CAAC,MAAM,EAAE;QACvB,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,KAAK,CAAC;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KACpD,KAAK,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChE,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC;AAStC,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,aAAa,CAiK1E"}
|
|
@@ -21,7 +21,7 @@ export type BurnerSweepToPoolParams = {
|
|
|
21
21
|
chainId: number;
|
|
22
22
|
poolAddress: string;
|
|
23
23
|
token: string;
|
|
24
|
-
/** Amount to sweep; omit to sweep full
|
|
24
|
+
/** Amount to sweep; omit to sweep full balance (ERC-20 only). Required for native ETH — sweep ETH last to know how much to reserve for gas. */
|
|
25
25
|
amount?: bigint;
|
|
26
26
|
};
|
|
27
27
|
export type BurnerAPI = {
|
|
@@ -35,7 +35,7 @@ export type BurnerAPI = {
|
|
|
35
35
|
exportKey(index: number): Promise<string>;
|
|
36
36
|
/** Withdraw from shielded pool to fund this burner */
|
|
37
37
|
fund(index: number, params: BurnerFundParams): Promise<WithdrawResult>;
|
|
38
|
-
/**
|
|
38
|
+
/** Sweep tokens from burner back into shielded pool (approve + deposit for ERC-20, direct deposit for native ETH) */
|
|
39
39
|
sweepToPool(index: number, params: BurnerSweepToPoolParams): Promise<{
|
|
40
40
|
txHash: string;
|
|
41
41
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../wallet/burner/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,E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M,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,+IAA+I;IAC/I,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,8CAA8C;IAC9C,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACjD,8CAA8C;IAC9C,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,gBAAgB,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACvE,qEAAqE;IACrE,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1C,sDAAsD;IACtD,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IACvE,qHAAqH;IACrH,WAAW,CACT,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/B,8CAA8C;IAC9C,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACjE,4CAA4C;IAC5C,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC9C,CAAC"}
|
package/dist/wallet/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { UnlinkWallet } from "./unlink
|
|
1
|
+
export { Unlink, UnlinkWallet } from "./unlink.js";
|
|
2
2
|
export { createBrowserWalletSDK, createWalletSDK, type BrowserWalletOptions, type BrowserWalletResult, } from "./sdk.js";
|
|
3
|
-
export type { AccountInfo, BurnerAccount, BurnerAPI, BurnerFundParams, BurnerSendParams, BurnerSweepToPoolParams, CoreSDK, ProverConfig,
|
|
3
|
+
export type { AccountInfo, BurnerAccount, BurnerAPI, BurnerFundParams, BurnerSendParams, BurnerSweepToPoolParams, CoreSDK, ProverConfig, InteractResult, InputTokenSpec, ReshieldInput, SpendInput, ReceiveInput, SimpleDepositParams, SimpleSendParams, SimpleWithdrawParams, SimpleInteractParams, SimpleBurnerFundParams, SimpleBurnerSweepToPoolParams, SimpleTransactParams, SendParams, SendPlanResult, SendResult, TxStatusChangedEvent, UnlinkCreateConfig, UnlinkEvent, UnlinkWalletConfig, WalletAccountAPI, WalletDepositAPI, WalletDepositParams, WalletDepositResult, WalletInteractAPI, WalletInteractParams, WalletTxAPI, SeedAPI, WalletBalanceAPI, WalletDeps, WalletSDK, WalletSDKEvent, WalletSendAPI, WalletWithdrawAPI, SignerOverride, WithdrawParams, WithdrawPlanResult, WithdrawResult, } from "./types.js";
|
|
4
4
|
export type { Account } from "../account/account.js";
|
|
5
5
|
export type { CommitmentRecord } from "../clients/indexer.js";
|
|
6
6
|
export type { DepositRelayResult } from "../transactions/types/index.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,GACzB,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,WAAW,EACX,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACvB,OAAO,EACP,YAAY,EACZ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,oBAAoB,CAAC;AAGlE,OAAO,EACL,YAAY,EACZ,SAAS,EACT,mBAAmB,EACnB,UAAU,EACV,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/wallet/index.js
CHANGED
|
@@ -1875,6 +1875,11 @@ function parseChainConfig(chain, value) {
|
|
|
1875
1875
|
"artifactVersion",
|
|
1876
1876
|
raw.artifactVersion
|
|
1877
1877
|
).replace(/^\/+|\/+$/g, "");
|
|
1878
|
+
const adapterAddress = parseOptionalString(
|
|
1879
|
+
chain,
|
|
1880
|
+
"adapterAddress",
|
|
1881
|
+
raw.adapterAddress
|
|
1882
|
+
);
|
|
1878
1883
|
const frostUrl = parseOptionalString(
|
|
1879
1884
|
chain,
|
|
1880
1885
|
"frostUrl",
|
|
@@ -1885,13 +1890,33 @@ function parseChainConfig(chain, value) {
|
|
|
1885
1890
|
"artifactBaseUrl",
|
|
1886
1891
|
raw.artifactBaseUrl
|
|
1887
1892
|
)?.replace(/\/+$/, "");
|
|
1893
|
+
let tokenAddresses;
|
|
1894
|
+
if (raw.tokenAddresses !== void 0) {
|
|
1895
|
+
if (raw.tokenAddresses === null || typeof raw.tokenAddresses !== "object" || Array.isArray(raw.tokenAddresses)) {
|
|
1896
|
+
throw new InitializationError(
|
|
1897
|
+
`Invalid SDK config for ${chain}: tokenAddresses must be an object`
|
|
1898
|
+
);
|
|
1899
|
+
}
|
|
1900
|
+
tokenAddresses = {};
|
|
1901
|
+
for (const [name, addr] of Object.entries(
|
|
1902
|
+
raw.tokenAddresses
|
|
1903
|
+
)) {
|
|
1904
|
+
tokenAddresses[name] = parseRequiredString(
|
|
1905
|
+
chain,
|
|
1906
|
+
`tokenAddresses.${name}`,
|
|
1907
|
+
addr
|
|
1908
|
+
);
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1888
1911
|
return {
|
|
1889
1912
|
chainId,
|
|
1890
1913
|
gatewayUrl,
|
|
1891
1914
|
...frostUrl !== void 0 ? { frostUrl } : {},
|
|
1892
1915
|
poolAddress,
|
|
1916
|
+
...adapterAddress !== void 0 ? { adapterAddress } : {},
|
|
1893
1917
|
artifactVersion,
|
|
1894
|
-
...artifactBaseUrl !== void 0 ? { artifactBaseUrl } : { artifactBaseUrl: DEFAULT_ARTIFACT_BASE_URL }
|
|
1918
|
+
...artifactBaseUrl !== void 0 ? { artifactBaseUrl } : { artifactBaseUrl: DEFAULT_ARTIFACT_BASE_URL },
|
|
1919
|
+
...tokenAddresses !== void 0 ? { tokenAddresses } : {}
|
|
1895
1920
|
};
|
|
1896
1921
|
}
|
|
1897
1922
|
async function fetchChainConfig(chain) {
|
|
@@ -8350,26 +8375,34 @@ function normalizeCall2(call, index) {
|
|
|
8350
8375
|
value: call.value
|
|
8351
8376
|
};
|
|
8352
8377
|
}
|
|
8353
|
-
function
|
|
8354
|
-
const token = ensureAddress(`
|
|
8378
|
+
function normalizeSpendInput(input, index) {
|
|
8379
|
+
const token = ensureAddress(`spend[${index}].token`, input.token);
|
|
8380
|
+
if (token.toLowerCase() === ETH_TOKEN.toLowerCase()) {
|
|
8381
|
+
throw new AdapterError(
|
|
8382
|
+
`spend[${index}].token: native ETH is not supported in adapter execution`
|
|
8383
|
+
);
|
|
8384
|
+
}
|
|
8355
8385
|
if (input.amount <= 0n) {
|
|
8356
|
-
throw new AdapterError(`
|
|
8386
|
+
throw new AdapterError(`spend[${index}].amount must be greater than zero`);
|
|
8357
8387
|
}
|
|
8358
8388
|
return {
|
|
8359
8389
|
token,
|
|
8360
8390
|
amount: input.amount
|
|
8361
8391
|
};
|
|
8362
8392
|
}
|
|
8363
|
-
function
|
|
8364
|
-
const token = ensureAddress(`
|
|
8365
|
-
if (
|
|
8393
|
+
function normalizeReceiveInput(receive, index) {
|
|
8394
|
+
const token = ensureAddress(`receive[${index}].token`, receive.token);
|
|
8395
|
+
if (token.toLowerCase() === ETH_TOKEN.toLowerCase()) {
|
|
8366
8396
|
throw new AdapterError(
|
|
8367
|
-
`
|
|
8397
|
+
`receive[${index}].token: native ETH is not supported in adapter execution`
|
|
8368
8398
|
);
|
|
8369
8399
|
}
|
|
8400
|
+
if (receive.minAmount < 0n) {
|
|
8401
|
+
throw new AdapterError(`receive[${index}].minAmount must be non-negative`);
|
|
8402
|
+
}
|
|
8370
8403
|
return {
|
|
8371
8404
|
token,
|
|
8372
|
-
minAmount:
|
|
8405
|
+
minAmount: receive.minAmount
|
|
8373
8406
|
};
|
|
8374
8407
|
}
|
|
8375
8408
|
function randomFieldElement(randomBigintFn) {
|
|
@@ -8389,41 +8422,41 @@ function createAdapterService(deps) {
|
|
|
8389
8422
|
"adapterAddress",
|
|
8390
8423
|
params.adapterAddress
|
|
8391
8424
|
);
|
|
8392
|
-
if (!params.
|
|
8393
|
-
throw new AdapterError("at least one
|
|
8425
|
+
if (!params.spend.length) {
|
|
8426
|
+
throw new AdapterError("at least one spend token is required");
|
|
8394
8427
|
}
|
|
8395
8428
|
if (!params.calls.length) {
|
|
8396
8429
|
throw new AdapterError("at least one adapter call is required");
|
|
8397
8430
|
}
|
|
8398
|
-
if (!params.
|
|
8399
|
-
throw new AdapterError("at least one
|
|
8431
|
+
if (!params.receive.length) {
|
|
8432
|
+
throw new AdapterError("at least one receive output is required");
|
|
8400
8433
|
}
|
|
8401
|
-
const
|
|
8402
|
-
(input, i) =>
|
|
8434
|
+
const spendInputs = params.spend.map(
|
|
8435
|
+
(input, i) => normalizeSpendInput(input, i)
|
|
8403
8436
|
);
|
|
8404
8437
|
const seenTokens = /* @__PURE__ */ new Set();
|
|
8405
|
-
for (const input of
|
|
8438
|
+
for (const input of spendInputs) {
|
|
8406
8439
|
const lower = input.token.toLowerCase();
|
|
8407
8440
|
if (seenTokens.has(lower)) {
|
|
8408
8441
|
throw new AdapterError(
|
|
8409
|
-
`duplicate
|
|
8442
|
+
`duplicate spend token ${input.token}; combine amounts per token instead`
|
|
8410
8443
|
);
|
|
8411
8444
|
}
|
|
8412
8445
|
seenTokens.add(lower);
|
|
8413
8446
|
}
|
|
8414
8447
|
const calls = params.calls.map((call, i) => normalizeCall2(call, i));
|
|
8415
|
-
const
|
|
8416
|
-
(
|
|
8448
|
+
const receiveSpecs = params.receive.map(
|
|
8449
|
+
(receive, i) => normalizeReceiveInput(receive, i)
|
|
8417
8450
|
);
|
|
8418
|
-
const
|
|
8419
|
-
for (const r2 of
|
|
8451
|
+
const seenReceiveTokens = /* @__PURE__ */ new Set();
|
|
8452
|
+
for (const r2 of receiveSpecs) {
|
|
8420
8453
|
const lower = r2.token.toLowerCase();
|
|
8421
|
-
if (
|
|
8454
|
+
if (seenReceiveTokens.has(lower)) {
|
|
8422
8455
|
throw new AdapterError(
|
|
8423
|
-
`duplicate
|
|
8456
|
+
`duplicate receive token ${r2.token}; each receive must target a unique token`
|
|
8424
8457
|
);
|
|
8425
8458
|
}
|
|
8426
|
-
|
|
8459
|
+
seenReceiveTokens.add(lower);
|
|
8427
8460
|
}
|
|
8428
8461
|
const account = overrides?.account ?? await deps.requireActiveAccount();
|
|
8429
8462
|
const signer = overrides?.signer ?? deps.requireSigner(account);
|
|
@@ -8433,19 +8466,19 @@ function createAdapterService(deps) {
|
|
|
8433
8466
|
throw new AdapterError("deadline must be in the future");
|
|
8434
8467
|
}
|
|
8435
8468
|
const executionCalls = calls;
|
|
8436
|
-
const reshields =
|
|
8437
|
-
(
|
|
8469
|
+
const reshields = receiveSpecs.map(
|
|
8470
|
+
(receive) => {
|
|
8438
8471
|
const random = randomFieldElement(randomBigintImpl);
|
|
8439
8472
|
const npk = poseidon([account.masterPublicKey, random]);
|
|
8440
8473
|
return {
|
|
8441
8474
|
npk,
|
|
8442
8475
|
random,
|
|
8443
|
-
token:
|
|
8444
|
-
minAmount:
|
|
8476
|
+
token: receive.token,
|
|
8477
|
+
minAmount: receive.minAmount
|
|
8445
8478
|
};
|
|
8446
8479
|
}
|
|
8447
8480
|
);
|
|
8448
|
-
const inputTokens =
|
|
8481
|
+
const inputTokens = spendInputs.map((input) => input.token);
|
|
8449
8482
|
const nonce = randomFieldElement(randomBigintImpl);
|
|
8450
8483
|
const adapterDataHash = computeAdapterDataHash({
|
|
8451
8484
|
calls: executionCalls,
|
|
@@ -8462,7 +8495,7 @@ function createAdapterService(deps) {
|
|
|
8462
8495
|
});
|
|
8463
8496
|
const withdrawalPlans = planWithdrawalsImpl(
|
|
8464
8497
|
notes,
|
|
8465
|
-
|
|
8498
|
+
spendInputs.map((input) => ({
|
|
8466
8499
|
token: input.token,
|
|
8467
8500
|
amount: input.amount,
|
|
8468
8501
|
recipient: adapterAddress
|
|
@@ -8545,7 +8578,7 @@ function createAdapterService(deps) {
|
|
|
8545
8578
|
adapterCalldata,
|
|
8546
8579
|
historyPreview: {
|
|
8547
8580
|
kind: "Withdraw",
|
|
8548
|
-
amounts:
|
|
8581
|
+
amounts: spendInputs.map((input) => ({
|
|
8549
8582
|
token: input.token,
|
|
8550
8583
|
delta: (-input.amount).toString()
|
|
8551
8584
|
}))
|
|
@@ -8572,6 +8605,9 @@ import {
|
|
|
8572
8605
|
} from "ethers";
|
|
8573
8606
|
var BIP44_ETH_PREFIX = "m/44'/60'/0'/0";
|
|
8574
8607
|
var ERC20_BALANCE_OF = "function balanceOf(address) view returns (uint256)";
|
|
8608
|
+
function isNativeToken(token) {
|
|
8609
|
+
return token.toLowerCase() === ETH_TOKEN.toLowerCase();
|
|
8610
|
+
}
|
|
8575
8611
|
function createBurnerService(deps) {
|
|
8576
8612
|
const { chainRpcUrl, getMasterSeed, withdrawToAddress, requestDeposit } = deps;
|
|
8577
8613
|
const provider = new JsonRpcProvider(chainRpcUrl);
|
|
@@ -8619,8 +8655,8 @@ function createBurnerService(deps) {
|
|
|
8619
8655
|
}
|
|
8620
8656
|
async function getTokenBalance(address, token) {
|
|
8621
8657
|
const iface = new Interface4([ERC20_BALANCE_OF]);
|
|
8622
|
-
const
|
|
8623
|
-
const bal = await
|
|
8658
|
+
const contract2 = new Contract(token, iface, provider);
|
|
8659
|
+
const bal = await contract2.getFunction("balanceOf")(address);
|
|
8624
8660
|
return BigInt(bal ?? 0);
|
|
8625
8661
|
}
|
|
8626
8662
|
async function getBalance(address) {
|
|
@@ -8639,6 +8675,12 @@ function createBurnerService(deps) {
|
|
|
8639
8675
|
}
|
|
8640
8676
|
async function sweepToPool(index, params) {
|
|
8641
8677
|
const { address } = await addressOf(index);
|
|
8678
|
+
const native = isNativeToken(params.token);
|
|
8679
|
+
if (native && params.amount == null) {
|
|
8680
|
+
throw new Error(
|
|
8681
|
+
"amount is required for native ETH sweeps (needed to reserve gas)"
|
|
8682
|
+
);
|
|
8683
|
+
}
|
|
8642
8684
|
const amount = params.amount ?? await getTokenBalance(address, params.token);
|
|
8643
8685
|
if (amount === 0n) {
|
|
8644
8686
|
throw new Error("No token balance to sweep");
|
|
@@ -8649,17 +8691,20 @@ function createBurnerService(deps) {
|
|
|
8649
8691
|
depositor: address,
|
|
8650
8692
|
deposits: [{ token: params.token, amount }]
|
|
8651
8693
|
});
|
|
8652
|
-
|
|
8653
|
-
|
|
8654
|
-
|
|
8655
|
-
|
|
8656
|
-
|
|
8657
|
-
|
|
8658
|
-
|
|
8659
|
-
|
|
8694
|
+
if (!native) {
|
|
8695
|
+
const erc20Iface = new Interface4([
|
|
8696
|
+
"function approve(address spender, uint256 amount)"
|
|
8697
|
+
]);
|
|
8698
|
+
const approveData = erc20Iface.encodeFunctionData("approve", [
|
|
8699
|
+
params.poolAddress,
|
|
8700
|
+
amount
|
|
8701
|
+
]);
|
|
8702
|
+
await send(index, { to: params.token, data: approveData });
|
|
8703
|
+
}
|
|
8660
8704
|
const { txHash } = await send(index, {
|
|
8661
8705
|
to: depositResult.to,
|
|
8662
|
-
data: depositResult.calldata
|
|
8706
|
+
data: depositResult.calldata,
|
|
8707
|
+
value: depositResult.value
|
|
8663
8708
|
});
|
|
8664
8709
|
return { txHash };
|
|
8665
8710
|
}
|
|
@@ -9369,21 +9414,27 @@ async function createBrowserWalletSDK(options) {
|
|
|
9369
9414
|
};
|
|
9370
9415
|
}
|
|
9371
9416
|
|
|
9372
|
-
// wallet/unlink
|
|
9373
|
-
var
|
|
9417
|
+
// wallet/unlink.ts
|
|
9418
|
+
var Unlink = class _Unlink {
|
|
9374
9419
|
/** @internal */
|
|
9375
9420
|
sdk;
|
|
9376
9421
|
/** Chain ID this wallet operates on. */
|
|
9377
9422
|
chainId;
|
|
9378
9423
|
/** Pool contract address this wallet transacts with. */
|
|
9379
9424
|
poolAddress;
|
|
9380
|
-
|
|
9425
|
+
/** Adapter contract address for DeFi operations. */
|
|
9426
|
+
adapterAddress;
|
|
9427
|
+
constructor(sdk, chainId, poolAddress, adapterAddress) {
|
|
9381
9428
|
this.sdk = sdk;
|
|
9382
9429
|
this.chainId = chainId;
|
|
9383
9430
|
this.poolAddress = poolAddress;
|
|
9431
|
+
this.adapterAddress = adapterAddress;
|
|
9432
|
+
this.adapter = {
|
|
9433
|
+
address: adapterAddress
|
|
9434
|
+
};
|
|
9384
9435
|
}
|
|
9385
9436
|
/**
|
|
9386
|
-
* Create a new
|
|
9437
|
+
* Create a new Unlink instance.
|
|
9387
9438
|
*
|
|
9388
9439
|
* Handles all initialization internally:
|
|
9389
9440
|
* - Resolves chain config (if using `chain` instead of explicit URLs)
|
|
@@ -9395,12 +9446,14 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
9395
9446
|
let chainId;
|
|
9396
9447
|
let gatewayUrl;
|
|
9397
9448
|
let poolAddress;
|
|
9449
|
+
let adapterAddress;
|
|
9398
9450
|
let proverConfig = config.prover;
|
|
9399
9451
|
if ("chain" in config) {
|
|
9400
9452
|
const chainConfig = await fetchChainConfig(config.chain);
|
|
9401
9453
|
chainId = chainConfig.chainId;
|
|
9402
9454
|
gatewayUrl = chainConfig.gatewayUrl;
|
|
9403
9455
|
poolAddress = config.poolAddress ?? chainConfig.poolAddress;
|
|
9456
|
+
adapterAddress = config.adapterAddress ?? chainConfig.adapterAddress;
|
|
9404
9457
|
proverConfig = {
|
|
9405
9458
|
artifactSource: {
|
|
9406
9459
|
baseUrl: config.prover?.artifactSource?.baseUrl ?? chainConfig.artifactBaseUrl,
|
|
@@ -9412,6 +9465,7 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
9412
9465
|
chainId = config.chainId;
|
|
9413
9466
|
gatewayUrl = config.gatewayUrl;
|
|
9414
9467
|
poolAddress = config.poolAddress;
|
|
9468
|
+
adapterAddress = config.adapterAddress;
|
|
9415
9469
|
if (typeof window !== "undefined" && !config.prover?.artifactSource?.version) {
|
|
9416
9470
|
throw new InitializationError(
|
|
9417
9471
|
"prover.artifactSource.version is required in browser when using explicit gatewayUrl mode. Use chain mode or provide a pinned artifact version."
|
|
@@ -9432,7 +9486,7 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
9432
9486
|
autoSync: config.autoSync
|
|
9433
9487
|
}
|
|
9434
9488
|
);
|
|
9435
|
-
return new
|
|
9489
|
+
return new _Unlink(sdk, chainId, poolAddress, adapterAddress ?? "");
|
|
9436
9490
|
}
|
|
9437
9491
|
// ===== Seed Lifecycle =====
|
|
9438
9492
|
/** Seed management (create, import, export, delete mnemonic). */
|
|
@@ -9463,10 +9517,10 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
9463
9517
|
return this.sdk.deposit.reconcile(relayId);
|
|
9464
9518
|
}
|
|
9465
9519
|
/**
|
|
9466
|
-
*
|
|
9520
|
+
* Send a private transfer (1 or more recipients).
|
|
9467
9521
|
* Handles note selection, circuit selection, and proof generation automatically.
|
|
9468
9522
|
*/
|
|
9469
|
-
async
|
|
9523
|
+
async send(params, overrides) {
|
|
9470
9524
|
return this.sdk.transfer.send(
|
|
9471
9525
|
{
|
|
9472
9526
|
chainId: this.chainId,
|
|
@@ -9477,9 +9531,9 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
9477
9531
|
);
|
|
9478
9532
|
}
|
|
9479
9533
|
/**
|
|
9480
|
-
* Get a
|
|
9534
|
+
* Get a send plan without executing (for preview/confirmation UIs).
|
|
9481
9535
|
*/
|
|
9482
|
-
async
|
|
9536
|
+
async planSend(params, account) {
|
|
9483
9537
|
return this.sdk.transfer.plan(
|
|
9484
9538
|
{
|
|
9485
9539
|
chainId: this.chainId,
|
|
@@ -9489,8 +9543,8 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
9489
9543
|
account
|
|
9490
9544
|
);
|
|
9491
9545
|
}
|
|
9492
|
-
/** Execute a pre-built
|
|
9493
|
-
async
|
|
9546
|
+
/** Execute a pre-built send plan. */
|
|
9547
|
+
async executeSend(plans, overrides) {
|
|
9494
9548
|
return this.sdk.transfer.execute(
|
|
9495
9549
|
plans,
|
|
9496
9550
|
{ chainId: this.chainId, poolAddress: this.poolAddress },
|
|
@@ -9639,31 +9693,31 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
9639
9693
|
return this.sdk.burner.getBalance(address);
|
|
9640
9694
|
}
|
|
9641
9695
|
};
|
|
9642
|
-
// =====
|
|
9696
|
+
// ===== Interact (Private DeFi) =====
|
|
9643
9697
|
/**
|
|
9644
|
-
*
|
|
9645
|
-
*
|
|
9698
|
+
* Adapter contract address (resolved from config).
|
|
9699
|
+
* Use for building DeFi calls that reference the adapter.
|
|
9646
9700
|
*/
|
|
9647
|
-
adapter
|
|
9648
|
-
|
|
9649
|
-
|
|
9650
|
-
|
|
9651
|
-
|
|
9652
|
-
|
|
9653
|
-
|
|
9654
|
-
|
|
9655
|
-
|
|
9656
|
-
|
|
9657
|
-
|
|
9658
|
-
|
|
9659
|
-
|
|
9660
|
-
|
|
9661
|
-
|
|
9662
|
-
|
|
9663
|
-
|
|
9664
|
-
|
|
9665
|
-
|
|
9666
|
-
}
|
|
9701
|
+
adapter;
|
|
9702
|
+
/**
|
|
9703
|
+
* Execute an atomic unshield -> DeFi call(s) -> reshield flow through an adapter.
|
|
9704
|
+
* chainId/poolAddress/adapterAddress are injected automatically.
|
|
9705
|
+
*/
|
|
9706
|
+
async interact(params, opts, overrides) {
|
|
9707
|
+
return this.sdk.adapter.execute(
|
|
9708
|
+
{
|
|
9709
|
+
chainId: this.chainId,
|
|
9710
|
+
poolAddress: this.poolAddress,
|
|
9711
|
+
adapterAddress: this.adapterAddress,
|
|
9712
|
+
spend: params.spend,
|
|
9713
|
+
calls: params.calls,
|
|
9714
|
+
receive: params.receive,
|
|
9715
|
+
deadline: params.deadline
|
|
9716
|
+
},
|
|
9717
|
+
opts,
|
|
9718
|
+
overrides
|
|
9719
|
+
);
|
|
9720
|
+
}
|
|
9667
9721
|
// ===== Advanced =====
|
|
9668
9722
|
/**
|
|
9669
9723
|
* Advanced escape hatch for raw JoinSplit transaction building.
|
|
@@ -9711,6 +9765,7 @@ var defaultRng = (n) => {
|
|
|
9711
9765
|
}
|
|
9712
9766
|
return globalThis.crypto.getRandomValues(new Uint8Array(n));
|
|
9713
9767
|
};
|
|
9768
|
+
var UnlinkWallet = Unlink;
|
|
9714
9769
|
|
|
9715
9770
|
// utils/amounts.ts
|
|
9716
9771
|
function parseAmount(value, decimals) {
|
|
@@ -9763,6 +9818,7 @@ export {
|
|
|
9763
9818
|
HttpError,
|
|
9764
9819
|
InitializationError,
|
|
9765
9820
|
ProofError,
|
|
9821
|
+
Unlink,
|
|
9766
9822
|
UnlinkWallet,
|
|
9767
9823
|
ValidationError,
|
|
9768
9824
|
computeBalances,
|