Skip to content

Commit

Permalink
add wbtc and weth tokens to polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed Sep 12, 2023
1 parent 1794151 commit 85e6474
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 4 deletions.
10 changes: 8 additions & 2 deletions client/asset/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3737,6 +3737,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 @@ -4535,7 +4537,11 @@ func getFileCredentials(chain, path string, net dex.Network) (seed []byte, provi
return nil, nil, fmt.Errorf("must provide both seeds in credentials file")
}
seed = p.Seed
providers = p.Providers[chain][net.String()]
for _, uri := range p.Providers[chain][net.String()] {
if !strings.HasPrefix(uri, "#") && !strings.HasPrefix(uri, ";") {
providers = append(providers, uri)
}
}
if net == dex.Simnet && len(providers) == 0 {
u, _ := user.Current()
switch chain {
Expand Down Expand Up @@ -5213,7 +5219,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=faadd923|2e83f47d"></script>
<script src="/js/entry.js?v=ffd2f4d9|cf0a1389"></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 BipSymbols = Object.values(BipIDs)
Expand Down
2 changes: 2 additions & 0 deletions dex/bip-id.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,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
101 changes: 101 additions & 0 deletions dex/networks/polygon/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ var (

testTokenID, _ = dex.BipSymbolID("dextt.polygon")
usdcTokenID, _ = dex.BipSymbolID("usdc.polygon")
wethTokenID, _ = dex.BipSymbolID("weth.polygon")
wbtcTokenID, _ = dex.BipSymbolID("wbtc.polygon")

Tokens = map[uint32]*dexeth.Token{
testTokenID: {
Expand Down Expand Up @@ -179,6 +181,105 @@ var (
},
},
},
wethTokenID: TokenWETH,
wbtcTokenID: TokenWBTC,
}

// Wrapped ETH
TokenWETH = &dexeth.Token{
Token: &dex.Token{
ParentID: PolygonBipID,
Name: "WETH",
UnitInfo: dex.UnitInfo{
AtomicUnit: "gwei",
Conventional: dex.Denomination{
Unit: "WETH",
ConversionFactor: 1e9,
},
},
},
NetTokens: map[dex.Network]*dexeth.NetToken{
dex.Mainnet: {
Address: common.HexToAddress("0x7ceb23fd6bc0add59e62ac25578270cff1b9f619"), // https://polygonscan.com/token/0x7ceb23fd6bc0add59e62ac25578270cff1b9f619
SwapContracts: map[uint32]*dexeth.SwapContract{
0: {
// deploy tx: https://polygonscan.com/tx/0xc569774add0a9f41eace3ff6289eafd4c17fbcaafcf8b7758e0a5c4d74dcf307
// swap contract: https://polygonscan.com/address/0x878dF60d47Afa9C665dFaDCB6BF4e303C080032f
Address: common.HexToAddress("0x878dF60d47Afa9C665dFaDCB6BF4e303C080032f"),
Gas: dexeth.Gases{
// First swap used 158846 gas Recommended Gases.Swap = 206499
// 4 additional swaps averaged 112618 gas each. Recommended Gases.SwapAdd = 146403
// [158846 271461 384064 496691 609318]
Swap: 206_499,
SwapAdd: 146_403,
// First redeem used 70222 gas. Recommended Gases.Redeem = 91288
// 4 additional redeems averaged 31629 gas each. recommended Gases.RedeemAdd = 41117
// [70222 101851 133468 165110 196739]
Redeem: 91_288,
RedeemAdd: 41_117,
// Average of 5 refunds: 50354. Recommended Gases.Refund = 65460
// [50350 50362 50338 50362 50362]
Refund: 65_460,
// Average of 2 approvals: 36762. Recommended Gases.Approve = 47790
// [46712 26812]
Approve: 47_790,
// Average of 1 transfers: 51910. Recommended Gases.Transfer = 67483
// [51910]
Transfer: 67_483,
},
},
},
},
},
}

// Wrapped BTC
TokenWBTC = &dexeth.Token{
EVMFactor: new(int64),
Token: &dex.Token{
ParentID: PolygonBipID,
Name: "Wrapped Bitcoin",
UnitInfo: dex.UnitInfo{
AtomicUnit: "Sats",
Conventional: dex.Denomination{
Unit: "WBTC",
ConversionFactor: 1e8,
},
},
},
NetTokens: map[dex.Network]*dexeth.NetToken{
dex.Mainnet: {
Address: common.HexToAddress("0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6"), // https://polygonscan.com/token/0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6
SwapContracts: map[uint32]*dexeth.SwapContract{
0: {
// deploy tx: https://polygonscan.com/tx/0xcd84a1fa2f890d5fc1fcb0dde6c5a3bb50d9b25927ec5666b96b5ad3d6902b0a
// swap contract: https://polygonscan.com/address/0x625B7Ecd21B25b0808c4221dA281CD3A82f8b797
Address: common.HexToAddress("0x625B7Ecd21B25b0808c4221dA281CD3A82f8b797"),
Gas: dexeth.Gases{
// First swap used 181278 gas Recommended Gases.Swap = 235661
// 4 additional swaps averaged 112591 gas each. Recommended Gases.SwapAdd = 146368
// [181278 293857 406460 519039 631642]
Swap: 235_661,
SwapAdd: 146_368,
// First redeem used 70794 gas. Recommended Gases.Redeem = 92032
// 4 additional redeems averaged 31629 gas each. recommended Gases.RedeemAdd = 41117
// [70794 102399 134052 165646 197311]
Redeem: 92_032,
RedeemAdd: 41_117,
// Average of 5 refunds: 63126. Recommended Gases.Refund = 82063
// [63126 63126 63126 63126 63126]
Refund: 82_063,
// Average of 2 approvals: 52072. Recommended Gases.Approve = 67693
// [52072 52072]
Approve: 67_693,
// Average of 1 transfers: 57270. Recommended Gases.Transfer = 74451
// [57270]
Transfer: 74_451,
},
},
},
},
},
}
)

Expand Down
4 changes: 4 additions & 0 deletions server/asset/polygon/polygon.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func init() {

registerToken(testTokenID, 0)
registerToken(usdcID, 0)
registerToken(wethTokenID, 0)
registerToken(wbtcTokenID, 0)

if blockPollIntervalStr != "" {
blockPollInterval, _ = time.ParseDuration(blockPollIntervalStr)
Expand All @@ -61,6 +63,8 @@ const (
var (
testTokenID, _ = dex.BipSymbolID("dextt.polygon")
usdcID, _ = dex.BipSymbolID("usdc.polygon")
wethTokenID, _ = dex.BipSymbolID("weth.polygon")
wbtcTokenID, _ = dex.BipSymbolID("wbtc.polygon")

// blockPollInterval is the delay between calls to bestBlockHash to check
// for new blocks. Modify at compile time via blockPollIntervalStr:
Expand Down

0 comments on commit 85e6474

Please sign in to comment.