Skip to content

Commit

Permalink
add: improve axelar bridge fee calc
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpy committed Dec 3, 2023
1 parent 273783f commit 6a55c54
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 42 deletions.
18 changes: 16 additions & 2 deletions contracts/reserve/DistributionHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ contract DistributionHelper is
address public constant WETH_TOKEN =
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;

address public constant AXL_TOKEN =
0x467719aD09025FcC6cF6F8311755809d45a5E5f3;

enum TransferType {
FuseBridge,
LayerZeroBridge,
Expand All @@ -55,7 +58,7 @@ contract DistributionHelper is
}

struct FeeSettings {
uint128 axelarBaseFeeUSD;
uint128 axelarBaseFee;
uint128 bridgeExecuteGas;
uint128 targetChainGasPrice;
uint128 maxFee;
Expand Down Expand Up @@ -144,10 +147,21 @@ contract DistributionHelper is
);

uint24[] memory fees = new uint24[](1);
fees[0] = 3000;

(uint256 baseFeeInUSDC, ) = STATIC_ORACLE
.quoteSpecificFeeTiersWithTimePeriod(
uint128(feeSettings.axelarBaseFee),
AXL_TOKEN,
USDC_TOKEN,
fees,
60 //last 1 minute
);

fees[0] = 500;
(uint256 baseFeeInEth, ) = STATIC_ORACLE
.quoteSpecificFeeTiersWithTimePeriod(
uint128(feeSettings.axelarBaseFeeUSD) / 1e12, //reduce to usdc 6 decimals
uint128(baseFeeInUSDC) / 1e12, //reduce to usdc 6 decimals
USDC_TOKEN,
WETH_TOKEN,
fees,
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/superfluid/SuperGoodDollar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ contract SuperGoodDollar is
IIdentity public identity;
uint256 public cap;
bool public disableHostOperations;
address public getUnderlyingToken;
// Append additional state variables here!

// ============== constants and immutables ==============

address public constant getUnderlyingToken = address(0x0);
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");

Expand Down
5 changes: 4 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { HardhatUserConfig } from "hardhat/types";
import "@typechain/hardhat";
import "@nomicfoundation/hardhat-chai-matchers"; //Added for revertWithCustomErrors
import "@nomiclabs/hardhat-etherscan";
import "@nomicfoundation/hardhat-verify";
import "@openzeppelin/hardhat-upgrades";
import "solidity-coverage";
import "hardhat-gas-reporter";
Expand Down Expand Up @@ -63,6 +63,9 @@ const hhconfig: HardhatUserConfig = {
typechain: {
outDir: "types"
},
sourcify: {
enabled: false
},
etherscan: {
apiKey: {
mainnet: etherscan_key,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@
"@mean-finance/uniswap-v3-oracle": "^1.0.3",
"@nomicfoundation/hardhat-chai-matchers": "1",
"@nomicfoundation/hardhat-network-helpers": "^1.0.8",
"@nomicfoundation/hardhat-verify": "^2.0.1",
"@nomiclabs/hardhat-ethers": "^2.2.1",
"@nomiclabs/hardhat-etherscan": "^3.1.0",
"@nomiclabs/hardhat-waffle": "^2.0.6",
"@swc/core": "1.3.96",
"@swc/helpers": "^0.3.16",
Expand Down
70 changes: 70 additions & 0 deletions scripts/analytics/stuckgd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { range } from "lodash";
import PromisePool from "async-promise-pool";
import fs from "fs";
import { Provider, setMulticallAddress } from "ethers-multicall";

import { ethers } from "hardhat";
import { Retrier } from "@jsier/retrier";

setMulticallAddress(122, "0x3CE6158b7278Bf6792e014FA7B4f3c6c46fe9410");
const celoProvider = new ethers.providers.JsonRpcBatchProvider(
"https://forno.celo.org"
);

const GD_CELO = "0x62B8B11039FcfE5aB0C56E502b1C372A3d2a9c7A";

let gd = new ethers.Contract(
GD_CELO,
[
"event Transfer(address indexed from, address indexed to, uint amount)",
"function balanceOf(address) view returns(uint256)"
],
celoProvider
);

/**
* in/out G$ to a specific address (here used for invites)
*/
const main = async () => {
const curBlock = await celoProvider.getBlockNumber();
let txs = [];
const f = gd.filters.Transfer(null, GD_CELO);
const STEP_SIZE = 5000;
const fromBlocks = range(curBlock - 6e6, curBlock, STEP_SIZE); //600k blocks roughly a month
const pool = new PromisePool({ concurrency: 2 });
console.log({ curBlock });
fromBlocks.forEach(fromBlock => {
pool.add(async () => {
const options = { limit: 20, delay: 2000 };
const retrier = new Retrier(options);

const results = await retrier
.resolve(() => gd.queryFilter(f, fromBlock, fromBlock + STEP_SIZE))
.catch(e => console.warn("queryfilter failed:", { fromBlock }));
if (!results) return;

txs = txs.concat(results);
console.log({ fromBlock }, results.length);
});
});

await pool.all();

console.log(txs.length);
fs.writeFileSync("stuckgd.json", JSON.stringify(txs));
};

const analyze = () => {
const txs = JSON.parse(fs.readFileSync("stuckgd.json").toString());
let value = 0;
console.log(txs[0]);
txs.forEach(tx => {
value += Number(tx.args[2].hex);
console.log(
`erc20,${GD_CELO},${tx.args[0]},${Number(tx.args[2].hex) / 1e18},`
);
});
console.log(txs.length, { value });
};
analyze();
// main().catch(e => console.error("Error:", e.message));
63 changes: 58 additions & 5 deletions scripts/fv.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import fetch from "cross-fetch";
import fs from "fs";
import { chunk } from "lodash";
import { bulkIsWhitelisted } from "./utils";
import { chunk, uniqBy } from "lodash";
import { bulkIsWhitelisted, bulkLastAuth } from "./utils";

const main = async () => {
const data = JSON.parse(fs.readFileSync("fvtriplets.txt").toString());
const triplets = chunk(data, 3);
const triplets = uniqBy(chunk(data, 3), _ => _.join("_"));

const accounts = triplets.map(_ => _[0]);
const whitelisted = await bulkIsWhitelisted(accounts);
const failed = triplets.filter(_ => whitelisted.includes(_[0]) === false);
Expand Down Expand Up @@ -39,10 +40,62 @@ const main = async () => {
encoding: "base64"
}
);
} else console.log("not found", a);
} else
console.log("not found", a, !!i1.auditTrailBase64, !!i2.auditTrailBase64);
});

