Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Launchpad Architecture Refactoring #451

Merged
merged 67 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
0e0c413
chore: remove function prefix from panic msg
notJoon Dec 26, 2024
21ba603
save
notJoon Dec 27, 2024
955a906
save
notJoon Dec 27, 2024
be7b53c
test: reward handler
notJoon Dec 27, 2024
d2eca32
feat: deposit handler
notJoon Dec 27, 2024
8fc43b3
fix error
notJoon Jan 2, 2025
2c1d6a9
reward distributor
notJoon Jan 2, 2025
08f7a7e
update test
notJoon Jan 2, 2025
e4834d5
update docs
notJoon Jan 2, 2025
a25166a
fix
notJoon Jan 2, 2025
fc64b50
refactor deposit, launchpad, reward
notJoon Jan 3, 2025
25a578a
reduce type size
notJoon Jan 3, 2025
a04e3c7
fix rpc
notJoon Jan 3, 2025
fbd351c
refactor: error message
onlyhyde Jan 3, 2025
39655bb
fix
notJoon Jan 3, 2025
4641f0b
fix
notJoon Jan 3, 2025
2f2fa18
test: json builder
notJoon Jan 3, 2025
b482db8
update deposit test
notJoon Jan 4, 2025
cf9421f
test: reward
notJoon Jan 4, 2025
f682679
fix
notJoon Jan 5, 2025
0761123
add launchpad new logic
mconcat Jan 6, 2025
b9d4109
catch compile errors
notJoon Jan 7, 2025
a1491bc
fix: weird interface nil error
notJoon Jan 7, 2025
3978bd4
refactor: reward empty
onlyhyde Jan 8, 2025
323749b
fix: when collecting deposit, check claimable Time
r3v4s Jan 8, 2025
158d843
test: fix
r3v4s Jan 8, 2025
94681f5
test: fix MultipleDeposit
r3v4s Jan 8, 2025
5504b2e
test: fix TestValidateRewardCollection
r3v4s Jan 8, 2025
eb596b5
resolved some comments
notJoon Jan 8, 2025
f5b33c6
remove unnecessary things
notJoon Jan 8, 2025
645126a
remove unnecessary json builder functuion
notJoon Jan 8, 2025
d703148
refactor: event message
onlyhyde Jan 8, 2025
09bfc7c
update launchpad test
notJoon Jan 9, 2025
30fb984
fix: reward_calculation
notJoon Jan 9, 2025
545ceba
remove dummy_test file
notJoon Jan 9, 2025
1b15aef
additional refactor for `CreateProject`
notJoon Jan 9, 2025
744999d
fix: prevent throwing nil deref error in `CollectRewardByProjectId`
notJoon Jan 9, 2025
0484f69
validate json creation
notJoon Jan 9, 2025
2dc6624
save
notJoon Jan 9, 2025
2bac374
fix fee protocol
mconcat Jan 9, 2025
b218fe8
remove: token register
notJoon Jan 9, 2025
1dd921e
fix compile error for reward03 test
notJoon Jan 9, 2025
7136488
paritally fix: `CollectRewardByProjectId` -- update `RewardState`
notJoon Jan 9, 2025
6de8ce8
fix
notJoon Jan 13, 2025
e96a4cd
refactor: clean code and add comments for functions
onlyhyde Jan 16, 2025
42ccd47
Merge branch 'main' into refactor-launchpad
notJoon Jan 16, 2025
26acf7c
test: reward calculation
notJoon Jan 16, 2025
cc10169
update reward test
notJoon Jan 16, 2025
19d58c4
refactor: deposit refactoring
onlyhyde Jan 16, 2025
27be524
refactor: create project
onlyhyde Jan 17, 2025
765ec87
Merge branch 'main' into refactor-launchpad
notJoon Jan 19, 2025
6fe064e
Merge branch 'refactor-launchpad' of https://github.com/gnoswap-labs/…
onlyhyde Jan 19, 2025
5a5834e
refactor: deposit
onlyhyde Jan 19, 2025
39dcbcb
refactor: reward by projectId
onlyhyde Jan 19, 2025
b21ec0a
refactor: deposit and reward
onlyhyde Jan 19, 2025
ff66ce8
refactor: left reward
onlyhyde Jan 19, 2025
f73508b
refactor: reward test
onlyhyde Jan 19, 2025
182dfa3
refactor: move test code into test folder
onlyhyde Jan 19, 2025
95966a9
refactor: remove unused code
onlyhyde Jan 19, 2025
1d0b4e7
chore: remove some comments
onlyhyde Jan 19, 2025
b7efc17
chore: remove comments
onlyhyde Jan 19, 2025
3603c21
remove: hard-coded string
notJoon Jan 19, 2025
0af85d0
Merge branch 'refactor-launchpad' of https://github.com/gnoswap-labs/…
notJoon Jan 19, 2025
ee22957
remove: invalid comments
notJoon Jan 19, 2025
85429ee
Merge branch 'main' into refactor-launchpad
notJoon Jan 19, 2025
899e89d
fix: check duplicate collect gns
onlyhyde Jan 19, 2025
38e31c7
Merge branch 'refactor-launchpad' of https://github.com/gnoswap-labs/…
onlyhyde Jan 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _deploy/r/gnoswap/common/liquidity_amounts_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func TestGetLiquidityForAmounts(t *testing.T) {
}{
{
name: "Basic Liquidity Calculation - Token0 Dominant",
sqrtRatioX96: q96.ToString(), // 현재 가격이 Q96
sqrtRatioX96: q96.ToString(),
sqrtRatioAX96: (new(u256.Uint).Mul(q96, u256.NewUint(4))).ToString(),
sqrtRatioBX96: (new(u256.Uint).Mul(q96, u256.NewUint(16))).ToString(),
amount0: "1000000",
Expand Down
24 changes: 12 additions & 12 deletions gov/staker/api_staker.gno
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,31 @@ func GetLockedInfoByAddress(addr std.Address) string {
func GetClaimableRewardByAddress(addr std.Address) string {
en.MintAndDistributeGns()

emissionReward, exist := userEmissionReward.Get(addr.String())
if !exist {
rewardState.finalize(getCurrentBalance(), getCurrentProtocolFeeBalance())

emissionReward, protocolFeeRewards := rewardState.CalculateReward(addr)

if emissionReward == 0 && len(protocolFeeRewards) == 0 {
return ""
}

data := json.Builder().
WriteString("height", formatInt(std.GetHeight())).
WriteString("now", formatInt(time.Now().Unix())).
WriteString("emissionReward", formatUint(emissionReward.(uint64))).
WriteString("emissionReward", formatUint(emissionReward)).
Node()

protocolFees, exist := userProtocolFeeReward.Get(addr.String())
if exist {
if len(protocolFeeRewards) > 0 {
pfArr := json.ArrayNode("", nil)
protocolFees.(*avl.Tree).Iterate("", "", func(key string, value interface{}) bool {
amount := value.(uint64)
if amount > 0 {
for tokenPath, protocolFeeReward := range protocolFeeRewards {
if protocolFeeReward > 0 {
pfObj := json.Builder().
WriteString("tokenPath", key).
WriteString("amount", formatUint(amount)).
WriteString("tokenPath", tokenPath).
WriteString("amount", formatUint(protocolFeeReward)).
Node()
pfArr.AppendArray(pfObj)
}
return false
})
}

data.AppendObject("protocolFees", pfArr)
}
Expand Down
125 changes: 125 additions & 0 deletions gov/staker/api_staker_test.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package staker

import (
"std"
"testing"
"time"

"gno.land/p/demo/json"
"gno.land/p/demo/testutils"
"gno.land/p/demo/uassert"
)

func TestGetLockedInfoByAddress(t *testing.T) {
addr := testutils.TestAddress("locked_info_test")

now := uint64(time.Now().Unix())
lockedGNSList := []lockedGNS{
{amount: 1000, unlock: now - 100}, // already unlocked
{amount: 2000, unlock: now + 100}, // still locked
{amount: 3000, unlock: now - 50}, // already unlocked
}
addrLockedGns.Set(addr.String(), lockedGNSList)

result := GetLockedInfoByAddress(addr)

node := json.Must(json.Unmarshal([]byte(result)))

uassert.True(t, node.HasKey("height"))
uassert.True(t, node.HasKey("now"))
uassert.True(t, node.HasKey("totalLocked"))
uassert.True(t, node.HasKey("claimableAmount"))

// summation of all the locked quantities
totalLocked, err := node.MustKey("totalLocked").GetString()
uassert.NoError(t, err)
uassert.Equal(t, totalLocked, "6000") // 1000 + 2000 + 3000 = 6000

claimableAmount, err := node.MustKey("claimableAmount").GetString()
uassert.NoError(t, err)
uassert.Equal(t, claimableAmount, "4000") // 1000 + 3000 = 4000
}

func TestGetLockedInfoByAddress_NoLocks(t *testing.T) {
addr := testutils.TestAddress("no_locks_test")

// no quantities are locked here
result := GetLockedInfoByAddress(addr)
uassert.Equal(t, result, "")
}

func TestGetLockedInfoByAddress_EmptyLocks(t *testing.T) {
addr := testutils.TestAddress("empty_locks_test")

addrLockedGns.Set(addr.String(), []lockedGNS{})

result := GetLockedInfoByAddress(addr)

node := json.Must(json.Unmarshal([]byte(result)))
uassert.True(t, node.HasKey("height"))
uassert.True(t, node.HasKey("now"))
uassert.True(t, node.HasKey("totalLocked"))
uassert.True(t, node.HasKey("claimableAmount"))

totalLocked, err := node.MustKey("totalLocked").GetString()
uassert.NoError(t, err)
uassert.Equal(t, totalLocked, "0")

claimableAmount, err := node.MustKey("claimableAmount").GetString()
uassert.NoError(t, err)
uassert.Equal(t, claimableAmount, "0")
}

func TestGetClaimableRewardByAddress(t *testing.T) {
addr := testutils.TestAddress("claimable_test")

rewardState.AddStake(uint64(std.GetHeight()), addr, 100, 0, nil)

currentGNSBalance = 1000
// userEmissionReward.Set(addr.String(), uint64(1000))

currentProtocolFeeBalance["token1:token2"] = 500
currentProtocolFeeBalance["token2:token3"] = 300
//pfTree := avl.NewTree()
//pfTree.Set("token1:token2", uint64(500))
//pfTree.Set("token2:token3", uint64(300))
//userProtocolFeeReward.Set(addr.String(), pfTree)

result := GetClaimableRewardByAddress(addr)

node := json.Must(json.Unmarshal([]byte(result)))

uassert.True(t, node.HasKey("height"))
uassert.True(t, node.HasKey("now"))

emissionReward, err := node.MustKey("emissionReward").GetString()
uassert.NoError(t, err)
uassert.Equal(t, emissionReward, "1000")

protocolFees := node.MustKey("protocolFees")
uassert.True(t, protocolFees.IsArray())

protocolFees.ArrayEach(func(i int, fee *json.Node) {
tokenPath, err := fee.MustKey("tokenPath").GetString()
uassert.NoError(t, err)

amount, err := fee.MustKey("amount").GetString()
uassert.NoError(t, err)

switch tokenPath {
case "token1:token2":
uassert.Equal(t, amount, "500")
case "token2:token3":
uassert.Equal(t, amount, "300")
default:
t.Errorf("unexpected tokenPath: %s", tokenPath)
}
})
}

func TestGetClaimableRewardByAddress_NoRewards(t *testing.T) {
addr := testutils.TestAddress("no_reward_test")

result := GetClaimableRewardByAddress(addr)
uassert.Equal(t, result, "")
}
Loading
Loading