Skip to content

Commit

Permalink
Merge pull request #46 from hai-on-op/dev
Browse files Browse the repository at this point in the history
feat: adding method to retrieve collateral from handler (#45)
  • Loading branch information
piesrtasty authored Jul 8, 2024
2 parents 048edfc + 4d88818 commit ea0bad0
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 35 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hai-on-op/sdk",
"version": "1.2.10",
"version": "1.2.11",
"description": "Javascript client for HAI",
"license": "MIT",
"main": "lib",
Expand All @@ -21,7 +21,7 @@
"**/*": "prettier --write --ignore-unknown"
},
"dependencies": {
"@hai-on-op/abis": "1.0.0",
"@hai-on-op/abis": "0.0.0-785e0b4c",
"ethers": "5.4.7"
},
"devDependencies": {
Expand Down
26 changes: 18 additions & 8 deletions solidity/contracts/VirtualUserSafes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ interface IProxyFactory {
}

interface ISafeManager {
function getSafesData(address guy)
external
view
returns (uint256[] memory ids, address[] memory safes, bytes32[] memory collateralTypes);
function getSafesData(
address guy
) external view returns (uint256[] memory ids, address[] memory safes, bytes32[] memory collateralTypes);
}

interface ISAFEEngine {
Expand All @@ -23,13 +22,15 @@ interface ISAFEEngine {
}

function safes(bytes32 collateralType, address safe) external view returns (SafeDeposit memory _safe);
function tokenCollateral(bytes32 collateralType, address safe) external view returns (uint256 collateralBalance);
}

contract VirtualUserSafes {
struct SafeData {
address addy;
uint256 id;
uint256 lockedCollateral;
uint256 freeCollateral;
uint256 generatedDebt;
bytes32 collateralType;
}
Expand All @@ -49,13 +50,22 @@ contract VirtualUserSafes {
if (userProxy == address(0)) {
safesData = new SafeData[](0);
} else {
(uint256[] memory ids, address[] memory safes, bytes32[] memory _cTypes) =
safeManager.getSafesData(userProxy);
(uint256[] memory ids, address[] memory safes, bytes32[] memory _cTypes) = safeManager.getSafesData(
userProxy
);

safesData = new SafeData[](safes.length);
for (uint256 i = 0; i < safes.length; i++) {
ISAFEEngine.SafeDeposit memory _safeData = safeEngine.safes(_cTypes[i], safes[i]);
safesData[i] = SafeData(safes[i], ids[i], _safeData.lockedCollateral, _safeData.generatedDebt, _cTypes[i]);
uint256 freeCollateral = safeEngine.tokenCollateral(_cTypes[i], safes[i]);
safesData[i] = SafeData(
safes[i],
ids[i],
_safeData.lockedCollateral,
freeCollateral,
_safeData.generatedDebt,
_cTypes[i]
);
}
}

Expand All @@ -68,4 +78,4 @@ contract VirtualUserSafes {
return(dataStart, sub(msize(), dataStart))
}
}
}
}
2 changes: 1 addition & 1 deletion src/api/contract-apis.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers } from 'ethers'
import * as types from '../typechained'
import { GebDeployment, getAddressList } from '../contracts'
import { getTokenList } from '../contracts/addreses'
import { getTokenList } from '../contracts/addresses'

// Container class used to instantiate most GEB contracts
// prettier-ignore
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/addreses.ts → src/contracts/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const addresses: Record<GebDeployment, ContractList> = {
GEB_POST_SETTLEMENT_SURPLUS_AUCTIONEER: '0x7EDaD06B56bbEC6A1C5Dd95b8D00aebc803afe43',
SAFE_MANAGER: '0xB0FF82D8322f6Fa9C28Ec46eF0A5C343e95106C3',
PROXY_FACTORY: '0xBAfbCDbFbB1569722253ED4D491D2fB3b5E03a27',
PROXY_BASIC_ACTIONS: '0xd36b1bD5445374Ceb7Fe4148a719584234Da7Bb0',
PROXY_BASIC_ACTIONS: '0x7Bd5fBa59E6FF3ad5c6937CdD83f5cAf7aA49669',
PROXY_DEBT_AUCTION_ACTIONS: '0xFC55B886a2619bd8645549f7Cb672872479F8117',
PROXY_SURPLUS_AUCTION_ACTIONS: '0x632229A0A849bde3A1f1200cF23118b33A925cEc',
PROXY_COLLATERAL_AUCTION_ACTIONS: '0xbFAc170711DFE2043f47b34F118E9FCDA8FC694D',
Expand Down Expand Up @@ -158,7 +158,7 @@ const addresses: Record<GebDeployment, ContractList> = {
GEB_POST_SETTLEMENT_SURPLUS_AUCTIONEER: '0x5486d6a98231d977AD5Ab90A5C3150fe304bD6C8',
SAFE_MANAGER: '0x1463a2D373111ace4A13b4B8147AE70789996556',
PROXY_FACTORY: '0x9fc5d3Be336FFdf0A1a5e1F9ac94340Aaa66d278',
PROXY_BASIC_ACTIONS: '0xF5348795719186D1eFAa13e1D8A3D890b2640e42',
PROXY_BASIC_ACTIONS: '0x8131Cf71e652F783D6f7393435F68FC095044E78',
PROXY_DEBT_AUCTION_ACTIONS: '0x312C5DcCd2D63b3bD29342219Dcc1dE2C4aE86d4',
PROXY_SURPLUS_AUCTION_ACTIONS: '0x2EA2f271b6C0Ad3fE5412B020B6657ef158dcb57',
PROXY_COLLATERAL_AUCTION_ACTIONS: '0x172931C396292ca8133c9a616a48E9252c3Be1b0',
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './addreses'
export * from './addresses'
export * from './base-contract-api'
export * from './chain-provider-interface'
2 changes: 1 addition & 1 deletion src/geb.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers } from 'ethers'
import { ContractApis } from './api/contract-apis'
import { Auctions } from './auctions'
import { TokenList, getTokenList } from './contracts/addreses'
import { TokenList, getTokenList } from './contracts/addresses'
import { ContractList, GebDeployment, getAddressList } from './contracts/index'
import { GebError, GebErrorTypes } from './errors'
import { BasicActions } from './proxy-action'
Expand Down
2 changes: 1 addition & 1 deletion src/liquidation-actions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BigNumberish } from '@ethersproject/bignumber'
import { ethers } from 'ethers'
import { ContractApis } from './api/contract-apis'
import { TokenList } from './contracts/addreses'
import { TokenList } from './contracts/addresses'
import { GebDeployment } from './contracts/index'