await Promise.all(ps);
};

main();
const deleteIdentifiers = async () => {
const data = JSON.parse(fs.readFileSync("todeletefvtriplets.txt").toString());
const triplets = uniqBy(chunk(data, 3), _ => _.join("_"));
const accounts = triplets.map(_ => _[0]);
const whitelisted = await bulkIsWhitelisted(accounts);
const lastAuth = await bulkLastAuth(accounts);
const failed = triplets.filter(
_ =>
whitelisted.includes(_[0]) === false && lastAuth.includes(_[0]) === true
);

let ps = [];
console.log({ failed });

for (let record of failed) {
ps.push(
fetch("https://goodserver.gooddollar.org/admin/verify/face/delete", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
password,
enrollmentIdentifier: record[1]
})
})
.then(_ => _.json())
.catch(_ => record[1])
);
ps.push(
fetch("https://goodserver.gooddollar.org/admin/verify/face/delete", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
password,
enrollmentIdentifier: record[2]
})
})
.then(_ => _.json())
.catch(_ => record[2])
);
if (ps.length % 10 === 0) {
console.log("waiting...", ps.length);
const r = await Promise.all(ps);
console.log(r);
ps = [];
}
}
const res = await Promise.all(ps);
console.log(res);
};

deleteIdentifiers();
// main();
27 changes: 25 additions & 2 deletions scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,34 @@ import { ethers } from "hardhat";
export const bulkIsWhitelisted = async (accounts: Array<String>) => {
setMulticallAddress(122, "0x3CE6158b7278Bf6792e014FA7B4f3c6c46fe9410");
setMulticallAddress(42220, "0x75F59534dd892c1f8a7B172D639FA854D529ada3");
const celoProvider = new ethers.providers.JsonRpcProvider("https://forno.celo.org");
const celoProvider = new ethers.providers.JsonRpcProvider(
"https://forno.celo.org"
);
const ethcallProvider = new Provider(celoProvider, 42220);
const identityContract = new Contract("0xC361A6E67822a0EDc17D899227dd9FC50BD62F42", Identity.abi);
const identityContract = new Contract(
"0xC361A6E67822a0EDc17D899227dd9FC50BD62F42",
Identity.abi
);
const calls = accounts.map(d => identityContract.isWhitelisted(d));
const result = await ethcallProvider.all(calls);
const whitelisted = accounts.filter((v, i) => result[i]);
return whitelisted;
};

export const bulkLastAuth = async (accounts: Array<String>) => {
setMulticallAddress(122, "0x3CE6158b7278Bf6792e014FA7B4f3c6c46fe9410");
setMulticallAddress(42220, "0x75F59534dd892c1f8a7B172D639FA854D529ada3");
const celoProvider = new ethers.providers.JsonRpcProvider(
"https://forno.celo.org"
);
const ethcallProvider = new Provider(celoProvider, 42220);
const identityContract = new Contract(
"0xC361A6E67822a0EDc17D899227dd9FC50BD62F42",
Identity.abi
);
const calls = accounts.map(d => identityContract.lastAuthenticated(d));
const result = await ethcallProvider.all(calls);
console.log({ result });
const whitelisted = accounts.filter((v, i) => parseInt(result[i]));
return whitelisted;
};
59 changes: 29 additions & 30 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2399,8 +2399,8 @@ __metadata:
"@mean-finance/uniswap-v3-oracle": ^1.0.3
"@nomicfoundation/hardhat-chai-matchers": 1
"@nomicfoundation/hardhat-network-helpers": ^1.0.8
"@nomicfoundation/hardhat-verify": ^2.0.1
"@nomiclabs/hardhat-ethers": ^2.2.1
"@nomiclabs/hardhat-etherscan": ^3.1.0
"@nomiclabs/hardhat-waffle": ^2.0.6
"@openzeppelin/contracts": ^4.8.0
"@openzeppelin/contracts-upgradeable": ^4.8.0
Expand Down Expand Up @@ -2933,6 +2933,25 @@ __metadata:
languageName: node
linkType: hard

