Skip to content

Commit

Permalink
Merge pull request #309 from EdgeApp/paul/upgradeCore2.0
Browse files Browse the repository at this point in the history
Paul/upgrade core2.0
  • Loading branch information
paullinator authored Jan 4, 2024
2 parents b4a707e + e262ece commit 1cbe56c
Show file tree
Hide file tree
Showing 26 changed files with 619 additions and 243 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"chai": "^4.2.0",
"cleaner-config": "^0.1.10",
"crypto-browserify": "^3.12.0",
"edge-core-js": "^1.11.0",
"edge-core-js": "^2.0.0",
"edge-currency-accountbased": "^2.9.0",
"edge-currency-plugins": "^2.4.1",
"esbuild-loader": "^2.20.0",
Expand Down
22 changes: 17 additions & 5 deletions src/swap/changehero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export function makeChangeHeroPlugin(
)

const spendInfo: EdgeSpendInfo = {
currencyCode: fromCurrencyCode,
tokenId: request.fromTokenId,
spendTargets: [
{
nativeAmount: amountExpectedFromNative,
Expand All @@ -306,15 +306,27 @@ export function makeChangeHeroPlugin(
],
networkFeeOption:
request.fromCurrencyCode.toUpperCase() === 'BTC' ? 'high' : 'standard',
swapData: {
assetAction: {
assetActionType: 'swap'
},
savedAction: {
actionType: 'swap',
swapInfo,
orderUri: orderUri + quoteInfo.id,
orderId: quoteInfo.id,
isEstimate: false,
toAsset: {
pluginId: request.toWallet.currencyInfo.pluginId,
tokenId: request.toTokenId,
nativeAmount: amountExpectedToNative
},
fromAsset: {
pluginId: request.fromWallet.currencyInfo.pluginId,
tokenId: request.fromTokenId,
nativeAmount: amountExpectedFromNative
},
payoutAddress: toAddress,
payoutCurrencyCode: toCurrencyCode,
payoutNativeAmount: amountExpectedToNative,
payoutWalletId: request.toWallet.id,
plugin: { ...swapInfo },
refundAddress: fromAddress
}
}
Expand Down
44 changes: 34 additions & 10 deletions src/swap/changenow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export function makeChangeNowPlugin(
)

const spendInfo: EdgeSpendInfo = {
currencyCode: fromCurrencyCode,
tokenId: request.fromTokenId,
spendTargets: [
{
nativeAmount,
Expand All @@ -210,15 +210,27 @@ export function makeChangeNowPlugin(
}
],
networkFeeOption: fromCurrencyCode === 'BTC' ? 'high' : 'standard',
swapData: {
assetAction: {
assetActionType: 'swap'
},
savedAction: {
actionType: 'swap',
swapInfo,
orderId: id,
orderUri: orderUri + id,
isEstimate: flow === 'standard',
toAsset: {
pluginId: request.toWallet.currencyInfo.pluginId,
tokenId: request.toTokenId,
nativeAmount: toNativeAmount
},
fromAsset: {
pluginId: request.fromWallet.currencyInfo.pluginId,
tokenId: request.fromTokenId,
nativeAmount
},
payoutAddress: toAddress,
payoutCurrencyCode: toCurrencyCode,
payoutNativeAmount: toNativeAmount,
payoutWalletId: request.toWallet.id,
plugin: { ...swapInfo },
refundAddress: fromAddress
}
}
Expand Down Expand Up @@ -256,7 +268,7 @@ export function makeChangeNowPlugin(
)

const spendInfo: EdgeSpendInfo = {
currencyCode: fromCurrencyCode,
tokenId: request.fromTokenId,
spendTargets: [
{
nativeAmount: fromNativeAmount,
Expand All @@ -265,15 +277,27 @@ export function makeChangeNowPlugin(
}
],
networkFeeOption: fromCurrencyCode === 'BTC' ? 'high' : 'standard',
swapData: {
assetAction: {
assetActionType: 'swap'
},
savedAction: {
actionType: 'swap',
swapInfo,
orderId: id,
orderUri: orderUri + id,
isEstimate: false,
toAsset: {
pluginId: request.toWallet.currencyInfo.pluginId,
tokenId: request.toTokenId,
nativeAmount: nativeAmount
},
fromAsset: {
pluginId: request.fromWallet.currencyInfo.pluginId,
tokenId: request.fromTokenId,
nativeAmount: fromNativeAmount
},
payoutAddress: toAddress,
payoutCurrencyCode: toCurrencyCode,
payoutNativeAmount: nativeAmount,
payoutWalletId: request.toWallet.id,
plugin: { ...swapInfo },
refundAddress: fromAddress
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/swap/defi/defiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const asContractLocation = asObject({
export const getInOutTokenAddresses = (
currencyConfig: EdgeCurrencyConfig,
wrappedMainnetAddress: string,
fromTokenId?: string,
toTokenId?: string
fromTokenId: string | null,
toTokenId: string | null
): InOutTokenAddresses => {
const { allTokens } = currencyConfig

Expand Down
44 changes: 34 additions & 10 deletions src/swap/defi/lifi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ export function makeLifiPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
})

const spendInfo: EdgeSpendInfo = {
currencyCode: request.fromCurrencyCode,
// Token approvals only spend the parent currency
tokenId: null,
spendTargets: [
{
memo: approvalData,
Expand All @@ -320,20 +321,30 @@ export function makeLifiPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
customNetworkFee: {
gasPrice: gasPriceGwei
},
metadata: {
name: 'Li.Fi',
category: 'expense:Token Approval'
assetAction: {
assetActionType: 'tokenApproval'
},
savedAction: {
actionType: 'tokenApproval',
tokenApproved: {
pluginId: fromWallet.currencyInfo.pluginId,
tokenId: fromTokenId,
nativeAmount
},
tokenContractAddress: fromContractAddress,
contractAddress: approvalAddress
}
}
preTx = await request.fromWallet.makeSpend(spendInfo)
}

const fromNativeAmount = mul(transactionRequest.value, '1')
const spendInfo: EdgeSpendInfo = {
currencyCode: request.fromCurrencyCode,
tokenId: request.fromTokenId,
spendTargets: [
{
memo: data,
nativeAmount: mul(transactionRequest.value, '1'),
nativeAmount: fromNativeAmount,
publicAddress: approvalAddress
}
],
Expand All @@ -343,13 +354,26 @@ export function makeLifiPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
gasLimit: round(mul(hexToDecimal(gasLimit), '1.4'), 0),
gasPrice: gasPriceGwei
},
swapData: {
assetAction: {
assetActionType: 'swap'
},
savedAction: {
actionType: 'swap',
swapInfo,
isEstimate: false,
toAsset: {
pluginId: toWallet.currencyInfo.pluginId,
tokenId: toTokenId,
nativeAmount: toAmountMin
},
fromAsset: {
pluginId: fromWallet.currencyInfo.pluginId,
tokenId: fromTokenId,
nativeAmount: fromNativeAmount
},
payoutAddress: toAddress,
payoutCurrencyCode: toCurrencyCode,
payoutNativeAmount: toAmountMin,
payoutWalletId: toWallet.id,
plugin: { ...swapInfo }
refundAddress: fromAddress
}
}

Expand Down
59 changes: 39 additions & 20 deletions src/swap/defi/thorchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
EdgeSwapQuote,
EdgeSwapRequest,
EdgeTransaction,
EdgeTxSwap,
EdgeTxActionSwap,
SwapBelowLimitError,
SwapCurrencyError
} from 'edge-core-js/types'
Expand Down Expand Up @@ -452,14 +452,14 @@ export function makeThorchainPlugin(
pools
)
const [
sourceAsset,
fromAsset,
sourceTokenContractAddressAllCaps
] = sourcePool.asset.split('-')
const sourceTokenContractAddress =
sourceTokenContractAddressAllCaps != null
? sourceTokenContractAddressAllCaps.toLowerCase()
: undefined
log(`sourceAsset: ${sourceAsset}`)
log(`fromAsset: ${fromAsset}`)

const destPool = getPool(request, toMainnetCode, toCurrencyCode, pools)

Expand Down Expand Up @@ -526,14 +526,23 @@ export function makeThorchainPlugin(
let approvalData
let memoType: EdgeMemo['type']

const swapData: EdgeTxSwap = {
const savedAction: EdgeTxActionSwap = {
actionType: 'swap',
swapInfo,
orderUri: 'https://track.ninerealms.com/',
isEstimate,
toAsset: {
pluginId: toWallet.currencyInfo.pluginId,
tokenId: toTokenId,
nativeAmount: toNativeAmount
},
fromAsset: {
pluginId: fromWallet.currencyInfo.pluginId,
tokenId: fromTokenId,
nativeAmount: fromNativeAmount
},
payoutAddress: toAddress,
payoutCurrencyCode: toCurrencyCode,
payoutNativeAmount: toNativeAmount,
payoutWalletId: toWallet.id,
plugin: { ...swapInfo }
payoutWalletId: toWallet.id
}

if (EVM_CURRENCY_CODES[fromMainnetCode]) {
Expand Down Expand Up @@ -582,8 +591,8 @@ export function makeThorchainPlugin(
}
],
memo,
metadata: {},
swapData
assetAction: { assetActionType: 'swap' },
savedAction
}

// If this is a max quote. Call getMaxTx and modify the request
Expand Down Expand Up @@ -627,7 +636,8 @@ export function makeThorchainPlugin(
approvalData = approvalData.replace('0x', '')

const spendInfo: EdgeSpendInfo = {
currencyCode: request.fromCurrencyCode,
// Token approvals only spend the parent currency
tokenId: null,
memos: [
{
type: memoType,
Expand All @@ -640,9 +650,18 @@ export function makeThorchainPlugin(
publicAddress: sourceTokenContractAddress
}
],
metadata: {
name: 'Thorchain',
category: 'expense:Token Approval'
assetAction: {
assetActionType: 'tokenApproval'
},
savedAction: {
actionType: 'tokenApproval',
tokenApproved: {
pluginId: fromWallet.currencyInfo.pluginId,
tokenId: fromTokenId,
nativeAmount
},
tokenContractAddress: sourceTokenContractAddress ?? '',
contractAddress: router ?? ''
}
}
preTx = await request.fromWallet.makeSpend(spendInfo)
Expand All @@ -653,7 +672,7 @@ export function makeThorchainPlugin(
}

const spendInfo: EdgeSpendInfo = {
currencyCode: request.fromCurrencyCode,
tokenId: request.fromTokenId,
memos: [
{
type: memoType,
Expand All @@ -666,8 +685,8 @@ export function makeThorchainPlugin(
publicAddress
}
],

swapData,
assetAction: { assetActionType: 'swap' },
savedAction,
otherParams: {
outputSort: 'targets'
}
Expand Down Expand Up @@ -1160,7 +1179,7 @@ const getQuote = async (

export const getGasLimit = (
chain: ChainTypes,
tokenId: string | undefined
tokenId: string | null
): string | undefined => {
if (EVM_CURRENCY_CODES[chain]) {
if (tokenId == null) {
Expand All @@ -1183,10 +1202,10 @@ export const getVolatilitySpread = ({
perAssetSpread
}: {
fromPluginId: string
fromTokenId?: string
fromTokenId: string | null
fromCurrencyCode: string
toPluginId: string
toTokenId?: string
toTokenId: string | null
toCurrencyCode: string
likeKindVolatilitySpread: number
volatilitySpread: number
Expand Down
Loading

0 comments on commit 1cbe56c

Please sign in to comment.