@owney/sdk 0.7.8 → 0.7.10-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.
- package/dist/chunk-PWIKIQOX.js +140 -0
- package/dist/index.cjs +906 -214
- package/dist/index.d.cts +30 -2
- package/dist/index.d.ts +30 -2
- package/dist/index.js +225 -190
- package/dist/surfliquid.agent-VNGQUSXN.js +473 -0
- package/package.json +3 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var OwneyError = class extends Error {
|
|
3
|
+
code;
|
|
4
|
+
details;
|
|
5
|
+
agentId;
|
|
6
|
+
constructor(code, message, details, agentId) {
|
|
7
|
+
const prefix = agentId ? `[${code}][agent:${agentId}]` : `[${code}]`;
|
|
8
|
+
super(`${prefix} ${message}`);
|
|
9
|
+
this.name = "OwneyError";
|
|
10
|
+
this.code = code;
|
|
11
|
+
this.details = details;
|
|
12
|
+
this.agentId = agentId;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var AgentNotFoundError = class extends OwneyError {
|
|
16
|
+
constructor(agentId, available) {
|
|
17
|
+
super(
|
|
18
|
+
"AGENT_NOT_FOUND",
|
|
19
|
+
`Unknown agent "${agentId}". Available agents: ${available.join(", ")}`,
|
|
20
|
+
{ agentId, available },
|
|
21
|
+
agentId
|
|
22
|
+
);
|
|
23
|
+
this.name = "AgentNotFoundError";
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var NotConnectedError = class extends OwneyError {
|
|
27
|
+
constructor() {
|
|
28
|
+
super("NOT_CONNECTED", "Not connected. Call sdk.connect(provider) first.");
|
|
29
|
+
this.name = "NotConnectedError";
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var AgentChainIncompatibleError = class extends OwneyError {
|
|
33
|
+
incompatibleAgents;
|
|
34
|
+
connectedChainId;
|
|
35
|
+
constructor(incompatibleAgents, connectedChainId) {
|
|
36
|
+
const details = incompatibleAgents.map(
|
|
37
|
+
({ agentId, supportedChainIds }) => `"${agentId}" supports chains [${supportedChainIds.join(", ")}]`
|
|
38
|
+
).join("; ");
|
|
39
|
+
super(
|
|
40
|
+
"AGENT_CHAIN_INCOMPATIBLE",
|
|
41
|
+
`Chain ${connectedChainId} is not supported by the following agents: ${details}`,
|
|
42
|
+
{ incompatibleAgents, connectedChainId }
|
|
43
|
+
);
|
|
44
|
+
this.name = "AgentChainIncompatibleError";
|
|
45
|
+
this.incompatibleAgents = incompatibleAgents;
|
|
46
|
+
this.connectedChainId = connectedChainId;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/lib/permit2.ts
|
|
51
|
+
import { bytesToHex } from "viem";
|
|
52
|
+
var PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
53
|
+
var MAX_UINT256 = 2n ** 256n - 1n;
|
|
54
|
+
var ERC20_ALLOWANCE_ABI = [
|
|
55
|
+
{
|
|
56
|
+
type: "function",
|
|
57
|
+
name: "allowance",
|
|
58
|
+
stateMutability: "view",
|
|
59
|
+
inputs: [
|
|
60
|
+
{ name: "owner", type: "address" },
|
|
61
|
+
{ name: "spender", type: "address" }
|
|
62
|
+
],
|
|
63
|
+
outputs: [{ name: "", type: "uint256" }]
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
type: "function",
|
|
67
|
+
name: "approve",
|
|
68
|
+
stateMutability: "nonpayable",
|
|
69
|
+
inputs: [
|
|
70
|
+
{ name: "spender", type: "address" },
|
|
71
|
+
{ name: "amount", type: "uint256" }
|
|
72
|
+
],
|
|
73
|
+
outputs: [{ name: "", type: "bool" }]
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
type: "function",
|
|
77
|
+
name: "balanceOf",
|
|
78
|
+
stateMutability: "view",
|
|
79
|
+
inputs: [{ name: "account", type: "address" }],
|
|
80
|
+
outputs: [{ name: "", type: "uint256" }]
|
|
81
|
+
}
|
|
82
|
+
];
|
|
83
|
+
function buildPermitTransferFromTypedData(input) {
|
|
84
|
+
return {
|
|
85
|
+
domain: {
|
|
86
|
+
name: "Permit2",
|
|
87
|
+
chainId: input.chainId,
|
|
88
|
+
verifyingContract: PERMIT2_ADDRESS
|
|
89
|
+
},
|
|
90
|
+
types: {
|
|
91
|
+
PermitTransferFrom: [
|
|
92
|
+
{ name: "permitted", type: "TokenPermissions" },
|
|
93
|
+
{ name: "spender", type: "address" },
|
|
94
|
+
{ name: "nonce", type: "uint256" },
|
|
95
|
+
{ name: "deadline", type: "uint256" }
|
|
96
|
+
],
|
|
97
|
+
TokenPermissions: [
|
|
98
|
+
{ name: "token", type: "address" },
|
|
99
|
+
{ name: "amount", type: "uint256" }
|
|
100
|
+
]
|
|
101
|
+
},
|
|
102
|
+
primaryType: "PermitTransferFrom",
|
|
103
|
+
message: input.message
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function randomPermit2Nonce() {
|
|
107
|
+
const bytes = new Uint8Array(32);
|
|
108
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
109
|
+
return BigInt(bytesToHex(bytes));
|
|
110
|
+
}
|
|
111
|
+
async function readPermit2Allowance(publicClient, token, owner) {
|
|
112
|
+
return publicClient.readContract({
|
|
113
|
+
address: token,
|
|
114
|
+
abi: ERC20_ALLOWANCE_ABI,
|
|
115
|
+
functionName: "allowance",
|
|
116
|
+
args: [owner, PERMIT2_ADDRESS]
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
async function readErc20Balance(publicClient, token, owner) {
|
|
120
|
+
return publicClient.readContract({
|
|
121
|
+
address: token,
|
|
122
|
+
abi: ERC20_ALLOWANCE_ABI,
|
|
123
|
+
functionName: "balanceOf",
|
|
124
|
+
args: [owner]
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export {
|
|
129
|
+
OwneyError,
|
|
130
|
+
AgentNotFoundError,
|
|
131
|
+
NotConnectedError,
|
|
132
|
+
AgentChainIncompatibleError,
|
|
133
|
+
PERMIT2_ADDRESS,
|
|
134
|
+
MAX_UINT256,
|
|
135
|
+
ERC20_ALLOWANCE_ABI,
|
|
136
|
+
buildPermitTransferFromTypedData,
|
|
137
|
+
randomPermit2Nonce,
|
|
138
|
+
readPermit2Allowance,
|
|
139
|
+
readErc20Balance
|
|
140
|
+
};
|