tx · 3sPLws5tXwicZQGq4hv1AaDf27Z369MFXcftqpGZsoHa 3MwLcJy3MSb2kq6dUaUR5uBgm8zCKZMjz2S: -0.01400000 Waves 2021.03.26 23:26 [1455189] smart account 3MwLcJy3MSb2kq6dUaUR5uBgm8zCKZMjz2S > SELF 0.00000000 Waves
{ "type": 13, "id": "3sPLws5tXwicZQGq4hv1AaDf27Z369MFXcftqpGZsoHa", "fee": 1400000, "feeAssetId": null, "timestamp": 1616790406533, "version": 2, "chainId": 84, "sender": "3MwLcJy3MSb2kq6dUaUR5uBgm8zCKZMjz2S", "senderPublicKey": "CgByewRUvLk7UtWSfRMLSYw4Ap2wT5dcdVYKideqDp9M", "proofs": [ "tUZAmPEkMACLu5KT9Vm1GydrSfg5bq3Ao6sL8vY6Btk7iDn13TpUyXGWgaw2iE1Z8bevWzPWF7x8okg14NU3MBM" ], "script": "base64:AAIEAAAAAAAAAAgIAhIAEgASAAAAAA8AAAAADnRvdGFsRmVlRXRoS2V5AgAAAA10b3RhbF9mZWVfZXRoAAAAAA50b3RhbEZlZVVzZEtleQIAAAANdG90YWxfZmVlX3VzZAAAAAASdG90YWxGZWVEeXpyYXB0S2V5AgAAABF0b3RhbF9mZWVfZHl6cmFwdAAAAAARcHJpY2VPZkR5enJhcHRLZXkCAAAAA2R5egAAAAANcHJpY2VPZkV0aEtleQIAAAADZXRoAAAAAA1vcmFjbGVBZGRyZXNzCQEAAAAHQWRkcmVzcwAAAAEBAAAAGgFUvj/uzYkPvAWmBY0l0o79qoW9wh0kW3OWAAAAAA5keXpyYXB0QXNzZXRJZAEAAAAgnxnpc9km71BHiGYaP3+jsvIwnjyNE9APQJ48k4SnBCMAAAAACmV0aEFzc2V0SWQBAAAAICImU7qSm/1VgN3CrHN9jStFD2u0cA4gGz96jcaC4wuhAAAAAAt1c2RuQXNzZXRJZAEAAAAgfGnBa2RwgHQkUhuI1e0jfydVGajNaZehqKCu72Hgd8IBAAAADGdldEZlZUFtb3VudAAAAAEAAAAGYW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QAAAApldGhBc3NldElkCQAAAgAAAAECAAAAKU9ubHkgd2V0aCB0b2tlbnMgYXJlIGFsbG93ZWQgZm9yIHN3YXBwaW5nBAAAAANmZWUJAQAAAAxnZXRGZWVBbW91bnQAAAABBQAAAAt0b3RhbEFtb3VudAQAAAAGYW1vdW50CQAAZQAAAAIFAAAAC3RvdGFsQW1vdW50BQAAAANmZWUEAAAACGV0aFByaWNlCQEAAAATdmFsdWVPckVycm9yTWVzc2FnZQAAAAIJAAQaAAAAAgUAAAANb3JhY2xlQWRkcmVzcwUAAAANcHJpY2VPZkV0aEtleQIAAAAUVW5hYmxlIHRvIGxvYWQgcHJpY2UEAAAACnVzZG5BbW91bnQJAABrAAAAAwUAAAAGYW1vdW50BQAAAAhldGhQcmljZQAAAAAAAAAnEAQAAAANZHl6cmFwdEFtb3VudAkBAAAADXVzZG5Ub0R5enJhcHQAAAABBQAAAAp1c2RuQW1vdW50BAAAAAhzYXZlZEZlZQkBAAAADmdldFRvdGFsRmVlRXRoAAAAAAQAAAAIdG90YWxGZWUJAABkAAAAAgUAAAAIc2F2ZWRGZWUFAAAAA2ZlZQkABEwAAAACCQEAAAAMSW50ZWdlckVudHJ5AAAAAgUAAAAOdG90YWxGZWVFdGhLZXkFAAAACHRvdGFsRmVlCQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMIBQAAAAFpAAAABmNhbGxlcgUAAAANZHl6cmFwdEFtb3VudAUAAAAOZHl6cmFwdEFzc2V0SWQFAAAAA25pbAAAAAANN/Wx", "height": 1455189, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: Fm35RrkjvLNf4dZYggTUdmDGAtDW7KV7VRWJWcH1tMFc Next: 5R5BHKikDAGwFGHyA72uMjcsx5XfXsQJNRvZmsmcyxUB Diff:
Old | New | Differences | |
---|---|---|---|
7 | 7 | ||
8 | 8 | let totalFeeDyzraptKey = "total_fee_dyzrapt" | |
9 | 9 | ||
10 | - | let | |
10 | + | let priceOfDyzraptKey = "dyz" | |
11 | 11 | ||
12 | - | let | |
12 | + | let priceOfEthKey = "eth" | |
13 | 13 | ||
14 | 14 | let oracleAddress = Address(base58'3N7G2kVtBTh94aEnDHQ9dpi4EdsDxAiDXjB') | |
15 | 15 | ||
41 | 41 | ||
42 | 42 | ||
43 | 43 | func usdnToDyzrapt (amount) = { | |
44 | - | let dyzraptPrice = valueOrErrorMessage(getInteger(oracleAddress, | |
44 | + | let dyzraptPrice = valueOrErrorMessage(getInteger(oracleAddress, priceOfDyzraptKey), "Unable to load price") | |
45 | 45 | fraction(amount, 10000, dyzraptPrice) | |
46 | 46 | } | |
47 | 47 | ||
76 | 76 | } | |
77 | 77 | ||
78 | 78 | ||
79 | + | ||
80 | + | @Callable(i) | |
81 | + | func swapEthToDyzrapt () = { | |
82 | + | let pmt = value(i.payments[0]) | |
83 | + | let assetId = pmt.assetId | |
84 | + | let totalAmount = pmt.amount | |
85 | + | if ((assetId != ethAssetId)) | |
86 | + | then throw("Only weth tokens are allowed for swapping") | |
87 | + | else { | |
88 | + | let fee = getFeeAmount(totalAmount) | |
89 | + | let amount = (totalAmount - fee) | |
90 | + | let ethPrice = valueOrErrorMessage(getInteger(oracleAddress, priceOfEthKey), "Unable to load price") | |
91 | + | let usdnAmount = fraction(amount, ethPrice, 10000) | |
92 | + | let dyzraptAmount = usdnToDyzrapt(usdnAmount) | |
93 | + | let savedFee = getTotalFeeEth() | |
94 | + | let totalFee = (savedFee + fee) | |
95 | + | [IntegerEntry(totalFeeEthKey, totalFee), ScriptTransfer(i.caller, dyzraptAmount, dyzraptAssetId)] | |
96 | + | } | |
97 | + | } | |
98 | + | ||
99 | + |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 4 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let totalFeeEthKey = "total_fee_eth" | |
5 | 5 | ||
6 | 6 | let totalFeeUsdKey = "total_fee_usd" | |
7 | 7 | ||
8 | 8 | let totalFeeDyzraptKey = "total_fee_dyzrapt" | |
9 | 9 | ||
10 | - | let | |
10 | + | let priceOfDyzraptKey = "dyz" | |
11 | 11 | ||
12 | - | let | |
12 | + | let priceOfEthKey = "eth" | |
13 | 13 | ||
14 | 14 | let oracleAddress = Address(base58'3N7G2kVtBTh94aEnDHQ9dpi4EdsDxAiDXjB') | |
15 | 15 | ||
16 | 16 | let dyzraptAssetId = base58'Bi4jxKEFjjYG2emeyxZfpkVMS88N7uAogHNsi1urkoJA' | |
17 | 17 | ||
18 | 18 | let ethAssetId = base58'3JJkzB4pFXcqdJvC9TcV8ys1FLgesr5SxbhmykkpceQp' | |
19 | 19 | ||
20 | 20 | let usdnAssetId = base58'9Nf5wpj6jds3VRZKDryp6Dtf3R9d8MdbjNhencLogCr5' | |
21 | 21 | ||
22 | 22 | func getFeeAmount (amount) = { | |
23 | 23 | let fee = fraction(amount, 3, 100) | |
24 | 24 | fee | |
25 | 25 | } | |
26 | 26 | ||
27 | 27 | ||
28 | 28 | func getIntKeyData (key) = { | |
29 | 29 | let v = valueOrElse(getInteger(this, key), 0) | |
30 | 30 | v | |
31 | 31 | } | |
32 | 32 | ||
33 | 33 | ||
34 | 34 | func getTotalFeeEth () = getIntKeyData(totalFeeEthKey) | |
35 | 35 | ||
36 | 36 | ||
37 | 37 | func getTotalFeeUsd () = getIntKeyData(totalFeeUsdKey) | |
38 | 38 | ||
39 | 39 | ||
40 | 40 | func getTotalFeeDyzrapt () = getIntKeyData(totalFeeDyzraptKey) | |
41 | 41 | ||
42 | 42 | ||
43 | 43 | func usdnToDyzrapt (amount) = { | |
44 | - | let dyzraptPrice = valueOrErrorMessage(getInteger(oracleAddress, | |
44 | + | let dyzraptPrice = valueOrErrorMessage(getInteger(oracleAddress, priceOfDyzraptKey), "Unable to load price") | |
45 | 45 | fraction(amount, 10000, dyzraptPrice) | |
46 | 46 | } | |
47 | 47 | ||
48 | 48 | ||
49 | 49 | @Callable(i) | |
50 | 50 | func test () = { | |
51 | 51 | let pmt = value(i.payments[0]) | |
52 | 52 | let assetId = pmt.assetId | |
53 | 53 | let amount = pmt.amount | |
54 | 54 | if ((assetId == dyzraptAssetId)) | |
55 | 55 | then throw(("its a dyzrapt. Amount=" + toString(amount))) | |
56 | 56 | else throw("its not a dyzrapt") | |
57 | 57 | } | |
58 | 58 | ||
59 | 59 | ||
60 | 60 | ||
61 | 61 | @Callable(i) | |
62 | 62 | func swapUsdnToDyzrapt () = { | |
63 | 63 | let pmt = value(i.payments[0]) | |
64 | 64 | let assetId = pmt.assetId | |
65 | 65 | let totalAmount = pmt.amount | |
66 | 66 | if ((assetId != usdnAssetId)) | |
67 | 67 | then throw("Only usdn tokens are allowed for swapping") | |
68 | 68 | else { | |
69 | 69 | let fee = getFeeAmount(totalAmount) | |
70 | 70 | let amount = (totalAmount - fee) | |
71 | 71 | let dyzraptAmount = usdnToDyzrapt(amount) | |
72 | 72 | let savedFee = getTotalFeeUsd() | |
73 | 73 | let totalFee = (savedFee + fee) | |
74 | 74 | [IntegerEntry(totalFeeUsdKey, totalFee), ScriptTransfer(i.caller, dyzraptAmount, dyzraptAssetId)] | |
75 | 75 | } | |
76 | 76 | } | |
77 | 77 | ||
78 | 78 | ||
79 | + | ||
80 | + | @Callable(i) | |
81 | + | func swapEthToDyzrapt () = { | |
82 | + | let pmt = value(i.payments[0]) | |
83 | + | let assetId = pmt.assetId | |
84 | + | let totalAmount = pmt.amount | |
85 | + | if ((assetId != ethAssetId)) | |
86 | + | then throw("Only weth tokens are allowed for swapping") | |
87 | + | else { | |
88 | + | let fee = getFeeAmount(totalAmount) | |
89 | + | let amount = (totalAmount - fee) | |
90 | + | let ethPrice = valueOrErrorMessage(getInteger(oracleAddress, priceOfEthKey), "Unable to load price") | |
91 | + | let usdnAmount = fraction(amount, ethPrice, 10000) | |
92 | + | let dyzraptAmount = usdnToDyzrapt(usdnAmount) | |
93 | + | let savedFee = getTotalFeeEth() | |
94 | + | let totalFee = (savedFee + fee) | |
95 | + | [IntegerEntry(totalFeeEthKey, totalFee), ScriptTransfer(i.caller, dyzraptAmount, dyzraptAssetId)] | |
96 | + | } | |
97 | + | } | |
98 | + | ||
99 | + |
github/deemru/w8io/169f3d6 28.07 ms ◑