Skip to content

Commit

Permalink
Merge pull request #34 from labscommunity/kranthi/remove-subsidize
Browse files Browse the repository at this point in the history
Kranthi/remove subsidize
  • Loading branch information
kranthicodes authored Sep 26, 2024
2 parents d572c6f + 4e7fb85 commit 223d326
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 199 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-carrots-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@protocol.land/sync': minor
---

remove repo subsidization
30 changes: 1 addition & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The Protocol Land Sync package simplifies the process of syncing Git repositorie

To sync a repository with Protocol Land, you can either run it manually from your local Git repository's root folder or set up a GitHub Action if your repository is hosted on GitHub.

For both methods, **you need an Arweave wallet with some $AR** to pay for the upload, unless your repository uses less than 100KB of data.
For both methods, **you need an Arweave wallet with some $AR** to pay for the upload.

### GitHub Actions

Expand Down Expand Up @@ -60,24 +60,9 @@ jobs:
REPO_TITLE: ${{ github.event.repository.name }}
REPO_DESCRIPTION: ${{ github.event.repository.description }}
WALLET: ${{ secrets.WALLET }}
# Optional Environment variables for ArSeeding strategy
STRATEGY: "ARSEEDING"
ARSEEDING_TOKEN_SYMBOL: "AR"
# Use personal funds in case of transaction subsidization failure
HANDLE_SUBSIDY_ERROR: "true"

```


> [!NOTE]
> Currently all Sync transactions are subsidized by Protocol Land. In case of subsidizing service failure, Sync program will exit unless `HANDLE_SUBSIDY_ERROR` env is set which lets you pay for the transaction from your wallet and continue.

> [!NOTE]
> Only include `STRATEGY` and `ARSEEDING_TOKEN_SYMBOL` environment variables for using [ArSeeding](https://web3infra.dev/docs/arseeding/introduction/lightNode/) to sync your repositories to Protocol Land.
> Supported Arweave tokens for ArSeeding strategy are: `['XYZ', 'ARDRIVE', 'PIA', 'VRT', 'U', 'STAMP', 'AR']`.
> You need [EverPay](https://app.everpay.io/) balances for these tokens to use ArSeeding strategy.
> [!NOTE]
> This GitHub Action **will run on every push to the 'main' branch**.
> If you want to run it manually, comment the lines after `on:` and uncomment the `workflow_dispatch:` line.
Expand Down Expand Up @@ -107,25 +92,12 @@ Follow `1.` and `2.` from the previous section to set up a GitHub Secret.
WALLET='YOUR_WALLET_JWK_HERE'
REPO_TITLE='Your Repo Name Here'
REPO_DESCRIPTION='Your Repo Description Here'

# Optional Environment variables for ArSeeding strategy

STRATEGY='ARSEEDING'
ARSEEDING_TOKEN_SYMBOL='AR'

# Use personal funds in case of transaction subsidization failure

HANDLE_SUBSIDY_ERROR='true'
```

Replace `'YOUR_WALLET_JWK_HERE'` with your Arweave wallet's JWK (JSON Web Key).
Currently Sync transaction costs are subsidized by Protocol Land and in case of subsidization failure, Sync program will exit unless `HANDLE_SUBSIDY_ERROR` env is set which lets you pay for the transaction from your wallet and continue.
If the compressed size of your repository exceeds 100kb, ensure your wallet has enough $AR to cover the transaction fees.
These environment variables (`WALLET`, `REPO_TITLE`, and `REPO_DESCRIPTION`) are crucial for setting up your repository and providing a meaningful description.
`STRATEGY` and `ARSEEDING_TOKEN_SYMBOL` are needed for using [ArSeeding](https://web3infra.dev/docs/arseeding/introduction/lightNode/) to sync repositories to Protocol Land. Supported Arweave tokens for ArSeeding strategy are: `['XYZ', 'ARDRIVE', 'PIA', 'VRT', 'U', 'STAMP', 'AR']`.
4. **(optional)** Checkout locally all the branches you want synced. The tool uploads all the branches you have checked out locally with Git.
Run this bash command to checkout all the remote branches:
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@
"@amplitude/analytics-node": "^1.3.4",
"@permaweb/aoconnect": "^0.0.52",
"arbundles": "^0.9.11",
"arseeding-js": "^0.0.30",
"arweave": "^1.14.4",
"dotenv": "^16.4.1",
"everpay": "^1.2.2",
"jszip": "^3.10.1",
"uuid": "^9.0.1"
},
Expand Down
85 changes: 0 additions & 85 deletions src/lib/arseeding.ts

