Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add SUSDS connectors #32

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
17 changes: 17 additions & 0 deletions contracts/mainnet/connectors/susds/events.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;

contract Events {
event LogDeposit(
uint256 usdsAmount,
uint256 susdsAmount,
uint256 getId,
uint256 setId
);
event LogWithdraw(
uint256 susdsAmount,
uint256 usdsAmount,
uint256 getId,
uint256 setId
);
}
24 changes: 24 additions & 0 deletions contracts/mainnet/connectors/susds/helpers.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;

import {ISUSDS} from "./interfaces.sol";
import {TokenInterface} from "../../common/interfaces.sol";

contract Helpers {
/**
* @dev referral key
*/
uint16 internal constant referralKey = 0;

/**
* @dev susds interface
*/
ISUSDS internal constant susds =
ISUSDS(0xa3931d71877C0E7a3148CB7Eb4463524FEc27fbD);

/**
* @dev usds interface
*/
TokenInterface internal constant usds =
TokenInterface(0xdC035D45d973E3EC169d2276DDab16f1e407384F);
}
20 changes: 20 additions & 0 deletions contracts/mainnet/connectors/susds/interfaces.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;

interface ISUSDS {
function approve(address, uint256) external;

function balanceOf(address) external view returns (uint256);

function deposit(
uint256 assets,
address receiver,
uint16 referral
) external returns (uint256 shares);

function withdraw(
uint256 assets,
address receiver,
address owner
) external returns (uint256 shares);
}
69 changes: 69 additions & 0 deletions contracts/mainnet/connectors/susds/main.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;

import {Helpers} from "./helpers.sol";
import {Events} from "./events.sol";
import {Basic} from "../../common/basic.sol";

contract SUSDSConnector is Basic, Helpers, Events {
/**
* @dev Deposit USDS into sUSDS.
* @notice Deposit USDS into sUSDS (Saving USDS).
* @param usdsAmount The amount of USDS to deposit. (For max: `uint256(-1)`)
* @param getId ID to retrieve USDS amount.
* @param setId ID stores the amount of sUSDS.
*/
function deposit(
uint256 usdsAmount,
uint256 getId,
uint256 setId
) external returns (string memory _eventName, bytes memory _eventParam) {
uint256 _usdsAmount = getUint(getId, usdsAmount);
_usdsAmount = _usdsAmount == type(uint).max
? usds.balanceOf(address(this))
: _usdsAmount;

// TODO: Obtain referral code
usds.approve(address(susds), _usdsAmount);
uint256 _susdsAmount = susds.deposit(_usdsAmount, address(this), 0); // this returns shares

setUint(setId, _susdsAmount);

_eventName = "LogDeposit(uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(_usdsAmount, _susdsAmount, getId, setId);
}

/**
* @dev Withdraw sUSDS into USDS.
* @notice Withdraw sUSDS into USDS (Saving USDS).
* @param susdsAmount The amount of USDS to withdraw. (For max: `uint256(-1)`)
* @param getId ID to retrieve sUSDS amount.
* @param setId ID stores the amount of USDS.
*/
function withdraw(
uint256 susdsAmount,
uint256 getId,
uint256 setId
) external returns (string memory _eventName, bytes memory _eventParam) {
uint256 _susdsAmount = getUint(getId, susdsAmount);
_susdsAmount = _susdsAmount == type(uint).max
? susds.balanceOf(address(this))
: _susdsAmount;

susds.approve(address(susds), _susdsAmount);
uint256 _usdsAmount = susds.withdraw(
_susdsAmount,
address(this),
address(this)
); // this returns shares

setUint(setId, _usdsAmount);

_eventName = "LogWithdraw(uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(_susdsAmount, _usdsAmount, getId, setId);
}
}

contract ConnectV2SUSDS is SUSDSConnector {
string public constant name = "SUSDS-v1.0";
}