@stablecoin.xyz/swap-intent 0.1.0 → 0.1.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/dist/index.js +23 -12
- package/dist/types/mcp/shared/spl.d.ts +5 -0
- package/package.json +3 -4
package/dist/index.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
// ../../mcp/shared/intent-check.ts
|
|
2
2
|
import { formatUnits, getAddress as getAddress2, toHex } from "viem";
|
|
3
|
-
import { PublicKey as
|
|
4
|
-
import { ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync } from "@solana/spl-token";
|
|
3
|
+
import { PublicKey as PublicKey4 } from "@solana/web3.js";
|
|
5
4
|
|
|
6
|
-
// ../../
|
|
5
|
+
// ../../mcp/shared/spl.ts
|
|
7
6
|
import { PublicKey } from "@solana/web3.js";
|
|
7
|
+
var TOKEN_PROGRAM_ID = new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
|
|
8
|
+
var TOKEN_2022_PROGRAM_ID = new PublicKey("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
|
|
9
|
+
var ASSOCIATED_TOKEN_PROGRAM_ID = new PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
|
|
10
|
+
function getAssociatedTokenAddressSync(mint, owner, programId = TOKEN_PROGRAM_ID) {
|
|
11
|
+
return PublicKey.findProgramAddressSync([owner.toBuffer(), programId.toBuffer(), mint.toBuffer()], ASSOCIATED_TOKEN_PROGRAM_ID)[0];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// ../../engine/svm.js
|
|
15
|
+
import { PublicKey as PublicKey2 } from "@solana/web3.js";
|
|
8
16
|
import { getAddress } from "viem";
|
|
9
17
|
var SETTLE_DISC = {
|
|
10
18
|
open: Buffer.from([228, 220, 155, 71, 199, 189, 60, 45]),
|
|
@@ -86,8 +94,7 @@ function hydrateTypedData(td) {
|
|
|
86
94
|
}
|
|
87
95
|
|
|
88
96
|
// ../../mcp/shared/sol-decode.ts
|
|
89
|
-
import { ComputeBudgetProgram, PublicKey as
|
|
90
|
-
import { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
|
97
|
+
import { ComputeBudgetProgram, PublicKey as PublicKey3, SystemProgram, VersionedTransaction } from "@solana/web3.js";
|
|
91
98
|
var TOKEN_PROGRAMS = /* @__PURE__ */ new Set([TOKEN_PROGRAM_ID.toBase58(), TOKEN_2022_PROGRAM_ID.toBase58()]);
|
|
92
99
|
var SYSTEM = SystemProgram.programId.toBase58();
|
|
93
100
|
var COMPUTE_BUDGET = ComputeBudgetProgram.programId.toBase58();
|
|
@@ -120,7 +127,7 @@ function decodeIx(program, accounts, data, signers) {
|
|
|
120
127
|
inputMint: accounts[1],
|
|
121
128
|
userAta: accounts[3],
|
|
122
129
|
tokenProgram: accounts[6],
|
|
123
|
-
solver: new
|
|
130
|
+
solver: new PublicKey3(data.subarray(40, 72)).toBase58(),
|
|
124
131
|
inputAmount: u64(data, 72),
|
|
125
132
|
outputToken: "0x" + hex(data.subarray(80, 112)),
|
|
126
133
|
outputAmount: u64(data, 112) + (u64(data, 120) << 64n),
|
|
@@ -215,7 +222,7 @@ function userInstructions(s, me) {
|
|
|
215
222
|
}
|
|
216
223
|
var sourceChain = (req) => req.kind === "sol-tx" ? "solana" : req.chain;
|
|
217
224
|
function ata(mint, owner, program) {
|
|
218
|
-
return getAssociatedTokenAddressSync(new
|
|
225
|
+
return getAssociatedTokenAddressSync(new PublicKey4(mint), new PublicKey4(owner), new PublicKey4(program)).toBase58();
|
|
219
226
|
}
|
|
220
227
|
function quotedOutOf(req) {
|
|
221
228
|
try {
|
|
@@ -259,7 +266,7 @@ function evmChecks(p, e) {
|
|
|
259
266
|
if (e.recipientVm === "svm") {
|
|
260
267
|
need(e.destinationChainId === BigInt(m.solana.dstChainId), "wrong-chain");
|
|
261
268
|
const outT = token(req.net, req.outSym, "solana");
|
|
262
|
-
need(outT?.mint && e.outputToken === toHex(new
|
|
269
|
+
need(outT?.mint && e.outputToken === toHex(new PublicKey4(outT.mint).toBytes()), "unknown-token");
|
|
263
270
|
outDec = outT.decimals;
|
|
264
271
|
destChain = "solana";
|
|
265
272
|
} else {
|
|
@@ -357,7 +364,7 @@ function checkIntent(p) {
|
|
|
357
364
|
|
|
358
365
|
// ../../mcp/shared/evm-decode.ts
|
|
359
366
|
import { decodeAbiParameters, decodeFunctionData, getAddress as getAddress4, hexToBytes } from "viem";
|
|
360
|
-
import { PublicKey as
|
|
367
|
+
import { PublicKey as PublicKey5 } from "@solana/web3.js";
|
|
361
368
|
|
|
362
369
|
// ../../ui-app/src/core/evm.ts
|
|
363
370
|
var PERMIT_TYPES = {
|
|
@@ -535,7 +542,7 @@ function decodeTxs(req) {
|
|
|
535
542
|
target: escrow,
|
|
536
543
|
inputToken: addr(od.inputToken),
|
|
537
544
|
inputAmount: BigInt(od.inputAmount),
|
|
538
|
-
recipient: toSolana ? new
|
|
545
|
+
recipient: toSolana ? new PublicKey5(recipientBytes).toBase58() : evmFrom32(recipientBytes),
|
|
539
546
|
recipientVm: toSolana ? "svm" : "evm",
|
|
540
547
|
outputToken: od.outputToken,
|
|
541
548
|
destinationChainId: BigInt(od.destinationChainId),
|
|
@@ -956,7 +963,7 @@ async function evmOrigin(d, a, engine) {
|
|
|
956
963
|
uiAmount: a.uiAmount,
|
|
957
964
|
user,
|
|
958
965
|
recipient,
|
|
959
|
-
orderId: open.orderId,
|
|
966
|
+
orderId: orderIdOf(open.orderId),
|
|
960
967
|
rail,
|
|
961
968
|
legacyGas: src === "radius",
|
|
962
969
|
txs: [
|
|
@@ -965,6 +972,10 @@ async function evmOrigin(d, a, engine) {
|
|
|
965
972
|
]
|
|
966
973
|
};
|
|
967
974
|
}
|
|
975
|
+
function orderIdOf(id) {
|
|
976
|
+
if (typeof id !== "string" || !/^(0x)?[0-9a-fA-F]{64}$/.test(id)) throw new Error("refused: the server returned an order id that is not 32 bytes of hex");
|
|
977
|
+
return id;
|
|
978
|
+
}
|
|
968
979
|
async function solOrigin(d, a, engine) {
|
|
969
980
|
const user = solUser(a.user);
|
|
970
981
|
const recipient = getAddress5(a.recipient);
|
|
@@ -980,7 +991,7 @@ async function solOrigin(d, a, engine) {
|
|
|
980
991
|
uiAmount: a.uiAmount,
|
|
981
992
|
user,
|
|
982
993
|
recipient,
|
|
983
|
-
orderId: open.orderId,
|
|
994
|
+
orderId: orderIdOf(open.orderId),
|
|
984
995
|
rail: RAIL[engine],
|
|
985
996
|
txBase64: open.txB64,
|
|
986
997
|
versioned: false
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
export declare const TOKEN_PROGRAM_ID: PublicKey;
|
|
3
|
+
export declare const TOKEN_2022_PROGRAM_ID: PublicKey;
|
|
4
|
+
export declare const ASSOCIATED_TOKEN_PROGRAM_ID: PublicKey;
|
|
5
|
+
export declare function getAssociatedTokenAddressSync(mint: PublicKey, owner: PublicKey, programId?: PublicKey): PublicKey;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stablecoin.xyz/swap-intent",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Build an SBC Swap API transaction and check it against what the user asked for before signing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/stablecoinxyz/better-intents",
|
|
9
|
+
"url": "git+https://github.com/stablecoinxyz/better-intents.git",
|
|
10
10
|
"directory": "packages/swap-intent"
|
|
11
11
|
},
|
|
12
12
|
"publishConfig": {
|
|
@@ -29,10 +29,9 @@
|
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "node ../../scripts/build-swap-intent.mjs",
|
|
32
|
-
"prepublishOnly": "node ../../scripts/build-swap-intent.mjs"
|
|
32
|
+
"prepublishOnly": "node ../../scripts/build-swap-intent.mjs --publish"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@solana/spl-token": "^0.4.14",
|
|
36
35
|
"@solana/web3.js": "^1.98.4",
|
|
37
36
|
"viem": "^2.51.3",
|
|
38
37
|
"zod": "^4.6.7"
|