Skip to content

Commit

Permalink
Add MakeTxDeposit type
Browse files Browse the repository at this point in the history
  • Loading branch information
peachbits committed Nov 10, 2023
1 parent 1e4624c commit daf3776
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
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

- added: Add `MakeTxDeposit` to support THORChain swap transactions
- changed: Move `makeTx` params types to common
- fixed: Use transaction type 0 (legacy transactions) currencies which do no support EIP-1559

## 2.11.0 (2023-11-08)
Expand Down
10 changes: 10 additions & 0 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ export type MakeTxParams =
*/
expiration?: number
}
| {
type: 'MakeTxDeposit'
assets: Array<{
amount: string
asset: string
decimals: string
}>
memo: string
metadata?: EdgeMetadata
}
| {
type: 'MakeTxDummyType'
}
47 changes: 47 additions & 0 deletions src/cosmos/CosmosEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { base16 } from 'rfc4648'

import { CurrencyEngine } from '../common/CurrencyEngine'
import { PluginEnvironment } from '../common/innerPlugin'
import { MakeTxParams } from '../common/types'
import { upgradeMemos } from '../common/upgradeMemos'
import { cleanTxLogs, getFetchCors } from '../common/utils'
import { CosmosTools } from './CosmosTools'
Expand All @@ -33,6 +34,7 @@ import {
asSafeCosmosWalletInfo,
asShapeshiftResponse,
CosmosNetworkInfo,
CosmosOtherMethods,
CosmosWalletOtherData,
SafeCosmosWalletInfo,
ShapeshiftTx
Expand All @@ -50,6 +52,7 @@ export class CosmosEngine extends CurrencyEngine<
sequence: number
fetchCors: EdgeFetchFunction
otherData!: CosmosWalletOtherData
otherMethods: CosmosOtherMethods

constructor(
env: PluginEnvironment<CosmosNetworkInfo>,
Expand All @@ -62,6 +65,50 @@ export class CosmosEngine extends CurrencyEngine<
this.accountNumber = 0
this.sequence = 0
this.fetchCors = getFetchCors(env.io)
this.otherMethods = {
makeTx: async (params: MakeTxParams) => {
switch (params.type) {
case 'MakeTxDeposit': {
if (this.tools.methods.deposit == null) {
throw new Error(
`${this.currencyInfo.displayName} does not support the deposit method`
)
}

const { assets, memo, metadata } = params

const msg = this.tools.methods.deposit({
assets,
memo,
signer: this.walletInfo.keys.bech32Address
})
const otherParams = this.createUnsignedTxHexOtherParams([msg], memo)

const networkFee = this.networkInfo.defaultTransactionFee.amount

const out: EdgeTransaction = {
blockHeight: 0, // blockHeight,
currencyCode: this.currencyInfo.currencyCode,
date: Date.now() / 1000,
isSend: true,
memos: [],
metadata,
nativeAmount: `-${networkFee}`,
networkFee,
otherParams,
ourReceiveAddresses: [],
signedTx: '',
txid: '',
walletId: this.walletId
}
return out
}
default: {
throw new Error(`Invalid type: ${params.type}`)
}
}
}
}
}

setOtherData(raw: any): void {
Expand Down
10 changes: 7 additions & 3 deletions src/cosmos/cosmosTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {
asObject,
asString,
asTuple,
asValue,
Cleaner
} from 'cleaners'
import { EdgeTransaction } from 'edge-core-js/types'

import { asWalletInfo } from '../common/types'
import { asWalletInfo, MakeTxParams } from '../common/types'

export interface DepositOpts {
assets: Array<{
Expand Down Expand Up @@ -71,7 +71,7 @@ const asShapeshiftTx = asObject({
// origin: string
from: asString,
to: asString,
type: asValue('send'),
// type: asValue('send'),
value: asObject({
amount: asString,
denom: asString
Expand Down Expand Up @@ -125,3 +125,7 @@ export const asCosmosPrivateKeys = (
}
)
}

export interface CosmosOtherMethods {
makeTx: (makeTxParams: MakeTxParams) => Promise<EdgeTransaction>
}

0 comments on commit daf3776

Please sign in to comment.