Skip to content

Commit

Permalink
Sdk supported assets filter (#5283)
Browse files Browse the repository at this point in the history
* feat: allow disabling chains or assets

* chore: disable usdt and dai from sdk server

* feat: config consistency with wrapper

* chore: bump sdk version

* test: getSupported filter

* test: fix test
  • Loading branch information
just-a-node authored and wanglonghong committed Dec 6, 2023
1 parent 3585200 commit a9e11c0
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 29 deletions.
5 changes: 3 additions & 2 deletions ops/mainnet/prod/backend/config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ locals {
providers = ["https://rpc.ankr.com/gnosis"]
}
"1818848877" = {
providers = ["https://rpc.linea.build"]
providers = ["https://rpc.linea.build"]
disabledAssets = ["0xA219439258ca9da29E9Cc4cE5596924745e12B93", "0x4AF15ec2A0BD43Db75dd04E62FAA3B8EF36b00d5"]
}
}

Expand Down Expand Up @@ -84,7 +85,7 @@ locals {
"1634886255" = { confirmations = 1 }
"6450786" = { confirmations = 50 }
"6778479" = { confirmations = 100 }
"1818848877" = { confirmations = 10 }
"1818848877" = { confirmations = 10 }
}
environment = var.stage
healthUrls = {
Expand Down
8 changes: 8 additions & 0 deletions packages/agents/sdk-wrapper/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Next Release

## v2.2.0-alpha.4

- `getSupported`: Filters out disabled assets/chains from config

## v2.2.0-alpha.3

- `getTransfers`: Fix query syntax

## v2.2.0-alpha.0

- Linea mainnet support
Expand Down
2 changes: 1 addition & 1 deletion packages/agents/sdk-wrapper/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@connext/sdk",
"version": "2.2.0-alpha.1",
"version": "2.2.0-alpha.4",
"description": "Client-side package for interacting with the Connext protocol",
"author": "Connext",
"license": "MIT",
Expand Down
6 changes: 5 additions & 1 deletion packages/agents/sdk-wrapper/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export const TChainConfig = Type.Object({
confirmations: Type.Optional(Type.Integer({ minimum: 1 })), // What we consider the "safe confirmations" number for this chain.
chainId: Type.Optional(Type.Number()),
deployments: Type.Optional(TChainDeployments),
assets: Type.Optional(Type.Array(TAssetDescription)), /// Not Being Used
disabled: Type.Optional(Type.Boolean()),
disabledAssets: Type.Optional(Type.Array(TAddress)), // By adopted address
});

export type ChainConfig = Static<typeof TChainConfig>;
Expand Down Expand Up @@ -105,6 +106,9 @@ export const getEnvConfig = (
: (`${nxtpConfig.environment![0].toUpperCase()}${nxtpConfig.environment!.slice(1)}` as ContractPostfix);
// add contract deployments if they exist
Object.entries(nxtpConfig.chains).forEach(([domainId, chainConfig]) => {
nxtpConfig.chains[domainId].disabled = chainConfig.disabled ?? false;
nxtpConfig.chains[domainId].disabledAssets = chainConfig.disabledAssets ?? [];

const chainDataForChain = chainData.get(domainId);
const chainRecommendedConfirmations = chainDataForChain?.confirmations ?? defaultConfirmations;
const chainRecommendedGasStations = chainDataForChain?.gasStations ?? [];
Expand Down
8 changes: 8 additions & 0 deletions packages/agents/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Next Release

## v2.2.0-alpha.4

- `getSupported`: Filters out disabled assets/chains from config

## v2.2.0-alpha.3

- `getTransfers`: Fix query syntax

## v2.2.0-alpha.0

- Linea mainnet support
Expand Down
2 changes: 1 addition & 1 deletion packages/agents/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@connext/sdk-core",
"version": "2.2.0-alpha.1",
"version": "2.2.0-alpha.4",
"description": "Client-side package for interacting with the Connext protocol",
"author": "Connext",
"license": "MIT",
Expand Down
6 changes: 5 additions & 1 deletion packages/agents/sdk/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export const TChainConfig = Type.Object({
confirmations: Type.Optional(Type.Integer({ minimum: 1 })), // What we consider the "safe confirmations" number for this chain.
chainId: Type.Optional(Type.Number()),
deployments: Type.Optional(TChainDeployments),
assets: Type.Optional(Type.Array(TAssetDescription)), /// Not Being Used
disabled: Type.Optional(Type.Boolean()),
disabledAssets: Type.Optional(Type.Array(TAddress)), // By adopted address
});

export type ChainConfig = Static<typeof TChainConfig>;
Expand Down Expand Up @@ -105,6 +106,9 @@ export const getEnvConfig = (
: (`${nxtpConfig.environment![0].toUpperCase()}${nxtpConfig.environment!.slice(1)}` as ContractPostfix);
// add contract deployments if they exist
Object.entries(nxtpConfig.chains).forEach(([domainId, chainConfig]) => {
nxtpConfig.chains[domainId].disabled = chainConfig.disabled ?? false;
nxtpConfig.chains[domainId].disabledAssets = chainConfig.disabledAssets ?? [];

const chainDataForChain = chainData.get(domainId);
const chainRecommendedConfirmations = chainDataForChain?.confirmations ?? defaultConfirmations;
const chainRecommendedGasStations = chainDataForChain?.gasStations ?? [];
Expand Down
26 changes: 14 additions & 12 deletions packages/agents/sdk/src/sdkShared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,21 +362,23 @@ export class SdkShared {
*/
async getSupported(): Promise<ConnextSupport[]> {
const data: AssetData[] = await this.getAssetsData();

const supported: Map<string, ConnextSupport> = new Map();

for (const asset of data) {
const support = supported.get(asset.domain);
if (support) {
support.assets.push(asset.adopted);
} else {
const entry: ConnextSupport = {
name: domainsToChainNames[asset.domain],
chainId: _domainToChainId(+asset.domain),
domainId: asset.domain,
assets: [asset.adopted],
};
supported.set(asset.domain, entry);
const chainConfig = this.config.chains[asset.domain];
if (!chainConfig.disabled && !chainConfig.disabledAssets?.includes(utils.getAddress(asset.adopted))) {
const support = supported.get(asset.domain);
if (support) {
support.assets.push(asset.adopted);
} else {
const entry: ConnextSupport = {
name: domainsToChainNames[asset.domain],
chainId: _domainToChainId(+asset.domain),
domainId: asset.domain,
assets: [asset.adopted],
};
supported.set(asset.domain, entry);
}
}
}

Expand Down
31 changes: 20 additions & 11 deletions packages/agents/sdk/test/sdkShared.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ describe("SdkShared", () => {
stub(SharedFns, "axiosGetRequest").resolves([]);

sdkShared = new SdkShared(mockConfig, logger, mockChainData);
// console.log(sdkShared.config.chains);
// console.log(sdkShared.config.chains[13337]);
// console.log(sdkShared.config.chains[13338]);
});

afterEach(() => {
Expand Down Expand Up @@ -133,14 +136,6 @@ describe("SdkShared", () => {
});
});

describe("#getSupported", () => {
it("happy: should work", async () => {
(sdkShared as any).config.cartographerUrl = config.cartographerUrl;
const connext = await sdkShared.getSupported();
expect(connext).to.not.be.undefined;
});
});

describe("#providerSanityCheck", () => {
it("happy: should return true with a domain in existing config", async () => {
const params = { domains: [mock.domain.A] };
Expand Down Expand Up @@ -322,6 +317,7 @@ describe("SdkShared", () => {

describe("#getAssetsData", () => {
it("happy: should work", async () => {
sdkShared.config.cartographerUrl = config.cartographerUrl;
restore();
stub(SharedFns, "axiosGetRequest").resolves([mockAssetData]);
const res = await sdkShared.getAssetsData();
Expand Down Expand Up @@ -427,9 +423,22 @@ describe("SdkShared", () => {

describe("#getSupported", () => {
it("happy: should work", async () => {
(sdkShared as any).config.cartographerUrl = config.cartographerUrl;
const connext = await sdkShared.getSupported();
expect(connext).to.not.be.undefined;
sdkShared.config.cartographerUrl = config.cartographerUrl;
restore();
stub(sdkShared, "getAssetsData").resolves([mockAssetData]);

const supported = await sdkShared.getSupported();
expect(supported.length).to.be.eq(1);
});

it("happy: should filter out assets disabled in config", async () => {
sdkShared.config.cartographerUrl = config.cartographerUrl;
restore();
stub(sdkShared, "getAssetsData").resolves([mockAssetData]);
sdkShared.config.chains[mock.domain.A].disabledAssets = [mock.asset.B.address];

const supported = await sdkShared.getSupported();
expect(supported.length).to.be.eq(0);
});
});

Expand Down

0 comments on commit a9e11c0

Please sign in to comment.