Skip to content

Commit

Permalink
feat(jellyfish-api-core, jellyfish-transaction): added TransferDomain (
Browse files Browse the repository at this point in the history
…#2092)

<!--  Thanks for sending a pull request! -->

#### What this PR does / why we need it:
In this pr we have added 
1. TransferDomain which will create an transfer balances transaction
submitted to a connected node.
2. Updated `getTokenBalances` method to include eth address balance 
3. Update `getNewAddress` method to include eth address type option
4. Enable EVM on the node by setGov `'v0/params/feature/evm': 'true'`

#### Which issue(s) does this PR fixes?:
<!--
(Optional) Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
Fixes #

#### Additional comments?:

---------

Signed-off-by: Harsh R <[email protected]>
Co-authored-by: Pierre Gee <[email protected]>
Co-authored-by: canonbrother <[email protected]>
  • Loading branch information
3 people authored Jun 14, 2023
1 parent afed8a4 commit fe59971
Show file tree
Hide file tree
Showing 22 changed files with 957 additions and 16 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/fuxing.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ it('should have gov set', async () => {
'v0/token/17/loan_payback_fee_pct/15': '0.01',
'v0/token/17/fixed_interval_price_id': 'TR50/USD',
'v0/token/17/loan_minting_enabled': 'true',
'v0/token/17/loan_minting_interest': '3'
'v0/token/17/loan_minting_interest': '3',
'v0/params/feature/evm': 'true'
})
})

Expand Down
3 changes: 2 additions & 1 deletion apps/playground-api/src/controllers/WalletController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export class WalletController {
async balances (): Promise<WalletBalances> {
const balance = await this.client.wallet.getBalance()
const account = await this.client.account.getTokenBalances({}, true, {
symbolLookup: false
symbolLookup: false,
includeEth: false
})

const tokens = Object.entries(account).map(([id, value]) => {
Expand Down
7 changes: 7 additions & 0 deletions apps/playground-api/src/setups/setup.gov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,12 @@ export class SetupGov extends PlaygroundSetup<Record<string, any>> {
}
})
await this.generate(1)

await this.client.masternode.setGov({
ATTRIBUTES: {
'v0/params/feature/evm': 'true'
}
})
await this.generate(1)
}
}
2 changes: 2 additions & 0 deletions apps/whale-api/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ services:
-fortcanninggreatworldheight=14
-fortcanningepilogueheight=15
-grandcentralheight=16
-grandcentralepilogueheight=17
-nextnetworkupgradeheight=18
-regtest-skip-loan-collateral-validation
-regtest-minttoken-simulate-mainnet=0
Expand Down
7 changes: 7 additions & 0 deletions docs/node/CATEGORIES/05-wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@ Returns a new DeFi address for receiving payments. If 'label' is specified, it's
interface wallet {
getNewAddress (label: string = '', addressType = AddressType.BECH32): Promise<string>
}

enum AddressType {
LEGACY = 'legacy',
P2SH_SEGWIT = 'p2sh-segwit',
BECH32 = 'bech32',
ETH = 'eth',
}
```

## validateAddress
Expand Down
29 changes: 28 additions & 1 deletion docs/node/CATEGORIES/08-account.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ interface account {
getTokenBalances (
pagination: AccountPagination = { limit: 100 },
indexedAmounts = false,
options: GetTokenBalancesOptions = { symbolLookup: false}
options: GetTokenBalancesOptions = { symbolLookup: false, includeEth: false},
): Promise<string[] | AccountAmount>
}

Expand All @@ -105,6 +105,7 @@ interface AccountPagination {

interface GetTokenBalancesOptions {
symbolLookup?: boolean
includeEth?: boolean
}
```

Expand Down Expand Up @@ -152,6 +153,32 @@ interface UTXO {
}
```

## transferDomain

Create a transfer domain transaction submitted to a connected node.

```ts title="client.account.transferDomain()"
interface account {
transferDomain (payload: Array<Record<string, TransferDomainInfo>>): Promise<string>
}

interface TransferDomainInfo {
address: string
amount: string
domain: TransferDomainType
}

enum TransferDomainType {
NONE = 0,
/** type reserved for UTXO */
UTXO = 1,
/** type for DVM Token To EVM transfer */
DVM = 2,
/** type for EVM To DVM Token transfer */
EVM = 3,
};
```

## accountToUtxos

Create an Account to UTXOS transaction submitted to a connected node.
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { ContainerAdapterClient } from '../../container_adapter_client'
import { TransferDomainType } from '../../../src/category/account'
import waitForExpect from 'wait-for-expect'
import BigNumber from 'bignumber.js'

Expand Down Expand Up @@ -80,7 +81,7 @@ describe('Account', () => {

it('should getTokenBalances with indexedAmounts true', async () => {
await waitForExpect(async () => {
const tokenBalances = await client.account.getTokenBalances({}, true, { symbolLookup: false })
const tokenBalances = await client.account.getTokenBalances({}, true, { symbolLookup: false, includeEth: false })
expect(typeof tokenBalances === 'object').toStrictEqual(true)
for (const k in tokenBalances) {
expect(tokenBalances[k] instanceof BigNumber).toStrictEqual(true)
Expand All @@ -90,13 +91,53 @@ describe('Account', () => {

it('should getTokenBalances with symbolLookup', async () => {
await waitForExpect(async () => {
const tokenBalances = await client.account.getTokenBalances({}, false, { symbolLookup: true })
const tokenBalances = await client.account.getTokenBalances({}, false, { symbolLookup: true, includeEth: false })
expect(tokenBalances.length).toBeGreaterThan(0)
})

const tokenBalances = await client.account.getTokenBalances({}, false, { symbolLookup: true })
const tokenBalances = await client.account.getTokenBalances({}, false, { symbolLookup: true, includeEth: false })
for (let i = 0; i < tokenBalances.length; i += 1) {
expect(typeof tokenBalances[i]).toStrictEqual('string')
}
})

it('should getTokenBlaances with including eth', async () => {
await client.masternode.setGov({
ATTRIBUTES: {
'v0/params/feature/evm': 'true'
}
})
await container.generate(1)

const dvmAddr = await container.call('getnewaddress')
const evmAddr = await container.getNewAddress('eth', 'eth')

await container.call('utxostoaccount', [{ [dvmAddr]: '100@0' }])
await container.generate(1)

await client.account.transferDomain([
{
src: {
address: dvmAddr,
amount: '3@DFI',
domain: TransferDomainType.DVM
},
dst: {
address: evmAddr,
amount: '3@DFI',
domain: TransferDomainType.EVM
}
}
])
await container.generate(1)

await waitForExpect(async () => {
const withoutEth = await client.account.getTokenBalances({}, false, { symbolLookup: true, includeEth: false })
const wo = withoutEth[0].split('@')[0]

const withEth = await client.account.getTokenBalances({}, false, { symbolLookup: true, includeEth: true })
const w = withEth[0].split('@')[0]
expect(new BigNumber(w)).toStrictEqual(new BigNumber(wo).plus(3))
})
})
})
Loading

0 comments on commit fe59971

Please sign in to comment.