Skip to content

Commit c88f1f9

Browse files
authored
Merge pull request #179 from gnoswap-labs/GSW-877-feat-implement-some-todos
GSW-877 feat: implement some todos
2 parents afd1752 + ccf3714 commit c88f1f9

14 files changed

+101
-118
lines changed

_setup/gns/gns.gno

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,28 @@ import (
77
"gno.land/p/demo/grc/grc20"
88
"gno.land/p/demo/ufmt"
99
"gno.land/r/demo/users"
10+
11+
"gno.land/r/demo/consts"
1012
)
1113

14+
const MAXIMUM_SUPPLY = uint64(1_000_000_000_000_000)
15+
1216
var (
1317
gns *grc20.AdminToken
1418
admins []string
1519
)
1620

17-
const (
18-
admin std.Address = "g12l9splsyngcgefrwa52x5a7scc29e9v086m6p4" // GSA, r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK
19-
INTERNAL_REWARD_ACCOUNT std.Address = "g1paqttvcjcluuya9n9twyw7yacv54mt7ld3gvzm" // IRA, r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK
20-
)
21-
2221
func init() {
23-
// r3v4_xxx: SET MAXIMUM SUPPLY
24-
2522
gns = grc20.NewAdminToken("Gnoswap", "GNS", 6)
26-
// gns.Mint(admin, 100_000_000_000_000) // @administrator
27-
gns.Mint(INTERNAL_REWARD_ACCOUNT, 400_000_000_000_000) // @INTERNAL_REWARD_ACCOUNT
28-
gns.Mint(std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"), 100_000_000_000) // default test1
23+
gns.Mint(consts.INTERNAL_REWARD_ACCOUNT, 500_000_000_000_000)
24+
25+
gns.Mint(std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"), 100_000_000_000) // r3v4_xxx: default test1
2926

30-
stakerAddr := std.DerivePkgAddr("gno.land/r/demo/staker") // r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK
27+
stakerAddr := consts.GOV_ADDR
3128
admins = append(admins, string(stakerAddr))
32-
admins = append(admins, string(admin))
29+
admins = append(admins, string(consts.GNOSWAP_ADMIN))
3330

34-
gns.Approve(INTERNAL_REWARD_ACCOUNT, stakerAddr, 9_223_372_036_854_775_807) // max uint64
31+
gns.Approve(consts.INTERNAL_REWARD_ACCOUNT, stakerAddr, uint64(consts.MAX_UINT64))
3532
}
3633

3734
// method proxies as public functions.
@@ -90,19 +87,29 @@ func TransferFrom(from, to users.AddressOrName, amount uint64) {
9087

9188
// faucet.
9289
func Faucet(addr std.Address) { // r3v4_xxx: REMOVE FAUCET WHEN DEPLOYING TO OFFICIAL NETWORK
93-
gns.Mint(addr, 100_000_000)
90+
toGive := uint64(100 * 1_000_000)
91+
if gns.TotalSupply()+toGive <= MAXIMUM_SUPPLY {
92+
gns.Mint(addr, toGive)
93+
}
9494
}
9595

9696
func FaucetL() { // r3v4_xxx: REMOVE FAUCET WHEN DEPLOYING TO OFFICIAL NETWORK
97+
toGive := uint64(1_000_000 * 1_000_000) // 1M
9798
caller := std.PrevRealm().Addr()
98-
gns.Mint(caller, 1_000_000_000_000)
99+
100+
if gns.TotalSupply()+toGive <= MAXIMUM_SUPPLY {
101+
gns.Mint(caller, 1_000_000_000_000)
102+
}
99103
}
100104

101105
// administration.
102106
func Mint(address users.AddressOrName, amount uint64) {
103107
caller := std.PrevRealm().Addr()
104108
assertIsAdmin(caller)
105-
gns.Mint(address.Resolve(), amount)
109+
110+
if gns.TotalSupply()+amount <= MAXIMUM_SUPPLY {
111+
gns.Mint(address.Resolve(), amount)
112+
}
106113
}
107114

108115
func Burn(address users.AddressOrName, amount uint64) {

consts/consts.gno

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
// GNOSWAP SERVICE
88
const (
99
GNOSWAP_ADMIN std.Address = "g12l9splsyngcgefrwa52x5a7scc29e9v086m6p4" // GSA, r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK
10-
INTERNAL_REWARD_ACCOUNT std.Address = "g1paqttvcjcluuya9n9twyw7yacv54mt7ld3gvzm"
10+
INTERNAL_REWARD_ACCOUNT std.Address = "g1paqttvcjcluuya9n9twyw7yacv54mt7ld3gvzm" // IRA, r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK
1111

1212
// 500 GNS as creation fee (r3v4_xxx: 500 or 500_000_000)
1313
POOL_CREATION_FEE uint64 = 500

pool/pool_manager.gno

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ func CreatePool(
5757
requireExist(!exist, ufmt.Sprintf("[POOl] pool_manager.gno__CreatePool() || expected poolPath(%s) not to exist", poolPath))
5858

5959
if !exist {
60-
// recipient is same address that receives protocol fee
61-
// r3v4_xxx: change admin address when publish
6260
gns.TransferFrom(a2u(std.GetOrigCaller()), a2u(consts.GNOSWAP_ADMIN), consts.POOL_CREATION_FEE)
6361

6462
pool = newPool(token0Path, token1Path, fee, tickSpacing, sqrtPriceX96)

pool/type.gno

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ type ProtocolFees struct {
2121
token1 bigint
2222
}
2323

24-
type ModifyPositionParams struct { // r3v4_xxx: private?
24+
type ModifyPositionParams struct {
2525
owner std.Address
2626
tickLower int32
2727
tickUpper int32
2828
liquidityDelta bigint
2929
}
3030

31-
type SwapCache struct { // r3v4_xxx: private?
31+
type SwapCache struct {
3232
feeProtocol uint8
3333
liquidityStart bigint
3434
}
3535

36-
type SwapState struct { // r3v4_xxx: private?
36+
type SwapState struct {
3737
amountSpecifiedRemaining bigint
3838
amountCalculated bigint
3939
sqrtPriceX96 bigint
@@ -43,7 +43,7 @@ type SwapState struct { // r3v4_xxx: private?
4343
liquidity bigint
4444
}
4545

46-
type StepComputations struct { // r3v4_xxx: private?
46+
type StepComputations struct {
4747
sqrtPriceStartX96 bigint
4848
tickNext int32
4949
initialized bool

position/liquidity_management.gno

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package position
33
import (
44
"gno.land/p/demo/common"
55

6+
"gno.land/r/demo/consts"
7+
68
pl "gno.land/r/demo/pool"
79
)
810

@@ -27,7 +29,7 @@ func addLiquidity(params AddLiquidityParams) (bigint, bigint, bigint) {
2729
pToken0,
2830
pToken1,
2931
pFee,
30-
params.recipient,
32+
consts.POSITION_ADDR,
3133
params.tickLower,
3234
params.tickUpper,
3335
liquidity,

position/position.gno

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ func mint(params MintParams) (uint64, bigint, bigint, bigint) {
5757
liquidity, amount0, amount1 := addLiquidity(
5858
AddLiquidityParams{
5959
poolKey: pl.GetPoolPath(params.token0, params.token1, params.fee),
60-
recipient: GetOrigPkgAddr(), // hardcoded
6160
tickLower: params.tickLower,
6261
tickUpper: params.tickUpper,
6362
amount0Desired: params.amount0Desired,
@@ -127,7 +126,6 @@ func increaseLiquidity(params IncreaseLiquidityParams) (uint64, bigint, bigint,
127126
liquidity, amount0, amount1 := addLiquidity(
128127
AddLiquidityParams{
129128
poolKey: position.poolKey,
130-
recipient: GetOrigPkgAddr(), // MUST BE POSITION
131129
tickLower: position.tickLower,
132130
tickUpper: position.tickUpper,
133131
amount0Desired: params.amount0Desired,
@@ -275,8 +273,8 @@ func CollectFee(tokenId uint64) (uint64, bigint, bigint, string) { // tokenId, t
275273
GetOrigCaller(),
276274
position.tickLower,
277275
position.tickUpper,
278-
consts.MAX_UINT64, // r3v4_xxx: current grc20 handles amount by `unit64`
279-
consts.MAX_UINT64, // r3v4_xxx: current grc20 handles amount by `unit64`
276+
consts.MAX_UINT64, // r3v4_xxx: current grc20 handles amount by `uint64`
277+
consts.MAX_UINT64, // r3v4_xxx: current grc20 handles amount by `uint64`
280278
)
281279

282280
// r3v4_xxx: DOES THIS NEED FOR COLLECT FEE

position/type.gno

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ type MintParams struct {
3535
amount1Desired bigint
3636
amount0Min bigint
3737
amount1Min bigint
38-
// recipient std.Address // XXX de facto: hardcoded to nft manager contract address
39-
deadline bigint
38+
deadline bigint
4039
}
4140

4241
type AddLiquidityParams struct {
4342
poolKey string
44-
recipient std.Address // XXX de facto: hardcoded to nft manager contract address
4543
tickLower int32
4644
tickUpper int32
4745
amount0Desired bigint

router/_TEST_INIT_basic_test.gno

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func init() {
5656

5757
wugnot.Approve(a2u(consts.POOL_ADDR), 500_000_000_000_000)
5858

59-
std.TestSetPrevAddr(consts.INTERNAL_REWARD_ACCOUNT) // r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK
59+
std.TestSetPrevAddr(consts.INTERNAL_REWARD_ACCOUNT)
6060
gns.Approve(a2u(consts.STAKER_ADDR), 500_000_000_000_000) // to create internal incentive
6161
}
6262

router/comptue_routes.gno

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,16 @@ func _computeAllRoutes(
5555

5656
routes := []BuildRoute{}
5757

58+
tokenVisited := make(map[string]bool, 0)
59+
tokenVisited[inputTokenPath] = true
60+
5861
computeRoutes(
5962
inputTokenPath,
6063
outputTokenPath,
6164
[]PoolWithMeta{}, // currentRoute
6265
poolUsed,
63-
[]string{inputTokenPath}, // tokenVisited
64-
"", // _previousTokenOut
66+
tokenVisited, // tokenVisited
67+
"", // _previousTokenOut
6568
//
6669
maxHops,
6770
pools,
@@ -77,9 +80,8 @@ func computeRoutes(
7780
outputTokenPath string,
7881
currentRoute []PoolWithMeta,
7982
poolsUsed []bool,
80-
tokenVisited []string, // r3v4_xxx: could be map
83+
tokenVisited map[string]bool,
8184
_previousTokenOut string,
82-
//
8385
maxHops int,
8486
pools []PoolWithMeta,
8587
routes *[]BuildRoute,
@@ -125,11 +127,11 @@ func computeRoutes(
125127
currentTokenOut = curPool.token0Path
126128
}
127129

128-
if isStringInStringArr(tokenVisited, currentTokenOut) {
130+
if tokenVisited[currentTokenOut] {
129131
continue
130132
}
131133

132-
tokenVisited = append(tokenVisited, currentTokenOut)
134+
tokenVisited[currentTokenOut] = true
133135
currentRoute = append(currentRoute, curPool)
134136
poolsUsed[i] = true
135137

@@ -149,7 +151,8 @@ func computeRoutes(
149151

150152
poolsUsed[i] = false
151153
currentRoute = currentRoute[:len(currentRoute)-1]
152-
tokenVisited = removeStringFromStringArr(tokenVisited, currentTokenOut)
154+
155+
delete(tokenVisited, currentTokenOut)
153156
}
154157

155158
return routes

router/type.gno

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ const (
1010
ExactOut SwapType = "EXACT_OUT"
1111
)
1212

13-
// PRICE
14-
type SwapPaths map[int]string
15-
type TokenPairs map[string][]string
16-
type QuoterTarget struct {
17-
pct int
18-
pctAmount bigint
19-
targetPath string
20-
resultRatioX96 bigint
21-
}
22-
2313
// SINGLE SWAP
2414
type SingleSwapParams struct {
2515
tokenIn string
@@ -45,19 +35,3 @@ type SwapCallbackData struct {
4535

4636
payer std.Address
4737
}
48-
49-
// QueryPool
50-
type QueryPool struct {
51-
PoolPath string `json:"pool_path"`
52-
Token0Path string `json:"token0_path"`
53-
Token1Path string `json:"token1_path"`
54-
Token0Balance bigint `json:"token0_balance"`
55-
Token1Balance bigint `json:"token1_balance"`
56-
Fee uint16 `json:"fee"`
57-
TickSpacing int32 `json:"tick_spacing"`
58-
CurrentTick int32 `json:"current_tick"`
59-
FeeGrowthGlobal0X128 bigint `json:"fee_growth_global0_x128"`
60-
FeeGrowthGlobal1X128 bigint `json:"fee_growth_global1_x128"`
61-
SqrtPriceX96 bigint `json:"sqrt_price_x96"`
62-
Liquidity bigint `json:"liquidity"`
63-
}

staker/_TEST_INIT_basic_test.gno

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ func init() {
5757

5858
wugnot.Approve(a2u(consts.POOL_ADDR), 500_000_000_000_000)
5959

60-
std.TestSetPrevAddr(std.Address("g1paqttvcjcluuya9n9twyw7yacv54mt7ld3gvzm")) // IRA, r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK
61-
gns.Approve(a2u(consts.STAKER_ADDR), 500_000_000_000_000) // to create internal incentive
60+
std.TestSetPrevAddr(consts.INTERNAL_REWARD_ACCOUNT)
61+
gns.Approve(a2u(consts.STAKER_ADDR), 500_000_000_000_000) // to create internal incentive
6262
}
6363

6464
/* HELPER */

0 commit comments

Comments
 (0)