@owney/sdk 0.6.8-beta.2 → 0.6.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/index.cjs +102 -53
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +102 -53
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1523,6 +1523,84 @@ async function getSponsorRelayerAddress(input) {
|
|
|
1523
1523
|
return parsed.data.relayer;
|
|
1524
1524
|
}
|
|
1525
1525
|
|
|
1526
|
+
// src/lib/permit2.ts
|
|
1527
|
+
var import_viem4 = require("viem");
|
|
1528
|
+
var PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
1529
|
+
var MAX_UINT256 = 2n ** 256n - 1n;
|
|
1530
|
+
var ERC20_ALLOWANCE_ABI = [
|
|
1531
|
+
{
|
|
1532
|
+
type: "function",
|
|
1533
|
+
name: "allowance",
|
|
1534
|
+
stateMutability: "view",
|
|
1535
|
+
inputs: [
|
|
1536
|
+
{ name: "owner", type: "address" },
|
|
1537
|
+
{ name: "spender", type: "address" }
|
|
1538
|
+
],
|
|
1539
|
+
outputs: [{ name: "", type: "uint256" }]
|
|
1540
|
+
},
|
|
1541
|
+
{
|
|
1542
|
+
type: "function",
|
|
1543
|
+
name: "approve",
|
|
1544
|
+
stateMutability: "nonpayable",
|
|
1545
|
+
inputs: [
|
|
1546
|
+
{ name: "spender", type: "address" },
|
|
1547
|
+
{ name: "amount", type: "uint256" }
|
|
1548
|
+
],
|
|
1549
|
+
outputs: [{ name: "", type: "bool" }]
|
|
1550
|
+
},
|
|
1551
|
+
{
|
|
1552
|
+
type: "function",
|
|
1553
|
+
name: "balanceOf",
|
|
1554
|
+
stateMutability: "view",
|
|
1555
|
+
inputs: [{ name: "account", type: "address" }],
|
|
1556
|
+
outputs: [{ name: "", type: "uint256" }]
|
|
1557
|
+
}
|
|
1558
|
+
];
|
|
1559
|
+
function buildPermitTransferFromTypedData(input) {
|
|
1560
|
+
return {
|
|
1561
|
+
domain: {
|
|
1562
|
+
name: "Permit2",
|
|
1563
|
+
chainId: input.chainId,
|
|
1564
|
+
verifyingContract: PERMIT2_ADDRESS
|
|
1565
|
+
},
|
|
1566
|
+
types: {
|
|
1567
|
+
PermitTransferFrom: [
|
|
1568
|
+
{ name: "permitted", type: "TokenPermissions" },
|
|
1569
|
+
{ name: "spender", type: "address" },
|
|
1570
|
+
{ name: "nonce", type: "uint256" },
|
|
1571
|
+
{ name: "deadline", type: "uint256" }
|
|
1572
|
+
],
|
|
1573
|
+
TokenPermissions: [
|
|
1574
|
+
{ name: "token", type: "address" },
|
|
1575
|
+
{ name: "amount", type: "uint256" }
|
|
1576
|
+
]
|
|
1577
|
+
},
|
|
1578
|
+
primaryType: "PermitTransferFrom",
|
|
1579
|
+
message: input.message
|
|
1580
|
+
};
|
|
1581
|
+
}
|
|
1582
|
+
function randomPermit2Nonce() {
|
|
1583
|
+
const bytes = new Uint8Array(32);
|
|
1584
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
1585
|
+
return BigInt((0, import_viem4.bytesToHex)(bytes));
|
|
1586
|
+
}
|
|
1587
|
+
async function readPermit2Allowance(publicClient, token, owner) {
|
|
1588
|
+
return publicClient.readContract({
|
|
1589
|
+
address: token,
|
|
1590
|
+
abi: ERC20_ALLOWANCE_ABI,
|
|
1591
|
+
functionName: "allowance",
|
|
1592
|
+
args: [owner, PERMIT2_ADDRESS]
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1595
|
+
async function readErc20Balance(publicClient, token, owner) {
|
|
1596
|
+
return publicClient.readContract({
|
|
1597
|
+
address: token,
|
|
1598
|
+
abi: ERC20_ALLOWANCE_ABI,
|
|
1599
|
+
functionName: "balanceOf",
|
|
1600
|
+
args: [owner]
|
|
1601
|
+
});
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1526
1604
|
// src/lib/sponsored-deposit.ts
|
|
1527
1605
|
var AUTH_WINDOW_SECONDS = 15 * 60;
|
|
1528
1606
|
function makeSponsoredDepositCallback(deps) {
|
|
@@ -1538,6 +1616,18 @@ function makeSponsoredDepositCallback(deps) {
|
|
|
1538
1616
|
}
|
|
1539
1617
|
const pub = deps.getPublicClient(cid);
|
|
1540
1618
|
const wallet = deps.getWalletClient(cid);
|
|
1619
|
+
try {
|
|
1620
|
+
const balance = await readErc20Balance(pub, token, deps.ownerAddress);
|
|
1621
|
+
if (balance < BigInt(amount)) {
|
|
1622
|
+
throw new OwneyError(
|
|
1623
|
+
"DEPOSIT_INSUFFICIENT_BALANCE",
|
|
1624
|
+
"Insufficient balance for this deposit.",
|
|
1625
|
+
{ token, chainId: cid, balance: balance.toString(), amount }
|
|
1626
|
+
);
|
|
1627
|
+
}
|
|
1628
|
+
} catch (err) {
|
|
1629
|
+
if (err instanceof OwneyError) throw err;
|
|
1630
|
+
}
|
|
1541
1631
|
const { tokenName, tokenVersion } = await readTokenMeta(pub, token);
|
|
1542
1632
|
const validAfter = 0n;
|
|
1543
1633
|
const validBefore = BigInt(
|
|
@@ -1584,59 +1674,6 @@ function makeSponsoredDepositCallback(deps) {
|
|
|
1584
1674
|
};
|
|
1585
1675
|
}
|
|
1586
1676
|
|
|
1587
|
-
// src/lib/permit2.ts
|
|
1588
|
-
var import_viem4 = require("viem");
|
|
1589
|
-
var PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
1590
|
-
var MAX_UINT256 = 2n ** 256n - 1n;
|
|
1591
|
-
var ERC20_ALLOWANCE_ABI = [
|
|
1592
|
-
{
|
|
1593
|
-
type: "function",
|
|
1594
|
-
name: "allowance",
|
|
1595
|
-
stateMutability: "view",
|
|
1596
|
-
inputs: [{ name: "owner", type: "address" }, { name: "spender", type: "address" }],
|
|
1597
|
-
outputs: [{ name: "", type: "uint256" }]
|
|
1598
|
-
},
|
|
1599
|
-
{
|
|
1600
|
-
type: "function",
|
|
1601
|
-
name: "approve",
|
|
1602
|
-
stateMutability: "nonpayable",
|
|
1603
|
-
inputs: [{ name: "spender", type: "address" }, { name: "amount", type: "uint256" }],
|
|
1604
|
-
outputs: [{ name: "", type: "bool" }]
|
|
1605
|
-
}
|
|
1606
|
-
];
|
|
1607
|
-
function buildPermitTransferFromTypedData(input) {
|
|
1608
|
-
return {
|
|
1609
|
-
domain: { name: "Permit2", chainId: input.chainId, verifyingContract: PERMIT2_ADDRESS },
|
|
1610
|
-
types: {
|
|
1611
|
-
PermitTransferFrom: [
|
|
1612
|
-
{ name: "permitted", type: "TokenPermissions" },
|
|
1613
|
-
{ name: "spender", type: "address" },
|
|
1614
|
-
{ name: "nonce", type: "uint256" },
|
|
1615
|
-
{ name: "deadline", type: "uint256" }
|
|
1616
|
-
],
|
|
1617
|
-
TokenPermissions: [
|
|
1618
|
-
{ name: "token", type: "address" },
|
|
1619
|
-
{ name: "amount", type: "uint256" }
|
|
1620
|
-
]
|
|
1621
|
-
},
|
|
1622
|
-
primaryType: "PermitTransferFrom",
|
|
1623
|
-
message: input.message
|
|
1624
|
-
};
|
|
1625
|
-
}
|
|
1626
|
-
function randomPermit2Nonce() {
|
|
1627
|
-
const bytes = new Uint8Array(32);
|
|
1628
|
-
globalThis.crypto.getRandomValues(bytes);
|
|
1629
|
-
return BigInt((0, import_viem4.bytesToHex)(bytes));
|
|
1630
|
-
}
|
|
1631
|
-
async function readPermit2Allowance(publicClient, token, owner) {
|
|
1632
|
-
return publicClient.readContract({
|
|
1633
|
-
address: token,
|
|
1634
|
-
abi: ERC20_ALLOWANCE_ABI,
|
|
1635
|
-
functionName: "allowance",
|
|
1636
|
-
args: [owner, PERMIT2_ADDRESS]
|
|
1637
|
-
});
|
|
1638
|
-
}
|
|
1639
|
-
|
|
1640
1677
|
// src/lib/sponsored-weth-deposit.ts
|
|
1641
1678
|
var PERMIT_WINDOW_SECONDS = 15 * 60;
|
|
1642
1679
|
function makeSponsoredWethCallback(deps) {
|
|
@@ -1653,6 +1690,18 @@ function makeSponsoredWethCallback(deps) {
|
|
|
1653
1690
|
}
|
|
1654
1691
|
const amountWei = BigInt(amount);
|
|
1655
1692
|
const pub = deps.getPublicClient(cid);
|
|
1693
|
+
try {
|
|
1694
|
+
const balance = await readErc20Balance(pub, token, deps.ownerAddress);
|
|
1695
|
+
if (balance < amountWei) {
|
|
1696
|
+
throw new OwneyError(
|
|
1697
|
+
"DEPOSIT_INSUFFICIENT_BALANCE",
|
|
1698
|
+
"Insufficient WETH balance for this deposit.",
|
|
1699
|
+
{ token, chainId: cid, balance: balance.toString(), amount }
|
|
1700
|
+
);
|
|
1701
|
+
}
|
|
1702
|
+
} catch (err) {
|
|
1703
|
+
if (err instanceof OwneyError) throw err;
|
|
1704
|
+
}
|
|
1656
1705
|
const allowance = await readPermit2Allowance(pub, token, deps.ownerAddress);
|
|
1657
1706
|
if (allowance < amountWei) {
|
|
1658
1707
|
throw new OwneyError(
|
package/dist/index.d.cts
CHANGED
|
@@ -525,7 +525,7 @@ declare class OwneySDK {
|
|
|
525
525
|
getAllocationApy({ agentId, }?: AllocationApyOptions): Promise<OwneyAllocationApy>;
|
|
526
526
|
}
|
|
527
527
|
|
|
528
|
-
type OwneyErrorCode = "NOT_CONNECTED" | "NO_ACTIVE_CHAIN" | "WALLET_NO_ACCOUNTS" | "WALLET_ADDRESS_REQUIRED" | "AGENT_NOT_FOUND" | "AGENT_CHAIN_INCOMPATIBLE" | "AGENT_EMPTY_LIST" | "AGENT_DISABLED" | "CHAIN_UNSUPPORTED" | "CHAIN_NO_COMPATIBLE_AGENTS" | "ASSET_UNSUPPORTED" | "ASSET_NO_COMPATIBLE_AGENTS" | "DEPOSIT_AMOUNT_BELOW_MINIMUM" | "DEPOSIT_CALLBACK_REQUIRED" | "DEPOSIT_CALLBACK_INVALID" | "DEPOSIT_NO_PERMITTED_TOKENS" | "WITHDRAW_NO_PERMITTED_TOKENS" | "WITHDRAW_INSUFFICIENT_BALANCE" | "WITHDRAW_ALL_FAILED" | "WITHDRAW_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_SAIL_ERROR" | "API_SAIL_TIMEOUT" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "PERMIT2_APPROVAL_REQUIRED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
|
|
528
|
+
type OwneyErrorCode = "NOT_CONNECTED" | "NO_ACTIVE_CHAIN" | "WALLET_NO_ACCOUNTS" | "WALLET_ADDRESS_REQUIRED" | "AGENT_NOT_FOUND" | "AGENT_CHAIN_INCOMPATIBLE" | "AGENT_EMPTY_LIST" | "AGENT_DISABLED" | "CHAIN_UNSUPPORTED" | "CHAIN_NO_COMPATIBLE_AGENTS" | "ASSET_UNSUPPORTED" | "ASSET_NO_COMPATIBLE_AGENTS" | "DEPOSIT_AMOUNT_BELOW_MINIMUM" | "DEPOSIT_CALLBACK_REQUIRED" | "DEPOSIT_CALLBACK_INVALID" | "DEPOSIT_NO_PERMITTED_TOKENS" | "DEPOSIT_INSUFFICIENT_BALANCE" | "WITHDRAW_NO_PERMITTED_TOKENS" | "WITHDRAW_INSUFFICIENT_BALANCE" | "WITHDRAW_ALL_FAILED" | "WITHDRAW_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_SAIL_ERROR" | "API_SAIL_TIMEOUT" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "PERMIT2_APPROVAL_REQUIRED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
|
|
529
529
|
declare class OwneyError extends Error {
|
|
530
530
|
readonly code: OwneyErrorCode;
|
|
531
531
|
readonly details?: Record<string, unknown>;
|
package/dist/index.d.ts
CHANGED
|
@@ -525,7 +525,7 @@ declare class OwneySDK {
|
|
|
525
525
|
getAllocationApy({ agentId, }?: AllocationApyOptions): Promise<OwneyAllocationApy>;
|
|
526
526
|
}
|
|
527
527
|
|
|
528
|
-
type OwneyErrorCode = "NOT_CONNECTED" | "NO_ACTIVE_CHAIN" | "WALLET_NO_ACCOUNTS" | "WALLET_ADDRESS_REQUIRED" | "AGENT_NOT_FOUND" | "AGENT_CHAIN_INCOMPATIBLE" | "AGENT_EMPTY_LIST" | "AGENT_DISABLED" | "CHAIN_UNSUPPORTED" | "CHAIN_NO_COMPATIBLE_AGENTS" | "ASSET_UNSUPPORTED" | "ASSET_NO_COMPATIBLE_AGENTS" | "DEPOSIT_AMOUNT_BELOW_MINIMUM" | "DEPOSIT_CALLBACK_REQUIRED" | "DEPOSIT_CALLBACK_INVALID" | "DEPOSIT_NO_PERMITTED_TOKENS" | "WITHDRAW_NO_PERMITTED_TOKENS" | "WITHDRAW_INSUFFICIENT_BALANCE" | "WITHDRAW_ALL_FAILED" | "WITHDRAW_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_SAIL_ERROR" | "API_SAIL_TIMEOUT" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "PERMIT2_APPROVAL_REQUIRED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
|
|
528
|
+
type OwneyErrorCode = "NOT_CONNECTED" | "NO_ACTIVE_CHAIN" | "WALLET_NO_ACCOUNTS" | "WALLET_ADDRESS_REQUIRED" | "AGENT_NOT_FOUND" | "AGENT_CHAIN_INCOMPATIBLE" | "AGENT_EMPTY_LIST" | "AGENT_DISABLED" | "CHAIN_UNSUPPORTED" | "CHAIN_NO_COMPATIBLE_AGENTS" | "ASSET_UNSUPPORTED" | "ASSET_NO_COMPATIBLE_AGENTS" | "DEPOSIT_AMOUNT_BELOW_MINIMUM" | "DEPOSIT_CALLBACK_REQUIRED" | "DEPOSIT_CALLBACK_INVALID" | "DEPOSIT_NO_PERMITTED_TOKENS" | "DEPOSIT_INSUFFICIENT_BALANCE" | "WITHDRAW_NO_PERMITTED_TOKENS" | "WITHDRAW_INSUFFICIENT_BALANCE" | "WITHDRAW_ALL_FAILED" | "WITHDRAW_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_SAIL_ERROR" | "API_SAIL_TIMEOUT" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "PERMIT2_APPROVAL_REQUIRED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
|
|
529
529
|
declare class OwneyError extends Error {
|
|
530
530
|
readonly code: OwneyErrorCode;
|
|
531
531
|
readonly details?: Record<string, unknown>;
|
package/dist/index.js
CHANGED
|
@@ -1495,6 +1495,84 @@ async function getSponsorRelayerAddress(input) {
|
|
|
1495
1495
|
return parsed.data.relayer;
|
|
1496
1496
|
}
|
|
1497
1497
|
|
|
1498
|
+
// src/lib/permit2.ts
|
|
1499
|
+
import { bytesToHex as bytesToHex2 } from "viem";
|
|
1500
|
+
var PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
1501
|
+
var MAX_UINT256 = 2n ** 256n - 1n;
|
|
1502
|
+
var ERC20_ALLOWANCE_ABI = [
|
|
1503
|
+
{
|
|
1504
|
+
type: "function",
|
|
1505
|
+
name: "allowance",
|
|
1506
|
+
stateMutability: "view",
|
|
1507
|
+
inputs: [
|
|
1508
|
+
{ name: "owner", type: "address" },
|
|
1509
|
+
{ name: "spender", type: "address" }
|
|
1510
|
+
],
|
|
1511
|
+
outputs: [{ name: "", type: "uint256" }]
|
|
1512
|
+
},
|
|
1513
|
+
{
|
|
1514
|
+
type: "function",
|
|
1515
|
+
name: "approve",
|
|
1516
|
+
stateMutability: "nonpayable",
|
|
1517
|
+
inputs: [
|
|
1518
|
+
{ name: "spender", type: "address" },
|
|
1519
|
+
{ name: "amount", type: "uint256" }
|
|
1520
|
+
],
|
|
1521
|
+
outputs: [{ name: "", type: "bool" }]
|
|
1522
|
+
},
|
|
1523
|
+
{
|
|
1524
|
+
type: "function",
|
|
1525
|
+
name: "balanceOf",
|
|
1526
|
+
stateMutability: "view",
|
|
1527
|
+
inputs: [{ name: "account", type: "address" }],
|
|
1528
|
+
outputs: [{ name: "", type: "uint256" }]
|
|
1529
|
+
}
|
|
1530
|
+
];
|
|
1531
|
+
function buildPermitTransferFromTypedData(input) {
|
|
1532
|
+
return {
|
|
1533
|
+
domain: {
|
|
1534
|
+
name: "Permit2",
|
|
1535
|
+
chainId: input.chainId,
|
|
1536
|
+
verifyingContract: PERMIT2_ADDRESS
|
|
1537
|
+
},
|
|
1538
|
+
types: {
|
|
1539
|
+
PermitTransferFrom: [
|
|
1540
|
+
{ name: "permitted", type: "TokenPermissions" },
|
|
1541
|
+
{ name: "spender", type: "address" },
|
|
1542
|
+
{ name: "nonce", type: "uint256" },
|
|
1543
|
+
{ name: "deadline", type: "uint256" }
|
|
1544
|
+
],
|
|
1545
|
+
TokenPermissions: [
|
|
1546
|
+
{ name: "token", type: "address" },
|
|
1547
|
+
{ name: "amount", type: "uint256" }
|
|
1548
|
+
]
|
|
1549
|
+
},
|
|
1550
|
+
primaryType: "PermitTransferFrom",
|
|
1551
|
+
message: input.message
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1554
|
+
function randomPermit2Nonce() {
|
|
1555
|
+
const bytes = new Uint8Array(32);
|
|
1556
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
1557
|
+
return BigInt(bytesToHex2(bytes));
|
|
1558
|
+
}
|
|
1559
|
+
async function readPermit2Allowance(publicClient, token, owner) {
|
|
1560
|
+
return publicClient.readContract({
|
|
1561
|
+
address: token,
|
|
1562
|
+
abi: ERC20_ALLOWANCE_ABI,
|
|
1563
|
+
functionName: "allowance",
|
|
1564
|
+
args: [owner, PERMIT2_ADDRESS]
|
|
1565
|
+
});
|
|
1566
|
+
}
|
|
1567
|
+
async function readErc20Balance(publicClient, token, owner) {
|
|
1568
|
+
return publicClient.readContract({
|
|
1569
|
+
address: token,
|
|
1570
|
+
abi: ERC20_ALLOWANCE_ABI,
|
|
1571
|
+
functionName: "balanceOf",
|
|
1572
|
+
args: [owner]
|
|
1573
|
+
});
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1498
1576
|
// src/lib/sponsored-deposit.ts
|
|
1499
1577
|
var AUTH_WINDOW_SECONDS = 15 * 60;
|
|
1500
1578
|
function makeSponsoredDepositCallback(deps) {
|
|
@@ -1510,6 +1588,18 @@ function makeSponsoredDepositCallback(deps) {
|
|
|
1510
1588
|
}
|
|
1511
1589
|
const pub = deps.getPublicClient(cid);
|
|
1512
1590
|
const wallet = deps.getWalletClient(cid);
|
|
1591
|
+
try {
|
|
1592
|
+
const balance = await readErc20Balance(pub, token, deps.ownerAddress);
|
|
1593
|
+
if (balance < BigInt(amount)) {
|
|
1594
|
+
throw new OwneyError(
|
|
1595
|
+
"DEPOSIT_INSUFFICIENT_BALANCE",
|
|
1596
|
+
"Insufficient balance for this deposit.",
|
|
1597
|
+
{ token, chainId: cid, balance: balance.toString(), amount }
|
|
1598
|
+
);
|
|
1599
|
+
}
|
|
1600
|
+
} catch (err) {
|
|
1601
|
+
if (err instanceof OwneyError) throw err;
|
|
1602
|
+
}
|
|
1513
1603
|
const { tokenName, tokenVersion } = await readTokenMeta(pub, token);
|
|
1514
1604
|
const validAfter = 0n;
|
|
1515
1605
|
const validBefore = BigInt(
|
|
@@ -1556,59 +1646,6 @@ function makeSponsoredDepositCallback(deps) {
|
|
|
1556
1646
|
};
|
|
1557
1647
|
}
|
|
1558
1648
|
|
|
1559
|
-
// src/lib/permit2.ts
|
|
1560
|
-
import { bytesToHex as bytesToHex2 } from "viem";
|
|
1561
|
-
var PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
1562
|
-
var MAX_UINT256 = 2n ** 256n - 1n;
|
|
1563
|
-
var ERC20_ALLOWANCE_ABI = [
|
|
1564
|
-
{
|
|
1565
|
-
type: "function",
|
|
1566
|
-
name: "allowance",
|
|
1567
|
-
stateMutability: "view",
|
|
1568
|
-
inputs: [{ name: "owner", type: "address" }, { name: "spender", type: "address" }],
|
|
1569
|
-
outputs: [{ name: "", type: "uint256" }]
|
|
1570
|
-
},
|
|
1571
|
-
{
|
|
1572
|
-
type: "function",
|
|
1573
|
-
name: "approve",
|
|
1574
|
-
stateMutability: "nonpayable",
|
|
1575
|
-
inputs: [{ name: "spender", type: "address" }, { name: "amount", type: "uint256" }],
|
|
1576
|
-
outputs: [{ name: "", type: "bool" }]
|
|
1577
|
-
}
|
|
1578
|
-
];
|
|
1579
|
-
function buildPermitTransferFromTypedData(input) {
|
|
1580
|
-
return {
|
|
1581
|
-
domain: { name: "Permit2", chainId: input.chainId, verifyingContract: PERMIT2_ADDRESS },
|
|
1582
|
-
types: {
|
|
1583
|
-
PermitTransferFrom: [
|
|
1584
|
-
{ name: "permitted", type: "TokenPermissions" },
|
|
1585
|
-
{ name: "spender", type: "address" },
|
|
1586
|
-
{ name: "nonce", type: "uint256" },
|
|
1587
|
-
{ name: "deadline", type: "uint256" }
|
|
1588
|
-
],
|
|
1589
|
-
TokenPermissions: [
|
|
1590
|
-
{ name: "token", type: "address" },
|
|
1591
|
-
{ name: "amount", type: "uint256" }
|
|
1592
|
-
]
|
|
1593
|
-
},
|
|
1594
|
-
primaryType: "PermitTransferFrom",
|
|
1595
|
-
message: input.message
|
|
1596
|
-
};
|
|
1597
|
-
}
|
|
1598
|
-
function randomPermit2Nonce() {
|
|
1599
|
-
const bytes = new Uint8Array(32);
|
|
1600
|
-
globalThis.crypto.getRandomValues(bytes);
|
|
1601
|
-
return BigInt(bytesToHex2(bytes));
|
|
1602
|
-
}
|
|
1603
|
-
async function readPermit2Allowance(publicClient, token, owner) {
|
|
1604
|
-
return publicClient.readContract({
|
|
1605
|
-
address: token,
|
|
1606
|
-
abi: ERC20_ALLOWANCE_ABI,
|
|
1607
|
-
functionName: "allowance",
|
|
1608
|
-
args: [owner, PERMIT2_ADDRESS]
|
|
1609
|
-
});
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
1649
|
// src/lib/sponsored-weth-deposit.ts
|
|
1613
1650
|
var PERMIT_WINDOW_SECONDS = 15 * 60;
|
|
1614
1651
|
function makeSponsoredWethCallback(deps) {
|
|
@@ -1625,6 +1662,18 @@ function makeSponsoredWethCallback(deps) {
|
|
|
1625
1662
|
}
|
|
1626
1663
|
const amountWei = BigInt(amount);
|
|
1627
1664
|
const pub = deps.getPublicClient(cid);
|
|
1665
|
+
try {
|
|
1666
|
+
const balance = await readErc20Balance(pub, token, deps.ownerAddress);
|
|
1667
|
+
if (balance < amountWei) {
|
|
1668
|
+
throw new OwneyError(
|
|
1669
|
+
"DEPOSIT_INSUFFICIENT_BALANCE",
|
|
1670
|
+
"Insufficient WETH balance for this deposit.",
|
|
1671
|
+
{ token, chainId: cid, balance: balance.toString(), amount }
|
|
1672
|
+
);
|
|
1673
|
+
}
|
|
1674
|
+
} catch (err) {
|
|
1675
|
+
if (err instanceof OwneyError) throw err;
|
|
1676
|
+
}
|
|
1628
1677
|
const allowance = await readPermit2Allowance(pub, token, deps.ownerAddress);
|
|
1629
1678
|
if (allowance < amountWei) {
|
|
1630
1679
|
throw new OwneyError(
|