Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jon/fix/mv-thorchainda-swapkit #342

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- changed: Changed 'thorchainda' pluginId to 'swapkit.' 'thorchainda' still exists for backwards compatibility

## 2.8.0 (2024-09-12)

- added: `minReceiveAmount` passed in `EdgeSwapQuotes` for lifi and rango
Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { make0xGaslessPlugin } from './swap/defi/0x/0xGasless'
import { makeCosmosIbcPlugin } from './swap/defi/cosmosIbc'
import { makeLifiPlugin } from './swap/defi/lifi'
import { makeRangoPlugin } from './swap/defi/rango'
import { makeSwapKitPlugin } from './swap/defi/swapKit'
import { makeThorchainPlugin } from './swap/defi/thorchain'
import { makeThorchainDaPlugin } from './swap/defi/thorchainDa'
import { makeSpookySwapPlugin } from './swap/defi/uni-v2-based/plugins/spookySwap'
import { makeTombSwapPlugin } from './swap/defi/uni-v2-based/plugins/tombSwap'
import { makeVelodromePlugin } from './swap/defi/uni-v2-based/plugins/velodrome'
Expand All @@ -33,9 +33,11 @@ const plugins = {
rango: makeRangoPlugin,
sideshift: makeSideshiftPlugin,
spookySwap: makeSpookySwapPlugin,
swapkit: makeSwapKitPlugin,
swapuz: makeSwapuzPlugin,
thorchain: makeThorchainPlugin,
thorchainda: makeThorchainDaPlugin,
/** @deprecated - For backwards compatibility with swapkit */
thorchainda: makeSwapKitPlugin,
tombSwap: makeTombSwapPlugin,
transfer: makeTransferPlugin,
velodrome: makeVelodromePlugin,
Expand Down
28 changes: 11 additions & 17 deletions src/swap/defi/thorchainDa.ts → src/swap/defi/swapKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ import {
THORNODE_SERVERS_DEFAULT
} from './thorchain'

const pluginId = 'thorchainda'
const pluginId = 'swapkit'
const swapInfo: EdgeSwapInfo = {
pluginId,
isDex: true,
displayName: 'Thorchain DEX Aggregator',
displayName: 'Swap Kit',
supportEmail: '[email protected]'
}

// This needs to be a type so adding the '& {}' prevents auto correction to an interface
type ThorSwapQuoteParams = {
type SwapKitSwapQuoteParams = {
sellAsset: string
buyAsset: string
sellAmount: string
Expand All @@ -78,7 +78,7 @@ const asCalldata = asObject({
memo: asOptional(asString)
})

const asThorSwapRoute = asObject({
const asSwapKitSwapRoute = asObject({
contract: asEither(asString, asNull),
contractMethod: asEither(asString, asNull),
contractInfo: asOptional(asString),
Expand All @@ -93,8 +93,8 @@ const asThorSwapRoute = asObject({
deadline: asOptional(asString)
})

const asThorSwapQuoteResponse = asObject({
routes: asArray(asThorSwapRoute)
const asSwapKitSwapQuoteResponse = asObject({
routes: asArray(asSwapKitSwapRoute)
})

/** Max slippage for 5% for estimated quotes */
Expand All @@ -111,9 +111,7 @@ const tokenProxyMap: { [currencyPluginId: string]: string } = {
avalanche: '0x69ba883af416ff5501d54d5e27a1f497fbd97156'
}

export function makeThorchainDaPlugin(
opts: EdgeCorePluginOptions
): EdgeSwapPlugin {
export function makeSwapKitPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
const { io, log } = opts
const { fetchCors = io.fetch } = io
const {
Expand Down Expand Up @@ -225,7 +223,7 @@ export function makeThorchainDaPlugin(
fromCurrencyCode
)

const quoteParams: ThorSwapQuoteParams = {
const quoteParams: SwapKitSwapQuoteParams = {
sellAsset:
`${fromMainnetCode}.${fromCurrencyCode}` +
(fromTokenId != null ? `-0x${fromTokenId}` : ''),
Expand Down Expand Up @@ -263,7 +261,7 @@ export function makeThorchainDaPlugin(
if (!iaResponse.ok) {
const responseText = await iaResponse.text()
throw new Error(
`Thorchain could not fetch inbound_addresses: ${JSON.stringify(
`Swap Kit could not fetch inbound_addresses: ${JSON.stringify(
responseText,
null,
2
Expand All @@ -273,19 +271,15 @@ export function makeThorchainDaPlugin(
if (!thorSwapResponse.ok) {
const responseText = await thorSwapResponse.text()
throw new Error(
`Thorchain could not get thorswap quote: ${JSON.stringify(
responseText,
null,
2
)}`
`Swap Kit could not get quote: ${JSON.stringify(responseText, null, 2)}`
)
}

const iaJson = await iaResponse.json()
const inboundAddresses = asInboundAddresses(iaJson)

const thorSwapJson = await thorSwapResponse.json()
const thorSwapQuote = asThorSwapQuoteResponse(thorSwapJson)
const thorSwapQuote = asSwapKitSwapQuoteResponse(thorSwapJson)

// Check for supported chain and asset
const inAddressObject = inboundAddresses.find(
Expand Down
1 change: 1 addition & 0 deletions test/createUserDump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async function main(): Promise<void> {
avalanche: true,
piratechain: true,
polygon: true,
swapkit: true,
thorchainda: true
}
})
Expand Down
1 change: 1 addition & 0 deletions test/testpartner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ async function main(): Promise<void> {
polygon: config.POLYGON_INIT,
piratechain: true,
rango: config.RANGO_INIT,
swapkit: config.THORCHAIN_INIT,
thorchain: config.THORCHAIN_INIT,
thorchainda: config.THORCHAIN_INIT
}
Expand Down
Loading