-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import chai from 'chai'; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import { address } from '@waves/ts-lib-crypto'; | ||
import { invokeScript, nodeInteraction as ni } from '@waves/waves-transactions'; | ||
import { create } from '@waves/node-api-js'; | ||
|
||
chai.use(chaiAsPromised); | ||
const { expect } = chai; | ||
|
||
const apiBase = process.env.API_NODE_URL; | ||
const chainId = 'R'; | ||
|
||
const api = create(apiBase); | ||
|
||
describe('lp_stable: doublePutOneTkn.mjs', /** @this {MochaSuiteModified} */() => { | ||
it('should successfully putOneTkn with autoStake false', async function () { | ||
const amAssetPart = 1e8; | ||
const prAssetPart = 1e8; | ||
const outLp = 1e10; | ||
const slippage = 1e3; | ||
const autoStake = false; | ||
const usdtAmount = 1e8; | ||
const usdnAmount = 1e8; | ||
const shouldAutoStake = false; | ||
|
||
const expectedPriceLast = 1e8; | ||
const expectedPriceHistory = 1e8; | ||
const expectedWriteAmAmt = 1e8; | ||
const expectedWritePrAmt = 0; | ||
const expectedEmitLpAmt = 1e10; | ||
const expectedSlippageCalc = 1e3; | ||
const expectedAmDiff = 0; | ||
const expectedPrDiff = 0; | ||
|
||
const lpStable = address(this.accounts.lpStable, chainId); | ||
|
||
const put = invokeScript({ | ||
dApp: lpStable, | ||
payment: [ | ||
{ assetId: this.usdtAssetId, amount: usdtAmount }, | ||
{ assetId: this.usdnAssetId, amount: usdnAmount }, | ||
], | ||
call: { | ||
function: 'put', | ||
args: [ | ||
{ type: 'integer', value: 0 }, | ||
{ type: 'boolean', value: shouldAutoStake }, | ||
], | ||
}, | ||
chainId, | ||
}, this.accounts.user1); | ||
await api.transactions.broadcast(put, {}); | ||
await ni.waitForTx(put.id, { apiBase }); | ||
|
||
const firstPutOneTkn = invokeScript({ | ||
dApp: lpStable, | ||
payment: [ | ||
{ assetId: this.usdtAssetId, amount: usdtAmount }, | ||
], | ||
call: { | ||
function: 'putOneTkn', | ||
args: [ | ||
{ type: 'integer', value: amAssetPart }, | ||
{ type: 'integer', value: prAssetPart }, | ||
{ type: 'integer', value: outLp }, | ||
{ type: 'integer', value: slippage }, | ||
{ type: 'boolean', value: autoStake }, | ||
], | ||
}, | ||
chainId, | ||
}, this.accounts.user1); | ||
await api.transactions.broadcast(firstPutOneTkn, {}); | ||
await ni.waitForTx(firstPutOneTkn.id, { apiBase }); | ||
|
||
const secondPutOneTkn = invokeScript({ | ||
dApp: lpStable, | ||
payment: [ | ||
{ assetId: this.usdtAssetId, amount: usdtAmount }, | ||
], | ||
call: { | ||
function: 'putOneTkn', | ||
args: [ | ||
{ type: 'integer', value: amAssetPart }, | ||
{ type: 'integer', value: prAssetPart }, | ||
{ type: 'integer', value: outLp }, | ||
{ type: 'integer', value: slippage }, | ||
{ type: 'boolean', value: autoStake }, | ||
], | ||
}, | ||
chainId, | ||
}, this.accounts.user1); | ||
await api.transactions.broadcast(secondPutOneTkn, {}); | ||
const { height, stateChanges, id } = await ni.waitForTx(secondPutOneTkn.id, { apiBase }); | ||
|
||
const { timestamp } = await api.blocks.fetchHeadersAt(height); | ||
const keyPriceHistory = `%s%s%d%d__price__history__${height}__${timestamp}`; | ||
|
||
expect(stateChanges.data).to.eql([{ | ||
key: '%s%s__price__last', | ||
type: 'integer', | ||
value: expectedPriceLast, | ||
}, { | ||
key: keyPriceHistory, | ||
type: 'integer', | ||
value: expectedPriceHistory, | ||
}, { | ||
key: `%s%s%s__P__${address(this.accounts.user1, chainId)}__${id}`, | ||
type: 'string', | ||
value: `%d%d%d%d%d%d%d%d%d%d__${expectedWriteAmAmt}__${expectedWritePrAmt}__${expectedEmitLpAmt}__${expectedPriceLast}__${slippage}__${expectedSlippageCalc}__${height}__${timestamp}__${expectedAmDiff}__${expectedPrDiff}`, | ||
}]); | ||
|
||
expect(stateChanges.transfers).to.eql([{ | ||
address: address(this.accounts.user1, chainId), | ||
asset: this.lpStableAssetId, | ||
amount: outLp, | ||
}]); | ||
|
||
expect(stateChanges.invokes.map((item) => [item.dApp, item.call.function])) | ||
.to.deep.include.members([ | ||
[address(this.accounts.lpStableAddon, chainId), 'ensureCanPutOneTkn'], | ||
[address(this.accounts.gwxReward, chainId), 'calcD'], | ||
[address(this.accounts.gwxReward, chainId), 'calcD'], | ||
[address(this.accounts.factoryV2, chainId), 'emit'], | ||
]); | ||
}); | ||
}); |