tx · 3h61i52da33peAjoDhbkS8BsCcWZQPe9du5hU69rqSKu 3MvkaAmaBu7ngK68fQMV8faYLdcnnBJtrj5: -0.01400000 Waves 2021.12.14 18:07 [1834085] smart account 3MvkaAmaBu7ngK68fQMV8faYLdcnnBJtrj5 > SELF 0.00000000 Waves
{ "type": 13, "id": "3h61i52da33peAjoDhbkS8BsCcWZQPe9du5hU69rqSKu", "fee": 1400000, "feeAssetId": null, "timestamp": 1639494503894, "version": 1, "sender": "3MvkaAmaBu7ngK68fQMV8faYLdcnnBJtrj5", "senderPublicKey": "hXnMcUKtqomxgSbnHn7eToAsYJGaa1PWq7Lq6QQLumm", "proofs": [ "2LPtmVRgQuUs4cygaYM6e46yvC6dKsWtteSUhHX3Brsn2U7HHbYgVLT349De9GdEaUkzhUfTjExoZFfGCCNddJnx" ], "script": "base64:AAIFAAAAAAAAABoIAhIDCgEIEgASBAoCCAESAwoBCBIECgIICAAAAAwAAAAAA1NFUAIAAAACX18BAAAAD2dldFN0cmluZ09yRmFpbAAAAAEAAAADa2V5CQEAAAATdmFsdWVPckVycm9yTWVzc2FnZQAAAAIJAAQiAAAAAQUAAAADa2V5CQABLAAAAAIJAAEsAAAAAgIAAAAPbWFuZGF0b3J5IHRoaXMuBQAAAANrZXkCAAAADyBpcyBub3QgZGVmaW5lZAEAAAAYZ2V0U3RyaW5nQnlBZGRyZXNzT3JGYWlsAAAAAgAAAAdhZGRyZXNzAAAAA2tleQkBAAAAE3ZhbHVlT3JFcnJvck1lc3NhZ2UAAAACCQAEHQAAAAIFAAAAB2FkZHJlc3MFAAAAA2tleQkAASwAAAACCQABLAAAAAIJAAEsAAAAAgkAASwAAAACAgAAAAptYW5kYXRvcnkgCQAEJQAAAAEFAAAAB2FkZHJlc3MCAAAAAS4FAAAAA2tleQIAAAAPIGlzIG5vdCBkZWZpbmVkAQAAABFrZXlGYWN0b3J5QWRkcmVzcwAAAAACAAAAHCVzJXNfX2NvbmZpZ19fZmFjdG9yeUFkZHJlc3M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AAAgkABEwAAAACAgAAAAYlcyVzJWQJAARMAAAAAgUAAAAMbHBBc3NldElkU3RyCQAETAAAAAIFAAAAC3VzZXJBZGRyZXNzCQAETAAAAAICAAAAATAFAAAAA25pbAUAAAADU0VQAAAAADz8MV0=", "chainId": 84, "height": 1834085, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 6pEJp49btvb7sddDa9SwvejMnwHYfqh8uFfsUTQ1P67W Next: 3FeqZfcBUkgvS4hWunrgSPa5komepakdZsdsYAiZkQe2 Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let SCALE8 = 8 | |
5 | - | ||
6 | - | let MULT8 = 100000000 | |
7 | - | ||
8 | - | let SCALE18 = 18 | |
9 | - | ||
10 | - | let MULT18 = toBigInt(1000000000000000000) | |
11 | - | ||
12 | 4 | let SEP = "__" | |
13 | 5 | ||
14 | 6 | func getStringOrFail (key) = valueOrErrorMessage(getString(key), (("mandatory this." + key) + " is not defined")) | |
17 | 9 | func getStringByAddressOrFail (address,key) = valueOrErrorMessage(getString(address, key), (((("mandatory " + toString(address)) + ".") + key) + " is not defined")) | |
18 | 10 | ||
19 | 11 | ||
20 | - | func getIntOrZero (address,key) = valueOrElse(getInteger(address, key), 0) | |
21 | - | ||
22 | - | ||
23 | - | func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), (("mandatory this." + key) + " is not defined")) | |
24 | - | ||
25 | - | ||
26 | 12 | func keyFactoryAddress () = "%s%s__config__factoryAddress" | |
27 | - | ||
28 | - | ||
29 | - | let IdxFactoryCfgStakingDapp = 1 | |
30 | - | ||
31 | - | let IdxFactoryCfgBoostingDapp = 2 | |
32 | - | ||
33 | - | let IdxFactoryCfgIdoDapp = 3 | |
34 | - | ||
35 | - | let IdxFactoryCfgTeamDapp = 4 | |
36 | - | ||
37 | - | let IdxFactoryCfgEmissionDapp = 5 | |
38 | - | ||
39 | - | let IdxFactoryCfgRestDapp = 6 | |
40 | - | ||
41 | - | let IdxFactoryCfgSlippageDapp = 7 | |
42 | - | ||
43 | - | func keyFactoryCfg () = "%s__factoryConfig" | |
44 | 13 | ||
45 | 14 | ||
46 | 15 | func keyFactoryLp2AssetsMapping (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP) | |
47 | 16 | ||
48 | 17 | ||
49 | - | func keyFactoryLpList () = "%s__lpTokensList" | |
50 | - | ||
51 | - | ||
52 | - | func keyFactoryLpAssetToPoolContractAddress (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP) | |
53 | - | ||
54 | - | ||
55 | - | func keyFactoryPoolWeight (contractAddress) = makeString(["%s%s", "poolWeight", contractAddress], SEP) | |
56 | - | ||
57 | - | ||
58 | 18 | func readFactoryAddressOrFail () = addressFromStringValue(getStringOrFail(keyFactoryAddress())) | |
59 | - | ||
60 | - | ||
61 | - | func readLpList () = split(valueOrElse(getString(readFactoryAddressOrFail(), keyFactoryLpList()), ""), SEP) | |
62 | - | ||
63 | - | ||
64 | - | func readFactoryCfgOrFail (factory) = split(getStringByAddressOrFail(factory, keyFactoryCfg()), SEP) | |
65 | - | ||
66 | - | ||
67 | - | func getBoostingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgBoostingDapp]) | |
68 | - | ||
69 | - | ||
70 | - | func getEmissionAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgEmissionDapp]) | |
71 | - | ||
72 | - | ||
73 | - | func getStakingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgStakingDapp]) | |
74 | - | ||
75 | - | ||
76 | - | func keyEmissionRatePerBlockCurrent () = "%s%s__ratePerBlock__current" | |
77 | - | ||
78 | - | ||
79 | - | func keyEmissionRatePerBlockMaxCurrent () = "%s%s__ratePerBlockMax__current" | |
80 | - | ||
81 | - | ||
82 | - | func keyEmissionStartBlock () = "%s%s__emission__startBlock" | |
83 | - | ||
84 | - | ||
85 | - | func keyEmissionDurationInBlocks () = "%s%s__emission__duration" | |
86 | - | ||
87 | - | ||
88 | - | func keyEmissionEndBlock () = "%s%s__emission__endBlock" | |
89 | 19 | ||
90 | 20 | ||
91 | 21 | func keyStakedByUser (userAddressStr,lpAssetIdStr) = makeString(["%s%s%s__staked", userAddressStr, lpAssetIdStr], SEP) | |
141 | 71 | @Callable(i) | |
142 | 72 | func unstake (lpAssetIdStr,amount) = { | |
143 | 73 | let factory = readFactoryAddressOrFail() | |
144 | - | let userAddressStr = toString(i.caller) | |
145 | 74 | let lpAssetId = fromBase58String(lpAssetIdStr) | |
146 | - | if (!(isDefined(getString(factory, keyFactoryLp2AssetsMapping(lpAssetIdStr))))) | |
147 | - | then throw(("unsupported lp asset " + lpAssetIdStr)) | |
148 | - | else { | |
149 | - | let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr) | |
150 | - | let stakedTotalKEY = keyStakedTotal(lpAssetIdStr) | |
151 | - | let stakedByUser = readStaked(stakedByUserKEY) | |
152 | - | let stakedTotal = readStaked(stakedTotalKEY) | |
153 | - | if ((amount > stakedByUser)) | |
154 | - | then throw("passed amount is less then available") | |
155 | - | else [IntegerEntry(stakedByUserKEY, (stakedByUser - amount)), IntegerEntry(stakedTotalKEY, (stakedTotal - amount)), ScriptTransfer(i.caller, amount, lpAssetId), OperationHistoryEntry("unstake", userAddressStr, lpAssetIdStr, amount, i.transactionId)] | |
156 | - | } | |
75 | + | let lpDappStr = valueOrErrorMessage(getString(factory, keyFactoryLp2AssetsMapping(lpAssetIdStr)), ("unsupported lp asset " + lpAssetIdStr)) | |
76 | + | let callerStr = toString(i.caller) | |
77 | + | let userAddressStr = if ((callerStr == lpDappStr)) | |
78 | + | then toString(i.originCaller) | |
79 | + | else callerStr | |
80 | + | let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr) | |
81 | + | let stakedTotalKEY = keyStakedTotal(lpAssetIdStr) | |
82 | + | let stakedByUser = readStaked(stakedByUserKEY) | |
83 | + | let stakedTotal = readStaked(stakedTotalKEY) | |
84 | + | if ((amount > stakedByUser)) | |
85 | + | then throw("passed amount is less then available") | |
86 | + | else [IntegerEntry(stakedByUserKEY, (stakedByUser - amount)), IntegerEntry(stakedTotalKEY, (stakedTotal - amount)), ScriptTransfer(i.caller, amount, lpAssetId), OperationHistoryEntry("unstake", userAddressStr, lpAssetIdStr, amount, i.transactionId)] | |
157 | 87 | } | |
158 | 88 | ||
159 | 89 | ||
164 | 94 | ||
165 | 95 | ||
166 | 96 | @Callable(i) | |
167 | - | func claimWxREADONLY (lpAssetIdStr,userAddress) = { | |
168 | - | let factoryContract = readFactoryAddressOrFail() | |
169 | - | let factoryCfg = readFactoryCfgOrFail(factoryContract) | |
170 | - | let emissionContract = getEmissionAddressOrFail(factoryCfg) | |
171 | - | let stakedByUserKEY = keyStakedByUser(userAddress, lpAssetIdStr) | |
172 | - | let stakedTotalKEY = keyStakedTotal(lpAssetIdStr) | |
173 | - | let stakedByUser = readStaked(stakedByUserKEY) | |
174 | - | let stakedTotal = readStaked(stakedTotalKEY) | |
175 | - | let poolAddressStr = getStringByAddressOrFail(factoryContract, keyFactoryLpAssetToPoolContractAddress(lpAssetIdStr)) | |
176 | - | let poolWeightMult = MULT8 | |
177 | - | let poolWeight = getIntegerValue(factoryContract, keyFactoryPoolWeight(poolAddressStr)) | |
178 | - | let wxEmissionPerBlock = getIntOrFail(emissionContract, keyEmissionRatePerBlockCurrent()) | |
179 | - | let emissionStartBlock = getIntOrFail(emissionContract, keyEmissionStartBlock()) | |
180 | - | let passedBlocks = if ((emissionStartBlock > height)) | |
181 | - | then 0 | |
182 | - | else (height - emissionStartBlock) | |
183 | - | let poolWxEmission = fraction((wxEmissionPerBlock * passedBlocks), poolWeight, poolWeightMult) | |
184 | - | let userWxReward = fraction(poolWxEmission, stakedByUser, stakedTotal) | |
185 | - | $Tuple2(nil, makeString(["%s%s%d", lpAssetIdStr, userAddress, toString(userWxReward)], SEP)) | |
186 | - | } | |
97 | + | func claimWxREADONLY (lpAssetIdStr,userAddress) = $Tuple2(nil, makeString(["%s%s%d", lpAssetIdStr, userAddress, "0"], SEP)) | |
187 | 98 | ||
188 | 99 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let SCALE8 = 8 | |
5 | - | ||
6 | - | let MULT8 = 100000000 | |
7 | - | ||
8 | - | let SCALE18 = 18 | |
9 | - | ||
10 | - | let MULT18 = toBigInt(1000000000000000000) | |
11 | - | ||
12 | 4 | let SEP = "__" | |
13 | 5 | ||
14 | 6 | func getStringOrFail (key) = valueOrErrorMessage(getString(key), (("mandatory this." + key) + " is not defined")) | |
15 | 7 | ||
16 | 8 | ||
17 | 9 | func getStringByAddressOrFail (address,key) = valueOrErrorMessage(getString(address, key), (((("mandatory " + toString(address)) + ".") + key) + " is not defined")) | |
18 | 10 | ||
19 | 11 | ||
20 | - | func getIntOrZero (address,key) = valueOrElse(getInteger(address, key), 0) | |
21 | - | ||
22 | - | ||
23 | - | func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), (("mandatory this." + key) + " is not defined")) | |
24 | - | ||
25 | - | ||
26 | 12 | func keyFactoryAddress () = "%s%s__config__factoryAddress" | |
27 | - | ||
28 | - | ||
29 | - | let IdxFactoryCfgStakingDapp = 1 | |
30 | - | ||
31 | - | let IdxFactoryCfgBoostingDapp = 2 | |
32 | - | ||
33 | - | let IdxFactoryCfgIdoDapp = 3 | |
34 | - | ||
35 | - | let IdxFactoryCfgTeamDapp = 4 | |
36 | - | ||
37 | - | let IdxFactoryCfgEmissionDapp = 5 | |
38 | - | ||
39 | - | let IdxFactoryCfgRestDapp = 6 | |
40 | - | ||
41 | - | let IdxFactoryCfgSlippageDapp = 7 | |
42 | - | ||
43 | - | func keyFactoryCfg () = "%s__factoryConfig" | |
44 | 13 | ||
45 | 14 | ||
46 | 15 | func keyFactoryLp2AssetsMapping (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP) | |
47 | 16 | ||
48 | 17 | ||
49 | - | func keyFactoryLpList () = "%s__lpTokensList" | |
50 | - | ||
51 | - | ||
52 | - | func keyFactoryLpAssetToPoolContractAddress (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP) | |
53 | - | ||
54 | - | ||
55 | - | func keyFactoryPoolWeight (contractAddress) = makeString(["%s%s", "poolWeight", contractAddress], SEP) | |
56 | - | ||
57 | - | ||
58 | 18 | func readFactoryAddressOrFail () = addressFromStringValue(getStringOrFail(keyFactoryAddress())) | |
59 | - | ||
60 | - | ||
61 | - | func readLpList () = split(valueOrElse(getString(readFactoryAddressOrFail(), keyFactoryLpList()), ""), SEP) | |
62 | - | ||
63 | - | ||
64 | - | func readFactoryCfgOrFail (factory) = split(getStringByAddressOrFail(factory, keyFactoryCfg()), SEP) | |
65 | - | ||
66 | - | ||
67 | - | func getBoostingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgBoostingDapp]) | |
68 | - | ||
69 | - | ||
70 | - | func getEmissionAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgEmissionDapp]) | |
71 | - | ||
72 | - | ||
73 | - | func getStakingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgStakingDapp]) | |
74 | - | ||
75 | - | ||
76 | - | func keyEmissionRatePerBlockCurrent () = "%s%s__ratePerBlock__current" | |
77 | - | ||
78 | - | ||
79 | - | func keyEmissionRatePerBlockMaxCurrent () = "%s%s__ratePerBlockMax__current" | |
80 | - | ||
81 | - | ||
82 | - | func keyEmissionStartBlock () = "%s%s__emission__startBlock" | |
83 | - | ||
84 | - | ||
85 | - | func keyEmissionDurationInBlocks () = "%s%s__emission__duration" | |
86 | - | ||
87 | - | ||
88 | - | func keyEmissionEndBlock () = "%s%s__emission__endBlock" | |
89 | 19 | ||
90 | 20 | ||
91 | 21 | func keyStakedByUser (userAddressStr,lpAssetIdStr) = makeString(["%s%s%s__staked", userAddressStr, lpAssetIdStr], SEP) | |
92 | 22 | ||
93 | 23 | ||
94 | 24 | func keyStakedTotal (lpAssetIdStr) = ("%s%s%s__staked__total__" + lpAssetIdStr) | |
95 | 25 | ||
96 | 26 | ||
97 | 27 | func readStaked (key) = valueOrElse(getInteger(this, key), 0) | |
98 | 28 | ||
99 | 29 | ||
100 | 30 | func keyOperationHistoryRecord (type,userAddress,txId58) = makeString(["%s%s%s%s__history", type, userAddress, txId58], SEP) | |
101 | 31 | ||
102 | 32 | ||
103 | 33 | func formatHistoryRecord (userAddress,lpAssetId,type,amount) = makeString(["%s%s%s%d%d%d", userAddress, lpAssetId, type, toString(height), toString(lastBlock.timestamp), toString(amount)], SEP) | |
104 | 34 | ||
105 | 35 | ||
106 | 36 | func OperationHistoryEntry (type,userAddress,lpAssetId,amount,txId) = StringEntry(keyOperationHistoryRecord(type, userAddress, toBase58String(txId)), formatHistoryRecord(userAddress, lpAssetId, type, amount)) | |
107 | 37 | ||
108 | 38 | ||
109 | 39 | @Callable(i) | |
110 | 40 | func constructor (factoryAddressStr) = if ((i.caller != this)) | |
111 | 41 | then throw("not authorized") | |
112 | 42 | else [StringEntry(keyFactoryAddress(), factoryAddressStr)] | |
113 | 43 | ||
114 | 44 | ||
115 | 45 | ||
116 | 46 | @Callable(i) | |
117 | 47 | func stake () = { | |
118 | 48 | let factory = readFactoryAddressOrFail() | |
119 | 49 | if ((size(i.payments) != 1)) | |
120 | 50 | then throw("invalid payment - exact one payment must be attached") | |
121 | 51 | else { | |
122 | 52 | let pmt = i.payments[0] | |
123 | 53 | let lpAssetId = value(pmt.assetId) | |
124 | 54 | let lpAssetIdStr = toBase58String(lpAssetId) | |
125 | 55 | let amount = pmt.amount | |
126 | 56 | let lpDappStr = valueOrErrorMessage(getString(factory, keyFactoryLp2AssetsMapping(lpAssetIdStr)), ("unsupported lp asset " + lpAssetIdStr)) | |
127 | 57 | let callerStr = toString(i.caller) | |
128 | 58 | let userAddressStr = if ((callerStr == lpDappStr)) | |
129 | 59 | then toString(i.originCaller) | |
130 | 60 | else callerStr | |
131 | 61 | let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr) | |
132 | 62 | let stakedTotalKEY = keyStakedTotal(lpAssetIdStr) | |
133 | 63 | let stakedByUser = readStaked(stakedByUserKEY) | |
134 | 64 | let stakedTotal = readStaked(stakedTotalKEY) | |
135 | 65 | [IntegerEntry(stakedByUserKEY, (stakedByUser + amount)), IntegerEntry(stakedTotalKEY, (stakedTotal + amount)), OperationHistoryEntry("stake", userAddressStr, lpAssetIdStr, amount, i.transactionId)] | |
136 | 66 | } | |
137 | 67 | } | |
138 | 68 | ||
139 | 69 | ||
140 | 70 | ||
141 | 71 | @Callable(i) | |
142 | 72 | func unstake (lpAssetIdStr,amount) = { | |
143 | 73 | let factory = readFactoryAddressOrFail() | |
144 | - | let userAddressStr = toString(i.caller) | |
145 | 74 | let lpAssetId = fromBase58String(lpAssetIdStr) | |
146 | - | if (!(isDefined(getString(factory, keyFactoryLp2AssetsMapping(lpAssetIdStr))))) | |
147 | - | then throw(("unsupported lp asset " + lpAssetIdStr)) | |
148 | - | else { | |
149 | - | let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr) | |
150 | - | let stakedTotalKEY = keyStakedTotal(lpAssetIdStr) | |
151 | - | let stakedByUser = readStaked(stakedByUserKEY) | |
152 | - | let stakedTotal = readStaked(stakedTotalKEY) | |
153 | - | if ((amount > stakedByUser)) | |
154 | - | then throw("passed amount is less then available") | |
155 | - | else [IntegerEntry(stakedByUserKEY, (stakedByUser - amount)), IntegerEntry(stakedTotalKEY, (stakedTotal - amount)), ScriptTransfer(i.caller, amount, lpAssetId), OperationHistoryEntry("unstake", userAddressStr, lpAssetIdStr, amount, i.transactionId)] | |
156 | - | } | |
75 | + | let lpDappStr = valueOrErrorMessage(getString(factory, keyFactoryLp2AssetsMapping(lpAssetIdStr)), ("unsupported lp asset " + lpAssetIdStr)) | |
76 | + | let callerStr = toString(i.caller) | |
77 | + | let userAddressStr = if ((callerStr == lpDappStr)) | |
78 | + | then toString(i.originCaller) | |
79 | + | else callerStr | |
80 | + | let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr) | |
81 | + | let stakedTotalKEY = keyStakedTotal(lpAssetIdStr) | |
82 | + | let stakedByUser = readStaked(stakedByUserKEY) | |
83 | + | let stakedTotal = readStaked(stakedTotalKEY) | |
84 | + | if ((amount > stakedByUser)) | |
85 | + | then throw("passed amount is less then available") | |
86 | + | else [IntegerEntry(stakedByUserKEY, (stakedByUser - amount)), IntegerEntry(stakedTotalKEY, (stakedTotal - amount)), ScriptTransfer(i.caller, amount, lpAssetId), OperationHistoryEntry("unstake", userAddressStr, lpAssetIdStr, amount, i.transactionId)] | |
157 | 87 | } | |
158 | 88 | ||
159 | 89 | ||
160 | 90 | ||
161 | 91 | @Callable(i) | |
162 | 92 | func claimWx (lpAssetIdStr) = throw("temorary disabled") | |
163 | 93 | ||
164 | 94 | ||
165 | 95 | ||
166 | 96 | @Callable(i) | |
167 | - | func claimWxREADONLY (lpAssetIdStr,userAddress) = { | |
168 | - | let factoryContract = readFactoryAddressOrFail() | |
169 | - | let factoryCfg = readFactoryCfgOrFail(factoryContract) | |
170 | - | let emissionContract = getEmissionAddressOrFail(factoryCfg) | |
171 | - | let stakedByUserKEY = keyStakedByUser(userAddress, lpAssetIdStr) | |
172 | - | let stakedTotalKEY = keyStakedTotal(lpAssetIdStr) | |
173 | - | let stakedByUser = readStaked(stakedByUserKEY) | |
174 | - | let stakedTotal = readStaked(stakedTotalKEY) | |
175 | - | let poolAddressStr = getStringByAddressOrFail(factoryContract, keyFactoryLpAssetToPoolContractAddress(lpAssetIdStr)) | |
176 | - | let poolWeightMult = MULT8 | |
177 | - | let poolWeight = getIntegerValue(factoryContract, keyFactoryPoolWeight(poolAddressStr)) | |
178 | - | let wxEmissionPerBlock = getIntOrFail(emissionContract, keyEmissionRatePerBlockCurrent()) | |
179 | - | let emissionStartBlock = getIntOrFail(emissionContract, keyEmissionStartBlock()) | |
180 | - | let passedBlocks = if ((emissionStartBlock > height)) | |
181 | - | then 0 | |
182 | - | else (height - emissionStartBlock) | |
183 | - | let poolWxEmission = fraction((wxEmissionPerBlock * passedBlocks), poolWeight, poolWeightMult) | |
184 | - | let userWxReward = fraction(poolWxEmission, stakedByUser, stakedTotal) | |
185 | - | $Tuple2(nil, makeString(["%s%s%d", lpAssetIdStr, userAddress, toString(userWxReward)], SEP)) | |
186 | - | } | |
97 | + | func claimWxREADONLY (lpAssetIdStr,userAddress) = $Tuple2(nil, makeString(["%s%s%d", lpAssetIdStr, userAddress, "0"], SEP)) | |
187 | 98 | ||
188 | 99 |
github/deemru/w8io/fabc49c 42.58 ms ◑