Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c4ae256
Init commit
bra1nsurfer Oct 11, 2023
dce5a13
Merge branch 'main' of other.github.com:waves-exchange/contracts into…
bra1nsurfer Oct 11, 2023
c52ba20
calAmountAndSend test
bra1nsurfer Oct 11, 2023
ca5f988
calAmountAndSwap
bra1nsurfer Oct 12, 2023
4ff8f10
put test
bra1nsurfer Oct 16, 2023
e63fd33
put + tests
bra1nsurfer Oct 18, 2023
53e84df
refactor tests
bra1nsurfer Oct 18, 2023
b8fd4a4
putOneTknv2
bra1nsurfer Oct 18, 2023
4c4ad21
putForFree test
bra1nsurfer Oct 20, 2023
17c45bf
putForFree rewrite
bra1nsurfer Oct 20, 2023
80fd3e8
get tests
bra1nsurfer Oct 20, 2023
69b524e
get update
bra1nsurfer Oct 25, 2023
611cc67
getOneTknV2
bra1nsurfer Oct 30, 2023
544c5ac
refreshDLp test
bra1nsurfer Oct 31, 2023
5327659
refreshDLp
bra1nsurfer Nov 1, 2023
532ac6a
getOneTknV2READONLY test
bra1nsurfer Nov 2, 2023
b533d3b
getOneTknV2READONLY
bra1nsurfer Nov 2, 2023
0dec103
getOneTknV2WithBonusREADONLY tests
bra1nsurfer Nov 2, 2023
ee11e80
test
bra1nsurfer Nov 6, 2023
7a2107e
getOneTknBonusReadonly
bra1nsurfer Nov 7, 2023
fe68f9b
fix
bra1nsurfer Nov 7, 2023
05ee739
getNoLess
bra1nsurfer Nov 7, 2023
096f132
unstakeAndGet test update
bra1nsurfer Nov 7, 2023
f48d209
unstakeAndGet
bra1nsurfer Nov 8, 2023
774c685
unstakeAndGetOneV2 test
bra1nsurfer Nov 10, 2023
0253ca6
unsatkeAndGetV2
bra1nsurfer Nov 13, 2023
56b8bcf
readonly tests
bra1nsurfer Nov 16, 2023
0bd9f67
READONLY methods + tests
bra1nsurfer Nov 20, 2023
52d97f3
READONLY 2 + tests
bra1nsurfer Nov 20, 2023
0994c3b
Readonly flag
bra1nsurfer Nov 21, 2023
bbc9777
Merge branch 'main' of other.github.com:waves-exchange/contracts into…
bra1nsurfer Dec 5, 2023
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
748 changes: 232 additions & 516 deletions ride/lp_stable.ride

Large diffs are not rendered by default.

2,161 changes: 2,161 additions & 0 deletions ride/lp_stable_impl.ride

Large diffs are not rendered by default.

46 changes: 43 additions & 3 deletions test/components/lp_stable/_hooks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ const seedWordsCount = 5;
const ridePath = '../ride';
const mockRidePath = 'components/lp_stable/mock';
const lpStablePath = format({ dir: ridePath, base: 'lp_stable.ride' });
const lpStableImplPath = format({ dir: ridePath, base: 'lp_stable_impl.ride' });
const factoryV2Path = format({ dir: ridePath, base: 'factory_v2.ride' });
const stakingPath = format({ dir: mockRidePath, base: 'staking.mock.ride' });
const slippagePath = format({ dir: mockRidePath, base: 'slippage.mock.ride' });
const assetsStorePath = format({ dir: mockRidePath, base: 'assets_store.mock.ride' });
const gwxRewardPath = format({ dir: mockRidePath, base: 'gwx_reward.mock.ride' });
const swapPath = format({ dir: mockRidePath, base: 'swap.mock.ride' });
const restPath = format({ dir: ridePath, base: 'rest.ride' });

