Skip to content

feat: WXDEFI-58 different decimals in lp_stable #70

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"test-lp-staking-v2": "mocha --parallel --require test/lp_staking_v2/_hooks.mjs test/lp_staking_v2",
"test-lp": "mocha --parallel --require test/lp/_hooks.mjs test/lp",
"test-lp-stable": "mocha --parallel --require test/lp_stable/_hooks.mjs test/lp_stable",
"test-lp-stable-new-pools-with-different-decimals": "mocha --parallel --require test/lp_stable/new_pools_with_different_decimals/_hooks.mjs test/lp_stable/new_pools_with_different_decimals",
"test-lp-stable-decimals-migration": "mocha --parallel --require test/lp_stable/lp_stable_decimals_migration/_hooks.mjs test/lp_stable/lp_stable_decimals_migration",
"test-lp-to-lp-stable-migration": "mocha --parallel --require test/lp_stable/lp_to_lp_stable_migration/_hooks.mjs test/lp_stable/lp_to_lp_stable_migration",
"test-referral": "mocha --parallel --require test/referral/_hooks.mjs test/referral",
"ci-test": "concurrently --max-processes 8 --timings npm:test-*",
"test": "API_NODE_URL=http://localhost:6869 npm run ci-test",
Expand Down
1,219 changes: 645 additions & 574 deletions ride/lp_stable.ride

Large diffs are not rendered by default.

64 changes: 1 addition & 63 deletions ride/lp_stable_addon.ride
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ let idxPrAsId = 5
# data indexes from factory config
let idxFactStakCntr = 1

let delay = "%s__delay"

#-------------------------
# KEYS ON CURRENT CONTRACT
#-------------------------
Expand All @@ -28,8 +26,6 @@ func keyAdminPubKeys() = "%s__adminPubKeys"
func keyAmp() = "%s__amp"
func keyAmpHistory(height: Int) = "%s%d__amp__" + height.toString()

func lastGetOneTknCall(caller: String) = {makeString(["%s%s__lastGetOneTknCall", caller], SEP)}
func lastPutOneTknCall(caller: String) = {makeString(["%s%s__lastPutOneTknCall", caller], SEP)}
#------------------------
# KEYS ON OTHER CONTRACTS
#------------------------
Expand Down Expand Up @@ -141,7 +137,7 @@ func unstakeAndGetOneTkn(amount: Int, exchResult: Int, notUsed: Int, outAmount:

# negative amount will not pass
strict unstakeInv = staking.invoke("unstake", [lpAssetId.toBase58String(), amount], [])
strict getOneTkn = poolContract.reentrantInvoke("getOneTkn", [exchResult, notUsed, outAmount, outAssetId, slippage],[AttachedPayment(lpAssetId, amount)] )
strict getOneTkn = poolContract.invoke("getOneTkn", [exchResult, notUsed, outAmount, outAssetId, slippage],[AttachedPayment(lpAssetId, amount)] )
[]
}

Expand All @@ -155,64 +151,6 @@ func setAmp(amp: String) = {
([], (res1, res2))
}

@Callable(i)
func ensureCanGetOneTkn(caller: String) = {
strict checkCaller = i.mustPool()

strict ensureCanPut = match poolContract.getInteger(lastPutOneTknCall(caller)) {
case int: Int => {
let permittedHeight = int + poolContract.getInteger(delay).value()
let isReadyforPutOneTkn = height >= permittedHeight
let needBlocks = permittedHeight - height
isReadyforPutOneTkn || (["you should wait", needBlocks.toString(), "blocks more to perform the action"]).makeString(" ").throw()
}
case _ => true
}

strict ensureCanGet = match poolContract.getInteger(lastGetOneTknCall(caller)) {
case int: Int => {
let permittedHeight = int + poolContract.getInteger(delay).value()
let isReadyforGetOneTkn = height >= permittedHeight
let needBlocks = permittedHeight - height
isReadyforGetOneTkn || (["you should wait", needBlocks.toString(), "blocks more to perform the action"]).makeString(" ").throw()
}
case _ => true
}

strict setI = poolContract.invoke("setI", [lastPutOneTknCall(caller), height], [])

[]
}

@Callable(i)
func ensureCanPutOneTkn(caller: String) = {
strict checkCaller = i.mustPool()

strict ensureCanPut = match poolContract.getInteger(lastPutOneTknCall(caller)) {
case int: Int => {
let permittedHeight = int + poolContract.getInteger(delay).value()
let isReadyforPutOneTkn = height >= permittedHeight
let needBlocks = permittedHeight - height
isReadyforPutOneTkn || (["you should wait", needBlocks.toString(), "blocks more to perform the action"]).makeString(" ").throw()
}
case _ => true
}

strict ensureCanGet = match poolContract.getInteger(lastGetOneTknCall(caller)) {
case int: Int => {
let permittedHeight = int + poolContract.getInteger(delay).value()
let isReadyforGetOneTkn = height >= permittedHeight
let needBlocks = permittedHeight - height
isReadyforGetOneTkn || (["you should wait", needBlocks.toString(), "blocks more to perform the action"]).makeString(" ").throw()
}
case _ => true
}

strict setI = poolContract.invoke("setI", [lastPutOneTknCall(caller), height], [])

[]
}

@Verifier(tx)
func verify() = {
let targetPublicKey = match managerPublicKeyOrUnit() {
Expand Down
6 changes: 1 addition & 5 deletions test/lp_stable/getOneTkn.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe('lp_stable: getOneTkn.mjs', /** @this {MochaSuiteModified} */() => {
const usdtAmount = 1e8;
const exchResult = 0;
const notUsed = 0;
const delay = 2;

const expectedOutAmAmt = 1e8;
const expectedOutPrAmt = 0;
Expand All @@ -47,9 +46,7 @@ describe('lp_stable: getOneTkn.mjs', /** @this {MochaSuiteModified} */() => {
chainId,
}, this.accounts.user1);
await api.transactions.broadcast(putOneTkn, {});
const { height } = await ni.waitForTx(putOneTkn.id, { apiBase });

await ni.waitForHeight(height + delay, { apiBase });
await ni.waitForTx(putOneTkn.id, { apiBase });

const getOneTkn = invokeScript({
dApp: lpStable,
Expand Down Expand Up @@ -100,7 +97,6 @@ describe('lp_stable: getOneTkn.mjs', /** @this {MochaSuiteModified} */() => {

expect(stateChanges.invokes.map((item) => [item.dApp, item.call.function]))
.to.deep.include.members([
[address(this.accounts.lpStableAddon, chainId), 'ensureCanGetOneTkn'],
[address(this.accounts.gwxReward, chainId), 'calcD'],
[address(this.accounts.gwxReward, chainId), 'calcD'],
[address(this.accounts.factoryV2, chainId), 'burn'],
Expand Down
Loading