Skip to content

Commit 23c77d4

Browse files
authored
Merge pull request #205 from icon-project/fix-issuer
Fix issuer
2 parents 6ebbc2d + a02b8a6 commit 23c77d4

File tree

4 files changed

+91
-15
lines changed

4 files changed

+91
-15
lines changed

icon/icmodule/revision.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const (
4545
Revision23
4646
Revision24
4747
Revision25
48+
Revision26
4849
RevisionReserved
4950
)
5051

@@ -120,6 +121,8 @@ const (
120121
RevisionChainScoreEventLog = Revision24
121122

122123
RevisionIISS4R1 = Revision25
124+
125+
RevisionFixIssueRegulator = Revision26
123126
)
124127

125128
var revisionFlags []module.Revision

icon/iiss/eventlog.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const (
4141
EventPRepRegistered = "PRepRegistered(Address)"
4242
EventPRepSet = "PRepSet(Address)"
4343
EventRewardFundTransferred = "RewardFundTransferred(str,Address,Address,int)"
44+
EventRewardFundTransferFailed = "RewardFundTransferFailed(str,Address,Address,int)"
4445
EventRewardFundBurned = "RewardFundBurned(str,Address,int)"
4546
EventPRepUnregistered = "PRepUnregistered(Address)"
4647
EventBTPNetworkTypeActivated = "BTPNetworkTypeActivated(str,int)"
@@ -218,6 +219,18 @@ func EmitRewardFundTransferredEvent(cc icmodule.CallContext, key string, from, t
218219
)
219220
}
220221

