From 8ab58297b16e23ecea47e27dd959edc86ee693d4 Mon Sep 17 00:00:00 2001 From: 0xdavinchee <0xdavinchee@gmail.com> Date: Tue, 24 Oct 2023 12:49:14 +0300 Subject: [PATCH] [SDK-CORE] GoodDollar sdk core fix (#1734) * fix supertoken initialization for gooddollar * bump version + update changelog * use governance address from networkData * gooddollar symbol --------- Co-authored-by: Kaspar Kallas --- packages/sdk-core/CHANGELOG.md | 5 ++++ packages/sdk-core/package.json | 2 +- packages/sdk-core/src/Framework.ts | 19 +++++------- packages/sdk-core/src/SuperToken.ts | 46 ++++++++++++++++++++++++++--- 4 files changed, 55 insertions(+), 17 deletions(-) diff --git a/packages/sdk-core/CHANGELOG.md b/packages/sdk-core/CHANGELOG.md index e52a669066..5e0dca827a 100644 --- a/packages/sdk-core/CHANGELOG.md +++ b/packages/sdk-core/CHANGELOG.md @@ -5,6 +5,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] +## [0.6.12] - 2023-10-23 + +### Fixed +- Support for `CustomSuperToken` contracts without `CONSTANT_OUTFLOW_NFT()` and `CONSTANT_INFLOW_NFT()` function implemented + ## [0.6.11] - 2023-10-20 ### Fixed diff --git a/packages/sdk-core/package.json b/packages/sdk-core/package.json index 7953193b94..8efc2f3548 100644 --- a/packages/sdk-core/package.json +++ b/packages/sdk-core/package.json @@ -1,6 +1,6 @@ { "name": "@superfluid-finance/sdk-core", - "version": "0.6.11", + "version": "0.6.12", "description": "SDK Core for building with Superfluid Protocol", "homepage": "https://github.com/superfluid-finance/protocol-monorepo/tree/dev/packages/sdk-core#readme", "repository": { diff --git a/packages/sdk-core/src/Framework.ts b/packages/sdk-core/src/Framework.ts index df663fe217..f1102681d5 100644 --- a/packages/sdk-core/src/Framework.ts +++ b/packages/sdk-core/src/Framework.ts @@ -176,18 +176,13 @@ export default class Framework { }; // supported networks scenario - if ( - networkData != null && - baseSettings.protocolReleaseVersion === V1 - ) { - let governanceAddress = ethers.constants.AddressZero; - - if (networkData.addresses.governance == null) { - governanceAddress = await Superfluid__factory.connect( - networkData.addresses.host, - provider - ).getGovernance(); - } + if (networkData && baseSettings.protocolReleaseVersion === V1) { + const governanceAddress = networkData.addresses.governance + ? networkData.addresses.governance + : await Superfluid__factory.connect( + networkData.addresses.host, + provider + ).getGovernance(); const settings: IFrameworkSettings = { ...baseSettings, diff --git a/packages/sdk-core/src/SuperToken.ts b/packages/sdk-core/src/SuperToken.ts index 12ab5dffe2..1d7f67e889 100644 --- a/packages/sdk-core/src/SuperToken.ts +++ b/packages/sdk-core/src/SuperToken.ts @@ -162,10 +162,48 @@ export default abstract class SuperToken extends ERC20Token { const nativeTokenSymbol = resolverData.nativeTokenSymbol || "ETH"; const nativeSuperTokenSymbol = nativeTokenSymbol + "x"; - const constantOutflowNFTProxy = - await superToken.CONSTANT_OUTFLOW_NFT(); - const constantInflowNFTProxy = - await superToken.CONSTANT_INFLOW_NFT(); + // @note This is tech debt and should be reverted once GoodDollar upgrades their token contract + // @note We are using tryGet here just to handle GoodDollar not having + // CONSTANT_OUTFLOW_NFT in its SuperToken implementation. + let constantOutflowNFTProxy = await tryGet( + superToken.CONSTANT_OUTFLOW_NFT(), + ethers.constants.AddressZero + ); + let constantInflowNFTProxy = await tryGet( + superToken.CONSTANT_INFLOW_NFT(), + ethers.constants.AddressZero + ); + + // @note We only want to run this bit of code for GoodDollar SuperTokens + // (dev and mainnet) + const GOOD_DOLLAR_SYMBOL = "G$"; + if (tokenSymbol === GOOD_DOLLAR_SYMBOL) { + // @note we need to create a new interface for the old GoodDollar SuperToken + // which contains the functions for constantInflowNFT and constantOutflowNFT + const oldSuperTokenInterface = new ethers.utils.Interface([ + "function constantInflowNFT() view returns (address)", + "function constantOutflowNFT() view returns (address)", + ]); + const goodDollarSpecificToken = new ethers.Contract( + superToken.address, + oldSuperTokenInterface + ); + + // @note we attempt to get the constantInflowNFT and constantOutflowNFT + if (constantOutflowNFTProxy === ethers.constants.AddressZero) { + constantOutflowNFTProxy = await tryGet( + goodDollarSpecificToken.constantOutflowNFT(), + ethers.constants.AddressZero + ); + } + if (constantInflowNFTProxy === ethers.constants.AddressZero) { + constantInflowNFTProxy = await tryGet( + goodDollarSpecificToken.constantInflowNFT(), + ethers.constants.AddressZero + ); + } + } + const nftAddresses: NFTAddresses = { constantOutflowNFTProxy, constantInflowNFTProxy,