Skip to content

Commit 8d00b1b

Browse files
feat: add syrupUSDC and syrupUSDT (#1141)
* Add custom exchange name * Add custom approval address for erc4626
1 parent ce4c644 commit 8d00b1b

File tree

7 files changed

+35
-6
lines changed

7 files changed

+35
-6
lines changed

pkg/liquidity-source/erc4626/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ type Config struct {
66
}
77

88
type VaultCfg struct {
9-
Gas GasCfg `json:"gas"`
10-
SwapTypes SwapType `json:"swapTypes"`
9+
Gas GasCfg `json:"gas"`
10+
SwapTypes SwapType `json:"swapTypes"`
11+
Meta map[string]any `json:"meta,omitempty"`
1112
}
1213

1314
type GasCfg struct {

pkg/liquidity-source/erc4626/constant.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
const (
1414
DexType = "erc4626"
1515

16+
ExchangeMetaKey = "exchange"
17+
1618
erc4626MethodAsset = "asset"
1719
erc4626MethodMaxDeposit = "maxDeposit"
1820
erc4626MethodMaxRedeem = "maxRedeem"

pkg/liquidity-source/erc4626/pool_simulator.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package erc4626
33
import (
44
"math/big"
55

6+
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/valueobject"
67
"github.com/goccy/go-json"
78
"github.com/holiman/uint256"
89
"github.com/pkg/errors"
@@ -151,7 +152,10 @@ func (s *PoolSimulator) UpdateBalance(params pool.UpdateBalanceParams) {
151152
}
152153

153154
func (s *PoolSimulator) GetMetaInfo(_, _ string) interface{} {
154-
return Meta{BlockNumber: s.Info.BlockNumber}
155+
return MetaInfo{
156+
Meta: s.Meta,
157+
BlockNumber: s.Info.BlockNumber,
158+
}
155159
}
156160

157161
func (s *PoolSimulator) CanSwapTo(address string) []string {
@@ -200,3 +204,12 @@ func (s *PoolSimulator) getSwapType(tokenIn string, tokenOut string) (SwapType,
200204

201205
return swapType, nil
202206
}
207+
208+
func (s *PoolSimulator) GetApprovalAddress(_, _ string) string {
209+
switch s.GetExchange() {
210+
case valueobject.ExchangeMapleSyrup:
211+
return s.Meta["router"].(string)
212+
default:
213+
return s.GetAddress()
214+
}
215+
}

pkg/liquidity-source/erc4626/pool_tracker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func updateEntityState(p *entity.Pool, vaultCfg VaultCfg, state *PoolState) erro
9494
MaxRedeem: uint256.MustFromBig(state.MaxRedeem),
9595
DepositRates: lo.Map(state.DepositRates, func(item *big.Int, _ int) *uint256.Int { return uint256.MustFromBig(item) }),
9696
RedeemRates: lo.Map(state.RedeemRates, func(item *big.Int, _ int) *uint256.Int { return uint256.MustFromBig(item) }),
97+
Meta: vaultCfg.Meta,
9798
})
9899
if err != nil {
99100
return errors.WithMessage(err, "json.Marshal extra")

pkg/liquidity-source/erc4626/pools_list_updater.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,22 @@ func (u *PoolsListUpdater) getNewPool(ctx context.Context, vaultAddr string, vau
7676
return nil, err
7777
}
7878

79+
exchange := u.cfg.DexId
80+
if vaultCfg.Meta != nil {
81+
if exchangeStr, ok := vaultCfg.Meta[ExchangeMetaKey].(string); ok && exchangeStr != "" {
82+
exchange = exchangeStr
83+
}
84+
}
85+
7986
p := &entity.Pool{
8087
Address: strings.ToLower(vaultAddr),
81-
Exchange: u.cfg.DexId,
88+
Exchange: exchange,
8289
Type: DexType,
8390
Tokens: []*entity.PoolToken{
8491
{Address: strings.ToLower(vaultAddr), Swappable: true},
8592
{Address: hexutil.Encode(assetToken[:]), Swappable: true},
8693
},
8794
}
95+
8896
return p, updateEntityState(p, vaultCfg, state)
8997
}

pkg/liquidity-source/erc4626/type.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ type (
2828
MaxRedeem *uint256.Int `json:"mR,omitempty"`
2929
DepositRates []*uint256.Int `json:"dR,omitempty"`
3030
RedeemRates []*uint256.Int `json:"rR,omitempty"`
31+
Meta map[string]any `json:"meta,omitempty"`
3132
}
3233

33-
Meta struct {
34-
BlockNumber uint64 `json:"blockNumber"`
34+
MetaInfo struct {
35+
Meta map[string]any `json:"meta,omitempty"`
36+
BlockNumber uint64 `json:"blockNumber"`
3537
}
3638

3739
PoolState struct {

pkg/valueobject/exchange.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ const (
232232
ExchangeLynex = "lynex"
233233
ExchangeLynexV1 = "lynex-v1"
234234
ExchangeLyve = "lyve"
235+
ExchangeMapleSyrup = "maple-syrup"
235236
ExchangeMDex = "mdex"
236237
ExchangeMMF = "mmf"
237238
ExchangeMMFV3 = "mmf-v3"
@@ -713,6 +714,7 @@ var AMMSourceSet = map[Exchange]struct{}{
713714
ExchangeLynex: {},
714715
ExchangeLynexV1: {},
715716
ExchangeLyve: {},
717+
ExchangeMapleSyrup: {},
716718
ExchangeMDex: {},
717719
ExchangeMMF: {},
718720
ExchangeMMFV3: {},

0 commit comments

Comments
 (0)