-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdApp.ride
231 lines (196 loc) · 9.79 KB
/
dApp.ride
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
{-# STDLIB_VERSION 6 #-}
{-# CONTENT_TYPE DAPP #-}
{-# SCRIPT_TYPE ACCOUNT #-}
{-# IMPORT artifacts/mainnet.ride #-}
func tryGetInteger (address:Address, key:String)= match getInteger(address, key) {
case b: Int =>
b
case _ =>
0
}
func tryGetString (address:Address, key:String) = match getString(address, key) {
case b: String =>
b
case _ =>
""
}
let d6 = 1000000
let d8 = 100000000
let wxId = base58'Atqv59EYzjFGuitKVnMRk6H8FukjoV3ktPorbEys25on'
let xtnId = base58'DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p'
let unit0id = base58'GjwAHMjqWzYR4LgoNy91CxUKAGJN79h2hseZoae4nU8t'
let wavesdlpid = base58'HYogWffUjS8Uw4bYA1Dn3qrGmJerMqkf139aJcHhk8yq'
let invoker = Address(base58'3P1yEqCmumg3rJmuNA39HMav6UxknqtYkb9')
let swopWAVESxtn = Address(base58'3PHaNgomBkrvEL2QnuJarQVJa71wjw9qiqG')
let hWhirlpool = Address(base58'3PAkmJniMgnnAej5pYf2jFYkCbZow5pt9tr')
let unlockBlock = (30 * 1440)
let heirPubKey = base58'2kpmuzw1ZbrtgAN3BrR7vbEW1XrJoJKCstL7mf7XNf2P' # Ivash
let unlockBlock2 = (90 * 1440)
let PuzzleMasterPubKey = base58'4z8CKSYQBKkzx7PBb5uBP1YPa6YAHRNTApW1sQVHT5eU' # Vladimir and Ania Address: 3PLjwHcz9NEuaTo63NZR9B9okQiKQxZSbmf
let keyActivated = "Activated blockheight"
let keySurplusReceived = "surplus received in wavelets"
let keyWaveletsReceived = "total WAVES received in wavelets"
let keyWaveletsReceivedBT = "total wavelets received for base treasury"
let keyWaveletsPaidOut = "total WAVES paid out in wavelets"
let keyROI = "ROI basis points"
let kLeasingAmount = "leasing_amount"
let kLeasingId = "leasing_id"
let kDisable = "disabled"
let projectOwner = base58'3PEtLVxDT8mxAh1SDAn8m7JTGNkdpkaFxBk'
let whirlpoolPoolId = base58'3P2myTbd5zpEHcYmNpdWTp5gXS5B8tL1RCY'
let bbbPoolId = base58'3P9VPwVfNj3dDevQZt1Z951A4K57cmQmCgk'
let volatilePoolId = base58'3PDzArEBNXuTmczWH58mH5YMNkTVnYtNLXK'
let megaPoolId = base58'3PLWzzX6KeqnYZTXygzyCWZ8J48zsh8KLSW'
let eaglePoolId = base58'3PH6MrR3xUadhRv3pr8VcWVotviVH9BjkTv'
let burnxtnWhirlPoolId = base58'3P48ZN6yghcoQaHPtLM9V2hFc5cd4ARd1hc'
let poolboostSC = base58'3P8eeDzUnoDNbQjW617pAe76cEUDQsP1m1V'
let rewardsAddress = Address(base58'3P6H24XKLyRX8RKwyA5ARsChE6WhjDcVBiZ')
#let whirlpool = base58'fHJWWsh2hZAc4Atv8VRhKy3jNbHLeMwQMsLpdaBY51Y' # = test token
let whirlpool = base58'73tY3E6Gd5AWYmsuq8m8Kek7KnJNAYyS3GoveTbc6jCi' # = orginal token
let whirlpoolString = toBase58String(base58'73tY3E6Gd5AWYmsuq8m8Kek7KnJNAYyS3GoveTbc6jCi')
let waves = base58'WAVES'
func tokensInPool(poolId:ByteVector, assetStr:String)=
{
tryGetInteger(Address(poolId), ("global_" + assetStr) + "_balance")
}
# LP Whirlpool AMM
let wavesInWhirlpool = tokensInPool(whirlpoolPoolId, toBase58String(waves))
let whirlInWhirlpool = tokensInPool(whirlpoolPoolId, whirlpoolString)
let projectStakeWhirl = tryGetInteger(Address(whirlpoolPoolId), (toString(this) + "_indexStaked"))
let totalStakeWhirl = tryGetInteger(Address(whirlpoolPoolId), ("global_poolToken_amount"))
let whirlInBBB = tokensInPool(bbbPoolId, whirlpoolString)
let whirlInVolatile = tokensInPool(volatilePoolId, whirlpoolString)
let whirlInBurnxtnWhirl = tokensInPool(burnxtnWhirlPoolId, whirlpoolString)
let whirlInMega = tokensInPool(megaPoolId, whirlpoolString)
let whirlInEagle = tokensInPool(eaglePoolId, whirlpoolString)
let totalWhirl = whirlInWhirlpool + whirlInBBB + whirlInVolatile + whirlInBurnxtnWhirl + whirlInMega + whirlInEagle
let whirlpoolWaves = fraction(d8, wavesInWhirlpool * tryGetInteger(Address(whirlpoolPoolId), "static_" + toBase58String(whirlpool) + "_weight") / 1000, whirlInWhirlpool)
let whirlpoolSupply = match assetInfo(whirlpool) {
case asset:Asset => asset.quantity
case _ => throw("Can't find asset")
}
func boost (poolId:String, amount:Int, days:Int) =
{invoke(Address(poolboostSC), "addBoosting", [poolId, days], [AttachedPayment(unit, amount)])}
func swapWX (assetIn:ByteVector, assetOut:ByteVector, amountIn:Int) =
{invoke(Address(base58'3P68zNiufsu1viZpu1aY3cdahRRKcvV5N93'), "swap", [1, toBase58String(assetOut), toString(this)], [AttachedPayment(assetIn, amountIn)])}
@Callable(i)
func priceStats () =
{
[
IntegerEntry("WHIRLPOOL/WAVES mid market price", whirlpoolWaves),
IntegerEntry("WHIRLPOOL total supply", whirlpoolSupply / d8),
IntegerEntry("total WAVES received", tryGetInteger(this, keyWaveletsReceived) / d8),
IntegerEntry("total WAVES paid out in WAVES", tryGetInteger(this, keyWaveletsPaidOut) / d8),
IntegerEntry(keyROI, fraction(tryGetInteger(this, keyWaveletsPaidOut), 10000, tryGetInteger(this, keyWaveletsReceived)))
]
}
@Callable(i)
func boostPoolAPY (WAVES_amount:Int, days:Int, projectOwnerReward:Boolean) =
if (i.caller != this) then throw("access only by project owner") else
{
let amountBoost = if ((projectOwnerReward == true))
then fraction((WAVES_amount * d8), 80, 100)
else (WAVES_amount * d8)
let amountOwner = if ((projectOwnerReward == true))
then fraction((WAVES_amount * d8), 20, 100)
else 0
func rewardsShare (poolShare:Int) =
{fraction(amountBoost, poolShare, totalWhirl)}
strict boostW = boost("3P2myTbd5zpEHcYmNpdWTp5gXS5B8tL1RCY", rewardsShare(whirlInWhirlpool), days)
strict boostBBB = boost("3P9VPwVfNj3dDevQZt1Z951A4K57cmQmCgk", rewardsShare(whirlInBBB), days)
strict boostVolatile = boost("3PDzArEBNXuTmczWH58mH5YMNkTVnYtNLXK", rewardsShare(whirlInVolatile), days)
strict boostBurnxtnWhirl = boost("3P48ZN6yghcoQaHPtLM9V2hFc5cd4ARd1hc", rewardsShare(whirlInBurnxtnWhirl), days)
strict boostEagle = boost("3PH6MrR3xUadhRv3pr8VcWVotviVH9BjkTv", rewardsShare(whirlInEagle), days)
#strict boostMega = boost("3PLWzzX6KeqnYZTXygzyCWZ8J48zsh8KLSW", rewardsShare(whirlInMega), days) WHIRLPOOL token!
strict transferMega = invoke(this, "transferMega", [rewardsShare(whirlInMega)], [])
strict admin = invoke(rewardsAddress, "adminRewards", [], [])
[
ScriptTransfer(Address(projectOwner), amountOwner, unit),
IntegerEntry(keyWaveletsPaidOut, amountBoost + tryGetInteger(this, keyWaveletsPaidOut)),
IntegerEntry(keyROI, fraction(tryGetInteger(this, keyWaveletsPaidOut), 10000, tryGetInteger(this, keyWaveletsReceived))),
IntegerEntry(keyActivated, height)
]
}
@Callable(i)
func transferMega (rewardsShare:Int) =
if (i.caller != this) then throw("access only by project owner") else
{
let totalIndexStaked = getIntegerValue(Address(megaPoolId), "global_indexStaked")
func amount(address:String) =
{
fraction(getIntegerValue(Address(megaPoolId), address + "_indexStaked"), rewardsShare, totalIndexStaked)
}
[
ScriptTransfer(Address(base58'3P3S2ugYddc7invK1FKwXkVehPpj6tjAJC7'), amount("3P3S2ugYddc7invK1FKwXkVehPpj6tjAJC7"), unit),
ScriptTransfer(Address(base58'3PF7eE5LpBvTVgP3wi7sXEUmaYo1Bw6PpBm'), amount("3PF7eE5LpBvTVgP3wi7sXEUmaYo1Bw6PpBm"), unit),
ScriptTransfer(Address(base58'3PHFAavxj2ePJqFB46H2aRGA7oQL6kz1rJJ'), amount("3PHFAavxj2ePJqFB46H2aRGA7oQL6kz1rJJ"), unit),
ScriptTransfer(Address(base58'3PJtPfCWYGtSDry7UtL7CKnWp4Jgq8rM4Da'), amount("3PJtPfCWYGtSDry7UtL7CKnWp4Jgq8rM4Da"), unit),
ScriptTransfer(Address(base58'3PPwwvLTHe5AvcTXk54Wqr4wBm6HQCyDDKr'), amount("3PPwwvLTHe5AvcTXk54Wqr4wBm6HQCyDDKr"), unit)
]
}
@Callable(i)
func withdraw () =
if (i.caller != invoker) then throw("no access") else
{
strict withdraw = invoke(Address(base58'3PCbvPVQfSvVu88ip8Fm5YjwJhjEYk1Txhk'), "withdrawVestedAllUSDN", [false, true], [])
[]
}
@Callable(i)
func changeIntegerEntry (keyString:String, integer:Int) =
if (i.caller != this) then throw("access only by project owner") else
{[IntegerEntry(keyString, integer)]}
@Callable(i)
func activated () =
if (i.caller != this) then throw("you are not allowed") else
{[IntegerEntry(keyActivated, height)]}
@Callable(i)
func swap () =
if i.caller != this && i.caller != invoker then throw("no access") else
if getBoolean(kDisable) == true then [] else
{
let amount = if assetBalance(this, xtnId) > 1000 * d6 then 1000 * d6 else assetBalance(this, xtnId)
strict swapXtnWaves = if assetBalance(this, xtnId) > 0 then invoke(swopWAVESxtn, "callFunction", ["exchange", ["1"]], [AttachedPayment(xtnId, amount)]) else unit
let amountWX = if assetBalance(this, wxId) > 1000 * d8 then 1000 * d8 else assetBalance(this, wxId)
strict swapWxWaves = if assetBalance(this, wxId) > 0 then swapWX(wxId, base58'WAVES', amountWX) else unit
[]
}
@Callable(i)
func stakeUnstake (stake:Boolean, WAVES_amount:Int) =
if i.caller != this && i.caller != invoker then throw("no access") else
if (stake == true && wavesBalance(this).available <= d8) then [] else
{
let pool = Address(base58'3PJvwxivuWv29LzU1DaEQLsMeXeUJqMAuMk')
let leasingId = getBinary(this, kLeasingId)
let leasingAmount = valueOrElse(getInteger(this, kLeasingAmount), 0)
let newLeaseAmount = if (stake)
then (leasingAmount + wavesBalance(this).available - d8)
else (leasingAmount - (WAVES_amount * d8))
let newLease = Lease(pool, newLeaseAmount, 1)
let newLeaseId = calculateLeaseId(newLease)
let baseEntry =
[newLease,
BinaryEntry(kLeasingId, newLeaseId),
IntegerEntry(kLeasingAmount,
newLeaseAmount),
ScriptTransfer(hWhirlpool, assetBalance(this, unit0id), unit0id),
ScriptTransfer(hWhirlpool, assetBalance(this, wavesdlpid), wavesdlpid)]
match leasingId {
case lId: ByteVector => ([LeaseCancel(lId)] ++ baseEntry)
case _ => baseEntry
}
}
@Callable(i)
func disable (disable:Boolean) =
if i.caller != this && i.caller != invoker then throw("no access") else
{
[BooleanEntry(kDisable, disable)]
}
@Verifier(tx)
func verify() =
{
sigVerify_16Kb(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
|| if (height < getIntegerValue(this, keyActivated) + unlockBlock) then false else
sigVerify_16Kb(tx.bodyBytes, tx.proofs[0], heirPubKey)
|| if (height < getIntegerValue(this, keyActivated) + unlockBlock2) then false else
sigVerify_16Kb(tx.bodyBytes, tx.proofs[0], PuzzleMasterPubKey)
}