Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polygon: add wbtc and weth tokens #2522

Merged
merged 4 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 34 additions & 11 deletions client/asset/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ type monitoredTx struct {
// replacedTx could be set when the tx is created, be immutable, and not
// need the mutex, but since Redeem doesn't know if the transaction is a
// replacement or a new one, this variable is set in recordReplacementTx.
replacedTx *common.Hash
replacedTx *common.Hash
errorsBroadcasted uint16
}

// MarshalBinary marshals a monitoredTx into a byte array.
Expand Down Expand Up @@ -3235,8 +3236,13 @@ func (w *assetWallet) SwapConfirmations(ctx context.Context, coinID dex.Bytes, c
}

spent = swapData.State >= dexeth.SSRedeemed
confs = uint32(hdr.Number.Uint64() - swapData.BlockHeight + 1)

tip := hdr.Number.Uint64()
// TODO: If tip < swapData.BlockHeight (which has been observed), what does
// that mean? Are we using the wrong provider in a multi-provider setup? How
// do we resolve provider relevance?
if tip >= swapData.BlockHeight {
confs = uint32(hdr.Number.Uint64() - swapData.BlockHeight + 1)
}
return
}

Expand Down Expand Up @@ -3763,6 +3769,8 @@ func (w *assetWallet) resubmitRedemption(tx *types.Transaction, contractVersion
var replacementHash common.Hash
copy(replacementHash[:], txs[0])

w.log.Infof("Redemption transaction %s was broadcast to replace transaction %s (original tx: %s)", replacementHash, monitoredTx.tx.Hash(), tx.Hash())

if monitoredTx != nil {
err = w.recordReplacementTx(monitoredTx, replacementHash)
if err != nil {
Expand Down Expand Up @@ -4041,11 +4049,27 @@ func (w *assetWallet) confirmRedemption(coinID dex.Bytes, redemption *asset.Rede
w.clearMonitoredTx(monitoredTx)
return confStatus(txConfsNeededToConfirm, txHash), nil
}
replacementTxHash, err := w.resubmitRedemption(tx, contractVer, nil, feeWallet, monitoredTx)
if err != nil {
return nil, err

w.log.Errorf("Redemption transaction rejected!!! Tx %s failed to redeem %s funds", tx.Hash(), dex.BipIDSymbol(w.assetID))
// Only broadcast a single replacement before giving up.
if monitoredTx.replacedTx == nil {
w.log.Infof("Attempting to resubmit a %s redemption with secret hash %s", dex.BipIDSymbol(w.assetID), hex.EncodeToString(secretHash[:]))
replacementTxHash, err := w.resubmitRedemption(tx, contractVer, nil, feeWallet, monitoredTx)
if err != nil {
return nil, err
}
return confStatus(0, *replacementTxHash), nil
}
return confStatus(0, *replacementTxHash), nil
// We've failed to redeem twice. We can't keep broadcasting txs into the
// void. We have to give up. Print a bunch of errors and then report
// the redemption as confirmed so we'll stop following it.
if monitoredTx.errorsBroadcasted < 100 {
monitoredTx.errorsBroadcasted++
return nil, fmt.Errorf("failed to redeem %s swap with secret hash %s twice. not trying again",
dex.BipIDSymbol(w.assetID), hex.EncodeToString(secretHash[:]))
}
const aTonOfFakeConfs = 1e3
return confStatus(aTonOfFakeConfs, txHash), nil
}
if confirmations > 0 {
return confStatus(confirmations, txHash), nil
Expand Down Expand Up @@ -4637,10 +4661,9 @@ func getFileCredentials(chain, path string, net dex.Network) (seed []byte, provi
}
seed = p.Seed
for _, uri := range p.Providers[chain][net.String()] {
if strings.HasPrefix(uri, "#") || strings.HasPrefix(uri, ";") {
continue
if !strings.HasPrefix(uri, "#") && !strings.HasPrefix(uri, ";") {
providers = append(providers, uri)
}
providers = append(providers, uri)
}
if net == dex.Simnet && len(providers) == 0 {
u, _ := user.Current()
Expand Down Expand Up @@ -5319,7 +5342,7 @@ func getGasEstimates(ctx context.Context, cl, acl ethFetcher, c contractor, ac t
copy(randomAddr[:], encode.RandomBytes(20))
transferTx, err := tc.transfer(txOpts, randomAddr, big.NewInt(1))
if err != nil {
return fmt.Errorf("error estimating transfer gas: %w", err)
return fmt.Errorf("transfer error: %w", err)
}
if err = waitForConfirmation(ctx, cl, transferTx.Hash()); err != nil {
return fmt.Errorf("error waiting for transfer tx: %w", err)
Expand Down
4 changes: 4 additions & 0 deletions client/asset/polygon/polygon.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func init() {
asset.Register(BipID, &Driver{})
registerToken(simnetTokenID, "A token wallet for the DEX test token. Used for testing DEX software.", dex.Simnet)
registerToken(usdcTokenID, "The USDC Ethereum ERC20 token.", dex.Mainnet, dex.Testnet)
registerToken(wbtcTokenID, "Wrapped BTC.", dex.Mainnet)
registerToken(wethTokenID, "Wrapped ETH.", dex.Mainnet)
}

const (
Expand All @@ -43,6 +45,8 @@ const (
var (
simnetTokenID, _ = dex.BipSymbolID("dextt.polygon")
usdcTokenID, _ = dex.BipSymbolID("usdc.polygon")
wethTokenID, _ = dex.BipSymbolID("weth.polygon")
wbtcTokenID, _ = dex.BipSymbolID("wbtc.polygon")
// WalletInfo defines some general information about a Polygon Wallet(EVM
// Compatible).

Expand Down
2 changes: 1 addition & 1 deletion client/webserver/site/src/html/bodybuilder.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
{{end}}

{{define "bottom"}}
<script src="/js/entry.js?v=be17df38|cdcbc806"></script>
<script src="/js/entry.js?v=c57a0c0c|dce53427"></script>
</body>
</html>
{{end}}
Binary file added client/webserver/site/src/img/coins/wbtc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/webserver/site/src/img/coins/wbtc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/webserver/site/src/img/coins/weth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/webserver/site/src/img/coins/weth.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion client/webserver/site/src/js/doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const BipIDs: Record<number, string> = {
60000: 'dextt.eth',
60001: 'usdc.eth',
966000: 'dextt.polygon',
966001: 'usdc.polygon'
966001: 'usdc.polygon',
966002: 'weth.polygon',
966003: 'wbtc.polygon'
}

const BipSymbolIDs: Record<string, number> = {};
Expand Down
2 changes: 2 additions & 0 deletions dex/bip-id.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,8 @@ var bipIDs = map[uint32]string{
// Polygon reserved token range 966000-966999
966000: "dextt.polygon",
966001: "usdc.polygon",
966002: "weth.polygon",
966003: "wbtc.polygon",
// END Polygon reserved token range
1171337: "ilt",
1313114: "etho",
Expand Down
Loading