222+
func EmitRewardFundTransferFailedEvent(cc icmodule.CallContext, key string, from, to module.Address, amount *big.Int) {
223+
cc.OnEvent(state.SystemAddress,
224+
[][]byte{[]byte(EventRewardFundTransferFailed)},
225+
[][]byte{
226+
[]byte(key),
227+
from.Bytes(),
228+
to.Bytes(),
229+
intconv.BigIntToBytes(amount),
230+
},
231+
)
232+
}
233+
221234
func EmitRewardFundBurnedEvent(cc icmodule.CallContext, key string, from module.Address, amount *big.Int) {
222235
cc.OnEvent(state.SystemAddress,
223236
[][]byte{[]byte(EventRewardFundBurned)},

icon/iiss/extension.go

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -927,19 +927,39 @@ func (es *ExtensionStateImpl) regulateIssue(iScore *big.Int) error {
927927
return err
928928
}
929929
reward := new(big.Int).Set(iScore)
930-
if prevGlobal != nil && icstate.IISSVersion3 == prevGlobal.GetIISSVersion() {
931-
pg := prevGlobal.GetV2()
932-
multiplier := big.NewInt(int64(prevGlobal.GetTermPeriod() * icmodule.IScoreICXRatio))
933-
divider := big.NewInt(icmodule.MonthBlock * icmodule.DenomInRate)
934-
rewardCPS := new(big.Int).Mul(pg.GetIGlobal(), pg.GetICps().NumBigInt())
935-
rewardCPS.Mul(rewardCPS, multiplier)
936-
rewardCPS.Div(rewardCPS, divider)
937-
reward.Add(reward, rewardCPS)
938-
rewardRelay := new(big.Int).Mul(pg.GetIGlobal(), pg.GetIRelay().NumBigInt())
939-
rewardRelay.Mul(rewardRelay, multiplier)
940-
rewardRelay.Div(rewardRelay, divider)
941-
reward.Add(reward, rewardRelay)
942-
es.logger.Tracef("regulateIssue with cps: %d, relay: %d", rewardCPS, rewardRelay)
930+
if prevGlobal != nil {
931+
switch prevGlobal.GetIISSVersion() {
932+
case icstate.IISSVersion2:
933+
case icstate.IISSVersion3:
934+
pg := prevGlobal.GetV2()
935+
multiplier := big.NewInt(int64(prevGlobal.GetTermPeriod() * icmodule.IScoreICXRatio))
936+
divider := big.NewInt(icmodule.MonthBlock * icmodule.DenomInRate)
937+
rewardCPS := new(big.Int).Mul(pg.GetIGlobal(), pg.GetICps().NumBigInt())
938+
rewardCPS.Mul(rewardCPS, multiplier)
939+
rewardCPS.Div(rewardCPS, divider)
940+
reward.Add(reward, rewardCPS)
941+
rewardRelay := new(big.Int).Mul(pg.GetIGlobal(), pg.GetIRelay().NumBigInt())
942+
rewardRelay.Mul(rewardRelay, multiplier)
943+
rewardRelay.Div(rewardRelay, divider)
944+
reward.Add(reward, rewardRelay)
945+
es.logger.Tracef("regulateIssue with cps: %d, relay: %d", rewardCPS, rewardRelay)
946+
case icstate.IISSVersion4:
947+
if term.Revision() >= icmodule.RevisionFixIssueRegulator {
948+
pg := prevGlobal.GetV3()
949+
multiplier := big.NewInt(int64(pg.GetTermPeriod() * icmodule.IScoreICXRatio))
950+
951+
keys := []icstate.RFundKey{icstate.KeyIcps, icstate.KeyIrelay}
952+
for _, key := range keys {
953+
amount := pg.GetRewardFundAmountByKey(key)
954+
amount.Mul(amount, multiplier)
955+
amount.Div(amount, big.NewInt(icmodule.MonthBlock))
956+
reward.Add(reward, amount)
957+
es.logger.Tracef("regulateIssue with %s: %s", key, amount)
958+
}
959+
}
960+
default:
961+
panic("regulateIssue: unknown IISS version")
962+
}
943963
}
944964

945965
is, err := es.State.GetIssue()
@@ -1703,9 +1723,10 @@ func (es *ExtensionStateImpl) transferRewardFund(cc icmodule.CallContext) error
17031723
amount.Div(amount, div)
17041724
if ok {
17051725
if err := cc.Transfer(from, to, amount, module.Reward); err != nil {
1706-
return err
1726+
EmitRewardFundTransferFailedEvent(cc, k.key, from, to, amount)
1727+
} else {
1728+
EmitRewardFundTransferredEvent(cc, k.key, from, to, amount)
17071729
}
1708-
EmitRewardFundTransferredEvent(cc, k.key, from, to, amount)
17091730
} else {
17101731
if cc.Revision().Value() >= icmodule.RevisionFixTransferRewardFund {
17111732
if err := cc.Withdraw(from, amount, module.Burn); err != nil {

icon/revision.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
package icon
1818

1919
import (
20+
"math/big"
21+
22+
"github.com/icon-project/goloop/common"
2023
"github.com/icon-project/goloop/icon/icmodule"
2124
"github.com/icon-project/goloop/icon/iiss"
2225
"github.com/icon-project/goloop/icon/iiss/icstate"
@@ -42,6 +45,7 @@ var revHandlerTable = []revHandlerItem{
4245
{icmodule.RevisionBlockAccounts2, onRevBlockAccounts2},
4346
{icmodule.RevisionIISS4R0, onRevIISS4R0},
4447
{icmodule.RevisionIISS4R1, onRevIISS4R1},
48+
{icmodule.RevisionFixIssueRegulator, onRevFixIssueRegulator},
4549
}
4650

4751
// DO NOT update revHandlerMap manually
@@ -358,3 +362,38 @@ func onRevIISS4R1(s *chainScore, _, _ int) error {
358362

359363
return nil
360364
}
365+
366+
func onRevFixIssueRegulator(s *chainScore, _, _ int) error {
367+
if s.cc.ChainID() != CIDForMainNet {
368+
return nil
369+
}
370+
371+
cc := s.newCallContext(s.cc)
372+
// deposit 6M to treasury
373+
issueAmount := new(big.Int).Mul(icmodule.BigIntICX, big.NewInt(6_000_000))
374+
if err := cc.Deposit(cc.Treasury(), issueAmount, module.Issue); err != nil {
375+
return err
376+
}
377+
// increase total supply
378+
if _, err := cc.AddTotalSupply(issueAmount); err != nil {
379+
return err
380+
}
381+
382+
// emit event logs
383+
es := s.cc.GetExtensionState().(*iiss.ExtensionStateImpl)
384+
issue, err := es.State.GetIssue()
385+
if err != nil {
386+
issue = icstate.NewIssue()
387+
}
388+
iiss.EmitICXIssuedEvent(
389+
cc,
390+
&iiss.IssueResultJSON{
391+
common.HexIntZero,
392+
common.HexIntZero,
393+
common.NewHexInt(0).SetValue(issueAmount),
394+
},
395+
issue,
396+
)
397+
398+
return nil
399+
}

0 commit comments

Comments
 (0)