implement pool limit
This commit is contained in:
parent
e053d561c9
commit
c09cb77e19
26
dev/api.go
26
dev/api.go
@ -309,16 +309,20 @@ func (das *DevAccountService) RegisterPool(ctx context.Context, name string, sm
|
|||||||
z := h.Sum(nil)
|
z := h.Sum(nil)
|
||||||
pooladdr := fmt.Sprintf("0x%x", z)
|
pooladdr := fmt.Sprintf("0x%x", z)
|
||||||
|
|
||||||
|
p := Pool{
|
||||||
|
Name: name,
|
||||||
|
Symbol: sm,
|
||||||
|
Address: pooladdr,
|
||||||
|
PoolLimit: make(map[string]string),
|
||||||
|
}
|
||||||
|
|
||||||
for _, v := range das.vouchers {
|
for _, v := range das.vouchers {
|
||||||
//pre-load vouchers with vouchers when a pool is registered
|
//pre-load vouchers with vouchers when a pool is registered
|
||||||
seedVouchers = append(seedVouchers, v)
|
seedVouchers = append(seedVouchers, v)
|
||||||
|
p.PoolLimit[v.Address] = fmt.Sprintf("%f", defaultVoucherBalance)
|
||||||
}
|
}
|
||||||
p := Pool{
|
p.Vouchers = append(p.Vouchers, seedVouchers...)
|
||||||
Name: name,
|
|
||||||
Symbol: sm,
|
|
||||||
Address: pooladdr,
|
|
||||||
Vouchers: seedVouchers,
|
|
||||||
}
|
|
||||||
err := das.savePoolInfo(ctx, p)
|
err := das.savePoolInfo(ctx, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -509,10 +513,6 @@ func (das *DevAccountService) PoolDeposit(ctx context.Context, amount, from, poo
|
|||||||
return nil, fmt.Errorf("voucher address %v found but does not resolve", tokenAddress)
|
return nil, fmt.Errorf("voucher address %v found but does not resolve", tokenAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
// das.pool.Vouchers = append(das.pool.Vouchers, voucher)
|
|
||||||
// das.pool.PoolLimit = map[string]string{tokenAddress: amount}
|
|
||||||
|
|
||||||
// err = das.savePoolInfo(ctx, das.pool)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -526,15 +526,15 @@ func (das *DevAccountService) GetPoolSwapQuote(ctx context.Context, amount, from
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("account not found (publickey): %v", from)
|
return nil, fmt.Errorf("account not found (publickey): %v", from)
|
||||||
}
|
}
|
||||||
_, ok = das.pools[poolAddress]
|
p, ok := das.pools[poolAddress]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("pool address %v not found", poolAddress)
|
return nil, fmt.Errorf("pool address %v not found", poolAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
//resolve the token address you are trying to swap from(fromTokenAddress)
|
//resolve the token address you are trying to swap from(fromTokenAddress)
|
||||||
_, ok = das.vouchersAddress[fromTokenAddress]
|
ok = p.hasVoucher(fromTokenAddress)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("voucher address %v not found", fromTokenAddress)
|
return nil, fmt.Errorf("voucher with address %v not found in the pool", fromTokenAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Return a a quote that is equal to the amount entered
|
//Return a a quote that is equal to the amount entered
|
||||||
|
Loading…
Reference in New Issue
Block a user