@owney/sdk 0.7.25-beta.3 → 0.7.25-beta.4
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.cjs +51 -8
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +51 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2354,12 +2354,13 @@ function randomPermit2Nonce() {
|
|
|
2354
2354
|
globalThis.crypto.getRandomValues(bytes);
|
|
2355
2355
|
return BigInt((0, import_viem3.bytesToHex)(bytes));
|
|
2356
2356
|
}
|
|
2357
|
-
async function readPermit2Allowance(publicClient, token, owner) {
|
|
2357
|
+
async function readPermit2Allowance(publicClient, token, owner, blockNumber) {
|
|
2358
2358
|
return publicClient.readContract({
|
|
2359
2359
|
address: token,
|
|
2360
2360
|
abi: ERC20_ALLOWANCE_ABI,
|
|
2361
2361
|
functionName: "allowance",
|
|
2362
|
-
args: [owner, PERMIT2_ADDRESS]
|
|
2362
|
+
args: [owner, PERMIT2_ADDRESS],
|
|
2363
|
+
...blockNumber === void 0 ? {} : { blockNumber }
|
|
2363
2364
|
});
|
|
2364
2365
|
}
|
|
2365
2366
|
async function readErc20Balance(publicClient, token, owner) {
|
|
@@ -4714,6 +4715,8 @@ function makeSponsoredCallsCallback(deps) {
|
|
|
4714
4715
|
}
|
|
4715
4716
|
|
|
4716
4717
|
// src/client.ts
|
|
4718
|
+
var PERMIT2_ALLOWANCE_VERIFY_ATTEMPTS = 6;
|
|
4719
|
+
var PERMIT2_ALLOWANCE_VERIFY_DELAY_MS = 250;
|
|
4717
4720
|
function encodeMultiAgentCursor(map) {
|
|
4718
4721
|
return Buffer.from(JSON.stringify(map), "utf8").toString("base64");
|
|
4719
4722
|
}
|
|
@@ -5362,7 +5365,8 @@ var OwneySDK = class {
|
|
|
5362
5365
|
);
|
|
5363
5366
|
await this.approvePermit2(
|
|
5364
5367
|
asset,
|
|
5365
|
-
requiredAmount
|
|
5368
|
+
requiredAmount,
|
|
5369
|
+
cid
|
|
5366
5370
|
);
|
|
5367
5371
|
return batchTransfer(cid, transfers);
|
|
5368
5372
|
}
|
|
@@ -5452,7 +5456,8 @@ var OwneySDK = class {
|
|
|
5452
5456
|
);
|
|
5453
5457
|
await this.approvePermit2(
|
|
5454
5458
|
asset,
|
|
5455
|
-
BigInt(amount)
|
|
5459
|
+
BigInt(amount),
|
|
5460
|
+
chainId
|
|
5456
5461
|
);
|
|
5457
5462
|
continue;
|
|
5458
5463
|
}
|
|
@@ -6175,14 +6180,16 @@ var OwneySDK = class {
|
|
|
6175
6180
|
* User-paid approval of Permit2 on the selected token for the active chain.
|
|
6176
6181
|
* Grants the maximum ERC20 allowance so later deposits do not require another
|
|
6177
6182
|
* approval. Resolves after one confirmation so the subsequent deposit attempt
|
|
6178
|
-
* sees the new allowance.
|
|
6183
|
+
* sees the new allowance. Deposit retries pass their captured chain id so a
|
|
6184
|
+
* concurrent activation cannot redirect the approval to another network.
|
|
6179
6185
|
*
|
|
6180
6186
|
* @param requiredAmount Raw base-unit amount the pending deposit must cover.
|
|
6187
|
+
* @param expectedChainId Chain captured by the deposit that requested approval.
|
|
6181
6188
|
* @returns the approval transaction hash.
|
|
6182
6189
|
*/
|
|
6183
|
-
async approvePermit2(asset = "WETH", requiredAmount = 0n) {
|
|
6190
|
+
async approvePermit2(asset = "WETH", requiredAmount = 0n, expectedChainId) {
|
|
6184
6191
|
const state = this.requireState();
|
|
6185
|
-
const chainId = this.requireChainId();
|
|
6192
|
+
const chainId = expectedChainId ?? this.requireChainId();
|
|
6186
6193
|
this.getEligibleAgents(chainId, asset, { excludeDisabled: true });
|
|
6187
6194
|
const token = sponsoredTokensFor(asset)[chainId];
|
|
6188
6195
|
if (!token) {
|
|
@@ -6202,6 +6209,7 @@ var OwneySDK = class {
|
|
|
6202
6209
|
chain: VIEM_CHAIN2[chainId],
|
|
6203
6210
|
transport: (0, import_viem11.custom)(provider)
|
|
6204
6211
|
});
|
|
6212
|
+
await ensureWalletOnChain(publicClient, wallet, chainId);
|
|
6205
6213
|
const hash = await wallet.writeContract({
|
|
6206
6214
|
address: token,
|
|
6207
6215
|
abi: ERC20_ALLOWANCE_ABI,
|
|
@@ -6217,7 +6225,42 @@ var OwneySDK = class {
|
|
|
6217
6225
|
if (receipt.status !== "success") {
|
|
6218
6226
|
throw new Error(`Permit2 approval reverted (tx ${hash})`);
|
|
6219
6227
|
}
|
|
6220
|
-
|
|
6228
|
+
let observedAllowance = 0n;
|
|
6229
|
+
let verificationError;
|
|
6230
|
+
for (let attempt = 0; attempt < PERMIT2_ALLOWANCE_VERIFY_ATTEMPTS; attempt += 1) {
|
|
6231
|
+
try {
|
|
6232
|
+
observedAllowance = await readPermit2Allowance(
|
|
6233
|
+
publicClient,
|
|
6234
|
+
token,
|
|
6235
|
+
state.walletAddress,
|
|
6236
|
+
attempt === 0 ? receipt.blockNumber : void 0
|
|
6237
|
+
);
|
|
6238
|
+
verificationError = void 0;
|
|
6239
|
+
if (observedAllowance >= requiredAmount) return hash;
|
|
6240
|
+
} catch (error) {
|
|
6241
|
+
verificationError = error;
|
|
6242
|
+
}
|
|
6243
|
+
if (attempt + 1 < PERMIT2_ALLOWANCE_VERIFY_ATTEMPTS) {
|
|
6244
|
+
await new Promise(
|
|
6245
|
+
(resolve) => setTimeout(resolve, PERMIT2_ALLOWANCE_VERIFY_DELAY_MS)
|
|
6246
|
+
);
|
|
6247
|
+
}
|
|
6248
|
+
}
|
|
6249
|
+
throw new OwneyError(
|
|
6250
|
+
"PERMIT2_APPROVAL_REQUIRED",
|
|
6251
|
+
"Permit2 approval was confirmed, but the required token allowance was not observable.",
|
|
6252
|
+
{
|
|
6253
|
+
approvalConfirmed: true,
|
|
6254
|
+
approvalTxHash: hash,
|
|
6255
|
+
owner: state.walletAddress,
|
|
6256
|
+
token,
|
|
6257
|
+
spender: PERMIT2_ADDRESS,
|
|
6258
|
+
chainId,
|
|
6259
|
+
requiredAmount: requiredAmount.toString(),
|
|
6260
|
+
observedAllowance: observedAllowance.toString(),
|
|
6261
|
+
...verificationError instanceof Error ? { verificationError: verificationError.message } : {}
|
|
6262
|
+
}
|
|
6263
|
+
);
|
|
6221
6264
|
}
|
|
6222
6265
|
// --- Discovery (no wallet required) ---
|
|
6223
6266
|
/**
|
package/dist/index.d.cts
CHANGED
|
@@ -795,12 +795,14 @@ declare class OwneySDK {
|
|
|
795
795
|
* User-paid approval of Permit2 on the selected token for the active chain.
|
|
796
796
|
* Grants the maximum ERC20 allowance so later deposits do not require another
|
|
797
797
|
* approval. Resolves after one confirmation so the subsequent deposit attempt
|
|
798
|
-
* sees the new allowance.
|
|
798
|
+
* sees the new allowance. Deposit retries pass their captured chain id so a
|
|
799
|
+
* concurrent activation cannot redirect the approval to another network.
|
|
799
800
|
*
|
|
800
801
|
* @param requiredAmount Raw base-unit amount the pending deposit must cover.
|
|
802
|
+
* @param expectedChainId Chain captured by the deposit that requested approval.
|
|
801
803
|
* @returns the approval transaction hash.
|
|
802
804
|
*/
|
|
803
|
-
approvePermit2(asset?: OwneySupportedTokens, requiredAmount?: bigint): Promise<`0x${string}`>;
|
|
805
|
+
approvePermit2(asset?: OwneySupportedTokens, requiredAmount?: bigint, expectedChainId?: OwneySupportedChainId): Promise<`0x${string}`>;
|
|
804
806
|
/**
|
|
805
807
|
* Get the agent's average APY performance over a time period. Does not require a wallet connection.
|
|
806
808
|
* @param options - Contains agentId (optional) and days ("7D", "14D", or "30D")
|
package/dist/index.d.ts
CHANGED
|
@@ -795,12 +795,14 @@ declare class OwneySDK {
|
|
|
795
795
|
* User-paid approval of Permit2 on the selected token for the active chain.
|
|
796
796
|
* Grants the maximum ERC20 allowance so later deposits do not require another
|
|
797
797
|
* approval. Resolves after one confirmation so the subsequent deposit attempt
|
|
798
|
-
* sees the new allowance.
|
|
798
|
+
* sees the new allowance. Deposit retries pass their captured chain id so a
|
|
799
|
+
* concurrent activation cannot redirect the approval to another network.
|
|
799
800
|
*
|
|
800
801
|
* @param requiredAmount Raw base-unit amount the pending deposit must cover.
|
|
802
|
+
* @param expectedChainId Chain captured by the deposit that requested approval.
|
|
801
803
|
* @returns the approval transaction hash.
|
|
802
804
|
*/
|
|
803
|
-
approvePermit2(asset?: OwneySupportedTokens, requiredAmount?: bigint): Promise<`0x${string}`>;
|
|
805
|
+
approvePermit2(asset?: OwneySupportedTokens, requiredAmount?: bigint, expectedChainId?: OwneySupportedChainId): Promise<`0x${string}`>;
|
|
804
806
|
/**
|
|
805
807
|
* Get the agent's average APY performance over a time period. Does not require a wallet connection.
|
|
806
808
|
* @param options - Contains agentId (optional) and days ("7D", "14D", or "30D")
|
package/dist/index.js
CHANGED
|
@@ -2328,12 +2328,13 @@ function randomPermit2Nonce() {
|
|
|
2328
2328
|
globalThis.crypto.getRandomValues(bytes);
|
|
2329
2329
|
return BigInt(bytesToHex2(bytes));
|
|
2330
2330
|
}
|
|
2331
|
-
async function readPermit2Allowance(publicClient, token, owner) {
|
|
2331
|
+
async function readPermit2Allowance(publicClient, token, owner, blockNumber) {
|
|
2332
2332
|
return publicClient.readContract({
|
|
2333
2333
|
address: token,
|
|
2334
2334
|
abi: ERC20_ALLOWANCE_ABI,
|
|
2335
2335
|
functionName: "allowance",
|
|
2336
|
-
args: [owner, PERMIT2_ADDRESS]
|
|
2336
|
+
args: [owner, PERMIT2_ADDRESS],
|
|
2337
|
+
...blockNumber === void 0 ? {} : { blockNumber }
|
|
2337
2338
|
});
|
|
2338
2339
|
}
|
|
2339
2340
|
async function readErc20Balance(publicClient, token, owner) {
|
|
@@ -4701,6 +4702,8 @@ function makeSponsoredCallsCallback(deps) {
|
|
|
4701
4702
|
}
|
|
4702
4703
|
|
|
4703
4704
|
// src/client.ts
|
|
4705
|
+
var PERMIT2_ALLOWANCE_VERIFY_ATTEMPTS = 6;
|
|
4706
|
+
var PERMIT2_ALLOWANCE_VERIFY_DELAY_MS = 250;
|
|
4704
4707
|
function encodeMultiAgentCursor(map) {
|
|
4705
4708
|
return Buffer.from(JSON.stringify(map), "utf8").toString("base64");
|
|
4706
4709
|
}
|
|
@@ -5349,7 +5352,8 @@ var OwneySDK = class {
|
|
|
5349
5352
|
);
|
|
5350
5353
|
await this.approvePermit2(
|
|
5351
5354
|
asset,
|
|
5352
|
-
requiredAmount
|
|
5355
|
+
requiredAmount,
|
|
5356
|
+
cid
|
|
5353
5357
|
);
|
|
5354
5358
|
return batchTransfer(cid, transfers);
|
|
5355
5359
|
}
|
|
@@ -5439,7 +5443,8 @@ var OwneySDK = class {
|
|
|
5439
5443
|
);
|
|
5440
5444
|
await this.approvePermit2(
|
|
5441
5445
|
asset,
|
|
5442
|
-
BigInt(amount)
|
|
5446
|
+
BigInt(amount),
|
|
5447
|
+
chainId
|
|
5443
5448
|
);
|
|
5444
5449
|
continue;
|
|
5445
5450
|
}
|
|
@@ -6162,14 +6167,16 @@ var OwneySDK = class {
|
|
|
6162
6167
|
* User-paid approval of Permit2 on the selected token for the active chain.
|
|
6163
6168
|
* Grants the maximum ERC20 allowance so later deposits do not require another
|
|
6164
6169
|
* approval. Resolves after one confirmation so the subsequent deposit attempt
|
|
6165
|
-
* sees the new allowance.
|
|
6170
|
+
* sees the new allowance. Deposit retries pass their captured chain id so a
|
|
6171
|
+
* concurrent activation cannot redirect the approval to another network.
|
|
6166
6172
|
*
|
|
6167
6173
|
* @param requiredAmount Raw base-unit amount the pending deposit must cover.
|
|
6174
|
+
* @param expectedChainId Chain captured by the deposit that requested approval.
|
|
6168
6175
|
* @returns the approval transaction hash.
|
|
6169
6176
|
*/
|
|
6170
|
-
async approvePermit2(asset = "WETH", requiredAmount = 0n) {
|
|
6177
|
+
async approvePermit2(asset = "WETH", requiredAmount = 0n, expectedChainId) {
|
|
6171
6178
|
const state = this.requireState();
|
|
6172
|
-
const chainId = this.requireChainId();
|
|
6179
|
+
const chainId = expectedChainId ?? this.requireChainId();
|
|
6173
6180
|
this.getEligibleAgents(chainId, asset, { excludeDisabled: true });
|
|
6174
6181
|
const token = sponsoredTokensFor(asset)[chainId];
|
|
6175
6182
|
if (!token) {
|
|
@@ -6189,6 +6196,7 @@ var OwneySDK = class {
|
|
|
6189
6196
|
chain: VIEM_CHAIN2[chainId],
|
|
6190
6197
|
transport: custom3(provider)
|
|
6191
6198
|
});
|
|
6199
|
+
await ensureWalletOnChain(publicClient, wallet, chainId);
|
|
6192
6200
|
const hash = await wallet.writeContract({
|
|
6193
6201
|
address: token,
|
|
6194
6202
|
abi: ERC20_ALLOWANCE_ABI,
|
|
@@ -6204,7 +6212,42 @@ var OwneySDK = class {
|
|
|
6204
6212
|
if (receipt.status !== "success") {
|
|
6205
6213
|
throw new Error(`Permit2 approval reverted (tx ${hash})`);
|
|
6206
6214
|
}
|
|
6207
|
-
|
|
6215
|
+
let observedAllowance = 0n;
|
|
6216
|
+
let verificationError;
|
|
6217
|
+
for (let attempt = 0; attempt < PERMIT2_ALLOWANCE_VERIFY_ATTEMPTS; attempt += 1) {
|
|
6218
|
+
try {
|
|
6219
|
+
observedAllowance = await readPermit2Allowance(
|
|
6220
|
+
publicClient,
|
|
6221
|
+
token,
|
|
6222
|
+
state.walletAddress,
|
|
6223
|
+
attempt === 0 ? receipt.blockNumber : void 0
|
|
6224
|
+
);
|
|
6225
|
+
verificationError = void 0;
|
|
6226
|
+
if (observedAllowance >= requiredAmount) return hash;
|
|
6227
|
+
} catch (error) {
|
|
6228
|
+
verificationError = error;
|
|
6229
|
+
}
|
|
6230
|
+
if (attempt + 1 < PERMIT2_ALLOWANCE_VERIFY_ATTEMPTS) {
|
|
6231
|
+
await new Promise(
|
|
6232
|
+
(resolve) => setTimeout(resolve, PERMIT2_ALLOWANCE_VERIFY_DELAY_MS)
|
|
6233
|
+
);
|
|
6234
|
+
}
|
|
6235
|
+
}
|
|
6236
|
+
throw new OwneyError(
|
|
6237
|
+
"PERMIT2_APPROVAL_REQUIRED",
|
|
6238
|
+
"Permit2 approval was confirmed, but the required token allowance was not observable.",
|
|
6239
|
+
{
|
|
6240
|
+
approvalConfirmed: true,
|
|
6241
|
+
approvalTxHash: hash,
|
|
6242
|
+
owner: state.walletAddress,
|
|
6243
|
+
token,
|
|
6244
|
+
spender: PERMIT2_ADDRESS,
|
|
6245
|
+
chainId,
|
|
6246
|
+
requiredAmount: requiredAmount.toString(),
|
|
6247
|
+
observedAllowance: observedAllowance.toString(),
|
|
6248
|
+
...verificationError instanceof Error ? { verificationError: verificationError.message } : {}
|
|
6249
|
+
}
|
|
6250
|
+
);
|
|
6208
6251
|
}
|
|
6209
6252
|
// --- Discovery (no wallet required) ---
|
|
6210
6253
|
/**
|