Skip to content

Commit

Permalink
Merge pull request #179 from gnoswap-labs/GSW-877-feat-implement-some…
Browse files Browse the repository at this point in the history
…-todos

GSW-877 feat: implement some todos
  • Loading branch information
notJoon authored Feb 26, 2024
2 parents afd1752 + ccf3714 commit c88f1f9
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 118 deletions.
39 changes: 23 additions & 16 deletions _setup/gns/gns.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,28 @@ import (
"gno.land/p/demo/grc/grc20"
"gno.land/p/demo/ufmt"
"gno.land/r/demo/users"

"gno.land/r/demo/consts"
)

const MAXIMUM_SUPPLY = uint64(1_000_000_000_000_000)

var (
gns *grc20.AdminToken
admins []string
)

const (
admin std.Address = "g12l9splsyngcgefrwa52x5a7scc29e9v086m6p4" // GSA, r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK
INTERNAL_REWARD_ACCOUNT std.Address = "g1paqttvcjcluuya9n9twyw7yacv54mt7ld3gvzm" // IRA, r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK
)

func init() {
// r3v4_xxx: SET MAXIMUM SUPPLY

gns = grc20.NewAdminToken("Gnoswap", "GNS", 6)
// gns.Mint(admin, 100_000_000_000_000) // @administrator
gns.Mint(INTERNAL_REWARD_ACCOUNT, 400_000_000_000_000) // @INTERNAL_REWARD_ACCOUNT
gns.Mint(std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"), 100_000_000_000) // default test1
gns.Mint(consts.INTERNAL_REWARD_ACCOUNT, 500_000_000_000_000)

gns.Mint(std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"), 100_000_000_000) // r3v4_xxx: default test1

stakerAddr := std.DerivePkgAddr("gno.land/r/demo/staker") // r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK
stakerAddr := consts.GOV_ADDR
admins = append(admins, string(stakerAddr))
admins = append(admins, string(admin))
admins = append(admins, string(consts.GNOSWAP_ADMIN))

gns.Approve(INTERNAL_REWARD_ACCOUNT, stakerAddr, 9_223_372_036_854_775_807) // max uint64
gns.Approve(consts.INTERNAL_REWARD_ACCOUNT, stakerAddr, uint64(consts.MAX_UINT64))
}

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

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

func FaucetL() { // r3v4_xxx: REMOVE FAUCET WHEN DEPLOYING TO OFFICIAL NETWORK
toGive := uint64(1_000_000 * 1_000_000) // 1M
caller := std.PrevRealm().Addr()
gns.Mint(caller, 1_000_000_000_000)

if gns.TotalSupply()+toGive <= MAXIMUM_SUPPLY {
gns.Mint(caller, 1_000_000_000_000)
}
}

// administration.
func Mint(address users.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
assertIsAdmin(caller)
gns.Mint(address.Resolve(), amount)

if gns.TotalSupply()+amount <= MAXIMUM_SUPPLY {
gns.Mint(address.Resolve(), amount)
}
}

func Burn(address users.AddressOrName, amount uint64) {
Expand Down
2 changes: 1 addition & 1 deletion consts/consts.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
// GNOSWAP SERVICE
const (
GNOSWAP_ADMIN std.Address = "g12l9splsyngcgefrwa52x5a7scc29e9v086m6p4" // GSA, r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK
INTERNAL_REWARD_ACCOUNT std.Address = "g1paqttvcjcluuya9n9twyw7yacv54mt7ld3gvzm"
INTERNAL_REWARD_ACCOUNT std.Address = "g1paqttvcjcluuya9n9twyw7yacv54mt7ld3gvzm" // IRA, r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK

// 500 GNS as creation fee (r3v4_xxx: 500 or 500_000_000)
POOL_CREATION_FEE uint64 = 500
Expand Down
2 changes: 0 additions & 2 deletions pool/pool_manager.gno
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ func CreatePool(
requireExist(!exist, ufmt.Sprintf("[POOl] pool_manager.gno__CreatePool() || expected poolPath(%s) not to exist", poolPath))

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

pool = newPool(token0Path, token1Path, fee, tickSpacing, sqrtPriceX96)
Expand Down
8 changes: 4 additions & 4 deletions pool/type.gno
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ type ProtocolFees struct {
token1 bigint
}

type ModifyPositionParams struct { // r3v4_xxx: private?
type ModifyPositionParams struct {
owner std.Address
tickLower int32
tickUpper int32
liquidityDelta bigint
}

type SwapCache struct { // r3v4_xxx: private?
type SwapCache struct {
feeProtocol uint8
liquidityStart bigint
}

type SwapState struct { // r3v4_xxx: private?
type SwapState struct {
amountSpecifiedRemaining bigint
amountCalculated bigint
sqrtPriceX96 bigint
Expand All @@ -43,7 +43,7 @@ type SwapState struct { // r3v4_xxx: private?
liquidity bigint
}

type StepComputations struct { // r3v4_xxx: private?
type StepComputations struct {
sqrtPriceStartX96 bigint
tickNext int32
initialized bool
Expand Down
4 changes: 3 additions & 1 deletion position/liquidity_management.gno
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package position
import (
"gno.land/p/demo/common"

"gno.land/r/demo/consts"

pl "gno.land/r/demo/pool"
)

Expand All @@ -27,7 +29,7 @@ func addLiquidity(params AddLiquidityParams) (bigint, bigint, bigint) {
pToken0,
pToken1,
pFee,
params.recipient,
consts.POSITION_ADDR,
params.tickLower,
params.tickUpper,
liquidity,
Expand Down
6 changes: 2 additions & 4 deletions position/position.gno
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func mint(params MintParams) (uint64, bigint, bigint, bigint) {
liquidity, amount0, amount1 := addLiquidity(
AddLiquidityParams{
poolKey: pl.GetPoolPath(params.token0, params.token1, params.fee),
recipient: GetOrigPkgAddr(), // hardcoded
tickLower: params.tickLower,
tickUpper: params.tickUpper,
amount0Desired: params.amount0Desired,
Expand Down Expand Up @@ -127,7 +126,6 @@ func increaseLiquidity(params IncreaseLiquidityParams) (uint64, bigint, bigint,
liquidity, amount0, amount1 := addLiquidity(
AddLiquidityParams{
poolKey: position.poolKey,
recipient: GetOrigPkgAddr(), // MUST BE POSITION
tickLower: position.tickLower,
tickUpper: position.tickUpper,
amount0Desired: params.amount0Desired,
Expand Down Expand Up @@ -275,8 +273,8 @@ func CollectFee(tokenId uint64) (uint64, bigint, bigint, string) { // tokenId, t
GetOrigCaller(),
position.tickLower,
position.tickUpper,
consts.MAX_UINT64, // r3v4_xxx: current grc20 handles amount by `unit64`
consts.MAX_UINT64, // r3v4_xxx: current grc20 handles amount by `unit64`
consts.MAX_UINT64, // r3v4_xxx: current grc20 handles amount by `uint64`
consts.MAX_UINT64, // r3v4_xxx: current grc20 handles amount by `uint64`
)

// r3v4_xxx: DOES THIS NEED FOR COLLECT FEE
Expand Down
4 changes: 1 addition & 3 deletions position/type.gno
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ type MintParams struct {
amount1Desired bigint
amount0Min bigint
amount1Min bigint
// recipient std.Address // XXX de facto: hardcoded to nft manager contract address
deadline bigint
deadline bigint
}

type AddLiquidityParams struct {
poolKey string
recipient std.Address // XXX de facto: hardcoded to nft manager contract address
tickLower int32
tickUpper int32
amount0Desired bigint
Expand Down
2 changes: 1 addition & 1 deletion router/_TEST_INIT_basic_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func init() {

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

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

Expand Down
17 changes: 10 additions & 7 deletions router/comptue_routes.gno
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,16 @@ func _computeAllRoutes(

routes := []BuildRoute{}

tokenVisited := make(map[string]bool, 0)
tokenVisited[inputTokenPath] = true

computeRoutes(
inputTokenPath,
outputTokenPath,
[]PoolWithMeta{}, // currentRoute
poolUsed,
[]string{inputTokenPath}, // tokenVisited
"", // _previousTokenOut
tokenVisited, // tokenVisited
"", // _previousTokenOut
//
maxHops,
pools,
Expand All @@ -77,9 +80,8 @@ func computeRoutes(
outputTokenPath string,
currentRoute []PoolWithMeta,
poolsUsed []bool,
tokenVisited []string, // r3v4_xxx: could be map
tokenVisited map[string]bool,
_previousTokenOut string,
//
maxHops int,
pools []PoolWithMeta,
routes *[]BuildRoute,
Expand Down Expand Up @@ -125,11 +127,11 @@ func computeRoutes(
currentTokenOut = curPool.token0Path
}

if isStringInStringArr(tokenVisited, currentTokenOut) {
if tokenVisited[currentTokenOut] {
continue
}

tokenVisited = append(tokenVisited, currentTokenOut)
tokenVisited[currentTokenOut] = true
currentRoute = append(currentRoute, curPool)
poolsUsed[i] = true

Expand All @@ -149,7 +151,8 @@ func computeRoutes(

poolsUsed[i] = false
currentRoute = currentRoute[:len(currentRoute)-1]
tokenVisited = removeStringFromStringArr(tokenVisited, currentTokenOut)

delete(tokenVisited, currentTokenOut)
}

return routes
Expand Down
26 changes: 0 additions & 26 deletions router/type.gno
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ const (
ExactOut SwapType = "EXACT_OUT"
)

// PRICE
type SwapPaths map[int]string
type TokenPairs map[string][]string
type QuoterTarget struct {
pct int
pctAmount bigint
targetPath string
resultRatioX96 bigint
}

// SINGLE SWAP
type SingleSwapParams struct {
tokenIn string
Expand All @@ -45,19 +35,3 @@ type SwapCallbackData struct {

payer std.Address
}

// QueryPool
type QueryPool struct {
PoolPath string `json:"pool_path"`
Token0Path string `json:"token0_path"`
Token1Path string `json:"token1_path"`
Token0Balance bigint `json:"token0_balance"`
Token1Balance bigint `json:"token1_balance"`
Fee uint16 `json:"fee"`
TickSpacing int32 `json:"tick_spacing"`
CurrentTick int32 `json:"current_tick"`
FeeGrowthGlobal0X128 bigint `json:"fee_growth_global0_x128"`
FeeGrowthGlobal1X128 bigint `json:"fee_growth_global1_x128"`
SqrtPriceX96 bigint `json:"sqrt_price_x96"`
Liquidity bigint `json:"liquidity"`
}
4 changes: 2 additions & 2 deletions staker/_TEST_INIT_basic_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func init() {

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

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

/* HELPER */
Expand Down
Loading

0 comments on commit c88f1f9

Please sign in to comment.