Skip to content

Commit

Permalink
GSW-1639 feat: launchpad getters for rdb (#348)
Browse files Browse the repository at this point in the history
* GSW-1639 feat: getters for rdb

* fix: typo

* refactor: remove unused functions

* build: makefile to test launchpad
  • Loading branch information
r3v4s authored Oct 11, 2024
1 parent 85146cb commit 63fe0b7
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 211 deletions.
6 changes: 4 additions & 2 deletions __local/test/launchpad_test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ send-ugnot-must:
@echo "" | gnokey maketx send -send 10000000000ugnot -to $(ADDR_TR01) -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 100000000 -memo "" test1
@echo

dummy-tx:
@echo "" | gnokey maketx send -send 1ugnot -to $(ADDR_GSA) -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 100000000 -memo "" test1

# deploy test grc20 tokens
deploy-foo:
Expand Down Expand Up @@ -404,15 +406,15 @@ launchpad-deposit:

## DEPOSIT TO PROJECT ( tier 30 )
$(info ************ deposit to project // gnoswap_admin ************)
@echo "" | gnokey maketx call -pkgpath gno.land/r/gnoswap/v2/launchpad -func DepositGns -args "gno.land/r/onbloc/obl:69:30" -args 1000000 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 100000000 -memo "" gnoswap_admin
@echo "" | gnokey maketx call -pkgpath gno.land/r/gnoswap/v2/launchpad -func DepositGns -args "gno.land/r/onbloc/obl:62:30" -args 1000000 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 100000000 -memo "" gnoswap_admin

launchpad-collect-protocol:
$(info ************ collect protocol fee by projects recipients // tr01 ************)
@echo "" | gnokey maketx call -pkgpath gno.land/r/gnoswap/v2/launchpad -func CollectProtocolFee -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 100000000 -memo "" gnoswap_tr01

launchpad-collect-reward:
$(info ************ collect reward bt project id // gnoswap_admin ************)
@echo "" | gnokey maketx call -pkgpath gno.land/r/gnoswap/v2/launchpad -func CollectRewardByProjectId -args "gno.land/r/onbloc/obl:69" -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 100000000 -memo "" gnoswap_admin
@echo "" | gnokey maketx call -pkgpath gno.land/r/gnoswap/v2/launchpad -func CollectRewardByProjectId -args "gno.land/r/onbloc/obl:62" -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 100000000 -memo "" gnoswap_admin

## TRANSFER FOR QA
ADDR_ROH := g16a7etgm9z2r653ucl36rj0l2yqcxgrz2jyegzx
Expand Down
82 changes: 82 additions & 0 deletions launchpad/_RPC_api_project.gno
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,46 @@ import (
"gno.land/p/demo/ufmt"
)

func ApiGetProjectAndTierStatisticsByProjectId(projectId string) string {
project, exist := projects[projectId]
if !exist {
return ""
}

totalDepositAmount := project.totalDepositAmount
actualDepositAmount := project.actualDepositAmount

totalParticipant := project.totalParticipant
actualParticipant := project.actualParticipant

totalCollectedAmount := project.totalCollectedAmount

projectObj := metaNode()
projectObj.AppendObject("projectId", json.StringNode("projectId", projectId))
projectObj.AppendObject("totalDepositAmount", json.StringNode("totalDepositAmount", ufmt.Sprintf("%d", totalDepositAmount)))
projectObj.AppendObject("actualDepositAmount", json.StringNode("actualDepositAmount", ufmt.Sprintf("%d", actualDepositAmount)))
projectObj.AppendObject("totalParticipant", json.StringNode("totalParticipant", ufmt.Sprintf("%d", totalParticipant)))
projectObj.AppendObject("actualParticipant", json.StringNode("actualParticipant", ufmt.Sprintf("%d", actualParticipant)))
projectObj.AppendObject("totalCollectedAmount", json.StringNode("totalCollectedAmount", ufmt.Sprintf("%d", totalCollectedAmount)))

projectObj.AppendObject("tier30TotalDepositAmount", json.StringNode("tier30TotalDepositAmount", ufmt.Sprintf("%d", project.tier30.totalDepositAmount)))
projectObj.AppendObject("tier30ActualDepositAmount", json.StringNode("tier30ActualDepositAmount", ufmt.Sprintf("%d", project.tier30.actualDepositAmount)))
projectObj.AppendObject("tier30TotalParticipant", json.StringNode("tier30TotalParticipant", ufmt.Sprintf("%d", project.tier30.totalParticipant)))
projectObj.AppendObject("tier30ActualParticipant", json.StringNode("tier30ActualParticipant", ufmt.Sprintf("%d", project.tier30.actualParticipant)))

projectObj.AppendObject("tier90TotalDepositAmount", json.StringNode("tier90TotalDepositAmount", ufmt.Sprintf("%d", project.tier90.totalDepositAmount)))
projectObj.AppendObject("tier90ActualDepositAmount", json.StringNode("tier90ActualDepositAmount", ufmt.Sprintf("%d", project.tier90.actualDepositAmount)))
projectObj.AppendObject("tier90TotalParticipant", json.StringNode("tier90TotalParticipant", ufmt.Sprintf("%d", project.tier90.totalParticipant)))
projectObj.AppendObject("tier90ActualParticipant", json.StringNode("tier90ActualParticipant", ufmt.Sprintf("%d", project.tier90.actualParticipant)))

projectObj.AppendObject("tier180TotalDepositAmount", json.StringNode("tier180TotalDepositAmount", ufmt.Sprintf("%d", project.tier180.totalDepositAmount)))
projectObj.AppendObject("tier180ActualDepositAmount", json.StringNode("tier180ActualDepositAmount", ufmt.Sprintf("%d", project.tier180.actualDepositAmount)))
projectObj.AppendObject("tier180TotalParticipant", json.StringNode("tier180TotalParticipant", ufmt.Sprintf("%d", project.tier180.totalParticipant)))
projectObj.AppendObject("tier180ActualParticipant", json.StringNode("tier180ActualParticipant", ufmt.Sprintf("%d", project.tier180.actualParticipant)))

return marshal(projectObj)
}

func ApiGetProjectStatisticsByProjectId(projectId string) string {
project, exist := projects[projectId]
if !exist {
Expand All @@ -23,6 +63,7 @@ func ApiGetProjectStatisticsByProjectId(projectId string) string {
totalCollectedAmount := project.totalCollectedAmount

projectObj := metaNode()
projectObj.AppendObject("projectId", json.StringNode("projectId", projectId))
projectObj.AppendObject("totalDepositAmount", json.StringNode("totalDepositAmount", ufmt.Sprintf("%d", totalDepositAmount)))
projectObj.AppendObject("actualDepositAmount", json.StringNode("actualDepositAmount", ufmt.Sprintf("%d", actualDepositAmount)))
projectObj.AppendObject("totalParticipant", json.StringNode("totalParticipant", ufmt.Sprintf("%d", totalParticipant)))
Expand All @@ -32,6 +73,47 @@ func ApiGetProjectStatisticsByProjectId(projectId string) string {
return marshal(projectObj)
}

func ApiGetProjectStatisticsByProjectTierId(tierId string) string {
projectId, tierStr := getProjectIdAndTierFromTierId(tierId)
project, exist := projects[projectId]
if !exist {
println("NO PROJECT FOR THIS ID", projectId)
return ""
}

var tier Tier
switch tierStr {
case "30":
tier = project.tier30
case "90":
tier = project.tier90
case "180":
tier = project.tier180
default:
println("NO TIER FOR THIS ID", tierId)
return ""
}

tierAmount := tier.tierAmount // project token allocation

tierTotalDepositAmount := tier.totalDepositAmount
tierActualDepositAmount := tier.actualDepositAmount

tierTotalParticipant := tier.totalParticipant
tierActualParticipant := tier.actualParticipant

projectTierObj := metaNode()
projectTierObj.AppendObject("projectId", json.StringNode("projectId", projectId))
projectTierObj.AppendObject("tierId", json.StringNode("tierId", tierId))
projectTierObj.AppendObject("tierAmount", json.StringNode("tierAmount", ufmt.Sprintf("%d", tierAmount)))
projectTierObj.AppendObject("tierTotalDepositAmount", json.StringNode("tierTotalDepositAmount", ufmt.Sprintf("%d", tierTotalDepositAmount)))
projectTierObj.AppendObject("tierActualDepositAmount", json.StringNode("tierActualDepositAmount", ufmt.Sprintf("%d", tierActualDepositAmount)))
projectTierObj.AppendObject("tierTotalParticipant", json.StringNode("tierTotalParticipant", ufmt.Sprintf("%d", tierTotalParticipant)))
projectTierObj.AppendObject("tierActualParticipant", json.StringNode("tierActualParticipant", ufmt.Sprintf("%d", tierActualParticipant)))

return marshal(projectTierObj)
}

func metaNode() *json.Node {
height := std.GetHeight()
now := time.Now().Unix()
Expand Down
22 changes: 12 additions & 10 deletions launchpad/launchpad_deposit.gno
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ func DepositGns(
gs.SetAmountByProjectWallet(project.recipient, amount, true) // true == add

// update tier
tier.depositAmount += amount
tier.participant += 1
tier.totalDepositAmount += amount
tier.actualDepositAmount += amount
tier.totalParticipant += 1
tier.actualParticipant += 1
project = setTier(project, tierStr, tier)

// update project
Expand Down Expand Up @@ -179,8 +181,8 @@ func CollectDepositGns() uint64 {
gs.SetAmountByProjectWallet(project.recipient, deposit.amount, false) // subtract

// update tier
tier.depositAmount -= deposit.amount
tier.participant -= 1
tier.actualDepositAmount -= deposit.amount
tier.actualParticipant -= 1

// update project
project = setTier(project, deposit.tier, tier)
Expand Down Expand Up @@ -213,7 +215,7 @@ func CollectDepositGns() uint64 {
//
// returns collected gns amount
func CollectDepositGnsByProjectId(projectId string) uint64 {
project, exist := projects[projectId]
_, exist := projects[projectId]
if !exist {
println("NO PROJECT FOR THIS ID", projectId)
return 0
Expand Down Expand Up @@ -264,8 +266,8 @@ func CollectDepositGnsByProjectId(projectId string) uint64 {
gs.SetAmountByProjectWallet(project.recipient, deposit.amount, false) // subtract

// update tier
tier.depositAmount -= deposit.amount
tier.participant -= 1
tier.actualDepositAmount -= deposit.amount
tier.actualParticipant -= 1

// update project
project = setTier(project, deposit.tier, tier)
Expand Down Expand Up @@ -338,8 +340,8 @@ func CollectDepositGnsByDepositId(depositId string) uint64 {
gs.SetAmountByProjectWallet(project.recipient, deposit.amount, false) // subtract

// update tier
tier.depositAmount -= deposit.amount
tier.participant -= 1
tier.actualDepositAmount -= deposit.amount
tier.actualParticipant -= 1

// update project
project = setTier(project, deposit.tier, tier)
Expand All @@ -351,7 +353,7 @@ func CollectDepositGnsByDepositId(depositId string) uint64 {
std.Emit(
"CollectDepositGns",
"m_prevRealm", prevRealm(),
"depositId", depositId,
"p_depositId", depositId,
"amount", ufmt.Sprintf("%d", deposit.amount),
)

Expand Down
2 changes: 1 addition & 1 deletion launchpad/launchpad_init.gno
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ func CreateProject(
"p_tier30Ratio", ufmt.Sprintf("%d", tier30Ratio),
"p_tier90Ratio", ufmt.Sprintf("%d", tier90Ratio),
"p_tier180Ratio", ufmt.Sprintf("%d", tier180Ratio),
"p_startHeight", ufmt.Sprintf("%d", startHeight),
"p_startTime", ufmt.Sprintf("%d", startTime),
"startHeight", ufmt.Sprintf("%d", startHeight),
"projectId", projectId,

"tier30Amount", ufmt.Sprintf("%d", tier30Amount),
Expand Down
Loading

0 comments on commit 63fe0b7

Please sign in to comment.