This file was deleted.

87 changes: 4 additions & 83 deletions src/lib/arweaveHelper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { getWallet, initArweave } from './common';
import { Tag } from 'arweave/node/lib/transaction';
import { ArweaveSigner, bundleAndSignData, createData } from 'arbundles';
import { arseedingUpload } from './arseeding';
import { ArweaveSigner, createData } from 'arbundles';

const jwk = getWallet();

Expand All @@ -15,44 +14,9 @@ export function getActivePublicKey() {
}

export async function uploadRepo(zipBuffer: Buffer, tags: Tag[]) {
//Subsidized Upload
try {
const uploadedTx = await subsidizedUpload(zipBuffer, tags);
const serviceUsed = uploadedTx.bundled ? 'Turbo' : 'Arweave';

console.log(
`[ PL SUBSIDIZE ] Posted Tx to ${serviceUsed}: ${uploadedTx.data.repoTxId}`
);

return uploadedTx.data.repoTxId;
} catch (error) {
const userWantsToPay = process.env.HANDLE_SUBSIDY_ERROR === 'true';

if (!userWantsToPay) {
throw '[ PL SUBSIDIZE ] Failed to subsidize this transaction.';
}
//continue
}

const isArSeedingStrategy = process.env.STRATEGY === 'ARSEEDING';
if (isArSeedingStrategy) {
const arweaveTxId = await arseedingUpload(zipBuffer, tags);
console.log('Posted Tx to Arseeding: ', arweaveTxId);
return arweaveTxId;
} else {
try {
// upload compressed repo using turbo
const turboTxId = await turboUpload(zipBuffer, tags);
console.log('Posted Tx to Turbo: ', turboTxId);
return turboTxId;
} catch (error) {
console.log('Error uploading using turbo, trying with Arweave...');
// let Arweave throw if it encounters errors
const arweaveTxId = await arweaveUpload(zipBuffer, tags);
console.log('Posted Tx to Arweave: ', arweaveTxId);
return arweaveTxId;
}
}
const arweaveTxId = await arweaveUpload(zipBuffer, tags);
console.log('Posted Tx to Arweave: ', arweaveTxId);
return arweaveTxId;
}

async function arweaveUpload(zipBuffer: Buffer, tags: Tag[]) {
Expand Down Expand Up @@ -116,46 +80,3 @@ export async function turboUpload(zipBuffer: Buffer, tags: Tag[]) {

return dataItem.id;
}

export async function subsidizedUpload(zipBuffer: Buffer, tags: Tag[]) {
if (!jwk) throw '[ turbo ] No jwk wallet supplied';

const node = 'https://subsidize.saikranthi.dev/api/v1/postrepobuffer';
const uint8ArrayZip = new Uint8Array(zipBuffer);
const signer = new ArweaveSigner(jwk);
const address = await getAddress();

const dataItem = createData(uint8ArrayZip, signer, { tags });
await dataItem.sign(signer);

const bundle = await bundleAndSignData([dataItem], signer);
const bundleBuffer = bundle.getRaw();

const formData = new FormData();
formData.append('txBundle', new Blob([bundleBuffer]));
formData.append('platform', 'CLI');
formData.append('owner', address);

const res = await fetch(`${node}`, {
method: 'POST',
headers: {
Accept: 'application/json',
},
body: formData,
});
const upload = (await res.json()) as SubsidizedUploadJsonResponse;

if (!upload || !upload.success)
throw new Error(
`[ turbo ] Posting repo with turbo failed. Error: ${res.status} - ${res.statusText}`
);

return upload;
}

export type SubsidizedUploadJsonResponse = {
success: boolean;
bundled: boolean;
data: { repoTxId: string };
error?: string;
};

0 comments on commit 223d326

Please sign in to comment.