Skip to content

Commit

Permalink
feat(playground-api): add MATIC token in playground (#2141)
Browse files Browse the repository at this point in the history
<!--  Thanks for sending a pull request! -->

#### What this PR does / why we need it:

#### 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?:

---------

Co-authored-by: Harsh <[email protected]>
Co-authored-by: JJ Adonis <[email protected]>
  • Loading branch information
3 people authored Aug 28, 2023
1 parent adb503f commit 79a4f60
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 58 deletions.
3 changes: 3 additions & 0 deletions apps/playground-api/__tests__/bots/OracleBot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ describe('oracle bot', () => {

const USDT = oracleData.tokenPrices.find(x => x.token === 'USDT')
expect(USDT?.amount).toBeDefined()

const MATIC = oracleData.tokenPrices.find(x => x.token === 'MATIC')
expect(MATIC?.amount).toBeDefined()
}, 200000)
})
})
71 changes: 37 additions & 34 deletions apps/playground-api/__tests__/modules/PlaygroundModule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ afterAll(async () => {

it('should have pool pairs setup', async () => {
const pairs = await testing.container.call('listpoolpairs')
expect(Object.values(pairs).length).toBe(16)
expect(Object.values(pairs).length).toBe(17)
})

it('should have tokens setup', async () => {
const tokens = await testing.container.call('listtokens')
expect(Object.values(tokens).length).toBe(34)
expect(Object.values(tokens).length).toBe(36)
})

it('should have oracles setup', async () => {
Expand Down Expand Up @@ -56,7 +56,7 @@ it('should have loan tokens', async () => {

it('should have loan collateral tokens', async () => {
const results = await testing.container.call('listcollateraltokens')
expect(results.length).toBe(13)
expect(results.length).toBe(14)
})

it('should have gov set', async () => {
Expand Down Expand Up @@ -156,46 +156,49 @@ it('should have gov set', async () => {
'v0/token/12/fixed_interval_price_id': 'EUROC/USD',
'v0/token/12/loan_collateral_enabled': 'true',
'v0/token/12/loan_collateral_factor': '1',
'v0/token/13/payback_dfi': 'true',
'v0/token/13/payback_dfi_fee_pct': '0.01',
'v0/token/13/loan_payback/1': 'true',
'v0/token/13/loan_payback/15': 'true',
'v0/token/13/loan_payback_fee_pct/1': '0.01',
'v0/token/13/loan_payback_fee_pct/15': '0.01',
'v0/token/13/fixed_interval_price_id': 'DUSD/USD',
'v0/token/13/fixed_interval_price_id': 'MATIC/USD',
'v0/token/13/loan_collateral_enabled': 'true',
'v0/token/13/loan_collateral_factor': '1.2',
'v0/token/13/loan_minting_enabled': 'true',
'v0/token/13/loan_minting_interest': '0',
'v0/token/13/loan_payback_collateral': 'true',
'v0/token/14/loan_payback/6': 'true',
'v0/token/14/loan_payback/13': 'true',
'v0/token/14/loan_payback_fee_pct/6': '0.01',
'v0/token/14/loan_payback_fee_pct/13': '0.01',
'v0/token/14/fixed_interval_price_id': 'TU10/USD',
'v0/token/13/loan_collateral_factor': '1',
'v0/token/14/payback_dfi': 'true',
'v0/token/14/payback_dfi_fee_pct': '0.01',
'v0/token/14/loan_payback/1': 'true',
'v0/token/14/loan_payback/16': 'true',
'v0/token/14/loan_payback_fee_pct/1': '0.01',
'v0/token/14/loan_payback_fee_pct/16': '0.01',
'v0/token/14/fixed_interval_price_id': 'DUSD/USD',
'v0/token/14/loan_collateral_enabled': 'true',
'v0/token/14/loan_collateral_factor': '1.2',
'v0/token/14/loan_minting_enabled': 'true',
'v0/token/14/loan_minting_interest': '1',
'v0/token/15/loan_payback/1': 'true',
'v0/token/15/loan_payback/13': 'true',
'v0/token/15/loan_payback_fee_pct/1': '0.01',
'v0/token/15/loan_payback_fee_pct/13': '0.01',
'v0/token/15/fixed_interval_price_id': 'TD10/USD',
'v0/token/14/loan_minting_interest': '0',
'v0/token/14/loan_payback_collateral': 'true',
'v0/token/15/loan_payback/6': 'true',
'v0/token/15/loan_payback/14': 'true',
'v0/token/15/loan_payback_fee_pct/6': '0.01',
'v0/token/15/loan_payback_fee_pct/14': '0.01',
'v0/token/15/fixed_interval_price_id': 'TU10/USD',
'v0/token/15/loan_minting_enabled': 'true',
'v0/token/15/loan_minting_interest': '1.5',
'v0/token/15/loan_minting_interest': '1',
'v0/token/16/loan_payback/1': 'true',
'v0/token/16/loan_payback/14': 'true',
'v0/token/16/loan_payback_fee_pct/1': '0.01',
'v0/token/16/loan_payback_fee_pct/14': '0.01',
'v0/token/16/fixed_interval_price_id': 'TS25/USD',
'v0/token/16/fixed_interval_price_id': 'TD10/USD',
'v0/token/16/loan_minting_enabled': 'true',
'v0/token/16/loan_minting_interest': '2',
'v0/token/17/payback_dfi': 'true',
'v0/token/17/payback_dfi_fee_pct': '0.01',
'v0/token/17/loan_payback/13': 'true',
'v0/token/16/loan_minting_interest': '1.5',
'v0/token/17/loan_payback/15': 'true',
'v0/token/17/loan_payback_fee_pct/13': '0.01',
'v0/token/17/loan_payback_fee_pct/15': '0.01',
'v0/token/17/fixed_interval_price_id': 'TR50/USD',
'v0/token/17/fixed_interval_price_id': 'TS25/USD',
'v0/token/17/loan_minting_enabled': 'true',
'v0/token/17/loan_minting_interest': '3',
'v0/token/17/loan_minting_interest': '2',
'v0/token/18/payback_dfi': 'true',
'v0/token/18/payback_dfi_fee_pct': '0.01',
'v0/token/18/loan_payback/14': 'true',
'v0/token/18/loan_payback/16': 'true',
'v0/token/18/loan_payback_fee_pct/14': '0.01',
'v0/token/18/loan_payback_fee_pct/16': '0.01',
'v0/token/18/fixed_interval_price_id': 'TR50/USD',
'v0/token/18/loan_minting_enabled': 'true',
'v0/token/18/loan_minting_interest': '3',
'v0/params/feature/icx': 'true',
'v0/params/feature/evm': 'true',
'v0/params/feature/transferdomain': 'true',
Expand Down
6 changes: 6 additions & 0 deletions apps/playground-api/src/bots/OracleBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ export class OracleBot {
amount: new BigNumber(1),
change: new BigNumber(0),
direction: PriceDirection.STABLE
},
{
token: 'MATIC',
amount: new BigNumber(1),
change: new BigNumber(0),
direction: PriceDirection.STABLE
}
]

Expand Down
22 changes: 21 additions & 1 deletion apps/playground-api/src/setups/setup.dex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,22 @@ export class SetupDex extends PlaygroundSetup<PoolPairSetup> {
utxoToAccount: {
[PlaygroundSetup.address]: '2000@0'
}
},
{
symbol: 'MATIC-DFI',
create: {
tokenA: 'MATIC',
tokenB: 'DFI',
commission: 0,
status: true,
ownerAddress: PlaygroundSetup.address
},
add: {
'*': ['3000@DFI', '30000000@MATIC']
},
utxoToAccount: {
[PlaygroundSetup.address]: '3000@0'
}
}
]
}
Expand Down Expand Up @@ -269,13 +285,17 @@ export class SetupDex extends PlaygroundSetup<PoolPairSetup> {
const poolPairs = await this.client.poolpair.listPoolPairs()
const poolPairIds = Object.keys(poolPairs)

// apply `toFixed(8)` due to 1 / 16 = 0.0625 which is valid amount on setgov
// apply `toFixed(8)` due to 1 / 17 = 0.05882353 which is valid amount on setgov
const splits = Number(new BigNumber(1 / poolPairIds.length).toFixed(8))

const lpSplits: any = {}
for (const k in poolPairs) {
lpSplits[parseInt(k)] = splits
}
// to fix: LP_SPLITS: total = 0.9996 vs expected 100000000', code: -32600, method: setgov
// 0.05882353 * 17 !== 100000000
const lstKey = Object.keys(lpSplits)[0]
lpSplits[lstKey] = Number(new BigNumber(lpSplits[lstKey]).minus(0.00000001).toFixed(8))
await this.client.masternode.setGov({ LP_SPLITS: lpSplits })
await this.generate(1)
}
Expand Down
46 changes: 23 additions & 23 deletions apps/playground-api/src/setups/setup.gov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,54 @@ export class SetupGov extends PlaygroundSetup<Record<string, any>> {
ATTRIBUTES: {
// dfi pay dtoken
// DFI pay DUSD
'v0/token/13/payback_dfi': 'true',
'v0/token/13/payback_dfi_fee_pct': '0.01',
'v0/token/14/payback_dfi': 'true',
'v0/token/14/payback_dfi_fee_pct': '0.01',

// DFI pay TR50
'v0/token/17/payback_dfi': 'true',
'v0/token/17/payback_dfi_fee_pct': '0.01',
'v0/token/18/payback_dfi': 'true',
'v0/token/18/payback_dfi_fee_pct': '0.01',

// dtoken (DUSD) pay dtoken #1
// DUSD pay TD10
'v0/token/15/loan_payback/13': 'true',
'v0/token/15/loan_payback_fee_pct/13': '0.01',
'v0/token/16/loan_payback/14': 'true',
'v0/token/16/loan_payback_fee_pct/14': '0.01',

// DUSD pay TU10
'v0/token/14/loan_payback/13': 'true',
'v0/token/14/loan_payback_fee_pct/13': '0.01',
'v0/token/15/loan_payback/14': 'true',
'v0/token/15/loan_payback_fee_pct/14': '0.01',

// DUSD pay TR50
'v0/token/17/loan_payback/13': 'true',
'v0/token/17/loan_payback_fee_pct/13': '0.01',
'v0/token/18/loan_payback/14': 'true',
'v0/token/18/loan_payback_fee_pct/14': '0.01',

// dtoken pay dtoken #2
// TD10 pay DUSD
'v0/token/13/loan_payback/15': 'true',
'v0/token/13/loan_payback_fee_pct/15': '0.01',
'v0/token/14/loan_payback/16': 'true',
'v0/token/14/loan_payback_fee_pct/16': '0.01',

// TD10 pay TR50
'v0/token/17/loan_payback/15': 'true',
'v0/token/17/loan_payback_fee_pct/15': '0.01',
'v0/token/18/loan_payback/16': 'true',
'v0/token/18/loan_payback_fee_pct/16': '0.01',

// TU10 pay TS25
'v0/token/16/loan_payback/14': 'true',
'v0/token/16/loan_payback_fee_pct/14': '0.01',
'v0/token/17/loan_payback/15': 'true',
'v0/token/17/loan_payback_fee_pct/15': '0.01',

// cToken pay dToken
// BTC pay TD10
'v0/token/15/loan_payback/1': 'true',
'v0/token/15/loan_payback_fee_pct/1': '0.01',
'v0/token/16/loan_payback/1': 'true',
'v0/token/16/loan_payback_fee_pct/1': '0.01',

// BTC pay DUSD
'v0/token/13/loan_payback/1': 'true',
'v0/token/13/loan_payback_fee_pct/1': '0.01',
'v0/token/14/loan_payback/1': 'true',
'v0/token/14/loan_payback_fee_pct/1': '0.01',

// CU10 pay TU10
'v0/token/14/loan_payback/6': 'true',
'v0/token/14/loan_payback_fee_pct/6': '0.01',
'v0/token/15/loan_payback/6': 'true',
'v0/token/15/loan_payback_fee_pct/6': '0.01',

// Unloop mechanism for DUSD
'v0/token/13/loan_payback_collateral': 'true',
'v0/token/14/loan_payback_collateral': 'true',

// On-chain governance
'v0/params/feature/gov': 'true',
Expand Down
5 changes: 5 additions & 0 deletions apps/playground-api/src/setups/setup.loan.collateral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ export class SetupLoanCollateral extends PlaygroundSetup<SetCollateralToken> {
token: 'EUROC',
fixedIntervalPriceId: 'EUROC/USD',
factor: new BigNumber('1')
},
{
token: 'MATIC',
fixedIntervalPriceId: 'MATIC/USD',
factor: new BigNumber('1')
}
]
}
Expand Down
4 changes: 4 additions & 0 deletions apps/playground-api/src/setups/setup.oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ const FEEDS: OraclePriceFeed[] = [
{
token: 'EUROC',
currency: 'USD'
},
{
token: 'MATIC',
currency: 'USD'
}
]

Expand Down
11 changes: 11 additions & 0 deletions apps/playground-api/src/setups/setup.token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ export class SetupToken extends PlaygroundSetup<TokenSetup> {
collateralAddress: PlaygroundSetup.address
},
amount: 200000000
},
{
create: {
symbol: 'MATIC',
name: 'Playground MATIC',
isDAT: true,
mintable: true,
tradeable: true,
collateralAddress: PlaygroundSetup.address
},
amount: 100000000
}
]
}
Expand Down

0 comments on commit 79a4f60

Please sign in to comment.