Skip to content

Commit

Permalink
buffer redeem gas for wbtc and usdc
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed Sep 26, 2023
1 parent 773f8e3 commit 01f15fd
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 119 deletions.
9 changes: 7 additions & 2 deletions client/asset/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3236,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
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=ffd2f4d9|cf0a1389"></script>
<script src="/js/entry.js?v=c57a0c0c|dce53427"></script>
</body>
</html>
{{end}}
242 changes: 126 additions & 116 deletions dex/networks/polygon/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,140 +61,146 @@ var (
wbtcTokenID, _ = dex.BipSymbolID("wbtc.polygon")

Tokens = map[uint32]*dexeth.Token{
testTokenID: {
Token: &dex.Token{
ParentID: PolygonBipID,
Name: "DCRDEXTestToken",
UnitInfo: dex.UnitInfo{
AtomicUnit: "Dextoshi",
Conventional: dex.Denomination{
Unit: "DEXTT",
ConversionFactor: dexeth.GweiFactor,
},
testTokenID: TestToken,
usdcTokenID: TokenUSDC,
wethTokenID: TokenWETH,
wbtcTokenID: TokenWBTC,
}

// TestToken is the siment test token
TestToken = &dexeth.Token{
Token: &dex.Token{
ParentID: PolygonBipID,
Name: "DCRDEXTestToken",
UnitInfo: dex.UnitInfo{
AtomicUnit: "Dextoshi",
Conventional: dex.Denomination{
Unit: "DEXTT",
ConversionFactor: dexeth.GweiFactor,
},
},
NetTokens: map[dex.Network]*dexeth.NetToken{
dex.Simnet: {
// ERC20 token contract address. The simnet harness writes this
// address to file. Live tests must populate this field.
Address: common.Address{},
SwapContracts: map[uint32]*dexeth.SwapContract{
0: {
Address: common.Address{}, // Set in MaybeReadSimnetAddrs
Gas: dexeth.Gases{
// First swap used 171664 gas Recommended Gases.Swap = 223163
// 4 additional swaps averaged 112615 gas each. Recommended Gases.SwapAdd = 146399
// [171664 284279 396882 509509 622124]
Swap: 223_163,
SwapAdd: 146_399,
// First redeem used 63170 gas. Recommended Gases.Redeem = 82121
// 4 additional redeems averaged 31626 gas each. recommended Gases.RedeemAdd = 41113
// [63170 94799 126416 158058 189675]
Redeem: 82_121,
RedeemAdd: 41_113,
// Average of 5 refunds: 48098. Recommended Gases.Refund = 62527
// [48098 48098 48098 48098 48098]
Refund: 62_527,
// Average of 2 approvals: 44754. Recommended Gases.Approve = 58180
// [44754 44754]
Approve: 58_180,
// Average of 1 transfers: 49646. Recommended Gases.Transfer = 64539
// [49646]
Transfer: 64_539,
},
},
NetTokens: map[dex.Network]*dexeth.NetToken{
dex.Simnet: {
// ERC20 token contract address. The simnet harness writes this
// address to file. Live tests must populate this field.
Address: common.Address{},
SwapContracts: map[uint32]*dexeth.SwapContract{
0: {
Address: common.Address{}, // Set in MaybeReadSimnetAddrs
Gas: dexeth.Gases{
// First swap used 171664 gas Recommended Gases.Swap = 223163
// 4 additional swaps averaged 112615 gas each. Recommended Gases.SwapAdd = 146399
// [171664 284279 396882 509509 622124]
Swap: 223_163,
SwapAdd: 146_399,
// First redeem used 63170 gas. Recommended Gases.Redeem = 82121
// 4 additional redeems averaged 31626 gas each. recommended Gases.RedeemAdd = 41113
// [63170 94799 126416 158058 189675]
Redeem: 82_121,
RedeemAdd: 41_113,
// Average of 5 refunds: 48098. Recommended Gases.Refund = 62527
// [48098 48098 48098 48098 48098]
Refund: 62_527,
// Average of 2 approvals: 44754. Recommended Gases.Approve = 58180
// [44754 44754]
Approve: 58_180,
// Average of 1 transfers: 49646. Recommended Gases.Transfer = 64539
// [49646]
Transfer: 64_539,
},
},
},
},
},
}

usdcTokenID: {
EVMFactor: new(int64),
Token: &dex.Token{
ParentID: PolygonBipID,
Name: "USDC",
UnitInfo: dex.UnitInfo{
AtomicUnit: "microUSD",
Conventional: dex.Denomination{
Unit: "USDC",
ConversionFactor: 1e6,
},
TokenUSDC = &dexeth.Token{
EVMFactor: new(int64),
Token: &dex.Token{
ParentID: PolygonBipID,
Name: "USDC",
UnitInfo: dex.UnitInfo{
AtomicUnit: "microUSD",
Conventional: dex.Denomination{
Unit: "USDC",
ConversionFactor: 1e6,
},
},
NetTokens: map[dex.Network]*dexeth.NetToken{
dex.Mainnet: {
Address: common.HexToAddress("0x2791bca1f2de4661ed88a30c99a7a9449aa84174"), // https://polygonscan.com/address/0x2791bca1f2de4661ed88a30c99a7a9449aa84174
SwapContracts: map[uint32]*dexeth.SwapContract{
0: {
// deploy tx: https://polygonscan.com/tx/0xe5a22c2c5c9a216dd648f12d1654c0e3a4e8d541f62eefe2a938cfe015826ccb
// swap contract: https://polygonscan.com/address/0x73bc803A2604b2c58B8680c3CE1b14489842EF16
Address: common.HexToAddress("0x73bc803A2604b2c58B8680c3CE1b14489842EF16"),
Gas: dexeth.Gases{
// First swap used 187794 gas Recommended Gases.Swap = 244132
// 4 additional swaps averaged 112591 gas each. Recommended Gases.SwapAdd = 146368
// [187794 300385 412976 525567 638158]
Swap: 244_132,
SwapAdd: 146_368,
// First redeem used 77040 gas. Recommended Gases.Redeem = 100152
// 4 additional redeems averaged 31629 gas each. recommended Gases.RedeemAdd = 41117
// [77040 108669 140298 171928 203557]
Redeem: 100_152,
RedeemAdd: 41_117,
// Average of 5 refunds: 69474. Recommended Gases.Refund = 90316
// [69474 69474 69474 69474 69474]
Refund: 90_316,
// Average of 2 approvals: 58446. Recommended Gases.Approve = 75979
// [58446 58446]
Approve: 75_979,
// Average of 1 transfers: 63504. Recommended Gases.Transfer = 82555
// [63504]
Transfer: 82_555,
},
},
NetTokens: map[dex.Network]*dexeth.NetToken{
dex.Mainnet: {
Address: common.HexToAddress("0x2791bca1f2de4661ed88a30c99a7a9449aa84174"), // https://polygonscan.com/address/0x2791bca1f2de4661ed88a30c99a7a9449aa84174
SwapContracts: map[uint32]*dexeth.SwapContract{
0: {
// deploy tx: https://polygonscan.com/tx/0xe5a22c2c5c9a216dd648f12d1654c0e3a4e8d541f62eefe2a938cfe015826ccb
// swap contract: https://polygonscan.com/address/0x73bc803A2604b2c58B8680c3CE1b14489842EF16
Address: common.HexToAddress("0x73bc803A2604b2c58B8680c3CE1b14489842EF16"),
Gas: dexeth.Gases{
// First swap used 187794 gas Recommended Gases.Swap = 244132
// 4 additional swaps averaged 112591 gas each. Recommended Gases.SwapAdd = 146368
// [187794 300385 412976 525567 638158]
Swap: 244_132,
SwapAdd: 146_368,
// First redeem used 77040 gas. Recommended Gases.Redeem = 100152
// 4 additional redeems averaged 31629 gas each. recommended Gases.RedeemAdd = 41117
// [77040 108669 140298 171928 203557]
// Observed 98,928 on mainnet. Bumping from
// recommendation.
Redeem: 125_152,
RedeemAdd: 41_117,
// Average of 5 refunds: 69474. Recommended Gases.Refund = 90316
// [69474 69474 69474 69474 69474]
Refund: 90_316,
// Average of 2 approvals: 58446. Recommended Gases.Approve = 75979
// [58446 58446]
Approve: 75_979,
// Average of 1 transfers: 63504. Recommended Gases.Transfer = 82555
// [63504]
Transfer: 82_555,
},
},
},
dex.Testnet: {
Address: common.HexToAddress("0x0fa8781a83e46826621b3bc094ea2a0212e71b23"), // https://polygonscan.com/address/0x2791bca1f2de4661ed88a30c99a7a9449aa84174
SwapContracts: map[uint32]*dexeth.SwapContract{
0: {
// deploy tx: https://polygonscan.com/tx/0xfc27a89e5befba05df5ebe64670d5df89f635957f3fbeb2d4240cd3f0e540022
// swap contract: https://polygonscan.com/address/0x73bc803A2604b2c58B8680c3CE1b14489842EF16
Address: common.HexToAddress("0x73bc803A2604b2c58B8680c3CE1b14489842EF16"),
Gas: dexeth.Gases{
// First swap used 187982 gas Recommended Gases.Swap = 244376
// 4 additional swaps averaged 112591 gas each. Recommended Gases.SwapAdd = 146368
// [187982 300573 413152 525755 638346]
Swap: 244_376,
SwapAdd: 146_368,
// First redeem used 77229 gas. Recommended Gases.Redeem = 100397
// 4 additional redeems averaged 31629 gas each. recommended Gases.RedeemAdd = 41117
// [77229 108858 140475 172105 203746]
Redeem: 100_397,
RedeemAdd: 41_117,
// Average of 5 refunds: 69660. Recommended Gases.Refund = 90558
// [69663 69663 69651 69663 69663]
Refund: 90_558,
// Average of 2 approvals: 58634. Recommended Gases.Approve = 76224
// [58634 58634]
Approve: 76_224,
// Average of 1 transfers: 63705. Recommended Gases.Transfer = 82816
// [63705]
Transfer: 82_816,
},
},
dex.Testnet: {
Address: common.HexToAddress("0x0fa8781a83e46826621b3bc094ea2a0212e71b23"), // https://polygonscan.com/address/0x2791bca1f2de4661ed88a30c99a7a9449aa84174
SwapContracts: map[uint32]*dexeth.SwapContract{
0: {
// deploy tx: https://polygonscan.com/tx/0xfc27a89e5befba05df5ebe64670d5df89f635957f3fbeb2d4240cd3f0e540022
// swap contract: https://polygonscan.com/address/0x73bc803A2604b2c58B8680c3CE1b14489842EF16
Address: common.HexToAddress("0x73bc803A2604b2c58B8680c3CE1b14489842EF16"),
Gas: dexeth.Gases{
// First swap used 187982 gas Recommended Gases.Swap = 244376
// 4 additional swaps averaged 112591 gas each. Recommended Gases.SwapAdd = 146368
// [187982 300573 413152 525755 638346]
Swap: 244_376,
SwapAdd: 146_368,
// First redeem used 77229 gas. Recommended Gases.Redeem = 100397
// 4 additional redeems averaged 31629 gas each. recommended Gases.RedeemAdd = 41117
// [77229 108858 140475 172105 203746]
Redeem: 100_397,
RedeemAdd: 41_117,
// Average of 5 refunds: 69660. Recommended Gases.Refund = 90558
// [69663 69663 69651 69663 69663]
Refund: 90_558,
// Average of 2 approvals: 58634. Recommended Gases.Approve = 76224
// [58634 58634]
Approve: 76_224,
// Average of 1 transfers: 63705. Recommended Gases.Transfer = 82816
// [63705]
Transfer: 82_816,
},
},
},
},
},
wethTokenID: TokenWETH,
wbtcTokenID: TokenWBTC,
}

// Wrapped ETH
// TokenWETH is for Wrapped ETH.
TokenWETH = &dexeth.Token{
Token: &dex.Token{
ParentID: PolygonBipID,
Name: "WETH",
Name: "Wrapped Ether",
UnitInfo: dex.UnitInfo{
AtomicUnit: "gwei",
Conventional: dex.Denomination{
Expand All @@ -220,14 +226,15 @@ var (
// 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,
// Observed an 87,334 in the wild, so bumping this
// a bit.
Redeem: 104_800,
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,
Approve: 56_054,
// Average of 1 transfers: 51910. Recommended Gases.Transfer = 67483
// [51910]
Transfer: 67_483,
Expand All @@ -238,7 +245,7 @@ var (
},
}

// Wrapped BTC
// TokenWBTC is for Wrapped BTC.
TokenWBTC = &dexeth.Token{
EVMFactor: new(int64),
Token: &dex.Token{
Expand Down Expand Up @@ -269,7 +276,10 @@ var (
// 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,
// Values around 92k were observed in the wild, so
// this limit has been bumped up from the
// recommendation.
Redeem: 110_032,
RedeemAdd: 41_117,
// Average of 5 refunds: 63126. Recommended Gases.Refund = 82063
// [63126 63126 63126 63126 63126]
Expand Down

0 comments on commit 01f15fd

Please sign in to comment.