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: prepare sway scripts for mainnet #280

Merged
merged 34 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c271ef1
feat: add upgrade script
DefiCake Sep 3, 2024
6c34d49
feat: add L2 bridge proxy owner transfer script
DefiCake Sep 3, 2024
51ac219
chore: upgrade ts-sdk to 0.94.3
DefiCake Sep 3, 2024
455c9f2
chore: align hardhat deployment names with testnet and devnet
DefiCake Sep 3, 2024
112b0f3
feat: improve message relay utils
DefiCake Sep 4, 2024
de6303f
chore: bump ts-sdk
DefiCake Sep 5, 2024
aeb374e
feat: adapt new typings from fuels::provider.getMessageByNonce()
DefiCake Sep 5, 2024
39b5f0e
feat: improve test-utils sway scripts
DefiCake Sep 5, 2024
e5bb548
Merge branch 'main' into deficake/mainnet-sway-scripts
DefiCake Sep 5, 2024
fd2fb7d
chore: remove gas limit override in relayCommonMessage
DefiCake Sep 5, 2024
c2da580
chore: add changeset
DefiCake Sep 5, 2024
297abcc
chore: regenerate pnpm-lock.yaml
DefiCake Sep 5, 2024
0013031
Merge branch 'main' into deficake/mainnet-sway-scripts
K1-R1 Sep 6, 2024
e6983bc
feat: update upgrade script and forc
DefiCake Sep 6, 2024
b18421c
chore: regenerate pnpm-lock.yaml
DefiCake Sep 6, 2024
56c690b
fix: fix upgrade-bridge script
DefiCake Sep 6, 2024
515d027
chore: remove console.log
DefiCake Sep 6, 2024
2db8513
feat: improved workflow of upgrade-bridge script
DefiCake Sep 6, 2024
6f720da
Merge branch 'main' into deficake/mainnet-sway-scripts
DefiCake Sep 11, 2024
389303a
feat: add check-nonce script
DefiCake Sep 29, 2024
abc4f40
feat: add withdraw script
DefiCake Sep 30, 2024
f50b3ad
feat: estabilize withdraw-init
DefiCake Sep 30, 2024
ee6140e
feat: add check-balance script
DefiCake Sep 30, 2024
42c9dbc
feat: add relay metadata script
DefiCake Oct 1, 2024
b41f25a
feat: add relay metadata message script
DefiCake Oct 1, 2024
af0d9e0
feat: add option in verify-asset-metadata to provide l1 address
DefiCake Oct 2, 2024
b1f353f
feat: improve verify-asset-metadata logging
DefiCake Oct 2, 2024
541c43a
Merge branch 'main' into deficake/mainnet-sway-scripts
DefiCake Oct 4, 2024
43804cc
feat: add upgrade script with kms
DefiCake Oct 4, 2024
58761da
Merge branch 'main' into deficake/mainnet-sway-scripts
DefiCake Oct 10, 2024
6fa2875
Merge branch 'main' into deficake/mainnet-sway-scripts
viraj124 Oct 10, 2024
5676348
Merge branch 'main' into deficake/mainnet-sway-scripts
DefiCake Oct 10, 2024
f85e439
docs: fix comments on a couple of scripts
DefiCake Oct 14, 2024
bb3f4f1
Merge branch 'main' into deficake/mainnet-sway-scripts
DefiCake Oct 14, 2024
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
5 changes: 5 additions & 0 deletions .changeset/few-rivers-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@fuel-bridge/test-utils': minor
---

Improve sway scripts
19 changes: 13 additions & 6 deletions packages/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,26 @@
"scripts": {
"build": "tsup",
"build:watch": "tsup --watch",
"deploy:bridge": "pnpm ts-node src/scripts/bridge.ts",
"deploy:relay": "pnpm ts-node src/scripts/relay-deposit.ts"
"bridge:deploy": "pnpm ts-node src/scripts/deploy-bridge.ts",
"bridge:upgrade": "pnpm ts-node src/scripts/upgrade-bridge.ts",
"bridge:transfer-ownership": "pnpm ts-node src/scripts/transfer-bridge-ownership.ts",
"bridge:relay": "pnpm ts-node src/scripts/relay-deposit.ts",
"bridge:withdraw": "pnpm ts-node src/scripts/withdraw-init.ts",
"script:check-balances": "pnpm ts-node src/scripts/check-balances.ts"
},
"peerDependencies": {
"fuels": "0.94.4",
"ethers": "6.13.1"
"ethers": "6.13.1",
"fuels": "0.94.4"
},
"devDependencies": {
"@fuel-bridge/fungible-token": "workspace:*",
"@fuel-bridge/message-predicates": "workspace:*",
"@fuel-bridge/solidity-contracts": "workspace:*",
"@fuels/kms-account": "0.24.0-preview-63de5d8",
"@inquirer/prompts": "^5.3.8",
"dotenv": "^16.0.3",
"typescript": "^5.1.6",
"ts-node": "^10.9.1"
"inquirer": "^10.1.8",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
}
}
30 changes: 30 additions & 0 deletions packages/test-utils/src/scripts/check-balances.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* This is a stand-alone script that looks an address' balances
*/

