Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jellyfish-api-core): Add futureswap RPC #1273

Merged
merged 30 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
cb115e5
Added dfip2203 futures rpcs.
surangap Mar 28, 2022
fa477cd
Added listFutureSwapHistory rpc.
surangap Mar 29, 2022
6f2551e
Updated futureswap API.
surangap Apr 1, 2022
4468967
Added dfip2203 futures rpcs.
surangap Mar 28, 2022
68f69fa
Added listFutureSwapHistory rpc.
surangap Mar 29, 2022
a133624
Updated futureswap API.
surangap Apr 1, 2022
a9990a2
Added futureswap tests.
surangap Apr 3, 2022
30cf8a8
Merge branch 'surangap/dfi2203-futures' of https://github.com/DeFiCh/…
jingyi2811 Apr 4, 2022
0207801
Added dfip2203 futures rpcs.
surangap Mar 28, 2022
2320d99
Added listFutureSwapHistory rpc.
surangap Mar 29, 2022
77e19d8
Updated futureswap API.
surangap Apr 1, 2022
a6bcedd
Added futureswap tests.
surangap Apr 3, 2022
9f8f3a8
Updated tests.
surangap Apr 4, 2022
7e9feaa
Addted a test to withdraw fututre swap
chanakasameera Apr 5, 2022
247656e
Revert "Addted a test to withdraw fututre swap"
chanakasameera Apr 5, 2022
8a71f88
Fixed failing tests due to ain 1159.
surangap Apr 5, 2022
efb7d52
Updated tests.
surangap Apr 5, 2022
703243a
Removed untested futureswap extra APIs.
surangap Apr 5, 2022
e653cdc
fix pg as master-35ad71b82 require participate pool with liq
canonbrother Apr 6, 2022
20c3641
Merge branch 'main' into surangap/dfi2203-futures
canonbrother Apr 6, 2022
cfd7852
Fixed failing test due to ain 1159.
surangap Apr 6, 2022
58ffff9
Merge branch 'surangap/dfi2203-futures' of https://github.com/DeFiCh/…
jingyi2811 Apr 6, 2022
eda7768
Refactored as per suggestions.
surangap Apr 6, 2022
3581d87
Merge branch 'surangap/dfi2203-futures' of https://github.com/DeFiCh/…
jingyi2811 Apr 7, 2022
da2b5bb
Refactored as per suggestions.
surangap Apr 7, 2022
94c295c
Updated ain image v2.7.0
surangap Apr 7, 2022
ff6456a
minor update.
surangap Apr 7, 2022
db26ee4
Rename futureswap.test.ts to futureSwap.test.ts
surangap Apr 8, 2022
b674731
Merge branch 'surangap/dfi2203-futures' of https://github.com/DeFiCh/…
jingyi2811 Apr 8, 2022
403236c
Fix typos and extra spacing
jingyi2811 Apr 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions apps/playground-api/__tests__/modules/PlaygroundModule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ afterAll(async () => {

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

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

it('should have oracles setup', async () => {
Expand Down Expand Up @@ -116,10 +116,14 @@ it('should have gov set', async () => {
})
await testing.generate(1)

await testing.container.waitForPriceValid('TD10/USD')
await testing.container.waitForPriceValid('TU10/USD')
await testing.container.waitForPriceValid('TR50/USD')
await testing.container.waitForPriceValid('TS25/USD')
{
const prices = await testing.container.call('listfixedintervalprices')

const invalidPrices = prices.filter((p: any) => p.isLive !== true)
for (const p of invalidPrices) {
await testing.container.waitForPriceValid(p.priceFeedId)
}
}

await testing.rpc.loan.takeLoan({
vaultId: vaultId,
Expand Down
49 changes: 45 additions & 4 deletions apps/playground-api/src/setups/setup.dex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ export class SetupDex extends PlaygroundSetup<PoolPairSetup> {
commission: 0.02,
status: true,
ownerAddress: PlaygroundSetup.address
},
add: {
'*': ['10000000@DUSD', '10000000@DFI']
},
utxoToAccount: {
[PlaygroundSetup.address]: '10000000@0'
}
},
{
Expand All @@ -114,6 +120,9 @@ export class SetupDex extends PlaygroundSetup<PoolPairSetup> {
commission: 0.02,
status: true,
ownerAddress: PlaygroundSetup.address
},
add: {
'*': ['10000000@DUSD', '10000000@TU10']
}
},
{
Expand All @@ -124,6 +133,9 @@ export class SetupDex extends PlaygroundSetup<PoolPairSetup> {
commission: 0.02,
status: true,
ownerAddress: PlaygroundSetup.address
},
add: {
'*': ['10000000@DUSD', '10000000@TD10']
}
},
{
Expand All @@ -144,6 +156,9 @@ export class SetupDex extends PlaygroundSetup<PoolPairSetup> {
commission: 0.02,
status: true,
ownerAddress: PlaygroundSetup.address
},
add: {
'*': ['10000000@DUSD', '10000000@TR50']
}
},
{
Expand All @@ -165,6 +180,32 @@ export class SetupDex extends PlaygroundSetup<PoolPairSetup> {
status: false,
ownerAddress: PlaygroundSetup.address
}
},
{
symbol: 'BTC-DUSD',
create: {
tokenA: 'BTC',
tokenB: 'DUSD',
commission: 0.01,
status: true,
ownerAddress: PlaygroundSetup.address
},
add: {
'*': ['1000@BTC', '10000000@DUSD']
}
},
{
symbol: 'CU10-DUSD',
create: {
tokenA: 'CU10',
tokenB: 'DUSD',
commission: 0.01,
status: true,
ownerAddress: PlaygroundSetup.address
},
add: {
'*': ['100000@CU10', '1000@DUSD']
}
}
]
}
Expand Down Expand Up @@ -199,18 +240,18 @@ export class SetupDex extends PlaygroundSetup<PoolPairSetup> {
const poolPairs = await this.client.poolpair.listPoolPairs()
const poolPairIds = Object.keys(poolPairs)

// apply `toFixed(8)` due to 1 / 12 = 0.08333333333333333 which is invalid amount on setgov
// apply `toFixed(8)` due to 1 / 14 = 0.07142857 which is invalid 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 = 99999996 vs expected 100000000', code: -32600, method: setgov
// 0.08333333 * 11 !== 100000000
// to fix: LP_SPLITS: total = 99999998 vs expected 100000000', code: -32600, method: setgov
// 0.07142857 * 14 !== 100000000
const lstKey = Object.keys(lpSplits)[0]
lpSplits[lstKey] = Number(new BigNumber(lpSplits[lstKey]).plus(0.00000004).toFixed(8))
lpSplits[lstKey] = Number(new BigNumber(lpSplits[lstKey]).plus(0.00000002).toFixed(8))

await this.client.masternode.setGov({ LP_SPLITS: lpSplits })
await this.generate(1)
Expand Down
25 changes: 25 additions & 0 deletions docs/node/CATEGORIES/08-account.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,5 +464,30 @@ interface BurnInfo {
* Amount of tokens that are paid back
*/
paybacktokens: string[]
/**
* Amount of tokens burned due to futureswap
*/
dfip2203: string[]
}
```

## futureSwap

Creates and submits to the network a futures contract.

```ts title="client.account.futureSwap()"
interface account {
futureSwap (future: FutureSwap, utxos: UTXO[] = []): Promise<string>
}

interface FutureSwap {
address: string
amount: string
destination?: string
}

interface UTXO {
txid: string
vout: number
}
```
2 changes: 1 addition & 1 deletion docs/node/CATEGORIES/09-oracle.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,4 @@ interface ListFixedIntervalPrice {
timestamp: number
isLive: boolean
}
```
```
Loading