@swapkit/plugins 1.0.0-beta.9 → 4.0.0-beta.36
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 +1 -0
- package/dist/chainflip/index.js +2 -1
- package/dist/chunk-fazw0jvt.js +1 -0
- package/dist/{chunk-tvrdndbw.js → chunk-wfktpptf.js} +2 -1
- package/dist/{chunk-tvrdndbw.js.map → chunk-wfktpptf.js.map} +1 -1
- package/dist/evm/index.cjs +1 -0
- package/dist/evm/index.js +2 -1
- package/dist/index.cjs +3 -2
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +3 -2
- package/dist/index.js.map +3 -3
- 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 +1 -0
- package/dist/radix/index.js +2 -1
- package/dist/solana/index.cjs +1 -0
- package/dist/solana/index.js +2 -1
- package/dist/thorchain/index.cjs +3 -2
- package/dist/thorchain/index.cjs.map +4 -4
- package/dist/thorchain/index.js +3 -2
- package/dist/thorchain/index.js.map +4 -4
- package/package.json +17 -13
- package/src/near/index.ts +9 -0
- package/src/near/nearNames.ts +37 -0
- package/src/near/plugin.ts +217 -0
- package/src/near/types.ts +67 -0
- package/src/thorchain/plugin.ts +0 -21
- package/src/thorchain/shared.ts +1 -7
- package/src/thorchain/types.ts +0 -12
- package/src/types.ts +3 -4
- package/src/utils.ts +4 -4
- package/dist/kado/index.cjs +0 -20
- package/dist/kado/index.cjs.map +0 -12
- package/dist/kado/index.js +0 -20
- package/dist/kado/index.js.map +0 -12
- package/src/kado/helpers.ts +0 -117
- package/src/kado/index.ts +0 -3
- package/src/kado/plugin.ts +0 -234
- package/src/kado/types.ts +0 -225
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/thorchain/plugin.ts", "../src/thorchain/shared.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import {\n ApproveMode,\n type ApproveReturnType,\n AssetValue,\n Chain,\n type CryptoChain,\n type EVMChain,\n EVMChains,\n type ErrorKeys,\n FeeOption,\n MemoType,\n ProviderName,\n SwapKitError,\n type SwapKitPluginParams,\n type SwapParams,\n createPlugin,\n getMemoForDeposit,\n getMemoForLeaveAndBond,\n getMemoForNamePreferredAssetRegister,\n getMemoForNameRegister,\n getMemoForSaverDeposit,\n getMemoForSaverWithdraw,\n getMemoForUnbond,\n getMemoForWithdraw,\n getMinAmountByChain,\n wrapWithThrow,\n} from \"@swapkit/helpers\";\nimport { type QuoteResponseRoute, SwapKitApi, type THORNodeType } from \"@swapkit/helpers/api\";\nimport {\n MayaArbitrumVaultAbi,\n MayaEthereumVaultAbi,\n TCAvalancheDepositABI,\n TCBaseDepositABI,\n TCBscDepositABI,\n TCEthereumVaultAbi,\n} from \"@swapkit/helpers/contracts\";\nimport { prepareTxParams, validateAddressType } from \"./shared\";\nimport type {\n AddLiquidityParams,\n AddLiquidityPartParams,\n CoreTxParams,\n CreateLiquidityParams,\n NodeActionParams,\n RegisterThornameParams,\n SavingsParams,\n WithdrawParams,\n} from \"./types\";\n\nconst gasFeeMultiplier: Record<FeeOption, number> = {\n [FeeOption.Average]: 1.2,\n [FeeOption.Fast]: 1.5,\n [FeeOption.Fastest]: 2,\n};\n\nconst TCSpecificAbi = {\n [Chain.Avalanche]: TCAvalancheDepositABI,\n [Chain.Base]: TCBaseDepositABI,\n [Chain.BinanceSmartChain]: TCBscDepositABI,\n [Chain.Ethereum]: TCEthereumVaultAbi,\n};\n\nconst MayaSpecificAbi = {\n [Chain.Arbitrum]: MayaArbitrumVaultAbi,\n [Chain.Ethereum]: MayaEthereumVaultAbi,\n};\n\nexport const ThorchainPlugin = createPlugin({\n name: \"thorchain\",\n methods: createTCBasedPlugin(Chain.THORChain),\n properties: {\n supportedSwapkitProviders: [ProviderName.THORCHAIN, ProviderName.THORCHAIN_STREAMING],\n },\n});\n\nexport const MayachainPlugin = createPlugin({\n name: \"mayachain\",\n methods: createTCBasedPlugin(Chain.Maya),\n properties: {\n supportedSwapkitProviders: [ProviderName.MAYACHAIN],\n },\n});\n\nfunction getInboundDataFunction(type?: THORNodeType) {\n return async function getInboundDataByChain<T extends Chain>(chain: T) {\n if (\n (type === \"thorchain\" && chain === Chain.THORChain) ||\n (type === \"mayachain\" && chain === Chain.Maya)\n ) {\n return { gas_rate: \"0\", router: \"\", address: \"\", halted: false, chain };\n }\n\n const inboundData = await SwapKitApi.thornode.getInboundAddresses(type);\n const chainAddressData = inboundData.find((item) => item.chain === chain);\n\n if (!chainAddressData) throw new SwapKitError(\"core_inbound_data_not_found\");\n if (chainAddressData?.halted) throw new SwapKitError(\"core_chain_halted\");\n\n return chainAddressData;\n };\n}\n\ntype PluginChain = Chain.Maya | Chain.THORChain;\n\nfunction createTCBasedPlugin<T extends PluginChain>(pluginChain: T) {\n return function plugin({ getWallet }: SwapKitPluginParams) {\n const pluginType = pluginChain === Chain.Maya ? \"mayachain\" : \"thorchain\";\n const getInboundDataByChain = getInboundDataFunction(pluginType);\n\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO: refactor/split\n async function approve<T extends ApproveMode>({\n assetValue,\n type = \"checkOnly\" as T,\n }: { type: T; assetValue: AssetValue }) {\n const router = (await getInboundDataByChain(assetValue.chain)).router as string;\n\n const chain = assetValue.chain as EVMChain;\n\n const isEVMChain = EVMChains.includes(chain as EVMChain);\n const isNativeEVM = isEVMChain && assetValue.isGasAsset;\n\n if (isNativeEVM || !isEVMChain || assetValue.isSynthetic) {\n return Promise.resolve(type === \"checkOnly\" ? true : \"approved\") as ApproveReturnType<T>;\n }\n\n const wallet = getWallet(chain);\n\n if (!wallet) {\n throw new SwapKitError(\"core_wallet_connection_not_found\");\n }\n\n const walletAction = type === \"checkOnly\" ? wallet.isApproved : wallet.approve;\n\n if (!(assetValue.address && wallet.address)) {\n throw new SwapKitError(\"core_approve_asset_address_or_from_not_found\");\n }\n\n return walletAction({\n amount: assetValue.getBaseValue(\"bigint\"),\n assetAddress: assetValue.address,\n from: wallet.address,\n spenderAddress: router,\n });\n }\n\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO refactor\n async function deposit({\n assetValue,\n recipient,\n router,\n ...rest\n }: CoreTxParams & { router?: string }) {\n const abis = pluginType === \"thorchain\" ? TCSpecificAbi : MayaSpecificAbi;\n const { chain, symbol, ticker } = assetValue;\n\n const wallet = getWallet(chain as CryptoChain);\n if (!wallet) {\n throw new SwapKitError(\"core_wallet_connection_not_found\");\n }\n const { address } = wallet;\n const isAddressValidated = validateAddressType({ address, chain });\n if (!isAddressValidated) {\n throw new SwapKitError(\"core_transaction_invalid_sender_address\");\n }\n\n const params = prepareTxParams({ from: address, assetValue, recipient, router, ...rest });\n\n try {\n const abi = abis?.[chain as keyof typeof abis];\n\n if (!abi) {\n const wallet = getWallet(chain as PluginChain);\n const shouldDeposit = pluginChain === chain && recipient === \"\";\n // @Towan: Is that the same action? :)\n return shouldDeposit ? wallet.deposit(params) : wallet.transfer(params);\n }\n\n const { getChecksumAddressFromAsset } = await import(\"@swapkit/toolboxes/evm\");\n const wallet = getWallet(chain as EVMChain);\n\n return wallet.call<string>({\n abi,\n contractAddress: router || ((await getInboundDataByChain(chain)).router as string),\n funcName: \"depositWithExpiry\",\n funcParams: [\n recipient,\n getChecksumAddressFromAsset({ chain, symbol, ticker }, chain as EVMChain),\n assetValue.getBaseValue(\"string\"),\n params.memo,\n rest.expiration || Number.parseInt(`${(Date.now() + 15 * 60 * 1000) / 1000}`),\n ],\n txOverrides: {\n from: params.from,\n value: assetValue.isGasAsset ? assetValue.getBaseValue(\"bigint\") : undefined,\n },\n });\n } catch (error) {\n const errorMessage =\n // @ts-expect-error Fine to use error as string\n typeof error === \"string\" ? error.toLowerCase() : error?.message.toLowerCase();\n const isInsufficientFunds = errorMessage?.includes(\"insufficient funds\");\n const isGas = errorMessage?.includes(\"gas\");\n const isServer = errorMessage?.includes(\"server\");\n const isUserRejected = errorMessage?.includes(\"user rejected\");\n const errorKey: ErrorKeys = isInsufficientFunds\n ? \"core_transaction_deposit_insufficient_funds_error\"\n : isGas\n ? \"core_transaction_deposit_gas_error\"\n : isServer\n ? \"core_transaction_deposit_server_error\"\n : isUserRejected\n ? \"core_transaction_user_rejected\"\n : \"core_transaction_deposit_error\";\n\n throw new SwapKitError(errorKey, error);\n }\n }\n\n async function depositToProtocol({\n memo,\n assetValue,\n }: { assetValue: AssetValue; memo: string }) {\n const mimir = await SwapKitApi.thornode.getMimirInfo(pluginType);\n\n // check if trading is halted or not\n if (mimir.HALTCHAINGLOBAL >= 1 || mimir.HALTTHORCHAIN >= 1) {\n throw new SwapKitError(\"thorchain_chain_halted\");\n }\n\n return deposit({ assetValue, recipient: \"\", memo });\n }\n\n async function depositToPool({\n assetValue,\n memo,\n feeOptionKey = FeeOption.Fast,\n }: { assetValue: AssetValue; memo: string; feeOptionKey?: FeeOption }) {\n const {\n gas_rate = \"0\",\n router,\n address: poolAddress,\n } = await getInboundDataByChain(assetValue.chain);\n\n return deposit({\n assetValue,\n recipient: poolAddress,\n memo,\n router,\n feeRate: Number.parseInt(gas_rate) * gasFeeMultiplier[feeOptionKey],\n });\n }\n\n function approveAssetValue({ assetValue }: { assetValue: AssetValue }) {\n return approve({ assetValue, type: ApproveMode.Approve });\n }\n\n function isAssetValueApproved({ assetValue }: { assetValue: AssetValue }) {\n return approve({ assetValue, type: ApproveMode.CheckOnly });\n }\n\n function registerName({ assetValue, ...params }: RegisterThornameParams) {\n return depositToProtocol({ assetValue, memo: getMemoForNameRegister(params) });\n }\n\n function registerPreferredAsset({\n assetValue,\n payoutAddress,\n name,\n ownerAddress,\n }: {\n assetValue: AssetValue;\n payoutAddress?: string;\n name: string;\n ownerAddress: string;\n }) {\n const payout = payoutAddress || getWallet(assetValue.chain as CryptoChain)?.address;\n\n if (!payout) {\n throw new SwapKitError(\"thorchain_preferred_asset_payout_required\");\n }\n\n return depositToProtocol({\n assetValue: AssetValue.from({ chain: pluginChain }),\n memo: getMemoForNamePreferredAssetRegister({\n asset: assetValue.toString(),\n chain: assetValue.chain,\n name,\n owner: ownerAddress,\n payout,\n }),\n });\n }\n\n function nodeAction({ type, assetValue, address }: NodeActionParams) {\n const memo =\n type === MemoType.UNBOND\n ? getMemoForUnbond({ address, unbondAmount: assetValue.getBaseValue(\"number\") })\n : getMemoForLeaveAndBond({ type, address });\n\n const assetToTransfer =\n type === MemoType.BOND ? assetValue : getMinAmountByChain(pluginChain);\n return depositToProtocol({ memo, assetValue: assetToTransfer });\n }\n\n async function createLiquidity({ baseAssetValue, assetValue }: CreateLiquidityParams) {\n if (baseAssetValue.lte(0) || assetValue.lte(0)) {\n throw new SwapKitError(\"core_transaction_create_liquidity_invalid_params\");\n }\n\n const assetAddress = getWallet(assetValue.chain as CryptoChain).address;\n const baseAssetAddress = getWallet(pluginChain).address;\n\n const baseAssetTx = await wrapWithThrow(() => {\n return depositToPool({\n assetValue: baseAssetValue,\n memo: getMemoForDeposit({ ...assetValue, address: assetAddress }),\n });\n }, \"core_transaction_create_liquidity_base_error\");\n\n const assetTx = await wrapWithThrow(() => {\n return depositToPool({\n assetValue,\n memo: getMemoForDeposit({ ...assetValue, address: baseAssetAddress }),\n });\n }, \"core_transaction_create_liquidity_asset_error\");\n\n return { baseAssetTx, assetTx };\n }\n\n function addLiquidityPart({\n assetValue,\n poolAddress,\n address,\n symmetric,\n }: AddLiquidityPartParams) {\n if (symmetric && !address) {\n throw new SwapKitError(\"core_transaction_add_liquidity_invalid_params\");\n }\n const memo = getMemoForDeposit({\n chain: poolAddress.split(\".\")[0] as Chain,\n symbol: poolAddress.split(\".\")[1] as string,\n address: symmetric ? address : \"\",\n });\n\n return depositToPool({ assetValue, memo });\n }\n\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO: Refactor\n async function addLiquidity({\n baseAssetValue,\n assetValue,\n baseAssetAddr,\n assetAddr,\n isPendingSymmAsset,\n mode = \"sym\",\n }: AddLiquidityParams) {\n const { chain, symbol } = assetValue;\n const isSym = mode === \"sym\";\n const baseTransfer = baseAssetValue?.gt(0) && (isSym || mode === \"baseAsset\");\n const assetTransfer = assetValue?.gt(0) && (isSym || mode === \"asset\");\n const includeBaseAddress = isPendingSymmAsset || baseTransfer;\n const baseAssetWalletAddress = getWallet(pluginChain).address;\n\n const baseAddress = includeBaseAddress ? baseAssetAddr || baseAssetWalletAddress : \"\";\n const assetAddress =\n isSym || mode === \"asset\" ? assetAddr || getWallet(chain as CryptoChain).address : \"\";\n\n if (!(baseTransfer || assetTransfer)) {\n throw new SwapKitError(\"core_transaction_add_liquidity_invalid_params\");\n }\n if (includeBaseAddress && !baseAddress) {\n throw new SwapKitError(\"core_transaction_add_liquidity_base_address\");\n }\n\n const baseAssetTx =\n baseTransfer && baseAssetValue\n ? await wrapWithThrow(() => {\n return depositToPool({\n assetValue: baseAssetValue,\n memo: getMemoForDeposit({ chain, symbol, address: assetAddress }),\n });\n }, \"core_transaction_add_liquidity_base_error\")\n : undefined;\n\n const assetTx =\n assetTransfer && assetValue\n ? await wrapWithThrow(() => {\n return depositToPool({\n assetValue,\n memo: getMemoForDeposit({ chain, symbol, address: baseAddress }),\n });\n }, \"core_transaction_add_liquidity_asset_error\")\n : undefined;\n\n return { baseAssetTx, assetTx };\n }\n\n function savings({ assetValue, memo, percent, type }: SavingsParams) {\n const { chain, symbol } = assetValue;\n const isDeposit = type === \"add\";\n const memoString = isDeposit\n ? getMemoForSaverDeposit({ symbol, chain })\n : getMemoForSaverWithdraw({\n basisPoints: Math.min(10000, Math.round(percent * 100)),\n symbol,\n chain,\n });\n\n return depositToPool({\n memo: memo || memoString,\n assetValue: isDeposit ? assetValue : getMinAmountByChain(chain),\n });\n }\n\n function withdraw({ memo, assetValue, percent, from, to }: WithdrawParams) {\n const targetAsset =\n to === \"baseAsset\" && from !== \"baseAsset\"\n ? AssetValue.from({ chain: pluginChain })\n : (from === \"sym\" && to === \"sym\") || from === \"baseAsset\" || from === \"asset\"\n ? undefined\n : assetValue;\n\n const value = getMinAmountByChain(from === \"asset\" ? assetValue.chain : pluginChain);\n const memoString =\n memo ||\n getMemoForWithdraw({\n symbol: assetValue.symbol,\n chain: assetValue.chain,\n ticker: assetValue.ticker,\n basisPoints: Math.min(10000, Math.round(percent * 100)),\n targetAsset: targetAsset?.toString(),\n });\n\n return depositToPool({ assetValue: value, memo: memoString });\n }\n\n async function swap({\n feeOptionKey,\n route,\n }: SwapParams<typeof pluginType, QuoteResponseRoute>) {\n const { memo, expiration, targetAddress } = route;\n\n const assetValue = await AssetValue.from({\n asyncTokenLookup: true,\n asset: route.sellAsset,\n value: route.sellAmount,\n });\n\n if (!assetValue) {\n throw new SwapKitError(\"core_swap_asset_not_recognized\");\n }\n\n const isRecipientValidated = validateAddressType({\n address: route.destinationAddress,\n chain: AssetValue.from({ asset: route.buyAsset }).chain,\n });\n\n if (!isRecipientValidated) {\n throw new SwapKitError(\"core_transaction_invalid_recipient_address\");\n }\n\n const { address: recipient } = await getInboundDataByChain(assetValue.chain);\n\n return deposit({\n expiration: Number(expiration),\n assetValue,\n memo,\n feeOptionKey,\n router: targetAddress,\n recipient,\n });\n }\n\n return {\n addLiquidity,\n addLiquidityPart,\n approveAssetValue,\n createLiquidity,\n deposit,\n depositToPool,\n getInboundDataByChain,\n isAssetValueApproved,\n nodeAction,\n registerName,\n registerPreferredAsset,\n savings,\n swap,\n withdraw,\n };\n };\n}\n",
|
|
6
|
-
"import { Chain } from \"@swapkit/helpers\";\nimport type { CoreTxParams } from \"./types\";\n\nexport function validateAddressType({ chain, address }: { chain?: Chain; address?: string }) {\n if (!address) return false;\n\n
|
|
5
|
+
"import {\n ApproveMode,\n type ApproveReturnType,\n AssetValue,\n Chain,\n type CryptoChain,\n type EVMChain,\n EVMChains,\n type ErrorKeys,\n FeeOption,\n MemoType,\n ProviderName,\n SwapKitError,\n type SwapKitPluginParams,\n type SwapParams,\n createPlugin,\n getMemoForDeposit,\n getMemoForLeaveAndBond,\n getMemoForNamePreferredAssetRegister,\n getMemoForNameRegister,\n getMemoForUnbond,\n getMemoForWithdraw,\n getMinAmountByChain,\n wrapWithThrow,\n} from \"@swapkit/helpers\";\nimport { type QuoteResponseRoute, SwapKitApi, type THORNodeType } from \"@swapkit/helpers/api\";\nimport {\n MayaArbitrumVaultAbi,\n MayaEthereumVaultAbi,\n TCAvalancheDepositABI,\n TCBaseDepositABI,\n TCBscDepositABI,\n TCEthereumVaultAbi,\n} from \"@swapkit/helpers/contracts\";\nimport { prepareTxParams, validateAddressType } from \"./shared\";\nimport type {\n AddLiquidityParams,\n AddLiquidityPartParams,\n CoreTxParams,\n CreateLiquidityParams,\n NodeActionParams,\n RegisterThornameParams,\n WithdrawParams,\n} from \"./types\";\n\nconst gasFeeMultiplier: Record<FeeOption, number> = {\n [FeeOption.Average]: 1.2,\n [FeeOption.Fast]: 1.5,\n [FeeOption.Fastest]: 2,\n};\n\nconst TCSpecificAbi = {\n [Chain.Avalanche]: TCAvalancheDepositABI,\n [Chain.Base]: TCBaseDepositABI,\n [Chain.BinanceSmartChain]: TCBscDepositABI,\n [Chain.Ethereum]: TCEthereumVaultAbi,\n};\n\nconst MayaSpecificAbi = {\n [Chain.Arbitrum]: MayaArbitrumVaultAbi,\n [Chain.Ethereum]: MayaEthereumVaultAbi,\n};\n\nexport const ThorchainPlugin = createPlugin({\n name: \"thorchain\",\n methods: createTCBasedPlugin(Chain.THORChain),\n properties: {\n supportedSwapkitProviders: [ProviderName.THORCHAIN, ProviderName.THORCHAIN_STREAMING],\n },\n});\n\nexport const MayachainPlugin = createPlugin({\n name: \"mayachain\",\n methods: createTCBasedPlugin(Chain.Maya),\n properties: {\n supportedSwapkitProviders: [ProviderName.MAYACHAIN],\n },\n});\n\nfunction getInboundDataFunction(type?: THORNodeType) {\n return async function getInboundDataByChain<T extends Chain>(chain: T) {\n if (\n (type === \"thorchain\" && chain === Chain.THORChain) ||\n (type === \"mayachain\" && chain === Chain.Maya)\n ) {\n return { gas_rate: \"0\", router: \"\", address: \"\", halted: false, chain };\n }\n\n const inboundData = await SwapKitApi.thornode.getInboundAddresses(type);\n const chainAddressData = inboundData.find((item) => item.chain === chain);\n\n if (!chainAddressData) throw new SwapKitError(\"core_inbound_data_not_found\");\n if (chainAddressData?.halted) throw new SwapKitError(\"core_chain_halted\");\n\n return chainAddressData;\n };\n}\n\ntype PluginChain = Chain.Maya | Chain.THORChain;\n\nfunction createTCBasedPlugin<T extends PluginChain>(pluginChain: T) {\n return function plugin({ getWallet }: SwapKitPluginParams) {\n const pluginType = pluginChain === Chain.Maya ? \"mayachain\" : \"thorchain\";\n const getInboundDataByChain = getInboundDataFunction(pluginType);\n\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO: refactor/split\n async function approve<T extends ApproveMode>({\n assetValue,\n type = \"checkOnly\" as T,\n }: { type: T; assetValue: AssetValue }) {\n const router = (await getInboundDataByChain(assetValue.chain)).router as string;\n\n const chain = assetValue.chain as EVMChain;\n\n const isEVMChain = EVMChains.includes(chain as EVMChain);\n const isNativeEVM = isEVMChain && assetValue.isGasAsset;\n\n if (isNativeEVM || !isEVMChain || assetValue.isSynthetic) {\n return Promise.resolve(type === \"checkOnly\" ? true : \"approved\") as ApproveReturnType<T>;\n }\n\n const wallet = getWallet(chain);\n\n if (!wallet) {\n throw new SwapKitError(\"core_wallet_connection_not_found\");\n }\n\n const walletAction = type === \"checkOnly\" ? wallet.isApproved : wallet.approve;\n\n if (!(assetValue.address && wallet.address)) {\n throw new SwapKitError(\"core_approve_asset_address_or_from_not_found\");\n }\n\n return walletAction({\n amount: assetValue.getBaseValue(\"bigint\"),\n assetAddress: assetValue.address,\n from: wallet.address,\n spenderAddress: router,\n });\n }\n\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO refactor\n async function deposit({\n assetValue,\n recipient,\n router,\n ...rest\n }: CoreTxParams & { router?: string }) {\n const abis = pluginType === \"thorchain\" ? TCSpecificAbi : MayaSpecificAbi;\n const { chain, symbol, ticker } = assetValue;\n\n const wallet = getWallet(chain as CryptoChain);\n if (!wallet) {\n throw new SwapKitError(\"core_wallet_connection_not_found\");\n }\n const { address } = wallet;\n const isAddressValidated = validateAddressType({ address, chain });\n if (!isAddressValidated) {\n throw new SwapKitError(\"core_transaction_invalid_sender_address\");\n }\n\n const params = prepareTxParams({ from: address, assetValue, recipient, router, ...rest });\n\n try {\n const abi = abis?.[chain as keyof typeof abis];\n\n if (!abi) {\n const wallet = getWallet(chain as PluginChain);\n const shouldDeposit = pluginChain === chain && recipient === \"\";\n // @Towan: Is that the same action? :)\n return shouldDeposit ? wallet.deposit(params) : wallet.transfer(params);\n }\n\n const { getChecksumAddressFromAsset } = await import(\"@swapkit/toolboxes/evm\");\n const wallet = getWallet(chain as EVMChain);\n\n return wallet.call<string>({\n abi,\n contractAddress: router || ((await getInboundDataByChain(chain)).router as string),\n funcName: \"depositWithExpiry\",\n funcParams: [\n recipient,\n getChecksumAddressFromAsset({ chain, symbol, ticker }, chain as EVMChain),\n assetValue.getBaseValue(\"string\"),\n params.memo,\n rest.expiration || Number.parseInt(`${(Date.now() + 15 * 60 * 1000) / 1000}`),\n ],\n txOverrides: {\n from: params.from,\n value: assetValue.isGasAsset ? assetValue.getBaseValue(\"bigint\") : undefined,\n },\n });\n } catch (error) {\n const errorMessage =\n // @ts-expect-error Fine to use error as string\n typeof error === \"string\" ? error.toLowerCase() : error?.message.toLowerCase();\n const isInsufficientFunds = errorMessage?.includes(\"insufficient funds\");\n const isGas = errorMessage?.includes(\"gas\");\n const isServer = errorMessage?.includes(\"server\");\n const isUserRejected = errorMessage?.includes(\"user rejected\");\n const errorKey: ErrorKeys = isInsufficientFunds\n ? \"core_transaction_deposit_insufficient_funds_error\"\n : isGas\n ? \"core_transaction_deposit_gas_error\"\n : isServer\n ? \"core_transaction_deposit_server_error\"\n : isUserRejected\n ? \"core_transaction_user_rejected\"\n : \"core_transaction_deposit_error\";\n\n throw new SwapKitError(errorKey, error);\n }\n }\n\n async function depositToProtocol({\n memo,\n assetValue,\n }: { assetValue: AssetValue; memo: string }) {\n const mimir = await SwapKitApi.thornode.getMimirInfo(pluginType);\n\n // check if trading is halted or not\n if (mimir.HALTCHAINGLOBAL >= 1 || mimir.HALTTHORCHAIN >= 1) {\n throw new SwapKitError(\"thorchain_chain_halted\");\n }\n\n return deposit({ assetValue, recipient: \"\", memo });\n }\n\n async function depositToPool({\n assetValue,\n memo,\n feeOptionKey = FeeOption.Fast,\n }: { assetValue: AssetValue; memo: string; feeOptionKey?: FeeOption }) {\n const {\n gas_rate = \"0\",\n router,\n address: poolAddress,\n } = await getInboundDataByChain(assetValue.chain);\n\n return deposit({\n assetValue,\n recipient: poolAddress,\n memo,\n router,\n feeRate: Number.parseInt(gas_rate) * gasFeeMultiplier[feeOptionKey],\n });\n }\n\n function approveAssetValue({ assetValue }: { assetValue: AssetValue }) {\n return approve({ assetValue, type: ApproveMode.Approve });\n }\n\n function isAssetValueApproved({ assetValue }: { assetValue: AssetValue }) {\n return approve({ assetValue, type: ApproveMode.CheckOnly });\n }\n\n function registerName({ assetValue, ...params }: RegisterThornameParams) {\n return depositToProtocol({ assetValue, memo: getMemoForNameRegister(params) });\n }\n\n function registerPreferredAsset({\n assetValue,\n payoutAddress,\n name,\n ownerAddress,\n }: {\n assetValue: AssetValue;\n payoutAddress?: string;\n name: string;\n ownerAddress: string;\n }) {\n const payout = payoutAddress || getWallet(assetValue.chain as CryptoChain)?.address;\n\n if (!payout) {\n throw new SwapKitError(\"thorchain_preferred_asset_payout_required\");\n }\n\n return depositToProtocol({\n assetValue: AssetValue.from({ chain: pluginChain }),\n memo: getMemoForNamePreferredAssetRegister({\n asset: assetValue.toString(),\n chain: assetValue.chain,\n name,\n owner: ownerAddress,\n payout,\n }),\n });\n }\n\n function nodeAction({ type, assetValue, address }: NodeActionParams) {\n const memo =\n type === MemoType.UNBOND\n ? getMemoForUnbond({ address, unbondAmount: assetValue.getBaseValue(\"number\") })\n : getMemoForLeaveAndBond({ type, address });\n\n const assetToTransfer =\n type === MemoType.BOND ? assetValue : getMinAmountByChain(pluginChain);\n return depositToProtocol({ memo, assetValue: assetToTransfer });\n }\n\n async function createLiquidity({ baseAssetValue, assetValue }: CreateLiquidityParams) {\n if (baseAssetValue.lte(0) || assetValue.lte(0)) {\n throw new SwapKitError(\"core_transaction_create_liquidity_invalid_params\");\n }\n\n const assetAddress = getWallet(assetValue.chain as CryptoChain).address;\n const baseAssetAddress = getWallet(pluginChain).address;\n\n const baseAssetTx = await wrapWithThrow(() => {\n return depositToPool({\n assetValue: baseAssetValue,\n memo: getMemoForDeposit({ ...assetValue, address: assetAddress }),\n });\n }, \"core_transaction_create_liquidity_base_error\");\n\n const assetTx = await wrapWithThrow(() => {\n return depositToPool({\n assetValue,\n memo: getMemoForDeposit({ ...assetValue, address: baseAssetAddress }),\n });\n }, \"core_transaction_create_liquidity_asset_error\");\n\n return { baseAssetTx, assetTx };\n }\n\n function addLiquidityPart({\n assetValue,\n poolAddress,\n address,\n symmetric,\n }: AddLiquidityPartParams) {\n if (symmetric && !address) {\n throw new SwapKitError(\"core_transaction_add_liquidity_invalid_params\");\n }\n const memo = getMemoForDeposit({\n chain: poolAddress.split(\".\")[0] as Chain,\n symbol: poolAddress.split(\".\")[1] as string,\n address: symmetric ? address : \"\",\n });\n\n return depositToPool({ assetValue, memo });\n }\n\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO: Refactor\n async function addLiquidity({\n baseAssetValue,\n assetValue,\n baseAssetAddr,\n assetAddr,\n isPendingSymmAsset,\n mode = \"sym\",\n }: AddLiquidityParams) {\n const { chain, symbol } = assetValue;\n const isSym = mode === \"sym\";\n const baseTransfer = baseAssetValue?.gt(0) && (isSym || mode === \"baseAsset\");\n const assetTransfer = assetValue?.gt(0) && (isSym || mode === \"asset\");\n const includeBaseAddress = isPendingSymmAsset || baseTransfer;\n const baseAssetWalletAddress = getWallet(pluginChain).address;\n\n const baseAddress = includeBaseAddress ? baseAssetAddr || baseAssetWalletAddress : \"\";\n const assetAddress =\n isSym || mode === \"asset\" ? assetAddr || getWallet(chain as CryptoChain).address : \"\";\n\n if (!(baseTransfer || assetTransfer)) {\n throw new SwapKitError(\"core_transaction_add_liquidity_invalid_params\");\n }\n if (includeBaseAddress && !baseAddress) {\n throw new SwapKitError(\"core_transaction_add_liquidity_base_address\");\n }\n\n const baseAssetTx =\n baseTransfer && baseAssetValue\n ? await wrapWithThrow(() => {\n return depositToPool({\n assetValue: baseAssetValue,\n memo: getMemoForDeposit({ chain, symbol, address: assetAddress }),\n });\n }, \"core_transaction_add_liquidity_base_error\")\n : undefined;\n\n const assetTx =\n assetTransfer && assetValue\n ? await wrapWithThrow(() => {\n return depositToPool({\n assetValue,\n memo: getMemoForDeposit({ chain, symbol, address: baseAddress }),\n });\n }, \"core_transaction_add_liquidity_asset_error\")\n : undefined;\n\n return { baseAssetTx, assetTx };\n }\n\n function withdraw({ memo, assetValue, percent, from, to }: WithdrawParams) {\n const targetAsset =\n to === \"baseAsset\" && from !== \"baseAsset\"\n ? AssetValue.from({ chain: pluginChain })\n : (from === \"sym\" && to === \"sym\") || from === \"baseAsset\" || from === \"asset\"\n ? undefined\n : assetValue;\n\n const value = getMinAmountByChain(from === \"asset\" ? assetValue.chain : pluginChain);\n const memoString =\n memo ||\n getMemoForWithdraw({\n symbol: assetValue.symbol,\n chain: assetValue.chain,\n ticker: assetValue.ticker,\n basisPoints: Math.min(10000, Math.round(percent * 100)),\n targetAsset: targetAsset?.toString(),\n });\n\n return depositToPool({ assetValue: value, memo: memoString });\n }\n\n async function swap({\n feeOptionKey,\n route,\n }: SwapParams<typeof pluginType, QuoteResponseRoute>) {\n const { memo, expiration, targetAddress } = route;\n\n const assetValue = await AssetValue.from({\n asyncTokenLookup: true,\n asset: route.sellAsset,\n value: route.sellAmount,\n });\n\n if (!assetValue) {\n throw new SwapKitError(\"core_swap_asset_not_recognized\");\n }\n\n const isRecipientValidated = validateAddressType({\n address: route.destinationAddress,\n chain: AssetValue.from({ asset: route.buyAsset }).chain,\n });\n\n if (!isRecipientValidated) {\n throw new SwapKitError(\"core_transaction_invalid_recipient_address\");\n }\n\n const { address: recipient } = await getInboundDataByChain(assetValue.chain);\n\n return deposit({\n expiration: Number(expiration),\n assetValue,\n memo,\n feeOptionKey,\n router: targetAddress,\n recipient,\n });\n }\n\n return {\n addLiquidity,\n addLiquidityPart,\n approveAssetValue,\n createLiquidity,\n deposit,\n depositToPool,\n getInboundDataByChain,\n isAssetValueApproved,\n nodeAction,\n registerName,\n registerPreferredAsset,\n swap,\n withdraw,\n };\n };\n}\n",
|
|
6
|
+
"import { Chain } from \"@swapkit/helpers\";\nimport type { CoreTxParams } from \"./types\";\n\nexport function validateAddressType({ chain, address }: { chain?: Chain; address?: string }) {\n if (!address) return false;\n\n return chain === Chain.Bitcoin ? !address.startsWith(\"bc1p\") : true;\n}\n\nexport function prepareTxParams({\n assetValue,\n from,\n memo = \"\",\n ...restTxParams\n}: CoreTxParams & { from: string; router?: string }) {\n return { ...restTxParams, memo, from, assetValue };\n}\n"
|
|
7
7
|
],
|
|
8
|
-
"mappings": "
|
|
9
|
-
"debugId": "
|
|
8
|
+
"mappings": "iDAAA,sBACE,gBAEA,WACA,eAGA,gBAEA,cACA,kBACA,kBACA,kBAGA,uBACA,4BACA,2CACA,6BACA,uBACA,yBACA,0BACA,mBACA,yBAEF,qBAAkC,6BAClC,+BACE,2BACA,4BACA,uBACA,sBACA,yBACA,oCChCF,gBAAS,yBAGF,SAAS,CAAmB,EAAG,QAAO,WAAgD,CAC3F,IAAK,EAAS,MAAO,GAErB,OAAO,IAAU,EAAM,SAAW,EAAQ,WAAW,MAAM,EAAI,GAG1D,SAAS,CAAe,EAC7B,aACA,OACA,OAAO,MACJ,GACgD,CACnD,MAAO,IAAK,EAAc,OAAM,OAAM,YAAW,ED8BnD,IAAM,GAA8C,EACjD,EAAU,SAAU,KACpB,EAAU,MAAO,KACjB,EA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Ae,CAAI,EACjB,eACA,SACoD,CACpD,IAAQ,OAAM,aAAY,iBAAkB,EAEtC,EAAa,MAAM,EAAW,KAAK,CACvC,iBAAkB,GAClB,MAAO,EAAM,UACb,MAAO,EAAM,UACf,CAAC,EAED,IAAK,EACH,MAAM,IAAI,EAAa,gCAAgC,EAQzD,IAL6B,EAAoB,CAC/C,QAAS,EAAM,mBACf,MAAO,EAAW,KAAK,CAAE,MAAO,EAAM,QAAS,CAAC,EAAE,KACpD,CAAC,EAGC,MAAM,IAAI,EAAa,4CAA4C,EAGrE,IAAQ,QAAS,GAAc,MAAM,EAAsB,EAAW,KAAK,EAE3E,OAAO,EAAQ,CACb,WAAY,OAAO,CAAU,EAC7B,aACA,OACA,eACA,OAAQ,EACR,WACF,CAAC,EAGH,MAAO,CACL,eACA,mBACA,oBACA,kBACA,UACA,gBACA,wBACA,uBACA,aACA,eACA,yBACA,OACA,UACF",
|
|
9
|
+
"debugId": "9E969DDFEF3179D664756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "swapkit-oss",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@polkadot/keyring": "13.
|
|
5
|
-
"@polkadot/util": "13.
|
|
4
|
+
"@polkadot/keyring": "^13.5.0",
|
|
5
|
+
"@polkadot/util": "^13.5.0",
|
|
6
|
+
"@solana/web3.js": "^1.98.0",
|
|
7
|
+
"@swapkit/helpers": "^4.0.0-beta.24",
|
|
8
|
+
"@swapkit/toolboxes": "^4.0.0-beta.36",
|
|
9
|
+
"ts-pattern": "^5.0.0"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@polkadot/keyring": "13.5.3",
|
|
13
|
+
"@polkadot/util": "13.5.3",
|
|
6
14
|
"@solana/web3.js": "1.98.2",
|
|
7
|
-
"
|
|
8
|
-
"@swapkit/toolboxes": "1.0.0-beta.9",
|
|
9
|
-
"ts-pattern": "5.7.0"
|
|
15
|
+
"ts-pattern": "5.7.1"
|
|
10
16
|
},
|
|
11
|
-
"description": "SwapKit Plugin -
|
|
17
|
+
"description": "SwapKit Plugin - Chainflip",
|
|
12
18
|
"exports": {
|
|
13
19
|
".": {
|
|
14
20
|
"default": "./dist/index.js",
|
|
@@ -25,10 +31,10 @@
|
|
|
25
31
|
"require": "./dist/evm/index.cjs",
|
|
26
32
|
"types": "./src/evm/index.ts"
|
|
27
33
|
},
|
|
28
|
-
"./
|
|
29
|
-
"default": "./dist/
|
|
30
|
-
"require": "./dist/
|
|
31
|
-
"types": "./src/
|
|
34
|
+
"./near": {
|
|
35
|
+
"default": "./dist/near/index.js",
|
|
36
|
+
"require": "./dist/near/index.cjs",
|
|
37
|
+
"types": "./src/near/index.ts"
|
|
32
38
|
},
|
|
33
39
|
"./radix": {
|
|
34
40
|
"default": "./dist/radix/index.js",
|
|
@@ -62,11 +68,9 @@
|
|
|
62
68
|
"build": "bun run ./build.ts",
|
|
63
69
|
"build:clean": "rm -rf dist && bun run ./build.ts",
|
|
64
70
|
"clean": "rm -rf dist node_modules *.tsbuildinfo",
|
|
65
|
-
"test": "echo 'bun test'",
|
|
66
|
-
"test:ci": "bun test --coverage",
|
|
67
71
|
"type-check": "bun tsc --noEmit",
|
|
68
72
|
"type-check:go": "tsgo"
|
|
69
73
|
},
|
|
70
74
|
"type": "module",
|
|
71
|
-
"version": "
|
|
75
|
+
"version": "4.0.0-beta.36"
|
|
72
76
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { parseNearAmount } from "near-api-js/lib/utils/format";
|
|
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
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AssetValue,
|
|
3
|
+
Chain,
|
|
4
|
+
ProviderName,
|
|
5
|
+
SwapKitError,
|
|
6
|
+
type SwapParams,
|
|
7
|
+
createPlugin,
|
|
8
|
+
} from "@swapkit/helpers";
|
|
9
|
+
import { SwapKitApi } from "@swapkit/helpers/api";
|
|
10
|
+
import type { NearWallet } from "@swapkit/toolboxes/near";
|
|
11
|
+
import { calculateNearNameCost, validateNearName } from "./nearNames";
|
|
12
|
+
import type {
|
|
13
|
+
NearDepositChannelParams,
|
|
14
|
+
NearNameRegistrationParams,
|
|
15
|
+
NearSwapResponse,
|
|
16
|
+
NearSwapRoute,
|
|
17
|
+
} from "./types";
|
|
18
|
+
|
|
19
|
+
export const NearPlugin = createPlugin({
|
|
20
|
+
name: "near",
|
|
21
|
+
properties: {
|
|
22
|
+
supportedSwapkitProviders: [ProviderName.NEAR],
|
|
23
|
+
},
|
|
24
|
+
methods: ({ getWallet }) => ({
|
|
25
|
+
async swap({
|
|
26
|
+
route,
|
|
27
|
+
recipient,
|
|
28
|
+
}: SwapParams<{
|
|
29
|
+
route: NearSwapRoute & {
|
|
30
|
+
meta?: {
|
|
31
|
+
nearSwapInfo?: NearDepositChannelParams;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
}>) {
|
|
35
|
+
const { meta } = route as any;
|
|
36
|
+
if (!meta?.nearSwapInfo) {
|
|
37
|
+
throw new SwapKitError("core_swap_invalid_params", {
|
|
38
|
+
message: "Missing NEAR swap metadata",
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const nearSwapInfo = meta.nearSwapInfo;
|
|
43
|
+
const srcWallet = await getWallet(nearSwapInfo.srcChain);
|
|
44
|
+
|
|
45
|
+
const nearDepositChannelParams: NearDepositChannelParams = {
|
|
46
|
+
...nearSwapInfo,
|
|
47
|
+
toAddress: recipient || (await srcWallet.getAddress()),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// TODO: UPSTREAM getNearDepositChannel in SwapKitApi from v3 branch
|
|
51
|
+
const response = await (SwapKitApi as any).getNearDepositChannel?.(nearDepositChannelParams);
|
|
52
|
+
if (!response) {
|
|
53
|
+
throw new SwapKitError("core_plugin_not_found", {
|
|
54
|
+
info: "NEAR deposit channel API not implemented",
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const nearResponse = response as NearSwapResponse;
|
|
58
|
+
|
|
59
|
+
if (!nearResponse.isSuccess) {
|
|
60
|
+
throw new SwapKitError("core_swap_invalid_params", {
|
|
61
|
+
message: "Failed to create NEAR deposit channel",
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const { channelId, depositAddress } = nearResponse.response;
|
|
66
|
+
|
|
67
|
+
const assetValue = AssetValue.from({
|
|
68
|
+
chain: nearSwapInfo.srcChain,
|
|
69
|
+
symbol: nearSwapInfo.srcToken,
|
|
70
|
+
value: nearSwapInfo.amount,
|
|
71
|
+
decimal: (route as any).srcToken.decimals,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const txHash = await srcWallet.transfer({
|
|
75
|
+
assetValue,
|
|
76
|
+
recipient: depositAddress,
|
|
77
|
+
memo: channelId,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return txHash;
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
// NEAR Names functionality
|
|
84
|
+
nearNames: {
|
|
85
|
+
async resolve(name: string) {
|
|
86
|
+
try {
|
|
87
|
+
const normalizedName = name.toLowerCase().replace(/\.near$/, "");
|
|
88
|
+
|
|
89
|
+
if (!validateNearName(normalizedName)) {
|
|
90
|
+
throw new SwapKitError("plugin_near_invalid_name");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const wallet = getWallet(Chain.Near);
|
|
94
|
+
|
|
95
|
+
if (!wallet) {
|
|
96
|
+
throw new SwapKitError("plugin_near_no_connection");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const result = await wallet.provider.query({
|
|
100
|
+
request_type: "call_function",
|
|
101
|
+
finality: "final",
|
|
102
|
+
account_id: "near",
|
|
103
|
+
method_name: "resolve",
|
|
104
|
+
args_base64: Buffer.from(JSON.stringify({ name: normalizedName })).toString("base64"),
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const response = JSON.parse(Buffer.from((result as any).result).toString());
|
|
108
|
+
return response?.owner || null;
|
|
109
|
+
} catch {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
async isAvailable(name: string) {
|
|
115
|
+
const owner = await this.resolve(name);
|
|
116
|
+
return owner === null;
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
async getInfo(name: string) {
|
|
120
|
+
try {
|
|
121
|
+
const normalizedName = name.toLowerCase().replace(/\.near$/, "");
|
|
122
|
+
|
|
123
|
+
if (!validateNearName(normalizedName)) {
|
|
124
|
+
throw new SwapKitError("plugin_near_invalid_name");
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const wallet = getWallet(Chain.Near);
|
|
128
|
+
|
|
129
|
+
if (!wallet) {
|
|
130
|
+
throw new SwapKitError("plugin_near_no_connection");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const result = await wallet.provider.query({
|
|
134
|
+
request_type: "call_function",
|
|
135
|
+
finality: "final",
|
|
136
|
+
account_id: "near",
|
|
137
|
+
method_name: "get_info",
|
|
138
|
+
args_base64: Buffer.from(JSON.stringify({ name: normalizedName })).toString("base64"),
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const response = JSON.parse(Buffer.from((result as any).result).toString());
|
|
142
|
+
return response || null;
|
|
143
|
+
} catch {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
async lookupNames(accountId: string) {
|
|
149
|
+
try {
|
|
150
|
+
const wallet = getWallet(Chain.Near);
|
|
151
|
+
|
|
152
|
+
if (!wallet) {
|
|
153
|
+
throw new SwapKitError("plugin_near_no_connection");
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const result = await wallet.provider.query({
|
|
157
|
+
request_type: "call_function",
|
|
158
|
+
finality: "final",
|
|
159
|
+
account_id: "near",
|
|
160
|
+
method_name: "get_names_by_owner",
|
|
161
|
+
args_base64: Buffer.from(JSON.stringify({ account_id: accountId })).toString("base64"),
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const response = JSON.parse(Buffer.from((result as any).result).toString());
|
|
165
|
+
return Array.isArray(response) ? response.map((n) => `${n}.near`) : [];
|
|
166
|
+
} catch {
|
|
167
|
+
return [];
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
async register(params: NearNameRegistrationParams) {
|
|
172
|
+
const { name, publicKey: publicKeyOverwrite } = params;
|
|
173
|
+
const normalizedName = name.toLowerCase().replace(/\.near$/, "");
|
|
174
|
+
|
|
175
|
+
if (!validateNearName(normalizedName)) {
|
|
176
|
+
throw new SwapKitError("plugin_near_invalid_name");
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const wallet = getWallet(Chain.Near) as NearWallet;
|
|
180
|
+
|
|
181
|
+
const newPublicKey = publicKeyOverwrite || (await wallet.getPublicKey());
|
|
182
|
+
|
|
183
|
+
const cost = calculateNearNameCost(normalizedName);
|
|
184
|
+
|
|
185
|
+
return wallet.callFunction({
|
|
186
|
+
contractId: "near",
|
|
187
|
+
methodName: "create_account",
|
|
188
|
+
args: {
|
|
189
|
+
new_account_id: `${normalizedName}.near`,
|
|
190
|
+
new_public_key: newPublicKey,
|
|
191
|
+
},
|
|
192
|
+
deposit: cost,
|
|
193
|
+
});
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
transfer(name: string, newOwner: string) {
|
|
197
|
+
const normalizedName = name.toLowerCase().replace(/\.near$/, "");
|
|
198
|
+
|
|
199
|
+
if (!validateNearName(normalizedName)) {
|
|
200
|
+
throw new SwapKitError("plugin_near_invalid_name");
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const wallet = getWallet(Chain.Near) as NearWallet;
|
|
204
|
+
|
|
205
|
+
return wallet.callFunction({
|
|
206
|
+
contractId: "near",
|
|
207
|
+
methodName: "transfer",
|
|
208
|
+
args: {
|
|
209
|
+
name: normalizedName,
|
|
210
|
+
new_owner: newOwner,
|
|
211
|
+
},
|
|
212
|
+
deposit: "1",
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
}),
|
|
217
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
};
|
|
56
|
+
|
|
57
|
+
export type NearNameInfo = {
|
|
58
|
+
owner: string;
|
|
59
|
+
price?: string;
|
|
60
|
+
expiresAt?: string;
|
|
61
|
+
registeredAt?: string;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type NearNameRegistrationParams = {
|
|
65
|
+
name: string;
|
|
66
|
+
publicKey?: string;
|
|
67
|
+
};
|
package/src/thorchain/plugin.ts
CHANGED
|
@@ -18,8 +18,6 @@ import {
|
|
|
18
18
|
getMemoForLeaveAndBond,
|
|
19
19
|
getMemoForNamePreferredAssetRegister,
|
|
20
20
|
getMemoForNameRegister,
|
|
21
|
-
getMemoForSaverDeposit,
|
|
22
|
-
getMemoForSaverWithdraw,
|
|
23
21
|
getMemoForUnbond,
|
|
24
22
|
getMemoForWithdraw,
|
|
25
23
|
getMinAmountByChain,
|
|
@@ -42,7 +40,6 @@ import type {
|
|
|
42
40
|
CreateLiquidityParams,
|
|
43
41
|
NodeActionParams,
|
|
44
42
|
RegisterThornameParams,
|
|
45
|
-
SavingsParams,
|
|
46
43
|
WithdrawParams,
|
|
47
44
|
} from "./types";
|
|
48
45
|
|
|
@@ -394,23 +391,6 @@ function createTCBasedPlugin<T extends PluginChain>(pluginChain: T) {
|
|
|
394
391
|
return { baseAssetTx, assetTx };
|
|
395
392
|
}
|
|
396
393
|
|
|
397
|
-
function savings({ assetValue, memo, percent, type }: SavingsParams) {
|
|
398
|
-
const { chain, symbol } = assetValue;
|
|
399
|
-
const isDeposit = type === "add";
|
|
400
|
-
const memoString = isDeposit
|
|
401
|
-
? getMemoForSaverDeposit({ symbol, chain })
|
|
402
|
-
: getMemoForSaverWithdraw({
|
|
403
|
-
basisPoints: Math.min(10000, Math.round(percent * 100)),
|
|
404
|
-
symbol,
|
|
405
|
-
chain,
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
return depositToPool({
|
|
409
|
-
memo: memo || memoString,
|
|
410
|
-
assetValue: isDeposit ? assetValue : getMinAmountByChain(chain),
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
|
|
414
394
|
function withdraw({ memo, assetValue, percent, from, to }: WithdrawParams) {
|
|
415
395
|
const targetAsset =
|
|
416
396
|
to === "baseAsset" && from !== "baseAsset"
|
|
@@ -482,7 +462,6 @@ function createTCBasedPlugin<T extends PluginChain>(pluginChain: T) {
|
|
|
482
462
|
nodeAction,
|
|
483
463
|
registerName,
|
|
484
464
|
registerPreferredAsset,
|
|
485
|
-
savings,
|
|
486
465
|
swap,
|
|
487
466
|
withdraw,
|
|
488
467
|
};
|
package/src/thorchain/shared.ts
CHANGED
|
@@ -4,13 +4,7 @@ import type { CoreTxParams } from "./types";
|
|
|
4
4
|
export function validateAddressType({ chain, address }: { chain?: Chain; address?: string }) {
|
|
5
5
|
if (!address) return false;
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
case Chain.Bitcoin:
|
|
9
|
-
// filter out taproot addresses
|
|
10
|
-
return !address.startsWith("bc1p");
|
|
11
|
-
default:
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
7
|
+
return chain === Chain.Bitcoin ? !address.startsWith("bc1p") : true;
|
|
14
8
|
}
|
|
15
9
|
|
|
16
10
|
export function prepareTxParams({
|
package/src/thorchain/types.ts
CHANGED
|
@@ -32,23 +32,11 @@ export type CoreTxParams = {
|
|
|
32
32
|
expiration?: number;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
export type LoanParams = {
|
|
36
|
-
assetValue: AssetValue;
|
|
37
|
-
memo?: string;
|
|
38
|
-
minAmount: AssetValue;
|
|
39
|
-
type: "open" | "close";
|
|
40
|
-
};
|
|
41
|
-
|
|
42
35
|
export type NodeActionParams = { address: string } & (
|
|
43
36
|
| { type: MemoType.BOND | MemoType.UNBOND; assetValue: AssetValue }
|
|
44
37
|
| { type: MemoType.LEAVE; assetValue?: undefined }
|
|
45
38
|
);
|
|
46
39
|
|
|
47
|
-
export type SavingsParams = { assetValue: AssetValue; memo?: string } & (
|
|
48
|
-
| { type: "add"; percent?: undefined }
|
|
49
|
-
| { type: "withdraw"; percent: number }
|
|
50
|
-
);
|
|
51
|
-
|
|
52
40
|
export type RegisterThornameParams = {
|
|
53
41
|
assetValue: AssetValue;
|
|
54
42
|
name: string;
|
package/src/types.ts
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import type { ChainflipPlugin } from "./chainflip";
|
|
2
2
|
import type { EVMPlugin } from "./evm";
|
|
3
|
-
import type {
|
|
3
|
+
import type { NearPlugin } from "./near";
|
|
4
4
|
import type { RadixPlugin } from "./radix";
|
|
5
5
|
import type { SolanaPlugin } from "./solana/plugin";
|
|
6
6
|
import type { ThorchainPlugin } from "./thorchain";
|
|
7
7
|
|
|
8
8
|
export type * from "./chainflip/types";
|
|
9
9
|
export type * from "./thorchain/types";
|
|
10
|
-
export type * from "./kado/types";
|
|
11
10
|
|
|
12
11
|
export type SKPlugins = typeof ChainflipPlugin &
|
|
13
12
|
typeof ThorchainPlugin &
|
|
14
|
-
typeof KadoPlugin &
|
|
15
13
|
typeof RadixPlugin &
|
|
16
14
|
typeof SolanaPlugin &
|
|
17
|
-
typeof EVMPlugin
|
|
15
|
+
typeof EVMPlugin &
|
|
16
|
+
typeof NearPlugin;
|
|
18
17
|
|
|
19
18
|
export type PluginName = keyof SKPlugins;
|
package/src/utils.ts
CHANGED
|
@@ -12,10 +12,6 @@ export async function loadPlugin<P extends PluginName>(pluginName: P) {
|
|
|
12
12
|
const { ThorchainPlugin } = await import("./thorchain");
|
|
13
13
|
return ThorchainPlugin;
|
|
14
14
|
})
|
|
15
|
-
.with("kado", async () => {
|
|
16
|
-
const { KadoPlugin } = await import("./kado");
|
|
17
|
-
return KadoPlugin;
|
|
18
|
-
})
|
|
19
15
|
.with("radix", async () => {
|
|
20
16
|
const { RadixPlugin } = await import("./radix");
|
|
21
17
|
return RadixPlugin;
|
|
@@ -28,6 +24,10 @@ export async function loadPlugin<P extends PluginName>(pluginName: P) {
|
|
|
28
24
|
const { SolanaPlugin } = await import("./solana");
|
|
29
25
|
return SolanaPlugin;
|
|
30
26
|
})
|
|
27
|
+
.with("near", async () => {
|
|
28
|
+
const { NearPlugin } = await import("./near");
|
|
29
|
+
return NearPlugin;
|
|
30
|
+
})
|
|
31
31
|
.exhaustive();
|
|
32
32
|
|
|
33
33
|
return plugin as unknown as SKPlugins[P];
|