"@nomicfoundation/hardhat-verify@npm:^2.0.1":
version: 2.0.1
resolution: "@nomicfoundation/hardhat-verify@npm:2.0.1"
dependencies:
"@ethersproject/abi": ^5.1.2
"@ethersproject/address": ^5.0.2
cbor: ^8.1.0
chalk: ^2.4.2
debug: ^4.1.1
lodash.clonedeep: ^4.5.0
semver: ^6.3.0
table: ^6.8.0
undici: ^5.14.0
peerDependencies:
hardhat: ^2.0.4
checksum: 3bf3a1a0edc913a5c920faeb6574c98118996d994574a8c3cf048acd915a18297a931aae46db31f54a39a34bed666ae0982e4f9c3ee2c5ac7f75ecb3ef2307d8
languageName: node
linkType: hard

"@nomicfoundation/solidity-analyzer-darwin-arm64@npm:0.1.1":
version: 0.1.1
resolution: "@nomicfoundation/solidity-analyzer-darwin-arm64@npm:0.1.1"
Expand Down Expand Up @@ -3052,26 +3071,6 @@ __metadata:
languageName: node
linkType: hard

"@nomiclabs/hardhat-etherscan@npm:^3.1.0":
version: 3.1.0
resolution: "@nomiclabs/hardhat-etherscan@npm:3.1.0"
dependencies:
"@ethersproject/abi": ^5.1.2
"@ethersproject/address": ^5.0.2
cbor: ^5.0.2
chalk: ^2.4.2
debug: ^4.1.1
fs-extra: ^7.0.1
lodash: ^4.17.11
semver: ^6.3.0
table: ^6.8.0
undici: ^5.4.0
peerDependencies:
hardhat: ^2.0.4
checksum: 3f28abc39edce2936226b6d0087c3be78bffcba68b6935f3f60767f0e10233e940ddc74803dff91f7ddf9464a7199aab00fba08d8b3865dbc2f8936f53a7a5a5
languageName: node
linkType: hard

"@nomiclabs/hardhat-waffle@npm:^2.0.6":
version: 2.0.6
resolution: "@nomiclabs/hardhat-waffle@npm:2.0.6"
Expand Down Expand Up @@ -7513,7 +7512,7 @@ __metadata:
languageName: node
linkType: hard

"cbor@npm:^5.0.2, cbor@npm:^5.2.0":
"cbor@npm:^5.2.0":
version: 5.2.0
resolution: "cbor@npm:5.2.0"
dependencies:
Expand All @@ -7523,7 +7522,7 @@ __metadata:
languageName: node
linkType: hard

"cbor@npm:^8.0.0":
"cbor@npm:^8.0.0, cbor@npm:^8.1.0":
version: 8.1.0
resolution: "cbor@npm:8.1.0"
dependencies:
Expand Down Expand Up @@ -14537,6 +14536,13 @@ __metadata:
languageName: node
linkType: hard

"lodash.clonedeep@npm:^4.5.0":
version: 4.5.0
resolution: "lodash.clonedeep@npm:4.5.0"
checksum: 92c46f094b064e876a23c97f57f81fbffd5d760bf2d8a1c61d85db6d1e488c66b0384c943abee4f6af7debf5ad4e4282e74ff83177c9e63d8ff081a4837c3489
languageName: node
linkType: hard

"lodash.debounce@npm:^4.0.8":
version: 4.0.8
resolution: "lodash.debounce@npm:4.0.8"
Expand Down Expand Up @@ -21313,13 +21319,6 @@ patch-package@latest:
languageName: node
linkType: hard

"undici@npm:^5.4.0":
version: 5.9.1
resolution: "undici@npm:5.9.1"
checksum: 8acabbac8e18943ff822574f831d03d65e697e66ef486a679763f7778f37b28980caf7097ededf4017b58c099809e8efd8509a6688f60638360fb86ef47a59df
languageName: node
linkType: hard

"unicode-canonical-property-names-ecmascript@npm:^1.0.4":
version: 1.0.4
resolution: "unicode-canonical-property-names-ecmascript@npm:1.0.4"
Expand Down

0 comments on commit 6a55c54

Please sign in to comment.