1 | | - | {-# STDLIB_VERSION 5 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let dAppAddress = Address(base58'3PPNhHYkkEy13gRWDCaruQyhNbX2GrjYSyV') |
---|
5 | | - | |
---|
6 | | - | let wxAssetId = base58'Atqv59EYzjFGuitKVnMRk6H8FukjoV3ktPorbEys25on' |
---|
7 | | - | |
---|
8 | | - | let wxbAssetId = base58'BbP9tmd5Zxk345y9zipXkYaqDfxDG1suTj64eJmy1BAT' |
---|
9 | | - | |
---|
10 | | - | let giveawayAssetId = base58'Atqv59EYzjFGuitKVnMRk6H8FukjoV3ktPorbEys25on' |
---|
11 | | - | |
---|
12 | | - | let wxLockAddress = Address(base58'3PJL8Hn8LACaSBWLQ3UVhctA5cTQLBFwBAP') |
---|
13 | | - | |
---|
14 | | - | @Callable(i) |
---|
15 | | - | func stakeLP () = { |
---|
16 | | - | let callerAddressString = toString(i.caller) |
---|
17 | | - | let isWhitelisted = valueOrElse(getBoolean((callerAddressString + "_whitelisted")), false) |
---|
18 | | - | let lpAssetId = valueOrElse(getString((callerAddressString + "_assetId")), "") |
---|
19 | | - | if (if (if (if (isWhitelisted) |
---|
20 | | - | then (size(i.payments) == 1) |
---|
21 | | - | else false) |
---|
22 | | - | then (i.payments[0].amount > 0) |
---|
23 | | - | else false) |
---|
24 | | - | then (i.payments[0].assetId == fromBase58String(lpAssetId)) |
---|
25 | | - | else false) |
---|
26 | | - | then { |
---|
27 | | - | let stakeLPCall = invoke(dAppAddress, "stake", nil, [AttachedPayment(i.payments[0].assetId, i.payments[0].amount)]) |
---|
28 | | - | if ((stakeLPCall == stakeLPCall)) |
---|
29 | | - | then { |
---|
30 | | - | let balance = (valueOrElse(getInteger((((callerAddressString + "_") + lpAssetId) + "_balance")), 0) + i.payments[0].amount) |
---|
31 | | - | $Tuple2([IntegerEntry((((callerAddressString + "_") + lpAssetId) + "_balance"), balance)], unit) |
---|
32 | | - | } |
---|
33 | | - | else throw("Strict value is not equal to itself.") |
---|
34 | | - | } |
---|
35 | | - | else throw("") |
---|
36 | | - | } |
---|
37 | | - | |
---|
38 | | - | |
---|
39 | | - | |
---|
40 | | - | @Callable(i) |
---|
41 | | - | func unstakeLP (amount) = { |
---|
42 | | - | let callerAddressString = toString(i.caller) |
---|
43 | | - | let isWhitelisted = valueOrElse(getBoolean((callerAddressString + "_whitelisted")), false) |
---|
44 | | - | if (isWhitelisted) |
---|
45 | | - | then { |
---|
46 | | - | let lpAssetId = valueOrElse(getString((callerAddressString + "_assetId")), "") |
---|
47 | | - | let unstakeLPCall = invoke(dAppAddress, "unstake", [lpAssetId, amount], nil) |
---|
48 | | - | if ((unstakeLPCall == unstakeLPCall)) |
---|
49 | | - | then { |
---|
50 | | - | let balance = (valueOrElse(getInteger((((callerAddressString + "_") + lpAssetId) + "_balance")), 0) - amount) |
---|
51 | | - | $Tuple2([ScriptTransfer(i.caller, amount, fromBase58String(lpAssetId)), IntegerEntry((((callerAddressString + "_") + lpAssetId) + "_balance"), balance)], unit) |
---|
52 | | - | } |
---|
53 | | - | else throw("Strict value is not equal to itself.") |
---|
54 | | - | } |
---|
55 | | - | else throw("") |
---|
56 | | - | } |
---|
57 | | - | |
---|
58 | | - | |
---|
59 | | - | |
---|
60 | | - | @Callable(i) |
---|
61 | | - | func claim () = { |
---|
62 | | - | let callerAddressString = toString(i.caller) |
---|
63 | | - | let isWhitelisted = valueOrElse(getBoolean((callerAddressString + "_whitelisted")), false) |
---|
64 | | - | if (isWhitelisted) |
---|
65 | | - | then { |
---|
66 | | - | let lpAssetId = valueOrElse(getString((callerAddressString + "_assetId")), "") |
---|
67 | | - | let wxBalance = assetBalance(this, wxAssetId) |
---|
68 | | - | if ((wxBalance == wxBalance)) |
---|
69 | | - | then { |
---|
70 | | - | let claimWXCall = invoke(dAppAddress, "claimWx", [lpAssetId], nil) |
---|
71 | | - | if ((claimWXCall == claimWXCall)) |
---|
72 | | - | then { |
---|
73 | | - | let claimedWXAmount = (assetBalance(this, wxAssetId) - wxBalance) |
---|
74 | | - | if ((claimedWXAmount == claimedWXAmount)) |
---|
75 | | - | then { |
---|
76 | | - | let totalClaimedWXPool = (valueOrElse(getInteger((((callerAddressString + "_") + lpAssetId) + "_total_claimed_wx")), 0) + claimedWXAmount) |
---|
77 | | - | let totalClaimedWX = (valueOrElse(getInteger(this, "total_claimed_wx"), 0) + claimedWXAmount) |
---|
78 | | - | let feeRate = getIntegerValue(this, "fee") |
---|
79 | | - | let fee = fraction(claimedWXAmount, feeRate, 100) |
---|
80 | | - | let totalCollectedFeePool = (valueOrElse(getInteger((((callerAddressString + "_") + lpAssetId) + "_total_collected_fee")), 0) + fee) |
---|
81 | | - | let totalCollectedFee = (valueOrElse(getInteger("total_collected_fee"), 0) + fee) |
---|
82 | | - | let wxLockCall = invoke(wxLockAddress, "increaseLock", [0], [AttachedPayment(wxAssetId, fee)]) |
---|
83 | | - | if ((wxLockCall == wxLockCall)) |
---|
84 | | - | then { |
---|
85 | | - | let totalLockedWX = (valueOrElse(getInteger("total_locked_wx"), 0) + fee) |
---|
86 | | - | let wxbAllocation = valueOrElse(getInteger((((callerAddressString + "_") + lpAssetId) + "_wxb_allocation")), 0) |
---|
87 | | - | let totalClaimedWXBPool = (valueOrElse(getInteger((((callerAddressString + "_") + lpAssetId) + "_total_claimed_wxb")), 0) + wxbAllocation) |
---|
88 | | - | let totalClaimedWXB = (valueOrElse(getInteger("total_claimed_wxb"), 0) + wxbAllocation) |
---|
89 | | - | $Tuple2([ScriptTransfer(i.caller, (claimedWXAmount - fee), wxAssetId), ScriptTransfer(i.caller, wxbAllocation, wxbAssetId), IntegerEntry("total_locked_wx", totalLockedWX), IntegerEntry((((callerAddressString + "_") + lpAssetId) + "_total_claimed_wx"), totalClaimedWXPool), IntegerEntry("total_claimed_wx", totalClaimedWX), IntegerEntry((((callerAddressString + "_") + lpAssetId) + "_total_claimed_wxb"), totalClaimedWXBPool), IntegerEntry("total_claimed_wxb", totalClaimedWXB), IntegerEntry((((callerAddressString + "_") + lpAssetId) + "_total_collected_fee"), totalCollectedFeePool), IntegerEntry("total_collected_fee", totalCollectedFee)], unit) |
---|
90 | | - | } |
---|
91 | | - | else throw("Strict value is not equal to itself.") |
---|
92 | | - | } |
---|
93 | | - | else throw("Strict value is not equal to itself.") |
---|
94 | | - | } |
---|
95 | | - | else throw("Strict value is not equal to itself.") |
---|
96 | | - | } |
---|
97 | | - | else throw("Strict value is not equal to itself.") |
---|
98 | | - | } |
---|
99 | | - | else throw("") |
---|
100 | | - | } |
---|
101 | | - | |
---|
102 | | - | |
---|
103 | | - | |
---|
104 | | - | @Callable(i) |
---|
105 | | - | func init () = { |
---|
106 | | - | let initialized = valueOrElse(getBoolean("initialized"), false) |
---|
107 | | - | if (!(initialized)) |
---|
108 | | - | then { |
---|
109 | | - | let firstLock = invoke(wxLockAddress, "lock", [2102400], [AttachedPayment(i.payments[0].assetId, i.payments[0].amount)]) |
---|
110 | | - | if ((firstLock == firstLock)) |
---|
111 | | - | then $Tuple2([BooleanEntry("initialized", true), IntegerEntry("it_all_started_in_this_block", height), IntegerEntry("total_locked_wx", i.payments[0].amount), IntegerEntry("lock_duration", (2102400 + height)), IntegerEntry("fee", 10)], unit) |
---|
112 | | - | else throw("Strict value is not equal to itself.") |
---|
113 | | - | } |
---|
114 | | - | else throw("") |
---|
115 | | - | } |
---|
116 | | - | |
---|
117 | | - | |
---|
118 | | - | |
---|
119 | | - | @Callable(i) |
---|
120 | | - | func setFee (fee) = if ((i.caller == this)) |
---|
121 | | - | then $Tuple2([IntegerEntry("fee", fee)], unit) |
---|
122 | | - | else throw("") |
---|
123 | | - | |
---|
124 | | - | |
---|
125 | | - | |
---|
126 | | - | @Callable(i) |
---|
127 | | - | func whitelist (whitelistAddress,assetId,allocation) = if ((i.caller == this)) |
---|
128 | | - | then $Tuple2([BooleanEntry((whitelistAddress + "_whitelisted"), true), StringEntry((whitelistAddress + "_assetId"), assetId), IntegerEntry((((whitelistAddress + "_") + assetId) + "_wxb_allocation"), allocation)], unit) |
---|
129 | | - | else throw("") |
---|
130 | | - | |
---|
131 | | - | |
---|
132 | | - | |
---|
133 | | - | @Callable(i) |
---|
134 | | - | func removeWhitelist (whitelistAddress) = if ((i.caller == this)) |
---|
135 | | - | then $Tuple2([BooleanEntry((whitelistAddress + "_whitelisted"), false)], unit) |
---|
136 | | - | else throw("") |
---|
137 | | - | |
---|
138 | | - | |
---|
139 | | - | |
---|
140 | | - | @Callable(i) |
---|
141 | | - | func setAllocation (amount,whitelistAddress,assetId) = if ((i.caller == this)) |
---|
142 | | - | then [IntegerEntry((((whitelistAddress + "_") + assetId) + "_wxb_allocation"), amount)] |
---|
143 | | - | else throw("") |
---|
144 | | - | |
---|
145 | | - | |
---|
146 | | - | |
---|
147 | | - | @Callable(i) |
---|
148 | | - | func giveaway () = { |
---|
149 | | - | let callerAddressString = toString(i.caller) |
---|
150 | | - | let isWhitelisted = valueOrElse(getBoolean((callerAddressString + "_whitelisted")), false) |
---|
151 | | - | if (if (if (if (isWhitelisted) |
---|
152 | | - | then (size(i.payments) == 1) |
---|
153 | | - | else false) |
---|
154 | | - | then (i.payments[0].assetId == giveawayAssetId) |
---|
155 | | - | else false) |
---|
156 | | - | then (i.payments[0].amount > 0) |
---|
157 | | - | else false) |
---|
158 | | - | then { |
---|
159 | | - | let wxLockCall = invoke(wxLockAddress, "increaseLock", [0], [AttachedPayment(i.payments[0].assetId, i.payments[0].amount)]) |
---|
160 | | - | if ((wxLockCall == wxLockCall)) |
---|
161 | | - | then { |
---|
162 | | - | let totalLockedWX = (valueOrElse(getInteger("total_locked_wx"), 0) + i.payments[0].amount) |
---|
163 | | - | let totalGiveawayWX = (valueOrElse(getInteger("total_giveaway_wx"), 0) + i.payments[0].amount) |
---|
164 | | - | $Tuple2([IntegerEntry("total_locked_wx", totalLockedWX), IntegerEntry("total_giveaway_wx", totalGiveawayWX)], unit) |
---|
165 | | - | } |
---|
166 | | - | else throw("Strict value is not equal to itself.") |
---|
167 | | - | } |
---|
168 | | - | else throw("") |
---|
169 | | - | } |
---|
170 | | - | |
---|
171 | | - | |
---|
172 | | - | |
---|
173 | | - | @Callable(i) |
---|
174 | | - | func increaseLockDuration (duration) = if ((i.caller == this)) |
---|
175 | | - | then { |
---|
176 | | - | let increaseLockDurationCall = invoke(wxLockAddress, "increaseLock", [duration], nil) |
---|
177 | | - | if ((increaseLockDurationCall == increaseLockDurationCall)) |
---|
178 | | - | then { |
---|
179 | | - | let lockDuration = (getIntegerValue("lock_duration") + duration) |
---|
180 | | - | $Tuple2([IntegerEntry("lock_duration", lockDuration)], unit) |
---|
181 | | - | } |
---|
182 | | - | else throw("Strict value is not equal to itself.") |
---|
183 | | - | } |
---|
184 | | - | else throw("") |
---|
185 | | - | |
---|
186 | | - | |
---|
187 | | - | @Verifier(tx) |
---|
188 | | - | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|
189 | | - | |
---|
| 1 | + | # no script |
---|