Skip to content

Commit

Permalink
feat: add new assets
Browse files Browse the repository at this point in the history
  • Loading branch information
EviLord032 committed May 9, 2024
1 parent 90e34bf commit b1be1cd
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 40 deletions.
18 changes: 9 additions & 9 deletions deployments/polygon/usdt/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
},
"rewardTokenAddress": "0x8505b9d2254A7Ae468c0E9dd10Ccea3A837aef5c",
"assets": {
"WMATIC": {
"address": "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
"priceFeed": "0xAB594600376Ec9fD91F8e885dADF0CE036862dE0",
"decimals": "18",
"borrowCF": 0.65,
"liquidateCF": 0.80,
"liquidationFactor": 0.85,
"supplyCap": "0e18"
},
"aPolMATICX": {
"address": "0x80cA0d8C38d2e2BcbaB66aA1648Bd1C7160500FE",
"priceFeed": "0x5d37E4b374E6907de8Fc7fb33EE3b0af403C7403",
Expand Down Expand Up @@ -54,15 +63,6 @@
"liquidationFactor": 0.95,
"supplyCap": "0e18"
},
"WMATIC": {
"address": "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
"priceFeed": "0xAB594600376Ec9fD91F8e885dADF0CE036862dE0",
"decimals": "18",
"borrowCF": 0.65,
"liquidateCF": 0.80,
"liquidationFactor": 0.85,
"supplyCap": "0e18"
},
"WBTC": {
"address": "0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6",
"priceFeed": "0xDE31F8bFBD8c84b5360CFACCa3539B938dd78ae6",
Expand Down
26 changes: 17 additions & 9 deletions deployments/polygon/usdt/relations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,29 @@ export default {
'governor': {
artifact: 'contracts/bridges/polygon/PolygonBridgeReceiver.sol:PolygonBridgeReceiver',
},
InitializableImmutableAdminUpgradeabilityProxy: {
artifact: 'contracts/ERC20.sol:ERC20',
delegates: {
field: {
slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'
}
}
},
// InitializableImmutableAdminUpgradeabilityProxy: {
aPolMATICX: {
artifact: 'contracts/ERC20.sol:ERC20',
delegates: {
field: {
slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'
}
}
},
UChildERC20Proxy: {
artifact: 'contracts/ERC20.sol:ERC20',
delegates: {
field: {
slot: '0xbaab7dbf64751104133af04abc7d9979f0fda3b059a322a8333f533d3f32bf7f',
}
},
// aPolMATICX
'0x80cA0d8C38d2e2BcbaB66aA1648Bd1C7160500FE': {
artifact: 'contracts/ERC20.sol:ERC20',
delegates: {
field: {
slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'
}
}
}
}
};
48 changes: 26 additions & 22 deletions plugins/import/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,36 @@ async function getEtherscanApiData(network: string, address: string, apiKey: str
};
}

async function scrapeContractCreationCodeFromEtherscanApi(network: string, address: string) {
const params = {
module: 'proxy',
action: 'eth_getCode',
address,
apikey: getEtherscanApiKey(network)
};
const url = `${getEtherscanApiUrl(network)}?${paramString(params)}`;
const debugUrl = `${getEtherscanApiUrl(network)}?${paramString({ ...params, ...{ apikey: '[API_KEY]'}})}`;

debug(`Attempting to pull Contract Creation code from API at ${debugUrl}`);
const result = await get(url, {});
const contractCreationCode = result.result;
if (!contractCreationCode) {
throw new Error(`Unable to find Contract Creation code from API at ${debugUrl}`);
}
debug(`Creation Code found in first tx at ${debugUrl}`);
return contractCreationCode.slice(2);
}

/**
* @description Does not work for 0x566511a1A09561e2896F8c0fD77E8544E59bFDB0 as etherscan starts using some firewall
*/
async function scrapeContractCreationCodeFromEtherscan(network: string, address: string) {
const url = `${getEtherscanUrl(network)}/address/${address}#code`;
debug(`Attempting to scrape Contract Creation code at ${url}`);
const result = <string>await get(url, {});
const regex = /<div id='verifiedbytecode2'>[\s\r\n]*([0-9a-fA-F]*)[\s\r\n]*<\/div>/g;
const matches = [...result.matchAll(regex)];
const regexDoubleQuotes = /<div id="verifiedbytecode2">[\s\r\n]*([0-9a-fA-F]*)[\s\r\n]*<\/div>/g;
const matches = [...result.matchAll(regex), ...result.matchAll(regexDoubleQuotes)];
if (matches.length === 0) {
if (result.match(/request throttled/i) || result.match(/try again later/i)) {
throw new Error(`Request throttled: ${url}`);
Expand Down Expand Up @@ -129,31 +153,11 @@ async function pullFirstTransactionForContract(network: string, address: string)
return contractCreationCode.slice(2);
}

async function scrapeContractCreationCodeFromEtherscanApi(network: string, address: string) {
const params = {
module: 'proxy',
action: 'eth_getCode',
address,
apikey: getEtherscanApiKey(network)
};
const url = `${getEtherscanApiUrl(network)}?${paramString(params)}`;
const debugUrl = `${getEtherscanApiUrl(network)}?${paramString({ ...params, ...{ apikey: '[API_KEY]'}})}`;

debug(`Attempting to pull Contract Creation code from API at ${debugUrl}`);
const result = await get(url, {});
const contractCreationCode = result.result;
if (!contractCreationCode) {
throw new Error(`Unable to find Contract Creation code from API at ${debugUrl}`);
}
debug(`Creation Code found in first tx at ${debugUrl}`);
return contractCreationCode.slice(2);
}

async function getContractCreationCode(network: string, address: string) {
const strategies = [
scrapeContractCreationCodeFromEtherscan,
scrapeContractCreationCodeFromEtherscanApi,
pullFirstTransactionForContract
pullFirstTransactionForContract,
];
let errors = [];
for (const strategy of strategies) {
Expand Down

0 comments on commit b1be1cd

Please sign in to comment.