@swapkit/plugins 1.0.0-beta.0 → 1.0.0-beta.2
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 +2 -2
- package/dist/chainflip/index.cjs.map +4 -4
- package/dist/chainflip/index.js +2 -2
- package/dist/chainflip/index.js.map +4 -4
- package/dist/evm/index.cjs +2 -2
- package/dist/evm/index.cjs.map +3 -3
- package/dist/evm/index.js +2 -2
- package/dist/evm/index.js.map +3 -3
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +4 -3
- package/dist/index.js +2 -1
- package/dist/index.js.map +4 -3
- package/dist/kado/index.cjs +2 -2
- package/dist/kado/index.cjs.map +3 -3
- package/dist/kado/index.js +3 -3
- package/dist/kado/index.js.map +3 -3
- package/dist/radix/index.cjs.map +1 -1
- package/dist/radix/index.js.map +1 -1
- package/dist/solana/index.cjs +3 -0
- package/dist/solana/index.cjs.map +10 -0
- package/dist/solana/index.js +3 -0
- package/dist/solana/index.js.map +10 -0
- package/dist/thorchain/index.cjs +2 -2
- package/dist/thorchain/index.cjs.map +3 -3
- package/dist/thorchain/index.js +2 -2
- package/dist/thorchain/index.js.map +3 -3
- package/package.json +17 -8
- package/src/chainflip/broker.ts +12 -11
- package/src/chainflip/plugin.ts +3 -8
- package/src/evm/index.ts +1 -1
- package/src/index.ts +2 -3
- package/src/kado/helpers.ts +3 -3
- package/src/solana/index.ts +1 -0
- package/src/solana/plugin.ts +36 -0
- package/src/thorchain/plugin.ts +10 -11
- package/src/thorchain/types.ts +1 -16
- package/src/types.ts +19 -0
- package/src/utils.ts +34 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SolanaPlugin } from "./plugin";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AssetValue,
|
|
3
|
+
Chain,
|
|
4
|
+
ProviderName,
|
|
5
|
+
SwapKitError,
|
|
6
|
+
type SwapParams,
|
|
7
|
+
createPlugin,
|
|
8
|
+
} from "@swapkit/helpers";
|
|
9
|
+
import type { QuoteResponseRoute } from "@swapkit/helpers/api";
|
|
10
|
+
|
|
11
|
+
export const SolanaPlugin = createPlugin({
|
|
12
|
+
name: "solana",
|
|
13
|
+
properties: {
|
|
14
|
+
supportedSwapkitProviders: [ProviderName.JUPITER],
|
|
15
|
+
},
|
|
16
|
+
methods: ({ getWallet }) => ({
|
|
17
|
+
swap: async function solanaSwap({ route }: SwapParams<"solana", QuoteResponseRoute>) {
|
|
18
|
+
const { VersionedTransaction } = await import("@solana/web3.js");
|
|
19
|
+
const { tx, sellAsset } = route;
|
|
20
|
+
|
|
21
|
+
const assetValue = await AssetValue.from({
|
|
22
|
+
asset: sellAsset,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const chain = assetValue.chain;
|
|
26
|
+
if (!(chain === Chain.Solana && tx)) throw new SwapKitError("core_swap_invalid_params");
|
|
27
|
+
|
|
28
|
+
const wallet = getWallet(chain);
|
|
29
|
+
const transaction = VersionedTransaction.deserialize(Buffer.from(tx as string, "base64"));
|
|
30
|
+
|
|
31
|
+
const signedTransaction = await wallet.signTransaction(transaction);
|
|
32
|
+
|
|
33
|
+
return wallet.broadcastTransaction(signedTransaction);
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
});
|
package/src/thorchain/plugin.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
type ApproveReturnType,
|
|
4
4
|
AssetValue,
|
|
5
5
|
Chain,
|
|
6
|
+
type CryptoChain,
|
|
6
7
|
type EVMChain,
|
|
7
8
|
EVMChains,
|
|
8
9
|
type ErrorKeys,
|
|
@@ -33,18 +34,15 @@ import {
|
|
|
33
34
|
TCBscDepositABI,
|
|
34
35
|
TCEthereumVaultAbi,
|
|
35
36
|
} from "@swapkit/helpers/contracts";
|
|
36
|
-
|
|
37
37
|
import { prepareTxParams, validateAddressType } from "./shared";
|
|
38
38
|
import type {
|
|
39
39
|
AddLiquidityParams,
|
|
40
40
|
AddLiquidityPartParams,
|
|
41
|
-
ApproveParams,
|
|
42
41
|
CoreTxParams,
|
|
43
42
|
CreateLiquidityParams,
|
|
44
43
|
NodeActionParams,
|
|
45
44
|
RegisterThornameParams,
|
|
46
45
|
SavingsParams,
|
|
47
|
-
SupportedChain,
|
|
48
46
|
WithdrawParams,
|
|
49
47
|
} from "./types";
|
|
50
48
|
|
|
@@ -154,7 +152,7 @@ function createTCBasedPlugin<T extends PluginChain>(pluginChain: T) {
|
|
|
154
152
|
const abis = pluginType === "thorchain" ? TCSpecificAbi : MayaSpecificAbi;
|
|
155
153
|
const { chain, symbol, ticker } = assetValue;
|
|
156
154
|
|
|
157
|
-
const wallet = getWallet(chain as
|
|
155
|
+
const wallet = getWallet(chain as CryptoChain);
|
|
158
156
|
if (!wallet) {
|
|
159
157
|
throw new SwapKitError("core_wallet_connection_not_found");
|
|
160
158
|
}
|
|
@@ -172,6 +170,7 @@ function createTCBasedPlugin<T extends PluginChain>(pluginChain: T) {
|
|
|
172
170
|
if (!abi) {
|
|
173
171
|
const wallet = getWallet(chain as PluginChain);
|
|
174
172
|
const shouldDeposit = pluginChain === chain && recipient === "";
|
|
173
|
+
// @Towan: Is that the same action? :)
|
|
175
174
|
return shouldDeposit ? wallet.deposit(params) : wallet.transfer(params);
|
|
176
175
|
}
|
|
177
176
|
|
|
@@ -250,12 +249,12 @@ function createTCBasedPlugin<T extends PluginChain>(pluginChain: T) {
|
|
|
250
249
|
});
|
|
251
250
|
}
|
|
252
251
|
|
|
253
|
-
function approveAssetValue(
|
|
254
|
-
return approve({
|
|
252
|
+
function approveAssetValue({ assetValue }: { assetValue: AssetValue }) {
|
|
253
|
+
return approve({ assetValue, type: ApproveMode.Approve });
|
|
255
254
|
}
|
|
256
255
|
|
|
257
|
-
function isAssetValueApproved(
|
|
258
|
-
return approve({
|
|
256
|
+
function isAssetValueApproved({ assetValue }: { assetValue: AssetValue }) {
|
|
257
|
+
return approve({ assetValue, type: ApproveMode.CheckOnly });
|
|
259
258
|
}
|
|
260
259
|
|
|
261
260
|
function registerName({ assetValue, ...params }: RegisterThornameParams) {
|
|
@@ -273,7 +272,7 @@ function createTCBasedPlugin<T extends PluginChain>(pluginChain: T) {
|
|
|
273
272
|
name: string;
|
|
274
273
|
ownerAddress: string;
|
|
275
274
|
}) {
|
|
276
|
-
const payout = payoutAddress || getWallet(assetValue.chain as
|
|
275
|
+
const payout = payoutAddress || getWallet(assetValue.chain as CryptoChain)?.address;
|
|
277
276
|
|
|
278
277
|
if (!payout) {
|
|
279
278
|
throw new SwapKitError("thorchain_preferred_asset_payout_required");
|
|
@@ -307,7 +306,7 @@ function createTCBasedPlugin<T extends PluginChain>(pluginChain: T) {
|
|
|
307
306
|
throw new SwapKitError("core_transaction_create_liquidity_invalid_params");
|
|
308
307
|
}
|
|
309
308
|
|
|
310
|
-
const assetAddress = getWallet(assetValue.chain as
|
|
309
|
+
const assetAddress = getWallet(assetValue.chain as CryptoChain).address;
|
|
311
310
|
const baseAssetAddress = getWallet(pluginChain).address;
|
|
312
311
|
|
|
313
312
|
const baseAssetTx = await wrapWithThrow(() => {
|
|
@@ -363,7 +362,7 @@ function createTCBasedPlugin<T extends PluginChain>(pluginChain: T) {
|
|
|
363
362
|
|
|
364
363
|
const baseAddress = includeBaseAddress ? baseAssetAddr || baseAssetWalletAddress : "";
|
|
365
364
|
const assetAddress =
|
|
366
|
-
isSym || mode === "asset" ? assetAddr || getWallet(chain as
|
|
365
|
+
isSym || mode === "asset" ? assetAddr || getWallet(chain as CryptoChain).address : "";
|
|
367
366
|
|
|
368
367
|
if (!(baseTransfer || assetTransfer)) {
|
|
369
368
|
throw new SwapKitError("core_transaction_add_liquidity_invalid_params");
|
package/src/thorchain/types.ts
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AssetValue,
|
|
3
|
-
CosmosWallets,
|
|
4
|
-
EVMWallets,
|
|
5
|
-
FeeOption,
|
|
6
|
-
MemoType,
|
|
7
|
-
ThorchainWallets,
|
|
8
|
-
UTXOWallets,
|
|
9
|
-
} from "@swapkit/helpers";
|
|
10
|
-
|
|
11
|
-
export type SupportedChain = keyof (EVMWallets & UTXOWallets & ThorchainWallets & CosmosWallets);
|
|
1
|
+
import type { AssetValue, FeeOption, MemoType } from "@swapkit/helpers";
|
|
12
2
|
|
|
13
3
|
export type AddLiquidityPartParams = {
|
|
14
4
|
assetValue: AssetValue;
|
|
@@ -26,11 +16,6 @@ export type AddLiquidityParams = {
|
|
|
26
16
|
mode?: "sym" | "baseAsset" | "asset";
|
|
27
17
|
};
|
|
28
18
|
|
|
29
|
-
export type ApproveParams = {
|
|
30
|
-
assetValue: AssetValue;
|
|
31
|
-
contractAddress?: string;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
19
|
export type CreateLiquidityParams = {
|
|
35
20
|
baseAssetValue: AssetValue;
|
|
36
21
|
assetValue: AssetValue;
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ChainflipPlugin } from "./chainflip";
|
|
2
|
+
import type { EVMPlugin } from "./evm";
|
|
3
|
+
import type { KadoPlugin } from "./kado";
|
|
4
|
+
import type { RadixPlugin } from "./radix";
|
|
5
|
+
import type { SolanaPlugin } from "./solana/plugin";
|
|
6
|
+
import type { ThorchainPlugin } from "./thorchain";
|
|
7
|
+
|
|
8
|
+
export type * from "./chainflip/types";
|
|
9
|
+
export type * from "./thorchain/types";
|
|
10
|
+
export type * from "./kado/types";
|
|
11
|
+
|
|
12
|
+
export type SKPlugins = typeof ChainflipPlugin &
|
|
13
|
+
typeof ThorchainPlugin &
|
|
14
|
+
typeof KadoPlugin &
|
|
15
|
+
typeof RadixPlugin &
|
|
16
|
+
typeof SolanaPlugin &
|
|
17
|
+
typeof EVMPlugin;
|
|
18
|
+
|
|
19
|
+
export type PluginName = keyof SKPlugins;
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { PluginName, SKPlugins } from "./types";
|
|
2
|
+
|
|
3
|
+
export async function loadPlugin<P extends PluginName>(pluginName: P) {
|
|
4
|
+
const { match } = await import("ts-pattern");
|
|
5
|
+
|
|
6
|
+
const plugin = await match(pluginName as PluginName)
|
|
7
|
+
.with("chainflip", async () => {
|
|
8
|
+
const { ChainflipPlugin } = await import("./chainflip");
|
|
9
|
+
return ChainflipPlugin;
|
|
10
|
+
})
|
|
11
|
+
.with("thorchain", async () => {
|
|
12
|
+
const { ThorchainPlugin } = await import("./thorchain");
|
|
13
|
+
return ThorchainPlugin;
|
|
14
|
+
})
|
|
15
|
+
.with("kado", async () => {
|
|
16
|
+
const { KadoPlugin } = await import("./kado");
|
|
17
|
+
return KadoPlugin;
|
|
18
|
+
})
|
|
19
|
+
.with("radix", async () => {
|
|
20
|
+
const { RadixPlugin } = await import("./radix");
|
|
21
|
+
return RadixPlugin;
|
|
22
|
+
})
|
|
23
|
+
.with("evm", async () => {
|
|
24
|
+
const { EVMPlugin } = await import("./evm");
|
|
25
|
+
return EVMPlugin;
|
|
26
|
+
})
|
|
27
|
+
.with("solana", async () => {
|
|
28
|
+
const { SolanaPlugin } = await import("./solana");
|
|
29
|
+
return SolanaPlugin;
|
|
30
|
+
})
|
|
31
|
+
.exhaustive();
|
|
32
|
+
|
|
33
|
+
return plugin as unknown as SKPlugins[P];
|
|
34
|
+
}
|