@openfort/openfort-node 0.7.4 → 0.7.6
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/CHANGELOG.md +12 -0
- package/dist/index.d.mts +203 -189
- package/dist/index.d.ts +203 -189
- package/dist/index.js +34 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -47
- package/dist/index.mjs.map +1 -1
- package/openapi-auth.json +6 -0
- package/openapi.json +224 -417
- package/package.json +1 -1
- package/examples/exchange/createSwap.ts +0 -50
- package/examples/exchange/quoteSwap.ts +0 -34
package/package.json
CHANGED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// Usage: npx tsx exchange/createSwap.ts
|
|
2
|
-
|
|
3
|
-
import Openfort from "@openfort/openfort-node";
|
|
4
|
-
import "dotenv/config";
|
|
5
|
-
|
|
6
|
-
const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
|
|
7
|
-
basePath: process.env.OPENFORT_BASE_URL,
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const chainId = 84532; // Should be the chain which supports swaps
|
|
11
|
-
|
|
12
|
-
// Create an account (V1 legacy API)
|
|
13
|
-
const account = await openfort.accounts.v1.create({
|
|
14
|
-
chainId,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
// Create a policy for the swap
|
|
18
|
-
const policy = await openfort.policies.create({
|
|
19
|
-
name: `SwapPolicy-${Date.now()}`,
|
|
20
|
-
chainId,
|
|
21
|
-
strategy: {
|
|
22
|
-
sponsorSchema: "pay_for_user",
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
await openfort.policyRules.create({
|
|
27
|
-
type: "account_functions",
|
|
28
|
-
policy: policy.id,
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
console.log("Account address:", account.address);
|
|
32
|
-
console.log("Policy ID:", policy.id);
|
|
33
|
-
console.log("Account ID:", account.id);
|
|
34
|
-
|
|
35
|
-
// Create a swap transaction
|
|
36
|
-
// Note: Token addresses and amounts will vary by network
|
|
37
|
-
// The account must have sufficient balance for the swap
|
|
38
|
-
const swap = await openfort.exchange.createSwap({
|
|
39
|
-
fromAddress: account.id,
|
|
40
|
-
chainId,
|
|
41
|
-
tokenInAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", // Native token
|
|
42
|
-
tokenOutAddress: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174", // USDC
|
|
43
|
-
amount: "1000000000000000", // 0.001 native token
|
|
44
|
-
tradeType: "EXACT_INPUT",
|
|
45
|
-
policy: policy.id,
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
console.log("\nSwap created:");
|
|
49
|
-
console.log(" Transaction Intent ID:", swap.id);
|
|
50
|
-
console.log(" Status:", swap.response?.status || "pending");
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// Usage: npx tsx exchange/quoteSwap.ts
|
|
2
|
-
|
|
3
|
-
import Openfort from "@openfort/openfort-node";
|
|
4
|
-
import "dotenv/config";
|
|
5
|
-
|
|
6
|
-
const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
|
|
7
|
-
basePath: process.env.OPENFORT_BASE_URL,
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const chainId = Number(process.env.CHAIN_ID) || 80002;
|
|
11
|
-
|
|
12
|
-
// Create an account (V1 legacy API)
|
|
13
|
-
const account = await openfort.accounts.v1.create({
|
|
14
|
-
chainId,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
console.log("Account address:", account.address);
|
|
18
|
-
|
|
19
|
-
// Get a quote for swapping tokens
|
|
20
|
-
// Note: Token addresses and amounts will vary by network
|
|
21
|
-
const quote = await openfort.exchange.quoteSwap({
|
|
22
|
-
fromAddress: account.id,
|
|
23
|
-
chainId,
|
|
24
|
-
tokenInAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", // Native token (ETH/MATIC)
|
|
25
|
-
tokenOutAddress: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174", // USDC on Polygon
|
|
26
|
-
amount: "1000000000000000", // 0.001 native token
|
|
27
|
-
tradeType: "EXACT_INPUT",
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
console.log("\nSwap quote:");
|
|
31
|
-
console.log(" Amount:", quote.amount);
|
|
32
|
-
console.log(" Slippage:", quote.slippage);
|
|
33
|
-
console.log(" Estimated Gas Fee:", quote.estimatedTXGasFee);
|
|
34
|
-
console.log(" Estimated Gas Fee (USD):", quote.estimatedTXGasFeeUSD);
|