import { password } from '@inquirer/prompts';
import { Provider, WalletUnlocked } from 'fuels';

let { L2_ADDRESS, L2_RPC } = process.env;

const main = async () => {
const provider = await Provider.create(L2_RPC, { resourceCacheTTL: -1 });

if (!L2_ADDRESS) {
const privKey = await password({ message: 'Enter private key' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why get a privatekey instead of address?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that you can get information about the loaded address from a certain private key

const wallet = new WalletUnlocked(privKey);
L2_ADDRESS = wallet.address.toB256();
}

await provider.getBalances(L2_ADDRESS).then(console.log);
};

main()
.then(() => {
console.log('\t> Finished');
process.exit(0);
})
.catch((e) => {
console.error(e);
process.exit(1);
});
44 changes: 44 additions & 0 deletions packages/test-utils/src/scripts/check-nonce.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* This is a stand-alone script that looks for a message nonce
*/

import { BN, Message, Provider } from 'fuels';

let { L2_RPC, L2_MESSAGE_NONCE } = process.env;

const main = async () => {
if (!L2_MESSAGE_NONCE) {
console.log('Specify L2_MESSAGE_NONCE');
return;
}

if (!L2_RPC) {
console.log('Specify L2_RPC');
return;
}

const provider = await Provider.create(L2_RPC, { resourceCacheTTL: -1 });

const message: Message = await provider
.getMessageByNonce(new BN(L2_MESSAGE_NONCE).toHex(32))
.catch((e) => {
console.log(JSON.stringify(e, undefined, 2));
return null;
});

if (!message) {
console.log('Could not fetch message');
}

console.log(message);
};

main()
.then(() => {
console.log('\t> Finished');
process.exit(0);
})
.catch((e) => {
console.error(e);
process.exit(1);
});
31 changes: 31 additions & 0 deletions packages/test-utils/src/scripts/check-proxy-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* This is a stand-alone script that
* calls the bridge 's withdraw method
*/

import { Proxy } from '@fuel-bridge/fungible-token';

import { Provider } from 'fuels';

let { L2_RPC, L2_BRIDGE_ID } = process.env;
const L1_LLAMA_RPC = 'https://eth.llamarpc.com';
const main = async () => {
const fuel_provider = await Provider.create(L2_RPC, { resourceCacheTTL: -1 });

const proxy = new Proxy(L2_BRIDGE_ID, fuel_provider);

console.log('\t> Checking asset metadata...');

console.log('Owner', (await proxy.functions._proxy_owner().get()).value);
console.log('Target', (await proxy.functions.proxy_target().get()).value);
};

main()
.then(() => {
console.log('\t> Finished');
process.exit(0);
})
.catch((e) => {
console.error(e);
process.exit(1);
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import {
WalletUnlocked,
ZeroBytes32,
} from 'fuels';
import { password } from '@inquirer/prompts';

const { L1_TOKEN_GATEWAY, L2_SIGNER, L2_RPC } = process.env;
let { L1_TOKEN_GATEWAY, L2_SIGNER, L2_RPC } = process.env;

// This helper avoids an exception in the case that the contract
// was already deployed, and returns the contract instead
Expand All @@ -37,6 +38,11 @@ function fetchIfDeployed(provider: Provider, wallet: WalletUnlocked) {

const main = async () => {
const provider = await Provider.create(L2_RPC, { resourceCacheTTL: -1 });

if (!L2_SIGNER) {
L2_SIGNER = await password({ message: 'Enter private key' });
}

const wallet = Wallet.fromPrivateKey(L2_SIGNER, provider);

console.log('\t> L2 Bridge deployment script initiated');
Expand Down
45 changes: 45 additions & 0 deletions packages/test-utils/src/scripts/deposit-to-coin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* This is a stand-alone script that self-transfers
* to convert a message coin into a coin utxo
*/

import { Provider, TransactionStatus, Wallet } from 'fuels';
import { password } from '@inquirer/prompts';

let { L2_SIGNER, L2_RPC } = process.env;

const main = async () => {
if (!L2_RPC) {
console.log('Must provide L2_RPC');
return;
}

const provider = await Provider.create(L2_RPC, { resourceCacheTTL: -1 });

if (!L2_SIGNER) {
L2_SIGNER = await password({ message: 'Enter private key' });
}

const wallet = Wallet.fromPrivateKey(L2_SIGNER, provider);
const balance = await wallet.getBalance();
const tx = await wallet.transfer(wallet.address, balance.div(2));

console.log('\tTransaction ID: ', tx.id);
const txResult = await tx.waitForResult();

if (txResult.status === TransactionStatus.success) {
console.log('\t> Transaction succeeded');
} else {
console.log('\t> Transaction errored');
}
};

main()
.then(() => {
console.log('\t> Finished');
process.exit(0);
})
.catch((e) => {
console.error(e);
process.exit(1);
});
83 changes: 52 additions & 31 deletions packages/test-utils/src/scripts/relay-deposit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* This is a stand-alone script that deploys the
* fetches a deposit messages and relays it to the bridge
* This is a stand-alone script that
* fetches a deposit message and relays it to the bridge
*/

import { Proxy } from '@fuel-bridge/fungible-token';
Expand All @@ -16,6 +16,7 @@ import {
getPredicateRoot,
hexlify,
} from 'fuels';
import { password } from '@inquirer/prompts';
import {
FUEL_MESSAGE_TIMEOUT_MS,
debug,
Expand All @@ -25,11 +26,16 @@ import {

const TOKEN_RECIPIENT_DATA_OFFSET = 160;

const { L2_SIGNER, L2_RPC, L2_BRIDGE_ID, L2_MESSAGE_NONCE, L2_TOKEN_RECEIVER } =
let { L2_SIGNER, L2_RPC, L2_BRIDGE_ID, L2_MESSAGE_NONCE, L2_TOKEN_RECEIVER } =
process.env;

const main = async () => {
const provider = await Provider.create(L2_RPC, { resourceCacheTTL: -1 });

if (!L2_SIGNER) {
L2_SIGNER = await password({ message: 'Enter private key' });
}

const wallet = Wallet.fromPrivateKey(L2_SIGNER, provider);

const proxy = new Proxy(L2_BRIDGE_ID, wallet);
Expand All @@ -43,47 +49,58 @@ const main = async () => {
.proxy_target()
.dryRun()
.then((result) => {
debug('bridge_proxy.target() succeeded, assuming proxy');
debug(`.proxy_target() returned ${result.value.bits}, assuming proxy`);
return result.value.bits;
})
.catch(() => {
debug('bridge.proxy_target() errored, assuming not proxy');
debug('.proxy_target() errored, assuming not proxy');
return null;
});

const predicateRoot = getPredicateRoot(contractMessagePredicate);

let nonce: BN;
let endCursor: string | undefined;

if (L2_MESSAGE_NONCE) nonce = new BN(L2_MESSAGE_NONCE);
else {
const response = await provider.getMessages(predicateRoot);
if (!response.messages || response.messages.length === 0) {
console.log('No messages in the predicate');
return;
else
while (true) {
const response = await provider.getMessages(predicateRoot, {
after: endCursor,
});

if (!response.messages || response.messages.length === 0) {
console.log('No messages in the predicate');
return;
}

const { messages } = response;

const message = messages.find((message) => {
const hex = hexlify(message.data).replace('0x', '');
const recipient = hex.substring(
TOKEN_RECIPIENT_DATA_OFFSET * 2,
TOKEN_RECIPIENT_DATA_OFFSET * 2 + 64 // Recipient is 32 bytes
);
const expectedRecipient = L2_TOKEN_RECEIVER || wallet.address.toB256();

return recipient === expectedRecipient.replace('0x', '');
});

if (!message) {
if (response.pageInfo.hasNextPage) {
endCursor = response.pageInfo.endCursor;
continue;
} else {
console.log('No messages for the recipient');
return;
}
}

nonce = new BN(message.nonce);
break;
}

const { messages } = response;

const message = messages.find((message) => {
const hex = hexlify(message.data).replace('0x', '');
const recipient = hex.substring(
TOKEN_RECIPIENT_DATA_OFFSET * 2,
TOKEN_RECIPIENT_DATA_OFFSET * 2 + 64 // Recipient is 32 bytes
);
const expectedRecipient = L2_TOKEN_RECEIVER || wallet.address.toB256();

return recipient === expectedRecipient.replace('0x', '');
});

if (!message) {
console.log('No messages for the recipient');
return;
}

nonce = new BN(message.nonce);
}

const message = await waitForMessage(
provider,
new Account(predicateRoot).address,
Expand All @@ -105,6 +122,10 @@ const main = async () => {

if (txResult.status === TransactionStatus.success) {
console.log('\t> Transaction succeeded');
console.log(
'\t > Minted asset IDs: ',
txResult.mintedAssets.map((asset) => asset.assetId)
);
} else {
console.log('\t> Transaction errored');
}
Expand Down
Loading
Loading