tx · 2KzffYLLdDPu6L12mnejYehEXPNSe4gvi4PFcQUEVP8t 3MvVBtsXroQpy1tsPw21TU2ET9A8WfmrNjz: -0.14000000 Waves 2022.12.05 18:53 [2347261] smart account 3MvVBtsXroQpy1tsPw21TU2ET9A8WfmrNjz > SELF 0.00000000 Waves
{ "type": 13, "id": "2KzffYLLdDPu6L12mnejYehEXPNSe4gvi4PFcQUEVP8t", "fee": 14000000, "feeAssetId": null, "timestamp": 1670255508972, "version": 2, "chainId": 84, "sender": "3MvVBtsXroQpy1tsPw21TU2ET9A8WfmrNjz", "senderPublicKey": "C3v9sfZTmGuW7YXwjUKypU41QpFcHCoJxLpvdR4d3iSv", "proofs": [ "3oVJo4RsYYZsodNd2qd5A28LzupAgf6urC4kPsRbtLpmtTGD2MBLAV5VKXHWwUF6s8nX5yiWARANsh9gTNhHMJDK", "3fLt9DdWEZoK1Ti2btapuKFUuBF46WVKf7ednwYmCtJRfCFRq4gEzqALQHnCCVFBF5BJjzY7hHsxxT5VBFu5Ms3s" ], "script": "base64:BgICCAITAAZvcmFjbGUJAQdBZGRyZXNzAQEaAVRIE5cMwNMzzCUygLYp96dkaICr48x7S5kBE2dldEJhc2U1OEZyb21PcmFjbGUBA2tleQQHJG1hdGNoMAkAnQgCBQZvcmFjbGUFA2tleQMJAAECBQckbWF0Y2gwAgZTdHJpbmcEBnN0cmluZwUHJG1hdGNoMAkA2QQBBQZzdHJpbmcEB25vdGhpbmcFByRtYXRjaDAJAAIBCQCsAgIFA2tleQIIaXMgZW1wdHkADWtBZG1pblB1YktleTECC2FkbWluX3B1Yl8xAA1rQWRtaW5QdWJLZXkyAgthZG1pbl9wdWJfMgANa0FkbWluUHViS2V5MwILYWRtaW5fcHViXzMAEmtBZG1pbkludm9rZVB1YktleQIQYWRtaW5faW52b2tlX3B1YgALa0dvdkFkZHJlc3MCEmdvdmVybmFuY2VfYWRkcmVzcwAMa0Zhcm1BZGRyZXNzAg9mYXJtaW5nX2FkZHJlc3MAD2tTd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AAACCAUDaW52BGRBcHAFDnN1cnZleXNBZGRyZXNzCQAAAggFA2ludghmdW5jdGlvbgILd3JpdGVUb3RhbHMHBA1zaWduZWRCeUFkbWluCQD0AwMIBQJ0eAlib2R5Qnl0ZXMJAJEDAggFAnR4BnByb29mcwAABQthZG1pbkludm9rZQMDAwMDAwUOaXNFeGNoYW5nZUNhbGwGBRJpc0V4Y2hhbmdlQ2FsbENQTU0GBQ1pc0FpcmRyb3BDYWxsBgUNaXNSb3V0aW5nQ2FsbAkAAAIJAJADAQgFA2ludghwYXltZW50cwABBwYDAwMDAwUTaXNVcGRhdGVXZWlnaHRzQ2FsbAYFFGlzVXBkYXRlUG9vbEludGVyZXN0BgUSaXNUYWtlbkludG9BY2NvdW50BgUWaXNUYWtlbkludG9BY2NvdW50Q1BNTQYFDGlzV3JpdGVUb3RhbAkAAAIJAJADAQgFA2ludghwYXltZW50cwAABwUNc2lnbmVkQnlBZG1pbgcEEmFkbWluUHViS2V5MVNpZ25lZAMJAPQDAwgFAnR4CWJvZHlCeXRlcwkAkQMCCAUCdHgGcHJvb2ZzAAAFDGFkbWluUHViS2V5MQABAAAEEmFkbWluUHViS2V5MlNpZ25lZAMJAPQDAwgFAnR4CWJvZHlCeXRlcwkAkQMCCAUCdHgGcHJvb2ZzAAEFDGFkbWluUHViS2V5MgABAAAEEmFkbWluUHViS2V5M1NpZ25lZAMJAPQDAwgFAnR4CWJvZHlCeXRlcwkAkQMCCAUCdHgGcHJvb2ZzAAIFDGFkbWluUHViS2V5MwABAAAJAGcCCQBkAgkAZAIFEmFkbWluUHViS2V5MVNpZ25lZAUSYWRtaW5QdWJLZXkyU2lnbmVkBRJhZG1pblB1YktleTNTaWduZWQAAkgjsu8=", "height": 2347261, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: CCULoPK3Xs1fpTp9cw5aZN7QXJPXse3HxBJxyH2uxBsc Next: 3yA1EuqYkrXyJZh5XbKiYtGssX6WEaWCkJv5G6uJ1v1S Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let | |
4 | + | let oracle = Address(base58'3MvVBtsXroQpy1tsPw21TU2ET9A8WfmrNjz') | |
5 | 5 | ||
6 | - | let kPair = "pair_" | |
6 | + | func getBase58FromOracle (key) = match getString(oracle, key) { | |
7 | + | case string: String => | |
8 | + | fromBase58String(string) | |
9 | + | case nothing => | |
10 | + | throw((key + "is empty")) | |
11 | + | } | |
7 | 12 | ||
8 | - | let kAssetIdA = "A_asset_id" | |
9 | - | ||
10 | - | let kAssetIdB = "B_asset_id" | |
11 | - | ||
12 | - | let kLaunchpadDataTransactionStatus = "launchpad_data_transaction_status" | |
13 | - | ||
14 | - | let kActiveAllContracts = "active_all_contracts" | |
15 | - | ||
16 | - | let kAdminPubKey = "admin_pub_" | |
17 | 13 | ||
18 | 14 | let kAdminPubKey1 = "admin_pub_1" | |
19 | 15 | ||
23 | 19 | ||
24 | 20 | let kAdminInvokePubKey = "admin_invoke_pub" | |
25 | 21 | ||
26 | - | let | |
22 | + | let kGovAddress = "governance_address" | |
27 | 23 | ||
28 | - | let | |
24 | + | let kFarmAddress = "farming_address" | |
29 | 25 | ||
30 | - | let | |
26 | + | let kSurveysAddress = "surveys_address" | |
31 | 27 | ||
32 | - | let | |
28 | + | let kRoutingAddr = "routing_address" | |
33 | 29 | ||
34 | - | let | |
30 | + | let adminPubKey1 = getBase58FromOracle(kAdminPubKey1) | |
35 | 31 | ||
36 | - | func isSelfCall (i) = if ((i.caller == this)) | |
37 | - | then unit | |
38 | - | else throw("Only the Oracle itself can invoke this function") | |
32 | + | let adminPubKey2 = getBase58FromOracle(kAdminPubKey2) | |
39 | 33 | ||
34 | + | let adminPubKey3 = getBase58FromOracle(kAdminPubKey3) | |
40 | 35 | ||
41 | - | func getPoolType (poolAddress) = { | |
42 | - | let version = valueOrErrorMessage(getString(poolAddress, "version"), "Pool is not initialized") | |
43 | - | if ((version == "1.0.0")) | |
44 | - | then "cpmm" | |
45 | - | else if ((version == "2.0.0")) | |
46 | - | then "flat" | |
47 | - | else if ((version == "3.0.0")) | |
48 | - | then "multycurve" | |
49 | - | else throw("Unknown version of pool") | |
50 | - | } | |
36 | + | let adminInvoke = getBase58FromOracle(kAdminInvokePubKey) | |
51 | 37 | ||
38 | + | let governanceAddress = Address(getBase58FromOracle(kGovAddress)) | |
52 | 39 | ||
53 | - | ||
40 | + | let farmingAddress = Address(getBase58FromOracle(kFarmAddress)) | |
54 | 41 | ||
42 | + | let surveysAddress = Address(getBase58FromOracle(kSurveysAddress)) | |
55 | 43 | ||
56 | - | func isAdminCall (i) = if (containsElement([adminPubKey1, adminPubKey2, adminPubKey3], i.callerPublicKey)) | |
57 | - | then unit | |
58 | - | else throw("Only admin can call this function") | |
44 | + | let routingAddress = Address(getBase58FromOracle(kRoutingAddr)) | |
59 | 45 | ||
60 | - | ||
61 | - | @Callable(i) | |
62 | - | func setAdmin (adminId,adminPubKey) = valueOrElse(isSelfCall(i), if (if ((0 > adminId)) | |
63 | - | then (adminId > 3) | |
64 | - | else false) | |
65 | - | then throw("Wrong admin id") | |
66 | - | else [StringEntry((kAdminPubKey + toString(adminId)), adminPubKey)]) | |
67 | - | ||
68 | - | ||
69 | - | ||
70 | - | @Callable(i) | |
71 | - | func addPool (poolAddress,poolName) = valueOrElse(isAdminCall(i), { | |
72 | - | let validatedAddress = getAddressIfValid(poolAddress) | |
73 | - | let keyName = (kPrefixPoolName + validatedAddress) | |
74 | - | let possiblyAlreadyAddedPool = getString(this, keyName) | |
75 | - | if (isDefined(possiblyAlreadyAddedPool)) | |
76 | - | then throw((((("Pool with address \"" + validatedAddress) + "\" is already defined with name \"") + value(possiblyAlreadyAddedPool)) + "\"")) | |
77 | - | else ([StringEntry(keyName, poolName)] ++ (if ((getPoolType(value(addressFromString(poolAddress))) == "multycurve")) | |
78 | - | then nil | |
79 | - | else { | |
80 | - | let assetIdA = valueOrErrorMessage(getString(value(addressFromString(poolAddress)), kAssetIdA), "Asset id A is incorrect") | |
81 | - | let assetIdB = valueOrErrorMessage(getString(value(addressFromString(poolAddress)), kAssetIdB), "Asset id B is incorrect") | |
82 | - | [StringEntry((((kPair + assetIdA) + "_") + assetIdB), poolAddress)] | |
83 | - | })) | |
84 | - | }) | |
85 | - | ||
86 | - | ||
87 | - | ||
88 | - | @Callable(i) | |
89 | - | func launchpadDataTransactionStatus (status) = valueOrElse(isAdminCall(i), [BooleanEntry(kLaunchpadDataTransactionStatus, status)]) | |
90 | - | ||
91 | - | ||
92 | - | ||
93 | - | @Callable(i) | |
94 | - | func addAchievementsWriter (address) = valueOrElse(isAdminCall(i), { | |
95 | - | let writers = valueOrElse(getString(this, kAchievementsWriters), "") | |
96 | - | let data = if ((writers == "")) | |
97 | - | then nil | |
98 | - | else split(writers, ",") | |
99 | - | [StringEntry(kAchievementsWriters, makeString((data :+ address), ","))] | |
100 | - | }) | |
101 | - | ||
102 | - | ||
103 | - | ||
104 | - | @Callable(i) | |
105 | - | func removeAchievementsWriter (address) = valueOrElse(isAdminCall(i), { | |
106 | - | let writers = split(valueOrElse(getString(this, kAchievementsWriters), ""), ",") | |
107 | - | let index = valueOrErrorMessage(indexOf(writers, address), "Can't find address in the list") | |
108 | - | [StringEntry(kAchievementsWriters, makeString(removeByIndex(writers, index), ","))] | |
109 | - | }) | |
110 | - | ||
111 | - | ||
112 | - | ||
113 | - | @Callable(i) | |
114 | - | func shutdownAllContracts () = valueOrElse(isAdminCall(i), if (!(activeAllContracts)) | |
115 | - | then throw("All contracts already shutdown") | |
116 | - | else [BooleanEntry(kActiveAllContracts, false)]) | |
117 | - | ||
118 | - | ||
119 | - | ||
120 | - | @Callable(i) | |
121 | - | func activateAllContracts () = valueOrElse(isAdminCall(i), if (activeAllContracts) | |
122 | - | then throw("All contracts already active") | |
123 | - | else [BooleanEntry(kActiveAllContracts, true)]) | |
46 | + | let keyPrefixPoolName = "pool_" | |
124 | 47 | ||
125 | 48 | ||
126 | 49 | @Verifier(tx) | |
127 | - | func verify () = { | |
128 | - | let adminPubKey1Signed = if (sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey1)) | |
129 | - | then 1 | |
130 | - | else 0 | |
131 | - | let adminPubKey2Signed = if (sigVerify(tx.bodyBytes, tx.proofs[1], adminPubKey2)) | |
132 | - | then 1 | |
133 | - | else 0 | |
134 | - | let adminPubKey3Signed = if (sigVerify(tx.bodyBytes, tx.proofs[2], adminPubKey3)) | |
135 | - | then 1 | |
136 | - | else 0 | |
137 | - | (((adminPubKey1Signed + adminPubKey2Signed) + adminPubKey3Signed) >= 2) | |
138 | - | } | |
50 | + | func verify () = match tx { | |
51 | + | case inv: InvokeScriptTransaction => | |
52 | + | let isRoutingCall = if ((inv.dApp == routingAddress)) | |
53 | + | then (inv.function == "routingTrade") | |
54 | + | else false | |
55 | + | let isExchangeCallCPMM = if (if (isDefined(getString(oracle, (keyPrefixPoolName + toString(addressFromRecipient(inv.dApp)))))) | |
56 | + | then (inv.function == "callFunction") | |
57 | + | else false) | |
58 | + | then (inv.args[0] == "exchange") | |
59 | + | else false | |
60 | + | let isExchangeCall = if (isDefined(getString(oracle, (keyPrefixPoolName + toString(addressFromRecipient(inv.dApp)))))) | |
61 | + | then (inv.function == "exchange") | |
62 | + | else false | |
63 | + | let isAirdropCall = if ((inv.dApp == governanceAddress)) | |
64 | + | then (inv.function == "airDrop") | |
65 | + | else false | |
66 | + | let isUpdateWeightsCall = if ((inv.dApp == governanceAddress)) | |
67 | + | then (inv.function == "updateWeights") | |
68 | + | else false | |
69 | + | let isUpdatePoolInterest = if ((inv.dApp == farmingAddress)) | |
70 | + | then (inv.function == "updatePoolInterest") | |
71 | + | else false | |
72 | + | let isTakenIntoAccountCPMM = if (if (isDefined(getString(oracle, (keyPrefixPoolName + toString(addressFromRecipient(inv.dApp)))))) | |
73 | + | then (inv.function == "callFunction") | |
74 | + | else false) | |
75 | + | then (inv.args[0] == "takeIntoAccountExtraFunds") | |
76 | + | else false | |
77 | + | let isTakenIntoAccount = if (isDefined(getString(oracle, (keyPrefixPoolName + toString(addressFromRecipient(inv.dApp)))))) | |
78 | + | then (inv.function == "takeIntoAccountExtraFunds") | |
79 | + | else false | |
80 | + | let isWriteTotal = if ((inv.dApp == surveysAddress)) | |
81 | + | then (inv.function == "writeTotals") | |
82 | + | else false | |
83 | + | let signedByAdmin = sigVerify(tx.bodyBytes, tx.proofs[0], adminInvoke) | |
84 | + | if (if (if (if (if (if (isExchangeCall) | |
85 | + | then true | |
86 | + | else isExchangeCallCPMM) | |
87 | + | then true | |
88 | + | else isAirdropCall) | |
89 | + | then true | |
90 | + | else isRoutingCall) | |
91 | + | then (size(inv.payments) == 1) | |
92 | + | else false) | |
93 | + | then true | |
94 | + | else if (if (if (if (if (isUpdateWeightsCall) | |
95 | + | then true | |
96 | + | else isUpdatePoolInterest) | |
97 | + | then true | |
98 | + | else isTakenIntoAccount) | |
99 | + | then true | |
100 | + | else isTakenIntoAccountCPMM) | |
101 | + | then true | |
102 | + | else isWriteTotal) | |
103 | + | then (size(inv.payments) == 0) | |
104 | + | else false) | |
105 | + | then signedByAdmin | |
106 | + | else false | |
107 | + | case _ => | |
108 | + | let adminPubKey1Signed = if (sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey1)) | |
109 | + | then 1 | |
110 | + | else 0 | |
111 | + | let adminPubKey2Signed = if (sigVerify(tx.bodyBytes, tx.proofs[1], adminPubKey2)) | |
112 | + | then 1 | |
113 | + | else 0 | |
114 | + | let adminPubKey3Signed = if (sigVerify(tx.bodyBytes, tx.proofs[2], adminPubKey3)) | |
115 | + | then 1 | |
116 | + | else 0 | |
117 | + | (((adminPubKey1Signed + adminPubKey2Signed) + adminPubKey3Signed) >= 2) | |
118 | + | } | |
139 | 119 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let | |
4 | + | let oracle = Address(base58'3MvVBtsXroQpy1tsPw21TU2ET9A8WfmrNjz') | |
5 | 5 | ||
6 | - | let kPair = "pair_" | |
6 | + | func getBase58FromOracle (key) = match getString(oracle, key) { | |
7 | + | case string: String => | |
8 | + | fromBase58String(string) | |
9 | + | case nothing => | |
10 | + | throw((key + "is empty")) | |
11 | + | } | |
7 | 12 | ||
8 | - | let kAssetIdA = "A_asset_id" | |
9 | - | ||
10 | - | let kAssetIdB = "B_asset_id" | |
11 | - | ||
12 | - | let kLaunchpadDataTransactionStatus = "launchpad_data_transaction_status" | |
13 | - | ||
14 | - | let kActiveAllContracts = "active_all_contracts" | |
15 | - | ||
16 | - | let kAdminPubKey = "admin_pub_" | |
17 | 13 | ||
18 | 14 | let kAdminPubKey1 = "admin_pub_1" | |
19 | 15 | ||
20 | 16 | let kAdminPubKey2 = "admin_pub_2" | |
21 | 17 | ||
22 | 18 | let kAdminPubKey3 = "admin_pub_3" | |
23 | 19 | ||
24 | 20 | let kAdminInvokePubKey = "admin_invoke_pub" | |
25 | 21 | ||
26 | - | let | |
22 | + | let kGovAddress = "governance_address" | |
27 | 23 | ||
28 | - | let | |
24 | + | let kFarmAddress = "farming_address" | |
29 | 25 | ||
30 | - | let | |
26 | + | let kSurveysAddress = "surveys_address" | |
31 | 27 | ||
32 | - | let | |
28 | + | let kRoutingAddr = "routing_address" | |
33 | 29 | ||
34 | - | let | |
30 | + | let adminPubKey1 = getBase58FromOracle(kAdminPubKey1) | |
35 | 31 | ||
36 | - | func isSelfCall (i) = if ((i.caller == this)) | |
37 | - | then unit | |
38 | - | else throw("Only the Oracle itself can invoke this function") | |
32 | + | let adminPubKey2 = getBase58FromOracle(kAdminPubKey2) | |
39 | 33 | ||
34 | + | let adminPubKey3 = getBase58FromOracle(kAdminPubKey3) | |
40 | 35 | ||
41 | - | func getPoolType (poolAddress) = { | |
42 | - | let version = valueOrErrorMessage(getString(poolAddress, "version"), "Pool is not initialized") | |
43 | - | if ((version == "1.0.0")) | |
44 | - | then "cpmm" | |
45 | - | else if ((version == "2.0.0")) | |
46 | - | then "flat" | |
47 | - | else if ((version == "3.0.0")) | |
48 | - | then "multycurve" | |
49 | - | else throw("Unknown version of pool") | |
50 | - | } | |
36 | + | let adminInvoke = getBase58FromOracle(kAdminInvokePubKey) | |
51 | 37 | ||
38 | + | let governanceAddress = Address(getBase58FromOracle(kGovAddress)) | |
52 | 39 | ||
53 | - | ||
40 | + | let farmingAddress = Address(getBase58FromOracle(kFarmAddress)) | |
54 | 41 | ||
42 | + | let surveysAddress = Address(getBase58FromOracle(kSurveysAddress)) | |
55 | 43 | ||
56 | - | func isAdminCall (i) = if (containsElement([adminPubKey1, adminPubKey2, adminPubKey3], i.callerPublicKey)) | |
57 | - | then unit | |
58 | - | else throw("Only admin can call this function") | |
44 | + | let routingAddress = Address(getBase58FromOracle(kRoutingAddr)) | |
59 | 45 | ||
60 | - | ||
61 | - | @Callable(i) | |
62 | - | func setAdmin (adminId,adminPubKey) = valueOrElse(isSelfCall(i), if (if ((0 > adminId)) | |
63 | - | then (adminId > 3) | |
64 | - | else false) | |
65 | - | then throw("Wrong admin id") | |
66 | - | else [StringEntry((kAdminPubKey + toString(adminId)), adminPubKey)]) | |
67 | - | ||
68 | - | ||
69 | - | ||
70 | - | @Callable(i) | |
71 | - | func addPool (poolAddress,poolName) = valueOrElse(isAdminCall(i), { | |
72 | - | let validatedAddress = getAddressIfValid(poolAddress) | |
73 | - | let keyName = (kPrefixPoolName + validatedAddress) | |
74 | - | let possiblyAlreadyAddedPool = getString(this, keyName) | |
75 | - | if (isDefined(possiblyAlreadyAddedPool)) | |
76 | - | then throw((((("Pool with address \"" + validatedAddress) + "\" is already defined with name \"") + value(possiblyAlreadyAddedPool)) + "\"")) | |
77 | - | else ([StringEntry(keyName, poolName)] ++ (if ((getPoolType(value(addressFromString(poolAddress))) == "multycurve")) | |
78 | - | then nil | |
79 | - | else { | |
80 | - | let assetIdA = valueOrErrorMessage(getString(value(addressFromString(poolAddress)), kAssetIdA), "Asset id A is incorrect") | |
81 | - | let assetIdB = valueOrErrorMessage(getString(value(addressFromString(poolAddress)), kAssetIdB), "Asset id B is incorrect") | |
82 | - | [StringEntry((((kPair + assetIdA) + "_") + assetIdB), poolAddress)] | |
83 | - | })) | |
84 | - | }) | |
85 | - | ||
86 | - | ||
87 | - | ||
88 | - | @Callable(i) | |
89 | - | func launchpadDataTransactionStatus (status) = valueOrElse(isAdminCall(i), [BooleanEntry(kLaunchpadDataTransactionStatus, status)]) | |
90 | - | ||
91 | - | ||
92 | - | ||
93 | - | @Callable(i) | |
94 | - | func addAchievementsWriter (address) = valueOrElse(isAdminCall(i), { | |
95 | - | let writers = valueOrElse(getString(this, kAchievementsWriters), "") | |
96 | - | let data = if ((writers == "")) | |
97 | - | then nil | |
98 | - | else split(writers, ",") | |
99 | - | [StringEntry(kAchievementsWriters, makeString((data :+ address), ","))] | |
100 | - | }) | |
101 | - | ||
102 | - | ||
103 | - | ||
104 | - | @Callable(i) | |
105 | - | func removeAchievementsWriter (address) = valueOrElse(isAdminCall(i), { | |
106 | - | let writers = split(valueOrElse(getString(this, kAchievementsWriters), ""), ",") | |
107 | - | let index = valueOrErrorMessage(indexOf(writers, address), "Can't find address in the list") | |
108 | - | [StringEntry(kAchievementsWriters, makeString(removeByIndex(writers, index), ","))] | |
109 | - | }) | |
110 | - | ||
111 | - | ||
112 | - | ||
113 | - | @Callable(i) | |
114 | - | func shutdownAllContracts () = valueOrElse(isAdminCall(i), if (!(activeAllContracts)) | |
115 | - | then throw("All contracts already shutdown") | |
116 | - | else [BooleanEntry(kActiveAllContracts, false)]) | |
117 | - | ||
118 | - | ||
119 | - | ||
120 | - | @Callable(i) | |
121 | - | func activateAllContracts () = valueOrElse(isAdminCall(i), if (activeAllContracts) | |
122 | - | then throw("All contracts already active") | |
123 | - | else [BooleanEntry(kActiveAllContracts, true)]) | |
46 | + | let keyPrefixPoolName = "pool_" | |
124 | 47 | ||
125 | 48 | ||
126 | 49 | @Verifier(tx) | |
127 | - | func verify () = { | |
128 | - | let adminPubKey1Signed = if (sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey1)) | |
129 | - | then 1 | |
130 | - | else 0 | |
131 | - | let adminPubKey2Signed = if (sigVerify(tx.bodyBytes, tx.proofs[1], adminPubKey2)) | |
132 | - | then 1 | |
133 | - | else 0 | |
134 | - | let adminPubKey3Signed = if (sigVerify(tx.bodyBytes, tx.proofs[2], adminPubKey3)) | |
135 | - | then 1 | |
136 | - | else 0 | |
137 | - | (((adminPubKey1Signed + adminPubKey2Signed) + adminPubKey3Signed) >= 2) | |
138 | - | } | |
50 | + | func verify () = match tx { | |
51 | + | case inv: InvokeScriptTransaction => | |
52 | + | let isRoutingCall = if ((inv.dApp == routingAddress)) | |
53 | + | then (inv.function == "routingTrade") | |
54 | + | else false | |
55 | + | let isExchangeCallCPMM = if (if (isDefined(getString(oracle, (keyPrefixPoolName + toString(addressFromRecipient(inv.dApp)))))) | |
56 | + | then (inv.function == "callFunction") | |
57 | + | else false) | |
58 | + | then (inv.args[0] == "exchange") | |
59 | + | else false | |
60 | + | let isExchangeCall = if (isDefined(getString(oracle, (keyPrefixPoolName + toString(addressFromRecipient(inv.dApp)))))) | |
61 | + | then (inv.function == "exchange") | |
62 | + | else false | |
63 | + | let isAirdropCall = if ((inv.dApp == governanceAddress)) | |
64 | + | then (inv.function == "airDrop") | |
65 | + | else false | |
66 | + | let isUpdateWeightsCall = if ((inv.dApp == governanceAddress)) | |
67 | + | then (inv.function == "updateWeights") | |
68 | + | else false | |
69 | + | let isUpdatePoolInterest = if ((inv.dApp == farmingAddress)) | |
70 | + | then (inv.function == "updatePoolInterest") | |
71 | + | else false | |
72 | + | let isTakenIntoAccountCPMM = if (if (isDefined(getString(oracle, (keyPrefixPoolName + toString(addressFromRecipient(inv.dApp)))))) | |
73 | + | then (inv.function == "callFunction") | |
74 | + | else false) | |
75 | + | then (inv.args[0] == "takeIntoAccountExtraFunds") | |
76 | + | else false | |
77 | + | let isTakenIntoAccount = if (isDefined(getString(oracle, (keyPrefixPoolName + toString(addressFromRecipient(inv.dApp)))))) | |
78 | + | then (inv.function == "takeIntoAccountExtraFunds") | |
79 | + | else false | |
80 | + | let isWriteTotal = if ((inv.dApp == surveysAddress)) | |
81 | + | then (inv.function == "writeTotals") | |
82 | + | else false | |
83 | + | let signedByAdmin = sigVerify(tx.bodyBytes, tx.proofs[0], adminInvoke) | |
84 | + | if (if (if (if (if (if (isExchangeCall) | |
85 | + | then true | |
86 | + | else isExchangeCallCPMM) | |
87 | + | then true | |
88 | + | else isAirdropCall) | |
89 | + | then true | |
90 | + | else isRoutingCall) | |
91 | + | then (size(inv.payments) == 1) | |
92 | + | else false) | |
93 | + | then true | |
94 | + | else if (if (if (if (if (isUpdateWeightsCall) | |
95 | + | then true | |
96 | + | else isUpdatePoolInterest) | |
97 | + | then true | |
98 | + | else isTakenIntoAccount) | |
99 | + | then true | |
100 | + | else isTakenIntoAccountCPMM) | |
101 | + | then true | |
102 | + | else isWriteTotal) | |
103 | + | then (size(inv.payments) == 0) | |
104 | + | else false) | |
105 | + | then signedByAdmin | |
106 | + | else false | |
107 | + | case _ => | |
108 | + | let adminPubKey1Signed = if (sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey1)) | |
109 | + | then 1 | |
110 | + | else 0 | |
111 | + | let adminPubKey2Signed = if (sigVerify(tx.bodyBytes, tx.proofs[1], adminPubKey2)) | |
112 | + | then 1 | |
113 | + | else 0 | |
114 | + | let adminPubKey3Signed = if (sigVerify(tx.bodyBytes, tx.proofs[2], adminPubKey3)) | |
115 | + | then 1 | |
116 | + | else 0 | |
117 | + | (((adminPubKey1Signed + adminPubKey2Signed) + adminPubKey3Signed) >= 2) | |
118 | + | } | |
139 | 119 |
github/deemru/w8io/169f3d6 31.91 ms ◑