Skip to content

Commit

Permalink
Merge dd15230 into 18c2389
Browse files Browse the repository at this point in the history
  • Loading branch information
chanakasameera authored Mar 29, 2022
2 parents 18c2389 + dd15230 commit b96e5a1
Show file tree
Hide file tree
Showing 19 changed files with 1,176 additions and 20 deletions.
3 changes: 2 additions & 1 deletion apps/rich-list-api/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ services:
-eunospayaheight=7
-fortcanningheight=8
-fortcanningmuseumheight=9
-fortcanninghillheight=10
-fortcanninghillheight=10
-fortcanningroadheight=11
8 changes: 8 additions & 0 deletions docs/node/CATEGORIES/08-account.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,5 +456,13 @@ interface BurnInfo {
* Amount of tokens that are paid back; formatted as AMOUNT@SYMBOL
*/
dfipaybacktokens: string[]
/**
* Amount of paybacks
*/
paybackfees: string[]
/**
* Amount of tokens that are paid back
*/
paybacktokens: string[]
}
```
13 changes: 12 additions & 1 deletion docs/node/CATEGORIES/16-loan.md
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ Return loan in a desired amount.

```ts title="client.loan.paybackLoan()"
interface loan {
paybackLoan (metadata: PaybackLoanMetadata, utxos: UTXO[] = []): Promise<string>
paybackLoan (metadata: PaybackLoanMetadata | PaybackLoanMetadataV2, utxos: UTXO[] = []): Promise<string>
}

