@swapkit/plugins 1.0.0-beta.15 → 1.0.0-beta.16
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/near/index.cjs +3 -0
- package/dist/near/index.cjs.map +10 -0
- package/dist/near/index.js +3 -0
- package/dist/near/index.js.map +10 -0
- package/package.json +11 -6
- package/src/near/index.ts +7 -0
- package/src/near/plugin.ts +76 -0
- package/src/near/types.ts +55 -0
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var T={};Q(T,{NearPlugin:()=>M});module.exports=O(T);var x=require("@swapkit/helpers"),C=require("@swapkit/helpers/api"),M=x.createPlugin({name:"near",properties:{supportedSwapkitProviders:[x.ProviderName.NEAR]},methods:({getWallet:D})=>({async swap({route:N,recipient:F}){let{meta:j}=N;if(!j?.nearSwapInfo)throw new x.SwapKitError("core_swap_invalid_params",{message:"Missing NEAR swap metadata"});let y=j.nearSwapInfo,q=await D(y.srcChain),G={...y,toAddress:F||await q.getAddress()},z=await C.SwapKitApi.getNearDepositChannel?.(G);if(!z)throw new x.SwapKitError("core_plugin_not_found",{info:"NEAR deposit channel API not implemented"});let B=z;if(!B.isSuccess)throw new x.SwapKitError("core_swap_invalid_params",{message:"Failed to create NEAR deposit channel"});let{channelId:H,depositAddress:J}=B.response,L=x.AssetValue.from({chain:y.srcChain,symbol:y.srcToken,value:y.amount,decimal:N.srcToken.decimals});return await q.transfer({assetValue:L,recipient:J,memo:H})}})});
|
|
2
|
+
|
|
3
|
+
//# debugId=16063BF3E8C2F12E64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/near/plugin.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import {\n AssetValue,\n ProviderName,\n SwapKitError,\n type SwapParams,\n createPlugin,\n} from \"@swapkit/helpers\";\nimport { SwapKitApi } from \"@swapkit/helpers/api\";\nimport type { NearDepositChannelParams, NearSwapResponse, NearSwapRoute } from \"./types\";\n\nexport const NearPlugin = createPlugin({\n name: \"near\",\n properties: {\n supportedSwapkitProviders: [ProviderName.NEAR],\n },\n methods: ({ getWallet }) => ({\n async swap({\n route,\n recipient,\n }: SwapParams<{\n route: NearSwapRoute & {\n meta?: {\n nearSwapInfo?: NearDepositChannelParams;\n };\n };\n }>) {\n const { meta } = route as any;\n if (!meta?.nearSwapInfo) {\n throw new SwapKitError(\"core_swap_invalid_params\", {\n message: \"Missing NEAR swap metadata\",\n });\n }\n\n const nearSwapInfo = meta.nearSwapInfo;\n const srcWallet = await getWallet(nearSwapInfo.srcChain);\n\n const nearDepositChannelParams: NearDepositChannelParams = {\n ...nearSwapInfo,\n toAddress: recipient || (await srcWallet.getAddress()),\n };\n\n // TODO: Implement getNearDepositChannel in SwapKitApi\n // This endpoint needs to be added to the API for NEAR support\n const response = await (SwapKitApi as any).getNearDepositChannel?.(nearDepositChannelParams);\n if (!response) {\n throw new SwapKitError(\"core_plugin_not_found\", {\n info: \"NEAR deposit channel API not implemented\",\n });\n }\n const nearResponse = response as NearSwapResponse;\n\n if (!nearResponse.isSuccess) {\n throw new SwapKitError(\"core_swap_invalid_params\", {\n message: \"Failed to create NEAR deposit channel\",\n });\n }\n\n const { channelId, depositAddress } = nearResponse.response;\n\n const assetValue = AssetValue.from({\n chain: nearSwapInfo.srcChain,\n symbol: nearSwapInfo.srcToken,\n value: nearSwapInfo.amount,\n decimal: (route as any).srcToken.decimals,\n });\n\n const txHash = await srcWallet.transfer({\n assetValue,\n recipient: depositAddress,\n memo: channelId,\n });\n\n return txHash;\n },\n }),\n});\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": "qDAMO,IANP,8BAOA,kCAGa,EAAa,eAAa,CACrC,KAAM,OACN,WAAY,CACV,0BAA2B,CAAC,eAAa,IAAI,CAC/C,EACA,QAAS,EAAG,gBAAiB,MACrB,KAAI,EACR,QACA,aAOE,CACF,IAAQ,QAAS,EACjB,IAAK,GAAM,aACT,MAAM,IAAI,eAAa,2BAA4B,CACjD,QAAS,4BACX,CAAC,EAGH,IAAM,EAAe,EAAK,aACpB,EAAY,MAAM,EAAU,EAAa,QAAQ,EAEjD,EAAqD,IACtD,EACH,UAAW,GAAc,MAAM,EAAU,WAAW,CACtD,EAIM,EAAW,MAAO,aAAmB,wBAAwB,CAAwB,EAC3F,IAAK,EACH,MAAM,IAAI,eAAa,wBAAyB,CAC9C,KAAM,0CACR,CAAC,EAEH,IAAM,EAAe,EAErB,IAAK,EAAa,UAChB,MAAM,IAAI,eAAa,2BAA4B,CACjD,QAAS,uCACX,CAAC,EAGH,IAAQ,YAAW,kBAAmB,EAAa,SAE7C,EAAa,aAAW,KAAK,CACjC,MAAO,EAAa,SACpB,OAAQ,EAAa,SACrB,MAAO,EAAa,OACpB,QAAU,EAAc,SAAS,QACnC,CAAC,EAQD,OANe,MAAM,EAAU,SAAS,CACtC,aACA,UAAW,EACX,KAAM,CACR,CAAC,EAIL,EACF,CAAC",
|
|
8
|
+
"debugId": "16063BF3E8C2F12E64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import"../chunk-tvrdndbw.js";import{AssetValue as L,ProviderName as M,SwapKitError as y,createPlugin as O}from"@swapkit/helpers";import{SwapKitApi as Q}from"@swapkit/helpers/api";var Y=O({name:"near",properties:{supportedSwapkitProviders:[M.NEAR]},methods:({getWallet:C})=>({async swap({route:N,recipient:D}){let{meta:j}=N;if(!j?.nearSwapInfo)throw new y("core_swap_invalid_params",{message:"Missing NEAR swap metadata"});let x=j.nearSwapInfo,q=await C(x.srcChain),F={...x,toAddress:D||await q.getAddress()},z=await Q.getNearDepositChannel?.(F);if(!z)throw new y("core_plugin_not_found",{info:"NEAR deposit channel API not implemented"});let B=z;if(!B.isSuccess)throw new y("core_swap_invalid_params",{message:"Failed to create NEAR deposit channel"});let{channelId:G,depositAddress:H}=B.response,J=L.from({chain:x.srcChain,symbol:x.srcToken,value:x.amount,decimal:N.srcToken.decimals});return await q.transfer({assetValue:J,recipient:H,memo:G})}})});export{Y as NearPlugin};
|
|
2
|
+
|
|
3
|
+
//# debugId=40DC44646B72361164756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/near/plugin.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import {\n AssetValue,\n ProviderName,\n SwapKitError,\n type SwapParams,\n createPlugin,\n} from \"@swapkit/helpers\";\nimport { SwapKitApi } from \"@swapkit/helpers/api\";\nimport type { NearDepositChannelParams, NearSwapResponse, NearSwapRoute } from \"./types\";\n\nexport const NearPlugin = createPlugin({\n name: \"near\",\n properties: {\n supportedSwapkitProviders: [ProviderName.NEAR],\n },\n methods: ({ getWallet }) => ({\n async swap({\n route,\n recipient,\n }: SwapParams<{\n route: NearSwapRoute & {\n meta?: {\n nearSwapInfo?: NearDepositChannelParams;\n };\n };\n }>) {\n const { meta } = route as any;\n if (!meta?.nearSwapInfo) {\n throw new SwapKitError(\"core_swap_invalid_params\", {\n message: \"Missing NEAR swap metadata\",\n });\n }\n\n const nearSwapInfo = meta.nearSwapInfo;\n const srcWallet = await getWallet(nearSwapInfo.srcChain);\n\n const nearDepositChannelParams: NearDepositChannelParams = {\n ...nearSwapInfo,\n toAddress: recipient || (await srcWallet.getAddress()),\n };\n\n // TODO: Implement getNearDepositChannel in SwapKitApi\n // This endpoint needs to be added to the API for NEAR support\n const response = await (SwapKitApi as any).getNearDepositChannel?.(nearDepositChannelParams);\n if (!response) {\n throw new SwapKitError(\"core_plugin_not_found\", {\n info: \"NEAR deposit channel API not implemented\",\n });\n }\n const nearResponse = response as NearSwapResponse;\n\n if (!nearResponse.isSuccess) {\n throw new SwapKitError(\"core_swap_invalid_params\", {\n message: \"Failed to create NEAR deposit channel\",\n });\n }\n\n const { channelId, depositAddress } = nearResponse.response;\n\n const assetValue = AssetValue.from({\n chain: nearSwapInfo.srcChain,\n symbol: nearSwapInfo.srcToken,\n value: nearSwapInfo.amount,\n decimal: (route as any).srcToken.decimals,\n });\n\n const txHash = await srcWallet.transfer({\n assetValue,\n recipient: depositAddress,\n memo: channelId,\n });\n\n return txHash;\n },\n }),\n});\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": "6BAAA,qBACE,kBACA,kBACA,kBAEA,yBAEF,qBAAS,6BAGF,IAAM,EAAa,EAAa,CACrC,KAAM,OACN,WAAY,CACV,0BAA2B,CAAC,EAAa,IAAI,CAC/C,EACA,QAAS,EAAG,gBAAiB,MACrB,KAAI,EACR,QACA,aAOE,CACF,IAAQ,QAAS,EACjB,IAAK,GAAM,aACT,MAAM,IAAI,EAAa,2BAA4B,CACjD,QAAS,4BACX,CAAC,EAGH,IAAM,EAAe,EAAK,aACpB,EAAY,MAAM,EAAU,EAAa,QAAQ,EAEjD,EAAqD,IACtD,EACH,UAAW,GAAc,MAAM,EAAU,WAAW,CACtD,EAIM,EAAW,MAAO,EAAmB,wBAAwB,CAAwB,EAC3F,IAAK,EACH,MAAM,IAAI,EAAa,wBAAyB,CAC9C,KAAM,0CACR,CAAC,EAEH,IAAM,EAAe,EAErB,IAAK,EAAa,UAChB,MAAM,IAAI,EAAa,2BAA4B,CACjD,QAAS,uCACX,CAAC,EAGH,IAAQ,YAAW,kBAAmB,EAAa,SAE7C,EAAa,EAAW,KAAK,CACjC,MAAO,EAAa,SACpB,OAAQ,EAAa,SACrB,MAAO,EAAa,OACpB,QAAU,EAAc,SAAS,QACnC,CAAC,EAQD,OANe,MAAM,EAAU,SAAS,CACtC,aACA,UAAW,EACX,KAAM,CACR,CAAC,EAIL,EACF,CAAC",
|
|
8
|
+
"debugId": "40DC44646B72361164756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "swapkit-oss",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@polkadot/keyring": "13.
|
|
5
|
-
"@polkadot/util": "13.
|
|
4
|
+
"@polkadot/keyring": "13.5.1",
|
|
5
|
+
"@polkadot/util": "13.5.1",
|
|
6
6
|
"@solana/web3.js": "1.98.2",
|
|
7
|
-
"@swapkit/helpers": "3.0.0-beta.
|
|
8
|
-
"@swapkit/toolboxes": "1.0.0-beta.
|
|
9
|
-
"ts-pattern": "5.7.
|
|
7
|
+
"@swapkit/helpers": "3.0.0-beta.11",
|
|
8
|
+
"@swapkit/toolboxes": "1.0.0-beta.16",
|
|
9
|
+
"ts-pattern": "5.7.1"
|
|
10
10
|
},
|
|
11
11
|
"description": "SwapKit Plugin - ChainFlip",
|
|
12
12
|
"exports": {
|
|
@@ -25,6 +25,11 @@
|
|
|
25
25
|
"require": "./dist/evm/index.cjs",
|
|
26
26
|
"types": "./src/evm/index.ts"
|
|
27
27
|
},
|
|
28
|
+
"./near": {
|
|
29
|
+
"default": "./dist/near/index.js",
|
|
30
|
+
"require": "./dist/near/index.cjs",
|
|
31
|
+
"types": "./src/near/index.ts"
|
|
32
|
+
},
|
|
28
33
|
"./radix": {
|
|
29
34
|
"default": "./dist/radix/index.js",
|
|
30
35
|
"require": "./dist/radix/index.cjs",
|
|
@@ -63,5 +68,5 @@
|
|
|
63
68
|
"type-check:go": "tsgo"
|
|
64
69
|
},
|
|
65
70
|
"type": "module",
|
|
66
|
-
"version": "1.0.0-beta.
|
|
71
|
+
"version": "1.0.0-beta.16"
|
|
67
72
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AssetValue,
|
|
3
|
+
ProviderName,
|
|
4
|
+
SwapKitError,
|
|
5
|
+
type SwapParams,
|
|
6
|
+
createPlugin,
|
|
7
|
+
} from "@swapkit/helpers";
|
|
8
|
+
import { SwapKitApi } from "@swapkit/helpers/api";
|
|
9
|
+
import type { NearDepositChannelParams, NearSwapResponse, NearSwapRoute } from "./types";
|
|
10
|
+
|
|
11
|
+
export const NearPlugin = createPlugin({
|
|
12
|
+
name: "near",
|
|
13
|
+
properties: {
|
|
14
|
+
supportedSwapkitProviders: [ProviderName.NEAR],
|
|
15
|
+
},
|
|
16
|
+
methods: ({ getWallet }) => ({
|
|
17
|
+
async swap({
|
|
18
|
+
route,
|
|
19
|
+
recipient,
|
|
20
|
+
}: SwapParams<{
|
|
21
|
+
route: NearSwapRoute & {
|
|
22
|
+
meta?: {
|
|
23
|
+
nearSwapInfo?: NearDepositChannelParams;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}>) {
|
|
27
|
+
const { meta } = route as any;
|
|
28
|
+
if (!meta?.nearSwapInfo) {
|
|
29
|
+
throw new SwapKitError("core_swap_invalid_params", {
|
|
30
|
+
message: "Missing NEAR swap metadata",
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const nearSwapInfo = meta.nearSwapInfo;
|
|
35
|
+
const srcWallet = await getWallet(nearSwapInfo.srcChain);
|
|
36
|
+
|
|
37
|
+
const nearDepositChannelParams: NearDepositChannelParams = {
|
|
38
|
+
...nearSwapInfo,
|
|
39
|
+
toAddress: recipient || (await srcWallet.getAddress()),
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// TODO: Implement getNearDepositChannel in SwapKitApi
|
|
43
|
+
// This endpoint needs to be added to the API for NEAR support
|
|
44
|
+
const response = await (SwapKitApi as any).getNearDepositChannel?.(nearDepositChannelParams);
|
|
45
|
+
if (!response) {
|
|
46
|
+
throw new SwapKitError("core_plugin_not_found", {
|
|
47
|
+
info: "NEAR deposit channel API not implemented",
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const nearResponse = response as NearSwapResponse;
|
|
51
|
+
|
|
52
|
+
if (!nearResponse.isSuccess) {
|
|
53
|
+
throw new SwapKitError("core_swap_invalid_params", {
|
|
54
|
+
message: "Failed to create NEAR deposit channel",
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const { channelId, depositAddress } = nearResponse.response;
|
|
59
|
+
|
|
60
|
+
const assetValue = AssetValue.from({
|
|
61
|
+
chain: nearSwapInfo.srcChain,
|
|
62
|
+
symbol: nearSwapInfo.srcToken,
|
|
63
|
+
value: nearSwapInfo.amount,
|
|
64
|
+
decimal: (route as any).srcToken.decimals,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const txHash = await srcWallet.transfer({
|
|
68
|
+
assetValue,
|
|
69
|
+
recipient: depositAddress,
|
|
70
|
+
memo: channelId,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return txHash;
|
|
74
|
+
},
|
|
75
|
+
}),
|
|
76
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export type NearTokenInfo = {
|
|
2
|
+
address: string;
|
|
3
|
+
chainId: number;
|
|
4
|
+
decimals: number;
|
|
5
|
+
identifier: string;
|
|
6
|
+
ticker: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type NearSwapRoute = {
|
|
10
|
+
amount: string;
|
|
11
|
+
dstToken: NearTokenInfo;
|
|
12
|
+
srcToken: NearTokenInfo;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type NearDepositChannelParams = {
|
|
16
|
+
amount: string;
|
|
17
|
+
blockNumber: number;
|
|
18
|
+
fromAddress: string;
|
|
19
|
+
srcToken?: string;
|
|
20
|
+
toAddress: string;
|
|
21
|
+
affiliate?: string;
|
|
22
|
+
affiliateFee?: number;
|
|
23
|
+
channelId?: string;
|
|
24
|
+
chainId?: number;
|
|
25
|
+
dstChain?: string;
|
|
26
|
+
dstToken?: string;
|
|
27
|
+
isAffiliateFeeFlat?: boolean;
|
|
28
|
+
srcChain?: string;
|
|
29
|
+
txnMetadata?: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type NearSwapResponse = {
|
|
33
|
+
amount: {
|
|
34
|
+
deposit: string;
|
|
35
|
+
estimatedOutput: string;
|
|
36
|
+
};
|
|
37
|
+
dstChain: string;
|
|
38
|
+
dstToken: string;
|
|
39
|
+
estimatedWaitTime: {
|
|
40
|
+
deposit: string;
|
|
41
|
+
swap: string;
|
|
42
|
+
};
|
|
43
|
+
isSuccess: boolean;
|
|
44
|
+
response: {
|
|
45
|
+
channelId: string;
|
|
46
|
+
depositAddress: string;
|
|
47
|
+
depositChannelBrokerCommissionBps: string;
|
|
48
|
+
estimatedDepositChannelExpiryTime: number;
|
|
49
|
+
issuedBlock: number;
|
|
50
|
+
maxBoostFeeBps: number;
|
|
51
|
+
srcChainExpiryBlock: string;
|
|
52
|
+
};
|
|
53
|
+
srcChain: string;
|
|
54
|
+
srcToken: string;
|
|
55
|
+
};
|