Skip to content
Open
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
24 changes: 24 additions & 0 deletions contracts/TokenConverter/SingleTokenConverter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,30 @@ contract SingleTokenConverter is AbstractTokenConverter {
}
}

/// @notice Hook called after a private conversion is completed
/// @dev Emits an AssetTransferredToDestination event if Private Conversion happens
/// @param comptroller The address of the comptroller (pool) associated with the conversion
/// @param tokenAddressIn The address of the input token that was converted
/// @param convertedTokenInBalance The amount of input token that was converted
/// @custom:event AssetTransferredToDestination Emitted when convertedTokenInBalance > 0, indicating
/// the converted assets were transferred to the destination address
function _postPrivateConversionHook(
address comptroller,
address tokenAddressIn,
uint256 convertedTokenInBalance,
address,
uint256
) internal override {
if (convertedTokenInBalance > 0) {
emit AssetTransferredToDestination(
destinationAddress,
comptroller,
tokenAddressIn,
convertedTokenInBalance
);
}
}

/// @dev Sets the base asset for the contract
/// @param baseAsset_ The new address of the base asset
/// @custom:error ZeroAddressNotAllowed is thrown when address is zero
Expand Down
2 changes: 1 addition & 1 deletion deployments/arbitrumone.json
Original file line number Diff line number Diff line change
Expand Up @@ -3343,7 +3343,7 @@
]
},
"SingleTokenConverterImp": {
"address": "0x07801d54906Be49517DfDEd26c89A81fb94e504B",
"address": "0x2EE413F4e060451CB25AeD5Cdd348F430aa79105",
"abi": [
{
"inputs": [],
Expand Down
88 changes: 44 additions & 44 deletions deployments/arbitrumone/SingleTokenConverterImp.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion deployments/arbitrumone_addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"ProtocolShareReserve_Implementation": "0x6B2D272CD89585BCE8404006f366a77680324F7d",
"ProtocolShareReserve_Proxy": "0xF9263eaF7eB50815194f26aCcAB6765820B13D41",
"SingleTokenConverterBeacon": "0x993900Ab4ef4092e5B76d4781D09A2732086F0F0",
"SingleTokenConverterImp": "0x07801d54906Be49517DfDEd26c89A81fb94e504B",
"SingleTokenConverterImp": "0x2EE413F4e060451CB25AeD5Cdd348F430aa79105",
"USDCPrimeConverter": "0x6553C9f9E131191d4fECb6F0E73bE13E229065C6",
"USDTPrimeConverter": "0x435Fac1B002d5D31f374E07c0177A1D709d5DC2D",
"WBTCPrimeConverter": "0xF91369009c37f029aa28AF89709a352375E5A162",
Expand Down
2 changes: 1 addition & 1 deletion deployments/arbitrumsepolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -3343,7 +3343,7 @@
]
},
"SingleTokenConverterImp": {
"address": "0x4ea44b72e00e942b259a6a3720Cf1B8776b9fe93",
"address": "0xcf78eB1806660F0D001F786C66f294DADb9F95b0",
"abi": [
{
"inputs": [],
Expand Down
94 changes: 47 additions & 47 deletions deployments/arbitrumsepolia/SingleTokenConverterImp.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion deployments/arbitrumsepolia_addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"ProtocolShareReserve_Implementation": "0xF5B07c27d213A2B838A3D155FFEC0d52B17E91fd",
"ProtocolShareReserve_Proxy": "0x09267d30798B59c581ce54E861A084C6FC298666",
"SingleTokenConverterBeacon": "0xC77D0F75f1e4e3720DA1D2F5D809F439125a2Fd4",
"SingleTokenConverterImp": "0x4ea44b72e00e942b259a6a3720Cf1B8776b9fe93",
"SingleTokenConverterImp": "0xcf78eB1806660F0D001F786C66f294DADb9F95b0",
"USDCPrimeConverter": "0xE88ed530597bc8D50e8CfC0EecAAFf6A93248C74",
"USDTPrimeConverter": "0xFC0ec257d3ec4D673cB4e2CD3827C202e75fd0be",
"WBTCPrimeConverter": "0x3089F46caf6611806caA39Ffaf672097156b893a",
Expand Down
2 changes: 1 addition & 1 deletion deployments/bscmainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -8554,7 +8554,7 @@
]
},
"SingleTokenConverterImp": {
"address": "0x40ed28180Df01FdeB957224E4A5415704B9D5990",
"address": "0xF96363e03D175eEcc6A965f117e1497EAe878d29",
"abi": [
{
"inputs": [],
Expand Down
91 changes: 48 additions & 43 deletions deployments/bscmainnet/SingleTokenConverterImp.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion deployments/bscmainnet_addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"RiskFundV2_Implementation": "0x7Ef5ABbcC9A701e728BeB7Afd4fb5747fAB15A28",
"RiskFundV2_Proxy": "0xdF31a28D68A2AB381D42b380649Ead7ae2A76E42",
"SingleTokenConverterBeacon": "0x4c9D57b05B245c40235D720A5f3A592f3DfF11ca",
"SingleTokenConverterImp": "0x40ed28180Df01FdeB957224E4A5415704B9D5990",
"SingleTokenConverterImp": "0xF96363e03D175eEcc6A965f117e1497EAe878d29",
"USDCPrimeConverter": "0xa758c9C215B6c4198F0a0e3FA46395Fa15Db691b",
"USDTPrimeConverter": "0xD9f101AA67F3D72662609a2703387242452078C3",
"WBNBBurnConverter": "0x9eF79830e626C8ccA7e46DCEd1F90e51E7cFCeBE",
Expand Down
2 changes: 1 addition & 1 deletion deployments/bsctestnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -8554,7 +8554,7 @@
]
},
"SingleTokenConverterImp": {
"address": "0x42Ec3Eb6F23460dFDfa3aE5688f3415CDfE0C6AD",
"address": "0x892A70c9D9f946c0CB2b148f40B95Ba0024e8968",
"abi": [
{
"inputs": [],
Expand Down
93 changes: 49 additions & 44 deletions deployments/bsctestnet/SingleTokenConverterImp.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion deployments/bsctestnet_addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"RiskFundV2_Implementation": "0x394C9a8cDbbFcAbEAb21fB105311B6B1f09b667a",
"RiskFundV2_Proxy": "0x487CeF72dacABD7E12e633bb3B63815a386f7012",
"SingleTokenConverterBeacon": "0xD2410D8B581D37c5B474CD9Ee0C15F02138AC028",
"SingleTokenConverterImp": "0x42Ec3Eb6F23460dFDfa3aE5688f3415CDfE0C6AD",
"SingleTokenConverterImp": "0x892A70c9D9f946c0CB2b148f40B95Ba0024e8968",
"USDCPrimeConverter": "0x2ecEdE6989d8646c992344fF6C97c72a3f811A13",
"USDTPrimeConverter": "0xf1FA230D25fC5D6CAfe87C5A6F9e1B17Bc6F194E",
"WBNBBurnConverter": "0x42DBA48e7cCeB030eC73AaAe29d4A3F0cD4facba",
Expand Down
2 changes: 1 addition & 1 deletion deployments/ethereum.json
Original file line number Diff line number Diff line change
Expand Up @@ -3343,7 +3343,7 @@
]
},
"SingleTokenConverterImp": {
"address": "0x95de59aD391589603DF33F81B53C4d894D8e5545",
"address": "0x560E50dc157E7140C0E5bdF46e586c658C8A066c",
"abi": [
{
"inputs": [],
Expand Down
80 changes: 40 additions & 40 deletions deployments/ethereum/SingleTokenConverterImp.json

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions deployments/ethereum/solcInputs/e2c9962896c0d2548025c54c4fbe3c77.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion deployments/ethereum_addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"ProtocolShareReserve_Implementation": "0xee934792431B4Ebd91591a86c884A8b49Ed494C2",
"ProtocolShareReserve_Proxy": "0x8c8c8530464f7D95552A11eC31Adbd4dC4AC4d3E",
"SingleTokenConverterBeacon": "0x5C0b5D09388F2BA6441E74D40666C4d96e4527D1",
"SingleTokenConverterImp": "0x95de59aD391589603DF33F81B53C4d894D8e5545",
"SingleTokenConverterImp": "0x560E50dc157E7140C0E5bdF46e586c658C8A066c",
"USDCPrimeConverter": "0xcEB9503f10B781E30213c0b320bCf3b3cE54216E",
"USDTPrimeConverter": "0x4f55cb0a24D5542a3478B0E284259A6B850B06BD",
"WBTCPrimeConverter": "0xDcCDE673Cd8988745dA384A7083B0bd22085dEA0",
Expand Down
2 changes: 1 addition & 1 deletion deployments/sepolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -3333,7 +3333,7 @@
]
},
"SingleTokenConverterImp": {
"address": "0xb13409Cbf2b3420856DD577AE2FcC4a4Cd6d9F1e",
"address": "0x04444eAc8811140A3B22814a2203F6908d0708ad",
"abi": [
{
"inputs": [],
Expand Down
96 changes: 48 additions & 48 deletions deployments/sepolia/SingleTokenConverterImp.json

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions deployments/sepolia/solcInputs/e2c9962896c0d2548025c54c4fbe3c77.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion deployments/sepolia_addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"ProtocolShareReserve_Implementation": "0x5429e6ddc967c7f6a1e2c13bb812b6c6a57cbe19",
"ProtocolShareReserve_Proxy": "0xbea70755cc3555708ca11219adB0db4C80F6721B",
"SingleTokenConverterBeacon": "0xb86e532a5333d413A1c35d86cCdF1484B40219eF",
"SingleTokenConverterImp": "0xb13409Cbf2b3420856DD577AE2FcC4a4Cd6d9F1e",
"SingleTokenConverterImp": "0x04444eAc8811140A3B22814a2203F6908d0708ad",
"USDCPrimeConverter": "0x511a559a699cBd665546a1F75908f7E9454Bfc67",
"USDTPrimeConverter": "0x3716C24EA86A67cAf890d7C9e4C4505cDDC2F8A2",
"WBTCPrimeConverter": "0x8a3937F27921e859db3FDA05729CbCea8cfd82AE",
Expand Down
74 changes: 74 additions & 0 deletions tests/fork/SingleTokenConverter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import chai from "chai";
import { Contract, Signer } from "ethers";
import { parseUnits } from "ethers/lib/utils";
import hre from "hardhat";
import { ethers } from "hardhat";

import { forking, initMainnetUser } from "../utils";

Expand All @@ -13,6 +15,10 @@ const SINGLE_TOKEN_CONVERTER_BEACON_PROXY = "0x4c9D57b05B245c40235D720A5f3A592f3
const RISK_FUND_CONVERTER_PROXY = "0xA5622D276CcbB8d9BBE3D1ffd1BB11a0032E53F0";
const PROXY_ADMIN = "0x6beb6D2695B67FEb73ad4f172E8E2975497187e4";
const BTCB_PRIME_CONVERTER = "0xE8CeAa79f082768f99266dFd208d665d2Dd18f53";
const USDT_PRIME_CONVERTER = "0xD9f101AA67F3D72662609a2703387242452078C3";
const USDC_PRIME_CONVERTER = "0xa758c9C215B6c4198F0a0e3FA46395Fa15Db691b";
const ETH_PRIME_CONVERTER = "0xca430B8A97Ea918fF634162acb0b731445B8195E";
const XVS_VAULT_CONVERTER = "0xd5b9AE835F4C59272032B3B954417179573331E0";
const CORE_POOL = "0xfd36e2c2a6789db23113685031d7f16329158384";

//Assets listed in core pool and need to release funds for them
Expand Down Expand Up @@ -57,6 +63,7 @@ forking(36468100, () => {
let proxyAdmin: Contract;
let singleTokenConverterImplementation = Contract;
let timeLockSigner: Signer;

const FORK_MAINNET = process.env.FORK === "true" && process.env.FORKED_NETWORK === "bscmainnet";

if (FORK_MAINNET) {
Expand Down Expand Up @@ -219,6 +226,73 @@ forking(36468100, () => {
});
});
});

describe("SingleTokenConverter Private Conversion Event Test", () => {
let usdtPrimeConverter: Contract;
let usdcPrimeConverter: Contract;
let ethPrimeConverter: Contract;
let xvsVaultConverter: Contract;
let riskFundConverter: Contract;
let protocolShareReserve: Contract;
let timeLockSigner: SignerWithAddress;

before(async () => {
// Setup mainnet state
protocolShareReserve = await hre.ethers.getContractAt("ProtocolShareReserve", PROTOCOL_SHARE_RESERVE);
timeLockSigner = await initMainnetUser(NORMAL_TIMELOCK);

// Upgrade logic contracts to ensure we have correct _postPrivateConversionHook behavior
const concreteImpl = await hre.ethers.getContractFactory("SingleTokenConverter");
const upgradedImpl = await concreteImpl.deploy();
await upgradedImpl.deployed();

const beacon = await hre.ethers.getContractAt("UpgradeableBeacon", SINGLE_TOKEN_CONVERTER_BEACON_PROXY);
await beacon.connect(timeLockSigner).upgradeTo(upgradedImpl.address);

console.log("beacon implementation : ", await beacon.implementation());

usdtPrimeConverter = await hre.ethers.getContractAt("SingleTokenConverter", USDT_PRIME_CONVERTER);
ethPrimeConverter = await hre.ethers.getContractAt("SingleTokenConverter", ETH_PRIME_CONVERTER);
usdcPrimeConverter = await hre.ethers.getContractAt("SingleTokenConverter", USDC_PRIME_CONVERTER);
xvsVaultConverter = await hre.ethers.getContractAt("SingleTokenConverter", XVS_VAULT_CONVERTER);
riskFundConverter = await hre.ethers.getContractAt("RiskFundConverter", RISK_FUND_CONVERTER_PROXY);
});

it("emits AssetTransferredToDestination from Converters during private conversion", async () => {
const tx = await protocolShareReserve.releaseFunds(CORE_POOL, [BTCB]);
const receipt = await tx.wait();

const converters = [usdtPrimeConverter, usdcPrimeConverter, ethPrimeConverter, xvsVaultConverter];

for (const converter of converters) {
const AssetTransferredEvent = usdtPrimeConverter.interface.getEvent("AssetTransferredToDestination");
const AssetTransferredTopic = usdtPrimeConverter.interface.getEventTopic(AssetTransferredEvent);

// Filter all logs matching the event topic
const AssetTransferredLogs = receipt.logs.filter(log => log.topics[0] === AssetTransferredTopic);

console.log(`\n[${(await converter.name?.()) || converter.address}]`);
console.log(" Receiver: ", await converter.destinationAddress());
console.log(" Comptroller: ", CORE_POOL.toLowerCase());
console.log(" Asset: ", await converter.baseAsset());

// Decode each log
for (const log of AssetTransferredLogs) {
const parsed = usdtPrimeConverter.interface.parseLog(log);
if (
(await converter.baseAsset()) == parsed.args.asset &&
parsed.args.receiver !== (await riskFundConverter.destinationAddress())
) {
// Expect the event to be emitted
await expect(tx).to.emit(converter, "AssetTransferredToDestination");
expect(parsed.args.receiver).to.equal(await converter.destinationAddress());
expect(parsed.args.comptroller.toLowerCase()).to.equal(CORE_POOL.toLowerCase());
expect(parsed.args.asset).to.equal(await converter.baseAsset());
}
}
}
});
});
});
}
});
Loading