tx · 7zoigKNpgR81ZhNZoqPtu4AUtrP4y4VoGP85qgPjn8Wi 3MxN27tyS9DuFsab1QSfM5Q2BfauiyVCr4M: -0.03700000 Waves 2022.09.21 12:24 [2238712] smart account 3MxN27tyS9DuFsab1QSfM5Q2BfauiyVCr4M > SELF 0.00000000 Waves
{ "type": 13, "id": "7zoigKNpgR81ZhNZoqPtu4AUtrP4y4VoGP85qgPjn8Wi", "fee": 3700000, "feeAssetId": null, "timestamp": 1663752373321, "version": 2, "chainId": 84, "sender": "3MxN27tyS9DuFsab1QSfM5Q2BfauiyVCr4M", "senderPublicKey": "6PjNBLx8VTTNLWTS5y6zecyVfYCUC9ZCrAULFnLQU4XM", "proofs": [ "24GbAc1b7kvr4CQxQpoDtwg1wj3m68HApR9mJtw8D7i6h2FuRdnvMDJwkVbUQGdbQ6Jo3KmxHfRFV4iRe44mH2gq" ], "script": "base64:BgIXCAISABIECgIICBIDCgEIEgASBAoCCAEzABBrX3JlZl9saW5rX293bmVyAhBrX3JlZl9saW5rX293bmVyABZrX3JlZl9saW5rX293bmVyX2NvdW50AhZrX3JlZl9saW5rX293bmVyX2NvdW50ABBrX3JlZl9vd25lcl9saW5rAhBrX3JlZl9vd25lcl9saW5rAAprX3JlZmVycmVyAgprX3JlZmVycmVyAAhrX2FjdGl2ZQIIa19hY3RpdmUADGtfZGVmYXVsdEZlZQIMa19kZWZhdWx0RmVlABRrX3JlZmVycmVyX3JlZl9jb3VudAIUa19yZWZlcnJlcl9yZWZfY291bnQAEWtfcmVmZXJyZXJfZWFybmVkAhFrX3JlZmVycmVyX2Vhcm5lZAASa19yZWZlcnJlcl9jbGFpbWVkAhJrX3JlZmVycmVyX2NsYWltZWQADWtfaW5pdGlhbGl6ZWQCDWtfaW5pdGlhbGl6ZWQAFGtfY29vcmRpbmF0b3JBZGRyZXNzAhRrX2Nvb3JkaW5hdG9yQWRkcmVzcwASa19nb3Zlcm5hbmNlX2Fzc2V0AgtrX2dvdl9hc3NldAANa19xdW90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JEDAggFAnR4BnByb29mcwAACQEOYWRtaW5QdWJsaWNLZXkAdS+48A==", "height": 2238712, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: Bp2ucuWSx5Ze19CY2ywZaTwHNPqkVophepFgRi9X2gTU Next: 4rj3raxFbSJnq3Va31d43cCz7gCc1VaMk6rb2BRWyv6S Diff:
Old | New | Differences | |
---|---|---|---|
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let k_ref_link_owner = "k_ref_link_owner" | |
5 | + | ||
6 | + | let k_ref_link_owner_count = "k_ref_link_owner_count" | |
7 | + | ||
8 | + | let k_ref_owner_link = "k_ref_owner_link" | |
5 | 9 | ||
6 | 10 | let k_referrer = "k_referrer" | |
7 | 11 | ||
37 | 41 | ||
38 | 42 | ||
39 | 43 | func getReferrerRefCountKey (_referrer) = ((k_referrer_ref_count + "_") + _referrer) | |
44 | + | ||
45 | + | ||
46 | + | func getReferrerLinkCountKey (_referrer) = ((k_ref_link_owner_count + "_") + _referrer) | |
47 | + | ||
48 | + | ||
49 | + | func getReferrerLinkKeyAt (_referrer,_linkId) = ((((k_ref_owner_link + "_") + _referrer) + "_") + toString(_linkId)) | |
40 | 50 | ||
41 | 51 | ||
42 | 52 | func getReferrerEarnedKey (_referrer) = ((k_referrer_earned + "_") + _referrer) | |
120 | 130 | func getReferrerRefCount (_referrer) = valueOrElse(getInteger(this, getReferrerRefCountKey(_referrer)), 0) | |
121 | 131 | ||
122 | 132 | ||
133 | + | func getReferrerLinkCount (_referrer) = valueOrElse(getInteger(this, getReferrerLinkCountKey(_referrer)), 0) | |
134 | + | ||
135 | + | ||
123 | 136 | func getReferrerEarned (_referrer) = valueOrElse(getInteger(this, getReferrerEarnedKey(_referrer)), 0) | |
124 | 137 | ||
125 | 138 | ||
133 | 146 | let long = toBase58String(sha256(bytes)) | |
134 | 147 | let short = take(long, 10) | |
135 | 148 | let key = getReferrerLinkKey(short) | |
149 | + | let linkId = (getReferrerLinkCount(toString(i.caller)) + 1) | |
136 | 150 | if (isDefined(getString(this, key))) | |
137 | 151 | then throw("Short link exists, try generating it again") | |
138 | - | else [StringEntry(key, toString(i.caller))] | |
152 | + | else [StringEntry(getReferrerLinkKeyAt(toString(i.caller), linkId), short), StringEntry(key, toString(i.caller))] | |
139 | 153 | } | |
140 | 154 | ||
141 | 155 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let k_ref_link_owner = "k_ref_link_owner" | |
5 | + | ||
6 | + | let k_ref_link_owner_count = "k_ref_link_owner_count" | |
7 | + | ||
8 | + | let k_ref_owner_link = "k_ref_owner_link" | |
5 | 9 | ||
6 | 10 | let k_referrer = "k_referrer" | |
7 | 11 | ||
8 | 12 | let k_active = "k_active" | |
9 | 13 | ||
10 | 14 | let k_defaultFee = "k_defaultFee" | |
11 | 15 | ||
12 | 16 | let k_referrer_ref_count = "k_referrer_ref_count" | |
13 | 17 | ||
14 | 18 | let k_referrer_earned = "k_referrer_earned" | |
15 | 19 | ||
16 | 20 | let k_referrer_claimed = "k_referrer_claimed" | |
17 | 21 | ||
18 | 22 | let k_initialized = "k_initialized" | |
19 | 23 | ||
20 | 24 | let k_coordinatorAddress = "k_coordinatorAddress" | |
21 | 25 | ||
22 | 26 | let k_governance_asset = "k_gov_asset" | |
23 | 27 | ||
24 | 28 | let k_quote_asset = "k_quote_asset" | |
25 | 29 | ||
26 | 30 | let k_admin_public_key = "k_admin_public_key" | |
27 | 31 | ||
28 | 32 | let k_amm = "k_amm" | |
29 | 33 | ||
30 | 34 | func toCompositeKey (_key,_address) = ((_key + "_") + _address) | |
31 | 35 | ||
32 | 36 | ||
33 | 37 | func getReferrerLinkKey (_link) = ((k_ref_link_owner + "_") + _link) | |
34 | 38 | ||
35 | 39 | ||
36 | 40 | func getReferrerKey (_trader) = ((k_referrer + "_") + _trader) | |
37 | 41 | ||
38 | 42 | ||
39 | 43 | func getReferrerRefCountKey (_referrer) = ((k_referrer_ref_count + "_") + _referrer) | |
44 | + | ||
45 | + | ||
46 | + | func getReferrerLinkCountKey (_referrer) = ((k_ref_link_owner_count + "_") + _referrer) | |
47 | + | ||
48 | + | ||
49 | + | func getReferrerLinkKeyAt (_referrer,_linkId) = ((((k_ref_owner_link + "_") + _referrer) + "_") + toString(_linkId)) | |
40 | 50 | ||
41 | 51 | ||
42 | 52 | func getReferrerEarnedKey (_referrer) = ((k_referrer_earned + "_") + _referrer) | |
43 | 53 | ||
44 | 54 | ||
45 | 55 | func getReferrerClaimedKey (_referrer) = ((k_referrer_claimed + "_") + _referrer) | |
46 | 56 | ||
47 | 57 | ||
48 | 58 | func getActiveKey (_trader) = ((k_active + "_") + _trader) | |
49 | 59 | ||
50 | 60 | ||
51 | 61 | func coordinator () = valueOrErrorMessage(addressFromString(getStringValue(this, k_coordinatorAddress)), "Coordinator not set") | |
52 | 62 | ||
53 | 63 | ||
54 | 64 | func adminPublicKey () = fromBase58String(getStringValue(coordinator(), k_admin_public_key)) | |
55 | 65 | ||
56 | 66 | ||
57 | 67 | func governanceAsset () = fromBase58String(getStringValue(coordinator(), k_governance_asset)) | |
58 | 68 | ||
59 | 69 | ||
60 | 70 | func quoteAsset () = fromBase58String(getStringValue(coordinator(), k_quote_asset)) | |
61 | 71 | ||
62 | 72 | ||
63 | 73 | func isWhitelist (_address) = valueOrElse(getBoolean(coordinator(), toCompositeKey(k_amm, _address)), false) | |
64 | 74 | ||
65 | 75 | ||
66 | 76 | let DECIMAL_UNIT = (1 * (((((10 * 10) * 10) * 10) * 10) * 10)) | |
67 | 77 | ||
68 | 78 | let DURATION = ((60 * 60) * 24) | |
69 | 79 | ||
70 | 80 | let NO_ADDRESS = "" | |
71 | 81 | ||
72 | 82 | let NO_STAKER = 0 | |
73 | 83 | ||
74 | 84 | func usdnFromDecimals (_amount) = (_amount / 100) | |
75 | 85 | ||
76 | 86 | ||
77 | 87 | func usdnToDecimals (_amount) = (_amount * 100) | |
78 | 88 | ||
79 | 89 | ||
80 | 90 | func divd (_x,_y) = fraction(_x, DECIMAL_UNIT, _y, HALFEVEN) | |
81 | 91 | ||
82 | 92 | ||
83 | 93 | func muld (_x,_y) = fraction(_x, _y, DECIMAL_UNIT, HALFEVEN) | |
84 | 94 | ||
85 | 95 | ||
86 | 96 | func abs (_x) = if ((_x > 0)) | |
87 | 97 | then _x | |
88 | 98 | else -(_x) | |
89 | 99 | ||
90 | 100 | ||
91 | 101 | func minv (_x,_y) = if ((_x > _y)) | |
92 | 102 | then _y | |
93 | 103 | else _x | |
94 | 104 | ||
95 | 105 | ||
96 | 106 | func int (k) = valueOrErrorMessage(getInteger(this, k), ("no value for " + k)) | |
97 | 107 | ||
98 | 108 | ||
99 | 109 | func int0 (k) = valueOrElse(getInteger(this, k), 0) | |
100 | 110 | ||
101 | 111 | ||
102 | 112 | func initialized () = valueOrElse(getBoolean(this, k_initialized), false) | |
103 | 113 | ||
104 | 114 | ||
105 | 115 | func getLinkReferrer (_link) = valueOrElse(getString(this, getReferrerLinkKey(_link)), "") | |
106 | 116 | ||
107 | 117 | ||
108 | 118 | func getReferrer (_trader) = valueOrElse(getString(this, getReferrerKey(_trader)), "") | |
109 | 119 | ||
110 | 120 | ||
111 | 121 | func isReferral (_trader) = (getReferrer(_trader) != "") | |
112 | 122 | ||
113 | 123 | ||
114 | 124 | func isFirstTime (_trader) = (valueOrElse(getBoolean(this, getActiveKey(_trader)), false) == false) | |
115 | 125 | ||
116 | 126 | ||
117 | 127 | func getDefaultFee () = int(k_defaultFee) | |
118 | 128 | ||
119 | 129 | ||
120 | 130 | func getReferrerRefCount (_referrer) = valueOrElse(getInteger(this, getReferrerRefCountKey(_referrer)), 0) | |
121 | 131 | ||
122 | 132 | ||
133 | + | func getReferrerLinkCount (_referrer) = valueOrElse(getInteger(this, getReferrerLinkCountKey(_referrer)), 0) | |
134 | + | ||
135 | + | ||
123 | 136 | func getReferrerEarned (_referrer) = valueOrElse(getInteger(this, getReferrerEarnedKey(_referrer)), 0) | |
124 | 137 | ||
125 | 138 | ||
126 | 139 | func getReferrerClaimed (_referrer) = valueOrElse(getInteger(this, getReferrerClaimedKey(_referrer)), 0) | |
127 | 140 | ||
128 | 141 | ||
129 | 142 | @Callable(i) | |
130 | 143 | func createReferralLink () = { | |
131 | 144 | let raw = (toBase58String(i.transactionId) + toBase58String(i.callerPublicKey)) | |
132 | 145 | let bytes = toBytes(raw) | |
133 | 146 | let long = toBase58String(sha256(bytes)) | |
134 | 147 | let short = take(long, 10) | |
135 | 148 | let key = getReferrerLinkKey(short) | |
149 | + | let linkId = (getReferrerLinkCount(toString(i.caller)) + 1) | |
136 | 150 | if (isDefined(getString(this, key))) | |
137 | 151 | then throw("Short link exists, try generating it again") | |
138 | - | else [StringEntry(key, toString(i.caller))] | |
152 | + | else [StringEntry(getReferrerLinkKeyAt(toString(i.caller), linkId), short), StringEntry(key, toString(i.caller))] | |
139 | 153 | } | |
140 | 154 | ||
141 | 155 | ||
142 | 156 | ||
143 | 157 | @Callable(i) | |
144 | 158 | func acceptPaymentWithLink (_trader,_refLink) = { | |
145 | 159 | let _amount = i.payments[0].amount | |
146 | 160 | let amm = toString(i.caller) | |
147 | 161 | if (if (!(isWhitelist(amm))) | |
148 | 162 | then true | |
149 | 163 | else !(initialized())) | |
150 | 164 | then throw("Invalid acceptPaymentWithLink params") | |
151 | 165 | else { | |
152 | 166 | let _isReferral = isReferral(_trader) | |
153 | 167 | let _isFirstTime = isFirstTime(_trader) | |
154 | 168 | if (if (isReferral(_trader)) | |
155 | 169 | then true | |
156 | 170 | else isFirstTime(_trader)) | |
157 | 171 | then if (_isReferral) | |
158 | 172 | then { | |
159 | 173 | let referrer = getReferrer(_trader) | |
160 | 174 | let fee = getDefaultFee() | |
161 | 175 | let amountToReferrer = muld(_amount, fee) | |
162 | 176 | $Tuple2([IntegerEntry(getReferrerEarnedKey(referrer), (getReferrerEarned(referrer) + amountToReferrer)), ScriptTransfer(i.caller, (i.payments[0].amount - amountToReferrer), i.payments[0].assetId)], amountToReferrer) | |
163 | 177 | } | |
164 | 178 | else { | |
165 | 179 | let referrer = getLinkReferrer(_refLink) | |
166 | 180 | if ((referrer == "")) | |
167 | 181 | then $Tuple2([ScriptTransfer(i.caller, i.payments[0].amount, i.payments[0].assetId), BooleanEntry(getActiveKey(_trader), true)], 0) | |
168 | 182 | else { | |
169 | 183 | let fee = getDefaultFee() | |
170 | 184 | let amountToReferrer = muld(_amount, fee) | |
171 | 185 | $Tuple2([IntegerEntry(getReferrerRefCountKey(referrer), (getReferrerRefCount(referrer) + 1)), IntegerEntry(getReferrerEarnedKey(referrer), (getReferrerEarned(referrer) + amountToReferrer)), StringEntry(getReferrerKey(_trader), referrer), BooleanEntry(getActiveKey(_trader), true), ScriptTransfer(i.caller, (i.payments[0].amount - amountToReferrer), i.payments[0].assetId)], amountToReferrer) | |
172 | 186 | } | |
173 | 187 | } | |
174 | 188 | else $Tuple2([ScriptTransfer(i.caller, i.payments[0].amount, i.payments[0].assetId)], 0) | |
175 | 189 | } | |
176 | 190 | } | |
177 | 191 | ||
178 | 192 | ||
179 | 193 | ||
180 | 194 | @Callable(i) | |
181 | 195 | func acceptPayment (_trader) = { | |
182 | 196 | let _amount = i.payments[0].amount | |
183 | 197 | let amm = toString(i.caller) | |
184 | 198 | if (if (!(isWhitelist(amm))) | |
185 | 199 | then true | |
186 | 200 | else !(initialized())) | |
187 | 201 | then throw("Invalid acceptPayment params") | |
188 | 202 | else { | |
189 | 203 | let _isReferral = isReferral(_trader) | |
190 | 204 | if (_isReferral) | |
191 | 205 | then { | |
192 | 206 | let referrer = getReferrer(_trader) | |
193 | 207 | let fee = getDefaultFee() | |
194 | 208 | let amountToReferrer = muld(_amount, fee) | |
195 | 209 | $Tuple2([IntegerEntry(getReferrerEarnedKey(referrer), (getReferrerEarned(referrer) + amountToReferrer)), ScriptTransfer(i.caller, (i.payments[0].amount - amountToReferrer), i.payments[0].assetId)], amountToReferrer) | |
196 | 210 | } | |
197 | 211 | else $Tuple2([ScriptTransfer(i.caller, i.payments[0].amount, i.payments[0].assetId)], 0) | |
198 | 212 | } | |
199 | 213 | } | |
200 | 214 | ||
201 | 215 | ||
202 | 216 | ||
203 | 217 | @Callable(i) | |
204 | 218 | func claimRewards () = { | |
205 | 219 | let referrer = toString(i.caller) | |
206 | 220 | let totalRewards = getReferrerEarned(referrer) | |
207 | 221 | let totalClaimed = getReferrerClaimed(referrer) | |
208 | 222 | let toClaim = (totalRewards - totalClaimed) | |
209 | 223 | if ((toClaim > 0)) | |
210 | 224 | then [IntegerEntry(getReferrerClaimedKey(referrer), (getReferrerClaimed(referrer) + toClaim)), ScriptTransfer(i.caller, toClaim, quoteAsset())] | |
211 | 225 | else throw("Nothing to claim") | |
212 | 226 | } | |
213 | 227 | ||
214 | 228 | ||
215 | 229 | ||
216 | 230 | @Callable(i) | |
217 | 231 | func initialize (_coordinator,_defaultFee) = if (initialized()) | |
218 | 232 | then throw("Already initialized") | |
219 | 233 | else [StringEntry(k_coordinatorAddress, _coordinator), IntegerEntry(k_defaultFee, _defaultFee), BooleanEntry(k_initialized, true)] | |
220 | 234 | ||
221 | 235 | ||
222 | 236 | @Verifier(tx) | |
223 | 237 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], adminPublicKey()) | |
224 | 238 |
github/deemru/w8io/169f3d6 40.12 ms ◑