interface PaybackLoanMetadata {
Expand All @@ -621,6 +621,17 @@ interface PaybackLoanMetadata {
from: string
}

interface TokenPaybackAmount {
dToken: string
amounts: string | string[] // amount@symbol
}

interface PaybackLoanMetadataV2 {
vaultId: string
from: string
loans: TokenPaybackAmount[]
}

interface UTXO {
txid: string
vout: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ it('should getBurnInfo', async () => {
auctionburn: new BigNumber(0),
emissionburn: new BigNumber('6274'),
paybackburn: new BigNumber(0),
paybackfees: [],
paybacktokens: [],
dexfeetokens: [],
dfipaybackfee: new BigNumber(0),
dfipaybacktokens: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class GovernanceMasterNodeRegTestContainer extends MasterNodeRegTestConta
.filter(cmd => cmd !== '-fortcanningheight=8')
.filter(cmd => cmd !== '-fortcanningmuseumheight=9')
.filter(cmd => cmd !== '-fortcanninghillheight=10')
.filter(cmd => cmd !== '-fortcanningroadheight=11')

return [
...cmd,
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ describe('takeloan failed', () => {
amounts: '1000@TSLA'
})
await expect(promise).rejects.toThrow(RpcApiError)
await expect(promise).rejects.toThrow('At least 50% of the minimum required collateral must be in DFI when taking a loan.')
await expect(promise).rejects.toThrow('At least 50% of the minimum required collateral must be in DFI or DUSD when taking a loan.')

{
// revert DFI value changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { RpcApiError } from '@defichain/jellyfish-api-core'
import { GenesisKeys, MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { createPoolPair, createToken } from '@defichain/testing'
import { ContainerAdapterClient } from '../../container_adapter_client'
import { Testing } from '@defichain/jellyfish-testing'

describe('Masternode', () => {
const container = new MasterNodeRegTestContainer()
Expand Down Expand Up @@ -69,3 +70,71 @@ describe('Masternode', () => {
await expect(promise).rejects.toThrow('LP_DAILY_DFI_REWARD: Cannot be set manually after Eunos hard fork')
})
})

describe('Masternode setGov ATTRIBUTES', () => {
const container = new MasterNodeRegTestContainer()
const testing = Testing.create(container)
const attributeKey = 'ATTRIBUTES'
let key: string

beforeAll(async () => {
await testing.container.start()
await testing.container.waitForWalletCoinbaseMaturity()

// setup loan token
await testing.rpc.loan.setLoanToken({
symbol: 'DUSD',
fixedIntervalPriceId: 'DUSD/USD'
})
await testing.generate(1)

const address = await container.call('getnewaddress')
const metadata = {
symbol: 'BTC',
name: 'BTC Token',
isDAT: true,
mintable: true,
tradeable: true,
collateralAddress: address
}
await testing.rpc.token.createToken(metadata)
await testing.generate(1)

const dusdInfo = await testing.rpc.token.getToken('DUSD')
const dusdId = Object.keys(dusdInfo)[0]
key = `v0/token/${dusdId}`
})

afterAll(async () => {
await testing.container.stop()
})

it('should setGov with loan_payback and loan_payback_fee_pct', async () => {
const key0 = `${key}/loan_payback/1`
const key1 = `${key}/loan_payback/2`
const key2 = `${key}/loan_payback_fee_pct/1`
await testing.rpc.masternode.setGov({ [attributeKey]: { [key0]: 'true', [key1]: 'true', [key2]: '0.25' } })
await testing.container.generate(1)

const govAfter = await testing.rpc.masternode.getGov(attributeKey)
expect(govAfter.ATTRIBUTES[key0].toString()).toStrictEqual('true')
expect(govAfter.ATTRIBUTES[key1].toString()).toStrictEqual('true')
expect(govAfter.ATTRIBUTES[key2].toString()).toStrictEqual('0.25')
})

it('should setGov dfi keys with loan_payback and loan_payback_fee_pct', async () => {
const key0 = `${key}/loan_payback/0`
const key1 = `${key}/loan_payback_fee_pct/0`
await testing.rpc.masternode.setGov({ [attributeKey]: { [key0]: 'false', [key1]: '0.35' } })
await testing.container.generate(1)

const govAfter = await testing.rpc.masternode.getGov(attributeKey)
expect(govAfter.ATTRIBUTES[key0]).toBeUndefined()
expect(govAfter.ATTRIBUTES[key1]).toBeUndefined()

const key2 = `${key}/payback_dfi`
const key3 = `${key}/payback_dfi_fee_pct`
expect(govAfter.ATTRIBUTES[key2].toString()).toStrictEqual('false')
expect(govAfter.ATTRIBUTES[key3].toString()).toStrictEqual('0.35')
})
})
8 changes: 8 additions & 0 deletions packages/jellyfish-api-core/src/category/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,4 +543,12 @@ export interface BurnInfo {
* Amount of tokens that are paid back; formatted as AMOUNT@SYMBOL
*/
dfipaybacktokens: string[]
/**
* Amount of paybacks
*/
paybackfees: string[]
/**
* Amount of tokens that are paid back
*/
paybacktokens: string[]
}
18 changes: 16 additions & 2 deletions packages/jellyfish-api-core/src/category/loan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,16 +357,19 @@ export class Loan {
/**
* Return loan in a desired amount.
*
* @param {PaybackLoanMetadata} metadata
* @param {PaybackLoanMetadata | PaybackLoanMetadataV2} metadata
* @param {string} metadata.vaultId Vault id
* @param {string| string[]} metadata.amounts In "amount@symbol" format
* @param {string} metadata.from Address from transfer tokens
* @param {TokenPaybackAmount[]} metadata.loans
* @param {string | string[]} metadata.loans[0].amounts In "amount@symbol" format to be spent
* @param {string} metadata.loans[0].dToken Token to be paid
* @param {UTXO[]} [utxos = []] Specific UTXOs to spend
* @param {string} utxos.txid Transaction Id
* @param {number} utxos.vout Output number
* @return {Promise<string>} txid
*/
async paybackLoan (metadata: PaybackLoanMetadata, utxos: UTXO[] = []): Promise<string> {
async paybackLoan (metadata: PaybackLoanMetadata | PaybackLoanMetadataV2, utxos: UTXO[] = []): Promise<string> {
return await this.client.call('paybackloan', [metadata, utxos], 'number')
}

Expand Down Expand Up @@ -605,6 +608,17 @@ export interface PaybackLoanMetadata {
from: string
}

export interface TokenPaybackAmount {
dToken: string
amounts: string | string[] // amount@symbol
}

export interface PaybackLoanMetadataV2 {
vaultId: string
from: string
loans: TokenPaybackAmount[]
}

export interface VaultPagination {
start?: string
including_start?: boolean
Expand Down
Loading

0 comments on commit b96e5a1

Please sign in to comment.