/**
Expand Down
18 changes: 17 additions & 1 deletion src/proxy-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BigNumber, BigNumberish } from '@ethersproject/bignumber'
import { ethers } from 'ethers'
import { ContractList, GebDeployment, getAddressList } from './contracts'

import { TokenList, getTokenList } from './contracts/addreses'
import { TokenList, getTokenList } from './contracts/addresses'
import * as types from './typechained'
import { NULL_ADDRESS } from './utils'

Expand Down Expand Up @@ -281,6 +281,22 @@ export class BasicActions {
)
}

collectTokenCollateral(
collateralName: string,
safe: BigNumberish,
amt: BigNumberish
): Promise<ethers.PopulatedTransaction> {
let collateralJoin = this.tokenList[collateralName].collateralJoin
return this.getProxiedTransactionRequest(
this.proxyActionCore.populateTransaction.collectTokenCollateral(
this.addressList.SAFE_MANAGER,
collateralJoin,
safe,
amt
)
)
}

// ==== Proxy Actions Global Settlement ====

freeCollateralGlobalSettlement(collateralName: string, safe: BigNumberish): Promise<ethers.PopulatedTransaction> {
Expand Down
2 changes: 1 addition & 1 deletion src/virtual/tokenData.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers } from 'ethers'
import { Geb } from '../geb'
import TokensData from '../artifacts/contracts/TokensData.sol/TokensData.json'
import { TokenData } from '../contracts/addreses'
import { TokenData } from '../contracts/addresses'

export interface TokenFetchData {
balanceE18: string
Expand Down
2 changes: 1 addition & 1 deletion src/virtual/virtualLiquidationData.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BigNumber, ethers } from 'ethers'
import { Geb } from '../geb'
import VirtualLiquidationData from '../artifacts/contracts/VirtualLiquidationData.sol/VirtualLiquidationData.json'
import { TokenData } from '../contracts/addreses'
import { TokenData } from '../contracts/addresses'

interface LiquidationData {
redemptionPrice: BigNumber
Expand Down
2 changes: 2 additions & 0 deletions src/virtual/virtualUserSafes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface SafeData {
addy: string
id: BigNumber
lockedCollateral: BigNumber
freeCollateral: BigNumber
generatedDebt: BigNumber
collateralType: string
}
Expand Down Expand Up @@ -36,6 +37,7 @@ export async function fetchUserSafes(geb: Geb, userAddress: string): Promise<[Bi
address addy,
uint256 id,
uint256 lockedCollateral,
uint256 freeCollateral,
uint256 generatedDebt,
bytes32 collateralType
)[]`,
Expand Down
38 changes: 22 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -828,21 +828,22 @@
"@ethersproject/properties" "^5.7.0"
"@ethersproject/strings" "^5.7.0"

"@hai-on-op/abis@1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@hai-on-op/abis/-/abis-1.0.0.tgz#8bf08b1d2319e3126c4e488aad3460d907bbb4f4"
integrity sha512-LJ0u+mneJhtU5RTmkIox7P4AewSsL4iKWWghrp+9K1EO99aD+uNAI3rAEVjwhBw7YatRpxdm6B2E0kkWPWC5Jg==
"@hai-on-op/abis@0.0.0-785e0b4c":
version "0.0.0-785e0b4c"
resolved "https://registry.yarnpkg.com/@hai-on-op/abis/-/abis-0.0.0-785e0b4c.tgz#4cf67055c6237a41c0eb04e4a9fd804a3d2251df"
integrity sha512-CO4jbahHz/AXo2v84UPN/qoXNLlqly5kbJ+nHP27Mw/2jAg5Tky20TmJk93EuMAWdH3wZgKi2uxP9hDH+kKPpw==
dependencies:
"@defi-wonderland/solidity-utils" "0.0.0-4298c6c6"
"@ethersproject/abi" "5.7.0"
"@ethersproject/providers" "5.7.2"
"@openzeppelin/contracts" "5.0.0"
"@openzeppelin/contracts" "5.0.1"
"@typechain/ethers-v6" "^0.5.1"
"@typechain/web3-v1" "^6.0.7"
"@uniswap/v3-periphery" "https://github.com/Uniswap/v3-periphery.git#0.8"
bn.js "5.2.1"
ds-test "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0"
ethers "6.0.3"
forge-std "https://github.com/foundry-rs/forge-std.git#f73c73d2018eb6a111f35e4dae7b4f27401e9421"
forge-std "https://github.com/foundry-rs/forge-std.git#155d547c449afa8715f538d69454b83944117811"
typechain "^8.3.2"

"@jridgewell/resolve-uri@^3.0.3":
Expand Down Expand Up @@ -912,10 +913,10 @@
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.8.1.tgz#709cfc4bbb3ca9f4460d60101f15dac6b7a2d5e4"
integrity sha512-xQ6eUZl+RDyb/FiZe1h+U7qr/f4p/SrTSQcTPH2bjur3C5DbuW/zFgCU/b1P/xcIaEqJep+9ju4xDRi3rmChdQ==

"@openzeppelin/[email protected].0":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-5.0.0.tgz#ee0e4b4564f101a5c4ee398cd4d73c0bd92b289c"
integrity sha512-bv2sdS6LKqVVMLI5+zqnNrNU/CA+6z6CmwFXm/MzmOPBRSO5reEJN7z0Gbzvs0/bv/MZZXNklubpwy3v2+azsw==
"@openzeppelin/[email protected].1":
version "5.0.1"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-5.0.1.tgz#93da90fc209a0a4ff09c1deb037fbb35e4020890"
integrity sha512-yQJaT5HDp9hYOOp4jTYxMsR02gdFZFXhewX5HW9Jo4fsqSVqqyIO/xTHdWDaKX5a3pv1txmf076Lziz+sO7L1w==

"@tsconfig/node10@^1.0.7":
version "1.0.9"
Expand Down Expand Up @@ -991,9 +992,9 @@
resolved "https://registry.yarnpkg.com/@uniswap/v3-core/-/v3-core-1.0.2-solc-0.8-simulate.tgz#77fb42f2b502b4fec81844736d039fc059e8688c"
integrity sha512-ALAZbsb3wvUrRzeAjrTKjv1fH7UrueJ/+D8uX4yintXHxxzbnnp78Kis2pa4D26cFQ72rwM3DrZpUES9rhsEuQ==

"@uniswap/v3-periphery@https://github.com/Uniswap/v3-periphery.git#0.8":
"@uniswap/v3-periphery@git+https://github.com/Uniswap/v3-periphery.git#0.8":
version "1.4.2-solc-0.8"
resolved "https://github.com/Uniswap/v3-periphery.git#b325bb0905d922ae61fcc7df85ee802e8df5e96c"
resolved "git+https://github.com/Uniswap/v3-periphery.git#b325bb0905d922ae61fcc7df85ee802e8df5e96c"
dependencies:
"@openzeppelin/contracts" "4.6.0"
"@uniswap/v2-core" "1.0.1"
Expand Down Expand Up @@ -1453,6 +1454,11 @@ dot-prop@^5.1.0:
dependencies:
is-obj "^2.0.0"

"ds-test@git+https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0":
version "1.0.0"
uid e282159d5170298eb2455a6c05280ab5a73a4ef0
resolved "git+https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0"

"ds-test@https://github.com/dapphub/ds-test":
version "1.0.0"
resolved "https://github.com/dapphub/ds-test#e282159d5170298eb2455a6c05280ab5a73a4ef0"
Expand Down Expand Up @@ -1633,14 +1639,14 @@ find-up@^5.0.0:
locate-path "^6.0.0"
path-exists "^4.0.0"

"forge-std@git+https://github.com/foundry-rs/forge-std.git#155d547c449afa8715f538d69454b83944117811":
version "1.7.4"
resolved "git+https://github.com/foundry-rs/forge-std.git#155d547c449afa8715f538d69454b83944117811"

"forge-std@https://github.com/foundry-rs/forge-std":
version "1.6.0"
resolved "https://github.com/foundry-rs/forge-std#7742caf9a5c9f20af90ef2801b5f0c4b7f29a8f5"

"forge-std@https://github.com/foundry-rs/forge-std.git#f73c73d2018eb6a111f35e4dae7b4f27401e9421":
version "1.7.1"
resolved "https://github.com/foundry-rs/forge-std.git#f73c73d2018eb6a111f35e4dae7b4f27401e9421"

fs-extra@^11.0.0:
version "11.1.1"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.1.1.tgz#da69f7c39f3b002378b0954bb6ae7efdc0876e2d"
Expand Down

0 comments on commit ea0bad0

Please sign in to comment.