tx · GDCV9izPX1v5AkRUCBmMpYN7L1mW6qmAMhFJ7eNA5pSp
3NCCpaecUeQcHCJGnv1ZocqT3xAz2wiXFwe: -0.05000000 Waves
2022.05.11 12:17 [2046808] smart account 3NCCpaecUeQcHCJGnv1ZocqT3xAz2wiXFwe > SELF 0.00000000 Waves
{
"type": 13,
"id": "GDCV9izPX1v5AkRUCBmMpYN7L1mW6qmAMhFJ7eNA5pSp",
"fee": 5000000,
"feeAssetId": null,
"timestamp": 1652260734371,
"version": 2,
"chainId": 84,
"sender": "3NCCpaecUeQcHCJGnv1ZocqT3xAz2wiXFwe",
"senderPublicKey": "FX5ZmtqMuiefGRPoKkAcBUEDvaHBS4FSzt8VW49mzcjM",
"proofs": [
"2Upf3B9A7muQvLUaFyWYyCMMBKT3Qbm6XSQgCzjvKksorhr3aL1dpAr4m2nYA9xJEu36jtu17YY472sEYsfm7Ksx"
],
"script": "base64:AAIFAAAAAAAAAAQIAhIAAAAAAwAAAAACSUQBAAAAIP8QR3aaHO4gAEH6GV3RAr44yVLBwb023LSVkrkR45liAAAAAAJMUAEAAAAgf1BDCThONgyo3aXVGaZPHbvUVh7DJtZBDkYdxqjt6R0AAAAACWlzU3RvcHBlZAcAAAABAAAAAWkBAAAABXN0YWtlAAAAAAQAAAADcG10CQEAAAAFdmFsdWUAAAABCQABkQAAAAIIBQAAAAFpAAAACHBheW1lbnRzAAAAAAAAAAAABAAAAAlwbXRBbW91bnQIBQAAAANwbXQAAAAGYW1vdW50BAAAAAlrZXlTdGFrZWQCAAAACVNUQUtFRF9MUAMJAQAAAAIhPQAAAAIIBQAAAANwbXQAAAAHYXNzZXRJZAUAAAACSUQJAAACAAAAAQIAAAAbYXR0YWNoIHRlc3ROU0JUIHRva2VucyBvbmx5AwUAAAAJaXNTdG9wcGVkCQAAAgAAAAECAAAAGXNtYXJ0IGNvbnRyYWN0IGlzIG9uIGxvY2sEAAAACmluVHJlYXN1cnkJAAPwAAAAAgUAAAAEdGhpcwUAAAACSUQ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T39wBLKU1w1aMeXGr
Next: GHMshr3656d58JDiHN3buqoj8i2b6HwbyCJTkP8akYFe
Diff:
Old | New | | Differences |
---|
11 | 11 | | func stake () = { |
---|
12 | 12 | | let pmt = value(i.payments[0]) |
---|
13 | 13 | | let pmtAmount = pmt.amount |
---|
| 14 | + | let keyStaked = "STAKED_LP" |
---|
14 | 15 | | if ((pmt.assetId != ID)) |
---|
15 | 16 | | then throw("attach testNSBT tokens only") |
---|
16 | 17 | | else if (isStopped) |
---|
|
23 | 24 | | case _ => |
---|
24 | 25 | | throw("Can't find asset") |
---|
25 | 26 | | } |
---|
26 | | - | let singleLPinValue = ((totalIssued * 100000000) / inTreasury) |
---|
27 | | - | let amountToIssue = ((pmtAmount * singleLPinValue) / 100000000) |
---|
| 27 | + | let treasury = (inTreasury - pmtAmount) |
---|
| 28 | + | let singleLPinValue = fraction(totalIssued, 100000000, treasury) |
---|
| 29 | + | let amountToIssue = fraction(pmtAmount, singleLPinValue, 100000000) |
---|
28 | 30 | | let LPIssue = Reissue(LP, amountToIssue, true) |
---|
29 | 31 | | let transfer = ScriptTransfer(i.caller, amountToIssue, LP) |
---|
30 | | - | [LPIssue, transfer] |
---|
| 32 | + | let staked = valueOrElse(getInteger(this, keyStaked), 0) |
---|
| 33 | + | let updateState = IntegerEntry(keyStaked, (staked + i.payments[0].amount)) |
---|
| 34 | + | [LPIssue, transfer, updateState] |
---|
31 | 35 | | } |
---|
32 | 36 | | } |
---|
33 | 37 | | |
---|
34 | | - | |
---|
35 | | - | |
---|
36 | | - | @Callable(i) |
---|
37 | | - | func withdraw (amount) = { |
---|
38 | | - | let attached = i.payments[0] |
---|
39 | | - | let paymentID = i.payments[0].assetId |
---|
40 | | - | if ((paymentID != LP)) |
---|
41 | | - | then throw("Attach the correct LP token") |
---|
42 | | - | else { |
---|
43 | | - | let newAmount = (attached.amount - amount) |
---|
44 | | - | if ((0 > amount)) |
---|
45 | | - | then throw("Can't withdraw negative amount") |
---|
46 | | - | else if ((0 > newAmount)) |
---|
47 | | - | then throw("Not enough balance") |
---|
48 | | - | else { |
---|
49 | | - | let burning = Burn(LP, amount) |
---|
50 | | - | let transfer = ScriptTransfer(i.caller, newAmount, ID) |
---|
51 | | - | [burning, transfer] |
---|
52 | | - | } |
---|
53 | | - | } |
---|
54 | | - | } |
---|
55 | | - | |
---|
56 | | - | |
---|
57 | | - | @Verifier(tx) |
---|
58 | | - | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|
59 | 38 | | |
---|
Full:
Old | New | | Differences |
---|
1 | 1 | | {-# STDLIB_VERSION 5 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
4 | 4 | | let ID = base58'JAfMu2seKNzTVfqi5w5Pjh4kwwPTZPCEFpc2q2vDyFeh' |
---|
5 | 5 | | |
---|
6 | 6 | | let LP = base58'9ZymB4TJF6oQ3HwYgYFKizAf6m64sQF896mUzcsDJ4Wx' |
---|
7 | 7 | | |
---|
8 | 8 | | let isStopped = false |
---|
9 | 9 | | |
---|
10 | 10 | | @Callable(i) |
---|
11 | 11 | | func stake () = { |
---|
12 | 12 | | let pmt = value(i.payments[0]) |
---|
13 | 13 | | let pmtAmount = pmt.amount |
---|
| 14 | + | let keyStaked = "STAKED_LP" |
---|
14 | 15 | | if ((pmt.assetId != ID)) |
---|
15 | 16 | | then throw("attach testNSBT tokens only") |
---|
16 | 17 | | else if (isStopped) |
---|
17 | 18 | | then throw("smart contract is on lock") |
---|
18 | 19 | | else { |
---|
19 | 20 | | let inTreasury = assetBalance(this, ID) |
---|
20 | 21 | | let totalIssued = match assetInfo(LP) { |
---|
21 | 22 | | case asset: Asset => |
---|
22 | 23 | | asset.quantity |
---|
23 | 24 | | case _ => |
---|
24 | 25 | | throw("Can't find asset") |
---|
25 | 26 | | } |
---|
26 | | - | let singleLPinValue = ((totalIssued * 100000000) / inTreasury) |
---|
27 | | - | let amountToIssue = ((pmtAmount * singleLPinValue) / 100000000) |
---|
| 27 | + | let treasury = (inTreasury - pmtAmount) |
---|
| 28 | + | let singleLPinValue = fraction(totalIssued, 100000000, treasury) |
---|
| 29 | + | let amountToIssue = fraction(pmtAmount, singleLPinValue, 100000000) |
---|
28 | 30 | | let LPIssue = Reissue(LP, amountToIssue, true) |
---|
29 | 31 | | let transfer = ScriptTransfer(i.caller, amountToIssue, LP) |
---|
30 | | - | [LPIssue, transfer] |
---|
| 32 | + | let staked = valueOrElse(getInteger(this, keyStaked), 0) |
---|
| 33 | + | let updateState = IntegerEntry(keyStaked, (staked + i.payments[0].amount)) |
---|
| 34 | + | [LPIssue, transfer, updateState] |
---|
31 | 35 | | } |
---|
32 | 36 | | } |
---|
33 | 37 | | |
---|
34 | | - | |
---|
35 | | - | |
---|
36 | | - | @Callable(i) |
---|
37 | | - | func withdraw (amount) = { |
---|
38 | | - | let attached = i.payments[0] |
---|
39 | | - | let paymentID = i.payments[0].assetId |
---|
40 | | - | if ((paymentID != LP)) |
---|
41 | | - | then throw("Attach the correct LP token") |
---|
42 | | - | else { |
---|
43 | | - | let newAmount = (attached.amount - amount) |
---|
44 | | - | if ((0 > amount)) |
---|
45 | | - | then throw("Can't withdraw negative amount") |
---|
46 | | - | else if ((0 > newAmount)) |
---|
47 | | - | then throw("Not enough balance") |
---|
48 | | - | else { |
---|
49 | | - | let burning = Burn(LP, amount) |
---|
50 | | - | let transfer = ScriptTransfer(i.caller, newAmount, ID) |
---|
51 | | - | [burning, transfer] |
---|
52 | | - | } |
---|
53 | | - | } |
---|
54 | | - | } |
---|
55 | | - | |
---|
56 | | - | |
---|
57 | | - | @Verifier(tx) |
---|
58 | | - | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|
59 | 38 | | |
---|