Skip to content

Commit

Permalink
feat: migrate to new icy (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
baenv authored Mar 25, 2024
1 parent 2e12774 commit e3d4f55
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 35 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/discord/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (c *controller) PublishIcyActivityLog() error {
ActionList: []mochipay.TransactionAction{mochipay.TransactionActionVaultTransfer},
Type: mochipay.TransactionTypeReceive,
TokenAddress: mochipay.ICYAddress,
ChainIDs: []string{mochipay.POLYGONChainID},
ChainIDs: []string{mochipay.BASEChainID},
SortBy: "created_at-", // sort by created_at desc
})
if err != nil {
Expand Down Expand Up @@ -204,7 +204,7 @@ func (c *controller) PublishIcyActivityLog() error {
}

if !strings.EqualFold(txMetadata.VaultRequest.TokenInfo.Address, mochipay.ICYAddress) ||
txMetadata.VaultRequest.TokenInfo.ChainID != mochipay.POLYGONChainID {
txMetadata.VaultRequest.TokenInfo.ChainID != mochipay.BASEChainID {
logger.Info("Skip transaction without ICY token")
continue
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/employee/earns.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (r *controller) GetEmployeeEarnTransactions(discordID string, input GetEmpl
ActionList: []mochipay.TransactionAction{mochipay.TransactionActionVaultTransfer},
Status: mochipay.TransactionStatusSuccess,
TokenAddress: mochipay.ICYAddress,
ChainIDs: []string{mochipay.POLYGONChainID},
ChainIDs: []string{mochipay.BASEChainID},
ProfileID: profile.ID,
Page: input.Page,
Size: input.Size,
Expand All @@ -50,7 +50,7 @@ func (r *controller) GetEmployeeTotalEarn(discordID string) (string, string, err
ActionList: []mochipay.TransactionAction{mochipay.TransactionActionVaultTransfer},
Status: mochipay.TransactionStatusSuccess,
TokenAddress: mochipay.ICYAddress,
ChainIDs: []string{mochipay.POLYGONChainID},
ChainIDs: []string{mochipay.BASEChainID},
ProfileID: profile.ID,
Size: math.MaxInt64,
IsSender: &isSender,
Expand Down Expand Up @@ -95,7 +95,7 @@ func (r *controller) GetTotalEarn(from, to time.Time) (string, string, error) {
ActionList: []mochipay.TransactionAction{mochipay.TransactionActionVaultTransfer},
Status: mochipay.TransactionStatusSuccess,
TokenAddress: mochipay.ICYAddress,
ChainIDs: []string{mochipay.POLYGONChainID},
ChainIDs: []string{mochipay.BASEChainID},
Size: math.MaxInt64,
IsSender: &isSender,
SortBy: "created_at-",
Expand Down
29 changes: 15 additions & 14 deletions pkg/controller/icy/icy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/dwarvesf/fortress-api/pkg/model"
"github.com/dwarvesf/fortress-api/pkg/service"
"github.com/dwarvesf/fortress-api/pkg/service/icyswap"
"github.com/dwarvesf/fortress-api/pkg/service/mochipay"
"github.com/dwarvesf/fortress-api/pkg/service/mochiprofile"
)

Expand Down Expand Up @@ -42,7 +43,7 @@ func (c *controller) Accounting() (*model.IcyAccounting, error) {

// 0.Prepare token and swap contract data
icy := c.icy()
usdt := c.usdt()
usdt := c.usdc()
icySwap := c.icySwap()

// 1.Get current conversion rate from icyswap contract
Expand All @@ -55,7 +56,7 @@ func (c *controller) Accounting() (*model.IcyAccounting, error) {
conversionRateFloat, _ := new(big.Float).Quo(new(big.Float).SetInt(conversionRate), usdtDecimals).Float32()

// 2. Get current usdt fund in icyswap contract
icyswapUsdtBal, err := c.service.IcySwap.UsdtFund()
icyswapUsdtBal, err := c.service.IcySwap.UsdcFund()
if err != nil {
l.Error(err, "failed to get usdt fund in icyswap contract")
return nil, err
Expand Down Expand Up @@ -124,7 +125,7 @@ func (c *controller) lockedIcyAmount() (*big.Int, error) {
func (c *controller) onchainLockedIcyAmount() (*big.Int, error) {
icyAddress := common.HexToAddress(c.icy().Address)
oldIcySwapContractAddr := common.HexToAddress("0xd327b6d878bcd9d5ec6a5bc99445985d75f0d6e5")
icyswapAddr := common.HexToAddress(icyswap.IcySwapAddress)
icyswapAddr := common.HexToAddress(icyswap.ICYSwapAddress)
teamAddr := common.HexToAddress("0x0762c4b40c9cb21Af95192a3Dc3EDd3043CF3d41")
icyLockedAddrs := []common.Address{oldIcySwapContractAddr, icyswapAddr, teamAddr}

Expand Down Expand Up @@ -214,29 +215,29 @@ func (c *controller) icy() model.TokenInfo {
return model.TokenInfo{
Name: "Icy",
Symbol: "ICY",
Address: "0x8D57d71B02d71e1e449a0E459DE40473Eb8f4a90",
Address: mochipay.ICYAddress,
Decimals: 18,
Chain: "Polygon",
ChainID: "137",
Chain: mochipay.BASEChainID,
ChainID: mochipay.BASEChainID,
TotalSupply: "100000000000000000000000",
}
}

func (c *controller) usdt() model.TokenInfo {
func (c *controller) usdc() model.TokenInfo {
return model.TokenInfo{
Name: "Usdt",
Symbol: "USDT",
Address: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
Name: "USD Base Coin",
Symbol: "USDbC",
Address: icyswap.USDCAddress,
Decimals: 6,
Chain: "Polygon",
ChainID: "137",
Chain: mochipay.BaseChainName,
ChainID: mochipay.BASEChainID,
}
}

func (c *controller) icySwap() model.ContractInfo {
return model.ContractInfo{
Name: "IcySwap",
Address: icyswap.IcySwapAddress,
Chain: "Polygon",
Address: icyswap.ICYSwapAddress,
Chain: mochipay.BaseChainName,
}
}
2 changes: 1 addition & 1 deletion pkg/service/evm/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ type RpcClient struct {
}

var (
DefaultPolygonClient = RpcClient{Url: "https://rpc.ankr.com/polygon"}
DefaultBASEClient = RpcClient{Url: "https://mainnet.base.org"}
)
12 changes: 6 additions & 6 deletions pkg/service/icyswap/icyswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

type IService interface {
ConversionRate() (*big.Int, error)
UsdtFund() (*big.Int, error)
UsdcFund() (*big.Int, error)
}

type icyswap struct {
Expand All @@ -24,12 +24,12 @@ type icyswap struct {
}

const (
IcySwapAddress = "0x8De345A73625237223dEDf8c93dfE79A999C17FB"
UsdtAddress = "0xc2132D05D31c914a87C6611C10748AEb04B58e8F"
ICYSwapAddress = "0x982d2c5A654E4f7CC65ACDCa4ECc649fE4F4DAa4"
USDCAddress = "0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA"
)

func New(evm evm.IService, cfg *config.Config, l logger.Logger) (IService, error) {
instance, err := icyswapabi.NewIcySwap(common.HexToAddress(IcySwapAddress), evm.Client())
instance, err := icyswapabi.NewIcySwap(common.HexToAddress(ICYSwapAddress), evm.Client())
if err != nil {
return nil, err
}
Expand All @@ -50,8 +50,8 @@ func (i *icyswap) ConversionRate() (*big.Int, error) {
return rate, nil
}

func (i *icyswap) UsdtFund() (*big.Int, error) {
balance, err := i.evm.ERC20Balance(common.HexToAddress(UsdtAddress), common.HexToAddress(IcySwapAddress))
func (i *icyswap) UsdcFund() (*big.Int, error) {
balance, err := i.evm.ERC20Balance(common.HexToAddress(USDCAddress), common.HexToAddress(ICYSwapAddress))
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/service/mochi/mochi.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/dwarvesf/fortress-api/pkg/config"
"github.com/dwarvesf/fortress-api/pkg/logger"
"github.com/dwarvesf/fortress-api/pkg/service/mochipay"
)

type IService interface {
Expand Down Expand Up @@ -56,7 +57,7 @@ func (c *client) SendFromAccountToUser(amount int, discordID string) ([]model.Tr
txs, err := c.mochiClient.Transfer(&model.TransferRequest{
RecipientIDs: []string{profile.ID},
Amounts: []string{strconv.Itoa(amount)},
TokenID: "941f0fb1-00da-49dc-a538-5e81fc874cb4",
TokenID: mochipay.ICYTokenMochiID,
Description: fmt.Sprintf("%s Addvance Salary in %s", discordID, currentMonth.String()),
References: "Advance Salary",
})
Expand Down
6 changes: 4 additions & 2 deletions pkg/service/mochipay/mochipay.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import (
)

const (
ICYAddress = "0x8D57d71B02d71e1e449a0E459DE40473Eb8f4a90"
POLYGONChainID = "137"
ICYAddress = "0xf289e3b222dd42b185b7e335fa3c5bd6d132441d"
BASEChainID = "8453"
RewardDefaultMsg = "Send money to treasurer"
ICYTokenMochiID = "9d25232e-add3-4bd8-b7c6-be6c14debc58"
BaseChainName = "BASE"
)

type IService interface {
Expand Down
5 changes: 0 additions & 5 deletions pkg/service/mochipay/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import (
"time"
)

const (
PolygonChainID = "137"
ICYContractAddress = "0x8D57d71B02d71e1e449a0E459DE40473Eb8f4a90"
)

type TransactionType string

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func New(cfg *config.Config, store *store.Store, repo store.DBRepo) *Service {

Currency := currency.New(cfg)

polygonClient, err := evm.New(evm.DefaultPolygonClient, cfg, logger.L)
polygonClient, err := evm.New(evm.DefaultBASEClient, cfg, logger.L)
if err != nil {
logger.L.Error(err, "failed to init polygon client service")
}
Expand Down

0 comments on commit e3d4f55

Please sign in to comment.