Skip to content

Commit 908b44d

Browse files
committed
fix: single usd erc20
1 parent 2a79d11 commit 908b44d

File tree

2 files changed

+14
-61
lines changed

2 files changed

+14
-61
lines changed

ethereum/contracts/Marketplace.sol

+12-29
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ import {Deferred} from "./Deferred.sol";
88
import {RewardPool} from "./RewardPool.sol";
99

1010
contract Marketplace is Ownable {
11-
/// @notice The address of the USDT token
12-
address private usdt;
13-
14-
/// @notice The address of the USDC token
15-
address private usdc;
11+
/// @notice The address of the USD ERC20 token
12+
address public usdErc20;
1613

1714
/// @notice The address of the EKOKE token
1815
address private ekoke;
@@ -41,20 +38,19 @@ contract Marketplace is Ownable {
4138

4239
constructor(
4340
address _owner,
44-
address _usdt,
45-
address _usdc,
41+
address _usdErc20,
4642
address _ekoke,
4743
address _deferred
4844
) Ownable(_owner) {
49-
require(_usdt != address(0), "Marketplace: USDT address is zero");
50-
require(_usdc != address(0), "Marketplace: USDC address is zero");
51-
require(_ekoke != address(0), "Marketplace: EKOKE address is zero");
45+
require(
46+
_usdErc20 != address(0),
47+
"Marketplace: USD ERC20 address is zero"
48+
);
5249
require(
5350
_deferred != address(0),
5451
"Marketplace: Deferred address is zero"
5552
);
56-
usdt = _usdt;
57-
usdc = _usdc;
53+
usdErc20 = _usdErc20;
5854
ekoke = _ekoke;
5955
deferred = _deferred;
6056
}
@@ -79,22 +75,9 @@ contract Marketplace is Ownable {
7975
interestRate = _interestRate;
8076
}
8177

82-
/// @notice Buy a deferred NFT with USDT
83-
/// @param _tokenId The ID of the deferred NFT
84-
function buyTokenWithUSDT(uint256 _tokenId) external {
85-
buyToken(_tokenId, usdt);
86-
}
87-
88-
/// @notice Buy a deferred NFT with USDC
89-
/// @param _tokenId The ID of the deferred NFT
90-
function buyTokenWithUSDC(uint256 _tokenId) external {
91-
buyToken(_tokenId, usdc);
92-
}
93-
94-
/// @notice Buy a deferred NFT with the provided currency
95-
/// @param _tokenId The ID of the deferred NFT
96-
/// @param _currency The address of the currency
97-
function buyToken(uint256 _tokenId, address _currency) internal {
78+
/// @notice Buy a deferred NFT with the configured USD ERC20 token
79+
/// @param _tokenId The ID of the deferred NFT\
80+
function buyToken(uint256 _tokenId) external {
9881
require(rewardPool != address(0), "Marketplace: Reward pool not set");
9982

10083
// get the contract from deferred
@@ -121,7 +104,7 @@ contract Marketplace is Ownable {
121104
sellContract.ekokeReward > 0;
122105

123106
// get the currency token
124-
ERC20 currency = ERC20(_currency);
107+
ERC20 currency = ERC20(usdErc20);
125108

126109
// get the required allowance
127110
uint256 requiredAllowance = isContractBuyer

ethereum/test/Marketplace.ts

+2-32
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ describe("RewardPool", () => {
1212
deferred: Deferred;
1313
rewardPool: RewardPool;
1414
ekoke: Ekoke;
15-
usdc: Ekoke;
1615
usdt: Ekoke;
1716
owner: SignerWithAddress;
1817
seller: SignerWithAddress;
@@ -36,12 +35,6 @@ describe("RewardPool", () => {
3635
await usdt.adminMint(buyer.address, 1000);
3736
await usdt.adminMint(thirdParty.address, 1000);
3837

39-
const usdcContract = await ethers.deployContract("Ekoke", [owner.address]);
40-
const usdc = usdcContract as unknown as Ekoke;
41-
// mint 1000 USDC to alice
42-
await usdc.adminMint(buyer.address, 1000);
43-
await usdc.adminMint(thirdParty.address, 1000);
44-
4538
const deferredContract = await ethers.deployContract("Deferred", [
4639
owner.address,
4740
]);
@@ -57,7 +50,6 @@ describe("RewardPool", () => {
5750
const marketplaceContract = await ethers.deployContract("Marketplace", [
5851
owner.address,
5952
usdt.getAddress(),
60-
usdc.getAddress(),
6153
ekoke.getAddress(),
6254
deferred.getAddress(),
6355
]);
@@ -97,7 +89,6 @@ describe("RewardPool", () => {
9789
seller,
9890
minter,
9991
usdt,
100-
usdc,
10192
thirdParty,
10293
};
10394
});
@@ -109,7 +100,7 @@ describe("RewardPool", () => {
109100
// give allowance to marketplace
110101
await usdt.connect(thirdParty).approve(marketplace.getAddress(), USD_PRICE);
111102
// buy
112-
await marketplace.connect(thirdParty).buyTokenWithUSDT(tokenId);
103+
await marketplace.connect(thirdParty).buyToken(tokenId);
113104

114105
// USDT balance of buyer
115106
expect(await usdt.balanceOf(thirdParty.address)).to.equal(1000 - USD_PRICE);
@@ -123,27 +114,6 @@ describe("RewardPool", () => {
123114
expect(await ekoke.balanceOf(thirdParty.address)).to.equal(EKOKE_REWARD);
124115
});
125116

126-
it("Should buy a NFT with USDC as third-party", async () => {
127-
const { marketplace, thirdParty, seller, deferred, ekoke, usdc } = deploy;
128-
129-
const tokenId = 0;
130-
// give allowance to marketplace
131-
await usdc.connect(thirdParty).approve(marketplace.getAddress(), USD_PRICE);
132-
// buy
133-
await marketplace.connect(thirdParty).buyTokenWithUSDC(tokenId);
134-
135-
// USDT balance of buyer
136-
expect(await usdc.balanceOf(thirdParty.address)).to.equal(1000 - USD_PRICE);
137-
// USDT balance of seller
138-
expect(await usdc.balanceOf(seller.address)).to.equal(USD_PRICE);
139-
140-
// check NFT has been transferred
141-
expect(await deferred.ownerOf(tokenId)).to.equal(thirdParty.address);
142-
143-
// check buyer has received the reward
144-
expect(await ekoke.balanceOf(thirdParty.address)).to.equal(EKOKE_REWARD);
145-
});
146-
147117
it("Should buy a NFT with USDT as contract buyer", async () => {
148118
const { marketplace, buyer, seller, deferred, ekoke, usdt } = deploy;
149119

@@ -154,7 +124,7 @@ describe("RewardPool", () => {
154124
.connect(buyer)
155125
.approve(marketplace.getAddress(), USD_PRICE + interest);
156126
// buy
157-
await marketplace.connect(buyer).buyTokenWithUSDT(tokenId);
127+
await marketplace.connect(buyer).buyToken(tokenId);
158128

159129
// USDT balance of buyer
160130
expect(await usdt.balanceOf(buyer.address)).to.equal(

0 commit comments

Comments
 (0)