export const mochaHooks = {
async beforeAll() {
const names = ['lpStable', 'factoryV2', 'staking', 'slippage', 'gwxReward', 'manager', 'store', 'feeCollector', 'rest', 'user1'];
const names = ['lpStable', 'lpStableImpl', 'factoryV2', 'staking', 'slippage', 'gwxReward', 'manager', 'store', 'feeCollector', 'rest', 'swap', 'user1'];
this.accounts = Object.fromEntries(names.map((item) => [item, randomSeed(seedWordsCount)]));
const seeds = Object.values(this.accounts);
const amount = 1e10;
Expand All @@ -40,11 +42,13 @@ export const mochaHooks = {
await waitForTx(massTransferTx.id, { apiBase });

await setScriptFromFile(lpStablePath, this.accounts.lpStable);
await setScriptFromFile(lpStableImplPath, this.accounts.lpStableImpl);
await setScriptFromFile(factoryV2Path, this.accounts.factoryV2);
await setScriptFromFile(stakingPath, this.accounts.staking);
await setScriptFromFile(slippagePath, this.accounts.slippage);
await setScriptFromFile(assetsStorePath, this.accounts.store);
await setScriptFromFile(gwxRewardPath, this.accounts.gwxReward);
await setScriptFromFile(swapPath, this.accounts.swap);
await setScriptFromFile(restPath, this.accounts.rest);

const usdnIssueTx = issue({
Expand All @@ -60,7 +64,7 @@ export const mochaHooks = {

const usdnAmount = 1e16;
const massTransferTxUSDN = massTransfer({
transfers: names.slice(-1).map((name) => ({
transfers: names.slice(-2).map((name) => ({
recipient: address(this.accounts[name], chainId), amount: usdnAmount,
})),
assetId: this.usdnAssetId,
Expand All @@ -82,7 +86,7 @@ export const mochaHooks = {

const usdtAmount = 1e16;
const massTransferTxUSDT = massTransfer({
transfers: names.slice(-1).map((name) => ({
transfers: names.slice(-2).map((name) => ({
recipient: address(this.accounts[name], chainId), amount: usdtAmount,
})),
assetId: this.usdtAssetId,
Expand Down Expand Up @@ -242,6 +246,16 @@ export const mochaHooks = {
key: '%s__managerPublicKey',
type: 'string',
value: publicKey(this.accounts.manager),
},
{
key: '%s__lpStableImpl',
type: 'string',
value: address(this.accounts.lpStableImpl, chainId),
},
{
key: '%s__swapContract',
type: 'string',
value: address(this.accounts.swap, chainId),
}],
chainId,
}, this.accounts.factoryV2);
Expand Down Expand Up @@ -314,10 +328,36 @@ export const mochaHooks = {
key: '%s__managerPublicKey',
type: 'string',
value: publicKey(this.accounts.manager),
},
{
key: '%s__factoryContract',
type: 'string',
value: address(this.accounts.factoryV2, chainId),
}, {
key: '%s__refreshDLpDelay',
type: 'integer',
value: 2,
}],
chainId,
}, this.accounts.lpStable);
await api.transactions.broadcast(setManagerLpStableTx, {});
await waitForTx(setManagerLpStableTx.id, { apiBase });

const setLpStableImplStateTx = data({
additionalFee: 4e5,
data: [{
key: '%s__factoryContract',
type: 'string',
value: address(this.accounts.factoryV2, chainId),
},
{
key: '%s__swap',
type: 'string',
value: address(this.accounts.factoryV2, chainId),
}],
chainId,
}, this.accounts.lpStableImpl);
await api.transactions.broadcast(setLpStableImplStateTx, {});
await waitForTx(setLpStableImplStateTx.id, { apiBase });
},
};
56 changes: 56 additions & 0 deletions test/components/lp_stable/calcPriceBigIntWrapperREADONLY.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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: calcPriceBigIntWrapperREADONLY.mjs', /** @this {MochaSuiteModified} */() => {
it(
'should successfully calcPriceBigIntWrapperREADONLY',
async function () {
const usdnAmount = 1e8;
const usdtAmount = 1e8;
const shouldAutoStake = false;

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 expr1 = `calcPriceBigIntWrapperREADONLY("12345678000", "10000000000")`; /* eslint-disable-line */
const response1 = await api.utils.fetchEvaluate(
lpStable,
expr1,
);
const evaluateData1 = response1.result.value._2; /* eslint-disable-line */

expect(evaluateData1).to.eql({
type: 'String',
value: '1234567800000000000',
});
},
);
});
69 changes: 69 additions & 0 deletions test/components/lp_stable/calcPricesWrapperREADONLY.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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: calcPricesWrapperREADONLY.mjs', /** @this {MochaSuiteModified} */() => {
it(
'should successfully calcPricesWrapperREADONLY',
async function () {
const usdnAmount = 1e8;
const usdtAmount = 1e8;
const shouldAutoStake = false;

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 expr1 = `calcPricesWrapperREADONLY(1000000, 1100000, 100000000)`; /* eslint-disable-line */
const response1 = await api.utils.fetchEvaluate(
lpStable,
expr1,
);
const evaluateData1 = response1.result.value._2; /* eslint-disable-line */

expect(evaluateData1).to.eql({
type: 'Array',
value: [
{
type: 'String',
value: '1100000000000000000',
},
{
type: 'String',
value: '1000000000000000000',
},
{
type: 'String',
value: '1100000000000000000',
},
],
});
},
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
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: calculateAmountOutForSwapAndSendTokens.mjs', /** @this {MochaSuiteModified} */() => {
it('should successfully calculateAmountOutForSwapAndSendTokens', async function () {
const usdnAmount = 10e8;
const usdtAmount = 10e8;
const shouldAutoStake = false;
const user1Address = address(this.accounts.user1, chainId);

const expected1 = {
address: address(this.accounts.user1, chainId),
amount: 29996411,
asset: this.usdnAssetId,
};

const lpStable = address(this.accounts.lpStable, chainId);
const swapAmount = 30e6;
const feePoolAmount = 3e6;

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 poolUsdtBalanceBeforeInvoke = (
await api.assets.fetchBalanceAddressAssetId(
user1Address,
this.usdnAssetId,
)
).balance;

const invokeTx = invokeScript({
dApp: lpStable,
payment: [
{ assetId: this.usdtAssetId, amount: swapAmount },
],
call: {
function: 'calculateAmountOutForSwapAndSendTokens',
args: [
{ type: 'integer', value: swapAmount },
{ type: 'boolean', value: false },
{ type: 'integer', value: 0 },
{ type: 'string', value: address(this.accounts.user1, chainId) },
{ type: 'integer', value: feePoolAmount },
],
},
chainId,
}, this.accounts.swap);
await api.transactions.broadcast(invokeTx, {});
await ni.waitForTx(invokeTx.id, { apiBase });

const poolUsdtBalanceAfterInvoke = (
await api.assets.fetchBalanceAddressAssetId(
user1Address,
this.usdnAssetId,
)
).balance;

expect(Number(poolUsdtBalanceAfterInvoke))
.to.be.eql(Number(poolUsdtBalanceBeforeInvoke) + expected1.amount);
});
});
52 changes: 52 additions & 0 deletions test/components/lp_stable/calculateAmountOutForSwapREADONLY.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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: calculateAmountOutForSwapREADONLY.mjs', /** @this {MochaSuiteModified} */() => {
it('should successfully calculateAmountOutForSwapREADONLY', async function () {
const usdnAmount = 1e8;
const usdtAmount = 1e8;
const shouldAutoStake = false;

const expected1 = { type: 'Int', value: 99257041 };

const lpStable = address(this.accounts.lpStable, chainId);
const swapAmount = 123e6;
const feePoolAmount = 3e6;

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 expr = `calculateAmountOutForSwapREADONLY(${swapAmount}, false, ${feePoolAmount})`; /* eslint-disable-line */
const response = await api.utils.fetchEvaluate(lpStable, expr);
console.log(response.result);
const checkData = response.result.value._2; /* eslint-disable-line */

expect(checkData).to.eql(expected1); /* eslint-disable-line */
});
});
Loading