Skip to content

Commit 736ecea

Browse files
authored
Merge pull request #3821 from connext/main
Staging sync
2 parents a4b1901 + 5559d73 commit 736ecea

File tree

26 files changed

+244
-24
lines changed

26 files changed

+244
-24
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
## Next Release
44

5-
- [sdk] Add removeLiquidityOneToken method
5+
## Amarok 1.2.0-alpha.0
6+
7+
- [sdk] Add removeLiquidityOneToken, removeLiquidityImbalance, calculateRemoveSwapLiquidityOneToken methods
68

79
## Amarok 1.0.3-alpha.2
810

ops/testnet/staging/core/config.tf

+24-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ locals {
9191
"1734439522" = {
9292
providers = ["https://arb-goerli.g.alchemy.com/v2/${var.arbgoerli_alchemy_key_0}", "https://goerli-rollup.arbitrum.io/rpc"]
9393
}
94+
"2053862260" = {
95+
providers = ["https://zksync2-testnet.zksync.dev"]
96+
}
9497
}
9598
web3SignerUrl = "https://${module.sequencer_web3signer.service_endpoint}"
9699
relayers = [
@@ -141,6 +144,12 @@ locals {
141144
queueLimit = 10000
142145
subscribe = true
143146
},
147+
{
148+
name = "2053862260"
149+
limit = 1
150+
queueLimit = 10000
151+
subscribe = true
152+
},
144153
{
145154
name = "1734439522"
146155
limit = 1
@@ -164,6 +173,11 @@ locals {
164173
target = "9991"
165174
keys = ["9991"]
166175
},
176+
{
177+
exchange = "sequencerX"
178+
target = "2053862260"
179+
keys = ["2053862260"]
180+
},
167181
{
168182
exchange = "sequencerX"
169183
target = "1734439522"
@@ -207,6 +221,9 @@ locals {
207221
"1734439522" = {
208222
providers = ["https://arb-goerli.g.alchemy.com/v2/${var.arbgoerli_alchemy_key_0}", "https://goerli-rollup.arbitrum.io/rpc"]
209223
}
224+
"2053862260" = {
225+
providers = ["https://zksync2-testnet.zksync.dev"]
226+
}
210227
}
211228
cartographerUrl = "https://postgrest.testnet.staging.connext.ninja"
212229
web3SignerUrl = "https://${module.router_web3signer.service_endpoint}"
@@ -231,6 +248,9 @@ locals {
231248
"1734439522" = {
232249
providers = ["https://arb-goerli.g.alchemy.com/v2/${var.arbgoerli_alchemy_key_0}", "https://goerli-rollup.arbitrum.io/rpc"]
233250
}
251+
"2053862260" = {
252+
providers = ["https://zksync2-testnet.zksync.dev"]
253+
}
234254
}
235255
gelatoApiKey = "${var.gelato_api_key}"
236256
relayers = [
@@ -275,6 +295,9 @@ locals {
275295
"1734439522" = {
276296
providers = ["https://arb-goerli.g.alchemy.com/v2/${var.arbgoerli_alchemy_key_0}", "https://goerli-rollup.arbitrum.io/rpc"]
277297
}
298+
"2053862260" = {
299+
providers = ["https://zksync2-testnet.zksync.dev"]
300+
}
278301
}
279302
environment = var.stage
280303
web3SignerUrl = "https://${module.relayer_web3signer.service_endpoint}"
@@ -284,7 +307,7 @@ locals {
284307
server = {
285308
adminToken = var.admin_token_watcher
286309
}
287-
logLevel = "debug"
310+
logLevel = "debug"
288311
environment = "staging"
289312
chains = {
290313
"1735353714" = {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@connext/nxtp",
3-
"version": "1.1.0-alpha.0",
3+
"version": "1.2.0-alpha.0",
44
"private": true,
55
"devDependencies": {
66
"@istanbuljs/nyc-config-typescript": "1.0.2",

packages/adapters/cache/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@connext/nxtp-adapters-cache",
3-
"version": "1.1.0-alpha.0",
3+
"version": "1.2.0-alpha.0",
44
"description": "adapter for handling communication with Redis cache for nxtp protocol",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

packages/adapters/database/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@connext/nxtp-adapters-database",
3-
"version": "1.1.0-alpha.0",
3+
"version": "1.2.0-alpha.0",
44
"description": "adapter for handling communication with Redis cache for nxtp protocol",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

packages/adapters/relayer/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@connext/nxtp-adapters-relayer",
3-
"version": "1.1.0-alpha.0",
3+
"version": "1.2.0-alpha.0",
44
"description": "adapter for handling communication with relayer",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

packages/adapters/subgraph/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@connext/nxtp-adapters-subgraph",
3-
"version": "1.1.0-alpha.0",
3+
"version": "1.2.0-alpha.0",
44
"description": "adapter for subgraph interaction of nxtp protocol",
55
"main": "dist/src/index.js",
66
"types": "dist/src/index.d.ts",

packages/adapters/txservice/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@connext/nxtp-txservice",
3-
"version": "1.1.0-alpha.0",
3+
"version": "1.2.0-alpha.0",
44
"description": "Robust transaction sending service for a wallet configured across multiple chains. Will bump gas and reattempt transactions as needed",
55
"author": "Connext",
66
"license": "MIT",

packages/adapters/watcher/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@connext/nxtp-adapters-watcher",
3-
"version": "1.1.0-alpha.0",
3+
"version": "1.2.0-alpha.0",
44
"description": "adapter for watcher related calls, monitoring, and functionality",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

packages/adapters/web3signer/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@connext/nxtp-adapters-web3signer",
3-
"version": "1.1.0-alpha.0",
3+
"version": "1.2.0-alpha.0",
44
"description": "adapter for subgraph interaction of nxtp protocol",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

packages/agents/cartographer/poller/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@connext/cartographer-poller",
3-
"version": "1.1.0-alpha.0",
3+
"version": "1.2.0-alpha.0",
44
"description": "",
55
"types": "dist/index.d.ts",
66
"files": [

packages/agents/lighthouse/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@connext/lighthouse",
3-
"version": "1.1.0-alpha.0",
3+
"version": "1.2.0-alpha.0",
44
"description": "",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

packages/agents/relayer/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@connext/nxtp-relayer",
3-
"version": "1.1.0-alpha.0",
3+
"version": "1.2.0-alpha.0",
44
"description": "Generic relayer agent for Amarok",
55
"author": "Connext",
66
"license": "MIT",

packages/agents/router/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@connext/nxtp-router",
3-
"version": "1.1.0-alpha.0",
3+
"version": "1.2.0-alpha.0",
44
"description": "",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

packages/agents/sdk/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@connext/sdk",
3-
"version": "1.1.0-alpha.0",
3+
"version": "1.2.0-alpha.0",
44
"description": "Client-side package for interacting with the NXTP protocol for crosschain packages",
55
"author": "Connext",
66
"license": "MIT",

packages/agents/sdk/src/sdkPool.ts

+85-3
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export class SdkPool extends SdkShared {
248248
}
249249

250250
/**
251-
* Calculates the amounts of underlying tokens returned.
251+
* Calculates the amounts of underlying tokens returned.
252252
*
253253
* @param domainId - The domain ID of the pool.
254254
* @param tokenAddress - The address of local or adopted token.
@@ -268,6 +268,33 @@ export class SdkPool extends SdkShared {
268268
return amounts;
269269
}
270270

271+
/**
272+
* Calculate the dy, the amount of selected token that user receives
273+
*
274+
* @param domainId - The domain ID of the pool.
275+
* @param tokenAddress - The address of local or adopted token.
276+
* @param amount - The amount of the LP token to burn on withdrawal.
277+
* @param index - The index of the token to withdraw.
278+
* @returns availableTokenAmount calculated amount of underlying token
279+
*/
280+
async calculateRemoveSwapLiquidityOneToken(
281+
domainId: string,
282+
tokenAddress: string,
283+
amount: string,
284+
index: number,
285+
): Promise<BigNumber> {
286+
const _tokenAddress = utils.getAddress(tokenAddress);
287+
288+
const [connextContract, [canonicalDomain, canonicalId]] = await Promise.all([
289+
this.getConnext(domainId),
290+
this.getCanonicalTokenId(domainId, _tokenAddress),
291+
]);
292+
const key = this.calculateCanonicalKey(canonicalDomain, canonicalId);
293+
const available = await connextContract.calculateRemoveSwapLiquidityOneToken(key, amount, index);
294+
295+
return available;
296+
}
297+
271298
/**
272299
* Calculates the price impact depending on whether liquidity is being deposited or withdrawn.
273300
*
@@ -845,8 +872,8 @@ export class SdkPool extends SdkShared {
845872
*
846873
* @param domainId - The domain ID of the pool.
847874
* @param tokenAddress - The address of local or adopted token.
848-
* @param amount - The amount of the token to swap.
849-
* @param minAmounts - (optional) The minimum acceptable amounts of each token to withdraw.
875+
* @param amount - The amount of the LP token to remove.
876+
* @param minAmounts - (optional) The minimum amounts of each token in the pool
850877
* @param deadline - (optional) The deadline for the swap.
851878
* @returns providers.TransactionRequest object.
852879
*/
@@ -879,6 +906,61 @@ export class SdkPool extends SdkShared {
879906
return txRequest;
880907
}
881908

909+
/**
910+
* Returns the transaction request for removing liquidity from the pool, weighted differently than the
911+
* pool's current balances.
912+
*
913+
* @param domainId - The domain ID of the pool.
914+
* @param tokenAddress - The address of local or adopted token.
915+
* @param amounts - The amounts of the each token to remove.
916+
* @param maxBurnAmount - (optional) The max LP token provider is willing to pay to
917+
* @param deadline - (optional) The deadline for the swap.
918+
* @returns providers.TransactionRequest object.
919+
*/
920+
async removeLiquidityImbalance(
921+
domainId: string,
922+
tokenAddress: string,
923+
amounts: string[],
924+
maxBurnAmount = "0",
925+
deadline = this.getDefaultDeadline(),
926+
): Promise<providers.TransactionRequest> {
927+
const { requestContext, methodContext } = createLoggingContext(this.removeLiquidityImbalance.name);
928+
this.logger.info("Method start", requestContext, methodContext, { domainId, amounts, maxBurnAmount, deadline });
929+
930+
const _tokenAddress = utils.getAddress(tokenAddress);
931+
932+
const signerAddress = this.config.signerAddress;
933+
if (!signerAddress) {
934+
throw new SignerAddressMissing();
935+
}
936+
937+
const [connextContract, [canonicalDomain, canonicalId]] = await Promise.all([
938+
this.getConnext(domainId),
939+
this.getCanonicalTokenId(domainId, _tokenAddress),
940+
]);
941+
const key = this.calculateCanonicalKey(canonicalDomain, canonicalId);
942+
943+
if (maxBurnAmount === "0" || !maxBurnAmount) {
944+
const poolDataResults = await this.getPoolData({ key: key, domainId: domainId });
945+
if (!poolDataResults || poolDataResults.length == 0) {
946+
this.logger.debug(`No Pool for token ${_tokenAddress} on domain ${domainId}`);
947+
}
948+
const poolData = poolDataResults[0]; // there should only be one pool
949+
maxBurnAmount = (await this.getTokenUserBalance(domainId, String(poolData.lp_token), signerAddress)).toString();
950+
}
951+
952+
const txRequest = await connextContract.populateTransaction.removeSwapLiquidityImbalance(
953+
key,
954+
amounts,
955+
maxBurnAmount,
956+
deadline,
957+
);
958+
959+
this.logger.info(`${this.removeLiquidityImbalance.name} transaction created `, requestContext, methodContext);
960+
961+
return txRequest;
962+
}
963+
882964
/**
883965
* Returns the transaction request for performing a swap in a pool.
884966
*

packages/agents/sdk/test/sdkPool.spec.ts

+38
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,44 @@ describe("SdkPool", () => {
252252
});
253253
});
254254

255+
describe("#removeLiquidityImbalance", () => {
256+
const mockParams = {
257+
canonicalId: utils.formatBytes32String("0"),
258+
amounts: ["100", "100"],
259+
maxBurnAmount: "100",
260+
deadline: 10000000000,
261+
connextAddress: mockConfig.chains[mock.domain.A].deployments!.connext,
262+
};
263+
264+
it("happy: should work", async () => {
265+
sdkPool.config.signerAddress = mockConfig.signerAddress;
266+
const key = getCanonicalHash(mockPool.domainId, mockParams.canonicalId);
267+
const data = getConnextInterface().encodeFunctionData("removeSwapLiquidityImbalance", [
268+
key,
269+
mockParams.amounts,
270+
mockParams.maxBurnAmount,
271+
mockParams.deadline,
272+
]);
273+
274+
const mockRequest: providers.TransactionRequest = {
275+
to: mockParams.connextAddress,
276+
data,
277+
};
278+
279+
stub(sdkPool, "getCanonicalTokenId").resolves([mockPool.domainId, mockParams.canonicalId]);
280+
stub(sdkPool, "getPoolTokenIndex").resolves(0);
281+
282+
const res = await sdkPool.removeLiquidityImbalance(
283+
mockPool.domainId,
284+
mockPool.local.address,
285+
mockParams.amounts,
286+
mockParams.maxBurnAmount,
287+
mockParams.deadline,
288+
);
289+
expect(res).to.be.deep.eq(mockRequest);
290+
});
291+
});
292+
255293
describe("#swap", () => {
256294
const mockParams = {
257295
canonicalId: utils.formatBytes32String("0"),

packages/agents/sequencer/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@connext/nxtp-sequencer",
3-
"version": "1.1.0-alpha.0",
3+
"version": "1.2.0-alpha.0",
44
"description": "Sequencer for Amarok, previously auctioneer",
55
"author": "Connext",
66
"license": "MIT",

packages/agents/watcher/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@connext/nxtp-watcher",
3-
"version": "1.1.0-alpha.0",
3+
"version": "1.2.0-alpha.0",
44
"description": "",
55
"types": "dist/index.d.ts",
66
"files": [

packages/deployments/contracts/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@connext/smart-contracts",
3-
"version": "1.1.0-alpha.0",
3+
"version": "1.2.0-alpha.0",
44
"description": "",
55
"scripts": {
66
"test": "yarn forge test --no-match-path '*/upgrade/**.sol'",

packages/deployments/subgraph/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@connext/nxtp-subgraph",
3-
"version": "1.1.0-alpha.0",
3+
"version": "1.2.0-alpha.0",
44
"license": "UNLICENSED",
55
"scripts": {
66
"graph": "graph",

0 commit comments

Comments
 (0)