@owney/sdk 0.7.21-beta.3 → 0.7.22-beta.1
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/README.md +0 -2
- package/dist/chunk-3HL52KM7.js +283 -0
- package/dist/chunk-AURO3C3R.js +58 -0
- package/dist/chunk-XBDJWZXY.js +141 -0
- package/dist/index.cjs +3702 -4259
- package/dist/index.d.cts +28 -128
- package/dist/index.d.ts +28 -128
- package/dist/index.js +694 -2574
- package/dist/surfliquid.agent-AE7RZ66F.js +638 -0
- package/dist/surfliquid.smart-account-C535356J.js +135 -0
- package/package.json +4 -2
|
@@ -0,0 +1,135 @@
|
|
|
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-3HL52KM7.js";
|
|
10
|
+
import {
|
|
11
|
+
readTokenMeta
|
|
12
|
+
} from "./chunk-AURO3C3R.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
|
+
readAllowance: (owner, spender) => client.readContract({
|
|
60
|
+
address: SURFLIQUID_USDC_ADDRESS,
|
|
61
|
+
abi: USDC_ABI,
|
|
62
|
+
functionName: "allowance",
|
|
63
|
+
args: [owner, spender]
|
|
64
|
+
}),
|
|
65
|
+
readPermitNonce: (owner) => client.readContract({
|
|
66
|
+
address: SURFLIQUID_USDC_ADDRESS,
|
|
67
|
+
abi: USDC_ABI,
|
|
68
|
+
functionName: "nonces",
|
|
69
|
+
args: [owner]
|
|
70
|
+
})
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function pinAccount(provider, address) {
|
|
74
|
+
return {
|
|
75
|
+
...provider,
|
|
76
|
+
request: (args) => args.method === "eth_accounts" || args.method === "eth_requestAccounts" ? Promise.resolve([address]) : provider.request(args)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
async function createSponsoredWallet(input) {
|
|
80
|
+
const entryPoint = { address: entryPoint08Address, version: "0.8" };
|
|
81
|
+
const account = await toSimpleSmartAccount({
|
|
82
|
+
client: publicClientFor(input.rpcUrl),
|
|
83
|
+
owner: pinAccount(input.provider, input.ownerAddress),
|
|
84
|
+
entryPoint
|
|
85
|
+
});
|
|
86
|
+
const bundlerTransport = http(sponsorProxyUrl(input.routingApiBaseUrl), {
|
|
87
|
+
fetchOptions: { headers: { "x-owney-api-key": input.apiKey } }
|
|
88
|
+
});
|
|
89
|
+
const pimlico = createPimlicoClient({ transport: bundlerTransport, entryPoint });
|
|
90
|
+
const smartAccountClient = createSmartAccountClient({
|
|
91
|
+
account,
|
|
92
|
+
chain: base,
|
|
93
|
+
bundlerTransport,
|
|
94
|
+
paymaster: pimlico,
|
|
95
|
+
userOperation: {
|
|
96
|
+
estimateFeesPerGas: async () => (await pimlico.getUserOperationGasPrice()).fast
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
const walletClient = createWalletClient({
|
|
100
|
+
account: input.ownerAddress,
|
|
101
|
+
chain: base,
|
|
102
|
+
transport: custom(input.provider)
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
smartAccountAddress: account.address,
|
|
106
|
+
ownerAddress: input.ownerAddress,
|
|
107
|
+
// The EOA signs, not the smart account: USDC verifies ECDSA from the token holder.
|
|
108
|
+
signPermit: (typedData) => walletClient.signTypedData({
|
|
109
|
+
account: input.ownerAddress,
|
|
110
|
+
domain: typedData.domain,
|
|
111
|
+
types: typedData.types,
|
|
112
|
+
primaryType: typedData.primaryType,
|
|
113
|
+
message: typedData.message
|
|
114
|
+
}),
|
|
115
|
+
sendCalls: async (calls) => {
|
|
116
|
+
const userOpHash = await smartAccountClient.sendUserOperation({
|
|
117
|
+
calls: calls.map((c) => ({ to: c.to, data: c.data, value: 0n }))
|
|
118
|
+
});
|
|
119
|
+
try {
|
|
120
|
+
const receipt = await smartAccountClient.waitForUserOperationReceipt({ hash: userOpHash });
|
|
121
|
+
return receipt.receipt.transactionHash;
|
|
122
|
+
} catch (error) {
|
|
123
|
+
throw new SubmittedError(
|
|
124
|
+
`user operation ${userOpHash} was submitted but its receipt never arrived`,
|
|
125
|
+
userOpHash
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
export {
|
|
132
|
+
createSponsoredChain,
|
|
133
|
+
createSponsoredWallet,
|
|
134
|
+
pinAccount
|
|
135
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owney/sdk",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.22-beta.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -20,10 +20,12 @@
|
|
|
20
20
|
"build": "tsup",
|
|
21
21
|
"dev": "tsup --watch",
|
|
22
22
|
"test": "vitest run",
|
|
23
|
-
"test:watch": "vitest"
|
|
23
|
+
"test:watch": "vitest",
|
|
24
|
+
"typecheck": "tsc -p tsconfig.test.json --noEmit"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
27
|
"@zyfai/sdk": "0.2.52",
|
|
28
|
+
"permissionless": "^0.4.0",
|
|
27
29
|
"siwe": "^3.0.0",
|
|
28
30
|
"viem": "^2.48.1"
|
|
29
31
|
},
|