@tcswap/plugins 4.2.15
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/chainflip/index.cjs +4 -0
- package/dist/chainflip/index.cjs.map +11 -0
- package/dist/chainflip/index.js +4 -0
- package/dist/chainflip/index.js.map +11 -0
- package/dist/chunk-vzvcxw96.js +5 -0
- package/dist/chunk-vzvcxw96.js.map +10 -0
- package/dist/chunk-zweecvg1.js +4 -0
- package/dist/chunk-zweecvg1.js.map +10 -0
- package/dist/evm/index.cjs +4 -0
- package/dist/evm/index.cjs.map +10 -0
- package/dist/evm/index.js +4 -0
- package/dist/evm/index.js.map +10 -0
- package/dist/garden/index.cjs +4 -0
- package/dist/garden/index.cjs.map +10 -0
- package/dist/garden/index.js +4 -0
- package/dist/garden/index.js.map +10 -0
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +10 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +10 -0
- package/dist/near/index.cjs +4 -0
- package/dist/near/index.cjs.map +11 -0
- package/dist/near/index.js +4 -0
- package/dist/near/index.js.map +11 -0
- package/dist/radix/index.cjs +4 -0
- package/dist/radix/index.cjs.map +10 -0
- package/dist/radix/index.js +4 -0
- package/dist/radix/index.js.map +10 -0
- package/dist/solana/index.cjs +4 -0
- package/dist/solana/index.cjs.map +10 -0
- package/dist/solana/index.js +4 -0
- package/dist/solana/index.js.map +10 -0
- package/dist/thorchain/index.cjs +4 -0
- package/dist/thorchain/index.cjs.map +11 -0
- package/dist/thorchain/index.js +4 -0
- package/dist/thorchain/index.js.map +11 -0
- package/dist/types/chainflip/broker.d.ts +23 -0
- package/dist/types/chainflip/broker.d.ts.map +1 -0
- package/dist/types/chainflip/index.d.ts +4 -0
- package/dist/types/chainflip/index.d.ts.map +1 -0
- package/dist/types/chainflip/plugin.d.ts +13 -0
- package/dist/types/chainflip/plugin.d.ts.map +1 -0
- package/dist/types/chainflip/types.d.ts +41 -0
- package/dist/types/chainflip/types.d.ts.map +1 -0
- package/dist/types/evm/index.d.ts +21 -0
- package/dist/types/evm/index.d.ts.map +1 -0
- package/dist/types/garden/index.d.ts +2 -0
- package/dist/types/garden/index.d.ts.map +1 -0
- package/dist/types/garden/plugin.d.ts +21 -0
- package/dist/types/garden/plugin.d.ts.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/near/index.d.ts +3 -0
- package/dist/types/near/index.d.ts.map +1 -0
- package/dist/types/near/nearNames.d.ts +3 -0
- package/dist/types/near/nearNames.d.ts.map +1 -0
- package/dist/types/near/plugin.d.ts +22 -0
- package/dist/types/near/plugin.d.ts.map +1 -0
- package/dist/types/near/types.d.ts +12 -0
- package/dist/types/near/types.d.ts.map +1 -0
- package/dist/types/radix/index.d.ts +13 -0
- package/dist/types/radix/index.d.ts.map +1 -0
- package/dist/types/solana/index.d.ts +2 -0
- package/dist/types/solana/index.d.ts.map +1 -0
- package/dist/types/solana/plugin.d.ts +13 -0
- package/dist/types/solana/plugin.d.ts.map +1 -0
- package/dist/types/thorchain/index.d.ts +4 -0
- package/dist/types/thorchain/index.d.ts.map +1 -0
- package/dist/types/thorchain/plugin.d.ts +110 -0
- package/dist/types/thorchain/plugin.d.ts.map +1 -0
- package/dist/types/thorchain/shared.d.ts +21 -0
- package/dist/types/thorchain/shared.d.ts.map +1 -0
- package/dist/types/thorchain/types.d.ts +64 -0
- package/dist/types/thorchain/types.d.ts.map +1 -0
- package/dist/types/types.d.ts +19 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils.d.ts +20 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/package.json +88 -0
- package/src/chainflip/broker.ts +116 -0
- package/src/chainflip/index.ts +3 -0
- package/src/chainflip/plugin.ts +56 -0
- package/src/chainflip/types.ts +37 -0
- package/src/evm/index.ts +49 -0
- package/src/garden/index.ts +1 -0
- package/src/garden/plugin.ts +50 -0
- package/src/index.ts +41 -0
- package/src/near/index.ts +2 -0
- package/src/near/nearNames.ts +37 -0
- package/src/near/plugin.ts +214 -0
- package/src/near/types.ts +9 -0
- package/src/radix/index.ts +28 -0
- package/src/solana/index.ts +1 -0
- package/src/solana/plugin.ts +30 -0
- package/src/thorchain/index.ts +3 -0
- package/src/thorchain/plugin.ts +491 -0
- package/src/thorchain/shared.ts +17 -0
- package/src/thorchain/types.ts +59 -0
- package/src/types.ts +26 -0
- package/src/utils.ts +46 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { AssetValue, Chain, ProviderName, type SwapParams, USwapError } from "@tcswap/helpers";
|
|
6
|
+
import type { QuoteResponseRoute } from "@tcswap/helpers/api";
|
|
7
|
+
import type { NearWallet } from "@tcswap/toolboxes/near";
|
|
8
|
+
import { createPlugin } from "../utils";
|
|
9
|
+
import { calculateNearNameCost, validateNearName } from "./nearNames";
|
|
10
|
+
import type { NearAccountInfo, NearNameRegistrationParams } from "./types";
|
|
11
|
+
|
|
12
|
+
export const NearPlugin = createPlugin({
|
|
13
|
+
methods: ({ getWallet }) => ({
|
|
14
|
+
nearNames: {
|
|
15
|
+
async getInfo(name: string): Promise<NearAccountInfo | null> {
|
|
16
|
+
const normalizedName = name.toLowerCase().replace(/\.near$/, "");
|
|
17
|
+
|
|
18
|
+
if (!validateNearName(normalizedName)) {
|
|
19
|
+
throw new USwapError("plugin_near_invalid_name");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const accountId = `${normalizedName}.near`;
|
|
23
|
+
const wallet = getWallet(Chain.Near);
|
|
24
|
+
|
|
25
|
+
if (!wallet) {
|
|
26
|
+
throw new USwapError("plugin_near_no_connection");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
// Get account info
|
|
31
|
+
const accountInfo = await wallet.provider.query({
|
|
32
|
+
account_id: accountId,
|
|
33
|
+
finality: "final",
|
|
34
|
+
request_type: "view_account",
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Optionally get the account's public keys
|
|
38
|
+
const keysInfo = await wallet.provider.query({
|
|
39
|
+
account_id: accountId,
|
|
40
|
+
finality: "final",
|
|
41
|
+
request_type: "view_access_key_list",
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
accountId,
|
|
46
|
+
balance: (accountInfo as any).amount,
|
|
47
|
+
codeHash: (accountInfo as any).code_hash,
|
|
48
|
+
publicKeys: (keysInfo as any).keys?.map((k: any) => k.public_key) || [],
|
|
49
|
+
storageUsed: (accountInfo as any).storage_usage,
|
|
50
|
+
};
|
|
51
|
+
} catch (err: any) {
|
|
52
|
+
if (/UNKNOWN_ACCOUNT|does not exist while viewing/.test(err.message)) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
throw err;
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
async isAvailable(name: string) {
|
|
60
|
+
const owner = await this.resolve(name);
|
|
61
|
+
return owner === null;
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
async lookupNames(accountId: string) {
|
|
65
|
+
// NEAR doesn't have a central registry to look up all names owned by an account
|
|
66
|
+
// This would require indexing or an external service
|
|
67
|
+
// For now, we can only check if a specific account exists
|
|
68
|
+
const wallet = getWallet(Chain.Near);
|
|
69
|
+
|
|
70
|
+
if (!wallet) {
|
|
71
|
+
throw new USwapError("plugin_near_no_connection");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
// Check if the account exists
|
|
76
|
+
await wallet.provider.query({ account_id: accountId, finality: "final", request_type: "view_account" });
|
|
77
|
+
|
|
78
|
+
// If the account ID ends with .near, it's a NEAR name
|
|
79
|
+
if (accountId.endsWith(".near")) {
|
|
80
|
+
return [accountId];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Otherwise, we can't determine what names they own without an indexer
|
|
84
|
+
return [];
|
|
85
|
+
} catch {
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
async register(params: NearNameRegistrationParams) {
|
|
91
|
+
const { name, publicKey: publicKeyOverwrite } = params;
|
|
92
|
+
const normalizedName = name.toLowerCase().replace(/\.near$/, "");
|
|
93
|
+
|
|
94
|
+
if (!validateNearName(normalizedName)) {
|
|
95
|
+
throw new USwapError("plugin_near_invalid_name");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const wallet = getWallet(Chain.Near) as NearWallet;
|
|
99
|
+
|
|
100
|
+
const newPublicKey = publicKeyOverwrite || (await wallet.getPublicKey());
|
|
101
|
+
|
|
102
|
+
const cost = calculateNearNameCost(normalizedName);
|
|
103
|
+
|
|
104
|
+
return wallet.callFunction({
|
|
105
|
+
args: { new_account_id: `${normalizedName}.near`, new_public_key: newPublicKey },
|
|
106
|
+
contractId: "near",
|
|
107
|
+
deposit: cost,
|
|
108
|
+
methodName: "create_account",
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
async resolve(name: string) {
|
|
112
|
+
const normalizedName = name.toLowerCase().replace(/\.near$/, "");
|
|
113
|
+
|
|
114
|
+
if (!validateNearName(normalizedName)) {
|
|
115
|
+
throw new USwapError("plugin_near_invalid_name");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const accountId = `${normalizedName}.near`;
|
|
119
|
+
const wallet = getWallet(Chain.Near);
|
|
120
|
+
|
|
121
|
+
if (!wallet) {
|
|
122
|
+
throw new USwapError("plugin_near_no_connection");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
// Ask RPC whether the account exists
|
|
127
|
+
await wallet.provider.query({ account_id: accountId, finality: "final", request_type: "view_account" });
|
|
128
|
+
// If no error is thrown, the account exists
|
|
129
|
+
return accountId; // Account is taken, return the account ID as "owner"
|
|
130
|
+
} catch (err: any) {
|
|
131
|
+
// UNKNOWN_ACCOUNT means it hasn't been created yet → available
|
|
132
|
+
if (/UNKNOWN_ACCOUNT|does not exist while viewing/.test(err.message)) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
// Re-throw any unexpected errors
|
|
136
|
+
throw err;
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
transfer(name: string, newOwner: string) {
|
|
141
|
+
const normalizedName = name.toLowerCase().replace(/\.near$/, "");
|
|
142
|
+
|
|
143
|
+
if (!validateNearName(normalizedName)) {
|
|
144
|
+
throw new USwapError("plugin_near_invalid_name");
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const wallet = getWallet(Chain.Near) as NearWallet;
|
|
148
|
+
|
|
149
|
+
return wallet.callFunction({
|
|
150
|
+
args: { name: normalizedName, new_owner: newOwner },
|
|
151
|
+
contractId: "near",
|
|
152
|
+
deposit: "1",
|
|
153
|
+
methodName: "transfer",
|
|
154
|
+
});
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
async swap(swapParams: SwapParams<"near", QuoteResponseRoute>) {
|
|
158
|
+
const {
|
|
159
|
+
route: { buyAsset: buyAssetString, sellAsset: sellAssetString, inboundAddress, sellAmount, meta },
|
|
160
|
+
} = swapParams;
|
|
161
|
+
|
|
162
|
+
if (!(sellAssetString && buyAssetString && meta?.near?.sellAsset)) {
|
|
163
|
+
throw new USwapError("core_swap_asset_not_recognized");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (!inboundAddress) {
|
|
167
|
+
throw new USwapError("core_swap_invalid_params", { missing: ["inboundAddress"] });
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const sellAsset = await AssetValue.from({ asset: sellAssetString, value: sellAmount });
|
|
171
|
+
|
|
172
|
+
const sellAssetChain = sellAsset.chain;
|
|
173
|
+
|
|
174
|
+
const wallet = getWallet(sellAsset.chain as Exclude<Chain, typeof Chain.Radix>);
|
|
175
|
+
|
|
176
|
+
if (sellAssetChain === Chain.Near && !sellAsset.isGasAsset) {
|
|
177
|
+
const wallet = getWallet(sellAsset.chain as Chain.Near);
|
|
178
|
+
if (!wallet) {
|
|
179
|
+
throw new USwapError("core_wallet_connection_not_found");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const unsignedTransaction = await wallet.createContractFunctionCall({
|
|
183
|
+
args: {
|
|
184
|
+
amount: sellAsset.getBaseValue("string"),
|
|
185
|
+
msg: JSON.stringify({ receiver_id: inboundAddress }),
|
|
186
|
+
receiver_id: "intents.near",
|
|
187
|
+
},
|
|
188
|
+
attachedDeposit: "1",
|
|
189
|
+
contractId: sellAsset.address as string,
|
|
190
|
+
gas: "250000000000000",
|
|
191
|
+
methodName: "ft_transfer_call",
|
|
192
|
+
sender: wallet.address,
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
return wallet.signAndSendTransaction(unsignedTransaction);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (!wallet) {
|
|
199
|
+
throw new USwapError("core_wallet_connection_not_found");
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const tx = await wallet.transfer({
|
|
203
|
+
assetValue: sellAsset,
|
|
204
|
+
isProgramDerivedAddress: true,
|
|
205
|
+
recipient: inboundAddress,
|
|
206
|
+
sender: wallet.address,
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
return tx as string;
|
|
210
|
+
},
|
|
211
|
+
}),
|
|
212
|
+
name: "near",
|
|
213
|
+
properties: { supportedUSwapProviders: [ProviderName.NEAR] as const },
|
|
214
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { AssetValue, Chain, ProviderName, type SwapParams, USwapError } from "@tcswap/helpers";
|
|
6
|
+
import type { QuoteResponseRoute } from "@tcswap/helpers/api";
|
|
7
|
+
import { createPlugin } from "../utils";
|
|
8
|
+
|
|
9
|
+
export const RadixPlugin = createPlugin({
|
|
10
|
+
methods: ({ getWallet }) => ({
|
|
11
|
+
swap: async function radixSwap({ route: { tx, sellAmount, sellAsset } }: SwapParams<"radix", QuoteResponseRoute>) {
|
|
12
|
+
const assetValue = await AssetValue.from({ asset: sellAsset, asyncTokenLookup: true, value: sellAmount });
|
|
13
|
+
|
|
14
|
+
if (Chain.Radix !== assetValue.chain) {
|
|
15
|
+
throw new USwapError("core_swap_invalid_params");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const wallet = getWallet(assetValue.chain);
|
|
19
|
+
try {
|
|
20
|
+
return wallet.signAndBroadcast({ manifest: tx as string });
|
|
21
|
+
} catch (error) {
|
|
22
|
+
throw new USwapError("core_swap_invalid_params", error);
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
name: "radix",
|
|
27
|
+
properties: { supportedUSwapProviders: [ProviderName.CAVIAR_V1] as const },
|
|
28
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SolanaPlugin } from "./plugin";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { AssetValue, Chain, ProviderName, type SwapParams, USwapError } from "@tcswap/helpers";
|
|
6
|
+
import type { QuoteResponseRoute } from "@tcswap/helpers/api";
|
|
7
|
+
import { createPlugin } from "../utils";
|
|
8
|
+
|
|
9
|
+
export const SolanaPlugin = createPlugin({
|
|
10
|
+
methods: ({ getWallet }) => ({
|
|
11
|
+
swap: async function solanaSwap({ route }: SwapParams<"solana", QuoteResponseRoute>) {
|
|
12
|
+
const { VersionedTransaction } = await import("@solana/web3.js");
|
|
13
|
+
const { tx, sellAsset } = route;
|
|
14
|
+
|
|
15
|
+
const assetValue = await AssetValue.from({ asset: sellAsset });
|
|
16
|
+
|
|
17
|
+
const chain = assetValue.chain;
|
|
18
|
+
if (!(chain === Chain.Solana && tx)) throw new USwapError("core_swap_invalid_params");
|
|
19
|
+
|
|
20
|
+
const wallet = getWallet(chain);
|
|
21
|
+
const transaction = VersionedTransaction.deserialize(Buffer.from(tx as string, "base64"));
|
|
22
|
+
|
|
23
|
+
const signedTransaction = await wallet.signTransaction(transaction);
|
|
24
|
+
|
|
25
|
+
return wallet.broadcastTransaction(signedTransaction);
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
name: "solana",
|
|
29
|
+
properties: { supportedUSwapProviders: [ProviderName.JUPITER] as const },
|
|
30
|
+
});
|