@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/config.d.ts
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* Each maps to a full config (chainId, gateway, pool, artifacts).
|
|
4
4
|
*/
|
|
5
5
|
export type SupportedChain = "monad-testnet" | "monad-testnet-staging";
|
|
6
|
+
/**
|
|
7
|
+
* Default public RPC URLs per chain (not fetched from remote config).
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEFAULT_RPC_URLS: Record<SupportedChain, string>;
|
|
6
10
|
/**
|
|
7
11
|
* Full configuration for a supported chain.
|
|
8
12
|
*/
|
|
@@ -11,8 +15,10 @@ export interface ChainConfig {
|
|
|
11
15
|
gatewayUrl: string;
|
|
12
16
|
frostUrl?: string;
|
|
13
17
|
poolAddress: string;
|
|
18
|
+
adapterAddress?: string;
|
|
14
19
|
artifactVersion: string;
|
|
15
20
|
artifactBaseUrl?: string;
|
|
21
|
+
tokenAddresses?: Record<string, string>;
|
|
16
22
|
}
|
|
17
23
|
/**
|
|
18
24
|
* Service configuration with broadcaster and indexer URLs.
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../config.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG,uBAAuB,CAAC;AAEvE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../config.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG,uBAAuB,CAAC;AAEvE;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,cAAc,EAAE,MAAM,CAG3D,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;CACxB;AAqHD;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,cAAc,GACpB,OAAO,CAAC,WAAW,CAAC,CAYtB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,aAAa,CAMrE"}
|
package/dist/index.d.ts
CHANGED
|
@@ -16,13 +16,13 @@ export * from "./account/account.js";
|
|
|
16
16
|
export * from "./keys/index.js";
|
|
17
17
|
export * from "./history/index.js";
|
|
18
18
|
export * from "./transactions/index.js";
|
|
19
|
-
export { createServiceConfig, fetchChainConfig } from "./config.js";
|
|
19
|
+
export { createServiceConfig, DEFAULT_RPC_URLS, fetchChainConfig, } from "./config.js";
|
|
20
20
|
export type { ChainConfig, ServiceConfig, SupportedChain } from "./config.js";
|
|
21
21
|
export * from "./clients/broadcaster.js";
|
|
22
22
|
export * from "./clients/indexer.js";
|
|
23
23
|
export { HttpError } from "./clients/http.js";
|
|
24
24
|
export * from "./crypto/adapters/index.js";
|
|
25
|
-
export { UnlinkWallet } from "./wallet/unlink
|
|
25
|
+
export { Unlink, UnlinkWallet } from "./wallet/unlink.js";
|
|
26
26
|
export { encryptNote, deriveNpk, computeCommitment } from "./crypto/encrypt.js";
|
|
27
27
|
export { createBrowserWalletSDK, createWalletSDK, type BrowserWalletOptions, type BrowserWalletResult, } from "./wallet/sdk.js";
|
|
28
28
|
export type * from "./wallet/types.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC9E,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,GACzB,MAAM,iBAAiB,CAAC;AACzB,mBAAmB,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5568,6 +5568,10 @@ var Runtime = {
|
|
|
5568
5568
|
};
|
|
5569
5569
|
|
|
5570
5570
|
// config.ts
|
|
5571
|
+
var DEFAULT_RPC_URLS = {
|
|
5572
|
+
"monad-testnet": "https://testnet-rpc.monad.xyz",
|
|
5573
|
+
"monad-testnet-staging": "https://testnet-rpc.monad.xyz"
|
|
5574
|
+
};
|
|
5571
5575
|
var CONFIG_URL = "https://config.unlink.xyz/networks.json";
|
|
5572
5576
|
function parseRequiredString(chain, field, value) {
|
|
5573
5577
|
if (typeof value !== "string" || value.trim().length === 0) {
|
|
@@ -5617,6 +5621,11 @@ function parseChainConfig(chain, value) {
|
|
|
5617
5621
|
"artifactVersion",
|
|
5618
5622
|
raw.artifactVersion
|
|
5619
5623
|
).replace(/^\/+|\/+$/g, "");
|
|
5624
|
+
const adapterAddress = parseOptionalString(
|
|
5625
|
+
chain,
|
|
5626
|
+
"adapterAddress",
|
|
5627
|
+
raw.adapterAddress
|
|
5628
|
+
);
|
|
5620
5629
|
const frostUrl = parseOptionalString(
|
|
5621
5630
|
chain,
|
|
5622
5631
|
"frostUrl",
|
|
@@ -5627,13 +5636,33 @@ function parseChainConfig(chain, value) {
|
|
|
5627
5636
|
"artifactBaseUrl",
|
|
5628
5637
|
raw.artifactBaseUrl
|
|
5629
5638
|
)?.replace(/\/+$/, "");
|
|
5639
|
+
let tokenAddresses;
|
|
5640
|
+
if (raw.tokenAddresses !== void 0) {
|
|
5641
|
+
if (raw.tokenAddresses === null || typeof raw.tokenAddresses !== "object" || Array.isArray(raw.tokenAddresses)) {
|
|
5642
|
+
throw new InitializationError(
|
|
5643
|
+
`Invalid SDK config for ${chain}: tokenAddresses must be an object`
|
|
5644
|
+
);
|
|
5645
|
+
}
|
|
5646
|
+
tokenAddresses = {};
|
|
5647
|
+
for (const [name, addr] of Object.entries(
|
|
5648
|
+
raw.tokenAddresses
|
|
5649
|
+
)) {
|
|
5650
|
+
tokenAddresses[name] = parseRequiredString(
|
|
5651
|
+
chain,
|
|
5652
|
+
`tokenAddresses.${name}`,
|
|
5653
|
+
addr
|
|
5654
|
+
);
|
|
5655
|
+
}
|
|
5656
|
+
}
|
|
5630
5657
|
return {
|
|
5631
5658
|
chainId,
|
|
5632
5659
|
gatewayUrl,
|
|
5633
5660
|
...frostUrl !== void 0 ? { frostUrl } : {},
|
|
5634
5661
|
poolAddress,
|
|
5662
|
+
...adapterAddress !== void 0 ? { adapterAddress } : {},
|
|
5635
5663
|
artifactVersion,
|
|
5636
|
-
...artifactBaseUrl !== void 0 ? { artifactBaseUrl } : { artifactBaseUrl: DEFAULT_ARTIFACT_BASE_URL }
|
|
5664
|
+
...artifactBaseUrl !== void 0 ? { artifactBaseUrl } : { artifactBaseUrl: DEFAULT_ARTIFACT_BASE_URL },
|
|
5665
|
+
...tokenAddresses !== void 0 ? { tokenAddresses } : {}
|
|
5637
5666
|
};
|
|
5638
5667
|
}
|
|
5639
5668
|
async function fetchChainConfig(chain) {
|
|
@@ -7147,7 +7176,7 @@ function buildCall(params) {
|
|
|
7147
7176
|
}
|
|
7148
7177
|
return { to, data, value };
|
|
7149
7178
|
}
|
|
7150
|
-
function
|
|
7179
|
+
function approve(token, spender, amount) {
|
|
7151
7180
|
const normalizedToken = ensureAddress("token", token);
|
|
7152
7181
|
const normalizedSpender = ensureAddress("spender", spender);
|
|
7153
7182
|
const normalizedAmount = ensureNonNegative("amount", amount);
|
|
@@ -7161,6 +7190,44 @@ function buildApproveCall(token, spender, amount) {
|
|
|
7161
7190
|
value: 0n
|
|
7162
7191
|
};
|
|
7163
7192
|
}
|
|
7193
|
+
function toCall(tx) {
|
|
7194
|
+
if (tx.to == null) {
|
|
7195
|
+
throw new AdapterError("tx.to is required");
|
|
7196
|
+
}
|
|
7197
|
+
const to = ensureAddress("tx.to", tx.to);
|
|
7198
|
+
if (tx.data == null) {
|
|
7199
|
+
throw new AdapterError("tx.data is required");
|
|
7200
|
+
}
|
|
7201
|
+
const data = ensureHexData("tx.data", tx.data);
|
|
7202
|
+
let value;
|
|
7203
|
+
if (tx.value == null) {
|
|
7204
|
+
value = 0n;
|
|
7205
|
+
} else {
|
|
7206
|
+
try {
|
|
7207
|
+
value = BigInt(tx.value);
|
|
7208
|
+
} catch {
|
|
7209
|
+
throw new AdapterError(
|
|
7210
|
+
`tx.value must be convertible to bigint, received: ${String(tx.value)}`
|
|
7211
|
+
);
|
|
7212
|
+
}
|
|
7213
|
+
}
|
|
7214
|
+
return { to, data, value: ensureNonNegative("tx.value", value) };
|
|
7215
|
+
}
|
|
7216
|
+
function contract(address, abi) {
|
|
7217
|
+
const to = ensureAddress("contract.address", address);
|
|
7218
|
+
const iface = new Interface3(abi);
|
|
7219
|
+
return new Proxy(
|
|
7220
|
+
{},
|
|
7221
|
+
{
|
|
7222
|
+
get(_, method) {
|
|
7223
|
+
return (...args) => {
|
|
7224
|
+
const data = iface.encodeFunctionData(method, args);
|
|
7225
|
+
return { to, data, value: 0n };
|
|
7226
|
+
};
|
|
7227
|
+
}
|
|
7228
|
+
}
|
|
7229
|
+
);
|
|
7230
|
+
}
|
|
7164
7231
|
function encodeAdapterExecute(params) {
|
|
7165
7232
|
const transactCalldata = ensureHexData(
|
|
7166
7233
|
"transactCalldata",
|
|
@@ -7184,6 +7251,7 @@ function encodeAdapterExecute(params) {
|
|
|
7184
7251
|
deadline
|
|
7185
7252
|
]);
|
|
7186
7253
|
}
|
|
7254
|
+
var buildApproveCall = approve;
|
|
7187
7255
|
|
|
7188
7256
|
// transactions/note-selection.ts
|
|
7189
7257
|
var MAX_CIRCUIT_INPUTS = Math.max(
|
|
@@ -8562,26 +8630,34 @@ function normalizeCall2(call, index) {
|
|
|
8562
8630
|
value: call.value
|
|
8563
8631
|
};
|
|
8564
8632
|
}
|
|
8565
|
-
function
|
|
8566
|
-
const token = ensureAddress(`
|
|
8633
|
+
function normalizeSpendInput(input, index) {
|
|
8634
|
+
const token = ensureAddress(`spend[${index}].token`, input.token);
|
|
8635
|
+
if (token.toLowerCase() === ETH_TOKEN.toLowerCase()) {
|
|
8636
|
+
throw new AdapterError(
|
|
8637
|
+
`spend[${index}].token: native ETH is not supported in adapter execution`
|
|
8638
|
+
);
|
|
8639
|
+
}
|
|
8567
8640
|
if (input.amount <= 0n) {
|
|
8568
|
-
throw new AdapterError(`
|
|
8641
|
+
throw new AdapterError(`spend[${index}].amount must be greater than zero`);
|
|
8569
8642
|
}
|
|
8570
8643
|
return {
|
|
8571
8644
|
token,
|
|
8572
8645
|
amount: input.amount
|
|
8573
8646
|
};
|
|
8574
8647
|
}
|
|
8575
|
-
function
|
|
8576
|
-
const token = ensureAddress(`
|
|
8577
|
-
if (
|
|
8648
|
+
function normalizeReceiveInput(receive, index) {
|
|
8649
|
+
const token = ensureAddress(`receive[${index}].token`, receive.token);
|
|
8650
|
+
if (token.toLowerCase() === ETH_TOKEN.toLowerCase()) {
|
|
8578
8651
|
throw new AdapterError(
|
|
8579
|
-
`
|
|
8652
|
+
`receive[${index}].token: native ETH is not supported in adapter execution`
|
|
8580
8653
|
);
|
|
8581
8654
|
}
|
|
8655
|
+
if (receive.minAmount < 0n) {
|
|
8656
|
+
throw new AdapterError(`receive[${index}].minAmount must be non-negative`);
|
|
8657
|
+
}
|
|
8582
8658
|
return {
|
|
8583
8659
|
token,
|
|
8584
|
-
minAmount:
|
|
8660
|
+
minAmount: receive.minAmount
|
|
8585
8661
|
};
|
|
8586
8662
|
}
|
|
8587
8663
|
function randomFieldElement(randomBigintFn) {
|
|
@@ -8601,41 +8677,41 @@ function createAdapterService(deps) {
|
|
|
8601
8677
|
"adapterAddress",
|
|
8602
8678
|
params.adapterAddress
|
|
8603
8679
|
);
|
|
8604
|
-
if (!params.
|
|
8605
|
-
throw new AdapterError("at least one
|
|
8680
|
+
if (!params.spend.length) {
|
|
8681
|
+
throw new AdapterError("at least one spend token is required");
|
|
8606
8682
|
}
|
|
8607
8683
|
if (!params.calls.length) {
|
|
8608
8684
|
throw new AdapterError("at least one adapter call is required");
|
|
8609
8685
|
}
|
|
8610
|
-
if (!params.
|
|
8611
|
-
throw new AdapterError("at least one
|
|
8686
|
+
if (!params.receive.length) {
|
|
8687
|
+
throw new AdapterError("at least one receive output is required");
|
|
8612
8688
|
}
|
|
8613
|
-
const
|
|
8614
|
-
(input, i) =>
|
|
8689
|
+
const spendInputs = params.spend.map(
|
|
8690
|
+
(input, i) => normalizeSpendInput(input, i)
|
|
8615
8691
|
);
|
|
8616
8692
|
const seenTokens = /* @__PURE__ */ new Set();
|
|
8617
|
-
for (const input of
|
|
8693
|
+
for (const input of spendInputs) {
|
|
8618
8694
|
const lower = input.token.toLowerCase();
|
|
8619
8695
|
if (seenTokens.has(lower)) {
|
|
8620
8696
|
throw new AdapterError(
|
|
8621
|
-
`duplicate
|
|
8697
|
+
`duplicate spend token ${input.token}; combine amounts per token instead`
|
|
8622
8698
|
);
|
|
8623
8699
|
}
|
|
8624
8700
|
seenTokens.add(lower);
|
|
8625
8701
|
}
|
|
8626
8702
|
const calls = params.calls.map((call, i) => normalizeCall2(call, i));
|
|
8627
|
-
const
|
|
8628
|
-
(
|
|
8703
|
+
const receiveSpecs = params.receive.map(
|
|
8704
|
+
(receive, i) => normalizeReceiveInput(receive, i)
|
|
8629
8705
|
);
|
|
8630
|
-
const
|
|
8631
|
-
for (const r2 of
|
|
8706
|
+
const seenReceiveTokens = /* @__PURE__ */ new Set();
|
|
8707
|
+
for (const r2 of receiveSpecs) {
|
|
8632
8708
|
const lower = r2.token.toLowerCase();
|
|
8633
|
-
if (
|
|
8709
|
+
if (seenReceiveTokens.has(lower)) {
|
|
8634
8710
|
throw new AdapterError(
|
|
8635
|
-
`duplicate
|
|
8711
|
+
`duplicate receive token ${r2.token}; each receive must target a unique token`
|
|
8636
8712
|
);
|
|
8637
8713
|
}
|
|
8638
|
-
|
|
8714
|
+
seenReceiveTokens.add(lower);
|
|
8639
8715
|
}
|
|
8640
8716
|
const account = overrides?.account ?? await deps.requireActiveAccount();
|
|
8641
8717
|
const signer = overrides?.signer ?? deps.requireSigner(account);
|
|
@@ -8645,19 +8721,19 @@ function createAdapterService(deps) {
|
|
|
8645
8721
|
throw new AdapterError("deadline must be in the future");
|
|
8646
8722
|
}
|
|
8647
8723
|
const executionCalls = calls;
|
|
8648
|
-
const reshields =
|
|
8649
|
-
(
|
|
8724
|
+
const reshields = receiveSpecs.map(
|
|
8725
|
+
(receive) => {
|
|
8650
8726
|
const random = randomFieldElement(randomBigintImpl);
|
|
8651
8727
|
const npk = poseidon([account.masterPublicKey, random]);
|
|
8652
8728
|
return {
|
|
8653
8729
|
npk,
|
|
8654
8730
|
random,
|
|
8655
|
-
token:
|
|
8656
|
-
minAmount:
|
|
8731
|
+
token: receive.token,
|
|
8732
|
+
minAmount: receive.minAmount
|
|
8657
8733
|
};
|
|
8658
8734
|
}
|
|
8659
8735
|
);
|
|
8660
|
-
const inputTokens =
|
|
8736
|
+
const inputTokens = spendInputs.map((input) => input.token);
|
|
8661
8737
|
const nonce = randomFieldElement(randomBigintImpl);
|
|
8662
8738
|
const adapterDataHash = computeAdapterDataHash({
|
|
8663
8739
|
calls: executionCalls,
|
|
@@ -8674,7 +8750,7 @@ function createAdapterService(deps) {
|
|
|
8674
8750
|
});
|
|
8675
8751
|
const withdrawalPlans = planWithdrawalsImpl(
|
|
8676
8752
|
notes,
|
|
8677
|
-
|
|
8753
|
+
spendInputs.map((input) => ({
|
|
8678
8754
|
token: input.token,
|
|
8679
8755
|
amount: input.amount,
|
|
8680
8756
|
recipient: adapterAddress
|
|
@@ -8757,7 +8833,7 @@ function createAdapterService(deps) {
|
|
|
8757
8833
|
adapterCalldata,
|
|
8758
8834
|
historyPreview: {
|
|
8759
8835
|
kind: "Withdraw",
|
|
8760
|
-
amounts:
|
|
8836
|
+
amounts: spendInputs.map((input) => ({
|
|
8761
8837
|
token: input.token,
|
|
8762
8838
|
delta: (-input.amount).toString()
|
|
8763
8839
|
}))
|
|
@@ -8784,6 +8860,9 @@ import {
|
|
|
8784
8860
|
} from "ethers";
|
|
8785
8861
|
var BIP44_ETH_PREFIX = "m/44'/60'/0'/0";
|
|
8786
8862
|
var ERC20_BALANCE_OF = "function balanceOf(address) view returns (uint256)";
|
|
8863
|
+
function isNativeToken(token) {
|
|
8864
|
+
return token.toLowerCase() === ETH_TOKEN.toLowerCase();
|
|
8865
|
+
}
|
|
8787
8866
|
function createBurnerService(deps) {
|
|
8788
8867
|
const { chainRpcUrl, getMasterSeed, withdrawToAddress, requestDeposit } = deps;
|
|
8789
8868
|
const provider = new JsonRpcProvider(chainRpcUrl);
|
|
@@ -8831,8 +8910,8 @@ function createBurnerService(deps) {
|
|
|
8831
8910
|
}
|
|
8832
8911
|
async function getTokenBalance(address, token) {
|
|
8833
8912
|
const iface = new Interface4([ERC20_BALANCE_OF]);
|
|
8834
|
-
const
|
|
8835
|
-
const bal = await
|
|
8913
|
+
const contract2 = new Contract(token, iface, provider);
|
|
8914
|
+
const bal = await contract2.getFunction("balanceOf")(address);
|
|
8836
8915
|
return BigInt(bal ?? 0);
|
|
8837
8916
|
}
|
|
8838
8917
|
async function getBalance(address) {
|
|
@@ -8851,6 +8930,12 @@ function createBurnerService(deps) {
|
|
|
8851
8930
|
}
|
|
8852
8931
|
async function sweepToPool(index, params) {
|
|
8853
8932
|
const { address } = await addressOf(index);
|
|
8933
|
+
const native = isNativeToken(params.token);
|
|
8934
|
+
if (native && params.amount == null) {
|
|
8935
|
+
throw new Error(
|
|
8936
|
+
"amount is required for native ETH sweeps (needed to reserve gas)"
|
|
8937
|
+
);
|
|
8938
|
+
}
|
|
8854
8939
|
const amount = params.amount ?? await getTokenBalance(address, params.token);
|
|
8855
8940
|
if (amount === 0n) {
|
|
8856
8941
|
throw new Error("No token balance to sweep");
|
|
@@ -8861,17 +8946,20 @@ function createBurnerService(deps) {
|
|
|
8861
8946
|
depositor: address,
|
|
8862
8947
|
deposits: [{ token: params.token, amount }]
|
|
8863
8948
|
});
|
|
8864
|
-
|
|
8865
|
-
|
|
8866
|
-
|
|
8867
|
-
|
|
8868
|
-
|
|
8869
|
-
|
|
8870
|
-
|
|
8871
|
-
|
|
8949
|
+
if (!native) {
|
|
8950
|
+
const erc20Iface = new Interface4([
|
|
8951
|
+
"function approve(address spender, uint256 amount)"
|
|
8952
|
+
]);
|
|
8953
|
+
const approveData = erc20Iface.encodeFunctionData("approve", [
|
|
8954
|
+
params.poolAddress,
|
|
8955
|
+
amount
|
|
8956
|
+
]);
|
|
8957
|
+
await send(index, { to: params.token, data: approveData });
|
|
8958
|
+
}
|
|
8872
8959
|
const { txHash } = await send(index, {
|
|
8873
8960
|
to: depositResult.to,
|
|
8874
|
-
data: depositResult.calldata
|
|
8961
|
+
data: depositResult.calldata,
|
|
8962
|
+
value: depositResult.value
|
|
8875
8963
|
});
|
|
8876
8964
|
return { txHash };
|
|
8877
8965
|
}
|
|
@@ -9581,21 +9669,27 @@ async function createBrowserWalletSDK(options) {
|
|
|
9581
9669
|
};
|
|
9582
9670
|
}
|
|
9583
9671
|
|
|
9584
|
-
// wallet/unlink
|
|
9585
|
-
var
|
|
9672
|
+
// wallet/unlink.ts
|
|
9673
|
+
var Unlink = class _Unlink {
|
|
9586
9674
|
/** @internal */
|
|
9587
9675
|
sdk;
|
|
9588
9676
|
/** Chain ID this wallet operates on. */
|
|
9589
9677
|
chainId;
|
|
9590
9678
|
/** Pool contract address this wallet transacts with. */
|
|
9591
9679
|
poolAddress;
|
|
9592
|
-
|
|
9680
|
+
/** Adapter contract address for DeFi operations. */
|
|
9681
|
+
adapterAddress;
|
|
9682
|
+
constructor(sdk, chainId, poolAddress, adapterAddress) {
|
|
9593
9683
|
this.sdk = sdk;
|
|
9594
9684
|
this.chainId = chainId;
|
|
9595
9685
|
this.poolAddress = poolAddress;
|
|
9686
|
+
this.adapterAddress = adapterAddress;
|
|
9687
|
+
this.adapter = {
|
|
9688
|
+
address: adapterAddress
|
|
9689
|
+
};
|
|
9596
9690
|
}
|
|
9597
9691
|
/**
|
|
9598
|
-
* Create a new
|
|
9692
|
+
* Create a new Unlink instance.
|
|
9599
9693
|
*
|
|
9600
9694
|
* Handles all initialization internally:
|
|
9601
9695
|
* - Resolves chain config (if using `chain` instead of explicit URLs)
|
|
@@ -9607,12 +9701,14 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
9607
9701
|
let chainId;
|
|
9608
9702
|
let gatewayUrl;
|
|
9609
9703
|
let poolAddress;
|
|
9704
|
+
let adapterAddress;
|
|
9610
9705
|
let proverConfig = config.prover;
|
|
9611
9706
|
if ("chain" in config) {
|
|
9612
9707
|
const chainConfig = await fetchChainConfig(config.chain);
|
|
9613
9708
|
chainId = chainConfig.chainId;
|
|
9614
9709
|
gatewayUrl = chainConfig.gatewayUrl;
|
|
9615
9710
|
poolAddress = config.poolAddress ?? chainConfig.poolAddress;
|
|
9711
|
+
adapterAddress = config.adapterAddress ?? chainConfig.adapterAddress;
|
|
9616
9712
|
proverConfig = {
|
|
9617
9713
|
artifactSource: {
|
|
9618
9714
|
baseUrl: config.prover?.artifactSource?.baseUrl ?? chainConfig.artifactBaseUrl,
|
|
@@ -9624,6 +9720,7 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
9624
9720
|
chainId = config.chainId;
|
|
9625
9721
|
gatewayUrl = config.gatewayUrl;
|
|
9626
9722
|
poolAddress = config.poolAddress;
|
|
9723
|
+
adapterAddress = config.adapterAddress;
|
|
9627
9724
|
if (typeof window !== "undefined" && !config.prover?.artifactSource?.version) {
|
|
9628
9725
|
throw new InitializationError(
|
|
9629
9726
|
"prover.artifactSource.version is required in browser when using explicit gatewayUrl mode. Use chain mode or provide a pinned artifact version."
|
|
@@ -9644,7 +9741,7 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
9644
9741
|
autoSync: config.autoSync
|
|
9645
9742
|
}
|
|
9646
9743
|
);
|
|
9647
|
-
return new
|
|
9744
|
+
return new _Unlink(sdk, chainId, poolAddress, adapterAddress ?? "");
|
|
9648
9745
|
}
|
|
9649
9746
|
// ===== Seed Lifecycle =====
|
|
9650
9747
|
/** Seed management (create, import, export, delete mnemonic). */
|
|
@@ -9675,10 +9772,10 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
9675
9772
|
return this.sdk.deposit.reconcile(relayId);
|
|
9676
9773
|
}
|
|
9677
9774
|
/**
|
|
9678
|
-
*
|
|
9775
|
+
* Send a private transfer (1 or more recipients).
|
|
9679
9776
|
* Handles note selection, circuit selection, and proof generation automatically.
|
|
9680
9777
|
*/
|
|
9681
|
-
async
|
|
9778
|
+
async send(params, overrides) {
|
|
9682
9779
|
return this.sdk.transfer.send(
|
|
9683
9780
|
{
|
|
9684
9781
|
chainId: this.chainId,
|
|
@@ -9689,9 +9786,9 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
9689
9786
|
);
|
|
9690
9787
|
}
|
|
9691
9788
|
/**
|
|
9692
|
-
* Get a
|
|
9789
|
+
* Get a send plan without executing (for preview/confirmation UIs).
|
|
9693
9790
|
*/
|
|
9694
|
-
async
|
|
9791
|
+
async planSend(params, account) {
|
|
9695
9792
|
return this.sdk.transfer.plan(
|
|
9696
9793
|
{
|
|
9697
9794
|
chainId: this.chainId,
|
|
@@ -9701,8 +9798,8 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
9701
9798
|
account
|
|
9702
9799
|
);
|
|
9703
9800
|
}
|
|
9704
|
-
/** Execute a pre-built
|
|
9705
|
-
async
|
|
9801
|
+
/** Execute a pre-built send plan. */
|
|
9802
|
+
async executeSend(plans, overrides) {
|
|
9706
9803
|
return this.sdk.transfer.execute(
|
|
9707
9804
|
plans,
|
|
9708
9805
|
{ chainId: this.chainId, poolAddress: this.poolAddress },
|
|
@@ -9851,31 +9948,31 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
9851
9948
|
return this.sdk.burner.getBalance(address);
|
|
9852
9949
|
}
|
|
9853
9950
|
};
|
|
9854
|
-
// =====
|
|
9951
|
+
// ===== Interact (Private DeFi) =====
|
|
9855
9952
|
/**
|
|
9856
|
-
*
|
|
9857
|
-
*
|
|
9953
|
+
* Adapter contract address (resolved from config).
|
|
9954
|
+
* Use for building DeFi calls that reference the adapter.
|
|
9858
9955
|
*/
|
|
9859
|
-
adapter
|
|
9860
|
-
|
|
9861
|
-
|
|
9862
|
-
|
|
9863
|
-
|
|
9864
|
-
|
|
9865
|
-
|
|
9866
|
-
|
|
9867
|
-
|
|
9868
|
-
|
|
9869
|
-
|
|
9870
|
-
|
|
9871
|
-
|
|
9872
|
-
|
|
9873
|
-
|
|
9874
|
-
|
|
9875
|
-
|
|
9876
|
-
|
|
9877
|
-
|
|
9878
|
-
}
|
|
9956
|
+
adapter;
|
|
9957
|
+
/**
|
|
9958
|
+
* Execute an atomic unshield -> DeFi call(s) -> reshield flow through an adapter.
|
|
9959
|
+
* chainId/poolAddress/adapterAddress are injected automatically.
|
|
9960
|
+
*/
|
|
9961
|
+
async interact(params, opts, overrides) {
|
|
9962
|
+
return this.sdk.adapter.execute(
|
|
9963
|
+
{
|
|
9964
|
+
chainId: this.chainId,
|
|
9965
|
+
poolAddress: this.poolAddress,
|
|
9966
|
+
adapterAddress: this.adapterAddress,
|
|
9967
|
+
spend: params.spend,
|
|
9968
|
+
calls: params.calls,
|
|
9969
|
+
receive: params.receive,
|
|
9970
|
+
deadline: params.deadline
|
|
9971
|
+
},
|
|
9972
|
+
opts,
|
|
9973
|
+
overrides
|
|
9974
|
+
);
|
|
9975
|
+
}
|
|
9879
9976
|
// ===== Advanced =====
|
|
9880
9977
|
/**
|
|
9881
9978
|
* Advanced escape hatch for raw JoinSplit transaction building.
|
|
@@ -9923,12 +10020,14 @@ var defaultRng = (n) => {
|
|
|
9923
10020
|
}
|
|
9924
10021
|
return globalThis.crypto.getRandomValues(new Uint8Array(n));
|
|
9925
10022
|
};
|
|
10023
|
+
var UnlinkWallet = Unlink;
|
|
9926
10024
|
export {
|
|
9927
10025
|
ADAPTER_EXECUTE_ABI,
|
|
9928
10026
|
AdapterError,
|
|
9929
10027
|
CORE_SCHEMA_VERSION,
|
|
9930
10028
|
CoreError,
|
|
9931
10029
|
DEFAULT_JOB_TIMEOUT_MS,
|
|
10030
|
+
DEFAULT_RPC_URLS,
|
|
9932
10031
|
DEPOSIT_ABI,
|
|
9933
10032
|
ETH_TOKEN,
|
|
9934
10033
|
FieldSize,
|
|
@@ -9946,8 +10045,10 @@ export {
|
|
|
9946
10045
|
ReconcileError,
|
|
9947
10046
|
SNARK_SCALAR_FIELD,
|
|
9948
10047
|
SchemaMismatchError,
|
|
10048
|
+
Unlink,
|
|
9949
10049
|
UnlinkWallet,
|
|
9950
10050
|
ValidationError,
|
|
10051
|
+
approve,
|
|
9951
10052
|
assertNonNegative,
|
|
9952
10053
|
buildApproveCall,
|
|
9953
10054
|
buildCall,
|
|
@@ -9957,6 +10058,7 @@ export {
|
|
|
9957
10058
|
computeCommitment,
|
|
9958
10059
|
computeMasterPublicKey,
|
|
9959
10060
|
computeNullifyingKey,
|
|
10061
|
+
contract,
|
|
9960
10062
|
createBroadcasterClient,
|
|
9961
10063
|
createBrowserWalletSDK,
|
|
9962
10064
|
createCiphertextStore,
|
|
@@ -10029,6 +10131,7 @@ export {
|
|
|
10029
10131
|
syncDeposit,
|
|
10030
10132
|
syncTransact,
|
|
10031
10133
|
toAccountView,
|
|
10134
|
+
toCall,
|
|
10032
10135
|
transact,
|
|
10033
10136
|
validateKey,
|
|
10034
10137
|
verifySignature,
|