@owney/sdk 0.7.22-beta.0 → 0.7.23-beta.0

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.
@@ -1,123 +0,0 @@
1
- import {
2
- SURFLIQUID_CHAIN_ID,
3
- SURFLIQUID_FACTORY_ABI,
4
- SURFLIQUID_FACTORY_ADDRESS,
5
- SURFLIQUID_USDC_ADDRESS,
6
- SURFLIQUID_VAULT_ABI,
7
- SubmittedError,
8
- USDC_ABI
9
- } from "./chunk-W3FYRJLJ.js";
10
- import {
11
- readTokenMeta
12
- } from "./chunk-5LU2SHO7.js";
13
-
14
- // src/agents/surfliquid/surfliquid.smart-account.ts
15
- import { createSmartAccountClient } from "permissionless";
16
- import { toSimpleSmartAccount } from "permissionless/accounts";
17
- import { createPimlicoClient } from "permissionless/clients/pimlico";
18
- import {
19
- createPublicClient,
20
- createWalletClient,
21
- custom,
22
- http
23
- } from "viem";
24
- import { entryPoint08Address } from "viem/account-abstraction";
25
- import { base } from "viem/chains";
26
- var sponsorProxyUrl = (routingApiBaseUrl) => `${routingApiBaseUrl.replace(/\/$/, "")}/api/v1/sponsor/pimlico-rpc/${SURFLIQUID_CHAIN_ID}`;
27
- function publicClientFor(rpcUrl) {
28
- return createPublicClient({ chain: base, transport: http(rpcUrl) });
29
- }
30
- function createSponsoredChain(rpcUrl) {
31
- const client = publicClientFor(rpcUrl);
32
- return {
33
- computeVaultAddress: (owner, salt) => client.readContract({
34
- address: SURFLIQUID_FACTORY_ADDRESS,
35
- abi: SURFLIQUID_FACTORY_ABI,
36
- functionName: "computeVaultAddress",
37
- args: [owner, salt]
38
- }),
39
- isDeployed: async (address) => {
40
- const code = await client.getCode({ address });
41
- return Boolean(code && code !== "0x");
42
- },
43
- readVaultOwner: (vault) => client.readContract({ address: vault, abi: SURFLIQUID_VAULT_ABI, functionName: "owner" }),
44
- hasInitialDeposit: (vault, asset) => client.readContract({
45
- address: vault,
46
- abi: SURFLIQUID_VAULT_ABI,
47
- functionName: "assetHasInitialDeposit",
48
- args: [asset]
49
- }),
50
- usdcBalanceOf: (address) => client.readContract({
51
- address: SURFLIQUID_USDC_ADDRESS,
52
- abi: USDC_ABI,
53
- functionName: "balanceOf",
54
- args: [address]
55
- }),
56
- // Cast: viem's OP-stack tx union does not match the generic PublicClient
57
- // the helper is typed against, though every method it uses is present.
58
- readTokenMeta: () => readTokenMeta(client, SURFLIQUID_USDC_ADDRESS)
59
- };
60
- }
61
- function pinAccount(provider, address) {
62
- return {
63
- ...provider,
64
- request: (args) => args.method === "eth_accounts" || args.method === "eth_requestAccounts" ? Promise.resolve([address]) : provider.request(args)
65
- };
66
- }
67
- async function createSponsoredWallet(input) {
68
- const entryPoint = { address: entryPoint08Address, version: "0.8" };
69
- const account = await toSimpleSmartAccount({
70
- client: publicClientFor(input.rpcUrl),
71
- owner: pinAccount(input.provider, input.ownerAddress),
72
- entryPoint
73
- });
74
- const bundlerTransport = http(sponsorProxyUrl(input.routingApiBaseUrl), {
75
- fetchOptions: { headers: { "x-owney-api-key": input.apiKey } }
76
- });
77
- const pimlico = createPimlicoClient({ transport: bundlerTransport, entryPoint });
78
- const smartAccountClient = createSmartAccountClient({
79
- account,
80
- chain: base,
81
- bundlerTransport,
82
- paymaster: pimlico,
83
- userOperation: {
84
- estimateFeesPerGas: async () => (await pimlico.getUserOperationGasPrice()).fast
85
- }
86
- });
87
- const walletClient = createWalletClient({
88
- account: input.ownerAddress,
89
- chain: base,
90
- transport: custom(input.provider)
91
- });
92
- return {
93
- smartAccountAddress: account.address,
94
- ownerAddress: input.ownerAddress,
95
- // The EOA signs, not the smart account: USDC verifies ECDSA from the token holder.
96
- signTransferAuthorization: (typedData) => walletClient.signTypedData({
97
- account: input.ownerAddress,
98
- domain: typedData.domain,
99
- types: typedData.types,
100
- primaryType: typedData.primaryType,
101
- message: typedData.message
102
- }),
103
- sendCalls: async (calls) => {
104
- const userOpHash = await smartAccountClient.sendUserOperation({
105
- calls: calls.map((c) => ({ to: c.to, data: c.data, value: 0n }))
106
- });
107
- try {
108
- const receipt = await smartAccountClient.waitForUserOperationReceipt({ hash: userOpHash });
109
- return receipt.receipt.transactionHash;
110
- } catch (error) {
111
- throw new SubmittedError(
112
- `user operation ${userOpHash} was submitted but its receipt never arrived`,
113
- userOpHash
114
- );
115
- }
116
- }
117
- };
118
- }
119
- export {
120
- createSponsoredChain,
121
- createSponsoredWallet,
122
- pinAccount
123
- };