@swapkit/plugins 4.2.10 → 4.6.19
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/LICENSE +246 -0
- package/dist/chunk-k2pk60qs.js +1 -0
- package/dist/chunk-nbtnyjp9.js +2 -0
- package/dist/src/chainflip/index.cjs +1 -0
- package/dist/src/chainflip/index.js +1 -0
- package/dist/src/evm/index.cjs +1 -0
- package/dist/src/evm/index.js +1 -0
- package/dist/src/garden/index.cjs +1 -0
- package/dist/src/garden/index.js +1 -0
- package/dist/src/harbor/index.cjs +1 -0
- package/dist/src/harbor/index.js +1 -0
- package/dist/src/index.cjs +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/near/index.cjs +1 -0
- package/dist/src/near/index.js +1 -0
- package/dist/src/radix/index.cjs +1 -0
- package/dist/src/radix/index.js +1 -0
- package/dist/{solana → src/solana}/index.cjs +1 -4
- package/dist/src/solana/index.js +1 -0
- package/dist/src/swapkit/index.cjs +1 -0
- package/dist/src/swapkit/index.js +1 -0
- package/dist/src/thorchain/index.cjs +1 -0
- package/dist/src/thorchain/index.js +1 -0
- package/dist/types/chainflip/broker.d.ts +3 -3
- package/dist/types/chainflip/broker.d.ts.map +1 -1
- package/dist/types/chainflip/plugin.d.ts.map +1 -1
- package/dist/types/chainflip/types.d.ts +4 -1
- package/dist/types/chainflip/types.d.ts.map +1 -1
- package/dist/types/evm/index.d.ts +7 -5
- package/dist/types/evm/index.d.ts.map +1 -1
- package/dist/types/garden/plugin.d.ts +6 -4
- package/dist/types/garden/plugin.d.ts.map +1 -1
- package/dist/types/harbor/index.d.ts +20 -0
- package/dist/types/harbor/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/near/plugin.d.ts +7 -1
- package/dist/types/near/plugin.d.ts.map +1 -1
- package/dist/types/near/types.d.ts +17 -0
- package/dist/types/near/types.d.ts.map +1 -1
- package/dist/types/radix/index.d.ts +2 -2
- package/dist/types/radix/index.d.ts.map +1 -1
- package/dist/types/swapkit/index.d.ts +2 -0
- package/dist/types/swapkit/index.d.ts.map +1 -0
- package/dist/types/swapkit/plugin.d.ts +20 -0
- package/dist/types/swapkit/plugin.d.ts.map +1 -0
- package/dist/types/types.d.ts +3 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts +5 -3
- package/dist/types/utils.d.ts.map +1 -1
- package/package.json +41 -39
- package/dist/chainflip/index.cjs +0 -4
- package/dist/chainflip/index.cjs.map +0 -11
- package/dist/chainflip/index.js +0 -4
- package/dist/chainflip/index.js.map +0 -11
- package/dist/chunk-g305pte1.js +0 -4
- package/dist/chunk-g305pte1.js.map +0 -10
- package/dist/chunk-ykf9bj9d.js +0 -5
- package/dist/chunk-ykf9bj9d.js.map +0 -10
- package/dist/evm/index.cjs +0 -4
- package/dist/evm/index.cjs.map +0 -10
- package/dist/evm/index.js +0 -4
- package/dist/evm/index.js.map +0 -10
- package/dist/garden/index.cjs +0 -4
- package/dist/garden/index.cjs.map +0 -10
- package/dist/garden/index.js +0 -4
- package/dist/garden/index.js.map +0 -10
- package/dist/index.cjs +0 -4
- package/dist/index.cjs.map +0 -10
- package/dist/index.js +0 -4
- package/dist/index.js.map +0 -10
- package/dist/near/index.cjs +0 -4
- package/dist/near/index.cjs.map +0 -11
- package/dist/near/index.js +0 -4
- package/dist/near/index.js.map +0 -11
- package/dist/radix/index.cjs +0 -4
- package/dist/radix/index.cjs.map +0 -10
- package/dist/radix/index.js +0 -4
- package/dist/radix/index.js.map +0 -10
- package/dist/solana/index.cjs.map +0 -10
- package/dist/solana/index.js +0 -4
- package/dist/solana/index.js.map +0 -10
- package/dist/thorchain/index.cjs +0 -4
- package/dist/thorchain/index.cjs.map +0 -11
- package/dist/thorchain/index.js +0 -4
- package/dist/thorchain/index.js.map +0 -11
- package/src/chainflip/broker.ts +0 -112
- package/src/chainflip/index.ts +0 -3
- package/src/chainflip/plugin.ts +0 -52
- package/src/chainflip/types.ts +0 -37
- package/src/evm/index.ts +0 -45
- package/src/garden/index.ts +0 -1
- package/src/garden/plugin.ts +0 -54
- package/src/index.ts +0 -37
- package/src/near/index.ts +0 -2
- package/src/near/nearNames.ts +0 -37
- package/src/near/plugin.ts +0 -216
- package/src/near/types.ts +0 -9
- package/src/radix/index.ts +0 -24
- package/src/solana/index.ts +0 -1
- package/src/solana/plugin.ts +0 -26
- package/src/thorchain/index.ts +0 -3
- package/src/thorchain/plugin.ts +0 -492
- package/src/thorchain/shared.ts +0 -17
- package/src/thorchain/types.ts +0 -59
- package/src/types.ts +0 -22
- package/src/utils.ts +0 -42
package/src/chainflip/index.ts
DELETED
package/src/chainflip/plugin.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { AssetValue, type Chain, ProviderName, SwapKitError } from "@swapkit/helpers";
|
|
2
|
-
import { SwapKitApi } from "@swapkit/helpers/api";
|
|
3
|
-
import { createPlugin } from "../utils";
|
|
4
|
-
import type { RequestSwapDepositAddressParams } from "./types";
|
|
5
|
-
|
|
6
|
-
export const ChainflipPlugin = createPlugin({
|
|
7
|
-
methods: ({ getWallet }) => ({
|
|
8
|
-
swap: async function chainflipSwap(swapParams: RequestSwapDepositAddressParams) {
|
|
9
|
-
if (!(swapParams?.route?.buyAsset && swapParams.route.meta.chainflip)) {
|
|
10
|
-
throw new SwapKitError("core_swap_invalid_params", { ...swapParams });
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const {
|
|
14
|
-
route: {
|
|
15
|
-
buyAsset: buyAssetString,
|
|
16
|
-
sellAsset: sellAssetString,
|
|
17
|
-
sellAmount,
|
|
18
|
-
meta: { chainflip },
|
|
19
|
-
},
|
|
20
|
-
maxBoostFeeBps = 0,
|
|
21
|
-
} = swapParams;
|
|
22
|
-
|
|
23
|
-
if (!(sellAssetString && buyAssetString)) {
|
|
24
|
-
throw new SwapKitError("core_swap_asset_not_recognized");
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const sellAsset = await AssetValue.from({ asset: sellAssetString, asyncTokenLookup: true, value: sellAmount });
|
|
28
|
-
|
|
29
|
-
const wallet = getWallet(sellAsset.chain as Exclude<Chain, Chain.Radix>);
|
|
30
|
-
|
|
31
|
-
if (!wallet || !("transfer" in wallet)) {
|
|
32
|
-
throw new SwapKitError("core_wallet_connection_not_found");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const { depositAddress } = await SwapKitApi.getChainflipDepositChannel({
|
|
36
|
-
...chainflip,
|
|
37
|
-
maxBoostFeeBps: maxBoostFeeBps || chainflip.maxBoostFeeBps,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
const tx = await wallet.transfer({
|
|
41
|
-
assetValue: sellAsset,
|
|
42
|
-
isProgramDerivedAddress: true,
|
|
43
|
-
recipient: depositAddress,
|
|
44
|
-
sender: wallet.address,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
return tx;
|
|
48
|
-
},
|
|
49
|
-
}),
|
|
50
|
-
name: "chainflip",
|
|
51
|
-
properties: { supportedSwapkitProviders: [ProviderName.CHAINFLIP, ProviderName.CHAINFLIP_STREAMING] as const },
|
|
52
|
-
});
|
package/src/chainflip/types.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { AssetValue, SwapParams } from "@swapkit/helpers";
|
|
2
|
-
import type { QuoteResponseRoute } from "@swapkit/helpers/api";
|
|
3
|
-
|
|
4
|
-
export type WithdrawFeeResponse = {
|
|
5
|
-
egressId: string;
|
|
6
|
-
egressAsset: string;
|
|
7
|
-
egressAmount: string;
|
|
8
|
-
egressFee: string;
|
|
9
|
-
destinationAddress: string;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type DepositChannelRequest = {
|
|
13
|
-
brokerCommissionBPS: number;
|
|
14
|
-
ccmMetadata: ccmMetadata | null;
|
|
15
|
-
maxBoostFeeBps?: number;
|
|
16
|
-
affiliateFees?: AffiliateBroker[];
|
|
17
|
-
refundParameters?: SwapRefundParameters;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export type ccmMetadata = { message: string; gasBudget: string; cfParameters: string };
|
|
21
|
-
|
|
22
|
-
export type SwapDepositResponse = {
|
|
23
|
-
depositChannelId: string;
|
|
24
|
-
depositAddress: string;
|
|
25
|
-
srcChainExpiryBlock: number;
|
|
26
|
-
sellAsset: AssetValue;
|
|
27
|
-
buyAsset: AssetValue;
|
|
28
|
-
recipient: string;
|
|
29
|
-
brokerCommissionBPS: number;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export type AffiliateBroker = { brokerAddress: string; basisPoints: number };
|
|
33
|
-
|
|
34
|
-
export type SwapRefundParameters = { retryDuration: number; refundAddress: string; minPrice: string };
|
|
35
|
-
|
|
36
|
-
export type RequestSwapDepositAddressParams = Partial<SwapParams<"chainflip", QuoteResponseRoute>> &
|
|
37
|
-
Partial<DepositChannelRequest>;
|
package/src/evm/index.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ApproveMode,
|
|
3
|
-
AssetValue,
|
|
4
|
-
type EVMChain,
|
|
5
|
-
EVMChains,
|
|
6
|
-
ProviderName,
|
|
7
|
-
SwapKitError,
|
|
8
|
-
type SwapParams,
|
|
9
|
-
} from "@swapkit/helpers";
|
|
10
|
-
import type { EVMTransaction, QuoteResponseRoute } from "@swapkit/helpers/api";
|
|
11
|
-
import { approve, createPlugin } from "../utils";
|
|
12
|
-
|
|
13
|
-
export const EVMPlugin = createPlugin({
|
|
14
|
-
methods: ({ getWallet }) => ({
|
|
15
|
-
approveAssetValue: approve({ approveMode: ApproveMode.Approve, getWallet }),
|
|
16
|
-
isAssetValueApproved: approve({ approveMode: ApproveMode.CheckOnly, getWallet }),
|
|
17
|
-
swap: async function evmSwap({ route: { tx, sellAsset }, feeOptionKey }: SwapParams<"evm", QuoteResponseRoute>) {
|
|
18
|
-
const assetValue = await AssetValue.from({ asset: sellAsset, asyncTokenLookup: true });
|
|
19
|
-
const evmChain = assetValue.chain as EVMChain;
|
|
20
|
-
const wallet = getWallet(evmChain);
|
|
21
|
-
|
|
22
|
-
if (!(EVMChains.includes(evmChain) && tx)) {
|
|
23
|
-
throw new SwapKitError("core_swap_invalid_params");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const { from, to, data, value } = tx as EVMTransaction;
|
|
27
|
-
return wallet.sendTransaction({ data, feeOptionKey, from, to, value: BigInt(value) });
|
|
28
|
-
},
|
|
29
|
-
}),
|
|
30
|
-
name: "evm",
|
|
31
|
-
properties: {
|
|
32
|
-
supportedSwapkitProviders: [
|
|
33
|
-
ProviderName.CAMELOT_V3,
|
|
34
|
-
ProviderName.OPENOCEAN_V2,
|
|
35
|
-
ProviderName.OKX,
|
|
36
|
-
ProviderName.ONEINCH,
|
|
37
|
-
ProviderName.PANCAKESWAP,
|
|
38
|
-
ProviderName.PANGOLIN_V1,
|
|
39
|
-
ProviderName.SUSHISWAP_V2,
|
|
40
|
-
ProviderName.TRADERJOE_V2,
|
|
41
|
-
ProviderName.UNISWAP_V2,
|
|
42
|
-
ProviderName.UNISWAP_V3,
|
|
43
|
-
] as const,
|
|
44
|
-
},
|
|
45
|
-
});
|
package/src/garden/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { GardenPlugin } from "./plugin";
|
package/src/garden/plugin.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { VersionedTransaction } from "@solana/web3.js";
|
|
2
|
-
import {
|
|
3
|
-
ApproveMode,
|
|
4
|
-
AssetValue,
|
|
5
|
-
Chain,
|
|
6
|
-
EVMChains,
|
|
7
|
-
ProviderName,
|
|
8
|
-
SwapKitError,
|
|
9
|
-
type SwapParams,
|
|
10
|
-
} from "@swapkit/helpers";
|
|
11
|
-
import type { EVMTransaction, QuoteResponseRoute } from "@swapkit/helpers/api";
|
|
12
|
-
import { match } from "ts-pattern";
|
|
13
|
-
import { approve, createPlugin } from "../utils";
|
|
14
|
-
|
|
15
|
-
export const GardenPlugin = createPlugin({
|
|
16
|
-
methods: ({ getWallet }) => ({
|
|
17
|
-
approveAssetValue: approve({ approveMode: ApproveMode.Approve, getWallet }),
|
|
18
|
-
isAssetValueApproved: approve({ approveMode: ApproveMode.CheckOnly, getWallet }),
|
|
19
|
-
swap: function gardenSwap({ route }: SwapParams<"garden", QuoteResponseRoute>) {
|
|
20
|
-
const { sellAsset, sellAmount, targetAddress, tx } = route;
|
|
21
|
-
|
|
22
|
-
const sellAssetValue = AssetValue.from({ asset: sellAsset, value: sellAmount });
|
|
23
|
-
|
|
24
|
-
return match(sellAssetValue.chain as Chain)
|
|
25
|
-
.returnType<Promise<string>>()
|
|
26
|
-
.with(...EVMChains, (chain) => {
|
|
27
|
-
const wallet = getWallet(chain);
|
|
28
|
-
|
|
29
|
-
const { from, to, data, value } = tx as EVMTransaction;
|
|
30
|
-
return wallet.sendTransaction({ data, from, to, value: BigInt(value) });
|
|
31
|
-
})
|
|
32
|
-
.with(Chain.Solana, async (chain) => {
|
|
33
|
-
const wallet = getWallet(chain);
|
|
34
|
-
const transaction = VersionedTransaction.deserialize(Buffer.from(tx as string, "base64"));
|
|
35
|
-
|
|
36
|
-
const signedTransaction = await wallet.signTransaction(transaction);
|
|
37
|
-
|
|
38
|
-
return wallet.broadcastTransaction(signedTransaction);
|
|
39
|
-
})
|
|
40
|
-
.otherwise(async (chain) => {
|
|
41
|
-
if (!targetAddress) {
|
|
42
|
-
throw new SwapKitError("plugin_garden_missing_data", { message: "Missing target address: " });
|
|
43
|
-
}
|
|
44
|
-
const wallet = getWallet(chain as Exclude<Chain, Chain.Radix>);
|
|
45
|
-
|
|
46
|
-
const txHash = await wallet.transfer({ assetValue: sellAssetValue, recipient: targetAddress });
|
|
47
|
-
|
|
48
|
-
return txHash;
|
|
49
|
-
});
|
|
50
|
-
},
|
|
51
|
-
}),
|
|
52
|
-
name: "garden",
|
|
53
|
-
properties: { supportedSwapkitProviders: [ProviderName.GARDEN] as const },
|
|
54
|
-
});
|
package/src/index.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { PluginName, SKPlugins } from "./types";
|
|
2
|
-
|
|
3
|
-
export * from "./types";
|
|
4
|
-
export * from "./utils";
|
|
5
|
-
|
|
6
|
-
export async function loadPlugin<P extends PluginName>(pluginName: P) {
|
|
7
|
-
const { match } = await import("ts-pattern");
|
|
8
|
-
|
|
9
|
-
const plugin = await match(pluginName as PluginName)
|
|
10
|
-
.with("chainflip", async () => {
|
|
11
|
-
const { ChainflipPlugin } = await import("./chainflip");
|
|
12
|
-
return ChainflipPlugin;
|
|
13
|
-
})
|
|
14
|
-
.with("thorchain", async () => {
|
|
15
|
-
const { ThorchainPlugin } = await import("./thorchain");
|
|
16
|
-
return ThorchainPlugin;
|
|
17
|
-
})
|
|
18
|
-
.with("radix", async () => {
|
|
19
|
-
const { RadixPlugin } = await import("./radix");
|
|
20
|
-
return RadixPlugin;
|
|
21
|
-
})
|
|
22
|
-
.with("evm", async () => {
|
|
23
|
-
const { EVMPlugin } = await import("./evm");
|
|
24
|
-
return EVMPlugin;
|
|
25
|
-
})
|
|
26
|
-
.with("solana", async () => {
|
|
27
|
-
const { SolanaPlugin } = await import("./solana");
|
|
28
|
-
return SolanaPlugin;
|
|
29
|
-
})
|
|
30
|
-
.with("near", async () => {
|
|
31
|
-
const { NearPlugin } = await import("./near");
|
|
32
|
-
return NearPlugin;
|
|
33
|
-
})
|
|
34
|
-
.exhaustive();
|
|
35
|
-
|
|
36
|
-
return plugin as unknown as SKPlugins[P];
|
|
37
|
-
}
|
package/src/near/index.ts
DELETED
package/src/near/nearNames.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { parseNearAmount } from "@near-js/utils";
|
|
2
|
-
|
|
3
|
-
const MINIMUM_NAME_LENGTH = 2;
|
|
4
|
-
const MAXIMUM_NAME_LENGTH = 64;
|
|
5
|
-
|
|
6
|
-
export function validateNearName(name: string): boolean {
|
|
7
|
-
if (name.length < MINIMUM_NAME_LENGTH || name.length > MAXIMUM_NAME_LENGTH) {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// Only lowercase letters, numbers, and hyphens
|
|
12
|
-
// Cannot start or end with hyphen
|
|
13
|
-
// No consecutive hyphens
|
|
14
|
-
return /^[a-z0-9]+(-[a-z0-9]+)*$/.test(name);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function calculateNearNameCost(name: string): string {
|
|
18
|
-
// Pricing based on name length
|
|
19
|
-
// These are suggested prices, the actual minimum is ~0.00182 NEAR
|
|
20
|
-
const length = name.length;
|
|
21
|
-
|
|
22
|
-
let costInNear: string;
|
|
23
|
-
if (length <= 2) {
|
|
24
|
-
costInNear = "50"; // 50 NEAR for 2-char names
|
|
25
|
-
} else if (length <= 3) {
|
|
26
|
-
costInNear = "20"; // 20 NEAR for 3-char names
|
|
27
|
-
} else if (length <= 4) {
|
|
28
|
-
costInNear = "5"; // 5 NEAR for 4-char names
|
|
29
|
-
} else if (length <= 5) {
|
|
30
|
-
costInNear = "1"; // 1 NEAR for 5-char names
|
|
31
|
-
} else {
|
|
32
|
-
costInNear = "0.1"; // 0.1 NEAR for 6+ characters
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Convert NEAR to yoctoNEAR
|
|
36
|
-
return parseNearAmount(costInNear) || "0";
|
|
37
|
-
}
|
package/src/near/plugin.ts
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import { AssetValue, Chain, ProviderName, SwapKitError, type SwapParams } from "@swapkit/helpers";
|
|
2
|
-
import type { QuoteResponseRoute } from "@swapkit/helpers/api";
|
|
3
|
-
import type { NearWallet } from "@swapkit/toolboxes/near";
|
|
4
|
-
import { createPlugin } from "../utils";
|
|
5
|
-
import { calculateNearNameCost, validateNearName } from "./nearNames";
|
|
6
|
-
import type { NearAccountInfo, NearNameRegistrationParams } from "./types";
|
|
7
|
-
|
|
8
|
-
export const NearPlugin = createPlugin({
|
|
9
|
-
methods: ({ getWallet }) => ({
|
|
10
|
-
nearNames: {
|
|
11
|
-
async getInfo(name: string): Promise<NearAccountInfo | null> {
|
|
12
|
-
const normalizedName = name.toLowerCase().replace(/\.near$/, "");
|
|
13
|
-
|
|
14
|
-
if (!validateNearName(normalizedName)) {
|
|
15
|
-
throw new SwapKitError("plugin_near_invalid_name");
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const accountId = `${normalizedName}.near`;
|
|
19
|
-
const wallet = getWallet(Chain.Near);
|
|
20
|
-
|
|
21
|
-
if (!wallet) {
|
|
22
|
-
throw new SwapKitError("plugin_near_no_connection");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
// Get account info
|
|
27
|
-
const accountInfo = await wallet.provider.query({
|
|
28
|
-
account_id: accountId,
|
|
29
|
-
finality: "final",
|
|
30
|
-
request_type: "view_account",
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
// Optionally get the account's public keys
|
|
34
|
-
const keysInfo = await wallet.provider.query({
|
|
35
|
-
account_id: accountId,
|
|
36
|
-
finality: "final",
|
|
37
|
-
request_type: "view_access_key_list",
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
accountId,
|
|
42
|
-
balance: (accountInfo as any).amount,
|
|
43
|
-
codeHash: (accountInfo as any).code_hash,
|
|
44
|
-
publicKeys: (keysInfo as any).keys?.map((k: any) => k.public_key) || [],
|
|
45
|
-
storageUsed: (accountInfo as any).storage_usage,
|
|
46
|
-
};
|
|
47
|
-
} catch (err: any) {
|
|
48
|
-
if (/UNKNOWN_ACCOUNT|does not exist while viewing/.test(err.message)) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
throw err;
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
async isAvailable(name: string) {
|
|
56
|
-
const owner = await this.resolve(name);
|
|
57
|
-
return owner === null;
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
async lookupNames(accountId: string) {
|
|
61
|
-
// NEAR doesn't have a central registry to look up all names owned by an account
|
|
62
|
-
// This would require indexing or an external service
|
|
63
|
-
// For now, we can only check if a specific account exists
|
|
64
|
-
const wallet = getWallet(Chain.Near);
|
|
65
|
-
|
|
66
|
-
if (!wallet) {
|
|
67
|
-
throw new SwapKitError("plugin_near_no_connection");
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
try {
|
|
71
|
-
// Check if the account exists
|
|
72
|
-
await wallet.provider.query({ account_id: accountId, finality: "final", request_type: "view_account" });
|
|
73
|
-
|
|
74
|
-
// If the account ID ends with .near, it's a NEAR name
|
|
75
|
-
if (accountId.endsWith(".near")) {
|
|
76
|
-
return [accountId];
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Otherwise, we can't determine what names they own without an indexer
|
|
80
|
-
return [];
|
|
81
|
-
} catch {
|
|
82
|
-
return [];
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
|
|
86
|
-
async register(params: NearNameRegistrationParams) {
|
|
87
|
-
const { name, publicKey: publicKeyOverwrite } = params;
|
|
88
|
-
const normalizedName = name.toLowerCase().replace(/\.near$/, "");
|
|
89
|
-
|
|
90
|
-
if (!validateNearName(normalizedName)) {
|
|
91
|
-
throw new SwapKitError("plugin_near_invalid_name");
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const wallet = getWallet(Chain.Near) as NearWallet;
|
|
95
|
-
|
|
96
|
-
const newPublicKey = publicKeyOverwrite || (await wallet.getPublicKey());
|
|
97
|
-
|
|
98
|
-
const cost = calculateNearNameCost(normalizedName);
|
|
99
|
-
|
|
100
|
-
return wallet.callFunction({
|
|
101
|
-
args: { new_account_id: `${normalizedName}.near`, new_public_key: newPublicKey },
|
|
102
|
-
contractId: "near",
|
|
103
|
-
deposit: cost,
|
|
104
|
-
methodName: "create_account",
|
|
105
|
-
});
|
|
106
|
-
},
|
|
107
|
-
async resolve(name: string) {
|
|
108
|
-
const normalizedName = name.toLowerCase().replace(/\.near$/, "");
|
|
109
|
-
|
|
110
|
-
if (!validateNearName(normalizedName)) {
|
|
111
|
-
throw new SwapKitError("plugin_near_invalid_name");
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const accountId = `${normalizedName}.near`;
|
|
115
|
-
const wallet = getWallet(Chain.Near);
|
|
116
|
-
|
|
117
|
-
if (!wallet) {
|
|
118
|
-
throw new SwapKitError("plugin_near_no_connection");
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
try {
|
|
122
|
-
// Ask RPC whether the account exists
|
|
123
|
-
await wallet.provider.query({ account_id: accountId, finality: "final", request_type: "view_account" });
|
|
124
|
-
// If no error is thrown, the account exists
|
|
125
|
-
return accountId; // Account is taken, return the account ID as "owner"
|
|
126
|
-
} catch (err: any) {
|
|
127
|
-
// UNKNOWN_ACCOUNT means it hasn't been created yet → available
|
|
128
|
-
if (/UNKNOWN_ACCOUNT|does not exist while viewing/.test(err.message)) {
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
// Re-throw any unexpected errors
|
|
132
|
-
throw err;
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
transfer(name: string, newOwner: string) {
|
|
137
|
-
const normalizedName = name.toLowerCase().replace(/\.near$/, "");
|
|
138
|
-
|
|
139
|
-
if (!validateNearName(normalizedName)) {
|
|
140
|
-
throw new SwapKitError("plugin_near_invalid_name");
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const wallet = getWallet(Chain.Near) as NearWallet;
|
|
144
|
-
|
|
145
|
-
return wallet.callFunction({
|
|
146
|
-
args: { name: normalizedName, new_owner: newOwner },
|
|
147
|
-
contractId: "near",
|
|
148
|
-
deposit: "1",
|
|
149
|
-
methodName: "transfer",
|
|
150
|
-
});
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
async swap(swapParams: SwapParams<"near", QuoteResponseRoute>) {
|
|
154
|
-
const {
|
|
155
|
-
route: {
|
|
156
|
-
buyAsset: buyAssetString,
|
|
157
|
-
sellAsset: sellAssetString,
|
|
158
|
-
inboundAddress,
|
|
159
|
-
sellAmount,
|
|
160
|
-
meta: { near },
|
|
161
|
-
},
|
|
162
|
-
} = swapParams;
|
|
163
|
-
|
|
164
|
-
if (!(sellAssetString && buyAssetString && near?.sellAsset)) {
|
|
165
|
-
throw new SwapKitError("core_swap_asset_not_recognized");
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (!inboundAddress) {
|
|
169
|
-
throw new SwapKitError("core_swap_invalid_params", { missing: ["inboundAddress"] });
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const sellAsset = await AssetValue.from({ asset: sellAssetString, value: sellAmount });
|
|
173
|
-
|
|
174
|
-
const sellAssetChain = sellAsset.chain;
|
|
175
|
-
|
|
176
|
-
const wallet = getWallet(sellAsset.chain as Exclude<Chain, typeof Chain.Radix>);
|
|
177
|
-
|
|
178
|
-
if (sellAssetChain === Chain.Near && !sellAsset.isGasAsset) {
|
|
179
|
-
const wallet = getWallet(sellAsset.chain as Chain.Near);
|
|
180
|
-
if (!wallet) {
|
|
181
|
-
throw new SwapKitError("core_wallet_connection_not_found");
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const unsignedTransaction = await wallet.createContractFunctionCall({
|
|
185
|
-
args: {
|
|
186
|
-
amount: sellAsset.getBaseValue("string"),
|
|
187
|
-
msg: JSON.stringify({ receiver_id: inboundAddress }),
|
|
188
|
-
receiver_id: "intents.near",
|
|
189
|
-
},
|
|
190
|
-
attachedDeposit: "1",
|
|
191
|
-
contractId: sellAsset.address as string,
|
|
192
|
-
gas: "250000000000000",
|
|
193
|
-
methodName: "ft_transfer_call",
|
|
194
|
-
sender: wallet.address,
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
return wallet.signAndSendTransaction(unsignedTransaction);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if (!wallet) {
|
|
201
|
-
throw new SwapKitError("core_wallet_connection_not_found");
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const tx = await wallet.transfer({
|
|
205
|
-
assetValue: sellAsset,
|
|
206
|
-
isProgramDerivedAddress: true,
|
|
207
|
-
recipient: inboundAddress,
|
|
208
|
-
sender: wallet.address,
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
return tx as string;
|
|
212
|
-
},
|
|
213
|
-
}),
|
|
214
|
-
name: "near",
|
|
215
|
-
properties: { supportedSwapkitProviders: [ProviderName.NEAR] as const },
|
|
216
|
-
});
|
package/src/near/types.ts
DELETED
package/src/radix/index.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { AssetValue, Chain, ProviderName, SwapKitError, type SwapParams } from "@swapkit/helpers";
|
|
2
|
-
import type { QuoteResponseRoute } from "@swapkit/helpers/api";
|
|
3
|
-
import { createPlugin } from "../utils";
|
|
4
|
-
|
|
5
|
-
export const RadixPlugin = createPlugin({
|
|
6
|
-
methods: ({ getWallet }) => ({
|
|
7
|
-
swap: async function radixSwap({ route: { tx, sellAmount, sellAsset } }: SwapParams<"radix", QuoteResponseRoute>) {
|
|
8
|
-
const assetValue = await AssetValue.from({ asset: sellAsset, asyncTokenLookup: true, value: sellAmount });
|
|
9
|
-
|
|
10
|
-
if (Chain.Radix !== assetValue.chain) {
|
|
11
|
-
throw new SwapKitError("core_swap_invalid_params");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const wallet = getWallet(assetValue.chain);
|
|
15
|
-
try {
|
|
16
|
-
return wallet.signAndBroadcast({ manifest: tx as string });
|
|
17
|
-
} catch (error) {
|
|
18
|
-
throw new SwapKitError("core_swap_invalid_params", error);
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
}),
|
|
22
|
-
name: "radix",
|
|
23
|
-
properties: { supportedSwapkitProviders: [ProviderName.CAVIAR_V1] as const },
|
|
24
|
-
});
|
package/src/solana/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { SolanaPlugin } from "./plugin";
|
package/src/solana/plugin.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { AssetValue, Chain, ProviderName, SwapKitError, type SwapParams } from "@swapkit/helpers";
|
|
2
|
-
import type { QuoteResponseRoute } from "@swapkit/helpers/api";
|
|
3
|
-
import { createPlugin } from "../utils";
|
|
4
|
-
|
|
5
|
-
export const SolanaPlugin = createPlugin({
|
|
6
|
-
methods: ({ getWallet }) => ({
|
|
7
|
-
swap: async function solanaSwap({ route }: SwapParams<"solana", QuoteResponseRoute>) {
|
|
8
|
-
const { VersionedTransaction } = await import("@solana/web3.js");
|
|
9
|
-
const { tx, sellAsset } = route;
|
|
10
|
-
|
|
11
|
-
const assetValue = await AssetValue.from({ asset: sellAsset });
|
|
12
|
-
|
|
13
|
-
const chain = assetValue.chain;
|
|
14
|
-
if (!(chain === Chain.Solana && tx)) throw new SwapKitError("core_swap_invalid_params");
|
|
15
|
-
|
|
16
|
-
const wallet = getWallet(chain);
|
|
17
|
-
const transaction = VersionedTransaction.deserialize(Buffer.from(tx as string, "base64"));
|
|
18
|
-
|
|
19
|
-
const signedTransaction = await wallet.signTransaction(transaction);
|
|
20
|
-
|
|
21
|
-
return wallet.broadcastTransaction(signedTransaction);
|
|
22
|
-
},
|
|
23
|
-
}),
|
|
24
|
-
name: "solana",
|
|
25
|
-
properties: { supportedSwapkitProviders: [ProviderName.JUPITER] as const },
|
|
26
|
-
});
|
package/src/thorchain/index.ts
DELETED